From 3bf9df6b2785fa6d951086978a3e66f49427166a Mon Sep 17 00:00:00 2001 From: FluorescentCIAAfricanAmerican <0934gj3049fk@protonmail.com> Date: Wed, 22 Apr 2020 12:56:21 -0400 Subject: 1 --- materialsystem/CColorCorrection.cpp | 837 ++ materialsystem/CMaterialSubRect.cpp | 1069 ++ materialsystem/IHardwareConfigInternal.h | 30 + materialsystem/IShaderSystem.h | 104 + materialsystem/MaterialSystem.rc | 63 + materialsystem/Resource.rc | 109 + materialsystem/checkmaterials.cpp | 664 + materialsystem/cmaterial.cpp | 3599 +++++ materialsystem/cmaterial_queuefriendly.cpp | 410 + materialsystem/cmaterial_queuefriendly.h | 162 + materialsystem/cmaterialdict.cpp | 171 + materialsystem/cmaterialdict.h | 179 + materialsystem/cmaterialsystem.cpp | 5547 +++++++ materialsystem/cmaterialsystem.h | 736 + materialsystem/cmaterialvar.cpp | 1631 +++ materialsystem/cmatlightmaps.cpp | 2191 +++ materialsystem/cmatlightmaps.h | 199 + materialsystem/cmatnullrendercontext.cpp | 847 ++ materialsystem/cmatnullrendercontext.h | 18 + materialsystem/cmatqueuedrendercontext.cpp | 1753 +++ materialsystem/cmatqueuedrendercontext.h | 641 + materialsystem/cmatrendercontext.cpp | 3157 ++++ materialsystem/cmatrendercontext.h | 720 + materialsystem/colorspace.cpp | 212 + materialsystem/colorspace.h | 333 + materialsystem/ctexture.cpp | 4959 +++++++ materialsystem/ctexturecompositor.cpp | 2842 ++++ materialsystem/ctexturecompositor.h | 132 + materialsystem/genshadermacro.pl | 105 + materialsystem/imagepacker.cpp | 169 + materialsystem/imagepacker.h | 69 + materialsystem/imaterialinternal.h | 161 + materialsystem/imaterialsysteminternal.h | 224 + materialsystem/imatrendercontextinternal.h | 79 + materialsystem/imorphinternal.h | 91 + materialsystem/itextureinternal.h | 190 + materialsystem/mat_stub.cpp | 2373 +++ materialsystem/materialsystem.vpc | 174 + materialsystem/materialsystem_global.cpp | 20 + materialsystem/materialsystem_global.h | 110 + materialsystem/morph.cpp | 2280 +++ materialsystem/occlusionquerymgr.cpp | 258 + materialsystem/occlusionquerymgr.h | 106 + materialsystem/pch_materialsystem.cpp | 7 + materialsystem/pch_materialsystem.h | 56 + materialsystem/resource.h | 22 + materialsystem/shader_dll_verify.cpp | 96 + materialsystem/shader_dll_verify.h | 38 + materialsystem/shaderapidx9/ShaderShadowDx10.h | 176 + materialsystem/shaderapidx9/TransitionTable.cpp | 1924 +++ materialsystem/shaderapidx9/TransitionTable.h | 407 + materialsystem/shaderapidx9/colorformatdx8.cpp | 727 + materialsystem/shaderapidx9/colorformatdx8.h | 60 + materialsystem/shaderapidx9/cvballoctracker.cpp | 764 + materialsystem/shaderapidx9/d3d_async.cpp | 825 ++ materialsystem/shaderapidx9/d3d_async.h | 1567 ++ materialsystem/shaderapidx9/dx9hook.h | 1289 ++ materialsystem/shaderapidx9/dynamicib.h | 1056 ++ materialsystem/shaderapidx9/dynamicvb.h | 1098 ++ materialsystem/shaderapidx9/gpubufferallocator.cpp | 480 + materialsystem/shaderapidx9/gpubufferallocator.h | 146 + materialsystem/shaderapidx9/hardwareconfig.cpp | 1311 ++ materialsystem/shaderapidx9/hardwareconfig.h | 286 + materialsystem/shaderapidx9/imeshdx8.h | 98 + materialsystem/shaderapidx9/inputlayoutdx10.cpp | 214 + materialsystem/shaderapidx9/inputlayoutdx10.h | 35 + materialsystem/shaderapidx9/ivertexbufferdx8.h | 34 + materialsystem/shaderapidx9/locald3dtypes.h | 191 + materialsystem/shaderapidx9/meshbase.cpp | 419 + materialsystem/shaderapidx9/meshbase.h | 309 + materialsystem/shaderapidx9/meshdx10.cpp | 775 + materialsystem/shaderapidx9/meshdx10.h | 282 + materialsystem/shaderapidx9/meshdx8.cpp | 5980 ++++++++ materialsystem/shaderapidx9/recording.cpp | 157 + materialsystem/shaderapidx9/recording.h | 198 + materialsystem/shaderapidx9/shaderapi_global.h | 105 + materialsystem/shaderapidx9/shaderapibase.cpp | 42 + materialsystem/shaderapidx9/shaderapibase.h | 86 + materialsystem/shaderapidx9/shaderapidx10.cpp | 1461 ++ materialsystem/shaderapidx9/shaderapidx10.h | 940 ++ materialsystem/shaderapidx9/shaderapidx10.vpc | 174 + materialsystem/shaderapidx9/shaderapidx10_global.h | 19 + materialsystem/shaderapidx9/shaderapidx8.cpp | 14354 +++++++++++++++++++ materialsystem/shaderapidx9/shaderapidx8.h | 118 + materialsystem/shaderapidx9/shaderapidx8_global.h | 100 + materialsystem/shaderapidx9/shaderapidx9.vpc | 146 + materialsystem/shaderapidx9/shaderdevicebase.cpp | 1256 ++ materialsystem/shaderapidx9/shaderdevicebase.h | 234 + materialsystem/shaderapidx9/shaderdevicedx10.cpp | 1002 ++ materialsystem/shaderapidx9/shaderdevicedx10.h | 254 + materialsystem/shaderapidx9/shaderdevicedx8.cpp | 3707 +++++ materialsystem/shaderapidx9/shaderdevicedx8.h | 382 + materialsystem/shaderapidx9/shadershadowdx10.cpp | 227 + materialsystem/shaderapidx9/shadershadowdx8.cpp | 1826 +++ materialsystem/shaderapidx9/shadershadowdx8.h | 176 + materialsystem/shaderapidx9/stubd3ddevice.h | 809 ++ materialsystem/shaderapidx9/texturedx8.cpp | 1545 ++ materialsystem/shaderapidx9/texturedx8.h | 110 + materialsystem/shaderapidx9/textureheap.cpp | 1258 ++ materialsystem/shaderapidx9/textureheap.h | 42 + materialsystem/shaderapidx9/vertexdecl.cpp | 576 + materialsystem/shaderapidx9/vertexdecl.h | 32 + materialsystem/shaderapidx9/vertexshaderdx8.cpp | 3783 +++++ materialsystem/shaderapidx9/vertexshaderdx8.h | 135 + materialsystem/shaderapidx9/winutils.cpp | 93 + materialsystem/shaderapidx9/winutils.h | 21 + materialsystem/shaderapidx9/wmi.cpp | 182 + materialsystem/shaderapidx9/wmi.h | 17 + materialsystem/shaderapidx9/xbox/xbox.def | 3 + materialsystem/shaderapiempty/shaderapiempty.cpp | 2956 ++++ materialsystem/shaderapiempty/shaderapiempty.vpc | 38 + materialsystem/shaderlib/BaseShader.cpp | 1791 +++ materialsystem/shaderlib/ShaderDLL.cpp | 169 + materialsystem/shaderlib/shaderDLL_Global.h | 33 + materialsystem/shaderlib/shaderlib.vpc | 70 + materialsystem/shaderlib/shaderlib_cvar.cpp | 42 + materialsystem/shaderlib/shaderlib_cvar.h | 20 + materialsystem/shadersystem.cpp | 2057 +++ materialsystem/shadersystem.h | 216 + materialsystem/stdshaders/AccumBuff4Sample.cpp | 114 + .../stdshaders/AccumBuff4Sample_ps2x.fxc | 32 + materialsystem/stdshaders/BaseVSShader.cpp | 2249 +++ materialsystem/stdshaders/BaseVSShader.h | 440 + materialsystem/stdshaders/Bloom.cpp | 90 + materialsystem/stdshaders/Bloom_ps2x.fxc | 21 + materialsystem/stdshaders/BlurFilterX.cpp | 122 + materialsystem/stdshaders/BlurFilterX_dx80.cpp | 86 + materialsystem/stdshaders/BlurFilterY.cpp | 136 + materialsystem/stdshaders/BlurFilterY_dx80.cpp | 91 + materialsystem/stdshaders/BlurFilter_ps11.psh | 18 + materialsystem/stdshaders/BlurFilter_ps2x.fxc | 91 + materialsystem/stdshaders/BlurFilter_vs11.fxc | 34 + materialsystem/stdshaders/BlurFilter_vs20.fxc | 39 + .../stdshaders/BufferClearObeyStencil_dx6.cpp | 51 + .../stdshaders/BufferClearObeyStencil_dx8.cpp | 67 + .../stdshaders/BufferClearObeyStencil_dx9.cpp | 112 + .../stdshaders/BufferClearObeyStencil_ps11.psh | 3 + .../stdshaders/BufferClearObeyStencil_vs11.vsh | 8 + materialsystem/stdshaders/BumpmappedEnvmap.psh | 32 + materialsystem/stdshaders/BumpmappedEnvmap.vsh | 83 + materialsystem/stdshaders/BumpmappedLightmap.vsh | 57 + ...BumpmappedLightmap_LightingOnly_OverBright2.psh | 43 + .../stdshaders/BumpmappedLightmap_OverBright2.psh | 43 + materialsystem/stdshaders/Cable.psh | 27 + materialsystem/stdshaders/Cable.vsh | 117 + materialsystem/stdshaders/DebugDrawDepth_ps2x.fxc | 23 + materialsystem/stdshaders/DebugDrawDepth_vs20.fxc | 38 + materialsystem/stdshaders/DebugDrawEnvmapMask.cpp | 94 + .../stdshaders/DebugDrawEnvmapMask_ps2x.fxc | 26 + .../stdshaders/DebugDrawEnvmapMask_vs20.fxc | 39 + materialsystem/stdshaders/DebugTextureView.cpp | 104 + .../stdshaders/DebugTextureView_ps2x.fxc | 81 + .../stdshaders/DebugTextureView_vs20.fxc | 23 + ...lBaseTimesLightmapAlphaBlendSelfIllum1_ps11.psh | 9 + ...lBaseTimesLightmapAlphaBlendSelfIllum2_ps11.psh | 5 + ...calBaseTimesLightmapAlphaBlendSelfIllum_dx6.cpp | 83 + ...calBaseTimesLightmapAlphaBlendSelfIllum_dx8.cpp | 142 + ...calBaseTimesLightmapAlphaBlendSelfIllum_dx9.cpp | 270 + materialsystem/stdshaders/DecalModulate_dx9.cpp | 232 + materialsystem/stdshaders/Downsample.cpp | 110 + .../stdshaders/Downsample_nohdr_ps11.psh | 23 + .../stdshaders/Downsample_nohdr_ps2x.fxc | 82 + materialsystem/stdshaders/Downsample_ps2x.fxc | 30 + materialsystem/stdshaders/Downsample_vs11.fxc | 40 + materialsystem/stdshaders/Downsample_vs20.fxc | 34 + materialsystem/stdshaders/Engine_Post_dx9.cpp | 227 + materialsystem/stdshaders/Engine_Post_ps2x.fxc | 433 + materialsystem/stdshaders/Eyes.psh | 16 + materialsystem/stdshaders/Eyes_Overbright2.psh | 18 + materialsystem/stdshaders/Eyes_vs20.fxc | 145 + materialsystem/stdshaders/HDRCombineTo16Bit.cpp | 83 + .../stdshaders/HDRCombineTo16Bit_ps2x.fxc | 25 + .../stdshaders/HDRCombineTo16Bit_vs20.fxc | 24 + materialsystem/stdshaders/HDRSelectRange.cpp | 82 + materialsystem/stdshaders/HDRSelectRange_ps2x.fxc | 45 + materialsystem/stdshaders/HDRSelectRange_vs20.fxc | 24 + .../stdshaders/IntroScreenSpaceEffect_ps11.fxc | 111 + .../stdshaders/IntroScreenSpaceEffect_ps11_asm.psh | 159 + .../stdshaders/IntroScreenSpaceEffect_ps2x.fxc | 339 + materialsystem/stdshaders/JellyFish.psh | 17 + materialsystem/stdshaders/JellyFish.vsh | 82 + materialsystem/stdshaders/LightingOnly.vsh | 40 + materialsystem/stdshaders/LightmappedGeneric.psh | 15 + ...LightmappedGeneric_AddBaseAlphaMaskedEnvMap.psh | 17 + .../LightmappedGeneric_AddEnvMapMaskNoTexture.psh | 17 + .../LightmappedGeneric_AddEnvMapNoTexture.psh | 15 + .../LightmappedGeneric_BaseAlphaMaskedEnvMapV2.psh | 22 + .../stdshaders/LightmappedGeneric_BaseTexture.psh | 14 + .../stdshaders/LightmappedGeneric_BaseTexture.vsh | 38 + .../LightmappedGeneric_BaseTextureBlend.vsh | 43 + .../LightmappedGeneric_BumpmappedEnvmap.psh | 66 + .../LightmappedGeneric_BumpmappedEnvmap.vsh | 96 + .../LightmappedGeneric_BumpmappedEnvmap_ps14.psh | 72 + .../LightmappedGeneric_BumpmappedEnvmap_ps14.vsh | 92 + .../LightmappedGeneric_BumpmappedLightmap.psh | 79 + .../LightmappedGeneric_BumpmappedLightmap.vsh | 54 + ...tmappedGeneric_BumpmappedLightmap_base_ps14.psh | 39 + ...tmappedGeneric_BumpmappedLightmap_base_ps14.vsh | 55 + ...mappedGeneric_BumpmappedLightmap_blend_ps14.psh | 47 + ...mappedGeneric_BumpmappedLightmap_blend_ps14.vsh | 57 + .../stdshaders/LightmappedGeneric_Decal.psh | 47 + .../stdshaders/LightmappedGeneric_Decal.vsh | 56 + .../stdshaders/LightmappedGeneric_Detail.psh | 18 + .../LightmappedGeneric_DetailNoTexture.psh | 16 + .../LightmappedGeneric_DetailSelfIlluminated.psh | 23 + .../LightmappedGeneric_EnvMapNoTexture.psh | 21 + .../stdshaders/LightmappedGeneric_EnvMapV2.psh | 20 + .../stdshaders/LightmappedGeneric_LightingOnly.vsh | 45 + ...LightmappedGeneric_LightingOnly_Overbright2.psh | 6 + .../LightmappedGeneric_MaskedEnvMapNoTexture.psh | 24 + .../LightmappedGeneric_MaskedEnvMapV2.psh | 22 + .../LightmappedGeneric_MultiplyByLighting.psh | 20 + ...htmappedGeneric_MultiplyByLightingNoTexture.psh | 20 + ...htmappedGeneric_MultiplyByLightingSelfIllum.psh | 23 + .../stdshaders/LightmappedGeneric_NoTexture.psh | 14 + .../LightmappedGeneric_SSBumpmappedLightmap.psh | 34 + .../LightmappedGeneric_SelfIlluminated.psh | 21 + .../LightmappedGeneric_SelfIlluminatedEnvMapV2.psh | 27 + ...mappedGeneric_SelfIlluminatedMaskedEnvMapV2.psh | 28 + .../stdshaders/LightmappedGeneric_VertexColor.vsh | 15 + .../stdshaders/LightmappedTranslucentTexture.psh | 19 + .../stdshaders/LightmappedTranslucentTexture.vsh | 16 + materialsystem/stdshaders/Modulate_ps11.psh | 8 + materialsystem/stdshaders/MonitorScreen.psh | 17 + materialsystem/stdshaders/MonitorScreen_dx8.cpp | 150 + materialsystem/stdshaders/MonitorScreen_dx9.cpp | 197 + materialsystem/stdshaders/ParticleSphere.vsh | 163 + materialsystem/stdshaders/Refract_model_vs11.vsh | 105 + materialsystem/stdshaders/Refract_ps11.psh | 36 + materialsystem/stdshaders/Refract_vs20.fxc | 140 + materialsystem/stdshaders/Refract_world_vs11.vsh | 168 + materialsystem/stdshaders/ScreenSpaceEffect.vsh | 29 + materialsystem/stdshaders/SetZ.cpp | 43 + materialsystem/stdshaders/Shadow.psh | 12 + materialsystem/stdshaders/ShadowBuildTexture.psh | 12 + materialsystem/stdshaders/ShadowModel.psh | 22 + materialsystem/stdshaders/ShadowModel.vsh | 85 + materialsystem/stdshaders/ShatteredGlass.psh | 21 + materialsystem/stdshaders/ShatteredGlass.vsh | 15 + .../stdshaders/ShatteredGlass_EnvMap.psh | 26 + .../stdshaders/ShatteredGlass_EnvMap.vsh | 15 + .../stdshaders/ShatteredGlass_EnvMapSphere.vsh | 15 + materialsystem/stdshaders/ShatteredGlass_inc.vsh | 105 + materialsystem/stdshaders/ShatteredGlass_ps2x.fxc | 130 + materialsystem/stdshaders/ShatteredGlass_vs20.fxc | 70 + materialsystem/stdshaders/SpriteRenderNormal.psh | 5 + materialsystem/stdshaders/SpriteRenderTransAdd.psh | 7 + .../stdshaders/SpriteRenderTransColor.psh | 5 + materialsystem/stdshaders/Teeth.vsh | 97 + materialsystem/stdshaders/TreeLeaf.cpp | 102 + materialsystem/stdshaders/TreeLeaf_ps2x.fxc | 20 + materialsystem/stdshaders/TreeLeaf_vs20.fxc | 72 + materialsystem/stdshaders/UPDB_X360/dummy.txt | 3 + materialsystem/stdshaders/UnlitGeneric.psh | 13 + .../UnlitGeneric_BaseAlphaMaskedEnvMap.psh | 19 + materialsystem/stdshaders/UnlitGeneric_Detail.psh | 15 + .../UnlitGeneric_DetailBaseAlphaMaskedEnvMap.psh | 29 + .../stdshaders/UnlitGeneric_DetailEnvMap.psh | 25 + .../stdshaders/UnlitGeneric_DetailEnvMapMask.psh | 29 + .../UnlitGeneric_DetailEnvMapMaskNoTexture.psh | 21 + .../UnlitGeneric_DetailEnvMapNoTexture.psh | 19 + .../stdshaders/UnlitGeneric_DetailNoTexture.psh | 10 + materialsystem/stdshaders/UnlitGeneric_EnvMap.psh | 17 + .../stdshaders/UnlitGeneric_EnvMapMask.psh | 19 + .../UnlitGeneric_EnvMapMaskNoTexture.psh | 17 + .../stdshaders/UnlitGeneric_EnvMapNoTexture.psh | 15 + .../stdshaders/UnlitGeneric_LightingOnly.vsh | 21 + .../UnlitGeneric_MaskBaseByDetailAlpha_ps11.fxc | 20 + .../stdshaders/UnlitGeneric_NoTexture.psh | 7 + materialsystem/stdshaders/UnlitTwoTexture.psh | 15 + materialsystem/stdshaders/UnlitTwoTexture.vsh | 10 + materialsystem/stdshaders/VertexLitGeneric.psh | 13 + .../VertexLitGeneric_BaseAlphaMaskedEnvMapV2.psh | 17 + .../stdshaders/VertexLitGeneric_BlendTint.psh | 17 + .../stdshaders/VertexLitGeneric_Detail.psh | 16 + ...texLitGeneric_DetailBaseAlphaMaskedEnvMapV2.psh | 18 + .../stdshaders/VertexLitGeneric_DetailEnvMapV2.psh | 16 + .../VertexLitGeneric_DetailMaskedEnvMapV2.psh | 18 + .../VertexLitGeneric_DetailNoTexture.psh | 12 + .../VertexLitGeneric_DetailSelfIlluminated.psh | 22 + ...texLitGeneric_DetailSelfIlluminatedEnvMapV2.psh | 24 + ...Generic_DetailSelfIlluminatedMaskedEnvMapV2.psh | 26 + .../VertexLitGeneric_Detail_LerpBase.psh | 15 + .../VertexLitGeneric_Detail_additive.psh | 15 + .../VertexLitGeneric_Detail_additive_selfillum.psh | 15 + .../VertexLitGeneric_EnvMapNoTexture.psh | 14 + .../stdshaders/VertexLitGeneric_EnvMapV2.psh | 14 + .../VertexLitGeneric_EnvmappedBumpmapV2.psh | 36 + ...exLitGeneric_EnvmappedBumpmapV2_MultByAlpha.psh | 42 + ...Generic_EnvmappedBumpmapV2_MultByAlpha_ps14.psh | 42 + .../VertexLitGeneric_EnvmappedBumpmapV2_ps14.psh | 39 + ...ertexLitGeneric_EnvmappedBumpmap_NoLighting.vsh | 93 + ...LitGeneric_EnvmappedBumpmap_NoLighting_ps14.vsh | 90 + .../VertexLitGeneric_MaskedEnvMapNoTexture.psh | 15 + .../stdshaders/VertexLitGeneric_MaskedEnvMapV2.psh | 16 + .../stdshaders/VertexLitGeneric_NoTexture.psh | 9 + .../stdshaders/VertexLitGeneric_SelfIllumOnly.psh | 5 + .../stdshaders/VertexLitGeneric_SelfIllumOnly.vsh | 41 + .../VertexLitGeneric_SelfIlluminated.psh | 19 + .../VertexLitGeneric_SelfIlluminatedEnvMapV2.psh | 21 + ...texLitGeneric_SelfIlluminatedMaskedEnvMapV2.psh | 23 + materialsystem/stdshaders/VertexLitTexture.psh | 15 + .../stdshaders/VertexLitTexture_Overbright2.psh | 16 + materialsystem/stdshaders/VertexTextureTest.cpp | 84 + .../stdshaders/WaterCheapFresnelOpaque_ps14.psh | 40 + .../stdshaders/WaterCheapFresnel_ps14.psh | 39 + .../stdshaders/WaterCheapNoFresnelOpaque_ps11.psh | 19 + .../stdshaders/WaterCheapNoFresnel_ps11.psh | 18 + .../stdshaders/WaterCheapOpaque_ps11.psh | 26 + .../stdshaders/WaterCheapOpaque_ps14.psh | 31 + .../stdshaders/WaterCheapPerVertexFresnel_vs11.vsh | 100 + materialsystem/stdshaders/WaterCheap_ps11.psh | 26 + materialsystem/stdshaders/WaterCheap_ps14.psh | 30 + materialsystem/stdshaders/WaterCheap_ps2x.fxc | 152 + materialsystem/stdshaders/WaterCheap_vs11.vsh | 88 + materialsystem/stdshaders/WaterCheap_vs14.vsh | 96 + materialsystem/stdshaders/WaterCheap_vs20.fxc | 84 + materialsystem/stdshaders/WaterReflect_ps11.psh | 27 + .../stdshaders/WaterRefractFresnel_ps11.psh | 24 + materialsystem/stdshaders/WaterRefract_ps11.psh | 13 + materialsystem/stdshaders/Water_ps14.psh | 96 + materialsystem/stdshaders/Water_ps14.vsh | 95 + materialsystem/stdshaders/Water_vs11.vsh | 102 + materialsystem/stdshaders/Water_vs20.fxc | 117 + materialsystem/stdshaders/WorldTexture.psh | 14 + materialsystem/stdshaders/WorldTwoTextureBlend.psh | 21 + .../WorldTwoTextureBlend_DetailAlpha.psh | 25 + .../WorldTwoTextureBlend_SelfIlluminated.psh | 27 + materialsystem/stdshaders/WorldVertexAlpha.psh | 10 + materialsystem/stdshaders/WorldVertexAlpha.vsh | 37 + .../stdshaders/WorldVertexAlpha_ps2x.fxc | 43 + .../stdshaders/WorldVertexTransition.psh | 18 + .../stdshaders/WorldVertexTransition.vsh | 48 + .../WorldVertexTransition_BlendBase2.psh | 16 + .../stdshaders/WorldVertexTransition_Editor.psh | 10 + .../stdshaders/WorldVertexTransition_Seamless.psh | 23 + .../stdshaders/WorldVertexTransition_Seamless.vsh | 54 + .../stdshaders/WorldVertexTransition_dx8.cpp | 537 + .../stdshaders/WorldVertexTransition_ps14.psh | 32 + .../stdshaders/WorldVertexTransition_ps2x.fxc | 47 + .../stdshaders/WorldVertexTransition_vs14.vsh | 52 + .../stdshaders/WorldVertexTransition_vs20.fxc | 64 + materialsystem/stdshaders/accumbuff5sample.cpp | 110 + .../stdshaders/accumbuff5sample_ps2x.fxc | 35 + materialsystem/stdshaders/aftershock.cpp | 76 + materialsystem/stdshaders/aftershock_helper.cpp | 196 + materialsystem/stdshaders/aftershock_helper.h | 56 + materialsystem/stdshaders/aftershock_ps2x.fxc | 162 + materialsystem/stdshaders/aftershock_vs20.fxc | 110 + materialsystem/stdshaders/alphadist_ps11.fxc | 27 + .../stdshaders/appchooser360movie_ps2x.fxc | 31 + materialsystem/stdshaders/bik_dx80.cpp | 95 + materialsystem/stdshaders/bik_dx81.cpp | 86 + materialsystem/stdshaders/bik_dx90.cpp | 132 + materialsystem/stdshaders/bik_ps11.psh | 53 + materialsystem/stdshaders/bik_ps14.psh | 22 + materialsystem/stdshaders/bik_ps2x.fxc | 96 + materialsystem/stdshaders/bik_vs11.vsh | 19 + materialsystem/stdshaders/bik_vs20.fxc | 45 + materialsystem/stdshaders/bloomadd_ps11.fxc | 18 + materialsystem/stdshaders/bloomadd_ps2x.fxc | 23 + .../stdshaders/bufferclearobeystencil_ps2x.fxc | 14 + .../stdshaders/bufferclearobeystencil_vs20.fxc | 35 + materialsystem/stdshaders/buildallshaders.bat | 77 + materialsystem/stdshaders/builddynamic.bat | 3 + materialsystem/stdshaders/buildshaders.bat | 258 + .../stdshaders/bumpmappedlightmap_vs11.fxc | 59 + materialsystem/stdshaders/cable_dx6.cpp | 62 + materialsystem/stdshaders/cable_dx8.cpp | 132 + materialsystem/stdshaders/cable_dx9.cpp | 141 + materialsystem/stdshaders/cable_ps2x.fxc | 54 + materialsystem/stdshaders/cable_vs20.fxc | 80 + materialsystem/stdshaders/clean.bat | 43 + materialsystem/stdshaders/cleantemps.bat | 12 + materialsystem/stdshaders/cloak.cpp | 122 + .../stdshaders/cloak_blended_pass_dx8_helper.cpp | 252 + .../stdshaders/cloak_blended_pass_dx8_ps11.psh | 12 + .../stdshaders/cloak_blended_pass_dx8_vs11.vsh | 104 + .../stdshaders/cloak_blended_pass_helper.cpp | 358 + .../stdshaders/cloak_blended_pass_helper.h | 46 + .../stdshaders/cloak_blended_pass_ps2x.fxc | 106 + .../stdshaders/cloak_blended_pass_vs20.fxc | 132 + materialsystem/stdshaders/cloak_dx9_helper.cpp | 341 + materialsystem/stdshaders/cloak_dx9_helper.h | 63 + materialsystem/stdshaders/cloak_ps2x.fxc | 201 + materialsystem/stdshaders/cloak_vs20.fxc | 147 + materialsystem/stdshaders/cloud.cpp | 76 + materialsystem/stdshaders/cloud_dx8.cpp | 77 + materialsystem/stdshaders/cloud_dx9.cpp | 94 + materialsystem/stdshaders/cloud_ps11.psh | 6 + materialsystem/stdshaders/cloud_ps20.fxc | 26 + materialsystem/stdshaders/cloud_vs11.vsh | 26 + materialsystem/stdshaders/cloud_vs20.fxc | 37 + materialsystem/stdshaders/color_projection.cpp | 290 + .../stdshaders/color_projection_ps2x.fxc | 133 + .../stdshaders/color_projection_vs20.fxc | 24 + materialsystem/stdshaders/colorcorrection.cpp | 151 + materialsystem/stdshaders/colorcorrection_ps2x.fxc | 55 + materialsystem/stdshaders/commandbuilder.h | 407 + materialsystem/stdshaders/common_flashlight_fxc.h | 821 ++ materialsystem/stdshaders/common_fxc.h | 326 + materialsystem/stdshaders/common_fxc2.h | 19 + materialsystem/stdshaders/common_hlsl_cpp_consts.h | 27 + .../stdshaders/common_lightmappedgeneric_fxc.h | 202 + materialsystem/stdshaders/common_pragmas.h | 38 + materialsystem/stdshaders/common_ps_fxc.h | 804 ++ .../stdshaders/common_vertexlitgeneric_dx9.h | 423 + .../stdshaders/common_vertexlitgeneric_vs20.fxc | 0 materialsystem/stdshaders/common_vs_fxc.h | 955 ++ materialsystem/stdshaders/compositor.cpp | 455 + materialsystem/stdshaders/compositor_ps2x.fxc | 340 + materialsystem/stdshaders/compositor_vs20.fxc | 41 + materialsystem/stdshaders/constant_color_ps2x.fxc | 26 + materialsystem/stdshaders/copy_fp_rt_ps2x.fxc | 21 + materialsystem/stdshaders/core_dx7.cpp | 43 + materialsystem/stdshaders/core_dx8.cpp | 249 + materialsystem/stdshaders/core_dx9.cpp | 298 + materialsystem/stdshaders/core_ps11.psh | 27 + materialsystem/stdshaders/core_ps2x.fxc | 218 + materialsystem/stdshaders/core_vs11.fxc | 156 + materialsystem/stdshaders/core_vs20.fxc | 103 + .../stdshaders/cpp_shader_constant_register_map.h | 45 + materialsystem/stdshaders/debugdepth.cpp | 113 + materialsystem/stdshaders/debugluxel.cpp | 97 + materialsystem/stdshaders/debugluxel_ps2x.fxc | 15 + materialsystem/stdshaders/debugluxel_vs20.fxc | 40 + materialsystem/stdshaders/debugmodifyvertex.cpp | 93 + .../stdshaders/debugmorphaccumulator_dx9.cpp | 64 + .../stdshaders/debugmorphaccumulator_ps30.fxc | 16 + .../stdshaders/debugmorphaccumulator_vs30.fxc | 23 + materialsystem/stdshaders/debugmrttexture.cpp | 86 + materialsystem/stdshaders/debugmrttexture_ps2x.fxc | 26 + materialsystem/stdshaders/debugmrttexture_vs20.fxc | 29 + materialsystem/stdshaders/debugnormalmap.cpp | 148 + .../stdshaders/debugsoftwarevertexshader.cpp | 56 + materialsystem/stdshaders/debugtangentspace.cpp | 133 + materialsystem/stdshaders/debugtangentspace.vsh | 34 + .../stdshaders/debugtangentspace_vs11.fxc | 51 + .../stdshaders/debugtangentspace_vs20.fxc | 55 + materialsystem/stdshaders/decal.cpp | 127 + ...lbasetimeslightmapalphablendselfillum2_ps2x.fxc | 26 + materialsystem/stdshaders/decalmodulate.cpp | 63 + materialsystem/stdshaders/decalmodulate_dx8.cpp | 86 + materialsystem/stdshaders/decalmodulate_ps11.psh | 4 + materialsystem/stdshaders/decalmodulate_ps2x.fxc | 45 + materialsystem/stdshaders/decalmodulate_vs11.vsh | 8 + .../stdshaders/depthtodestalpha_ps20b.fxc | 11 + .../stdshaders/depthtodestalpha_vs20.fxc | 23 + materialsystem/stdshaders/depthwrite.cpp | 207 + materialsystem/stdshaders/depthwrite_ps2x.fxc | 44 + materialsystem/stdshaders/depthwrite_vs20.fxc | 83 + materialsystem/stdshaders/detail.cpp | 37 + materialsystem/stdshaders/detail_ps11.psh | 12 + materialsystem/stdshaders/detail_vs11.vsh | 56 + materialsystem/stdshaders/downsample_nohdr.cpp | 135 + .../stdshaders/downsample_nohdr_dx80.cpp | 81 + materialsystem/stdshaders/dx8fallbacks.cpp | 14 + .../emissive_scroll_blended_pass_dx8_helper.cpp | 201 + .../emissive_scroll_blended_pass_dx8_ps11.psh | 20 + .../emissive_scroll_blended_pass_dx8_vs11.vsh | 61 + .../emissive_scroll_blended_pass_helper.cpp | 278 + .../emissive_scroll_blended_pass_helper.h | 45 + .../emissive_scroll_blended_pass_ps2x.fxc | 51 + .../emissive_scroll_blended_pass_vs20.fxc | 68 + materialsystem/stdshaders/example_model_dx9.cpp | 60 + .../stdshaders/example_model_dx9_helper.cpp | 341 + .../stdshaders/example_model_dx9_helper.h | 46 + materialsystem/stdshaders/example_model_ps20b.fxc | 92 + materialsystem/stdshaders/example_model_vs20.fxc | 91 + materialsystem/stdshaders/eye_refract.cpp | 253 + materialsystem/stdshaders/eye_refract_helper.cpp | 461 + materialsystem/stdshaders/eye_refract_helper.h | 69 + materialsystem/stdshaders/eye_refract_ps2x.fxc | 494 + materialsystem/stdshaders/eye_refract_vs20.fxc | 217 + materialsystem/stdshaders/eyeball.cpp | 37 + materialsystem/stdshaders/eyeglint_dx9.cpp | 66 + materialsystem/stdshaders/eyeglint_ps2x.fxc | 32 + materialsystem/stdshaders/eyeglint_vs20.fxc | 38 + materialsystem/stdshaders/eyes.cpp | 186 + materialsystem/stdshaders/eyes.vsh | 80 + materialsystem/stdshaders/eyes_dx6.cpp | 251 + materialsystem/stdshaders/eyes_dx8_dx9_helper.cpp | 550 + materialsystem/stdshaders/eyes_dx8_dx9_helper.h | 54 + materialsystem/stdshaders/eyes_dx9.cpp | 84 + .../stdshaders/eyes_flashlight2_ps11.psh | 17 + materialsystem/stdshaders/eyes_flashlight_inc.fxc | 92 + materialsystem/stdshaders/eyes_flashlight_ps11.fxc | 9 + materialsystem/stdshaders/eyes_flashlight_ps2x.fxc | 15 + materialsystem/stdshaders/eyes_flashlight_vs11.vsh | 115 + materialsystem/stdshaders/eyes_flashlight_vs20.fxc | 145 + materialsystem/stdshaders/eyes_ps2x.fxc | 68 + materialsystem/stdshaders/fillrate.cpp | 251 + materialsystem/stdshaders/fillrate.psh | 12 + materialsystem/stdshaders/fillrate.vsh | 35 + materialsystem/stdshaders/fillrate_ps11.fxc | 6 + materialsystem/stdshaders/fillrate_ps2x.fxc | 13 + materialsystem/stdshaders/fillrate_vs11.fxc | 33 + materialsystem/stdshaders/fillrate_vs20.fxc | 32 + materialsystem/stdshaders/filmdust_dx7.cpp | 67 + materialsystem/stdshaders/filmdust_dx8_dx9.cpp | 111 + materialsystem/stdshaders/filmdust_ps11.fxc | 18 + materialsystem/stdshaders/filmdust_ps20.fxc | 18 + materialsystem/stdshaders/filmgrain_dx7.cpp | 62 + materialsystem/stdshaders/filmgrain_dx8_dx9.cpp | 113 + materialsystem/stdshaders/filmgrain_ps11.fxc | 21 + materialsystem/stdshaders/filmgrain_ps20.fxc | 21 + materialsystem/stdshaders/filmgrain_vs20.fxc | 32 + materialsystem/stdshaders/flashlight_ps11.fxc | 69 + materialsystem/stdshaders/flashlight_ps2x.fxc | 235 + .../flesh_interior_blended_pass_dx8_helper.cpp | 271 + .../flesh_interior_blended_pass_dx8_ps11.psh | 15 + .../flesh_interior_blended_pass_dx8_vs11.vsh | 114 + .../flesh_interior_blended_pass_helper.cpp | 355 + .../flesh_interior_blended_pass_helper.h | 68 + .../flesh_interior_blended_pass_ps2x.fxc | 127 + .../flesh_interior_blended_pass_vs20.fxc | 155 + materialsystem/stdshaders/floatcombine.cpp | 118 + .../stdshaders/floatcombine_autoexpose.cpp | 123 + .../stdshaders/floatcombine_autoexpose_ps2x.fxc | 48 + materialsystem/stdshaders/floatcombine_ps2x.fxc | 60 + materialsystem/stdshaders/floattoscreen.cpp | 93 + .../stdshaders/floattoscreen_notonemap_ps2x.fxc | 38 + materialsystem/stdshaders/floattoscreen_ps2x.fxc | 21 + .../stdshaders/floattoscreen_vanilla.cpp | 88 + .../stdshaders/floattoscreen_vanilla_ps2x.fxc | 19 + materialsystem/stdshaders/fxctmp9/Bloom_ps20.inc | 33 + materialsystem/stdshaders/fxctmp9/Bloom_ps20b.inc | 60 + .../stdshaders/fxctmp9/BlurFilter_ps20.inc | 33 + .../stdshaders/fxctmp9/BlurFilter_ps20b.inc | 85 + .../stdshaders/fxctmp9/BlurFilter_vs11.inc | 33 + .../stdshaders/fxctmp9/BlurFilter_vs20.inc | 33 + .../stdshaders/fxctmp9/Downsample_nohdr_ps20.inc | 60 + .../stdshaders/fxctmp9/Downsample_nohdr_ps20b.inc | 110 + .../stdshaders/fxctmp9/Downsample_ps20.inc | 33 + .../stdshaders/fxctmp9/Downsample_ps20b.inc | 60 + .../stdshaders/fxctmp9/Downsample_vs11.inc | 33 + .../stdshaders/fxctmp9/Downsample_vs20.inc | 33 + .../stdshaders/fxctmp9/HDRCombineTo16Bit_ps20.inc | 33 + .../stdshaders/fxctmp9/HDRCombineTo16Bit_ps20b.inc | 60 + .../stdshaders/fxctmp9/HDRCombineTo16Bit_vs20.inc | 33 + .../stdshaders/fxctmp9/HDRSelectRange_ps20.inc | 33 + .../stdshaders/fxctmp9/HDRSelectRange_ps20b.inc | 60 + .../stdshaders/fxctmp9/HDRSelectRange_vs20.inc | 33 + .../fxctmp9/IntroScreenSpaceEffect_ps20.inc | 60 + .../fxctmp9/IntroScreenSpaceEffect_ps20b.inc | 112 + .../stdshaders/fxctmp9/ParticleSphere_ps11.inc | 33 + .../stdshaders/fxctmp9/ParticleSphere_vs11.inc | 60 + materialsystem/stdshaders/fxctmp9/Refract_ps20.inc | 262 + .../stdshaders/fxctmp9/Refract_ps20b.inc | 337 + materialsystem/stdshaders/fxctmp9/Refract_vs20.inc | 137 + .../stdshaders/fxctmp9/ShatteredGlass_ps20.inc | 212 + .../stdshaders/fxctmp9/ShatteredGlass_ps20b.inc | 237 + .../stdshaders/fxctmp9/ShatteredGlass_vs20.inc | 87 + .../VertexLit_and_unlit_Generic_bump_vs20.inc | 212 + .../fxctmp9/VertexLit_and_unlit_Generic_vs20.inc | 462 + .../stdshaders/fxctmp9/WaterCheap_ps20.inc | 237 + .../stdshaders/fxctmp9/WaterCheap_ps20b.inc | 262 + .../stdshaders/fxctmp9/WaterCheap_vs20.inc | 60 + materialsystem/stdshaders/fxctmp9/Water_ps20.inc | 212 + materialsystem/stdshaders/fxctmp9/Water_vs20.inc | 85 + .../fxctmp9/WorldTwoTextureBlend_ps20.inc | 287 + .../fxctmp9/WorldTwoTextureBlend_ps20b.inc | 387 + .../stdshaders/fxctmp9/accumbuff4sample_ps20.inc | 33 + .../stdshaders/fxctmp9/accumbuff4sample_ps20b.inc | 60 + .../stdshaders/fxctmp9/accumbuff5sample_ps20.inc | 33 + .../stdshaders/fxctmp9/accumbuff5sample_ps20b.inc | 60 + .../stdshaders/fxctmp9/aftershock_ps20.inc | 33 + .../stdshaders/fxctmp9/aftershock_ps20b.inc | 60 + .../stdshaders/fxctmp9/aftershock_vs20.inc | 85 + .../stdshaders/fxctmp9/alphadist_ps11.inc | 33 + .../stdshaders/fxctmp9/appchooser360movie_ps20.inc | 33 + .../fxctmp9/appchooser360movie_ps20b.inc | 33 + materialsystem/stdshaders/fxctmp9/bik_ps20.inc | 60 + materialsystem/stdshaders/fxctmp9/bik_ps20b.inc | 87 + materialsystem/stdshaders/fxctmp9/bik_vs20.inc | 60 + .../stdshaders/fxctmp9/bloomadd_ps11.inc | 33 + .../stdshaders/fxctmp9/bloomadd_ps20.inc | 33 + .../stdshaders/fxctmp9/bloomadd_ps20b.inc | 33 + .../fxctmp9/bufferclearobeystencil_ps20.inc | 33 + .../fxctmp9/bufferclearobeystencil_ps20b.inc | 60 + .../fxctmp9/bufferclearobeystencil_vs20.inc | 60 + .../stdshaders/fxctmp9/bumpmappedlightmap_vs11.inc | 60 + materialsystem/stdshaders/fxctmp9/cable_ps20.inc | 60 + materialsystem/stdshaders/fxctmp9/cable_ps20b.inc | 112 + materialsystem/stdshaders/fxctmp9/cable_vs20.inc | 60 + .../stdshaders/fxctmp9/cloak_blended_pass_ps20.inc | 60 + .../fxctmp9/cloak_blended_pass_ps20b.inc | 85 + .../stdshaders/fxctmp9/cloak_blended_pass_ps30.inc | 85 + .../stdshaders/fxctmp9/cloak_blended_pass_vs20.inc | 112 + .../stdshaders/fxctmp9/cloak_blended_pass_vs30.inc | 137 + materialsystem/stdshaders/fxctmp9/cloak_ps20.inc | 137 + materialsystem/stdshaders/fxctmp9/cloak_ps20b.inc | 162 + materialsystem/stdshaders/fxctmp9/cloak_ps30.inc | 162 + materialsystem/stdshaders/fxctmp9/cloak_vs20.inc | 187 + materialsystem/stdshaders/fxctmp9/cloak_vs30.inc | 162 + materialsystem/stdshaders/fxctmp9/cloud_ps20.inc | 33 + materialsystem/stdshaders/fxctmp9/cloud_vs20.inc | 33 + .../stdshaders/fxctmp9/color_projection_ps20.inc | 110 + .../stdshaders/fxctmp9/color_projection_ps20b.inc | 110 + .../stdshaders/fxctmp9/color_projection_vs20.inc | 33 + .../stdshaders/fxctmp9/colorcorrection_ps20.inc | 60 + .../stdshaders/fxctmp9/colorcorrection_ps20b.inc | 87 + .../stdshaders/fxctmp9/compositor_ps20.inc | 87 + .../stdshaders/fxctmp9/compositor_ps20b.inc | 87 + .../stdshaders/fxctmp9/compositor_vs20.inc | 33 + .../stdshaders/fxctmp9/constant_color_ps20.inc | 33 + .../stdshaders/fxctmp9/constant_color_ps20b.inc | 60 + .../stdshaders/fxctmp9/copy_fp_rt_ps20.inc | 33 + .../stdshaders/fxctmp9/copy_fp_rt_ps20b.inc | 60 + materialsystem/stdshaders/fxctmp9/core_ps20.inc | 162 + materialsystem/stdshaders/fxctmp9/core_ps20b.inc | 187 + materialsystem/stdshaders/fxctmp9/core_vs11.inc | 60 + materialsystem/stdshaders/fxctmp9/core_vs20.inc | 112 + .../fxctmp9/debugbumpmappedlightmap_ps11.inc | 59 + .../fxctmp9/debugbumpmappedlightmap_ps20.inc | 59 + .../fxctmp9/debugbumpmappedlightmap_ps20b.inc | 59 + .../stdshaders/fxctmp9/debugdrawdepth_ps20.inc | 33 + .../stdshaders/fxctmp9/debugdrawdepth_ps20b.inc | 60 + .../stdshaders/fxctmp9/debugdrawdepth_vs20.inc | 85 + .../fxctmp9/debugdrawenvmapmask_ps20.inc | 60 + .../fxctmp9/debugdrawenvmapmask_ps20b.inc | 87 + .../fxctmp9/debugdrawenvmapmask_vs20.inc | 85 + .../stdshaders/fxctmp9/debugluxel_ps20.inc | 33 + .../stdshaders/fxctmp9/debugluxel_ps20b.inc | 33 + .../stdshaders/fxctmp9/debugluxel_vs20.inc | 33 + .../fxctmp9/debugmorphaccumulator_ps30.inc | 33 + .../fxctmp9/debugmorphaccumulator_vs30.inc | 33 + .../stdshaders/fxctmp9/debugmrttexture_ps20.inc | 60 + .../stdshaders/fxctmp9/debugmrttexture_ps20b.inc | 85 + .../stdshaders/fxctmp9/debugmrttexture_vs20.inc | 33 + .../stdshaders/fxctmp9/debugtangentspace_vs11.inc | 85 + .../stdshaders/fxctmp9/debugtangentspace_vs20.inc | 110 + .../stdshaders/fxctmp9/debugtextureview_ps20.inc | 87 + .../stdshaders/fxctmp9/debugtextureview_ps20b.inc | 112 + .../stdshaders/fxctmp9/debugtextureview_vs20.inc | 60 + ...lbasetimeslightmapalphablendselfillum2_ps20.inc | 60 + ...basetimeslightmapalphablendselfillum2_ps20b.inc | 87 + .../stdshaders/fxctmp9/decalmodulate_ps20.inc | 60 + .../stdshaders/fxctmp9/decalmodulate_ps20b.inc | 87 + .../stdshaders/fxctmp9/decalmodulate_ps30.inc | 87 + .../stdshaders/fxctmp9/depthtodestalpha_ps20b.inc | 33 + .../stdshaders/fxctmp9/depthtodestalpha_vs20.inc | 33 + .../stdshaders/fxctmp9/depthwrite_ps20.inc | 87 + .../stdshaders/fxctmp9/depthwrite_ps20b.inc | 87 + .../stdshaders/fxctmp9/depthwrite_ps30.inc | 87 + .../stdshaders/fxctmp9/depthwrite_vs20.inc | 137 + .../stdshaders/fxctmp9/depthwrite_vs30.inc | 162 + .../fxctmp9/emissive_scroll_blended_pass_ps20.inc | 33 + .../fxctmp9/emissive_scroll_blended_pass_ps20b.inc | 60 + .../fxctmp9/emissive_scroll_blended_pass_ps30.inc | 60 + .../fxctmp9/emissive_scroll_blended_pass_vs20.inc | 85 + .../fxctmp9/emissive_scroll_blended_pass_vs30.inc | 110 + .../stdshaders/fxctmp9/engine_post_ps20.inc | 135 + .../stdshaders/fxctmp9/engine_post_ps20b.inc | 212 + .../stdshaders/fxctmp9/example_model_ps20b.inc | 237 + .../stdshaders/fxctmp9/example_model_vs20.inc | 160 + .../stdshaders/fxctmp9/eye_refract_ps20.inc | 112 + .../stdshaders/fxctmp9/eye_refract_ps20b.inc | 212 + .../stdshaders/fxctmp9/eye_refract_ps30.inc | 212 + .../stdshaders/fxctmp9/eye_refract_vs20.inc | 287 + .../stdshaders/fxctmp9/eye_refract_vs30.inc | 312 + .../stdshaders/fxctmp9/eyeglint_ps20.inc | 33 + .../stdshaders/fxctmp9/eyeglint_ps20b.inc | 33 + .../stdshaders/fxctmp9/eyeglint_vs20.inc | 33 + .../stdshaders/fxctmp9/eyes_cloak_ps20b.inc | 262 + .../stdshaders/fxctmp9/eyes_cloak_vs20b.inc | 187 + .../stdshaders/fxctmp9/eyes_flashlight_ps11.inc | 33 + .../stdshaders/fxctmp9/eyes_flashlight_ps20.inc | 60 + .../stdshaders/fxctmp9/eyes_flashlight_ps20b.inc | 112 + .../stdshaders/fxctmp9/eyes_flashlight_ps30.inc | 112 + .../stdshaders/fxctmp9/eyes_flashlight_vs20.inc | 110 + .../stdshaders/fxctmp9/eyes_flashlight_vs30.inc | 135 + materialsystem/stdshaders/fxctmp9/eyes_ps20.inc | 60 + materialsystem/stdshaders/fxctmp9/eyes_ps20b.inc | 85 + materialsystem/stdshaders/fxctmp9/eyes_ps30.inc | 85 + materialsystem/stdshaders/fxctmp9/eyes_vs20.inc | 262 + materialsystem/stdshaders/fxctmp9/eyes_vs30.inc | 237 + .../stdshaders/fxctmp9/fillrate_ps11.inc | 33 + .../stdshaders/fxctmp9/fillrate_ps20.inc | 33 + .../stdshaders/fxctmp9/fillrate_ps20b.inc | 60 + .../stdshaders/fxctmp9/fillrate_vs11.inc | 85 + .../stdshaders/fxctmp9/fillrate_vs20.inc | 85 + .../stdshaders/fxctmp9/filmdust_ps11.inc | 33 + .../stdshaders/fxctmp9/filmdust_ps20.inc | 33 + .../stdshaders/fxctmp9/filmgrain_ps11.inc | 33 + .../stdshaders/fxctmp9/filmgrain_ps20.inc | 33 + .../stdshaders/fxctmp9/filmgrain_vs20.inc | 33 + .../stdshaders/fxctmp9/flashlight_ps11.inc | 85 + .../stdshaders/fxctmp9/flashlight_ps20.inc | 212 + .../stdshaders/fxctmp9/flashlight_ps20b.inc | 262 + .../fxctmp9/flesh_interior_blended_pass_ps20.inc | 33 + .../fxctmp9/flesh_interior_blended_pass_ps20b.inc | 60 + .../fxctmp9/flesh_interior_blended_pass_vs20.inc | 237 + .../fxctmp9/floatcombine_autoexpose_ps20.inc | 33 + .../fxctmp9/floatcombine_autoexpose_ps20b.inc | 60 + .../stdshaders/fxctmp9/floatcombine_ps20.inc | 33 + .../stdshaders/fxctmp9/floatcombine_ps20b.inc | 60 + .../fxctmp9/floattoscreen_notonemap_ps20.inc | 33 + .../fxctmp9/floattoscreen_notonemap_ps20b.inc | 60 + .../stdshaders/fxctmp9/floattoscreen_ps20.inc | 33 + .../stdshaders/fxctmp9/floattoscreen_ps20b.inc | 60 + .../fxctmp9/floattoscreen_vanilla_ps20.inc | 33 + .../fxctmp9/floattoscreen_vanilla_ps20b.inc | 60 + .../stdshaders/fxctmp9/haloadd1d_ps20.inc | 33 + .../stdshaders/fxctmp9/haloadd1d_ps20b.inc | 33 + materialsystem/stdshaders/fxctmp9/haloadd_ps20.inc | 33 + .../stdshaders/fxctmp9/haloadd_ps20b.inc | 33 + .../stdshaders/fxctmp9/haloaddoutline_ps20.inc | 33 + .../stdshaders/fxctmp9/haloaddoutline_ps20b.inc | 33 + .../fxctmp9/hsl_filmgrain_pass1_ps20.inc | 33 + .../fxctmp9/hsl_filmgrain_pass1_ps20b.inc | 60 + .../fxctmp9/hsl_filmgrain_pass2_ps20.inc | 33 + .../fxctmp9/hsl_filmgrain_pass2_ps20b.inc | 60 + materialsystem/stdshaders/fxctmp9/hsv_ps20.inc | 33 + materialsystem/stdshaders/fxctmp9/hsv_ps20b.inc | 60 + .../fxctmp9/introscreenspaceeffect_ps11.inc | 60 + .../stdshaders/fxctmp9/lightingonly_vs20.inc | 161 + .../fxctmp9/lightmappedgeneric_decal_ps20.inc | 60 + .../fxctmp9/lightmappedgeneric_decal_ps20b.inc | 87 + .../fxctmp9/lightmappedgeneric_decal_vs20.inc | 60 + .../fxctmp9/lightmappedgeneric_flashlight_vs11.inc | 137 + .../fxctmp9/lightmappedgeneric_flashlight_vs20.inc | 162 + ...mappedgeneric_lightingonly_overbright2_ps11.inc | 33 + .../lightmappedgeneric_lightingonly_vs11.inc | 60 + .../stdshaders/fxctmp9/lightmappedgeneric_ps20.inc | 712 + .../fxctmp9/lightmappedgeneric_ps20b.inc | 762 + .../stdshaders/fxctmp9/lightmappedgeneric_vs20.inc | 337 + .../fxctmp9/lightmappedreflective_ps20.inc | 162 + .../fxctmp9/lightmappedreflective_ps20b.inc | 212 + .../fxctmp9/lightmappedreflective_vs20.inc | 60 + .../stdshaders/fxctmp9/lpreview1_ps20.inc | 33 + .../stdshaders/fxctmp9/lpreview1_ps20b.inc | 60 + .../stdshaders/fxctmp9/lpreview_output_ps20.inc | 33 + .../stdshaders/fxctmp9/lpreview_output_ps20b.inc | 60 + .../stdshaders/fxctmp9/luminance_compare_ps20.inc | 33 + .../stdshaders/fxctmp9/luminance_compare_ps20b.inc | 60 + .../stdshaders/fxctmp9/modulate_ps20.inc | 60 + .../stdshaders/fxctmp9/modulate_ps20b.inc | 112 + .../stdshaders/fxctmp9/monitorscreen_ps20.inc | 87 + .../stdshaders/fxctmp9/monitorscreen_ps20b.inc | 137 + .../stdshaders/fxctmp9/morphaccumulate_ps30.inc | 60 + .../stdshaders/fxctmp9/morphaccumulate_vs30.inc | 60 + .../stdshaders/fxctmp9/morphweight_ps30.inc | 33 + .../stdshaders/fxctmp9/morphweight_vs30.inc | 33 + .../stdshaders/fxctmp9/motion_blur_ps20.inc | 60 + .../stdshaders/fxctmp9/motion_blur_ps20b.inc | 87 + .../stdshaders/fxctmp9/motion_blur_vs20.inc | 33 + .../fxctmp9/particlelit_generic_ps30.inc | 186 + .../fxctmp9/particlelit_generic_vs30.inc | 59 + .../stdshaders/fxctmp9/particlesphere_ps20.inc | 60 + .../stdshaders/fxctmp9/particlesphere_ps20b.inc | 112 + .../stdshaders/fxctmp9/particlesphere_vs20.inc | 60 + materialsystem/stdshaders/fxctmp9/portal_ps11.inc | 162 + materialsystem/stdshaders/fxctmp9/portal_ps20.inc | 162 + materialsystem/stdshaders/fxctmp9/portal_ps20b.inc | 187 + .../stdshaders/fxctmp9/portal_refract_ps11.inc | 60 + .../stdshaders/fxctmp9/portal_refract_ps20.inc | 60 + .../stdshaders/fxctmp9/portal_refract_ps20b.inc | 137 + .../stdshaders/fxctmp9/portal_refract_vs11.inc | 60 + .../stdshaders/fxctmp9/portal_refract_vs20.inc | 60 + materialsystem/stdshaders/fxctmp9/portal_vs11.inc | 187 + materialsystem/stdshaders/fxctmp9/portal_vs20.inc | 162 + .../fxctmp9/portalstaticoverlay_ps11.inc | 137 + .../fxctmp9/portalstaticoverlay_ps20.inc | 137 + .../fxctmp9/portalstaticoverlay_ps20b.inc | 162 + .../fxctmp9/portalstaticoverlay_vs11.inc | 87 + .../fxctmp9/portalstaticoverlay_vs20.inc | 87 + .../stdshaders/fxctmp9/pyro_vision_ps20.inc | 312 + .../stdshaders/fxctmp9/pyro_vision_ps20b.inc | 312 + .../stdshaders/fxctmp9/pyro_vision_ps30.inc | 312 + .../stdshaders/fxctmp9/pyro_vision_vs20.inc | 387 + .../stdshaders/fxctmp9/pyro_vision_vs30.inc | 337 + .../stdshaders/fxctmp9/rendertargetblit_ps20.inc | 33 + .../stdshaders/fxctmp9/rendertargetblit_ps20b.inc | 33 + .../stdshaders/fxctmp9/rendertargetblit_vs20.inc | 33 + .../stdshaders/fxctmp9/sample4x4_blend_ps20.inc | 33 + .../stdshaders/fxctmp9/sample4x4_blend_ps20b.inc | 60 + .../stdshaders/fxctmp9/sample4x4_ps20.inc | 33 + .../stdshaders/fxctmp9/sample4x4_ps20b.inc | 60 + .../stdshaders/fxctmp9/sample4x4delog_ps20.inc | 33 + .../stdshaders/fxctmp9/sample4x4delog_ps20b.inc | 60 + .../stdshaders/fxctmp9/sample4x4log_ps20.inc | 33 + .../stdshaders/fxctmp9/sample4x4log_ps20b.inc | 60 + .../stdshaders/fxctmp9/sample4x4maxmin_ps20.inc | 33 + .../stdshaders/fxctmp9/sample4x4maxmin_ps20b.inc | 60 + .../stdshaders/fxctmp9/screenspaceeffect_vs11.inc | 33 + .../stdshaders/fxctmp9/screenspaceeffect_vs20.inc | 60 + .../stdshaders/fxctmp9/sfm_combine_vs20.inc | 33 + .../stdshaders/fxctmp9/sfm_integercombine_ps20.inc | 33 + .../fxctmp9/sfm_integercombine_ps20b.inc | 60 + materialsystem/stdshaders/fxctmp9/shadow_ps20.inc | 60 + materialsystem/stdshaders/fxctmp9/shadow_ps20b.inc | 87 + materialsystem/stdshaders/fxctmp9/shadow_vs20.inc | 60 + .../stdshaders/fxctmp9/shadowbuildtexture_ps20.inc | 33 + .../fxctmp9/shadowbuildtexture_ps20b.inc | 60 + .../stdshaders/fxctmp9/shadowmodel_ps20.inc | 33 + .../stdshaders/fxctmp9/shadowmodel_vs20.inc | 85 + materialsystem/stdshaders/fxctmp9/showz_ps20.inc | 60 + materialsystem/stdshaders/fxctmp9/showz_ps20b.inc | 85 + materialsystem/stdshaders/fxctmp9/showz_vs20.inc | 33 + materialsystem/stdshaders/fxctmp9/skin_ps20.inc | 261 + materialsystem/stdshaders/fxctmp9/skin_ps20b.inc | 537 + materialsystem/stdshaders/fxctmp9/skin_ps30.inc | 537 + materialsystem/stdshaders/fxctmp9/skin_ps30b.inc | 387 + materialsystem/stdshaders/fxctmp9/skin_vs20.inc | 187 + materialsystem/stdshaders/fxctmp9/skin_vs30.inc | 187 + .../stdshaders/fxctmp9/sky_hdr_compressed_ps20.inc | 33 + .../fxctmp9/sky_hdr_compressed_ps20b.inc | 87 + .../fxctmp9/sky_hdr_compressed_rgbs_ps20.inc | 33 + .../fxctmp9/sky_hdr_compressed_rgbs_ps20b.inc | 87 + materialsystem/stdshaders/fxctmp9/sky_ps20.inc | 33 + materialsystem/stdshaders/fxctmp9/sky_ps20b.inc | 87 + materialsystem/stdshaders/fxctmp9/sky_vs20.inc | 33 + .../stdshaders/fxctmp9/splinecard_vs11.inc | 33 + .../stdshaders/fxctmp9/splinecard_vs20.inc | 33 + materialsystem/stdshaders/fxctmp9/sprite_ps20.inc | 187 + materialsystem/stdshaders/fxctmp9/sprite_ps20b.inc | 237 + materialsystem/stdshaders/fxctmp9/sprite_vs20.inc | 112 + .../stdshaders/fxctmp9/spritecard_ps11.inc | 110 + .../stdshaders/fxctmp9/spritecard_ps20.inc | 260 + .../stdshaders/fxctmp9/spritecard_ps20b.inc | 310 + .../stdshaders/fxctmp9/spritecard_vs11.inc | 137 + .../stdshaders/fxctmp9/spritecard_vs20.inc | 162 + .../stdshaders/fxctmp9/teeth_bump_ps20.inc | 110 + .../stdshaders/fxctmp9/teeth_bump_ps20b.inc | 162 + .../stdshaders/fxctmp9/teeth_bump_ps30.inc | 162 + .../stdshaders/fxctmp9/teeth_bump_vs20.inc | 212 + .../stdshaders/fxctmp9/teeth_bump_vs30.inc | 187 + .../stdshaders/fxctmp9/teeth_flashlight_ps20.inc | 60 + .../stdshaders/fxctmp9/teeth_flashlight_ps20b.inc | 137 + .../stdshaders/fxctmp9/teeth_flashlight_ps30.inc | 137 + .../stdshaders/fxctmp9/teeth_flashlight_vs20.inc | 137 + .../stdshaders/fxctmp9/teeth_flashlight_vs30.inc | 162 + materialsystem/stdshaders/fxctmp9/teeth_ps20.inc | 60 + materialsystem/stdshaders/fxctmp9/teeth_ps20b.inc | 112 + materialsystem/stdshaders/fxctmp9/teeth_ps30.inc | 112 + materialsystem/stdshaders/fxctmp9/teeth_vs20.inc | 237 + materialsystem/stdshaders/fxctmp9/teeth_vs30.inc | 212 + .../stdshaders/fxctmp9/treeleaf_ps20.inc | 33 + .../stdshaders/fxctmp9/treeleaf_ps20b.inc | 60 + .../stdshaders/fxctmp9/treeleaf_vs20.inc | 162 + .../fxctmp9/unlitgeneric_lightingonly_vs11.inc | 84 + .../unlitgeneric_maskbasebydetailalpha_ps11.inc | 33 + .../fxctmp9/unlitgeneric_notexture_ps11.inc | 33 + .../fxctmp9/unlitgeneric_notexture_ps20.inc | 33 + .../fxctmp9/unlitgeneric_notexture_ps20b.inc | 60 + .../stdshaders/fxctmp9/unlitgeneric_ps11.inc | 33 + .../stdshaders/fxctmp9/unlitgeneric_ps20.inc | 33 + .../stdshaders/fxctmp9/unlitgeneric_ps20b.inc | 60 + .../stdshaders/fxctmp9/unlitgeneric_vs20.inc | 137 + .../stdshaders/fxctmp9/unlittwotexture_ps20.inc | 85 + .../stdshaders/fxctmp9/unlittwotexture_ps20b.inc | 137 + .../stdshaders/fxctmp9/unlittwotexture_vs20.inc | 110 + .../vertexlit_and_unlit_generic_bump_ps20.inc | 412 + .../vertexlit_and_unlit_generic_bump_ps20b.inc | 412 + .../vertexlit_and_unlit_generic_bump_ps30.inc | 412 + .../vertexlit_and_unlit_generic_bump_vs30.inc | 212 + .../fxctmp9/vertexlit_and_unlit_generic_ps20.inc | 587 + .../fxctmp9/vertexlit_and_unlit_generic_ps20b.inc | 687 + .../fxctmp9/vertexlit_and_unlit_generic_ps30.inc | 662 + .../fxctmp9/vertexlit_and_unlit_generic_vs30.inc | 462 + .../fxctmp9/vertexlit_lighting_only_ps20.inc | 137 + .../fxctmp9/vertexlit_lighting_only_ps20b.inc | 162 + ...texlitgeneric_lightingonly_overbright2_ps11.inc | 33 + .../stdshaders/fxctmp9/volume_clouds_ps20.inc | 33 + .../stdshaders/fxctmp9/volume_clouds_ps20b.inc | 60 + .../stdshaders/fxctmp9/volume_clouds_vs20.inc | 85 + .../stdshaders/fxctmp9/vortwarp_ps20.inc | 337 + .../stdshaders/fxctmp9/vortwarp_ps20b.inc | 362 + .../stdshaders/fxctmp9/vortwarp_ps30.inc | 362 + .../stdshaders/fxctmp9/vortwarp_vs20.inc | 187 + .../stdshaders/fxctmp9/vortwarp_vs30.inc | 162 + .../stdshaders/fxctmp9/vr_distort_hud_ps20.inc | 60 + .../stdshaders/fxctmp9/vr_distort_hud_ps20b.inc | 60 + .../stdshaders/fxctmp9/vr_distort_hud_ps30.inc | 60 + .../stdshaders/fxctmp9/vr_distort_hud_vs20.inc | 33 + .../stdshaders/fxctmp9/vr_distort_hud_vs30.inc | 33 + .../stdshaders/fxctmp9/vr_distort_texture_ps20.inc | 60 + .../fxctmp9/vr_distort_texture_ps20b.inc | 60 + .../stdshaders/fxctmp9/vr_distort_texture_ps30.inc | 60 + .../stdshaders/fxctmp9/vr_distort_texture_vs20.inc | 33 + .../stdshaders/fxctmp9/vr_distort_texture_vs30.inc | 33 + materialsystem/stdshaders/fxctmp9/warp_ps20.inc | 60 + materialsystem/stdshaders/fxctmp9/warp_ps20b.inc | 60 + materialsystem/stdshaders/fxctmp9/warp_ps30.inc | 60 + materialsystem/stdshaders/fxctmp9/warp_vs20.inc | 33 + materialsystem/stdshaders/fxctmp9/warp_vs30.inc | 33 + materialsystem/stdshaders/fxctmp9/water_ps20b.inc | 287 + .../stdshaders/fxctmp9/weapon_sheen_pass_ps20.inc | 60 + .../stdshaders/fxctmp9/weapon_sheen_pass_ps20b.inc | 85 + .../stdshaders/fxctmp9/weapon_sheen_pass_ps30.inc | 85 + .../stdshaders/fxctmp9/weapon_sheen_pass_vs20.inc | 112 + .../stdshaders/fxctmp9/weapon_sheen_pass_vs30.inc | 137 + materialsystem/stdshaders/fxctmp9/white_ps20.inc | 33 + materialsystem/stdshaders/fxctmp9/white_ps20b.inc | 60 + .../stdshaders/fxctmp9/windowimposter_ps11.inc | 33 + .../stdshaders/fxctmp9/windowimposter_ps20.inc | 60 + .../stdshaders/fxctmp9/windowimposter_ps20b.inc | 87 + .../stdshaders/fxctmp9/windowimposter_vs11.inc | 60 + .../stdshaders/fxctmp9/windowimposter_vs20.inc | 60 + .../stdshaders/fxctmp9/worldvertexalpha_ps20.inc | 60 + .../stdshaders/fxctmp9/worldvertexalpha_ps20b.inc | 85 + .../fxctmp9/writevertexalphatodestalpha_ps11.inc | 33 + .../fxctmp9/writevertexalphatodestalpha_vs11.inc | 33 + materialsystem/stdshaders/fxctmp9/writez_vs20.inc | 85 + .../stdshaders/fxctmp9_360/Bloom_ps20.inc | 60 + .../stdshaders/fxctmp9_360/Bloom_ps20b.inc | 60 + .../stdshaders/fxctmp9_360/BlurFilter_ps20.inc | 60 + .../stdshaders/fxctmp9_360/BlurFilter_ps20b.inc | 60 + .../stdshaders/fxctmp9_360/BlurFilter_vs11.inc | 33 + .../stdshaders/fxctmp9_360/BlurFilter_vs20.inc | 33 + .../fxctmp9_360/Downsample_nohdr_ps20.inc | 85 + .../fxctmp9_360/Downsample_nohdr_ps20b.inc | 85 + .../stdshaders/fxctmp9_360/Downsample_ps20.inc | 60 + .../stdshaders/fxctmp9_360/Downsample_ps20b.inc | 60 + .../stdshaders/fxctmp9_360/Downsample_vs11.inc | 33 + .../stdshaders/fxctmp9_360/Downsample_vs20.inc | 33 + .../fxctmp9_360/HDRCombineTo16Bit_ps20.inc | 60 + .../fxctmp9_360/HDRCombineTo16Bit_ps20b.inc | 60 + .../fxctmp9_360/HDRCombineTo16Bit_vs20.inc | 33 + .../stdshaders/fxctmp9_360/HDRSelectRange_ps20.inc | 60 + .../fxctmp9_360/HDRSelectRange_ps20b.inc | 60 + .../stdshaders/fxctmp9_360/HDRSelectRange_vs20.inc | 33 + .../fxctmp9_360/IntroScreenSpaceEffect_ps20.inc | 87 + .../fxctmp9_360/IntroScreenSpaceEffect_ps20b.inc | 112 + .../stdshaders/fxctmp9_360/ParticleSphere_ps11.inc | 33 + .../stdshaders/fxctmp9_360/ParticleSphere_vs11.inc | 60 + .../stdshaders/fxctmp9_360/Refract_ps20.inc | 287 + .../stdshaders/fxctmp9_360/Refract_vs20.inc | 137 + .../stdshaders/fxctmp9_360/ShatteredGlass_ps20.inc | 237 + .../fxctmp9_360/ShatteredGlass_ps20b.inc | 237 + .../stdshaders/fxctmp9_360/ShatteredGlass_vs20.inc | 87 + .../VertexLit_and_unlit_Generic_bump_vs20.inc | 237 + .../VertexLit_and_unlit_Generic_vs20.inc | 437 + .../stdshaders/fxctmp9_360/WaterCheap_ps20.inc | 262 + .../stdshaders/fxctmp9_360/WaterCheap_ps20b.inc | 262 + .../stdshaders/fxctmp9_360/WaterCheap_vs20.inc | 60 + .../stdshaders/fxctmp9_360/Water_ps20.inc | 237 + .../stdshaders/fxctmp9_360/Water_vs20.inc | 85 + .../fxctmp9_360/WorldTwoTextureBlend_ps20.inc | 312 + .../fxctmp9_360/WorldTwoTextureBlend_ps20b.inc | 387 + .../fxctmp9_360/accumbuff4sample_ps20.inc | 60 + .../fxctmp9_360/accumbuff4sample_ps20b.inc | 60 + .../fxctmp9_360/accumbuff5sample_ps20.inc | 60 + .../fxctmp9_360/accumbuff5sample_ps20b.inc | 60 + .../stdshaders/fxctmp9_360/aftershock_ps20.inc | 60 + .../stdshaders/fxctmp9_360/aftershock_ps20b.inc | 60 + .../stdshaders/fxctmp9_360/aftershock_vs20.inc | 85 + .../stdshaders/fxctmp9_360/alphadist_ps11.inc | 33 + .../fxctmp9_360/appchooser360movie_ps20.inc | 33 + .../fxctmp9_360/appchooser360movie_ps20b.inc | 33 + materialsystem/stdshaders/fxctmp9_360/bik_ps20.inc | 87 + .../stdshaders/fxctmp9_360/bik_ps20b.inc | 87 + materialsystem/stdshaders/fxctmp9_360/bik_vs20.inc | 60 + .../stdshaders/fxctmp9_360/bloomadd_ps11.inc | 33 + .../stdshaders/fxctmp9_360/bloomadd_ps20.inc | 33 + .../stdshaders/fxctmp9_360/bloomadd_ps20b.inc | 33 + .../fxctmp9_360/bufferclearobeystencil_ps20.inc | 60 + .../fxctmp9_360/bufferclearobeystencil_ps20b.inc | 60 + .../fxctmp9_360/bufferclearobeystencil_vs20.inc | 60 + .../fxctmp9_360/bumpmappedlightmap_vs11.inc | 60 + .../stdshaders/fxctmp9_360/cable_ps20.inc | 87 + .../stdshaders/fxctmp9_360/cable_ps20b.inc | 112 + .../stdshaders/fxctmp9_360/cable_vs20.inc | 60 + .../fxctmp9_360/cloak_blended_pass_ps20.inc | 85 + .../fxctmp9_360/cloak_blended_pass_ps20b.inc | 85 + .../fxctmp9_360/cloak_blended_pass_vs20.inc | 112 + .../stdshaders/fxctmp9_360/cloak_ps20.inc | 162 + .../stdshaders/fxctmp9_360/cloak_ps20b.inc | 162 + .../stdshaders/fxctmp9_360/cloak_vs20.inc | 187 + .../stdshaders/fxctmp9_360/cloud_ps20.inc | 33 + .../stdshaders/fxctmp9_360/cloud_vs20.inc | 33 + .../fxctmp9_360/color_projection_ps20.inc | 110 + .../fxctmp9_360/color_projection_ps20b.inc | 110 + .../fxctmp9_360/color_projection_vs20.inc | 33 + .../fxctmp9_360/colorcorrection_ps20.inc | 87 + .../fxctmp9_360/colorcorrection_ps20b.inc | 87 + .../stdshaders/fxctmp9_360/constant_color_ps20.inc | 60 + .../fxctmp9_360/constant_color_ps20b.inc | 60 + .../stdshaders/fxctmp9_360/copy_fp_rt_ps20.inc | 60 + .../stdshaders/fxctmp9_360/copy_fp_rt_ps20b.inc | 60 + .../stdshaders/fxctmp9_360/core_ps20.inc | 187 + .../stdshaders/fxctmp9_360/core_ps20b.inc | 187 + .../stdshaders/fxctmp9_360/core_vs11.inc | 60 + .../stdshaders/fxctmp9_360/core_vs20.inc | 112 + .../stdshaders/fxctmp9_360/debugdrawdepth_ps20.inc | 60 + .../fxctmp9_360/debugdrawdepth_ps20b.inc | 60 + .../stdshaders/fxctmp9_360/debugdrawdepth_vs20.inc | 85 + .../fxctmp9_360/debugdrawenvmapmask_ps20.inc | 87 + .../fxctmp9_360/debugdrawenvmapmask_ps20b.inc | 87 + .../fxctmp9_360/debugdrawenvmapmask_vs20.inc | 85 + .../fxctmp9_360/debugmrttexture_ps20.inc | 85 + .../fxctmp9_360/debugmrttexture_ps20b.inc | 85 + .../fxctmp9_360/debugmrttexture_vs20.inc | 33 + .../fxctmp9_360/debugtangentspace_vs11.inc | 85 + .../fxctmp9_360/debugtangentspace_vs20.inc | 110 + .../fxctmp9_360/debugtextureview_ps20.inc | 112 + .../fxctmp9_360/debugtextureview_ps20b.inc | 112 + .../fxctmp9_360/debugtextureview_vs20.inc | 60 + ...lbasetimeslightmapalphablendselfillum2_ps20.inc | 87 + ...basetimeslightmapalphablendselfillum2_ps20b.inc | 87 + .../stdshaders/fxctmp9_360/decalmodulate_ps20.inc | 87 + .../stdshaders/fxctmp9_360/decalmodulate_ps20b.inc | 87 + .../fxctmp9_360/depthtodestalpha_ps20b.inc | 33 + .../fxctmp9_360/depthtodestalpha_vs20.inc | 33 + .../stdshaders/fxctmp9_360/depthwrite_ps20.inc | 60 + .../stdshaders/fxctmp9_360/depthwrite_ps20b.inc | 60 + .../stdshaders/fxctmp9_360/depthwrite_vs20.inc | 112 + .../emissive_scroll_blended_pass_ps20.inc | 60 + .../emissive_scroll_blended_pass_ps20b.inc | 60 + .../emissive_scroll_blended_pass_vs20.inc | 85 + .../stdshaders/fxctmp9_360/engine_post_ps20.inc | 162 + .../stdshaders/fxctmp9_360/engine_post_ps20b.inc | 212 + .../stdshaders/fxctmp9_360/eye_refract_ps20.inc | 112 + .../stdshaders/fxctmp9_360/eye_refract_ps20b.inc | 212 + .../stdshaders/fxctmp9_360/eye_refract_vs20.inc | 287 + .../stdshaders/fxctmp9_360/eyeglint_ps20.inc | 33 + .../stdshaders/fxctmp9_360/eyeglint_ps20b.inc | 33 + .../stdshaders/fxctmp9_360/eyeglint_vs20.inc | 33 + .../fxctmp9_360/eyes_flashlight_ps11.inc | 33 + .../fxctmp9_360/eyes_flashlight_ps20.inc | 60 + .../fxctmp9_360/eyes_flashlight_ps20b.inc | 112 + .../fxctmp9_360/eyes_flashlight_vs20.inc | 110 + .../stdshaders/fxctmp9_360/eyes_ps20.inc | 60 + .../stdshaders/fxctmp9_360/eyes_ps20b.inc | 85 + .../stdshaders/fxctmp9_360/eyes_vs20.inc | 262 + .../stdshaders/fxctmp9_360/fillrate_ps11.inc | 33 + .../stdshaders/fxctmp9_360/fillrate_ps20.inc | 60 + .../stdshaders/fxctmp9_360/fillrate_ps20b.inc | 60 + .../stdshaders/fxctmp9_360/fillrate_vs11.inc | 85 + .../stdshaders/fxctmp9_360/fillrate_vs20.inc | 85 + .../stdshaders/fxctmp9_360/filmdust_ps11.inc | 33 + .../stdshaders/fxctmp9_360/filmdust_ps20.inc | 33 + .../stdshaders/fxctmp9_360/filmgrain_ps11.inc | 33 + .../stdshaders/fxctmp9_360/filmgrain_ps20.inc | 33 + .../stdshaders/fxctmp9_360/filmgrain_vs20.inc | 33 + .../stdshaders/fxctmp9_360/flashlight_ps11.inc | 85 + .../stdshaders/fxctmp9_360/flashlight_ps20.inc | 212 + .../stdshaders/fxctmp9_360/flashlight_ps20b.inc | 262 + .../flesh_interior_blended_pass_ps20.inc | 60 + .../flesh_interior_blended_pass_ps20b.inc | 60 + .../flesh_interior_blended_pass_vs20.inc | 237 + .../fxctmp9_360/floatcombine_autoexpose_ps20.inc | 60 + .../fxctmp9_360/floatcombine_autoexpose_ps20b.inc | 60 + .../stdshaders/fxctmp9_360/floatcombine_ps20.inc | 60 + .../stdshaders/fxctmp9_360/floatcombine_ps20b.inc | 60 + .../fxctmp9_360/floattoscreen_notonemap_ps20.inc | 60 + .../fxctmp9_360/floattoscreen_notonemap_ps20b.inc | 60 + .../stdshaders/fxctmp9_360/floattoscreen_ps20.inc | 60 + .../stdshaders/fxctmp9_360/floattoscreen_ps20b.inc | 60 + .../fxctmp9_360/floattoscreen_vanilla_ps20.inc | 60 + .../fxctmp9_360/floattoscreen_vanilla_ps20b.inc | 60 + .../stdshaders/fxctmp9_360/haloadd1d_ps20.inc | 33 + .../stdshaders/fxctmp9_360/haloadd1d_ps20b.inc | 33 + .../stdshaders/fxctmp9_360/haloadd_ps20.inc | 33 + .../stdshaders/fxctmp9_360/haloadd_ps20b.inc | 33 + .../stdshaders/fxctmp9_360/haloaddoutline_ps20.inc | 33 + .../fxctmp9_360/haloaddoutline_ps20b.inc | 33 + .../fxctmp9_360/hsl_filmgrain_pass1_ps20.inc | 60 + .../fxctmp9_360/hsl_filmgrain_pass1_ps20b.inc | 60 + .../fxctmp9_360/hsl_filmgrain_pass2_ps20.inc | 60 + .../fxctmp9_360/hsl_filmgrain_pass2_ps20b.inc | 60 + materialsystem/stdshaders/fxctmp9_360/hsv_ps20.inc | 60 + .../stdshaders/fxctmp9_360/hsv_ps20b.inc | 60 + .../fxctmp9_360/introscreenspaceeffect_ps11.inc | 60 + .../fxctmp9_360/lightmappedgeneric_decal_ps20.inc | 87 + .../fxctmp9_360/lightmappedgeneric_decal_ps20b.inc | 87 + .../fxctmp9_360/lightmappedgeneric_decal_vs20.inc | 60 + .../lightmappedgeneric_flashlight_vs11.inc | 137 + .../lightmappedgeneric_flashlight_vs20.inc | 162 + ...mappedgeneric_lightingonly_overbright2_ps11.inc | 33 + .../lightmappedgeneric_lightingonly_vs11.inc | 60 + .../fxctmp9_360/lightmappedgeneric_ps20.inc | 712 + .../fxctmp9_360/lightmappedgeneric_ps20b.inc | 787 + .../fxctmp9_360/lightmappedgeneric_vs20.inc | 362 + .../fxctmp9_360/lightmappedreflective_ps20.inc | 187 + .../fxctmp9_360/lightmappedreflective_ps20b.inc | 212 + .../fxctmp9_360/lightmappedreflective_vs20.inc | 60 + .../stdshaders/fxctmp9_360/lpreview1_ps20.inc | 60 + .../stdshaders/fxctmp9_360/lpreview1_ps20b.inc | 60 + .../fxctmp9_360/lpreview_output_ps20.inc | 60 + .../fxctmp9_360/lpreview_output_ps20b.inc | 60 + .../fxctmp9_360/luminance_compare_ps20.inc | 60 + .../fxctmp9_360/luminance_compare_ps20b.inc | 60 + .../stdshaders/fxctmp9_360/modulate_ps20.inc | 87 + .../stdshaders/fxctmp9_360/modulate_ps20b.inc | 112 + .../stdshaders/fxctmp9_360/monitorscreen_ps20.inc | 112 + .../stdshaders/fxctmp9_360/monitorscreen_ps20b.inc | 137 + .../stdshaders/fxctmp9_360/motion_blur_ps20.inc | 87 + .../stdshaders/fxctmp9_360/motion_blur_ps20b.inc | 87 + .../stdshaders/fxctmp9_360/motion_blur_vs20.inc | 33 + .../stdshaders/fxctmp9_360/particlesphere_ps20.inc | 87 + .../fxctmp9_360/particlesphere_ps20b.inc | 112 + .../stdshaders/fxctmp9_360/particlesphere_vs20.inc | 60 + .../stdshaders/fxctmp9_360/portal_ps11.inc | 162 + .../stdshaders/fxctmp9_360/portal_ps20.inc | 187 + .../stdshaders/fxctmp9_360/portal_ps20b.inc | 187 + .../stdshaders/fxctmp9_360/portal_refract_ps11.inc | 60 + .../stdshaders/fxctmp9_360/portal_refract_ps20.inc | 85 + .../fxctmp9_360/portal_refract_ps20b.inc | 137 + .../stdshaders/fxctmp9_360/portal_refract_vs11.inc | 60 + .../stdshaders/fxctmp9_360/portal_refract_vs20.inc | 60 + .../stdshaders/fxctmp9_360/portal_vs11.inc | 187 + .../stdshaders/fxctmp9_360/portal_vs20.inc | 162 + .../fxctmp9_360/portalstaticoverlay_ps11.inc | 137 + .../fxctmp9_360/portalstaticoverlay_ps20.inc | 162 + .../fxctmp9_360/portalstaticoverlay_ps20b.inc | 162 + .../fxctmp9_360/portalstaticoverlay_vs11.inc | 87 + .../fxctmp9_360/portalstaticoverlay_vs20.inc | 87 + .../stdshaders/fxctmp9_360/refract_ps20b.inc | 337 + .../fxctmp9_360/rendertargetblit_ps20.inc | 33 + .../fxctmp9_360/rendertargetblit_ps20b.inc | 33 + .../fxctmp9_360/rendertargetblit_vs20.inc | 33 + .../fxctmp9_360/sample4x4_blend_ps20.inc | 60 + .../fxctmp9_360/sample4x4_blend_ps20b.inc | 60 + .../stdshaders/fxctmp9_360/sample4x4_ps20.inc | 60 + .../stdshaders/fxctmp9_360/sample4x4_ps20b.inc | 60 + .../stdshaders/fxctmp9_360/sample4x4delog_ps20.inc | 60 + .../fxctmp9_360/sample4x4delog_ps20b.inc | 60 + .../stdshaders/fxctmp9_360/sample4x4log_ps20.inc | 60 + .../stdshaders/fxctmp9_360/sample4x4log_ps20b.inc | 60 + .../fxctmp9_360/sample4x4maxmin_ps20.inc | 60 + .../fxctmp9_360/sample4x4maxmin_ps20b.inc | 60 + .../fxctmp9_360/screenspaceeffect_vs11.inc | 33 + .../fxctmp9_360/screenspaceeffect_vs20.inc | 60 + .../stdshaders/fxctmp9_360/sfm_combine_vs20.inc | 33 + .../fxctmp9_360/sfm_integercombine_ps20.inc | 60 + .../fxctmp9_360/sfm_integercombine_ps20b.inc | 60 + .../stdshaders/fxctmp9_360/shadow_ps20.inc | 87 + .../stdshaders/fxctmp9_360/shadow_ps20b.inc | 87 + .../stdshaders/fxctmp9_360/shadow_vs20.inc | 60 + .../fxctmp9_360/shadowbuildtexture_ps20.inc | 60 + .../fxctmp9_360/shadowbuildtexture_ps20b.inc | 60 + .../stdshaders/fxctmp9_360/shadowmodel_ps20.inc | 33 + .../stdshaders/fxctmp9_360/shadowmodel_vs20.inc | 85 + .../stdshaders/fxctmp9_360/showz_ps20.inc | 85 + .../stdshaders/fxctmp9_360/showz_ps20b.inc | 85 + .../stdshaders/fxctmp9_360/showz_vs11.inc | 33 + .../stdshaders/fxctmp9_360/showz_vs20.inc | 33 + .../stdshaders/fxctmp9_360/skin_ps20b.inc | 512 + .../stdshaders/fxctmp9_360/skin_vs20.inc | 187 + .../fxctmp9_360/sky_hdr_compressed_ps20.inc | 60 + .../fxctmp9_360/sky_hdr_compressed_ps20b.inc | 87 + .../fxctmp9_360/sky_hdr_compressed_rgbs_ps20.inc | 60 + .../fxctmp9_360/sky_hdr_compressed_rgbs_ps20b.inc | 87 + materialsystem/stdshaders/fxctmp9_360/sky_ps20.inc | 60 + .../stdshaders/fxctmp9_360/sky_ps20b.inc | 87 + materialsystem/stdshaders/fxctmp9_360/sky_vs20.inc | 33 + .../stdshaders/fxctmp9_360/splinecard_vs11.inc | 33 + .../stdshaders/fxctmp9_360/splinecard_vs20.inc | 33 + .../stdshaders/fxctmp9_360/sprite_ps20.inc | 212 + .../stdshaders/fxctmp9_360/sprite_ps20b.inc | 237 + .../stdshaders/fxctmp9_360/sprite_vs20.inc | 112 + .../stdshaders/fxctmp9_360/spritecard_ps11.inc | 110 + .../stdshaders/fxctmp9_360/spritecard_ps20.inc | 285 + .../stdshaders/fxctmp9_360/spritecard_ps20b.inc | 310 + .../stdshaders/fxctmp9_360/spritecard_vs11.inc | 137 + .../stdshaders/fxctmp9_360/spritecard_vs20.inc | 162 + .../stdshaders/fxctmp9_360/teeth_bump_ps20.inc | 137 + .../stdshaders/fxctmp9_360/teeth_bump_ps20b.inc | 162 + .../stdshaders/fxctmp9_360/teeth_bump_vs20.inc | 212 + .../fxctmp9_360/teeth_flashlight_ps20.inc | 87 + .../fxctmp9_360/teeth_flashlight_ps20b.inc | 137 + .../fxctmp9_360/teeth_flashlight_vs20.inc | 137 + .../stdshaders/fxctmp9_360/teeth_ps20.inc | 87 + .../stdshaders/fxctmp9_360/teeth_ps20b.inc | 112 + .../stdshaders/fxctmp9_360/teeth_vs20.inc | 237 + .../stdshaders/fxctmp9_360/treeleaf_ps20.inc | 60 + .../stdshaders/fxctmp9_360/treeleaf_ps20b.inc | 60 + .../stdshaders/fxctmp9_360/treeleaf_vs20.inc | 162 + .../unlitgeneric_maskbasebydetailalpha_ps11.inc | 33 + .../fxctmp9_360/unlitgeneric_notexture_ps11.inc | 33 + .../fxctmp9_360/unlitgeneric_notexture_ps20.inc | 60 + .../fxctmp9_360/unlitgeneric_notexture_ps20b.inc | 60 + .../stdshaders/fxctmp9_360/unlitgeneric_ps20.inc | 60 + .../stdshaders/fxctmp9_360/unlitgeneric_ps20b.inc | 60 + .../stdshaders/fxctmp9_360/unlitgeneric_vs20.inc | 110 + .../fxctmp9_360/unlittwotexture_ps20.inc | 112 + .../fxctmp9_360/unlittwotexture_ps20b.inc | 137 + .../fxctmp9_360/unlittwotexture_vs20.inc | 110 + .../vertexlit_and_unlit_generic_bump_ps20.inc | 412 + .../vertexlit_and_unlit_generic_bump_ps20b.inc | 412 + .../vertexlit_and_unlit_generic_ps20.inc | 537 + .../vertexlit_and_unlit_generic_ps20b.inc | 612 + ...texlitgeneric_lightingonly_overbright2_ps11.inc | 33 + .../stdshaders/fxctmp9_360/volume_clouds_ps20.inc | 60 + .../stdshaders/fxctmp9_360/volume_clouds_ps20b.inc | 60 + .../stdshaders/fxctmp9_360/volume_clouds_vs20.inc | 85 + .../stdshaders/fxctmp9_360/vortwarp_ps20.inc | 362 + .../stdshaders/fxctmp9_360/vortwarp_ps20b.inc | 362 + .../stdshaders/fxctmp9_360/vortwarp_vs20.inc | 187 + .../stdshaders/fxctmp9_360/water_ps20b.inc | 287 + .../stdshaders/fxctmp9_360/white_ps20.inc | 60 + .../stdshaders/fxctmp9_360/white_ps20b.inc | 60 + .../stdshaders/fxctmp9_360/windowimposter_ps11.inc | 33 + .../stdshaders/fxctmp9_360/windowimposter_ps20.inc | 87 + .../fxctmp9_360/windowimposter_ps20b.inc | 87 + .../stdshaders/fxctmp9_360/windowimposter_vs11.inc | 60 + .../stdshaders/fxctmp9_360/windowimposter_vs20.inc | 60 + .../fxctmp9_360/worldvertexalpha_ps20.inc | 85 + .../fxctmp9_360/worldvertexalpha_ps20b.inc | 85 + .../writevertexalphatodestalpha_ps11.inc | 33 + .../writevertexalphatodestalpha_vs11.inc | 33 + .../stdshaders/fxctmp9_360/writez_vs20.inc | 85 + materialsystem/stdshaders/genwaterloop.pl | 9 + materialsystem/stdshaders/glowwarp.psh | 20 + materialsystem/stdshaders/gooinglass.cpp | 169 + materialsystem/stdshaders/haloadd1d_ps2x.fxc | 35 + materialsystem/stdshaders/haloadd_ps2x.fxc | 26 + materialsystem/stdshaders/haloaddoutline_ps2x.fxc | 34 + materialsystem/stdshaders/hsl_filmgrain_pass1.cpp | 103 + .../stdshaders/hsl_filmgrain_pass1_ps2x.fxc | 26 + materialsystem/stdshaders/hsl_filmgrain_pass2.cpp | 93 + .../stdshaders/hsl_filmgrain_pass2_ps2x.fxc | 19 + materialsystem/stdshaders/hsv.cpp | 67 + materialsystem/stdshaders/hsv_ps2x.fxc | 27 + .../stdshaders/introscreenspaceeffect.cpp | 104 + .../stdshaders/introscreenspaceeffect_dx60.cpp | 79 + .../stdshaders/introscreenspaceeffect_dx80.cpp | 69 + materialsystem/stdshaders/jellyfish.cpp | 111 + materialsystem/stdshaders/lightingonly_vs20.fxc | 74 + .../lightmappedenvmappedbumpmappedtexture.psh | 33 + .../lightmappedgeneric_basealphamaskedenvmap.psh | 22 + .../lightmappedgeneric_basetextureblend.psh | 9 + .../stdshaders/lightmappedgeneric_decal.cpp | 135 + .../stdshaders/lightmappedgeneric_decal_ps2x.fxc | 59 + .../stdshaders/lightmappedgeneric_decal_vs20.fxc | 74 + .../stdshaders/lightmappedgeneric_dx6.cpp | 288 + .../stdshaders/lightmappedgeneric_dx8.cpp | 802 ++ .../stdshaders/lightmappedgeneric_dx9.cpp | 164 + .../stdshaders/lightmappedgeneric_dx9_helper.cpp | 1021 ++ .../stdshaders/lightmappedgeneric_dx9_helper.h | 99 + .../stdshaders/lightmappedgeneric_envmap.psh | 20 + .../lightmappedgeneric_flashlight_vs11.fxc | 122 + .../lightmappedgeneric_flashlight_vs20.fxc | 184 + .../stdshaders/lightmappedgeneric_inc.vsh | 110 + ...mappedgeneric_lightingonly_overbright2_ps11.fxc | 12 + .../lightmappedgeneric_lightingonly_vs11.fxc | 51 + .../stdshaders/lightmappedgeneric_maskedenvmap.psh | 22 + ..._multiplybylightingbasealphamaskedselfillum.psh | 24 + ...ppedgeneric_multiplybylightingbasenotexture.psh | 20 + .../stdshaders/lightmappedgeneric_ps11.fxc | 122 + .../stdshaders/lightmappedgeneric_ps2_3_x.h | 583 + .../stdshaders/lightmappedgeneric_ps2x.fxc | 59 + .../lightmappedgeneric_selfilluminatedenvmap.psh | 27 + ...htmappedgeneric_selfilluminatedmaskedenvmap.psh | 27 + .../stdshaders/lightmappedgeneric_vs11.vsh | 20 + .../stdshaders/lightmappedgeneric_vs20.fxc | 254 + .../stdshaders/lightmappedreflective.cpp | 287 + .../stdshaders/lightmappedreflective_ps2x.fxc | 190 + .../stdshaders/lightmappedreflective_vs20.fxc | 106 + materialsystem/stdshaders/lightmappedtexture.psh | 17 + .../stdshaders/lightmappedtwotexture.cpp | 186 + materialsystem/stdshaders/lpreview1_ps2x.fxc | 69 + materialsystem/stdshaders/lpreview_output_ps2x.fxc | 25 + .../stdshaders/luminance_compare_ps2x.fxc | 51 + materialsystem/stdshaders/macros.vsh | 1393 ++ materialsystem/stdshaders/modeldiffusebump.psh | 39 + materialsystem/stdshaders/modeldiffusebump2.psh | 33 + .../stdshaders/modelenvmappedbumpmapv2.psh | 30 + .../modelenvmappedbumpmapv2_multbyalpha.psh | 35 + materialsystem/stdshaders/modulate_dx6.cpp | 96 + materialsystem/stdshaders/modulate_dx8.cpp | 231 + materialsystem/stdshaders/modulate_dx9.cpp | 291 + materialsystem/stdshaders/modulate_ps2x.fxc | 38 + materialsystem/stdshaders/modulate_vs11.vsh | 0 materialsystem/stdshaders/monitorscreen_ps2x.fxc | 53 + materialsystem/stdshaders/morphaccumulate_dx9.cpp | 108 + materialsystem/stdshaders/morphaccumulate_ps30.fxc | 59 + materialsystem/stdshaders/morphaccumulate_vs30.fxc | 54 + materialsystem/stdshaders/morphweight_dx9.cpp | 72 + materialsystem/stdshaders/morphweight_ps30.fxc | 13 + materialsystem/stdshaders/morphweight_vs30.fxc | 29 + materialsystem/stdshaders/motion_blur_dx9.cpp | 132 + materialsystem/stdshaders/motion_blur_ps2x.fxc | 189 + materialsystem/stdshaders/motion_blur_vs20.fxc | 29 + materialsystem/stdshaders/occlusion_dx8.cpp | 62 + materialsystem/stdshaders/occlusion_dx9.cpp | 91 + materialsystem/stdshaders/overlay_fit.cpp | 90 + materialsystem/stdshaders/overlay_fit_ps11.psh | 11 + materialsystem/stdshaders/overlay_fit_vs11.vsh | 55 + .../stdshaders/particlelitgeneric_dx9.cpp | 66 + .../stdshaders/particlelitgeneric_dx9_helper.cpp | 303 + .../stdshaders/particlelitgeneric_dx9_helper.h | 47 + materialsystem/stdshaders/particlesphere.psh | 39 + materialsystem/stdshaders/particlesphere_dx8.cpp | 101 + materialsystem/stdshaders/particlesphere_dx9.cpp | 175 + materialsystem/stdshaders/particlesphere_ps11.fxc | 40 + materialsystem/stdshaders/particlesphere_ps2x.fxc | 67 + materialsystem/stdshaders/particlesphere_vs11.fxc | 103 + materialsystem/stdshaders/particlesphere_vs20.fxc | 130 + materialsystem/stdshaders/portal.cpp | 262 + materialsystem/stdshaders/portal_dx60.cpp | 205 + materialsystem/stdshaders/portal_dx80.cpp | 307 + materialsystem/stdshaders/portal_ps11.fxc | 122 + materialsystem/stdshaders/portal_ps2x.fxc | 88 + materialsystem/stdshaders/portal_refract.cpp | 98 + materialsystem/stdshaders/portal_refract_dx8.cpp | 83 + .../stdshaders/portal_refract_dx8_helper.cpp | 145 + .../stdshaders/portal_refract_dx8_helper.h | 45 + .../stdshaders/portal_refract_helper.cpp | 190 + materialsystem/stdshaders/portal_refract_helper.h | 46 + materialsystem/stdshaders/portal_refract_ps11.fxc | 33 + materialsystem/stdshaders/portal_refract_ps2x.fxc | 224 + materialsystem/stdshaders/portal_refract_vs11.fxc | 63 + materialsystem/stdshaders/portal_refract_vs20.fxc | 90 + materialsystem/stdshaders/portal_vs11.fxc | 142 + materialsystem/stdshaders/portal_vs20.fxc | 97 + materialsystem/stdshaders/portalstaticoverlay.cpp | 198 + .../stdshaders/portalstaticoverlay_dx60.cpp | 181 + .../stdshaders/portalstaticoverlay_dx80.cpp | 152 + .../stdshaders/portalstaticoverlay_ps11.fxc | 68 + .../stdshaders/portalstaticoverlay_ps2x.fxc | 74 + .../stdshaders/portalstaticoverlay_vs11.fxc | 55 + .../stdshaders/portalstaticoverlay_vs20.fxc | 58 + materialsystem/stdshaders/predator.cpp | 99 + materialsystem/stdshaders/predator.psh | 11 + materialsystem/stdshaders/predator.vsh | 86 + materialsystem/stdshaders/predator_envmap.psh | 7 + materialsystem/stdshaders/pyro_vision.cpp | 696 + materialsystem/stdshaders/pyro_vision_ps2x.fxc | 460 + materialsystem/stdshaders/pyro_vision_vs20.fxc | 185 + materialsystem/stdshaders/refract.cpp | 111 + materialsystem/stdshaders/refract_dx60.cpp | 16 + materialsystem/stdshaders/refract_dx80.cpp | 317 + materialsystem/stdshaders/refract_dx9_helper.cpp | 298 + materialsystem/stdshaders/refract_dx9_helper.h | 62 + materialsystem/stdshaders/refract_ps2x.fxc | 250 + .../stdshaders/rendertargetblit_ps2x.fxc | 20 + .../stdshaders/rendertargetblit_vs20.fxc | 24 + .../stdshaders/rendertargetblit_x360.cpp | 83 + materialsystem/stdshaders/rift_dx6.cpp | 112 + materialsystem/stdshaders/rift_dx8.cpp | 102 + materialsystem/stdshaders/rift_ps11.psh | 16 + materialsystem/stdshaders/rift_vs11.vsh | 70 + materialsystem/stdshaders/sample4x4.cpp | 121 + materialsystem/stdshaders/sample4x4_blend.cpp | 111 + materialsystem/stdshaders/sample4x4_blend_ps2x.fxc | 30 + materialsystem/stdshaders/sample4x4_ps2x.fxc | 32 + materialsystem/stdshaders/sample4x4delog_ps2x.fxc | 35 + materialsystem/stdshaders/sample4x4log_ps2x.fxc | 51 + materialsystem/stdshaders/sample4x4maxmin_ps2x.fxc | 32 + materialsystem/stdshaders/screenspace_general.cpp | 313 + .../stdshaders/screenspace_general_dx8.cpp | 196 + .../stdshaders/screenspaceeffect_vs11.fxc | 26 + .../stdshaders/screenspaceeffect_vs20.fxc | 47 + materialsystem/stdshaders/sfm_blurfilterx.cpp | 121 + materialsystem/stdshaders/sfm_blurfiltery.cpp | 123 + materialsystem/stdshaders/sfm_combine_vs20.fxc | 25 + materialsystem/stdshaders/sfm_downsample.cpp | 103 + materialsystem/stdshaders/sfm_integercombine.cpp | 97 + .../stdshaders/sfm_integercombine_ps2x.fxc | 27 + .../stdshaders/shader_constant_register_map.h | 81 + materialsystem/stdshaders/shadow.cpp | 138 + materialsystem/stdshaders/shadow_dx6.cpp | 90 + materialsystem/stdshaders/shadow_dx8.cpp | 135 + materialsystem/stdshaders/shadow_ps14.psh | 28 + materialsystem/stdshaders/shadow_ps2x.fxc | 63 + materialsystem/stdshaders/shadow_vs14.vsh | 43 + materialsystem/stdshaders/shadow_vs20.fxc | 66 + materialsystem/stdshaders/shadowbuild_dx6.cpp | 45 + materialsystem/stdshaders/shadowbuild_dx8.cpp | 118 + materialsystem/stdshaders/shadowbuild_dx9.cpp | 149 + .../stdshaders/shadowbuildtexture_ps2x.fxc | 28 + materialsystem/stdshaders/shadowmodel_dx8.cpp | 97 + materialsystem/stdshaders/shadowmodel_dx9.cpp | 154 + materialsystem/stdshaders/shadowmodel_ps20.fxc | 20 + materialsystem/stdshaders/shadowmodel_vs20.fxc | 81 + materialsystem/stdshaders/shatteredglass.cpp | 297 + materialsystem/stdshaders/shatteredglass_dx7.cpp | 194 + materialsystem/stdshaders/shatteredglass_dx8.cpp | 211 + materialsystem/stdshaders/showz.cpp | 98 + materialsystem/stdshaders/showz_ps2x.fxc | 34 + materialsystem/stdshaders/showz_vs20.fxc | 33 + materialsystem/stdshaders/skin_dx9_helper.cpp | 990 ++ materialsystem/stdshaders/skin_dx9_helper.h | 35 + materialsystem/stdshaders/skin_ps20b.fxc | 381 + materialsystem/stdshaders/skin_vs20.fxc | 173 + materialsystem/stdshaders/sky_dx6.cpp | 15 + materialsystem/stdshaders/sky_dx9.cpp | 126 + .../stdshaders/sky_hdr_compressed_ps2x.fxc | 29 + .../stdshaders/sky_hdr_compressed_rgbs_ps2x.fxc | 81 + materialsystem/stdshaders/sky_hdr_dx9.cpp | 297 + materialsystem/stdshaders/sky_ps2x.fxc | 27 + materialsystem/stdshaders/sky_vs20.fxc | 64 + materialsystem/stdshaders/splinecard_vsxx.fxc | 65 + materialsystem/stdshaders/sprite.cpp | 379 + materialsystem/stdshaders/sprite_dx6.cpp | 289 + materialsystem/stdshaders/sprite_dx9.cpp | 490 + materialsystem/stdshaders/sprite_ps11.psh | 15 + materialsystem/stdshaders/sprite_ps2x.fxc | 61 + materialsystem/stdshaders/sprite_vs11.vsh | 9 + materialsystem/stdshaders/sprite_vs20.fxc | 65 + materialsystem/stdshaders/spritecard.cpp | 484 + materialsystem/stdshaders/spritecard_ps11.fxc | 72 + materialsystem/stdshaders/spritecard_ps2x.fxc | 194 + materialsystem/stdshaders/spritecard_vsxx.fxc | 347 + materialsystem/stdshaders/stdshader_dbg.vpc | 102 + materialsystem/stdshaders/stdshader_dx10.txt | 1 + materialsystem/stdshaders/stdshader_dx6.vpc | 105 + materialsystem/stdshaders/stdshader_dx7.vpc | 74 + materialsystem/stdshaders/stdshader_dx8.vpc | 141 + materialsystem/stdshaders/stdshader_dx9.vpc | 247 + materialsystem/stdshaders/stdshader_dx9_20b.txt | 529 + .../stdshaders/stdshader_dx9_20b_new.txt | 11 + materialsystem/stdshaders/stdshader_dx9_30.txt | 54 + materialsystem/stdshaders/teeth.cpp | 578 + materialsystem/stdshaders/teeth_bump_ps2x.fxc | 101 + materialsystem/stdshaders/teeth_bump_vs20.fxc | 152 + materialsystem/stdshaders/teeth_dx6.cpp | 69 + materialsystem/stdshaders/teeth_dx8.cpp | 116 + .../stdshaders/teeth_flashlight_ps2x.fxc | 66 + .../stdshaders/teeth_flashlight_vs20.fxc | 149 + materialsystem/stdshaders/teeth_ps2x.fxc | 48 + materialsystem/stdshaders/teeth_vs20.fxc | 127 + .../stdshaders/unlitgeneric_basetimesdetail.psh | 24 + materialsystem/stdshaders/unlitgeneric_dx6.cpp | 310 + materialsystem/stdshaders/unlitgeneric_dx8.cpp | 72 + materialsystem/stdshaders/unlitgeneric_dx9.cpp | 200 + materialsystem/stdshaders/unlitgeneric_inc.vsh | 142 + .../stdshaders/unlitgeneric_lightingonly_vs11.fxc | 47 + .../stdshaders/unlitgeneric_notexture_ps11.fxc | 9 + .../stdshaders/unlitgeneric_notexture_ps2x.fxc | 14 + materialsystem/stdshaders/unlitgeneric_ps11.fxc | 12 + materialsystem/stdshaders/unlitgeneric_ps2x.fxc | 19 + materialsystem/stdshaders/unlitgeneric_vs11.vsh | 23 + materialsystem/stdshaders/unlitgeneric_vs20.fxc | 91 + materialsystem/stdshaders/unlittwotexture_dx6.cpp | 85 + materialsystem/stdshaders/unlittwotexture_dx8.cpp | 222 + materialsystem/stdshaders/unlittwotexture_dx9.cpp | 280 + materialsystem/stdshaders/unlittwotexture_inc.vsh | 64 + materialsystem/stdshaders/unlittwotexture_ps2x.fxc | 76 + materialsystem/stdshaders/unlittwotexture_vs20.fxc | 73 + .../vertexlit_and_unlit_generic_bump_ps2x.fxc | 350 + .../vertexlit_and_unlit_generic_bump_vs20.fxc | 198 + .../vertexlit_and_unlit_generic_ps2x.fxc | 507 + .../vertexlit_and_unlit_generic_vs20.fxc | 250 + .../stdshaders/vertexlit_lighting_only_ps2x.fxc | 68 + materialsystem/stdshaders/vertexlit_notexture.psh | 13 + .../vertexlitgeneric_basealphamaskedenvmap.psh | 19 + ...ertexlitgeneric_detailbasealphamaskedenvmap.psh | 21 + .../stdshaders/vertexlitgeneric_detailenvmap.psh | 19 + .../vertexlitgeneric_detailmaskedenvmap.psh | 21 + ...ertexlitgeneric_detailselfilluminatedenvmap.psh | 28 + ...itgeneric_detailselfilluminatedmaskedenvmap.psh | 29 + materialsystem/stdshaders/vertexlitgeneric_dx6.cpp | 421 + materialsystem/stdshaders/vertexlitgeneric_dx7.cpp | 413 + materialsystem/stdshaders/vertexlitgeneric_dx8.cpp | 807 ++ materialsystem/stdshaders/vertexlitgeneric_dx9.cpp | 524 + .../stdshaders/vertexlitgeneric_dx95_helper.h | 71 + .../stdshaders/vertexlitgeneric_dx9_helper.cpp | 1468 ++ .../stdshaders/vertexlitgeneric_dx9_helper.h | 145 + .../stdshaders/vertexlitgeneric_envmap.psh | 17 + .../vertexlitgeneric_flashlight_vs11.vsh | 137 + materialsystem/stdshaders/vertexlitgeneric_inc.vsh | 145 + .../vertexlitgeneric_lightingonly_overbright2.psh | 5 + ...texlitgeneric_lightingonly_overbright2_ps11.fxc | 9 + .../stdshaders/vertexlitgeneric_maskedenvmap.psh | 19 + .../vertexlitgeneric_selfilluminatedenvmap.psh | 25 + ...ertexlitgeneric_selfilluminatedmaskedenvmap.psh | 26 + .../stdshaders/vertexlitgeneric_vs11.vsh | 22 + materialsystem/stdshaders/viewalpha.cpp | 48 + materialsystem/stdshaders/volume_clouds.cpp | 59 + materialsystem/stdshaders/volume_clouds_helper.cpp | 138 + materialsystem/stdshaders/volume_clouds_helper.h | 41 + materialsystem/stdshaders/volume_clouds_ps2x.fxc | 66 + materialsystem/stdshaders/volume_clouds_vs20.fxc | 103 + materialsystem/stdshaders/volumetricfog.cpp | 37 + materialsystem/stdshaders/vortwarp_dx7.cpp | 268 + materialsystem/stdshaders/vortwarp_dx8.cpp | 175 + materialsystem/stdshaders/vortwarp_dx9.cpp | 640 + materialsystem/stdshaders/vortwarp_ps11.psh | 42 + materialsystem/stdshaders/vortwarp_ps2x.fxc | 198 + materialsystem/stdshaders/vortwarp_vs11.vsh | 85 + materialsystem/stdshaders/vortwarp_vs20.fxc | 174 + materialsystem/stdshaders/vortwarp_vs20_helper.h | 42 + materialsystem/stdshaders/vr_distort_hud.cpp | 224 + materialsystem/stdshaders/vr_distort_hud_ps2x.fxc | 78 + materialsystem/stdshaders/vr_distort_hud_vs20.fxc | 26 + materialsystem/stdshaders/vr_distort_texture.cpp | 213 + .../stdshaders/vr_distort_texture_ps2x.fxc | 49 + .../stdshaders/vr_distort_texture_vs20.fxc | 26 + .../vshtmp9/BufferClearObeyStencil_vs11.inc | 30 + .../stdshaders/vshtmp9/BumpmappedEnvmap.inc | 57 + .../stdshaders/vshtmp9/BumpmappedLightmap.inc | 57 + materialsystem/stdshaders/vshtmp9/Cable.inc | 57 + .../stdshaders/vshtmp9/DebugTangentSpace.inc | 82 + materialsystem/stdshaders/vshtmp9/Eyes.inc | 134 + materialsystem/stdshaders/vshtmp9/JellyFish.inc | 82 + materialsystem/stdshaders/vshtmp9/Jojirium.inc | 57 + materialsystem/stdshaders/vshtmp9/LightingOnly.inc | 134 + .../vshtmp9/LightmappedGeneric_BaseTexture.inc | 57 + ...tmappedGeneric_BumpmappedLightmap_Base_ps14.inc | 57 + ...mappedGeneric_BumpmappedLightmap_Blend_ps14.inc | 57 + .../vshtmp9/LightmappedGeneric_Decal.inc | 57 + .../vshtmp9/LightmappedGeneric_LightingOnly.inc | 57 + .../stdshaders/vshtmp9/Refract_model_vs11.inc | 82 + .../stdshaders/vshtmp9/Refract_world_vs11.inc | 57 + .../stdshaders/vshtmp9/ScreenSpaceEffect.inc | 57 + materialsystem/stdshaders/vshtmp9/ShadowModel.inc | 82 + .../stdshaders/vshtmp9/ShatteredGlass.inc | 57 + .../stdshaders/vshtmp9/ShatteredGlass_EnvMap.inc | 57 + .../vshtmp9/ShatteredGlass_EnvMapSphere.inc | 57 + materialsystem/stdshaders/vshtmp9/Teeth.inc | 159 + .../vshtmp9/UnlitGeneric_LightingOnly.inc | 82 + .../stdshaders/vshtmp9/UnlitTwoTexture.inc | 82 + ...ertexLitGeneric_EnvmappedBumpmap_NoLighting.inc | 82 + ...LitGeneric_EnvmappedBumpmap_NoLighting_ps14.inc | 82 + .../vshtmp9/VertexLitGeneric_SelfIllumOnly.inc | 82 + .../stdshaders/vshtmp9/VertexLitGeneric_vs11.inc | 200 + .../vshtmp9/WaterCheapPerVertexFresnel_vs11.inc | 57 + .../stdshaders/vshtmp9/WaterCheap_vs11.inc | 57 + .../stdshaders/vshtmp9/WaterCheap_vs14.inc | 57 + materialsystem/stdshaders/vshtmp9/Water_ps14.inc | 57 + materialsystem/stdshaders/vshtmp9/Water_vs11.inc | 57 + .../stdshaders/vshtmp9/WorldVertexAlpha.inc | 57 + .../stdshaders/vshtmp9/WorldVertexTransition.inc | 57 + materialsystem/stdshaders/vshtmp9/bik_vs11.inc | 30 + .../vshtmp9/cloak_blended_pass_dx8_vs11.inc | 57 + materialsystem/stdshaders/vshtmp9/cloud_vs11.inc | 48 + .../emissive_scroll_blended_pass_dx8_vs11.inc | 57 + .../stdshaders/vshtmp9/eyes_flashlight_vs11.inc | 82 + materialsystem/stdshaders/vshtmp9/fillrate.inc | 82 + .../flesh_interior_blended_pass_dx8_vs11.inc | 57 + .../lightmappedgeneric_basetextureblend.inc | 57 + .../lightmappedgeneric_bumpmappedenvmap.inc | 57 + .../lightmappedgeneric_bumpmappedenvmap_ps14.inc | 57 + .../lightmappedgeneric_bumpmappedlightmap.inc | 57 + .../stdshaders/vshtmp9/lightmappedgeneric_vs11.inc | 175 + .../stdshaders/vshtmp9/overlay_fit_vs11.inc | 57 + materialsystem/stdshaders/vshtmp9/predator.inc | 82 + .../stdshaders/vshtmp9/rendertargetblit_vs11.inc | 30 + materialsystem/stdshaders/vshtmp9/shadow_vs14.inc | 57 + materialsystem/stdshaders/vshtmp9/sprite_vs11.inc | 100 + .../stdshaders/vshtmp9/unlitgeneric_vs11.inc | 225 + .../vshtmp9/vertexlitgeneric_flashlight_vs11.inc | 109 + .../stdshaders/vshtmp9/vortwarp_vs11.inc | 134 + .../vshtmp9/worldvertextransition_seamless.inc | 57 + .../vshtmp9/worldvertextransition_vs14.inc | 57 + materialsystem/stdshaders/vshtmp9/writez.inc | 57 + .../vshtmp9_360/BufferClearObeyStencil_vs11.inc | 30 + .../stdshaders/vshtmp9_360/BumpmappedEnvmap.inc | 57 + .../stdshaders/vshtmp9_360/BumpmappedLightmap.inc | 57 + materialsystem/stdshaders/vshtmp9_360/Cable.inc | 57 + .../stdshaders/vshtmp9_360/DebugTangentSpace.inc | 82 + materialsystem/stdshaders/vshtmp9_360/Eyes.inc | 134 + .../stdshaders/vshtmp9_360/JellyFish.inc | 82 + .../stdshaders/vshtmp9_360/LightingOnly.inc | 134 + .../vshtmp9_360/LightmappedGeneric_BaseTexture.inc | 57 + ...tmappedGeneric_BumpmappedLightmap_Base_ps14.inc | 57 + ...mappedGeneric_BumpmappedLightmap_Blend_ps14.inc | 57 + .../vshtmp9_360/LightmappedGeneric_Decal.inc | 57 + .../LightmappedGeneric_LightingOnly.inc | 57 + .../stdshaders/vshtmp9_360/Refract_model_vs11.inc | 82 + .../stdshaders/vshtmp9_360/Refract_world_vs11.inc | 57 + .../stdshaders/vshtmp9_360/ScreenSpaceEffect.inc | 57 + .../stdshaders/vshtmp9_360/ShadowModel.inc | 82 + .../stdshaders/vshtmp9_360/ShatteredGlass.inc | 57 + .../vshtmp9_360/ShatteredGlass_EnvMap.inc | 57 + .../vshtmp9_360/ShatteredGlass_EnvMapSphere.inc | 57 + materialsystem/stdshaders/vshtmp9_360/Teeth.inc | 159 + .../vshtmp9_360/UnlitGeneric_LightingOnly.inc | 82 + .../stdshaders/vshtmp9_360/UnlitTwoTexture.inc | 82 + ...ertexLitGeneric_EnvmappedBumpmap_NoLighting.inc | 82 + ...LitGeneric_EnvmappedBumpmap_NoLighting_ps14.inc | 82 + .../vshtmp9_360/VertexLitGeneric_SelfIllumOnly.inc | 82 + .../vshtmp9_360/VertexLitGeneric_vs11.inc | 200 + .../WaterCheapPerVertexFresnel_vs11.inc | 57 + .../stdshaders/vshtmp9_360/WaterCheap_vs11.inc | 57 + .../stdshaders/vshtmp9_360/WaterCheap_vs14.inc | 57 + .../stdshaders/vshtmp9_360/Water_ps14.inc | 57 + .../stdshaders/vshtmp9_360/Water_vs11.inc | 57 + .../stdshaders/vshtmp9_360/WorldVertexAlpha.inc | 57 + .../vshtmp9_360/WorldVertexTransition.inc | 57 + materialsystem/stdshaders/vshtmp9_360/bik_vs11.inc | 30 + .../vshtmp9_360/cloak_blended_pass_dx8_vs11.inc | 57 + .../stdshaders/vshtmp9_360/cloud_vs11.inc | 48 + .../emissive_scroll_blended_pass_dx8_vs11.inc | 57 + .../vshtmp9_360/eyes_flashlight_vs11.inc | 82 + materialsystem/stdshaders/vshtmp9_360/fillrate.inc | 82 + .../flesh_interior_blended_pass_dx8_vs11.inc | 57 + .../lightmappedgeneric_basetextureblend.inc | 57 + .../lightmappedgeneric_bumpmappedenvmap.inc | 57 + .../lightmappedgeneric_bumpmappedenvmap_ps14.inc | 57 + .../lightmappedgeneric_bumpmappedlightmap.inc | 57 + .../vshtmp9_360/lightmappedgeneric_vs11.inc | 175 + .../stdshaders/vshtmp9_360/overlay_fit_vs11.inc | 57 + materialsystem/stdshaders/vshtmp9_360/predator.inc | 82 + .../stdshaders/vshtmp9_360/shadow_vs14.inc | 57 + .../stdshaders/vshtmp9_360/sprite_vs11.inc | 100 + .../stdshaders/vshtmp9_360/unlitgeneric_vs11.inc | 225 + .../vertexlitgeneric_flashlight_vs11.inc | 109 + .../stdshaders/vshtmp9_360/vortwarp_vs11.inc | 134 + .../vshtmp9_360/worldvertextransition_seamless.inc | 57 + .../vshtmp9_360/worldvertextransition_vs14.inc | 57 + materialsystem/stdshaders/vshtmp9_360/writez.inc | 57 + materialsystem/stdshaders/warp.cpp | 251 + materialsystem/stdshaders/warp_ps2x.fxc | 210 + materialsystem/stdshaders/warp_vs20.fxc | 26 + materialsystem/stdshaders/water.cpp | 592 + materialsystem/stdshaders/water_dudv.cpp | 95 + materialsystem/stdshaders/water_dx60.cpp | 15 + materialsystem/stdshaders/water_dx80.cpp | 419 + materialsystem/stdshaders/water_dx81.cpp | 311 + materialsystem/stdshaders/water_ps2x.fxc | 110 + materialsystem/stdshaders/water_ps2x_helper.h | 239 + materialsystem/stdshaders/waterreflect_ps14.psh | 8 + materialsystem/stdshaders/waterrefract_ps14.psh | 23 + .../stdshaders/weapon_sheen_pass_helper.cpp | 291 + .../stdshaders/weapon_sheen_pass_helper.h | 51 + .../stdshaders/weapon_sheen_pass_ps2x.fxc | 199 + .../stdshaders/weapon_sheen_pass_vs20.fxc | 132 + materialsystem/stdshaders/white.psh | 8 + materialsystem/stdshaders/white_ps2x.fxc | 13 + materialsystem/stdshaders/windowimposter_dx80.cpp | 70 + materialsystem/stdshaders/windowimposter_dx90.cpp | 107 + materialsystem/stdshaders/windowimposter_ps11.fxc | 24 + materialsystem/stdshaders/windowimposter_ps2x.fxc | 37 + materialsystem/stdshaders/windowimposter_vs11.fxc | 42 + materialsystem/stdshaders/windowimposter_vs20.fxc | 45 + materialsystem/stdshaders/wireframe_dx8.cpp | 50 + materialsystem/stdshaders/wireframe_dx9.cpp | 52 + materialsystem/stdshaders/worldtwotextureblend.cpp | 500 + .../stdshaders/worldtwotextureblend_dx6.cpp | 258 + .../stdshaders/worldtwotextureblend_dx8.cpp | 175 + .../stdshaders/worldtwotextureblend_ps2x.fxc | 217 + materialsystem/stdshaders/worldvertexalpha.cpp | 259 + materialsystem/stdshaders/worldvertexalpha_dx8.cpp | 113 + .../stdshaders/worldvertextransition.cpp | 157 + .../stdshaders/worldvertextransition_dx6.cpp | 52 + .../worldvertextransition_dx6_helper.cpp | 206 + .../stdshaders/worldvertextransition_dx6_helper.h | 39 + .../worldvertextransition_dx8_helper.cpp | 81 + .../stdshaders/worldvertextransition_dx8_helper.h | 44 + materialsystem/stdshaders/writestencil_dx8.cpp | 61 + materialsystem/stdshaders/writestencil_dx9.cpp | 81 + .../writevertexalphatodestalpha_ps11.fxc | 18 + .../writevertexalphatodestalpha_vs11.fxc | 33 + materialsystem/stdshaders/writez.vsh | 22 + materialsystem/stdshaders/writez_dx6.cpp | 41 + materialsystem/stdshaders/writez_dx8.cpp | 60 + materialsystem/stdshaders/writez_dx9.cpp | 81 + materialsystem/stdshaders/writez_vs20.fxc | 24 + materialsystem/stdshaders/xbox/xbox_dbg.def | 4 + materialsystem/stdshaders/xbox/xbox_dx8.def | 4 + materialsystem/stdshaders/xbox/xbox_dx9.def | 4 + materialsystem/stdshaders/yuv.cpp | 62 + materialsystem/stdshaders/yuv.psh | 23 + materialsystem/texturemanager.cpp | 3102 ++++ materialsystem/texturemanager.h | 180 + materialsystem/wireframe.cpp | 58 + materialsystem/xbox/xbox.def | 3 + 1652 files changed, 268639 insertions(+) create mode 100644 materialsystem/CColorCorrection.cpp create mode 100644 materialsystem/CMaterialSubRect.cpp create mode 100644 materialsystem/IHardwareConfigInternal.h create mode 100644 materialsystem/IShaderSystem.h create mode 100644 materialsystem/MaterialSystem.rc create mode 100644 materialsystem/Resource.rc create mode 100644 materialsystem/checkmaterials.cpp create mode 100644 materialsystem/cmaterial.cpp create mode 100644 materialsystem/cmaterial_queuefriendly.cpp create mode 100644 materialsystem/cmaterial_queuefriendly.h create mode 100644 materialsystem/cmaterialdict.cpp create mode 100644 materialsystem/cmaterialdict.h create mode 100644 materialsystem/cmaterialsystem.cpp create mode 100644 materialsystem/cmaterialsystem.h create mode 100644 materialsystem/cmaterialvar.cpp create mode 100644 materialsystem/cmatlightmaps.cpp create mode 100644 materialsystem/cmatlightmaps.h create mode 100644 materialsystem/cmatnullrendercontext.cpp create mode 100644 materialsystem/cmatnullrendercontext.h create mode 100644 materialsystem/cmatqueuedrendercontext.cpp create mode 100644 materialsystem/cmatqueuedrendercontext.h create mode 100644 materialsystem/cmatrendercontext.cpp create mode 100644 materialsystem/cmatrendercontext.h create mode 100644 materialsystem/colorspace.cpp create mode 100644 materialsystem/colorspace.h create mode 100644 materialsystem/ctexture.cpp create mode 100644 materialsystem/ctexturecompositor.cpp create mode 100644 materialsystem/ctexturecompositor.h create mode 100644 materialsystem/genshadermacro.pl create mode 100644 materialsystem/imagepacker.cpp create mode 100644 materialsystem/imagepacker.h create mode 100644 materialsystem/imaterialinternal.h create mode 100644 materialsystem/imaterialsysteminternal.h create mode 100644 materialsystem/imatrendercontextinternal.h create mode 100644 materialsystem/imorphinternal.h create mode 100644 materialsystem/itextureinternal.h create mode 100644 materialsystem/mat_stub.cpp create mode 100644 materialsystem/materialsystem.vpc create mode 100644 materialsystem/materialsystem_global.cpp create mode 100644 materialsystem/materialsystem_global.h create mode 100644 materialsystem/morph.cpp create mode 100644 materialsystem/occlusionquerymgr.cpp create mode 100644 materialsystem/occlusionquerymgr.h create mode 100644 materialsystem/pch_materialsystem.cpp create mode 100644 materialsystem/pch_materialsystem.h create mode 100644 materialsystem/resource.h create mode 100644 materialsystem/shader_dll_verify.cpp create mode 100644 materialsystem/shader_dll_verify.h create mode 100644 materialsystem/shaderapidx9/ShaderShadowDx10.h create mode 100644 materialsystem/shaderapidx9/TransitionTable.cpp create mode 100644 materialsystem/shaderapidx9/TransitionTable.h create mode 100644 materialsystem/shaderapidx9/colorformatdx8.cpp create mode 100644 materialsystem/shaderapidx9/colorformatdx8.h create mode 100644 materialsystem/shaderapidx9/cvballoctracker.cpp create mode 100644 materialsystem/shaderapidx9/d3d_async.cpp create mode 100644 materialsystem/shaderapidx9/d3d_async.h create mode 100644 materialsystem/shaderapidx9/dx9hook.h create mode 100644 materialsystem/shaderapidx9/dynamicib.h create mode 100644 materialsystem/shaderapidx9/dynamicvb.h create mode 100644 materialsystem/shaderapidx9/gpubufferallocator.cpp create mode 100644 materialsystem/shaderapidx9/gpubufferallocator.h create mode 100644 materialsystem/shaderapidx9/hardwareconfig.cpp create mode 100644 materialsystem/shaderapidx9/hardwareconfig.h create mode 100644 materialsystem/shaderapidx9/imeshdx8.h create mode 100644 materialsystem/shaderapidx9/inputlayoutdx10.cpp create mode 100644 materialsystem/shaderapidx9/inputlayoutdx10.h create mode 100644 materialsystem/shaderapidx9/ivertexbufferdx8.h create mode 100644 materialsystem/shaderapidx9/locald3dtypes.h create mode 100644 materialsystem/shaderapidx9/meshbase.cpp create mode 100644 materialsystem/shaderapidx9/meshbase.h create mode 100644 materialsystem/shaderapidx9/meshdx10.cpp create mode 100644 materialsystem/shaderapidx9/meshdx10.h create mode 100644 materialsystem/shaderapidx9/meshdx8.cpp create mode 100644 materialsystem/shaderapidx9/recording.cpp create mode 100644 materialsystem/shaderapidx9/recording.h create mode 100644 materialsystem/shaderapidx9/shaderapi_global.h create mode 100644 materialsystem/shaderapidx9/shaderapibase.cpp create mode 100644 materialsystem/shaderapidx9/shaderapibase.h create mode 100644 materialsystem/shaderapidx9/shaderapidx10.cpp create mode 100644 materialsystem/shaderapidx9/shaderapidx10.h create mode 100644 materialsystem/shaderapidx9/shaderapidx10.vpc create mode 100644 materialsystem/shaderapidx9/shaderapidx10_global.h create mode 100644 materialsystem/shaderapidx9/shaderapidx8.cpp create mode 100644 materialsystem/shaderapidx9/shaderapidx8.h create mode 100644 materialsystem/shaderapidx9/shaderapidx8_global.h create mode 100644 materialsystem/shaderapidx9/shaderapidx9.vpc create mode 100644 materialsystem/shaderapidx9/shaderdevicebase.cpp create mode 100644 materialsystem/shaderapidx9/shaderdevicebase.h create mode 100644 materialsystem/shaderapidx9/shaderdevicedx10.cpp create mode 100644 materialsystem/shaderapidx9/shaderdevicedx10.h create mode 100644 materialsystem/shaderapidx9/shaderdevicedx8.cpp create mode 100644 materialsystem/shaderapidx9/shaderdevicedx8.h create mode 100644 materialsystem/shaderapidx9/shadershadowdx10.cpp create mode 100644 materialsystem/shaderapidx9/shadershadowdx8.cpp create mode 100644 materialsystem/shaderapidx9/shadershadowdx8.h create mode 100644 materialsystem/shaderapidx9/stubd3ddevice.h create mode 100644 materialsystem/shaderapidx9/texturedx8.cpp create mode 100644 materialsystem/shaderapidx9/texturedx8.h create mode 100644 materialsystem/shaderapidx9/textureheap.cpp create mode 100644 materialsystem/shaderapidx9/textureheap.h create mode 100644 materialsystem/shaderapidx9/vertexdecl.cpp create mode 100644 materialsystem/shaderapidx9/vertexdecl.h create mode 100644 materialsystem/shaderapidx9/vertexshaderdx8.cpp create mode 100644 materialsystem/shaderapidx9/vertexshaderdx8.h create mode 100644 materialsystem/shaderapidx9/winutils.cpp create mode 100644 materialsystem/shaderapidx9/winutils.h create mode 100644 materialsystem/shaderapidx9/wmi.cpp create mode 100644 materialsystem/shaderapidx9/wmi.h create mode 100644 materialsystem/shaderapidx9/xbox/xbox.def create mode 100644 materialsystem/shaderapiempty/shaderapiempty.cpp create mode 100644 materialsystem/shaderapiempty/shaderapiempty.vpc create mode 100644 materialsystem/shaderlib/BaseShader.cpp create mode 100644 materialsystem/shaderlib/ShaderDLL.cpp create mode 100644 materialsystem/shaderlib/shaderDLL_Global.h create mode 100644 materialsystem/shaderlib/shaderlib.vpc create mode 100644 materialsystem/shaderlib/shaderlib_cvar.cpp create mode 100644 materialsystem/shaderlib/shaderlib_cvar.h create mode 100644 materialsystem/shadersystem.cpp create mode 100644 materialsystem/shadersystem.h create mode 100644 materialsystem/stdshaders/AccumBuff4Sample.cpp create mode 100644 materialsystem/stdshaders/AccumBuff4Sample_ps2x.fxc create mode 100644 materialsystem/stdshaders/BaseVSShader.cpp create mode 100644 materialsystem/stdshaders/BaseVSShader.h create mode 100644 materialsystem/stdshaders/Bloom.cpp create mode 100644 materialsystem/stdshaders/Bloom_ps2x.fxc create mode 100644 materialsystem/stdshaders/BlurFilterX.cpp create mode 100644 materialsystem/stdshaders/BlurFilterX_dx80.cpp create mode 100644 materialsystem/stdshaders/BlurFilterY.cpp create mode 100644 materialsystem/stdshaders/BlurFilterY_dx80.cpp create mode 100644 materialsystem/stdshaders/BlurFilter_ps11.psh create mode 100644 materialsystem/stdshaders/BlurFilter_ps2x.fxc create mode 100644 materialsystem/stdshaders/BlurFilter_vs11.fxc create mode 100644 materialsystem/stdshaders/BlurFilter_vs20.fxc create mode 100644 materialsystem/stdshaders/BufferClearObeyStencil_dx6.cpp create mode 100644 materialsystem/stdshaders/BufferClearObeyStencil_dx8.cpp create mode 100644 materialsystem/stdshaders/BufferClearObeyStencil_dx9.cpp create mode 100644 materialsystem/stdshaders/BufferClearObeyStencil_ps11.psh create mode 100644 materialsystem/stdshaders/BufferClearObeyStencil_vs11.vsh create mode 100644 materialsystem/stdshaders/BumpmappedEnvmap.psh create mode 100644 materialsystem/stdshaders/BumpmappedEnvmap.vsh create mode 100644 materialsystem/stdshaders/BumpmappedLightmap.vsh create mode 100644 materialsystem/stdshaders/BumpmappedLightmap_LightingOnly_OverBright2.psh create mode 100644 materialsystem/stdshaders/BumpmappedLightmap_OverBright2.psh create mode 100644 materialsystem/stdshaders/Cable.psh create mode 100644 materialsystem/stdshaders/Cable.vsh create mode 100644 materialsystem/stdshaders/DebugDrawDepth_ps2x.fxc create mode 100644 materialsystem/stdshaders/DebugDrawDepth_vs20.fxc create mode 100644 materialsystem/stdshaders/DebugDrawEnvmapMask.cpp create mode 100644 materialsystem/stdshaders/DebugDrawEnvmapMask_ps2x.fxc create mode 100644 materialsystem/stdshaders/DebugDrawEnvmapMask_vs20.fxc create mode 100644 materialsystem/stdshaders/DebugTextureView.cpp create mode 100644 materialsystem/stdshaders/DebugTextureView_ps2x.fxc create mode 100644 materialsystem/stdshaders/DebugTextureView_vs20.fxc create mode 100644 materialsystem/stdshaders/DecalBaseTimesLightmapAlphaBlendSelfIllum1_ps11.psh create mode 100644 materialsystem/stdshaders/DecalBaseTimesLightmapAlphaBlendSelfIllum2_ps11.psh create mode 100644 materialsystem/stdshaders/DecalBaseTimesLightmapAlphaBlendSelfIllum_dx6.cpp create mode 100644 materialsystem/stdshaders/DecalBaseTimesLightmapAlphaBlendSelfIllum_dx8.cpp create mode 100644 materialsystem/stdshaders/DecalBaseTimesLightmapAlphaBlendSelfIllum_dx9.cpp create mode 100644 materialsystem/stdshaders/DecalModulate_dx9.cpp create mode 100644 materialsystem/stdshaders/Downsample.cpp create mode 100644 materialsystem/stdshaders/Downsample_nohdr_ps11.psh create mode 100644 materialsystem/stdshaders/Downsample_nohdr_ps2x.fxc create mode 100644 materialsystem/stdshaders/Downsample_ps2x.fxc create mode 100644 materialsystem/stdshaders/Downsample_vs11.fxc create mode 100644 materialsystem/stdshaders/Downsample_vs20.fxc create mode 100644 materialsystem/stdshaders/Engine_Post_dx9.cpp create mode 100644 materialsystem/stdshaders/Engine_Post_ps2x.fxc create mode 100644 materialsystem/stdshaders/Eyes.psh create mode 100644 materialsystem/stdshaders/Eyes_Overbright2.psh create mode 100644 materialsystem/stdshaders/Eyes_vs20.fxc create mode 100644 materialsystem/stdshaders/HDRCombineTo16Bit.cpp create mode 100644 materialsystem/stdshaders/HDRCombineTo16Bit_ps2x.fxc create mode 100644 materialsystem/stdshaders/HDRCombineTo16Bit_vs20.fxc create mode 100644 materialsystem/stdshaders/HDRSelectRange.cpp create mode 100644 materialsystem/stdshaders/HDRSelectRange_ps2x.fxc create mode 100644 materialsystem/stdshaders/HDRSelectRange_vs20.fxc create mode 100644 materialsystem/stdshaders/IntroScreenSpaceEffect_ps11.fxc create mode 100644 materialsystem/stdshaders/IntroScreenSpaceEffect_ps11_asm.psh create mode 100644 materialsystem/stdshaders/IntroScreenSpaceEffect_ps2x.fxc create mode 100644 materialsystem/stdshaders/JellyFish.psh create mode 100644 materialsystem/stdshaders/JellyFish.vsh create mode 100644 materialsystem/stdshaders/LightingOnly.vsh create mode 100644 materialsystem/stdshaders/LightmappedGeneric.psh create mode 100644 materialsystem/stdshaders/LightmappedGeneric_AddBaseAlphaMaskedEnvMap.psh create mode 100644 materialsystem/stdshaders/LightmappedGeneric_AddEnvMapMaskNoTexture.psh create mode 100644 materialsystem/stdshaders/LightmappedGeneric_AddEnvMapNoTexture.psh create mode 100644 materialsystem/stdshaders/LightmappedGeneric_BaseAlphaMaskedEnvMapV2.psh create mode 100644 materialsystem/stdshaders/LightmappedGeneric_BaseTexture.psh create mode 100644 materialsystem/stdshaders/LightmappedGeneric_BaseTexture.vsh create mode 100644 materialsystem/stdshaders/LightmappedGeneric_BaseTextureBlend.vsh create mode 100644 materialsystem/stdshaders/LightmappedGeneric_BumpmappedEnvmap.psh create mode 100644 materialsystem/stdshaders/LightmappedGeneric_BumpmappedEnvmap.vsh create mode 100644 materialsystem/stdshaders/LightmappedGeneric_BumpmappedEnvmap_ps14.psh create mode 100644 materialsystem/stdshaders/LightmappedGeneric_BumpmappedEnvmap_ps14.vsh create mode 100644 materialsystem/stdshaders/LightmappedGeneric_BumpmappedLightmap.psh create mode 100644 materialsystem/stdshaders/LightmappedGeneric_BumpmappedLightmap.vsh create mode 100644 materialsystem/stdshaders/LightmappedGeneric_BumpmappedLightmap_base_ps14.psh create mode 100644 materialsystem/stdshaders/LightmappedGeneric_BumpmappedLightmap_base_ps14.vsh create mode 100644 materialsystem/stdshaders/LightmappedGeneric_BumpmappedLightmap_blend_ps14.psh create mode 100644 materialsystem/stdshaders/LightmappedGeneric_BumpmappedLightmap_blend_ps14.vsh create mode 100644 materialsystem/stdshaders/LightmappedGeneric_Decal.psh create mode 100644 materialsystem/stdshaders/LightmappedGeneric_Decal.vsh create mode 100644 materialsystem/stdshaders/LightmappedGeneric_Detail.psh create mode 100644 materialsystem/stdshaders/LightmappedGeneric_DetailNoTexture.psh create mode 100644 materialsystem/stdshaders/LightmappedGeneric_DetailSelfIlluminated.psh create mode 100644 materialsystem/stdshaders/LightmappedGeneric_EnvMapNoTexture.psh create mode 100644 materialsystem/stdshaders/LightmappedGeneric_EnvMapV2.psh create mode 100644 materialsystem/stdshaders/LightmappedGeneric_LightingOnly.vsh create mode 100644 materialsystem/stdshaders/LightmappedGeneric_LightingOnly_Overbright2.psh create mode 100644 materialsystem/stdshaders/LightmappedGeneric_MaskedEnvMapNoTexture.psh create mode 100644 materialsystem/stdshaders/LightmappedGeneric_MaskedEnvMapV2.psh create mode 100644 materialsystem/stdshaders/LightmappedGeneric_MultiplyByLighting.psh create mode 100644 materialsystem/stdshaders/LightmappedGeneric_MultiplyByLightingNoTexture.psh create mode 100644 materialsystem/stdshaders/LightmappedGeneric_MultiplyByLightingSelfIllum.psh create mode 100644 materialsystem/stdshaders/LightmappedGeneric_NoTexture.psh create mode 100644 materialsystem/stdshaders/LightmappedGeneric_SSBumpmappedLightmap.psh create mode 100644 materialsystem/stdshaders/LightmappedGeneric_SelfIlluminated.psh create mode 100644 materialsystem/stdshaders/LightmappedGeneric_SelfIlluminatedEnvMapV2.psh create mode 100644 materialsystem/stdshaders/LightmappedGeneric_SelfIlluminatedMaskedEnvMapV2.psh create mode 100644 materialsystem/stdshaders/LightmappedGeneric_VertexColor.vsh create mode 100644 materialsystem/stdshaders/LightmappedTranslucentTexture.psh create mode 100644 materialsystem/stdshaders/LightmappedTranslucentTexture.vsh create mode 100644 materialsystem/stdshaders/Modulate_ps11.psh create mode 100644 materialsystem/stdshaders/MonitorScreen.psh create mode 100644 materialsystem/stdshaders/MonitorScreen_dx8.cpp create mode 100644 materialsystem/stdshaders/MonitorScreen_dx9.cpp create mode 100644 materialsystem/stdshaders/ParticleSphere.vsh create mode 100644 materialsystem/stdshaders/Refract_model_vs11.vsh create mode 100644 materialsystem/stdshaders/Refract_ps11.psh create mode 100644 materialsystem/stdshaders/Refract_vs20.fxc create mode 100644 materialsystem/stdshaders/Refract_world_vs11.vsh create mode 100644 materialsystem/stdshaders/ScreenSpaceEffect.vsh create mode 100644 materialsystem/stdshaders/SetZ.cpp create mode 100644 materialsystem/stdshaders/Shadow.psh create mode 100644 materialsystem/stdshaders/ShadowBuildTexture.psh create mode 100644 materialsystem/stdshaders/ShadowModel.psh create mode 100644 materialsystem/stdshaders/ShadowModel.vsh create mode 100644 materialsystem/stdshaders/ShatteredGlass.psh create mode 100644 materialsystem/stdshaders/ShatteredGlass.vsh create mode 100644 materialsystem/stdshaders/ShatteredGlass_EnvMap.psh create mode 100644 materialsystem/stdshaders/ShatteredGlass_EnvMap.vsh create mode 100644 materialsystem/stdshaders/ShatteredGlass_EnvMapSphere.vsh create mode 100644 materialsystem/stdshaders/ShatteredGlass_inc.vsh create mode 100644 materialsystem/stdshaders/ShatteredGlass_ps2x.fxc create mode 100644 materialsystem/stdshaders/ShatteredGlass_vs20.fxc create mode 100644 materialsystem/stdshaders/SpriteRenderNormal.psh create mode 100644 materialsystem/stdshaders/SpriteRenderTransAdd.psh create mode 100644 materialsystem/stdshaders/SpriteRenderTransColor.psh create mode 100644 materialsystem/stdshaders/Teeth.vsh create mode 100644 materialsystem/stdshaders/TreeLeaf.cpp create mode 100644 materialsystem/stdshaders/TreeLeaf_ps2x.fxc create mode 100644 materialsystem/stdshaders/TreeLeaf_vs20.fxc create mode 100644 materialsystem/stdshaders/UPDB_X360/dummy.txt create mode 100644 materialsystem/stdshaders/UnlitGeneric.psh create mode 100644 materialsystem/stdshaders/UnlitGeneric_BaseAlphaMaskedEnvMap.psh create mode 100644 materialsystem/stdshaders/UnlitGeneric_Detail.psh create mode 100644 materialsystem/stdshaders/UnlitGeneric_DetailBaseAlphaMaskedEnvMap.psh create mode 100644 materialsystem/stdshaders/UnlitGeneric_DetailEnvMap.psh create mode 100644 materialsystem/stdshaders/UnlitGeneric_DetailEnvMapMask.psh create mode 100644 materialsystem/stdshaders/UnlitGeneric_DetailEnvMapMaskNoTexture.psh create mode 100644 materialsystem/stdshaders/UnlitGeneric_DetailEnvMapNoTexture.psh create mode 100644 materialsystem/stdshaders/UnlitGeneric_DetailNoTexture.psh create mode 100644 materialsystem/stdshaders/UnlitGeneric_EnvMap.psh create mode 100644 materialsystem/stdshaders/UnlitGeneric_EnvMapMask.psh create mode 100644 materialsystem/stdshaders/UnlitGeneric_EnvMapMaskNoTexture.psh create mode 100644 materialsystem/stdshaders/UnlitGeneric_EnvMapNoTexture.psh create mode 100644 materialsystem/stdshaders/UnlitGeneric_LightingOnly.vsh create mode 100644 materialsystem/stdshaders/UnlitGeneric_MaskBaseByDetailAlpha_ps11.fxc create mode 100644 materialsystem/stdshaders/UnlitGeneric_NoTexture.psh create mode 100644 materialsystem/stdshaders/UnlitTwoTexture.psh create mode 100644 materialsystem/stdshaders/UnlitTwoTexture.vsh create mode 100644 materialsystem/stdshaders/VertexLitGeneric.psh create mode 100644 materialsystem/stdshaders/VertexLitGeneric_BaseAlphaMaskedEnvMapV2.psh create mode 100644 materialsystem/stdshaders/VertexLitGeneric_BlendTint.psh create mode 100644 materialsystem/stdshaders/VertexLitGeneric_Detail.psh create mode 100644 materialsystem/stdshaders/VertexLitGeneric_DetailBaseAlphaMaskedEnvMapV2.psh create mode 100644 materialsystem/stdshaders/VertexLitGeneric_DetailEnvMapV2.psh create mode 100644 materialsystem/stdshaders/VertexLitGeneric_DetailMaskedEnvMapV2.psh create mode 100644 materialsystem/stdshaders/VertexLitGeneric_DetailNoTexture.psh create mode 100644 materialsystem/stdshaders/VertexLitGeneric_DetailSelfIlluminated.psh create mode 100644 materialsystem/stdshaders/VertexLitGeneric_DetailSelfIlluminatedEnvMapV2.psh create mode 100644 materialsystem/stdshaders/VertexLitGeneric_DetailSelfIlluminatedMaskedEnvMapV2.psh create mode 100644 materialsystem/stdshaders/VertexLitGeneric_Detail_LerpBase.psh create mode 100644 materialsystem/stdshaders/VertexLitGeneric_Detail_additive.psh create mode 100644 materialsystem/stdshaders/VertexLitGeneric_Detail_additive_selfillum.psh create mode 100644 materialsystem/stdshaders/VertexLitGeneric_EnvMapNoTexture.psh create mode 100644 materialsystem/stdshaders/VertexLitGeneric_EnvMapV2.psh create mode 100644 materialsystem/stdshaders/VertexLitGeneric_EnvmappedBumpmapV2.psh create mode 100644 materialsystem/stdshaders/VertexLitGeneric_EnvmappedBumpmapV2_MultByAlpha.psh create mode 100644 materialsystem/stdshaders/VertexLitGeneric_EnvmappedBumpmapV2_MultByAlpha_ps14.psh create mode 100644 materialsystem/stdshaders/VertexLitGeneric_EnvmappedBumpmapV2_ps14.psh create mode 100644 materialsystem/stdshaders/VertexLitGeneric_EnvmappedBumpmap_NoLighting.vsh create mode 100644 materialsystem/stdshaders/VertexLitGeneric_EnvmappedBumpmap_NoLighting_ps14.vsh create mode 100644 materialsystem/stdshaders/VertexLitGeneric_MaskedEnvMapNoTexture.psh create mode 100644 materialsystem/stdshaders/VertexLitGeneric_MaskedEnvMapV2.psh create mode 100644 materialsystem/stdshaders/VertexLitGeneric_NoTexture.psh create mode 100644 materialsystem/stdshaders/VertexLitGeneric_SelfIllumOnly.psh create mode 100644 materialsystem/stdshaders/VertexLitGeneric_SelfIllumOnly.vsh create mode 100644 materialsystem/stdshaders/VertexLitGeneric_SelfIlluminated.psh create mode 100644 materialsystem/stdshaders/VertexLitGeneric_SelfIlluminatedEnvMapV2.psh create mode 100644 materialsystem/stdshaders/VertexLitGeneric_SelfIlluminatedMaskedEnvMapV2.psh create mode 100644 materialsystem/stdshaders/VertexLitTexture.psh create mode 100644 materialsystem/stdshaders/VertexLitTexture_Overbright2.psh create mode 100644 materialsystem/stdshaders/VertexTextureTest.cpp create mode 100644 materialsystem/stdshaders/WaterCheapFresnelOpaque_ps14.psh create mode 100644 materialsystem/stdshaders/WaterCheapFresnel_ps14.psh create mode 100644 materialsystem/stdshaders/WaterCheapNoFresnelOpaque_ps11.psh create mode 100644 materialsystem/stdshaders/WaterCheapNoFresnel_ps11.psh create mode 100644 materialsystem/stdshaders/WaterCheapOpaque_ps11.psh create mode 100644 materialsystem/stdshaders/WaterCheapOpaque_ps14.psh create mode 100644 materialsystem/stdshaders/WaterCheapPerVertexFresnel_vs11.vsh create mode 100644 materialsystem/stdshaders/WaterCheap_ps11.psh create mode 100644 materialsystem/stdshaders/WaterCheap_ps14.psh create mode 100644 materialsystem/stdshaders/WaterCheap_ps2x.fxc create mode 100644 materialsystem/stdshaders/WaterCheap_vs11.vsh create mode 100644 materialsystem/stdshaders/WaterCheap_vs14.vsh create mode 100644 materialsystem/stdshaders/WaterCheap_vs20.fxc create mode 100644 materialsystem/stdshaders/WaterReflect_ps11.psh create mode 100644 materialsystem/stdshaders/WaterRefractFresnel_ps11.psh create mode 100644 materialsystem/stdshaders/WaterRefract_ps11.psh create mode 100644 materialsystem/stdshaders/Water_ps14.psh create mode 100644 materialsystem/stdshaders/Water_ps14.vsh create mode 100644 materialsystem/stdshaders/Water_vs11.vsh create mode 100644 materialsystem/stdshaders/Water_vs20.fxc create mode 100644 materialsystem/stdshaders/WorldTexture.psh create mode 100644 materialsystem/stdshaders/WorldTwoTextureBlend.psh create mode 100644 materialsystem/stdshaders/WorldTwoTextureBlend_DetailAlpha.psh create mode 100644 materialsystem/stdshaders/WorldTwoTextureBlend_SelfIlluminated.psh create mode 100644 materialsystem/stdshaders/WorldVertexAlpha.psh create mode 100644 materialsystem/stdshaders/WorldVertexAlpha.vsh create mode 100644 materialsystem/stdshaders/WorldVertexAlpha_ps2x.fxc create mode 100644 materialsystem/stdshaders/WorldVertexTransition.psh create mode 100644 materialsystem/stdshaders/WorldVertexTransition.vsh create mode 100644 materialsystem/stdshaders/WorldVertexTransition_BlendBase2.psh create mode 100644 materialsystem/stdshaders/WorldVertexTransition_Editor.psh create mode 100644 materialsystem/stdshaders/WorldVertexTransition_Seamless.psh create mode 100644 materialsystem/stdshaders/WorldVertexTransition_Seamless.vsh create mode 100644 materialsystem/stdshaders/WorldVertexTransition_dx8.cpp create mode 100644 materialsystem/stdshaders/WorldVertexTransition_ps14.psh create mode 100644 materialsystem/stdshaders/WorldVertexTransition_ps2x.fxc create mode 100644 materialsystem/stdshaders/WorldVertexTransition_vs14.vsh create mode 100644 materialsystem/stdshaders/WorldVertexTransition_vs20.fxc create mode 100644 materialsystem/stdshaders/accumbuff5sample.cpp create mode 100644 materialsystem/stdshaders/accumbuff5sample_ps2x.fxc create mode 100644 materialsystem/stdshaders/aftershock.cpp create mode 100644 materialsystem/stdshaders/aftershock_helper.cpp create mode 100644 materialsystem/stdshaders/aftershock_helper.h create mode 100644 materialsystem/stdshaders/aftershock_ps2x.fxc create mode 100644 materialsystem/stdshaders/aftershock_vs20.fxc create mode 100644 materialsystem/stdshaders/alphadist_ps11.fxc create mode 100644 materialsystem/stdshaders/appchooser360movie_ps2x.fxc create mode 100644 materialsystem/stdshaders/bik_dx80.cpp create mode 100644 materialsystem/stdshaders/bik_dx81.cpp create mode 100644 materialsystem/stdshaders/bik_dx90.cpp create mode 100644 materialsystem/stdshaders/bik_ps11.psh create mode 100644 materialsystem/stdshaders/bik_ps14.psh create mode 100644 materialsystem/stdshaders/bik_ps2x.fxc create mode 100644 materialsystem/stdshaders/bik_vs11.vsh create mode 100644 materialsystem/stdshaders/bik_vs20.fxc create mode 100644 materialsystem/stdshaders/bloomadd_ps11.fxc create mode 100644 materialsystem/stdshaders/bloomadd_ps2x.fxc create mode 100644 materialsystem/stdshaders/bufferclearobeystencil_ps2x.fxc create mode 100644 materialsystem/stdshaders/bufferclearobeystencil_vs20.fxc create mode 100644 materialsystem/stdshaders/buildallshaders.bat create mode 100644 materialsystem/stdshaders/builddynamic.bat create mode 100644 materialsystem/stdshaders/buildshaders.bat create mode 100644 materialsystem/stdshaders/bumpmappedlightmap_vs11.fxc create mode 100644 materialsystem/stdshaders/cable_dx6.cpp create mode 100644 materialsystem/stdshaders/cable_dx8.cpp create mode 100644 materialsystem/stdshaders/cable_dx9.cpp create mode 100644 materialsystem/stdshaders/cable_ps2x.fxc create mode 100644 materialsystem/stdshaders/cable_vs20.fxc create mode 100644 materialsystem/stdshaders/clean.bat create mode 100644 materialsystem/stdshaders/cleantemps.bat create mode 100644 materialsystem/stdshaders/cloak.cpp create mode 100644 materialsystem/stdshaders/cloak_blended_pass_dx8_helper.cpp create mode 100644 materialsystem/stdshaders/cloak_blended_pass_dx8_ps11.psh create mode 100644 materialsystem/stdshaders/cloak_blended_pass_dx8_vs11.vsh create mode 100644 materialsystem/stdshaders/cloak_blended_pass_helper.cpp create mode 100644 materialsystem/stdshaders/cloak_blended_pass_helper.h create mode 100644 materialsystem/stdshaders/cloak_blended_pass_ps2x.fxc create mode 100644 materialsystem/stdshaders/cloak_blended_pass_vs20.fxc create mode 100644 materialsystem/stdshaders/cloak_dx9_helper.cpp create mode 100644 materialsystem/stdshaders/cloak_dx9_helper.h create mode 100644 materialsystem/stdshaders/cloak_ps2x.fxc create mode 100644 materialsystem/stdshaders/cloak_vs20.fxc create mode 100644 materialsystem/stdshaders/cloud.cpp create mode 100644 materialsystem/stdshaders/cloud_dx8.cpp create mode 100644 materialsystem/stdshaders/cloud_dx9.cpp create mode 100644 materialsystem/stdshaders/cloud_ps11.psh create mode 100644 materialsystem/stdshaders/cloud_ps20.fxc create mode 100644 materialsystem/stdshaders/cloud_vs11.vsh create mode 100644 materialsystem/stdshaders/cloud_vs20.fxc create mode 100644 materialsystem/stdshaders/color_projection.cpp create mode 100644 materialsystem/stdshaders/color_projection_ps2x.fxc create mode 100644 materialsystem/stdshaders/color_projection_vs20.fxc create mode 100644 materialsystem/stdshaders/colorcorrection.cpp create mode 100644 materialsystem/stdshaders/colorcorrection_ps2x.fxc create mode 100644 materialsystem/stdshaders/commandbuilder.h create mode 100644 materialsystem/stdshaders/common_flashlight_fxc.h create mode 100644 materialsystem/stdshaders/common_fxc.h create mode 100644 materialsystem/stdshaders/common_fxc2.h create mode 100644 materialsystem/stdshaders/common_hlsl_cpp_consts.h create mode 100644 materialsystem/stdshaders/common_lightmappedgeneric_fxc.h create mode 100644 materialsystem/stdshaders/common_pragmas.h create mode 100644 materialsystem/stdshaders/common_ps_fxc.h create mode 100644 materialsystem/stdshaders/common_vertexlitgeneric_dx9.h create mode 100644 materialsystem/stdshaders/common_vertexlitgeneric_vs20.fxc create mode 100644 materialsystem/stdshaders/common_vs_fxc.h create mode 100644 materialsystem/stdshaders/compositor.cpp create mode 100644 materialsystem/stdshaders/compositor_ps2x.fxc create mode 100644 materialsystem/stdshaders/compositor_vs20.fxc create mode 100644 materialsystem/stdshaders/constant_color_ps2x.fxc create mode 100644 materialsystem/stdshaders/copy_fp_rt_ps2x.fxc create mode 100644 materialsystem/stdshaders/core_dx7.cpp create mode 100644 materialsystem/stdshaders/core_dx8.cpp create mode 100644 materialsystem/stdshaders/core_dx9.cpp create mode 100644 materialsystem/stdshaders/core_ps11.psh create mode 100644 materialsystem/stdshaders/core_ps2x.fxc create mode 100644 materialsystem/stdshaders/core_vs11.fxc create mode 100644 materialsystem/stdshaders/core_vs20.fxc create mode 100644 materialsystem/stdshaders/cpp_shader_constant_register_map.h create mode 100644 materialsystem/stdshaders/debugdepth.cpp create mode 100644 materialsystem/stdshaders/debugluxel.cpp create mode 100644 materialsystem/stdshaders/debugluxel_ps2x.fxc create mode 100644 materialsystem/stdshaders/debugluxel_vs20.fxc create mode 100644 materialsystem/stdshaders/debugmodifyvertex.cpp create mode 100644 materialsystem/stdshaders/debugmorphaccumulator_dx9.cpp create mode 100644 materialsystem/stdshaders/debugmorphaccumulator_ps30.fxc create mode 100644 materialsystem/stdshaders/debugmorphaccumulator_vs30.fxc create mode 100644 materialsystem/stdshaders/debugmrttexture.cpp create mode 100644 materialsystem/stdshaders/debugmrttexture_ps2x.fxc create mode 100644 materialsystem/stdshaders/debugmrttexture_vs20.fxc create mode 100644 materialsystem/stdshaders/debugnormalmap.cpp create mode 100644 materialsystem/stdshaders/debugsoftwarevertexshader.cpp create mode 100644 materialsystem/stdshaders/debugtangentspace.cpp create mode 100644 materialsystem/stdshaders/debugtangentspace.vsh create mode 100644 materialsystem/stdshaders/debugtangentspace_vs11.fxc create mode 100644 materialsystem/stdshaders/debugtangentspace_vs20.fxc create mode 100644 materialsystem/stdshaders/decal.cpp create mode 100644 materialsystem/stdshaders/decalbasetimeslightmapalphablendselfillum2_ps2x.fxc create mode 100644 materialsystem/stdshaders/decalmodulate.cpp create mode 100644 materialsystem/stdshaders/decalmodulate_dx8.cpp create mode 100644 materialsystem/stdshaders/decalmodulate_ps11.psh create mode 100644 materialsystem/stdshaders/decalmodulate_ps2x.fxc create mode 100644 materialsystem/stdshaders/decalmodulate_vs11.vsh create mode 100644 materialsystem/stdshaders/depthtodestalpha_ps20b.fxc create mode 100644 materialsystem/stdshaders/depthtodestalpha_vs20.fxc create mode 100644 materialsystem/stdshaders/depthwrite.cpp create mode 100644 materialsystem/stdshaders/depthwrite_ps2x.fxc create mode 100644 materialsystem/stdshaders/depthwrite_vs20.fxc create mode 100644 materialsystem/stdshaders/detail.cpp create mode 100644 materialsystem/stdshaders/detail_ps11.psh create mode 100644 materialsystem/stdshaders/detail_vs11.vsh create mode 100644 materialsystem/stdshaders/downsample_nohdr.cpp create mode 100644 materialsystem/stdshaders/downsample_nohdr_dx80.cpp create mode 100644 materialsystem/stdshaders/dx8fallbacks.cpp create mode 100644 materialsystem/stdshaders/emissive_scroll_blended_pass_dx8_helper.cpp create mode 100644 materialsystem/stdshaders/emissive_scroll_blended_pass_dx8_ps11.psh create mode 100644 materialsystem/stdshaders/emissive_scroll_blended_pass_dx8_vs11.vsh create mode 100644 materialsystem/stdshaders/emissive_scroll_blended_pass_helper.cpp create mode 100644 materialsystem/stdshaders/emissive_scroll_blended_pass_helper.h create mode 100644 materialsystem/stdshaders/emissive_scroll_blended_pass_ps2x.fxc create mode 100644 materialsystem/stdshaders/emissive_scroll_blended_pass_vs20.fxc create mode 100644 materialsystem/stdshaders/example_model_dx9.cpp create mode 100644 materialsystem/stdshaders/example_model_dx9_helper.cpp create mode 100644 materialsystem/stdshaders/example_model_dx9_helper.h create mode 100644 materialsystem/stdshaders/example_model_ps20b.fxc create mode 100644 materialsystem/stdshaders/example_model_vs20.fxc create mode 100644 materialsystem/stdshaders/eye_refract.cpp create mode 100644 materialsystem/stdshaders/eye_refract_helper.cpp create mode 100644 materialsystem/stdshaders/eye_refract_helper.h create mode 100644 materialsystem/stdshaders/eye_refract_ps2x.fxc create mode 100644 materialsystem/stdshaders/eye_refract_vs20.fxc create mode 100644 materialsystem/stdshaders/eyeball.cpp create mode 100644 materialsystem/stdshaders/eyeglint_dx9.cpp create mode 100644 materialsystem/stdshaders/eyeglint_ps2x.fxc create mode 100644 materialsystem/stdshaders/eyeglint_vs20.fxc create mode 100644 materialsystem/stdshaders/eyes.cpp create mode 100644 materialsystem/stdshaders/eyes.vsh create mode 100644 materialsystem/stdshaders/eyes_dx6.cpp create mode 100644 materialsystem/stdshaders/eyes_dx8_dx9_helper.cpp create mode 100644 materialsystem/stdshaders/eyes_dx8_dx9_helper.h create mode 100644 materialsystem/stdshaders/eyes_dx9.cpp create mode 100644 materialsystem/stdshaders/eyes_flashlight2_ps11.psh create mode 100644 materialsystem/stdshaders/eyes_flashlight_inc.fxc create mode 100644 materialsystem/stdshaders/eyes_flashlight_ps11.fxc create mode 100644 materialsystem/stdshaders/eyes_flashlight_ps2x.fxc create mode 100644 materialsystem/stdshaders/eyes_flashlight_vs11.vsh create mode 100644 materialsystem/stdshaders/eyes_flashlight_vs20.fxc create mode 100644 materialsystem/stdshaders/eyes_ps2x.fxc create mode 100644 materialsystem/stdshaders/fillrate.cpp create mode 100644 materialsystem/stdshaders/fillrate.psh create mode 100644 materialsystem/stdshaders/fillrate.vsh create mode 100644 materialsystem/stdshaders/fillrate_ps11.fxc create mode 100644 materialsystem/stdshaders/fillrate_ps2x.fxc create mode 100644 materialsystem/stdshaders/fillrate_vs11.fxc create mode 100644 materialsystem/stdshaders/fillrate_vs20.fxc create mode 100644 materialsystem/stdshaders/filmdust_dx7.cpp create mode 100644 materialsystem/stdshaders/filmdust_dx8_dx9.cpp create mode 100644 materialsystem/stdshaders/filmdust_ps11.fxc create mode 100644 materialsystem/stdshaders/filmdust_ps20.fxc create mode 100644 materialsystem/stdshaders/filmgrain_dx7.cpp create mode 100644 materialsystem/stdshaders/filmgrain_dx8_dx9.cpp create mode 100644 materialsystem/stdshaders/filmgrain_ps11.fxc create mode 100644 materialsystem/stdshaders/filmgrain_ps20.fxc create mode 100644 materialsystem/stdshaders/filmgrain_vs20.fxc create mode 100644 materialsystem/stdshaders/flashlight_ps11.fxc create mode 100644 materialsystem/stdshaders/flashlight_ps2x.fxc create mode 100644 materialsystem/stdshaders/flesh_interior_blended_pass_dx8_helper.cpp create mode 100644 materialsystem/stdshaders/flesh_interior_blended_pass_dx8_ps11.psh create mode 100644 materialsystem/stdshaders/flesh_interior_blended_pass_dx8_vs11.vsh create mode 100644 materialsystem/stdshaders/flesh_interior_blended_pass_helper.cpp create mode 100644 materialsystem/stdshaders/flesh_interior_blended_pass_helper.h create mode 100644 materialsystem/stdshaders/flesh_interior_blended_pass_ps2x.fxc create mode 100644 materialsystem/stdshaders/flesh_interior_blended_pass_vs20.fxc create mode 100644 materialsystem/stdshaders/floatcombine.cpp create mode 100644 materialsystem/stdshaders/floatcombine_autoexpose.cpp create mode 100644 materialsystem/stdshaders/floatcombine_autoexpose_ps2x.fxc create mode 100644 materialsystem/stdshaders/floatcombine_ps2x.fxc create mode 100644 materialsystem/stdshaders/floattoscreen.cpp create mode 100644 materialsystem/stdshaders/floattoscreen_notonemap_ps2x.fxc create mode 100644 materialsystem/stdshaders/floattoscreen_ps2x.fxc create mode 100644 materialsystem/stdshaders/floattoscreen_vanilla.cpp create mode 100644 materialsystem/stdshaders/floattoscreen_vanilla_ps2x.fxc create mode 100644 materialsystem/stdshaders/fxctmp9/Bloom_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/Bloom_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/BlurFilter_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/BlurFilter_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/BlurFilter_vs11.inc create mode 100644 materialsystem/stdshaders/fxctmp9/BlurFilter_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/Downsample_nohdr_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/Downsample_nohdr_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/Downsample_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/Downsample_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/Downsample_vs11.inc create mode 100644 materialsystem/stdshaders/fxctmp9/Downsample_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/HDRCombineTo16Bit_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/HDRCombineTo16Bit_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/HDRCombineTo16Bit_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/HDRSelectRange_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/HDRSelectRange_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/HDRSelectRange_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/IntroScreenSpaceEffect_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/IntroScreenSpaceEffect_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/ParticleSphere_ps11.inc create mode 100644 materialsystem/stdshaders/fxctmp9/ParticleSphere_vs11.inc create mode 100644 materialsystem/stdshaders/fxctmp9/Refract_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/Refract_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/Refract_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/ShatteredGlass_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/ShatteredGlass_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/ShatteredGlass_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/VertexLit_and_unlit_Generic_bump_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/VertexLit_and_unlit_Generic_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/WaterCheap_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/WaterCheap_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/WaterCheap_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/Water_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/Water_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/WorldTwoTextureBlend_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/WorldTwoTextureBlend_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/accumbuff4sample_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/accumbuff4sample_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/accumbuff5sample_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/accumbuff5sample_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/aftershock_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/aftershock_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/aftershock_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/alphadist_ps11.inc create mode 100644 materialsystem/stdshaders/fxctmp9/appchooser360movie_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/appchooser360movie_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/bik_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/bik_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/bik_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/bloomadd_ps11.inc create mode 100644 materialsystem/stdshaders/fxctmp9/bloomadd_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/bloomadd_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/bufferclearobeystencil_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/bufferclearobeystencil_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/bufferclearobeystencil_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/bumpmappedlightmap_vs11.inc create mode 100644 materialsystem/stdshaders/fxctmp9/cable_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/cable_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/cable_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/cloak_blended_pass_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/cloak_blended_pass_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/cloak_blended_pass_ps30.inc create mode 100644 materialsystem/stdshaders/fxctmp9/cloak_blended_pass_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/cloak_blended_pass_vs30.inc create mode 100644 materialsystem/stdshaders/fxctmp9/cloak_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/cloak_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/cloak_ps30.inc create mode 100644 materialsystem/stdshaders/fxctmp9/cloak_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/cloak_vs30.inc create mode 100644 materialsystem/stdshaders/fxctmp9/cloud_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/cloud_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/color_projection_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/color_projection_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/color_projection_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/colorcorrection_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/colorcorrection_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/compositor_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/compositor_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/compositor_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/constant_color_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/constant_color_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/copy_fp_rt_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/copy_fp_rt_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/core_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/core_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/core_vs11.inc create mode 100644 materialsystem/stdshaders/fxctmp9/core_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/debugbumpmappedlightmap_ps11.inc create mode 100644 materialsystem/stdshaders/fxctmp9/debugbumpmappedlightmap_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/debugbumpmappedlightmap_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/debugdrawdepth_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/debugdrawdepth_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/debugdrawdepth_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/debugdrawenvmapmask_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/debugdrawenvmapmask_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/debugdrawenvmapmask_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/debugluxel_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/debugluxel_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/debugluxel_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/debugmorphaccumulator_ps30.inc create mode 100644 materialsystem/stdshaders/fxctmp9/debugmorphaccumulator_vs30.inc create mode 100644 materialsystem/stdshaders/fxctmp9/debugmrttexture_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/debugmrttexture_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/debugmrttexture_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/debugtangentspace_vs11.inc create mode 100644 materialsystem/stdshaders/fxctmp9/debugtangentspace_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/debugtextureview_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/debugtextureview_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/debugtextureview_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/decalbasetimeslightmapalphablendselfillum2_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/decalbasetimeslightmapalphablendselfillum2_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/decalmodulate_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/decalmodulate_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/decalmodulate_ps30.inc create mode 100644 materialsystem/stdshaders/fxctmp9/depthtodestalpha_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/depthtodestalpha_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/depthwrite_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/depthwrite_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/depthwrite_ps30.inc create mode 100644 materialsystem/stdshaders/fxctmp9/depthwrite_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/depthwrite_vs30.inc create mode 100644 materialsystem/stdshaders/fxctmp9/emissive_scroll_blended_pass_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/emissive_scroll_blended_pass_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/emissive_scroll_blended_pass_ps30.inc create mode 100644 materialsystem/stdshaders/fxctmp9/emissive_scroll_blended_pass_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/emissive_scroll_blended_pass_vs30.inc create mode 100644 materialsystem/stdshaders/fxctmp9/engine_post_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/engine_post_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/example_model_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/example_model_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/eye_refract_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/eye_refract_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/eye_refract_ps30.inc create mode 100644 materialsystem/stdshaders/fxctmp9/eye_refract_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/eye_refract_vs30.inc create mode 100644 materialsystem/stdshaders/fxctmp9/eyeglint_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/eyeglint_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/eyeglint_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/eyes_cloak_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/eyes_cloak_vs20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/eyes_flashlight_ps11.inc create mode 100644 materialsystem/stdshaders/fxctmp9/eyes_flashlight_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/eyes_flashlight_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/eyes_flashlight_ps30.inc create mode 100644 materialsystem/stdshaders/fxctmp9/eyes_flashlight_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/eyes_flashlight_vs30.inc create mode 100644 materialsystem/stdshaders/fxctmp9/eyes_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/eyes_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/eyes_ps30.inc create mode 100644 materialsystem/stdshaders/fxctmp9/eyes_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/eyes_vs30.inc create mode 100644 materialsystem/stdshaders/fxctmp9/fillrate_ps11.inc create mode 100644 materialsystem/stdshaders/fxctmp9/fillrate_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/fillrate_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/fillrate_vs11.inc create mode 100644 materialsystem/stdshaders/fxctmp9/fillrate_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/filmdust_ps11.inc create mode 100644 materialsystem/stdshaders/fxctmp9/filmdust_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/filmgrain_ps11.inc create mode 100644 materialsystem/stdshaders/fxctmp9/filmgrain_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/filmgrain_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/flashlight_ps11.inc create mode 100644 materialsystem/stdshaders/fxctmp9/flashlight_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/flashlight_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/flesh_interior_blended_pass_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/flesh_interior_blended_pass_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/flesh_interior_blended_pass_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/floatcombine_autoexpose_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/floatcombine_autoexpose_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/floatcombine_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/floatcombine_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/floattoscreen_notonemap_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/floattoscreen_notonemap_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/floattoscreen_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/floattoscreen_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/floattoscreen_vanilla_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/floattoscreen_vanilla_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/haloadd1d_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/haloadd1d_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/haloadd_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/haloadd_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/haloaddoutline_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/haloaddoutline_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/hsl_filmgrain_pass1_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/hsl_filmgrain_pass1_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/hsl_filmgrain_pass2_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/hsl_filmgrain_pass2_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/hsv_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/hsv_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/introscreenspaceeffect_ps11.inc create mode 100644 materialsystem/stdshaders/fxctmp9/lightingonly_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/lightmappedgeneric_decal_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/lightmappedgeneric_decal_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/lightmappedgeneric_decal_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/lightmappedgeneric_flashlight_vs11.inc create mode 100644 materialsystem/stdshaders/fxctmp9/lightmappedgeneric_flashlight_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/lightmappedgeneric_lightingonly_overbright2_ps11.inc create mode 100644 materialsystem/stdshaders/fxctmp9/lightmappedgeneric_lightingonly_vs11.inc create mode 100644 materialsystem/stdshaders/fxctmp9/lightmappedgeneric_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/lightmappedgeneric_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/lightmappedgeneric_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/lightmappedreflective_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/lightmappedreflective_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/lightmappedreflective_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/lpreview1_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/lpreview1_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/lpreview_output_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/lpreview_output_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/luminance_compare_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/luminance_compare_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/modulate_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/modulate_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/monitorscreen_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/monitorscreen_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/morphaccumulate_ps30.inc create mode 100644 materialsystem/stdshaders/fxctmp9/morphaccumulate_vs30.inc create mode 100644 materialsystem/stdshaders/fxctmp9/morphweight_ps30.inc create mode 100644 materialsystem/stdshaders/fxctmp9/morphweight_vs30.inc create mode 100644 materialsystem/stdshaders/fxctmp9/motion_blur_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/motion_blur_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/motion_blur_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/particlelit_generic_ps30.inc create mode 100644 materialsystem/stdshaders/fxctmp9/particlelit_generic_vs30.inc create mode 100644 materialsystem/stdshaders/fxctmp9/particlesphere_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/particlesphere_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/particlesphere_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/portal_ps11.inc create mode 100644 materialsystem/stdshaders/fxctmp9/portal_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/portal_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/portal_refract_ps11.inc create mode 100644 materialsystem/stdshaders/fxctmp9/portal_refract_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/portal_refract_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/portal_refract_vs11.inc create mode 100644 materialsystem/stdshaders/fxctmp9/portal_refract_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/portal_vs11.inc create mode 100644 materialsystem/stdshaders/fxctmp9/portal_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/portalstaticoverlay_ps11.inc create mode 100644 materialsystem/stdshaders/fxctmp9/portalstaticoverlay_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/portalstaticoverlay_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/portalstaticoverlay_vs11.inc create mode 100644 materialsystem/stdshaders/fxctmp9/portalstaticoverlay_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/pyro_vision_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/pyro_vision_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/pyro_vision_ps30.inc create mode 100644 materialsystem/stdshaders/fxctmp9/pyro_vision_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/pyro_vision_vs30.inc create mode 100644 materialsystem/stdshaders/fxctmp9/rendertargetblit_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/rendertargetblit_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/rendertargetblit_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/sample4x4_blend_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/sample4x4_blend_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/sample4x4_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/sample4x4_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/sample4x4delog_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/sample4x4delog_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/sample4x4log_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/sample4x4log_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/sample4x4maxmin_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/sample4x4maxmin_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/screenspaceeffect_vs11.inc create mode 100644 materialsystem/stdshaders/fxctmp9/screenspaceeffect_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/sfm_combine_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/sfm_integercombine_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/sfm_integercombine_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/shadow_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/shadow_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/shadow_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/shadowbuildtexture_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/shadowbuildtexture_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/shadowmodel_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/shadowmodel_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/showz_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/showz_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/showz_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/skin_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/skin_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/skin_ps30.inc create mode 100644 materialsystem/stdshaders/fxctmp9/skin_ps30b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/skin_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/skin_vs30.inc create mode 100644 materialsystem/stdshaders/fxctmp9/sky_hdr_compressed_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/sky_hdr_compressed_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/sky_hdr_compressed_rgbs_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/sky_hdr_compressed_rgbs_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/sky_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/sky_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/sky_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/splinecard_vs11.inc create mode 100644 materialsystem/stdshaders/fxctmp9/splinecard_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/sprite_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/sprite_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/sprite_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/spritecard_ps11.inc create mode 100644 materialsystem/stdshaders/fxctmp9/spritecard_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/spritecard_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/spritecard_vs11.inc create mode 100644 materialsystem/stdshaders/fxctmp9/spritecard_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/teeth_bump_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/teeth_bump_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/teeth_bump_ps30.inc create mode 100644 materialsystem/stdshaders/fxctmp9/teeth_bump_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/teeth_bump_vs30.inc create mode 100644 materialsystem/stdshaders/fxctmp9/teeth_flashlight_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/teeth_flashlight_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/teeth_flashlight_ps30.inc create mode 100644 materialsystem/stdshaders/fxctmp9/teeth_flashlight_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/teeth_flashlight_vs30.inc create mode 100644 materialsystem/stdshaders/fxctmp9/teeth_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/teeth_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/teeth_ps30.inc create mode 100644 materialsystem/stdshaders/fxctmp9/teeth_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/teeth_vs30.inc create mode 100644 materialsystem/stdshaders/fxctmp9/treeleaf_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/treeleaf_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/treeleaf_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/unlitgeneric_lightingonly_vs11.inc create mode 100644 materialsystem/stdshaders/fxctmp9/unlitgeneric_maskbasebydetailalpha_ps11.inc create mode 100644 materialsystem/stdshaders/fxctmp9/unlitgeneric_notexture_ps11.inc create mode 100644 materialsystem/stdshaders/fxctmp9/unlitgeneric_notexture_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/unlitgeneric_notexture_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/unlitgeneric_ps11.inc create mode 100644 materialsystem/stdshaders/fxctmp9/unlitgeneric_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/unlitgeneric_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/unlitgeneric_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/unlittwotexture_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/unlittwotexture_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/unlittwotexture_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/vertexlit_and_unlit_generic_bump_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/vertexlit_and_unlit_generic_bump_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/vertexlit_and_unlit_generic_bump_ps30.inc create mode 100644 materialsystem/stdshaders/fxctmp9/vertexlit_and_unlit_generic_bump_vs30.inc create mode 100644 materialsystem/stdshaders/fxctmp9/vertexlit_and_unlit_generic_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/vertexlit_and_unlit_generic_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/vertexlit_and_unlit_generic_ps30.inc create mode 100644 materialsystem/stdshaders/fxctmp9/vertexlit_and_unlit_generic_vs30.inc create mode 100644 materialsystem/stdshaders/fxctmp9/vertexlit_lighting_only_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/vertexlit_lighting_only_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/vertexlitgeneric_lightingonly_overbright2_ps11.inc create mode 100644 materialsystem/stdshaders/fxctmp9/volume_clouds_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/volume_clouds_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/volume_clouds_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/vortwarp_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/vortwarp_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/vortwarp_ps30.inc create mode 100644 materialsystem/stdshaders/fxctmp9/vortwarp_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/vortwarp_vs30.inc create mode 100644 materialsystem/stdshaders/fxctmp9/vr_distort_hud_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/vr_distort_hud_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/vr_distort_hud_ps30.inc create mode 100644 materialsystem/stdshaders/fxctmp9/vr_distort_hud_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/vr_distort_hud_vs30.inc create mode 100644 materialsystem/stdshaders/fxctmp9/vr_distort_texture_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/vr_distort_texture_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/vr_distort_texture_ps30.inc create mode 100644 materialsystem/stdshaders/fxctmp9/vr_distort_texture_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/vr_distort_texture_vs30.inc create mode 100644 materialsystem/stdshaders/fxctmp9/warp_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/warp_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/warp_ps30.inc create mode 100644 materialsystem/stdshaders/fxctmp9/warp_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/warp_vs30.inc create mode 100644 materialsystem/stdshaders/fxctmp9/water_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/weapon_sheen_pass_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/weapon_sheen_pass_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/weapon_sheen_pass_ps30.inc create mode 100644 materialsystem/stdshaders/fxctmp9/weapon_sheen_pass_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/weapon_sheen_pass_vs30.inc create mode 100644 materialsystem/stdshaders/fxctmp9/white_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/white_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/windowimposter_ps11.inc create mode 100644 materialsystem/stdshaders/fxctmp9/windowimposter_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/windowimposter_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/windowimposter_vs11.inc create mode 100644 materialsystem/stdshaders/fxctmp9/windowimposter_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/worldvertexalpha_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9/worldvertexalpha_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9/writevertexalphatodestalpha_ps11.inc create mode 100644 materialsystem/stdshaders/fxctmp9/writevertexalphatodestalpha_vs11.inc create mode 100644 materialsystem/stdshaders/fxctmp9/writez_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/Bloom_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/Bloom_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/BlurFilter_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/BlurFilter_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/BlurFilter_vs11.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/BlurFilter_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/Downsample_nohdr_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/Downsample_nohdr_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/Downsample_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/Downsample_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/Downsample_vs11.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/Downsample_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/HDRCombineTo16Bit_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/HDRCombineTo16Bit_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/HDRCombineTo16Bit_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/HDRSelectRange_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/HDRSelectRange_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/HDRSelectRange_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/IntroScreenSpaceEffect_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/IntroScreenSpaceEffect_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/ParticleSphere_ps11.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/ParticleSphere_vs11.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/Refract_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/Refract_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/ShatteredGlass_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/ShatteredGlass_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/ShatteredGlass_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/VertexLit_and_unlit_Generic_bump_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/VertexLit_and_unlit_Generic_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/WaterCheap_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/WaterCheap_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/WaterCheap_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/Water_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/Water_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/WorldTwoTextureBlend_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/WorldTwoTextureBlend_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/accumbuff4sample_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/accumbuff4sample_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/accumbuff5sample_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/accumbuff5sample_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/aftershock_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/aftershock_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/aftershock_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/alphadist_ps11.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/appchooser360movie_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/appchooser360movie_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/bik_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/bik_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/bik_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/bloomadd_ps11.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/bloomadd_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/bloomadd_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/bufferclearobeystencil_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/bufferclearobeystencil_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/bufferclearobeystencil_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/bumpmappedlightmap_vs11.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/cable_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/cable_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/cable_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/cloak_blended_pass_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/cloak_blended_pass_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/cloak_blended_pass_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/cloak_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/cloak_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/cloak_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/cloud_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/cloud_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/color_projection_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/color_projection_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/color_projection_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/colorcorrection_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/colorcorrection_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/constant_color_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/constant_color_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/copy_fp_rt_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/copy_fp_rt_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/core_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/core_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/core_vs11.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/core_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/debugdrawdepth_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/debugdrawdepth_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/debugdrawdepth_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/debugdrawenvmapmask_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/debugdrawenvmapmask_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/debugdrawenvmapmask_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/debugmrttexture_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/debugmrttexture_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/debugmrttexture_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/debugtangentspace_vs11.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/debugtangentspace_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/debugtextureview_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/debugtextureview_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/debugtextureview_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/decalbasetimeslightmapalphablendselfillum2_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/decalbasetimeslightmapalphablendselfillum2_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/decalmodulate_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/decalmodulate_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/depthtodestalpha_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/depthtodestalpha_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/depthwrite_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/depthwrite_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/depthwrite_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/emissive_scroll_blended_pass_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/emissive_scroll_blended_pass_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/emissive_scroll_blended_pass_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/engine_post_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/engine_post_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/eye_refract_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/eye_refract_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/eye_refract_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/eyeglint_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/eyeglint_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/eyeglint_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/eyes_flashlight_ps11.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/eyes_flashlight_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/eyes_flashlight_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/eyes_flashlight_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/eyes_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/eyes_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/eyes_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/fillrate_ps11.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/fillrate_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/fillrate_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/fillrate_vs11.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/fillrate_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/filmdust_ps11.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/filmdust_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/filmgrain_ps11.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/filmgrain_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/filmgrain_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/flashlight_ps11.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/flashlight_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/flashlight_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/flesh_interior_blended_pass_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/flesh_interior_blended_pass_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/flesh_interior_blended_pass_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/floatcombine_autoexpose_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/floatcombine_autoexpose_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/floatcombine_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/floatcombine_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/floattoscreen_notonemap_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/floattoscreen_notonemap_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/floattoscreen_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/floattoscreen_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/floattoscreen_vanilla_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/floattoscreen_vanilla_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/haloadd1d_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/haloadd1d_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/haloadd_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/haloadd_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/haloaddoutline_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/haloaddoutline_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/hsl_filmgrain_pass1_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/hsl_filmgrain_pass1_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/hsl_filmgrain_pass2_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/hsl_filmgrain_pass2_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/hsv_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/hsv_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/introscreenspaceeffect_ps11.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/lightmappedgeneric_decal_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/lightmappedgeneric_decal_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/lightmappedgeneric_decal_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/lightmappedgeneric_flashlight_vs11.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/lightmappedgeneric_flashlight_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/lightmappedgeneric_lightingonly_overbright2_ps11.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/lightmappedgeneric_lightingonly_vs11.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/lightmappedgeneric_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/lightmappedgeneric_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/lightmappedgeneric_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/lightmappedreflective_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/lightmappedreflective_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/lightmappedreflective_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/lpreview1_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/lpreview1_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/lpreview_output_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/lpreview_output_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/luminance_compare_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/luminance_compare_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/modulate_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/modulate_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/monitorscreen_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/monitorscreen_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/motion_blur_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/motion_blur_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/motion_blur_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/particlesphere_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/particlesphere_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/particlesphere_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/portal_ps11.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/portal_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/portal_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/portal_refract_ps11.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/portal_refract_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/portal_refract_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/portal_refract_vs11.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/portal_refract_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/portal_vs11.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/portal_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/portalstaticoverlay_ps11.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/portalstaticoverlay_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/portalstaticoverlay_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/portalstaticoverlay_vs11.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/portalstaticoverlay_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/refract_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/rendertargetblit_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/rendertargetblit_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/rendertargetblit_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/sample4x4_blend_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/sample4x4_blend_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/sample4x4_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/sample4x4_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/sample4x4delog_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/sample4x4delog_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/sample4x4log_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/sample4x4log_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/sample4x4maxmin_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/sample4x4maxmin_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/screenspaceeffect_vs11.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/screenspaceeffect_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/sfm_combine_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/sfm_integercombine_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/sfm_integercombine_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/shadow_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/shadow_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/shadow_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/shadowbuildtexture_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/shadowbuildtexture_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/shadowmodel_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/shadowmodel_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/showz_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/showz_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/showz_vs11.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/showz_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/skin_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/skin_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/sky_hdr_compressed_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/sky_hdr_compressed_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/sky_hdr_compressed_rgbs_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/sky_hdr_compressed_rgbs_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/sky_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/sky_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/sky_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/splinecard_vs11.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/splinecard_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/sprite_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/sprite_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/sprite_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/spritecard_ps11.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/spritecard_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/spritecard_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/spritecard_vs11.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/spritecard_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/teeth_bump_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/teeth_bump_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/teeth_bump_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/teeth_flashlight_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/teeth_flashlight_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/teeth_flashlight_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/teeth_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/teeth_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/teeth_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/treeleaf_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/treeleaf_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/treeleaf_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/unlitgeneric_maskbasebydetailalpha_ps11.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/unlitgeneric_notexture_ps11.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/unlitgeneric_notexture_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/unlitgeneric_notexture_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/unlitgeneric_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/unlitgeneric_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/unlitgeneric_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/unlittwotexture_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/unlittwotexture_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/unlittwotexture_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/vertexlit_and_unlit_generic_bump_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/vertexlit_and_unlit_generic_bump_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/vertexlit_and_unlit_generic_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/vertexlit_and_unlit_generic_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/vertexlitgeneric_lightingonly_overbright2_ps11.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/volume_clouds_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/volume_clouds_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/volume_clouds_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/vortwarp_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/vortwarp_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/vortwarp_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/water_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/white_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/white_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/windowimposter_ps11.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/windowimposter_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/windowimposter_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/windowimposter_vs11.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/windowimposter_vs20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/worldvertexalpha_ps20.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/worldvertexalpha_ps20b.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/writevertexalphatodestalpha_ps11.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/writevertexalphatodestalpha_vs11.inc create mode 100644 materialsystem/stdshaders/fxctmp9_360/writez_vs20.inc create mode 100644 materialsystem/stdshaders/genwaterloop.pl create mode 100644 materialsystem/stdshaders/glowwarp.psh create mode 100644 materialsystem/stdshaders/gooinglass.cpp create mode 100644 materialsystem/stdshaders/haloadd1d_ps2x.fxc create mode 100644 materialsystem/stdshaders/haloadd_ps2x.fxc create mode 100644 materialsystem/stdshaders/haloaddoutline_ps2x.fxc create mode 100644 materialsystem/stdshaders/hsl_filmgrain_pass1.cpp create mode 100644 materialsystem/stdshaders/hsl_filmgrain_pass1_ps2x.fxc create mode 100644 materialsystem/stdshaders/hsl_filmgrain_pass2.cpp create mode 100644 materialsystem/stdshaders/hsl_filmgrain_pass2_ps2x.fxc create mode 100644 materialsystem/stdshaders/hsv.cpp create mode 100644 materialsystem/stdshaders/hsv_ps2x.fxc create mode 100644 materialsystem/stdshaders/introscreenspaceeffect.cpp create mode 100644 materialsystem/stdshaders/introscreenspaceeffect_dx60.cpp create mode 100644 materialsystem/stdshaders/introscreenspaceeffect_dx80.cpp create mode 100644 materialsystem/stdshaders/jellyfish.cpp create mode 100644 materialsystem/stdshaders/lightingonly_vs20.fxc create mode 100644 materialsystem/stdshaders/lightmappedenvmappedbumpmappedtexture.psh create mode 100644 materialsystem/stdshaders/lightmappedgeneric_basealphamaskedenvmap.psh create mode 100644 materialsystem/stdshaders/lightmappedgeneric_basetextureblend.psh create mode 100644 materialsystem/stdshaders/lightmappedgeneric_decal.cpp create mode 100644 materialsystem/stdshaders/lightmappedgeneric_decal_ps2x.fxc create mode 100644 materialsystem/stdshaders/lightmappedgeneric_decal_vs20.fxc create mode 100644 materialsystem/stdshaders/lightmappedgeneric_dx6.cpp create mode 100644 materialsystem/stdshaders/lightmappedgeneric_dx8.cpp create mode 100644 materialsystem/stdshaders/lightmappedgeneric_dx9.cpp create mode 100644 materialsystem/stdshaders/lightmappedgeneric_dx9_helper.cpp create mode 100644 materialsystem/stdshaders/lightmappedgeneric_dx9_helper.h create mode 100644 materialsystem/stdshaders/lightmappedgeneric_envmap.psh create mode 100644 materialsystem/stdshaders/lightmappedgeneric_flashlight_vs11.fxc create mode 100644 materialsystem/stdshaders/lightmappedgeneric_flashlight_vs20.fxc create mode 100644 materialsystem/stdshaders/lightmappedgeneric_inc.vsh create mode 100644 materialsystem/stdshaders/lightmappedgeneric_lightingonly_overbright2_ps11.fxc create mode 100644 materialsystem/stdshaders/lightmappedgeneric_lightingonly_vs11.fxc create mode 100644 materialsystem/stdshaders/lightmappedgeneric_maskedenvmap.psh create mode 100644 materialsystem/stdshaders/lightmappedgeneric_multiplybylightingbasealphamaskedselfillum.psh create mode 100644 materialsystem/stdshaders/lightmappedgeneric_multiplybylightingbasenotexture.psh create mode 100644 materialsystem/stdshaders/lightmappedgeneric_ps11.fxc create mode 100644 materialsystem/stdshaders/lightmappedgeneric_ps2_3_x.h create mode 100644 materialsystem/stdshaders/lightmappedgeneric_ps2x.fxc create mode 100644 materialsystem/stdshaders/lightmappedgeneric_selfilluminatedenvmap.psh create mode 100644 materialsystem/stdshaders/lightmappedgeneric_selfilluminatedmaskedenvmap.psh create mode 100644 materialsystem/stdshaders/lightmappedgeneric_vs11.vsh create mode 100644 materialsystem/stdshaders/lightmappedgeneric_vs20.fxc create mode 100644 materialsystem/stdshaders/lightmappedreflective.cpp create mode 100644 materialsystem/stdshaders/lightmappedreflective_ps2x.fxc create mode 100644 materialsystem/stdshaders/lightmappedreflective_vs20.fxc create mode 100644 materialsystem/stdshaders/lightmappedtexture.psh create mode 100644 materialsystem/stdshaders/lightmappedtwotexture.cpp create mode 100644 materialsystem/stdshaders/lpreview1_ps2x.fxc create mode 100644 materialsystem/stdshaders/lpreview_output_ps2x.fxc create mode 100644 materialsystem/stdshaders/luminance_compare_ps2x.fxc create mode 100644 materialsystem/stdshaders/macros.vsh create mode 100644 materialsystem/stdshaders/modeldiffusebump.psh create mode 100644 materialsystem/stdshaders/modeldiffusebump2.psh create mode 100644 materialsystem/stdshaders/modelenvmappedbumpmapv2.psh create mode 100644 materialsystem/stdshaders/modelenvmappedbumpmapv2_multbyalpha.psh create mode 100644 materialsystem/stdshaders/modulate_dx6.cpp create mode 100644 materialsystem/stdshaders/modulate_dx8.cpp create mode 100644 materialsystem/stdshaders/modulate_dx9.cpp create mode 100644 materialsystem/stdshaders/modulate_ps2x.fxc create mode 100644 materialsystem/stdshaders/modulate_vs11.vsh create mode 100644 materialsystem/stdshaders/monitorscreen_ps2x.fxc create mode 100644 materialsystem/stdshaders/morphaccumulate_dx9.cpp create mode 100644 materialsystem/stdshaders/morphaccumulate_ps30.fxc create mode 100644 materialsystem/stdshaders/morphaccumulate_vs30.fxc create mode 100644 materialsystem/stdshaders/morphweight_dx9.cpp create mode 100644 materialsystem/stdshaders/morphweight_ps30.fxc create mode 100644 materialsystem/stdshaders/morphweight_vs30.fxc create mode 100644 materialsystem/stdshaders/motion_blur_dx9.cpp create mode 100644 materialsystem/stdshaders/motion_blur_ps2x.fxc create mode 100644 materialsystem/stdshaders/motion_blur_vs20.fxc create mode 100644 materialsystem/stdshaders/occlusion_dx8.cpp create mode 100644 materialsystem/stdshaders/occlusion_dx9.cpp create mode 100644 materialsystem/stdshaders/overlay_fit.cpp create mode 100644 materialsystem/stdshaders/overlay_fit_ps11.psh create mode 100644 materialsystem/stdshaders/overlay_fit_vs11.vsh create mode 100644 materialsystem/stdshaders/particlelitgeneric_dx9.cpp create mode 100644 materialsystem/stdshaders/particlelitgeneric_dx9_helper.cpp create mode 100644 materialsystem/stdshaders/particlelitgeneric_dx9_helper.h create mode 100644 materialsystem/stdshaders/particlesphere.psh create mode 100644 materialsystem/stdshaders/particlesphere_dx8.cpp create mode 100644 materialsystem/stdshaders/particlesphere_dx9.cpp create mode 100644 materialsystem/stdshaders/particlesphere_ps11.fxc create mode 100644 materialsystem/stdshaders/particlesphere_ps2x.fxc create mode 100644 materialsystem/stdshaders/particlesphere_vs11.fxc create mode 100644 materialsystem/stdshaders/particlesphere_vs20.fxc create mode 100644 materialsystem/stdshaders/portal.cpp create mode 100644 materialsystem/stdshaders/portal_dx60.cpp create mode 100644 materialsystem/stdshaders/portal_dx80.cpp create mode 100644 materialsystem/stdshaders/portal_ps11.fxc create mode 100644 materialsystem/stdshaders/portal_ps2x.fxc create mode 100644 materialsystem/stdshaders/portal_refract.cpp create mode 100644 materialsystem/stdshaders/portal_refract_dx8.cpp create mode 100644 materialsystem/stdshaders/portal_refract_dx8_helper.cpp create mode 100644 materialsystem/stdshaders/portal_refract_dx8_helper.h create mode 100644 materialsystem/stdshaders/portal_refract_helper.cpp create mode 100644 materialsystem/stdshaders/portal_refract_helper.h create mode 100644 materialsystem/stdshaders/portal_refract_ps11.fxc create mode 100644 materialsystem/stdshaders/portal_refract_ps2x.fxc create mode 100644 materialsystem/stdshaders/portal_refract_vs11.fxc create mode 100644 materialsystem/stdshaders/portal_refract_vs20.fxc create mode 100644 materialsystem/stdshaders/portal_vs11.fxc create mode 100644 materialsystem/stdshaders/portal_vs20.fxc create mode 100644 materialsystem/stdshaders/portalstaticoverlay.cpp create mode 100644 materialsystem/stdshaders/portalstaticoverlay_dx60.cpp create mode 100644 materialsystem/stdshaders/portalstaticoverlay_dx80.cpp create mode 100644 materialsystem/stdshaders/portalstaticoverlay_ps11.fxc create mode 100644 materialsystem/stdshaders/portalstaticoverlay_ps2x.fxc create mode 100644 materialsystem/stdshaders/portalstaticoverlay_vs11.fxc create mode 100644 materialsystem/stdshaders/portalstaticoverlay_vs20.fxc create mode 100644 materialsystem/stdshaders/predator.cpp create mode 100644 materialsystem/stdshaders/predator.psh create mode 100644 materialsystem/stdshaders/predator.vsh create mode 100644 materialsystem/stdshaders/predator_envmap.psh create mode 100644 materialsystem/stdshaders/pyro_vision.cpp create mode 100644 materialsystem/stdshaders/pyro_vision_ps2x.fxc create mode 100644 materialsystem/stdshaders/pyro_vision_vs20.fxc create mode 100644 materialsystem/stdshaders/refract.cpp create mode 100644 materialsystem/stdshaders/refract_dx60.cpp create mode 100644 materialsystem/stdshaders/refract_dx80.cpp create mode 100644 materialsystem/stdshaders/refract_dx9_helper.cpp create mode 100644 materialsystem/stdshaders/refract_dx9_helper.h create mode 100644 materialsystem/stdshaders/refract_ps2x.fxc create mode 100644 materialsystem/stdshaders/rendertargetblit_ps2x.fxc create mode 100644 materialsystem/stdshaders/rendertargetblit_vs20.fxc create mode 100644 materialsystem/stdshaders/rendertargetblit_x360.cpp create mode 100644 materialsystem/stdshaders/rift_dx6.cpp create mode 100644 materialsystem/stdshaders/rift_dx8.cpp create mode 100644 materialsystem/stdshaders/rift_ps11.psh create mode 100644 materialsystem/stdshaders/rift_vs11.vsh create mode 100644 materialsystem/stdshaders/sample4x4.cpp create mode 100644 materialsystem/stdshaders/sample4x4_blend.cpp create mode 100644 materialsystem/stdshaders/sample4x4_blend_ps2x.fxc create mode 100644 materialsystem/stdshaders/sample4x4_ps2x.fxc create mode 100644 materialsystem/stdshaders/sample4x4delog_ps2x.fxc create mode 100644 materialsystem/stdshaders/sample4x4log_ps2x.fxc create mode 100644 materialsystem/stdshaders/sample4x4maxmin_ps2x.fxc create mode 100644 materialsystem/stdshaders/screenspace_general.cpp create mode 100644 materialsystem/stdshaders/screenspace_general_dx8.cpp create mode 100644 materialsystem/stdshaders/screenspaceeffect_vs11.fxc create mode 100644 materialsystem/stdshaders/screenspaceeffect_vs20.fxc create mode 100644 materialsystem/stdshaders/sfm_blurfilterx.cpp create mode 100644 materialsystem/stdshaders/sfm_blurfiltery.cpp create mode 100644 materialsystem/stdshaders/sfm_combine_vs20.fxc create mode 100644 materialsystem/stdshaders/sfm_downsample.cpp create mode 100644 materialsystem/stdshaders/sfm_integercombine.cpp create mode 100644 materialsystem/stdshaders/sfm_integercombine_ps2x.fxc create mode 100644 materialsystem/stdshaders/shader_constant_register_map.h create mode 100644 materialsystem/stdshaders/shadow.cpp create mode 100644 materialsystem/stdshaders/shadow_dx6.cpp create mode 100644 materialsystem/stdshaders/shadow_dx8.cpp create mode 100644 materialsystem/stdshaders/shadow_ps14.psh create mode 100644 materialsystem/stdshaders/shadow_ps2x.fxc create mode 100644 materialsystem/stdshaders/shadow_vs14.vsh create mode 100644 materialsystem/stdshaders/shadow_vs20.fxc create mode 100644 materialsystem/stdshaders/shadowbuild_dx6.cpp create mode 100644 materialsystem/stdshaders/shadowbuild_dx8.cpp create mode 100644 materialsystem/stdshaders/shadowbuild_dx9.cpp create mode 100644 materialsystem/stdshaders/shadowbuildtexture_ps2x.fxc create mode 100644 materialsystem/stdshaders/shadowmodel_dx8.cpp create mode 100644 materialsystem/stdshaders/shadowmodel_dx9.cpp create mode 100644 materialsystem/stdshaders/shadowmodel_ps20.fxc create mode 100644 materialsystem/stdshaders/shadowmodel_vs20.fxc create mode 100644 materialsystem/stdshaders/shatteredglass.cpp create mode 100644 materialsystem/stdshaders/shatteredglass_dx7.cpp create mode 100644 materialsystem/stdshaders/shatteredglass_dx8.cpp create mode 100644 materialsystem/stdshaders/showz.cpp create mode 100644 materialsystem/stdshaders/showz_ps2x.fxc create mode 100644 materialsystem/stdshaders/showz_vs20.fxc create mode 100644 materialsystem/stdshaders/skin_dx9_helper.cpp create mode 100644 materialsystem/stdshaders/skin_dx9_helper.h create mode 100644 materialsystem/stdshaders/skin_ps20b.fxc create mode 100644 materialsystem/stdshaders/skin_vs20.fxc create mode 100644 materialsystem/stdshaders/sky_dx6.cpp create mode 100644 materialsystem/stdshaders/sky_dx9.cpp create mode 100644 materialsystem/stdshaders/sky_hdr_compressed_ps2x.fxc create mode 100644 materialsystem/stdshaders/sky_hdr_compressed_rgbs_ps2x.fxc create mode 100644 materialsystem/stdshaders/sky_hdr_dx9.cpp create mode 100644 materialsystem/stdshaders/sky_ps2x.fxc create mode 100644 materialsystem/stdshaders/sky_vs20.fxc create mode 100644 materialsystem/stdshaders/splinecard_vsxx.fxc create mode 100644 materialsystem/stdshaders/sprite.cpp create mode 100644 materialsystem/stdshaders/sprite_dx6.cpp create mode 100644 materialsystem/stdshaders/sprite_dx9.cpp create mode 100644 materialsystem/stdshaders/sprite_ps11.psh create mode 100644 materialsystem/stdshaders/sprite_ps2x.fxc create mode 100644 materialsystem/stdshaders/sprite_vs11.vsh create mode 100644 materialsystem/stdshaders/sprite_vs20.fxc create mode 100644 materialsystem/stdshaders/spritecard.cpp create mode 100644 materialsystem/stdshaders/spritecard_ps11.fxc create mode 100644 materialsystem/stdshaders/spritecard_ps2x.fxc create mode 100644 materialsystem/stdshaders/spritecard_vsxx.fxc create mode 100644 materialsystem/stdshaders/stdshader_dbg.vpc create mode 100644 materialsystem/stdshaders/stdshader_dx10.txt create mode 100644 materialsystem/stdshaders/stdshader_dx6.vpc create mode 100644 materialsystem/stdshaders/stdshader_dx7.vpc create mode 100644 materialsystem/stdshaders/stdshader_dx8.vpc create mode 100644 materialsystem/stdshaders/stdshader_dx9.vpc create mode 100644 materialsystem/stdshaders/stdshader_dx9_20b.txt create mode 100644 materialsystem/stdshaders/stdshader_dx9_20b_new.txt create mode 100644 materialsystem/stdshaders/stdshader_dx9_30.txt create mode 100644 materialsystem/stdshaders/teeth.cpp create mode 100644 materialsystem/stdshaders/teeth_bump_ps2x.fxc create mode 100644 materialsystem/stdshaders/teeth_bump_vs20.fxc create mode 100644 materialsystem/stdshaders/teeth_dx6.cpp create mode 100644 materialsystem/stdshaders/teeth_dx8.cpp create mode 100644 materialsystem/stdshaders/teeth_flashlight_ps2x.fxc create mode 100644 materialsystem/stdshaders/teeth_flashlight_vs20.fxc create mode 100644 materialsystem/stdshaders/teeth_ps2x.fxc create mode 100644 materialsystem/stdshaders/teeth_vs20.fxc create mode 100644 materialsystem/stdshaders/unlitgeneric_basetimesdetail.psh create mode 100644 materialsystem/stdshaders/unlitgeneric_dx6.cpp create mode 100644 materialsystem/stdshaders/unlitgeneric_dx8.cpp create mode 100644 materialsystem/stdshaders/unlitgeneric_dx9.cpp create mode 100644 materialsystem/stdshaders/unlitgeneric_inc.vsh create mode 100644 materialsystem/stdshaders/unlitgeneric_lightingonly_vs11.fxc create mode 100644 materialsystem/stdshaders/unlitgeneric_notexture_ps11.fxc create mode 100644 materialsystem/stdshaders/unlitgeneric_notexture_ps2x.fxc create mode 100644 materialsystem/stdshaders/unlitgeneric_ps11.fxc create mode 100644 materialsystem/stdshaders/unlitgeneric_ps2x.fxc create mode 100644 materialsystem/stdshaders/unlitgeneric_vs11.vsh create mode 100644 materialsystem/stdshaders/unlitgeneric_vs20.fxc create mode 100644 materialsystem/stdshaders/unlittwotexture_dx6.cpp create mode 100644 materialsystem/stdshaders/unlittwotexture_dx8.cpp create mode 100644 materialsystem/stdshaders/unlittwotexture_dx9.cpp create mode 100644 materialsystem/stdshaders/unlittwotexture_inc.vsh create mode 100644 materialsystem/stdshaders/unlittwotexture_ps2x.fxc create mode 100644 materialsystem/stdshaders/unlittwotexture_vs20.fxc create mode 100644 materialsystem/stdshaders/vertexlit_and_unlit_generic_bump_ps2x.fxc create mode 100644 materialsystem/stdshaders/vertexlit_and_unlit_generic_bump_vs20.fxc create mode 100644 materialsystem/stdshaders/vertexlit_and_unlit_generic_ps2x.fxc create mode 100644 materialsystem/stdshaders/vertexlit_and_unlit_generic_vs20.fxc create mode 100644 materialsystem/stdshaders/vertexlit_lighting_only_ps2x.fxc create mode 100644 materialsystem/stdshaders/vertexlit_notexture.psh create mode 100644 materialsystem/stdshaders/vertexlitgeneric_basealphamaskedenvmap.psh create mode 100644 materialsystem/stdshaders/vertexlitgeneric_detailbasealphamaskedenvmap.psh create mode 100644 materialsystem/stdshaders/vertexlitgeneric_detailenvmap.psh create mode 100644 materialsystem/stdshaders/vertexlitgeneric_detailmaskedenvmap.psh create mode 100644 materialsystem/stdshaders/vertexlitgeneric_detailselfilluminatedenvmap.psh create mode 100644 materialsystem/stdshaders/vertexlitgeneric_detailselfilluminatedmaskedenvmap.psh create mode 100644 materialsystem/stdshaders/vertexlitgeneric_dx6.cpp create mode 100644 materialsystem/stdshaders/vertexlitgeneric_dx7.cpp create mode 100644 materialsystem/stdshaders/vertexlitgeneric_dx8.cpp create mode 100644 materialsystem/stdshaders/vertexlitgeneric_dx9.cpp create mode 100644 materialsystem/stdshaders/vertexlitgeneric_dx95_helper.h create mode 100644 materialsystem/stdshaders/vertexlitgeneric_dx9_helper.cpp create mode 100644 materialsystem/stdshaders/vertexlitgeneric_dx9_helper.h create mode 100644 materialsystem/stdshaders/vertexlitgeneric_envmap.psh create mode 100644 materialsystem/stdshaders/vertexlitgeneric_flashlight_vs11.vsh create mode 100644 materialsystem/stdshaders/vertexlitgeneric_inc.vsh create mode 100644 materialsystem/stdshaders/vertexlitgeneric_lightingonly_overbright2.psh create mode 100644 materialsystem/stdshaders/vertexlitgeneric_lightingonly_overbright2_ps11.fxc create mode 100644 materialsystem/stdshaders/vertexlitgeneric_maskedenvmap.psh create mode 100644 materialsystem/stdshaders/vertexlitgeneric_selfilluminatedenvmap.psh create mode 100644 materialsystem/stdshaders/vertexlitgeneric_selfilluminatedmaskedenvmap.psh create mode 100644 materialsystem/stdshaders/vertexlitgeneric_vs11.vsh create mode 100644 materialsystem/stdshaders/viewalpha.cpp create mode 100644 materialsystem/stdshaders/volume_clouds.cpp create mode 100644 materialsystem/stdshaders/volume_clouds_helper.cpp create mode 100644 materialsystem/stdshaders/volume_clouds_helper.h create mode 100644 materialsystem/stdshaders/volume_clouds_ps2x.fxc create mode 100644 materialsystem/stdshaders/volume_clouds_vs20.fxc create mode 100644 materialsystem/stdshaders/volumetricfog.cpp create mode 100644 materialsystem/stdshaders/vortwarp_dx7.cpp create mode 100644 materialsystem/stdshaders/vortwarp_dx8.cpp create mode 100644 materialsystem/stdshaders/vortwarp_dx9.cpp create mode 100644 materialsystem/stdshaders/vortwarp_ps11.psh create mode 100644 materialsystem/stdshaders/vortwarp_ps2x.fxc create mode 100644 materialsystem/stdshaders/vortwarp_vs11.vsh create mode 100644 materialsystem/stdshaders/vortwarp_vs20.fxc create mode 100644 materialsystem/stdshaders/vortwarp_vs20_helper.h create mode 100644 materialsystem/stdshaders/vr_distort_hud.cpp create mode 100644 materialsystem/stdshaders/vr_distort_hud_ps2x.fxc create mode 100644 materialsystem/stdshaders/vr_distort_hud_vs20.fxc create mode 100644 materialsystem/stdshaders/vr_distort_texture.cpp create mode 100644 materialsystem/stdshaders/vr_distort_texture_ps2x.fxc create mode 100644 materialsystem/stdshaders/vr_distort_texture_vs20.fxc create mode 100644 materialsystem/stdshaders/vshtmp9/BufferClearObeyStencil_vs11.inc create mode 100644 materialsystem/stdshaders/vshtmp9/BumpmappedEnvmap.inc create mode 100644 materialsystem/stdshaders/vshtmp9/BumpmappedLightmap.inc create mode 100644 materialsystem/stdshaders/vshtmp9/Cable.inc create mode 100644 materialsystem/stdshaders/vshtmp9/DebugTangentSpace.inc create mode 100644 materialsystem/stdshaders/vshtmp9/Eyes.inc create mode 100644 materialsystem/stdshaders/vshtmp9/JellyFish.inc create mode 100644 materialsystem/stdshaders/vshtmp9/Jojirium.inc create mode 100644 materialsystem/stdshaders/vshtmp9/LightingOnly.inc create mode 100644 materialsystem/stdshaders/vshtmp9/LightmappedGeneric_BaseTexture.inc create mode 100644 materialsystem/stdshaders/vshtmp9/LightmappedGeneric_BumpmappedLightmap_Base_ps14.inc create mode 100644 materialsystem/stdshaders/vshtmp9/LightmappedGeneric_BumpmappedLightmap_Blend_ps14.inc create mode 100644 materialsystem/stdshaders/vshtmp9/LightmappedGeneric_Decal.inc create mode 100644 materialsystem/stdshaders/vshtmp9/LightmappedGeneric_LightingOnly.inc create mode 100644 materialsystem/stdshaders/vshtmp9/Refract_model_vs11.inc create mode 100644 materialsystem/stdshaders/vshtmp9/Refract_world_vs11.inc create mode 100644 materialsystem/stdshaders/vshtmp9/ScreenSpaceEffect.inc create mode 100644 materialsystem/stdshaders/vshtmp9/ShadowModel.inc create mode 100644 materialsystem/stdshaders/vshtmp9/ShatteredGlass.inc create mode 100644 materialsystem/stdshaders/vshtmp9/ShatteredGlass_EnvMap.inc create mode 100644 materialsystem/stdshaders/vshtmp9/ShatteredGlass_EnvMapSphere.inc create mode 100644 materialsystem/stdshaders/vshtmp9/Teeth.inc create mode 100644 materialsystem/stdshaders/vshtmp9/UnlitGeneric_LightingOnly.inc create mode 100644 materialsystem/stdshaders/vshtmp9/UnlitTwoTexture.inc create mode 100644 materialsystem/stdshaders/vshtmp9/VertexLitGeneric_EnvmappedBumpmap_NoLighting.inc create mode 100644 materialsystem/stdshaders/vshtmp9/VertexLitGeneric_EnvmappedBumpmap_NoLighting_ps14.inc create mode 100644 materialsystem/stdshaders/vshtmp9/VertexLitGeneric_SelfIllumOnly.inc create mode 100644 materialsystem/stdshaders/vshtmp9/VertexLitGeneric_vs11.inc create mode 100644 materialsystem/stdshaders/vshtmp9/WaterCheapPerVertexFresnel_vs11.inc create mode 100644 materialsystem/stdshaders/vshtmp9/WaterCheap_vs11.inc create mode 100644 materialsystem/stdshaders/vshtmp9/WaterCheap_vs14.inc create mode 100644 materialsystem/stdshaders/vshtmp9/Water_ps14.inc create mode 100644 materialsystem/stdshaders/vshtmp9/Water_vs11.inc create mode 100644 materialsystem/stdshaders/vshtmp9/WorldVertexAlpha.inc create mode 100644 materialsystem/stdshaders/vshtmp9/WorldVertexTransition.inc create mode 100644 materialsystem/stdshaders/vshtmp9/bik_vs11.inc create mode 100644 materialsystem/stdshaders/vshtmp9/cloak_blended_pass_dx8_vs11.inc create mode 100644 materialsystem/stdshaders/vshtmp9/cloud_vs11.inc create mode 100644 materialsystem/stdshaders/vshtmp9/emissive_scroll_blended_pass_dx8_vs11.inc create mode 100644 materialsystem/stdshaders/vshtmp9/eyes_flashlight_vs11.inc create mode 100644 materialsystem/stdshaders/vshtmp9/fillrate.inc create mode 100644 materialsystem/stdshaders/vshtmp9/flesh_interior_blended_pass_dx8_vs11.inc create mode 100644 materialsystem/stdshaders/vshtmp9/lightmappedgeneric_basetextureblend.inc create mode 100644 materialsystem/stdshaders/vshtmp9/lightmappedgeneric_bumpmappedenvmap.inc create mode 100644 materialsystem/stdshaders/vshtmp9/lightmappedgeneric_bumpmappedenvmap_ps14.inc create mode 100644 materialsystem/stdshaders/vshtmp9/lightmappedgeneric_bumpmappedlightmap.inc create mode 100644 materialsystem/stdshaders/vshtmp9/lightmappedgeneric_vs11.inc create mode 100644 materialsystem/stdshaders/vshtmp9/overlay_fit_vs11.inc create mode 100644 materialsystem/stdshaders/vshtmp9/predator.inc create mode 100644 materialsystem/stdshaders/vshtmp9/rendertargetblit_vs11.inc create mode 100644 materialsystem/stdshaders/vshtmp9/shadow_vs14.inc create mode 100644 materialsystem/stdshaders/vshtmp9/sprite_vs11.inc create mode 100644 materialsystem/stdshaders/vshtmp9/unlitgeneric_vs11.inc create mode 100644 materialsystem/stdshaders/vshtmp9/vertexlitgeneric_flashlight_vs11.inc create mode 100644 materialsystem/stdshaders/vshtmp9/vortwarp_vs11.inc create mode 100644 materialsystem/stdshaders/vshtmp9/worldvertextransition_seamless.inc create mode 100644 materialsystem/stdshaders/vshtmp9/worldvertextransition_vs14.inc create mode 100644 materialsystem/stdshaders/vshtmp9/writez.inc create mode 100644 materialsystem/stdshaders/vshtmp9_360/BufferClearObeyStencil_vs11.inc create mode 100644 materialsystem/stdshaders/vshtmp9_360/BumpmappedEnvmap.inc create mode 100644 materialsystem/stdshaders/vshtmp9_360/BumpmappedLightmap.inc create mode 100644 materialsystem/stdshaders/vshtmp9_360/Cable.inc create mode 100644 materialsystem/stdshaders/vshtmp9_360/DebugTangentSpace.inc create mode 100644 materialsystem/stdshaders/vshtmp9_360/Eyes.inc create mode 100644 materialsystem/stdshaders/vshtmp9_360/JellyFish.inc create mode 100644 materialsystem/stdshaders/vshtmp9_360/LightingOnly.inc create mode 100644 materialsystem/stdshaders/vshtmp9_360/LightmappedGeneric_BaseTexture.inc create mode 100644 materialsystem/stdshaders/vshtmp9_360/LightmappedGeneric_BumpmappedLightmap_Base_ps14.inc create mode 100644 materialsystem/stdshaders/vshtmp9_360/LightmappedGeneric_BumpmappedLightmap_Blend_ps14.inc create mode 100644 materialsystem/stdshaders/vshtmp9_360/LightmappedGeneric_Decal.inc create mode 100644 materialsystem/stdshaders/vshtmp9_360/LightmappedGeneric_LightingOnly.inc create mode 100644 materialsystem/stdshaders/vshtmp9_360/Refract_model_vs11.inc create mode 100644 materialsystem/stdshaders/vshtmp9_360/Refract_world_vs11.inc create mode 100644 materialsystem/stdshaders/vshtmp9_360/ScreenSpaceEffect.inc create mode 100644 materialsystem/stdshaders/vshtmp9_360/ShadowModel.inc create mode 100644 materialsystem/stdshaders/vshtmp9_360/ShatteredGlass.inc create mode 100644 materialsystem/stdshaders/vshtmp9_360/ShatteredGlass_EnvMap.inc create mode 100644 materialsystem/stdshaders/vshtmp9_360/ShatteredGlass_EnvMapSphere.inc create mode 100644 materialsystem/stdshaders/vshtmp9_360/Teeth.inc create mode 100644 materialsystem/stdshaders/vshtmp9_360/UnlitGeneric_LightingOnly.inc create mode 100644 materialsystem/stdshaders/vshtmp9_360/UnlitTwoTexture.inc create mode 100644 materialsystem/stdshaders/vshtmp9_360/VertexLitGeneric_EnvmappedBumpmap_NoLighting.inc create mode 100644 materialsystem/stdshaders/vshtmp9_360/VertexLitGeneric_EnvmappedBumpmap_NoLighting_ps14.inc create mode 100644 materialsystem/stdshaders/vshtmp9_360/VertexLitGeneric_SelfIllumOnly.inc create mode 100644 materialsystem/stdshaders/vshtmp9_360/VertexLitGeneric_vs11.inc create mode 100644 materialsystem/stdshaders/vshtmp9_360/WaterCheapPerVertexFresnel_vs11.inc create mode 100644 materialsystem/stdshaders/vshtmp9_360/WaterCheap_vs11.inc create mode 100644 materialsystem/stdshaders/vshtmp9_360/WaterCheap_vs14.inc create mode 100644 materialsystem/stdshaders/vshtmp9_360/Water_ps14.inc create mode 100644 materialsystem/stdshaders/vshtmp9_360/Water_vs11.inc create mode 100644 materialsystem/stdshaders/vshtmp9_360/WorldVertexAlpha.inc create mode 100644 materialsystem/stdshaders/vshtmp9_360/WorldVertexTransition.inc create mode 100644 materialsystem/stdshaders/vshtmp9_360/bik_vs11.inc create mode 100644 materialsystem/stdshaders/vshtmp9_360/cloak_blended_pass_dx8_vs11.inc create mode 100644 materialsystem/stdshaders/vshtmp9_360/cloud_vs11.inc create mode 100644 materialsystem/stdshaders/vshtmp9_360/emissive_scroll_blended_pass_dx8_vs11.inc create mode 100644 materialsystem/stdshaders/vshtmp9_360/eyes_flashlight_vs11.inc create mode 100644 materialsystem/stdshaders/vshtmp9_360/fillrate.inc create mode 100644 materialsystem/stdshaders/vshtmp9_360/flesh_interior_blended_pass_dx8_vs11.inc create mode 100644 materialsystem/stdshaders/vshtmp9_360/lightmappedgeneric_basetextureblend.inc create mode 100644 materialsystem/stdshaders/vshtmp9_360/lightmappedgeneric_bumpmappedenvmap.inc create mode 100644 materialsystem/stdshaders/vshtmp9_360/lightmappedgeneric_bumpmappedenvmap_ps14.inc create mode 100644 materialsystem/stdshaders/vshtmp9_360/lightmappedgeneric_bumpmappedlightmap.inc create mode 100644 materialsystem/stdshaders/vshtmp9_360/lightmappedgeneric_vs11.inc create mode 100644 materialsystem/stdshaders/vshtmp9_360/overlay_fit_vs11.inc create mode 100644 materialsystem/stdshaders/vshtmp9_360/predator.inc create mode 100644 materialsystem/stdshaders/vshtmp9_360/shadow_vs14.inc create mode 100644 materialsystem/stdshaders/vshtmp9_360/sprite_vs11.inc create mode 100644 materialsystem/stdshaders/vshtmp9_360/unlitgeneric_vs11.inc create mode 100644 materialsystem/stdshaders/vshtmp9_360/vertexlitgeneric_flashlight_vs11.inc create mode 100644 materialsystem/stdshaders/vshtmp9_360/vortwarp_vs11.inc create mode 100644 materialsystem/stdshaders/vshtmp9_360/worldvertextransition_seamless.inc create mode 100644 materialsystem/stdshaders/vshtmp9_360/worldvertextransition_vs14.inc create mode 100644 materialsystem/stdshaders/vshtmp9_360/writez.inc create mode 100644 materialsystem/stdshaders/warp.cpp create mode 100644 materialsystem/stdshaders/warp_ps2x.fxc create mode 100644 materialsystem/stdshaders/warp_vs20.fxc create mode 100644 materialsystem/stdshaders/water.cpp create mode 100644 materialsystem/stdshaders/water_dudv.cpp create mode 100644 materialsystem/stdshaders/water_dx60.cpp create mode 100644 materialsystem/stdshaders/water_dx80.cpp create mode 100644 materialsystem/stdshaders/water_dx81.cpp create mode 100644 materialsystem/stdshaders/water_ps2x.fxc create mode 100644 materialsystem/stdshaders/water_ps2x_helper.h create mode 100644 materialsystem/stdshaders/waterreflect_ps14.psh create mode 100644 materialsystem/stdshaders/waterrefract_ps14.psh create mode 100644 materialsystem/stdshaders/weapon_sheen_pass_helper.cpp create mode 100644 materialsystem/stdshaders/weapon_sheen_pass_helper.h create mode 100644 materialsystem/stdshaders/weapon_sheen_pass_ps2x.fxc create mode 100644 materialsystem/stdshaders/weapon_sheen_pass_vs20.fxc create mode 100644 materialsystem/stdshaders/white.psh create mode 100644 materialsystem/stdshaders/white_ps2x.fxc create mode 100644 materialsystem/stdshaders/windowimposter_dx80.cpp create mode 100644 materialsystem/stdshaders/windowimposter_dx90.cpp create mode 100644 materialsystem/stdshaders/windowimposter_ps11.fxc create mode 100644 materialsystem/stdshaders/windowimposter_ps2x.fxc create mode 100644 materialsystem/stdshaders/windowimposter_vs11.fxc create mode 100644 materialsystem/stdshaders/windowimposter_vs20.fxc create mode 100644 materialsystem/stdshaders/wireframe_dx8.cpp create mode 100644 materialsystem/stdshaders/wireframe_dx9.cpp create mode 100644 materialsystem/stdshaders/worldtwotextureblend.cpp create mode 100644 materialsystem/stdshaders/worldtwotextureblend_dx6.cpp create mode 100644 materialsystem/stdshaders/worldtwotextureblend_dx8.cpp create mode 100644 materialsystem/stdshaders/worldtwotextureblend_ps2x.fxc create mode 100644 materialsystem/stdshaders/worldvertexalpha.cpp create mode 100644 materialsystem/stdshaders/worldvertexalpha_dx8.cpp create mode 100644 materialsystem/stdshaders/worldvertextransition.cpp create mode 100644 materialsystem/stdshaders/worldvertextransition_dx6.cpp create mode 100644 materialsystem/stdshaders/worldvertextransition_dx6_helper.cpp create mode 100644 materialsystem/stdshaders/worldvertextransition_dx6_helper.h create mode 100644 materialsystem/stdshaders/worldvertextransition_dx8_helper.cpp create mode 100644 materialsystem/stdshaders/worldvertextransition_dx8_helper.h create mode 100644 materialsystem/stdshaders/writestencil_dx8.cpp create mode 100644 materialsystem/stdshaders/writestencil_dx9.cpp create mode 100644 materialsystem/stdshaders/writevertexalphatodestalpha_ps11.fxc create mode 100644 materialsystem/stdshaders/writevertexalphatodestalpha_vs11.fxc create mode 100644 materialsystem/stdshaders/writez.vsh create mode 100644 materialsystem/stdshaders/writez_dx6.cpp create mode 100644 materialsystem/stdshaders/writez_dx8.cpp create mode 100644 materialsystem/stdshaders/writez_dx9.cpp create mode 100644 materialsystem/stdshaders/writez_vs20.fxc create mode 100644 materialsystem/stdshaders/xbox/xbox_dbg.def create mode 100644 materialsystem/stdshaders/xbox/xbox_dx8.def create mode 100644 materialsystem/stdshaders/xbox/xbox_dx9.def create mode 100644 materialsystem/stdshaders/yuv.cpp create mode 100644 materialsystem/stdshaders/yuv.psh create mode 100644 materialsystem/texturemanager.cpp create mode 100644 materialsystem/texturemanager.h create mode 100644 materialsystem/wireframe.cpp create mode 100644 materialsystem/xbox/xbox.def (limited to 'materialsystem') diff --git a/materialsystem/CColorCorrection.cpp b/materialsystem/CColorCorrection.cpp new file mode 100644 index 0000000..5483d18 --- /dev/null +++ b/materialsystem/CColorCorrection.cpp @@ -0,0 +1,837 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: Color correction system +// +//============================================================================== + +#if defined (WIN32) && !defined( _X360 ) +#include +#elif POSIX +#define _cdecl +#endif +#include "materialsystem/IColorCorrection.h" +#include "materialsystem_global.h" +#include "shaderapi/ishaderapi.h" +#include "texturemanager.h" +#include "utlvector.h" +#include "generichash.h" +#include "filesystem.h" +#include "filesystem/IQueuedLoader.h" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +class ITextureInternal; + +//----------------------------------------------------------------------------- +// Holds all the necessary information for a single color correction lookup +// function +//----------------------------------------------------------------------------- +struct ColorCorrectionLookup_t +{ + ColorCorrectionHandle_t m_Handle; + + ITextureInternal *m_pColorCorrectionTexture; + + color24 m_pColorCorrection[COLOR_CORRECTION_TEXTURE_SIZE*COLOR_CORRECTION_TEXTURE_SIZE*COLOR_CORRECTION_TEXTURE_SIZE]; + bool m_bLocked; + float m_flWeight; + bool m_bResetable; + + ColorCorrectionLookup_t( ColorCorrectionHandle_t handle ); + ~ColorCorrectionLookup_t( ); + + void ReleaseTexture(); + void RestoreTexture(); + void AllocTexture(); +}; + +ColorCorrectionLookup_t::ColorCorrectionLookup_t( ColorCorrectionHandle_t handle ) +{ + m_Handle = handle; + m_bLocked = false; + m_flWeight = 1.0f; + m_bResetable = true; + + AllocTexture(); +} + +ColorCorrectionLookup_t::~ColorCorrectionLookup_t( ) +{ + // We must remove the texture from the active color correction + // textures, otherwise we may leak a reference + if ( m_pColorCorrectionTexture ) + { + for ( int i=0; iColorCorrectionTexture( i ) ) + { + TextureManager()->SetColorCorrectionTexture( i, NULL ); + } + } + + m_pColorCorrectionTexture->DecrementReferenceCount(); + ITextureInternal::Destroy( m_pColorCorrectionTexture ); + m_pColorCorrectionTexture = NULL; + } +} + +void ColorCorrectionLookup_t::AllocTexture() +{ + char name[64]; + sprintf( name, "ColorCorrection - %d", m_Handle ); + + m_pColorCorrectionTexture = ITextureInternal::CreateProceduralTexture( name, TEXTURE_GROUP_OTHER, + COLOR_CORRECTION_TEXTURE_SIZE, COLOR_CORRECTION_TEXTURE_SIZE, COLOR_CORRECTION_TEXTURE_SIZE, IMAGE_FORMAT_BGRX8888, + TEXTUREFLAGS_NOMIP | TEXTUREFLAGS_NOLOD | TEXTUREFLAGS_SINGLECOPY | TEXTUREFLAGS_CLAMPS | + TEXTUREFLAGS_CLAMPT | TEXTUREFLAGS_CLAMPU | TEXTUREFLAGS_NODEBUGOVERRIDE ); + + extern void CreateColorCorrectionTexture( ITextureInternal *pTexture, ColorCorrectionHandle_t handle ); + CreateColorCorrectionTexture( m_pColorCorrectionTexture, m_Handle ); + + m_pColorCorrectionTexture->Download(); +} + +void ColorCorrectionLookup_t::ReleaseTexture() +{ + m_pColorCorrectionTexture->ReleaseMemory(); +} + +void ColorCorrectionLookup_t::RestoreTexture() +{ + // Put the texture back onto the board + m_pColorCorrectionTexture->OnRestore(); // Give render targets a chance to reinitialize themselves if necessary (due to AA changes). + m_pColorCorrectionTexture->Download(); +} + + +//----------------------------------------------------------------------------- +// IColorCorrectionSystem interface implementation +//----------------------------------------------------------------------------- +class CColorCorrectionSystem : public IColorCorrectionSystem +{ +public: + virtual void Init(); + virtual void Shutdown(); + + virtual void LockLookup(); + virtual void SetLookup( RGBX5551_t inColor, color24 outColor ); + virtual void UnlockLookup(); + virtual color24 GetLookup( RGBX5551_t inColor ); + + virtual void LoadLookup( const char *pLookupName ); + virtual void CopyLookup( const color24 *pSrcColorCorrection ); + virtual void ResetLookup( ); + + virtual ColorCorrectionHandle_t AddLookup( const char *pName ); + virtual bool RemoveLookup( ColorCorrectionHandle_t handle ); + + virtual void SetLookupWeight( ColorCorrectionHandle_t handle, float flWeight ); + virtual float GetLookupWeight( ColorCorrectionHandle_t handle ); + virtual float GetLookupWeight( int i ); + + virtual void LockLookup( ColorCorrectionHandle_t handle ); + virtual void SetLookup( ColorCorrectionHandle_t handle, RGBX5551_t inColor, color24 outColor ); + virtual color24 GetLookup( ColorCorrectionHandle_t handle, RGBX5551_t inColor ); + virtual void UnlockLookup( ColorCorrectionHandle_t handle ); + + virtual void LoadLookup( ColorCorrectionHandle_t handle, const char *pLookupName ); + virtual void CopyLookup( ColorCorrectionHandle_t handle, const color24 *pSrcColorCorrection ); + virtual void ResetLookup( ColorCorrectionHandle_t handle ); + + virtual void ResetLookupWeights( ); + + virtual void ReleaseTextures( ); + virtual void RestoreTextures( ); + + virtual color24 ConvertToColor24( RGBX5551_t inColor ); + + virtual int GetNumLookups( ); + + virtual void SetResetable( ColorCorrectionHandle_t handle, bool bResetable ); + virtual void GetCurrentColorCorrection( ShaderColorCorrectionInfo_t* pInfo ); + virtual void EnableColorCorrection( bool bEnable ); + +protected: + CUtlVector< ColorCorrectionLookup_t * > m_ColorCorrectionList; + ColorCorrectionHandle_t m_DefaultColorCorrectionHandle; + ColorCorrectionHandle_t m_UnnamedColorCorrectionHandle; + float m_DefaultColorCorrectionWeight; + bool m_bEnabled; + + void SortLookups( ); + ColorCorrectionLookup_t *FindLookup( ColorCorrectionHandle_t handle ); + ColorCorrectionHandle_t GetLookupHandle( const char *pName ); + void SetLookupPtr( ColorCorrectionLookup_t *lookup, RGBX5551_t inColor, color24 outColor ); + void GetNormalizedWeights( float *pDefaultWeight, float *pLookupWeights ); +}; + +CColorCorrectionSystem g_ColorCorrectionSystem; +IColorCorrectionSystem *g_pColorCorrectionSystem = &g_ColorCorrectionSystem; + +#ifndef _X360 +// Don't allow this on the 360.. it doesn't work in mat_queued_mode +EXPOSE_SINGLE_INTERFACE_GLOBALVAR( CColorCorrectionSystem, IColorCorrectionSystem, COLORCORRECTION_INTERFACE_VERSION, g_ColorCorrectionSystem ); +#endif + + +//----------------------------------------------------------------------------- +// Wrappers for release/restore functionality +//----------------------------------------------------------------------------- +void ReleaseColorCorrection() +{ + g_pColorCorrectionSystem->ReleaseTextures(); +} + +void RestoreColorCorrection( int changeFlags ) +{ + g_pColorCorrectionSystem->RestoreTextures(); +} + + +//----------------------------------------------------------------------------- +// Init function +//----------------------------------------------------------------------------- +void CColorCorrectionSystem::Init() +{ + m_DefaultColorCorrectionHandle = (ColorCorrectionHandle_t)-1; + m_UnnamedColorCorrectionHandle = GetLookupHandle( "unnamed" ); + m_DefaultColorCorrectionWeight = 0.0f; + m_bEnabled = true; + + MaterialSystem()->AddReleaseFunc( ReleaseColorCorrection ); + MaterialSystem()->AddRestoreFunc( RestoreColorCorrection ); +} + +//----------------------------------------------------------------------------- +// Shutdown function +//----------------------------------------------------------------------------- +void CColorCorrectionSystem::Shutdown() +{ + for ( int i=0;iRemoveReleaseFunc( ReleaseColorCorrection ); + MaterialSystem()->RemoveRestoreFunc( RestoreColorCorrection ); +} + + +//----------------------------------------------------------------------------- +// Global enable/disable of color correction +//----------------------------------------------------------------------------- +void CColorCorrectionSystem::EnableColorCorrection( bool bEnable ) +{ + m_bEnabled = bEnable; +} + + +//----------------------------------------------------------------------------- +// Lock the "unnamed" color correction lookup +//----------------------------------------------------------------------------- +void CColorCorrectionSystem::LockLookup() +{ + ColorCorrectionLookup_t *lookup = FindLookup( m_UnnamedColorCorrectionHandle ); + if ( !lookup ) + { + AddLookup( "unnamed" ); + } + + LockLookup( m_UnnamedColorCorrectionHandle ); +} + +//----------------------------------------------------------------------------- +// Set the specified mapping for the "unnamed" color correction lookup +//----------------------------------------------------------------------------- +void CColorCorrectionSystem::SetLookup( RGBX5551_t inColor, color24 outColor ) +{ + ColorCorrectionLookup_t *lookup = FindLookup( m_UnnamedColorCorrectionHandle ); + if ( !lookup ) + return; + + SetLookup( m_UnnamedColorCorrectionHandle, inColor, outColor ); +} + +//----------------------------------------------------------------------------- +// Unlock the "unnamed" color correction lookup +//----------------------------------------------------------------------------- +void CColorCorrectionSystem::UnlockLookup() +{ + ColorCorrectionLookup_t *lookup = FindLookup( m_UnnamedColorCorrectionHandle ); + if ( !lookup ) + return; + + UnlockLookup( m_UnnamedColorCorrectionHandle ); +} + +//----------------------------------------------------------------------------- +// Get the specified mapping from the "unnamed" color correction lookup +//----------------------------------------------------------------------------- +color24 CColorCorrectionSystem::GetLookup( RGBX5551_t inColor ) +{ + ColorCorrectionLookup_t *lookup = FindLookup( m_UnnamedColorCorrectionHandle ); + if ( !lookup ) + AddLookup( "unnamed" ); + + return GetLookup( m_UnnamedColorCorrectionHandle, inColor ); +} + +//----------------------------------------------------------------------------- +// Load the specified file into the "unnamed" color correction lookup +//----------------------------------------------------------------------------- +void CColorCorrectionSystem::LoadLookup( const char *pLookupName ) +{ + ColorCorrectionLookup_t *lookup = FindLookup( m_UnnamedColorCorrectionHandle ); + if ( !lookup ) + return; + + return LoadLookup( m_UnnamedColorCorrectionHandle, pLookupName ); +} + +//----------------------------------------------------------------------------- +// Copy the specified data into the "unnamed" color correction lookup +//----------------------------------------------------------------------------- +void CColorCorrectionSystem::CopyLookup( const color24 *pSrcColorCorrection ) +{ + ColorCorrectionLookup_t *lookup = FindLookup( m_UnnamedColorCorrectionHandle ); + if ( !lookup ) + return; + + CopyLookup( m_UnnamedColorCorrectionHandle, pSrcColorCorrection ); +} + +//----------------------------------------------------------------------------- +// Reset the "unnamed" color correction lookup +//----------------------------------------------------------------------------- +void CColorCorrectionSystem::ResetLookup( ) +{ + ColorCorrectionLookup_t *lookup = FindLookup( m_UnnamedColorCorrectionHandle ); + if ( !lookup ) + return; + + return ResetLookup( m_UnnamedColorCorrectionHandle ); +} + +//----------------------------------------------------------------------------- +// ColorCorrectionLookup_t sorting function +//----------------------------------------------------------------------------- +typedef ColorCorrectionLookup_t * CCLPtr; +int _cdecl CompareLookups( const CCLPtr *lookup_a, const CCLPtr *lookup_b ) +{ + if ( (*lookup_a)->m_flWeight < (*lookup_b)->m_flWeight ) + return 1; + else if ( (*lookup_a)->m_flWeight > (*lookup_b)->m_flWeight ) + return -1; + return 0; +} + +//----------------------------------------------------------------------------- +// Sort ColorCorrectionLookup_t vector based on decreasing weight +//----------------------------------------------------------------------------- +void CColorCorrectionSystem::SortLookups( ) +{ + m_ColorCorrectionList.Sort( CompareLookups ); + + for ( int i=0;iSetColorCorrectionTexture( i, m_ColorCorrectionList[i]->m_pColorCorrectionTexture ); + } + + for ( int i=m_ColorCorrectionList.Count();iSetColorCorrectionTexture( i, NULL ); + } +} + +//----------------------------------------------------------------------------- +// Find the ColorCorrectionLookup_t corresponding to the specified handle +//----------------------------------------------------------------------------- +ColorCorrectionLookup_t *CColorCorrectionSystem::FindLookup( ColorCorrectionHandle_t handle ) +{ + for ( int i=0; im_Handle == handle ) + { + return m_ColorCorrectionList[i]; + } + } + + return NULL; +} + +//----------------------------------------------------------------------------- +// Find the handle associated with a specified name +//----------------------------------------------------------------------------- +ColorCorrectionHandle_t CColorCorrectionSystem::GetLookupHandle( const char *pName ) +{ + // case and slash insensitive + FileNameHandle_t hName = g_pFullFileSystem->FindOrAddFileName( pName ); + COMPILE_TIME_ASSERT( sizeof( FileNameHandle_t ) == sizeof( ColorCorrectionHandle_t ) ); + + return (ColorCorrectionHandle_t)hName; +} + +//----------------------------------------------------------------------------- +// Add a color correction lookup with the specified name +//----------------------------------------------------------------------------- +ColorCorrectionHandle_t CColorCorrectionSystem::AddLookup( const char *pName ) +{ + ColorCorrectionHandle_t handle = GetLookupHandle( pName ); + if ( handle == m_DefaultColorCorrectionHandle ) + return handle; + + ColorCorrectionLookup_t *lookup = FindLookup( handle ); + if ( lookup ) + { +// Warning( "Cannot have 2 lookups referencing the same name %s\n", pName ); + + // NOTE: Cannot use 0xFFFFFFFF because that's the default handle + return (ColorCorrectionHandle_t)0xFFFFFFFE; + } + + lookup = new ColorCorrectionLookup_t( handle ); + m_ColorCorrectionList.AddToTail( lookup ); + + LockLookup( handle ); + ResetLookup( handle ); + UnlockLookup( handle ); + + SetLookupWeight( handle, 1.0f ); + + return handle; +} + +//----------------------------------------------------------------------------- +// Remove the specified color correction lookup +//----------------------------------------------------------------------------- +bool CColorCorrectionSystem::RemoveLookup( ColorCorrectionHandle_t handle ) +{ + if ( handle == m_DefaultColorCorrectionHandle ) + return false; + + for ( int i=0;im_Handle == handle ) + { + m_ColorCorrectionList.Remove( i ); + + delete lookup; + + return true; + } + } + + return false; +} + +//----------------------------------------------------------------------------- +// Sets the weight for the specified color correction lookup +//----------------------------------------------------------------------------- +void CColorCorrectionSystem::SetLookupWeight( ColorCorrectionHandle_t handle, float flWeight ) +{ + if ( handle == m_DefaultColorCorrectionHandle ) + { + m_DefaultColorCorrectionWeight = flWeight; + return; + } + + ColorCorrectionLookup_t *lookup = FindLookup( handle ); + if ( lookup && flWeight>lookup->m_flWeight ) + { + lookup->m_flWeight = flWeight; + } + + SortLookups( ); +} + +//----------------------------------------------------------------------------- +// Gets the weight for the specified color correction lookup +//----------------------------------------------------------------------------- +float CColorCorrectionSystem::GetLookupWeight( ColorCorrectionHandle_t handle ) +{ + if ( handle == m_DefaultColorCorrectionHandle ) + { + return m_DefaultColorCorrectionWeight; + } + + ColorCorrectionLookup_t *lookup = FindLookup( handle ); + if ( !lookup ) + return 0.0f; + + return lookup->m_flWeight; +} + +//----------------------------------------------------------------------------- +// Gets the weight for the color correction lookup specified by index +//----------------------------------------------------------------------------- +float CColorCorrectionSystem::GetLookupWeight( int i ) +{ + if ( im_flWeight; + } + + return 0.0f; +} + +//----------------------------------------------------------------------------- +// Lock the specified color correction lookup +//----------------------------------------------------------------------------- +void CColorCorrectionSystem::LockLookup( ColorCorrectionHandle_t handle ) +{ + if ( handle == m_DefaultColorCorrectionHandle ) + { + return; + } + + ColorCorrectionLookup_t *lookup = FindLookup( handle ); + if ( !lookup ) + return; + + lookup->m_bLocked = true; +} + +//----------------------------------------------------------------------------- +// Set the mapping for the specified color correction lookup +//----------------------------------------------------------------------------- +void CColorCorrectionSystem::SetLookup( ColorCorrectionHandle_t handle, RGBX5551_t inColor, color24 outColor ) +{ + if ( handle == m_DefaultColorCorrectionHandle ) + return; + + ColorCorrectionLookup_t *lookup = FindLookup( handle ); + if ( !lookup ) + return; + + SetLookupPtr( lookup, inColor, outColor ); +} + +//----------------------------------------------------------------------------- +// Set the mapping for the specified color correction lookup +//----------------------------------------------------------------------------- +void CColorCorrectionSystem::SetLookupPtr( ColorCorrectionLookup_t *lookup, RGBX5551_t inColor, color24 outColor ) +{ + Assert( lookup->m_bLocked ); + lookup->m_pColorCorrection[inColor.r + inColor.g*COLOR_CORRECTION_TEXTURE_SIZE + inColor.b*COLOR_CORRECTION_TEXTURE_SIZE*COLOR_CORRECTION_TEXTURE_SIZE] = outColor; +} + +//----------------------------------------------------------------------------- +// Get the mapping for the specified color correction lookup +//----------------------------------------------------------------------------- +color24 CColorCorrectionSystem::GetLookup( ColorCorrectionHandle_t handle, RGBX5551_t inColor ) +{ + if ( handle == m_DefaultColorCorrectionHandle ) + { + color24 col = ConvertToColor24( inColor ); + return col; + } + + ColorCorrectionLookup_t *lookup = FindLookup( handle ); + if ( !lookup ) + { + color24 col; col.r = 0; col.g = 0; col.b = 0; + return col; + } + + return lookup->m_pColorCorrection[inColor.r + inColor.g*COLOR_CORRECTION_TEXTURE_SIZE + inColor.b*COLOR_CORRECTION_TEXTURE_SIZE*COLOR_CORRECTION_TEXTURE_SIZE]; +} + +//----------------------------------------------------------------------------- +// Unlock the specified color correction lookup +//----------------------------------------------------------------------------- +void CColorCorrectionSystem::UnlockLookup( ColorCorrectionHandle_t handle ) +{ + if ( handle == m_DefaultColorCorrectionHandle ) + { + return; + } + + ColorCorrectionLookup_t *lookup = FindLookup( handle ); + if ( !lookup ) + return; + + lookup->m_bLocked = false; + + lookup->m_pColorCorrectionTexture->Download(); +} + +//----------------------------------------------------------------------------- +// Load the specified file into the color correction lookup +//----------------------------------------------------------------------------- +void CColorCorrectionSystem::LoadLookup( ColorCorrectionHandle_t handle, const char *pLookupName ) +{ + if ( handle == m_DefaultColorCorrectionHandle ) + { + return; + } + + ColorCorrectionLookup_t *lookup = FindLookup( handle ); + if ( !lookup ) + return; + + Assert( lookup->m_bLocked ); + Assert( pLookupName ); + + CUtlBuffer colorBuff; + if ( !g_pFullFileSystem->ReadFile( pLookupName, "GAME", colorBuff ) ) + { + return; + } + + int res = (int)powf( (float)( colorBuff.TellMaxPut()/sizeof( color24 ) ), 1.0f/3.0f ); + if ( res != COLOR_CORRECTION_TEXTURE_SIZE || res*res*res*(int)sizeof( color24 ) != colorBuff.TellMaxPut() ) + { + Warning( "CColorCorrectionSystem: Raw file '%s' has bad size (%d)\n", pLookupName, colorBuff.TellMaxPut() ); + return; + } + + color24 *pColors = (color24 *)colorBuff.Base(); + int colorIndex = 0; + RGBX5551_t inColor; + + inColor.b = 0; + for ( int b = 0; b < COLOR_CORRECTION_TEXTURE_SIZE; ++b, ++inColor.b ) + { + inColor.g = 0; + for ( int g = 0; g < COLOR_CORRECTION_TEXTURE_SIZE; ++g, ++inColor.g ) + { + inColor.r = 0; + for ( int r = 0; r < COLOR_CORRECTION_TEXTURE_SIZE; ++r, ++inColor.r ) + { + color24 vOutColor24 = pColors[colorIndex]; + + /* // Still experimenting with this...it looks banded right now so leaving it off. + // I think we need to generate better raw data for the 360 instead of hacking it here. + if ( IsX360() ) + { + // We need to adjust the outcolor for the 360's piecewise linear gamma space + // So apply SrgbLinearToGamma( X360GammaToLinear( inColor.rgb ) ) to fetch the desired + // srgb outColor assuming a 360 gamma input color and then put that into 360 gamma space as the new outColor + + // Our input is in 360 gamma space + color24 inColor24 = ConvertToColor24( inColor ); + float flInColor360[3] = { float( inColor24.r ) / float( 255 ), + float( inColor24.g ) / float( 255 ), + float( inColor24.b ) / float( 255 ) }; + + // Find the srgb gamma color this maps to + float flInColorSrgb[3]; + for ( int i = 0; i < 3; i++ ) + { + flInColorSrgb[i] = SrgbLinearToGamma( X360GammaToLinear( flInColor360[i] ) ); + } + + int nInColor[3]; + for ( int i = 0; i < 3; i++ ) + { + nInColor[i] = ( int )( flInColorSrgb[i] * float( COLOR_CORRECTION_TEXTURE_SIZE - 1 ) ); + } + + // Now convert the sRGB out color into 360 gamma space + color24 vOutColor24Srgb = pColors[nInColor[0] + nInColor[1]*COLOR_CORRECTION_TEXTURE_SIZE + nInColor[2]*COLOR_CORRECTION_TEXTURE_SIZE*COLOR_CORRECTION_TEXTURE_SIZE]; + + color24 vOutColor24X360; + vOutColor24X360.r = ( unsigned char )( X360LinearToGamma( SrgbGammaToLinear( float( vOutColor24Srgb.r ) / float( 255 ) ) ) * float( 255 ) ); + vOutColor24X360.g = ( unsigned char )( X360LinearToGamma( SrgbGammaToLinear( float( vOutColor24Srgb.g ) / float( 255 ) ) ) * float( 255 ) ); + vOutColor24X360.b = ( unsigned char )( X360LinearToGamma( SrgbGammaToLinear( float( vOutColor24Srgb.b ) / float( 255 ) ) ) * float( 255 ) ); + + // Copy the outColor and pass that to SetLookupPtr() below + vOutColor24 = vOutColor24X360; + } + //*/ + + SetLookupPtr( lookup, inColor, vOutColor24 ); + colorIndex++; + } + } + } +} + +//----------------------------------------------------------------------------- +// Copy the data to the specified color correction lookup +//----------------------------------------------------------------------------- +void CColorCorrectionSystem::CopyLookup( ColorCorrectionHandle_t handle, const color24 *pSrcColorCorrection ) +{ + if ( handle == m_DefaultColorCorrectionHandle ) + { + return; + } + + ColorCorrectionLookup_t *lookup = FindLookup( handle ); + if ( !lookup ) + return; + + Assert( lookup->m_bLocked ); + Assert( pSrcColorCorrection ); + + Q_memcpy( lookup->m_pColorCorrection, pSrcColorCorrection, sizeof(color24)*COLOR_CORRECTION_TEXTURE_SIZE*COLOR_CORRECTION_TEXTURE_SIZE*COLOR_CORRECTION_TEXTURE_SIZE ); +} + +//----------------------------------------------------------------------------- +// Reset the mapping for the specified color correction lookup +//----------------------------------------------------------------------------- +void CColorCorrectionSystem::ResetLookup( ColorCorrectionHandle_t handle ) +{ + if ( handle == m_DefaultColorCorrectionHandle ) + { + return; + } + + ColorCorrectionLookup_t *lookup = FindLookup( handle ); + if ( !lookup ) + return; + + Assert( lookup->m_bLocked ); + + RGBX5551_t inColor; + + inColor.b = 0; + for ( int b = 0; b < COLOR_CORRECTION_TEXTURE_SIZE; ++b, ++inColor.b ) + { + inColor.g = 0; + for ( int g = 0; g < COLOR_CORRECTION_TEXTURE_SIZE; ++g, ++inColor.g ) + { + inColor.r = 0; + for ( int r = 0; r < COLOR_CORRECTION_TEXTURE_SIZE; ++r, ++inColor.r ) + { + color24 outColor = ConvertToColor24( inColor ); + SetLookupPtr( lookup, inColor, outColor ); + } + } + } +} + +//----------------------------------------------------------------------------- +// Reset the weight to zero for all lookups +//----------------------------------------------------------------------------- +void CColorCorrectionSystem::ResetLookupWeights( ) +{ + m_DefaultColorCorrectionWeight = 0.0f; + + for ( int i=0;im_bResetable ) + { + lookup->m_flWeight = 0.0f; + } + else + { + lookup->m_flWeight = 1.0f; + } + } +} + +//----------------------------------------------------------------------------- +// Convert a color from RGBX5551_t to color24 +//----------------------------------------------------------------------------- +color24 CColorCorrectionSystem::ConvertToColor24( RGBX5551_t inColor ) +{ + color24 out; + out.r = (inColor.r << 3) | (inColor.r >> 2); + out.g = (inColor.g << 3) | (inColor.g >> 2); + out.b = (inColor.b << 3) | (inColor.b >> 2); + return out; +} + +//----------------------------------------------------------------------------- +// Call ReleaseTexture for all ColorCorrectionLookup_t +//----------------------------------------------------------------------------- +void CColorCorrectionSystem::ReleaseTextures( ) +{ + for ( int i=0;iReleaseTexture(); + } +} + +//----------------------------------------------------------------------------- +// Call RestoreTexture for all ColorCorrectionLookup_t +//----------------------------------------------------------------------------- +void CColorCorrectionSystem::RestoreTextures( ) +{ + for ( int i=0;iRestoreTexture(); + } +} + +//----------------------------------------------------------------------------- +// Normalize the active set of color correction weights +//----------------------------------------------------------------------------- +void CColorCorrectionSystem::GetNormalizedWeights( float *pDefaultWeight, float *pLookupWeights ) +{ + float total_weight = 0.0f; + int nLoopCount = min( m_ColorCorrectionList.Count(), (int)COLOR_CORRECTION_MAX_TEXTURES ); + for ( int i=0; im_flWeight; + pLookupWeights[i] = m_ColorCorrectionList[i]->m_flWeight; + } + + for ( int i = nLoopCount; i < COLOR_CORRECTION_MAX_TEXTURES; ++i ) + { + pLookupWeights[i] = 0.0f; + } + + if ( total_weight <= ( 1.0f - 1e-3 ) ) + { + *pDefaultWeight = 1.0f - total_weight; + } + else + { + *pDefaultWeight = 0.0f; + + float inv_total_weight = 1.0f / total_weight; + for ( int i=0; i< nLoopCount; i++ ) + { + pLookupWeights[i] *= inv_total_weight; + } + } +} + +//----------------------------------------------------------------------------- +// Returns the number of active lookup +//----------------------------------------------------------------------------- +int CColorCorrectionSystem::GetNumLookups( ) +{ + int i; + for ( i=0;im_flWeight<=0.0f ) + break; + } + + return i; +} + + +//----------------------------------------------------------------------------- +// Enables/disables resetting of this lookup +//----------------------------------------------------------------------------- +void CColorCorrectionSystem::SetResetable( ColorCorrectionHandle_t handle, bool bResetable ) +{ + ColorCorrectionLookup_t *lookup = FindLookup( handle ); + if ( lookup ) + { + lookup->m_bResetable = bResetable; + } +} + + +//----------------------------------------------------------------------------- +// Returns info for the shaders to control color correction +//----------------------------------------------------------------------------- +void CColorCorrectionSystem::GetCurrentColorCorrection( ShaderColorCorrectionInfo_t* pInfo ) +{ + COMPILE_TIME_ASSERT( COLOR_CORRECTION_MAX_TEXTURES == ARRAYSIZE( pInfo->m_pLookupWeights ) ); + pInfo->m_bIsEnabled = m_bEnabled && ( GetNumLookups() > 0 || m_DefaultColorCorrectionWeight != 0.0f ); + pInfo->m_nLookupCount = GetNumLookups(); + GetNormalizedWeights( &pInfo->m_flDefaultWeight, pInfo->m_pLookupWeights ); +} diff --git a/materialsystem/CMaterialSubRect.cpp b/materialsystem/CMaterialSubRect.cpp new file mode 100644 index 0000000..1b4d386 --- /dev/null +++ b/materialsystem/CMaterialSubRect.cpp @@ -0,0 +1,1069 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//=====================================================================================// + +#include "imaterialinternal.h" +#include "bitmap/tgaloader.h" +#include "colorspace.h" +#include "materialsystem/imaterialvar.h" +#include "materialsystem/itexture.h" +#include +#include "materialsystem_global.h" +#include "shaderapi/ishaderapi.h" +#include "materialsystem/imaterialproxy.h" +#include "shadersystem.h" +#include "materialsystem/imaterialproxyfactory.h" +#include "IHardwareConfigInternal.h" +#include "utlsymbol.h" +#include +#include "filesystem.h" +#include +#include "mempool.h" +#include "shaderapi/ishaderutil.h" +#include "vtf/vtf.h" +#include "tier1/strtools.h" +#include +#include "utlbuffer.h" +#include "mathlib/vmatrix.h" +#include "texturemanager.h" +#include "itextureinternal.h" +#include "cmaterial_queuefriendly.h" +#include "mempool.h" + +static IMaterialVar *CreateMaterialVarFromKeyValue( IMaterial* pMaterial, KeyValues* pKeyValue ); + +//----------------------------------------------------------------------------- +// Material SubRect implementation +//----------------------------------------------------------------------------- +class CMaterialSubRect : public IMaterialInternal +{ +public: + + // pVMTKeyValues and pPatchKeyValues should come from LoadVMTFile() + CMaterialSubRect( char const *pMaterialName, const char *pTextureGroupName, KeyValues *pVMTKeyValues, KeyValues *pPatchKeyValues, bool bAssumeCreateFromFile ); + virtual ~CMaterialSubRect(); + + // IMaterial Interface + const char *GetName() const; + const char *GetTextureGroupName() const; + + int GetMappingWidth(); + int GetMappingHeight(); + + bool InMaterialPage( void ) { return true; } + void GetMaterialOffset( float *pOffset ); + void GetMaterialScale( float *pScale ); + IMaterial *GetMaterialPage( void ) { return m_pMaterialPage; } + + void IncrementReferenceCount( void ); + void DecrementReferenceCount( void ); + + IMaterialVar *FindVar( char const *varName, bool *found, bool complain = true ); + IMaterialVar *FindVarFast( char const *pVarName, unsigned int *pToken ); + + // Sets new VMT shader parameters for the material + virtual void SetShaderAndParams( KeyValues *pKeyValues ); + + int GetEnumerationID() const; + + // Maybe! + void GetReflectivity( Vector& reflect ) { m_pMaterialPage->GetReflectivity( reflect ); } + + + // IMaterialInternal Interface + int GetReferenceCount( void ) const; + void Precache(); + void Uncache( bool bPreserveVars = false ); + // If provided, pKeyValues and pPatchKeyValues should come from LoadVMTFile() + bool PrecacheVars( KeyValues *pKeyValues = NULL, KeyValues *pPatchKeyValues = NULL, CUtlVector *pIncludes = NULL, int nFindContext = MATERIAL_FINDCONTEXT_NONE ); + bool IsPrecached() const; + bool IsPrecachedVars( ) const; + bool IsManuallyCreated() const; + void SetEnumerationID( int id ); + void AddMaterialVar( IMaterialVar *pMaterialVar ); + void MarkAsPreloaded( bool bSet ); + bool IsPreloaded() const; + void ArtificialAddRef(); + void ArtificialRelease(); + + //============================= + // Chained to the material page. + //============================= + // IMaterial Interface. + PreviewImageRetVal_t GetPreviewImageProperties( int *width, int *height, ImageFormat *imageFormat, bool* isTranslucent ) const + { return m_pMaterialPage->GetPreviewImageProperties( width, height, imageFormat, isTranslucent ); } + PreviewImageRetVal_t GetPreviewImage( unsigned char *data, int width, int height, ImageFormat imageFormat ) const + { return m_pMaterialPage->GetPreviewImage( data, width, height, imageFormat ); } + + ShaderRenderState_t *GetRenderState() { return m_pMaterialPage->GetRenderState(); } + int GetNumAnimationFrames() { return m_pMaterialPage->GetNumAnimationFrames(); } + + void GetLowResColorSample( float s, float t, float *color ) const + { + if ( m_pMaterialPage ) + m_pMaterialPage->GetLowResColorSample( s, t, color ); + else + color[ 0 ] = color[ 1 ] = color[ 2 ] = 0.0f; + } + + bool UsesEnvCubemap( void ) { return m_pMaterialPage->UsesEnvCubemap(); } + bool NeedsSoftwareSkinning( void ) { return m_pMaterialPage->NeedsSoftwareSkinning(); } + bool NeedsSoftwareLighting( void ) { return m_pMaterialPage->NeedsSoftwareLighting(); } + bool NeedsTangentSpace( void ) { return m_pMaterialPage->NeedsTangentSpace(); } + bool NeedsPowerOfTwoFrameBufferTexture( bool bCheckSpecificToThisFrame = true ) { return m_pMaterialPage->NeedsPowerOfTwoFrameBufferTexture( bCheckSpecificToThisFrame ); } + bool NeedsFullFrameBufferTexture( bool bCheckSpecificToThisFrame = true ) { return m_pMaterialPage->NeedsFullFrameBufferTexture( bCheckSpecificToThisFrame ); } + bool NeedsLightmapBlendAlpha( void ) { return m_pMaterialPage->NeedsLightmapBlendAlpha(); } + + void AlphaModulate( float alpha ) { m_pMaterialPage->AlphaModulate( alpha ); } + void ColorModulate( float r, float g, float b ) { m_pMaterialPage->ColorModulate( r, g, b ); } + float GetAlphaModulation( ) { return m_pMaterialPage->GetAlphaModulation( ); } + void GetColorModulation( float *r, float *g, float *b ) { m_pMaterialPage->GetColorModulation( r, g, b ); } + + void SetMaterialVarFlag( MaterialVarFlags_t flag, bool on ) { m_pMaterialPage->SetMaterialVarFlag( flag, on ); } + bool GetMaterialVarFlag( MaterialVarFlags_t flag ) const { return m_pMaterialPage->GetMaterialVarFlag( flag ); } + + bool IsTranslucent() { return m_pMaterialPage->IsTranslucent(); } + bool IsTranslucentInternal( float fAlphaModulation ) const { return m_pMaterialPage->IsTranslucentInternal( fAlphaModulation ); } + bool IsAlphaTested() { return m_pMaterialPage->IsAlphaTested(); } + bool IsVertexLit() { return m_pMaterialPage->IsVertexLit(); } + + bool GetPropertyFlag( MaterialPropertyTypes_t type ) { return m_pMaterialPage->GetPropertyFlag( type ); } + + bool IsTwoSided() { return m_pMaterialPage->IsTwoSided(); } + + int GetNumPasses( void ) { return m_pMaterialPage->GetNumPasses(); } + int GetTextureMemoryBytes( void ) { return m_pMaterialPage->GetTextureMemoryBytes(); } + + // IMaterialInternal Interface. + void DrawMesh( VertexCompressionType_t vertexCompression ) { m_pMaterialPage->DrawMesh( vertexCompression ); } + void ReloadTextures( void ) { m_pMaterialPage->ReloadTextures(); } + void SetMinLightmapPageID( int pageID ) + { + m_pMaterialPage->SetMinLightmapPageID( pageID ); + } + + void SetMaxLightmapPageID( int pageID ) + { + m_pMaterialPage->SetMaxLightmapPageID( pageID ); + } + + int GetMinLightmapPageID( ) const { return m_pMaterialPage->GetMinLightmapPageID(); } + int GetMaxLightmapPageID( ) const { return m_pMaterialPage->GetMaxLightmapPageID(); } + + void SetNeedsWhiteLightmap( bool val ) + { + m_pMaterialPage->SetNeedsWhiteLightmap( val ); + } + + bool GetNeedsWhiteLightmap( ) const { return m_pMaterialPage->GetNeedsWhiteLightmap(); } + + IShader * GetShader() const { return m_pMaterialPage->GetShader(); } + void CallBindProxy( void *proxyData ) { m_pMaterialPage->CallBindProxy( proxyData ); } + IMaterial *CheckProxyReplacement( void *proxyData ) { return m_pMaterialPage->CheckProxyReplacement( proxyData ); } + bool HasProxy( void ) const { return m_pMaterialPage->HasProxy(); } + + // Sets the shader associated with the material + void SetShader( const char *pShaderName ) { m_pMaterialPage->SetShader( pShaderName ); } + const char * GetShaderName() const { return m_pMaterialPage->GetShaderName(); } + + virtual void DeleteIfUnreferenced(); + virtual bool IsSpriteCard() { return m_pMaterialPage->IsSpriteCard(); } + + // Can we override this material in debug? + bool NoDebugOverride() const { return m_pMaterialPage->NoDebugOverride(); } + + // Gets the vertex format + VertexFormat_t GetVertexFormat() const { return m_pMaterialPage->GetVertexFormat(); } + + // Gets the morph format + virtual MorphFormat_t GetMorphFormat() const { return m_pMaterialPage->GetMorphFormat(); } + + // diffuse bump lightmap? +// bool IsUsingDiffuseBumpedLighting() const { return m_pChainMaterial->IsUsingDiffuseBumpedLighting(); } + + // lightmap? +// bool IsUsingLightmap() const { return m_pChainMaterial->IsUsingLightmap(); } + + // Gets the vertex usage flags + VertexFormat_t GetVertexUsage() const { return m_pMaterialPage->GetVertexUsage(); } + + // Debugs this material + bool PerformDebugTrace() const { return m_pMaterialPage->PerformDebugTrace(); } + + // Are we suppressed? + bool IsSuppressed() const { return m_pMaterialPage->IsSuppressed(); } + + // Do we use fog? + bool UseFog( void ) const { return m_pMaterialPage->UseFog(); } + + // Should we draw? + void ToggleSuppression() { m_pMaterialPage->ToggleSuppression(); } + void ToggleDebugTrace() { m_pMaterialPage->ToggleDebugTrace(); } + + // Refresh material based on current var values + void Refresh() { m_pMaterialPage->Refresh(); } + void RefreshPreservingMaterialVars() { m_pMaterialPage->RefreshPreservingMaterialVars(); } + + // This computes the state snapshots for this material + void RecomputeStateSnapshots() { m_pMaterialPage->RecomputeStateSnapshots(); } + + // Gets at the shader parameters + int ShaderParamCount() const { return m_pMaterialPage->ShaderParamCount(); } + IMaterialVar **GetShaderParams( void ) { return m_pMaterialPage->GetShaderParams(); } + + bool IsErrorMaterial() const { return false; } + + void SetUseFixedFunctionBakedLighting( bool bEnable ) { m_pMaterialPage->SetUseFixedFunctionBakedLighting( bEnable ); } + bool NeedsFixedFunctionFlashlight() const { return m_pMaterialPage->NeedsFixedFunctionFlashlight(); } + + virtual void DecideShouldReloadFromWhitelist( IFileList *pFileList ) { m_pMaterialPage->DecideShouldReloadFromWhitelist( pFileList ); } + virtual void ReloadFromWhitelistIfMarked() { return m_pMaterialPage->ReloadFromWhitelistIfMarked(); } + virtual bool WasReloadedFromWhitelist() { return m_pMaterialPage->WasReloadedFromWhitelist(); } + + bool IsUsingVertexID( ) const { return m_pMaterialPage->IsUsingVertexID(); } + + virtual void ReportVarChanged( IMaterialVar *pVar ) { m_pMaterialPage->ReportVarChanged(pVar); } + virtual uint32 GetChangeID() const { return m_pMaterialPage->GetChangeID(); } + + virtual bool IsRealTimeVersion( void ) const { return true; } + virtual IMaterialInternal *GetRealTimeVersion( void ) { return this; } + virtual IMaterialInternal *GetQueueFriendlyVersion( void ) { return &m_QueueFriendlyVersion; }; + + virtual void PrecacheMappingDimensions( void ) { m_pMaterialPage->PrecacheMappingDimensions(); } + virtual void FindRepresentativeTexture( void ) { m_pMaterialPage->FindRepresentativeTexture(); } + +private: + + void ParseMaterialVars( KeyValues &keyValues ); + void SetupMaterialVars( void ); + + // Do we use a UNC-specified materal name? + bool UsesUNCFileName() const; + + IMaterialVar *GetDummyMaterialVar(); + +private: + + enum + { + MATERIALSUBRECT_IS_PRECACHED = 0x1, + MATERIALSUBRECT_VARS_IS_PRECACHED = 0x2, + MATERIALSUBRECT_IS_MANUALLY_CREATED = 0x4, + MATERIALSUBRECT_USES_UNC_FILENAME = 0x20, + MATERIALSUBRECT_IS_PRELOADED = 0x40, + MATERIALSUBRECT_ARTIFICIAL_REFCOUNT = 0x80, + }; + + // Fixed-size allocator + DECLARE_FIXEDSIZE_ALLOCATOR( CMaterialSubRect ); + + IMaterialInternal *m_pMaterialPage; + + int m_iEnumID; + + CUtlSymbol m_symName; + CUtlSymbol m_symTextureGroupName; + + Vector2D m_vecOffset; + Vector2D m_vecScale; + Vector2D m_vecSize; + + short m_nRefCount; + + unsigned int m_fLocal; // Local flags - precached etc... + + CUtlVector m_aMaterialVars; + + // Used only by procedural materials; it essentially is an in-memory .VMT file + KeyValues *m_pVMTKeyValues; + +#ifdef _DEBUG + // Makes it easier to see what's going on + char* m_pDebugName; +#endif + + CMaterial_QueueFriendly m_QueueFriendlyVersion; +}; + + +// NOTE: This must be the last file included +// Has to exist *after* fixed size allocator declaration +#include "tier0/memdbgon.h" + +DEFINE_FIXEDSIZE_ALLOCATOR( CMaterialSubRect, 256, true ); + +//----------------------------------------------------------------------------- +// Purpose: Static create method for material subrect. +//----------------------------------------------------------------------------- +IMaterialInternal* IMaterialInternal::CreateMaterialSubRect( char const* pMaterialName, const char *pTextureGroupName, + KeyValues *pVMTKeyValues, KeyValues *pPatchKeyValues, bool bAssumeCreateFromFile ) +{ + return new CMaterialSubRect( pMaterialName, pTextureGroupName, pVMTKeyValues, pPatchKeyValues, bAssumeCreateFromFile ); +} + +//----------------------------------------------------------------------------- +// Purpose: Static destroy method for material subrect. +//----------------------------------------------------------------------------- +void IMaterialInternal::DestroyMaterialSubRect( IMaterialInternal* pMaterial ) +{ + if ( pMaterial ) + { + CMaterialSubRect* pMat = static_cast( pMaterial ); + delete pMat; + } +} + +//----------------------------------------------------------------------------- +// Purpose: Constructor +//----------------------------------------------------------------------------- +CMaterialSubRect::CMaterialSubRect( const char *pMaterialName, const char *pTextureGroupName, + KeyValues *pVMTKeyValues, KeyValues *pPatchKeyValues, bool bAssumeCreateFromFile ) +{ + m_QueueFriendlyVersion.SetRealTimeVersion( this ); + + // Name with extension stripped off. + int len = Q_strlen( pMaterialName ); + char* pTemp = ( char* )_alloca( len + 1 ); + Q_strncpy( pTemp, pMaterialName, len + 1 ); + Q_strlower( pTemp ); + pTemp[ len - 4 ] = '\0'; + m_symName = pTemp; + +#ifdef _DEBUG + m_pDebugName = new char[Q_strlen( pTemp ) + 1]; + Q_strncpy( m_pDebugName, pTemp, Q_strlen( pTemp ) + 1 ); +#endif + + m_pMaterialPage = NULL; + m_iEnumID = 0; + m_symTextureGroupName = pTextureGroupName; + m_vecOffset.Init(); + m_vecScale.Init(); + m_vecSize.Init(); + m_nRefCount = 0; + m_fLocal = 0; + m_aMaterialVars.Purge(); + + if ( pTemp[0] == '/' && pTemp[1] == '/' && pTemp[2] != '/' ) + { + m_fLocal |= MATERIALSUBRECT_USES_UNC_FILENAME; + } + if ( !bAssumeCreateFromFile ) + { + m_pVMTKeyValues = pVMTKeyValues; + if (m_pVMTKeyValues) + { + m_fLocal |= MATERIALSUBRECT_IS_MANUALLY_CREATED; + } + // Precache immediately. We need the material page immediately. + Precache(); + } + else + { + m_pVMTKeyValues = NULL; + PrecacheVars( pVMTKeyValues, pPatchKeyValues ); + Precache(); + } + + Assert( m_pMaterialPage ); + + // Increment the material page usage counter. + m_pMaterialPage->IncrementReferenceCount(); +} + +//----------------------------------------------------------------------------- +// Purpose: Deconstructor +//----------------------------------------------------------------------------- +CMaterialSubRect::~CMaterialSubRect() +{ + Uncache( ); + if( m_nRefCount != 0 ) + { + DevWarning( 2, "Reference Count for Material %s (%d) != 0\n", GetName(), m_nRefCount ); + } + + if ( m_pMaterialPage ) + { + m_pMaterialPage->DecrementReferenceCount(); + m_pMaterialPage = NULL; + } + + if ( m_pVMTKeyValues ) + { + m_pVMTKeyValues->deleteThis(); + m_pVMTKeyValues = NULL; + } + + // m_aMaterialVars is freed, purged, and lit on fire in Uncache() above. + +#ifdef _DEBUG + if ( m_pDebugName ) + { + delete[] m_pDebugName; + m_pDebugName = NULL; + } +#endif +} + +//----------------------------------------------------------------------------- +// Sets new VMT shader parameters for the material +//----------------------------------------------------------------------------- +void CMaterialSubRect::SetShaderAndParams( KeyValues *pKeyValues ) +{ + Uncache(); + + if ( m_pVMTKeyValues ) + { + m_pVMTKeyValues->deleteThis(); + m_pVMTKeyValues = NULL; + } + + m_pVMTKeyValues = pKeyValues ? pKeyValues->MakeCopy() : NULL; + if (m_pVMTKeyValues) + { + m_fLocal |= MATERIALSUBRECT_IS_MANUALLY_CREATED; + } + + if ( g_pShaderDevice->IsUsingGraphics() ) + { + Precache(); + } +} + + +//----------------------------------------------------------------------------- +// Purpose: +//----------------------------------------------------------------------------- +const char *CMaterialSubRect::GetName() const +{ + return m_symName.String(); +} + +//----------------------------------------------------------------------------- +// Purpose: +//----------------------------------------------------------------------------- +const char *CMaterialSubRect::GetTextureGroupName() const +{ + return m_symTextureGroupName.String(); +} + +//----------------------------------------------------------------------------- +// Purpose: Return the size of the subrect not the texture page size (width). +//----------------------------------------------------------------------------- +int CMaterialSubRect::GetMappingWidth() +{ + return int( m_vecSize.x ); +} + +//----------------------------------------------------------------------------- +// Purpose: Return the size of the subrect not the texture page size (height). +//----------------------------------------------------------------------------- +int CMaterialSubRect::GetMappingHeight() +{ + return int( m_vecSize.y ); +} + +//----------------------------------------------------------------------------- +// Purpose: Return the texture offset into the texture page. +//----------------------------------------------------------------------------- +void CMaterialSubRect::GetMaterialOffset( float *pOffset ) +{ + pOffset[0] = m_vecOffset.x; + pOffset[1] = m_vecOffset.y; +} + +//----------------------------------------------------------------------------- +// Purpose: Return the texture scale (size) within the texture page. +//----------------------------------------------------------------------------- +void CMaterialSubRect::GetMaterialScale( float *pScale ) +{ + pScale[0] = m_vecScale.x; + pScale[1] = m_vecScale.y; +} + +//----------------------------------------------------------------------------- +// Purpose: +//----------------------------------------------------------------------------- +void CMaterialSubRect::IncrementReferenceCount( void ) +{ + ++m_nRefCount; +} + +//----------------------------------------------------------------------------- +// Purpose: +//----------------------------------------------------------------------------- +void CMaterialSubRect::DecrementReferenceCount( void ) +{ + --m_nRefCount; +} + +//----------------------------------------------------------------------------- +// Purpose: +//----------------------------------------------------------------------------- +int CMaterialSubRect::GetReferenceCount( void ) const +{ + return m_nRefCount; +} + + +//----------------------------------------------------------------------------- +// Purpose: +//----------------------------------------------------------------------------- +bool CMaterialSubRect::IsPrecached() const +{ + return ( m_fLocal & MATERIALSUBRECT_IS_PRECACHED ) != 0; +} + + +//----------------------------------------------------------------------------- +// Purpose: +//----------------------------------------------------------------------------- +bool CMaterialSubRect::IsPrecachedVars( ) const +{ + return ( m_fLocal & MATERIALSUBRECT_VARS_IS_PRECACHED ) != 0; +} + + +//----------------------------------------------------------------------------- +// Purpose: +//----------------------------------------------------------------------------- +bool CMaterialSubRect::IsManuallyCreated() const +{ + return ( m_fLocal & MATERIALSUBRECT_IS_MANUALLY_CREATED ) != 0; +} + + +//----------------------------------------------------------------------------- +// Do we use a UNC-specified materal name? +//----------------------------------------------------------------------------- +bool CMaterialSubRect::UsesUNCFileName() const +{ + return ( m_fLocal & MATERIALSUBRECT_USES_UNC_FILENAME ) != 0; +} + + +//----------------------------------------------------------------------------- +// Purpose: +//----------------------------------------------------------------------------- +void CMaterialSubRect::Precache() +{ + // Are we already precached? + if( IsPrecached() ) + return; + + // Load data from the .vmt file. + if( !PrecacheVars() ) + return; + + m_QueueFriendlyVersion.UpdateToRealTime(); + + // Precached. + m_fLocal |= MATERIALSUBRECT_IS_PRECACHED; +} + + +//----------------------------------------------------------------------------- +// Purpose: +//----------------------------------------------------------------------------- +bool CMaterialSubRect::PrecacheVars( KeyValues * pVMTKeyValues, KeyValues * pPatchKeyValues, CUtlVector *pIncludes, int nFindContext ) +{ + // FIXME: Should call through to the parent material for all of this??? + // We should get both parameters or neither + Assert( ( pVMTKeyValues == NULL ) ? ( pPatchKeyValues == NULL ) : ( pPatchKeyValues != NULL ) ); + + // Are we already precached? + if( IsPrecachedVars() ) + return true; + + // load data from the vmt file + bool bOk = false; + KeyValues *vmtKeyValues = NULL; + KeyValues *patchKeyValues = NULL; + if ( m_pVMTKeyValues ) + { + // Use the procedural KeyValues + vmtKeyValues = m_pVMTKeyValues; + patchKeyValues = new KeyValues( "vmt_patches" ); + + // The caller should not be passing in KeyValues if we have procedural ones + Assert( ( pVMTKeyValues == NULL ) && ( pPatchKeyValues == NULL ) ); + } + else if ( pVMTKeyValues ) + { + // Use the passed-in (already-loaded) KeyValues + vmtKeyValues = pVMTKeyValues; + patchKeyValues = pPatchKeyValues; + } + else + { + // load data from the vmt file + vmtKeyValues = new KeyValues( "vmt" ); + patchKeyValues = new KeyValues( "vmt_patches" ); + if( !LoadVMTFile( *vmtKeyValues, *patchKeyValues, GetName(), UsesUNCFileName(), NULL ) ) + { + Warning( "CMaterialSubRect::PrecacheVars: error loading vmt file for %s\n", GetName() ); + goto precacheVarsDone; + } + } + + // Get the "Subrect" material vars. + ParseMaterialVars( *vmtKeyValues ); + + // Setup the "Subrect" material vars. + SetupMaterialVars(); + + // Vars are precached. + m_fLocal |= MATERIALSUBRECT_VARS_IS_PRECACHED; + bOk = true; + +precacheVarsDone: + // Clean up + if ( ( vmtKeyValues != m_pVMTKeyValues ) && ( vmtKeyValues != pVMTKeyValues ) ) + { + vmtKeyValues->deleteThis(); + } + if ( patchKeyValues != pPatchKeyValues ) + { + patchKeyValues->deleteThis(); + } + + return bOk; +} + +//----------------------------------------------------------------------------- +// Purpose: +//----------------------------------------------------------------------------- +void CMaterialSubRect::ParseMaterialVars( KeyValues &keyValues ) +{ + KeyValues *pKeyValues = &keyValues; + + // I'm not quite sure how this can happen, but we'll see... + const char *pShaderName = pKeyValues->GetName(); + if ( !pShaderName ) + { + DevWarning( 1, "CMaterialSubRect::InitializeShader: Shader not specified in material %s.\n", GetName() ); + Assert( 0 ); + pShaderName = IsPC() && !IsEmulatingGL() ? "Wireframe_DX6" : "Wireframe_DX9"; + } + + // Verify we have the correct "shader." There is only one type. + // Needs to be case insensitive because we can't guarantee case specified in VMTs + if ( !Q_stricmp( pShaderName, "Subrect" ) ) + { + KeyValues *pVar = pKeyValues->GetFirstSubKey(); + while ( pVar ) + { + if ( !Q_stricmp( pVar->GetName(), "$Pos" ) ) + { + sscanf( pVar->GetString(), "%f %f", &m_vecOffset.x, &m_vecOffset.y ); + } + else if ( !Q_stricmp( pVar->GetName(), "$Size" ) ) + { + sscanf( pVar->GetString(), "%f %f", &m_vecSize.x, &m_vecSize.y ); + } + else if ( !Q_stricmp( pVar->GetName(), "$Material" ) ) + { + m_pMaterialPage = static_cast( MaterialSystem()->FindMaterial( pVar->GetString(), TEXTURE_GROUP_DECAL ) ); + m_pMaterialPage = m_pMaterialPage->GetRealTimeVersion(); //always work with the realtime material internally + } + +// else if ( !Q_stricmp( pVar->GetName(), "$decalscale" ) ) +// { +// m_flDecalScale = pVar->GetFloat(); +// } + + // Add var to list. + IMaterialVar *pNewVar = CreateMaterialVarFromKeyValue( this, pVar ); + if ( pNewVar ) + { + m_aMaterialVars.AddToTail( pNewVar ); + } + + // Continue getting the keys until they are all found. + pVar = pVar->GetNextKey(); + } + } +} + +//----------------------------------------------------------------------------- +// Purpose: +//----------------------------------------------------------------------------- +void CMaterialSubRect::SetupMaterialVars( void ) +{ + if ( !m_pMaterialPage ) + { + DevWarning( 1, "CMaterialSubRect::SetupMaterialVars: Invalid Material Page!\n" ); + return; + } + + // Ask the material page for its size. + int nMaterialPageWidth = m_pMaterialPage->GetMappingWidth(); + int nMaterialPageHeight = m_pMaterialPage->GetMappingHeight(); + + // Normalize the offset and scale. + float flOOWidth = 1.0f / static_cast( nMaterialPageWidth ); + float flOOHeight = 1.0f / static_cast( nMaterialPageHeight ); + + // Add 0.5f to push the image "in" by 1/2 a texel, and subtract 1.0f to push it + // "in" by 1/2 a texel on the other side. + m_vecOffset.x += 1.0f; + m_vecOffset.y += 1.0f; + m_vecOffset.x *= flOOWidth; + m_vecOffset.y *= flOOHeight; + m_vecScale.x = ( m_vecSize.x - 2.0f ) * flOOWidth; + m_vecScale.y = ( m_vecSize.y - 2.0f ) * flOOHeight; +} + +//----------------------------------------------------------------------------- +// Purpose: Look through +//----------------------------------------------------------------------------- +IMaterialVar *CMaterialSubRect::FindVar( char const *varName, bool *found, bool complain ) +{ + // Look for the var in the material page - it has precedence. + IMaterialVar *pVar = m_pMaterialPage->FindVar( varName, found, false ); + if ( *found ) + return pVar; + + // Look for the var in the local list of vars. + MaterialVarSym_t symVar = IMaterialVar::FindSymbol( varName ); + if ( symVar != UTL_INVAL_SYMBOL ) + { + int nVarCount = m_aMaterialVars.Count(); + for ( int iVar = 0; iVar < nVarCount; ++iVar ) + { + if ( m_aMaterialVars[iVar]->GetNameAsSymbol() == symVar ) + { + *found = true; + return m_aMaterialVars[iVar]; + } + } + } + + // Not found! + if( complain ) + { + static int complainCount = 0; + if( complainCount < 100 ) + { + DevWarning( 1, "No such variable \"%s\" for material \"%s\"\n", varName, GetName() ); + complainCount++; + } + } + + return GetDummyMaterialVar(); +} + +IMaterialVar *CMaterialSubRect::FindVarFast( char const *pVarName, unsigned int *pToken ) +{ + // Look for the var in the material page - it has precedence. + IMaterialVar *pVar = m_pMaterialPage->FindVarFast( pVarName, pToken ); + if ( pVar ) + return pVar; + + if ( *pToken != UTL_INVAL_SYMBOL ) + { + int nVarCount = m_aMaterialVars.Count(); + for ( int iVar = 0; iVar < nVarCount; ++iVar ) + { + if ( m_aMaterialVars[iVar]->GetNameAsSymbol() == *pToken ) + return m_aMaterialVars[iVar]; + } + } + + return NULL; +} + +//----------------------------------------------------------------------------- +// Purpose: +//----------------------------------------------------------------------------- +IMaterialVar *CMaterialSubRect::GetDummyMaterialVar() +{ + static IMaterialVar* pDummyVar = 0; + if ( !pDummyVar ) + pDummyVar = IMaterialVar::Create( 0, "$dummyVar", 0 ); + + return pDummyVar; +} + +//----------------------------------------------------------------------------- +// Purpose: +//----------------------------------------------------------------------------- +int CMaterialSubRect::GetEnumerationID() const +{ + return m_iEnumID; +} + +//----------------------------------------------------------------------------- +// Purpose: +//----------------------------------------------------------------------------- +void CMaterialSubRect::SetEnumerationID( int id ) +{ + m_iEnumID = id; +} + +//----------------------------------------------------------------------------- +// Purpose: +//----------------------------------------------------------------------------- +void CMaterialSubRect::Uncache( bool bPreserveVars ) +{ + MaterialLock_t hMaterialLock = MaterialSystem()->Lock(); + + // Don't bother if we're not cached + if ( IsPrecached() ) + { + m_fLocal &= ~MATERIALSUBRECT_IS_PRECACHED; + } + + if ( !bPreserveVars ) + { + if ( IsPrecachedVars() ) + { + for ( int i = 0; i < m_aMaterialVars.Count(); ++i ) + { + IMaterialVar::Destroy( m_aMaterialVars[i] ); + } + m_aMaterialVars.Purge(); + + m_fLocal &= ~MATERIALSUBRECT_VARS_IS_PRECACHED; + } + } + + MaterialSystem()->Unlock( hMaterialLock ); +} + +//----------------------------------------------------------------------------- +// Purpose: +//----------------------------------------------------------------------------- +void CMaterialSubRect::AddMaterialVar( IMaterialVar *pMaterialVar ) +{ + m_aMaterialVars.AddToTail( pMaterialVar ); +} + +void CMaterialSubRect::MarkAsPreloaded( bool bSet ) +{ + if ( bSet ) + { + m_fLocal |= MATERIALSUBRECT_IS_PRELOADED; + } + else + { + m_fLocal &= ~MATERIALSUBRECT_IS_PRELOADED; + } +} + +bool CMaterialSubRect::IsPreloaded() const +{ + return ( m_fLocal & MATERIALSUBRECT_IS_PRELOADED ) != 0; +} + +void CMaterialSubRect::ArtificialAddRef( void ) +{ + if ( m_fLocal & MATERIALSUBRECT_ARTIFICIAL_REFCOUNT ) + { + // already done + return; + } + + m_fLocal |= MATERIALSUBRECT_ARTIFICIAL_REFCOUNT; + m_nRefCount++; +} + +void CMaterialSubRect::ArtificialRelease( void ) +{ + if ( !( m_fLocal & MATERIALSUBRECT_ARTIFICIAL_REFCOUNT ) ) + { + return; + } + + m_fLocal &= ~MATERIALSUBRECT_ARTIFICIAL_REFCOUNT; + m_nRefCount--; +} + +//----------------------------------------------------------------------------- +// Parser utilities +//----------------------------------------------------------------------------- +static inline bool IsWhitespace( char c ) +{ + return c == ' ' || c == '\t'; +} + +static inline bool IsEndline( char c ) +{ + return c == '\n' || c == '\0'; +} + +static inline bool IsVector( char const* v ) +{ + while (IsWhitespace(*v)) + { + ++v; + if (IsEndline(*v)) + return false; + } + return *v == '[' || *v == '{'; +} + +//----------------------------------------------------------------------------- +// Creates a vector material var +//----------------------------------------------------------------------------- +static IMaterialVar* CreateVectorMaterialVarFromKeyValue( IMaterial* pMaterial, KeyValues* pKeyValue ) +{ + float vecVal[4]; + char const* pScan = pKeyValue->GetString(); + bool divideBy255 = false; + + // skip whitespace + while( IsWhitespace(*pScan) ) + { + ++pScan; + } + + if( *pScan == '{' ) + { + divideBy255 = true; + } + else + { + Assert( *pScan == '[' ); + } + + // skip the '[' + ++pScan; + int i; + for( i = 0; i < 4; i++ ) + { + // skip whitespace + while( IsWhitespace(*pScan) ) + { + ++pScan; + } + + if( IsEndline(*pScan) || *pScan == ']' || *pScan == '}' ) + { + if (*pScan != ']' && *pScan != '}') + { + Warning( "Warning in .VMT file (%s): no ']' or '}' found in vector key \"%s\".\n" + "Did you forget to surround the vector with \"s?\n", pMaterial->GetName(), pKeyValue->GetName() ); + } + + // allow for vec2's, etc. + vecVal[i] = 0.0f; + break; + } + + char* pEnd; + + vecVal[i] = strtod( pScan, &pEnd ); + if (pScan == pEnd) + { + Warning( "Error in .VMT file: error parsing vector element \"%s\" in \"%s\"\n", pKeyValue->GetName(), pMaterial->GetName() ); + return 0; + } + + pScan = pEnd; + } + + if( divideBy255 ) + { + vecVal[0] *= ( 1.0f / 255.0f ); + vecVal[1] *= ( 1.0f / 255.0f ); + vecVal[2] *= ( 1.0f / 255.0f ); + vecVal[3] *= ( 1.0f / 255.0f ); + } + + // Create the variable! + return IMaterialVar::Create( pMaterial, pKeyValue->GetName(), vecVal, i ); +} + +//----------------------------------------------------------------------------- +// Creates a vector material var +//----------------------------------------------------------------------------- +static IMaterialVar* CreateMatrixMaterialVarFromKeyValue( IMaterial* pMaterial, KeyValues* pKeyValue ) +{ + char const* pScan = pKeyValue->GetString(); + + // Matrices can be specified one of two ways: + // [ # # # # # # # # # # # # # # # # ] + // or + // center # # scale # # rotate # translate # # + + VMatrix mat; + int count = sscanf( pScan, " [ %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f ]", + &mat.m[0][0], &mat.m[0][1], &mat.m[0][2], &mat.m[0][3], + &mat.m[1][0], &mat.m[1][1], &mat.m[1][2], &mat.m[1][3], + &mat.m[2][0], &mat.m[2][1], &mat.m[2][2], &mat.m[2][3], + &mat.m[3][0], &mat.m[3][1], &mat.m[3][2], &mat.m[3][3] ); + if (count == 16) + { + return IMaterialVar::Create( pMaterial, pKeyValue->GetName(), mat ); + } + + Vector2D scale, center; + float angle; + Vector2D translation; + count = sscanf( pScan, " center %f %f scale %f %f rotate %f translate %f %f", + ¢er.x, ¢er.y, &scale.x, &scale.y, &angle, &translation.x, &translation.y ); + if (count != 7) + return NULL; + + VMatrix temp; + MatrixBuildTranslation( mat, -center.x, -center.y, 0.0f ); + MatrixBuildScale( temp, scale.x, scale.y, 1.0f ); + MatrixMultiply( temp, mat, mat ); + MatrixBuildRotateZ( temp, angle ); + MatrixMultiply( temp, mat, mat ); + MatrixBuildTranslation( temp, center.x + translation.x, center.y + translation.y, 0.0f ); + MatrixMultiply( temp, mat, mat ); + + // Create the variable! + return IMaterialVar::Create( pMaterial, pKeyValue->GetName(), mat ); +} + +//----------------------------------------------------------------------------- +// Purpose: +//----------------------------------------------------------------------------- +static IMaterialVar *CreateMaterialVarFromKeyValue( IMaterial* pMaterial, KeyValues* pKeyValue ) +{ + switch( pKeyValue->GetDataType() ) + { + case KeyValues::TYPE_INT: + { + return IMaterialVar::Create( pMaterial, pKeyValue->GetName(), pKeyValue->GetInt() ); + } + + case KeyValues::TYPE_FLOAT: + { + return IMaterialVar::Create( pMaterial, pKeyValue->GetName(), pKeyValue->GetFloat() ); + } + + case KeyValues::TYPE_STRING: + { + char const* pString = pKeyValue->GetString(); + if (!pString || !pString[0]) + return 0; + + // Look for matrices + IMaterialVar *pMatrixVar = CreateMatrixMaterialVarFromKeyValue( pMaterial, pKeyValue ); + if ( pMatrixVar ) + return pMatrixVar; + + // Look for vectors + if ( !IsVector( pString ) ) + return IMaterialVar::Create( pMaterial, pKeyValue->GetName(), pString ); + + // Parse the string as a vector... + return CreateVectorMaterialVarFromKeyValue( pMaterial, pKeyValue ); + } + } + + return 0; +} + +void CMaterialSubRect::DeleteIfUnreferenced() +{ + if ( m_nRefCount > 0 ) + return; + MaterialSystem()->RemoveMaterialSubRect( this ); +} diff --git a/materialsystem/IHardwareConfigInternal.h b/materialsystem/IHardwareConfigInternal.h new file mode 100644 index 0000000..9704a52 --- /dev/null +++ b/materialsystem/IHardwareConfigInternal.h @@ -0,0 +1,30 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $Header: $ +// $NoKeywords: $ +//=============================================================================// + +#ifndef IHARDWARECONFIGINTERNAL_H +#define IHARDWARECONFIGINTERNAL_H + +#ifdef _WIN32 +#pragma once +#endif + + +#include "materialsystem/imaterialsystemhardwareconfig.h" + +//----------------------------------------------------------------------------- +// Material system configuration +//----------------------------------------------------------------------------- +class IHardwareConfigInternal : public IMaterialSystemHardwareConfig +{ +public: + // Gets at the HW specific shader DLL name + virtual const char *GetHWSpecificShaderDLLName() const = 0; +}; + + +#endif // IHARDWARECONFIGINTERNAL_H diff --git a/materialsystem/IShaderSystem.h b/materialsystem/IShaderSystem.h new file mode 100644 index 0000000..81f3a8e --- /dev/null +++ b/materialsystem/IShaderSystem.h @@ -0,0 +1,104 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $Header: $ +// $NoKeywords: $ +// An interface that should not ever be accessed directly from shaders +// but instead is visible only to shaderlib. +//===========================================================================// + +#ifndef ISHADERSYSTEM_H +#define ISHADERSYSTEM_H + +#ifdef _WIN32 +#pragma once +#endif + +#include "interface.h" +#include + +//----------------------------------------------------------------------------- +// Forward declarations +//----------------------------------------------------------------------------- +enum Sampler_t; +class ITexture; +class IShader; + + +//----------------------------------------------------------------------------- +// The Shader system interface version +//----------------------------------------------------------------------------- +#define SHADERSYSTEM_INTERFACE_VERSION "ShaderSystem002" + + +//----------------------------------------------------------------------------- +// Modulation flags +//----------------------------------------------------------------------------- +enum +{ + SHADER_USING_COLOR_MODULATION = 0x1, + SHADER_USING_ALPHA_MODULATION = 0x2, + SHADER_USING_FLASHLIGHT = 0x4, + SHADER_USING_FIXED_FUNCTION_BAKED_LIGHTING = 0x8, + SHADER_USING_EDITOR = 0x10, +}; + + +//----------------------------------------------------------------------------- +// The shader system (a singleton) +//----------------------------------------------------------------------------- +abstract_class IShaderSystem +{ +public: + virtual ShaderAPITextureHandle_t GetShaderAPITextureBindHandle( ITexture *pTexture, int nFrameVar, int nTextureChannel = 0 ) =0; + + // Binds a texture + virtual void BindTexture( Sampler_t sampler1, ITexture *pTexture, int nFrameVar = 0 ) = 0; + virtual void BindTexture( Sampler_t sampler1, Sampler_t sampler2, ITexture *pTexture, int nFrameVar = 0 ) = 0; + + // Takes a snapshot + virtual void TakeSnapshot( ) = 0; + + // Draws a snapshot + virtual void DrawSnapshot( bool bMakeActualDrawCall = true ) = 0; + + // Are we using graphics? + virtual bool IsUsingGraphics() const = 0; + + // Are we using graphics? + virtual bool CanUseEditorMaterials() const = 0; +}; + + +//----------------------------------------------------------------------------- +// The Shader plug-in DLL interface version +//----------------------------------------------------------------------------- +#define SHADER_DLL_INTERFACE_VERSION "ShaderDLL004" + + +//----------------------------------------------------------------------------- +// The Shader interface versions +//----------------------------------------------------------------------------- +abstract_class IShaderDLLInternal +{ +public: + // Here's where the app systems get to learn about each other + virtual bool Connect( CreateInterfaceFn factory, bool bIsMaterialSystem ) = 0; + virtual void Disconnect( bool bIsMaterialSystem ) = 0; + + // Returns the number of shaders defined in this DLL + virtual int ShaderCount() const = 0; + + // Returns information about each shader defined in this DLL + virtual IShader *GetShader( int nShader ) = 0; +}; + + +//----------------------------------------------------------------------------- +// Singleton interface +//----------------------------------------------------------------------------- +IShaderDLLInternal *GetShaderDLLInternal(); + + +#endif // ISHADERSYSTEM_H diff --git a/materialsystem/MaterialSystem.rc b/materialsystem/MaterialSystem.rc new file mode 100644 index 0000000..64f8f90 --- /dev/null +++ b/materialsystem/MaterialSystem.rc @@ -0,0 +1,63 @@ +// Microsoft Visual C++ generated resource script. +// +#include "resource.h" + +#define APSTUDIO_READONLY_SYMBOLS +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 2 resource. +// +#include "afxres.h" + +///////////////////////////////////////////////////////////////////////////// +#undef APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +// English (U.S.) resources + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) +#ifdef _WIN32 +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US +#pragma code_page(1252) +#endif //_WIN32 + +#ifdef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// TEXTINCLUDE +// + +1 TEXTINCLUDE +BEGIN + "resource.h\0" +END + +2 TEXTINCLUDE +BEGIN + "#include ""afxres.h""\r\n" + "\0" +END + +3 TEXTINCLUDE +BEGIN + "\r\n" + "\0" +END + +#endif // APSTUDIO_INVOKED + +#endif // English (U.S.) resources +///////////////////////////////////////////////////////////////////////////// + + + +#ifndef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 3 resource. +// + + +///////////////////////////////////////////////////////////////////////////// +#endif // not APSTUDIO_INVOKED + diff --git a/materialsystem/Resource.rc b/materialsystem/Resource.rc new file mode 100644 index 0000000..61d0d83 --- /dev/null +++ b/materialsystem/Resource.rc @@ -0,0 +1,109 @@ +//Microsoft Developer Studio generated resource script. +// +#include "resource.h" + +#define APSTUDIO_READONLY_SYMBOLS +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 2 resource. +// +#include "afxres.h" + +///////////////////////////////////////////////////////////////////////////// +#undef APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +// English (U.S.) resources + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) +#ifdef _WIN32 +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US +#pragma code_page(1252) +#endif //_WIN32 + +#ifdef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// TEXTINCLUDE +// + +1 TEXTINCLUDE DISCARDABLE +BEGIN + "resource.h\0" +END + +2 TEXTINCLUDE DISCARDABLE +BEGIN + "#include ""afxres.h""\r\n" + "\0" +END + +3 TEXTINCLUDE DISCARDABLE +BEGIN + "\r\n" + "\0" +END + +#endif // APSTUDIO_INVOKED + + +#ifndef _MAC +///////////////////////////////////////////////////////////////////////////// +// +// Version +// + +VS_VERSION_INFO VERSIONINFO + FILEVERSION 1,0,0,1 + PRODUCTVERSION 1,0,0,1 + FILEFLAGSMASK 0x3fL +#ifdef _DEBUG + FILEFLAGS 0x1L +#else + FILEFLAGS 0x0L +#endif + FILEOS 0x40004L + FILETYPE 0x2L + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904b0" + BEGIN + VALUE "Comments", "\0" + VALUE "CompanyName", "VALVE\0" + VALUE "FileDescription", "materialsystem\0" + VALUE "FileVersion", "1, 0, 0, 1\0" + VALUE "InternalName", "materialsystem\0" + VALUE "LegalCopyright", "Copyright © 2003\0" + VALUE "LegalTrademarks", "\0" + VALUE "OriginalFilename", "materialsystem.dll\0" + VALUE "PrivateBuild", "\0" + VALUE "ProductName", "VALVE materialsystem\0" + VALUE "ProductVersion", "1, 0, 0, 1\0" + VALUE "SpecialBuild", "\0" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x409, 1200 + END +END + +#endif // !_MAC + +#endif // English (U.S.) resources +///////////////////////////////////////////////////////////////////////////// + + + +#ifndef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 3 resource. +// + + +///////////////////////////////////////////////////////////////////////////// +#endif // not APSTUDIO_INVOKED + diff --git a/materialsystem/checkmaterials.cpp b/materialsystem/checkmaterials.cpp new file mode 100644 index 0000000..30432f8 --- /dev/null +++ b/materialsystem/checkmaterials.cpp @@ -0,0 +1,664 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//============================================================================= + +#include "pch_materialsystem.h" + +// NOTE: currently this file is marked as "exclude from build" + +//#define _CHECK_MATERIALS_FOR_PROBLEMS 1 +#ifdef _CHECK_MATERIALS_FOR_PROBLEMS +#include "vtf/vtf.h" +#include "tier1/utlbuffer.h" +#include "tier1/utlstring.h" +void CheckMateralsInDirectoryRecursive( const char *pRoot, const char *pDirectory ); +#endif + +#ifdef _CHECK_MATERIALS_FOR_PROBLEMS + +//----------------------------------------------------------------------------- +// Does a texture have alpha? +//----------------------------------------------------------------------------- +static bool DoesTextureUseAlpha( const char *pTextureName, const char *pMaterialName ) +{ + if ( IsX360() ) + { + // not supporting + return false; + } + + // Special textures start with '_'.. + if ( pTextureName[0] == '_' ) + return false; + + // The texture name doubles as the relative file name + // It's assumed to have already been set by this point + // Compute the cache name + char pCacheFileName[MATERIAL_MAX_PATH]; + Q_snprintf( pCacheFileName, sizeof( pCacheFileName ), "materials/%s.vtf", pTextureName ); + + CUtlBuffer buf; + FileHandle_t fileHandle = g_pFullFileSystem->Open( pCacheFileName, "rb" ); + if ( fileHandle == FILESYSTEM_INVALID_HANDLE) + { + Warning( "Material \"%s\": can't open texture \"%s\"\n", pMaterialName, pCacheFileName ); + return false; + } + + // Check the .vtf for an alpha channel + IVTFTexture *pVTFTexture = CreateVTFTexture(); + + int nHeaderSize = VTFFileHeaderSize( VTF_MAJOR_VERSION ); + buf.EnsureCapacity( nHeaderSize ); + + // read the header first.. it's faster!! + g_pFullFileSystem->Read( buf.Base(), nHeaderSize, fileHandle ); + buf.SeekPut( CUtlBuffer::SEEK_HEAD, nHeaderSize ); + + // Unserialize the header + bool bUsesAlpha = false; + + if (!pVTFTexture->Unserialize( buf, true )) + { + Warning( "Error reading material \"%s\"\n", pCacheFileName ); + g_pFullFileSystem->Close(fileHandle); + } + else + { + if ( pVTFTexture->Flags() & (TEXTUREFLAGS_ONEBITALPHA | TEXTUREFLAGS_EIGHTBITALPHA) ) + { + bUsesAlpha = true; + } + } + + DestroyVTFTexture( pVTFTexture ); + g_pFullFileSystem->Close( fileHandle ); + return bUsesAlpha; +} + + +//----------------------------------------------------------------------------- +// Does a texture have alpha? +//----------------------------------------------------------------------------- +static bool DoesTextureUseNormal( const char *pTextureName, const char *pMaterialName, bool &bUsesAlpha, bool &bIsCompressed, int &nSizeInBytes ) +{ + nSizeInBytes = 0; + bUsesAlpha = false; + + if ( IsX360() ) + { + // not supporting + return false; + } + + // Special textures start with '_'.. + if ( !pTextureName || ( pTextureName[0] == '_' ) || ( pTextureName[0] == 0 ) ) + return false; + + // The texture name doubles as the relative file name + // It's assumed to have already been set by this point + // Compute the cache name + char pCacheFileName[MATERIAL_MAX_PATH]; + Q_snprintf( pCacheFileName, sizeof( pCacheFileName ), "materials/%s.vtf", pTextureName ); + + CUtlBuffer buf; + FileHandle_t fileHandle = g_pFullFileSystem->Open( pCacheFileName, "rb" ); + if ( fileHandle == FILESYSTEM_INVALID_HANDLE) + { +// Warning( "Material \"%s\": can't open texture \"%s\"\n", pMaterialName, pCacheFileName ); + return false; + } + + // Check the .vtf for an alpha channel + IVTFTexture *pVTFTexture = CreateVTFTexture(); + + int nHeaderSize = VTFFileHeaderSize( VTF_MAJOR_VERSION ); + buf.EnsureCapacity( nHeaderSize ); + + // read the header first.. it's faster!! + g_pFullFileSystem->Read( buf.Base(), nHeaderSize, fileHandle ); + buf.SeekPut( CUtlBuffer::SEEK_HEAD, nHeaderSize ); + + // Unserialize the header + bool bUsesNormal = false; + if ( !pVTFTexture->Unserialize( buf, true ) ) + { + Warning( "Error reading material \"%s\"\n", pCacheFileName ); + } + else + { + if ( pVTFTexture->Flags() & TEXTUREFLAGS_NORMAL ) + { + bUsesAlpha = false; + bUsesNormal = true; + bIsCompressed = ImageLoader::IsCompressed( pVTFTexture->Format() ) || ( pVTFTexture->Format() == IMAGE_FORMAT_A8 ); + nSizeInBytes = pVTFTexture->ComputeTotalSize(); + if ( pVTFTexture->Flags() & (TEXTUREFLAGS_ONEBITALPHA | TEXTUREFLAGS_EIGHTBITALPHA) ) + { + bUsesAlpha = true; + } + } + } + + DestroyVTFTexture( pVTFTexture ); + g_pFullFileSystem->Close( fileHandle ); + return bUsesNormal; +} + + +//----------------------------------------------------------------------------- +// Is this a real texture +//----------------------------------------------------------------------------- +static bool IsTexture( const char *pTextureName ) +{ + // Special textures start with '_'.. + if ( pTextureName[0] == '_' ) + return false; + + // The texture name doubles as the relative file name + // It's assumed to have already been set by this point + // Compute the cache name + char pCacheFileName[MATERIAL_MAX_PATH]; + Q_snprintf( pCacheFileName, sizeof( pCacheFileName ), "materials/%s.vtf", pTextureName ); + + FileHandle_t fileHandle = g_pFullFileSystem->Open( pCacheFileName, "rb" ); + if ( fileHandle == FILESYSTEM_INVALID_HANDLE) + return false; + + g_pFullFileSystem->Close( fileHandle ); + return true; +} + + +//----------------------------------------------------------------------------- +// Scan material + all subsections for key +//----------------------------------------------------------------------------- +static float MaterialFloatKeyValue( KeyValues *pKeyValues, const char *pKeyName, float flDefault ) +{ + float flValue = pKeyValues->GetFloat( pKeyName, flDefault ); + if ( flValue != flDefault ) + return flValue; + + for( KeyValues *pSubKey = pKeyValues->GetFirstTrueSubKey(); pSubKey; pSubKey = pSubKey->GetNextTrueSubKey() ) + { + float flValue = MaterialFloatKeyValue( pSubKey, pKeyName, flDefault ); + if ( flValue != flDefault ) + return flValue; + } + + return flDefault; +} + +int ParseVectorFromKeyValueString( KeyValues *pKeyValue, const char *pMaterialName, float vecVal[4] ); + +static bool AsVectorsEqual( int nDim1, float *pVector1, int nDim2, float *pVector2 ) +{ + if ( nDim1 != nDim2 ) + return false; + + for ( int i = 0; i < nDim1; ++i ) + { + if ( fabs( pVector1[i] - pVector2[i] ) > 1e-3 ) + return false; + } + + return true; +} + +static bool MaterialVectorKeyValue( KeyValues *pKeyValues, const char *pKeyName, int nDefaultDim, float *pDefault, int *pDim, float *pVector ) +{ + int nDim; + float retVal[4]; + + KeyValues *pValue = pKeyValues->FindKey( pKeyName ); + if ( pValue ) + { + switch( pValue->GetDataType() ) + { + case KeyValues::TYPE_INT: + { + int nInt = pValue->GetInt(); + for ( int i = 0; i < 4; ++i ) + { + retVal[i] = nInt; + } + if ( !AsVectorsEqual( nDefaultDim, pDefault, nDefaultDim, retVal ) ) + { + *pDim = nDefaultDim; + memcpy( pVector, retVal, nDefaultDim * sizeof(float) ); + return true; + } + } + break; + + case KeyValues::TYPE_FLOAT: + { + float flFloat = pValue->GetFloat(); + for ( int i = 0; i < 4; ++i ) + { + retVal[i] = flFloat; + } + if ( !AsVectorsEqual( nDefaultDim, pDefault, nDefaultDim, retVal ) ) + { + *pDim = nDefaultDim; + memcpy( pVector, retVal, nDefaultDim * sizeof(float) ); + return true; + } + } + break; + + case KeyValues::TYPE_STRING: + { + nDim = ParseVectorFromKeyValueString( pValue, "", retVal ); + if ( !AsVectorsEqual( nDefaultDim, pDefault, nDim, retVal ) ) + { + *pDim = nDim; + memcpy( pVector, retVal, nDim * sizeof(float) ); + return true; + } + } + break; + } + } + + for( KeyValues *pSubKey = pKeyValues->GetFirstTrueSubKey(); pSubKey; pSubKey = pSubKey->GetNextTrueSubKey() ) + { + if ( MaterialVectorKeyValue( pSubKey, pKeyName, nDefaultDim, pDefault, &nDim, retVal ) ) + { + *pDim = nDim; + memcpy( pVector, retVal, nDim * sizeof(float) ); + return true; + } + } + + *pDim = nDefaultDim; + memcpy( pVector, pDefault, nDefaultDim * sizeof(float) ); + return false; +} + + +//----------------------------------------------------------------------------- +// Scan material + all subsections for key +//----------------------------------------------------------------------------- +static bool DoesMaterialHaveKey( KeyValues *pKeyValues, const char *pKeyName ) +{ + if ( pKeyValues->GetString( pKeyName, NULL ) != NULL ) + return true; + + for( KeyValues *pSubKey = pKeyValues->GetFirstTrueSubKey(); pSubKey; pSubKey = pSubKey->GetNextTrueSubKey() ) + { + if ( DoesMaterialHaveKey( pSubKey, pKeyName ) ) + return true; + } + + return false; +} + + +//----------------------------------------------------------------------------- +// Scan all materials for errors +//----------------------------------------------------------------------------- +static int s_nNormalBytes; +static int s_nNormalCompressedBytes; +static int s_nNormalPalettizedBytes; +static int s_nNormalWithAlphaBytes; +static int s_nNormalWithAlphaCompressedBytes; + +struct VTFInfo_t +{ + CUtlString m_VTFName; + bool m_bFoundInVMT; +}; + +void CheckKeyValues( KeyValues *pKeyValues, CUtlVector &vtf ) +{ + for ( KeyValues *pSubKey = pKeyValues->GetFirstValue(); pSubKey; pSubKey = pSubKey->GetNextValue() ) + { + if ( pSubKey->GetDataType() != KeyValues::TYPE_STRING ) + continue; + + if ( IsTexture( pSubKey->GetString() ) ) + { + int nLen = Q_strlen( pSubKey->GetString() ) + 1; + char *pTemp = (char*)_alloca( nLen ); + memcpy( pTemp, pSubKey->GetString(), nLen ); + Q_FixSlashes( pTemp ); + + int nCount = vtf.Count(); + for ( int i = 0; i < nCount; ++i ) + { + if ( Q_stricmp( vtf[i].m_VTFName, pTemp ) ) + continue; + vtf[i].m_bFoundInVMT = true; + break; + } + } + } + + for ( KeyValues *pSubKey = pKeyValues->GetFirstTrueSubKey(); pSubKey; pSubKey = pSubKey->GetNextTrueSubKey() ) + { + CheckKeyValues( pSubKey, vtf ); + } +} + +void CheckMaterial( KeyValues *pKeyValues, const char *pRoot, const char *pFileName, CUtlVector &vtf ) +{ + const char *pShaderName = pKeyValues->GetName(); +/* + if ( Q_stristr( pShaderName, "Water" ) || + Q_stristr( pShaderName, "Eyeball" ) || + Q_stristr( pShaderName, "Shadow" ) || + Q_stristr( pShaderName, "Refract" ) || + Q_stristr( pShaderName, "Predator" ) || + Q_stristr( pShaderName, "ParticleSphere" ) || + Q_stristr( pShaderName, "DebugLuxels" ) || + Q_stristr( pShaderName, "GooInGlass" ) || + Q_stristr( pShaderName, "Modulate" ) || + Q_stristr( pShaderName, "UnlitTwoTexture" ) || + Q_stristr( pShaderName, "Cloud" ) || + Q_stristr( pShaderName, "WorldVertexTransition" ) || + Q_stristr( pShaderName, "DecalModulate" ) || + Q_stristr( pShaderName, "DecalBaseTimesLightmapAlphaBlendSelfIllum" ) || + Q_stristr( pShaderName, "Sprite" ) ) + { + return; + } + + // Check for alpha channels + const char *pBaseTextureName = pKeyValues->GetString( "$basetexture", NULL ); + if ( pBaseTextureName != NULL ) + { + if ( DoesTextureUseAlpha( pBaseTextureName, pFileName ) ) + { + float flAlpha = MaterialFloatKeyValue( pKeyValues, "$alpha", 1.0f ); + bool bHasVertexAlpha = DoesMaterialHaveKey( pKeyValues, "$vertexalpha" ); // Modulation always happens here whether we want it to or not + bool bHasAlphaTest = DoesMaterialHaveKey( pKeyValues, "$alphatest" ); + bool bHasTranslucent = DoesMaterialHaveKey( pKeyValues, "$translucent" ); + bool bHasSelfIllum = DoesMaterialHaveKey( pKeyValues, "$selfillum" ); + bool bHasBaseAlphaEnvMapMask = DoesMaterialHaveKey( pKeyValues, "$basealphaenvmapmask" ); + if ( (flAlpha == 1.0f) && !bHasVertexAlpha && !bHasAlphaTest && !bHasTranslucent && !bHasSelfIllum && !bHasBaseAlphaEnvMapMask ) + { + Warning("Material \"%s\": BASETEXTURE \"%s\"\n", pFileName, pBaseTextureName ); + } + } + } +*/ + +/* +// Check for bump, spec, and no normalmapalphaenvmapmask + const char *pBumpmapName = pKeyValues->GetString( "$bumpmap", NULL ); + if ( pBumpmapName != NULL ) + { + if ( DoesTextureUseAlpha( pBumpmapName, pFileName ) ) + { + bool bHasEnvmap = DoesMaterialHaveKey( pKeyValues, "$envmap" ); + bool bHasNormalMapAlphaEnvMapMask = DoesMaterialHaveKey( pKeyValues, "$normalmapalphaenvmapmask" ); + if ( !bHasEnvmap || !bHasNormalMapAlphaEnvMapMask ) + { + Warning("Material \"%s\": BUMPMAP \"%s\"\n", pFileName, pBumpmapName ); + } + } + } +*/ + +/* + if ( !Q_stristr( pShaderName, "LightmappedGeneric" ) && + !Q_stristr( pShaderName, "VertexLitGeneric" ) ) + { + return; + } + + if ( DoesMaterialHaveKey( pKeyValues, "$envmap" ) && DoesMaterialHaveKey( pKeyValues, "$bumpmap" ) ) + { + int nDim; + float retVal[4]; + float defaultVal[4] = { 1, 1, 1, 1 }; + + if ( MaterialVectorKeyValue( pKeyValues, "$envmaptint", 3, defaultVal, &nDim, retVal ) ) + { + Warning("ENVMAP + ENVMAPTINT : Material \"%s\"\n", pFileName ); + } +// else +// { +// Warning("ENVMAP only: Material \"%s\"\n", pFileName ); +// } + } + */ + +/* + if ( !Q_stristr( pShaderName, "Refract" ) ) + { + return; + } + + if ( !DoesMaterialHaveKey( pKeyValues, "$envmap" ) ) + { + bool bUsesAlpha, bIsCompressed, bIsPalettized; + int nSizeInBytes; + if ( DoesTextureUseNormal( pKeyValues->GetString( "$normalmap" ), + pFileName, bUsesAlpha, bIsCompressed, bIsPalettized, nSizeInBytes ) ) + { + if ( bIsCompressed ) + { + Warning("Bad : Material compressed \"%s\"\n", pFileName ); + } + else + { + Warning("Bad : Material \"%s\"\n", pFileName ); + } + } + } +*/ + +/* + if ( !Q_stristr( pShaderName, "WorldTwoTextureBlend" ) ) + { + return; + } + + if ( DoesMaterialHaveKey( pKeyValues, "$envmap" ) || + DoesMaterialHaveKey( pKeyValues, "$parallaxmap" ) || + DoesMaterialHaveKey( pKeyValues, "$bumpmap" ) || + DoesMaterialHaveKey( pKeyValues, "$vertexcolor" ) || + DoesMaterialHaveKey( pKeyValues, "$basetexture2" ) + ) + { + Warning("Bad : Material \"%s\"\n", pFileName ); + } +*/ + + for ( KeyValues *pSubKey = pKeyValues->GetFirstValue(); pSubKey; pSubKey = pSubKey->GetNextValue() ) + { +// Msg( " Checking %s\n", pSubKey->GetString() ); + if ( pSubKey->GetDataType() != KeyValues::TYPE_STRING ) + continue; + + bool bUsesAlpha, bIsCompressed; + int nSizeInBytes; + if ( DoesTextureUseNormal( pSubKey->GetString(), pFileName, bUsesAlpha, bIsCompressed, nSizeInBytes ) ) + { + if ( bUsesAlpha ) + { + if ( bIsCompressed ) + { + s_nNormalWithAlphaCompressedBytes += nSizeInBytes; + } + else + { + s_nNormalWithAlphaBytes += nSizeInBytes; + Msg( "Normal texture w alpha uncompressed %s\n", pSubKey->GetString() ); + } + } + else + { + if ( bIsCompressed ) + { + s_nNormalCompressedBytes += nSizeInBytes; + } + else + { + s_nNormalBytes += nSizeInBytes; + } + } + } + } + +/* + if ( !Q_stristr( pShaderName, "VertexLitGeneric" ) ) + return; + + if ( !DoesMaterialHaveKey( pKeyValues, "$envmap" ) && DoesMaterialHaveKey( pKeyValues, "$bumpmap" ) ) + { + Warning("BUMPMAP + no ENVMAP : Material \"%s\"\n", pFileName ); + } +*/ + +// CheckKeyValues( pKeyValues, vtf ); +} + +//----------------------------------------------------------------------------- +// Build list of all VTFs +//----------------------------------------------------------------------------- +void CheckVTFInDirectoryRecursive( const char *pRoot, const char *pDirectory, CUtlVector< VTFInfo_t > &vtf ) +{ +#define BUF_SIZE 1024 + char buf[BUF_SIZE]; + WIN32_FIND_DATA wfd; + HANDLE findHandle; + + sprintf( buf, "%s/%s/*.vtf", pRoot, pDirectory ); + + findHandle = FindFirstFile( buf, &wfd ); + if ( findHandle != INVALID_HANDLE_VALUE ) + { + do + { + int i = vtf.AddToTail( ); + + char buf[MAX_PATH]; + char buf2[MAX_PATH]; + Q_snprintf( buf, MAX_PATH, "%s/%s", pDirectory, wfd.cFileName ); + Q_FixSlashes( buf ); + + Q_StripExtension( buf, buf2, sizeof(buf2) ); + Assert( !Q_strnicmp( buf2, "materials\\", 10 ) ); + + vtf[i].m_VTFName = &buf2[10]; + vtf[i].m_bFoundInVMT = false; + + } while ( FindNextFile ( findHandle, &wfd ) ); + + FindClose ( findHandle ); + } + + // do subdirectories + sprintf( buf, "%s/%s/*.*", pRoot, pDirectory ); + findHandle = FindFirstFile( buf, &wfd ); + if ( findHandle != INVALID_HANDLE_VALUE ) + { + do + { + if( wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) + { + if( ( strcmp( wfd.cFileName, ".." ) == 0 ) || + ( strcmp( wfd.cFileName, "." ) == 0 ) ) + { + continue; + } + + char buf[MAX_PATH]; + Q_snprintf( buf, MAX_PATH, "%s/%s", pDirectory, wfd.cFileName ); + CheckVTFInDirectoryRecursive( pRoot, buf, vtf ); + } + } while ( FindNextFile ( findHandle, &wfd ) ); + FindClose ( findHandle ); + } + +#undef BUF_SIZE +} + + +//----------------------------------------------------------------------------- +// Scan all materials for errors +//----------------------------------------------------------------------------- +void _CheckMateralsInDirectoryRecursive( const char *pRoot, const char *pDirectory, CUtlVector< VTFInfo_t > &vtf ) +{ +#define BUF_SIZE 1024 + char buf[BUF_SIZE]; + WIN32_FIND_DATA wfd; + HANDLE findHandle; + + sprintf( buf, "%s/%s/*.vmt", pRoot, pDirectory ); + findHandle = FindFirstFile( buf, &wfd ); + if ( findHandle != INVALID_HANDLE_VALUE ) + { + do + { + KeyValues * vmtKeyValues = new KeyValues("vmt"); + + char pFileName[MAX_PATH]; + Q_snprintf( pFileName, sizeof( pFileName ), "%s/%s", pDirectory, wfd.cFileName ); + if ( !vmtKeyValues->LoadFromFile( g_pFullFileSystem, pFileName, "GAME" ) ) + { + Warning( "CheckMateralsInDirectoryRecursive: can't open \"%s\"\n", pFileName ); + continue; + } + + CheckMaterial( vmtKeyValues, pRoot, pFileName, vtf ); + + vmtKeyValues->deleteThis(); + + } while ( FindNextFile ( findHandle, &wfd ) ); + + FindClose ( findHandle ); + } + + // do subdirectories + sprintf( buf, "%s/%s/*.*", pRoot, pDirectory ); + findHandle = FindFirstFile( buf, &wfd ); + if ( findHandle != INVALID_HANDLE_VALUE ) + { + do + { + if( wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) + { + if( ( strcmp( wfd.cFileName, ".." ) == 0 ) || + ( strcmp( wfd.cFileName, "." ) == 0 ) ) + { + continue; + } + + char buf[MAX_PATH]; + Q_snprintf( buf, MAX_PATH, "%s/%s", pDirectory, wfd.cFileName ); + _CheckMateralsInDirectoryRecursive( pRoot, buf, vtf ); + } + } while ( FindNextFile ( findHandle, &wfd ) ); + FindClose ( findHandle ); + } + +// Msg( "Normal only %d/%d/%d Normal w alpha %d/%d\n", s_nNormalBytes, s_nNormalPalettizedBytes, s_nNormalCompressedBytes, s_nNormalWithAlphaBytes, s_nNormalWithAlphaCompressedBytes ); +#undef BUF_SIZE +} + +void CheckMateralsInDirectoryRecursive( const char *pRoot, const char *pDirectory ) +{ + CUtlVector< VTFInfo_t > vtfNames; +// CheckVTFInDirectoryRecursive( pRoot, pDirectory, vtfNames ); + _CheckMateralsInDirectoryRecursive( pRoot, pDirectory, vtfNames ); + + /* + int nCount = vtfNames.Count(); + for ( int i = 0; i < nCount; ++i ) + { + if ( !vtfNames[i].m_bFoundInVMT ) + { + Msg( "Unused VTF %s\n", vtfNames[i].m_VTFName ); + } + } + */ +} + +#endif // _CHECK_MATERIALS_FOR_PROBLEMS + diff --git a/materialsystem/cmaterial.cpp b/materialsystem/cmaterial.cpp new file mode 100644 index 0000000..90f53d6 --- /dev/null +++ b/materialsystem/cmaterial.cpp @@ -0,0 +1,3599 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: Implementation of a material +// +//===========================================================================// + +#include "imaterialinternal.h" +#include "bitmap/tgaloader.h" +#include "colorspace.h" +#include "materialsystem/imaterialvar.h" +#include "materialsystem/itexture.h" +#include +#include "materialsystem_global.h" +#include "shaderapi/ishaderapi.h" +#include "materialsystem/imaterialproxy.h" +#include "shadersystem.h" +#include "materialsystem/imaterialproxyfactory.h" +#include "IHardwareConfigInternal.h" +#include "utlsymbol.h" +#include +#include "filesystem.h" +#include +#include "mempool.h" +#include "shaderapi/ishaderutil.h" +#include "vtf/vtf.h" +#include "tier1/strtools.h" +#include +#include "utlbuffer.h" +#include "mathlib/vmatrix.h" +#include "texturemanager.h" +#include "itextureinternal.h" +#include "mempool.h" +#include "tier1/callqueue.h" +#include "cmaterial_queuefriendly.h" +#include "ifilelist.h" +#include "tier0/icommandline.h" +#include "tier0/minidump.h" + +// #define PROXY_TRACK_NAMES + +//----------------------------------------------------------------------------- +// Material implementation +//----------------------------------------------------------------------------- +class CMaterial : public IMaterialInternal +{ +public: + // Members of the IMaterial interface + const char *GetName() const; + const char *GetTextureGroupName() const; + + PreviewImageRetVal_t GetPreviewImageProperties( int *width, int *height, + ImageFormat *imageFormat, bool* isTranslucent ) const; + PreviewImageRetVal_t GetPreviewImage( unsigned char *data, int width, int height, + ImageFormat imageFormat ) const; + + int GetMappingWidth( ); + int GetMappingHeight( ); + int GetNumAnimationFrames( ); + + bool InMaterialPage( void ) { return false; } + void GetMaterialOffset( float *pOffset ); + void GetMaterialScale( float *pOffset ); + IMaterial *GetMaterialPage( void ) { return NULL; } + + void IncrementReferenceCount( ); + void DecrementReferenceCount( ); + int GetEnumerationID( ) const; + void GetLowResColorSample( float s, float t, float *color ) const; + + IMaterialVar * FindVar( char const *varName, bool *found, bool complain = true ); + IMaterialVar * FindVarFast( char const *pVarName, unsigned int *pToken ); + + // Sets new VMT shader parameters for the material + virtual void SetShaderAndParams( KeyValues *pKeyValues ); + + bool UsesEnvCubemap( void ); + bool NeedsSoftwareSkinning( void ); + virtual bool NeedsSoftwareLighting( void ); + bool NeedsTangentSpace( void ); + bool NeedsPowerOfTwoFrameBufferTexture( bool bCheckSpecificToThisFrame = true ); + bool NeedsFullFrameBufferTexture( bool bCheckSpecificToThisFrame = true ); + virtual bool IsUsingVertexID( ) const; + + // GR - Is lightmap alpha needed? + bool NeedsLightmapBlendAlpha( void ); + + virtual void AlphaModulate( float alpha ); + virtual void ColorModulate( float r, float g, float b ); + virtual float GetAlphaModulation(); + virtual void GetColorModulation( float *r, float *g, float *b ); + + // Gets the morph format + virtual MorphFormat_t GetMorphFormat() const; + + void SetMaterialVarFlag( MaterialVarFlags_t flag, bool on ); + bool GetMaterialVarFlag( MaterialVarFlags_t flag ) const; + + bool IsTranslucent(); + bool IsTranslucentInternal( float fAlphaModulation ) const; //need to centralize the logic without relying on the *current* alpha modulation being that which is stored in m_pShaderParams[ALPHA]. + bool IsAlphaTested(); + bool IsVertexLit(); + virtual bool IsSpriteCard(); + + void GetReflectivity( Vector& reflect ); + bool GetPropertyFlag( MaterialPropertyTypes_t type ); + + // Is the material visible from both sides? + bool IsTwoSided(); + + int GetNumPasses( void ); + int GetTextureMemoryBytes( void ); + + void SetUseFixedFunctionBakedLighting( bool bEnable ); + + virtual bool IsPrecached( ) const; + +public: + // stuff that is visible only from within the material system + + // constructor, destructor + CMaterial( char const* materialName, const char *pTextureGroupName, KeyValues *pVMTKeyValues ); + virtual ~CMaterial(); + + void DrawMesh( VertexCompressionType_t vertexCompression ); + int GetReferenceCount( ) const; + void Uncache( bool bPreserveVars = false ); + void Precache(); + void ReloadTextures( void ); + // If provided, pKeyValues and pPatchKeyValues should come from LoadVMTFile() + bool PrecacheVars( KeyValues *pKeyValues = NULL, KeyValues *pPatchKeyValues = NULL, CUtlVector *pIncludes = NULL, int nFindContext = MATERIAL_FINDCONTEXT_NONE ); + void SetMinLightmapPageID( int pageID ); + void SetMaxLightmapPageID( int pageID ); + int GetMinLightmapPageID( ) const; + int GetMaxLightmapPageID( ) const; + void SetNeedsWhiteLightmap( bool val ); + bool GetNeedsWhiteLightmap( ) const; + bool IsPrecachedVars( ) const; + IShader * GetShader() const; + const char *GetShaderName() const; + + virtual void DeleteIfUnreferenced(); + + void SetEnumerationID( int id ); + void CallBindProxy( void *proxyData ); + virtual IMaterial *CheckProxyReplacement( void *proxyData ); + bool HasProxy( void ) const; + + // Sets the shader associated with the material + void SetShader( const char *pShaderName ); + + // Can we override this material in debug? + bool NoDebugOverride() const; + + // Gets the vertex format + VertexFormat_t GetVertexFormat() const; + + // diffuse bump lightmap? + bool IsUsingDiffuseBumpedLighting() const; + + // lightmap? + bool IsUsingLightmap() const; + + // Gets the vertex usage flags + VertexFormat_t GetVertexUsage() const; + + // Debugs this material + bool PerformDebugTrace() const; + + // Are we suppressed? + bool IsSuppressed() const; + + // Do we use fog? + bool UseFog( void ) const; + + // Should we draw? + void ToggleSuppression(); + void ToggleDebugTrace(); + + // Refresh material based on current var values + void Refresh(); + void RefreshPreservingMaterialVars(); + + // This computes the state snapshots for this material + void RecomputeStateSnapshots(); + + // Gets at the shader parameters + virtual int ShaderParamCount() const; + virtual IMaterialVar **GetShaderParams( void ); + + virtual void AddMaterialVar( IMaterialVar *pMaterialVar ); + + virtual bool IsErrorMaterial() const; + + // Was this manually created (not read from a file?) + virtual bool IsManuallyCreated() const; + + virtual bool NeedsFixedFunctionFlashlight() const; + + virtual void MarkAsPreloaded( bool bSet ); + virtual bool IsPreloaded() const; + + virtual void ArtificialAddRef( void ); + virtual void ArtificialRelease( void ); + + virtual void ReportVarChanged( IMaterialVar *pVar ) + { + m_ChangeID++; + } + virtual void ClearContextData( void ); + + virtual uint32 GetChangeID() const { return m_ChangeID; } + + virtual bool IsRealTimeVersion( void ) const { return true; } + virtual IMaterialInternal *GetRealTimeVersion( void ) { return this; } + virtual IMaterialInternal *GetQueueFriendlyVersion( void ) { return &m_QueueFriendlyVersion; } + + void DecideShouldReloadFromWhitelist( IFileList *pFilesToReload ); + void ReloadFromWhitelistIfMarked(); + bool WasReloadedFromWhitelist(); + +private: + // Initializes, cleans up the shader params + void CleanUpShaderParams(); + + // Sets up an error shader when we run into problems. + void SetupErrorShader(); + + // Does this material have a UNC-file name? + bool UsesUNCFileName() const; + + // Prints material flags. + void PrintMaterialFlags( int flags, int flagsDefined ); + + // Parses material flags + bool ParseMaterialFlag( KeyValues* pParseValue, IMaterialVar* pFlagVar, + IMaterialVar* pFlagDefinedVar, bool parsingOverrides, int& flagMask, int& overrideMask ); + + // Computes the material vars for the shader + int ParseMaterialVars( IShader* pShader, KeyValues& keyValues, + KeyValues* pOverride, bool modelDefault, IMaterialVar** ppVars, int nFindContext = MATERIAL_FINDCONTEXT_NONE ); + + // Figures out the preview image for worldcraft + char const* GetPreviewImageName( ); + char const* GetPreviewImageFileName( void ) const; + + // Hooks up the shader, returns keyvalues of fallback that was used + KeyValues* InitializeShader( KeyValues &keyValues, KeyValues &patchKeyValues, int nFindContext = MATERIAL_FINDCONTEXT_NONE ); + + // Finds the flag associated with a particular flag name + int FindMaterialVarFlag( char const* pFlagName ) const; + + // Initializes, cleans up the state snapshots + bool InitializeStateSnapshots(); + void CleanUpStateSnapshots(); + + // Initializes, cleans up the material proxy + void InitializeMaterialProxy( KeyValues* pFallbackKeyValues ); + void CleanUpMaterialProxy(); + void DetermineProxyReplacements( KeyValues *pFallbackKeyValues ); + + // Creates, destroys snapshots + RenderPassList_t *CreateRenderPassList(); + void DestroyRenderPassList( RenderPassList_t *pPassList ); + + // Grabs the texture width and height from the var list for faster access + void PrecacheMappingDimensions( ); + + // Gets the renderstate + virtual ShaderRenderState_t *GetRenderState(); + + // Do we have a valid renderstate? + bool IsValidRenderState() const; + + // Get the material var flags + int GetMaterialVarFlags() const; + void SetMaterialVarFlags( int flags, bool on ); + int GetMaterialVarFlags2() const; + void SetMaterialVarFlags2( int flags, bool on ); + + // Returns a dummy material variable + IMaterialVar* GetDummyVariable(); + + IMaterialVar* GetShaderParam( int id ); + + void FindRepresentativeTexture( void ); + + bool ShouldSkipVar( KeyValues *pMaterialVar, bool * pWasConditional ); + + + // Fixed-size allocator + DECLARE_FIXEDSIZE_ALLOCATOR( CMaterial ); + +private: + enum + { + MATERIAL_NEEDS_WHITE_LIGHTMAP = 0x1, + MATERIAL_IS_PRECACHED = 0x2, + MATERIAL_VARS_IS_PRECACHED = 0x4, + MATERIAL_VALID_RENDERSTATE = 0x8, + MATERIAL_IS_MANUALLY_CREATED = 0x10, + MATERIAL_USES_UNC_FILENAME = 0x20, + MATERIAL_IS_PRELOADED = 0x40, + MATERIAL_ARTIFICIAL_REFCOUNT = 0x80, + }; + + int m_iEnumerationID; + + int m_minLightmapPageID; + int m_maxLightmapPageID; + + unsigned short m_MappingWidth; + unsigned short m_MappingHeight; + + IShader *m_pShader; + + CUtlSymbol m_Name; + // Any textures created for this material go under this texture group. + CUtlSymbol m_TextureGroupName; + + CInterlockedInt m_RefCount; + unsigned short m_Flags; + + unsigned char m_VarCount; + + CUtlVector< IMaterialProxy * > m_ProxyInfo; + +#ifdef PROXY_TRACK_NAMES + // Array to track names of above material proxies. Useful for tracking down issues with proxies. + CUtlVector< CUtlString > m_ProxyInfoNames; +#endif + + IMaterialVar** m_pShaderParams; + IMaterialProxy *m_pReplacementProxy; + ShaderRenderState_t m_ShaderRenderState; + + // This remembers filenames of VMTs that we included so we can sv_pure/flush ourselves if any of them need to be reloaded. + CUtlVector m_VMTIncludes; + bool m_bShouldReloadFromWhitelist; // Tells us if the material decided it should be reloaded due to sv_pure whitelist changes. + + ITextureInternal *m_representativeTexture; + Vector m_Reflectivity; + uint32 m_ChangeID; + + // Used only by procedural materials; it essentially is an in-memory .VMT file + KeyValues *m_pVMTKeyValues; + +#if defined( _DEBUG ) + // Makes it easier to see what's going on + char *m_pDebugName; +#endif + +protected: + CMaterial_QueueFriendly m_QueueFriendlyVersion; +}; + + +// NOTE: This must be the last file included +// Has to exist *after* fixed size allocator declaration +#include "tier0/memdbgon.h" + +// Forward decls of helper functions for dealing with patch vmts. +static void ApplyPatchKeyValues( KeyValues &keyValues, KeyValues &patchKeyValues ); +static bool AccumulateRecursiveVmtPatches( KeyValues &patchKeyValuesOut, KeyValues **ppBaseKeyValuesOut, + const KeyValues& keyValues, const char *pPathID, CUtlVector *pIncludes ); + +//----------------------------------------------------------------------------- +// Parser utilities +//----------------------------------------------------------------------------- +static inline bool IsWhitespace( char c ) +{ + return c == ' ' || c == '\t'; +} + +static inline bool IsEndline( char c ) +{ + return c == '\n' || c == '\0'; +} + +static inline bool IsVector( char const* v ) +{ + while (IsWhitespace(*v)) + { + ++v; + if (IsEndline(*v)) + return false; + } + return *v == '[' || *v == '{'; +} + + +//----------------------------------------------------------------------------- +// Methods to create state snapshots +//----------------------------------------------------------------------------- +#include "tier0/memdbgoff.h" + +#ifndef _CONSOLE +struct EditorRenderStateList_t +{ + // Store combo of alpha, color, fixed-function baked lighting, flashlight, editor mode + RenderPassList_t m_Snapshots[SNAPSHOT_COUNT_EDITOR]; + + DECLARE_FIXEDSIZE_ALLOCATOR( EditorRenderStateList_t ); +}; +#endif + +struct StandardRenderStateList_t +{ + // Store combo of alpha, color, fixed-function baked lighting, flashlight + RenderPassList_t m_Snapshots[SNAPSHOT_COUNT_NORMAL]; + + DECLARE_FIXEDSIZE_ALLOCATOR( StandardRenderStateList_t ); +}; + +#include "tier0/memdbgon.h" + +#ifndef _CONSOLE +DEFINE_FIXEDSIZE_ALLOCATOR( EditorRenderStateList_t, 256, true ); +#endif +DEFINE_FIXEDSIZE_ALLOCATOR( StandardRenderStateList_t, 256, true ); + + +//----------------------------------------------------------------------------- +// class factory methods +//----------------------------------------------------------------------------- +DEFINE_FIXEDSIZE_ALLOCATOR( CMaterial, 256, true ); + +IMaterialInternal* IMaterialInternal::CreateMaterial( char const* pMaterialName, const char *pTextureGroupName, KeyValues *pVMTKeyValues ) +{ + MaterialLock_t hMaterialLock = MaterialSystem()->Lock(); + IMaterialInternal *pResult = new CMaterial( pMaterialName, pTextureGroupName, pVMTKeyValues ); + MaterialSystem()->Unlock( hMaterialLock ); + return pResult; +} + +void IMaterialInternal::DestroyMaterial( IMaterialInternal* pMaterial ) +{ + MaterialLock_t hMaterialLock = MaterialSystem()->Lock(); + if (pMaterial) + { + Assert( pMaterial->IsRealTimeVersion() ); + CMaterial* pMatImp = static_cast(pMaterial); + // Deletion of the error material is deferred until after all other materials have been deleted. + // See CMaterialSystem::CleanUpErrorMaterial() in cmaterialsystem.cpp. + if ( !pMatImp->IsErrorMaterial() ) + { + delete pMatImp; + } + } + MaterialSystem()->Unlock( hMaterialLock ); +} + +//----------------------------------------------------------------------------- +// constructor, destructor +//----------------------------------------------------------------------------- +CMaterial::CMaterial( char const* materialName, const char *pTextureGroupName, KeyValues *pKeyValues ) +{ + m_Reflectivity.Init( 0.2f, 0.2f, 0.2f ); + int len = Q_strlen(materialName); + char* pTemp = (char*)_alloca( len + 1 ); + + // Strip off the extension + Q_StripExtension( materialName, pTemp, len+1 ); + Q_strlower( pTemp ); + +#if defined( _X360 ) + // material names are expected to be forward slashed for correct sort and find behavior! + // assert now to track alternate or regressed path that is source of inconsistency + Assert( strchr( pTemp, '\\' ) == NULL ); +#endif + + // Convert it to a symbol + m_Name = pTemp; + +#if defined( _DEBUG ) + m_pDebugName = new char[strlen(pTemp) + 1]; + Q_strncpy( m_pDebugName, pTemp, strlen(pTemp) + 1 ); +#endif + + m_bShouldReloadFromWhitelist = false; + m_Flags = 0; + m_pShader = NULL; + m_pShaderParams = NULL; + m_RefCount = 0; + m_representativeTexture = NULL; + m_pReplacementProxy = NULL; + m_VarCount = 0; + m_MappingWidth = m_MappingHeight = 0; + m_iEnumerationID = 0; + m_minLightmapPageID = m_maxLightmapPageID = 0; + m_TextureGroupName = pTextureGroupName; + m_pVMTKeyValues = pKeyValues; + if (m_pVMTKeyValues) + { + m_Flags |= MATERIAL_IS_MANUALLY_CREATED; + } + + if ( pTemp[0] == '/' && pTemp[1] == '/' && pTemp[2] != '/' ) + { + m_Flags |= MATERIAL_USES_UNC_FILENAME; + } + + // Initialize the renderstate to something indicating nothing should be drawn + m_ShaderRenderState.m_Flags = 0; + m_ShaderRenderState.m_VertexFormat = m_ShaderRenderState.m_VertexUsage = 0; + m_ShaderRenderState.m_MorphFormat = 0; + m_ShaderRenderState.m_pSnapshots = CreateRenderPassList(); + m_ChangeID = 0; + + m_QueueFriendlyVersion.SetRealTimeVersion( this ); +} + +CMaterial::~CMaterial() +{ + MaterialSystem()->UnbindMaterial( this ); + + Uncache(); + + if ( m_RefCount != 0 ) + { + DevWarning( 2, "Reference Count for Material %s (%d) != 0\n", GetName(), (int) m_RefCount ); + } + + if ( m_pVMTKeyValues ) + { + m_pVMTKeyValues->deleteThis(); + m_pVMTKeyValues = NULL; + } + + DestroyRenderPassList( m_ShaderRenderState.m_pSnapshots ); + + m_representativeTexture = NULL; + +#if defined( _DEBUG ) + delete [] m_pDebugName; +#endif + + // Deliberately stomp our VTable so that we can detect cases where code tries to access freed materials. + int *p = (int *)this; + *p = 0xc0dedbad; +} + + +void CMaterial::ClearContextData( void ) +{ + int nSnapshotCount = SnapshotTypeCount(); + for( int i = 0 ; i < nSnapshotCount ; i++ ) + for( int j = 0 ; j < m_ShaderRenderState.m_pSnapshots[i].m_nPassCount; j++ ) + { + if ( m_ShaderRenderState.m_pSnapshots[i].m_pContextData[j] ) + { + delete m_ShaderRenderState.m_pSnapshots[i].m_pContextData[j]; + m_ShaderRenderState.m_pSnapshots[i].m_pContextData[j] = NULL; + } + + } +} + +//----------------------------------------------------------------------------- +// Sets new VMT shader parameters for the material +//----------------------------------------------------------------------------- +void CMaterial::SetShaderAndParams( KeyValues *pKeyValues ) +{ + Uncache(); + + if ( m_pVMTKeyValues ) + { + m_pVMTKeyValues->deleteThis(); + m_pVMTKeyValues = NULL; + } + + m_pVMTKeyValues = pKeyValues ? pKeyValues->MakeCopy() : NULL; + if (m_pVMTKeyValues) + { + m_Flags |= MATERIAL_IS_MANUALLY_CREATED; + } + + // Apply patches + const char *pMaterialName = GetName(); + char pFileName[MAX_PATH]; + const char *pPathID = "GAME"; + if ( !UsesUNCFileName() ) + { + Q_snprintf( pFileName, sizeof( pFileName ), "materials/%s.vmt", pMaterialName ); + } + else + { + Q_snprintf( pFileName, sizeof( pFileName ), "%s.vmt", pMaterialName ); + if ( pMaterialName[0] == '/' && pMaterialName[1] == '/' && pMaterialName[2] != '/' ) + { + // UNC, do full search + pPathID = NULL; + } + } + + KeyValues *pLoadedKeyValues = new KeyValues( "vmt" ); + if ( pLoadedKeyValues->LoadFromFile( g_pFullFileSystem, pFileName, pPathID ) ) + { + // Load succeeded, check if it's a patch file + if ( V_stricmp( pLoadedKeyValues->GetName(), "patch" ) == 0 ) + { + // it's a patch file, recursively build up patch keyvalues + KeyValues *pPatchKeyValues = new KeyValues( "vmt_patch" ); + bool bSuccess = AccumulateRecursiveVmtPatches( *pPatchKeyValues, NULL, *pLoadedKeyValues, pPathID, NULL ); + if ( bSuccess ) + { + // Apply accumulated patches to final vmt + ApplyPatchKeyValues( *m_pVMTKeyValues, *pPatchKeyValues ); + } + pPatchKeyValues->deleteThis(); + } + } + pLoadedKeyValues->deleteThis(); + + if ( g_pShaderDevice->IsUsingGraphics() ) + { + Precache(); + } +} + + +//----------------------------------------------------------------------------- +// Creates, destroys snapshots +//----------------------------------------------------------------------------- +RenderPassList_t *CMaterial::CreateRenderPassList() +{ + RenderPassList_t *pRenderPassList; + if ( IsConsole() || !MaterialSystem()->CanUseEditorMaterials() ) + { + StandardRenderStateList_t *pList = new StandardRenderStateList_t; + pRenderPassList = (RenderPassList_t*)pList->m_Snapshots; + } +#ifndef _CONSOLE + else + { + EditorRenderStateList_t *pList = new EditorRenderStateList_t; + pRenderPassList = (RenderPassList_t*)pList->m_Snapshots; + } +#endif + + int nSnapshotCount = SnapshotTypeCount(); + memset( pRenderPassList, 0, nSnapshotCount * sizeof(RenderPassList_t) ); + return pRenderPassList; +} + +void CMaterial::DestroyRenderPassList( RenderPassList_t *pPassList ) +{ + if ( !pPassList ) + return; + + int nSnapshotCount = SnapshotTypeCount(); + for( int i = 0 ; i < nSnapshotCount ; i++ ) + for( int j = 0 ; j < pPassList[i].m_nPassCount; j++ ) + { + if ( pPassList[i].m_pContextData[j] ) + { + delete pPassList[i].m_pContextData[j]; + pPassList[i].m_pContextData[j] = NULL; + } + + } + if ( IsConsole() || !MaterialSystem()->CanUseEditorMaterials() ) + { + StandardRenderStateList_t *pList = (StandardRenderStateList_t*)pPassList; + delete pList; + } +#ifndef _CONSOLE + else + { + EditorRenderStateList_t *pList = (EditorRenderStateList_t*)pPassList; + delete pList; + } +#endif +} + + +//----------------------------------------------------------------------------- +// Gets the renderstate +//----------------------------------------------------------------------------- +ShaderRenderState_t *CMaterial::GetRenderState() +{ + Precache(); + return &m_ShaderRenderState; +} + + +//----------------------------------------------------------------------------- +// Returns a dummy material variable +//----------------------------------------------------------------------------- +IMaterialVar* CMaterial::GetDummyVariable() +{ + static IMaterialVar* pDummyVar = 0; + if (!pDummyVar) + pDummyVar = IMaterialVar::Create( 0, "$dummyVar", 0 ); + + return pDummyVar; +} + + +//----------------------------------------------------------------------------- +// Are vars precached? +//----------------------------------------------------------------------------- +bool CMaterial::IsPrecachedVars( ) const +{ + return (m_Flags & MATERIAL_VARS_IS_PRECACHED) != 0; +} + + +//----------------------------------------------------------------------------- +// Are we precached? +//----------------------------------------------------------------------------- +bool CMaterial::IsPrecached( ) const +{ + return (m_Flags & MATERIAL_IS_PRECACHED) != 0; +} + + +//----------------------------------------------------------------------------- +// Cleans up shader parameters +//----------------------------------------------------------------------------- +void CMaterial::CleanUpShaderParams() +{ + if( m_pShaderParams ) + { + for (int i = 0; i < m_VarCount; ++i) + { + IMaterialVar::Destroy( m_pShaderParams[i] ); + } + + free( m_pShaderParams ); + m_pShaderParams = 0; + } + m_VarCount = 0; +} + + +//----------------------------------------------------------------------------- +// Initializes the material proxy +//----------------------------------------------------------------------------- +void CMaterial::InitializeMaterialProxy( KeyValues* pFallbackKeyValues ) +{ + IMaterialProxyFactory *pMaterialProxyFactory; + pMaterialProxyFactory = MaterialSystem()->GetMaterialProxyFactory(); + if( !pMaterialProxyFactory ) + return; + + DetermineProxyReplacements( pFallbackKeyValues ); + + if ( m_pReplacementProxy ) + { + m_ProxyInfo.AddToTail( m_pReplacementProxy ); +#ifdef PROXY_TRACK_NAMES + m_ProxyInfoNames.AddToTail( "__replacementproxy" ); +#endif + } + + // See if we've got a proxy section; obey fallbacks + KeyValues* pProxySection = pFallbackKeyValues->FindKey("Proxies"); + if ( pProxySection ) + { + // Iterate through the section + create all of the proxies + KeyValues* pProxyKey = pProxySection->GetFirstSubKey(); + + for ( ; pProxyKey; pProxyKey = pProxyKey->GetNextKey() ) + { + // Each of the proxies should themselves be databases + IMaterialProxy* pProxy = pMaterialProxyFactory->CreateProxy( pProxyKey->GetName() ); + if (!pProxy) + { + Warning( "Error: Material \"%s\" : proxy \"%s\" not found!\n", GetName(), pProxyKey->GetName() ); + continue; + } + + if (!pProxy->Init( this->GetQueueFriendlyVersion(), pProxyKey )) + { + pMaterialProxyFactory->DeleteProxy( pProxy ); + Warning( "Error: Material \"%s\" : proxy \"%s\" unable to initialize!\n", GetName(), pProxyKey->GetName() ); + } + else + { + m_ProxyInfo.AddToTail( pProxy ); +#ifdef PROXY_TRACK_NAMES + m_ProxyInfoNames.AddToTail( pProxyKey->GetName() ); +#endif + } + } + } +} + + +//----------------------------------------------------------------------------- +// Cleans up the material proxy +//----------------------------------------------------------------------------- +void CMaterial::CleanUpMaterialProxy() +{ + if ( !m_ProxyInfo.Count() ) + return; + + IMaterialProxyFactory *pMaterialProxyFactory; + pMaterialProxyFactory = MaterialSystem()->GetMaterialProxyFactory(); + if ( !pMaterialProxyFactory ) + return; + + // Clean up material proxies + for ( int i = m_ProxyInfo.Count() - 1; i >= 0; i-- ) + { + IMaterialProxy *pProxy = m_ProxyInfo[ i ]; + + pMaterialProxyFactory->DeleteProxy( pProxy ); + } + + m_ProxyInfo.RemoveAll(); +#ifdef PROXY_TRACK_NAMES + m_ProxyInfoNames.RemoveAll(); +#endif +} + + +void CMaterial::DetermineProxyReplacements( KeyValues *pFallbackKeyValues ) +{ + m_pReplacementProxy = MaterialSystem()->DetermineProxyReplacements( this, pFallbackKeyValues ); +} + + +static char const *GetVarName( KeyValues *pVar ) +{ + char const *pVarName = pVar->GetName(); + char const *pQuestion = strchr( pVarName, '?' ); + if (! pQuestion ) + return pVarName; + else + return pQuestion + 1; +} + +//----------------------------------------------------------------------------- +// Finds the index of the material var associated with a var +//----------------------------------------------------------------------------- +static int FindMaterialVar( IShader* pShader, char const* pVarName ) +{ + if ( !pShader ) + return -1; + + // Strip preceeding spaces + pVarName += strspn( pVarName, " \t" ); + + for (int i = pShader->GetNumParams(); --i >= 0; ) + { + // Makes the parser a little more lenient.. strips off bogus spaces in the var name. + const char *pParamName = pShader->GetParamName(i); + const char *pFound = Q_stristr( pVarName, pParamName ); + + // The found string had better start with the first non-whitespace character + if ( pFound != pVarName ) + continue; + + // Strip spaces at the end + int nLen = Q_strlen( pParamName ); + pFound += nLen; + while ( true ) + { + if ( !pFound[0] ) + return i; + + if ( !IsWhitespace( pFound[0] ) ) + break; + + ++pFound; + } + } + return -1; +} + + +//----------------------------------------------------------------------------- +// Creates a vector material var +//----------------------------------------------------------------------------- +int ParseVectorFromKeyValueString( KeyValues *pKeyValue, const char *pMaterialName, float vecVal[4] ) +{ + char const* pScan = pKeyValue->GetString(); + bool divideBy255 = false; + + // skip whitespace + while( IsWhitespace(*pScan) ) + { + ++pScan; + } + + if( *pScan == '{' ) + { + divideBy255 = true; + } + else + { + Assert( *pScan == '[' ); + } + + // skip the '[' + ++pScan; + int i; + for( i = 0; i < 4; i++ ) + { + // skip whitespace + while( IsWhitespace(*pScan) ) + { + ++pScan; + } + + if( IsEndline(*pScan) || *pScan == ']' || *pScan == '}' ) + { + if (*pScan != ']' && *pScan != '}') + { + Warning( "Warning in .VMT file (%s): no ']' or '}' found in vector key \"%s\".\n" + "Did you forget to surround the vector with \"s?\n", pMaterialName, pKeyValue->GetName() ); + } + + // allow for vec2's, etc. + vecVal[i] = 0.0f; + break; + } + + char* pEnd; + + vecVal[i] = strtod( pScan, &pEnd ); + if (pScan == pEnd) + { + Warning( "Error in .VMT file: error parsing vector element \"%s\" in \"%s\"\n", pKeyValue->GetName(), pMaterialName ); + return 0; + } + + pScan = pEnd; + } + + if( divideBy255 ) + { + vecVal[0] *= ( 1.0f / 255.0f ); + vecVal[1] *= ( 1.0f / 255.0f ); + vecVal[2] *= ( 1.0f / 255.0f ); + vecVal[3] *= ( 1.0f / 255.0f ); + } + + return i; +} + +static IMaterialVar* CreateVectorMaterialVarFromKeyValue( IMaterial* pMaterial, KeyValues* pKeyValue ) +{ + char const *pszName = GetVarName( pKeyValue ); + float vecVal[4]; + int nDim = ParseVectorFromKeyValueString( pKeyValue, pszName, vecVal ); + if ( nDim == 0 ) + return NULL; + + // Create the variable! + return IMaterialVar::Create( pMaterial, pszName, vecVal, nDim ); +} + + +//----------------------------------------------------------------------------- +// Creates a vector material var +//----------------------------------------------------------------------------- +static IMaterialVar* CreateMatrixMaterialVarFromKeyValue( IMaterial* pMaterial, KeyValues* pKeyValue ) +{ + char const* pScan = pKeyValue->GetString(); + char const *pszName = GetVarName( pKeyValue ); + + // Matrices can be specified one of two ways: + // [ # # # # # # # # # # # # # # # # ] + // or + // center # # scale # # rotate # translate # # + + VMatrix mat; + int count = sscanf( pScan, " [ %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f ]", + &mat.m[0][0], &mat.m[0][1], &mat.m[0][2], &mat.m[0][3], + &mat.m[1][0], &mat.m[1][1], &mat.m[1][2], &mat.m[1][3], + &mat.m[2][0], &mat.m[2][1], &mat.m[2][2], &mat.m[2][3], + &mat.m[3][0], &mat.m[3][1], &mat.m[3][2], &mat.m[3][3] ); + if (count == 16) + { + return IMaterialVar::Create( pMaterial, pszName, mat ); + } + + Vector2D scale, center; + float angle; + Vector2D translation; + count = sscanf( pScan, " center %f %f scale %f %f rotate %f translate %f %f", + ¢er.x, ¢er.y, &scale.x, &scale.y, &angle, &translation.x, &translation.y ); + if (count != 7) + return NULL; + + VMatrix temp; + MatrixBuildTranslation( mat, -center.x, -center.y, 0.0f ); + MatrixBuildScale( temp, scale.x, scale.y, 1.0f ); + MatrixMultiply( temp, mat, mat ); + MatrixBuildRotateZ( temp, angle ); + MatrixMultiply( temp, mat, mat ); + MatrixBuildTranslation( temp, center.x + translation.x, center.y + translation.y, 0.0f ); + MatrixMultiply( temp, mat, mat ); + + // Create the variable! + return IMaterialVar::Create( pMaterial, pszName, mat ); +} + + +//----------------------------------------------------------------------------- +// Creates a material var from a key value +//----------------------------------------------------------------------------- + +static IMaterialVar* CreateMaterialVarFromKeyValue( IMaterial* pMaterial, KeyValues* pKeyValue ) +{ + char const *pszName = GetVarName( pKeyValue ); + switch( pKeyValue->GetDataType() ) + { + case KeyValues::TYPE_INT: + return IMaterialVar::Create( pMaterial, pszName, pKeyValue->GetInt() ); + + case KeyValues::TYPE_FLOAT: + return IMaterialVar::Create( pMaterial, pszName, pKeyValue->GetFloat() ); + + case KeyValues::TYPE_STRING: + { + char const* pString = pKeyValue->GetString(); + if (!pString || !pString[0]) + return 0; + + // Look for matrices + IMaterialVar *pMatrixVar = CreateMatrixMaterialVarFromKeyValue( pMaterial, pKeyValue ); + if (pMatrixVar) + return pMatrixVar; + + // Look for vectors + if (!IsVector(pString)) + return IMaterialVar::Create( pMaterial, pszName, pString ); + + // Parse the string as a vector... + return CreateVectorMaterialVarFromKeyValue( pMaterial, pKeyValue ); + } + } + + return 0; +} + + +//----------------------------------------------------------------------------- +// Reads out common flags, prevents them from becoming material vars +//----------------------------------------------------------------------------- +int CMaterial::FindMaterialVarFlag( char const* pFlagName ) const +{ + // Strip preceeding spaces + while ( pFlagName[0] ) + { + if ( !IsWhitespace( pFlagName[0] ) ) + break; + + ++pFlagName; + } + + for( int i = 0; *ShaderSystem()->ShaderStateString(i); ++i ) + { + const char *pStateString = ShaderSystem()->ShaderStateString(i); + const char *pFound = Q_stristr( pFlagName, pStateString ); + + // The found string had better start with the first non-whitespace character + if ( pFound != pFlagName ) + continue; + + // Strip spaces at the end + int nLen = Q_strlen( pStateString ); + pFound += nLen; + while ( true ) + { + if ( !pFound[0] ) + return (1 << i); + + if ( !IsWhitespace( pFound[0] ) ) + break; + + ++pFound; + } + } + return 0; +} + + +//----------------------------------------------------------------------------- +// Print material flags +//----------------------------------------------------------------------------- +void CMaterial::PrintMaterialFlags( int flags, int flagsDefined ) +{ + int i; + for( i = 0; *ShaderSystem()->ShaderStateString(i); i++ ) + { + if( flags & ( 1<ShaderStateString(i) ); + } + } + Warning( "\n" ); +} + + +//----------------------------------------------------------------------------- +// Parses material flags +//----------------------------------------------------------------------------- +bool CMaterial::ParseMaterialFlag( KeyValues* pParseValue, IMaterialVar* pFlagVar, + IMaterialVar* pFlagDefinedVar, bool parsingOverrides, int& flagMask, int& overrideMask ) +{ + // See if the var is a flag... + int flagbit = FindMaterialVarFlag( GetVarName( pParseValue ) ); + if (!flagbit) + return false; + + // Allow for flag override + int testMask = parsingOverrides ? overrideMask : flagMask; + if (testMask & flagbit) + { + Warning("Error! Flag \"%s\" is multiply defined in material \"%s\"!\n", pParseValue->GetName(), GetName() ); + return true; + } + + // Make sure overrides win + if (overrideMask & flagbit) + return true; + + if (parsingOverrides) + overrideMask |= flagbit; + else + flagMask |= flagbit; + + // If so, then set the flag bit + if (pParseValue->GetInt()) + pFlagVar->SetIntValue( pFlagVar->GetIntValue() | flagbit ); + else + pFlagVar->SetIntValue( pFlagVar->GetIntValue() & (~flagbit) ); + + // Mark the flag as being defined + pFlagDefinedVar->SetIntValue( pFlagDefinedVar->GetIntValue() | flagbit ); + +/* + if( stristr( m_pDebugName, "glasswindow064a" ) ) + { + Warning( "flags\n" ); + PrintMaterialFlags( pFlagVar->GetIntValue(), pFlagDefinedVar->GetIntValue() ); + } +*/ + + return true; +} + + +ConVar mat_reduceparticles( "mat_reduceparticles", "0", FCVAR_ALLOWED_IN_COMPETITIVE ); + +bool CMaterial::ShouldSkipVar( KeyValues *pVar, bool *pWasConditional ) +{ + char const *pVarName = pVar->GetName(); + char const *pQuestion = strchr( pVarName, '?' ); + if ( ( ! pQuestion ) || (pQuestion == pVarName ) ) + { + *pWasConditional = false; // unconditional var + return false; + } + else + { + bool bShouldSkip = true; + *pWasConditional = true; + // parse the conditional part + char pszConditionName[256]; + V_strncpy( pszConditionName, pVarName, 1+pQuestion-pVarName ); + char const *pCond = pszConditionName; + bool bToggle = false; + if ( pCond[0] == '!' ) + { + pCond++; + bToggle = true; + } + + if ( ! stricmp( pCond, "lowfill" ) ) + { + bShouldSkip = !mat_reduceparticles.GetBool(); + } + else if ( ! stricmp( pCond, "hdr" ) ) + { + bShouldSkip = ( HardwareConfig()->GetHDRType() == HDR_TYPE_NONE ); + } + else if ( ! stricmp( pCond, "srgb" ) ) + { + bShouldSkip = ( !HardwareConfig()->UsesSRGBCorrectBlending() ); + } + else if ( ! stricmp( pCond, "ldr" ) ) + { + bShouldSkip = ( HardwareConfig()->GetHDRType() != HDR_TYPE_NONE ); + } + else if ( ! stricmp( pCond, "360" ) ) + { + bShouldSkip = !IsX360(); + } + else + { + Warning( "unrecognized conditional test %s in %s\n", pVarName, GetName() ); + } + + return bShouldSkip ^ bToggle; + } +} + + +//----------------------------------------------------------------------------- +// Computes the material vars for the shader +//----------------------------------------------------------------------------- +int CMaterial::ParseMaterialVars( IShader* pShader, KeyValues& keyValues, + KeyValues* pOverrideKeyValues, bool modelDefault, IMaterialVar** ppVars, int nFindContext ) +{ + IMaterialVar* pNewVar; + bool pOverride[256]; + bool bWasConditional[256]; + int overrideMask = 0; + int flagMask = 0; + + memset( ppVars, 0, 256 * sizeof(IMaterialVar*) ); + memset( pOverride, 0, sizeof( pOverride ) ); + memset( bWasConditional, 0, sizeof( bWasConditional ) ); + + // Create the flag var... + // Set model mode if we fell back from a model mode shader + int modelFlag = modelDefault ? MATERIAL_VAR_MODEL : 0; + ppVars[FLAGS] = IMaterialVar::Create( this, "$flags", modelFlag ); + ppVars[FLAGS_DEFINED] = IMaterialVar::Create( this, "$flags_defined", modelFlag ); + ppVars[FLAGS2] = IMaterialVar::Create( this, "$flags2", 0 ); + ppVars[FLAGS_DEFINED2] = IMaterialVar::Create( this, "$flags_defined2", 0 ); + + int numParams = pShader ? pShader->GetNumParams() : 0; + int varCount = numParams; + + bool parsingOverrides = (pOverrideKeyValues != 0); + KeyValues* pVar = pOverrideKeyValues ? pOverrideKeyValues->GetFirstSubKey() : keyValues.GetFirstSubKey(); + + const char *pszMatName = pVar ? pVar->GetString() : "Unknown"; + + while( pVar ) + { + bool bProcessThisOne = true; + + bool bIsConditionalVar; + + const char *pszVarName = GetVarName( pVar ); + + if ( (nFindContext == MATERIAL_FINDCONTEXT_ISONAMODEL) && pszVarName && pszVarName[0] ) + { + // Prevent ignorez models + // Should we do 'nofog' too? For now, decided not to. + if ( Q_stristr(pszVarName,"$ignorez") ) + { + Warning("Ignoring material flag '%s' on material '%s'.\n", pszVarName, pszMatName ); + goto nextVar; + } + } + + // See if the var is a flag... + if ( + ShouldSkipVar( pVar, &bIsConditionalVar ) || // should skip? + ((pVar->GetName()[0] == '%') && (g_pShaderDevice->IsUsingGraphics()) && (!MaterialSystem()->CanUseEditorMaterials() ) ) || // is an editor var? + ParseMaterialFlag( pVar, ppVars[FLAGS], ppVars[FLAGS_DEFINED], parsingOverrides, flagMask, overrideMask ) || // is a flag? + ParseMaterialFlag( pVar, ppVars[FLAGS2], ppVars[FLAGS_DEFINED2], parsingOverrides, flagMask, overrideMask ) + ) + bProcessThisOne = false; + + if ( bProcessThisOne ) + { + // See if the var is one of the shader params + int varIdx = FindMaterialVar( pShader, pszVarName ); + + // Check for multiply defined or overridden + if (varIdx >= 0) + { + if (ppVars[varIdx] && (! bIsConditionalVar ) ) + { + if ( !pOverride[varIdx] || parsingOverrides ) + { + Warning("Error! Variable \"%s\" is multiply defined in material \"%s\"!\n", pVar->GetName(), GetName() ); + } + goto nextVar; + } + } + else + { + int i; + for ( i = numParams; i < varCount; ++i) + { + Assert( ppVars[i] ); + if (!stricmp( ppVars[i]->GetName(), pVar->GetName() )) + break; + } + if (i != varCount) + { + if ( !pOverride[i] || parsingOverrides ) + { + Warning("Error! Variable \"%s\" is multiply defined in material \"%s\"!\n", pVar->GetName(), GetName() ); + } + goto nextVar; + } + } + + // Create a material var for this dudely dude; could be zero... + pNewVar = CreateMaterialVarFromKeyValue( this, pVar ); + if (!pNewVar) + goto nextVar; + + if (varIdx < 0) + { + varIdx = varCount++; + } + if ( ppVars[varIdx] ) + { + IMaterialVar::Destroy( ppVars[varIdx] ); + } + ppVars[varIdx] = pNewVar; + if (parsingOverrides) + pOverride[varIdx] = true; + bWasConditional[varIdx] = bIsConditionalVar; + + } + +nextVar: + pVar = pVar->GetNextKey(); + if (!pVar && parsingOverrides) + { + pVar = keyValues.GetFirstSubKey(); + parsingOverrides = false; + } + } + + // Create undefined vars for all the actual material vars + for (int i = 0; i < numParams; ++i) + { + if (!ppVars[i]) + ppVars[i] = IMaterialVar::Create( this, pShader->GetParamName(i) ); + } + + return varCount; +} + + +static KeyValues *CheckConditionalFakeShaderName( char const *pShaderName, char const *pSuffixName, + KeyValues *pKeyValues ) +{ + KeyValues *pFallbackSection = pKeyValues->FindKey( pSuffixName ); + if (pFallbackSection) + return pFallbackSection; + + char nameBuf[256]; + V_snprintf( nameBuf, sizeof(nameBuf), "%s_%s", pShaderName, pSuffixName ); + pFallbackSection = pKeyValues->FindKey( nameBuf ); + + if (pFallbackSection) + return pFallbackSection; + + return NULL; +} + + +static KeyValues *FindBuiltinFallbackBlock( char const *pShaderName, KeyValues *pKeyValues ) +{ + // handle "fake" shader fallbacks which are conditional upon mode. like _hdr_dx9, etc + if ( HardwareConfig()->GetDXSupportLevel() < 90 ) + { + KeyValues *pRet = CheckConditionalFakeShaderName( pShaderName,"GetDXSupportLevel() < 95 ) + { + KeyValues *pRet = CheckConditionalFakeShaderName( pShaderName,"GetDXSupportLevel() < 90 || !HardwareConfig()->SupportsPixelShaders_2_b() ) + { + KeyValues *pRet = CheckConditionalFakeShaderName( pShaderName,"GetDXSupportLevel() >= 90 && HardwareConfig()->SupportsPixelShaders_2_b() ) + { + KeyValues *pRet = CheckConditionalFakeShaderName( pShaderName,">=DX90_20b", pKeyValues ); + if ( pRet ) + return pRet; + } + if ( HardwareConfig()->GetDXSupportLevel() <= 90 ) + { + KeyValues *pRet = CheckConditionalFakeShaderName( pShaderName,"<=DX90", pKeyValues ); + if ( pRet ) + return pRet; + } + if ( HardwareConfig()->GetDXSupportLevel() >= 90 ) + { + KeyValues *pRet = CheckConditionalFakeShaderName( pShaderName,">=DX90", pKeyValues ); + if ( pRet ) + return pRet; + } + if ( HardwareConfig()->GetDXSupportLevel() > 90 ) + { + KeyValues *pRet = CheckConditionalFakeShaderName( pShaderName,">DX90", pKeyValues ); + if ( pRet ) + return pRet; + } + if ( HardwareConfig()->GetHDRType() != HDR_TYPE_NONE ) + { + KeyValues *pRet = CheckConditionalFakeShaderName( pShaderName,"hdr_dx9", pKeyValues ); + if ( pRet ) + return pRet; + pRet = CheckConditionalFakeShaderName( pShaderName,"hdr", pKeyValues ); + if ( pRet ) + return pRet; + } + else + { + KeyValues *pRet = CheckConditionalFakeShaderName( pShaderName,"ldr", pKeyValues ); + if ( pRet ) + return pRet; + } + if ( HardwareConfig()->UsesSRGBCorrectBlending() ) + { + KeyValues *pRet = CheckConditionalFakeShaderName( pShaderName,"srgb", pKeyValues ); + if ( pRet ) + return pRet; + } + if ( HardwareConfig()->GetDXSupportLevel() >= 90 ) + { + KeyValues *pRet = CheckConditionalFakeShaderName( pShaderName,"dx9", pKeyValues ); + if ( pRet ) + return pRet; + } + return NULL; +} + +inline const char *MissingShaderName() +{ + return (IsWindows() && !IsEmulatingGL()) ? "Wireframe_DX8" : "Wireframe_DX9"; +} + +//----------------------------------------------------------------------------- +// Hooks up the shader +//----------------------------------------------------------------------------- +KeyValues* CMaterial::InitializeShader( KeyValues &keyValues, KeyValues &patchKeyValues, int nFindContext ) +{ + MaterialLock_t hMaterialLock = MaterialSystem()->Lock(); + + KeyValues* pCurrentFallback = &keyValues; + KeyValues* pFallbackSection = 0; + + char szShaderName[MAX_PATH]; + char const* pShaderName = pCurrentFallback->GetName(); + if ( !pShaderName ) + { + // I'm not quite sure how this can happen, but we'll see... + Warning( "Shader not specified in material %s\nUsing wireframe instead...\n", GetName() ); + Assert( 0 ); + pShaderName = MissingShaderName(); + } + else + { + // can't pass a stable reference to the key values name around + // naive leaf functions can cause KV system to re-alloc + V_strncpy( szShaderName, pShaderName, sizeof( szShaderName ) ); + pShaderName = szShaderName; + } + + IShader* pShader; + IMaterialVar* ppVars[256]; + char pFallbackShaderNameBuf[256]; + char pFallbackMaterialNameBuf[256]; + int varCount = 0; + bool modelDefault = false; + + // Keep going until there's no more fallbacks... + while( true ) + { + // Find the shader for this material. Note that this may not be + // the actual shader we use due to fallbacks... + pShader = ShaderSystem()->FindShader( pShaderName ); + if ( !pShader ) + { + if ( g_pShaderDevice->IsUsingGraphics() ) + { + Warning( "Error: Material \"%s\" uses unknown shader \"%s\"\n", GetName(), pShaderName ); + //hushed Assert( 0 ); + } + + pShaderName = MissingShaderName(); + pShader = ShaderSystem()->FindShader( pShaderName ); + + if ( !HushAsserts() ) + { + AssertMsg( pShader, "pShader==NULL. Shader: %s", GetName() ); + } + +#ifndef DEDICATED + if ( !pShader ) + { +#ifdef LINUX + // Exit out here. We're running into issues where this material is returned in a horribly broken + // state and you wind up crashing in LockMesh() because the vertex and index buffer pointers + // are NULL. You can repro this by not dying here and showing the intro movie. This happens on + // Linux when you run from a symlink'd SteamApps directory. + Error( "Shader '%s' for material '%s' not found.\n", + pCurrentFallback->GetName() ? pCurrentFallback->GetName() : pShaderName, GetName() ); +#endif + MaterialSystem()->Unlock( hMaterialLock ); + return NULL; + } +#endif + + } + + bool bHasBuiltinFallbackBlock = false; + if ( !pFallbackSection ) + { + pFallbackSection = FindBuiltinFallbackBlock( pShaderName, &keyValues ); + if( pFallbackSection ) + { + bHasBuiltinFallbackBlock = true; + pFallbackSection->ChainKeyValue( &keyValues ); + pCurrentFallback = pFallbackSection; + } + } + + // Here we must set up all flags + material vars that the shader needs + // because it may look at them when choosing shader fallback. + varCount = ParseMaterialVars( pShader, keyValues, pFallbackSection, modelDefault, ppVars, nFindContext ); + + if ( !pShader ) + break; + + // Make sure we set default values before the fallback is looked for + ShaderSystem()->InitShaderParameters( pShader, ppVars, GetName() ); + + // Now that the material vars are parsed, see if there's a fallback + // But only if we're not in the tools +/* + if (!g_pShaderAPI->IsUsingGraphics()) + break; +*/ + + // Check for a fallback; if not, we're done + pShaderName = pShader->GetFallbackShader( ppVars ); + if (!pShaderName) + { + break; + } + // Copy off the shader name, as it may be in a materialvar in the shader + // because we're about to delete all materialvars + Q_strncpy( pFallbackShaderNameBuf, pShaderName, 256 ); + pShaderName = pFallbackShaderNameBuf; + + // Remember the model flag if we're on dx7 or higher... + if (HardwareConfig()->SupportsVertexAndPixelShaders()) + { + modelDefault = ( ppVars[FLAGS]->GetIntValue() & MATERIAL_VAR_MODEL ) != 0; + } + + // Try to get the section associated with the fallback shader + // Then chain it to the base data so it can override the + // values if it wants to + if( !bHasBuiltinFallbackBlock ) + { + pFallbackSection = keyValues.FindKey( pShaderName ); + if (pFallbackSection) + { + pFallbackSection->ChainKeyValue( &keyValues ); + pCurrentFallback = pFallbackSection; + } + } + + // Now, blow away all of the material vars + try again... + for (int i = 0; i < varCount; ++i) + { + Assert( ppVars[i] ); + IMaterialVar::Destroy( ppVars[i] ); + } + + // Check the KeyValues for '$fallbackmaterial' + // Note we have to do this *after* we chain the keyvalues + // based on the fallback shader since the names of the fallback material + // must lie within the shader-specific block usually. + const char *pFallbackMaterial = pCurrentFallback->GetString( "$fallbackmaterial" ); + if ( pFallbackMaterial[0] ) + { + // Don't fallback to ourselves + if ( Q_stricmp( GetName(), pFallbackMaterial ) ) + { + // Gotta copy it off; clearing the keyvalues will blow the string away + Q_strncpy( pFallbackMaterialNameBuf, pFallbackMaterial, 256 ); + keyValues.Clear(); + if( !LoadVMTFile( keyValues, patchKeyValues, pFallbackMaterialNameBuf, UsesUNCFileName(), NULL ) ) + { + Warning( "CMaterial::PrecacheVars: error loading vmt file %s for %s\n", pFallbackMaterialNameBuf, GetName() ); + keyValues = *(((CMaterial *)g_pErrorMaterial)->m_pVMTKeyValues); + } + } + else + { + Warning( "CMaterial::PrecacheVars: fallback material for vmt file %s is itself!\n", GetName() ); + keyValues = *(((CMaterial *)g_pErrorMaterial)->m_pVMTKeyValues); + } + pCurrentFallback = &keyValues; + pFallbackSection = NULL; + + // I'm not quite sure how this can happen, but we'll see... + pShaderName = pCurrentFallback->GetName(); + if (!pShaderName) + { + Warning("Shader not specified in material %s (fallback %s)\nUsing wireframe instead...\n", GetName(), pFallbackMaterialNameBuf ); + pShaderName = MissingShaderName(); + } + } + } + + // Store off the shader + m_pShader = pShader; + + // Store off the material vars + flags + m_VarCount = varCount; + m_pShaderParams = (IMaterialVar**)malloc( varCount * sizeof(IMaterialVar*) ); + memcpy( m_pShaderParams, ppVars, varCount * sizeof(IMaterialVar*) ); + +#ifdef _DEBUG + for (int i = 0; i < varCount; ++i) + { + Assert( ppVars[i] ); + } +#endif + + MaterialSystem()->Unlock( hMaterialLock ); + return pCurrentFallback; +} + +//----------------------------------------------------------------------------- +// Gets the texturemap size +//----------------------------------------------------------------------------- + +void CMaterial::PrecacheMappingDimensions( ) +{ + // Cache mapping width and mapping height + if (!m_representativeTexture) + { +#ifdef PARANOID + Warning( "No representative texture on material: \"%s\"\n", GetName() ); +#endif + m_MappingWidth = 64; + m_MappingHeight = 64; + } + else + { + m_MappingWidth = m_representativeTexture->GetMappingWidth(); + m_MappingHeight = m_representativeTexture->GetMappingHeight(); + } +} + + +//----------------------------------------------------------------------------- +// Initialize the state snapshot +//----------------------------------------------------------------------------- +bool CMaterial::InitializeStateSnapshots() +{ + if (IsPrecached()) + { + if ( MaterialSystem()->GetCurrentMaterial() == this) + { + g_pShaderAPI->FlushBufferedPrimitives(); + } + + // Default state + CleanUpStateSnapshots(); + + if ( m_pShader && !ShaderSystem()->InitRenderState( m_pShader, m_VarCount, m_pShaderParams, &m_ShaderRenderState, GetName() )) + { + m_Flags &= ~MATERIAL_VALID_RENDERSTATE; + return false; + } + + m_Flags |= MATERIAL_VALID_RENDERSTATE; + } + + return true; +} + +void CMaterial::CleanUpStateSnapshots() +{ + if (IsValidRenderState()) + { + ShaderSystem()->CleanupRenderState(&m_ShaderRenderState); + // -- THIS CANNOT BE HERE: m_Flags &= ~MATERIAL_VALID_RENDERSTATE; + // -- because it will cause a crash when main thread asks for material + // -- sort group it can temporarily see material in invalid render state + // -- and crash in DecalSurfaceAdd(msurface2_t*, int) + } +} + + +//----------------------------------------------------------------------------- +// This sets up a debugging/error shader... +//----------------------------------------------------------------------------- +void CMaterial::SetupErrorShader() +{ + // Preserve the model flags + int flags = 0; + if ( m_pShaderParams && m_pShaderParams[FLAGS] ) + { + flags = (m_pShaderParams[FLAGS]->GetIntValue() & MATERIAL_VAR_MODEL); + } + + CleanUpShaderParams(); + CleanUpMaterialProxy(); + + // We had a failure; replace it with a valid shader... + + m_pShader = ShaderSystem()->FindShader( MissingShaderName() ); + Assert( m_pShader ); + + // Create undefined vars for all the actual material vars + m_VarCount = m_pShader->GetNumParams(); + m_pShaderParams = (IMaterialVar**)malloc( m_VarCount * sizeof(IMaterialVar*) ); + + for (int i = 0; i < m_VarCount; ++i) + { + m_pShaderParams[i] = IMaterialVar::Create( this, m_pShader->GetParamName(i) ); + } + + // Store the model flags + SetMaterialVarFlags( flags, true ); + + // Set the default values + ShaderSystem()->InitShaderParameters( m_pShader, m_pShaderParams, "Error" ); + + // Invokes the SHADER_INIT block in the various shaders, + ShaderSystem()->InitShaderInstance( m_pShader, m_pShaderParams, "Error", GetTextureGroupName() ); + +#ifdef DBGFLAG_ASSERT + bool ok = +#endif + InitializeStateSnapshots(); + + m_QueueFriendlyVersion.UpdateToRealTime(); + + Assert(ok); +} + + +//----------------------------------------------------------------------------- +// This computes the state snapshots for this material +//----------------------------------------------------------------------------- +void CMaterial::RecomputeStateSnapshots() +{ + CMatCallQueue *pCallQueue = MaterialSystem()->GetRenderCallQueue(); + if ( pCallQueue ) + { + pCallQueue->QueueCall( this, &CMaterial::RecomputeStateSnapshots ); + return; + } + + bool ok = InitializeStateSnapshots(); + + // compute the state snapshots + if (!ok) + { + SetupErrorShader(); + } +} + + +//----------------------------------------------------------------------------- +// Are we valid +//----------------------------------------------------------------------------- +inline bool CMaterial::IsValidRenderState() const +{ + return (m_Flags & MATERIAL_VALID_RENDERSTATE) != 0; +} + + +//----------------------------------------------------------------------------- +// Gets/sets material var flags +//----------------------------------------------------------------------------- +inline int CMaterial::GetMaterialVarFlags() const +{ + if ( m_pShaderParams && m_pShaderParams[FLAGS] ) + { + return m_pShaderParams[FLAGS]->GetIntValueFast(); + } + else + { + return 0; + } +} + +inline void CMaterial::SetMaterialVarFlags( int flags, bool on ) +{ + if ( !m_pShaderParams ) + { + Assert( 0 ); // are we hanging onto a material that has been cleaned up or isn't ready? + return; + } + + if (on) + { + m_pShaderParams[FLAGS]->SetIntValue( GetMaterialVarFlags() | flags ); + } + else + { + m_pShaderParams[FLAGS]->SetIntValue( GetMaterialVarFlags() & (~flags) ); + } + + // Mark it as being defined... + m_pShaderParams[FLAGS_DEFINED]->SetIntValue( m_pShaderParams[FLAGS_DEFINED]->GetIntValueFast() | flags ); +} + +inline int CMaterial::GetMaterialVarFlags2() const +{ + if ( m_pShaderParams && m_VarCount > FLAGS2 && m_pShaderParams[FLAGS2] ) + { + return m_pShaderParams[FLAGS2]->GetIntValueFast(); + } + else + { + return 0; + } +} + +inline void CMaterial::SetMaterialVarFlags2( int flags, bool on ) +{ + if ( m_pShaderParams && m_VarCount > FLAGS2 && m_pShaderParams[FLAGS2] ) + { + if (on) + m_pShaderParams[FLAGS2]->SetIntValue( GetMaterialVarFlags2() | flags ); + else + m_pShaderParams[FLAGS2]->SetIntValue( GetMaterialVarFlags2() & (~flags) ); + } + + if ( m_pShaderParams && m_VarCount > FLAGS_DEFINED2 && m_pShaderParams[FLAGS_DEFINED2] ) + { + // Mark it as being defined... + m_pShaderParams[FLAGS_DEFINED2]->SetIntValue( + m_pShaderParams[FLAGS_DEFINED2]->GetIntValueFast() | flags ); + } +} + + +//----------------------------------------------------------------------------- +// Gets the morph format +//----------------------------------------------------------------------------- +MorphFormat_t CMaterial::GetMorphFormat() const +{ + const_cast(this)->Precache(); + Assert( IsValidRenderState() ); + return m_ShaderRenderState.m_MorphFormat; +} + +//----------------------------------------------------------------------------- +// Gets the vertex format +//----------------------------------------------------------------------------- +VertexFormat_t CMaterial::GetVertexFormat() const +{ + Assert( IsValidRenderState() ); + return m_ShaderRenderState.m_VertexFormat; +} + +VertexFormat_t CMaterial::GetVertexUsage() const +{ + Assert( IsValidRenderState() ); + return m_ShaderRenderState.m_VertexUsage; +} + +bool CMaterial::PerformDebugTrace() const +{ + return IsValidRenderState() && ((GetMaterialVarFlags() & MATERIAL_VAR_DEBUG ) != 0); +} + + +//----------------------------------------------------------------------------- +// Are we suppressed? +//----------------------------------------------------------------------------- +bool CMaterial::IsSuppressed() const +{ + if ( !IsValidRenderState() ) + return true; + + return ((GetMaterialVarFlags() & MATERIAL_VAR_NO_DRAW) != 0); +} + +void CMaterial::ToggleSuppression() +{ + if (IsValidRenderState()) + { + if ((GetMaterialVarFlags() & MATERIAL_VAR_NO_DEBUG_OVERRIDE) != 0) + return; + + SetMaterialVarFlags( MATERIAL_VAR_NO_DRAW, + (GetMaterialVarFlags() & MATERIAL_VAR_NO_DRAW) == 0 ); + } +} + +void CMaterial::ToggleDebugTrace() +{ + if (IsValidRenderState()) + { + SetMaterialVarFlags( MATERIAL_VAR_DEBUG, + (GetMaterialVarFlags() & MATERIAL_VAR_DEBUG) == 0 ); + } +} + +//----------------------------------------------------------------------------- +// Can we override this material in debug? +//----------------------------------------------------------------------------- + +bool CMaterial::NoDebugOverride() const +{ + return IsValidRenderState() && (GetMaterialVarFlags() & MATERIAL_VAR_NO_DEBUG_OVERRIDE) != 0; +} + + +//----------------------------------------------------------------------------- +// Material Var flags +//----------------------------------------------------------------------------- +void CMaterial::SetMaterialVarFlag( MaterialVarFlags_t flag, bool on ) +{ + CMatCallQueue *pCallQueue = MaterialSystem()->GetRenderCallQueue(); + if ( pCallQueue ) + { + pCallQueue->QueueCall( this, &CMaterial::SetMaterialVarFlag, flag, on ); + return; + } + + bool oldOn = (GetMaterialVarFlags( ) & flag) != 0; + if (oldOn != on) + { + SetMaterialVarFlags( flag, on ); + + // This is going to be called from client code; recompute snapshots! + RecomputeStateSnapshots(); + } +} + +bool CMaterial::GetMaterialVarFlag( MaterialVarFlags_t flag ) const +{ + return (GetMaterialVarFlags() & flag) != 0; +} + + +//----------------------------------------------------------------------------- +// Do we use the env_cubemap entity to get cubemaps from the level? +//----------------------------------------------------------------------------- +bool CMaterial::UsesEnvCubemap( void ) +{ + Precache(); + + if( !m_pShader ) + { + if ( !HushAsserts() ) + { + AssertMsg( m_pShader, "m_pShader==NULL. Shader: %s", GetName() ); + } + return false; + } + + Assert( m_pShaderParams ); + return IsFlag2Set( m_pShaderParams, MATERIAL_VAR2_USES_ENV_CUBEMAP ); +} + + +//----------------------------------------------------------------------------- +// Do we need a tangent space at the vertex level? +//----------------------------------------------------------------------------- +bool CMaterial::NeedsTangentSpace( void ) +{ + Precache(); + + if( !m_pShader ) + { + if ( !HushAsserts() ) + { + AssertMsg( m_pShader, "m_pShader==NULL. Shader: %s", GetName() ); + } + return false; + } + + Assert( m_pShaderParams ); + return IsFlag2Set( m_pShaderParams, MATERIAL_VAR2_NEEDS_TANGENT_SPACES ); +} + +bool CMaterial::NeedsPowerOfTwoFrameBufferTexture( bool bCheckSpecificToThisFrame ) +{ + PrecacheVars(); + if( !m_pShader ) + { + if ( !HushAsserts() ) + { + AssertMsg( m_pShader, "m_pShader==NULL. Shader: %s", GetName() ); + } + return false; + } + + Assert( m_pShaderParams ); + return m_pShader->NeedsPowerOfTwoFrameBufferTexture( m_pShaderParams, bCheckSpecificToThisFrame ); +} + +bool CMaterial::NeedsFullFrameBufferTexture( bool bCheckSpecificToThisFrame ) +{ + PrecacheVars(); + if( !m_pShader ) + { + if ( !HushAsserts() ) + { + AssertMsg( m_pShader, "m_pShader==NULL. Shader: %s", GetName() ); + } + return false; + } + + Assert( m_pShaderParams ); + return m_pShader->NeedsFullFrameBufferTexture( m_pShaderParams, bCheckSpecificToThisFrame ); +} + +// GR - Is lightmap alpha needed? +bool CMaterial::NeedsLightmapBlendAlpha( void ) +{ + Precache(); + return (GetMaterialVarFlags2() & MATERIAL_VAR2_BLEND_WITH_LIGHTMAP_ALPHA ) != 0; +} + +//----------------------------------------------------------------------------- +// Do we need software skinning? +//----------------------------------------------------------------------------- +bool CMaterial::NeedsSoftwareSkinning( void ) +{ + Precache(); + Assert( m_pShader ); + if( !m_pShader ) + { + return false; + } + + Assert( m_pShaderParams ); + return IsFlagSet( m_pShaderParams, MATERIAL_VAR_NEEDS_SOFTWARE_SKINNING ); +} + + +//----------------------------------------------------------------------------- +// Do we need software lighting? +//----------------------------------------------------------------------------- +bool CMaterial::NeedsSoftwareLighting( void ) +{ + Precache(); + Assert( m_pShader ); + if( !m_pShader ) + { + return false; + } + Assert( m_pShaderParams ); + return IsFlag2Set( m_pShaderParams, MATERIAL_VAR2_NEEDS_SOFTWARE_LIGHTING ); +} + +//----------------------------------------------------------------------------- +// Alpha/color modulation +//----------------------------------------------------------------------------- +void CMaterial::AlphaModulate( float alpha ) +{ + Precache(); + if ( m_VarCount > ALPHA ) + m_pShaderParams[ALPHA]->SetFloatValue(alpha); +} + +void CMaterial::ColorModulate( float r, float g, float b ) +{ + Precache(); + if ( m_VarCount > COLOR ) + m_pShaderParams[COLOR]->SetVecValue( r, g, b ); +} + +float CMaterial::GetAlphaModulation() +{ + Precache(); + if ( m_VarCount > ALPHA ) + return m_pShaderParams[ALPHA]->GetFloatValue(); + return 0.0f; +} + +void CMaterial::GetColorModulation( float *r, float *g, float *b ) +{ + Precache(); + + float pColor[3] = { 0.0f, 0.0f, 0.0f }; + if ( m_VarCount > COLOR ) + m_pShaderParams[COLOR]->GetVecValue( pColor, 3 ); + *r = pColor[0]; + *g = pColor[1]; + *b = pColor[2]; +} + + +//----------------------------------------------------------------------------- +// Do we use fog? +//----------------------------------------------------------------------------- +bool CMaterial::UseFog() const +{ + Assert( m_VarCount > 0 ); + return IsValidRenderState() && ((GetMaterialVarFlags() & MATERIAL_VAR_NOFOG) == 0); +} + + +//----------------------------------------------------------------------------- +// diffuse bump? +//----------------------------------------------------------------------------- +bool CMaterial::IsUsingDiffuseBumpedLighting() const +{ + return (GetMaterialVarFlags2() & MATERIAL_VAR2_LIGHTING_BUMPED_LIGHTMAP ) != 0; +} + + +//----------------------------------------------------------------------------- +// lightmap? +//----------------------------------------------------------------------------- +bool CMaterial::IsUsingLightmap() const +{ + return (GetMaterialVarFlags2() & MATERIAL_VAR2_LIGHTING_LIGHTMAP ) != 0; +} + +bool CMaterial::IsManuallyCreated() const +{ + return (m_Flags & MATERIAL_IS_MANUALLY_CREATED) != 0; +} + +bool CMaterial::UsesUNCFileName() const +{ + return (m_Flags & MATERIAL_USES_UNC_FILENAME) != 0; +} + + +void CMaterial::DecideShouldReloadFromWhitelist( IFileList *pFilesToReload ) +{ + m_bShouldReloadFromWhitelist = false; + if ( IsManuallyCreated() || !IsPrecached() ) + return; + + // Materials loaded with an absolute pathname are usually debug materials. + if ( V_IsAbsolutePath( GetName() ) ) + return; + + char vmtFilename[MAX_PATH]; + V_ComposeFileName( "materials", GetName(), vmtFilename, sizeof( vmtFilename ) ); + V_strncat( vmtFilename, ".vmt", sizeof( vmtFilename ) ); + + // Check if either this file or any of the files it included need to be reloaded. + bool bShouldReload = pFilesToReload->IsFileInList( vmtFilename ); + if ( !bShouldReload ) + { + for ( int i=0; i < m_VMTIncludes.Count(); i++ ) + { + g_pFullFileSystem->String( m_VMTIncludes[i], vmtFilename, sizeof( vmtFilename ) ); + if ( pFilesToReload->IsFileInList( vmtFilename ) ) + { + bShouldReload = true; + break; + } + } + } + + m_bShouldReloadFromWhitelist = bShouldReload; +} + +void CMaterial::ReloadFromWhitelistIfMarked() +{ + if ( !m_bShouldReloadFromWhitelist ) + return; + + #ifdef PURE_SERVER_DEBUG_SPEW + { + char vmtFilename[MAX_PATH]; + V_ComposeFileName( "materials", GetName(), vmtFilename, sizeof( vmtFilename ) ); + V_strncat( vmtFilename, ".vmt", sizeof( vmtFilename ) ); + Msg( "Reloading %s due to pure server whitelist change\n", GetName() ); + } + #endif + + Uncache(); + Precache(); + if ( !GetShader() ) + { + // We can get in here if we previously loaded this material off disk and now the whitelist + // says to get it out of Steam but it's not in Steam. So just setup a wireframe thingy + // to draw the material with. + m_Flags |= MATERIAL_IS_PRECACHED | MATERIAL_VARS_IS_PRECACHED; + #if DEBUG + if (IsOSX()) + { + printf("\n ##### CMaterial::ReloadFromWhitelistIfMarked: GetShader failed on %s, calling SetupErrorShader", m_pDebugName ); + } + #endif + + SetupErrorShader(); + } +} + +bool CMaterial::WasReloadedFromWhitelist() +{ + return m_bShouldReloadFromWhitelist; +} + +//----------------------------------------------------------------------------- +// Loads the material vars +//----------------------------------------------------------------------------- +bool CMaterial::PrecacheVars( KeyValues *pVMTKeyValues, KeyValues *pPatchKeyValues, CUtlVector *pIncludes, int nFindContext ) +{ + // We should get both parameters or neither + Assert( ( pVMTKeyValues == NULL ) ? ( pPatchKeyValues == NULL ) : ( pPatchKeyValues != NULL ) ); + + // Don't bother if we're already precached + if( IsPrecachedVars() ) + return true; + + if ( pIncludes ) + m_VMTIncludes = *pIncludes; + else + m_VMTIncludes.Purge(); + + MaterialLock_t hMaterialLock = MaterialSystem()->Lock(); + + bool bOk = false; + bool bError = false; + KeyValues *vmtKeyValues = NULL; + KeyValues *patchKeyValues = NULL; + if ( m_pVMTKeyValues ) + { + // Use the procedural KeyValues + vmtKeyValues = m_pVMTKeyValues; + patchKeyValues = new KeyValues( "vmt_patches" ); + + // The caller should not be passing in KeyValues if we have procedural ones + Assert( ( pVMTKeyValues == NULL ) && ( pPatchKeyValues == NULL ) ); + } + else if ( pVMTKeyValues ) + { + // Use the passed-in (already-loaded) KeyValues + vmtKeyValues = pVMTKeyValues; + patchKeyValues = pPatchKeyValues; + } + else + { + m_VMTIncludes.Purge(); + + // load data from the vmt file + vmtKeyValues = new KeyValues( "vmt" ); + patchKeyValues = new KeyValues( "vmt_patches" ); + if( !LoadVMTFile( *vmtKeyValues, *patchKeyValues, GetName(), UsesUNCFileName(), &m_VMTIncludes ) ) + { + Warning( "CMaterial::PrecacheVars: error loading vmt file for %s\n", GetName() ); + bError = true; + } + } + + if ( ! bError ) + { + // Needed to prevent re-entrancy + m_Flags |= MATERIAL_VARS_IS_PRECACHED; + + // Create shader and the material vars... + KeyValues *pFallbackKeyValues = InitializeShader( *vmtKeyValues, *patchKeyValues, nFindContext ); + if ( pFallbackKeyValues ) + { + // Gotta initialize the proxies too, using the fallback proxies + InitializeMaterialProxy(pFallbackKeyValues); + bOk = true; + } + } + + // Clean up + if ( ( vmtKeyValues != m_pVMTKeyValues ) && ( vmtKeyValues != pVMTKeyValues ) ) + { + vmtKeyValues->deleteThis(); + } + if ( patchKeyValues != pPatchKeyValues ) + { + patchKeyValues->deleteThis(); + } + + MaterialSystem()->Unlock( hMaterialLock ); + + return bOk; +} + + +//----------------------------------------------------------------------------- +// Loads the material info from the VMT file +//----------------------------------------------------------------------------- +void CMaterial::Precache() +{ + // Don't bother if we're already precached + if ( IsPrecached() ) + return; + + // load data from the vmt file + if ( !PrecacheVars() ) + return; + + MaterialLock_t hMaterialLock = MaterialSystem()->Lock(); + + m_Flags |= MATERIAL_IS_PRECACHED; + + // Invokes the SHADER_INIT block in the various shaders, + if ( m_pShader ) + { + ShaderSystem()->InitShaderInstance( m_pShader, m_pShaderParams, GetName(), GetTextureGroupName() ); + } + + // compute the state snapshots + RecomputeStateSnapshots(); + + FindRepresentativeTexture(); + + // Reads in the texture width and height from the material var + PrecacheMappingDimensions(); + + Assert( IsValidRenderState() ); + + if( m_pShaderParams ) + m_QueueFriendlyVersion.UpdateToRealTime(); + + MaterialSystem()->Unlock( hMaterialLock ); +} + + +//----------------------------------------------------------------------------- +// Unloads the material data from memory +//----------------------------------------------------------------------------- +void CMaterial::Uncache( bool bPreserveVars ) +{ + MaterialLock_t hMaterialLock = MaterialSystem()->Lock(); + + // Don't bother if we're not cached + if ( IsPrecached() ) + { + // Clean up the state snapshots + CleanUpStateSnapshots(); + m_Flags &= ~MATERIAL_VALID_RENDERSTATE; + m_Flags &= ~MATERIAL_IS_PRECACHED; + } + + if ( !bPreserveVars ) + { + if ( IsPrecachedVars() ) + { + // Clean up the shader + params + CleanUpShaderParams(); + m_pShader = 0; + + // Clean up the material proxy + CleanUpMaterialProxy(); + + m_Flags &= ~MATERIAL_VARS_IS_PRECACHED; + } + } + + MaterialSystem()->Unlock( hMaterialLock ); + + // Whether we just now did it, or we were already unloaded, + // notify the pure system that the material is unloaded, + // so it doesn't caue us to fail sv_pure checks + if ( ( m_Flags & ( MATERIAL_VARS_IS_PRECACHED | MATERIAL_IS_MANUALLY_CREATED | MATERIAL_USES_UNC_FILENAME ) ) == 0 ) + { + char szName[ MAX_PATH ]; + V_sprintf_safe( szName, "materials/%s.vmt", GetName() ); + g_pFullFileSystem->NotifyFileUnloaded( szName, "GAME" ); + } +} + +//----------------------------------------------------------------------------- +// reload all textures used by this materals +//----------------------------------------------------------------------------- +void CMaterial::ReloadTextures( void ) +{ + Precache(); + int i; + int nParams = ShaderParamCount(); + IMaterialVar **ppVars = GetShaderParams(); + for( i = 0; i < nParams; i++ ) + { + if( ppVars[i] ) + { + if( ppVars[i]->IsTexture() ) + { + ITextureInternal *pTexture = ( ITextureInternal * )ppVars[i]->GetTextureValue(); + if( !IsTextureInternalEnvCubemap( pTexture ) ) + { + pTexture->Download(); + } + } + } + } +} + + +//----------------------------------------------------------------------------- +// Meant to be used with materials created using CreateMaterial +// It updates the materials to reflect the current values stored in the material vars +//----------------------------------------------------------------------------- +void CMaterial::Refresh() +{ + if ( g_pShaderDevice->IsUsingGraphics() ) + { + Uncache(); + Precache(); + } +} + +void CMaterial::RefreshPreservingMaterialVars() +{ + if ( g_pShaderDevice->IsUsingGraphics() ) + { + Uncache( true ); + Precache(); + } +} + +//----------------------------------------------------------------------------- +// Gets the material name +//----------------------------------------------------------------------------- +char const* CMaterial::GetName() const +{ + return m_Name.String(); +} + + +char const* CMaterial::GetTextureGroupName() const +{ + return m_TextureGroupName.String(); +} + + +//----------------------------------------------------------------------------- +// Material dimensions +//----------------------------------------------------------------------------- +int CMaterial::GetMappingWidth( ) +{ + Precache(); + return m_MappingWidth; +} + +int CMaterial::GetMappingHeight( ) +{ + Precache(); + return m_MappingHeight; +} + + +//----------------------------------------------------------------------------- +// Animated material info +//----------------------------------------------------------------------------- + +int CMaterial::GetNumAnimationFrames( ) +{ + Precache(); + if( m_representativeTexture ) + { + return m_representativeTexture->GetNumAnimationFrames(); + } + else + { +#ifndef POSIX + Warning( "CMaterial::GetNumAnimationFrames:\nno representative texture for material %s\n", GetName() ); +#endif + return 1; + } +} + +//----------------------------------------------------------------------------- +// Purpose: +//----------------------------------------------------------------------------- +void CMaterial::GetMaterialOffset( float *pOffset ) +{ + // Identity. + pOffset[0] = 0.0f; + pOffset[1] = 0.0f; +} + +//----------------------------------------------------------------------------- +// Purpose: +//----------------------------------------------------------------------------- +void CMaterial::GetMaterialScale( float *pScale ) +{ + // Identity. + pScale[0] = 1.0f; + pScale[1] = 1.0f; +} + +//----------------------------------------------------------------------------- +// Reference count +//----------------------------------------------------------------------------- +void CMaterial::IncrementReferenceCount( ) +{ + ++m_RefCount; +} + +void CMaterial::DecrementReferenceCount( ) +{ + --m_RefCount; +} + +int CMaterial::GetReferenceCount( ) const +{ + return m_RefCount; +} + +//----------------------------------------------------------------------------- +// Sets the shader associated with the material +//----------------------------------------------------------------------------- +void CMaterial::SetShader( const char *pShaderName ) +{ + Assert( pShaderName ); + + int i; + IShader* pShader; + IMaterialVar* ppVars[256]; + int iVarCount = 0; + + // Clean up existing state + Uncache(); + + // Keep going until there's no more fallbacks... + while( true ) + { + // Find the shader for this material. Note that this may not be + // the actual shader we use due to fallbacks... + pShader = ShaderSystem()->FindShader( pShaderName ); + if (!pShader) + { + // Couldn't find the shader we wanted to use; it's not defined... + Warning( "SetShader: Couldn't find shader %s for material %s!\n", pShaderName, GetName() ); + pShaderName = MissingShaderName(); + pShader = ShaderSystem()->FindShader( pShaderName ); + Assert( pShader ); + } + + // Create undefined vars for all the actual material vars + iVarCount = pShader->GetNumParams(); + for (i = 0; i < iVarCount; ++i) + { + ppVars[i] = IMaterialVar::Create( this, pShader->GetParamName(i) ); + } + + // Make sure we set default values before the fallback is looked for + ShaderSystem()->InitShaderParameters( pShader, ppVars, pShaderName ); + + // Now that the material vars are parsed, see if there's a fallback + // But only if we're not in the tools + if (!g_pShaderDevice->IsUsingGraphics()) + break; + + // Check for a fallback; if not, we're done + pShaderName = pShader->GetFallbackShader( ppVars ); + if (!pShaderName) + break; + + // Now, blow away all of the material vars + try again... + for (i = 0; i < iVarCount; ++i) + { + Assert( ppVars[i] ); + IMaterialVar::Destroy( ppVars[i] ); + } + } + + // Store off the shader + m_pShader = pShader; + + // Store off the material vars + flags + m_VarCount = iVarCount; + m_pShaderParams = (IMaterialVar**)malloc( iVarCount * sizeof(IMaterialVar*) ); + memcpy( m_pShaderParams, ppVars, iVarCount * sizeof(IMaterialVar*) ); + + // Invokes the SHADER_INIT block in the various shaders, + ShaderSystem()->InitShaderInstance( m_pShader, m_pShaderParams, GetName(), GetTextureGroupName() ); + + // Precache our initial state... + // NOTE: What happens here for textures??? + + // Pretend that we precached our material vars; we certainly don't have any! + m_Flags |= MATERIAL_VARS_IS_PRECACHED; + + // NOTE: The caller has to call 'Refresh' for the shader to be ready... +} + +const char *CMaterial::GetShaderName() const +{ + const_cast< CMaterial* >( this )->PrecacheVars(); + return m_pShader ? m_pShader->GetName() : "shader_error"; +} + + +//----------------------------------------------------------------------------- +// Enumeration ID +//----------------------------------------------------------------------------- +int CMaterial::GetEnumerationID( ) const +{ + return m_iEnumerationID; +} + +void CMaterial::SetEnumerationID( int id ) +{ + m_iEnumerationID = id; +} + +//----------------------------------------------------------------------------- +// Preview image +//----------------------------------------------------------------------------- +char const* CMaterial::GetPreviewImageName( void ) +{ + if ( IsConsole() ) + { + // not supporting + return NULL; + } + + PrecacheVars(); + + bool found; + IMaterialVar *pRepresentativeTextureVar; + + FindVar( "%noToolTexture", &found, false ); + if (found) + return NULL; + + pRepresentativeTextureVar = FindVar( "%toolTexture", &found, false ); + if( found ) + { + if (pRepresentativeTextureVar->GetType() == MATERIAL_VAR_TYPE_STRING ) + return pRepresentativeTextureVar->GetStringValue(); + if (pRepresentativeTextureVar->GetType() == MATERIAL_VAR_TYPE_TEXTURE ) + return pRepresentativeTextureVar->GetTextureValue()->GetName(); + } + pRepresentativeTextureVar = FindVar( "$baseTexture", &found, false ); + if( found ) + { + if (pRepresentativeTextureVar->GetType() == MATERIAL_VAR_TYPE_STRING ) + return pRepresentativeTextureVar->GetStringValue(); + if (pRepresentativeTextureVar->GetType() == MATERIAL_VAR_TYPE_TEXTURE ) + return pRepresentativeTextureVar->GetTextureValue()->GetName(); + } + return GetName(); +} + +char const* CMaterial::GetPreviewImageFileName( void ) const +{ + char const* pName = const_cast(this)->GetPreviewImageName(); + if( !pName ) + return NULL; + + static char vtfFilename[MATERIAL_MAX_PATH]; + if( Q_strlen( pName ) >= MATERIAL_MAX_PATH - 5 ) + { + Warning( "MATERIAL_MAX_PATH to short for %s.vtf\n", pName ); + return NULL; + } + + if ( !UsesUNCFileName() ) + { + Q_snprintf( vtfFilename, sizeof( vtfFilename ), "materials/%s.vtf", pName ); + } + else + { + Q_snprintf( vtfFilename, sizeof( vtfFilename ), "%s.vtf", pName ); + } + + return vtfFilename; +} + +PreviewImageRetVal_t CMaterial::GetPreviewImageProperties( int *width, int *height, + ImageFormat *imageFormat, bool* isTranslucent ) const +{ + char const* pFileName = GetPreviewImageFileName(); + if ( IsX360() || !pFileName ) + { + *width = *height = 0; + *imageFormat = IMAGE_FORMAT_RGBA8888; + *isTranslucent = false; + return MATERIAL_NO_PREVIEW_IMAGE; + } + + int nHeaderSize = VTFFileHeaderSize( VTF_MAJOR_VERSION ); + unsigned char *pMem = (unsigned char *)stackalloc( nHeaderSize ); + CUtlBuffer buf( pMem, nHeaderSize ); + if( !g_pFullFileSystem->ReadFile( pFileName, NULL, buf, nHeaderSize ) ) + { + Warning( "\"%s\" - \"%s\": cached version doesn't exist\n", GetName(), pFileName ); + return MATERIAL_PREVIEW_IMAGE_BAD; + } + + IVTFTexture *pVTFTexture = CreateVTFTexture(); + if (!pVTFTexture->Unserialize( buf, true )) + { + Warning( "Error reading material \"%s\"\n", pFileName ); + DestroyVTFTexture( pVTFTexture ); + return MATERIAL_PREVIEW_IMAGE_BAD; + } + + *width = pVTFTexture->Width(); + *height = pVTFTexture->Height(); + *imageFormat = pVTFTexture->Format(); + *isTranslucent = (pVTFTexture->Flags() & (TEXTUREFLAGS_ONEBITALPHA | TEXTUREFLAGS_EIGHTBITALPHA)) != 0; + DestroyVTFTexture( pVTFTexture ); + return MATERIAL_PREVIEW_IMAGE_OK; +} + +PreviewImageRetVal_t CMaterial::GetPreviewImage( unsigned char *pData, int width, int height, + ImageFormat imageFormat ) const +{ + CUtlBuffer buf; + int nHeaderSize; + int nImageOffset, nImageSize; + + char const* pFileName = GetPreviewImageFileName(); + if ( IsX360() || !pFileName ) + { + return MATERIAL_NO_PREVIEW_IMAGE; + } + + IVTFTexture *pVTFTexture = CreateVTFTexture(); + FileHandle_t fileHandle = g_pFullFileSystem->Open( pFileName, "rb" ); + if( !fileHandle ) + { + Warning( "\"%s\": cached version doesn't exist\n", pFileName ); + goto fail; + } + + nHeaderSize = VTFFileHeaderSize( VTF_MAJOR_VERSION ); + buf.EnsureCapacity( nHeaderSize ); + + // read the header first.. it's faster!! + int nBytesRead; // GCC won't let this be initialized right away + nBytesRead = g_pFullFileSystem->Read( buf.Base(), nHeaderSize, fileHandle ); + buf.SeekPut( CUtlBuffer::SEEK_HEAD, nBytesRead ); + + // Unserialize the header + if (!pVTFTexture->Unserialize( buf, true )) + { + Warning( "Error reading material \"%s\"\n", pFileName ); + goto fail; + } + + // FIXME: Make sure the preview image size requested is the same + // size as mip level 0 of the texture + Assert( (width == pVTFTexture->Width()) && (height == pVTFTexture->Height()) ); + + // Determine where in the file to start reading (frame 0, face 0, mip 0) + pVTFTexture->ImageFileInfo( 0, 0, 0, &nImageOffset, &nImageSize ); + + if ( nImageSize == 0 ) + { + Warning( "Couldn't determine offset and size of material \"%s\"\n", pFileName ); + goto fail; + } + + // Prep the utlbuffer for reading + buf.EnsureCapacity( nImageSize ); + buf.SeekPut( CUtlBuffer::SEEK_HEAD, 0 ); + + // Read in the bits at the specified location + g_pFullFileSystem->Seek( fileHandle, nImageOffset, FILESYSTEM_SEEK_HEAD ); + g_pFullFileSystem->Read( buf.Base(), nImageSize, fileHandle ); + g_pFullFileSystem->Close( fileHandle ); + + // Convert from the format read in to the requested format + ImageLoader::ConvertImageFormat( (unsigned char*)buf.Base(), pVTFTexture->Format(), + pData, imageFormat, width, height ); + + DestroyVTFTexture( pVTFTexture ); + return MATERIAL_PREVIEW_IMAGE_OK; + +fail: + if( fileHandle ) + { + g_pFullFileSystem->Close( fileHandle ); + } + int nSize = ImageLoader::GetMemRequired( width, height, 1, imageFormat, false ); + memset( pData, 0xff, nSize ); + DestroyVTFTexture( pVTFTexture ); + return MATERIAL_PREVIEW_IMAGE_BAD; +} + +//----------------------------------------------------------------------------- +// Material variables +//----------------------------------------------------------------------------- +IMaterialVar *CMaterial::FindVar( char const *pVarName, bool *pFound, bool complain ) +{ + PrecacheVars(); + + // FIXME: Could look for flags here too... + + MaterialVarSym_t sym = IMaterialVar::FindSymbol(pVarName); + if ( sym != UTL_INVAL_SYMBOL ) + { + for (int i = m_VarCount; --i >= 0; ) + { + if (m_pShaderParams[i]->GetNameAsSymbol() == sym) + { + if( pFound ) + *pFound = true; + return m_pShaderParams[i]; + } + } + } + + if( pFound ) + *pFound = false; + + if( complain ) + { + static int complainCount = 0; + if( complainCount < 100 ) + { + Warning( "No such variable \"%s\" for material \"%s\"\n", pVarName, GetName() ); + complainCount++; + } + } + return GetDummyVariable(); +} + +struct tokencache_t +{ + unsigned short symbol; + unsigned char varIndex; + unsigned char cached; +}; + +IMaterialVar *CMaterial::FindVarFast( char const *pVarName, unsigned int *pCacheData ) +{ + tokencache_t *pToken = reinterpret_cast(pCacheData); + PrecacheVars(); + + if ( pToken->cached ) + { + if ( pToken->varIndex < m_VarCount && m_pShaderParams[pToken->varIndex]->GetNameAsSymbol() == pToken->symbol ) + return m_pShaderParams[pToken->varIndex]; + // FIXME: Could look for flags here too... + if ( !IMaterialVar::SymbolMatches(pVarName, pToken->symbol) ) + { + pToken->symbol = IMaterialVar::FindSymbol(pVarName); + } + } + else + { + pToken->cached = true; + pToken->symbol = IMaterialVar::FindSymbol(pVarName); + } + + if ( pToken->symbol != UTL_INVAL_SYMBOL ) + { + for (int i = m_VarCount; --i >= 0; ) + { + if (m_pShaderParams[i]->GetNameAsSymbol() == pToken->symbol) + { + pToken->varIndex = i; + return m_pShaderParams[i]; + } + } + } + return NULL; +} + +//----------------------------------------------------------------------------- +// Lovely material properties +//----------------------------------------------------------------------------- +void CMaterial::GetReflectivity( Vector& reflect ) +{ + Precache(); + + reflect = m_Reflectivity; +} + + +bool CMaterial::GetPropertyFlag( MaterialPropertyTypes_t type ) +{ + Precache(); + + if (!IsValidRenderState()) + return false; + + switch( type ) + { + case MATERIAL_PROPERTY_NEEDS_LIGHTMAP: + return IsUsingLightmap(); + + case MATERIAL_PROPERTY_NEEDS_BUMPED_LIGHTMAPS: + return IsUsingDiffuseBumpedLighting(); + } + + return false; +} + + +//----------------------------------------------------------------------------- +// Is the material visible from both sides? +//----------------------------------------------------------------------------- +bool CMaterial::IsTwoSided() +{ + PrecacheVars(); + return GetMaterialVarFlag(MATERIAL_VAR_NOCULL); +} + + +//----------------------------------------------------------------------------- +// Are we translucent? +//----------------------------------------------------------------------------- +bool CMaterial::IsTranslucent() +{ + Precache(); + if ( m_VarCount > ALPHA ) + return IsTranslucentInternal( m_pShaderParams? m_pShaderParams[ALPHA]->GetFloatValue() : 0.0 ); + return false; +} + + +bool CMaterial::IsTranslucentInternal( float fAlphaModulation ) const +{ + if (m_pShader && IsValidRenderState()) + { + // I have to check for alpha modulation here because it isn't + // factored into the shader's notion of whether or not it's transparent + return ::IsTranslucent(&m_ShaderRenderState) || + (fAlphaModulation < 1.0f) || + m_pShader->IsTranslucent( m_pShaderParams ); + } + return false; +} + + +//----------------------------------------------------------------------------- +// Are we alphatested? +//----------------------------------------------------------------------------- +bool CMaterial::IsAlphaTested() +{ + Precache(); + if (m_pShader && IsValidRenderState()) + { + return ::IsAlphaTested(&m_ShaderRenderState) || + GetMaterialVarFlag( MATERIAL_VAR_ALPHATEST ); + } + return false; +} + + +//----------------------------------------------------------------------------- +// Are we vertex lit? +//----------------------------------------------------------------------------- +bool CMaterial::IsVertexLit() +{ + Precache(); + if (IsValidRenderState()) + { + return ( GetMaterialVarFlags2() & MATERIAL_VAR2_LIGHTING_VERTEX_LIT ) != 0; + } + return false; +} + + +//----------------------------------------------------------------------------- +// Is the shader a sprite card shader? +//----------------------------------------------------------------------------- +bool CMaterial::IsSpriteCard() +{ + Precache(); + if (IsValidRenderState()) + { + return ( GetMaterialVarFlags2() & MATERIAL_VAR2_IS_SPRITECARD ) != 0; + } + return false; +} + + +//----------------------------------------------------------------------------- +// Proxies +//----------------------------------------------------------------------------- +void CMaterial::CallBindProxy( void *proxyData ) +{ + CMatCallQueue *pCallQueue = MaterialSystem()->GetRenderCallQueue(); + bool bIsThreaded = ( pCallQueue != NULL ); + switch (g_config.proxiesTestMode) + { + case 0: + { + // Make sure we call the proxies in the order in which they show up + // in the .vmt file + if ( m_ProxyInfo.Count() ) + { + if ( bIsThreaded ) + { + EnableThreadedMaterialVarAccess( true, m_pShaderParams, m_VarCount ); + } + for( int i = 0; i < m_ProxyInfo.Count(); ++i ) + { + m_ProxyInfo[i]->OnBind( proxyData ); + } + if ( bIsThreaded ) + { + EnableThreadedMaterialVarAccess( false, m_pShaderParams, m_VarCount ); + } + } + } + break; + + case 2: + // alpha mod all.... + { + float value = ( sin( 2.0f * M_PI * Plat_FloatTime() / 10.0f ) * 0.5f ) + 0.5f; + m_pShaderParams[ALPHA]->SetFloatValue( value ); + } + break; + + case 3: + // color mod all... + { + float value = ( sin( 2.0f * M_PI * Plat_FloatTime() / 10.0f ) * 0.5f ) + 0.5f; + m_pShaderParams[COLOR]->SetVecValue( value, 1.0f, 1.0f ); + } + break; + } +} + + +IMaterial *CMaterial::CheckProxyReplacement( void *proxyData ) +{ + if ( m_pReplacementProxy != NULL ) + { + IMaterial *pReplaceMaterial = m_pReplacementProxy->GetMaterial(); + + if ( pReplaceMaterial ) + { + return pReplaceMaterial; + } + } + + return this; +} + + +bool CMaterial::HasProxy( ) const +{ + const_cast< CMaterial* >( this )->PrecacheVars(); + return m_ProxyInfo.Count() > 0; +} + + +//----------------------------------------------------------------------------- +// Main draw method +//----------------------------------------------------------------------------- + +#ifdef _WIN32 +#pragma warning (disable: 4189) +#endif + +void CMaterial::DrawMesh( VertexCompressionType_t vertexCompression ) +{ + if ( m_pShader ) + { +#ifdef _DEBUG + if ( GetMaterialVarFlags() & MATERIAL_VAR_DEBUG ) + { + // Putcher breakpoint here to catch the rendering of a material + // marked for debugging ($debug = 1 in a .vmt file) dynamic state version + int x = 0; + } +#endif + if ((GetMaterialVarFlags() & MATERIAL_VAR_NO_DRAW) == 0) + { + const char *pName = m_pShader->GetName(); + ShaderSystem()->DrawElements( m_pShader, m_pShaderParams, &m_ShaderRenderState, vertexCompression, m_ChangeID ^ g_nDebugVarsSignature ); + } + } + else + { + Warning( "CMaterial::DrawElements: No bound shader\n" ); + } +} + +#ifdef _WIN32 +#pragma warning (default: 4189) +#endif + +IShader *CMaterial::GetShader( ) const +{ + return m_pShader; +} + +IMaterialVar *CMaterial::GetShaderParam( int id ) +{ + return m_pShaderParams[id]; +} + + +//----------------------------------------------------------------------------- +// Adds a material variable to the material +//----------------------------------------------------------------------------- +void CMaterial::AddMaterialVar( IMaterialVar *pMaterialVar ) +{ + ++m_VarCount; + m_pShaderParams = (IMaterialVar**)realloc( m_pShaderParams, m_VarCount * sizeof( IMaterialVar*) ); + m_pShaderParams[m_VarCount-1] = pMaterialVar; +} + + +bool CMaterial::IsErrorMaterial() const +{ + extern IMaterialInternal *g_pErrorMaterial; + const IMaterialInternal *pThis = this; + return g_pErrorMaterial == pThis; +} + + +void CMaterial::FindRepresentativeTexture( void ) +{ + Precache(); + + // First try to find the base texture... + bool found; + IMaterialVar *textureVar = FindVar( "$baseTexture", &found, false ); + if( found && textureVar->GetType() == MATERIAL_VAR_TYPE_TEXTURE ) + { + ITextureInternal *pTexture = ( ITextureInternal * )textureVar->GetTextureValue(); + if( pTexture ) + { + pTexture->GetReflectivity( m_Reflectivity ); + } + } + if( !found || textureVar->GetType() != MATERIAL_VAR_TYPE_TEXTURE ) + { + // Try the env map mask if the base texture doesn't work... + // this is needed for specular decals + textureVar = FindVar( "$envmapmask", &found, false ); + if( !found || textureVar->GetType() != MATERIAL_VAR_TYPE_TEXTURE ) + { + // Try the bumpmap + textureVar = FindVar( "$bumpmap", &found, false ); + if( !found || textureVar->GetType() != MATERIAL_VAR_TYPE_TEXTURE ) + { + textureVar = FindVar( "$dudvmap", &found, false ); + if( !found || textureVar->GetType() != MATERIAL_VAR_TYPE_TEXTURE ) + { + textureVar = FindVar( "$normalmap", &found, false ); + if( !found || textureVar->GetType() != MATERIAL_VAR_TYPE_TEXTURE ) + { + // Warning( "Can't find representative texture for material \"%s\"\n", GetName() ); + m_representativeTexture = TextureManager()->ErrorTexture(); + return; + } + } + } + } + } + + m_representativeTexture = static_cast( textureVar->GetTextureValue() ); + if (m_representativeTexture) + { + m_representativeTexture->Precache(); + } + else + { + m_representativeTexture = TextureManager()->ErrorTexture(); + Assert( m_representativeTexture ); + } +} + + +void CMaterial::GetLowResColorSample( float s, float t, float *color ) const +{ + if( !m_representativeTexture ) + { + return; + } + m_representativeTexture->GetLowResColorSample( s, t, color); +} + + +//----------------------------------------------------------------------------- +// Lightmap-related methods +//----------------------------------------------------------------------------- + +void CMaterial::SetMinLightmapPageID( int pageID ) +{ + m_minLightmapPageID = pageID; +} + +void CMaterial::SetMaxLightmapPageID( int pageID ) +{ + m_maxLightmapPageID = pageID; +} + +int CMaterial::GetMinLightmapPageID( ) const +{ + return m_minLightmapPageID; +} + +int CMaterial::GetMaxLightmapPageID( ) const +{ + return m_maxLightmapPageID; +} + +void CMaterial::SetNeedsWhiteLightmap( bool val ) +{ + if ( val ) + m_Flags |= MATERIAL_NEEDS_WHITE_LIGHTMAP; + else + m_Flags &= ~MATERIAL_NEEDS_WHITE_LIGHTMAP; +} + +bool CMaterial::GetNeedsWhiteLightmap( ) const +{ + return (m_Flags & MATERIAL_NEEDS_WHITE_LIGHTMAP) != 0; +} + +void CMaterial::MarkAsPreloaded( bool bSet ) +{ + if ( bSet ) + { + m_Flags |= MATERIAL_IS_PRELOADED; + } + else + { + m_Flags &= ~MATERIAL_IS_PRELOADED; + } +} + +bool CMaterial::IsPreloaded() const +{ + return ( m_Flags & MATERIAL_IS_PRELOADED ) != 0; +} + +void CMaterial::ArtificialAddRef( void ) +{ + if ( m_Flags & MATERIAL_ARTIFICIAL_REFCOUNT ) + { + // already done + return; + } + + m_Flags |= MATERIAL_ARTIFICIAL_REFCOUNT; + m_RefCount++; +} + +void CMaterial::ArtificialRelease( void ) +{ + if ( !( m_Flags & MATERIAL_ARTIFICIAL_REFCOUNT ) ) + { + return; + } + + m_Flags &= ~MATERIAL_ARTIFICIAL_REFCOUNT; + m_RefCount--; +} + +//----------------------------------------------------------------------------- +// Return the shader params +//----------------------------------------------------------------------------- +IMaterialVar **CMaterial::GetShaderParams( void ) +{ + return m_pShaderParams; +} + +int CMaterial::ShaderParamCount() const +{ + return m_VarCount; +} + + +//----------------------------------------------------------------------------- +// VMT parser +//----------------------------------------------------------------------------- +void InsertKeyValues( KeyValues& dst, KeyValues& src, bool bCheckForExistence, bool bRecursive ) +{ + KeyValues *pSrcVar = src.GetFirstSubKey(); + while( pSrcVar ) + { + if ( !bCheckForExistence || dst.FindKey( pSrcVar->GetName() ) ) + { + switch( pSrcVar->GetDataType() ) + { + case KeyValues::TYPE_STRING: + dst.SetString( pSrcVar->GetName(), pSrcVar->GetString() ); + break; + case KeyValues::TYPE_INT: + dst.SetInt( pSrcVar->GetName(), pSrcVar->GetInt() ); + break; + case KeyValues::TYPE_FLOAT: + dst.SetFloat( pSrcVar->GetName(), pSrcVar->GetFloat() ); + break; + case KeyValues::TYPE_PTR: + dst.SetPtr( pSrcVar->GetName(), pSrcVar->GetPtr() ); + break; + case KeyValues::TYPE_NONE: + { + // Subkey. Recurse. + KeyValues *pNewDest = dst.FindKey( pSrcVar->GetName(), true ); + Assert( pNewDest ); + InsertKeyValues( *pNewDest, *pSrcVar, bCheckForExistence, true ); + } + break; + } + } + pSrcVar = pSrcVar->GetNextKey(); + } + + if ( bRecursive && !dst.GetFirstSubKey() ) + { + // Insert a dummy key to an empty subkey to make sure it doesn't get removed + dst.SetInt( "__vmtpatchdummy", 1 ); + } + + if( bCheckForExistence ) + { + for( KeyValues *pScan = dst.GetFirstTrueSubKey(); pScan; pScan = pScan->GetNextTrueSubKey() ) + { + KeyValues *pTmp = src.FindKey( pScan->GetName() ); + if( !pTmp ) + continue; + // make sure that this is a subkey. + if( pTmp->GetDataType() != KeyValues::TYPE_NONE ) + continue; + InsertKeyValues( *pScan, *pTmp, bCheckForExistence ); + } + } +} + +void WriteKeyValuesToFile( const char *pFileName, KeyValues& keyValues ) +{ + keyValues.SaveToFile( g_pFullFileSystem, pFileName ); +} + +void ApplyPatchKeyValues( KeyValues &keyValues, KeyValues &patchKeyValues ) +{ + KeyValues *pInsertSection = patchKeyValues.FindKey( "insert" ); + KeyValues *pReplaceSection = patchKeyValues.FindKey( "replace" ); + + if ( pInsertSection ) + { + InsertKeyValues( keyValues, *pInsertSection, false ); + } + + if ( pReplaceSection ) + { + InsertKeyValues( keyValues, *pReplaceSection, true ); + } + + // Could add other commands here, like "delete", "rename", etc. +} + +//----------------------------------------------------------------------------- +// Adds keys from srcKeys to destKeys, overwriting any keys that are already +// there. +//----------------------------------------------------------------------------- +void MergeKeyValues( KeyValues &srcKeys, KeyValues &destKeys ) +{ + for( KeyValues *pKV = srcKeys.GetFirstValue(); pKV; pKV = pKV->GetNextValue() ) + { + switch( pKV->GetDataType() ) + { + case KeyValues::TYPE_STRING: + destKeys.SetString( pKV->GetName(), pKV->GetString() ); + break; + case KeyValues::TYPE_INT: + destKeys.SetInt( pKV->GetName(), pKV->GetInt() ); + break; + case KeyValues::TYPE_FLOAT: + destKeys.SetFloat( pKV->GetName(), pKV->GetFloat() ); + break; + case KeyValues::TYPE_PTR: + destKeys.SetPtr( pKV->GetName(), pKV->GetPtr() ); + break; + } + } + for( KeyValues *pKV = srcKeys.GetFirstTrueSubKey(); pKV; pKV = pKV->GetNextTrueSubKey() ) + { + KeyValues *pDestKV = destKeys.FindKey( pKV->GetName(), true ); + MergeKeyValues( *pKV, *pDestKV ); + } +} + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +void AccumulatePatchKeyValues( KeyValues &srcKeyValues, KeyValues &patchKeyValues ) +{ + KeyValues *pDestInsertSection = patchKeyValues.FindKey( "insert" ); + if ( pDestInsertSection == NULL ) + { + pDestInsertSection = new KeyValues( "insert" ); + patchKeyValues.AddSubKey( pDestInsertSection ); + } + + KeyValues *pDestReplaceSection = patchKeyValues.FindKey( "replace" ); + if ( pDestReplaceSection == NULL ) + { + pDestReplaceSection = new KeyValues( "replace" ); + patchKeyValues.AddSubKey( pDestReplaceSection ); + } + + KeyValues *pSrcInsertSection = srcKeyValues.FindKey( "insert" ); + if ( pSrcInsertSection ) + { + MergeKeyValues( *pSrcInsertSection, *pDestInsertSection ); + } + + KeyValues *pSrcReplaceSection = srcKeyValues.FindKey( "replace" ); + if ( pSrcReplaceSection ) + { + MergeKeyValues( *pSrcReplaceSection, *pDestReplaceSection ); + } +} + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +bool AccumulateRecursiveVmtPatches( KeyValues &patchKeyValuesOut, KeyValues **ppBaseKeyValuesOut, const KeyValues& keyValues, const char *pPathID, CUtlVector *pIncludes ) +{ + if ( pIncludes ) + { + pIncludes->Purge(); + } + + patchKeyValuesOut.Clear(); + + if ( V_stricmp( keyValues.GetName(), "patch" ) != 0 ) + { + // Not a patch file, nothing to do + if ( ppBaseKeyValuesOut ) + { + // flag to the caller that the passed in keyValues are in fact final non-patch values + *ppBaseKeyValuesOut = NULL; + } + return true; + } + + KeyValues *pCurrentKeyValues = keyValues.MakeCopy(); + + // Recurse down through all patch files: + int nCount = 0; + while( ( nCount < 10 ) && ( V_stricmp( pCurrentKeyValues->GetName(), "patch" ) == 0 ) ) + { + // Accumulate the new patch keys from this file + AccumulatePatchKeyValues( *pCurrentKeyValues, patchKeyValuesOut ); + + // Load the included file + const char *pIncludeFileName = pCurrentKeyValues->GetString( "include" ); + + if ( pIncludeFileName == NULL ) + { + // A patch file without an include key? Not good... + Warning( "VMT patch file has no include key - invalid!\n" ); + Assert( pIncludeFileName ); + break; + } + + CUtlString includeFileName( pIncludeFileName ); // copy off the string before we clear the keyvalues it lives in + pCurrentKeyValues->Clear(); + bool bSuccess = pCurrentKeyValues->LoadFromFile( g_pFullFileSystem, includeFileName, pPathID ); + if( bSuccess ) + { + if ( pIncludes ) + { + // Remember that we included this file for the pure server stuff. + pIncludes->AddToTail( g_pFullFileSystem->FindOrAddFileName( includeFileName ) ); + } + } + else + { + pCurrentKeyValues->deleteThis(); +#ifndef DEDICATED + Warning( "Failed to load $include VMT file (%s)\n", includeFileName.String() ); +#endif + if ( !HushAsserts() ) + { + AssertMsg( false, "Failed to load $include VMT file (%s)", includeFileName.String() ); + } + return false; + } + + nCount++; + } + + if ( ppBaseKeyValuesOut ) + { + *ppBaseKeyValuesOut = pCurrentKeyValues; + } + else + { + pCurrentKeyValues->deleteThis(); + } + + if( nCount >= 10 ) + { + Warning( "Infinite recursion in patch file?\n" ); + } + return true; +} + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +void ExpandPatchFile( KeyValues& keyValues, KeyValues &patchKeyValues, const char *pPathID, CUtlVector *pIncludes ) +{ + KeyValues *pNonPatchKeyValues = NULL; + if ( !patchKeyValues.IsEmpty() ) + { + pNonPatchKeyValues = keyValues.MakeCopy(); + } + else + { + bool bSuccess = AccumulateRecursiveVmtPatches( patchKeyValues, &pNonPatchKeyValues, keyValues, pPathID, pIncludes ); + if ( !bSuccess ) + { + return; + } + } + + if ( pNonPatchKeyValues != NULL ) + { + // We're dealing with a patch file. Apply accumulated patches to final vmt + ApplyPatchKeyValues( *pNonPatchKeyValues, patchKeyValues ); + keyValues = *pNonPatchKeyValues; + pNonPatchKeyValues->deleteThis(); + } +} + +bool LoadVMTFile( KeyValues &vmtKeyValues, KeyValues &patchKeyValues, const char *pMaterialName, bool bAbsolutePath, CUtlVector *pIncludes ) +{ + char pFileName[MAX_PATH]; + const char *pPathID = "GAME"; + if ( !bAbsolutePath ) + { + Q_snprintf( pFileName, sizeof( pFileName ), "materials/%s.vmt", pMaterialName ); + } + else + { + Q_snprintf( pFileName, sizeof( pFileName ), "%s.vmt", pMaterialName ); + if ( pMaterialName[0] == '/' && pMaterialName[1] == '/' && pMaterialName[2] != '/' ) + { + // UNC, do full search + pPathID = NULL; + } + } + + if ( !vmtKeyValues.LoadFromFile( g_pFullFileSystem, pFileName, pPathID ) ) + { + return false; + } + ExpandPatchFile( vmtKeyValues, patchKeyValues, pPathID, pIncludes ); + + return true; +} + +int CMaterial::GetNumPasses( void ) +{ + Precache(); +// int mod = m_ShaderRenderState.m_Modulation; + int mod = 0; + return m_ShaderRenderState.m_pSnapshots[mod].m_nPassCount; +} + +int CMaterial::GetTextureMemoryBytes( void ) +{ + Precache(); + int bytes = 0; + int i; + for( i = 0; i < m_VarCount; i++ ) + { + IMaterialVar *pVar = m_pShaderParams[i]; + if( pVar->GetType() == MATERIAL_VAR_TYPE_TEXTURE ) + { + ITexture *pTexture = pVar->GetTextureValue(); + if( pTexture && pTexture != ( ITexture * )0xffffffff ) + { + bytes += pTexture->GetApproximateVidMemBytes(); + } + } + } + return bytes; +} + +void CMaterial::SetUseFixedFunctionBakedLighting( bool bEnable ) +{ + SetMaterialVarFlags2( MATERIAL_VAR2_USE_FIXED_FUNCTION_BAKED_LIGHTING, bEnable ); +} + +bool CMaterial::NeedsFixedFunctionFlashlight() const +{ + return ( GetMaterialVarFlags2() & MATERIAL_VAR2_NEEDS_FIXED_FUNCTION_FLASHLIGHT ) && + MaterialSystem()->InFlashlightMode(); +} + +bool CMaterial::IsUsingVertexID( ) const +{ + return ( GetMaterialVarFlags2() & MATERIAL_VAR2_USES_VERTEXID ) != 0; +} + +void CMaterial::DeleteIfUnreferenced() +{ + if ( m_RefCount > 0 ) + return; + IMaterialVar::DeleteUnreferencedTextures( true ); + IMaterialInternal::DestroyMaterial( this ); + IMaterialVar::DeleteUnreferencedTextures( false ); +} diff --git a/materialsystem/cmaterial_queuefriendly.cpp b/materialsystem/cmaterial_queuefriendly.cpp new file mode 100644 index 0000000..d6a9097 --- /dev/null +++ b/materialsystem/cmaterial_queuefriendly.cpp @@ -0,0 +1,410 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +// +//=============================================================================// + +#include "cmaterial_queuefriendly.h" +#include "tier1/callqueue.h" +#include "materialsystem_global.h" + + +#define USE_QUEUED_MATERIAL_CALLS //uncomment to queue up material changing calls. Comment out to always use instant calls. + + +#ifdef USE_QUEUED_MATERIAL_CALLS + +#define QUEUE_MATERIAL_CALL( FuncName, ... ) \ + { \ + ICallQueue *pCallQueue = materials->GetRenderContext()->GetCallQueue(); \ + if ( !pCallQueue ) \ + { \ + m_pRealTimeVersion->FuncName( __VA_ARGS__ ); \ + } \ + else \ + { \ + pCallQueue->QueueCall( m_pRealTimeVersion, &IMaterialInternal::FuncName, ##__VA_ARGS__ ); \ + } \ + } + +#else + +#define QUEUE_MATERIAL_CALL( FuncName, ... ) m_pRealTimeVersion->FuncName( __VA_ARGS__ ); + +#endif + + +const char *CMaterial_QueueFriendly::GetName() const +{ + return m_pRealTimeVersion->GetName(); +} + +const char *CMaterial_QueueFriendly::GetTextureGroupName() const +{ + return m_pRealTimeVersion->GetTextureGroupName(); +} + +PreviewImageRetVal_t CMaterial_QueueFriendly::GetPreviewImageProperties( int *width, int *height, ImageFormat *imageFormat, bool* isTranslucent ) const +{ + return m_pRealTimeVersion->GetPreviewImageProperties( width, height, imageFormat, isTranslucent ); +} + +PreviewImageRetVal_t CMaterial_QueueFriendly::GetPreviewImage( unsigned char *data, int width, int height, ImageFormat imageFormat ) const +{ + return m_pRealTimeVersion->GetPreviewImage( data, width, height, imageFormat ); +} + +int CMaterial_QueueFriendly::GetMappingWidth( ) +{ + return m_pRealTimeVersion->GetMappingWidth(); +} + +int CMaterial_QueueFriendly::GetMappingHeight( ) +{ + return m_pRealTimeVersion->GetMappingHeight(); +} + +int CMaterial_QueueFriendly::GetNumAnimationFrames( ) +{ + return m_pRealTimeVersion->GetNumAnimationFrames(); +} + +bool CMaterial_QueueFriendly::InMaterialPage( void ) +{ + return m_pRealTimeVersion->InMaterialPage(); +} + +void CMaterial_QueueFriendly::GetMaterialOffset( float *pOffset ) +{ + m_pRealTimeVersion->GetMaterialOffset( pOffset ); +} + +void CMaterial_QueueFriendly::GetMaterialScale( float *pScale ) +{ + m_pRealTimeVersion->GetMaterialScale( pScale ); +} + +IMaterial *CMaterial_QueueFriendly::GetMaterialPage( void ) +{ + return m_pRealTimeVersion->GetMaterialPage(); +} + +void CMaterial_QueueFriendly::IncrementReferenceCount( void ) +{ + Assert( ThreadInMainThread() ); + ++m_nReferenceCount; + m_pRealTimeVersion->IncrementReferenceCount(); +} + +int CMaterial_QueueFriendly::GetEnumerationID( void ) const +{ + return m_pRealTimeVersion->GetEnumerationID(); +} + +bool CMaterial_QueueFriendly::HasProxy( void ) const +{ + return m_pRealTimeVersion->HasProxy(); +} + +void CMaterial_QueueFriendly::GetReflectivity( Vector& reflect ) +{ + m_pRealTimeVersion->GetReflectivity( reflect ); +} + +bool CMaterial_QueueFriendly::GetPropertyFlag( MaterialPropertyTypes_t type ) +{ + return m_pRealTimeVersion->GetPropertyFlag( type ); +} + +bool CMaterial_QueueFriendly::IsTwoSided() +{ + return m_pRealTimeVersion->IsTwoSided(); +} + +int CMaterial_QueueFriendly::ShaderParamCount() const +{ + return m_pRealTimeVersion->ShaderParamCount(); +} + +bool CMaterial_QueueFriendly::IsErrorMaterial() const +{ + return m_pRealTimeVersion->IsErrorMaterial(); +} + +bool CMaterial_QueueFriendly::IsSpriteCard() +{ + return m_pRealTimeVersion->IsSpriteCard(); +} + + + +//TODO: Investigate if these are likely to change at all when setting vars/flags +bool CMaterial_QueueFriendly::IsAlphaTested() +{ + return m_pRealTimeVersion->IsAlphaTested(); +} + +bool CMaterial_QueueFriendly::IsVertexLit() +{ + return m_pRealTimeVersion->IsVertexLit(); +} + +VertexFormat_t CMaterial_QueueFriendly::GetVertexFormat() const +{ + return m_pRealTimeVersion->GetVertexFormat(); +} + +bool CMaterial_QueueFriendly::UsesEnvCubemap( void ) +{ + return m_pRealTimeVersion->UsesEnvCubemap(); +} + +bool CMaterial_QueueFriendly::NeedsTangentSpace( void ) +{ + return m_pRealTimeVersion->NeedsTangentSpace(); +} + +bool CMaterial_QueueFriendly::NeedsSoftwareSkinning( void ) +{ + return m_pRealTimeVersion->NeedsSoftwareSkinning(); +} + +int CMaterial_QueueFriendly::GetNumPasses( void ) +{ + return m_pRealTimeVersion->GetNumPasses(); +} + +int CMaterial_QueueFriendly::GetTextureMemoryBytes( void ) +{ + return m_pRealTimeVersion->GetTextureMemoryBytes(); +} + +bool CMaterial_QueueFriendly::NeedsLightmapBlendAlpha( void ) +{ + return m_pRealTimeVersion->NeedsLightmapBlendAlpha(); +} + +bool CMaterial_QueueFriendly::NeedsSoftwareLighting( void ) +{ + return m_pRealTimeVersion->NeedsSoftwareLighting(); +} + +MorphFormat_t CMaterial_QueueFriendly::GetMorphFormat() const +{ + return m_pRealTimeVersion->GetMorphFormat(); +} + +void CMaterial_QueueFriendly::GetLowResColorSample( float s, float t, float *color ) const +{ + if ( m_pRealTimeVersion ) + m_pRealTimeVersion->GetLowResColorSample( s, t, color ); + else + color[ 0 ] = color[ 1 ] = color[ 2 ] = 0.0f; +} + + + +IMaterialVar *CMaterial_QueueFriendly::FindVar( const char *varName, bool *found, bool complain ) +{ + //TODO: return a queue friendly variable that can be get/set + return m_pRealTimeVersion->FindVar( varName, found, complain ); +} + +IMaterialVar *CMaterial_QueueFriendly::FindVarFast( char const *pVarName, unsigned int *pToken ) +{ + //TODO: return a queue friendly variable that can be get/set + return m_pRealTimeVersion->FindVarFast( pVarName, pToken ); +} + +IMaterialVar **CMaterial_QueueFriendly::GetShaderParams( void ) +{ + //TODO: return queue friendly variables that can be get/set + return m_pRealTimeVersion->GetShaderParams(); +} + +void CMaterial_QueueFriendly::DecrementReferenceCount( void ) +{ + Assert( ThreadInMainThread() ); + --m_nReferenceCount; + QUEUE_MATERIAL_CALL( DecrementReferenceCount ); +} + +void CMaterial_QueueFriendly::DeleteIfUnreferenced() +{ + Assert( ThreadInMainThread() ); + if ( m_nReferenceCount > 0 ) + return; + + MaterialSystem()->RemoveMaterial( GetRealTimeVersion() ); + QUEUE_MATERIAL_CALL( DeleteIfUnreferenced ); +} + +void CMaterial_QueueFriendly::RecomputeStateSnapshots() +{ + QUEUE_MATERIAL_CALL( RecomputeStateSnapshots ); +} + + +bool CMaterial_QueueFriendly::IsTranslucent() +{ + //TODO: need to base this as if the queued state is 100% up to date + return m_pRealTimeVersion->IsTranslucentInternal( GetMaterialVarFlag( MATERIAL_VAR_IGNORE_ALPHA_MODULATION ) ? 1.0f : m_fAlphaModulationOnQueueCompletion ); +} + +bool CMaterial_QueueFriendly::NeedsPowerOfTwoFrameBufferTexture( bool bCheckSpecificToThisFrame ) +{ + //bCheckSpecificToThisFrame scares me a bit. + return m_pRealTimeVersion->NeedsPowerOfTwoFrameBufferTexture( bCheckSpecificToThisFrame ); +} + +bool CMaterial_QueueFriendly::NeedsFullFrameBufferTexture( bool bCheckSpecificToThisFrame ) +{ + //bCheckSpecificToThisFrame scares me a bit. + return m_pRealTimeVersion->NeedsFullFrameBufferTexture( bCheckSpecificToThisFrame ); +} + +void CMaterial_QueueFriendly::AlphaModulate( float alpha ) +{ + QUEUE_MATERIAL_CALL( AlphaModulate, alpha ); + m_fAlphaModulationOnQueueCompletion = alpha; +} + +void CMaterial_QueueFriendly::ColorModulate( float r, float g, float b ) +{ + QUEUE_MATERIAL_CALL( ColorModulate, r, g, b ); + m_vColorModulationOnQueueCompletion.Init( r, g, b ); +} + +void CMaterial_QueueFriendly::SetMaterialVarFlag( MaterialVarFlags_t flag, bool on ) +{ + QUEUE_MATERIAL_CALL( SetMaterialVarFlag, flag, on ); +} +bool CMaterial_QueueFriendly::GetMaterialVarFlag( MaterialVarFlags_t flag ) const +{ + //TODO: somehow mix both queued and real time states + return m_pRealTimeVersion->GetMaterialVarFlag( flag ); +} + +void CMaterial_QueueFriendly::SetShader( const char *pShaderName ) +{ + //TODO: queue it and investigate, seems like a grenade. + m_pRealTimeVersion->SetShader( pShaderName ); +} + +void CMaterial_QueueFriendly::SetShaderAndParams( KeyValues *pKeyValues ) +{ + //TODO: queue it and investigate, seems like a grenade. + m_pRealTimeVersion->SetShaderAndParams( pKeyValues ); +} + +const char *CMaterial_QueueFriendly::GetShaderName() const +{ + //TODO: return as if the queue is up to date. Someone could have set the shader very recently + return m_pRealTimeVersion->GetShaderName(); +} + +void CMaterial_QueueFriendly::Refresh() +{ + //TODO: Investigate, this one seems like a grenade. + m_pRealTimeVersion->Refresh(); + //QUEUE_MATERIAL_CALL( Refresh ); +} + +void CMaterial_QueueFriendly::RefreshPreservingMaterialVars() +{ + //TODO: Investigate, this one seems like a grenade. + m_pRealTimeVersion->RefreshPreservingMaterialVars(); + //QUEUE_MATERIAL_CALL( RefreshPreservingMaterialVars ); +} + +void CMaterial_QueueFriendly::SetUseFixedFunctionBakedLighting( bool bEnable ) +{ + QUEUE_MATERIAL_CALL( SetUseFixedFunctionBakedLighting, bEnable ); +} + +float CMaterial_QueueFriendly::GetAlphaModulation() +{ +#ifdef USE_QUEUED_MATERIAL_CALLS + return m_fAlphaModulationOnQueueCompletion; +#else + return m_pRealTimeVersion->GetAlphaModulation(); +#endif +} + +void CMaterial_QueueFriendly::GetColorModulation( float *r, float *g, float *b ) +{ +#ifdef USE_QUEUED_MATERIAL_CALLS + *r = m_vColorModulationOnQueueCompletion.x; + *g = m_vColorModulationOnQueueCompletion.y; + *b = m_vColorModulationOnQueueCompletion.z; +#else + m_pRealTimeVersion->GetColorModulation( r, g, b ); +#endif +} + +void CMaterial_QueueFriendly::CallBindProxy( void *proxyData ) +{ + //TODO: queue it? Investigate. + return m_pRealTimeVersion->CallBindProxy( proxyData ); +} + +IMaterial *CMaterial_QueueFriendly::CheckProxyReplacement( void *proxyData ) +{ + return m_pRealTimeVersion->CheckProxyReplacement( proxyData ); +} + +void CMaterial_QueueFriendly::PrecacheMappingDimensions() +{ + return m_pRealTimeVersion->PrecacheMappingDimensions(); +} + +void CMaterial_QueueFriendly::FindRepresentativeTexture() +{ + return m_pRealTimeVersion->FindRepresentativeTexture(); +} + +bool CMaterial_QueueFriendly::IsRealTimeVersion( void ) const +{ + return false; +} + +IMaterialInternal *CMaterial_QueueFriendly::GetRealTimeVersion( void ) +{ + return m_pRealTimeVersion; +} + +IMaterialInternal *CMaterial_QueueFriendly::GetQueueFriendlyVersion( void ) +{ + return this; +} + + +void CMaterial_QueueFriendly::UpdateToRealTime( void ) +{ + m_fAlphaModulationOnQueueCompletion = m_pRealTimeVersion->GetAlphaModulation(); + m_pRealTimeVersion->GetColorModulation( &m_vColorModulationOnQueueCompletion.x, + &m_vColorModulationOnQueueCompletion.y, + &m_vColorModulationOnQueueCompletion.z ); + + m_nReferenceCount = m_pRealTimeVersion->GetReferenceCount(); +} + + + + + + + + + + + + + + + + + + diff --git a/materialsystem/cmaterial_queuefriendly.h b/materialsystem/cmaterial_queuefriendly.h new file mode 100644 index 0000000..d91792c --- /dev/null +++ b/materialsystem/cmaterial_queuefriendly.h @@ -0,0 +1,162 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +// +//=============================================================================// + +#ifndef CMATERIAL_QUEUEFRIENDLY_H +#define CMATERIAL_QUEUEFRIENDLY_H + +#ifdef _WIN32 +#pragma once +#endif + +#include "imaterialinternal.h" + +class CMaterial_QueueFriendly : public IMaterialInternal //wraps a CMaterial with queue friendly functions for game/engine code. materialsystem/shaderapi code should use CMaterial directly. +{ +public: + virtual const char * GetName() const; + virtual const char * GetTextureGroupName() const; + virtual PreviewImageRetVal_t GetPreviewImageProperties( int *width, int *height, ImageFormat *imageFormat, bool* isTranslucent ) const; + virtual PreviewImageRetVal_t GetPreviewImage( unsigned char *data, int width, int height, ImageFormat imageFormat ) const; + + virtual int GetMappingWidth( ); + virtual int GetMappingHeight( ); + virtual int GetNumAnimationFrames( ); + virtual bool InMaterialPage( void ); + virtual void GetMaterialOffset( float *pOffset ); + virtual void GetMaterialScale( float *pScale ); + virtual IMaterial *GetMaterialPage( void ); + virtual void IncrementReferenceCount( void ); + virtual int GetEnumerationID( void ) const; + virtual bool HasProxy( void ) const; + virtual void GetReflectivity( Vector& reflect ); + virtual bool GetPropertyFlag( MaterialPropertyTypes_t type ); + virtual bool IsTwoSided(); + virtual int ShaderParamCount() const; + virtual bool IsErrorMaterial() const; //should probably return the realtime error material instead of this wrapper for it + virtual bool IsSpriteCard(); //lets just assume nobody changes the shader to spritecard and immediately asks if it's a spritecard + + + + //TODO: Investigate if these are likely to change at all when setting vars/flags + virtual bool IsAlphaTested(); + virtual bool IsVertexLit(); + virtual VertexFormat_t GetVertexFormat() const; + virtual bool UsesEnvCubemap( void ); + virtual bool NeedsTangentSpace( void ); + virtual bool NeedsSoftwareSkinning( void ); + virtual int GetNumPasses( void ); + virtual int GetTextureMemoryBytes( void ); + virtual bool NeedsLightmapBlendAlpha( void ); + virtual bool NeedsSoftwareLighting( void ); + virtual MorphFormat_t GetMorphFormat() const; + + //TODO: Investigate if this can change over the course of a frame. + virtual void GetLowResColorSample( float s, float t, float *color ) const; + + + //Functions that need to be queue friendly, the whole reason for this wrapper class. + virtual IMaterialVar * FindVar( const char *varName, bool *found, bool complain = true ); + virtual IMaterialVar * FindVarFast( char const *pVarName, unsigned int *pToken ); + virtual IMaterialVar **GetShaderParams( void ); + virtual void DecrementReferenceCount( void ); + virtual void DeleteIfUnreferenced(); + virtual void RecomputeStateSnapshots(); + virtual bool IsTranslucent(); + virtual bool NeedsPowerOfTwoFrameBufferTexture( bool bCheckSpecificToThisFrame = true ); + virtual bool NeedsFullFrameBufferTexture( bool bCheckSpecificToThisFrame = true ); + virtual void AlphaModulate( float alpha ); + virtual void ColorModulate( float r, float g, float b ); + virtual void SetMaterialVarFlag( MaterialVarFlags_t flag, bool on ); + virtual bool GetMaterialVarFlag( MaterialVarFlags_t flag ) const; + virtual void SetShader( const char *pShaderName ); + virtual void SetShaderAndParams( KeyValues *pKeyValues ); + virtual const char * GetShaderName() const; + virtual void Refresh(); + virtual void RefreshPreservingMaterialVars(); + virtual void SetUseFixedFunctionBakedLighting( bool bEnable ); + virtual float GetAlphaModulation(); + virtual void GetColorModulation( float *r, float *g, float *b ); + virtual void CallBindProxy( void *proxyData ); + virtual IMaterial *CheckProxyReplacement( void *proxyData ); + virtual void PrecacheMappingDimensions( ); + virtual void FindRepresentativeTexture( void ); + virtual bool WasReloadedFromWhitelist() { return m_pRealTimeVersion->WasReloadedFromWhitelist(); } + virtual bool IsPrecached( ) const { return m_pRealTimeVersion->IsPrecached(); } + + +#define QUEUEFRIENDLY_USED_INTERNALLY_ASSERT AssertMsg( 0, "CMaterial_QueueFriendly used internally within materialsystem. Update the calling code to use a realtime CMaterial." ) + + //------------------------------------------------------------------------------ + // IMaterialInternal interfaces. Internal systems should not be using this queue + // wrapper class at all. Switch to the real time pointer in the calling code. + //------------------------------------------------------------------------------ + virtual int GetReferenceCount( ) const { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; return m_pRealTimeVersion->GetReferenceCount(); } + virtual void SetEnumerationID( int id ) { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; m_pRealTimeVersion->SetEnumerationID( id ); } + virtual void SetNeedsWhiteLightmap( bool val ) { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; m_pRealTimeVersion->SetNeedsWhiteLightmap( val ); } + virtual bool GetNeedsWhiteLightmap( ) const { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; return m_pRealTimeVersion->GetNeedsWhiteLightmap(); } + virtual void Uncache( bool bPreserveVars = false ) { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; m_pRealTimeVersion->Uncache( bPreserveVars ); } + virtual void Precache() { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; m_pRealTimeVersion->Precache(); } + // If provided, pKeyValues and pPatchKeyValues should come from LoadVMTFile() + virtual bool PrecacheVars( KeyValues *pKeyValues = NULL, KeyValues *pPatchKeyValues = NULL, CUtlVector *pIncludes = NULL, int nFindContext = MATERIAL_FINDCONTEXT_NONE ) { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; return m_pRealTimeVersion->PrecacheVars( pKeyValues, pPatchKeyValues, pIncludes, nFindContext ); } + virtual void ReloadTextures() { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; m_pRealTimeVersion->ReloadTextures(); } + virtual void SetMinLightmapPageID( int pageID ) { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; m_pRealTimeVersion->SetMinLightmapPageID( pageID ); } + virtual void SetMaxLightmapPageID( int pageID ) { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; m_pRealTimeVersion->SetMaxLightmapPageID( pageID ); } + virtual int GetMinLightmapPageID( ) const { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; return m_pRealTimeVersion->GetMinLightmapPageID(); } + virtual int GetMaxLightmapPageID( ) const { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; return m_pRealTimeVersion->GetMaxLightmapPageID(); } + virtual IShader *GetShader() const { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; return m_pRealTimeVersion->GetShader(); } + virtual bool IsPrecachedVars() const { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; return m_pRealTimeVersion->IsPrecachedVars(); } + virtual void DrawMesh( VertexCompressionType_t vertexCompression ) { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; m_pRealTimeVersion->DrawMesh( vertexCompression ); } + virtual VertexFormat_t GetVertexUsage() const { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; return m_pRealTimeVersion->GetVertexUsage(); } + virtual bool PerformDebugTrace() const { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; return m_pRealTimeVersion->PerformDebugTrace(); } + virtual bool NoDebugOverride() const { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; return m_pRealTimeVersion->NoDebugOverride(); } + virtual void ToggleSuppression() { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; m_pRealTimeVersion->ToggleSuppression(); } + virtual bool IsSuppressed() const { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; return m_pRealTimeVersion->IsSuppressed(); } + virtual void ToggleDebugTrace() { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; m_pRealTimeVersion->ToggleDebugTrace(); } + virtual bool UseFog() const { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; return m_pRealTimeVersion->UseFog(); } + virtual void AddMaterialVar( IMaterialVar *pMaterialVar ) { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; m_pRealTimeVersion->AddMaterialVar( pMaterialVar ); } + virtual ShaderRenderState_t *GetRenderState() { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; return m_pRealTimeVersion->GetRenderState(); } + virtual bool IsManuallyCreated() const { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; return m_pRealTimeVersion->IsManuallyCreated(); } + virtual bool NeedsFixedFunctionFlashlight() const { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; return m_pRealTimeVersion->NeedsFixedFunctionFlashlight(); } + virtual bool IsUsingVertexID() const { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; return m_pRealTimeVersion->IsUsingVertexID(); } + virtual void MarkAsPreloaded( bool bSet ) { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; m_pRealTimeVersion->MarkAsPreloaded( bSet ); } + virtual bool IsPreloaded() const { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; return m_pRealTimeVersion->IsPreloaded(); } + virtual void ArtificialAddRef() { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; m_pRealTimeVersion->ArtificialAddRef(); } + virtual void ArtificialRelease() { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; m_pRealTimeVersion->ArtificialRelease(); } + virtual void ReportVarChanged( IMaterialVar *pVar ) { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; m_pRealTimeVersion->ReportVarChanged( pVar ); } + virtual uint32 GetChangeID() const { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; return m_pRealTimeVersion->GetChangeID(); } + virtual bool IsTranslucentInternal( float fAlphaModulation ) const { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; return m_pRealTimeVersion->IsTranslucentInternal( fAlphaModulation ); } + + virtual void DecideShouldReloadFromWhitelist( IFileList *pFileList ) { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; return m_pRealTimeVersion->DecideShouldReloadFromWhitelist( pFileList ); } + virtual void ReloadFromWhitelistIfMarked() { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; return m_pRealTimeVersion->ReloadFromWhitelistIfMarked(); } + + virtual bool IsRealTimeVersion( void ) const; + virtual IMaterialInternal *GetRealTimeVersion( void ); + virtual IMaterialInternal *GetQueueFriendlyVersion( void ); + + void SetRealTimeVersion( IMaterialInternal *pRealTimeVersion ) + { + m_pRealTimeVersion = pRealTimeVersion; + m_nReferenceCount = m_pRealTimeVersion->GetReferenceCount(); + } + void UpdateToRealTime( void ); //update cached off variables using the real time version as a base. + + +protected: + IMaterialInternal *m_pRealTimeVersion; //the material we're wrapping with queued delays + +private: + //some calls need to know what state the material would be in right now if the queue had completed. + float m_fAlphaModulationOnQueueCompletion; + Vector m_vColorModulationOnQueueCompletion; + int m_nReferenceCount; // Only ever accessed from the main thread. +}; + + + +#endif //#ifndef CMATERIAL_QUEUEFRIENDLY_H + diff --git a/materialsystem/cmaterialdict.cpp b/materialsystem/cmaterialdict.cpp new file mode 100644 index 0000000..9eb8f0b --- /dev/null +++ b/materialsystem/cmaterialdict.cpp @@ -0,0 +1,171 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//============================================================================= + +#include "pch_materialsystem.h" + +#define MATSYS_INTERNAL + +#include "cmaterialdict.h" + +#include "materialsystem_global.h" +#include "filesystem.h" +#include "imaterialinternal.h" + +// NOTE: This must be the last file included!!! +#include "tier0/memdbgon.h" + +//----------------------------------------------------------------------------- +// sort function +//----------------------------------------------------------------------------- +bool CMaterialDict::MaterialLessFunc( const MaterialLookup_t& src1, + const MaterialLookup_t& src2 ) +{ + Assert( ThreadInMainThread() ); + // Always sort manually-created materials to the front + if ( src1.m_bManuallyCreated != src2.m_bManuallyCreated ) + return src1.m_bManuallyCreated; + + return src1.m_Name < src2.m_Name; +} + +//----------------------------------------------------------------------------- +// sort function for missing materials +//----------------------------------------------------------------------------- +bool CMaterialDict::MissingMaterialLessFunc( const MissingMaterial_t& src1, + const MissingMaterial_t& src2 ) +{ + Assert( ThreadInMainThread() ); + return src1.m_Name < src2.m_Name; +} + +void CMaterialDict::Shutdown( ) +{ + Assert( ThreadInMainThread() ); + // Clean up all materials.. + RemoveAllMaterials(); + + // FIXME: Could dump list here... + if ( m_MissingList.Count() ) + DevMsg( "%s m_MissingList count: %d\n", __FUNCTION__, m_MissingList.Count() ); + m_MissingList.RemoveAll(); +} + +//----------------------------------------------------------------------------- +// Adds/removes the material to the list of all materials +//----------------------------------------------------------------------------- +void CMaterialDict::AddMaterialToMaterialList( IMaterialInternal *pMaterial ) +{ + Assert( ThreadInMainThread() ); + MaterialLookup_t lookup; + lookup.m_pMaterial = pMaterial; + lookup.m_Name = pMaterial->GetName(); + lookup.m_bManuallyCreated = pMaterial->IsManuallyCreated(); + + m_MaterialDict.Insert( lookup ); +} + +void CMaterialDict::RemoveMaterialFromMaterialList( IMaterialInternal *pMaterial ) +{ + Assert( ThreadInMainThread() ); + // Gotta iterate over this manually; name-based lookup is bogus if there are two + // materials with the same name, which can happen for procedural materials + // First remove all the subrect materials, because they'll point at their material pages. + MaterialHandle_t i; + MaterialHandle_t iNext = InvalidMaterial(); + for (i = FirstMaterial(); i != InvalidMaterial(); i = iNext ) + { + iNext = NextMaterial(i); + if ( m_MaterialDict[i].m_pMaterial == pMaterial ) + { + m_MaterialDict.RemoveAt( i ); + break; + } + } + + Assert( i != InvalidMaterial() ); + +#ifdef _DEBUG + for ( i = iNext; i != InvalidMaterial(); i = NextMaterial(i) ) + { + Assert( m_MaterialDict[i].m_pMaterial != pMaterial ); + } +#endif +} + + +//----------------------------------------------------------------------------- +// Adds, removes materials +//----------------------------------------------------------------------------- +IMaterialInternal* CMaterialDict::AddMaterial( char const* pName, const char *pTextureGroupName ) +{ + Assert( ThreadInMainThread() ); + IMaterialInternal *pMaterial = IMaterialInternal::CreateMaterial( pName, pTextureGroupName ); + Assert( pMaterial && pMaterial->IsRealTimeVersion() ); + AddMaterialToMaterialList( pMaterial ); + return pMaterial; +} + +void CMaterialDict::RemoveMaterial( IMaterialInternal* pMaterial ) +{ + Assert( ThreadInMainThread() ); + Assert( (pMaterial == NULL) || pMaterial->IsRealTimeVersion() ); + RemoveMaterialFromMaterialList( pMaterial ); +} + +IMaterialInternal *CMaterialDict::AddMaterialSubRect( const char *pName, const char *pTextureGroupName, KeyValues *pKeyValues, KeyValues *pPatchKeyValues ) +{ + Assert( ThreadInMainThread() ); + IMaterialInternal *pMaterial = IMaterialInternal::CreateMaterialSubRect( pName, pTextureGroupName, pKeyValues, pPatchKeyValues, true ); + Assert( pMaterial ); + AddMaterialToMaterialList( pMaterial ); + return pMaterial; +} + +void CMaterialDict::RemoveMaterialSubRect( IMaterialInternal *pMaterial ) +{ + Assert( ThreadInMainThread() ); + RemoveMaterialFromMaterialList( pMaterial ); + IMaterialInternal::DestroyMaterialSubRect( pMaterial ); +} + +void CMaterialDict::RemoveMaterialFromMaterialList( MaterialHandle_t h ) +{ + Assert( ThreadInMainThread() ); + m_MaterialDict.RemoveAt( h ); +} + +void CMaterialDict::RemoveAllMaterialsFromMaterialList() +{ + Assert( ThreadInMainThread() ); + m_MaterialDict.RemoveAll(); +} + +void CMaterialDict::RemoveAllMaterials() +{ + Assert( ThreadInMainThread() ); + + // First remove all the subrect materials, because they'll point at their material pages. + MaterialHandle_t i, iNext; + for (i = FirstMaterial(); i != InvalidMaterial(); i = iNext ) + { + iNext = NextMaterial(i); + IMaterialInternal *pMaterial = GetMaterialInternal( i ); + if ( pMaterial->InMaterialPage() ) + { + IMaterialInternal::DestroyMaterialSubRect( pMaterial ); + RemoveMaterialFromMaterialList( i ); + } + } + + // Now get rid of the rest of the materials, including the pages. + for (i = FirstMaterial(); i != InvalidMaterial(); i = NextMaterial(i) ) + { + IMaterialInternal::DestroyMaterial( GetMaterialInternal( i ) ); + } + + RemoveAllMaterialsFromMaterialList(); +} + diff --git a/materialsystem/cmaterialdict.h b/materialsystem/cmaterialdict.h new file mode 100644 index 0000000..c78d934 --- /dev/null +++ b/materialsystem/cmaterialdict.h @@ -0,0 +1,179 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//============================================================================= + +#ifndef CMATERIALDICT_H +#define CMATERIALDICT_H + +#include "tier1/utlsymbol.h" +#include "tier1/utlrbtree.h" + +#ifndef MATSYS_INTERNAL +#error "This file is private to the implementation of IMaterialSystem/IMaterialSystemInternal" +#endif + +#if defined( _WIN32 ) +#pragma once +#endif + +//----------------------------------------------------------------------------- + +class IMaterial; +class IMaterialInternal; +typedef unsigned short MaterialHandle_t; + +//----------------------------------------------------------------------------- +// Dictionary of all known materials +//----------------------------------------------------------------------------- + +class CMaterialDict +{ +public: + CMaterialDict() : + m_MaterialDict( 0, 256, MaterialLessFunc ), + m_MissingList( 0, 32, MissingMaterialLessFunc ) + { + Assert( ThreadInMainThread() ); + } + + void Shutdown(); + + int GetNumMaterials( void ) const; + + IMaterial* GetMaterial( MaterialHandle_t h ) const; + IMaterialInternal * GetMaterialInternal( MaterialHandle_t idx ) const; + + MaterialHandle_t FirstMaterial() const; + MaterialHandle_t NextMaterial( MaterialHandle_t h ) const; + MaterialHandle_t InvalidMaterial() const; + + IMaterialInternal * FindMaterial( const char *pszName, bool bManuallyCreated ) const; + + void AddMaterialToMaterialList( IMaterialInternal *pMaterial ); + void RemoveMaterialFromMaterialList( IMaterialInternal *pMaterial ); + + void RemoveMaterial( IMaterialInternal *pMaterial ); + void RemoveMaterialSubRect( IMaterialInternal *pMaterial ); + + IMaterialInternal* AddMaterial( const char* pName, const char *pTextureGroupName ); + // pKeyValues and pPatchKeyValues should come from LoadVMTFile() + IMaterialInternal* AddMaterialSubRect( const char* pName, const char *pTextureGroupName, KeyValues *pKeyValues, KeyValues *pPatchKeyValues ); + + bool NoteMissing( const char *pszName ); + +protected: /*private:*/ + void RemoveAllMaterials(); + void RemoveAllMaterialsFromMaterialList(); + void RemoveMaterialFromMaterialList( MaterialHandle_t h ); + + + // Stores a dictionary of materials, searched by name + struct MaterialLookup_t + { + IMaterialInternal* m_pMaterial; + CUtlSymbol m_Name; + bool m_bManuallyCreated; + }; + + // Stores a dictionary of missing materials to cut down on redundant warning messages + // TODO: 1) Could add a counter + // 2) Could dump to file/console at exit for exact list of missing materials + struct MissingMaterial_t + { + CUtlSymbol m_Name; + }; + + static bool MaterialLessFunc( const MaterialLookup_t& src1, + const MaterialLookup_t& src2 ); + + static bool MissingMaterialLessFunc( const MissingMaterial_t& src1, + const MissingMaterial_t& src2 ); + + CUtlRBTree< MaterialLookup_t, MaterialHandle_t > m_MaterialDict; + CUtlRBTree< MissingMaterial_t, int > m_MissingList; +}; + +//----------------------------------------------------------------------------- +// Material iteration methods +//----------------------------------------------------------------------------- +inline MaterialHandle_t CMaterialDict::FirstMaterial() const +{ + Assert( ThreadInMainThread() ); + return m_MaterialDict.FirstInorder(); +} + +inline MaterialHandle_t CMaterialDict::NextMaterial( MaterialHandle_t h ) const +{ + Assert( ThreadInMainThread() ); + return m_MaterialDict.NextInorder(h); +} + +inline int CMaterialDict::GetNumMaterials( ) const +{ + Assert( ThreadInMainThread() ); + return m_MaterialDict.Count(); +} + + +//----------------------------------------------------------------------------- +// Invalid index handle.... +//----------------------------------------------------------------------------- +inline MaterialHandle_t CMaterialDict::InvalidMaterial() const +{ + Assert( ThreadInMainThread() ); + return m_MaterialDict.InvalidIndex(); +} + + +//----------------------------------------------------------------------------- +// Handle to material +//----------------------------------------------------------------------------- +inline IMaterial* CMaterialDict::GetMaterial( MaterialHandle_t idx ) const +{ + Assert( ThreadInMainThread() ); + return m_MaterialDict[idx].m_pMaterial; +} + +inline IMaterialInternal* CMaterialDict::GetMaterialInternal( MaterialHandle_t idx ) const +{ + Assert( ThreadInMainThread() ); + Assert( (m_MaterialDict[idx].m_pMaterial == NULL) || m_MaterialDict[idx].m_pMaterial->IsRealTimeVersion() ); + return m_MaterialDict[idx].m_pMaterial; +} + +inline IMaterialInternal* CMaterialDict::FindMaterial( const char *pszName, bool bManuallyCreated ) const +{ + Assert( ThreadInMainThread() ); + MaterialLookup_t lookup; + lookup.m_Name = pszName; + lookup.m_bManuallyCreated = bManuallyCreated; // This causes the search to find only file-created materials + + MaterialHandle_t h = m_MaterialDict.Find( lookup ); + + if ( h != m_MaterialDict.InvalidIndex() ) + { + return m_MaterialDict[h].m_pMaterial; + } + + return NULL; +} + +inline bool CMaterialDict::NoteMissing( const char *pszName ) +{ + Assert( ThreadInMainThread() ); + MissingMaterial_t missing; + missing.m_Name = pszName; + if ( m_MissingList.Find( missing ) != m_MissingList.InvalidIndex() ) + { + return false; + } + + m_MissingList.Insert( missing ); + return true; +} + +//----------------------------------------------------------------------------- + +#endif // CMATERIALDICT_H diff --git a/materialsystem/cmaterialsystem.cpp b/materialsystem/cmaterialsystem.cpp new file mode 100644 index 0000000..3d19a16 --- /dev/null +++ b/materialsystem/cmaterialsystem.cpp @@ -0,0 +1,5547 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//===========================================================================// + +#include "pch_materialsystem.h" + +#define MATSYS_INTERNAL + +#include "cmaterialsystem.h" + +#include "colorspace.h" +#include "materialsystem/materialsystem_config.h" +#include "IHardwareConfigInternal.h" +#include "shadersystem.h" +#include "texturemanager.h" +#include "shaderlib/ShaderDLL.h" +#include "tier1/callqueue.h" +#include "vstdlib/jobthread.h" +#include "cmatnullrendercontext.h" +#include "filesystem/IQueuedLoader.h" +#include "datacache/idatacache.h" +#include "materialsystem/imaterialproxy.h" +#include "vstdlib/IKeyValuesSystem.h" +#include "ctexturecompositor.h" + +#if defined( _X360 ) +#include "xbox/xbox_console.h" +#include "xbox/xbox_win32stubs.h" +#endif + +// NOTE: This must be the last file included!!! +#include "tier0/memdbgon.h" + +#ifdef POSIX +#define _finite finite +#endif + +// this is hooked into the engines convar +ConVar mat_debugalttab( "mat_debugalttab", "0", FCVAR_CHEAT ); + +ConVar mat_forcemanagedtextureintohardware( "mat_forcemanagedtextureintohardware", "1", FCVAR_HIDDEN | FCVAR_ALLOWED_IN_COMPETITIVE ); + +ConVar mat_supportflashlight( "mat_supportflashlight", "-1", FCVAR_HIDDEN, "0 - do not support flashlight (don't load flashlight shader combos), 1 - flashlight is supported" ); +#ifdef OSX +#define CV_FRAME_SWAP_WORKAROUND_DEFAULT "1" +#else +#define CV_FRAME_SWAP_WORKAROUND_DEFAULT "0" +#endif +ConVar mat_texture_reload_frame_swap_workaround( "mat_texture_reload_frame_swap_workaround", CV_FRAME_SWAP_WORKAROUND_DEFAULT, FCVAR_INTERNAL_USE, + "Workaround certain GL drivers holding unnecessary amounts of data when loading many materials by forcing synthetic frame swaps" ); + +// This ConVar allows us to skip ~40% of our map load time, but it doesn't work on GPUs older +// than ~2005. We set it automatically and don't expose it to players. +ConVar mat_requires_rt_alloc_first( "mat_requires_rt_alloc_first", "0", FCVAR_HIDDEN ); + +// Make sure this convar gets created before videocfg.lib is initialized, so it can be driven by dxsupport.cfg +static ConVar mat_tonemapping_occlusion_use_stencil( "mat_tonemapping_occlusion_use_stencil", "0" ); + +#ifdef DX_TO_GL_ABSTRACTION +// In GL mode, we currently require mat_dxlevel to be between 90-92 +static ConVar mat_dxlevel( "mat_dxlevel", "92", 0, "", true, 90, true, 92, NULL ); +#else +static ConVar mat_dxlevel( "mat_dxlevel", "0", 0, "Current DirectX Level. Competitive play requires at least mat_dxlevel 90", false, 0, false, 0, true, 90, false, 0, NULL ); +#endif + +IMaterialInternal *g_pErrorMaterial = NULL; + +CreateInterfaceFn g_fnMatSystemConnectCreateInterface = NULL; + +static int ReadListFromFile(CUtlVector* outReplacementMaterials, const char *pszPathName); + +//#define PERF_TESTING 1 + +//----------------------------------------------------------------------------- +// Implementational structures +//----------------------------------------------------------------------------- + + +//----------------------------------------------------------------------------- +// Singleton instance exposed to the engine +//----------------------------------------------------------------------------- + +CMaterialSystem g_MaterialSystem; +EXPOSE_SINGLE_INTERFACE_GLOBALVAR( CMaterialSystem, IMaterialSystem, + MATERIAL_SYSTEM_INTERFACE_VERSION, g_MaterialSystem ); + +// Expose this to the external shader DLLs +MaterialSystem_Config_t g_config; +EXPOSE_SINGLE_INTERFACE_GLOBALVAR( MaterialSystem_Config_t, MaterialSystem_Config_t, MATERIALSYSTEM_CONFIG_VERSION, g_config ); + +//----------------------------------------------------------------------------- + +CThreadFastMutex g_MatSysMutex; + +//----------------------------------------------------------------------------- +// Purpose: additional materialsystem information, internal use only +//----------------------------------------------------------------------------- +#ifndef _X360 +struct MaterialSystem_Config_Internal_t +{ + int r_waterforceexpensive; +}; +MaterialSystem_Config_Internal_t g_config_internal; +#endif + +//----------------------------------------------------------------------------- +// Necessary to allow the shader DLLs to get ahold of IMaterialSystemHardwareConfig +//----------------------------------------------------------------------------- +IHardwareConfigInternal* g_pHWConfig = 0; +static void *GetHardwareConfig() +{ + if ( g_pHWConfig ) + return (IMaterialSystemHardwareConfig*)g_pHWConfig; + + // can't call QueryShaderAPI here because it calls a factory function + // and we end up in an infinite recursion + return NULL; +} +EXPOSE_INTERFACE_FN( GetHardwareConfig, IMaterialSystemHardwareConfig, MATERIALSYSTEM_HARDWARECONFIG_INTERFACE_VERSION ); + + +//----------------------------------------------------------------------------- +// Necessary to allow the shader DLLs to get ahold of ICvar +//----------------------------------------------------------------------------- +static void *GetICVar() +{ + return g_pCVar; +} +EXPOSE_INTERFACE_FN( GetICVar, ICVar, CVAR_INTERFACE_VERSION ); + +//----------------------------------------------------------------------------- +// Accessor to get at the material system +//----------------------------------------------------------------------------- +IMaterialSystemInternal *g_pInternalMaterialSystem = &g_MaterialSystem; +IShaderUtil *g_pShaderUtil = &g_MaterialSystem; + +#if defined(USE_SDL) +#include "appframework/ilaunchermgr.h" +ILauncherMgr *g_pLauncherMgr = NULL; // set in CMaterialSystem::Connect +#endif + +//----------------------------------------------------------------------------- +// Factory used to get at internal interfaces (used by shaderapi + shader dlls) +//----------------------------------------------------------------------------- +void *ShaderFactory( const char *pName, int *pReturnCode ) +{ + if (pReturnCode) + { + *pReturnCode = IFACE_OK; + } + + if ( !Q_stricmp( pName, FILESYSTEM_INTERFACE_VERSION )) + return g_pFullFileSystem; + + if ( !Q_stricmp( pName, QUEUEDLOADER_INTERFACE_VERSION )) + return g_pQueuedLoader; + + if ( !Q_stricmp( pName, SHADER_UTIL_INTERFACE_VERSION )) + return g_pShaderUtil; + +#ifdef USE_SDL + if ( !Q_stricmp( pName, "SDLMgrInterface001" /*SDLMGR_INTERFACE_VERSION*/ )) + return g_pLauncherMgr; +#endif + + void * pInterface = g_MaterialSystem.QueryInterface( pName ); + if ( pInterface ) + return pInterface; + + if ( pReturnCode ) + { + *pReturnCode = IFACE_FAILED; + } + return NULL; +} + +//----------------------------------------------------------------------------- +// Resource preloading for materials. +//----------------------------------------------------------------------------- +class CResourcePreloadMaterial : public CResourcePreload +{ + virtual bool CreateResource( const char *pName ) + { + IMaterial *pMaterial = g_MaterialSystem.FindMaterial( pName, TEXTURE_GROUP_WORLD, false ); + IMaterialInternal *pMatInternal = static_cast< IMaterialInternal * >( pMaterial ); + if ( pMatInternal ) + { + // always work with the realtime material internally + pMatInternal = pMatInternal->GetRealTimeVersion(); + + // tag these for later identification (prevents an unwanted purge) + pMatInternal->MarkAsPreloaded( true ); + if ( !pMatInternal->IsErrorMaterial() ) + { + // force material's textures to create now + pMatInternal->Precache(); + return true; + } + else + { + if ( IsPosix() ) + { + printf("\n ##### CResourcePreloadMaterial::CreateResource can't find material %s\n", pName); + } + } + } + + return false; + } + + //----------------------------------------------------------------------------- + // Called before queued loader i/o jobs are actually performed. Must free up memory + // to ensure i/o requests have enough memory to succeed. The materials that were + // touched by the CreateResource() are inhibited from purging (as is their textures, + // by virtue of ref counts), all others are candidates. The preloaded materials + // are by definition zero ref'd until owned by the normal loading process. Any material + // that stays zero ref'd is a candidate for the post load purge. + //----------------------------------------------------------------------------- + virtual void PurgeUnreferencedResources() + { + bool bSpew = ( g_pQueuedLoader->GetSpewDetail() & LOADER_DETAIL_PURGES ) != 0; + + bool bDidUncacheMaterial = false; + MaterialHandle_t hNext; + for ( MaterialHandle_t hMaterial = g_MaterialSystem.FirstMaterial(); hMaterial != g_MaterialSystem.InvalidMaterial(); hMaterial = hNext ) + { + hNext = g_MaterialSystem.NextMaterial( hMaterial ); + + IMaterialInternal *pMatInternal = g_MaterialSystem.GetMaterialInternal( hMaterial ); + Assert( pMatInternal->GetReferenceCount() >= 0 ); + + // preloaded materials are safe from this pre-purge + if ( !pMatInternal->IsPreloaded() ) + { + // undo any possible artifical ref count + pMatInternal->ArtificialRelease(); + if ( pMatInternal->GetReferenceCount() <= 0 ) + { + if ( bSpew ) + { + Msg( "CResourcePreloadMaterial: Purging: %s (%d)\n", pMatInternal->GetName(), pMatInternal->GetReferenceCount() ); + } + bDidUncacheMaterial = true; + pMatInternal->Uncache(); + pMatInternal->DeleteIfUnreferenced(); + } + } + else + { + // clear the bit + pMatInternal->MarkAsPreloaded( false ); + } + } + + // purged materials unreference their textures + // purge any zero ref'd textures + TextureManager()->RemoveUnusedTextures(); + + // fixup any excluded textures, may cause some new batch requests + MaterialSystem()->UpdateExcludedTextures(); + } + + virtual void PurgeAll() + { + bool bSpew = ( g_pQueuedLoader->GetSpewDetail() & LOADER_DETAIL_PURGES ) != 0; + + bool bDidUncacheMaterial = false; + MaterialHandle_t hNext; + for ( MaterialHandle_t hMaterial = g_MaterialSystem.FirstMaterial(); hMaterial != g_MaterialSystem.InvalidMaterial(); hMaterial = hNext ) + { + hNext = g_MaterialSystem.NextMaterial( hMaterial ); + + IMaterialInternal *pMatInternal = g_MaterialSystem.GetMaterialInternal( hMaterial ); + Assert( pMatInternal->GetReferenceCount() >= 0 ); + + pMatInternal->MarkAsPreloaded( false ); + // undo any possible artifical ref count + pMatInternal->ArtificialRelease(); + if ( pMatInternal->GetReferenceCount() <= 0 ) + { + if ( bSpew ) + { + Msg( "CResourcePreloadMaterial: Purging: %s (%d)\n", pMatInternal->GetName(), pMatInternal->GetReferenceCount() ); + } + bDidUncacheMaterial = true; + pMatInternal->Uncache(); + pMatInternal->DeleteIfUnreferenced(); + } + } + + // purged materials unreference their textures + // purge any zero ref'd textures + TextureManager()->RemoveUnusedTextures(); + } +}; + +static CResourcePreloadMaterial s_ResourcePreloadMaterial; + +//----------------------------------------------------------------------------- +// Resource preloading for cubemaps. +//----------------------------------------------------------------------------- +class CResourcePreloadCubemap : public CResourcePreload +{ + virtual bool CreateResource( const char *pName ) + { + ITexture *pTexture = g_MaterialSystem.FindTexture( pName, TEXTURE_GROUP_CUBE_MAP, true ); + ITextureInternal *pTexInternal = static_cast< ITextureInternal * >( pTexture ); + if ( pTexInternal ) + { + // There can be cubemaps that are unbound by materials. To prevent an unwanted purge, + // mark and increase the ref count. Otherwise the pre-purge discards these zero + // ref'd textures, and then the normal loading process hitches on the miss. + // The zombie cubemaps DO get discarded after the normal loading process completes + // if no material references them. + pTexInternal->MarkAsPreloaded( true ); + pTexInternal->IncrementReferenceCount(); + if ( !IsErrorTexture( pTexInternal ) ) + { + return true; + } + } + return false; + } + + //----------------------------------------------------------------------------- + // All valid cubemaps should have been owned by their materials. Undo the preloaded + // cubemap locks. Any zero ref'd cubemaps will be purged by the normal loading path conclusion. + //----------------------------------------------------------------------------- + virtual void OnEndMapLoading( bool bAbort ) + { + int iIndex = -1; + for ( ;; ) + { + ITextureInternal *pTexInternal; + iIndex = TextureManager()->FindNext( iIndex, &pTexInternal ); + if ( iIndex == -1 || !pTexInternal ) + { + // end of list + break; + } + + if ( pTexInternal->IsPreloaded() ) + { + // undo the artificial increase + pTexInternal->MarkAsPreloaded( false ); + pTexInternal->DecrementReferenceCount(); + } + } + } +}; +static CResourcePreloadCubemap s_ResourcePreloadCubemap; + +//----------------------------------------------------------------------------- +// Creates the debugging materials +//----------------------------------------------------------------------------- +void CMaterialSystem::CreateDebugMaterials() +{ + if ( !m_pDrawFlatMaterial ) + { + KeyValues *pVMTKeyValues = new KeyValues( "UnlitGeneric" ); + pVMTKeyValues->SetInt( "$model", 1 ); + pVMTKeyValues->SetFloat( "$decalscale", 0.05f ); + pVMTKeyValues->SetString( "$basetexture", "error" ); // This is the "error texture" + g_pErrorMaterial = static_cast(CreateMaterial( "___error.vmt", pVMTKeyValues ))->GetRealTimeVersion(); + + pVMTKeyValues = new KeyValues( "UnlitGeneric" ); + pVMTKeyValues->SetInt( "$flat", 1 ); + pVMTKeyValues->SetInt( "$vertexcolor", 1 ); + m_pDrawFlatMaterial = static_cast(CreateMaterial( "___flat.vmt", pVMTKeyValues ))->GetRealTimeVersion(); + + pVMTKeyValues = new KeyValues( "BufferClearObeyStencil" ); + pVMTKeyValues->SetInt( "$nocull", 1 ); + m_pBufferClearObeyStencil[BUFFER_CLEAR_NONE] = static_cast(CreateMaterial( "___buffer_clear_obey_stencil0.vmt", pVMTKeyValues ))->GetRealTimeVersion(); + + pVMTKeyValues = new KeyValues( "BufferClearObeyStencil" ); + pVMTKeyValues->SetInt( "$nocull", 1 ); + pVMTKeyValues->SetInt( "$clearcolor", 1 ); + pVMTKeyValues->SetInt( "$vertexcolor", 1 ); + m_pBufferClearObeyStencil[BUFFER_CLEAR_COLOR] = static_cast(CreateMaterial( "___buffer_clear_obey_stencil1.vmt", pVMTKeyValues ))->GetRealTimeVersion(); + + pVMTKeyValues = new KeyValues( "BufferClearObeyStencil" ); + pVMTKeyValues->SetInt( "$nocull", 1 ); + pVMTKeyValues->SetInt( "$clearalpha", 1 ); + pVMTKeyValues->SetInt( "$vertexcolor", 1 ); + m_pBufferClearObeyStencil[BUFFER_CLEAR_ALPHA] = static_cast(CreateMaterial( "___buffer_clear_obey_stencil2.vmt", pVMTKeyValues ))->GetRealTimeVersion(); + + pVMTKeyValues = new KeyValues( "BufferClearObeyStencil" ); + pVMTKeyValues->SetInt( "$nocull", 1 ); + pVMTKeyValues->SetInt( "$clearcolor", 1 ); + pVMTKeyValues->SetInt( "$clearalpha", 1 ); + pVMTKeyValues->SetInt( "$vertexcolor", 1 ); + m_pBufferClearObeyStencil[BUFFER_CLEAR_COLOR_AND_ALPHA] = static_cast(CreateMaterial( "___buffer_clear_obey_stencil3.vmt", pVMTKeyValues ))->GetRealTimeVersion(); + + pVMTKeyValues = new KeyValues( "BufferClearObeyStencil" ); + pVMTKeyValues->SetInt( "$nocull", 1 ); + pVMTKeyValues->SetInt( "$cleardepth", 1 ); + m_pBufferClearObeyStencil[BUFFER_CLEAR_DEPTH] = static_cast(CreateMaterial( "___buffer_clear_obey_stencil4.vmt", pVMTKeyValues ))->GetRealTimeVersion(); + + pVMTKeyValues = new KeyValues( "BufferClearObeyStencil" ); + pVMTKeyValues->SetInt( "$nocull", 1 ); + pVMTKeyValues->SetInt( "$cleardepth", 1 ); + pVMTKeyValues->SetInt( "$clearcolor", 1 ); + pVMTKeyValues->SetInt( "$vertexcolor", 1 ); + m_pBufferClearObeyStencil[BUFFER_CLEAR_COLOR_AND_DEPTH] = static_cast(CreateMaterial( "___buffer_clear_obey_stencil5.vmt", pVMTKeyValues ))->GetRealTimeVersion(); + + pVMTKeyValues = new KeyValues( "BufferClearObeyStencil" ); + pVMTKeyValues->SetInt( "$nocull", 1 ); + pVMTKeyValues->SetInt( "$cleardepth", 1 ); + pVMTKeyValues->SetInt( "$clearalpha", 1 ); + pVMTKeyValues->SetInt( "$vertexcolor", 1 ); + m_pBufferClearObeyStencil[BUFFER_CLEAR_ALPHA_AND_DEPTH] = static_cast(CreateMaterial( "___buffer_clear_obey_stencil6.vmt", pVMTKeyValues ))->GetRealTimeVersion(); + + pVMTKeyValues = new KeyValues( "BufferClearObeyStencil" ); + pVMTKeyValues->SetInt( "$nocull", 1 ); + pVMTKeyValues->SetInt( "$cleardepth", 1 ); + pVMTKeyValues->SetInt( "$clearcolor", 1 ); + pVMTKeyValues->SetInt( "$clearalpha", 1 ); + pVMTKeyValues->SetInt( "$vertexcolor", 1 ); + m_pBufferClearObeyStencil[BUFFER_CLEAR_COLOR_AND_ALPHA_AND_DEPTH] = static_cast(CreateMaterial( "___buffer_clear_obey_stencil7.vmt", pVMTKeyValues ))->GetRealTimeVersion(); + + if ( IsX360() ) + { + pVMTKeyValues = new KeyValues( "RenderTargetBlit_X360" ); + m_pRenderTargetBlitMaterial = static_cast(CreateMaterial( "___renderTargetBlit.vmt", pVMTKeyValues ))->GetRealTimeVersion(); + } + + ShaderSystem()->CreateDebugMaterials(); + } +} + +//----------------------------------------------------------------------------- +// Creates compositor materials +//----------------------------------------------------------------------------- +void CMaterialSystem::CreateCompositorMaterials() +{ + // precache composite materials + for ( int i = ECO_FirstPrecacheMaterial; i < ECO_LastPrecacheMaterial; i++ ) + { + const char *pszMaterial = GetCombinedMaterialName( ( ECombineOperation ) i ); + if ( pszMaterial[ 0 ] == '\0' ) + continue; + + IMaterialInternal *pMatqf = assert_cast< IMaterialInternal* >( FindMaterial( pszMaterial, TEXTURE_GROUP_RUNTIME_COMPOSITE ) ); + Assert( pMatqf ); + Assert( !pMatqf->IsErrorMaterial() ); + IMaterialInternal *pMatrt = pMatqf->GetRealTimeVersion(); + Assert( pMatrt ); + pMatrt->IncrementReferenceCount(); // Hold a ref. + + m_pCompositorMaterials.AddToTail( pMatrt ); + } + +} + +//----------------------------------------------------------------------------- +// Cleanup compositor materials +//----------------------------------------------------------------------------- +void CMaterialSystem::CleanUpCompositorMaterials() +{ + FOR_EACH_VEC( m_pCompositorMaterials, i ) + { + if ( m_pCompositorMaterials[ i ] == NULL ) + continue; + + m_pCompositorMaterials[ i ]->DecrementReferenceCount(); + RemoveMaterial( m_pCompositorMaterials[ i ] ); + } + + m_pCompositorMaterials.RemoveAll(); +} + +//----------------------------------------------------------------------------- +// Creates the debugging materials +//----------------------------------------------------------------------------- +void CMaterialSystem::CleanUpDebugMaterials() +{ + if ( m_pDrawFlatMaterial ) + { + m_pDrawFlatMaterial->DecrementReferenceCount(); + RemoveMaterial( m_pDrawFlatMaterial ); + m_pDrawFlatMaterial = NULL; + + for ( int i = BUFFER_CLEAR_NONE; i < BUFFER_CLEAR_TYPE_COUNT; ++i ) + { + m_pBufferClearObeyStencil[i]->DecrementReferenceCount(); + RemoveMaterial( m_pBufferClearObeyStencil[i] ); + m_pBufferClearObeyStencil[i] = NULL; + } + + if ( IsX360() ) + { + m_pRenderTargetBlitMaterial->DecrementReferenceCount(); + RemoveMaterial( m_pRenderTargetBlitMaterial ); + m_pRenderTargetBlitMaterial = NULL; + } + + ShaderSystem()->CleanUpDebugMaterials(); + } +} + + +void CMaterialSystem::CleanUpErrorMaterial() +{ + // Destruction of g_pErrorMaterial is deferred until after CMaterialDict::Shutdown. + // The global g_pErrorMaterial is set to NULL so that IsErrorMaterial() will return false and + // RemoveMaterial() / DestroyMaterial() will delete it. + IMaterialInternal *pErrorMaterial = g_pErrorMaterial; + g_pErrorMaterial = NULL; + pErrorMaterial->DecrementReferenceCount(); + RemoveMaterial( pErrorMaterial ); +} + +//----------------------------------------------------------------------------- +// Constructor +//----------------------------------------------------------------------------- +CMaterialSystem::CMaterialSystem() +{ + m_nRenderThreadID = 0xFFFFFFFF; + m_hAsyncLoadFileCache = NULL; + m_ShaderHInst = 0; + m_pMaterialProxyFactory = NULL; + m_nAdapter = 0; + m_nAdapterFlags = 0; + m_bRequestedEditorMaterials = false; + m_bCanUseEditorMaterials = false; + m_StandardTexturesAllocated = false; + m_bInFrame = false; + m_bThreadHasOwnership = false; + m_ThreadOwnershipID = 0; + m_pShaderDLL = NULL; + m_FullbrightLightmapTextureHandle = INVALID_SHADERAPI_TEXTURE_HANDLE; + m_FullbrightBumpedLightmapTextureHandle = INVALID_SHADERAPI_TEXTURE_HANDLE; + m_BlackTextureHandle = INVALID_SHADERAPI_TEXTURE_HANDLE; + m_FlatNormalTextureHandle = INVALID_SHADERAPI_TEXTURE_HANDLE; + m_GreyTextureHandle = INVALID_SHADERAPI_TEXTURE_HANDLE; + m_GreyAlphaZeroTextureHandle = INVALID_SHADERAPI_TEXTURE_HANDLE; + m_WhiteTextureHandle = INVALID_SHADERAPI_TEXTURE_HANDLE; + m_LinearToGammaTableTextureHandle = INVALID_SHADERAPI_TEXTURE_HANDLE; + m_LinearToGammaIdentityTableTextureHandle = INVALID_SHADERAPI_TEXTURE_HANDLE; + m_MaxDepthTextureHandle = INVALID_SHADERAPI_TEXTURE_HANDLE; + + m_bInStubMode = false; + m_pForcedTextureLoadPathID = NULL; + m_bAllocatingRenderTargets = false; + m_pRenderContext.Set( &m_HardwareRenderContext ); + m_iCurQueuedContext = 0; +#if defined(DEDICATED) + m_bThreadingNotAvailable = true; + m_bForcedSingleThreaded = true; + m_bAllowQueuedRendering = false; +#else + m_bThreadingNotAvailable = false; + m_bForcedSingleThreaded = false; + m_bAllowQueuedRendering = true; +#endif + m_bGeneratedConfig = false; + m_pActiveAsyncJob = NULL; + m_pMatQueueThreadPool = NULL; + m_IdealThreadMode = m_ThreadMode = MATERIAL_SINGLE_THREADED; + m_nServiceThread = 0; + m_nRenderTargetFrameBufferHeightOverride = m_nRenderTargetFrameBufferWidthOverride = 0; + + m_bReplacementFilesValid = false; +} + +CMaterialSystem::~CMaterialSystem() +{ + if (m_pShaderDLL) + { + delete[] m_pShaderDLL; + } +} + + +//----------------------------------------------------------------------------- +// Creates/destroys the shader implementation for the selected API +//----------------------------------------------------------------------------- +CreateInterfaceFn CMaterialSystem::CreateShaderAPI( char const* pShaderDLL ) +{ + if ( !pShaderDLL ) + return 0; + + // Clean up the old shader + DestroyShaderAPI(); + + // Load the new shader + m_ShaderHInst = Sys_LoadModule( pShaderDLL ); + + // Error loading the shader + if ( !m_ShaderHInst ) + return 0; + + // Get our class factory methods... + return Sys_GetFactory( m_ShaderHInst ); +} + +void CMaterialSystem::DestroyShaderAPI() +{ + if (m_ShaderHInst) + { + // NOTE: By unloading the library, this will destroy m_pShaderAPI + Sys_UnloadModule( m_ShaderHInst ); + g_pShaderAPI = 0; + g_pHWConfig = 0; + g_pShaderShadow = 0; + m_ShaderHInst = 0; + } +} + + +//----------------------------------------------------------------------------- +// Sets which shader we should be using. Has to be done before connect! +//----------------------------------------------------------------------------- +void CMaterialSystem::SetShaderAPI( char const *pShaderAPIDLL ) +{ + if ( m_ShaderAPIFactory ) + { + Error( "Cannot set the shader API twice!\n" ); + } + + if ( !pShaderAPIDLL ) + { + pShaderAPIDLL = "shaderapidx9"; + } + + // m_pShaderDLL is needed to spew driver info + Assert( pShaderAPIDLL ); + int len = Q_strlen( pShaderAPIDLL ) + 1; + m_pShaderDLL = new char[len]; + memcpy( m_pShaderDLL, pShaderAPIDLL, len ); + + m_ShaderAPIFactory = CreateShaderAPI( pShaderAPIDLL ); + if ( !m_ShaderAPIFactory ) + { + DestroyShaderAPI(); + } +} + + +//----------------------------------------------------------------------------- +// Connect/disconnect +//----------------------------------------------------------------------------- + +bool CMaterialSystem::Connect( CreateInterfaceFn factory ) +{ +// __stop__(); + + if ( !factory ) + return false; + + if ( !BaseClass::Connect( factory ) ) + return false; + + if ( !g_pFullFileSystem ) + { + Warning( "The material system requires the filesystem to run!\n" ); + return false; + } + + // Get at the interfaces exported by the shader DLL + g_pShaderDeviceMgr = (IShaderDeviceMgr*)m_ShaderAPIFactory( SHADER_DEVICE_MGR_INTERFACE_VERSION, 0 ); + if ( !g_pShaderDeviceMgr ) + return false; + g_pHWConfig = (IHardwareConfigInternal*)m_ShaderAPIFactory( MATERIALSYSTEM_HARDWARECONFIG_INTERFACE_VERSION, 0 ); + if ( !g_pHWConfig ) + return false; + +#if !defined(DEDICATED) +#if defined( USE_SDL ) + g_pLauncherMgr = (ILauncherMgr *)factory( "SDLMgrInterface001" /*SDL_MGR_INTERFACE_VERSION*/, NULL ); + if ( !g_pLauncherMgr ) + { + return false; + } +#endif // USE_SDL +#endif // !DEDICATED + + + // FIXME: ShaderAPI, ShaderDevice, and ShaderShadow should only come in after setting mode + g_pShaderAPI = (IShaderAPI*)m_ShaderAPIFactory( SHADERAPI_INTERFACE_VERSION, 0 ); + if ( !g_pShaderAPI ) + return false; + g_pShaderDevice = (IShaderDevice*)m_ShaderAPIFactory( SHADER_DEVICE_INTERFACE_VERSION, 0 ); + if ( !g_pShaderDevice ) + return false; + g_pShaderShadow = (IShaderShadow*)m_ShaderAPIFactory( SHADERSHADOW_INTERFACE_VERSION, 0 ); + if ( !g_pShaderShadow ) + return false; + + // Remember the factory for connect + g_fnMatSystemConnectCreateInterface = factory; + + return g_pShaderDeviceMgr->Connect( ShaderFactory ); +} + +void CMaterialSystem::Disconnect() +{ + // Forget the factory for connect + g_fnMatSystemConnectCreateInterface = NULL; + + if ( g_pShaderDeviceMgr ) + { + g_pShaderDeviceMgr->Disconnect(); + g_pShaderDeviceMgr = NULL; + + // Unload the DLL + DestroyShaderAPI(); + } + g_pShaderAPI = NULL; + g_pHWConfig = NULL; + g_pShaderShadow = NULL; + g_pShaderDevice = NULL; + BaseClass::Disconnect(); +} + + +//----------------------------------------------------------------------------- +// Used to enable editor materials. Must be called before Init. +//----------------------------------------------------------------------------- +void CMaterialSystem::EnableEditorMaterials() +{ + m_bRequestedEditorMaterials = true; +} + + +//----------------------------------------------------------------------------- +// Method to get at interfaces supported by the SHADDERAPI +//----------------------------------------------------------------------------- +void *CMaterialSystem::QueryShaderAPI( const char *pInterfaceName ) +{ + // Returns various interfaces supported by the shader API dll + void *pInterface = NULL; + if (m_ShaderAPIFactory) + { + pInterface = m_ShaderAPIFactory( pInterfaceName, NULL ); + } + return pInterface; +} + + +//----------------------------------------------------------------------------- +// Method to get at different interfaces supported by the material system +//----------------------------------------------------------------------------- +void *CMaterialSystem::QueryInterface( const char *pInterfaceName ) +{ + // Returns various interfaces supported by the shader API dll + void *pInterface = QueryShaderAPI( pInterfaceName ); + if ( pInterface ) + return pInterface; + + CreateInterfaceFn factory = Sys_GetFactoryThis(); // This silly construction is necessary + return factory( pInterfaceName, NULL ); // to prevent the LTCG compiler from crashing. +} + + +//----------------------------------------------------------------------------- +// Must be called before Init(), if you're going to call it at all... +//----------------------------------------------------------------------------- +void CMaterialSystem::SetAdapter( int nAdapter, int nAdapterFlags ) +{ + m_nAdapter = nAdapter; + m_nAdapterFlags = nAdapterFlags; +} + + +//----------------------------------------------------------------------------- +// Initializes the color correction terms +//----------------------------------------------------------------------------- +void CMaterialSystem::InitColorCorrection( ) +{ + if ( ColorCorrectionSystem() ) + { + ColorCorrectionSystem()->Init(); + } +} + +//----------------------------------------------------------------------------- +// Initialization + shutdown of the material system +//----------------------------------------------------------------------------- +InitReturnVal_t CMaterialSystem::Init() +{ + InitReturnVal_t nRetVal = BaseClass::Init(); + if ( nRetVal != INIT_OK ) + return nRetVal; + + // NOTE! : Overbright is 1.0 so that Hammer will work properly with the white bumped and unbumped lightmaps. + MathLib_Init( 2.2f, 2.2f, 0.0f, 2.0f ); + + g_pShaderDeviceMgr->SetAdapter( m_nAdapter, m_nAdapterFlags ); + if ( g_pShaderDeviceMgr->Init( ) != INIT_OK ) + { + DestroyShaderAPI(); + return INIT_FAILED; + } + + // Texture manager... + TextureManager()->Init( m_nAdapterFlags ); + + // Shader system! + ShaderSystem()->Init(); + +#if defined( WIN32 ) && !defined( _X360 ) + // HACKHACK: This horrible hack is possibly the only way to reliably detect an old + // version of hammer initializing the material system. We need to know this so that we set + // up the editor materials properly. If we don't do this, we never allocate the white lightmap, + // for example. We can remove this when we update the SDK!! + char szExeName[_MAX_PATH]; + if ( ::GetModuleFileName( ( HINSTANCE )GetModuleHandle( NULL ), szExeName, sizeof( szExeName ) ) ) + { + char szRight[20]; + Q_StrRight( szExeName, 11, szRight, sizeof( szRight ) ); + if ( !Q_stricmp( szRight, "\\hammer.exe" ) ) + { + m_bRequestedEditorMaterials = true; + } + } +#endif // WIN32 + + m_bCanUseEditorMaterials = m_bRequestedEditorMaterials; + + InitColorCorrection(); + + // Set up debug materials... + CreateDebugMaterials(); + +#if !defined(DEDICATED) + CreateCompositorMaterials(); +#endif + + if ( IsX360() ) + { + g_pQueuedLoader->InstallLoader( RESOURCEPRELOAD_MATERIAL, &s_ResourcePreloadMaterial ); + g_pQueuedLoader->InstallLoader( RESOURCEPRELOAD_CUBEMAP, &s_ResourcePreloadCubemap ); + } + + // Set up a default material system config +// GenerateConfigFromConfigKeyValues( &g_config, false ); +// UpdateConfig( false ); + + // JAY: Added this command line parameter to force creating <32x32 mips + // to test for reported performance regressions on some systems + if ( CommandLine()->FindParm("-forceallmips") ) + { + extern bool g_bForceTextureAllMips; + g_bForceTextureAllMips = true; + } + +#if defined(DEDICATED) + m_bThreadingNotAvailable = true; +#else + for ( int i = 0; i < ARRAYSIZE( m_QueuedRenderContexts ); i++ ) + { + if ( !m_QueuedRenderContexts[i].IsInitialized() ) + { + if ( !m_QueuedRenderContexts[i].Init( this, &m_HardwareRenderContext ) ) + { + m_bThreadingNotAvailable = true; + break; + } + } + } +#endif + + return m_HardwareRenderContext.Init( this ); +} + +//----------------------------------------------------------------------------- +// For backwards compatability +//----------------------------------------------------------------------------- +static CreateInterfaceFn s_TempCVarFactory; +static CreateInterfaceFn s_TempFileSystemFactory; + +void* TempCreateInterface( const char *pName, int *pReturnCode ) +{ + void *pRetVal = NULL; + + if ( s_TempCVarFactory ) + { + pRetVal = s_TempCVarFactory( pName, pReturnCode ); + if (pRetVal) + return pRetVal; + } + + pRetVal = s_TempFileSystemFactory( pName, pReturnCode ); + if (pRetVal) + return pRetVal; + + return NULL; +} + + +//----------------------------------------------------------------------------- +// Initializes and shuts down the shader API +//----------------------------------------------------------------------------- +CreateInterfaceFn CMaterialSystem::Init( char const* pShaderAPIDLL, + IMaterialProxyFactory *pMaterialProxyFactory, + CreateInterfaceFn fileSystemFactory, + CreateInterfaceFn cvarFactory ) +{ + SetShaderAPI( pShaderAPIDLL ); + + s_TempCVarFactory = cvarFactory; + s_TempFileSystemFactory = fileSystemFactory; + if ( !Connect( TempCreateInterface ) ) + return 0; + + if (Init() != INIT_OK) + return NULL; + + // save the proxy factory + m_pMaterialProxyFactory = pMaterialProxyFactory; + + return m_ShaderAPIFactory; +} + +void CMaterialSystem::Shutdown( ) +{ + DestroyMatQueueThreadPool(); + + m_HardwareRenderContext.Shutdown(); + + // Clean up standard textures + ReleaseStandardTextures(); + + CleanUpCompositorMaterials(); + + // Clean up the debug materials + CleanUpDebugMaterials(); + + g_pMorphMgr->FreeMaterials(); + g_pOcclusionQueryMgr->FreeOcclusionQueryObjects(); + + GetLightmaps()->Shutdown(); + m_MaterialDict.Shutdown(); + + CleanUpErrorMaterial(); + + // Shader system! + ShaderSystem()->Shutdown(); + + // Texture manager... + TextureManager()->Shutdown(); + + if (g_pShaderDeviceMgr) + { + g_pShaderDeviceMgr->Shutdown(); + } + + BaseClass::Shutdown(); +} + +void CMaterialSystem::ModInit() +{ + // Set up a default material system config + GenerateConfigFromConfigKeyValues( &g_config, false ); + UpdateConfig( false ); + + // Shader system! + ShaderSystem()->ModInit(); +} + +void CMaterialSystem::ModShutdown() +{ + // Shader system! + ShaderSystem()->ModShutdown(); + + // HACK - this is here to unhook ourselves from the client interface, since we're not actually notified when it happens + m_pMaterialProxyFactory = NULL; +} + +//----------------------------------------------------------------------------- +// Returns the current adapter in use +//----------------------------------------------------------------------------- +IMaterialSystemHardwareConfig *CMaterialSystem::GetHardwareConfig( const char *pVersion, int *returnCode ) +{ + return ( IMaterialSystemHardwareConfig * )m_ShaderAPIFactory( pVersion, returnCode ); +} + + +//----------------------------------------------------------------------------- +// Returns the current adapter in use +//----------------------------------------------------------------------------- +int CMaterialSystem::GetCurrentAdapter() const +{ + return g_pShaderDevice->GetCurrentAdapter(); +} + + +//----------------------------------------------------------------------------- +// Returns the device name for the current adapter +//----------------------------------------------------------------------------- +char *CMaterialSystem::GetDisplayDeviceName() const +{ + return g_pShaderDevice->GetDisplayDeviceName(); +} + + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +void CMaterialSystem::SetThreadMode( MaterialThreadMode_t nextThreadMode, int nServiceThread ) +{ + m_IdealThreadMode = nextThreadMode; + m_nServiceThread = nServiceThread; +} + +MaterialThreadMode_t CMaterialSystem::GetThreadMode() +{ + return m_ThreadMode; +} + + +bool CMaterialSystem::IsRenderThreadSafe( ) +{ + return ( m_ThreadMode != MATERIAL_QUEUED_THREADED && ThreadInMainThread() ) || + ( m_ThreadMode == MATERIAL_QUEUED_THREADED && m_nRenderThreadID == ThreadGetCurrentId() ); +} + + +bool CMaterialSystem::AllowThreading( bool bAllow, int nServiceThread ) +{ +#if defined(DEDICATED) + return false; +#else + if ( CommandLine()->ParmValue( "-threads", 2 ) < 2 ) // if -threads specified on command line to restrict all the pools then obey and not turn on QMS + bAllow = false; + + bool bOldAllow = m_bAllowQueuedRendering; + + if ( GetCPUInformation()->m_nPhysicalProcessors >= 2 ) + { + m_bAllowQueuedRendering = bAllow; + bool bQueued = m_IdealThreadMode != MATERIAL_SINGLE_THREADED; + if ( bAllow && !bQueued ) + { + // go into queued mode + DevMsg( "Queued Material System: ENABLED!\n" ); + SetThreadMode( MATERIAL_QUEUED_THREADED, nServiceThread ); + } + else if ( !bAllow && bQueued ) + { + // disabling queued mode just needs to stop the queuing of drawing + // but still allow other threaded access to the Material System + // flush the queue + DevMsg( "Queued Material System: DISABLED!\n" ); + ForceSingleThreaded(); + MaterialLock_t hMaterialLock = Lock(); + SetThreadMode( MATERIAL_SINGLE_THREADED, -1 ); + Unlock( hMaterialLock ); + } + } + else + { + m_bAllowQueuedRendering = false; + } + return bOldAllow; +#endif // !DEDICATED +} +void CMaterialSystem::ExecuteQueued() +{ +} + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +IMatRenderContext *CMaterialSystem::GetRenderContext() +{ + IMatRenderContext *pResult = m_pRenderContext.Get(); + if ( !pResult ) + { + pResult = &m_HardwareRenderContext; + m_pRenderContext.Set( &m_HardwareRenderContext ); + } + return RetAddRef( pResult ); +} + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +IMatRenderContext *CMaterialSystem::CreateRenderContext( MaterialContextType_t type ) +{ + switch ( type ) + { + case MATERIAL_HARDWARE_CONTEXT: + return NULL; + + case MATERIAL_QUEUED_CONTEXT: + { + CMatQueuedRenderContext *pQueuedContext = new CMatQueuedRenderContext; + pQueuedContext->Init( this, &m_HardwareRenderContext ); + pQueuedContext->BeginQueue( &m_HardwareRenderContext ); + return pQueuedContext; + + } + + case MATERIAL_NULL_CONTEXT: + { + CMatRenderContextBase *pNullContext = CreateNullRenderContext(); + pNullContext->Init(); + pNullContext->InitializeFrom( &m_HardwareRenderContext ); + return pNullContext; + } + } + Assert(0); + return NULL; +} + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +IMatRenderContext *CMaterialSystem::SetRenderContext( IMatRenderContext *pNewContext ) +{ + IMatRenderContext *pOldContext = m_pRenderContext.Get(); + if ( pNewContext ) + { + pNewContext->AddRef(); + m_pRenderContext.Set( assert_cast(pNewContext) ); + } + else + { + m_pRenderContext.Set( NULL ); + } + return pOldContext; +} + + +//----------------------------------------------------------------------------- +// Get/Set Material proxy factory +//----------------------------------------------------------------------------- +IMaterialProxyFactory* CMaterialSystem::GetMaterialProxyFactory() +{ + return m_pMaterialProxyFactory; +} + +void CMaterialSystem::SetMaterialProxyFactory( IMaterialProxyFactory* pFactory ) +{ + // Changing the factory requires an uncaching of all materials + // since the factory may contain different proxies + UncacheAllMaterials(); + + m_pMaterialProxyFactory = pFactory; +} + + +//----------------------------------------------------------------------------- +// Can we use editor materials? +//----------------------------------------------------------------------------- +bool CMaterialSystem::CanUseEditorMaterials() const +{ + return m_bCanUseEditorMaterials; +} + + +//----------------------------------------------------------------------------- +// Methods related to mode setting... +//----------------------------------------------------------------------------- + +// Gets the number of adapters... +int CMaterialSystem::GetDisplayAdapterCount() const +{ + return g_pShaderDeviceMgr->GetAdapterCount( ); +} + +// Returns info about each adapter +void CMaterialSystem::GetDisplayAdapterInfo( int adapter, MaterialAdapterInfo_t& info ) const +{ + g_pShaderDeviceMgr->GetAdapterInfo( adapter, info ); +} + +// Returns the number of modes +int CMaterialSystem::GetModeCount( int adapter ) const +{ + return g_pShaderDeviceMgr->GetModeCount( adapter ); +} + + +//----------------------------------------------------------------------------- +// Compatability function, should go away eventually +//----------------------------------------------------------------------------- +static void ConvertModeStruct( ShaderDeviceInfo_t *pMode, const MaterialSystem_Config_t &config ) +{ + pMode->m_DisplayMode.m_nWidth = config.m_VideoMode.m_Width; + pMode->m_DisplayMode.m_nHeight = config.m_VideoMode.m_Height; + pMode->m_DisplayMode.m_Format = config.m_VideoMode.m_Format; + pMode->m_DisplayMode.m_nRefreshRateNumerator = config.m_VideoMode.m_RefreshRate; + pMode->m_DisplayMode.m_nRefreshRateDenominator = config.m_VideoMode.m_RefreshRate ? 1 : 0; + pMode->m_nBackBufferCount = 1; + pMode->m_nAASamples = config.m_nAASamples; + pMode->m_nAAQuality = config.m_nAAQuality; + pMode->m_nDXLevel = MAX( ABSOLUTE_MINIMUM_DXLEVEL, config.dxSupportLevel ); + pMode->m_nWindowedSizeLimitWidth = (int)config.m_WindowedSizeLimitWidth; + pMode->m_nWindowedSizeLimitHeight = (int)config.m_WindowedSizeLimitHeight; + + pMode->m_bWindowed = config.Windowed(); + pMode->m_bResizing = config.Resizing(); + pMode->m_bUseStencil = config.Stencil(); + pMode->m_bLimitWindowedSize = config.LimitWindowedSize(); + pMode->m_bWaitForVSync = config.WaitForVSync(); + pMode->m_bScaleToOutputResolution = config.ScaleToOutputResolution(); + pMode->m_bUsingMultipleWindows = config.UsingMultipleWindows(); +} + +static void ConvertModeStruct( MaterialVideoMode_t *pMode, const ShaderDisplayMode_t &info ) +{ + pMode->m_Width = info.m_nWidth; + pMode->m_Height = info.m_nHeight; + pMode->m_Format = info.m_Format; + pMode->m_RefreshRate = info.m_nRefreshRateDenominator ? ( info.m_nRefreshRateNumerator / info.m_nRefreshRateDenominator ) : 0; +} + + +//----------------------------------------------------------------------------- +// Returns mode information.. +//----------------------------------------------------------------------------- +void CMaterialSystem::GetModeInfo( int nAdapter, int nMode, MaterialVideoMode_t& info ) const +{ + ShaderDisplayMode_t shaderInfo; + g_pShaderDeviceMgr->GetModeInfo( &shaderInfo, nAdapter, nMode ); + ConvertModeStruct( &info, shaderInfo ); +} + + +//----------------------------------------------------------------------------- +// Returns the mode info for the current display device +//----------------------------------------------------------------------------- +void CMaterialSystem::GetDisplayMode( MaterialVideoMode_t& info ) const +{ + ShaderDisplayMode_t shaderInfo; + g_pShaderDeviceMgr->GetCurrentModeInfo( &shaderInfo, m_nAdapter ); + ConvertModeStruct( &info, shaderInfo ); +} + +void CMaterialSystem::ForceSingleThreaded() +{ + if ( !ThreadInMainThread() ) + { + Error("Can't force single thread from within thread!\n"); + } + if ( GetThreadMode() != MATERIAL_SINGLE_THREADED ) + { + if ( m_pActiveAsyncJob && !m_pActiveAsyncJob->IsFinished() ) + { + m_pActiveAsyncJob->WaitForFinish(); + } + SafeRelease( m_pActiveAsyncJob ); + + ThreadRelease(); + + g_pShaderAPI->EnableShaderShaderMutex( false ); + m_HardwareRenderContext.InitializeFrom(&m_QueuedRenderContexts[m_iCurQueuedContext]); + m_pRenderContext.Set( &m_HardwareRenderContext ); + for ( int i = 0; i < ARRAYSIZE( m_QueuedRenderContexts ); i++ ) + { + Assert( m_QueuedRenderContexts[i].IsInitialized() ); + m_QueuedRenderContexts[i].EndQueue(true); + } + if( mat_debugalttab.GetBool() ) + { + Warning("Forcing queued mode off!\n"); + } + + // NOTE: Must happen after EndQueue or proxies get bound again, which is bad. + m_ThreadMode = MATERIAL_SINGLE_THREADED; + + m_bForcedSingleThreaded = true; + } +} + +//----------------------------------------------------------------------------- +// Sets the mode... +//----------------------------------------------------------------------------- +bool CMaterialSystem::SetMode( void* hwnd, const MaterialSystem_Config_t &config ) +{ + Assert( m_bGeneratedConfig ); + + ForceSingleThreaded(); + + ShaderDeviceInfo_t info; + ConvertModeStruct( &info, config ); + + bool bPreviouslyUsingGraphics = g_pShaderDevice->IsUsingGraphics(); + if( config.m_nVRModeAdapter != -1 && config.m_nVRModeAdapter < GetDisplayAdapterCount() && !bPreviouslyUsingGraphics ) + { + // if this is init-time, we need to override the adapter with the + // VR mode adapter + m_nAdapter = config.m_nVRModeAdapter; + } + + bool bOk = g_pShaderAPI->SetMode( hwnd, m_nAdapter, info ); + if ( !bOk ) + return false; + +#if defined( USE_SDL ) + uint width = info.m_DisplayMode.m_nWidth; + uint height = info.m_DisplayMode.m_nHeight; + g_pLauncherMgr->RenderedSize( width, height, true ); // true = set +#endif + + TextureManager()->FreeStandardRenderTargets(); + TextureManager()->AllocateStandardRenderTargets(); + + // FIXME: There's gotta be a better way of doing this? + // After the first mode set, make sure to download any textures created + // before the first mode set. After the first mode set, all textures + // will be reloaded via the reaquireresources call. Same goes for procedural materials + if ( !bPreviouslyUsingGraphics ) + { + if ( IsPC() ) + { + TextureManager()->RestoreRenderTargets(); + TextureManager()->RestoreNonRenderTargetTextures(); + if ( MaterialSystem()->CanUseEditorMaterials() ) + { + // We are in Hammer. Allocate these here since we aren't going to allocate + // lightmaps. + // HACK! + // NOTE! : Overbright is 1.0 so that Hammer will work properly with the white bumped and unbumped lightmaps. + MathLib_Init( 2.2f, 2.2f, 0.0f, OVERBRIGHT ); + } + + AllocateStandardTextures(); + TextureManager()->WarmTextureCache(); + } + + if ( IsX360() ) + { + // shaderapi was not viable at init time, it is now + TextureManager()->ReloadTextures(); + AllocateStandardTextures(); + } + } + + g_pShaderDevice->SetHardwareGammaRamp( config.m_fMonitorGamma, config.m_fGammaTVRangeMin, config.m_fGammaTVRangeMax, + config.m_fGammaTVExponent, config.m_bGammaTVEnabled ); + + // Copy over that state which isn't stored currently in convars + g_config.m_VideoMode = config.m_VideoMode; + g_config.SetFlag( MATSYS_VIDCFG_FLAGS_WINDOWED, config.Windowed() ); + g_config.SetFlag( MATSYS_VIDCFG_FLAGS_STENCIL, config.Stencil() ); + g_config.SetFlag( MATSYS_VIDCFG_FLAGS_VR_MODE, config.VRMode() ); + WriteConfigIntoConVars( config ); + + extern void SetupDirtyDiskReportFunc(); + SetupDirtyDiskReportFunc(); + + return true; +} + +// Creates/ destroys a child window +bool CMaterialSystem::AddView( void* hwnd ) +{ + return g_pShaderDevice->AddView( hwnd ); +} + +void CMaterialSystem::RemoveView( void* hwnd ) +{ + g_pShaderDevice->RemoveView( hwnd ); +} + +// Activates a view +void CMaterialSystem::SetView( void* hwnd ) +{ + g_pShaderDevice->SetView( hwnd ); +} + + +//----------------------------------------------------------------------------- +// Installs a function to be called when we need to release vertex buffers +//----------------------------------------------------------------------------- +void CMaterialSystem::AddReleaseFunc( MaterialBufferReleaseFunc_t func ) +{ + // Shouldn't have two copies in our list + Assert( m_ReleaseFunc.Find( func ) == -1 ); + m_ReleaseFunc.AddToTail( func ); +} + +void CMaterialSystem::RemoveReleaseFunc( MaterialBufferReleaseFunc_t func ) +{ + int i = m_ReleaseFunc.Find( func ); + if( i != -1 ) + m_ReleaseFunc.Remove(i); +} + + +//----------------------------------------------------------------------------- +// Installs a function to be called when we need to restore vertex buffers +//----------------------------------------------------------------------------- +void CMaterialSystem::AddRestoreFunc( MaterialBufferRestoreFunc_t func ) +{ + // Shouldn't have two copies in our list + Assert( m_RestoreFunc.Find( func ) == -1 ); + m_RestoreFunc.AddToTail( func ); +} + +void CMaterialSystem::RemoveRestoreFunc( MaterialBufferRestoreFunc_t func ) +{ + int i = m_RestoreFunc.Find( func ); + Assert( i != -1 ); + m_RestoreFunc.Remove(i); +} + + +//----------------------------------------------------------------------------- +// Called by the shader API when it's just about to lose video memory +//----------------------------------------------------------------------------- +void CMaterialSystem::ReleaseShaderObjects() +{ + if( mat_debugalttab.GetBool() ) + { + Warning( "mat_debugalttab: CMaterialSystem::ReleaseShaderObjects\n" ); + } + + m_HardwareRenderContext.OnReleaseShaderObjects(); + + g_pOcclusionQueryMgr->FreeOcclusionQueryObjects(); + TextureManager()->ReleaseTextures(); + ReleaseStandardTextures(); + GetLightmaps()->ReleaseLightmapPages(); + for (int i = 0; i < m_ReleaseFunc.Count(); ++i) + { + m_ReleaseFunc[i](); + } +} + +void CMaterialSystem::RestoreShaderObjects( CreateInterfaceFn shaderFactory, int nChangeFlags ) +{ + if ( shaderFactory ) + { + g_pShaderAPI = (IShaderAPI*)shaderFactory( SHADERAPI_INTERFACE_VERSION, NULL ); + g_pShaderDevice = (IShaderDevice*)shaderFactory( SHADER_DEVICE_INTERFACE_VERSION, NULL ); + g_pShaderShadow = (IShaderShadow*)shaderFactory( SHADERSHADOW_INTERFACE_VERSION, NULL ); + } + + for( MaterialHandle_t i = m_MaterialDict.FirstMaterial(); i != m_MaterialDict.InvalidMaterial(); i = m_MaterialDict.NextMaterial( i ) ) + { + IMaterialInternal *pMat = m_MaterialDict.GetMaterialInternal( i ); + if ( pMat ) + pMat->ReportVarChanged( NULL ); + } + + + if ( mat_debugalttab.GetBool() ) + { + Warning( "mat_debugalttab: CMaterialSystem::RestoreShaderObjects\n" ); + } + // Shader API sets this to the max value the card supports when it resets + // the state, so restore this value. + g_pShaderAPI->SetAnisotropicLevel( GetCurrentConfigForVideoCard().m_nForceAnisotropicLevel ); + + // NOTE: render targets must be restored first, then vb/ibs, then managed textures + // FIXME: Gotta restore lightmap pages + standard textures before restore funcs are called + // because they use them both. + TextureManager()->RestoreRenderTargets(); + AllocateStandardTextures(); + GetLightmaps()->RestoreLightmapPages(); + g_pOcclusionQueryMgr->AllocOcclusionQueryObjects(); + for (int i = 0; i < m_RestoreFunc.Count(); ++i) + { + m_RestoreFunc[i]( nChangeFlags ); + } + TextureManager()->RestoreNonRenderTargetTextures( ); +} + + +//----------------------------------------------------------------------------- +// Use this to spew information about the 3D layer +//----------------------------------------------------------------------------- +void CMaterialSystem::SpewDriverInfo() const +{ + Warning( "ShaderAPI: %s\n", m_pShaderDLL ); + g_pShaderDevice->SpewDriverInfo(); +} + + +//----------------------------------------------------------------------------- +// Color converting blitter +//----------------------------------------------------------------------------- + +bool CMaterialSystem::ConvertImageFormat( unsigned char *src, enum ImageFormat srcImageFormat, + unsigned char *dst, enum ImageFormat dstImageFormat, + int width, int height, int srcStride, int dstStride ) +{ + return ImageLoader::ConvertImageFormat( src, srcImageFormat, + dst, dstImageFormat, width, height, srcStride, dstStride ); +} + +//----------------------------------------------------------------------------- +// Figures out the amount of memory needed by a bitmap +//----------------------------------------------------------------------------- +int CMaterialSystem::GetMemRequired( int width, int height, int depth, ImageFormat format, bool mipmap ) +{ + return ImageLoader::GetMemRequired( width, height, depth, format, mipmap ); +} + + +//----------------------------------------------------------------------------- +// Method to allow clients access to the MaterialSystem_Config +//----------------------------------------------------------------------------- +MaterialSystem_Config_t& CMaterialSystem::GetConfig() +{ +//hushed Assert( m_bGeneratedConfig ); + return g_config; +} + + +//----------------------------------------------------------------------------- +// Gets image format info +//----------------------------------------------------------------------------- +ImageFormatInfo_t const& CMaterialSystem::ImageFormatInfo( ImageFormat fmt) const +{ + return ImageLoader::ImageFormatInfo(fmt); +} + + +//----------------------------------------------------------------------------- +// Reads keyvalues for information +//----------------------------------------------------------------------------- +static void ReadInt( KeyValues *pGroup, const char *pName, int nDefaultVal, int nUndefinedVal, int *pDest ) +{ + *pDest = pGroup->GetInt( pName, nDefaultVal ); +// Warning( "\t%s = %d\n", pName, *pDest ); + Assert( *pDest != nUndefinedVal ); +} + +static void ReadFlt( KeyValues *pGroup, const char *pName, float flDefaultVal, float flUndefinedVal, float *pDest ) +{ + *pDest = pGroup->GetFloat( pName, flDefaultVal ); +// Warning( "\t%s = %f\n", pName, *pDest ); + Assert( *pDest != flUndefinedVal ); +} + +static void LoadFlags( KeyValues *pGroup, const char *pName, bool bDefaultValue, unsigned int nFlag, unsigned int *pFlags ) +{ + int nValue = pGroup->GetInt( pName, bDefaultValue ? 1 : 0 ); +// Warning( "\t%s = %s\n", pName, nValue ? "true" : "false" ); + if ( nValue ) + { + *pFlags |= nFlag; + } +} + +#define ASPECT_4x3 0 +#define ASPECT_16x9 1 +#define ASPECT_16x10 2 + + +//----------------------------------------------------------------------------- +// Purpose: aspect ratio mappings (for normal/widescreen combo) +//----------------------------------------------------------------------------- +struct RatioToAspectMode_t +{ + int nAspectCode; + float flAspectRatio; +}; + +RatioToAspectMode_t g_RatioToAspectModes[] = +{ + { ASPECT_4x3, 4.0f / 3.0f }, + { ASPECT_16x9, 16.0f / 9.0f }, + { ASPECT_16x10, 16.0f / 10.0f }, + { ASPECT_16x10, 1.0f }, +}; + +//----------------------------------------------------------------------------- +// Purpose: returns the aspect ratio mode number for the given resolution +//----------------------------------------------------------------------------- +int GetScreenAspectMode( int width, int height ) +{ + float flAspectRatio = (float)width / (float)height; + + // Just find the closest ratio + float flClosestAspectRatioDist = 99999.0f; + int nClosestAspectCode = ASPECT_4x3; + for ( int i = 0; i < ARRAYSIZE(g_RatioToAspectModes); i++ ) + { + float flDist = fabs( g_RatioToAspectModes[i].flAspectRatio - flAspectRatio ); + if ( flDist < flClosestAspectRatioDist ) + { + flClosestAspectRatioDist = flDist; + nClosestAspectCode = g_RatioToAspectModes[i].nAspectCode; + } + } + + return nClosestAspectCode; +} + + +// Heuristic similar to one we put into L4D +bool BetterResolution( int nRecommendedNumPixels, int nBestNumPixels, int nNewNumPixels ) +{ + float flRecommendedNumPixels = (float) nRecommendedNumPixels; + float flBestNumPixels = (float) nBestNumPixels; + float flNewNumPixels = (float) nNewNumPixels; + + // Give ourselves a little head room + float flTooBig = flRecommendedNumPixels * 1.1f; + + // If our best is too big and the new resolution is no bigger, pick it + if ( ( flBestNumPixels > flTooBig ) && ( flNewNumPixels < flBestNumPixels ) ) + return true; + + // Don't allow resolutions which are too big + if ( flNewNumPixels > flTooBig ) + return false; + + // Finally, just check for nearness to desired number of pixels + float flDelta = fabs( flRecommendedNumPixels - flNewNumPixels ); + float flBestDelta = fabs( flRecommendedNumPixels - flBestNumPixels ); + if ( flDelta >= flBestDelta ) + return false; + + return true; +} + + +//----------------------------------------------------------------------------- +// This is called when the config changes +//----------------------------------------------------------------------------- +void CMaterialSystem::GenerateConfigFromConfigKeyValues( MaterialSystem_Config_t *pConfig, bool bOverwriteCommandLineValues ) +{ + if ( !g_pShaderDeviceMgr || !pConfig ) + return; + + // Look for the default recommended dx support level + MaterialAdapterInfo_t adapterInfo; + g_pShaderDeviceMgr->GetAdapterInfo( m_nAdapter, adapterInfo ); + + pConfig->dxSupportLevel = MAX( ABSOLUTE_MINIMUM_DXLEVEL, adapterInfo.m_nDXSupportLevel ); + KeyValues *pKeyValues = new KeyValues( "config" ); + if ( !GetRecommendedConfigurationInfo( pConfig->dxSupportLevel, pKeyValues ) ) + { + pKeyValues->deleteThis(); + return; + } + + pConfig->m_Flags = 0; + +#ifdef LINUX + + uint width = 0; + uint height = 0; + uint refreshHz = 0; // Not used + +#ifdef USE_SDL + // query backbuffer size (window size whether FS or windowed) + if( g_pLauncherMgr ) + { + g_pLauncherMgr->GetNativeDisplayInfo( -1, width, height, refreshHz ); + } +#endif + + pConfig->m_VideoMode.m_Width = width; + pConfig->m_VideoMode.m_Height = height; + +#else + + // Get the recommended resolution from dxsupport.cfg, this assumes a 4:3 aspect ratio + int nRecommendedWidth, nRecommendedHeight; + ReadInt( pKeyValues, "DefaultRes", 640, -1, &nRecommendedWidth ); + nRecommendedHeight = ( nRecommendedWidth * 3 ) / 4; + int nRecommendedPixels = nRecommendedHeight * nRecommendedWidth; + + // Get the desktop resolution and aspect ratio + ShaderDisplayMode_t displayMode; + g_pShaderDeviceMgr->GetCurrentModeInfo( &displayMode, 0 ); + int nCurrentScreenAspect = GetScreenAspectMode( displayMode.m_nWidth, displayMode.m_nHeight ); + + // Let's see what the device supports and pick the most appropriate mode + g_pShaderDeviceMgr->GetModeInfo( &displayMode, 0, 0 ); + int nBestMode, nBestWidth, nBestHeight; + nBestMode = nBestWidth = nBestHeight = -1; + int nBestPixels = displayMode.m_nHeight * displayMode.m_nWidth; + + int nNumVideoModes = g_pShaderDeviceMgr->GetModeCount( 0 ); + + // Pick the resolution with the right aspect ratio which matches the recommended resolution most closely + for ( int i=0; iGetModeInfo( &displayMode, 0, i ); + + if ( nCurrentScreenAspect == GetScreenAspectMode( displayMode.m_nWidth, displayMode.m_nHeight ) ) + { + int nNumPixels = displayMode.m_nWidth * displayMode.m_nHeight; + + // Initially select the first mode we find of the correct aspect ratio for the display + if ( ( nBestMode == -1) || BetterResolution( nRecommendedPixels, nBestPixels, nNumPixels ) ) + { + nBestMode = i; + nBestPixels = nNumPixels; + nBestWidth = displayMode.m_nWidth; + nBestHeight = displayMode.m_nHeight; + } + } + } + + // We found a good mode + if ( nBestMode != -1 ) + { + pConfig->m_VideoMode.m_Width = nBestWidth; + pConfig->m_VideoMode.m_Height = nBestHeight; + } + else // Fall back to 4:3 mode from the cfg file. This should never happen + { + pConfig->m_VideoMode.m_Width = nRecommendedWidth; + pConfig->m_VideoMode.m_Height = nRecommendedHeight; + } + +#if defined( _X360 ) + pConfig->m_VideoMode.m_Width = GetSystemMetrics( SM_CXSCREEN ); + pConfig->m_VideoMode.m_Height = GetSystemMetrics( SM_CYSCREEN ); +#endif + + pKeyValues->deleteThis(); + +#endif // LINUX + + WriteConfigurationInfoToConVars( bOverwriteCommandLineValues ); + m_bGeneratedConfig = true; +} + +//----------------------------------------------------------------------------- +// If mat_proxy goes to 0, we need to reload all materials, because their shader +// params might have been messed with. +//----------------------------------------------------------------------------- +static void MatProxyCallback( IConVar *pConVar, const char *old, float flOldValue ) +{ + ConVarRef var( pConVar ); + int oldVal = (int)flOldValue; + if ( var.GetInt() == 0 && oldVal != 0 ) + { + g_MaterialSystem.ReloadMaterials(); + } +} + + +//----------------------------------------------------------------------------- +// Convars that control the config record +//----------------------------------------------------------------------------- +static ConVar mat_vsync( "mat_vsync", "0", FCVAR_ALLOWED_IN_COMPETITIVE, "Force sync to vertical retrace", true, 0.0, true, 1.0 ); +static ConVar mat_forcehardwaresync( "mat_forcehardwaresync", IsPC() ? "1" : "0", FCVAR_ALLOWED_IN_COMPETITIVE ); + +// Texture-related +static ConVar mat_trilinear( "mat_trilinear", "0", FCVAR_ALLOWED_IN_COMPETITIVE ); +#ifdef _X360 // The code that reads this out of moddefaults.txt is #if'd out for the 360, so force aniso to 2 here. + static ConVar mat_forceaniso( "mat_forceaniso", "2", FCVAR_ARCHIVE ); // 0 = Bilinear, 1 = Trilinear, 2+ = Aniso +#elif defined ( OSX ) + static ConVar mat_forceaniso( "mat_forceaniso", "1", FCVAR_ARCHIVE, "Filtering level", true, 0, true, 8 ); // 0 = Bilinear, 1 = Trilinear, 2+ = Aniso +#else + static ConVar mat_forceaniso( "mat_forceaniso", "1", FCVAR_ARCHIVE ); // 0 = Bilinear, 1 = Trilinear, 2+ = Aniso +#endif +static ConVar mat_filterlightmaps( "mat_filterlightmaps", "1" ); +static ConVar mat_filtertextures( "mat_filtertextures", "1" ); +static ConVar mat_mipmaptextures( "mat_mipmaptextures", "1" ); +static ConVar mat_vrmode_adapter( "mat_vrmode_adapter", "-1" ); + +static void mat_showmiplevels_Callback_f( IConVar *var, const char *pOldValue, float flOldValue ) +{ + // turn off texture filtering if we are showing mip levels. + mat_filtertextures.SetValue( ( ( ConVar * )var )->GetInt() == 0 ); +} +// Debugging textures +static ConVar mat_showmiplevels( "mat_showmiplevels", "0", FCVAR_CHEAT, "color-code miplevels 2: normalmaps, 1: everything else", mat_showmiplevels_Callback_f ); + +static ConVar mat_specular( "mat_specular", "1", FCVAR_ALLOWED_IN_COMPETITIVE, "Enable/Disable specularity for perf testing. Will cause a material reload upon change." ); +static ConVar mat_bumpmap( "mat_bumpmap", "1", FCVAR_ALLOWED_IN_COMPETITIVE ); +static ConVar mat_phong( "mat_phong", "1" ); +static ConVar mat_parallaxmap( "mat_parallaxmap", "1", FCVAR_HIDDEN | FCVAR_ALLOWED_IN_COMPETITIVE ); +static ConVar mat_reducefillrate( "mat_reducefillrate", "0", FCVAR_ALLOWED_IN_COMPETITIVE ); + +#if defined( OSX ) && !defined( STAGING_ONLY ) && !defined( _DEBUG ) +// OSX users are currently running OOM. We limit them to texture quality high here, which avoids the problem while we come up with a real solution. +static ConVar mat_picmip( "mat_picmip", "1", FCVAR_ARCHIVE, "", true, 0, true, 4 ); +#else +static ConVar mat_picmip( "mat_picmip", "0", FCVAR_ARCHIVE, "", true, -1, true, 4 ); +#endif +static ConVar mat_slopescaledepthbias_normal( "mat_slopescaledepthbias_normal", "0.0f", FCVAR_CHEAT ); +static ConVar mat_depthbias_normal( "mat_depthbias_normal", "0.0f", FCVAR_CHEAT | FCVAR_ALLOWED_IN_COMPETITIVE ); +static ConVar mat_slopescaledepthbias_decal( "mat_slopescaledepthbias_decal", "-0.5", FCVAR_CHEAT ); // Reciprocals of these biases sent to API +static ConVar mat_depthbias_decal( "mat_depthbias_decal", "-262144", FCVAR_CHEAT | FCVAR_ALLOWED_IN_COMPETITIVE ); // + +static ConVar mat_slopescaledepthbias_shadowmap( "mat_slopescaledepthbias_shadowmap", "16", FCVAR_CHEAT ); +static ConVar mat_depthbias_shadowmap( "mat_depthbias_shadowmap", "0.0005", FCVAR_CHEAT ); + +static ConVar mat_monitorgamma( "mat_monitorgamma", "2.2", FCVAR_ARCHIVE, "monitor gamma (typically 2.2 for CRT and 1.7 for LCD)", true, 1.6f, true, 2.6f ); +static ConVar mat_monitorgamma_tv_range_min( "mat_monitorgamma_tv_range_min", "16" ); +static ConVar mat_monitorgamma_tv_range_max( "mat_monitorgamma_tv_range_max", "255" ); +// TV's generally have a 2.5 gamma, so we need to convert our 2.2 frame buffer into a 2.5 frame buffer for display on a TV +static ConVar mat_monitorgamma_tv_exp( "mat_monitorgamma_tv_exp", "2.5", 0, "", true, 1.0f, true, 4.0f ); +#ifdef _X360 +static ConVar mat_monitorgamma_tv_enabled( "mat_monitorgamma_tv_enabled", "1", FCVAR_ARCHIVE, "" ); +#else +static ConVar mat_monitorgamma_tv_enabled( "mat_monitorgamma_tv_enabled", "0", FCVAR_ARCHIVE, "" ); +#endif + +static ConVar mat_antialias( "mat_antialias", "0", FCVAR_ARCHIVE ); +static ConVar mat_aaquality( "mat_aaquality", "0", FCVAR_ARCHIVE ); +static ConVar mat_diffuse( "mat_diffuse", "1", FCVAR_CHEAT ); +//============================================================================= +// HPE_BEGIN: +// [Forrest] Make this a cheat variable because low res textures makes enemy +// players and bullet impacts stand out more. +//============================================================================= +static ConVar mat_showlowresimage( "mat_showlowresimage", "0", FCVAR_CHEAT ); +//============================================================================= +// HPE_END +//============================================================================= +static ConVar mat_fullbright( "mat_fullbright","0", FCVAR_CHEAT ); +static ConVar mat_normalmaps( "mat_normalmaps", "0", FCVAR_CHEAT ); +static ConVar mat_measurefillrate( "mat_measurefillrate", "0", FCVAR_CHEAT ); +static ConVar mat_fillrate( "mat_fillrate", "0", FCVAR_CHEAT ); +static ConVar mat_reversedepth( "mat_reversedepth", "0", FCVAR_CHEAT ); +#ifdef DX_TO_GL_ABSTRACTION +static ConVar mat_bufferprimitives( "mat_bufferprimitives", "0" ); // I'm not seeing any benefit speed wise for buffered primitives on GLM/POSIX (checked via TF2 timedemo) - default to zero +#else +static ConVar mat_bufferprimitives( "mat_bufferprimitives", "1" ); +#endif +static ConVar mat_drawflat( "mat_drawflat","0", FCVAR_CHEAT ); +static ConVar mat_softwarelighting( "mat_softwarelighting", "0", FCVAR_ALLOWED_IN_COMPETITIVE ); +static ConVar mat_proxy( "mat_proxy", "0", FCVAR_CHEAT, "", MatProxyCallback ); +static ConVar mat_norendering( "mat_norendering", "0", FCVAR_CHEAT ); +static ConVar mat_compressedtextures( "mat_compressedtextures", "1" ); +static ConVar mat_fastspecular( "mat_fastspecular", "1", 0, "Enable/Disable specularity for visual testing. Will not reload materials and will not affect perf." ); +static ConVar mat_fastnobump( "mat_fastnobump", "0", FCVAR_CHEAT ); // Binds 1-texel normal map for quick internal testing + +// These are not controlled by the material system, but are limited by settings in the material system +static ConVar r_shadowrendertotexture( "r_shadowrendertotexture", "0", FCVAR_ARCHIVE ); +static ConVar r_flashlightdepthtexture( "r_flashlightdepthtexture", "1" ); +#ifndef _X360 +static ConVar r_waterforceexpensive( "r_waterforceexpensive", "0", FCVAR_ARCHIVE ); +#endif +static ConVar r_waterforcereflectentities( "r_waterforcereflectentities", "0", FCVAR_ALLOWED_IN_COMPETITIVE ); +static ConVar mat_motion_blur_enabled( "mat_motion_blur_enabled", "0", FCVAR_ARCHIVE ); + + +uint32 g_nDebugVarsSignature = 0; + + +//----------------------------------------------------------------------------- +// This is called when the config changes +//----------------------------------------------------------------------------- +void CMaterialSystem::ReadConfigFromConVars( MaterialSystem_Config_t *pConfig ) +{ + if ( !g_pCVar ) + return; + + // video panel config items +#ifndef CSS_PERF_TEST + pConfig->SetFlag( MATSYS_VIDCFG_FLAGS_NO_WAIT_FOR_VSYNC, !mat_vsync.GetBool() ); +#endif + pConfig->SetFlag( MATSYS_VIDCFG_FLAGS_FORCE_TRILINEAR, mat_trilinear.GetBool() ); + pConfig->SetFlag( MATSYS_VIDCFG_FLAGS_DISABLE_SPECULAR, !mat_specular.GetBool() ); + pConfig->SetFlag( MATSYS_VIDCFG_FLAGS_DISABLE_BUMPMAP, !mat_bumpmap.GetBool() ); + pConfig->SetFlag( MATSYS_VIDCFG_FLAGS_DISABLE_PHONG, !mat_phong.GetBool() ); + pConfig->SetFlag( MATSYS_VIDCFG_FLAGS_ENABLE_PARALLAX_MAPPING, mat_parallaxmap.GetBool() ); + pConfig->SetFlag( MATSYS_VIDCFG_FLAGS_REDUCE_FILLRATE, mat_reducefillrate.GetBool() ); + pConfig->m_nForceAnisotropicLevel = max( mat_forceaniso.GetInt(), 1 ); + pConfig->dxSupportLevel = MAX( ABSOLUTE_MINIMUM_DXLEVEL, mat_dxlevel.GetInt() ); + pConfig->skipMipLevels = mat_picmip.GetInt(); + pConfig->SetFlag( MATSYS_VIDCFG_FLAGS_FORCE_HWSYNC, mat_forcehardwaresync.GetBool() ); + pConfig->m_SlopeScaleDepthBias_Decal = mat_slopescaledepthbias_decal.GetFloat(); + pConfig->m_DepthBias_Decal = mat_depthbias_decal.GetFloat(); + pConfig->m_SlopeScaleDepthBias_Normal = mat_slopescaledepthbias_normal.GetFloat(); + pConfig->m_DepthBias_Normal = mat_depthbias_normal.GetFloat(); + pConfig->m_SlopeScaleDepthBias_ShadowMap = mat_slopescaledepthbias_shadowmap.GetFloat(); + pConfig->m_DepthBias_ShadowMap = mat_depthbias_shadowmap.GetFloat(); + + pConfig->m_fMonitorGamma = mat_monitorgamma.GetFloat(); + pConfig->m_fGammaTVRangeMin = mat_monitorgamma_tv_range_min.GetFloat(); + pConfig->m_fGammaTVRangeMax = mat_monitorgamma_tv_range_max.GetFloat(); + pConfig->m_fGammaTVExponent = mat_monitorgamma_tv_exp.GetFloat(); + pConfig->m_bGammaTVEnabled = mat_monitorgamma_tv_enabled.GetBool(); + + pConfig->m_nAASamples = mat_antialias.GetInt(); + pConfig->m_nAAQuality = mat_aaquality.GetInt(); + pConfig->bShowDiffuse = mat_diffuse.GetInt() ? true : false; +// pConfig->bAllowCheats = false; // hack + pConfig->bShowNormalMap = mat_normalmaps.GetInt() ? true : false; + pConfig->bShowLowResImage = mat_showlowresimage.GetInt() ? true : false; + pConfig->bMeasureFillRate = mat_measurefillrate.GetInt() ? true : false; + pConfig->bVisualizeFillRate = mat_fillrate.GetInt() ? true : false; + pConfig->bFilterLightmaps = mat_filterlightmaps.GetInt() ? true : false; + pConfig->bFilterTextures = mat_filtertextures.GetInt() ? true : false; + pConfig->bMipMapTextures = mat_mipmaptextures.GetInt() ? true : false; + pConfig->nShowMipLevels = mat_showmiplevels.GetInt(); + pConfig->bReverseDepth = mat_reversedepth.GetInt() ? true : false; + pConfig->bBufferPrimitives = mat_bufferprimitives.GetInt() ? true : false; + pConfig->bDrawFlat = mat_drawflat.GetInt() ? true : false; + pConfig->bSoftwareLighting = mat_softwarelighting.GetInt() ? true : false; + pConfig->proxiesTestMode = mat_proxy.GetInt(); + pConfig->m_bSuppressRendering = mat_norendering.GetInt() != 0; + pConfig->bCompressedTextures = mat_compressedtextures.GetBool(); + pConfig->bShowSpecular = mat_fastspecular.GetInt() ? true : false; + pConfig->nFullbright = mat_fullbright.GetInt(); + pConfig->m_bFastNoBump = mat_fastnobump.GetInt() != 0; + pConfig->m_bMotionBlur = mat_motion_blur_enabled.GetBool(); + pConfig->m_bSupportFlashlight = mat_supportflashlight.GetInt() != 0; + pConfig->m_bShadowDepthTexture = r_flashlightdepthtexture.GetBool(); + + pConfig->SetFlag( MATSYS_VIDCFG_FLAGS_ENABLE_HDR, HardwareConfig() && HardwareConfig()->GetHDREnabled() ); + + // Render-to-texture shadows are disabled for dxlevel 70 because of material issues + if ( pConfig->dxSupportLevel < 80 ) + { + r_shadowrendertotexture.SetValue( 0 ); +#ifndef _X360 + r_waterforceexpensive.SetValue( 0 ); +#endif + r_waterforcereflectentities.SetValue( 0 ); + } + if ( pConfig->dxSupportLevel < 90 ) + { + mat_requires_rt_alloc_first.SetValue( 1 ); + r_flashlightdepthtexture.SetValue( 0 ); + mat_motion_blur_enabled.SetValue( 0 ); + pConfig->m_bShadowDepthTexture = false; + pConfig->m_bMotionBlur = false; + pConfig->SetFlag( MATSYS_VIDCFG_FLAGS_ENABLE_HDR, false ); + } + + // VR mode adapter will generally be -1 if VR mode is not disabled + pConfig->m_nVRModeAdapter = mat_vrmode_adapter.GetInt(); + if( pConfig->m_nVRModeAdapter != -1 ) + { + // we must always be windowed in the config in VR mode + // so that we will start up on the main display. Once + // VR overrides the adapter the only place we can go + // full screen is on the HMD. + pConfig->SetFlag( MATSYS_VIDCFG_FLAGS_WINDOWED, true ); + } +} + + +//----------------------------------------------------------------------------- +// Was the convar specified on the command-line? +//----------------------------------------------------------------------------- +static bool WasConVarSpecifiedOnCommandLine( const char *pConfigName ) +{ + // mat_dxlevel cannot be used on the command-line. Use -dxlevel instead. + if ( !Q_stricmp( pConfigName, "mat_dxlevel" ) ) + return false; + + return ( g_pCVar->GetCommandLineValue( pConfigName ) != NULL); +} + + +static const char *pConvarsAllowedInDXSupport[]={ + "cl_detaildist", + "cl_detailfade", + "cl_ejectbrass", + "dsp_off", + "dsp_slow_cpu", + "mat_antialias", + "mat_aaquality", + "mat_bumpmap", + "mat_colorcorrection", + "mat_depthbias_decal", + "mat_depthbias_normal", + "mat_disable_ps_patch", + "mat_forceaniso", + "mat_forcehardwaresync", + "mat_forcemanagedtextureintohardware", + "mat_hdr_level", + "mat_parallaxmap", + "mat_picmip", + "mat_reducefillrate", + "mat_reduceparticles", + "mat_slopescaledepthbias_decal", + "mat_slopescaledepthbias_normal", + "mat_softwarelighting", + "mat_specular", + "mat_trilinear", + "mat_vsync", + "props_break_max_pieces", + "r_VehicleViewDampen", + "r_decal_cullsize", + "r_dopixelvisibility", + "r_drawdetailprops", + "r_drawflecks", + "r_drawmodeldecals", + "r_dynamic", + "r_lightcache_zbuffercache", + "r_fastzreject", + "r_overlayfademax", + "r_overlayfademin", + "r_rootlod", + "r_screenfademaxsize", + "r_screenfademinsize", + "r_shadowrendertotexture", + "r_shadows", + "r_waterforceexpensive", + "r_waterforcereflectentities", + "sv_alternateticks", + "mat_dxlevel", + "mat_fallbackEyeRefract20", + "r_shader_srgb", + "mat_motion_blur_enabled", + "r_flashlightdepthtexture", + "mat_disablehwmorph", + "r_portal_stencil_depth", + "cl_blobbyshadows", + "r_flex", + "r_drawropes", + "props_break_max_pieces", + "cl_ragdoll_fade_time", + "cl_ragdoll_forcefade", + "tf_impactwatertimeenable", + "fx_drawimpactdebris", + "fx_drawimpactdust", + "fx_drawmetalspark", + "mem_min_heapsize", + "mem_max_heapsize", + "mem_max_heapsize_dedicated", + "snd_spatialize_roundrobin", + "snd_cull_duplicates", + "cl_particle_retire_cost", + "mat_phong" +}; + +//----------------------------------------------------------------------------- +// Write dxsupport info to configvars +//----------------------------------------------------------------------------- +void CMaterialSystem::WriteConfigurationInfoToConVars( bool bOverwriteCommandLineValues ) +{ + if ( !g_pCVar ) + return; + + KeyValues *pKeyValues = new KeyValues( "config" ); + if ( !GetRecommendedConfigurationInfo( g_config.dxSupportLevel, pKeyValues ) ) + { + pKeyValues->deleteThis(); + return; + } + + for( KeyValues *pKey = pKeyValues->GetFirstSubKey(); pKey; pKey = pKey->GetNextKey() ) + { + const char *pConfigName = pKey->GetName(); + if ( Q_strnicmp( pConfigName, "convar.", 7 )) + continue; + + pConfigName += 7; + // check if legal + bool bLegalVar = false; + for(int i=0; i< NELEMS( pConvarsAllowedInDXSupport ) ; i++) + { + if (! stricmp( pConvarsAllowedInDXSupport[i], pConfigName ) ) + { + bLegalVar = true; + break; + } + } + if (! bLegalVar ) + { + Msg(" Bad convar found in dxsupport - %s\n", pConfigName ); + continue; + } + + if ( bOverwriteCommandLineValues || !WasConVarSpecifiedOnCommandLine( pConfigName ) ) + { + ConVar *pConVar = g_pCVar->FindVar( pConfigName ); + if ( !pConVar ) + { + // NOTE: This is essential for dealing with convars that + // are not specified in either the app that uses the materialsystem + // or the materialsystem itself + + // Yes, this causes a memory leak. Too bad! + int nLen = Q_strlen( pConfigName ) + 1; + char *pString = new char[nLen]; + Q_strncpy( pString, pConfigName, nLen ); + + // Actually, we need two memory leaks, or we lose the default string. + int nDefaultLen = Q_strlen( pKey->GetString() ) + 1; + char *pDefaultString = new char[nDefaultLen]; + Q_strncpy( pDefaultString, pKey->GetString(), nDefaultLen ); + + pConVar = new ConVar( pString, pDefaultString ); + } + pConVar->SetValue( pKey->GetString() ); + } + } + + pKeyValues->deleteThis(); +} + + +//----------------------------------------------------------------------------- +// This is called when the config changes +//----------------------------------------------------------------------------- +void CMaterialSystem::WriteConfigIntoConVars( const MaterialSystem_Config_t &config ) +{ + if ( !g_pCVar ) + return; + + mat_vsync.SetValue( config.WaitForVSync() ); + mat_trilinear.SetValue( config.ForceTrilinear() ); + mat_specular.SetValue( config.UseSpecular() ); + mat_bumpmap.SetValue( config.UseBumpmapping() ); + mat_phong.SetValue( config.UsePhong() ); + mat_parallaxmap.SetValue( config.UseParallaxMapping() ); + mat_reducefillrate.SetValue( config.ReduceFillrate() ); + mat_forceaniso.SetValue( config.m_nForceAnisotropicLevel ); + mat_dxlevel.SetValue( MAX( ABSOLUTE_MINIMUM_DXLEVEL, config.dxSupportLevel ) ); + mat_picmip.SetValue( config.skipMipLevels ); + mat_forcehardwaresync.SetValue( config.ForceHWSync() ); + mat_slopescaledepthbias_normal.SetValue( config.m_SlopeScaleDepthBias_Normal ); + mat_depthbias_normal.SetValue( config.m_DepthBias_Normal ); + mat_slopescaledepthbias_decal.SetValue( config.m_SlopeScaleDepthBias_Decal ); + mat_depthbias_decal.SetValue( config.m_DepthBias_Decal ); + mat_slopescaledepthbias_shadowmap.SetValue( config.m_SlopeScaleDepthBias_ShadowMap ); + mat_depthbias_shadowmap.SetValue( config.m_DepthBias_ShadowMap ); + + mat_monitorgamma.SetValue( config.m_fMonitorGamma ); + mat_monitorgamma_tv_range_min.SetValue( config.m_fGammaTVRangeMin ); + mat_monitorgamma_tv_range_max.SetValue( config.m_fGammaTVRangeMax ); + mat_monitorgamma_tv_exp.SetValue( config.m_fGammaTVExponent ); + mat_monitorgamma_tv_enabled.SetValue( config.m_bGammaTVEnabled ); + + mat_antialias.SetValue( config.m_nAASamples ); + mat_aaquality.SetValue( config.m_nAAQuality ); + mat_diffuse.SetValue( config.bShowDiffuse ? 1 : 0 ); +// config.bAllowCheats = false; // hack + mat_normalmaps.SetValue( config.bShowNormalMap ? 1 : 0 ); + mat_showlowresimage.SetValue( config.bShowLowResImage ? 1 : 0 ); + mat_measurefillrate.SetValue( config.bMeasureFillRate ? 1 : 0 ); + mat_fillrate.SetValue( config.bVisualizeFillRate ? 1 : 0 ); + mat_filterlightmaps.SetValue( config.bFilterLightmaps ? 1 : 0 ); + mat_filtertextures.SetValue( config.bFilterTextures ? 1 : 0 ); + mat_mipmaptextures.SetValue( config.bMipMapTextures ? 1 : 0 ); + mat_showmiplevels.SetValue( config.nShowMipLevels ); + mat_reversedepth.SetValue( config.bReverseDepth ? 1 : 0 ); + mat_bufferprimitives.SetValue( config.bBufferPrimitives ? 1 : 0 ); + mat_drawflat.SetValue( config.bDrawFlat ? 1 : 0 ); + mat_softwarelighting.SetValue( config.bSoftwareLighting ? 1 : 0 ); + mat_proxy.SetValue( config.proxiesTestMode ); + mat_norendering.SetValue( config.m_bSuppressRendering ? 1 : 0 ); + mat_compressedtextures.SetValue( config.bCompressedTextures ? 1 : 0 ); + mat_fastspecular.SetValue( config.bShowSpecular ? 1 : 0 ); + mat_fullbright.SetValue( config.nFullbright ); + mat_fastnobump.SetValue( config.m_bFastNoBump ? 1 : 0 ); + bool hdre = config.HDREnabled(); + HardwareConfig()->SetHDREnabled( hdre ); + r_flashlightdepthtexture.SetValue( config.m_bShadowDepthTexture ? 1 : 0 ); + mat_motion_blur_enabled.SetValue( config.m_bMotionBlur ? 1 : 0 ); + mat_supportflashlight.SetValue( config.m_bSupportFlashlight ? 1 : 0 ); +} + + +//----------------------------------------------------------------------------- +// This is called constantly to catch for config changes +//----------------------------------------------------------------------------- +bool CMaterialSystem::OverrideConfig( const MaterialSystem_Config_t &_config, bool forceUpdate ) +{ + Assert( m_bGeneratedConfig ); + if ( memcmp( &_config, &g_config, sizeof(_config) ) == 0 ) + { + return false; + } + + MaterialLock_t hLock = Lock(); + MaterialSystem_Config_t config = _config; + + bool bRedownloadLightmaps = false; + bool bRedownloadTextures = false; + bool recomputeSnapshots = false; + bool dxSupportLevelChanged = false; + bool bReloadMaterials = false; + bool bResetAnisotropy = false; + bool bSetStandardVertexShaderConstants = false; + bool bMonitorGammaChanged = false; + bool bVideoModeChange = false; + bool bResetTextureFilter = false; + bool bForceAltTab = false; + + // internal config settings +#ifndef _X360 + MaterialSystem_Config_Internal_t config_internal; + config_internal.r_waterforceexpensive = r_waterforceexpensive.GetInt(); +#endif + + if ( !g_pShaderDevice->IsUsingGraphics() ) + { + g_config = config; +#ifndef _X360 + g_config_internal = config_internal; +#endif + + // Shouldn't call this more than once. + ColorSpace::SetGamma( 2.2f, 2.2f, OVERBRIGHT, g_config.bAllowCheats, false ); + Unlock( hLock ); + return bRedownloadLightmaps; + } + + // set the default state since we might be changing the number of + // texture units, etc. (i.e. we don't want to leave unit 2 in overbright mode + // if it isn't going to be reset upon each SetDefaultState because there is + // effectively only one texture unit.) + g_pShaderAPI->SetDefaultState(); + + // toggle dx emulation level + if ( config.dxSupportLevel != g_config.dxSupportLevel ) + { + if ( mat_debugalttab.GetBool() ) + { + Warning( "mat_debugalttab: Setting dxSupportLevelChanged, bResetAnisotropy, and bReloadMaterials because new dxlevel = %d and old dxlevel = %d\n", + ( int )config.dxSupportLevel, g_config.dxSupportLevel ); + } + dxSupportLevelChanged = true; + bResetAnisotropy = true; + + // Necessary for DXSupportLevelChanged to work + g_config.dxSupportLevel = config.dxSupportLevel; + + // This will reset config to match whatever the dxlevel wants + // and slam to convars to match + g_pShaderAPI->DXSupportLevelChanged( ); + WriteConfigurationInfoToConVars(); + ReadConfigFromConVars( &config ); + bReloadMaterials = true; + } + + if ( config.HDREnabled() != g_config.HDREnabled() ) + { + if ( mat_debugalttab.GetBool() ) + { + Warning( "mat_debugalttab: Setting forceUpdate, bReloadMaterials, and bForceAltTab because new hdr level = %d and old hdr level = %d\n", + ( int )config.HDREnabled(), g_config.HDREnabled() ); + } + + forceUpdate = true; + bReloadMaterials = true; + bForceAltTab = true; + } + + if ( config.ShadowDepthTexture() != g_config.ShadowDepthTexture() ) + { + if ( mat_debugalttab.GetBool() ) + { + Warning( "mat_debugalttab: Setting forceUpdate, bReloadMaterials and recomputeSnapshots (ShadowDepthTexture changed: %d -> %d)\n", + g_config.ShadowDepthTexture() ? 1 : 0, config.ShadowDepthTexture() ? 1 : 0 ); + } + + forceUpdate = true; + bReloadMaterials = true; + recomputeSnapshots = true; + } + + if ( config.VRMode() != g_config.VRMode() || config.m_nVRModeAdapter != g_config.m_nVRModeAdapter ) + { + bVideoModeChange = true; + } + + // Don't use compressed textures for the moment if we don't support them + if ( HardwareConfig() && !HardwareConfig()->SupportsCompressedTextures() ) + { + config.bCompressedTextures = false; + } + + if ( forceUpdate ) + { + if ( mat_debugalttab.GetBool() ) + { + Warning( "mat_debugalttab: forceUpdate is true, therefore setting recomputeSnapshots, bRedownloadLightmaps, bRedownloadTextures, bResetAnisotropy, and bSetStandardVertexShaderConstants\n" ); + } + GetLightmaps()->EnableLightmapFiltering( config.bFilterLightmaps ); + recomputeSnapshots = true; + bRedownloadLightmaps = true; + bRedownloadTextures = true; + bResetAnisotropy = true; + bSetStandardVertexShaderConstants = true; + } + + // toggle bump mapping + if ( config.UseBumpmapping() != g_config.UseBumpmapping() || config.UsePhong() != g_config.UsePhong() ) + { + if( mat_debugalttab.GetBool() ) + { + Warning( "mat_debugalttab: forceUpdate is true, therefore setting recomputeSnapshots, bRedownloadLightmaps, bRedownloadTextures, bResetAnisotropy, and bSetStandardVertexShaderConstants\n" ); + } + recomputeSnapshots = true; + bReloadMaterials = true; + bResetAnisotropy = true; + } + + // toggle specularity + if ( config.UseSpecular() != g_config.UseSpecular() ) + { + if( mat_debugalttab.GetBool() ) + { + Warning( "mat_debugalttab: new usespecular=%d, old usespecular=%d, setting recomputeSnapshots, bReloadMaterials, and bResetAnisotropy\n", + ( int )config.UseSpecular(), ( int )g_config.UseSpecular() ); + } + recomputeSnapshots = true; + bReloadMaterials = true; + bResetAnisotropy = true; + } + + // toggle parallax mapping + if ( config.UseParallaxMapping() != g_config.UseParallaxMapping() ) + { + if ( mat_debugalttab.GetBool() ) + { + Warning( "mat_debugalttab: new UseParallaxMapping=%d, old UseParallaxMapping=%d, setting bReloadMaterials\n", + ( int )config.UseParallaxMapping(), ( int )g_config.UseParallaxMapping() ); + } + bReloadMaterials = true; + } + + // Reload materials if we want reduced fillrate + if ( config.ReduceFillrate() != g_config.ReduceFillrate() ) + { + if ( mat_debugalttab.GetBool() ) + { + Warning( "mat_debugalttab: new ReduceFillrate=%d, old ReduceFillrate=%d, setting bReloadMaterials\n", + ( int )config.ReduceFillrate(), ( int )g_config.ReduceFillrate() ); + } + bReloadMaterials = true; + } + + // toggle reverse depth + if ( config.bReverseDepth != g_config.bReverseDepth ) + { + if( mat_debugalttab.GetBool() ) + { + Warning( "mat_debugalttab: new ReduceFillrate=%d, old ReduceFillrate=%d, setting bReloadMaterials\n", + ( int )config.ReduceFillrate(), ( int )g_config.ReduceFillrate() ); + } + recomputeSnapshots = true; + bResetAnisotropy = true; + } + + // toggle no transparency + if ( config.bNoTransparency != g_config.bNoTransparency ) + { + if ( mat_debugalttab.GetBool() ) + { + Warning( "mat_debugalttab: new bNoTransparency=%d, old bNoTransparency=%d, setting recomputeSnapshots and bResetAnisotropy\n", + ( int )config.bNoTransparency, ( int )g_config.bNoTransparency ); + } + recomputeSnapshots = true; + bResetAnisotropy = true; + } + + // toggle lightmap filtering + if ( config.bFilterLightmaps != g_config.bFilterLightmaps ) + { + if ( mat_debugalttab.GetBool() ) + { + Warning( "mat_debugalttab: new bFilterLightmaps=%d, old bFilterLightmaps=%d, setting EnableLightmapFiltering\n", + ( int )config.bFilterLightmaps, ( int )g_config.bFilterLightmaps ); + } + GetLightmaps()->EnableLightmapFiltering( config.bFilterLightmaps ); + } + + // toggle software lighting + if ( config.bSoftwareLighting != g_config.bSoftwareLighting ) + { + if( mat_debugalttab.GetBool() ) + { + Warning( "mat_debugalttab: new bSoftwareLighting=%d, old bSoftwareLighting=%d, setting bReloadMaterials\n", + ( int )config.bFilterLightmaps, ( int )g_config.bFilterLightmaps ); + } + bReloadMaterials = true; + } + +#ifndef _X360 + if ( config_internal.r_waterforceexpensive != g_config_internal.r_waterforceexpensive ) + { + if ( mat_debugalttab.GetBool() ) + { + Warning( "mat_debugalttab: new r_waterforceexpensive=%d, old r_waterforceexpensive=%d, setting bReloadMaterials\n", + ( int )config_internal.r_waterforceexpensive, ( int )g_config_internal.r_waterforceexpensive ); + } + bReloadMaterials = true; + } +#endif + + // generic things that cause us to redownload lightmaps + if ( config.bAllowCheats != g_config.bAllowCheats ) + { + if ( mat_debugalttab.GetBool() ) + { + Warning( "mat_debugalttab: new bAllowCheats=%d, old bAllowCheats=%d, setting bRedownloadLightmaps\n", + ( int )config.bAllowCheats, ( int )g_config.bAllowCheats ); + } + bRedownloadLightmaps = true; + } + + // generic things that cause us to redownload textures + if ( config.bAllowCheats != g_config.bAllowCheats || + config.skipMipLevels != g_config.skipMipLevels || + config.nShowMipLevels != g_config.nShowMipLevels || + ((config.bCompressedTextures != g_config.bCompressedTextures) && HardwareConfig()->SupportsCompressedTextures())|| + config.bShowLowResImage != g_config.bShowLowResImage + ) + { + if ( mat_debugalttab.GetBool() ) + { + Warning( "mat_debugalttab: setting bRedownloadTextures, recomputeSnapshots, and bResetAnisotropy\n" ); + } + bRedownloadTextures = true; + recomputeSnapshots = true; + bResetAnisotropy = true; + } + + if ( config.ForceTrilinear() != g_config.ForceTrilinear() ) + { + if ( mat_debugalttab.GetBool() ) + { + Warning( "mat_debugalttab: new forcetrilinear: %d, old forcetrilinear: %d, setting bResetTextureFilter\n", + ( int )config.ForceTrilinear(), ( int )g_config.ForceTrilinear() ); + } + bResetTextureFilter = true; + } + + if ( config.m_nForceAnisotropicLevel != g_config.m_nForceAnisotropicLevel ) + { + if( mat_debugalttab.GetBool() ) + { + Warning( "mat_debugalttab: new m_nForceAnisotropicLevel: %d, old m_nForceAnisotropicLevel: %d, setting bResetAnisotropy and bResetTextureFilter\n", + ( int )config.ForceTrilinear(), ( int )g_config.ForceTrilinear() ); + } + bResetAnisotropy = true; + bResetTextureFilter = true; + } + + if ( config.m_fMonitorGamma != g_config.m_fMonitorGamma || config.m_fGammaTVRangeMin != g_config.m_fGammaTVRangeMin || + config.m_fGammaTVRangeMax != g_config.m_fGammaTVRangeMax || config.m_fGammaTVExponent != g_config.m_fGammaTVExponent || + config.m_bGammaTVEnabled != g_config.m_bGammaTVEnabled ) + { + if( mat_debugalttab.GetBool() ) + { + Warning( "mat_debugalttab: new monitorgamma: %f, old monitorgamma: %f, setting bMonitorGammaChanged\n", + config.m_fMonitorGamma, g_config.m_fMonitorGamma ); + } + bMonitorGammaChanged = true; + } + + if ( config.m_VideoMode.m_Width != g_config.m_VideoMode.m_Width || + config.m_VideoMode.m_Height != g_config.m_VideoMode.m_Height || + config.m_VideoMode.m_RefreshRate != g_config.m_VideoMode.m_RefreshRate || + config.m_nAASamples != g_config.m_nAASamples || + config.m_nAAQuality != g_config.m_nAAQuality || + config.Windowed() != g_config.Windowed() || + config.Stencil() != g_config.Stencil() ) + { + if( mat_debugalttab.GetBool() ) + { + Warning( "mat_debugalttab: video mode changed for one of various reasons\n" ); + } + bVideoModeChange = true; + } + + // toggle wait for vsync + // In GL, we just check this and it's just a function call--no need for device shenanigans. +#if !defined( DX_TO_GL_ABSTRACTION ) + if ( (IsX360() || !config.Windowed()) && (config.WaitForVSync() != g_config.WaitForVSync()) ) + { +# if ( !defined( _X360 ) ) + { + if ( mat_debugalttab.GetBool() ) + { + Warning( "mat_debugalttab: video mode changed due to toggle of wait for vsync\n" ); + } + bVideoModeChange = true; + } +# else + { + g_pShaderAPI->EnableVSync_360( config.WaitForVSync() ); + } +# endif + } +#endif + + g_config = config; +#ifndef _X360 + g_config_internal = config_internal; +#endif + + if ( dxSupportLevelChanged ) + { + if ( mat_debugalttab.GetBool() ) + { + Warning( "mat_debugalttab: dx support level changed, clearing snapshots\n" ); + } + // All snapshots have basically become invalid; + g_pShaderAPI->ClearSnapshots(); + } + + if ( bRedownloadTextures || bRedownloadLightmaps ) + { + // Get rid of this? + ColorSpace::SetGamma( 2.2f, 2.2f, OVERBRIGHT, g_config.bAllowCheats, false ); + } + + // 360 does not support various configuration changes and cannot reload materials + if ( !IsX360() ) + { + if ( bResetAnisotropy || recomputeSnapshots || bRedownloadLightmaps || + bRedownloadTextures || bResetAnisotropy || bVideoModeChange || + bSetStandardVertexShaderConstants || bResetTextureFilter ) + { + Unlock( hLock ); + ForceSingleThreaded(); + hLock = Lock(); + } + } + if ( bReloadMaterials && !IsX360() ) + { + if ( mat_debugalttab.GetBool() ) + { + Warning( "mat_debugalttab: ReloadMaterials\n" ); + } + ReloadMaterials(); + } + + // 360 does not support various configuration changes and cannot reload textures + // 360 has no reason to reload textures, it's unnecessary and massively expensive + // 360 does not use this path as an init affect to get its textures into memory + if ( bRedownloadTextures && !IsX360() ) + { + if ( mat_debugalttab.GetBool() ) + { + Warning( "mat_debugalttab: redownloading textures\n" ); + } + + if ( g_pShaderAPI->CanDownloadTextures() ) + { + TextureManager()->RestoreRenderTargets(); + TextureManager()->RestoreNonRenderTargetTextures(); + } + } + else if ( bResetTextureFilter ) + { + if( mat_debugalttab.GetBool() ) + { + Warning( "mat_debugalttab: ResetTextureFilteringState\n" ); + } + TextureManager()->ResetTextureFilteringState(); + } + + // Recompute all state snapshots + if ( recomputeSnapshots ) + { + if( mat_debugalttab.GetBool() ) + { + Warning( "mat_debugalttab: RecomputeAllStateSnapshots\n" ); + } + RecomputeAllStateSnapshots(); + } + + if ( bResetAnisotropy ) + { + if( mat_debugalttab.GetBool() ) + { + Warning( "mat_debugalttab: SetAnisotropicLevel\n" ); + } + g_pShaderAPI->SetAnisotropicLevel( config.m_nForceAnisotropicLevel ); + } + + if ( bSetStandardVertexShaderConstants ) + { + if ( mat_debugalttab.GetBool() ) + { + Warning( "mat_debugalttab: SetStandardVertexShaderConstants\n" ); + } + g_pShaderAPI->SetStandardVertexShaderConstants( OVERBRIGHT ); + } + + if ( bMonitorGammaChanged ) + { + if( mat_debugalttab.GetBool() ) + { + Warning( "mat_debugalttab: SetHardwareGammaRamp\n" ); + } + g_pShaderDevice->SetHardwareGammaRamp( config.m_fMonitorGamma, config.m_fGammaTVRangeMin, config.m_fGammaTVRangeMax, + config.m_fGammaTVExponent, config.m_bGammaTVEnabled ); + } + + if ( bVideoModeChange ) + { + if ( mat_debugalttab.GetBool() ) + { + Warning( "mat_debugalttab: ChangeVideoMode\n" ); + } + ShaderDeviceInfo_t info; + ConvertModeStruct( &info, config ); + g_pShaderAPI->ChangeVideoMode( info ); + +#if defined( USE_SDL ) + uint width = info.m_DisplayMode.m_nWidth; + uint height = info.m_DisplayMode.m_nHeight; + g_pLauncherMgr->RenderedSize( width, height, true ); // true = set +#endif + } + + if ( bForceAltTab ) + { + // Simulate an Alt-Tab +// g_pShaderAPI->ReleaseResources(); +// g_pShaderAPI->ReacquireResources(); + } + + Unlock( hLock ); + if ( bVideoModeChange ) + { + ForceSingleThreaded(); + } + return bRedownloadLightmaps; +} + + +//----------------------------------------------------------------------------- +// This is called when the config changes +//----------------------------------------------------------------------------- +bool CMaterialSystem::UpdateConfig( bool forceUpdate ) +{ + int nUpdateFlags = 0; + if ( g_pCVar && g_pCVar->HasQueuedMaterialThreadConVarSets() ) + { + ForceSingleThreaded(); + nUpdateFlags = g_pCVar->ProcessQueuedMaterialThreadConVarSets(); + } + + MaterialSystem_Config_t config = g_config; + ReadConfigFromConVars( &config ); + return OverrideConfig( config, forceUpdate ); +} + + + +void CMaterialSystem::ReleaseResources() +{ + if( mat_debugalttab.GetBool() ) + { + Warning( "mat_debugalttab: CMaterialSystem::ReleaseResources\n" ); + } + g_pShaderAPI->FlushBufferedPrimitives(); + g_pShaderDevice->ReleaseResources(); +} + +void CMaterialSystem::ReacquireResources() +{ + if( mat_debugalttab.GetBool() ) + { + Warning( "mat_debugalttab: CMaterialSystem::ReacquireResources\n" ); + } + g_pShaderDevice->ReacquireResources(); +} + + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +bool CMaterialSystem::OnDrawMesh( IMesh *pMesh, int firstIndex, int numIndices ) +{ + if ( IsInStubMode() ) + { + return false; + } + + return GetRenderContextInternal()->OnDrawMesh( pMesh, firstIndex, numIndices ); +} + +bool CMaterialSystem::OnDrawMesh( IMesh *pMesh, CPrimList *pLists, int nLists ) +{ + if ( IsInStubMode() ) + { + return false; + } + + return GetRenderContextInternal()->OnDrawMesh( pMesh, pLists, nLists ); +} + +void CMaterialSystem::OnThreadEvent( uint32 threadEvent ) +{ + m_threadEvents.AddToTail( threadEvent ); +} + +ShaderAPITextureHandle_t CMaterialSystem::GetShaderAPITextureBindHandle( ITexture *pTexture, int nFrame, int nTextureChannel ) +{ + return ShaderSystem()->GetShaderAPITextureBindHandle( pTexture, nFrame, nTextureChannel ); +} + +//----------------------------------------------------------------------------- +// Creates a procedural texture +//----------------------------------------------------------------------------- +ITexture *CMaterialSystem::CreateProceduralTexture( + const char *pTextureName, + const char *pTextureGroupName, + int w, + int h, + ImageFormat fmt, + int nFlags ) +{ + ITextureInternal* pTex = TextureManager()->CreateProceduralTexture( pTextureName, pTextureGroupName, w, h, 1, fmt, nFlags ); + return pTex; +} + + +//----------------------------------------------------------------------------- +// Create new materials (currently only used by the editor!) +//----------------------------------------------------------------------------- +IMaterial *CMaterialSystem::CreateMaterial( const char *pMaterialName, KeyValues *pVMTKeyValues ) +{ + // For not, just create a material with no default settings + IMaterialInternal* pMaterial = IMaterialInternal::CreateMaterial( pMaterialName, TEXTURE_GROUP_OTHER, pVMTKeyValues ); + pMaterial->IncrementReferenceCount(); + AddMaterialToMaterialList( pMaterial ); + return pMaterial->GetQueueFriendlyVersion(); +} + + +//----------------------------------------------------------------------------- +// Finds or creates a procedural material +//----------------------------------------------------------------------------- +IMaterial *CMaterialSystem::FindProceduralMaterial( const char *pMaterialName, const char *pTextureGroupName, KeyValues *pVMTKeyValues ) +{ + // We need lower-case symbols for this to work + int nLen = Q_strlen( pMaterialName ) + 1; + char *pTemp = (char*)stackalloc( nLen ); + Q_strncpy( pTemp, pMaterialName, nLen ); + Q_strlower( pTemp ); + Q_FixSlashes( pTemp, '/' ); + + // 'true' causes the search to find procedural materials + IMaterialInternal *pMaterial = m_MaterialDict.FindMaterial( pTemp, true ); + if ( pMaterial ) + { + pVMTKeyValues->deleteThis(); + } + else + { + pMaterial = IMaterialInternal::CreateMaterial( pMaterialName, pTextureGroupName, pVMTKeyValues ); + AddMaterialToMaterialList( static_cast( pMaterial ) ); + } + + return pMaterial->GetQueueFriendlyVersion(); +} + + +//----------------------------------------------------------------------------- +// Search by name +//----------------------------------------------------------------------------- +bool CMaterialSystem::IsMaterialLoaded( char const *pMaterialName ) +{ + // We need lower-case symbols for this to work + int nLen = Q_strlen( pMaterialName ) + 1; + char *pFixedNameTemp = (char*)stackalloc( nLen ); + char *pTemp = (char*)stackalloc( nLen ); + Q_strncpy( pFixedNameTemp, pMaterialName, nLen ); + Q_strlower( pFixedNameTemp ); +#ifdef POSIX + // strip extensions needs correct slashing for the OS, so fix it up early for Posix + Q_FixSlashes( pFixedNameTemp, '/' ); +#endif + Q_StripExtension( pFixedNameTemp, pTemp, nLen ); +#ifndef POSIX + Q_FixSlashes( pTemp, '/' ); +#endif + + Assert( nLen >= Q_strlen( pTemp ) + 1 ); + + return m_MaterialDict.FindMaterial( pTemp, false ) != NULL; // 'false' causes the search to find only file-created materials +} + +//----------------------------------------------------------------------------- +// Search by name +//----------------------------------------------------------------------------- +IMaterial* CMaterialSystem::FindMaterial( char const *pMaterialName, const char *pTextureGroupName, bool bComplain, const char *pComplainPrefix ) +{ + return FindMaterialEx( pMaterialName, pTextureGroupName, MATERIAL_FINDCONTEXT_NONE, bComplain, pComplainPrefix ); +} + +//----------------------------------------------------------------------------- +// Search by name +//----------------------------------------------------------------------------- +IMaterial* CMaterialSystem::FindMaterialEx( char const* pMaterialName, const char *pTextureGroupName, int nContext, bool bComplain, const char *pComplainPrefix ) +{ + // We need lower-case symbols for this to work + int nLen = Q_strlen( pMaterialName ) + 1; + char *pFixedNameTemp = (char*)stackalloc( nLen ); + char *pTemp = (char*)stackalloc( nLen ); + Q_strncpy( pFixedNameTemp, pMaterialName, nLen ); + Q_strlower( pFixedNameTemp ); +#ifdef POSIX + // strip extensions needs correct slashing for the OS, so fix it up early for Posix + Q_FixSlashes( pFixedNameTemp, '/' ); +#endif + Q_StripExtension( pFixedNameTemp, pTemp, nLen ); +#ifndef POSIX + Q_FixSlashes( pTemp, '/' ); +#endif + + Assert( nLen >= Q_strlen( pTemp ) + 1 ); + + IMaterialInternal *pExistingMaterial = m_MaterialDict.FindMaterial( pTemp, false ); // 'false' causes the search to find only file-created materials + + if ( pExistingMaterial ) + return pExistingMaterial->GetQueueFriendlyVersion(); + + // It hasn't been seen yet, so let's check to see if it's in the filesystem. + nLen = Q_strlen( "materials/" ) + Q_strlen( pTemp ) + Q_strlen( ".vmt" ) + 1; + char *vmtName = (char *)stackalloc( nLen ); + + // Check to see if this is a UNC-specified material name + bool bIsUNC = pTemp[0] == '/' && pTemp[1] == '/' && pTemp[2] != '/'; + if ( !bIsUNC ) + { + Q_strncpy( vmtName, "materials/", nLen ); + Q_strncat( vmtName, pTemp, nLen, COPY_ALL_CHARACTERS ); + + V_FixDoubleSlashes( vmtName ); + } + else + { + Q_strncpy( vmtName, pTemp, nLen ); + } + + //Q_strncat( vmtName, ".vmt", nLen, COPY_ALL_CHARACTERS ); + Assert( nLen >= (int)Q_strlen( vmtName ) + 1 ); + + CUtlVector includes; + KeyValues *pKeyValues = new KeyValues("vmt"); + KeyValues *pPatchKeyValues = new KeyValues( "vmt_patches" ); + if ( !LoadVMTFile( *pKeyValues, *pPatchKeyValues, vmtName, true, &includes ) ) + { + pKeyValues->deleteThis(); + pKeyValues = NULL; + pPatchKeyValues->deleteThis(); + pPatchKeyValues = NULL; + } + else + { + char *matNameWithExtension; + nLen = Q_strlen( pTemp ) + Q_strlen( ".vmt" ) + 1; + matNameWithExtension = (char *)stackalloc( nLen ); + Q_strncpy( matNameWithExtension, pTemp, nLen ); + Q_strncat( matNameWithExtension, ".vmt", nLen, COPY_ALL_CHARACTERS ); + + IMaterialInternal *pMat = NULL; + if ( !Q_stricmp( pKeyValues->GetName(), "subrect" ) ) + { + pMat = m_MaterialDict.AddMaterialSubRect( matNameWithExtension, pTextureGroupName, pKeyValues, pPatchKeyValues ); + } + else + { + pMat = m_MaterialDict.AddMaterial( matNameWithExtension, pTextureGroupName ); + if ( g_pShaderDevice->IsUsingGraphics() ) + { + if ( !bIsUNC ) + { + m_pForcedTextureLoadPathID = "GAME"; + } + pMat->PrecacheVars( pKeyValues, pPatchKeyValues, &includes, nContext ); + m_pForcedTextureLoadPathID = NULL; + } + } + pKeyValues->deleteThis(); + pPatchKeyValues->deleteThis(); + + return pMat->GetQueueFriendlyVersion(); + } + + if ( bComplain ) + { + Assert( pTemp ); + + // convert to lowercase + nLen = Q_strlen(pTemp) + 1 ; + char *name = (char*)stackalloc( nLen ); + Q_strncpy( name, pTemp, nLen ); + Q_strlower( name ); + + if ( m_MaterialDict.NoteMissing( name ) ) + { + if ( pComplainPrefix ) + { + DevWarning( "%s", pComplainPrefix ); + } + DevWarning( "material \"%s\" not found.\n", name ); + } + } + + return g_pErrorMaterial->GetRealTimeVersion(); +} + +void CMaterialSystem::SetAsyncTextureLoadCache( void* h ) +{ + Assert( !h || !m_hAsyncLoadFileCache ); + m_hAsyncLoadFileCache = ( FileCacheHandle_t ) h; +} + +static char const *TextureAliases[] = +{ + // this table is only here for backwards compatibility where a render target change was made, + // and we wish to redirect an existing old client.dll for hl2 to reference this texture. It's + // not meant as a general texture aliasing system. + "_rt_FullFrameFB1", "_rt_FullScreen" +}; + +ITexture *CMaterialSystem::FindTexture( char const *pTextureName, const char *pTextureGroupName, bool bComplain /* = false */, int nAdditionalCreationFlags /* = 0 */ ) +{ + if ( m_hAsyncLoadFileCache && !TextureManager()->IsTextureLoaded( pTextureName ) ) + { + bool bIsUNCName = ( pTextureName[0] == '/' && pTextureName[1] == '/' && pTextureName[2] != '/' ); + if ( !bIsUNCName ) + { + const char* pPathID = "GAME"; + char buf[MAX_PATH]; + V_snprintf( buf, MAX_PATH, "materials/%s", pTextureName ); + V_SetExtension( buf, ".vtf", sizeof( buf ) ); + + const char *pbuf = buf; + g_pFullFileSystem->AddFilesToFileCache( m_hAsyncLoadFileCache, &pbuf, 1, pPathID ); + return TextureManager()->ErrorTexture(); + } + } + + ITextureInternal *pTexture = TextureManager()->FindOrLoadTexture( pTextureName, pTextureGroupName, nAdditionalCreationFlags ); + Assert( pTexture ); + if ( pTexture->IsError() ) + { + if ( IsPC() ) + { + for ( int i=0; iIsTextureLoaded( pTextureName ); +} + +void CMaterialSystem::AddTextureAlias( const char *pAlias, const char *pRealName ) +{ + TextureManager()->AddTextureAlias( pAlias, pRealName ); +} + +void CMaterialSystem::RemoveTextureAlias( const char *pAlias ) +{ + TextureManager()->RemoveTextureAlias( pAlias ); +} + +void CMaterialSystem::SetExcludedTextures( const char *pScriptName ) +{ + TextureManager()->SetExcludedTextures( pScriptName ); +} + +void CMaterialSystem::UpdateExcludedTextures( void ) +{ + TextureManager()->UpdateExcludedTextures(); + // Have to re-setup the representative textures since they may have been removed out from under us by the queued loader. + for (MaterialHandle_t i = FirstMaterial(); i != InvalidMaterial(); i = NextMaterial(i) ) + { + GetMaterialInternal(i)->FindRepresentativeTexture(); + GetMaterialInternal(i)->PrecacheMappingDimensions(); + } +} + +//----------------------------------------------------------------------------- +// Recomputes state snapshots for all materials +//----------------------------------------------------------------------------- +void CMaterialSystem::RecomputeAllStateSnapshots() +{ + g_pShaderAPI->ClearSnapshots(); + for (MaterialHandle_t i = FirstMaterial(); i != InvalidMaterial(); i = NextMaterial(i) ) + { + GetMaterialInternal(i)->RecomputeStateSnapshots(); + } + g_pShaderAPI->ResetRenderState(); +} + +//----------------------------------------------------------------------------- +// Suspend texture streaming operations, for abormal periods such as loading +//----------------------------------------------------------------------------- +void CMaterialSystem::SuspendTextureStreaming() +{ + TextureManager()->SuspendTextureStreaming(); +} + +//----------------------------------------------------------------------------- +// Inverse of SuspendTextureStreaming +//----------------------------------------------------------------------------- +void CMaterialSystem::ResumeTextureStreaming() +{ + TextureManager()->ResumeTextureStreaming(); +} + +//----------------------------------------------------------------------------- +// Uncache all materials +//----------------------------------------------------------------------------- +void CMaterialSystem::UncacheAllMaterials() +{ + MaterialLock_t hLock = Lock(); + Flush( true ); + + m_bReplacementFilesValid = false; + + for ( MaterialHandle_t i = FirstMaterial(); i != InvalidMaterial(); i = NextMaterial( i ) ) + { + Assert( GetMaterialInternal(i)->GetReferenceCount() >= 0 ); + GetMaterialInternal(i)->Uncache(); + } + TextureManager()->RemoveUnusedTextures(); + Unlock( hLock ); +} + + +//----------------------------------------------------------------------------- +// Uncache unused materials +//----------------------------------------------------------------------------- +void CMaterialSystem::UncacheUnusedMaterials( bool bRecomputeStateSnapshots ) +{ + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s", __FUNCTION__ ); + + MaterialLock_t hLock = Lock(); + Flush( true ); + + // We need two loops to make sure we don't reset the snapshots if nothing got removed, + // otherwise the snapshot recomputation is expensive and avoided at load time + bool bDidUncacheMaterial = false; + for ( MaterialHandle_t i = FirstMaterial(); i != InvalidMaterial(); i = NextMaterial(i) ) + { + IMaterialInternal *pMatInternal = GetMaterialInternal( i ); + Assert( pMatInternal->GetReferenceCount() >= 0 ); + if ( pMatInternal->GetReferenceCount() <= 0 ) + { + bDidUncacheMaterial = true; + pMatInternal->Uncache(); + } + } + + if ( IsX360() && bRecomputeStateSnapshots ) + { + // Always recompute snapshots because the queued loading process skips it during pre-purge, + // allowing it to happen just once, here. + bDidUncacheMaterial = true; + } + + if ( bDidUncacheMaterial && bRecomputeStateSnapshots ) + { + // Clear the state snapshots since we are going to rebuild all of them. + g_pShaderAPI->ClearSnapshots(); + g_pShaderAPI->ClearVertexAndPixelShaderRefCounts(); + + for ( MaterialHandle_t i = FirstMaterial(); i != InvalidMaterial(); i = NextMaterial(i) ) + { + IMaterialInternal *pMatInternal = GetMaterialInternal(i); + if ( pMatInternal->GetReferenceCount() > 0 ) + { + // Recompute the state snapshots for the materials that we are keeping + // since we blew all of them away above. + pMatInternal->RecomputeStateSnapshots(); + } + } + g_pShaderAPI->PurgeUnusedVertexAndPixelShaders(); + } + + if ( bRecomputeStateSnapshots ) + { + // kick out all per material context datas + for( MaterialHandle_t i = m_MaterialDict.FirstMaterial(); i != m_MaterialDict.InvalidMaterial(); i = m_MaterialDict.NextMaterial( i ) ) + { + GetMaterialInternal(i)->ClearContextData(); + } + } + + TextureManager()->RemoveUnusedTextures(); + Unlock( hLock ); +} + + +//----------------------------------------------------------------------------- +// Release temporary HW memory... +//----------------------------------------------------------------------------- +void CMaterialSystem::ResetTempHWMemory( bool bExitingLevel ) +{ + g_pShaderAPI->DestroyVertexBuffers( bExitingLevel ); + TextureManager()->ReleaseTempRenderTargetBits(); +} + + +//----------------------------------------------------------------------------- +// Cache used materials +//----------------------------------------------------------------------------- +void CMaterialSystem::CacheUsedMaterials( ) +{ + g_pShaderAPI->EvictManagedResources(); + size_t count = 0; + for (MaterialHandle_t i = FirstMaterial(); i != InvalidMaterial(); i = NextMaterial(i) ) + { + // Some (mac) drivers (amd) seem to keep extra resources around on uploads until the next frame swap. This + // injects pointless synthetic swaps (between already-static load frames) + if ( mat_texture_reload_frame_swap_workaround.GetBool() ) + { + if ( count++ % 20 == 0 ) + { + Flush(true); + SwapBuffers(); // Not the right thing to call + } + } + IMaterialInternal* pMat = GetMaterialInternal(i); + Assert( pMat->GetReferenceCount() >= 0 ); + if( pMat->GetReferenceCount() > 0 ) + { + pMat->Precache(); + } + } + if ( mat_forcemanagedtextureintohardware.GetBool() ) + { + TextureManager()->ForceAllTexturesIntoHardware(); + } +} + +//----------------------------------------------------------------------------- +// Reloads textures + materials +//----------------------------------------------------------------------------- +void CMaterialSystem::ReloadTextures( void ) +{ + // Add by jay in changelist 621420. + ForceSingleThreaded(); + + // 360 should not have gotten here + Assert( !IsX360() ); + + KeyValuesSystem()->InvalidateCache(); + + TextureManager()->RestoreRenderTargets(); + TextureManager()->RestoreNonRenderTargetTextures(); +} + +void CMaterialSystem::ReloadMaterials( const char *pSubString ) +{ + bool bDeviceReady = g_pShaderAPI->CanDownloadTextures(); + + if ( !bDeviceReady ) + { + //$ TODO: Merge m_bDeferredMaterialReload from cs:go? + Msg( "%s bDeviceReady false\n", __FUNCTION__ ); + } + + // Add by jay in changelist 621420. + ForceSingleThreaded(); + + KeyValuesSystem()->InvalidateCache(); + + bool bVertexFormatChanged = false; + if( pSubString == NULL ) + { + bVertexFormatChanged = true; + UncacheAllMaterials(); + CacheUsedMaterials(); + } + else + { + Flush( false ); + + char const chMultiDelim = '*'; + CUtlVector< char > arrSearchSubString; + CUtlVector< char const * > arrSearchItems; + + if ( strchr( pSubString, chMultiDelim ) ) + { + arrSearchSubString.SetCount( strlen( pSubString ) + 1 ); + strcpy( arrSearchSubString.Base(), pSubString ); + for ( char * pch = arrSearchSubString.Base(); pch; ) + { + char *pchEnd = strchr( pch, chMultiDelim ); + pchEnd ? *( pchEnd ++ ) = 0 : 0; + arrSearchItems.AddToTail( pch ); + pch = pchEnd; + } + } + + for (MaterialHandle_t i = FirstMaterial(); i != InvalidMaterial(); i = NextMaterial(i) ) + { + if( GetMaterialInternal(i)->GetReferenceCount() <= 0 ) + continue; + + char const *szMatName = GetMaterialInternal(i)->GetName(); + + if ( arrSearchItems.Count() > 1 ) + { + bool bMatched = false; + + for ( int k = 0; !bMatched && ( k < arrSearchItems.Count() ); ++ k ) + if( Q_stristr( szMatName, arrSearchItems[k] ) ) + bMatched = true; + + if ( !bMatched ) + continue; + } + else + { + if( !Q_stristr( szMatName, pSubString ) ) + continue; + } + + if ( !GetMaterialInternal(i)->IsPrecached() ) + { + if ( GetMaterialInternal(i)->IsPrecachedVars() ) + { + GetMaterialInternal(i)->Uncache( ); + } + } + else + { + VertexFormat_t oldVertexFormat = GetMaterialInternal(i)->GetVertexFormat(); + GetMaterialInternal(i)->Uncache(); + GetMaterialInternal(i)->Precache(); + GetMaterialInternal(i)->ReloadTextures(); + if( GetMaterialInternal(i)->GetVertexFormat() != oldVertexFormat ) + { + bVertexFormatChanged = true; + } + } + } + } + + if( bVertexFormatChanged && bDeviceReady ) + { + // Reloading materials could cause a vertex format change, so + // we need to release and restore + ReleaseShaderObjects(); + RestoreShaderObjects( NULL, MATERIAL_RESTORE_VERTEX_FORMAT_CHANGED ); + } +} + +//----------------------------------------------------------------------------- +// Allocates the standard textures used by the material system +//----------------------------------------------------------------------------- +void CMaterialSystem::AllocateStandardTextures() +{ + if ( m_StandardTexturesAllocated ) + return; + + m_StandardTexturesAllocated = true; + + float nominal_lightmap_value = 1.0; + if ( HardwareConfig()->GetHDRType() == HDR_TYPE_INTEGER ) + nominal_lightmap_value = 1.0/16.0; + + unsigned char texel[4]; + texel[3] = 255; + + int tcFlags = TEXTURE_CREATE_MANAGED; + int tcFlagsSRGB = TEXTURE_CREATE_MANAGED | TEXTURE_CREATE_SRGB; + + if ( IsX360() ) + { + tcFlags |= TEXTURE_CREATE_CANCONVERTFORMAT; + tcFlagsSRGB |= TEXTURE_CREATE_CANCONVERTFORMAT; + } + + // allocate a white, single texel texture for the fullbright lightmap + // note: make sure and redo this when changing gamma, etc. + // don't mipmap lightmaps + m_FullbrightLightmapTextureHandle = g_pShaderAPI->CreateTexture( 1, 1, 1, IMAGE_FORMAT_BGRX8888, 1, 1, tcFlags, "[FULLBRIGHT_LIGHTMAP_TEXID]", TEXTURE_GROUP_LIGHTMAP ); + g_pShaderAPI->ModifyTexture( m_FullbrightLightmapTextureHandle ); + g_pShaderAPI->TexMinFilter( SHADER_TEXFILTERMODE_LINEAR ); + g_pShaderAPI->TexMagFilter( SHADER_TEXFILTERMODE_LINEAR ); + float tmpVect[3] = { nominal_lightmap_value, nominal_lightmap_value, nominal_lightmap_value }; + ColorSpace::LinearToLightmap( texel, tmpVect ); + g_pShaderAPI->TexImage2D( 0, 0, IMAGE_FORMAT_BGRX8888, 0, 1, 1, IMAGE_FORMAT_BGRX8888, false, texel ); + + // allocate a black single texel texture +#if !defined( _X360 ) + m_BlackTextureHandle = g_pShaderAPI->CreateTexture( 1, 1, 1, IMAGE_FORMAT_BGRX8888, 1, 1, tcFlagsSRGB, "[BLACK_TEXID]", TEXTURE_GROUP_OTHER ); + g_pShaderAPI->ModifyTexture( m_BlackTextureHandle ); + g_pShaderAPI->TexMinFilter( SHADER_TEXFILTERMODE_LINEAR ); + g_pShaderAPI->TexMagFilter( SHADER_TEXFILTERMODE_LINEAR ); + texel[0] = texel[1] = texel[2] = 0; + g_pShaderAPI->TexImage2D( 0, 0, IMAGE_FORMAT_BGRX8888, 0, 1, 1, IMAGE_FORMAT_BGRX8888, false, texel ); +#else + m_BlackTextureHandle = ((ITextureInternal*)FindTexture( "black", TEXTURE_GROUP_OTHER, true ))->GetTextureHandle( 0 ); +#endif + g_pShaderAPI->SetStandardTextureHandle( TEXTURE_BLACK, m_BlackTextureHandle ); + + // allocate a fully white single texel texture +#if !defined( _X360 ) + m_WhiteTextureHandle = g_pShaderAPI->CreateTexture( 1, 1, 1, IMAGE_FORMAT_BGRX8888, 1, 1, tcFlagsSRGB, "[WHITE_TEXID]", TEXTURE_GROUP_OTHER ); + g_pShaderAPI->ModifyTexture( m_WhiteTextureHandle ); + g_pShaderAPI->TexMinFilter( SHADER_TEXFILTERMODE_LINEAR ); + g_pShaderAPI->TexMagFilter( SHADER_TEXFILTERMODE_LINEAR ); + texel[0] = texel[1] = texel[2] = 255; + g_pShaderAPI->TexImage2D( 0, 0, IMAGE_FORMAT_BGRX8888, 0, 1, 1, IMAGE_FORMAT_BGRX8888, false, texel ); +#else + m_WhiteTextureHandle = ((ITextureInternal*)FindTexture( "white", TEXTURE_GROUP_OTHER, true ))->GetTextureHandle( 0 ); +#endif + g_pShaderAPI->SetStandardTextureHandle( TEXTURE_WHITE, m_WhiteTextureHandle ); + + // allocate a grey single texel texture with an alpha of zero (for mat_fullbright 2) +#if !defined( _X360 ) + m_GreyTextureHandle = g_pShaderAPI->CreateTexture( 1, 1, 1, IMAGE_FORMAT_BGRX8888, 1, 1, tcFlagsSRGB, "[GREY_TEXID]", TEXTURE_GROUP_OTHER ); + g_pShaderAPI->ModifyTexture( m_GreyTextureHandle ); + g_pShaderAPI->TexMinFilter( SHADER_TEXFILTERMODE_LINEAR ); + g_pShaderAPI->TexMagFilter( SHADER_TEXFILTERMODE_LINEAR ); + texel[0] = texel[1] = texel[2] = 128; + texel[3] = 255; // needs to be 255 so that mat_fullbright 2 stuff isn't translucent. + g_pShaderAPI->TexImage2D( 0, 0, IMAGE_FORMAT_BGRX8888, 0, 1, 1, IMAGE_FORMAT_BGRX8888, false, texel ); +#else + m_GreyTextureHandle = ((ITextureInternal*)FindTexture( "grey", TEXTURE_GROUP_OTHER, true ))->GetTextureHandle( 0 ); +#endif + g_pShaderAPI->SetStandardTextureHandle( TEXTURE_GREY, m_GreyTextureHandle ); + + // allocate a grey single texel texture with an alpha of zero (for mat_fullbright 2) +#if !defined( _X360 ) + m_GreyAlphaZeroTextureHandle = g_pShaderAPI->CreateTexture( 1, 1, 1, IMAGE_FORMAT_RGBA8888, 1, 1, tcFlagsSRGB, "[GREYALPHAZERO_TEXID]", TEXTURE_GROUP_OTHER ); + g_pShaderAPI->ModifyTexture( m_GreyAlphaZeroTextureHandle ); + g_pShaderAPI->TexMinFilter( SHADER_TEXFILTERMODE_LINEAR ); + g_pShaderAPI->TexMagFilter( SHADER_TEXFILTERMODE_LINEAR ); + texel[0] = texel[1] = texel[2] = 128; + texel[3] = 0; // needs to be 0 so that self-illum doens't affect mat_fullbright 2 + g_pShaderAPI->TexImage2D( 0, 0, IMAGE_FORMAT_RGBA8888, 0, 1, 1, IMAGE_FORMAT_RGBA8888, false, texel ); + texel[3] = 255; // set back to default value so we don't affect the rest of this code.' +#else + m_GreyAlphaZeroTextureHandle = ((ITextureInternal*)FindTexture( "greyalphazero", TEXTURE_GROUP_OTHER, true ))->GetTextureHandle( 0 ); +#endif + g_pShaderAPI->SetStandardTextureHandle( TEXTURE_GREY_ALPHA_ZERO, m_GreyAlphaZeroTextureHandle ); + + // allocate a single texel flat normal texture lightmap + m_FlatNormalTextureHandle = g_pShaderAPI->CreateTexture( 1, 1, 1, IMAGE_FORMAT_BGRX8888, 1, 1, tcFlags, "[FLAT_NORMAL_TEXTURE]", TEXTURE_GROUP_OTHER ); + g_pShaderAPI->ModifyTexture( m_FlatNormalTextureHandle ); + g_pShaderAPI->TexMinFilter( SHADER_TEXFILTERMODE_LINEAR ); + g_pShaderAPI->TexMagFilter( SHADER_TEXFILTERMODE_LINEAR ); + texel[0] = 255; // B + texel[1] = 127; // G + texel[2] = 127; // R + g_pShaderAPI->TexImage2D( 0, 0, IMAGE_FORMAT_BGRX8888, 0, 1, 1, IMAGE_FORMAT_BGRX8888, false, texel ); + g_pShaderAPI->SetStandardTextureHandle( TEXTURE_NORMALMAP_FLAT, m_FlatNormalTextureHandle ); + + // allocate a single texel fullbright 1 lightmap for use with bump textures + m_FullbrightBumpedLightmapTextureHandle = g_pShaderAPI->CreateTexture( 1, 1, 1, IMAGE_FORMAT_BGRX8888, 1, 1, tcFlags, "[FULLBRIGHT_BUMPED_LIGHTMAP_TEXID]", TEXTURE_GROUP_LIGHTMAP ); + g_pShaderAPI->ModifyTexture( m_FullbrightBumpedLightmapTextureHandle ); + g_pShaderAPI->TexMinFilter( SHADER_TEXFILTERMODE_LINEAR ); + g_pShaderAPI->TexMagFilter( SHADER_TEXFILTERMODE_LINEAR ); + float linearColor[3] = { nominal_lightmap_value, nominal_lightmap_value, nominal_lightmap_value }; + unsigned char dummy[3]; + ColorSpace::LinearToBumpedLightmap( linearColor, linearColor, linearColor, linearColor, + dummy, texel, dummy, dummy ); + g_pShaderAPI->TexImage2D( 0, 0, IMAGE_FORMAT_BGRX8888, 0, 1, 1, IMAGE_FORMAT_BGRX8888, false, texel ); + g_pShaderAPI->SetStandardTextureHandle( TEXTURE_LIGHTMAP_BUMPED_FULLBRIGHT, m_FullbrightBumpedLightmapTextureHandle ); + + { + int iGammaLookupFlags = tcFlags; + ImageFormat gammalookupfmt; + gammalookupfmt = IMAGE_FORMAT_I8; + + // generate the linear->gamma conversion table texture. + { + const int LINEAR_TO_GAMMA_TABLE_WIDTH = 512; + m_LinearToGammaTableTextureHandle = g_pShaderAPI->CreateTexture( LINEAR_TO_GAMMA_TABLE_WIDTH, 1, 1, gammalookupfmt, 1, 1, iGammaLookupFlags, "[LINEAR_TO_GAMMA_LOOKUP_SRGBON_TEXID]", TEXTURE_GROUP_PIXEL_SHADERS ); + g_pShaderAPI->ModifyTexture( m_LinearToGammaTableTextureHandle ); + g_pShaderAPI->TexMinFilter( SHADER_TEXFILTERMODE_LINEAR ); + g_pShaderAPI->TexMagFilter( SHADER_TEXFILTERMODE_LINEAR ); + g_pShaderAPI->TexWrap( SHADER_TEXCOORD_S, SHADER_TEXWRAPMODE_CLAMP ); + g_pShaderAPI->TexWrap( SHADER_TEXCOORD_T, SHADER_TEXWRAPMODE_CLAMP ); + g_pShaderAPI->TexWrap( SHADER_TEXCOORD_U, SHADER_TEXWRAPMODE_CLAMP ); + + float pixelData[LINEAR_TO_GAMMA_TABLE_WIDTH]; //sometimes used as float, sometimes as uint8, sizeof(float) > sizeof(uint8) + for( int i = 0; i != LINEAR_TO_GAMMA_TABLE_WIDTH; ++i ) + { + float fLookupResult = ((float)i) / ((float)(LINEAR_TO_GAMMA_TABLE_WIDTH - 1)); + fLookupResult = g_pShaderAPI->LinearToGamma_HardwareSpecific( fLookupResult ); + + //do an extra srgb conversion because we'll be converting back on texture read + fLookupResult = g_pShaderAPI->LinearToGamma_HardwareSpecific( fLookupResult ); //that's right, linear->gamma->gamma2x so that that gamma->linear srgb read still ends up in gamma + + int iColor = RoundFloatToInt( fLookupResult * 255.0f ); + if( iColor > 255 ) + iColor = 255; + + ((uint8 *)pixelData)[i] = (uint8)iColor; + } + + g_pShaderAPI->TexImage2D( 0, 0, gammalookupfmt, 0, LINEAR_TO_GAMMA_TABLE_WIDTH, 1, gammalookupfmt, false, (void *)pixelData ); + } + + // generate the identity conversion table texture. + { + const int LINEAR_TO_GAMMA_IDENTITY_TABLE_WIDTH = 256; + m_LinearToGammaIdentityTableTextureHandle = g_pShaderAPI->CreateTexture( LINEAR_TO_GAMMA_IDENTITY_TABLE_WIDTH, 1, 1, gammalookupfmt, 1, 1, tcFlags, "[LINEAR_TO_GAMMA_LOOKUP_SRGBOFF_TEXID]", TEXTURE_GROUP_PIXEL_SHADERS ); + g_pShaderAPI->ModifyTexture( m_LinearToGammaIdentityTableTextureHandle ); + g_pShaderAPI->TexMinFilter( SHADER_TEXFILTERMODE_LINEAR ); + g_pShaderAPI->TexMagFilter( SHADER_TEXFILTERMODE_LINEAR ); + g_pShaderAPI->TexWrap( SHADER_TEXCOORD_S, SHADER_TEXWRAPMODE_CLAMP ); + g_pShaderAPI->TexWrap( SHADER_TEXCOORD_T, SHADER_TEXWRAPMODE_CLAMP ); + g_pShaderAPI->TexWrap( SHADER_TEXCOORD_U, SHADER_TEXWRAPMODE_CLAMP ); + + float pixelData[LINEAR_TO_GAMMA_IDENTITY_TABLE_WIDTH]; //sometimes used as float, sometimes as uint8, sizeof(float) > sizeof(uint8) + for( int i = 0; i != LINEAR_TO_GAMMA_IDENTITY_TABLE_WIDTH; ++i ) + { + float fLookupResult = ((float)i) / ((float)(LINEAR_TO_GAMMA_IDENTITY_TABLE_WIDTH - 1)); + + //do an extra srgb conversion because we'll be converting back on texture read + fLookupResult = g_pShaderAPI->LinearToGamma_HardwareSpecific( fLookupResult ); + + int iColor = RoundFloatToInt( fLookupResult * 255.0f ); + if ( iColor > 255 ) + iColor = 255; + + ((uint8 *)pixelData)[i] = (uint8)iColor; + } + + g_pShaderAPI->TexImage2D( 0, 0, gammalookupfmt, 0, LINEAR_TO_GAMMA_IDENTITY_TABLE_WIDTH, 1, gammalookupfmt, false, (void *)pixelData ); + } + } + + //create the maximum depth texture + { + m_MaxDepthTextureHandle = g_pShaderAPI->CreateTexture( 1, 1, 1, IMAGE_FORMAT_RGBA8888, 1, 1, tcFlags, "[MAXDEPTH_TEXID]", TEXTURE_GROUP_OTHER ); + g_pShaderAPI->ModifyTexture( m_MaxDepthTextureHandle ); + g_pShaderAPI->TexMinFilter( SHADER_TEXFILTERMODE_LINEAR ); + g_pShaderAPI->TexMagFilter( SHADER_TEXFILTERMODE_LINEAR ); + + //360 gets depth out of the red channel (which doubles as depth in D24S8) and may be 0/1 depending on REVERSE_DEPTH_ON_X360 + //PC gets depth out of the alpha channel + texel[0] = texel[1] = texel[2] = ReverseDepthOnX360() ? 0 : 255; + texel[3] = 255; + + g_pShaderAPI->TexImage2D( 0, 0, IMAGE_FORMAT_RGBA8888, 0, 1, 1, IMAGE_FORMAT_RGBA8888, false, texel ); + } + + //only the shaderapi can handle switching between textures correctly, so pass off the textures to it. + g_pShaderAPI->SetLinearToGammaConversionTextures( m_LinearToGammaTableTextureHandle, m_LinearToGammaIdentityTableTextureHandle ); +} + +void CMaterialSystem::ReleaseStandardTextures() +{ + if ( m_StandardTexturesAllocated ) + { + if ( IsPC() ) + { + g_pShaderAPI->DeleteTexture( m_BlackTextureHandle ); + g_pShaderAPI->DeleteTexture( m_WhiteTextureHandle ); + g_pShaderAPI->DeleteTexture( m_GreyTextureHandle ); + g_pShaderAPI->DeleteTexture( m_GreyAlphaZeroTextureHandle ); + } + g_pShaderAPI->DeleteTexture( m_FullbrightLightmapTextureHandle ); + g_pShaderAPI->DeleteTexture( m_FlatNormalTextureHandle ); + g_pShaderAPI->DeleteTexture( m_FullbrightBumpedLightmapTextureHandle ); + + g_pShaderAPI->DeleteTexture( m_LinearToGammaTableTextureHandle ); + g_pShaderAPI->DeleteTexture( m_LinearToGammaIdentityTableTextureHandle ); + g_pShaderAPI->SetLinearToGammaConversionTextures( INVALID_SHADERAPI_TEXTURE_HANDLE, INVALID_SHADERAPI_TEXTURE_HANDLE ); + + g_pShaderAPI->DeleteTexture( m_MaxDepthTextureHandle ); + + m_StandardTexturesAllocated = false; + } +} + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +void CMaterialSystem::BeginFrame( float frameTime ) +{ + // Safety measure (calls should only come from the main thread, also check correct pairing) + if ( !ThreadInMainThread() || IsInFrame() ) + return; + + // check debug vars. we will use these to setup g_nDebugVarsSignature so that materials will + // rebuild their draw lists when debug modes changed. + g_nDebugVarsSignature = ( + (mat_specular.GetInt() != 0 ) + ( mat_normalmaps.GetInt() << 1 ) + + ( mat_fullbright.GetInt() << 2 ) + (mat_fastnobump.GetInt() << 4 ) ) << 24; + + + Assert( m_bGeneratedConfig ); + + VPROF_BUDGET( "CMaterialSystem::BeginFrame", VPROF_BUDGETGROUP_SWAP_BUFFERS ); + tmZoneFiltered( TELEMETRY_LEVEL0, 50, TMZF_NONE, "%s", __FUNCTION__ ); + + IMatRenderContextInternal *pRenderContext = GetRenderContextInternal(); + if ( g_config.ForceHWSync() && (IsPC() || m_ThreadMode != MATERIAL_QUEUED_THREADED) ) + { + tmZoneFiltered( TELEMETRY_LEVEL0, 50, TMZF_NONE, "ForceHardwareSync" ); + pRenderContext->ForceHardwareSync(); + } + + pRenderContext->MarkRenderDataUnused( true ); + pRenderContext->BeginFrame(); + pRenderContext->SetFrameTime( frameTime ); + pRenderContext->SetToneMappingScaleLinear( Vector( 1,1,1) ); + + Assert( !m_bInFrame ); + m_bInFrame = true; +} + +bool CMaterialSystem::IsInFrame( ) const +{ + return m_bInFrame; +} + +#ifdef RAD_TELEMETRY_ENABLED +static const char *GetMatString( enum MaterialThreadMode_t ThreadMode ) +{ + switch( ThreadMode ) + { + case MATERIAL_SINGLE_THREADED: return "single"; + case MATERIAL_QUEUED_SINGLE_THREADED: return "queued_single"; + case MATERIAL_QUEUED_THREADED: return "queued_threaded"; + default: return "???"; + } +} +#endif + +ConVar mat_queue_mode( "mat_queue_mode", "-1", FCVAR_ARCHIVE, "The queue/thread mode the material system should use: -1=default, 0=synchronous single thread" +#ifdef MAT_QUEUE_MODE_PROFILE + ", 1=queued single thread" +#endif + ", 2=queued multithreaded" ); + +ConVar mat_queue_report( "mat_queue_report", "0", FCVAR_ARCHIVE, "Report thread stalls. Positive number will filter by stalls >= time in ms. -1 reports all locks." ); + +void CMaterialSystem::ThreadExecuteQueuedContext( CMatQueuedRenderContext *pContext ) +{ +#ifdef RAD_TELEMETRY_ENABLED + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s-%s", __FUNCTION__, GetMatString( m_ThreadMode ) ); + CTelemetrySpikeDetector Spike( "ThreadExecuteQueuedContext", 1 ); +#endif + + Assert( m_bThreadHasOwnership ); + + m_nRenderThreadID = ThreadGetCurrentId(); + IMatRenderContextInternal* pSavedRenderContext = m_pRenderContext.Get(); + m_pRenderContext.Set( &m_HardwareRenderContext ); + pContext->EndQueue( true ); + m_pRenderContext.Set( pSavedRenderContext ); + m_nRenderThreadID = 0xFFFFFFFF; +} + +IThreadPool *CMaterialSystem::CreateMatQueueThreadPool() +{ + if( IsX360() ) + { + return g_pThreadPool; + } + else if( !m_pMatQueueThreadPool ) + { + ThreadPoolStartParams_t startParams; + + startParams.nThreads = 1; + startParams.nStackSize = 256*1024; + startParams.fDistribute = TRS_TRUE; + + // The rendering thread has the GL context and the main thread is coming in and + // "helping" finish jobs - that breaks OpenGL, which requires TLS. This flag states + // that only the threadpool threads should execute these jobs. + startParams.bExecOnThreadPoolThreadsOnly = true; + + m_pMatQueueThreadPool = CreateThreadPool(); + m_pMatQueueThreadPool->Start( startParams, "MatQueue" ); + } + + return m_pMatQueueThreadPool; +} + +void CMaterialSystem::DestroyMatQueueThreadPool() +{ + if( m_pMatQueueThreadPool ) + { + m_pMatQueueThreadPool->Stop(); + delete m_pMatQueueThreadPool; + m_pMatQueueThreadPool = NULL; + } +} + + +//----------------------------------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------------------------------- +class CThreadAcquire : public CJob +{ + virtual JobStatus_t DoExecute() + { + g_pShaderAPI->AcquireThreadOwnership(); + + return JOB_OK; + } +}; + +void CMaterialSystem::EndFrame( void ) +{ + // Safety measure (calls should only come from the main thread, also check correct pairing) + if ( !ThreadInMainThread() || !IsInFrame() ) + return; + + Assert( m_bGeneratedConfig ); + VPROF_BUDGET( "CMaterialSystem::EndFrame", VPROF_BUDGETGROUP_SWAP_BUFFERS ); + + GetRenderContextInternal()->EndFrame(); + + TextureManager()->Update(); + + while ( !m_scheduledComposites.IsEmpty() ) + { + // We hold a ref, so if there's only one count left, it's us. Let it go and move on. + if ( m_scheduledComposites[ 0 ]->GetRefCount() == 1 ) + { + m_scheduledComposites[ 0 ]->Release(); + m_scheduledComposites.Remove( 0 ); + continue; + } + + m_scheduledComposites[ 0 ]->Resolve(); + m_pendingComposites.AddToTail( m_scheduledComposites[ 0 ] ); + + m_scheduledComposites.Remove( 0 ); + + // Only do one per frame, because these can actually be fairly expensive. + break; + } + + FOR_EACH_VEC( m_pendingComposites, i ) + { + CTextureCompositor* comp = m_pendingComposites[ i ]; + + // We hold a ref, so if there's only one count left, it's us. Let it go and move on. + if ( comp->GetRefCount() == 1 ) + { + comp->Release(); + m_pendingComposites.Remove( i ); + // Back up one + --i; + continue; + } + + comp->Update(); + + if ( comp->GetResolveStatus() == ECRS_Complete || comp->GetResolveStatus() == ECRS_Error ) + { + comp->Release(); + m_pendingComposites.Remove( i ); + + // Stop after the first one reports that it was completed, these can take awhile and + // we don't want to hammer anyone's framerate. + break; + } + } + + //------------------------------------------------------------- + + int iConVarThreadMode = mat_queue_mode.GetInt(); + + // For this testing release, -2 is equivalent to 0 (off). When we release, we'll make -2 equivalent to -1 (on) + if ( iConVarThreadMode == -2 ) + { + iConVarThreadMode = MATERIAL_QUEUED_THREADED; + } + +#ifndef MAT_QUEUE_MODE_PROFILE + if ( iConVarThreadMode == MATERIAL_QUEUED_SINGLE_THREADED ) + { + iConVarThreadMode = MATERIAL_SINGLE_THREADED; + } +#endif + + MaterialThreadMode_t nextThreadMode = ( iConVarThreadMode >= 0 ) ? (MaterialThreadMode_t)iConVarThreadMode : m_IdealThreadMode; + // note: This is a hack because there is no explicit query for the device being deactivated due to device lost. + // however, that is all the current implementation of CanDownloadTextures actually does. + bool bDeviceReady = g_pShaderAPI->CanDownloadTextures(); + if ( !bDeviceReady || !m_bAllowQueuedRendering ) + { + nextThreadMode = MATERIAL_SINGLE_THREADED; + } + + if ( m_bForcedSingleThreaded || m_bThreadingNotAvailable ) + { + nextThreadMode = MATERIAL_SINGLE_THREADED; + m_bForcedSingleThreaded = false; + } + + switch ( m_ThreadMode ) + { + case MATERIAL_SINGLE_THREADED: + OnRenderingAsyncComplete(); + break; + + case MATERIAL_QUEUED_THREADED: + { + VPROF_BUDGET( "Mat_ThreadedEndframe", "Mat_ThreadedEndframe" ); + if ( !m_bThreadHasOwnership ) + { + ThreadAcquire( true ); + } + + if ( m_pActiveAsyncJob && !m_pActiveAsyncJob->IsFinished() ) + { + m_pActiveAsyncJob->WaitForFinish(); + if ( !IsPC() && g_config.ForceHWSync() ) + { + g_pShaderAPI->ForceHardwareSync(); + } + } + SafeRelease( m_pActiveAsyncJob ); + + OnRenderingAsyncComplete(); + + CMatQueuedRenderContext *pPrevContext = &m_QueuedRenderContexts[m_iCurQueuedContext]; + + m_iCurQueuedContext = ( ( m_iCurQueuedContext + 1 ) % ARRAYSIZE( m_QueuedRenderContexts) ); + m_QueuedRenderContexts[m_iCurQueuedContext].BeginQueue( pPrevContext ); + m_pRenderContext.Set( &m_QueuedRenderContexts[m_iCurQueuedContext] ); + + m_pActiveAsyncJob = new CFunctorJob( CreateFunctor( this, &CMaterialSystem::ThreadExecuteQueuedContext, pPrevContext ), "ThreadExecuteQueuedContext" ); + if ( IsX360() ) + { + if ( m_nServiceThread >= 0 ) + { + m_pActiveAsyncJob->SetServiceThread( m_nServiceThread ); + } + } + + IThreadPool *pThreadPool = CreateMatQueueThreadPool(); + pThreadPool->AddJob( m_pActiveAsyncJob ); + break; + } + + case MATERIAL_QUEUED_SINGLE_THREADED: + OnRenderingAsyncComplete(); + break; + +#ifdef MAT_QUEUE_MODE_PROFILE + { + VPROF_BUDGET( "Mat_ThreadedEndframe", "Mat_QueuedEndframe" ); + + g_pShaderAPI->SetDisallowAccess( false ); + m_pRenderContext.Set( &m_HardwareRenderContext ); + m_QueuedRenderContexts[m_iCurQueuedContext].CallQueued(); + m_pRenderContext.Set( &m_QueuedRenderContexts[m_iCurQueuedContext] ); + g_pShaderAPI->SetDisallowAccess( true ); + break; + } +#endif + } + + bool bRelease = false; + if ( !bDeviceReady ) + { + if ( nextThreadMode != MATERIAL_SINGLE_THREADED ) + { + Assert( nextThreadMode == MATERIAL_SINGLE_THREADED ); + bRelease = true; + nextThreadMode = MATERIAL_SINGLE_THREADED; + if( mat_debugalttab.GetBool() ) + { + Warning("Handling alt-tab in queued mode!\n"); + } + } + } + + if ( m_threadEvents.Count() ) + { + nextThreadMode = MATERIAL_SINGLE_THREADED; + } + + if ( m_ThreadMode != nextThreadMode ) + { + // Shut down the current mode & set new mode + switch ( m_ThreadMode ) + { + case MATERIAL_SINGLE_THREADED: + break; + + case MATERIAL_QUEUED_THREADED: + { + if ( m_pActiveAsyncJob ) + { + m_pActiveAsyncJob->WaitForFinish(); + SafeRelease( m_pActiveAsyncJob ); + } + // probably have a queued context set here, need hardware to flush the queue if the job isn't active + m_HardwareRenderContext.InitializeFrom(&m_QueuedRenderContexts[m_iCurQueuedContext]); + m_pRenderContext.Set( &m_HardwareRenderContext ); + + m_QueuedRenderContexts[m_iCurQueuedContext].EndQueue( true ); + ThreadRelease(); + } + break; + +#ifdef MAT_QUEUE_MODE_PROFILE + case MATERIAL_QUEUED_SINGLE_THREADED: + { + g_pShaderAPI->SetDisallowAccess( false ); + // We have a queued context set here, need hardware to flush the queue if the job isn't active + m_pRenderContext.Set( &m_HardwareRenderContext ); + m_QueuedRenderContexts[m_iCurQueuedContext].EndQueue( true ); + break; + } +#endif + } + + m_ThreadMode = nextThreadMode; + Assert( g_MatSysMutex.GetOwnerId() == 0 ); + + g_pShaderAPI->EnableShaderShaderMutex( m_ThreadMode != MATERIAL_SINGLE_THREADED ); // use mutex even for queued to allow "disalow access" to function properly + g_pShaderAPI->EnableBuffer2FramesAhead( true ); + + switch ( m_ThreadMode ) + { + case MATERIAL_SINGLE_THREADED: + m_pRenderContext.Set( &m_HardwareRenderContext ); + for ( int i = 0; i < ARRAYSIZE( m_QueuedRenderContexts ); i++ ) + { + Assert( m_QueuedRenderContexts[i].IsInitialized() ); + m_QueuedRenderContexts[i].EndQueue( true ); + } + break; + +#ifdef MAT_QUEUE_MODE_PROFILE + case MATERIAL_QUEUED_SINGLE_THREADED: +#endif + case MATERIAL_QUEUED_THREADED: + { + m_iCurQueuedContext = 0; + m_QueuedRenderContexts[m_iCurQueuedContext].BeginQueue( &m_HardwareRenderContext ); + m_pRenderContext.Set( &m_QueuedRenderContexts[m_iCurQueuedContext] ); +#ifdef MAT_QUEUE_MODE_PROFILE + if ( m_ThreadMode == MATERIAL_QUEUED_SINGLE_THREADED ) + { + g_pShaderAPI->SetDisallowAccess( true ); + } + else +#endif + { + g_pShaderAPI->ReleaseThreadOwnership(); + + CJob *pActiveAsyncJob = new CThreadAcquire(); + IThreadPool *pThreadPool = CreateMatQueueThreadPool(); + pThreadPool->AddJob( pActiveAsyncJob ); + SafeRelease( pActiveAsyncJob ); + + m_bThreadHasOwnership = true; + m_ThreadOwnershipID = ThreadGetCurrentId(); + } + } + break; + } + } + + if ( m_ThreadMode == MATERIAL_SINGLE_THREADED ) + { + for ( int i = 0; i < m_threadEvents.Count(); i++ ) + { + g_pShaderDevice->HandleThreadEvent(m_threadEvents[i]); + } + m_threadEvents.RemoveAll(); + } + Assert( m_bInFrame ); + m_bInFrame = false; +} + +void CMaterialSystem::SetInStubMode( bool bInStubMode ) +{ + m_bInStubMode = bInStubMode; +} + +bool CMaterialSystem::IsInStubMode() +{ + return m_bInStubMode; +} + +void CMaterialSystem::Flush( bool flushHardware ) +{ + GetRenderContextInternal()->Flush( flushHardware ); +} + + +//----------------------------------------------------------------------------- +// Flushes managed textures from the texture cacher +//----------------------------------------------------------------------------- +void CMaterialSystem::EvictManagedResources() +{ + g_pShaderAPI->EvictManagedResources(); +} + +int __cdecl MaterialNameCompareFunc( const void *elem1, const void *elem2 ) +{ + IMaterialInternal *pMaterialA = g_MaterialSystem.GetMaterialInternal( *(MaterialHandle_t *)elem1 ); + IMaterialInternal *pMaterialB = g_MaterialSystem.GetMaterialInternal( *(MaterialHandle_t *)elem2 ); + + // case insensitive to group similar named materials + return stricmp( pMaterialA->GetName(), pMaterialB->GetName() ); +} + +void CMaterialSystem::DebugPrintUsedMaterials( const char *pSearchSubString, bool bVerbose ) +{ + MaterialHandle_t h; + int i; + int nNumCached; + int nRefCount; + int nSortedMaterials; + int nNumErrors; + + // build a mapping to sort the material names + MaterialHandle_t *pSorted = (MaterialHandle_t*)stackalloc( GetNumMaterials() * sizeof(MaterialHandle_t) ); + nSortedMaterials = 0; + for (h = FirstMaterial(); h != InvalidMaterial(); h = NextMaterial(h) ) + { + pSorted[nSortedMaterials++] = h; + } + qsort( pSorted, nSortedMaterials, sizeof(MaterialHandle_t), MaterialNameCompareFunc ); + + nNumCached = 0; + nNumErrors = 0; + for (i = 0; i < nSortedMaterials; i++) + { + // iterate using sort mapping + IMaterialInternal *pMaterial = GetMaterialInternal(pSorted[i]); + + nRefCount = pMaterial->GetReferenceCount(); + + if ( nRefCount < 0 ) + { + nNumErrors++; + } + else if (!nRefCount) + { + if (pMaterial->IsPrecached() || pMaterial->IsPrecachedVars()) + { + nNumErrors++; + } + } + else + { + // nonzero reference count + // tally the valid ones + nNumCached++; + + if( pSearchSubString ) + { + if( !Q_stristr( pMaterial->GetName(), pSearchSubString ) && + (!pMaterial->GetShader() || !Q_stristr( pMaterial->GetShader()->GetName(), pSearchSubString )) ) + { + continue; + } + } + + DevMsg( "%s (shader: %s) refCount: %d.\n", pMaterial->GetName(), + pMaterial->GetShader() ? pMaterial->GetShader()->GetName() : "unknown\n", nRefCount ); + + if( !bVerbose ) + { + continue; + } + + if( pMaterial->IsPrecached() ) + { + if( pMaterial->GetShader() ) + { + for( int j = 0; j < pMaterial->GetShader()->GetNumParams(); j++ ) + { + IMaterialVar *var; + var = pMaterial->GetShaderParams()[j]; + + if( var ) + { + switch( var->GetType() ) + { + case MATERIAL_VAR_TYPE_TEXTURE: + { + ITextureInternal *texture = static_cast( var->GetTextureValue() ); + if( !texture ) + { + DevWarning( "Programming error: CMaterialSystem::DebugPrintUsedMaterialsCallback: NULL texture\n" ); + continue; + } + + if( IsTextureInternalEnvCubemap( texture ) ) + { + DevMsg( " \"%s\" \"env_cubemap\"\n", var->GetName() ); + } + else + { + DevMsg( " \"%s\" \"%s\"\n", + var->GetName(), + texture->GetName() ); + DevMsg( " %dx%d refCount: %d numframes: %d\n", texture->GetActualWidth(), texture->GetActualHeight(), + texture->GetReferenceCount(), texture->GetNumAnimationFrames() ); + } + } + break; + case MATERIAL_VAR_TYPE_UNDEFINED: + break; + default: + DevMsg( " \"%s\" \"%s\"\n", var->GetName(), var->GetStringValue() ); + break; + } + } + } + } + } + } + } + + // list the critical errors after, otherwise the console log scrolls them away + if (nNumErrors) + { + for (i = 0; i < nSortedMaterials; i++) + { + // iterate using sort mapping + IMaterialInternal *pMaterial = GetMaterialInternal(pSorted[i]); + + nRefCount = pMaterial->GetReferenceCount(); + + if ( nRefCount < 0 ) + { + // reference counts should not be negative + DevWarning( "DebugPrintUsedMaterials: refCount (%d) < 0 for material: \"%s\"\n", + nRefCount, pMaterial->GetName() ); + } + else if (!nRefCount) + { + // ensure that it stayed uncached after the post loading uncache + // this is effectively a coding bug thats needs to be fixed + // a material is being precached without incrementing its reference + if (pMaterial->IsPrecached() || pMaterial->IsPrecachedVars()) + { + DevWarning( "DebugPrintUsedMaterials: material: \"%s\" didn't unache\n", + pMaterial->GetName() ); + } + } + } + DevWarning( "%d Errors\n", nNumErrors ); + } + + if (!pSearchSubString) + { + DevMsg( "%d Cached, %d Total Materials\n", nNumCached, GetNumMaterials() ); + } +} + +void CMaterialSystem::DebugPrintUsedTextures( void ) +{ + TextureManager()->DebugPrintUsedTextures(); +} + +#if defined( _X360 ) +void CMaterialSystem::ListUsedMaterials( void ) +{ + int numMaterials = GetNumMaterials(); + xMaterialList_t* pMaterialList = (xMaterialList_t *)stackalloc( numMaterials * sizeof( xMaterialList_t ) ); + + numMaterials = 0; + for ( MaterialHandle_t hMaterial = FirstMaterial(); hMaterial != InvalidMaterial(); hMaterial = NextMaterial( hMaterial ) ) + { + IMaterialInternal *pMaterial = GetMaterialInternal( hMaterial ); + pMaterialList[numMaterials].pName = pMaterial->GetName(); + pMaterialList[numMaterials].pShaderName = pMaterial->GetShader() ? pMaterial->GetShader()->GetName() : "???"; + pMaterialList[numMaterials].refCount = pMaterial->GetReferenceCount(); + numMaterials++; + } + + XBX_rMaterialList( numMaterials, pMaterialList ); +} +#endif + +void CMaterialSystem::ToggleSuppressMaterial( char const* pMaterialName ) +{ + /* + // This version suppresses all but the material + IMaterial *pMaterial = GetFirstMaterial(); + while (pMaterial) + { + if (stricmp(pMaterial->GetName(), pMaterialName)) + { + IMaterialInternal* pMatInt = static_cast(pMaterial); + pMatInt->ToggleSuppression(); + } + pMaterial = GetNextMaterial(); + } + */ + + // Note: if we use this function a lot, we'll want to do something else, like have them + // pass in a texture group or reuse whatever texture group the material already had. + // As it is, this is rarely used, so if it's not in TEXTURE_GROUP_OTHER, it'll go in + // TEXTURE_GROUP_SHARED. + IMaterial* pMaterial = FindMaterial( pMaterialName, TEXTURE_GROUP_OTHER, true, NULL ); + if ( !IsErrorMaterial( pMaterial ) ) + { + IMaterialInternal* pMatInt = static_cast(pMaterial); + pMatInt = pMatInt->GetRealTimeVersion(); //always work with the realtime material internally + pMatInt->ToggleSuppression(); + } +} + +void CMaterialSystem::ToggleDebugMaterial( char const* pMaterialName ) +{ + // Note: if we use this function a lot, we'll want to do something else, like have them + // pass in a texture group or reuse whatever texture group the material already had. + // As it is, this is rarely used, so if it's not in TEXTURE_GROUP_OTHER, it'll go in + // TEXTURE_GROUP_SHARED. + IMaterial* pMaterial = FindMaterial( pMaterialName, TEXTURE_GROUP_OTHER, false, NULL ); + if ( !IsErrorMaterial( pMaterial ) ) + { + IMaterialInternal* pMatInt = static_cast(pMaterial); + pMatInt = pMatInt->GetRealTimeVersion(); //always work with the realtime material internally + pMatInt->ToggleDebugTrace(); + } + else + { + Warning("Unknown material %s\n", pMaterialName ); + } +} + + +//----------------------------------------------------------------------------- +// Used to iterate over all shaders for editing purposes +//----------------------------------------------------------------------------- +int CMaterialSystem::ShaderCount() const +{ + return ShaderSystem()->ShaderCount(); +} + +int CMaterialSystem::GetShaders( int nFirstShader, int nMaxCount, IShader **ppShaderList ) const +{ + return ShaderSystem()->GetShaders( nFirstShader, nMaxCount, ppShaderList ); +} + + +//----------------------------------------------------------------------------- +// FIXME: Is there a better way of doing this? +// Returns shader flag names for editors to be able to edit them +//----------------------------------------------------------------------------- +int CMaterialSystem::ShaderFlagCount() const +{ + return ShaderSystem()->ShaderStateCount( ); +} + +const char *CMaterialSystem::ShaderFlagName( int nIndex ) const +{ + return ShaderSystem()->ShaderStateString( nIndex ); +} + + +//----------------------------------------------------------------------------- +// Returns the currently active shader fallback for a particular shader +//----------------------------------------------------------------------------- +void CMaterialSystem::GetShaderFallback( const char *pShaderName, char *pFallbackShader, int nFallbackLength ) +{ + // FIXME: This is pretty much a hack. We need a better way for the + // editor to get ahold of shader fallbacks + int nCount = ShaderCount(); + IShader** ppShaderList = (IShader**)_alloca( nCount * sizeof(IShader) ); + GetShaders( 0, nCount, ppShaderList ); + + do + { + int i; + for ( i = 0; i < nCount; ++i ) + { + if ( !Q_stricmp( pShaderName, ppShaderList[i]->GetName() ) ) + break; + } + + // Didn't find a match! + if ( i == nCount ) + { + Q_strncpy( pFallbackShader, "wireframe", nFallbackLength ); + return; + } + + // Found a match + // FIXME: Theoretically, getting fallbacks should require a param list + // In practice, it looks rare or maybe even neved done + const char *pFallback = ppShaderList[i]->GetFallbackShader( NULL ); + if ( !pFallback ) + { + Q_strncpy( pFallbackShader, pShaderName, nFallbackLength ); + return; + } + else + { + pShaderName = pFallback; + } + } while (true); +} + +//----------------------------------------------------------------------------- +// Triggers OpenGL shader preloading at game startup +//----------------------------------------------------------------------------- +#ifdef DX_TO_GL_ABSTRACTION +void CMaterialSystem::DoStartupShaderPreloading( void ) +{ + GetRenderContextInternal()->DoStartupShaderPreloading(); +} +#endif + + +void CMaterialSystem::SwapBuffers( void ) +{ + VPROF_BUDGET( "CMaterialSystem::SwapBuffers", VPROF_BUDGETGROUP_SWAP_BUFFERS ); + GetRenderContextInternal()->SwapBuffers(); + g_FrameNum++; +} + +bool CMaterialSystem::InEditorMode() const +{ + Assert( m_bGeneratedConfig ); + return g_config.bEditMode && CanUseEditorMaterials(); +} + +void CMaterialSystem::NoteAnisotropicLevel( int currentLevel ) +{ + Assert( m_bGeneratedConfig ); + g_config.m_nForceAnisotropicLevel = currentLevel; +} + +// Get the current config for this video card (as last set by control panel or the default if not) +const MaterialSystem_Config_t &CMaterialSystem::GetCurrentConfigForVideoCard() const +{ + Assert( m_bGeneratedConfig ); + return g_config; +} + +// Does the device support the given MSAA level? +bool CMaterialSystem::SupportsMSAAMode( int nNumSamples ) +{ + return g_pShaderAPI->SupportsMSAAMode( nNumSamples ); +} + +void CMaterialSystem::ReloadFilesInList( IFileList *pFilesToReload ) +{ + if ( !IsPC() ) + return; + + // We have to flush the materials in 2 steps because they have recursive dependencies. The problem case + // is if you have two materials, A and B, that depend on C. You tell A to reload and it also reloads C. Then + // the filesystem thinks C doesn't need to be reloaded anymore. So when you get to B, it decides not to reload + // either since C doesn't need to be reloaded. To fix this, we ask all materials if they want to reload in + // one stage, then in the next stage we actually reload the appropriate ones. + MaterialHandle_t hNext; + for ( MaterialHandle_t h=m_MaterialDict.FirstMaterial(); h != m_MaterialDict.InvalidMaterial(); h=hNext ) + { + hNext = m_MaterialDict.NextMaterial( h ); + IMaterialInternal *pMat = m_MaterialDict.GetMaterialInternal( h ); + + pMat->DecideShouldReloadFromWhitelist( pFilesToReload ); + } + + // Now reload the materials that wanted to be reloaded. + for ( MaterialHandle_t h=m_MaterialDict.FirstMaterial(); h != m_MaterialDict.InvalidMaterial(); h=hNext ) + { + hNext = m_MaterialDict.NextMaterial( h ); + IMaterialInternal *pMat = m_MaterialDict.GetMaterialInternal( h ); + + pMat->ReloadFromWhitelistIfMarked(); + } + + // Flush out necessary textures. + TextureManager()->ReloadFilesInList( pFilesToReload ); +} + +// Does the device support the given CSAA level? +bool CMaterialSystem::SupportsCSAAMode( int nNumSamples, int nQualityLevel ) +{ + return g_pShaderAPI->SupportsCSAAMode( nNumSamples, nQualityLevel ); +} + +// Does the device support shadow depth texturing? +bool CMaterialSystem::SupportsShadowDepthTextures( void ) +{ + return g_pShaderAPI->SupportsShadowDepthTextures(); +} + +// Does the device support Fetch4 +bool CMaterialSystem::SupportsFetch4( void ) +{ + return g_pShaderAPI->SupportsFetch4(); +} + +// Vendor-dependent shadow depth texture format +ImageFormat CMaterialSystem::GetShadowDepthTextureFormat( void ) +{ + return g_pShaderAPI->GetShadowDepthTextureFormat(); +} + +// Vendor-dependent slim texture format +ImageFormat CMaterialSystem::GetNullTextureFormat( void ) +{ + return g_pShaderAPI->GetNullTextureFormat(); +} + +void CMaterialSystem::SetShadowDepthBiasFactors( float fShadowSlopeScaleDepthBias, float fShadowDepthBias ) +{ + g_pShaderAPI->SetShadowDepthBiasFactors( fShadowSlopeScaleDepthBias, fShadowDepthBias ); +} + +bool CMaterialSystem::SupportsHDRMode( HDRType_t nHDRMode ) +{ + return HardwareConfig()->SupportsHDRMode( nHDRMode ); +} + +bool CMaterialSystem::UsesSRGBCorrectBlending( void ) const +{ + return HardwareConfig()->UsesSRGBCorrectBlending(); +} + +// Get video card identitier +const MaterialSystemHardwareIdentifier_t &CMaterialSystem::GetVideoCardIdentifier( void ) const +{ + static MaterialSystemHardwareIdentifier_t foo; + Assert( 0 ); + return foo; +} + +void CMaterialSystem::AddModeChangeCallBack( ModeChangeCallbackFunc_t func ) +{ + g_pShaderDeviceMgr->AddModeChangeCallback( func ); +} + +void CMaterialSystem::RemoveModeChangeCallBack( ModeChangeCallbackFunc_t func ) +{ + g_pShaderDeviceMgr->RemoveModeChangeCallback( func ); +} + + +//----------------------------------------------------------------------------- +// Gets configuration information associated with the display card, and optionally for a particular DX level. +// It will return a list of ConVars and values to set. +//----------------------------------------------------------------------------- +bool CMaterialSystem::GetRecommendedConfigurationInfo( int nDXLevel, KeyValues *pKeyValues ) +{ + MaterialLock_t hLock = Lock(); + bool bResult = g_pShaderDeviceMgr->GetRecommendedConfigurationInfo( m_nAdapter, nDXLevel, pKeyValues ); + Unlock( hLock ); + return bResult; +} + + +//----------------------------------------------------------------------------- +// For dealing with device lost in cases where SwapBuffers isn't called all the time (Hammer) +//----------------------------------------------------------------------------- +void CMaterialSystem::HandleDeviceLost() +{ + if ( IsX360() ) + return; + + g_pShaderAPI->HandleDeviceLost(); +} + +bool CMaterialSystem::UsingFastClipping( void ) +{ + return (HardwareConfig()->UseFastClipping() || (HardwareConfig()->MaxUserClipPlanes() < 1)); +}; + +int CMaterialSystem::StencilBufferBits( void ) +{ + return HardwareConfig()->StencilBufferBits(); +} + +ITexture* CMaterialSystem::CreateRenderTargetTexture( + int w, + int h, + RenderTargetSizeMode_t sizeMode, // Controls how size is generated (and regenerated on video mode change). + ImageFormat format, + MaterialRenderTargetDepth_t depth ) +{ + return CreateNamedRenderTargetTextureEx( NULL, w, h, sizeMode, format, depth, TEXTUREFLAGS_CLAMPS|TEXTUREFLAGS_CLAMPT, 0 ); +} + +ITexture* CMaterialSystem::CreateNamedRenderTargetTexture( + const char *pRTName, + int w, + int h, + RenderTargetSizeMode_t sizeMode, // Controls how size is generated (and regenerated on video mode change). + ImageFormat format, + MaterialRenderTargetDepth_t depth, + bool bClampTexCoords, + bool bAutoMipMap ) +{ + unsigned int textureFlags = 0; + if ( bClampTexCoords ) + { + textureFlags |= TEXTUREFLAGS_CLAMPS | TEXTUREFLAGS_CLAMPT; + } + + unsigned int renderTargetFlags = 0; + if ( bAutoMipMap ) + { + renderTargetFlags |= CREATERENDERTARGETFLAGS_AUTOMIPMAP; + } + + return CreateNamedRenderTargetTextureEx( pRTName, w, h, sizeMode, format, depth, textureFlags, renderTargetFlags ); +} + +ITexture* CMaterialSystem::CreateNamedRenderTargetTextureEx( + const char *pRTName, + int w, + int h, + RenderTargetSizeMode_t sizeMode, // Controls how size is generated (and regenerated on video mode change). + ImageFormat format, + MaterialRenderTargetDepth_t depth, + unsigned int textureFlags, + unsigned int renderTargetFlags ) +{ + RenderTargetType_t rtType; + + bool gl_canMixTargetSizes = (HardwareConfig() && HardwareConfig()->SupportsGLMixedSizeTargets()); + + // On GL, the depth buffer for a render target must be the same size (until we pick up mixed-sized attachments in 10.6.3) + if ( (!gl_canMixTargetSizes && IsPosix()) || IsEmulatingGL() ) + { + if ( depth != MATERIAL_RT_DEPTH_SEPARATE && depth != MATERIAL_RT_DEPTH_NONE ) + { + int fbWidth, fbHeight; + g_pShaderAPI->GetBackBufferDimensions( fbWidth, fbHeight ); + + if ( sizeMode != RT_SIZE_FULL_FRAME_BUFFER ) + { + if ( w != fbWidth || h != fbHeight ) + { + depth = MATERIAL_RT_DEPTH_SEPARATE; + } + } + } + } + + // Determine RT type based on depth buffer requirements + switch ( depth ) + { + case MATERIAL_RT_DEPTH_SEPARATE: + // using own depth buffer + rtType = RENDER_TARGET_WITH_DEPTH; + break; + case MATERIAL_RT_DEPTH_NONE: + // no depth buffer + rtType = RENDER_TARGET_NO_DEPTH; + break; + case MATERIAL_RT_DEPTH_ONLY: + // only depth buffer + rtType = RENDER_TARGET_ONLY_DEPTH; + break; + case MATERIAL_RT_DEPTH_SHARED: + default: + // using shared depth buffer + rtType = RENDER_TARGET; + break; + } + + ITextureInternal* pTex = TextureManager()->CreateRenderTargetTexture( pRTName, w, h, sizeMode, format, rtType, textureFlags, renderTargetFlags ); + pTex->IncrementReferenceCount(); + +#if defined( _X360 ) + if ( !( renderTargetFlags & CREATERENDERTARGETFLAGS_NOEDRAM ) ) + { + // create the EDRAM surface that is bound to the RT Texture + pTex->CreateRenderTargetSurface( 0, 0, IMAGE_FORMAT_UNKNOWN, true ); + } +#endif + + // If we're not in a BeginRenderTargetAllocation-EndRenderTargetAllocation block + // because we're being called by a legacy path (i.e. a mod), force an Alt-Tab after every + // RT allocation to ensure that all RTs get priority during allocation + if ( !m_bAllocatingRenderTargets ) + { + EndRenderTargetAllocation(); + } + + return pTex; +} + +//----------------------------------------------------------------------------------------------------- +// New version which must be called inside BeginRenderTargetAllocation-EndRenderTargetAllocation block +//----------------------------------------------------------------------------------------------------- +ITexture *CMaterialSystem::CreateNamedRenderTargetTextureEx2( + const char *pRTName, + int w, + int h, + RenderTargetSizeMode_t sizeMode, // Controls how size is generated (and regenerated on video mode change). + ImageFormat format, + MaterialRenderTargetDepth_t depth, + unsigned int textureFlags, + unsigned int renderTargetFlags ) +{ + // Only proceed if we are between BeginRenderTargetAllocation and EndRenderTargetAllocation + if ( !m_bAllocatingRenderTargets ) + { + Warning( "Tried to create render target outside of CMaterialSystem::BeginRenderTargetAllocation/EndRenderTargetAllocation block\n" ); + return NULL; + } + + ITexture* pTexture = CreateNamedRenderTargetTextureEx( pRTName, w, h, sizeMode, format, depth, textureFlags, renderTargetFlags ); + + pTexture->DecrementReferenceCount(); // Follow the same convention as CTextureManager::LoadTexture (return refcount of 0). + return pTexture; +} + +class CTextureBitsRegenerator : public ITextureRegenerator +{ +public: + CTextureBitsRegenerator( int w, int h, int mips, ImageFormat fmt, int srcBufferSize, byte* srcBits ) + : m_nWidth( w ) + , m_nHeight( h ) + , m_nMipmaps( mips ) + , m_ImageFormat( fmt ) + { + Assert( srcBits ); + Assert( srcBufferSize > 0 ); + Assert( m_nMipmaps != 0 ); + + // If these fail, we'll crash later, so look to before here for the problem. + Assert( ImageLoader::GetMemRequired( w, h, 1, fmt, m_nMipmaps > 1 ? true : false ) <= srcBufferSize ); + Assert( m_nMipmaps == 1 || m_nMipmaps == ImageLoader::GetNumMipMapLevels( m_nWidth, m_nHeight, 1 ) ); + + + m_ImageData.EnsureCapacity( srcBufferSize ); + Q_memcpy( m_ImageData.Base(), srcBits, srcBufferSize ); + } + + virtual void RegenerateTextureBits( ITexture *pTexture, IVTFTexture *pVTFTexture, Rect_t *pRect ) + { + Assert( pVTFTexture->FrameCount() == 1 ); + Assert( pVTFTexture->FaceCount() == 1 ); + + int destWidth, destHeight, destDepth; + pVTFTexture->ComputeMipLevelDimensions( 0, &destWidth, &destHeight, &destDepth ); + Assert( destDepth == 1 ); + Assert( destWidth <= m_nWidth && destHeight <= m_nHeight ); + + unsigned char* pDest = pVTFTexture->ImageData(); + ImageFormat destFmt = pVTFTexture->Format(); + + if ( destFmt == m_ImageFormat && destWidth == m_nWidth && destHeight == m_nHeight ) + { + Q_memcpy( pDest, m_ImageData.Base(), m_ImageData.NumAllocated() ); + } + else + { + int srcResX = m_nWidth; + int srcResY = m_nHeight; + int srcOffset = 0; + int dstOffset = 0; + int mip = 0; + + // Skip the mips we're not including. + while ( mip < m_nMipmaps && ( srcResX > destWidth || srcResY > destHeight ) ) + { + srcOffset += ImageLoader::GetMemRequired( srcResX, srcResY, 1, m_ImageFormat, false ); + + srcResX = Max( 1, ( srcResX >> 1 ) ); + srcResY = Max( 1, ( srcResY >> 1 ) ); + + mip++; + } + // Assert we're where we expect to be now. + Assert( srcResX == destWidth && srcResY == destHeight ); + + for ( ; mip < m_nMipmaps; ++mip ) + { + // Convert this mipmap level. + ImageLoader::ConvertImageFormat( m_ImageData.Base() + srcOffset, m_ImageFormat, pDest + dstOffset, destFmt, srcResX, srcResY ); + + // Then update offsets for the next mipmap level. + srcOffset += ImageLoader::GetMemRequired( srcResX, srcResY, 1, m_ImageFormat, false ); + dstOffset += ImageLoader::GetMemRequired( srcResX, srcResY, 1, destFmt, false ); + + srcResX = Max( 1, ( srcResX >> 1 ) ); + srcResY = Max( 1, ( srcResY >> 1 ) ); + } + } + } + + virtual void Release() + { + delete this; + } + +private: + int m_nWidth; + int m_nHeight; + int m_nMipmaps; + ImageFormat m_ImageFormat; + CUtlMemory m_ImageData; +}; + +ITexture* CMaterialSystem::CreateTextureFromBits(int w, int h, int mips, ImageFormat fmt, int srcBufferSize, byte* srcBits) +{ + int flags = TEXTUREFLAGS_SINGLECOPY + | ( mips > 1 + ? TEXTUREFLAGS_ALL_MIPS + : TEXTUREFLAGS_NOMIP ) + ; + + return CreateNamedTextureFromBitsEx( "frombits", TEXTURE_GROUP_OTHER, w, h, mips, fmt, srcBufferSize, srcBits, flags ); +} + +void CMaterialSystem::OverrideRenderTargetAllocation( bool rtAlloc ) +{ + m_bAllocatingRenderTargets = rtAlloc; +} + +ITextureCompositor* CMaterialSystem::NewTextureCompositor( int w, int h, const char* pCompositeName, int nTeamNum, uint64 randomSeed, KeyValues* stageDesc, uint32 texCompositeCreateFlags ) +{ + return CreateTextureCompositor( w, h, pCompositeName, nTeamNum, randomSeed, stageDesc, texCompositeCreateFlags ); +} + +void CMaterialSystem::ScheduleTextureComposite( CTextureCompositor* _texCompositor ) +{ + Assert( _texCompositor != NULL ); + _texCompositor->AddRef(); + m_scheduledComposites.AddToTail( _texCompositor ); +} + +void CMaterialSystem::AsyncFindTexture( const char* pFilename, const char *pTextureGroupName, IAsyncTextureOperationReceiver* pRecipient, void* pExtraArgs, bool bComplain, int nAdditionalCreationFlags ) +{ + Assert( pFilename != NULL ); + Assert( pTextureGroupName != NULL ); + Assert( pRecipient != NULL ); + + // Bump the ref count on the recipient before handing it off. This ensures the receiver won't go away before we have completed our work. + pRecipient->AddRef(); + + TextureManager()->AsyncFindOrLoadTexture( pFilename, pTextureGroupName, pRecipient, pExtraArgs, bComplain, nAdditionalCreationFlags ); +} + +// creates a texture suitable for use with materials from a raw stream of bits. +// The bits will be retained by the material system and can be freed upon return. +ITexture *CMaterialSystem::CreateNamedTextureFromBitsEx( const char* pName, const char *pTextureGroupName, int w, int h, int mips, ImageFormat fmt, int srcBufferSize, byte* srcBits, int nFlags ) +{ + Assert( srcBits ); + + CTextureBitsRegenerator* regen = new CTextureBitsRegenerator( w, h, mips, fmt, srcBufferSize, srcBits ); + ITextureInternal* tex = TextureManager()->CreateProceduralTexture( pName, pTextureGroupName, w, h, 1, fmt, nFlags, regen ); + return tex; +} + +bool CMaterialSystem::AddTextureCompositorTemplate( const char* pName, KeyValues* pTmplDesc, int /* nTexCompositeTemplateFlags */ ) +{ + // Flags are currently unused, but added for futureproofing. + return TextureManager()->AddTextureCompositorTemplate( pName, pTmplDesc ); +} + +bool CMaterialSystem::VerifyTextureCompositorTemplates() +{ + return TextureManager()->VerifyTextureCompositorTemplates(); +} + + +void CMaterialSystem::BeginRenderTargetAllocation( void ) +{ + g_pShaderAPI->FlushBufferedPrimitives(); + m_bAllocatingRenderTargets = true; +} + +void CMaterialSystem::EndRenderTargetAllocation( void ) +{ + // Any GPU newer than 2005 doesn't need to do this, and it eats up ~40% of our level load time! + const bool cbRequiresRenderTargetAllocationFirst = mat_requires_rt_alloc_first.GetBool(); + + g_pShaderAPI->FlushBufferedPrimitives(); + m_bAllocatingRenderTargets = false; + + if ( IsPC() && cbRequiresRenderTargetAllocationFirst && g_pShaderAPI->CanDownloadTextures() ) + { + // Simulate an Alt-Tab...will cause RTs to be allocated first + + g_pShaderDevice->ReleaseResources(); + g_pShaderDevice->ReacquireResources(); + } + + TextureManager()->CacheExternalStandardRenderTargets(); +} + +void CMaterialSystem::SetRenderTargetFrameBufferSizeOverrides( int nWidth, int nHeight ) +{ + m_nRenderTargetFrameBufferWidthOverride = nWidth; + m_nRenderTargetFrameBufferHeightOverride = nHeight; +} + + +void CMaterialSystem::GetRenderTargetFrameBufferDimensions( int & nWidth, int & nHeight ) +{ + if( m_nRenderTargetFrameBufferHeightOverride && m_nRenderTargetFrameBufferWidthOverride ) + { + nWidth = m_nRenderTargetFrameBufferWidthOverride; + nHeight = m_nRenderTargetFrameBufferHeightOverride; + } + else + { + GetBackBufferDimensions( nWidth, nHeight ); + } +} + + +//----------------------------------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------------------------------- +void CMaterialSystem::UpdateLightmap( int lightmapPageID, int lightmapSize[2], + int offsetIntoLightmapPage[2], + float *pFloatImage, float *pFloatImageBump1, + float *pFloatImageBump2, float *pFloatImageBump3 ) +{ + CMatCallQueue *pCallQueue = GetRenderCallQueue(); + if ( !pCallQueue ) + { + m_Lightmaps.UpdateLightmap( lightmapPageID, lightmapSize, offsetIntoLightmapPage, pFloatImage, pFloatImageBump1, pFloatImageBump2, pFloatImageBump3 ); + } + else + { + ExecuteOnce( DebuggerBreakIfDebugging() ); + } +} + +//----------------------------------------------------------------------------------------------------- +// 360 TTF Font Support +//----------------------------------------------------------------------------------------------------- +#if defined( _X360 ) +HXUIFONT CMaterialSystem::OpenTrueTypeFont( const char *pFontname, int tall, int style ) +{ + MaterialLock_t hLock = Lock(); + HXUIFONT result = g_pShaderAPI->OpenTrueTypeFont( pFontname, tall, style ); + Unlock( hLock ); + return result; +} +void CMaterialSystem::CloseTrueTypeFont( HXUIFONT hFont ) +{ + MaterialLock_t hLock = Lock(); + g_pShaderAPI->CloseTrueTypeFont( hFont ); + Unlock( hLock ); +} +bool CMaterialSystem::GetTrueTypeFontMetrics( HXUIFONT hFont, XUIFontMetrics *pFontMetrics, XUICharMetrics charMetrics[256] ) +{ + MaterialLock_t hLock = Lock(); + bool result = g_pShaderAPI->GetTrueTypeFontMetrics( hFont, pFontMetrics, charMetrics ); + Unlock( hLock ); + return result; +} +bool CMaterialSystem::GetTrueTypeGlyphs( HXUIFONT hFont, int numChars, wchar_t *pWch, int *pOffsetX, int *pOffsetY, int *pWidth, int *pHeight, unsigned char *pRGBA, int *pRGBAOffset ) +{ + MaterialLock_t hLock = Lock(); + bool result = g_pShaderAPI->GetTrueTypeGlyphs( hFont, numChars, pWch, pOffsetX, pOffsetY, pWidth, pHeight, pRGBA, pRGBAOffset ); + Unlock( hLock ); + return result; +} +#endif + +//----------------------------------------------------------------------------------------------------- +// 360 Back Buffer access. Due to hardware, RT data must be blitted from EDRAM +// and converted. +//----------------------------------------------------------------------------------------------------- +#if defined( _X360 ) +void CMaterialSystem::ReadBackBuffer( Rect_t *pSrcRect, Rect_t *pDstRect, unsigned char *pDstData, ImageFormat dstFormat, int dstStride ) +{ + Assert( pSrcRect && pDstRect && pDstData ); + + int fbWidth, fbHeight; + g_pShaderAPI->GetBackBufferDimensions( fbWidth, fbHeight ); + + if ( pDstRect->width > fbWidth || pDstRect->height > fbHeight ) + { + Assert( 0 ); + return; + } + + // intermediate results will be placed at (0,0) + Rect_t rect; + rect.x = 0; + rect.y = 0; + rect.width = pDstRect->width; + rect.height = pDstRect->height; + + ITexture *pTempRT; + bool bStretch = ( pSrcRect->width != pDstRect->width || pSrcRect->height != pDstRect->height ); + if ( !bStretch ) + { + // hijack an unused RT (no surface required) for 1:1 resolve work, fastest path + pTempRT = FindTexture( "_rt_FullFrameFB", TEXTURE_GROUP_RENDER_TARGET ); + } + else + { + // hijack an unused RT (with surface abilities) for stretch work, slower path + pTempRT = FindTexture( "_rt_WaterReflection", TEXTURE_GROUP_RENDER_TARGET ); + } + + Assert( !pTempRT->IsError() && pDstRect->width <= pTempRT->GetActualWidth() && pDstRect->height <= pTempRT->GetActualHeight() ); + GetRenderContextInternal()->CopyRenderTargetToTextureEx( pTempRT, 0, pSrcRect, &rect ); + + // access the RT bits + CPixelWriter writer; + g_pShaderAPI->ModifyTexture( ((ITextureInternal*)pTempRT)->GetTextureHandle( 0 ) ); + if ( !g_pShaderAPI->TexLock( 0, 0, 0, 0, pTempRT->GetActualWidth(), pTempRT->GetActualHeight(), writer ) ) + return; + + // this will be adequate for non-block formats + int srcStride = pTempRT->GetActualWidth() * ImageLoader::SizeInBytes( pTempRT->GetImageFormat() ); + + // untile intermediate RT in place to achieve linear access + XGUntileTextureLevel( + pTempRT->GetActualWidth(), + pTempRT->GetActualHeight(), + 0, + XGGetGpuFormat( ImageLoader::ImageFormatToD3DFormat( pTempRT->GetImageFormat() ) ), + 0, + (char*)writer.GetPixelMemory(), + srcStride, + NULL, + writer.GetPixelMemory(), + NULL ); + + // swap back to x86 order as expected by image conversion + ImageLoader::ByteSwapImageData( (unsigned char*)writer.GetPixelMemory(), srcStride*pTempRT->GetActualHeight(), pTempRT->GetImageFormat() ); + + // convert to callers format + Assert( dstFormat == IMAGE_FORMAT_RGB888 ); + ImageLoader::ConvertImageFormat( (unsigned char*)writer.GetPixelMemory(), pTempRT->GetImageFormat(), pDstData, dstFormat, pDstRect->width, pDstRect->height, srcStride, dstStride ); + + g_pShaderAPI->TexUnlock(); +} +#endif + +#if defined( _X360 ) +void CMaterialSystem::PersistDisplay() +{ + g_pShaderAPI->PersistDisplay(); +} +#endif + +#if defined( _X360 ) +void *CMaterialSystem::GetD3DDevice() +{ + return g_pShaderAPI->GetD3DDevice(); +} +#endif + +#if defined( _X360 ) +bool CMaterialSystem::OwnGPUResources( bool bEnable ) +{ + return g_pShaderAPI->OwnGPUResources( bEnable ); +} +#endif + +//----------------------------------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------------------------------- +class CThreadRelease : public CJob +{ + virtual JobStatus_t DoExecute() + { + g_pShaderAPI->ReleaseThreadOwnership(); + + return JOB_OK; + } +}; + + +void CMaterialSystem::ThreadRelease( ) +{ + if ( !m_bThreadHasOwnership ) + { + return; + } + + double flStartTime, flEndThreadRelease, flEndTime; + int do_report = mat_queue_report.GetInt(); + + if ( do_report ) + { + flStartTime = Plat_FloatTime(); + } + + CJob *pActiveAsyncJob = new CThreadRelease(); + IThreadPool *pThreadPool = CreateMatQueueThreadPool(); + pThreadPool->AddJob( pActiveAsyncJob ); + pActiveAsyncJob->WaitForFinish(); + + SafeRelease( pActiveAsyncJob ); + + if ( do_report ) + { + flEndThreadRelease = Plat_FloatTime(); + } + + g_pShaderAPI->AcquireThreadOwnership(); + + m_bThreadHasOwnership = false; + m_ThreadOwnershipID = 0; + + if ( do_report ) + { + flEndTime = Plat_FloatTime(); + double flResult = ( flEndTime - flStartTime ) * 1000.0; + + if ( do_report == -1 || flResult > mat_queue_report.GetFloat() ) + { + Color red( 200, 20, 20, 255 ); + ConColorMsg( red, "CMaterialSystem::ThreadRelease: %0.2fms = Release:%0.2fms + Acquire:%0.2fms\n", flResult, ( flEndThreadRelease - flStartTime ) * 1000.0, ( flEndTime - flEndThreadRelease ) * 1000.0 ); + } + } +} + + +void CMaterialSystem::ThreadAcquire( bool bForce ) +{ + if ( !bForce ) + { + return; + } + + double flStartTime, flEndTime; + int do_report = mat_queue_report.GetInt(); + + if ( do_report ) + { + flStartTime = Plat_FloatTime(); + } + + g_pShaderAPI->ReleaseThreadOwnership(); + + CJob *pActiveAsyncJob = new CThreadAcquire(); + IThreadPool *pThreadPool = CreateMatQueueThreadPool(); + pThreadPool->AddJob( pActiveAsyncJob ); +// while we could wait for this job to finish, there's no reason too +// pActiveAsyncJob->WaitForFinish(); + + SafeRelease( pActiveAsyncJob ); + + m_bThreadHasOwnership = true; + m_ThreadOwnershipID = ThreadGetCurrentId(); + + if ( do_report ) + { + flEndTime = Plat_FloatTime(); + double flResult = ( flEndTime - flStartTime ) * 1000.0; + + if ( do_report == -1 || flResult > mat_queue_report.GetFloat() ) + { + Color red( 200, 20, 20, 255 ); + ConColorMsg( red, "CMaterialSystem::ThreadAcquire: %0.2fms\n", flResult ); + } + } +} + + +//----------------------------------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------------------------------- +MaterialLock_t CMaterialSystem::Lock() +{ + double flStartTime; + int do_report = mat_queue_report.GetInt(); + + if ( do_report ) + { + flStartTime = Plat_FloatTime(); + } + + IMatRenderContextInternal *pCurContext = GetRenderContextInternal(); +#if 1 // Rick's optimization: not sure this is needed anymore + if ( pCurContext != &m_HardwareRenderContext && m_pActiveAsyncJob ) + { + m_pActiveAsyncJob->WaitForFinish(); + // threadsafety note: not releasing or nulling pointer. + } + + if ( m_ThreadMode != MATERIAL_SINGLE_THREADED ) + { + TelemetrySetLockName( TELEMETRY_LEVEL0, (char const *)&g_MatSysMutex, "MatSysMutex" ); + + tmTryLock( TELEMETRY_LEVEL0, (char const *)&g_MatSysMutex, "CMaterialSystem" ); + g_MatSysMutex.Lock(); + tmEndTryLock( TELEMETRY_LEVEL0, (char const *)&g_MatSysMutex, TMLR_SUCCESS ); + tmSetLockState( TELEMETRY_LEVEL0, (char const *)&g_MatSysMutex, TMLS_LOCKED, "CMaterialSystem" ); + } +#endif + + MaterialLock_t hMaterialLock = (MaterialLock_t)pCurContext; + m_pRenderContext.Set( &m_HardwareRenderContext ); + + if ( m_ThreadMode != MATERIAL_SINGLE_THREADED ) + { + g_pShaderAPI->SetDisallowAccess( false ); + if ( pCurContext->GetCallQueueInternal() ) + { + ThreadRelease(); + } + } + + g_pShaderAPI->ShaderLock(); + + if ( do_report ) + { + double flEndTime = Plat_FloatTime(); + double flResult = ( flEndTime - flStartTime ) * 1000.0; + + if ( do_report == -1 || flResult > mat_queue_report.GetFloat() ) + { + Color red( 200, 20, 20, 255 ); + ConColorMsg( red, "*CMaterialSystem::Lock: %0.2fms\n", flResult ); + } + } + + return hMaterialLock; +} + +//----------------------------------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------------------------------- +void CMaterialSystem::Unlock( MaterialLock_t hMaterialLock ) +{ + double flStartTime; + int do_report = mat_queue_report.GetInt(); + + if ( do_report ) + { + flStartTime = Plat_FloatTime(); + } + + IMatRenderContextInternal *pRenderContext = (IMatRenderContextInternal *)hMaterialLock; + m_pRenderContext.Set( pRenderContext ); + g_pShaderAPI->ShaderUnlock(); + +#ifdef MAT_QUEUE_MODE_PROFILE + if ( m_ThreadMode == MATERIAL_QUEUED_SINGLE_THREADED ) + { + g_pShaderAPI->SetDisallowAccess( true ); + } + else +#endif + if ( m_ThreadMode == MATERIAL_QUEUED_THREADED ) + { + if ( pRenderContext->GetCallQueueInternal() ) + { + ThreadAcquire(); + } + } + +#if 1 // Rick's optimization: not sure this is needed anymore + if ( m_ThreadMode != MATERIAL_SINGLE_THREADED ) + { + g_MatSysMutex.Unlock(); + tmSetLockState( TELEMETRY_LEVEL0, (char const *)&g_MatSysMutex, TMLS_RELEASED, "CMaterialSystem" ); + } +#endif + + if ( do_report ) + { + double flEndTime = Plat_FloatTime(); + double flResult = ( flEndTime - flStartTime ) * 1000.0; + + if ( do_report || flResult > mat_queue_report.GetFloat() ) + { + Color red( 200, 20, 20, 255 ); + ConColorMsg( red, "*CMaterialSystem::Unlock: %0.2fms\n", flResult ); + } + } +} + +//----------------------------------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------------------------------- +CMatCallQueue *CMaterialSystem::GetRenderCallQueue() +{ + IMatRenderContextInternal *pRenderContext = m_pRenderContext.Get(); + return pRenderContext ? pRenderContext->GetCallQueueInternal() : NULL; +} + +void CMaterialSystem::UnbindMaterial( IMaterial *pMaterial ) +{ + Assert( (pMaterial == NULL) || ((IMaterialInternal *)pMaterial)->IsRealTimeVersion() ); + if ( m_HardwareRenderContext.GetCurrentMaterial() == pMaterial ) + { + m_HardwareRenderContext.Bind( g_pErrorMaterial, NULL ); + } +} + + + +class CReplacementProxy : public IMaterialProxy +{ +public: + CReplacementProxy( void ); + virtual ~CReplacementProxy( void ); + virtual bool Init( IMaterial *pMaterial, KeyValues *pKeyValues ); + virtual void OnBind( void * ); + virtual void Release( ); + virtual IMaterial * GetMaterial( ); + +private: + IMaterial *m_pReplaceMaterial; +}; + + +#define REPLACEMENT_NAME "_replacement" + + +//----------------------------------------------------------------------------- +// Purpose: +//----------------------------------------------------------------------------- +CReplacementProxy::CReplacementProxy( void ) : m_pReplaceMaterial ( NULL ) +{ +} + + +//----------------------------------------------------------------------------- +// Purpose: +//----------------------------------------------------------------------------- +CReplacementProxy::~CReplacementProxy( void ) +{ +} + + +//----------------------------------------------------------------------------- +// Purpose: Get pointer to the color value +// Input : *pMaterial - +//----------------------------------------------------------------------------- +bool CReplacementProxy::Init( IMaterial *pMaterial, KeyValues *pKeyValues ) +{ + const char *pszFileName = pMaterial->GetName(); + char szNewName[ MAX_PATH ]; + + V_sprintf_safe( szNewName, "%s" REPLACEMENT_NAME, pszFileName ); + m_pReplaceMaterial = materials->CreateMaterial( szNewName, pKeyValues ); + + return true; +} + + +//----------------------------------------------------------------------------- +// Purpose: +// Input : +//----------------------------------------------------------------------------- +void CReplacementProxy::OnBind( void * ) +{ +} + + +void CReplacementProxy::Release( ) +{ + m_pReplaceMaterial->DecrementReferenceCount(); + // Since we have a material-holding-a-material situation here, we need to nuke these if unreferenced to prevent the + // engine needing to double-call UncacheUnusedMaterials to actually get rid of all materials. + m_pReplaceMaterial->DeleteIfUnreferenced(); + m_pReplaceMaterial = NULL; +} + + + +IMaterial *CReplacementProxy::GetMaterial() +{ + static ConVarRef localplayer_visionflags( "localplayer_visionflags" ); + bool bVisionOverride = ( localplayer_visionflags.IsValid() && ( localplayer_visionflags.GetInt() & ( 0x01 ) ) ); // Pyro-vision Goggles + + if ( bVisionOverride ) + { + return m_pReplaceMaterial; + } + + return NULL; +} + + +EXPOSE_INTERFACE( CReplacementProxy, IMaterialProxy, "replace_proxy" IMATERIAL_PROXY_INTERFACE_VERSION ); + + +static const char *pszReplacementForceCopy[] = +{ + "$nocull", + + NULL +}; + +void CMaterialSystem::LoadReplacementMaterials() +{ + const char* cLocation = "materials"; + if ( CommandLine()->FindParm( "-matscan") ) { + ScanDirForReplacements( cLocation ); + } else { + InitReplacementsFromFile( cLocation ); + } +} + +void CMaterialSystem::ScanDirForReplacements( const char *pszPathName ) +{ + char szBaseName[ MAX_PATH ]; + + V_sprintf_safe( szBaseName, "%s/replacements.vmt", pszPathName ); + if ( g_pFullFileSystem->FileExists( szBaseName ) ) + { + KeyValues *pKV = g_pFullFileSystem->LoadKeyValues( IFileSystem::TYPE_VMT, szBaseName ); + if ( pKV ) + { + V_sprintf_safe( szBaseName, "%s/", pszPathName ); + m_Replacements.Insert( szBaseName, pKV ); + } + } + + V_sprintf_safe( szBaseName, "%s/*", pszPathName ); + + FileFindHandle_t FindHandle; + const char *pFindFileName = g_pFullFileSystem->FindFirst( szBaseName, &FindHandle ); + + while ( pFindFileName && pFindFileName[ 0 ] != '\0' ) + { + if ( g_pFullFileSystem->FindIsDirectory( FindHandle ) ) + { + if ( strcmp( pFindFileName, "." ) != 0 && strcmp( pFindFileName, ".." ) != 0 ) + { + char szNextBaseName[ MAX_PATH ]; + + V_sprintf_safe( szNextBaseName, "%s/%s", pszPathName, pFindFileName ); + ScanDirForReplacements( szNextBaseName ); + } + } + + pFindFileName = g_pFullFileSystem->FindNext( FindHandle ); + } + + g_pFullFileSystem->FindClose( FindHandle ); + +} + +void CMaterialSystem::InitReplacementsFromFile( const char *pszPathName ) +{ + CUtlVector replacementFiles; + char szBaseName[MAX_PATH]; + V_sprintf_safe( szBaseName, "%s/replacements.txt", pszPathName ); + + int replacementCount = ReadListFromFile( &replacementFiles, szBaseName ); + + for ( int i = 0; i < replacementCount; ++i ) + { + V_snprintf( szBaseName, sizeof(szBaseName), "%s/%s/replacements.vmt", pszPathName, replacementFiles[i] ); + if ( g_pFullFileSystem->FileExists(szBaseName) ) + { + KeyValues *pKV = g_pFullFileSystem->LoadKeyValues( IFileSystem::TYPE_VMT, szBaseName ); + if (pKV) + { + V_sprintf_safe( szBaseName, "%s/%s/", pszPathName, replacementFiles[i] ); + m_Replacements.Insert( szBaseName, pKV ); + } + } + } + + replacementFiles.PurgeAndDeleteElements(); +} + +void CMaterialSystem::PreloadReplacements( ) +{ + int nIndex = m_Replacements.First(); + while( m_Replacements.IsValidIndex( nIndex ) ) + { + m_Replacements.Element( nIndex )->deleteThis(); + + nIndex = m_Replacements.Next( nIndex ); + } + m_Replacements.Purge(); + + COM_TimestampedLog( "LoadReplacementMaterials(): Begin" ); + LoadReplacementMaterials(); + COM_TimestampedLog( "LoadReplacementMaterials(): End" ); + + m_bReplacementFilesValid = true; +} + + +IMaterialProxy *CMaterialSystem::DetermineProxyReplacements( IMaterial *pMaterial, KeyValues *pFallbackKeyValues ) +{ + CReplacementProxy *pReplacementProxy = NULL; + + if ( !g_pMaterialSystemHardwareConfig->SupportsPixelShaders_2_0() ) + { + return NULL; + } + + if ( !m_bReplacementFilesValid ) + { + PreloadReplacements(); + } + + const char *pszMaterialName = pMaterial->GetName(); + + char szCheckPath[ MAX_PATH ], szCheckName[ MAX_PATH ], szLastPath[ MAX_PATH ]; + const char *pszShadername = pFallbackKeyValues->GetName(); + + V_strcpy_safe( szLastPath, pszMaterialName ); + int nLength = strlen( szLastPath ) - strlen( REPLACEMENT_NAME ); + if ( nLength > 0 && strcmpi( &szLastPath[ nLength ], REPLACEMENT_NAME ) == 0 ) + { + return NULL; + } + + while( 1 ) + { + const char *pszRemoveSlashes; + V_ExtractFilePath( szLastPath, szCheckPath, sizeof( szCheckPath ) ); + + pszRemoveSlashes = szCheckPath; + while ( ( *pszRemoveSlashes ) != 0 && ( ( *pszRemoveSlashes ) == '/' || ( *pszRemoveSlashes ) == '\\' ) ) + { + pszRemoveSlashes++; + } + + V_sprintf_safe( szCheckName, "materials/%s", pszRemoveSlashes ); + int nIndex = m_Replacements.Find( szCheckName ); + + if ( m_Replacements.IsValidIndex( nIndex ) ) + { + KeyValues *pKV = m_Replacements.Element( nIndex ); + + KeyValues *pTemplatesKV = pKV->FindKey( "templates" ); + KeyValues *pPatternsKV = pKV->FindKey( "patterns" ); + + const char *pszFileName = V_GetFileName( pszMaterialName ); + + if ( !pTemplatesKV || !pPatternsKV ) + { + Warning( "Replacements: Invalid KV file %s\n", szCheckName ); + } + else + { + for ( KeyValues *pSubKey = pPatternsKV->GetFirstSubKey(); pSubKey; pSubKey = pSubKey->GetNextKey() ) + { + const char *pszReplacementName = pSubKey->GetName(); + +// Msg( " Sub: %s\n", pSubKey->GetName() ); + if ( strnicmp( pszFileName, pszReplacementName, strlen( pszReplacementName ) ) == 0 ) + { // We found a replacement! + const char *pszTemplateName = pSubKey->GetString( "template", NULL ); + KeyValues *pReplacementMaterial = NULL; + + if ( pszTemplateName && pTemplatesKV ) + { + KeyValues *pTemplateKV = pTemplatesKV->FindKey( pszTemplateName ); + if ( pTemplateKV ) + { + pTemplateKV = pTemplateKV->FindKey( pszShadername ); + + if ( pTemplateKV && pTemplateKV->GetFirstSubKey() ) + { + pReplacementMaterial = pTemplateKV->GetFirstSubKey()->MakeCopy(); + } + } + } + else + { + if ( pSubKey->GetFirstSubKey() ) + { + pReplacementMaterial = pSubKey->GetFirstSubKey()->MakeCopy(); + } + } + + if ( !pReplacementMaterial ) + { + break; + } + + if ( pReplacementMaterial->GetInt( "$copyall" ) == 1 ) + { + for( KeyValues *pCopyKV = pFallbackKeyValues->GetFirstSubKey(); pCopyKV; pCopyKV = pCopyKV->GetNextKey() ) + { + const char *pszCopyValue = pReplacementMaterial->GetString( pCopyKV->GetName(), NULL ); + if ( !pszCopyValue ) + { + pReplacementMaterial->SetString( pCopyKV->GetName(), pCopyKV->GetString() ); + } + } + } + else + { + int nReplaceIndex = 0; + + while( pszReplacementForceCopy[nReplaceIndex] ) + { + const char *pszCopyValue = pFallbackKeyValues->GetString( pszReplacementForceCopy[nReplaceIndex], NULL ); + if ( pszCopyValue ) + { + pReplacementMaterial->SetString( pszReplacementForceCopy[nReplaceIndex], pszCopyValue ); + } + nReplaceIndex++; + } + } + + for( KeyValues *pSearchKV = pReplacementMaterial->GetFirstSubKey(); pSearchKV; pSearchKV = pSearchKV->GetNextKey() ) + { + const char *pszValue = pSearchKV->GetString(); + if ( pszValue[ 0 ] == '$' ) + { + const char *pszCopyValue = pFallbackKeyValues->GetString( pszValue, NULL ); + if ( pszCopyValue ) + { + pSearchKV->SetStringValue( pszCopyValue ); + } + else + { + pSearchKV->SetStringValue( "" ); + } + } + } + pReplacementProxy = new CReplacementProxy(); + pReplacementProxy->Init( pMaterial, pReplacementMaterial ); + + break; + } + } + } + + if ( pReplacementProxy == NULL ) + { +// Msg( "Failed to find: %s\n", GetName() ); + } + + break; + } + + if ( szCheckPath[ 0 ] == 0 ) + { + break; + } + + strcpy( szLastPath, szCheckPath ); + } + + return pReplacementProxy; +} + + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +void CMaterialSystem::CompactMemory() +{ + for ( int i = 0; i < ARRAYSIZE(m_QueuedRenderContexts); i++) + { + m_QueuedRenderContexts[i].CompactMemory(); + } +} + +void CMaterialSystem::OnRenderingAsyncComplete() +{ + Assert( m_pActiveAsyncJob == NULL ); + + // Update the texture manager, which may cause some textures to become available for compositing. + // Because updating textures may cause textures to swap out their active texture handles, this can only be done + // while the async job is not running. + bool bThreadHadOwnership = m_bThreadHasOwnership; + + TextureManager()->UpdatePostAsync(); + + if ( bThreadHadOwnership && !m_bThreadHasOwnership ) + ThreadAcquire( true ); +} + +//----------------------------------------------------------------------------- +// Material + texture related commands +//----------------------------------------------------------------------------- +void CMaterialSystem::DebugPrintUsedMaterials( const CCommand &args ) +{ + if( args.ArgC() == 1 ) + { + DebugPrintUsedMaterials( NULL, false ); + } + else + { + DebugPrintUsedMaterials( args[ 1 ], false ); + } +} + +void CMaterialSystem::DebugPrintUsedMaterialsVerbose( const CCommand &args ) +{ + if( args.ArgC() == 1 ) + { + DebugPrintUsedMaterials( NULL, true ); + } + else + { + DebugPrintUsedMaterials( args[ 1 ], true ); + } +} + +void CMaterialSystem::DebugPrintUsedTextures( const CCommand &args ) +{ + DebugPrintUsedTextures(); +} + +#if defined( _X360 ) +void CMaterialSystem::ListUsedMaterials( const CCommand &args ) +{ + ListUsedMaterials(); +} +#endif // !_X360 + +void CMaterialSystem::ReloadAllMaterials( const CCommand &args ) +{ + ReloadMaterials( NULL ); +} + +void CMaterialSystem::ReloadMaterials( const CCommand &args ) +{ + if( args.ArgC() != 2 ) + { + ConWarning( "Usage: mat_reloadmaterial material_name_substring\n" + " or mat_reloadmaterial substring1*substring2*...*substringN\n" ); + return; + } + ReloadMaterials( args[ 1 ] ); +} + +void CMaterialSystem::ReloadTextures( const CCommand &args ) +{ + ReloadTextures(); +} + +CON_COMMAND( mat_hdr_enabled, "Report if HDR is enabled for debugging" ) +{ + if( HardwareConfig() && HardwareConfig()->GetHDREnabled() ) + { + Warning( "HDR Enabled\n" ); + } + else + { + Warning( "HDR Disabled\n" ); + } +} + + +static int ReadListFromFile(CUtlVector* outReplacementMaterials, const char *pszPathName) +{ + Assert(outReplacementMaterials != NULL); + Assert(pszPathName != NULL); + + CUtlBuffer fileContents; + if ( !g_pFullFileSystem->ReadFile( pszPathName, NULL, fileContents ) ) + return 0; + + const char* seps[] = { "\r", "\r\n", "\n" }; + V_SplitString2( (char*)fileContents.Base(), seps, ARRAYSIZE(seps), *outReplacementMaterials ); + + + return outReplacementMaterials->Size(); +} diff --git a/materialsystem/cmaterialsystem.h b/materialsystem/cmaterialsystem.h new file mode 100644 index 0000000..a5c890d --- /dev/null +++ b/materialsystem/cmaterialsystem.h @@ -0,0 +1,736 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//============================================================================= + +#ifndef CMATERIALSYSTEM_H +#define CMATERIALSYSTEM_H + +#include "tier1/delegates.h" + +#include "materialsystem_global.h" +#include "materialsystem/imaterialsystem.h" +#include "materialsystem/ishaderapi.h" +#include "imaterialinternal.h" +#include "imaterialsysteminternal.h" +#include "shaderapi/ishaderutil.h" +#include "materialsystem/deformations.h" + +#include "tier1/utlintrusivelist.h" +#include "utlvector.h" +#include "utldict.h" +#include "cmaterialdict.h" +#include "cmatlightmaps.h" +#include "cmatrendercontext.h" +#include "cmatqueuedrendercontext.h" +#include "materialsystem_global.h" + +#ifndef MATSYS_INTERNAL +#error "This file is private to the implementation of IMaterialSystem/IMaterialSystemInternal" +#endif + +#if defined( _WIN32 ) +#pragma once +#endif + +//----------------------------------------------------------------------------- + +class CJob; +class CTextureCompositor; +class IThreadPool; +struct DeferredUpdateLightmapInfo_t; + +// typedefs to allow use of delegation macros +typedef int LightmapOffset_t[2]; + +//----------------------------------------------------------------------------- + +extern CThreadFastMutex g_MatSysMutex; + +//----------------------------------------------------------------------------- +// The material system implementation +//----------------------------------------------------------------------------- + + +class CMaterialSystem : public CTier2AppSystem< IMaterialSystemInternal >, public IShaderUtil +{ + typedef CTier2AppSystem< IMaterialSystemInternal > BaseClass; +public: + + CMaterialSystem(); + ~CMaterialSystem(); + + //--------------------------------------------------------- + // Initialization and shutdown + //--------------------------------------------------------- + + // + // IAppSystem + // + virtual bool Connect( CreateInterfaceFn factory ); + virtual void Disconnect(); + virtual void * QueryInterface( const char *pInterfaceName ); + virtual InitReturnVal_t Init(); + virtual void Shutdown(); + + CreateInterfaceFn Init( const char* pShaderDLL, + IMaterialProxyFactory* pMaterialProxyFactory, + CreateInterfaceFn fileSystemFactory, + CreateInterfaceFn cvarFactory ); + + // Call this to set an explicit shader version to use + // Must be called before Init(). + void SetShaderAPI( const char *pShaderAPIDLL ); + + // Must be called before Init(), if you're going to call it at all... + void SetAdapter( int nAdapter, int nFlags ); + + void ModInit(); + void ModShutdown(); + +private: + // Used to dynamically load and unload the shader api + CreateInterfaceFn CreateShaderAPI( const char* pShaderDLL ); + void DestroyShaderAPI(); + + // Method to get at interfaces supported by the SHADDERAPI + void * QueryShaderAPI( const char *pInterfaceName ); + + // Initializes the color correction terms + void InitColorCorrection(); + + // force the thread mode to single threaded, synchronizes with render thread if running + void ForceSingleThreaded(); + + void ThreadRelease( ); + void ThreadAcquire( bool bForce = false ); + +public: + virtual void SetThreadMode( MaterialThreadMode_t nextThreadMode, int nServiceThread ); + virtual MaterialThreadMode_t GetThreadMode( ); // current thread mode + virtual bool IsRenderThreadSafe( ); + virtual bool AllowThreading( bool bAllow, int nServiceThread ); + virtual void ExecuteQueued(); + + //--------------------------------------------------------- + // Component accessors + //--------------------------------------------------------- + const CMatLightmaps * GetLightmaps() const { return &m_Lightmaps; } + CMatLightmaps * GetLightmaps() { return &m_Lightmaps; } + + IMatRenderContext * GetRenderContext(); + IMatRenderContext * CreateRenderContext( MaterialContextType_t type ); + IMatRenderContext * SetRenderContext( IMatRenderContext * ); + + const IMatRenderContextInternal * GetRenderContextInternal() const { IMatRenderContextInternal *pRenderContext = m_pRenderContext.Get(); return ( pRenderContext ) ? pRenderContext : &m_HardwareRenderContext; } + IMatRenderContextInternal * GetRenderContextInternal() { IMatRenderContextInternal *pRenderContext = m_pRenderContext.Get(); return ( pRenderContext ) ? pRenderContext : &m_HardwareRenderContext; } + + const CMaterialDict * GetMaterialDict() const { return &m_MaterialDict; } + CMaterialDict * GetMaterialDict() { return &m_MaterialDict; } + + virtual void ReloadFilesInList( IFileList *pFilesToReload ); + +public: + //--------------------------------------------------------- + // Config management + //--------------------------------------------------------- + + // IMaterialSystem + virtual IMaterialSystemHardwareConfig * GetHardwareConfig( const char *pVersion, int *returnCode ); + + // Get the current config for this video card (as last set by control panel or the default if not) + virtual bool UpdateConfig( bool forceUpdate ); + virtual bool OverrideConfig( const MaterialSystem_Config_t &config, bool bForceUpdate ); + const MaterialSystem_Config_t & GetCurrentConfigForVideoCard() const; + + // Gets *recommended* configuration information associated with the display card, + virtual bool GetRecommendedConfigurationInfo( int nDXLevel, KeyValues * pKeyValues ); + + // IShaderUtil + MaterialSystem_Config_t & GetConfig(); + +private: + //--------------------------------- + + // This is called when the config changes + void GenerateConfigFromConfigKeyValues( MaterialSystem_Config_t *pConfig, bool bOverwriteCommandLineValues ); + + // Read/write config into convars + void ReadConfigFromConVars( MaterialSystem_Config_t *pConfig ); + void WriteConfigIntoConVars( const MaterialSystem_Config_t &config ); + + // Write dxsupport info to configvars + void WriteConfigurationInfoToConVars( bool bOverwriteCommandLineValues = true ); + + +public: + // ----------------------------------------------------------- + // Device methods + // ----------------------------------------------------------- + int GetDisplayAdapterCount() const; + int GetCurrentAdapter() const; + char *GetDisplayDeviceName() const OVERRIDE; + void GetDisplayAdapterInfo( int adapter, MaterialAdapterInfo_t& info ) const; + int GetModeCount( int adapter ) const; + void GetModeInfo( int adapter, int mode, MaterialVideoMode_t& info ) const; + void AddModeChangeCallBack( ModeChangeCallbackFunc_t func ); + void RemoveModeChangeCallBack( ModeChangeCallbackFunc_t func ); + + // Returns the mode info for the current display device + void GetDisplayMode( MaterialVideoMode_t& info ) const; + bool SetMode( void* hwnd, const MaterialSystem_Config_t &config ); + + // Reports support for a given MSAA mode + bool SupportsMSAAMode( int nMSAAMode ); + + // Reports support for a given CSAA mode + bool SupportsCSAAMode( int nNumSamples, int nQualityLevel ); + + bool SupportsHDRMode( HDRType_t nHDRModede ); + + bool UsesSRGBCorrectBlending() const; + + // Reports support for shadow depth texturing + bool SupportsShadowDepthTextures( void ); + + // Reports support for fetch4 texture access (useful for shadow map PCF in shader) + bool SupportsFetch4( void ); + + // Vendor-dependent shadow depth texture format + ImageFormat GetShadowDepthTextureFormat( void ); + + // Vendor-dependent slim texture format + ImageFormat GetNullTextureFormat( void ); + + // Shadow depth bias factors + void SetShadowDepthBiasFactors( float fShadowSlopeScaleDepthBias, float fShadowDepthBias ); + + const MaterialSystemHardwareIdentifier_t &GetVideoCardIdentifier() const; + + // Use this to spew information about the 3D layer + void SpewDriverInfo() const; + + DELEGATE_TO_OBJECT_2V( GetDXLevelDefaults, uint &, uint &, g_pShaderAPI ); + + DELEGATE_TO_OBJECT_2VC( GetBackBufferDimensions, int &, int &, g_pShaderDevice ); + DELEGATE_TO_OBJECT_0C( ImageFormat, GetBackBufferFormat, g_pShaderDevice ); + + DELEGATE_TO_OBJECT_1V( PushDeformation, DeformationBase_t const *, g_pShaderAPI ); + + DELEGATE_TO_OBJECT_0V( PopDeformation, g_pShaderAPI ); + + DELEGATE_TO_OBJECT_0C(int, GetNumActiveDeformations, g_pShaderAPI ); + + // ----------------------------------------------------------- + // Window methods + // ----------------------------------------------------------- + // Creates/ destroys a child window + bool AddView( void* hwnd ); + void RemoveView( void* hwnd ); + + // Sets the view + void SetView( void* hwnd ); + + // ----------------------------------------------------------- + // Control flow + // ----------------------------------------------------------- + void BeginFrame( float frameTime ); + void EndFrame(); + virtual bool IsInFrame( ) const; + void Flush( bool flushHardware = false ); + void SwapBuffers(); + + // Flushes managed textures from the texture cacher + void EvictManagedResources(); + + void ReleaseResources(); + void ReacquireResources(); + + // Recomputes a state snapshot + void RecomputeAllStateSnapshots(); + + void NoteAnisotropicLevel( int currentLevel ); + + // ----------------------------------------------------------- + // Device loss/restore + // ----------------------------------------------------------- + // Installs a function to be called when we need to release vertex buffers + void AddReleaseFunc( MaterialBufferReleaseFunc_t func ); + void RemoveReleaseFunc( MaterialBufferReleaseFunc_t func ); + + // Installs a function to be called when we need to restore vertex buffers + void AddRestoreFunc( MaterialBufferRestoreFunc_t func ); + void RemoveRestoreFunc( MaterialBufferRestoreFunc_t func ); + + // Called by the shader API when it's just about to lose video memory + void ReleaseShaderObjects(); + void RestoreShaderObjects( CreateInterfaceFn shaderFactory, int nChangeFlags = 0 ); + + // Release temporary HW memory... + void ResetTempHWMemory( bool bExitingLevel = false ); + + // For dealing with device lost in cases where SwapBuffers isn't called all the time (Hammer) + void HandleDeviceLost(); + + + // ----------------------------------------------------------- + // Shaders + // ----------------------------------------------------------- + int ShaderCount() const; + int GetShaders( int nFirstShader, int nCount, IShader **ppShaderList ) const; + int ShaderFlagCount() const; + const char * ShaderFlagName( int nIndex ) const; + void GetShaderFallback( const char *pShaderName, char *pFallbackShader, int nFallbackLength ); + + + // ----------------------------------------------------------- + // Material proxies + // ----------------------------------------------------------- + IMaterialProxyFactory* GetMaterialProxyFactory(); + void SetMaterialProxyFactory( IMaterialProxyFactory* pFactory ); + + + // ----------------------------------------------------------- + // Editor mode + // ----------------------------------------------------------- + bool InEditorMode() const; + + // Used to enable editor materials. Must be called before Init. + void EnableEditorMaterials(); + + // Can we use editor materials? + bool CanUseEditorMaterials() const; + + + // ----------------------------------------------------------- + // Stub mode mode + // ----------------------------------------------------------- + void SetInStubMode( bool bInStubMode ); + bool IsInStubMode(); + + + //--------------------------------------------------------- + // Image formats + //--------------------------------------------------------- + ImageFormatInfo_t const& ImageFormatInfo( ImageFormat fmt) const; + + int GetMemRequired( int width, int height, int depth, ImageFormat format, bool mipmap ); + + bool ConvertImageFormat( unsigned char *src, enum ImageFormat srcImageFormat, + unsigned char *dst, enum ImageFormat dstImageFormat, + int width, int height, int srcStride = 0, int dstStride = 0 ); + + + //--------------------------------------------------------- + // Debug support + //--------------------------------------------------------- + void CreateDebugMaterials(); + void CleanUpDebugMaterials(); + void CleanUpErrorMaterial(); + + void DebugPrintUsedMaterials( const char *pSearchSubString, bool bVerbose ); + void DebugPrintUsedTextures(); + + void ToggleSuppressMaterial( const char* pMaterialName ); + void ToggleDebugMaterial( const char* pMaterialName ); + + + //--------------------------------------------------------- + // Compositor Support + //--------------------------------------------------------- + void CreateCompositorMaterials(); + void CleanUpCompositorMaterials(); + + //--------------------------------------------------------- + // Misc features + //--------------------------------------------------------- + + //returns whether fast clipping is being used or not - needed to be exposed for better per-object clip behavior + bool UsingFastClipping(); + + int StencilBufferBits(); + + + //--------------------------------------------------------- + // Standard material and textures + //--------------------------------------------------------- + void AllocateStandardTextures(); + void ReleaseStandardTextures(); + + IMaterialInternal * GetDrawFlatMaterial() { return m_pDrawFlatMaterial; } + IMaterialInternal * GetBufferClearObeyStencil( int i ) { return m_pBufferClearObeyStencil[i]; } + IMaterialInternal * GetRenderTargetBlitMaterial() { return m_pRenderTargetBlitMaterial; } + + ShaderAPITextureHandle_t GetFullbrightLightmapTextureHandle() const { return m_FullbrightLightmapTextureHandle; } + ShaderAPITextureHandle_t GetFullbrightBumpedLightmapTextureHandle() const { return m_FullbrightBumpedLightmapTextureHandle; } + ShaderAPITextureHandle_t GetBlackTextureHandle() const { return m_BlackTextureHandle; } + ShaderAPITextureHandle_t GetFlatNormalTextureHandle() const { return m_FlatNormalTextureHandle; } + ShaderAPITextureHandle_t GetGreyTextureHandle() const { return m_GreyTextureHandle; } + ShaderAPITextureHandle_t GetGreyAlphaZeroTextureHandle() const { return m_GreyAlphaZeroTextureHandle; } + ShaderAPITextureHandle_t GetWhiteTextureHandle() const { return m_WhiteTextureHandle; } + ShaderAPITextureHandle_t GetLinearToGammaTableTextureHandle() const { return m_LinearToGammaTableTextureHandle; } + ShaderAPITextureHandle_t GetLinearToGammaIdentityTableTextureHandle() const { return m_LinearToGammaIdentityTableTextureHandle; } + ShaderAPITextureHandle_t GetMaxDepthTextureHandle() const { return m_MaxDepthTextureHandle; } + + //--------------------------------------------------------- + // Material and texture management + //--------------------------------------------------------- + // Stop attempting to stream in textures in response to usage. Useful for phases such as loading or other explicit + // operations that shouldn't take usage of textures as a signal to stream them in at full rez. + void SuspendTextureStreaming( ); + void ResumeTextureStreaming( ); + void UncacheAllMaterials(); + void UncacheUnusedMaterials( bool bRecomputeStateSnapshots ); + void CacheUsedMaterials(); + void ReloadTextures(); + void ReloadMaterials( const char *pSubString = NULL ); + + // Create new materials (currently only used by the editor!) + IMaterial * CreateMaterial( const char *pMaterialName, KeyValues *pVMTKeyValues ); + IMaterial * FindMaterial( const char *materialName, const char *pTextureGroupName, bool complain = true, const char *pComplainPrefix = NULL ); + virtual IMaterial * FindMaterialEx( char const* pMaterialName, const char *pTextureGroupName, int nContext, bool complain = true, const char *pComplainPrefix = NULL ); + bool IsMaterialLoaded( const char *materialName ); + virtual IMaterial * FindProceduralMaterial( const char *pMaterialName, const char *pTextureGroupName, KeyValues *pVMTKeyValues ); + const char * GetForcedTextureLoadPathID() { return m_pForcedTextureLoadPathID; } + + void SetAsyncTextureLoadCache( void* h ); + void SetVMTFileLoadCache( void* h ); + + //--------------------------------- + + DELEGATE_TO_OBJECT_0C( MaterialHandle_t, FirstMaterial, &m_MaterialDict ); + DELEGATE_TO_OBJECT_1C( MaterialHandle_t, NextMaterial, MaterialHandle_t, &m_MaterialDict ); + DELEGATE_TO_OBJECT_0C( MaterialHandle_t, InvalidMaterial, &m_MaterialDict ); + DELEGATE_TO_OBJECT_1C( IMaterial *, GetMaterial, MaterialHandle_t, &m_MaterialDict ); + DELEGATE_TO_OBJECT_1C( IMaterialInternal *, GetMaterialInternal, MaterialHandle_t, &m_MaterialDict ); + DELEGATE_TO_OBJECT_0C( int, GetNumMaterials, &m_MaterialDict ); + DELEGATE_TO_OBJECT_1V( AddMaterialToMaterialList, IMaterialInternal *, &m_MaterialDict ); + DELEGATE_TO_OBJECT_1V( RemoveMaterial, IMaterialInternal *, &m_MaterialDict ); + DELEGATE_TO_OBJECT_1V( RemoveMaterialSubRect, IMaterialInternal *, &m_MaterialDict ); + + //--------------------------------- + + ITexture * FindTexture( char const* pTextureName, const char *pTextureGroupName, bool complain = true, int nAdditionalCreationFlags = 0 ); + + bool IsTextureLoaded( const char* pTextureName ) const; + + void AddTextureAlias( const char *pAlias, const char *pRealName ); + void RemoveTextureAlias( const char *pAlias ); + + void SetExcludedTextures( const char *pScriptName ); + void UpdateExcludedTextures( void ); + + // Creates a procedural texture + ITexture * CreateProceduralTexture( const char *pTextureName, + const char *pTextureGroupName, + int w, + int h, + ImageFormat fmt, + int nFlags ); + + // + // Render targets + // + void BeginRenderTargetAllocation(); + void EndRenderTargetAllocation(); // Simulate an Alt-Tab in here, which causes a release/restore of all resources + + // Creates a texture for use as a render target + ITexture * CreateRenderTargetTexture( int w, + int h, + RenderTargetSizeMode_t sizeMode, // Controls how size is generated (and regenerated on video mode change). + ImageFormat format, + MaterialRenderTargetDepth_t depth = MATERIAL_RT_DEPTH_SHARED ); + + ITexture * CreateNamedRenderTargetTextureEx( const char *pRTName, // Pass in NULL here for an unnamed render target. + int w, + int h, + RenderTargetSizeMode_t sizeMode, // Controls how size is generated (and regenerated on video mode change). + ImageFormat format, + MaterialRenderTargetDepth_t depth = MATERIAL_RT_DEPTH_SHARED, + unsigned int textureFlags = TEXTUREFLAGS_CLAMPS | TEXTUREFLAGS_CLAMPT, + unsigned int renderTargetFlags = 0 ); + + ITexture * CreateNamedRenderTargetTexture( const char *pRTName, + int w, + int h, + RenderTargetSizeMode_t sizeMode, // Controls how size is generated (and regenerated on video mode change). + ImageFormat format, + MaterialRenderTargetDepth_t depth = MATERIAL_RT_DEPTH_SHARED, + bool bClampTexCoords = true, + bool bAutoMipMap = false ); + + ITexture * CreateNamedRenderTargetTextureEx2( const char *pRTName, // Pass in NULL here for an unnamed render target. + int w, + int h, + RenderTargetSizeMode_t sizeMode, // Controls how size is generated (and regenerated on video mode change). + ImageFormat format, + MaterialRenderTargetDepth_t depth = MATERIAL_RT_DEPTH_SHARED, + unsigned int textureFlags = TEXTUREFLAGS_CLAMPS | TEXTUREFLAGS_CLAMPT, + unsigned int renderTargetFlags = 0 ); + + virtual ITexture* CreateTextureFromBits(int w, int h, int mips, ImageFormat fmt, int srcBufferSize, byte* srcBits); + + virtual void OverrideRenderTargetAllocation( bool rtAlloc ); + + virtual ITextureCompositor* NewTextureCompositor( int w, int h, const char* pCompositeName, int nTeamNum, uint64 randomSeed, KeyValues* stageDesc, uint32 texCompositeCreateFlags ) OVERRIDE; + void ScheduleTextureComposite( CTextureCompositor* _texCompositor ); + + + virtual void SetRenderTargetFrameBufferSizeOverrides( int nWidth, int nHeight ) OVERRIDE; + virtual void GetRenderTargetFrameBufferDimensions( int & nWidth, int & nHeight ) OVERRIDE; + + virtual void AsyncFindTexture( const char* pFilename, const char *pTextureGroupName, IAsyncTextureOperationReceiver* pRecipient, void* pExtraArgs, bool bComplain = true, int nAdditionalCreationFlags = 0 ) OVERRIDE; + virtual ITexture* CreateNamedTextureFromBitsEx( const char* pName, const char *pTextureGroupName, int w, int h, int mips, ImageFormat fmt, int srcBufferSize, byte* srcBits, int nFlags ) OVERRIDE; + + virtual bool AddTextureCompositorTemplate( const char* pName, KeyValues* pTmplDesc, int nTexCompositeTemplateFlags = 0 ) OVERRIDE; + virtual bool VerifyTextureCompositorTemplates() OVERRIDE; + + + + + // ----------------------------------------------------------- + + bool OnDrawMesh( IMesh *pMesh, int firstIndex, int numIndices ); + bool OnDrawMesh( IMesh *pMesh, CPrimList *pLists, int nLists ); + DELEGATE_TO_OBJECT_3( bool, OnSetFlexMesh, IMesh *, IMesh *, int, GetRenderContextInternal() ); + DELEGATE_TO_OBJECT_3( bool, OnSetColorMesh, IMesh *, IMesh *, int, GetRenderContextInternal() ); + DELEGATE_TO_OBJECT_2( bool, OnSetPrimitiveType, IMesh *, MaterialPrimitiveType_t, GetRenderContextInternal() ); + DELEGATE_TO_OBJECT_0V( SyncMatrices, GetRenderContextInternal() ); + DELEGATE_TO_OBJECT_1V( SyncMatrix, MaterialMatrixMode_t, GetRenderContextInternal() ); + DELEGATE_TO_OBJECT_0( bool, OnFlushBufferedPrimitives, GetRenderContextInternal() ); + void OnThreadEvent( uint32 threadEvent ); + ShaderAPITextureHandle_t GetShaderAPITextureBindHandle( ITexture *pTexture, int nFrame, int nTextureChannel ); // JasonM ???? + + + + // ----------------------------------------------------------- + // Lightmaps delegates + // ----------------------------------------------------------- + DELEGATE_TO_OBJECT_0V( BeginLightmapAllocation, &m_Lightmaps ); + + void EndLightmapAllocation() + { + GetLightmaps()->EndLightmapAllocation(); + AllocateStandardTextures(); + } + + DELEGATE_TO_OBJECT_4( int, AllocateLightmap, int, int, LightmapOffset_t, IMaterial *, &m_Lightmaps ); + DELEGATE_TO_OBJECT_1( int, AllocateWhiteLightmap, IMaterial *, &m_Lightmaps ); + DELEGATE_TO_OBJECT_3( int, AllocateDynamicLightmap, LightmapOffset_t, int *, int, &m_Lightmaps ); + void UpdateLightmap( int, LightmapOffset_t, LightmapOffset_t, float *, float *, float *, float * ); + DELEGATE_TO_OBJECT_0( int, GetNumSortIDs, &m_Lightmaps ); + DELEGATE_TO_OBJECT_1V( GetSortInfo, MaterialSystem_SortInfo_t *, &m_Lightmaps ); + DELEGATE_TO_OBJECT_3VC( GetLightmapPageSize, int, int *, int *, &m_Lightmaps ); + DELEGATE_TO_OBJECT_0V( ResetMaterialLightmapPageInfo, &m_Lightmaps ); + DELEGATE_TO_OBJECT_1C( int, GetLightmapWidth, int, &m_Lightmaps ); + DELEGATE_TO_OBJECT_1C( int, GetLightmapHeight, int, &m_Lightmaps ); + DELEGATE_TO_OBJECT_0V( BeginUpdateLightmaps, &m_Lightmaps ); + DELEGATE_TO_OBJECT_0V( EndUpdateLightmaps, &m_Lightmaps ); + + // ----------------------------------------------------------- + // Render context delegates + // ----------------------------------------------------------- + + // IMaterialSystem + DELEGATE_TO_OBJECT_3V( ClearBuffers, bool, bool, bool, GetRenderContextInternal() ); + + // IMaterialSystemInternal + DELEGATE_TO_OBJECT_0( IMaterial *, GetCurrentMaterial, GetRenderContextInternal() ); + DELEGATE_TO_OBJECT_0( int, GetLightmapPage, GetRenderContextInternal() ); + DELEGATE_TO_OBJECT_0( ITexture *, GetLocalCubemap, GetRenderContextInternal() ); + DELEGATE_TO_OBJECT_1V( ForceDepthFuncEquals, bool, GetRenderContextInternal() ); + DELEGATE_TO_OBJECT_0( MaterialHeightClipMode_t, GetHeightClipMode, GetRenderContextInternal() ); + DELEGATE_TO_OBJECT_0C( bool, InFlashlightMode, GetRenderContextInternal() ); + + // IShaderUtil + DELEGATE_TO_OBJECT_2V( BindStandardTexture, Sampler_t, StandardTextureId_t, &m_HardwareRenderContext ); + DELEGATE_TO_OBJECT_2V( BindStandardVertexTexture, VertexTextureSampler_t, StandardTextureId_t, &m_HardwareRenderContext ); + DELEGATE_TO_OBJECT_2V( GetLightmapDimensions, int *, int *, &m_HardwareRenderContext ); + DELEGATE_TO_OBJECT_3V( GetStandardTextureDimensions, int *, int *, StandardTextureId_t, &m_HardwareRenderContext ); + DELEGATE_TO_OBJECT_0( MorphFormat_t, GetBoundMorphFormat, &m_HardwareRenderContext ); + DELEGATE_TO_OBJECT_1( ITexture *, GetRenderTargetEx, int, &m_HardwareRenderContext ); + DELEGATE_TO_OBJECT_7V( DrawClearBufferQuad, unsigned char, unsigned char, unsigned char, unsigned char, bool, bool, bool, &m_HardwareRenderContext ); + DELEGATE_TO_OBJECT_0C( int, MaxHWMorphBatchCount, g_pMorphMgr ); + DELEGATE_TO_OBJECT_1V( GetCurrentColorCorrection, ShaderColorCorrectionInfo_t*, g_pColorCorrectionSystem ); + +#if defined( _X360 ) + void ListUsedMaterials(); + HXUIFONT OpenTrueTypeFont( const char *pFontname, int tall, int style ); + void CloseTrueTypeFont( HXUIFONT hFont ); + bool GetTrueTypeFontMetrics( HXUIFONT hFont, XUIFontMetrics *pFontMetrics, XUICharMetrics charMetrics[256] ); + // Render a sequence of characters and extract the data into a buffer + // For each character, provide the width+height of the font texture subrect, + // an offset to apply when rendering the glyph, and an offset into a buffer to receive the RGBA data + bool GetTrueTypeGlyphs( HXUIFONT hFont, int numChars, wchar_t *pWch, int *pOffsetX, int *pOffsetY, int *pWidth, int *pHeight, unsigned char *pRGBA, int *pOffset ); + void ReadBackBuffer( Rect_t *pSrcRect, Rect_t *pDstRect, unsigned char *pData, ImageFormat dstFormat, int nDstStride ); + void PersistDisplay(); + void *GetD3DDevice(); + bool OwnGPUResources( bool bEnable ); +#endif + + MaterialLock_t Lock(); + void Unlock( MaterialLock_t ); + CMatCallQueue * GetRenderCallQueue(); + uint GetRenderThreadId() const { return m_nRenderThreadID; } + void UnbindMaterial( IMaterial *pMaterial ); + + IMaterialProxy *DetermineProxyReplacements( IMaterial *pMaterial, KeyValues *pFallbackKeyValues ); + void LoadReplacementMaterials(); + void ScanDirForReplacements( const char *pszPathName ); + void InitReplacementsFromFile( const char *pszPathName ); + + void PreloadReplacements( ); + CUtlDict< KeyValues *, int > m_Replacements; + + virtual void CompactMemory(); + +private: + void OnRenderingAsyncComplete(); + + // ----------------------------------------------------------- +private: + CON_COMMAND_MEMBER_F( CMaterialSystem, "mat_showmaterials", DebugPrintUsedMaterials, "Show materials.", 0 ); + CON_COMMAND_MEMBER_F( CMaterialSystem, "mat_showmaterialsverbose", DebugPrintUsedMaterialsVerbose, "Show materials (verbose version).", 0 ); + CON_COMMAND_MEMBER_F( CMaterialSystem, "mat_showtextures", DebugPrintUsedTextures, "Show used textures.", 0 ); + CON_COMMAND_MEMBER_F( CMaterialSystem, "mat_reloadallmaterials", ReloadAllMaterials, "Reloads all materials", FCVAR_CHEAT ); + CON_COMMAND_MEMBER_F( CMaterialSystem, "mat_reloadmaterial", ReloadMaterials, "Reloads a single material", FCVAR_CHEAT ); + CON_COMMAND_MEMBER_F( CMaterialSystem, "mat_reloadtextures", ReloadTextures, "Reloads all textures", FCVAR_CHEAT ); + +#if defined( _X360 ) + CON_COMMAND_MEMBER_F( CMaterialSystem, "mat_material_list", ListUsedMaterials, "Show used textures.", 0 ); +#endif + + friend void* InstantiateMaterialSystemV76Interface(); + friend CMaterialSystem *CMatLightmaps::GetMaterialSystem() const; + + void ThreadExecuteQueuedContext( CMatQueuedRenderContext *pContext ); + + IThreadPool * CreateMatQueueThreadPool(); + void DestroyMatQueueThreadPool(); + +#ifdef DX_TO_GL_ABSTRACTION + void DoStartupShaderPreloading( void ); +#endif + + // ----------------------------------------------------------- + + CMaterialDict m_MaterialDict; + CMatLightmaps m_Lightmaps; + CThreadLocal m_pRenderContext; + CMatRenderContext m_HardwareRenderContext; + + CMatQueuedRenderContext m_QueuedRenderContexts[2]; + int m_iCurQueuedContext; + + MaterialThreadMode_t m_ThreadMode; + MaterialThreadMode_t m_IdealThreadMode; + bool m_bThreadingNotAvailable; // this is true if the VirtualAlloc()'s in the threading fail to allocate + int m_nServiceThread; + + //--------------------------------- + + char * m_pShaderDLL; + CSysModule * m_ShaderHInst; // Used to dynamically load the shader DLL + CreateInterfaceFn m_ShaderAPIFactory; + + int m_nAdapter; + int m_nAdapterFlags; + + //--------------------------------- + + IMaterialProxyFactory * m_pMaterialProxyFactory; + + //--------------------------------- + // Callback methods for releasing + restoring video memory + CUtlVector< MaterialBufferReleaseFunc_t > m_ReleaseFunc; + CUtlVector< MaterialBufferRestoreFunc_t > m_RestoreFunc; + + //--------------------------------- + + bool m_bRequestedEditorMaterials; + bool m_bCanUseEditorMaterials; + + //--------------------------------- + + // Store texids for various things + ShaderAPITextureHandle_t m_FullbrightLightmapTextureHandle; + ShaderAPITextureHandle_t m_FullbrightBumpedLightmapTextureHandle; + ShaderAPITextureHandle_t m_BlackTextureHandle; + ShaderAPITextureHandle_t m_FlatNormalTextureHandle; + ShaderAPITextureHandle_t m_GreyTextureHandle; + ShaderAPITextureHandle_t m_GreyAlphaZeroTextureHandle; + ShaderAPITextureHandle_t m_WhiteTextureHandle; + ShaderAPITextureHandle_t m_LinearToGammaTableTextureHandle; //linear to gamma srgb conversion lookup for the current hardware + ShaderAPITextureHandle_t m_LinearToGammaIdentityTableTextureHandle; //An identity lookup for when srgb writes are off + ShaderAPITextureHandle_t m_MaxDepthTextureHandle; //a 1x1 texture with maximum depth values. + + // Have we allocated the standard lightmaps? + bool m_StandardTexturesAllocated; + + + bool m_bReplacementFilesValid; + + //--------------------------------- + // Shared materials used for debugging.... + //--------------------------------- + + enum BufferClearType_t //bClearColor + ( bClearAlpha << 1 ) + ( bClearDepth << 2 ) + { + BUFFER_CLEAR_NONE, + BUFFER_CLEAR_COLOR, + BUFFER_CLEAR_ALPHA, + BUFFER_CLEAR_COLOR_AND_ALPHA, + BUFFER_CLEAR_DEPTH, + BUFFER_CLEAR_COLOR_AND_DEPTH, + BUFFER_CLEAR_ALPHA_AND_DEPTH, + BUFFER_CLEAR_COLOR_AND_ALPHA_AND_DEPTH, + + BUFFER_CLEAR_TYPE_COUNT + }; + + IMaterialInternal * m_pBufferClearObeyStencil[BUFFER_CLEAR_TYPE_COUNT]; + IMaterialInternal * m_pDrawFlatMaterial; + IMaterialInternal * m_pRenderTargetBlitMaterial; + CUtlVector< IMaterialInternal* > m_pCompositorMaterials; + + //--------------------------------- + + const char * m_pForcedTextureLoadPathID; + FileCacheHandle_t m_hAsyncLoadFileCache; + uint m_nRenderThreadID; + bool m_bAllocatingRenderTargets; + bool m_bInStubMode; + bool m_bGeneratedConfig; + bool m_bInFrame; + bool m_bForcedSingleThreaded; + bool m_bAllowQueuedRendering; + volatile bool m_bThreadHasOwnership; + uint m_ThreadOwnershipID; + + //--------------------------------- + + CJob * m_pActiveAsyncJob; + CUtlVector m_threadEvents; + + IThreadPool * m_pMatQueueThreadPool; + + //--------------------------------- + + int m_nRenderTargetFrameBufferWidthOverride; + int m_nRenderTargetFrameBufferHeightOverride; + + CUtlVector< CTextureCompositor* > m_scheduledComposites; + CUtlVector< CTextureCompositor* > m_pendingComposites; +}; + +//----------------------------------------------------------------------------- + +inline CMaterialSystem *CMatLightmaps::GetMaterialSystem() const +{ + return GET_OUTER( CMaterialSystem, m_Lightmaps ); +} + +//----------------------------------------------------------------------------- + +#endif // CMATERIALSYSTEM_H diff --git a/materialsystem/cmaterialvar.cpp b/materialsystem/cmaterialvar.cpp new file mode 100644 index 0000000..ce86b92 --- /dev/null +++ b/materialsystem/cmaterialvar.cpp @@ -0,0 +1,1631 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//===========================================================================// + +#include "materialsystem/imaterialvar.h" +#include "materialsystem/imaterialsystem.h" +#include "materialsystem/itexture.h" +#include +#include "materialsystem_global.h" +#include +#include "shaderapi/ishaderapi.h" +#include "imaterialinternal.h" +#include "utlsymbol.h" +#include "mempool.h" +#include "itextureinternal.h" +#include "tier0/dbg.h" +#include "tier1/callqueue.h" +#include "mathlib/vmatrix.h" +#include "tier1/strtools.h" +#include "texturemanager.h" + +#define MATERIALVAR_CHAR_BUF_SIZE 512 + +#if !defined( _X360 ) +#pragma pack (1) +#endif + +ConVar mat_texture_tracking( "mat_texture_tracking", IsDebug() ? "1" : "0" ); +CUtlMap s_TextureRefList( DefLessFunc( ITexture* ) ); +CUtlMap *g_pTextureRefList = &s_TextureRefList; + +struct MaterialVarMatrix_t +{ + VMatrix m_Matrix; + bool m_bIsIdent; +}; + +class CMaterialVar : public IMaterialVar +{ +public: + // stuff from IMaterialVar + virtual const char * GetName( void ) const; + virtual MaterialVarSym_t GetNameAsSymbol() const; + virtual void SetFloatValue( float val ); + virtual void SetIntValue( int val ); + virtual void SetStringValue( const char *val ); + virtual const char * GetStringValue( void ) const; + virtual void SetMatrixValue( VMatrix const& matrix ); + virtual VMatrix const& GetMatrixValue( ); + virtual bool MatrixIsIdentity( void ) const; + virtual void SetVecValue( const float* pVal, int numComps ); + virtual void SetVecValue( float x, float y ); + virtual void SetVecValue( float x, float y, float z ); + virtual void SetVecValue( float x, float y, float z, float w ); + void SetVecValueInternal( const Vector4D &vec, int nComps ); + virtual void SetVecComponentValue( float fVal, int nComponent ); + virtual void GetLinearVecValue( float *val, int numComps ) const; + virtual void SetFourCCValue( FourCC type, void *pData ); + virtual void GetFourCCValue( FourCC *type, void **ppData ); + virtual int GetIntValueInternal( void ) const; + virtual float GetFloatValueInternal( void ) const; + virtual float const* GetVecValueInternal( ) const; + virtual void GetVecValueInternal( float *val, int numcomps ) const; + virtual int VectorSizeInternal() const; + + // revisit: is this a good interface for textures? + + virtual ITexture * GetTextureValue( void ); + virtual void SetTextureValue( ITexture * ); + void SetTextureValueQueued( ITexture *texture ); + + virtual IMaterial * GetMaterialValue( void ); + virtual void SetMaterialValue( IMaterial * ); + + virtual operator ITexture *() { return GetTextureValue(); } + virtual bool IsDefined() const; + virtual void SetUndefined(); + + virtual void CopyFrom( IMaterialVar *pMaterialVar ); + + FORCEINLINE void Init( void ) + { + m_nNumVectorComps = 4; + m_VecVal.Init(); + m_pStringVal = NULL; + m_intVal = 0; + m_nTempIndex = 0xFF; + m_bFakeMaterialVar = false; + m_Type = MATERIAL_VAR_TYPE_INT; + } + + // stuff that is only visible inside of the material system + CMaterialVar(); + CMaterialVar( IMaterial* pMaterial, const char *key, VMatrix const& matrix ); + CMaterialVar( IMaterial* pMaterial, const char *key, const char *val ); + CMaterialVar( IMaterial* pMaterial, const char *key, float* pVal, int numcomps ); + CMaterialVar( IMaterial* pMaterial, const char *key, float val ); + CMaterialVar( IMaterial* pMaterial, const char *key, int val ); + CMaterialVar( IMaterial* pMaterial, const char *key ); + virtual ~CMaterialVar(); + + virtual void SetValueAutodetectType( const char *val ); + + virtual IMaterial * GetOwningMaterial() { return m_pMaterial; } + +private: + // Cleans up material var data + CMaterialVar *AllocThreadVar(); + void CleanUpData(); + + // NOTE: Dummy vars have no backlink so we have to check the pointer here + void VarChanged() { if ( m_pMaterial ) m_pMaterial->ReportVarChanged(this); } + + // class data + static char s_CharBuf[MATERIALVAR_CHAR_BUF_SIZE]; + static ITextureInternal *m_dummyTexture; + + // Fixed-size allocator +#ifdef NO_SBH // not needed if tier0 small block heap enabled + DECLARE_FIXEDSIZE_ALLOCATOR( CMaterialVar ); +#endif + + // Owning material.... + IMaterialInternal* m_pMaterial; + + // Only using one of these at a time... + struct FourCC_t + { + FourCC m_FourCC; + void *m_pFourCCData; + }; + + FourCC_t *AllocFourCC(); + + union + { + IMaterialInternal* m_pMaterialValue; + ITextureInternal *m_pTexture; + MaterialVarMatrix_t* m_pMatrix; + FourCC_t *m_pFourCC; + }; +}; + +// Has to exist *after* fixed size allocator declaration +#include "tier0/memdbgon.h" + +typedef CMaterialVar *CMaterialVarPtr; + +#ifdef NO_SBH // not needed if tier0 small block heap enabled +DEFINE_FIXEDSIZE_ALLOCATOR( CMaterialVar, 1024, true ); +#endif + +// Stores symbols for the material vars +static CUtlSymbolTableMT s_MaterialVarSymbols( 0, 32, true ); + +static bool g_bDeleteUnreferencedTexturesEnabled = false; + + +//----------------------------------------------------------------------------- +// Used to make GetIntValue thread safe from within proxy calls +//----------------------------------------------------------------------------- +static CMaterialVar s_pTempMaterialVar[254]; +static MaterialVarMatrix_t s_pTempMatrix[254]; +static bool s_bEnableThreadedAccess = false; +static int s_nTempVarsUsed = 0; +static int s_nOverflowTempVars = 0; + + +//----------------------------------------------------------------------------- +// Global methods related to material vars +//----------------------------------------------------------------------------- +void EnableThreadedMaterialVarAccess( bool bEnable, IMaterialVar **ppParams, int nVarCount ) +{ + if ( s_bEnableThreadedAccess == bEnable ) + return; + + s_bEnableThreadedAccess = bEnable; + if ( !s_bEnableThreadedAccess ) + { + // Necessary to free up reference counts + Assert( s_nTempVarsUsed <= Q_ARRAYSIZE(s_pTempMaterialVar) ); + for ( int i = 0; i < s_nTempVarsUsed; ++i ) + { + s_pTempMaterialVar[i].SetUndefined(); + } + for ( int i = 0; i < nVarCount; ++i ) + { + ppParams[i]->SetTempIndex( 0xFF ); + } + s_nTempVarsUsed = 0; + if ( s_nOverflowTempVars ) + { + Warning("Overflowed %d temp material vars!\n", s_nOverflowTempVars ); + s_nOverflowTempVars = 0; + } + } +} + + +CMaterialVar *CMaterialVar::AllocThreadVar() +{ + if ( s_bEnableThreadedAccess ) + { + if ( m_nTempIndex == 0xFF ) + { + if ( s_nTempVarsUsed >= Q_ARRAYSIZE(s_pTempMaterialVar) ) + { + s_nOverflowTempVars++; + return NULL; + } + m_nTempIndex = s_nTempVarsUsed++; + } + + return &s_pTempMaterialVar[m_nTempIndex]; + } + + return NULL; +} + +//----------------------------------------------------------------------------- +// Purpose: Static method +// Input : enable - +//----------------------------------------------------------------------------- +void IMaterialVar::DeleteUnreferencedTextures( bool enable ) +{ + g_bDeleteUnreferencedTexturesEnabled = enable; +} + +//----------------------------------------------------------------------------- +// class factory methods +//----------------------------------------------------------------------------- +IMaterialVar* IMaterialVar::Create( IMaterial* pMaterial, const char* pKey, VMatrix const& matrix ) +{ + return new CMaterialVar( pMaterial, pKey, matrix ); +} + +IMaterialVar* IMaterialVar::Create( IMaterial* pMaterial, const char* pKey, const char* pVal ) +{ + return new CMaterialVar( pMaterial, pKey, pVal ); +} + +IMaterialVar* IMaterialVar::Create( IMaterial* pMaterial, const char* pKey, float* pVal, int numComps ) +{ + return new CMaterialVar( pMaterial, pKey, pVal, numComps ); +} + +IMaterialVar* IMaterialVar::Create( IMaterial* pMaterial, const char* pKey, float val ) +{ + return new CMaterialVar( pMaterial, pKey, val ); +} + +IMaterialVar* IMaterialVar::Create( IMaterial* pMaterial, const char* pKey, int val ) +{ + return new CMaterialVar( pMaterial, pKey, val ); +} + +IMaterialVar* IMaterialVar::Create( IMaterial* pMaterial, const char* pKey ) +{ + return new CMaterialVar( pMaterial, pKey ); +} + +void IMaterialVar::Destroy( IMaterialVar* pVar ) +{ + if (pVar) + { + CMaterialVar* pVarImp = static_cast(pVar); + delete pVarImp; + } +} + +MaterialVarSym_t IMaterialVar::GetSymbol( const char* pName ) +{ + if (!pName) + return UTL_INVAL_SYMBOL; + + char temp[1024]; + Q_strncpy( temp, pName, sizeof( temp ) ); + Q_strlower( temp ); + return s_MaterialVarSymbols.AddString( temp ); +} + +MaterialVarSym_t IMaterialVar::FindSymbol( const char* pName ) +{ + if (!pName) + return UTL_INVAL_SYMBOL; + + return s_MaterialVarSymbols.Find( pName ); +} + +bool IMaterialVar::SymbolMatches( const char* pName, MaterialVarSym_t symbol ) +{ + return !Q_stricmp( s_MaterialVarSymbols.String(symbol), pName ); +} + + +//----------------------------------------------------------------------------- +// class globals +//----------------------------------------------------------------------------- +char CMaterialVar::s_CharBuf[MATERIALVAR_CHAR_BUF_SIZE]; + + +//----------------------------------------------------------------------------- +// constructors +//----------------------------------------------------------------------------- +inline CMaterialVar::FourCC_t *CMaterialVar::AllocFourCC() +{ + return new FourCC_t; +} + + +//----------------------------------------------------------------------------- +// NOTE: This constructor is only used by the "fake" material vars +// used to get thread mode working +//----------------------------------------------------------------------------- +CMaterialVar::CMaterialVar() +{ + Init(); + m_pMaterial = NULL; + m_bFakeMaterialVar = true; +} + +//------------------------------------- + +CMaterialVar::CMaterialVar( IMaterial* pMaterial, const char *pKey, VMatrix const& matrix ) +{ + Init(); + Assert( pKey ); + + m_pMaterial = static_cast(pMaterial); + m_Name = GetSymbol( pKey ); + Assert( m_Name != UTL_INVAL_SYMBOL ); + m_Type = MATERIAL_VAR_TYPE_MATRIX; + m_pMatrix = new MaterialVarMatrix_t; + Assert( m_pMatrix ); + MatrixCopy( matrix, m_pMatrix->m_Matrix ); + m_pMatrix->m_bIsIdent = matrix.IsIdentity(); + m_intVal = 0; + m_VecVal.Init(); + +} + +CMaterialVar::CMaterialVar( IMaterial* pMaterial, const char *pKey, const char *pVal ) +{ + Init(); + Assert( pVal && pKey ); + + m_pMaterial = static_cast(pMaterial); + m_Name = GetSymbol( pKey ); + Assert( m_Name != UTL_INVAL_SYMBOL ); + int len = Q_strlen( pVal ) + 1; + m_pStringVal = new char[ len ]; + Q_strncpy( m_pStringVal, pVal, len ); + m_Type = MATERIAL_VAR_TYPE_STRING; + m_VecVal[0] = m_VecVal[1] = m_VecVal[2] = m_VecVal[3] = atof( m_pStringVal ); + m_intVal = int( atof( m_pStringVal ) ); +} + +CMaterialVar::CMaterialVar( IMaterial* pMaterial, const char *pKey, float* pVal, int numComps ) +{ + Init(); + Assert( pVal && pKey && (numComps <= 4) ); + + m_pMaterial = static_cast(pMaterial);; + m_Name = GetSymbol( pKey ); + Assert( m_Name != UTL_INVAL_SYMBOL ); + m_Type = MATERIAL_VAR_TYPE_VECTOR; + memcpy( m_VecVal.Base(), pVal, numComps * sizeof(float) ); + for (int i = numComps; i < 4; ++i) + m_VecVal[i] = 0.0f; + + m_intVal = ( int ) m_VecVal[0]; + m_nNumVectorComps = numComps; +} + +CMaterialVar::CMaterialVar( IMaterial* pMaterial, const char *pKey, float val ) +{ + Init(); + m_pMaterial = static_cast(pMaterial); + m_Name = GetSymbol( pKey ); + Assert( m_Name != UTL_INVAL_SYMBOL ); + m_Type = MATERIAL_VAR_TYPE_FLOAT; + m_VecVal[0] = m_VecVal[1] = m_VecVal[2] = m_VecVal[3] = val; + m_intVal = (int) val; + +} + +CMaterialVar::CMaterialVar( IMaterial* pMaterial, const char *pKey, int val ) +{ + Init(); + m_pMaterial = static_cast(pMaterial); + m_Name = GetSymbol( pKey ); + Assert( m_Name != UTL_INVAL_SYMBOL ); + m_Type = MATERIAL_VAR_TYPE_INT; + m_VecVal[0] = m_VecVal[1] = m_VecVal[2] = m_VecVal[3] = (float) val; + m_intVal = val; +} + +CMaterialVar::CMaterialVar( IMaterial* pMaterial, const char *pKey ) +{ + Init(); + m_pMaterial = static_cast(pMaterial); + m_Name = GetSymbol( pKey ); + Assert( m_Name != UTL_INVAL_SYMBOL ); + m_Type = MATERIAL_VAR_TYPE_UNDEFINED; +} + + +//----------------------------------------------------------------------------- +// destructor +//----------------------------------------------------------------------------- +CMaterialVar::~CMaterialVar() +{ + CleanUpData(); +} + + +//----------------------------------------------------------------------------- +// Cleans up material var allocated data if necessary +//----------------------------------------------------------------------------- +void CMaterialVar::CleanUpData() +{ + switch ( m_Type ) + { + case MATERIAL_VAR_TYPE_STRING: + delete [] m_pStringVal; + m_pStringVal = NULL; + break; + + case MATERIAL_VAR_TYPE_TEXTURE: + // garymcthack + if( m_pTexture && !IsTextureInternalEnvCubemap( m_pTexture ) ) + { + m_pTexture->DecrementReferenceCount(); + if ( g_bDeleteUnreferencedTexturesEnabled ) + { + m_pTexture->DeleteIfUnreferenced(); + } + m_pTexture = NULL; + } + break; + + case MATERIAL_VAR_TYPE_MATERIAL: + if( m_pMaterialValue != NULL ) + { + m_pMaterialValue->DecrementReferenceCount(); + m_pMaterialValue = NULL; + } + break; + + case MATERIAL_VAR_TYPE_MATRIX: + delete m_pMatrix; + m_pMatrix = NULL; + break; + + case MATERIAL_VAR_TYPE_FOURCC: + delete m_pFourCC; + m_pFourCC = NULL; + break; + + case MATERIAL_VAR_TYPE_VECTOR: + case MATERIAL_VAR_TYPE_INT: + case MATERIAL_VAR_TYPE_FLOAT: + default: + break; + } +} + + +//----------------------------------------------------------------------------- +// name + type +//----------------------------------------------------------------------------- +MaterialVarSym_t CMaterialVar::GetNameAsSymbol() const +{ + return m_Name; +} + +const char *CMaterialVar::GetName( ) const +{ + if( !m_Name.IsValid() ) + { + Warning( "m_pName is NULL for CMaterialVar\n" ); + return ""; + } + return s_MaterialVarSymbols.String( m_Name ); +} + + +//----------------------------------------------------------------------------- +// Thread-safe versions +//----------------------------------------------------------------------------- +int CMaterialVar::GetIntValueInternal( void ) const +{ + CMatCallQueue *pCallQueue = MaterialSystem()->GetRenderCallQueue(); + if ( pCallQueue && !m_bFakeMaterialVar ) + { + if ( !s_bEnableThreadedAccess ) + { + //DevMsg( 2, "Non-thread safe call to CMaterialVar %s!\n", GetName() ); + } + + if ( m_nTempIndex != 0xFF ) + return s_pTempMaterialVar[m_nTempIndex].GetIntValueInternal(); + } + + // Set methods for float and vector update this + return m_intVal; +} + +float CMaterialVar::GetFloatValueInternal( void ) const +{ + CMatCallQueue *pCallQueue = MaterialSystem()->GetRenderCallQueue(); + if ( pCallQueue && !m_bFakeMaterialVar ) + { + if ( !s_bEnableThreadedAccess ) + { + //DevMsg( 2, "Non-thread safe call to CMaterialVar %s!\n", GetName() ); + } + + if ( m_nTempIndex != 0xFF ) + return s_pTempMaterialVar[m_nTempIndex].GetFloatValueInternal(); + } + + return m_VecVal[0]; +} + +float const* CMaterialVar::GetVecValueInternal( ) const +{ + CMatCallQueue *pCallQueue = MaterialSystem()->GetRenderCallQueue(); + if ( pCallQueue && !m_bFakeMaterialVar ) + { + if ( !s_bEnableThreadedAccess ) + { + //DevMsg( 2, "Non-thread safe call to CMaterialVar %s!\n", GetName() ); + } + + if ( m_nTempIndex != 0xFF ) + return s_pTempMaterialVar[m_nTempIndex].GetVecValueInternal(); + } + + return m_VecVal.Base(); +} + +void CMaterialVar::GetVecValueInternal( float *val, int numcomps ) const +{ + CMatCallQueue *pCallQueue = MaterialSystem()->GetRenderCallQueue(); + if ( pCallQueue && !m_bFakeMaterialVar ) + { + if ( !s_bEnableThreadedAccess ) + { + //DevMsg( 2, "Non-thread safe call to CMaterialVar %s!\n", GetName() ); + } + + if ( m_nTempIndex != 0xFF ) + { + s_pTempMaterialVar[m_nTempIndex].GetVecValueInternal( val, numcomps ); + return; + } + } + + Assert( ( numcomps >0 ) && ( numcomps <= 4 ) ); + for( int i=0 ; i < numcomps; i++ ) + { + val[i] = m_VecVal[ i ]; + } +} + +int CMaterialVar::VectorSizeInternal() const +{ + CMatCallQueue *pCallQueue = MaterialSystem()->GetRenderCallQueue(); + if ( pCallQueue && !m_bFakeMaterialVar ) + { + if ( !s_bEnableThreadedAccess ) + { + //DevMsg( 2, "Non-thread safe call to CMaterialVar %s!\n", GetName() ); + } + + if ( m_nTempIndex != 0xFF ) + return s_pTempMaterialVar[m_nTempIndex].VectorSizeInternal( ); + } + + return m_nNumVectorComps; +} + +// Don't want to be grabbing the dummy var and changing it's value. That usually means badness. +#define ASSERT_NOT_DUMMY_VAR() AssertMsg( m_bFakeMaterialVar || ( V_stricmp( GetName(), "$dummyvar" ) != 0 ), "TRYING TO MODIFY $dummyvar, WHICH IS BAD, MMMKAY!" ) + +//----------------------------------------------------------------------------- +// float +//----------------------------------------------------------------------------- +void CMaterialVar::SetFloatValue( float val ) +{ + ASSERT_NOT_DUMMY_VAR(); + CMatCallQueue *pCallQueue = MaterialSystem()->GetRenderCallQueue(); + if ( !m_bFakeMaterialVar && pCallQueue ) + { + CMaterialVar *pThreadVar = AllocThreadVar(); + if ( pThreadVar ) + { + pThreadVar->SetFloatValue( val ); + } + pCallQueue->QueueCall( this, &CMaterialVar::SetFloatValue, val ); + return; + } + + // Suppress all this if we're not actually changing anything + if ((m_Type == MATERIAL_VAR_TYPE_FLOAT) && (m_VecVal[0] == val)) + return; + + // Gotta flush if we've changed state and this is the current material + if ( !m_bFakeMaterialVar && m_pMaterial && (m_pMaterial == ( IMaterialInternal* )MaterialSystem()->GetCurrentMaterial())) + g_pShaderAPI->FlushBufferedPrimitives(); + + CleanUpData(); + m_VecVal[0] = m_VecVal[1] = m_VecVal[2] = m_VecVal[3] = val; + m_intVal = (int) val; + m_Type = MATERIAL_VAR_TYPE_FLOAT; + VarChanged(); +} + + +//----------------------------------------------------------------------------- +// int +//----------------------------------------------------------------------------- +void CMaterialVar::SetIntValue( int val ) +{ + ASSERT_NOT_DUMMY_VAR(); + CMatCallQueue *pCallQueue = MaterialSystem()->GetRenderCallQueue(); + if ( !m_bFakeMaterialVar && pCallQueue ) + { + CMaterialVar *pThreadVar = AllocThreadVar(); + if ( pThreadVar ) + { + pThreadVar->SetIntValue( val ); + } + pCallQueue->QueueCall( this, &CMaterialVar::SetIntValue, val ); + return; + } + + // Suppress all this if we're not actually changing anything + if ((m_Type == MATERIAL_VAR_TYPE_INT) && (m_intVal == val)) + return; + + // Gotta flush if we've changed state and this is the current material + if ( !m_bFakeMaterialVar && m_pMaterial && (m_pMaterial == ( IMaterialInternal* )MaterialSystem()->GetCurrentMaterial())) + g_pShaderAPI->FlushBufferedPrimitives(); + + CleanUpData(); + m_intVal = val; + m_VecVal[0] = m_VecVal[1] = m_VecVal[2] = m_VecVal[3] = (float) val; + m_Type = MATERIAL_VAR_TYPE_INT; + VarChanged(); +} + + +//----------------------------------------------------------------------------- +// string +//----------------------------------------------------------------------------- +const char *CMaterialVar::GetStringValue( void ) const +{ + CMatCallQueue *pCallQueue = MaterialSystem()->GetRenderCallQueue(); + if ( pCallQueue && !m_bFakeMaterialVar ) + { + if ( !s_bEnableThreadedAccess ) + { + //DevMsg( 2, "Non-thread safe call to CMaterialVar %s!\n", GetName() ); + } + + if ( m_nTempIndex != 0xFF ) + return s_pTempMaterialVar[m_nTempIndex].GetStringValue(); + } + + switch( m_Type ) + { + case MATERIAL_VAR_TYPE_STRING: + return m_pStringVal; + + case MATERIAL_VAR_TYPE_INT: + Q_snprintf( s_CharBuf, sizeof( s_CharBuf ), "%d", m_intVal ); + return s_CharBuf; + + case MATERIAL_VAR_TYPE_FLOAT: + Q_snprintf( s_CharBuf, sizeof( s_CharBuf ), "%f", m_VecVal[0] ); + return s_CharBuf; + + case MATERIAL_VAR_TYPE_VECTOR: + { + s_CharBuf[0] = '['; + s_CharBuf[1] = ' '; + int len = 2; + for (int i = 0; i < m_nNumVectorComps; ++i) + { + if (len < sizeof( s_CharBuf )) + { + Q_snprintf( s_CharBuf + len, sizeof( s_CharBuf ) - len, "%f ", m_VecVal[i] ); + len += strlen( s_CharBuf + len ); + } + } + if (len < sizeof( s_CharBuf ) - 1) + { + s_CharBuf[len] = ']'; + s_CharBuf[len+1] = '\0'; + } + else + { + s_CharBuf[sizeof( s_CharBuf )-1] = '\0'; + } + return s_CharBuf; + } + + case MATERIAL_VAR_TYPE_MATRIX: + { + s_CharBuf[0] = '['; + s_CharBuf[1] = ' '; + int len = 2; + for (int i = 0; i < 4; ++i) + { + for (int j = 0; j < 4; ++j) + { + if (len < sizeof( s_CharBuf )) + len += Q_snprintf( s_CharBuf + len, sizeof( s_CharBuf ) - len, "%.3f ", m_pMatrix->m_Matrix[j][i] ); + } + } + if (len < sizeof( s_CharBuf ) - 1) + { + s_CharBuf[len] = ']'; + s_CharBuf[len+1] = '\0'; + } + else + { + s_CharBuf[sizeof( s_CharBuf )-1] = '\0'; + } + return s_CharBuf; + } + + case MATERIAL_VAR_TYPE_TEXTURE: + // check for env_cubemap + if( IsTextureInternalEnvCubemap( m_pTexture ) ) + { + return "env_cubemap"; + } + else + { + Q_snprintf( s_CharBuf, sizeof( s_CharBuf ), "%s", m_pTexture->GetName() ); + return s_CharBuf; + } + case MATERIAL_VAR_TYPE_MATERIAL: + Q_snprintf( s_CharBuf, sizeof( s_CharBuf ), "%s", ( m_pMaterialValue ? m_pMaterialValue->GetName() : "" ) ); + return s_CharBuf; + + case MATERIAL_VAR_TYPE_UNDEFINED: + return ""; + + default: + Warning( "CMaterialVar::GetStringValue: Unknown material var type\n" ); + return ""; + } +} + +void CMaterialVar::SetStringValue( const char *val ) +{ + ASSERT_NOT_DUMMY_VAR(); + CMatCallQueue *pCallQueue = MaterialSystem()->GetRenderCallQueue(); + if ( !m_bFakeMaterialVar && pCallQueue ) + { + CMaterialVar *pThreadVar = AllocThreadVar(); + if ( pThreadVar ) + { + pThreadVar->SetStringValue( val ); + } + pCallQueue->QueueCall( this, &CMaterialVar::SetStringValue, CUtlEnvelope(val) ); + return; + } + + // Gotta flush if we've changed state and this is the current material + if ( !m_bFakeMaterialVar && m_pMaterial && (m_pMaterial == ( IMaterialInternal* )MaterialSystem()->GetCurrentMaterial())) + g_pShaderAPI->FlushBufferedPrimitives(); + + CleanUpData(); + int len = Q_strlen( val ) + 1; + m_pStringVal = new char[len]; + Q_strncpy( m_pStringVal, val, len ); + m_Type = MATERIAL_VAR_TYPE_STRING; + m_intVal = atoi( val ); + m_VecVal[0] = m_VecVal[1] = m_VecVal[2] = m_VecVal[3] = atof( m_pStringVal ); + VarChanged(); +} + +void CMaterialVar::SetFourCCValue( FourCC type, void *pData ) +{ + ASSERT_NOT_DUMMY_VAR(); + CMatCallQueue *pCallQueue = MaterialSystem()->GetRenderCallQueue(); + if ( !m_bFakeMaterialVar && pCallQueue ) + { + CMaterialVar *pThreadVar = AllocThreadVar(); + if ( pThreadVar ) + { + pThreadVar->SetFourCCValue( type, pData ); + } + pCallQueue->QueueCall( this, &CMaterialVar::SetFourCCValue, type, pData ); + return; + } + + // Suppress all this if we're not actually changing anything + if ((m_Type == MATERIAL_VAR_TYPE_FOURCC) && m_pFourCC->m_FourCC == type && m_pFourCC->m_pFourCCData == pData ) + return; + + // Gotta flush if we've changed state and this is the current material + if ( !m_bFakeMaterialVar && m_pMaterial && (m_pMaterial == ( IMaterialInternal* )MaterialSystem()->GetCurrentMaterial())) + g_pShaderAPI->FlushBufferedPrimitives(); + + CleanUpData(); + + m_pFourCC = AllocFourCC(); + m_pFourCC->m_FourCC = type; + m_pFourCC->m_pFourCCData = pData; + m_Type = MATERIAL_VAR_TYPE_FOURCC; + m_VecVal.Init(); + m_intVal = 0; + VarChanged(); +} + +void CMaterialVar::GetFourCCValue( FourCC *type, void **ppData ) +{ + CMatCallQueue *pCallQueue = MaterialSystem()->GetRenderCallQueue(); + if ( pCallQueue && !m_bFakeMaterialVar ) + { + if ( !s_bEnableThreadedAccess ) + { + //DevMsg( 2, "Non-thread safe call to CMaterialVar %s!\n", GetName() ); + } + + if ( m_nTempIndex != 0xFF ) + return s_pTempMaterialVar[m_nTempIndex].GetFourCCValue( type, ppData ); + } + + if( m_Type == MATERIAL_VAR_TYPE_FOURCC ) + { + *type = m_pFourCC->m_FourCC; + *ppData = m_pFourCC->m_pFourCCData; + } + else + { + *type = FOURCC_UNKNOWN; + *ppData = 0; + + static int bitchCount; + if( bitchCount < 10 ) + { + Warning( "CMaterialVar::GetVecValue: trying to get a vec value for %s which is of type %d\n", + GetName(), ( int )m_Type ); + bitchCount++; + } + } +} + + +//----------------------------------------------------------------------------- +// texture +//----------------------------------------------------------------------------- +ITexture *CMaterialVar::GetTextureValue( void ) +{ + CMatCallQueue *pCallQueue = MaterialSystem()->GetRenderCallQueue(); + if ( pCallQueue && !m_bFakeMaterialVar ) + { + if ( !s_bEnableThreadedAccess ) + { + //DevMsg( 2, "Non-thread safe call to CMaterialVar %s!\n", GetName() ); + } + + if ( m_nTempIndex != 0xFF ) + return s_pTempMaterialVar[m_nTempIndex].GetTextureValue( ); + } + + ITexture *retVal = NULL; + + if( m_pMaterial ) + { + m_pMaterial->Precache(); + } + + if( m_Type == MATERIAL_VAR_TYPE_TEXTURE ) + { + if ( !IsTextureInternalEnvCubemap( m_pTexture ) ) + { + retVal = static_cast( m_pTexture ); + } + else + { + retVal = MaterialSystem()->GetLocalCubemap(); + } + if( !retVal ) + { + static int bitchCount = 0; + if( bitchCount < 10 ) + { + Warning( "Invalid texture value in CMaterialVar::GetTextureValue\n" ); + bitchCount++; + } + } + } + else + { + static int bitchCount = 0; + if( bitchCount < 10 ) + { + Warning( "Requesting texture value from var \"%s\" which is " + "not a texture value (material: %s)\n", GetName(), + m_pMaterial ? m_pMaterial->GetName() : "NULL material" ); + bitchCount++; + } + } + + if( !retVal ) + { + retVal = TextureManager()->ErrorTexture(); + } + return retVal; +} + + +void CMaterialVar::SetTextureValueQueued( ITexture *texture ) +{ + SetTextureValue( texture ); + + // Matches IncrementReferenceCount in SetTextureValue + if ( texture ) + texture->DecrementReferenceCount(); + + // Debug + if ( mat_texture_tracking.GetBool() ) + { + int iIndex = g_pTextureRefList->Find( texture ); + Assert( iIndex != g_pTextureRefList->InvalidIndex() ); + g_pTextureRefList->Element( iIndex )--; + } +} + +static bool s_bInitTextureRefList = false; + +void CMaterialVar::SetTextureValue( ITexture *texture ) +{ + if ( !s_bInitTextureRefList ) + { + g_pTextureRefList->SetLessFunc( DefLessFunc( ITexture* ) ); + s_bInitTextureRefList = true; + } + + // Avoid the garymcthack in CShaderSystem::LoadCubeMap by ensuring we're not using + // the internal env cubemap. + if ( ThreadInMainThread() && !IsTextureInternalEnvCubemap( static_cast( texture ) ) ) + { + ITextureInternal* pTexInternal = assert_cast( texture ); + TextureManager()->RequestAllMipmaps( pTexInternal ); + } + + ASSERT_NOT_DUMMY_VAR(); + CMatCallQueue *pCallQueue = MaterialSystem()->GetRenderCallQueue(); + if ( !m_bFakeMaterialVar && pCallQueue ) + { + // FIXME (toml): deal with reference count + CMaterialVar *pThreadVar = AllocThreadVar(); + if ( pThreadVar ) + { + pThreadVar->SetTextureValue( texture ); + } + + // Matches DecrementReferenceCount in SetTextureValueQueued + if ( texture ) + texture->IncrementReferenceCount(); + + // Debug! + if ( mat_texture_tracking.GetBool() ) + { + int iIndex = g_pTextureRefList->Find( texture ); + if ( iIndex == g_pTextureRefList->InvalidIndex() ) + { + g_pTextureRefList->Insert( texture, 1 ); + } + else + { + g_pTextureRefList->Element( iIndex )++; + } + } + + pCallQueue->QueueCall( this, &CMaterialVar::SetTextureValueQueued, texture ); + return; + } + + ITextureInternal* pTexImp = static_cast( texture ); + + // Suppress all this if we're not actually changing anything + if ((m_Type == MATERIAL_VAR_TYPE_TEXTURE) && (m_pTexture == pTexImp)) + return; + + // Gotta flush if we've changed state and this is the current material + if ( !m_bFakeMaterialVar && m_pMaterial && (m_pMaterial == MaterialSystem()->GetCurrentMaterial())) + g_pShaderAPI->FlushBufferedPrimitives(); + + if( pTexImp && !IsTextureInternalEnvCubemap( pTexImp ) ) + { + pTexImp->IncrementReferenceCount(); + } + + CleanUpData(); + m_pTexture = pTexImp; + m_Type = MATERIAL_VAR_TYPE_TEXTURE; + m_intVal = 0; + m_VecVal.Init(); + VarChanged(); +} + + +//----------------------------------------------------------------------------- +// material +//----------------------------------------------------------------------------- +IMaterial *CMaterialVar::GetMaterialValue( void ) +{ + CMatCallQueue *pCallQueue = MaterialSystem()->GetRenderCallQueue(); + if ( pCallQueue && !m_bFakeMaterialVar ) + { + if ( !s_bEnableThreadedAccess ) + { + //DevMsg( 2, "Non-thread safe call to CMaterialVar %s!\n", GetName() ); + } + + if ( m_nTempIndex != 0xFF ) + return s_pTempMaterialVar[m_nTempIndex].GetMaterialValue( ); + } + + IMaterial *retVal = NULL; + + if( m_pMaterial ) + { + m_pMaterial->Precache(); + } + + if( m_Type == MATERIAL_VAR_TYPE_MATERIAL ) + { + retVal = static_cast( m_pMaterialValue ); + } + else + { + static int bitchCount = 0; + if( bitchCount < 10 ) + { + Warning( "Requesting material value from var \"%s\" which is " + "not a material value (material: %s)\n", GetName(), + m_pMaterial ? m_pMaterial->GetName() : "NULL material" ); + bitchCount++; + } + } + return retVal; +} + +void CMaterialVar::SetMaterialValue( IMaterial *pMaterial ) +{ + ASSERT_NOT_DUMMY_VAR(); + CMatCallQueue *pCallQueue = MaterialSystem()->GetRenderCallQueue(); + if ( !m_bFakeMaterialVar && pCallQueue ) + { + // FIXME (toml): deal with reference count + CMaterialVar *pThreadVar = AllocThreadVar(); + if ( pThreadVar ) + { + pThreadVar->SetMaterialValue( pMaterial ); + } + pCallQueue->QueueCall( this, &CMaterialVar::SetMaterialValue, pMaterial ); + return; + } + + //HACKHACK: Only use the realtime material as the material value since converting it every time it's loaded could be forgotten, and chance of game code usage is low + if( pMaterial ) + pMaterial = ((IMaterialInternal *)pMaterial)->GetRealTimeVersion(); + + IMaterialInternal* pMaterialImp = static_cast( pMaterial ); + + // Suppress all this if we're not actually changing anything + if ((m_Type == MATERIAL_VAR_TYPE_MATERIAL) && (m_pMaterialValue == pMaterialImp)) + return; + + // Gotta flush if we've changed state and this is the current material + if ( !m_bFakeMaterialVar && m_pMaterial && (m_pMaterial == MaterialSystem()->GetCurrentMaterial())) + { + g_pShaderAPI->FlushBufferedPrimitives(); + } + + if( pMaterialImp != NULL ) + { + pMaterialImp->IncrementReferenceCount(); + } + + CleanUpData(); + m_pMaterialValue = pMaterialImp; + m_Type = MATERIAL_VAR_TYPE_MATERIAL; + m_intVal = 0; + m_VecVal.Init(); + VarChanged(); +} + + +//----------------------------------------------------------------------------- +// Vector +//----------------------------------------------------------------------------- +void CMaterialVar::GetLinearVecValue( float *pVal, int numComps ) const +{ + CMatCallQueue *pCallQueue = MaterialSystem()->GetRenderCallQueue(); + if ( pCallQueue && !m_bFakeMaterialVar ) + { + if ( !s_bEnableThreadedAccess ) + { + //DevMsg( 2, "Non-thread safe call to CMaterialVar %s!\n", GetName() ); + } + + if ( m_nTempIndex != 0xFF ) + return s_pTempMaterialVar[m_nTempIndex].GetLinearVecValue( pVal, numComps ); + } + + Assert( numComps <= 4 ); + + switch( m_Type ) + { + case MATERIAL_VAR_TYPE_VECTOR: + { + for ( int i = 0; i < numComps; ++i ) + { + pVal[i] = GammaToLinear( m_VecVal[i] ); + } + } + break; + + case MATERIAL_VAR_TYPE_INT: + { + for ( int i = 0; i < numComps; ++i ) + { + pVal[i] = GammaToLinear( m_intVal ); + } + } + break; + + case MATERIAL_VAR_TYPE_FLOAT: + { + for ( int i = 0; i < numComps; ++i ) + { + pVal[i] = GammaToLinear( m_VecVal[0] ); + } + } + break; + + case MATERIAL_VAR_TYPE_MATRIX: + case MATERIAL_VAR_TYPE_UNDEFINED: + { + for ( int i = 0; i < numComps; ++i ) + { + pVal[i] = 0.0f; + } + } + break; + + default: + Warning( "CMaterialVar::GetVecValue: trying to get a vec value for %s which is of type %d\n", + GetName(), ( int )m_Type ); + break; + } +} + +void CMaterialVar::SetVecValueInternal( const Vector4D &vec, int nComps ) +{ + ASSERT_NOT_DUMMY_VAR(); + CMatCallQueue *pCallQueue = MaterialSystem()->GetRenderCallQueue(); + if ( !m_bFakeMaterialVar && pCallQueue ) + { + CMaterialVar *pThreadVar = AllocThreadVar(); + if ( pThreadVar ) + { + pThreadVar->SetVecValueInternal( vec, nComps ); + } + pCallQueue->QueueCall( this, &CMaterialVar::SetVecValueInternal, RefToVal( vec ), nComps ); + return; + } + // Suppress all this if we're not actually changing anything + if ((m_Type == MATERIAL_VAR_TYPE_VECTOR ) && (m_VecVal == vec ) ) + return; + // Gotta flush if we've changed state and this is the current material + if ( !m_bFakeMaterialVar && m_pMaterial && (m_pMaterial == MaterialSystem()->GetCurrentMaterial())) + g_pShaderAPI->FlushBufferedPrimitives(); + + if ( m_Type != MATERIAL_VAR_TYPE_VECTOR ) + { + CleanUpData(); + m_Type = MATERIAL_VAR_TYPE_VECTOR; + } + Assert( nComps <= 4 ); + m_nNumVectorComps = nComps; + memcpy( m_VecVal.Base(), vec.Base(), 4 * sizeof(float) ); + m_intVal = ( int ) m_VecVal[0]; + +#ifdef _DEBUG + for (int i = m_nNumVectorComps; i < 4; ++i ) + Assert( m_VecVal[i] == 0.0f ); +#endif + VarChanged(); +} + +void CMaterialVar::SetVecValue( const float* pVal, int numComps ) +{ + Vector4D vec; + memcpy( vec.Base(), pVal, numComps * sizeof(float) ); + for (int i = numComps; i < 4; ++i ) + { + vec[i] = 0.0f; + } + SetVecValueInternal( vec, numComps); +} + +void CMaterialVar::SetVecValue( float x, float y ) +{ + SetVecValueInternal( Vector4D( x, y, 0.0f, 0.0f ), 2 ); +} + +void CMaterialVar::SetVecValue( float x, float y, float z ) +{ + SetVecValueInternal( Vector4D( x, y, z, 0.0f ), 3 ); +} + +void CMaterialVar::SetVecValue( float x, float y, float z, float w ) +{ + SetVecValueInternal( Vector4D( x, y, z, w ), 4 ); +} + + +void CMaterialVar::SetVecComponentValue( float fVal, int nComponent ) +{ + ASSERT_NOT_DUMMY_VAR(); + +#ifndef _CERT + // DIAF + if ( nComponent < 0 || nComponent > 3 ) + { + Error( "Invalid vector component (%d) of variable %s referenced in material %s", nComponent, GetName(), GetOwningMaterial()->GetName() ); + return; + } +#endif + + CMatCallQueue *pCallQueue = MaterialSystem()->GetRenderCallQueue(); + if ( !m_bFakeMaterialVar && pCallQueue ) + { + if ( s_bEnableThreadedAccess ) + { + bool bInit = ( m_nTempIndex == 0xFF ) ? true : false; + CMaterialVar *pThreadVar = AllocThreadVar(); + if ( pThreadVar ) + { + if ( bInit ) + { + pThreadVar->SetVecValue( m_VecVal.Base(), m_nNumVectorComps ); + } + pThreadVar->SetVecComponentValue( fVal, nComponent ); + } + } + pCallQueue->QueueCall( this, &CMaterialVar::SetVecComponentValue, fVal, nComponent ); + return; + } + + // Suppress all this if we're not actually changing anything + if ((m_Type == MATERIAL_VAR_TYPE_VECTOR ) && (m_VecVal[nComponent] == fVal ) ) + return; + + // Gotta flush if we've changed state and this is the current material + if ( !m_bFakeMaterialVar && m_pMaterial && (m_pMaterial == MaterialSystem()->GetCurrentMaterial())) + g_pShaderAPI->FlushBufferedPrimitives(); + + if ( m_Type != MATERIAL_VAR_TYPE_VECTOR ) + { + CleanUpData(); + m_Type = MATERIAL_VAR_TYPE_VECTOR; + } + Assert( nComponent <= 3 ); + + if( m_nNumVectorComps < nComponent ) + { + //reset all undefined components to 0 + for( int i = m_nNumVectorComps; i != nComponent; ++i ) + m_VecVal[i] = 0.0f; + + m_nNumVectorComps = nComponent; + } + + m_VecVal[nComponent] = fVal; + +#ifdef _DEBUG + for (int i = m_nNumVectorComps; i < 4; ++i ) + Assert( m_VecVal[i] == 0.0f ); +#endif + VarChanged(); +} + + +//----------------------------------------------------------------------------- +// Matrix +//----------------------------------------------------------------------------- +VMatrix const& CMaterialVar::GetMatrixValue( ) +{ + CMatCallQueue *pCallQueue = MaterialSystem()->GetRenderCallQueue(); + if ( pCallQueue && !m_bFakeMaterialVar ) + { + if ( !s_bEnableThreadedAccess ) + { + //DevMsg( 2, "Non-thread safe call to CMaterialVar %s!\n", GetName() ); + } + + if ( m_nTempIndex != 0xFF ) + return s_pTempMaterialVar[m_nTempIndex].GetMatrixValue(); + } + + if (m_Type == MATERIAL_VAR_TYPE_MATRIX) + return m_pMatrix->m_Matrix; + + static VMatrix identity( 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ); + return identity; +} + +void CMaterialVar::SetMatrixValue( VMatrix const& matrix ) +{ + ASSERT_NOT_DUMMY_VAR(); + CMatCallQueue *pCallQueue = MaterialSystem()->GetRenderCallQueue(); + if ( !m_bFakeMaterialVar && pCallQueue ) + { + CMaterialVar *pThreadVar = AllocThreadVar(); + if ( pThreadVar ) + { + pThreadVar->SetMatrixValue( matrix ); + } + pCallQueue->QueueCall( this, &CMaterialVar::SetMatrixValue, RefToVal( matrix ) ); + return; + } + + // Gotta flush if we've changed state and this is the current material + if ( !m_bFakeMaterialVar && m_pMaterial && (m_pMaterial == MaterialSystem()->GetCurrentMaterial())) + g_pShaderAPI->FlushBufferedPrimitives(); + + CleanUpData(); + + // NOTE: This is necessary because the mempool MaterialVarMatrix_t uses is not threadsafe + m_pMatrix = new MaterialVarMatrix_t; + + MatrixCopy( matrix, m_pMatrix->m_Matrix ); + m_Type = MATERIAL_VAR_TYPE_MATRIX; + m_pMatrix->m_bIsIdent = matrix.IsIdentity(); + m_VecVal.Init(); + m_intVal = ( int ) m_VecVal[0]; + VarChanged(); +} + +bool CMaterialVar::MatrixIsIdentity( void ) const +{ + if( m_Type != MATERIAL_VAR_TYPE_MATRIX ) + { + return true; + } + return m_pMatrix->m_bIsIdent; +} + +//----------------------------------------------------------------------------- +// Undefined +//----------------------------------------------------------------------------- +bool CMaterialVar::IsDefined() const +{ + return m_Type != MATERIAL_VAR_TYPE_UNDEFINED; +} + +void CMaterialVar::SetUndefined() +{ + ASSERT_NOT_DUMMY_VAR(); + CMatCallQueue *pCallQueue = MaterialSystem()->GetRenderCallQueue(); + if ( !m_bFakeMaterialVar && pCallQueue ) + { + CMaterialVar *pThreadVar = AllocThreadVar(); + if ( pThreadVar ) + { + pThreadVar->SetUndefined( ); + } + pCallQueue->QueueCall( this, &CMaterialVar::SetUndefined ); + return; + } + + if (m_Type == MATERIAL_VAR_TYPE_UNDEFINED) + return; + + // Gotta flush if we've changed state and this is the current material + if ( !m_bFakeMaterialVar && m_pMaterial && (m_pMaterial == MaterialSystem()->GetCurrentMaterial())) + g_pShaderAPI->FlushBufferedPrimitives(); + + CleanUpData(); + m_Type = MATERIAL_VAR_TYPE_UNDEFINED; + VarChanged(); +} + + +//----------------------------------------------------------------------------- +// Copy from another material var +//----------------------------------------------------------------------------- +void CMaterialVar::CopyFrom( IMaterialVar *pMaterialVar ) +{ + CMatCallQueue *pCallQueue = MaterialSystem()->GetRenderCallQueue(); + if ( !m_bFakeMaterialVar && pCallQueue ) + { + CMaterialVar *pThreadVar = AllocThreadVar(); + if ( pThreadVar ) + { + pThreadVar->CopyFrom( pMaterialVar ); + } + pCallQueue->QueueCall( this, &CMaterialVar::CopyFrom, pMaterialVar ); + return; + } + + switch( pMaterialVar->GetType() ) + { + case MATERIAL_VAR_TYPE_FLOAT: + SetFloatValue( pMaterialVar->GetFloatValue() ); + break; + + case MATERIAL_VAR_TYPE_STRING: + SetStringValue( pMaterialVar->GetStringValue() ); + break; + + case MATERIAL_VAR_TYPE_VECTOR: + SetVecValue( pMaterialVar->GetVecValue(), pMaterialVar->VectorSize() ); + break; + + case MATERIAL_VAR_TYPE_TEXTURE: + SetTextureValue( pMaterialVar->GetTextureValue() ); + break; + + case MATERIAL_VAR_TYPE_INT: + SetIntValue( pMaterialVar->GetIntValue() ); + break; + + case MATERIAL_VAR_TYPE_FOURCC: + { + FourCC fourCC; + void *pData; + pMaterialVar->GetFourCCValue( &fourCC, &pData ); + SetFourCCValue( fourCC, pData ); + } + break; + + case MATERIAL_VAR_TYPE_UNDEFINED: + SetUndefined(); + break; + + case MATERIAL_VAR_TYPE_MATRIX: + SetMatrixValue( pMaterialVar->GetMatrixValue() ); + break; + + case MATERIAL_VAR_TYPE_MATERIAL: + SetMaterialValue( pMaterialVar->GetMaterialValue() ); + break; + + default: + Assert(0); + } +} + +//----------------------------------------------------------------------------- +// Parser utilities +//----------------------------------------------------------------------------- +static inline bool IsWhitespace( char c ) +{ + return c == ' ' || c == '\t'; +} + +static inline bool IsEndline( char c ) +{ + return c == '\n' || c == '\0'; +} + +static inline bool IsVector( const char* v ) +{ + while (IsWhitespace(*v)) + { + ++v; + if (IsEndline(*v)) + return false; + } + return *v == '[' || *v == '{'; +} + +//----------------------------------------------------------------------------- +// Creates a vector material var +//----------------------------------------------------------------------------- +static int ParseVectorFromKeyValueString( const char *pString, float vecVal[4] ) +{ + const char* pScan = pString; + bool divideBy255 = false; + + // skip whitespace + while( IsWhitespace(*pScan) ) + { + ++pScan; + } + + if( *pScan == '{' ) + { + divideBy255 = true; + } + else + { + Assert( *pScan == '[' ); + } + + // skip the '[' + ++pScan; + int i; + for( i = 0; i < 4; i++ ) + { + // skip whitespace + while( IsWhitespace(*pScan) ) + { + ++pScan; + } + + if( IsEndline(*pScan) || *pScan == ']' || *pScan == '}' ) + { + if (*pScan != ']' && *pScan != '}') + { + Warning( "no ']' or '}' found in vector key in ParseVectorFromKeyValueString\n" ); + } + + // allow for vec2's, etc. + vecVal[i] = 0.0f; + break; + } + + char* pEnd; + + vecVal[i] = strtod( pScan, &pEnd ); + if (pScan == pEnd) + { + Warning( "error parsing vector element in ParseVectorFromKeyValueString\n" ); + return 0; + } + + pScan = pEnd; + } + + if( divideBy255 ) + { + vecVal[0] *= ( 1.0f / 255.0f ); + vecVal[1] *= ( 1.0f / 255.0f ); + vecVal[2] *= ( 1.0f / 255.0f ); + vecVal[3] *= ( 1.0f / 255.0f ); + } + + return i; +} + +void CMaterialVar::SetValueAutodetectType( const char *val ) +{ + ASSERT_NOT_DUMMY_VAR(); + int len = Q_strlen( val ); + + // Here, let's determine if we got a float or an int.... + char* pIEnd; // pos where int scan ended + char* pFEnd; // pos where float scan ended + const char* pSEnd = val + len ; // pos where token ends + + int ival = strtol( val, &pIEnd, 10 ); + float fval = (float)strtod( val, &pFEnd ); + + if ( ( pFEnd > pIEnd ) && ( pFEnd == pSEnd ) ) + { + SetFloatValue( fval ); + return; + } + + if ( pIEnd == pSEnd ) + { + SetIntValue( ival ); + return; + } + + // Isn't an int or a float. + + // Is it a matrix? + + VMatrix mat; + int count = sscanf( val, " [ %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f ]", + &mat.m[0][0], &mat.m[0][1], &mat.m[0][2], &mat.m[0][3], + &mat.m[1][0], &mat.m[1][1], &mat.m[1][2], &mat.m[1][3], + &mat.m[2][0], &mat.m[2][1], &mat.m[2][2], &mat.m[2][3], + &mat.m[3][0], &mat.m[3][1], &mat.m[3][2], &mat.m[3][3] ); + if (count == 16) + { + SetMatrixValue( mat ); + return; + } + + Vector2D scale, center; + float angle; + Vector2D translation; + count = sscanf( val, " center %f %f scale %f %f rotate %f translate %f %f", + ¢er.x, ¢er.y, &scale.x, &scale.y, &angle, &translation.x, &translation.y ); + if (count == 7) + { + VMatrix temp; + MatrixBuildTranslation( mat, -center.x, -center.y, 0.0f ); + MatrixBuildScale( temp, scale.x, scale.y, 1.0f ); + MatrixMultiply( temp, mat, mat ); + MatrixBuildRotateZ( temp, angle ); + MatrixMultiply( temp, mat, mat ); + MatrixBuildTranslation( temp, center.x + translation.x, center.y + translation.y, 0.0f ); + MatrixMultiply( temp, mat, mat ); + SetMatrixValue( mat ); + return; + } + + if( IsVector( val ) ) + { + float vecVal[4]; + int nDim = ParseVectorFromKeyValueString( val, vecVal ); + if ( nDim > 0 ) + { + SetVecValue( vecVal, nDim ); + return; + } + } + + SetStringValue( val ); +} diff --git a/materialsystem/cmatlightmaps.cpp b/materialsystem/cmatlightmaps.cpp new file mode 100644 index 0000000..fe2df86 --- /dev/null +++ b/materialsystem/cmatlightmaps.cpp @@ -0,0 +1,2191 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//============================================================================= + +#include "pch_materialsystem.h" + +#define MATSYS_INTERNAL + +#include "cmatlightmaps.h" + +#include "colorspace.h" +#include "IHardwareConfigInternal.h" + +#include "cmaterialsystem.h" + +// NOTE: This must be the last file included!!! +#include "tier0/memdbgon.h" +#include "bitmap/float_bm.h" + +static ConVar mat_lightmap_pfms( "mat_lightmap_pfms", "0", FCVAR_MATERIAL_SYSTEM_THREAD, "Outputs .pfm files containing lightmap data for each lightmap page when a level exits." ); // Write PFM files for each lightmap page in the game directory when exiting a level + +#define USE_32BIT_LIGHTMAPS_ON_360 //uncomment to use 32bit lightmaps, be sure to keep this in sync with the same #define in stdshaders/lightmappedgeneric_ps2_3_x.h + +#ifdef _X360 +#define X360_USE_SIMD_LIGHTMAP +#endif + +//----------------------------------------------------------------------------- + +inline IMaterialInternal* CMatLightmaps::GetCurrentMaterialInternal() const +{ + return GetMaterialSystem()->GetRenderContextInternal()->GetCurrentMaterialInternal(); +} + +inline void CMatLightmaps::SetCurrentMaterialInternal(IMaterialInternal* pCurrentMaterial) +{ + return GetMaterialSystem()->GetRenderContextInternal()->SetCurrentMaterialInternal( pCurrentMaterial ); +} + +inline IMaterialInternal *CMatLightmaps::GetMaterialInternal( MaterialHandle_t idx ) const +{ + return GetMaterialSystem()->GetMaterialInternal( idx ); +} + +inline const IMatRenderContextInternal *CMatLightmaps::GetRenderContextInternal() const +{ + return GetMaterialSystem()->GetRenderContextInternal(); +} + +inline IMatRenderContextInternal *CMatLightmaps::GetRenderContextInternal() +{ + return GetMaterialSystem()->GetRenderContextInternal(); +} + +inline const CMaterialDict *CMatLightmaps::GetMaterialDict() const +{ + return GetMaterialSystem()->GetMaterialDict(); +} + +inline CMaterialDict *CMatLightmaps::GetMaterialDict() +{ + return GetMaterialSystem()->GetMaterialDict(); +} + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +CMatLightmaps::CMatLightmaps() +{ + m_currentWhiteLightmapMaterial = NULL; + m_pLightmapPages = NULL; + m_NumLightmapPages = 0; + m_numSortIDs = 0; + m_nUpdatingLightmapsStackDepth = 0; + m_nLockedLightmap = -1; + m_pLightmapDataPtrArray = NULL; + m_eLightmapsState = STATE_DEFAULT; +} + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +void CMatLightmaps::Shutdown( ) +{ + // Clean up all lightmaps + CleanupLightmaps(); +} + +//----------------------------------------------------------------------------- +// Assign enumeration IDs to all materials +//----------------------------------------------------------------------------- +void CMatLightmaps::EnumerateMaterials( void ) +{ + // iterate in sorted order + int id = 0; + for (MaterialHandle_t i = GetMaterialDict()->FirstMaterial(); i != GetMaterialDict()->InvalidMaterial(); i = GetMaterialDict()->NextMaterial(i) ) + { + GetMaterialInternal(i)->SetEnumerationID( id ); + ++id; + } +} + + +//----------------------------------------------------------------------------- +// Gets the maximum lightmap page size... +//----------------------------------------------------------------------------- +int CMatLightmaps::GetMaxLightmapPageWidth() const +{ + // FIXME: It's unclear which we want here. + // It doesn't drastically increase primitives per DrawIndexedPrimitive + // call at the moment to increase it, so let's not for now. + + // If we're using dynamic textures though, we want bigger that's for sure. + // The tradeoff here is how much memory we waste if we don't fill the lightmap + + // We need to go to 512x256 textures because that's the only way bumped + // lighting on displacements can work given the 128x128 allowance.. + int nWidth = 512; + if ( nWidth > HardwareConfig()->MaxTextureWidth() ) + nWidth = HardwareConfig()->MaxTextureWidth(); + + return nWidth; +} + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +int CMatLightmaps::GetMaxLightmapPageHeight() const +{ + int nHeight = 256; + + if ( nHeight > HardwareConfig()->MaxTextureHeight() ) + nHeight = HardwareConfig()->MaxTextureHeight(); + + return nHeight; +} + + +//----------------------------------------------------------------------------- +// Returns the lightmap page size +//----------------------------------------------------------------------------- +void CMatLightmaps::GetLightmapPageSize( int lightmapPageID, int *pWidth, int *pHeight ) const +{ + switch( lightmapPageID ) + { + default: + Assert( lightmapPageID >= 0 && lightmapPageID < GetNumLightmapPages() ); + *pWidth = m_pLightmapPages[lightmapPageID].m_Width; + *pHeight = m_pLightmapPages[lightmapPageID].m_Height; + break; + + case MATERIAL_SYSTEM_LIGHTMAP_PAGE_USER_DEFINED: + *pWidth = *pHeight = 1; + AssertOnce( !"Can't use CMatLightmaps to get properties of MATERIAL_SYSTEM_LIGHTMAP_PAGE_USER_DEFINED" ); + break; + + case MATERIAL_SYSTEM_LIGHTMAP_PAGE_WHITE: + case MATERIAL_SYSTEM_LIGHTMAP_PAGE_WHITE_BUMP: + *pWidth = *pHeight = 1; + break; + } +} + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +int CMatLightmaps::GetLightmapWidth( int lightmapPageID ) const +{ + switch( lightmapPageID ) + { + default: + Assert( lightmapPageID >= 0 && lightmapPageID < GetNumLightmapPages() ); + return m_pLightmapPages[lightmapPageID].m_Width; + + case MATERIAL_SYSTEM_LIGHTMAP_PAGE_USER_DEFINED: + AssertOnce( !"Can't use CMatLightmaps to get properties of MATERIAL_SYSTEM_LIGHTMAP_PAGE_USER_DEFINED" ); + return 1; + + case MATERIAL_SYSTEM_LIGHTMAP_PAGE_WHITE: + case MATERIAL_SYSTEM_LIGHTMAP_PAGE_WHITE_BUMP: + return 1; + } +} + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +int CMatLightmaps::GetLightmapHeight( int lightmapPageID ) const +{ + switch( lightmapPageID ) + { + default: + Assert( lightmapPageID >= 0 && lightmapPageID < GetNumLightmapPages() ); + return m_pLightmapPages[lightmapPageID].m_Height; + + case MATERIAL_SYSTEM_LIGHTMAP_PAGE_USER_DEFINED: + AssertOnce( !"Can't use CMatLightmaps to get properties of MATERIAL_SYSTEM_LIGHTMAP_PAGE_USER_DEFINED" ); + return 1; + + case MATERIAL_SYSTEM_LIGHTMAP_PAGE_WHITE: + case MATERIAL_SYSTEM_LIGHTMAP_PAGE_WHITE_BUMP: + return 1; + } +} + + +//----------------------------------------------------------------------------- +// Clean up lightmap pages. +//----------------------------------------------------------------------------- +void CMatLightmaps::CleanupLightmaps() +{ + if ( mat_lightmap_pfms.GetBool()) + { + // Write PFM files containing lightmap data for this page + for (int lightmap = 0; lightmap < GetNumLightmapPages(); lightmap++) + { + if ((NULL != m_pLightmapDataPtrArray) && (NULL != m_pLightmapDataPtrArray[lightmap])) + { + char szPFMFileName[MAX_PATH]; + + sprintf(szPFMFileName, "Lightmap-Page-%d.pfm", lightmap); + m_pLightmapDataPtrArray[lightmap]->WritePFM(szPFMFileName); + } + } + } + + // Remove the lightmap data bitmap representations + if (m_pLightmapDataPtrArray) + { + int i; + for( i = 0; i < GetNumLightmapPages(); i++ ) + { + delete m_pLightmapDataPtrArray[i]; + } + + delete [] m_pLightmapDataPtrArray; + m_pLightmapDataPtrArray = NULL; + } + + // delete old lightmap pages + if( m_pLightmapPages ) + { + int i; + for( i = 0; i < GetNumLightmapPages(); i++ ) + { + g_pShaderAPI->DeleteTexture( m_LightmapPageTextureHandles[i] ); + } + delete [] m_pLightmapPages; + m_pLightmapPages = 0; + } + + m_NumLightmapPages = 0; +} + +//----------------------------------------------------------------------------- +// Resets the lightmap page info for each material +//----------------------------------------------------------------------------- +void CMatLightmaps::ResetMaterialLightmapPageInfo( void ) +{ + for (MaterialHandle_t i = GetMaterialDict()->FirstMaterial(); i != GetMaterialDict()->InvalidMaterial(); i = GetMaterialDict()->NextMaterial(i) ) + { + IMaterialInternal *pMaterial = GetMaterialInternal(i); + pMaterial->SetMinLightmapPageID( 9999 ); + pMaterial->SetMaxLightmapPageID( -9999 ); + pMaterial->SetNeedsWhiteLightmap( false ); + } +} + +//----------------------------------------------------------------------------- +// This is called before any lightmap allocations take place +//----------------------------------------------------------------------------- +void CMatLightmaps::BeginLightmapAllocation() +{ + // delete old lightmap pages + CleanupLightmaps(); + + m_ImagePackers.RemoveAll(); + int i = m_ImagePackers.AddToTail(); + m_ImagePackers[i].Reset( 0, GetMaxLightmapPageWidth(), GetMaxLightmapPageHeight() ); + + SetCurrentMaterialInternal(0); + m_currentWhiteLightmapMaterial = 0; + m_numSortIDs = 0; + + // need to set the min and max sorting id number for each material to + // a default value that basically means that it hasn't been used yet. + ResetMaterialLightmapPageInfo(); + + EnumerateMaterials(); +} + + +//----------------------------------------------------------------------------- +// Allocates space in the lightmaps; must be called after BeginLightmapAllocation +//----------------------------------------------------------------------------- +int CMatLightmaps::AllocateLightmap( int width, int height, + int offsetIntoLightmapPage[2], + IMaterial *iMaterial ) +{ + IMaterialInternal *pMaterial = static_cast( iMaterial ); + if ( !pMaterial ) + { + Warning( "Programming error: CMatRenderContext::AllocateLightmap: NULL material\n" ); + return m_numSortIDs; + } + pMaterial = pMaterial->GetRealTimeVersion(); //always work with the real time versions of materials internally + + // material change + int i; + int nPackCount = m_ImagePackers.Count(); + if ( GetCurrentMaterialInternal() != pMaterial ) + { + // If this happens, then we need to close out all image packers other than + // the last one so as to produce as few sort IDs as possible + for ( i = nPackCount - 1; --i >= 0; ) + { + // NOTE: We *must* use the order preserving one here so the remaining one + // is the last lightmap + m_ImagePackers.Remove( i ); + --nPackCount; + } + + // If it's not the first material, increment the sort id + if (GetCurrentMaterialInternal()) + { + m_ImagePackers[0].IncrementSortId( ); + ++m_numSortIDs; + } + + SetCurrentMaterialInternal(pMaterial); + + // This assertion guarantees we don't see the same material twice in this loop. + Assert( pMaterial->GetMinLightmapPageID( ) > pMaterial->GetMaxLightmapPageID() ); + + // NOTE: We may not use this lightmap page, but we might + // we won't know for sure until the next material is passed in. + // So, for now, we're going to forcibly add the current lightmap + // page to this material so the sort IDs work out correctly. + GetCurrentMaterialInternal()->SetMinLightmapPageID( GetNumLightmapPages() ); + GetCurrentMaterialInternal()->SetMaxLightmapPageID( GetNumLightmapPages() ); + } + + // Try to add it to any of the current images... + bool bAdded = false; + for ( i = 0; i < nPackCount; ++i ) + { + bAdded = m_ImagePackers[i].AddBlock( width, height, &offsetIntoLightmapPage[0], &offsetIntoLightmapPage[1] ); + if ( bAdded ) + break; + } + + if ( !bAdded ) + { + ++m_numSortIDs; + i = m_ImagePackers.AddToTail(); + m_ImagePackers[i].Reset( m_numSortIDs, GetMaxLightmapPageWidth(), GetMaxLightmapPageHeight() ); + ++m_NumLightmapPages; + if ( !m_ImagePackers[i].AddBlock( width, height, &offsetIntoLightmapPage[0], &offsetIntoLightmapPage[1] ) ) + { + Error( "MaterialSystem_Interface_t::AllocateLightmap: lightmap (%dx%d) too big to fit in page (%dx%d)\n", + width, height, GetMaxLightmapPageWidth(), GetMaxLightmapPageHeight() ); + } + + // Add this lightmap to the material... + GetCurrentMaterialInternal()->SetMaxLightmapPageID( GetNumLightmapPages() ); + } + + return m_ImagePackers[i].GetSortId(); +} + +// UNDONE: This needs testing, but it appears as though creating these textures managed +// results in huge stalls whenever they are locked for modify. +// That makes sense given the d3d docs, but these have been flagged as managed for quite some time. +#define DYNAMIC_TEXTURES_NO_BACKING 1 + +void CMatLightmaps::EndLightmapAllocation() +{ + // count the last page that we were on.if it wasn't + // and count the last sortID that we were on + m_NumLightmapPages++; + m_numSortIDs++; + + m_firstDynamicLightmap = m_NumLightmapPages; + // UNDONE: Until we start using the separate dynamic lighting textures don't allocate them + // NOTE: Enable this if we want to stop locking the base lightmaps and instead only lock update + // these completely dynamic pages +// m_NumLightmapPages += COUNT_DYNAMIC_LIGHTMAP_PAGES; + m_dynamic.Init(); + + // Compute the dimensions of the last lightmap + int lastLightmapPageWidth, lastLightmapPageHeight; + int nLastIdx = m_ImagePackers.Count(); + m_ImagePackers[nLastIdx - 1].GetMinimumDimensions( &lastLightmapPageWidth, &lastLightmapPageHeight ); + m_ImagePackers.Purge(); + + m_pLightmapPages = new LightmapPageInfo_t[GetNumLightmapPages()]; + Assert( m_pLightmapPages ); + + if ( mat_lightmap_pfms.GetBool()) + { + // This array will be used to write PFM files full of lightmap data + m_pLightmapDataPtrArray = new FloatBitMap_t*[GetNumLightmapPages()]; + } + + int i; + m_LightmapPageTextureHandles.EnsureCapacity( GetNumLightmapPages() ); + for ( i = 0; i < GetNumLightmapPages(); i++ ) + { + // Compute lightmap dimensions + bool lastStaticLightmap = ( i == (m_firstDynamicLightmap-1)); + m_pLightmapPages[i].m_Width = (unsigned short)(lastStaticLightmap ? lastLightmapPageWidth : GetMaxLightmapPageWidth()); + m_pLightmapPages[i].m_Height = (unsigned short)(lastStaticLightmap ? lastLightmapPageHeight : GetMaxLightmapPageHeight()); + m_pLightmapPages[i].m_Flags = 0; + + AllocateLightmapTexture( i ); + + if ( mat_lightmap_pfms.GetBool()) + { + // Initialize the pointers to lightmap data + m_pLightmapDataPtrArray[i] = NULL; + } + } +} + +//----------------------------------------------------------------------------- +// Allocate lightmap textures +//----------------------------------------------------------------------------- +void CMatLightmaps::AllocateLightmapTexture( int lightmap ) +{ + bool bUseDynamicTextures = HardwareConfig()->PreferDynamicTextures(); + + int flags = bUseDynamicTextures ? TEXTURE_CREATE_DYNAMIC : TEXTURE_CREATE_MANAGED; + + m_LightmapPageTextureHandles.EnsureCount( lightmap + 1 ); + + char debugName[256]; + Q_snprintf( debugName, sizeof( debugName ), "[lightmap %d]", lightmap ); + + ImageFormat imageFormat; + switch ( HardwareConfig()->GetHDRType() ) + { + default: + Assert( 0 ); + // fall through. + + case HDR_TYPE_NONE: +#if !defined( _X360 ) + imageFormat = IMAGE_FORMAT_RGBA8888; + flags |= TEXTURE_CREATE_SRGB; +#else + imageFormat = IMAGE_FORMAT_LINEAR_RGBA8888; +#endif + break; + + case HDR_TYPE_INTEGER: +#if !defined( _X360 ) + imageFormat = IMAGE_FORMAT_RGBA16161616; +#else +# if ( defined( USE_32BIT_LIGHTMAPS_ON_360 ) ) + imageFormat = IMAGE_FORMAT_LINEAR_RGBA8888; +# else + imageFormat = IMAGE_FORMAT_LINEAR_RGBA16161616; +# endif +#endif + break; + + case HDR_TYPE_FLOAT: + imageFormat = IMAGE_FORMAT_RGBA16161616F; + break; + } + + switch ( m_eLightmapsState ) + { + case STATE_DEFAULT: + // Allow allocations in default state + { + m_LightmapPageTextureHandles[lightmap] = g_pShaderAPI->CreateTexture( + GetLightmapWidth(lightmap), GetLightmapHeight(lightmap), 1, + imageFormat, + 1, 1, flags, debugName, TEXTURE_GROUP_LIGHTMAP ); // don't mipmap lightmaps + + // Load up the texture data + g_pShaderAPI->ModifyTexture( m_LightmapPageTextureHandles[lightmap] ); + g_pShaderAPI->TexMinFilter( SHADER_TEXFILTERMODE_LINEAR ); + g_pShaderAPI->TexMagFilter( SHADER_TEXFILTERMODE_LINEAR ); + + if ( !bUseDynamicTextures ) + { + g_pShaderAPI->TexSetPriority( 1 ); + } + + // Blat out the lightmap bits + InitLightmapBits( lightmap ); + } + break; + + case STATE_RELEASED: + // Not assigned m_LightmapPageTextureHandles[lightmap]; + DevMsg( "AllocateLightmapTexture(%d) in released lightmap state (STATE_RELEASED), delayed till \"Restore\".\n", lightmap ); + return; + + default: + // Not assigned m_LightmapPageTextureHandles[lightmap]; + Warning( "AllocateLightmapTexture(%d) in unknown lightmap state (%d), skipped.\n", lightmap, m_eLightmapsState ); + Assert( !"AllocateLightmapTexture(?) in unknown lightmap state (?)" ); + return; + } +} + + +int CMatLightmaps::AllocateWhiteLightmap( IMaterial *iMaterial ) +{ + IMaterialInternal *pMaterial = static_cast( iMaterial ); + if( !pMaterial ) + { + Warning( "Programming error: CMatRenderContext::AllocateWhiteLightmap: NULL material\n" ); + return m_numSortIDs; + } + pMaterial = pMaterial->GetRealTimeVersion(); //always work with the real time versions of materials internally + + if ( !m_currentWhiteLightmapMaterial || ( m_currentWhiteLightmapMaterial != pMaterial ) ) + { + if ( !GetCurrentMaterialInternal() && !m_currentWhiteLightmapMaterial ) + { + // don't increment if this is the very first material (ie. no lightmaps + // allocated with AllocateLightmap + // Assert( 0 ); + } + else + { + // material change + m_numSortIDs++; +#if 0 + char buf[128]; + Q_snprintf( buf, sizeof( buf ), "AllocateWhiteLightmap: m_numSortIDs = %d %s\n", m_numSortIDs, pMaterial->GetName() ); + OutputDebugString( buf ); +#endif + } +// Warning( "%d material: \"%s\" lightmapPageID: -1\n", m_numSortIDs, pMaterial->GetName() ); + m_currentWhiteLightmapMaterial = pMaterial; + pMaterial->SetNeedsWhiteLightmap( true ); + } + + return m_numSortIDs; +} + +//----------------------------------------------------------------------------- +// Releases/restores lightmap pages +//----------------------------------------------------------------------------- +void CMatLightmaps::ReleaseLightmapPages() +{ + switch ( m_eLightmapsState ) + { + case STATE_DEFAULT: + // Allow release in default state only + break; + + default: + Warning( "ReleaseLightmapPages is expected in STATE_DEFAULT, current state = %d, discarded.\n", m_eLightmapsState ); + Assert( !"ReleaseLightmapPages is expected in STATE_DEFAULT" ); + return; + } + + for( int i = 0; i < GetNumLightmapPages(); i++ ) + { + g_pShaderAPI->DeleteTexture( m_LightmapPageTextureHandles[i] ); + } + + // We are now in released state + m_eLightmapsState = STATE_RELEASED; +} + +void CMatLightmaps::RestoreLightmapPages() +{ + switch ( m_eLightmapsState ) + { + case STATE_RELEASED: + // Allow restore in released state only + break; + + default: + Warning( "RestoreLightmapPages is expected in STATE_RELEASED, current state = %d, discarded.\n", m_eLightmapsState ); + Assert( !"RestoreLightmapPages is expected in STATE_RELEASED" ); + return; + } + + // Switch to default state to allow allocations + m_eLightmapsState = STATE_DEFAULT; + + for( int i = 0; i < GetNumLightmapPages(); i++ ) + { + AllocateLightmapTexture( i ); + } +} + + +//----------------------------------------------------------------------------- +// This initializes the lightmap bits +//----------------------------------------------------------------------------- +void CMatLightmaps::InitLightmapBits( int lightmap ) +{ + VPROF_( "CMatLightmaps::InitLightmapBits", 1, VPROF_BUDGETGROUP_DLIGHT_RENDERING, false, 0 ); + int width = GetLightmapWidth(lightmap); + int height = GetLightmapHeight(lightmap); + + CPixelWriter writer; + + g_pShaderAPI->ModifyTexture( m_LightmapPageTextureHandles[lightmap] ); + if ( !g_pShaderAPI->TexLock( 0, 0, 0, 0, width, height, writer ) ) + return; + + // Debug mode, make em green checkerboard + if ( writer.IsUsingFloatFormat() ) + { + for ( int j = 0; j < height; ++j ) + { + writer.Seek( 0, j ); + for ( int k = 0; k < width; ++k ) + { +#ifndef _DEBUG + writer.WritePixel( 1.0f, 1.0f, 1.0f ); +#else // _DEBUG + if( ( j + k ) & 1 ) + { + writer.WritePixelF( 0.0f, 1.0f, 0.0f ); + } + else + { + writer.WritePixelF( 0.0f, 0.0f, 0.0f ); + } +#endif // _DEBUG + } + } + } + else + { + for ( int j = 0; j < height; ++j ) + { + writer.Seek( 0, j ); + for ( int k = 0; k < width; ++k ) + { +#ifndef _DEBUG + // note: make this white to find multisample centroid sampling problems. + // writer.WritePixel( 255, 255, 255 ); + writer.WritePixel( 0, 0, 0 ); +#else // _DEBUG + if ( ( j + k ) & 1 ) + { + writer.WritePixel( 0, 255, 0 ); + } + else + { + writer.WritePixel( 0, 0, 0 ); + } +#endif // _DEBUG + } + } + } + + g_pShaderAPI->TexUnlock(); +} + +bool CMatLightmaps::LockLightmap( int lightmap ) +{ +// Warning( "locking lightmap page: %d\n", lightmap ); + VPROF_INCREMENT_COUNTER( "lightmap fullpage texlock", 1 ); + if( m_nLockedLightmap != -1 ) + { + g_pShaderAPI->TexUnlock(); + } + g_pShaderAPI->ModifyTexture( m_LightmapPageTextureHandles[lightmap] ); + int pageWidth = m_pLightmapPages[lightmap].m_Width; + int pageHeight = m_pLightmapPages[lightmap].m_Height; + if (!g_pShaderAPI->TexLock( 0, 0, 0, 0, pageWidth, pageHeight, m_LightmapPixelWriter )) + { + Assert( 0 ); + return false; + } + m_nLockedLightmap = lightmap; + return true; +} + +Vector4D ConvertLightmapColorToRGBScale( const float *lightmapColor ) +{ + Vector4D result; + + float fScale = lightmapColor[0]; + for( int i = 1; i != 3; ++i ) + { + if( lightmapColor[i] > fScale ) + fScale = lightmapColor[i]; + } + + fScale = ceil( fScale * (255.0f/16.0f) ) * (16.0f/255.0f); + fScale = min( fScale, 16.0f ); + + float fInvScale = 1.0f / fScale; + + for( int i = 0; i != 3; ++i ) + { + result[i] = lightmapColor[i] * fInvScale; + result[i] = ceil( result[i] * 255.0f ) * (1.0f/255.0f); + result[i] = min( result[i], 1.0f ); + } + + fScale /= 16.0f; + + result.w = fScale; + + return result; +} + +#ifdef _X360 +// SIMD version of above +// input numbers from pSrc are on the domain [0..16] +// output is RGBA +// ignores contents of w channel of input +// the shader does this: rOut = Rin * Ain * 16.0f +// where Rin is [0..1], a float computed from a byte value [0..255] +// Ain is therefore the brightest channel (say R) divided by 16 and quantized +// Rin is computed from pSrc->r by dividing by Ain +// this outputs RGBa where RGB are [0..255] and a is the shader's scaling factor (also 0..255) +// +// WARNING - this code appears to be vulnerable to a compiler bug. Be very careful modifying and be +// sure to test +fltx4 ConvertLightmapColorToRGBScale( FLTX4 lightmapColor ) +{ + + static const fltx4 vTwoFiftyFive = {255.0f, 255.0f, 255.0f, 255.0f}; + static const fltx4 FourPoint1s = { 0.1, 0.1, 0.1, 0.1 }; + static const fltx4 vTwoFiftyFiveOverSixteen = {255.0f / 16.0f, 255.0f / 16.0f, 255.0f / 16.0f, 255.0f / 16.0f}; + // static const fltx4 vSixteenOverTwoFiftyFive = { 16.0f / 255.0f, 16.0f / 255.0f, 16.0f / 255.0f, 16.0f / 255.0f }; + + + // find the highest color value in lightmapColor and replicate it + fltx4 scale = FindHighestSIMD3( lightmapColor ); + fltx4 minscale = FindLowestSIMD3( lightmapColor ); + fltx4 fl4OutofRange = OrSIMD( CmpGeSIMD( scale, Four_Ones ), CmpLeSIMD( scale, FourPoint1s ) ); + fl4OutofRange = OrSIMD( fl4OutofRange, CmpGtSIMD( minscale, MulSIMD( Four_PointFives, scale ) ) ); + + // scale needs to be divided by 16 (because the shader multiplies it by 16) + // then mapped to 0..255 and quantized. + scale = __vrfip(MulSIMD(scale, vTwoFiftyFiveOverSixteen)); // scale = ceil(scale * 255/16) + + fltx4 result = MulSIMD(vTwoFiftyFive, lightmapColor); // start the scale cooking on the final result + + fltx4 invScale = ReciprocalEstSIMD(scale); // invScale = (16/255)(1/scale). may be +inf + invScale = MulSIMD(invScale, vTwoFiftyFiveOverSixteen); // take the quantizing factor back out + // of the inverse scale (one less + // dependent op if you do it this way) + + // scale the input channels + // compute so the numbers are all 0..255 ints. (if one happens to + // be 256 due to numerical error in the reciprocation, the unsigned-saturate + // store we'll use later on will bake it back down to 255) + result = MulSIMD(result, invScale); + + // now, output -- + // if the input color was nonzero, slip the scale into return value's w + // component and return. If the input was zero, return zero. + + result = MaskedAssign( + fl4OutofRange, + SetWSIMD( result, scale ), + SetWSIMD( MulSIMD( lightmapColor, vTwoFiftyFive ), vTwoFiftyFiveOverSixteen ) ); + return result; +} +#endif + + +// write bumped lightmap update to LDR 8-bit lightmap +void CMatLightmaps::BumpedLightmapBitsToPixelWriter_LDR( float* pFloatImage, float *pFloatImageBump1, float *pFloatImageBump2, + float *pFloatImageBump3, int pLightmapSize[2], int pOffsetIntoLightmapPage[2], FloatBitMap_t *pfmOut ) +{ + const int nLightmapSize0 = pLightmapSize[0]; + const int nLightmap0WriterSizeBytes = nLightmapSize0 * m_LightmapPixelWriter.GetPixelSize(); + const int nRewindToNextPixel = -( ( nLightmap0WriterSizeBytes * 3 ) - m_LightmapPixelWriter.GetPixelSize() ); + + for( int t = 0; t < pLightmapSize[1]; t++ ) + { + int srcTexelOffset = ( sizeof( Vector4D ) / sizeof( float ) ) * ( 0 + t * nLightmapSize0 ); + m_LightmapPixelWriter.Seek( pOffsetIntoLightmapPage[0], pOffsetIntoLightmapPage[1] + t ); + + for( int s = 0; s < nLightmapSize0; + s++, m_LightmapPixelWriter.SkipBytes(nRewindToNextPixel),srcTexelOffset += (sizeof(Vector4D)/sizeof(float))) + { + unsigned char color[4][3]; + + ColorSpace::LinearToBumpedLightmap( &pFloatImage[srcTexelOffset], + &pFloatImageBump1[srcTexelOffset], &pFloatImageBump2[srcTexelOffset], + &pFloatImageBump3[srcTexelOffset], + color[0], color[1], color[2], color[3] ); + + unsigned char alpha = RoundFloatToByte( pFloatImage[srcTexelOffset+3] * 255.0f ); + m_LightmapPixelWriter.WritePixelNoAdvance( color[0][0], color[0][1], color[0][2], alpha ); + + m_LightmapPixelWriter.SkipBytes( nLightmap0WriterSizeBytes ); + m_LightmapPixelWriter.WritePixelNoAdvance( color[1][0], color[1][1], color[1][2], alpha ); + + m_LightmapPixelWriter.SkipBytes( nLightmap0WriterSizeBytes ); + m_LightmapPixelWriter.WritePixelNoAdvance( color[2][0], color[2][1], color[2][2], alpha ); + + m_LightmapPixelWriter.SkipBytes( nLightmap0WriterSizeBytes ); + m_LightmapPixelWriter.WritePixelNoAdvance( color[3][0], color[3][1], color[3][2], alpha ); + } + } + if ( pfmOut ) + { + for( int t = 0; t < pLightmapSize[1]; t++ ) + { + int srcTexelOffset = ( sizeof( Vector4D ) / sizeof( float ) ) * ( 0 + t * nLightmapSize0 ); + for( int s = 0; s < nLightmapSize0; s++,srcTexelOffset += (sizeof(Vector4D)/sizeof(float))) + { + unsigned char color[4][3]; + + ColorSpace::LinearToBumpedLightmap( &pFloatImage[srcTexelOffset], + &pFloatImageBump1[srcTexelOffset], &pFloatImageBump2[srcTexelOffset], + &pFloatImageBump3[srcTexelOffset], + color[0], color[1], color[2], color[3] ); + + unsigned char alpha = RoundFloatToByte( pFloatImage[srcTexelOffset+3] * 255.0f ); + // Write data to the bitmapped represenations so that PFM files can be written + PixRGBAF pixelData; + pixelData.Red = color[0][0]; + pixelData.Green = color[0][1]; + pixelData.Blue = color[0][2]; + pixelData.Alpha = alpha; + pfmOut->WritePixelRGBAF( pOffsetIntoLightmapPage[0] + s, pOffsetIntoLightmapPage[1] + t, pixelData); + } + } + + } +} + +// write bumped lightmap update to HDR float lightmap +void CMatLightmaps::BumpedLightmapBitsToPixelWriter_HDRF( float* pFloatImage, float *pFloatImageBump1, float *pFloatImageBump2, + float *pFloatImageBump3, int pLightmapSize[2], int pOffsetIntoLightmapPage[2], FloatBitMap_t *pfmOut ) +{ + if ( IsX360() ) + { + // 360 does not support HDR float mode + Assert( 0 ); + return; + } + + Assert( !pfmOut ); // unsupported in this mode + + const int nLightmapSize0 = pLightmapSize[0]; + const int nLightmap0WriterSizeBytes = nLightmapSize0 * m_LightmapPixelWriter.GetPixelSize(); + const int nRewindToNextPixel = -( ( nLightmap0WriterSizeBytes * 3 ) - m_LightmapPixelWriter.GetPixelSize() ); + + for( int t = 0; t < pLightmapSize[1]; t++ ) + { + int srcTexelOffset = ( sizeof( Vector4D ) / sizeof( float ) ) * ( 0 + t * nLightmapSize0 ); + m_LightmapPixelWriter.Seek( pOffsetIntoLightmapPage[0], pOffsetIntoLightmapPage[1] + t ); + + for( int s = 0; + s < nLightmapSize0; + s++, m_LightmapPixelWriter.SkipBytes(nRewindToNextPixel),srcTexelOffset += (sizeof(Vector4D)/sizeof(float))) + { + m_LightmapPixelWriter.WritePixelNoAdvanceF( pFloatImage[srcTexelOffset], pFloatImage[srcTexelOffset+1], + pFloatImage[srcTexelOffset+2], pFloatImage[srcTexelOffset+3] ); + + m_LightmapPixelWriter.SkipBytes( nLightmap0WriterSizeBytes ); + m_LightmapPixelWriter.WritePixelNoAdvanceF( pFloatImageBump1[srcTexelOffset], pFloatImageBump1[srcTexelOffset+1], + pFloatImageBump1[srcTexelOffset+2], pFloatImage[srcTexelOffset+3] ); + + m_LightmapPixelWriter.SkipBytes( nLightmap0WriterSizeBytes ); + m_LightmapPixelWriter.WritePixelNoAdvanceF( pFloatImageBump2[srcTexelOffset], pFloatImageBump2[srcTexelOffset+1], + pFloatImageBump2[srcTexelOffset+2], pFloatImage[srcTexelOffset+3] ); + + m_LightmapPixelWriter.SkipBytes( nLightmap0WriterSizeBytes ); + m_LightmapPixelWriter.WritePixelNoAdvanceF( pFloatImageBump3[srcTexelOffset], pFloatImageBump3[srcTexelOffset+1], + pFloatImageBump3[srcTexelOffset+2], pFloatImage[srcTexelOffset+3] ); + } + } +} + +#ifdef _X360 +#pragma optimize("u", on) +#endif + + +#ifdef _X360 + +namespace { + // pack a pixel into BGRA8888 and return it with the data packed into the w component +FORCEINLINE fltx4 PackPixel_BGRA8888( FLTX4 rgba ) +{ + // this happens to be in an order such that we can use the handy builtin packing op + // clamp to 0..255 (coz it might have leaked over) + static const fltx4 vTwoFiftyFive = {255.0f, 255.0f, 255.0f, 255.0f}; + + // the magic number such that when mul-accummulated against rbga, + // gets us a representation 3.0 + (r)*2^-22 -- puts the bits at + // the bottom of the float + static const XMVECTOR PackScale = { (1.0f / (FLOAT)(1 << 22)), (1.0f / (FLOAT)(1 << 22)), (1.0f / (FLOAT)(1 << 22)), (1.0f / (FLOAT)(1 << 22))}; // 255.0f / (FLOAT)(1 << 22) + static const XMVECTOR Three = {3.0f, 3.0f, 3.0f, 3.0f}; + + fltx4 N = MinSIMD(vTwoFiftyFive, rgba); + + N = __vmaddfp(N, PackScale, Three); + N = __vpkd3d(N, N, VPACK_D3DCOLOR, VPACK_32, 0); // pack into w word + return N; +} + +// A small store-gather buffer used in the +// BumpedLightmapBitsToPixelWriter_HDRI_BGRA_X360(). +// The store-gather buffers. Hopefully these will live in the L1 +// cache, which will make writing to them, then to memory, faster +// than just using __stvewx to write directly into WC memory +// one noncontiguous float at a time. (If there weren't a huge +// compiler bug with __stvewx in the Apr07 XDK, that might not +// be the case.) +struct ALIGN128 CPixelWriterStoreGather +{ + enum { + kRows = 4, + kWordsPerRow = 32, + }; + + ALIGN128 uint32 m_data[kRows][kWordsPerRow]; // four rows of bgra data, aligned to 4 cache lines. dwords so memcpy works better. + int m_wordsGathered; + int m_bytesBetweenWriterRows; // the number of bytes spacing the maps inside the writer from each other + // if we weren't gathering, we'd SkipBytes this many between the base map, bump1, etc. + + // write four rows, as SIMD registers, into the buffers + inline void write( CPixelWriter * RESTRICT pLightmapPixelWriter, FLTX4 row0, FLTX4 row1, FLTX4 row2, FLTX4 row3 ) RESTRICT + { + // if full, commit + Assert(m_wordsGathered <= kWordsPerRow); + AssertMsg((m_wordsGathered & 3) == 0, "Don't call CPixelWriterStoreGather::write after ::writeJustX"); // single-word writes have misaligned me + if (m_wordsGathered >= kWordsPerRow) + { + commitWhenFull(pLightmapPixelWriter); + } + + XMStoreVector4A( &m_data[0][m_wordsGathered], row0 ); + XMStoreVector4A( &m_data[1][m_wordsGathered], row1 ); + XMStoreVector4A( &m_data[2][m_wordsGathered], row2 ); + XMStoreVector4A( &m_data[3][m_wordsGathered], row3 ); + + m_wordsGathered += 4 ; // four words per simd vec + } + + // pluck the w component out of each of the rows, and store it into the gather buffer. Don't + // call the other write function after calling this. + inline void writeJustW( CPixelWriter * RESTRICT pLightmapPixelWriter, FLTX4 row0, FLTX4 row1, FLTX4 row2, FLTX4 row3 ) RESTRICT + { + // if full, commit + Assert(m_wordsGathered <= kWordsPerRow); + if (m_wordsGathered >= kWordsPerRow) + { + commitWhenFull(pLightmapPixelWriter); + } + + // for each fltx4, splat out x and then use the __stvewx to store + // whichever word happens to align with the float pointer through + // that pointer. + + __stvewx(__vspltw(row0, 3), &m_data[0][m_wordsGathered], 0 ); + __stvewx(__vspltw(row1, 3), &m_data[1][m_wordsGathered], 0 ); + __stvewx(__vspltw(row2, 3), &m_data[2][m_wordsGathered], 0 ); + __stvewx(__vspltw(row3, 3), &m_data[3][m_wordsGathered], 0 ); + + m_wordsGathered += 1 ; // only stored one word + } + + // Commit my buffers to the pixelwriter's memory, and advance its + // pointer. + void commit(CPixelWriter * RESTRICT pLightmapPixelWriter) RESTRICT + { + if (m_wordsGathered > 0) + { + unsigned char* RESTRICT pWriteInto = pLightmapPixelWriter->GetCurrentPixel(); + // we have to use memcpy because we're writing to non-cacheable memory, + // but we can't even assume that the addresses we're writing to are + // vector-aligned. +#ifdef memcpy // if someone's overriden the intrinsic, complain +#pragma error("You have overridden memcpy(), which is an XBOX360 intrinsic. This function will not behave optimally.") +#endif + + memcpy(pWriteInto, m_data[0], m_wordsGathered * sizeof(uint32)); + pWriteInto += m_bytesBetweenWriterRows; + memcpy(pWriteInto, m_data[1], m_wordsGathered * sizeof(uint32)); + pWriteInto += m_bytesBetweenWriterRows; + memcpy(pWriteInto, m_data[2], m_wordsGathered * sizeof(uint32)); + pWriteInto += m_bytesBetweenWriterRows; + memcpy(pWriteInto, m_data[3], m_wordsGathered * sizeof(uint32)); + + pLightmapPixelWriter->SkipBytes(m_wordsGathered * sizeof(uint32)); + m_wordsGathered = 0; + } + } + + // like commit, but the version we use when we know we're full. + // Takes advantage of better compile-time generation for + // memcpy. + void commitWhenFull(CPixelWriter * RESTRICT pLightmapPixelWriter) RESTRICT + { + unsigned char* RESTRICT pWriteInto = pLightmapPixelWriter->GetCurrentPixel(); + // we have to use memcpy because we're writing to non-cacheable memory, + // but we can't even assume that the addresses we're writing to are + // vector-aligned. +#ifdef memcpy // if someone's overriden the intrinsic, complain +#pragma error("You have overridden memcpy(), which is an XBOX360 intrinsic. This function will not behave optimally.") +#endif + + // if we're full, use compile-time known version of + // mempcy to take advantage of its ability to generate + // inline code. In fact, use the dword-aligned + // version so that we use the 64-bit writing funcs. + Assert( m_wordsGathered == kWordsPerRow ); + COMPILE_TIME_ASSERT((kWordsPerRow & 3) == 0); // the number of words per row has to be a multiple of four + + memcpy(pWriteInto, reinterpret_cast(m_data[0]), kWordsPerRow * sizeof(uint32)); + pWriteInto += m_bytesBetweenWriterRows; + memcpy(pWriteInto, reinterpret_cast(m_data[1]), kWordsPerRow * sizeof(uint32)); + pWriteInto += m_bytesBetweenWriterRows; + memcpy(pWriteInto, reinterpret_cast(m_data[2]), kWordsPerRow * sizeof(uint32)); + pWriteInto += m_bytesBetweenWriterRows; + memcpy(pWriteInto, reinterpret_cast(m_data[3]), kWordsPerRow * sizeof(uint32)); + + pLightmapPixelWriter->SkipBytes(m_wordsGathered * sizeof(uint32)); + m_wordsGathered = 0; + } + + // parameter: space between bump pages in the pixelwriter + CPixelWriterStoreGather(int writerSizeBytes) : m_wordsGathered(0), m_bytesBetweenWriterRows(writerSizeBytes) {}; + +}; +} + + +// this is a function for specifically writing bumped BGRA lightmaps -- in order for it +// to be properly scheduled, I needed to break out the inline functions. Also, +// to make the write-combined memory more efficient (and work around a bug in the +// April 2007 XDK), we need to store-gather our writes on the cache before blasting +// them out to write-combined memory. We can't simply write from the SIMD registers +// into the pixelwriter's data, because the difference between the output rows, +// eg nLightmap0WriterSizeBytes[0], might not be a multiple of 16. Unaligned stores +// to non-cacheable memory cause an alignment exception. +static void BumpedLightmapBitsToPixelWriter_HDRI_BGRA_X360( float* RESTRICT pFloatImage, float * RESTRICT pFloatImageBump1, float * RESTRICT pFloatImageBump2, + float * RESTRICT pFloatImageBump3, int pLightmapSize[2], int pOffsetIntoLightmapPage[2], FloatBitMap_t *pfmOut, + CPixelWriter * RESTRICT m_LightmapPixelWriter) +{ + AssertMsg(m_LightmapPixelWriter->GetPixelSize() == 4, "BGRA format is no longer four bytes long? This is unsupported on 360, and probably immoral as well."); + const int nLightmap0WriterSizeBytes = pLightmapSize[0] * 4 /*m_LightmapPixelWriter->GetPixelSize()*/; + // const int nRewindToNextPixel = -( ( nLightmap0WriterSizeBytes * 3 ) - 4 ); + + // assert that 1 * 4 = 4 + COMPILE_TIME_ASSERT(sizeof( Vector4D ) == sizeof(float) * 4); + + AssertMsg(!pfmOut, "Runtime conversion of lightmaps to files is no longer supported on 360.\n"); + + + // The store-gather buffers. Hopefully these will live in the L1 + // cache, which will make writing to them, then to memory, faster + // than just using __stvewx to write directly into WC memory + // one noncontiguous float at a time. (If there weren't a huge + // compiler bug with __stvewx in the Apr07 XDK, that might not + // be the case.) + CPixelWriterStoreGather storeGather(nLightmap0WriterSizeBytes); + + for( int t = 0; t < pLightmapSize[1]; t++ ) + { +#define FOUR (sizeof( Vector4D ) / sizeof( float )) // make explicit when we're incrementing by length of a 4dvec + int srcTexelOffset = ( FOUR ) * ( 0 + t * pLightmapSize[0] ); + m_LightmapPixelWriter->Seek( pOffsetIntoLightmapPage[0], pOffsetIntoLightmapPage[1] + t ); + + // Our code works best when we can process luxels in groups of four. So, + // figure out how many four-luxel groups we can process, + // then do them in groups, then process the remainder. + unsigned int groupsOfFourLimit = (((unsigned int)pLightmapSize[0]) & ~3); + + // we want to hang on to this index when we're done with groups so we can do the remainder. + unsigned int s; // counts the number of luxels processed + for( s = 0; + s < groupsOfFourLimit; + s += 4, srcTexelOffset += 4 * ( FOUR )) + { + static const fltx4 vSixteen = {16.0f, 16.0f, 16.0f, 16.0f}; + // the store-gather simds + fltx4 outBaseMap = Four_Zeros, outBump1 = Four_Zeros, outBump2 = Four_Zeros, outBump3 = Four_Zeros; + // we'll read four at a time + fltx4 vFloatImage[4], vFloatImageBump1[4], vFloatImageBump2[4], vFloatImageBump3[4]; + + + // stripe these loads to cause less ERAT thrashing + vFloatImage[0] = LoadUnalignedSIMD(pFloatImage + srcTexelOffset ); + vFloatImage[1] = LoadUnalignedSIMD(pFloatImage + srcTexelOffset + 4 ); + vFloatImage[2] = LoadUnalignedSIMD(pFloatImage + srcTexelOffset + 8 ); + vFloatImage[3] = LoadUnalignedSIMD(pFloatImage + srcTexelOffset + 12 ); + + vFloatImageBump1[0] = LoadUnalignedSIMD(pFloatImageBump1 + srcTexelOffset ); + vFloatImageBump1[1] = LoadUnalignedSIMD(pFloatImageBump1 + srcTexelOffset + 4 ); + vFloatImageBump1[2] = LoadUnalignedSIMD(pFloatImageBump1 + srcTexelOffset + 8 ); + vFloatImageBump1[3] = LoadUnalignedSIMD(pFloatImageBump1 + srcTexelOffset + 12 ); + + vFloatImageBump2[0] = LoadUnalignedSIMD(pFloatImageBump2 + srcTexelOffset ); + vFloatImageBump2[1] = LoadUnalignedSIMD(pFloatImageBump2 + srcTexelOffset + 4 ); + vFloatImageBump2[2] = LoadUnalignedSIMD(pFloatImageBump2 + srcTexelOffset + 8 ); + vFloatImageBump2[3] = LoadUnalignedSIMD(pFloatImageBump2 + srcTexelOffset + 12 ); + + vFloatImageBump3[0] = LoadUnalignedSIMD(pFloatImageBump3 + srcTexelOffset ); + vFloatImageBump3[1] = LoadUnalignedSIMD(pFloatImageBump3 + srcTexelOffset + 4 ); + vFloatImageBump3[2] = LoadUnalignedSIMD(pFloatImageBump3 + srcTexelOffset + 8 ); + vFloatImageBump3[3] = LoadUnalignedSIMD(pFloatImageBump3 + srcTexelOffset + 12 ); + + // perform an arcane averaging operation upon the bump map values + // (todo: make this not an inline so it will schedule better -- inlining is + // done by the linker, which is too late for operation scheduling) + ColorSpace::LinearToBumpedLightmap( vFloatImage[0], vFloatImageBump1[0], + vFloatImageBump2[0], vFloatImageBump3[0], + // transform "in place": + vFloatImage[0], vFloatImageBump1[0], + vFloatImageBump2[0], vFloatImageBump3[0] ); + ColorSpace::LinearToBumpedLightmap( vFloatImage[1], vFloatImageBump1[1], + vFloatImageBump2[1], vFloatImageBump3[1], + // transform "in place": + vFloatImage[1], vFloatImageBump1[1], + vFloatImageBump2[1], vFloatImageBump3[1] ); + ColorSpace::LinearToBumpedLightmap( vFloatImage[2], vFloatImageBump1[2], + vFloatImageBump2[2], vFloatImageBump3[2], + // transform "in place": + vFloatImage[2], vFloatImageBump1[2], + vFloatImageBump2[2], vFloatImageBump3[2] ); + ColorSpace::LinearToBumpedLightmap( vFloatImage[3], vFloatImageBump1[3], + vFloatImageBump2[3], vFloatImageBump3[3], + // transform "in place": + vFloatImage[3], vFloatImageBump1[3], + vFloatImageBump2[3], vFloatImageBump3[3] ); + + + // convert each color to RGB scaled. + // DO NOT! make this into a for loop. The (April07 XDK) compiler + // in fact DOES NOT unroll them, and will perform very naive + // scheduling if you try. + + // clamp to 0..16 float + vFloatImage[0] = MinSIMD(vFloatImage[0], vSixteen); + vFloatImageBump1[0] = MinSIMD(vFloatImageBump1[0], vSixteen); + vFloatImageBump2[0] = MinSIMD(vFloatImageBump2[0], vSixteen); + vFloatImageBump3[0] = MinSIMD(vFloatImageBump3[0], vSixteen); + + vFloatImage[1] = MinSIMD(vFloatImage[1], vSixteen); + vFloatImageBump1[1] = MinSIMD(vFloatImageBump1[1], vSixteen); + vFloatImageBump2[1] = MinSIMD(vFloatImageBump2[1], vSixteen); + vFloatImageBump3[1] = MinSIMD(vFloatImageBump3[1], vSixteen); + + vFloatImage[2] = MinSIMD(vFloatImage[2], vSixteen); + vFloatImageBump1[2] = MinSIMD(vFloatImageBump1[2], vSixteen); + vFloatImageBump2[2] = MinSIMD(vFloatImageBump2[2], vSixteen); + vFloatImageBump3[2] = MinSIMD(vFloatImageBump3[2], vSixteen); + + vFloatImage[3] = MinSIMD(vFloatImage[3], vSixteen); + vFloatImageBump1[3] = MinSIMD(vFloatImageBump1[3], vSixteen); + vFloatImageBump2[3] = MinSIMD(vFloatImageBump2[3], vSixteen); + vFloatImageBump3[3] = MinSIMD(vFloatImageBump3[3], vSixteen); + + + // compute the scaling factor, place it in w, and + // scale the rest by it. Obliterates whatever was + // already in alpha. + // This code is why it is important to not use a for + // loop: you need to let the compiler keep the value + // on registers (which it can't do if you use a + // variable indexed array) and interleave the + // inlined instructions. + + vFloatImage[0] = PackPixel_BGRA8888( ConvertLightmapColorToRGBScale(vFloatImage[0]) ); + vFloatImageBump1[0] = PackPixel_BGRA8888( ConvertLightmapColorToRGBScale(vFloatImageBump1[0]) ); + vFloatImageBump2[0] = PackPixel_BGRA8888( ConvertLightmapColorToRGBScale(vFloatImageBump2[0]) ); + vFloatImageBump3[0] = PackPixel_BGRA8888( ConvertLightmapColorToRGBScale(vFloatImageBump3[0]) ); + + vFloatImage[1] = PackPixel_BGRA8888( ConvertLightmapColorToRGBScale(vFloatImage[1]) ); + vFloatImageBump1[1] = PackPixel_BGRA8888( ConvertLightmapColorToRGBScale(vFloatImageBump1[1]) ); + vFloatImageBump2[1] = PackPixel_BGRA8888( ConvertLightmapColorToRGBScale(vFloatImageBump2[1]) ); + vFloatImageBump3[1] = PackPixel_BGRA8888( ConvertLightmapColorToRGBScale(vFloatImageBump3[1]) ); + + vFloatImage[2] = PackPixel_BGRA8888( ConvertLightmapColorToRGBScale(vFloatImage[2]) ); + vFloatImageBump1[2] = PackPixel_BGRA8888( ConvertLightmapColorToRGBScale(vFloatImageBump1[2]) ); + vFloatImageBump2[2] = PackPixel_BGRA8888( ConvertLightmapColorToRGBScale(vFloatImageBump2[2]) ); + vFloatImageBump3[2] = PackPixel_BGRA8888( ConvertLightmapColorToRGBScale(vFloatImageBump3[2]) ); + + vFloatImage[3] = PackPixel_BGRA8888( ConvertLightmapColorToRGBScale(vFloatImage[3]) ); + vFloatImageBump1[3] = PackPixel_BGRA8888( ConvertLightmapColorToRGBScale(vFloatImageBump1[3]) ); + vFloatImageBump2[3] = PackPixel_BGRA8888( ConvertLightmapColorToRGBScale(vFloatImageBump2[3]) ); + vFloatImageBump3[3] = PackPixel_BGRA8888( ConvertLightmapColorToRGBScale(vFloatImageBump3[3]) ); + + // Each of the registers above contains one RGBA 32-bit struct + // in their w word. So, combine them such that each of the assignees + // below contains four RGBAs, in xyzw order (big-endian). + + outBaseMap = __vrlimi(outBaseMap, vFloatImage[0], 8, 3 ); // insert into x + outBump1 = __vrlimi(outBump1, vFloatImageBump1[0], 8, 3 ); // insert into x + outBump2 = __vrlimi(outBump2, vFloatImageBump2[0], 8, 3 ); // insert into x + outBump3 = __vrlimi(outBump3, vFloatImageBump3[0], 8, 3 ); // insert into x + + outBaseMap = __vrlimi(outBaseMap, vFloatImage[1], 4, 2 ); // insert into y + outBump1 = __vrlimi(outBump1, vFloatImageBump1[1], 4, 2 ); // insert into y + outBump2 = __vrlimi(outBump2, vFloatImageBump2[1], 4, 2 ); // insert into y + outBump3 = __vrlimi(outBump3, vFloatImageBump3[1], 4, 2 ); // insert into y + + outBaseMap = __vrlimi(outBaseMap, vFloatImage[2], 2, 1 ); // insert into z + outBump1 = __vrlimi(outBump1, vFloatImageBump1[2], 2, 1 ); // insert into z + outBump2 = __vrlimi(outBump2, vFloatImageBump2[2], 2, 1 ); // insert into z + outBump3 = __vrlimi(outBump3, vFloatImageBump3[2], 2, 1 ); // insert into z + + outBaseMap = __vrlimi(outBaseMap, vFloatImage[3], 1, 0 ); // insert into w + outBump1 = __vrlimi(outBump1, vFloatImageBump1[3], 1, 0 ); // insert into w + outBump2 = __vrlimi(outBump2, vFloatImageBump2[3], 1, 0 ); // insert into w + outBump3 = __vrlimi(outBump3, vFloatImageBump3[3], 1, 0 ); // insert into w + + // push the data through the store-gather buffer. + storeGather.write(m_LightmapPixelWriter, outBaseMap, outBump1, outBump2, outBump3); + + } + + // Once here, make sure we've committed any leftover changes, then process + // the remainders singly. + storeGather.commit(m_LightmapPixelWriter); + + for( ; // s is where it should be from the loop above + s < (unsigned int) pLightmapSize[0]; + s++, + // m_LightmapPixelWriter->SkipBytes(nRewindToNextPixel), // now handled by store-gather + srcTexelOffset += ( FOUR )) + { + + static const fltx4 vSixteen = {16.0f, 16.0f, 16.0f, 16.0f}; + fltx4 vColor[4]; + fltx4 vFloatImage = LoadUnalignedSIMD(&pFloatImage[srcTexelOffset]); + fltx4 vFloatImageBump1 = LoadUnalignedSIMD(&pFloatImageBump1[srcTexelOffset]); + fltx4 vFloatImageBump2 = LoadUnalignedSIMD(&pFloatImageBump2[srcTexelOffset]); + fltx4 vFloatImageBump3 = LoadUnalignedSIMD(&pFloatImageBump3[srcTexelOffset]); + + // perform an arcane averaging operation upon the bump map values + ColorSpace::LinearToBumpedLightmap( vFloatImage, + vFloatImageBump1, vFloatImageBump2, + vFloatImageBump3, + vColor[0], vColor[1], vColor[2], vColor[3] ); + + // convert each color to RGB scaled. + // DO NOT! make this into a for loop. The (April07 XDK) compiler + // in fact DOES NOT unroll them, and will perform very naive + // scheduling if you try. + + // clamp to 0..16 float + vColor[0] = MinSIMD(vColor[0], vSixteen); + vColor[1] = MinSIMD(vColor[1], vSixteen); + vColor[2] = MinSIMD(vColor[2], vSixteen); + vColor[3] = MinSIMD(vColor[3], vSixteen); + + // compute the scaling factor, place it in w, and + // scale the rest by it. Obliterates whatever was + // already in alpha. + // This code is why it is important to not use a for + // loop: you need to let the compiler interleave the + // inlined instructions. + vColor[0] = ConvertLightmapColorToRGBScale( vColor[0] ); + vColor[1] = ConvertLightmapColorToRGBScale( vColor[1] ); + vColor[2] = ConvertLightmapColorToRGBScale( vColor[2] ); + vColor[3] = ConvertLightmapColorToRGBScale( vColor[3] ); + + +#ifdef X360_DOUBLECHECK_LIGHTMAPS + unsigned short color[4][4]; + + ColorSpace::LinearToBumpedLightmap( &pFloatImage[srcTexelOffset], + &pFloatImageBump1[srcTexelOffset], &pFloatImageBump2[srcTexelOffset], + &pFloatImageBump3[srcTexelOffset], + color[0], color[1], color[2], color[3] ); + unsigned short alpha = ColorSpace::LinearToUnsignedShort( pFloatImage[srcTexelOffset+3], 16 ); + color[0][3] = color[1][3] = color[2][3] = color[3][3] = alpha; + + if( IsX360() ) + { + for( int i = 0; i != 4; ++i ) + { + Vector4D vRGBScale; + + vRGBScale.x = color[i][0] * (16.0f / 65535.0f); + vRGBScale.y = color[i][1] * (16.0f / 65535.0f); + vRGBScale.z = color[i][2] * (16.0f / 65535.0f); + vRGBScale = ConvertLightmapColorToRGBScale( &vRGBScale.x ); + color[i][0] = RoundFloatToByte( vRGBScale.x * 255.0f ); + color[i][1] = RoundFloatToByte( vRGBScale.y * 255.0f ); + color[i][2] = RoundFloatToByte( vRGBScale.z * 255.0f ); + color[i][3] = RoundFloatToByte( vRGBScale.w * 255.0f ); + } + } + + /* + for (int ii = 0; ii < 4; ++ii) + { + uint32 pack = (PackPixel_BGRA8888( vColor[ii] ).u[3]); + if (color[ii][3] != 0) + Assert( color[ii][0] == (pack & 0xFF0000) >> 16 && + color[ii][1] == (pack & 0xFF00) >> 8 && + color[ii][2] == (pack & 0xFF) && + color[ii][3] == (pack & 0xFF000000) >> 24 ); + } + */ + +#endif + + + vColor[0] = PackPixel_BGRA8888( vColor[0] ); + vColor[1] = PackPixel_BGRA8888( vColor[1] ); + vColor[2] = PackPixel_BGRA8888( vColor[2] ); + vColor[3] = PackPixel_BGRA8888( vColor[3] ); + + storeGather.writeJustW(m_LightmapPixelWriter, vColor[0], vColor[1], vColor[2], vColor[3] ); + + /* // here is the old way of writing pixels: + // now we store-gather this + m_LightmapPixelWriter->WritePixelNoAdvance_BGRA8888( vColor[0] ); + Assert(*reinterpret_cast(m_LightmapPixelWriter->GetCurrentPixel()) == PackPixel_BGRA8888( vColor[0] ).u[3] ); + void * RESTRICT pBits = m_LightmapPixelWriter->SkipBytes( nLightmap0WriterSizeBytes ); + m_LightmapPixelWriter->WritePixelNoAdvance_BGRA8888( vColor[1], pBits ); + Assert(*reinterpret_cast(m_LightmapPixelWriter->GetCurrentPixel()) == PackPixel_BGRA8888( vColor[1] ).u[3] ); + pBits = m_LightmapPixelWriter->SkipBytes( nLightmap0WriterSizeBytes ); + m_LightmapPixelWriter->WritePixelNoAdvance_BGRA8888( vColor[2], pBits ); + Assert(*reinterpret_cast(m_LightmapPixelWriter->GetCurrentPixel()) == PackPixel_BGRA8888( vColor[2] ).u[3] ); + pBits = m_LightmapPixelWriter->SkipBytes( nLightmap0WriterSizeBytes ); + m_LightmapPixelWriter->WritePixelNoAdvance_BGRA8888( vColor[3], pBits ); + Assert(*reinterpret_cast(m_LightmapPixelWriter->GetCurrentPixel()) == PackPixel_BGRA8888( vColor[3] ).u[3] ); + + m_LightmapPixelWriter->SkipBytes(nRewindToNextPixel); + */ + } + + storeGather.commit(m_LightmapPixelWriter); + + } +} + +#endif // _X360 + +// write bumped lightmap update to HDR integer lightmap +void CMatLightmaps::BumpedLightmapBitsToPixelWriter_HDRI( float* RESTRICT pFloatImage, float * RESTRICT pFloatImageBump1, float * RESTRICT pFloatImageBump2, + float * RESTRICT pFloatImageBump3, int pLightmapSize[2], int pOffsetIntoLightmapPage[2], FloatBitMap_t *pfmOut ) RESTRICT +{ + const int nLightmapSize0 = pLightmapSize[0]; + const int nLightmap0WriterSizeBytes = nLightmapSize0 * m_LightmapPixelWriter.GetPixelSize(); + const int nRewindToNextPixel = -( ( nLightmap0WriterSizeBytes * 3 ) - m_LightmapPixelWriter.GetPixelSize() ); + + if( m_LightmapPixelWriter.IsUsingFloatFormat() ) + { + AssertMsg(!IsX360(), "Tried to use a floating-point pixel format for lightmaps on 360, which is not supported."); + if (!IsX360()) + { + for( int t = 0; t < pLightmapSize[1]; t++ ) + { + int srcTexelOffset = ( sizeof( Vector4D ) / sizeof( float ) ) * ( 0 + t * nLightmapSize0 ); + m_LightmapPixelWriter.Seek( pOffsetIntoLightmapPage[0], pOffsetIntoLightmapPage[1] + t ); + + for( int s = 0; + s < nLightmapSize0; + s++, m_LightmapPixelWriter.SkipBytes(nRewindToNextPixel),srcTexelOffset += (sizeof(Vector4D)/sizeof(float))) + { + unsigned short color[4][4]; + + ColorSpace::LinearToBumpedLightmap( &pFloatImage[srcTexelOffset], + &pFloatImageBump1[srcTexelOffset], &pFloatImageBump2[srcTexelOffset], + &pFloatImageBump3[srcTexelOffset], + color[0], color[1], color[2], color[3] ); + float alpha = pFloatImage[srcTexelOffset+3]; + Assert( alpha >= 0.0f && alpha <= 1.0f ); + color[0][3] = color[1][3] = color[2][3] = color[3][3] = alpha; + + float toFloat = ( 1.0f / ( float )( 1 << 16 ) ); + + /* // This code is now a can't-happen, because we do not allow float formats on 360. +#if ( defined( USE_32BIT_LIGHTMAPS_ON_360 ) ) + if( IsX360() ) + { + for( int i = 0; i != 4; ++i ) + { + Vector4D vRGBScale; + + vRGBScale.x = color[i][0] * (16.0f / 65535.0f); + vRGBScale.y = color[i][1] * (16.0f / 65535.0f); + vRGBScale.z = color[i][2] * (16.0f / 65535.0f); + vRGBScale = ConvertLightmapColorToRGBScale( &vRGBScale.x ); + color[i][0] = RoundFloatToByte( vRGBScale.x * 255.0f ); + color[i][1] = RoundFloatToByte( vRGBScale.y * 255.0f ); + color[i][2] = RoundFloatToByte( vRGBScale.z * 255.0f ); + color[i][3] = RoundFloatToByte( vRGBScale.w * 255.0f ); + } + + toFloat = ( 1.0f / ( float )( 1 << 8 ) ); + } +#endif + */ + + m_LightmapPixelWriter.WritePixelNoAdvanceF( toFloat * color[0][0], toFloat * color[0][1], toFloat * color[0][2], toFloat * color[0][3] ); + + m_LightmapPixelWriter.SkipBytes( nLightmap0WriterSizeBytes ); + m_LightmapPixelWriter.WritePixelNoAdvanceF( toFloat * color[1][0], toFloat * color[1][1], toFloat * color[1][2], toFloat * color[1][3] ); + + m_LightmapPixelWriter.SkipBytes( nLightmap0WriterSizeBytes ); + m_LightmapPixelWriter.WritePixelNoAdvanceF( toFloat * color[2][0], toFloat * color[2][1], toFloat * color[2][2], toFloat * color[2][3] ); + + m_LightmapPixelWriter.SkipBytes( nLightmap0WriterSizeBytes ); + m_LightmapPixelWriter.WritePixelNoAdvanceF( toFloat * color[3][0], toFloat * color[3][1], toFloat * color[3][2], toFloat * color[3][3] ); + } + } + } + } + else + { +#ifndef X360_USE_SIMD_LIGHTMAP + for( int t = 0; t < pLightmapSize[1]; t++ ) + { + int srcTexelOffset = ( sizeof( Vector4D ) / sizeof( float ) ) * ( 0 + t * nLightmapSize0 ); + m_LightmapPixelWriter.Seek( pOffsetIntoLightmapPage[0], pOffsetIntoLightmapPage[1] + t ); + + for( int s = 0; + s < nLightmapSize0; + s++, m_LightmapPixelWriter.SkipBytes(nRewindToNextPixel),srcTexelOffset += (sizeof(Vector4D)/sizeof(float))) + { + unsigned short color[4][4]; + + ColorSpace::LinearToBumpedLightmap( &pFloatImage[srcTexelOffset], + &pFloatImageBump1[srcTexelOffset], &pFloatImageBump2[srcTexelOffset], + &pFloatImageBump3[srcTexelOffset], + color[0], color[1], color[2], color[3] ); + unsigned short alpha = ColorSpace::LinearToUnsignedShort( pFloatImage[srcTexelOffset+3], 16 ); + color[0][3] = color[1][3] = color[2][3] = color[3][3] = alpha; + +#if ( defined( USE_32BIT_LIGHTMAPS_ON_360 ) ) + if( IsX360() ) + { + for( int i = 0; i != 4; ++i ) + { + Vector4D vRGBScale; + + vRGBScale.x = color[i][0] * (16.0f / 65535.0f); + vRGBScale.y = color[i][1] * (16.0f / 65535.0f); + vRGBScale.z = color[i][2] * (16.0f / 65535.0f); + vRGBScale = ConvertLightmapColorToRGBScale( &vRGBScale.x ); + color[i][0] = RoundFloatToByte( vRGBScale.x * 255.0f ); + color[i][1] = RoundFloatToByte( vRGBScale.y * 255.0f ); + color[i][2] = RoundFloatToByte( vRGBScale.z * 255.0f ); + color[i][3] = RoundFloatToByte( vRGBScale.w * 255.0f ); + } + } +#endif + m_LightmapPixelWriter.WritePixelNoAdvance( color[0][0], color[0][1], color[0][2], color[0][3] ); + + m_LightmapPixelWriter.SkipBytes( nLightmap0WriterSizeBytes ); + m_LightmapPixelWriter.WritePixelNoAdvance( color[1][0], color[1][1], color[1][2], color[1][3] ); + + m_LightmapPixelWriter.SkipBytes( nLightmap0WriterSizeBytes ); + m_LightmapPixelWriter.WritePixelNoAdvance( color[2][0], color[2][1], color[2][2], color[2][3] ); + + m_LightmapPixelWriter.SkipBytes( nLightmap0WriterSizeBytes ); + m_LightmapPixelWriter.WritePixelNoAdvance( color[3][0], color[3][1], color[3][2], color[3][3] ); + + // Write data to the bitmapped represenations so that PFM files can be written + if ( pfmOut ) + { + PixRGBAF pixelData; + pixelData.Red = color[0][0]; + pixelData.Green = color[0][1]; + pixelData.Blue = color[0][2]; + pixelData.Alpha = alpha; + pfmOut->WritePixelRGBAF(pOffsetIntoLightmapPage[0] + s, pOffsetIntoLightmapPage[1] + t, pixelData); + } + } + } +#else + // this is an optimized XBOX implementation. For a clearer + // presentation of the algorithm, see the PC implementation + // above. + // First check for the most common case, using an efficient + // branch rather than a switch: + if (m_LightmapPixelWriter.GetFormat() == IMAGE_FORMAT_LINEAR_BGRA8888) + { + // broken out into a static to make things more readable + // and be nicer to the instruction cache + BumpedLightmapBitsToPixelWriter_HDRI_BGRA_X360( pFloatImage, pFloatImageBump1, pFloatImageBump2, + pFloatImageBump3, pLightmapSize, pOffsetIntoLightmapPage, pfmOut, &m_LightmapPixelWriter ); + } + else + { // This case should actually never be hit -- we do not use RGBA. + for( int t = 0; t < pLightmapSize[1]; t++ ) + { + // assert that 1 * 4 = 4 + COMPILE_TIME_ASSERT(sizeof( Vector4D ) == sizeof(float) * 4); +#define FOUR (sizeof( Vector4D ) / sizeof( float )) // in case this ever changes + int srcTexelOffset = ( FOUR ) * ( 0 + t * nLightmapSize0 ); + m_LightmapPixelWriter.Seek( pOffsetIntoLightmapPage[0], pOffsetIntoLightmapPage[1] + t ); + + for( int s = 0; + s < nLightmapSize0; + s++, m_LightmapPixelWriter.SkipBytes(nRewindToNextPixel),srcTexelOffset += ( FOUR )) + { + + static const fltx4 vSixteen = {16.0f, 16.0f, 16.0f, 16.0f}; + fltx4 vColor[4]; + fltx4 vFloatImage = LoadUnalignedSIMD(&pFloatImage[srcTexelOffset]); + fltx4 vFloatImageBump1 = LoadUnalignedSIMD(&pFloatImageBump1[srcTexelOffset]); + fltx4 vFloatImageBump2 = LoadUnalignedSIMD(&pFloatImageBump2[srcTexelOffset]); + fltx4 vFloatImageBump3 = LoadUnalignedSIMD(&pFloatImageBump3[srcTexelOffset]); + + // perform an arcane averaging operation upon the bump map values + ColorSpace::LinearToBumpedLightmap( vFloatImage, + vFloatImageBump1, vFloatImageBump2, + vFloatImageBump3, + vColor[0], vColor[1], vColor[2], vColor[3] ); + + // convert each color to RGB scaled. + // DO NOT! make this into a for loop. The (April07 XDK) compiler + // in fact DOES NOT unroll them, and will perform very naive + // scheduling if you try. + + // clamp to 0..16 float + vColor[0] = MinSIMD(vColor[0], vSixteen); + vColor[1] = MinSIMD(vColor[1], vSixteen); + vColor[2] = MinSIMD(vColor[2], vSixteen); + vColor[3] = MinSIMD(vColor[3], vSixteen); + + // compute the scaling factor, transform the RGB, + // and place the scale in w. Obliterates whatever was + // already in alpha. + // This code is why it is important to not use a for + // loop: you need to let the compiler interleave the + // inlined instructions. + vColor[0] = ConvertLightmapColorToRGBScale( vColor[0] ); + vColor[1] = ConvertLightmapColorToRGBScale( vColor[1] ); + vColor[2] = ConvertLightmapColorToRGBScale( vColor[2] ); + vColor[3] = ConvertLightmapColorToRGBScale( vColor[3] ); + + + m_LightmapPixelWriter.WritePixelNoAdvance( vColor[0] ); + m_LightmapPixelWriter.SkipBytes( nLightmap0WriterSizeBytes ); + m_LightmapPixelWriter.WritePixelNoAdvance( vColor[1] ); + m_LightmapPixelWriter.SkipBytes( nLightmap0WriterSizeBytes ); + m_LightmapPixelWriter.WritePixelNoAdvance( vColor[2] ); + m_LightmapPixelWriter.SkipBytes( nLightmap0WriterSizeBytes ); + m_LightmapPixelWriter.WritePixelNoAdvance( vColor[3] ); + + AssertMsg(!pfmOut, "Runtime conversion of lightmaps to files is no longer supported on 360.\n"); + + // Write data to the bitmapped represenations so that PFM files can be written + if ( pfmOut ) + { + Warning("**************************************************\n" + "Lightmap output to files on 360 HAS BEEN DISABLED.\n" + "A grave error has just occurred.\n" + "**************************************************\n"); + DebuggerBreakIfDebugging(); + /* + PixRGBAF pixelData; + pixelData.Red = color[0][0]; + pixelData.Green = color[0][1]; + pixelData.Blue = color[0][2]; + pixelData.Alpha = alpha; + pfmOut->WritePixelRGBAF(pOffsetIntoLightmapPage[0] + s, pOffsetIntoLightmapPage[1] + t, pixelData); + */ + } + } + } + } +#endif + } +} + + +void CMatLightmaps::LightmapBitsToPixelWriter_LDR( float* pFloatImage, int pLightmapSize[2], int pOffsetIntoLightmapPage[2], FloatBitMap_t *pfmOut ) +{ + // non-HDR lightmap processing + float *pSrc = pFloatImage; + for( int t = 0; t < pLightmapSize[1]; ++t ) + { + m_LightmapPixelWriter.Seek( pOffsetIntoLightmapPage[0], pOffsetIntoLightmapPage[1] + t ); + for( int s = 0; s < pLightmapSize[0]; ++s, pSrc += (sizeof(Vector4D)/sizeof(*pSrc)) ) + { + unsigned char color[4]; + ColorSpace::LinearToLightmap( color, pSrc ); + color[3] = RoundFloatToByte( pSrc[3] * 255.0f ); + m_LightmapPixelWriter.WritePixel( color[0], color[1], color[2], color[3] ); + + if ( pfmOut ) + { + // Write data to the bitmapped represenations so that PFM files can be written + PixRGBAF pixelData; + pixelData.Red = color[0]; + pixelData.Green = color[1]; + pixelData.Blue = color[2]; + pixelData.Alpha = color[3]; + pfmOut->WritePixelRGBAF( pOffsetIntoLightmapPage[0] + s, pOffsetIntoLightmapPage[1] + t, pixelData ); + } + } + } +} + + +void CMatLightmaps::LightmapBitsToPixelWriter_HDRF( float* pFloatImage, int pLightmapSize[2], int pOffsetIntoLightmapPage[2], FloatBitMap_t *pfmOut ) +{ + if ( IsX360() ) + { + // 360 does not support HDR float + Assert( 0 ); + return; + } + + // float HDR lightmap processing + float *pSrc = pFloatImage; + for ( int t = 0; t < pLightmapSize[1]; ++t ) + { + m_LightmapPixelWriter.Seek( pOffsetIntoLightmapPage[0], pOffsetIntoLightmapPage[1] + t ); + for ( int s = 0; s < pLightmapSize[0]; ++s, pSrc += (sizeof(Vector4D)/sizeof(*pSrc)) ) + { + m_LightmapPixelWriter.WritePixelF( pSrc[0], pSrc[1], pSrc[2], pSrc[3] ); + } + } +} + +// numbers come in on the domain [0..16] +void CMatLightmaps::LightmapBitsToPixelWriter_HDRI( float* RESTRICT pFloatImage, int pLightmapSize[2], int pOffsetIntoLightmapPage[2], FloatBitMap_t * RESTRICT pfmOut ) +{ +#ifndef X360_USE_SIMD_LIGHTMAP + // PC code (and old, pre-SIMD xbox version -- unshippably slow) + if ( m_LightmapPixelWriter.IsUsingFloatFormat() ) + { + // integer HDR lightmap processing + float *pSrc = pFloatImage; + for ( int t = 0; t < pLightmapSize[1]; ++t ) + { + m_LightmapPixelWriter.Seek( pOffsetIntoLightmapPage[0], pOffsetIntoLightmapPage[1] + t ); + for ( int s = 0; s < pLightmapSize[0]; ++s, pSrc += (sizeof(Vector4D)/sizeof(*pSrc)) ) + { + int r, g, b, a; + + r = ColorSpace::LinearFloatToCorrectedShort( pSrc[0] ); + g = ColorSpace::LinearFloatToCorrectedShort( pSrc[1] ); + b = ColorSpace::LinearFloatToCorrectedShort( pSrc[2] ); + a = ColorSpace::LinearToUnsignedShort( pSrc[3], 16 ); + + float toFloat = ( 1.0f / ( float )( 1 << 16 ) ); + +#if ( defined( USE_32BIT_LIGHTMAPS_ON_360 ) ) + if( IsX360() ) + { + Vector4D vRGBScale; + + vRGBScale.x = r * (16.0f / 65535.0f); + vRGBScale.y = g * (16.0f / 65535.0f); + vRGBScale.z = b * (16.0f / 65535.0f); + vRGBScale = ConvertLightmapColorToRGBScale( &vRGBScale.x ); + + r = RoundFloatToByte( vRGBScale.x * 255.0f ); + g = RoundFloatToByte( vRGBScale.y * 255.0f ); + b = RoundFloatToByte( vRGBScale.z * 255.0f ); + a = RoundFloatToByte( vRGBScale.w * 255.0f ); + + toFloat = ( 1.0f / ( float )( 1 << 8 ) ); + } + +#endif + Assert( pSrc[3] >= 0.0f && pSrc[3] <= 1.0f ); + m_LightmapPixelWriter.WritePixelF( r * toFloat, g * toFloat, b * toFloat, pSrc[3] ); + } + } + } + else + { + // integer HDR lightmap processing + float *pSrc = pFloatImage; + for ( int t = 0; t < pLightmapSize[1]; ++t ) + { + m_LightmapPixelWriter.Seek( pOffsetIntoLightmapPage[0], pOffsetIntoLightmapPage[1] + t ); + for ( int s = 0; s < pLightmapSize[0]; ++s, pSrc += (sizeof(Vector4D)/sizeof(*pSrc)) ) + { + int r, g, b, a; + + r = ColorSpace::LinearFloatToCorrectedShort( pSrc[0] ); + g = ColorSpace::LinearFloatToCorrectedShort( pSrc[1] ); + b = ColorSpace::LinearFloatToCorrectedShort( pSrc[2] ); + a = ColorSpace::LinearToUnsignedShort( pSrc[3], 16 ); + +#if ( defined( USE_32BIT_LIGHTMAPS_ON_360 ) ) + if( IsX360() ) + { + Vector4D vRGBScale; + + vRGBScale.x = r * (16.0f / 65535.0f); + vRGBScale.y = g * (16.0f / 65535.0f); + vRGBScale.z = b * (16.0f / 65535.0f); + vRGBScale = ConvertLightmapColorToRGBScale( &vRGBScale.x ); + + r = RoundFloatToByte( vRGBScale.x * 255.0f ); + g = RoundFloatToByte( vRGBScale.y * 255.0f ); + b = RoundFloatToByte( vRGBScale.z * 255.0f ); + a = RoundFloatToByte( vRGBScale.w * 255.0f ); + } +#endif + m_LightmapPixelWriter.WritePixel( r, g, b, a ); + + if ( pfmOut ) + { + // Write data to the bitmapped represenations so that PFM files can be written + PixRGBAF pixelData; + pixelData.Red = pSrc[0]; + pixelData.Green = pSrc[1]; + pixelData.Blue = pSrc[2]; + pixelData.Alpha = pSrc[3]; + pfmOut->WritePixelRGBAF( pOffsetIntoLightmapPage[0] + s, pOffsetIntoLightmapPage[1] + t, pixelData ); + } + } + } + } +#else + // XBOX360 code + if ( m_LightmapPixelWriter.IsUsingFloatFormat() ) + { + if( IsX360() ) + { + AssertMsg( false, "Float-format pixel writers do not exist on x360." ); + } + else + { // This code is here as an example only, in case floating point + // format is restored to 360. + + // integer HDR lightmap processing + float * RESTRICT pSrc = pFloatImage; + for ( int t = 0; t < pLightmapSize[1]; ++t ) + { + m_LightmapPixelWriter.Seek( pOffsetIntoLightmapPage[0], pOffsetIntoLightmapPage[1] + t ); + for ( int s = 0; s < pLightmapSize[0]; ++s, pSrc += (sizeof(Vector4D)/sizeof(*pSrc)) ) + { + int r, g, b, a; + + r = ColorSpace::LinearFloatToCorrectedShort( pSrc[0] ); + g = ColorSpace::LinearFloatToCorrectedShort( pSrc[1] ); + b = ColorSpace::LinearFloatToCorrectedShort( pSrc[2] ); + a = ColorSpace::LinearToUnsignedShort( pSrc[3], 16 ); + + float toFloat = ( 1.0f / ( float )( 1 << 16 ) ); + +#if ( defined( USE_32BIT_LIGHTMAPS_ON_360 ) ) + if( IsX360() ) + { + Vector4D vRGBScale; + + vRGBScale.x = r * (16.0f / 65535.0f); + vRGBScale.y = g * (16.0f / 65535.0f); + vRGBScale.z = b * (16.0f / 65535.0f); + vRGBScale = ConvertLightmapColorToRGBScale( &vRGBScale.x ); + + r = RoundFloatToByte( vRGBScale.x * 255.0f ); + g = RoundFloatToByte( vRGBScale.y * 255.0f ); + b = RoundFloatToByte( vRGBScale.z * 255.0f ); + a = RoundFloatToByte( vRGBScale.w * 255.0f ); + + toFloat = ( 1.0f / ( float )( 1 << 8 ) ); + } + +#endif + Assert( pSrc[3] >= 0.0f && pSrc[3] <= 1.0f ); + m_LightmapPixelWriter.WritePixelF( r * toFloat, g * toFloat, b * toFloat, pSrc[3] ); + } + } + } + } + else + { + // This is the fast X360 pathway. + + // integer HDR lightmap processing + float * RESTRICT pSrc = pFloatImage; + // Assert((reinterpret_cast(pSrc) & 15) == 0); // 16-byte aligned? + COMPILE_TIME_ASSERT(sizeof(Vector4D)/sizeof(*pSrc) == 4); // assert that 1 * 4 = 4 +#ifndef USE_32BIT_LIGHTMAPS_ON_360 +#pragma error("This function only supports 32 bit lightmaps.") +#endif + + // input numbers from pSrc are on the domain [0..+inf] + // we clamp them to the range [0..16] + // output is RGBA + // the shader does this: rOut = Rin * Ain * 16.0f + // where Rin is [0..1], a float computed from a byte value [0..255] + // Ain is therefore the brightest channel (say R) divided by 16 and quantized + // Rin is computed from pSrc->r by dividing by Ain + + // rather than switching inside WritePixel for each different format, + // thus causing a 23-cycle pipeline clear for every pixel, we'll + // branch on the format here. That will allow us to unroll the inline + // pixel write functions differently depending on their different + // latencies. + + Assert(!pfmOut); // should never happen on 360. +#ifndef ALLOW_PFM_OUTPUT_ON_360 + if ( pfmOut ) + { + Warning("*****************************************\n" + "Lightmap output on 360 HAS BEEN DISABLED.\n" + "A grave error has just occurred.\n" + "*****************************************\n"); + } +#endif + + // switch once, here, outside the loop, rather than + // switching inside each pixel. Switches are not fast + // on x360: they are usually implemented as jumps + // through function tables, which have a 24-cycle + // stall. + switch (m_LightmapPixelWriter.GetFormat()) + { + // note: format names are low-order-byte first. + case IMAGE_FORMAT_RGBA8888: + case IMAGE_FORMAT_LINEAR_RGBA8888: + { + for ( int t = 0; t < pLightmapSize[1]; ++t ) + { + m_LightmapPixelWriter.Seek( pOffsetIntoLightmapPage[0], pOffsetIntoLightmapPage[1] + t ); + for ( int s = 0; s < pLightmapSize[0]; ++s, pSrc += 4 ) + { + static const fltx4 vSixteen = {16.0f, 16.0f, 16.0f, 16.0f}; + fltx4 rgba = LoadUnalignedSIMD(pSrc); + + // clamp to 0..16 float + rgba = MinSIMD(rgba, vSixteen); + // compute the scaling factor, place it in w, and + // scale the rest by it. + rgba = ConvertLightmapColorToRGBScale( rgba ); + // rgba is now float 0..255 in each component + m_LightmapPixelWriter.WritePixelNoAdvance_RGBA8888(rgba); + + + /* // not supported on X360 + if ( pfmOut ) + { + // Write data to the bitmapped represenations so that PFM files can be written + PixRGBAF pixelData; + XMStoreVector4(&pixelData,rgba); + pfmOut->WritePixelRGBAF( pOffsetIntoLightmapPage[0] + s, pOffsetIntoLightmapPage[1] + t, pixelData ); + } + */ + } + } + break; + } + + case IMAGE_FORMAT_BGRA8888: // NOTE! : the low order bits are first in this naming convention. + case IMAGE_FORMAT_LINEAR_BGRA8888: + { + for ( int t = 0; t < pLightmapSize[1]; ++t ) + { + m_LightmapPixelWriter.Seek( pOffsetIntoLightmapPage[0], pOffsetIntoLightmapPage[1] + t ); + for ( int s = 0; s < pLightmapSize[0]; ++s, pSrc += 4 ) + { + static const fltx4 vSixteen = {16.0f, 16.0f, 16.0f, 16.0f}; + fltx4 rgba = LoadUnalignedSIMD(pSrc); + + // clamp to 0..16 float + rgba = MinSIMD(rgba, vSixteen); + // compute the scaling factor, place it in w, and + // scale the rest by it. + rgba = ConvertLightmapColorToRGBScale( rgba ); + // rgba is now float 0..255 in each component + m_LightmapPixelWriter.WritePixelNoAdvance_BGRA8888(rgba); + // forcibly advance + m_LightmapPixelWriter.SkipBytes(4); + + /* // not supported on X360 + if ( pfmOut ) + { + // Write data to the bitmapped represenations so that PFM files can be written + PixRGBAF pixelData; + XMStoreVector4(&pixelData,rgba); + pfmOut->WritePixelRGBAF( pOffsetIntoLightmapPage[0] + s, pOffsetIntoLightmapPage[1] + t, pixelData ); + } + */ + } + } + break; + } + + default: + AssertMsg1(false,"Unsupported pixel format %d while writing lightmaps!", m_LightmapPixelWriter.GetFormat() ); + Warning("Unsupported pixel format used in lightmap. Lightmaps could not be downloaded.\n"); + break; + } + } +#endif +} + +void CMatLightmaps::BeginUpdateLightmaps( void ) +{ + CMatCallQueue *pCallQueue = GetMaterialSystem()->GetRenderContextInternal()->GetCallQueueInternal(); + if ( pCallQueue ) + { + pCallQueue->QueueCall( this, &CMatLightmaps::BeginUpdateLightmaps ); + return; + } + + m_nUpdatingLightmapsStackDepth++; +} + +void CMatLightmaps::EndUpdateLightmaps( void ) +{ + CMatCallQueue *pCallQueue = GetMaterialSystem()->GetRenderContextInternal()->GetCallQueueInternal(); + if ( pCallQueue ) + { + pCallQueue->QueueCall( this, &CMatLightmaps::EndUpdateLightmaps ); + return; + } + + m_nUpdatingLightmapsStackDepth--; + Assert( m_nUpdatingLightmapsStackDepth >= 0 ); + if( m_nUpdatingLightmapsStackDepth <= 0 && m_nLockedLightmap != -1 ) + { + g_pShaderAPI->TexUnlock(); + m_nLockedLightmap = -1; + } +} + +int CMatLightmaps::AllocateDynamicLightmap( int lightmapSize[2], int *pOutOffsetIntoPage, int frameID ) +{ + // check frameID, fail if current + for ( int i = 0; i < COUNT_DYNAMIC_LIGHTMAP_PAGES; i++ ) + { + int dynamicIndex = (m_dynamic.currentDynamicIndex + i) % COUNT_DYNAMIC_LIGHTMAP_PAGES; + int lightmapPageIndex = m_firstDynamicLightmap + dynamicIndex; + if ( m_dynamic.lightmapLockFrame[dynamicIndex] != frameID ) + { + m_dynamic.lightmapLockFrame[dynamicIndex] = frameID; + m_dynamic.imagePackers[dynamicIndex].Reset( 0, m_pLightmapPages[lightmapPageIndex].m_Width, m_pLightmapPages[lightmapPageIndex].m_Height ); + } + + if ( m_dynamic.imagePackers[dynamicIndex].AddBlock( lightmapSize[0], lightmapSize[1], &pOutOffsetIntoPage[0], &pOutOffsetIntoPage[1] ) ) + { + return lightmapPageIndex; + } + } + + return -1; +} + +//----------------------------------------------------------------------------- +// Updates the lightmap +//----------------------------------------------------------------------------- +void CMatLightmaps::UpdateLightmap( int lightmapPageID, int lightmapSize[2], + int offsetIntoLightmapPage[2], + float *pFloatImage, float *pFloatImageBump1, + float *pFloatImageBump2, float *pFloatImageBump3 ) +{ + VPROF( "CMatRenderContext::UpdateLightmap" ); + + bool hasBump = false; + int uSize = 1; + FloatBitMap_t *pfmOut = NULL; + if ( pFloatImageBump1 && pFloatImageBump2 && pFloatImageBump3 ) + { + hasBump = true; + uSize = 4; + } + + if ( lightmapPageID >= GetNumLightmapPages() || lightmapPageID < 0 ) + { + Error( "MaterialSystem_Interface_t::UpdateLightmap lightmapPageID=%d out of range\n", lightmapPageID ); + return; + } + bool bDynamic = IsDynamicLightmap(lightmapPageID); + + if ( bDynamic ) + { + int dynamicIndex = lightmapPageID-m_firstDynamicLightmap; + Assert(dynamicIndex < COUNT_DYNAMIC_LIGHTMAP_PAGES); + m_dynamic.currentDynamicIndex = (dynamicIndex + 1) % COUNT_DYNAMIC_LIGHTMAP_PAGES; + } + + if ( mat_lightmap_pfms.GetBool()) + { + // Allocate and initialize lightmap data that will be written to a PFM file + if (NULL == m_pLightmapDataPtrArray[lightmapPageID]) + { + m_pLightmapDataPtrArray[lightmapPageID] = new FloatBitMap_t(m_pLightmapPages[lightmapPageID].m_Width, m_pLightmapPages[lightmapPageID].m_Height); + m_pLightmapDataPtrArray[lightmapPageID]->Clear(0, 0, 0, 1); + } + pfmOut = m_pLightmapDataPtrArray[lightmapPageID]; + } + + // NOTE: Change how the lock is taking place if you ever change how bumped + // lightmaps are put into the page. Right now, we assume that they're all + // added to the right of the original lightmap. + bool bLockSubRect; + { + VPROF_( "Locking lightmaps", 2, VPROF_BUDGETGROUP_DLIGHT_RENDERING, false, 0 ); // vprof scope + + bLockSubRect = m_nUpdatingLightmapsStackDepth <= 0 && !bDynamic; + if( bLockSubRect ) + { + VPROF_INCREMENT_COUNTER( "lightmap subrect texlock", 1 ); + g_pShaderAPI->ModifyTexture( m_LightmapPageTextureHandles[lightmapPageID] ); + if (!g_pShaderAPI->TexLock( 0, 0, offsetIntoLightmapPage[0], offsetIntoLightmapPage[1], + lightmapSize[0] * uSize, lightmapSize[1], m_LightmapPixelWriter )) + { + return; + } + } + else if( lightmapPageID != m_nLockedLightmap ) + { + if ( !LockLightmap( lightmapPageID ) ) + { + ExecuteNTimes( 10, Warning( "Failed to lock lightmap\n" ) ); + return; + } + } + } + + int subRectOffset[2] = {0,0}; + + { + // account for the part spent in math: + VPROF_( "LightmapBitsToPixelWriter", 2, VPROF_BUDGETGROUP_DLIGHT_RENDERING, false, 0 ); + if ( hasBump ) + { + switch( HardwareConfig()->GetHDRType() ) + { + case HDR_TYPE_NONE: + BumpedLightmapBitsToPixelWriter_LDR( pFloatImage, pFloatImageBump1, pFloatImageBump2, pFloatImageBump3, + lightmapSize, bLockSubRect ? subRectOffset : offsetIntoLightmapPage, pfmOut ); + break; + case HDR_TYPE_INTEGER: + BumpedLightmapBitsToPixelWriter_HDRI( pFloatImage, pFloatImageBump1, pFloatImageBump2, pFloatImageBump3, + lightmapSize, bLockSubRect ? subRectOffset : offsetIntoLightmapPage, pfmOut ); + break; + case HDR_TYPE_FLOAT: + BumpedLightmapBitsToPixelWriter_HDRF( pFloatImage, pFloatImageBump1, pFloatImageBump2, pFloatImageBump3, + lightmapSize, bLockSubRect ? subRectOffset : offsetIntoLightmapPage, pfmOut ); + break; + } + } + else + { + switch ( HardwareConfig()->GetHDRType() ) + { + case HDR_TYPE_NONE: + LightmapBitsToPixelWriter_LDR( pFloatImage, lightmapSize, bLockSubRect ? subRectOffset : offsetIntoLightmapPage, pfmOut ); + break; + + case HDR_TYPE_INTEGER: + LightmapBitsToPixelWriter_HDRI( pFloatImage, lightmapSize, bLockSubRect ? subRectOffset : offsetIntoLightmapPage, pfmOut ); + break; + + case HDR_TYPE_FLOAT: + LightmapBitsToPixelWriter_HDRF( pFloatImage, lightmapSize, bLockSubRect ? subRectOffset : offsetIntoLightmapPage, pfmOut ); + break; + + default: + Assert( 0 ); + break; + } + } + } + + if( bLockSubRect ) + { + VPROF_( "Unlocking Lightmaps", 2, VPROF_BUDGETGROUP_DLIGHT_RENDERING, false, 0 ); + g_pShaderAPI->TexUnlock(); + } +} + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +int CMatLightmaps::GetNumSortIDs( void ) +{ + return m_numSortIDs; +} + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +void CMatLightmaps::ComputeSortInfo( MaterialSystem_SortInfo_t* pInfo, int& sortId, bool alpha ) +{ + int lightmapPageID; + + for ( MaterialHandle_t i = GetMaterialDict()->FirstMaterial(); i != GetMaterialDict()->InvalidMaterial(); i = GetMaterialDict()->NextMaterial(i) ) + { + IMaterialInternal* pMaterial = GetMaterialInternal(i); + + if ( pMaterial->GetMinLightmapPageID() > pMaterial->GetMaxLightmapPageID() ) + { + continue; + } + + // const IMaterialVar *pTransVar = pMaterial->GetMaterialProperty( MATERIAL_PROPERTY_OPACITY ); + // if( ( !alpha && ( pTransVar->GetIntValue() == MATERIAL_TRANSLUCENT ) ) || + // ( alpha && !( pTransVar->GetIntValue() == MATERIAL_TRANSLUCENT ) ) ) + // { + // return true; + // } + + +// Warning( "sort stuff: %s %s\n", material->GetName(), bAlpha ? "alpha" : "not alpha" ); + + // fill in the lightmapped materials + for ( lightmapPageID = pMaterial->GetMinLightmapPageID(); + lightmapPageID <= pMaterial->GetMaxLightmapPageID(); ++lightmapPageID ) + { + pInfo[sortId].material = pMaterial->GetQueueFriendlyVersion(); + pInfo[sortId].lightmapPageID = lightmapPageID; +#if 0 + char buf[128]; + Q_snprintf( buf, sizeof( buf ), "ComputeSortInfo: %s lightmapPageID: %d sortID: %d\n", pMaterial->GetName(), lightmapPageID, sortId ); + OutputDebugString( buf ); +#endif + ++sortId; + } + } +} + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +void CMatLightmaps::ComputeWhiteLightmappedSortInfo( MaterialSystem_SortInfo_t* pInfo, int& sortId, bool alpha ) +{ + for (MaterialHandle_t i = GetMaterialDict()->FirstMaterial(); i != GetMaterialDict()->InvalidMaterial(); i = GetMaterialDict()->NextMaterial(i) ) + { + IMaterialInternal* pMaterial = GetMaterialInternal(i); + + // fill in the lightmapped materials that are actually used by this level + if( pMaterial->GetNeedsWhiteLightmap() && + ( pMaterial->GetReferenceCount() > 0 ) ) + { + // const IMaterialVar *pTransVar = pMaterial->GetMaterialProperty( MATERIAL_PROPERTY_OPACITY ); + // if( ( !alpha && ( pTransVar->GetIntValue() == MATERIAL_TRANSLUCENT ) ) || + // ( alpha && !( pTransVar->GetIntValue() == MATERIAL_TRANSLUCENT ) ) ) + // { + // return true; + // } + + pInfo[sortId].material = pMaterial->GetQueueFriendlyVersion(); + if( pMaterial->GetPropertyFlag( MATERIAL_PROPERTY_NEEDS_BUMPED_LIGHTMAPS ) ) + { + pInfo[sortId].lightmapPageID = MATERIAL_SYSTEM_LIGHTMAP_PAGE_WHITE_BUMP; + } + else + { + pInfo[sortId].lightmapPageID = MATERIAL_SYSTEM_LIGHTMAP_PAGE_WHITE; + } + + sortId++; + } + } +} + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +void CMatLightmaps::GetSortInfo( MaterialSystem_SortInfo_t *pSortInfoArray ) +{ + // sort non-alpha blended materials first + int sortId = 0; + ComputeSortInfo( pSortInfoArray, sortId, false ); + ComputeWhiteLightmappedSortInfo( pSortInfoArray, sortId, false ); + Assert( m_numSortIDs == sortId ); +} + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +void CMatLightmaps::EnableLightmapFiltering( bool enabled ) +{ + int i; + for( i = 0; i < GetNumLightmapPages(); i++ ) + { + g_pShaderAPI->ModifyTexture( m_LightmapPageTextureHandles[i] ); + if( enabled ) + { + g_pShaderAPI->TexMinFilter( SHADER_TEXFILTERMODE_LINEAR ); + g_pShaderAPI->TexMagFilter( SHADER_TEXFILTERMODE_LINEAR ); + } + else + { + g_pShaderAPI->TexMinFilter( SHADER_TEXFILTERMODE_NEAREST ); + g_pShaderAPI->TexMagFilter( SHADER_TEXFILTERMODE_NEAREST ); + } + } +} + + diff --git a/materialsystem/cmatlightmaps.h b/materialsystem/cmatlightmaps.h new file mode 100644 index 0000000..f2b135f --- /dev/null +++ b/materialsystem/cmatlightmaps.h @@ -0,0 +1,199 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//============================================================================= + +#ifndef CMATERIALLIGHTMAPS_H +#define CMATERIALLIGHTMAPS_H + +#include "tier1/utlvector.h" +#include "imagepacker.h" + +#ifndef MATSYS_INTERNAL +#error "This file is private to the implementation of IMaterialSystem/IMaterialSystemInternal" +#endif + +#if defined( _WIN32 ) +#pragma once +#endif + +//----------------------------------------------------------------------------- + +class CMaterialSystem; +class IMatRenderContextInternal; +class CMaterialDict; +class IMaterial; +class IMaterialInternal; +class FloatBitMap_t; +typedef int ShaderAPITextureHandle_t; +struct MaterialSystem_SortInfo_t; +typedef unsigned short MaterialHandle_t; + +//----------------------------------------------------------------------------- +// Manager of material system lightmaps +//----------------------------------------------------------------------------- +const int COUNT_DYNAMIC_LIGHTMAP_PAGES = 1; + +class CMatLightmaps +{ +public: + CMatLightmaps(); + + void Shutdown( ); + + //------------------------------------------------------------ + // Methods exposed in IMaterialSystem + //------------------------------------------------------------ + void BeginLightmapAllocation( void ); + void EndLightmapAllocation( void ); + + int AllocateLightmap( int width, int height, + int offsetIntoLightmapPage[2], + IMaterial *pMaterial ); + int AllocateWhiteLightmap( IMaterial *pMaterial ); + // NOTE: This returns a lightmap page ID, not a sortID like AllocateLightmap!!!! + int AllocateDynamicLightmap( int lightmapSize[2], int *pOutOffsetIntoPage, int frameID ); + + int GetNumSortIDs( void ); + void GetSortInfo( MaterialSystem_SortInfo_t *sortInfoArray ); + + void UpdateLightmap( int lightmapPageID, int lightmapSize[2], + int offsetIntoLightmapPage[2], + float *pFloatImage, float *pFloatImageBump1, + float *pFloatImageBump2, float *pFloatImageBump3 ); + + void GetLightmapPageSize( int lightmapPageID, int *width, int *height ) const; + + void ResetMaterialLightmapPageInfo( void ); + + //------------------------------------------------------------ + // Methods exposed in IMaterialSystemInternal + //------------------------------------------------------------ + int GetLightmapWidth( int lightmap ) const; + int GetLightmapHeight( int lightmap ) const; + + //------------------------------------------------------------ + // Methods used by other material system components + //------------------------------------------------------------ + + // Releases/restores lightmap pages + void ReleaseLightmapPages(); + void RestoreLightmapPages(); + + void EnableLightmapFiltering( bool enabled ); + + int GetNumLightmapPages() const { return m_NumLightmapPages;} + ShaderAPITextureHandle_t GetLightmapPageTextureHandle( int lightmap ) { return m_LightmapPageTextureHandles[lightmap]; } + bool IsDynamicLightmap( int lightmap ) const { return (lightmap >= m_firstDynamicLightmap ) ? true : false; } + + CMaterialSystem *GetMaterialSystem() const; + + void BeginUpdateLightmaps(); + void EndUpdateLightmaps(); + +private: + + // Gets the maximum lightmap page size... + int GetMaxLightmapPageWidth() const; + int GetMaxLightmapPageHeight() const; + + void CleanupLightmaps(); + + // Allocate lightmap textures in D3D + void AllocateLightmapTexture( int lightmap ); + + // Initializes lightmap bits + void InitLightmapBits( int lightmap ); + + // assumes m_LightmapPixelWriter is already set up - results written there + void BumpedLightmapBitsToPixelWriter_LDR( float* pFloatImage, float *pFloatImageBump1, float *pFloatImageBump2, + float *pFloatImageBump3, int pLightmapSize[2], int pOffsetIntoLightmapPage[2], FloatBitMap_t *pfmOut ); + void BumpedLightmapBitsToPixelWriter_HDRF( float* pFloatImage, float *pFloatImageBump1, float *pFloatImageBump2, + float *pFloatImageBump3, int pLightmapSize[2], int pOffsetIntoLightmapPage[2], FloatBitMap_t *pfmOut ); + + void BumpedLightmapBitsToPixelWriter_HDRI( float* pFloatImage, float *pFloatImageBump1, float *pFloatImageBump2, + float *pFloatImageBump3, int pLightmapSize[2], int pOffsetIntoLightmapPage[2], FloatBitMap_t *pfmOut ); + + void LightmapBitsToPixelWriter_LDR( float* pFloatImage, int pLightmapSize[2], int pOffsetIntoLightmapPage[2], FloatBitMap_t *pfmOut ); + void LightmapBitsToPixelWriter_HDRF( float* pFloatImage, int pLightmapSize[2], int pOffsetIntoLightmapPage[2], FloatBitMap_t *pfmOut ); + void LightmapBitsToPixelWriter_HDRI( float* pFloatImage, int pLightmapSize[2], int pOffsetIntoLightmapPage[2], FloatBitMap_t *pfmOut ); + + // For computing sort info + void ComputeSortInfo( MaterialSystem_SortInfo_t* pInfo, int& sortId, bool alpha ); + void ComputeWhiteLightmappedSortInfo( MaterialSystem_SortInfo_t* pInfo, int& sortId, bool alpha ); + + void EnumerateMaterials( void ); + + // Lock a lightmap for update. + bool LockLightmap( int lightmap ); + + + + //------------------------------------------------------------ + // Accessor helpers + //------------------------------------------------------------ + + IMaterialInternal* GetCurrentMaterialInternal() const; + void SetCurrentMaterialInternal(IMaterialInternal* pCurrentMaterial); + IMaterialInternal* GetMaterialInternal( MaterialHandle_t idx ) const; + const IMatRenderContextInternal *GetRenderContextInternal() const; + IMatRenderContextInternal *GetRenderContextInternal(); + const CMaterialDict *GetMaterialDict() const; + CMaterialDict *GetMaterialDict(); + + //------------------------------------------------------------ + + struct LightmapPageInfo_t + { + unsigned short m_Width; + unsigned short m_Height; + int m_Flags; + }; + + struct dynamiclightmap_t + { + void Init() + { + lightmapLocked = -1; + frameID = 0; + currentDynamicIndex = 0; + for ( int i = 0; i < COUNT_DYNAMIC_LIGHTMAP_PAGES; i++ ) + { + lightmapLockFrame[i] = 0; + } + } + + int lightmapLocked; + int frameID; + int currentDynamicIndex; + int lightmapLockFrame[COUNT_DYNAMIC_LIGHTMAP_PAGES]; + CImagePacker imagePackers[COUNT_DYNAMIC_LIGHTMAP_PAGES]; + }; + + + CUtlVector m_ImagePackers; + int m_numSortIDs; + IMaterialInternal *m_currentWhiteLightmapMaterial; + + LightmapPageInfo_t *m_pLightmapPages; + CUtlVector m_LightmapPageTextureHandles; + int m_NumLightmapPages; + int m_nUpdatingLightmapsStackDepth; + int m_firstDynamicLightmap; + CPixelWriter m_LightmapPixelWriter; + int m_nLockedLightmap; // -1 for nothing locked. + dynamiclightmap_t m_dynamic; + FloatBitMap_t **m_pLightmapDataPtrArray; + + enum LightmapsState + { + STATE_DEFAULT, // Lightmaps in default state - all operations allowed + STATE_RELEASED // Lightmaps in released state - usually due to lost/released D3D device, D3D operations disallowed, Restore() call to follow + }; + LightmapsState m_eLightmapsState; +}; + +//----------------------------------------------------------------------------- + +#endif // CMATERIALLIGHTMAPS_H diff --git a/materialsystem/cmatnullrendercontext.cpp b/materialsystem/cmatnullrendercontext.cpp new file mode 100644 index 0000000..a776312 --- /dev/null +++ b/materialsystem/cmatnullrendercontext.cpp @@ -0,0 +1,847 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//============================================================================= + +#include "pch_materialsystem.h" + +#include "cmatnullrendercontext.h" + +#define MATSYS_INTERNAL +#include "cmatrendercontext.h" +#include "itextureinternal.h" + +class CMatNullRenderContext : public CMatRenderContextBase +{ +public: + CMatNullRenderContext() + : m_WidthBackBuffer( 0 ), + m_HeightBackBuffer( 0 ) + { + } + + virtual void InitializeFrom( CMatRenderContextBase *pInitialState ) + { + CMatRenderContextBase::InitializeFrom( pInitialState ); + g_pShaderAPI->GetBackBufferDimensions( m_WidthBackBuffer, m_HeightBackBuffer ); + } + + void BeginRender() + { + } + + void EndRender() + { + } + + void Flush(bool) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + void GetRenderTargetDimensions(int &,int &) const + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + void DepthRange(float,float) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + void ClearBuffers(bool,bool,bool) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + void ReadPixels(int,int,int,int,unsigned char *,ImageFormat) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + void SetAmbientLight(float,float,float) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + void SetLight(int,const LightDesc_t &) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + void SetLightingOrigin( Vector vLightingOrigin ) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + void SetAmbientLightCube(Vector4D []) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + void CopyRenderTargetToTexture(ITexture *) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + void SetFrameBufferCopyTexture(ITexture *,int) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + ITexture *GetFrameBufferCopyTexture(int) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + return NULL; + } + + void GetViewport( int& x, int& y, int& width, int& height ) const + { + // Verify valid top of RT stack + Assert ( m_RenderTargetStack.Count() > 0 ); + + // Grab the top of stack + const RenderTargetStackElement_t& element = m_RenderTargetStack.Top(); + + // If either dimension is negative, set to full bounds of current target + if ( (element.m_nViewW < 0) || (element.m_nViewH < 0) ) + { + // Viewport origin at target origin + x = y = 0; + + // If target is back buffer + if ( element.m_pRenderTargets[0] == NULL ) + { + width = m_WidthBackBuffer; + height = m_HeightBackBuffer; + } + else // if target is texture + { + width = element.m_pRenderTargets[0]->GetActualWidth(); + height = element.m_pRenderTargets[0]->GetActualHeight(); + } + } + else // use the bounds from the stack directly + { + x = element.m_nViewX; + y = element.m_nViewY; + width = element.m_nViewW; + height = element.m_nViewH; + } + } + void CullMode(MaterialCullMode_t) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + void FogMode(MaterialFogMode_t) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + void FogStart(float) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + void FogEnd(float) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + void SetFogZ(float) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + MaterialFogMode_t GetFogMode() + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + return MATERIAL_FOG_NONE; + } + + int GetCurrentNumBones( ) const + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + return 0; + } + + void FogColor3f(float,float,float) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + void FogColor3fv(const float *) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + void FogColor3ub(unsigned char,unsigned char,unsigned char) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + void FogColor3ubv(const unsigned char *) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + void GetFogColor(unsigned char *) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + void SetNumBoneWeights(int) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + IMesh *CreateStaticMesh(VertexFormat_t,const char *,IMaterial *) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + return NULL; + } + + void DestroyStaticMesh(IMesh *) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + IMesh *GetDynamicMesh(bool,IMesh *,IMesh *,IMaterial *) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + return NULL; + } + + virtual IMesh* GetDynamicMeshEx( VertexFormat_t, bool, IMesh*, IMesh*, IMaterial * ) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + return NULL; + } + + int SelectionMode(bool) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + return 0; + } + + void SelectionBuffer(unsigned int *,int) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + void ClearSelectionNames() + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + void LoadSelectionName(int) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + void PushSelectionName(int) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + void PopSelectionName() + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + void ClearColor3ub(unsigned char,unsigned char,unsigned char) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + void ClearColor4ub(unsigned char,unsigned char,unsigned char,unsigned char) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + void OverrideDepthEnable(bool,bool) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + void OverrideColorWriteEnable( bool, bool ) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + void OverrideAlphaWriteEnable( bool, bool ) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + void DrawScreenSpaceQuad(IMaterial *) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + void SyncToken(const char *) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + OcclusionQueryObjectHandle_t CreateOcclusionQueryObject() + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + return NULL; + } + + void DestroyOcclusionQueryObject(OcclusionQueryObjectHandle_t) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + void ResetOcclusionQueryObject( OcclusionQueryObjectHandle_t hOcclusionQuery ) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + void BeginOcclusionQueryDrawing(OcclusionQueryObjectHandle_t) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + void EndOcclusionQueryDrawing(OcclusionQueryObjectHandle_t) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + int OcclusionQuery_GetNumPixelsRendered(OcclusionQueryObjectHandle_t) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + return 1; + } + + void SetFlashlightMode(bool) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + virtual bool GetFlashlightMode( void ) const + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + return false; + } + + void SetFlashlightState(const FlashlightState_t &,const VMatrix &) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + void SetScissorRect( const int nLeft, const int nTop, const int nRight, const int nBottom, const bool bEnableScissor ) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + virtual void PushDeformation( DeformationBase_t const *Deformation ) + { + } + + virtual void PopDeformation( ) + { + } + + virtual int GetNumActiveDeformations() const + { + return 0; + } + + void EnableUserClipTransformOverride(bool) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + void UserClipTransform(const VMatrix &) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + IMorph *CreateMorph(MorphFormat_t, const char *pDebugName) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + return NULL; + } + + void DestroyMorph(IMorph *) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + void BindMorph(IMorph *) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + void SetMorphTargetFactors(int,float *,int) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + void ReadPixelsAndStretch(Rect_t *,Rect_t *,unsigned char *,ImageFormat,int) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + void GetWindowSize(int &,int &) const + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + void DrawScreenSpaceRectangle(IMaterial *,int,int,int,int,float,float,float,float,int,int,void*,int,int) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + void LoadBoneMatrix(int,const matrix3x4_t &) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + void BindLightmapTexture(ITexture *) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + void CopyRenderTargetToTextureEx(ITexture *,int,Rect_t *,Rect_t *) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + void CopyTextureToRenderTargetEx(int,ITexture *,Rect_t *,Rect_t *) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + void SetFloatRenderingParameter(int,float) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + void SetIntRenderingParameter(int,int) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + void SetVectorRenderingParameter(int,const Vector &) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + void SetStencilEnable(bool) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + void SetStencilFailOperation(StencilOperation_t) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + void SetStencilZFailOperation(StencilOperation_t) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + void SetStencilPassOperation(StencilOperation_t) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + void SetStencilCompareFunction(StencilComparisonFunction_t) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + void SetStencilReferenceValue(int) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + void SetStencilTestMask(uint32) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + void SetStencilWriteMask(uint32) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + void ClearStencilBufferRectangle(int,int,int,int,int) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + void PushCustomClipPlane(const float *) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + void PopCustomClipPlane() + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + void GetMaxToRender(IMesh *,bool,int *,int *) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + int GetMaxVerticesToRender(IMaterial *) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + return 0; + } + + int GetMaxIndicesToRender() + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + return 0; + } + + void DisableAllLocalLights() + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + int CompareMaterialCombos(IMaterial *,IMaterial *,int,int) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + return 0; + } + + IMesh *GetFlexMesh() + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + return NULL; + } + + void SetFlashlightStateEx(const FlashlightState_t &,const VMatrix &,ITexture *) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + ITexture *GetLocalCubemap() + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + return NULL; + } + + void ClearBuffersObeyStencil(bool,bool) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + void ClearBuffersObeyStencilEx( bool bClearColor, bool bClearAlpha, bool bClearDepth ) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + void PerformFullScreenStencilOperation( void ) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + bool GetUserClipTransform(VMatrix &) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + return true; + } + + void GetFogDistances(float *,float *,float *) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + void BeginPIXEvent(unsigned long,const char *) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + void EndPIXEvent() + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + void SetPIXMarker(unsigned long,const char *) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + void BeginBatch(IMesh *) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + void BindBatch(IMesh *,IMaterial *) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + void DrawBatch(int,int) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + void EndBatch() + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + void SetToneMappingScaleLinear(const Vector &) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + float GetFloatRenderingParameter(int) const + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + return 0; + } + + int GetIntRenderingParameter(int) const + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + return 0; + } + + Vector GetVectorRenderingParameter(int) const + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + return Vector(0,0,0); + } + + void SwapBuffers() + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + void ForceDepthFuncEquals(bool) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + bool InFlashlightMode() const + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + return true; + } + + void BindStandardTexture(TextureStage_t,StandardTextureId_t) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + void GetLightmapDimensions(int *,int *) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + MorphFormat_t GetBoundMorphFormat() + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + return 0; + } + + void DrawClearBufferQuad(unsigned char,unsigned char,unsigned char,unsigned char,bool,bool,bool) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + bool OnDrawMesh(IMesh *,CPrimList *,int) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + return true; + } + + bool OnDrawMesh(IMesh *,int,int) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + return true; + } + + bool OnSetFlexMesh(IMesh *,IMesh *,int) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + return true; + } + + bool OnSetColorMesh(IMesh *,IMesh *,int) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + return true; + } + + bool OnSetPrimitiveType(IMesh *,MaterialPrimitiveType_t) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + return true; + } + + bool OnFlushBufferedPrimitives() + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + return true; + } + + void ForceHardwareSync() + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + void BeginFrame() + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + void EndFrame() + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + void AsyncCreateTextureFromRenderTarget( ITexture* pSrcRt, const char* pDstName, ImageFormat dstFmt, bool bGenMips, int nAdditionalCreationFlags, IAsyncTextureOperationReceiver* pRecipient, void* pExtraArgs ) OVERRIDE + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + virtual void AsyncMap( ITextureInternal* pTexToMap, IAsyncTextureOperationReceiver* pRecipient, void* pExtraArgs ) OVERRIDE + { + + } + + virtual void AsyncUnmap( ITextureInternal* pTexToUnmap ) OVERRIDE + { + + } + + virtual void AsyncCopyRenderTargetToStagingTexture( ITexture* pDst, ITexture* pSrc, IAsyncTextureOperationReceiver* pRecipient, void* pExtraArgs ) OVERRIDE + { + + } + + void SetShadowDepthBiasFactors( float fSlopeScaleDepthBias, float fDepthBias ) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + void BindStandardTexture( Sampler_t, StandardTextureId_t ) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + +// ------------ New Vertex/Index Buffer interface ---------------------------- + // Do we need support for bForceTempMesh and bSoftwareVertexShader? + // I don't think we use bSoftwareVertexShader anymore. .need to look into bForceTempMesh. + IVertexBuffer *CreateStaticVertexBuffer( VertexFormat_t fmt, int nVertexCount, const char *pBudgetGroup ) + { + Assert( 0 ); + return NULL; + } + IIndexBuffer *CreateStaticIndexBuffer( MaterialIndexFormat_t fmt, int nIndexCount, const char *pBudgetGroup ) + { + Assert( 0 ); + return NULL; + } + void DestroyVertexBuffer( IVertexBuffer * ) + { + Assert( 0 ); + } + void DestroyIndexBuffer( IIndexBuffer * ) + { + Assert( 0 ); + } + // Do we need to specify the stream here in the case of locking multiple dynamic VBs on different streams? + IVertexBuffer *GetDynamicVertexBuffer( int streamID, VertexFormat_t vertexFormat, bool bBufferedtrue ) + { + Assert( 0 ); + return NULL; + } + IIndexBuffer *GetDynamicIndexBuffer( MaterialIndexFormat_t fmt, bool bBufferedtrue ) + { + Assert( 0 ); + return NULL; + } + void BindVertexBuffer( int streamID, IVertexBuffer *pVertexBuffer, int nOffsetInBytes, int nFirstVertex, int nVertexCount, VertexFormat_t fmt, int nRepetitions1 ) + { + Assert( 0 ); + } + void BindIndexBuffer( IIndexBuffer *pIndexBuffer, int nOffsetInBytes ) + { + Assert( 0 ); + } + void Draw( MaterialPrimitiveType_t primitiveType, int firstIndex, int numIndices ) + { + Assert( 0 ); + } + virtual void BeginMorphAccumulation() + { + Assert( 0 ); + } + virtual void EndMorphAccumulation() + { + Assert( 0 ); + } + virtual void AccumulateMorph( IMorph* pMorph, int nMorphCount, const MorphWeight_t* pWeights ) + { + Assert( 0 ); + } + virtual bool GetMorphAccumulatorTexCoord( Vector2D *pTexCoord, IMorph *pMorph, int nVertex ) + { + Assert(0); + pTexCoord->Init(); + return false; + } + virtual void SetFlexWeights( int nFirstWeight, int nCount, const MorphWeight_t* pWeights ) {} + + virtual void FogMaxDensity( float flMaxDensity ) + { + AssertMsg( 0, "CMatNullRenderContext only provides base features, not a stub (right now)" ); + } + + virtual void EnableColorCorrection( bool bEnable ) {} + virtual ColorCorrectionHandle_t AddLookup( const char *pName ) { return 0; } + virtual bool RemoveLookup( ColorCorrectionHandle_t handle ) { return true; } + virtual void LockLookup( ColorCorrectionHandle_t handle ) {} + virtual void LoadLookup( ColorCorrectionHandle_t handle, const char *pLookupName ) {} + virtual void UnlockLookup( ColorCorrectionHandle_t handle ) {} + virtual void SetLookupWeight( ColorCorrectionHandle_t handle, float flWeight ) {} + virtual void ResetLookupWeights( ) {} + virtual void SetResetable( ColorCorrectionHandle_t handle, bool bResetable ) {} + virtual void SetFullScreenDepthTextureValidityFlag( bool bIsValid ) {} + + virtual void SetNonInteractivePacifierTexture( ITexture *pTexture, float flNormalizedX, float flNormalizedY, float flNormalizedSize ) {} + virtual void SetNonInteractiveTempFullscreenBuffer( ITexture *pTexture, MaterialNonInteractiveMode_t mode ) {} + virtual void EnableNonInteractiveMode( MaterialNonInteractiveMode_t mode ) {} + virtual void RefreshFrontBufferNonInteractive() {} + +#if defined( _X360 ) + virtual void PushVertexShaderGPRAllocation( int iVertexShaderCount = 64 ) + { + Assert( 0 ); + } + + virtual void PopVertexShaderGPRAllocation( void ) + { + Assert( 0 ); + } +#endif + +#ifdef DX_TO_GL_ABSTRACTION + void DoStartupShaderPreloading( void ) {}; +#endif + + void TextureManagerUpdate( void ) { } + + int m_WidthBackBuffer, m_HeightBackBuffer; +}; + + +CMatRenderContextBase *CreateNullRenderContext() +{ + return new CMatNullRenderContext; +} diff --git a/materialsystem/cmatnullrendercontext.h b/materialsystem/cmatnullrendercontext.h new file mode 100644 index 0000000..6aac1f5 --- /dev/null +++ b/materialsystem/cmatnullrendercontext.h @@ -0,0 +1,18 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//============================================================================= + +#ifndef CMATNULLRENDERCONTEXT_H +#define CMATNULLRENDERCONTEXT_H + +#if defined( _WIN32 ) +#pragma once +#endif + +class CMatRenderContextBase; + +CMatRenderContextBase *CreateNullRenderContext(); + +#endif // CMATNULLRENDERCONTEXT_H diff --git a/materialsystem/cmatqueuedrendercontext.cpp b/materialsystem/cmatqueuedrendercontext.cpp new file mode 100644 index 0000000..47b10d5 --- /dev/null +++ b/materialsystem/cmatqueuedrendercontext.cpp @@ -0,0 +1,1753 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//============================================================================= + +#include "pch_materialsystem.h" + +#include "tier1/functors.h" +#include "itextureinternal.h" + +#define MATSYS_INTERNAL + +#include "cmatqueuedrendercontext.h" +#include "cmaterialsystem.h" // @HACKHACK + +// NOTE: This has to be the last file included! +#include "tier0/memdbgon.h" + + +ConVar mat_report_queue_status( "mat_report_queue_status", "0", FCVAR_MATERIAL_SYSTEM_THREAD ); + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- + +#if defined( _WIN32 ) +void FastCopy( byte *pDest, const byte *pSrc, size_t nBytes ) +{ + if ( !nBytes ) + { + return; + } + +#if !defined( _X360 ) + if ( (size_t)pDest % 16 == 0 && (size_t)pSrc % 16 == 0 ) + { + const int BYTES_PER_FULL = 128; + int nBytesFull = nBytes - ( nBytes % BYTES_PER_FULL ); + for ( byte *pLimit = pDest + nBytesFull; pDest < pLimit; pDest += BYTES_PER_FULL, pSrc += BYTES_PER_FULL ) + { + // memcpy( pDest, pSrc, BYTES_PER_FULL); + __asm + { + mov esi, pSrc + mov edi, pDest + + movaps xmm0, [esi + 0] + movaps xmm1, [esi + 16] + movaps xmm2, [esi + 32] + movaps xmm3, [esi + 48] + movaps xmm4, [esi + 64] + movaps xmm5, [esi + 80] + movaps xmm6, [esi + 96] + movaps xmm7, [esi + 112] + + movntps [edi + 0], xmm0 + movntps [edi + 16], xmm1 + movntps [edi + 32], xmm2 + movntps [edi + 48], xmm3 + movntps [edi + 64], xmm4 + movntps [edi + 80], xmm5 + movntps [edi + 96], xmm6 + movntps [edi + 112], xmm7 + } + } + nBytes -= nBytesFull; + } + + if ( nBytes ) + { + memcpy( pDest, pSrc, nBytes ); + } +#else + if ( (size_t)pDest % 4 == 0 && nBytes % 4 == 0 ) + { + XMemCpyStreaming_WriteCombined( pDest, pSrc, nBytes ); + } + else + { + // work around a bug in memcpy + if ((size_t)pDest % 2 == 0 && nBytes == 4) + { + *(reinterpret_cast(pDest)) = *(reinterpret_cast(pSrc)); + *(reinterpret_cast(pDest)+1) = *(reinterpret_cast(pSrc)+1); + } + else + { + memcpy( pDest, pSrc, nBytes ); + } + } +#endif +} +#else +#define FastCopy memcpy +#endif + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- + +enum MatQueuedMeshFlags_t +{ + MQM_BUFFERED = ( 1 << 0 ), + MQM_FLEX = ( 1 << 1 ), +}; + +class CMatQueuedMesh : public IMesh +{ +public: + CMatQueuedMesh( CMatQueuedRenderContext *pOwner, IMatRenderContextInternal *pHardwareContext ) + : m_pLateBoundMesh( &m_pActualMesh ), + m_pOwner( pOwner ), + m_pCallQueue( pOwner->GetCallQueueInternal() ), + m_pHardwareContext( pHardwareContext ), + m_pVertexData( NULL ), + m_pIndexData( NULL ), + m_nVerts( 0 ), + m_nIndices( 0 ), + m_VertexSize( 0 ), + m_Type(MATERIAL_TRIANGLES), + m_pVertexOverride( NULL ), + m_pIndexOverride ( NULL ), + m_pActualMesh( NULL ), + m_nActualVertexOffsetInBytes( 0 ), + m_VertexFormat( 0 ), + m_MorphFormat( 0 ) + { + } + + CLateBoundPtr &AccessLateBoundMesh() + { + return m_pLateBoundMesh; + } + + byte *GetVertexData() { return m_pVertexData; } + uint16 *GetIndexData() { return m_pIndexData; } + IMesh *DetachActualMesh() { IMesh *p = m_pActualMesh; m_pActualMesh = NULL; return p; } + IMesh *GetActualMesh() { return m_pActualMesh; } + int GetActualVertexOffsetInBytes() { return m_nActualVertexOffsetInBytes; } + + void DeferredGetDynamicMesh( VertexFormat_t vertexFormat, unsigned flags, IMesh* pVertexOverride, IMesh* pIndexOverride, IMaterialInternal *pMaterial ) + { + if ( !( flags & MQM_FLEX )) + { + if ( vertexFormat == 0 ) + { + m_pActualMesh = m_pHardwareContext->GetDynamicMesh( ( ( flags & MQM_BUFFERED ) != 0 ), pVertexOverride, pIndexOverride, pMaterial ); + } + else + { + m_pActualMesh = m_pHardwareContext->GetDynamicMeshEx( vertexFormat, ( ( flags & MQM_BUFFERED ) != 0 ), pVertexOverride, pIndexOverride, pMaterial ); + } + } + else + { + m_pActualMesh = m_pHardwareContext->GetFlexMesh(); + } + } + + bool OnGetDynamicMesh( VertexFormat_t vertexFormat, unsigned flags, IMesh* pVertexOverride, IMesh* pIndexOverride, IMaterialInternal *pMaterial, int nHWSkinBoneCount ) + { + if ( !m_pVertexOverride && ( m_pVertexData || m_pIndexData ) ) + { + CannotSupport(); + if ( IsDebug() ) + { + Assert( !"Getting a dynamic mesh without resolving the previous one" ); + } + else + { + Error( "Getting a dynamic mesh without resolving the previous one" ); + } + } + FreeBuffers(); + + m_pVertexOverride = pVertexOverride; + m_pIndexOverride = pIndexOverride; + + if ( !( flags & MQM_FLEX ) ) + { + if ( pVertexOverride ) + { + m_VertexFormat = pVertexOverride->GetVertexFormat(); + } + else + { + // Remove VERTEX_FORMAT_COMPRESSED from the material's format (dynamic meshes don't + // support compression, and all materials should support uncompressed verts too) + m_VertexFormat = ( vertexFormat == 0 ) ? ( pMaterial->GetVertexFormat() & ~VERTEX_FORMAT_COMPRESSED ) : vertexFormat; + + if ( vertexFormat != 0 ) + { + int nVertexFormatBoneWeights = NumBoneWeights( vertexFormat ); + if ( nHWSkinBoneCount < nVertexFormatBoneWeights ) + { + nHWSkinBoneCount = nVertexFormatBoneWeights; + } + } + // Force the requested number of bone weights + m_VertexFormat &= ~VERTEX_BONE_WEIGHT_MASK; + m_VertexFormat |= VERTEX_BONEWEIGHT( nHWSkinBoneCount ); + if ( nHWSkinBoneCount > 0 ) + { + m_VertexFormat |= VERTEX_BONE_INDEX; + } + } + } + else + { + m_VertexFormat = VERTEX_POSITION | VERTEX_NORMAL | VERTEX_FORMAT_USE_EXACT_FORMAT; + if ( g_pMaterialSystemHardwareConfig->SupportsPixelShaders_2_b() ) + { + m_VertexFormat |= VERTEX_WRINKLE; + } + } + + MeshDesc_t temp; + g_pShaderAPI->ComputeVertexDescription( 0, m_VertexFormat, temp ); + m_VertexSize = temp.m_ActualVertexSize; + + // queue up get of real dynamic mesh, allocate space for verts & indices + m_pCallQueue->QueueCall( this, &CMatQueuedMesh::DeferredGetDynamicMesh, vertexFormat, flags, pVertexOverride, pIndexOverride, pMaterial ); + return true; + } + + void ModifyBegin( int firstVertex, int numVerts, int firstIndex, int numIndices, MeshDesc_t& desc ) + { + CannotSupport(); + } + + void ModifyBeginEx( bool bReadOnly, int firstVertex, int numVerts, int firstIndex, int numIndices, MeshDesc_t& desc ) + { + CannotSupport(); + } + + void ModifyEnd( MeshDesc_t& desc ) + { + CannotSupport(); + } + + void GenerateSequentialIndexBuffer( unsigned short* pIndexMemory, int numIndices, int firstVertex ) + { + Assert( pIndexMemory == m_pIndexData ); + m_pCallQueue->QueueCall( &::GenerateSequentialIndexBuffer, pIndexMemory, numIndices, firstVertex ); + } + + void GenerateQuadIndexBuffer( unsigned short* pIndexMemory, int numIndices, int firstVertex ) + { + Assert( pIndexMemory == m_pIndexData ); + m_pCallQueue->QueueCall( &::GenerateQuadIndexBuffer, pIndexMemory, numIndices, firstVertex ); + } + + void GeneratePolygonIndexBuffer( unsigned short* pIndexMemory, int numIndices, int firstVertex ) + { + Assert( pIndexMemory == m_pIndexData ); + m_pCallQueue->QueueCall( &::GeneratePolygonIndexBuffer, pIndexMemory, numIndices, firstVertex ); + } + + void GenerateLineStripIndexBuffer( unsigned short* pIndexMemory, int numIndices, int firstVertex ) + { + Assert( pIndexMemory == m_pIndexData ); + m_pCallQueue->QueueCall( &::GenerateLineStripIndexBuffer, pIndexMemory, numIndices, firstVertex ); + } + + void GenerateLineLoopIndexBuffer( unsigned short* pIndexMemory, int numIndices, int firstVertex ) + { + Assert( pIndexMemory == m_pIndexData ); + m_pCallQueue->QueueCall( &::GenerateLineLoopIndexBuffer, pIndexMemory, numIndices, firstVertex ); + } + + int VertexCount() const + { + return m_VertexSize ? m_nVerts : 0; + } + + int IndexCount() const + { + return m_nIndices; + } + + int GetVertexSize() + { + return m_VertexSize; + } + + void SetPrimitiveType( MaterialPrimitiveType_t type ) + { + m_Type = type; + m_pCallQueue->QueueCall( m_pLateBoundMesh, &IMesh::SetPrimitiveType, type ); + } + + void SetColorMesh( IMesh *pColorMesh, int nVertexOffset ) + { + m_pCallQueue->QueueCall( m_pLateBoundMesh, &IMesh::SetColorMesh, pColorMesh, nVertexOffset ); + } + + void Draw( CPrimList *pLists, int nLists ) + { + CannotSupport(); + } + + void CopyToMeshBuilder( int iStartVert, int nVerts, int iStartIndex, int nIndices, int indexOffset, CMeshBuilder &builder ) + { + CannotSupport(); + } + + void Spew( int numVerts, int numIndices, const MeshDesc_t & desc ) + { + } + + void ValidateData( int numVerts, int numIndices, const MeshDesc_t & desc ) + { + } + + void LockMesh( int numVerts, int numIndices, MeshDesc_t& desc ) + { + if ( !m_pVertexOverride ) + { + m_nVerts = numVerts; + } + else + { + m_nVerts = 0; + } + + if ( !m_pIndexOverride ) + { + m_nIndices = numIndices; + } + else + { + m_nIndices = 0; + } + + if( numVerts > 0 ) + { + Assert( m_VertexSize ); + Assert( !m_pVertexData ); + m_pVertexData = (byte *)m_pOwner->AllocVertices( numVerts, m_VertexSize ); + Assert( (unsigned)m_pVertexData % 16 == 0 ); + + // Compute the vertex index.. + desc.m_nFirstVertex = 0; + static_cast< VertexDesc_t* >( &desc )->m_nOffset = 0; + // Set up the mesh descriptor + g_pShaderAPI->ComputeVertexDescription( m_pVertexData, m_VertexFormat, desc ); + } + else + { + desc.m_nFirstVertex = 0; + static_cast< VertexDesc_t* >( &desc )->m_nOffset = 0; + // Set up the mesh descriptor + g_pShaderAPI->ComputeVertexDescription( 0, 0, desc ); + } + + if ( m_Type != MATERIAL_POINTS && numIndices > 0 ) + { + Assert( !m_pIndexData ); + m_pIndexData = m_pOwner->AllocIndices( numIndices ); + desc.m_pIndices = m_pIndexData; + desc.m_nIndexSize = 1; + desc.m_nFirstIndex = 0; + static_cast< IndexDesc_t* >( &desc )->m_nOffset = 0; + } + else + { + desc.m_pIndices = &gm_ScratchIndexBuffer[0]; + desc.m_nIndexSize = 0; + desc.m_nFirstIndex = 0; + static_cast< IndexDesc_t* >( &desc )->m_nOffset = 0; + } + } + + void UnlockMesh( int numVerts, int numIndices, MeshDesc_t& desc ) + { + if ( m_pVertexData && numVerts < m_nVerts ) + { + m_pVertexData = m_pOwner->ReallocVertices( m_pVertexData, m_nVerts, numVerts, m_VertexSize ); + } + m_nVerts = numVerts; + + if ( m_pIndexData && numIndices < m_nIndices ) + { + m_pIndexData = m_pOwner->ReallocIndices( m_pIndexData, m_nIndices, numIndices ); + } + m_nIndices = numIndices; + } + + void SetFlexMesh( IMesh *pMesh, int nVertexOffset ) + { + m_pCallQueue->QueueCall( m_pLateBoundMesh, &IMesh::SetFlexMesh, pMesh, nVertexOffset ); + } + + void DisableFlexMesh() + { + m_pCallQueue->QueueCall( m_pLateBoundMesh, &IMesh::DisableFlexMesh ); + } + + void ExecuteDefferredBuild( byte *pVertexData, int nVerts, int nBytesVerts, uint16 *pIndexData, int nIndices ) + { + Assert( m_pActualMesh ); + MeshDesc_t desc; + m_pActualMesh->LockMesh( nVerts, nIndices, desc ); + m_nActualVertexOffsetInBytes = desc.m_nFirstVertex * desc.m_ActualVertexSize; + if ( pVertexData && desc.m_ActualVertexSize ) // if !desc.m_ActualVertexSize, device lost + { + void *pDest; + if ( desc.m_VertexSize_Position != 0 ) + { + pDest = desc.m_pPosition; + } + else + { + #define FindMin( desc, pCurrent, tag ) ( ( desc.m_VertexSize_##tag != 0 ) ? min( pCurrent, (void *)desc.m_p##tag ) : pCurrent ) + + pDest = (void *)(((byte *)0) - 1); + + pDest = FindMin( desc, pDest, BoneWeight ); + pDest = FindMin( desc, pDest, BoneMatrixIndex ); + pDest = FindMin( desc, pDest, Normal ); + pDest = FindMin( desc, pDest, Color ); + pDest = FindMin( desc, pDest, Specular ); + pDest = FindMin( desc, pDest, TangentS ); + pDest = FindMin( desc, pDest, TangentT ); + pDest = FindMin( desc, pDest, Wrinkle ); + + for ( int i = 0; i < VERTEX_MAX_TEXTURE_COORDINATES; i++ ) + { + if ( desc.m_VertexSize_TexCoord[i] && desc.m_pTexCoord < pDest ) + { + pDest = desc.m_pTexCoord; + } + } + + #undef FindMin + } + + Assert( pDest ); + if ( pDest ) + { + FastCopy( (byte *)pDest, pVertexData, nBytesVerts ); + } + } + + if ( pIndexData && pIndexData != &gm_ScratchIndexBuffer[0] && desc.m_nIndexSize ) + { + if ( !desc.m_nFirstVertex ) + { + // AssertMsg(desc.m_pIndices & 0x03 == 0,"desc.m_pIndices is misaligned in CMatQueuedMesh::ExecuteDefferedBuild\n"); + FastCopy( (byte *)desc.m_pIndices, (byte *)pIndexData, nIndices * sizeof(*pIndexData) ); + } + else + { + ALIGN16 uint16 tempIndices[16]; + + int i = 0; + if ( (size_t)desc.m_pIndices % 4 == 2 ) + { + desc.m_pIndices[i] = pIndexData[i] + desc.m_nFirstVertex; + i++; + } + while ( i < nIndices ) + { + int nToCopy = min( (int)ARRAYSIZE(tempIndices), nIndices - i ); + for ( int j = 0; j < nToCopy; j++ ) + { + tempIndices[j] = pIndexData[i+j] + desc.m_nFirstVertex; + } + FastCopy( (byte *)(desc.m_pIndices + i), (byte *)tempIndices, nToCopy * sizeof(uint16) ); + i += nToCopy; + } + } + } + + m_pActualMesh->UnlockMesh( nVerts, nIndices, desc ); + + if ( pIndexData && pIndexData != &gm_ScratchIndexBuffer[0]) + { + m_pOwner->FreeIndices( pIndexData, nIndices ); + } + if ( pVertexData ) + { + m_pOwner->FreeVertices( pVertexData, nVerts, desc.m_ActualVertexSize ); + } + } + + void QueueBuild( bool bDetachBuffers = true ) + { + m_pCallQueue->QueueCall( this, &CMatQueuedMesh::ExecuteDefferredBuild, m_pVertexData, m_nVerts, m_nVerts * m_VertexSize, m_pIndexData, m_nIndices ); + if ( bDetachBuffers ) + { + DetachBuffers(); + m_Type = MATERIAL_TRIANGLES; + } + } + + void Draw( int firstIndex = -1, int numIndices = 0 ) + { + if ( !m_nVerts && !m_nIndices ) + { + MarkAsDrawn(); + return; + } + + void (IMesh::*pfnDraw)( int, int) = &IMesh::Draw; // need assignment to disambiguate overloaded function + bool bDetachBuffers; + if ( firstIndex == -1 || numIndices == 0 ) + { + bDetachBuffers = true; + } + else if ( m_pIndexOverride ) + { + bDetachBuffers = ( firstIndex + numIndices == m_pIndexOverride->IndexCount() ); + } + else if ( !m_nIndices || firstIndex + numIndices == m_nIndices ) + { + bDetachBuffers = true; + } + else + { + bDetachBuffers = false; + } + + QueueBuild( bDetachBuffers ); + m_pCallQueue->QueueCall( m_pLateBoundMesh, pfnDraw, firstIndex, numIndices ); + } + + void MarkAsDrawn() + { + FreeBuffers(); + m_pCallQueue->QueueCall( m_pLateBoundMesh, &IMesh::MarkAsDrawn ); + } + + void FreeBuffers() + { + if ( m_pIndexData && m_pIndexData != &gm_ScratchIndexBuffer[0]) + { + m_pOwner->FreeIndices( m_pIndexData, m_nIndices ); + m_pIndexData = NULL; + } + if ( m_pVertexData ) + { + m_pOwner->FreeVertices( m_pVertexData, m_nVerts, m_VertexSize ); + m_pVertexData = NULL; + } + } + + void DetachBuffers() + { + m_pVertexData = NULL; + m_pIndexData = NULL; + } + + unsigned ComputeMemoryUsed() + { + return 0; + } + + virtual VertexFormat_t GetVertexFormat() const + { + return m_VertexFormat; + } + + virtual IMesh *GetMesh() + { + return this; + } + + // FIXME: Implement! + virtual bool Lock( int nMaxIndexCount, bool bAppend, IndexDesc_t& desc ) + { + Assert( 0 ); + return false; + } + virtual void Unlock( int nWrittenIndexCount, IndexDesc_t& desc ) + { + Assert( 0 ); + } + virtual void ModifyBegin( bool bReadOnly, int nFirstIndex, int nIndexCount, IndexDesc_t& desc ) + { + CannotSupport(); + } + void ModifyEnd( IndexDesc_t& desc ) + { + CannotSupport(); + } + virtual void Spew( int nIndexCount, const IndexDesc_t & desc ) + { + Assert( 0 ); + } + virtual void ValidateData( int nIndexCount, const IndexDesc_t &desc ) + { + Assert( 0 ); + } + virtual bool Lock( int nVertexCount, bool bAppend, VertexDesc_t &desc ) + { + Assert( 0 ); + return false; + } + virtual void Unlock( int nVertexCount, VertexDesc_t &desc ) + { + Assert( 0 ); + } + virtual void Spew( int nVertexCount, const VertexDesc_t &desc ) + { + Assert( 0 ); + } + virtual void ValidateData( int nVertexCount, const VertexDesc_t & desc ) + { + Assert( 0 ); + } + virtual bool IsDynamic() const + { + Assert( 0 ); + return false; + } + + virtual MaterialIndexFormat_t IndexFormat() const + { + Assert( 0 ); + return MATERIAL_INDEX_FORMAT_UNKNOWN; + } + + virtual void BeginCastBuffer( VertexFormat_t format ) + { + Assert( 0 ); + } + + virtual void BeginCastBuffer( MaterialIndexFormat_t format ) + { + Assert( 0 ); + } + + virtual void EndCastBuffer( ) + { + Assert( 0 ); + } + + // Returns the number of vertices that can still be written into the buffer + virtual int GetRoomRemaining() const + { + Assert( 0 ); + return 0; + } + + + //---------------------------------------------------------------------------- + + static void DoDraw( int firstIndex = -1, int numIndices = 0 ) + { + + } +private: + + IMesh *m_pActualMesh; + int m_nActualVertexOffsetInBytes; + + CLateBoundPtr m_pLateBoundMesh; + + CMatQueuedRenderContext *m_pOwner; + CMatCallQueue *m_pCallQueue; + IMatRenderContextInternal *m_pHardwareContext; + + //----------------------------------------------------- + + // The vertex format we're using... + VertexFormat_t m_VertexFormat; + + // The morph format we're using + MorphFormat_t m_MorphFormat; + + byte *m_pVertexData; + uint16 *m_pIndexData; + + int m_nVerts; + int m_nIndices; + + unsigned short m_VertexSize; + MaterialPrimitiveType_t m_Type; + + // Used in rendering sub-parts of the mesh + //static unsigned int s_NumIndices; + //static unsigned int s_FirstIndex; + + IMesh *m_pVertexOverride; + IMesh *m_pIndexOverride; + + static unsigned short gm_ScratchIndexBuffer[6]; +}; + +unsigned short CMatQueuedMesh::gm_ScratchIndexBuffer[6]; + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +bool CMatQueuedRenderContext::Init( CMaterialSystem *pMaterialSystem, CMatRenderContextBase *pHardwareContext ) +{ + BaseClass::Init(); + + m_pMaterialSystem = pMaterialSystem; + m_pHardwareContext = pHardwareContext; + + m_pQueuedMesh = new CMatQueuedMesh( this, pHardwareContext ); + + MEM_ALLOC_CREDIT(); + + int nSize = 16 * 1024 * 1024; + int nCommitSize = 128 * 1024; +#if defined(DEDICATED) + Assert( !"CMatQueuedRenderContext shouldn't be initialized on dedicated servers..." ); + nSize = nCommitSize = 1024; +#endif + + bool bVerticesInit = m_Vertices.Init( nSize, nCommitSize ); + bool bIndicesInit = m_Indices.Init( nSize, nCommitSize ); + + if ( !bVerticesInit || !bIndicesInit ) + { + return false; + } + + return true; +} + + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +void CMatQueuedRenderContext::Shutdown() +{ + if ( !m_pHardwareContext ) + { + return; + } + + Assert( !m_pCurrentMaterial ); + + delete m_pQueuedMesh; + m_pMaterialSystem = NULL; + m_pHardwareContext = NULL; + m_pQueuedMesh = NULL; + + m_Vertices.Term(); + m_Indices.Term(); + + BaseClass::Shutdown(); + Assert(m_queue.Count() == 0); +} + + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +void CMatQueuedRenderContext::Free() +{ + m_Vertices.FreeAll(); + m_Indices.FreeAll(); +} + + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +void CMatQueuedRenderContext::CompactMemory() +{ + BaseClass::CompactMemory(); + m_Vertices.FreeAll(); + m_Indices.FreeAll(); +} + + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +void CMatQueuedRenderContext::BeginQueue( CMatRenderContextBase *pInitialState ) +{ + if ( !pInitialState ) + { + pInitialState = m_pHardwareContext; + } + CMatRenderContextBase::InitializeFrom( pInitialState ); + g_pShaderAPI->GetBackBufferDimensions( m_WidthBackBuffer, m_HeightBackBuffer ); + m_FogMode = pInitialState->GetFogMode(); + m_nBoneCount = pInitialState->GetCurrentNumBones(); + pInitialState->GetFogDistances( &m_flFogStart, &m_flFogEnd, &m_flFogZ ); + +} + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +void CMatQueuedRenderContext::EndQueue( bool bCallQueued ) +{ + if ( bCallQueued ) + { + CallQueued(); + } + int i; + + if ( m_pCurrentMaterial ) + { + m_pCurrentMaterial = NULL; + } + + if ( m_pUserDefinedLightmap ) + { + m_pUserDefinedLightmap = NULL; + } + + if ( m_pLocalCubemapTexture ) + { + m_pLocalCubemapTexture = NULL; + } + + for ( i = 0; i < MAX_FB_TEXTURES; i++ ) + { + if ( m_pCurrentFrameBufferCopyTexture[i] ) + { + m_pCurrentFrameBufferCopyTexture[i] = NULL; + } + } + + for ( i = 0; i < m_RenderTargetStack.Count(); i++ ) + { + for ( int j = 0; j < MAX_RENDER_TARGETS; j++ ) + { + if ( m_RenderTargetStack[i].m_pRenderTargets[j] ) + { + m_RenderTargetStack[i].m_pRenderTargets[j] = NULL; + } + } + } + + m_RenderTargetStack.Clear(); +} + + +void CMatQueuedRenderContext::Bind( IMaterial *iMaterial, void *proxyData ) +{ + if ( !iMaterial ) + { + if( !g_pErrorMaterial ) + return; + } + else + { + iMaterial = ((IMaterialInternal *)iMaterial)->GetRealTimeVersion(); //always work with the real time versions of materials internally + } + + CMatRenderContextBase::Bind( iMaterial, proxyData ); + + // We've always gotta call the bind proxy (assuming there is one) + // so we can copy off the material vars at this point. + IMaterialInternal* pIMaterial = GetCurrentMaterialInternal(); + pIMaterial->CallBindProxy( proxyData ); + + m_queue.QueueCall( m_pHardwareContext, &IMatRenderContext::Bind, iMaterial, proxyData ); +} + + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +void CMatQueuedRenderContext::BeginRender() +{ + if ( ++m_iRenderDepth == 1 ) + { + VPROF_INCREMENT_GROUP_COUNTER( "render/CMatQBeginRender", COUNTER_GROUP_TELEMETRY, 1 ); + + m_queue.QueueCall( m_pHardwareContext, &IMatRenderContext::BeginRender ); + } +} + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +void CMatQueuedRenderContext::EndRender() +{ + if ( --m_iRenderDepth == 0 ) + { + m_queue.QueueCall( m_pHardwareContext, &IMatRenderContext::EndRender ); + } +} + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +void CMatQueuedRenderContext::CallQueued( bool bTermAfterCall ) +{ + if ( mat_report_queue_status.GetBool() ) + { + Msg( "%d calls queued for %llu bytes in parameters and overhead, %d bytes verts, %d bytes indices, %d bytes other\n", m_queue.Count(), (uint64)(m_queue.GetMemoryUsed()), m_Vertices.GetUsed(), m_Indices.GetUsed(), RenderDataSizeUsed() ); + } + + m_queue.CallQueued(); + + m_Vertices.FreeAll( false ); + m_Indices.FreeAll( false ); + + if ( bTermAfterCall ) + { + Shutdown(); + } +} + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +void CMatQueuedRenderContext::FlushQueued() +{ + m_queue.Flush(); +} + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +ICallQueue *CMatQueuedRenderContext::GetCallQueue() +{ + return &m_CallQueueExternal; +} + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +void CMatQueuedRenderContext::SetRenderTargetEx( int nRenderTargetID, ITexture *pNewTarget ) +{ + CMatRenderContextBase::SetRenderTargetEx( nRenderTargetID, pNewTarget ); + + m_queue.QueueCall( m_pHardwareContext, &IMatRenderContext::SetRenderTargetEx, nRenderTargetID, pNewTarget ); +} + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +void CMatQueuedRenderContext::GetRenderTargetDimensions( int &width, int &height) const +{ + // Target at top of stack + ITexture *pTOS = NULL; + + if ( m_RenderTargetStack.Count() ) + { + pTOS = m_RenderTargetStack.Top().m_pRenderTargets[ 0 ]; + } + + // If top of stack isn't the back buffer, get dimensions from the texture + if ( pTOS != NULL ) + { + width = pTOS->GetActualWidth(); + height = pTOS->GetActualHeight(); + } + else // otherwise, get them from the shader API + { + width = m_WidthBackBuffer; + height = m_HeightBackBuffer; + } +} + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +void CMatQueuedRenderContext::Viewport( int x, int y, int width, int height ) +{ + CMatRenderContextBase::Viewport( x, y, width, height ); + m_queue.QueueCall( m_pHardwareContext, &IMatRenderContext::Viewport, x, y, width, height ); +} + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +void CMatQueuedRenderContext::SetLight( int i, const LightDesc_t &desc ) +{ + m_queue.QueueCall( m_pHardwareContext, &IMatRenderContext::SetLight, i, RefToVal( desc ) ); +} + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +void CMatQueuedRenderContext::SetLightingOrigin( Vector vLightingOrigin ) +{ + m_queue.QueueCall( m_pHardwareContext, &IMatRenderContext::SetLightingOrigin, vLightingOrigin ); +} + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +void CMatQueuedRenderContext::SetAmbientLightCube( LightCube_t cube ) +{ + // FIXME: does compiler do the right thing, is envelope needed? + m_queue.QueueCall( m_pHardwareContext, &IMatRenderContext::SetAmbientLightCube, CUtlEnvelope( &cube[0], 6 ) ); +} + +//----------------------------------------------------------------------------- +// Bone count +//----------------------------------------------------------------------------- +void CMatQueuedRenderContext::SetNumBoneWeights( int nBoneCount ) +{ + m_nBoneCount = nBoneCount; + m_queue.QueueCall( m_pHardwareContext, &IMatRenderContext::SetNumBoneWeights, nBoneCount ); +} + +int CMatQueuedRenderContext::GetCurrentNumBones( ) const +{ + return m_nBoneCount; +} + + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +void CMatQueuedRenderContext::FogMode( MaterialFogMode_t fogMode ) +{ + m_FogMode = fogMode; + m_queue.QueueCall( m_pHardwareContext, &IMatRenderContext::FogMode, fogMode ); +} + +void CMatQueuedRenderContext::FogStart( float fStart ) +{ + m_flFogStart = fStart; + m_queue.QueueCall( m_pHardwareContext, &IMatRenderContext::FogStart, fStart ); +} + +void CMatQueuedRenderContext::FogEnd( float fEnd ) +{ + m_flFogEnd = fEnd; + m_queue.QueueCall( m_pHardwareContext, &IMatRenderContext::FogEnd, fEnd ); +} + +void CMatQueuedRenderContext::FogMaxDensity( float flMaxDensity ) +{ + m_flFogMaxDensity = flMaxDensity; + m_queue.QueueCall( m_pHardwareContext, &IMatRenderContext::FogMaxDensity, flMaxDensity ); +} + +void CMatQueuedRenderContext::SetFogZ( float fogZ ) +{ + m_flFogZ = fogZ; + m_queue.QueueCall( m_pHardwareContext, &IMatRenderContext::SetFogZ, fogZ ); +} + +MaterialFogMode_t CMatQueuedRenderContext::GetFogMode( void ) +{ + return m_FogMode; +} + +void CMatQueuedRenderContext::FogColor3f( float r, float g, float b ) +{ + FogColor3ub( clamp( (int)(r * 255.0f), 0, 255 ), clamp( (int)(g * 255.0f), 0, 255 ), clamp( (int)(b * 255.0f), 0, 255 ) ); +} + +void CMatQueuedRenderContext::FogColor3fv( float const* rgb ) +{ + FogColor3ub( clamp( (int)(rgb[0] * 255.0f), 0, 255 ), clamp( (int)(rgb[1] * 255.0f), 0, 255 ), clamp( (int)(rgb[2] * 255.0f), 0, 255 ) ); +} + +void CMatQueuedRenderContext::FogColor3ub( unsigned char r, unsigned char g, unsigned char b ) +{ + m_FogColor.r = r; + m_FogColor.g = g; + m_FogColor.b = b; + m_queue.QueueCall( m_pHardwareContext, &IMatRenderContext::FogColor3ub, r, g, b ); +} + +void CMatQueuedRenderContext::FogColor3ubv( unsigned char const* rgb ) +{ + FogColor3ub( rgb[0], rgb[1], rgb[2] ); +} + +void CMatQueuedRenderContext::GetFogColor( unsigned char *rgb ) +{ + rgb[0] = m_FogColor.r; + rgb[1] = m_FogColor.g; + rgb[2] = m_FogColor.b; +} + +void CMatQueuedRenderContext::GetFogDistances( float *fStart, float *fEnd, float *fFogZ ) +{ + if( fStart ) + *fStart = m_flFogStart; + + if( fEnd ) + *fEnd = m_flFogEnd; + + if( fFogZ ) + *fFogZ = m_flFogZ; +} + + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +void CMatQueuedRenderContext::GetViewport( int& x, int& y, int& width, int& height ) const +{ + // Verify valid top of RT stack + Assert ( m_RenderTargetStack.Count() > 0 ); + + // Grab the top of stack + const RenderTargetStackElement_t& element = m_RenderTargetStack.Top(); + + // If either dimension is negative, set to full bounds of current target + if ( (element.m_nViewW < 0) || (element.m_nViewH < 0) ) + { + // Viewport origin at target origin + x = y = 0; + + // If target is back buffer + if ( element.m_pRenderTargets[0] == NULL ) + { + width = m_WidthBackBuffer; + height = m_HeightBackBuffer; + } + else // if target is texture + { + width = element.m_pRenderTargets[0]->GetActualWidth(); + height = element.m_pRenderTargets[0]->GetActualHeight(); + } + } + else // use the bounds from the stack directly + { + x = element.m_nViewX; + y = element.m_nViewY; + width = element.m_nViewW; + height = element.m_nViewH; + } +} + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +void CMatQueuedRenderContext::SyncToken( const char *p ) +{ + m_queue.QueueCall( m_pHardwareContext, &IMatRenderContext::SyncToken, CUtlEnvelope( p ) ); +} + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +IMesh* CMatQueuedRenderContext::GetDynamicMesh( bool buffered, IMesh* pVertexOverride, IMesh* pIndexOverride, IMaterial *pAutoBind ) +{ + if( pAutoBind ) + Bind( pAutoBind, NULL ); + + if ( pVertexOverride && pIndexOverride ) + { + // Use the new batch API + DebuggerBreak(); + return NULL; + } + + if ( pVertexOverride ) + { + if ( CompressionType( pVertexOverride->GetVertexFormat() ) != VERTEX_COMPRESSION_NONE ) + { + // UNDONE: support compressed dynamic meshes if needed (pro: less VB memory, con: time spent compressing) + DebuggerBreak(); + return NULL; + } + } + + // For anything more than 1 bone, imply the last weight from the 1 - the sum of the others. + int nCurrentBoneCount = GetCurrentNumBones(); + Assert( nCurrentBoneCount <= 4 ); + if ( nCurrentBoneCount > 1 ) + { + --nCurrentBoneCount; + } + + m_pQueuedMesh->OnGetDynamicMesh( 0, ( buffered ) ? MQM_BUFFERED : 0, pVertexOverride, pIndexOverride, GetCurrentMaterialInternal(), nCurrentBoneCount ); + return m_pQueuedMesh; +} + +IMesh* CMatQueuedRenderContext::GetDynamicMeshEx( VertexFormat_t vertexFormat, bool bBuffered, IMesh* pVertexOverride, IMesh* pIndexOverride, IMaterial *pAutoBind ) +{ + if( pAutoBind ) + { + Bind( pAutoBind, NULL ); + } + + if ( pVertexOverride && pIndexOverride ) + { + // Use the new batch API + DebuggerBreak(); + return NULL; + } + + if ( pVertexOverride ) + { + if ( CompressionType( pVertexOverride->GetVertexFormat() ) != VERTEX_COMPRESSION_NONE ) + { + // UNDONE: support compressed dynamic meshes if needed (pro: less VB memory, con: time spent compressing) + DebuggerBreak(); + return NULL; + } + } + + // For anything more than 1 bone, imply the last weight from the 1 - the sum of the others. + int nCurrentBoneCount = GetCurrentNumBones(); + Assert( nCurrentBoneCount <= 4 ); + if ( nCurrentBoneCount > 1 ) + { + --nCurrentBoneCount; + } + + m_pQueuedMesh->OnGetDynamicMesh( vertexFormat, ( bBuffered ) ? MQM_BUFFERED : 0, pVertexOverride, pIndexOverride, GetCurrentMaterialInternal(), nCurrentBoneCount ); + return m_pQueuedMesh; +} + + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +int CMatQueuedRenderContext::GetMaxVerticesToRender( IMaterial *pMaterial ) +{ + pMaterial = ((IMaterialInternal *)pMaterial)->GetRealTimeVersion(); //always work with the real time version of materials internally. + + MeshDesc_t temp; + + // Be conservative, assume no compression (in here, we don't know if the caller will used a compressed VB or not) + // FIXME: allow the caller to specify which compression type should be used to compute size from the vertex format + // (this can vary between multiple VBs/Meshes using the same material) + VertexFormat_t materialFormat = pMaterial->GetVertexFormat() & ~VERTEX_FORMAT_COMPRESSED; + g_pShaderAPI->ComputeVertexDescription( 0, materialFormat, temp ); + + int maxVerts = g_pShaderAPI->GetCurrentDynamicVBSize() / temp.m_ActualVertexSize; + if ( maxVerts > 65535 ) + { + maxVerts = 65535; + } + return maxVerts; +} + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +void CMatQueuedRenderContext::GetMaxToRender( IMesh *pMesh, bool bMaxUntilFlush, int *pMaxVerts, int *pMaxIndices ) +{ + Assert( !bMaxUntilFlush ); + *pMaxVerts = g_pShaderAPI->GetCurrentDynamicVBSize() / m_pQueuedMesh->GetVertexSize(); + if ( *pMaxVerts > 65535 ) + { + *pMaxVerts = 65535; + } + *pMaxIndices = INDEX_BUFFER_SIZE; +} + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +IMesh *CMatQueuedRenderContext::GetFlexMesh() +{ + m_pQueuedMesh->OnGetDynamicMesh( 0, MQM_FLEX, NULL, NULL, NULL, 0 ); + return m_pQueuedMesh; +} + + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +OcclusionQueryObjectHandle_t CMatQueuedRenderContext::CreateOcclusionQueryObject() +{ + OcclusionQueryObjectHandle_t h = g_pOcclusionQueryMgr->CreateOcclusionQueryObject(); + m_queue.QueueCall( g_pOcclusionQueryMgr, &COcclusionQueryMgr::OnCreateOcclusionQueryObject, h ); + return h; +} + +int CMatQueuedRenderContext::OcclusionQuery_GetNumPixelsRendered( OcclusionQueryObjectHandle_t h ) +{ + m_queue.QueueCall( g_pOcclusionQueryMgr, &COcclusionQueryMgr::OcclusionQuery_IssueNumPixelsRenderedQuery, h ); + return g_pOcclusionQueryMgr->OcclusionQuery_GetNumPixelsRendered( h, false ); +} + + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +void CMatQueuedRenderContext::SetFlashlightState( const FlashlightState_t &s, const VMatrix &m ) +{ + m_queue.QueueCall( m_pHardwareContext, &IMatRenderContext::SetFlashlightState, RefToVal( s ), RefToVal( m ) ); +} + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +bool CMatQueuedRenderContext::EnableClipping( bool bEnable ) +{ + m_queue.QueueCall( m_pHardwareContext, &IMatRenderContext::EnableClipping, bEnable ); + return BaseClass::EnableClipping( bEnable ); +} + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +void CMatQueuedRenderContext::UserClipTransform( const VMatrix &m ) +{ + m_queue.QueueCall( m_pHardwareContext, &IMatRenderContext::UserClipTransform, RefToVal( m ) ); +} + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +void CMatQueuedRenderContext::GetWindowSize( int &width, int &height ) const +{ + width = m_WidthBackBuffer; + height = m_HeightBackBuffer; +} + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +void CMatQueuedRenderContext::DrawScreenSpaceRectangle( + IMaterial *pMaterial, + int destx, int desty, + int width, int height, + float src_texture_x0, float src_texture_y0, // which texel you want to appear at + // destx/y + float src_texture_x1, float src_texture_y1, // which texel you want to appear at + // destx+width-1, desty+height-1 + int src_texture_width, int src_texture_height, // needed for fixup + void *pClientRenderable, + int nXDice, int nYDice ) // Amount to tessellate the quad +{ + IMaterial *pRealTimeVersionMaterial = ((IMaterialInternal *)pMaterial)->GetRealTimeVersion(); + pRealTimeVersionMaterial->CallBindProxy( pClientRenderable ); + m_queue.QueueCall( m_pHardwareContext, &IMatRenderContext::DrawScreenSpaceRectangle, pMaterial, destx, desty, width, height, src_texture_x0, src_texture_y0, src_texture_x1, src_texture_y1, src_texture_width, src_texture_height, pClientRenderable, nXDice, nYDice ); +} + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +void CMatQueuedRenderContext::LoadBoneMatrix( int i, const matrix3x4_t &m ) +{ + m_queue.QueueCall( m_pHardwareContext, &IMatRenderContext::LoadBoneMatrix, i, RefToVal( m ) ); +} + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +void CMatQueuedRenderContext::CopyRenderTargetToTextureEx( ITexture *pTexture, int i, Rect_t *pSrc, Rect_t *pDst ) +{ + m_queue.QueueCall( m_pHardwareContext, &IMatRenderContext::CopyRenderTargetToTextureEx, pTexture, i, CUtlEnvelope(pSrc), CUtlEnvelope(pDst) ); +} + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +void CMatQueuedRenderContext::CopyTextureToRenderTargetEx( int i, ITexture *pTexture, Rect_t *pSrc, Rect_t *pDst ) +{ + m_queue.QueueCall( m_pHardwareContext, &IMatRenderContext::CopyTextureToRenderTargetEx, i, pTexture, CUtlEnvelope(pSrc), CUtlEnvelope(pDst) ); +} + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +bool CMatQueuedRenderContext::OnDrawMesh( IMesh *pMesh, int firstIndex, int numIndices ) +{ + void (IMesh::*pfnDraw)( int, int) = &IMesh::Draw; // need assignment to disambiguate overloaded function + m_queue.QueueCall( pMesh, pfnDraw, firstIndex, numIndices ); + return false; +} + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +bool CMatQueuedRenderContext::OnDrawMesh( IMesh *pMesh, CPrimList *pLists, int nLists ) +{ + CMatRenderData< CPrimList > rdPrimList( this, nLists, pLists ); + m_queue.QueueCall( this, &CMatQueuedRenderContext::DeferredDrawPrimList, pMesh, rdPrimList.Base(), nLists ); + return false; +} + +void CMatQueuedRenderContext::DeferredDrawPrimList( IMesh *pMesh, CPrimList *pLists, int nLists ) +{ + pMesh->Draw( pLists, nLists ); +} + + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +void CMatQueuedRenderContext::DeferredSetFlexMesh( IMesh *pStaticMesh, int nVertexOffsetInBytes ) +{ + pStaticMesh->SetFlexMesh( m_pQueuedMesh->GetActualMesh(), m_pQueuedMesh->GetActualVertexOffsetInBytes() ); +} + +bool CMatQueuedRenderContext::OnSetFlexMesh( IMesh *pStaticMesh, IMesh *pMesh, int nVertexOffsetInBytes ) +{ + Assert( pMesh == m_pQueuedMesh || !pMesh ); + if ( pMesh ) + { + m_pQueuedMesh->QueueBuild(); + m_queue.QueueCall( this, &CMatQueuedRenderContext::DeferredSetFlexMesh, pStaticMesh, nVertexOffsetInBytes ); + } + else + { + m_queue.QueueCall( pStaticMesh, &IMesh::SetFlexMesh, (IMesh *)NULL, 0 ); + } + return false; +} + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +bool CMatQueuedRenderContext::OnSetColorMesh( IMesh *pStaticMesh, IMesh *pMesh, int nVertexOffsetInBytes ) +{ + m_queue.QueueCall( pStaticMesh, &IMesh::SetColorMesh, pMesh, nVertexOffsetInBytes ); + return false; +} + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +bool CMatQueuedRenderContext::OnSetPrimitiveType( IMesh *pMesh, MaterialPrimitiveType_t type ) +{ + m_queue.QueueCall( pMesh, &IMesh::SetPrimitiveType, type ); + return false; +} + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +bool CMatQueuedRenderContext::OnFlushBufferedPrimitives() +{ + m_queue.QueueCall( g_pShaderAPI, &IShaderAPI::FlushBufferedPrimitives ); + return false; +} + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +inline void CMatQueuedRenderContext::QueueMatrixSync() +{ + void (IMatRenderContext::*pfnLoadMatrix)( const VMatrix & ) = &IMatRenderContext::LoadMatrix; // need assignment to disambiguate overloaded function + m_queue.QueueCall( m_pHardwareContext, pfnLoadMatrix, RefToVal( AccessCurrentMatrix() ) ); +} + +void CMatQueuedRenderContext::MatrixMode( MaterialMatrixMode_t mode ) +{ + CMatRenderContextBase::MatrixMode( mode ); + m_queue.QueueCall( m_pHardwareContext, &IMatRenderContext::MatrixMode, mode ); +} + +void CMatQueuedRenderContext::PushMatrix() +{ + CMatRenderContextBase::PushMatrix(); + m_queue.QueueCall( m_pHardwareContext, &IMatRenderContext::PushMatrix ); +} + +void CMatQueuedRenderContext::PopMatrix() +{ + CMatRenderContextBase::PopMatrix(); + m_queue.QueueCall( m_pHardwareContext, &IMatRenderContext::PopMatrix ); +} + +void CMatQueuedRenderContext::LoadMatrix( const VMatrix& matrix ) +{ + CMatRenderContextBase::LoadMatrix( matrix ); + QueueMatrixSync(); +} + +void CMatQueuedRenderContext::LoadMatrix( const matrix3x4_t& matrix ) +{ + CMatRenderContextBase::LoadMatrix( matrix ); + QueueMatrixSync(); +} + +void CMatQueuedRenderContext::MultMatrix( const VMatrix& matrix ) +{ + CMatRenderContextBase::MultMatrix( matrix ); + QueueMatrixSync(); +} + +void CMatQueuedRenderContext::MultMatrix( const matrix3x4_t& matrix ) +{ + CMatRenderContextBase::MultMatrix( VMatrix( matrix ) ); + QueueMatrixSync(); +} + +void CMatQueuedRenderContext::MultMatrixLocal( const VMatrix& matrix ) +{ + CMatRenderContextBase::MultMatrixLocal( matrix ); + QueueMatrixSync(); +} + +void CMatQueuedRenderContext::MultMatrixLocal( const matrix3x4_t& matrix ) +{ + CMatRenderContextBase::MultMatrixLocal( VMatrix( matrix ) ); + QueueMatrixSync(); +} + +void CMatQueuedRenderContext::LoadIdentity() +{ + CMatRenderContextBase::LoadIdentity(); + m_queue.QueueCall( m_pHardwareContext, &IMatRenderContext::LoadIdentity ); +} + +void CMatQueuedRenderContext::Ortho( double left, double top, double right, double bottom, double zNear, double zFar ) +{ + CMatRenderContextBase::Ortho( left, top, right, bottom, zNear, zFar ); + QueueMatrixSync(); +} + +void CMatQueuedRenderContext::PerspectiveX( double flFovX, double flAspect, double flZNear, double flZFar ) +{ + CMatRenderContextBase::PerspectiveX( flFovX, flAspect, flZNear, flZFar ); + QueueMatrixSync(); +} + +void CMatQueuedRenderContext::PerspectiveOffCenterX( double flFovX, double flAspect, double flZNear, double flZFar, double bottom, double top, double left, double right ) +{ + CMatRenderContextBase::PerspectiveOffCenterX( flFovX, flAspect, flZNear, flZFar, bottom, top, left, right ); + QueueMatrixSync(); +} + +void CMatQueuedRenderContext::PickMatrix( int x, int y, int nWidth, int nHeight ) +{ + CMatRenderContextBase::PickMatrix( x, y, nWidth, nHeight ); + QueueMatrixSync(); +} + +void CMatQueuedRenderContext::Rotate( float flAngle, float x, float y, float z ) +{ + CMatRenderContextBase::Rotate( flAngle, x, y, z ); + QueueMatrixSync(); +} + +void CMatQueuedRenderContext::Translate( float x, float y, float z ) +{ + CMatRenderContextBase::Translate( x, y, z ); + QueueMatrixSync(); +} + +void CMatQueuedRenderContext::Scale( float x, float y, float z ) +{ + CMatRenderContextBase::Scale( x, y, z ); + QueueMatrixSync(); +} + +void CMatQueuedRenderContext::BeginBatch( IMesh* pIndices ) +{ + Assert( pIndices == (IMesh *)m_pQueuedMesh ); + m_queue.QueueCall( this, &CMatQueuedRenderContext::DeferredBeginBatch, m_pQueuedMesh->GetIndexData(), m_pQueuedMesh->IndexCount() ); + m_pQueuedMesh->DetachBuffers(); +} + +void CMatQueuedRenderContext::BindBatch( IMesh* pVertices, IMaterial *pAutoBind ) +{ + Assert( pVertices != (IMesh *)m_pQueuedMesh ); + m_queue.QueueCall( m_pHardwareContext, &IMatRenderContext::BindBatch, pVertices, pAutoBind ); +} + +void CMatQueuedRenderContext::DrawBatch(int firstIndex, int numIndices ) +{ + m_queue.QueueCall( m_pHardwareContext, &IMatRenderContext::DrawBatch, firstIndex, numIndices ); +} + +void CMatQueuedRenderContext::EndBatch() +{ + m_queue.QueueCall( m_pHardwareContext, &IMatRenderContext::EndBatch ); +} + +void CMatQueuedRenderContext::DeferredBeginBatch( uint16 *pIndexData, int nIndices ) +{ + m_pQueuedMesh->DeferredGetDynamicMesh( 0, false, NULL, NULL, NULL ); + m_pQueuedMesh->ExecuteDefferredBuild( NULL, 0, 0, pIndexData, nIndices ); + m_pHardwareContext->BeginBatch( m_pQueuedMesh->DetachActualMesh() ); +} + +//----------------------------------------------------------------------------- +// Memory allocation calls for queued mesh, et. al. +//----------------------------------------------------------------------------- +byte *CMatQueuedRenderContext::AllocVertices( int nVerts, int nVertexSize ) +{ + MEM_ALLOC_CREDIT(); + +#if defined(_WIN32) && !defined(_X360) + const byte *pNextAlloc = (const byte *)(m_Vertices.GetBase()) + m_Vertices.GetUsed() + AlignValue( nVerts * nVertexSize, 16 ); + const byte *pCommitLimit = (const byte *)(m_Vertices.GetBase()) + m_Vertices.GetSize(); +#endif + + void *pResult = m_Vertices.Alloc( nVerts * nVertexSize, false ); +#if defined(_WIN32) && !defined(_X360) + if ( !pResult ) + { + // Force a crash with useful minidump info in the registers. + uint64 status = 0x31415926; + + // Print some information to the console so that it's picked up in the minidump comment. + Msg( "AllocVertices( %d, %d ) on %p failed. m_Vertices is based at %p with a size of 0x%x.\n", nVerts, nVertexSize, this, m_Vertices.GetBase(), m_Vertices.GetSize() ); + Msg( "%d vertices used.\n", m_Vertices.GetUsed() ); + if ( pNextAlloc > pCommitLimit ) + { + Msg( "VirtualAlloc would have been called. %p > %p.\n", pNextAlloc, pCommitLimit ); + + const byte *pNewCommitLimit = AlignValue( pNextAlloc, 128 * 1024 ); + const uint32 commitSize = pNewCommitLimit - pCommitLimit; + const void *pRet = VirtualAlloc( (void *)pCommitLimit, commitSize, MEM_COMMIT, PAGE_READWRITE ); + if ( !pRet ) + status = GetLastError(); + + Msg( "VirtualAlloc( %p, %d ) returned %p on repeat. VirtualAlloc %s with code %x.\n", pCommitLimit, commitSize, pRet, (pRet != NULL) ? "succeeded" : "failed", (uint32) status ); + } + else + { + Msg( "VirtualAlloc would not have been called. %p <= %p.\n", pNextAlloc, pCommitLimit ); + } + + // Now crash. + *(volatile uint64 *)0 = status << 32 | m_Vertices.GetUsed(); + } +#endif + return (byte *) pResult; +} + +uint16 *CMatQueuedRenderContext::AllocIndices( int nIndices ) +{ + MEM_ALLOC_CREDIT(); + +#if defined(_WIN32) && !defined(_X360) + const byte *pNextAlloc = (const byte *)(m_Indices.GetBase()) + m_Indices.GetUsed() + AlignValue( nIndices * sizeof(uint16), 16 ); + const byte *pCommitLimit = (const byte *)(m_Indices.GetBase()) + m_Indices.GetSize(); +#endif + + void *pResult = m_Indices.Alloc( nIndices * sizeof(uint16), false ); +#if defined(_WIN32) && !defined(_X360) + if ( !pResult ) + { + // Force a crash with useful minidump info in the registers. + uint64 status = 0x31415926; + + // Print some information to the console so that it's picked up in the minidump comment. + Msg( "AllocIndices( %d ) on %p failed. m_Indices is based at %p with a size of 0x%x.\n", nIndices, this, m_Indices.GetBase(), m_Indices.GetSize() ); + Msg( "%d indices used.\n", m_Indices.GetUsed() ); + if ( pNextAlloc > pCommitLimit ) + { + Msg( "VirtualAlloc would have been called. %p > %p.\n", pNextAlloc, pCommitLimit ); + + const byte *pNewCommitLimit = AlignValue( pNextAlloc, 128 * 1024 ); + const uint32 commitSize = pNewCommitLimit - pCommitLimit; + const void *pRet = VirtualAlloc( (void *)pCommitLimit, commitSize, MEM_COMMIT, PAGE_READWRITE ); + if ( !pRet ) + status = GetLastError(); + + Msg( "VirtualAlloc( %p, %d ) returned %p on repeat. VirtualAlloc %s with code %x.\n", pCommitLimit, commitSize, pRet, (pRet != NULL) ? "succeeded" : "failed", (uint32) status ); + } + else + { + Msg( "VirtualAlloc would not have been called. %p <= %p.\n", pNextAlloc, pCommitLimit ); + } + + // Now crash. + *(volatile uint64 *)0 = status << 32 | m_Indices.GetUsed(); + } +#endif + return (uint16 *) pResult; +} + +byte *CMatQueuedRenderContext::ReallocVertices( byte *pVerts, int nVertsOld, int nVertsNew, int nVertexSize ) +{ + Assert( nVertsNew <= nVertsOld ); + + if ( nVertsNew < nVertsOld ) + { + unsigned nBytes = ( ( nVertsOld - nVertsNew ) * nVertexSize ); + m_Vertices.FreeToAllocPoint( AlignValue( m_Vertices.GetCurrentAllocPoint() - nBytes, 16), false ); // memstacks 128 bit aligned + } + return pVerts; +} + +uint16 *CMatQueuedRenderContext::ReallocIndices( uint16 *pIndices, int nIndicesOld, int nIndicesNew ) +{ + Assert( nIndicesNew <= nIndicesOld ); + if ( nIndicesNew < nIndicesOld ) + { + unsigned nBytes = ( ( nIndicesOld - nIndicesNew ) * sizeof(uint16) ); + m_Indices.FreeToAllocPoint( AlignValue( m_Indices.GetCurrentAllocPoint() - nBytes, 16 ), false ); // memstacks 128 bit aligned + } + return pIndices; +} + +void CMatQueuedRenderContext::FreeVertices( byte *pVerts, int nVerts, int nVertexSize ) +{ + // free at end of call dispatch +} + +void CMatQueuedRenderContext::FreeIndices( uint16 *pIndices, int nIndices ) +{ + // free at end of call dispatch +} + + + +//------------------------------------------------------------------------------ +// Color correction related methods +//------------------------------------------------------------------------------ +ColorCorrectionHandle_t CMatQueuedRenderContext::AddLookup( const char *pName ) +{ + MaterialLock_t hLock = m_pMaterialSystem->Lock(); + ColorCorrectionHandle_t hCC = ColorCorrectionSystem()->AddLookup( pName ); + m_pMaterialSystem->Unlock( hLock ); + return hCC; +} + +bool CMatQueuedRenderContext::RemoveLookup( ColorCorrectionHandle_t handle ) +{ + MaterialLock_t hLock = m_pMaterialSystem->Lock(); + bool bRemoved = ColorCorrectionSystem()->RemoveLookup( handle ); + m_pMaterialSystem->Unlock( hLock ); + return bRemoved; +} + +void CMatQueuedRenderContext::LockLookup( ColorCorrectionHandle_t handle ) +{ + MaterialLock_t hLock = m_pMaterialSystem->Lock(); + ColorCorrectionSystem()->LockLookup( handle ); + m_pMaterialSystem->Unlock( hLock ); +} + +void CMatQueuedRenderContext::LoadLookup( ColorCorrectionHandle_t handle, const char *pLookupName ) +{ + MaterialLock_t hLock = m_pMaterialSystem->Lock(); + ColorCorrectionSystem()->LoadLookup( handle, pLookupName ); + m_pMaterialSystem->Unlock( hLock ); +} + +void CMatQueuedRenderContext::UnlockLookup( ColorCorrectionHandle_t handle ) +{ + MaterialLock_t hLock = m_pMaterialSystem->Lock(); + ColorCorrectionSystem()->UnlockLookup( handle ); + m_pMaterialSystem->Unlock( hLock ); +} + +// NOTE: These are synchronous calls! The rendering thread is stopped, the current queue is drained and the pixels are read +// NOTE: We should also have a queued read pixels in the API for doing mid frame reads (as opposed to screenshots) +void CMatQueuedRenderContext::ReadPixels( int x, int y, int width, int height, unsigned char *data, ImageFormat dstFormat ) +{ + EndRender(); + MaterialLock_t hLock = m_pMaterialSystem->Lock(); + this->CallQueued(false); + g_pShaderAPI->ReadPixels( x, y, width, height, data, dstFormat ); + m_pMaterialSystem->Unlock( hLock ); + BeginRender(); +} + +void CMatQueuedRenderContext::ReadPixelsAndStretch( Rect_t *pSrcRect, Rect_t *pDstRect, unsigned char *pBuffer, ImageFormat dstFormat, int nDstStride ) +{ + EndRender(); + MaterialLock_t hLock = m_pMaterialSystem->Lock(); + this->CallQueued(false); + g_pShaderAPI->ReadPixels( pSrcRect, pDstRect, pBuffer, dstFormat, nDstStride ); + m_pMaterialSystem->Unlock( hLock ); + BeginRender(); +} + diff --git a/materialsystem/cmatqueuedrendercontext.h b/materialsystem/cmatqueuedrendercontext.h new file mode 100644 index 0000000..3131850 --- /dev/null +++ b/materialsystem/cmatqueuedrendercontext.h @@ -0,0 +1,641 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//============================================================================= + +#ifndef CMATQUEUEDRENDERCONTEXT_H +#define CMATQUEUEDRENDERCONTEXT_H + +#include "imatrendercontextinternal.h" +#include "cmatrendercontext.h" +#include "tier1/callqueue.h" +#include "tier1/utlenvelope.h" +#include "tier1/memstack.h" +#include "mathlib/mathlib.h" + +#include "tier0/memdbgon.h" + +#if defined( _WIN32 ) +#pragma once +#endif + +#ifndef MATSYS_INTERNAL +#error "This file is private to the implementation of IMaterialSystem/IMaterialSystemInternal" +#endif + +class CMaterialSystem; +class CMatQueuedMesh; +class CPrimList; + +//----------------------------------------------------------------------------- + +#define DEFINE_QUEUED_CALL_0( FuncName, ClassName, pObject ) void FuncName() { (*(const_cast(&m_queue))).QueueCall( pObject, (void (ClassName::*)())&ClassName::FuncName); } +#define DEFINE_QUEUED_CALL_1( FuncName, ArgType1, ClassName, pObject ) void FuncName( ArgType1 a1 ) { (*(const_cast(&m_queue))).QueueCall( pObject, (void (ClassName::*)(ArgType1))&ClassName::FuncName, a1 ); } +#define DEFINE_QUEUED_CALL_2( FuncName, ArgType1, ArgType2, ClassName, pObject ) void FuncName( ArgType1 a1, ArgType2 a2 ) { (*(const_cast(&m_queue))).QueueCall( pObject, (void (ClassName::*)(ArgType1, ArgType2))&ClassName::FuncName, a1, a2 ); } +#define DEFINE_QUEUED_CALL_3( FuncName, ArgType1, ArgType2, ArgType3, ClassName, pObject ) void FuncName( ArgType1 a1, ArgType2 a2, ArgType3 a3 ) { (*(const_cast(&m_queue))).QueueCall( pObject, (void (ClassName::*)(ArgType1, ArgType2, ArgType3))&ClassName::FuncName, a1, a2, a3 ); } +#define DEFINE_QUEUED_CALL_4( FuncName, ArgType1, ArgType2, ArgType3, ArgType4, ClassName, pObject ) void FuncName( ArgType1 a1, ArgType2 a2, ArgType3 a3, ArgType4 a4 ) { (*(const_cast(&m_queue))).QueueCall( pObject, (void (ClassName::*)(ArgType1, ArgType2, ArgType3, ArgType4))&ClassName::FuncName, a1, a2, a3, a4 ); } +#define DEFINE_QUEUED_CALL_5( FuncName, ArgType1, ArgType2, ArgType3, ArgType4, ArgType5, ClassName, pObject ) void FuncName( ArgType1 a1, ArgType2 a2, ArgType3 a3, ArgType4 a4, ArgType5 a5 ) { (*(const_cast(&m_queue))).QueueCall( pObject, (void (ClassName::*)(ArgType1, ArgType2, ArgType3, ArgType4, ArgType5))&ClassName::FuncName, a1, a2, a3, a4, a5 ); } +#define DEFINE_QUEUED_CALL_6( FuncName, ArgType1, ArgType2, ArgType3, ArgType4, ArgType5, ArgType6, ClassName, pObject ) void FuncName( ArgType1 a1, ArgType2 a2, ArgType3 a3, ArgType4 a4, ArgType5 a5, ArgType6 a6 ) { (*(const_cast(&m_queue))).QueueCall( pObject, (void (ClassName::*)(ArgType1, ArgType2, ArgType3, ArgType4, ArgType5, ArgType6))&ClassName::FuncName, a1, a2, a3, a4, a5, a6 ); } +#define DEFINE_QUEUED_CALL_7( FuncName, ArgType1, ArgType2, ArgType3, ArgType4, ArgType5, ArgType6, ArgType7, ClassName, pObject ) void FuncName( ArgType1 a1, ArgType2 a2, ArgType3 a3, ArgType4 a4, ArgType5 a5, ArgType6 a6, ArgType7 a7 ) { (*(const_cast(&m_queue))).QueueCall( pObject, (void (ClassName::*)(ArgType1, ArgType2, ArgType3, ArgType4, ArgType5, ArgType6, ArgType7))&ClassName::FuncName, a1, a2, a3, a4, a5, a6, a7 ); } +#define DEFINE_QUEUED_CALL_8( FuncName, ArgType1, ArgType2, ArgType3, ArgType4, ArgType5, ArgType6, ArgType7, ArgType8, ClassName, pObject ) void FuncName( ArgType1 a1, ArgType2 a2, ArgType3 a3, ArgType4 a4, ArgType5 a5, ArgType6 a6, ArgType7 a7, ArgType8 a8 ) { (*(const_cast(&m_queue))).QueueCall( pObject, (void (ClassName::*)(ArgType1, ArgType2, ArgType3, ArgType4, ArgType5, ArgType6, ArgType7, ArgType8))&ClassName::FuncName, a1, a2, a3, a4, a5, a6, a7, a8 ); } +#define DEFINE_QUEUED_CALL_9( FuncName, ArgType1, ArgType2, ArgType3, ArgType4, ArgType5, ArgType6, ArgType7, ArgType8, ArgType9, ClassName, pObject ) void FuncName( ArgType1 a1, ArgType2 a2, ArgType3 a3, ArgType4 a4, ArgType5 a5, ArgType6 a6, ArgType7 a7, ArgType8 a8, ArgType9 a9 ) { (*(const_cast(&m_queue))).QueueCall( pObject, (void (ClassName::*)(ArgType1, ArgType2, ArgType3, ArgType4, ArgType5, ArgType6, ArgType7, ArgType8, ArgType9))&ClassName::FuncName, a1, a2, a3, a4, a5, a6, a7, a8, a9 ); } +#define DEFINE_QUEUED_CALL_11( FuncName, ArgType1, ArgType2, ArgType3, ArgType4, ArgType5, ArgType6, ArgType7, ArgType8, ArgType9, ArgType10, ArgType11, ClassName, pObject ) void FuncName( ArgType1 a1, ArgType2 a2, ArgType3 a3, ArgType4 a4, ArgType5 a5, ArgType6 a6, ArgType7 a7, ArgType8 a8, ArgType9 a9, ArgType10 a10, ArgType11 a11 ) { (*(const_cast(&m_queue))).QueueCall( pObject, (void (ClassName::*)(ArgType1, ArgType2, ArgType3, ArgType4, ArgType5, ArgType6, ArgType7, ArgType8, ArgType9, ArgType10, ArgType11))&ClassName::FuncName, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11 ); } +#define DEFINE_QUEUED_CALL_12( FuncName, ArgType1, ArgType2, ArgType3, ArgType4, ArgType5, ArgType6, ArgType7, ArgType8, ArgType9, ArgType10, ArgType11, ArgType12, ClassName, pObject ) void FuncName( ArgType1 a1, ArgType2 a2, ArgType3 a3, ArgType4 a4, ArgType5 a5, ArgType6 a6, ArgType7 a7, ArgType8 a8, ArgType9 a9, ArgType10 a10, ArgType11 a11, ArgType12 a12 ) { (*(const_cast(&m_queue))).QueueCall( pObject, (void (ClassName::*)(ArgType1, ArgType2, ArgType3, ArgType4, ArgType5, ArgType6, ArgType7, ArgType8, ArgType9, ArgType10, ArgType11, ArgType12))&ClassName::FuncName, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12 ); } + +#define DEFINE_QUEUED_CALL_0C( FuncName, ClassName, pObject ) void FuncName() const { (*(const_cast(&m_queue))).QueueCall( pObject, (void (ClassName::*)() const)ClassName::FuncName); } +#define DEFINE_QUEUED_CALL_1C( FuncName, ArgType1, ClassName, pObject ) void FuncName( ArgType1 a1 ) const { (*(const_cast(&m_queue))).QueueCall( pObject, (void (ClassName::*)(ArgType1) const)ClassName::FuncName, a1 ); } +#define DEFINE_QUEUED_CALL_2C( FuncName, ArgType1, ArgType2, ClassName, pObject ) void FuncName( ArgType1 a1, ArgType2 a2 ) const { (*(const_cast(&m_queue))).QueueCall( pObject, (void (ClassName::*)(ArgType1, ArgType2) const)ClassName::FuncName, a1, a2 ); } +#define DEFINE_QUEUED_CALL_3C( FuncName, ArgType1, ArgType2, ArgType3, ClassName, pObject ) void FuncName( ArgType1 a1, ArgType2 a2, ArgType3 a3 ) const { (*(const_cast(&m_queue))).QueueCall( pObject, (void (ClassName::*)(ArgType1, ArgType2, ArgType3) const)ClassName::FuncName, a1, a2, a3 ); } +#define DEFINE_QUEUED_CALL_4C( FuncName, ArgType1, ArgType2, ArgType3, ArgType4, ClassName, pObject ) void FuncName( ArgType1 a1, ArgType2 a2, ArgType3 a3, ArgType4 a4 ) const { (*(const_cast(&m_queue))).QueueCall( pObject, (void (ClassName::*)(ArgType1, ArgType2, ArgType3, ArgType4) const)ClassName::FuncName, a1, a2, a3, a4 ); } +#define DEFINE_QUEUED_CALL_5C( FuncName, ArgType1, ArgType2, ArgType3, ArgType4, ArgType5, ClassName, pObject ) void FuncName( ArgType1 a1, ArgType2 a2, ArgType3 a3, ArgType4 a4, ArgType5 a5 ) const { (*(const_cast(&m_queue))).QueueCall( pObject, (void (ClassName::*)(ArgType1, ArgType2, ArgType3, ArgType4, ArgType5) const)ClassName::FuncName, a1, a2, a3, a4, a5 ); } +#define DEFINE_QUEUED_CALL_6C( FuncName, ArgType1, ArgType2, ArgType3, ArgType4, ArgType5, ArgType6, ClassName, pObject ) void FuncName( ArgType1 a1, ArgType2 a2, ArgType3 a3, ArgType4 a4, ArgType5 a5, ArgType6 a6 ) const { (*(const_cast(&m_queue))).QueueCall( pObject, (void (ClassName::*)(ArgType1, ArgType2, ArgType3, ArgType4, ArgType5, ArgType6) const)ClassName::FuncName, a1, a2, a3, a4, a5, a6 ); } +#define DEFINE_QUEUED_CALL_7C( FuncName, ArgType1, ArgType2, ArgType3, ArgType4, ArgType5, ArgType6, ArgType7, ClassName, pObject ) void FuncName( ArgType1 a1, ArgType2 a2, ArgType3 a3, ArgType4 a4, ArgType5 a5, ArgType6 a6, ArgType7 a7 ) const { (*(const_cast(&m_queue))).QueueCall( pObject, (void (ClassName::*)(ArgType1, ArgType2, ArgType3, ArgType4, ArgType5, ArgType6, ArgType7) const)ClassName::FuncName, a1, a2, a3, a4, a5, a6, a7 ); } +#define DEFINE_QUEUED_CALL_8C( FuncName, ArgType1, ArgType2, ArgType3, ArgType4, ArgType5, ArgType6, ArgType7, ArgType8, ClassName, pObject ) void FuncName( ArgType1 a1, ArgType2 a2, ArgType3 a3, ArgType4 a4, ArgType5 a5, ArgType6 a6, ArgType7 a7, ArgType8 a8 ) const { (*(const_cast(&m_queue))).QueueCall( pObject, (void (ClassName::*)(ArgType1, ArgType2, ArgType3, ArgType4, ArgType5, ArgType6, ArgType7, ArgType8) const)ClassName::FuncName, a1, a2, a3, a4, a5, a6, a7, a8 ); } +#define DEFINE_QUEUED_CALL_9C( FuncName, ArgType1, ArgType2, ArgType3, ArgType4, ArgType5, ArgType6, ArgType7, ArgType8, ArgType9, ClassName, pObject ) void FuncName( ArgType1 a1, ArgType2 a2, ArgType3 a3, ArgType4 a4, ArgType5 a5, ArgType6 a6, ArgType7 a7, ArgType8 a8, ArgType9 a9 ) const { (*(const_cast(&m_queue))).QueueCall( pObject, (void (ClassName::*)(ArgType1, ArgType2, ArgType3, ArgType4, ArgType5, ArgType6, ArgType7, ArgType8, ArgType9) const)ClassName::FuncName, a1, a2, a3, a4, a5, a6, a7, a8, a9 ); } + +#define DEFINE_QUEUED_CALL_AFTER_BASE_0( FuncName, ClassName, pObject ) void FuncName() { BaseClass::FuncName(); (*(const_cast(&m_queue))).QueueCall( pObject, (void (ClassName::*)())&ClassName::FuncName ); } +#define DEFINE_QUEUED_CALL_AFTER_BASE_1( FuncName, ArgType1, ClassName, pObject ) void FuncName( ArgType1 a1 ) { BaseClass::FuncName( a1 ); (*(const_cast(&m_queue))).QueueCall( pObject, (void (ClassName::*)(ArgType1))&ClassName::FuncName, a1 ); } +#define DEFINE_QUEUED_CALL_AFTER_BASE_2( FuncName, ArgType1, ArgType2, ClassName, pObject ) void FuncName( ArgType1 a1, ArgType2 a2 ) { BaseClass::FuncName( a1, a2 ); (*(const_cast(&m_queue))).QueueCall( pObject, (void (ClassName::*)(ArgType1, ArgType2))&ClassName::FuncName, a1, a2 ); } +#define DEFINE_QUEUED_CALL_AFTER_BASE_3( FuncName, ArgType1, ArgType2, ArgType3, ClassName, pObject ) void FuncName( ArgType1 a1, ArgType2 a2, ArgType3 a3 ) { BaseClass::FuncName( a1, a2, a3 ); (*(const_cast(&m_queue))).QueueCall( pObject, (void (ClassName::*)(ArgType1, ArgType2, ArgType3))&ClassName::FuncName, a1, a2, a3 ); } +#define DEFINE_QUEUED_CALL_AFTER_BASE_4( FuncName, ArgType1, ArgType2, ArgType3, ArgType4, ClassName, pObject ) void FuncName( ArgType1 a1, ArgType2 a2, ArgType3 a3, ArgType4 a4 ) { BaseClass::FuncName( a1, a2, a3, a4 ); (*(const_cast(&m_queue))).QueueCall( pObject, (void (ClassName::*)(ArgType1, ArgType2, ArgType3, ArgType4))&ClassName::FuncName, a1, a2, a3, a4 ); } +#define DEFINE_QUEUED_CALL_AFTER_BASE_5( FuncName, ArgType1, ArgType2, ArgType3, ArgType4, ArgType5, ClassName, pObject ) void FuncName( ArgType1 a1, ArgType2 a2, ArgType3 a3, ArgType4 a4, ArgType5 a5 ) { BaseClass::FuncName( a1, a2, a3, a4, a5 ); (*(const_cast(&m_queue))).QueueCall( pObject, (void (ClassName::*)(ArgType1, ArgType2, ArgType3, ArgType4, ArgType5))&ClassName::FuncName, a1, a2, a3, a4, a5 ); } +#define DEFINE_QUEUED_CALL_AFTER_BASE_6( FuncName, ArgType1, ArgType2, ArgType3, ArgType4, ArgType5, ArgType6, ClassName, pObject ) void FuncName( ArgType1 a1, ArgType2 a2, ArgType3 a3, ArgType4 a4, ArgType5 a5, ArgType6 a6 ) { BaseClass::FuncName( a1, a2, a3, a4, a5, a6 ); (*(const_cast(&m_queue))).QueueCall( pObject, (void (ClassName::*)(ArgType1, ArgType2, ArgType3, ArgType4, ArgType5, ArgType6))&ClassName::FuncName, a1, a2, a3, a4, a5, a6 ); } +#define DEFINE_QUEUED_CALL_AFTER_BASE_7( FuncName, ArgType1, ArgType2, ArgType3, ArgType4, ArgType5, ArgType6, ArgType7, ClassName, pObject ) void FuncName( ArgType1 a1, ArgType2 a2, ArgType3 a3, ArgType4 a4, ArgType5 a5, ArgType6 a6, ArgType7 a7 ) { BaseClass::FuncName( a1, a2, a3, a4, a5, a6, a7 ); (*(const_cast(&m_queue))).QueueCall( pObject, (void (ClassName::*)(ArgType1, ArgType2, ArgType3, ArgType4, ArgType5, ArgType6, ArgType7))&ClassName::FuncName, a1, a2, a3, a4, a5, a6, a7 ); } +#define DEFINE_QUEUED_CALL_AFTER_BASE_8( FuncName, ArgType1, ArgType2, ArgType3, ArgType4, ArgType5, ArgType6, ArgType7, ArgType8, ClassName, pObject ) void FuncName( ArgType1 a1, ArgType2 a2, ArgType3 a3, ArgType4 a4, ArgType5 a5, ArgType6 a6, ArgType7 a7, ArgType8 a8 ) { BaseClass::FuncName( a1, a2, a3, a4, a5, a6, a7, a8 ); (*(const_cast(&m_queue))).QueueCall( pObject, (void (ClassName::*)(ArgType1, ArgType2, ArgType3, ArgType4, ArgType5, ArgType6, ArgType7, ArgType8))&ClassName::FuncName, a1, a2, a3, a4, a5, a6, a7, a8 ); } +#define DEFINE_QUEUED_CALL_AFTER_BASE_9( FuncName, ArgType1, ArgType2, ArgType3, ArgType4, ArgType5, ArgType6, ArgType7, ArgType8, ArgType9, ClassName, pObject ) void FuncName( ArgType1 a1, ArgType2 a2, ArgType3 a3, ArgType4 a4, ArgType5 a5, ArgType6 a6, ArgType7 a7, ArgType8 a8, ArgType9 a9 ) { BaseClass::FuncName( a1, a2, a3, a4, a5, a6, a7, a8, a9 ); (*(const_cast(&m_queue))).QueueCall( pObject, (void (ClassName::*)(ArgType1, ArgType2, ArgType3, ArgType4, ArgType5, ArgType6, ArgType7, ArgType8, ArgType9))&ClassName::FuncName, a1, a2, a3, a4, a5, a6, a7, a8, a9 ); } + +#define DEFINE_QUEUED_CALL_AFTER_BASE_0C( FuncName, ClassName, pObject ) void FuncName() const { BaseClass::FuncName(); (*(const_cast(&m_queue))).QueueCall( pObject, (void (ClassName::*)())&ClassName::FuncName ); } +#define DEFINE_QUEUED_CALL_AFTER_BASE_1C( FuncName, ArgType1, ClassName, pObject ) void FuncName( ArgType1 a1 ) const { BaseClass::FuncName( a1 ); (*(const_cast(&m_queue))).QueueCall( pObject, (void (ClassName::*)(ArgType1))&ClassName::FuncName, a1 ); } +#define DEFINE_QUEUED_CALL_AFTER_BASE_2C( FuncName, ArgType1, ArgType2, ClassName, pObject ) void FuncName( ArgType1 a1, ArgType2 a2 ) const { BaseClass::FuncName( a1, a2 ); (*(const_cast(&m_queue))).QueueCall( pObject, (void (ClassName::*)(ArgType1, ArgType2))&ClassName::FuncName, a1, a2 ); } +#define DEFINE_QUEUED_CALL_AFTER_BASE_3C( FuncName, ArgType1, ArgType2, ArgType3, ClassName, pObject ) void FuncName( ArgType1 a1, ArgType2 a2, ArgType3 a3 ) const { BaseClass::FuncName( a1, a2, a3 ); (*(const_cast(&m_queue))).QueueCall( pObject, (void (ClassName::*)(ArgType1, ArgType2, ArgType3))&ClassName::FuncName, a1, a2, a3 ); } +#define DEFINE_QUEUED_CALL_AFTER_BASE_4C( FuncName, ArgType1, ArgType2, ArgType3, ArgType4, ClassName, pObject ) void FuncName( ArgType1 a1, ArgType2 a2, ArgType3 a3, ArgType4 a4 ) const { BaseClass::FuncName( a1, a2, a3, a4 ); (*(const_cast(&m_queue))).QueueCall( pObject, (void (ClassName::*)(ArgType1, ArgType2, ArgType3, ArgType4))&ClassName::FuncName, a1, a2, a3, a4 ); } +#define DEFINE_QUEUED_CALL_AFTER_BASE_5C( FuncName, ArgType1, ArgType2, ArgType3, ArgType4, ArgType5, ClassName, pObject ) void FuncName( ArgType1 a1, ArgType2 a2, ArgType3 a3, ArgType4 a4, ArgType5 a5 ) const { BaseClass::FuncName( a1, a2, a3, a4, a5 ); (*(const_cast(&m_queue))).QueueCall( pObject, (void (ClassName::*)(ArgType1, ArgType2, ArgType3, ArgType4, ArgType5))&ClassName::FuncName, a1, a2, a3, a4, a5 ); } +#define DEFINE_QUEUED_CALL_AFTER_BASE_6C( FuncName, ArgType1, ArgType2, ArgType3, ArgType4, ArgType5, ArgType6, ClassName, pObject ) void FuncName( ArgType1 a1, ArgType2 a2, ArgType3 a3, ArgType4 a4, ArgType5 a5, ArgType6 a6 ) const { BaseClass::FuncName( a1, a2, a3, a4, a5, a6 ); (*(const_cast(&m_queue))).QueueCall( pObject, (void (ClassName::*)(ArgType1, ArgType2, ArgType3, ArgType4, ArgType5, ArgType6))&ClassName::FuncName, a1, a2, a3, a4, a5, a6 ); } +#define DEFINE_QUEUED_CALL_AFTER_BASE_7C( FuncName, ArgType1, ArgType2, ArgType3, ArgType4, ArgType5, ArgType6, ArgType7, ClassName, pObject ) void FuncName( ArgType1 a1, ArgType2 a2, ArgType3 a3, ArgType4 a4, ArgType5 a5, ArgType6 a6, ArgType7 a7 ) const { BaseClass::FuncName( a1, a2, a3, a4, a5, a6, a7 ); (*(const_cast(&m_queue))).QueueCall( pObject, (void (ClassName::*)(ArgType1, ArgType2, ArgType3, ArgType4, ArgType5, ArgType6, ArgType7))&ClassName::FuncName, a1, a2, a3, a4, a5, a6, a7 ); } +#define DEFINE_QUEUED_CALL_AFTER_BASE_8C( FuncName, ArgType1, ArgType2, ArgType3, ArgType4, ArgType5, ArgType6, ArgType7, ArgType8, ClassName, pObject ) void FuncName( ArgType1 a1, ArgType2 a2, ArgType3 a3, ArgType4 a4, ArgType5 a5, ArgType6 a6, ArgType7 a7, ArgType8 a8 ) const { BaseClass::FuncName( a1, a2, a3, a4, a5, a6, a7, a8 ); (*(const_cast(&m_queue))).QueueCall( pObject, (void (ClassName::*)(ArgType1, ArgType2, ArgType3, ArgType4, ArgType5, ArgType6, ArgType7, ArgType8))&ClassName::FuncName, a1, a2, a3, a4, a5, a6, a7, a8 ); } +#define DEFINE_QUEUED_CALL_AFTER_BASE_9C( FuncName, ArgType1, ArgType2, ArgType3, ArgType4, ArgType5, ArgType6, ArgType7, ArgType8, ArgType9, ClassName, pObject ) void FuncName( ArgType1 a1, ArgType2 a2, ArgType3 a3, ArgType4 a4, ArgType5 a5, ArgType6 a6, ArgType7 a7, ArgType8 a8, ArgType9 a9 ) const { BaseClass::FuncName( a1, a2, a3, a4, a5, a6, a7, a8, a9 ); (*(const_cast(&m_queue))).QueueCall( pObject, (void (ClassName::*)(ArgType1, ArgType2, ArgType3, ArgType4, ArgType5, ArgType6, ArgType7, ArgType8, ArgType9))&ClassName::FuncName, a1, a2, a3, a4, a5, a6, a7, a8, a9 ); } + +//----------------------------------------------------------------------------- + +#define Unsupported( funcName ) ExecuteOnce( Msg( "CMatQueuedRenderContext: %s is unsupported\n", #funcName ) ) +#define FATAL_QUEUE 1 + +#ifdef FATAL_QUEUE +#define CannotSupport() ExecuteOnce( Msg( "Called function that cannot be supported\n" ) ); ExecuteOnce( DebuggerBreakIfDebugging() ) +#else +#define CannotSupport() ExecuteOnce( Msg( "Called function that cannot be supported\n" ) ) +#endif + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- + +class CMatQueuedRenderContext : public CMatRenderContextBase +{ + typedef CMatRenderContextBase BaseClass; +public: + CMatQueuedRenderContext() + : m_pHardwareContext( NULL ), + m_iRenderDepth( 0 ), + m_pQueuedMesh( NULL ), + m_WidthBackBuffer( 0 ), + m_HeightBackBuffer( 0 ), + m_FogMode( MATERIAL_FOG_NONE ), + m_flFogStart( 0 ), + m_flFogEnd( 0 ), + m_flFogZ( 0 ), + m_flFogMaxDensity( 1.0 ) + { + memset( &m_FogColor, 0, sizeof(m_FogColor) ); + } + + bool Init( CMaterialSystem *pMaterialSystem, CMatRenderContextBase *pHardwareContext ); + void Shutdown(); + void Free(); + + void CompactMemory(); + + bool IsInitialized() const { return ( m_pHardwareContext != NULL ); } + + void BeginQueue( CMatRenderContextBase *pInitialState = NULL ); + void EndQueue( bool bCallQueued = false ); + + void BeginRender(); + void EndRender(); + + void CallQueued( bool bTermAfterCall = false ); + void FlushQueued(); + + ICallQueue * GetCallQueue(); + CMatCallQueue * GetCallQueueInternal() { return &m_queue; } + + bool OnDrawMesh( IMesh *pMesh, int firstIndex, int numIndices ); + bool OnDrawMesh( IMesh *pMesh, CPrimList *pLists, int nLists ); + bool OnSetFlexMesh( IMesh *pStaticMesh, IMesh *pMesh, int nVertexOffsetInBytes ); + bool OnSetColorMesh( IMesh *pStaticMesh, IMesh *pMesh, int nVertexOffsetInBytes ); + bool OnSetPrimitiveType( IMesh *pMesh, MaterialPrimitiveType_t type ); + bool OnFlushBufferedPrimitives(); + + + DEFINE_QUEUED_CALL_1( Flush, bool, IMatRenderContext, m_pHardwareContext ); + + DEFINE_QUEUED_CALL_0( SwapBuffers, IMatRenderContextInternal, m_pHardwareContext ); + + void SetRenderTargetEx( int nRenderTargetID, ITexture *pTexture ); + void GetRenderTargetDimensions( int &, int &) const; + void GetViewport( int& x, int& y, int& width, int& height ) const; + + void Bind( IMaterial *, void * ); + DEFINE_QUEUED_CALL_AFTER_BASE_1( BindLocalCubemap, ITexture *, IMatRenderContext, m_pHardwareContext ); + DEFINE_QUEUED_CALL_AFTER_BASE_1( BindLightmapPage, int, IMatRenderContext, m_pHardwareContext ); + DEFINE_QUEUED_CALL_2( DepthRange, float, float, IMatRenderContext, m_pHardwareContext ); + DEFINE_QUEUED_CALL_3( ClearBuffers, bool, bool, bool, IMatRenderContext, m_pHardwareContext ); + + void ReadPixels( int x, int y, int width, int height, unsigned char *data, ImageFormat dstFormat ); + + DEFINE_QUEUED_CALL_3( SetAmbientLight, float, float, float, IMatRenderContext, m_pHardwareContext ); + + void SetLight( int i, const LightDesc_t &desc ); + + void SetLightingOrigin( Vector vLightingOrigin ); + + void SetAmbientLightCube( LightCube_t cube ); + + DEFINE_QUEUED_CALL_1( CopyRenderTargetToTexture, ITexture *, IMatRenderContext, m_pHardwareContext ); + DEFINE_QUEUED_CALL_AFTER_BASE_2( SetFrameBufferCopyTexture, ITexture *, int, IMatRenderContext, m_pHardwareContext ); + + // matrix api + void MatrixMode( MaterialMatrixMode_t); + void PushMatrix(); + void PopMatrix(); + void LoadMatrix( const VMatrix& matrix ); + void LoadMatrix( const matrix3x4_t& matrix ); + void MultMatrix( const VMatrix& matrix ); + void MultMatrixLocal( const VMatrix& matrix ); + void MultMatrix( const matrix3x4_t& matrix ); + void MultMatrixLocal( const matrix3x4_t& matrix ); + void LoadIdentity(); + void Ortho( double, double, double, double, double, double); + void PerspectiveX( double, double, double, double); + void PerspectiveOffCenterX( double, double, double, double, double, double, double, double ); + void PickMatrix( int, int, int, int); + void Rotate( float, float, float, float); + void Translate( float, float, float); + void Scale( float, float, float); + // end matrix api + + void Viewport( int x, int y, int width, int height ); + + DEFINE_QUEUED_CALL_1( CullMode, MaterialCullMode_t, IMatRenderContext, m_pHardwareContext ); + + void FogMode( MaterialFogMode_t fogMode ); + void FogStart( float fStart ); + void FogEnd( float fEnd ); + void SetFogZ( float fogZ ); + MaterialFogMode_t GetFogMode( void ); + void GetFogDistances( float *fStart, float *fEnd, float *fFogZ ); + void FogMaxDensity( float flMaxDensity ); + + void FogColor3f( float r, float g, float b ); + void FogColor3fv( float const* rgb ); + void FogColor3ub( unsigned char r, unsigned char g, unsigned char b ); + void FogColor3ubv( unsigned char const* rgb ); + + void GetFogColor( unsigned char *rgb ); + + int GetCurrentNumBones( ) const; + void SetNumBoneWeights( int nBoneCount ); + + DELEGATE_TO_OBJECT_3( IMesh *, CreateStaticMesh, VertexFormat_t, const char *, IMaterial *, m_pHardwareContext ); + DEFINE_QUEUED_CALL_1( DestroyStaticMesh, IMesh *, IMatRenderContext, m_pHardwareContext ); + + IMesh * GetDynamicMesh(bool, IMesh *, IMesh *, IMaterial * ); + IMesh* GetDynamicMeshEx( VertexFormat_t, bool, IMesh*, IMesh*, IMaterial* ); + +// ------------ New Vertex/Index Buffer interface ---------------------------- + DELEGATE_TO_OBJECT_3( IVertexBuffer *, CreateStaticVertexBuffer, VertexFormat_t, int, const char *, m_pHardwareContext ); + DELEGATE_TO_OBJECT_3( IIndexBuffer *, CreateStaticIndexBuffer, MaterialIndexFormat_t, int, const char *, m_pHardwareContext ); + DELEGATE_TO_OBJECT_1V( DestroyVertexBuffer, IVertexBuffer *, m_pHardwareContext ); + DELEGATE_TO_OBJECT_1V( DestroyIndexBuffer, IIndexBuffer *, m_pHardwareContext ); + DELEGATE_TO_OBJECT_3( IVertexBuffer *, GetDynamicVertexBuffer, int, VertexFormat_t, bool, m_pHardwareContext ); + DELEGATE_TO_OBJECT_2( IIndexBuffer *, GetDynamicIndexBuffer, MaterialIndexFormat_t, bool, m_pHardwareContext ); + DELEGATE_TO_OBJECT_7V( BindVertexBuffer, int, IVertexBuffer *, int, int, int, VertexFormat_t, int, m_pHardwareContext ); + DELEGATE_TO_OBJECT_2V( BindIndexBuffer, IIndexBuffer *, int, m_pHardwareContext ); + DELEGATE_TO_OBJECT_3V( Draw, MaterialPrimitiveType_t, int, int, m_pHardwareContext ); +// ------------ End ---------------------------- + + int SelectionMode( bool ) + { + CannotSupport(); + return 0; + } + + void SelectionBuffer( unsigned int *, int ) + { + CannotSupport(); + } + + DEFINE_QUEUED_CALL_0( ClearSelectionNames, IMatRenderContext, m_pHardwareContext ); + DEFINE_QUEUED_CALL_1( LoadSelectionName, int, IMatRenderContext, m_pHardwareContext ); + DEFINE_QUEUED_CALL_1( PushSelectionName, int, IMatRenderContext, m_pHardwareContext ); + DEFINE_QUEUED_CALL_0( PopSelectionName, IMatRenderContext, m_pHardwareContext ); + DEFINE_QUEUED_CALL_3( ClearColor3ub, unsigned char, unsigned char, unsigned char, IMatRenderContext, m_pHardwareContext ); + DEFINE_QUEUED_CALL_4( ClearColor4ub, unsigned char, unsigned char, unsigned char, unsigned char, IMatRenderContext, m_pHardwareContext ); + DEFINE_QUEUED_CALL_2( OverrideDepthEnable, bool, bool, IMatRenderContext, m_pHardwareContext ); + DEFINE_QUEUED_CALL_2( OverrideAlphaWriteEnable, bool, bool, IMatRenderContext, m_pHardwareContext ); + DEFINE_QUEUED_CALL_2( OverrideColorWriteEnable, bool, bool, IMatRenderContext, m_pHardwareContext ); + DEFINE_QUEUED_CALL_1( DrawScreenSpaceQuad, IMaterial *, IMatRenderContext, m_pHardwareContext ); + + void SyncToken( const char *p ); + + // Allocate and delete query objects. + OcclusionQueryObjectHandle_t CreateOcclusionQueryObject(); + DEFINE_QUEUED_CALL_1( DestroyOcclusionQueryObject, OcclusionQueryObjectHandle_t, IMatRenderContext, m_pHardwareContext ); + DEFINE_QUEUED_CALL_1( BeginOcclusionQueryDrawing, OcclusionQueryObjectHandle_t, IMatRenderContext, m_pHardwareContext ); + DEFINE_QUEUED_CALL_1( EndOcclusionQueryDrawing, OcclusionQueryObjectHandle_t, IMatRenderContext, m_pHardwareContext ); + DEFINE_QUEUED_CALL_1( ResetOcclusionQueryObject, OcclusionQueryObjectHandle_t, IMatRenderContext, m_pHardwareContext ); + int OcclusionQuery_GetNumPixelsRendered( OcclusionQueryObjectHandle_t ); + + void SetFlashlightState( const FlashlightState_t &s, const VMatrix &m ); + + DEFINE_QUEUED_CALL_AFTER_BASE_1( SetHeightClipMode, MaterialHeightClipMode_t, IMatRenderContext, m_pHardwareContext ); + DEFINE_QUEUED_CALL_AFTER_BASE_1( SetHeightClipZ, float, IMatRenderContext, m_pHardwareContext ); + + bool EnableClipping( bool bEnable ); + + DEFINE_QUEUED_CALL_1( EnableUserClipTransformOverride, bool, IMatRenderContext, m_pHardwareContext ); + + void UserClipTransform( const VMatrix &m ); + + IMorph *CreateMorph( MorphFormat_t format, const char *pDebugName ) + { + CannotSupport(); + return NULL; + } + + DEFINE_QUEUED_CALL_1( DestroyMorph, IMorph *, IMatRenderContext, m_pHardwareContext ); + DEFINE_QUEUED_CALL_1( BindMorph, IMorph *, IMatRenderContext, m_pHardwareContext ); + + void ReadPixelsAndStretch( Rect_t *pSrcRect, Rect_t *pDstRect, unsigned char *pBuffer, ImageFormat dstFormat, int nDstStride ); + + void GetWindowSize( int &width, int &height ) const; + + void DrawScreenSpaceRectangle( IMaterial *pMaterial, + int destx, int desty, + int width, int height, + float src_texture_x0, float src_texture_y0, // which texel you want to appear at + // destx/y + float src_texture_x1, float src_texture_y1, // which texel you want to appear at + // destx+width-1, desty+height-1 + int src_texture_width, int src_texture_height, // needed for fixup + void *pClientRenderable = NULL, + int nXDice = 1, + int nYDice = 1 ); + + void LoadBoneMatrix( int i, const matrix3x4_t &m ); + + DEFINE_QUEUED_CALL_AFTER_BASE_5( PushRenderTargetAndViewport, ITexture *, int, int, int, int, IMatRenderContext, m_pHardwareContext ); + DEFINE_QUEUED_CALL_AFTER_BASE_6( PushRenderTargetAndViewport, ITexture *, ITexture *, int, int, int, int, IMatRenderContext, m_pHardwareContext ); + DEFINE_QUEUED_CALL_AFTER_BASE_1( PushRenderTargetAndViewport, ITexture *, IMatRenderContext, m_pHardwareContext ); + DEFINE_QUEUED_CALL_AFTER_BASE_0( PushRenderTargetAndViewport, IMatRenderContext, m_pHardwareContext ); + DEFINE_QUEUED_CALL_AFTER_BASE_0( PopRenderTargetAndViewport, IMatRenderContext, m_pHardwareContext ); + DEFINE_QUEUED_CALL_1( BindLightmapTexture, ITexture *, IMatRenderContext, m_pHardwareContext ); + + void CopyRenderTargetToTextureEx( ITexture *pTexture, int i, Rect_t *pSrc, Rect_t *pDst ); + void CopyTextureToRenderTargetEx( int i, ITexture *pTexture, Rect_t *pSrc, Rect_t *pDst ); + + DEFINE_QUEUED_CALL_2( SetFloatRenderingParameter, int, float, IMatRenderContext, m_pHardwareContext ); + DEFINE_QUEUED_CALL_2( SetIntRenderingParameter, int, int, IMatRenderContext, m_pHardwareContext ); + + void SetVectorRenderingParameter( int i, const Vector &v ) + { + m_queue.QueueCall( m_pHardwareContext, &IMatRenderContext::SetVectorRenderingParameter, i, RefToVal( v ) ); + } + + float GetFloatRenderingParameter(int parm_number) const + { + CannotSupport(); + return 0; + } + + int GetIntRenderingParameter(int parm_number) const + { + CannotSupport(); + return 0; + } + + Vector GetVectorRenderingParameter(int parm_number) const + { + CannotSupport(); + return Vector(0,0,0); + } + + DEFINE_QUEUED_CALL_1( SetStencilEnable, bool, IMatRenderContext, m_pHardwareContext ); + DEFINE_QUEUED_CALL_1( SetStencilFailOperation, StencilOperation_t, IMatRenderContext, m_pHardwareContext ); + DEFINE_QUEUED_CALL_1( SetStencilZFailOperation, StencilOperation_t, IMatRenderContext, m_pHardwareContext ); + DEFINE_QUEUED_CALL_1( SetStencilPassOperation, StencilOperation_t, IMatRenderContext, m_pHardwareContext ); + DEFINE_QUEUED_CALL_1( SetStencilCompareFunction, StencilComparisonFunction_t, IMatRenderContext, m_pHardwareContext ); + DEFINE_QUEUED_CALL_1( SetStencilReferenceValue, int, IMatRenderContext, m_pHardwareContext ); + DEFINE_QUEUED_CALL_1( SetStencilTestMask, uint32, IMatRenderContext, m_pHardwareContext ); + DEFINE_QUEUED_CALL_1( SetStencilWriteMask, uint32, IMatRenderContext, m_pHardwareContext ); + DEFINE_QUEUED_CALL_5( ClearStencilBufferRectangle, int, int, int, int, int, IMatRenderContext, m_pHardwareContext ); + + DEFINE_QUEUED_CALL_2( SetShadowDepthBiasFactors, float, float, IMatRenderContext, m_pHardwareContext ); + + void PushCustomClipPlane( const float *p ) + { + + m_queue.QueueCall( m_pHardwareContext, &IMatRenderContext::PushCustomClipPlane, CUtlEnvelope( p, 4 ) ); + } + + DEFINE_QUEUED_CALL_0( PopCustomClipPlane, IMatRenderContext, m_pHardwareContext ); + + virtual void GetMaxToRender( IMesh *pMesh, bool bMaxUntilFlush, int *pMaxVerts, int *pMaxIndices ); + virtual int GetMaxVerticesToRender( IMaterial *pMaterial ); + virtual int GetMaxIndicesToRender( ) + { + return INDEX_BUFFER_SIZE; + } + + DEFINE_QUEUED_CALL_0( DisableAllLocalLights, IMatRenderContext, m_pHardwareContext ); + + int CompareMaterialCombos( IMaterial *pMaterial1, IMaterial *pMaterial2, int lightmapID1, int lightmapID2 ) + { + CannotSupport(); + return 0; + } + + IMesh *GetFlexMesh(); + + void SetFlashlightStateEx( const FlashlightState_t &s, const VMatrix &m, ITexture *p ) + { + m_queue.QueueCall( m_pHardwareContext, &IMatRenderContext::SetFlashlightStateEx, RefToVal( s ), RefToVal( m ), p ); + } + + void SetScissorRect( const int nLeft, const int nTop, const int nRight, const int nBottom, const bool bEnableScissor ) + { + m_queue.QueueCall( m_pHardwareContext, &IMatRenderContext::SetScissorRect, nLeft, nTop, nRight, nBottom, bEnableScissor ); + } + + virtual void PushDeformation( const DeformationBase_t *pDef ) + { + CannotSupport(); + } + + void PopDeformation( ) + { + CannotSupport(); + } + + int GetNumActiveDeformations( ) const + { + return 0; + } + + ITexture *GetLocalCubemap() + { + return m_pLocalCubemapTexture; + } + + DEFINE_QUEUED_CALL_2( ClearBuffersObeyStencil, bool, bool, IMatRenderContext, m_pHardwareContext ); + DEFINE_QUEUED_CALL_3( ClearBuffersObeyStencilEx, bool, bool, bool, IMatRenderContext, m_pHardwareContext ); + DEFINE_QUEUED_CALL_0( PerformFullScreenStencilOperation, IMatRenderContext, m_pHardwareContext ); + + virtual void AsyncCreateTextureFromRenderTarget( ITexture* pSrcRt, const char* pDstName, ImageFormat dstFmt, bool bGenMips, int nAdditionalCreationFlags, IAsyncTextureOperationReceiver* pRecipient, void* pExtraArgs ) OVERRIDE + { + OnAsyncCreateTextureFromRenderTarget( pSrcRt, &pDstName, pRecipient ); + + m_queue.QueueCall( m_pHardwareContext, &IMatRenderContext::AsyncCreateTextureFromRenderTarget, pSrcRt, pDstName, dstFmt, bGenMips, nAdditionalCreationFlags, pRecipient, pExtraArgs ); + } + + virtual void AsyncMap( ITextureInternal* pTexToMap, IAsyncTextureOperationReceiver* pRecipient, void* pExtraArgs ) OVERRIDE + { + OnAsyncMap( pTexToMap, pRecipient, pExtraArgs ); + + m_queue.QueueCall( m_pHardwareContext, &IMatRenderContextInternal::AsyncMap, pTexToMap, pRecipient, pExtraArgs ); + } + + virtual void AsyncUnmap( ITextureInternal* pTexToUnmap ) OVERRIDE + { + OnAsyncUnmap( pTexToUnmap ); + + m_queue.QueueCall( m_pHardwareContext, &IMatRenderContextInternal::AsyncUnmap, pTexToUnmap ); + } + + virtual void AsyncCopyRenderTargetToStagingTexture( ITexture* pDst, ITexture* pSrc, IAsyncTextureOperationReceiver* pRecipient, void* pExtraArgs ) OVERRIDE + { + OnAsyncCopyRenderTargetToStagingTexture( pDst, pSrc, pRecipient ); + + m_queue.QueueCall( m_pHardwareContext, &IMatRenderContextInternal::AsyncCopyRenderTargetToStagingTexture, pDst, pSrc, pRecipient, pExtraArgs ); + } + + DEFINE_QUEUED_CALL_0( TextureManagerUpdate, IMatRenderContextInternal, m_pHardwareContext ); + + bool GetUserClipTransform( VMatrix &worldToView ) + { + CannotSupport(); + return false; + } + + bool InFlashlightMode( void ) const + { + CannotSupport(); + return false; + } + + virtual void SetFlashlightMode( bool bEnable ) + { + m_bFlashlightEnable = bEnable; + m_queue.QueueCall( m_pHardwareContext, &IMatRenderContext::SetFlashlightMode, bEnable ); + } + + virtual bool GetFlashlightMode( void ) const { return m_bFlashlightEnable; } + + void BeginPIXEvent( unsigned long color, const char *pszName ) + { + m_queue.QueueCall( m_pHardwareContext, &IMatRenderContext::BeginPIXEvent, color, CUtlEnvelope( pszName ) ); + } + + DEFINE_QUEUED_CALL_0( EndPIXEvent, IMatRenderContext, m_pHardwareContext ); + + void SetPIXMarker( unsigned long color, const char *pszName ) + { + m_queue.QueueCall( m_pHardwareContext, &IMatRenderContext::SetPIXMarker, color, CUtlEnvelope( pszName ) ); + } + + DEFINE_QUEUED_CALL_0( ForceHardwareSync, IMatRenderContextInternal, m_pHardwareContext ); + DEFINE_QUEUED_CALL_0( BeginFrame, IMatRenderContextInternal, m_pHardwareContext ); + DEFINE_QUEUED_CALL_0( EndFrame, IMatRenderContextInternal, m_pHardwareContext ); + + void SetFrameTime( float frameTime ) + { + m_queue.QueueCall( m_pHardwareContext, &IMatRenderContextInternal::SetFrameTime, frameTime ); + m_FrameTime = frameTime; + } + + DEFINE_QUEUED_CALL_0( BeginMorphAccumulation, IMatRenderContextInternal, m_pHardwareContext ); + DEFINE_QUEUED_CALL_0( EndMorphAccumulation, IMatRenderContextInternal, m_pHardwareContext ); + virtual void AccumulateMorph( IMorph* pMorph, int nMorphCount, const MorphWeight_t* pWeights ) + { + // FIXME: Must copy off the morph weights here. Not sure the pattern for this. + Assert( 0 ); + } + virtual bool GetMorphAccumulatorTexCoord( Vector2D *pTexCoord, IMorph *pIMorph, int nVertex ) + { + // FIXME: We must assign morph ids in the queued mode + // and pass the ids down to the morph mgr to get the texcoord + Assert(0); + pTexCoord->Init(); + return false; + } + + virtual void SetFlexWeights( int nFirstWeight, int nCount, const MorphWeight_t* pWeights ) + { + Assert(0); + } + + //------------------------------------------------------------------------- + + DEFINE_QUEUED_CALL_AFTER_BASE_1( SetCurrentMaterialInternal, IMaterialInternal *, IMatRenderContextInternal, m_pHardwareContext ); + DEFINE_QUEUED_CALL_AFTER_BASE_1( SetCurrentProxy, void *, IMatRenderContextInternal, m_pHardwareContext ); + + int GetLightmapPage() + { + CannotSupport(); + return 0; + } + + void ForceDepthFuncEquals( bool ) + { + CannotSupport(); + } + + void BindStandardTexture( Sampler_t, StandardTextureId_t ) + { + CannotSupport(); + } + + void GetLightmapDimensions( int *, int * ) + { + CannotSupport(); + } + + MorphFormat_t GetBoundMorphFormat() + { + CannotSupport(); + return (MorphFormat_t)0; + } + + void DrawClearBufferQuad( unsigned char, unsigned char, unsigned char, unsigned char, bool, bool, bool ) + { + CannotSupport(); + } + + void BeginBatch( IMesh* pIndices ); + void BindBatch( IMesh* pVertices, IMaterial *pAutoBind = NULL ); + void DrawBatch(int firstIndex, int numIndices ); + void EndBatch(); + + // Color correction related methods.. + // Client cannot call IColorCorrectionSystem directly because it is not thread-safe + // FIXME: Make IColorCorrectionSystem threadsafe? + virtual ColorCorrectionHandle_t AddLookup( const char *pName ); + virtual void LockLookup( ColorCorrectionHandle_t handle ); + virtual void LoadLookup( ColorCorrectionHandle_t handle, const char *pLookupName ); + virtual void UnlockLookup( ColorCorrectionHandle_t handle ); + virtual bool RemoveLookup( ColorCorrectionHandle_t handle ); + + DEFINE_QUEUED_CALL_1( EnableColorCorrection, bool, IColorCorrectionSystem, g_pColorCorrectionSystem ); + DEFINE_QUEUED_CALL_0( ResetLookupWeights, IColorCorrectionSystem, g_pColorCorrectionSystem ); + DEFINE_QUEUED_CALL_2( SetLookupWeight, ColorCorrectionHandle_t, float, IColorCorrectionSystem, g_pColorCorrectionSystem ); + DEFINE_QUEUED_CALL_2( SetResetable, ColorCorrectionHandle_t, bool, IColorCorrectionSystem, g_pColorCorrectionSystem ); + + DEFINE_QUEUED_CALL_1( SetFullScreenDepthTextureValidityFlag, bool, IMatRenderContext, m_pHardwareContext ); + + void SetToneMappingScaleLinear( const Vector &scale ) + { + m_queue.QueueCall( m_pHardwareContext, &IMatRenderContext::SetToneMappingScaleLinear, RefToVal( scale ) ); + m_LastSetToneMapScale = Vector( scale ); + } + + + void DeferredBeginBatch( uint16 *pIndexData, int nIndices ); + void DeferredDrawPrimList( IMesh *pMesh, CPrimList *pLists, int nLists ); + void DeferredSetFlexMesh( IMesh *pStaticMesh, int nVertexOffsetInBytes ); + +#if defined( _X360 ) + DEFINE_QUEUED_CALL_1( PushVertexShaderGPRAllocation, int, IMatRenderContext, m_pHardwareContext ); + DEFINE_QUEUED_CALL_0( PopVertexShaderGPRAllocation, IMatRenderContext, m_pHardwareContext ); +#endif + + // A special path used to tick the front buffer while loading on the 360 + DEFINE_QUEUED_CALL_4( SetNonInteractivePacifierTexture, ITexture *, float, float, float, IMatRenderContext, m_pHardwareContext ); + DEFINE_QUEUED_CALL_2( SetNonInteractiveTempFullscreenBuffer, ITexture *, MaterialNonInteractiveMode_t, IMatRenderContext, m_pHardwareContext ); + DEFINE_QUEUED_CALL_1( EnableNonInteractiveMode, MaterialNonInteractiveMode_t, IMatRenderContext, m_pHardwareContext ); + DEFINE_QUEUED_CALL_0( RefreshFrontBufferNonInteractive, IMatRenderContext, m_pHardwareContext ); + + //-------------------------------------------------------- + // Memory allocation calls for queued mesh, et. al. + //-------------------------------------------------------- + byte *AllocVertices( int nVerts, int nVertexSize ); + uint16 *AllocIndices( int nIndices ); + CPrimList *AllocPrimLists( int nPrimLists ); + byte *ReallocVertices( byte *pVerts, int nVertsOld, int nVertsNew, int nVertexSize ); + uint16 *ReallocIndices( uint16 *pIndices, int nIndicesOld, int nIndicesNew ); + void FreeVertices( byte *pVerts, int nVerts, int nVertexSize ); + void FreeIndices( uint16 *pIndices, int nIndices ); + void FreePrimLists( CPrimList * ); + + //-------------------------------------------------------- + // debug logging - no-op in queued context + //-------------------------------------------------------- + virtual void Printf( PRINTF_FORMAT_STRING const char *fmt, ... ) {}; + virtual void PrintfVA( char *fmt, va_list vargs ){}; + virtual float Knob( char *knobname, float *setvalue=NULL ) { return 0.0f; }; + +#ifdef DX_TO_GL_ABSTRACTION + void DoStartupShaderPreloading( void ) {}; +#endif + +private: + void QueueMatrixSync(); + + //friend class CMatQueuedMesh; + friend class CCallQueueExternal; + + CMatCallQueue m_queue; + CMatQueuedMesh *m_pQueuedMesh; + + CMatRenderContextBase *m_pHardwareContext; + + int m_iRenderDepth; + int m_WidthBackBuffer, m_HeightBackBuffer; + int m_nBoneCount; + MaterialFogMode_t m_FogMode; + float m_flFogStart; + float m_flFogEnd; + float m_flFogZ; + float m_flFogMaxDensity; + color24 m_FogColor; + + CMemoryStack m_Vertices; + CMemoryStack m_Indices; + + class CCallQueueExternal : public ICallQueue + { + void QueueFunctorInternal( CFunctor *pFunctor ) + { + GET_OUTER( CMatQueuedRenderContext, m_CallQueueExternal )->m_queue.QueueFunctor( pFunctor ); + pFunctor->Release(); + } + }; + + CCallQueueExternal m_CallQueueExternal; +}; + +//----------------------------------------------------------------------------- + +#include "tier0/memdbgoff.h" + +#endif // CMATQUEUEDRENDERCONTEXT_H diff --git a/materialsystem/cmatrendercontext.cpp b/materialsystem/cmatrendercontext.cpp new file mode 100644 index 0000000..c8f217f --- /dev/null +++ b/materialsystem/cmatrendercontext.cpp @@ -0,0 +1,3157 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//============================================================================= + +#include "pch_materialsystem.h" + +#define MATSYS_INTERNAL + +#include +#include "cmatrendercontext.h" +#include "tier2/renderutils.h" +#include "cmaterialsystem.h" +#include "occlusionquerymgr.h" +#include "texturemanager.h" +#include "IHardwareConfigInternal.h" +#include "ctype.h" + +#include "tier1/fmtstr.h" +#include "togl/rendermechanism.h" + +// NOTE: This must be the last file included!!! +#include "tier0/memdbgon.h" + +//----------------------------------------------------------------------------- + +// FIXME: right now, always keeping shader API in sync, because debug overlays don't seem to work 100% with the delayed matrix loading +#define FORCE_MATRIX_SYNC 1 + +#ifdef VALIDATE_MATRICES +#define ShouldValidateMatrices() true +#else +#define ShouldValidateMatrices() false +#endif + +#ifdef VALIDATE_MATRICES +#define AllowLazyMatrixSync() false +#define ForceSync() ((void)(0)) +#elif defined(FORCE_MATRIX_SYNC) +#define AllowLazyMatrixSync() false +#define ForceSync() ForceSyncMatrix( m_MatrixMode ) +#else +#define AllowLazyMatrixSync() true +#define ForceSync() ((void)(0)) +#endif + +#ifdef _X360 +static bool s_bDirtyDisk = false; +#endif + + +void ValidateMatrices( const VMatrix &m1, const VMatrix &m2, float eps = .001 ) +{ + if ( !ShouldValidateMatrices() ) + return; + + for ( int i = 0; i < 16; i++ ) + { + AssertFloatEquals( m1.Base()[i], m1.Base()[i], eps ); + } +} + + +//----------------------------------------------------------------------------- +// The dirty disk error report function (NOTE: Could be called from any thread!) +//----------------------------------------------------------------------------- +#ifdef _X360 +unsigned ThreadedDirtyDiskErrorDisplay( void *pParam ) +{ + XShowDirtyDiscErrorUI( XBX_GetPrimaryUserId() ); +} +#endif + + +void SpinPresent() +{ + while ( true ) + { + g_pShaderAPI->ClearColor3ub( 0, 0, 0 ); + g_pShaderAPI->ClearBuffers( true, true, true, -1, -1 ); + g_pShaderDevice->Present(); + } +} + +void ReportDirtyDisk() +{ +#ifdef _X360 + s_bDirtyDisk = true; + ThreadHandle_t h = CreateSimpleThread( ThreadedDirtyDiskErrorDisplay, NULL ); + ThreadSetPriority( h, THREAD_PRIORITY_HIGHEST ); + + // If this is being called from the render thread, immediately swap + if ( ( ThreadGetCurrentId() == MaterialSystem()->GetRenderThreadId() ) || + ( ThreadInMainThread() && g_pMaterialSystem->GetThreadMode() != MATERIAL_QUEUED_THREADED ) ) + { + SpinPresent(); + } +#endif +} + + +//----------------------------------------------------------------------------- +// Install dirty disk error reporting function (call after SetMode) +//----------------------------------------------------------------------------- +void SetupDirtyDiskReportFunc() +{ + g_pFullFileSystem->InstallDirtyDiskReportFunc( ReportDirtyDisk ); +} + + +//----------------------------------------------------------------------------- +// Globals +//----------------------------------------------------------------------------- +CMemoryStack CMatRenderContextBase::sm_RenderData[2]; +int CMatRenderContextBase::sm_nRenderLockCount = 0; +int CMatRenderContextBase::sm_nRenderStack = 0; +int CMatRenderContextBase::sm_nInitializeCount = 0; + + +//----------------------------------------------------------------------------- +// Constructor +//----------------------------------------------------------------------------- +CMatRenderContextBase::CMatRenderContextBase() : + m_pMaterialSystem( NULL ), m_RenderTargetStack( 16, 32 ), m_MatrixMode( NUM_MATRIX_MODES ) +{ + int i; + + m_bDirtyViewState = true; + + // Put a special element at the top of the RT stack (indicating back buffer is current top of stack) + // NULL indicates back buffer, -1 indicates full-size viewport +#if !defined( _X360 ) + RenderTargetStackElement_t initialElement = { {NULL, NULL, NULL, NULL}, NULL, 0, 0, -1, -1 }; +#else + RenderTargetStackElement_t initialElement = { {NULL}, NULL, 0, 0, -1, -1 }; +#endif + + + m_RenderTargetStack.Push( initialElement ); + + for ( i = 0; i < MAX_FB_TEXTURES; i++ ) + { + m_pCurrentFrameBufferCopyTexture[i] = NULL; + } + + m_pCurrentMaterial = NULL; + m_pCurrentProxyData = NULL; + m_pUserDefinedLightmap = NULL; + m_HeightClipMode = MATERIAL_HEIGHTCLIPMODE_DISABLE; + m_HeightClipZ = 0.0f; + m_bEnableClipping = true; + m_bFlashlightEnable = false; + m_bFullFrameDepthIsValid = false; + + for ( i = 0; i < NUM_MATRIX_MODES; i++ ) + { + m_MatrixStacks[i].Push(); + m_MatrixStacks[i].Top().matrix.Identity(); + m_MatrixStacks[i].Top().flags |= ( MSF_DIRTY| MSF_IDENTITY ); + } + m_pCurMatrixItem = &m_MatrixStacks[0].Top(); + + m_Viewport.Init( 0, 0, 0, 0 ); + + m_LastSetToneMapScale=Vector(1,1,1); + m_CurToneMapScale=1.0; + m_GoalToneMapScale = 1.0f; +} + + +//----------------------------------------------------------------------------- +// Init, shutdown +//----------------------------------------------------------------------------- +InitReturnVal_t CMatRenderContextBase::Init( ) +{ + MEM_ALLOC_CREDIT(); + if ( !sm_nInitializeCount ) + { + int nSize = 2200 * 1024; + int nCommitSize = 32 * 1024; + +#ifdef SWDS + nSize = nCommitSize = 1024; +#endif + + const char *gamedir = CommandLine()->ParmValue("-game", CommandLine()->ParmValue( "-defaultgamedir", "hl2" ) ); + if ( gamedir && !Q_stricmp( "garrysmod", gamedir ) ) + { + nSize = 4400 * 1024; + } + + sm_RenderData[0].Init( nSize, nCommitSize, 0, 32 ); + sm_RenderData[1].Init( nSize, nCommitSize, 0, 32 ); + sm_nRenderStack = 0; + sm_nRenderLockCount = 0; + } + ++sm_nInitializeCount; + return INIT_OK; +} + +void CMatRenderContextBase::Shutdown( ) +{ + Assert( sm_nInitializeCount >= 0 ); + if ( --sm_nInitializeCount == 0 ) + { + sm_RenderData[0].Term(); + sm_RenderData[1].Term(); + } +} + +void CMatRenderContextBase::CompactMemory() +{ + if ( sm_nRenderLockCount ) + { + DevWarning( "CMatRenderContext: Trying to compact with render data still locked!\n" ); + sm_nRenderLockCount = 0; + } + sm_RenderData[0].FreeAll(); + sm_RenderData[1].FreeAll(); +} + +void CMatRenderContextBase::MarkRenderDataUnused( bool bFrameBegin ) +{ + if ( sm_nRenderLockCount ) + { + DevWarning( "CMatRenderContext: Trying to clear render data with render data still locked (%d)!\n", sm_nRenderLockCount ); + sm_nRenderLockCount = 0; + } + + + // JAY: DO NOT MERGE FROM TF2 - L4D HAS CHANGED THE UNDERLYING INTERFACE IN A WAY THAT DOESN'T REQUIRE THIS +#if 0 + // Switch stacks + if ( bFrameBegin ) + { + sm_nRenderStack = 1 - sm_nRenderStack; + } + + // Clear the new stack +#ifdef _DEBUG + memset( sm_RenderData[sm_nRenderStack].GetBase(), 0xFF, RenderDataSizeUsed() ); +#endif + sm_RenderData[ sm_nRenderStack ].FreeAll( false ); +#else + // Just for TF2, don't free the stack until the end of frame. TF2 Allocates render data and holds it over the lock + // period because we haven't revised the studiorender interface yet to change patterns. + // Switch stacks + if ( bFrameBegin ) + { + sm_nRenderStack = 1 - sm_nRenderStack; + // Clear the new stack +#ifdef _DEBUG + memset( sm_RenderData[sm_nRenderStack].GetBase(), 0xFF, RenderDataSizeUsed() ); +#endif + sm_RenderData[ sm_nRenderStack ].FreeAll( false ); + } +#endif + + +} + +int CMatRenderContextBase::RenderDataSizeUsed() const +{ + return sm_RenderData[sm_nRenderStack].GetUsed(); +} + +bool CMatRenderContextBase::IsRenderData( const void *pData ) const +{ + intp nData = (intp)pData; + intp nBaseAddress = (intp)sm_RenderData[sm_nRenderStack].GetBase(); + intp nLastAddress = nBaseAddress + RenderDataSizeUsed(); + return ( nData == 0 ) || ( nData >= nBaseAddress && nData < nLastAddress ); +} + + +//----------------------------------------------------------------------------- +// debug logging - empty in base class +//----------------------------------------------------------------------------- + +void CMatRenderContextBase::PrintfVA( char *fmt, va_list vargs ) +{ +} + +void CMatRenderContextBase::Printf( const char *fmt, ... ) +{ +} + +float CMatRenderContextBase::Knob( char *knobname, float *setvalue ) +{ + return 0.0f; +} + + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- + +#define g_pShaderAPI Cannot_use_ShaderAPI_in_CMatRenderContextBase + +void CMatRenderContextBase::InitializeFrom( CMatRenderContextBase *pInitialState ) +{ + int i; + + m_pCurrentMaterial = pInitialState->m_pCurrentMaterial; + m_pCurrentProxyData = pInitialState->m_pCurrentProxyData; + m_lightmapPageID = pInitialState->m_lightmapPageID; + m_pUserDefinedLightmap = pInitialState->m_pUserDefinedLightmap; + m_pLocalCubemapTexture = pInitialState->m_pLocalCubemapTexture; + + memcpy( m_pCurrentFrameBufferCopyTexture, pInitialState->m_pCurrentFrameBufferCopyTexture, MAX_FB_TEXTURES * sizeof(ITexture *) ); + + m_bEnableClipping = pInitialState->m_bEnableClipping; + + m_HeightClipMode = pInitialState->m_HeightClipMode; + m_HeightClipZ = pInitialState->m_HeightClipZ; + + m_pBoundMorph = pInitialState->m_pBoundMorph; // not reference counted? + + m_RenderTargetStack.Clear(); + m_RenderTargetStack.EnsureCapacity( pInitialState->m_RenderTargetStack.Count() ); + + for ( i = 0; i < pInitialState->m_RenderTargetStack.Count(); i++ ) + { + m_RenderTargetStack.Push( pInitialState->m_RenderTargetStack[i] ); + } + + m_MatrixMode = pInitialState->m_MatrixMode; + for ( i = 0; i < NUM_MATRIX_MODES; i++ ) + { + m_MatrixStacks[i].CopyFrom( pInitialState->m_MatrixStacks[i] ); + } + + m_bFlashlightEnable = pInitialState->m_bFlashlightEnable; + + m_FrameTime = pInitialState->m_FrameTime; + m_GoalToneMapScale = pInitialState->m_GoalToneMapScale; + m_CurToneMapScale = pInitialState->m_CurToneMapScale; + m_LastSetToneMapScale = pInitialState->m_LastSetToneMapScale; +} + +void CMatRenderContextBase::Bind( IMaterial *iMaterial, void *proxyData ) +{ + IMaterialInternal *material = static_cast( iMaterial ); + + if ( !material ) + { + Warning( "Programming error: CMatRenderContext::Bind: NULL material\n" ); + material = static_cast( g_pErrorMaterial ); + } + material = material->GetRealTimeVersion(); //always work with the real time versions of materials internally + + if ( GetCurrentMaterialInternal() != material ) + { + if( !material->IsPrecached() ) + { + DevWarning( "Binding uncached material \"%s\", artificially incrementing refcount\n", material->GetName() ); + material->ArtificialAddRef(); + material->Precache(); + } + SetCurrentMaterialInternal(material); + } + + SetCurrentProxy( proxyData ); +} + +void CMatRenderContextBase::BindLightmapPage( int lightmapPageID ) +{ + m_lightmapPageID = lightmapPageID; + +} + +void CMatRenderContextBase::SetRenderTargetEx( int nRenderTargetID, ITexture *pNewTarget ) +{ + // Verify valid top of RT stack + Assert ( m_RenderTargetStack.Count() > 0 ); + + // Reset the top of stack to the new target with old viewport + RenderTargetStackElement_t newTOS = m_RenderTargetStack.Top(); + newTOS.m_pRenderTargets[nRenderTargetID] = pNewTarget; + m_RenderTargetStack.Pop( ); + m_RenderTargetStack.Push( newTOS ); +} + +void CMatRenderContextBase::BindLocalCubemap( ITexture *pTexture ) +{ + if( pTexture ) + { + m_pLocalCubemapTexture = pTexture; + } + else + { + m_pLocalCubemapTexture = TextureManager()->ErrorTexture(); + } +} + +ITexture *CMatRenderContextBase::GetRenderTarget( void ) +{ + if (m_RenderTargetStack.Count() > 0) + { + return m_RenderTargetStack.Top().m_pRenderTargets[0]; + } + else + { + return NULL; // should this be something else, since NULL indicates back buffer? + } +} + +ITexture *CMatRenderContextBase::GetRenderTargetEx( int nRenderTargetID ) +{ + // Verify valid top of stack + Assert ( m_RenderTargetStack.Count() > 0 ); + + // Top of render target stack + ITexture *pTexture = m_RenderTargetStack.Top().m_pRenderTargets[ nRenderTargetID ]; + return pTexture; +} + +void CMatRenderContextBase::SetFrameBufferCopyTexture( ITexture *pTexture, int textureIndex ) +{ + if( textureIndex < 0 || textureIndex > MAX_FB_TEXTURES ) + { + Assert( 0 ); + return; + } + + // FIXME: Do I need to increment/decrement ref counts here, or assume that the app is going to do it? + m_pCurrentFrameBufferCopyTexture[textureIndex] = pTexture; +} + +ITexture *CMatRenderContextBase::GetFrameBufferCopyTexture( int textureIndex ) +{ + if( textureIndex < 0 || textureIndex > MAX_FB_TEXTURES ) + { + Assert( 0 ); + return NULL; // FIXME! This should return the error texture. + } + return m_pCurrentFrameBufferCopyTexture[textureIndex]; +} + + +void CMatRenderContextBase::MatrixMode( MaterialMatrixMode_t mode ) +{ + Assert( m_MatrixStacks[mode].Count() ); + m_MatrixMode = mode; + m_pCurMatrixItem = &m_MatrixStacks[mode].Top(); +} + +void CMatRenderContextBase::CurrentMatrixChanged() +{ + if ( m_MatrixMode == MATERIAL_VIEW ) + { + m_bDirtyViewState = true; + m_bDirtyViewProjState = true; + } + else if ( m_MatrixMode == MATERIAL_PROJECTION ) + { + m_bDirtyViewProjState = true; + } +} + +void CMatRenderContextBase::PushMatrix() +{ + CUtlStack &curStack = m_MatrixStacks[ m_MatrixMode ]; + Assert( curStack.Count() ); + int iNew = curStack.Push(); + curStack[ iNew ] = curStack[ iNew - 1 ]; + m_pCurMatrixItem = &curStack.Top(); + CurrentMatrixChanged(); +} + +void CMatRenderContextBase::PopMatrix() +{ + Assert( m_MatrixStacks[m_MatrixMode].Count() > 1 ); + m_MatrixStacks[ m_MatrixMode ].Pop(); + m_pCurMatrixItem = &m_MatrixStacks[m_MatrixMode].Top(); + CurrentMatrixChanged(); +} + +void CMatRenderContextBase::LoadMatrix( const VMatrix& matrix ) +{ + m_pCurMatrixItem->matrix = matrix; + m_pCurMatrixItem->flags = MSF_DIRTY; // clearing identity implicitly + CurrentMatrixChanged(); +} + +void CMatRenderContextBase::LoadMatrix( const matrix3x4_t& matrix ) +{ + m_pCurMatrixItem->matrix = matrix; + m_pCurMatrixItem->flags = MSF_DIRTY; // clearing identity implicitly + CurrentMatrixChanged(); +} + +void CMatRenderContextBase::MultMatrix( const VMatrix& matrix ) +{ + VMatrix result; + + MatrixMultiply( matrix, m_pCurMatrixItem->matrix, result ); + m_pCurMatrixItem->matrix = result; + m_pCurMatrixItem->flags = MSF_DIRTY; // clearing identity implicitly + CurrentMatrixChanged(); +} + +void CMatRenderContextBase::MultMatrix( const matrix3x4_t& matrix ) +{ + CMatRenderContextBase::MultMatrix( VMatrix( matrix ) ); +} + +void CMatRenderContextBase::MultMatrixLocal( const VMatrix& matrix ) +{ + VMatrix result; + MatrixMultiply( m_pCurMatrixItem->matrix, matrix, result ); + m_pCurMatrixItem->matrix = result; + m_pCurMatrixItem->flags = MSF_DIRTY; // clearing identity implicitly + CurrentMatrixChanged(); +} + +void CMatRenderContextBase::MultMatrixLocal( const matrix3x4_t& matrix ) +{ + CMatRenderContextBase::MultMatrixLocal( VMatrix( matrix ) ); +} + +void CMatRenderContextBase::LoadIdentity() +{ + // FIXME: possibly track is identity so can call shader API LoadIdentity() later instead of LoadMatrix()? + m_pCurMatrixItem->matrix.Identity(); + m_pCurMatrixItem->flags = ( MSF_DIRTY | MSF_IDENTITY ); + CurrentMatrixChanged(); +} + +void CMatRenderContextBase::Ortho( double left, double top, double right, double bottom, double zNear, double zFar ) +{ + MatrixOrtho( m_pCurMatrixItem->matrix, left, top, right, bottom, zNear, zFar ); + m_pCurMatrixItem->flags = MSF_DIRTY; +} + +void CMatRenderContextBase::PerspectiveX( double flFovX, double flAspect, double flZNear, double flZFar ) +{ + MatrixPerspectiveX( m_pCurMatrixItem->matrix, flFovX, flAspect, flZNear, flZFar ); + m_pCurMatrixItem->flags = MSF_DIRTY; +} + +void CMatRenderContextBase::PerspectiveOffCenterX( double flFovX, double flAspect, double flZNear, double flZFar, double bottom, double top, double left, double right ) +{ + MatrixPerspectiveOffCenterX( m_pCurMatrixItem->matrix, flFovX, flAspect, flZNear, flZFar, bottom, top, left, right ); + m_pCurMatrixItem->flags = MSF_DIRTY; +} + +void CMatRenderContextBase::PickMatrix( int x, int y, int nWidth, int nHeight ) +{ + int vx, vy, vwidth, vheight; + GetViewport( vx, vy, vwidth, vheight ); + + // Compute the location of the pick region in projection space... + float px = 2.0 * (float)(x - vx) / (float)vwidth - 1; + float py = 2.0 * (float)(y - vy)/ (float)vheight - 1; + float pw = 2.0 * (float)nWidth / (float)vwidth; + float ph = 2.0 * (float)nHeight / (float)vheight; + + // we need to translate (px, py) to the origin + // and scale so (pw,ph) -> (2, 2) + VMatrix mat; + MatrixSetIdentity( mat ); + mat.m[0][0] = 2.0 / pw; + mat.m[1][1] = 2.0 / ph; + mat.m[0][3] = -2.0 * px / pw; + mat.m[1][3] = -2.0 * py / ph; + + CMatRenderContextBase::MultMatrixLocal( mat ); +} + +void CMatRenderContextBase::Rotate( float flAngle, float x, float y, float z ) +{ + MatrixRotate( m_pCurMatrixItem->matrix, Vector( x, y, z ), flAngle ); + m_pCurMatrixItem->flags = MSF_DIRTY; +} + +void CMatRenderContextBase::Translate( float x, float y, float z ) +{ + MatrixTranslate( m_pCurMatrixItem->matrix, Vector( x, y, z ) ); + m_pCurMatrixItem->flags = MSF_DIRTY; +} + +void CMatRenderContextBase::Scale( float x, float y, float z ) +{ + VMatrix mat; + MatrixBuildScale( mat, x, y, z ); + CMatRenderContextBase::MultMatrixLocal( mat ); +} + +void CMatRenderContextBase::GetMatrix( MaterialMatrixMode_t matrixMode, VMatrix *pMatrix ) +{ + CUtlStack &stack = m_MatrixStacks[ matrixMode ]; + + if ( !stack.Count() ) + { + pMatrix->Identity(); + return; + } + + *pMatrix = stack.Top().matrix; +} + +void CMatRenderContextBase::GetMatrix( MaterialMatrixMode_t matrixMode, matrix3x4_t *pMatrix ) +{ + CUtlStack &stack = m_MatrixStacks[ matrixMode ]; + + if ( !stack.Count() ) + { + SetIdentityMatrix( *pMatrix ); + return; + } + + *pMatrix = stack.Top().matrix.As3x4(); +} + +void CMatRenderContextBase::RecomputeViewState() +{ + if ( !m_bDirtyViewState ) + return; + m_bDirtyViewState = false; + + // FIXME: Cache this off to make it less expensive? + matrix3x4_t viewMatrix; + GetMatrix( MATERIAL_VIEW, &viewMatrix ); + m_vecViewOrigin.x = + -( viewMatrix[0][3] * viewMatrix[0][0] + + viewMatrix[1][3] * viewMatrix[1][0] + + viewMatrix[2][3] * viewMatrix[2][0] ); + m_vecViewOrigin.y = + -( viewMatrix[0][3] * viewMatrix[0][1] + + viewMatrix[1][3] * viewMatrix[1][1] + + viewMatrix[2][3] * viewMatrix[2][1] ); + m_vecViewOrigin.z = + -( viewMatrix[0][3] * viewMatrix[0][2] + + viewMatrix[1][3] * viewMatrix[1][2] + + viewMatrix[2][3] * viewMatrix[2][2] ); + + // FIXME Implement computation of m_vecViewForward, etc + m_vecViewForward.Init(); + m_vecViewRight.Init(); + + // FIXME: Is this correct? + m_vecViewUp.Init( viewMatrix[1][0], viewMatrix[1][1], viewMatrix[1][2] ); +} + +void CMatRenderContextBase::GetWorldSpaceCameraPosition( Vector *pCameraPos ) +{ + RecomputeViewState(); + VectorCopy( m_vecViewOrigin, *pCameraPos ); +} + +void CMatRenderContextBase::GetWorldSpaceCameraVectors( Vector *pVecForward, Vector *pVecRight, Vector *pVecUp ) +{ + RecomputeViewState(); + + // FIXME Implement computation of m_vecViewForward + Assert( 0 ); + + if ( pVecForward ) + { + VectorCopy( m_vecViewForward, *pVecForward ); + } + if ( pVecRight ) + { + VectorCopy( m_vecViewRight, *pVecRight ); + } + if ( pVecUp ) + { + VectorCopy( m_vecViewUp, *pVecUp ); + } +} + +void *CMatRenderContextBase::LockRenderData( int nSizeInBytes ) +{ + MEM_ALLOC_CREDIT(); + void *pDest = sm_RenderData[ sm_nRenderStack ].Alloc( nSizeInBytes, false ); + if ( !pDest ) + { + ExecuteNTimes( 10, Warning("MaterialSystem: Out of memory in render data!\n") ); + } + AddRefRenderData(); + return pDest; +} + +void CMatRenderContextBase::UnlockRenderData( void *pData ) +{ + ReleaseRenderData(); +} + +void CMatRenderContextBase::AddRefRenderData() +{ + ++sm_nRenderLockCount; +} + +void CMatRenderContextBase::ReleaseRenderData() +{ + --sm_nRenderLockCount; + Assert( sm_nRenderLockCount >= 0 ); + if ( sm_nRenderLockCount == 0 ) + { + OnRenderDataUnreferenced(); + } +} + +void CMatRenderContextBase::SyncMatrices() +{ +} + +void CMatRenderContextBase::SyncMatrix( MaterialMatrixMode_t mode ) +{ +} + +void CMatRenderContextBase::SetHeightClipMode( enum MaterialHeightClipMode_t heightClipMode ) +{ + if( m_HeightClipMode != heightClipMode ) + { + m_HeightClipMode = heightClipMode; + UpdateHeightClipUserClipPlane(); + /*if ( HardwareConfig()->MaxUserClipPlanes() >= 1 && !HardwareConfig()->UseFastClipping()) + { + UpdateHeightClipUserClipPlane(); + } + else + { + g_pShaderAPI->SetHeightClipMode( heightClipMode ); + }*/ + } +} + +void CMatRenderContextBase::SetHeightClipZ( float z ) +{ + if( z != m_HeightClipZ ) + { + m_HeightClipZ = z; + UpdateHeightClipUserClipPlane(); + } + + // FIXME! : Need to move user clip plane support back to pre-dx9 cards (all of the pixel shaders + // have texkill in them. . blich.) + + /*if ( HardwareConfig()->MaxUserClipPlanes() >= 1 && !HardwareConfig()->UseFastClipping() ) + { + UpdateHeightClipUserClipPlane(); + } + else + { + g_pShaderAPI->SetHeightClipZ( z ); + }*/ +} + +bool CMatRenderContextBase::EnableClipping( bool bEnable ) +{ + if( bEnable != m_bEnableClipping ) + { + m_bEnableClipping = bEnable; + ApplyCustomClipPlanes(); + + return !bEnable; + } + return bEnable; +} + +void CMatRenderContextBase::Viewport( int x, int y, int width, int height ) +{ + // Verify valid top of RT stack + Assert ( m_RenderTargetStack.Count() > 0 ); + + // Reset the top of stack to the new viewport + RenderTargetStackElement_t newTOS; + memcpy(&newTOS,&(m_RenderTargetStack.Top()),sizeof(newTOS)); + newTOS.m_nViewX = x; + newTOS.m_nViewY = y; + newTOS.m_nViewW = width; + newTOS.m_nViewH = height; + + m_RenderTargetStack.Pop( ); + m_RenderTargetStack.Push( newTOS ); +} + + +//----------------------------------------------------------------------------- +// This version will push the current rendertarget + current viewport onto the stack +//----------------------------------------------------------------------------- +void CMatRenderContextBase::PushRenderTargetAndViewport( ) +{ + // Necessary to push the stack top onto itself; realloc could happen otherwise + m_RenderTargetStack.EnsureCapacity( m_RenderTargetStack.Count() + 1 ); + m_RenderTargetStack.Push( m_RenderTargetStack.Top() ); + CommitRenderTargetAndViewport(); +} + + +//----------------------------------------------------------------------------- +// Pushes a render target on the render target stack. Without a specific +// viewport also being pushed, this function uses dummy values which indicate +// that the viewport should span the the full render target and pushes +// the RenderTargetStackElement_t onto the stack +// +// The push and pop methods also implicitly set the render target to the new top of stack +// +// NULL for pTexture indicates rendering to the back buffer +//----------------------------------------------------------------------------- +void CMatRenderContextBase::PushRenderTargetAndViewport( ITexture *pTexture ) +{ + // Just blindly push the data on the stack with flags indicating full bounds +#if !defined( _X360 ) + RenderTargetStackElement_t element = { {pTexture, NULL, NULL, NULL}, 0, 0, -1, -1 }; +#else + RenderTargetStackElement_t element = { {pTexture}, 0, 0, -1, -1 }; +#endif + m_RenderTargetStack.Push( element ); + CommitRenderTargetAndViewport(); +} + + +//----------------------------------------------------------------------------- +// Pushes a render target on the render target stack and sets the viewport +// +// NULL for pTexture indicates rendering to the back buffer +// +// The push and pop methods also implicitly set the render target to the new top of stack +//----------------------------------------------------------------------------- +void CMatRenderContextBase::PushRenderTargetAndViewport( ITexture *pTexture, int nViewX, int nViewY, int nViewW, int nViewH ) +{ + CMatRenderContextBase::PushRenderTargetAndViewport( pTexture, NULL, nViewX, nViewY, nViewW, nViewH ); +} + + +//----------------------------------------------------------------------------- +// Pushes a render target on the render target stack and sets the viewport +// The push and pop methods also implicitly set the render target to the new top of stack +//----------------------------------------------------------------------------- +void CMatRenderContextBase::PushRenderTargetAndViewport( ITexture *pTexture, ITexture *pDepthTexture, int nViewX, int nViewY, int nViewW, int nViewH ) +{ + // Just blindly push the data on the stack +#if !defined( _X360 ) + RenderTargetStackElement_t element = { {pTexture, NULL, NULL, NULL}, pDepthTexture, nViewX, nViewY, nViewW, nViewH }; +#else + RenderTargetStackElement_t element = { {pTexture}, pDepthTexture, nViewX, nViewY, nViewW, nViewH }; +#endif + m_RenderTargetStack.Push( element ); + CommitRenderTargetAndViewport(); +} + + +//----------------------------------------------------------------------------- +// Pops from the render target stack +// Also implicitly sets the render target to the new top of stack +//----------------------------------------------------------------------------- +void CMatRenderContextBase::PopRenderTargetAndViewport( void ) +{ + // Check for underflow + if ( m_RenderTargetStack.Count() == 0 ) + { + Assert( !"CMatRenderContext::PopRenderTargetAndViewport: Stack is empty!!!" ); + return; + } + + // Changelist #266217 added this to main/src/materialsystem. + Flush(); + + // Remove the top of stack + m_RenderTargetStack.Pop( ); + CommitRenderTargetAndViewport(); +} + +void CMatRenderContextBase::RecomputeViewProjState() +{ + if ( m_bDirtyViewProjState ) + { + VMatrix viewMatrix, projMatrix; + + // FIXME: Should consider caching this upon change for projection or view matrix. + GetMatrix( MATERIAL_VIEW, &viewMatrix ); + GetMatrix( MATERIAL_PROJECTION, &projMatrix ); + m_viewProjMatrix = projMatrix * viewMatrix; + m_bDirtyViewProjState = false; + } +} + +//----------------------------------------------------------------------------- +// This returns the diameter of the sphere in pixels based on +// the current model, view, + projection matrices and viewport. +//----------------------------------------------------------------------------- +float CMatRenderContextBase::ComputePixelDiameterOfSphere( const Vector& vecAbsOrigin, float flRadius ) +{ + RecomputeViewState(); + RecomputeViewProjState(); + // This is sort of faked, but it's faster that way + // FIXME: Also, there's a much faster way to do this with similar triangles + // but I want to make sure it exactly matches the current matrices, so + // for now, I do it this conservative way + Vector4D testPoint1, testPoint2; + VectorMA( vecAbsOrigin, flRadius, m_vecViewUp, testPoint1.AsVector3D() ); + VectorMA( vecAbsOrigin, -flRadius, m_vecViewUp, testPoint2.AsVector3D() ); + testPoint1.w = testPoint2.w = 1.0f; + + Vector4D clipPos1, clipPos2; + Vector4DMultiply( m_viewProjMatrix, testPoint1, clipPos1 ); + Vector4DMultiply( m_viewProjMatrix, testPoint2, clipPos2 ); + if (clipPos1.w >= 0.001f) + { + clipPos1.y /= clipPos1.w; + } + else + { + clipPos1.y *= 1000; + } + if (clipPos2.w >= 0.001f) + { + clipPos2.y /= clipPos2.w; + } + else + { + clipPos2.y *= 1000; + } + int vx, vy, vwidth, vheight; + GetViewport( vx, vy, vwidth, vheight ); + + // The divide-by-two here is because y goes from -1 to 1 in projection space + return vheight * fabs( clipPos2.y - clipPos1.y ) / 2.0f; +} + +ConVar mat_accelerate_adjust_exposure_down( "mat_accelerate_adjust_exposure_down", "3.0", FCVAR_CHEAT ); +ConVar mat_hdr_manual_tonemap_rate( "mat_hdr_manual_tonemap_rate", "1.0" ); +ConVar mat_hdr_tonemapscale( "mat_hdr_tonemapscale", "1.0", FCVAR_CHEAT ); +ConVar mat_tonemap_algorithm( "mat_tonemap_algorithm", "1", FCVAR_CHEAT, "0 = Original Algorithm 1 = New Algorithm" ); + +void CMatRenderContextBase::TurnOnToneMapping(void) +{ + if ( ( HardwareConfig()->GetHDRType() != HDR_TYPE_NONE ) && ( m_FrameTime > 0.0f ) ) + { + float elapsed_time = m_FrameTime; + float goalScale = m_GoalToneMapScale; + float rate = mat_hdr_manual_tonemap_rate.GetFloat(); + + if ( mat_tonemap_algorithm.GetInt() == 1 ) + { + rate *= 2.0f; // Default 2x for the new tone mapping algorithm so it feels the same as the original + } + + if ( rate == 0.0f ) // Zero indicates instantaneous tonemap scaling + { + m_CurToneMapScale = goalScale; + } + else + { + if ( goalScale < m_CurToneMapScale ) + { + float acc_exposure_adjust = mat_accelerate_adjust_exposure_down.GetFloat(); + + // Adjust at up to 4x rate when over-exposed. + rate = min( ( acc_exposure_adjust * rate ), FLerp( rate, ( acc_exposure_adjust * rate ), 0.0f, 1.5f, ( m_CurToneMapScale - goalScale ) ) ); + } + + float flRateTimesTime = rate * elapsed_time; + if ( mat_tonemap_algorithm.GetInt() == 1 ) + { + // For the new tone mapping algorithm, limit the rate based on the number of bins to + // help reduce the tone map scalar "riding the wave" of the histogram re-building + + //Warning( "flRateTimesTime = %.4f", flRateTimesTime ); + flRateTimesTime = min( flRateTimesTime, ( 1.0f / 16.0f ) * 0.25f ); // 16 is number of HDR sample bins defined in viewpostprocess.cpp + //Warning( " --> %.4f\n", flRateTimesTime ); + } + + float alpha = max( 0.0f, min( 1.0f, flRateTimesTime ) ); + m_CurToneMapScale = ( goalScale * alpha ) + ( m_CurToneMapScale * ( 1.0f - alpha ) ); + + if ( !IsFinite( m_CurToneMapScale ) ) + { + Assert( 0 ); + m_CurToneMapScale = goalScale; + } + } + + SetToneMappingScaleLinear( Vector( m_CurToneMapScale, m_CurToneMapScale, m_CurToneMapScale ) ); + m_LastSetToneMapScale = Vector( m_CurToneMapScale, m_CurToneMapScale, m_CurToneMapScale ); + } +} + +void CMatRenderContextBase::ResetToneMappingScale(float sc) +{ + m_CurToneMapScale = sc; + SetToneMappingScaleLinear( Vector( m_CurToneMapScale, m_CurToneMapScale, m_CurToneMapScale ) ); + m_LastSetToneMapScale = Vector( m_CurToneMapScale, m_CurToneMapScale, m_CurToneMapScale ); + // mat_hdr_tonemapscale.SetValue(1.0f); + m_GoalToneMapScale = 1; +} + +void CMatRenderContextBase::SetGoalToneMappingScale( float monoscale) +{ + Assert( IsFinite( monoscale ) ); + if( IsFinite( monoscale ) ) + { + m_GoalToneMapScale = monoscale; + } +} + +Vector CMatRenderContextBase::GetToneMappingScaleLinear( void ) +{ + if ( HardwareConfig()->GetHDRType() == HDR_TYPE_NONE ) + return Vector( 1.0f, 1.0f, 1.0f ); + else + return m_LastSetToneMapScale; +} + +void CMatRenderContextBase::OnAsyncCreateTextureFromRenderTarget( ITexture* pSrcRt, const char** ppDstName, IAsyncTextureOperationReceiver* pRecipient ) +{ + Assert( pSrcRt != NULL ); + Assert( pRecipient != NULL ); + Assert( ppDstName != NULL && *ppDstName != NULL); + + // Bump the ref count on the recipient before handing it off. This ensures the receiver won't go away before we have completed our work. + pSrcRt->AddRef(); + pRecipient->AddRef(); + + // Also, need to allocate a copy of the string and use that one s.t. the caller doesn't have to worry about it. + char* pDstNameCopy = new char[ V_strlen( *ppDstName ) + 1 ]; + V_strcpy( pDstNameCopy, *ppDstName ); + ( *ppDstName ) = pDstNameCopy; +} + +// Map and unmap a texture. The pRecipient->OnAsyncMapComplete is called when complete. +void CMatRenderContextBase::OnAsyncMap( ITextureInternal* pTexToMap, IAsyncTextureOperationReceiver* pRecipient, void* pExtraArgs ) +{ + Assert( pTexToMap != NULL ); + Assert( pRecipient != NULL ); + + pTexToMap->AddRef(); + pRecipient->AddRef(); +} + +void CMatRenderContextBase::OnAsyncUnmap( ITextureInternal* pTexToUnmap ) +{ + Assert( pTexToUnmap != NULL ); + + pTexToUnmap->AddRef(); +} + +void CMatRenderContextBase::OnAsyncCopyRenderTargetToStagingTexture( ITexture* pDst, ITexture* pSrc, IAsyncTextureOperationReceiver* pRecipient ) +{ + Assert( pDst != NULL ); + Assert( pSrc != NULL ); + Assert( pRecipient != NULL ); + + pDst->AddRef(); + pSrc->AddRef(); + pRecipient->AddRef(); +} + +#undef g_pShaderAPI + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +CMatRenderContext::CMatRenderContext() +{ + g_FrameNum = 0; + m_pBatchIndices = NULL; + m_pBatchMesh = NULL; + m_pCurrentIndexBuffer = NULL; + m_pMorphRenderContext = NULL; + m_NonInteractiveMode = MATERIAL_NON_INTERACTIVE_MODE_NONE; +} + +InitReturnVal_t CMatRenderContext::Init( CMaterialSystem *pMaterialSystem ) +{ + InitReturnVal_t nRetVal = BaseClass::Init(); + if ( nRetVal != INIT_OK ) + return nRetVal; + + m_pMaterialSystem = pMaterialSystem; + + m_pBoundMorph = NULL; + + // Create some lovely textures + m_pLocalCubemapTexture = TextureManager()->ErrorTexture(); + m_pMorphRenderContext = g_pMorphMgr->AllocateRenderContext(); + + return INIT_OK; +} + +void CMatRenderContext::Shutdown( ) +{ + if ( m_pUserDefinedLightmap ) + { + m_pUserDefinedLightmap->DecrementReferenceCount(); + m_pUserDefinedLightmap = NULL; + } + + if ( m_pMorphRenderContext ) + { + g_pMorphMgr->FreeRenderContext( m_pMorphRenderContext ); + m_pMorphRenderContext = NULL; + } + + BaseClass::Shutdown(); +} + +void CMatRenderContext::OnReleaseShaderObjects() +{ + // alt-tab unbinds the morph + m_pBoundMorph = NULL; +} + +#ifdef DX_TO_GL_ABSTRACTION +void CMatRenderContext::DoStartupShaderPreloading( void ) +{ + g_pShaderDevice->DoStartupShaderPreloading(); +} +#endif + +void CMatRenderContext::TextureManagerUpdate() +{ + TextureManager()->Update(); +} + + +inline IMaterialInternal *CMatRenderContext::GetMaterialInternal( MaterialHandle_t h ) const +{ + return GetMaterialSystem()->GetMaterialInternal( h ); +} + +inline IMaterialInternal *CMatRenderContext::GetDrawFlatMaterial() +{ + return GetMaterialSystem()->GetDrawFlatMaterial(); +} + +inline IMaterialInternal *CMatRenderContext::GetBufferClearObeyStencil( int i ) +{ + return GetMaterialSystem()->GetBufferClearObeyStencil(i ); +} + +inline ShaderAPITextureHandle_t CMatRenderContext::GetFullbrightLightmapTextureHandle() const +{ + return GetMaterialSystem()->GetFullbrightLightmapTextureHandle(); +} + +inline ShaderAPITextureHandle_t CMatRenderContext::GetFullbrightBumpedLightmapTextureHandle() const +{ + return GetMaterialSystem()->GetFullbrightBumpedLightmapTextureHandle(); +} + +inline ShaderAPITextureHandle_t CMatRenderContext::GetBlackTextureHandle() const +{ + return GetMaterialSystem()->GetBlackTextureHandle(); +} + +inline ShaderAPITextureHandle_t CMatRenderContext::GetFlatNormalTextureHandle() const +{ + return GetMaterialSystem()->GetFlatNormalTextureHandle(); +} + +inline ShaderAPITextureHandle_t CMatRenderContext::GetGreyTextureHandle() const +{ + return GetMaterialSystem()->GetGreyTextureHandle(); +} + +inline ShaderAPITextureHandle_t CMatRenderContext::GetGreyAlphaZeroTextureHandle() const +{ + return GetMaterialSystem()->GetGreyAlphaZeroTextureHandle(); +} + +inline ShaderAPITextureHandle_t CMatRenderContext::GetWhiteTextureHandle() const +{ + return GetMaterialSystem()->GetWhiteTextureHandle(); +} + +inline const CMatLightmaps *CMatRenderContext::GetLightmaps() const +{ + return GetMaterialSystem()->GetLightmaps(); +} + +inline CMatLightmaps *CMatRenderContext::GetLightmaps() +{ + return GetMaterialSystem()->GetLightmaps(); +} + +inline ShaderAPITextureHandle_t CMatRenderContext::GetMaxDepthTextureHandle() const +{ + return GetMaterialSystem()->GetMaxDepthTextureHandle(); +} + +void CMatRenderContext::BeginRender() +{ +#if 1 // Rick's optimization: not sure this is needed anymore + if ( GetMaterialSystem()->GetThreadMode() != MATERIAL_SINGLE_THREADED ) + { + VPROF_INCREMENT_GROUP_COUNTER( "render/CMatBeginRender", COUNTER_GROUP_TELEMETRY, 1 ); + + TelemetrySetLockName( TELEMETRY_LEVEL1, (char const *)&g_MatSysMutex, "MatSysMutex" ); + + tmTryLock( TELEMETRY_LEVEL1, (char const *)&g_MatSysMutex, "BeginRender" ); + g_MatSysMutex.Lock(); + tmEndTryLock( TELEMETRY_LEVEL1, (char const *)&g_MatSysMutex, TMLR_SUCCESS ); + tmSetLockState( TELEMETRY_LEVEL1, (char const *)&g_MatSysMutex, TMLS_LOCKED, "BeginRender" ); + } +#endif +} + +void CMatRenderContext::EndRender() +{ +#if 1 // Rick's optimization: not sure this is needed anymore + if ( GetMaterialSystem()->GetThreadMode() != MATERIAL_SINGLE_THREADED ) + { + g_MatSysMutex.Unlock(); + tmSetLockState( TELEMETRY_LEVEL1, (char const *)&g_MatSysMutex, TMLS_RELEASED, "EndRender" ); + } +#endif +} + +void CMatRenderContext::Flush( bool flushHardware ) +{ + VPROF( "CMatRenderContextBase::Flush" ); + + g_pShaderAPI->FlushBufferedPrimitives(); + if ( IsPC() && flushHardware ) + { + g_pShaderAPI->FlushBufferedPrimitives(); + } +} + +bool CMatRenderContext::TestMatrixSync( MaterialMatrixMode_t mode ) +{ + if ( !ShouldValidateMatrices() ) + { + return true; + } + + VMatrix transposeMatrix, matrix; + g_pShaderAPI->GetMatrix( mode, (float*)transposeMatrix.m ); + MatrixTranspose( transposeMatrix, matrix ); + + ValidateMatrices( matrix, m_MatrixStacks[mode].Top().matrix ); + + return true; +} + +void CMatRenderContext::MatrixMode( MaterialMatrixMode_t mode ) +{ + CMatRenderContextBase::MatrixMode( mode ); + g_pShaderAPI->MatrixMode( mode ); + if ( ShouldValidateMatrices() ) + { + TestMatrixSync( mode ); + } + +} +void CMatRenderContext::PushMatrix() +{ + if ( ShouldValidateMatrices() ) + { + TestMatrixSync( m_MatrixMode ); + } + + CMatRenderContextBase::PushMatrix(); + g_pShaderAPI->PushMatrix(); + + if ( ShouldValidateMatrices() ) + { + TestMatrixSync( m_MatrixMode ); + } +} + +void CMatRenderContext::PopMatrix() +{ + if ( ShouldValidateMatrices() ) + { + TestMatrixSync( m_MatrixMode ); + } + + CMatRenderContextBase::PopMatrix(); + g_pShaderAPI->PopMatrix(); + + if ( ShouldValidateMatrices() ) + { + TestMatrixSync( m_MatrixMode ); + } +} + +void CMatRenderContext::LoadMatrix( const VMatrix& matrix ) +{ + CMatRenderContextBase::LoadMatrix( matrix ); + ForceSync(); + if ( ShouldValidateMatrices() ) + { + VMatrix transposeMatrix; + MatrixTranspose( matrix, transposeMatrix ); + g_pShaderAPI->LoadMatrix( transposeMatrix.Base() ); + TestMatrixSync( m_MatrixMode ); + } +} + +void CMatRenderContext::LoadMatrix( const matrix3x4_t& matrix ) +{ + CMatRenderContextBase::LoadMatrix( matrix ); + ForceSync(); + if ( ShouldValidateMatrices() ) + { + VMatrix transposeMatrix; + MatrixTranspose( VMatrix(matrix), transposeMatrix ); + g_pShaderAPI->LoadMatrix( transposeMatrix.Base() ); + TestMatrixSync( m_MatrixMode ); + } +} + +void CMatRenderContext::MultMatrix( const VMatrix& matrix ) +{ + CMatRenderContextBase::MultMatrix( matrix ); + ForceSync(); + if ( ShouldValidateMatrices() ) + { + VMatrix transposeMatrix; + MatrixTranspose( matrix, transposeMatrix ); + g_pShaderAPI->MultMatrix( transposeMatrix.Base() ); + TestMatrixSync( m_MatrixMode ); + } +} + +void CMatRenderContext::MultMatrix( const matrix3x4_t& matrix ) +{ + CMatRenderContextBase::MultMatrix( VMatrix( matrix ) ); + ForceSync(); + if ( ShouldValidateMatrices() ) + { + VMatrix transposeMatrix; + MatrixTranspose( VMatrix(matrix), transposeMatrix ); + g_pShaderAPI->MultMatrix( transposeMatrix.Base() ); + TestMatrixSync( m_MatrixMode ); + } +} + +void CMatRenderContext::MultMatrixLocal( const VMatrix& matrix ) +{ + CMatRenderContextBase::MultMatrixLocal( matrix ); + ForceSync(); + if ( ShouldValidateMatrices() ) + { + VMatrix transposeMatrix; + MatrixTranspose( matrix, transposeMatrix ); + g_pShaderAPI->MultMatrixLocal( transposeMatrix.Base() ); + TestMatrixSync( m_MatrixMode ); + } +} + +void CMatRenderContext::MultMatrixLocal( const matrix3x4_t& matrix ) +{ + CMatRenderContextBase::MultMatrixLocal( VMatrix( matrix ) ); + ForceSync(); + if ( ShouldValidateMatrices() ) + { + VMatrix transposeMatrix; + MatrixTranspose( VMatrix(matrix), transposeMatrix ); + g_pShaderAPI->MultMatrixLocal( transposeMatrix.Base() ); + TestMatrixSync( m_MatrixMode ); + } +} + +void CMatRenderContext::LoadIdentity() +{ + CMatRenderContextBase::LoadIdentity(); + ForceSync(); + if ( ShouldValidateMatrices() ) + { + g_pShaderAPI->LoadIdentity(); + TestMatrixSync( m_MatrixMode ); + } +} + +void CMatRenderContext::Ortho( double left, double top, double right, double bottom, double zNear, double zFar ) +{ + CMatRenderContextBase::Ortho( left, top, right, bottom, zNear, zFar ); + ForceSync(); + if ( ShouldValidateMatrices() ) + { + g_pShaderAPI->Ortho( left, top, right, bottom, zNear, zFar ); + TestMatrixSync( m_MatrixMode ); + } +} + +void CMatRenderContext::PerspectiveX( double flFovX, double flAspect, double flZNear, double flZFar ) +{ + CMatRenderContextBase::PerspectiveX( flFovX, flAspect, flZNear, flZFar ); + ForceSync(); + if ( ShouldValidateMatrices() ) + { + g_pShaderAPI->PerspectiveX( flFovX, flAspect, flZNear, flZFar ); + TestMatrixSync( m_MatrixMode ); + } +} + +void CMatRenderContext::PerspectiveOffCenterX( double flFovX, double flAspect, double flZNear, double flZFar, double bottom, double top, double left, double right ) +{ + CMatRenderContextBase::PerspectiveOffCenterX( flFovX, flAspect, flZNear, flZFar, bottom, top, left, right ); + ForceSync(); + if ( ShouldValidateMatrices() ) + { + g_pShaderAPI->PerspectiveOffCenterX( flFovX, flAspect, flZNear, flZFar, bottom, top, left, right ); + TestMatrixSync( m_MatrixMode ); + } +} + +void CMatRenderContext::PickMatrix( int x, int y, int nWidth, int nHeight ) +{ + CMatRenderContextBase::PickMatrix( x, y, nWidth, nHeight ); + ForceSync(); + if ( ShouldValidateMatrices() ) + { + g_pShaderAPI->PickMatrix( x, y, nWidth, nHeight ); + TestMatrixSync( m_MatrixMode ); + } +} + +void CMatRenderContext::Rotate( float flAngle, float x, float y, float z ) +{ + CMatRenderContextBase::Rotate( flAngle, x, y, z ); + ForceSync(); + if ( ShouldValidateMatrices() ) + { + g_pShaderAPI->Rotate( flAngle, x, y, z ); + TestMatrixSync( m_MatrixMode ); + } +} + +void CMatRenderContext::Translate( float x, float y, float z ) +{ + CMatRenderContextBase::Translate( x, y, z ); + ForceSync(); + if ( ShouldValidateMatrices() ) + { + g_pShaderAPI->Translate( x, y, z ); + TestMatrixSync( m_MatrixMode ); + } +} + +void CMatRenderContext::Scale( float x, float y, float z ) +{ + CMatRenderContextBase::Scale( x, y, z ); + ForceSync(); + if ( ShouldValidateMatrices() ) + { + g_pShaderAPI->Scale( x, y, z ); + TestMatrixSync( m_MatrixMode ); + } +} + +void CMatRenderContext::GetMatrix( MaterialMatrixMode_t matrixMode, VMatrix *pMatrix ) +{ + CMatRenderContextBase::GetMatrix( matrixMode, pMatrix ); + + ForceSync(); + if ( ShouldValidateMatrices() ) + { + VMatrix testMatrix; + VMatrix transposeMatrix; + g_pShaderAPI->GetMatrix( matrixMode, (float*)transposeMatrix.m ); + MatrixTranspose( transposeMatrix, testMatrix ); + + ValidateMatrices( testMatrix, *pMatrix ); + } +} + +void CMatRenderContext::GetMatrix( MaterialMatrixMode_t matrixMode, matrix3x4_t *pMatrix ) +{ + if ( !ShouldValidateMatrices() ) + { + CMatRenderContextBase::GetMatrix( matrixMode, pMatrix ); + } + else + { + VMatrix matrix; + CMatRenderContext::GetMatrix( matrixMode, &matrix ); + *pMatrix = matrix.As3x4(); + } +} + +void CMatRenderContext::SyncMatrices() +{ + if ( !ShouldValidateMatrices() && AllowLazyMatrixSync() ) + { + for( int i = 0; i < NUM_MATRIX_MODES; i++ ) + { + MatrixStackItem_t &top = m_MatrixStacks[i].Top(); + if ( top.flags & MSF_DIRTY ) + { + g_pShaderAPI->MatrixMode( (MaterialMatrixMode_t)i ); + if ( !( top.flags & MSF_IDENTITY ) ) + { + VMatrix transposeTop; + MatrixTranspose( top.matrix, transposeTop ); + g_pShaderAPI->LoadMatrix( transposeTop.Base() ); + } + else + { + g_pShaderAPI->LoadIdentity(); + } + + top.flags &= ~MSF_DIRTY; + } + } + } +} + +void CMatRenderContext::ForceSyncMatrix( MaterialMatrixMode_t mode ) +{ + MatrixStackItem_t &top = m_MatrixStacks[mode].Top(); + if ( top.flags & MSF_DIRTY ) + { + bool bSetMode = ( m_MatrixMode != mode ); + if ( bSetMode ) + { + g_pShaderAPI->MatrixMode( (MaterialMatrixMode_t)mode ); + } + + if ( !( top.flags & MSF_IDENTITY ) ) + { + VMatrix transposeTop; + MatrixTranspose( top.matrix, transposeTop ); + g_pShaderAPI->LoadMatrix( transposeTop.Base() ); + } + else + { + g_pShaderAPI->LoadIdentity(); + } + + if ( bSetMode ) + { + g_pShaderAPI->MatrixMode( (MaterialMatrixMode_t)mode ); + } + + top.flags &= ~MSF_DIRTY; + } +} + +void CMatRenderContext::SyncMatrix( MaterialMatrixMode_t mode ) +{ + if ( !ShouldValidateMatrices() && AllowLazyMatrixSync() ) + { + ForceSyncMatrix( mode ); + } +} + + +//----------------------------------------------------------------------------- +// Swap buffers +//----------------------------------------------------------------------------- +void CMatRenderContext::SwapBuffers() +{ + g_pMorphMgr->AdvanceFrame(); + g_pOcclusionQueryMgr->AdvanceFrame(); + g_pShaderDevice->Present(); + +#ifdef _X360 + if ( s_bDirtyDisk ) + { + SpinPresent(); + } +#endif +} + + +//----------------------------------------------------------------------------- +// Clears the render data after we're done with it +//----------------------------------------------------------------------------- +void CMatRenderContext::OnRenderDataUnreferenced() +{ + MarkRenderDataUnused( false ); +} + + +//----------------------------------------------------------------------------- +// Custom clip planes +//----------------------------------------------------------------------------- +void CMatRenderContext::PushCustomClipPlane( const float *pPlane ) +{ + PlaneStackElement psePlane; + memcpy( psePlane.fValues, pPlane, sizeof( float ) * 4 ); + psePlane.bHack_IsHeightClipPlane = false; + m_CustomClipPlanes.AddToTail( psePlane ); //we're doing this as a UtlVector so height clip planes never change their cached index + ApplyCustomClipPlanes(); +} + +void CMatRenderContext::PopCustomClipPlane( void ) +{ + Assert( m_CustomClipPlanes.Count() ); + + //remove the endmost non-height plane found + int i; + for( i = m_CustomClipPlanes.Count(); --i >= 0; ) + { + if( m_CustomClipPlanes[i].bHack_IsHeightClipPlane == false ) + { + m_CustomClipPlanes.Remove(i); + break; + } + } + Assert( i != -1 ); //only the height clip plane was found, which means this pop had no associated push + ApplyCustomClipPlanes(); +} + +void CMatRenderContext::ApplyCustomClipPlanes( void ) +{ + int iMaxClipPlanes = HardwareConfig()->MaxUserClipPlanes(); + int iCustomPlanes; + + if( m_bEnableClipping ) + iCustomPlanes = m_CustomClipPlanes.Count(); + else + iCustomPlanes = 0; + + float fFakePlane[4]; + unsigned int iFakePlaneVal = 0xFFFFFFFF; + fFakePlane[0] = fFakePlane[1] = fFakePlane[2] = fFakePlane[3] = *((float *)&iFakePlaneVal); + + SyncMatrices(); + + if( iMaxClipPlanes >= 1 && !HardwareConfig()->UseFastClipping() ) + { + //yay, we get to be the cool clipping club + if( iMaxClipPlanes >= iCustomPlanes ) + { + int i; + for( i = 0; i < iCustomPlanes; ++i ) + { + g_pShaderAPI->SetClipPlane( i, m_CustomClipPlanes[i].fValues ); + g_pShaderAPI->EnableClipPlane( i, true ); + } + for( ; i < iMaxClipPlanes; ++i ) //disable unused planes + { + g_pShaderAPI->EnableClipPlane( i, false ); + g_pShaderAPI->SetClipPlane( i, fFakePlane ); + } + } + else + { + int iCustomPlaneOffset = iCustomPlanes - iMaxClipPlanes; + + //can't enable them all + for( int i = iCustomPlaneOffset; i < iCustomPlanes; ++i ) + { + g_pShaderAPI->SetClipPlane( i % iMaxClipPlanes, m_CustomClipPlanes[i].fValues ); + g_pShaderAPI->EnableClipPlane( i % iMaxClipPlanes, true ); + } + } + } + else + { + //hmm, at most we can make 1 clip plane work + if( iCustomPlanes == 0 ) + { + //no planes at all + g_pShaderAPI->EnableFastClip( false ); + g_pShaderAPI->SetFastClipPlane( fFakePlane ); + } + else + { + //we have to wire the topmost plane into the fast clipping scheme + g_pShaderAPI->EnableFastClip( true ); + g_pShaderAPI->SetFastClipPlane( m_CustomClipPlanes[iCustomPlanes - 1].fValues ); + } + } +} + + +//----------------------------------------------------------------------------- +// Creates/destroys morph data associated w/ a particular material +//----------------------------------------------------------------------------- +IMorph *CMatRenderContext::CreateMorph( MorphFormat_t format, const char *pDebugName ) +{ + Assert( format != 0 ); + IMorphInternal *pMorph = g_pMorphMgr->CreateMorph( ); + pMorph->Init( format, pDebugName ); + return pMorph; +} + +void CMatRenderContext::DestroyMorph( IMorph *pMorph ) +{ + g_pMorphMgr->DestroyMorph( static_cast(pMorph) ); +} + +void CMatRenderContext::BindMorph( IMorph *pMorph ) +{ + IMorphInternal *pMorphInternal = static_cast(pMorph); + + if ( m_pBoundMorph != pMorphInternal ) + { + g_pShaderAPI->FlushBufferedPrimitives(); + + m_pBoundMorph = pMorphInternal; + + bool bEnableHWMorph = false; + if ( pMorphInternal == MATERIAL_MORPH_DECAL ) + { + bEnableHWMorph = true; + } + else if ( pMorphInternal ) + { + bEnableHWMorph = true; + pMorphInternal->Bind( m_pMorphRenderContext ); + } + g_pShaderAPI->EnableHWMorphing( bEnableHWMorph ); + } +} + +IMesh* CMatRenderContext::GetDynamicMesh( bool buffered, IMesh* pVertexOverride, IMesh* pIndexOverride, IMaterial *pAutoBind ) +{ + VPROF_ASSERT_ACCOUNTED( "CMatRenderContext::GetDynamicMesh" ); + if( pAutoBind ) + { + Bind( pAutoBind, NULL ); + } + + if ( pVertexOverride ) + { + if ( CompressionType( pVertexOverride->GetVertexFormat() ) != VERTEX_COMPRESSION_NONE ) + { + // UNDONE: support compressed dynamic meshes if needed (pro: less VB memory, con: time spent compressing) + DebuggerBreak(); + return NULL; + } + } + + // For anything more than 1 bone, imply the last weight from the 1 - the sum of the others. + int nCurrentBoneCount = GetCurrentNumBones(); + Assert( nCurrentBoneCount <= 4 ); + if ( nCurrentBoneCount > 1 ) + { + --nCurrentBoneCount; + } + + return g_pShaderAPI->GetDynamicMesh( GetCurrentMaterialInternal(), nCurrentBoneCount, + buffered, pVertexOverride, pIndexOverride); +} + +IMesh* CMatRenderContext::GetDynamicMeshEx( VertexFormat_t vertexFormat, bool bBuffered, IMesh* pVertexOverride, IMesh* pIndexOverride, IMaterial *pAutoBind ) +{ + VPROF_ASSERT_ACCOUNTED( "CMatRenderContext::GetDynamicMesh" ); + if( pAutoBind ) + { + Bind( pAutoBind, NULL ); + } + + if ( pVertexOverride ) + { + if ( CompressionType( pVertexOverride->GetVertexFormat() ) != VERTEX_COMPRESSION_NONE ) + { + // UNDONE: support compressed dynamic meshes if needed (pro: less VB memory, con: time spent compressing) + DebuggerBreak(); + return NULL; + } + } + + // For anything more than 1 bone, imply the last weight from the 1 - the sum of the others. + // FIXME: this seems wrong - in common_vs_fxc.h, we only infer the last weight if we have 3 (not 2) + int nCurrentBoneCount = GetCurrentNumBones(); + Assert( nCurrentBoneCount <= 4 ); + if ( nCurrentBoneCount > 1 ) + { + --nCurrentBoneCount; + } + + return g_pShaderAPI->GetDynamicMeshEx( GetCurrentMaterialInternal(), vertexFormat, nCurrentBoneCount, + bBuffered, pVertexOverride, pIndexOverride ); +} + + +//----------------------------------------------------------------------------- +// Deals with depth range +//----------------------------------------------------------------------------- +void CMatRenderContext::DepthRange( float zNear, float zFar ) +{ + m_Viewport.m_flMinZ = zNear; + m_Viewport.m_flMaxZ = zFar; + g_pShaderAPI->SetViewports( 1, &m_Viewport ); +} + + +//----------------------------------------------------------------------------- +// Private utility function to actually commit the top of the RT/Viewport stack +// to the device. Only called by the push and pop routines above. +//----------------------------------------------------------------------------- +void CMatRenderContext::CommitRenderTargetAndViewport( void ) +{ + Assert( m_RenderTargetStack.Count() > 0 ); + + const RenderTargetStackElement_t &element = m_RenderTargetStack.Top( ); + + for( int rt=0; rtSetRenderTargetEx(rt); // No texture parameter here indicates back buffer + + if ( IsPC() ) + { + Assert( ImageLoader::SizeInBytes( g_pShaderDevice->GetBackBufferFormat() ) <= 4 ); + g_pShaderAPI->EnableLinearColorSpaceFrameBuffer( false ); + } + + if (rt == 0) // the first rt sets the viewport + { + // If either dimension is negative, set to full bounds of back buffer + if ( (element.m_nViewW < 0) || (element.m_nViewH < 0) ) + { + m_Viewport.m_nTopLeftX = 0; + m_Viewport.m_nTopLeftY = 0; + g_pShaderAPI->GetBackBufferDimensions( m_Viewport.m_nWidth, m_Viewport.m_nHeight ); + g_pShaderAPI->SetViewports( 1, &m_Viewport ); + } + else // use the bounds in the element + { + m_Viewport.m_nTopLeftX = element.m_nViewX; + m_Viewport.m_nTopLeftY = element.m_nViewY; + m_Viewport.m_nWidth = element.m_nViewW; + m_Viewport.m_nHeight = element.m_nViewH; + g_pShaderAPI->SetViewports( 1, &m_Viewport ); + } + } + } + else // We're dealing with a texture + { + ITextureInternal *pTexInt = static_cast(element.m_pRenderTargets[rt]); + pTexInt->SetRenderTarget( rt, element.m_pDepthTexture ); + + if (rt == 0) + { + if ( IsPC() ) + { + if( element.m_pRenderTargets[rt]->GetImageFormat() == IMAGE_FORMAT_RGBA16161616F ) + { + g_pShaderAPI->EnableLinearColorSpaceFrameBuffer( true ); + } + else + { + g_pShaderAPI->EnableLinearColorSpaceFrameBuffer( false ); + } + } + + // If either dimension is negative, set to full bounds of target + if ( (element.m_nViewW < 0) || (element.m_nViewH < 0) ) + { + m_Viewport.m_nTopLeftX = 0; + m_Viewport.m_nTopLeftY = 0; + m_Viewport.m_nWidth = element.m_pRenderTargets[rt]->GetActualWidth(); + m_Viewport.m_nHeight = element.m_pRenderTargets[rt]->GetActualHeight(); + g_pShaderAPI->SetViewports( 1, &m_Viewport ); + } + else // use the bounds passed in + { + m_Viewport.m_nTopLeftX = element.m_nViewX; + m_Viewport.m_nTopLeftY = element.m_nViewY; + m_Viewport.m_nWidth = element.m_nViewW; + m_Viewport.m_nHeight = element.m_nViewH; + g_pShaderAPI->SetViewports( 1, &m_Viewport ); + } + } + } + } +} + + +void CMatRenderContext::SetFrameBufferCopyTexture( ITexture *pTexture, int textureIndex ) +{ + if( textureIndex < 0 || textureIndex > MAX_FB_TEXTURES ) + { + Assert( 0 ); + return; + } + if( m_pCurrentFrameBufferCopyTexture[textureIndex] != pTexture ) + { + g_pShaderAPI->FlushBufferedPrimitives(); + } + // FIXME: Do I need to increment/decrement ref counts here, or assume that the app is going to do it? + m_pCurrentFrameBufferCopyTexture[textureIndex] = pTexture; +} + +void CMatRenderContext::BindLocalCubemap( ITexture *pTexture ) +{ + ITexture *pPreviousTexture = m_pLocalCubemapTexture; + + CMatRenderContextBase::BindLocalCubemap( pTexture ); + + if( m_pLocalCubemapTexture != pPreviousTexture ) + { + g_pShaderAPI->FlushBufferedPrimitives(); + } +} + +void CMatRenderContext::SetNonInteractivePacifierTexture( ITexture *pTexture, float flNormalizedX, float flNormalizedY, float flNormalizedSize ) +{ + m_pNonInteractivePacifier.Init( pTexture ); + m_flNormalizedX = flNormalizedX; + m_flNormalizedY = flNormalizedY; + m_flNormalizedSize = flNormalizedSize; +} + +void CMatRenderContext::SetNonInteractiveTempFullscreenBuffer( ITexture *pTexture, MaterialNonInteractiveMode_t mode ) +{ + if ( mode != MATERIAL_NON_INTERACTIVE_MODE_NONE ) + { + m_pNonInteractiveTempFullscreenBuffer[mode].Init( pTexture ); + } +} + +void CMatRenderContext::RefreshFrontBufferNonInteractive() +{ + g_pShaderDevice->RefreshFrontBufferNonInteractive(); +#ifdef _X360 + if ( s_bDirtyDisk ) + { + if ( m_NonInteractiveMode == MATERIAL_NON_INTERACTIVE_MODE_NONE ) + { + SpinPresent(); + } + else + { + while ( true ) + { + g_pShaderDevice->RefreshFrontBufferNonInteractive(); + } + } + } +#endif +} + +void CMatRenderContext::EnableNonInteractiveMode( MaterialNonInteractiveMode_t mode ) +{ + m_NonInteractiveMode = mode; + if ( mode == MATERIAL_NON_INTERACTIVE_MODE_NONE ) + { + g_pShaderDevice->EnableNonInteractiveMode( mode ); + } + else + { + ShaderNonInteractiveInfo_t info; + info.m_flNormalizedX = m_flNormalizedX; + info.m_flNormalizedY = m_flNormalizedY; + info.m_flNormalizedSize = m_flNormalizedSize; + + ITextureInternal *pTexInternal = static_cast( (ITexture*)m_pNonInteractiveTempFullscreenBuffer[mode] ); + info.m_hTempFullscreenTexture = pTexInternal ? + pTexInternal->GetTextureHandle(0) : INVALID_SHADERAPI_TEXTURE_HANDLE; + ITextureInternal *pTexPacifierInternal = static_cast( (ITexture*)m_pNonInteractivePacifier ); + info.m_nPacifierCount = pTexPacifierInternal ? pTexPacifierInternal->GetNumAnimationFrames() : 0; + for ( int i = 0; i < info.m_nPacifierCount; ++i ) + { + info.m_pPacifierTextures[i] = pTexPacifierInternal->GetTextureHandle( i ); + } + g_pShaderDevice->EnableNonInteractiveMode( mode, &info ); + } +} + +void CMatRenderContext::SetRenderTargetEx( int nRenderTargetID, ITexture *pNewTarget ) +{ + // Verify valid top of RT stack + Assert ( m_RenderTargetStack.Count() > 0 ); + + // Grab the old target + ITexture *pOldTarget = m_RenderTargetStack.Top().m_pRenderTargets[nRenderTargetID]; + + CMatRenderContextBase::SetRenderTargetEx( nRenderTargetID, pNewTarget ); + + // If we're actually changing render targets + if( pNewTarget != pOldTarget ) + { + // If we're going to render to the back buffer + if ( pNewTarget == NULL ) + { + if ( nRenderTargetID == 0) // reset viewport on set of rt 0 + { + m_Viewport.m_nTopLeftX = 0; + m_Viewport.m_nTopLeftY = 0; + g_pShaderAPI->GetBackBufferDimensions( m_Viewport.m_nWidth, m_Viewport.m_nHeight ); + g_pShaderAPI->SetViewports( 1, &m_Viewport ); + } + g_pShaderAPI->SetRenderTargetEx( nRenderTargetID ); // No parameter here indicates back buffer + } + else + { + // If we're going to render to a texture + // Make sure the texture is a render target... + bool reset = true; + if (nRenderTargetID==0) + { + // reset vp on change of rt#0 + m_Viewport.m_nTopLeftX = 0; + m_Viewport.m_nTopLeftY = 0; + m_Viewport.m_nWidth = pNewTarget->GetActualWidth(); + m_Viewport.m_nHeight = pNewTarget->GetActualHeight(); + g_pShaderAPI->SetViewports( 1, &m_Viewport ); + } + ITextureInternal *pTexInt = static_cast(pNewTarget); + if ( pTexInt ) + { + reset = !pTexInt->SetRenderTarget( nRenderTargetID ); + if ( reset ) + { + g_pShaderAPI->SetRenderTargetEx( nRenderTargetID ); + } + } + + if( pNewTarget && pNewTarget->GetImageFormat() == IMAGE_FORMAT_RGBA16161616F ) + { + g_pShaderAPI->EnableLinearColorSpaceFrameBuffer( true ); + } + else + { + g_pShaderAPI->EnableLinearColorSpaceFrameBuffer( false ); + } + } + } + CommitRenderTargetAndViewport(); +} + + +void CMatRenderContext::GetRenderTargetDimensions( int &width, int &height ) const +{ + // Target at top of stack + ITexture *pTOS = m_RenderTargetStack.Top().m_pRenderTargets[0]; + + // If top of stack isn't the back buffer, get dimensions from the texture + if ( pTOS != NULL ) + { + width = pTOS->GetActualWidth(); + height = pTOS->GetActualHeight(); + } + else // otherwise, get them from the shader API + { + g_pShaderAPI->GetBackBufferDimensions( width, height ); + } +} + + +//----------------------------------------------------------------------------- +// What are the lightmap dimensions? +//----------------------------------------------------------------------------- +void CMatRenderContext::GetLightmapDimensions( int *w, int *h ) +{ + *w = GetMaterialSystem()->GetLightmapWidth( GetLightmapPage() ); + *h = GetMaterialSystem()->GetLightmapHeight( GetLightmapPage() ); +} + +void CMatRenderContext::DrawScreenSpaceQuad( IMaterial* pMaterial ) +{ + // Despite saying we render a full screen quad, this actually renders a single triangle + // that covers the whole screen. + int w, h; + + GetRenderTargetDimensions( w, h ); + if ( ( w == 0 ) || ( h == 0 ) ) + return; + + // DX9 disagrees about (0, 0) in a render target and (0, 0) in the texture. + // Fix that here by doing a half-pixel offset for the pixel. + // Because we are working in clip space which is 2 units across, the adjustment factor is 1. + float flOffsetW = 1.0f / w; + float flOffsetH = 1.0f / h; + + Bind( pMaterial ); + IMesh* pMesh = GetDynamicMesh( true ); + + CMeshBuilder meshBuilder;; + meshBuilder.Begin( pMesh, MATERIAL_TRIANGLES, 1 ); + + enum { TL, BL, TR, COORDS_COUNT }; + + struct CoordSSQ_t + { + float x, y; + float u, v; + }; + + CoordSSQ_t coords[] = { + { -1.0f - 1.0f * flOffsetW, 1.0f + 1.0f * flOffsetH, 0.0f, 0.0f }, // TL + { -1.0f - 1.0f * flOffsetW, -3.0f + 1.0f * flOffsetH, 0.0f, 2.0f }, // BL + { 3.0f - 1.0f * flOffsetW, 1.0f + 1.0f * flOffsetH, 2.0f, 0.0f }, // TR + }; + + static_assert( ARRAYSIZE( coords ) == COORDS_COUNT, "Unexpected number of coords in triangle, should match enum." ); + + MatrixMode( MATERIAL_VIEW ); + PushMatrix(); + LoadIdentity(); + + MatrixMode( MATERIAL_PROJECTION ); + PushMatrix(); + LoadIdentity(); + + for ( int i = 0; i < COORDS_COUNT; ++i ) + { + meshBuilder.Position3f( coords[ i ].x, coords[ i ].y, 0.0f ); + meshBuilder.Normal3f( 0.0f, 0.0f, 1.0f ); + meshBuilder.TangentS3f( 0.0f, 1.0f, 0.0f ); + meshBuilder.TangentT3f( 1.0f, 0.0f, 0.0f ); + meshBuilder.TexCoord2f( 0, coords[ i ].u, coords[ i ].v ); + + meshBuilder.AdvanceVertex(); + } + + meshBuilder.End(); + pMesh->Draw(); + + MatrixMode( MATERIAL_VIEW ); + PopMatrix(); + + MatrixMode( MATERIAL_PROJECTION ); + PopMatrix(); +} + +void CMatRenderContext::DrawScreenSpaceRectangle( + IMaterial *pMaterial, + int destx, int desty, + int width, int height, + float src_texture_x0, float src_texture_y0, // which texel you want to appear at + // destx/y + float src_texture_x1, float src_texture_y1, // which texel you want to appear at + // destx+width-1, desty+height-1 + int src_texture_width, int src_texture_height, // needed for fixup + void *pClientRenderable, + int nXDice, int nYDice ) // Amount to tessellate the quad +{ + pMaterial = ((IMaterialInternal *)pMaterial)->GetRealTimeVersion(); + + ::DrawScreenSpaceRectangle( pMaterial, destx, desty, width, height, + src_texture_x0, src_texture_y0, src_texture_x1, src_texture_y1, + src_texture_width, src_texture_height, pClientRenderable, nXDice, nYDice ); + return; +} + +static int CompareVertexFormats( VertexFormat_t Fmt1, VertexFormat_t Fmt2 ) +{ + if ( Fmt1 != Fmt2 ) + { + if ( Fmt1 > Fmt2 ) + return 1; + else + return -1; + } + else + return 0; +} + +int CMatRenderContext::CompareMaterialCombos( IMaterial *pMaterial1, IMaterial *pMaterial2, int lightMapID1, int lightMapID2 ) +{ + pMaterial1 = ((IMaterialInternal *)pMaterial1)->GetRealTimeVersion(); //always work with the real time version of materials internally. + pMaterial2 = ((IMaterialInternal *)pMaterial2)->GetRealTimeVersion(); //always work with the real time version of materials internally. + + IMaterialInternal *pMat1 = (IMaterialInternal *)pMaterial1; + IMaterialInternal *pMat2 = (IMaterialInternal *)pMaterial2; + ShaderRenderState_t *pState1 = pMat1->GetRenderState(); + ShaderRenderState_t *pState2 = pMat2->GetRenderState(); + int dPass = pState2->m_pSnapshots->m_nPassCount - pState1->m_pSnapshots->m_nPassCount; + if ( dPass ) + return dPass; + + if ( pState1->m_pSnapshots->m_nPassCount > 1 ) + { + int dFormat = CompareVertexFormats( pMat1->GetVertexFormat(), pMat2->GetVertexFormat() ); + if ( dFormat ) + return dFormat; + } + + for ( int i = 0; i < pState1->m_pSnapshots->m_nPassCount; i++ ) + { + // UNDONE: Compare snapshots in the shaderapi? + int dSnapshot = pState1->m_pSnapshots->m_Snapshot[i] - pState2->m_pSnapshots->m_Snapshot[i]; + if ( dSnapshot ) + { + dSnapshot = g_pShaderAPI->CompareSnapshots( pState1->m_pSnapshots->m_Snapshot[i], pState2->m_pSnapshots->m_Snapshot[i] ); + if ( dSnapshot ) + return dSnapshot; + } + } + + int dFormat = CompareVertexFormats( pMat1->GetVertexFormat(), pMat2->GetVertexFormat() ); + if ( dFormat ) + return dFormat; + + IMaterialVar **pParams1 = pMat1->GetShaderParams(); + IMaterialVar **pParams2 = pMat2->GetShaderParams(); + int nParams1 = pMat1->ShaderParamCount(); + int nParams2 = pMat2->ShaderParamCount(); + int nBaseTexParamType1 = pParams1 && nParams1 > BASETEXTURE ? pParams1[BASETEXTURE]->GetType() : -1; + int nBaseTexParamType2 = pParams2 && nParams2 > BASETEXTURE ? pParams2[BASETEXTURE]->GetType() : -1; + if( nBaseTexParamType1 == MATERIAL_VAR_TYPE_TEXTURE || nBaseTexParamType2 == MATERIAL_VAR_TYPE_TEXTURE ) + { + if( nBaseTexParamType1 != nBaseTexParamType2 ) + { + return nBaseTexParamType2 - nBaseTexParamType1; + } + int dBaseTexture = Q_stricmp( pParams1[BASETEXTURE]->GetTextureValue()->GetName(), pParams2[BASETEXTURE]->GetTextureValue()->GetName() ); + if ( dBaseTexture ) + return dBaseTexture; + } + + int dLightmap = lightMapID1 - lightMapID2; + if ( dLightmap ) + return dLightmap; + + return (int)pMat1 - (int)pMat2; +} + + +void CMatRenderContext::Bind( IMaterial *iMaterial, void *proxyData ) +{ + if ( !iMaterial ) + { + if ( !g_pErrorMaterial ) + return; + Warning( "Programming error: CMatRenderContext::Bind: NULL material\n" ); + iMaterial = g_pErrorMaterial; + } + else + { + iMaterial = iMaterial->CheckProxyReplacement( proxyData ); + } + + IMaterialInternal *material = static_cast( iMaterial ); + material = material->GetRealTimeVersion(); //always work with the real time versions of materials internally + if ( material->GetReferenceCount() <= 0 ) + { + static ConVarRef matTextureListConVar( "mat_texture_list" ); + static ConVarRef matShowWaterTextureConVar( "mat_showwatertextures" ); + + if ( ( !matTextureListConVar.IsValid() || !matTextureListConVar.GetBool() ) && + ( !matShowWaterTextureConVar.IsValid() || !matShowWaterTextureConVar.GetBool() )) + { + Warning( "Material %s has bad reference count %d when being bound\n", material->GetName(), material->GetReferenceCount() ); + // The usual solution for this for global materials that really don't need refcounting is to do material->AddRef(); + Assert( 0 ); + iMaterial = g_pErrorMaterial; + } + } + + if (g_config.bDrawFlat && !material->NoDebugOverride()) + { + material = static_cast( GetDrawFlatMaterial() ); + } + + CMatRenderContextBase::Bind( iMaterial, proxyData ); + + // We've always gotta call the bind proxy + SyncMatrices(); + if ( GetMaterialSystem()->GetThreadMode() == MATERIAL_SINGLE_THREADED ) + { + GetCurrentMaterialInternal()->CallBindProxy( proxyData ); + } + g_pShaderAPI->Bind( GetCurrentMaterialInternal() ); +} + +void CMatRenderContext::CopyRenderTargetToTextureEx( ITexture *pTexture, int nRenderTargetID, Rect_t *pSrcRect, Rect_t *pDstRect ) +{ + if ( !pTexture ) + { + Assert( 0 ); + return; + } + + GetMaterialSystem()->Flush( false ); + ITextureInternal *pTextureInternal = (ITextureInternal *)pTexture; + + if ( IsPC() || !IsX360() ) + { + pTextureInternal->CopyFrameBufferToMe( nRenderTargetID, pSrcRect, pDstRect ); + } + else + { + // X360 only does 1:1 resolves. So we can do full resolves to textures of size + // equal or greater than the viewport trivially. Downsizing is nasty. + Rect_t srcRect; + if ( !pSrcRect ) + { + // build out source rect + pSrcRect = &srcRect; + int x, y, w, h; + GetViewport( x, y, w, h ); + + pSrcRect->x = 0; + pSrcRect->y = 0; + pSrcRect->width = w; + pSrcRect->height = h; + } + + Rect_t dstRect; + if ( !pDstRect ) + { + // build out target rect + pDstRect = &dstRect; + + pDstRect->x = 0; + pDstRect->y = 0; + pDstRect->width = pTexture->GetActualWidth(); + pDstRect->height = pTexture->GetActualHeight(); + } + + if ( pSrcRect->width == pDstRect->width && pSrcRect->height == pDstRect->height ) + { + // 1:1 mapping, no stretching needed, use direct path + pTextureInternal->CopyFrameBufferToMe( nRenderTargetID, pSrcRect, pDstRect ); + return; + } + + if( (pDstRect->x == 0) && (pDstRect->y == 0) && + (pDstRect->width == pTexture->GetActualWidth()) && (pDstRect->height == pTexture->GetActualHeight()) && + (pDstRect->width >= pSrcRect->width) && (pDstRect->height >= pSrcRect->height) ) + { + // Resolve takes up the whole texture, and the texture is large enough to hold the resolve. + // This is turned into a 1:1 resolve within shaderapi by making D3D think the texture is smaller from now on. (Until it resolves from a bigger source) + pTextureInternal->CopyFrameBufferToMe( nRenderTargetID, pSrcRect, pDstRect ); + return; + } + + // currently assuming disparate copies are only for FB blits + // ensure active render target is actually the back buffer + Assert( m_RenderTargetStack.Top().m_pRenderTargets[0] == NULL ); + + // nasty sequence: + // resolve FB surface to matching clone DDR texture + // gpu draw from clone DDR FB texture to disparate RT target surface + // resolve to its matching DDR clone texture + ITextureInternal *pFullFrameFB = (ITextureInternal*)GetMaterialSystem()->FindTexture( "_rt_FullFrameFB", TEXTURE_GROUP_RENDER_TARGET ); + pFullFrameFB->CopyFrameBufferToMe( nRenderTargetID, NULL, NULL ); + + // target texture must be a render target + PushRenderTargetAndViewport( pTexture ); + + // blit FB source to render target + DrawScreenSpaceRectangle( + GetMaterialSystem()->GetRenderTargetBlitMaterial(), + pDstRect->x, pDstRect->y, pDstRect->width, pDstRect->height, + pSrcRect->x, pSrcRect->y, pSrcRect->x+pSrcRect->width-1, pSrcRect->y+pSrcRect->height-1, + pFullFrameFB->GetActualWidth(), pFullFrameFB->GetActualHeight() ); + + // resolve render target to texture + ((ITextureInternal *)pTexture)->CopyFrameBufferToMe( 0, NULL, NULL ); + + // restore render target and viewport + PopRenderTargetAndViewport(); + } +} + +void CMatRenderContext::CopyRenderTargetToTexture( ITexture *pTexture ) +{ + CopyRenderTargetToTextureEx( pTexture, NULL, NULL ); +} + + +void CMatRenderContext::CopyTextureToRenderTargetEx( int nRenderTargetID, ITexture *pTexture, Rect_t *pSrcRect, Rect_t *pDstRect ) +{ + if ( !pTexture ) + { + Assert( 0 ); + return; + } + + GetMaterialSystem()->Flush( false ); + ITextureInternal *pTextureInternal = (ITextureInternal *)pTexture; + + if ( IsPC() || !IsX360() ) + { + pTextureInternal->CopyMeToFrameBuffer( nRenderTargetID, pSrcRect, pDstRect ); + } + else + { + Assert( 0 ); + } +} + + +void CMatRenderContext::ClearBuffers( bool bClearColor, bool bClearDepth, bool bClearStencil ) +{ + int width, height; + GetRenderTargetDimensions( width, height ); + g_pShaderAPI->ClearBuffers( bClearColor, bClearDepth, bClearStencil, width, height ); +} + +void CMatRenderContext::DrawClearBufferQuad( unsigned char r, unsigned char g, unsigned char b, unsigned char a, bool bClearColor, bool bClearAlpha, bool bClearDepth ) +{ + IMaterialInternal *pClearMaterial = GetBufferClearObeyStencil( bClearColor + ( bClearAlpha << 1 ) + ( bClearDepth << 2 ) ); + Bind( pClearMaterial ); + + IMesh* pMesh = GetDynamicMesh( true ); + + MatrixMode( MATERIAL_MODEL ); + PushMatrix(); + LoadIdentity(); + + MatrixMode( MATERIAL_VIEW ); + PushMatrix(); + LoadIdentity(); + + MatrixMode( MATERIAL_PROJECTION ); + PushMatrix(); + LoadIdentity(); + + float flDepth = GetMaterialSystem()->GetConfig().bReverseDepth ? 0.0f : 1.0f; + + CMeshBuilder meshBuilder; + meshBuilder.Begin( pMesh, MATERIAL_QUADS, 1 ); + + //1.1 instead of 1.0 to fix small borders around the edges in full screen with anti-aliasing enabled + meshBuilder.Position3f( -1.1f, -1.1f, flDepth ); + meshBuilder.Color4ub( r, g, b, a ); + meshBuilder.AdvanceVertex(); + + meshBuilder.Position3f( -1.1f, 1.1f, flDepth ); + meshBuilder.Color4ub( r, g, b, a ); + meshBuilder.AdvanceVertex(); + + meshBuilder.Position3f( 1.1f, 1.1f, flDepth ); + meshBuilder.Color4ub( r, g, b, a ); + meshBuilder.AdvanceVertex(); + + meshBuilder.Position3f( 1.1f, -1.1f, flDepth ); + meshBuilder.Color4ub( r, g, b, a ); + meshBuilder.AdvanceVertex(); + + meshBuilder.End(); + pMesh->Draw(); + + MatrixMode( MATERIAL_MODEL ); + PopMatrix(); + + MatrixMode( MATERIAL_VIEW ); + PopMatrix(); + + MatrixMode( MATERIAL_PROJECTION ); + PopMatrix(); +} + +//----------------------------------------------------------------------------- +// Should really be called SetViewport +//----------------------------------------------------------------------------- +void CMatRenderContext::Viewport( int x, int y, int width, int height ) +{ + CMatRenderContextBase::Viewport( x, y, width, height ); + + // If either dimension is negative, set to full bounds of current target + if ( (width < 0) || (height < 0) ) + { + ITexture *pTarget = m_RenderTargetStack.Top().m_pRenderTargets[0]; + + // If target is the back buffer + if ( pTarget == NULL ) + { + m_Viewport.m_nTopLeftX = 0; + m_Viewport.m_nTopLeftY = 0; + g_pShaderAPI->GetBackBufferDimensions( m_Viewport.m_nWidth, m_Viewport.m_nHeight ); + g_pShaderAPI->SetViewports( 1, &m_Viewport ); + } + else // target is a texture + { + m_Viewport.m_nTopLeftX = 0; + m_Viewport.m_nTopLeftY = 0; + m_Viewport.m_nWidth = pTarget->GetActualWidth(); + m_Viewport.m_nHeight = pTarget->GetActualHeight(); + g_pShaderAPI->SetViewports( 1, &m_Viewport ); + } + } + else // use the bounds passed in + { + m_Viewport.m_nTopLeftX = x; + m_Viewport.m_nTopLeftY = y; + m_Viewport.m_nWidth = width; + m_Viewport.m_nHeight = height; + g_pShaderAPI->SetViewports( 1, &m_Viewport ); + } +} + +void CMatRenderContext::GetViewport( int& x, int& y, int& width, int& height ) const +{ + // Verify valid top of RT stack + Assert ( m_RenderTargetStack.Count() > 0 ); + + // Grab the top of stack + const RenderTargetStackElement_t& element = m_RenderTargetStack.Top(); + + // If either dimension is not positive, set to full bounds of current target + if ( (element.m_nViewW <= 0) || (element.m_nViewH <= 0) ) + { + // Viewport origin at target origin + x = y = 0; + + // If target is back buffer + if ( element.m_pRenderTargets[0] == NULL ) + { + g_pShaderAPI->GetBackBufferDimensions( width, height ); + } + else // if target is texture + { + width = element.m_pRenderTargets[0]->GetActualWidth(); + height = element.m_pRenderTargets[0]->GetActualHeight(); + } + } + else // use the bounds from the stack directly + { + x = element.m_nViewX; + y = element.m_nViewY; + width = element.m_nViewW; + height = element.m_nViewH; + } +} + + + +//----------------------------------------------------------------------------- +// Methods related to user clip planes +//----------------------------------------------------------------------------- +void CMatRenderContext::UpdateHeightClipUserClipPlane( void ) +{ + PlaneStackElement pse; + pse.bHack_IsHeightClipPlane = true; + + int iExistingHeightClipPlaneIndex; + for( iExistingHeightClipPlaneIndex = m_CustomClipPlanes.Count(); --iExistingHeightClipPlaneIndex >= 0; ) + { + if( m_CustomClipPlanes[iExistingHeightClipPlaneIndex].bHack_IsHeightClipPlane ) + break; + } + + switch( m_HeightClipMode ) + { + case MATERIAL_HEIGHTCLIPMODE_DISABLE: + if( iExistingHeightClipPlaneIndex != -1 ) + m_CustomClipPlanes.Remove( iExistingHeightClipPlaneIndex ); + break; + case MATERIAL_HEIGHTCLIPMODE_RENDER_ABOVE_HEIGHT: + pse.fValues[0] = 0.0f; + pse.fValues[1] = 0.0f; + pse.fValues[2] = 1.0f; + pse.fValues[3] = m_HeightClipZ; + if( iExistingHeightClipPlaneIndex != -1 ) + { + memcpy( m_CustomClipPlanes.Base() + iExistingHeightClipPlaneIndex, &pse, sizeof( PlaneStackElement ) ); + } + else + { + m_CustomClipPlanes.AddToTail( pse ); + } + break; + case MATERIAL_HEIGHTCLIPMODE_RENDER_BELOW_HEIGHT: + pse.fValues[0] = 0.0f; + pse.fValues[1] = 0.0f; + pse.fValues[2] = -1.0f; + pse.fValues[3] = -m_HeightClipZ; + if( iExistingHeightClipPlaneIndex != -1 ) + { + memcpy( m_CustomClipPlanes.Base() + iExistingHeightClipPlaneIndex, &pse, sizeof( PlaneStackElement ) ); + } + else + { + m_CustomClipPlanes.AddToTail( pse ); + } + break; + }; + + ApplyCustomClipPlanes(); + + /*switch( m_HeightClipMode ) + { + case MATERIAL_HEIGHTCLIPMODE_DISABLE: + g_pShaderAPI->EnableClipPlane( 0, false ); + break; + case MATERIAL_HEIGHTCLIPMODE_RENDER_ABOVE_HEIGHT: + plane[0] = 0.0f; + plane[1] = 0.0f; + plane[2] = 1.0f; + plane[3] = m_HeightClipZ; + g_pShaderAPI->SetClipPlane( 0, plane ); + g_pShaderAPI->EnableClipPlane( 0, true ); + break; + case MATERIAL_HEIGHTCLIPMODE_RENDER_BELOW_HEIGHT: + plane[0] = 0.0f; + plane[1] = 0.0f; + plane[2] = -1.0f; + plane[3] = -m_HeightClipZ; + g_pShaderAPI->SetClipPlane( 0, plane ); + g_pShaderAPI->EnableClipPlane( 0, true ); + break; + }*/ +} + + +//----------------------------------------------------------------------------- +// Lightmap stuff +//----------------------------------------------------------------------------- +void CMatRenderContext::BindLightmapPage( int lightmapPageID ) +{ + if ( m_lightmapPageID == lightmapPageID ) + return; + + // We gotta make sure there's no buffered primitives 'cause this'll + // change the render state. + g_pShaderAPI->FlushBufferedPrimitives(); + + CMatRenderContextBase::BindLightmapPage( lightmapPageID ); +} + +void CMatRenderContext::BindLightmapTexture( ITexture *pLightmapTexture ) +{ + if ( ( m_lightmapPageID == MATERIAL_SYSTEM_LIGHTMAP_PAGE_USER_DEFINED ) && ( m_pUserDefinedLightmap == pLightmapTexture ) ) + return; + + // We gotta make sure there's no buffered primitives 'cause this'll + // change the render state. + g_pShaderAPI->FlushBufferedPrimitives(); + + m_lightmapPageID = MATERIAL_SYSTEM_LIGHTMAP_PAGE_USER_DEFINED; + if ( pLightmapTexture ) + { + pLightmapTexture->IncrementReferenceCount(); + } + if ( m_pUserDefinedLightmap ) + { + m_pUserDefinedLightmap->DecrementReferenceCount(); + } + m_pUserDefinedLightmap = static_cast( pLightmapTexture ); +} + + +void CMatRenderContext::BindLightmap( Sampler_t sampler ) +{ + switch ( m_lightmapPageID ) + { + default: + Assert( ( m_lightmapPageID == 0 && GetLightmaps()->GetNumLightmapPages() == 0 ) || ( m_lightmapPageID >= 0 && m_lightmapPageID < GetLightmaps()->GetNumLightmapPages() ) ); + if( m_lightmapPageID >= 0 && m_lightmapPageID < GetLightmaps()->GetNumLightmapPages() ) + { + g_pShaderAPI->BindTexture( sampler, GetLightmaps()->GetLightmapPageTextureHandle( m_lightmapPageID ) ); + } + break; + + case MATERIAL_SYSTEM_LIGHTMAP_PAGE_USER_DEFINED: + AssertOnce( m_pUserDefinedLightmap ); + g_pShaderAPI->BindTexture( sampler, m_pUserDefinedLightmap->GetTextureHandle( 0 ) ); + break; + + case MATERIAL_SYSTEM_LIGHTMAP_PAGE_WHITE: + BindFullbrightLightmap( sampler ); + break; + + case MATERIAL_SYSTEM_LIGHTMAP_PAGE_WHITE_BUMP: + BindBumpedFullbrightLightmap( sampler ); + break; + } +} + +void CMatRenderContext::BindBumpLightmap( Sampler_t sampler ) +{ + switch ( m_lightmapPageID ) + { + default: + Assert( m_lightmapPageID >= 0 && m_lightmapPageID < GetLightmaps()->GetNumLightmapPages() ); + if( m_lightmapPageID >= 0 && m_lightmapPageID < GetLightmaps()->GetNumLightmapPages() ) + { + g_pShaderAPI->BindTexture( sampler, GetLightmaps()->GetLightmapPageTextureHandle( m_lightmapPageID ) ); + g_pShaderAPI->BindTexture( (Sampler_t)(sampler+1), GetLightmaps()->GetLightmapPageTextureHandle( m_lightmapPageID ) ); + g_pShaderAPI->BindTexture( (Sampler_t)(sampler+2), GetLightmaps()->GetLightmapPageTextureHandle( m_lightmapPageID ) ); + } + break; + case MATERIAL_SYSTEM_LIGHTMAP_PAGE_USER_DEFINED: + AssertOnce( m_pUserDefinedLightmap ); + g_pShaderAPI->BindTexture( sampler, m_pUserDefinedLightmap->GetTextureHandle( 0 ) ); + g_pShaderAPI->BindTexture( (Sampler_t)(sampler+1), m_pUserDefinedLightmap->GetTextureHandle( 0 ) ); + g_pShaderAPI->BindTexture( (Sampler_t)(sampler+2), m_pUserDefinedLightmap->GetTextureHandle( 0 ) ); + break; + case MATERIAL_SYSTEM_LIGHTMAP_PAGE_WHITE_BUMP: + BindBumpedFullbrightLightmap( sampler ); + BindBumpedFullbrightLightmap( (Sampler_t)(sampler+1) ); + BindBumpedFullbrightLightmap( (Sampler_t)(sampler+2) ); + break; + case MATERIAL_SYSTEM_LIGHTMAP_PAGE_WHITE: + BindBumpedFullbrightLightmap( sampler ); + BindBumpedFullbrightLightmap( (Sampler_t)(sampler+1) ); + BindBumpedFullbrightLightmap( (Sampler_t)(sampler+2) ); + break; + } +} + +void CMatRenderContext::BindFullbrightLightmap( Sampler_t sampler ) +{ + g_pShaderAPI->BindTexture( sampler, GetFullbrightLightmapTextureHandle() ); +} + +void CMatRenderContext::BindBumpedFullbrightLightmap( Sampler_t sampler ) +{ + g_pShaderAPI->BindTexture( sampler, GetFullbrightBumpedLightmapTextureHandle() ); +} + + +//----------------------------------------------------------------------------- +// Bind standard textures +//----------------------------------------------------------------------------- +void CMatRenderContext::BindStandardTexture( Sampler_t sampler, StandardTextureId_t id ) +{ + switch ( id ) + { + case TEXTURE_LIGHTMAP: + BindLightmap( sampler ); + return; + + case TEXTURE_LIGHTMAP_BUMPED: + BindBumpLightmap( sampler ); + return; + + case TEXTURE_LIGHTMAP_FULLBRIGHT: + BindFullbrightLightmap( sampler ); + return; + + case TEXTURE_LIGHTMAP_BUMPED_FULLBRIGHT: + BindBumpedFullbrightLightmap( sampler ); + return; + + case TEXTURE_WHITE: + g_pShaderAPI->BindTexture( sampler, GetWhiteTextureHandle() ); + return; + + case TEXTURE_BLACK: + g_pShaderAPI->BindTexture( sampler, GetBlackTextureHandle() ); + return; + + case TEXTURE_GREY: + g_pShaderAPI->BindTexture( sampler, GetGreyTextureHandle() ); + return; + + case TEXTURE_GREY_ALPHA_ZERO: + g_pShaderAPI->BindTexture( sampler, GetGreyAlphaZeroTextureHandle() ); + return; + + case TEXTURE_NORMALMAP_FLAT: + g_pShaderAPI->BindTexture( sampler, GetFlatNormalTextureHandle() ); + return; + + case TEXTURE_NORMALIZATION_CUBEMAP: + TextureManager()->NormalizationCubemap()->Bind( sampler ); + return; + + case TEXTURE_NORMALIZATION_CUBEMAP_SIGNED: + TextureManager()->SignedNormalizationCubemap()->Bind( sampler ); + return; + + case TEXTURE_FRAME_BUFFER_FULL_TEXTURE_0: + case TEXTURE_FRAME_BUFFER_FULL_TEXTURE_1: + { + int nTextureIndex = id - TEXTURE_FRAME_BUFFER_FULL_TEXTURE_0; + if( m_pCurrentFrameBufferCopyTexture[ nTextureIndex ] ) + { + ( ( ITextureInternal * )m_pCurrentFrameBufferCopyTexture[ nTextureIndex ] )->Bind( sampler ); + } + } + return; + + case TEXTURE_COLOR_CORRECTION_VOLUME_0: + case TEXTURE_COLOR_CORRECTION_VOLUME_1: + case TEXTURE_COLOR_CORRECTION_VOLUME_2: + case TEXTURE_COLOR_CORRECTION_VOLUME_3: + { + ITextureInternal *pTexture = TextureManager()->ColorCorrectionTexture( id - TEXTURE_COLOR_CORRECTION_VOLUME_0 ); + if( pTexture ) + { + pTexture->Bind( sampler ); + } + } + return; + + case TEXTURE_SHADOW_NOISE_2D: + TextureManager()->ShadowNoise2D()->Bind( sampler ); + return; + + case TEXTURE_IDENTITY_LIGHTWARP: + TextureManager()->IdentityLightWarp()->Bind( sampler ); + return; + + case TEXTURE_MORPH_ACCUMULATOR: + g_pMorphMgr->MorphAccumulator()->Bind( sampler ); + return; + + case TEXTURE_MORPH_WEIGHTS: + g_pMorphMgr->MorphWeights()->Bind( sampler ); + return; + + case TEXTURE_FRAME_BUFFER_FULL_DEPTH: + if( m_bFullFrameDepthIsValid ) + TextureManager()->FullFrameDepthTexture()->Bind( sampler ); + else + g_pShaderAPI->BindTexture( sampler, GetMaxDepthTextureHandle() ); + return; + + case TEXTURE_DEBUG_LUXELS: + TextureManager()->DebugLuxels2D()->Bind( sampler ); + return; + + default: + Assert(0); + } +} + +void CMatRenderContext::BindStandardVertexTexture( VertexTextureSampler_t sampler, StandardTextureId_t id ) +{ + switch ( id ) + { + case TEXTURE_MORPH_ACCUMULATOR: + g_pMorphMgr->MorphAccumulator()->BindVertexTexture( sampler ); + return; + + case TEXTURE_MORPH_WEIGHTS: + g_pMorphMgr->MorphWeights()->BindVertexTexture( sampler ); + return; + + default: + Assert(0); + } +} + +void CMatRenderContext::GetStandardTextureDimensions( int *pWidth, int *pHeight, StandardTextureId_t id ) +{ + ITexture *pTexture = NULL; + switch ( id ) + { + case TEXTURE_LIGHTMAP: + case TEXTURE_LIGHTMAP_BUMPED: + case TEXTURE_LIGHTMAP_FULLBRIGHT: + case TEXTURE_LIGHTMAP_BUMPED_FULLBRIGHT: + // NOTE: Doesn't exactly work since we may be in fullbright mode +// GetLightmapDimensions( pWidth, pHeight ); +// break; + + case TEXTURE_WHITE: + case TEXTURE_BLACK: + case TEXTURE_GREY: + case TEXTURE_GREY_ALPHA_ZERO: + case TEXTURE_NORMALMAP_FLAT: + default: + Assert( 0 ); + Warning( "GetStandardTextureDimensions: still unimplemented for this type!\n" ); + *pWidth = *pHeight = -1; + break; + + case TEXTURE_NORMALIZATION_CUBEMAP: + pTexture = TextureManager()->NormalizationCubemap(); + break; + + case TEXTURE_NORMALIZATION_CUBEMAP_SIGNED: + pTexture = TextureManager()->SignedNormalizationCubemap(); + break; + + case TEXTURE_FRAME_BUFFER_FULL_TEXTURE_0: + case TEXTURE_FRAME_BUFFER_FULL_TEXTURE_1: + { + int nTextureIndex = id - TEXTURE_FRAME_BUFFER_FULL_TEXTURE_0; + pTexture = m_pCurrentFrameBufferCopyTexture[ nTextureIndex ]; + } + break; + + case TEXTURE_COLOR_CORRECTION_VOLUME_0: + case TEXTURE_COLOR_CORRECTION_VOLUME_1: + case TEXTURE_COLOR_CORRECTION_VOLUME_2: + case TEXTURE_COLOR_CORRECTION_VOLUME_3: + pTexture = TextureManager()->ColorCorrectionTexture( id - TEXTURE_COLOR_CORRECTION_VOLUME_0 ); + break; + + case TEXTURE_SHADOW_NOISE_2D: + pTexture = TextureManager()->ShadowNoise2D(); + break; + + case TEXTURE_IDENTITY_LIGHTWARP: + pTexture = TextureManager()->IdentityLightWarp(); + return; + + case TEXTURE_MORPH_ACCUMULATOR: + pTexture = g_pMorphMgr->MorphAccumulator(); + break; + + case TEXTURE_MORPH_WEIGHTS: + pTexture = g_pMorphMgr->MorphWeights(); + break; + + case TEXTURE_DEBUG_LUXELS: + pTexture = TextureManager()->DebugLuxels2D(); + break; + } + + if ( pTexture ) + { + *pWidth = pTexture->GetActualWidth(); + *pHeight = pTexture->GetActualHeight(); + } + else + { + Warning( "GetStandardTextureDimensions: Couldn't find the texture to get the dimensions!\n" ); + *pWidth = *pHeight = -1; + } +} + +void CMatRenderContext::FogColor3f( float r, float g, float b ) +{ + unsigned char fogColor[3]; + fogColor[0] = clamp( (int)(r * 255.0f), 0, 255 ); + fogColor[1] = clamp( (int)(g * 255.0f), 0, 255 ); + fogColor[2] = clamp( (int)(b * 255.0f), 0, 255 ); + g_pShaderAPI->SceneFogColor3ub( fogColor[0], fogColor[1], fogColor[2] ); +} + +void CMatRenderContext::FogColor3fv( const float* rgb ) +{ + unsigned char fogColor[3]; + fogColor[0] = clamp( (int)(rgb[0] * 255.0f), 0, 255 ); + fogColor[1] = clamp( (int)(rgb[1] * 255.0f), 0, 255 ); + fogColor[2] = clamp( (int)(rgb[2] * 255.0f), 0, 255 ); + g_pShaderAPI->SceneFogColor3ub( fogColor[0], fogColor[1], fogColor[2] ); +} + + + +void CMatRenderContext::SetFlashlightMode( bool bEnable ) +{ + if( bEnable != m_bFlashlightEnable ) + { + g_pShaderAPI->FlushBufferedPrimitives(); + m_bFlashlightEnable = bEnable; + } +} + +bool CMatRenderContext::GetFlashlightMode( ) const +{ + return m_bFlashlightEnable; +} + +void CMatRenderContext::SetFlashlightStateEx( const FlashlightState_t &state, const VMatrix &worldToTexture, ITexture *pFlashlightDepthTexture ) +{ + g_pShaderAPI->SetFlashlightStateEx( state, worldToTexture, pFlashlightDepthTexture ); + if ( IsPC() && g_config.dxSupportLevel <= 70 ) + { + // Going to go ahead and set a single hardware light here to do all lighting except for + // the spotlight falloff function, which is done with a texture. + SetAmbientLight( 0.0f, 0.0f, 0.0f ); + static Vector4D blackCube[6]; + int i; + for( i = 0; i < 6; i++ ) + { + blackCube[i].Init( 0.0f, 0.0f, 0.0f, 0.0f ); + } + SetAmbientLightCube( blackCube ); + + // Disable all the lights except for the first one. + for( i = 1; i < HardwareConfig()->MaxNumLights(); ++i ) + { + LightDesc_t desc; + desc.m_Type = MATERIAL_LIGHT_DISABLE; + SetLight( i, desc ); + } + + LightDesc_t desc; + desc.m_Type = MATERIAL_LIGHT_POINT; + desc.m_Attenuation0 = state.m_fConstantAtten; + desc.m_Attenuation1 = state.m_fLinearAtten; + desc.m_Attenuation2 = state.m_fQuadraticAtten; + // flashlightfixme: I don't know why this scale has to be here to get fixed function lighting to work. + desc.m_Color.x = state.m_Color[0] * 17000.0f; + desc.m_Color.y = state.m_Color[1] * 17000.0f; + desc.m_Color.z = state.m_Color[2] * 17000.0f; + desc.m_Position = state.m_vecLightOrigin; + + QAngle angles; + QuaternionAngles( state.m_quatOrientation, angles ); + AngleVectors( angles, &desc.m_Direction ); + + desc.m_Range = state.m_FarZ; + desc.m_Falloff = 0.0f; + SetLight( 0, desc ); + } +} + +void CMatRenderContext::SetScissorRect( const int nLeft, const int nTop, const int nRight, const int nBottom, const bool bEnableScissor ) +{ + g_pShaderAPI->SetScissorRect( nLeft, nTop, nRight, nBottom, bEnableScissor ); +} + +void CMatRenderContext::SetToneMappingScaleLinear( const Vector &scale ) +{ + g_pShaderAPI->SetToneMappingScaleLinear( scale ); +} + +void CMatRenderContext::BeginBatch( IMesh* pIndices ) +{ + Assert( !m_pBatchMesh && !m_pBatchIndices); + m_pBatchIndices = pIndices; +} + +void CMatRenderContext::BindBatch( IMesh* pVertices, IMaterial *pAutoBind ) +{ + m_pBatchMesh = GetDynamicMesh( false, pVertices, m_pBatchIndices, pAutoBind ); +} + +void CMatRenderContext::DrawBatch(int firstIndex, int numIndices ) +{ + Assert( m_pBatchMesh ); + m_pBatchMesh->Draw( firstIndex, numIndices ); +} + +void CMatRenderContext::EndBatch() +{ + m_pBatchIndices = NULL; + m_pBatchMesh = NULL; +} + +bool CMatRenderContext::OnDrawMesh( IMesh *pMesh, int firstIndex, int numIndices ) +{ + SyncMatrices(); + return true; +} + +bool CMatRenderContext::OnDrawMesh( IMesh *pMesh, CPrimList *pLists, int nLists ) +{ + SyncMatrices(); + return true; +} + +void CMatRenderContext::AsyncCreateTextureFromRenderTarget( ITexture* pSrcRt, const char* pDstName, ImageFormat dstFmt, bool bGenMips, int nAdditionalCreationFlags, IAsyncTextureOperationReceiver* pRecipient, void* pExtraArgs ) +{ + if ( g_pMaterialSystem->GetThreadMode() == MATERIAL_SINGLE_THREADED ) + { + OnAsyncCreateTextureFromRenderTarget( pSrcRt, &pDstName, pRecipient ); + } + + TextureManager()->AsyncCreateTextureFromRenderTarget( pSrcRt, pDstName, dstFmt, bGenMips, nAdditionalCreationFlags, pRecipient, pExtraArgs ); +} + +void CMatRenderContext::AsyncMap( ITextureInternal* pTexToMap, IAsyncTextureOperationReceiver* pRecipient, void* pExtraArgs ) +{ + if ( g_pMaterialSystem->GetThreadMode() == MATERIAL_SINGLE_THREADED ) + { + OnAsyncMap( pTexToMap, pRecipient, pExtraArgs ); + } + + void* pMemory = NULL; + int nPitch = NULL; + + pTexToMap->Map( &pMemory, &nPitch ); + + pRecipient->OnAsyncMapComplete( pTexToMap, pExtraArgs, pMemory, nPitch ); + + // Release references held earlier in OnAsyncMap + SafeRelease( &pRecipient ); + SafeRelease( &pTexToMap ); +} + +void CMatRenderContext::AsyncUnmap( ITextureInternal* pTexToUnmap ) +{ + if ( g_pMaterialSystem->GetThreadMode() == MATERIAL_SINGLE_THREADED ) + { + OnAsyncUnmap( pTexToUnmap ); + } + + pTexToUnmap->Unmap(); + SafeRelease( &pTexToUnmap ); // Matches AddRef from OnAsyncUnmap +} + +void CMatRenderContext::AsyncCopyRenderTargetToStagingTexture( ITexture* pDst, ITexture* pSrc, IAsyncTextureOperationReceiver* pRecipient, void* pExtraArgs ) +{ + if ( g_pMaterialSystem->GetThreadMode() == MATERIAL_SINGLE_THREADED ) + { + OnAsyncCopyRenderTargetToStagingTexture( pDst, pSrc, pRecipient ); + } + + pSrc->CopyToStagingTexture( pDst ); + pRecipient->OnAsyncReadbackBegin( pDst, pSrc, pExtraArgs ); + + SafeRelease( &pDst ); + SafeRelease( &pSrc ); + SafeRelease( &pRecipient ); +} + + +//----------------------------------------------------------------------------- +// Methods related to morph accumulation +//----------------------------------------------------------------------------- +void CMatRenderContext::BeginMorphAccumulation() +{ + g_pMorphMgr->BeginMorphAccumulation( m_pMorphRenderContext ); +} + +void CMatRenderContext::EndMorphAccumulation() +{ + g_pMorphMgr->EndMorphAccumulation( m_pMorphRenderContext ); +} + +void CMatRenderContext::AccumulateMorph( IMorph* pMorph, int nMorphCount, const MorphWeight_t* pWeights ) +{ + g_pMorphMgr->AccumulateMorph( m_pMorphRenderContext, pMorph, nMorphCount, pWeights ); +} + +bool CMatRenderContext::GetMorphAccumulatorTexCoord( Vector2D *pTexCoord, IMorph *pMorph, int nVertex ) +{ + return g_pMorphMgr->GetMorphAccumulatorTexCoord( m_pMorphRenderContext, pTexCoord, pMorph, nVertex ); +} + + +//----------------------------------------------------------------------------- +// Occlusion query support +//----------------------------------------------------------------------------- +OcclusionQueryObjectHandle_t CMatRenderContext::CreateOcclusionQueryObject() +{ + OcclusionQueryObjectHandle_t h = g_pOcclusionQueryMgr->CreateOcclusionQueryObject(); + g_pOcclusionQueryMgr->OnCreateOcclusionQueryObject( h ); + return h; +} + +int CMatRenderContext::OcclusionQuery_GetNumPixelsRendered( OcclusionQueryObjectHandle_t h ) +{ + return g_pOcclusionQueryMgr->OcclusionQuery_GetNumPixelsRendered( h, true ); +} + + + + +void CMatRenderContext::SetFullScreenDepthTextureValidityFlag( bool bIsValid ) +{ + m_bFullFrameDepthIsValid = bIsValid; +} + +//----------------------------------------------------------------------------- +// Debug logging +//----------------------------------------------------------------------------- + +void CMatRenderContext::PrintfVA( char *fmt, va_list vargs ) +{ + #if GLMDEBUG + g_pShaderAPI->PrintfVA( fmt, vargs ); + #endif +} + +void CMatRenderContext::Printf( const char *fmt, ... ) +{ + #if GLMDEBUG + va_list vargs; + + va_start(vargs, fmt); + + g_pShaderAPI->PrintfVA( (char *)fmt, vargs ); + + va_end( vargs ); + #endif +} + +float CMatRenderContext::Knob( char *knobname, float *setvalue ) +{ + #if GLMDEBUG + return g_pShaderAPI->Knob( knobname, setvalue ); + #else + return 0.0f; + #endif +} + diff --git a/materialsystem/cmatrendercontext.h b/materialsystem/cmatrendercontext.h new file mode 100644 index 0000000..0f024eb --- /dev/null +++ b/materialsystem/cmatrendercontext.h @@ -0,0 +1,720 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//============================================================================= + +#ifndef CMATERIALRENDERSTATE_H +#define CMATERIALRENDERSTATE_H + +#include "tier1/delegates.h" +#include "tier1/utlstack.h" +#include "bitvec.h" +#include "materialsystem_global.h" +#include "materialsystem/imaterialsystem.h" +#include "materialsystem/ishaderapi.h" +#include "imaterialinternal.h" +#include "shadersystem.h" +#include "imorphinternal.h" +#include "imatrendercontextinternal.h" +#include "occlusionquerymgr.h" +#include "materialsystem/MaterialSystemUtil.h" + +#ifndef MATSYS_INTERNAL +#error "This file is private to the implementation of IMaterialSystem/IMaterialSystemInternal" +#endif + +#if defined( _WIN32 ) +#pragma once +#endif + +//----------------------------------------------------------------------------- +// Forward declarations +//----------------------------------------------------------------------------- +class ITextureInternal; +class CMaterialSystem; +class CMatLightmaps; +typedef int ShaderAPITextureHandle_t; +class IMorphMgrRenderContext; +class CMatCallQueue; + + +//----------------------------------------------------------------------------- +// Render targets +//----------------------------------------------------------------------------- +#if !defined( _X360 ) +#define MAX_RENDER_TARGETS 4 +#else +#define MAX_RENDER_TARGETS 1 +#endif + + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +class CMatRenderContextBase : public CRefCounted1 +{ +public: + virtual void InitializeFrom( CMatRenderContextBase *pInitialState ); + + InitReturnVal_t Init(); + void Shutdown(); + void CompactMemory(); + + void SetFrameTime( float frameTime ) { m_FrameTime = frameTime; } + + ICallQueue * GetCallQueue() { return NULL; } + CMatCallQueue * GetCallQueueInternal() { return NULL; } + + ITexture * GetRenderTarget( void ); + ITexture * GetRenderTargetEx( int nRenderTargetID ); + + IMaterialInternal* GetCurrentMaterialInternal() const { return m_pCurrentMaterial; } + virtual void SetCurrentMaterialInternal(IMaterialInternal* pCurrentMaterial) { m_pCurrentMaterial = pCurrentMaterial; Assert( (m_pCurrentMaterial == NULL) || ((IMaterialInternal *)m_pCurrentMaterial)->IsRealTimeVersion() ); } + IMaterial * GetCurrentMaterial() { return GetCurrentMaterialInternal(); } + virtual void * GetCurrentProxy() { return m_pCurrentProxyData; } + virtual void SetCurrentProxy( void *pProxyData ) { m_pCurrentProxyData = pProxyData; } + + void Bind( IMaterial *material, void *proxyData = NULL ); + void BindLightmapPage( int lightmapPageID ); + void BindLocalCubemap( ITexture *pTexture ); + + // matrix api + void MatrixMode( MaterialMatrixMode_t); + void PushMatrix(); + void PopMatrix(); + void LoadMatrix( const VMatrix& matrix ); + void LoadMatrix( const matrix3x4_t& matrix ); + void MultMatrix( const VMatrix& matrix ); + void MultMatrixLocal( const VMatrix& matrix ); + void MultMatrix( const matrix3x4_t& matrix ); + void MultMatrixLocal( const matrix3x4_t& matrix ); + void GetMatrix( MaterialMatrixMode_t matrixMode, VMatrix *pMatrix ); + void GetMatrix( MaterialMatrixMode_t matrixMode, matrix3x4_t *pMatrix ); + void LoadIdentity(); + void Ortho( double, double, double, double, double, double); + void PerspectiveX( double, double, double, double); + void PerspectiveOffCenterX( double, double, double, double, double, double, double, double ); + void PickMatrix( int, int, int, int); + void Rotate( float, float, float, float); + void Translate( float, float, float); + void Scale( float, float, float); + // end matrix api + + // Set the current texture that is a copy of the framebuffer. + void SetFrameBufferCopyTexture( ITexture *pTexture, int textureIndex ); + ITexture * GetFrameBufferCopyTexture( int textureIndex ); + + void SetHeightClipMode( MaterialHeightClipMode_t mode ); + MaterialHeightClipMode_t GetHeightClipMode( void ); + void SetHeightClipZ( float z ); + + bool EnableClipping( bool bEnable ); + + void SetRenderTarget( ITexture *pTexture ); + void SetRenderTargetEx( int nRenderTargetID, ITexture *pTexture ); + + void Viewport( int x, int y, int width, int height ); + void PushRenderTargetAndViewport( ); + void PushRenderTargetAndViewport( ITexture *pTexture ); + void PushRenderTargetAndViewport( ITexture *pTexture, int nViewX, int nViewY, int nViewW, int nViewH ); + void PushRenderTargetAndViewport( ITexture *pTexture, ITexture *pDepthTexture, int nViewX, int nViewY, int nViewW, int nViewH ); + void PopRenderTargetAndViewport( void ); + + void SyncMatrices(); + void SyncMatrix( MaterialMatrixMode_t ); + const VMatrix & AccessCurrentMatrix() const { return m_pCurMatrixItem->matrix; } + + virtual void UpdateHeightClipUserClipPlane( void ) {} + virtual void ApplyCustomClipPlanes( void ) {} + + float ComputePixelDiameterOfSphere( const Vector& origin, float flRadius ); + float ComputePixelWidthOfSphere( const Vector& origin, float flRadius ); // FIXME: REMOVE THIS FUNCTION! + + virtual void GetWorldSpaceCameraPosition( Vector *pCameraPos ); + virtual void GetWorldSpaceCameraVectors( Vector *pVecForward, Vector *pVecRight, Vector *pVecUp ); + + void ResetToneMappingScale( float scvalue); + void TurnOnToneMapping(); + Vector GetToneMappingScaleLinear(); + void SetGoalToneMappingScale( float monoscale); + + // Inherited from IMaterialSystemInternal + int GetLightmapPage( void ); + + virtual void * LockRenderData( int nSizeInBytes ); + virtual void UnlockRenderData( void *pData ); + virtual void AddRefRenderData(); + virtual void ReleaseRenderData(); + virtual bool IsRenderData( const void *pData ) const; + void MarkRenderDataUnused( bool bFrameEnd ); + int RenderDataSizeUsed() const; + + // debugging + virtual void PrintfVA( char *fmt, va_list vargs ); + virtual void Printf( PRINTF_FORMAT_STRING const char *fmt, ... ); + virtual float Knob( char *knobname, float *setvalue = NULL ); + +protected: + void OnAsyncCreateTextureFromRenderTarget( ITexture* pSrcRt, const char** pDstName, IAsyncTextureOperationReceiver* pRecipient ); + void OnAsyncMap( ITextureInternal* pTexToMap, IAsyncTextureOperationReceiver* pRecipient, void* pExtraArgs ); + void OnAsyncUnmap( ITextureInternal* pTexToUnmap ); + void OnAsyncCopyRenderTargetToStagingTexture( ITexture* pDst, ITexture* pSrc, IAsyncTextureOperationReceiver* pRecipient ); + +protected: + enum MatrixStackFlags_t + { + MSF_DIRTY = ( 1 << 0 ), + MSF_IDENTITY = ( 1 << 1 ), + }; + + struct MatrixStackItem_t + { + VMatrix matrix; + unsigned flags; + }; + + struct RenderTargetStackElement_t + { + // The render target + ITexture *m_pRenderTargets[MAX_RENDER_TARGETS]; + + // Optional depth texture (used for shadow mapping) + ITexture *m_pDepthTexture; + + // Viewport dimensions + int m_nViewX; + int m_nViewY; + int m_nViewW; + int m_nViewH; + }; + + struct PlaneStackElement + { + float fValues[4]; + bool bHack_IsHeightClipPlane; //used to hack in compatibility between the user clip planes and the existing height clip plane code + //I'm doing the hack this way to retain modder's flexibility to mess with clip plane ordering so that they can make special hacks on their side if necessary + PlaneStackElement( void ) : bHack_IsHeightClipPlane( false ) { }; + }; + +protected: + CMatRenderContextBase(); + virtual void CommitRenderTargetAndViewport( void ) {} + void RecomputeViewState(); + void RecomputeViewProjState(); + void CurrentMatrixChanged(); + virtual void OnRenderDataUnreferenced() {} + +protected: + IMaterialInternal * m_pCurrentMaterial; + void* m_pCurrentProxyData; + + // The lightmap page + int m_lightmapPageID; + ITextureInternal * m_pUserDefinedLightmap; + + ITexture * m_pLocalCubemapTexture; + + ITexture * m_pCurrentFrameBufferCopyTexture[MAX_FB_TEXTURES]; + + MaterialHeightClipMode_t m_HeightClipMode; + float m_HeightClipZ; + // The currently bound morph target + IMorphInternal * m_pBoundMorph; + IMorphMgrRenderContext *m_pMorphRenderContext; + + // Intially a stack of 32 elements allocated, growing by 16 on overflows + CUtlStack< RenderTargetStackElement_t > m_RenderTargetStack; + + MaterialMatrixMode_t m_MatrixMode; + MatrixStackItem_t * m_pCurMatrixItem; + CUtlStack m_MatrixStacks[NUM_MATRIX_MODES]; + + // View state + VMatrix m_viewProjMatrix; + Vector m_vecViewOrigin; + Vector m_vecViewForward; + Vector m_vecViewUp; + Vector m_vecViewRight; + + float m_FrameTime; + + Vector m_LastSetToneMapScale; + float m_CurToneMapScale; // last scale for chasing purposes + float m_GoalToneMapScale; + ShaderViewport_t m_Viewport; + CMaterialSystem * m_pMaterialSystem; + + static CMemoryStack sm_RenderData[2]; + static int sm_nRenderLockCount; + static int sm_nRenderStack; + static int sm_nInitializeCount; + + bool m_bFlashlightEnable : 1; + bool m_bDirtyViewState : 1; + bool m_bDirtyViewProjState : 1; + bool m_bEnableClipping : 1; + bool m_bFullFrameDepthIsValid : 1; +}; + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- + +class CMatRenderContext : public CMatRenderContextBase +{ + typedef CMatRenderContextBase BaseClass; + +public: + CMatRenderContext(); + + InitReturnVal_t Init( CMaterialSystem *pMaterialSystem ); + void Shutdown(); + + void BeginRender(); + void EndRender(); + + void Flush( bool flushHardware = false ); + + void SwapBuffers(); + + void OnReleaseShaderObjects(); + + // Set the current texture that is a copy of the framebuffer. + void SetFrameBufferCopyTexture( ITexture *pTexture, int textureIndex ); + + IMesh * CreateStaticMesh( VertexFormat_t vertexFormat, const char *pTextureBudgetGroup, IMaterial * pMaterial = NULL ); + DELEGATE_TO_OBJECT_1V( DestroyStaticMesh, IMesh *, g_pShaderDevice ); + IMesh * GetDynamicMesh( bool buffered, IMesh* pVertexOverride = 0, IMesh* pIndexOverride = 0, IMaterial *pAutoBind = 0 ); + virtual IMesh* GetDynamicMeshEx( VertexFormat_t vertexFormat, bool bBuffered = true, IMesh* pVertexOverride = 0, IMesh* pIndexOverride = 0, IMaterial *pAutoBind = 0 ); + DELEGATE_TO_OBJECT_0( IMesh *, GetFlexMesh, g_pShaderAPI ); + +// ------------ New Vertex/Index Buffer interface ---------------------------- + IVertexBuffer *CreateStaticVertexBuffer( VertexFormat_t fmt, int nVertexCount, const char *pBudgetGroup ) + { + return g_pShaderDevice->CreateVertexBuffer( SHADER_BUFFER_TYPE_STATIC, fmt, nVertexCount, pBudgetGroup ); + } + + IIndexBuffer *CreateStaticIndexBuffer( MaterialIndexFormat_t fmt, int nIndexCount, const char *pBudgetGroup ) + { + return g_pShaderDevice->CreateIndexBuffer( SHADER_BUFFER_TYPE_STATIC, fmt, nIndexCount, pBudgetGroup ); + } + + DELEGATE_TO_OBJECT_1V( DestroyVertexBuffer, IVertexBuffer *, g_pShaderDevice ); + DELEGATE_TO_OBJECT_1V( DestroyIndexBuffer, IIndexBuffer *, g_pShaderDevice ); + DELEGATE_TO_OBJECT_3( IVertexBuffer *, GetDynamicVertexBuffer, int, VertexFormat_t, bool, g_pShaderDevice ); + DELEGATE_TO_OBJECT_2( IIndexBuffer *, GetDynamicIndexBuffer, MaterialIndexFormat_t, bool, g_pShaderDevice ); + DELEGATE_TO_OBJECT_7V( BindVertexBuffer, int, IVertexBuffer *, int, int, int, VertexFormat_t, int, g_pShaderAPI ); + DELEGATE_TO_OBJECT_2V( BindIndexBuffer, IIndexBuffer *, int, g_pShaderAPI ); + DELEGATE_TO_OBJECT_3V( Draw, MaterialPrimitiveType_t, int, int, g_pShaderAPI ); +// ------------ End ---------------------------- + + void BindLocalCubemap( ITexture *pTexture ); + ITexture * GetLocalCubemap( void ); + void SetRenderTargetEx( int nRenderTargetID, ITexture *pTexture ); + void GetRenderTargetDimensions( int &width, int &height) const; + + // matrix api + void MatrixMode( MaterialMatrixMode_t); + void PushMatrix(); + void PopMatrix(); + void LoadMatrix( const VMatrix& matrix ); + void LoadMatrix( const matrix3x4_t& matrix ); + void MultMatrix( const VMatrix& matrix ); + void MultMatrixLocal( const VMatrix& matrix ); + void MultMatrix( const matrix3x4_t& matrix ); + void MultMatrixLocal( const matrix3x4_t& matrix ); + void GetMatrix( MaterialMatrixMode_t matrixMode, VMatrix *pMatrix ); + void GetMatrix( MaterialMatrixMode_t matrixMode, matrix3x4_t *pMatrix ); + void LoadIdentity(); + void Ortho( double, double, double, double, double, double); + void PerspectiveX( double, double, double, double); + void PerspectiveOffCenterX( double, double, double, double, double, double, double, double ); + void PickMatrix( int, int, int, int); + void Rotate( float, float, float, float); + void Translate( float, float, float); + void Scale( float, float, float); + // end matrix api + + void SyncMatrices(); + void SyncMatrix( MaterialMatrixMode_t ); + bool TestMatrixSync( MaterialMatrixMode_t ); + void ForceSyncMatrix( MaterialMatrixMode_t ); + + // Allows us to override the depth buffer setting of a material + DELEGATE_TO_OBJECT_2V( OverrideDepthEnable, bool, bool, g_pShaderAPI ); + DELEGATE_TO_OBJECT_2V( OverrideAlphaWriteEnable, bool, bool, g_pShaderAPI ); + DELEGATE_TO_OBJECT_2V( OverrideColorWriteEnable, bool, bool, g_pShaderAPI ); + + // FIXME: This is a hack required for NVidia/XBox, can they fix in drivers? + void DrawScreenSpaceQuad( IMaterial* pMaterial ); + + int CompareMaterialCombos( IMaterial *pMaterial1, IMaterial *pMaterial2, int lightMapID1, int lightMapID2 ); + + void Bind( IMaterial *material, void *proxyData = NULL ); + void BindLightmapPage( int lightmapPageID ); + + DELEGATE_TO_OBJECT_2V( SetLight, int, const LightDesc_t &, g_pShaderAPI ); + DELEGATE_TO_OBJECT_1V( SetLightingOrigin, Vector, g_pShaderAPI ); + + DELEGATE_TO_OBJECT_3V( SetAmbientLight, float, float, float, g_pShaderAPI ); + DELEGATE_TO_OBJECT_1V( SetAmbientLightCube, LightCube_t, g_pShaderAPI ); + DELEGATE_TO_OBJECT_0V( DisableAllLocalLights, g_pShaderAPI ); + + void CopyRenderTargetToTexture( ITexture *pTexture ); + + void ClearBuffers( bool bClearColor, bool bClearDepth, bool bClearStencil ); + DELEGATE_TO_OBJECT_3V( ClearColor3ub, unsigned char, unsigned char, unsigned char, g_pShaderAPI ); + DELEGATE_TO_OBJECT_4V( ClearColor4ub, unsigned char, unsigned char, unsigned char, unsigned char, g_pShaderAPI ); + DELEGATE_TO_OBJECT_2V( ClearBuffersObeyStencil, bool, bool, g_pShaderAPI ); + DELEGATE_TO_OBJECT_3V( ClearBuffersObeyStencilEx, bool, bool, bool, g_pShaderAPI ); + DELEGATE_TO_OBJECT_0V( PerformFullScreenStencilOperation, g_pShaderAPI ); + + // read to a unsigned char rgb image. + DELEGATE_TO_OBJECT_6V( ReadPixels, int, int, int, int, unsigned char *, ImageFormat, g_pShaderAPI ); + void ReadPixelsAndStretch( Rect_t *pSrcRect, Rect_t *pDstRect, unsigned char *pBuffer, ImageFormat dstFormat, int nDstStride ) { g_pShaderAPI->ReadPixels( pSrcRect, pDstRect, pBuffer, dstFormat, nDstStride ); } + + // Gets/sets viewport + void Viewport( int x, int y, int width, int height ); + void GetViewport( int& x, int& y, int& width, int& height ) const; + virtual void DepthRange( float zNear, float zFar ); + + // Selection mode methods + DELEGATE_TO_OBJECT_1( int, SelectionMode, bool, g_pShaderAPI ); + DELEGATE_TO_OBJECT_2V( SelectionBuffer, unsigned int *, int, g_pShaderAPI ); + DELEGATE_TO_OBJECT_0V( ClearSelectionNames, g_pShaderAPI ); + DELEGATE_TO_OBJECT_1V( LoadSelectionName, int, g_pShaderAPI ); + DELEGATE_TO_OBJECT_1V( PushSelectionName, int, g_pShaderAPI ); + DELEGATE_TO_OBJECT_0V( PopSelectionName, g_pShaderAPI ); + + // Sets the cull mode + DELEGATE_TO_OBJECT_1V( CullMode, MaterialCullMode_t, g_pShaderAPI ); + + // Sets the number of bones for skinning + DELEGATE_TO_OBJECT_1V( SetNumBoneWeights, int, g_pShaderAPI ); + + void LoadBoneMatrix( int boneIndex, const matrix3x4_t& matrix ); + DELEGATE_TO_OBJECT_3V( SetFlexWeights, int, int, const MorphWeight_t*, g_pShaderAPI ); + + // Fog-related methods + void FogMode( MaterialFogMode_t fogMode ) { g_pShaderAPI->SceneFogMode( fogMode ); } + DELEGATE_TO_OBJECT_1V( FogStart, float, g_pShaderAPI ); + DELEGATE_TO_OBJECT_1V( FogEnd, float, g_pShaderAPI ); + DELEGATE_TO_OBJECT_1V( SetFogZ, float, g_pShaderAPI ); + void FogColor3f( float r, float g, float b ); + void FogColor3fv( const float* rgb ); + void FogColor3ub( unsigned char r, unsigned char g, unsigned char b ) { g_pShaderAPI->SceneFogColor3ub( r, g, b ); } + void FogColor3ubv( unsigned char const* rgb ); + void FogMaxDensity( float flMaxDensity ); + + MaterialFogMode_t GetFogMode( void ) { return g_pShaderAPI->GetSceneFogMode(); } + void GetFogColor( unsigned char *rgb ) { g_pShaderAPI->GetSceneFogColor( rgb ); } + DELEGATE_TO_OBJECT_3V( GetFogDistances, float *, float *, float *, g_pShaderAPI ); + int GetCurrentNumBones( ) const { return g_pShaderAPI->GetCurrentNumBones(); } + + // Bind standard textures + void BindStandardTexture( Sampler_t sampler, StandardTextureId_t id ); + virtual void BindStandardVertexTexture( VertexTextureSampler_t sampler, StandardTextureId_t id ); + virtual void GetStandardTextureDimensions( int *pWidth, int *pHeight, StandardTextureId_t id ); + + // By default, the material system applies the VIEW and PROJECTION matrices to the user clip + // planes (which are specified in world space) to generate projection-space user clip planes + // Occasionally (for the particle system in hl2, for example), we want to override that + // behavior and explictly specify a ViewProj transform for user clip planes + DELEGATE_TO_OBJECT_1V( EnableUserClipTransformOverride, bool, g_pShaderAPI ); + DELEGATE_TO_OBJECT_1V( UserClipTransform, const VMatrix &, g_pShaderAPI ); + + // Gets the window size + DELEGATE_TO_OBJECT_2VC( GetWindowSize, int &, int &, g_pShaderDevice ); + + // Methods related to occlusion query + OcclusionQueryObjectHandle_t CreateOcclusionQueryObject(); + DELEGATE_TO_OBJECT_1V( DestroyOcclusionQueryObject, OcclusionQueryObjectHandle_t, g_pOcclusionQueryMgr ); + DELEGATE_TO_OBJECT_1V( BeginOcclusionQueryDrawing, OcclusionQueryObjectHandle_t, g_pOcclusionQueryMgr ); + DELEGATE_TO_OBJECT_1V( EndOcclusionQueryDrawing, OcclusionQueryObjectHandle_t, g_pOcclusionQueryMgr ); + DELEGATE_TO_OBJECT_1V( ResetOcclusionQueryObject, OcclusionQueryObjectHandle_t, g_pOcclusionQueryMgr ); + int OcclusionQuery_GetNumPixelsRendered( OcclusionQueryObjectHandle_t h ); + + bool InFlashlightMode() const; + void SetFlashlightMode( bool bEnable ); + bool GetFlashlightMode( ) const; + void SetFlashlightState( const FlashlightState_t &state, const VMatrix &worldToTexture ); + void SetFlashlightStateEx( const FlashlightState_t &state, const VMatrix &worldToTexture, ITexture *pFlashlightDepthTexture ); + + void SetScissorRect( const int nLeft, const int nTop, const int nRight, const int nBottom, const bool bEnableScissor ); + + // Creates/destroys morph data associated w/ a particular material + IMorph * CreateMorph( MorphFormat_t format, const char *pDebugName ); + void DestroyMorph( IMorph *pMorph ); + void BindMorph( IMorph *pMorph ); + // Gets the bound morph's vertex format; returns 0 if no morph is bound + MorphFormat_t GetBoundMorphFormat(); + + void DrawScreenSpaceRectangle( IMaterial *pMaterial, + int destx, int desty, + int width, int height, + float src_texture_x0, float src_texture_y0, // which texel you want to appear at + // destx/y + float src_texture_x1, float src_texture_y1, // which texel you want to appear at + // destx+width-1, desty+height-1 + int src_texture_width, int src_texture_height, // needed for fixup + void *pClientRenderable = NULL, + int nXDice = 1, + int nYDice = 1 ); + + // custom clip planes, beware that only the most recently pushed plane will actually be used in some hardware configurations + void PushCustomClipPlane( const float *fPlane ); + void PopCustomClipPlane( void ); + void ApplyCustomClipPlanes( void ); //updates the clip planes based on how many are supported by the hardware using the top of the stack first, at the end of the stack, the height clip plane will be evaluated + + // Force writes only when z matches. . . useful for stenciling things out + // by rendering the desired Z values ahead of time. + DELEGATE_TO_OBJECT_1V( ForceDepthFuncEquals, bool, g_pShaderAPI ); + + // Two methods of building lightmap bits from floating point src data + + // What are the lightmap dimensions? + void GetLightmapDimensions( int *w, int *h ); + + void DrawClearBufferQuad( unsigned char r, unsigned char g, unsigned char b, unsigned char a, bool bClearColor, bool bClearAlpha, bool bClearDepth ); + + void UpdateHeightClipUserClipPlane( void ); + + // Private routine called by render target stack push and pop routines to commit new top of stack to the device + void CommitRenderTargetAndViewport( void ); + + void SyncToken( const char *pToken ); + + void BindLightmapTexture( ITexture *pLightmapTexture ); + void CopyRenderTargetToTextureEx( ITexture *pTexture, int nRenderTargetID, Rect_t *pSrcRect, Rect_t *pDstRect = NULL ); + void CopyTextureToRenderTargetEx( int nRenderTargetID, ITexture *pTexture, Rect_t *pSrcRect, Rect_t *pDstRect = NULL ); + + DELEGATE_TO_OBJECT_2V( SetFloatRenderingParameter, int, float, g_pShaderAPI ); + DELEGATE_TO_OBJECT_2V( SetIntRenderingParameter, int, int, g_pShaderAPI ); + DELEGATE_TO_OBJECT_2V( SetVectorRenderingParameter, int, const Vector &, g_pShaderAPI ); + DELEGATE_TO_OBJECT_1C( float, GetFloatRenderingParameter, int, g_pShaderAPI ); + DELEGATE_TO_OBJECT_1C( int, GetIntRenderingParameter, int, g_pShaderAPI ); + DELEGATE_TO_OBJECT_1C( Vector, GetVectorRenderingParameter, int, g_pShaderAPI ); + + DELEGATE_TO_OBJECT_4V( GetMaxToRender, IMesh *, bool, int *, int *, g_pShaderAPI ); + DELEGATE_TO_OBJECT_1( int, GetMaxVerticesToRender, IMaterial *, g_pShaderAPI ); + DELEGATE_TO_OBJECT_0( int, GetMaxIndicesToRender, g_pShaderAPI ); + DELEGATE_TO_OBJECT_1V( SetStencilEnable, bool, g_pShaderAPI ); + DELEGATE_TO_OBJECT_1V( SetStencilFailOperation, StencilOperation_t, g_pShaderAPI ); + DELEGATE_TO_OBJECT_1V( SetStencilZFailOperation, StencilOperation_t, g_pShaderAPI ); + DELEGATE_TO_OBJECT_1V( SetStencilPassOperation, StencilOperation_t, g_pShaderAPI ); + DELEGATE_TO_OBJECT_1V( SetStencilCompareFunction, StencilComparisonFunction_t, g_pShaderAPI ); + DELEGATE_TO_OBJECT_1V( SetStencilReferenceValue, int, g_pShaderAPI ); + DELEGATE_TO_OBJECT_1V( SetStencilTestMask, uint32, g_pShaderAPI ); + DELEGATE_TO_OBJECT_1V( SetStencilWriteMask, uint32, g_pShaderAPI ); + DELEGATE_TO_OBJECT_5V( ClearStencilBufferRectangle, int, int, int, int, int, g_pShaderAPI ); + + // PIX support + DELEGATE_TO_OBJECT_2V( BeginPIXEvent, unsigned long, const char *, g_pShaderAPI ); + DELEGATE_TO_OBJECT_0V( EndPIXEvent, g_pShaderAPI ); + DELEGATE_TO_OBJECT_2V( SetPIXMarker, unsigned long, const char *, g_pShaderAPI ); + + DELEGATE_TO_OBJECT_2V( SetShadowDepthBiasFactors, float, float, g_pShaderAPI ); + + void BeginBatch( IMesh* pIndices ); + void BindBatch( IMesh* pVertices, IMaterial *pAutoBind = NULL ); + void DrawBatch(int firstIndex, int numIndices ); + void EndBatch(); + + void SetToneMappingScaleLinear( const Vector &scale ); + + bool OnDrawMesh( IMesh *pMesh, int firstIndex, int numIndices ); + bool OnDrawMesh( IMesh *pMesh, CPrimList *pLists, int nLists ); + bool OnSetFlexMesh( IMesh *pStaticMesh, IMesh *pMesh, int nVertexOffsetInBytes ) { return true; } + bool OnSetColorMesh( IMesh *pStaticMesh, IMesh *pMesh, int nVertexOffsetInBytes ) { return true; } + bool OnSetPrimitiveType( IMesh *pMesh, MaterialPrimitiveType_t type ) { return true; } + bool OnFlushBufferedPrimitives() { SyncMatrices(); return true; } + + CMaterialSystem *GetMaterialSystem() const; + + DELEGATE_TO_OBJECT_0V( ForceHardwareSync, g_pShaderAPI ); + DELEGATE_TO_OBJECT_0V( BeginFrame, g_pShaderAPI ); + DELEGATE_TO_OBJECT_0V( EndFrame, g_pShaderAPI ); + + virtual void AsyncCreateTextureFromRenderTarget( ITexture* pSrcRt, const char* pDstName, ImageFormat dstFmt, bool bGenMips, int nAdditionalCreationFlags, IAsyncTextureOperationReceiver* pRecipient, void* pExtraArgs ); + + virtual void AsyncMap( ITextureInternal* pTexToMap, IAsyncTextureOperationReceiver* pRecipient, void* pExtraArgs ) OVERRIDE; + virtual void AsyncUnmap( ITextureInternal* pTexToUnmap ) OVERRIDE; + virtual void AsyncCopyRenderTargetToStagingTexture( ITexture* pDst, ITexture* pSrc, IAsyncTextureOperationReceiver* pRecipient, void* pExtraArgs ) OVERRIDE; + + + + virtual void BeginMorphAccumulation(); + virtual void EndMorphAccumulation(); + virtual void AccumulateMorph( IMorph* pMorph, int nMorphCount, const MorphWeight_t* pWeights ); + virtual bool GetMorphAccumulatorTexCoord( Vector2D *pTexCoord, IMorph *pMorph, int nVertex ); + + DELEGATE_TO_OBJECT_1V( PushDeformation, const DeformationBase_t *, g_pShaderAPI ); + DELEGATE_TO_OBJECT_0V( PopDeformation, g_pShaderAPI ); + DELEGATE_TO_OBJECT_0C( int, GetNumActiveDeformations, g_pShaderAPI ); + + // Color correction related methods.. + DELEGATE_TO_OBJECT_1V( EnableColorCorrection, bool, g_pColorCorrectionSystem ); + DELEGATE_TO_OBJECT_1( ColorCorrectionHandle_t, AddLookup, const char *, g_pColorCorrectionSystem ); + DELEGATE_TO_OBJECT_1( bool, RemoveLookup, ColorCorrectionHandle_t, g_pColorCorrectionSystem ); + DELEGATE_TO_OBJECT_1V( LockLookup, ColorCorrectionHandle_t, g_pColorCorrectionSystem ); + DELEGATE_TO_OBJECT_2V( LoadLookup, ColorCorrectionHandle_t, const char *, g_pColorCorrectionSystem ); + DELEGATE_TO_OBJECT_1V( UnlockLookup, ColorCorrectionHandle_t, g_pColorCorrectionSystem ); + DELEGATE_TO_OBJECT_2V( SetLookupWeight, ColorCorrectionHandle_t, float, g_pColorCorrectionSystem ); + DELEGATE_TO_OBJECT_0V( ResetLookupWeights, g_pColorCorrectionSystem ); + DELEGATE_TO_OBJECT_2V( SetResetable, ColorCorrectionHandle_t, bool, g_pColorCorrectionSystem ); + + virtual void SetFullScreenDepthTextureValidityFlag( bool bIsValid ); + +#if defined( _X360 ) + DELEGATE_TO_OBJECT_1V( PushVertexShaderGPRAllocation, int, g_pShaderAPI ); + DELEGATE_TO_OBJECT_0V( PopVertexShaderGPRAllocation, g_pShaderAPI ); +#endif + + // A special path used to tick the front buffer while loading on the 360 + virtual void SetNonInteractivePacifierTexture( ITexture *pTexture, float flNormalizedX, float flNormalizedY, float flNormalizedSize ); + virtual void SetNonInteractiveTempFullscreenBuffer( ITexture *pTexture, MaterialNonInteractiveMode_t mode ); + virtual void EnableNonInteractiveMode( MaterialNonInteractiveMode_t mode ); + virtual void RefreshFrontBufferNonInteractive(); + + // debug logging + virtual void PrintfVA( char *fmt, va_list vargs ); + virtual void Printf( PRINTF_FORMAT_STRING const char *fmt, ... ); + virtual float Knob( char *knobname, float *setvalue=NULL ); + +#ifdef DX_TO_GL_ABSTRACTION + void DoStartupShaderPreloading( void ); +#endif + + virtual void TextureManagerUpdate(); + + //--------------------------------------------------------- +protected: + + IMaterialInternal *GetMaterialInternal( MaterialHandle_t ) const; + IMaterialInternal *GetDrawFlatMaterial(); + IMaterialInternal *GetRenderTargetBlitMaterial(); + IMaterialInternal *GetBufferClearObeyStencil( int i ); + + ShaderAPITextureHandle_t GetFullbrightLightmapTextureHandle() const; + ShaderAPITextureHandle_t GetFullbrightBumpedLightmapTextureHandle() const; + ShaderAPITextureHandle_t GetBlackTextureHandle() const; + ShaderAPITextureHandle_t GetFlatNormalTextureHandle() const; + ShaderAPITextureHandle_t GetGreyTextureHandle() const; + ShaderAPITextureHandle_t GetGreyAlphaZeroTextureHandle() const; + ShaderAPITextureHandle_t GetWhiteTextureHandle() const; + ShaderAPITextureHandle_t GetFrameBufferTextureHandle() const; + ShaderAPITextureHandle_t GetMaxDepthTextureHandle() const; + + // Helper methods + void BindLightmap( Sampler_t stage ); + void BindBumpLightmap( Sampler_t stage ); + void BindFullbrightLightmap( Sampler_t stage ); + void BindBumpedFullbrightLightmap( Sampler_t stage ); + + virtual void OnRenderDataUnreferenced(); + + const CMatLightmaps *GetLightmaps() const; + CMatLightmaps *GetLightmaps(); + + CUtlVector m_CustomClipPlanes; //implemented as a vector so we can remove in special ways + + IMesh *m_pBatchIndices; + IMesh *m_pBatchMesh; + IIndexBuffer *m_pCurrentIndexBuffer; + CTextureReference m_pNonInteractiveTempFullscreenBuffer[MATERIAL_NON_INTERACTIVE_MODE_COUNT]; + CTextureReference m_pNonInteractivePacifier; + MaterialNonInteractiveMode_t m_NonInteractiveMode; + float m_flNormalizedX; + float m_flNormalizedY; + float m_flNormalizedSize; +}; + + +//----------------------------------------------------------------------------- + +inline void CMatRenderContext::LoadBoneMatrix( int boneIndex, const matrix3x4_t& matrix ) +{ + g_pShaderAPI->LoadBoneMatrix( boneIndex, matrix.Base() ); +} + +//----------------------------------------------------------------------------- + + +inline bool CMatRenderContext::InFlashlightMode() const +{ + return m_bFlashlightEnable; +} + +inline void CMatRenderContext::SetFlashlightState( const FlashlightState_t &state, const VMatrix &worldToTexture ) +{ + SetFlashlightStateEx( state, worldToTexture, NULL ); +} + +inline float CMatRenderContextBase::ComputePixelWidthOfSphere( const Vector& vecOrigin, float flRadius ) +{ + return ComputePixelDiameterOfSphere( vecOrigin, flRadius ) * 2.0f; +} + +inline void CMatRenderContext::FogColor3ubv( unsigned char const* rgb ) +{ + g_pShaderAPI->SceneFogColor3ub( rgb[0], rgb[1], rgb[2] ); +} + +inline void CMatRenderContext::FogMaxDensity( float flMaxDensity ) +{ + g_pShaderAPI->FogMaxDensity( flMaxDensity ); +} + +inline ITexture *CMatRenderContext::GetLocalCubemap( void ) +{ + return m_pLocalCubemapTexture; +} + +inline void CMatRenderContextBase::SetRenderTarget( ITexture *pTexture_ ) +{ + SetRenderTargetEx( 0, pTexture_ ); +} + +//----------------------------------------------------------------------------- +// Gets the bound morph's vertex format; returns 0 if no morph is bound +//----------------------------------------------------------------------------- +inline MorphFormat_t CMatRenderContext::GetBoundMorphFormat() +{ + return m_pBoundMorph ? m_pBoundMorph->GetMorphFormat() : 0; +} + +//----------------------------------------------------------------------------- +// Use this to create static vertex and index buffers +//----------------------------------------------------------------------------- +inline IMesh* CMatRenderContext::CreateStaticMesh( VertexFormat_t vertexFormat, const char *pTextureBudgetGroup, IMaterial * pMaterial ) +{ + return g_pShaderDevice->CreateStaticMesh( vertexFormat, pTextureBudgetGroup, pMaterial ); +} + +inline void CMatRenderContext::SyncToken( const char *pToken ) +{ + if ( g_pShaderAPI ) + { + g_pShaderAPI->SyncToken( pToken ); + } +} + +inline enum MaterialHeightClipMode_t CMatRenderContextBase::GetHeightClipMode( void ) +{ + return m_HeightClipMode; +} + +inline int CMatRenderContextBase::GetLightmapPage( void ) +{ + return m_lightmapPageID; +} + +inline CMaterialSystem *CMatRenderContext::GetMaterialSystem() const +{ + return m_pMaterialSystem; +} + +//----------------------------------------------------------------------------- + +#endif // CMATERIALRENDERSTATE_H diff --git a/materialsystem/colorspace.cpp b/materialsystem/colorspace.cpp new file mode 100644 index 0000000..c1cdd79 --- /dev/null +++ b/materialsystem/colorspace.cpp @@ -0,0 +1,212 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//=====================================================================================// + +#include +#include "mathlib/bumpvects.h" +#include "colorspace.h" +#include "materialsystem_global.h" +#include "IHardwareConfigInternal.h" +#include "materialsystem/materialsystem_config.h" + +// NOTE: This has to be the last file included +#include "tier0/memdbgon.h" + +//static float texLightToLinear[256]; // texlight (0..255) to linear (0..4) +static float textureToLinear[256]; // texture (0..255) to linear (0..1) +static int linearToTexture[1024]; // linear (0..1) to texture (0..255) +static int linearToScreen[1024]; // linear (0..1) to gamma corrected vertex light (0..255) +float g_LinearToVertex[4096]; // linear (0..4) to screen corrected vertex space (0..1?) +static int linearToLightmap[4096]; // linear (0..4) to screen corrected texture value (0..255) + +void ColorSpace::SetGamma( float screenGamma, float texGamma, + float overbright, bool allowCheats, bool linearFrameBuffer ) +{ + int i, inf; + float g1, g3; + float g; + float brightness = 0.0f; // This used to be configurable. . hardcode to 0.0 + + if( linearFrameBuffer ) + { + screenGamma = 1.0f; + } + + g = screenGamma; + + // clamp values to prevent cheating in multiplayer + if( !allowCheats ) + { + if (brightness > 2.0f) + brightness = 2.0f; + + if (g < 1.8f) + g = 1.8f; + } + + if (g > 3.0) + g = 3.0; + + g = 1.0f / g; + g1 = texGamma * g; + + // pow( textureColor, g1 ) converts from on-disk texture space to framebuffer space + + if (brightness <= 0.0f) + { + g3 = 0.125; + } + else if (brightness > 1.0f) + { + g3 = 0.05f; + } + else + { + g3 = 0.125f - (brightness * brightness) * 0.075f; + } + + for (i=0 ; i<1024 ; i++) + { + float f; + + f = i / 1023.0f; + + // scale up + if (brightness > 1.0f) + f = f * brightness; + + // shift up + if (f <= g3) + f = (f / g3) * 0.125f; + else + f = 0.125f + ((f - g3) / (1.0f - g3)) * 0.875f; + + // convert linear space to desired gamma space + inf = ( int )( 255 * pow ( f, g ) ); + + if (inf < 0) + inf = 0; + if (inf > 255) + inf = 255; + linearToScreen[i] = inf; + } + + for (i=0 ; i<256 ; i++) + { + // convert from nonlinear texture space (0..255) to linear space (0..1) + textureToLinear[i] = ( float )pow( i / 255.0f, texGamma ); + } + + for (i=0 ; i<1024 ; i++) + { + // convert from linear space (0..1) to nonlinear texture space (0..255) + linearToTexture[i] = ( int )( pow( i / 1023.0f, 1.0f / texGamma ) * 255 ); + } + +#if 0 + for (i=0 ; i<256 ; i++) + { + float f; + + // convert from nonlinear lightmap space (0..255) to linear space (0..4) + f = ( float )( (i / 255.0f) * sqrt( 4 ) ); + f = f * f; + + texLightToLinear[i] = f; + } +#endif + + float f, overbrightFactor; + + // Can't do overbright without texcombine + // UNDONE: Add GAMMA ramp to rectify this + + if ( !HardwareConfig() ) + { + overbright = 1.0f; + } + if ( overbright == 2.0 ) + { + overbrightFactor = 0.5; + } + else if ( overbright == 4.0 ) + { + overbrightFactor = 0.25; + } + else + { + overbrightFactor = 1.0; + } + + for (i=0 ; i<4096 ; i++) + { + // convert from linear 0..4 (x1024) to screen corrected vertex space (0..1?) + f = ( float )pow ( i/1024.0f, 1.0f / screenGamma ); + + g_LinearToVertex[i] = f * overbrightFactor; + if (g_LinearToVertex[i] > 1) + g_LinearToVertex[i] = 1; + + linearToLightmap[i] = ( int )( f * 255 * overbrightFactor ); + if (linearToLightmap[i] > 255) + linearToLightmap[i] = 255; + } +} + +// convert texture to linear 0..1 value +float ColorSpace::TextureToLinear( int c ) +{ + if (c < 0) + return 0; + if (c > 255) + return 1.0f; + + return textureToLinear[c]; +} + +// convert texture to linear 0..1 value +int ColorSpace::LinearToTexture( float f ) +{ + int i; + i = ( int )( f * 1023.0f ); // assume 0..1 range + if (i < 0) + i = 0; + if (i > 1023) + i = 1023; + + return linearToTexture[i]; +} + +float ColorSpace::TexLightToLinear( int c, int exponent ) +{ +// return texLightToLinear[ c ]; + // optimize me + return ( float )c * ( float )pow( 2.0f, exponent ) * ( 1.0f / 255.0f ); +} + +// converts 0..1 linear value to screen gamma (0..255) +int ColorSpace::LinearToScreenGamma( float f ) +{ + int i; + i = ( int )( f * 1023.0f ); // assume 0..1 range + if (i < 0) + i = 0; + if (i > 1023) + i = 1023; + + return linearToScreen[i]; +} + + +uint16 ColorSpace::LinearFloatToCorrectedShort( float in ) +{ + uint16 out; + in = min( in * 4096.0, 65535.0 ); + out = max( in, 0.0f ); + + return out; +} + + diff --git a/materialsystem/colorspace.h b/materialsystem/colorspace.h new file mode 100644 index 0000000..4c13e0d --- /dev/null +++ b/materialsystem/colorspace.h @@ -0,0 +1,333 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $Workfile: $ +// $Date: $ +// $NoKeywords: $ +//=============================================================================// + +#ifndef COLORSPACE_H +#define COLORSPACE_H + +#ifdef _WIN32 +#pragma once +#endif + +#include "mathlib/mathlib.h" +#include "mathlib/ssemath.h" +#include "mathlib/bumpvects.h" +#include "tier0/dbg.h" + +extern float g_LinearToVertex[4096]; // linear (0..4) to screen corrected vertex space (0..1?) + +// FIXME!!! Get rid of this. . all of this should be in mathlib +namespace ColorSpace +{ + void SetGamma( float screenGamma, float texGamma, + float overbright, bool allowCheats, bool linearFrameBuffer ); + + // convert texture to linear 0..1 value + float TextureToLinear( int c ); + + // convert texture to linear 0..1 value + int LinearToTexture( float f ); + + float TexLightToLinear( int c, int exponent ); + + // assume 0..4 range + void LinearToLightmap( unsigned char *pDstRGB, const float *pSrcRGB ); + + // assume 0..4 range + void LinearToBumpedLightmap( const float *linearColor, const float *linearBumpColor1, + const float *linearBumpColor2, const float *linearBumpColor3, + unsigned char *ret, unsigned char *retBump1, + unsigned char *retBump2, unsigned char *retBump3 ); + + // converts 0..1 linear value to screen gamma (0..255) + int LinearToScreenGamma( float f ); + + FORCEINLINE void LinearToLightmap( unsigned char *pDstRGB, const float *pSrcRGB ) + { + Vector tmpVect; +#if 1 + int i, j; + for( j = 0; j < 3; j++ ) + { + i = RoundFloatToInt( pSrcRGB[j] * 1024 ); // assume 0..4 range + if (i < 0) + { + i = 0; + } + if (i > 4091) + { + i = 4091; + } + tmpVect[j] = g_LinearToVertex[i]; + } +#else + tmpVect[0] = LinearToVertexLight( pSrcRGB[0] ); + tmpVect[1] = LinearToVertexLight( pSrcRGB[1] ); + tmpVect[2] = LinearToVertexLight( pSrcRGB[2] ); +#endif + ColorClamp( tmpVect ); + + pDstRGB[0] = RoundFloatToByte( tmpVect[0] * 255.0f ); + pDstRGB[1] = RoundFloatToByte( tmpVect[1] * 255.0f ); + pDstRGB[2] = RoundFloatToByte( tmpVect[2] * 255.0f ); + } + + // Clamp the three values for bumped lighting such that we trade off directionality for brightness. + FORCEINLINE void ColorClampBumped( Vector& color1, Vector& color2, Vector& color3 ) + { + Vector maxs; + Vector *colors[3] = { &color1, &color2, &color3 }; + maxs[0] = VectorMaximum( color1 ); + maxs[1] = VectorMaximum( color2 ); + maxs[2] = VectorMaximum( color3 ); + + // HACK! Clean this up, and add some else statements +#define CONDITION(a,b,c) do { if( maxs[a] >= maxs[b] && maxs[b] >= maxs[c] ) { order[0] = a; order[1] = b; order[2] = c; } } while( 0 ) + + int order[3] = {}; + CONDITION(0,1,2); + CONDITION(0,2,1); + CONDITION(1,0,2); + CONDITION(1,2,0); + CONDITION(2,0,1); + CONDITION(2,1,0); + + int i; + for( i = 0; i < 3; i++ ) + { + float max = VectorMaximum( *colors[order[i]] ); + if( max <= 1.0f ) + { + continue; + } + // This channel is too bright. . take half of the amount that we are over and + // add it to the other two channel. + float factorToRedist = ( max - 1.0f ) / max; + Vector colorToRedist = factorToRedist * *colors[order[i]]; + *colors[order[i]] -= colorToRedist; + colorToRedist *= 0.5f; + *colors[order[(i+1)%3]] += colorToRedist; + *colors[order[(i+2)%3]] += colorToRedist; + } + + ColorClamp( color1 ); + ColorClamp( color2 ); + ColorClamp( color3 ); + + if( color1[0] < 0.f ) color1[0] = 0.f; + if( color1[1] < 0.f ) color1[1] = 0.f; + if( color1[2] < 0.f ) color1[2] = 0.f; + if( color2[0] < 0.f ) color2[0] = 0.f; + if( color2[1] < 0.f ) color2[1] = 0.f; + if( color2[2] < 0.f ) color2[2] = 0.f; + if( color3[0] < 0.f ) color3[0] = 0.f; + if( color3[1] < 0.f ) color3[1] = 0.f; + if( color3[2] < 0.f ) color3[2] = 0.f; + } + + FORCEINLINE void LinearToBumpedLightmap( const float *linearColor, const float *linearBumpColor1, + const float *linearBumpColor2, const float *linearBumpColor3, + unsigned char *ret, unsigned char *retBump1, + unsigned char *retBump2, unsigned char *retBump3 ) + { + const Vector &linearBump1 = *( ( const Vector * )linearBumpColor1 ); + const Vector &linearBump2 = *( ( const Vector * )linearBumpColor2 ); + const Vector &linearBump3 = *( ( const Vector * )linearBumpColor3 ); + + Vector gammaGoal; + // gammaGoal is premultiplied by 1/overbright, which we want + gammaGoal[0] = LinearToVertexLight( linearColor[0] ); + gammaGoal[1] = LinearToVertexLight( linearColor[1] ); + gammaGoal[2] = LinearToVertexLight( linearColor[2] ); + Vector bumpAverage = linearBump1; + bumpAverage += linearBump2; + bumpAverage += linearBump3; + bumpAverage *= ( 1.0f / 3.0f ); + + Vector correctionScale; + if( *( int * )&bumpAverage[0] != 0 && *( int * )&bumpAverage[1] != 0 && *( int * )&bumpAverage[2] != 0 ) + { + // fast path when we know that we don't have to worry about divide by zero. + VectorDivide( gammaGoal, bumpAverage, correctionScale ); +// correctionScale = gammaGoal / bumpSum; + } + else + { + correctionScale.Init( 0.0f, 0.0f, 0.0f ); + if( bumpAverage[0] != 0.0f ) + { + correctionScale[0] = gammaGoal[0] / bumpAverage[0]; + } + if( bumpAverage[1] != 0.0f ) + { + correctionScale[1] = gammaGoal[1] / bumpAverage[1]; + } + if( bumpAverage[2] != 0.0f ) + { + correctionScale[2] = gammaGoal[2] / bumpAverage[2]; + } + } + Vector correctedBumpColor1; + Vector correctedBumpColor2; + Vector correctedBumpColor3; + VectorMultiply( linearBump1, correctionScale, correctedBumpColor1 ); + VectorMultiply( linearBump2, correctionScale, correctedBumpColor2 ); + VectorMultiply( linearBump3, correctionScale, correctedBumpColor3 ); + + Vector check = ( correctedBumpColor1 + correctedBumpColor2 + correctedBumpColor3 ) / 3.0f; + + ColorClampBumped( correctedBumpColor1, correctedBumpColor2, correctedBumpColor3 ); + + ret[0] = RoundFloatToByte( gammaGoal[0] * 255.0f ); + ret[1] = RoundFloatToByte( gammaGoal[1] * 255.0f ); + ret[2] = RoundFloatToByte( gammaGoal[2] * 255.0f ); + retBump1[0] = RoundFloatToByte( correctedBumpColor1[0] * 255.0f ); + retBump1[1] = RoundFloatToByte( correctedBumpColor1[1] * 255.0f ); + retBump1[2] = RoundFloatToByte( correctedBumpColor1[2] * 255.0f ); + retBump2[0] = RoundFloatToByte( correctedBumpColor2[0] * 255.0f ); + retBump2[1] = RoundFloatToByte( correctedBumpColor2[1] * 255.0f ); + retBump2[2] = RoundFloatToByte( correctedBumpColor2[2] * 255.0f ); + retBump3[0] = RoundFloatToByte( correctedBumpColor3[0] * 255.0f ); + retBump3[1] = RoundFloatToByte( correctedBumpColor3[1] * 255.0f ); + retBump3[2] = RoundFloatToByte( correctedBumpColor3[2] * 255.0f ); + } + + + uint16 LinearFloatToCorrectedShort( float in ); + + inline unsigned short LinearToUnsignedShort( float in, int nFractionalBits ) + { + unsigned short out; + in = in * ( 1 << nFractionalBits ); + in = min( in, 65535.f ); + out = max( in, 0.0f ); + return out; + } + + inline void ClampToHDR( const Vector &in, unsigned short out[3] ) + { + Vector tmp = in; + + out[0] = LinearFloatToCorrectedShort( in.x ); + out[1] = LinearFloatToCorrectedShort( in.y ); + out[2] = LinearFloatToCorrectedShort( in.z ); + } + + FORCEINLINE void + LinearToBumpedLightmap( const float *linearColor, const float *linearBumpColor1, + const float *linearBumpColor2, const float *linearBumpColor3, + float *ret, float *retBump1, + float *retBump2, float *retBump3 ) + { + const Vector &linearUnbumped = *( ( const Vector * )linearColor ); + Vector linearBump1 = *( ( const Vector * )linearBumpColor1 ); + Vector linearBump2 = *( ( const Vector * )linearBumpColor2 ); + Vector linearBump3 = *( ( const Vector * )linearBumpColor3 ); + + // find a scale factor which makes the average of the 3 bumped mapped vectors match the + // straight up vector (if possible), so that flat bumpmapped areas match non-bumpmapped + // areas. + // Note: According to Alex, this code is completely wrong. + // Because the bump vectors constitute a orthonormal basis, one does not simply average + // them to get the straight-up result. In fact they are added together then multiplied + // by 0.575 + Vector bumpAverage = linearBump1; + bumpAverage += linearBump2; + bumpAverage += linearBump3; + bumpAverage *= ( 1.0f / 3.0f ); + + Vector correctionScale; + + if( *( int * )&bumpAverage[0] != 0 && + *( int * )&bumpAverage[1] != 0 && + *( int * )&bumpAverage[2] != 0 ) + { + // fast path when we know that we don't have to worry about divide by zero. + VectorDivide( linearUnbumped, bumpAverage, correctionScale ); + } + else + { + correctionScale.Init( 0.0f, 0.0f, 0.0f ); + if( bumpAverage[0] != 0.0f ) + { + correctionScale[0] = linearUnbumped[0] / bumpAverage[0]; + } + if( bumpAverage[1] != 0.0f ) + { + correctionScale[1] = linearUnbumped[1] / bumpAverage[1]; + } + if( bumpAverage[2] != 0.0f ) + { + correctionScale[2] = linearUnbumped[2] / bumpAverage[2]; + } + } + linearBump1 *= correctionScale; + linearBump2 *= correctionScale; + linearBump3 *= correctionScale; + + *((Vector *)ret) = linearUnbumped; + *((Vector *)retBump1) = linearBump1; + *((Vector *)retBump2) = linearBump2; + *((Vector *)retBump3) = linearBump3; + } + + + // The domain of the inputs is floats [0 .. 16.0f] + // the output range is also floats [0 .. 16.0f] (eg, compression to short does not happen) + FORCEINLINE void + LinearToBumpedLightmap( FLTX4 linearColor, FLTX4 linearBumpColor1, + FLTX4 linearBumpColor2, FLTX4 linearBumpColor3, + fltx4 &ret, fltx4 &retBump1, // I pray that with inlining + fltx4 &retBump2, fltx4 &retBump3 ) // these will be returned on registers + { + // preload 3.0f onto the returns so that we don't need to multiply the bumpAverage by it + // straight away (eg, reschedule this dependent op) + static const fltx4 vThree = { 3.0f, 3.0f, 3.0f, 0.0f }; + fltx4 retValBump1 = MulSIMD( vThree, linearBumpColor1); + fltx4 retValBump2 = MulSIMD( vThree, linearBumpColor2); + fltx4 retValBump3 = MulSIMD( vThree, linearBumpColor3); + + // find a scale factor which makes the average of the 3 bumped mapped vectors match the + // straight up vector (if possible), so that flat bumpmapped areas match non-bumpmapped + // areas. + fltx4 bumpAverage = AddSIMD(AddSIMD(linearBumpColor1, linearBumpColor2), linearBumpColor3); // actually average * 3 + + // find the zero terms so that we can quash their channels in the output + fltx4 zeroTerms = CmpEqSIMD(bumpAverage, Four_Zeros); + fltx4 correctionScale = ReciprocalEstSIMD(bumpAverage); // each channel is now 1.0f / (average[x] * 3.0f) + + // divide unbumped linear by the average to get the correction scale + correctionScale = MulSIMD( AndNotSIMD(zeroTerms, linearColor), // crush values that were zero in bumpAverage. (saves on dep latency) + correctionScale); // still has an extra 1/3 factor multiplied in + + // multiply this against three to get the return values + ret = linearColor; + retBump1 = MulSIMD(retValBump1, correctionScale); + retBump2 = MulSIMD(retValBump2, correctionScale); + retBump3 = MulSIMD(retValBump3, correctionScale); + } + + // input: floats [0 .. 16.0f] + // output: shorts [0 .. 65535] + FORCEINLINE void + LinearToBumpedLightmap( const float *linearColor, const float *linearBumpColor1, + const float *linearBumpColor2, const float *linearBumpColor3, + unsigned short *ret, unsigned short *retBump1, + unsigned short *retBump2, unsigned short *retBump3 ) + { + Vector linearUnbumped, linearBump1, linearBump2, linearBump3; + LinearToBumpedLightmap( linearColor, linearBumpColor1, linearBumpColor2, linearBumpColor3, &linearUnbumped.x, &linearBump1.x, &linearBump2.x, &linearBump3.x ); + + ClampToHDR( linearUnbumped, ret ); + ClampToHDR( linearBump1, retBump1 ); + ClampToHDR( linearBump2, retBump2 ); + ClampToHDR( linearBump3, retBump3 ); + } +}; + +#endif // COLORSPACE_H diff --git a/materialsystem/ctexture.cpp b/materialsystem/ctexture.cpp new file mode 100644 index 0000000..dbfac95 --- /dev/null +++ b/materialsystem/ctexture.cpp @@ -0,0 +1,4959 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//=====================================================================================// + +#ifdef PROTECTED_THINGS_ENABLE + #undef PROTECTED_THINGS_ENABLE +#endif + +#include "platform.h" + +// HACK: Need ShellExecute for PSD updates +#ifdef IS_WINDOWS_PC +#include +#include +#pragma comment ( lib, "shell32" ) +#endif + +#include "materialsystem_global.h" +#include "shaderapi/ishaderapi.h" +#include "itextureinternal.h" +#include "utlsymbol.h" +#include "time.h" +#include +#include +#include "bitmap/imageformat.h" +#include "bitmap/tgaloader.h" +#include "bitmap/tgawriter.h" +#ifdef _WIN32 +#include "direct.h" +#endif +#include "colorspace.h" +#include "string.h" +#include +#include +#include "utlmemory.h" +#include "IHardwareConfigInternal.h" +#include "filesystem.h" +#include "tier1/strtools.h" +#include "vtf/vtf.h" +#include "materialsystem/materialsystem_config.h" +#include "mempool.h" +#include "texturemanager.h" +#include "utlbuffer.h" +#include "pixelwriter.h" +#include "tier1/callqueue.h" +#include "tier1/UtlStringMap.h" +#include "filesystem/IQueuedLoader.h" +#include "tier2/fileutils.h" +#include "filesystem.h" +#include "tier2/p4helpers.h" +#include "tier2/tier2.h" +#include "p4lib/ip4.h" +#include "ctype.h" +#include "ifilelist.h" +#include "tier0/icommandline.h" +#include "tier0/vprof.h" + +// NOTE: This must be the last file included!!! +#include "tier0/memdbgon.h" + +// this allows the command line to force the "all mips" flag to on for all textures +bool g_bForceTextureAllMips = false; + +#if defined(IS_WINDOWS_PC) +static void ConVarChanged_mat_managedtextures( IConVar *var, const char *pOldValue, float flOldValue ); +static ConVar mat_managedtextures( "mat_managedtextures", "1", FCVAR_ARCHIVE, "If set, allows Direct3D to manage texture uploading at the cost of extra system memory", &ConVarChanged_mat_managedtextures ); +static void ConVarChanged_mat_managedtextures( IConVar *var, const char *pOldValue, float flOldValue ) +{ + if ( mat_managedtextures.GetBool() != (flOldValue != 0) ) + { + materials->ReleaseResources(); + materials->ReacquireResources(); + } +} +#endif + +static ConVar mat_spew_on_texture_size( "mat_spew_on_texture_size", "0", 0, "Print warnings about vtf content that isn't of the expected size" ); +static ConVar mat_lodin_time( "mat_lodin_time", "5.0", FCVAR_DEVELOPMENTONLY ); +static ConVar mat_lodin_hidden_pop( "mat_lodin_hidden_pop", "1", FCVAR_DEVELOPMENTONLY ); + +#define TEXTURE_FNAME_EXTENSION ".vtf" +#define TEXTURE_FNAME_EXTENSION_LEN 4 +#define TEXTURE_FNAME_EXTENSION_NORMAL "_normal.vtf" + +#ifdef STAGING_ONLY + ConVar mat_spewalloc( "mat_spewalloc", "0" ); +#else + ConVar mat_spewalloc( "mat_spewalloc", "0", FCVAR_ARCHIVE | FCVAR_DEVELOPMENTONLY ); +#endif + +struct TexDimensions_t +{ + uint16 m_nWidth; + uint16 m_nHeight; + uint16 m_nMipCount; + uint16 m_nDepth; + + TexDimensions_t( uint16 nWidth = 0, uint nHeight = 0, uint nMipCount = 0, uint16 nDepth = 1 ) + : m_nWidth( nWidth ) + , m_nHeight( nHeight ) + , m_nMipCount( nMipCount ) + , m_nDepth( nDepth ) + { } +}; + +#ifdef STAGING_ONLY + struct TexInfo_t + { + CUtlString m_Name; + unsigned short m_nWidth; + unsigned short m_nHeight; + unsigned short m_nDepth; + unsigned short m_nMipCount; + unsigned short m_nFrameCount; + unsigned short m_nCopies; + ImageFormat m_Format; + + uint64 ComputeTexSize() const + { + uint64 total = 0; + unsigned short width = m_nWidth; + unsigned short height = m_nHeight; + unsigned short depth = m_nDepth; + + for ( int mip = 0; mip < m_nMipCount; ++mip ) + { + // Make sure that mip count lines up with the count + Assert( width > 1 || height > 1 || depth > 1 || ( mip == ( m_nMipCount - 1 ) ) ); + + total += ImageLoader::GetMemRequired( width, height, depth, m_Format, false ); + + width = Max( 1, width >> 1 ); + height = Max( 1, height >> 1 ); + depth = Max( 1, depth >> 1 ); + } + + return total * Min( (unsigned short) 1, m_nFrameCount ) * Min( (unsigned short) 1, m_nCopies ); + } + + TexInfo_t( const char* name = "", unsigned short w = 0, unsigned short h = 0, unsigned short d = 0, unsigned short mips = 0, unsigned short frames = 0, unsigned short copies = 0, ImageFormat fmt = IMAGE_FORMAT_UNKNOWN ) + : m_nWidth( w ) + , m_nHeight( h ) + , m_nDepth( d ) + , m_nMipCount( mips ) + , m_nFrameCount( frames ) + , m_nCopies( copies ) + , m_Format( fmt ) + { + if ( name && name[0] ) + m_Name = name; + else + m_Name = ""; + } + }; + + CUtlMap< ITexture*, TexInfo_t > g_currentTextures( DefLessFunc( ITexture* ) ); +#endif + +//----------------------------------------------------------------------------- +// Internal texture flags +//----------------------------------------------------------------------------- +enum InternalTextureFlags +{ + TEXTUREFLAGSINTERNAL_ERROR = 0x00000001, + TEXTUREFLAGSINTERNAL_ALLOCATED = 0x00000002, + TEXTUREFLAGSINTERNAL_PRELOADED = 0x00000004, // 360: textures that went through the preload process + TEXTUREFLAGSINTERNAL_QUEUEDLOAD = 0x00000008, // 360: load using the queued loader + TEXTUREFLAGSINTERNAL_EXCLUDED = 0x00000020, // actual exclusion state + TEXTUREFLAGSINTERNAL_SHOULDEXCLUDE = 0x00000040, // desired exclusion state + TEXTUREFLAGSINTERNAL_TEMPRENDERTARGET = 0x00000080, // 360: should only allocate texture bits upon first resolve, destroy at level end +}; + +static int GetThreadId(); +static bool SLoadTextureBitsFromFile( IVTFTexture **ppOutVtfTexture, FileHandle_t hFile, unsigned int nFlags, TextureLODControlSettings_t* pInOutCachedFileLodSettings, int nDesiredDimensionLimit, unsigned short* pOutStreamedMips, const char* pName, const char* pCacheFileName, TexDimensions_t* pOptOutMappingDims = NULL, TexDimensions_t* pOptOutActualDims = NULL, TexDimensions_t* pOptOutAllocatedDims = NULL, unsigned int* pOptOutStripFlags = NULL ); +static int ComputeActualMipCount( const TexDimensions_t& actualDims, unsigned int nFlags ); +static int ComputeMipSkipCount( const char* pName, const TexDimensions_t& mappingDims, bool bIgnorePicmip, IVTFTexture *pOptVTFTexture, unsigned int nFlags, int nDesiredDimensionLimit, unsigned short* pOutStreamedMips, TextureLODControlSettings_t* pInOutCachedFileLodSettings, TexDimensions_t* pOptOutActualDims, TexDimensions_t* pOptOutAllocatedDims, unsigned int* pOptOutStripFlags ); +static int GetOptimalReadBuffer( CUtlBuffer *pOutOptimalBuffer, FileHandle_t hFile, int nFileSize ); +static void FreeOptimalReadBuffer( int nMaxSize ); + +//----------------------------------------------------------------------------- +// Use Warning to show texture flags. +//----------------------------------------------------------------------------- +static void PrintFlags( unsigned int flags ) +{ + if ( flags & TEXTUREFLAGS_NOMIP ) + { + Warning( "TEXTUREFLAGS_NOMIP|" ); + } + if ( flags & TEXTUREFLAGS_NOLOD ) + { + Warning( "TEXTUREFLAGS_NOLOD|" ); + } + if ( flags & TEXTUREFLAGS_SRGB ) + { + Warning( "TEXTUREFLAGS_SRGB|" ); + } + if ( flags & TEXTUREFLAGS_POINTSAMPLE ) + { + Warning( "TEXTUREFLAGS_POINTSAMPLE|" ); + } + if ( flags & TEXTUREFLAGS_TRILINEAR ) + { + Warning( "TEXTUREFLAGS_TRILINEAR|" ); + } + if ( flags & TEXTUREFLAGS_CLAMPS ) + { + Warning( "TEXTUREFLAGS_CLAMPS|" ); + } + if ( flags & TEXTUREFLAGS_CLAMPT ) + { + Warning( "TEXTUREFLAGS_CLAMPT|" ); + } + if ( flags & TEXTUREFLAGS_HINT_DXT5 ) + { + Warning( "TEXTUREFLAGS_HINT_DXT5|" ); + } + if ( flags & TEXTUREFLAGS_ANISOTROPIC ) + { + Warning( "TEXTUREFLAGS_ANISOTROPIC|" ); + } + if ( flags & TEXTUREFLAGS_PROCEDURAL ) + { + Warning( "TEXTUREFLAGS_PROCEDURAL|" ); + } + if ( flags & TEXTUREFLAGS_ALL_MIPS ) + { + Warning( "TEXTUREFLAGS_ALL_MIPS|" ); + } + if ( flags & TEXTUREFLAGS_SINGLECOPY ) + { + Warning( "TEXTUREFLAGS_SINGLECOPY|" ); + } + if ( flags & TEXTUREFLAGS_STAGING_MEMORY ) + { + Warning( "TEXTUREFLAGS_STAGING_MEMORY|" ); + } + if ( flags & TEXTUREFLAGS_IGNORE_PICMIP ) + { + Warning( "TEXTUREFLAGS_IGNORE_PICMIP|" ); + } + if ( flags & TEXTUREFLAGS_IMMEDIATE_CLEANUP ) + { + Warning( "TEXTUREFLAGS_IMMEDIATE_CLEANUP|" ); + } +} + + +namespace TextureLodOverride +{ + struct OverrideInfo + { + OverrideInfo() : x( 0 ), y( 0 ) {} + OverrideInfo( int8 x_, int8 y_ ) : x( x_ ), y( y_ ) {} + int8 x, y; + }; + + // Override map + typedef CUtlStringMap< OverrideInfo > OverrideMap_t; + OverrideMap_t s_OverrideMap; + + // Retrieves the override info adjustments + OverrideInfo Get( char const *szName ) + { + UtlSymId_t idx = s_OverrideMap.Find( szName ); + if ( idx != s_OverrideMap.InvalidIndex() ) + return s_OverrideMap[ idx ]; + else + return OverrideInfo(); + } + + // Combines the existing override info adjustments with the given one + void Add( char const *szName, OverrideInfo oi ) + { + OverrideInfo oiex = Get( szName ); + oiex.x += oi.x; + oiex.y += oi.y; + s_OverrideMap[ szName ] = oiex; + } + +}; // end namespace TextureLodOverride + +class CTextureStreamingJob; + +//----------------------------------------------------------------------------- +// Base texture class +//----------------------------------------------------------------------------- + +class CTexture : public ITextureInternal +{ +public: + CTexture(); + virtual ~CTexture(); + + virtual const char *GetName( void ) const; + const char *GetTextureGroupName( void ) const; + + // Stats about the texture itself + virtual ImageFormat GetImageFormat() const; + NormalDecodeMode_t GetNormalDecodeMode() const { return NORMAL_DECODE_NONE; } + virtual int GetMappingWidth() const; + virtual int GetMappingHeight() const; + virtual int GetActualWidth() const; + virtual int GetActualHeight() const; + virtual int GetNumAnimationFrames() const; + virtual bool IsTranslucent() const; + virtual void GetReflectivity( Vector& reflectivity ); + + // Reference counting + virtual void IncrementReferenceCount( ); + virtual void DecrementReferenceCount( ); + virtual int GetReferenceCount( ); + + // Used to modify the texture bits (procedural textures only) + virtual void SetTextureRegenerator( ITextureRegenerator *pTextureRegen ); + + // Little helper polling methods + virtual bool IsNormalMap( ) const; + virtual bool IsCubeMap( void ) const; + virtual bool IsRenderTarget( ) const; + virtual bool IsTempRenderTarget( void ) const; + virtual bool IsProcedural() const; + virtual bool IsMipmapped() const; + virtual bool IsError() const; + + // For volume textures + virtual bool IsVolumeTexture() const; + virtual int GetMappingDepth() const; + virtual int GetActualDepth() const; + + // Various ways of initializing the texture + void InitFileTexture( const char *pTextureFile, const char *pTextureGroupName ); + void InitProceduralTexture( const char *pTextureName, const char *pTextureGroupName, int w, int h, int d, ImageFormat fmt, int nFlags, ITextureRegenerator* generator = NULL ); + + // Releases the texture's hw memory + void ReleaseMemory(); + + virtual void OnRestore(); + + // Sets the filtering modes on the texture we're modifying + void SetFilteringAndClampingMode( bool bOnlyLodValues = false ); + void Download( Rect_t *pRect = NULL, int nAdditionalCreationFlags = 0 ); + + // Loads up information about the texture + virtual void Precache(); + + // FIXME: Bogus methods... can we please delete these? + virtual void GetLowResColorSample( float s, float t, float *color ) const; + + // Gets texture resource data of the specified type. + // Params: + // eDataType type of resource to retrieve. + // pnumBytes on return is the number of bytes available in the read-only data buffer or is undefined + // Returns: + // pointer to the resource data, or NULL. Note that the data from this pointer can disappear when + // the texture goes away - you want to copy this data! + virtual void *GetResourceData( uint32 eDataType, size_t *pNumBytes ) const; + + virtual int GetApproximateVidMemBytes( void ) const; + + // Stretch blit the framebuffer into this texture. + virtual void CopyFrameBufferToMe( int nRenderTargetID = 0, Rect_t *pSrcRect = NULL, Rect_t *pDstRect = NULL ); + virtual void CopyMeToFrameBuffer( int nRenderTargetID = 0, Rect_t *pSrcRect = NULL, Rect_t *pDstRect = NULL ); + + virtual ITexture *GetEmbeddedTexture( int nIndex ); + + // Get the shaderapi texture handle associated w/ a particular frame + virtual ShaderAPITextureHandle_t GetTextureHandle( int nFrame, int nChannel = 0 ); + + // Sets the texture as the render target + virtual void Bind( Sampler_t sampler ); + virtual void Bind( Sampler_t sampler1, int nFrame, Sampler_t sampler2 = (Sampler_t) -1 ); + virtual void BindVertexTexture( VertexTextureSampler_t stage, int nFrame ); + + // Set this texture as a render target + bool SetRenderTarget( int nRenderTargetID ); + + // Set this texture as a render target (optionally set depth texture as depth buffer as well) + bool SetRenderTarget( int nRenderTargetID, ITexture *pDepthTexture); + + virtual void MarkAsPreloaded( bool bSet ); + virtual bool IsPreloaded() const; + + virtual void MarkAsExcluded( bool bSet, int nDimensionsLimit ); + virtual bool UpdateExcludedState( void ); + + // Retrieve the vtf flags mask + virtual unsigned int GetFlags( void ) const; + + virtual void ForceLODOverride( int iNumLodsOverrideUpOrDown ); + + void GetFilename( char *pOut, int maxLen ) const; + virtual void ReloadFilesInList( IFileList *pFilesToReload ); + + // Save texture to a file. + virtual bool SaveToFile( const char *fileName ); + + // Load the texture from a file. + bool AsyncReadTextureFromFile( IVTFTexture* pVTFTexture, unsigned int nAdditionalCreationFlags ); + void AsyncCancelReadTexture( ); + + virtual void Map( void** pOutBits, int* pOutPitch ); + virtual void Unmap(); + + virtual ResidencyType_t GetCurrentResidence() const { return m_residenceCurrent; } + virtual ResidencyType_t GetTargetResidence() const { return m_residenceTarget; } + virtual bool MakeResident( ResidencyType_t newResidence ); + virtual void UpdateLodBias(); + +protected: + bool IsDepthTextureFormat( ImageFormat fmt ); + void ReconstructTexture( bool bCopyFromCurrent ); + void GetCacheFilename( char* pOutBuffer, int bufferSize ) const; + bool GetFileHandle( FileHandle_t *pOutFileHandle, char *pCacheFilename, char **ppResolvedFilename ) const; + + void ReconstructPartialTexture( const Rect_t *pRect ); + bool HasBeenAllocated() const; + void WriteDataToShaderAPITexture( int nFrameCount, int nFaceCount, int nFirstFace, int nMipCount, IVTFTexture *pVTFTexture, ImageFormat fmt ); + + // Initializes/shuts down the texture + void Init( int w, int h, int d, ImageFormat fmt, int iFlags, int iFrameCount ); + void Shutdown(); + + // Sets the texture name + void SetName( const char* pName ); + + // Assigns/releases texture IDs for our animation frames + void AllocateTextureHandles( ); + void ReleaseTextureHandles( ); + + // Calculates info about whether we can make the texture smaller and by how much + // Returns the number of skipped mip levels + int ComputeActualSize( bool bIgnorePicmip = false, IVTFTexture *pVTFTexture = NULL, bool bTextureMigration = false ); + + // Computes the actual format of the texture given a desired src format + ImageFormat ComputeActualFormat( ImageFormat srcFormat ); + + // Creates/releases the shader api texture + bool AllocateShaderAPITextures(); + void FreeShaderAPITextures(); + void MigrateShaderAPITextures(); + void NotifyUnloadedFile(); + + // Download bits + void DownloadTexture( Rect_t *pRect, bool bCopyFromCurrent = false ); + void ReconstructTextureBits(Rect_t *pRect); + + // Gets us modifying a particular frame of our texture + void Modify( int iFrame ); + + // Sets the texture clamping state on the currently modified frame + void SetWrapState( ); + + // Sets the texture filtering state on the currently modified frame + void SetFilterState(); + + // Sets the lod state on the currently modified frame + void SetLodState(); + + // Loads the texture bits from a file. Optionally provides absolute path + IVTFTexture *LoadTextureBitsFromFile( char *pCacheFileName, char **pResolvedFilename ); + IVTFTexture *HandleFileLoadFailedTexture( IVTFTexture *pVTFTexture ); + + // Generates the procedural bits + IVTFTexture *ReconstructProceduralBits( ); + IVTFTexture *ReconstructPartialProceduralBits( const Rect_t *pRect, Rect_t *pActualRect ); + + // Sets up debugging texture bits, if appropriate + bool SetupDebuggingTextures( IVTFTexture *pTexture ); + + // Generate a texture that shows the various mip levels + void GenerateShowMipLevelsTextures( IVTFTexture *pTexture ); + + void Cleanup( void ); + + // Converts a source image read from disk into its actual format + bool ConvertToActualFormat( IVTFTexture *pTexture ); + + // Builds the low-res image from the texture + void LoadLowResTexture( IVTFTexture *pTexture ); + void CopyLowResImageToTexture( IVTFTexture *pTexture ); + + void GetDownloadFaceCount( int &nFirstFace, int &nFaceCount ); + void ComputeMipLevelSubRect( const Rect_t* pSrcRect, int nMipLevel, Rect_t *pSubRect ); + + IVTFTexture *GetScratchVTFTexture( ); + void ReleaseScratchVTFTexture( IVTFTexture* tex ); + + void ApplyRenderTargetSizeMode( int &width, int &height, ImageFormat fmt ); + + virtual void CopyToStagingTexture( ITexture* pDstTex ); + + virtual void SetErrorTexture( bool _isErrorTexture ); + + // Texture streaming + void MakeNonResident(); + void MakePartiallyResident(); + bool MakeFullyResident(); + + void CancelStreamingJob( bool bJobMustExist = true ); + void OnStreamingJobComplete( ResidencyType_t newResidenceCurrent ); + +protected: +#ifdef _DEBUG + char *m_pDebugName; +#endif + + // Reflectivity vector + Vector m_vecReflectivity; + + CUtlSymbol m_Name; + + // What texture group this texture is in (winds up setting counters based on the group name, + // then the budget panel views the counters). + CUtlSymbol m_TextureGroupName; + + unsigned int m_nFlags; + unsigned int m_nInternalFlags; + + CInterlockedInt m_nRefCount; + + // This is the *desired* image format, which may or may not represent reality + ImageFormat m_ImageFormat; + + // mapping dimensions and actual dimensions can/will vary due to user settings, hardware support, etc. + // Allocated is what is physically allocated on the hardware at this instant, and considers texture streaming. + TexDimensions_t m_dimsMapping; + TexDimensions_t m_dimsActual; + TexDimensions_t m_dimsAllocated; + + // This is the iWidth/iHeight for whatever is downloaded to the card, ignoring current streaming settings + // Some callers want to know how big the texture is if all data was present, and that's this. + // TODO: Rename this before check in. + unsigned short m_nFrameCount; + + // These are the values for what is truly allocated on the card, including streaming settings. + unsigned short m_nStreamingMips; + + unsigned short m_nOriginalRTWidth; // The values they initially specified. We generated a different width + unsigned short m_nOriginalRTHeight; // and height based on screen size and the flags they specify. + + unsigned char m_LowResImageWidth; + unsigned char m_LowResImageHeight; + + unsigned short m_nDesiredDimensionLimit; // part of texture exclusion + unsigned short m_nActualDimensionLimit; // value not necessarily accurate, but mismatch denotes dirty state + + // m_pStreamingJob is refcounted, but it is not safe to call SafeRelease directly on it--you must call + // CancelStreamingJob to ensure that releasing it doesn't cause a crash. + CTextureStreamingJob* m_pStreamingJob; + IVTFTexture* m_pStreamingVTF; + ResidencyType_t m_residenceTarget; + ResidencyType_t m_residenceCurrent; + int m_lodClamp; + int m_lastLodBiasAdjustFrame; + float m_lodBiasInitial; + float m_lodBiasCurrent; + double m_lodBiasStartTime; + + // If the read failed, this will be true. We can't just return from the function because the call may + // happen in the async thread. + bool m_bStreamingFileReadFailed; + + + // The set of texture ids for each animation frame + ShaderAPITextureHandle_t *m_pTextureHandles; + + TextureLODControlSettings_t m_cachedFileLodSettings; + + // lowresimage info - used for getting color data from a texture + // without having a huge system mem overhead. + // FIXME: We should keep this in compressed form. .is currently decompressed at load time. + unsigned char *m_pLowResImage; + + ITextureRegenerator *m_pTextureRegenerator; + + // Used to help decide whether or not to recreate the render target if AA changes. + RenderTargetType_t m_nOriginalRenderTargetType; + RenderTargetSizeMode_t m_RenderTargetSizeMode; + + // Fixed-size allocator +// DECLARE_FIXEDSIZE_ALLOCATOR( CTexture ); +public: + void InitRenderTarget( const char *pRTName, int w, int h, RenderTargetSizeMode_t sizeMode, + ImageFormat fmt, RenderTargetType_t type, unsigned int textureFlags, + unsigned int renderTargetFlags ); + + virtual void DeleteIfUnreferenced(); + + void FixupTexture( const void *pData, int nSize, LoaderError_t loaderError ); + + void SwapContents( ITexture *pOther ); + +protected: + // private data, generally from VTF resource extensions + struct DataChunk + { + void Allocate( unsigned int numBytes ) + { + m_pvData = new unsigned char[ numBytes ]; + m_numBytes = numBytes; + } + void Deallocate() const { delete [] m_pvData; } + + unsigned int m_eType; + unsigned int m_numBytes; + unsigned char *m_pvData; + }; + CUtlVector< DataChunk > m_arrDataChunks; + + struct ScratchVTF + { + ScratchVTF( CTexture* _tex ) : m_pParent( _tex ), m_pScratchVTF( _tex->GetScratchVTFTexture( ) ) { } + ~ScratchVTF( ) + { + if ( m_pScratchVTF ) + m_pParent->ReleaseScratchVTFTexture( m_pScratchVTF ); + m_pScratchVTF = NULL; + } + + IVTFTexture* Get() const { return m_pScratchVTF; } + void TakeOwnership() { m_pScratchVTF = NULL; } + + CTexture* m_pParent; + IVTFTexture* m_pScratchVTF; + }; + + friend class CTextureStreamingJob; +}; + +class CTextureStreamingJob : public IAsyncTextureOperationReceiver +{ +public: + CTextureStreamingJob( CTexture* pTex ) : m_referenceCount( 0 ), m_pOwner( pTex ) { Assert( m_pOwner != NULL ); m_pOwner->AddRef(); } + virtual ~CTextureStreamingJob() { SafeRelease( &m_pOwner ); } + + virtual int AddRef() OVERRIDE { return ++m_referenceCount; } + virtual int Release() OVERRIDE { int retVal = --m_referenceCount; Assert( retVal >= 0 ); if ( retVal == 0 ) { delete this; } return retVal; } + virtual int GetRefCount() const OVERRIDE { return m_referenceCount; } + + virtual void OnAsyncCreateComplete( ITexture* pTex, void* pExtraArgs ) OVERRIDE { Assert( !"unimpl" ); } + virtual void OnAsyncFindComplete( ITexture* pTex, void* pExtraArgs ) OVERRIDE; + virtual void OnAsyncMapComplete( ITexture* pTex, void* pExtraArgs, void* pMemory, int nPitch ) { Assert( !"unimpl" ); } + virtual void OnAsyncReadbackBegin( ITexture* pDst, ITexture* pSrc, void* pExtraArgs ) OVERRIDE { Assert( !"unimpl" ); } + + void ForgetOwner( ITextureInternal* pTex ) { Assert( pTex == m_pOwner ); SafeRelease( &m_pOwner ); } + +private: + CInterlockedInt m_referenceCount; + CTexture* m_pOwner; +}; + +////////////////////////////////////////////////////////////////////////// +// +// CReferenceToHandleTexture is a special implementation of ITexture +// to be used solely for binding the texture handle when rendering. +// It is used when a D3D texture handle is available, but should be used +// at a higher level of abstraction requiring an ITexture or ITextureInternal. +// +////////////////////////////////////////////////////////////////////////// +class CReferenceToHandleTexture : public ITextureInternal +{ +public: + CReferenceToHandleTexture(); + virtual ~CReferenceToHandleTexture(); + + virtual const char *GetName( void ) const { return m_Name.String(); } + const char *GetTextureGroupName( void ) const { return m_TextureGroupName.String(); } + + // Stats about the texture itself + virtual ImageFormat GetImageFormat() const { return IMAGE_FORMAT_UNKNOWN; } + virtual NormalDecodeMode_t GetNormalDecodeMode() const { return NORMAL_DECODE_NONE; } + virtual int GetMappingWidth() const { return 1; } + virtual int GetMappingHeight() const { return 1; } + virtual int GetActualWidth() const { return 1; } + virtual int GetActualHeight() const { return 1; } + virtual int GetNumAnimationFrames() const { return 1; } + virtual bool IsTranslucent() const { return false; } + virtual void GetReflectivity( Vector& reflectivity ) { reflectivity.Zero(); } + + // Reference counting + virtual void IncrementReferenceCount( ) { ++ m_nRefCount; } + virtual void DecrementReferenceCount( ) { -- m_nRefCount; } + virtual int GetReferenceCount( ) { return m_nRefCount; } + + // Used to modify the texture bits (procedural textures only) + virtual void SetTextureRegenerator( ITextureRegenerator *pTextureRegen ) { NULL; } + + // Little helper polling methods + virtual bool IsNormalMap( ) const { return false; } + virtual bool IsCubeMap( void ) const { return false; } + virtual bool IsRenderTarget( ) const { return false; } + virtual bool IsTempRenderTarget( void ) const { return false; } + virtual bool IsProcedural() const { return true; } + virtual bool IsMipmapped() const { return false; } + virtual bool IsError() const { return false; } + + // For volume textures + virtual bool IsVolumeTexture() const { return false; } + virtual int GetMappingDepth() const { return 1; } + virtual int GetActualDepth() const { return 1; } + + // Releases the texture's hw memory + void ReleaseMemory() { NULL; } + + virtual void OnRestore() { NULL; } + + // Sets the filtering modes on the texture we're modifying + void SetFilteringAndClampingMode( bool bOnlyLodValues = false ) { NULL; } + void Download( Rect_t *pRect = NULL, int nAdditionalCreationFlags = 0 ) { NULL; } + + // Loads up information about the texture + virtual void Precache() { NULL; } + + // FIXME: Bogus methods... can we please delete these? + virtual void GetLowResColorSample( float s, float t, float *color ) const { NULL; } + + // Gets texture resource data of the specified type. + // Params: + // eDataType type of resource to retrieve. + // pnumBytes on return is the number of bytes available in the read-only data buffer or is undefined + // Returns: + // pointer to the resource data, or NULL. Note that the data from this pointer can disappear when + // the texture goes away - you want to copy this data! + virtual void *GetResourceData( uint32 eDataType, size_t *pNumBytes ) const { return NULL; } + + virtual int GetApproximateVidMemBytes( void ) const { return 32; } + + // Stretch blit the framebuffer into this texture. + virtual void CopyFrameBufferToMe( int nRenderTargetID = 0, Rect_t *pSrcRect = NULL, Rect_t *pDstRect = NULL ) { NULL; } + virtual void CopyMeToFrameBuffer( int nRenderTargetID = 0, Rect_t *pSrcRect = NULL, Rect_t *pDstRect = NULL ) { NULL; } + + virtual ITexture *GetEmbeddedTexture( int nIndex ) { return ( nIndex == 0 ) ? this : NULL; } + + // Get the shaderapi texture handle associated w/ a particular frame + virtual ShaderAPITextureHandle_t GetTextureHandle( int nFrame, int nTextureChannel = 0 ) { return m_hTexture; } + + // Bind the texture + virtual void Bind( Sampler_t sampler ); + virtual void Bind( Sampler_t sampler1, int nFrame, Sampler_t sampler2 = (Sampler_t) -1 ); + virtual void BindVertexTexture( VertexTextureSampler_t stage, int nFrame ); + + // Set this texture as a render target + bool SetRenderTarget( int nRenderTargetID ) { return SetRenderTarget( nRenderTargetID, NULL ); } + + // Set this texture as a render target (optionally set depth texture as depth buffer as well) + bool SetRenderTarget( int nRenderTargetID, ITexture *pDepthTexture) { return false; } + + virtual void MarkAsPreloaded( bool bSet ) { NULL; } + virtual bool IsPreloaded() const { return true; } + + virtual void MarkAsExcluded( bool bSet, int nDimensionsLimit ) { NULL; } + virtual bool UpdateExcludedState( void ) { return true; } + + // Retrieve the vtf flags mask + virtual unsigned int GetFlags( void ) const { return 0; } + + virtual void ForceLODOverride( int iNumLodsOverrideUpOrDown ) { NULL; } + + virtual void ReloadFilesInList( IFileList *pFilesToReload ) {} + + // Save texture to a file. + virtual bool SaveToFile( const char *fileName ) { return false; } + + virtual bool AsyncReadTextureFromFile( IVTFTexture* pVTFTexture, unsigned int nAdditionalCreationFlags ) { Assert( !"Should never get here." ); return false; } + virtual void AsyncCancelReadTexture() { Assert( !"Should never get here." ); } + + virtual void CopyToStagingTexture( ITexture* pDstTex ) { Assert( !"Should never get here." ); }; + + // Map and unmap. These can fail. And can cause a very significant perf penalty. Be very careful with them. + virtual void Map( void** pOutBits, int* pOutPitch ) { } + virtual void Unmap() { } + + virtual ResidencyType_t GetCurrentResidence() const { return RESIDENT_FULL; } + virtual ResidencyType_t GetTargetResidence() const { return RESIDENT_FULL; } + virtual bool MakeResident( ResidencyType_t newResidence ) { Assert( !"Unimpl" ); return true; } + virtual void UpdateLodBias() {} + + virtual void SetErrorTexture( bool isErrorTexture ) { } + +protected: +#ifdef _DEBUG + char *m_pDebugName; +#endif + + CUtlSymbol m_Name; + + // What texture group this texture is in (winds up setting counters based on the group name, + // then the budget panel views the counters). + CUtlSymbol m_TextureGroupName; + + // The set of texture ids for each animation frame + ShaderAPITextureHandle_t m_hTexture; + + // Refcount + int m_nRefCount; + +public: + virtual void DeleteIfUnreferenced(); + + void FixupTexture( const void *pData, int nSize, LoaderError_t loaderError ) { NULL; } + + void SwapContents( ITexture *pOther ) { NULL; } + +public: + void SetName( char const *szName ); + void InitFromHandle( + const char *pTextureName, + const char *pTextureGroupName, + ShaderAPITextureHandle_t hTexture ); +}; + +CReferenceToHandleTexture::CReferenceToHandleTexture() : + m_hTexture( INVALID_SHADERAPI_TEXTURE_HANDLE ), +#ifdef _DEBUG + m_pDebugName( NULL ), +#endif + m_nRefCount( 0 ) +{ + NULL; +} + +CReferenceToHandleTexture::~CReferenceToHandleTexture() +{ +#ifdef _DEBUG + if ( m_nRefCount != 0 ) + { + Warning( "Reference Count(%d) != 0 in ~CReferenceToHandleTexture for texture \"%s\"\n", m_nRefCount, m_Name.String() ); + } + if ( m_pDebugName ) + { + delete [] m_pDebugName; + } +#endif +} + +void CReferenceToHandleTexture::SetName( char const *szName ) +{ + // normalize and convert to a symbol + char szCleanName[MAX_PATH]; + m_Name = NormalizeTextureName( szName, szCleanName, sizeof( szCleanName ) ); + +#ifdef _DEBUG + if ( m_pDebugName ) + { + delete [] m_pDebugName; + } + int nLen = V_strlen( szCleanName ) + 1; + m_pDebugName = new char[nLen]; + V_memcpy( m_pDebugName, szCleanName, nLen ); +#endif +} + +void CReferenceToHandleTexture::InitFromHandle( const char *pTextureName, const char *pTextureGroupName, ShaderAPITextureHandle_t hTexture ) +{ + SetName( pTextureName ); + m_TextureGroupName = pTextureGroupName; + m_hTexture = hTexture; +} + +void CReferenceToHandleTexture::Bind( Sampler_t sampler ) +{ + if ( g_pShaderDevice->IsUsingGraphics() ) + { + g_pShaderAPI->BindTexture( sampler, m_hTexture ); + } +} + + +// TODO: make paired textures work with mat_texture_list +void CReferenceToHandleTexture::Bind( Sampler_t sampler1, int nFrame, Sampler_t sampler2 /* = -1 */ ) +{ + if ( g_pShaderDevice->IsUsingGraphics() ) + { + g_pShaderAPI->BindTexture( sampler1, m_hTexture ); + } +} + + +void CReferenceToHandleTexture::BindVertexTexture( VertexTextureSampler_t sampler, int nFrame ) +{ + if ( g_pShaderDevice->IsUsingGraphics() ) + { + g_pShaderAPI->BindVertexTexture( sampler, m_hTexture ); + } +} + +void CReferenceToHandleTexture::DeleteIfUnreferenced() +{ + if ( m_nRefCount > 0 ) + return; + + TextureManager()->RemoveTexture( this ); +} + + +//----------------------------------------------------------------------------- +// Fixed-size allocator +//----------------------------------------------------------------------------- +//DEFINE_FIXEDSIZE_ALLOCATOR( CTexture, 1024, true ); + + +//----------------------------------------------------------------------------- +// Static instance of VTF texture +//----------------------------------------------------------------------------- +#define MAX_RENDER_THREADS 4 + +// For safety's sake, we allow any of the threads that intersect with rendering +// to have their own state vars. In practice, we expect only the matqueue thread +// and the main thread to ever hit s_pVTFTexture. +static IVTFTexture *s_pVTFTexture[ MAX_RENDER_THREADS ] = { NULL }; + +// We only expect that the main thread or the matqueue thread to actually touch +// these, but we still need a NULL and size of 0 for the other threads. +static void *s_pOptimalReadBuffer[ MAX_RENDER_THREADS ] = { NULL }; +static int s_nOptimalReadBufferSize[ MAX_RENDER_THREADS ] = { 0 }; + +//----------------------------------------------------------------------------- +// Class factory methods +//----------------------------------------------------------------------------- +ITextureInternal *ITextureInternal::CreateFileTexture( const char *pFileName, const char *pTextureGroupName ) +{ + CTexture *pTex = new CTexture; + pTex->InitFileTexture( pFileName, pTextureGroupName ); + return pTex; +} + +ITextureInternal *ITextureInternal::CreateReferenceTextureFromHandle( + const char *pTextureName, + const char *pTextureGroupName, + ShaderAPITextureHandle_t hTexture ) +{ + CReferenceToHandleTexture *pTex = new CReferenceToHandleTexture; + pTex->InitFromHandle( pTextureName, pTextureGroupName, hTexture ); + return pTex; +} + +ITextureInternal *ITextureInternal::CreateProceduralTexture( + const char *pTextureName, + const char *pTextureGroupName, + int w, + int h, + int d, + ImageFormat fmt, + int nFlags, + ITextureRegenerator *generator) +{ + CTexture *pTex = new CTexture; + pTex->InitProceduralTexture( pTextureName, pTextureGroupName, w, h, d, fmt, nFlags, generator ); + pTex->IncrementReferenceCount(); + return pTex; +} + +// GR - named RT +ITextureInternal *ITextureInternal::CreateRenderTarget( + const char *pRTName, + int w, + int h, + RenderTargetSizeMode_t sizeMode, + ImageFormat fmt, + RenderTargetType_t type, + unsigned int textureFlags, + unsigned int renderTargetFlags ) +{ + CTexture *pTex = new CTexture; + pTex->InitRenderTarget( pRTName, w, h, sizeMode, fmt, type, textureFlags, renderTargetFlags ); + + return pTex; +} + +//----------------------------------------------------------------------------- +// Rebuild and exisiting render target in place. +//----------------------------------------------------------------------------- +void ITextureInternal::ChangeRenderTarget( + ITextureInternal *pTex, + int w, + int h, + RenderTargetSizeMode_t sizeMode, + ImageFormat fmt, + RenderTargetType_t type, + unsigned int textureFlags, + unsigned int renderTargetFlags ) +{ + pTex->ReleaseMemory(); + dynamic_cast< CTexture * >(pTex)->InitRenderTarget( pTex->GetName(), w, h, sizeMode, fmt, type, textureFlags, renderTargetFlags ); +} + +void ITextureInternal::Destroy( ITextureInternal *pTex, bool bSkipTexMgrCheck ) +{ + #ifdef STAGING_ONLY + if ( !bSkipTexMgrCheck && TextureManager()->HasPendingTextureDestroys() ) + { + // Multithreading badness. This will cause a crash later! Grab JohnS or McJohn know! + DebuggerBreakIfDebugging_StagingOnly(); + } + #endif + + int iIndex = g_pTextureRefList->Find( static_cast( pTex ) ); + if ( iIndex != g_pTextureRefList->InvalidIndex () ) + { + if ( g_pTextureRefList->Element(iIndex) != 0 ) + { + int currentCount = g_pTextureRefList->Element( iIndex ); + Warning( "Destroying a texture that is in the queue: %s (%p): %d!\n", pTex->GetName(), pTex, currentCount ); + } + } + + delete pTex; +} + +//----------------------------------------------------------------------------- +// Constructor, destructor +//----------------------------------------------------------------------------- +CTexture::CTexture() : m_ImageFormat( IMAGE_FORMAT_UNKNOWN ) +{ + m_dimsActual.m_nMipCount = 0; + m_dimsMapping.m_nWidth = 0; + m_dimsMapping.m_nHeight = 0; + m_dimsMapping.m_nDepth = 1; + m_dimsActual.m_nWidth = 0; + m_dimsActual.m_nHeight = 0; + m_dimsActual.m_nDepth = 1; + m_dimsAllocated.m_nWidth = 0; + m_dimsAllocated.m_nHeight = 0; + m_dimsAllocated.m_nDepth = 0; + m_dimsAllocated.m_nMipCount = 0; + m_nStreamingMips = 0; + m_nRefCount = 0; + m_nFlags = 0; + m_nInternalFlags = 0; + m_pTextureHandles = NULL; + m_nFrameCount = 0; + VectorClear( m_vecReflectivity ); + m_pTextureRegenerator = NULL; + m_nOriginalRenderTargetType = NO_RENDER_TARGET; + m_RenderTargetSizeMode = RT_SIZE_NO_CHANGE; + m_nOriginalRTWidth = m_nOriginalRTHeight = 1; + + m_LowResImageWidth = 0; + m_LowResImageHeight = 0; + m_pLowResImage = NULL; + + m_pStreamingJob = NULL; + m_residenceTarget = RESIDENT_NONE; + m_residenceCurrent = RESIDENT_NONE; + m_lodClamp = 0; + m_lodBiasInitial = 0; + m_lodBiasCurrent = 0; + + m_nDesiredDimensionLimit = 0; + m_nActualDimensionLimit = 0; + + memset( &m_cachedFileLodSettings, 0, sizeof( m_cachedFileLodSettings ) ); + +#ifdef _DEBUG + m_pDebugName = NULL; +#endif + + m_pStreamingVTF = NULL; + m_bStreamingFileReadFailed = false; +} + +CTexture::~CTexture() +{ +#ifdef _DEBUG + if ( m_nRefCount != 0 ) + { + Warning( "Reference Count(%d) != 0 in ~CTexture for texture \"%s\"\n", (int)m_nRefCount, m_Name.String() ); + } +#endif + + Shutdown(); + +#ifdef _DEBUG + if ( m_pDebugName ) + { + // delete[] m_pDebugName; + } +#endif + + // Deliberately stomp our VTable so that we can detect cases where code tries to access freed materials. + int *p = (int *)this; + *p = 0xdeadbeef; +} + + +//----------------------------------------------------------------------------- +// Initializes the texture +//----------------------------------------------------------------------------- +void CTexture::Init( int w, int h, int d, ImageFormat fmt, int iFlags, int iFrameCount ) +{ + Assert( iFrameCount > 0 ); + + // This is necessary to prevent blowing away the allocated state, + // which is necessary for the ReleaseTextureHandles call below to work. + SetErrorTexture( false ); + + // free and release previous data + // cannot change to new intialization parameters yet + FreeShaderAPITextures(); + ReleaseTextureHandles(); + + // update to new initialization parameters + // these are the *desired* new values + m_dimsMapping.m_nWidth = w; + m_dimsMapping.m_nHeight = h; + m_dimsMapping.m_nDepth = d; + m_ImageFormat = fmt; + m_nFrameCount = iFrameCount; + // We don't know the actual width and height until we get it ready to render + m_dimsActual.m_nWidth = m_dimsActual.m_nHeight = 0; + m_dimsActual.m_nDepth = 1; + m_dimsActual.m_nMipCount = 0; + + m_dimsAllocated.m_nWidth = 0; + m_dimsAllocated.m_nHeight = 0; + m_dimsAllocated.m_nDepth = 0; + m_dimsAllocated.m_nMipCount = 0; + m_nStreamingMips = 0; + + // Clear the m_nFlags bit. If we don't, then m_nFrameCount may end up being 1, and + // TEXTUREFLAGS_DEPTHRENDERTARGET could be set. + m_nFlags &= ~TEXTUREFLAGS_DEPTHRENDERTARGET; + m_nFlags |= iFlags; + + CancelStreamingJob( false ); + m_residenceTarget = RESIDENT_NONE; + m_residenceCurrent = RESIDENT_NONE; + m_lodClamp = 0; + m_lodBiasInitial = 0; + m_lodBiasCurrent = 0; + + AllocateTextureHandles(); +} + + +//----------------------------------------------------------------------------- +// Shuts down the texture +//----------------------------------------------------------------------------- +void CTexture::Shutdown() +{ + Assert( m_pStreamingVTF == NULL ); + + // Clean up the low-res texture + delete[] m_pLowResImage; + m_pLowResImage = 0; + + // Clean up the resources data + for ( DataChunk const *pDataChunk = m_arrDataChunks.Base(), + *pDataChunkEnd = pDataChunk + m_arrDataChunks.Count(); + pDataChunk < pDataChunkEnd; ++pDataChunk ) + { + pDataChunk->Deallocate(); + } + m_arrDataChunks.RemoveAll(); + + // Frees the texture regen class + if ( m_pTextureRegenerator ) + { + m_pTextureRegenerator->Release(); + m_pTextureRegenerator = NULL; + } + + CancelStreamingJob( false ); + + m_residenceTarget = RESIDENT_NONE; + m_residenceCurrent = RESIDENT_NONE; + m_lodClamp = 0; + m_lodBiasInitial = 0; + m_lodBiasCurrent = 0; + + // This deletes the textures + FreeShaderAPITextures(); + ReleaseTextureHandles(); + NotifyUnloadedFile(); +} + +void CTexture::ReleaseMemory() +{ + FreeShaderAPITextures(); + NotifyUnloadedFile(); +} + +IVTFTexture *CTexture::GetScratchVTFTexture( ) +{ + const bool cbThreadInMatQueue = ( MaterialSystem()->GetRenderThreadId() == ThreadGetCurrentId() ); cbThreadInMatQueue; + Assert( cbThreadInMatQueue || ThreadInMainThread() ); + + const int ti = GetThreadId(); + + if ( !s_pVTFTexture[ ti ] ) + s_pVTFTexture[ ti ] = CreateVTFTexture(); + return s_pVTFTexture[ ti ]; +} + +void CTexture::ReleaseScratchVTFTexture( IVTFTexture* tex ) +{ + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s", __FUNCTION__ ); + + const bool cbThreadInMatQueue = ( MaterialSystem()->GetRenderThreadId() == ThreadGetCurrentId() ); cbThreadInMatQueue; + Assert( cbThreadInMatQueue || ThreadInMainThread() ); + Assert( m_pStreamingVTF == NULL || ThreadInMainThread() ); // Can only manipulate m_pStreamingVTF to release safely in main thread. + + if ( m_pStreamingVTF ) + { + Assert( tex == m_pStreamingVTF ); + TextureManager()->ReleaseAsyncScratchVTF( m_pStreamingVTF ); + m_pStreamingVTF = NULL; + return; + } + + // Normal scratch main-thread vtf doesn't need to do anything. + +} + +//----------------------------------------------------------------------------- +// +// Various initialization methods +// +//----------------------------------------------------------------------------- +void CTexture::ApplyRenderTargetSizeMode( int &width, int &height, ImageFormat fmt ) +{ + width = m_nOriginalRTWidth; + height = m_nOriginalRTHeight; + + switch ( m_RenderTargetSizeMode ) + { + case RT_SIZE_FULL_FRAME_BUFFER: + { + MaterialSystem()->GetRenderTargetFrameBufferDimensions( width, height ); + if( !HardwareConfig()->SupportsNonPow2Textures() ) + { + width = FloorPow2( width + 1 ); + height = FloorPow2( height + 1 ); + } + } + break; + + case RT_SIZE_FULL_FRAME_BUFFER_ROUNDED_UP: + { + MaterialSystem()->GetRenderTargetFrameBufferDimensions( width, height ); + if( !HardwareConfig()->SupportsNonPow2Textures() ) + { + width = CeilPow2( width ); + height = CeilPow2( height ); + } + } + break; + + case RT_SIZE_PICMIP: + { + int fbWidth, fbHeight; + MaterialSystem()->GetRenderTargetFrameBufferDimensions( fbWidth, fbHeight ); + int picmip = g_config.skipMipLevels; + while( picmip > 0 ) + { + width >>= 1; + height >>= 1; + picmip--; + } + + while( width > fbWidth ) + { + width >>= 1; + } + while( height > fbHeight ) + { + height >>= 1; + } + } + break; + + case RT_SIZE_DEFAULT: + { + // Assume that the input is pow2. + Assert( ( width & ( width - 1 ) ) == 0 ); + Assert( ( height & ( height - 1 ) ) == 0 ); + int fbWidth, fbHeight; + MaterialSystem()->GetRenderTargetFrameBufferDimensions( fbWidth, fbHeight ); + while( width > fbWidth ) + { + width >>= 1; + } + while( height > fbHeight ) + { + height >>= 1; + } + } + break; + + case RT_SIZE_HDR: + { + MaterialSystem()->GetRenderTargetFrameBufferDimensions( width, height ); + width = width / 4; + height = height / 4; + } + break; + + case RT_SIZE_OFFSCREEN: + { + int fbWidth, fbHeight; + MaterialSystem()->GetRenderTargetFrameBufferDimensions( fbWidth, fbHeight ); + + // Shrink the buffer if it's bigger than back buffer. Otherwise, don't mess with it. + while( (width > fbWidth) || (height > fbHeight) ) + { + width >>= 1; + height >>= 1; + } + } + break; + + case RT_SIZE_LITERAL: + { + // Literal means literally don't mess with the dimensions. Unlike what OFFSCREEN does, + // which is totally to mess with the dimensions. + } + break; + + case RT_SIZE_LITERAL_PICMIP: + { + // Don't do anything here, like literal. Later, we will pay attention to picmip settings s.t. + // these render targets look like other textures wrt Mapping Dimensions vs Actual Dimensions. + } + break; + + case RT_SIZE_REPLAY_SCREENSHOT: + { + // Compute all possible resolutions if first time we're running this function + static bool bReplayInit = false; + static int m_aScreenshotWidths[ 3 ][ 2 ]; + static ConVarRef replay_screenshotresolution( "replay_screenshotresolution" ); + + if ( !bReplayInit ) + { + bReplayInit = true; + for ( int iAspect = 0; iAspect < 3; ++iAspect ) + { + for ( int iRes = 0; iRes < 2; ++iRes ) + { + int nWidth = (int)FastPow2( 9 + iRes ); + m_aScreenshotWidths[ iAspect ][ iRes ] = nWidth; + } + } + } + + // Get dimensions for unpadded image + int nUnpaddedWidth, nUnpaddedHeight; + + // Figure out the proper screenshot size to use based on the aspect ratio + int nScreenWidth, nScreenHeight; + MaterialSystem()->GetRenderTargetFrameBufferDimensions( nScreenWidth, nScreenHeight ); + float flAspectRatio = (float)nScreenWidth / nScreenHeight; + + // Get the screenshot res + int iRes = clamp( replay_screenshotresolution.GetInt(), 0, 1 ); + + int iAspect; + if ( flAspectRatio == 16.0f/9 ) + { + iAspect = 0; + } + else if ( flAspectRatio == 16.0f/10 ) + { + iAspect = 1; + } + else + { + iAspect = 2; // 4:3 + } + + static float s_flInvAspectRatios[3] = { 9.0f/16.0f, 10.0f/16, 3.0f/4 }; + nUnpaddedWidth = min( nScreenWidth, m_aScreenshotWidths[ iAspect ][ iRes ] ); + nUnpaddedHeight = m_aScreenshotWidths[ iAspect ][ iRes ] * s_flInvAspectRatios[ iAspect ]; + + // Get dimensions for padded image based on unpadded size - must be power of 2 for a material/texture + width = SmallestPowerOfTwoGreaterOrEqual( nUnpaddedWidth ); + height = SmallestPowerOfTwoGreaterOrEqual( nUnpaddedHeight ); + } + break; + + default: + { + if ( !HushAsserts() ) + { + Assert( m_RenderTargetSizeMode == RT_SIZE_NO_CHANGE ); + Assert( m_nOriginalRenderTargetType == RENDER_TARGET_NO_DEPTH ); // Only can use NO_CHANGE if we don't have a depth buffer. + } + } + break; + } +} + +void CTexture::CopyToStagingTexture( ITexture* pDstTex ) +{ + Assert( pDstTex ); + + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s", __FUNCTION__ ); + + // Need to flush any commands in flight on our side of things + materials->Flush( false ); + + CTexture* pDstTexActual = assert_cast< CTexture* >( pDstTex ); + + // Then do the copy if everything is on the up and up. + if ( ( m_pTextureHandles == NULL || m_nFrameCount == 0 ) || ( pDstTexActual->m_pTextureHandles == NULL || pDstTexActual->m_nFrameCount == 0 ) ) + { + Assert( !"Can't copy to a non-existent texture, may need to generate or something." ); + return; + } + + // Make sure we've actually got the right surface types. + Assert( m_nFlags & TEXTUREFLAGS_RENDERTARGET ); + Assert( pDstTex->GetFlags() & TEXTUREFLAGS_STAGING_MEMORY ); + + g_pShaderAPI->CopyRenderTargetToScratchTexture( m_pTextureHandles[0], pDstTexActual->m_pTextureHandles[0] ); +} + +void CTexture::Map( void** pOutBits, int* pOutPitch ) +{ + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s", __FUNCTION__ ); + + // Must be a staging texture to avoid catastrophic perf fail. + Assert( m_nFlags & TEXTUREFLAGS_STAGING_MEMORY ); + + if ( m_pTextureHandles == NULL || m_nFrameCount == 0 ) + { + Assert( !"Can't map a non-existent texture, may need to generate or something." ); + return; + } + + g_pShaderAPI->LockRect( pOutBits, pOutPitch, m_pTextureHandles[ 0 ], 0, 0, 0, GetActualWidth(), GetActualHeight(), false, true ); +} + +void CTexture::Unmap() +{ + if ( m_pTextureHandles == NULL || m_nFrameCount == 0 ) + { + Assert( !"Can't unmap a non-existent texture, may need to generate or something." ); + return; + } + + g_pShaderAPI->UnlockRect( m_pTextureHandles[ 0 ], 0 ); +} + +bool CTexture::MakeResident( ResidencyType_t newResidence ) +{ + Assert( ( GetFlags() & TEXTUREFLAGS_STREAMABLE ) != 0 ); + + // If we already think we're supposed to go here, nothing to do and we should report success. + if ( m_residenceTarget == newResidence ) + return true; + + TM_ZONE_DEFAULT( TELEMETRY_LEVEL0 ); + + // What are we moving towards? + switch ( newResidence ) + { + case RESIDENT_NONE: + MakeNonResident(); + return true; + + case RESIDENT_PARTIAL: + MakePartiallyResident(); + return true; + + case RESIDENT_FULL: + return MakeFullyResident(); + + default: + Assert( !"Missing switch statement" ); + }; + + return false; +} + +void CTexture::UpdateLodBias() +{ + if ( m_lodBiasInitial == 0.0f ) + return; + + // Only perform adjustment once per frame. + if ( m_lastLodBiasAdjustFrame == g_FrameNum ) + return; + + bool bPopIn = mat_lodin_time.GetFloat() == 0; + + if ( bPopIn && m_lodBiasInitial == 0.0f ) + return; + + if ( !bPopIn ) + m_lodBiasCurrent = m_lodBiasInitial - ( Plat_FloatTime() - m_lodBiasStartTime ) / mat_lodin_time.GetFloat() * m_lodBiasInitial; + else + m_lodBiasCurrent = m_lodBiasInitial = 0.0f; + + // If we're supposed to pop in when the object isn't visible and we have the opportunity... + if ( mat_lodin_hidden_pop.GetBool() && m_lastLodBiasAdjustFrame != g_FrameNum - 1 ) + m_lodBiasCurrent = m_lodBiasInitial = 0.0f; + + if ( m_lodBiasCurrent <= 0.0f ) + { + m_lodBiasCurrent = m_lodBiasInitial = 0.0f; + m_lodBiasStartTime = 0; + } + + m_lastLodBiasAdjustFrame = g_FrameNum; + SetFilteringAndClampingMode( true ); +} + +void CTexture::MakeNonResident() +{ + if ( m_residenceCurrent != RESIDENT_NONE ) + Shutdown(); + + m_residenceCurrent = m_residenceTarget = RESIDENT_NONE; + + // Clear our the streamable fine flag to ensure we reload properly. + m_nFlags &= ~TEXTUREFLAGS_STREAMABLE_FINE; +} + +void CTexture::MakePartiallyResident() +{ + TM_ZONE_DEFAULT( TELEMETRY_LEVEL0 ); + + ResidencyType_t oldCurrentResidence = m_residenceCurrent; + ResidencyType_t oldTargetResidence = m_residenceTarget; + + m_residenceCurrent = m_residenceTarget = RESIDENT_PARTIAL; + + if ( oldCurrentResidence == RESIDENT_PARTIAL ) + { + Assert( oldTargetResidence == RESIDENT_FULL ); oldTargetResidence; + // If we are already partially resident, then just cancel our job to stream in, + // cause we don't need that data anymore. + CancelStreamingJob(); + + return; + } + + Assert( oldCurrentResidence == RESIDENT_FULL ); + + // Clear the fine bit. + m_nFlags &= ~TEXTUREFLAGS_STREAMABLE_FINE; + + if ( HardwareConfig()->CanStretchRectFromTextures() ) + { + m_lodClamp = 0; + m_lodBiasInitial = m_lodBiasCurrent = 0; + m_lastLodBiasAdjustFrame = g_FrameNum; + DownloadTexture( NULL, true ); + } + else + { + // Oops. We were overzealous above--restore the residency to what it was. + m_residenceCurrent = oldCurrentResidence; + + // Immediately display it as lower res (for consistency) but if we can't (efficiently) + // copy we just have to re-read everything from disk. Lame! + m_lodClamp = 3; + m_lodBiasInitial = m_lodBiasCurrent = 0; + m_lastLodBiasAdjustFrame = g_FrameNum; + SetFilteringAndClampingMode( true ); + + SafeAssign( &m_pStreamingJob, new CTextureStreamingJob( this ) ); + MaterialSystem()->AsyncFindTexture( GetName(), GetTextureGroupName(), m_pStreamingJob, (void*) RESIDENT_PARTIAL, false, TEXTUREFLAGS_STREAMABLE_COARSE ); + } +} + +bool CTexture::MakeFullyResident() +{ + TM_ZONE_DEFAULT( TELEMETRY_LEVEL0 ); + + ResidencyType_t oldCurrentResidence = m_residenceCurrent; + ResidencyType_t oldTargetResidence = m_residenceTarget; + + if ( oldCurrentResidence == RESIDENT_FULL ) + { + // This isn't a requirement, but right now it would be a mistake + Assert( !HardwareConfig()->CanStretchRectFromTextures() ); + Assert( oldTargetResidence == RESIDENT_PARTIAL ); oldTargetResidence; + + m_residenceCurrent = m_residenceTarget = RESIDENT_FULL; + m_lodClamp = 0; + m_lodBiasInitial = m_lodBiasCurrent = 0; + m_lastLodBiasAdjustFrame = g_FrameNum; + SetFilteringAndClampingMode( true ); + + CancelStreamingJob(); + return true; + } + + Assert( m_residenceTarget == RESIDENT_PARTIAL && m_residenceCurrent == RESIDENT_PARTIAL ); + Assert( m_pStreamingJob == NULL ); + + SafeAssign( &m_pStreamingJob, new CTextureStreamingJob( this ) ); + MaterialSystem()->AsyncFindTexture( GetName(), GetTextureGroupName(), m_pStreamingJob, (void*) RESIDENT_FULL, false, TEXTUREFLAGS_STREAMABLE_FINE ); + + m_residenceTarget = RESIDENT_FULL; + + return true; +} + +void CTexture::CancelStreamingJob( bool bJobMustExist ) +{ + bJobMustExist; // Only used by asserts ensuring correctness, so reference it for release builds. + + // Most callers should be aware of whether the job exists, but for cleanup we don't know and we + // should be safe in that case. + Assert( !bJobMustExist || m_pStreamingJob ); + if ( !m_pStreamingJob ) + return; + + // The streaming job and this (this texture) have a circular reference count--each one holds one for the other. + // As a result, this means that having the streaming job forget about the texture may cause the texture to go + // away completely! So we need to ensure that after we call "ForgetOwner" that we don't touch any instance + // variables. + CTextureStreamingJob* pJob = m_pStreamingJob; + m_pStreamingJob = NULL; + + pJob->ForgetOwner( this ); + SafeRelease( &pJob ); +} + +void CTexture::OnStreamingJobComplete( ResidencyType_t newResidenceCurrent ) +{ + Assert( m_pStreamingJob ); + + // It's probable that if this assert fires, we should just do nothing in here and return--but I'd + // like to see that happen to be sure. + Assert( newResidenceCurrent == m_residenceTarget ); + + m_residenceCurrent = newResidenceCurrent; + + // Only do lod biasing for stream in. For stream out, just dump to lowest quality right away. + if ( m_residenceCurrent == RESIDENT_FULL ) + { + if ( mat_lodin_time.GetFloat() > 0 ) + { + m_lodBiasCurrent = m_lodBiasInitial = 1.0 * m_nStreamingMips; + m_lodBiasStartTime = Plat_FloatTime(); + } + else + m_lodBiasCurrent = m_lodBiasInitial = 0.0f; + + m_lastLodBiasAdjustFrame = g_FrameNum; + } + + m_lodClamp = 0; + m_nStreamingMips = 0; + + SetFilteringAndClampingMode( true ); + + // The job is complete, Cancel handles cleanup correctly. + CancelStreamingJob(); +} + +void CTexture::SetErrorTexture( bool bIsErrorTexture ) +{ + if ( bIsErrorTexture ) + m_nInternalFlags |= TEXTUREFLAGSINTERNAL_ERROR; + else + m_nInternalFlags &= ( ~TEXTUREFLAGSINTERNAL_ERROR ); +} + + + + +//----------------------------------------------------------------------------- +// Creates named render target texture +//----------------------------------------------------------------------------- +void CTexture::InitRenderTarget( + const char *pRTName, + int w, + int h, + RenderTargetSizeMode_t sizeMode, + ImageFormat fmt, + RenderTargetType_t type, + unsigned int textureFlags, + unsigned int renderTargetFlags ) +{ + if ( pRTName ) + { + SetName( pRTName ); + } + else + { + static int id = 0; + char pName[128]; + Q_snprintf( pName, sizeof( pName ), "__render_target_%d", id ); + ++id; + SetName( pName ); + } + + if ( renderTargetFlags & CREATERENDERTARGETFLAGS_HDR ) + { + if ( HardwareConfig()->GetHDRType() == HDR_TYPE_FLOAT ) + { + // slam the format + fmt = IMAGE_FORMAT_RGBA16161616F; + } + } + + int nFrameCount = 1; + + int nFlags = TEXTUREFLAGS_NOMIP | TEXTUREFLAGS_RENDERTARGET; + nFlags |= textureFlags; + + if ( type == RENDER_TARGET_NO_DEPTH ) + { + nFlags |= TEXTUREFLAGS_NODEPTHBUFFER; + } + else if ( type == RENDER_TARGET_WITH_DEPTH || type == RENDER_TARGET_ONLY_DEPTH || g_pShaderAPI->DoRenderTargetsNeedSeparateDepthBuffer() ) + { + nFlags |= TEXTUREFLAGS_DEPTHRENDERTARGET; + ++nFrameCount; + } + + if ( renderTargetFlags & CREATERENDERTARGETFLAGS_TEMP ) + { + m_nInternalFlags |= TEXTUREFLAGSINTERNAL_TEMPRENDERTARGET; + } + + m_nOriginalRenderTargetType = type; + m_RenderTargetSizeMode = sizeMode; + m_nOriginalRTWidth = w; + m_nOriginalRTHeight = h; + + if ( ImageLoader::ImageFormatInfo(fmt).m_NumAlphaBits > 1 ) + { + nFlags |= TEXTUREFLAGS_EIGHTBITALPHA; + } + else if ( ImageLoader::ImageFormatInfo(fmt).m_NumAlphaBits == 1 ) + { + nFlags |= TEXTUREFLAGS_ONEBITALPHA; + } + + ApplyRenderTargetSizeMode( w, h, fmt ); + + Init( w, h, 1, fmt, nFlags, nFrameCount ); + m_TextureGroupName = TEXTURE_GROUP_RENDER_TARGET; +} + + +void CTexture::OnRestore() +{ + // May have to change whether or not we have a depth buffer. + // Are we a render target? + if ( m_nFlags & TEXTUREFLAGS_RENDERTARGET ) + { + // Did they not ask for a depth buffer? + if ( m_nOriginalRenderTargetType == RENDER_TARGET ) + { + // But, did we force them to have one, or should we force them to have one this time around? + bool bShouldForce = g_pShaderAPI->DoRenderTargetsNeedSeparateDepthBuffer(); + bool bDidForce = ((m_nFlags & TEXTUREFLAGS_DEPTHRENDERTARGET) != 0); + if ( bShouldForce != bDidForce ) + { + int nFlags = m_nFlags; + int iFrameCount = m_nFrameCount; + if ( bShouldForce ) + { + Assert( !( nFlags & TEXTUREFLAGS_DEPTHRENDERTARGET ) ); + iFrameCount = 2; + nFlags |= TEXTUREFLAGS_DEPTHRENDERTARGET; + } + else + { + Assert( ( nFlags & TEXTUREFLAGS_DEPTHRENDERTARGET ) ); + iFrameCount = 1; + nFlags &= ~TEXTUREFLAGS_DEPTHRENDERTARGET; + } + + Shutdown(); + + int newWidth, newHeight; + ApplyRenderTargetSizeMode( newWidth, newHeight, m_ImageFormat ); + + Init( newWidth, newHeight, 1, m_ImageFormat, nFlags, iFrameCount ); + return; + } + } + + // If we didn't recreate it up above, then we may need to resize it anyway if the framebuffer + // got smaller than we are. + int newWidth, newHeight; + ApplyRenderTargetSizeMode( newWidth, newHeight, m_ImageFormat ); + if ( newWidth != m_dimsMapping.m_nWidth || newHeight != m_dimsMapping.m_nHeight ) + { + Shutdown(); + Init( newWidth, newHeight, 1, m_ImageFormat, m_nFlags, m_nFrameCount ); + return; + } + } + else + { + if ( m_nFlags & TEXTUREFLAGS_STREAMABLE_FINE ) + { + MakeResident( RESIDENT_NONE ); + } + } +} + + +//----------------------------------------------------------------------------- +// Creates a procedural texture +//----------------------------------------------------------------------------- +void CTexture::InitProceduralTexture( const char *pTextureName, const char *pTextureGroupName, int w, int h, int d, ImageFormat fmt, int nFlags, ITextureRegenerator* generator ) +{ + // We shouldn't be asking for render targets here + Assert( (nFlags & (TEXTUREFLAGS_RENDERTARGET | TEXTUREFLAGS_DEPTHRENDERTARGET)) == 0 ); + + SetName( pTextureName ); + + // Eliminate flags that are inappropriate... + nFlags &= ~TEXTUREFLAGS_HINT_DXT5 | TEXTUREFLAGS_ONEBITALPHA | TEXTUREFLAGS_EIGHTBITALPHA | + TEXTUREFLAGS_RENDERTARGET | TEXTUREFLAGS_DEPTHRENDERTARGET; + + // Insert required flags + nFlags |= TEXTUREFLAGS_PROCEDURAL; + int nAlphaBits = ImageLoader::ImageFormatInfo(fmt).m_NumAlphaBits; + if (nAlphaBits > 1) + { + nFlags |= TEXTUREFLAGS_EIGHTBITALPHA; + } + else if (nAlphaBits == 1) + { + nFlags |= TEXTUREFLAGS_ONEBITALPHA; + } + + // Procedural textures are always one frame only + Init( w, h, d, fmt, nFlags, 1 ); + + SetTextureRegenerator(generator); + + m_TextureGroupName = pTextureGroupName; +} + + +//----------------------------------------------------------------------------- +// Creates a file texture +//----------------------------------------------------------------------------- +void CTexture::InitFileTexture( const char *pTextureFile, const char *pTextureGroupName ) +{ + // For files, we only really know about the file name + // At any time, the file contents could change, and we could have + // a different size, number of frames, etc. + SetName( pTextureFile ); + m_TextureGroupName = pTextureGroupName; +} + +//----------------------------------------------------------------------------- +// Assigns/releases texture IDs for our animation frames +//----------------------------------------------------------------------------- +void CTexture::AllocateTextureHandles() +{ + Assert( !m_pTextureHandles ); + Assert( m_nFrameCount > 0 ); +#ifdef DBGFLAG_ASSERT + if( m_nFlags & TEXTUREFLAGS_DEPTHRENDERTARGET ) + { + Assert( m_nFrameCount >= 2 ); + } +#endif + + m_pTextureHandles = new ShaderAPITextureHandle_t[m_nFrameCount]; + for( int i = 0; i != m_nFrameCount; ++i ) + m_pTextureHandles[i] = INVALID_SHADERAPI_TEXTURE_HANDLE; +} + +void CTexture::ReleaseTextureHandles() +{ + if ( m_pTextureHandles ) + { + delete[] m_pTextureHandles; + m_pTextureHandles = NULL; + } +} + + +//----------------------------------------------------------------------------- +// Creates the texture +//----------------------------------------------------------------------------- +bool CTexture::AllocateShaderAPITextures() +{ + Assert( !HasBeenAllocated() ); + + TM_ZONE_DEFAULT( TELEMETRY_LEVEL0 ); + + int nCount = m_nFrameCount; + + int nCreateFlags = 0; + if ( ( m_nFlags & TEXTUREFLAGS_ENVMAP ) && HardwareConfig()->SupportsCubeMaps() ) + { + nCreateFlags |= TEXTURE_CREATE_CUBEMAP; + } + + bool bIsFloat = ( m_ImageFormat == IMAGE_FORMAT_RGBA16161616F ) || ( m_ImageFormat == IMAGE_FORMAT_R32F ) || + ( m_ImageFormat == IMAGE_FORMAT_RGB323232F ) || ( m_ImageFormat == IMAGE_FORMAT_RGBA32323232F ); + + // Don't do sRGB on floating point textures + if ( ( m_nFlags & TEXTUREFLAGS_SRGB ) && !bIsFloat ) + { + nCreateFlags |= TEXTURE_CREATE_SRGB; // for Posix/GL only + } + + if ( m_nFlags & TEXTUREFLAGS_RENDERTARGET ) + { + nCreateFlags |= TEXTURE_CREATE_RENDERTARGET; + + // This here is simply so we can use a different call to + // create the depth texture below + if ( ( m_nFlags & TEXTUREFLAGS_DEPTHRENDERTARGET ) && ( nCount == 2 ) ) //nCount must be 2 on pc + { + --nCount; + } + } + else + { + // If it's not a render target, use the texture manager in dx + if ( m_nFlags & TEXTUREFLAGS_STAGING_MEMORY ) + nCreateFlags |= TEXTURE_CREATE_SYSMEM; + else + { +#if defined(IS_WINDOWS_PC) + static ConVarRef mat_dxlevel("mat_dxlevel"); + if ( mat_dxlevel.GetInt() < 90 || mat_managedtextures.GetBool() ) +#endif + { + nCreateFlags |= TEXTURE_CREATE_MANAGED; + } + } + } + + if ( m_nFlags & TEXTUREFLAGS_POINTSAMPLE ) + { + nCreateFlags |= TEXTURE_CREATE_UNFILTERABLE_OK; + } + + if ( m_nFlags & TEXTUREFLAGS_VERTEXTEXTURE ) + { + nCreateFlags |= TEXTURE_CREATE_VERTEXTEXTURE; + } + + int nCopies = 1; + if ( IsProcedural() ) + { + // This is sort of hacky... should we store the # of copies in the VTF? + if ( !( m_nFlags & TEXTUREFLAGS_SINGLECOPY ) ) + { + // FIXME: That 6 there is heuristically what I came up with what I + // need to get eyes not to stall on map alyx3. We need a better way + // of determining how many copies of the texture we should store. + nCopies = 6; + } + } + + // For depth only render target: adjust texture width/height + // Currently we just leave it the same size, will update with further testing + int nShaderApiCreateTextureDepth = ( ( m_nFlags & TEXTUREFLAGS_DEPTHRENDERTARGET ) && ( m_nOriginalRenderTargetType == RENDER_TARGET_ONLY_DEPTH ) ) ? 1 : m_dimsAllocated.m_nDepth; + + // Create all animated texture frames in a single call + g_pShaderAPI->CreateTextures( + m_pTextureHandles, nCount, + m_dimsAllocated.m_nWidth, m_dimsAllocated.m_nHeight, nShaderApiCreateTextureDepth, m_ImageFormat, m_dimsAllocated.m_nMipCount, + nCopies, nCreateFlags, GetName(), GetTextureGroupName() ); + + int accountingCount = nCount; + + // Create the depth render target buffer + if ( m_nFlags & TEXTUREFLAGS_DEPTHRENDERTARGET ) + { + MEM_ALLOC_CREDIT(); + Assert( nCount == 1 ); + + char debugName[128]; + Q_snprintf( debugName, ARRAYSIZE( debugName ), "%s_ZBuffer", GetName() ); + Assert( m_nFrameCount >= 2 ); + m_pTextureHandles[1] = g_pShaderAPI->CreateDepthTexture( + m_ImageFormat, + m_dimsAllocated.m_nWidth, + m_dimsAllocated.m_nHeight, + debugName, + ( m_nOriginalRenderTargetType == RENDER_TARGET_ONLY_DEPTH ) ); + accountingCount += 1; + } + + STAGING_ONLY_EXEC( g_currentTextures.InsertOrReplace( this, TexInfo_t( GetName(), m_dimsAllocated.m_nWidth, m_dimsAllocated.m_nHeight, m_dimsAllocated.m_nDepth, m_dimsAllocated.m_nMipCount, accountingCount, nCopies, m_ImageFormat ) ) ); + + m_nInternalFlags |= TEXTUREFLAGSINTERNAL_ALLOCATED; + + return true; +} + +//----------------------------------------------------------------------------- +// Releases the texture's hardware memory +//----------------------------------------------------------------------------- +void CTexture::FreeShaderAPITextures() +{ + if ( m_pTextureHandles && HasBeenAllocated() ) + { + #ifdef STAGING_ONLY + // If this hits, there's a leak because we're not deallocating enough textures. Yikes! + Assert( g_currentTextures[ g_currentTextures.Find( this ) ].m_nFrameCount == m_nFrameCount ); + // Remove ourselves from the list. + g_currentTextures.Remove( this ); + #endif + + // Release the frames + for ( int i = m_nFrameCount; --i >= 0; ) + { + if ( g_pShaderAPI->IsTexture( m_pTextureHandles[i] ) ) + { +#ifdef WIN32 + Assert( _heapchk() == _HEAPOK ); +#endif + + g_pShaderAPI->DeleteTexture( m_pTextureHandles[i] ); + m_pTextureHandles[i] = INVALID_SHADERAPI_TEXTURE_HANDLE; + } + } + } + m_nInternalFlags &= ~TEXTUREFLAGSINTERNAL_ALLOCATED; + + // Clear texture streaming stuff, too. + if ( ( m_nFlags & TEXTUREFLAGS_STREAMABLE ) != 0 ) + { + m_nFlags &= ~TEXTUREFLAGS_STREAMABLE_FINE; + m_residenceCurrent = m_residenceTarget = RESIDENT_NONE; + m_lodClamp = 0; + m_lodBiasCurrent = m_lodBiasInitial = 0; + m_lodBiasStartTime = 0; + } +} + +void CTexture::MigrateShaderAPITextures() +{ + TM_ZONE_DEFAULT( TELEMETRY_LEVEL0 ); + + const int cBytes = m_nFrameCount * sizeof ( ShaderAPITextureHandle_t ); + + ShaderAPITextureHandle_t *pTextureHandles = ( ShaderAPITextureHandle_t * ) stackalloc( cBytes ); + + Assert( pTextureHandles ); + if ( !pTextureHandles ) + return; + + V_memcpy( pTextureHandles, m_pTextureHandles, cBytes ); + + // Pretend we haven't been allocated yet. + m_nInternalFlags &= ~TEXTUREFLAGSINTERNAL_ALLOCATED; + + AllocateShaderAPITextures(); + + for ( int i = 0; i < m_nFrameCount; ++i ) + { + Assert( g_pShaderAPI->IsTexture( pTextureHandles[ i ] ) == g_pShaderAPI->IsTexture( m_pTextureHandles[ i ] ) ); + if ( !g_pShaderAPI->IsTexture( pTextureHandles[ i ] ) ) + continue; + + g_pShaderAPI->CopyTextureToTexture( pTextureHandles[ i ], m_pTextureHandles[ i ] ); + } + + for ( int i = 0; i < m_nFrameCount; ++i ) + { + if ( !g_pShaderAPI->IsTexture( pTextureHandles[ i ] ) ) + continue; + + g_pShaderAPI->DeleteTexture( pTextureHandles[ i ] ); + } +} + +//----------------------------------------------------------------------------- +// Computes the actual format of the texture +//----------------------------------------------------------------------------- +ImageFormat CTexture::ComputeActualFormat( ImageFormat srcFormat ) +{ + ImageFormat dstFormat; + bool bIsCompressed = ImageLoader::IsCompressed( srcFormat ); + if ( g_config.bCompressedTextures && HardwareConfig()->SupportsCompressedTextures() && bIsCompressed ) + { + // for the runtime compressed formats the srcFormat won't equal the dstFormat, and we need to return srcFormat here + if ( ImageLoader::IsRuntimeCompressed( srcFormat ) ) + { + return srcFormat; + } + + // don't do anything since we are already in a compressed format. + dstFormat = g_pShaderAPI->GetNearestSupportedFormat( srcFormat ); + Assert( dstFormat == srcFormat ); + return dstFormat; + } + + // NOTE: Below this piece of code is only called when compressed textures are + // turned off, or if the source texture is not compressed. + +#ifdef DX_TO_GL_ABSTRACTION + if ( ( srcFormat == IMAGE_FORMAT_UVWQ8888 ) || ( srcFormat == IMAGE_FORMAT_UV88 ) || ( srcFormat == IMAGE_FORMAT_UVLX8888 ) ) + { + // Danger, this is going to blow up on the Mac. You better know what you're + // doing with these exotic formats...which were introduced in 1999 + Assert( 0 ); + } +#endif + + // We use the TEXTUREFLAGS_EIGHTBITALPHA and TEXTUREFLAGS_ONEBITALPHA flags + // to decide how many bits of alpha we need; vtex checks the alpha channel + // for all white, etc. + if( ( srcFormat == IMAGE_FORMAT_UVWQ8888 ) || ( srcFormat == IMAGE_FORMAT_UV88 ) || + ( srcFormat == IMAGE_FORMAT_UVLX8888 ) || ( srcFormat == IMAGE_FORMAT_RGBA16161616 ) || + ( srcFormat == IMAGE_FORMAT_RGBA16161616F ) ) + { +#ifdef DX_TO_GL_ABSTRACTION + dstFormat = g_pShaderAPI->GetNearestSupportedFormat( srcFormat, false ); // Stupid HACK! +#else + dstFormat = g_pShaderAPI->GetNearestSupportedFormat( srcFormat, true ); // Stupid HACK! +#endif + } + else if ( m_nFlags & ( TEXTUREFLAGS_EIGHTBITALPHA | TEXTUREFLAGS_ONEBITALPHA ) ) + { + dstFormat = g_pShaderAPI->GetNearestSupportedFormat( IMAGE_FORMAT_BGRA8888 ); + } + else if ( srcFormat == IMAGE_FORMAT_I8 ) + { + dstFormat = g_pShaderAPI->GetNearestSupportedFormat( IMAGE_FORMAT_I8 ); + } + else + { + dstFormat = g_pShaderAPI->GetNearestSupportedFormat( IMAGE_FORMAT_BGR888 ); + } + return dstFormat; +} + +//----------------------------------------------------------------------------- +// Calculates info about whether we can make the texture smaller and by how much +//----------------------------------------------------------------------------- +int CTexture::ComputeActualSize( bool bIgnorePicmip, IVTFTexture *pVTFTexture, bool bTextureMigration ) +{ + unsigned int stripFlags = 0; + return ComputeMipSkipCount( GetName(), m_dimsMapping, bIgnorePicmip, pVTFTexture, m_nFlags, m_nDesiredDimensionLimit, &m_nStreamingMips, &m_cachedFileLodSettings, &m_dimsActual, &m_dimsAllocated, &stripFlags ); + Assert( stripFlags == 0 ); // Not necessarily illegal, just needs investigating. +} + + +//----------------------------------------------------------------------------- +// Used to modify the texture bits (procedural textures only) +//----------------------------------------------------------------------------- +void CTexture::SetTextureRegenerator( ITextureRegenerator *pTextureRegen ) +{ + // NOTE: These can only be used by procedural textures + Assert( IsProcedural() ); + + if (m_pTextureRegenerator) + { + m_pTextureRegenerator->Release(); + } + m_pTextureRegenerator = pTextureRegen; +} + + +//----------------------------------------------------------------------------- +// Gets us modifying a particular frame of our texture +//----------------------------------------------------------------------------- +void CTexture::Modify( int iFrame ) +{ + Assert( iFrame >= 0 && iFrame < m_nFrameCount ); + Assert( HasBeenAllocated() ); + g_pShaderAPI->ModifyTexture( m_pTextureHandles[iFrame] ); +} + + +//----------------------------------------------------------------------------- +// Sets the texture clamping state on the currently modified frame +//----------------------------------------------------------------------------- +void CTexture::SetWrapState( ) +{ + // Border clamp applies to all texture coordinates + if ( m_nFlags & TEXTUREFLAGS_BORDER ) + { + g_pShaderAPI->TexWrap( SHADER_TEXCOORD_S, SHADER_TEXWRAPMODE_BORDER ); + g_pShaderAPI->TexWrap( SHADER_TEXCOORD_T, SHADER_TEXWRAPMODE_BORDER ); + g_pShaderAPI->TexWrap( SHADER_TEXCOORD_U, SHADER_TEXWRAPMODE_BORDER ); + return; + } + + // Clamp mode in S + if ( m_nFlags & TEXTUREFLAGS_CLAMPS ) + { + g_pShaderAPI->TexWrap( SHADER_TEXCOORD_S, SHADER_TEXWRAPMODE_CLAMP ); + } + else + { + g_pShaderAPI->TexWrap( SHADER_TEXCOORD_S, SHADER_TEXWRAPMODE_REPEAT ); + } + + // Clamp mode in T + if ( m_nFlags & TEXTUREFLAGS_CLAMPT ) + { + g_pShaderAPI->TexWrap( SHADER_TEXCOORD_T, SHADER_TEXWRAPMODE_CLAMP ); + } + else + { + g_pShaderAPI->TexWrap( SHADER_TEXCOORD_T, SHADER_TEXWRAPMODE_REPEAT ); + } + + // Clamp mode in U + if ( m_nFlags & TEXTUREFLAGS_CLAMPU ) + { + g_pShaderAPI->TexWrap( SHADER_TEXCOORD_U, SHADER_TEXWRAPMODE_CLAMP ); + } + else + { + g_pShaderAPI->TexWrap( SHADER_TEXCOORD_U, SHADER_TEXWRAPMODE_REPEAT ); + } +} + + +//----------------------------------------------------------------------------- +// Sets the texture filtering state on the currently modified frame +//----------------------------------------------------------------------------- +void CTexture::SetFilterState() +{ + // Turns off filtering when we're point sampling + if( m_nFlags & TEXTUREFLAGS_POINTSAMPLE ) + { + g_pShaderAPI->TexMinFilter( SHADER_TEXFILTERMODE_NEAREST ); + g_pShaderAPI->TexMagFilter( SHADER_TEXFILTERMODE_NEAREST ); + return; + } + + // NOTE: config.bMipMapTextures and config.bFilterTextures is handled in ShaderAPIDX8 + bool bEnableMipmapping = ( m_nFlags & TEXTUREFLAGS_NOMIP ) ? false : true; + if( !bEnableMipmapping ) + { + g_pShaderAPI->TexMinFilter( SHADER_TEXFILTERMODE_LINEAR ); + g_pShaderAPI->TexMagFilter( SHADER_TEXFILTERMODE_LINEAR ); + return; + } + + // Determing the filtering mode + bool bIsAnisotropic = false, bIsTrilinear = false; + if ( HardwareConfig()->GetDXSupportLevel() >= 80 && (g_config.m_nForceAnisotropicLevel > 1) && + (HardwareConfig()->MaximumAnisotropicLevel() > 1) ) + { + bIsAnisotropic = true; + } + else if ( g_config.ForceTrilinear() ) + { + bIsAnisotropic = (( m_nFlags & TEXTUREFLAGS_ANISOTROPIC ) != 0) && (HardwareConfig()->MaximumAnisotropicLevel() > 1); + bIsTrilinear = true; + } + else + { + bIsAnisotropic = (( m_nFlags & TEXTUREFLAGS_ANISOTROPIC ) != 0) && (HardwareConfig()->MaximumAnisotropicLevel() > 1); + bIsTrilinear = ( m_nFlags & TEXTUREFLAGS_TRILINEAR ) != 0; + } + + if ( bIsAnisotropic ) + { + g_pShaderAPI->TexMinFilter( SHADER_TEXFILTERMODE_ANISOTROPIC ); + g_pShaderAPI->TexMagFilter( SHADER_TEXFILTERMODE_ANISOTROPIC ); + } + else + { + // force trilinear if we are on a dx8 card or above + if ( bIsTrilinear ) + { + g_pShaderAPI->TexMinFilter( SHADER_TEXFILTERMODE_LINEAR_MIPMAP_LINEAR ); + g_pShaderAPI->TexMagFilter( SHADER_TEXFILTERMODE_LINEAR ); + } + else + { + g_pShaderAPI->TexMinFilter( SHADER_TEXFILTERMODE_LINEAR_MIPMAP_NEAREST ); + g_pShaderAPI->TexMagFilter( SHADER_TEXFILTERMODE_LINEAR ); + } + } + + SetLodState(); +} + +//----------------------------------------------------------------------------- +// Sets the lod state on the currently modified frame +//----------------------------------------------------------------------------- +void CTexture::SetLodState() +{ + // Set the lod clamping value to ensure we don't see anything we're not supposed to. + g_pShaderAPI->TexLodClamp( m_lodClamp ); + g_pShaderAPI->TexLodBias( m_lodBiasCurrent ); +} + +//----------------------------------------------------------------------------- +// Download bits main entry point!! +//----------------------------------------------------------------------------- +void CTexture::DownloadTexture( Rect_t *pRect, bool bCopyFromCurrent ) +{ + // No downloading necessary if there's no graphics + if ( !g_pShaderDevice->IsUsingGraphics() ) + return; + + // We don't know the actual size of the texture at this stage... + if ( !pRect ) + { + ReconstructTexture( bCopyFromCurrent ); + } + else + { + // Not implemented yet. + Assert( bCopyFromCurrent == false ); + ReconstructPartialTexture( pRect ); + } + + // Iterate over all the frames and set the appropriate wrapping + filtering state + SetFilteringAndClampingMode(); + + // texture bits have been updated, update the exclusion state + if ( m_nInternalFlags & TEXTUREFLAGSINTERNAL_SHOULDEXCLUDE ) + { + m_nInternalFlags |= TEXTUREFLAGSINTERNAL_EXCLUDED; + } + else + { + m_nInternalFlags &= ~TEXTUREFLAGSINTERNAL_EXCLUDED; + } + + // texture bits have been picmipped, update the picmip state + m_nActualDimensionLimit = m_nDesiredDimensionLimit; +} + +void CTexture::Download( Rect_t *pRect, int nAdditionalCreationFlags /* = 0 */ ) +{ + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s", __FUNCTION__ ); + + // Only download the bits if we can... + if ( g_pShaderAPI->CanDownloadTextures() ) + { + MaterialLock_t hLock = MaterialSystem()->Lock(); + m_nFlags |= nAdditionalCreationFlags; // Path to let stdshaders drive settings like sRGB-ness at creation time + DownloadTexture( pRect ); + MaterialSystem()->Unlock( hLock ); + } +} + +// Save texture to a file. +bool CTexture::SaveToFile( const char *fileName ) +{ + bool bRet = false; + ITexture *pTexture = materials->FindTexture( "_rt_FullFrameFB1", TEXTURE_GROUP_RENDER_TARGET ); + + if ( !pTexture ) + return bRet; + + const int width = GetActualWidth(); + const int height = GetActualHeight(); + + if ( pTexture->GetImageFormat() == IMAGE_FORMAT_RGBA8888 || + pTexture->GetImageFormat() == IMAGE_FORMAT_ABGR8888 || + pTexture->GetImageFormat() == IMAGE_FORMAT_ARGB8888 || + pTexture->GetImageFormat() == IMAGE_FORMAT_BGRA8888 || + pTexture->GetImageFormat() == IMAGE_FORMAT_BGRX8888 ) + { + bool bCleanupTexture = false; + + // Need to allocate a temporarily renderable surface. Sadness. + if ( width > pTexture->GetActualWidth() || height > pTexture->GetActualHeight() ) + { + materials->OverrideRenderTargetAllocation( true ); + // This one bumps the ref automatically for us. + pTexture = materials->CreateNamedRenderTargetTextureEx( "_rt_savetofile", width, height, RT_SIZE_LITERAL, IMAGE_FORMAT_BGRA8888, MATERIAL_RT_DEPTH_NONE, TEXTUREFLAGS_IMMEDIATE_CLEANUP ); + materials->OverrideRenderTargetAllocation( false ); + + if ( !pTexture || pTexture->IsError() ) + { + SafeRelease( &pTexture ); + Msg( "SaveToFile: texture '_rt_FullFrameFB1' failed. Ptr:%p Format:%d\n", pTexture, ( pTexture ? pTexture->GetImageFormat() : 0 ) ); + return false; + } + + bCleanupTexture = true; + } + + Rect_t SrcRect = { 0, 0, width, height }; + Rect_t DstRect = SrcRect; + + if ( ( width > 0 ) && ( height > 0 ) ) + { + void *pixelValue = malloc( width * height * 2 * sizeof( BGRA8888_t ) ); + + if( pixelValue ) + { + CMatRenderContextPtr pRenderContext( MaterialSystem() ); + + // Set the clear color to opaque black + pRenderContext->ClearColor4ub( 0, 0, 0, 0xFF ); + pRenderContext->ClearBuffers( true, true, true ); + pRenderContext->PushRenderTargetAndViewport( pTexture, 0, 0, width, height ); + pRenderContext->CopyTextureToRenderTargetEx( 0, this, &SrcRect, &DstRect ); + + pRenderContext->ReadPixels( 0, 0, width, height, ( unsigned char * )pixelValue, pTexture->GetImageFormat() ); + + // Slap the alpha channel at the bottom of the tga file so we don't have to deal with crappy tools that can't + // handle rgb + alpha well. This means we can just do a "mat_texture_save_fonts" concommand, and then use + // something like Beyond Compare to look at the fonts differences between various platforms, etc. + CPixelWriter pixelWriterSrc; + CPixelWriter pixelWriterDst; + pixelWriterSrc.SetPixelMemory( pTexture->GetImageFormat(), pixelValue, width * sizeof( BGRA8888_t ) ); + pixelWriterDst.SetPixelMemory( pTexture->GetImageFormat(), pixelValue, width * sizeof( BGRA8888_t ) ); + + for (int y = 0; y < height; ++y) + { + pixelWriterSrc.Seek( 0, y ); + pixelWriterDst.Seek( 0, y + height ); + + for (int x = 0; x < width; ++x) + { + int r, g, b, a; + + pixelWriterSrc.ReadPixelNoAdvance( r, g, b, a ); + pixelWriterSrc.WritePixel( a, a, a, 255 ); + pixelWriterDst.WritePixel( r, g, b, 255 ); + } + } + + if ( TGAWriter::WriteTGAFile( fileName, width, height * 2, pTexture->GetImageFormat(), ( uint8 * )pixelValue, width * sizeof( BGRA8888_t ) ) ) + { + bRet = true; + } + + // restore our previous state + pRenderContext->PopRenderTargetAndViewport(); + + free( pixelValue ); + } + } + + if ( bCleanupTexture ) + SafeRelease( &pTexture ); + } + else + { + Msg( "SaveToFile: texture '_rt_FullFrameFB1' failed. Ptr:%p Format:%d\n", pTexture, ( pTexture ? pTexture->GetImageFormat() : 0 ) ); + } + + return bRet; +} + +bool CTexture::AsyncReadTextureFromFile( IVTFTexture* pVTFTexture, unsigned int nAdditionalCreationFlags ) +{ + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s", __FUNCTION__ ); + + m_bStreamingFileReadFailed = false; // Optimism! + + char pCacheFileName[ MATERIAL_MAX_PATH ]; + FileHandle_t fileHandle = FILESYSTEM_INVALID_HANDLE; + + GetCacheFilename( pCacheFileName, MATERIAL_MAX_PATH ); + if ( !GetFileHandle( &fileHandle, pCacheFileName, NULL ) ) + { + m_bStreamingFileReadFailed = true; + return false; + } + + if ( V_strstr( GetName(), "c_sniperrifle_scope" ) ) + { + int i = 0; + i = 3; + } + + + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s - %s", __FUNCTION__, tmDynamicString( TELEMETRY_LEVEL0, pCacheFileName ) ); + + // OSX hackery + int nPreserveFlags = nAdditionalCreationFlags; + if ( m_nFlags & TEXTUREFLAGS_SRGB ) + nPreserveFlags |= TEXTUREFLAGS_SRGB; + + uint16 dontCareStreamedMips = m_nStreamingMips; + TextureLODControlSettings_t settings = m_cachedFileLodSettings; + + if ( !SLoadTextureBitsFromFile( &pVTFTexture, fileHandle, m_nFlags | nPreserveFlags, &settings, m_nDesiredDimensionLimit, &dontCareStreamedMips, GetName(), pCacheFileName, &m_dimsMapping ) ) + { + g_pFullFileSystem->Close( fileHandle ); + m_bStreamingFileReadFailed = true; + return false; + } + + g_pFullFileSystem->Close( fileHandle ); + + m_pStreamingVTF = pVTFTexture; + + return true; +} + +void CTexture::AsyncCancelReadTexture( ) +{ + Assert( m_bStreamingFileReadFailed || m_pStreamingVTF != NULL ); + if ( m_pStreamingVTF ) + { + TextureManager()->ReleaseAsyncScratchVTF( m_pStreamingVTF ); + m_pStreamingVTF = NULL; + } +} + +void CTexture::Bind( Sampler_t sampler ) +{ + Bind( sampler, 0 ); +} + +//----------------------------------------------------------------------------- +// Binds a particular texture (possibly paired) +//----------------------------------------------------------------------------- +void CTexture::Bind( Sampler_t sampler1, int nFrame, Sampler_t sampler2 /* = -1 */ ) +{ + if ( g_pShaderDevice->IsUsingGraphics() ) + { + TextureManager()->RequestAllMipmaps( this ); + + if ( nFrame < 0 || nFrame >= m_nFrameCount ) + { + // FIXME: Use the well-known 'error' id instead of frame 0 + nFrame = 0; + // Assert(0); + } + + // Make sure we've actually allocated the texture handle + if ( HasBeenAllocated() ) + { + g_pShaderAPI->BindTexture( sampler1, m_pTextureHandles[nFrame] ); + } + else + { + ExecuteNTimes( 20, Warning( "Trying to bind texture %s, but texture handles are not valid. Binding a white texture!\n", GetName() ) ); + g_pShaderAPI->BindStandardTexture( sampler1, TEXTURE_WHITE ); + } + } +} + + + +void CTexture::BindVertexTexture( VertexTextureSampler_t sampler, int nFrame ) +{ + if ( g_pShaderDevice->IsUsingGraphics() ) + { + if ( nFrame < 0 || nFrame >= m_nFrameCount ) + { + // FIXME: Use the well-known 'error' id instead of frame 0 + nFrame = 0; + // Assert(0); + } + + // Make sure we've actually allocated the texture + Assert( HasBeenAllocated() ); + + g_pShaderAPI->BindVertexTexture( sampler, m_pTextureHandles[nFrame] ); + } +} + + +//----------------------------------------------------------------------------- +// Set this texture as a render target +//----------------------------------------------------------------------------- +bool CTexture::SetRenderTarget( int nRenderTargetID ) +{ + return SetRenderTarget( nRenderTargetID, NULL ); +} + +//----------------------------------------------------------------------------- +// Set this texture as a render target +// Optionally bind pDepthTexture as depth buffer +//----------------------------------------------------------------------------- +bool CTexture::SetRenderTarget( int nRenderTargetID, ITexture *pDepthTexture ) +{ + if ( ( m_nFlags & TEXTUREFLAGS_RENDERTARGET ) == 0 ) + return false; + + // Make sure we've actually allocated the texture handles + Assert( HasBeenAllocated() ); + + ShaderAPITextureHandle_t textureHandle = m_pTextureHandles[0]; + + ShaderAPITextureHandle_t depthTextureHandle = (unsigned int)SHADER_RENDERTARGET_DEPTHBUFFER; + + if ( m_nFlags & TEXTUREFLAGS_DEPTHRENDERTARGET ) + { + Assert( m_nFrameCount >= 2 ); + depthTextureHandle = m_pTextureHandles[1]; + } + else if ( m_nFlags & TEXTUREFLAGS_NODEPTHBUFFER ) + { + // GR - render target without depth buffer + depthTextureHandle = (unsigned int)SHADER_RENDERTARGET_NONE; + } + + if ( pDepthTexture) + { + depthTextureHandle = static_cast(pDepthTexture)->GetTextureHandle(0); + } + + g_pShaderAPI->SetRenderTargetEx( nRenderTargetID, textureHandle, depthTextureHandle ); + return true; +} + + +//----------------------------------------------------------------------------- +// Reference counting +//----------------------------------------------------------------------------- +void CTexture::IncrementReferenceCount( void ) +{ + ++m_nRefCount; +} + +void CTexture::DecrementReferenceCount( void ) +{ + if ( ( --m_nRefCount <= 0 ) && ( m_nFlags & TEXTUREFLAGS_IMMEDIATE_CLEANUP ) != 0 ) + { + Assert( m_nRefCount == 0 ); + // Just inform the texture manager, it will decide to free us at a later date. + TextureManager()->MarkUnreferencedTextureForCleanup( this ); + } +} + +int CTexture::GetReferenceCount( ) +{ + return m_nRefCount; +} + + +//----------------------------------------------------------------------------- +// Various accessor methods +//----------------------------------------------------------------------------- +const char* CTexture::GetName( ) const +{ + return m_Name.String(); +} + +const char* CTexture::GetTextureGroupName( ) const +{ + return m_TextureGroupName.String(); +} + +void CTexture::SetName( const char* pName ) +{ + // normalize and convert to a symbol + char szCleanName[MAX_PATH]; + m_Name = NormalizeTextureName( pName, szCleanName, sizeof( szCleanName ) ); + +#ifdef _DEBUG + if ( m_pDebugName ) + { + delete [] m_pDebugName; + } + int nLen = V_strlen( szCleanName ) + 1; + m_pDebugName = new char[nLen]; + V_memcpy( m_pDebugName, szCleanName, nLen ); +#endif +} + +ImageFormat CTexture::GetImageFormat() const +{ + return m_ImageFormat; +} + +int CTexture::GetMappingWidth() const +{ + return m_dimsMapping.m_nWidth; +} + +int CTexture::GetMappingHeight() const +{ + return m_dimsMapping.m_nHeight; +} + +int CTexture::GetMappingDepth() const +{ + return m_dimsMapping.m_nDepth; +} + +int CTexture::GetActualWidth() const +{ + return m_dimsActual.m_nWidth; +} + +int CTexture::GetActualHeight() const +{ + return m_dimsActual.m_nHeight; +} + +int CTexture::GetActualDepth() const +{ + return m_dimsActual.m_nDepth; +} + +int CTexture::GetNumAnimationFrames() const +{ + return m_nFrameCount; +} + +void CTexture::GetReflectivity( Vector& reflectivity ) +{ + Precache(); + VectorCopy( m_vecReflectivity, reflectivity ); +} + +//----------------------------------------------------------------------------- +// Little helper polling methods +//----------------------------------------------------------------------------- +bool CTexture::IsTranslucent() const +{ + return ( m_nFlags & (TEXTUREFLAGS_ONEBITALPHA | TEXTUREFLAGS_EIGHTBITALPHA) ) != 0; +} + +bool CTexture::IsNormalMap( void ) const +{ + return ( ( m_nFlags & TEXTUREFLAGS_NORMAL ) != 0 ); +} + +bool CTexture::IsCubeMap( void ) const +{ + return ( ( m_nFlags & TEXTUREFLAGS_ENVMAP ) != 0 ); +} + +bool CTexture::IsRenderTarget( void ) const +{ + return ( ( m_nFlags & TEXTUREFLAGS_RENDERTARGET ) != 0 ); +} + +bool CTexture::IsTempRenderTarget( void ) const +{ + return ( ( m_nInternalFlags & TEXTUREFLAGSINTERNAL_TEMPRENDERTARGET ) != 0 ); +} + +bool CTexture::IsProcedural() const +{ + return ( (m_nFlags & TEXTUREFLAGS_PROCEDURAL) != 0 ); +} + +bool CTexture::IsMipmapped() const +{ + return ( (m_nFlags & TEXTUREFLAGS_NOMIP) == 0 ); +} + +unsigned int CTexture::GetFlags() const +{ + return m_nFlags; +} + +void CTexture::ForceLODOverride( int iNumLodsOverrideUpOrDown ) +{ + TextureLodOverride::OverrideInfo oi( iNumLodsOverrideUpOrDown, iNumLodsOverrideUpOrDown ); + TextureLodOverride::Add( GetName(), oi ); + Download( NULL ); +} + + +bool CTexture::IsError() const +{ + return ( (m_nInternalFlags & TEXTUREFLAGSINTERNAL_ERROR) != 0 ); +} + +bool CTexture::HasBeenAllocated() const +{ + return ( (m_nInternalFlags & TEXTUREFLAGSINTERNAL_ALLOCATED) != 0 ); +} + +bool CTexture::IsVolumeTexture() const +{ + return (m_dimsMapping.m_nDepth > 1); +} + +//----------------------------------------------------------------------------- +// Sets the filtering + clamping modes on the texture +//----------------------------------------------------------------------------- +void CTexture::SetFilteringAndClampingMode( bool bOnlyLodValues ) +{ + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s", __FUNCTION__ ); + + if( !HasBeenAllocated() ) + return; + + for ( int iFrame = 0; iFrame < m_nFrameCount; ++iFrame ) + { + Modify( iFrame ); // Indicate we're changing state with respect to a particular frame + if ( !bOnlyLodValues ) + { + SetWrapState(); // Send the appropriate wrap/clamping modes to the shaderapi. + SetFilterState(); // Set the filtering mode for the texture after downloading it. + // NOTE: Apparently, the filter state cannot be set until after download + } + else + SetLodState(); + } +} + +//----------------------------------------------------------------------------- +// Loads up the non-fallback information about the texture +//----------------------------------------------------------------------------- +void CTexture::Precache() +{ + // We only have to do something in the case of a file texture + if ( IsRenderTarget() || IsProcedural() ) + return; + + if ( HasBeenAllocated() ) + return; + + // Blow off env_cubemap too... + if ( !Q_strnicmp( m_Name.String(), "env_cubemap", 12 )) + return; + + int nAdditionalFlags = 0; + if ( ( m_nFlags & TEXTUREFLAGS_STREAMABLE ) != 0 ) + { + // If we were previously streamed in, make sure we still do this time around. + nAdditionalFlags = TEXTUREFLAGS_STREAMABLE_COARSE; + Assert( ( m_nFlags & TEXTUREFLAGS_STREAMABLE_FINE ) == 0 ); + Assert( m_residenceCurrent == RESIDENT_NONE && m_residenceTarget == RESIDENT_NONE ); + Assert( m_lodClamp == 0 ); + Assert( m_lodBiasCurrent == 0 && m_lodBiasInitial == 0 ); + Assert( m_lodBiasStartTime == 0 ); + } + + ScratchVTF scratch( this ); + IVTFTexture *pVTFTexture = scratch.Get(); + + // The texture name doubles as the relative file name + // It's assumed to have already been set by this point + // Compute the cache name + char pCacheFileName[MATERIAL_MAX_PATH]; + Q_snprintf( pCacheFileName, sizeof( pCacheFileName ), "materials/%s" TEXTURE_FNAME_EXTENSION, m_Name.String() ); + + int nHeaderSize = VTFFileHeaderSize( VTF_MAJOR_VERSION ); + unsigned char *pMem = (unsigned char *)stackalloc( nHeaderSize ); + CUtlBuffer buf( pMem, nHeaderSize ); + if ( !g_pFullFileSystem->ReadFile( pCacheFileName, NULL, buf, nHeaderSize ) ) + { + goto precacheFailed; + } + + if ( !pVTFTexture->Unserialize( buf, true ) ) + { + Warning( "Error reading material \"%s\"\n", pCacheFileName ); + goto precacheFailed; + } + + // NOTE: Don't set the image format in case graphics are active + VectorCopy( pVTFTexture->Reflectivity(), m_vecReflectivity ); + m_dimsMapping.m_nWidth = pVTFTexture->Width(); + m_dimsMapping.m_nHeight = pVTFTexture->Height(); + m_dimsMapping.m_nDepth = pVTFTexture->Depth(); + m_nFlags = pVTFTexture->Flags() | nAdditionalFlags; + m_nFrameCount = pVTFTexture->FrameCount(); + if ( !m_pTextureHandles ) + { + // NOTE: m_nFrameCount and m_pTextureHandles are strongly associated + // whenever one is modified the other must also be modified + AllocateTextureHandles(); + } + + return; + +precacheFailed: + m_vecReflectivity.Init( 0, 0, 0 ); + m_dimsMapping.m_nWidth = 32; + m_dimsMapping.m_nHeight = 32; + m_dimsMapping.m_nDepth = 1; + m_nFlags = TEXTUREFLAGS_NOMIP; + SetErrorTexture( true ); + m_nFrameCount = 1; + if ( !m_pTextureHandles ) + { + // NOTE: m_nFrameCount and m_pTextureHandles are strongly associated + // whenever one is modified the other must also be modified + AllocateTextureHandles(); + } +} + + + +//----------------------------------------------------------------------------- +// Loads the low-res image from the texture +//----------------------------------------------------------------------------- +void CTexture::LoadLowResTexture( IVTFTexture *pTexture ) +{ + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s", __FUNCTION__ ); + + delete [] m_pLowResImage; + m_pLowResImage = NULL; + + if ( pTexture->LowResWidth() == 0 || pTexture->LowResHeight() == 0 ) + { + m_LowResImageWidth = m_LowResImageHeight = 0; + return; + } + + m_LowResImageWidth = pTexture->LowResWidth(); + m_LowResImageHeight = pTexture->LowResHeight(); + + m_pLowResImage = new unsigned char[m_LowResImageWidth * m_LowResImageHeight * 3]; +#ifdef DBGFLAG_ASSERT + bool retVal = +#endif + ImageLoader::ConvertImageFormat( pTexture->LowResImageData(), pTexture->LowResFormat(), + m_pLowResImage, IMAGE_FORMAT_RGB888, m_LowResImageWidth, m_LowResImageHeight ); + Assert( retVal ); +} + +void *CTexture::GetResourceData( uint32 eDataType, size_t *pnumBytes ) const +{ + for ( DataChunk const *pDataChunk = m_arrDataChunks.Base(), + *pDataChunkEnd = pDataChunk + m_arrDataChunks.Count(); + pDataChunk < pDataChunkEnd; ++pDataChunk ) + { + if ( ( pDataChunk->m_eType & ~RSRCF_MASK ) == eDataType ) + { + if ( ( pDataChunk->m_eType & RSRCF_HAS_NO_DATA_CHUNK ) == 0 ) + { + if ( pnumBytes) + *pnumBytes = pDataChunk->m_numBytes; + return pDataChunk->m_pvData; + } + else + { + if ( pnumBytes ) + *pnumBytes = sizeof( pDataChunk->m_numBytes ); + + return ( void *)( &pDataChunk->m_numBytes ); + } + } + } + if ( pnumBytes ) + pnumBytes = 0; + return NULL; +} + +#pragma pack(1) + +struct DXTColBlock +{ + unsigned short col0; + unsigned short col1; + + // no bit fields - use bytes + unsigned char row[4]; +}; + +struct DXTAlphaBlock3BitLinear +{ + unsigned char alpha0; + unsigned char alpha1; + + unsigned char stuff[6]; +}; + +#pragma pack() + +static void FillCompressedTextureWithSingleColor( int red, int green, int blue, int alpha, unsigned char *pImageData, + int width, int height, int depth, ImageFormat imageFormat ) +{ + Assert( ( width < 4 ) || !( width % 4 ) ); + Assert( ( height < 4 ) || !( height % 4 ) ); + Assert( ( depth < 4 ) || !( depth % 4 ) ); + + if ( width < 4 && width > 0 ) + { + width = 4; + } + if ( height < 4 && height > 0 ) + { + height = 4; + } + if ( depth < 4 && depth > 1 ) + { + depth = 4; + } + int numBlocks = ( width * height ) >> 4; + numBlocks *= depth; + + DXTColBlock colorBlock; + memset( &colorBlock, 0, sizeof( colorBlock ) ); + ( ( BGR565_t * )&( colorBlock.col0 ) )->Set( red, green, blue ); + ( ( BGR565_t * )&( colorBlock.col1 ) )->Set( red, green, blue ); + + switch( imageFormat ) + { + case IMAGE_FORMAT_DXT1: + case IMAGE_FORMAT_ATI1N: // Invalid block data, but correct memory footprint + { + int i; + for( i = 0; i < numBlocks; i++ ) + { + memcpy( pImageData + i * 8, &colorBlock, sizeof( colorBlock ) ); + } + } + break; + case IMAGE_FORMAT_DXT5: + case IMAGE_FORMAT_ATI2N: + { + int i; + for( i = 0; i < numBlocks; i++ ) + { +// memset( pImageData + i * 16, 0, 16 ); + memcpy( pImageData + i * 16 + 8, &colorBlock, sizeof( colorBlock ) ); +// memset( pImageData + i * 16 + 8, 0xffff, 8 ); // alpha block + } + } + break; + default: + Assert( 0 ); + break; + } +} + +// This table starts out like the programmatic logic that used to be here, +// but then has some other colors, so that we don't see repeats. +// Also, there is no black, which seems to be an error condition on OpenGL. +// There also aren't any zeros in this table, since these colors may get +// multiplied with, say, vertex colors which are tinted, resulting in black pixels. +int sg_nMipLevelColors[14][3] = { { 64, 255, 64 }, // Green + { 255, 64, 64 }, // Red + { 255, 255, 64 }, // Yellow + { 64, 64, 255 }, // Blue + { 64, 255, 255 }, // Cyan + { 255, 64, 255 }, // Magenta + { 255, 255, 255 }, // White + { 255, 150, 150 }, // Light Red + { 255, 255, 150 }, // Light Yellow + { 150, 150, 255 }, // Light Blue + { 150, 255, 255 }, // Light Cyan + { 255, 150, 255 }, // Light Magenta + { 150, 150, 128 }, // Light Gray + { 138, 131, 64 } };// Brown + +//----------------------------------------------------------------------------- +// Generate a texture that shows the various mip levels +//----------------------------------------------------------------------------- +void CTexture::GenerateShowMipLevelsTextures( IVTFTexture *pTexture ) +{ + if( pTexture->FaceCount() > 1 ) + return; + + switch( pTexture->Format() ) + { + // These are formats that we don't bother with for generating mip level textures. + case IMAGE_FORMAT_RGBA16161616F: + case IMAGE_FORMAT_R32F: + case IMAGE_FORMAT_RGB323232F: + case IMAGE_FORMAT_RGBA32323232F: + case IMAGE_FORMAT_UV88: + break; + default: + for (int iFrame = 0; iFrame < pTexture->FrameCount(); ++iFrame ) + { + for (int iFace = 0; iFace < pTexture->FaceCount(); ++iFace ) + { + for (int iMip = 0; iMip < pTexture->MipCount(); ++iMip ) + { + int red = sg_nMipLevelColors[iMip][0];//( ( iMip + 1 ) & 2 ) ? 255 : 0; + int green = sg_nMipLevelColors[iMip][1];//( ( iMip + 1 ) & 1 ) ? 255 : 0; + int blue = sg_nMipLevelColors[iMip][2];//( ( iMip + 1 ) & 4 ) ? 255 : 0; + + int nWidth, nHeight, nDepth; + pTexture->ComputeMipLevelDimensions( iMip, &nWidth, &nHeight, &nDepth ); + if( pTexture->Format() == IMAGE_FORMAT_DXT1 || pTexture->Format() == IMAGE_FORMAT_DXT5 || + pTexture->Format() == IMAGE_FORMAT_ATI1N || pTexture->Format() == IMAGE_FORMAT_ATI2N ) + { + unsigned char *pImageData = pTexture->ImageData( iFrame, iFace, iMip, 0, 0, 0 ); + int alpha = 255; + FillCompressedTextureWithSingleColor( red, green, blue, alpha, pImageData, nWidth, nHeight, nDepth, pTexture->Format() ); + } + else + { + for ( int z = 0; z < nDepth; ++z ) + { + CPixelWriter pixelWriter; + pixelWriter.SetPixelMemory( pTexture->Format(), + pTexture->ImageData( iFrame, iFace, iMip, 0, 0, z ), pTexture->RowSizeInBytes( iMip ) ); + + for (int y = 0; y < nHeight; ++y) + { + pixelWriter.Seek( 0, y ); + for (int x = 0; x < nWidth; ++x) + { + pixelWriter.WritePixel( red, green, blue, 255 ); + } + } + } + } + } + } + } + break; + } +} + + +//----------------------------------------------------------------------------- +// Generate a texture that shows the various mip levels +//----------------------------------------------------------------------------- +void CTexture::CopyLowResImageToTexture( IVTFTexture *pTexture ) +{ + int nFlags = pTexture->Flags(); + nFlags |= TEXTUREFLAGS_NOMIP | TEXTUREFLAGS_POINTSAMPLE; + nFlags &= ~(TEXTUREFLAGS_TRILINEAR | TEXTUREFLAGS_ANISOTROPIC | TEXTUREFLAGS_HINT_DXT5); + nFlags &= ~(TEXTUREFLAGS_NORMAL | TEXTUREFLAGS_ENVMAP); + nFlags &= ~(TEXTUREFLAGS_ONEBITALPHA | TEXTUREFLAGS_EIGHTBITALPHA); + + Assert( pTexture->FrameCount() == 1 ); + + Init( pTexture->Width(), pTexture->Height(), 1, IMAGE_FORMAT_BGR888, nFlags, 1 ); + pTexture->Init( m_LowResImageWidth, m_LowResImageHeight, 1, IMAGE_FORMAT_BGR888, nFlags, 1 ); + + // Don't bother computing the actual size; it's actually equal to the low-res size + // With only one mip level + m_dimsActual.m_nWidth = m_LowResImageWidth; + m_dimsActual.m_nHeight = m_LowResImageHeight; + m_dimsActual.m_nDepth = 1; + m_dimsActual.m_nMipCount = 1; + + // Copy the row-res image into the VTF Texture + CPixelWriter pixelWriter; + pixelWriter.SetPixelMemory( pTexture->Format(), + pTexture->ImageData( 0, 0, 0 ), pTexture->RowSizeInBytes( 0 ) ); + + for ( int y = 0; y < m_LowResImageHeight; ++y ) + { + pixelWriter.Seek( 0, y ); + for ( int x = 0; x < m_LowResImageWidth; ++x ) + { + int red = m_pLowResImage[0]; + int green = m_pLowResImage[1]; + int blue = m_pLowResImage[2]; + m_pLowResImage += 3; + + pixelWriter.WritePixel( red, green, blue, 255 ); + } + } +} + +//----------------------------------------------------------------------------- +// Sets up debugging texture bits, if appropriate +//----------------------------------------------------------------------------- +bool CTexture::SetupDebuggingTextures( IVTFTexture *pVTFTexture ) +{ + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s", __FUNCTION__ ); + + if ( pVTFTexture->Flags() & TEXTUREFLAGS_NODEBUGOVERRIDE ) + return false; + + // The all mips flag is typically used on detail textures, which can + // really mess up visualization if we apply the debug-colorized + // versions of them to debug-colorized base textures, so skip 'em + if ( g_config.nShowMipLevels && !(pVTFTexture->Flags() & TEXTUREFLAGS_ALL_MIPS) ) + { + // mat_showmiplevels 1 means don't do normal maps + if ( ( g_config.nShowMipLevels == 1 ) && ( pVTFTexture->Flags() & ( TEXTUREFLAGS_NORMAL | TEXTUREFLAGS_SSBUMP ) ) ) + return false; + + // mat_showmiplevels 2 means don't do base textures + if ( ( g_config.nShowMipLevels == 2 ) && !( pVTFTexture->Flags() & ( TEXTUREFLAGS_NORMAL | TEXTUREFLAGS_SSBUMP ) ) ) + return false; + + // This mode shows the mip levels as different colors + GenerateShowMipLevelsTextures( pVTFTexture ); + return true; + } + else if ( g_config.bShowLowResImage && pVTFTexture->FrameCount() == 1 && + pVTFTexture->FaceCount() == 1 && ((pVTFTexture->Flags() & TEXTUREFLAGS_NORMAL) == 0) && + m_LowResImageWidth != 0 && m_LowResImageHeight != 0 ) + { + // This mode just uses the low res texture + CopyLowResImageToTexture( pVTFTexture ); + return true; + } + + return false; +} + +//----------------------------------------------------------------------------- +// Converts the texture to the actual format +// Returns true if conversion applied, false otherwise +//----------------------------------------------------------------------------- +bool CTexture::ConvertToActualFormat( IVTFTexture *pVTFTexture ) +{ + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s", __FUNCTION__ ); + + if ( !g_pShaderDevice->IsUsingGraphics() ) + return false; + + bool bConverted = false; + + ImageFormat fmt = m_ImageFormat; + + ImageFormat dstFormat = ComputeActualFormat( pVTFTexture->Format() ); + if ( fmt != dstFormat ) + { + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s - conversion from (%d to %d)", __FUNCTION__, fmt, dstFormat ); + + pVTFTexture->ConvertImageFormat( dstFormat, false ); + + m_ImageFormat = dstFormat; + bConverted = true; + } + else if ( HardwareConfig()->GetHDRType() == HDR_TYPE_INTEGER && + fmt == dstFormat && dstFormat == IMAGE_FORMAT_RGBA16161616F ) + { + // This is to force at most the precision of int16 for fp16 texture when running the integer path. + pVTFTexture->ConvertImageFormat( IMAGE_FORMAT_RGBA16161616, false ); + pVTFTexture->ConvertImageFormat( IMAGE_FORMAT_RGBA16161616F, false ); + bConverted = true; + } + + return bConverted; +} + +void CTexture::GetFilename( char *pOut, int maxLen ) const +{ + const char *pName = m_Name.String(); + bool bIsUNCName = ( pName[0] == '/' && pName[1] == '/' && pName[2] != '/' ); + + if ( !bIsUNCName ) + { + Q_snprintf( pOut, maxLen, + "materials/%s" TEXTURE_FNAME_EXTENSION, pName ); + } + else + { + Q_snprintf( pOut, maxLen, "%s" TEXTURE_FNAME_EXTENSION, pName ); + } +} + + +void CTexture::ReloadFilesInList( IFileList *pFilesToReload ) +{ + if ( IsProcedural() || IsRenderTarget() ) + return; + + char filename[MAX_PATH]; + GetFilename( filename, sizeof( filename ) ); + if ( pFilesToReload->IsFileInList( filename ) ) + { + Download(); + } +} + +//----------------------------------------------------------------------------- +// Loads the texture bits from a file. +//----------------------------------------------------------------------------- +IVTFTexture *CTexture::LoadTextureBitsFromFile( char *pCacheFileName, char **ppResolvedFilename ) +{ + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s %s", __FUNCTION__, tmDynamicString( TELEMETRY_LEVEL0, pCacheFileName ) ); + + if ( m_bStreamingFileReadFailed ) + { + Assert( m_pStreamingVTF == NULL ); + return HandleFileLoadFailedTexture( GetScratchVTFTexture() ); + } + + // OSX hackery + int nPreserveFlags = 0; + if ( m_nFlags & TEXTUREFLAGS_SRGB ) + nPreserveFlags |= TEXTUREFLAGS_SRGB; + + unsigned int stripFlags = 0; + + IVTFTexture *pVTFTexture = m_pStreamingVTF; + if ( !pVTFTexture ) + { + pVTFTexture = GetScratchVTFTexture(); + + FileHandle_t fileHandle = FILESYSTEM_INVALID_HANDLE; + + if ( !GetFileHandle( &fileHandle, pCacheFileName, ppResolvedFilename ) ) + return HandleFileLoadFailedTexture( pVTFTexture ); + + TextureLODControlSettings_t settings = m_cachedFileLodSettings; + if ( !SLoadTextureBitsFromFile( &pVTFTexture, fileHandle, m_nFlags | nPreserveFlags, &settings, m_nDesiredDimensionLimit, &m_nStreamingMips, GetName(), pCacheFileName, &m_dimsMapping, &m_dimsActual, &m_dimsAllocated, &stripFlags ) ) + { + g_pFullFileSystem->Close( fileHandle ); + return HandleFileLoadFailedTexture( pVTFTexture ); + } + + g_pFullFileSystem->Close( fileHandle ); + } + + + // Don't reinitialize here if we're streaming in the fine levels, we already have been initialized with coarse. + if ( ( m_nFlags & TEXTUREFLAGS_STREAMABLE_FINE ) == 0 ) + { + // Initing resets these, but we're happy with the values now--so store and restore them around the Init call. + TexDimensions_t actual = m_dimsActual, + allocated = m_dimsAllocated; + + // Initialize the texture class with vtf header data before operations + Init( m_dimsMapping.m_nWidth, + m_dimsMapping.m_nHeight, + m_dimsMapping.m_nDepth, + pVTFTexture->Format(), + pVTFTexture->Flags() | nPreserveFlags, + pVTFTexture->FrameCount() + ); + + m_dimsActual = actual; + m_dimsAllocated = allocated; + + m_nFlags &= ~stripFlags; + } + else + { + // Not illegal, just needs investigation. + Assert( stripFlags == 0 ); + } + + if ( m_pStreamingVTF ) + ComputeActualSize( false, pVTFTexture, ( m_nFlags & TEXTUREFLAGS_STREAMABLE ) != 0 ); + + VectorCopy( pVTFTexture->Reflectivity(), m_vecReflectivity ); + + // If we've only streamed in coarse but haven't started on fine yet, go ahead and mark us as + // partially resident and set up our clamping values. + if ( ( m_nFlags & TEXTUREFLAGS_STREAMABLE ) == TEXTUREFLAGS_STREAMABLE_COARSE ) + { + pVTFTexture->GetMipmapRange( &m_lodClamp, NULL ); + m_residenceTarget = RESIDENT_PARTIAL; + m_residenceCurrent = RESIDENT_PARTIAL; + } + + // Build the low-res texture + LoadLowResTexture( pVTFTexture ); + + // Load the resources + if ( unsigned int uiRsrcCount = pVTFTexture->GetResourceTypes( NULL, 0 ) ) + { + uint32 *arrRsrcTypes = ( uint32 * )_alloca( uiRsrcCount * sizeof( unsigned int ) ); + pVTFTexture->GetResourceTypes( arrRsrcTypes, uiRsrcCount ); + + m_arrDataChunks.EnsureCapacity( uiRsrcCount ); + for ( uint32 *arrRsrcTypesEnd = arrRsrcTypes + uiRsrcCount; + arrRsrcTypes < arrRsrcTypesEnd; ++arrRsrcTypes ) + { + switch ( *arrRsrcTypes ) + { + case VTF_LEGACY_RSRC_LOW_RES_IMAGE: + case VTF_LEGACY_RSRC_IMAGE: + // These stock types use specific load routines + continue; + + default: + { + DataChunk dc; + dc.m_eType = *arrRsrcTypes; + dc.m_eType &= ~RSRCF_MASK; + + size_t numBytes; + if ( void *pvData = pVTFTexture->GetResourceData( dc.m_eType, &numBytes ) ) + { + Assert( numBytes >= sizeof( uint32 ) ); + if ( numBytes == sizeof( dc.m_numBytes ) ) + { + dc.m_eType |= RSRCF_HAS_NO_DATA_CHUNK; + dc.m_pvData = NULL; + memcpy( &dc.m_numBytes, pvData, numBytes ); + } + else + { + dc.Allocate( numBytes ); + memcpy( dc.m_pvData, pvData, numBytes ); + } + + m_arrDataChunks.AddToTail( dc ); + } + } + } + } + } + + // Try to set up debugging textures, if we're in a debugging mode + if ( !IsProcedural() ) + SetupDebuggingTextures( pVTFTexture ); + + if ( ConvertToActualFormat( pVTFTexture ) ) + pVTFTexture; // STAGING_ONLY_EXEC ( Warning( "\"%s\" not in final format, this is causing stutters or load time bloat!\n", pCacheFileName ) ); + + return pVTFTexture; +} + + +IVTFTexture *CTexture::HandleFileLoadFailedTexture( IVTFTexture *pVTFTexture ) +{ + // create the error texture + + // This will make a checkerboard texture to indicate failure + pVTFTexture->Init( 32, 32, 1, IMAGE_FORMAT_BGRA8888, m_nFlags, 1 ); + Init( pVTFTexture->Width(), pVTFTexture->Height(), pVTFTexture->Depth(), pVTFTexture->Format(), + pVTFTexture->Flags(), pVTFTexture->FrameCount() ); + m_vecReflectivity.Init( 0.5f, 0.5f, 0.5f ); + + // NOTE: For mat_picmip to work, we must use the same size (32x32) + // Which should work since every card can handle textures of that size + m_dimsAllocated.m_nWidth = m_dimsActual.m_nWidth = pVTFTexture->Width(); + m_dimsAllocated.m_nHeight = m_dimsActual.m_nHeight = pVTFTexture->Height(); + m_dimsAllocated.m_nDepth = 1; + m_dimsAllocated.m_nMipCount = m_dimsActual.m_nMipCount = 1; + m_nStreamingMips = 0; + + + + // generate the checkerboard + TextureManager()->GenerateErrorTexture( this, pVTFTexture ); + ConvertToActualFormat( pVTFTexture ); + + // Deactivate procedural texture... + m_nFlags &= ~TEXTUREFLAGS_PROCEDURAL; + SetErrorTexture( true ); + + return pVTFTexture; +} + +//----------------------------------------------------------------------------- +// Computes subrect for a particular miplevel +//----------------------------------------------------------------------------- +void CTexture::ComputeMipLevelSubRect( const Rect_t* pSrcRect, int nMipLevel, Rect_t *pSubRect ) +{ + if (nMipLevel == 0) + { + *pSubRect = *pSrcRect; + return; + } + + float flInvShrink = 1.0f / (float)(1 << nMipLevel); + pSubRect->x = pSrcRect->x * flInvShrink; + pSubRect->y = pSrcRect->y * flInvShrink; + pSubRect->width = (int)ceil( (pSrcRect->x + pSrcRect->width) * flInvShrink ) - pSubRect->x; + pSubRect->height = (int)ceil( (pSrcRect->y + pSrcRect->height) * flInvShrink ) - pSubRect->y; +} + + +//----------------------------------------------------------------------------- +// Computes the face count + first face +//----------------------------------------------------------------------------- +void CTexture::GetDownloadFaceCount( int &nFirstFace, int &nFaceCount ) +{ + nFaceCount = 1; + nFirstFace = 0; + if ( IsCubeMap() ) + { + if ( HardwareConfig()->SupportsCubeMaps() ) + { + nFaceCount = CUBEMAP_FACE_COUNT-1; + } + else + { + // This will cause us to use the spheremap instead of the cube faces + // in the case where we don't support cubemaps + nFirstFace = CUBEMAP_FACE_SPHEREMAP; + } + } +} + +//----------------------------------------------------------------------------- +// Fixup a queue loaded texture with the delayed hi-res data +//----------------------------------------------------------------------------- +void CTexture::FixupTexture( const void *pData, int nSize, LoaderError_t loaderError ) +{ + if ( loaderError != LOADERERROR_NONE ) + { + // mark as invalid + nSize = 0; + } + + m_nInternalFlags &= ~TEXTUREFLAGSINTERNAL_QUEUEDLOAD; + + // Make sure we've actually allocated the texture handles + Assert( HasBeenAllocated() ); +} + +static void QueuedLoaderCallback( void *pContext, void *pContext2, const void *pData, int nSize, LoaderError_t loaderError ) +{ + reinterpret_cast< CTexture * >( pContext )->FixupTexture( pData, nSize, loaderError ); +} + +//----------------------------------------------------------------------------- +// Generates the procedural bits +//----------------------------------------------------------------------------- +IVTFTexture *CTexture::ReconstructPartialProceduralBits( const Rect_t *pRect, Rect_t *pActualRect ) +{ + // Figure out the actual size for this texture based on the current mode + bool bIgnorePicmip = ( m_nFlags & ( TEXTUREFLAGS_STAGING_MEMORY | TEXTUREFLAGS_IGNORE_PICMIP ) ) != 0; + ComputeActualSize( bIgnorePicmip ); + + // Figure out how many mip levels we're skipping... + int nSizeFactor = 1; + int nWidth = GetActualWidth(); + if ( nWidth != 0 ) + { + nSizeFactor = GetMappingWidth() / nWidth; + } + int nMipSkipCount = 0; + while (nSizeFactor > 1) + { + nSizeFactor >>= 1; + ++nMipSkipCount; + } + + // Determine a rectangle appropriate for the actual size... + // It must bound all partially-covered pixels.. + ComputeMipLevelSubRect( pRect, nMipSkipCount, pActualRect ); + + // Create the texture + IVTFTexture *pVTFTexture = GetScratchVTFTexture(); + + // Initialize the texture + pVTFTexture->Init( m_dimsActual.m_nWidth, m_dimsActual.m_nHeight, m_dimsActual.m_nDepth, + ComputeActualFormat( m_ImageFormat ), m_nFlags, m_nFrameCount ); + + // Generate the bits from the installed procedural regenerator + if ( m_pTextureRegenerator ) + { + m_pTextureRegenerator->RegenerateTextureBits( this, pVTFTexture, pActualRect ); + } + else + { + // In this case, we don't have one, so just use a checkerboard... + TextureManager()->GenerateErrorTexture( this, pVTFTexture ); + } + + return pVTFTexture; +} + + +//----------------------------------------------------------------------------- +// Regenerates the bits of a texture within a particular rectangle +//----------------------------------------------------------------------------- +void CTexture::ReconstructPartialTexture( const Rect_t *pRect ) +{ + // FIXME: for now, only procedural textures can handle sub-rect specification. + Assert( IsProcedural() ); + + // Also, we need procedural textures that have only a single copy!! + // Otherwise this partial upload will not occur on all copies + Assert( m_nFlags & TEXTUREFLAGS_SINGLECOPY ); + + Rect_t vtfRect; + IVTFTexture *pVTFTexture = ReconstructPartialProceduralBits( pRect, &vtfRect ); + + // FIXME: for now, depth textures do not work with this. + Assert( pVTFTexture->Depth() == 1 ); + + // Make sure we've allocated the API textures + if ( !HasBeenAllocated() ) + { + if ( !AllocateShaderAPITextures() ) + return; + } + + int nFaceCount, nFirstFace; + GetDownloadFaceCount( nFirstFace, nFaceCount ); + + // Blit down portions of the various VTF frames into the board memory + int nStride; + Rect_t mipRect; + for ( int iFrame = 0; iFrame < m_nFrameCount; ++iFrame ) + { + Modify( iFrame ); + + for ( int iFace = 0; iFace < nFaceCount; ++iFace ) + { + for ( int iMip = 0; iMip < m_dimsActual.m_nMipCount; ++iMip ) + { + pVTFTexture->ComputeMipLevelSubRect( &vtfRect, iMip, &mipRect ); + nStride = pVTFTexture->RowSizeInBytes( iMip ); + unsigned char *pBits = pVTFTexture->ImageData( iFrame, iFace + nFirstFace, iMip, mipRect.x, mipRect.y, 0 ); + g_pShaderAPI->TexSubImage2D( + iMip, + iFace, + mipRect.x, + mipRect.y, + 0, + mipRect.width, + mipRect.height, + pVTFTexture->Format(), + nStride, + false, + pBits ); + } + } + } +} + + +//----------------------------------------------------------------------------- +// Generates the procedural bits +//----------------------------------------------------------------------------- +IVTFTexture *CTexture::ReconstructProceduralBits() +{ + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s", __FUNCTION__ ); + + // Figure out the actual size for this texture based on the current mode + bool bIgnorePicmip = ( m_nFlags & ( TEXTUREFLAGS_STAGING_MEMORY | TEXTUREFLAGS_IGNORE_PICMIP ) ) != 0; + ComputeActualSize( bIgnorePicmip ); + + // Create the texture + IVTFTexture *pVTFTexture = NULL; + + { + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s - GetScratchVTFTexture", __FUNCTION__ ); + pVTFTexture = GetScratchVTFTexture(); + } + + { + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s - Init", __FUNCTION__ ); + // Initialize the texture + pVTFTexture->Init( m_dimsActual.m_nWidth, m_dimsActual.m_nHeight, m_dimsActual.m_nDepth, + ComputeActualFormat( m_ImageFormat ), m_nFlags, m_nFrameCount ); + } + + // Generate the bits from the installed procedural regenerator + if ( m_pTextureRegenerator ) + { + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s - RegenerateTextureBits", __FUNCTION__ ); + + Rect_t rect; + rect.x = 0; rect.y = 0; + rect.width = m_dimsActual.m_nWidth; + rect.height = m_dimsActual.m_nHeight; + m_pTextureRegenerator->RegenerateTextureBits( this, pVTFTexture, &rect ); + } + else + { + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s - GenerateErrorTexture", __FUNCTION__ ); + + // In this case, we don't have one, so just use a checkerboard... + TextureManager()->GenerateErrorTexture( this, pVTFTexture ); + } + + return pVTFTexture; +} + +void CTexture::WriteDataToShaderAPITexture( int nFrameCount, int nFaceCount, int nFirstFace, int nMipCount, IVTFTexture *pVTFTexture, ImageFormat fmt ) +{ + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s", __FUNCTION__ ); + + // If we're a staging texture, there's nothing to do. + if ( ( m_nFlags & TEXTUREFLAGS_STAGING_MEMORY ) != 0 ) + return; + + for ( int iFrame = 0; iFrame < m_nFrameCount; ++iFrame ) + { + Modify( iFrame ); + g_pShaderAPI->TexImageFromVTF( pVTFTexture, iFrame ); + } +} + +bool CTexture::IsDepthTextureFormat( ImageFormat fmt ) +{ + return ( ( m_ImageFormat == IMAGE_FORMAT_NV_DST16 ) || + ( m_ImageFormat == IMAGE_FORMAT_NV_DST24 ) || + ( m_ImageFormat == IMAGE_FORMAT_NV_INTZ ) || + ( m_ImageFormat == IMAGE_FORMAT_NV_RAWZ ) || + ( m_ImageFormat == IMAGE_FORMAT_ATI_DST16 ) || + ( m_ImageFormat == IMAGE_FORMAT_ATI_DST24 ) ); +} + +//----------------------------------------------------------------------------- +void CTexture::NotifyUnloadedFile() +{ + // Make sure we have a regular texture that was loaded from a file + if ( IsProcedural() || IsRenderTarget() || !m_Name.IsValid() ) + return; + const char *pName = m_Name.String(); + if ( *pName == '\0' ) + return; + bool bIsUNCName = ( pName[0] == '/' && pName[1] == '/' && pName[2] != '/' ); + if ( bIsUNCName ) + return; + + // Generate the filename + char pCacheFileName[MATERIAL_MAX_PATH]; + Q_snprintf( pCacheFileName, sizeof( pCacheFileName ), "materials/%s" TEXTURE_FNAME_EXTENSION, pName ); + + // Let filesystem know that the file is uncached, so it knows + // what to do with tracking info + g_pFullFileSystem->NotifyFileUnloaded( pCacheFileName, "GAME" ); +} + +//----------------------------------------------------------------------------- +// Sets or updates the texture bits +//----------------------------------------------------------------------------- +void CTexture::ReconstructTexture( bool bCopyFromCurrent ) +{ + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s", __FUNCTION__ ); + + Assert( !bCopyFromCurrent || HardwareConfig()->CanStretchRectFromTextures() ); + + int oldWidth = m_dimsAllocated.m_nWidth; + int oldHeight = m_dimsAllocated.m_nHeight; + int oldDepth = m_dimsAllocated.m_nDepth; + int oldMipCount = m_dimsAllocated.m_nMipCount; + int oldFrameCount = m_nFrameCount; + + // FIXME: Should RenderTargets be a special case of Procedural? + char *pResolvedFilename = NULL; + IVTFTexture *pVTFTexture = NULL; + + { + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s - Begin", __FUNCTION__ ); + if ( IsProcedural() ) + { + // This will call the installed texture bit regeneration interface + pVTFTexture = ReconstructProceduralBits(); + } + else if ( IsRenderTarget() ) + { + // Compute the actual size + format based on the current mode + bool bIgnorePicmip = m_RenderTargetSizeMode != RT_SIZE_LITERAL_PICMIP; + ComputeActualSize( bIgnorePicmip ); + } + else if ( bCopyFromCurrent ) + { + ComputeActualSize( false, NULL, true ); + } + else + { + NotifyUnloadedFile(); + + char pCacheFileName[ MATERIAL_MAX_PATH ] = { 0 }; + GetCacheFilename( pCacheFileName, ARRAYSIZE( pCacheFileName ) ); + + // Get the data from disk... + // NOTE: Reloading the texture bits can cause the texture size, frames, format, pretty much *anything* can change. + pVTFTexture = LoadTextureBitsFromFile( pCacheFileName, &pResolvedFilename ); + } + } + + if ( !HasBeenAllocated() || + m_dimsAllocated.m_nWidth != oldWidth || + m_dimsAllocated.m_nHeight != oldHeight || + m_dimsAllocated.m_nDepth != oldDepth || + m_dimsAllocated.m_nMipCount != oldMipCount || + m_nFrameCount != oldFrameCount ) + { + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s - Allocation", __FUNCTION__ ); + + const bool cbCanStretchRectTextures = HardwareConfig()->CanStretchRectFromTextures(); + const bool cbShouldMigrateTextures = ( ( m_nFlags & TEXTUREFLAGS_STREAMABLE_FINE ) != 0 ) && m_nFrameCount == oldFrameCount; + + // If we're just streaming in more data--or demoting ourselves, do a migration instead. + if ( bCopyFromCurrent || ( cbCanStretchRectTextures && cbShouldMigrateTextures ) ) + { + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s - Migration", __FUNCTION__ ); + + MigrateShaderAPITextures(); + + // Ahh--I feel terrible about this, but we genuinely don't need anything else if we're streaming. + if ( bCopyFromCurrent ) + return; + } + else + { + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s - Deallocate / Allocate", __FUNCTION__ ); + + // If we're doing a wholesale copy, we need to restore these values that will be cleared by FreeShaderAPITextures. + // Record them here, restore them below. + unsigned int restoreStreamingFlag = ( m_nFlags & TEXTUREFLAGS_STREAMABLE ); + ResidencyType_t restoreResidenceCurrent = m_residenceCurrent; + ResidencyType_t restoreResidenceTarget = m_residenceTarget; + + if ( HasBeenAllocated() ) + { + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s - Deallocate", __FUNCTION__ ); + + // This is necessary for the reload case, we may discover there + // are more frames of a texture animation, for example, which means + // we can't rely on having the same number of texture frames. + FreeShaderAPITextures(); + } + + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s - Allocate", __FUNCTION__ ); + + // Create the shader api textures + if ( !AllocateShaderAPITextures() ) + return; + + // Restored once we successfully allocate the shader api textures, but only if we're + // + if ( !cbCanStretchRectTextures && cbShouldMigrateTextures ) + { + m_nFlags |= restoreStreamingFlag; + m_residenceCurrent = restoreResidenceCurrent; + m_residenceTarget = restoreResidenceTarget; + } + } + } + else if ( bCopyFromCurrent ) + { + Assert( !"We're about to crash, last chance to examine this texture." ); + } + + + // Render Targets just need to be cleared, they have no upload + if ( IsRenderTarget() ) + { + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s - RT Stuff", __FUNCTION__ ); + + // Clear the render target to opaque black + + // Only clear if we're not a depth-stencil texture + if ( !IsDepthTextureFormat( m_ImageFormat ) ) + { + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s - Clearing", __FUNCTION__ ); + + CMatRenderContextPtr pRenderContext( MaterialSystem() ); + ITexture *pThisTexture = GetEmbeddedTexture( 0 ); + pRenderContext->PushRenderTargetAndViewport( pThisTexture ); // Push this texture on the stack + g_pShaderAPI->ClearColor4ub( 0, 0, 0, 0xFF ); // Set the clear color to opaque black + g_pShaderAPI->ClearBuffers( true, false, false, m_dimsActual.m_nWidth, m_dimsActual.m_nHeight ); // Clear the target + pRenderContext->PopRenderTargetAndViewport(); // Pop back to previous target + } + // no upload + return; + } + + // Blit down the texture faces, frames, and mips into the board memory + int nFirstFace, nFaceCount; + GetDownloadFaceCount( nFirstFace, nFaceCount ); + + WriteDataToShaderAPITexture( m_nFrameCount, nFaceCount, nFirstFace, m_dimsActual.m_nMipCount, pVTFTexture, m_ImageFormat ); + + ReleaseScratchVTFTexture( pVTFTexture ); + pVTFTexture = NULL; + + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s - Final Cleanup", __FUNCTION__ ); + + // allocated by strdup + free( pResolvedFilename ); + + // the pc can afford to persist a large buffer + FreeOptimalReadBuffer( 6*1024*1024 ); +} + +void CTexture::GetCacheFilename( char* pOutBuffer, int nBufferSize ) const +{ + Assert( pOutBuffer ); + + if ( IsProcedural() || IsRenderTarget() ) + { + pOutBuffer[0] = 0; + return; + } + else + { + const char *pName; + if ( m_nInternalFlags & TEXTUREFLAGSINTERNAL_SHOULDEXCLUDE ) + { + pName = "dev/dev_exclude_error"; + } + else + { + pName = m_Name.String(); + } + + bool bIsUNCName = ( pName[ 0 ] == '/' && pName[ 1 ] == '/' && pName[ 2 ] != '/' ); + if ( !bIsUNCName ) + { + Q_snprintf( pOutBuffer, nBufferSize, "materials/%s" TEXTURE_FNAME_EXTENSION, pName ); + } + else + { + Q_snprintf( pOutBuffer, nBufferSize, "%s" TEXTURE_FNAME_EXTENSION, pName ); + } + } +} + +bool CTexture::GetFileHandle( FileHandle_t *pOutFileHandle, char *pCacheFileName, char **ppResolvedFilename ) const +{ + Assert( pOutFileHandle ); + FileHandle_t& fileHandle = *pOutFileHandle; + fileHandle = FILESYSTEM_INVALID_HANDLE; + + while ( fileHandle == FILESYSTEM_INVALID_HANDLE ) // run until found a file or out of rules + { + fileHandle = g_pFullFileSystem->OpenEx( pCacheFileName, "rb", 0, MaterialSystem()->GetForcedTextureLoadPathID(), ppResolvedFilename ); + if ( fileHandle == FILESYSTEM_INVALID_HANDLE ) + { + // try any fallbacks. + char *pHdrExt = Q_stristr( pCacheFileName, ".hdr" TEXTURE_FNAME_EXTENSION ); + if ( pHdrExt ) + { + DevWarning( "A custom HDR cubemap \"%s\": cannot be found on disk.\n" + "This really should have a HDR version, trying a fall back to a non-HDR version.\n", pCacheFileName ); + strcpy( pHdrExt, TEXTURE_FNAME_EXTENSION ); + } + else + { + // no more fallbacks + break; + } + } + } + + if ( fileHandle == FILESYSTEM_INVALID_HANDLE ) + { + if ( Q_strnicmp( m_Name.String(), "env_cubemap", 12 ) ) + { + if ( IsPosix() ) + { + Msg( "\n ##### CTexture::LoadTextureBitsFromFile couldn't find %s\n", pCacheFileName ); + } + DevWarning( "\"%s\": can't be found on disk\n", pCacheFileName ); + } + + return false; + } + + return true; +} + + +// Get the shaderapi texture handle associated w/ a particular frame +ShaderAPITextureHandle_t CTexture::GetTextureHandle( int nFrame, int nTextureChannel ) +{ + if ( nFrame < 0 ) + { + nFrame = 0; + Warning( "CTexture::GetTextureHandle(): nFrame is < 0!\n" ); + } + if ( nFrame >= m_nFrameCount ) + { + // NOTE: This can happen during alt-tab. If you alt-tab while loading a level then the first local cubemap bind will do this, for example. + Assert( nFrame < m_nFrameCount ); + return INVALID_SHADERAPI_TEXTURE_HANDLE; + } + Assert( nTextureChannel < 2 ); + + // Make sure we've actually allocated the texture handles + Assert( m_pTextureHandles ); + Assert( HasBeenAllocated() ); + if ( m_pTextureHandles == NULL || !HasBeenAllocated() ) + { + return INVALID_SHADERAPI_TEXTURE_HANDLE; + } + + // Don't get paired handle here...callers of this function don't know about paired textures + return m_pTextureHandles[nFrame]; +} + +void CTexture::GetLowResColorSample( float s, float t, float *color ) const +{ + if ( m_LowResImageWidth <= 0 || m_LowResImageHeight <= 0 ) + { +// Warning( "Programming error: GetLowResColorSample \"%s\": %dx%d\n", m_pName, ( int )m_LowResImageWidth, ( int )m_LowResImageHeight ); + return; + } + + // force s and t into [0,1) + if ( s < 0.0f ) + { + s = ( 1.0f - ( float )( int )s ) + s; + } + if ( t < 0.0f ) + { + t = ( 1.0f - ( float )( int )t ) + t; + } + s = s - ( float )( int )s; + t = t - ( float )( int )t; + + s *= m_LowResImageWidth; + t *= m_LowResImageHeight; + + int wholeS, wholeT; + wholeS = ( int )s; + wholeT = ( int )t; + float fracS, fracT; + fracS = s - ( float )( int )s; + fracT = t - ( float )( int )t; + + // filter twice in the s dimension. + float sColor[2][3]; + int wholeSPlusOne = ( wholeS + 1 ) % m_LowResImageWidth; + int wholeTPlusOne = ( wholeT + 1 ) % m_LowResImageHeight; + sColor[0][0] = ( 1.0f - fracS ) * ( m_pLowResImage[( wholeS + wholeT * m_LowResImageWidth ) * 3 + 0] * ( 1.0f / 255.0f ) ); + sColor[0][1] = ( 1.0f - fracS ) * ( m_pLowResImage[( wholeS + wholeT * m_LowResImageWidth ) * 3 + 1] * ( 1.0f / 255.0f ) ); + sColor[0][2] = ( 1.0f - fracS ) * ( m_pLowResImage[( wholeS + wholeT * m_LowResImageWidth ) * 3 + 2] * ( 1.0f / 255.0f ) ); + sColor[0][0] += fracS * ( m_pLowResImage[( wholeSPlusOne + wholeT * m_LowResImageWidth ) * 3 + 0] * ( 1.0f / 255.0f ) ); + sColor[0][1] += fracS * ( m_pLowResImage[( wholeSPlusOne + wholeT * m_LowResImageWidth ) * 3 + 1] * ( 1.0f / 255.0f ) ); + sColor[0][2] += fracS * ( m_pLowResImage[( wholeSPlusOne + wholeT * m_LowResImageWidth ) * 3 + 2] * ( 1.0f / 255.0f ) ); + + sColor[1][0] = ( 1.0f - fracS ) * ( m_pLowResImage[( wholeS + wholeTPlusOne * m_LowResImageWidth ) * 3 + 0] * ( 1.0f / 255.0f ) ); + sColor[1][1] = ( 1.0f - fracS ) * ( m_pLowResImage[( wholeS + wholeTPlusOne * m_LowResImageWidth ) * 3 + 1] * ( 1.0f / 255.0f ) ); + sColor[1][2] = ( 1.0f - fracS ) * ( m_pLowResImage[( wholeS + wholeTPlusOne * m_LowResImageWidth ) * 3 + 2] * ( 1.0f / 255.0f ) ); + sColor[1][0] += fracS * ( m_pLowResImage[( wholeSPlusOne + wholeTPlusOne * m_LowResImageWidth ) * 3 + 0] * ( 1.0f / 255.0f ) ); + sColor[1][1] += fracS * ( m_pLowResImage[( wholeSPlusOne + wholeTPlusOne * m_LowResImageWidth ) * 3 + 1] * ( 1.0f / 255.0f ) ); + sColor[1][2] += fracS * ( m_pLowResImage[( wholeSPlusOne + wholeTPlusOne * m_LowResImageWidth ) * 3 + 2] * ( 1.0f / 255.0f ) ); + + color[0] = sColor[0][0] * ( 1.0f - fracT ) + sColor[1][0] * fracT; + color[1] = sColor[0][1] * ( 1.0f - fracT ) + sColor[1][1] * fracT; + color[2] = sColor[0][2] * ( 1.0f - fracT ) + sColor[1][2] * fracT; +} + +int CTexture::GetApproximateVidMemBytes( void ) const +{ + ImageFormat format = GetImageFormat(); + int width = GetActualWidth(); + int height = GetActualHeight(); + int depth = GetActualDepth(); + int numFrames = GetNumAnimationFrames(); + bool isMipmapped = IsMipmapped(); + + return numFrames * ImageLoader::GetMemRequired( width, height, depth, format, isMipmapped ); +} + +void CTexture::CopyFrameBufferToMe( int nRenderTargetID, Rect_t *pSrcRect, Rect_t *pDstRect ) +{ + Assert( m_pTextureHandles && m_nFrameCount >= 1 ); + + if ( m_pTextureHandles && m_nFrameCount >= 1 ) + { + g_pShaderAPI->CopyRenderTargetToTextureEx( m_pTextureHandles[0], nRenderTargetID, pSrcRect, pDstRect ); + } +} + +void CTexture::CopyMeToFrameBuffer( int nRenderTargetID, Rect_t *pSrcRect, Rect_t *pDstRect ) +{ + Assert( m_pTextureHandles && m_nFrameCount >= 1 ); + + if ( m_pTextureHandles && m_nFrameCount >= 1 ) + { + g_pShaderAPI->CopyTextureToRenderTargetEx( nRenderTargetID, m_pTextureHandles[0], pSrcRect, pDstRect ); + } +} + +ITexture *CTexture::GetEmbeddedTexture( int nIndex ) +{ + return ( nIndex == 0 ) ? this : NULL; +} + +void CTexture::DeleteIfUnreferenced() +{ + if ( m_nRefCount > 0 ) + return; + + if ( ThreadInMainThread() ) + { + // Render thread better not be active or bad things can happen. + Assert( MaterialSystem()->GetRenderThreadId() == 0xFFFFFFFF ); + TextureManager()->RemoveTexture( this ); + return; + } + + // Can't actually clean up from render thread--just safely mark this texture as + // one we should check for cleanup next EndFrame when it's safe. + TextureManager()->MarkUnreferencedTextureForCleanup( this ); +} + +//Swap everything about a texture except the name. Created to support Portal mod's need for swapping out water render targets in recursive stencil views +void CTexture::SwapContents( ITexture *pOther ) +{ + if( (pOther == NULL) || (pOther == this) ) + return; + + ICallQueue *pCallQueue = materials->GetRenderContext()->GetCallQueue(); + if ( pCallQueue ) + { + pCallQueue->QueueCall( this, &CTexture::SwapContents, pOther ); + return; + } + + AssertMsg( dynamic_cast(pOther) != NULL, "Texture swapping broken" ); + + CTexture *pOtherAsCTexture = (CTexture *)pOther; + + CTexture *pTemp = (CTexture *)stackalloc( sizeof( CTexture ) ); + + //swap everything. Note that this copies the entire object including the + // vtable pointer, thus ruining polymorphism. Use with care. + // The unnecessary casts to (void*) hint to clang that we know what we + // are doing. + memcpy( (void*)pTemp, (const void*)this, sizeof( CTexture ) ); + memcpy( (void*)this, (const void*)pOtherAsCTexture, sizeof( CTexture ) ); + memcpy( (void*)pOtherAsCTexture, (const void*)pTemp, sizeof( CTexture ) ); + + //we have the other's name, give it back + memcpy( &pOtherAsCTexture->m_Name, &m_Name, sizeof( m_Name ) ); + + //pTemp still has our name + memcpy( &m_Name, &pTemp->m_Name, sizeof( m_Name ) ); +} + +void CTexture::MarkAsPreloaded( bool bSet ) +{ + if ( bSet ) + { + m_nInternalFlags |= TEXTUREFLAGSINTERNAL_PRELOADED; + } + else + { + m_nInternalFlags &= ~TEXTUREFLAGSINTERNAL_PRELOADED; + } +} + +bool CTexture::IsPreloaded() const +{ + return ( ( m_nInternalFlags & TEXTUREFLAGSINTERNAL_PRELOADED ) != 0 ); +} + +void CTexture::MarkAsExcluded( bool bSet, int nDimensionsLimit ) +{ + if ( bSet ) + { + // exclusion trumps picmipping + m_nInternalFlags |= TEXTUREFLAGSINTERNAL_SHOULDEXCLUDE; + m_nDesiredDimensionLimit = 0; + } + else + { + // not excluding, but can optionally picmip + m_nInternalFlags &= ~TEXTUREFLAGSINTERNAL_SHOULDEXCLUDE; + m_nDesiredDimensionLimit = nDimensionsLimit; + } +} + +bool CTexture::UpdateExcludedState( void ) +{ + bool bDesired = ( m_nInternalFlags & TEXTUREFLAGSINTERNAL_SHOULDEXCLUDE ) != 0; + bool bActual = ( m_nInternalFlags & TEXTUREFLAGSINTERNAL_EXCLUDED ) != 0; + if ( ( bDesired == bActual ) && ( m_nDesiredDimensionLimit == m_nActualDimensionLimit ) ) + { + return false; + } + + if ( m_nInternalFlags & TEXTUREFLAGSINTERNAL_QUEUEDLOAD ) + { + // already scheduled + return true; + } + + // force the texture to re-download, causes the texture bits to match its desired exclusion state + Download(); + + return true; +} + +void CTextureStreamingJob::OnAsyncFindComplete( ITexture* pTex, void* pExtraArgs ) +{ + const int cArgsAsInt = ( int ) pExtraArgs; + + Assert( m_pOwner == NULL || m_pOwner == pTex ); + if ( m_pOwner ) + m_pOwner->OnStreamingJobComplete( static_cast( cArgsAsInt ) ); + + // OnStreamingJobComplete should've cleaned us up + Assert( m_pOwner == NULL ); +} + +// ------------------------------------------------------------------------------------------------ +int GetThreadId() +{ + TM_ZONE_DEFAULT( TELEMETRY_LEVEL0 ); + + // Turns the current thread into a 0-based index for use in accessing statics in this file. + int retVal = INT_MAX; + if ( ThreadInMainThread() ) + retVal = 0; + else if ( MaterialSystem()->GetRenderThreadId() == ThreadGetCurrentId() ) + retVal = 1; + else if ( TextureManager()->ThreadInAsyncLoadThread() ) + retVal = 2; + else if ( TextureManager()->ThreadInAsyncReadThread() ) + retVal = 3; + else + { + STAGING_ONLY_EXEC( AssertAlways( !"Unexpected thread in GetThreadId, need to debug this--crash is next. Tell McJohn." ) ); + DebuggerBreakIfDebugging_StagingOnly(); + } + + Assert( retVal < MAX_RENDER_THREADS ); + return retVal; +} + +// ------------------------------------------------------------------------------------------------ +bool SLoadTextureBitsFromFile( IVTFTexture **ppOutVtfTexture, FileHandle_t hFile, unsigned int nFlags, + TextureLODControlSettings_t* pInOutCachedFileLodSettings, + int nDesiredDimensionLimit, unsigned short* pOutStreamedMips, + const char* pName, const char* pCacheFileName, + TexDimensions_t* pOptOutDimsMapping, + TexDimensions_t* pOptOutDimsActual, + TexDimensions_t* pOptOutDimsAllocated, + unsigned int* pOptOutStripFlags ) +{ + // NOTE! NOTE! NOTE! If you are making changes to this function, be aware that it has threading + // NOTE! NOTE! NOTE! implications. It can be called synchronously by the Main thread, + // NOTE! NOTE! NOTE! or by the streaming texture code! + Assert( ppOutVtfTexture != NULL && *ppOutVtfTexture != NULL ); + + if ( V_strstr( pName, "c_rocketlauncher/c_rocketlauncher" ) ) + { + int i = 0; + i = 3; + } + + CUtlBuffer buf; + + { + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s - ReadHeaderFromFile", __FUNCTION__ ); + int nHeaderSize = VTFFileHeaderSize( VTF_MAJOR_VERSION ); + + // restrict read to the header only! + // header provides info to avoid reading the entire file + int nBytesOptimalRead = GetOptimalReadBuffer( &buf, hFile, nHeaderSize ); + int nBytesRead = g_pFullFileSystem->ReadEx( buf.Base(), nBytesOptimalRead, Min( nHeaderSize, ( int ) g_pFullFileSystem->Size( hFile ) ), hFile ); // only read as much as the file has + buf.SeekPut( CUtlBuffer::SEEK_HEAD, nBytesRead ); + nBytesRead = nHeaderSize = ( ( VTFFileBaseHeader_t * ) buf.Base() )->headerSize; + g_pFullFileSystem->Seek( hFile, nHeaderSize, FILESYSTEM_SEEK_HEAD ); + } + + // Unserialize the header only + // need the header first to determine remainder of data + if ( !( *ppOutVtfTexture )->Unserialize( buf, true ) ) + { + Warning( "Error reading texture header \"%s\"\n", pCacheFileName ); + return false; + } + + // Need to record this now, before we ask for the trimmed down data to potentially be loaded. + TexDimensions_t dimsMappingCurrent( ( *ppOutVtfTexture )->Width(), ( *ppOutVtfTexture )->Height(), ( *ppOutVtfTexture )->MipCount(), ( *ppOutVtfTexture )->Depth() ); + if ( pOptOutDimsMapping ) + ( *pOptOutDimsMapping ) = dimsMappingCurrent; + + + int nFullFlags = ( *ppOutVtfTexture )->Flags() + | nFlags; + + // Seek the reading back to the front of the buffer + buf.SeekGet( CUtlBuffer::SEEK_HEAD, 0 ); + + // Compute the actual texture dimensions + int nMipSkipCount = ComputeMipSkipCount( pName, dimsMappingCurrent, false, *ppOutVtfTexture, nFullFlags, nDesiredDimensionLimit, pOutStreamedMips, pInOutCachedFileLodSettings, pOptOutDimsActual, pOptOutDimsAllocated, pOptOutStripFlags ); + + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s - ReadDataFromFile", __FUNCTION__ ); + + // Determine how much of the file to read in + int nFileSize = ( *ppOutVtfTexture )->FileSize( nMipSkipCount ); + int nActualFileSize = (int)g_pFullFileSystem->Size( hFile ); + if ( nActualFileSize < nFileSize ) + { + if ( mat_spew_on_texture_size.GetInt() ) + DevMsg( "Bad VTF data for %s, expected file size:%d actual file size:%d \n", pCacheFileName, nFileSize, nActualFileSize ); + nFileSize = nActualFileSize; + } + + // Read only the portion of the file that we care about + g_pFullFileSystem->Seek( hFile, 0, FILESYSTEM_SEEK_HEAD ); + int nBytesOptimalRead = GetOptimalReadBuffer( &buf, hFile, nFileSize ); + int nBytesRead = g_pFullFileSystem->ReadEx( buf.Base(), nBytesOptimalRead, nFileSize, hFile ); + buf.SeekPut( CUtlBuffer::SEEK_HEAD, nBytesRead ); + + // Some hardware doesn't support copying textures to other textures. For them, we need to reread the + // whole file, so if they are doing the final read (the fine levels) then reread everything by stripping + // off the flags we are trying to pass in. + unsigned int nForceFlags = nFullFlags & TEXTUREFLAGS_STREAMABLE; + if ( !HardwareConfig()->CanStretchRectFromTextures() && ( nForceFlags & TEXTUREFLAGS_STREAMABLE_FINE ) ) + nForceFlags = 0; + + // NOTE: Skipping mip levels here will cause the size to be changed + bool bRetVal = ( *ppOutVtfTexture )->UnserializeEx( buf, false, nForceFlags, nMipSkipCount ); + + FreeOptimalReadBuffer( 6*1024*1024 ); + + if ( !bRetVal ) + { + Warning( "Error reading texture data \"%s\"\n", pCacheFileName ); + } + + return bRetVal; +} + +//----------------------------------------------------------------------------- +// Compute the actual mip count based on the actual size +//----------------------------------------------------------------------------- +int ComputeActualMipCount( const TexDimensions_t& actualDims, unsigned int nFlags ) +{ + if ( nFlags & TEXTUREFLAGS_ENVMAP ) + { + if ( !HardwareConfig()->SupportsMipmappedCubemaps() ) + { + return 1; + } + } + + if ( nFlags & TEXTUREFLAGS_NOMIP ) + { + return 1; + } + + // Unless ALLMIPS is set, we stop mips at 32x32 + const int nMaxMipSize = 32; + // Clamp border textures on Posix to fix L4D2 flashlight cookie issue +#ifdef DX_TO_GL_ABSTRACTION + if ( ( false && !g_bForceTextureAllMips && !( nFlags & TEXTUREFLAGS_ALL_MIPS ) ) || ( true && ( nFlags & TEXTUREFLAGS_BORDER ) ) ) +#else + if ( ( true && !g_bForceTextureAllMips && !( nFlags & TEXTUREFLAGS_ALL_MIPS ) ) || ( false && ( nFlags & TEXTUREFLAGS_BORDER ) ) ) +#endif + { + int nNumMipLevels = 1; + int h = actualDims.m_nWidth; + int w = actualDims.m_nHeight; + while ( MIN( w, h ) > nMaxMipSize ) + { + ++nNumMipLevels; + + w >>= 1; + h >>= 1; + } + return nNumMipLevels; + } + + return ImageLoader::GetNumMipMapLevels( actualDims.m_nWidth, actualDims.m_nHeight, actualDims.m_nDepth ); +} + +// ------------------------------------------------------------------------------------------------ +int ComputeMipSkipCount( const char* pName, const TexDimensions_t& mappingDims, bool bIgnorePicmip, IVTFTexture *pOptVTFTexture, unsigned int nFlags, int nDesiredDimensionLimit, unsigned short* pOutStreamedMips, TextureLODControlSettings_t* pInOutCachedFileLodSettings, TexDimensions_t* pOptOutActualDims, TexDimensions_t* pOptOutAllocatedDims, unsigned int* pOptOutStripFlags ) +{ + // NOTE! NOTE! NOTE! If you are making changes to this function, be aware that it has threading + // NOTE! NOTE! NOTE! implications. It can be called synchronously by the Main thread, + // NOTE! NOTE! NOTE! or by the streaming texture code! + + Assert( pName != NULL ); + Assert( pOutStreamedMips != NULL ); + Assert( pInOutCachedFileLodSettings != NULL ); + + TexDimensions_t actualDims = mappingDims, + allocatedDims; + + const bool bTextureMigration = ( nFlags & TEXTUREFLAGS_STREAMABLE ) != 0; + unsigned int stripFlags = 0; + + int nClampX = actualDims.m_nWidth; // no clamping (clamp to texture dimensions) + int nClampY = actualDims.m_nHeight; + int nClampZ = actualDims.m_nDepth; + + // Fetch LOD settings from the VTF if available + TextureLODControlSettings_t lcs; + memset( &lcs, 0, sizeof( lcs ) ); + TextureLODControlSettings_t const *pLODInfo = NULL; + if ( pOptVTFTexture ) + { + pLODInfo = reinterpret_cast ( + pOptVTFTexture->GetResourceData( VTF_RSRC_TEXTURE_LOD_SETTINGS, NULL ) ); + + // Texture streaming means there are times we call this where we don't have a VTFTexture, even though + // we're a file. So we need to store off the LOD settings whenever we get in here with a file that has them + // so that we can use the correct values for when we don't. Otherwise, the texture will be confused about + // what size to use and everything will die a horrible, horrible death. + if ( pLODInfo ) + ( *pInOutCachedFileLodSettings ) = ( *pLODInfo ); + } + else if ( bTextureMigration ) + { + pLODInfo = pInOutCachedFileLodSettings; + } + + if ( pLODInfo ) + lcs = *pLODInfo; + + // Prepare the default LOD settings (that essentially result in no clamping) + TextureLODControlSettings_t default_lod_settings; + memset( &default_lod_settings, 0, sizeof( default_lod_settings ) ); + { + for ( int w = actualDims.m_nWidth; w > 1; w >>= 1 ) + ++ default_lod_settings.m_ResolutionClampX; + for ( int h = actualDims.m_nHeight; h > 1; h >>= 1 ) + ++ default_lod_settings.m_ResolutionClampY; + } + + // Check for LOD control override + { + TextureLodOverride::OverrideInfo oi = TextureLodOverride::Get( pName ); + + if ( oi.x && oi.y && !pLODInfo ) // If overriding texture that doesn't have lod info yet, then use default + lcs = default_lod_settings; + + lcs.m_ResolutionClampX += oi.x; + lcs.m_ResolutionClampY += oi.y; + if ( int8( lcs.m_ResolutionClampX ) < 0 ) + lcs.m_ResolutionClampX = 0; + if ( int8( lcs.m_ResolutionClampY ) < 0 ) + lcs.m_ResolutionClampY = 0; + } + + // Compute the requested mip0 dimensions + if ( lcs.m_ResolutionClampX && lcs.m_ResolutionClampY ) + { + nClampX = (1 << lcs.m_ResolutionClampX ); + nClampY = (1 << lcs.m_ResolutionClampY ); + } + + // In case clamp values exceed texture dimensions, then fix up + // the clamping values + nClampX = min( nClampX, (int)actualDims.m_nWidth ); + nClampY = min( nClampY, (int)actualDims.m_nHeight ); + + // + // Honor dimension limit restrictions + // + if ( nDesiredDimensionLimit > 0 ) + { + while ( nClampX > nDesiredDimensionLimit || + nClampY > nDesiredDimensionLimit ) + { + nClampX >>= 1; + nClampY >>= 1; + } + } + + // + // Unless ignoring picmip, reflect the global picmip level in clamp dimensions + // + if ( !bIgnorePicmip ) + { + // If picmip requests texture degradation, then honor it + // for loddable textures only + if ( !( nFlags & TEXTUREFLAGS_NOLOD ) && + ( g_config.skipMipLevels > 0 ) ) + { + for ( int iDegrade = 0; iDegrade < g_config.skipMipLevels; ++ iDegrade ) + { + // don't go lower than 4, or dxt textures won't work properly + if ( nClampX > 4 && + nClampY > 4 ) + { + nClampX >>= 1; + nClampY >>= 1; + } + } + } + + // If picmip requests quality upgrade, then always honor it + if ( g_config.skipMipLevels < 0 ) + { + for ( int iUpgrade = 0; iUpgrade < - g_config.skipMipLevels; ++ iUpgrade ) + { + if ( nClampX < actualDims.m_nWidth && + nClampY < actualDims.m_nHeight ) + { + nClampX <<= 1; + nClampY <<= 1; + } + else + break; + } + } + } + + // + // Now use hardware settings to clamp our "clamping dimensions" + // + int iHwWidth = HardwareConfig()->MaxTextureWidth(); + int iHwHeight = HardwareConfig()->MaxTextureHeight(); + int iHwDepth = HardwareConfig()->MaxTextureDepth(); + + nClampX = min( nClampX, max( iHwWidth, 4 ) ); + nClampY = min( nClampY, max( iHwHeight, 4 ) ); + nClampZ = min( nClampZ, max( iHwDepth, 1 ) ); + + // In case clamp values exceed texture dimensions, then fix up + // the clamping values. + nClampX = min( nClampX, (int)actualDims.m_nWidth ); + nClampY = min( nClampY, (int)actualDims.m_nHeight ); + nClampZ = min( nClampZ, (int)actualDims.m_nDepth ); + + // + // Clamp to the determined dimensions + // + int numMipsSkipped = 0; // will compute now when clamping how many mips we drop + while ( ( actualDims.m_nWidth > nClampX ) || + ( actualDims.m_nHeight > nClampY ) || + ( actualDims.m_nDepth > nClampZ ) ) + { + actualDims.m_nWidth >>= 1; + actualDims.m_nHeight >>= 1; + actualDims.m_nDepth = Max( 1, actualDims.m_nDepth >> 1 ); + + ++ numMipsSkipped; + } + + Assert( actualDims.m_nWidth > 0 && actualDims.m_nHeight > 0 && actualDims.m_nDepth > 0 ); + + // Now that we've got the actual size, we can figure out the mip count + actualDims.m_nMipCount = ComputeActualMipCount( actualDims, nFlags ); + + // If we're streaming, cut down what we're loading. + // We can only stream things that have a mipmap pyramid (not just a single mipmap). + bool bHasSetAllocation = false; + if ( ( nFlags & TEXTUREFLAGS_STREAMABLE ) == TEXTUREFLAGS_STREAMABLE_COARSE ) + { + if ( actualDims.m_nMipCount > 1 ) + { + allocatedDims.m_nWidth = actualDims.m_nWidth; + allocatedDims.m_nHeight = actualDims.m_nHeight; + allocatedDims.m_nDepth = actualDims.m_nDepth; + allocatedDims.m_nMipCount = actualDims.m_nMipCount; + + for ( int i = 0; i < STREAMING_START_MIPMAP; ++i ) + { + // Stop when width or height is at 4 pixels (or less). We could do better, + // but some textures really can't function if they're less than 4 pixels (compressed textures, for example). + if ( allocatedDims.m_nWidth <= 4 || allocatedDims.m_nHeight <= 4 ) + break; + + allocatedDims.m_nWidth >>= 1; + allocatedDims.m_nHeight >>= 1; + allocatedDims.m_nDepth = Max( 1, allocatedDims.m_nDepth >> 1 ); + allocatedDims.m_nMipCount = Max( 1, allocatedDims.m_nMipCount - 1 ); + + ++numMipsSkipped; + ++( *pOutStreamedMips ); + } + + bHasSetAllocation = true; + } + else + { + // Clear out that we're streaming, this isn't a texture we can stream. + stripFlags |= TEXTUREFLAGS_STREAMABLE_COARSE; + } + } + + if ( !bHasSetAllocation ) + { + allocatedDims.m_nWidth = actualDims.m_nWidth; + allocatedDims.m_nHeight = actualDims.m_nHeight; + allocatedDims.m_nDepth = actualDims.m_nDepth; + allocatedDims.m_nMipCount = actualDims.m_nMipCount; + } + + if ( pOptOutActualDims ) + *pOptOutActualDims = actualDims; + + if ( pOptOutAllocatedDims ) + *pOptOutAllocatedDims = allocatedDims; + + if ( pOptOutStripFlags ) + ( *pOptOutStripFlags ) = stripFlags; + + // Returns the number we skipped + return numMipsSkipped; +} + +//----------------------------------------------------------------------------- +// Get an optimal read buffer, persists and avoids excessive allocations +//----------------------------------------------------------------------------- +int GetOptimalReadBuffer( CUtlBuffer* pOutOptimalBuffer, FileHandle_t hFile, int nSize ) +{ + // NOTE! NOTE! NOTE! If you are making changes to this function, be aware that it has threading + // NOTE! NOTE! NOTE! implications. It can be called synchronously by the Main thread, + // NOTE! NOTE! NOTE! or by the streaming texture code! + Assert( GetThreadId() < MAX_RENDER_THREADS ); + + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s (%d bytes)", __FUNCTION__, nSize ); + Assert( pOutOptimalBuffer != NULL ); + + // get an optimal read buffer, only resize if necessary + const int minSize = 2 * 1024 * 1024; // Uses 2MB min to avoid fragmentation + nSize = max( nSize, minSize ); + int nBytesOptimalRead = g_pFullFileSystem->GetOptimalReadSize( hFile, nSize ); + + const int ti = GetThreadId(); + + if ( nBytesOptimalRead > s_nOptimalReadBufferSize[ ti ] ) + { + FreeOptimalReadBuffer( 0 ); + + s_nOptimalReadBufferSize[ ti ] = nBytesOptimalRead; + s_pOptimalReadBuffer[ ti ] = g_pFullFileSystem->AllocOptimalReadBuffer( hFile, nSize ); + if ( mat_spewalloc.GetBool() ) + { + Msg( "Allocated optimal read buffer of %d bytes @ 0x%p for thread %d\n", s_nOptimalReadBufferSize[ ti ], s_pOptimalReadBuffer[ ti ], ti ); + } + } + + // set external buffer and reset to empty + ( *pOutOptimalBuffer ).SetExternalBuffer( s_pOptimalReadBuffer[ ti ], s_nOptimalReadBufferSize[ ti ], 0 ); + + // return the optimal read size + return nBytesOptimalRead; +} + +//----------------------------------------------------------------------------- +// Free the optimal read buffer if it grows too large +//----------------------------------------------------------------------------- +void FreeOptimalReadBuffer( int nMaxSize ) +{ + // NOTE! NOTE! NOTE! If you are making changes to this function, be aware that it has threading + // NOTE! NOTE! NOTE! implications. It can be called synchronously by the Main thread, + // NOTE! NOTE! NOTE! or by the streaming texture code! + Assert( GetThreadId() < MAX_RENDER_THREADS ); + + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s", __FUNCTION__ ); + + const int ti = GetThreadId(); + + if ( s_pOptimalReadBuffer[ ti ] && s_nOptimalReadBufferSize[ ti ] >= nMaxSize ) + { + if ( mat_spewalloc.GetBool() ) + { + Msg( "Freeing optimal read buffer of %d bytes @ 0x%p for thread %d\n", s_nOptimalReadBufferSize[ ti ], s_pOptimalReadBuffer[ ti ], ti ); + } + g_pFullFileSystem->FreeOptimalReadBuffer( s_pOptimalReadBuffer[ ti ] ); + s_pOptimalReadBuffer[ ti ] = NULL; + s_nOptimalReadBufferSize[ ti ] = 0; + } +} + + +#if defined( STAGING_ONLY ) + CON_COMMAND( dumptexallocs, "List currently allocated textures and properties about them" ) + { + Msg( "Texture Memory Statistics follow:\n" ); + uint64 totalTexMemAllocated = 0; + FOR_EACH_MAP_FAST( g_currentTextures, i ) + { + const TexInfo_t& tex = g_currentTextures[ i ]; + uint64 thisTexMem = tex.ComputeTexSize(); + + totalTexMemAllocated += thisTexMem; + Msg( "%s: %llu bytes\n", ( const char * ) tex.m_Name, thisTexMem ); + } + + Msg( "Total Memory Allocated: %llu bytes\n", totalTexMemAllocated ); + } +#endif + + +////////////////////////////////////////////////////////////////////////// +// +// Saving all the texture LOD modifications to content +// +////////////////////////////////////////////////////////////////////////// + +#ifdef IS_WINDOWS_PC +static bool SetBufferValue( char *chTxtFileBuffer, char const *szLookupKey, char const *szNewValue ) +{ + bool bResult = false; + + size_t lenTmp = strlen( szNewValue ); + size_t nTxtFileBufferLen = strlen( chTxtFileBuffer ); + + for ( char *pch = chTxtFileBuffer; + ( NULL != ( pch = strstr( pch, szLookupKey ) ) ); + ++ pch ) + { + char *val = pch + strlen( szLookupKey ); + if ( !V_isspace( *val ) ) + continue; + else + ++ val; + char *pValStart = val; + + // Okay, here comes the value + while ( *val && V_isspace( *val ) ) + ++ val; + while ( *val && !V_isspace( *val ) ) + ++ val; + + char *pValEnd = val; // Okay, here ends the value + + memmove( pValStart + lenTmp, pValEnd, chTxtFileBuffer + nTxtFileBufferLen + 1 - pValEnd ); + memcpy( pValStart, szNewValue, lenTmp ); + + nTxtFileBufferLen += ( lenTmp - ( pValEnd - pValStart ) ); + bResult = true; + } + + if ( !bResult ) + { + char *pchAdd = chTxtFileBuffer + nTxtFileBufferLen; + strcpy( pchAdd + strlen( pchAdd ), "\n" ); + strcpy( pchAdd + strlen( pchAdd ), szLookupKey ); + strcpy( pchAdd + strlen( pchAdd ), " " ); + strcpy( pchAdd + strlen( pchAdd ), szNewValue ); + strcpy( pchAdd + strlen( pchAdd ), "\n" ); + bResult = true; + } + + return bResult; +} + +// Replaces the first occurrence of "szFindData" with "szNewData" +// Returns the remaining buffer past the replaced data or NULL if +// no replacement occurred. +static char * BufferReplace( char *buf, char const *szFindData, char const *szNewData ) +{ + size_t len = strlen( buf ), lFind = strlen( szFindData ), lNew = strlen( szNewData ); + if ( char *pBegin = strstr( buf, szFindData ) ) + { + memmove( pBegin + lNew, pBegin + lFind, buf + len - ( pBegin + lFind ) ); + memmove( pBegin, szNewData, lNew ); + return pBegin + lNew; + } + return NULL; +} + + +class CP4Requirement +{ +public: + CP4Requirement(); + ~CP4Requirement(); + +protected: + bool m_bLoadedModule; + CSysModule *m_pP4Module; +}; + +CP4Requirement::CP4Requirement() : + m_bLoadedModule( false ), + m_pP4Module( NULL ) +{ +#ifdef STAGING_ONLY + if ( p4 ) + return; + + // load the p4 lib + m_pP4Module = Sys_LoadModule( "p4lib" ); + m_bLoadedModule = true; + + if ( m_pP4Module ) + { + CreateInterfaceFn factory = Sys_GetFactory( m_pP4Module ); + if ( factory ) + { + p4 = ( IP4 * )factory( P4_INTERFACE_VERSION, NULL ); + + if ( p4 ) + { + extern CreateInterfaceFn g_fnMatSystemConnectCreateInterface; + p4->Connect( g_fnMatSystemConnectCreateInterface ); + p4->Init(); + } + } + } +#endif // STAGING_ONLY + + if ( !p4 ) + { + Warning( "Can't load p4lib.dll\n" ); + } +} + +CP4Requirement::~CP4Requirement() +{ + if ( m_bLoadedModule && m_pP4Module ) + { + if ( p4 ) + { + p4->Shutdown(); + p4->Disconnect(); + } + + Sys_UnloadModule( m_pP4Module ); + m_pP4Module = NULL; + p4 = NULL; + } +} + +static ConVar mat_texture_list_content_path( "mat_texture_list_content_path", "", FCVAR_ARCHIVE, "The content path to the materialsrc directory. If left unset, it'll assume your content directory is next to the currently running game dir." ); + +CON_COMMAND_F( mat_texture_list_txlod_sync, "'reset' - resets all run-time changes to LOD overrides, 'save' - saves all changes to material content files", FCVAR_DONTRECORD ) +{ + using namespace TextureLodOverride; + + if ( args.ArgC() != 2 ) + goto usage; + + char const *szCmd = args.Arg( 1 ); + Msg( "mat_texture_list_txlod_sync %s...\n", szCmd ); + + if ( !stricmp( szCmd, "reset" ) ) + { + for ( int k = 0; k < s_OverrideMap.GetNumStrings(); ++ k ) + { + char const *szTx = s_OverrideMap.String( k ); + s_OverrideMap[ k ] = OverrideInfo(); // Reset the override info + + // Force the texture LOD override to get re-processed + if ( ITexture *pTx = materials->FindTexture( szTx, "" ) ) + pTx->ForceLODOverride( 0 ); + else + Warning( " mat_texture_list_txlod_sync reset - texture '%s' no longer found.\n", szTx ); + } + + s_OverrideMap.Purge(); + Msg("mat_texture_list_txlod_sync reset : completed.\n"); + return; + } + else if ( !stricmp( szCmd, "save" ) ) + { + CP4Requirement p4req; + if ( !p4 ) + g_p4factory->SetDummyMode( true ); + + for ( int k = 0; k < s_OverrideMap.GetNumStrings(); ++ k ) + { + char const *szTx = s_OverrideMap.String( k ); + OverrideInfo oi = s_OverrideMap[ k ]; + ITexture *pTx = materials->FindTexture( szTx, "" ); + + if ( !oi.x || !oi.y ) + continue; + + if ( !pTx ) + { + Warning( " mat_texture_list_txlod_sync save - texture '%s' no longer found.\n", szTx ); + continue; + } + + int iMaxWidth = pTx->GetActualWidth(), iMaxHeight = pTx->GetActualHeight(); + + // Save maxwidth and maxheight + char chMaxWidth[20], chMaxHeight[20]; + sprintf( chMaxWidth, "%d", iMaxWidth ), sprintf( chMaxHeight, "%d", iMaxHeight ); + + // We have the texture and path to its content + char chResolveName[ MAX_PATH ] = {0}, chResolveNameArg[ MAX_PATH ] = {0}; + Q_snprintf( chResolveNameArg, sizeof( chResolveNameArg ) - 1, "materials/%s" TEXTURE_FNAME_EXTENSION, szTx ); + char *szTextureContentPath; + if ( !mat_texture_list_content_path.GetString()[0] ) + { + szTextureContentPath = const_cast< char * >( g_pFullFileSystem->RelativePathToFullPath( chResolveNameArg, "game", chResolveName, sizeof( chResolveName ) - 1 ) ); + + if ( !szTextureContentPath ) + { + Warning( " mat_texture_list_txlod_sync save - texture '%s' is not loaded from file system.\n", szTx ); + continue; + } + if ( !BufferReplace( szTextureContentPath, "\\game\\", "\\content\\" ) || + !BufferReplace( szTextureContentPath, "\\materials\\", "\\materialsrc\\" ) ) + { + Warning( " mat_texture_list_txlod_sync save - texture '%s' cannot be mapped to content directory.\n", szTx ); + continue; + } + } + else + { + V_strncpy( chResolveName, mat_texture_list_content_path.GetString(), MAX_PATH ); + V_strncat( chResolveName, "/", MAX_PATH ); + V_strncat( chResolveName, szTx, MAX_PATH ); + V_strncat( chResolveName, TEXTURE_FNAME_EXTENSION, MAX_PATH ); + + szTextureContentPath = chResolveName; + } + + // Figure out what kind of source content is there: + // 1. look for TGA - if found, get the txt file (if txt file missing, create one) + // 2. otherwise look for PSD - affecting psdinfo + // 3. else error + char *pExtPut = szTextureContentPath + strlen( szTextureContentPath ) - strlen( TEXTURE_FNAME_EXTENSION ); // compensating the TEXTURE_FNAME_EXTENSION(.vtf) extension + + // 1.tga + sprintf( pExtPut, ".tga" ); + if ( g_pFullFileSystem->FileExists( szTextureContentPath ) ) + { + // Have tga - pump in the txt file + sprintf( pExtPut, ".txt" ); + + CUtlBuffer bufTxtFileBuffer( 0, 0, CUtlBuffer::TEXT_BUFFER ); + g_pFullFileSystem->ReadFile( szTextureContentPath, 0, bufTxtFileBuffer ); + for ( int kCh = 0; kCh < 1024; ++kCh ) bufTxtFileBuffer.PutChar( 0 ); + + // Now fix maxwidth/maxheight settings + SetBufferValue( ( char * ) bufTxtFileBuffer.Base(), "maxwidth", chMaxWidth ); + SetBufferValue( ( char * ) bufTxtFileBuffer.Base(), "maxheight", chMaxHeight ); + bufTxtFileBuffer.SeekPut( CUtlBuffer::SEEK_HEAD, strlen( ( char * ) bufTxtFileBuffer.Base() ) ); + + // Check out or add the file + g_p4factory->SetOpenFileChangeList( "Texture LOD Autocheckout" ); + CP4AutoEditFile autop4_edit( szTextureContentPath ); + + // Save the file contents + if ( g_pFullFileSystem->WriteFile( szTextureContentPath, 0, bufTxtFileBuffer ) ) + { + Msg(" '%s' : saved.\n", szTextureContentPath ); + CP4AutoAddFile autop4_add( szTextureContentPath ); + } + else + { + Warning( " '%s' : failed to save - set \"maxwidth %d maxheight %d\" manually.\n", + szTextureContentPath, iMaxWidth, iMaxHeight ); + } + + continue; + } + + // 2.psd + sprintf( pExtPut, ".psd" ); + if ( g_pFullFileSystem->FileExists( szTextureContentPath ) ) + { + char chCommand[MAX_PATH]; + char szTxtFileName[MAX_PATH] = {0}; + GetModSubdirectory( "tmp_lod_psdinfo.txt", szTxtFileName, sizeof( szTxtFileName ) ); + sprintf( chCommand, "/C psdinfo \"%s\" > \"%s\"", szTextureContentPath, szTxtFileName); + ShellExecute( NULL, NULL, "cmd.exe", chCommand, NULL, SW_HIDE ); + Sleep( 200 ); + + CUtlBuffer bufTxtFileBuffer( 0, 0, CUtlBuffer::TEXT_BUFFER ); + g_pFullFileSystem->ReadFile( szTxtFileName, 0, bufTxtFileBuffer ); + for ( int kCh = 0; kCh < 1024; ++ kCh ) bufTxtFileBuffer.PutChar( 0 ); + + // Now fix maxwidth/maxheight settings + SetBufferValue( ( char * ) bufTxtFileBuffer.Base(), "maxwidth", chMaxWidth ); + SetBufferValue( ( char * ) bufTxtFileBuffer.Base(), "maxheight", chMaxHeight ); + bufTxtFileBuffer.SeekPut( CUtlBuffer::SEEK_HEAD, strlen( ( char * ) bufTxtFileBuffer.Base() ) ); + + // Check out or add the file + // Save the file contents + if ( g_pFullFileSystem->WriteFile( szTxtFileName, 0, bufTxtFileBuffer ) ) + { + g_p4factory->SetOpenFileChangeList( "Texture LOD Autocheckout" ); + CP4AutoEditFile autop4_edit( szTextureContentPath ); + + sprintf( chCommand, "/C psdinfo -write \"%s\" < \"%s\"", szTextureContentPath, szTxtFileName ); + Sleep( 200 ); + ShellExecute( NULL, NULL, "cmd.exe", chCommand, NULL, SW_HIDE ); + Sleep( 200 ); + + Msg(" '%s' : saved.\n", szTextureContentPath ); + CP4AutoAddFile autop4_add( szTextureContentPath ); + } + else + { + Warning( " '%s' : failed to save - set \"maxwidth %d maxheight %d\" manually.\n", + szTextureContentPath, iMaxWidth, iMaxHeight ); + } + + continue; + } + + // 3. - error + sprintf( pExtPut, "" ); + { + Warning( " '%s' : doesn't specify a valid TGA or PSD file!\n", szTextureContentPath ); + continue; + } + } + + Msg("mat_texture_list_txlod_sync save : completed.\n"); + return; + } + else + goto usage; + + return; + +usage: + Warning( + "Usage:\n" + " mat_texture_list_txlod_sync reset - resets all run-time changes to LOD overrides;\n" + " mat_texture_list_txlod_sync save - saves all changes to material content files.\n" + ); +} +#endif diff --git a/materialsystem/ctexturecompositor.cpp b/materialsystem/ctexturecompositor.cpp new file mode 100644 index 0000000..88683b1 --- /dev/null +++ b/materialsystem/ctexturecompositor.cpp @@ -0,0 +1,2842 @@ +//========= Copyright Valve Corporation, All rights reserved. ================================== // +// +// Purpose: +// +//============================================================================================== // + +#include "pch_materialsystem.h" +#include "ctexturecompositor.h" + +#include "materialsystem/itexture.h" +#include "materialsystem/imaterialsystem.h" +#include "materialsystem/combineoperations.h" +#include "texturemanager.h" + +#define MATSYS_INTERNAL // Naughty! +#include "cmaterialsystem.h" + +#include "tier0/memdbgon.h" + +#ifndef _WINDOWS +#define sscanf_s sscanf +#endif + +// If this is 0 or unset, we won't use the caching functionality. +#define WITH_TEX_COMPOSITE_CACHE 1 + +#ifdef STAGING_ONLY // Always should remain staging only. + ConVar r_texcomp_dump( "r_texcomp_dump", "0", FCVAR_NONE, "Whether we should dump the textures to disk or not. 1: Save all; 2: Save Final; 3: Save Final with name suitable for scripting; 4: Save Final and skip saving workshop icons." ); +#endif + +const int cMaxSelectors = 16; + +// Ugh, this is annoying and matches TF's enums. That's lame. We should workaround this. +enum { Neutral = 0, Red = 2, Blue = 3 }; + +static int s_nDumpCount = 0; +static CInterlockedInt s_nCompositeCount = 0; + +void ComputeTextureMatrixFromRectangle( VMatrix* pOutMat, const Vector2D& bl, const Vector2D& tl, const Vector2D& tr ); +bool HasCycle( CTextureCompositorTemplate* pStartTempl ); +CTextureCompositorTemplate* Advance( CTextureCompositorTemplate* pTmpl, int nSteps ); +void PrintMinimumCycle( CTextureCompositorTemplate* pStartTempl ); + +// ------------------------------------------------------------------------------------------------ +// ------------------------------------------------------------------------------------------------ +// ------------------------------------------------------------------------------------------------ +struct CTCStageResult_t +{ + ITexture* m_pTexture; + ITexture* m_pRenderTarget; + + float m_fAdjustBlackPoint; + float m_fAdjustWhitePoint; + float m_fAdjustGamma; + + matrix3x4_t m_mUvAdjust; + + inline CTCStageResult_t() + : m_pTexture(NULL) + , m_pRenderTarget(NULL) + , m_fAdjustBlackPoint(0.0f) + , m_fAdjustWhitePoint(1.0f) + , m_fAdjustGamma(1.0f) + { + SetIdentityMatrix( m_mUvAdjust ); + } + + inline void Cleanup( CTextureCompositor* _comp ) + { + if ( m_pRenderTarget ) + _comp->ReleaseCompositorRenderTarget( m_pRenderTarget ); + + m_pTexture = NULL; + m_pRenderTarget = NULL; + } +}; + +// ------------------------------------------------------------------------------------------------ +// ------------------------------------------------------------------------------------------------ +// ------------------------------------------------------------------------------------------------ +class CTCStage : public IAsyncTextureOperationReceiver +{ +public: + CTCStage(); + +protected: + // Called by Release() + virtual ~CTCStage(); + +public: + // IAsyncTextureOperationReceiver + virtual int AddRef() OVERRIDE; + virtual int Release() OVERRIDE; + virtual int GetRefCount() const OVERRIDE { return m_nReferenceCount; } + virtual void OnAsyncCreateComplete( ITexture* pTex, void* pExtraArgs ) OVERRIDE { } + virtual void OnAsyncFindComplete( ITexture* pTex, void* pExtraArgs ) OVERRIDE { } + virtual void OnAsyncMapComplete( ITexture* pTex, void* pExtraArgs, void* pMemory, int pPitch ) OVERRIDE { } + virtual void OnAsyncReadbackBegin( ITexture* pDst, ITexture* pSrc, void* pExtraArgs ) OVERRIDE { } + + + // Our stuff. + void Resolve( bool bFirstTime, CTextureCompositor* _comp ); + inline ECompositeResolveStatus GetResolveStatus() const { return m_ResolveStatus; } + inline const CTCStageResult_t& GetResult() const { Assert( GetResolveStatus() == ECRS_Complete ); return m_Result; } + + bool HasTeamSpecifics() const; + void ComputeRandomValues( int* pCurIndex, CUniformRandomStream* pRNGs, int nRNGCount ); + + inline void SetFirstChild( CTCStage* _stage ) { m_pFirstChild = _stage; } + inline void SetNextSibling( CTCStage* _stage ) { m_pNextSibling = _stage; } + + inline CTCStage* GetFirstChild() { return m_pFirstChild; } + inline CTCStage* GetNextSibling() { return m_pNextSibling; } + + inline const CTCStage* GetFirstChild() const { return m_pFirstChild; } + inline const CTCStage* GetNextSibling() const { return m_pNextSibling; } + + void AppendChildren( const CUtlVector< CTCStage* >& _children ) + { + // Do these in reverse order, they will wind up in the right order + FOR_EACH_VEC_BACK( _children, i ) + { + CTCStage* childStage = _children[i]; + childStage->SetNextSibling( GetFirstChild() ); + SetFirstChild( childStage ); + } + } + + void CleanupChildResults( CTextureCompositor* _comp ); + + // Render a quad with _mat using _inputs to _destRT + void Render( ITexture* _destRT, IMaterial* _mat, const CUtlVector& _inputs, CTextureCompositor* _comp, bool bClear ); + + void Cleanup( CTextureCompositor* _comp ); + + // Does this stage target a render target or a texture? + virtual bool DoesTargetRenderTarget() const = 0; + + inline void SetResult( const CTCStageResult_t& _result ) + { + Assert( m_ResolveStatus != ECRS_Complete ); + m_Result = _result; + m_ResolveStatus = ECRS_Complete; + } + +protected: + + inline void SetResolveStatus( ECompositeResolveStatus _status ) + { + m_ResolveStatus = _status; + } + + // This function is called only once during the first ResolveTraversal, and is + // for the compositor to request its textures. Textures should not be requested + // before this or they can be held waaaay too long. + virtual void RequestTextures() = 0; + + // This function will be called during Resolve traversal. At the point when this is called, + // all of this node's children will have had their resolve completed. Our siblings will + // not have resolved yet. + virtual void ResolveThis( CTextureCompositor* _comp ) = 0; + + // This function is called during HasTeamSpecifics traversal. + virtual bool HasTeamSpecificsThis() const = 0; + + virtual bool ComputeRandomValuesThis( CUniformRandomStream* pRNG ) = 0; + +private: + CInterlockedInt m_nReferenceCount; + + CTCStage* m_pFirstChild; + CTCStage* m_pNextSibling; + + CTCStageResult_t m_Result; + ECompositeResolveStatus m_ResolveStatus; +}; + +// ------------------------------------------------------------------------------------------------ +// ------------------------------------------------------------------------------------------------ +// ------------------------------------------------------------------------------------------------ +typedef void ( *ParseSingleKV )( KeyValues* _kv, void* _dest ); +struct ParseTableEntry +{ + const char* keyName; + ParseSingleKV parseFunc; + size_t structOffset; +}; + +// ------------------------------------------------------------------------------------------------ +struct Range +{ + float low; + float high; + + Range( ) + : low( 0 ) + , high( 0 ) + { } + + Range( float _l, float _h ) + : low( _l ) + , high( _h ) + { } +}; + +// ------------------------------------------------------------------------------------------------ +// ------------------------------------------------------------------------------------------------ +// ------------------------------------------------------------------------------------------------ +void ParseBoolFromKV( KeyValues* _kv, void* _pDest ) +{ + bool* realDest = ( bool* ) _pDest; + ( *realDest ) = _kv->GetBool(); +} + +// ------------------------------------------------------------------------------------------------ +template +void ParseIntVectorFromKV( KeyValues* _kv, void* _pDest ) +{ + CCopyableUtlVector* realDest = ( CCopyableUtlVector* ) _pDest; + const int parsedValue = _kv->GetInt(); + if ( realDest->Size() < N ) + { + realDest->AddToTail( parsedValue ); + } + else + { + DevWarning( "Too many numbers (>%d), ignoring the value '%d'.\n", N, parsedValue ); + } +} + +// ------------------------------------------------------------------------------------------------ +template< class T > +CUtlString AsStringT( const T& _val ) +{ +#ifdef _WIN32 + // Not sure why linux is unhappy here. Error messages unhelpful. Thanks, GCC. + static_assert( false, "Must add specialization for typename T" ); +#endif + return CUtlString( "" ); +} + +// ------------------------------------------------------------------------------------------------ +template<> +CUtlString AsStringT< int >( const int& _val ) +{ + char buffer[ 12 ]; + V_sprintf_safe( buffer, "%d", _val ); + return CUtlString( buffer ); +} + +// ------------------------------------------------------------------------------------------------ +template< class T > +void ParseTFromKV( KeyValues* _kv, void* _pDest ) +{ +#ifdef _WIN32 + // Not sure why linux is unhappy here. Error messages unhelpful. Thanks, GCC. + static_assert( false, "Must add specialization for typename T" ); +#endif +} + +// ------------------------------------------------------------------------------------------------ +template<> +void ParseTFromKV< int >( KeyValues* _kv, void* _pDest ) +{ + int* realDest = ( int* ) _pDest; + ( *realDest ) = _kv->GetInt(); +} + +// ------------------------------------------------------------------------------------------------ +template<> +void ParseTFromKV< Vector2D >( KeyValues* _kv, void* _pDest ) +{ + Vector2D* realDest = ( Vector2D* ) _pDest; + Vector2D tmpDest; + int count = sscanf_s( _kv->GetString(), "%f %f", &tmpDest.x, &tmpDest.y ); + if ( count != 2 ) + { + Error( "Expected exactly two values, %d were provided.\n", count ); + return; + } + + *realDest = tmpDest; +} + +// ------------------------------------------------------------------------------------------------ +template< class T, int N = INT_MAX > +void ParseVectorFromKV( KeyValues* _kv, void* _pDest ) +{ + CCopyableUtlVector< T >* realDest = ( CCopyableUtlVector< T >* ) _pDest; + + T parsedValue = T(); + ParseTFromKV( _kv, &parsedValue ); + + if ( realDest->Size() < N ) + { + realDest->AddToTail( parsedValue ); + } + else + { + DevWarning( "Too many entries (>%d), ignoring the value '%s'.\n", N, AsStringT( parsedValue ).Get() ); + } +} + +// ------------------------------------------------------------------------------------------------ +void ParseRangeFromKV( KeyValues* _kv, void* _pDest ) +{ + Range* realDest = ( Range* ) _pDest; + Range tmpDest; + + int count = sscanf_s( _kv->GetString(), "%f %f", &tmpDest.low, &tmpDest.high ); + switch (count) + { + case 1: + // If we parse one, use the same value for low and high. + ( *realDest ).low = tmpDest.low; + ( *realDest ).high = tmpDest.low; + break; + case 2: + // If we parse two, they're both correct. + ( *realDest ).low = tmpDest.low; + ( *realDest ).high = tmpDest.high; + break; + + // error cases + case EOF: + case 0: + default: + Error( "Incorrect number of numbers while parsing, using defaults. This error message should be improved\n" ); + }; +} + +// ------------------------------------------------------------------------------------------------ +void ParseInverseRangeFromKV( KeyValues* _kv, void* _pDest ) +{ + const float kSubstValue = 0.00001; + ParseRangeFromKV( _kv, _pDest ); + Range* realDest = ( Range* ) _pDest; + + if ( realDest->low != 0.0f ) + { + ( *realDest ).low = 1.0f / realDest->low; + } + else + { + Error( "Specified 0.0 for low value, that is illegal in this field. Substituting %.5f\n", kSubstValue ); + ( *realDest ).low = kSubstValue; + } + + if ( realDest->high != 0.0f ) + { + ( *realDest ).high = 1.0f / realDest->high; + } + else + { + Error( "Specified 0.0 for high value, that is illegal in this field. Substituting %.5f\n", kSubstValue ); + ( *realDest ).high = kSubstValue; + } +} + +// ------------------------------------------------------------------------------------------------ +template < int Div > +void ParseRangeThenDivideBy( KeyValues *_kv, void* _pDest ) +{ + static_assert( Div != 0, "Cannot specify a divisor of 0." ); + float fDiv = (float) Div; + + ParseRangeFromKV( _kv, _pDest ); + Range* realDest = ( Range* ) _pDest; + + ( *realDest ).low = ( *realDest ).low / fDiv; + ( *realDest ).high = ( *realDest ).high / fDiv; +} + +// ------------------------------------------------------------------------------------------------ +void ParseStringFromKV( KeyValues* _kv, void* _pDest ) +{ + CUtlString* realDest = ( CUtlString* ) _pDest; + (*realDest) = _kv->GetString(); +} + +// ------------------------------------------------------------------------------------------------ +struct TextureStageParameters +{ + CUtlString m_pTexFilename; + CUtlString m_pTexRedFilename; + CUtlString m_pTexBlueFilename; + Range m_AdjustBlack; + Range m_AdjustOffset; + Range m_AdjustGamma; + + Range m_Rotation; + Range m_TranslateU; + Range m_TranslateV; + Range m_ScaleUV; + bool m_AllowFlipU; + bool m_AllowFlipV; + bool m_Evaluate; + + TextureStageParameters() + : m_AdjustBlack( 0, 0 ) + , m_AdjustOffset( 1, 1 ) + , m_AdjustGamma( 1, 1 ) + , m_Rotation( 0 , 0 ) + , m_TranslateU( 0, 0 ) + , m_TranslateV( 0, 0 ) + , m_ScaleUV( 1, 1 ) + , m_AllowFlipU( false ) + , m_AllowFlipV( false ) + , m_Evaluate( true ) + { } +}; + +// ------------------------------------------------------------------------------------------------ +const ParseTableEntry cTextureStageParametersParseTable[] = +{ + { "texture", ParseStringFromKV, offsetof( TextureStageParameters, m_pTexFilename ) }, + { "texture_red", ParseStringFromKV, offsetof( TextureStageParameters, m_pTexRedFilename ) }, + { "texture_blue", ParseStringFromKV, offsetof( TextureStageParameters, m_pTexBlueFilename ) }, + { "adjust_black", ParseRangeThenDivideBy<255>, offsetof( TextureStageParameters, m_AdjustBlack ) }, + { "adjust_offset", ParseRangeThenDivideBy<255>, offsetof( TextureStageParameters, m_AdjustOffset ) }, + { "adjust_gamma", ParseInverseRangeFromKV, offsetof( TextureStageParameters, m_AdjustGamma ) }, + { "rotation", ParseRangeFromKV, offsetof( TextureStageParameters, m_Rotation ) }, + { "translate_u", ParseRangeFromKV, offsetof( TextureStageParameters, m_TranslateU ) }, + { "translate_v", ParseRangeFromKV, offsetof( TextureStageParameters, m_TranslateV ) }, + { "scale_uv", ParseRangeFromKV, offsetof( TextureStageParameters, m_ScaleUV ) }, + { "flip_u", ParseBoolFromKV, offsetof( TextureStageParameters, m_AllowFlipU ) }, + { "flip_v", ParseBoolFromKV, offsetof( TextureStageParameters, m_AllowFlipV ) }, + { "evaluate?", ParseBoolFromKV, offsetof( TextureStageParameters, m_Evaluate ) }, + + { 0, 0 } +}; + + // ------------------------------------------------------------------------------------------------ + // ------------------------------------------------------------------------------------------------ + // ------------------------------------------------------------------------------------------------ +class CTCTextureStage : public CTCStage +{ +public: + CTCTextureStage( const TextureStageParameters& _tsp, uint32 nTexCompositeCreateFlags ) + : m_Parameters( _tsp ) + , m_pTex( NULL ) + , m_pTexRed( NULL ) + , m_pTexBlue( NULL ) + { + } + + virtual ~CTCTextureStage() + { + SafeRelease( &m_pTex ); + SafeRelease( &m_pTexBlue ); + SafeRelease( &m_pTexRed ); + } + + virtual void OnAsyncFindComplete( ITexture* pTex, void* pExtraArgs ) + { + switch ( ( int ) pExtraArgs ) + { + case Neutral: + SafeAssign( &m_pTex, pTex ); + break; + case Red: + SafeAssign( &m_pTexRed, pTex ); + break; + case Blue: + SafeAssign( &m_pTexBlue, pTex ); + break; + default: + Assert( !"Unexpected value passed to OnAsyncFindComplete" ); + break; + }; + } + + virtual bool DoesTargetRenderTarget() const { return false; } + +protected: + bool AreTexturesLoaded() const + { + if ( !m_Parameters.m_pTexFilename.IsEmpty() && !m_pTex ) + return false; + + if ( !m_Parameters.m_pTexRedFilename.IsEmpty() && !m_pTexRed ) + return false; + + if ( !m_Parameters.m_pTexBlueFilename.IsEmpty() && !m_pTexBlue ) + return false; + + return true; + } + + ITexture* GetTeamSpecificTexture( int nTeam ) + { + if ( nTeam == Red && m_pTexRed ) + return m_pTexRed; + + if ( nTeam == Blue && m_pTexBlue ) + return m_pTexBlue; + + return m_pTex; + } + + virtual void RequestTextures() + { + if ( !m_Parameters.m_pTexFilename.IsEmpty() ) + materials->AsyncFindTexture( m_Parameters.m_pTexFilename.Get(), TEXTURE_GROUP_RUNTIME_COMPOSITE, this, ( void* ) Neutral, false, TEXTUREFLAGS_IMMEDIATE_CLEANUP ); + if ( !m_Parameters.m_pTexRedFilename.IsEmpty() ) + materials->AsyncFindTexture( m_Parameters.m_pTexRedFilename.Get(), TEXTURE_GROUP_RUNTIME_COMPOSITE, this, ( void* ) Red, false, TEXTUREFLAGS_IMMEDIATE_CLEANUP ); + if ( !m_Parameters.m_pTexBlueFilename.IsEmpty() ) + materials->AsyncFindTexture( m_Parameters.m_pTexBlueFilename.Get(), TEXTURE_GROUP_RUNTIME_COMPOSITE, this, ( void* ) Blue, false, TEXTUREFLAGS_IMMEDIATE_CLEANUP ); + } + + virtual void ResolveThis( CTextureCompositor* _comp ) + { + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s", __FUNCTION__ ); + + // We shouldn't have any children, we're going to ignore them anyways. + Assert( GetFirstChild() == NULL ); + + ECompositeResolveStatus resolveStatus = GetResolveStatus(); + // If we're done, we're done. + if ( resolveStatus == ECRS_Complete || resolveStatus == ECRS_Error ) + return; + + if ( resolveStatus == ECRS_Scheduled ) + SetResolveStatus( ECRS_PendingTextureLoads ); + + // Someone is misusing this node if this assert fires. + Assert( GetResolveStatus() == ECRS_PendingTextureLoads ); + + // When the texture has finished loading, this will be set to the texture we should use. + if ( !AreTexturesLoaded() ) + return; + + if ( !m_pTex && !m_pTexRed && !m_pTexBlue ) + { + _comp->Error( false, "Invalid texture_lookup node, must specify at least texture (or texture_red and texture_blue) or all of them.\n" ); + return; + } + + if ( m_pTex && m_pTex->IsError() ) + { + _comp->Error( false, "Failed to load texture '%s', this is non-recoverable.\n", m_Parameters.m_pTexFilename.Get() ); + return; + } + + if ( m_pTexRed && m_pTexRed->IsError() ) + { + _comp->Error( false, "Failed to load texture_red '%s', this is non-recoverable.\n", m_Parameters.m_pTexRedFilename.Get() ); + return; + } + + if ( m_pTexBlue && m_pTexBlue->IsError() ) + { + _comp->Error( false, "Failed to load texture_blue '%s', this is non-recoverable.\n", m_Parameters.m_pTexBlueFilename.Get() ); + return; + } + + CTCStageResult_t res; + res.m_pTexture = GetTeamSpecificTexture( _comp->GetTeamNumber() ); + res.m_fAdjustBlackPoint = m_fAdjustBlack; + res.m_fAdjustWhitePoint = m_fAdjustWhite; + res.m_fAdjustGamma = m_fAdjustGamma; + // Store the matrix into the uv adjustment matrix + m_mTextureAdjust.Set3x4( res.m_mUvAdjust ); + + SetResult( res ); + + CleanupChildResults( _comp ); + tmMessage( TELEMETRY_LEVEL0, TMMF_ICON_NOTE, "Completed: %s", __FUNCTION__ ); + } + + virtual bool HasTeamSpecificsThis() const OVERRIDE + { + return !m_Parameters.m_pTexBlueFilename.IsEmpty(); + } + + virtual bool ComputeRandomValuesThis( CUniformRandomStream* pRNG ) OVERRIDE + { + // If you change the order of these random numbers being generated, or add new ones, you will + // change the look of existing players' weapons! Don't do that. + const bool shouldFlipU = m_Parameters.m_AllowFlipU ? pRNG->RandomInt( 0, 1 ) != 0 : false; + const bool shouldFlipV = m_Parameters.m_AllowFlipV ? pRNG->RandomInt( 0, 1 ) != 0 : false; + const float translateU = pRNG->RandomFloat( m_Parameters.m_TranslateU.low, m_Parameters.m_TranslateU.high ); + const float translateV = pRNG->RandomFloat( m_Parameters.m_TranslateV.low, m_Parameters.m_TranslateV.high ); + const float rotation = pRNG->RandomFloat( m_Parameters.m_Rotation.low, m_Parameters.m_Rotation.high ); + const float scaleUV = pRNG->RandomFloat( m_Parameters.m_ScaleUV.low, m_Parameters.m_ScaleUV.high ); + + const float adjustBlack = pRNG->RandomFloat( m_Parameters.m_AdjustBlack.low, m_Parameters.m_AdjustBlack.high ); + const float adjustOffset = pRNG->RandomFloat( m_Parameters.m_AdjustOffset.low, m_Parameters.m_AdjustOffset.high ); + const float adjustGamma = pRNG->RandomFloat( m_Parameters.m_AdjustGamma.low, m_Parameters.m_AdjustGamma.high ); + const float adjustWhite = adjustBlack + adjustOffset; + + m_fAdjustBlack = adjustBlack; + m_fAdjustWhite = adjustWhite; + m_fAdjustGamma = adjustGamma; + + const float finalScaleU = scaleUV * ( shouldFlipU ? -1.0f : 1.0f ); + const float finalScaleV = scaleUV * ( shouldFlipV ? -1.0f : 1.0f ); + + MatrixBuildRotateZ( m_mTextureAdjust, rotation ); + m_mTextureAdjust = m_mTextureAdjust.Scale( Vector( finalScaleU, finalScaleV, 1.0f ) ); + MatrixTranslate( m_mTextureAdjust, Vector( translateU, translateV, 0 ) ); + // Copy W into Z because we're doing a texture matrix. + m_mTextureAdjust[ 0 ][ 2 ] = m_mTextureAdjust[ 0 ][ 3 ]; + m_mTextureAdjust[ 1 ][ 2 ] = m_mTextureAdjust[ 1 ][ 3 ]; + m_mTextureAdjust[ 2 ][ 2 ] = 1.0f; + + return true; + } + + +private: + TextureStageParameters m_Parameters; + ITexture* m_pTex; + ITexture* m_pTexRed; + ITexture* m_pTexBlue; + + // Random values here + float m_fAdjustBlack; + float m_fAdjustWhite; + float m_fAdjustGamma; + VMatrix m_mTextureAdjust; +}; + +// ------------------------------------------------------------------------------------------------ +// ------------------------------------------------------------------------------------------------ +// ------------------------------------------------------------------------------------------------ + +// Keep in sync with CombineOperation +const char* cCombineMaterialName[] = +{ + "dev/CompositorMultiply", + "dev/CompositorAdd", + "dev/CompositorLerp", + + "dev/CompositorSelect", + + "\0 ECO_Legacy_Lerp_FirstPass", // Procedural; starting with \0 will skip precaching + "\0 ECO_Legacy_Lerp_SecondPass", // Procedural; starting with \0 will skip precaching + + "dev/CompositorBlend", + + "\0 ECO_LastPrecacheMaterial", // + + "CompositorError", + + NULL +}; + +static_assert( ARRAYSIZE( cCombineMaterialName ) == ECO_COUNT + 1, "cCombineMaterialName and ECombineOperation are out of sync." ); + +// ------------------------------------------------------------------------------------------------ +struct CombineStageParameters +{ + ECombineOperation m_CombineOp; + Range m_AdjustBlack; + Range m_AdjustOffset; + Range m_AdjustGamma; + + Range m_Rotation; + Range m_TranslateU; + Range m_TranslateV; + Range m_ScaleUV; + + bool m_AllowFlipU; + bool m_AllowFlipV; + bool m_Evaluate; + + CombineStageParameters() + : m_CombineOp( ECO_Error ) + , m_AdjustBlack( 0, 0 ) + , m_AdjustOffset( 1, 1 ) + , m_AdjustGamma( 1, 1 ) + , m_Rotation( 0 , 0 ) + , m_TranslateU( 0, 0 ) + , m_TranslateV( 0, 0 ) + , m_ScaleUV( 1, 1 ) + , m_AllowFlipU( false ) + , m_AllowFlipV( false ) + , m_Evaluate( true ) + { } + +}; + +// ------------------------------------------------------------------------------------------------ +void ParseOperationFromKV( KeyValues* _kv, void* _pDest ) +{ + ECombineOperation* realDest = ( ECombineOperation* ) _pDest; + const char* opStr = _kv->GetString(); + + if ( V_stricmp( "multiply", opStr ) == 0 ) + (*realDest) = ECO_Multiply; + else if ( V_stricmp( "add", opStr ) == 0 ) + (*realDest) = ECO_Add; + else if ( V_stricmp( "lerp", opStr) == 0 ) + (*realDest) = ECO_Lerp; + else + (*realDest) = ECO_Error; +} + +// ------------------------------------------------------------------------------------------------ +const ParseTableEntry cCombineStageParametersParseTable[] = +{ + { "adjust_black", ParseRangeThenDivideBy<255>, offsetof( CombineStageParameters, m_AdjustBlack ) }, + { "adjust_offset", ParseRangeThenDivideBy<255>, offsetof( CombineStageParameters, m_AdjustOffset ) }, + { "adjust_gamma", ParseInverseRangeFromKV, offsetof( CombineStageParameters, m_AdjustGamma ) }, + { "rotation", ParseRangeFromKV, offsetof( CombineStageParameters, m_Rotation ) }, + { "translate_u", ParseRangeFromKV, offsetof( CombineStageParameters, m_TranslateU ) }, + { "translate_v", ParseRangeFromKV, offsetof( CombineStageParameters, m_TranslateV ) }, + { "scale_uv", ParseRangeFromKV, offsetof( CombineStageParameters, m_ScaleUV ) }, + { "flip_u", ParseBoolFromKV, offsetof( CombineStageParameters, m_AllowFlipU ) }, + { "flip_v", ParseBoolFromKV, offsetof( CombineStageParameters, m_AllowFlipV ) }, + { "evaluate?", ParseBoolFromKV, offsetof( CombineStageParameters, m_Evaluate ) }, + + { 0, 0 } +}; + +// ------------------------------------------------------------------------------------------------ +// ------------------------------------------------------------------------------------------------ +// ------------------------------------------------------------------------------------------------ +class CTCCombineStage : public CTCStage +{ +public: + CTCCombineStage( const CombineStageParameters& _csp, uint32 nTexCompositeCreateFlags ) + : m_Parameters( _csp ) + , m_pMaterial( NULL ) + { + Assert( m_Parameters.m_CombineOp >= 0 && m_Parameters.m_CombineOp < ECO_COUNT ); + + SafeAssign( &m_pMaterial, materials->FindMaterial( cCombineMaterialName[ m_Parameters.m_CombineOp ], TEXTURE_GROUP_RUNTIME_COMPOSITE ) ); + } + + virtual ~CTCCombineStage() + { + SafeRelease( &m_pMaterial ); + } + + virtual bool DoesTargetRenderTarget() const { return true; } + + +protected: + virtual void RequestTextures() { /* No textures here */ } + + virtual void ResolveThis( CTextureCompositor* _comp ) + { + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s", __FUNCTION__ ); + + ECompositeResolveStatus resolveStatus = GetResolveStatus(); + // If we're done, we're done. + if ( resolveStatus == ECRS_Complete || resolveStatus == ECRS_Error ) + return; + + if ( resolveStatus == ECRS_Scheduled ) + SetResolveStatus( ECRS_PendingTextureLoads ); + + // Someone is misusing this node if this assert fires. + Assert( GetResolveStatus() == ECRS_PendingTextureLoads ); + + for ( CTCStage* child = GetFirstChild(); child; child = child->GetNextSibling() ) + { + // If any child isn't ready to go, we're not ready to go. + if ( child->GetResolveStatus() != ECRS_Complete ) + return; + } + + ITexture* pRenderTarget = _comp->AllocateCompositorRenderTarget(); + + CUtlVector results; + uint childCount = 0; + for ( CTCStage* child = GetFirstChild(); child; child = child->GetNextSibling() ) + { + results.AddToTail( child->GetResult() ); + ++childCount; + } + + // TODO: If there are more than 8 children, need to split them into multiple groups here. Skip it for now. + + Render( pRenderTarget, m_pMaterial, results, _comp, true ); + + CTCStageResult_t res; + res.m_pRenderTarget = pRenderTarget; + res.m_fAdjustBlackPoint = m_fAdjustBlack; + res.m_fAdjustWhitePoint = m_fAdjustWhite; + res.m_fAdjustGamma = m_fAdjustGamma; + + SetResult( res ); + + // As soon as we have scheduled the read of a child render target, we can release that + // texture back to the pool for use by another stage. Everything is pipelined, so this just + // works. + CleanupChildResults( _comp ); + tmMessage( TELEMETRY_LEVEL0, TMMF_ICON_NOTE, "Completed: %s", __FUNCTION__ ); + } + + virtual bool HasTeamSpecificsThis() const OVERRIDE{ return false; } + + virtual bool ComputeRandomValuesThis( CUniformRandomStream* pRNG ) OVERRIDE + { + const float adjustBlack = pRNG->RandomFloat( m_Parameters.m_AdjustBlack.low, m_Parameters.m_AdjustBlack.high ); + const float adjustOffset = pRNG->RandomFloat( m_Parameters.m_AdjustOffset.low, m_Parameters.m_AdjustOffset.high ); + const float adjustGamma = pRNG->RandomFloat( m_Parameters.m_AdjustGamma.low, m_Parameters.m_AdjustGamma.high ); + const float adjustWhite = adjustBlack + adjustOffset; + + m_fAdjustBlack = adjustBlack; + m_fAdjustWhite = adjustWhite; + m_fAdjustGamma = adjustGamma; + + return true; + } + +private: + CombineStageParameters m_Parameters; + IMaterial* m_pMaterial; + + float m_fAdjustBlack; + float m_fAdjustWhite; + float m_fAdjustGamma; +}; + +// ------------------------------------------------------------------------------------------------ +struct SelectStageParameters +{ + CUtlString m_pTexFilename; + CCopyableUtlVector m_Select; + bool m_Evaluate; + + SelectStageParameters() + : m_Evaluate( true ) + { + } +}; + +// ------------------------------------------------------------------------------------------------ +const ParseTableEntry cSelectStageParametersParseTable[] = +{ + { "groups", ParseStringFromKV, offsetof( SelectStageParameters, m_pTexFilename ) }, + { "select", ParseVectorFromKV< int, cMaxSelectors >, offsetof( SelectStageParameters, m_Select ) }, + { "evaluate?", ParseBoolFromKV, offsetof( SelectStageParameters, m_Evaluate ) }, + + { 0, 0 } +}; + + // ------------------------------------------------------------------------------------------------ + // ------------------------------------------------------------------------------------------------ + // ------------------------------------------------------------------------------------------------ +class CTCSelectStage : public CTCStage +{ +public: + CTCSelectStage( const SelectStageParameters& _ssp, uint32 nTexCompositeCreateFlags ) + : m_Parameters( _ssp ) + , m_pMaterial( NULL ) + , m_pTex( NULL ) + { + SafeAssign( &m_pMaterial, materials->FindMaterial( cCombineMaterialName[ ECO_Select ], TEXTURE_GROUP_RUNTIME_COMPOSITE ) ); + } + virtual ~CTCSelectStage() + { + SafeRelease( &m_pMaterial ); + SafeRelease( &m_pTex ); + } + + virtual void OnAsyncFindComplete( ITexture* pTex, void* pExtraArgs ) { SafeAssign( &m_pTex, pTex ); } + + virtual bool DoesTargetRenderTarget() const { return true; } + + +protected: + virtual void RequestTextures() + { + materials->AsyncFindTexture( m_Parameters.m_pTexFilename.Get(), TEXTURE_GROUP_RUNTIME_COMPOSITE, this, NULL, false, TEXTUREFLAGS_IMMEDIATE_CLEANUP ); + } + + virtual void ResolveThis( CTextureCompositor* _comp ) + { + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s", __FUNCTION__ ); + + // We shouldn't have any children, we're going to ignore them anyways. + Assert( GetFirstChild() == NULL ); + + ECompositeResolveStatus resolveStatus = GetResolveStatus(); + // If we're done, we're done. + if ( resolveStatus == ECRS_Complete || resolveStatus == ECRS_Error ) + return; + + if ( resolveStatus == ECRS_Scheduled ) + SetResolveStatus( ECRS_PendingTextureLoads ); + + // Someone is misusing this node if this assert fires. + Assert( GetResolveStatus() == ECRS_PendingTextureLoads ); + + // When the texture has finished loading, this will be set to the texture we should use. + if ( m_pTex == NULL ) + return; + + if ( m_pTex->IsError() ) + { + _comp->Error( false, "Failed to load texture %s, this is non-recoverable.\n", m_Parameters.m_pTexFilename.Get() ); + return; + } + + ITexture* pRenderTarget = _comp->AllocateCompositorRenderTarget(); + + char buffer[128]; + for ( int i = 0; i < cMaxSelectors; ++i ) + { + bool bFound = false; + + V_snprintf( buffer, ARRAYSIZE( buffer ), "$selector%d", i ); + IMaterialVar* pVar = m_pMaterial->FindVar( buffer, &bFound ); + Assert(bFound); + if ( i < m_Parameters.m_Select.Size() ) + pVar->SetIntValue( m_Parameters.m_Select[i] ); + else + pVar->SetIntValue( 0 ); + } + + CTCStageResult_t inRes; + inRes.m_pTexture = m_pTex; + CUtlVector fakeResults; + fakeResults.AddToTail( inRes ); + Render( pRenderTarget, m_pMaterial, fakeResults, _comp, true ); + + CTCStageResult_t outRes; + outRes.m_pRenderTarget = pRenderTarget; + SetResult( outRes ); + + CleanupChildResults( _comp ); + tmMessage( TELEMETRY_LEVEL0, TMMF_ICON_NOTE, "Completed: %s", __FUNCTION__ ); + } + + virtual bool HasTeamSpecificsThis() const OVERRIDE { return false; } + + virtual bool ComputeRandomValuesThis( CUniformRandomStream* pRNG ) OVERRIDE + { + // No RNG here. + return false; + } + +private: + SelectStageParameters m_Parameters; + IMaterial* m_pMaterial; + ITexture* m_pTex; +}; + +// ------------------------------------------------------------------------------------------------ +// ------------------------------------------------------------------------------------------------ +// ------------------------------------------------------------------------------------------------ +struct Sticker_t +{ + float m_fWeight; // Random likelihood this one is to be selected + CUtlString m_baseFilename; // Name of the base file for the sticker (the albedo). + CUtlString m_specFilename; // Name of the specular file for the sticker, or if blank we will assume it is baseFilename + _spec + baseExtension + + Sticker_t() + : m_fWeight( 1.0 ) + { } +}; + +// ------------------------------------------------------------------------------------------------ +template<> +void ParseTFromKV< Sticker_t >( KeyValues* _kv, void* _pDest ) +{ + Sticker_t* realDest = ( Sticker_t* ) _pDest; + Sticker_t tmpDest; + + tmpDest.m_fWeight = _kv->GetFloat( "weight", 1.0 ); + tmpDest.m_baseFilename = _kv->GetString( "base" ); + KeyValues* pSpec = _kv->FindKey( "spec" ); + if ( pSpec ) + tmpDest.m_specFilename = pSpec->GetString(); + else + { + CUtlString specPath = tmpDest.m_baseFilename.StripExtension() + + "_s" + + tmpDest.m_baseFilename.GetExtension(); + + tmpDest.m_specFilename = specPath; + } + + *realDest = tmpDest; +} + +// ------------------------------------------------------------------------------------------------ +template <> +CUtlString AsStringT< Sticker_t >( const Sticker_t& _val ) +{ + char buffer[ 80 ]; + V_sprintf_safe( buffer, "[ weight %.2f; base \"%s\"; spec \"%s\" ]", _val.m_fWeight, _val.m_baseFilename.Get(), _val.m_specFilename.Get() ); + return CUtlString( buffer ); +} + +// ------------------------------------------------------------------------------------------------ +template< class T > +struct Settable_t +{ + T m_val; + bool m_bSet; + + Settable_t() + : m_val( T() ) + , m_bSet( false ) + { } +}; + +// ------------------------------------------------------------------------------------------------ +template < class T > +void ParseSettable( KeyValues *_kv, void* _pDest ) +{ + Settable_t *pSettable = ( Settable_t* )_pDest; + + ParseTFromKV( _kv, &pSettable->m_val ); + ( *pSettable ).m_bSet = true; +} + +// ------------------------------------------------------------------------------------------------ +struct ApplyStickerStageParameters +{ + CCopyableUtlVector< Sticker_t > m_possibleStickers; + + Settable_t< Vector2D > m_vDestBL; + Settable_t< Vector2D > m_vDestTL; + Settable_t< Vector2D > m_vDestTR; + + Range m_AdjustBlack; + Range m_AdjustOffset; + Range m_AdjustGamma; + bool m_Evaluate; + + ApplyStickerStageParameters() + : m_AdjustBlack( 0, 0 ) + , m_AdjustOffset( 1, 1 ) + , m_AdjustGamma( 1, 1 ) + , m_Evaluate( true ) + { } +}; + +// ------------------------------------------------------------------------------------------------ +const ParseTableEntry cApplyStickerStageParametersParseTable[] = +{ + { "sticker", ParseVectorFromKV< Sticker_t >, offsetof( ApplyStickerStageParameters, m_possibleStickers ) }, + { "dest_bl", ParseSettable< Vector2D >, offsetof( ApplyStickerStageParameters, m_vDestBL ) }, + { "dest_tl", ParseSettable< Vector2D >, offsetof( ApplyStickerStageParameters, m_vDestTL ) }, + { "dest_tr", ParseSettable< Vector2D >, offsetof( ApplyStickerStageParameters, m_vDestTR ) }, + { "adjust_black", ParseRangeThenDivideBy< 255 >, offsetof( ApplyStickerStageParameters, m_AdjustBlack ) }, + { "adjust_offset", ParseRangeThenDivideBy< 255 >, offsetof( ApplyStickerStageParameters, m_AdjustOffset ) }, + { "adjust_gamma", ParseInverseRangeFromKV, offsetof( ApplyStickerStageParameters, m_AdjustGamma ) }, + { "evaluate?", ParseBoolFromKV, offsetof( ApplyStickerStageParameters, m_Evaluate ) }, + + { 0, 0 } +}; + +// ------------------------------------------------------------------------------------------------ +// ------------------------------------------------------------------------------------------------ +// ------------------------------------------------------------------------------------------------ +class CTCApplyStickerStage : public CTCStage +{ + enum { Albedo = 0, Specular = 1 }; + +public: + CTCApplyStickerStage( const ApplyStickerStageParameters& _assp, uint32 nTexCompositeCreateFlags ) + : m_Parameters( _assp ) + , m_pMaterial( NULL ) + , m_pTex( NULL ) + , m_pTexSpecular( NULL ) + , m_nChoice( 0 ) + { + SafeAssign( &m_pMaterial, materials->FindMaterial( cCombineMaterialName[ ECO_Blend ], TEXTURE_GROUP_RUNTIME_COMPOSITE ) ); + } + + virtual ~CTCApplyStickerStage() + { + SafeRelease( &m_pTex ); + SafeRelease( &m_pTexSpecular ); + SafeRelease( &m_pMaterial ); + } + + virtual bool DoesTargetRenderTarget() const { return true; } + +protected: + bool AreTexturesLoaded() const + { + if ( !m_Parameters.m_possibleStickers[ m_nChoice ].m_baseFilename.IsEmpty() && !m_pTex ) + return false; + + if ( !m_Parameters.m_possibleStickers[ m_nChoice ].m_specFilename.IsEmpty() && !m_pTexSpecular ) + return false; + + return true; + } + + virtual void RequestTextures() + { + if ( !m_Parameters.m_possibleStickers[ m_nChoice ].m_baseFilename.IsEmpty() ) + materials->AsyncFindTexture( m_Parameters.m_possibleStickers[ m_nChoice ].m_baseFilename.Get(), TEXTURE_GROUP_RUNTIME_COMPOSITE, this, ( void* ) Albedo, false, TEXTUREFLAGS_IMMEDIATE_CLEANUP ); + + if ( !m_Parameters.m_possibleStickers[ m_nChoice ].m_specFilename.IsEmpty() ) + materials->AsyncFindTexture( m_Parameters.m_possibleStickers[ m_nChoice ].m_specFilename.Get(), TEXTURE_GROUP_RUNTIME_COMPOSITE, this, ( void* ) Specular, false, TEXTUREFLAGS_IMMEDIATE_CLEANUP ); + } + + virtual void ResolveThis( CTextureCompositor* _comp ) + { + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s", __FUNCTION__ ); + + ECompositeResolveStatus resolveStatus = GetResolveStatus(); + // If we're done, we're done. + if ( resolveStatus == ECRS_Complete || resolveStatus == ECRS_Error ) + return; + + if ( resolveStatus == ECRS_Scheduled ) + SetResolveStatus( ECRS_PendingTextureLoads ); + + // Someone is misusing this node if this assert fires. + Assert( GetResolveStatus() == ECRS_PendingTextureLoads ); + + CTCStage* pChild = GetFirstChild(); + if ( pChild != NULL && pChild->GetResolveStatus() != ECRS_Complete ) + return; + + if ( !AreTexturesLoaded() ) + return; + + // Ensure we only have zero or one direct children. + Assert( !pChild || pChild->GetNextSibling() == NULL ); + + // We expect exactly one or zero children. If we have a child, use its render target to render to, otherwise + // Get one and use that. + ITexture* pRenderTarget = _comp->AllocateCompositorRenderTarget(); + + CUtlVector results; + + // If we have a child, great! Use it. If not, + if ( pChild ) + results.AddToTail( pChild->GetResult() ); + else + { + CTCStageResult_t fakeRes; + fakeRes.m_pTexture = materials->FindTexture( "black", TEXTURE_GROUP_RUNTIME_COMPOSITE ); + } + + CTCStageResult_t baseTex, specTex; + baseTex.m_pTexture = m_pTex; + m_mTextureAdjust.Set3x4( baseTex.m_mUvAdjust ); + results.AddToTail( baseTex ); + + specTex.m_pTexture = m_pTexSpecular; + m_mTextureAdjust.Set3x4( specTex.m_mUvAdjust ); + results.AddToTail( specTex ); + + Render( pRenderTarget, m_pMaterial, results, _comp, pChild == NULL ); + + CTCStageResult_t res; + res.m_pRenderTarget = pRenderTarget; + res.m_fAdjustBlackPoint = m_fAdjustBlack; + res.m_fAdjustWhitePoint = m_fAdjustWhite; + res.m_fAdjustGamma = m_fAdjustGamma; + + SetResult( res ); + + // As soon as we have scheduled the read of a child render target, we can release that + // texture back to the pool for use by another stage. Everything is pipelined, so this just + // works. + CleanupChildResults( _comp ); + tmMessage( TELEMETRY_LEVEL0, TMMF_ICON_NOTE, "Completed: %s", __FUNCTION__ ); + } + + virtual bool HasTeamSpecificsThis() const OVERRIDE{ return false; } + + virtual bool ComputeRandomValuesThis( CUniformRandomStream* pRNG ) OVERRIDE + { + float m_fTotalWeight = 0; + FOR_EACH_VEC( m_Parameters.m_possibleStickers, i ) + { + m_fTotalWeight += m_Parameters.m_possibleStickers[ i ].m_fWeight; + } + + float fWeight = pRNG->RandomFloat( 0.0f, m_fTotalWeight ); + FOR_EACH_VEC( m_Parameters.m_possibleStickers, i ) + { + const float thisWeight = m_Parameters.m_possibleStickers[ i ].m_fWeight; + if ( fWeight < thisWeight ) + { + m_nChoice = i; + break; + } + else + { + fWeight -= thisWeight; + } + } + + const float adjustBlack = pRNG->RandomFloat( m_Parameters.m_AdjustBlack.low, m_Parameters.m_AdjustBlack.high ); + const float adjustOffset = pRNG->RandomFloat( m_Parameters.m_AdjustOffset.low, m_Parameters.m_AdjustOffset.high ); + const float adjustGamma = pRNG->RandomFloat( m_Parameters.m_AdjustGamma.low, m_Parameters.m_AdjustGamma.high ); + const float adjustWhite = adjustBlack + adjustOffset; + + m_fAdjustBlack = adjustBlack; + m_fAdjustWhite = adjustWhite; + m_fAdjustGamma = adjustGamma; + + ComputeTextureMatrixFromRectangle( &m_mTextureAdjust, m_Parameters.m_vDestBL.m_val, m_Parameters.m_vDestTL.m_val, m_Parameters.m_vDestTR.m_val ); + return true; + } + + virtual void OnAsyncFindComplete( ITexture* pTex, void* pExtraArgs ) + { + switch ( ( int ) pExtraArgs ) + { + case Albedo: + SafeAssign( &m_pTex, pTex ); + break; + case Specular: + // It's okay if this is the case, we just need to substitute with the black texture. + if ( pTex->IsError() ) + { + pTex = materials->FindTexture( "black", TEXTURE_GROUP_RUNTIME_COMPOSITE ); + } + SafeAssign( &m_pTexSpecular, pTex ); + break; + default: + Assert( !"Unexpected value passed to OnAsyncFindComplete" ); + break; + }; + } + +private: + ApplyStickerStageParameters m_Parameters; + IMaterial* m_pMaterial; + ITexture* m_pTex; + ITexture* m_pTexSpecular; + int m_nChoice; + + float m_fAdjustBlack; + float m_fAdjustWhite; + float m_fAdjustGamma; + VMatrix m_mTextureAdjust; +}; + +// ------------------------------------------------------------------------------------------------ +// ------------------------------------------------------------------------------------------------ +// ------------------------------------------------------------------------------------------------ +// This is a procedural stage we use to copy the results of a composite into a texture so we can +// release the render targets back to a pool to be used later. +class CTCCopyStage : public CTCStage +{ +public: + CTCCopyStage() + : m_pTex( NULL ) + { + + } + + ~CTCCopyStage() + { + SafeRelease( &m_pTex ); + } + + virtual void OnAsyncCreateComplete( ITexture* pTex, void* pExtraArgs ) + { + SafeAssign( &m_pTex, pTex ); + tmMessage( TELEMETRY_LEVEL0, TMMF_ICON_NOTE, "Completed: %s", __FUNCTION__ ); + } + + virtual bool DoesTargetRenderTarget() const { return false; } + +private: + virtual void RequestTextures() { /* No input textures */ } + + virtual void ResolveThis( CTextureCompositor* _comp ) + { + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s", __FUNCTION__ ); + + ECompositeResolveStatus resolveStatus = GetResolveStatus(); + + // If we're done, we're done. + if ( resolveStatus == ECRS_Complete || resolveStatus == ECRS_Error ) + return; + + if ( resolveStatus == ECRS_Scheduled ) + SetResolveStatus( ECRS_PendingTextureLoads ); + + Assert( GetFirstChild() != NULL ); + + // Can't move forward until the child is done. + if ( GetFirstChild()->GetResolveStatus() != ECRS_Complete ) + return; + + // Compositing has completed! + if ( m_pTex ) + { + if ( m_pTex->IsError() ) + { + _comp->Error( false, "Error occurred copying render target to texture. This is fatal." ); + return; + } + + CTCStageResult_t res; + res.m_pTexture = m_pTex; + +#ifdef STAGING_ONLY + if ( r_texcomp_dump.GetInt() == 2 ) + { + char buffer[128]; + V_snprintf( buffer, ARRAYSIZE(buffer), "composite_%s_result_%02d.tga", _comp->GetName().Get(), s_nDumpCount++ ); + GetFirstChild()->GetResult().m_pRenderTarget->SaveToFile( buffer ); + } +#endif + + SetResult( res ); + return; + } + + if ( resolveStatus == ECRS_PendingComposites ) + return; + + ImageFormat fmt = IMAGE_FORMAT_DXT5_RUNTIME; + + if ( _comp->GetCreateFlags() & TEX_COMPOSITE_CREATE_FLAGS_NO_COMPRESSION ) + fmt = IMAGE_FORMAT_RGBA8888; + + bool bGenMipmaps = !( _comp->GetCreateFlags() & TEX_COMPOSITE_CREATE_FLAGS_NO_MIPMAPS ); + + // We want to do this once only. + char buffer[_MAX_PATH]; + _comp->GetTextureName( buffer, ARRAYSIZE( buffer ) ); + + int nCreateFlags = TEXTUREFLAGS_IMMEDIATE_CLEANUP + | TEXTUREFLAGS_TRILINEAR + | TEXTUREFLAGS_ANISOTROPIC; + +#if defined( STAGING_ONLY ) + #if WITH_TEX_COMPOSITE_CACHE + if ( r_texcomp_dump.GetInt() == 0 && ( _comp->GetCreateFlags() & TEX_COMPOSITE_CREATE_FLAGS_FORCE ) == 0 ) + nCreateFlags = 0; + #endif +#endif + + CMatRenderContextPtr pRenderContext( materials ); + pRenderContext->AsyncCreateTextureFromRenderTarget( GetFirstChild()->GetResult().m_pRenderTarget, buffer, fmt, bGenMipmaps, nCreateFlags, this, NULL ); + + SetResolveStatus( ECRS_PendingComposites ); + // Don't clean up here just yet, we'll get cleaned up when the composite is totally complete. + tmMessage( TELEMETRY_LEVEL0, TMMF_ICON_NOTE, "Begun: %s", __FUNCTION__ ); + } + + virtual bool HasTeamSpecificsThis() const OVERRIDE { return false; } + + virtual bool ComputeRandomValuesThis( CUniformRandomStream* pRNG ) OVERRIDE + { + // No RNG here. + return false; + } + + ITexture* m_pTex; + CUtlString m_FinalTextureName; + uint32 m_nTexCompositeCreateFlags; +}; + +// ------------------------------------------------------------------------------------------------ +// ------------------------------------------------------------------------------------------------ +// ------------------------------------------------------------------------------------------------ +CTextureCompositor::CTextureCompositor( int _width, int _height, int nTeam, const char* pCompositeName, uint64 nRandomSeed, uint32 nTexCompositeCreateFlags ) +: m_nReferenceCount( 0 ) +, m_nWidth( _width ) +, m_nHeight( _height ) +, m_nTeam( nTeam ) +, m_nRandomSeed( nRandomSeed ) +, m_pRootStage( NULL ) +, m_ResolveStatus( ECRS_Idle ) +, m_bError( false ) +, m_bFatal( false ) +, m_nRenderTargetsAllocated( 0 ) +, m_CompositeName( pCompositeName ) +, m_nTexCompositeCreateFlags( nTexCompositeCreateFlags ) +, m_bHasTeamSpecifics( false ) +, m_nCompositePaintKitId( 0 ) +{ + +} + +// ------------------------------------------------------------------------------------------------ +CTextureCompositor::~CTextureCompositor() +{ + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s", __FUNCTION__ ); + Assert ( m_nReferenceCount == 0 ); + + // Have to clean up the stages before cleaning up the render target pool, because cleanup up + // stages will throw things back to the render target pool. + SafeRelease( &m_pRootStage ); + + FOR_EACH_VEC( m_RenderTargetPool, i ) + { + RenderTarget_t& rt = m_RenderTargetPool[ i ]; + SafeRelease( &rt.m_pRT ); + } +} + +// ------------------------------------------------------------------------------------------------ +void CTextureCompositor::Restart() +{ + Assert(!"TODO! Need to clone the root node, then cleanup the old root and start the new work."); + + // CTCStage* clone = m_pRootStage->Clone(); + SafeRelease( &m_pRootStage ); + // m_pRootStage = clone; + + m_ResolveStatus = ECRS_Scheduled; + + // Kick it off again + m_pRootStage->Resolve( true, this ); + m_ResolveStatus = ECRS_PendingTextureLoads; +} + +// ------------------------------------------------------------------------------------------------ +void CTextureCompositor::Shutdown() +{ + // If this thing is a template, then it's a faker and doesn't have an m_pRootStage. This is + // only true during startup when we're just verifying that the templates look sane--later + // they should have real data. + if ( m_pRootStage ) + m_pRootStage->Cleanup( this ); + + // These should match now. + Assert( m_nRenderTargetsAllocated == m_RenderTargetPool.Count() ); +} + +// ------------------------------------------------------------------------------------------------ +int CTextureCompositor::AddRef() +{ + return ++m_nReferenceCount; +} + +// ------------------------------------------------------------------------------------------------ +int CTextureCompositor::Release() +{ + int retVal = --m_nReferenceCount; + Assert( retVal >= 0 ); + if ( retVal == 0 ) + { + Shutdown(); + delete this; + } + + return retVal; +} + +// ------------------------------------------------------------------------------------------------ +void CTextureCompositor::Update() +{ + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s", __FUNCTION__ ); + + Assert( m_pRootStage ); + + if ( m_bError ) + { + if ( !m_bFatal ) + { + m_bError = false; + Restart(); + } + else + m_ResolveStatus = ECRS_Error; + return; + } + + if ( m_pRootStage->GetResolveStatus() != ECRS_Complete ) + m_pRootStage->Resolve( false, this ); + + if ( m_pRootStage->GetResolveStatus() == ECRS_Complete ) + { + #ifdef STAGING_ONLY + // One time, go ahead and dump out the texture if we're supposed to right here, at completion time. + if ( ( r_texcomp_dump.GetInt() == 3 || r_texcomp_dump.GetInt() == 4 ) && m_ResolveStatus != ECRS_Complete ) + { + char filename[_MAX_PATH]; + V_sprintf_safe( filename, "%s.tga", m_CompositeName.Get() ); + m_pRootStage->GetResult().m_pTexture->SaveToFile( filename ); + } + #endif + + m_ResolveStatus = ECRS_Complete; + +#ifdef RAD_TELEMETRY_ENABLED + char buffer[ 256 ]; + GetTextureName( buffer, ARRAYSIZE( buffer ) ); + tmEndTimeSpan( TELEMETRY_LEVEL0, m_nCompositePaintKitId, 0, "Composite: %s", tmDynamicString( TELEMETRY_LEVEL0, buffer ) ); +#endif + } +} + +// ------------------------------------------------------------------------------------------------ +ITexture* CTextureCompositor::GetResultTexture() const +{ + Assert( m_pRootStage && m_pRootStage->GetResolveStatus() == ECRS_Complete ); + Assert( m_pRootStage->GetResult().m_pTexture ); + return m_pRootStage->GetResult().m_pTexture; +} + +// ------------------------------------------------------------------------------------------------ +ECompositeResolveStatus CTextureCompositor::GetResolveStatus() const +{ + return m_ResolveStatus; +} + +// ------------------------------------------------------------------------------------------------ +void CTextureCompositor::ScheduleResolve( ) +{ + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s", __FUNCTION__ ); + + Assert( m_pRootStage ); + Assert( m_ResolveStatus == ECRS_Idle ); + + #if WITH_TEX_COMPOSITE_CACHE + if ( ( GetCreateFlags() & TEX_COMPOSITE_CREATE_FLAGS_FORCE ) == 0) + { + char buffer[ _MAX_PATH ]; + GetTextureName( buffer, ARRAYSIZE( buffer ) ); + + // I think there's a race condition here, add a flag to FindTexture that says only if loaded, and bumps ref? + if ( materials->IsTextureLoaded( buffer ) ) + { + ITexture* resTexture = materials->FindTexture( buffer, TEXTURE_GROUP_RUNTIME_COMPOSITE, false, 0 ); + if ( resTexture && resTexture->IsError() == false ) + { + m_pRootStage->OnAsyncCreateComplete( resTexture, NULL ); + CTCStageResult_t res; + res.m_pTexture = resTexture; + m_pRootStage->SetResult( res ); + + m_ResolveStatus = ECRS_Complete; + return; + } + } + } + #endif + + #ifdef RAD_TELEMETRY_ENABLED + m_nCompositePaintKitId = ++s_nCompositeCount; + char buffer[256]; + GetTextureName( buffer, ARRAYSIZE( buffer ) ); + tmBeginTimeSpan( TELEMETRY_LEVEL0, m_nCompositePaintKitId, 0, "Composite: %s", tmDynamicString( TELEMETRY_LEVEL0, buffer ) ); + #endif + + m_ResolveStatus = ECRS_Scheduled; + + // Naughty. + extern CMaterialSystem g_MaterialSystem; + g_MaterialSystem.ScheduleTextureComposite( this ); +} + +// ------------------------------------------------------------------------------------------------ +void CTextureCompositor::Resolve() +{ + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s", __FUNCTION__ ); + + // We can actually get in multiply times for the same one because of the way EconItemView works. + // So if that's the case, bail. + if ( m_ResolveStatus != ECRS_Scheduled ) + return; + + m_pRootStage->Resolve( true, this ); + + // Update our resolve status + m_ResolveStatus = ECRS_PendingTextureLoads; +} + +// ------------------------------------------------------------------------------------------------ +void CTextureCompositor::Error( bool _retry, const char* _debugDevMsg, ... ) +{ + m_bError = true; + m_bFatal = !_retry; + + va_list args; + va_start( args, _debugDevMsg ); + WarningV( _debugDevMsg, args ); + va_end( args ); +} + +// ------------------------------------------------------------------------------------------------ +void CTextureCompositor::SetRootStage( CTCStage* rootStage ) +{ + SafeAssign( &m_pRootStage, rootStage ); + + // After we set a root, compute everyone's RNG values. Do this once, early, to ensure the values are stable. + uint32 seedhi = 0; + uint32 seedlo = 0; + GetSeed( &seedhi, &seedlo ); + + CUniformRandomStream streams[2]; + streams[0].SetSeed( seedhi ); + streams[1].SetSeed( seedlo ); + + int currentIndex = 0; + + m_pRootStage->ComputeRandomValues( ¤tIndex, streams, ARRAYSIZE( streams ) ); +} + +// ------------------------------------------------------------------------------------------------ +// TODO: Need to accept format and depth status +ITexture* CTextureCompositor::AllocateCompositorRenderTarget( ) +{ + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s", __FUNCTION__ ); + + FOR_EACH_VEC( m_RenderTargetPool, i ) + { + const RenderTarget_t& rt = m_RenderTargetPool[ i ]; + if ( rt.m_nWidth == m_nWidth && rt.m_nHeight == m_nHeight ) + { + ITexture* retVal = rt.m_pRT; + m_RenderTargetPool.Remove( i ); + return retVal; + } + } + + // Lie to the material system that we are asking for this allocation way back at the beginning of time. + // This used to matter to GPUs for perf, but hasn't in a long time. + materials->OverrideRenderTargetAllocation( true ); + ITexture* retVal = materials->CreateNamedRenderTargetTextureEx( "", m_nWidth, m_nHeight, RT_SIZE_LITERAL_PICMIP, IMAGE_FORMAT_RGBA8888, MATERIAL_RT_DEPTH_NONE, TEXTUREFLAGS_IMMEDIATE_CLEANUP ); + Assert( retVal ); + materials->OverrideRenderTargetAllocation( false ); + + // Used to count how many we actually allocated so we can verify we cleaned them all up at + // shutdown + ++m_nRenderTargetsAllocated; + return retVal; +} + +// ------------------------------------------------------------------------------------------------ +void CTextureCompositor::ReleaseCompositorRenderTarget( ITexture* _tex ) +{ + Assert( _tex ); + int w = _tex->GetMappingWidth(); + int h = _tex->GetMappingHeight(); + + RenderTarget_t rt = { w, h, _tex }; + m_RenderTargetPool.AddToTail( rt ); +} + +// ------------------------------------------------------------------------------------------------ +void CTextureCompositor::GetTextureName( char* pOutBuffer, int nBufferLen ) const +{ + uint32 seedhi = 0; + uint32 seedlo = 0; + GetSeed( &seedhi, &seedlo ); + + Assert( m_pRootStage != NULL ); + if ( m_pRootStage->HasTeamSpecifics() ) + V_snprintf( pOutBuffer, nBufferLen, "proc/texcomp/%s_flags%08x_seedhi%08x_seedlo%08x_team%d_w%d_h%d", GetName().Get(), GetCreateFlags(), seedhi, seedlo, m_nTeam, m_nWidth, m_nHeight ); + else + V_snprintf( pOutBuffer, nBufferLen, "proc/texcomp/%s_flags%08x_seedhi%08x_seedlo%08x_w%d_h%d", GetName().Get(), GetCreateFlags(), seedhi, seedlo, m_nWidth, m_nHeight ); +} + +// ------------------------------------------------------------------------------------------------ +void CTextureCompositor::GetSeed( uint32* pOutHi, uint32* pOutLo ) const +{ + tmZone( TELEMETRY_LEVEL2, TMZF_NONE, "%s", __FUNCTION__ ); + + Assert( pOutHi && pOutLo ); + ( *pOutHi ) = 0; + ( *pOutLo ) = 0; + + // This is most definitely not the most efficient way to do this. + for ( int i = 0; i < 32; ++i ) + { + ( *pOutHi ) |= (uint32)( ( m_nRandomSeed & ( uint64( 1 ) << ( ( 2 * i ) + 0 ) ) ) >> i ); + ( *pOutLo ) |= (uint32)( ( m_nRandomSeed & ( uint64( 1 ) << ( ( 2 * i ) + 1 ) ) ) >> ( i + 1 ) ); + } +} + +// ------------------------------------------------------------------------------------------------ +// ------------------------------------------------------------------------------------------------ +// ------------------------------------------------------------------------------------------------ +CTCStage::CTCStage() +: m_nReferenceCount( 1 ) // This is 1 because the common case is to assign these as children, and we don't want to play with refs there. +, m_pFirstChild( NULL ) +, m_pNextSibling( NULL ) +, m_ResolveStatus( ECRS_Idle ) +{ } + +// ------------------------------------------------------------------------------------------------ +CTCStage::~CTCStage() +{ + Assert ( m_nReferenceCount == 0 ); + SafeRelease( &m_pFirstChild ); + SafeRelease( &m_pNextSibling ); +} + +// ------------------------------------------------------------------------------------------------ +int CTCStage::AddRef() +{ + return ++m_nReferenceCount; +} + +// ------------------------------------------------------------------------------------------------ +int CTCStage::Release() +{ + int retVal = --m_nReferenceCount; + if ( retVal == 0 ) + delete this; + return retVal; +} + +// ------------------------------------------------------------------------------------------------ +void CTCStage::Resolve( bool bFirstTime, CTextureCompositor* _comp ) +{ + + if ( m_pFirstChild ) + m_pFirstChild->Resolve( bFirstTime, _comp ); + + // Update our status, which may be updated below. Only do this the first time through. + if ( bFirstTime ) + { + m_ResolveStatus = ECRS_Scheduled; + // Request textures here. We used to request in the constructor, but it caused us + // to potentially hold all paintkitted textures for all time. That's bad for Mac, + // where we are super memory constrained. + RequestTextures(); + } + + ResolveThis( _comp ); + + if ( m_pNextSibling ) + m_pNextSibling->Resolve( bFirstTime, _comp ); +} + +// ------------------------------------------------------------------------------------------------ +bool CTCStage::HasTeamSpecifics( ) const +{ + if ( m_pFirstChild && m_pFirstChild->HasTeamSpecifics() ) + return true; + + if ( HasTeamSpecificsThis() ) + return true; + + return m_pNextSibling && m_pNextSibling->HasTeamSpecifics(); +} + +// ------------------------------------------------------------------------------------------------ +void CTCStage::ComputeRandomValues( int* pCurIndex, CUniformRandomStream* pRNGs, int nRNGCount ) +{ + Assert( pCurIndex != NULL ); + Assert( pRNGs != NULL ); + Assert( nRNGCount != 0 ); + + // We do a depth-first traversal here, but we hit ourselves first. + if ( ComputeRandomValuesThis( &pRNGs[*pCurIndex] ) ) + { + // Switch which RNG the next person will use. + ( *pCurIndex ) = ( ( *pCurIndex ) + 1 ) % nRNGCount; + } + + if ( m_pFirstChild ) + m_pFirstChild->ComputeRandomValues( pCurIndex, pRNGs, nRNGCount ); + + if ( m_pNextSibling ) + m_pNextSibling->ComputeRandomValues( pCurIndex, pRNGs, nRNGCount ); +} + +// ------------------------------------------------------------------------------------------------ +void CTCStage::CleanupChildResults( CTextureCompositor* _comp ) +{ + // This does not recurse. We call it as we move through the tree to clean up our + // first-generation children. + for ( CTCStage* child = GetFirstChild(); child; child = child->GetNextSibling() ) + { + child->m_Result.Cleanup( _comp ); + child->m_Result = CTCStageResult_t(); + } +} + +// ------------------------------------------------------------------------------------------------ +void CTCStage::Render( ITexture* _destRT, IMaterial* _mat, const CUtlVector& _inputs, CTextureCompositor* _comp, bool bClear ) +{ + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s", __FUNCTION__ ); + + CUtlVector< IMaterialVar* > varsToClean; + bool bFound = false; + char buffer[128]; + FOR_EACH_VEC( _inputs, i ) + { + const CTCStageResult_t& stageParams = _inputs[ i ]; + + Assert( stageParams.m_pTexture || stageParams.m_pRenderTarget ); + ITexture* inTex = stageParams.m_pTexture + ? stageParams.m_pTexture + : stageParams.m_pRenderTarget; + + V_snprintf( buffer, ARRAYSIZE( buffer ), "$srctexture%d", i ); + + // Set the texture + IMaterialVar* var = _mat->FindVar( buffer, &bFound ); + Assert( bFound ); + var->SetTextureValue( inTex ); + varsToClean.AddToTail( var ); + + // And the levels parameters + V_snprintf( buffer, ARRAYSIZE(buffer), "$texadjustlevels%d", i ); + var = _mat->FindVar( buffer, &bFound ); + Assert(bFound); + var->SetVecValue( stageParams.m_fAdjustBlackPoint, stageParams.m_fAdjustWhitePoint, stageParams.m_fAdjustGamma ); + + // And the expected transform + V_snprintf( buffer, ARRAYSIZE(buffer), "$textransform%d", i ); + var = _mat->FindVar( buffer, &bFound ); + Assert(bFound); + var->SetMatrixValue( stageParams.m_mUvAdjust ); + } + + IMaterialVar* var = _mat->FindVar( "$textureinputcount", &bFound ); + Assert( bFound ); + var->SetIntValue( _inputs.Count() ); + + CMatRenderContextPtr pRenderContext( materials ); + + int w = _destRT->GetActualWidth(); + int h = _destRT->GetActualHeight(); + + pRenderContext->PushRenderTargetAndViewport( _destRT, 0, 0, w, h ); + + if ( bClear ) + { + pRenderContext->ClearColor4ub( 0, 0, 0, 255 ); + pRenderContext->ClearBuffers( true, false, false ); + } + + // Perform the render! + pRenderContext->DrawScreenSpaceQuad( _mat ); + +#ifdef STAGING_ONLY + if (r_texcomp_dump.GetInt() == 1) + { + FOR_EACH_VEC(_inputs, i) + { + if (_inputs[i].m_pTexture) + { + V_snprintf(buffer, ARRAYSIZE(buffer), "composite_%s_input_%02d_in%01d_%08x.tga", _comp->GetName().Get(), s_nDumpCount, i, (int) this); + _inputs[i].m_pTexture->SaveToFile(buffer); + } + } + + V_snprintf(buffer, ARRAYSIZE(buffer), "composite_%s_result_%02d_%08x.tga", _comp->GetName().Get(), s_nDumpCount++, (int) this); + _destRT->SaveToFile(buffer); + } +#endif + + // Restore previous state + pRenderContext->PopRenderTargetAndViewport(); + + // After rendering, clean up the leftover texture references or they will be there for a long + // time. + FOR_EACH_VEC( varsToClean, i ) + { + varsToClean[ i ]->SetUndefined(); + } +} + +// ------------------------------------------------------------------------------------------------ +void CTCStage::Cleanup( CTextureCompositor* _comp ) +{ + if ( m_pFirstChild ) + m_pFirstChild->Cleanup( _comp ); + + m_Result.Cleanup( _comp ); + + if ( m_pNextSibling ) + m_pNextSibling->Cleanup( _comp ); +} + +// ------------------------------------------------------------------------------------------------ +// ------------------------------------------------------------------------------------------------ +// ------------------------------------------------------------------------------------------------ +typedef bool ( *TBuildNodeFromKVFunc )( CTCStage** ppOutStage, const char* _key, KeyValues* _kv, uint32 nTexCompositeCreateFlags ); +bool TexStageFromKV( CTCStage** ppOutStage, const char* _key, KeyValues* _kv, uint32 nTexCompositeCreateFlags ); +template bool CombineStageFromKV( CTCStage** ppOutStage, const char* _key, KeyValues* _kv, uint32 nTexCompositeCreateFlags ); +bool SelectStageFromKV( CTCStage** ppOutStage, const char* _key, KeyValues* _kv, uint32 nTexCompositeCreateFlags ); +bool ApplyStickerStageFromKV( CTCStage** ppOutStage, const char* _key, KeyValues* _kv, uint32 nTexCompositeCreateFlags ); + +struct NodeDefinitionEntry +{ + const char* keyName; + TBuildNodeFromKVFunc buildFunc; +}; + +NodeDefinitionEntry cNodeParseTable[] = +{ + { "texture_lookup", TexStageFromKV }, + + { "combine_add", CombineStageFromKV }, + { "combine_lerp", CombineStageFromKV }, + { "combine_multiply", CombineStageFromKV }, + + { "select", SelectStageFromKV }, + + { "apply_sticker", ApplyStickerStageFromKV }, + + { 0, 0 } +}; + +// ------------------------------------------------------------------------------------------------ +template +void ParseIntoStruct( S* _outStruct, CUtlVector< KeyValues *>* _leftovers, KeyValues* _kv, uint32 nTexCompositeCreateFlags, const ParseTableEntry* _entries ) +{ + Assert( _leftovers ); + + const char* keyName = _kv->GetName(); + keyName; + + FOR_EACH_SUBKEY( _kv, thisKey ) + { + bool parsed = false; + for ( int e = 0; _entries[e].keyName; ++e ) + { + if ( V_stricmp( _entries[e].keyName, thisKey->GetName() ) == 0 ) + { + // If we're instancing, go ahead and run the parse function. If we're just doing template verification + // then the right hand side may still have variables that need to be expanded, so just verify that the + // left hand side is sane. + if ( ( nTexCompositeCreateFlags & TEX_COMPOSITE_CREATE_FLAGS_VERIFY_TEMPLATE_ONLY ) == 0 ) + { + void* pDest = ((unsigned char*)_outStruct) + _entries[e].structOffset; + _entries[e].parseFunc( thisKey, pDest ); + } + parsed = true; + break; + } + } + + if ( !parsed ) + { + ( *_leftovers ).AddToTail( thisKey ); + } + } +} + +// ------------------------------------------------------------------------------------------------ +bool ParseNodes( CUtlVector< CTCStage* >* _outStages, const CUtlVector< KeyValues *>& _kvs, uint32 nTexCompositeCreateFlags ) +{ + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s", __FUNCTION__ ); + + bool anyFails = false; + + FOR_EACH_VEC( _kvs, thisKey ) + { + KeyValues *thisKV = _kvs[ thisKey ]; + + bool parsed = false; + for ( int e = 0; cNodeParseTable[ e ].keyName; ++e ) + { + if ( V_stricmp( cNodeParseTable[ e ].keyName, thisKV->GetName() ) == 0 ) + { + CTCStage* pNewStage = NULL; + if ( !cNodeParseTable[ e ].buildFunc( &pNewStage, thisKV->GetName(), thisKV, nTexCompositeCreateFlags ) ) + anyFails = true; + + (*_outStages).AddToTail( pNewStage ); + parsed = true; + break; + } + } + + if (!parsed) + { + DevWarning( "Compositor Error: Unexpected key '%s' while parsing definition.\n", thisKV->GetName() ); + anyFails = true; + } + } + + return !anyFails; +} + +// ------------------------------------------------------------------------------------------------ +bool TexStageFromKV( CTCStage** ppOutStage, const char* _key, KeyValues* _kv, uint32 nTexCompositeCreateFlags ) +{ + Assert( ppOutStage != NULL ); + + TextureStageParameters tsp; + CUtlVector< KeyValues* > leftovers; + CUtlVector< CTCStage* > childNodes; + ParseIntoStruct( &tsp, &leftovers, _kv, nTexCompositeCreateFlags, cTextureStageParametersParseTable ); + if ( !ParseNodes( &childNodes, leftovers, nTexCompositeCreateFlags ) ) + return false; + + if ( !( nTexCompositeCreateFlags & TEX_COMPOSITE_CREATE_FLAGS_VERIFY_SCHEMA_ONLY ) ) + { + ( *ppOutStage ) = new CTCTextureStage( tsp, nTexCompositeCreateFlags ); + ( *ppOutStage )->AppendChildren( childNodes ); + } + + return true; +} + +// ------------------------------------------------------------------------------------------------ +template +bool CombineStageFromKV( CTCStage** ppOutStage, const char* _key, KeyValues* _kv, uint32 nTexCompositeCreateFlags ) +{ + Assert( ppOutStage != NULL ); + + static_assert( Type >= 0 && Type < ECO_Error, "Invalid type, you need to update the enum." ); + CombineStageParameters csp; + csp.m_CombineOp = (ECombineOperation) Type; + + CUtlVector< KeyValues* > leftovers; + CUtlVector< CTCStage* > childNodes; + ParseIntoStruct( &csp, &leftovers, _kv, nTexCompositeCreateFlags, cCombineStageParametersParseTable ); + if ( !ParseNodes( &childNodes, leftovers, nTexCompositeCreateFlags ) ) + return false; + + if ( !( nTexCompositeCreateFlags & TEX_COMPOSITE_CREATE_FLAGS_VERIFY_SCHEMA_ONLY ) ) + { + ( *ppOutStage ) = new CTCCombineStage( csp, nTexCompositeCreateFlags ); + ( *ppOutStage )->AppendChildren( childNodes ); + } + + return true; +} + +// ------------------------------------------------------------------------------------------------ +bool SelectStageFromKV( CTCStage** ppOutStage, const char* _key, KeyValues* _kv, uint32 nTexCompositeCreateFlags ) +{ + Assert( ppOutStage != NULL ); + + SelectStageParameters ssp; + CUtlVector< KeyValues* > leftovers; + CUtlVector< CTCStage* > childNodes; + ParseIntoStruct( &ssp, &leftovers, _kv, nTexCompositeCreateFlags, cSelectStageParametersParseTable ); + if ( !ParseNodes( &childNodes, leftovers, nTexCompositeCreateFlags ) ) + return false; + + if ( !( nTexCompositeCreateFlags & TEX_COMPOSITE_CREATE_FLAGS_VERIFY_SCHEMA_ONLY ) ) + { + ( *ppOutStage ) = new CTCSelectStage( ssp, nTexCompositeCreateFlags ); + ( *ppOutStage )->AppendChildren( childNodes ); + } + + return true; +} + +// ------------------------------------------------------------------------------------------------ +bool ApplyStickerStageFromKV( CTCStage** ppOutStage, const char* _key, KeyValues* _kv, uint32 nTexCompositeCreateFlags ) +{ + Assert( ppOutStage != NULL ); + + ApplyStickerStageParameters assp; + CUtlVector< KeyValues* > leftovers; + CUtlVector< CTCStage* > childNodes; + ParseIntoStruct( &assp, &leftovers, _kv, nTexCompositeCreateFlags, cApplyStickerStageParametersParseTable ); + if ( !ParseNodes( &childNodes, leftovers, nTexCompositeCreateFlags ) ) + return false; + + // These stages can have exactly one child. + if ( childNodes.Count() > 1 ) + return false; + + int setCount = 0; + if ( assp.m_vDestBL.m_bSet ) ++setCount; + if ( assp.m_vDestTL.m_bSet ) ++setCount; + if ( assp.m_vDestTR.m_bSet ) ++setCount; + if ( setCount != 3 ) + return false; + + if ( !( nTexCompositeCreateFlags & TEX_COMPOSITE_CREATE_FLAGS_VERIFY_SCHEMA_ONLY ) ) + { + ( *ppOutStage ) = new CTCApplyStickerStage( assp, nTexCompositeCreateFlags ); + ( *ppOutStage )->AppendChildren( childNodes ); + } + + return true; +} + +// ------------------------------------------------------------------------------------------------ +const char *GetCombinedMaterialName( ECombineOperation eMaterial ) +{ + Assert( eMaterial >= ECO_FirstPrecacheMaterial && eMaterial < ECO_COUNT ); + return cCombineMaterialName[eMaterial]; +} + +// ------------------------------------------------------------------------------------------------ +KeyValues* ResolveTemplate( const char* pRootName, KeyValues* pValues, uint32 nTexCompositeCreateFlags, bool *pInOutAllocdNew ) +{ + Assert( pRootName != NULL && pValues != NULL && pInOutAllocdNew != NULL ); + + const char* pTemplateName = NULL; + bool bImplementsTemplate = false; + bool bHasOtherNodes = false; + + // First, figure out if the tree is sensible. + FOR_EACH_SUBKEY( pValues, pChild ) + { + const char* pChildName = pChild->GetName(); + if ( V_stricmp( pChildName, "implements" ) == 0 ) + { + if ( bImplementsTemplate ) + { + Warning( "ERROR[%s]: implements field can only appear once, seen a second time as 'implements \"%s\"\n", pRootName, pChild->GetString() ); + return NULL; + } + + bImplementsTemplate = true; + pTemplateName = pChild->GetString(); + } + else if ( pChildName && pChildName[0] != '$' ) + { + bHasOtherNodes = true; + } + } + + if ( bImplementsTemplate && bHasOtherNodes ) + { + Warning( "ERROR[%s]: if using 'implements', can only have variable definitions--other fields not allowed.\n", pRootName ); + return NULL; + } + + // If we're not doing templates, we're all finished. + if ( !bImplementsTemplate ) + return pValues; + + KeyValues* pNewKV = NULL; + + if ( ( nTexCompositeCreateFlags & TEX_COMPOSITE_CREATE_FLAGS_VERIFY_TEMPLATE_ONLY ) == 0 ) + { + CTextureCompositorTemplate* pTmpl = TextureManager()->FindTextureCompositorTemplate( pTemplateName ); + if ( !pTmpl ) + { + Warning( "ERROR[%s]: Couldn't find template named '%s'.\n", pRootName, pTemplateName ); + return NULL; + } + + Assert( pTmpl->GetKV() ); + + // If the verify flag isn't set, we're instancing the template so do all the logic. + if ( pTmpl->ImplementsTemplate() ) + { + pNewKV = ResolveTemplate( pRootName, pTmpl->GetKV(), nTexCompositeCreateFlags, pInOutAllocdNew ); + } + else + { + // The root-most template will allocate the memory for all of us. + pNewKV = pTmpl->GetKV()->MakeCopy(); + pNewKV->SetName( pRootName ); + ( *pInOutAllocdNew ) = true; + } + } + else + { + // Just return the original KV back to the caller, who just wants a success code here. + return pValues; + } + + // Now, copy any child var definitions from pValues into pNewKV. Because of the recursive call stack, + // this has the net effect that more concrete templates will write their values later than more remote templates. + FOR_EACH_SUBKEY( pValues, pChild ) + { + const char* pChildName = pChild->GetName(); + if ( pChildName && pChildName[0] == '$' ) + { + pNewKV->AddSubKey( pChild->MakeCopy() ); + } + } + + // Success! + return pNewKV; +} + +// ------------------------------------------------------------------------------------------------ +typedef CUtlDict< const char* > VariableDefs_t; +KeyValues* ExtractVariableDefinitions( VariableDefs_t* pOutVarDefs, const char* pRootName, KeyValues* pKeyValues ) +{ + Assert( pOutVarDefs ); + + FOR_EACH_SUBKEY( pKeyValues, pChild ) + { + const char* pChildName = pChild->GetName(); + if ( pChildName[0] == '$' ) + { + if ( pChild->GetFirstTrueSubKey() ) + { + Warning( "ERROR[%s]: All variable definitions must be simple strings, '%s' was a full subtree.\n", pRootName, pChildName ); + return NULL; + } + + int ndx = ( *pOutVarDefs ).Find( pChildName + 1 ); + if ( pOutVarDefs->IsValidIndex( ndx ) ) + ( *pOutVarDefs )[ ndx ] = pChild->GetString(); + else + ( *pOutVarDefs ).Insert( pChildName + 1, pChild->GetString() ); + } + } + + return pKeyValues; +} + +// ------------------------------------------------------------------------------------------------ +CUtlString GetErrorTrail( CUtlVector< const char* >& errorStack ) +{ + if ( errorStack.Count() == 0 ) + return CUtlString( "" ); + + const int stackLength = errorStack.Count(); + const int stackLengthMinusOne = stackLength - 1; + + const char* cStageSep = " -> "; + const int cStageSepStrLen = V_strlen( cStageSep ); + + int totalStrLength = 0; + + for ( int i = 0; i < stackLength; ++i ) + { + totalStrLength += V_strlen( errorStack[ i ] ); + } + + totalStrLength += stackLengthMinusOne * cStageSepStrLen; + + CUtlString retStr; + retStr.SetLength( totalStrLength ); + + char* pDstOrig = retStr.GetForModify(); pDstOrig; + char* pDst = retStr.GetForModify(); + + int destPos = 0; + for ( int i = 0; i < stackLength; ++i ) + { + // Copy the string + const char* pSrc = errorStack[ i ]; + while ( ( *pDst++ = *pSrc++ ) != 0 ) + ++destPos; + --pDst; + + if ( i < stackLengthMinusOne ) + { + // Now copy our separator + pSrc = cStageSep; + while ( ( *pDst++ = *pSrc++ ) != 0 ) + ++destPos; + --pDst; + } + } + + Assert( destPos == totalStrLength ); + Assert( pDst - retStr.Get() == totalStrLength ); + // SetLength above already included the +1 to length for the null terminator. + *pDst = '\0'; + + return retStr; +} + +// ------------------------------------------------------------------------------------------------ +enum ParseMode +{ + Copy, + DetermineStringForReplace, +}; + +// ------------------------------------------------------------------------------------------------ +// Returns the number of characters written into pOutBuffer or -1 if there was an error. +int SubstituteVarsRecursive( char* pOutBuffer, int* pOutSubsts, CUtlVector< const char* >& errorStack, const char* pStr, uint32 nTexCompositeCreateFlags, const VariableDefs_t& varDefs ) +{ + ParseMode mode = Copy; + char* pCurVariable = NULL; + + char* pDst = pOutBuffer; + + int srcPos = 0; + int dstPos = 0; + while ( pStr[ srcPos ] != 0 ) + { + const char* srcC = pStr + srcPos; + + switch ( mode ) + { + case Copy: + if ( srcC[ 0 ] == '$' && srcC[ 1 ] == '[' ) + { + mode = DetermineStringForReplace; + srcPos += 2; + pCurVariable = const_cast< char* >( pStr + srcPos ); + continue; + } + else if ( pOutBuffer ) + { + pDst[ dstPos++ ] = pStr[ srcPos++ ]; + } + else + { + ++dstPos; + ++srcPos; + } + + break; + + case DetermineStringForReplace: + if ( srcC[ 0 ] == ']' ) + { + // Make a modification so we can just do the lookup from this buffer. + pCurVariable[ srcC - pCurVariable ] = 0; + + // Lookup our substitution value. + int ndx = varDefs.Find( pCurVariable ); + const char* pSubstText = NULL; + + if ( ndx != varDefs.InvalidIndex() ) + { + pSubstText = varDefs[ ndx ]; + } + else if ( ( nTexCompositeCreateFlags & TEX_COMPOSITE_CREATE_FLAGS_VERIFY_TEMPLATE_ONLY ) != 0 ) + { + pSubstText = ""; // It's fine to run into these when verifying the template only. + } + else + { + Warning( "ERROR[%s]: Couldn't find variable named $%s that was requested to be substituted.\n", ( const char* ) GetErrorTrail( errorStack ), pCurVariable ); + + // Restore the string first. + pCurVariable[ srcC - pCurVariable ] = ']'; + + return -1; + } + + // Put it back. + pCurVariable[ srcC - pCurVariable ] = ']'; + + int charsWritten = SubstituteVarsRecursive( pOutBuffer ? &pDst[ dstPos ] : NULL, pOutSubsts, errorStack, pSubstText, nTexCompositeCreateFlags, varDefs ); + if ( charsWritten < 0 ) + return -1; + + ++( *pOutSubsts ); + dstPos += charsWritten; + ++srcPos; + + mode = Copy; + } + else + { + ++srcPos; + } + + break; + } + } + + if ( mode == DetermineStringForReplace ) + { + Warning( "ERROR[%s]: Variable $[%s missing closing bracket ].\n", ( const char* ) GetErrorTrail( errorStack ), pCurVariable ); + return -1; + } + + return dstPos; +} + +// ------------------------------------------------------------------------------------------------ +// Returns true if successful, false otherwise. +bool SubstituteVars( CUtlString* pOutStr, int* pOutSubsts, CUtlVector< const char* >& errorStack, const char* pStr, uint32 nTexCompositeCreateFlags, const VariableDefs_t& varDefs ) +{ + Assert( pOutStr != NULL && pOutSubsts != NULL && pStr != NULL ); + + ( *pOutSubsts ) = 0; + + // Even though this involves a traversal, we're saving a malloc by walking this thing once looking for the start token. + const char* pFirstRepl = V_strstr( pStr, "$[" ); + + // No substitutions, so bail out now. + if ( pFirstRepl == NULL ) + { + ( *pOutStr ) = pStr; + return true; + } + + // We could do this as we go, but we're trying to avoid re-mallocing memory repeatedly in here so process once + // to find out what the size is. + int expectedLen = SubstituteVarsRecursive( NULL, pOutSubsts, errorStack, pStr, nTexCompositeCreateFlags, varDefs ); + if ( expectedLen < 0 ) + return false; + + // We don't need to actually write the string, and we shouldn't. If we're just verifying, exit now with success. + if ( ( nTexCompositeCreateFlags & TEX_COMPOSITE_CREATE_FLAGS_VERIFY_TEMPLATE_ONLY ) != 0 ) + return true; + + CUtlString& outStr = ( *pOutStr ); + outStr.SetLength( expectedLen ); // SetLength does +1 to the length for us. + + int finalLen = SubstituteVarsRecursive( outStr.GetForModify(), pOutSubsts, errorStack, pStr, nTexCompositeCreateFlags, varDefs ); + + if ( finalLen < 0 ) + return false; + + // Otherwise things have gone horribly wrong. + Assert( outStr.Length() == expectedLen ); + Assert( expectedLen == finalLen ); + + // Success! + return true; +} + +// ------------------------------------------------------------------------------------------------ +bool ResolveAllVariablesRecursive( CUtlVector< const char* >& errorStack, const VariableDefs_t& varDefs, KeyValues* pKeyValues, uint32 nTexCompositeCreateFlags, CUtlString& tmpStr ) +{ + // hope for the best + bool success = true; + + FOR_EACH_SUBKEY( pKeyValues, pChild ) + { + if ( pChild->GetName()[ 0 ] == '$' ) + continue; + + errorStack.AddToTail( pChild->GetName() ); + + if ( pChild->GetFirstSubKey() ) + { + if ( !ResolveAllVariablesRecursive( errorStack, varDefs, pChild, nTexCompositeCreateFlags, tmpStr ) ) + success = false; + } + else + { + int nSubsts = 0; + if ( !SubstituteVars( &tmpStr, &nSubsts, errorStack, pChild->GetString(), nTexCompositeCreateFlags, varDefs ) ) + success = false; + + // Did we do any substitutions? + if ( nSubsts > 0 && ( ( nTexCompositeCreateFlags & TEX_COMPOSITE_CREATE_FLAGS_VERIFY_TEMPLATE_ONLY ) == 0 ) ) + pChild->SetStringValue( tmpStr ); + } + + errorStack.RemoveMultipleFromTail( 1 ); + } + + return success; +} + +// ------------------------------------------------------------------------------------------------ +KeyValues* ResolveAllVariables( const char* pRootName, const VariableDefs_t& varDefs, KeyValues* pKeyValues, uint32 nTexCompositeCreateFlags, bool *pInOutAllocdNew ) +{ + KeyValuesAD kvad_onError( ( KeyValues* ) nullptr ); + + // Let's just assume first that if we have any vars, we will need to substitute them. + // But if we're just verifying the template, no need. + if ( !( *pInOutAllocdNew ) && varDefs.Count() > 0 && ( ( nTexCompositeCreateFlags & TEX_COMPOSITE_CREATE_FLAGS_VERIFY_TEMPLATE_ONLY ) == 0 ) ) + { + pKeyValues = pKeyValues->MakeCopy(); + kvad_onError.Assign( pKeyValues ); + ( *pInOutAllocdNew ) = true; + } + + CUtlString str; + + CUtlVector< const char* > errorStack; + errorStack.AddToHead( pRootName ); + + if ( !ResolveAllVariablesRecursive( errorStack, varDefs, pKeyValues, nTexCompositeCreateFlags, str ) ) + return NULL; + + kvad_onError.Assign( NULL ); + return pKeyValues; +} + +// ------------------------------------------------------------------------------------------------ +// Perform all template expansion and variable substitution here. What should be output +// should look like v1.0 paintkits without templates or variables. Return NULL +// if var substitution fails or if we can't resolve a template or something +// (after outputting a meaningful error message, of course). +KeyValues* ParseTopLevelIntoKV( const char* pRootName, KeyValues* pValues, uint32 nTexCompositeCreateFlags, bool *pOutAllocdNew ) +{ + Assert( pRootName != NULL ); + Assert( pOutAllocdNew != NULL ); + if ( !pValues ) + return NULL; + + bool bRequiresCleanup = false; + KeyValues* pExpandedKV = NULL; + KeyValuesAD autoCleanup_pExpandedKV( pExpandedKV ); + VariableDefs_t varDefs; + + pExpandedKV = ResolveTemplate( pRootName, pValues, nTexCompositeCreateFlags, &bRequiresCleanup ); + if ( pExpandedKV == NULL ) + return NULL; + + if ( bRequiresCleanup ) + { + Assert( autoCleanup_pExpandedKV == nullptr || autoCleanup_pExpandedKV == pExpandedKV ); + autoCleanup_pExpandedKV.Assign( pExpandedKV ); + } + + pExpandedKV = ExtractVariableDefinitions( &varDefs, pRootName, pExpandedKV ); + if ( pExpandedKV == NULL ) + return NULL; + + // Only resolve the variables if we're instantiating. During verification time, we'll + // just check that the keys are sensible and we can skip this. + pExpandedKV = ResolveAllVariables( pRootName, varDefs, pExpandedKV, nTexCompositeCreateFlags, &bRequiresCleanup); + if ( pExpandedKV == NULL ) + return NULL; + + Assert( bRequiresCleanup || varDefs.Count() == 0 || ( ( nTexCompositeCreateFlags & TEX_COMPOSITE_CREATE_FLAGS_VERIFY_TEMPLATE_ONLY ) != 0 ) ); + varDefs.RemoveAll(); // These won't be valid after we cleanup the tree to remove variable definitions. + + if ( bRequiresCleanup ) + { + KeyValues* pChild = pExpandedKV->GetFirstSubKey(); + + while ( pChild ) + { + const char* pChildName = pChild->GetName(); + if ( pChildName[ 0 ] == '$' ) + { + KeyValues* pNext = pChild->GetNextKey(); + + pExpandedKV->RemoveSubKey( pChild ); + pChild->deleteThis(); + pChild = pNext; + } + else + pChild = pChild->GetNextKey(); + } + } + + + // We don't need to clean up the KeyValues we created, so clear the AD. + autoCleanup_pExpandedKV.Assign( NULL ); + + ( *pOutAllocdNew ) = bRequiresCleanup; + return pExpandedKV; +} + +// ------------------------------------------------------------------------------------------------ +bool HasTemplateOrVariables( const char** ppOutTemplateName, KeyValues* pKV) +{ + Assert( ppOutTemplateName ); + + bool retVal = false; + ( *ppOutTemplateName ) = NULL; + + FOR_EACH_SUBKEY( pKV, pChild ) + { + const char* pName = pChild->GetName(); + if ( V_stricmp( pName, "implements" ) == 0 ) + { + ( *ppOutTemplateName ) = pChild->GetString(); + retVal = true; + } + + if ( pName[ 0 ] == '$' ) + retVal = true; + } + + return retVal; +} + +// ------------------------------------------------------------------------------------------------ +CTextureCompositor* CreateTextureCompositor( int _w, int _h, const char* pCompositeName, int nTeamNum, uint64 nRandomSeed, KeyValues* _stageDesc, uint32 nTexCompositeCreateFlags ) +{ + TM_ZONE_DEFAULT( TELEMETRY_LEVEL0 ); + + #ifdef STAGING_ONLY + if ( r_texcomp_dump.GetInt() == 3 || r_texcomp_dump.GetInt() == 4 ) + { + // Skip compression because it breaks saving render targets out + // Also don't pollute the cache (or use it) + nTexCompositeCreateFlags |= ( TEX_COMPOSITE_CREATE_FLAGS_NO_COMPRESSION | TEX_COMPOSITE_CREATE_FLAGS_FORCE ); + } + #endif + + CUtlVector< CTCStage* > vecStage; + CUtlVector< KeyValues* > kvs; + + KeyValuesAD kvAutoCleanup( (KeyValues*) nullptr ); + + bool bRequiresCleanup = false; + + if ( ( nTexCompositeCreateFlags & TEX_COMPOSITE_CREATE_FLAGS_LOG_NODES_ONLY ) != 0 ) + { + DevMsg( 0, "%s\n{\n", pCompositeName ); + KeyValuesDumpAsDevMsg( _stageDesc, 1, 0 ); + DevMsg( 0, "}\n" ); + } + + _stageDesc = ParseTopLevelIntoKV( pCompositeName, _stageDesc, nTexCompositeCreateFlags, &bRequiresCleanup ); + if ( !_stageDesc ) + { + if ( ( nTexCompositeCreateFlags & TEX_COMPOSITE_CREATE_FLAGS_LOG_NODES_ONLY ) != 0 ) + Msg( "ERROR[%s]: Failed to create compositor, errors above.\n", pCompositeName ); + + return NULL; + } + + // Set ourselves up for future cleanup. + if ( bRequiresCleanup ) + kvAutoCleanup.Assign( _stageDesc ); + + if ( nTexCompositeCreateFlags & TEX_COMPOSITE_CREATE_FLAGS_LOG_NODES_ONLY ) + { + if ( bRequiresCleanup ) + { + DevMsg( 0, "With expansion:\n%s\n{\n", pCompositeName ); + KeyValuesDumpAsDevMsg( _stageDesc, 1, 0 ); + DevMsg( 0, "}\n" ); + } + return NULL; + } + + const char* pTemplateName = NULL; + // If we're just doing a template verification, and we still have keys or values that look like template stuff, bail out now. + if ( HasTemplateOrVariables( &pTemplateName, _stageDesc ) && ( ( nTexCompositeCreateFlags & TEX_COMPOSITE_CREATE_FLAGS_VERIFY_TEMPLATE_ONLY ) != 0 ) ) + { + CTextureCompositor* pComp = new CTextureCompositor( _w, _h, nTeamNum, pCompositeName, nRandomSeed, nTexCompositeCreateFlags ); + if ( pTemplateName ) + pComp->SetTemplate( pTemplateName ); + return pComp; + } + + KeyValues* kv = _stageDesc->GetFirstTrueSubKey(); + if ( !kv ) + return NULL; + + kvs.AddToTail( kv ); + + if ( !ParseNodes( &vecStage, kvs, nTexCompositeCreateFlags ) ) + { + FOR_EACH_VEC( vecStage, i ) + { + SafeRelease( &vecStage[ i ] ); + } + + return NULL; + } + + // Should only get 1 here. + Assert( vecStage.Count() == 1 ); + + CTCStage* rootStage = vecStage[ 0 ]; + + // Need to add a copy as the new root. + CTCStage* copyStage = new CTCCopyStage; + copyStage->SetFirstChild( rootStage ); + rootStage = copyStage; + + CTextureCompositor* texCompositor = new CTextureCompositor( _w, _h, nTeamNum, pCompositeName, nRandomSeed, nTexCompositeCreateFlags ); + if ( pTemplateName ) + texCompositor->SetTemplate( pTemplateName ); + + texCompositor->SetRootStage( rootStage ); + + SafeRelease( &rootStage ); + + return texCompositor; +} + +// ------------------------------------------------------------------------------------------------ +CTextureCompositorTemplate* CTextureCompositorTemplate::Create( const char* pName, KeyValues* pTmplDesc ) +{ + if ( !pName || !pTmplDesc ) + return NULL; + + CTextureCompositor* texCompositor = CreateTextureCompositor( 1, 1, pName, 2, 0, pTmplDesc, TEX_COMPOSITE_CREATE_FLAGS_VERIFY_SCHEMA_ONLY | TEX_COMPOSITE_CREATE_FLAGS_VERIFY_TEMPLATE_ONLY ); + + if ( texCompositor ) + { + CTextureCompositorTemplate* pTemplate = new CTextureCompositorTemplate( pName, pTmplDesc ); + if ( texCompositor->UsesTemplate() ) + { + pTemplate->SetImplementsName( texCompositor->GetTemplateName() ); + } + // Bump then release the ref. + texCompositor->AddRef(); + texCompositor->Release(); + + return pTemplate; + } + + return NULL; +} + +// ------------------------------------------------------------------------------------------------ +CTextureCompositorTemplate::~CTextureCompositorTemplate() +{ + // We don't own the KV we were created with--don't delete it. +} + +// ------------------------------------------------------------------------------------------------ +bool CTextureCompositorTemplate::ResolveDependencies() const +{ + // If we don't reference another template, then our verification was validated at construction + // time. + if ( m_ImplementsName.IsEmpty() ) + return true; + + CTextureCompositorTemplate* pImplementsTmpl = TextureManager()->FindTextureCompositorTemplate( m_ImplementsName ); + + // If we couldn't find our child, then we are not okay. + if ( pImplementsTmpl == NULL ) + { + Warning( "ERROR[paintkit_template %s]: Couldn't find template '%s' which we claim to implement.\n", (const char*) m_Name, (const char*)m_ImplementsName ); + return false; + } + + return true; +} + +// ------------------------------------------------------------------------------------------------ +bool CTextureCompositorTemplate::HasDependencyCycles() +{ + // Uses Floyd's algorithm to determine if there's a cycle. + TM_ZONE_DEFAULT( TELEMETRY_LEVEL1 ); + + if ( HasCycle( this ) ) + { + // Print the cycle. This also marks the nodes as having been tested for cycles. + PrintMinimumCycle( this ); + return true; + } + else + { + // Mark everything in this lineage as having been tested for cycles. + CTextureCompositorTemplate* pTmpl = this; + while ( pTmpl != NULL ) + { + if ( pTmpl->HasCheckedForCycles() ) + break; + + pTmpl->SetCheckedForCycles( true ); + pTmpl = Advance( pTmpl, 1 ); + } + } + + return false; +} + +// ------------------------------------------------------------------------------------------------ +// ------------------------------------------------------------------------------------------------ +// ------------------------------------------------------------------------------------------------ +void ComputeTextureMatrixFromRectangle( VMatrix* pOutMat, const Vector2D& bl, const Vector2D& tl, const Vector2D& tr ) +{ + Assert( pOutMat != NULL ); + + Vector2D leftEdge = bl - tl; + Vector2D topEdge = tr - tl; + Vector2D topEdgePerpLeft( -topEdge.y, topEdge.x ); + + float magLeftEdge = leftEdge.Length(); + float magTopEdge = topEdge.Length(); + + float xScalar = ( topEdgePerpLeft.Dot( leftEdge ) > 0 ) ? 1 : -1; + + + // Simplification of acos( ( A . L ) / ( mag( A ) * mag( L ) ) + // Because A is ( 0, 1), which means A . L is just L.y + // and mag( A ) * mag( L ) is just mag( L ) + float rotationD = RAD2DEG( acos( leftEdge.y / magLeftEdge ) ) + * ( leftEdge.x < 0 ? 1 : -1 ); + + VMatrix tmpMat; + tmpMat.Identity(); + MatrixTranslate( tmpMat, Vector( tl.x, tl.y, 0 ) ); + MatrixRotate( tmpMat, Vector( 0, 0, 1 ), rotationD ); + tmpMat = tmpMat.Scale( Vector( xScalar * magTopEdge, magLeftEdge, 1.0f ) ); + MatrixInverseGeneral( tmpMat, *pOutMat ); + + // Copy W into Z because this is a 2-D matrix. + ( *pOutMat )[ 0 ][ 2 ] = ( *pOutMat )[ 0 ][ 3 ]; + ( *pOutMat )[ 1 ][ 2 ] = ( *pOutMat )[ 1 ][ 3 ]; + ( *pOutMat )[ 2 ][ 2 ] = 1.0f; +} + +// ------------------------------------------------------------------------------------------------ +// ------------------------------------------------------------------------------------------------ +// ------------------------------------------------------------------------------------------------ +CTextureCompositorTemplate* Advance( CTextureCompositorTemplate* pTmpl, int nSteps ) +{ + Assert( pTmpl != NULL ); + + for ( int i = 0; i < nSteps; ++i ) + { + if ( pTmpl->ImplementsTemplate() ) + { + pTmpl = TextureManager()->FindTextureCompositorTemplate( pTmpl->GetImplementsName() ); + } + else + return NULL; + } + + return pTmpl; +} + +// ------------------------------------------------------------------------------------------------ +bool HasCycle( CTextureCompositorTemplate* pStartTempl ) +{ + Assert( pStartTempl != NULL ); + + CTextureCompositorTemplate* pTortoise = pStartTempl; + CTextureCompositorTemplate* pHare = Advance( pStartTempl, 1 ); + + while ( pHare != NULL ) + { + Assert( pTortoise != NULL ); // pTortoise should never be NULL unless pHare already is. + + if ( pTortoise == pHare ) + return true; + + // There may still actually be a cycle here, but we've already reported it if so, + // so go ahead and bail out and say "no cycle found." + if ( pTortoise->HasCheckedForCycles() || pHare->HasCheckedForCycles() ) + return false; + + pTortoise = Advance( pTortoise, 1 ); + pHare = Advance( pHare, 1 ); + } + + return false; +} + +// ------------------------------------------------------------------------------------------------ +void PrintMinimumCycle( CTextureCompositorTemplate* pTmpl ) +{ + TM_ZONE_DEFAULT( TELEMETRY_LEVEL1 ); + + const char* pFirstNodeName = pTmpl->GetName(); + // Also mark the nodes as having been cycle-tested to save execution of retesting the same templates. + + // Finding a minimum cycle is O( n log n ) using a map, but we only do this when there's an error. + CUtlMap< CTextureCompositorTemplate*, int > cycles( DefLessFunc( CTextureCompositorTemplate* ) ); + CUtlLinkedList< const char* > cycleBuilder; + + while ( pTmpl != NULL) + { + // Add before we bail so that the first looping element is in the list twice. + cycleBuilder.AddToTail( pTmpl->GetName() ); + + if ( cycles.IsValidIndex( cycles.Find( pTmpl ) ) ) + break; + + pTmpl->SetCheckedForCycles( true ); + cycles.Insert( pTmpl ); + pTmpl = Advance( pTmpl, 1 ); + } + + // If this hits, we didn't actually have a cycle. What? + Assert( pTmpl ); + + Warning( "ERROR[paintkit_template %s]: Detected cycle in paintkit template dependency chain: ", pFirstNodeName ); + FOR_EACH_LL( cycleBuilder, i ) + { + Warning( "%s -> ", cycleBuilder[ i ] ); + } + + Warning( "...\n" ); +} + diff --git a/materialsystem/ctexturecompositor.h b/materialsystem/ctexturecompositor.h new file mode 100644 index 0000000..2079de7 --- /dev/null +++ b/materialsystem/ctexturecompositor.h @@ -0,0 +1,132 @@ +//========= Copyright Valve Corporation, All rights reserved. ================================== // +// +// Purpose: Defines a texture compositor which uses simple operations and shaders to +// create complex procedural textures. +// +//============================================================================================== // + +#ifndef CTEXTURECOMPOSITOR_H +#define CTEXTURECOMPOSITOR_H + +#include "materialsystem/itexturecompositor.h" +#include "materialsystem/combineoperations.h" + +class CTCStage; + +// ------------------------------------------------------------------------------------------------ +struct RenderTarget_t +{ + int m_nWidth; + int m_nHeight; + ITexture* m_pRT; +}; + +// ------------------------------------------------------------------------------------------------ +class CTextureCompositor : public ITextureCompositor +{ +public: + CTextureCompositor( int _width, int _height, int nTeam, const char* pCompositeName, uint64 nRandomSeed, uint32 nTexCompositeCreateFlags ); + + virtual int AddRef() OVERRIDE; + virtual int Release() OVERRIDE; + virtual int GetRefCount() const OVERRIDE { return m_nReferenceCount; } + + virtual void Update() OVERRIDE; + virtual ITexture* GetResultTexture() const OVERRIDE; + virtual ECompositeResolveStatus GetResolveStatus() const OVERRIDE; + virtual void ScheduleResolve() OVERRIDE; + + void Resolve(); + + void Error( bool _retry, PRINTF_FORMAT_STRING const char* _debugDevMsg, ... ); + + void SetRootStage( CTCStage* _rootStage ); + + ITexture* AllocateCompositorRenderTarget( ); + void ReleaseCompositorRenderTarget( ITexture* _tex ); + + int GetTeamNumber() const { return m_nTeam; } + const CUtlString& GetName() const { return m_CompositeName; } + uint32 GetCreateFlags() const { return m_nTexCompositeCreateFlags; } + void GetTextureName( char* pOutBuffer, int nBufferLen ) const; + void GetSeed( uint32* pOutHi, uint32* pOutLo ) const; + + void SetTemplate( const char* pTemplate ) { m_TemplateName = pTemplate; } + bool UsesTemplate() const { return m_TemplateName.IsEmpty() == false; } + const CUtlString& GetTemplateName() const { return m_TemplateName; } + +protected: + virtual ~CTextureCompositor(); + void Restart(); + +private: + void Shutdown(); + + CInterlockedInt m_nReferenceCount; + + int m_nWidth; + int m_nHeight; + int m_nTeam; + uint64 m_nRandomSeed; + CTCStage* m_pRootStage; + ECompositeResolveStatus m_ResolveStatus; + + // Did an error occur + bool m_bError; + // And is it fatal, or should we try again? + bool m_bFatal; + + CUtlVector m_RenderTargetPool; + int m_nRenderTargetsAllocated; + int m_nCompositePaintKitId; + + CUtlString m_CompositeName; + CUtlString m_TemplateName; + uint32 m_nTexCompositeCreateFlags; + bool m_bHasTeamSpecifics; +}; + +// ------------------------------------------------------------------------------------------------ +class CTextureCompositorTemplate +{ +public: + static CTextureCompositorTemplate* Create( const char* pName, KeyValues* pTmplDesc ); + ~CTextureCompositorTemplate(); + + /* const */ KeyValues* GetKV() /* const */ { return m_pKV; } + const CUtlString& GetName() const { return m_Name; } + + bool ResolveDependencies() const; + bool HasDependencyCycles(); // Not const because we update m_bCheckedForCycles + + void SetImplementsName( const CUtlString& implementsName ) { m_ImplementsName = implementsName; } + bool ImplementsTemplate() const { return m_ImplementsName.IsEmpty() == false; } + const CUtlString& GetImplementsName() const { return m_ImplementsName; } + + void SetCheckedForCycles( bool checked ) { m_bCheckedForCycles = checked; } + bool HasCheckedForCycles() const { return m_bCheckedForCycles; } + +private: + CTextureCompositorTemplate( const char* pName, KeyValues* pKV ) + : m_pKV( pKV ) + , m_Name( pName ) + , m_bCheckedForCycles( false ) + { } + + KeyValues* m_pKV; + + // Our own name + CUtlString m_Name; + + // If we are an implementation of another template, what is that template's name? + CUtlString m_ImplementsName; + + // Have we checked this template and it's hierarchy for cycles? If so we can early out on future checks. + bool m_bCheckedForCycles; +}; + +// ------------------------------------------------------------------------------------------------ +const char *GetCombinedMaterialName( ECombineOperation eMaterial ); +CTextureCompositor* CreateTextureCompositor( int _w, int _h, const char* pCompositeName, int nTeamNum, uint64 _randomSeed, KeyValues* _stageDesc, uint32 texCompositeCreateFlags ); + +#endif /* CTEXTURECOMPOSITOR_H */ diff --git a/materialsystem/genshadermacro.pl b/materialsystem/genshadermacro.pl new file mode 100644 index 0000000..0f51d65 --- /dev/null +++ b/materialsystem/genshadermacro.pl @@ -0,0 +1,105 @@ +for( $i = 0; $i < 16; $i++ ) +{ + print "\#define SHADER_CLASS$i(name,help"; + for( $j = 0; $j < $i; $j++ ) + { + print ",p$j,p$j" . "type,p$j" . "default,p$j" . "help\\\n\t\t"; + } + print ")\\\n"; + print "\tstatic const char *s_HelpString = help;\\\n"; + print "\tstatic const char *s_ParamNames[] = {"; + if( $i == 0 ) + { + print "NULL"; + } + else + { + for( $j = 0; $j < $i; $j++ ) + { + print "\\\n\t\t\"\$\" #p$j"; + if( $j != $i - 1 ) + { + print ","; + } + } + } + print "\\\n\t};\\\n"; + + print "\tstatic ShaderParamType_t s_ParamType[] = {"; + if( $i == 0 ) + { + print "SHADER_PARAM_TYPE_INTEGER"; + } + else + { + for( $j = 0; $j < $i; $j++ ) + { + print "\\\n\t\tp$j" . "type"; + if( $j != $i - 1 ) + { + print ","; + } + } + } + print "\\\n\t};\\\n"; + + print "\tstatic const char *s_ParamDefault[] = {"; + if( $i == 0 ) + { + print "\"\""; + } + else + { + for( $j = 0; $j < $i; $j++ ) + { + print "\\\n\t\tp$j" . "default"; + if( $j != $i - 1 ) + { + print ","; + } + } + } + print "\\\n\t};\\\n"; + + print "\tstatic const char *s_ParamHelp[] = {"; + if( $i == 0 ) + { + print "\"\""; + } + else + { + for( $j = 0; $j < $i; $j++ ) + { + print "\\\n\t\tp$j" . "help"; + if( $j != $i - 1 ) + { + print ","; + } + } + } + print "\\\n\t};\\\n"; + + + print "\\\n\tenum {"; + if( $i == 0 ) + { + print "DUMMY_PARAM"; + } + else + { + for( $j = 0; $j < $i; $j++ ) + { + print "\\\n\t\tp$j"; + if( $j == 0 ) + { + print " = NUM_SHADER_MATERIAL_VARS"; + } + if( $j != $i - 1 ) + { + print ","; + } + } + } + print "\\\n\t};\\\n"; + print "\tstatic const char *s_Name = #name;\\\n\tclass CShader_ ## name : public Shader_t\n\n"; +} diff --git a/materialsystem/imagepacker.cpp b/materialsystem/imagepacker.cpp new file mode 100644 index 0000000..882639f --- /dev/null +++ b/materialsystem/imagepacker.cpp @@ -0,0 +1,169 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//=====================================================================================// + +#include "imagepacker.h" +#include "materialsystem_global.h" +#include "IHardwareConfigInternal.h" + +// NOTE: This has to be the last file included +#include "tier0/memdbgon.h" + +float CImagePacker::GetEfficiency( void ) +{ + return ( float )m_AreaUsed / ( float )( m_MaxLightmapWidth * CeilPow2( m_MinimumHeight ) ); +} + +bool CImagePacker::Reset( int nSortId, int maxLightmapWidth, int maxLightmapHeight ) +{ + int i; + + Assert( maxLightmapWidth <= MAX_MAX_LIGHTMAP_WIDTH ); + + m_MaxLightmapWidth = maxLightmapWidth; + m_MaxLightmapHeight = maxLightmapHeight; + + m_MaxBlockWidth = maxLightmapWidth + 1; + m_MaxBlockHeight = maxLightmapHeight + 1; + + m_nSortID = nSortId; + + m_AreaUsed = 0; + m_MinimumHeight = -1; + for( i = 0; i < m_MaxLightmapWidth; i++ ) + { + m_pLightmapWavefront[i] = -1; + } + return true; +} + +inline int CImagePacker::GetMaxYIndex( int firstX, int width ) +{ + int maxY = -1; + int maxYIndex = 0; + for( int x = firstX; x < firstX + width; ++x ) + { + // NOTE: Want the equals here since we'll never be able to fit + // in between the multiple instances of maxY + if( m_pLightmapWavefront[x] >= maxY ) + { + maxY = m_pLightmapWavefront[x]; + maxYIndex = x; + } + } + return maxYIndex; +} + +//#define ADD_ONE_TEXEL_BORDER + +bool CImagePacker::AddBlock( int width, int height, + int *returnX, int *returnY ) +{ +#ifdef ADD_ONE_TEXEL_BORDER + width += 2; + height += 2; + width = clamp( width, m_MaxLightmapWidth ); + height = clamp( height, m_MaxLightmapHeight ); +#endif + + // If we've already determined that a block this big couldn't fit + // then blow off checking again... + if ( ( width >= m_MaxBlockWidth ) && ( height >= m_MaxBlockHeight ) ) + return false; + + int bestX = -1; + int maxYIdx; + int outerX = 0; + int outerMinY = m_MaxLightmapHeight; + int lastX = m_MaxLightmapWidth - width; + int lastMaxYVal = -2; + while (outerX <= lastX) + { + // Skip all tiles that have the last Y value, these + // aren't going to change our min Y value + if (m_pLightmapWavefront[outerX] == lastMaxYVal) + { + ++outerX; + continue; + } + + maxYIdx = GetMaxYIndex( outerX, width ); + lastMaxYVal = m_pLightmapWavefront[maxYIdx]; + if (outerMinY > lastMaxYVal) + { + outerMinY = lastMaxYVal; + bestX = outerX; + + // Early out for the first row... +// if (outerMinY == -1) +// break; + } + outerX = maxYIdx + 1; + } + + if( bestX == -1 ) + { + // If we failed to add it, remember the block size that failed + // *only if both dimensions are smaller*!! + // Just because a 1x10 block failed, doesn't mean a 10x1 block will fail + if ( ( width <= m_MaxBlockWidth ) && ( height <= m_MaxBlockHeight ) ) + { + m_MaxBlockWidth = width; + m_MaxBlockHeight = height; + } + + return false; + } + + // Set the return positions for the block. + *returnX = bestX; + *returnY = outerMinY + 1; + + // Check if it actually fit height-wise. + // hack + // if( *returnY + height > maxLightmapHeight ) + if( *returnY + height >= m_MaxLightmapHeight - 1 ) + { + if ( ( width <= m_MaxBlockWidth ) && ( height <= m_MaxBlockHeight ) ) + { + m_MaxBlockWidth = width; + m_MaxBlockHeight = height; + } + + return false; + } + + // It fit! + // Keep up with the smallest possible size for the image so far. + if( *returnY + height > m_MinimumHeight ) + m_MinimumHeight = *returnY + height; + + // Update the wavefront info. + int x; + for( x = bestX; x < bestX + width; x++ ) + { + m_pLightmapWavefront[x] = outerMinY + height; + } + + // AddBlockToLightmapImage( *returnX, *returnY, width, height ); + m_AreaUsed += width * height; +#ifdef ADD_ONE_TEXEL_BORDER + *returnX++; + *returnY++; +#endif + return true; +} + +void CImagePacker::GetMinimumDimensions( int *pReturnWidth, int *pReturnHeight ) +{ + *pReturnWidth = CeilPow2( m_MaxLightmapWidth ); + *pReturnHeight = CeilPow2( m_MinimumHeight ); + + int aspect = *pReturnWidth / *pReturnHeight; + if (aspect > HardwareConfig()->MaxTextureAspectRatio()) + { + *pReturnHeight = *pReturnWidth / HardwareConfig()->MaxTextureAspectRatio(); + } +} diff --git a/materialsystem/imagepacker.h b/materialsystem/imagepacker.h new file mode 100644 index 0000000..f15bbbc --- /dev/null +++ b/materialsystem/imagepacker.h @@ -0,0 +1,69 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $Workfile: $ +// $Date: $ +// $NoKeywords: $ +//=============================================================================// + +#ifndef IMAGEPACKER_H +#define IMAGEPACKER_H + +#ifdef _WIN32 +#pragma once +#endif + +#include "utlvector.h" +#include "utlrbtree.h" + +#define MAX_MAX_LIGHTMAP_WIDTH 2048 + + +//----------------------------------------------------------------------------- +// This packs a single lightmap +//----------------------------------------------------------------------------- +class CImagePacker +{ +public: + bool Reset( int nSortId, int maxLightmapWidth, int maxLightmapHeight ); + bool AddBlock( int width, int height, + int *returnX, int *returnY ); + void GetMinimumDimensions( int *returnWidth, int *returnHeight ); + float GetEfficiency( void ); + int GetSortId() const; + void IncrementSortId(); + +protected: + int GetMaxYIndex( int firstX, int width ); + + int m_MaxLightmapWidth; + int m_MaxLightmapHeight; + int m_pLightmapWavefront[MAX_MAX_LIGHTMAP_WIDTH]; + int m_AreaUsed; + int m_MinimumHeight; + + // For optimization purposes: + // These store the width + height of the first image + // that was unable to be stored in this image + int m_MaxBlockWidth; + int m_MaxBlockHeight; + int m_nSortID; +}; + + +//----------------------------------------------------------------------------- +// Inline methods +//----------------------------------------------------------------------------- +inline int CImagePacker::GetSortId() const +{ + return m_nSortID; +} + +inline void CImagePacker::IncrementSortId() +{ + ++m_nSortID; +} + + +#endif // IMAGEPACKER_H diff --git a/materialsystem/imaterialinternal.h b/materialsystem/imaterialinternal.h new file mode 100644 index 0000000..693b709 --- /dev/null +++ b/materialsystem/imaterialinternal.h @@ -0,0 +1,161 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +// +//=============================================================================// + +#ifndef IMATERIALINTERNAL_H +#define IMATERIALINTERNAL_H + +#ifdef _WIN32 +#pragma once +#endif + +// identifier was truncated to '255' characters in the debug information +#pragma warning(disable: 4786) + +#include "materialsystem/imaterialsystem.h" +#include "materialsystem/imaterial.h" +#include "shaderapi/ishaderapi.h" +#include "filesystem.h" + + +//----------------------------------------------------------------------------- +// forward declarations +//----------------------------------------------------------------------------- +enum MaterialPrimitiveType_t; +class IShader; +class IMesh; +class IVertexBuffer; +class IIndexBuffer; +struct Shader_VertexArrayData_t; +struct ShaderRenderState_t; +class KeyValues; + +//----------------------------------------------------------------------------- +// Interface for materials used only within the material system +//----------------------------------------------------------------------------- +abstract_class IMaterialInternal : public IMaterial +{ +public: + // class factory methods + static IMaterialInternal* CreateMaterial( char const* pMaterialName, const char *pTextureGroupName, KeyValues *pKeyValues = NULL ); + static void DestroyMaterial( IMaterialInternal* pMaterial ); + + // If supplied, pKeyValues and pPatchKeyValues should come from LoadVMTFile() + static IMaterialInternal* CreateMaterialSubRect( char const* pMaterialName, const char *pTextureGroupName, + KeyValues *pKeyValues = NULL, KeyValues *pPatchKeyValues = NULL, bool bAssumeCreateFromFile = false ); + static void DestroyMaterialSubRect( IMaterialInternal* pMaterial ); + + // refcount + virtual int GetReferenceCount( ) const = 0; + + // enumeration id + virtual void SetEnumerationID( int id ) = 0; + + // White lightmap methods + virtual void SetNeedsWhiteLightmap( bool val ) = 0; + virtual bool GetNeedsWhiteLightmap( ) const = 0; + + // load/unload + virtual void Uncache( bool bPreserveVars = false ) = 0; + virtual void Precache() = 0; + // If supplied, pKeyValues and pPatchKeyValues should come from LoadVMTFile() + virtual bool PrecacheVars( KeyValues *pKeyValues = NULL, KeyValues *pPatchKeyValues = NULL, CUtlVector *pIncludes = NULL, int nFindContext = MATERIAL_FINDCONTEXT_NONE ) = 0; + + // reload all textures used by this materals + virtual void ReloadTextures() = 0; + + // lightmap pages associated with this material + virtual void SetMinLightmapPageID( int pageID ) = 0; + virtual void SetMaxLightmapPageID( int pageID ) = 0;; + virtual int GetMinLightmapPageID( ) const = 0; + virtual int GetMaxLightmapPageID( ) const = 0; + + virtual IShader *GetShader() const = 0; + + // Can we use it? + virtual bool IsPrecached( ) const = 0; + virtual bool IsPrecachedVars() const = 0; + + // main draw method + virtual void DrawMesh( VertexCompressionType_t vertexCompression ) = 0; + + // Gets the vertex format + virtual VertexFormat_t GetVertexFormat() const = 0; + virtual VertexFormat_t GetVertexUsage() const = 0; + + // Performs a debug trace on this material + virtual bool PerformDebugTrace() const = 0; + + // Can we override this material in debug? + virtual bool NoDebugOverride() const = 0; + + // Should we draw? + virtual void ToggleSuppression() = 0; + + // Are we suppressed? + virtual bool IsSuppressed() const = 0; + + // Should we debug? + virtual void ToggleDebugTrace() = 0; + + // Do we use fog? + virtual bool UseFog() const = 0; + + // Adds a material variable to the material + virtual void AddMaterialVar( IMaterialVar *pMaterialVar ) = 0; + + // Gets the renderstate + virtual ShaderRenderState_t *GetRenderState() = 0; + + // Was this manually created (not read from a file?) + virtual bool IsManuallyCreated() const = 0; + + virtual bool NeedsFixedFunctionFlashlight() const = 0; + + virtual bool IsUsingVertexID() const = 0; + + // Identifies a material mounted through the preload path + virtual void MarkAsPreloaded( bool bSet ) = 0; + virtual bool IsPreloaded() const = 0; + + // Conditonally increments the refcount + virtual void ArtificialAddRef( void ) = 0; + virtual void ArtificialRelease( void ) = 0; + + virtual void ReportVarChanged( IMaterialVar *pVar ) = 0; + virtual uint32 GetChangeID() const = 0; + + virtual bool IsTranslucentInternal( float fAlphaModulation ) const = 0; + + //Is this the queue friendly or realtime version of the material? + virtual bool IsRealTimeVersion( void ) const = 0; + + virtual void ClearContextData( void ) + { + } + + //easy swapping between the queue friendly and realtime versions of the material + virtual IMaterialInternal *GetRealTimeVersion( void ) = 0; + virtual IMaterialInternal *GetQueueFriendlyVersion( void ) = 0; + + virtual void PrecacheMappingDimensions( void ) = 0; + virtual void FindRepresentativeTexture( void ) = 0; + + // These are used when a new whitelist is passed in. First materials to be reloaded are flagged, then they are reloaded. + virtual void DecideShouldReloadFromWhitelist( IFileList *pFileList ) = 0; + virtual void ReloadFromWhitelistIfMarked() = 0; +}; + +extern void InsertKeyValues( KeyValues& dst, KeyValues& src, bool bCheckForExistence, bool bRecursive = false ); +extern void WriteKeyValuesToFile( const char *pFileName, KeyValues& keyValues ); +extern void ExpandPatchFile( KeyValues& keyValues, KeyValues &patchKeyValues ); +// patchKeyValues accumulates keys applied by VMT patch files (this is necessary to make $fallbackmaterial +// work properly - the patch keys need to be reapplied when the fallback VMT is loaded). It may contain +// previously accumulated patch keys on entry, and may contain more encountered patch keys on exit. +extern bool LoadVMTFile( KeyValues &vmtKeyValues, KeyValues &patchKeyValues, const char *pMaterialName, bool bUsesUNCFilename, CUtlVector *pIncludes ); + +#endif // IMATERIALINTERNAL_H diff --git a/materialsystem/imaterialsysteminternal.h b/materialsystem/imaterialsysteminternal.h new file mode 100644 index 0000000..dc55bfa --- /dev/null +++ b/materialsystem/imaterialsysteminternal.h @@ -0,0 +1,224 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +// +//=============================================================================// + +#ifndef IMATERIALSYSTEMINTERNAL_H +#define IMATERIALSYSTEMINTERNAL_H + +#ifdef _WIN32 +#pragma once +#endif + +#include "materialsystem/imaterialsystem.h" +#include "tier1/callqueue.h" +#include "tier1/memstack.h" + +class IMaterialInternal; + +//----------------------------------------------------------------------------- +// Special call queue that knows (a) single threaded access, and (b) all +// functions called after last function added +//----------------------------------------------------------------------------- + +class CMatCallQueue +{ +public: + CMatCallQueue() + { + MEM_ALLOC_CREDIT_( "CMatCallQueue.m_Allocator" ); +#ifdef SWDS + m_Allocator.Init( 2*1024, 0, 0, 4 ); +#else + m_Allocator.Init( IsX360() ? 2*1024*1024 : 8*1024*1024, 64*1024, 256*1024, 4 ); +#endif + m_FunctorFactory.SetAllocator( &m_Allocator ); + m_pHead = m_pTail = NULL; + } + + size_t GetMemoryUsed() + { + return m_Allocator.GetUsed(); + } + + int Count() + { + int i = 0; + Elem_t *pCurrent = m_pHead; + while ( pCurrent ) + { + i++; + pCurrent = pCurrent->pNext; + } + return i; + } + + void CallQueued() + { + if ( !m_pHead ) + { + return; + } + + CFunctor *pFunctor; + + Elem_t *pCurrent = m_pHead; + while ( pCurrent ) + { + pFunctor = pCurrent->pFunctor; +#ifdef _DEBUG + if ( pFunctor->m_nUserID == m_nBreakSerialNumber) + { + m_nBreakSerialNumber = (unsigned)-1; + } +#endif + (*pFunctor)(); + pFunctor->Release(); + pCurrent = pCurrent->pNext; + } + m_Allocator.FreeAll( false ); + m_pHead = m_pTail = NULL; + } + + void QueueFunctor( CFunctor *pFunctor ) + { + Assert( pFunctor ); + QueueFunctorInternal( RetAddRef( pFunctor ) ); + } + + void Flush() + { + if ( !m_pHead ) + { + return; + } + + CFunctor *pFunctor; + + Elem_t *pCurrent = m_pHead; + while ( pCurrent ) + { + pFunctor = pCurrent->pFunctor; + pFunctor->Release(); + pCurrent = pCurrent->pNext; + } + + m_Allocator.FreeAll( false ); + m_pHead = m_pTail = NULL; + } + + #define DEFINE_MATCALLQUEUE_NONMEMBER_QUEUE_CALL(N) \ + template \ + void QueueCall(FUNCTION_RETTYPE (*pfnProxied)( FUNC_BASE_TEMPLATE_FUNC_PARAMS_##N ) FUNC_ARG_FORMAL_PARAMS_##N ) \ + { \ + QueueFunctorInternal( m_FunctorFactory.CreateFunctor( pfnProxied FUNC_FUNCTOR_CALL_ARGS_##N ) ); \ + } + + //------------------------------------- + + #define DEFINE_MATCALLQUEUE_MEMBER_QUEUE_CALL(N) \ + template \ + void QueueCall(OBJECT_TYPE_PTR pObject, FUNCTION_RETTYPE ( FUNCTION_CLASS::*pfnProxied )( FUNC_BASE_TEMPLATE_FUNC_PARAMS_##N ) FUNC_ARG_FORMAL_PARAMS_##N ) \ + { \ + QueueFunctorInternal( m_FunctorFactory.CreateFunctor( pObject, pfnProxied FUNC_FUNCTOR_CALL_ARGS_##N ) ); \ + } + + //------------------------------------- + + #define DEFINE_MATCALLQUEUE_CONST_MEMBER_QUEUE_CALL(N) \ + template \ + void QueueCall(OBJECT_TYPE_PTR pObject, FUNCTION_RETTYPE ( FUNCTION_CLASS::*pfnProxied )( FUNC_BASE_TEMPLATE_FUNC_PARAMS_##N ) const FUNC_ARG_FORMAL_PARAMS_##N ) \ + { \ + QueueFunctorInternal( m_FunctorFactory.CreateFunctor( pObject, pfnProxied FUNC_FUNCTOR_CALL_ARGS_##N ) ); \ + } + + //------------------------------------- + + FUNC_GENERATE_ALL( DEFINE_MATCALLQUEUE_NONMEMBER_QUEUE_CALL ); + FUNC_GENERATE_ALL( DEFINE_MATCALLQUEUE_MEMBER_QUEUE_CALL ); + FUNC_GENERATE_ALL( DEFINE_MATCALLQUEUE_CONST_MEMBER_QUEUE_CALL ); + +private: + void QueueFunctorInternal( CFunctor *pFunctor ) + { +#ifdef _DEBUG + pFunctor->m_nUserID = m_nCurSerialNumber++; +#endif + MEM_ALLOC_CREDIT_( "CMatCallQueue.m_Allocator" ); + Elem_t *pNew = (Elem_t *)m_Allocator.Alloc( sizeof(Elem_t) ); + if ( m_pTail ) + { + m_pTail->pNext = pNew; + m_pTail = pNew; + } + else + { + m_pHead = m_pTail = pNew; + } + pNew->pNext = NULL; + pNew->pFunctor = pFunctor; + } + + struct Elem_t + { + Elem_t *pNext; + CFunctor *pFunctor; + }; + + Elem_t *m_pHead; + Elem_t *m_pTail; + + CMemoryStack m_Allocator; + CCustomizedFunctorFactory > > m_FunctorFactory; + unsigned m_nCurSerialNumber; + unsigned m_nBreakSerialNumber; +}; + + +class IMaterialProxy; + + +//----------------------------------------------------------------------------- +// Additional interfaces used internally to the library +//----------------------------------------------------------------------------- +abstract_class IMaterialSystemInternal : public IMaterialSystem +{ +public: + // Returns the current material + virtual IMaterial* GetCurrentMaterial() = 0; + + virtual int GetLightmapPage( void ) = 0; + + // Gets the maximum lightmap page size... + virtual int GetLightmapWidth( int lightmap ) const = 0; + virtual int GetLightmapHeight( int lightmap ) const = 0; + + virtual ITexture *GetLocalCubemap( void ) = 0; + +// virtual bool RenderZOnlyWithHeightClipEnabled( void ) = 0; + virtual void ForceDepthFuncEquals( bool bEnable ) = 0; + virtual enum MaterialHeightClipMode_t GetHeightClipMode( void ) = 0; + + // FIXME: Remove? Here for debugging shaders in CShaderSystem + virtual void AddMaterialToMaterialList( IMaterialInternal *pMaterial ) = 0; + virtual void RemoveMaterial( IMaterialInternal *pMaterial ) = 0; + virtual void RemoveMaterialSubRect( IMaterialInternal *pMaterial ) = 0; + virtual bool InFlashlightMode() const = 0; + + // Can we use editor materials? + virtual bool CanUseEditorMaterials() const = 0; + virtual const char *GetForcedTextureLoadPathID() = 0; + + virtual CMatCallQueue *GetRenderCallQueue() = 0; + + virtual void UnbindMaterial( IMaterial *pMaterial ) = 0; + virtual uint GetRenderThreadId() const = 0 ; + + virtual IMaterialProxy *DetermineProxyReplacements( IMaterial *pMaterial, KeyValues *pFallbackKeyValues ) = 0; +}; + + +#endif // IMATERIALSYSTEMINTERNAL_H diff --git a/materialsystem/imatrendercontextinternal.h b/materialsystem/imatrendercontextinternal.h new file mode 100644 index 0000000..ed08716 --- /dev/null +++ b/materialsystem/imatrendercontextinternal.h @@ -0,0 +1,79 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//============================================================================= + +#ifndef IMATRENDERCONTEXTINTERNAL_H +#define IMATRENDERCONTEXTINTERNAL_H + +#if defined( _WIN32 ) +#pragma once +#endif + +// typedefs to allow use of delegation macros +typedef Vector4D LightCube_t[6]; + + +abstract_class IMatRenderContextInternal : public IMatRenderContext +{ + // For now, stuck implementing these until IMaterialSystem is reworked + bool Connect(CreateInterfaceFn) { return true; } + void Disconnect(void) {} + void *QueryInterface(const char *pszInterface) { return NULL; } + InitReturnVal_t Init(void) { return INIT_OK; } + void Shutdown(void) {} + +public: + virtual float GetFloatRenderingParameter(int parm_number) const = 0; + virtual int GetIntRenderingParameter(int parm_number) const = 0; + virtual Vector GetVectorRenderingParameter(int parm_number) const = 0; + + virtual void SwapBuffers() = 0; + + virtual void SetCurrentMaterialInternal(IMaterialInternal* pCurrentMaterial) = 0; + virtual IMaterialInternal* GetCurrentMaterialInternal() const = 0; + virtual int GetLightmapPage() = 0; + virtual void ForceDepthFuncEquals( bool) = 0; + + virtual bool InFlashlightMode() const = 0; + virtual void BindStandardTexture( Sampler_t, StandardTextureId_t ) = 0; + virtual void GetLightmapDimensions( int *, int *) = 0; + virtual MorphFormat_t GetBoundMorphFormat() = 0; + virtual ITexture *GetRenderTargetEx( int ) = 0; + virtual void DrawClearBufferQuad( unsigned char, unsigned char, unsigned char, unsigned char, bool, bool, bool ) = 0; + + virtual bool OnDrawMesh( IMesh *pMesh, int firstIndex, int numIndices ) = 0; + virtual bool OnDrawMesh( IMesh *pMesh, CPrimList *pLists, int nLists ) = 0; + virtual bool OnSetFlexMesh( IMesh *pStaticMesh, IMesh *pMesh, int nVertexOffsetInBytes ) = 0; + virtual bool OnSetColorMesh( IMesh *pStaticMesh, IMesh *pMesh, int nVertexOffsetInBytes ) = 0; + virtual bool OnSetPrimitiveType( IMesh *pMesh, MaterialPrimitiveType_t type ) = 0; + virtual bool OnFlushBufferedPrimitives() = 0; + + virtual void SyncMatrices() = 0; + virtual void SyncMatrix( MaterialMatrixMode_t ) = 0; + + virtual void ForceHardwareSync() = 0; + virtual void BeginFrame() = 0; + virtual void EndFrame() = 0; + + virtual void SetFrameTime( float frameTime ) = 0; + virtual void SetCurrentProxy( void *pProxy ) = 0; + virtual void MarkRenderDataUnused( bool bBeginFrame ) = 0; + virtual CMatCallQueue *GetCallQueueInternal() = 0; + + // Map and unmap a texture. The pRecipient->OnAsyncMapComplete is called when complete. + virtual void AsyncMap( ITextureInternal* pTexToMap, IAsyncTextureOperationReceiver* pRecipient, void* pExtraArgs ) = 0; + virtual void AsyncUnmap( ITextureInternal* pTexToUnmap ) = 0; + + // Copy from a render target to a staging texture, in order with other async commands. + virtual void AsyncCopyRenderTargetToStagingTexture( ITexture* pDst, ITexture* pSrc, IAsyncTextureOperationReceiver* pRecipient, void* pExtraArgs ) = 0; + +#ifdef DX_TO_GL_ABSTRACTION + virtual void DoStartupShaderPreloading( void ) = 0; +#endif + + virtual void TextureManagerUpdate() = 0; +}; + +#endif // IMATRENDERCONTEXTINTERNAL_H diff --git a/materialsystem/imorphinternal.h b/materialsystem/imorphinternal.h new file mode 100644 index 0000000..9a7c83c --- /dev/null +++ b/materialsystem/imorphinternal.h @@ -0,0 +1,91 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//============================================================================= + +#ifndef IMORPHINTERNAL_H +#define IMORPHINTERNAL_H + +#ifdef _WIN32 +#pragma once +#endif + +#include "materialsystem/imorph.h" +#include "shaderapi/shareddefs.h" + + +//----------------------------------------------------------------------------- +// Forward declarations +//----------------------------------------------------------------------------- +class ITextureInternal; + + +//----------------------------------------------------------------------------- +// Render context for morphs +//----------------------------------------------------------------------------- +abstract_class IMorphMgrRenderContext +{ +public: +}; + + +//----------------------------------------------------------------------------- +// +// Morph data class +// +//----------------------------------------------------------------------------- +abstract_class IMorphInternal : public IMorph +{ +public: + virtual void Init( MorphFormat_t format, const char *pDebugName ) = 0; + virtual void Bind( IMorphMgrRenderContext *pRenderContext ) = 0; + virtual MorphFormat_t GetMorphFormat() const = 0; +}; + + +//----------------------------------------------------------------------------- +// Morph manager class +//----------------------------------------------------------------------------- +abstract_class IMorphMgr +{ +public: + // Allocate,free scratch textures + materials + virtual bool ShouldAllocateScratchTextures() = 0; + virtual void AllocateScratchTextures() = 0; + virtual void FreeScratchTextures() = 0; + virtual void AllocateMaterials() = 0; + virtual void FreeMaterials() = 0; + + // Returns the morph accumulator scratch texture + virtual ITextureInternal *MorphAccumulator() = 0; + virtual ITextureInternal *MorphWeights() = 0; + + // Class factory + virtual IMorphInternal *CreateMorph() = 0; + virtual void DestroyMorph( IMorphInternal *pMorphData ) = 0; + + // Max morphs between Begin/End + virtual int MaxHWMorphBatchCount() const = 0; + + // Begin, end morph accumulation phase + virtual void BeginMorphAccumulation( IMorphMgrRenderContext *pRenderContext ) = 0; + virtual void EndMorphAccumulation( IMorphMgrRenderContext *pRenderContext ) = 0; + + // Accumulate a morph + virtual void AccumulateMorph( IMorphMgrRenderContext *pRenderContext, IMorph* pMorph, int nMorphCount, const MorphWeight_t* pWeights ) = 0; + + // Advances frame count (for debugging) + virtual void AdvanceFrame() = 0; + + // Returns the location of a particular vertex in the morph accumulator + virtual bool GetMorphAccumulatorTexCoord( IMorphMgrRenderContext *pRenderContext, Vector2D *pTexCoord, IMorph *pMorph, int nVertex ) = 0; + + // Allocate, free morph mgr render context data. + virtual IMorphMgrRenderContext *AllocateRenderContext() = 0; + virtual void FreeRenderContext( IMorphMgrRenderContext *pRenderContext ) = 0; +}; + +extern IMorphMgr *g_pMorphMgr; + +#endif // IMORPHINTERNAL_H diff --git a/materialsystem/itextureinternal.h b/materialsystem/itextureinternal.h new file mode 100644 index 0000000..a6028a6 --- /dev/null +++ b/materialsystem/itextureinternal.h @@ -0,0 +1,190 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +// +//===========================================================================// + +#ifndef ITEXTUREINTERNAL_H +#define ITEXTUREINTERNAL_H + +#ifdef _WIN32 +#pragma once +#endif + +#include "materialsystem/itexture.h" +#include "shaderapi/ishaderapi.h" +#include "tier1/utlmap.h" + +class Vector; +enum Sampler_t; +class IFileList; + +enum RenderTargetType_t +{ + NO_RENDER_TARGET = 0, + // GR - using shared depth buffer + RENDER_TARGET = 1, + // GR - using own depth buffer + RENDER_TARGET_WITH_DEPTH = 2, + // GR - no depth buffer + RENDER_TARGET_NO_DEPTH = 3, + // only cares about depth buffer + RENDER_TARGET_ONLY_DEPTH = 4, +}; + +enum ResidencyType_t +{ + RESIDENT_NONE, + RESIDENT_PARTIAL, + RESIDENT_FULL +}; + +abstract_class ITextureInternal : public ITexture +{ +public: + + virtual void Bind( Sampler_t sampler ) = 0; + virtual void Bind( Sampler_t sampler1, int nFrame, Sampler_t sampler2 = (Sampler_t) -1 ) = 0; + + // Methods associated with reference counting + virtual int GetReferenceCount() = 0; + + virtual void GetReflectivity( Vector& reflectivity ) = 0; + + // Set this as the render target, return false for failure + virtual bool SetRenderTarget( int nRenderTargetID ) = 0; + + // Releases the texture's hw memory + virtual void ReleaseMemory() = 0; + + // Called before Download() on restore. Gives render targets a change to change whether or + // not they force themselves to have a separate depth buffer due to AA. + virtual void OnRestore() = 0; + + // Resets the texture's filtering and clamping mode + virtual void SetFilteringAndClampingMode( bool bOnlyLodValues = false ) = 0; + + // Used by tools.... loads up the non-fallback information about the texture + virtual void Precache() = 0; + + // Stretch blit the framebuffer into this texture. + virtual void CopyFrameBufferToMe( int nRenderTargetID = 0, Rect_t *pSrcRect = NULL, Rect_t *pDstRect = NULL ) = 0; + virtual void CopyMeToFrameBuffer( int nRenderTargetID = 0, Rect_t *pSrcRect = NULL, Rect_t *pDstRect = NULL ) = 0; + + virtual ITexture *GetEmbeddedTexture( int nIndex ) = 0; + + // Get the shaderapi texture handle associated w/ a particular frame + virtual ShaderAPITextureHandle_t GetTextureHandle( int nFrame, int nTextureChannel =0 ) = 0; + + virtual ~ITextureInternal() + { + } + + virtual ImageFormat GetImageFormat() const = 0; + + // Creates a new texture + static ITextureInternal *CreateFileTexture( const char *pFileName, const char *pTextureGroupName ); + + static ITextureInternal *CreateProceduralTexture( + const char *pTextureName, + const char *pTextureGroupName, + int w, + int h, + int d, + ImageFormat fmt, + int nFlags, + ITextureRegenerator *generator = NULL); + + static ITextureInternal *CreateRenderTarget( + const char *pRTName, // NULL for an auto-generated name. + int w, + int h, + RenderTargetSizeMode_t sizeMode, + ImageFormat fmt, + RenderTargetType_t type, + unsigned int textureFlags, + unsigned int renderTargetFlags ); + + static void ChangeRenderTarget( + ITextureInternal *pTexture, + int w, + int h, + RenderTargetSizeMode_t sizeMode, + ImageFormat fmt, + RenderTargetType_t type, + unsigned int textureFlags, + unsigned int renderTargetFlags ); + + static ITextureInternal *CreateReferenceTextureFromHandle( + const char *pTextureName, + const char *pTextureGroupName, + ShaderAPITextureHandle_t hTexture ); + + static void Destroy( ITextureInternal *pTexture, bool bSkipTexMgrCheck = false ); + + // Set this as the render target, return false for failure + virtual bool SetRenderTarget( int nRenderTargetID, ITexture* pDepthTexture ) = 0; + + // Bind this to a vertex texture sampler + virtual void BindVertexTexture( VertexTextureSampler_t sampler, int frameNum = 0 ) = 0; + + virtual void MarkAsPreloaded( bool bSet ) = 0; + virtual bool IsPreloaded() const = 0; + + virtual void MarkAsExcluded( bool bSet, int nDimensionsLimit ) = 0; + virtual bool UpdateExcludedState( void ) = 0; + + virtual bool IsTempRenderTarget( void ) const = 0; + + // Reload any files the texture is responsible for. + virtual void ReloadFilesInList( IFileList *pFilesToReload ) = 0; + + virtual bool AsyncReadTextureFromFile( IVTFTexture* pVTFTexture, unsigned int nAdditionalCreationFlags ) = 0; + virtual void AsyncCancelReadTexture() = 0; + + // Map and unmap. These can fail. And can cause a very significant perf penalty. Be very careful with them. + virtual void Map( void** pOutDst, int* pOutPitch ) = 0; + virtual void Unmap() = 0; + + // Texture streaming! + virtual ResidencyType_t GetCurrentResidence() const = 0; + virtual ResidencyType_t GetTargetResidence() const = 0; + virtual bool MakeResident( ResidencyType_t newResidence ) = 0; + virtual void UpdateLodBias() = 0; +}; + +inline bool IsTextureInternalEnvCubemap( const ITextureInternal *pTexture ) +{ + return ( pTexture == ( ITextureInternal * )-1 ); +} + +//----------------------------------------------------------------------------- +// Ensures that caller provided names are consistent to the dictionary +//----------------------------------------------------------------------------- +inline char *NormalizeTextureName( const char *pName, char *pOutName, int nOutNameSize ) +{ + // hdr textures have an ldr version and need to resolve correctly + int nLen = Q_strlen( pName ) + 1; + if ( nLen <= 5 || Q_stricmp( pName + nLen - 5, ".hdr" ) ) + { + // strip any non .hdr extension + Q_StripExtension( pName, pOutName, nOutNameSize ); + } + else + { + // keep .hdr extension + Q_strncpy( pOutName, pName, nOutNameSize ); + } + + Q_strlower( pOutName ); + Q_FixSlashes( pOutName, '/' ); + + return pOutName; +} + +extern ConVar mat_texture_tracking; +extern CUtlMap *g_pTextureRefList; + +#endif // ITEXTUREINTERNAL_H diff --git a/materialsystem/mat_stub.cpp b/materialsystem/mat_stub.cpp new file mode 100644 index 0000000..67d77f8 --- /dev/null +++ b/materialsystem/mat_stub.cpp @@ -0,0 +1,2373 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//=====================================================================================// + +#include "materialsystem/imesh.h" +#include "materialsystem/imaterialsystemhardwareconfig.h" +#include "materialsystem/imorph.h" +#include "materialsystem/imaterialsystemstub.h" +#include "materialsystem/imaterial.h" +#include "materialsystem/itexture.h" +#include "materialsystem/imaterialvar.h" +#include "bitmap/imageformat.h" +#include "mathlib/vmatrix.h" +#include "utlvector.h" +// GR +#include "imaterialinternal.h" +#include "materialsystem/materialsystem_config.h" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +// ---------------------------------------------------------------------------------------- // +// IMaterialSystem and IMesh stub classes. +// ---------------------------------------------------------------------------------------- // +static unsigned short g_DummyIndices[6]; + +class CDummyMesh : public IMesh +{ +public: + // Locks/ unlocks the mesh, providing space for nVertexCount and nIndexCount. + // nIndexCount of -1 means don't lock the index buffer... + virtual void LockMesh( int nVertexCount, int nIndexCount, MeshDesc_t& desc ) + { + Lock( nVertexCount, false, *static_cast< VertexDesc_t* >( &desc ) ); + Lock( nIndexCount, false, *static_cast< IndexDesc_t* >( &desc ) ); + } + + virtual void UnlockMesh( int nVertexCount, int nIndexCount, MeshDesc_t& desc ) + { + } + + virtual void ModifyBeginEx( bool bReadOnly, int nFirstVertex, int nVertexCount, int nFirstIndex, int nIndexCount, MeshDesc_t& desc ) + { + ModifyBegin( bReadOnly, nFirstIndex, nIndexCount, *static_cast< IndexDesc_t* >( &desc ) ); + } + + virtual void ModifyBegin( int nFirstVertex, int nVertexCount, int nFirstIndex, int nIndexCount, MeshDesc_t& desc ) + { + ModifyBegin( false, nFirstIndex, nIndexCount, *static_cast< IndexDesc_t* >( &desc ) ); + } + + virtual void ModifyEnd( MeshDesc_t &desc ) + { + } + + // FIXME: Make this work! Unsupported methods of IIndexBuffer + virtual bool Lock( int nMaxIndexCount, bool bAppend, IndexDesc_t& desc ) + { + desc.m_pIndices = g_DummyIndices; + desc.m_nIndexSize = 0; + desc.m_nFirstIndex = 0; + desc.m_nOffset = 0; + return true; + } + + virtual void Unlock( int nWrittenIndexCount, IndexDesc_t& desc ) {} + + virtual void ModifyBegin( bool bReadOnly, int nFirstIndex, int nIndexCount, IndexDesc_t& desc ) + { + desc.m_pIndices = g_DummyIndices; + desc.m_nIndexSize = 0; + desc.m_nFirstIndex = 0; + desc.m_nOffset = 0; + } + + virtual void ModifyEnd( IndexDesc_t &desc ) {} + virtual void Spew( int nIndexCount, const IndexDesc_t & desc ) {} + virtual void ValidateData( int nIndexCount, const IndexDesc_t &desc ) {} + virtual bool IsDynamic() const + { + return false; + } + + virtual void BeginCastBuffer( MaterialIndexFormat_t format ) {} + virtual void BeginCastBuffer( VertexFormat_t format ) {} + virtual void EndCastBuffer( ) {} + + // Returns the number of vertices that can still be written into the buffer + virtual int GetRoomRemaining() const { return 0; } + + virtual int IndexCount() const + { + return 0; + } + + // returns the # of vertices (static meshes only) + virtual int VertexCount() const + { + return 0; + } + + // returns the vertex format + virtual bool Lock( int nVertexCount, bool bAppend, VertexDesc_t &desc ) + { + static float dummyFloat[32]; + static unsigned char dummyChar[32]; + + memset( &desc, 0, sizeof( desc ) ); + + // Pointers to our current vertex data + desc.m_pPosition = dummyFloat; + desc.m_pBoneWeight = dummyFloat; +#ifdef NEW_SKINNING + desc.m_pBoneMatrixIndex = dummyFloat; +#else + desc.m_pBoneMatrixIndex = dummyChar; +#endif + + desc.m_pNormal = dummyFloat; + desc.m_pColor = dummyChar; + desc.m_pSpecular = dummyChar; + for( int i = 0; i < VERTEX_MAX_TEXTURE_COORDINATES; i++ ) + { + desc.m_pTexCoord[i] = dummyFloat; + } + + desc.m_pTangentS = dummyFloat; + desc.m_pTangentT = dummyFloat; + desc.m_pWrinkle = dummyFloat; + + // user data + desc.m_pUserData = dummyFloat; + desc.m_nFirstVertex = 0; + desc.m_nOffset = 0; + return true; + } + + virtual void Unlock( int nVertexCount, VertexDesc_t &desc ) {} + virtual void Spew( int nVertexCount, const VertexDesc_t &desc ) {} + virtual void ValidateData( int nVertexCount, const VertexDesc_t & desc ) {} + + // Sets/gets the primitive type + virtual void SetPrimitiveType( MaterialPrimitiveType_t type ) + { + } + + // Draws the mesh + virtual void Draw( int nFirstIndex = -1, int nIndexCount = 0 ) + { + } + + virtual void SetColorMesh( IMesh *pColorMesh, int nVertexOffset ) + { + } + + virtual void SetFlexMesh( IMesh *pMesh, int nVertexOffset ) + { + } + + virtual void DisableFlexMesh( ) + { + } + + // Draw a list of (lists of) primitives. Batching your lists together that use + // the same lightmap, material, vertex and index buffers with multipass shaders + // can drastically reduce state-switching overhead. + // NOTE: this only works with STATIC meshes. + virtual void Draw( CPrimList *pLists, int nLists ) + { + } + + // Copy verts and/or indices to a mesh builder. This only works for temp meshes! + virtual void CopyToMeshBuilder( + int iStartVert, // Which vertices to copy. + int nVerts, + int iStartIndex, // Which indices to copy. + int nIndices, + int indexOffset, // This is added to each index. + CMeshBuilder &builder ) + { + } + + // Spews the mesh data + virtual void Spew( int nVertexCount, int nIndexCount, const MeshDesc_t& desc ) + { + } + + // Call this in debug mode to make sure our data is good. + virtual void ValidateData( int nVertexCount, int nIndexCount, const MeshDesc_t& desc ) + { + } + + virtual void MarkAsDrawn() {} + + virtual unsigned ComputeMemoryUsed() { return 0; } + + virtual VertexFormat_t GetVertexFormat() const + { + return VERTEX_POSITION; + } + virtual MaterialIndexFormat_t IndexFormat() const + { + return MATERIAL_INDEX_FORMAT_16BIT; + } + virtual IMesh *GetMesh() + { + return this; + } +}; + +// We allocate this dynamically because it uses a bunch of memory and we don't want to +// waste the memory unless we need to. +CDummyMesh *g_pDummyMesh = NULL; +CDummyMesh* GetDummyMesh() +{ + if ( !g_pDummyMesh ) + { + g_pDummyMesh = new CDummyMesh; + } + + return g_pDummyMesh; +} + + +// ---------------------------------------------------------------------------------------- // +// ITexture dummy implementation. +// ---------------------------------------------------------------------------------------- // + +class CDummyTexture : public ITexture +{ +public: + // Various texture polling methods + virtual const char *GetName( void ) const { return "DummyTexture"; } + virtual int GetMappingWidth() const { return 512; } + virtual int GetMappingHeight() const { return 512; } + virtual int GetActualWidth() const { return 512; } + virtual int GetActualHeight() const { return 512; } + virtual int GetNumAnimationFrames() const { return 0; } + virtual bool IsTranslucent() const { return false; } + virtual bool IsMipmapped() const { return false; } + + virtual void GetLowResColorSample( float s, float t, float *color ) const {} + + // Gets texture resource data of the specified type. + // Params: + // eDataType type of resource to retrieve. + // pnumBytes on return is the number of bytes available in the read-only data buffer or is undefined + // Returns: + // pointer to the resource data, or NULL + virtual void *GetResourceData( uint32 eDataType, size_t *pNumBytes ) const + { + return NULL; + } + + + // Methods associated with reference count + virtual void IncrementReferenceCount( void ) {} + virtual void DecrementReferenceCount( void ) {} + + // Used to modify the texture bits (procedural textures only) + virtual void SetTextureRegenerator( ITextureRegenerator *pTextureRegen ) {} + + // Reconstruct the texture bits in HW memory + + // If rect is not specified, reconstruct all bits, otherwise just + // reconstruct a subrect. + virtual void Download( Rect_t *pRect = 0, int nAdditionalCreationFlags = 0 ) {} + + // Uses for stats. . .get the approximate size of the texture in it's current format. + virtual int GetApproximateVidMemBytes( void ) const { return 64; } + + virtual bool IsError() const { return false; } + + virtual ITexture *GetEmbeddedTexture( int nIndex ) { return NULL; } + + // For volume textures + virtual bool IsVolumeTexture() const { return false; } + virtual int GetMappingDepth() const { return 1; } + virtual int GetActualDepth() const { return 1; } + + virtual ImageFormat GetImageFormat() const { return IMAGE_FORMAT_RGBA8888; } + virtual NormalDecodeMode_t GetNormalDecodeMode() const { return NORMAL_DECODE_NONE; } + + // Various information about the texture + virtual bool IsRenderTarget() const { return false; } + virtual bool IsCubeMap() const { return false; } + virtual bool IsNormalMap() const { return false; } + virtual bool IsProcedural() const { return false; } + virtual void DeleteIfUnreferenced() {} + + virtual void SwapContents( ITexture *pOther ) {} + + virtual unsigned int GetFlags( void ) const { return 0; } + virtual void ForceLODOverride( int iNumLodsOverrideUpOrDown ) { NULL; } + +#if defined( _X360 ) + virtual bool ClearTexture( int r, int g, int b, int a ) { return true; } + virtual bool CreateRenderTargetSurface( int width, int height, ImageFormat format, bool bSameAsTexture ) { return true; } +#endif + + // Save texture to a file. + virtual bool SaveToFile( const char *fileName ) { return false; } + + void CopyToStagingTexture( ITexture* pDstTex ) {} + + virtual void SetErrorTexture( bool bIsErrorTexture ) { } +}; + +CDummyTexture g_DummyTexture; + + +// ---------------------------------------------------------------------------------------- // +// Dummy implementation of IMaterialVar. +// ---------------------------------------------------------------------------------------- // +static VMatrix g_DummyMatrix( 1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1 ); + +class CDummyMaterialVar : public IMaterialVar +{ +public: + virtual char const * GetName( void ) const { return "DummyMaterialVar"; } + virtual MaterialVarSym_t GetNameAsSymbol() const { return 0; } + + virtual void SetFloatValue( float val ) {} + virtual float GetFloatValueInternal( void ) const { return 1; } + + virtual void SetIntValue( int val ) {} + virtual int GetIntValueInternal( void ) const { return 1; } + + virtual void SetStringValue( char const *val ) {} + virtual char const * GetStringValue( void ) const { return ""; } + + // Use FourCC values to pass app-defined data structures between + // the proxy and the shader. The shader should ignore the data if + // its FourCC type not correct. + virtual void SetFourCCValue( FourCC type, void *pData ) {} + virtual void GetFourCCValue( FourCC *type, void **ppData ) {} + + // Vec (dim 2-4) + virtual void SetVecValue( float const* val, int numcomps ) {} + virtual void SetVecValue( float x, float y ) {} + virtual void SetVecValue( float x, float y, float z ) {} + virtual void SetVecValue( float x, float y, float z, float w ) {} + virtual void SetVecComponentValue( float fVal, int nComponent ) {} + virtual void GetVecValueInternal( float *val, int numcomps ) const + { + for ( int i=0; i < numcomps; i++ ) + val[i] = 1; + } + virtual void GetLinearVecValue( float *val, int numcomps ) const + { + for ( int i=0; i < numcomps; i++ ) + val[i] = 1; + } + + virtual float const* GetVecValueInternal( ) const + { + static float val[4] = {1,1,1,1}; + return val; + } + + virtual int VectorSizeInternal() const + { + return 3; + } + + // revisit: is this a good interface for textures? + virtual ITexture * GetTextureValue( void ) + { + return &g_DummyTexture; + } + + virtual void SetTextureValue( ITexture * ) {} + virtual operator ITexture*() + { + return GetTextureValue(); + } + + virtual IMaterial * GetMaterialValue( void ) + { + extern IMaterial *g_pDummyMaterial; + return g_pDummyMaterial; + } + + virtual void SetMaterialValue( IMaterial * ) {} + + virtual MaterialVarType_t GetType() const { return MATERIAL_VAR_TYPE_INT; } + virtual bool IsDefined() const { return true; } + virtual void SetUndefined() {} + + // Matrix + virtual void SetMatrixValue( VMatrix const& matrix ) {} + virtual const VMatrix &GetMatrixValue( ) + { + return g_DummyMatrix; + } + virtual bool MatrixIsIdentity() const + { + return false; + } + + // Copy.... + virtual void CopyFrom( IMaterialVar *pMaterialVar ) {} + + virtual void SetValueAutodetectType( char const *val ) {} + + virtual IMaterial * GetOwningMaterial() + { + extern IMaterial *g_pDummyMaterial; + return g_pDummyMaterial; + } +}; +CDummyMaterialVar g_DummyMaterialVar; + + +// ---------------------------------------------------------------------------------------- // +// Dummy implementation of IMaterialSystemHardwareConfig +// ---------------------------------------------------------------------------------------- // + +class CDummyHardwareConfig : public IMaterialSystemHardwareConfig +{ +public: + virtual bool HasDestAlphaBuffer() const { return false; } + virtual bool HasStencilBuffer() const { return false; } + virtual int StencilBufferBits() const { return 0; } + virtual int GetFrameBufferColorDepth() const { return 0; } + virtual int GetSamplerCount() const { return 0; } + virtual bool HasSetDeviceGammaRamp() const { return false; } + virtual bool SupportsCompressedTextures() const { return false; } + virtual VertexCompressionType_t SupportsCompressedVertices() const { return VERTEX_COMPRESSION_NONE; } + virtual bool SupportsVertexAndPixelShaders() const { return false; } + virtual bool SupportsPixelShaders_1_4() const { return false; } + virtual bool SupportsPixelShaders_2_0() const { return false; } + virtual bool SupportsPixelShaders_2_b() const { return false; } + virtual bool ActuallySupportsPixelShaders_2_b() const { return false; } + virtual bool SupportsStaticControlFlow() const { return false; } + virtual bool SupportsVertexShaders_2_0() const { return false; } + virtual bool SupportsShaderModel_3_0() const { return false; } + virtual int MaximumAnisotropicLevel() const { return 1; } + virtual int MaxTextureWidth() const { return 0; } + virtual int MaxTextureHeight() const { return 0; } + virtual int MaxTextureDepth() const { return 0; } + virtual int TextureMemorySize() const { return 0; } + virtual bool SupportsOverbright() const { return false; } + virtual bool SupportsCubeMaps() const { return false; } + virtual bool SupportsMipmappedCubemaps() const { return false; } + virtual bool SupportsNonPow2Textures() const { return false; } + + // The number of texture stages represents the number of computations + // we can do in the pixel pipeline, it is *not* related to the + // simultaneous number of textures we can use + virtual int GetTextureStageCount() const { return 0; } + virtual int NumVertexShaderConstants() const { return 0; } + virtual int NumBooleanVertexShaderConstants() const { return 0; } + virtual int NumIntegerVertexShaderConstants() const { return 0; } + virtual int NumPixelShaderConstants() const { return 0; } + virtual int MaxNumLights() const { return 0; } + virtual bool SupportsHardwareLighting() const { return false; } + virtual int MaxBlendMatrices() const { return 0; } + virtual int MaxBlendMatrixIndices() const { return 0; } + virtual int MaxTextureAspectRatio() const { return 0; } + virtual int MaxVertexShaderBlendMatrices() const { return 0; } + virtual int MaxUserClipPlanes() const { return 0; } + virtual bool UseFastClipping() const { return false; } + virtual bool UseFastZReject() const { return false; } + virtual bool PreferReducedFillrate() const { return false; } + + // This here should be the major item looked at when checking for compat + // from anywhere other than the material system shaders + virtual int GetDXSupportLevel() const { return 90; } + virtual const char *GetShaderDLLName() const { return NULL; } + + virtual bool ReadPixelsFromFrontBuffer() const { return false; } + + // Are dx dynamic textures preferred? + virtual bool PreferDynamicTextures() const { return false; } + + virtual bool SupportsHDR() const { return false; } + virtual HDRType_t GetHDRType() const { return HDR_TYPE_NONE; } + virtual HDRType_t GetHardwareHDRType() const { return HDR_TYPE_NONE; } + + virtual bool HasProjectedBumpEnv() const { return false; } + virtual bool SupportsSpheremapping() const { return false; } + virtual bool NeedsAAClamp() const { return false; } + virtual bool HasFastZReject() const { return false; } + virtual bool NeedsATICentroidHack() const { return false; } + virtual bool SupportsColorOnSecondStream() const{ return false; } + virtual bool SupportsStaticPlusDynamicLighting() const{ return false; } + virtual bool SupportsStreamOffset() const { return false; } + virtual int GetMaxDXSupportLevel() const { return 90; } + virtual bool SpecifiesFogColorInLinearSpace() const { return false; } + virtual bool SupportsSRGB() const { return false; } + virtual bool FakeSRGBWrite() const { return false; } + virtual bool CanDoSRGBReadFromRTs() const { return true; } + virtual bool SupportsGLMixedSizeTargets() const { return false; } + virtual bool IsAAEnabled() const { return false; } + virtual int GetVertexTextureCount() const { return 0; } + virtual int GetMaxVertexTextureDimension() const { return 0; } + virtual int MaxViewports() const { return 1; } + virtual void OverrideStreamOffsetSupport( bool bOverrideEnabled, bool bEnableSupport ) {} + virtual int GetShadowFilterMode() const { return 0; } + virtual int NeedsShaderSRGBConversion() const { return 0; } + bool UsesSRGBCorrectBlending() const { return false; } + virtual bool HasFastVertexTextures() const { return false; } + virtual int MaxHWMorphBatchCount() const { return 0; } + virtual bool SupportsHDRMode( HDRType_t nMode ) const { return 0; } + virtual bool IsDX10Card() const { return 0; } + virtual bool GetHDREnabled( void ) const { return true; } + virtual void SetHDREnabled( bool bEnable ) {} + virtual bool SupportsBorderColor( void ) const { return true; } + virtual bool SupportsFetch4( void ) const { return false; } + virtual bool CanStretchRectFromTextures() const { return false; } +}; +CDummyHardwareConfig g_DummyHardwareConfig; + + +// ---------------------------------------------------------------------------------------- // +// CDummyMaterial. +// ---------------------------------------------------------------------------------------- // + +class CDummyMaterial : public IMaterial +{ +public: + virtual const char * GetName() const { return "dummy material"; } + virtual const char * GetTextureGroupName() const { return "dummy group"; } + + virtual PreviewImageRetVal_t GetPreviewImageProperties( int *width, int *height, + ImageFormat *imageFormat, bool* isTranslucent ) const + { + if ( width ) + *width = 4; + + if ( height ) + *height = 4; + + if ( imageFormat ) + *imageFormat = IMAGE_FORMAT_RGBA8888; + + if ( isTranslucent ) + *isTranslucent = false; + + return MATERIAL_PREVIEW_IMAGE_OK; + } + + virtual PreviewImageRetVal_t GetPreviewImage( unsigned char *data, + int width, int height, + ImageFormat imageFormat ) const + { + return MATERIAL_PREVIEW_IMAGE_OK; + } + + // + virtual int GetMappingWidth( ) + { + return 512; + } + + virtual int GetMappingHeight( ) + { + return 512; + } + + virtual int GetNumAnimationFrames( ) + { + return 0; + } + + virtual bool InMaterialPage( void ) + { + return false; + } + + virtual void GetMaterialOffset( float *pOffset ) + { + pOffset[0] = 0.0f; + pOffset[1] = 0.0f; + } + + virtual void GetMaterialScale( float *pScale ) + { + pScale[0] = 1.0f; + pScale[1] = 1.0f; + } + + virtual IMaterial *GetMaterialPage( void ) + { + return NULL; + } + + virtual IMaterialVar * FindVar( const char *varName, bool *found, bool complain = true ) + { + if ( found ) + *found = true; + + return &g_DummyMaterialVar; + } + virtual IMaterialVar * FindVarFast( const char *varName, unsigned int *pToken ) + { + return NULL; + } + + virtual void IncrementReferenceCount( void ) + { + } + + virtual void DecrementReferenceCount( void ) + { + } + + virtual int GetEnumerationID( void ) const + { + return 0; + } + + virtual void GetLowResColorSample( float s, float t, float *color ) const + { + } + + virtual void RecomputeStateSnapshots() + { + } + + + // Are we translucent? + virtual bool IsTranslucent() + { + return false; + } + + // Are we alphatested? + virtual bool IsAlphaTested() + { + return false; + } + + // Are we vertex lit? + virtual bool IsVertexLit() + { + return false; + } + + // Gets the vertex format + virtual VertexFormat_t GetVertexFormat() const + { + return 0; + } + + // returns true if this material uses a material proxy + virtual bool HasProxy( void ) const + { + return false; + } + virtual void CallBindProxy( void* ) {} + + virtual IMaterial *CheckProxyReplacement( void *proxyData ) + { + return this; + } + + virtual bool UsesEnvCubemap( void ) + { + return false; + } + + virtual bool NeedsTangentSpace( void ) + { + return false; + } + + virtual bool NeedsPowerOfTwoFrameBufferTexture( bool bCheckSpecificToThisFrame ) + { + return false; + } + + virtual bool NeedsFullFrameBufferTexture( bool bCheckSpecificToThisFrame ) + { + return false; + } + + virtual bool NeedsSoftwareSkinning( void ) + { + return false; + } + + // Apply constant color or alpha modulation + virtual void AlphaModulate( float alpha ) + { + } + + virtual void ColorModulate( float r, float g, float b ) + { + } + + float GetAlphaModulation( ) + { + return 1; + } + + void GetColorModulation( float *r, float *g, float *b ) + { + *r = *g = *b = 1; + } + + // Material Var flags... + virtual void SetMaterialVarFlag( MaterialVarFlags_t flag, bool on ) + { + } + + virtual bool GetMaterialVarFlag( MaterialVarFlags_t flag ) const + { + return true; + } + + + // Gets material reflectivity + virtual void GetReflectivity( Vector& reflect ) + { + reflect.Init(1,0,0); + } + + + // Gets material property flags + virtual bool GetPropertyFlag( MaterialPropertyTypes_t type ) + { + return true; + } + + // Is the material visible from both sides? + virtual bool IsTwoSided() + { + return false; + } + + // Sets the shader associated with the material + virtual void SetShader( const char *pShaderName ) + { + } + + // Can't be const because the material might have to precache itself. + virtual int GetNumPasses( void ) + { + return 1; + } + + // Can't be const because the material might have to precache itself. + virtual int GetTextureMemoryBytes( void ) + { + return 64; + } + + // Meant to be used with materials created using CreateMaterial + // It updates the materials to reflect the current values stored in the material vars + virtual void Refresh() + { + } + + // GR - returns true is material uses lightmap alpha for blending + virtual bool NeedsLightmapBlendAlpha( void ) + { + return false; + } + + // returns true if the shader doesn't do lighting itself and requires + // the data that is sent to it to be prelighted + virtual bool NeedsSoftwareLighting( void ) + { + return false; + } + + // Gets at the shader parameters + virtual int ShaderParamCount() const + { + return 0; + } + + virtual IMaterialVar **GetShaderParams( void ) + { + return 0; + } + + virtual bool IsErrorMaterial() const + { + return false; + } + virtual void SetUseFixedFunctionBakedLighting( bool bEnable ) + { + } + virtual MorphFormat_t GetMorphFormat() const + { + return 0; + } + virtual void SetShaderAndParams( KeyValues *pKeyValues ) + { + } + virtual const char *GetShaderName() const { return "Wireframe"; } + + virtual void DeleteIfUnreferenced() {} + virtual bool IsSpriteCard() { return false; } + + virtual void RefreshPreservingMaterialVars() {}; + + virtual bool WasReloadedFromWhitelist() {return false;} + + virtual bool IsPrecached() const {return true;} +}; + +CDummyMaterial g_DummyMaterial; +IMaterial *g_pDummyMaterial = &g_DummyMaterial; + + +void* DummyMaterialSystemFactory( const char *pName, int *pReturnCode ) +{ + if ( stricmp( pName, MATERIALSYSTEM_HARDWARECONFIG_INTERFACE_VERSION ) == 0 ) + return &g_DummyHardwareConfig; + + else + return NULL; +} + + +// ---------------------------------------------------------------------------------------- // +// Dummy morph +// ---------------------------------------------------------------------------------------- // +class CDummyMorph : public IMorph +{ +public: + virtual void Lock( float flFloatToFixedScale ) {} + virtual void AddMorph( const MorphVertexInfo_t &info ) {} + virtual void Unlock( ) {} + virtual void AccumulateMorph( int nWeightCount, const MorphWeight_t* pWeights ) {} +}; + + +// ---------------------------------------------------------------------------------------- // +// CDummyMaterialSystem. +// ---------------------------------------------------------------------------------------- // +class CDummyMaterialSystem : public IMaterialSystemStub, public CRefCounted1 +{ +private: + IMaterialSystem *m_pRealMaterialSystem; +public: + CDummyMaterialSystem() + { + m_pRealMaterialSystem = 0; + } + + virtual void SetRealMaterialSystem( IMaterialSystem *pSys ) + { + m_pRealMaterialSystem = pSys; + } + + + // Call this to initialize the material system + // returns a method to create interfaces in the shader dll + virtual CreateInterfaceFn Init( char const* pShaderDLL, + IMaterialProxyFactory *pMaterialProxyFactory, + CreateInterfaceFn fileSystemFactory, + CreateInterfaceFn cvarFactory ) + { + return DummyMaterialSystemFactory; + } + + virtual void Shutdown( ) + { + } + + virtual IMaterialSystemHardwareConfig *GetHardwareConfig( const char *pVersion, int *returnCode ) + { + if ( returnCode ) + *returnCode = 1; + + return &g_DummyHardwareConfig; + } + + // Gets the number of adapters... + virtual int GetDisplayAdapterCount() const + { + return 0; + } + + // Returns info about each adapter + virtual void GetDisplayAdapterInfo( int adapter, MaterialAdapterInfo_t& info ) const + { + } + + // Returns the number of modes + virtual int GetModeCount( int adapter ) const + { + return 0; + } + + // Returns mode information.. + virtual void GetModeInfo( int adapter, int mode, MaterialVideoMode_t& info ) const + { + } + + // Returns the mode info for the current display device + virtual void GetDisplayMode( MaterialVideoMode_t& mode ) const + { + } + + // Sets the mode... + virtual bool SetMode( void* hwnd, const MaterialSystem_Config_t &config ) + { + return true; + } + + // Creates/ destroys a child window + virtual bool AddView( void* hwnd ) + { + return false; + } + virtual void RemoveView( void* hwnd ) + { + } + + // Sets the view + virtual void SetView( void* hwnd ) + { + } + + // return true if lightmaps need to be redownloaded + // Call this before rendering each frame with the current config + // for the material system. + // Will do whatever is necessary to get the material system into the correct state + // upon configuration change. .doesn't much else otherwise. + virtual bool UpdateConfig( bool forceUpdate ) + { + return false; + } + + virtual bool OverrideConfig( const MaterialSystem_Config_t &config, bool bForceUpdate ) + { + return false; + } + + // This is the interface for knowing what materials are available + // is to use the following functions to get a list of materials. The + // material names will have the full path to the material, and that is the + // only way that the directory structure of the materials will be seen through this + // interface. + // NOTE: This is mostly for worldcraft to get a list of materials to put + // in the "texture" browser.in Worldcraft + virtual MaterialHandle_t FirstMaterial() const + { + return 0; + } + + // returns InvalidMaterial if there isn't another material. + // WARNING: you must call GetNextMaterial until it returns NULL, + // otherwise there will be a memory leak. + virtual MaterialHandle_t NextMaterial( MaterialHandle_t h ) const + { + return 0; + } + + // This is the invalid material + virtual MaterialHandle_t InvalidMaterial() const + { + if ( m_pRealMaterialSystem ) + return m_pRealMaterialSystem->InvalidMaterial(); + else + return 0; + } + + // Returns a particular material + virtual IMaterial* GetMaterial( MaterialHandle_t h ) const + { + if ( m_pRealMaterialSystem ) + return m_pRealMaterialSystem->GetMaterial( h ); + else + return &g_DummyMaterial; + } + + // Find a material by name. + // The name of a material is a full path to + // the vmt file starting from "hl2/materials" (or equivalent) without + // a file extension. + // eg. "dev/dev_bumptest" refers to somethign similar to: + // "d:/hl2/hl2/materials/dev/dev_bumptest.vmt" + virtual IMaterial *FindMaterial( char const* pMaterialName, const char *pTextureGroupName, bool complain = true, const char *pComplainPrefix = NULL ) + { + if ( m_pRealMaterialSystem ) + return m_pRealMaterialSystem->FindMaterial( pMaterialName, pTextureGroupName, complain, pComplainPrefix ); + return &g_DummyMaterial; + } + + virtual bool IsMaterialLoaded( char const* pMaterialName ) + { + if ( m_pRealMaterialSystem ) + return m_pRealMaterialSystem->IsMaterialLoaded( pMaterialName ); + return true; + } + + virtual IMaterial *FindMaterialEx( char const* pMaterialName, const char *pTextureGroupName, int nContext, bool complain = true, const char *pComplainPrefix = NULL ) + { + if ( m_pRealMaterialSystem ) + return m_pRealMaterialSystem->FindMaterialEx( pMaterialName, pTextureGroupName, nContext, complain, pComplainPrefix ); + return &g_DummyMaterial; + } + + virtual IMaterial *FindProceduralMaterial( const char *pMaterialName, const char *pTextureGroupName, KeyValues *pVMTKeyValues ) + { + if ( m_pRealMaterialSystem ) + return m_pRealMaterialSystem->FindProceduralMaterial( pMaterialName, pTextureGroupName, pVMTKeyValues ); + return &g_DummyMaterial; + } + + virtual ITexture *FindTexture( char const* pTextureName, const char *pTextureGroupName, bool complain = true, int nAdditionalCreationFlags = 0) + { + if ( m_pRealMaterialSystem ) + return m_pRealMaterialSystem->FindTexture( pTextureName, pTextureGroupName, complain, nAdditionalCreationFlags ); + return &g_DummyTexture; + } + + virtual void SetAsyncTextureLoadCache( FileCacheHandle_t hFileCache ) + { + } + + virtual void BindLocalCubemap( ITexture *pTexture ) + { + } + virtual ITexture *GetLocalCubemap( ) + { + return &g_DummyTexture; + } + + // pass in an ITexture (that is build with "rendertarget" "1") or + // pass in NULL for the regular backbuffer. + virtual void SetRenderTarget( ITexture *pTexture ) + { + } + + virtual ITexture * GetRenderTarget( void ) + { + return &g_DummyTexture; + } + + virtual void SetRenderTargetEx( int nRenderTargetID, ITexture *pTexture ) + { + } + + virtual ITexture * GetRenderTargetEx( int nRenderTargetID ) + { + return &g_DummyTexture; + } + virtual void GetRenderTargetDimensions( int &width, int &height) const + { + width = 256; + height = 256; + } + + // Get the total number of materials in the system. These aren't just the used + // materials, but the complete collection. + virtual int GetNumMaterials( ) const + { + return m_pRealMaterialSystem->GetNumMaterials(); + } + + // Remove any materials from memory that aren't in use as determined + // by the IMaterial's reference count. + virtual void UncacheUnusedMaterials( bool bRecomputeStateSnapshots ) + { + if ( m_pRealMaterialSystem ) + { + m_pRealMaterialSystem->UncacheUnusedMaterials( bRecomputeStateSnapshots ); + } + } + + virtual void SuspendTextureStreaming( ) + { + if ( m_pRealMaterialSystem ) + m_pRealMaterialSystem->SuspendTextureStreaming(); + } + + virtual void ResumeTextureStreaming( ) + { + if ( m_pRealMaterialSystem ) + m_pRealMaterialSystem->ResumeTextureStreaming(); + } + + // uncache all materials. . good for forcing reload of materials. + virtual void UncacheAllMaterials( ) + { + if ( m_pRealMaterialSystem ) + m_pRealMaterialSystem->UncacheAllMaterials(); + } + + // Load any materials into memory that are to be used as determined + // by the IMaterial's reference count. + virtual void CacheUsedMaterials( ) + { + if ( m_pRealMaterialSystem ) + m_pRealMaterialSystem->CacheUsedMaterials( ); + } + + // Force all textures to be reloaded from disk. + virtual void ReloadTextures( ) + { + } + + // Allows us to override the depth buffer setting of a material + virtual void OverrideDepthEnable( bool bEnable, bool bEnableValue ) + { + } + + virtual void OverrideAlphaWriteEnable( bool bOverrideEnable, bool bAlphaWriteEnable ) + { + } + + virtual void OverrideColorWriteEnable( bool bOverrideEnable, bool bColorWriteEnable ) + { + } + + // + // lightmap allocation stuff + // + + // To allocate lightmaps, sort the whole world by material twice. + // The first time through, call AllocateLightmap for every surface. + // that has a lightmap. + // The second time through, call AllocateWhiteLightmap for every + // surface that expects to use shaders that expect lightmaps. + virtual void BeginLightmapAllocation( ) + { + } + // returns the sorting id for this surface + virtual int AllocateLightmap( int width, int height, + int offsetIntoLightmapPage[2], + IMaterial *pMaterial ) + { + return 0; + } + // returns a lightmap page ID for this allocation, -1 if none available + virtual int AllocateDynamicLightmap( int lightmapSize[2], int *pOutOffsetIntoPage, int frameID ) + { + return -1; + } + + // returns the sorting id for this surface + virtual int AllocateWhiteLightmap( IMaterial *pMaterial ) + { + return 0; + } + virtual void EndLightmapAllocation( ) + { + } + + // lightmaps are in linear color space + // lightmapPageID is returned by GetLightmapPageIDForSortID + // lightmapSize and offsetIntoLightmapPage are returned by AllocateLightmap. + // You should never call UpdateLightmap for a lightmap allocated through + // AllocateWhiteLightmap. + virtual void UpdateLightmap( int lightmapPageID, int lightmapSize[2], + int offsetIntoLightmapPage[2], + float *pFloatImage, float *pFloatImageBump1, + float *pFloatImageBump2, float *pFloatImageBump3 ) + { + } + // Force the lightmaps updated with UpdateLightmap to be sent to the hardware. + virtual void FlushLightmaps( ) + { + } + + // fixme: could just be an array of ints for lightmapPageIDs since the material + // for a surface is already known. + virtual int GetNumSortIDs( ) + { + return 10; + } +// virtual int GetLightmapPageIDForSortID( int sortID ) = 0; + virtual void GetSortInfo( MaterialSystem_SortInfo_t *pSortInfoArray ) + { + } + + virtual void BeginFrame( float ) + { + } + virtual void EndFrame( ) + { + } + virtual bool IsInFrame() const { return false; } + + // Bind a material is current for rendering. + virtual void Bind( IMaterial *material, void *proxyData = 0 ) + { + } + // Bind a lightmap page current for rendering. You only have to + // do this for materials that require lightmaps. + virtual void BindLightmapPage( int lightmapPageID ) + { + } + + // inputs are between 0 and 1 + virtual void DepthRange( float zNear, float zFar ) + { + } + + virtual void ClearBuffers( bool bClearColor, bool bClearDepth, bool bClearStencil ) + { + } + + virtual void ClearBuffersObeyStencil( bool bClearColor, bool bClearDepth ) + { + } + + virtual void ClearBuffersObeyStencilEx( bool bClearColor, bool bClearAlpha, bool bClearDepth ) + { + } + + virtual void PerformFullScreenStencilOperation( void ) + { + } + + // read to a unsigned char rgb image. + virtual void ReadPixels( int x, int y, int width, int height, unsigned char *data, ImageFormat dstFormat ) + { + } + + // Read w/ stretch to a host-memory buffer + virtual void ReadPixelsAndStretch( Rect_t *pSrcRect, Rect_t *pDstRect, unsigned char *pBuffer, ImageFormat dstFormat, int nDstStride ) + { + } + + // Sets lighting + virtual void SetAmbientLight( float r, float g, float b ) + { + } + virtual void SetLight( int lightNum, const LightDesc_t& desc ) + { + } + virtual void SetLightingOrigin( Vector vLightingOrigin ) + { + } + + // The faces of the cube are specified in the same order as cubemap textures + virtual void SetAmbientLightCube( Vector4D cube[6] ) + { + } + + // Blit the backbuffer to the framebuffer texture + virtual void CopyRenderTargetToTexture( ITexture * ) + { + } + + virtual void SetFrameBufferCopyTexture( ITexture *pTexture, int textureIndex ) + { + } + + virtual ITexture * GetFrameBufferCopyTexture( int textureIndex ) + { + return &g_DummyTexture; + } + + // do we need this? + virtual void Flush( bool flushHardware = false ) + { + } + + // + // end vertex array api + // + + // + // Debugging tools + // + virtual void DebugPrintUsedMaterials( const char *pSearchSubString, bool bVerbose ) + { + } + virtual void DebugPrintUsedTextures( void ) + { + } + virtual void ToggleSuppressMaterial( char const* pMaterialName ) + { + } + virtual void ToggleDebugMaterial( char const* pMaterialName ) + { + } + + // matrix api + virtual void MatrixMode( MaterialMatrixMode_t matrixMode ) + { + } + virtual void PushMatrix( void ) + { + } + virtual void PopMatrix( void ) + { + } +/* + virtual void LoadMatrix( float * ) + { + } +*/ + // Methods that use VMatrix + virtual void LoadMatrix( const VMatrix& matrix ) + { + } + + virtual void LoadMatrix( const matrix3x4_t& matrix ) + { + } + + virtual void LoadBoneMatrix( int boneIndex, const matrix3x4_t& matrix ) + { + } + + virtual void MultMatrix( const VMatrix& matrix ) + { + } + + virtual void MultMatrix( const matrix3x4_t& matrix ) + { + } + virtual void MultMatrixLocal( const VMatrix& matrix ) + { + } + + virtual void MultMatrixLocal( const matrix3x4_t& matrix ) + { + } + virtual void GetMatrix( MaterialMatrixMode_t matrixMode, VMatrix *pMatrix ) + { + pMatrix->Identity(); + } + virtual void GetMatrix( MaterialMatrixMode_t matrixMode, matrix3x4_t *pMatrix ) + { + SetIdentityMatrix( *pMatrix ); + } + virtual void LoadIdentity( void ) + { + } + virtual void Ortho( double left, double top, double right, double bottom, double zNear, double zFar ) + { + } + virtual void PerspectiveX( double fovx, double aspect, double zNear, double zFar ) + { + } + virtual void PickMatrix( int x, int y, int width, int height ) + { + } + virtual void Rotate( float angle, float x, float y, float z ) + { + } + virtual void Translate( float x, float y, float z ) + { + } + virtual void Scale( float x, float y, float z ) + { + } + // end matrix api + + // Sets/gets the viewport + virtual void Viewport( int x, int y, int width, int height ) + { + } + virtual void GetViewport( int& x, int& y, int& width, int& height ) const + { + x = y = 0; + width = height = 640; + } + + // The cull mode + virtual void CullMode( MaterialCullMode_t cullMode ) + { + } + + // end matrix api + + // Force writes only when z matches. . . useful for stenciling things out + // by rendering the desired Z values ahead of time. +// virtual void ForceDepthFuncEquals( bool bEnable ) = 0; +// virtual void RenderZOnlyWithHeightClip( bool bEnable ) = 0; + // This could easily be extended to a general user clip plane + virtual void SetHeightClipMode( MaterialHeightClipMode_t nClipMode ) + { + } + virtual MaterialHeightClipMode_t GetHeightClipMode( ) + { + return MATERIAL_HEIGHTCLIPMODE_DISABLE; + } + // garymcthack : fog z is always used for heightclipz for now. + virtual void SetHeightClipZ( float z ) + { + } + + // Fog methods... + virtual void FogMode( MaterialFogMode_t fogMode ) + { + } + MaterialFogMode_t GetFogMode( void ) + { + return MATERIAL_FOG_NONE; + } + virtual void FogStart( float fStart ) + { + } + virtual void FogEnd( float fEnd ) + { + } + virtual void FogMaxDensity( float flMaxDensity ) + { + } + + virtual void SetFogZ( float fogZ ) + { + } + virtual void GetFogDistances( float *fStart, float *fEnd, float *fFogZ ) + { + } + + virtual void FogColor3f( float r, float g, float b ) + { + } + virtual void FogColor3fv( float const* rgb ) + { + } + virtual void FogColor3ub( unsigned char r, unsigned char g, unsigned char b ) + { + } + virtual void FogColor3ubv( unsigned char const* rgb ) + { + } + + virtual void GetFogColor( unsigned char *rgb ) + { + } + + // Sets the number of bones for skinning + virtual void SetNumBoneWeights( int numBones ) + { + } + virtual IMaterialProxyFactory *GetMaterialProxyFactory() + { + return NULL; + } + + virtual void SetMaterialProxyFactory( IMaterialProxyFactory* pFactory ) + { + } + + // Read the page size of an existing lightmap by sort id (returned from AllocateLightmap()) + virtual void GetLightmapPageSize( int lightmap, int *width, int *height ) const + { + if ( m_pRealMaterialSystem ) + m_pRealMaterialSystem->GetLightmapPageSize( lightmap, width, height ); + else + *width = *height = 32; + } + + /// FIXME: This stuff needs to be cleaned up and abstracted. + // Stuff that gets exported to the launcher through the engine + virtual void SwapBuffers( ) + { + } + + // Use this to spew information about the 3D layer + virtual void SpewDriverInfo() const + { + } + + // Creates/destroys Mesh + virtual IMesh* CreateStaticMesh( VertexFormat_t fmt, const char *pTextureBudgetGroup, IMaterial * pMaterial ) + { + return GetDummyMesh(); + } + virtual void DestroyStaticMesh( IMesh* mesh ) + { + } + + // Gets the dynamic mesh associated with the currently bound material + // note that you've got to render the mesh before calling this function + // a second time. Clients should *not* call DestroyStaticMesh on the mesh + // returned by this call. + // Use buffered = false if you want to not have the mesh be buffered, + // but use it instead in the following pattern: + // meshBuilder.Begin + // meshBuilder.End + // Draw partial + // Draw partial + // Draw partial + // meshBuilder.Begin + // meshBuilder.End + // etc + // Use Vertex or Index Override to supply a static vertex or index buffer + // to use in place of the dynamic buffers. + // + // If you pass in a material in pAutoBind, it will automatically bind the + // material. This can be helpful since you must bind the material you're + // going to use BEFORE calling GetDynamicMesh. + virtual IMesh* GetDynamicMesh( bool bBuffered = true, IMesh* pVertexOverride = 0, + IMesh* pIndexOverride = 0, IMaterial *pAutoBind = 0 ) + { + return GetDummyMesh(); + } + + virtual IMesh* GetDynamicMeshEx( VertexFormat_t vertexFormat, bool bBuffered = true, + IMesh* pVertexOverride = 0, IMesh* pIndexOverride = 0, IMaterial *pAutoBind = 0 ) + { + return GetDummyMesh(); + } + + virtual IMesh *GetFlexMesh() + { + return GetDummyMesh(); + } + + // Selection mode methods + virtual int SelectionMode( bool selectionMode ) + { + return 0; + } + virtual void SelectionBuffer( unsigned int* pBuffer, int size ) + { + } + virtual void ClearSelectionNames( ) + { + } + virtual void LoadSelectionName( int name ) + { + } + virtual void PushSelectionName( int name ) + { + } + virtual void PopSelectionName() + { + } + + // Installs a function to be called when we need to release vertex buffers + textures + virtual void AddReleaseFunc( MaterialBufferReleaseFunc_t func ) + { + } + virtual void RemoveReleaseFunc( MaterialBufferReleaseFunc_t func ) + { + } + + // Installs a function to be called when we need to restore vertex buffers + virtual void AddRestoreFunc( MaterialBufferRestoreFunc_t func ) + { + } + virtual void RemoveRestoreFunc( MaterialBufferRestoreFunc_t func ) + { + } + + // Stuff for probing properties of shaders. + virtual int GetNumShaders( void ) const + { + return 0; + } + virtual const char * GetShaderName( int shaderID ) const + { + return NULL; + } + virtual int GetNumShaderParams( int shaderID ) const + { + return 0; + } + virtual const char * GetShaderParamName( int shaderID, int paramID ) const + { + return NULL; + } + virtual const char * GetShaderParamHelp( int shaderID, int paramID ) const + { + return NULL; + } + virtual ShaderParamType_t GetShaderParamType( int shaderID, int paramID ) const + { + return ( enum ShaderParamType_t )0; + } + virtual const char * GetShaderParamDefault( int shaderID, int paramID ) const + { + return NULL; + } + + // Reloads materials + virtual void ReloadMaterials( const char *pSubString = NULL ) + { + } + + virtual void ResetMaterialLightmapPageInfo() + { + } + + virtual ITexture* CreateRenderTargetTexture( + int w, + int h, + RenderTargetSizeMode_t sizeMode, // Controls how size is generated (and regenerated on video mode change). + ImageFormat format, + MaterialRenderTargetDepth_t depth ) + { + return &g_DummyTexture; + } + + virtual ITexture *CreateProceduralTexture( + const char *pTextureName, + const char *pTextureGroupName, + int w, + int h, + ImageFormat fmt, + int nFlags ) + { + return &g_DummyTexture; + } + + // Sets the Clear Color for ClearBuffer.... + virtual void ClearColor3ub( unsigned char r, unsigned char g, unsigned char b ) + { + } + virtual void ClearColor4ub( unsigned char r, unsigned char g, unsigned char b, unsigned char a ) + { + } + virtual void SetInStubMode( bool b ) + { + } + + // Create new materials + virtual IMaterial *CreateMaterial( const char *pMaterialName, KeyValues *pVMTKeyValues ) + { + return &g_DummyMaterial; + } + + void GetBackBufferDimensions( int &w, int &h ) const + { + w = 1024; + h = 768; + } + + ImageFormat GetBackBufferFormat( void ) const + { + return IMAGE_FORMAT_RGBA8888; + } + + // FIXME: This is a hack required for NVidia/XBox, can they fix in drivers? + virtual void DrawScreenSpaceQuad( IMaterial* pMaterial ) {} + + // FIXME: Test interface + virtual bool Connect( CreateInterfaceFn factory ) { return true; } + virtual void Disconnect() {} + virtual void *QueryInterface( const char *pInterfaceName ) { return NULL; } + virtual InitReturnVal_t Init() { return INIT_OK; } + virtual void SetShaderAPI( const char *pShaderAPIDLL ) {} + virtual void SetAdapter( int nAdapter, int nFlags ) {} + + // Release temporary HW memory... + virtual void ResetTempHWMemory( bool bExitingLevel ) {} + virtual ITexture* CreateNamedRenderTargetTextureEx( + const char *pRTName, // Pass in NULL here for an unnamed render target. + int w, + int h, + RenderTargetSizeMode_t sizeMode, // Controls how size is generated (and regenerated on video mode change). + ImageFormat format, + MaterialRenderTargetDepth_t depth = MATERIAL_RT_DEPTH_SHARED, + unsigned int textureFlags = TEXTUREFLAGS_CLAMPS | TEXTUREFLAGS_CLAMPT, + unsigned int renderTargetFlags = 0 + ) + { + return &g_DummyTexture; + } + virtual ITexture* CreateNamedRenderTargetTexture( + const char *pRTName, + int w, + int h, + RenderTargetSizeMode_t sizeMode, // Controls how size is generated (and regenerated on video mode change). + ImageFormat format, + MaterialRenderTargetDepth_t depth, + bool bClampTexCoords, + bool bAutoMipMap + ) + { + return &g_DummyTexture; + } + virtual void SyncToken( const char *pToken ) {} + virtual float ComputePixelWidthOfSphere( const Vector& origin, float flRadius ) + { + return 1.0f; + } + virtual float ComputePixelDiameterOfSphere( const Vector& origin, float flRadius ) + { + return 1.0f; + } + + OcclusionQueryObjectHandle_t CreateOcclusionQueryObject( void ) + { + return INVALID_OCCLUSION_QUERY_OBJECT_HANDLE; + } + + void DestroyOcclusionQueryObject( OcclusionQueryObjectHandle_t handle ) + { + } + + void ResetOcclusionQueryObject( OcclusionQueryObjectHandle_t hOcclusionQuery ) {} + + void BeginOcclusionQueryDrawing( OcclusionQueryObjectHandle_t handle ) + { + } + + void EndOcclusionQueryDrawing( OcclusionQueryObjectHandle_t handle ) + { + } + + int OcclusionQuery_GetNumPixelsRendered( OcclusionQueryObjectHandle_t handle ) + { + return 0; + } + virtual void SetFlashlightMode( bool ) + { + } + virtual bool GetFlashlightMode( void ) const + { + return false; + } + virtual bool InFlashlightMode( void ) const + { + return false; + } + virtual void SetFlashlightState( const FlashlightState_t &state, const VMatrix &worldToTexture ) + { + } + virtual void SetFlashlightStateEx( const FlashlightState_t &state, const VMatrix &worldToTexture, ITexture *pFlashlightDepthTexture ) + { + } + + virtual void SetScissorRect( const int nLeft, const int nTop, const int nRight, const int nBottom, const bool bEnableScissor ) + { + } + + virtual void PushDeformation( DeformationBase_t const *Deformation ) + { + } + + virtual void PopDeformation( ) + { + } + + virtual int GetNumActiveDeformations() const + { + return 0; + } + + + + // Get the current config for this video card (as last set by control panel or the default if not) + virtual const MaterialSystem_Config_t &GetCurrentConfigForVideoCard() const + { + static MaterialSystem_Config_t dummy; + return dummy; + } + + // Get video card identitier + virtual const MaterialSystemHardwareIdentifier_t &GetVideoCardIdentifier( void ) const + { + static MaterialSystemHardwareIdentifier_t dummy; + return dummy; + } + virtual void AddModeChangeCallBack( ModeChangeCallbackFunc_t func ) + { + } + virtual void RemoveModeChangeCallBack( ModeChangeCallbackFunc_t func ) + { + } + virtual bool GetRecommendedConfigurationInfo( int nDxLevel, KeyValues *pKeyValues ) + { + return false; + } + + virtual void EnableUserClipTransformOverride( bool bEnable ) + { + } + + virtual void UserClipTransform( const VMatrix &worldToProjection ) + { + } + + // Used to iterate over all shaders for editing purposes + virtual int ShaderCount() const + { + return 0; + } + + virtual int GetShaders( int nFirstShader, int nCount, IShader **ppShaderList ) const + { + return 0; + } + + // Used to enable editor materials. Must be called before Init. + virtual void EnableEditorMaterials() + { + } + + // Used to enable editor materials. Must be called before Init. + virtual int GetCurrentAdapter() const + { + return 0; + } + + virtual char *GetDisplayDeviceName() const OVERRIDE + { + return ""; + } + + // Creates/destroys morph data associated w/ a particular material + IMorph *CreateMorph( MorphFormat_t, const char *pDebugName ) + { + static CDummyMorph s_DummyMorph; + return &s_DummyMorph; + } + + void DestroyMorph( IMorph *pMorph ) + { + } + + void BindMorph( IMorph *pMorph ) + { + } + + // Sets morph target factors + virtual void SetMorphTargetFactors( int nTargetId, float *pValue, int nCount ) + { + } + + virtual void SetToneMappingScaleLinear( const Vector &scale ) + { + } + + virtual void EvictManagedResources() + { + } + + // Gets the window size + virtual void GetWindowSize( int &width, int &height ) const + { + width = height = 0; + if ( m_pRealMaterialSystem ) + { + CMatRenderContextPtr pRenderContext( m_pRealMaterialSystem ); + pRenderContext->GetWindowSize(width, height); + } + } + + // For dealing with device lost in cases where SwapBuffers isn't called all the time (Hammer) + virtual void HandleDeviceLost() + { + } + + virtual void AppUsesRenderTargets() + { + } + + virtual void DrawScreenSpaceRectangle( + IMaterial *pMaterial, + int destx, int desty, + int width, int height, + float src_texture_x0, float src_texture_y0, + float src_texture_x1, float src_texture_y1, + int src_texture_width, int src_texture_height, + void *pClientRenderable = NULL, + int nXDice = 1, + int nYDice = 1 ) + { + } + + virtual void BeginRenderTargetAllocation() + { + } + + // Simulate an Alt-Tab in here, which causes a release/restore of all resources + virtual void EndRenderTargetAllocation() + { + } + + ITexture *CreateNamedRenderTargetTextureEx2( + const char *pRTName, // Pass in NULL here for an unnamed render target. + int w, + int h, + RenderTargetSizeMode_t sizeMode, // Controls how size is generated (and regenerated on video mode change). + ImageFormat format, + MaterialRenderTargetDepth_t depth = MATERIAL_RT_DEPTH_SHARED, + unsigned int textureFlags = TEXTUREFLAGS_CLAMPS | TEXTUREFLAGS_CLAMPT, + unsigned int renderTargetFlags = 0 + ) + { + return NULL; + }; + + void PushRenderTargetAndViewport( ) + { + } + + void PushRenderTargetAndViewport( ITexture *pTexture ) + { + } + + void PushRenderTargetAndViewport( ITexture *pTexture, int nViewX, int nViewY, int nViewW, int nViewH ) + { + } + + void PushRenderTargetAndViewport( ITexture *pTexture, ITexture *pDepthTexture, int nViewX, int nViewY, int nViewW, int nViewH ) + { + } + + void PopRenderTargetAndViewport( void ) + { + } + + virtual int ShaderFlagCount() const + { + return 0; + } + + virtual const char *ShaderFlagName( int nIndex ) const + { + return ""; + } + + virtual void BindLightmapTexture( ITexture *pLightmapTexture ) + { + } + + // Returns the currently active shader fallback for a particular shader + virtual void GetShaderFallback( const char *pShaderName, char *pFallbackShader, int nFallbackLength ) + { + pFallbackShader[0] = 0; + } + +#ifdef DX_TO_GL_ABSTRACTION + virtual void DoStartupShaderPreloading( void ) + { + } +#endif + + // Blit a subrect of the current render target to another texture + virtual void CopyRenderTargetToTextureEx( ITexture *pTexture, int nRenderTargetID, Rect_t *pSrcRect, Rect_t *pDstRect = NULL ) + { + } + + virtual void CopyTextureToRenderTargetEx( int nRenderTargetID, ITexture *pTexture, Rect_t *pSrcRect, Rect_t *pDstRect = NULL ) + { + } + + bool IsTextureLoaded( char const* pTextureName ) const + { + return false; + } + + void PerspectiveOffCenterX( double fovx, double aspect, double zNear, double zFar, double bottom, double top, double left, double right ) + { + } + + void SetFloatRenderingParameter(int parm_number, float value) + { + } + + void SetIntRenderingParameter(int parm_number, int value) + { + } + void SetVectorRenderingParameter(int parm_number, Vector const &value) + { + } + + float GetFloatRenderingParameter(int parm_number) const + { + return 0; + } + + int GetIntRenderingParameter(int parm_number) const + { + return 0; + } + + Vector GetVectorRenderingParameter(int parm_number) const + { + return Vector(0,0,0); + } + + void ReleaseResources(void) + { + } + + void ReacquireResources(void) + { + } + + Vector GetToneMappingScaleLinear( void ) + { + return Vector(1,1,1); + } + + virtual void GetMaxToRender( IMesh *pMesh, bool bMaxUntilFlush, int *pMaxVerts, int *pMaxIndices ) + { + *pMaxVerts = 32768; + *pMaxIndices = 32768; + } + + // Returns the max possible vertices + indices to render in a single draw call + virtual int GetMaxVerticesToRender( IMaterial *pMaterial ) + { + return 32768; + } + + virtual int GetMaxIndicesToRender( ) + { + return 32768; + } + + // stencil buffer operations. + virtual void SetStencilEnable(bool onoff) + { + } + + virtual void SetStencilFailOperation(StencilOperation_t op) + { + } + + virtual void SetStencilZFailOperation(StencilOperation_t op) + { + } + + virtual void SetStencilPassOperation(StencilOperation_t op) + { + } + + virtual void SetStencilCompareFunction(StencilComparisonFunction_t cmpfn) + { + } + + virtual void SetStencilReferenceValue(int ref) + { + } + + virtual void SetStencilTestMask(uint32 msk) + { + } + + virtual void SetStencilWriteMask(uint32 msk) + { + } + + virtual void ClearStencilBufferRectangle(int xmin, int ymin, int xmax, int ymax, int value) + { + } + + virtual void ModInit() + { + } + + virtual void ModShutdown() + { + } + + virtual void EnableColorCorrection( bool bEnable ) {} + virtual ColorCorrectionHandle_t AddLookup( const char *pName ) { return 0; } + virtual bool RemoveLookup( ColorCorrectionHandle_t handle ) { return true; } + virtual void LockLookup( ColorCorrectionHandle_t handle ) {} + virtual void LoadLookup( ColorCorrectionHandle_t handle, const char *pLookupName ) {} + virtual void UnlockLookup( ColorCorrectionHandle_t handle ) {} + virtual void SetLookupWeight( ColorCorrectionHandle_t handle, float flWeight ) {} + virtual void ResetLookupWeights( ) {} + virtual void SetResetable( ColorCorrectionHandle_t handle, bool bResetable ) {} + + virtual void PushCustomClipPlane( const float *pPlane ) + { + } + + virtual void PopCustomClipPlane( void ) + { + } + + virtual bool EnableClipping( bool bEnable ) + { + return true; + } + + virtual void PushHeightClipPlane( void ) + { + } + void ResetToneMappingScale( float sc) + { + } + void TurnOnToneMapping() + { + } + + virtual void GetDXLevelDefaults(uint &max_dxlevel,uint &recommended_dxlevel) + { + max_dxlevel=recommended_dxlevel=90; + } + + virtual bool UsingFastClipping( void ) + { + return true; //true for "crappier" hardware, so true is safer than false + } + + virtual int StencilBufferBits( void ) + { + return 0; + } + + virtual void DisableAllLocalLights() {} + virtual int CompareMaterialCombos( IMaterial *pMaterial1, IMaterial *pMaterial2, int lightmapID1, int lightmapID2 ) { return 0; } + + virtual bool SupportsMSAAMode( int nMSAAMode ) { return false; } + virtual bool SupportsCSAAMode( int nNumSamples, int nQualityLevel ) { return false; } + virtual bool SupportsHDRMode( HDRType_t nHDRModede ) { return false; } + virtual bool IsDX10Card() { return false; } + + // Hooks for firing PIX events from outside the Material System... + virtual void BeginPIXEvent( unsigned long color, const char *szName ) {}; + virtual void EndPIXEvent() {}; + virtual void SetPIXMarker( unsigned long color, const char *szName ) {}; + + virtual IMatRenderContext *GetRenderContext() { return this; } + + void BeginRender() {} + void BeginRender( float ) {} + void EndRender() {} + + virtual void SetThreadMode( MaterialThreadMode_t, int ) {} + virtual MaterialThreadMode_t GetThreadMode( ) { return MATERIAL_SINGLE_THREADED; } + virtual bool IsRenderThreadSafe( ) { return true; } + virtual bool AllowThreading( bool bAllow, int nServiceThread ) { return false; } + virtual void ExecuteQueued() {} + + virtual void BeginBatch( IMesh* pIndices ) {} + virtual void BindBatch( IMesh* pVertices, IMaterial *pAutoBind = NULL ) {} + virtual void DrawBatch(int nFirstIndex, int nIndexCount ) {} + virtual void EndBatch() {} + + virtual void SetGoalToneMappingScale(float) {} + + virtual bool SupportsShadowDepthTextures( void ) { return false; } + + virtual bool SupportsFetch4( void ) { return false; } + + + virtual void SetShadowDepthBiasFactors( float fShadowSlopeScaleDepthBias, float fShadowDepthBias ) {} + + virtual ICallQueue *GetCallQueue() { return NULL; } + virtual void GetWorldSpaceCameraPosition( Vector *pCameraPos ) + { + pCameraPos->Init(); + } + virtual void GetWorldSpaceCameraVectors( Vector *pVecForward, Vector *pVecRight, Vector *pVecUp ) + { + if ( pVecForward ) + { + pVecForward->Init( 1, 0, 0 ); + } + if ( pVecRight ) + { + pVecRight->Init( 0, -1, 0 ); + } + if ( pVecUp ) + { + pVecUp->Init( 0, 0, 1 ); + } + } + + virtual void BeginUpdateLightmaps() {} + virtual void EndUpdateLightmaps() {} + + virtual MaterialLock_t Lock() { return NULL; } + virtual void Unlock( MaterialLock_t ) {} + + virtual ImageFormat GetShadowDepthTextureFormat() { return IMAGE_FORMAT_UNKNOWN; } + + virtual IMatRenderContext *CreateRenderContext( MaterialContextType_t type ) + { + return RetAddRef( (IMatRenderContext *)this ); + } + + virtual IMatRenderContext *SetRenderContext( IMatRenderContext *pContext ) + { + SafeRelease( pContext ); + return RetAddRef( this ); + } + virtual IVertexBuffer * GetDynamicVertexBuffer( /*VertexFormat_t vertexFormat, */bool buffered = true ) + { + Assert( 0 ); + return NULL; +// return GetDummyMesh(); + } + virtual IIndexBuffer * GetDynamicIndexBuffer( /*MaterialIndexFormat_t fmt, */bool buffered = true ) + { + Assert( 0 ); + return NULL; +// return GetDummyMesh(); + } + +// ------------ New Vertex/Index Buffer interface ---------------------------- + virtual IVertexBuffer *CreateStaticVertexBuffer( VertexFormat_t fmt, int nVertexCount, const char *pBudgetGroup ) + { + Assert( 0 ); + return NULL; + } + virtual IIndexBuffer *CreateStaticIndexBuffer( MaterialIndexFormat_t fmt, int nIndexCount, const char *pBudgetGroup ) + { + Assert( 0 ); + return NULL; + } + virtual void DestroyVertexBuffer( IVertexBuffer * ) + { + } + virtual void DestroyIndexBuffer( IIndexBuffer * ) + { + } + // Do we need to specify the stream here in the case of locking multiple dynamic VBs on different streams? + virtual IVertexBuffer *GetDynamicVertexBuffer( int streamID, VertexFormat_t vertexFormat, bool bBuffered = true ) + { + Assert( 0 ); + return NULL; + } + virtual IIndexBuffer *GetDynamicIndexBuffer( MaterialIndexFormat_t fmt, bool bBuffered = true ) + { + Assert( 0 ); + return NULL; + } + virtual void BindVertexBuffer( int streamID, IVertexBuffer *pVertexBuffer, int nOffsetInBytes, int nFirstVertex, int nVertexCount, VertexFormat_t fmt, int nRepetitions = 1 ) + { + } + virtual void BindIndexBuffer( IIndexBuffer *pIndexBuffer, int nOffsetInBytes ) + { + } + virtual void Draw( MaterialPrimitiveType_t primitiveType, int nFirstIndex, int nIndexCount ) + { + } + virtual void BeginMorphAccumulation() + { + } + virtual void EndMorphAccumulation() + { + } + virtual void AccumulateMorph( IMorph* pMorph, int nMorphCount, const MorphWeight_t* pWeights ) + { + } + virtual bool GetMorphAccumulatorTexCoord( Vector2D *pTexCoord, IMorph *pMorph, int nVertex ) + { + pTexCoord->Init(); + return false; + } +// ------------ End ---------------------------- + + virtual ImageFormat GetNullTextureFormat() { return IMAGE_FORMAT_UNKNOWN; } + + virtual void AddTextureAlias( const char *pAlias, const char *pRealName ) {} + virtual void RemoveTextureAlias( const char *pAlias ) {} + + virtual void SetExcludedTextures( const char *pScriptName ) {} + virtual void UpdateExcludedTextures( void ) {} + + virtual void SetFlexWeights( int nFirstWeight, int nCount, const MorphWeight_t* pWeights ) {} + + virtual bool SupportsBorderColor() { return false; } + + virtual IMaterial *GetCurrentMaterial() { return NULL; } + virtual int GetCurrentNumBones() const { return 0; } + virtual void *GetCurrentProxy() { return NULL; } + + virtual void SetFullScreenDepthTextureValidityFlag( bool bIsValid ) {} + + // A special path used to tick the front buffer while loading on the 360 + virtual void SetNonInteractivePacifierTexture( ITexture *pTexture, float flNormalizedX, float flNormalizedY, float flNormalizedSize ) {} + virtual void SetNonInteractiveTempFullscreenBuffer( ITexture *pTexture, MaterialNonInteractiveMode_t mode ) {} + virtual void EnableNonInteractiveMode( MaterialNonInteractiveMode_t mode ) {} + virtual void RefreshFrontBufferNonInteractive() {} + + virtual void * LockRenderData( int nSizeInBytes ) { return NULL; } + virtual void UnlockRenderData( void *pData ) {} + virtual bool IsRenderData( const void *pData ) const { return false; } + virtual void AddRefRenderData() {} + virtual void ReleaseRenderData() {} +#if defined( _X360 ) + virtual void ListUsedMaterials( void ) {} + virtual HXUIFONT OpenTrueTypeFont( const char *pFontname, int tall, int style ) + { + return (HXUIFONT)0; + } + virtual void CloseTrueTypeFont( HXUIFONT hFont ) {} + virtual bool GetTrueTypeFontMetrics( HXUIFONT hFont, XUIFontMetrics *pFontMetrics, XUICharMetrics charMetrics[256] ) + { + pFontMetrics->fLineHeight = 0.0f; + pFontMetrics->fMaxAscent = 0.0f; + pFontMetrics->fMaxDescent = 0.0f; + pFontMetrics->fMaxWidth = 0.0f; + pFontMetrics->fMaxHeight = 0.0f; + pFontMetrics->fMaxAdvance = 0.0f; + return true; + } + + virtual bool GetTrueTypeGlyphs( HXUIFONT hFont, int numChars, wchar_t *pWch, int *pOffsetX, int *pOffsetY, int *pWidth, int *pHeight, unsigned char *pRGBA, int *pRGBAOffset ) + { + return false; + } + + virtual void PersistDisplay() {} + virtual void *GetD3DDevice() { return NULL; } + + virtual void PushVertexShaderGPRAllocation( int iVertexShaderCount = 64 ) { }; + virtual void PopVertexShaderGPRAllocation( void ) { }; + + virtual bool OwnGPUResources( bool bEnable ) { return false; } +#endif + + virtual void CompactMemory() {} + + // For sv_pure mode. The filesystem figures out which files the client needs to reload to be "pure" ala the server's preferences. + virtual void ReloadFilesInList( IFileList *pFilesToReload ) + { + } + + virtual void PrintfVA( char *fmt, va_list vargs ) {} + virtual void Printf( const char *fmt, ... ) {} + virtual float Knob( char *knobname, float *setvalue=NULL ) { return 0.0f; } + + virtual void SetRenderTargetFrameBufferSizeOverrides( int nWidth, int nHeight ) OVERRIDE + { + // Nope. + } + virtual void GetRenderTargetFrameBufferDimensions( int & nWidth, int & nHeight ) OVERRIDE + { + GetBackBufferDimensions( nWidth, nHeight ); + } + + virtual ITexture* CreateTextureFromBits(int w, int h, int mips, ImageFormat fmt, int srcBufferSize, byte* srcBits) + { + return NULL; + } + + virtual void OverrideRenderTargetAllocation( bool ) + { + // anda + + } + + virtual ITextureCompositor* NewTextureCompositor( int w, int h, const char* pCompositeName, int nTeamNum, uint64 randomSeed, KeyValues* stageDesc, uint texCompositeCreateFlags ) OVERRIDE + { + return NULL; + } + + virtual void AsyncFindTexture( const char* pFilename, const char *pTextureGroupName, IAsyncTextureOperationReceiver* pRecipient, void* pExtraArgs, bool bComplain = true, int nAdditionalCreationFlags = 0 ) + { + + } + + virtual void AsyncCreateTextureFromRenderTarget( ITexture* pSrcRt, const char* pDstName, ImageFormat dstFmt, bool bGenMips, int nAdditionalCreationFlags, IAsyncTextureOperationReceiver* pRecipient, void* pExtraArgs ) + { + + } + + virtual ITexture* CreateNamedTextureFromBitsEx( const char* pName, const char *pTextureGroupName, int w, int h, int mips, ImageFormat fmt, int srcBufferSize, byte* srcBits, int nFlags ) + { + return NULL; + } + + virtual bool AddTextureCompositorTemplate( const char* pName, KeyValues* pTmplDesc, int nTexCompositeTemplateFlags ) OVERRIDE + { + return false; + } + + virtual bool VerifyTextureCompositorTemplates() OVERRIDE + { + return false; + } + +}; + + +static CDummyMaterialSystem g_DummyMaterialSystem; + +EXPOSE_SINGLE_INTERFACE_GLOBALVAR( CDummyMaterialSystem, IMaterialSystemStub, + MATERIAL_SYSTEM_STUB_INTERFACE_VERSION, g_DummyMaterialSystem ); + + diff --git a/materialsystem/materialsystem.vpc b/materialsystem/materialsystem.vpc new file mode 100644 index 0000000..d0394cf --- /dev/null +++ b/materialsystem/materialsystem.vpc @@ -0,0 +1,174 @@ +//----------------------------------------------------------------------------- +// MATERIALSYSTEM.VPC +// +// Project Script +//----------------------------------------------------------------------------- + +$macro SRCDIR ".." +$Macro OUTBINDIR "$SRCDIR\..\game\bin" + +$include "$SRCDIR\vpc_scripts\source_dll_base.vpc" + +$Configuration +{ + $Compiler + { + $PreprocessorDefinitions "$BASE;DEFINE_MATERIALSYSTEM_INTERFACE;MATERIALSYSTEM_EXPORTS;PROTECTED_THINGS_ENABLE;strncpy=use_Q_strncpy_instead;_snprintf=use_Q_snprintf_instead" + $PreprocessorDefinitions "$BASE;fopen=dont_use_fopen" [$WINDOWS] + $Create/UsePCHThroughFile "pch_materialsystem.h" + } + $Linker + { + $SystemLibraries "iconv" [$OSXALL] + } +} + +$Configuration "Debug" +{ + $Linker [$X360] + { + $AdditionalDependencies "$BASE d3dx9d.lib" + } +} + +$Configuration "Release" +{ + $Linker [$X360] + { + $AdditionalDependencies "$BASE d3dx9.lib" + } +} + +$Project "MaterialSystem" +{ + $Folder "Source Files" + { + $File "CColorCorrection.cpp" + $File "cmaterial.cpp" + $File "cmaterial_queuefriendly.cpp" + $File "CMaterialSubRect.cpp" + $File "cmaterialvar.cpp" + $File "cmatnullrendercontext.cpp" + $File "colorspace.cpp" + $File "ctexture.cpp" + $File "$SRCDIR\public\filesystem_helpers.cpp" + $File "imagepacker.cpp" + $File "mat_stub.cpp" + $File "materialsystem_global.cpp" + $File "morph.cpp" + $File "occlusionquerymgr.cpp" + $File "shadersystem.cpp" + $File "texturemanager.cpp" + + $File "pch_materialsystem.cpp" + { + $Configuration + { + $Compiler + { + $Create/UsePrecompiledHeader "Create Precompiled Header (/Yc)" + } + } + } + + $File "cmaterialdict.cpp" \ + "cmaterialsystem.cpp" \ + "cmatlightmaps.cpp" \ + "cmatrendercontext.cpp" \ + "cmatqueuedrendercontext.cpp" \ + "ctexturecompositor.cpp" + { + $Configuration + { + $Compiler + { + $Create/UsePrecompiledHeader "Use Precompiled Header (/Yu)" + } + } + } + } + + $Folder "Public Header Files" + { + $File "$SRCDIR\public\mathlib\amd3dx.h" + $File "$SRCDIR\public\tier0\basetypes.h" + $File "$SRCDIR\public\mathlib\bumpvects.h" + $File "$SRCDIR\public\const.h" + $File "$SRCDIR\public\tier1\convar.h" + $File "$SRCDIR\public\crtmemdebug.h" + $File "$SRCDIR\common\cstringhash.h" + $File "$SRCDIR\public\filesystem.h" + $File "$SRCDIR\public\appframework\IAppSystem.h" + $File "$SRCDIR\public\materialsystem\combineoperations.h" + $File "$SRCDIR\public\materialsystem\IColorCorrection.h" + $File "$SRCDIR\public\materialsystem\imaterial.h" + $File "$SRCDIR\public\materialsystem\imaterialproxy.h" + $File "$SRCDIR\public\materialsystem\imaterialproxyfactory.h" + $File "$SRCDIR\public\materialsystem\imaterialsystem.h" + $File "$SRCDIR\public\materialsystem\imaterialsystemhardwareconfig.h" + $File "$SRCDIR\public\materialsystem\imaterialsystemstub.h" + $File "$SRCDIR\public\materialsystem\imaterialvar.h" + $File "$SRCDIR\public\materialsystem\imesh.h" + $File "$SRCDIR\public\materialsystem\imorph.h" + $File "$SRCDIR\public\tier1\interface.h" + $File "$SRCDIR\public\materialsystem\IShader.h" + $File "$SRCDIR\public\materialsystem\ishaderapi.h" + $File "$SRCDIR\public\materialsystem\itexture.h" + $File "$SRCDIR\public\materialsystem\itexturecompositor.h" + $File "$SRCDIR\public\tier1\KeyValues.h" + $File "$SRCDIR\public\materialsystem\materialsystem_config.h" + $File "$SRCDIR\public\mathlib\mathlib.h" + $File "$SRCDIR\public\tier1\mempool.h" + $File "$SRCDIR\public\pixelwriter.h" + $File "$SRCDIR\public\renderparm.h" + $File "$SRCDIR\public\tier1\strtools.h" + $File "$SRCDIR\public\tier1\utlbuffer.h" + $File "$SRCDIR\public\tier1\utlmemory.h" + $File "$SRCDIR\public\tier1\utlrbtree.h" + $File "$SRCDIR\public\tier1\utlsymbol.h" + $File "$SRCDIR\public\tier1\utlvector.h" + $File "$SRCDIR\public\mathlib\vector.h" + $File "$SRCDIR\public\mathlib\vector2d.h" + $File "$SRCDIR\public\mathlib\vector4d.h" + $File "$SRCDIR\public\mathlib\vmatrix.h" + $File "$SRCDIR\public\mathlib\vplane.h" + $File "$SRCDIR\public\vstdlib\vstdlib.h" + $File "$SRCDIR\public\vtf\vtf.h" + } + + $Folder "Header Files" + { + $File "cmaterial_queuefriendly.h" + $File "cmaterialdict.h" + $File "cmaterialsystem.h" + $File "cmatlightmaps.h" + $File "cmatnullrendercontext.h" + $File "cmatqueuedrendercontext.h" + $File "cmatrendercontext.h" + $File "colorspace.h" + $File "ctexturecompositor.h" + $File "IHardwareConfigInternal.h" + $File "imagepacker.h" + $File "imaterialinternal.h" + $File "imaterialsysteminternal.h" + $File "imatrendercontextinternal.h" + $File "imorphinternal.h" + $File "IShaderSystem.h" + $File "$SRCDIR\public\shaderapi\ishaderutil.h" + $File "itextureinternal.h" + $File "materialsystem_global.h" + $File "occlusionquerymgr.h" + $File "shader_dll_verify.h" [$WIN32] + $File "shadersystem.h" + $File "texturemanager.h" + } + + $Folder "Link Libraries" + { + $Lib bitmap + $Lib mathlib + $Lib shaderlib + $Lib tier2 + $Lib vtf + } +} diff --git a/materialsystem/materialsystem_global.cpp b/materialsystem/materialsystem_global.cpp new file mode 100644 index 0000000..f64c155 --- /dev/null +++ b/materialsystem/materialsystem_global.cpp @@ -0,0 +1,20 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//=====================================================================================// + +#include "materialsystem_global.h" +#include "shaderapi/ishaderapi.h" +#include "shadersystem.h" +#include +#include "filesystem.h" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +int g_FrameNum; +IShaderAPI *g_pShaderAPI = 0; +IShaderDeviceMgr* g_pShaderDeviceMgr = 0; +IShaderDevice *g_pShaderDevice = 0; +IShaderShadow* g_pShaderShadow = 0; diff --git a/materialsystem/materialsystem_global.h b/materialsystem/materialsystem_global.h new file mode 100644 index 0000000..bed23a7 --- /dev/null +++ b/materialsystem/materialsystem_global.h @@ -0,0 +1,110 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $Header: $ +// $NoKeywords: $ +// +//=============================================================================// + +#ifndef MATERIALSYSTEM_GLOBAL_H +#define MATERIALSYSTEM_GLOBAL_H + +#ifdef _WIN32 +#pragma once +#endif + +#include "imaterialsysteminternal.h" +#include "tier0/dbg.h" +#include "tier2/tier2.h" + + +//----------------------------------------------------------------------------- +// Forward declarations +//----------------------------------------------------------------------------- +class ITextureInternal; +class IShaderAPI; +class IHardwareConfigInternal; +class IShaderUtil; +class IShaderShadow; +class IShaderDeviceMgr; +class IShaderDevice; +class IShaderSystemInternal; +class IMaterialInternal; +class IColorCorrectionSystem; +class IMaterialVar; + + +//----------------------------------------------------------------------------- +// Constants used by the system +//----------------------------------------------------------------------------- + +#define MATERIAL_MAX_PATH 256 + +// GR - limits for blured image (HDR stuff) +#define MAX_BLUR_IMAGE_WIDTH 256 +#define MAX_BLUR_IMAGE_HEIGHT 192 + +#define CLAMP_BLUR_IMAGE_WIDTH( _w ) ( ( _w < MAX_BLUR_IMAGE_WIDTH ) ? _w : MAX_BLUR_IMAGE_WIDTH ) +#define CLAMP_BLUR_IMAGE_HEIGHT( _h ) ( ( _h < MAX_BLUR_IMAGE_HEIGHT ) ? _h : MAX_BLUR_IMAGE_HEIGHT ) + +//----------------------------------------------------------------------------- +// Global structures +//----------------------------------------------------------------------------- +extern MaterialSystem_Config_t g_config; +extern uint32 g_nDebugVarsSignature; + +//extern MaterialSystem_ErrorFunc_t Error; +//extern MaterialSystem_WarningFunc_t Warning; + +extern int g_FrameNum; + +extern IShaderAPI* g_pShaderAPI; +extern IShaderDeviceMgr* g_pShaderDeviceMgr; +extern IShaderDevice* g_pShaderDevice; +extern IShaderShadow* g_pShaderShadow; + +extern IMaterialInternal *g_pErrorMaterial; + +IShaderSystemInternal* ShaderSystem(); +inline IShaderSystemInternal* ShaderSystem() +{ + extern IShaderSystemInternal *g_pShaderSystem; + return g_pShaderSystem; +} + +inline IHardwareConfigInternal *HardwareConfig() +{ + extern IHardwareConfigInternal* g_pHWConfig; + return g_pHWConfig; +} + +//----------------------------------------------------------------------------- +// Accessor to get at the material system +//----------------------------------------------------------------------------- +inline IMaterialSystemInternal* MaterialSystem() +{ + extern IMaterialSystemInternal *g_pInternalMaterialSystem; + return g_pInternalMaterialSystem; +} + +inline IShaderUtil* ShaderUtil() +{ + extern IShaderUtil *g_pShaderUtil; + return g_pShaderUtil; +} + +extern IColorCorrectionSystem *g_pColorCorrectionSystem; +inline IColorCorrectionSystem *ColorCorrectionSystem() +{ + return g_pColorCorrectionSystem; +} + + +//----------------------------------------------------------------------------- +// Global methods related to material vars +//----------------------------------------------------------------------------- +void EnableThreadedMaterialVarAccess( bool bEnable, IMaterialVar **ppParams, int nVarCount ); + + +#endif // MATERIALSYSTEM_GLOBAL_H diff --git a/materialsystem/morph.cpp b/materialsystem/morph.cpp new file mode 100644 index 0000000..fba110b --- /dev/null +++ b/materialsystem/morph.cpp @@ -0,0 +1,2280 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//===========================================================================// + +#include "imorphinternal.h" +#include "tier0/dbg.h" +#include "materialsystem/imaterialsystem.h" +#include "materialsystem/MaterialSystemUtil.h" +#include "materialsystem/itexture.h" +#include "materialsystem/imesh.h" +#include "UtlSortVector.h" +#include "materialsystem_global.h" +#include "IHardwareConfigInternal.h" +#include "pixelwriter.h" +#include "itextureinternal.h" +#include "tier1/KeyValues.h" +#include "texturemanager.h" +#include "imaterialsysteminternal.h" +#include "imatrendercontextinternal.h" +#include "studio.h" +#include "tier0/vprof.h" +#include "renderparm.h" +#include "tier2/renderutils.h" +#include "bitmap/imageformat.h" +#include "materialsystem/IShader.h" +#include "imaterialinternal.h" + + +#include "tier0/memdbgon.h" + +//----------------------------------------------------------------------------- +// Activate to get stats +//----------------------------------------------------------------------------- +//#define REPORT_MORPH_STATS 1 + + +//----------------------------------------------------------------------------- +// Used to collapse quads with small gaps +//----------------------------------------------------------------------------- +#define MIN_SEGMENT_GAP_SIZE 12 + + +//----------------------------------------------------------------------------- +// Used to compile the morph data into a vertex texture +//----------------------------------------------------------------------------- +class CVertexMorphDict +{ +public: + CVertexMorphDict(); + + // Adds a morph to the dictionary + void AddMorph( const MorphVertexInfo_t &info ); + + // Sets up, cleans up the morph information + void Setup( ); + void CleanUp(); + + // Gets at morph info + int MorphCount() const; + int GetMorphTargetId( int nMorphTargetIndex ) const; + int GetMorphVertexCount( int nMorphTargetIndex ) const; + const MorphVertexInfo_t &GetMorphVertexInfo( int nMorphTargetIndex, int nIndex ) const; + + // Sorts deltas by destination vertex + void SortDeltas(); + +private: + // Sort method for each morph target's vertices + class CMorphVertexListLess + { + public: + bool Less( const MorphVertexInfo_t& src1, const MorphVertexInfo_t& src2, void *pCtx ) + { + return src1.m_nVertexId < src2.m_nVertexId; + } + }; + + // A list of all vertices affecting a particular morph target + struct MorphVertexList_t + { + MorphVertexList_t() {} + MorphVertexList_t( const MorphVertexList_t& src ) : m_nMorphTargetId( src.m_nMorphTargetId ) {} + + int m_nMorphTargetId; + CUtlSortVector< MorphVertexInfo_t, CMorphVertexListLess > m_MorphInfo; + }; + + // Sort function for the morph lists + class VertexMorphDictLess + { + public: + bool Less( const MorphVertexList_t& src1, const MorphVertexList_t& src2, void *pCtx ); + }; + + // For each morph, store all target vertex indices + // List of all morphs affecting all vertices, used for constructing the morph only + CUtlSortVector< MorphVertexList_t, VertexMorphDictLess > m_MorphLists; +}; + + +//----------------------------------------------------------------------------- +// Used to sort the morphs affecting a particular vertex +//----------------------------------------------------------------------------- +bool CVertexMorphDict::VertexMorphDictLess::Less( const CVertexMorphDict::MorphVertexList_t& src1, const CVertexMorphDict::MorphVertexList_t& src2, void *pCtx ) +{ + return src1.m_nMorphTargetId < src2.m_nMorphTargetId; +} + + +//----------------------------------------------------------------------------- +// Dictionary of morphs affecting a particular vertex +//----------------------------------------------------------------------------- +CVertexMorphDict::CVertexMorphDict() : m_MorphLists() +{ +} + + +//----------------------------------------------------------------------------- +// Adds a morph to the dictionary +//----------------------------------------------------------------------------- +void CVertexMorphDict::AddMorph( const MorphVertexInfo_t &info ) +{ + Assert( info.m_nVertexId != 65535 ); + + MorphVertexList_t find; + find.m_nMorphTargetId = info.m_nMorphTargetId; + int nIndex = m_MorphLists.Find( find ); + if ( nIndex == m_MorphLists.InvalidIndex() ) + { + m_MorphLists.Insert( find ); + nIndex = m_MorphLists.Find( find ); + } + + m_MorphLists[nIndex].m_MorphInfo.InsertNoSort( info ); +} + + +//----------------------------------------------------------------------------- +// Sets up, cleans up the morph information +//----------------------------------------------------------------------------- +void CVertexMorphDict::Setup( ) +{ + m_MorphLists.Purge(); +} + +void CVertexMorphDict::CleanUp( ) +{ +} + + +//----------------------------------------------------------------------------- +// Gets at the dictionary elemenst +//----------------------------------------------------------------------------- +int CVertexMorphDict::MorphCount() const +{ + return m_MorphLists.Count(); +} + +int CVertexMorphDict::GetMorphTargetId( int i ) const +{ + if ( i >= m_MorphLists.Count() ) + return -1; + + return m_MorphLists[i].m_nMorphTargetId; +} + +int CVertexMorphDict::GetMorphVertexCount( int nMorphTarget ) const +{ + return m_MorphLists[nMorphTarget].m_MorphInfo.Count(); +} + +const MorphVertexInfo_t &CVertexMorphDict::GetMorphVertexInfo( int nMorphTarget, int j ) const +{ + return m_MorphLists[nMorphTarget].m_MorphInfo[j]; +} + + +//----------------------------------------------------------------------------- +// Sorts deltas by destination vertex +//----------------------------------------------------------------------------- +void CVertexMorphDict::SortDeltas() +{ + int nMorphTargetCount = m_MorphLists.Count(); + for ( int i = 0; i < nMorphTargetCount; ++i ) + { + m_MorphLists[i].m_MorphInfo.RedoSort(); + } +} + + +//----------------------------------------------------------------------------- +// +// Morph data class +// +//----------------------------------------------------------------------------- +class CMorph : public IMorphInternal, public ITextureRegenerator +{ +public: + // Constructor, destructor + CMorph(); + ~CMorph(); + + // Inherited from IMorph + virtual void Lock( float flFloatToFixedScale ); + virtual void AddMorph( const MorphVertexInfo_t &info ); + virtual void Unlock( ); + + // Inherited from IMorphInternal + virtual void Init( MorphFormat_t format, const char *pDebugName ); + virtual void Bind( IMorphMgrRenderContext *pRenderContext ); + virtual MorphFormat_t GetMorphFormat() const; + + // Other public methods + bool RenderMorphWeights( IMatRenderContext *pRenderContext, int nRenderId, int nWeightCount, const MorphWeight_t* pWeights ); + void AccumulateMorph( int nRenderId ); + +private: + // A list of all morphs affecting a particular vertex + // Assume that consecutive morphs are stored under each other in V coordinates + // both in the src texture and destination texture (which is the morph accumulation texture). + struct MorphSegment_t + { + unsigned int m_nFirstSrc; + unsigned short m_nFirstDest; + unsigned short m_nCount; + }; + + struct MorphQuad_t + { + unsigned int m_nFirstSrc; + unsigned short m_nFirstDest; + unsigned short m_nCount; + unsigned short m_nQuadIndex; + }; + + enum MorphTextureId_t + { + MORPH_TEXTURE_POS_NORMAL_DELTA = 0, + MORPH_TEXTURE_SPEED_SIDE_MAP, + + MORPH_TEXTURE_COUNT + }; + + typedef void (CMorph::*MorphPixelWriter_t)( CPixelWriter &pixelWriter, int x, int y, const MorphVertexInfo_t &info ); + + typedef CUtlVector< MorphSegment_t > MorphSegmentList_t; + typedef CUtlVector< MorphQuad_t > MorphQuadList_t; + +private: + // Inherited from ITextureRegenerator + virtual void RegenerateTextureBits( ITexture *pTexture, IVTFTexture *pVTFTexture, Rect_t *pRect ); + virtual void Release() {} + + // Packs all morph data in the dictionary into a vertex texture layout + void PackMorphData( ); + + // Builds the list of segments to render, returns total # of src texels to read from + void BuildSegmentList( CUtlVector< MorphSegmentList_t > &morphSegments ); + + // Builds the list of quads to render + void BuildQuadList( const CUtlVector< MorphSegmentList_t > &morphSegments ); + + // Computes the vertex texture width + void ComputeTextureDimensions( const CUtlVector< MorphSegmentList_t > &morphSegments ); + + // Writes a morph delta into the texture + void WriteDeltaPositionNormalToTexture( CPixelWriter &pixelWriter, int x, int y, const MorphVertexInfo_t &info ); + void WriteSideSpeedToTexture( CPixelWriter &pixelWriter, int x, int y, const MorphVertexInfo_t &info ); + + // Computes the morph target 4tuple count + int Get4TupleCount( MorphFormat_t format ) const; + + // Cleans up vertex textures + void CleanUp( ); + + // Is the morph locked? + bool IsLocked() const; + + // Creates a material for use to do the morph accumulation + void CreateAccumulatorMaterial( int nMaterialIndex ); + + // Renders to the morph accumulator texture + void RenderMorphQuads( IMatRenderContext *pRenderContext, int nRenderId, int nTotalQuadCount, int nWeightCount, int *pWeightLookup, const MorphWeight_t* pWeights ); + + // Displays static morph data statistics + void DisplayMorphStats(); + + // Dynamic stat data + void ClearMorphStats(); + void AccumulateMorphStats( int nActiveMorphCount, int nQuadsRendered, int nTexelsRendered ); + void ReportMorphStats( ); + void HandleMorphStats( int nActiveMorphCount, int nQuadsRendered, int nTexelsRendered ); + + // Computes morph texture size in bytes + int ComputeMorphTextureSizeInBytes( ) const; + + // Counts the total number of vertices to place in the static mesh + int CountStaticMeshVertices() const; + + // Determines mesh vertex format + VertexFormat_t ComputeVertexFormat( IMaterial * pMaterial ) const; + + // Builds the list of quads to render + void CreateStaticMesh(); + + // Builds a list of non-zero morph targets + int BuildNonZeroMorphList( int *pWeightIndices, int nWeightCount, const MorphWeight_t* pWeights ); + + // Determines the total number of deltas + int DetermineTotalDeltaCount( const CUtlVector< MorphSegmentList_t > &morphSegments ) const; + + // Binds the morph weight texture + void BindMorphWeight( int nRenderId ); + +private: + // Used when constructing the morph targets + CVertexMorphDict m_MorphDict; + bool m_bLocked; + + // The morph format + MorphFormat_t m_Format; + + // The compiled vertex textures + ITextureInternal *m_pMorphTexture[MORPH_TEXTURE_COUNT]; + + // The compiled vertex streams + IMesh* m_pMorphBuffer; + + // Describes all morph line segments required to draw a particular morph + CUtlVector< MorphQuadList_t > m_MorphQuads; + CUtlVector< int > m_MorphTargetIdToQuadIndex; + + // Caches off the morph weights when in the middle of performing morph accumulation + int m_nMaxMorphTargetCount; + MorphWeight_t *m_pRenderMorphWeight; + + CMaterialReference m_MorphAccumulationMaterial; + + // Float->fixed scale + float m_flFloatToFixedScale; + + // Morph input texture size + int m_nTextureWidth; + int m_nTextureHeight; + +#ifdef _DEBUG + CUtlString m_pDebugName; +#endif + + // Used to unique-ify morph texture names + static int s_nUniqueId; +}; + + +//----------------------------------------------------------------------------- +// Render context for morphing. Only is used to determine +// where in the morph accumulator to put the texture. +//----------------------------------------------------------------------------- +class CMorphMgrRenderContext : public IMorphMgrRenderContext +{ +public: + enum UnnamedEnumsAreNotLegal + { + MAX_MODEL_MORPHS = 4, + }; + + CMorphMgrRenderContext(); + int GetRenderId( CMorph* pMorph ); + +public: + int m_nMorphCount; + CMorph *m_pMorphsToAccumulate[MAX_MODEL_MORPHS]; + +#ifdef DBGFLAG_ASSERT + bool m_bInMorphAccumulation; +#endif +}; + + +//----------------------------------------------------------------------------- +// Morph manager class +//----------------------------------------------------------------------------- +class CMorphMgr : public IMorphMgr +{ +public: + CMorphMgr(); + + // Methods of IMorphMgr + virtual bool ShouldAllocateScratchTextures(); + virtual void AllocateScratchTextures(); + virtual void FreeScratchTextures(); + virtual void AllocateMaterials(); + virtual void FreeMaterials(); + virtual ITextureInternal *MorphAccumulator(); + virtual ITextureInternal *MorphWeights(); + virtual IMorphInternal *CreateMorph(); + virtual void DestroyMorph( IMorphInternal *pMorphData ); + virtual int MaxHWMorphBatchCount() const; + virtual void BeginMorphAccumulation( IMorphMgrRenderContext *pIRenderContext ); + virtual void EndMorphAccumulation( IMorphMgrRenderContext *pIRenderContext ); + virtual void AccumulateMorph( IMorphMgrRenderContext *pIRenderContext, IMorph* pMorph, int nMorphCount, const MorphWeight_t* pWeights ); + virtual void AdvanceFrame(); + virtual bool GetMorphAccumulatorTexCoord( IMorphMgrRenderContext *pRenderContext, Vector2D *pTexCoord, IMorph *pMorph, int nVertex ); + virtual IMorphMgrRenderContext *AllocateRenderContext(); + virtual void FreeRenderContext( IMorphMgrRenderContext *pRenderContext ); + + // Other public methods +public: + // Computes texel offsets for the upper corner of the morph accumulator for a particular block + void ComputeAccumulatorSubrect( int *pXOffset, int *pYOffset, int *pWidth, int *pHeight, int nMorphAccumBlockId ); + void GetAccumulatorSubrectDimensions( int *pWidth, int *pHeight ); + int GetAccumulator4TupleCount() const; + + // Computes texel offsets for the upper corner of the morph weight texture for a particular block + void ComputeWeightSubrect( int *pXOffset, int *pYOffset, int *pWidth, int *pHeight, int nMorphAccumBlockId ); + + // Used to compute stats of memory used + void RegisterMorphSizeInBytes( int nSizeInBytes ); + int GetTotalMemoryUsage() const; + + // Are we using the constant register method? + bool IsUsingConstantRegisters() const { return m_bUsingConstantRegisters; } + +private: + // Displays 32bit float texture data + void Display32FTextureData( float *pBuf, int nTexelID, int *pSubRect, ITexture *pTexture, int n4TupleCount ); + + // A debugging utility to display the morph accumulator + void DebugMorphAccumulator( IMatRenderContext *pRenderContext ); + + // A debugging utility to display the morph weights + void DebugMorphWeights( IMatRenderContext *pRenderContext ); + + // Draws the morph accumulator + morph weights + void DrawMorphTempTexture( IMatRenderContext *pRenderContext, IMaterial *pMaterial, ITexture *pTexture ); + +private: + enum + { + MAX_MORPH_ACCUMULATOR_VERTICES = 32768, + MORPH_ACCUMULATOR_4TUPLES = 2, // 1 for pos + wrinkle, 1 for normal + }; + + int m_nAccumulatorWidth; + int m_nAccumulatorHeight; + int m_nSubrectVerticalCount; + int m_nWeightWidth; + int m_nWeightHeight; + int m_nFrameCount; + int m_nTotalMorphSizeInBytes; + IMaterial *m_pPrevMaterial; + void *m_pPrevProxy; + int m_nPrevBoneCount; + MaterialHeightClipMode_t m_nPrevClipMode; + bool m_bPrevClippingEnabled; + bool m_bUsingConstantRegisters; + bool m_bFlashlightMode; + + ITextureInternal *m_pMorphAccumTexture; + ITextureInternal *m_pMorphWeightTexture; + IMaterial *m_pVisualizeMorphAccum; + IMaterial *m_pVisualizeMorphWeight; + IMaterial *m_pRenderMorphWeight; +}; + + +//----------------------------------------------------------------------------- +// Singleton +//----------------------------------------------------------------------------- +static CMorphMgr s_MorphMgr; +IMorphMgr *g_pMorphMgr = &s_MorphMgr; + + + +//----------------------------------------------------------------------------- +// Globals +//----------------------------------------------------------------------------- +int CMorph::s_nUniqueId = 0; + + +//----------------------------------------------------------------------------- +// Constructor, destructor +//----------------------------------------------------------------------------- +CMorph::CMorph() +{ + memset( m_pMorphTexture, 0, sizeof(m_pMorphTexture) ); + m_pMorphBuffer = NULL; + m_nTextureWidth = 0; + m_nTextureHeight = 0; + m_bLocked = false; + m_Format = 0; + m_flFloatToFixedScale = 1.0f; + m_pRenderMorphWeight = 0; + m_nMaxMorphTargetCount = 0; +} + +CMorph::~CMorph() +{ + CleanUp(); +} + + +//----------------------------------------------------------------------------- +// Initialization +//----------------------------------------------------------------------------- +void CMorph::Init( MorphFormat_t format, const char *pDebugName ) +{ + m_Format = format; + +#ifdef _DEBUG + m_pDebugName = pDebugName; +#endif +} + + +//----------------------------------------------------------------------------- +// Returns the morph format +//----------------------------------------------------------------------------- +MorphFormat_t CMorph::GetMorphFormat() const +{ + return m_Format; +} + + +//----------------------------------------------------------------------------- +// Binds morph accumulator, morph weights +//----------------------------------------------------------------------------- +void CMorph::Bind( IMorphMgrRenderContext *pIRenderContext ) +{ + CMorphMgrRenderContext *pMorphRenderContext = static_cast< CMorphMgrRenderContext* >( pIRenderContext ); + int nRenderId = pMorphRenderContext->GetRenderId( this ); + if ( nRenderId < 0 ) + return; + + int nXOffset, nYOffset, nWidth, nHeight; + s_MorphMgr.ComputeAccumulatorSubrect( &nXOffset, &nYOffset, &nWidth, &nHeight, nRenderId ); + + g_pShaderAPI->SetIntRenderingParameter( INT_RENDERPARM_MORPH_ACCUMULATOR_4TUPLE_COUNT, s_MorphMgr.GetAccumulator4TupleCount() ); + g_pShaderAPI->SetIntRenderingParameter( INT_RENDERPARM_MORPH_ACCUMULATOR_X_OFFSET, nXOffset ); + g_pShaderAPI->SetIntRenderingParameter( INT_RENDERPARM_MORPH_ACCUMULATOR_Y_OFFSET, nYOffset ); + g_pShaderAPI->SetIntRenderingParameter( INT_RENDERPARM_MORPH_ACCUMULATOR_SUBRECT_WIDTH, nWidth ); + g_pShaderAPI->SetIntRenderingParameter( INT_RENDERPARM_MORPH_ACCUMULATOR_SUBRECT_HEIGHT, nHeight ); +} + +void CMorph::BindMorphWeight( int nRenderId ) +{ + int nXOffset, nYOffset, nWidth, nHeight; + s_MorphMgr.ComputeWeightSubrect( &nXOffset, &nYOffset, &nWidth, &nHeight, nRenderId ); + + g_pShaderAPI->SetIntRenderingParameter( INT_RENDERPARM_MORPH_WEIGHT_X_OFFSET, nXOffset ); + g_pShaderAPI->SetIntRenderingParameter( INT_RENDERPARM_MORPH_WEIGHT_Y_OFFSET, nYOffset ); + g_pShaderAPI->SetIntRenderingParameter( INT_RENDERPARM_MORPH_WEIGHT_SUBRECT_WIDTH, nWidth ); + g_pShaderAPI->SetIntRenderingParameter( INT_RENDERPARM_MORPH_WEIGHT_SUBRECT_HEIGHT, nHeight ); +} + + +//----------------------------------------------------------------------------- +// Computes morph texture size in bytes +//----------------------------------------------------------------------------- +int CMorph::ComputeMorphTextureSizeInBytes( ) const +{ + int nSize = 0; + + if ( m_pMorphTexture[MORPH_TEXTURE_POS_NORMAL_DELTA] ) + { + int nTotal4Tuples = Get4TupleCount( m_Format ); + nSize += m_nTextureWidth * m_nTextureHeight * nTotal4Tuples * ImageLoader::SizeInBytes( IMAGE_FORMAT_RGBA16161616 ); + } + + if ( m_pMorphTexture[MORPH_TEXTURE_SPEED_SIDE_MAP] ) + { + nSize += m_nTextureWidth * m_nTextureHeight * ImageLoader::SizeInBytes( IMAGE_FORMAT_RGBA8888 ); + } + + // NOTE: Vertex size here is kind of a hack, but whatever. + int nVertexCount = CountStaticMeshVertices(); + nSize += nVertexCount * 5 * sizeof(float); + return nSize; +} + + +//----------------------------------------------------------------------------- +// Cleans up vertex textures +//----------------------------------------------------------------------------- +void CMorph::CleanUp( ) +{ + CMatRenderContextPtr pRenderContext( g_pMaterialSystem ); + + int nMorphTextureSize = ComputeMorphTextureSizeInBytes(); + s_MorphMgr.RegisterMorphSizeInBytes( -nMorphTextureSize ); + + IMaterial *pMat = m_MorphAccumulationMaterial; + m_MorphAccumulationMaterial.Shutdown(); + if ( pMat ) + { + pMat->DeleteIfUnreferenced(); + } + + if ( m_pMorphBuffer ) + { + pRenderContext->DestroyStaticMesh( m_pMorphBuffer ); + m_pMorphBuffer = NULL; + } + + for ( int i = 0; i < MORPH_TEXTURE_COUNT; ++i ) + { + if ( m_pMorphTexture[i] ) + { + m_pMorphTexture[i]->SetTextureRegenerator( NULL ); + m_pMorphTexture[i]->DecrementReferenceCount( ); + m_pMorphTexture[i]->DeleteIfUnreferenced(); + m_pMorphTexture[i] = NULL; + } + } + + if ( m_pRenderMorphWeight ) + { + delete[] m_pRenderMorphWeight; + m_pRenderMorphWeight = NULL; + } + + m_nMaxMorphTargetCount = 0; +} + + +//----------------------------------------------------------------------------- +// Is the morph locked? +//----------------------------------------------------------------------------- +bool CMorph::IsLocked() const +{ + return m_bLocked; +} + + +//----------------------------------------------------------------------------- +// Locks the morph data +//----------------------------------------------------------------------------- +void CMorph::Lock( float flFloatToFixedScale ) +{ + Assert( !IsLocked() ); + m_bLocked = true; + CleanUp(); + m_flFloatToFixedScale = flFloatToFixedScale; + m_MorphQuads.Purge(); + m_MorphTargetIdToQuadIndex.RemoveAll(); + m_MorphDict.Setup( ); +} + + +//----------------------------------------------------------------------------- +// Adds morph data to the morph dictionary +//----------------------------------------------------------------------------- +void CMorph::AddMorph( const MorphVertexInfo_t &info ) +{ + Assert( IsLocked() ); + m_MorphDict.AddMorph( info ); +} + + +//----------------------------------------------------------------------------- +// Unlocks the morph data, builds the vertex textures +//----------------------------------------------------------------------------- +void CMorph::Unlock( ) +{ + Assert( IsLocked() ); + + // Sort the deltas by destination vertex + m_MorphDict.SortDeltas(); + + // Now lay out morph data as if it were in a vertex texture + PackMorphData( ); + + // Free up temporary memory used in building + m_MorphDict.CleanUp(); + + m_bLocked = false; + + // Gather stats + int nMorphTextureSize = ComputeMorphTextureSizeInBytes(); + s_MorphMgr.RegisterMorphSizeInBytes( nMorphTextureSize ); +} + + +//----------------------------------------------------------------------------- +// Creates a material for use to do the morph accumulation +//----------------------------------------------------------------------------- +void CMorph::CreateAccumulatorMaterial( int nMaterialIndex ) +{ + // NOTE: Delta scale is a little tricky. The numbers are store in fixed-point 16 bit. + // The pixel shader will interpret 65536 as 1.0, and 0 as 0.0. In the pixel shader, + // we will read the delta, multiply it by 2, and subtract 1 to get a -1 to 1 range. + // The float to fixed scale is applied prior to writing it in (delta * scale + 32768). + // Therefore the max representable positive value = + // 65536 = max positive delta * scale + 32768 + // max positive delta = 32768 / scale + // This is what we will multiply our -1 to 1 values by in the pixel shader. + char pTemp[256]; + KeyValues *pVMTKeyValues = new KeyValues( "MorphAccumulate" ); + pVMTKeyValues->SetInt( "$nocull", 1 ); + pVMTKeyValues->SetFloat( "$deltascale", ( m_flFloatToFixedScale != 0.0f ) ? 32768.0f / m_flFloatToFixedScale : 1.0f ); + if ( m_pMorphTexture[MORPH_TEXTURE_POS_NORMAL_DELTA] ) + { + pVMTKeyValues->SetString( "$delta", m_pMorphTexture[MORPH_TEXTURE_POS_NORMAL_DELTA]->GetName() ); + } + if ( m_pMorphTexture[MORPH_TEXTURE_SPEED_SIDE_MAP] ) + { + pVMTKeyValues->SetString( "$sidespeed", m_pMorphTexture[MORPH_TEXTURE_SPEED_SIDE_MAP]->GetName() ); + } + Q_snprintf( pTemp, sizeof(pTemp), "[%d %d %d]", m_nTextureWidth, m_nTextureHeight, Get4TupleCount(m_Format) ); + pVMTKeyValues->SetString( "$dimensions", pTemp ); + + Q_snprintf( pTemp, sizeof(pTemp), "___AccumulateMorph%d.vmt", nMaterialIndex ); + m_MorphAccumulationMaterial.Init( pTemp, pVMTKeyValues ); +} + + + +//----------------------------------------------------------------------------- +// Computes the morph target field count +//----------------------------------------------------------------------------- +int CMorph::Get4TupleCount( MorphFormat_t format ) const +{ + int nSize = 0; + if ( format & ( MORPH_POSITION | MORPH_WRINKLE ) ) + { + ++nSize; + } + if ( format & MORPH_NORMAL ) + { + ++nSize; + } + return nSize; +} + + +//----------------------------------------------------------------------------- +// Determines the total number of deltas +//----------------------------------------------------------------------------- +int CMorph::DetermineTotalDeltaCount( const CUtlVector< MorphSegmentList_t > &morphSegments ) const +{ + int nDeltaCount = 0; + int nMorphCount = morphSegments.Count(); + for ( int i = 0; i < nMorphCount; ++i ) + { + const MorphSegmentList_t& list = morphSegments[i]; + int nSegmentCount = list.Count(); + for ( int j = 0; j < nSegmentCount; ++j ) + { + nDeltaCount += list[j].m_nCount; + } + } + return nDeltaCount; +} + + +//----------------------------------------------------------------------------- +// Computes the texture width +//----------------------------------------------------------------------------- +void CMorph::ComputeTextureDimensions( const CUtlVector< MorphSegmentList_t > &morphSegments ) +{ + int nTotalDeltas = DetermineTotalDeltaCount( morphSegments ); + m_nTextureHeight = ceil( sqrt( (float)nTotalDeltas ) ); + + // Round the dimension up to a multiple of 4 + m_nTextureHeight = ( m_nTextureHeight + 3 ) & ( ~0x3 ); + m_nTextureWidth = ( m_nTextureHeight != 0 ) ? ( nTotalDeltas + ( m_nTextureHeight - 1 ) ) / m_nTextureHeight : 0; + m_nTextureWidth = ( m_nTextureWidth + 3 ) & ( ~0x3 ); + + int nTotal4Tuples = Get4TupleCount( m_Format ); + + // Make sure it obeys bounds + int nMaxTextureWidth = HardwareConfig()->MaxTextureWidth(); + int nMaxTextureHeight = HardwareConfig()->MaxTextureHeight(); + while( m_nTextureWidth * nTotal4Tuples > nMaxTextureWidth ) + { + m_nTextureWidth >>= 1; + m_nTextureHeight <<= 1; + if ( m_nTextureHeight > nMaxTextureHeight ) + { + Warning( "Morph texture is too big!!! Make brian add support for morphs having multiple textures.\n" ); + Assert( 0 ); + m_nTextureHeight = nMaxTextureHeight; + break; + } + } +} + + +//----------------------------------------------------------------------------- +// Displays morph data statistics +//----------------------------------------------------------------------------- +void CMorph::DisplayMorphStats() +{ + ITexture *pDest = g_pMorphMgr->MorphAccumulator( ); + int nDestTextureHeight = pDest->GetActualHeight(); + +#ifdef _DEBUG + Msg( "Morph %s:\n", m_pDebugName.Get() ); +#else + Msg( "Morph :\n" ); +#endif + + int nMorphCount = m_MorphQuads.Count(); + Msg( "\tMorph Target Count : %d\n", nMorphCount ); + + int nTotalQuadCount = 0; + int nTotalVertexCount = 0; + CUtlVector quadHisto; + CUtlVector vertexHisto; + CUtlVector gapSizeHisto; + for ( int i = 0; i < nMorphCount; ++i ) + { + MorphQuadList_t &list = m_MorphQuads[i]; + int nQuadCount = list.Count(); + int nVertexCount = 0; + for ( int j = 0; j < nQuadCount; ++j ) + { + nVertexCount += list[j].m_nCount; + if ( j != 0 ) + { + // Filter out src gaps + wraparound gaps + if ( ( list[j].m_nFirstDest / nDestTextureHeight == list[j-1].m_nFirstDest / nDestTextureHeight ) && + ( list[j].m_nFirstSrc / m_nTextureHeight == list[j-1].m_nFirstSrc / m_nTextureHeight ) ) + { + int nGapSize = list[j].m_nFirstDest - ( list[j-1].m_nFirstDest + list[j-1].m_nCount ); + while ( nGapSize >= gapSizeHisto.Count() ) + { + gapSizeHisto.AddToTail( 0 ); + } + gapSizeHisto[nGapSize] += 1; + } + } + } + while ( nQuadCount >= quadHisto.Count() ) + { + quadHisto.AddToTail( 0 ); + } + while ( nVertexCount >= vertexHisto.Count() ) + { + vertexHisto.AddToTail( 0 ); + } + quadHisto[nQuadCount]+=1; + vertexHisto[nVertexCount]+=1; + nTotalQuadCount += nQuadCount; + nTotalVertexCount += nVertexCount; + } + + Msg( "\tAverage # of vertices per target: %d\n", nTotalVertexCount / nMorphCount ); + Msg( "\tAverage # of quad draws per target: %d\n", nTotalQuadCount / nMorphCount ); + + Msg( "\tQuad Count Histogram :\n\t\t" ); + for ( int i = 0; i < quadHisto.Count(); ++i ) + { + if ( quadHisto[i] == 0 ) + continue; + Msg( "[%d : %d] ", i, quadHisto[i] ); + } + Msg( "\n\tVertex Count Histogram :\n\t\t" ); + for ( int i = 0; i < vertexHisto.Count(); ++i ) + { + if ( vertexHisto[i] == 0 ) + continue; + Msg( "[%d : %d] ", i, vertexHisto[i] ); + } + Msg( "\n\tGap size Count Histogram :\n\t\t" ); + for ( int i = 0; i < gapSizeHisto.Count(); ++i ) + { + if ( gapSizeHisto[i] == 0 ) + continue; + Msg( "[%d : %d] ", i, gapSizeHisto[i] ); + } + Msg( "\n" ); +} + + +//----------------------------------------------------------------------------- +// Packs all morph data in the dictionary into a vertex texture layout +//----------------------------------------------------------------------------- +void CMorph::PackMorphData( ) +{ + CUtlVector< MorphSegmentList_t > morphSegments; + + BuildSegmentList( morphSegments ); + ComputeTextureDimensions( morphSegments ); + BuildQuadList( morphSegments ); + + if ( m_nTextureWidth == 0 || m_nTextureHeight == 0 ) + return; + + char pTemp[512]; + if ( m_Format & ( MORPH_POSITION | MORPH_WRINKLE | MORPH_NORMAL ) ) + { + Q_snprintf( pTemp, sizeof(pTemp), "__morphtarget[%d]: pos/norm", s_nUniqueId ); + + int nTotal4Tuples = Get4TupleCount( m_Format ); + ITexture *pTexture = g_pMaterialSystem->CreateProceduralTexture( pTemp, TEXTURE_GROUP_MORPH_TARGETS, + m_nTextureWidth * nTotal4Tuples, m_nTextureHeight, IMAGE_FORMAT_RGBA16161616, + TEXTUREFLAGS_NOMIP | TEXTUREFLAGS_NOLOD | TEXTUREFLAGS_NODEBUGOVERRIDE | + TEXTUREFLAGS_SINGLECOPY | TEXTUREFLAGS_CLAMPS | TEXTUREFLAGS_CLAMPT | TEXTUREFLAGS_POINTSAMPLE ); + m_pMorphTexture[MORPH_TEXTURE_POS_NORMAL_DELTA] = static_cast( pTexture ); + } + + if ( m_Format & ( MORPH_SIDE | MORPH_SPEED ) ) + { + Q_snprintf( pTemp, sizeof(pTemp), "__morphtarget[%d]: side/speed", s_nUniqueId ); + + ITexture *pTexture = g_pMaterialSystem->CreateProceduralTexture( pTemp, TEXTURE_GROUP_MORPH_TARGETS, + m_nTextureWidth, m_nTextureHeight, IMAGE_FORMAT_RGBA8888, + TEXTUREFLAGS_NOMIP | TEXTUREFLAGS_NOLOD | TEXTUREFLAGS_NODEBUGOVERRIDE | + TEXTUREFLAGS_SINGLECOPY | TEXTUREFLAGS_CLAMPS | TEXTUREFLAGS_CLAMPT | TEXTUREFLAGS_POINTSAMPLE ); + m_pMorphTexture[MORPH_TEXTURE_SPEED_SIDE_MAP] = static_cast( pTexture ); + } + + for ( int i = 0; i < MORPH_TEXTURE_COUNT; ++i ) + { + if ( m_pMorphTexture[i] ) + { + m_pMorphTexture[i]->SetTextureRegenerator( this ); + m_pMorphTexture[i]->Download(); + } + } + + CreateAccumulatorMaterial( s_nUniqueId ); + ++s_nUniqueId; + + CreateStaticMesh(); + +#ifdef REPORT_MORPH_STATS + DisplayMorphStats( ); +#endif +} + + +//----------------------------------------------------------------------------- +// Writes a morph delta into the texture +//----------------------------------------------------------------------------- +void CMorph::WriteDeltaPositionNormalToTexture( CPixelWriter &pixelWriter, int x, int y, const MorphVertexInfo_t &info ) +{ + // NOTE: 0 = -max range, 32767 = 0, 65534, 65535 = maxrange. + // This way we can encode +/- maxrange and 0 exactly + Assert ( m_Format & ( MORPH_POSITION | MORPH_WRINKLE | MORPH_NORMAL ) ); + + int n4TupleCount = Get4TupleCount( m_Format ); + pixelWriter.Seek( x*n4TupleCount, y ); + + // NOTE: int cast is where it is to force round-to-zero prior to offset + if ( m_Format & ( MORPH_POSITION | MORPH_WRINKLE ) ) + { + int r = 32767, g = 32767, b = 32767, a = 32767; + if ( m_Format & MORPH_POSITION ) + { + r = (int)( info.m_PositionDelta.x * m_flFloatToFixedScale ) + 32767; + g = (int)( info.m_PositionDelta.y * m_flFloatToFixedScale ) + 32767; + b = (int)( info.m_PositionDelta.z * m_flFloatToFixedScale ) + 32767; + r = clamp( r, 0, 65534 ); + g = clamp( g, 0, 65534 ); + b = clamp( b, 0, 65534 ); + } + if ( m_Format & MORPH_WRINKLE ) + { + a = (int)( info.m_flWrinkleDelta * m_flFloatToFixedScale ) + 32767; + a = clamp( a, 0, 65534 ); + } + pixelWriter.WritePixel( r, g, b, a ); + } + + if ( m_Format & MORPH_NORMAL ) + { + int r = 32767, g = 32767, b = 32767, a = 32767; + r = (int)( info.m_NormalDelta.x * m_flFloatToFixedScale ) + 32767; + g = (int)( info.m_NormalDelta.y * m_flFloatToFixedScale ) + 32767; + b = (int)( info.m_NormalDelta.z * m_flFloatToFixedScale ) + 32767; + r = clamp( r, 0, 65534 ); + g = clamp( g, 0, 65534 ); + b = clamp( b, 0, 65534 ); + + pixelWriter.WritePixel( r, g, b, a ); + } +} + +void CMorph::WriteSideSpeedToTexture( CPixelWriter &pixelWriter, int x, int y, const MorphVertexInfo_t &info ) +{ + Assert ( m_Format & ( MORPH_SPEED | MORPH_SIDE ) ); + + // Speed + size go from 0 to 1. + int r = 0, g = 0, b = 0, a = 0; + if ( m_Format & MORPH_SIDE ) + { + r = info.m_flSide * 255; + } + if ( m_Format & MORPH_SPEED ) + { + g = info.m_flSpeed * 255; + } + r = clamp( r, 0, 255 ); + g = clamp( g, 0, 255 ); + + pixelWriter.Seek( x, y ); + pixelWriter.WritePixel( r, g, b, a ); +} + + +//----------------------------------------------------------------------------- +// Builds the list of segments to render +//----------------------------------------------------------------------------- +void CMorph::BuildSegmentList( CUtlVector< MorphSegmentList_t > &morphSegments ) +{ + // Find the dimensions of the destination texture + int nDestTextureWidth, nDestTextureHeight; + s_MorphMgr.GetAccumulatorSubrectDimensions( &nDestTextureWidth, &nDestTextureHeight ); + + // Prepares the morph segments array + m_nMaxMorphTargetCount = 0; + int nMorphTargetCount = m_MorphDict.MorphCount(); + for ( int i = 0; i < nMorphTargetCount; ++i ) + { + if ( m_nMaxMorphTargetCount <= m_MorphDict.GetMorphTargetId(i) ) + { + m_nMaxMorphTargetCount = m_MorphDict.GetMorphTargetId(i) + 1; + } + } + + // Allocate space to cache off the morph weights when in the middle of performing morph accumulation + Assert( !m_pRenderMorphWeight ); + m_pRenderMorphWeight = new MorphWeight_t[ m_nMaxMorphTargetCount ]; + + Assert( m_nMaxMorphTargetCount < 1024 ); // This algorithm of storing a full array is bogus if this isn't true + m_MorphTargetIdToQuadIndex.SetCount( m_nMaxMorphTargetCount ); + memset( m_MorphTargetIdToQuadIndex.Base(), 0xFF, m_nMaxMorphTargetCount * sizeof(int) ); + + // Builds the segment list + int nSrcIndex = 0; + for ( int i = 0; i < nMorphTargetCount; ++i ) + { + int nMorphTargetId = m_MorphDict.GetMorphTargetId( i ); + m_MorphTargetIdToQuadIndex[nMorphTargetId] = i; + + int nSegmentIndex = morphSegments.AddToTail(); + MorphSegmentList_t &list = morphSegments[nSegmentIndex]; + Assert( nSegmentIndex == i ); + + MorphSegment_t segment; + segment.m_nCount = 0; + + int nVertexCount = m_MorphDict.GetMorphVertexCount( i ); + int nLastDestIndex = -1; + for ( int j = 0; j < nVertexCount; ++j ) + { + const MorphVertexInfo_t &info = m_MorphDict.GetMorphVertexInfo( i, j ); + + // Check for segment break conditions + if ( segment.m_nCount ) + { + // Vertical overflow, non-contiguous destination verts, or contiguous dest + // verts which happen to lie in different columns are the break conditions + if ( ( nLastDestIndex < 0 ) || ( info.m_nVertexId > nLastDestIndex + MIN_SEGMENT_GAP_SIZE ) || + ( info.m_nVertexId / nDestTextureHeight != nLastDestIndex / nDestTextureHeight ) ) + { + list.AddToTail( segment ); + nLastDestIndex = -1; + } + } + + // Start new segment, or append to existing segment + if ( nLastDestIndex < 0 ) + { + segment.m_nFirstSrc = nSrcIndex; + segment.m_nFirstDest = info.m_nVertexId; + segment.m_nCount = 1; + ++nSrcIndex; + } + else + { + int nSegmentCount = info.m_nVertexId - nLastDestIndex; + segment.m_nCount += nSegmentCount; + nSrcIndex += nSegmentCount; + } + nLastDestIndex = info.m_nVertexId; + } + + // Add any trailing segment + if ( segment.m_nCount ) + { + list.AddToTail( segment ); + } + } +} + + +//----------------------------------------------------------------------------- +// Builds the list of quads to render +//----------------------------------------------------------------------------- +void CMorph::BuildQuadList( const CUtlVector< MorphSegmentList_t > &morphSegments ) +{ + m_MorphQuads.RemoveAll(); + + int nQuadIndex = 0; + int nMorphCount = morphSegments.Count(); + for ( int i = 0; i < nMorphCount; ++i ) + { + int k = m_MorphQuads.AddToTail(); + MorphQuadList_t &quadList = m_MorphQuads[k]; + + const MorphSegmentList_t& segmentList = morphSegments[i]; + int nSegmentCount = segmentList.Count(); + for ( int j = 0; j < nSegmentCount; ++j ) + { + const MorphSegment_t &segment = segmentList[j]; + + int nSrc = segment.m_nFirstSrc; + int nDest = segment.m_nFirstDest; + int nTotalCount = segment.m_nCount; + + do + { + int sx = nSrc / m_nTextureHeight; + int sy = nSrc - sx * m_nTextureHeight; + + int nMaxCount = m_nTextureHeight - sy; + int nCount = min( nMaxCount, nTotalCount ); + nTotalCount -= nCount; + + int l = quadList.AddToTail(); + MorphQuad_t &quad = quadList[l]; + quad.m_nQuadIndex = nQuadIndex++; + quad.m_nCount = nCount; + quad.m_nFirstSrc = nSrc; + quad.m_nFirstDest = nDest; + + nSrc += nCount; + nDest += nCount; + } while ( nTotalCount > 0 ); + } + } +} + + +//----------------------------------------------------------------------------- +// Counts the total number of vertices to place in the static mesh +//----------------------------------------------------------------------------- +int CMorph::CountStaticMeshVertices() const +{ + // FIXME: I'm doing the simple thing here of 4 verts per segment. + // I believe I should be able to share any edge that isn't on the edges of the texture + // so I should be able to get down to nearly 2 (or is it 1?) verts per segment. + int nVertexCount = 0; + int nMorphCount = m_MorphQuads.Count(); + for ( int i = 0; i < nMorphCount; ++i ) + { + const MorphQuadList_t& quadList = m_MorphQuads[i]; + nVertexCount += quadList.Count() * 4; + } + + return nVertexCount; +} + +//----------------------------------------------------------------------------- +// Determines mesh vertex format +//----------------------------------------------------------------------------- +VertexFormat_t CMorph::ComputeVertexFormat( IMaterial * pMaterial ) const +{ + // We believe this material's vertex format is reliable (unlike many others as of June 07) + VertexFormat_t vertexFormat = pMaterial->GetVertexFormat(); + + // UNDONE: optimize the vertex format to compress or remove elements where possible + vertexFormat &= ~VERTEX_FORMAT_COMPRESSED; + + return vertexFormat; +} + +//----------------------------------------------------------------------------- +// Builds the list of segments to render +//----------------------------------------------------------------------------- +void CMorph::CreateStaticMesh() +{ + CMatRenderContextPtr pRenderContext( g_pMaterialSystem ); + m_MorphAccumulationMaterial->Refresh(); + VertexFormat_t vertexFormat = ComputeVertexFormat( m_MorphAccumulationMaterial ); + m_pMorphBuffer = pRenderContext->CreateStaticMesh( vertexFormat, TEXTURE_GROUP_MORPH_TARGETS, m_MorphAccumulationMaterial ); + + int nVertexCount = CountStaticMeshVertices(); + if ( nVertexCount >= 65535 ) + { + Warning( "Too many morph vertices! Call brian\n" ); + } + Assert( nVertexCount < 65535 ); + + int n4TupleCount = Get4TupleCount( m_Format ); + + float flOOTexWidth = 1.0f / ( n4TupleCount * m_nTextureWidth ); + float flOOTexHeight = 1.0f / m_nTextureHeight; + + int nDestTextureWidth, nDestTextureHeight; + s_MorphMgr.GetAccumulatorSubrectDimensions( &nDestTextureWidth, &nDestTextureHeight ); + float flOODestWidth = 1.0f / nDestTextureWidth; + float flOODestHeight = 1.0f / nDestTextureHeight; + + // NOTE: zero index count implies no index buffer + CMeshBuilder meshBuilder; + meshBuilder.Begin( m_pMorphBuffer, MATERIAL_TRIANGLES, nVertexCount, 0 ); + + int nMorphCount = m_MorphQuads.Count(); + for ( int i = 0; i < nMorphCount; ++i ) + { + MorphQuadList_t& quadList = m_MorphQuads[i]; + int nQuadCount = quadList.Count(); + for ( int j = 0; j < nQuadCount; ++j ) + { + MorphQuad_t &quad = quadList[j]; + + int sx = quad.m_nFirstSrc / m_nTextureHeight; + int sy = quad.m_nFirstSrc - sx * m_nTextureHeight; + int dx = quad.m_nFirstDest / nDestTextureHeight; + int dy = quad.m_nFirstDest - dx * nDestTextureHeight; + sx *= n4TupleCount; dx *= n4TupleCount; + + meshBuilder.TexCoord4f( 0, sx * flOOTexWidth, sy * flOOTexHeight, + ( dx - 0.5f ) * flOODestWidth, ( dy - 0.5f ) * flOODestHeight ); // Stores the source to read from + meshBuilder.TexCoord1f( 1, i ); + meshBuilder.AdvanceVertex(); + + meshBuilder.TexCoord4f( 0, sx * flOOTexWidth, ( sy + quad.m_nCount ) * flOOTexHeight, + ( dx - 0.5f ) * flOODestWidth, ( dy + quad.m_nCount - 0.5f ) * flOODestHeight ); // Stores the source to read from + meshBuilder.TexCoord1f( 1, i ); + meshBuilder.AdvanceVertex(); + + meshBuilder.TexCoord4f( 0, (sx + n4TupleCount) * flOOTexWidth, ( sy + quad.m_nCount ) * flOOTexHeight, + ( dx + n4TupleCount - 0.5f ) * flOODestWidth, ( dy + quad.m_nCount - 0.5f ) * flOODestHeight ); // Stores the source to read from + meshBuilder.TexCoord1f( 1, i ); + meshBuilder.AdvanceVertex(); + + meshBuilder.TexCoord4f( 0, (sx + n4TupleCount) * flOOTexWidth, sy * flOOTexHeight, + ( dx + n4TupleCount - 0.5f ) * flOODestWidth, ( dy - 0.5f ) * flOODestHeight ); // Stores the source to read from + meshBuilder.TexCoord1f( 1, i ); + meshBuilder.AdvanceVertex(); + } + } + + meshBuilder.End(); +} + + +//----------------------------------------------------------------------------- +// Inherited from ITextureRegenerator +//----------------------------------------------------------------------------- +void CMorph::RegenerateTextureBits( ITexture *pTexture, IVTFTexture *pVTFTexture, Rect_t *pRect ) +{ + Assert( pVTFTexture->FrameCount() == 1 && pVTFTexture->FaceCount() == 1 ); + Assert( pVTFTexture->Height() == m_nTextureHeight ); + + int nTextureType; + for ( nTextureType = 0; nTextureType < MORPH_TEXTURE_COUNT; ++nTextureType ) + { + if ( pTexture == m_pMorphTexture[nTextureType] ) + break; + } + Assert( nTextureType < MORPH_TEXTURE_COUNT ); + MorphPixelWriter_t pWriteFuncs[MORPH_TEXTURE_COUNT] = + { + &CMorph::WriteDeltaPositionNormalToTexture, + &CMorph::WriteSideSpeedToTexture, + }; + + MorphPixelWriter_t writeFunc = pWriteFuncs[nTextureType]; + + CPixelWriter pixelWriter; + pixelWriter.SetPixelMemory( pVTFTexture->Format(), pVTFTexture->ImageData(), pVTFTexture->RowSizeInBytes( 0 ) ); + + // Clear the buffer + MorphVertexInfo_t zeroDelta; + zeroDelta.m_PositionDelta.Init(); + zeroDelta.m_NormalDelta.Init(); + zeroDelta.m_flWrinkleDelta = 0.0f; + zeroDelta.m_flSpeed = 1.0f; + zeroDelta.m_flSide = 0.5f; + + int nWidth = pVTFTexture->Width() / Get4TupleCount( m_Format ); + int nHeight = pVTFTexture->Height(); + for ( int i = 0; i < nHeight; ++i ) + { + for ( int j = 0; j < nWidth; ++j ) + { + (this->*writeFunc)( pixelWriter, j, i, zeroDelta ); + } + } + + int nQuadListCount = m_MorphQuads.Count(); + for ( int i = 0; i < nQuadListCount; ++i ) + { + MorphQuadList_t &quadList = m_MorphQuads[i]; + int nQuadCount = quadList.Count(); + int nVertIndex = 0; + for ( int j = 0; j < nQuadCount; ++j ) + { + MorphQuad_t &quad = quadList[j]; + int sx = quad.m_nFirstSrc / m_nTextureHeight; + int sy = quad.m_nFirstSrc - sx * m_nTextureHeight; + int nDest = quad.m_nFirstDest; + for ( int k = 0; k < quad.m_nCount; ++k ) + { + const MorphVertexInfo_t &info = m_MorphDict.GetMorphVertexInfo( i, nVertIndex ); + if ( info.m_nVertexId > nDest ) + { + (this->*writeFunc)( pixelWriter, sx, sy+k, zeroDelta ); + } + else + { + (this->*writeFunc)( pixelWriter, sx, sy+k, info ); + ++nVertIndex; + } + ++nDest; + } + } + } +} + + +//----------------------------------------------------------------------------- +// Deals with morph stats +//----------------------------------------------------------------------------- +static ConVar mat_morphstats( "mat_morphstats", "0", FCVAR_CHEAT ); +static CUtlVector s_ActiveMorphHisto; +static CUtlVector s_RenderedQuadHisto; +static CUtlVector s_RenderedTexelHisto; +static int s_nStatFrameCount = 0; +static int s_nStatMorphCount = 0; +static int s_nTotalMorphCount = 0; +static int s_nTotalQuadCount = 0; +static int s_nTotalTexelCount = 0; + +void CMorph::ClearMorphStats() +{ + s_ActiveMorphHisto.Purge(); + s_RenderedQuadHisto.Purge(); + s_RenderedTexelHisto.Purge(); + + s_nStatFrameCount = 0; + s_nTotalMorphCount = 0; + s_nTotalQuadCount = 0; + s_nTotalTexelCount = 0; +} + +void CMorph::AccumulateMorphStats( int nActiveMorphCount, int nQuadsRendered, int nTexelsRendered ) +{ + while ( nActiveMorphCount >= s_ActiveMorphHisto.Count() ) + { + s_ActiveMorphHisto.AddToTail( 0 ); + } + while ( nQuadsRendered >= s_RenderedQuadHisto.Count() ) + { + s_RenderedQuadHisto.AddToTail( 0 ); + } + while ( nTexelsRendered >= s_RenderedTexelHisto.Count() ) + { + s_RenderedTexelHisto.AddToTail( 0 ); + } + s_ActiveMorphHisto[nActiveMorphCount] += 1; + s_RenderedQuadHisto[nQuadsRendered] += 1; + s_RenderedTexelHisto[nTexelsRendered] += 1; + + s_nStatMorphCount++; + s_nTotalMorphCount += nActiveMorphCount; + s_nTotalQuadCount += nQuadsRendered; + s_nTotalTexelCount += nTexelsRendered; +} + +void CMorph::ReportMorphStats( ) +{ + Msg( "Morph stats:\n" ); + if ( s_nStatMorphCount == 0 ) + { + Msg( "\tNo morphing done\n" ); + return; + } + + Msg( "\tAverage # of active morph targets per mesh group: %d\n", s_nTotalMorphCount / s_nStatMorphCount ); + Msg( "\tAverage # of actual quad draws per morph: %d\n", s_nTotalQuadCount / s_nStatMorphCount ); + Msg( "\tAverage # of actual rendered texels per morph: %d\n", s_nTotalTexelCount / s_nStatMorphCount ); + + Msg( "\tRendered Quad Count Histogram :\n\t\t" ); + for ( int i = 0; i < s_RenderedQuadHisto.Count(); ++i ) + { + if ( s_RenderedQuadHisto[i] == 0 ) + continue; + Msg( "[%d : %d] ", i, s_RenderedQuadHisto[i] ); + } + Msg( "\n\tRendered Texel Count Histogram :\n\t\t" ); + for ( int i = 0; i < s_RenderedTexelHisto.Count(); ++i ) + { + if ( s_RenderedTexelHisto[i] == 0 ) + continue; + Msg( "[%d : %d] ", i, s_RenderedTexelHisto[i] ); + } + Msg( "\n\tActive morph target Count Histogram :\n\t\t" ); + for ( int i = 0; i < s_ActiveMorphHisto.Count(); ++i ) + { + if ( s_ActiveMorphHisto[i] == 0 ) + continue; + Msg( "[%d : %d] ", i, s_ActiveMorphHisto[i] ); + } + Msg( "\n" ); +} + +void CMorph::HandleMorphStats( int nActiveMorphCount, int nQuadsRendered, int nTexelsRendered ) +{ + static bool s_bLastMorphStats = false; + bool bDoStats = mat_morphstats.GetInt() != 0; + if ( bDoStats ) + { + if ( !s_bLastMorphStats ) + { + ClearMorphStats(); + } + AccumulateMorphStats( nActiveMorphCount, nQuadsRendered, nTexelsRendered ); + } + else + { + if ( s_bLastMorphStats ) + { + ReportMorphStats(); + ClearMorphStats(); + } + } + + s_bLastMorphStats = bDoStats; +} + + +//----------------------------------------------------------------------------- +// Renders to the morph accumulator texture +//----------------------------------------------------------------------------- +void CMorph::RenderMorphQuads( IMatRenderContext *pRenderContext, int nRenderId, int nTotalQuadCount, int nWeightCount, int *pWeightLookup, const MorphWeight_t* pWeights ) +{ + if ( s_MorphMgr.IsUsingConstantRegisters() ) + { + pRenderContext->SetFlexWeights( 0, m_nMaxMorphTargetCount, m_pRenderMorphWeight ); + } + else + { + BindMorphWeight( nRenderId ); + } + + int nXOffset, nYOffset, nWidth, nHeight; + s_MorphMgr.ComputeAccumulatorSubrect( &nXOffset, &nYOffset, &nWidth, &nHeight, nRenderId ); + pRenderContext->Viewport( nXOffset, nYOffset, nWidth, nHeight ); + + CMeshBuilder meshBuilder; + IMesh *pMesh = pRenderContext->GetDynamicMesh( false, m_pMorphBuffer ); + meshBuilder.Begin( pMesh, MATERIAL_TRIANGLES, 0, nTotalQuadCount * 6 ); + +#ifdef REPORT_MORPH_STATS + int nTexelsRendered = 0; +#endif + + for ( int i = 0; i < nWeightCount; ++i ) + { + int nMorphIndex = m_MorphTargetIdToQuadIndex[ pWeightLookup[i] ]; + if ( nMorphIndex < 0 ) + continue; + + const MorphQuadList_t& quadList = m_MorphQuads[nMorphIndex]; + int nQuadCount = quadList.Count(); + for ( int j = 0; j < nQuadCount; ++j ) + { + const MorphQuad_t &quad = quadList[j]; + +#ifdef _DEBUG + static int s_nMinDest = -1, s_nMaxDest = -1; + if ( s_nMinDest >= 0 && quad.m_nFirstDest + quad.m_nCount <= s_nMinDest ) + continue; + if ( s_nMaxDest >= 0 && quad.m_nFirstDest > s_nMaxDest ) + continue; +#endif + +#ifdef REPORT_MORPH_STATS + nTexelsRendered += n4TupleCount * quad.m_nCount; +#endif + + int nBaseIndex = quad.m_nQuadIndex * 4; + meshBuilder.FastIndex( nBaseIndex ); + meshBuilder.FastIndex( nBaseIndex+1 ); + meshBuilder.FastIndex( nBaseIndex+2 ); + + meshBuilder.FastIndex( nBaseIndex ); + meshBuilder.FastIndex( nBaseIndex+2 ); + meshBuilder.FastIndex( nBaseIndex+3 ); + } + } + meshBuilder.End(); + pMesh->Draw(); + +#ifdef REPORT_MORPH_STATS + HandleMorphStats( nWeightCount, nTotalQuadCount, nTexelsRendered ); +#endif +} + + +//----------------------------------------------------------------------------- +// Should a morph weight be treated as zero +//----------------------------------------------------------------------------- +static inline bool IsMorphWeightZero( const MorphWeight_t &weight ) +{ + return ( FloatMakePositive( weight.m_pWeight[MORPH_WEIGHT] ) < 0.001 && + FloatMakePositive( weight.m_pWeight[MORPH_WEIGHT_LAGGED] ) < 0.001 && + FloatMakePositive( weight.m_pWeight[MORPH_WEIGHT_STEREO] ) < 0.001 && + FloatMakePositive( weight.m_pWeight[MORPH_WEIGHT_STEREO_LAGGED] ) < 0.001 ); +} + + +//----------------------------------------------------------------------------- +// Builds a list of non-zero morph targets +//----------------------------------------------------------------------------- +int CMorph::BuildNonZeroMorphList( int *pWeightIndices, int nWeightCount, const MorphWeight_t* pWeights ) +{ + int nWeightIndexCount = 0; + for ( int i = 0; i < m_nMaxMorphTargetCount; ++i ) + { + const MorphWeight_t& weight = pWeights[i]; + + // Don't bother with weights that aren't represented in the morph + if ( m_MorphTargetIdToQuadIndex[i] < 0 ) + continue; + + // Don't bother with small weights + if ( IsMorphWeightZero( weight ) ) + continue; + + pWeightIndices[nWeightIndexCount++] = i; + } + + return nWeightIndexCount; +} + + +//----------------------------------------------------------------------------- +// Renders to the morph weight texture +//----------------------------------------------------------------------------- +bool CMorph::RenderMorphWeights( IMatRenderContext *pRenderContext, int nRenderId, int nWeightCount, const MorphWeight_t* pWeights ) +{ + VPROF_BUDGET( "CMorph::RenderMorphWeights", _T("HW Morphing") ); + if ( m_nMaxMorphTargetCount == 0 ) + return false; + + // Cache off the weights, we need them when we accumulate the morphs later. + int nCountToCopy = min( nWeightCount, m_nMaxMorphTargetCount ); + memcpy( m_pRenderMorphWeight, pWeights, nCountToCopy * sizeof(MorphWeight_t) ); + int nCountToClear = m_nMaxMorphTargetCount - nWeightCount; + if ( nCountToClear > 0 ) + { + memset( &m_pRenderMorphWeight[nCountToCopy], 0, nCountToClear * sizeof(MorphWeight_t) ); + } + + int *pWeightIndices = (int*)_alloca( nCountToCopy * sizeof(int) ); + int nIndexCount = BuildNonZeroMorphList( pWeightIndices, nCountToCopy, pWeights ); + if ( nIndexCount == 0 ) + return false; + + if ( s_MorphMgr.IsUsingConstantRegisters() ) + return true; + + int x, y, w, h; + s_MorphMgr.ComputeWeightSubrect( &x, &y, &w, &h, nRenderId ); + + ITexture *pMorphWeightTexture = s_MorphMgr.MorphWeights(); + int nWidth = pMorphWeightTexture->GetActualWidth(); + int nHeight = pMorphWeightTexture->GetActualHeight(); + float flOOWidth = ( nWidth != 0 ) ? 1.0f / nWidth : 1.0f; + float flOOHeight = ( nHeight != 0 ) ? 1.0f / nHeight : 1.0f; + + // Render the weights into the morph weight texture + CMeshBuilder meshBuilder; + IMesh *pMesh = pRenderContext->GetDynamicMesh( ); + meshBuilder.Begin( pMesh, MATERIAL_POINTS, nCountToCopy ); + + for ( int i = 0; i < nIndexCount; ++i ) + { + int nMorphId = pWeightIndices[i]; + const MorphWeight_t& weight = pWeights[ nMorphId ]; + + int nLocalX = nMorphId / h; + int nLocalY = nMorphId - nLocalX * h; + meshBuilder.TexCoord2f( 0, ( nLocalX + x ) * flOOWidth, ( nLocalY + y ) * flOOHeight ); + meshBuilder.TexCoord4fv( 1, weight.m_pWeight ); + meshBuilder.AdvanceVertex(); + } + + meshBuilder.End(); + pMesh->Draw(); + + return true; +} + + +//----------------------------------------------------------------------------- +// This will generate an accumulated morph target based on the passed-in weights +//----------------------------------------------------------------------------- +void CMorph::AccumulateMorph( int nRenderId ) +{ + VPROF_BUDGET( "CMorph::AccumulateMorph", _T("HW Morphing") ); + + // Build a non-zero weight list and a total quad count + int *pTargets = (int*)_alloca( m_nMaxMorphTargetCount * sizeof(int) ); + int nTargetCount = BuildNonZeroMorphList( pTargets, m_nMaxMorphTargetCount, m_pRenderMorphWeight ); + + // Count the total number of quads to draw + int nTotalQuadCount = 0; + for ( int i = 0; i < nTargetCount; ++i ) + { + int nMorphIndex = m_MorphTargetIdToQuadIndex[ pTargets[i] ]; + if ( nMorphIndex < 0 ) + continue; + + const MorphQuadList_t& quadList = m_MorphQuads[ nMorphIndex ]; + nTotalQuadCount += quadList.Count(); + } + + // Clear the morph accumulator + // FIXME: Can I avoid even changing the render target if I know the last time + // the morph accumulator was used that it was also cleared to black? Yes, but + // I need to deal with alt-tab. + bool bRenderQuads = ( nTotalQuadCount != 0 ) && ( m_nTextureWidth != 0 ) && ( m_nTextureHeight != 0 ); + if ( !bRenderQuads ) + return; + + // Next, iterate over all non-zero morphs and add them in. + CMatRenderContextPtr pRenderContext( g_pMaterialSystem ); + pRenderContext->Bind( m_MorphAccumulationMaterial ); + RenderMorphQuads( pRenderContext, nRenderId, nTotalQuadCount, nTargetCount, pTargets, m_pRenderMorphWeight ); +} + + +//----------------------------------------------------------------------------- +// +// Morph mgr render context +// +//----------------------------------------------------------------------------- +CMorphMgrRenderContext::CMorphMgrRenderContext() +{ + m_nMorphCount = 0; + +#ifdef DBGFLAG_ASSERT + m_bInMorphAccumulation = false; +#endif +} + +int CMorphMgrRenderContext::GetRenderId( CMorph* pMorph ) +{ + // FIXME: This could be done without all these comparisons, at the cost of memory + complexity. + // NOTE: m_nMorphCount <= 4. + for ( int i = 0; i < m_nMorphCount; ++i ) + { + if ( m_pMorphsToAccumulate[i] == pMorph ) + return i; + } + return -1; +} + + +//----------------------------------------------------------------------------- +// +// Morph manager implementation starts here +// +//----------------------------------------------------------------------------- + + +//----------------------------------------------------------------------------- +// Constructor +//----------------------------------------------------------------------------- +CMorphMgr::CMorphMgr() +{ + m_pMorphAccumTexture = NULL; + m_pMorphWeightTexture = NULL; + m_pVisualizeMorphAccum = NULL; + m_pVisualizeMorphWeight = NULL; + m_pRenderMorphWeight = NULL; + m_nFrameCount = 0; + m_nTotalMorphSizeInBytes = 0; + m_bUsingConstantRegisters = false; +} + + +//----------------------------------------------------------------------------- +// Should we allocate textures? +//----------------------------------------------------------------------------- +bool CMorphMgr::ShouldAllocateScratchTextures() +{ + return g_pMaterialSystemHardwareConfig->HasFastVertexTextures(); +} + + +//----------------------------------------------------------------------------- +// Allocates scratch textures used in hw morphing +//----------------------------------------------------------------------------- +void CMorphMgr::AllocateScratchTextures() +{ + // Debug using 32323232F because we can read that back reasonably. +#ifdef _DEBUG + ImageFormat fmt = IMAGE_FORMAT_RGBA32323232F; +#else + ImageFormat fmt = IMAGE_FORMAT_RGBA16161616F; +#endif + + // NOTE: I'm not writing code to compute an appropriate width and height + // given a MAX_MORPH_ACCUMULATOR_VERTICES and MORPH_ACCUMULATOR_4TUPLES + // because this will rarely change. Just hard code it to something that will fit it. + m_nAccumulatorWidth = 256; + m_nAccumulatorHeight = 256; + Assert( m_nAccumulatorWidth * m_nAccumulatorHeight == MAX_MORPH_ACCUMULATOR_VERTICES * MORPH_ACCUMULATOR_4TUPLES ); + + Assert( IsPowerOfTwo( CMorphMgrRenderContext::MAX_MODEL_MORPHS ) ); + int nMultFactor = sqrt( (float)CMorphMgrRenderContext::MAX_MODEL_MORPHS ); + m_nSubrectVerticalCount = nMultFactor; + + m_pMorphAccumTexture = TextureManager()->CreateRenderTargetTexture( "_rt_MorphAccumulator", + m_nAccumulatorWidth * nMultFactor, m_nAccumulatorHeight * nMultFactor, + RT_SIZE_OFFSCREEN, fmt, RENDER_TARGET_NO_DEPTH, + TEXTUREFLAGS_NOMIP | TEXTUREFLAGS_NOLOD | TEXTUREFLAGS_NODEBUGOVERRIDE | + TEXTUREFLAGS_CLAMPS | TEXTUREFLAGS_CLAMPT | TEXTUREFLAGS_POINTSAMPLE | TEXTUREFLAGS_VERTEXTEXTURE, + 0 ); + m_pMorphAccumTexture->IncrementReferenceCount(); + + int nDim = (int)sqrt( (float)MAXSTUDIOFLEXDESC ); + while( nDim * nDim < MAXSTUDIOFLEXDESC ) + { + ++nDim; + } + + m_nWeightWidth = m_nWeightHeight = nDim; + + // FIXME: Re-enable if NVidia gets a fast implementation using more shader constants + m_bUsingConstantRegisters = false; //( g_pMaterialSystemHardwareConfig->NumVertexShaderConstants() >= VERTEX_SHADER_FLEX_WEIGHTS + VERTEX_SHADER_MAX_FLEX_WEIGHT_COUNT ); + + if ( !m_bUsingConstantRegisters ) + { + m_pMorphWeightTexture = TextureManager()->CreateRenderTargetTexture( "_rt_MorphWeight", + m_nWeightWidth * nMultFactor, m_nWeightHeight * nMultFactor, + RT_SIZE_OFFSCREEN, fmt, RENDER_TARGET_NO_DEPTH, + TEXTUREFLAGS_NOMIP | TEXTUREFLAGS_NOLOD | TEXTUREFLAGS_NODEBUGOVERRIDE | + TEXTUREFLAGS_CLAMPS | TEXTUREFLAGS_CLAMPT | TEXTUREFLAGS_POINTSAMPLE, + 0 ); + m_pMorphWeightTexture->IncrementReferenceCount(); + } +} + +void CMorphMgr::FreeScratchTextures() +{ + if ( m_pMorphAccumTexture ) + { + m_pMorphAccumTexture->DecrementReferenceCount(); + m_pMorphAccumTexture->DeleteIfUnreferenced(); + m_pMorphAccumTexture = NULL; + } + + if ( m_pMorphWeightTexture ) + { + m_pMorphWeightTexture->DecrementReferenceCount(); + m_pMorphWeightTexture->DeleteIfUnreferenced(); + m_pMorphWeightTexture = NULL; + } +} + + +//----------------------------------------------------------------------------- +// Allocates, frees materials used in hw morphing +//----------------------------------------------------------------------------- +void CMorphMgr::AllocateMaterials() +{ + KeyValues *pVMTKeyValues = new KeyValues( "debugmorphaccumulator" ); + pVMTKeyValues->SetString( "$basetexture", "_rt_MorphAccumulator" ); + pVMTKeyValues->SetString( "$nocull", "1" ); + pVMTKeyValues->SetString( "$ignorez", "1" ); + m_pVisualizeMorphAccum = g_pMaterialSystem->CreateMaterial( "___visualizeMorphAccum.vmt", pVMTKeyValues ); + + if ( !m_bUsingConstantRegisters ) + { + pVMTKeyValues = new KeyValues( "morphweight" ); + pVMTKeyValues->SetString( "$model", "0" ); + pVMTKeyValues->SetString( "$nocull", "1" ); + pVMTKeyValues->SetString( "$ignorez", "1" ); + m_pRenderMorphWeight = g_pMaterialSystem->CreateMaterial( "___morphweight.vmt", pVMTKeyValues ); + + pVMTKeyValues = new KeyValues( "debugmorphaccumulator" ); + pVMTKeyValues->SetString( "$basetexture", "_rt_MorphWeight" ); + pVMTKeyValues->SetString( "$nocull", "1" ); + pVMTKeyValues->SetString( "$ignorez", "1" ); + m_pVisualizeMorphWeight = g_pMaterialSystem->CreateMaterial( "___visualizeMorphWeight.vmt", pVMTKeyValues ); + } +} + + +void CMorphMgr::FreeMaterials() +{ + if ( m_pVisualizeMorphAccum ) + { + m_pVisualizeMorphAccum->DecrementReferenceCount(); + m_pVisualizeMorphAccum->DeleteIfUnreferenced(); + m_pVisualizeMorphAccum = NULL; + } + + if ( m_pVisualizeMorphWeight ) + { + m_pVisualizeMorphWeight->DecrementReferenceCount(); + m_pVisualizeMorphWeight->DeleteIfUnreferenced(); + m_pVisualizeMorphWeight = NULL; + } + + if ( m_pRenderMorphWeight ) + { + m_pRenderMorphWeight->DecrementReferenceCount(); + m_pRenderMorphWeight->DeleteIfUnreferenced(); + m_pRenderMorphWeight = NULL; + } +} + + +//----------------------------------------------------------------------------- +// Morph render context +//----------------------------------------------------------------------------- +IMorphMgrRenderContext *CMorphMgr::AllocateRenderContext() +{ + return new CMorphMgrRenderContext; +} + +void CMorphMgr::FreeRenderContext( IMorphMgrRenderContext *pRenderContext ) +{ + delete static_cast< CMorphMgrRenderContext* >( pRenderContext ); +} + + +//----------------------------------------------------------------------------- +// Returns the morph accumulation texture +//----------------------------------------------------------------------------- +ITextureInternal *CMorphMgr::MorphAccumulator() +{ + return m_pMorphAccumTexture; +} + +ITextureInternal *CMorphMgr::MorphWeights() +{ + return m_pMorphWeightTexture; +} + + +//----------------------------------------------------------------------------- +// Class factory +//----------------------------------------------------------------------------- +IMorphInternal *CMorphMgr::CreateMorph() +{ + return new CMorph; +} + +void CMorphMgr::DestroyMorph( IMorphInternal *pMorphData ) +{ + if ( pMorphData ) + { + delete static_cast< CMorph*>( pMorphData ); + } +} + + +//----------------------------------------------------------------------------- +// Advances the frame (for debugging) +//----------------------------------------------------------------------------- +void CMorphMgr::AdvanceFrame() +{ + ++m_nFrameCount; +} + + +//----------------------------------------------------------------------------- +// Computes texel offsets for the upper corner of the morph weight texture for a particular block +//----------------------------------------------------------------------------- +void CMorphMgr::ComputeWeightSubrect( int *pXOffset, int *pYOffset, int *pWidth, int *pHeight, int nMorphAccumBlockId ) +{ + *pXOffset = nMorphAccumBlockId / m_nSubrectVerticalCount; + *pYOffset = nMorphAccumBlockId - m_nSubrectVerticalCount * (*pXOffset); + *pXOffset *= m_nWeightWidth; + *pYOffset *= m_nWeightHeight; + *pWidth = m_nWeightWidth; + *pHeight = m_nWeightHeight; +} + + +//----------------------------------------------------------------------------- +// Computes texel offsets for the upper corner of the morph accumulator for a particular block +//----------------------------------------------------------------------------- +void CMorphMgr::ComputeAccumulatorSubrect( int *pXOffset, int *pYOffset, int *pWidth, int *pHeight, int nMorphAccumBlockId ) +{ + *pXOffset = nMorphAccumBlockId / m_nSubrectVerticalCount; + *pYOffset = nMorphAccumBlockId - m_nSubrectVerticalCount * (*pXOffset); + *pXOffset *= m_nAccumulatorWidth; + *pYOffset *= m_nAccumulatorHeight; + *pWidth = m_nAccumulatorWidth; + *pHeight = m_nAccumulatorHeight; +} + +void CMorphMgr::GetAccumulatorSubrectDimensions( int *pWidth, int *pHeight ) +{ + *pWidth = m_nAccumulatorWidth; + *pHeight = m_nAccumulatorHeight; +} + +int CMorphMgr::GetAccumulator4TupleCount() const +{ + return MORPH_ACCUMULATOR_4TUPLES; +} + + +//----------------------------------------------------------------------------- +// Used to compute stats of memory used +//----------------------------------------------------------------------------- +CON_COMMAND_F( mat_reporthwmorphmemory, "Reports the amount of size in bytes taken up by hardware morph textures.", FCVAR_CHEAT ) +{ + ConMsg( "Total HW Morph memory used: %dk\n", s_MorphMgr.GetTotalMemoryUsage() /1024 ); +} + +void CMorphMgr::RegisterMorphSizeInBytes( int nSizeInBytes ) +{ + m_nTotalMorphSizeInBytes += nSizeInBytes; + Assert( m_nTotalMorphSizeInBytes >= 0 ); +} + +int CMorphMgr::GetTotalMemoryUsage() const +{ + int nSize = 0; + if ( m_pMorphAccumTexture ) + { + nSize += m_pMorphAccumTexture->GetActualWidth() * m_pMorphAccumTexture->GetActualHeight() * + ImageLoader::SizeInBytes( m_pMorphAccumTexture->GetImageFormat() ); + } + if ( m_pMorphWeightTexture ) + { + nSize += m_pMorphWeightTexture->GetActualWidth() * m_pMorphWeightTexture->GetActualHeight() * + ImageLoader::SizeInBytes( m_pMorphWeightTexture->GetImageFormat() ); + } + nSize += m_nTotalMorphSizeInBytes; + return nSize; +} + + +//----------------------------------------------------------------------------- +// Displays 32bit float texture data +//----------------------------------------------------------------------------- +void CMorphMgr::Display32FTextureData( float *pBuf, int nTexelID, int *pSubRect, ITexture *pTexture, int n4TupleCount ) +{ + int nColumn = nTexelID / pSubRect[3]; + int nRow = nTexelID - nColumn * pSubRect[3]; + nColumn *= n4TupleCount; + nColumn += pSubRect[0]; + nRow += pSubRect[1]; + + Msg( "[%d] : ", nTexelID ); + for ( int i = 0; i < n4TupleCount; ++i ) + { + float *pBase = &pBuf[ (nRow * pTexture->GetActualWidth() + nColumn + i ) * 4 ]; + Msg( "[ %.4f %.4f %.4f %.4f ] ", pBase[0], pBase[1], pBase[2], pBase[3] ); + } + Msg( "\n" ); +} + + +//----------------------------------------------------------------------------- +// A debugging utility to display the morph accumulator +//----------------------------------------------------------------------------- +void CMorphMgr::DebugMorphAccumulator( IMatRenderContext *pRenderContext ) +{ + static bool s_bDebug = false; + if ( !s_bDebug ) + return; + + ITexture *pDest = g_pMorphMgr->MorphAccumulator( ); + if ( pDest->GetImageFormat() != IMAGE_FORMAT_RGBA32323232F ) + return; + + int nDestWidth = pDest->GetActualWidth(); + int nDestHeight = pDest->GetActualHeight(); + + float* pBuf = (float*)malloc( nDestWidth * nDestHeight * 4 * sizeof(float) ); + pRenderContext->ReadPixels( 0, 0, nDestWidth, nDestHeight, (unsigned char*)pBuf, IMAGE_FORMAT_RGBA32323232F ); + + Msg( "Morph Accumulator:\n" ); + + static int s_nMinDisplay = 0; + static int s_nMaxDisplay = -1; + static int s_nMorphIndex = 0; + + int pSubRect[4]; + ComputeAccumulatorSubrect( &pSubRect[0], &pSubRect[1], &pSubRect[2], &pSubRect[3], s_nMorphIndex ); + + if ( s_nMaxDisplay < 0 ) + { + Display32FTextureData( pBuf, s_nMinDisplay, pSubRect, pDest, MORPH_ACCUMULATOR_4TUPLES ); + } + else + { + for ( int i = s_nMinDisplay; i <= s_nMaxDisplay; ++i ) + { + Display32FTextureData( pBuf, i, pSubRect, pDest, MORPH_ACCUMULATOR_4TUPLES ); + } + } + free( pBuf ); +} + + +//----------------------------------------------------------------------------- +// A debugging utility to display the morph weights +//----------------------------------------------------------------------------- +void CMorphMgr::DebugMorphWeights( IMatRenderContext *pRenderContext ) +{ + static bool s_bDebug = false; + if ( !s_bDebug ) + return; + + ITexture *pTexture = MorphWeights(); + int nWidth = pTexture->GetActualWidth(); + int nHeight = pTexture->GetActualHeight(); + if ( pTexture->GetImageFormat() != IMAGE_FORMAT_RGBA32323232F ) + return; + + pRenderContext->Flush(); + float* pBuf = (float*)malloc( nWidth * nHeight * 4 * sizeof(float) ); + pRenderContext->ReadPixels( 0, 0, nWidth, nHeight, (unsigned char*)pBuf, IMAGE_FORMAT_RGBA32323232F ); + + Msg( "Morph Weights:\n" ); + + static int s_nMinDisplay = 0; + static int s_nMaxDisplay = -1; + static int s_nMorphIndex = 0; + + int pSubRect[4]; + ComputeWeightSubrect( &pSubRect[0], &pSubRect[1], &pSubRect[2], &pSubRect[3], s_nMorphIndex ); + + if ( s_nMaxDisplay < 0 ) + { + Display32FTextureData( pBuf, s_nMinDisplay, pSubRect, pTexture, 1 ); + } + else + { + for ( int i = s_nMinDisplay; i <= s_nMaxDisplay; ++i ) + { + Display32FTextureData( pBuf, i, pSubRect, pTexture, 1 ); + } + } + free( pBuf ); +} + + +//----------------------------------------------------------------------------- +// Draws the morph accumulator +//----------------------------------------------------------------------------- +#ifdef _DEBUG +ConVar mat_drawmorphaccumulator( "mat_drawmorphaccumulator", "0", FCVAR_CHEAT ); +ConVar mat_drawmorphweights( "mat_drawmorphweights", "0", FCVAR_CHEAT ); +#endif + +void CMorphMgr::DrawMorphTempTexture( IMatRenderContext *pRenderContext, IMaterial *pMaterial, ITexture *pTexture ) +{ + pMaterial = ((IMaterialInternal *)pMaterial)->GetRealTimeVersion(); //always work with the real time version of materials internally. + + static int s_nLastFrameCount = -1; + static int s_nX = 0, s_nY = 0; + if ( s_nLastFrameCount != m_nFrameCount ) + { + s_nX = 0; s_nY = 0; + s_nLastFrameCount = m_nFrameCount; + } + + pRenderContext->Flush(); + + int nWidth = pTexture->GetActualWidth(); + int nHeight = pTexture->GetActualHeight(); + ::DrawScreenSpaceRectangle( pMaterial, s_nX, s_nY, nWidth, nHeight, + 0, 0, nWidth-1, nHeight-1, nWidth, nHeight ); + + s_nX += nWidth; + if ( s_nX > 1024 ) + { + s_nX = 0; + s_nY += nHeight; + } + pRenderContext->Flush(); +} + + +//----------------------------------------------------------------------------- +// Starts, ends morph accumulation. +//----------------------------------------------------------------------------- +int CMorphMgr::MaxHWMorphBatchCount() const +{ + return CMorphMgrRenderContext::MAX_MODEL_MORPHS; +} + + +//----------------------------------------------------------------------------- +// Returns the texcoord associated with a morph +//----------------------------------------------------------------------------- +bool CMorphMgr::GetMorphAccumulatorTexCoord( IMorphMgrRenderContext *pRenderContext, Vector2D *pTexCoord, IMorph *pMorph, int nVertex ) +{ + CMorphMgrRenderContext *pMorphRenderContext = static_cast< CMorphMgrRenderContext* >( pRenderContext ); + int nRenderId = pMorphRenderContext->GetRenderId( static_cast( pMorph ) ); + if ( nRenderId < 0 ) + { + pTexCoord->Init(); + return false; + } + + int nWidth = m_pMorphAccumTexture->GetActualWidth(); + int nHeight = m_pMorphAccumTexture->GetActualHeight(); + if ( !nWidth || !nHeight ) + { + pTexCoord->Init(); + return false; + } + + float flOOWidth = ( nWidth != 0 ) ? 1.0f / nWidth : 1.0f; + float flOOHeight = ( nHeight != 0 ) ? 1.0f / nHeight : 1.0f; + + int x, y, w, h; + ComputeAccumulatorSubrect( &x, &y, &w, &h, nRenderId ); + int nColumn = nVertex / h; + int nRow = nVertex - h * nColumn; + nColumn *= MORPH_ACCUMULATOR_4TUPLES; + + pTexCoord->x = ( x + nColumn + 0.5f ) * flOOWidth; + pTexCoord->y = ( y + nRow + 0.5f ) * flOOHeight; + Assert( IsFinite( pTexCoord->x ) && IsFinite( pTexCoord->y ) ); + return true; +} + + +//----------------------------------------------------------------------------- +// Starts, ends morph accumulation. +//----------------------------------------------------------------------------- +void CMorphMgr::BeginMorphAccumulation( IMorphMgrRenderContext *pIRenderContext ) +{ + VPROF_BUDGET( "CMorph::BeginMorphAccumulation", _T("HW Morphing") ); + + // Set up the render context + CMorphMgrRenderContext *pMorphRenderContext = static_cast< CMorphMgrRenderContext* >( pIRenderContext ); + Assert( !pMorphRenderContext->m_bInMorphAccumulation ); + pMorphRenderContext->m_nMorphCount = 0; + + CMatRenderContextPtr pRenderContext( g_pMaterialSystem ); + IMatRenderContextInternal *pRenderContextInternal = static_cast( (IMatRenderContext*)pRenderContext ); + + // Cache off the current material and other render state + // NOTE: We always have to do this because pushing the morph accumulator + // may cause it to be unbound; therefore we must force a rebind of the material. + m_pPrevMaterial = pRenderContextInternal->GetCurrentMaterial(); + m_pPrevProxy = pRenderContextInternal->GetCurrentProxy(); + m_nPrevBoneCount = pRenderContextInternal->GetCurrentNumBones(); + m_nPrevClipMode = pRenderContext->GetHeightClipMode( ); + m_bPrevClippingEnabled = pRenderContext->EnableClipping( false ); + m_bFlashlightMode = pRenderContext->GetFlashlightMode(); + pRenderContext->SetHeightClipMode( MATERIAL_HEIGHTCLIPMODE_DISABLE ); + pRenderContext->SetNumBoneWeights( 0 ); + pRenderContext->SetFlashlightMode( false ); + + if ( !m_bUsingConstantRegisters ) + { + // FIXME: We could theoretically avoid pushing this if we copied off all the + // weights and set the weight texture only at the end if any non-zero weights + // were sent down + pRenderContext->PushRenderTargetAndViewport( m_pMorphWeightTexture ); + +#ifdef _DEBUG + // NOTE: No need to clear the texture; we will only be reading out of that + // texture at points where we've rendered to in this pass. + // But, we'll do it for debugging reasons. + // I believe this pattern of weights is the least likely to occur naturally. + pRenderContext->ClearColor4ub( 0, 0, 0, 0 ); + pRenderContext->ClearBuffers( true, false, false ); +#endif + } + +#ifdef DBGFLAG_ASSERT + pMorphRenderContext->m_bInMorphAccumulation = true; +#endif +} + +void CMorphMgr::EndMorphAccumulation( IMorphMgrRenderContext *pIRenderContext ) +{ + VPROF_BUDGET( "CMorph::EndMorphAccumulation", _T("HW Morphing") ); + + CMorphMgrRenderContext *pMorphRenderContext = static_cast< CMorphMgrRenderContext* >( pIRenderContext ); + Assert( pMorphRenderContext->m_bInMorphAccumulation ); + VPROF_INCREMENT_COUNTER( "HW Morph Count", pMorphRenderContext->m_nMorphCount ); + + CMatRenderContextPtr pRenderContext( g_pMaterialSystem ); + +#ifdef _DEBUG + if ( !m_bUsingConstantRegisters ) + { + DebugMorphWeights( pRenderContext ); + } +#endif + + // Now that all the weights have been rendered, accumulate the morphs + // First, clear the morph accumulation texture + int nWidth = m_pMorphAccumTexture->GetActualWidth(); + int nHeight = m_pMorphAccumTexture->GetActualHeight(); + if ( !m_bUsingConstantRegisters ) + { + pRenderContext->SetRenderTargetEx( 0, m_pMorphAccumTexture ); + pRenderContext->Viewport( 0, 0, nWidth, nHeight ); + } + else + { + pRenderContext->PushRenderTargetAndViewport( m_pMorphAccumTexture ); + } + pRenderContext->ClearColor4ub( 0, 0, 0, 0 ); + pRenderContext->ClearBuffers( true, false, false ); + + for ( int i = 0; i < pMorphRenderContext->m_nMorphCount; ++i ) + { + pMorphRenderContext->m_pMorphsToAccumulate[i]->AccumulateMorph( i ); + } +#ifdef _DEBUG + DebugMorphAccumulator( pRenderContext ); +#endif + pRenderContext->PopRenderTargetAndViewport(); + +#ifdef _DEBUG + if ( mat_drawmorphweights.GetInt() ) + { + if ( !m_bUsingConstantRegisters ) + { + DrawMorphTempTexture( pRenderContext, m_pVisualizeMorphWeight, MorphWeights( ) ); + } + } + if ( mat_drawmorphaccumulator.GetInt() ) + { + DrawMorphTempTexture( pRenderContext, m_pVisualizeMorphAccum, MorphAccumulator( ) ); + } +#endif + + pRenderContext->Bind( m_pPrevMaterial, m_pPrevProxy ); + pRenderContext->SetNumBoneWeights( m_nPrevBoneCount ); + pRenderContext->SetHeightClipMode( m_nPrevClipMode ); + pRenderContext->EnableClipping( m_bPrevClippingEnabled ); + pRenderContext->SetFlashlightMode( m_bFlashlightMode ); + +#ifdef DBGFLAG_ASSERT + pMorphRenderContext->m_bInMorphAccumulation = false; +#endif +} + + +//----------------------------------------------------------------------------- +// Accumulates a morph target into the morph texture +//----------------------------------------------------------------------------- +void CMorphMgr::AccumulateMorph( IMorphMgrRenderContext *pIRenderContext, IMorph* pMorph, int nMorphCount, const MorphWeight_t* pWeights ) +{ + CMorphMgrRenderContext *pMorphRenderContext = static_cast< CMorphMgrRenderContext* >( pIRenderContext ); + Assert( pMorphRenderContext->m_bInMorphAccumulation ); + + Assert( pMorphRenderContext->m_nMorphCount < CMorphMgrRenderContext::MAX_MODEL_MORPHS ); + if ( pMorphRenderContext->m_nMorphCount >= CMorphMgrRenderContext::MAX_MODEL_MORPHS ) + { + Warning( "Attempted to morph too many meshes in a single model!\n" ); + Assert(0); + return; + } + + CMatRenderContextPtr pRenderContext( g_pMaterialSystem ); + + CMorph *pMorphInternal = static_cast( pMorph ); + if ( !m_bUsingConstantRegisters ) + { + pRenderContext->Bind( m_pRenderMorphWeight ); + } + if ( pMorphInternal->RenderMorphWeights( pRenderContext, pMorphRenderContext->m_nMorphCount, nMorphCount, pWeights ) ) + { + pMorphRenderContext->m_pMorphsToAccumulate[pMorphRenderContext->m_nMorphCount] = pMorphInternal; + ++pMorphRenderContext->m_nMorphCount; + } +} + diff --git a/materialsystem/occlusionquerymgr.cpp b/materialsystem/occlusionquerymgr.cpp new file mode 100644 index 0000000..5ee497e --- /dev/null +++ b/materialsystem/occlusionquerymgr.cpp @@ -0,0 +1,258 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//============================================================================= + +#include "pch_materialsystem.h" + +#define MATSYS_INTERNAL + +#include "occlusionquerymgr.h" +#include "imaterialsysteminternal.h" +#include "imatrendercontextinternal.h" + +// NOTE: This must be the last file included!!! +#include "tier0/memdbgon.h" + + +//----------------------------------------------------------------------------- +// Singleton +//----------------------------------------------------------------------------- +static COcclusionQueryMgr s_OcclusionQueryMgr; +COcclusionQueryMgr *g_pOcclusionQueryMgr = &s_OcclusionQueryMgr; + + +//----------------------------------------------------------------------------- +// Constructor +//----------------------------------------------------------------------------- +COcclusionQueryMgr::COcclusionQueryMgr() +{ + m_nFrameCount = 0; +} + + +//----------------------------------------------------------------------------- +// Allocate and delete query objects. +//----------------------------------------------------------------------------- +OcclusionQueryObjectHandle_t COcclusionQueryMgr::CreateOcclusionQueryObject( ) +{ + m_Mutex.Lock(); + int h = m_OcclusionQueryObjects.AddToTail(); + m_Mutex.Unlock(); + return (OcclusionQueryObjectHandle_t)h; +} + +void COcclusionQueryMgr::OnCreateOcclusionQueryObject( OcclusionQueryObjectHandle_t h ) +{ + for ( int i = 0; i < COUNT_OCCLUSION_QUERY_STACK; i++) + { + m_OcclusionQueryObjects[(int)h].m_QueryHandle[i] = g_pShaderAPI->CreateOcclusionQueryObject( ); + } +} + +// Flushes an outstanding query +// HEY - Be very careful using this method - it causes a full pipeline flush/stall! +void COcclusionQueryMgr::FlushQuery( OcclusionQueryObjectHandle_t hOcclusionQuery, int nIndex ) +{ + // Flush out any previous queries + int h = (int)hOcclusionQuery; + if ( m_OcclusionQueryObjects[h].m_bHasBeenIssued[nIndex] ) + { + ShaderAPIOcclusionQuery_t hQuery = m_OcclusionQueryObjects[h].m_QueryHandle[nIndex]; + + while ( OCCLUSION_QUERY_RESULT_PENDING == g_pShaderAPI->OcclusionQuery_GetNumPixelsRendered( hQuery, true ) ) + continue; + } +} + +void COcclusionQueryMgr::DestroyOcclusionQueryObject( OcclusionQueryObjectHandle_t hOcclusionQuery ) +{ + int h = (int)hOcclusionQuery; + Assert( m_OcclusionQueryObjects.IsValidIndex( h ) ); + if ( m_OcclusionQueryObjects.IsValidIndex( h ) ) + { + for ( int i = 0; i < COUNT_OCCLUSION_QUERY_STACK; i++) + { + if ( m_OcclusionQueryObjects[h].m_QueryHandle[i] != INVALID_SHADERAPI_OCCLUSION_QUERY_HANDLE ) + { + g_pShaderAPI->DestroyOcclusionQueryObject( m_OcclusionQueryObjects[h].m_QueryHandle[i] ); + } + } + m_Mutex.Lock(); + m_OcclusionQueryObjects.Remove( h ); + m_Mutex.Unlock(); + } +} + + +//----------------------------------------------------------------------------- +// Advance frame +//----------------------------------------------------------------------------- +void COcclusionQueryMgr::AdvanceFrame() +{ + ++m_nFrameCount; +} + + +//----------------------------------------------------------------------------- +// Alt-tab support +// NOTE: This doesn't queue anything up +//----------------------------------------------------------------------------- +void COcclusionQueryMgr::AllocOcclusionQueryObjects( void ) +{ + FOR_EACH_LL( m_OcclusionQueryObjects, iterator ) + { + for ( int i = 0; i < COUNT_OCCLUSION_QUERY_STACK; i++) + { + m_OcclusionQueryObjects[iterator].m_QueryHandle[i] = g_pShaderAPI->CreateOcclusionQueryObject(); + m_OcclusionQueryObjects[iterator].m_bHasBeenIssued[i] = false; // any in-flight queries are never returning + } + } +} + +void COcclusionQueryMgr::FreeOcclusionQueryObjects( void ) +{ + FOR_EACH_LL( m_OcclusionQueryObjects, iterator ) + { + for ( int i = 0; i < COUNT_OCCLUSION_QUERY_STACK; i++) + { + if ( m_OcclusionQueryObjects[iterator].m_QueryHandle[i] != INVALID_SHADERAPI_OCCLUSION_QUERY_HANDLE ) + { + g_pShaderAPI->DestroyOcclusionQueryObject( m_OcclusionQueryObjects[iterator].m_QueryHandle[i] ); + m_OcclusionQueryObjects[iterator].m_QueryHandle[i] = INVALID_SHADERAPI_OCCLUSION_QUERY_HANDLE; + m_OcclusionQueryObjects[iterator].m_bHasBeenIssued[i] = false; + } + } + } +} + + +//----------------------------------------------------------------------------- +// Used to make the handle think it's never had a successful query before +//----------------------------------------------------------------------------- +void COcclusionQueryMgr::ResetOcclusionQueryObject( OcclusionQueryObjectHandle_t hOcclusionQuery ) +{ + int h = (int)hOcclusionQuery; + Assert( m_OcclusionQueryObjects.IsValidIndex( h ) ); + if ( m_OcclusionQueryObjects.IsValidIndex( h ) ) + { + // Forget we've issued any previous queries - there's no need to flush them. + for ( int i = 0; i < COUNT_OCCLUSION_QUERY_STACK; i++) + { + m_OcclusionQueryObjects[h].m_bHasBeenIssued[i] = false; + } + + m_OcclusionQueryObjects[h].m_LastResult = -1; + m_OcclusionQueryObjects[h].m_nFrameIssued = -1; + } +} + + +//----------------------------------------------------------------------------- +// Bracket drawing with begin and end so that we can get counts next frame. +//----------------------------------------------------------------------------- +void COcclusionQueryMgr::BeginOcclusionQueryDrawing( OcclusionQueryObjectHandle_t hOcclusionQuery ) +{ + int h = (int)hOcclusionQuery; + Assert( m_OcclusionQueryObjects.IsValidIndex( h ) ); + if ( m_OcclusionQueryObjects.IsValidIndex( h ) ) + { + int nCurrent = m_OcclusionQueryObjects[h].m_nCurrentIssue; + ShaderAPIOcclusionQuery_t hQuery = m_OcclusionQueryObjects[h].m_QueryHandle[nCurrent]; + if ( hQuery != INVALID_SHADERAPI_OCCLUSION_QUERY_HANDLE ) + { + // If it's been issued, but we haven't gotten a result when we polled last time, + // try polling one last time, since we can't poll again after we issue again. + if ( m_OcclusionQueryObjects[h].m_bHasBeenIssued[nCurrent] ) + { + int nPixels = g_pShaderAPI->OcclusionQuery_GetNumPixelsRendered( hQuery, false ); + if ( ( nPixels == OCCLUSION_QUERY_RESULT_PENDING ) && ( m_OcclusionQueryObjects[h].m_nFrameIssued == m_nFrameCount ) ) + { + static int s_nWarnCount = 0; + if ( s_nWarnCount++ < 5 ) + { + DevWarning( "blocking issue in occlusion queries! Grab brian!\n" ); + } + } + while( !OCCLUSION_QUERY_FINISHED( nPixels ) ) + { + // We're going to reuse this query, so issue a flush to force the query results to come back. + nPixels = g_pShaderAPI->OcclusionQuery_GetNumPixelsRendered( hQuery, true ); + } + if ( nPixels >= 0 ) + { + m_OcclusionQueryObjects[h].m_LastResult = nPixels; + } + m_OcclusionQueryObjects[h].m_bHasBeenIssued[nCurrent] = false; + } + g_pShaderAPI->BeginOcclusionQueryDrawing( hQuery ); + } + } +} + + +void COcclusionQueryMgr::EndOcclusionQueryDrawing( OcclusionQueryObjectHandle_t hOcclusionQuery ) +{ + int h = (int)hOcclusionQuery; + Assert( m_OcclusionQueryObjects.IsValidIndex( h ) ); + if ( m_OcclusionQueryObjects.IsValidIndex( h ) ) + { + int nCurrent = m_OcclusionQueryObjects[h].m_nCurrentIssue; + ShaderAPIOcclusionQuery_t hQuery = m_OcclusionQueryObjects[h].m_QueryHandle[nCurrent]; + if ( hQuery != INVALID_SHADERAPI_OCCLUSION_QUERY_HANDLE ) + { + g_pShaderAPI->EndOcclusionQueryDrawing( hQuery ); + + m_OcclusionQueryObjects[h].m_bHasBeenIssued[nCurrent] = true; + m_OcclusionQueryObjects[h].m_nFrameIssued = m_nFrameCount; + + nCurrent = ( nCurrent + 1 ) % COUNT_OCCLUSION_QUERY_STACK; + m_OcclusionQueryObjects[h].m_nCurrentIssue = nCurrent; + } + } +} + + +//----------------------------------------------------------------------------- +// Get the number of pixels rendered between begin and end on an earlier frame. +// Calling this in the same frame is a huge perf hit! +//----------------------------------------------------------------------------- +void COcclusionQueryMgr::OcclusionQuery_IssueNumPixelsRenderedQuery( OcclusionQueryObjectHandle_t hOcclusionQuery ) +{ + int h = (int)hOcclusionQuery; + Assert( m_OcclusionQueryObjects.IsValidIndex( h ) ); + if ( m_OcclusionQueryObjects.IsValidIndex( h ) ) + { + for( int i = 0; i < COUNT_OCCLUSION_QUERY_STACK; i++ ) + { + int nIndex = ( m_OcclusionQueryObjects[h].m_nCurrentIssue + i ) % COUNT_OCCLUSION_QUERY_STACK; + ShaderAPIOcclusionQuery_t hQuery = m_OcclusionQueryObjects[h].m_QueryHandle[nIndex]; + if ( hQuery != INVALID_SHADERAPI_OCCLUSION_QUERY_HANDLE && m_OcclusionQueryObjects[h].m_bHasBeenIssued[nIndex] ) + { + int nPixels = g_pShaderAPI->OcclusionQuery_GetNumPixelsRendered( hQuery ); + if ( nPixels == OCCLUSION_QUERY_RESULT_ERROR ) + { + // In GL mode, it's possible for queries to fail (say when mat_queue_mode is toggled). In this case, just clear m_bHasBeenIssued and forget we ever issued this query. + m_OcclusionQueryObjects[h].m_bHasBeenIssued[nIndex] = false; + } + else if ( nPixels >= 0 ) + { + m_OcclusionQueryObjects[h].m_LastResult = nPixels; + m_OcclusionQueryObjects[h].m_bHasBeenIssued[nIndex] = false; + } + } + } + } +} + +int COcclusionQueryMgr::OcclusionQuery_GetNumPixelsRendered( OcclusionQueryObjectHandle_t h, bool bDoQuery ) +{ + if ( bDoQuery ) + { + OcclusionQuery_IssueNumPixelsRenderedQuery( h ); + } + + int nPixels = m_OcclusionQueryObjects[(int)h].m_LastResult; + return nPixels; +} diff --git a/materialsystem/occlusionquerymgr.h b/materialsystem/occlusionquerymgr.h new file mode 100644 index 0000000..2820e51 --- /dev/null +++ b/materialsystem/occlusionquerymgr.h @@ -0,0 +1,106 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//============================================================================= + +#ifndef OCCLUSIONQUERY_H +#define OCCLUSIONQUERY_H + +#include "tier1/utlsymbol.h" +#include "tier1/utlrbtree.h" + +#ifndef MATSYS_INTERNAL +#error "This file is private to the implementation of IMaterialSystem/IMaterialSystemInternal" +#endif + +#if defined( _WIN32 ) +#pragma once +#endif + + +#include "tier1/utllinkedlist.h" +#include "shaderapi/ishaderapi.h" + + +class IMatRenderContextInternal; + +// because the GPU/driver can buffer frames we need to allow several queries to be in flight. +// The game wants to reiusse the queries every frame so we buffer them here to avoid +// having to block waiting for a query to be available for reissue. +#define COUNT_OCCLUSION_QUERY_STACK 4 + +//----------------------------------------------------------------------------- +// Dictionary of all known materials +//----------------------------------------------------------------------------- +class COcclusionQueryMgr +{ +public: + COcclusionQueryMgr(); + + // Allocate and delete query objects. + OcclusionQueryObjectHandle_t CreateOcclusionQueryObject( ); + void OnCreateOcclusionQueryObject( OcclusionQueryObjectHandle_t h ); + void DestroyOcclusionQueryObject( OcclusionQueryObjectHandle_t h ); + + // Bracket drawing with begin and end so that we can get counts next frame. + void BeginOcclusionQueryDrawing( OcclusionQueryObjectHandle_t h ); + void EndOcclusionQueryDrawing( OcclusionQueryObjectHandle_t h ); + + // Used to make the handle think it's never had a successful query before + void ResetOcclusionQueryObject( OcclusionQueryObjectHandle_t ); + + // Get the number of pixels rendered between begin and end on an earlier frame. + // Calling this in the same frame is a huge perf hit! + int OcclusionQuery_GetNumPixelsRendered( OcclusionQueryObjectHandle_t h, bool bDoQuery ); + void OcclusionQuery_IssueNumPixelsRenderedQuery( OcclusionQueryObjectHandle_t h ); + + // Internal stuff for occlusion query + void AllocOcclusionQueryObjects( void ); + void FreeOcclusionQueryObjects( void ); + + // Advance frame + void AdvanceFrame(); + +private: + //----------------------------------------------------------------------------- + // Occlusion query objects + //----------------------------------------------------------------------------- + struct OcclusionQueryObject_t + { + ShaderAPIOcclusionQuery_t m_QueryHandle[COUNT_OCCLUSION_QUERY_STACK]; + int m_LastResult; + int m_nFrameIssued; + int m_nCurrentIssue; + bool m_bHasBeenIssued[COUNT_OCCLUSION_QUERY_STACK]; + + OcclusionQueryObject_t(void) + { + for ( int i = 0; i < COUNT_OCCLUSION_QUERY_STACK; i++ ) + { + m_QueryHandle[i] = INVALID_SHADERAPI_OCCLUSION_QUERY_HANDLE; + m_bHasBeenIssued[i] = false; + } + m_LastResult = -1; + m_nFrameIssued = -1; + m_nCurrentIssue = 0; + } + }; + + // Flushes an outstanding query + void FlushQuery( OcclusionQueryObjectHandle_t hOcclusionQuery, int nIndex ); + + // Occlusion query objects + CUtlFixedLinkedList m_OcclusionQueryObjects; + CThreadFastMutex m_Mutex; + int m_nFrameCount; +}; + + +//----------------------------------------------------------------------------- +// Singleton +//----------------------------------------------------------------------------- +extern COcclusionQueryMgr *g_pOcclusionQueryMgr; + + +#endif // OCCLUSIONQUERY_H diff --git a/materialsystem/pch_materialsystem.cpp b/materialsystem/pch_materialsystem.cpp new file mode 100644 index 0000000..2042eb6 --- /dev/null +++ b/materialsystem/pch_materialsystem.cpp @@ -0,0 +1,7 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//============================================================================= + +#include "pch_materialsystem.h" \ No newline at end of file diff --git a/materialsystem/pch_materialsystem.h b/materialsystem/pch_materialsystem.h new file mode 100644 index 0000000..f6935b5 --- /dev/null +++ b/materialsystem/pch_materialsystem.h @@ -0,0 +1,56 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//============================================================================= + +#ifndef PCH_MATERIALSYSTEM_H +#define PCH_MATERIALSYSTEM_H + +#if defined( _WIN32 ) +#pragma once +#endif + +#if defined( _WIN32 ) && !defined( _X360 ) +#define WIN32_LEAN_AND_MEAN 1 +#include "windows.h" +#endif + +#include +#include +#include "crtmemdebug.h" + +#include "tier0/platform.h" +#include "tier0/dbg.h" +#include "tier0/fasttimer.h" +#include "tier0/vprof.h" + +#include "tier1/tier1.h" +#include "tier1/utlstack.h" +#include "tier1/generichash.h" +#include "tier1/utlsymbol.h" +#include "tier1/utlrbtree.h" +#include "tier1/strtools.h" +#include "tier0/icommandline.h" +#include "mathlib/vmatrix.h" +#include "icvar.h" +#include "KeyValues.h" +#include "convar.h" + +#include "tier2/tier2.h" +#include "bitmap/imageformat.h" +#include "bitmap/tgawriter.h" +#include "bitmap/tgaloader.h" +#include "datacache/idatacache.h" +#include "filesystem.h" +#include "pixelwriter.h" + +#include "materialsystem_global.h" +#include "materialsystem/imaterialvar.h" +#include "materialsystem/imesh.h" +#include "materialsystem/IColorCorrection.h" + +#include "imaterialinternal.h" +#include "imaterialsysteminternal.h" + +#endif // PCH_MATERIALSYSTEM_H diff --git a/materialsystem/resource.h b/materialsystem/resource.h new file mode 100644 index 0000000..24e508b --- /dev/null +++ b/materialsystem/resource.h @@ -0,0 +1,22 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +// +//=============================================================================// +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by MaterialSystem.rc +// + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NEXT_RESOURCE_VALUE 101 +#define _APS_NEXT_COMMAND_VALUE 40001 +#define _APS_NEXT_CONTROL_VALUE 1000 +#define _APS_NEXT_SYMED_VALUE 101 +#endif +#endif diff --git a/materialsystem/shader_dll_verify.cpp b/materialsystem/shader_dll_verify.cpp new file mode 100644 index 0000000..b9a3fbb --- /dev/null +++ b/materialsystem/shader_dll_verify.cpp @@ -0,0 +1,96 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//============================================================================= + +#include +#include "shader_dll_verify.h" + + +static unsigned char *g_pLastInputData = 0; +static HANDLE g_hDLLInst = 0; + + +extern "C" +{ + void __declspec( dllexport ) _ftol3( char *pData ); + BOOL WINAPI DllMain (HANDLE hInst, ULONG ulInit, LPVOID lpReserved); +}; + + +BOOL WINAPI DllMain (HANDLE hInst, ULONG ulInit, LPVOID lpReserved) +{ + lpReserved = lpReserved; + ulInit = ulInit; + + g_hDLLInst = hInst; + return true; +} + + +class CShaderDLLVerification : public IShaderDLLVerification +{ +public: + + virtual CRC32_t Function1( unsigned char *pData ); + virtual void Function2( int a, int b, int c ); + virtual void Function3( int a, int b, int c ); + virtual void Function4( int a, int b, int c ); + virtual CRC32_t Function5(); +}; + +static CShaderDLLVerification g_Blah; + + + +// The main exported function.. return a pointer to g_Blah. +void __declspec( dllexport ) _ftol3( char *pData ) +{ + pData += SHADER_DLL_VERIFY_DATA_PTR_OFFSET; + char *pToFillIn = (char*)&g_Blah; + memcpy( pData, &pToFillIn, 4 ); +} + + +CRC32_t CShaderDLLVerification::Function1( unsigned char *pData ) +{ + pData += SHADER_DLL_VERIFY_DATA_PTR_OFFSET; + g_pLastInputData = (unsigned char*)pData; + + void *pVerifyPtr1 = &g_Blah; + + CRC32_t testCRC; + CRC32_Init( &testCRC ); + CRC32_ProcessBuffer( &testCRC, pData, SHADER_DLL_VERIFY_DATA_LEN1 ); + CRC32_ProcessBuffer( &testCRC, &g_hDLLInst, 4 ); + CRC32_ProcessBuffer( &testCRC, &pVerifyPtr1, 4 ); + CRC32_Final( &testCRC ); + + return testCRC; +} + +void CShaderDLLVerification::Function2( int a, int b, int c ) +{ + a=b=c; + MD5Context_t md5Context; + MD5Init( &md5Context ); + MD5Update( &md5Context, g_pLastInputData + SHADER_DLL_VERIFY_DATA_PTR_OFFSET, SHADER_DLL_VERIFY_DATA_LEN1 - SHADER_DLL_VERIFY_DATA_PTR_OFFSET ); + MD5Final( g_pLastInputData, &md5Context ); +} + +void CShaderDLLVerification::Function3( int a, int b, int c ) +{ + a=b=c; +} + +void CShaderDLLVerification::Function4( int a, int b, int c ) +{ + a=b=c; +} + + +CRC32_t CShaderDLLVerification::Function5() +{ + return 32423; +} diff --git a/materialsystem/shader_dll_verify.h b/materialsystem/shader_dll_verify.h new file mode 100644 index 0000000..daefe9f --- /dev/null +++ b/materialsystem/shader_dll_verify.h @@ -0,0 +1,38 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: This is temporary obfuscation code to verify that a base shader +// DLL comes from us (because it includes some interfaces that we don't +// give out with the SDK). +// +//============================================================================= + +#ifndef SHADER_DLL_VERIFY_H +#define SHADER_DLL_VERIFY_H +#ifdef _WIN32 +#pragma once +#endif + +#include "tier0/platform.h" +#include "tier1/checksum_crc.h" +#include "tier1/checksum_md5.h" + + +#define SHADER_DLL_VERIFY_DATA_LEN1 4101 +#define SHADER_DLL_VERIFY_DATA_PTR_OFFSET 43 + +#define SHADER_DLL_FNNAME_1 "_ftol3" +typedef void (*ShaderDLLVerifyFn)( char *pData ); + +abstract_class IShaderDLLVerification +{ +public: + + virtual CRC32_t Function1( unsigned char *pData ) = 0; + virtual void Function2( int a, int b, int c ) = 0; + virtual void Function3( int a, int b, int c ) = 0; + virtual void Function4( int a, int b, int c ) = 0; + virtual CRC32_t Function5() = 0; +}; + + +#endif // SHADER_DLL_VERIFY_H diff --git a/materialsystem/shaderapidx9/ShaderShadowDx10.h b/materialsystem/shaderapidx9/ShaderShadowDx10.h new file mode 100644 index 0000000..ff987c0 --- /dev/null +++ b/materialsystem/shaderapidx9/ShaderShadowDx10.h @@ -0,0 +1,176 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +// +//===========================================================================// + +#ifndef SHADERSHADOWDX10_H +#define SHADERSHADOWDX10_H + +#ifdef _WIN32 +#pragma once +#endif + +#include "shaderapi/ishaderapi.h" +#include "shaderapi/ishadershadow.h" + + +//----------------------------------------------------------------------------- +// The empty shader shadow +//----------------------------------------------------------------------------- +class CShaderShadowDx10 : public IShaderShadow +{ +public: + CShaderShadowDx10(); + virtual ~CShaderShadowDx10(); + + // Sets the default *shadow* state + void SetDefaultState(); + + // Methods related to depth buffering + void DepthFunc( ShaderDepthFunc_t depthFunc ); + void EnableDepthWrites( bool bEnable ); + void EnableDepthTest( bool bEnable ); + void EnablePolyOffset( PolygonOffsetMode_t nOffsetMode ); + + // Suppresses/activates color writing + void EnableColorWrites( bool bEnable ); + void EnableAlphaWrites( bool bEnable ); + + // Methods related to alpha blending + void EnableBlending( bool bEnable ); + void BlendFunc( ShaderBlendFactor_t srcFactor, ShaderBlendFactor_t dstFactor ); + + // Alpha testing + void EnableAlphaTest( bool bEnable ); + void AlphaFunc( ShaderAlphaFunc_t alphaFunc, float alphaRef /* [0-1] */ ); + + // Wireframe/filled polygons + void PolyMode( ShaderPolyModeFace_t face, ShaderPolyMode_t polyMode ); + + // Back face culling + void EnableCulling( bool bEnable ); + + // constant color + transparency + void EnableConstantColor( bool bEnable ); + + // Indicates the vertex format for use with a vertex shader + // The flags to pass in here come from the VertexFormatFlags_t enum + // If pTexCoordDimensions is *not* specified, we assume all coordinates + // are 2-dimensional + void VertexShaderVertexFormat( unsigned int flags, + int numTexCoords, int* pTexCoordDimensions, + int userDataSize ); + + // Indicates we're going to light the model + void EnableLighting( bool bEnable ); + void EnableSpecular( bool bEnable ); + + // vertex blending + void EnableVertexBlend( bool bEnable ); + + // per texture unit stuff + void OverbrightValue( TextureStage_t stage, float value ); + void EnableTexture( Sampler_t stage, bool bEnable ); + void EnableTexGen( TextureStage_t stage, bool bEnable ); + void TexGen( TextureStage_t stage, ShaderTexGenParam_t param ); + + // alternate method of specifying per-texture unit stuff, more flexible and more complicated + // Can be used to specify different operation per channel (alpha/color)... + void EnableCustomPixelPipe( bool bEnable ); + void CustomTextureStages( int stageCount ); + void CustomTextureOperation( TextureStage_t stage, ShaderTexChannel_t channel, + ShaderTexOp_t op, ShaderTexArg_t arg1, ShaderTexArg_t arg2 ); + + // indicates what per-vertex data we're providing + void DrawFlags( unsigned int drawFlags ); + + // A simpler method of dealing with alpha modulation + void EnableAlphaPipe( bool bEnable ); + void EnableConstantAlpha( bool bEnable ); + void EnableVertexAlpha( bool bEnable ); + void EnableTextureAlpha( TextureStage_t stage, bool bEnable ); + + // GR - Separate alpha blending + void EnableBlendingSeparateAlpha( bool bEnable ); + void BlendFuncSeparateAlpha( ShaderBlendFactor_t srcFactor, ShaderBlendFactor_t dstFactor ); + + // Sets the vertex and pixel shaders + void SetVertexShader( const char *pFileName, int vshIndex ); + void SetPixelShader( const char *pFileName, int pshIndex ); + + // Convert from linear to gamma color space on writes to frame buffer. + void EnableSRGBWrite( bool bEnable ) + { + } + + void EnableSRGBRead( Sampler_t stage, bool bEnable ) + { + } + + virtual void FogMode( ShaderFogMode_t fogMode ) + { + } + virtual void SetDiffuseMaterialSource( ShaderMaterialSource_t materialSource ) + { + } + + virtual void SetMorphFormat( MorphFormat_t flags ) + { + } + + virtual void EnableStencil( bool bEnable ) + { + } + virtual void StencilFunc( ShaderStencilFunc_t stencilFunc ) + { + } + virtual void StencilPassOp( ShaderStencilOp_t stencilOp ) + { + } + virtual void StencilFailOp( ShaderStencilOp_t stencilOp ) + { + } + virtual void StencilDepthFailOp( ShaderStencilOp_t stencilOp ) + { + } + virtual void StencilReference( int nReference ) + { + } + virtual void StencilMask( int nMask ) + { + } + virtual void StencilWriteMask( int nMask ) + { + } + + virtual void DisableFogGammaCorrection( bool bDisable ) + { + //FIXME: empty for now. + } + virtual void FogMode( ShaderFogMode_t fogMode, bool bVertexFog ) + { + //FIXME: empty for now. + } + + // Alpha to coverage + void EnableAlphaToCoverage( bool bEnable ); + + void SetShadowDepthFiltering( Sampler_t stage ); + + // More alpha blending state + void BlendOp( ShaderBlendOp_t blendOp ); + void BlendOpSeparateAlpha( ShaderBlendOp_t blendOp ); + + bool m_IsTranslucent; + bool m_IsAlphaTested; + bool m_bIsDepthWriteEnabled; + bool m_bUsesVertexAndPixelShaders; +}; + + +extern CShaderShadowDx10* g_pShaderShadowDx10; + +#endif // SHADERSHADOWDX10_H \ No newline at end of file diff --git a/materialsystem/shaderapidx9/TransitionTable.cpp b/materialsystem/shaderapidx9/TransitionTable.cpp new file mode 100644 index 0000000..ab12389 --- /dev/null +++ b/materialsystem/shaderapidx9/TransitionTable.cpp @@ -0,0 +1,1924 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +// +//===========================================================================// + +#define DISABLE_PROTECTED_THINGS +#include "togl/rendermechanism.h" +#include "TransitionTable.h" +#include "recording.h" +#include "shaderapidx8.h" +#include "shaderapi/ishaderutil.h" +#include "tier1/convar.h" +#include "materialsystem/imaterialsystemhardwareconfig.h" +#include "vertexshaderdx8.h" +#include "tier0/vprof.h" +#include "shaderdevicedx8.h" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + + +enum +{ + TEXTURE_STAGE_BIT_COUNT = 4, + TEXTURE_STAGE_MAX_STAGE = 1 << TEXTURE_STAGE_BIT_COUNT, + TEXTURE_STAGE_MASK = TEXTURE_STAGE_MAX_STAGE - 1, + + TEXTURE_OP_BIT_COUNT = 7 - TEXTURE_STAGE_BIT_COUNT, + TEXTURE_OP_SHIFT = TEXTURE_STAGE_BIT_COUNT, + TEXTURE_OP_MASK = ((1 << TEXTURE_OP_BIT_COUNT) - 1) << TEXTURE_OP_SHIFT, +}; + + +//----------------------------------------------------------------------------- +// Texture op compressing/uncompressing +//----------------------------------------------------------------------------- +inline unsigned char TextureOp( TextureStateFunc_t func, int stage ) +{ + // This fails if we've added too many texture stages states to fit in a byte. + COMPILE_TIME_ASSERT( TEXTURE_STATE_COUNT < (1 << TEXTURE_OP_BIT_COUNT) ); + Assert( stage < TEXTURE_STAGE_MAX_STAGE ); + + return ((func << TEXTURE_OP_SHIFT) & TEXTURE_OP_MASK) | (stage & TEXTURE_STAGE_MASK); +} + +inline void GetTextureOp( unsigned char nBits, TextureStateFunc_t *pFunc, int *pStage ) +{ + *pStage = (nBits & TEXTURE_STAGE_MASK); + *pFunc = (TextureStateFunc_t)((nBits & TEXTURE_OP_MASK) >> TEXTURE_OP_SHIFT); +} + + +//----------------------------------------------------------------------------- +// Stats +//----------------------------------------------------------------------------- +static int s_pRenderTransitions[RENDER_STATE_COUNT]; +static int s_pTextureTransitions[TEXTURE_STATE_COUNT][TEXTURE_STAGE_MAX_STAGE]; + + +//----------------------------------------------------------------------------- +// Singleton +//----------------------------------------------------------------------------- +CTransitionTable *g_pTransitionTable = NULL; + +#ifdef DEBUG_BOARD_STATE +inline ShadowState_t& BoardState() +{ + return g_pTransitionTable->BoardState(); +} +#endif + +inline CTransitionTable::CurrentState_t& CurrentState() +{ + return g_pTransitionTable->CurrentState(); +} + + +//----------------------------------------------------------------------------- +// Less functions +//----------------------------------------------------------------------------- +bool CTransitionTable::ShadowStateDictLessFunc::Less( const CTransitionTable::ShadowStateDictEntry_t &src1, const CTransitionTable::ShadowStateDictEntry_t &src2, void *pCtx ) +{ + return src1.m_nChecksum < src2.m_nChecksum; +} + +bool CTransitionTable::SnapshotDictLessFunc::Less( const CTransitionTable::SnapshotDictEntry_t &src1, const CTransitionTable::SnapshotDictEntry_t &src2, void *pCtx ) +{ + return src1.m_nChecksum < src2.m_nChecksum; +} + +bool CTransitionTable::UniqueSnapshotLessFunc::Less( const CTransitionTable::TransitionList_t &src1, const CTransitionTable::TransitionList_t &src2, void *pCtx ) +{ + return src1.m_NumOperations > src2.m_NumOperations; +} + + +//----------------------------------------------------------------------------- +// Constructor, destructor +//----------------------------------------------------------------------------- +CTransitionTable::CTransitionTable() : m_DefaultStateSnapshot(-1), + m_CurrentShadowId(-1), m_CurrentSnapshotId(-1), m_TransitionOps( 0, 8192 ), m_ShadowStateList( 0, 256 ), + m_TransitionTable( 0, 256 ), m_SnapshotList( 0, 256 ), + m_ShadowStateDict(0, 256 ), + m_SnapshotDict( 0, 256 ), + m_UniqueTransitions( 0, 4096 ) +{ + Assert( !g_pTransitionTable ); + g_pTransitionTable = this; + +#ifdef DEBUG_BOARD_STATE + memset( &m_BoardState, 0, sizeof( m_BoardState ) ); + memset( &m_BoardShaderState, 0, sizeof( m_BoardShaderState ) ); +#endif +} + +CTransitionTable::~CTransitionTable() +{ + Assert( g_pTransitionTable == this ); + g_pTransitionTable = NULL; +} + + +//----------------------------------------------------------------------------- +// Initialization, shutdown +//----------------------------------------------------------------------------- +bool CTransitionTable::Init( ) +{ + return true; +} + +void CTransitionTable::Shutdown( ) +{ + Reset(); +} + + +//----------------------------------------------------------------------------- +// Creates a shadow, adding an entry into the shadow list and transition table +//----------------------------------------------------------------------------- +StateSnapshot_t CTransitionTable::CreateStateSnapshot( ShadowStateId_t shadowStateId, const ShadowShaderState_t& currentShaderState ) +{ + StateSnapshot_t snapshotId = m_SnapshotList.AddToTail(); + + // Copy our snapshot into the list + SnapshotShaderState_t &shaderState = m_SnapshotList[snapshotId]; + shaderState.m_ShadowStateId = shadowStateId; + memcpy( &shaderState.m_ShaderState, ¤tShaderState, sizeof(ShadowShaderState_t) ); + memset( shaderState.m_ShaderState.m_nReserved, 0, sizeof( shaderState.m_ShaderState.m_nReserved ) ); + shaderState.m_nReserved = 0; // needed to get a good CRC + shaderState.m_nReserved2 = 0; + + // Insert entry into the lookup table + SnapshotDictEntry_t insert; + + CRC32_Init( &insert.m_nChecksum ); + CRC32_ProcessBuffer( &insert.m_nChecksum, &shaderState, sizeof(SnapshotShaderState_t) ); + CRC32_Final( &insert.m_nChecksum ); + + insert.m_nSnapshot = snapshotId; + m_SnapshotDict.Insert( insert ); + + return snapshotId; +} + + +//----------------------------------------------------------------------------- +// Creates a shadow, adding an entry into the shadow list and transition table +//----------------------------------------------------------------------------- +CTransitionTable::ShadowStateId_t CTransitionTable::CreateShadowState( const ShadowState_t ¤tState ) +{ + int newShaderState = m_ShadowStateList.AddToTail(); + + // Copy our snapshot into the list + memcpy( &m_ShadowStateList[newShaderState], ¤tState, sizeof(ShadowState_t) ); + + // all existing states must transition to the new state + int i; + for ( i = 0; i < newShaderState; ++i ) + { + // Add a new transition to all existing states + int newElem = m_TransitionTable[i].AddToTail(); + m_TransitionTable[i][newElem].m_FirstOperation = INVALID_TRANSITION_OP; + m_TransitionTable[i][newElem].m_NumOperations = 0; + } + + // Add a new vector for this transition + int newTransitionElem = m_TransitionTable.AddToTail(); + m_TransitionTable[newTransitionElem].EnsureCapacity( 32 ); + Assert( newShaderState == newTransitionElem ); + + for ( i = 0; i <= newShaderState; ++i ) + { + // Add a new transition from all existing states + int newElem = m_TransitionTable[newShaderState].AddToTail(); + m_TransitionTable[newShaderState][newElem].m_FirstOperation = INVALID_TRANSITION_OP; + m_TransitionTable[newShaderState][newElem].m_NumOperations = 0; + } + + // Insert entry into the lookup table + ShadowStateDictEntry_t insert; + + CRC32_Init( &insert.m_nChecksum ); + CRC32_ProcessBuffer( &insert.m_nChecksum, &m_ShadowStateList[newShaderState], sizeof(ShadowState_t) ); + CRC32_Final( &insert.m_nChecksum ); + + insert.m_nShadowStateId = newShaderState; + m_ShadowStateDict.Insert( insert ); + + return newShaderState; +} + + +//----------------------------------------------------------------------------- +// Finds a snapshot, if it exists. Or creates a new one if it doesn't. +//----------------------------------------------------------------------------- +CTransitionTable::ShadowStateId_t CTransitionTable::FindShadowState( const ShadowState_t& currentState ) const +{ + ShadowStateDictEntry_t find; + + CRC32_Init( &find.m_nChecksum ); + CRC32_ProcessBuffer( &find.m_nChecksum, ¤tState, sizeof(ShadowState_t) ); + CRC32_Final( &find.m_nChecksum ); + + int nDictCount = m_ShadowStateDict.Count(); + int i = m_ShadowStateDict.FindLessOrEqual( find ); + if ( i < 0 ) + return (ShadowStateId_t)-1; + + for ( ; i < nDictCount; ++i ) + { + const ShadowStateDictEntry_t &entry = m_ShadowStateDict[i]; + + // Didn't find a match + if ( entry.m_nChecksum > find.m_nChecksum ) + break; + + if ( entry.m_nChecksum != find.m_nChecksum ) + continue; + + ShadowStateId_t nShadowState = entry.m_nShadowStateId; + if (!memcmp(&m_ShadowStateList[nShadowState], ¤tState, sizeof(ShadowState_t) )) + return nShadowState; + } + + // Need to create a new one + return (ShadowStateId_t)-1; +} + + +//----------------------------------------------------------------------------- +// Finds a snapshot, if it exists. Or creates a new one if it doesn't. +//----------------------------------------------------------------------------- +StateSnapshot_t CTransitionTable::FindStateSnapshot( ShadowStateId_t id, const ShadowShaderState_t& currentState ) const +{ + SnapshotShaderState_t temp; + temp.m_ShaderState = currentState; + temp.m_ShadowStateId = id; + memset( temp.m_ShaderState.m_nReserved, 0, sizeof( temp.m_ShaderState.m_nReserved ) ); + temp.m_nReserved = 0; // needed to get a good CRC + temp.m_nReserved2 = 0; + + SnapshotDictEntry_t find; + + CRC32_Init( &find.m_nChecksum ); + CRC32_ProcessBuffer( &find.m_nChecksum, &temp, sizeof(temp) ); + CRC32_Final( &find.m_nChecksum ); + + int nDictCount = m_SnapshotDict.Count(); + int i = m_SnapshotDict.FindLessOrEqual( find ); + if ( i < 0 ) + return (StateSnapshot_t)-1; + + for ( ; i < nDictCount; ++i ) + { + // Didn't find a match + if ( m_SnapshotDict[i].m_nChecksum > find.m_nChecksum ) + break; + + if ( m_SnapshotDict[i].m_nChecksum != find.m_nChecksum ) + continue; + + StateSnapshot_t nShapshot = m_SnapshotDict[i].m_nSnapshot; + if ( (id == m_SnapshotList[nShapshot].m_ShadowStateId) && + !memcmp(&m_SnapshotList[nShapshot].m_ShaderState, ¤tState, sizeof(ShadowShaderState_t)) ) + { + return nShapshot; + } + } + + // Need to create a new one + return (StateSnapshot_t)-1; +} + + +//----------------------------------------------------------------------------- +// Used to clear the transition table when we know it's become invalid. +//----------------------------------------------------------------------------- +void CTransitionTable::Reset() +{ + m_ShadowStateList.RemoveAll(); + m_SnapshotList.RemoveAll(); + m_TransitionTable.RemoveAll(); + m_TransitionOps.RemoveAll(); + m_ShadowStateDict.RemoveAll(); + m_SnapshotDict.RemoveAll(); + m_UniqueTransitions.RemoveAll(); + m_CurrentShadowId = -1; + m_CurrentSnapshotId = -1; + m_DefaultStateSnapshot = -1; +} + + +//----------------------------------------------------------------------------- +// Sets the texture stage state +//----------------------------------------------------------------------------- +#ifdef _WIN32 +#pragma warning( disable : 4189 ) +#endif + +static inline void SetTextureStageState( int stage, D3DTEXTURESTAGESTATETYPE state, DWORD val ) +{ +#if !defined( _X360 ) + Assert( !g_pShaderDeviceDx8->IsDeactivated() ); + Dx9Device()->SetTextureStageState( stage, state, val ); +#endif +} + +//Moved to a #define so every instance of this skips unsupported render states at compile time +#define SetSamplerState( _stage, _state, _val ) \ + { \ + if ( (_state != D3DSAMP_NOTSUPPORTED) ) \ + { \ + Assert( !g_pShaderDeviceDx8->IsDeactivated() ); \ + Dx9Device()->SetSamplerState( _stage, _state, _val ); \ + } \ + } + +//Moved to a #define so every instance of this skips unsupported render states at compile time +#define SetRenderState( _state, _val ) \ + { \ + if ( _state != D3DRS_NOTSUPPORTED ) \ + { \ + Assert( !g_pShaderDeviceDx8->IsDeactivated() ); \ + Dx9Device()->SetRenderState( _state, _val ); \ + } \ + } + +#ifdef DX_TO_GL_ABSTRACTION + #define SetRenderStateConstMacro( state, val ) { if ( state != D3DRS_NOTSUPPORTED ) Dx9Device()->SetRenderStateConstInline( state, val ); } +#else + #define SetRenderStateConstMacro( state, val ) SetRenderState( state, val ) +#endif + +#ifdef _WIN32 +#pragma warning( default : 4189 ) +#endif + +//----------------------------------------------------------------------------- +// Methods that actually apply the state +//----------------------------------------------------------------------------- +#ifdef DEBUG_BOARD_STATE + +static bool g_SpewTransitions = false; + +#define UPDATE_BOARD_RENDER_STATE( _d3dState, _state ) \ + { \ + BoardState().m_ ## _state = shaderState.m_ ## _state; \ + if (g_SpewTransitions) \ + { \ + char buf[128]; \ + sprintf( buf, "Apply %s : %d\n", #_d3dState, shaderState.m_ ## _state ); \ + Plat_DebugString(buf); \ + } \ + } + +#define UPDATE_BOARD_TEXTURE_STAGE_STATE( _d3dState, _state, _stage ) \ + { \ + BoardState().m_TextureStage[_stage].m_ ## _state = shaderState.m_TextureStage[_stage].m_ ## _state; \ + if (g_SpewTransitions) \ + { \ + char buf[128]; \ + sprintf( buf, "Apply Tex %s (%d): %d\n", #_d3dState, _stage, shaderState.m_TextureStage[_stage].m_ ## _state ); \ + Plat_DebugString(buf); \ + } \ + } + +#define UPDATE_BOARD_SAMPLER_STATE( _d3dState, _state, _stage ) \ + { \ + BoardState().m_SamplerState[_stage].m_ ## _state = shaderState.m_SamplerState[_stage].m_ ## _state; \ + if (g_SpewTransitions) \ + { \ + char buf[128]; \ + sprintf( buf, "Apply SamplerSate %s (%d): %d\n", #_d3dState, stage, shaderState.m_SamplerState[_stage].m_ ## _state ); \ + Plat_DebugString(buf); \ + } \ + } + +#else + +#define UPDATE_BOARD_RENDER_STATE( _d3dState, _state ) {} +#define UPDATE_BOARD_TEXTURE_STAGE_STATE( _d3dState, _state, _stage ) {} +#define UPDATE_BOARD_SAMPLER_STATE( _d3dState, _state, _stage ) {} + +#endif + + +#define APPLY_RENDER_STATE_FUNC( _d3dState, _state ) \ + void Apply ## _state( const ShadowState_t& shaderState, int arg ) \ + { \ + SetRenderState( _d3dState, shaderState.m_ ## _state ); \ + UPDATE_BOARD_RENDER_STATE( _d3dState, _state ); \ + } + +#define APPLY_TEXTURE_STAGE_STATE_FUNC( _d3dState, _state ) \ + void Apply ## _state( const ShadowState_t& shaderState, int stage ) \ + { \ + SetTextureStageState( stage, _d3dState, shaderState.m_TextureStage[stage].m_ ## _state ); \ + UPDATE_BOARD_TEXTURE_STAGE_STATE( _d3dState, _state, stage ); \ + } + +#define APPLY_SAMPLER_STATE_FUNC( _d3dState, _state ) \ + void Apply ## _state( const ShadowState_t& shaderState, int stage ) \ + { \ + SetSamplerState( stage, _d3dState, shaderState.m_SamplerState[stage].m_ ## _state ); \ + UPDATE_BOARD_SAMPLER_STATE( _d3dState, _state, stage ); \ + } + + +// Special overridden sampler state to turn on Fetch4 on ATI hardware (and 360?) +void ApplyFetch4Enable( const ShadowState_t& shaderState, int stage ) +{ + if ( ShaderAPI()->SupportsFetch4() ) + { + SetSamplerState( stage, ATISAMP_FETCH4, shaderState.m_SamplerState[stage].m_Fetch4Enable ? ATI_FETCH4_ENABLE : ATI_FETCH4_DISABLE ); + } + + UPDATE_BOARD_SAMPLER_STATE( ATISAMP_FETCH4, Fetch4Enable, stage ); +} + +#ifdef DX_TO_GL_ABSTRACTION +void ApplyShadowFilterEnable( const ShadowState_t& shaderState, int stage ) +{ + SetSamplerState( stage, D3DSAMP_SHADOWFILTER, shaderState.m_SamplerState[stage].m_ShadowFilterEnable ); + + UPDATE_BOARD_SAMPLER_STATE( D3DSAMP_SHADOWFILTER, ShadowFilterEnable, stage ); +} +#endif + + +//APPLY_RENDER_STATE_FUNC( D3DRS_ZWRITEENABLE, ZWriteEnable ) +//APPLY_RENDER_STATE_FUNC( D3DRS_COLORWRITEENABLE, ColorWriteEnable ) +APPLY_RENDER_STATE_FUNC( D3DRS_FILLMODE, FillMode ) +APPLY_RENDER_STATE_FUNC( D3DRS_LIGHTING, Lighting ) +APPLY_RENDER_STATE_FUNC( D3DRS_SPECULARENABLE, SpecularEnable ) +APPLY_RENDER_STATE_FUNC( D3DRS_DIFFUSEMATERIALSOURCE, DiffuseMaterialSource ) +APPLY_TEXTURE_STAGE_STATE_FUNC( D3DTSS_TEXCOORDINDEX, TexCoordIndex ) + + +void ApplyZWriteEnable( const ShadowState_t& shaderState, int arg ) +{ + SetRenderStateConstMacro( D3DRS_ZWRITEENABLE, shaderState.m_ZWriteEnable ); +#if defined( _X360 ) + //SetRenderStateConstMacro( D3DRS_HIZWRITEENABLE, shaderState.m_ZWriteEnable ? D3DHIZ_AUTOMATIC : D3DHIZ_DISABLE ); +#endif + + UPDATE_BOARD_RENDER_STATE( D3DRS_ZWRITEENABLE, ZWriteEnable ); +} + +void ApplyColorWriteEnable( const ShadowState_t& shaderState, int arg ) +{ + SetRenderState( D3DRS_COLORWRITEENABLE, shaderState.m_ColorWriteEnable ); + g_pTransitionTable->CurrentState().m_ColorWriteEnable = shaderState.m_ColorWriteEnable; + + UPDATE_BOARD_RENDER_STATE( D3DRS_COLORWRITEENABLE, ColorWriteEnable ); +} + +void ApplySRGBReadEnable( const ShadowState_t& shaderState, int stage ) +{ +# if ( !defined( _X360 ) ) + { + SetSamplerState( stage, D3DSAMP_SRGBTEXTURE, shaderState.m_SamplerState[stage].m_SRGBReadEnable ); + } +# else + { + ShaderAPI()->ApplySRGBReadState( stage, shaderState.m_SamplerState[stage].m_SRGBReadEnable ); + } +# endif + + UPDATE_BOARD_SAMPLER_STATE( D3DSAMP_SRGBTEXTURE, SRGBReadEnable, stage ); +} + + +void ApplySRGBWriteEnable( const ShadowState_t& shadowState, int stageUnused ) +{ + g_pTransitionTable->ApplySRGBWriteEnable( shadowState ); +} + + +void CTransitionTable::ApplySRGBWriteEnable( const ShadowState_t& shaderState ) +{ + // ApplySRGBWriteEnable set to true means that the shader is writing linear values. + if ( CurrentState().m_bLinearColorSpaceFrameBufferEnable ) + { + // The shader had better be writing linear values since we can't convert to gamma here. + // Can't leave this assert here since there are cases where the shader is doing the right thing. + // This is good to test occasionally to make sure that the shaders are doing the right thing. + // Assert( shaderState.m_SRGBWriteEnable ); + + // render target is linear + SetRenderStateConstMacro( D3DRS_SRGBWRITEENABLE, 0 ); + ShaderAPI()->EnabledSRGBWrite( false ); + + // fog isn't fixed-function with linear frame buffers, so don't bother with that here. + } + else + { + // render target is gamma + + // SRGBWrite enable can affect the space in which fog color is defined + if ( HardwareConfig()->NeedsShaderSRGBConversion() ) + { + if ( HardwareConfig()->SupportsPixelShaders_2_b() ) //in 2b supported devices, we never actually enable SRGB writes, but instead handle the conversion in the pixel shader. But we want all other code to be unaware. + { + SetRenderStateConstMacro( D3DRS_SRGBWRITEENABLE, 0 ); + } + else + { + SetRenderStateConstMacro( D3DRS_SRGBWRITEENABLE, shaderState.m_SRGBWriteEnable ); + } + } + else + { + SetRenderStateConstMacro( D3DRS_SRGBWRITEENABLE, shaderState.m_SRGBWriteEnable ); + } + + ShaderAPI()->EnabledSRGBWrite( shaderState.m_SRGBWriteEnable ); + + if ( HardwareConfig()->SpecifiesFogColorInLinearSpace() ) + { + ShaderAPI()->ApplyFogMode( shaderState.m_FogMode, shaderState.m_SRGBWriteEnable, shaderState.m_bDisableFogGammaCorrection ); + } + } + +#ifdef _DEBUG + BoardState().m_SRGBWriteEnable = shaderState.m_SRGBWriteEnable; + if (g_SpewTransitions) + { + char buf[128]; + sprintf( buf, "Apply %s : %d\n", "D3DRS_SRGBWRITEENABLE", shaderState.m_SRGBWriteEnable ); + Plat_DebugString(buf); + } +#endif +} + +void ApplyDisableFogGammaCorrection( const ShadowState_t& shadowState, int stageUnused ) +{ + ShaderAPI()->ApplyFogMode( shadowState.m_FogMode, shadowState.m_SRGBWriteEnable, shadowState.m_bDisableFogGammaCorrection ); + +#ifdef DEBUG_BOARD_STATE + g_pTransitionTable->BoardState().m_bDisableFogGammaCorrection = shadowState.m_bDisableFogGammaCorrection; +#endif +} + + + + +void ApplyDepthTest( const ShadowState_t& state, int stage ) +{ + g_pTransitionTable->ApplyDepthTest( state ); +} + +void CTransitionTable::SetZEnable( D3DZBUFFERTYPE nEnable ) +{ + if (m_CurrentState.m_ZEnable != nEnable ) + { + SetRenderStateConstMacro( D3DRS_ZENABLE, nEnable ); +#if defined( _X360 ) + //SetRenderState( D3DRS_HIZENABLE, nEnable ? D3DHIZ_AUTOMATIC : D3DHIZ_DISABLE ); +#endif + m_CurrentState.m_ZEnable = nEnable; + } +} + +void CTransitionTable::SetZFunc( D3DCMPFUNC nCmpFunc ) +{ + if (m_CurrentState.m_ZFunc != nCmpFunc ) + { + SetRenderStateConstMacro( D3DRS_ZFUNC, nCmpFunc ); + m_CurrentState.m_ZFunc = nCmpFunc; + } +} + +void CTransitionTable::ApplyDepthTest( const ShadowState_t& state ) +{ + SetZEnable( state.m_ZEnable ); + if (state.m_ZEnable != D3DZB_FALSE) + { + SetZFunc( state.m_ZFunc ); + } + if (m_CurrentState.m_ZBias != state.m_ZBias) + { + ShaderAPI()->ApplyZBias( state ); + m_CurrentState.m_ZBias = (PolygonOffsetMode_t) state.m_ZBias; // Cast two bits from m_ZBias + } + +#ifdef DEBUG_BOARD_STATE + // This isn't quite true, but it's necessary for other error checking to work + BoardState().m_ZEnable = state.m_ZEnable; + BoardState().m_ZFunc = state.m_ZFunc; + BoardState().m_ZBias = state.m_ZBias; +#endif +} + +void ApplyAlphaTest( const ShadowState_t& state, int stage ) +{ + g_pTransitionTable->ApplyAlphaTest( state ); +} + +void CTransitionTable::ApplyAlphaTest( const ShadowState_t& state ) +{ + if (m_CurrentState.m_AlphaTestEnable != state.m_AlphaTestEnable) + { + SetRenderStateConstMacro( D3DRS_ALPHATESTENABLE, state.m_AlphaTestEnable ); + m_CurrentState.m_AlphaTestEnable = state.m_AlphaTestEnable; + } + + if (state.m_AlphaTestEnable) + { + // Set the blend state here... + if (m_CurrentState.m_AlphaFunc != state.m_AlphaFunc) + { + SetRenderStateConstMacro( D3DRS_ALPHAFUNC, state.m_AlphaFunc ); + m_CurrentState.m_AlphaFunc = state.m_AlphaFunc; + } + + if (m_CurrentState.m_AlphaRef != state.m_AlphaRef) + { + SetRenderStateConstMacro( D3DRS_ALPHAREF, state.m_AlphaRef ); + m_CurrentState.m_AlphaRef = state.m_AlphaRef; + } + } + +#ifdef DEBUG_BOARD_STATE + // This isn't quite true, but it's necessary for other error checking to work + BoardState().m_AlphaTestEnable = state.m_AlphaTestEnable; + BoardState().m_AlphaFunc = state.m_AlphaFunc; + BoardState().m_AlphaRef = state.m_AlphaRef; +#endif +} + +void ApplyAlphaBlend( const ShadowState_t& state, int stage ) +{ + g_pTransitionTable->ApplyAlphaBlend( state ); +} + +void CTransitionTable::ApplyAlphaBlend( const ShadowState_t& state ) +{ + if (m_CurrentState.m_AlphaBlendEnable != state.m_AlphaBlendEnable) + { + SetRenderStateConstMacro( D3DRS_ALPHABLENDENABLE, state.m_AlphaBlendEnable ); + m_CurrentState.m_AlphaBlendEnable = state.m_AlphaBlendEnable; + } + + if (state.m_AlphaBlendEnable) + { + // Set the blend state here... + if (m_CurrentState.m_SrcBlend != state.m_SrcBlend) + { + SetRenderStateConstMacro( D3DRS_SRCBLEND, state.m_SrcBlend ); + m_CurrentState.m_SrcBlend = state.m_SrcBlend; + } + + if (m_CurrentState.m_DestBlend != state.m_DestBlend) + { + SetRenderStateConstMacro( D3DRS_DESTBLEND, state.m_DestBlend ); + m_CurrentState.m_DestBlend = state.m_DestBlend; + } + + if (m_CurrentState.m_BlendOp != state.m_BlendOp ) + { + SetRenderStateConstMacro( D3DRS_BLENDOP, state.m_BlendOp ); + m_CurrentState.m_BlendOp = state.m_BlendOp; + } + } + +#ifdef DEBUG_BOARD_STATE + // This isn't quite true, but it's necessary for other error checking to work + BoardState().m_AlphaBlendEnable = state.m_AlphaBlendEnable; + BoardState().m_SrcBlend = state.m_SrcBlend; + BoardState().m_DestBlend = state.m_DestBlend; + BoardState().m_BlendOp = state.m_BlendOp; +#endif +} + +void ApplySeparateAlphaBlend( const ShadowState_t& state, int stage ) +{ + g_pTransitionTable->ApplySeparateAlphaBlend( state ); +} + +void CTransitionTable::ApplySeparateAlphaBlend( const ShadowState_t& state ) +{ + if (m_CurrentState.m_SeparateAlphaBlendEnable != state.m_SeparateAlphaBlendEnable) + { + SetRenderStateConstMacro( D3DRS_SEPARATEALPHABLENDENABLE, state.m_SeparateAlphaBlendEnable ); + m_CurrentState.m_SeparateAlphaBlendEnable = state.m_SeparateAlphaBlendEnable; + } + + if (state.m_SeparateAlphaBlendEnable) + { + // Set the blend state here... + if (m_CurrentState.m_SrcBlendAlpha != state.m_SrcBlendAlpha) + { + SetRenderStateConstMacro( D3DRS_SRCBLENDALPHA, state.m_SrcBlendAlpha ); + m_CurrentState.m_SrcBlendAlpha = state.m_SrcBlendAlpha; + } + + if (m_CurrentState.m_DestBlendAlpha != state.m_DestBlendAlpha) + { + SetRenderStateConstMacro( D3DRS_DESTBLENDALPHA, state.m_DestBlendAlpha ); + m_CurrentState.m_DestBlendAlpha = state.m_DestBlendAlpha; + } + + if (m_CurrentState.m_BlendOpAlpha != state.m_BlendOpAlpha ) + { + SetRenderStateConstMacro( D3DRS_BLENDOPALPHA, state.m_BlendOpAlpha ); + m_CurrentState.m_BlendOpAlpha = state.m_BlendOpAlpha; + } + } + +#ifdef DEBUG_BOARD_STATE + // This isn't quite true, but it's necessary for other error checking to work + BoardState().m_SeparateAlphaBlendEnable = state.m_SeparateAlphaBlendEnable; + BoardState().m_SrcBlendAlpha = state.m_SrcBlendAlpha; + BoardState().m_DestBlendAlpha = state.m_DestBlendAlpha; + BoardState().m_BlendOpAlpha = state.m_BlendOpAlpha; +#endif +} + +//----------------------------------------------------------------------------- +// Applies alpha texture op +//----------------------------------------------------------------------------- +void ApplyColorTextureStage( const ShadowState_t& state, int stage ) +{ + g_pTransitionTable->ApplyColorTextureStage( state, stage ); +} + +void ApplyAlphaTextureStage( const ShadowState_t& state, int stage ) +{ + g_pTransitionTable->ApplyAlphaTextureStage( state, stage ); +} + +void CTransitionTable::ApplyColorTextureStage( const ShadowState_t& state, int stage ) +{ + D3DTEXTUREOP op = state.m_TextureStage[stage].m_ColorOp; + int arg1 = state.m_TextureStage[stage].m_ColorArg1; + int arg2 = state.m_TextureStage[stage].m_ColorArg2; + + if (m_CurrentState.m_TextureStage[stage].m_ColorOp != op) + { + SetTextureStageState( stage, D3DTSS_COLOROP, op ); + m_CurrentState.m_TextureStage[stage].m_ColorOp = op; + } + + if (op != D3DTOP_DISABLE) + { + if (m_CurrentState.m_TextureStage[stage].m_ColorArg1 != arg1) + { + SetTextureStageState( stage, D3DTSS_COLORARG1, arg1 ); + m_CurrentState.m_TextureStage[stage].m_ColorArg1 = arg1; + } + if (m_CurrentState.m_TextureStage[stage].m_ColorArg2 != arg2) + { + SetTextureStageState( stage, D3DTSS_COLORARG2, arg2 ); + m_CurrentState.m_TextureStage[stage].m_ColorArg2 = arg2; + } + } + +#ifdef DEBUG_BOARD_STATE + // This isn't quite true, but it's necessary for other error checking to work + BoardState().m_TextureStage[stage].m_ColorOp = op; + BoardState().m_TextureStage[stage].m_ColorArg1 = arg1; + BoardState().m_TextureStage[stage].m_ColorArg2 = arg2; +#endif +} + +void CTransitionTable::ApplyAlphaTextureStage( const ShadowState_t& state, int stage ) +{ + D3DTEXTUREOP op = state.m_TextureStage[stage].m_AlphaOp; + int arg1 = state.m_TextureStage[stage].m_AlphaArg1; + int arg2 = state.m_TextureStage[stage].m_AlphaArg2; + + if (m_CurrentState.m_TextureStage[stage].m_AlphaOp != op) + { + SetTextureStageState( stage, D3DTSS_ALPHAOP, op ); + m_CurrentState.m_TextureStage[stage].m_AlphaOp = op; + } + + if (op != D3DTOP_DISABLE) + { + if (m_CurrentState.m_TextureStage[stage].m_AlphaArg1 != arg1) + { + SetTextureStageState( stage, D3DTSS_ALPHAARG1, arg1 ); + m_CurrentState.m_TextureStage[stage].m_AlphaArg1 = arg1; + } + if (m_CurrentState.m_TextureStage[stage].m_AlphaArg2 != arg2) + { + SetTextureStageState( stage, D3DTSS_ALPHAARG2, arg2 ); + m_CurrentState.m_TextureStage[stage].m_AlphaArg2 = arg2; + } + } + +#ifdef DEBUG_BOARD_STATE + // This isn't quite true, but it's necessary for other error checking to work + BoardState().m_TextureStage[stage].m_AlphaOp = op; + BoardState().m_TextureStage[stage].m_AlphaArg1 = arg1; + BoardState().m_TextureStage[stage].m_AlphaArg2 = arg2; +#endif +} + + +void ApplyActivateFixedFunction( const ShadowState_t& state, int stage ) +{ + int nStageCount = HardwareConfig()->GetTextureStageCount(); + for ( int i = 0; i < nStageCount; ++i ) + { + g_pTransitionTable->ApplyColorTextureStage( state, i ); + g_pTransitionTable->ApplyAlphaTextureStage( state, i ); + } +} + + +//----------------------------------------------------------------------------- +// Enables textures +//----------------------------------------------------------------------------- +void ApplyTextureEnable( const ShadowState_t& state, int stage ) +{ + // This may well enable/disable textures that are already enabled/disabled + // but the ShaderAPI will handle that + int i; + int nSamplerCount = HardwareConfig()->GetSamplerCount(); + for ( i = 0; i < nSamplerCount; ++i ) + { + ShaderAPI()->ApplyTextureEnable( state, i ); + +#ifdef DEBUG_BOARD_STATE + BoardState().m_SamplerState[i].m_TextureEnable = state.m_SamplerState[i].m_TextureEnable; +#endif + } + + // Needed to prevent mat_dxlevel assertions +#ifdef DEBUG_BOARD_STATE + for ( i = nSamplerCount; i < MAX_SAMPLERS; ++i ) + { + BoardState().m_SamplerState[i].m_TextureEnable = false; + } +#endif +} + + +//----------------------------------------------------------------------------- +// All transitions below this point depend on dynamic render state +// FIXME: Eliminate these virtual calls? +//----------------------------------------------------------------------------- +void ApplyCullEnable( const ShadowState_t& state, int arg ) +{ + ShaderAPI()->ApplyCullEnable( state.m_CullEnable ); + +#ifdef DEBUG_BOARD_STATE + BoardState().m_CullEnable = state.m_CullEnable; +#endif +} + +//----------------------------------------------------------------------------- +void ApplyAlphaToCoverage( const ShadowState_t& state, int arg ) +{ + ShaderAPI()->ApplyAlphaToCoverage( state.m_EnableAlphaToCoverage ); + +#ifdef DEBUG_BOARD_STATE + BoardState().m_EnableAlphaToCoverage = state.m_EnableAlphaToCoverage; +#endif +} + +//----------------------------------------------------------------------------- +void ApplyVertexBlendEnable( const ShadowState_t& state, int stage ) +{ + ShaderAPI()->SetVertexBlendState( state.m_VertexBlendEnable ? -1 : 0 ); + +#ifdef DEBUG_BOARD_STATE + BoardState().m_VertexBlendEnable = state.m_VertexBlendEnable; +#endif +} + + +//----------------------------------------------------------------------------- +// Outputs the fog mode string +//----------------------------------------------------------------------------- +#ifdef RECORDING +const char *ShaderFogModeToString( ShaderFogMode_t fogMode ) +{ + switch( fogMode ) + { + case SHADER_FOGMODE_DISABLED: + return "SHADER_FOGMODE_DISABLED"; + case SHADER_FOGMODE_OO_OVERBRIGHT: + return "SHADER_FOGMODE_OO_OVERBRIGHT"; + case SHADER_FOGMODE_BLACK: + return "SHADER_FOGMODE_BLACK"; + case SHADER_FOGMODE_GREY: + return "SHADER_FOGMODE_GREY"; + case SHADER_FOGMODE_FOGCOLOR: + return "SHADER_FOGMODE_FOGCOLOR"; + case SHADER_FOGMODE_WHITE: + return "SHADER_FOGMODE_WHITE"; + case SHADER_FOGMODE_NUMFOGMODES: + return "SHADER_FOGMODE_NUMFOGMODES"; + default: + return "ERROR"; + } +} +#endif + +// Uses GetConfig().overbright and GetSceneFogMode, so +// will have to fix up the state manually when those change. +void ApplyFogMode( const ShadowState_t& state, int arg ) +{ +#ifdef RECORDING + char buf[1024]; + sprintf( buf, "ApplyFogMode( %s )", ShaderFogModeToString( state.m_FogMode ) ); + RECORD_DEBUG_STRING( buf ); +#endif + + ShaderAPI()->ApplyFogMode( state.m_FogMode, state.m_SRGBWriteEnable, state.m_bDisableFogGammaCorrection ); + +#ifdef DEBUG_BOARD_STATE + BoardState().m_FogMode = state.m_FogMode; +#endif +} + + +//----------------------------------------------------------------------------- +// Function tables mapping enum to function +//----------------------------------------------------------------------------- +ApplyStateFunc_t s_pRenderFunctionTable[] = +{ + ApplyDepthTest, + ApplyZWriteEnable, + ApplyColorWriteEnable, + ApplyAlphaTest, + ApplyFillMode, + ApplyLighting, + ApplySpecularEnable, + ApplySRGBWriteEnable, + ApplyAlphaBlend, + ApplySeparateAlphaBlend, + ApplyCullEnable, + ApplyVertexBlendEnable, + ApplyFogMode, + ApplyActivateFixedFunction, + ApplyTextureEnable, // Enables textures on *all* stages + ApplyDiffuseMaterialSource, + ApplyDisableFogGammaCorrection, + ApplyAlphaToCoverage, +}; + +ApplyStateFunc_t s_pTextureFunctionTable[] = +{ + ApplyTexCoordIndex, + ApplySRGBReadEnable, + ApplyFetch4Enable, +#ifdef DX_TO_GL_ABSTRACTION + ApplyShadowFilterEnable, +#endif + // Fixed function states + ApplyColorTextureStage, + ApplyAlphaTextureStage, +}; + + +//----------------------------------------------------------------------------- +// Creates an entry in the state transition table +//----------------------------------------------------------------------------- +inline void CTransitionTable::AddTransition( RenderStateFunc_t func ) +{ + int nElem = m_TransitionOps.AddToTail(); + TransitionOp_t &op = m_TransitionOps[nElem]; + op.m_nInfo.m_bIsTextureCode = false; + op.m_nInfo.m_nOpCode = func; + + // Stats +// ++s_pRenderTransitions[ func ]; +} + +inline void CTransitionTable::AddTextureTransition( TextureStateFunc_t func, int stage ) +{ + int nElem = m_TransitionOps.AddToTail(); + TransitionOp_t &op = m_TransitionOps[nElem]; + op.m_nInfo.m_bIsTextureCode = true; + op.m_nInfo.m_nOpCode = TextureOp( func, stage ); + + // Stats +// ++s_pTextureTransitions[ func ][stage]; +} + +#define ADD_RENDER_STATE_TRANSITION( _state ) \ + if (bForce || (toState.m_ ## _state != fromState.m_ ## _state)) \ + { \ + AddTransition( RENDER_STATE_ ## _state ); \ + ++numOps; \ + } + +#define ADD_TEXTURE_STAGE_STATE_TRANSITION( _stage, _state )\ + if (bForce || (toState.m_TextureStage[_stage].m_ ## _state != fromState.m_TextureStage[_stage].m_ ## _state)) \ + { \ + Assert( _stage < MAX_TEXTURE_STAGES ); \ + AddTextureTransition( TEXTURE_STATE_ ## _state, _stage ); \ + ++numOps; \ + } + +#define ADD_SAMPLER_STATE_TRANSITION( _stage, _state )\ + if (bForce || (toState.m_SamplerState[_stage].m_ ## _state != fromState.m_SamplerState[_stage].m_ ## _state)) \ + { \ + Assert( _stage < MAX_SAMPLERS ); \ + AddTextureTransition( TEXTURE_STATE_ ## _state, _stage ); \ + ++numOps; \ + } + +int CTransitionTable::CreateNormalTransitions( const ShadowState_t& fromState, const ShadowState_t& toState, bool bForce ) +{ + int numOps = 0; + + // Special case for alpha blending to eliminate extra transitions + bool blendEnableDifferent = (toState.m_AlphaBlendEnable != fromState.m_AlphaBlendEnable); + bool srcBlendDifferent = toState.m_AlphaBlendEnable && (toState.m_SrcBlend != fromState.m_SrcBlend); + bool destBlendDifferent = toState.m_AlphaBlendEnable && (toState.m_DestBlend != fromState.m_DestBlend); + bool blendOpDifferent = toState.m_AlphaBlendEnable && ( toState.m_BlendOp != fromState.m_BlendOp ); + if (bForce || blendOpDifferent || blendEnableDifferent || srcBlendDifferent || destBlendDifferent) + { + AddTransition( RENDER_STATE_AlphaBlend ); + ++numOps; + } + + // Shouldn't have m_SeparateAlphaBlendEnable set unless m_AlphaBlendEnable is also set. + Assert ( toState.m_AlphaBlendEnable || !toState.m_SeparateAlphaBlendEnable ); + bool blendSeparateAlphaEnableDifferent = (toState.m_SeparateAlphaBlendEnable != fromState.m_SeparateAlphaBlendEnable); + bool srcBlendAlphaDifferent = toState.m_SeparateAlphaBlendEnable && (toState.m_SrcBlendAlpha != fromState.m_SrcBlendAlpha); + bool destBlendAlphaDifferent = toState.m_SeparateAlphaBlendEnable && (toState.m_DestBlendAlpha != fromState.m_DestBlendAlpha); + bool blendOpAlphaDifferent = toState.m_SeparateAlphaBlendEnable && ( toState.m_BlendOpAlpha != fromState.m_BlendOpAlpha ); + if (bForce || blendOpAlphaDifferent || blendSeparateAlphaEnableDifferent || srcBlendAlphaDifferent || destBlendAlphaDifferent) + { + AddTransition( RENDER_STATE_SeparateAlphaBlend ); + ++numOps; + } + + bool bAlphaTestEnableDifferent = (toState.m_AlphaTestEnable != fromState.m_AlphaTestEnable); + bool bAlphaFuncDifferent = toState.m_AlphaTestEnable && (toState.m_AlphaFunc != fromState.m_AlphaFunc); + bool bAlphaRefDifferent = toState.m_AlphaTestEnable && (toState.m_AlphaRef != fromState.m_AlphaRef); + if (bForce || bAlphaTestEnableDifferent || bAlphaFuncDifferent || bAlphaRefDifferent) + { + AddTransition( RENDER_STATE_AlphaTest ); + ++numOps; + } + + bool bDepthTestEnableDifferent = (toState.m_ZEnable != fromState.m_ZEnable); + bool bDepthFuncDifferent = (toState.m_ZEnable != D3DZB_FALSE) && (toState.m_ZFunc != fromState.m_ZFunc); + bool bDepthBiasDifferent = (toState.m_ZBias != fromState.m_ZBias); + if (bForce || bDepthTestEnableDifferent || bDepthFuncDifferent || bDepthBiasDifferent) + { + AddTransition( RENDER_STATE_DepthTest ); + ++numOps; + } + + if ( bForce || (toState.m_UsingFixedFunction && !fromState.m_UsingFixedFunction) ) + { + AddTransition( RENDER_STATE_ActivateFixedFunction ); + ++numOps; + } + + if ( bForce || (toState.m_bDisableFogGammaCorrection != fromState.m_bDisableFogGammaCorrection) ) + { + AddTransition( RENDER_STATE_DisableFogGammaCorrection ); + ++numOps; + } + + int nStageCount = HardwareConfig()->GetTextureStageCount(); + int i; + for ( i = 0; i < nStageCount; ++i ) + { + // Special case for texture stage ops to eliminate extra transitions + // NOTE: If we're forcing transitions, then ActivateFixedFunction above will take care of all these transitions + if ( !bForce && toState.m_UsingFixedFunction && fromState.m_UsingFixedFunction ) + { + const TextureStageShadowState_t& fromTexture = fromState.m_TextureStage[i]; + const TextureStageShadowState_t& toTexture = toState.m_TextureStage[i]; + + bool fromEnabled = (fromTexture.m_ColorOp != D3DTOP_DISABLE); + bool toEnabled = (toTexture.m_ColorOp != D3DTOP_DISABLE); + if ( fromEnabled || toEnabled ) + { + bool opDifferent = (toTexture.m_ColorOp != fromTexture.m_ColorOp); + bool arg1Different = (toTexture.m_ColorArg1 != fromTexture.m_ColorArg1); + bool arg2Different = (toTexture.m_ColorArg2 != fromTexture.m_ColorArg2); + if (opDifferent || arg1Different || arg2Different ) + { + AddTextureTransition( TEXTURE_STATE_ColorTextureStage, i ); + ++numOps; + } + } + + fromEnabled = (fromTexture.m_AlphaOp != D3DTOP_DISABLE); + toEnabled = (toTexture.m_AlphaOp != D3DTOP_DISABLE); + if ( fromEnabled || toEnabled ) + { + bool opDifferent = (toTexture.m_AlphaOp != fromTexture.m_AlphaOp); + bool arg1Different = (toTexture.m_AlphaArg1 != fromTexture.m_AlphaArg1); + bool arg2Different = (toTexture.m_AlphaArg2 != fromTexture.m_AlphaArg2); + if (opDifferent || arg1Different || arg2Different ) + { + AddTextureTransition( TEXTURE_STATE_AlphaTextureStage, i ); + ++numOps; + } + } + } + + ADD_TEXTURE_STAGE_STATE_TRANSITION( i, TexCoordIndex ); + } + + int nSamplerCount = HardwareConfig()->GetSamplerCount(); + for ( int i = 0; i < nSamplerCount; ++i ) + { + ADD_SAMPLER_STATE_TRANSITION( i, SRGBReadEnable ); + ADD_SAMPLER_STATE_TRANSITION( i, Fetch4Enable ); +#ifdef DX_TO_GL_ABSTRACTION + ADD_SAMPLER_STATE_TRANSITION( i, ShadowFilterEnable ); +#endif + } + + return numOps; +} + +void CTransitionTable::CreateTransitionTableEntry( int to, int from ) +{ + // You added or removed a state to the enums but not to the function table lists! + COMPILE_TIME_ASSERT( sizeof(s_pRenderFunctionTable) == sizeof(ApplyStateFunc_t) * RENDER_STATE_COUNT ); + COMPILE_TIME_ASSERT( sizeof(s_pTextureFunctionTable) == sizeof(ApplyStateFunc_t) * TEXTURE_STATE_COUNT ); + + // If from < 0, that means add *all* transitions into it. + unsigned int firstElem = m_TransitionOps.Count(); + unsigned short numOps = 0; + + const ShadowState_t& toState = m_ShadowStateList[to]; + const ShadowState_t& fromState = (from >= 0) ? m_ShadowStateList[from] : m_ShadowStateList[to]; + bool bForce = (from < 0); + + ADD_RENDER_STATE_TRANSITION( ZWriteEnable ) + ADD_RENDER_STATE_TRANSITION( ColorWriteEnable ) + ADD_RENDER_STATE_TRANSITION( FillMode ) + ADD_RENDER_STATE_TRANSITION( Lighting ) + ADD_RENDER_STATE_TRANSITION( SpecularEnable ) + ADD_RENDER_STATE_TRANSITION( SRGBWriteEnable ) + ADD_RENDER_STATE_TRANSITION( DiffuseMaterialSource ) + + // Some code for the non-trivial transitions + numOps += CreateNormalTransitions( fromState, toState, bForce ); + + // NOTE: From here on down are transitions that depend on dynamic state + // and which can therefore not appear in the state block + ADD_RENDER_STATE_TRANSITION( CullEnable ) + ADD_RENDER_STATE_TRANSITION( EnableAlphaToCoverage ) + ADD_RENDER_STATE_TRANSITION( VertexBlendEnable ) + + // NOTE! : Have to do the extra check for changes in m_UsingFixedFunction + // since d3d fog state is different if you are using fixed function vs. + // using a vsh/psh. + // This code is derived from: ADD_RENDER_STATE_TRANSITION( FogMode ) + // If ADD_RENDER_STATE_TRANSITION ever changes, this needs to be updated! + // This is another reason to try to have very little fixed function in the dx8/dx9 path. + if( bForce || (toState.m_FogMode != fromState.m_FogMode ) || + ( toState.m_UsingFixedFunction != fromState.m_UsingFixedFunction ) ) + { + AddTransition( RENDER_STATE_FogMode ); + ++numOps; + } + + bool bDifferentTexturesEnabled = false; + int nSamplerCount = HardwareConfig()->GetSamplerCount(); + for ( int i = 0; i < nSamplerCount; ++i ) + { + if ( toState.m_SamplerState[i].m_TextureEnable != fromState.m_SamplerState[i].m_TextureEnable ) + { + bDifferentTexturesEnabled = true; + break; + } + } + + if ( bForce || bDifferentTexturesEnabled ) + { + AddTransition( RENDER_STATE_TextureEnable ); + ++numOps; + } + + // Look for identical transition lists, and use those instead... + TransitionList_t& transition = (from >= 0) ? + m_TransitionTable[to][from] : m_DefaultTransition; + Assert( numOps <= 255 ); + transition.m_NumOperations = numOps; + + // This condition can happen, and is valid. It occurs when we snapshot + // state but do not generate a transition function for that state + if (numOps == 0) + { + transition.m_FirstOperation = INVALID_TRANSITION_OP; + return; + } + + // An optimization to try to early out of the identical transition check + // taking advantage of the fact that the matrix is usually diagonal. + unsigned int nFirstTest = INVALID_TRANSITION_OP; + if (from >= 0) + { + TransitionList_t &diagonalList = m_TransitionTable[from][to]; + if ( diagonalList.m_NumOperations == numOps ) + { + nFirstTest = diagonalList.m_FirstOperation; + } + } + + unsigned int identicalListFirstElem = FindIdenticalTransitionList( firstElem, numOps, nFirstTest ); + if (identicalListFirstElem == INVALID_TRANSITION_OP) + { + transition.m_FirstOperation = firstElem; + m_UniqueTransitions.Insert( transition ); + Assert( (int)firstElem + (int)numOps < 16777215 ); + + if( (int)firstElem + (int)numOps >= 16777215 ) + { + Warning("**** WARNING: Transition table overflow. Grab Brian\n"); + } + } + else + { + // Remove the transitions ops we made; use the duplicate copy + transition.m_FirstOperation = identicalListFirstElem; + m_TransitionOps.RemoveMultiple( firstElem, numOps ); + } +} + + +//----------------------------------------------------------------------------- +// Tests a snapshot to see if it can be used +//----------------------------------------------------------------------------- + +#define PERFORM_RENDER_STATE_TRANSITION( _state, _func ) \ + ::Apply ## _func( _state, 0 ); +#define PERFORM_TEXTURE_STAGE_STATE_TRANSITION( _state, _stage, _func ) \ + ::Apply ## _func( _state, _stage ); +#define PERFORM_SAMPLER_STATE_TRANSITION( _state, _stage, _func ) \ + ::Apply ## _func( _state, _stage ); + +bool CTransitionTable::TestShadowState( const ShadowState_t& state, const ShadowShaderState_t &shaderState ) +{ + PERFORM_RENDER_STATE_TRANSITION( state, DepthTest ) + PERFORM_RENDER_STATE_TRANSITION( state, ZWriteEnable ) + PERFORM_RENDER_STATE_TRANSITION( state, ColorWriteEnable ) + PERFORM_RENDER_STATE_TRANSITION( state, AlphaTest ) + PERFORM_RENDER_STATE_TRANSITION( state, FillMode ) + PERFORM_RENDER_STATE_TRANSITION( state, Lighting ) + PERFORM_RENDER_STATE_TRANSITION( state, SpecularEnable ) + PERFORM_RENDER_STATE_TRANSITION( state, SRGBWriteEnable ) + PERFORM_RENDER_STATE_TRANSITION( state, AlphaBlend ) + PERFORM_RENDER_STATE_TRANSITION( state, SeparateAlphaBlend ) + PERFORM_RENDER_STATE_TRANSITION( state, CullEnable ) + PERFORM_RENDER_STATE_TRANSITION( state, AlphaToCoverage ) + PERFORM_RENDER_STATE_TRANSITION( state, VertexBlendEnable ) + PERFORM_RENDER_STATE_TRANSITION( state, FogMode ) + PERFORM_RENDER_STATE_TRANSITION( state, ActivateFixedFunction ) + PERFORM_RENDER_STATE_TRANSITION( state, TextureEnable ) + PERFORM_RENDER_STATE_TRANSITION( state, DiffuseMaterialSource ) + + int i; + int nStageCount = HardwareConfig()->GetTextureStageCount(); + for ( i = 0; i < nStageCount; ++i ) + { + PERFORM_TEXTURE_STAGE_STATE_TRANSITION( state, i, ColorTextureStage ); + PERFORM_TEXTURE_STAGE_STATE_TRANSITION( state, i, AlphaTextureStage ); + PERFORM_TEXTURE_STAGE_STATE_TRANSITION( state, i, TexCoordIndex ); + } + + int nSamplerCount = HardwareConfig()->GetSamplerCount(); + for ( i = 0; i < nSamplerCount; ++i ) + { + PERFORM_SAMPLER_STATE_TRANSITION( state, i, SRGBReadEnable ); + PERFORM_SAMPLER_STATE_TRANSITION( state, i, Fetch4Enable ); +#ifdef DX_TO_GL_ABSTRACTION + PERFORM_SAMPLER_STATE_TRANSITION( state, i, ShadowFilterEnable ); +#endif + } + + // Just make sure we've got a good snapshot + RECORD_COMMAND( DX8_VALIDATE_DEVICE, 0 ); + +#if !defined( _X360 ) + DWORD numPasses; + HRESULT hr = Dx9Device()->ValidateDevice( &numPasses ); + bool ok = !FAILED(hr); +#else + bool ok = true; +#endif + + // Now set the board state to match the default state + ApplyTransition( m_DefaultTransition, m_DefaultStateSnapshot ); + + ShaderManager()->SetVertexShader( shaderState.m_VertexShader ); + ShaderManager()->SetPixelShader( shaderState.m_PixelShader ); + + return ok; +} + +//----------------------------------------------------------------------------- +// Finds identical transition lists and shares them +//----------------------------------------------------------------------------- +unsigned int CTransitionTable::FindIdenticalTransitionList( unsigned int firstElem, + unsigned short numOps, unsigned int nFirstTest ) const +{ + VPROF("CTransitionTable::FindIdenticalTransitionList"); + // As it turns out, this works most of the time + if ( nFirstTest != INVALID_TRANSITION_OP ) + { + const TransitionOp_t *pCurrOp = &m_TransitionOps[firstElem]; + const TransitionOp_t *pTestOp = &m_TransitionOps[nFirstTest]; + if ( !memcmp( pCurrOp, pTestOp, numOps * sizeof(TransitionOp_t) ) ) + return nFirstTest; + } + + // Look for a common list + const TransitionOp_t &op = m_TransitionOps[firstElem]; + + int nCount = m_UniqueTransitions.Count(); + for ( int i = 0; i < nCount; ++i ) + { + const TransitionList_t &list = m_UniqueTransitions[i]; + + // We can early out here because we've sorted the unique transitions + // descending by count + if ( list.m_NumOperations < numOps ) + return INVALID_TRANSITION_OP; + + // If we don't find a match in the first + int nPotentialMatch; + int nLastTest = list.m_FirstOperation + list.m_NumOperations - numOps; + for ( nPotentialMatch = list.m_FirstOperation; nPotentialMatch <= nLastTest; ++nPotentialMatch ) + { + // Find the first match + const TransitionOp_t &testOp = m_TransitionOps[nPotentialMatch]; + if ( testOp.m_nBits == op.m_nBits ) + break; + } + + // No matches found, continue + if ( nPotentialMatch > nLastTest ) + continue; + + // Ok, found a match of the first op, lets see if they all match + if ( numOps == 1 ) + return nPotentialMatch; + + const TransitionOp_t *pCurrOp = &m_TransitionOps[firstElem + 1]; + const TransitionOp_t *pTestOp = &m_TransitionOps[nPotentialMatch + 1]; + if ( !memcmp( pCurrOp, pTestOp, (numOps - 1) * sizeof(TransitionOp_t) ) ) + return nPotentialMatch; + } + return INVALID_TRANSITION_OP; +} + + +//----------------------------------------------------------------------------- +// Create startup snapshot +//----------------------------------------------------------------------------- +void CTransitionTable::TakeDefaultStateSnapshot( ) +{ + if (m_DefaultStateSnapshot == -1) + { + m_DefaultStateSnapshot = TakeSnapshot(); + + // This will create a transition which sets *all* shadowed state + CreateTransitionTableEntry( m_DefaultStateSnapshot, -1 ); + } +} + + +//----------------------------------------------------------------------------- +// Applies the transition list +//----------------------------------------------------------------------------- +void CTransitionTable::ApplyTransitionList( int snapshot, int nFirstOp, int nOpCount ) +{ + VPROF("CTransitionTable::ApplyTransitionList"); + // Don't bother if there's nothing to do + if (nOpCount > 0) + { + // Trying to avoid function overhead here + ShadowState_t& shadowState = m_ShadowStateList[snapshot]; + TransitionOp_t* pTransitionOp = &m_TransitionOps[nFirstOp]; + + for (int i = 0; i < nOpCount; ++i ) + { + // invoke the transition method + if ( pTransitionOp->m_nInfo.m_bIsTextureCode ) + { + TextureStateFunc_t code; + int nStage; + GetTextureOp( pTransitionOp->m_nInfo.m_nOpCode, &code, &nStage ); + (*s_pTextureFunctionTable[code])( shadowState, nStage ); + } + else + { + (*s_pRenderFunctionTable[pTransitionOp->m_nInfo.m_nOpCode])( shadowState, 0 ); + } + ++pTransitionOp; + } + } +} + + +//----------------------------------------------------------------------------- +// Apply startup snapshot +//----------------------------------------------------------------------------- +#ifdef _WIN32 +#pragma warning( disable : 4189 ) +#endif + +void CTransitionTable::ApplyTransition( TransitionList_t& list, int snapshot ) +{ + VPROF("CTransitionTable::ApplyTransition"); + if ( g_pShaderDeviceDx8->IsDeactivated() ) + return; + + // Transition lists when using state blocks have 2 parts: the first + // is the stateblock part, which is states that are not related to + // dynamic state at all; followed by states that *are* affected by dynamic state + int nFirstOp = list.m_FirstOperation; + int nOpCount = list.m_NumOperations; + + ApplyTransitionList( snapshot, nFirstOp, nOpCount ); + + // Semi-hacky code to override what the transitions are doing + PerformShadowStateOverrides(); + + // Set the current snapshot id + m_CurrentShadowId = snapshot; + +#ifdef DEBUG_BOARD_STATE + // Copy over the board states that aren't explicitly in the transition table + // so the assertion works... + + int i; + int nSamplerCount = HardwareConfig()->GetSamplerCount(); + for ( i = nSamplerCount; i < MAX_SAMPLERS; ++i ) + { + m_BoardState.m_SamplerState[i].m_TextureEnable = + CurrentShadowState()->m_SamplerState[i].m_TextureEnable; + } + + int nTextureStageCount = HardwareConfig()->GetTextureStageCount(); + for ( i = nTextureStageCount; i < MAX_TEXTURE_STAGES; ++i ) + { + memcpy( &m_BoardState.m_TextureStage[i], &CurrentShadowState()->m_TextureStage[i], sizeof(TextureStageShadowState_t) ); + } + m_BoardState.m_UsingFixedFunction = CurrentShadowState()->m_UsingFixedFunction; + + // State blocks bypass the code that sets the board state +#ifdef _DEBUG + // NOTE: A memcmp here isn't enough since we don't set alpha args in cases where the op is nothing. + // Assert( !memcmp( &m_BoardState, &CurrentShadowState(), sizeof(m_BoardState) ) ); + const ShadowState_t &testState1 = *CurrentShadowState(); + ShadowState_t testState2 = m_BoardState; + + if ( testState1.m_ZEnable == D3DZB_FALSE ) + { + testState2.m_ZBias = testState1.m_ZBias; + testState2.m_ZFunc = testState1.m_ZFunc; + } + + if ( !testState1.m_AlphaTestEnable ) + { + testState2.m_AlphaRef = testState1.m_AlphaRef; + testState2.m_AlphaFunc = testState1.m_AlphaFunc; + } + for( i = 0; i < nTextureStageCount; i++ ) + { + if ( !testState1.m_UsingFixedFunction ) + { + testState2.m_TextureStage[i].m_ColorOp = testState1.m_TextureStage[i].m_ColorOp; + testState2.m_TextureStage[i].m_ColorArg1 = testState1.m_TextureStage[i].m_ColorArg1; + testState2.m_TextureStage[i].m_ColorArg2 = testState1.m_TextureStage[i].m_ColorArg2; + testState2.m_TextureStage[i].m_AlphaOp = testState1.m_TextureStage[i].m_AlphaOp; + testState2.m_TextureStage[i].m_AlphaArg1 = testState1.m_TextureStage[i].m_AlphaArg1; + testState2.m_TextureStage[i].m_AlphaArg2 = testState1.m_TextureStage[i].m_AlphaArg2; + } + else + { + if ( testState1.m_TextureStage[i].m_ColorOp == D3DTOP_DISABLE ) + { + testState2.m_TextureStage[i].m_ColorArg1 = testState1.m_TextureStage[i].m_ColorArg1; + testState2.m_TextureStage[i].m_ColorArg2 = testState1.m_TextureStage[i].m_ColorArg2; + } + if ( testState1.m_TextureStage[i].m_AlphaOp == D3DTOP_DISABLE ) + { + testState2.m_TextureStage[i].m_AlphaArg1 = testState1.m_TextureStage[i].m_AlphaArg1; + testState2.m_TextureStage[i].m_AlphaArg2 = testState1.m_TextureStage[i].m_AlphaArg2; + } + } + } + + Assert( !memcmp( &testState1, &testState2, sizeof( testState1 ) ) ); +#endif +#endif +} + +#ifdef _WIN32 +#pragma warning( default : 4189 ) +#endif + +//----------------------------------------------------------------------------- +// Takes a snapshot, hooks it into the material +//----------------------------------------------------------------------------- +StateSnapshot_t CTransitionTable::TakeSnapshot( ) +{ + // Do any final computation of the shadow state + ShaderShadow()->ComputeAggregateShadowState(); + + // Get the current snapshot + const ShadowState_t& currentState = ShaderShadow()->GetShadowState(); + + // Create a new snapshot + ShadowStateId_t shadowStateId = FindShadowState( currentState ); + if (shadowStateId == -1) + { + // Create entry in state transition table + shadowStateId = CreateShadowState( currentState ); + + // Now create new transition entries + for (int to = 0; to < shadowStateId; ++to) + { + CreateTransitionTableEntry( to, shadowStateId ); + } + + for (int from = 0; from < shadowStateId; ++from) + { + CreateTransitionTableEntry( shadowStateId, from ); + } + } + + const ShadowShaderState_t& currentShaderState = ShaderShadow()->GetShadowShaderState(); + StateSnapshot_t snapshotId = FindStateSnapshot( shadowStateId, currentShaderState ); + if (snapshotId == -1) + { + // Create entry in state transition table + snapshotId = CreateStateSnapshot( shadowStateId, currentShaderState ); + } + + return snapshotId; +} + + +//----------------------------------------------------------------------------- +// Apply shader state (stuff that doesn't lie in the transition table) +//----------------------------------------------------------------------------- +void CTransitionTable::ApplyShaderState( const ShadowState_t &shadowState, const ShadowShaderState_t &shaderState ) +{ + VPROF("CTransitionTable::ApplyShaderState"); + // Don't bother testing against the current state because there + // could well be dynamic state modifiers affecting this too.... + if ( !shadowState.m_UsingFixedFunction ) + { + // FIXME: Improve early-binding of vertex shader index + ShaderManager()->SetVertexShader( shaderState.m_VertexShader ); + ShaderManager()->SetPixelShader( shaderState.m_PixelShader ); + +#ifdef DEBUG_BOARD_STATE + BoardShaderState().m_VertexShader = shaderState.m_VertexShader; + BoardShaderState().m_PixelShader = shaderState.m_PixelShader; + BoardShaderState().m_nStaticVshIndex = shaderState.m_nStaticVshIndex; + BoardShaderState().m_nStaticPshIndex = shaderState.m_nStaticPshIndex; +#endif + } + else + { + ShaderManager()->SetVertexShader( INVALID_SHADER ); + ShaderManager()->SetPixelShader( INVALID_SHADER ); +#if defined( _X360 ) + // no fixed function support + Assert( 0 ); +#endif + +#ifdef DEBUG_BOARD_STATE + BoardShaderState().m_VertexShader = INVALID_SHADER; + BoardShaderState().m_PixelShader = INVALID_SHADER; + BoardShaderState().m_nStaticVshIndex = 0; + BoardShaderState().m_nStaticPshIndex = 0; +#endif + } +} + +//----------------------------------------------------------------------------- +// Makes the board state match the snapshot +//----------------------------------------------------------------------------- +void CTransitionTable::UseSnapshot( StateSnapshot_t snapshotId ) +{ + VPROF("CTransitionTable::UseSnapshot"); + ShadowStateId_t id = m_SnapshotList[snapshotId].m_ShadowStateId; + if (m_CurrentSnapshotId != snapshotId) + { + // First apply things that are in the transition table + if ( m_CurrentShadowId != id ) + { + TransitionList_t& transition = m_TransitionTable[id][m_CurrentShadowId]; + ApplyTransition( transition, id ); + } + + // NOTE: There is an opportunity here to set non-dynamic state that we don't + // store in the transition list if we ever need it. + + m_CurrentSnapshotId = snapshotId; + } + + // NOTE: This occurs regardless of whether the snapshot changed because it depends + // on dynamic state (namely, the dynamic vertex + pixel shader index) + // Followed by things that are not + ApplyShaderState( m_ShadowStateList[id], m_SnapshotList[snapshotId].m_ShaderState ); + +#ifdef _DEBUG + // NOTE: We can't ship with this active because mod makers may well violate this rule + // We don't want no stinking fixed-function on hardware that has vertex and pixel shaders. . + // This could cause a serious perf hit. + if( HardwareConfig()->SupportsVertexAndPixelShaders() ) + { +// Assert( !CurrentShadowState().m_UsingFixedFunction ); + } +#endif +} + + +//----------------------------------------------------------------------------- +// Cause the board to match the default state snapshot +//----------------------------------------------------------------------------- +void CTransitionTable::UseDefaultState( ) +{ + VPROF("CTransitionTable::UseDefaultState"); + // Need to blat these out because they are tested during transitions + m_CurrentState.m_AlphaBlendEnable = false; + m_CurrentState.m_SrcBlend = D3DBLEND_ONE; + m_CurrentState.m_DestBlend = D3DBLEND_ZERO; + m_CurrentState.m_BlendOp = D3DBLENDOP_ADD; + SetRenderStateConstMacro( D3DRS_ALPHABLENDENABLE, m_CurrentState.m_AlphaBlendEnable ); + SetRenderStateConstMacro( D3DRS_SRCBLEND, m_CurrentState.m_SrcBlend ); + SetRenderStateConstMacro( D3DRS_DESTBLEND, m_CurrentState.m_DestBlend ); + SetRenderStateConstMacro( D3DRS_BLENDOP, m_CurrentState.m_BlendOp ); + + m_CurrentState.m_SeparateAlphaBlendEnable = false; + m_CurrentState.m_SrcBlendAlpha = D3DBLEND_ONE; + m_CurrentState.m_DestBlendAlpha = D3DBLEND_ZERO; + m_CurrentState.m_BlendOpAlpha = D3DBLENDOP_ADD; + SetRenderStateConstMacro( D3DRS_SEPARATEALPHABLENDENABLE, m_CurrentState.m_SeparateAlphaBlendEnable ); + SetRenderStateConstMacro( D3DRS_SRCBLENDALPHA, m_CurrentState.m_SrcBlendAlpha ); + SetRenderStateConstMacro( D3DRS_DESTBLENDALPHA, m_CurrentState.m_DestBlendAlpha ); + SetRenderStateConstMacro( D3DRS_BLENDOPALPHA, m_CurrentState.m_BlendOpAlpha ); + + m_CurrentState.m_ZEnable = D3DZB_TRUE; + m_CurrentState.m_ZFunc = D3DCMP_LESSEQUAL; + m_CurrentState.m_ZBias = SHADER_POLYOFFSET_DISABLE; + SetRenderStateConstMacro( D3DRS_ZENABLE, m_CurrentState.m_ZEnable ); +#if defined( _X360 ) + //SetRenderStateConstMacro( D3DRS_HIZENABLE, m_CurrentState.m_ZEnable ? D3DHIZ_AUTOMATIC : D3DHIZ_DISABLE ); +#endif + SetRenderStateConstMacro( D3DRS_ZFUNC, m_CurrentState.m_ZFunc ); + + m_CurrentState.m_AlphaTestEnable = false; + m_CurrentState.m_AlphaFunc = D3DCMP_GREATEREQUAL; + m_CurrentState.m_AlphaRef = 0; + SetRenderStateConstMacro( D3DRS_ALPHATESTENABLE, m_CurrentState.m_AlphaTestEnable ); + SetRenderStateConstMacro( D3DRS_ALPHAFUNC, m_CurrentState.m_AlphaFunc ); + SetRenderStateConstMacro( D3DRS_ALPHAREF, m_CurrentState.m_AlphaRef ); + + int nTextureStages = ShaderAPI()->GetActualTextureStageCount(); + for ( int i = 0; i < nTextureStages; ++i) + { + TextureStage(i).m_ColorOp = D3DTOP_DISABLE; + TextureStage(i).m_ColorArg1 = D3DTA_TEXTURE; + TextureStage(i).m_ColorArg2 = (i == 0) ? D3DTA_DIFFUSE : D3DTA_CURRENT; + TextureStage(i).m_AlphaOp = D3DTOP_DISABLE; + TextureStage(i).m_AlphaArg1 = D3DTA_TEXTURE; + TextureStage(i).m_AlphaArg2 = (i == 0) ? D3DTA_DIFFUSE : D3DTA_CURRENT; + + SetTextureStageState( i, D3DTSS_COLOROP, TextureStage(i).m_ColorOp ); + SetTextureStageState( i, D3DTSS_COLORARG1, TextureStage(i).m_ColorArg1 ); + SetTextureStageState( i, D3DTSS_COLORARG2, TextureStage(i).m_ColorArg2 ); + SetTextureStageState( i, D3DTSS_ALPHAOP, TextureStage(i).m_AlphaOp ); + SetTextureStageState( i, D3DTSS_ALPHAARG1, TextureStage(i).m_AlphaArg1 ); + SetTextureStageState( i, D3DTSS_ALPHAARG2, TextureStage(i).m_AlphaArg2 ); + } + + int nSamplerCount = ShaderAPI()->GetActualSamplerCount(); + for ( int i = 0; i < nSamplerCount; ++i) + { + SetSamplerState( i, D3DSAMP_SRGBTEXTURE, SamplerState(i).m_SRGBReadEnable ); + + // Set default Fetch4 state on parts which support it + if ( ShaderAPI()->SupportsFetch4() ) + { + SetSamplerState( i, ATISAMP_FETCH4, SamplerState(i).m_Fetch4Enable ? ATI_FETCH4_ENABLE : ATI_FETCH4_DISABLE ); + } + +#ifdef DX_TO_GL_ABSTRACTION + SetSamplerState( i, D3DSAMP_SHADOWFILTER, SamplerState(i).m_ShadowFilterEnable ); +#endif + } + + // Disable z overrides... + m_CurrentState.m_bOverrideDepthEnable = false; + m_CurrentState.m_bOverrideAlphaWriteEnable = false; + m_CurrentState.m_bOverrideColorWriteEnable = false; + m_CurrentState.m_ForceDepthFuncEquals = false; + m_CurrentState.m_bLinearColorSpaceFrameBufferEnable = false; + ApplyTransition( m_DefaultTransition, m_DefaultStateSnapshot ); + + ShaderManager()->SetVertexShader( INVALID_SHADER ); + ShaderManager()->SetPixelShader( INVALID_SHADER ); + + m_CurrentSnapshotId = -1; +} + + +//----------------------------------------------------------------------------- +// Snapshotted state overrides +//----------------------------------------------------------------------------- +void CTransitionTable::ForceDepthFuncEquals( bool bEnable ) +{ + if( bEnable != m_CurrentState.m_ForceDepthFuncEquals ) + { + // Do this so that we can call this from within the rendering code + // See OverrideDepthEnable + PerformShadowStateOverrides for a version + // that isn't expected to be called from within rendering code + if( !ShaderAPI()->IsRenderingMesh() ) + { + ShaderAPI()->FlushBufferedPrimitives(); + } + + m_CurrentState.m_ForceDepthFuncEquals = bEnable; + + if( bEnable ) + { + SetZFunc( D3DCMP_EQUAL ); + } + else + { + if ( CurrentShadowState() ) + { + SetZFunc( CurrentShadowState()->m_ZFunc ); + } + } + } +} + +void CTransitionTable::OverrideDepthEnable( bool bEnable, bool bDepthEnable ) +{ + if ( bEnable != m_CurrentState.m_bOverrideDepthEnable ) + { + ShaderAPI()->FlushBufferedPrimitives(); + m_CurrentState.m_bOverrideDepthEnable = bEnable; + m_CurrentState.m_OverrideZWriteEnable = bDepthEnable ? D3DZB_TRUE : D3DZB_FALSE; + + if ( m_CurrentState.m_bOverrideDepthEnable ) + { + SetZEnable( D3DZB_TRUE ); + SetRenderStateConstMacro( D3DRS_ZWRITEENABLE, m_CurrentState.m_OverrideZWriteEnable ); +#if defined( _X360 ) + //SetRenderStateConstMacro( D3DRS_HIZWRITEENABLE, m_CurrentState.m_OverrideZWriteEnable ? D3DHIZ_AUTOMATIC : D3DHIZ_DISABLE ); +#endif + } + else + { + if ( CurrentShadowState() ) + { + SetZEnable( CurrentShadowState()->m_ZEnable ); + SetRenderStateConstMacro( D3DRS_ZWRITEENABLE, CurrentShadowState()->m_ZWriteEnable ); +#if defined( _X360 ) + //SetRenderStateConstMacro( D3DRS_HIZWRITEENABLE, CurrentShadowState()->m_ZWriteEnable ? D3DHIZ_AUTOMATIC : D3DHIZ_DISABLE ); +#endif + } + } + } +} + +void CTransitionTable::OverrideAlphaWriteEnable( bool bOverrideEnable, bool bAlphaWriteEnable ) +{ + if ( bOverrideEnable != m_CurrentState.m_bOverrideAlphaWriteEnable ) + { + ShaderAPI()->FlushBufferedPrimitives(); + m_CurrentState.m_bOverrideAlphaWriteEnable = bOverrideEnable; + m_CurrentState.m_bOverriddenAlphaWriteValue = bAlphaWriteEnable; + + DWORD dwSetValue = m_CurrentState.m_ColorWriteEnable; + if ( m_CurrentState.m_bOverrideAlphaWriteEnable ) + { + if( m_CurrentState.m_bOverriddenAlphaWriteValue ) + { + dwSetValue |= D3DCOLORWRITEENABLE_ALPHA; + } + else + { + dwSetValue &= ~D3DCOLORWRITEENABLE_ALPHA; + } + } + else + { + if ( CurrentShadowState() ) + { + //probably being paranoid, but only copy the alpha flag from the shadow state + dwSetValue &= ~D3DCOLORWRITEENABLE_ALPHA; + dwSetValue |= CurrentShadowState()->m_ColorWriteEnable & D3DCOLORWRITEENABLE_ALPHA; + } + } + + if( dwSetValue != m_CurrentState.m_ColorWriteEnable ) + { + m_CurrentState.m_ColorWriteEnable = dwSetValue; + SetRenderState( D3DRS_COLORWRITEENABLE, m_CurrentState.m_ColorWriteEnable ); + } + } +} + +void CTransitionTable::OverrideColorWriteEnable( bool bOverrideEnable, bool bColorWriteEnable ) +{ + if ( bOverrideEnable != m_CurrentState.m_bOverrideColorWriteEnable ) + { + ShaderAPI()->FlushBufferedPrimitives(); + m_CurrentState.m_bOverrideColorWriteEnable = bOverrideEnable; + m_CurrentState.m_bOverriddenColorWriteValue = bColorWriteEnable; + + DWORD dwSetValue = m_CurrentState.m_ColorWriteEnable; + if ( m_CurrentState.m_bOverrideColorWriteEnable ) + { + if( m_CurrentState.m_bOverriddenColorWriteValue ) + { + dwSetValue |= (D3DCOLORWRITEENABLE_RED | D3DCOLORWRITEENABLE_GREEN | D3DCOLORWRITEENABLE_BLUE); + } + else + { + dwSetValue &= ~(D3DCOLORWRITEENABLE_RED | D3DCOLORWRITEENABLE_GREEN | D3DCOLORWRITEENABLE_BLUE); + } + } + else + { + if ( CurrentShadowState() ) + { + //probably being paranoid, but only copy the alpha flag from the shadow state + dwSetValue &= ~(D3DCOLORWRITEENABLE_RED | D3DCOLORWRITEENABLE_GREEN | D3DCOLORWRITEENABLE_BLUE); + dwSetValue |= CurrentShadowState()->m_ColorWriteEnable & (D3DCOLORWRITEENABLE_RED | D3DCOLORWRITEENABLE_GREEN | D3DCOLORWRITEENABLE_BLUE); + } + } + + if( dwSetValue != m_CurrentState.m_ColorWriteEnable ) + { + m_CurrentState.m_ColorWriteEnable = dwSetValue; + SetRenderState( D3DRS_COLORWRITEENABLE, m_CurrentState.m_ColorWriteEnable ); + } + } +} + +void CTransitionTable::EnableLinearColorSpaceFrameBuffer( bool bEnable ) +{ + if ( m_CurrentState.m_bLinearColorSpaceFrameBufferEnable != bEnable && CurrentShadowState() ) + { + ShaderAPI()->FlushBufferedPrimitives(); + m_CurrentState.m_bLinearColorSpaceFrameBufferEnable = bEnable; + ApplySRGBWriteEnable( *CurrentShadowState() ); + } +} + +//----------------------------------------------------------------------------- +// Perform state block overrides +//----------------------------------------------------------------------------- +void CTransitionTable::PerformShadowStateOverrides( ) +{ + VPROF("CTransitionTable::PerformShadowStateOverrides"); + // Deal with funky overrides here, because the state blocks can't... + if ( m_CurrentState.m_ForceDepthFuncEquals ) + { + SetZFunc( D3DCMP_EQUAL ); + } + + if ( m_CurrentState.m_bOverrideDepthEnable ) + { + SetZEnable( D3DZB_TRUE ); + SetRenderStateConstMacro( D3DRS_ZWRITEENABLE, m_CurrentState.m_OverrideZWriteEnable ); +#if defined( _X360 ) + //SetRenderStateConstMacro( D3DRS_HIZWRITEENABLE, m_CurrentState.m_OverrideZWriteEnable ? D3DHIZ_AUTOMATIC : D3DHIZ_DISABLE ); +#endif + } + + if ( m_CurrentState.m_bOverrideAlphaWriteEnable ) + { + DWORD dwSetValue = m_CurrentState.m_ColorWriteEnable & ~D3DCOLORWRITEENABLE_ALPHA; + dwSetValue |= m_CurrentState.m_bOverriddenAlphaWriteValue ? D3DCOLORWRITEENABLE_ALPHA : 0; + if ( dwSetValue != m_CurrentState.m_ColorWriteEnable ) + { + m_CurrentState.m_ColorWriteEnable = dwSetValue; + SetRenderState( D3DRS_COLORWRITEENABLE, m_CurrentState.m_ColorWriteEnable ); + } + } + + if ( m_CurrentState.m_bOverrideColorWriteEnable ) + { + DWORD dwSetValue = m_CurrentState.m_ColorWriteEnable & ~(D3DCOLORWRITEENABLE_RED | D3DCOLORWRITEENABLE_GREEN | D3DCOLORWRITEENABLE_BLUE); + dwSetValue |= m_CurrentState.m_bOverriddenColorWriteValue ? (D3DCOLORWRITEENABLE_RED | D3DCOLORWRITEENABLE_GREEN | D3DCOLORWRITEENABLE_BLUE) : 0; + if ( dwSetValue != m_CurrentState.m_ColorWriteEnable ) + { + m_CurrentState.m_ColorWriteEnable = dwSetValue; + SetRenderState( D3DRS_COLORWRITEENABLE, m_CurrentState.m_ColorWriteEnable ); + } + } +} diff --git a/materialsystem/shaderapidx9/TransitionTable.h b/materialsystem/shaderapidx9/TransitionTable.h new file mode 100644 index 0000000..730943b --- /dev/null +++ b/materialsystem/shaderapidx9/TransitionTable.h @@ -0,0 +1,407 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +// +//=============================================================================// + +#ifndef TRANSITION_TABLE_H +#define TRANSITION_TABLE_H + +#ifdef _WIN32 +#pragma once +#endif + +#include "utlvector.h" +#include "shadershadowdx8.h" +#include "UtlSortVector.h" +#include "checksum_crc.h" +#include "shaderapi/ishaderapi.h" + +// Required for DEBUG_BOARD_STATE +#include "shaderapidx8_global.h" + + +//----------------------------------------------------------------------------- +// Forward declarations +//----------------------------------------------------------------------------- +struct IDirect3DStateBlock9; +//----------------------------------------------------------------------------- +// Enumeration for ApplyStateFunc_ts +//----------------------------------------------------------------------------- +// Any function that does not require a texture stage +// NOTE: If you change this, change the function table s_pRenderFunctionTable[] below!! +enum RenderStateFunc_t +{ + RENDER_STATE_DepthTest = 0, + RENDER_STATE_ZWriteEnable, + RENDER_STATE_ColorWriteEnable, + RENDER_STATE_AlphaTest, + RENDER_STATE_FillMode, + RENDER_STATE_Lighting, + RENDER_STATE_SpecularEnable, + RENDER_STATE_SRGBWriteEnable, + RENDER_STATE_AlphaBlend, + RENDER_STATE_SeparateAlphaBlend, + RENDER_STATE_CullEnable, + RENDER_STATE_VertexBlendEnable, + RENDER_STATE_FogMode, + RENDER_STATE_ActivateFixedFunction, + RENDER_STATE_TextureEnable, + RENDER_STATE_DiffuseMaterialSource, + RENDER_STATE_DisableFogGammaCorrection, + RENDER_STATE_EnableAlphaToCoverage, + + RENDER_STATE_COUNT, +}; + + +// Any function that requires a texture stage +// NOTE: If you change this, change the function table s_pTextureFunctionTable[] below!! +enum TextureStateFunc_t +{ + TEXTURE_STATE_TexCoordIndex = 0, + TEXTURE_STATE_SRGBReadEnable, + TEXTURE_STATE_Fetch4Enable, +#ifdef DX_TO_GL_ABSTRACTION + TEXTURE_STATE_ShadowFilterEnable, +#endif + // Fixed function states + TEXTURE_STATE_ColorTextureStage, + TEXTURE_STATE_AlphaTextureStage, + TEXTURE_STATE_COUNT +}; + + +//----------------------------------------------------------------------------- +// Types related to transition table entries +//----------------------------------------------------------------------------- +typedef void (*ApplyStateFunc_t)( const ShadowState_t& shadowState, int arg ); + + +//----------------------------------------------------------------------------- +// The DX8 implementation of the transition table +//----------------------------------------------------------------------------- +class CTransitionTable +{ +public: + struct CurrentTextureStageState_t + { + D3DTEXTUREOP m_ColorOp; + int m_ColorArg1; + int m_ColorArg2; + D3DTEXTUREOP m_AlphaOp; + int m_AlphaArg1; + int m_AlphaArg2; + }; + struct CurrentSamplerState_t + { + bool m_SRGBReadEnable; + bool m_Fetch4Enable; + bool m_ShadowFilterEnable; + }; + struct CurrentState_t + { + // Everything in this 'CurrentState' structure is a state whose value we don't care about + // under certain circumstances, (which therefore can diverge from the shadow state), + // or states which we override in the dynamic pass. + + // Alpha state + bool m_AlphaBlendEnable; + D3DBLEND m_SrcBlend; + D3DBLEND m_DestBlend; + D3DBLENDOP m_BlendOp; + + // GR - Separate alpha state + bool m_SeparateAlphaBlendEnable; + D3DBLEND m_SrcBlendAlpha; + D3DBLEND m_DestBlendAlpha; + D3DBLENDOP m_BlendOpAlpha; + + // Depth testing states + D3DZBUFFERTYPE m_ZEnable; + D3DCMPFUNC m_ZFunc; + PolygonOffsetMode_t m_ZBias; + + // Alpha testing states + bool m_AlphaTestEnable; + D3DCMPFUNC m_AlphaFunc; + int m_AlphaRef; + + bool m_ForceDepthFuncEquals; + bool m_bOverrideDepthEnable; + D3DZBUFFERTYPE m_OverrideZWriteEnable; + + bool m_bOverrideAlphaWriteEnable; + bool m_bOverriddenAlphaWriteValue; + bool m_bOverrideColorWriteEnable; + bool m_bOverriddenColorWriteValue; + DWORD m_ColorWriteEnable; + + bool m_bLinearColorSpaceFrameBufferEnable; + + bool m_StencilEnable; + D3DCMPFUNC m_StencilFunc; + int m_StencilRef; + int m_StencilMask; + DWORD m_StencilFail; + DWORD m_StencilZFail; + DWORD m_StencilPass; + int m_StencilWriteMask; + + // Texture stage state + CurrentTextureStageState_t m_TextureStage[MAX_TEXTURE_STAGES]; + CurrentSamplerState_t m_SamplerState[MAX_SAMPLERS]; + }; + +public: + // constructor, destructor + CTransitionTable( ); + virtual ~CTransitionTable(); + + // Initialization, shutdown + bool Init( ); + void Shutdown( ); + + // Resets the snapshots... + void Reset(); + + // Takes a snapshot + StateSnapshot_t TakeSnapshot( ); + + // Take startup snapshot + void TakeDefaultStateSnapshot( ); + + // Makes the board state match the snapshot + void UseSnapshot( StateSnapshot_t snapshotId ); + + // Cause the board to match the default state snapshot + void UseDefaultState(); + + // Snapshotted state overrides + void ForceDepthFuncEquals( bool bEnable ); + void OverrideDepthEnable( bool bEnable, bool bDepthEnable ); + void OverrideAlphaWriteEnable( bool bOverrideEnable, bool bAlphaWriteEnable ); + void OverrideColorWriteEnable( bool bOverrideEnable, bool bColorWriteEnable ); + void EnableLinearColorSpaceFrameBuffer( bool bEnable ); + + // Returns a particular snapshot + const ShadowState_t &GetSnapshot( StateSnapshot_t snapshotId ) const; + const ShadowShaderState_t &GetSnapshotShader( StateSnapshot_t snapshotId ) const; + + // Gets the current shadow state + const ShadowState_t *CurrentShadowState() const; + const ShadowShaderState_t *CurrentShadowShaderState() const; + + // Return the current shapshot + int CurrentSnapshot() const { return m_CurrentSnapshotId; } + + CurrentState_t& CurrentState() { return m_CurrentState; } + +#ifdef DEBUG_BOARD_STATE + ShadowState_t& BoardState() { return m_BoardState; } + ShadowShaderState_t& BoardShaderState() { return m_BoardShaderState; } +#endif + + // The following are meant to be used by the transition table only +public: + // Applies alpha blending + void ApplyAlphaBlend( const ShadowState_t& state ); + // GR - separate alpha blend + void ApplySeparateAlphaBlend( const ShadowState_t& state ); + void ApplyAlphaTest( const ShadowState_t& state ); + void ApplyDepthTest( const ShadowState_t& state ); + + // Applies alpha texture op + void ApplyColorTextureStage( const ShadowState_t& state, int stage ); + void ApplyAlphaTextureStage( const ShadowState_t& state, int stage ); + + void ApplySRGBWriteEnable( const ShadowState_t& state ); +private: + enum + { + INVALID_TRANSITION_OP = 0xFFFFFF + }; + + typedef short ShadowStateId_t; + + // For the transition table + struct TransitionList_t + { + unsigned int m_FirstOperation : 24; + unsigned int m_NumOperations : 8; + }; + + union TransitionOp_t + { + unsigned char m_nBits; + struct + { + unsigned char m_nOpCode : 7; + unsigned char m_bIsTextureCode : 1; + } m_nInfo; + }; + + struct SnapshotShaderState_t + { + ShadowShaderState_t m_ShaderState; + ShadowStateId_t m_ShadowStateId; + unsigned short m_nReserved; // Pad to 2 ints + unsigned int m_nReserved2; + }; + + struct ShadowStateDictEntry_t + { + CRC32_t m_nChecksum; + ShadowStateId_t m_nShadowStateId; + }; + + struct SnapshotDictEntry_t + { + CRC32_t m_nChecksum; + StateSnapshot_t m_nSnapshot; + }; + + class ShadowStateDictLessFunc + { + public: + bool Less( const ShadowStateDictEntry_t &src1, const ShadowStateDictEntry_t &src2, void *pCtx ); + }; + + class SnapshotDictLessFunc + { + public: + bool Less( const SnapshotDictEntry_t &src1, const SnapshotDictEntry_t &src2, void *pCtx ); + }; + + class UniqueSnapshotLessFunc + { + public: + bool Less( const TransitionList_t &src1, const TransitionList_t &src2, void *pCtx ); + }; + + CurrentTextureStageState_t &TextureStage( int stage ) { return m_CurrentState.m_TextureStage[stage]; } + const CurrentTextureStageState_t &TextureStage( int stage ) const { return m_CurrentState.m_TextureStage[stage]; } + + CurrentSamplerState_t &SamplerState( int stage ) { return m_CurrentState.m_SamplerState[stage]; } + const CurrentSamplerState_t &SamplerState( int stage ) const { return m_CurrentState.m_SamplerState[stage]; } + + // creates state snapshots + ShadowStateId_t CreateShadowState( const ShadowState_t ¤tState ); + StateSnapshot_t CreateStateSnapshot( ShadowStateId_t shadowStateId, const ShadowShaderState_t& currentShaderState ); + + // finds state snapshots + ShadowStateId_t FindShadowState( const ShadowState_t& currentState ) const; + StateSnapshot_t FindStateSnapshot( ShadowStateId_t id, const ShadowShaderState_t& currentState ) const; + + // Finds identical transition lists + unsigned int FindIdenticalTransitionList( unsigned int firstElem, + unsigned short numOps, unsigned int nFirstTest ) const; + + // Adds a transition + void AddTransition( RenderStateFunc_t func ); + void AddTextureTransition( TextureStateFunc_t func, int stage ); + + // Apply a transition + void ApplyTransition( TransitionList_t& list, int snapshot ); + + // Creates an entry in the transition table + void CreateTransitionTableEntry( int to, int from ); + + // Checks if a state is valid + bool TestShadowState( const ShadowState_t& state, const ShadowShaderState_t &shaderState ); + + // Perform state block overrides + void PerformShadowStateOverrides( ); + + // Applies the transition list + void ApplyTransitionList( int snapshot, int nFirstOp, int nOpCount ); + + // Apply shader state (stuff that doesn't lie in the transition table) + void ApplyShaderState( const ShadowState_t &shadowState, const ShadowShaderState_t &shaderState ); + + // Wrapper for the non-standard transitions for stateblock + non-stateblock cases + int CreateNormalTransitions( const ShadowState_t& fromState, const ShadowState_t& toState, bool bForce ); + + // State setting methods + void SetZEnable( D3DZBUFFERTYPE nEnable ); + void SetZFunc( D3DCMPFUNC nCmpFunc ); + +private: + // Sets up the default state + StateSnapshot_t m_DefaultStateSnapshot; + TransitionList_t m_DefaultTransition; + ShadowState_t m_DefaultShadowState; + + // The current snapshot id + ShadowStateId_t m_CurrentShadowId; + StateSnapshot_t m_CurrentSnapshotId; + + // Maintains a list of all used snapshot transition states + CUtlVector< ShadowState_t > m_ShadowStateList; + + // Lookup table for fast snapshot finding + CUtlSortVector< ShadowStateDictEntry_t, ShadowStateDictLessFunc > m_ShadowStateDict; + + // The snapshot transition table + CUtlVector< CUtlVector< TransitionList_t > > m_TransitionTable; + + // List of unique transitions + CUtlSortVector< TransitionList_t, UniqueSnapshotLessFunc > m_UniqueTransitions; + + // Stores all state transition operations + CUtlVector< TransitionOp_t > m_TransitionOps; + + // Stores all state for a particular snapshot + CUtlVector< SnapshotShaderState_t > m_SnapshotList; + + // Lookup table for fast snapshot finding + CUtlSortVector< SnapshotDictEntry_t, SnapshotDictLessFunc > m_SnapshotDict; + + // The current board state. + CurrentState_t m_CurrentState; + +#ifdef DEBUG_BOARD_STATE + // Maintains the total shadow state + ShadowState_t m_BoardState; + ShadowShaderState_t m_BoardShaderState; +#endif +}; + + +//----------------------------------------------------------------------------- +// Inline methods +//----------------------------------------------------------------------------- +inline const ShadowState_t &CTransitionTable::GetSnapshot( StateSnapshot_t snapshotId ) const +{ + Assert( (snapshotId >= 0) && (snapshotId < m_SnapshotList.Count()) ); + return m_ShadowStateList[m_SnapshotList[snapshotId].m_ShadowStateId]; +} + +inline const ShadowShaderState_t &CTransitionTable::GetSnapshotShader( StateSnapshot_t snapshotId ) const +{ + Assert( (snapshotId >= 0) && (snapshotId < m_SnapshotList.Count()) ); + return m_SnapshotList[snapshotId].m_ShaderState; +} + +inline const ShadowState_t *CTransitionTable::CurrentShadowState() const +{ + if ( m_CurrentShadowId == -1 ) + return NULL; + + Assert( (m_CurrentShadowId >= 0) && (m_CurrentShadowId < m_ShadowStateList.Count()) ); + return &m_ShadowStateList[m_CurrentShadowId]; +} + +inline const ShadowShaderState_t *CTransitionTable::CurrentShadowShaderState() const +{ + if ( m_CurrentShadowId == -1 ) + return NULL; + + Assert( (m_CurrentShadowId >= 0) && (m_CurrentShadowId < m_ShadowStateList.Count()) ); + return &m_SnapshotList[m_CurrentShadowId].m_ShaderState; +} + + +#endif // TRANSITION_TABLE_H diff --git a/materialsystem/shaderapidx9/colorformatdx8.cpp b/materialsystem/shaderapidx9/colorformatdx8.cpp new file mode 100644 index 0000000..daf3e50 --- /dev/null +++ b/materialsystem/shaderapidx9/colorformatdx8.cpp @@ -0,0 +1,727 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +// +//===========================================================================// + +#define DISABLE_PROTECTED_THINGS +#include "togl/rendermechanism.h" +#include "locald3dtypes.h" +#include "colorformatdx8.h" +#include "shaderapidx8_global.h" +#include "bitmap/imageformat.h" +#include "shaderapi/ishaderutil.h" +#include "tier0/dbg.h" +#include "tier1/strtools.h" +#include "shaderdevicedx8.h" + + +// Must be last +#include "tier0/memdbgon.h" + + +//----------------------------------------------------------------------------- +// Figures out what texture formats we support +//----------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +// globals +//----------------------------------------------------------------------------- + +// Texture formats supported by DX driver[vertextexture][render target][non filterable] +static D3DFORMAT g_D3DColorFormat[NUM_IMAGE_FORMATS][2][2][2]; +static UINT g_DisplayAdapter; +static D3DDEVTYPE g_DeviceType; +static ImageFormat g_DeviceFormat; +static bool g_bSupportsD24S8; +static bool g_bSupportsD24X8; +static bool g_bSupportsD16; +static bool g_bSupportsD24X4S4; +static bool g_bSupportsD15S1; + +//----------------------------------------------------------------------------- +// Determines what formats we actually *do* support +//----------------------------------------------------------------------------- +static bool TestTextureFormat( D3DFORMAT format, bool bIsRenderTarget, + bool bIsVertexTexture, bool bIsFilterableRequired ) +{ + int nUsage = bIsRenderTarget ? D3DUSAGE_RENDERTARGET : 0; + if ( bIsVertexTexture ) + { + // vertex textures never need filtering + nUsage |= D3DUSAGE_QUERY_VERTEXTEXTURE; + } + if ( bIsFilterableRequired ) + { + nUsage |= D3DUSAGE_QUERY_FILTER; + } + + HRESULT hr; + + // IHV depth texture formats require a slightly different check... + if ( !IsX360() && bIsRenderTarget && ( ( format == NVFMT_RAWZ ) || ( format == NVFMT_INTZ ) || + ( format == D3DFMT_D16 ) || ( format == D3DFMT_D24S8 ) || + ( format == ATIFMT_D16 ) || ( format == ATIFMT_D24S8 ) ) ) + { + hr = D3D()->CheckDeviceFormat( + g_DisplayAdapter, g_DeviceType, ImageLoader::ImageFormatToD3DFormat( g_DeviceFormat ), + D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_TEXTURE, format ); + } + else if ( !IsX360() || !bIsRenderTarget ) + { + // See if we can do it! + hr = D3D()->CheckDeviceFormat( + g_DisplayAdapter, g_DeviceType, ImageLoader::ImageFormatToD3DFormat( g_DeviceFormat ), + nUsage, D3DRTYPE_TEXTURE, format ); + } + else // 360 + { + // 360 can only validate render targets as surface display format + hr = D3D()->CheckDeviceFormat( g_DisplayAdapter, g_DeviceType, format, 0, D3DRTYPE_SURFACE, format ); + } + + return SUCCEEDED( hr ); +} + +D3DFORMAT GetNearestD3DColorFormat( ImageFormat fmt, + bool isRenderTarget, bool bIsVertexTexture, + bool bIsFilterableRequired) +{ + switch(fmt) + { + case IMAGE_FORMAT_RGBA8888: + case IMAGE_FORMAT_ABGR8888: + case IMAGE_FORMAT_ARGB8888: + case IMAGE_FORMAT_BGRA8888: + if (TestTextureFormat(D3DFMT_A8R8G8B8, isRenderTarget, bIsVertexTexture, bIsFilterableRequired)) + return D3DFMT_A8R8G8B8; + if (TestTextureFormat(D3DFMT_A4R4G4B4, isRenderTarget, bIsVertexTexture, bIsFilterableRequired)) + return D3DFMT_A4R4G4B4; + break; + +#if defined( _X360 ) + case IMAGE_FORMAT_LINEAR_RGBA8888: + case IMAGE_FORMAT_LINEAR_ABGR8888: + case IMAGE_FORMAT_LINEAR_ARGB8888: + case IMAGE_FORMAT_LINEAR_BGRA8888: + // same as above - all xxxx8888 RGBA ordering funnels to d3d a8r8g8b8 + if ( TestTextureFormat( D3DFMT_LIN_A8R8G8B8, isRenderTarget, bIsVertexTexture, bIsFilterableRequired ) ) + return D3DFMT_LIN_A8R8G8B8; + break; +#endif + +#if defined( _X360 ) + case IMAGE_FORMAT_LINEAR_BGRX8888: + if ( TestTextureFormat( D3DFMT_LIN_X8R8G8B8, isRenderTarget, bIsVertexTexture, bIsFilterableRequired ) ) + return D3DFMT_LIN_X8R8G8B8; + break; +#endif + + case IMAGE_FORMAT_BGRX8888: + // We want this format to return exactly it's equivalent so that + // when we create render targets to blit to from the framebuffer, + // the CopyRect won't fail due to format mismatches. + if (TestTextureFormat(D3DFMT_X8R8G8B8, isRenderTarget, bIsVertexTexture, bIsFilterableRequired)) + return D3DFMT_X8R8G8B8; + + // fall through. . . . + case IMAGE_FORMAT_RGB888: + case IMAGE_FORMAT_BGR888: +#if !defined( _X360 ) + if (TestTextureFormat(D3DFMT_R8G8B8, isRenderTarget, bIsVertexTexture, bIsFilterableRequired)) + return D3DFMT_R8G8B8; +#endif + if (TestTextureFormat(D3DFMT_X8R8G8B8, isRenderTarget, bIsVertexTexture, bIsFilterableRequired)) + return D3DFMT_X8R8G8B8; + if (TestTextureFormat(D3DFMT_A8R8G8B8, isRenderTarget, bIsVertexTexture, bIsFilterableRequired)) + return D3DFMT_A8R8G8B8; + if (TestTextureFormat(D3DFMT_R5G6B5, isRenderTarget, bIsVertexTexture, bIsFilterableRequired)) + return D3DFMT_R5G6B5; + if (TestTextureFormat(D3DFMT_X1R5G5B5, isRenderTarget, bIsVertexTexture, bIsFilterableRequired)) + return D3DFMT_X1R5G5B5; + if (TestTextureFormat(D3DFMT_A1R5G5B5, isRenderTarget, bIsVertexTexture, bIsFilterableRequired)) + return D3DFMT_A1R5G5B5; + break; + + case IMAGE_FORMAT_BGR565: + case IMAGE_FORMAT_RGB565: + if (TestTextureFormat(D3DFMT_R5G6B5, isRenderTarget, bIsVertexTexture, bIsFilterableRequired)) + return D3DFMT_R5G6B5; + if (TestTextureFormat(D3DFMT_X1R5G5B5, isRenderTarget, bIsVertexTexture, bIsFilterableRequired)) + return D3DFMT_X1R5G5B5; + if (TestTextureFormat(D3DFMT_A1R5G5B5, isRenderTarget, bIsVertexTexture, bIsFilterableRequired)) + return D3DFMT_A1R5G5B5; +#if !defined( _X360 ) + if (TestTextureFormat(D3DFMT_R8G8B8, isRenderTarget, bIsVertexTexture, bIsFilterableRequired)) + return D3DFMT_R8G8B8; +#endif + if (TestTextureFormat(D3DFMT_X8R8G8B8, isRenderTarget, bIsVertexTexture, bIsFilterableRequired)) + return D3DFMT_X8R8G8B8; + if (TestTextureFormat(D3DFMT_A8R8G8B8, isRenderTarget, bIsVertexTexture, bIsFilterableRequired)) + return D3DFMT_A8R8G8B8; + break; + + case IMAGE_FORMAT_BGRX5551: + if (TestTextureFormat(D3DFMT_X1R5G5B5, isRenderTarget, bIsVertexTexture, bIsFilterableRequired)) + return D3DFMT_X1R5G5B5; + if (TestTextureFormat(D3DFMT_A1R5G5B5, isRenderTarget, bIsVertexTexture, bIsFilterableRequired)) + return D3DFMT_A1R5G5B5; + if (TestTextureFormat(D3DFMT_R5G6B5, isRenderTarget, bIsVertexTexture, bIsFilterableRequired)) + return D3DFMT_R5G6B5; +#if !defined( _X360 ) + if (TestTextureFormat(D3DFMT_R8G8B8, isRenderTarget, bIsVertexTexture, bIsFilterableRequired)) + return D3DFMT_R8G8B8; +#endif + if (TestTextureFormat(D3DFMT_X8R8G8B8, isRenderTarget, bIsVertexTexture, bIsFilterableRequired)) + return D3DFMT_X8R8G8B8; + if (TestTextureFormat(D3DFMT_A8R8G8B8, isRenderTarget, bIsVertexTexture, bIsFilterableRequired)) + return D3DFMT_A8R8G8B8; + break; + +#if defined( _X360 ) + case IMAGE_FORMAT_LINEAR_BGRX5551: + if ( TestTextureFormat( D3DFMT_LIN_X1R5G5B5, isRenderTarget, bIsVertexTexture, bIsFilterableRequired ) ) + return D3DFMT_LIN_X1R5G5B5; + break; +#endif + + case IMAGE_FORMAT_BGRA5551: + if (TestTextureFormat(D3DFMT_A1R5G5B5, isRenderTarget, bIsVertexTexture, bIsFilterableRequired)) + return D3DFMT_A1R5G5B5; + if (TestTextureFormat(D3DFMT_A4R4G4B4, isRenderTarget, bIsVertexTexture, bIsFilterableRequired)) + return D3DFMT_A4R4G4B4; + if (TestTextureFormat(D3DFMT_A8R8G8B8, isRenderTarget, bIsVertexTexture, bIsFilterableRequired)) + return D3DFMT_A8R8G8B8; + break; + + case IMAGE_FORMAT_BGRA4444: + if (TestTextureFormat(D3DFMT_A4R4G4B4, isRenderTarget, bIsVertexTexture, bIsFilterableRequired)) + return D3DFMT_A4R4G4B4; + if (TestTextureFormat(D3DFMT_A8R8G8B8, isRenderTarget, bIsVertexTexture, bIsFilterableRequired)) + return D3DFMT_A8R8G8B8; + break; + + case IMAGE_FORMAT_I8: + if (TestTextureFormat(D3DFMT_L8, isRenderTarget, bIsVertexTexture, bIsFilterableRequired)) + return D3DFMT_L8; + if (TestTextureFormat(D3DFMT_A8R8G8B8, isRenderTarget, bIsVertexTexture, bIsFilterableRequired)) + return D3DFMT_A8R8G8B8; + break; + +#if defined( _X360 ) + case IMAGE_FORMAT_LINEAR_I8: + if ( TestTextureFormat( D3DFMT_LIN_L8, isRenderTarget, bIsVertexTexture, bIsFilterableRequired ) ) + return D3DFMT_LIN_L8; + break; +#endif + + case IMAGE_FORMAT_IA88: + if (TestTextureFormat(D3DFMT_A8L8, isRenderTarget, bIsVertexTexture, bIsFilterableRequired)) + return D3DFMT_A8L8; + if (TestTextureFormat(D3DFMT_A8R8G8B8, isRenderTarget, bIsVertexTexture, bIsFilterableRequired)) + return D3DFMT_A8R8G8B8; + break; + + case IMAGE_FORMAT_A8: + if (TestTextureFormat(D3DFMT_A8, isRenderTarget, bIsVertexTexture, bIsFilterableRequired)) + return D3DFMT_A8; + if (TestTextureFormat(D3DFMT_A8R8G8B8, isRenderTarget, bIsVertexTexture, bIsFilterableRequired)) + return D3DFMT_A8R8G8B8; + break; + + case IMAGE_FORMAT_DXT1: + case IMAGE_FORMAT_DXT1_ONEBITALPHA: + case IMAGE_FORMAT_DXT1_RUNTIME: + if (TestTextureFormat(D3DFMT_DXT1, isRenderTarget, bIsVertexTexture, bIsFilterableRequired)) + return D3DFMT_DXT1; + break; + + case IMAGE_FORMAT_DXT3: + if (TestTextureFormat(D3DFMT_DXT3, isRenderTarget, bIsVertexTexture, bIsFilterableRequired )) + return D3DFMT_DXT3; + break; + + case IMAGE_FORMAT_DXT5: + case IMAGE_FORMAT_DXT5_RUNTIME: + if (TestTextureFormat(D3DFMT_DXT5, isRenderTarget, bIsVertexTexture, bIsFilterableRequired )) + return D3DFMT_DXT5; + break; + + case IMAGE_FORMAT_UV88: + if (TestTextureFormat(D3DFMT_V8U8, isRenderTarget, bIsVertexTexture, bIsFilterableRequired )) + return D3DFMT_V8U8; + break; + + case IMAGE_FORMAT_UVWQ8888: + if (TestTextureFormat(D3DFMT_Q8W8V8U8, isRenderTarget, bIsVertexTexture, bIsFilterableRequired )) + return D3DFMT_Q8W8V8U8; + break; + + case IMAGE_FORMAT_UVLX8888: + if (TestTextureFormat(D3DFMT_X8L8V8U8, isRenderTarget, bIsVertexTexture, bIsFilterableRequired )) + return D3DFMT_X8L8V8U8; + break; + + case IMAGE_FORMAT_RGBA16161616F: + if ( TestTextureFormat( D3DFMT_A16B16G16R16F, isRenderTarget, bIsVertexTexture, bIsFilterableRequired ) ) + return D3DFMT_A16B16G16R16F; + if ( TestTextureFormat( D3DFMT_A16B16G16R16, isRenderTarget, bIsVertexTexture, bIsFilterableRequired ) ) + return D3DFMT_A16B16G16R16; + break; + + case IMAGE_FORMAT_RGBA16161616: + if ( TestTextureFormat( D3DFMT_A16B16G16R16, isRenderTarget, bIsVertexTexture, bIsFilterableRequired ) ) + return D3DFMT_A16B16G16R16; + if ( TestTextureFormat( D3DFMT_A16B16G16R16F, isRenderTarget, bIsVertexTexture, bIsFilterableRequired ) ) + return D3DFMT_A16B16G16R16F; + break; + +#if defined( _X360 ) + case IMAGE_FORMAT_LINEAR_RGBA16161616: + if ( TestTextureFormat( D3DFMT_LIN_A16B16G16R16, isRenderTarget, bIsVertexTexture, bIsFilterableRequired ) ) + return D3DFMT_LIN_A16B16G16R16; + break; +#endif + + case IMAGE_FORMAT_R32F: + if ( TestTextureFormat( D3DFMT_R32F, isRenderTarget, bIsVertexTexture, bIsFilterableRequired ) ) + return D3DFMT_R32F; + break; + + case IMAGE_FORMAT_RGBA32323232F: + if ( TestTextureFormat( D3DFMT_A32B32G32R32F, isRenderTarget, bIsVertexTexture, bIsFilterableRequired ) ) + return D3DFMT_A32B32G32R32F; + break; + +#if defined( _X360 ) + case IMAGE_FORMAT_X360_DST16: + return D3DFMT_D16; + + case IMAGE_FORMAT_X360_DST24: + return D3DFMT_D24S8; + + case IMAGE_FORMAT_X360_DST24F: + return D3DFMT_D24FS8; + + case IMAGE_FORMAT_LE_BGRX8888: + return D3DFMT_LE_X8R8G8B8; + + case IMAGE_FORMAT_LE_BGRA8888: + return D3DFMT_LE_A8R8G8B8; +#endif + + // nVidia overloads DST formats as texture formats + case IMAGE_FORMAT_NV_DST16: + if ( TestTextureFormat( D3DFMT_D16, isRenderTarget, bIsVertexTexture, bIsFilterableRequired ) ) + return D3DFMT_D16; + break; + + case IMAGE_FORMAT_NV_DST24: + if ( TestTextureFormat( D3DFMT_D24S8, isRenderTarget, bIsVertexTexture, bIsFilterableRequired ) ) + return D3DFMT_D24S8; + break; + case IMAGE_FORMAT_NV_INTZ: + if ( TestTextureFormat( NVFMT_INTZ, isRenderTarget, bIsVertexTexture, false ) ) + return NVFMT_INTZ; + break; + + case IMAGE_FORMAT_NV_RAWZ: + if ( TestTextureFormat( NVFMT_RAWZ, isRenderTarget, bIsVertexTexture, false ) ) + return NVFMT_RAWZ; + break; + + case IMAGE_FORMAT_NV_NULL: + if ( TestTextureFormat( NVFMT_NULL, isRenderTarget, bIsVertexTexture, false ) ) + return NVFMT_NULL; + break; + + case IMAGE_FORMAT_ATI_DST16: + if ( TestTextureFormat( ATIFMT_D16, isRenderTarget, bIsVertexTexture, false ) ) + return ATIFMT_D16; + break; + + case IMAGE_FORMAT_ATI_DST24: + if ( TestTextureFormat( ATIFMT_D24S8, isRenderTarget, bIsVertexTexture, false ) ) + return ATIFMT_D24S8; + break; + + case IMAGE_FORMAT_ATI2N: + if ( TestTextureFormat( ATIFMT_ATI2N, isRenderTarget, bIsVertexTexture, bIsFilterableRequired ) ) + return ATIFMT_ATI2N; + break; + + case IMAGE_FORMAT_ATI1N: + if ( TestTextureFormat( ATIFMT_ATI1N, isRenderTarget, bIsVertexTexture, bIsFilterableRequired ) ) + return ATIFMT_ATI1N; + break; + } + + return D3DFMT_UNKNOWN; +} + +void InitializeColorInformation( UINT displayAdapter, D3DDEVTYPE deviceType, + ImageFormat displayFormat ) +{ + g_DisplayAdapter = displayAdapter; + g_DeviceType = deviceType; + g_DeviceFormat = displayFormat; + + int fmt = 0; + while ( fmt < NUM_IMAGE_FORMATS ) + { + for ( int nVertexTexture = 0; nVertexTexture <= 1; ++nVertexTexture ) + { + for ( int nRenderTarget = 0; nRenderTarget <= 1; ++nRenderTarget ) + { + for ( int nFilterable = 0; nFilterable <= 1; ++nFilterable ) + { + g_D3DColorFormat[fmt][nVertexTexture][nRenderTarget][nFilterable] = + GetNearestD3DColorFormat( (ImageFormat)fmt, nRenderTarget != 0, nVertexTexture != 0, nFilterable != 0 ); + } + } + } + ++fmt; + } + + // Check the depth formats + HRESULT hr = D3D()->CheckDeviceFormat( + g_DisplayAdapter, g_DeviceType, ImageLoader::ImageFormatToD3DFormat( g_DeviceFormat ), + D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DFMT_D24S8 ); + g_bSupportsD24S8 = !FAILED(hr); + + hr = D3D()->CheckDeviceFormat( + g_DisplayAdapter, g_DeviceType, ImageLoader::ImageFormatToD3DFormat( g_DeviceFormat ), + D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DFMT_D24X8 ); + g_bSupportsD24X8 = !FAILED(hr); + + hr = D3D()->CheckDeviceFormat( + g_DisplayAdapter, g_DeviceType, ImageLoader::ImageFormatToD3DFormat( g_DeviceFormat ), + D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DFMT_D16 ); + g_bSupportsD16 = !FAILED(hr); + +#if !defined( _X360 ) + hr = D3D()->CheckDeviceFormat( + g_DisplayAdapter, g_DeviceType, ImageLoader::ImageFormatToD3DFormat( g_DeviceFormat ), + D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DFMT_D24X4S4 ); + g_bSupportsD24X4S4 = !FAILED(hr); +#else + g_bSupportsD24X4S4 = false; +#endif + +#if !defined( _X360 ) + hr = D3D()->CheckDeviceFormat( + g_DisplayAdapter, g_DeviceType, ImageLoader::ImageFormatToD3DFormat( g_DeviceFormat ), + D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DFMT_D15S1 ); + g_bSupportsD15S1 = !FAILED(hr); +#else + g_bSupportsD15S1 = false; +#endif +} + + +//----------------------------------------------------------------------------- +// Returns true if compressed textures are supported +//----------------------------------------------------------------------------- +bool D3DSupportsCompressedTextures() +{ + return (g_D3DColorFormat[IMAGE_FORMAT_DXT1][0][0][0] != D3DFMT_UNKNOWN) && + (g_D3DColorFormat[IMAGE_FORMAT_DXT3][0][0][0] != D3DFMT_UNKNOWN) && + (g_D3DColorFormat[IMAGE_FORMAT_DXT5][0][0][0] != D3DFMT_UNKNOWN); +} + + +//----------------------------------------------------------------------------- +// Returns closest supported format +//----------------------------------------------------------------------------- +ImageFormat FindNearestSupportedFormat( ImageFormat format, bool bIsVertexTexture, bool bIsRenderTarget, bool bFilterableRequired ) +{ + return ImageLoader::D3DFormatToImageFormat( g_D3DColorFormat[format][bIsVertexTexture][bIsRenderTarget][bFilterableRequired] ); +} + + +//----------------------------------------------------------------------------- +// Returns true if compressed textures are supported +//----------------------------------------------------------------------------- +bool D3DSupportsDepthTexture(D3DFORMAT format) +{ + // See if we can do it! + HRESULT hr = D3D()->CheckDeviceFormat( + g_DisplayAdapter, g_DeviceType, ImageLoader::ImageFormatToD3DFormat(g_DeviceFormat), + D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_TEXTURE, format); + + return !FAILED(hr); +} + + +//----------------------------------------------------------------------------- +// Returns true if the depth format is compatible with the display +//----------------------------------------------------------------------------- +static inline bool IsDepthFormatCompatible( int nAdapter, ImageFormat displayFormat, ImageFormat renderTargetFormat, D3DFORMAT depthFormat ) +{ + D3DFORMAT d3dDisplayFormat = ImageLoader::ImageFormatToD3DFormat( displayFormat ); + D3DFORMAT d3dRenderTargetFormat = ImageLoader::ImageFormatToD3DFormat( renderTargetFormat ); + + // Verify that the depth format is compatible. + HRESULT hr = D3D()->CheckDepthStencilMatch( nAdapter, DX8_DEVTYPE, + d3dDisplayFormat, d3dRenderTargetFormat, depthFormat); + return !FAILED(hr); +} + +//----------------------------------------------------------------------------- +// Finds the nearest supported depth buffer format +//----------------------------------------------------------------------------- +D3DFORMAT FindNearestSupportedDepthFormat( int nAdapter, ImageFormat displayFormat, ImageFormat renderTargetFormat, D3DFORMAT depthFormat ) +{ + // This is the default case, used for rendering to the main render target + Assert( displayFormat != IMAGE_FORMAT_UNKNOWN && renderTargetFormat != IMAGE_FORMAT_UNKNOWN ); + + switch (depthFormat) + { +#if defined( _X360 ) + case D3DFMT_D24FS8: + return D3DFMT_D24FS8; + + case D3DFMT_LIN_D24S8: + if ( g_bSupportsD24S8 && IsDepthFormatCompatible( nAdapter, displayFormat, renderTargetFormat, D3DFMT_LIN_D24S8 ) ) + return D3DFMT_LIN_D24S8; +#endif + case D3DFMT_D24S8: + if ( g_bSupportsD24S8 && IsDepthFormatCompatible( nAdapter, displayFormat, renderTargetFormat, D3DFMT_D24S8 ) ) + return D3DFMT_D24S8; +#if !defined( _X360 ) + if ( g_bSupportsD24X4S4 && IsDepthFormatCompatible( nAdapter, displayFormat, renderTargetFormat, D3DFMT_D24X4S4 ) ) + return D3DFMT_D24X4S4; + if ( g_bSupportsD15S1 && IsDepthFormatCompatible( nAdapter, displayFormat, renderTargetFormat, D3DFMT_D15S1 ) ) + return D3DFMT_D15S1; +#endif + if ( g_bSupportsD24X8 && IsDepthFormatCompatible( nAdapter, displayFormat, renderTargetFormat, D3DFMT_D24X8 ) ) + return D3DFMT_D24X8; + if ( g_bSupportsD16 && IsDepthFormatCompatible( nAdapter, displayFormat, renderTargetFormat, D3DFMT_D16 ) ) + return D3DFMT_D16; + break; + + case D3DFMT_D24X8: + if ( g_bSupportsD24X8 && IsDepthFormatCompatible( nAdapter, displayFormat, renderTargetFormat, D3DFMT_D24X8 ) ) + return D3DFMT_D24X8; + if ( g_bSupportsD24S8 && IsDepthFormatCompatible( nAdapter, displayFormat, renderTargetFormat, D3DFMT_D24S8 ) ) + return D3DFMT_D24S8; +#if !defined( _X360 ) + if ( g_bSupportsD24X4S4 && IsDepthFormatCompatible( nAdapter, displayFormat, renderTargetFormat, D3DFMT_D24X4S4 ) ) + return D3DFMT_D24X4S4; +#endif + if ( g_bSupportsD16 && IsDepthFormatCompatible( nAdapter, displayFormat, renderTargetFormat, D3DFMT_D16 ) ) + return D3DFMT_D16; +#if !defined( _X360 ) + if ( g_bSupportsD15S1 && IsDepthFormatCompatible( nAdapter, displayFormat, renderTargetFormat, D3DFMT_D15S1 ) ) + return D3DFMT_D15S1; +#endif + break; + + case D3DFMT_D16: + if ( g_bSupportsD16 && IsDepthFormatCompatible( nAdapter, displayFormat, renderTargetFormat, D3DFMT_D16 ) ) + return D3DFMT_D16; +#if !defined( _X360 ) + if ( g_bSupportsD15S1 && IsDepthFormatCompatible( nAdapter, displayFormat, renderTargetFormat, D3DFMT_D15S1 ) ) + return D3DFMT_D15S1; +#endif + if ( g_bSupportsD24X8 && IsDepthFormatCompatible( nAdapter, displayFormat, renderTargetFormat, D3DFMT_D24X8 ) ) + return D3DFMT_D24X8; + if ( g_bSupportsD24S8 && IsDepthFormatCompatible( nAdapter, displayFormat, renderTargetFormat, D3DFMT_D24S8 ) ) + return D3DFMT_D24S8; +#if !defined( _X360 ) + if ( g_bSupportsD24X4S4 && IsDepthFormatCompatible( nAdapter, displayFormat, renderTargetFormat, D3DFMT_D24X4S4 ) ) + return D3DFMT_D24X4S4; +#endif + break; + } + + Assert( 0 ); + return D3DFMT_D16; +} + + +//----------------------------------------------------------------------------- +// Is a display buffer valid? +//----------------------------------------------------------------------------- +static inline bool IsFrameBufferFormatValid( UINT displayAdapter, D3DDEVTYPE deviceType, + D3DFORMAT displayFormat, D3DFORMAT backBufferFormat, bool bIsWindowed ) +{ + HRESULT hr = D3D()->CheckDeviceType( displayAdapter, deviceType, displayFormat, + backBufferFormat, bIsWindowed ); + return !FAILED(hr); +} + + +//----------------------------------------------------------------------------- +// Finds the nearest supported frame buffer format +//----------------------------------------------------------------------------- +ImageFormat FindNearestSupportedBackBufferFormat( UINT displayAdapter, + D3DDEVTYPE deviceType, ImageFormat displayFormat, ImageFormat backBufferFormat, bool bIsWindowed ) +{ + D3DFORMAT d3dDisplayFormat = ImageLoader::ImageFormatToD3DFormat( displayFormat ); + switch (backBufferFormat) + { + case IMAGE_FORMAT_RGBA8888: + case IMAGE_FORMAT_ABGR8888: + case IMAGE_FORMAT_ARGB8888: + case IMAGE_FORMAT_BGRA8888: + case IMAGE_FORMAT_BGRA4444: // This is not supported ever; bump up to 32 bit + if (IsFrameBufferFormatValid( displayAdapter, deviceType, d3dDisplayFormat, D3DFMT_A8R8G8B8, bIsWindowed )) + return IMAGE_FORMAT_BGRA8888; + + // Bye, bye dest alpha + if (IsFrameBufferFormatValid( displayAdapter, deviceType, d3dDisplayFormat, D3DFMT_X8R8G8B8, bIsWindowed )) + return IMAGE_FORMAT_BGRX8888; + + if (IsFrameBufferFormatValid( displayAdapter, deviceType, d3dDisplayFormat, D3DFMT_R5G6B5, bIsWindowed )) + return IMAGE_FORMAT_BGR565; + + if (IsFrameBufferFormatValid( displayAdapter, deviceType, d3dDisplayFormat, D3DFMT_A1R5G5B5, bIsWindowed )) + return IMAGE_FORMAT_BGRA5551; + + if (IsFrameBufferFormatValid( displayAdapter, deviceType, d3dDisplayFormat, D3DFMT_X1R5G5B5, bIsWindowed )) + return IMAGE_FORMAT_BGRX5551; + + return IMAGE_FORMAT_UNKNOWN; + + case IMAGE_FORMAT_RGB888: + case IMAGE_FORMAT_BGR888: + case IMAGE_FORMAT_RGB888_BLUESCREEN: + case IMAGE_FORMAT_BGRX8888: + if (IsFrameBufferFormatValid( displayAdapter, deviceType, d3dDisplayFormat, D3DFMT_X8R8G8B8, bIsWindowed )) + return IMAGE_FORMAT_BGRX8888; + + if (IsFrameBufferFormatValid( displayAdapter, deviceType, d3dDisplayFormat, D3DFMT_A8R8G8B8, bIsWindowed )) + return IMAGE_FORMAT_BGRA8888; + + if (IsFrameBufferFormatValid( displayAdapter, deviceType, d3dDisplayFormat, D3DFMT_R5G6B5, bIsWindowed )) + return IMAGE_FORMAT_BGR565; + + if (IsFrameBufferFormatValid( displayAdapter, deviceType, d3dDisplayFormat, D3DFMT_A1R5G5B5, bIsWindowed )) + return IMAGE_FORMAT_BGRA5551; + + if (IsFrameBufferFormatValid( displayAdapter, deviceType, d3dDisplayFormat, D3DFMT_X1R5G5B5, bIsWindowed )) + return IMAGE_FORMAT_BGRX5551; + + return IMAGE_FORMAT_UNKNOWN; + + case IMAGE_FORMAT_RGB565: + case IMAGE_FORMAT_BGR565: + if (IsFrameBufferFormatValid( displayAdapter, deviceType, d3dDisplayFormat, D3DFMT_R5G6B5, bIsWindowed )) + return IMAGE_FORMAT_BGR565; + + if (IsFrameBufferFormatValid( displayAdapter, deviceType, d3dDisplayFormat, D3DFMT_A1R5G5B5, bIsWindowed )) + return IMAGE_FORMAT_BGRA5551; + + if (IsFrameBufferFormatValid( displayAdapter, deviceType, d3dDisplayFormat, D3DFMT_X1R5G5B5, bIsWindowed )) + return IMAGE_FORMAT_BGRX5551; + + if (IsFrameBufferFormatValid( displayAdapter, deviceType, d3dDisplayFormat, D3DFMT_X8R8G8B8, bIsWindowed )) + return IMAGE_FORMAT_BGRX8888; + + if (IsFrameBufferFormatValid( displayAdapter, deviceType, d3dDisplayFormat, D3DFMT_A8R8G8B8, bIsWindowed )) + return IMAGE_FORMAT_BGRA8888; + + return IMAGE_FORMAT_UNKNOWN; + + case IMAGE_FORMAT_BGRX5551: + if (IsFrameBufferFormatValid( displayAdapter, deviceType, d3dDisplayFormat, D3DFMT_X1R5G5B5, bIsWindowed )) + return IMAGE_FORMAT_BGRX5551; + + if (IsFrameBufferFormatValid( displayAdapter, deviceType, d3dDisplayFormat, D3DFMT_A1R5G5B5, bIsWindowed )) + return IMAGE_FORMAT_BGRA5551; + + if (IsFrameBufferFormatValid( displayAdapter, deviceType, d3dDisplayFormat, D3DFMT_R5G6B5, bIsWindowed )) + return IMAGE_FORMAT_BGR565; + + if (IsFrameBufferFormatValid( displayAdapter, deviceType, d3dDisplayFormat, D3DFMT_X8R8G8B8, bIsWindowed )) + return IMAGE_FORMAT_BGRX8888; + + if (IsFrameBufferFormatValid( displayAdapter, deviceType, d3dDisplayFormat, D3DFMT_A8R8G8B8, bIsWindowed )) + return IMAGE_FORMAT_BGRA8888; + + return IMAGE_FORMAT_UNKNOWN; + + case IMAGE_FORMAT_BGRA5551: + if (IsFrameBufferFormatValid( displayAdapter, deviceType, d3dDisplayFormat, D3DFMT_A1R5G5B5, bIsWindowed )) + return IMAGE_FORMAT_BGRA5551; + + if (IsFrameBufferFormatValid( displayAdapter, deviceType, d3dDisplayFormat, D3DFMT_X1R5G5B5, bIsWindowed )) + return IMAGE_FORMAT_BGRX5551; + + if (IsFrameBufferFormatValid( displayAdapter, deviceType, d3dDisplayFormat, D3DFMT_R5G6B5, bIsWindowed )) + return IMAGE_FORMAT_BGR565; + + if (IsFrameBufferFormatValid( displayAdapter, deviceType, d3dDisplayFormat, D3DFMT_A8R8G8B8, bIsWindowed )) + return IMAGE_FORMAT_BGRA8888; + + if (IsFrameBufferFormatValid( displayAdapter, deviceType, d3dDisplayFormat, D3DFMT_X8R8G8B8, bIsWindowed )) + return IMAGE_FORMAT_BGRX8888; + + return IMAGE_FORMAT_UNKNOWN; + } + + return IMAGE_FORMAT_UNKNOWN; +} + +#if defined( _X360 ) +const char *D3DFormatName( D3DFORMAT d3dFormat ) +{ + if ( IS_D3DFORMAT_SRGB( d3dFormat ) ) + { + // sanitize the format from possible sRGB state for comparison purposes + d3dFormat = MAKE_NON_SRGB_FMT( d3dFormat ); + } + + switch ( d3dFormat ) + { + case D3DFMT_A8R8G8B8: + return "D3DFMT_A8R8G8B8"; + case D3DFMT_LIN_A8R8G8B8: + return "D3DFMT_LIN_A8R8G8B8"; + case D3DFMT_X8R8G8B8: + return "D3DFMT_X8R8G8B8"; + case D3DFMT_LIN_X8R8G8B8: + return "D3DFMT_LIN_X8R8G8B8"; + case D3DFMT_R5G6B5: + return "D3DFMT_R5G6B5"; + case D3DFMT_X1R5G5B5: + return "D3DFMT_X1R5G5B5"; + case D3DFMT_A1R5G5B5: + return "D3DFMT_A1R5G5B5"; + case D3DFMT_A4R4G4B4: + return "D3DFMT_A4R4G4B4"; + case D3DFMT_L8: + return "D3DFMT_L8"; + case D3DFMT_A8L8: + return "D3DFMT_A8L8"; + case D3DFMT_A8: + return "D3DFMT_A8"; + case D3DFMT_DXT1: + return "D3DFMT_DXT1"; + case D3DFMT_DXT3: + return "D3DFMT_DXT3"; + case D3DFMT_DXT5: + return "D3DFMT_DXT5"; + case D3DFMT_V8U8: + return "D3DFMT_V8U8"; + case D3DFMT_Q8W8V8U8: + return "D3DFMT_Q8W8V8U8"; + case D3DFMT_D16: + return "D3DFMT_D16"; + case D3DFMT_D24S8: + return "D3DFMT_D24S8"; + case D3DFMT_D24FS8: + return "D3DFMT_D24FS8"; + case D3DFMT_LIN_D24S8: + return "D3DFMT_LIN_D24S8"; + case D3DFMT_A16B16G16R16: + return "D3DFMT_A16B16G16R16"; + case D3DFMT_LIN_A16B16G16R16: + return "D3DFMT_LIN_A16B16G16R16"; + } + return "???"; +} +#endif diff --git a/materialsystem/shaderapidx9/colorformatdx8.h b/materialsystem/shaderapidx9/colorformatdx8.h new file mode 100644 index 0000000..20e9973 --- /dev/null +++ b/materialsystem/shaderapidx9/colorformatdx8.h @@ -0,0 +1,60 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +// +//=============================================================================// + +#ifndef COLORFORMATDX8_H +#define COLORFORMATDX8_H + +#include +#include "togl/rendermechanism.h" + +// FOURCC formats for ATI shadow depth textures +#define ATIFMT_D16 ((D3DFORMAT)(MAKEFOURCC('D','F','1','6'))) +#define ATIFMT_D24S8 ((D3DFORMAT)(MAKEFOURCC('D','F','2','4'))) + +// FOURCC formats for ATI2N and ATI1N compressed textures (360 and DX10 parts also do these) +#define ATIFMT_ATI2N ((D3DFORMAT) MAKEFOURCC('A', 'T', 'I', '2')) +#define ATIFMT_ATI1N ((D3DFORMAT) MAKEFOURCC('A', 'T', 'I', '1')) + +// FOURCC formats for nVidia shadow depth textures +#define NVFMT_RAWZ ((D3DFORMAT)(MAKEFOURCC('R','A','W','Z'))) +#define NVFMT_INTZ ((D3DFORMAT)(MAKEFOURCC('I','N','T','Z'))) + +// FOURCC format for nVidia null texture format +#define NVFMT_NULL ((D3DFORMAT)(MAKEFOURCC('N','U','L','L'))) + + +//----------------------------------------------------------------------------- +// Finds the nearest supported frame buffer format +//----------------------------------------------------------------------------- +ImageFormat FindNearestSupportedBackBufferFormat( unsigned int displayAdapter, D3DDEVTYPE deviceType, + ImageFormat displayFormat, ImageFormat backBufferFormat, bool bIsWindowed ); + +//----------------------------------------------------------------------------- +// Initializes the color format informat; call it every time display mode changes +//----------------------------------------------------------------------------- +void InitializeColorInformation( unsigned int displayAdapter, D3DDEVTYPE deviceType, + ImageFormat displayFormat ); + +//----------------------------------------------------------------------------- +// Returns true if compressed textures are supported +//----------------------------------------------------------------------------- +bool D3DSupportsCompressedTextures(); + +//----------------------------------------------------------------------------- +// Returns closest supported format +//----------------------------------------------------------------------------- +ImageFormat FindNearestSupportedFormat( ImageFormat format, bool bIsVertexTexture, bool bIsRenderTarget, bool bFilterableRequired ); + +//----------------------------------------------------------------------------- +// Finds the nearest supported depth buffer format +//----------------------------------------------------------------------------- +D3DFORMAT FindNearestSupportedDepthFormat( int nAdapter, ImageFormat displayFormat, ImageFormat renderTargetFormat, D3DFORMAT depthFormat ); + +const char *D3DFormatName( D3DFORMAT d3dFormat ); + +#endif // COLORFORMATDX8_H diff --git a/materialsystem/shaderapidx9/cvballoctracker.cpp b/materialsystem/shaderapidx9/cvballoctracker.cpp new file mode 100644 index 0000000..8c3cdd0 --- /dev/null +++ b/materialsystem/shaderapidx9/cvballoctracker.cpp @@ -0,0 +1,764 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: tracks VB allocations (and compressed/uncompressed vertex memory usage) +// +//===========================================================================// + +#include "materialsystem/imaterial.h" +#include "imeshdx8.h" +#include "convar.h" +#include "tier1/utlhash.h" +#include "tier1/utlstack.h" + +#include "materialsystem/ivballoctracker.h" + + +//----------------------------------------------------------------------------- +// +// Types +// +//----------------------------------------------------------------------------- + +#if ENABLE_VB_ALLOC_TRACKER + +// FIXME: combine this into the lower bits of VertexFormat_t +typedef uint64 VertexElementMap_t; + +enum Saving_t +{ + SAVING_COMPRESSION = 0, + SAVING_REMOVAL = 1, + SAVING_ALIGNMENT = 2 +}; + +struct ElementData +{ + VertexElement_t element; + int uncompressed; // uncompressed vertex size + int currentCompressed; // current compressed vertex element size + int idealCompressed; // ideal future compressed vertex element size + const char *name; +}; + +class CounterData +{ +public: + CounterData() : m_memCount( 0 ), m_vertCount( 0 ), m_paddingCount( 0 ) + { + for ( int i = 0; i < VERTEX_ELEMENT_NUMELEMENTS; i++ ) + { + m_elementsCompressed[ i ] = 0; + m_elementsUncompressed[ i ] = 0; + } + m_AllocatorName[ 0 ] = 0; + } + + static const int MAX_NAME_SIZE = 128; + int m_memCount; + int m_vertCount; + int m_paddingCount; + int m_elementsCompressed[ VERTEX_ELEMENT_NUMELEMENTS ]; // Number of compressed verts using each element + int m_elementsUncompressed[ VERTEX_ELEMENT_NUMELEMENTS ]; // Number of uncompressed verts using each element + char m_AllocatorName[ MAX_NAME_SIZE ]; +}; + +class AllocData +{ +public: + AllocData( void * buffer, int bufferSize, VertexFormat_t fmt, int numVerts, int allocatorHash ) + : m_buffer( buffer ), m_bufferSize( bufferSize ), m_fmt( fmt ), m_numVerts( numVerts ), m_allocatorHash( allocatorHash ) {} + AllocData() : m_buffer( NULL ), m_bufferSize( 0 ), m_fmt( 0 ), m_numVerts( 0 ), m_allocatorHash( 0 ) {} + + VertexFormat_t m_fmt; + void * m_buffer; + int m_bufferSize; + int m_numVerts; + short m_allocatorHash; +}; + +typedef CUtlHashFixed < CounterData, 64 > CCounterTable; +typedef CUtlHashFixed < AllocData, 4096 > CAllocTable; +typedef CUtlStack < short > CAllocNameHashes; + +#endif // ENABLE_VB_ALLOC_TRACKER + + +class CVBAllocTracker : public IVBAllocTracker +{ +public: + virtual void CountVB( void * buffer, bool isDynamic, int bufferSize, int vertexSize, VertexFormat_t fmt ); + virtual void UnCountVB( void * buffer ); + virtual bool TrackMeshAllocations( const char * allocatorName ); + + void DumpVBAllocs(); + +#if ENABLE_VB_ALLOC_TRACKER + +public: + CVBAllocTracker() : m_bSuperSpew( false ) { m_MeshAllocatorName[0] = 0; } + +private: + + UtlHashFixedHandle_t TrackAlloc( void * buffer, int bufferSize, VertexFormat_t fmt, int numVerts, short allocatorHash ); + bool KillAlloc( void * buffer, int & bufferSize, VertexFormat_t & fmt, int & numVerts, short & allocatorHash ); + + UtlHashFixedHandle_t GetCounterHandle( const char * allocatorName, short allocatorHash ); + + void SpewElements( const char * allocatorName, short nameHash ); + int ComputeVertexSize( VertexElementMap_t map, VertexFormat_t fmt, bool compressed ); + VertexElementMap_t ComputeElementMap( VertexFormat_t fmt, int vertexSize, bool isDynamic ); + void UpdateElements( CounterData & data, VertexFormat_t fmt, int numVerts, int vertexSize, + bool isDynamic, bool isCompressed ); + + int ComputeAlignmentWastage( int bufferSize ); + void AddSaving( int & alreadySaved, int & yetToSave, const char *allocatorName, VertexElement_t element, Saving_t savingType ); + void SpewExpectedSavings( void ); + void UpdateData( const char * allocatorName, short allocatorKey, int bufferSize, VertexFormat_t fmt, + int numVerts, int vertexSize, bool isDynamic, bool isCompressed ); + + const char * GetNameString( int allocatorKey ); + void SpewData( const char * allocatorName, short nameHash = 0 ); + void SpewDataSometimes( int inc ); + + + static const int SPEW_RATE = 64; + static const int MAX_ALLOCATOR_NAME_SIZE = 128; + char m_MeshAllocatorName[ MAX_ALLOCATOR_NAME_SIZE ]; + bool m_bSuperSpew; + + CCounterTable m_VBCountTable; + CAllocTable m_VBAllocTable; + CAllocNameHashes m_VBTableNameHashes; + + // We use a mutex since allocation tracking is accessed from multiple loading threads. + // CThreadFastMutex is used as contention is expected to be low during loading. + CThreadFastMutex m_VBAllocMutex; +#endif // ENABLE_VB_ALLOC_TRACKER +}; + + +//----------------------------------------------------------------------------- +// +// Global data +// +//----------------------------------------------------------------------------- + +#if ENABLE_VB_ALLOC_TRACKER + +// FIXME: do this in a better way: +static const ElementData positionElement = { VERTEX_ELEMENT_POSITION, 12, 12, 8, "POSITION " }; // (UNDONE: need vertex shader to scale, may cause cracking w/ static props) +static const ElementData normalElement = { VERTEX_ELEMENT_NORMAL, 12, 4, 4, "NORMAL " }; // (UNDONE: PC (2x16-byte Ravi method) or 360 (D3DDECLTYPE_HEND3N)) +static const ElementData colorElement = { VERTEX_ELEMENT_COLOR, 4, 4, 4, "COLOR " }; // (already minimal) +static const ElementData specularElement = { VERTEX_ELEMENT_SPECULAR, 4, 4, 4, "SPECULAR " }; // (already minimal) +static const ElementData tangentSElement = { VERTEX_ELEMENT_TANGENT_S, 12, 12, 4, "TANGENT_S " }; // (all-but-unused) +static const ElementData tangentTElement = { VERTEX_ELEMENT_TANGENT_T, 12, 12, 4, "TANGENT_T " }; // (all-but-unused) +static const ElementData wrinkleElement = { VERTEX_ELEMENT_WRINKLE, 4, 4, 0, "WRINKLE " }; // (UNDONE: compress it as a SHORTN in Position.w - is it [0,1]?) +static const ElementData boneIndexElement = { VERTEX_ELEMENT_BONEINDEX, 4, 4, 4, "BONEINDEX " }; // (already minimal) +static const ElementData boneWeight1Element = { VERTEX_ELEMENT_BONEWEIGHTS1, 4, 4, 4, "BONEWEIGHT1 " }; // (unused) +static const ElementData boneWeight2Element = { VERTEX_ELEMENT_BONEWEIGHTS2, 8, 8, 4, "BONEWEIGHT2 " }; // (UNDONE: take care w.r.t cracking in flex regions) +static const ElementData boneWeight3Element = { VERTEX_ELEMENT_BONEWEIGHTS3, 12, 12, 8, "BONEWEIGHT3 " }; // (unused) +static const ElementData boneWeight4Element = { VERTEX_ELEMENT_BONEWEIGHTS4, 16, 16, 8, "BONEWEIGHT4 " }; // (unused) +static const ElementData userData1Element = { VERTEX_ELEMENT_USERDATA1, 4, 4, 4, "USERDATA1 " }; // (unused) +static const ElementData userData2Element = { VERTEX_ELEMENT_USERDATA2, 8, 8, 4, "USERDATA2 " }; // (unused) +static const ElementData userData3Element = { VERTEX_ELEMENT_USERDATA3, 12, 12, 4, "USERDATA3 " }; // (unused) +#if ( COMPRESSED_NORMALS_TYPE == COMPRESSED_NORMALS_SEPARATETANGENTS_SHORT2 ) +static const ElementData userData4Element = { VERTEX_ELEMENT_USERDATA4, 16, 4, 4, "USERDATA4 " }; // (UNDONE: PC (2x16-byte Ravi method) or 360 (D3DDECLTYPE_HEND3N)) +#else // ( COMPRESSED_NORMALS_TYPE == COMPRESSED_NORMALS_COMBINEDTANGENTS_UBYTE4 ) +static const ElementData userData4Element = { VERTEX_ELEMENT_USERDATA4, 16, 0, 0, "USERDATA4 " }; // (UNDONE: PC (2x16-byte Ravi method) or 360 (D3DDECLTYPE_HEND3N)) +#endif +static const ElementData texCoord1D0Element = { VERTEX_ELEMENT_TEXCOORD1D_0, 4, 4, 4, "TEXCOORD1D_0" }; // (not worth compressing) +static const ElementData texCoord1D1Element = { VERTEX_ELEMENT_TEXCOORD1D_1, 4, 4, 4, "TEXCOORD1D_1" }; // (not worth compressing) +static const ElementData texCoord1D2Element = { VERTEX_ELEMENT_TEXCOORD1D_2, 4, 4, 4, "TEXCOORD1D_2" }; // (not worth compressing) +static const ElementData texCoord1D3Element = { VERTEX_ELEMENT_TEXCOORD1D_3, 4, 4, 4, "TEXCOORD1D_3" }; // (not worth compressing) +static const ElementData texCoord1D4Element = { VERTEX_ELEMENT_TEXCOORD1D_4, 4, 4, 4, "TEXCOORD1D_4" }; // (not worth compressing) +static const ElementData texCoord1D5Element = { VERTEX_ELEMENT_TEXCOORD1D_5, 4, 4, 4, "TEXCOORD1D_5" }; // (not worth compressing) +static const ElementData texCoord1D6Element = { VERTEX_ELEMENT_TEXCOORD1D_6, 4, 4, 4, "TEXCOORD1D_6" }; // (not worth compressing) +static const ElementData texCoord1D7Element = { VERTEX_ELEMENT_TEXCOORD1D_7, 4, 4, 4, "TEXCOORD1D_7" }; // (not worth compressing) +static const ElementData texCoord2D0Element = { VERTEX_ELEMENT_TEXCOORD2D_0, 8, 8, 4, "TEXCOORD2D_0" }; // (UNDONE: need vertex shader to take scale, account for clamping) +static const ElementData texCoord2D1Element = { VERTEX_ELEMENT_TEXCOORD2D_1, 8, 8, 4, "TEXCOORD2D_1" }; // (UNDONE: need vertex shader to take scale, account for clamping) +static const ElementData texCoord2D2Element = { VERTEX_ELEMENT_TEXCOORD2D_2, 8, 8, 4, "TEXCOORD2D_2" }; // (all-but-unused) +static const ElementData texCoord2D3Element = { VERTEX_ELEMENT_TEXCOORD2D_3, 8, 8, 4, "TEXCOORD2D_3" }; // (unused) +static const ElementData texCoord2D4Element = { VERTEX_ELEMENT_TEXCOORD2D_4, 8, 8, 4, "TEXCOORD2D_4" }; // (unused) +static const ElementData texCoord2D5Element = { VERTEX_ELEMENT_TEXCOORD2D_5, 8, 8, 4, "TEXCOORD2D_5" }; // (unused) +static const ElementData texCoord2D6Element = { VERTEX_ELEMENT_TEXCOORD2D_6, 8, 8, 4, "TEXCOORD2D_6" }; // (unused) +static const ElementData texCoord2D7Element = { VERTEX_ELEMENT_TEXCOORD2D_7, 8, 8, 4, "TEXCOORD2D_7" }; // (unused) +static const ElementData texCoord3D0Element = { VERTEX_ELEMENT_TEXCOORD3D_0, 12, 12, 8, "TEXCOORD3D_0" }; // FIXME: used how much? (UNDONE: need vertex shader to take scale, account for clamping) +static const ElementData texCoord3D1Element = { VERTEX_ELEMENT_TEXCOORD3D_1, 12, 12, 8, "TEXCOORD3D_1" }; // FIXME: used how much? (UNDONE: need vertex shader to take scale, account for clamping) +static const ElementData texCoord3D2Element = { VERTEX_ELEMENT_TEXCOORD3D_2, 12, 12, 8, "TEXCOORD3D_2" }; // FIXME: used how much? (UNDONE: need vertex shader to take scale, account for clamping) +static const ElementData texCoord3D3Element = { VERTEX_ELEMENT_TEXCOORD3D_3, 12, 12, 8, "TEXCOORD3D_3" }; // FIXME: used how much? (UNDONE: need vertex shader to take scale, account for clamping) +static const ElementData texCoord3D4Element = { VERTEX_ELEMENT_TEXCOORD3D_4, 12, 12, 8, "TEXCOORD3D_4" }; // FIXME: used how much? (UNDONE: need vertex shader to take scale, account for clamping) +static const ElementData texCoord3D5Element = { VERTEX_ELEMENT_TEXCOORD3D_5, 12, 12, 8, "TEXCOORD3D_5" }; // FIXME: used how much? (UNDONE: need vertex shader to take scale, account for clamping) +static const ElementData texCoord3D6Element = { VERTEX_ELEMENT_TEXCOORD3D_6, 12, 12, 8, "TEXCOORD3D_6" }; // FIXME: used how much? (UNDONE: need vertex shader to take scale, account for clamping) +static const ElementData texCoord3D7Element = { VERTEX_ELEMENT_TEXCOORD3D_7, 12, 12, 8, "TEXCOORD3D_7" }; // FIXME: used how much? (UNDONE: need vertex shader to take scale, account for clamping) +static const ElementData texCoord4D0Element = { VERTEX_ELEMENT_TEXCOORD4D_0, 16, 16, 8, "TEXCOORD4D_0" }; // FIXME: used how much? (UNDONE: need vertex shader to take scale, account for clamping) +static const ElementData texCoord4D1Element = { VERTEX_ELEMENT_TEXCOORD4D_1, 16, 16, 8, "TEXCOORD4D_1" }; // FIXME: used how much? (UNDONE: need vertex shader to take scale, account for clamping) +static const ElementData texCoord4D2Element = { VERTEX_ELEMENT_TEXCOORD4D_2, 16, 16, 8, "TEXCOORD4D_2" }; // FIXME: used how much? (UNDONE: need vertex shader to take scale, account for clamping) +static const ElementData texCoord4D3Element = { VERTEX_ELEMENT_TEXCOORD4D_3, 16, 16, 8, "TEXCOORD4D_3" }; // FIXME: used how much? (UNDONE: need vertex shader to take scale, account for clamping) +static const ElementData texCoord4D4Element = { VERTEX_ELEMENT_TEXCOORD4D_4, 16, 16, 8, "TEXCOORD4D_4" }; // FIXME: used how much? (UNDONE: need vertex shader to take scale, account for clamping) +static const ElementData texCoord4D5Element = { VERTEX_ELEMENT_TEXCOORD4D_5, 16, 16, 8, "TEXCOORD4D_5" }; // FIXME: used how much? (UNDONE: need vertex shader to take scale, account for clamping) +static const ElementData texCoord4D6Element = { VERTEX_ELEMENT_TEXCOORD4D_6, 16, 16, 8, "TEXCOORD4D_6" }; // FIXME: used how much? (UNDONE: need vertex shader to take scale, account for clamping) +static const ElementData texCoord4D7Element = { VERTEX_ELEMENT_TEXCOORD4D_7, 16, 16, 8, "TEXCOORD4D_7" }; // FIXME: used how much? (UNDONE: need vertex shader to take scale, account for clamping) +static const ElementData elementTable[ VERTEX_ELEMENT_NUMELEMENTS ] = { positionElement, + normalElement, + colorElement, + specularElement, + tangentSElement, + tangentTElement, + wrinkleElement, + boneIndexElement, + boneWeight1Element, boneWeight2Element, boneWeight3Element, boneWeight4Element, + userData1Element, userData2Element, userData3Element, userData4Element, + texCoord1D0Element, texCoord1D1Element, texCoord1D2Element, texCoord1D3Element, texCoord1D4Element, texCoord1D5Element, texCoord1D6Element, texCoord1D7Element, + texCoord2D0Element, texCoord2D1Element, texCoord2D2Element, texCoord2D3Element, texCoord2D4Element, texCoord2D5Element, texCoord2D6Element, texCoord2D7Element, + texCoord3D0Element, texCoord3D1Element, texCoord3D2Element, texCoord3D3Element, texCoord3D4Element, texCoord3D5Element, texCoord3D6Element, texCoord3D7Element, + texCoord4D0Element, texCoord4D1Element, texCoord4D2Element, texCoord4D3Element, texCoord4D4Element, texCoord4D5Element, texCoord4D6Element, texCoord4D7Element, + }; + +static ConVar mem_vballocspew( "mem_vballocspew", "0", FCVAR_CHEAT, "How often to spew vertex buffer allocation stats - 1: every alloc, 2+: every 2+ allocs, 0: off" ); + +#endif // ENABLE_VB_ALLOC_TRACKER + +//----------------------------------------------------------------------------- +// Singleton instance exposed to the engine +//----------------------------------------------------------------------------- + +CVBAllocTracker g_VBAllocTrackerShaderAPI; +EXPOSE_SINGLE_INTERFACE_GLOBALVAR( CVBAllocTracker, IVBAllocTracker, + VB_ALLOC_TRACKER_INTERFACE_VERSION, g_VBAllocTrackerShaderAPI ); + +//----------------------------------------------------------------------------- +// +// VB alloc-tracking code starts here +// +//----------------------------------------------------------------------------- + +#if ENABLE_VB_ALLOC_TRACKER + +UtlHashFixedHandle_t CVBAllocTracker::TrackAlloc( void * buffer, int bufferSize, VertexFormat_t fmt, int numVerts, short allocatorHash ) +{ + AllocData newData( buffer, bufferSize, fmt, numVerts, allocatorHash ); + UtlHashFixedHandle_t handle = m_VBAllocTable.Insert( (int)buffer, newData ); + if ( handle == m_VBAllocTable.InvalidHandle() ) + { + Warning( "[VBMEM] VBMemAllocTable hash collision (grow table).\n" ); + } + return handle; +} + +bool CVBAllocTracker::KillAlloc( void * buffer, int & bufferSize, VertexFormat_t & fmt, int & numVerts, short & allocatorHash ) +{ + UtlHashFixedHandle_t handle = m_VBAllocTable.Find( (int)buffer ); + if ( handle != m_VBAllocTable.InvalidHandle() ) + { + AllocData & data = m_VBAllocTable.Element( handle ); + bufferSize = data.m_bufferSize; + fmt = data.m_fmt; + numVerts = data.m_numVerts; + allocatorHash = data.m_allocatorHash; + m_VBAllocTable.Remove( handle ); + return true; + } + Warning( "[VBMEM] VBMemAllocTable failed to find alloc entry...\n" ); + return false; +} + +UtlHashFixedHandle_t CVBAllocTracker::GetCounterHandle( const char * allocatorName, short allocatorHash ) +{ + UtlHashFixedHandle_t handle = m_VBCountTable.Find( allocatorHash ); + if ( handle == m_VBCountTable.InvalidHandle() ) + { + CounterData newData; + Assert( ( allocatorName != NULL ) && ( allocatorName[0] != 0 ) ); + V_strncpy( newData.m_AllocatorName, allocatorName, CounterData::MAX_NAME_SIZE ); + handle = m_VBCountTable.Insert( allocatorHash, newData ); + m_VBTableNameHashes.Push( allocatorHash ); + } + if ( handle == m_VBCountTable.InvalidHandle() ) + { + Warning( "[VBMEM] CounterData hash collision (grow table).\n" ); + } + return handle; +} + +void CheckForElementTableUpdates( const ElementData & element ) +{ + // Ensure that 'elementTable' gets updated if VertexElement_t ever changes: + int tableIndex = &element - &( elementTable[0] ); + Assert( tableIndex == element.element ); + if ( tableIndex != element.element ) + { + static int timesToSpew = 20; + if ( timesToSpew > 0 ) + { + Warning( "VertexElement_t structure has changed, ElementData table in cvballoctracker needs updating!\n" ); + timesToSpew--; + } + } +} + +void CVBAllocTracker::SpewElements( const char * allocatorName, short nameHash ) +{ + short allocatorHash = allocatorName ? HashString( allocatorName ) : nameHash; + UtlHashFixedHandle_t handle = GetCounterHandle( allocatorName, allocatorHash ); + if ( handle != m_VBCountTable.InvalidHandle() ) + { + CounterData & data = m_VBCountTable.Element( handle ); + int originalSum = 0, currentSum = 0, idealSum = 0; + for (int i = 0;i < VERTEX_ELEMENT_NUMELEMENTS;i++) + { + CheckForElementTableUpdates( elementTable[ i ] ); + int numCompressed = data.m_elementsCompressed[ i ]; + int numUncompressed = data.m_elementsUncompressed[ i ]; + int numVerts = numCompressed + numUncompressed; + originalSum += numVerts*elementTable[ i ].uncompressed; + currentSum += numCompressed*elementTable[ i ].currentCompressed + numUncompressed*elementTable[ i ].uncompressed; + idealSum += numVerts*elementTable[ i ].idealCompressed; + } + + if ( originalSum > 0 ) + { + Msg( "[VBMEM] ----elements (%s)----:\n", data.m_AllocatorName); + for (int i = 0;i < VERTEX_ELEMENT_NUMELEMENTS;i++) + { + // We count vertices (converted to bytes via elementTable) + int numCompressed = data.m_elementsCompressed[ i ]; + int numUncompressed = data.m_elementsUncompressed[ i ]; + int numVerts = numCompressed + numUncompressed; + const ElementData & elementData = elementTable[ i ]; + if ( numVerts > 0 ) + { + Msg( " element: %5.2f MB 'U', %5.2f MB 'C', %5.2f MB 'I', %6.2f MB 'D', %s\n", + numVerts*elementData.uncompressed / ( 1024.0f*1024.0f ), + ( numCompressed*elementData.currentCompressed + numUncompressed*elementData.uncompressed ) / ( 1024.0f*1024.0f ), + numVerts*elementData.idealCompressed / ( 1024.0f*1024.0f ), + -( numCompressed*elementData.currentCompressed + numUncompressed*elementData.uncompressed - numVerts*elementData.idealCompressed ) / ( 1024.0f*1024.0f ), + elementData.name ); + } + } + Msg( "[VBMEM] total: %5.2f MB 'U', %5.2f MB 'C', %5.2f MB 'I', %6.2f MB 'D'\n", + originalSum / ( 1024.0f*1024.0f ), + currentSum / ( 1024.0f*1024.0f ), + idealSum / ( 1024.0f*1024.0f ), + -( currentSum - idealSum ) / ( 1024.0f*1024.0f ) ); + Msg( "[VBMEM] ----elements (%s)----:\n", data.m_AllocatorName); + } + } +} + +int CVBAllocTracker::ComputeVertexSize( VertexElementMap_t map, VertexFormat_t fmt, bool compressed ) +{ + int vertexSize = 0; + for ( int i = 0;i < VERTEX_ELEMENT_NUMELEMENTS;i++ ) + { + const ElementData & element = elementTable[ i ]; + CheckForElementTableUpdates( element ); + VertexElementMap_t LSB = 1; + if ( map & ( LSB << i ) ) + { + vertexSize += compressed ? element.currentCompressed : element.uncompressed; + } + } + + // On PC (see CVertexBufferBase::ComputeVertexDescription() in meshbase.cpp) + // vertex strides are aligned to 16 bytes: + bool bCacheAlign = ( fmt & VERTEX_FORMAT_USE_EXACT_FORMAT ) == 0; + if ( bCacheAlign && ( vertexSize > 16 ) && IsPC() ) + { + vertexSize = (vertexSize + 0xF) & (~0xF); + } + + return vertexSize; +} + +VertexElementMap_t CVBAllocTracker::ComputeElementMap( VertexFormat_t fmt, int vertexSize, bool isDynamic ) +{ + VertexElementMap_t map = 0, LSB = 1; + if ( fmt & VERTEX_POSITION ) map |= LSB << VERTEX_ELEMENT_POSITION; + if ( fmt & VERTEX_NORMAL ) map |= LSB << VERTEX_ELEMENT_NORMAL; + if ( fmt & VERTEX_COLOR ) map |= LSB << VERTEX_ELEMENT_COLOR; + if ( fmt & VERTEX_SPECULAR ) map |= LSB << VERTEX_ELEMENT_SPECULAR; + if ( fmt & VERTEX_TANGENT_S ) map |= LSB << VERTEX_ELEMENT_TANGENT_S; + if ( fmt & VERTEX_TANGENT_T ) map |= LSB << VERTEX_ELEMENT_TANGENT_T; + if ( fmt & VERTEX_WRINKLE ) map |= LSB << VERTEX_ELEMENT_WRINKLE; + if ( fmt & VERTEX_BONE_INDEX) map |= LSB << VERTEX_ELEMENT_BONEINDEX; + int numBones = NumBoneWeights( fmt ); + if ( numBones > 0 ) map |= LSB << ( VERTEX_ELEMENT_BONEWEIGHTS1 + numBones - 1 ); + int userDataSize = UserDataSize( fmt ); + if ( userDataSize > 0 ) map |= LSB << ( VERTEX_ELEMENT_USERDATA1 + userDataSize - 1 ); + for ( int i = 0; i < VERTEX_MAX_TEXTURE_COORDINATES; ++i ) + { + VertexElement_t texCoordElements[4] = { VERTEX_ELEMENT_TEXCOORD1D_0, VERTEX_ELEMENT_TEXCOORD2D_0, VERTEX_ELEMENT_TEXCOORD3D_0, VERTEX_ELEMENT_TEXCOORD4D_0 }; + int nCoordSize = TexCoordSize( i, fmt ); + if ( nCoordSize > 0 ) + { + Assert( i < 4 ); + if ( i < 4 ) + { + map |= LSB << ( texCoordElements[ nCoordSize - 1 ] + i ); + } + } + } + + if ( map == 0 ) + { + if ( !isDynamic ) + { + // We expect all (non-dynamic) VB allocs to specify a vertex format + // Warning("[VBMEM] unknown vertex format\n"); + return 0; + } + } + else + { + if ( vertexSize != 0 ) + { + // Make sure elementTable above matches external computations of vertex size + // FIXME: make this assert dependent on whether the current VB is compressed or not + VertexCompressionType_t compressionType = CompressionType( fmt ); + bool isCompressedAlloc = ( compressionType == VERTEX_COMPRESSION_ON ); + // FIXME: once we've finalised which elements we're compressing for ship, update + // elementTable to reflect that and re-enable this assert for compressed verts + if ( !isCompressedAlloc ) + { + Assert( vertexSize == ComputeVertexSize( map, fmt, isCompressedAlloc ) ); + } + } + } + + return map; +} + +void CVBAllocTracker::UpdateElements( CounterData & data, VertexFormat_t fmt, int numVerts, int vertexSize, + bool isDynamic, bool isCompressed ) +{ + VertexElementMap_t map = ComputeElementMap( fmt, vertexSize, isDynamic ); + if ( map != 0 ) + { + for (int i = 0;i < VERTEX_ELEMENT_NUMELEMENTS;i++) + { + // Count vertices (get bytes from our elements table) + VertexElementMap_t LSB = 1; + if ( map & ( LSB << i ) ) + { + if ( isCompressed ) + data.m_elementsCompressed[ i ] += numVerts; + else + data.m_elementsUncompressed[ i ] += numVerts; + } + } + } +} + +int CVBAllocTracker::ComputeAlignmentWastage( int bufferSize ) +{ + if ( !IsX360() ) + return 0; + + // VBs are 4KB-aligned on 360, so we waste thiiiiiis much: + return ( ( 4096 - (bufferSize & 4095)) & 4095 ); +} + +void CVBAllocTracker::AddSaving( int & alreadySaved, int & yetToSave, const char *allocatorName, VertexElement_t element, Saving_t savingType ) +{ + UtlHashFixedHandle_t handle = GetCounterHandle( allocatorName, HashString( allocatorName ) ); + if ( handle != m_VBCountTable.InvalidHandle() ) + { + CheckForElementTableUpdates( elementTable[ element ] ); + CounterData & counterData = m_VBCountTable.Element( handle ); + const ElementData & elementData = elementTable[ element ]; + int numVerts = counterData.m_vertCount; + int numCompressed = counterData.m_elementsCompressed[ element ]; + int numUncompressed = counterData.m_elementsUncompressed[ element ]; + switch( savingType ) + { + case SAVING_COMPRESSION: + alreadySaved += numCompressed*( elementData.uncompressed - elementData.currentCompressed ); + yetToSave += numUncompressed*( elementData.uncompressed - elementData.currentCompressed ); + break; + case SAVING_REMOVAL: + alreadySaved += elementData.uncompressed*( numVerts - ( numUncompressed + numCompressed ) ); + yetToSave += numUncompressed*elementData.uncompressed + numCompressed*elementData.uncompressed; + break; + case SAVING_ALIGNMENT: + yetToSave += counterData.m_paddingCount; + break; + default: + Assert(0); + break; + } + } +} + +void CVBAllocTracker::SpewExpectedSavings( void ) +{ + int alreadySaved = 0, yetToSave = 0; + + // We have removed bone weights+indices from static props + AddSaving( alreadySaved, yetToSave, "R_StudioCreateStaticMeshes (prop_static)", VERTEX_ELEMENT_BONEWEIGHTS2, SAVING_REMOVAL ); + AddSaving( alreadySaved, yetToSave, "R_StudioCreateStaticMeshes (prop_static)", VERTEX_ELEMENT_BONEINDEX, SAVING_REMOVAL ); + // We have removed vertex colors from all models (color should only ever be in stream1, for static vertex lighting) + AddSaving( alreadySaved, yetToSave, "R_StudioCreateStaticMeshes (prop_dynamic)", VERTEX_ELEMENT_COLOR, SAVING_REMOVAL ); + AddSaving( alreadySaved, yetToSave, "R_StudioCreateStaticMeshes (prop_static)", VERTEX_ELEMENT_COLOR, SAVING_REMOVAL ); + AddSaving( alreadySaved, yetToSave, "R_StudioCreateStaticMeshes (character)", VERTEX_ELEMENT_COLOR, SAVING_REMOVAL ); + + // We expect to compress texcoords (DONE: normals+tangents, boneweights) for all studiomdls + AddSaving( alreadySaved, yetToSave, "R_StudioCreateStaticMeshes (prop_dynamic)", VERTEX_ELEMENT_NORMAL, SAVING_COMPRESSION ); + AddSaving( alreadySaved, yetToSave, "R_StudioCreateStaticMeshes (prop_static)", VERTEX_ELEMENT_NORMAL, SAVING_COMPRESSION ); + AddSaving( alreadySaved, yetToSave, "R_StudioCreateStaticMeshes (character)", VERTEX_ELEMENT_NORMAL, SAVING_COMPRESSION ); + AddSaving( alreadySaved, yetToSave, "R_StudioCreateStaticMeshes (prop_dynamic)", VERTEX_ELEMENT_USERDATA4, SAVING_COMPRESSION ); + AddSaving( alreadySaved, yetToSave, "R_StudioCreateStaticMeshes (prop_static)", VERTEX_ELEMENT_USERDATA4, SAVING_COMPRESSION ); + AddSaving( alreadySaved, yetToSave, "R_StudioCreateStaticMeshes (character)", VERTEX_ELEMENT_USERDATA4, SAVING_COMPRESSION ); + AddSaving( alreadySaved, yetToSave, "R_StudioCreateStaticMeshes (prop_dynamic)", VERTEX_ELEMENT_TEXCOORD2D_0, SAVING_COMPRESSION ); + AddSaving( alreadySaved, yetToSave, "R_StudioCreateStaticMeshes (prop_static)", VERTEX_ELEMENT_TEXCOORD2D_0, SAVING_COMPRESSION ); + AddSaving( alreadySaved, yetToSave, "R_StudioCreateStaticMeshes (character)", VERTEX_ELEMENT_TEXCOORD2D_0, SAVING_COMPRESSION ); + AddSaving( alreadySaved, yetToSave, "R_StudioCreateStaticMeshes (character)", VERTEX_ELEMENT_BONEWEIGHTS1, SAVING_COMPRESSION ); + AddSaving( alreadySaved, yetToSave, "R_StudioCreateStaticMeshes (character)", VERTEX_ELEMENT_BONEWEIGHTS2, SAVING_COMPRESSION ); + AddSaving( alreadySaved, yetToSave, "R_StudioCreateStaticMeshes (prop_dynamic)", VERTEX_ELEMENT_BONEWEIGHTS1, SAVING_COMPRESSION ); + AddSaving( alreadySaved, yetToSave, "R_StudioCreateStaticMeshes (prop_dynamic)", VERTEX_ELEMENT_BONEWEIGHTS2, SAVING_COMPRESSION ); + + // UNDONE: compress bone weights for studiomdls? (issue: possible flex artifacts, but 2xSHORTN probably ok) + // UNDONE: compress positions (+wrinkle) for studiomdls? (issue: possible flex artifacts) + // UNDONE: disable tangents for non-bumped models (issue: forcedmaterialoverride support... don't think that needs tangents, though + // however, if we use UBYTE4 normal+tangent encoding, removing tangents saves nothing) + + if ( IsX360() ) + { + // We expect to avoid 4-KB-alignment wastage for color meshes, by allocating them + // out of a single, shared VB and adding per-mesh offsets in vertex shaders + AddSaving( alreadySaved, yetToSave, "CColorMeshData::CreateResource", VERTEX_ELEMENT_USERDATA4, SAVING_ALIGNMENT ); + } + + Msg("[VBMEM]\n"); + Msg("[VBMEM] Total expected memory saving by disabling/compressing vertex elements: %6.2f MB\n", yetToSave / ( 1024.0f*1024.0f ) ); + Msg("[VBMEM] ( total memory already saved: %6.2f MB)\n", alreadySaved / ( 1024.0f*1024.0f ) ); + Msg("[VBMEM] - compression of model texcoords, [DONE: normals+tangents, bone weights]\n" ); + Msg("[VBMEM] - avoidance of 4-KB alignment wastage for color meshes (on 360)\n" ); + Msg("[VBMEM] - [DONE: removal of unneeded bone weights+indices on models]\n" ); + Msg("[VBMEM]\n"); +} + +void CVBAllocTracker::UpdateData( const char * allocatorName, short allocatorKey, int bufferSize, VertexFormat_t fmt, + int numVerts, int vertexSize, bool isDynamic, bool isCompressed ) +{ + UtlHashFixedHandle_t handle = GetCounterHandle( allocatorName, allocatorKey ); + if ( handle != m_VBCountTable.InvalidHandle() ) + { + CounterData & data = m_VBCountTable.Element( handle ); + data.m_memCount += bufferSize; + Assert( data.m_memCount >= 0 ); + data.m_vertCount += numVerts; + Assert( data.m_vertCount >= 0 ); + data.m_paddingCount += ( bufferSize < 0 ? -1 : +1 )*ComputeAlignmentWastage( abs( bufferSize ) ); + UpdateElements( data, fmt, numVerts, vertexSize, isDynamic, isCompressed ); + } +} + +const char * CVBAllocTracker::GetNameString( int allocatorKey ) +{ + UtlHashFixedHandle_t handle = GetCounterHandle( NULL, allocatorKey ); + if ( handle != m_VBCountTable.InvalidHandle() ) + { + CounterData & data = m_VBCountTable.Element( handle ); + return data.m_AllocatorName; + } + return "null"; +} + +void CVBAllocTracker::SpewData( const char * allocatorName, short nameHash ) +{ + short allocatorHash = allocatorName ? HashString( allocatorName ) : nameHash; + UtlHashFixedHandle_t handle = GetCounterHandle( allocatorName, allocatorHash ); + if ( handle != m_VBCountTable.InvalidHandle() ) + { + CounterData & data = m_VBCountTable.Element( handle ); + if ( data.m_memCount > 0 ) + { + Msg("[VBMEM] running mem usage: (%5.2f M-verts) %6.2f MB | '%s'\n", + data.m_vertCount / ( 1024.0f*1024.0f ), + data.m_memCount / ( 1024.0f*1024.0f ), + data.m_AllocatorName ); + } + if ( data.m_paddingCount > 0 ) + { + Msg("[VBMEM] 4KB VB alignment wastage: %6.2f MB | '%s'\n", + data.m_paddingCount / ( 1024.0f*1024.0f ), + data.m_AllocatorName ); + } + } +} + +void CVBAllocTracker::SpewDataSometimes( int inc ) +{ + static int count = 0; + + if ( inc < 0 ) count += inc; + Assert( count >= 0 ); + + int period = mem_vballocspew.GetInt(); + if ( period >= 1 ) + { + if ( ( count % period ) == 0 ) + { + Msg( "[VBMEM] Status after %d VB allocs:\n", count ); + //#define ROUND_UP( _x_ ) ( ( ( _x_ ) + 31 ) & 31 ) + //Msg( "[VBMEM] Conservative estimate of mem used to track allocs: %d\n", 4096*ROUND_UP( 4 + sizeof( CUtlPtrLinkedList ) ) + count*ROUND_UP( sizeof( AllocData ) + 8 ) ); + SpewData( "total_static" ); + SpewData( "unknown" ); + } + } + + if ( inc > 0 ) count += inc; +} + +void CVBAllocTracker::DumpVBAllocs() +{ + m_VBAllocMutex.Lock(); + + Msg("[VBMEM] ----running totals----\n" ); + for ( int i = ( m_VBTableNameHashes.Count() - 1 ); i >= 0; i-- ) + { + short nameHash = m_VBTableNameHashes.Element( i ); + SpewElements( NULL, nameHash ); + } + + Msg("[VBMEM]\n"); + Msg("[VBMEM] 'U' - original memory usage (all vertices uncompressed)\n" ); + Msg("[VBMEM] 'C' - current memory usage (some compression)\n" ); + Msg("[VBMEM] 'I' - ideal memory usage (all verts maximally compressed)\n" ); + Msg("[VBMEM] 'D' - difference between C and I (-> how much more compression could save)\n" ); + Msg("[VBMEM] 'W' - memory wasted due to 4-KB vertex buffer alignment\n" ); + Msg("[VBMEM]\n"); + for ( int i = ( m_VBTableNameHashes.Count() - 1 ); i >= 0; i-- ) + { + short nameHash = m_VBTableNameHashes.Element( i ); + SpewData( NULL, nameHash ); + } + SpewExpectedSavings(); + Msg("[VBMEM] ----running totals----\n" ); + + m_VBAllocMutex.Unlock(); +} + +#endif // ENABLE_VB_ALLOC_TRACKER + +void CVBAllocTracker::CountVB( void * buffer, bool isDynamic, int bufferSize, int vertexSize, VertexFormat_t fmt ) +{ +#if ENABLE_VB_ALLOC_TRACKER + m_VBAllocMutex.Lock(); + + // Update VB memory counts for the relevant allocation type + // (NOTE: we have 'unknown', 'dynamic' and 'total' counts) + const char * allocatorName = ( m_MeshAllocatorName[0] == 0 ) ? "unknown" : m_MeshAllocatorName; + if ( isDynamic ) allocatorName = "total_dynamic"; + int numVerts = ( vertexSize > 0 ) ? ( bufferSize / vertexSize ) : 0; + short totalStaticKey = HashString( "total_static" ); + short key = HashString( allocatorName ); + bool isCompressed = ( VERTEX_COMPRESSION_NONE != CompressionType( fmt ) ); + + if ( m_MeshAllocatorName[0] == 0 ) + { + Warning("[VBMEM] unknown allocation!\n"); + } + + // Add to the VB memory counters + TrackAlloc( buffer, bufferSize, fmt, numVerts, key ); + if ( !isDynamic ) + { + // Keep dynamic allocs out of the total (dynamic VBs don't get compressed) + UpdateData( "total_static", totalStaticKey, bufferSize, fmt, numVerts, vertexSize, isDynamic, isCompressed ); + } + UpdateData( allocatorName, key, bufferSize, fmt, numVerts, vertexSize, isDynamic, isCompressed ); + + if ( m_bSuperSpew ) + { + // Spew every alloc + Msg( "[VBMEM] VB-alloc | %6.2f MB | %s | %s\n", bufferSize / ( 1024.0f*1024.0f ), ( isDynamic ? "DYNamic" : " STAtic" ), allocatorName ); + SpewData( allocatorName ); + } + SpewDataSometimes( +1 ); + + m_VBAllocMutex.Unlock(); +#endif // ENABLE_VB_ALLOC_TRACKER +} + +void CVBAllocTracker::UnCountVB( void * buffer ) +{ +#if ENABLE_VB_ALLOC_TRACKER + m_VBAllocMutex.Lock(); + + short totalKey = HashString( "total_static" ); + short dynamicKey = HashString( "total_dynamic" ); + int bufferSize; + VertexFormat_t fmt; + int numVerts; + short key; + + // We have to store allocation data because the caller often doesn't know what it alloc'd :o/ + if ( KillAlloc( buffer, bufferSize, fmt, numVerts, key ) ) + { + bool isCompressed = ( VERTEX_COMPRESSION_NONE != CompressionType( fmt ) ); + bool isDynamic = ( key == dynamicKey ); + + // Subtract from the VB memory counters + if ( !isDynamic ) + { + UpdateData( NULL, totalKey, -bufferSize, fmt, -numVerts, 0, isDynamic, isCompressed ); + } + UpdateData( NULL, key, -bufferSize, fmt, -numVerts, 0, isDynamic, isCompressed ); + + const char * nameString = GetNameString( key ); + + if ( m_bSuperSpew ) + { + Msg( "[VBMEM] VB-free | %6.2f MB | %s | %s\n", bufferSize / ( 1024.0f*1024.0f ), ( isDynamic ? "DYNamic" : " STAtic" ), nameString ); + SpewData( nameString ); + } + SpewDataSometimes( -1 ); + } + + m_VBAllocMutex.Unlock(); +#endif // ENABLE_VB_ALLOC_TRACKER +} + +bool CVBAllocTracker::TrackMeshAllocations( const char * allocatorName ) +{ +#if ENABLE_VB_ALLOC_TRACKER + // Tracks mesh allocations by name (set this before an alloc, clear it after) + + if ( m_MeshAllocatorName[ 0 ] ) + { + return true; + } + + m_VBAllocMutex.Lock(); + + if ( allocatorName ) + { + Assert( m_MeshAllocatorName[0] == 0 ); + V_strncpy( m_MeshAllocatorName, allocatorName, MAX_ALLOCATOR_NAME_SIZE ); + } + else + { + m_MeshAllocatorName[0] = 0; + } + + m_VBAllocMutex.Unlock(); +#endif // ENABLE_VB_ALLOC_TRACKER + + return false; +} + +#ifndef RETAIL + +static void CC_DumpVBMemAllocs() +{ +#if ( ENABLE_VB_ALLOC_TRACKER == 0 ) + Warning( "ENABLE_VB_ALLOC_TRACKER must be 1 to enable VB mem alloc tracking\n"); +#else + g_VBAllocTrackerShaderAPI.DumpVBAllocs(); +#endif +} + +static ConCommand mem_dumpvballocs( "mem_dumpvballocs", CC_DumpVBMemAllocs, "Dump VB memory allocation stats.", FCVAR_CHEAT ); + +#endif // RETAIL diff --git a/materialsystem/shaderapidx9/d3d_async.cpp b/materialsystem/shaderapidx9/d3d_async.cpp new file mode 100644 index 0000000..6c9cf8b --- /dev/null +++ b/materialsystem/shaderapidx9/d3d_async.cpp @@ -0,0 +1,825 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// methods for muti-core dx9 threading +//===========================================================================// + +#ifdef D3D_ASYNC_SUPPORTED + +#include "glmgr/dxabstract.h" +#include "utlsymbol.h" +#include "utlvector.h" +#include "utldict.h" +#include "utlbuffer.h" +#include "UtlStringMap.h" +#include "locald3dtypes.h" +#include "shaderapidx8_global.h" +#include "recording.h" +#include "tier0/vprof.h" +#include "materialsystem/imaterialsystem.h" +#include "materialsystem/imaterialsystemhardwareconfig.h" +#include "shaderapidx8.h" +#include "materialsystem/IShader.h" +#include "utllinkedlist.h" +#include "IShaderSystem.h" +#include "tier0/fasttimer.h" +#include +#include "convar.h" +#include "materialsystem/shader_vcs_version.h" +#include "datacache/idatacache.h" +#include "winutils.h" + +#include "tier0/memdbgon.h" + +#if SHADERAPI_USE_SMP + +// Set this to 1 to get vprof nodes for playing back the command stream. This is good for counting calls in a frame, etc. +#define SHADERAPI_VPROF_BUFFER_PLAYBACK 1 + +#if SHADERAPI_VPROF_BUFFER_PLAYBACK && SHADERAPI_BUFFER_D3DCALLS +#define VPROF_BUFFER_PLAYBACK(name) VPROF(name) +#else +#define VPROF_BUFFER_PLAYBACK(name) ((void)0) +#endif + +template class FixedWorkQueue +{ + T Data[QSIZE]; + char pad0[256]; + volatile int n_added; + int write_index; + char pad1[256]; // make sure these don't share cache lines + volatile int n_removed; + int read_index; + +public: + FixedWorkQueue(void) + { + read_index=write_index=0; + n_added=n_removed=0; + } + + int IsEmpty(void) + { + return (n_added==n_removed); + } + + int IsFull(void) + { + return (n_added-n_removed)>=QSIZE; + } + + T GetWorkUnit(void) + { + if (IsEmpty()) + return 0; + return Data[read_index]; + } + + void MarkUnitDone(void) + { + n_removed++; + read_index=(read_index+1) % QSIZE; + } + + void AddWorkUnit(T unit) + { +#if SHADERAPI_BUFFER_D3DCALLS + Assert( !IsFull() ); +#else + while (IsFull()) + Sleep(0); +#endif + Data[write_index]=unit; + n_added++; + write_index=(write_index+1) % QSIZE; + } +}; + + +#if SHADERAPI_BUFFER_D3DCALLS +#define N_PUSH_BUFFERS 5000 +#else +#define N_PUSH_BUFFERS 500 +#endif +static volatile PushBuffer *PushBuffers[N_PUSH_BUFFERS]; +FixedWorkQueue PBQueue; + + + +#ifdef WIN32 +void __cdecl OurThreadInit( void * ourthis ) +#else +unsigned int OurThreadInit( void * ourthis ) +#endif +{ + (( D3DDeviceWrapper *) ourthis )->RunThread(); +#ifndef WIN32 + return 0; +#endif +} + +void D3DDeviceWrapper::RunThread( void ) +{ + SetThreadAffinityMask(GetCurrentThread(), 2); + for(;;) + { + PushBuffer *Pbuf=PBQueue.GetWorkUnit(); + if (! Pbuf) + { + ; //Sleep(0); + } + else + { + ExecutePushBuffer( Pbuf ); + PBQueue.MarkUnitDone(); + Pbuf->m_State = PUSHBUFFER_AVAILABLE; + } + } +} + +#if SHADERAPI_BUFFER_D3DCALLS +void D3DDeviceWrapper::ExecuteAllWork( void ) +{ + if( !m_bBufferingD3DCalls ) + return; + VPROF_BUDGET( "ExecuteAllWork", "ExecuteAllWork" ); + SubmitPushBufferAndGetANewOne(); + PushBuffer *Pbuf; + while( ( Pbuf = PBQueue.GetWorkUnit() ) != NULL ) + { + ExecutePushBuffer( Pbuf ); + PBQueue.MarkUnitDone(); + Pbuf->m_State = PUSHBUFFER_AVAILABLE; + } + m_bBufferingD3DCalls = false; +} +#endif + +#if SHADERAPI_BUFFER_D3DCALLS +#define MAXIMUM_NUMBER_OF_BUFFERS_LOCKED_AT_ONCE 1600 +#else +#define MAXIMUM_NUMBER_OF_BUFFERS_LOCKED_AT_ONCE 16 +#endif + +struct RememberedPointer +{ + void *m_pKey; + void *m_pRememberedPtr; +} RememberedPointerHistory[MAXIMUM_NUMBER_OF_BUFFERS_LOCKED_AT_ONCE]; + +void D3DDeviceWrapper::SetASyncMode( bool onoff ) +{ +#if SHADERAPI_BUFFER_D3DCALLS + if ( onoff ) + { + m_bBufferingD3DCalls = true; + // allocate push buffers if we need to + if ( PushBuffers[0] == NULL ) + { + for(int i=0; im_State == PUSHBUFFER_AVAILABLE ) + { + PushBuffers[i]->m_State = newstate; + return (PushBuffer *) PushBuffers[i]; + } + } + // hmm, out of push buffers. better sleep and try again later + SubmitPushBufferAndGetANewOne(); + Sleep(0); + } +} + +void D3DDeviceWrapper::GetPushBuffer( void ) +{ + VPROF_BUFFER_PLAYBACK( "D3DDeviceWrapper::GetPushBuffer" ); + m_pCurPushBuffer = FindFreePushBuffer( PUSHBUFFER_BEING_FILLED ); + m_pOutputPtr = m_pCurPushBuffer->m_BufferData; + m_PushBufferFreeSlots = PUSHBUFFER_NELEMS - 1; // leave room for end marker +} + +void D3DDeviceWrapper::SubmitPushBufferAndGetANewOne( void ) +{ + VPROF_BUFFER_PLAYBACK( "D3DDeviceWrapper::SubmitPushBufferAndGetANewOne" ); + + // submit the current push buffer + if ( m_pCurPushBuffer ) + { + if (m_pOutputPtr == m_pCurPushBuffer->m_BufferData) // haven't done anyting, don't bother + return; + *(m_pOutputPtr) = PBCMD_END; // mark end + m_pCurPushBuffer->m_State = PUSHBUFFER_SUBMITTED; + // here, enqueue for task + PBQueue.AddWorkUnit( m_pCurPushBuffer ); + } + GetPushBuffer(); +} + +void D3DDeviceWrapper::SubmitIfNotBusy( void ) +{ + VPROF_BUFFER_PLAYBACK( "D3DDeviceWrapper::SubmitIfNotBusy" ); + if ( PBQueue.IsEmpty() ) + SubmitPushBufferAndGetANewOne(); +} + + +void D3DDeviceWrapper::Synchronize( void ) +{ +#if SHADERAPI_BUFFER_D3DCALLS + if( m_bBufferingD3DCalls ) + { + Assert( 0 ); + Error( "Synchronize not supported with SHADERAPI_BUFFER_D3DCALLS" ); + } + return; +#endif + if ( ASyncMode()) + { + SubmitPushBufferAndGetANewOne(); + // here, wait for queue to become empty + while (! PBQueue.IsEmpty() ) + { + // Sleep(1); + } + } +} + +void D3DDeviceWrapper::AsynchronousLock( IDirect3DIndexBuffer9* ib, + size_t offset, size_t size, void **ptr, + DWORD flags, + LockedBufferContext *lb) +{ + VPROF_BUFFER_PLAYBACK( "D3DDeviceWrapper::AsynchronousLock index" ); + + if ( size <= sizeof( PushBuffers[0]->m_BufferData )) + { + // can use one of our pushbuffers for this + lb->m_pPushBuffer = FindFreePushBuffer( PUSHBUFFER_BEING_USED_FOR_LOCKEDDATA ); + *(ptr) = lb->m_pPushBuffer->m_BufferData; + Assert( *ptr ); + lb->m_pMallocedMemory = NULL; + } + else // out of buffer space or size too big + { + lb->m_pPushBuffer = NULL; + lb->m_pMallocedMemory = new uint8 [ size ]; + *(ptr) = lb->m_pMallocedMemory; + } + // now, push lock commands + AllocatePushBufferSpace( 1+N_DWORDS_IN_PTR+3 ); + *(m_pOutputPtr++)=PBCMD_ASYNC_LOCK_IB; + *((LPDIRECT3DINDEXBUFFER *) m_pOutputPtr)=ib; + m_pOutputPtr+=N_DWORDS_IN_PTR; + *(m_pOutputPtr++)=offset; + *(m_pOutputPtr++)=size; + *(m_pOutputPtr++)=flags; +} + +void D3DDeviceWrapper::AsynchronousLock( IDirect3DVertexBuffer9* vb, + size_t offset, size_t size, void **ptr, + DWORD flags, + LockedBufferContext *lb) +{ + VPROF_BUFFER_PLAYBACK( "D3DDeviceWrapper::AsynchronousLock vertex" ); + // we have commands in flight. Need to use temporary memory for this lock. + // if the size needed is < the amount of space in a push buffer, we can use + // a push buffer for the buffer. Otherwise, we're going to malloc one. + if ( size <= sizeof( PushBuffers[0]->m_BufferData )) + { + // can use one of our pushbuffers for this + lb->m_pPushBuffer = FindFreePushBuffer( PUSHBUFFER_BEING_USED_FOR_LOCKEDDATA ); + *(ptr) = lb->m_pPushBuffer->m_BufferData; + Assert( *ptr ); + lb->m_pMallocedMemory = NULL; + } + else // out of buffer space or size too big + { + lb->m_pPushBuffer = NULL; + lb->m_pMallocedMemory = new uint8 [ size ]; + *(ptr) = lb->m_pMallocedMemory; + } + // now, push lock commands + AllocatePushBufferSpace( 1+N_DWORDS_IN_PTR+3 ); + *(m_pOutputPtr++)=PBCMD_ASYNC_LOCK_VB; + *((LPDIRECT3DVERTEXBUFFER *) m_pOutputPtr)=vb; + m_pOutputPtr+=N_DWORDS_IN_PTR; + *(m_pOutputPtr++)=offset; + *(m_pOutputPtr++)=size; + *(m_pOutputPtr++)=flags; +} + + + +inline void RememberLockedPointer( void *key, void *value ) +{ + VPROF_BUFFER_PLAYBACK( "RememberLockedPointer" ); + int repl=-1; + int i; + for(i=0;iLock( offset, size, &locked_ptr, flags ); + RememberLockedPointer( vb, locked_ptr ); +} + +void D3DDeviceWrapper::HandleAsynchronousUnLockVBCommand( uint32 const *dptr ) +{ + dptr++; + LPDIRECT3DVERTEXBUFFER vb=*((LPDIRECT3DVERTEXBUFFER *) dptr); + dptr+=N_DWORDS_IN_PTR; + LockedBufferContext lb=*((LockedBufferContext *) dptr); + dptr+=N_DWORDS( LockedBufferContext ); + size_t unlock_size=*( dptr++ ); + void *locked_data=RecallLockedPointer( vb ); + Assert( locked_data ); + if (lb.m_pPushBuffer) + { + Assert( ! lb.m_pMallocedMemory ); + if ( locked_data ) + memcpy( locked_data, lb.m_pPushBuffer->m_BufferData, unlock_size ); + lb.m_pPushBuffer->m_State = PUSHBUFFER_AVAILABLE; + } + else if ( lb.m_pMallocedMemory ) + { + Assert( ! lb.m_pPushBuffer ); + if ( locked_data ) + memcpy( locked_data, lb.m_pMallocedMemory, unlock_size ); + delete[] ((uint8 *) lb.m_pMallocedMemory); + } + // now, actually unlock + RememberLockedPointer( vb, NULL ); + vb->Unlock(); +} + +void D3DDeviceWrapper::HandleAsynchronousLockIBCommand( uint32 const *dptr ) +{ + dptr++; + LPDIRECT3DINDEXBUFFER ib=*((LPDIRECT3DINDEXBUFFER *) dptr); + Assert( ib ); + dptr+=N_DWORDS_IN_PTR; + uint32 offset=*(dptr++); + uint32 size=*(dptr++); + uint32 flags=*(dptr++); + void *locked_ptr=0; + ib->Lock( offset, size, &locked_ptr, flags ); + RememberLockedPointer( ib, locked_ptr ); +} + +void D3DDeviceWrapper::HandleAsynchronousUnLockIBCommand( uint32 const *dptr ) +{ + dptr++; + LPDIRECT3DINDEXBUFFER ib=*((LPDIRECT3DINDEXBUFFER *) dptr); + dptr+=N_DWORDS_IN_PTR; + LockedBufferContext lb=*((LockedBufferContext *) dptr); + dptr+=N_DWORDS( LockedBufferContext ); + size_t unlock_size=*( dptr++ ); + void *locked_data=RecallLockedPointer( ib ); + Assert( locked_data ); + if (lb.m_pPushBuffer) + { + Assert( ! lb.m_pMallocedMemory ); + if ( locked_data ) + memcpy( locked_data, lb.m_pPushBuffer->m_BufferData, unlock_size ); + lb.m_pPushBuffer->m_State = PUSHBUFFER_AVAILABLE; + } + else if ( lb.m_pMallocedMemory ) + { + Assert( ! lb.m_pPushBuffer ); + if ( locked_data ) + memcpy( locked_data, lb.m_pMallocedMemory, unlock_size ); + delete[] ((uint8 *) lb.m_pMallocedMemory); + } + // now, actually unlock + RememberLockedPointer( ib, NULL ); + ib->Unlock(); + +} + + +static inline void *FetchPtr( uint32 const *mem) +{ + void **p=(void **) mem; + return *p; +} + +#define CALC_STATS 1 +#if CALC_STATS +int n_commands_executed=0; +int n_pbs_executed=0; +#endif + +void D3DDeviceWrapper::ExecutePushBuffer( PushBuffer const* pb) +{ + VPROF_BUFFER_PLAYBACK( "D3DDeviceWrapper::ExecutePushBuffer" ); + uint32 const *dptr=pb->m_BufferData; + n_pbs_executed++; + for(;;) + { + n_commands_executed++; + switch( dptr[0] ) + { + case PBCMD_END: + { + VPROF_BUFFER_PLAYBACK( "END" ); + n_commands_executed--; // doesn't count + return; + } + + case PBCMD_SET_RENDERSTATE: + { + VPROF_BUFFER_PLAYBACK( "SET_RENDERSTATE" ); + Dx9Device()->SetRenderState((D3DRENDERSTATETYPE) dptr[1],dptr[2]); + dptr+=3; + break; + } + + case PBCMD_SET_SAMPLER_STATE: + { + VPROF_BUFFER_PLAYBACK( "SET_SAMPLER_STATE" ); + Dx9Device()->SetSamplerState(dptr[1], (D3DSAMPLERSTATETYPE) dptr[2], dptr[3]); + dptr+=4; + break; + } + + case PBCMD_DRAWPRIM: + { + VPROF_BUFFER_PLAYBACK( "DRAWPRIM" ); + + tmZone( TELEMETRY_LEVEL2, TMZF_NONE, "Dx9Device()->DrawPrimitive" ); + + Dx9Device()->DrawPrimitive( (D3DPRIMITIVETYPE) dptr[1], dptr[2], dptr[3] ); + dptr+=4; + break; + } + + case PBCMD_DRAWINDEXEDPRIM: + { + VPROF_BUFFER_PLAYBACK( "DRAWINDEXEDPRIM" ); + + tmZone( TELEMETRY_LEVEL2, TMZF_NONE, "Dx9Device()->DrawIndexedPrimitive" ); + + Dx9Device()->DrawIndexedPrimitive( (D3DPRIMITIVETYPE) dptr[1], dptr[2], dptr[3], + dptr[4], dptr[5], dptr[6]); + dptr+=7; + break; + } + + case PBCMD_SET_STREAM_SOURCE: + { + VPROF_BUFFER_PLAYBACK( "SET_STREAM_SOURCE" ); + Dx9Device()->SetStreamSource( dptr[1],(IDirect3DVertexBuffer9 *) FetchPtr(dptr+2), + dptr[3],dptr[4] ); + dptr += 4+N_DWORDS( IDirect3DVertexBuffer9 * ); + break; + } + + case PBCMD_SET_TEXTURE: + { + VPROF_BUFFER_PLAYBACK( "SET_TEXTURE" ); + Dx9Device()->SetTexture( dptr[1],(IDirect3DBaseTexture *) FetchPtr(dptr+2)); + dptr += 2+N_DWORDS_IN_PTR; + break; + } + + case PBCMD_SET_RENDER_TARGET: + { + VPROF_BUFFER_PLAYBACK( "SET_RENDER_TARGET" ); + Dx9Device()->SetRenderTarget( dptr[1],(IDirect3DSurface *) FetchPtr(dptr+2)); + dptr += 2+N_DWORDS_IN_PTR; + break; + } + + case PBCMD_SET_PIXEL_SHADER: + { + VPROF_BUFFER_PLAYBACK( "SET_PIXEL_SHADER" ); + Dx9Device()->SetPixelShader( (IDirect3DPixelShader9 *) FetchPtr(dptr+1)); + dptr += 1+N_DWORDS_IN_PTR; + break; + } + + case PBCMD_SET_INDICES: + { + VPROF_BUFFER_PLAYBACK( "SET_INDICES" ); + Dx9Device()->SetIndices( (IDirect3DIndexBuffer9*) FetchPtr(dptr+1)); + dptr += 1+N_DWORDS_IN_PTR; + break; + } + + case PBCMD_SET_DEPTH_STENCIL_SURFACE: + { + VPROF_BUFFER_PLAYBACK( "SET_DEPTH_STENCIL_SURFACE" ); + Dx9Device()->SetDepthStencilSurface( (IDirect3DSurface9*) FetchPtr(dptr+1)); + dptr += 1+N_DWORDS_IN_PTR; + break; + } + + case PBCMD_SETVIEWPORT: + { + VPROF_BUFFER_PLAYBACK( "SETVIEWPORT" ); + Dx9Device()->SetViewport( (D3DVIEWPORT9 const *) (dptr+1) ); + dptr += 1+N_DWORDS(D3DVIEWPORT9); + break; + } + + case PBCMD_SET_VERTEX_SHADER: + { + VPROF_BUFFER_PLAYBACK( "SET_VERTEX_SHADER" ); + Dx9Device()->SetVertexShader( (IDirect3DVertexShader9 *) FetchPtr(dptr+1)); + dptr += 1+N_DWORDS_IN_PTR; + break; + } + + case PBCMD_ASYNC_LOCK_VB: + { + VPROF_BUFFER_PLAYBACK( "ASYNC_LOCK_VB" ); + HandleAsynchronousLockVBCommand(dptr); + dptr+=1+N_DWORDS_IN_PTR+3; + break; + } + + case PBCMD_ASYNC_UNLOCK_VB: + { + VPROF_BUFFER_PLAYBACK( "ASYNC_UNLOCK_VB" ); + HandleAsynchronousUnLockVBCommand( dptr ); + dptr+=1+N_DWORDS_IN_PTR+N_DWORDS( LockedBufferContext )+1; + break; + } + + case PBCMD_ASYNC_LOCK_IB: + { + VPROF_BUFFER_PLAYBACK( "ASYNC_LOCK_IB" ); + HandleAsynchronousLockIBCommand(dptr); + dptr+=1+N_DWORDS_IN_PTR+3; + break; + } + + case PBCMD_ASYNC_UNLOCK_IB: + { + VPROF_BUFFER_PLAYBACK( "ASYNC_UNLOCK_IB" ); + HandleAsynchronousUnLockIBCommand( dptr ); + dptr+=1+N_DWORDS_IN_PTR+N_DWORDS( LockedBufferContext )+1; + break; + } + + case PBCMD_UNLOCK_VB: + { + VPROF_BUFFER_PLAYBACK( "UNLOCK_VB" ); + IDirect3DVertexBuffer9 *p=(IDirect3DVertexBuffer9 *) FetchPtr(dptr+1); + p->Unlock(); + dptr += 1+N_DWORDS_IN_PTR; + break; + } + case PBCMD_UNLOCK_IB: + { + VPROF_BUFFER_PLAYBACK( "UNLOCK_IB" ); + IDirect3DIndexBuffer9 *p=(IDirect3DIndexBuffer9 *) FetchPtr(dptr+1); + p->Unlock(); + dptr += 1+N_DWORDS_IN_PTR; + break; + } + case PBCMD_SET_VERTEX_SHADER_CONSTANT: + { + VPROF_BUFFER_PLAYBACK( "SET_VERTEX_SHADER_CONSTANT" ); + Dx9Device()->SetVertexShaderConstantF( dptr[1], (float const *) dptr+3, dptr[2]); + dptr += 3+4*dptr[2]; + break; + } + case PBCMD_SET_BOOLEAN_VERTEX_SHADER_CONSTANT: + { + VPROF_BUFFER_PLAYBACK( "SET_BOOLEAN_VERTEX_SHADER_CONSTANT" ); + Dx9Device()->SetVertexShaderConstantB( dptr[1], (int const *) dptr+3, dptr[2]); + dptr += 3+dptr[2]; + break; + } + + case PBCMD_SET_INTEGER_VERTEX_SHADER_CONSTANT: + { + VPROF_BUFFER_PLAYBACK( "SET_INTEGER_VERTEX_SHADER_CONSTANT" ); + Dx9Device()->SetVertexShaderConstantI( dptr[1], (int const *) dptr+3, dptr[2]); + dptr += 3+4*dptr[2]; + break; + } + + case PBCMD_SET_PIXEL_SHADER_CONSTANT: + { + VPROF_BUFFER_PLAYBACK( "SET_PIXEL_SHADER_CONSTANT" ); + Dx9Device()->SetPixelShaderConstantF( dptr[1], (float const *) dptr+3, dptr[2]); + dptr += 3+4*dptr[2]; + break; + } + case PBCMD_SET_BOOLEAN_PIXEL_SHADER_CONSTANT: + { + VPROF_BUFFER_PLAYBACK( "SET_BOOLEAN_PIXEL_SHADER_CONSTANT" ); + Dx9Device()->SetPixelShaderConstantB( dptr[1], (int const *) dptr+3, dptr[2]); + dptr += 3+dptr[2]; + break; + } + + case PBCMD_SET_INTEGER_PIXEL_SHADER_CONSTANT: + { + VPROF_BUFFER_PLAYBACK( "SET_INTEGER_PIXEL_SHADER_CONSTANT" ); + Dx9Device()->SetPixelShaderConstantI( dptr[1], (int const *) dptr+3, dptr[2]); + dptr += 3+4*dptr[2]; + break; + } + + case PBCMD_BEGIN_SCENE: + { + VPROF_BUFFER_PLAYBACK( "BEGIN_SCENE" ); + Dx9Device()->BeginScene(); + dptr++; + break; + } + + case PBCMD_END_SCENE: + { + VPROF_BUFFER_PLAYBACK( "END_SCENE" ); + Dx9Device()->EndScene(); + dptr++; + break; + } + + case PBCMD_CLEAR: + { + VPROF_BUFFER_PLAYBACK( "CLEAR" ); + dptr++; + int count=*(dptr++); + D3DRECT const *pRects=0; + if (count) + { + pRects=(D3DRECT const *) dptr; + dptr+=count*N_DWORDS( D3DRECT ); + } + int flags=*(dptr++); + D3DCOLOR color=*((D3DCOLOR const *) (dptr++)); + float z=*((float const *) (dptr++)); + int stencil=*(dptr++); + Dx9Device()->Clear( count, pRects, flags, color, z, stencil ); + break; + } + + case PBCMD_SET_VERTEXDECLARATION: + { + VPROF_BUFFER_PLAYBACK( "SET_VERTEXDECLARATION" ); + Dx9Device()->SetVertexDeclaration( (IDirect3DVertexDeclaration9 *) FetchPtr(dptr+1)); + dptr += 1+N_DWORDS_IN_PTR; + break; + } + + case PBCMD_SETCLIPPLANE: + { + VPROF_BUFFER_PLAYBACK( "SETCLIPPLANE" ); + Dx9Device()->SetClipPlane( dptr[1], (float const *) dptr+2 ); + dptr+=6; + } + break; + + case PBCMD_STRETCHRECT: + { + VPROF_BUFFER_PLAYBACK( "STRETCHRECT" ); + dptr++; + IDirect3DSurface9 *pSourceSurface=(IDirect3DSurface9 *) FetchPtr(dptr); + dptr+=N_DWORDS_IN_PTR; + RECT const *pSourceRect=0; + if (*(dptr++)) + pSourceRect=(RECT const *) dptr; + dptr += N_DWORDS( RECT ); + IDirect3DSurface9 *pDestSurface= (IDirect3DSurface9 *) FetchPtr( dptr ); + dptr += N_DWORDS_IN_PTR; + RECT const *pDestRect=0; + if (*(dptr++)) + pDestRect=(RECT const *) dptr; + dptr += N_DWORDS( RECT ); + D3DTEXTUREFILTERTYPE Filter = (D3DTEXTUREFILTERTYPE) *(dptr++); + Dx9Device()->StretchRect( pSourceSurface, pSourceRect, + pDestSurface, pDestRect, + Filter ); + } + break; + + + case PBCMD_PRESENT: + { + VPROF_BUFFER_PLAYBACK( "PRESENT" ); + dptr++; + RECT const *pSourceRect=0; + if (* (dptr++) ) + pSourceRect=(RECT const *) dptr; + dptr+=N_DWORDS( RECT ); + RECT const *pDestRect = 0; + if (* (dptr++) ) + pDestRect=(RECT const *) dptr; + dptr+=N_DWORDS( RECT ); + VD3DHWND hDestWindowOverride = (VD3DHWND) *(dptr++); + RGNDATA const *pDirtyRegion=0; + if ( *(dptr++) ) + pDirtyRegion= (RGNDATA const *) dptr; + dptr+=N_DWORDS( RGNDATA ); + + tmZone( TELEMETRY_LEVEL1, TMZF_NONE, "!D3DPresent" ); + + Dx9Device()->Present( pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion ); + break; + } + + case PBCMD_SET_SCISSOR_RECT: + { + VPROF_BUFFER_PLAYBACK( "SET_SCISSOR_RECT" ); + dptr++; + const RECT *pRect = ( RECT * )FetchPtr( dptr ); + dptr += sizeof( RECT ); + Dx9Device()->SetScissorRect( pRect ); + } + } + } +} + +#endif + +#endif // D3D_ASYNC_SUPPORTED diff --git a/materialsystem/shaderapidx9/d3d_async.h b/materialsystem/shaderapidx9/d3d_async.h new file mode 100644 index 0000000..7deb2f3 --- /dev/null +++ b/materialsystem/shaderapidx9/d3d_async.h @@ -0,0 +1,1567 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +// +//===========================================================================// + +#ifdef D3D_ASYNC_SUPPORTED + +#ifndef D3DASYNC_H +#define D3DASYNC_H + +#ifdef _WIN32 +#pragma once +#endif + +// Set this to 1 to allow d3d calls to be buffered and played back on another thread +// Slamming this off - it's causing very hot D3D9 function calls to not be inlined and contain a bunch of unused code. (Does this code even work/add real value any more?) +#define SHADERAPI_USE_SMP 0 + +// Set this to 1 to allow buffering of the whole frame to memory and then playback (singlethreaded). +// This is for debugging only and is used to test the performance of just calling D3D and rendering without other CPU overhead. +#define SHADERAPI_BUFFER_D3DCALLS 0 + +#if SHADERAPI_BUFFER_D3DCALLS && !SHADERAPI_USE_SMP +# error "SHADERAPI_USE_SMP must be 1 for SHADERAPI_BUFFER_D3DCALLS to work!" +#endif + +#include "recording.h" +#include "strtools.h" +#include "glmgr/dxabstract.h" + +#ifdef NDEBUG +#define DO_D3D(x) Dx9Device()->x +#else +#define DO_D3D(x) Dx9Device()->x +//#define DO_D3D(x) { HRESULT hr=Dx9Device()->x; Assert( !FAILED(hr) ); } +#endif + +#define PUSHBUFFER_NELEMS 4096 + +enum PushBufferState +{ + PUSHBUFFER_AVAILABLE, + PUSHBUFFER_BEING_FILLED, + PUSHBUFFER_SUBMITTED, + PUSHBUFFER_BEING_USED_FOR_LOCKEDDATA, +}; + +class PushBuffer +{ + friend class D3DDeviceWrapper; + + volatile PushBufferState m_State; + uint32 m_BufferData[PUSHBUFFER_NELEMS]; +public: + PushBuffer(void) + { + m_State = PUSHBUFFER_AVAILABLE; + } +}; + +// When running multithreaded, lock for write calls actually return a pointer to temporary memory +// buffer. When the buffer is later unlocked by the caller, data must be queued with the Unlock() +// that lets the d3d thread know how much data to copy from where. One possible optimization for +// things which write a lot of data into lock buffers woudl be to proviude a way for the caller to +// occasionally check if the Lock() has been dequeued. If so, the the data pushed so far could be +// copied asynchronously into the buffer, while the caller would be told to switch to writing +// directly to the vertex buffer. +// +// another possibility would be lock()ing in advance for large ones, such as the world renderer, +// or keeping multiple locked vb's open for meshbuilder. + +struct LockedBufferContext +{ + PushBuffer *m_pPushBuffer; // if a push buffer was used to hold + // the temporary data, this will be non-null + void *m_pMallocedMemory; // if memory had to be malloc'd, this will be set. + + size_t m_MallocSize; // # of bytes malloced if mallocedmem ptr non-null + + LockedBufferContext( void ) + { + m_pPushBuffer = NULL; + m_pMallocedMemory = NULL; + } + +}; + + + +// push buffer commands follow +enum PushBufferCommand +{ + PBCMD_END, // at end of push buffer + PBCMD_SET_RENDERSTATE, // state, val + PBCMD_SET_TEXTURE, // stage, txtr + PBCMD_DRAWPRIM, // prim type, start v, nprims + PBCMD_DRAWINDEXEDPRIM, // prim type, baseidx, minidx, numv, starti, pcount + PBCMD_SET_PIXEL_SHADER, // shaderptr + PBCMD_SET_VERTEX_SHADER, // shaderptr + PBCMD_SET_PIXEL_SHADER_CONSTANT, // startreg, nregs, data... + PBCMD_SET_BOOLEAN_PIXEL_SHADER_CONSTANT, // startreg, nregs, data... + PBCMD_SET_INTEGER_PIXEL_SHADER_CONSTANT, // startreg, nregs, data... + PBCMD_SET_VERTEX_SHADER_CONSTANT, // startreg, nregs, data... + PBCMD_SET_BOOLEAN_VERTEX_SHADER_CONSTANT, // startreg, nregs, data... + PBCMD_SET_INTEGER_VERTEX_SHADER_CONSTANT, // startreg, nregs, data... + PBCMD_SET_RENDER_TARGET, // idx, targetptr + PBCMD_SET_DEPTH_STENCIL_SURFACE, // surfptr + PBCMD_SET_STREAM_SOURCE, // idx, sptr, ofs, stride + PBCMD_SET_INDICES, // idxbuffer + PBCMD_SET_SAMPLER_STATE, // stage, state, val + PBCMD_UNLOCK_VB, // vptr + PBCMD_UNLOCK_IB, // idxbufptr + PBCMD_SETVIEWPORT, // vp_struct + PBCMD_CLEAR, // count, n rect structs, flags, color, z, stencil + PBCMD_SET_VERTEXDECLARATION, // vdeclptr + PBCMD_BEGIN_SCENE, // + PBCMD_END_SCENE, // + PBCMD_PRESENT, // complicated..see code + PBCMD_SETCLIPPLANE, // idx, 4 floats + PBCMD_STRETCHRECT, // see code + PBCMD_ASYNC_LOCK_VB, // see code + PBCMD_ASYNC_UNLOCK_VB, + PBCMD_ASYNC_LOCK_IB, // see code + PBCMD_ASYNC_UNLOCK_IB, + PBCMD_SET_SCISSOR_RECT, // RECT +}; + + + +#define N_DWORDS( x ) (( sizeof(x)+3)/sizeof( DWORD )) +#define N_DWORDS_IN_PTR (N_DWORDS( void * )) + +class D3DDeviceWrapper +{ +private: + IDirect3DDevice9 *m_pD3DDevice; + bool m_bSupportsTessellation; + int m_nCurrentTessLevel; + TessellationMode_t m_nTessellationMode; + +#if SHADERAPI_USE_SMP + uintptr_t m_pASyncThreadHandle; + PushBuffer *m_pCurPushBuffer; + uint32 *m_pOutputPtr; + size_t m_PushBufferFreeSlots; +#endif + +#if SHADERAPI_BUFFER_D3DCALLS + bool m_bBufferingD3DCalls; +# define SHADERAPI_BUFFER_MAXRENDERTARGETS 4 + IDirect3DSurface9 *m_StoredRenderTargets[SHADERAPI_BUFFER_MAXRENDERTARGETS]; +#endif + + PushBuffer *FindFreePushBuffer( PushBufferState newstate ); // find a free push buffer and change its state + + void GetPushBuffer(void); // set us up to point at a new push buffer + void SubmitPushBufferAndGetANewOne(void); // submit the current push buffer + void ExecutePushBuffer( PushBuffer const *pb); + +#if SHADERAPI_USE_SMP + void Synchronize(void); // wait for all commands to be done +#else + FORCEINLINE void Synchronize(void) + { + } +#endif + + + void SubmitIfNotBusy(void); + +#if SHADERAPI_USE_SMP + template FORCEINLINE void PushStruct( PushBufferCommand cmd, T const *str ) + { + int nwords=N_DWORDS( T ); + AllocatePushBufferSpace( 1+ nwords ); + m_pOutputPtr[0]=cmd; + memcpy( m_pOutputPtr+1, str, sizeof( T ) ); + m_pOutputPtr += 1+nwords; + } + + FORCEINLINE void AllocatePushBufferSpace(size_t nSlots) + { + // check for N slots of space, and decrement amount of space left + if ( nSlots>m_PushBufferFreeSlots ) // out of room? + { + SubmitPushBufferAndGetANewOne(); + } + m_PushBufferFreeSlots -= nSlots; + } + + // simple methods for pushing a few words into output buffer + FORCEINLINE void Push( PushBufferCommand cmd ) + { + AllocatePushBufferSpace(1); + m_pOutputPtr[0]=cmd; + m_pOutputPtr++; + } + + FORCEINLINE void Push( PushBufferCommand cmd, int arg1) + { + AllocatePushBufferSpace(2); + m_pOutputPtr[0]=cmd; + m_pOutputPtr[1]=arg1; + m_pOutputPtr += 2; + } + + FORCEINLINE void Push( PushBufferCommand cmd, void *ptr ) + { + AllocatePushBufferSpace(1+N_DWORDS_IN_PTR); + *(m_pOutputPtr++)=cmd; + *((void **) m_pOutputPtr)=ptr; + m_pOutputPtr+=N_DWORDS_IN_PTR; + } + + FORCEINLINE void Push( PushBufferCommand cmd, void *ptr, void *ptr1 ) + { + AllocatePushBufferSpace(1+2*N_DWORDS_IN_PTR); + *(m_pOutputPtr++)=cmd; + *((void **) m_pOutputPtr)=ptr; + m_pOutputPtr+=N_DWORDS_IN_PTR; + *((void **) m_pOutputPtr)=ptr1; + m_pOutputPtr+=N_DWORDS_IN_PTR; + } + + FORCEINLINE void Push( PushBufferCommand cmd, void *arg1, uint32 arg2, uint32 arg3, uint32 arg4, + void *arg5) + { + AllocatePushBufferSpace(1+N_DWORDS_IN_PTR+1+1+1+N_DWORDS_IN_PTR); + *(m_pOutputPtr++)=cmd; + *((void **) m_pOutputPtr)=arg1; + m_pOutputPtr+=N_DWORDS_IN_PTR; + *(m_pOutputPtr++)=arg2; + *(m_pOutputPtr++)=arg3; + *(m_pOutputPtr++)=arg4; + *((void **) m_pOutputPtr)=arg5; + m_pOutputPtr+=N_DWORDS_IN_PTR; + + } + + FORCEINLINE void Push( PushBufferCommand cmd, uint32 arg1, void *ptr ) + { + AllocatePushBufferSpace(2+N_DWORDS_IN_PTR); + *(m_pOutputPtr++)=cmd; + *(m_pOutputPtr++)=arg1; + *((void **) m_pOutputPtr)=ptr; + m_pOutputPtr+=N_DWORDS_IN_PTR; + } + + FORCEINLINE void Push( PushBufferCommand cmd, uint32 arg1, void *ptr, int arg2, int arg3 ) + { + AllocatePushBufferSpace( 4+N_DWORDS_IN_PTR ); + *(m_pOutputPtr++)=cmd; + *(m_pOutputPtr++)=arg1; + *((void **) m_pOutputPtr)=ptr; + m_pOutputPtr+=N_DWORDS_IN_PTR; + m_pOutputPtr[0]=arg2; + m_pOutputPtr[1]=arg3; + m_pOutputPtr += 2; + } + + FORCEINLINE void Push( PushBufferCommand cmd, int arg1, int arg2) + { + AllocatePushBufferSpace(3); + m_pOutputPtr[0]=cmd; + m_pOutputPtr[1]=arg1; + m_pOutputPtr[2]=arg2; + m_pOutputPtr += 3; + } + + FORCEINLINE void Push( PushBufferCommand cmd, int arg1, int arg2, int arg3) + { + AllocatePushBufferSpace(4); + m_pOutputPtr[0]=cmd; + m_pOutputPtr[1]=arg1; + m_pOutputPtr[2]=arg2; + m_pOutputPtr[3]=arg3; + m_pOutputPtr += 4; + } + + FORCEINLINE void Push( PushBufferCommand cmd, int arg1, int arg2, int arg3, int arg4, int arg5, int arg6 ) + { + AllocatePushBufferSpace(7); + m_pOutputPtr[0]=cmd; + m_pOutputPtr[1]=arg1; + m_pOutputPtr[2]=arg2; + m_pOutputPtr[3]=arg3; + m_pOutputPtr[4]=arg4; + m_pOutputPtr[5]=arg5; + m_pOutputPtr[6]=arg6; + m_pOutputPtr += 7; + } + +#else + template FORCEINLINE void PushStruct( PushBufferCommand cmd, T const *str ) + { + } + + FORCEINLINE void AllocatePushBufferSpace(size_t nSlots) + { + } + + // simple methods for pushing a few words into output buffer + FORCEINLINE void Push( PushBufferCommand cmd ) + { + } + + FORCEINLINE void Push( PushBufferCommand cmd, int arg1) + { + } + + FORCEINLINE void Push( PushBufferCommand cmd, void *ptr ) + { + } + + FORCEINLINE void Push( PushBufferCommand cmd, void *ptr, void *ptr1 ) + { + } + + FORCEINLINE void Push( PushBufferCommand cmd, void *arg1, uint32 arg2, uint32 arg3, uint32 arg4, + void *arg5) + { + } + + FORCEINLINE void Push( PushBufferCommand cmd, uint32 arg1, void *ptr ) + { + } + + FORCEINLINE void Push( PushBufferCommand cmd, uint32 arg1, void *ptr, int arg2, int arg3 ) + { + } + + FORCEINLINE void Push( PushBufferCommand cmd, int arg1, int arg2) + { + } + + FORCEINLINE void Push( PushBufferCommand cmd, int arg1, int arg2, int arg3) + { + } + + FORCEINLINE void Push( PushBufferCommand cmd, int arg1, int arg2, int arg3, int arg4, int arg5, int arg6 ) + { + } + +#endif + + FORCEINLINE bool ASyncMode(void) const + { +#if SHADERAPI_USE_SMP +# if SHADERAPI_BUFFER_D3DCALLS + return m_bBufferingD3DCalls; +# else + return (m_pASyncThreadHandle != 0 ); +# endif +#else + return false; +#endif + } + + FORCEINLINE IDirect3DDevice9* Dx9Device(void) const + { + return m_pD3DDevice; + } + + void AsynchronousLock( IDirect3DVertexBuffer9* vb, size_t offset, size_t size, void **ptr, + DWORD flags, + LockedBufferContext *lb); + + void AsynchronousLock( IDirect3DIndexBuffer9* ib, size_t offset, size_t size, void **ptr, + DWORD flags, + LockedBufferContext *lb); + + // handlers for push buffer contexts + void HandleAsynchronousLockVBCommand( uint32 const *dptr ); + void HandleAsynchronousUnLockVBCommand( uint32 const *dptr ); + void HandleAsynchronousLockIBCommand( uint32 const *dptr ); + void HandleAsynchronousUnLockIBCommand( uint32 const *dptr ); + +public: + +#if SHADERAPI_BUFFER_D3DCALLS + void ExecuteAllWork( void ); +#endif + void RunThread( void ); // this is what the worker thread runs + + void SetASyncMode( bool onoff ); + + + bool IsActive( void )const + { + return m_pD3DDevice != NULL; + } + + void D3DeviceWrapper(void) + { + m_pD3DDevice = 0; +#if SHADERAPI_USE_SMP + m_pASyncThreadHandle = 0; +#endif +#if SHADERAPI_BUFFER_D3DCALLS + m_bBufferingD3DCalls = false; +#endif + } + + void SetDevicePtr(IDirect3DDevice9 *pD3DDev ) + { + m_pD3DDevice = pD3DDev; + } + + void SetSupportsTessellation( bool bSupportsTessellation ) + { + m_bSupportsTessellation = bSupportsTessellation; + } + + void ShutDownDevice(void) + { + if ( ASyncMode() ) + { + // sync w/ thread + } + m_pD3DDevice = 0; + } + + void FORCEINLINE SetDepthStencilSurface( IDirect3DSurface9 *new_stencil ) + { + if ( ASyncMode() ) + Push( PBCMD_SET_DEPTH_STENCIL_SURFACE, new_stencil ); + else + DO_D3D( SetDepthStencilSurface( new_stencil ) ); + } + + HRESULT CreateCubeTexture( + UINT EdgeLength, + UINT Levels, + DWORD Usage, + D3DFORMAT Format, + D3DPOOL Pool, + IDirect3DCubeTexture9 ** ppCubeTexture, + HANDLE* pSharedHandle, + char *debugLabel = NULL // <-- OK to not pass this arg, only passed through on DX_TO_GL_ABSTRACTION + ) + { + Synchronize(); + return m_pD3DDevice->CreateCubeTexture( EdgeLength, Levels, Usage, Format, Pool, + ppCubeTexture, pSharedHandle + #if defined( DX_TO_GL_ABSTRACTION ) + ,debugLabel + #endif + ); + } + + HRESULT CreateVolumeTexture( + UINT Width, + UINT Height, + UINT Depth, + UINT Levels, + DWORD Usage, + D3DFORMAT Format, + D3DPOOL Pool, + IDirect3DVolumeTexture9** ppVolumeTexture, + HANDLE* pSharedHandle, + char *debugLabel = NULL // <-- OK to not pass this arg, only passed through on DX_TO_GL_ABSTRACTION + ) + { + Synchronize(); + return m_pD3DDevice->CreateVolumeTexture( Width, Height, Depth, Levels, + Usage, Format, Pool, ppVolumeTexture, + pSharedHandle + #if defined( DX_TO_GL_ABSTRACTION ) + ,debugLabel + #endif + ); + } + + HRESULT CreateOffscreenPlainSurface( UINT Width, + UINT Height, + D3DFORMAT Format, + D3DPOOL Pool, + IDirect3DSurface9** ppSurface, + HANDLE* pSharedHandle) + { + Synchronize(); + return m_pD3DDevice->CreateOffscreenPlainSurface( Width, Height, Format, Pool, + ppSurface, pSharedHandle); + } + + HRESULT CreateTexture( + UINT Width, + UINT Height, + UINT Levels, + DWORD Usage, + D3DFORMAT Format, + D3DPOOL Pool, + IDirect3DTexture9** ppTexture, + HANDLE* pSharedHandle, + char *debugLabel = NULL // <-- OK to not pass this arg, only passed through on DX_TO_GL_ABSTRACTION + ) + { + Synchronize(); + return m_pD3DDevice->CreateTexture( Width, Height, Levels, Usage, + Format, Pool, ppTexture, pSharedHandle + #if defined( DX_TO_GL_ABSTRACTION ) + ,debugLabel + #endif + ); + } + + HRESULT GetRenderTargetData( + IDirect3DSurface9* pRenderTarget, + IDirect3DSurface9* pDestSurface + ) + { + Synchronize(); + return m_pD3DDevice->GetRenderTargetData( pRenderTarget, pDestSurface ); + } + + + void GetDeviceCaps( D3DCAPS9 * pCaps ) + { + Synchronize(); + m_pD3DDevice->GetDeviceCaps( pCaps ); + } + + LPCSTR GetPixelShaderProfile( void ) + { + Synchronize(); + return D3DXGetPixelShaderProfile( m_pD3DDevice ); + } + + HRESULT TestCooperativeLevel( void ) + { + // hack! We are going to assume that calling this immediately when in buffered mode isn't going to cause problems. +#if !SHADERAPI_BUFFER_D3DCALLS + Synchronize(); +#endif + return m_pD3DDevice->TestCooperativeLevel(); + } + + HRESULT GetFrontBufferData( UINT iSwapChain, IDirect3DSurface9 * pDestSurface ) + { + Synchronize(); + return m_pD3DDevice->GetFrontBufferData( iSwapChain, pDestSurface ); + } + + void SetGammaRamp( int swapchain, int flags, D3DGAMMARAMP const *pRamp) + { + Synchronize(); + m_pD3DDevice->SetGammaRamp( swapchain, flags, pRamp); + } + + HRESULT GetTexture( DWORD Stage, IDirect3DBaseTexture9 ** ppTexture ) + { + Synchronize(); + return m_pD3DDevice->GetTexture( Stage, ppTexture ); + } + + HRESULT GetFVF( DWORD * pFVF ) + { + Synchronize(); + return m_pD3DDevice->GetFVF( pFVF ); + } + + HRESULT GetDepthStencilSurface( + IDirect3DSurface9 ** ppZStencilSurface + ) + { + Synchronize(); + return m_pD3DDevice->GetDepthStencilSurface( ppZStencilSurface ); + } + + FORCEINLINE void SetClipPlane( int idx, float const * pplane) + { + RECORD_COMMAND( DX8_SET_CLIP_PLANE, 5 ); + RECORD_INT( idx ); + RECORD_FLOAT( pplane[0] ); + RECORD_FLOAT( pplane[1] ); + RECORD_FLOAT( pplane[2] ); + RECORD_FLOAT( pplane[3] ); +#if SHADERAPI_USE_SMP + if ( ASyncMode() ) + { + AllocatePushBufferSpace( 6 ); + m_pOutputPtr[0]=PBCMD_SETCLIPPLANE; + m_pOutputPtr[1]=idx; + memcpy(m_pOutputPtr+2,pplane, 4*sizeof(float) ); + m_pOutputPtr += 6; + } + else +#endif + DO_D3D( SetClipPlane( idx, pplane ) ); + } + + FORCEINLINE void SetVertexDeclaration( IDirect3DVertexDeclaration9 *decl ) + { + RECORD_COMMAND( DX8_SET_VERTEX_DECLARATION, 1 ); + RECORD_INT( ( int ) decl ); + +#if SHADERAPI_USE_SMP + if ( ASyncMode() ) + { + Push( PBCMD_SET_VERTEXDECLARATION, decl ); + } + else +#endif + DO_D3D( SetVertexDeclaration( decl ) ); + } + + FORCEINLINE void SetViewport( D3DVIEWPORT9 const *vp ) + { + RECORD_COMMAND( DX8_SET_VIEWPORT, 1 ); + RECORD_STRUCT( vp, sizeof( *vp )); + +#if SHADERAPI_USE_SMP + if ( ASyncMode() ) + PushStruct( PBCMD_SETVIEWPORT, vp ); + else +#endif + DO_D3D( SetViewport( vp ) ); + } + + HRESULT GetRenderTarget( + DWORD RenderTargetIndex, + IDirect3DSurface9 ** ppRenderTarget) + { +#if SHADERAPI_BUFFER_D3DCALLS + if ( ASyncMode() ) + { + Assert( RenderTargetIndex >= 0 && RenderTargetIndex < SHADERAPI_BUFFER_MAXRENDERTARGETS ); + *ppRenderTarget = m_StoredRenderTargets[RenderTargetIndex]; + return D3D_OK; + } +#endif + Synchronize(); + return m_pD3DDevice->GetRenderTarget( RenderTargetIndex, ppRenderTarget ); + } + + HRESULT CreateQuery( D3DQUERYTYPE Type, IDirect3DQuery9** ppQuery ) + { + Synchronize(); + return m_pD3DDevice->CreateQuery( Type, ppQuery ); + } + + HRESULT CreateRenderTarget( + UINT Width, + UINT Height, + D3DFORMAT Format, + D3DMULTISAMPLE_TYPE MultiSample, + DWORD MultisampleQuality, + BOOL Lockable, + IDirect3DSurface9** ppSurface, + HANDLE* pSharedHandle + ) + { + Synchronize(); + return m_pD3DDevice->CreateRenderTarget( Width, Height, Format, MultiSample, + MultisampleQuality, Lockable, ppSurface, + pSharedHandle); + } + + HRESULT CreateDepthStencilSurface( + UINT Width, + UINT Height, + D3DFORMAT Format, + D3DMULTISAMPLE_TYPE MultiSample, + DWORD MultisampleQuality, + BOOL Discard, + IDirect3DSurface9** ppSurface, + HANDLE* pSharedHandle + ) + { + Synchronize(); + return m_pD3DDevice->CreateDepthStencilSurface( Width, Height, Format, MultiSample, + MultisampleQuality, Discard, ppSurface, + pSharedHandle ); + } + + + FORCEINLINE void SetRenderTarget( int idx, IDirect3DSurface9 *new_rt ) + { + if (ASyncMode()) + { + Push( PBCMD_SET_RENDER_TARGET, idx, new_rt ); +#if SHADERAPI_BUFFER_D3DCALLS + m_StoredRenderTargets[idx] = new_rt; +#endif + } + else + { + // NOTE: If the debug runtime breaks here on the shadow depth render target that is normal. dx9 doesn't directly support shadow + // depth texturing so we are forced to initialize this texture without the render target flagr + DO_D3D( SetRenderTarget( idx, new_rt) ); + } + } + + FORCEINLINE void LightEnable( int lidx, bool onoff ) + { + RECORD_COMMAND( DX8_LIGHT_ENABLE, 2 ); + RECORD_INT( lidx ); + RECORD_INT( onoff ); + + Synchronize(); + DO_D3D( LightEnable( lidx, onoff ) ); + } + + FORCEINLINE void SetRenderState( D3DRENDERSTATETYPE state, DWORD val ) + { +// Assert( state >= 0 && state < MAX_NUM_RENDERSTATES ); + RECORD_RENDER_STATE( state, val ); + if (ASyncMode()) + { + Push( PBCMD_SET_RENDERSTATE, state, val ); + } + else + DO_D3D( SetRenderState( state, val ) ); + } + + FORCEINLINE void SetRenderStateInline( D3DRENDERSTATETYPE state, DWORD val ) + { + // Assert( state >= 0 && state < MAX_NUM_RENDERSTATES ); + RECORD_RENDER_STATE( state, val ); + if (ASyncMode()) + { + SetRenderState( state, val ); + } + else + { +#ifdef DX_TO_GL_ABSTRACTION + DO_D3D( SetRenderStateInline( state, val ) ); +#else + DO_D3D( SetRenderState( state, val ) ); +#endif + } + } + + FORCEINLINE void SetScissorRect( const RECT *pScissorRect ) + { + RECORD_COMMAND( DX8_SET_SCISSOR_RECT, 1 ); + RECORD_STRUCT( pScissorRect, 4 * sizeof(LONG) ); +#if SHADERAPI_USE_SMP + if ( ASyncMode() ) + { + AllocatePushBufferSpace( 5 ); + m_pOutputPtr[0] = PBCMD_SET_SCISSOR_RECT; + memcpy( m_pOutputPtr + 1, pScissorRect, sizeof( *pScissorRect ) ); + } + else +#endif + DO_D3D( SetScissorRect( pScissorRect ) ); + } + + FORCEINLINE void SetVertexShaderConstantF( UINT StartRegister, CONST float * pConstantData, + UINT Vector4fCount) + { + RECORD_COMMAND( DX8_SET_VERTEX_SHADER_CONSTANT, 3 ); + RECORD_INT( StartRegister ); + RECORD_INT( Vector4fCount ); + RECORD_STRUCT( pConstantData, Vector4fCount * 4 * sizeof(float) ); +#if SHADERAPI_USE_SMP + if ( ASyncMode() ) + { + AllocatePushBufferSpace(3+4*Vector4fCount); + m_pOutputPtr[0]=PBCMD_SET_VERTEX_SHADER_CONSTANT; + m_pOutputPtr[1]=StartRegister; + m_pOutputPtr[2]=Vector4fCount; + memcpy(m_pOutputPtr+3,pConstantData,sizeof(float)*4*Vector4fCount); + m_pOutputPtr+=3+4*Vector4fCount; + } + else +#endif + DO_D3D( SetVertexShaderConstantF( StartRegister, pConstantData, Vector4fCount ) ); + } + + FORCEINLINE void SetVertexShaderConstantB( UINT StartRegister, CONST int * pConstantData, + UINT BoolCount) + { + RECORD_COMMAND( DX8_SET_VERTEX_SHADER_CONSTANT, 3 ); + RECORD_INT( StartRegister ); + RECORD_INT( BoolCount ); + RECORD_STRUCT( pConstantData, BoolCount * sizeof(int) ); +#if SHADERAPI_USE_SMP + if ( ASyncMode() ) + { + AllocatePushBufferSpace(3+BoolCount); + m_pOutputPtr[0]=PBCMD_SET_BOOLEAN_VERTEX_SHADER_CONSTANT; + m_pOutputPtr[1]=StartRegister; + m_pOutputPtr[2]=BoolCount; + memcpy(m_pOutputPtr+3,pConstantData,sizeof(int)*BoolCount); + m_pOutputPtr+=3+BoolCount; + } + else +#endif + DO_D3D( SetVertexShaderConstantB( StartRegister, pConstantData, BoolCount ) ); + } + + FORCEINLINE void SetVertexShaderConstantI( UINT StartRegister, CONST int * pConstantData, + UINT Vector4IntCount) + { + RECORD_COMMAND( DX8_SET_VERTEX_SHADER_CONSTANT, 3 ); + RECORD_INT( StartRegister ); + RECORD_INT( Vector4IntCount ); + RECORD_STRUCT( pConstantData, Vector4IntCount * 4 * sizeof(int) ); +#if SHADERAPI_USE_SMP + if ( ASyncMode() ) + { + AllocatePushBufferSpace(3+4*Vector4IntCount); + m_pOutputPtr[0]=PBCMD_SET_INTEGER_VERTEX_SHADER_CONSTANT; + m_pOutputPtr[1]=StartRegister; + m_pOutputPtr[2]=Vector4IntCount; + memcpy(m_pOutputPtr+3,pConstantData,sizeof(int)*4*Vector4IntCount); + m_pOutputPtr+=3+4*Vector4IntCount; + } + else +#endif + DO_D3D( SetVertexShaderConstantI( StartRegister, pConstantData, Vector4IntCount ) ); + } + + FORCEINLINE void SetPixelShaderConstantF( UINT StartRegister, CONST float * pConstantData, + UINT Vector4fCount) + { + RECORD_COMMAND( DX8_SET_PIXEL_SHADER_CONSTANT, 3 ); + RECORD_INT( StartRegister ); + RECORD_INT( Vector4fCount ); + RECORD_STRUCT( pConstantData, Vector4fCount * 4 * sizeof(float) ); +#if SHADERAPI_USE_SMP + if ( ASyncMode() ) + { + AllocatePushBufferSpace(3+4*Vector4fCount); + m_pOutputPtr[0]=PBCMD_SET_PIXEL_SHADER_CONSTANT; + m_pOutputPtr[1]=StartRegister; + m_pOutputPtr[2]=Vector4fCount; + memcpy(m_pOutputPtr+3,pConstantData,sizeof(float)*4*Vector4fCount); + m_pOutputPtr+=3+4*Vector4fCount; + } + else +#endif + DO_D3D( SetPixelShaderConstantF( StartRegister, pConstantData, Vector4fCount ) ); + } + + FORCEINLINE void SetPixelShaderConstantB( UINT StartRegister, CONST int * pConstantData, + UINT BoolCount) + { + RECORD_COMMAND( DX8_SET_PIXEL_SHADER_CONSTANT, 3 ); + RECORD_INT( StartRegister ); + RECORD_INT( BoolCount ); + RECORD_STRUCT( pConstantData, BoolCount * sizeof(int) ); +#if SHADERAPI_USE_SMP + if ( ASyncMode() ) + { + AllocatePushBufferSpace(3+BoolCount); + m_pOutputPtr[0]=PBCMD_SET_BOOLEAN_PIXEL_SHADER_CONSTANT; + m_pOutputPtr[1]=StartRegister; + m_pOutputPtr[2]=BoolCount; + memcpy(m_pOutputPtr+3,pConstantData,sizeof(int)*BoolCount); + m_pOutputPtr+=3+BoolCount; + } + else +#endif + DO_D3D( SetPixelShaderConstantB( StartRegister, pConstantData, BoolCount ) ); + } + + FORCEINLINE void SetPixelShaderConstantI( UINT StartRegister, CONST int * pConstantData, + UINT Vector4IntCount) + { + RECORD_COMMAND( DX8_SET_PIXEL_SHADER_CONSTANT, 3 ); + RECORD_INT( StartRegister ); + RECORD_INT( Vector4IntCount ); + RECORD_STRUCT( pConstantData, Vector4IntCount * 4 * sizeof(int) ); +#if SHADERAPI_USE_SMP + if ( ASyncMode() ) + { + AllocatePushBufferSpace(3+4*Vector4IntCount); + m_pOutputPtr[0]=PBCMD_SET_INTEGER_PIXEL_SHADER_CONSTANT; + m_pOutputPtr[1]=StartRegister; + m_pOutputPtr[2]=Vector4IntCount; + memcpy(m_pOutputPtr+3,pConstantData,sizeof(int)*4*Vector4IntCount); + m_pOutputPtr+=3+4*Vector4IntCount; + } + else +#endif + DO_D3D( SetPixelShaderConstantI( StartRegister, pConstantData, Vector4IntCount ) ); + } + + HRESULT StretchRect( IDirect3DSurface9 * pSourceSurface, + CONST RECT * pSourceRect, + IDirect3DSurface9 * pDestSurface, + CONST RECT * pDestRect, + D3DTEXTUREFILTERTYPE Filter ) + { +#if SHADERAPI_USE_SMP + if ( ASyncMode() ) + { + AllocatePushBufferSpace(1+1+1+N_DWORDS( RECT )+1+1+N_DWORDS( RECT ) + 1); + *(m_pOutputPtr++)=PBCMD_STRETCHRECT; + *(m_pOutputPtr++)=(int) pSourceSurface; + *(m_pOutputPtr++)=(pSourceRect != NULL); + if (pSourceRect) + { + memcpy(m_pOutputPtr,pSourceRect,sizeof(RECT)); + } + m_pOutputPtr+=N_DWORDS(RECT); + *(m_pOutputPtr++)=(int) pDestSurface; + *(m_pOutputPtr++)=(pDestRect != NULL); + if (pDestRect) + memcpy(m_pOutputPtr,pDestRect,sizeof(RECT)); + m_pOutputPtr+=N_DWORDS(RECT); + *(m_pOutputPtr++)=Filter; + return S_OK; // !bug! + } + else +#endif + return m_pD3DDevice-> + StretchRect( pSourceSurface, pSourceRect, pDestSurface, pDestRect, Filter ); + } + + + FORCEINLINE void BeginScene(void) + { + RECORD_COMMAND( DX8_BEGIN_SCENE, 0 ); + if ( ASyncMode() ) + Push( PBCMD_BEGIN_SCENE ); + else + DO_D3D( BeginScene() ); + } + + FORCEINLINE void EndScene(void) + { + RECORD_COMMAND( DX8_END_SCENE, 0 ); + if ( ASyncMode() ) + Push( PBCMD_END_SCENE ); + else + DO_D3D( EndScene() ); + } + + FORCEINLINE HRESULT Lock( IDirect3DVertexBuffer9* vb, size_t offset, size_t size, void **ptr, DWORD flags ) + { + Assert( size ); // lock size of 0 = unknown entire size of buffer = bad + Synchronize(); + + HRESULT hr = vb->Lock(offset, size, ptr, flags); + switch (hr) + { + case D3DERR_INVALIDCALL: + Warning( "D3DERR_INVALIDCALL - Vertex Buffer Lock Failed in %s on line %d(offset %d, size %d, flags 0x%x)\n", V_UnqualifiedFileName(__FILE__), __LINE__, offset, size, flags ); + break; + case D3DERR_DRIVERINTERNALERROR: + Warning( "D3DERR_DRIVERINTERNALERROR - Vertex Buffer Lock Failed in %s on line %d (offset %d, size %d, flags 0x%x)\n", V_UnqualifiedFileName(__FILE__), __LINE__, offset, size, flags ); + break; + case D3DERR_OUTOFVIDEOMEMORY: + Warning( "D3DERR_OUTOFVIDEOMEMORY - Vertex Buffer Lock Failed in %s on line %d (offset %d, size %d, flags 0x%x)\n", V_UnqualifiedFileName(__FILE__), __LINE__, offset, size, flags ); + break; + } + + return hr; + } + + + FORCEINLINE HRESULT Lock( IDirect3DVertexBuffer9* vb, size_t offset, size_t size, void **ptr, + DWORD flags, + LockedBufferContext *lb) + { + + HRESULT hr = D3D_OK; + + // asynchronous write-only dynamic vb lock + if ( ASyncMode() ) + { + AsynchronousLock( vb, offset, size, ptr, flags, lb ); + } + else + { + hr = vb->Lock(offset, size, ptr, flags); + switch (hr) + { + case D3DERR_INVALIDCALL: + Warning( "D3DERR_INVALIDCALL - Vertex Buffer Lock Failed in %s on line %d(offset %d, size %d, flags 0x%x)\n", V_UnqualifiedFileName(__FILE__), __LINE__, offset, size, flags ); + break; + case D3DERR_DRIVERINTERNALERROR: + Warning( "D3DERR_DRIVERINTERNALERROR - Vertex Buffer Lock Failed in %s on line %d (offset %d, size %d, flags 0x%x)\n", V_UnqualifiedFileName(__FILE__), __LINE__, offset, size, flags ); + break; + case D3DERR_OUTOFVIDEOMEMORY: + Warning( "D3DERR_OUTOFVIDEOMEMORY - Vertex Buffer Lock Failed in %s on line %d (offset %d, size %d, flags 0x%x)\n", V_UnqualifiedFileName(__FILE__), __LINE__, offset, size, flags ); + break; + } + } + + return hr; + } + + FORCEINLINE HRESULT Lock( IDirect3DIndexBuffer9* ib, size_t offset, size_t size, void **ptr, DWORD flags) + { + HRESULT hr = D3D_OK; + + Synchronize(); + + hr = ib->Lock(offset, size, ptr, flags); + switch (hr) + { + case D3DERR_INVALIDCALL: + Warning( "D3DERR_INVALIDCALL - Index Buffer Lock Failed in %s on line %d(offset %d, size %d, flags 0x%x)\n", V_UnqualifiedFileName(__FILE__), __LINE__, offset, size, flags ); + break; + case D3DERR_DRIVERINTERNALERROR: + Warning( "D3DERR_DRIVERINTERNALERROR - Index Buffer Lock Failed in %s on line %d (offset %d, size %d, flags 0x%x)\n", V_UnqualifiedFileName(__FILE__), __LINE__, offset, size, flags ); + break; + case D3DERR_OUTOFVIDEOMEMORY: + Warning( "D3DERR_OUTOFVIDEOMEMORY - Index Buffer Lock Failed in %s on line %d (offset %d, size %d, flags 0x%x)\n", V_UnqualifiedFileName(__FILE__), __LINE__, offset, size, flags ); + break; + } + + return hr; + } + + // asycnhronous lock of index buffer + FORCEINLINE HRESULT Lock( IDirect3DIndexBuffer9* ib, size_t offset, size_t size, void **ptr, DWORD flags, + LockedBufferContext * lb) + { + HRESULT hr = D3D_OK; + + if ( ASyncMode() ) + AsynchronousLock( ib, offset, size, ptr, flags, lb ); + else + { + hr = ib->Lock(offset, size, ptr, flags); + switch (hr) + { + case D3DERR_INVALIDCALL: + Warning( "D3DERR_INVALIDCALL - Index Buffer Lock Failed in %s on line %d(offset %d, size %d, flags 0x%x)\n", V_UnqualifiedFileName(__FILE__), __LINE__, offset, size, flags ); + break; + case D3DERR_DRIVERINTERNALERROR: + Warning( "D3DERR_DRIVERINTERNALERROR - Index Buffer Lock Failed in %s on line %d (offset %d, size %d, flags 0x%x)\n", V_UnqualifiedFileName(__FILE__), __LINE__, offset, size, flags ); + break; + case D3DERR_OUTOFVIDEOMEMORY: + Warning( "D3DERR_OUTOFVIDEOMEMORY - Index Buffer Lock Failed in %s on line %d (offset %d, size %d, flags 0x%x)\n", V_UnqualifiedFileName(__FILE__), __LINE__, offset, size, flags ); + break; + } + } + + return hr; + } + +#ifndef DX_TO_GL_ABSTRACTION + FORCEINLINE HRESULT UpdateSurface( IDirect3DSurface9* pSourceSurface, CONST RECT* pSourceRect, IDirect3DSurface9* pDestSurface, CONST POINT* pDestPoint ) + { + return m_pD3DDevice->UpdateSurface( pSourceSurface, pSourceRect, pDestSurface, pDestPoint ); + } +#endif + + void Release( IDirect3DIndexBuffer9* ib ) + { + Synchronize(); + ib->Release(); + } + + void Release( IDirect3DVertexBuffer9* vb ) + { + Synchronize(); + vb->Release(); + } + + FORCEINLINE void Unlock( IDirect3DVertexBuffer9* vb ) + { + // needed for d3d on pc only + if ( ASyncMode() ) + Push(PBCMD_UNLOCK_VB, vb); + else + { + HRESULT hr = vb->Unlock( ); + + if ( FAILED(hr) ) + { + Warning( "Vertex Buffer Unlock Failed in %s on line %d\n", V_UnqualifiedFileName(__FILE__), __LINE__ ); + } + } + } + + FORCEINLINE void Unlock( IDirect3DVertexBuffer9* vb, LockedBufferContext *lb, size_t unlock_size) + { + // needed for d3d on pc only +#if SHADERAPI_USE_SMP + if ( ASyncMode() ) + { + AllocatePushBufferSpace( 1+N_DWORDS_IN_PTR+N_DWORDS( LockedBufferContext )+1 ); + *(m_pOutputPtr++)=PBCMD_ASYNC_UNLOCK_VB; + *((IDirect3DVertexBuffer9* *) m_pOutputPtr)=vb; + m_pOutputPtr+=N_DWORDS_IN_PTR; + *((LockedBufferContext *) m_pOutputPtr)=*lb; + m_pOutputPtr+=N_DWORDS( LockedBufferContext ); + *(m_pOutputPtr++)=unlock_size; + } + else +#endif + { + HRESULT hr = vb->Unlock(); + + if ( FAILED(hr) ) + { + Warning( "Vertex Buffer Unlock Failed in %s on line %d\n", V_UnqualifiedFileName(__FILE__), __LINE__ ); + } + } + } + + FORCEINLINE void Unlock( IDirect3DIndexBuffer9* ib ) + { + // needed for d3d on pc only + if ( ASyncMode() ) + Push(PBCMD_UNLOCK_IB, ib); + else + { + HRESULT hr = ib->Unlock(); + + if ( FAILED(hr) ) + { + Warning( "Index Buffer Unlock Failed in %s on line %d\n", V_UnqualifiedFileName(__FILE__), __LINE__ ); + } + } + } + + FORCEINLINE void Unlock( IDirect3DIndexBuffer9* ib, LockedBufferContext *lb, size_t unlock_size) + { + // needed for d3d on pc only +#if SHADERAPI_USE_SMP + if ( ASyncMode() ) + { + AllocatePushBufferSpace( 1+N_DWORDS_IN_PTR+N_DWORDS( LockedBufferContext )+1 ); + *(m_pOutputPtr++)=PBCMD_ASYNC_UNLOCK_IB; + *((IDirect3DIndexBuffer9* *) m_pOutputPtr)=ib; + m_pOutputPtr+=N_DWORDS_IN_PTR; + *((LockedBufferContext *) m_pOutputPtr)=*lb; + m_pOutputPtr+=N_DWORDS( LockedBufferContext ); + *(m_pOutputPtr++)=unlock_size; + } + else +#endif + { + HRESULT hr = ib->Unlock( ); + + if ( FAILED(hr) ) + { + Warning( "Index Buffer Unlock Failed in %s on line %d\n", V_UnqualifiedFileName(__FILE__), __LINE__ ); + } + } + } + + void ShowCursor( bool onoff) + { + Synchronize(); + DO_D3D( ShowCursor(onoff) ); + } + + FORCEINLINE void Clear( int count, D3DRECT const *pRects, int Flags, D3DCOLOR color, float Z, int stencil) + { +#if SHADERAPI_USE_SMP + if ( ASyncMode() ) + { + int n_rects_words = count * N_DWORDS( D3DRECT ); + AllocatePushBufferSpace( 2 + n_rects_words + 4 ); + *(m_pOutputPtr++) = PBCMD_CLEAR; + *(m_pOutputPtr++) = count; + if ( count ) + { + memcpy( m_pOutputPtr, pRects, count * sizeof( D3DRECT ) ); + m_pOutputPtr += n_rects_words; + } + *(m_pOutputPtr++) = Flags; + *( (D3DCOLOR *) m_pOutputPtr ) = color; + m_pOutputPtr++; + *( (float *) m_pOutputPtr ) = Z; + m_pOutputPtr++; + *(m_pOutputPtr++) = stencil; + } + else +#endif + DO_D3D( Clear(count, pRects, Flags, color, Z, stencil) ); + } + + HRESULT Reset( D3DPRESENT_PARAMETERS *parms) + { + RECORD_COMMAND( DX8_RESET, 1 ); + RECORD_STRUCT( parms, sizeof(*parms) ); + Synchronize(); + return m_pD3DDevice->Reset( parms ); + } + + void Release( void ) + { + Synchronize(); + DO_D3D( Release() ); + } + + FORCEINLINE void SetTexture(int stage, IDirect3DBaseTexture9 *txtr) + { + RECORD_COMMAND( DX8_SET_TEXTURE, 3 ); + RECORD_INT( stage ); + RECORD_INT( -1 ); + RECORD_INT( -1 ); + if (ASyncMode()) + { + Push( PBCMD_SET_TEXTURE, stage, txtr ); + } + else + DO_D3D( SetTexture( stage, txtr) ); + } + void SetTransform( D3DTRANSFORMSTATETYPE mtrx_id, D3DXMATRIX const *mt) + { + RECORD_COMMAND( DX8_SET_TRANSFORM, 2 ); + RECORD_INT( mtrx_id ); + RECORD_STRUCT( mt, sizeof(D3DXMATRIX) ); + Synchronize(); + DO_D3D( SetTransform( mtrx_id, mt) ); + } + + FORCEINLINE void SetSamplerState( int stage, D3DSAMPLERSTATETYPE state, DWORD val) + { + RECORD_SAMPLER_STATE( stage, state, val ); + if ( ASyncMode() ) + Push( PBCMD_SET_SAMPLER_STATE, stage, state, val ); + else + DO_D3D( SetSamplerState( stage, state, val) ); + } + + void SetFVF( int fvf) + { + Synchronize(); + DO_D3D( SetFVF( fvf) ); + } + + FORCEINLINE void SetTextureStageState( int stage, D3DTEXTURESTAGESTATETYPE state, DWORD val ) + { + RECORD_TEXTURE_STAGE_STATE( stage, state, val ); + Synchronize(); + DO_D3D( SetTextureStageState( stage, state, val) ); + } + + FORCEINLINE void DrawPrimitive( + D3DPRIMITIVETYPE PrimitiveType, + UINT StartVertex, + UINT PrimitiveCount + ) + { + RECORD_COMMAND( DX8_DRAW_PRIMITIVE, 3 ); + RECORD_INT( PrimitiveType ); + RECORD_INT( StartVertex ); + RECORD_INT( PrimitiveCount ); + if ( ASyncMode() ) + { + Push( PBCMD_DRAWPRIM, PrimitiveType, StartVertex, PrimitiveCount ); + SubmitIfNotBusy(); + } + else + DO_D3D( DrawPrimitive( PrimitiveType, StartVertex, PrimitiveCount ) ); + + } + + HRESULT CreateVertexDeclaration( + CONST D3DVERTEXELEMENT9* pVertexElements, + IDirect3DVertexDeclaration9** ppDecl + ) + { + Synchronize(); + return m_pD3DDevice->CreateVertexDeclaration( pVertexElements, ppDecl ); + } + + + HRESULT ValidateDevice( DWORD * pNumPasses ) + { + Synchronize(); + return m_pD3DDevice->ValidateDevice( pNumPasses ); + } + + + + HRESULT CreateVertexShader( + CONST DWORD * pFunction, + IDirect3DVertexShader9** ppShader, + const char *pShaderName, + char *debugLabel = NULL + ) + { + Synchronize(); + #ifdef DX_TO_GL_ABSTRACTION + return m_pD3DDevice->CreateVertexShader( pFunction, ppShader, pShaderName, debugLabel ); + #else + return m_pD3DDevice->CreateVertexShader( pFunction, ppShader ); + #endif + } + + HRESULT CreatePixelShader( + CONST DWORD * pFunction, + IDirect3DPixelShader9** ppShader, + const char *pShaderName, + char *debugLabel = NULL + ) + { + Synchronize(); + #ifdef DX_TO_GL_ABSTRACTION + return m_pD3DDevice->CreatePixelShader( pFunction, ppShader, pShaderName, debugLabel ); + #else + return m_pD3DDevice->CreatePixelShader( pFunction, ppShader ); + #endif + } + + + FORCEINLINE void SetIndices( + IDirect3DIndexBuffer9 * pIndexData + ) + { + if ( ASyncMode() ) + Push( PBCMD_SET_INDICES, pIndexData ); + else + DO_D3D( SetIndices( pIndexData ) ); + } + + FORCEINLINE void SetStreamSource( + UINT StreamNumber, + IDirect3DVertexBuffer9 * pStreamData, + UINT OffsetInBytes, + UINT Stride + ) + { + if ( ASyncMode() ) + Push( PBCMD_SET_STREAM_SOURCE, StreamNumber, pStreamData, OffsetInBytes, Stride ); + else + DO_D3D( SetStreamSource( StreamNumber, pStreamData, OffsetInBytes, Stride ) ); + } + + + HRESULT CreateVertexBuffer( + UINT Length, + DWORD Usage, + DWORD FVF, + D3DPOOL Pool, + IDirect3DVertexBuffer9** ppVertexBuffer, + HANDLE* pSharedHandle + ) + { + Synchronize(); + return m_pD3DDevice->CreateVertexBuffer( Length, Usage, FVF, + Pool, ppVertexBuffer, pSharedHandle ); + } + + HRESULT CreateIndexBuffer( + UINT Length, + DWORD Usage, + D3DFORMAT Format, + D3DPOOL Pool, + IDirect3DIndexBuffer9** ppIndexBuffer, + HANDLE* pSharedHandle + ) + { + Synchronize(); + return m_pD3DDevice->CreateIndexBuffer( Length, Usage, Format, Pool, ppIndexBuffer, + pSharedHandle ); + } + + + FORCEINLINE void DrawIndexedPrimitive( + D3DPRIMITIVETYPE Type, + INT BaseVertexIndex, + UINT MinIndex, + UINT NumVertices, + UINT StartIndex, + UINT PrimitiveCount ) + { + RECORD_COMMAND( DX8_DRAW_INDEXED_PRIMITIVE, 6 ); + RECORD_INT( Type ); + RECORD_INT( BaseVertexIndex ); + RECORD_INT( MinIndex ); + RECORD_INT( NumVertices ); + RECORD_INT( StartIndex ); + RECORD_INT( PrimitiveCount ); + if ( ASyncMode() ) + { + Push(PBCMD_DRAWINDEXEDPRIM, + Type, BaseVertexIndex, MinIndex, NumVertices, StartIndex, PrimitiveCount ); +// SubmitIfNotBusy(); + } + else + { + DO_D3D( DrawIndexedPrimitive( Type, BaseVertexIndex, MinIndex, NumVertices, StartIndex, PrimitiveCount ) ); + } + } + +#ifndef DX_TO_GL_ABSTRACTION + FORCEINLINE void DrawTessellatedIndexedPrimitive( INT BaseVertexIndex, UINT MinIndex, UINT NumVertices, + UINT StartIndex, UINT PrimitiveCount ) + { + // Setup our stream-source frequencies + DO_D3D( SetStreamSourceFreq( 0, D3DSTREAMSOURCE_INDEXEDDATA | PrimitiveCount ) ); + DO_D3D( SetStreamSourceFreq( VertexStreamSpec_t::STREAM_MORPH, D3DSTREAMSOURCE_INSTANCEDATA | 1ul ) ); + DO_D3D( SetStreamSourceFreq( VertexStreamSpec_t::STREAM_SUBDQUADS, D3DSTREAMSOURCE_INSTANCEDATA | 1ul ) ); + + int nIndicesPerPatch = ( ( ( m_nCurrentTessLevel + 1 ) * 2 + 2 ) * m_nCurrentTessLevel ) - 2; + int nVerticesPerPatch = m_nCurrentTessLevel + 1; + nVerticesPerPatch *= nVerticesPerPatch; + int nPrimitiveCount = nIndicesPerPatch - 2; + DO_D3D( DrawIndexedPrimitive( D3DPT_TRIANGLESTRIP, 0, 0, nVerticesPerPatch, 0, nPrimitiveCount ) ); + + // Disable instancing + DO_D3D( SetStreamSourceFreq( 0, 1ul ) ); + DO_D3D( SetStreamSourceFreq( VertexStreamSpec_t::STREAM_MORPH, 1ul ) ); + DO_D3D( SetStreamSourceFreq( VertexStreamSpec_t::STREAM_SUBDQUADS, 1ul ) ); + } + + FORCEINLINE void DrawTessellatedPrimitive( UINT StartVertex, UINT PrimitiveCount ) + { + + // Setup our stream-source frequencies + DO_D3D( SetStreamSourceFreq( 0, D3DSTREAMSOURCE_INDEXEDDATA | PrimitiveCount ) ); + DO_D3D( SetStreamSourceFreq( VertexStreamSpec_t::STREAM_MORPH, D3DSTREAMSOURCE_INSTANCEDATA | 1ul ) ); + DO_D3D( SetStreamSourceFreq( VertexStreamSpec_t::STREAM_SUBDQUADS, D3DSTREAMSOURCE_INSTANCEDATA | 1ul ) ); + + int nIndicesPerPatch = ( ( ( m_nCurrentTessLevel + 1 ) * 2 + 2 ) * m_nCurrentTessLevel ) - 2; + int nVerticesPerPatch = m_nCurrentTessLevel + 1; + nVerticesPerPatch *= nVerticesPerPatch; + int nPrimitiveCount = nIndicesPerPatch - 2; + DO_D3D( DrawIndexedPrimitive( D3DPT_TRIANGLESTRIP, 0, 0, nVerticesPerPatch, 0, nPrimitiveCount ) ); + + // Disable instancing + DO_D3D( SetStreamSourceFreq( 0, 1ul ) ); + DO_D3D( SetStreamSourceFreq( VertexStreamSpec_t::STREAM_MORPH, 1ul ) ); + DO_D3D( SetStreamSourceFreq( VertexStreamSpec_t::STREAM_SUBDQUADS, 1ul ) ); + } + + FORCEINLINE void SetTessellationLevel( float level ) + { + // Track our current tessellation level + m_nCurrentTessLevel = (int)ceil( level ); + } +#endif + + void SetMaterial( D3DMATERIAL9 const *mat) + { + RECORD_COMMAND( DX8_SET_MATERIAL, 1 ); + RECORD_STRUCT( &mat, sizeof(mat) ); + Synchronize(); + DO_D3D( SetMaterial( mat ) ); + } + + FORCEINLINE void SetPixelShader( IDirect3DPixelShader9 *pShader ) + { + RECORD_COMMAND( DX8_SET_PIXEL_SHADER, 1 ); + RECORD_INT( ( int ) pShader ); + if ( ASyncMode() ) + Push( PBCMD_SET_PIXEL_SHADER, pShader ); + else + DO_D3D( SetPixelShader( pShader ) ); + } + + FORCEINLINE void SetVertexShader( IDirect3DVertexShader9 *pShader ) + { + if ( ASyncMode() ) + Push( PBCMD_SET_VERTEX_SHADER, pShader ); + else + DO_D3D( SetVertexShader( pShader ) ); + } + +#ifdef DX_TO_GL_ABSTRACTION + FORCEINLINE HRESULT LinkShaderPair( IDirect3DVertexShader9* vs, IDirect3DPixelShader9* ps ) + { + Assert ( !ASyncMode() ); + return DO_D3D( LinkShaderPair( vs, ps ) ); + } + + HRESULT QueryShaderPair( int index, GLMShaderPairInfo *infoOut ) + { + Assert ( !ASyncMode() ); + return DO_D3D( QueryShaderPair( index, infoOut ) ); + } + + void SetMaxUsedVertexShaderConstantsHint( uint nMaxReg ) + { + Assert( !ASyncMode() ); + DO_D3D( SetMaxUsedVertexShaderConstantsHint( nMaxReg ) ); + } + +#endif + + void EvictManagedResources( void ) + { + if (m_pD3DDevice) // people call this before creating the device + { + Synchronize(); + DO_D3D( EvictManagedResources() ); + } + } + + void SetLight( int i, D3DLIGHT9 const *l) + { + RECORD_COMMAND( DX8_SET_LIGHT, 2 ); + RECORD_INT( i ); + RECORD_STRUCT( l, sizeof(*l) ); + + Synchronize(); + DO_D3D( SetLight(i, l) ); + } + + void DrawIndexedPrimitiveUP( D3DPRIMITIVETYPE PrimitiveType, + UINT MinVertexIndex, + UINT NumVertices, + UINT PrimitiveCount, + CONST void * pIndexData, + D3DFORMAT IndexDataFormat, + CONST void* pVertexStreamZeroData, + UINT VertexStreamZeroStride ) + { + Synchronize(); + DO_D3D( DrawIndexedPrimitiveUP( PrimitiveType, MinVertexIndex, NumVertices, PrimitiveCount, + pIndexData, IndexDataFormat, pVertexStreamZeroData, + VertexStreamZeroStride ) ); + } + + HRESULT Present( + CONST RECT * pSourceRect, + CONST RECT * pDestRect, + VD3DHWND hDestWindowOverride, + CONST RGNDATA * pDirtyRegion) + { + RECORD_COMMAND( DX8_PRESENT, 0 ); +#if SHADERAPI_USE_SMP + if ( ASyncMode() ) + { + // need to deal with ret code here + AllocatePushBufferSpace(1+1+ + N_DWORDS( RECT )+1+N_DWORDS( RECT )+1+1+N_DWORDS( RGNDATA )); + *(m_pOutputPtr++)=PBCMD_PRESENT; + *(m_pOutputPtr++)=( pSourceRect != NULL ); + if (pSourceRect) + memcpy(m_pOutputPtr, pSourceRect, sizeof( RECT ) ); + m_pOutputPtr+=N_DWORDS( RECT ); + *(m_pOutputPtr++)=( pDestRect != NULL ); + if (pDestRect) + memcpy(m_pOutputPtr, pDestRect, sizeof( RECT ) ); + m_pOutputPtr+=N_DWORDS( RECT ); + *(m_pOutputPtr++)=(uint32) hDestWindowOverride; + *(m_pOutputPtr++)=( pDirtyRegion != NULL ); + if (pDirtyRegion) + memcpy(m_pOutputPtr, pDirtyRegion, sizeof( RGNDATA )); + m_pOutputPtr+=N_DWORDS( RGNDATA ); + return S_OK; // not good - caller wants to here about lost devices + } + else +#endif + return m_pD3DDevice->Present( pSourceRect, pDestRect, + hDestWindowOverride, pDirtyRegion ); + } + + +#if defined( DX_TO_GL_ABSTRACTION ) + + void AcquireThreadOwnership( ) + { + m_pD3DDevice->AcquireThreadOwnership(); + } + + void ReleaseThreadOwnership( ) + { + m_pD3DDevice->ReleaseThreadOwnership(); + } + +#endif + +}; + +#endif // D3DASYNC_H + +#endif // #if D3D_ASYNC_SUPPORTED diff --git a/materialsystem/shaderapidx9/dx9hook.h b/materialsystem/shaderapidx9/dx9hook.h new file mode 100644 index 0000000..a117f3e --- /dev/null +++ b/materialsystem/shaderapidx9/dx9hook.h @@ -0,0 +1,1289 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +/* +TODO: add option to null out drawprim calls. + +Also maybe hook the PIX_ENABLE stuff to Telemetry + + In imaterialsystem.h: + #define PIX_ENABLE 1 // set this to 1 and build engine/studiorender to enable pix events in the engine + + And in shaderapidx8.h: + #define PIX_ENABLE 1 // set this to 1 and build engine/studiorender to enable pix events in the engine + +Might be interesting to make it so dx9hook.h paid attention to the PIX_ENABLE names + and allowed you to filter drawprim calls based on those? +*/ + +#ifndef _DX9HOOK_H_ +#define _DX9HOOK_H_ + +#if D3D_BATCH_PERF_ANALYSIS + #include "../../thirdparty/miniz/miniz.c" + #include "../../thirdparty/miniz/simple_bitmap.h" + + extern ConVar d3d_batch_vis, d3d_batch_vis_abs_scale, d3d_batch_vis_y_scale, d3d_present_vis_abs_scale; + extern uint64 g_nTotalD3DCalls, g_nTotalD3DCycles; + + class CD3DCallTimer + { + public: + inline CD3DCallTimer() { g_nTotalD3DCalls++; g_nTotalD3DCycles -= tmFastTime(); } + inline ~CD3DCallTimer() { g_nTotalD3DCycles += tmFastTime(); } + }; + + #define D3D_BATCH_PERF(...) __VA_ARGS__ +#else + #define D3D_BATCH_PERF(...) +#endif + +#if D3D_BATCH_PERF_ANALYSIS + #define XXX \ + tmZone( TELEMETRY_LEVEL3, TMZF_NONE, "D3D9: %s", __FUNCTION__ ); \ + CD3DCallTimer scopedCallTimer; +#else + #define XXX \ + if( ThreadInMainThread() ) \ + { \ + tmMessage( TELEMETRY_LEVEL0, TMMF_ICON_NOTE | TMMF_SEVERITY_WARNING, "(source/d3d)%s", __FUNCTION__ ); \ + tmZoneFiltered( TELEMETRY_LEVEL0, 50, TMZF_NONE, "%s", __FUNCTION__ ); \ + } +#endif + +// Hooks for routines which return values. +#define _DOCALL0( _member ) ( m_Data.pHWObj->_member )() +#define _DOCALL( _member, ... ) ( m_Data.pHWObj->_member )( __VA_ARGS__ ) +// And hooks for routines which return squatola. +#define _DOCALL0_NORET( _member ) ( m_Data.pHWObj->_member )() +#define _DOCALL_NORET( _member, ... ) ( m_Data.pHWObj->_member )( __VA_ARGS__) + +#define DEF_HOOKCLASSES( X ) \ + template<> class CDx9HookBase< struct I ## X > \ + { \ + public: \ + typedef I ## X _D3DINTERFACE; \ + typedef class C ## X ## Hook _HOOKCLASS; \ + \ + public: \ + CDx9HookBase() { memset( &m_Data, 0, sizeof( m_Data ) ); } \ + virtual ~CDx9HookBase() {} \ + \ + public: \ + struct DATA \ + { \ + class CDirect3DDevice9Hook *pDevice; \ + _D3DINTERFACE *pHWObj; \ + }; \ + \ + DATA m_Data; \ + } + +template < class T > class CDx9HookBase; +DEF_HOOKCLASSES( Direct3DVertexDeclaration9 ); +DEF_HOOKCLASSES( Direct3DPixelShader9 ); +DEF_HOOKCLASSES( Direct3DVertexShader9 ); +DEF_HOOKCLASSES( Direct3DVertexBuffer9 ); +DEF_HOOKCLASSES( Direct3DIndexBuffer9 ); +DEF_HOOKCLASSES( Direct3DQuery9 ); +DEF_HOOKCLASSES( Direct3DStateBlock9 ); +DEF_HOOKCLASSES( Direct3DSurface9 ); +DEF_HOOKCLASSES( Direct3DBaseTexture9 ); +DEF_HOOKCLASSES( Direct3DTexture9 ); +DEF_HOOKCLASSES( Direct3DCubeTexture9 ); +DEF_HOOKCLASSES( Direct3DVolume9 ); +DEF_HOOKCLASSES( Direct3DVolumeTexture9 ); +DEF_HOOKCLASSES( Direct3DSwapChain9 ); +DEF_HOOKCLASSES( Direct3D9 ); +DEF_HOOKCLASSES( Direct3DDevice9 ); + +template < class _D3DINTERFACE > HRESULT AllocOverride( HRESULT *hr, class CDirect3DDevice9Hook *pDevice, _D3DINTERFACE **ppHWObj ) +{ + if( SUCCEEDED(*hr) && ppHWObj && *ppHWObj ) + { + CDx9HookBase< _D3DINTERFACE >::_HOOKCLASS *pClass = new CDx9HookBase< _D3DINTERFACE >::_HOOKCLASS; + + if(!pClass) + { + ( *ppHWObj )->Release(); + *hr = E_OUTOFMEMORY; + return NULL; + } + pClass->m_Data.pDevice = pDevice; + pClass->m_Data.pHWObj = *ppHWObj; + *ppHWObj = pClass; + return *hr; + } + + return *hr; +} + +template _D3DINTERFACE *GetHWPtr( _D3DINTERFACE *pD3DInterface ) +{ + if( pD3DInterface ) + { + CDx9HookBase< _D3DINTERFACE >::_HOOKCLASS *pClass = ( CDx9HookBase< _D3DINTERFACE >::_HOOKCLASS * )pD3DInterface; + return pClass->m_Data.pHWObj; + } + return NULL; +} + +template CDirect3DDevice9Hook *GetHookDevice( _D3DINTERFACE *pD3DInterface ) +{ + if( pD3DInterface ) + { + CDx9HookBase< _D3DINTERFACE >::_HOOKCLASS *pClass = ( CDx9HookBase< _D3DINTERFACE >::_HOOKCLASS * )pD3DInterface; + return pClass->m_Data.pDevice; + } + return NULL; +} + +//$ TODO: if(riid == IID_IDirect3DDevice9Ex, IID_IDirect3DDevice9, etc. +#define IMPL_QUERYINTERFACE() \ + STDMETHOD(QueryInterface)(THIS_ REFIID riid, void** ppvObj) \ + { \ + __debugbreak(); \ + XXX; return _DOCALL(QueryInterface, riid, ppvObj); \ + } + +#define IMPL_IUNKOWN() \ + IMPL_QUERYINTERFACE(); \ + STDMETHOD_(ULONG,AddRef)(THIS) \ + { XXX; return _DOCALL0(AddRef); } \ + STDMETHOD_(ULONG,Release)(THIS) \ + { \ + XXX; \ + ULONG retval = _DOCALL0(Release); \ + if(retval == 0) \ + delete this; \ + return retval; \ + } + +#define IMPL_GETDEVICE() \ + STDMETHOD(GetDevice)(THIS_ IDirect3DDevice9** ppDevice) \ + { \ + XXX; \ + HRESULT hr = _DOCALL( GetDevice, ppDevice ); \ + return AllocOverride( &hr, m_Data.pDevice, ppDevice ); \ + } + +#define IMPL_SETPRIVATEDATA() \ + STDMETHOD(SetPrivateData)(THIS_ REFGUID refguid,CONST void* pData,DWORD SizeOfData,DWORD Flags) \ + { XXX; return _DOCALL(SetPrivateData, refguid, pData, SizeOfData, Flags); } + +#define IMPL_GETPRIVATEDATA() \ + STDMETHOD(GetPrivateData)(THIS_ REFGUID refguid,void* pData,DWORD* pSizeOfData) \ + { XXX; return _DOCALL(GetPrivateData, refguid, pData, pSizeOfData); } + +#define IMPL_FREEPRIVATEDATA() \ + STDMETHOD(FreePrivateData)(THIS_ REFGUID refguid) \ + { XXX; return _DOCALL(FreePrivateData, refguid); } + +#define IMPL_IDIRECT3DRESOURCE9() \ + IMPL_GETDEVICE(); \ + IMPL_SETPRIVATEDATA(); \ + IMPL_GETPRIVATEDATA(); \ + IMPL_FREEPRIVATEDATA(); \ + STDMETHOD_(DWORD, SetPriority)(THIS_ DWORD PriorityNew) \ + { XXX; return _DOCALL(SetPriority, PriorityNew); } \ + STDMETHOD_(DWORD, GetPriority)(THIS) \ + { XXX; return _DOCALL0(GetPriority); } \ + STDMETHOD_(void, PreLoad)(THIS) \ + { XXX; _DOCALL0_NORET(PreLoad); } \ + STDMETHOD_(D3DRESOURCETYPE, GetType)(THIS) \ + { XXX; return _DOCALL0(GetType); } + +class CDirect3DSwapChain9Hook : public CDx9HookBase, public IDirect3DSwapChain9 +{ +public: + /*** IUnknown methods ***/ + IMPL_IUNKOWN(); + + /*** IDirect3DSwapChain9 methods ***/ + STDMETHOD(Present)(THIS_ CONST RECT* pSourceRect,CONST RECT* pDestRect,HWND hDestWindowOverride,CONST RGNDATA* pDirtyRegion,DWORD dwFlags) + { XXX; return _DOCALL(Present, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion, dwFlags); } + + STDMETHOD(GetFrontBufferData)(THIS_ IDirect3DSurface9* pDestSurface) + { + XXX; return _DOCALL(GetFrontBufferData, GetHWPtr(pDestSurface)); + } + STDMETHOD(GetBackBuffer)(THIS_ UINT iBackBuffer,D3DBACKBUFFER_TYPE Type,IDirect3DSurface9** ppBackBuffer) + { + XXX; + HRESULT hr = _DOCALL(GetBackBuffer, iBackBuffer, Type, ppBackBuffer); + return AllocOverride( &hr, m_Data.pDevice, ppBackBuffer ); + } + + STDMETHOD(GetRasterStatus)(THIS_ D3DRASTER_STATUS* pRasterStatus) + { XXX; return _DOCALL(GetRasterStatus, pRasterStatus); } + STDMETHOD(GetDisplayMode)(THIS_ D3DDISPLAYMODE* pMode) + { XXX; return _DOCALL(GetDisplayMode, pMode); } + + IMPL_GETDEVICE(); + + STDMETHOD(GetPresentParameters)(THIS_ D3DPRESENT_PARAMETERS* pPresentationParameters) + { XXX; return _DOCALL(GetPresentParameters, pPresentationParameters); } +}; + +class CDirect3DVertexDeclaration9Hook : public CDx9HookBase, public IDirect3DVertexDeclaration9 +{ +public: + /*** IUnknown methods ***/ + IMPL_IUNKOWN(); + + // IDirect3DVertexDeclaration9 methods + IMPL_GETDEVICE(); + + STDMETHOD(GetDeclaration)(THIS_ D3DVERTEXELEMENT9 *pVertElem, UINT* pNumElements) + { XXX; return _DOCALL(GetDeclaration, pVertElem, pNumElements); } +}; + +class CDirect3DPixelShader9Hook : public CDx9HookBase, public IDirect3DPixelShader9 +{ +public: + /*** IUnknown methods ***/ + IMPL_IUNKOWN(); + + // IDirect3DPixelShader9 methods + IMPL_GETDEVICE(); + + STDMETHOD(GetFunction)(THIS_ void *pData,UINT* pSizeOfData) + { XXX; return _DOCALL(GetFunction, pData, pSizeOfData); } +}; + +class CDirect3DVertexShader9Hook : public CDx9HookBase, public IDirect3DVertexShader9 +{ +public: + /*** IUnknown methods ***/ + IMPL_IUNKOWN(); + + // IDirect3DVertexDeclaration9 methods + IMPL_GETDEVICE(); + + STDMETHOD(GetFunction)(THIS_ void *pData,UINT* pSizeOfData) + { XXX; return _DOCALL(GetFunction, pData, pSizeOfData); } +}; + +class CDirect3DVertexBuffer9Hook : public CDx9HookBase, public IDirect3DVertexBuffer9 +{ +public: + /*** IUnknown methods ***/ + IMPL_IUNKOWN(); + + // IDirect3DResource9 methods + IMPL_IDIRECT3DRESOURCE9(); + + // IDirect3DVertexBuffer9 + STDMETHOD(Lock)(THIS_ UINT OffsetToLock,UINT SizeToLock,void** ppbData,DWORD Flags) + { XXX; return _DOCALL(Lock, OffsetToLock, SizeToLock, ppbData, Flags); } + STDMETHOD(Unlock)(THIS) + { XXX; return _DOCALL0(Unlock); } + + STDMETHOD(GetDesc)(THIS_ D3DVERTEXBUFFER_DESC *pDesc) + { XXX; return _DOCALL(GetDesc, pDesc); } +}; + +class CDirect3DIndexBuffer9Hook : public CDx9HookBase, public IDirect3DIndexBuffer9 +{ +public: + /*** IUnknown methods ***/ + IMPL_IUNKOWN(); + + // IDirect3DResource9 methods + IMPL_IDIRECT3DRESOURCE9(); + + // IDirect3DIndexBuffer9 + STDMETHOD(Lock)(THIS_ UINT OffsetToLock,UINT SizeToLock,void** ppbData,DWORD Flags) + { XXX; return _DOCALL(Lock, OffsetToLock, SizeToLock, ppbData, Flags); } + STDMETHOD(Unlock)(THIS) + { XXX; return _DOCALL0(Unlock); } + + STDMETHOD(GetDesc)(THIS_ D3DINDEXBUFFER_DESC *pDesc) + { XXX; return _DOCALL(GetDesc, pDesc); } +}; + +class CDirect3DQuery9Hook : public CDx9HookBase, public IDirect3DQuery9 +{ +public: + /*** IUnknown methods ***/ + IMPL_IUNKOWN(); + + /*** IDirect3DQuery9 methods ***/ + IMPL_GETDEVICE(); + + // IDirect3DQuery9 + STDMETHOD_(D3DQUERYTYPE, GetType)(THIS) + { XXX; return _DOCALL0(GetType); } + STDMETHOD_(DWORD, GetDataSize)(THIS) + { XXX; return _DOCALL0(GetDataSize); } + STDMETHOD(Issue)(THIS_ DWORD dwIssueFlags) + { XXX; return _DOCALL(Issue, dwIssueFlags); } + STDMETHOD(GetData)(THIS_ void* pData,DWORD dwSize,DWORD dwGetDataFlags) + { XXX; return _DOCALL(GetData, pData, dwSize, dwGetDataFlags); } +}; + +class CDirect3DStateBlock9Hook : public CDx9HookBase, public IDirect3DStateBlock9 +{ +public: + CDirect3DStateBlock9Hook() {} + virtual ~CDirect3DStateBlock9Hook() {} + + /*** IUnknown methods ***/ + IMPL_IUNKOWN(); + + // IDirect3DStateBlock9 methods + IMPL_GETDEVICE(); + + STDMETHOD(Capture)(THIS) + { XXX; return _DOCALL0(Capture); } + STDMETHOD(Apply)(THIS) + { XXX; return _DOCALL0(Apply); } +}; + +class CDirect3DSurface9Hook : public CDx9HookBase, public IDirect3DSurface9 +{ +public: + /*** IUnknown methods ***/ + IMPL_IUNKOWN(); + + // IDirect3DResource9 methods + IMPL_IDIRECT3DRESOURCE9(); + + STDMETHOD(GetContainer)(THIS_ REFIID riid,void** ppContainer) + { + //$ TODO: do the call, check riid, and wrap the returned ppContainer + __debugbreak(); + XXX; return _DOCALL(GetContainer, riid, ppContainer); + } + STDMETHOD(GetDesc)(THIS_ D3DSURFACE_DESC *pDesc) + { XXX; return _DOCALL(GetDesc, pDesc); } + + STDMETHOD(LockRect)(THIS_ D3DLOCKED_RECT* pLockedRect,CONST RECT* pRect,DWORD Flags) + { XXX; return _DOCALL(LockRect, pLockedRect, pRect, Flags); } + STDMETHOD(UnlockRect)(THIS) + { XXX; return _DOCALL0(UnlockRect); } + + STDMETHOD(GetDC)(THIS_ HDC *phdc) + { XXX; return _DOCALL(GetDC, phdc); } + STDMETHOD(ReleaseDC)(THIS_ HDC hdc) + { XXX; return _DOCALL(ReleaseDC, hdc); } +}; + +class CDirect3DBaseTexture9Hook : public CDx9HookBase, public IDirect3DBaseTexture9 +{ +public: + /*** IUnknown methods ***/ + IMPL_IUNKOWN(); + + /*** IDirect3DBaseTexture9 methods ***/ + IMPL_IDIRECT3DRESOURCE9(); + + STDMETHOD_(DWORD, SetLOD)(THIS_ DWORD LODNew) + { XXX; return _DOCALL(SetLOD, LODNew); } + STDMETHOD_(DWORD, GetLOD)(THIS) + { XXX; return _DOCALL0(GetLOD); } + STDMETHOD_(DWORD, GetLevelCount)(THIS) + { XXX; return _DOCALL0(GetLevelCount); } + STDMETHOD(SetAutoGenFilterType)(THIS_ D3DTEXTUREFILTERTYPE FilterType) + { XXX; return _DOCALL(SetAutoGenFilterType, FilterType); } + STDMETHOD_(D3DTEXTUREFILTERTYPE, GetAutoGenFilterType)(THIS) + { XXX; return _DOCALL0(GetAutoGenFilterType); } + STDMETHOD_(void, GenerateMipSubLevels)(THIS) + { XXX; return _DOCALL0(GenerateMipSubLevels); } +}; + +class CDirect3DTexture9Hook : public CDx9HookBase, public IDirect3DTexture9 +{ +public: + /*** IUnknown methods ***/ + IMPL_IUNKOWN(); + + /*** IDirect3DBaseTexture9 methods ***/ + IMPL_IDIRECT3DRESOURCE9(); + + STDMETHOD_(DWORD, SetLOD)(THIS_ DWORD LODNew) + { XXX; return _DOCALL(SetLOD, LODNew); } + STDMETHOD_(DWORD, GetLOD)(THIS) + { XXX; return _DOCALL0(GetLOD); } + STDMETHOD_(DWORD, GetLevelCount)(THIS) + { XXX; return _DOCALL0(GetLevelCount); } + STDMETHOD(SetAutoGenFilterType)(THIS_ D3DTEXTUREFILTERTYPE FilterType) + { XXX; return _DOCALL(SetAutoGenFilterType, FilterType); } + STDMETHOD_(D3DTEXTUREFILTERTYPE, GetAutoGenFilterType)(THIS) + { XXX; return _DOCALL0(GetAutoGenFilterType); } + + STDMETHOD_(void, GenerateMipSubLevels)(THIS) + { XXX; return _DOCALL0(GenerateMipSubLevels); } + + STDMETHOD(GetLevelDesc)(THIS_ UINT Level,D3DSURFACE_DESC *pDesc) + { XXX; return _DOCALL(GetLevelDesc, Level, pDesc); } + + STDMETHOD(GetSurfaceLevel)(THIS_ UINT Level,IDirect3DSurface9** ppSurfaceLevel) + { + XXX; + HRESULT hr = _DOCALL(GetSurfaceLevel, Level, ppSurfaceLevel); + return AllocOverride( &hr, m_Data.pDevice, ppSurfaceLevel ); + } + STDMETHOD(LockRect)(THIS_ UINT Level,D3DLOCKED_RECT* pLockedRect,CONST RECT* pRect,DWORD Flags) + { XXX; return _DOCALL(LockRect, Level, pLockedRect, pRect, Flags); } + STDMETHOD(UnlockRect)(THIS_ UINT Level) + { XXX; return _DOCALL(UnlockRect, Level); } + + STDMETHOD(AddDirtyRect)(THIS_ CONST RECT* pDirtyRect) + { XXX; return _DOCALL(AddDirtyRect, pDirtyRect); } +}; + +class CDirect3DCubeTexture9Hook : public CDx9HookBase, public IDirect3DCubeTexture9 +{ +public: + /*** IUnknown methods ***/ + IMPL_IUNKOWN(); + + /*** IDirect3DBaseTexture9 methods ***/ + IMPL_IDIRECT3DRESOURCE9(); + + STDMETHOD_(DWORD, SetLOD)(THIS_ DWORD LODNew) + { XXX; return _DOCALL(SetLOD, LODNew); } + STDMETHOD_(DWORD, GetLOD)(THIS) + { XXX; return _DOCALL0(GetLOD); } + STDMETHOD_(DWORD, GetLevelCount)(THIS) + { XXX; return _DOCALL0(GetLevelCount); } + STDMETHOD(SetAutoGenFilterType)(THIS_ D3DTEXTUREFILTERTYPE FilterType) + { XXX; return _DOCALL(SetAutoGenFilterType, FilterType); } + STDMETHOD_(D3DTEXTUREFILTERTYPE, GetAutoGenFilterType)(THIS) + { XXX; return _DOCALL0(GetAutoGenFilterType); } + + STDMETHOD_(void, GenerateMipSubLevels)(THIS) + { XXX; return _DOCALL0(GenerateMipSubLevels); } + + STDMETHOD(GetLevelDesc)(THIS_ UINT Level,D3DSURFACE_DESC *pDesc) + { XXX; return _DOCALL(GetLevelDesc, Level, pDesc); } + + STDMETHOD(GetCubeMapSurface)(THIS_ D3DCUBEMAP_FACES FaceType,UINT Level,IDirect3DSurface9** ppCubeMapSurface) + { + XXX; + HRESULT hr = _DOCALL(GetCubeMapSurface, FaceType, Level, ppCubeMapSurface); + return AllocOverride(&hr, m_Data.pDevice, ppCubeMapSurface); + } + STDMETHOD(LockRect)(THIS_ D3DCUBEMAP_FACES FaceType,UINT Level,D3DLOCKED_RECT* pLockedRect,CONST RECT* pRect,DWORD Flags) + { XXX; return _DOCALL(LockRect, FaceType, Level, pLockedRect, pRect, Flags); } + STDMETHOD(UnlockRect)(THIS_ D3DCUBEMAP_FACES FaceType,UINT Level) + { XXX; return _DOCALL(UnlockRect, FaceType, Level); } + + STDMETHOD(AddDirtyRect)(THIS_ D3DCUBEMAP_FACES FaceType,CONST RECT* pDirtyRect) + { XXX; return _DOCALL(AddDirtyRect, FaceType, pDirtyRect); } +}; + +class CDirect3DVolume9Hook : public CDx9HookBase, public IDirect3DVolume9 +{ +public: + /*** IUnknown methods ***/ + IMPL_IUNKOWN(); + + /*** IDirect3DVolume9 methods ***/ + IMPL_GETDEVICE(); + + IMPL_SETPRIVATEDATA(); + IMPL_GETPRIVATEDATA(); + IMPL_FREEPRIVATEDATA() + + STDMETHOD(GetContainer)(THIS_ REFIID riid,void** ppContainer) + { + //$ TODO: do the call, check riid, and wrap the returned ppContainer + __debugbreak(); + XXX; return _DOCALL(GetContainer, riid, ppContainer); + } + + STDMETHOD(GetDesc)(THIS_ D3DVOLUME_DESC *pDesc) + { XXX; return _DOCALL(GetDesc, pDesc); } + + STDMETHOD(LockBox)(THIS_ D3DLOCKED_BOX * pLockedVolume,CONST D3DBOX* pBox,DWORD Flags) + { XXX; return _DOCALL(LockBox, pLockedVolume, pBox, Flags); } + STDMETHOD(UnlockBox)(THIS) + { XXX; return _DOCALL0(UnlockBox); } +}; + +class CDirect3DVolumeTexture9Hook : public CDx9HookBase, public IDirect3DVolumeTexture9 +{ +public: + /*** IUnknown methods ***/ + IMPL_IUNKOWN(); + + /*** IDirect3DBaseTexture9 methods ***/ + IMPL_IDIRECT3DRESOURCE9(); + + STDMETHOD_(DWORD, SetLOD)(THIS_ DWORD LODNew) + { XXX; return _DOCALL(SetLOD, LODNew); } + STDMETHOD_(DWORD, GetLOD)(THIS) + { XXX; return _DOCALL0(GetLOD); } + STDMETHOD_(DWORD, GetLevelCount)(THIS) + { XXX; return _DOCALL0(GetLevelCount); } + STDMETHOD(SetAutoGenFilterType)(THIS_ D3DTEXTUREFILTERTYPE FilterType) + { XXX; return _DOCALL(SetAutoGenFilterType, FilterType); } + STDMETHOD_(D3DTEXTUREFILTERTYPE, GetAutoGenFilterType)(THIS) + { XXX; return _DOCALL0(GetAutoGenFilterType); } + + STDMETHOD_(void, GenerateMipSubLevels)(THIS) + { XXX; return _DOCALL0(GenerateMipSubLevels); } + + STDMETHOD(GetLevelDesc)(THIS_ UINT Level,D3DVOLUME_DESC *pDesc) + { XXX; return _DOCALL(GetLevelDesc, Level, pDesc); } + + STDMETHOD(GetVolumeLevel)(THIS_ UINT Level,IDirect3DVolume9** ppVolumeLevel) + { + XXX; + HRESULT hr = _DOCALL(GetVolumeLevel, Level, ppVolumeLevel); + return AllocOverride( &hr, m_Data.pDevice, ppVolumeLevel ); + } + STDMETHOD(LockBox)(THIS_ UINT Level,D3DLOCKED_BOX* pLockedVolume,CONST D3DBOX* pBox,DWORD Flags) + { XXX; return _DOCALL(LockBox, Level, pLockedVolume, pBox, Flags); } + STDMETHOD(UnlockBox)(THIS_ UINT Level) + { XXX; return _DOCALL(UnlockBox, Level); } + + STDMETHOD(AddDirtyBox)(THIS_ CONST D3DBOX* pDirtyBox) + { XXX; return _DOCALL(AddDirtyBox, pDirtyBox); } +}; + +class CDirect3DDevice9Hook : public CDx9HookBase, public IDirect3DDevice9 +{ +public: + /*** IUnknown methods ***/ + IMPL_IUNKOWN(); + + CDirect3DDevice9Hook() : CDx9HookBase(), IDirect3DDevice9() + { + D3D_BATCH_PERF( g_nTotalD3DCycles = 0; g_nTotalD3DCalls = 0; m_batch_state.Clear(); m_nTotalDraws = 0; m_nTotalPrims = 0; m_nTotalD3DCalls = 0; m_flTotalD3DTime = 0; m_nOverallDraws = 0; m_nOverallPrims = 0; m_nOverallD3DCalls = 0; m_flOverallD3DTime = 0; m_nTotalFrames = 0; m_pPrevRenderTarget0 = NULL; ) + } + + // IDirect3DDevice9 methods + STDMETHOD(TestCooperativeLevel)(THIS) + { XXX; return _DOCALL0(TestCooperativeLevel); } + STDMETHOD_(UINT, GetAvailableTextureMem)(THIS) + { XXX; return _DOCALL0(GetAvailableTextureMem); } + STDMETHOD(EvictManagedResources)(THIS) + { XXX; return _DOCALL0(EvictManagedResources); } + STDMETHOD(GetDirect3D)(THIS_ IDirect3D9** ppD3D9) + { + XXX; + HRESULT hr = _DOCALL(GetDirect3D, ppD3D9); + return AllocOverride(&hr, this, ppD3D9); + } + STDMETHOD(GetDeviceCaps)(THIS_ D3DCAPS9* pCaps) + { XXX; return _DOCALL(GetDeviceCaps, pCaps); } + STDMETHOD(GetDisplayMode)(THIS_ UINT iSwapChain,D3DDISPLAYMODE* pMode) + { XXX; return _DOCALL(GetDisplayMode, iSwapChain, pMode); } + STDMETHOD(GetCreationParameters)(THIS_ D3DDEVICE_CREATION_PARAMETERS *pParameters) + { XXX; return _DOCALL(GetCreationParameters, pParameters); } + STDMETHOD(SetCursorProperties)(THIS_ UINT XHotSpot,UINT YHotSpot,IDirect3DSurface9* pCursorBitmap) + { XXX; return _DOCALL(SetCursorProperties, XHotSpot, YHotSpot, GetHWPtr(pCursorBitmap)); } + STDMETHOD_(void, SetCursorPosition)(THIS_ int X,int Y,DWORD Flags) + { XXX; _DOCALL_NORET(SetCursorPosition, X, Y, Flags); } + STDMETHOD_(BOOL, ShowCursor)(THIS_ BOOL bShow) + { XXX; return _DOCALL(ShowCursor, bShow); } + STDMETHOD(CreateAdditionalSwapChain)(THIS_ D3DPRESENT_PARAMETERS* pPresentationParameters,IDirect3DSwapChain9** ppSwapChain) + { + XXX; + HRESULT hr = _DOCALL(CreateAdditionalSwapChain, pPresentationParameters, ppSwapChain); + return AllocOverride(&hr, this, ppSwapChain); + } + STDMETHOD(GetSwapChain)(THIS_ UINT iSwapChain,IDirect3DSwapChain9** ppSwapChain) + { + XXX; + HRESULT hr = _DOCALL(GetSwapChain, iSwapChain, ppSwapChain); + return AllocOverride(&hr, this, ppSwapChain); + } + STDMETHOD_(UINT, GetNumberOfSwapChains)(THIS) + { XXX; return _DOCALL0(GetNumberOfSwapChains); } + STDMETHOD(Reset)(THIS_ D3DPRESENT_PARAMETERS* pPresentationParameters) + { XXX; return _DOCALL( Reset, pPresentationParameters ); } + STDMETHOD(Present)(THIS_ CONST RECT* pSourceRect,CONST RECT* pDestRect,HWND hDestWindowOverride,CONST RGNDATA* pDirtyRegion) + { + HRESULT hres; + +#if D3D_BATCH_PERF_ANALYSIS + uint64 nStartCycles = g_nTotalD3DCycles; + + CFastTimer tm; + tm.Start(); + + g_nTotalD3DCalls++; +#endif + + { + XXX; + hres = _DOCALL(Present, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion); + } + +#if D3D_BATCH_PERF_ANALYSIS + const uint nFrameIndex = m_nTotalFrames; + m_nTotalFrames++; + + if (nFrameIndex >= 5) + { + double flPresentTime = tm.GetDurationInProgress().GetMillisecondsF(); + uint64 nEndCycles = g_nTotalD3DCycles; + + double flTotalPresentTime = ( nEndCycles - nStartCycles ) * s_rdtsc_to_ms; + + m_nTotalD3DCalls += g_nTotalD3DCalls; + m_flTotalD3DTime += g_nTotalD3DCycles * s_rdtsc_to_ms; + + static int bPrevBatchVis = -1; + + if ((bPrevBatchVis == 1) && m_batch_vis_bitmap.is_valid()) + { + m_nOverallDraws += m_nTotalDraws; + m_nOverallPrims += m_nTotalPrims; + m_nOverallD3DCalls += m_nTotalD3DCalls; + m_flOverallD3DTime += m_flTotalD3DTime; + + m_batch_vis_bitmap.fill_box(0, m_nBatchVisY, (uint)(.5f + flPresentTime / d3d_present_vis_abs_scale.GetFloat() * m_batch_vis_bitmap.width()), 10, 255, 16, 128); + m_batch_vis_bitmap.additive_fill_box(0, m_nBatchVisY, (uint)(.5f + flTotalPresentTime / d3d_present_vis_abs_scale.GetFloat() * m_batch_vis_bitmap.width()), 10, 0, 255, 128); + m_nBatchVisY += 10; + + uint y = MAX( 600, m_nBatchVisY + 20 ), l = 0; + m_batch_vis_bitmap.draw_formatted_text(0, y+8*(l++), 1, 255, 255, 255, "Frame: %u, Batches: %u, Prims: %u", nFrameIndex, m_nTotalDraws, m_nTotalPrims ); + m_batch_vis_bitmap.draw_formatted_text(0, y+8*(l++), 1, 255, 255, 255, "Frame: D3D Calls: %u, D3D Time: %3.3fms", m_nTotalD3DCalls, m_flTotalD3DTime); + l++; + m_batch_vis_bitmap.draw_formatted_text(0, y+8*(l++), 1, 255, 255, 255, "Overall: Batches: %u, Prims: %u", m_nOverallDraws, m_nOverallPrims ); + m_batch_vis_bitmap.draw_formatted_text(0, y+8*(l++), 1, 255, 255, 255, "Overall: D3D Calls: %u D3D Time: %4.3fms", m_nOverallD3DCalls, m_flOverallD3DTime ); + + size_t png_size = 0; + void *pPNG_data = tdefl_write_image_to_png_file_in_memory(m_batch_vis_bitmap.get_ptr(), m_batch_vis_bitmap.width(), m_batch_vis_bitmap.height(), 3, &png_size, true); + if (pPNG_data) + { + char filename[256]; + V_snprintf(filename, sizeof(filename), "left4dead2/batchvis_%u_%u.png", m_nBatchVisFileIdx, m_nBatchVisFrameIndex); + FILE* pFile = fopen(filename, "wb"); + if (pFile) + { + fwrite(pPNG_data, png_size, 1, pFile); + fclose(pFile); + } + free(pPNG_data); + } + m_nBatchVisFrameIndex++; + m_nBatchVisY = 0; + m_batch_vis_bitmap.cls(); + } + + if (bPrevBatchVis != (int)d3d_batch_vis.GetBool()) + { + bPrevBatchVis = d3d_batch_vis.GetBool(); + if (!bPrevBatchVis) + { + m_batch_vis_bitmap.clear(); + } + else + { + m_batch_vis_bitmap.init(768, 1024); + } + m_nBatchVisY = 0; + m_nBatchVisFrameIndex = 0; + m_nBatchVisFileIdx = (uint)time(NULL); //rand(); + + m_nOverallDraws = 0; + m_nOverallPrims = 0; + m_nOverallD3DCalls = 0; + m_flOverallD3DTime = 0; + } + } + + m_nTotalD3DCalls = 0; + m_nTotalPrims = 0; + m_flTotalD3DTime = 0; + g_nTotalD3DCycles = 0; + g_nTotalD3DCalls = 0; + m_nTotalDraws = 0; +#else + if ( d3d_batch_vis.GetBool() ) + { + d3d_batch_vis.SetValue( false ); + + ConMsg( "Must define D3D_BATCH_PERF_ANALYSIS to use this feature" ); + } +#endif + + return hres; + } + + STDMETHOD(GetBackBuffer)(THIS_ UINT iSwapChain,UINT iBackBuffer,D3DBACKBUFFER_TYPE Type,IDirect3DSurface9** ppBackBuffer) + { + XXX; + HRESULT hr = _DOCALL(GetBackBuffer, iSwapChain, iBackBuffer, Type, ppBackBuffer); + return AllocOverride(&hr, this, ppBackBuffer); + } + STDMETHOD(GetRasterStatus)(THIS_ UINT iSwapChain,D3DRASTER_STATUS* pRasterStatus) + { XXX; return _DOCALL(GetRasterStatus, iSwapChain, pRasterStatus); } + STDMETHOD(SetDialogBoxMode)(THIS_ BOOL bEnableDialogs) + { XXX; return _DOCALL(SetDialogBoxMode, bEnableDialogs); } + STDMETHOD_(void, SetGammaRamp)(THIS_ UINT iSwapChain,DWORD Flags,CONST D3DGAMMARAMP* pRamp) + { XXX; _DOCALL_NORET(SetGammaRamp, iSwapChain, Flags, pRamp); } + STDMETHOD_(void, GetGammaRamp)(THIS_ UINT iSwapChain,D3DGAMMARAMP* pRamp) + { XXX; _DOCALL_NORET(GetGammaRamp, iSwapChain, pRamp); } + STDMETHOD(CreateTexture)(THIS_ UINT Width,UINT Height,UINT Levels,DWORD Usage,D3DFORMAT Format,D3DPOOL Pool,IDirect3DTexture9** ppTexture,HANDLE* pSharedHandle) + { + XXX; + HRESULT hr = _DOCALL(CreateTexture, Width, Height, Levels, Usage, Format, Pool, ppTexture, pSharedHandle); + return AllocOverride(&hr, this, ppTexture); + } + STDMETHOD(CreateVolumeTexture)(THIS_ UINT Width,UINT Height,UINT Depth,UINT Levels,DWORD Usage,D3DFORMAT Format,D3DPOOL Pool,IDirect3DVolumeTexture9** ppVolumeTexture,HANDLE* pSharedHandle) + { + XXX; + HRESULT hr = _DOCALL(CreateVolumeTexture, Width, Height, Depth, Levels, Usage, Format, Pool, ppVolumeTexture, pSharedHandle); + return AllocOverride(&hr, this, ppVolumeTexture); + } + STDMETHOD(CreateCubeTexture)(THIS_ UINT EdgeLength,UINT Levels,DWORD Usage,D3DFORMAT Format,D3DPOOL Pool,IDirect3DCubeTexture9** ppCubeTexture,HANDLE* pSharedHandle) + { + XXX; + HRESULT hr = _DOCALL(CreateCubeTexture, EdgeLength, Levels, Usage, Format, Pool, ppCubeTexture, pSharedHandle); + return AllocOverride(&hr, this, ppCubeTexture); + } + STDMETHOD(CreateVertexBuffer)(THIS_ UINT Length,DWORD Usage,DWORD FVF,D3DPOOL Pool,IDirect3DVertexBuffer9** ppVertexBuffer,HANDLE* pSharedHandle) + { + XXX; + HRESULT hr = _DOCALL(CreateVertexBuffer, Length, Usage, FVF, Pool, ppVertexBuffer, pSharedHandle); + return AllocOverride(&hr, this, ppVertexBuffer); + } + STDMETHOD(CreateIndexBuffer)(THIS_ UINT Length,DWORD Usage,D3DFORMAT Format,D3DPOOL Pool,IDirect3DIndexBuffer9** ppIndexBuffer,HANDLE* pSharedHandle) + { + XXX; + HRESULT hr = _DOCALL(CreateIndexBuffer, Length, Usage, Format, Pool, ppIndexBuffer, pSharedHandle); + return AllocOverride(&hr, this, ppIndexBuffer); + } + STDMETHOD(CreateRenderTarget)(THIS_ UINT Width,UINT Height,D3DFORMAT Format,D3DMULTISAMPLE_TYPE MultiSample,DWORD MultiSampleQuality,BOOL Lockable,IDirect3DSurface9** ppSurface,HANDLE* pSharedHandle) + { + XXX; + HRESULT hr = _DOCALL(CreateRenderTarget, Width, Height, Format, MultiSample, MultiSampleQuality, Lockable, ppSurface, pSharedHandle); + return AllocOverride(&hr, this, ppSurface); + } + STDMETHOD(CreateDepthStencilSurface)(THIS_ UINT Width,UINT Height,D3DFORMAT Format,D3DMULTISAMPLE_TYPE MultiSample,DWORD MultiSampleQuality,BOOL Discard,IDirect3DSurface9** ppSurface,HANDLE* pSharedHandle) + { + XXX; + HRESULT hr = _DOCALL(CreateDepthStencilSurface, Width, Height, Format, MultiSample, MultiSampleQuality, Discard, ppSurface, pSharedHandle); + return AllocOverride(&hr, this, ppSurface); + } + STDMETHOD(UpdateSurface)(THIS_ IDirect3DSurface9* pSourceSurface,CONST RECT* pSourceRect,IDirect3DSurface9* pDestinationSurface,CONST POINT* pDestPoint) + { XXX; return _DOCALL(UpdateSurface, GetHWPtr(pSourceSurface), pSourceRect, GetHWPtr(pDestinationSurface), pDestPoint); } + STDMETHOD(UpdateTexture)(THIS_ IDirect3DBaseTexture9* pSourceTexture,IDirect3DBaseTexture9* pDestinationTexture) + { XXX; return _DOCALL(UpdateTexture, GetHWPtr(pSourceTexture), GetHWPtr(pDestinationTexture)); } + STDMETHOD(GetRenderTargetData)(THIS_ IDirect3DSurface9* pRenderTarget,IDirect3DSurface9* pDestSurface) + { XXX; return _DOCALL(GetRenderTargetData, GetHWPtr(pRenderTarget), GetHWPtr(pDestSurface)); } + STDMETHOD(GetFrontBufferData)(THIS_ UINT iSwapChain,IDirect3DSurface9* pDestSurface) + { XXX; return _DOCALL(GetFrontBufferData, iSwapChain, GetHWPtr(pDestSurface)); } + STDMETHOD(StretchRect)(THIS_ IDirect3DSurface9* pSourceSurface,CONST RECT* pSourceRect,IDirect3DSurface9* pDestSurface,CONST RECT* pDestRect,D3DTEXTUREFILTERTYPE Filter) + { XXX; return _DOCALL(StretchRect, GetHWPtr(pSourceSurface), pSourceRect, GetHWPtr(pDestSurface), pDestRect, Filter); } + STDMETHOD(ColorFill)(THIS_ IDirect3DSurface9* pSurface,CONST RECT* pRect,D3DCOLOR color) + { XXX; return _DOCALL(ColorFill, GetHWPtr(pSurface), pRect, color); } + STDMETHOD(CreateOffscreenPlainSurface)(THIS_ UINT Width,UINT Height,D3DFORMAT Format,D3DPOOL Pool,IDirect3DSurface9** ppSurface,HANDLE* pSharedHandle) + { + XXX; + HRESULT hr = _DOCALL(CreateOffscreenPlainSurface, Width, Height, Format, Pool, ppSurface, pSharedHandle); + return AllocOverride(&hr, this, ppSurface); + } + + STDMETHOD(SetRenderTarget)(THIS_ DWORD RenderTargetIndex,IDirect3DSurface9* pRenderTarget) + { + HRESULT hres; + { + XXX; + hres = _DOCALL(SetRenderTarget, RenderTargetIndex, GetHWPtr(pRenderTarget)); + } +#if D3D_BATCH_PERF_ANALYSIS + if ( m_batch_vis_bitmap.is_valid() && !RenderTargetIndex ) + { + if ( pRenderTarget != m_pPrevRenderTarget0 ) + { + m_batch_vis_bitmap.fill_box(0, m_nBatchVisY, m_batch_vis_bitmap.width(), 1, 30, 20, 20); + m_nBatchVisY += 1; + } + } + if ( !RenderTargetIndex ) + { + m_pPrevRenderTarget0 = pRenderTarget; + } +#endif + return hres; + } + + STDMETHOD(GetRenderTarget)(THIS_ DWORD RenderTargetIndex,IDirect3DSurface9** ppRenderTarget) + { + XXX; + HRESULT hr = _DOCALL(GetRenderTarget, RenderTargetIndex, ppRenderTarget); + return AllocOverride(&hr, this, ppRenderTarget); + } + STDMETHOD(SetDepthStencilSurface)(THIS_ IDirect3DSurface9* pNewZStencil) + { XXX; return _DOCALL(SetDepthStencilSurface, GetHWPtr(pNewZStencil)); } + STDMETHOD(GetDepthStencilSurface)(THIS_ IDirect3DSurface9** ppZStencilSurface) + { + XXX; + HRESULT hr = _DOCALL(GetDepthStencilSurface, ppZStencilSurface); + return AllocOverride(&hr, this, ppZStencilSurface); + } + STDMETHOD(BeginScene)(THIS) + { XXX; return _DOCALL0(BeginScene); } + STDMETHOD(EndScene)(THIS) + { XXX; return _DOCALL0(EndScene); } + STDMETHOD(Clear)(THIS_ DWORD Count,CONST D3DRECT* pRects,DWORD Flags,D3DCOLOR Color,float Z,DWORD Stencil) + { XXX; return _DOCALL(Clear, Count, pRects, Flags, Color, Z, Stencil); } + STDMETHOD(SetTransform)(THIS_ D3DTRANSFORMSTATETYPE State,CONST D3DMATRIX* pMatrix) + { XXX; return _DOCALL(SetTransform, State, pMatrix); } + STDMETHOD(GetTransform)(THIS_ D3DTRANSFORMSTATETYPE State,D3DMATRIX* pMatrix) + { XXX; return _DOCALL(GetTransform, State, pMatrix); } + STDMETHOD(MultiplyTransform)(THIS_ D3DTRANSFORMSTATETYPE State,CONST D3DMATRIX *pMatrix) + { XXX; return _DOCALL(MultiplyTransform, State, pMatrix); } + STDMETHOD(SetViewport)(THIS_ CONST D3DVIEWPORT9* pViewport) + { XXX; return _DOCALL(SetViewport, pViewport); } + STDMETHOD(GetViewport)(THIS_ D3DVIEWPORT9* pViewport) + { XXX; return _DOCALL(GetViewport, pViewport); } + STDMETHOD(SetMaterial)(THIS_ CONST D3DMATERIAL9* pMaterial) + { XXX; return _DOCALL(SetMaterial, pMaterial); } + STDMETHOD(GetMaterial)(THIS_ D3DMATERIAL9* pMaterial) + { XXX; return _DOCALL(GetMaterial, pMaterial); } + STDMETHOD(SetLight)(THIS_ DWORD Index,CONST D3DLIGHT9* pLight) + { XXX; return _DOCALL(SetLight, Index, pLight); } + STDMETHOD(GetLight)(THIS_ DWORD Index,D3DLIGHT9* pLight) + { XXX; return _DOCALL(GetLight, Index, pLight); } + STDMETHOD(LightEnable)(THIS_ DWORD Index,BOOL Enable) + { XXX; return _DOCALL(LightEnable, Index, Enable); } + STDMETHOD(GetLightEnable)(THIS_ DWORD Index,BOOL* pEnable) + { XXX; return _DOCALL(GetLightEnable, Index, pEnable); } + STDMETHOD(SetClipPlane)(THIS_ DWORD Index,CONST float* pPlane) + { XXX; return _DOCALL(SetClipPlane, Index, pPlane);} + STDMETHOD(GetClipPlane)(THIS_ DWORD Index,float* pPlane) + { XXX; return _DOCALL(GetClipPlane, Index, pPlane); } + STDMETHOD(SetRenderState)(THIS_ D3DRENDERSTATETYPE State,DWORD Value) + { XXX; return _DOCALL(SetRenderState, State, Value); } + STDMETHOD(GetRenderState)(THIS_ D3DRENDERSTATETYPE State,DWORD* pValue) + { XXX; return _DOCALL(GetRenderState, State, pValue); } + STDMETHOD(CreateStateBlock)(THIS_ D3DSTATEBLOCKTYPE Type,IDirect3DStateBlock9** ppSB) + { + XXX; + HRESULT hr = _DOCALL(CreateStateBlock, Type, ppSB); + return AllocOverride(&hr, this, ppSB); + } + STDMETHOD(BeginStateBlock)(THIS) + { XXX; return _DOCALL0(BeginStateBlock); } + STDMETHOD(EndStateBlock)(THIS_ IDirect3DStateBlock9** ppSB) + { + XXX; + HRESULT hr = _DOCALL(EndStateBlock, ppSB); + return AllocOverride(&hr, this, ppSB); + } + STDMETHOD(SetClipStatus)(THIS_ CONST D3DCLIPSTATUS9* pClipStatus) + { XXX; return _DOCALL(SetClipStatus, pClipStatus);} + STDMETHOD(GetClipStatus)(THIS_ D3DCLIPSTATUS9* pClipStatus) + { XXX; return _DOCALL(GetClipStatus, pClipStatus);} + STDMETHOD(GetTexture)(THIS_ DWORD Stage,IDirect3DBaseTexture9** ppTexture) + { + XXX; + HRESULT hr = _DOCALL(GetTexture, Stage, ppTexture); + return AllocOverride(&hr, this, ppTexture); + } + + STDMETHOD(SetTexture)(THIS_ DWORD Stage,IDirect3DBaseTexture9* pTexture) + { + HRESULT hres; + { + XXX; + hres = _DOCALL(SetTexture, Stage, GetHWPtr(pTexture)); + } + D3D_BATCH_PERF( m_batch_state.m_nNumSamplersChanged++; ) + return hres; + } + + STDMETHOD(GetTextureStageState)(THIS_ DWORD Stage,D3DTEXTURESTAGESTATETYPE Type,DWORD* pValue) + { XXX; return _DOCALL(GetTextureStageState, Stage, Type, pValue); } + STDMETHOD(SetTextureStageState)(THIS_ DWORD Stage,D3DTEXTURESTAGESTATETYPE Type,DWORD Value) + { XXX; return _DOCALL(SetTextureStageState, Stage, Type, Value); } + STDMETHOD(GetSamplerState)(THIS_ DWORD Sampler,D3DSAMPLERSTATETYPE Type,DWORD* pValue) + { XXX; return _DOCALL(GetSamplerState, Sampler, Type, pValue); } + STDMETHOD(SetSamplerState)(THIS_ DWORD Sampler,D3DSAMPLERSTATETYPE Type,DWORD Value) + { + HRESULT hres; + { + XXX; + hres = _DOCALL(SetSamplerState, Sampler, Type, Value); + } + D3D_BATCH_PERF( m_batch_state.m_nNumSamplerStatesChanged++; ) + return hres; + } + + STDMETHOD(ValidateDevice)(THIS_ DWORD* pNumPasses) + { XXX; return _DOCALL(ValidateDevice, pNumPasses); } + STDMETHOD(SetPaletteEntries)(THIS_ UINT PaletteNumber,CONST PALETTEENTRY* pEntries) + { XXX; return _DOCALL(SetPaletteEntries, PaletteNumber, pEntries); } + STDMETHOD(GetPaletteEntries)(THIS_ UINT PaletteNumber,PALETTEENTRY* pEntries) + { XXX; return _DOCALL(GetPaletteEntries, PaletteNumber, pEntries); } + STDMETHOD(SetCurrentTexturePalette)(THIS_ UINT PaletteNumber) + { XXX; return _DOCALL(SetCurrentTexturePalette, PaletteNumber);} + STDMETHOD(GetCurrentTexturePalette)(THIS_ UINT *PaletteNumber) + { XXX; return _DOCALL(GetCurrentTexturePalette, PaletteNumber); } + STDMETHOD(SetScissorRect)(THIS_ CONST RECT* pRect) + { XXX; return _DOCALL(SetScissorRect, pRect); } + STDMETHOD(GetScissorRect)(THIS_ RECT* pRect) + { XXX; return _DOCALL(GetScissorRect, pRect); } + STDMETHOD(SetSoftwareVertexProcessing)(THIS_ BOOL bSoftware) + { XXX; return _DOCALL(SetSoftwareVertexProcessing, bSoftware); } + STDMETHOD_(BOOL, GetSoftwareVertexProcessing)(THIS) + { XXX; return _DOCALL0(GetSoftwareVertexProcessing); } + STDMETHOD(SetNPatchMode)(THIS_ float nSegments) + { XXX; return _DOCALL(SetNPatchMode, nSegments); } + STDMETHOD_(float, GetNPatchMode)(THIS) + { XXX; return _DOCALL0(GetNPatchMode);} + STDMETHOD(DrawPrimitive)(THIS_ D3DPRIMITIVETYPE PrimitiveType,UINT StartVertex,UINT PrimitiveCount) + { XXX; m_nTotalDraws++; m_nTotalPrims += PrimitiveCount; return _DOCALL(DrawPrimitive, PrimitiveType, StartVertex, PrimitiveCount); } + STDMETHOD(DrawIndexedPrimitive)(THIS_ D3DPRIMITIVETYPE PrimitiveType,INT BaseVertexIndex,UINT MinVertexIndex,UINT NumVertices,UINT startIndex,UINT primCount) + { + m_nTotalDraws++; + m_nTotalPrims += primCount; + +#if D3D_BATCH_PERF_ANALYSIS + CFastTimer tm; + if ( m_batch_vis_bitmap.is_valid() ) + { + tm.Start(); + } +#endif + + HRESULT hres; + { + XXX; + hres = _DOCALL(DrawIndexedPrimitive, PrimitiveType, BaseVertexIndex, MinVertexIndex, NumVertices, startIndex, primCount); + } + +#if D3D_BATCH_PERF_ANALYSIS + if ( m_batch_vis_bitmap.is_valid() ) + { + double t = tm.GetDurationInProgress().GetMillisecondsF(); + + uint h = 1; + if ( d3d_batch_vis_y_scale.GetFloat() > 0.0f) + { + h = ceil( t / d3d_batch_vis_y_scale.GetFloat() ); + h = MAX(h, 1); + } + + m_batch_vis_bitmap.fill_box(0, m_nBatchVisY, (uint)(.5f + t / d3d_batch_vis_abs_scale.GetFloat() * m_batch_vis_bitmap.width()), h, 64, 64, 64); + + if ( s_rdtsc_to_ms == 0.0f ) + { + TmU64 t0 = tmFastTime(); + double d0 = Plat_FloatTime(); + + ThreadSleep( 1 ); + + TmU64 t1 = tmFastTime(); + double d1 = Plat_FloatTime(); + + s_rdtsc_to_ms = ( 1000.0f * ( d1 - d0 ) ) / ( t1 - t0 ); + } + + double flTotalD3DCallMS = g_nTotalD3DCycles * s_rdtsc_to_ms; + + m_batch_vis_bitmap.additive_fill_box(0, m_nBatchVisY, (uint)(.5f + flTotalD3DCallMS / d3d_batch_vis_abs_scale.GetFloat() * m_batch_vis_bitmap.width()), h, 96, 96, 128); + + if (m_batch_state.m_bVertexShaderChanged) m_batch_vis_bitmap.additive_fill_box(0, m_nBatchVisY, 8, h, 0, 0, 64); + if (m_batch_state.m_bPixelShaderChanged) m_batch_vis_bitmap.additive_fill_box(32, m_nBatchVisY, 8, h, 64, 0, 64); + + int lm = 80; + m_batch_vis_bitmap.fill_box(lm+0+0, m_nBatchVisY, m_batch_state.m_nNumVSConstants, h, 64, 255, 255); + m_batch_vis_bitmap.fill_box(lm+64+256+0, m_nBatchVisY, m_batch_state.m_nNumPSConstants, h, 64, 64, 255); + + m_batch_vis_bitmap.fill_box(lm+64+256+32, m_nBatchVisY, m_batch_state.m_nNumSamplersChanged, h, 255, 255, 255); + m_batch_vis_bitmap.fill_box(lm+64+256+32+16, m_nBatchVisY, m_batch_state.m_nNumSamplerStatesChanged, h, 92, 128, 255); + + if ( m_batch_state.m_bStreamSourceChanged) m_batch_vis_bitmap.fill_box(lm+64+256+32+16+64, m_nBatchVisY, 16, h, 128, 128, 128); + if ( m_batch_state.m_bIndicesChanged ) m_batch_vis_bitmap.fill_box(lm+64+256+32+16+64+16, m_nBatchVisY, 16, h, 128, 128, 255); + + m_nBatchVisY += h; + + m_nTotalD3DCalls += g_nTotalD3DCalls; + m_flTotalD3DTime += flTotalD3DCallMS; + + g_nTotalD3DCycles = 0; + g_nTotalD3DCalls = 0; + + m_batch_state.Clear(); + } +#endif + + return hres; + } + + STDMETHOD(DrawPrimitiveUP)(THIS_ D3DPRIMITIVETYPE PrimitiveType,UINT PrimitiveCount,CONST void* pVertexStreamZeroData,UINT VertexStreamZeroStride) + { XXX; m_nTotalDraws++; m_nTotalPrims += PrimitiveCount; return _DOCALL(DrawPrimitiveUP, PrimitiveType, PrimitiveCount, pVertexStreamZeroData, VertexStreamZeroStride); } + STDMETHOD(DrawIndexedPrimitiveUP)(THIS_ D3DPRIMITIVETYPE PrimitiveType,UINT MinVertexIndex,UINT NumVertices,UINT PrimitiveCount,CONST void* pIndexData,D3DFORMAT IndexDataFormat,CONST void* pVertexStreamZeroData,UINT VertexStreamZeroStride) + { XXX; m_nTotalDraws++; m_nTotalPrims += PrimitiveCount; return _DOCALL(DrawIndexedPrimitiveUP, PrimitiveType, MinVertexIndex, NumVertices, PrimitiveCount, pIndexData, IndexDataFormat, pVertexStreamZeroData, VertexStreamZeroStride); } + STDMETHOD(ProcessVertices)(THIS_ UINT SrcStartIndex,UINT DestIndex,UINT VertexCount,IDirect3DVertexBuffer9* pDestBuffer,IDirect3DVertexDeclaration9* pVertexDecl,DWORD Flags) + { XXX; return _DOCALL(ProcessVertices, SrcStartIndex, DestIndex, VertexCount, GetHWPtr(pDestBuffer), GetHWPtr(pVertexDecl), Flags); } + STDMETHOD(CreateVertexDeclaration)(THIS_ CONST D3DVERTEXELEMENT9* pVertexElements,IDirect3DVertexDeclaration9** ppDecl) + { + XXX; + HRESULT hr = _DOCALL(CreateVertexDeclaration, pVertexElements, ppDecl); + return AllocOverride(&hr, this, ppDecl); + } + STDMETHOD(SetVertexDeclaration)(THIS_ IDirect3DVertexDeclaration9* pDecl) + { XXX; return _DOCALL(SetVertexDeclaration, GetHWPtr(pDecl)); } + STDMETHOD(GetVertexDeclaration)(THIS_ IDirect3DVertexDeclaration9** ppDecl) + { + XXX; + HRESULT hr = _DOCALL(GetVertexDeclaration, ppDecl); + return AllocOverride(&hr, this, ppDecl); + } + STDMETHOD(SetFVF)(THIS_ DWORD FVF) + { XXX; return _DOCALL(SetFVF, FVF); } + STDMETHOD(GetFVF)(THIS_ DWORD* pFVF) + { XXX; return _DOCALL(GetFVF, pFVF); } + STDMETHOD(CreateVertexShader)(THIS_ CONST DWORD* pFunction,IDirect3DVertexShader9** ppShader) + { + XXX; + HRESULT hr = _DOCALL(CreateVertexShader, pFunction, ppShader); + return AllocOverride(&hr, this, ppShader); + } + + STDMETHOD(SetVertexShader)(THIS_ IDirect3DVertexShader9* pShader) + { + HRESULT hres; + { + XXX; + hres = _DOCALL(SetVertexShader, GetHWPtr(pShader)); + } + D3D_BATCH_PERF( m_batch_state.m_bVertexShaderChanged = true; ) + return hres; + } + + STDMETHOD(GetVertexShader)(THIS_ IDirect3DVertexShader9** ppShader) + { + XXX; + HRESULT hr = _DOCALL(GetVertexShader, ppShader); + return AllocOverride(&hr, this, ppShader); + } + + STDMETHOD(SetVertexShaderConstantF)(THIS_ UINT StartRegister,CONST float* pConstantData,UINT Vector4fCount) + { + HRESULT hres; + { + XXX; + hres = _DOCALL(SetVertexShaderConstantF, StartRegister, pConstantData, Vector4fCount); + } + D3D_BATCH_PERF( m_batch_state.m_nNumVSConstants += Vector4fCount; ) + return hres; + } + + STDMETHOD(GetVertexShaderConstantF)(THIS_ UINT StartRegister,float* pConstantData,UINT Vector4fCount) + { XXX; return _DOCALL(GetVertexShaderConstantF, StartRegister, pConstantData, Vector4fCount);} + STDMETHOD(SetVertexShaderConstantI)(THIS_ UINT StartRegister,CONST int* pConstantData,UINT Vector4iCount) + { XXX; return _DOCALL(SetVertexShaderConstantI, StartRegister, pConstantData, Vector4iCount); } + STDMETHOD(GetVertexShaderConstantI)(THIS_ UINT StartRegister,int* pConstantData,UINT Vector4iCount) + { XXX; return _DOCALL(GetVertexShaderConstantI, StartRegister, pConstantData, Vector4iCount); } + STDMETHOD(SetVertexShaderConstantB)(THIS_ UINT StartRegister,CONST BOOL* pConstantData,UINT BoolCount) + { XXX; return _DOCALL(SetVertexShaderConstantB, StartRegister, pConstantData, BoolCount); } + STDMETHOD(GetVertexShaderConstantB)(THIS_ UINT StartRegister,BOOL* pConstantData,UINT BoolCount) + { XXX; return _DOCALL(GetVertexShaderConstantB, StartRegister, pConstantData, BoolCount); } + + STDMETHOD(SetStreamSource)(THIS_ UINT StreamNumber,IDirect3DVertexBuffer9* pStreamData,UINT OffsetInBytes,UINT Stride) + + { + HRESULT hres; + { + XXX; + hres = _DOCALL(SetStreamSource, StreamNumber, GetHWPtr(pStreamData), OffsetInBytes, Stride); + } + + D3D_BATCH_PERF( m_batch_state.m_bStreamSourceChanged = true; ) + + return hres; + } + + STDMETHOD(GetStreamSource)(THIS_ UINT StreamNumber,IDirect3DVertexBuffer9** ppStreamData,UINT* OffsetInBytes,UINT* pStride) + { + XXX; + HRESULT hr = _DOCALL(GetStreamSource, StreamNumber, ppStreamData, OffsetInBytes, pStride); + return AllocOverride(&hr, this, ppStreamData); + } + STDMETHOD(SetStreamSourceFreq)(THIS_ UINT StreamNumber,UINT Divider) + { XXX; return _DOCALL(SetStreamSourceFreq, StreamNumber, Divider); } + + STDMETHOD(GetStreamSourceFreq)(THIS_ UINT StreamNumber,UINT* Divider) + { XXX; return _DOCALL(GetStreamSourceFreq, StreamNumber, Divider); } + + STDMETHOD(SetIndices)(THIS_ IDirect3DIndexBuffer9* pIndexData) + { + HRESULT hres; + + { + XXX; + hres = _DOCALL(SetIndices, GetHWPtr(pIndexData)); + } + + D3D_BATCH_PERF( m_batch_state.m_bIndicesChanged = true; ) + + return hres; + } + + STDMETHOD(GetIndices)(THIS_ IDirect3DIndexBuffer9** ppIndexData) + { + XXX; + HRESULT hr = _DOCALL(GetIndices, ppIndexData); + return AllocOverride(&hr, this, ppIndexData); + } + STDMETHOD(CreatePixelShader)(THIS_ CONST DWORD* pFunction,IDirect3DPixelShader9** ppShader) + { + XXX; + HRESULT hr = _DOCALL(CreatePixelShader, pFunction, ppShader); + return AllocOverride(&hr, this, ppShader); + } + + STDMETHOD(SetPixelShader)(THIS_ IDirect3DPixelShader9* pShader) + { + HRESULT hres; + { + XXX; + hres = _DOCALL(SetPixelShader, GetHWPtr(pShader)); + } + D3D_BATCH_PERF( m_batch_state.m_bPixelShaderChanged = true; ) + return hres; + } + + STDMETHOD(GetPixelShader)(THIS_ IDirect3DPixelShader9** ppShader) + { + XXX; + HRESULT hr = _DOCALL(GetPixelShader, ppShader); + return AllocOverride(&hr, this, ppShader); + } + + STDMETHOD(SetPixelShaderConstantF)(THIS_ UINT StartRegister,CONST float* pConstantData,UINT Vector4fCount) + { + HRESULT hres; + { + XXX; + hres = _DOCALL(SetPixelShaderConstantF, StartRegister, pConstantData, Vector4fCount); + } + D3D_BATCH_PERF( m_batch_state.m_nNumPSConstants += Vector4fCount; ) + return hres; + } + + STDMETHOD(GetPixelShaderConstantF)(THIS_ UINT StartRegister,float* pConstantData,UINT Vector4fCount) + { XXX; return _DOCALL(GetPixelShaderConstantF, StartRegister, pConstantData, Vector4fCount); } + STDMETHOD(SetPixelShaderConstantI)(THIS_ UINT StartRegister,CONST int* pConstantData,UINT Vector4iCount) + { XXX; return _DOCALL(SetPixelShaderConstantI, StartRegister, pConstantData, Vector4iCount); } + STDMETHOD(GetPixelShaderConstantI)(THIS_ UINT StartRegister,int* pConstantData,UINT Vector4iCount) + { XXX; return _DOCALL(GetPixelShaderConstantI, StartRegister, pConstantData, Vector4iCount); } + STDMETHOD(SetPixelShaderConstantB)(THIS_ UINT StartRegister,CONST BOOL* pConstantData,UINT BoolCount) + { XXX; return _DOCALL(SetPixelShaderConstantB, StartRegister, pConstantData, BoolCount); } + STDMETHOD(GetPixelShaderConstantB)(THIS_ UINT StartRegister,BOOL* pConstantData,UINT BoolCount) + { XXX; return _DOCALL(GetPixelShaderConstantB, StartRegister, pConstantData, BoolCount); } + STDMETHOD(DrawRectPatch)(THIS_ UINT Handle,CONST float* pNumSegs,CONST D3DRECTPATCH_INFO* pRectPatchInfo) + { XXX; return _DOCALL(DrawRectPatch, Handle, pNumSegs, pRectPatchInfo);} + STDMETHOD(DrawTriPatch)(THIS_ UINT Handle,CONST float* pNumSegs,CONST D3DTRIPATCH_INFO* pTriPatchInfo) + { XXX; return _DOCALL(DrawTriPatch, Handle, pNumSegs, pTriPatchInfo); } + STDMETHOD(DeletePatch)(THIS_ UINT Handle) + { XXX; return _DOCALL(DeletePatch, Handle);} + STDMETHOD(CreateQuery)(THIS_ D3DQUERYTYPE Type,IDirect3DQuery9** ppQuery) + { + XXX; + HRESULT hr = _DOCALL(CreateQuery, Type, ppQuery); + return AllocOverride(&hr, this, ppQuery); + } + +private: + +#if D3D_BATCH_PERF_ANALYSIS + IDirect3DSurface9* m_pPrevRenderTarget0; + simple_bitmap m_batch_vis_bitmap; + uint m_nBatchVisY; + uint m_nBatchVisFrameIndex, m_nBatchVisFileIdx; + + struct BatchState_t + { + void Clear() { memset(this, 0, sizeof(*this)); } + + bool m_bStreamSourceChanged; + bool m_bIndicesChanged; + bool m_bPixelShaderChanged; + bool m_bVertexShaderChanged; + uint m_nNumPSConstants; + uint m_nNumVSConstants; + uint m_nNumSamplersChanged; + uint m_nNumSamplerStatesChanged; + }; + + BatchState_t m_batch_state; + + uint m_nTotalFrames; + + uint m_nTotalDraws; + uint m_nTotalPrims; + uint m_nTotalD3DCalls; + double m_flTotalD3DTime; + + uint m_nOverallDraws; + uint m_nOverallPrims; + uint m_nOverallD3DCalls; + double m_flOverallD3DTime; +#endif +}; + +class CDirect3D9Hook : public CDx9HookBase, public IDirect3D9 +{ +public: + /*** IUnknown methods ***/ + IMPL_IUNKOWN(); + + // IDirect3D9 methods + STDMETHOD(RegisterSoftwareDevice)(THIS_ void* pInitializeFunction) + { XXX; return _DOCALL(RegisterSoftwareDevice, pInitializeFunction); } + STDMETHOD_(UINT, GetAdapterCount)(THIS) + { XXX; return _DOCALL0(GetAdapterCount); } + STDMETHOD(GetAdapterIdentifier)(THIS_ UINT Adapter,DWORD Flags,D3DADAPTER_IDENTIFIER9* pIdentifier) + { XXX; return _DOCALL(GetAdapterIdentifier, Adapter, Flags, pIdentifier);} + STDMETHOD_(UINT, GetAdapterModeCount)(THIS_ UINT Adapter,D3DFORMAT Format) + { XXX; return _DOCALL(GetAdapterModeCount, Adapter, Format);} + STDMETHOD(EnumAdapterModes)(THIS_ UINT Adapter,D3DFORMAT Format,UINT Mode,D3DDISPLAYMODE* pMode) + { XXX; return _DOCALL(EnumAdapterModes, Adapter, Format, Mode, pMode); } + STDMETHOD(GetAdapterDisplayMode)(THIS_ UINT Adapter,D3DDISPLAYMODE* pMode) + { XXX; return _DOCALL(GetAdapterDisplayMode, Adapter, pMode); } + STDMETHOD(CheckDeviceType)(THIS_ UINT iAdapter,D3DDEVTYPE DevType,D3DFORMAT DisplayFormat,D3DFORMAT BackBufferFormat,BOOL bWindowed) + { XXX; return _DOCALL(CheckDeviceType, iAdapter, DevType, DisplayFormat, BackBufferFormat, bWindowed); } + STDMETHOD(CheckDeviceFormat)(THIS_ UINT Adapter,D3DDEVTYPE DeviceType,D3DFORMAT AdapterFormat,DWORD Usage,D3DRESOURCETYPE RType,D3DFORMAT CheckFormat) + { XXX; return _DOCALL(CheckDeviceFormat, Adapter, DeviceType, AdapterFormat, Usage, RType, CheckFormat); } + STDMETHOD(CheckDeviceMultiSampleType)(THIS_ UINT Adapter,D3DDEVTYPE DeviceType,D3DFORMAT SurfaceFormat,BOOL Windowed,D3DMULTISAMPLE_TYPE MultiSampleType,DWORD* pQualityLevels) + { XXX; return _DOCALL(CheckDeviceMultiSampleType, Adapter, DeviceType, SurfaceFormat, Windowed, MultiSampleType, pQualityLevels); } + STDMETHOD(CheckDepthStencilMatch)(THIS_ UINT Adapter,D3DDEVTYPE DeviceType,D3DFORMAT AdapterFormat,D3DFORMAT RenderTargetFormat,D3DFORMAT DepthStencilFormat) + { XXX; return _DOCALL(CheckDepthStencilMatch, Adapter, DeviceType, AdapterFormat, RenderTargetFormat, DepthStencilFormat); } + STDMETHOD(CheckDeviceFormatConversion)(THIS_ UINT Adapter,D3DDEVTYPE DeviceType,D3DFORMAT SourceFormat,D3DFORMAT TargetFormat) + { XXX; return _DOCALL(CheckDeviceFormatConversion, Adapter, DeviceType, SourceFormat, TargetFormat); } + STDMETHOD(GetDeviceCaps)(THIS_ UINT Adapter,D3DDEVTYPE DeviceType,D3DCAPS9* pCaps) + { XXX; return _DOCALL(GetDeviceCaps, Adapter, DeviceType, pCaps); } + STDMETHOD_(HMONITOR, GetAdapterMonitor)(THIS_ UINT Adapter) + { XXX; return _DOCALL(GetAdapterMonitor, Adapter); } + STDMETHOD(CreateDevice)(THIS_ UINT Adapter,D3DDEVTYPE DeviceType,HWND hFocusWindow,DWORD BehaviorFlags,D3DPRESENT_PARAMETERS* pPresentationParameters,IDirect3DDevice9** ppReturnedDeviceInterface) + { + XXX; + HRESULT hr = _DOCALL(CreateDevice, Adapter, DeviceType, hFocusWindow, BehaviorFlags, pPresentationParameters, ppReturnedDeviceInterface); + + if( SUCCEEDED( hr ) && ppReturnedDeviceInterface && *ppReturnedDeviceInterface ) + { + CDirect3DDevice9Hook *pDevice = new CDirect3DDevice9Hook; + if(!pDevice) + { + ( *ppReturnedDeviceInterface )->Release(); + hr = E_OUTOFMEMORY; + return NULL; + } + pDevice->m_Data.pDevice = pDevice; + pDevice->m_Data.pHWObj = *ppReturnedDeviceInterface; + *ppReturnedDeviceInterface = pDevice; + } + return hr; + } +}; + +inline IDirect3D9 *Direct3DCreate9Hook( UINT SDKVersion ) +{ + HRESULT hr = S_OK; + IDirect3D9 *pD3D = Direct3DCreate9( D3D_SDK_VERSION ); + AllocOverride( &hr, NULL, &pD3D ); + return pD3D; +} + +#endif // _DX9HOOK_H_ diff --git a/materialsystem/shaderapidx9/dynamicib.h b/materialsystem/shaderapidx9/dynamicib.h new file mode 100644 index 0000000..304c7ef --- /dev/null +++ b/materialsystem/shaderapidx9/dynamicib.h @@ -0,0 +1,1056 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//===========================================================================// + +#ifndef DYNAMICIB_H +#define DYNAMICIB_H + +#ifdef _WIN32 +#pragma once +#endif + +#include "locald3dtypes.h" +#include "recording.h" +#include "shaderapidx8_global.h" +#include "shaderapidx8.h" +#include "shaderapi/ishaderutil.h" +#include "materialsystem/ivballoctracker.h" +#include "tier1/memstack.h" +#include "gpubufferallocator.h" + +///////////////////////////// +// D. Sim Dietrich Jr. +// sim.dietrich@nvidia.com +///////////////////////////// + +#ifdef _WIN32 +#pragma warning (disable:4189) +#endif + +#include "locald3dtypes.h" +#include "tier1/strtools.h" +#include "tier1/utlqueue.h" +#include "tier0/memdbgon.h" + +// Helper function to unbind an index buffer +void Unbind( IDirect3DIndexBuffer9 *pIndexBuffer ); + +#define X360_INDEX_BUFFER_SIZE_MULTIPLIER 4.0 //minimum of 1, only affects dynamic buffers +//#define X360_BLOCK_ON_IB_FLUSH //uncomment to block until all data is consumed when a flush is requested. Otherwise we only block when absolutely necessary + +#define SPEW_INDEX_BUFFER_STALLS //uncomment to allow buffer stall spewing. + +class CIndexBuffer +{ +public: + CIndexBuffer( IDirect3DDevice9 *pD3D, int count, bool bSoftwareVertexProcessing, bool dynamic = false ); + +#ifdef _X360 + CIndexBuffer(); + void Init( IDirect3DDevice9 *pD3D, uint16 *pIndexMemory, int count ); +#endif + + int AddRef() { return ++m_nReferenceCount; } + int Release() + { + int retVal = --m_nReferenceCount; + if ( retVal == 0 ) + delete this; + return retVal; + } + + LPDIRECT3DINDEXBUFFER GetInterface() const + { + // If this buffer still exists, then Late Creation didn't happen. Best case: we'll render the wrong image. Worst case: Crash. + Assert( !m_pSysmemBuffer ); + return m_pIB; + } + + // Use at beginning of frame to force a flush of VB contents on first draw + void FlushAtFrameStart() { m_bFlush = true; } + + // lock, unlock + unsigned short *Lock( bool bReadOnly, int numIndices, int &startIndex, int startPosition = -1 ); + void Unlock( int numIndices ); + void HandleLateCreation( ); + + // Index position + int IndexPosition() const { return m_Position; } + + // Index size + int IndexSize() const { return sizeof(unsigned short); } + + // Index count + int IndexCount() const { return m_IndexCount; } + +#if _X360 + // For some IBs, memory allocation is managed by CGPUBufferAllocator, via ShaderAPI + const GPUBufferHandle_t *GetBufferAllocationHandle( void ); + void SetBufferAllocationHandle( const GPUBufferHandle_t &bufferAllocationHandle ); + bool IsPooled( void ) { return m_GPUBufferHandle.IsValid(); } + // Expose the data pointer for read-only CPU access to the data + // (double-indirection supports relocation of the data by CGPUBufferAllocator) + const byte **GetBufferDataPointerAddress( void ); +#endif // _X360 + // Do we have enough room without discarding? + bool HasEnoughRoom( int numIndices ) const; + + bool IsDynamic() const { return m_bDynamic; } + bool IsExternal() const { return m_bExternalMemory; } + + // Block until there's a free portion of the buffer of this size, m_Position will be updated to point at where this section starts + void BlockUntilUnused( int nAllocationSize ); + +#ifdef CHECK_INDICES + void UpdateShadowIndices( unsigned short *pData ) + { + Assert( m_LockedStartIndex + m_LockedNumIndices <= m_NumIndices ); + memcpy( m_pShadowIndices + m_LockedStartIndex, pData, m_LockedNumIndices * IndexSize() ); + } + + unsigned short GetShadowIndex( int i ) + { + Assert( i >= 0 && i < (int)m_NumIndices ); + return m_pShadowIndices[i]; + } +#endif + + // UID + unsigned int UID() const + { +#ifdef RECORDING + return m_UID; +#else + return 0; +#endif + } + + void HandlePerFrameTextureStats( int frame ) + { +#ifdef VPROF_ENABLED + if ( m_Frame != frame && !m_bDynamic ) + { + m_Frame = frame; + VPROF_INCREMENT_GROUP_COUNTER( "TexGroup_frame_" TEXTURE_GROUP_STATIC_INDEX_BUFFER, + COUNTER_GROUP_TEXTURE_PER_FRAME, IndexCount() * IndexSize() ); + } +#endif + } + + static int BufferCount() + { +#ifdef _DEBUG + return s_BufferCount; +#else + return 0; +#endif + } + + inline int AllocationSize() const; + + inline int AllocationCount() const; + + // Marks a fence indicating when this buffer was used + void MarkUsedInRendering() + { +#ifdef _X360 + if ( m_bDynamic && m_pIB ) + { + Assert( m_AllocationRing.Count() > 0 ); + m_AllocationRing[m_AllocationRing.Tail()].m_Fence = Dx9Device()->GetCurrentFence(); + } +#endif + } + +private : + void Create( IDirect3DDevice9 *pD3D ); + inline void ReallyUnlock( int unlockBytes ) + { + #if DX_TO_GL_ABSTRACTION + // Knowing how much data was actually written is critical for performance under OpenGL. + m_pIB->UnlockActualSize( unlockBytes ); + #else + unlockBytes; // Unused here + m_pIB->Unlock(); + #endif + } + + enum LOCK_FLAGS + { + LOCKFLAGS_FLUSH = D3DLOCK_NOSYSLOCK | D3DLOCK_DISCARD, +#if !defined( _X360 ) + LOCKFLAGS_APPEND = D3DLOCK_NOSYSLOCK | D3DLOCK_NOOVERWRITE +#else + // X360BUG: forcing all locks to gpu flush, otherwise bizarre mesh corruption on decals + // Currently iterating with microsoft 360 support to track source of gpu corruption + LOCKFLAGS_APPEND = D3DLOCK_NOSYSLOCK +#endif + }; + + LPDIRECT3DINDEXBUFFER m_pIB; +#ifdef _X360 + + struct DynamicBufferAllocation_t + { + DWORD m_Fence; //track whether this memory is safe to use again. + int m_iStartOffset; + int m_iEndOffset; + unsigned int m_iZPassIdx; // The zpass during which this allocation was made + }; + + int m_iNextBlockingPosition; // m_iNextBlockingPosition >= m_Position where another allocation is still in use. + unsigned char *m_pAllocatedMemory; + int m_iAllocationCount; //The total number of indices the buffer we allocated can hold. Usually greater than the number of indices asked for + IDirect3DIndexBuffer9 m_D3DIndexBuffer; //Only need one shared D3D header for our usage patterns. + CUtlLinkedList m_AllocationRing; //tracks what chunks of our memory are potentially still in use by D3D + + GPUBufferHandle_t m_GPUBufferHandle; // Handle to a memory allocation within a shared physical memory pool (see CGPUBufferAllocator) +#endif + + int m_IndexCount; + int m_Position; + byte *m_pSysmemBuffer; + int m_nSysmemBufferStartBytes; + unsigned char m_bLocked : 1; + unsigned char m_bFlush : 1; + unsigned char m_bDynamic : 1; + unsigned char m_bExternalMemory : 1; + unsigned char m_bSoftwareVertexProcessing : 1; + unsigned char m_bLateCreateShouldDiscard : 1; + +#ifdef VPROF_ENABLED + int m_Frame; +#endif + + CInterlockedInt m_nReferenceCount; + +#ifdef _DEBUG + static int s_BufferCount; +#endif + +#ifdef RECORDING + unsigned int m_UID; +#endif + +#if !defined( _X360 ) + //LockedBufferContext m_LockData; +#endif + +protected: +#ifdef CHECK_INDICES + unsigned short *m_pShadowIndices; + unsigned int m_NumIndices; +#endif + + unsigned int m_LockedStartIndex; + unsigned int m_LockedNumIndices; + +private: + // Must use reference counting functions above + ~CIndexBuffer(); +}; + +#if defined( _X360 ) +#include "utlmap.h" +MEMALLOC_DECLARE_EXTERNAL_TRACKING( XMem_CIndexBuffer ); +#endif + + +//----------------------------------------------------------------------------- +// constructor, destructor +//----------------------------------------------------------------------------- + +inline CIndexBuffer::CIndexBuffer( IDirect3DDevice9 *pD3D, int count, + bool bSoftwareVertexProcessing, bool dynamic ) : + m_pIB(0), + m_Position(0), + m_bFlush(true), + m_bLocked(false), + m_bExternalMemory(false), + m_bDynamic(dynamic), + m_bSoftwareVertexProcessing( bSoftwareVertexProcessing ), + m_bLateCreateShouldDiscard( false ) +#ifdef _X360 + ,m_pAllocatedMemory(NULL) + ,m_iNextBlockingPosition(0) + ,m_iAllocationCount(0) +#endif +#ifdef VPROF_ENABLED + ,m_Frame( -1 ) +#endif + , m_nReferenceCount( 0 ) +{ + // For write-combining, ensure we always have locked memory aligned to 4-byte boundaries + count = ALIGN_VALUE( count, 2 ); + m_IndexCount = count; + + MEM_ALLOC_CREDIT_( m_bDynamic ? ( "D3D: " TEXTURE_GROUP_DYNAMIC_INDEX_BUFFER ) : ( "D3D: " TEXTURE_GROUP_STATIC_INDEX_BUFFER ) ); + +#ifdef CHECK_INDICES + m_pShadowIndices = NULL; +#endif + +#ifdef RECORDING + // assign a UID + static unsigned int uid = 0; + m_UID = uid++; +#endif + +#ifdef _DEBUG + ++s_BufferCount; +#endif + +#ifdef CHECK_INDICES + m_pShadowIndices = new unsigned short[ m_IndexCount ]; + m_NumIndices = m_IndexCount; +#endif + + + if ( g_pShaderUtil->GetThreadMode() != MATERIAL_SINGLE_THREADED || !ThreadInMainThread() ) + { + m_pSysmemBuffer = ( byte * )malloc( count * IndexSize() ); + m_nSysmemBufferStartBytes = 0; + } + else + { + m_pSysmemBuffer = NULL; + Create( pD3D ); + } + +#else // _X360 + int nBufferSize = (count * IndexSize()); + if ( m_bDynamic ) + { + m_iAllocationCount = count * X360_INDEX_BUFFER_SIZE_MULTIPLIER; + Assert( m_iAllocationCount >= count ); + m_iAllocationCount = ALIGN_VALUE( m_iAllocationCount, 2 ); + m_pAllocatedMemory = (unsigned char*)XPhysicalAlloc( m_iAllocationCount * IndexSize(), MAXULONG_PTR, 0, PAGE_READWRITE | MEM_LARGE_PAGES | PAGE_WRITECOMBINE ); + } + else if ( MeshMgr()->AllocatePooledIB( this, nBufferSize, TEXTURE_GROUP_STATIC_INDEX_BUFFER ) ) + { + // Successfully allocated in a shared ShaderAPI memory pool (SetBufferAllocationHandle will have been called to set the pointer and stream offset) + m_iAllocationCount = count; + Assert( m_pAllocatedMemory ); + } + else + { + // Fall back to allocating a standalone IB + // NOTE: write-combining (PAGE_WRITECOMBINE) is deliberately not used, since it slows down CPU access to the data (decals+defragmentation) + m_iAllocationCount = count; + m_pAllocatedMemory = (unsigned char*)XPhysicalAlloc( nBufferSize, MAXULONG_PTR, 0, PAGE_READWRITE ); + } + + if ( m_pAllocatedMemory && !IsPooled() ) + { + MemAlloc_RegisterExternalAllocation( XMem_CIndexBuffer, m_pAllocatedMemory, XPhysicalSize( m_pAllocatedMemory ) ); + if ( !m_bDynamic ) + { + // Track non-pooled physallocs, to help tune CGPUBufferAllocator usage + g_SizeIndividualIBPhysAllocs += XPhysicalSize( m_pAllocatedMemory ); + g_NumIndividualIBPhysAllocs++; + } + } + + m_iNextBlockingPosition = m_iAllocationCount; +#endif // _X360 + + +#ifdef VPROF_ENABLED + if ( !m_bDynamic ) + { + VPROF_INCREMENT_GROUP_COUNTER( "TexGroup_global_" TEXTURE_GROUP_STATIC_INDEX_BUFFER, + COUNTER_GROUP_TEXTURE_GLOBAL, IndexCount() * IndexSize() ); + } + else if ( IsX360() ) + { + VPROF_INCREMENT_GROUP_COUNTER( "TexGroup_global_" TEXTURE_GROUP_DYNAMIC_INDEX_BUFFER, + COUNTER_GROUP_TEXTURE_GLOBAL, IndexCount() * IndexSize() ); + } +#endif +} + + +void CIndexBuffer::Create( IDirect3DDevice9 *pD3D ) +{ + D3DINDEXBUFFER_DESC desc; + memset( &desc, 0x00, sizeof( desc ) ); + desc.Format = D3DFMT_INDEX16; + desc.Size = sizeof(unsigned short) * m_IndexCount; + desc.Type = D3DRTYPE_INDEXBUFFER; + desc.Pool = D3DPOOL_DEFAULT; + desc.Usage = D3DUSAGE_WRITEONLY; + if ( m_bDynamic ) + { + desc.Usage |= D3DUSAGE_DYNAMIC; + } + if ( m_bSoftwareVertexProcessing ) + { + desc.Usage |= D3DUSAGE_SOFTWAREPROCESSING; + } + + RECORD_COMMAND( DX8_CREATE_INDEX_BUFFER, 6 ); + RECORD_INT( m_UID ); + RECORD_INT( m_IndexCount * IndexSize() ); + RECORD_INT( desc.Usage ); + RECORD_INT( desc.Format ); + RECORD_INT( desc.Pool ); + RECORD_INT( m_bDynamic ); + +#if !defined( _X360 ) + HRESULT hr = pD3D->CreateIndexBuffer( + m_IndexCount * IndexSize(), + desc.Usage, + desc.Format, + desc.Pool, + &m_pIB, + NULL ); + if ( hr != D3D_OK ) + { + Warning( "CreateIndexBuffer failed!\n" ); + } + + if ( ( hr == D3DERR_OUTOFVIDEOMEMORY ) || ( hr == E_OUTOFMEMORY ) ) + { + // Don't have the memory for this. Try flushing all managed resources + // out of vid mem and try again. + // FIXME: need to record this + pD3D->EvictManagedResources(); + hr = pD3D->CreateIndexBuffer( m_IndexCount * IndexSize(), + desc.Usage, desc.Format, desc.Pool, &m_pIB, NULL ); + } + + Assert( m_pIB ); + Assert( hr == D3D_OK ); + +#ifdef MEASURE_DRIVER_ALLOCATIONS + int nMemUsed = 1024; + VPROF_INCREMENT_GROUP_COUNTER( "ib count", COUNTER_GROUP_NO_RESET, 1 ); + VPROF_INCREMENT_GROUP_COUNTER( "ib driver mem", COUNTER_GROUP_NO_RESET, nMemUsed ); + VPROF_INCREMENT_GROUP_COUNTER( "total driver mem", COUNTER_GROUP_NO_RESET, nMemUsed ); +#endif + +#if defined( _DEBUG ) + if ( IsPC() && m_pIB && !m_pSysmemBuffer ) + { + D3DINDEXBUFFER_DESC aDesc; + m_pIB->GetDesc( &aDesc ); + Assert( memcmp( &aDesc, &desc, sizeof( desc ) ) == 0 ); + } +#endif +} + + +#ifdef _X360 +void *AllocateTempBuffer( size_t nSizeInBytes ); + +inline CIndexBuffer::CIndexBuffer() : + m_pIB(0), + m_Position(0), + m_bFlush(false), + m_bLocked(false), + m_bExternalMemory( true ), + m_bDynamic( false ) +#ifdef VPROF_ENABLED + ,m_Frame( -1 ) +#endif +{ + m_IndexCount = 0; + +#ifdef CHECK_INDICES + m_pShadowIndices = NULL; +#endif + + m_iAllocationCount = 0; + m_pAllocatedMemory = NULL; + m_iNextBlockingPosition = 0; +} + +#include "tier0/memdbgoff.h" + +inline void CIndexBuffer::Init( IDirect3DDevice9 *pD3D, uint16 *pIndexMemory, int count ) +{ + m_IndexCount = count; + m_Position = count; + + m_iAllocationCount = count; + m_pAllocatedMemory = (uint8*)pIndexMemory; + m_iNextBlockingPosition = m_iAllocationCount; + + int nBufferSize = count * sizeof(uint16); + m_pIB = new( AllocateTempBuffer( sizeof( IDirect3DIndexBuffer9 ) ) ) IDirect3DIndexBuffer9; + XGSetIndexBufferHeader( nBufferSize, 0, D3DFMT_INDEX16, 0, 0, m_pIB ); + XGOffsetResourceAddress( m_pIB, pIndexMemory ); +} + +#include "tier0/memdbgon.h" + +#endif // _X360 + +inline CIndexBuffer::~CIndexBuffer() +{ +#ifdef _DEBUG + if ( !m_bExternalMemory ) + { + --s_BufferCount; + } +#endif + + Unlock(0); + +#ifdef CHECK_INDICES + if ( m_pShadowIndices ) + { + delete [] m_pShadowIndices; + m_pShadowIndices = NULL; + } +#endif + + if ( m_pSysmemBuffer ) + { + free( m_pSysmemBuffer ); + m_pSysmemBuffer = NULL; + } + +#ifdef MEASURE_DRIVER_ALLOCATIONS + if ( !m_bExternalMemory ) + { + int nMemUsed = 1024; + VPROF_INCREMENT_GROUP_COUNTER( "ib count", COUNTER_GROUP_NO_RESET, -1 ); + VPROF_INCREMENT_GROUP_COUNTER( "ib driver mem", COUNTER_GROUP_NO_RESET, -nMemUsed ); + VPROF_INCREMENT_GROUP_COUNTER( "total driver mem", COUNTER_GROUP_NO_RESET, -nMemUsed ); + } +#endif + +#if !defined( _X360 ) + if ( m_pIB ) + { + RECORD_COMMAND( DX8_DESTROY_INDEX_BUFFER, 1 ); + RECORD_INT( m_UID ); + + m_pIB->Release(); + } +#else + if ( m_pIB && m_pIB->IsSet( Dx9Device() ) ) + { + Unbind( m_pIB ); + } + + if ( m_pAllocatedMemory && !m_bExternalMemory ) + { + if ( IsPooled() ) + { + MeshMgr()->DeallocatePooledIB( this ); + } + else + { + MemAlloc_RegisterExternalDeallocation( XMem_CIndexBuffer, m_pAllocatedMemory, XPhysicalSize( m_pAllocatedMemory ) ); + if ( !m_bDynamic ) + { + // Track non-pooled physallocs, to help tune CGPUBufferAllocator usage + g_SizeIndividualIBPhysAllocs -= XPhysicalSize( m_pAllocatedMemory ); + g_NumIndividualIBPhysAllocs--; + } + XPhysicalFree( m_pAllocatedMemory ); + } + } + + m_pAllocatedMemory = NULL; + m_pIB = NULL; +#endif + +#ifdef VPROF_ENABLED + if ( !m_bExternalMemory ) + { + if ( !m_bDynamic ) + { + VPROF_INCREMENT_GROUP_COUNTER( "TexGroup_global_" TEXTURE_GROUP_STATIC_INDEX_BUFFER, + COUNTER_GROUP_TEXTURE_GLOBAL, - IndexCount() * IndexSize() ); + } + else if ( IsX360() ) + { + VPROF_INCREMENT_GROUP_COUNTER( "TexGroup_global_" TEXTURE_GROUP_DYNAMIC_INDEX_BUFFER, + COUNTER_GROUP_TEXTURE_GLOBAL, - IndexCount() * IndexSize() ); + } + } +#endif +} + +#ifdef _X360 +//----------------------------------------------------------------------------- +// Get memory allocation data +//----------------------------------------------------------------------------- +inline const GPUBufferHandle_t *CIndexBuffer::GetBufferAllocationHandle( void ) +{ + Assert( IsPooled() ); + return ( IsPooled() ? &m_GPUBufferHandle : NULL ); +} + +//----------------------------------------------------------------------------- +// Update memory allocation data +//----------------------------------------------------------------------------- +inline void CIndexBuffer::SetBufferAllocationHandle( const GPUBufferHandle_t &bufferAllocationHandle ) +{ + // This IB's memory has been reallocated or freed, update our cached pointer and the D3D header + // NOTE: this should never be called while any rendering is in flight! + Assert( ( m_pAllocatedMemory == NULL ) || IsPooled() ); + if ( ( m_pAllocatedMemory == NULL ) || IsPooled() ) + { + m_GPUBufferHandle = bufferAllocationHandle; + m_pAllocatedMemory = m_GPUBufferHandle.pMemory; + if ( m_pIB ) + { + int nBufferSize = m_IndexCount * IndexSize(); + XGSetIndexBufferHeader( nBufferSize, 0, D3DFMT_INDEX16, 0, 0, m_pIB ); + XGOffsetResourceAddress( m_pIB, m_pAllocatedMemory ); + } + } +} + +//----------------------------------------------------------------------------- +// Expose the data pointer for read-only CPU access to the data +//----------------------------------------------------------------------------- +inline const byte **CIndexBuffer::GetBufferDataPointerAddress( void ) +{ + if ( m_bDynamic /* FIXME: || m_bExternalMemory */ ) + return NULL; + return (const byte **)&m_pAllocatedMemory; +} +#endif // _X360 + +//----------------------------------------------------------------------------- +// Do we have enough room without discarding? +//----------------------------------------------------------------------------- +inline bool CIndexBuffer::HasEnoughRoom( int numIndices ) const +{ +#if !defined( _X360 ) + return ( numIndices + m_Position ) <= m_IndexCount; +#else + return numIndices <= m_IndexCount; //the ring buffer will free room as needed +#endif +} + +//----------------------------------------------------------------------------- +// Block until this part of the index buffer is free +//----------------------------------------------------------------------------- +inline void CIndexBuffer::BlockUntilUnused( int nAllocationSize ) +{ + Assert( nAllocationSize <= m_IndexCount ); + +#ifdef _X360 + Assert( (m_AllocationRing.Count() != 0) || ((m_Position == 0) && (m_iNextBlockingPosition == m_iAllocationCount)) ); + + if ( (m_iNextBlockingPosition - m_Position) >= nAllocationSize ) + return; + + Assert( (m_AllocationRing[m_AllocationRing.Head()].m_iStartOffset == 0) || ((m_iNextBlockingPosition == m_AllocationRing[m_AllocationRing.Head()].m_iStartOffset) && (m_Position <= m_iNextBlockingPosition)) ); + + int iMinBlockPosition = m_Position + nAllocationSize; + if( iMinBlockPosition > m_iAllocationCount ) + { + //Allocation requires us to wrap + iMinBlockPosition = nAllocationSize; + m_Position = 0; + + //modify the last allocation so that it uses up the whole tail end of the buffer. Makes other code simpler + Assert( m_AllocationRing.Count() != 0 ); + m_AllocationRing[m_AllocationRing.Tail()].m_iEndOffset = m_iAllocationCount; + + //treat all allocations between the current position and the tail end of the ring as freed since they will be before we unblock + while( m_AllocationRing.Count() ) + { + unsigned int head = m_AllocationRing.Head(); + if( m_AllocationRing[head].m_iStartOffset == 0 ) + break; + + m_AllocationRing.Remove( head ); + } + } + + //now we go through the allocations until we find the last fence we care about. Treat everything up until that fence as freed. + DWORD FinalFence = 0; + unsigned int iFinalAllocationZPassIdx = 0; + while( m_AllocationRing.Count() ) + { + unsigned int head = m_AllocationRing.Head(); + + if( m_AllocationRing[head].m_iEndOffset >= iMinBlockPosition ) + { + //When this frees, we'll finally have enough space for the allocation + FinalFence = m_AllocationRing[head].m_Fence; + iFinalAllocationZPassIdx = m_AllocationRing[head].m_iZPassIdx; + m_iNextBlockingPosition = m_AllocationRing[head].m_iEndOffset; + m_AllocationRing.Remove( head ); + break; + } + m_AllocationRing.Remove( head ); + } + Assert( FinalFence != 0 ); + + if( Dx9Device()->IsFencePending( FinalFence ) ) + { +#ifdef SPEW_INDEX_BUFFER_STALLS + float st = Plat_FloatTime(); +#endif + + if ( ( Dx9Device()->GetDeviceState() & D3DDEVICESTATE_ZPASS_BRACKET ) && + ( iFinalAllocationZPassIdx == ShaderAPI()->Get360ZPassCounter() ) ) + { + // We're about to overrun our IB ringbuffer in a single Z prepass. To avoid rendering corruption, close out the + // Z prepass and continue. This will reduce early-Z rejection efficiency and could cause a momentary framerate drop, + // but it's better than rendering corruption. + Warning( "Dynamic IB ring buffer overrun in Z Prepass. Tell Thorsten.\n" ); + + ShaderAPI()->End360ZPass(); + } + + Dx9Device()->BlockOnFence( FinalFence ); + +#ifdef SPEW_INDEX_BUFFER_STALLS + float dt = Plat_FloatTime() - st; + Warning( "Blocked locking dynamic index buffer for %f ms!\n", 1000.0 * dt ); +#endif + } + +#endif +} + + +//----------------------------------------------------------------------------- +// lock, unlock +//----------------------------------------------------------------------------- +inline unsigned short* CIndexBuffer::Lock( bool bReadOnly, int numIndices, int& startIndex, int startPosition ) +{ + Assert( !m_bLocked ); + +#if defined( _X360 ) + if ( m_pIB && m_pIB->IsSet( Dx9Device() ) ) + { + Unbind( m_pIB ); + } +#endif + + unsigned short* pLockedData = NULL; + + // For write-combining, ensure we always have locked memory aligned to 4-byte boundaries + if( m_bDynamic ) + numIndices = ALIGN_VALUE( numIndices, 2 ); + + // Ensure there is enough space in the IB for this data + if ( numIndices > m_IndexCount ) + { + Error( "too many indices for index buffer. . tell a programmer (%d>%d)\n", ( int )numIndices, ( int )m_IndexCount ); + Assert( false ); + return 0; + } + + if ( !IsX360() && !m_pIB && !m_pSysmemBuffer ) + return 0; + + DWORD dwFlags; + + if ( m_bDynamic ) + { + // startPosition now can be != -1, when calling in here with a static (staging) buffer. +#if !defined( _X360 ) + dwFlags = LOCKFLAGS_APPEND; + + // If either user forced us to flush, + // or there is not enough space for the vertex data, + // then flush the buffer contents + // xbox must not append at position 0 because nooverwrite cannot be guaranteed + + if ( !m_Position || m_bFlush || !HasEnoughRoom(numIndices) ) + { + if ( m_pSysmemBuffer || !g_pShaderUtil->IsRenderThreadSafe() ) + m_bLateCreateShouldDiscard = true; + + m_bFlush = false; + m_Position = 0; + + dwFlags = LOCKFLAGS_FLUSH; + } +#else + if ( m_bFlush ) + { +# if ( defined( X360_BLOCK_ON_IB_FLUSH ) ) + { + if( m_AllocationRing.Count() ) + { + DWORD FinalFence = m_AllocationRing[m_AllocationRing.Tail()].m_Fence; + + m_AllocationRing.RemoveAll(); + m_Position = 0; + m_iNextBlockingPosition = m_iAllocationCount; + +# if ( defined( SPEW_VERTEX_BUFFER_STALLS ) ) + if( Dx9Device()->IsFencePending( FinalFence ) ) + { + float st = Plat_FloatTime(); +# endif + Dx9Device()->BlockOnFence( FinalFence ); +# if ( defined ( SPEW_VERTEX_BUFFER_STALLS ) ) + float dt = Plat_FloatTime() - st; + Warning( "Blocked FLUSHING dynamic index buffer for %f ms!\n", 1000.0 * dt ); + } +# endif + } + } +# endif + m_bFlush = false; + } +#endif + } + else + { + dwFlags = D3DLOCK_NOSYSLOCK; + } + + if ( bReadOnly ) + { + dwFlags |= D3DLOCK_READONLY; + } + + int position = m_Position; + if( startPosition >= 0 ) + { + position = startPosition; + } + + RECORD_COMMAND( DX8_LOCK_INDEX_BUFFER, 4 ); + RECORD_INT( m_UID ); + RECORD_INT( position * IndexSize() ); + RECORD_INT( numIndices * IndexSize() ); + RECORD_INT( dwFlags ); + + m_LockedStartIndex = position; + m_LockedNumIndices = numIndices; + + HRESULT hr = D3D_OK; + +#if !defined( _X360 ) + // If the caller isn't in the thread that owns the render lock, need to return a system memory pointer--cannot talk to GL from + // the non-current thread. + if ( !m_pSysmemBuffer && !g_pShaderUtil->IsRenderThreadSafe() ) + { + m_pSysmemBuffer = ( byte * )malloc( m_IndexCount * IndexSize() ); + m_nSysmemBufferStartBytes = position * IndexSize(); + } + + if ( m_pSysmemBuffer != NULL ) + { + // Ensure that we're never moving backwards in a buffer--this code would need to be rewritten if so. + // We theorize this can happen if you hit the end of a buffer and then wrap before drawing--but + // this would probably break in other places as well. + Assert( position * IndexSize() >= m_nSysmemBufferStartBytes ); + pLockedData = ( unsigned short * )( m_pSysmemBuffer + ( position * IndexSize() ) ); + } + else + { + hr = m_pIB->Lock( position * IndexSize(), numIndices * IndexSize(), + reinterpret_cast< void** >( &pLockedData ), dwFlags ); + } +#else + if ( m_bDynamic ) + { + // Block until earlier parts of the buffer are free + BlockUntilUnused( numIndices ); + position = m_Position; + m_pIB = NULL; + Assert( (m_Position + numIndices) <= m_iAllocationCount ); + } + else + { + //static, block until last lock finished? + m_Position = position; + } + pLockedData = (unsigned short *)(m_pAllocatedMemory + (position * IndexSize())); + +#endif + + switch ( hr ) + { + case D3DERR_INVALIDCALL: + Msg( "D3DERR_INVALIDCALL - Index Buffer Lock Failed in %s on line %d(offset %d, size %d, flags 0x%x)\n", V_UnqualifiedFileName(__FILE__), __LINE__, position * IndexSize(), numIndices * IndexSize(), dwFlags ); + break; + case D3DERR_DRIVERINTERNALERROR: + Msg( "D3DERR_DRIVERINTERNALERROR - Index Buffer Lock Failed in %s on line %d (offset %d, size %d, flags 0x%x)\n", V_UnqualifiedFileName(__FILE__), __LINE__, position * IndexSize(), numIndices * IndexSize(), dwFlags ); + break; + case D3DERR_OUTOFVIDEOMEMORY: + Msg( "D3DERR_OUTOFVIDEOMEMORY - Index Buffer Lock Failed in %s on line %d (offset %d, size %d, flags 0x%x)\n", V_UnqualifiedFileName(__FILE__), __LINE__, position * IndexSize(), numIndices * IndexSize(), dwFlags ); + break; + } + + Assert( pLockedData != NULL ); + + if ( !IsX360() ) + { + startIndex = position; + } + else + { + startIndex = 0; + } + + Assert( m_bLocked == false ); + m_bLocked = true; + return pLockedData; +} + +inline void CIndexBuffer::Unlock( int numIndices ) +{ +#if defined( _X360 ) + Assert( (m_Position + numIndices) <= m_iAllocationCount ); +#else + Assert( (m_Position + numIndices) <= m_IndexCount ); +#endif + + if ( !m_bLocked ) + return; + + // For write-combining, ensure we always have locked memory aligned to 4-byte boundaries +// if( m_bDynamic ) +// numIndices = ALIGN_VALUE( numIndices, 2 ); + + if ( !IsX360() && !m_pIB && !m_pSysmemBuffer ) + return; + + RECORD_COMMAND( DX8_UNLOCK_INDEX_BUFFER, 1 ); + RECORD_INT( m_UID ); + +#if !defined( _X360 ) + if ( m_pSysmemBuffer ) + { + } + else + { +#if DX_TO_GL_ABSTRACTION + // Knowing how much data was actually written is critical for performance under OpenGL. + // Important notes: numIndices indicates how much we could move the current position. For dynamic buffer, it should indicate the # of actually written indices, for static buffers it's typically 0. + // If it's a dynamic buffer (where we actually care about perf), assume the caller isn't lying about numIndices, otherwise just assume they wrote the entire thing. + // If you modify this code, be sure to test on both AMD and NVidia drivers! + Assert( numIndices <= (int)m_LockedNumIndices ); + int unlockBytes = ( m_bDynamic ? numIndices : m_LockedNumIndices ) * IndexSize(); +#else + int unlockBytes = 0; +#endif + ReallyUnlock( unlockBytes ); + } +#else + if ( m_bDynamic ) + { + Assert( (m_Position == 0) || (m_AllocationRing[m_AllocationRing.Tail()].m_iEndOffset == m_Position) ); + + DynamicBufferAllocation_t LockData; + LockData.m_Fence = Dx9Device()->GetCurrentFence(); //This isn't the correct fence, but it's all we have access to for now and it'll provide marginal safety if something goes really wrong. + LockData.m_iStartOffset = m_Position; + LockData.m_iEndOffset = LockData.m_iStartOffset + numIndices; + LockData.m_iZPassIdx = ( Dx9Device()->GetDeviceState() & D3DDEVICESTATE_ZPASS_BRACKET ) ? ShaderAPI()->Get360ZPassCounter() : 0; + Assert( (LockData.m_iStartOffset == 0) || (LockData.m_iStartOffset == m_AllocationRing[m_AllocationRing.Tail()].m_iEndOffset) ); + m_AllocationRing.AddToTail( LockData ); + + void* pLockedData = m_pAllocatedMemory + (LockData.m_iStartOffset * IndexSize()); + + //Always re-use the same index buffer header based on the assumption that D3D copies it off in the draw calls. + m_pIB = &m_D3DIndexBuffer; + XGSetIndexBufferHeader( numIndices * IndexSize(), 0, D3DFMT_INDEX16, 0, 0, m_pIB ); + XGOffsetResourceAddress( m_pIB, pLockedData ); + + // Invalidate the GPU caches for this memory. + // FIXME: Should dynamic allocations be 4k aligned? + Dx9Device()->InvalidateGpuCache( pLockedData, numIndices * IndexSize(), 0 ); + } + else + { + if ( !m_pIB ) + { + int nBufferSize = m_IndexCount * IndexSize(); + XGSetIndexBufferHeader( nBufferSize, 0, D3DFMT_INDEX16, 0, 0, &m_D3DIndexBuffer ); + XGOffsetResourceAddress( &m_D3DIndexBuffer, m_pAllocatedMemory ); + m_pIB = &m_D3DIndexBuffer; + } + + // Invalidate the GPU caches for this memory. + Dx9Device()->InvalidateGpuCache( m_pAllocatedMemory, m_IndexCount * IndexSize(), 0 ); + } +#endif + + m_Position += numIndices; + m_bLocked = false; + + m_LockedStartIndex = 0; + m_LockedNumIndices = 0; +} + + +inline void CIndexBuffer::HandleLateCreation( ) +{ + if ( !m_pSysmemBuffer ) + { + return; + } + + if( !m_pIB ) + { + bool bPrior = g_VBAllocTracker->TrackMeshAllocations( "HandleLateCreation" ); + Create( Dx9Device() ); + if ( !bPrior ) + { + g_VBAllocTracker->TrackMeshAllocations( NULL ); + } + } + + void* pWritePtr = NULL; + const int dataToWriteBytes = ( m_Position * IndexSize() ) - m_nSysmemBufferStartBytes; + DWORD dwFlags = D3DLOCK_NOSYSLOCK; + if ( m_bDynamic ) + dwFlags |= ( m_bLateCreateShouldDiscard ? D3DLOCK_DISCARD : D3DLOCK_NOOVERWRITE ); + + // Always clear this. + m_bLateCreateShouldDiscard = false; + + // Don't use the Lock function, it does a bunch of stuff we don't want. + HRESULT hr = m_pIB->Lock( m_nSysmemBufferStartBytes, + dataToWriteBytes, + &pWritePtr, + dwFlags); + + // If this fails we're about to crash. Consider skipping the update and leaving + // m_pSysmemBuffer around to try again later. (For example in case of device loss) + Assert( SUCCEEDED( hr ) ); hr; + memcpy( pWritePtr, m_pSysmemBuffer + m_nSysmemBufferStartBytes, dataToWriteBytes ); + ReallyUnlock( dataToWriteBytes ); + + free( m_pSysmemBuffer ); + m_pSysmemBuffer = NULL; +} + + +// Returns the allocated size +inline int CIndexBuffer::AllocationSize() const +{ +#ifdef _X360 + return m_iAllocationCount * IndexSize(); +#else + return m_IndexCount * IndexSize(); +#endif +} + +inline int CIndexBuffer::AllocationCount() const +{ +#ifdef _X360 + return m_iAllocationCount; +#else + return m_IndexCount; +#endif +} + +#ifdef _WIN32 +#pragma warning (default:4189) +#endif + +#include "tier0/memdbgoff.h" + +#endif // DYNAMICIB_H + diff --git a/materialsystem/shaderapidx9/dynamicvb.h b/materialsystem/shaderapidx9/dynamicvb.h new file mode 100644 index 0000000..5eeee8f --- /dev/null +++ b/materialsystem/shaderapidx9/dynamicvb.h @@ -0,0 +1,1098 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +// +//===========================================================================// + +#ifndef DYNAMICVB_H +#define DYNAMICVB_H + +#ifdef _WIN32 +#pragma once +#endif + +#include "locald3dtypes.h" +#include "recording.h" +#include "shaderapidx8_global.h" +#include "shaderapidx8.h" +#include "imeshdx8.h" +#include "materialsystem/ivballoctracker.h" +#include "gpubufferallocator.h" +#include "tier1/utllinkedlist.h" +#include "tier0/dbg.h" +#include "tier1/memstack.h" + +///////////////////////////// +// D. Sim Dietrich Jr. +// sim.dietrich@nvidia.com +////////////////////// + + +// Helper function to unbind an vertex buffer +void Unbind( IDirect3DVertexBuffer9 *pVertexBuffer ); + +#define X360_VERTEX_BUFFER_SIZE_MULTIPLIER 2.0 //minimum of 1, only affects dynamic buffers +//#define X360_BLOCK_ON_VB_FLUSH //uncomment to block until all data is consumed when a flush is requested. Otherwise we only block when absolutely necessary + +//#define SPEW_VERTEX_BUFFER_STALLS //uncomment to allow buffer stall spewing. + + +class CVertexBuffer +{ +public: + CVertexBuffer( IDirect3DDevice9 * pD3D, VertexFormat_t fmt, DWORD theFVF, int vertexSize, + int theVertexCount, const char *pTextureBudgetName, bool bSoftwareVertexProcessing, bool dynamic = false ); + +#ifdef _X360 + CVertexBuffer(); + void Init( IDirect3DDevice9 * pD3D, VertexFormat_t fmt, DWORD theFVF, uint8 *pVertexData, int vertexSize, int theVertexCount ); +#endif + + ~CVertexBuffer(); + + LPDIRECT3DVERTEXBUFFER GetInterface() const + { + // If this buffer still exists, then Late Creation didn't happen. Best case: we'll render the wrong image. Worst case: Crash. + Assert( !m_pSysmemBuffer ); + return m_pVB; + } + + // Use at beginning of frame to force a flush of VB contents on first draw + void FlushAtFrameStart() { m_bFlush = true; } + + // lock, unlock + unsigned char* Lock( int numVerts, int& baseVertexIndex ); + unsigned char* Modify( bool bReadOnly, int firstVertex, int numVerts ); + void Unlock( int numVerts ); + + void HandleLateCreation( ); + + // Vertex size + int VertexSize() const { return m_VertexSize; } + + // Vertex count + int VertexCount() const { return m_VertexCount; } +#ifdef _X360 + // For some VBs, memory allocation is managed by CGPUBufferAllocator, via ShaderAPI + const GPUBufferHandle_t *GetBufferAllocationHandle( void ); + void SetBufferAllocationHandle( const GPUBufferHandle_t &bufferAllocationHandle ); + bool IsPooled( void ) { creturn m_GPUBufferHandle.IsValid(); } + // Expose the data pointer for read-only CPU access to the data + // (double-indirection supports relocation of the data by CGPUBufferAllocator) + const byte **GetBufferDataPointerAddress( void ); +#endif // _X360 + + static int BufferCount() + { +#ifdef _DEBUG + return s_BufferCount; +#else + return 0; +#endif + } + + // UID + unsigned int UID() const + { +#ifdef RECORDING + return m_UID; +#else + return 0; +#endif + } + + void HandlePerFrameTextureStats( int frame ) + { +#ifdef VPROF_ENABLED + if ( m_Frame != frame && !m_bDynamic ) + { + m_Frame = frame; + m_pFrameCounter += m_nBufferSize; + } +#endif + } + + // Do we have enough room without discarding? + bool HasEnoughRoom( int numVertices ) const; + + // Is this dynamic? + bool IsDynamic() const { return m_bDynamic; } + bool IsExternal() const { return m_bExternalMemory; } + + // Block until this part of the vertex buffer is free + void BlockUntilUnused( int nBufferSize ); + + // used to alter the characteristics after creation + // allows one dynamic vb to be shared for multiple formats + void ChangeConfiguration( int vertexSize, int totalSize ) + { + Assert( m_bDynamic && !m_bLocked && vertexSize ); + m_VertexSize = vertexSize; + m_VertexCount = m_nBufferSize / vertexSize; + } + + // Compute the next offset for the next lock + int NextLockOffset( ) const; + + // Returns the allocated size + int AllocationSize() const; + + // Returns the number of vertices we have enough room for + int NumVerticesUntilFlush() const + { +#if defined( _X360 ) + if( m_AllocationRing.Count() ) + { + //Cycle through the ring buffer and see what memory is free now + int iNode = m_AllocationRing.Head(); + while( m_AllocationRing.IsValidIndex( iNode ) ) + { + if( Dx9Device()->IsFencePending( m_AllocationRing[iNode].m_Fence ) ) + break; + + iNode = m_AllocationRing.Next( iNode ); + } + + if( m_AllocationRing.IsValidIndex( iNode ) ) + { + int iEndFreeOffset = m_AllocationRing[iNode].m_iEndOffset; + if( iEndFreeOffset < m_Position ) + { + //Wrapped. Making the arbitrary decision that the return value for this function *should* handle the singe giant allocation case which requires contiguous memory + if( iEndFreeOffset > (m_iNextBlockingPosition - m_Position) ) + return iEndFreeOffset / m_VertexSize; + else + return (m_iNextBlockingPosition - m_Position) / m_VertexSize; + } + } + else + { + //we didn't block on any fence + return m_VertexCount; + } + } + + return m_VertexCount; +#else + return (m_nBufferSize - NextLockOffset()) / m_VertexSize; +#endif + } + + // Marks a fence indicating when this buffer was used + void MarkUsedInRendering() + { +#ifdef _X360 + if ( m_bDynamic && m_pVB ) + { + Assert( m_AllocationRing.Count() > 0 ); + m_AllocationRing[m_AllocationRing.Tail()].m_Fence = Dx9Device()->GetCurrentFence(); + } +#endif + } + +private: + void Create( IDirect3DDevice9 *pD3D ); + inline void ReallyUnlock( int unlockBytes ) + { + #if DX_TO_GL_ABSTRACTION + // Knowing how much data was actually written is critical for performance under OpenGL. + m_pVB->UnlockActualSize( unlockBytes ); + #else + unlockBytes; // Unused here + m_pVB->Unlock(); + #endif + } + + enum LOCK_FLAGS + { + LOCKFLAGS_FLUSH = D3DLOCK_NOSYSLOCK | D3DLOCK_DISCARD, +#if !defined( _X360 ) + LOCKFLAGS_APPEND = D3DLOCK_NOSYSLOCK | D3DLOCK_NOOVERWRITE +#else + // X360BUG: forcing all locks to gpu flush, otherwise bizarre mesh corruption on decals + // Currently iterating with microsoft 360 support to track source of gpu corruption + LOCKFLAGS_APPEND = D3DLOCK_NOSYSLOCK +#endif + }; + + LPDIRECT3DVERTEXBUFFER m_pVB; + +#ifdef _X360 + struct DynamicBufferAllocation_t + { + DWORD m_Fence; //track whether this memory is safe to use again. + int m_iStartOffset; + int m_iEndOffset; + unsigned int m_iZPassIdx; // The zpass during which this allocation was made + }; + + int m_iNextBlockingPosition; // m_iNextBlockingPosition >= m_Position where another allocation is still in use. + unsigned char *m_pAllocatedMemory; + int m_iAllocationSize; //Total size of the ring buffer, usually more than what was asked for + IDirect3DVertexBuffer9 m_D3DVertexBuffer; //Only need one shared D3D header for our usage patterns. + CUtlLinkedList m_AllocationRing; //tracks what chunks of our memory are potentially still in use by D3D + + GPUBufferHandle_t m_GPUBufferHandle; // Handle to a memory allocation within a shared physical memory pool (see CGPUBufferAllocator) +#endif + + VertexFormat_t m_VertexBufferFormat; // yes, Vertex, only used for allocation tracking + int m_nBufferSize; + int m_Position; + int m_VertexCount; + int m_VertexSize; + DWORD m_TheFVF; + byte *m_pSysmemBuffer; + int m_nSysmemBufferStartBytes; + + uint m_nLockCount; + unsigned char m_bDynamic : 1; + unsigned char m_bLocked : 1; + unsigned char m_bFlush : 1; + unsigned char m_bExternalMemory : 1; + unsigned char m_bSoftwareVertexProcessing : 1; + unsigned char m_bLateCreateShouldDiscard : 1; + +#ifdef VPROF_ENABLED + int m_Frame; + int *m_pFrameCounter; + int *m_pGlobalCounter; +#endif + +#ifdef _DEBUG + static int s_BufferCount; +#endif + +#ifdef RECORDING + unsigned int m_UID; +#endif +}; + +#if defined( _X360 ) +#include "utlmap.h" +MEMALLOC_DECLARE_EXTERNAL_TRACKING( XMem_CVertexBuffer ); +#endif + +//----------------------------------------------------------------------------- +// constructor, destructor +//----------------------------------------------------------------------------- +inline CVertexBuffer::CVertexBuffer(IDirect3DDevice9 * pD3D, VertexFormat_t fmt, DWORD theFVF, + int vertexSize, int vertexCount, const char *pTextureBudgetName, + bool bSoftwareVertexProcessing, bool dynamic ) : + m_pVB(0), + m_Position(0), + m_VertexSize(vertexSize), + m_VertexCount(vertexCount), + m_bFlush(true), + m_bLocked(false), + m_bExternalMemory( false ), + m_nBufferSize(vertexSize * vertexCount), + m_TheFVF( theFVF ), + m_bSoftwareVertexProcessing( bSoftwareVertexProcessing ), + m_bDynamic(dynamic), + m_VertexBufferFormat( fmt ), + m_bLateCreateShouldDiscard( false ) +#ifdef _X360 + ,m_pAllocatedMemory(NULL) + ,m_iNextBlockingPosition(0) + ,m_iAllocationSize(0) +#endif +#ifdef VPROF_ENABLED + ,m_Frame( -1 ) +#endif +{ + MEM_ALLOC_CREDIT_( pTextureBudgetName ); + +#ifdef RECORDING + // assign a UID + static unsigned int uid = 0; + m_UID = uid++; +#endif + +#ifdef _DEBUG + ++s_BufferCount; +#endif + +#ifdef VPROF_ENABLED + if ( !m_bDynamic ) + { + char name[256]; + V_strcpy_safe( name, "TexGroup_global_" ); + V_strcat_safe( name, pTextureBudgetName, sizeof(name) ); + m_pGlobalCounter = g_VProfCurrentProfile.FindOrCreateCounter( name, COUNTER_GROUP_TEXTURE_GLOBAL ); + + V_strcpy_safe( name, "TexGroup_frame_" ); + V_strcat_safe( name, pTextureBudgetName, sizeof(name) ); + m_pFrameCounter = g_VProfCurrentProfile.FindOrCreateCounter( name, COUNTER_GROUP_TEXTURE_PER_FRAME ); + } + else + { + m_pGlobalCounter = g_VProfCurrentProfile.FindOrCreateCounter( "TexGroup_global_" TEXTURE_GROUP_DYNAMIC_VERTEX_BUFFER, COUNTER_GROUP_TEXTURE_GLOBAL ); + } +#endif + + if ( !g_pShaderUtil->IsRenderThreadSafe() ) + { + m_pSysmemBuffer = ( byte * )MemAlloc_AllocAligned( m_nBufferSize, 16 ); + m_nSysmemBufferStartBytes = 0; + } + else + { + m_pSysmemBuffer = NULL; + Create( pD3D ); + } + +#ifdef VPROF_ENABLED + if ( IsX360() || !m_bDynamic ) + { + Assert( m_pGlobalCounter ); + *m_pGlobalCounter += m_nBufferSize; + } +#endif +} + + +void CVertexBuffer::Create( IDirect3DDevice9 *pD3D ) +{ + D3DVERTEXBUFFER_DESC desc; + memset( &desc, 0x00, sizeof( desc ) ); + desc.Format = D3DFMT_VERTEXDATA; + desc.Size = m_nBufferSize; + desc.Type = D3DRTYPE_VERTEXBUFFER; + desc.Pool = m_bDynamic ? D3DPOOL_DEFAULT : D3DPOOL_MANAGED; + desc.FVF = m_TheFVF; + +#if defined(IS_WINDOWS_PC) && defined(SHADERAPIDX9) + extern bool g_ShaderDeviceUsingD3D9Ex; + if ( g_ShaderDeviceUsingD3D9Ex ) + { + desc.Pool = D3DPOOL_DEFAULT; + } +#endif + + desc.Usage = D3DUSAGE_WRITEONLY; + if ( m_bDynamic ) + { + desc.Usage |= D3DUSAGE_DYNAMIC; + // Dynamic meshes should never be compressed (slows down writing to them) + Assert( CompressionType( m_TheFVF ) == VERTEX_COMPRESSION_NONE ); + } + if ( m_bSoftwareVertexProcessing ) + { + desc.Usage |= D3DUSAGE_SOFTWAREPROCESSING; + } + +#if !defined( _X360 ) + RECORD_COMMAND( DX8_CREATE_VERTEX_BUFFER, 6 ); + RECORD_INT( m_UID ); + RECORD_INT( m_nBufferSize ); + RECORD_INT( desc.Usage ); + RECORD_INT( desc.FVF ); + RECORD_INT( desc.Pool ); + RECORD_INT( m_bDynamic ); + + HRESULT hr = pD3D->CreateVertexBuffer( m_nBufferSize, desc.Usage, desc.FVF, desc.Pool, &m_pVB, NULL ); + + if ( hr == D3DERR_OUTOFVIDEOMEMORY || hr == E_OUTOFMEMORY ) + { + // Don't have the memory for this. Try flushing all managed resources + // out of vid mem and try again. + // FIXME: need to record this + pD3D->EvictManagedResources(); + pD3D->CreateVertexBuffer( m_nBufferSize, desc.Usage, desc.FVF, desc.Pool, &m_pVB, NULL ); + } + +#ifdef _DEBUG + if ( hr != D3D_OK ) + { + switch ( hr ) + { + case D3DERR_INVALIDCALL: + Assert( !"D3DERR_INVALIDCALL" ); + break; + case D3DERR_OUTOFVIDEOMEMORY: + Assert( !"D3DERR_OUTOFVIDEOMEMORY" ); + break; + case E_OUTOFMEMORY: + Assert( !"E_OUTOFMEMORY" ); + break; + default: + Assert( 0 ); + break; + } + } +#endif + + Assert( m_pVB ); +#else + // _X360 + if ( m_bDynamic ) + { + m_iAllocationSize = m_nBufferSize * X360_VERTEX_BUFFER_SIZE_MULTIPLIER; + Assert( m_iAllocationSize >= m_nBufferSize ); + m_pAllocatedMemory = (unsigned char*)XPhysicalAlloc( m_iAllocationSize, MAXULONG_PTR, 0, PAGE_READWRITE | MEM_LARGE_PAGES | PAGE_WRITECOMBINE ); + } + else if ( MeshMgr()->AllocatePooledVB( this, m_nBufferSize, pTextureBudgetName ) ) + { + // Successfully allocated in a shared ShaderAPI memory pool (SetBufferAllocationHandle will have been called to set the pointer and stream offset) + m_iAllocationSize = m_nBufferSize; + Assert( m_pAllocatedMemory ); + } + else + { + // Fall back to allocating a standalone VB + // NOTE: write-combining (PAGE_WRITECOMBINE) is deliberately not used, since it slows down CPU access to the data (decals+defragmentation) + m_iAllocationSize = m_nBufferSize; + m_pAllocatedMemory = (unsigned char*)XPhysicalAlloc( m_iAllocationSize, MAXULONG_PTR, 0, PAGE_READWRITE ); + } + + if ( m_pAllocatedMemory && !IsPooled() ) + { + MemAlloc_RegisterExternalAllocation( XMem_CVertexBuffer, m_pAllocatedMemory, XPhysicalSize( m_pAllocatedMemory ) ); + if ( !m_bDynamic ) + { + // Track non-pooled physallocs, to help tune CGPUBufferAllocator usage + g_SizeIndividualVBPhysAllocs += XPhysicalSize( m_pAllocatedMemory ); + g_NumIndividualVBPhysAllocs++; + } + } + + m_iNextBlockingPosition = m_iAllocationSize; +#endif + +#ifdef MEASURE_DRIVER_ALLOCATIONS + int nMemUsed = 1024; + VPROF_INCREMENT_GROUP_COUNTER( "vb count", COUNTER_GROUP_NO_RESET, 1 ); + VPROF_INCREMENT_GROUP_COUNTER( "vb driver mem", COUNTER_GROUP_NO_RESET, nMemUsed ); + VPROF_INCREMENT_GROUP_COUNTER( "total driver mem", COUNTER_GROUP_NO_RESET, nMemUsed ); +#endif + + // Track VB allocations +#if !defined( _X360 ) + g_VBAllocTracker->CountVB( m_pVB, m_bDynamic, m_nBufferSize, m_VertexSize, m_VertexBufferFormat ); +#else + g_VBAllocTracker->CountVB( this, m_bDynamic, m_iAllocationSize, m_VertexSize, m_VertexBufferFormat ); +#endif +} + + +#ifdef _X360 +void *AllocateTempBuffer( size_t nSizeInBytes ); + +//----------------------------------------------------------------------------- +// This variant is for when we already have the data in physical memory +//----------------------------------------------------------------------------- +inline CVertexBuffer::CVertexBuffer( ) : + m_pVB( 0 ), + m_Position( 0 ), + m_VertexSize( 0 ), + m_VertexCount( 0 ), + m_bFlush( false ), + m_bLocked( false ), + m_bExternalMemory( true ), + m_nBufferSize( 0 ), + m_bDynamic( false ) +#ifdef VPROF_ENABLED + ,m_Frame( -1 ) +#endif +{ + m_iAllocationSize = 0; + m_pAllocatedMemory = 0; + m_iNextBlockingPosition = 0; +} + +#include "tier0/memdbgoff.h" + +inline void CVertexBuffer::Init( IDirect3DDevice9 *pD3D, VertexFormat_t fmt, DWORD theFVF, uint8 *pVertexData, int vertexSize, int vertexCount ) +{ + m_nBufferSize = vertexSize * vertexCount; + m_Position = m_Position; + m_VertexSize = vertexSize; + m_VertexCount = vertexCount; + m_iAllocationSize = m_nBufferSize; + m_pAllocatedMemory = pVertexData; + m_iNextBlockingPosition = m_iAllocationSize; + + m_pVB = new( AllocateTempBuffer( sizeof( IDirect3DVertexBuffer9 ) ) ) IDirect3DVertexBuffer9; + XGSetVertexBufferHeader( m_nBufferSize, 0, 0, 0, m_pVB ); + XGOffsetResourceAddress( m_pVB, pVertexData ); +} + +#include "tier0/memdbgon.h" + +#endif // _X360 + +inline CVertexBuffer::~CVertexBuffer() +{ + // Track VB allocations (even if pooled) +#if !defined( _X360 ) + if ( m_pVB != NULL ) + { + g_VBAllocTracker->UnCountVB( m_pVB ); + } +#else + if ( m_pVB && m_pVB->IsSet( Dx9Device() ) ) + { + Unbind( m_pVB ); + } + + if ( !m_bExternalMemory ) + { + g_VBAllocTracker->UnCountVB( this ); + } +#endif + + if ( !m_bExternalMemory ) + { +#ifdef MEASURE_DRIVER_ALLOCATIONS + int nMemUsed = 1024; + VPROF_INCREMENT_GROUP_COUNTER( "vb count", COUNTER_GROUP_NO_RESET, -1 ); + VPROF_INCREMENT_GROUP_COUNTER( "vb driver mem", COUNTER_GROUP_NO_RESET, -nMemUsed ); + VPROF_INCREMENT_GROUP_COUNTER( "total driver mem", COUNTER_GROUP_NO_RESET, -nMemUsed ); +#endif + +#ifdef VPROF_ENABLED + if ( IsX360() || !m_bDynamic ) + { + Assert( m_pGlobalCounter ); + *m_pGlobalCounter -= m_nBufferSize; + } +#endif + +#ifdef _DEBUG + --s_BufferCount; +#endif + } + + Unlock( 0 ); + + if ( m_pSysmemBuffer ) + { + MemAlloc_FreeAligned( m_pSysmemBuffer ); + m_pSysmemBuffer = NULL; + } + +#if !defined( _X360 ) + if ( m_pVB ) + { + RECORD_COMMAND( DX8_DESTROY_VERTEX_BUFFER, 1 ); + RECORD_INT( m_UID ); + + m_pVB->Release(); + } +#else + if ( m_pAllocatedMemory && !m_bExternalMemory ) + { + if ( IsPooled() ) + { + MeshMgr()->DeallocatePooledVB( this ); + } + else + { + MemAlloc_RegisterExternalDeallocation( XMem_CVertexBuffer, m_pAllocatedMemory, XPhysicalSize( m_pAllocatedMemory ) ); + if ( !m_bDynamic ) + { + // Track non-pooled physallocs, to help tune CGPUBufferAllocator usage + g_SizeIndividualVBPhysAllocs -= XPhysicalSize( m_pAllocatedMemory ); + g_NumIndividualVBPhysAllocs--; + } + XPhysicalFree( m_pAllocatedMemory ); + } + } + + m_pAllocatedMemory = NULL; + m_pVB = NULL; +#endif // _X360 +} +#ifdef _X360 +//----------------------------------------------------------------------------- +// Get memory allocation data +//----------------------------------------------------------------------------- +inline const GPUBufferHandle_t *CVertexBuffer::GetBufferAllocationHandle( void ) +{ + Assert( IsPooled() ); + return ( IsPooled() ? &m_GPUBufferHandle : NULL ); +} + +//----------------------------------------------------------------------------- +// Update memory allocation data +//----------------------------------------------------------------------------- +inline void CVertexBuffer::SetBufferAllocationHandle( const GPUBufferHandle_t &bufferAllocationHandle ) +{ + // This VB's memory has been reallocated or freed, update our cached pointer and the D3D header + // NOTE: this should never be called while any rendering is in flight! + Assert( ( m_pAllocatedMemory == NULL ) || IsPooled() ); + if ( ( m_pAllocatedMemory == NULL ) || IsPooled() ) + { + m_GPUBufferHandle = bufferAllocationHandle; + m_pAllocatedMemory = m_GPUBufferHandle.pMemory; + if ( m_pVB ) + { + XGSetVertexBufferHeader( m_nBufferSize, 0, D3DPOOL_DEFAULT, 0, m_pVB ); + XGOffsetResourceAddress( m_pVB, m_pAllocatedMemory ); + } + } +} + +//----------------------------------------------------------------------------- +// Expose the data pointer for read-only CPU access to the data +//----------------------------------------------------------------------------- +inline const byte **CVertexBuffer::GetBufferDataPointerAddress( void ) +{ + if ( m_bDynamic /* FIXME: || m_bExternalMemory*/ ) + return NULL; + return (const byte **)&m_pAllocatedMemory; +} +#endif // _X360 + +//----------------------------------------------------------------------------- +// Compute the next offset for the next lock +//----------------------------------------------------------------------------- +inline int CVertexBuffer::NextLockOffset( ) const +{ +#if !defined( _X360 ) + int nNextOffset = ( m_Position + m_VertexSize - 1 ) / m_VertexSize; + nNextOffset *= m_VertexSize; + return nNextOffset; +#else + return m_Position; //position is already aligned properly on unlocks for 360. +#endif +} + + +//----------------------------------------------------------------------------- +// Do we have enough room without discarding? +//----------------------------------------------------------------------------- +inline bool CVertexBuffer::HasEnoughRoom( int numVertices ) const +{ +#if defined( _X360 ) + return numVertices <= m_VertexCount; //the ring buffer will free room as needed +#else + return (NextLockOffset() + (numVertices * m_VertexSize)) <= m_nBufferSize; +#endif +} + +//----------------------------------------------------------------------------- +// Block until this part of the index buffer is free +//----------------------------------------------------------------------------- +inline void CVertexBuffer::BlockUntilUnused( int nBufferSize ) +{ + Assert( nBufferSize <= m_nBufferSize ); + +#ifdef _X360 + int nLockOffset = NextLockOffset(); + Assert( (m_AllocationRing.Count() != 0) || ((m_Position == 0) && (m_iNextBlockingPosition == m_iAllocationSize)) ); + + if ( (m_iNextBlockingPosition - nLockOffset) >= nBufferSize ) + return; + + Assert( (m_AllocationRing[m_AllocationRing.Head()].m_iStartOffset == 0) || ((m_iNextBlockingPosition == m_AllocationRing[m_AllocationRing.Head()].m_iStartOffset) && (m_Position <= m_iNextBlockingPosition)) ); + + int iMinBlockPosition = nLockOffset + nBufferSize; + if( iMinBlockPosition > m_iAllocationSize ) + { + //Allocation requires us to wrap + iMinBlockPosition = nBufferSize; + m_Position = 0; + + //modify the last allocation so that it uses up the whole tail end of the buffer. Makes other code simpler + Assert( m_AllocationRing.Count() != 0 ); + m_AllocationRing[m_AllocationRing.Tail()].m_iEndOffset = m_iAllocationSize; + + //treat all allocations between the current position and the tail end of the ring as freed since they will be before we unblock + while( m_AllocationRing.Count() ) + { + unsigned int head = m_AllocationRing.Head(); + if( m_AllocationRing[head].m_iStartOffset == 0 ) + break; + + m_AllocationRing.Remove( head ); + } + } + + //now we go through the allocations until we find the last fence we care about. Treat everything up until that fence as freed. + DWORD FinalFence = 0; + unsigned int iFinalAllocationZPassIdx = 0; + while( m_AllocationRing.Count() ) + { + unsigned int head = m_AllocationRing.Head(); + + if( m_AllocationRing[head].m_iEndOffset >= iMinBlockPosition ) + { + //When this frees, we'll finally have enough space for the allocation + FinalFence = m_AllocationRing[head].m_Fence; + iFinalAllocationZPassIdx = m_AllocationRing[head].m_iZPassIdx; + m_iNextBlockingPosition = m_AllocationRing[head].m_iEndOffset; + m_AllocationRing.Remove( head ); + break; + } + m_AllocationRing.Remove( head ); + } + Assert( FinalFence != 0 ); + + if( Dx9Device()->IsFencePending( FinalFence ) ) + { +#ifdef SPEW_VERTEX_BUFFER_STALLS + float st = Plat_FloatTime(); +#endif + + if ( ( Dx9Device()->GetDeviceState() & D3DDEVICESTATE_ZPASS_BRACKET ) && + ( iFinalAllocationZPassIdx == ShaderAPI()->Get360ZPassCounter() ) ) + { + // We're about to overrun our VB ringbuffer in a single Z prepass. To avoid rendering corruption, close out the + // Z prepass and continue. This will reduce early-Z rejection efficiency and could cause a momentary framerate drop, + // but it's better than rendering corruption. + Warning( "Dynamic VB ring buffer overrun in Z Prepass. Tell Thorsten.\n" ); + + ShaderAPI()->End360ZPass(); + } + + Dx9Device()->BlockOnFence( FinalFence ); + +#ifdef SPEW_VERTEX_BUFFER_STALLS + float dt = Plat_FloatTime() - st; + Warning( "Blocked locking dynamic vertex buffer for %f ms!\n", 1000.0 * dt ); +#endif + } + +#endif +} + + +//----------------------------------------------------------------------------- +// lock, unlock +//----------------------------------------------------------------------------- +inline unsigned char* CVertexBuffer::Lock( int numVerts, int& baseVertexIndex ) +{ +#if defined( _X360 ) + if ( m_pVB && m_pVB->IsSet( Dx9Device() ) ) + { + Unbind( m_pVB ); + } +#endif + + m_nLockCount = numVerts; + + unsigned char* pLockedData = 0; + baseVertexIndex = 0; + int nBufferSize = numVerts * m_VertexSize; + + Assert( IsPC() || ( IsX360() && !m_bLocked ) ); + + // Ensure there is enough space in the VB for this data + if ( numVerts > m_VertexCount ) + { + Assert( 0 ); + return 0; + } + + if ( !IsX360() && !m_pVB && !m_pSysmemBuffer ) + return 0; + + DWORD dwFlags; + if ( m_bDynamic ) + { + dwFlags = LOCKFLAGS_APPEND; + +#if !defined( _X360 ) + // If either the user forced us to flush, + // or there is not enough space for the vertex data, + // then flush the buffer contents + if ( !m_Position || m_bFlush || !HasEnoughRoom(numVerts) ) + { + if ( m_pSysmemBuffer || !g_pShaderUtil->IsRenderThreadSafe() ) + m_bLateCreateShouldDiscard = true; + m_bFlush = false; + m_Position = 0; + + dwFlags = LOCKFLAGS_FLUSH; + } +#else + if( m_bFlush ) + { +# if ( defined( X360_BLOCK_ON_VB_FLUSH ) ) + { + if( m_AllocationRing.Count() ) + { + DWORD FinalFence = m_AllocationRing[m_AllocationRing.Tail()].m_Fence; + + m_AllocationRing.RemoveAll(); + m_Position = 0; + m_iNextBlockingPosition = m_iAllocationSize; + +# if ( defined( SPEW_VERTEX_BUFFER_STALLS ) ) + if( Dx9Device()->IsFencePending( FinalFence ) ) + { + float st = Plat_FloatTime(); +# endif + Dx9Device()->BlockOnFence( FinalFence ); +# if ( defined ( SPEW_VERTEX_BUFFER_STALLS ) ) + float dt = Plat_FloatTime() - st; + Warning( "Blocked FLUSHING dynamic vertex buffer for %f ms!\n", 1000.0 * dt ); + } +# endif + } + } +# endif + m_bFlush = false; + } +#endif + } + else + { + // Since we are a static VB, always lock the beginning of the buffer. + dwFlags = D3DLOCK_NOSYSLOCK; + m_Position = 0; + } + + if ( IsX360() && m_bDynamic ) + { + // Block until we have enough room in the buffer, this affects the result of NextLockOffset() in wrap conditions. + BlockUntilUnused( nBufferSize ); + m_pVB = NULL; + } + + int nLockOffset = NextLockOffset( ); + RECORD_COMMAND( DX8_LOCK_VERTEX_BUFFER, 4 ); + RECORD_INT( m_UID ); + RECORD_INT( nLockOffset ); + RECORD_INT( nBufferSize ); + RECORD_INT( dwFlags ); + +#if !defined( _X360 ) + // If the caller isn't in the thread that owns the render lock, need to return a system memory pointer--cannot talk to GL from + // the non-current thread. + if ( !m_pSysmemBuffer && !g_pShaderUtil->IsRenderThreadSafe() ) + { + m_pSysmemBuffer = ( byte * )MemAlloc_AllocAligned( m_nBufferSize, 16 ); + m_nSysmemBufferStartBytes = nLockOffset; + Assert( ( m_nSysmemBufferStartBytes % m_VertexSize ) == 0 ); + } + + if ( m_pSysmemBuffer != NULL ) + { + // Ensure that we're never moving backwards in a buffer--this code would need to be rewritten if so. + // We theorize this can happen if you hit the end of a buffer and then wrap before drawing--but + // this would probably break in other places as well. + Assert( nLockOffset >= m_nSysmemBufferStartBytes ); + pLockedData = m_pSysmemBuffer + nLockOffset; + } + else + { + m_pVB->Lock( nLockOffset, + nBufferSize, + reinterpret_cast< void** >( &pLockedData ), + dwFlags ); + } +#else + pLockedData = m_pAllocatedMemory + nLockOffset; +#endif + + Assert( pLockedData != 0 ); + m_bLocked = true; + if ( !IsX360() ) + { + baseVertexIndex = nLockOffset / m_VertexSize; + } + else + { + baseVertexIndex = 0; + } + return pLockedData; +} + +inline unsigned char* CVertexBuffer::Modify( bool bReadOnly, int firstVertex, int numVerts ) +{ + unsigned char* pLockedData = 0; + + // D3D still returns a pointer when you call lock with 0 verts, so just in + // case it's actually doing something, don't even try to lock the buffer with 0 verts. + if ( numVerts == 0 ) + return NULL; + + m_nLockCount = numVerts; + + // If this hits, m_pSysmemBuffer logic needs to be added to this code. + Assert( g_pShaderUtil->IsRenderThreadSafe() ); + Assert( !m_pSysmemBuffer ); // if this hits, then we need to add code to handle it + + Assert( m_pVB && !m_bDynamic ); + + if ( firstVertex + numVerts > m_VertexCount ) + { + Assert( 0 ); + return NULL; + } + + DWORD dwFlags = D3DLOCK_NOSYSLOCK; + if ( bReadOnly ) + { + dwFlags |= D3DLOCK_READONLY; + } + + RECORD_COMMAND( DX8_LOCK_VERTEX_BUFFER, 4 ); + RECORD_INT( m_UID ); + RECORD_INT( firstVertex * m_VertexSize ); + RECORD_INT( numVerts * m_VertexSize ); + RECORD_INT( dwFlags ); + + // mmw: for forcing all dynamic... LOCKFLAGS_FLUSH ); +#if !defined( _X360 ) + m_pVB->Lock( + firstVertex * m_VertexSize, + numVerts * m_VertexSize, + reinterpret_cast< void** >( &pLockedData ), + dwFlags ); +#else + if ( m_pVB->IsSet( Dx9Device() ) ) + { + Unbind( m_pVB ); + } + pLockedData = m_pAllocatedMemory + (firstVertex * m_VertexSize); +#endif + + m_Position = firstVertex * m_VertexSize; + Assert( pLockedData != 0 ); + m_bLocked = true; + + return pLockedData; +} + +inline void CVertexBuffer::Unlock( int numVerts ) +{ + if ( !m_bLocked ) + return; + + if ( !IsX360() && !m_pVB && !m_pSysmemBuffer ) + return; + + int nLockOffset = NextLockOffset(); + int nBufferSize = numVerts * m_VertexSize; + + RECORD_COMMAND( DX8_UNLOCK_VERTEX_BUFFER, 1 ); + RECORD_INT( m_UID ); + +#if !defined( _X360 ) + if ( m_pSysmemBuffer != NULL ) + { + } + else + { + #if DX_TO_GL_ABSTRACTION + Assert( numVerts <= (int)m_nLockCount ); + int unlockBytes = ( m_bDynamic ? nBufferSize : ( m_nLockCount * m_VertexSize ) ); + #else + int unlockBytes = 0; + #endif + + ReallyUnlock( unlockBytes ); + } + m_Position = nLockOffset + nBufferSize; +#else + if ( m_bDynamic ) + { + if ( numVerts > 0 ) + { + DynamicBufferAllocation_t LockData; + LockData.m_Fence = Dx9Device()->GetCurrentFence(); //This isn't the correct fence, but it's all we have access to for now and it'll provide marginal safety if something goes really wrong. + LockData.m_iStartOffset = nLockOffset; + LockData.m_iEndOffset = LockData.m_iStartOffset + nBufferSize; + LockData.m_iZPassIdx = ( Dx9Device()->GetDeviceState() & D3DDEVICESTATE_ZPASS_BRACKET ) ? ShaderAPI()->Get360ZPassCounter() : 0; + + // Round dynamic locks to 4k boundaries for GPU cache reasons + LockData.m_iEndOffset = ALIGN_VALUE( LockData.m_iEndOffset, 4096 ); + if( LockData.m_iEndOffset > m_iAllocationSize ) + LockData.m_iEndOffset = m_iAllocationSize; + + m_AllocationRing.AddToTail( LockData ); + m_Position = LockData.m_iEndOffset; + + void* pLockedData = m_pAllocatedMemory + LockData.m_iStartOffset; + + //Always re-use the same vertex buffer header based on the assumption that D3D copies it off in the draw calls. + m_pVB = &m_D3DVertexBuffer; + XGSetVertexBufferHeader( nBufferSize, 0, D3DPOOL_DEFAULT, 0, m_pVB ); + XGOffsetResourceAddress( m_pVB, pLockedData ); + + // Invalidate the GPU caches for this memory. + Dx9Device()->InvalidateGpuCache( pLockedData, nBufferSize, 0 ); + } + } + else + { + if ( !m_pVB ) + { + m_pVB = &m_D3DVertexBuffer; + XGSetVertexBufferHeader( m_nBufferSize, 0, D3DPOOL_DEFAULT, 0, m_pVB ); + XGOffsetResourceAddress( m_pVB, m_pAllocatedMemory ); + } + m_Position = nLockOffset + nBufferSize; + + // Invalidate the GPU caches for this memory. + Dx9Device()->InvalidateGpuCache( m_pAllocatedMemory, m_nBufferSize, 0 ); + } +#endif + + m_bLocked = false; +} + + +inline void CVertexBuffer::HandleLateCreation( ) +{ + if ( !m_pSysmemBuffer ) + { + return; + } + + if( !m_pVB ) + { + bool bPrior = g_VBAllocTracker->TrackMeshAllocations( "HandleLateCreation" ); + Create( Dx9Device() ); + if ( !bPrior ) + { + g_VBAllocTracker->TrackMeshAllocations( NULL ); + } + } + + void* pWritePtr = NULL; + const int dataToWriteBytes = m_bDynamic ? ( m_Position - m_nSysmemBufferStartBytes ) : ( m_nLockCount * m_VertexSize ); + DWORD dwFlags = D3DLOCK_NOSYSLOCK; + if ( m_bDynamic ) + { + dwFlags |= ( m_bLateCreateShouldDiscard ? D3DLOCK_DISCARD : D3DLOCK_NOOVERWRITE ); + } + + // Always clear this. + m_bLateCreateShouldDiscard = false; + + // Don't use the Lock function, it does a bunch of stuff we don't want. + HRESULT hr = m_pVB->Lock( m_nSysmemBufferStartBytes, + dataToWriteBytes, + &pWritePtr, + dwFlags); + + // If this fails we're about to crash. Consider skipping the update and leaving + // m_pSysmemBuffer around to try again later. (For example in case of device loss) + Assert( SUCCEEDED( hr ) ); hr; + memcpy( pWritePtr, m_pSysmemBuffer + m_nSysmemBufferStartBytes, dataToWriteBytes ); + ReallyUnlock( dataToWriteBytes ); + + MemAlloc_FreeAligned( m_pSysmemBuffer ); + m_pSysmemBuffer = NULL; +} + + +// Returns the allocated size +inline int CVertexBuffer::AllocationSize() const +{ +#ifdef _X360 + return m_iAllocationSize; +#else + return m_VertexCount * m_VertexSize; +#endif +} + + +#endif // DYNAMICVB_H + diff --git a/materialsystem/shaderapidx9/gpubufferallocator.cpp b/materialsystem/shaderapidx9/gpubufferallocator.cpp new file mode 100644 index 0000000..e86a009 --- /dev/null +++ b/materialsystem/shaderapidx9/gpubufferallocator.cpp @@ -0,0 +1,480 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: See gpubufferallocator.h +// +// $NoKeywords: $ +// +//===========================================================================// + +#include "gpubufferallocator.h" +#include "dynamicvb.h" +#include "dynamicib.h" + +// NOTE: This has to be the last file included! +#include "tier0/memdbgon.h" + +#if defined( _X360 ) + + + +//----------------------------------------------------------------------------- +// globals +//----------------------------------------------------------------------------- + +#include "utlmap.h" +MEMALLOC_DEFINE_EXTERNAL_TRACKING( XMem_CGPUBufferPool ); + +// Track non-pooled VB/IB physical allocations (used by CGPUBufferAllocator::SpewStats) +CInterlockedInt g_NumIndividualVBPhysAllocs = 0; +CInterlockedInt g_SizeIndividualVBPhysAllocs = 0; +CInterlockedInt g_NumIndividualIBPhysAllocs = 0; +CInterlockedInt g_SizeIndividualIBPhysAllocs = 0; + + + +//============================================================================= +//============================================================================= +// CGPUBufferAllocator +//============================================================================= +//============================================================================= + +CGPUBufferAllocator::CGPUBufferAllocator( void ) + : m_nBufferPools( 0 ), + m_bEnabled( true ) +{ + memset( &( m_BufferPools[ 0 ] ), 0, sizeof( m_BufferPools ) ); + + m_bEnabled = USE_GPU_BUFFER_ALLOCATOR && !CommandLine()->FindParm( "-no_gpu_buffer_allocator" ); + if ( m_bEnabled ) + { + // Start with one pool (the size should be the lowest-common-denominator for all maps) + AllocatePool( INITIAL_POOL_SIZE ); + } +} + +CGPUBufferAllocator::~CGPUBufferAllocator( void ) +{ + for ( int i = 0; i < m_nBufferPools; i++ ) + { + delete m_BufferPools[ i ]; + } +} + +//----------------------------------------------------------------------------- +// Allocate a new memory pool +//----------------------------------------------------------------------------- +bool CGPUBufferAllocator::AllocatePool( int nPoolSize ) +{ + if ( m_nBufferPools == MAX_POOLS ) + return false; + + m_BufferPools[ m_nBufferPools ] = new CGPUBufferPool( nPoolSize ); + if ( m_BufferPools[ m_nBufferPools ]->m_pMemory == NULL ) + { + // Physical alloc failed! Continue without crashing, we *might* get away with it... + ExecuteOnce( DebuggerBreakIfDebugging() ); + ExecuteNTimes( 15, Warning( "CGPUBufferAllocator::AllocatePool - physical allocation failed! Physical fragmentation is in bad shape... falling back to non-pooled VB/IB allocations. Brace for a crash :o/\n" ) ); + delete m_BufferPools[ m_nBufferPools ]; + m_BufferPools[ m_nBufferPools ] = NULL; + return false; + } + m_nBufferPools++; + return true; +} + +//----------------------------------------------------------------------------- +// Make a new GPUBufferHandle_t to represent a given buffer allocation +//----------------------------------------------------------------------------- +inline GPUBufferHandle_t CGPUBufferAllocator::MakeGPUBufferHandle( int nPoolNum, int nPoolEntry ) +{ + GPUBufferHandle_t newHandle; + newHandle.nPoolNum = nPoolNum; + newHandle.nPoolEntry = nPoolEntry; + newHandle.pMemory = m_BufferPools[ nPoolNum ]->m_pMemory + m_BufferPools[ nPoolNum ]->m_PoolEntries[ nPoolEntry ].nOffset; + return newHandle; +} + +//----------------------------------------------------------------------------- +// Try to allocate a block of the given size from one of our pools +//----------------------------------------------------------------------------- +bool CGPUBufferAllocator::AllocateBuffer( GPUBufferHandle_t *pHandle, int nBufferSize, void *pObject, bool bIsVertexBuffer ) +{ + if ( m_bEnabled && ( nBufferSize <= MAX_BUFFER_SIZE ) ) + { + // Try to allocate at the end of one of our pools + for ( int nPool = 0; nPool < m_nBufferPools; nPool++ ) + { + int nPoolEntry = m_BufferPools[ nPool ]->Allocate( nBufferSize, bIsVertexBuffer, pObject ); + if ( nPoolEntry >= 0 ) + { + // Tada. + *pHandle = MakeGPUBufferHandle( nPool, nPoolEntry ); + return true; + } + if ( nPool == ( m_nBufferPools - 1 ) ) + { + // Allocate a new pool (in which this buffer should DEFINITELY fit!) + COMPILE_TIME_ASSERT( ADDITIONAL_POOL_SIZE >= MAX_BUFFER_SIZE ); + AllocatePool( ADDITIONAL_POOL_SIZE ); + } + } + } + return false; +} + +//----------------------------------------------------------------------------- +// Clear the given allocation from our pools (NOTE: the memory cannot be reused until Defrag() is called) +//----------------------------------------------------------------------------- +void CGPUBufferAllocator::DeallocateBuffer( const GPUBufferHandle_t *pHandle ) +{ + Assert( pHandle ); + if ( pHandle ) + { + Assert( ( pHandle->nPoolNum >= 0 ) && ( pHandle->nPoolNum < m_nBufferPools ) ); + if ( ( pHandle->nPoolNum >= 0 ) && ( pHandle->nPoolNum < m_nBufferPools ) ) + { + m_BufferPools[ pHandle->nPoolNum ]->Deallocate( pHandle ); + } + } +} + +//----------------------------------------------------------------------------- +// If appropriate, allocate this VB's memory from one of our pools +//----------------------------------------------------------------------------- +bool CGPUBufferAllocator::AllocateVertexBuffer( CVertexBuffer *pVertexBuffer, int nBufferSize ) +{ + AUTO_LOCK( m_mutex ); + + bool bIsVertexBuffer = true; + GPUBufferHandle_t handle; + if ( AllocateBuffer( &handle, nBufferSize, (void *)pVertexBuffer, bIsVertexBuffer ) ) + { + // Success - give the VB the handle to this allocation + pVertexBuffer->SetBufferAllocationHandle( handle ); + return true; + } + return false; +} + +//----------------------------------------------------------------------------- +// Deallocate this VB's memory from our pools +//----------------------------------------------------------------------------- +void CGPUBufferAllocator::DeallocateVertexBuffer( CVertexBuffer *pVertexBuffer ) +{ + AUTO_LOCK( m_mutex ); + + // Remove the allocation from the pool and clear the VB's handle + DeallocateBuffer( pVertexBuffer->GetBufferAllocationHandle() ); + pVertexBuffer->SetBufferAllocationHandle( GPUBufferHandle_t() ); +} + +//----------------------------------------------------------------------------- +// If appropriate, allocate this IB's memory from one of our pools +//----------------------------------------------------------------------------- +bool CGPUBufferAllocator::AllocateIndexBuffer( CIndexBuffer *pIndexBuffer, int nBufferSize ) +{ + AUTO_LOCK( m_mutex ); + + bool bIsNOTVertexBuffer = false; + GPUBufferHandle_t handle; + if ( AllocateBuffer( &handle, nBufferSize, (void *)pIndexBuffer, bIsNOTVertexBuffer ) ) + { + // Success - give the IB the handle to this allocation + pIndexBuffer->SetBufferAllocationHandle( handle ); + return true; + } + return false; +} + +//----------------------------------------------------------------------------- +// Deallocate this IB's memory from our pools +//----------------------------------------------------------------------------- +void CGPUBufferAllocator::DeallocateIndexBuffer( CIndexBuffer *pIndexBuffer ) +{ + AUTO_LOCK( m_mutex ); + + // Remove the allocation from the pool and clear the IB's handle + DeallocateBuffer( pIndexBuffer->GetBufferAllocationHandle() ); + pIndexBuffer->SetBufferAllocationHandle( GPUBufferHandle_t() ); +} + +//----------------------------------------------------------------------------- +// Move a buffer from one location to another (could be movement within the same pool) +//----------------------------------------------------------------------------- +void CGPUBufferAllocator::MoveBufferMemory( int nDstPool, int *pnDstEntry, int *pnDstOffset, CGPUBufferPool &srcPool, GPUBufferPoolEntry_t &srcEntry ) +{ + // Move the data + CGPUBufferPool &dstPool = *m_BufferPools[ nDstPool ]; + byte *pDest = dstPool.m_pMemory + *pnDstOffset; + byte *pSource = srcPool.m_pMemory + srcEntry.nOffset; + if ( pDest != pSource ) + V_memmove( pDest, pSource, srcEntry.nSize ); + + // Update the destination pool's allocation entry (NOTE: this could be srcEntry, so srcEntry.nOffset would change) + dstPool.m_PoolEntries[ *pnDstEntry ] = srcEntry; + dstPool.m_PoolEntries[ *pnDstEntry ].nOffset = *pnDstOffset; + + // Tell the VB/IB about the updated allocation + GPUBufferHandle_t newHandle = MakeGPUBufferHandle( nDstPool, *pnDstEntry ); + if ( srcEntry.bIsVertexBuffer ) + srcEntry.pVertexBuffer->SetBufferAllocationHandle( newHandle ); + else + srcEntry.pIndexBuffer->SetBufferAllocationHandle( newHandle ); + + // Move the write address past this entry and increment the pool high water mark + *pnDstOffset += srcEntry.nSize; + *pnDstEntry += 1; + dstPool.m_nBytesUsed += srcEntry.nSize; +} + +//----------------------------------------------------------------------------- +// Reclaim space freed by destroyed buffers and compact our pools ready for new allocations +//----------------------------------------------------------------------------- +void CGPUBufferAllocator::Compact( void ) +{ + // NOTE: this must only be called during map transitions, no rendering must be in flight and everything must be single-threaded! + AUTO_LOCK( m_mutex ); + + // SpewStats(); // pre-compact state + + CFastTimer timer; + timer.Start(); + + // Shuffle all pools to get rid of the empty space occupied by freed buffers. + // We just walk the pools and entries in order, moving each buffer down within the same pool, + // or to the end of a previous pool (if, after compaction, it now has free space). + // Each pool should end up with contiguous, usable free space (may be zero bytes) at the end. + int nDstPool = 0, nDstEntry = 0, nDstOffset = 0; + for ( int nSrcPool = 0; nSrcPool < m_nBufferPools; nSrcPool++ ) + { + CGPUBufferPool &srcPool = *m_BufferPools[ nSrcPool ]; + srcPool.m_nBytesUsed = 0; // Re-fill each pool from scratch + int nEntriesRemainingInPool = 0; + for ( int nSrcEntry = 0; nSrcEntry < srcPool.m_PoolEntries.Count(); nSrcEntry++ ) + { + GPUBufferPoolEntry_t &srcEntry = srcPool.m_PoolEntries[ nSrcEntry ]; + if ( srcEntry.pVertexBuffer ) + { + // First, try to move the buffer into one of the previous (already-compacted) pools + bool bDone = false; + while ( nDstPool < nSrcPool ) + { + CGPUBufferPool &dstPool = *m_BufferPools[ nDstPool ]; + if ( ( nDstOffset + srcEntry.nSize ) <= dstPool.m_nSize ) + { + // Add this buffer to the end of dstPool + Assert( nDstEntry == dstPool.m_PoolEntries.Count() ); + dstPool.m_PoolEntries.AddToTail(); + MoveBufferMemory( nDstPool, &nDstEntry, &nDstOffset, srcPool, srcEntry ); + bDone = true; + break; + } + else + { + // This pool is full, start writing into the next one + nDstPool++; + nDstEntry = 0; + nDstOffset = 0; + } + } + + // If that fails, just shuffle the entry down within srcPool + if ( !bDone ) + { + Assert( nSrcPool == nDstPool ); + MoveBufferMemory( nDstPool, &nDstEntry, &nDstOffset, srcPool, srcEntry ); + nEntriesRemainingInPool++; + } + } + } + + // Discard unused entries from the end of the pool (freed buffers, or buffers moved to other pools) + srcPool.m_PoolEntries.SetCountNonDestructively( nEntriesRemainingInPool ); + } + + // Now free empty pools (keep the first (very large) one around, since fragmentation makes freeing+reallocing it a big risk) + int nBytesFreed = 0; + for ( int nPool = ( m_nBufferPools - 1 ); nPool > 0; nPool-- ) + { + if ( m_BufferPools[ nPool ]->m_PoolEntries.Count() ) + break; + + nBytesFreed += m_BufferPools[ nPool ]->m_nSize; + Assert( m_BufferPools[ nPool ]->m_nBytesUsed == 0 ); + delete m_BufferPools[ nPool ]; + m_nBufferPools--; + } + + if ( m_nBufferPools > 1 ) + { + // The above compaction algorithm could waste space due to large allocs causing nDstPool to increment before that pool + // is actually full. With our current usage pattern (total in-use memory is less than INITIAL_POOL_SIZE, whenever Compact + // is called), that doesn't matter. If that changes (i.e. the below warning fires), then the fix would be: + // - for each pool, sort its entries by size (largest first) and try to allocate them on the end of prior (already-compacted) pools + // - pack whatever remains in the pool down, and proceed to the next pool + ExecuteOnce( Warning( "CGPUBufferAllocator::Compact may be wasting memory due to changed usage patterns (see code for suggested fix)." ) ); + } + +#ifdef _X360 + // Invalidate the GPU caches for all pooled memory, since stuff has moved around + for ( int nPool = 0; nPool < m_nBufferPools; nPool++ ) + { + Dx9Device()->InvalidateGpuCache( m_BufferPools[ nPool ]->m_pMemory, m_BufferPools[ nPool ]->m_nSize, 0 ); + } +#endif + + timer.End(); + float compactTime = (float)timer.GetDuration().GetSeconds(); + Msg( "CGPUBufferAllocator::Compact took %.2f seconds, and freed %.1fkb\n", compactTime, ( nBytesFreed / 1024.0f ) ); + + // SpewStats(); // post-compact state +} + +//----------------------------------------------------------------------------- +// Spew statistics about pool usage, so we can tune our constant values +//----------------------------------------------------------------------------- +void CGPUBufferAllocator::SpewStats( bool bBrief ) +{ + AUTO_LOCK( m_mutex ); + + int nMemAllocated = 0; + int nMemUsed = 0; + int nOldMemWasted = 0; + int nVBsInPools = 0; + int nIBsInPools = 0; + int nFreedBuffers = 0; + int nFreedBufferMem = 0; + for ( int i = 0; i < m_nBufferPools; i++ ) + { + CGPUBufferPool *pool = m_BufferPools[ i ]; + nMemAllocated += pool->m_nSize; + nMemUsed += pool->m_nBytesUsed; + for ( int j = 0; j < pool->m_PoolEntries.Count(); j++ ) + { + GPUBufferPoolEntry_t &poolEntry = pool->m_PoolEntries[ j ]; + if ( poolEntry.pVertexBuffer ) + { + // Figure out how much memory we WOULD have allocated for this buffer, if we'd allocated it individually: + nOldMemWasted += ALIGN_VALUE( poolEntry.nSize, 4096 ) - poolEntry.nSize; + if ( poolEntry.bIsVertexBuffer ) nVBsInPools++; + if ( !poolEntry.bIsVertexBuffer ) nIBsInPools++; + } + else + { + nFreedBuffers++; + nFreedBufferMem += poolEntry.nSize; + } + } + } + + // NOTE: 'unused' memory doesn't count memory used by freed buffers, which should be zero during gameplay. The purpose is + // to measure wastage at the END of a pool, to help determine ideal values for ADDITIONAL_POOL_SIZE and MAX_BUFFER_SIZE. + int nMemUnused = nMemAllocated - nMemUsed; + + const float KB = 1024.0f, MB = KB*KB; + if ( bBrief ) + { + ConMsg( "[GPUBUFLOG] Pools:%2d | Size:%5.1fMB | Unused:%5.1fMB | Freed:%5.1fMB | Unpooled:%5.1fMB\n", + m_nBufferPools, nMemAllocated / MB, nMemUnused / MB, nFreedBufferMem / MB, ( g_SizeIndividualVBPhysAllocs + g_SizeIndividualIBPhysAllocs ) / MB ); + } + else + { + Msg( "\nGPU Buffer Allocator stats:\n" ); + Msg( " -- %5d -- Num Pools allocated\n", m_nBufferPools ); + Msg( " -- %7.1fMB -- Memory allocated to pools\n", nMemAllocated / MB ); + Msg( " -- %7.1fkb -- Unused memory at tail-end of pools\n", nMemUnused / KB ); + Msg( " -- %7.1fkb -- Memory saved by allocating buffers from pools\n", nOldMemWasted / KB ); + Msg( " -- %5d -- Number of VBs allocated from pools\n", nVBsInPools ); + Msg( " -- %5d -- Number of IBs allocated from pools\n", nIBsInPools ); + Msg( " -- %5d -- Number of freed buffers in pools (should be zero during gameplay)\n", nFreedBuffers ); + Msg( " -- %7.1fkb -- Memory used by freed buffers in pools\n", nFreedBufferMem / KB ); + Msg( " -- %7.1fkb -- Mem allocated for NON-pooled VBs (%d VBs)\n", g_SizeIndividualVBPhysAllocs / KB, g_NumIndividualVBPhysAllocs ); + Msg( " -- %7.1fkb -- Mem allocated for NON-pooled IBs (%d IBs)\n", g_SizeIndividualIBPhysAllocs / KB, g_NumIndividualVBPhysAllocs ); + Msg( "\n" ); + } +} + + +//============================================================================= +//============================================================================= +// CGPUBufferPool +//============================================================================= +//============================================================================= + +CGPUBufferPool::CGPUBufferPool( int nSize ) + : m_PoolEntries( POOL_ENTRIES_GROW_SIZE, POOL_ENTRIES_INIT_SIZE ), + m_nSize( 0 ), + m_nBytesUsed( 0 ) +{ + // NOTE: write-combining (PAGE_WRITECOMBINE) is deliberately not used, since it slows down 'Compact' hugely (and doesn't noticeably benefit load times) + m_pMemory = (byte*)XPhysicalAlloc( nSize, MAXULONG_PTR, 0, PAGE_READWRITE ); + if ( m_pMemory ) + { + MemAlloc_RegisterExternalAllocation( XMem_CGPUBufferPool, m_pMemory, XPhysicalSize( m_pMemory ) ); + m_nSize = nSize; + } +} + +CGPUBufferPool::~CGPUBufferPool( void ) +{ + for ( int i = 0; i < m_PoolEntries.Count(); i++ ) + { + if ( m_PoolEntries[ i ].pVertexBuffer ) + { + // Buffers should be cleaned up before the CGPUBufferAllocator is shut down! + Assert( 0 ); + Warning( "ERROR: Un-freed %s in CGPUBufferPool on shut down! (%6.1fKB\n", + ( m_PoolEntries[ i ].bIsVertexBuffer ? "VB" : "IB" ), ( m_PoolEntries[ i ].nSize / 1024.0f ) ); + break; + } + } + + if ( m_pMemory ) + { + MemAlloc_RegisterExternalDeallocation( XMem_CGPUBufferPool, m_pMemory, XPhysicalSize( m_pMemory ) ); + XPhysicalFree( m_pMemory ); + m_pMemory = 0; + } + + m_nSize = m_nBytesUsed = 0; +} + +//----------------------------------------------------------------------------- +// Attempt to allocate a buffer of the given size in this pool +//----------------------------------------------------------------------------- +int CGPUBufferPool::Allocate( int nBufferSize, bool bIsVertexBuffer, void *pObject ) +{ + // Align the buffer size + nBufferSize = ALIGN_VALUE( nBufferSize, POOL_ENTRY_ALIGNMENT ); + + // Check available space + if ( ( m_nBytesUsed + nBufferSize ) > m_nSize ) + return -1; + + int nPoolEntry = m_PoolEntries.AddToTail(); + GPUBufferPoolEntry_t &poolEntry = m_PoolEntries[ nPoolEntry ]; + poolEntry.nOffset = m_nBytesUsed; + poolEntry.nSize = nBufferSize; + poolEntry.bIsVertexBuffer = bIsVertexBuffer; + poolEntry.pVertexBuffer = (CVertexBuffer *)pObject; + + // Update 'used space' high watermark + m_nBytesUsed += nBufferSize; + + return nPoolEntry; +} + +//----------------------------------------------------------------------------- +// Deallocate the given entry from this pool +//----------------------------------------------------------------------------- +void CGPUBufferPool::Deallocate( const GPUBufferHandle_t *pHandle ) +{ + Assert( m_PoolEntries.IsValidIndex( pHandle->nPoolEntry ) ); + if ( m_PoolEntries.IsValidIndex( pHandle->nPoolEntry ) ) + { + Assert( m_PoolEntries[ pHandle->nPoolEntry ].pVertexBuffer ); + m_PoolEntries[ pHandle->nPoolEntry ].pVertexBuffer = NULL; + } +} + +#endif // _X360 diff --git a/materialsystem/shaderapidx9/gpubufferallocator.h b/materialsystem/shaderapidx9/gpubufferallocator.h new file mode 100644 index 0000000..cffd96d --- /dev/null +++ b/materialsystem/shaderapidx9/gpubufferallocator.h @@ -0,0 +1,146 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: CGPUBufferAllocator manages allocation of VBs/IBs from shared memory pools. +// Avoids 4KB physical alloc alignment overhead per VB/IB. +// +// $NoKeywords: $ +// +//===========================================================================// + + +#ifndef GPUBUFFERALLOCATOR_H +#define GPUBUFFERALLOCATOR_H + +#ifdef _WIN32 +#pragma once +#endif + +#ifdef _X360 + +#include "tier1/utlvector.h" +#include "tier1/convar.h" + +class CVertexBuffer; +class CIndexBuffer; + + +// Only active on X360 atm +#define USE_GPU_BUFFER_ALLOCATOR ( IsX360() ) + + +//----------------------------------------------------------------------------- +// A handle to a buffer pool allocation, held by the allocated VB/IB +//----------------------------------------------------------------------------- +struct GPUBufferHandle_t +{ + GPUBufferHandle_t( void ) : nPoolNum( -1 ), pMemory( NULL ), nPoolEntry( -1 ) {} + bool IsValid( void ) { return ( pMemory != NULL ); } + byte * pMemory; // Physical address of the allocation + int nPoolNum; // Identifies the pool + int nPoolEntry; // Identifies this allocation within the pool +}; + +//----------------------------------------------------------------------------- +// Describes an entry in a CGPUBufferPool +//----------------------------------------------------------------------------- +struct GPUBufferPoolEntry_t +{ + int nOffset; + int nSize; + bool bIsVertexBuffer; + union + { + // These are set to NULL by CGPUBufferPool::Free() (called when the VB/IB is destroyed) + CVertexBuffer *pVertexBuffer; + CIndexBuffer *pIndexBuffer; + }; +}; + +//----------------------------------------------------------------------------- +// A single memory block out of which individual VBs/IBs are allocated +//----------------------------------------------------------------------------- +class CGPUBufferPool +{ +public: + CGPUBufferPool( int nSize ); + virtual ~CGPUBufferPool( void ); + + // Returns the index (-1 on failure) of a new allocation in the pool, for a buffer of the given size. + int Allocate( int nSize, bool bIsVertexBuffer, void *pObject ); + // Frees a given entry (just marks it as freed, the memory will not be reused by Allocate() until CGPUBufferAllocator::Defrag() is called ) + void Deallocate( const GPUBufferHandle_t *pHandle ); + +private: + // NOTE: these values are specialized for X360 and should be #ifdef'd for other target platforms + static const int POOL_ENTRIES_INIT_SIZE = 256; + static const int POOL_ENTRIES_GROW_SIZE = 256; + static const int POOL_ENTRY_ALIGNMENT = 4; // 4-byte alignment required for VB/IB data on XBox360 + + byte * m_pMemory; // Pointer to the (physical) address of the pool's memory + int m_nSize; // Total size of the pool + int m_nBytesUsed; // High watermark of used memory in the pool + CUtlVectorm_PoolEntries; // Memory-order array of items allocated in the pool + + // CGPUBufferAllocator is a friend so that CGPUBufferAllocator::Defrag() can shuffle allocations around + friend class CGPUBufferAllocator; +}; + +//----------------------------------------------------------------------------- +// Manages a set of memory blocks out of which individual VBs/IBs are allocated +//----------------------------------------------------------------------------- +class CGPUBufferAllocator +{ +public: + CGPUBufferAllocator( void ); + virtual ~CGPUBufferAllocator( void ); + + // (De)Allocates memory for a vertex/index buffer: + bool AllocateVertexBuffer( CVertexBuffer *pVertexBuffer, int nBufferSize ); + bool AllocateIndexBuffer( CIndexBuffer *pIndexBuffer, int nBufferSize ); + void DeallocateVertexBuffer( CVertexBuffer *pVertexBuffer ); + void DeallocateIndexBuffer( CIndexBuffer *pIndexBuffer ); + + // Compact memory to account for freed buffers + // NOTE: this must only be called during map transitions, no rendering must be in flight and everything must be single-threaded! + void Compact(); + + // Spew statistics about pooled buffer allocations + void SpewStats( bool bBrief = false ); + + +private: + // NOTE: these values are specialized for X360 and should be #ifdef'd for other target platforms + static const int INITIAL_POOL_SIZE = 57*1024*1024 + 256*1024; + static const int ADDITIONAL_POOL_SIZE = 2*1024*1024; + static const int MAX_POOLS = 8; + static const int MAX_BUFFER_SIZE = ADDITIONAL_POOL_SIZE; // 256*1024; + + + // Allocate a new CGPUBufferPool + bool AllocatePool( int nPoolSize ); + // Allocate/deallocate a buffer (type-agnostic) + bool AllocateBuffer( GPUBufferHandle_t *pHandle, int nBufferSize, void *pObject, bool bIsVertexBuffer ); + void DeallocateBuffer( const GPUBufferHandle_t *pHandle ); + // Make a handle for a given allocation + GPUBufferHandle_t MakeGPUBufferHandle( int nPoolNum, int nPoolEntry ); + // Helper for Compact + void MoveBufferMemory( int nDstPool, int *pnDstEntry, int *pnDstOffset, CGPUBufferPool &srcPool, GPUBufferPoolEntry_t &srcEntry ); + + + CGPUBufferPool *m_BufferPools[ MAX_POOLS ]; + int m_nBufferPools; + bool m_bEnabled; + + CThreadFastMutex m_mutex; +}; + + +// Track non-pooled physallocs, to help tune CGPUBufferAllocator usage: +extern CInterlockedInt g_NumIndividualIBPhysAllocs; +extern CInterlockedInt g_SizeIndividualIBPhysAllocs; +extern CInterlockedInt g_NumIndividualVBPhysAllocs; +extern CInterlockedInt g_SizeIndividualVBPhysAllocs; + +#endif // _X360 + +#endif // GPUBUFFERALLOCATOR_H diff --git a/materialsystem/shaderapidx9/hardwareconfig.cpp b/materialsystem/shaderapidx9/hardwareconfig.cpp new file mode 100644 index 0000000..133be43 --- /dev/null +++ b/materialsystem/shaderapidx9/hardwareconfig.cpp @@ -0,0 +1,1311 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +// +//=============================================================================// + +#include "togl/rendermechanism.h" +#include "hardwareconfig.h" +#include "shaderapi/ishaderutil.h" +#include "shaderapi_global.h" +#include "materialsystem/materialsystem_config.h" +#include "tier1/convar.h" +#include "shaderdevicebase.h" +#include "tier0/icommandline.h" + + +//----------------------------------------------------------------------------- +// +// Hardware Config! +// +//----------------------------------------------------------------------------- +static CHardwareConfig s_HardwareConfig; +CHardwareConfig *g_pHardwareConfig = &s_HardwareConfig; + +EXPOSE_SINGLE_INTERFACE_GLOBALVAR( CHardwareConfig, IMaterialSystemHardwareConfig, + MATERIALSYSTEM_HARDWARECONFIG_INTERFACE_VERSION, s_HardwareConfig ) + +template +static void ccs_create_convar_from_hwconfig( const T& val, const char *pName ) +{ + int nValue = static_cast( val ); + + ConVar *pConVar = g_pCVar->FindVar( pName ); + if ( pConVar ) + { + pConVar->SetValue( nValue ); + } + else + { + // Don't care if this leaks - this is only used for development + pConVar = new ConVar( pName, "" ); + } + if ( !nValue ) + pConVar->SetValue( "0" ); + else + pConVar->SetValue( nValue ); +} + +static void ccs_create_convar_from_hwconfig( const char *pVal, const char *pName ) +{ + ConVar *pConVar = g_pCVar->FindVar( pName ); + if ( pConVar ) + { + pConVar->SetValue( pVal ); + } + else + { + // Don't care if this leaks - this is only used for development + pConVar = new ConVar( pName, "" ); + } + pConVar->SetValue( pVal ); +} + +CON_COMMAND_F( ccs_create_convars_from_hwconfig, "Create convars from the current hardware config, useful for diffing purposes", FCVAR_CHEAT ) +{ + if ( !g_pHardwareConfig ) + return; + + const HardwareCaps_t &caps = g_pHardwareConfig->CapsForEdit(); + +#define HWCFG( Name ) ccs_create_convar_from_hwconfig( caps.Name, #Name ) + HWCFG( m_NumTextureStages ); + HWCFG( m_nMaxAnisotropy ); + HWCFG( m_MaxTextureWidth ); + HWCFG( m_MaxTextureHeight ); + HWCFG( m_MaxTextureDepth ); + HWCFG( m_MaxTextureAspectRatio ); + HWCFG( m_MaxPrimitiveCount ); + HWCFG( m_NumPixelShaderConstants ); + HWCFG( m_NumBooleanPixelShaderConstants ); + HWCFG( m_NumIntegerPixelShaderConstants ); + HWCFG( m_NumVertexShaderConstants ); + HWCFG( m_NumBooleanVertexShaderConstants ); + HWCFG( m_NumIntegerVertexShaderConstants ); + HWCFG( m_TextureMemorySize ); + HWCFG( m_MaxNumLights ); + HWCFG( m_MaxBlendMatrices ); + HWCFG( m_MaxBlendMatrixIndices ); + HWCFG( m_MaxVertexShaderBlendMatrices ); + HWCFG( m_MaxUserClipPlanes ); + HWCFG( m_HDRType ); + HWCFG( m_pShaderDLL ); + HWCFG( m_ShadowDepthTextureFormat ); + HWCFG( m_NullTextureFormat ); + HWCFG( m_nVertexTextureCount ); + HWCFG( m_nMaxVertexTextureDimension ); + HWCFG( m_AlphaToCoverageState ); + HWCFG( m_AlphaToCoverageEnableValue ); + HWCFG( m_AlphaToCoverageDisableValue ); + HWCFG( m_nMaxViewports ); + HWCFG( m_flMinGammaControlPoint ); + HWCFG( m_flMaxGammaControlPoint ); + HWCFG( m_nGammaControlPointCount ); + HWCFG( m_MaxVertexShader30InstructionSlots ); + HWCFG( m_MaxPixelShader30InstructionSlots ); + HWCFG( m_MaxSimultaneousRenderTargets ); + HWCFG( m_bDeviceOk ); + HWCFG( m_HasSetDeviceGammaRamp ); + HWCFG( m_SupportsVertexShaders ); + HWCFG( m_SupportsVertexShaders_2_0 ); + HWCFG( m_SupportsPixelShaders ); + HWCFG( m_SupportsPixelShaders_1_4 ); + HWCFG( m_SupportsPixelShaders_2_0 ); + HWCFG( m_SupportsPixelShaders_2_b ); + HWCFG( m_SupportsShaderModel_3_0 ); + HWCFG( m_bSupportsAnisotropicFiltering ); + HWCFG( m_bSupportsMagAnisotropicFiltering ); + HWCFG( m_bSupportsVertexTextures ); + HWCFG( m_ZBiasAndSlopeScaledDepthBiasSupported ); + HWCFG( m_SupportsMipmapping ); + HWCFG( m_SupportsOverbright ); + HWCFG( m_SupportsCubeMaps ); + HWCFG( m_SupportsHardwareLighting ); + HWCFG( m_SupportsMipmappedCubemaps ); + HWCFG( m_SupportsNonPow2Textures ); + HWCFG( m_PreferDynamicTextures ); + HWCFG( m_HasProjectedBumpEnv ); + HWCFG( m_SupportsSRGB ); + HWCFG( m_bSupportsSpheremapping ); + HWCFG( m_UseFastClipping ); + HWCFG( m_bNeedsATICentroidHack ); + HWCFG( m_bDisableShaderOptimizations ); + HWCFG( m_bColorOnSecondStream ); + HWCFG( m_bSupportsStreamOffset ); + HWCFG( m_bFogColorSpecifiedInLinearSpace ); + HWCFG( m_bFogColorAlwaysLinearSpace ); + HWCFG( m_bSupportsAlphaToCoverage ); + HWCFG( m_bSupportsShadowDepthTextures ); + HWCFG( m_bSupportsFetch4 ); + HWCFG( m_bSoftwareVertexProcessing ); + HWCFG( m_bScissorSupported ); + HWCFG( m_bSupportsFloat32RenderTargets ); + HWCFG( m_bSupportsBorderColor ); + HWCFG( m_bDX10Card ); + HWCFG( m_bDX10Blending ); + HWCFG( m_bSupportsStaticControlFlow ); + HWCFG( m_FakeSRGBWrite ); + HWCFG( m_CanDoSRGBReadFromRTs ); + HWCFG( m_bSupportsGLMixedSizeTargets ); + HWCFG( m_bCanStretchRectFromTextures ); + + HWCFG( m_MaxHDRType ); +#undef HWCFG +} + +CHardwareConfig::CHardwareConfig() +{ + memset( &m_Caps, 0, sizeof( HardwareCaps_t ) ); + memset( &m_ActualCaps, 0, sizeof( HardwareCaps_t ) ); + memset( &m_UnOverriddenCaps, 0, sizeof( HardwareCaps_t ) ); + +#ifdef POSIX + GLMPRINTF((" CHardwareConfig::CHardwareConfig setting m_bHDREnabled to false on %8x", this )); +#endif + + m_bHDREnabled = false; + + // FIXME: This is kind of a hack to deal with DX8 worldcraft startup. + // We can at least have this much texture + m_Caps.m_MaxTextureWidth = m_Caps.m_MaxTextureHeight = m_Caps.m_MaxTextureDepth = 256; +} + + +//----------------------------------------------------------------------------- + +bool CHardwareConfig::GetHDREnabled( void ) const +{ +// printf("\n CHardwareConfig::GetHDREnabled returning m_bHDREnabled value of %s on %8x", m_bHDREnabled?"true":"false", this ); + return m_bHDREnabled; +} + +void CHardwareConfig::SetHDREnabled( bool bEnable ) +{ +// printf("\n CHardwareConfig::SetHDREnabled setting m_bHDREnabled to value of %s on %8x", bEnable?"true":"false", this ); + m_bHDREnabled = bEnable; +} + + +//----------------------------------------------------------------------------- +// Gets the recommended configuration associated with a particular dx level +//----------------------------------------------------------------------------- +void CHardwareConfig::ForceCapsToDXLevel( HardwareCaps_t *pCaps, int nDxLevel, const HardwareCaps_t &actualCaps ) +{ + if ( !IsPC() || nDxLevel >= 100 ) + return; + + pCaps->m_nDXSupportLevel = nDxLevel; + switch( nDxLevel ) + { + case 60: + // NOTE: Prior to dx9, numsamplers = num texture stages + pCaps->m_NumTextureStages = min( 2, actualCaps.m_NumTextureStages ); + pCaps->m_NumSamplers = pCaps->m_NumTextureStages; + pCaps->m_SupportsVertexShaders = false; + pCaps->m_SupportsVertexShaders_2_0 = false; + pCaps->m_SupportsPixelShaders = false; + pCaps->m_SupportsPixelShaders_1_4 = false; + pCaps->m_SupportsPixelShaders_2_0 = false; + pCaps->m_SupportsPixelShaders_2_b = false; + pCaps->m_SupportsShaderModel_3_0 = false; + pCaps->m_bSupportsStaticControlFlow = false; + pCaps->m_SupportsCompressedTextures = COMPRESSED_TEXTURES_OFF; + pCaps->m_SupportsCompressedVertices = VERTEX_COMPRESSION_NONE; + pCaps->m_bSupportsAnisotropicFiltering = false; + pCaps->m_bSupportsMagAnisotropicFiltering = false; + pCaps->m_nMaxAnisotropy = 1; + pCaps->m_MaxTextureWidth = max( 256, pCaps->m_MaxTextureWidth ); + pCaps->m_MaxTextureHeight = max( 256, pCaps->m_MaxTextureHeight ); + pCaps->m_MaxTextureDepth = max( 256, pCaps->m_MaxTextureDepth ); + // m_MaxTextureAspectRatio; + // int m_MaxPrimitiveCount; + pCaps->m_ZBiasAndSlopeScaledDepthBiasSupported = false; + // pCaps->m_SupportsMipmapping = + // bool m_SupportsOverbright; + pCaps->m_SupportsCubeMaps = false; + pCaps->m_NumPixelShaderConstants = 0; + pCaps->m_NumBooleanPixelShaderConstants = 0; + pCaps->m_NumIntegerPixelShaderConstants = 0; + pCaps->m_NumVertexShaderConstants = 0; + pCaps->m_NumBooleanVertexShaderConstants = 0; + pCaps->m_NumIntegerVertexShaderConstants = 0; + pCaps->m_NumBooleanPixelShaderConstants = 0; + pCaps->m_NumIntegerPixelShaderConstants = 0; + pCaps->m_TextureMemorySize = 32 * 1024 * 1024; + pCaps->m_MaxNumLights = 0; + pCaps->m_SupportsHardwareLighting = 0; + pCaps->m_MaxBlendMatrices = 0; + pCaps->m_MaxBlendMatrixIndices = 0; + pCaps->m_MaxVertexShaderBlendMatrices = 0; + pCaps->m_SupportsMipmappedCubemaps = false; + pCaps->m_SupportsNonPow2Textures = false; + // pCaps->m_DXSupportLevel = 60; + pCaps->m_PreferDynamicTextures = false; + pCaps->m_HasProjectedBumpEnv = false; + pCaps->m_MaxUserClipPlanes = 0; + pCaps->m_SupportsSRGB = false; + pCaps->m_FakeSRGBWrite = false; + pCaps->m_CanDoSRGBReadFromRTs = true; + pCaps->m_bSupportsGLMixedSizeTargets = false; + pCaps->m_HDRType = HDR_TYPE_NONE; + // pCaps->m_bSupportsSpheremapping = true; + pCaps->m_UseFastClipping = true; + pCaps->m_bNeedsATICentroidHack = false; + pCaps->m_bColorOnSecondStream = false; + pCaps->m_bSupportsStreamOffset = false; + pCaps->m_bFogColorSpecifiedInLinearSpace = false; + pCaps->m_bFogColorAlwaysLinearSpace = false; + pCaps->m_bSupportsAlphaToCoverage = false; + pCaps->m_bSupportsShadowDepthTextures = false; + pCaps->m_bSupportsFetch4 = false; + pCaps->m_bSupportsBorderColor = false; + // m_bSoftwareVertexProcessing + pCaps->m_nVertexTextureCount = 0; + pCaps->m_nMaxVertexTextureDimension = 0; + pCaps->m_bSupportsVertexTextures = false; + pCaps->m_nMaxViewports = 1; + // m_bScissorSupported + pCaps->m_bSupportsFloat32RenderTargets = false; + // ImageFormat m_ShadowDepthTextureFormat; + // ImageFormat m_NullTextureFormat; + // m_AlphaToCoverageState; + // m_AlphaToCoverageEnableValue; + // m_AlphaToCoverageDisableValue; + // m_flMinGammaControlPoint + // m_flMaxGammaControlPoint + // m_nGammaControlPointCount + pCaps->m_MaxVertexShader30InstructionSlots = 0; + pCaps->m_MaxPixelShader30InstructionSlots = 0; + pCaps->m_bCanStretchRectFromTextures = false; + break; + + case 70: + // NOTE: Prior to dx9, numsamplers = num texture stages + pCaps->m_NumTextureStages = min( 2, actualCaps.m_NumTextureStages ); + pCaps->m_NumSamplers = pCaps->m_NumTextureStages; + pCaps->m_SupportsVertexShaders = false; + pCaps->m_SupportsVertexShaders_2_0 = false; + pCaps->m_SupportsPixelShaders = false; + pCaps->m_SupportsPixelShaders_1_4 = false; + pCaps->m_SupportsPixelShaders_2_0 = false; + pCaps->m_SupportsPixelShaders_2_b = false; + pCaps->m_SupportsShaderModel_3_0 = false; + pCaps->m_bSupportsStaticControlFlow = false; + // pCaps->m_SupportsCompressedTextures = true; + pCaps->m_SupportsCompressedVertices = VERTEX_COMPRESSION_NONE; + pCaps->m_bSupportsAnisotropicFiltering = false; + pCaps->m_bSupportsMagAnisotropicFiltering = false; + pCaps->m_nMaxAnisotropy = 1; + // pCaps->m_MaxTextureWidth = max( 256, pCaps->m_MaxTextureWidth ); + // pCaps->m_MaxTextureHeight = max( 256, pCaps->m_MaxTextureHeight ); +// pCaps->m_MaxTextureDepth = max( 256, pCaps->m_MaxTextureDepth ); + // m_MaxTextureAspectRatio; + // int m_MaxPrimitiveCount; + pCaps->m_ZBiasAndSlopeScaledDepthBiasSupported = false; + // pCaps->m_SupportsMipmapping = + // bool m_SupportsOverbright; + // pCaps->m_SupportsCubeMaps = false; + pCaps->m_NumPixelShaderConstants = 0; + pCaps->m_NumBooleanPixelShaderConstants = 0; + pCaps->m_NumIntegerPixelShaderConstants = 0; + pCaps->m_NumBooleanPixelShaderConstants = 0; + pCaps->m_NumIntegerPixelShaderConstants = 0; + pCaps->m_NumVertexShaderConstants = 0; + pCaps->m_NumBooleanVertexShaderConstants = 0; + pCaps->m_NumIntegerVertexShaderConstants = 0; + pCaps->m_TextureMemorySize = 32 * 1024 * 1024; + pCaps->m_MaxNumLights = 2; + pCaps->m_SupportsHardwareLighting = 1; + pCaps->m_MaxBlendMatrices = 0; + pCaps->m_MaxBlendMatrixIndices = 0; + pCaps->m_MaxVertexShaderBlendMatrices = 0; + pCaps->m_SupportsMipmappedCubemaps = false; + pCaps->m_SupportsNonPow2Textures = false; + pCaps->m_nDXSupportLevel = 70; + pCaps->m_PreferDynamicTextures = false; + pCaps->m_HasProjectedBumpEnv = false; + pCaps->m_MaxUserClipPlanes = 0; + pCaps->m_SupportsSRGB = false; + pCaps->m_FakeSRGBWrite = false; + pCaps->m_CanDoSRGBReadFromRTs = true; + pCaps->m_bSupportsGLMixedSizeTargets = false; + pCaps->m_HDRType = HDR_TYPE_NONE; + // pCaps->m_bSupportsSpheremapping = true; + pCaps->m_UseFastClipping = true; + pCaps->m_bNeedsATICentroidHack = false; + // pCaps->m_bColorOnSecondStream = false; // dont' force this! + pCaps->m_bSupportsStreamOffset = false; + pCaps->m_bFogColorSpecifiedInLinearSpace = false; + pCaps->m_bFogColorAlwaysLinearSpace = false; + pCaps->m_bSupportsAlphaToCoverage = false; + pCaps->m_bSupportsShadowDepthTextures = false; + pCaps->m_bSupportsFetch4 = false; + pCaps->m_bSupportsBorderColor = false; + // m_bSoftwareVertexProcessing + pCaps->m_nVertexTextureCount = 0; + pCaps->m_nMaxVertexTextureDimension = 0; + pCaps->m_bSupportsVertexTextures = false; + pCaps->m_nMaxViewports = 1; + // m_bScissorSupported + pCaps->m_bSupportsFloat32RenderTargets = false; + pCaps->m_bDX10Card = false; + pCaps->m_bDX10Blending = false; + pCaps->m_bCanStretchRectFromTextures = false; + break; + + case 80: + // NOTE: Prior to dx9, numsamplers = num texture stages + // We clamp num texture stages to 2, though, since we never use + // fixed-function shaders with more than 2 texture stages + pCaps->m_NumTextureStages = min( 2, actualCaps.m_NumTextureStages ); + pCaps->m_NumSamplers = min( 4, actualCaps.m_NumTextureStages ); + // pCaps->m_SupportsVertexShaders = true; + pCaps->m_SupportsVertexShaders_2_0 = false; + // pCaps->m_SupportsPixelShaders = false; + pCaps->m_SupportsPixelShaders_1_4 = false; + pCaps->m_SupportsPixelShaders_2_0 = false; + pCaps->m_SupportsPixelShaders_2_b = false; + pCaps->m_SupportsShaderModel_3_0 = false; + pCaps->m_bSupportsStaticControlFlow = false; + // pCaps->m_SupportsCompressedTextures = true; + pCaps->m_SupportsCompressedVertices = VERTEX_COMPRESSION_NONE; + // pCaps->m_bSupportsAnisotropicFiltering = false; + // pCaps->m_bSupportsMagAnisotropicFiltering = false; + // pCaps->m_nMaxAnisotropy = 1; + // pCaps->m_MaxTextureWidth = max( 256, pCaps->m_MaxTextureWidth ); + // pCaps->m_MaxTextureHeight = max( 256, pCaps->m_MaxTextureHeight ); + // pCaps->m_MaxTextureDepth = max( 256, pCaps->m_MaxTextureDepth ); + // m_MaxTextureAspectRatio; + // int m_MaxPrimitiveCount; + // pCaps->m_ZBiasAndSlopeScaledDepthBiasSupported = false; + // pCaps->m_SupportsMipmapping = + // bool m_SupportsOverbright; + // pCaps->m_SupportsCubeMaps = false; + pCaps->m_NumPixelShaderConstants = 8; + pCaps->m_NumVertexShaderConstants = min( 96, pCaps->m_NumVertexShaderConstants ); + pCaps->m_NumBooleanVertexShaderConstants = 0; + pCaps->m_NumIntegerVertexShaderConstants = 0; + pCaps->m_NumBooleanPixelShaderConstants = 0; + pCaps->m_NumIntegerPixelShaderConstants = 0; + // pCaps->m_TextureMemorySize = 32 * 1024 * 1024; + // pCaps->m_MaxNumLights = 0; + // pCaps->m_SupportsHardwareLighting = 0; + // pCaps->m_MaxBlendMatrices = 0; + // pCaps->m_MaxBlendMatrixIndices = 0; + pCaps->m_MaxVertexShaderBlendMatrices = min( 16, pCaps->m_MaxVertexShaderBlendMatrices ); + // pCaps->m_SupportsMipmappedCubemaps = false; + // pCaps->m_SupportsNonPow2Textures = false; + pCaps->m_nDXSupportLevel = 80; + // pCaps->m_PreferDynamicTextures = false; + // pCaps->m_HasProjectedBumpEnv = false; + // pCaps->m_MaxUserClipPlanes = 0; + pCaps->m_bSupportsGLMixedSizeTargets = false; + pCaps->m_HDRType = HDR_TYPE_NONE; + // pCaps->m_bSupportsSpheremapping = true; + // pCaps->m_UseFastClipping = true; + // pCaps->m_bNeedsATICentroidHack = false; + // pCaps->m_bColorOnSecondStream = false; + pCaps->m_bSupportsStreamOffset = false; + pCaps->m_bFogColorSpecifiedInLinearSpace = false; + pCaps->m_bFogColorAlwaysLinearSpace = false; + pCaps->m_bSupportsAlphaToCoverage = false; + pCaps->m_bSupportsShadowDepthTextures = false; + pCaps->m_bSupportsFetch4 = false; + // m_bSoftwareVertexProcessing + pCaps->m_nVertexTextureCount = 0; + pCaps->m_nMaxVertexTextureDimension = 0; + pCaps->m_bSupportsVertexTextures = false; + pCaps->m_MaxNumLights = 2; + pCaps->m_nMaxViewports = 1; + // m_bScissorSupported + pCaps->m_SupportsSRGB = false; + pCaps->m_FakeSRGBWrite = false; + pCaps->m_CanDoSRGBReadFromRTs = true; + pCaps->m_bSupportsGLMixedSizeTargets = false; + pCaps->m_bSupportsFetch4 = false; + pCaps->m_bSupportsBorderColor = false; + pCaps->m_bSupportsFloat32RenderTargets = false; + // ImageFormat m_ShadowDepthTextureFormat; + // ImageFormat m_NullTextureFormat; + // m_AlphaToCoverageState; + // m_AlphaToCoverageEnableValue; + // m_AlphaToCoverageDisableValue; + // m_flMinGammaControlPoint + // m_flMaxGammaControlPoint + // m_nGammaControlPointCount + pCaps->m_MaxVertexShader30InstructionSlots = 0; + pCaps->m_MaxPixelShader30InstructionSlots = 0; + pCaps->m_bDX10Card = false; + pCaps->m_bDX10Blending = false; + pCaps->m_bCanStretchRectFromTextures = false; + break; + + case 81: + // NOTE: Prior to dx9, numsamplers = num texture stages + // We clamp num texture stages to 2, though, since we never use + // fixed-function shaders with more than 2 texture stages + pCaps->m_NumTextureStages = min( 2, actualCaps.m_NumTextureStages ); + pCaps->m_NumSamplers = min( 6, actualCaps.m_NumTextureStages ); + // pCaps->m_SupportsVertexShaders = true; + pCaps->m_SupportsVertexShaders_2_0 = false; + // pCaps->m_SupportsPixelShaders = false; + pCaps->m_SupportsPixelShaders_1_4 = true; + pCaps->m_SupportsPixelShaders_2_0 = false; + pCaps->m_SupportsPixelShaders_2_b = false; + pCaps->m_SupportsShaderModel_3_0 = false; + pCaps->m_bSupportsStaticControlFlow = false; + // pCaps->m_SupportsCompressedTextures = true; + pCaps->m_SupportsCompressedVertices = VERTEX_COMPRESSION_NONE; + // pCaps->m_bSupportsAnisotropicFiltering = false; + // pCaps->m_bSupportsMagAnisotropicFiltering = false; + // pCaps->m_nMaxAnisotropy = 1; + // pCaps->m_MaxTextureWidth = max( 256, pCaps->m_MaxTextureWidth ); + // pCaps->m_MaxTextureHeight = max( 256, pCaps->m_MaxTextureHeight ); + // pCaps->m_MaxTextureDepth = max( 256, pCaps->m_MaxTextureDepth ); + // m_MaxTextureAspectRatio; + // int m_MaxPrimitiveCount; + // pCaps->m_ZBiasAndSlopeScaledDepthBiasSupported = false; + // pCaps->m_SupportsMipmapping = + // bool m_SupportsOverbright; + // pCaps->m_SupportsCubeMaps = false; + pCaps->m_NumPixelShaderConstants = 8; + pCaps->m_NumVertexShaderConstants = min( 96, pCaps->m_NumVertexShaderConstants ); + pCaps->m_NumBooleanVertexShaderConstants = 0; + pCaps->m_NumIntegerVertexShaderConstants = 0; + pCaps->m_NumBooleanPixelShaderConstants = 0; + pCaps->m_NumIntegerPixelShaderConstants = 0; + // pCaps->m_TextureMemorySize = 32 * 1024 * 1024; + pCaps->m_MaxNumLights = 2; + // pCaps->m_SupportsHardwareLighting = 0; + // pCaps->m_MaxBlendMatrices = 0; + // pCaps->m_MaxBlendMatrixIndices = 0; + pCaps->m_MaxVertexShaderBlendMatrices = min( 16, pCaps->m_MaxVertexShaderBlendMatrices ); + // pCaps->m_SupportsMipmappedCubemaps = false; + // pCaps->m_SupportsNonPow2Textures = false; + pCaps->m_nDXSupportLevel = 81; + // pCaps->m_PreferDynamicTextures = false; + // pCaps->m_HasProjectedBumpEnv = false; + // pCaps->m_MaxUserClipPlanes = 0; + pCaps->m_SupportsSRGB = false; + pCaps->m_FakeSRGBWrite = false; + pCaps->m_CanDoSRGBReadFromRTs = true; + pCaps->m_bSupportsGLMixedSizeTargets = false; + pCaps->m_HDRType = HDR_TYPE_NONE; + // pCaps->m_bSupportsSpheremapping = true; + // pCaps->m_UseFastClipping = true; + // pCaps->m_bNeedsATICentroidHack = false; + // pCaps->m_bColorOnSecondStream = false; + pCaps->m_bSupportsStreamOffset = false; + pCaps->m_bFogColorSpecifiedInLinearSpace = false; + pCaps->m_bFogColorAlwaysLinearSpace = false; + pCaps->m_bSupportsAlphaToCoverage = false; + pCaps->m_bSupportsShadowDepthTextures = false; + pCaps->m_bSupportsFetch4 = false; + pCaps->m_bSupportsBorderColor = false; + // m_bSoftwareVertexProcessing + pCaps->m_nVertexTextureCount = 0; + pCaps->m_nMaxVertexTextureDimension = 0; + pCaps->m_bSupportsVertexTextures = false; + pCaps->m_nMaxViewports = 1; + // m_bScissorSupported + pCaps->m_bSupportsFloat32RenderTargets = false; + // ImageFormat m_ShadowDepthTextureFormat; + // ImageFormat m_NullTextureFormat; + // m_AlphaToCoverageState; + // m_AlphaToCoverageEnableValue; + // m_AlphaToCoverageDisableValue; + // m_flMinGammaControlPoint + // m_flMaxGammaControlPoint + // m_nGammaControlPointCount + pCaps->m_MaxVertexShader30InstructionSlots = 0; + pCaps->m_MaxPixelShader30InstructionSlots = 0; + pCaps->m_bDX10Card = false; + pCaps->m_bDX10Blending = false; + pCaps->m_bCanStretchRectFromTextures = false; + break; + + case 90: + pCaps->m_nVertexTextureCount = 0; + pCaps->m_nMaxVertexTextureDimension = 0; + pCaps->m_bSupportsVertexTextures = false; + pCaps->m_bSupportsStreamOffset = true; + pCaps->m_bSupportsGLMixedSizeTargets = true; + + if ( IsOpenGL() ) + { + //FIXME this is way too complicated, we should just check the caps bit from GLM + + pCaps->m_bSupportsStaticControlFlow = false; + + if (1) //(CommandLine()->FindParm("-glslmode")) + { + // rbarris 03Feb10: this is now hardwired because we are defaulting GLSL mode "on". + // so this will mean that the engine will always ask for user clip planes. + // this will misbehave under ARB mode, since ARB shaders won't respect that state. + // it's difficult to make this fluid without teaching the engine about a cap that could change during run. + + pCaps->m_MaxUserClipPlanes = 2; + pCaps->m_UseFastClipping = false; + } + else + { + pCaps->m_MaxUserClipPlanes = 0; + pCaps->m_UseFastClipping = true; + } + + pCaps->m_MaxNumLights = 2; + } + else + { + pCaps->m_bSupportsStaticControlFlow = true; + pCaps->m_MaxNumLights = pCaps->m_SupportsPixelShaders_2_b ? 4 : 2; // 2b gets four lights, 2.0 gets two... + } + + pCaps->m_bSupportsBorderColor = false; + pCaps->m_nMaxViewports = 1; + pCaps->m_NumPixelShaderConstants = 32; + pCaps->m_nMaxVertexTextureDimension = 0; + pCaps->m_MaxVertexShader30InstructionSlots = 0; + pCaps->m_MaxPixelShader30InstructionSlots = 0; + pCaps->m_bCanStretchRectFromTextures = false; + break; + + case 92: + pCaps->m_nVertexTextureCount = 0; + pCaps->m_nMaxVertexTextureDimension = 0; + pCaps->m_bSupportsVertexTextures = false; + pCaps->m_bSupportsBorderColor = false; + + // 2b gets four lights, 2.0 gets two... + pCaps->m_SupportsShaderModel_3_0 = false; + if ( IsOpenGL() ) + { + if ( IsOSX() ) + { + pCaps->m_bSupportsStaticControlFlow = CommandLine()->CheckParm( "-glslcontrolflow" ) != NULL; + } + else + { + pCaps->m_bSupportsStaticControlFlow = !CommandLine()->CheckParm( "-noglslcontrolflow" ); + } + + pCaps->m_MaxUserClipPlanes = 2; + pCaps->m_UseFastClipping = false; + pCaps->m_MaxNumLights = pCaps->m_bSupportsStaticControlFlow ? MAX_NUM_LIGHTS : ( MAX_NUM_LIGHTS - 2 ); + } + else + { + pCaps->m_MaxNumLights = MAX_NUM_LIGHTS; + } + + pCaps->m_nMaxViewports = 1; + pCaps->m_NumPixelShaderConstants = 32; + pCaps->m_nMaxVertexTextureDimension = 0; + pCaps->m_bDX10Card = false; + pCaps->m_bDX10Blending = false; + pCaps->m_MaxVertexShader30InstructionSlots = 0; + pCaps->m_MaxPixelShader30InstructionSlots = 0; + pCaps->m_bCanStretchRectFromTextures = false; + break; + + case 95: + pCaps->m_bSupportsStreamOffset = true; + pCaps->m_bSupportsStaticControlFlow = true; + pCaps->m_bDX10Card = false; + pCaps->m_bDX10Blending = false; + pCaps->m_MaxNumLights = MAX_NUM_LIGHTS; + pCaps->m_nMaxViewports = 1; + pCaps->m_bSupportsBorderColor = false; + pCaps->m_bCanStretchRectFromTextures = false; + break; + + case 100: + break; + + default: + Assert( 0 ); + break; + } +} + + +//----------------------------------------------------------------------------- +// Sets up the hardware caps given the specified DX level +//----------------------------------------------------------------------------- +void CHardwareConfig::SetupHardwareCaps( int nDXLevel, const HardwareCaps_t &actualCaps ) +{ + Assert( nDXLevel != 0 ); + + memcpy( &m_Caps, &actualCaps, sizeof(HardwareCaps_t) ); + memcpy( &m_UnOverriddenCaps, &actualCaps, sizeof(HardwareCaps_t) ); + + // Don't bother with fallbacks for DX10 or consoles +#ifdef DX_TO_GL_ABSTRACTION + if ( nDXLevel >= 100 ) +#else + if ( !( IsPC() || IsPosix() ) || ( nDXLevel >= 100 ) ) +#endif + return; + + // Slam the support level to what we were requested + m_Caps.m_nDXSupportLevel = nDXLevel; + if ( m_Caps.m_nDXSupportLevel != m_Caps.m_nMaxDXSupportLevel || CommandLine()->ParmValue( "-maxdxlevel", 0 ) > 0 ) + { + // We're falling back to some other dx level + ForceCapsToDXLevel( &m_Caps, m_Caps.m_nDXSupportLevel, m_ActualCaps ); + } + + // Clamp num texture stages to 2, since it's only used for fixed function + m_Caps.m_NumTextureStages = min( 2, m_Caps.m_NumTextureStages ); + + // Read dxsupport.cfg which has config overrides for particular cards. + g_pShaderDeviceMgr->ReadHardwareCaps( m_Caps, m_Caps.m_nDXSupportLevel ); + + // This is the spot to validate read in caps versus actual caps. + if ( m_Caps.m_MaxUserClipPlanes > m_ActualCaps.m_MaxUserClipPlanes ) + { + m_Caps.m_MaxUserClipPlanes = m_ActualCaps.m_MaxUserClipPlanes; + } + if ( m_Caps.m_MaxUserClipPlanes == 0 ) + { + m_Caps.m_UseFastClipping = true; + } + + if ( IsOpenGL() ) + { + m_Caps.m_MaxNumLights = MIN( m_Caps.m_MaxNumLights, ( m_Caps.m_bSupportsStaticControlFlow && m_Caps.m_SupportsPixelShaders_2_b ) ? MAX_NUM_LIGHTS : ( MAX_NUM_LIGHTS - 2 ) ); + m_Caps.m_bSupportsShadowDepthTextures = true; + } + else // not POSIX or emulated + { + // 2b supports more lights than just 2.0 + if ( m_Caps.m_SupportsPixelShaders_2_b ) + { + m_Caps.m_MaxNumLights = MIN( m_Caps.m_MaxNumLights, MAX_NUM_LIGHTS ); + } + else + { + m_Caps.m_MaxNumLights = MIN( m_Caps.m_MaxNumLights, MAX_NUM_LIGHTS - 2 ); + } + } + + m_Caps.m_MaxNumLights = min( m_Caps.m_MaxNumLights, (int)MAX_NUM_LIGHTS ); + + memcpy( &m_UnOverriddenCaps, &m_Caps, sizeof(HardwareCaps_t) ); +} + + +//----------------------------------------------------------------------------- +// Sets up the hardware caps given the specified DX level +//----------------------------------------------------------------------------- +void CHardwareConfig::SetupHardwareCaps( const ShaderDeviceInfo_t& mode, const HardwareCaps_t &actualCaps ) +{ + memcpy( &m_ActualCaps, &actualCaps, sizeof(HardwareCaps_t) ); + SetupHardwareCaps( mode.m_nDXLevel, actualCaps ); +} + + +void CHardwareConfig::OverrideStreamOffsetSupport( bool bOverrideEnabled, bool bEnableSupport ) +{ + if ( bOverrideEnabled ) + { + m_Caps.m_bSupportsStreamOffset = bEnableSupport; + if ( !m_ActualCaps.m_bSupportsStreamOffset ) + { + m_Caps.m_bSupportsStreamOffset = false; + } + } + else + { + // Go back to default + m_Caps.m_bSupportsStreamOffset = m_UnOverriddenCaps.m_bSupportsStreamOffset; + } +} + + +//----------------------------------------------------------------------------- +// Implementation of IMaterialSystemHardwareConfig +//----------------------------------------------------------------------------- +bool CHardwareConfig::HasDestAlphaBuffer() const +{ + if ( !g_pShaderDevice ) + return false; + return (g_pShaderDevice->GetBackBufferFormat() == IMAGE_FORMAT_BGRA8888); +} + +bool CHardwareConfig::HasStencilBuffer() const +{ + return StencilBufferBits() > 0; +} + +int CHardwareConfig::GetFrameBufferColorDepth() const +{ + if ( !g_pShaderDevice ) + return 0; + return ShaderUtil()->ImageFormatInfo( g_pShaderDevice->GetBackBufferFormat() ).m_NumBytes; +} + +int CHardwareConfig::GetSamplerCount() const +{ + return m_Caps.m_NumSamplers; +} + +bool CHardwareConfig::HasSetDeviceGammaRamp() const +{ + return m_Caps.m_HasSetDeviceGammaRamp; +} + +bool CHardwareConfig::SupportsCompressedTextures() const +{ + Assert( m_Caps.m_SupportsCompressedTextures != COMPRESSED_TEXTURES_NOT_INITIALIZED ); + return m_Caps.m_SupportsCompressedTextures == COMPRESSED_TEXTURES_ON; +} + +VertexCompressionType_t CHardwareConfig::SupportsCompressedVertices() const +{ + return m_Caps.m_SupportsCompressedVertices; +} + +bool CHardwareConfig::SupportsBorderColor() const +{ + return m_Caps.m_bSupportsBorderColor; +} + +bool CHardwareConfig::SupportsFetch4() const +{ + return m_Caps.m_bSupportsFetch4; +} + +bool CHardwareConfig::CanStretchRectFromTextures() const +{ + return m_Caps.m_bCanStretchRectFromTextures; +} + +bool CHardwareConfig::SupportsVertexAndPixelShaders() const +{ + if ( (ShaderUtil()->GetConfig().dxSupportLevel != 0) && (GetDXSupportLevel() < 80) ) + return false; + + return m_Caps.m_SupportsPixelShaders; +} + +bool CHardwareConfig::SupportsPixelShaders_1_4() const +{ + if ( (ShaderUtil()->GetConfig().dxSupportLevel != 0) && (GetDXSupportLevel() < 81) ) + return false; + + return m_Caps.m_SupportsPixelShaders_1_4; +} + +bool CHardwareConfig::SupportsPixelShaders_2_0() const +{ + if ( (ShaderUtil()->GetConfig().dxSupportLevel != 0) && (GetDXSupportLevel() < 90) ) + return false; + + return m_Caps.m_SupportsPixelShaders_2_0; +} + +bool CHardwareConfig::SupportsPixelShaders_2_b() const +{ + if ((ShaderUtil()->GetConfig().dxSupportLevel != 0) && + (GetDXSupportLevel() < 90)) + return false; + + return m_Caps.m_SupportsPixelShaders_2_b; +} + +bool CHardwareConfig::SupportsVertexShaders_2_0() const +{ + if ((ShaderUtil()->GetConfig().dxSupportLevel != 0) && + (GetDXSupportLevel() < 90)) + return false; + + return m_Caps.m_SupportsVertexShaders_2_0; +} + +bool CHardwareConfig::SupportsStaticControlFlow() const +{ + return m_Caps.m_bSupportsStaticControlFlow; +} + + +bool CHardwareConfig::SupportsShaderModel_3_0() const +{ + if ((ShaderUtil()->GetConfig().dxSupportLevel != 0) && + (GetDXSupportLevel() < 95)) + return false; + + return m_Caps.m_SupportsShaderModel_3_0; +} + +// If you change these, make the corresponding change in common_ps_fxc.h +#define NVIDIA_PCF_POISSON 0 +#define ATI_NOPCF 1 +#define ATI_NO_PCF_FETCH4 2 + +int CHardwareConfig::GetShadowFilterMode() const +{ + +#ifdef DX_TO_GL_ABSTRACTION + if ( !m_Caps.m_bSupportsShadowDepthTextures ) + return 0; +#else + if ( !m_Caps.m_bSupportsShadowDepthTextures || !ShaderUtil()->GetConfig().ShadowDepthTexture() ) + return 0; +#endif + + switch ( m_Caps.m_ShadowDepthTextureFormat ) + { + case IMAGE_FORMAT_NV_DST16: + case IMAGE_FORMAT_NV_DST24: + + return NVIDIA_PCF_POISSON; // NVIDIA hardware bilinear PCF + + case IMAGE_FORMAT_ATI_DST16: + case IMAGE_FORMAT_ATI_DST24: + + if ( m_Caps.m_bSupportsFetch4 ) + return ATI_NO_PCF_FETCH4; // ATI fetch4 depth texture sampling + + return ATI_NOPCF; // ATI vanilla depth texture sampling + +#if defined( _X360 ) + case IMAGE_FORMAT_X360_DST16: + case IMAGE_FORMAT_X360_DST24: + case IMAGE_FORMAT_X360_DST24F: + return 0; +#endif + + default: + return 0; + } + + return 0; +} + +static ConVar r_shader_srgb( "r_shader_srgb", "0", FCVAR_ALLOWED_IN_COMPETITIVE, "-1 = use hardware caps. 0 = use hardware srgb. 1 = use shader srgb(software lookup)" ); // -1=use caps 0=off 1=on + +int CHardwareConfig::NeedsShaderSRGBConversion() const +{ + if ( IsX360() ) + { + // 360 always now uses a permanent hw solution + return false; + } + + int cValue = r_shader_srgb.GetInt(); + switch( cValue ) + { + case 0: + return false; + + case 1: + return true; + + default: + return m_Caps.m_bDX10Blending; // !!! change to return false after portal deport built!!!!! + } +} + +bool CHardwareConfig::UsesSRGBCorrectBlending() const +{ + int cValue = r_shader_srgb.GetInt(); + return ( cValue == 0 ) && ( ( m_Caps.m_bDX10Blending ) || IsX360() ); +} + +static ConVar mat_disablehwmorph( "mat_disablehwmorph", "0", FCVAR_ALLOWED_IN_COMPETITIVE, "Disables HW morphing for particular mods" ); +bool CHardwareConfig::HasFastVertexTextures() const +{ + static int bEnableFastVertexTextures = -1; + static bool bDisableHWMorph = false; + if ( bEnableFastVertexTextures < 0 ) + { + bEnableFastVertexTextures = 1; + if ( CommandLine()->FindParm( "-disallowhwmorph" ) ) + { + bEnableFastVertexTextures = 0; + } + bDisableHWMorph = ( mat_disablehwmorph.GetInt() != 0 ); + } + + // JasonM - turned this off for Orange Box release... + return false; + +// return m_Caps.m_bDX10Card && ( GetDXSupportLevel() >= 95 ) && ( bEnableFastVertexTextures != 0 ) && ( !bDisableHWMorph ); +} + +int CHardwareConfig::MaxHWMorphBatchCount() const +{ + return ShaderUtil()->MaxHWMorphBatchCount(); +} + +int CHardwareConfig::MaximumAnisotropicLevel() const +{ + return m_Caps.m_nMaxAnisotropy; +} + +int CHardwareConfig::MaxTextureWidth() const +{ + return m_Caps.m_MaxTextureWidth; +} + +int CHardwareConfig::MaxTextureHeight() const +{ + return m_Caps.m_MaxTextureHeight; +} + +int CHardwareConfig::TextureMemorySize() const +{ + return m_Caps.m_TextureMemorySize; +} + +bool CHardwareConfig::SupportsOverbright() const +{ + return m_Caps.m_SupportsOverbright; +} + +bool CHardwareConfig::SupportsCubeMaps() const +{ + if ( (ShaderUtil()->GetConfig().dxSupportLevel > 0) && (GetDXSupportLevel() < 70) ) + return false; + + return m_Caps.m_SupportsCubeMaps; +} + +bool CHardwareConfig::SupportsMipmappedCubemaps() const +{ + if ( (ShaderUtil()->GetConfig().dxSupportLevel > 0) && (GetDXSupportLevel() < 70) ) + return false; + + return m_Caps.m_SupportsMipmappedCubemaps; +} + +bool CHardwareConfig::SupportsNonPow2Textures() const +{ + return m_Caps.m_SupportsNonPow2Textures; +} + +int CHardwareConfig::GetTextureStageCount() const +{ + return m_Caps.m_NumTextureStages; +} + +int CHardwareConfig::NumVertexShaderConstants() const +{ + return m_Caps.m_NumVertexShaderConstants; +} + +int CHardwareConfig::NumBooleanVertexShaderConstants() const +{ + return m_Caps.m_NumBooleanVertexShaderConstants; +} + +int CHardwareConfig::NumIntegerVertexShaderConstants() const +{ + return m_Caps.m_NumIntegerVertexShaderConstants; +} + +int CHardwareConfig::NumPixelShaderConstants() const +{ + return m_Caps.m_NumPixelShaderConstants; +} + +int CHardwareConfig::NumBooleanPixelShaderConstants() const +{ + return m_Caps.m_NumBooleanPixelShaderConstants; +} + +int CHardwareConfig::NumIntegerPixelShaderConstants() const +{ + return m_Caps.m_NumIntegerPixelShaderConstants; +} + +int CHardwareConfig::MaxNumLights() const +{ + return m_Caps.m_MaxNumLights; +} + +bool CHardwareConfig::SupportsHardwareLighting() const +{ + if ( (ShaderUtil()->GetConfig().dxSupportLevel > 0) && (GetDXSupportLevel() < 70) ) + return false; + + return m_Caps.m_SupportsHardwareLighting; +} + +int CHardwareConfig::MaxBlendMatrices() const +{ + if ( (ShaderUtil()->GetConfig().dxSupportLevel > 0) && (GetDXSupportLevel() < 70) ) + return 1; + + return m_Caps.m_MaxBlendMatrices; +} + +int CHardwareConfig::MaxBlendMatrixIndices() const +{ + if ( (ShaderUtil()->GetConfig().dxSupportLevel > 0) && (GetDXSupportLevel() < 70) ) + return 1; + + return m_Caps.m_MaxBlendMatrixIndices; +} + +int CHardwareConfig::MaxTextureAspectRatio() const +{ + return m_Caps.m_MaxTextureAspectRatio; +} + +int CHardwareConfig::MaxVertexShaderBlendMatrices() const +{ + if ( (ShaderUtil()->GetConfig().dxSupportLevel > 0) && (GetDXSupportLevel() < 70) ) + return 1; + + return m_Caps.m_MaxVertexShaderBlendMatrices; +} + +// Useful for testing fastclip on Windows +extern ConVar mat_fastclip; + +int CHardwareConfig::MaxUserClipPlanes() const +{ + if ( mat_fastclip.GetBool() ) + return 0; + + return m_Caps.m_MaxUserClipPlanes; +} + +bool CHardwareConfig::UseFastClipping() const +{ + // rbarris broke this up for easier view of outcome in debugger + bool fastclip = mat_fastclip.GetBool(); + + bool result = m_Caps.m_UseFastClipping || fastclip; + + return result; +} + +int CHardwareConfig::MaxTextureDepth() const +{ + return m_Caps.m_MaxTextureDepth; +} + +int CHardwareConfig::GetDXSupportLevel() const +{ + if ( ShaderUtil()->GetConfig().dxSupportLevel != 0 ) + { + return min( ShaderUtil()->GetConfig().dxSupportLevel, m_Caps.m_nDXSupportLevel ); + } + + return m_Caps.m_nDXSupportLevel; +} + +const char *CHardwareConfig::GetShaderDLLName() const +{ + return ( m_Caps.m_pShaderDLL && m_Caps.m_pShaderDLL[0] ) ? m_Caps.m_pShaderDLL : "DEFAULT"; +} + +bool CHardwareConfig::ReadPixelsFromFrontBuffer() const +{ + if ( IsX360() ) + { + // future proof safety, not allowing the front read path + return false; + } + + // GR - in DX 9.0a can blit from MSAA back buffer + return false; +} + +bool CHardwareConfig::PreferDynamicTextures() const +{ + if ( IsX360() ) + { + // future proof safety, not allowing these + return false; + } + + return m_Caps.m_PreferDynamicTextures; +} + +bool CHardwareConfig::SupportsHDR() const +{ + // This is a deprecated function. . use GetHDRType instead. For shipping HL2, this always being false is correct. + Assert( 0 ); + return false; +} + +bool CHardwareConfig::SupportsHDRMode( HDRType_t nHDRType ) const +{ + switch( nHDRType ) + { + case HDR_TYPE_NONE: + return true; + + case HDR_TYPE_INTEGER: + return ( m_Caps.m_MaxHDRType == HDR_TYPE_INTEGER ) || ( m_Caps.m_MaxHDRType == HDR_TYPE_FLOAT ); + + case HDR_TYPE_FLOAT: + return ( m_Caps.m_MaxHDRType == HDR_TYPE_FLOAT ); + + } + return false; + +} + +bool CHardwareConfig::HasProjectedBumpEnv() const +{ + return m_Caps.m_HasProjectedBumpEnv; +} + +bool CHardwareConfig::SupportsSpheremapping() const +{ + return m_Caps.m_bSupportsSpheremapping; +} + +bool CHardwareConfig::NeedsAAClamp() const +{ + return false; +} + +bool CHardwareConfig::NeedsATICentroidHack() const +{ + return m_Caps.m_bNeedsATICentroidHack; +} + +bool CHardwareConfig::SupportsColorOnSecondStream() const +{ + return m_Caps.m_bColorOnSecondStream; +} + +bool CHardwareConfig::SupportsStaticPlusDynamicLighting() const +{ + return GetDXSupportLevel() >= 80; +} + +bool CHardwareConfig::PreferReducedFillrate() const +{ + return ShaderUtil()->GetConfig().ReduceFillrate(); +} + +// This is the max dx support level supported by the card +int CHardwareConfig::GetMaxDXSupportLevel() const +{ + return m_ActualCaps.m_nMaxDXSupportLevel; +} + +bool CHardwareConfig::SpecifiesFogColorInLinearSpace() const +{ + return m_Caps.m_bFogColorSpecifiedInLinearSpace; +} + +bool CHardwareConfig::SupportsSRGB() const +{ + return m_Caps.m_SupportsSRGB; +} + +bool CHardwareConfig::FakeSRGBWrite() const +{ + return m_Caps.m_FakeSRGBWrite; +} + +bool CHardwareConfig::CanDoSRGBReadFromRTs() const +{ + return m_Caps.m_CanDoSRGBReadFromRTs; +} + +bool CHardwareConfig::SupportsGLMixedSizeTargets() const +{ + return m_Caps.m_bSupportsGLMixedSizeTargets; +} + +bool CHardwareConfig::IsAAEnabled() const +{ + return g_pShaderDevice ? g_pShaderDevice->IsAAEnabled() : false; +// bool bAntialiasing = ( m_PresentParameters.MultiSampleType != D3DMULTISAMPLE_NONE ); +// return bAntialiasing; +} + +int CHardwareConfig::GetVertexTextureCount() const +{ + return m_Caps.m_nVertexTextureCount; +} + +int CHardwareConfig::GetMaxVertexTextureDimension() const +{ + return m_Caps.m_nMaxVertexTextureDimension; +} + +HDRType_t CHardwareConfig::GetHDRType() const +{ + bool enabled = m_bHDREnabled; + int dxlev = GetDXSupportLevel(); + int dxsupp = dxlev >= 90; + HDRType_t caps_hdr = m_Caps.m_HDRType; + HDRType_t result = HDR_TYPE_NONE; + + //printf("\nCHardwareConfig::GetHDRType..."); + if (enabled) + { + //printf("-> enabled..."); + if (dxsupp) + { + //printf("-> supported..."); + result = caps_hdr; + } + } + + //printf("-> result is %d.\n", result); + return result; + +/* + if ( m_bHDREnabled && ( GetDXSupportLevel() >= 90 ) ) + return m_Caps.m_HDRType; + return HDR_TYPE_NONE; +*/ +} + +HDRType_t CHardwareConfig::GetHardwareHDRType() const +{ + return m_Caps.m_HDRType; +} + +bool CHardwareConfig::SupportsStreamOffset() const +{ + return ( (GetDXSupportLevel() >= 90) && m_Caps.m_bSupportsStreamOffset ); +} + +int CHardwareConfig::StencilBufferBits() const +{ + return g_pShaderDevice ? g_pShaderDevice->StencilBufferBits() : 0; +} + +int CHardwareConfig:: MaxViewports() const +{ + return m_Caps.m_nMaxViewports; +} + +int CHardwareConfig::GetActualSamplerCount() const +{ + return m_ActualCaps.m_NumSamplers; +} + +int CHardwareConfig::GetActualTextureStageCount() const +{ + return m_ActualCaps.m_NumTextureStages; +} + +const char *CHardwareConfig::GetHWSpecificShaderDLLName() const +{ + return m_Caps.m_pShaderDLL && m_Caps.m_pShaderDLL[0] ? m_Caps.m_pShaderDLL : NULL; +} + +bool CHardwareConfig::SupportsMipmapping() const +{ + return m_Caps.m_SupportsMipmapping; +} + +bool CHardwareConfig::ActuallySupportsPixelShaders_2_b() const +{ + return m_ActualCaps.m_SupportsPixelShaders_2_b; +} diff --git a/materialsystem/shaderapidx9/hardwareconfig.h b/materialsystem/shaderapidx9/hardwareconfig.h new file mode 100644 index 0000000..792a80e --- /dev/null +++ b/materialsystem/shaderapidx9/hardwareconfig.h @@ -0,0 +1,286 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +// +//===========================================================================// + +#ifndef HARDWARECONFIG_H +#define HARDWARECONFIG_H + +#ifdef _WIN32 +#pragma once +#endif + + +#include "materialsystem/imaterialsystemhardwareconfig.h" +#include "IHardwareConfigInternal.h" +#include "bitmap/imageformat.h" +#include "materialsystem/imaterialsystem.h" + + +//----------------------------------------------------------------------------- +// Forward declarations +//----------------------------------------------------------------------------- +struct ShaderDeviceInfo_t; + + +//----------------------------------------------------------------------------- +// Vendor IDs sometimes needed for vendor-specific code +//----------------------------------------------------------------------------- +#define VENDORID_NVIDIA 0x10DE +#define VENDORID_ATI 0x1002 +#define VENDORID_INTEL 0x8086 + +//----------------------------------------------------------------------------- +// ShaderAPI constants +//----------------------------------------------------------------------------- +enum +{ +#if defined( DX_TO_GL_ABSTRACTION ) + MAXUSERCLIPPLANES = 2, +#else + MAXUSERCLIPPLANES = 6, +#endif + MAX_NUM_LIGHTS = 4, + MAX_OUTPUTS = 3, +}; + + +//----------------------------------------------------------------------------- +// Hardware caps structures +//----------------------------------------------------------------------------- +enum CompressedTextureState_t +{ + COMPRESSED_TEXTURES_ON, + COMPRESSED_TEXTURES_OFF, + COMPRESSED_TEXTURES_NOT_INITIALIZED +}; + +struct HardwareCaps_t : public MaterialAdapterInfo_t +{ + // *****************************NOTE********************************************* + // If you change any members, make sure and reflect the changes in CHardwareConfig::ForceCapsToDXLevel for every dxlevel!!!!! + // If you change any members, make sure and reflect the changes in CHardwareConfig::ForceCapsToDXLevel for every dxlevel!!!!! + // If you change any members, make sure and reflect the changes in CHardwareConfig::ForceCapsToDXLevel for every dxlevel!!!!! + // If you change any members, make sure and reflect the changes in CHardwareConfig::ForceCapsToDXLevel for every dxlevel!!!!! + // If you change any members, make sure and reflect the changes in CHardwareConfig::ForceCapsToDXLevel for every dxlevel!!!!! + // *****************************NOTE********************************************* + // + // NOTE: Texture stages are an obsolete concept; used by fixed-function hardware + // Samplers are dx9+, indicating how many textures we can simultaneously bind + // In Dx8, samplers didn't exist and texture stages were used to indicate the + // number of simultaneously bound textures; we'll emulate that by slamming + // the number of samplers to == the number of texture stages. + CompressedTextureState_t m_SupportsCompressedTextures; + VertexCompressionType_t m_SupportsCompressedVertices; + int m_NumSamplers; + int m_NumTextureStages; + int m_nMaxAnisotropy; + int m_MaxTextureWidth; + int m_MaxTextureHeight; + int m_MaxTextureDepth; + int m_MaxTextureAspectRatio; + int m_MaxPrimitiveCount; + int m_NumPixelShaderConstants; + int m_NumBooleanPixelShaderConstants; + int m_NumIntegerPixelShaderConstants; + int m_NumVertexShaderConstants; + int m_NumBooleanVertexShaderConstants; + int m_NumIntegerVertexShaderConstants; + int m_TextureMemorySize; + int m_MaxNumLights; + int m_MaxBlendMatrices; + int m_MaxBlendMatrixIndices; + int m_MaxVertexShaderBlendMatrices; + int m_MaxUserClipPlanes; + HDRType_t m_HDRType; + char m_pShaderDLL[32]; + ImageFormat m_ShadowDepthTextureFormat; + ImageFormat m_NullTextureFormat; + int m_nVertexTextureCount; + int m_nMaxVertexTextureDimension; + unsigned long m_AlphaToCoverageState; // State to ping to toggle Alpha To Coverage (vendor-dependent) + unsigned long m_AlphaToCoverageEnableValue; // Value to set above state to turn on Alpha To Coverage (vendor-dependent) + unsigned long m_AlphaToCoverageDisableValue; // Value to set above state to turn off Alpha To Coverage (vendor-dependent) + int m_nMaxViewports; + float m_flMinGammaControlPoint; + float m_flMaxGammaControlPoint; + int m_nGammaControlPointCount; + int m_MaxVertexShader30InstructionSlots; + int m_MaxPixelShader30InstructionSlots; + int m_MaxSimultaneousRenderTargets; + + bool m_bDeviceOk : 1; + bool m_HasSetDeviceGammaRamp : 1; + bool m_SupportsVertexShaders : 1; + bool m_SupportsVertexShaders_2_0 : 1; + bool m_SupportsPixelShaders : 1; + bool m_SupportsPixelShaders_1_4 : 1; + bool m_SupportsPixelShaders_2_0 : 1; + bool m_SupportsPixelShaders_2_b : 1; + bool m_SupportsShaderModel_3_0 : 1; + bool m_bSupportsAnisotropicFiltering : 1; + bool m_bSupportsMagAnisotropicFiltering : 1; + bool m_bSupportsVertexTextures : 1; + bool m_ZBiasAndSlopeScaledDepthBiasSupported : 1; + bool m_SupportsMipmapping : 1; + bool m_SupportsOverbright : 1; + bool m_SupportsCubeMaps : 1; + bool m_SupportsHardwareLighting : 1; + bool m_SupportsMipmappedCubemaps : 1; + bool m_SupportsNonPow2Textures : 1; + bool m_PreferDynamicTextures : 1; + bool m_HasProjectedBumpEnv : 1; + bool m_SupportsSRGB : 1; // Means both read and write + bool m_bSupportsSpheremapping : 1; + bool m_UseFastClipping : 1; + bool m_bNeedsATICentroidHack : 1; + bool m_bDisableShaderOptimizations : 1; + bool m_bColorOnSecondStream : 1; + bool m_bSupportsStreamOffset : 1; + bool m_bFogColorSpecifiedInLinearSpace : 1; + bool m_bFogColorAlwaysLinearSpace : 1; + bool m_bSupportsAlphaToCoverage : 1; + bool m_bSupportsShadowDepthTextures : 1; + bool m_bSupportsFetch4 : 1; + bool m_bSoftwareVertexProcessing : 1; + bool m_bScissorSupported : 1; + bool m_bSupportsFloat32RenderTargets : 1; + bool m_bSupportsBorderColor : 1; + bool m_bDX10Card : 1; // Indicates DX10 part with performant vertex textures running DX9 path + bool m_bDX10Blending : 1; // Indicates DX10 part that does DX10 blending (but may not have performant vertex textures, such as Intel parts) + bool m_bSupportsStaticControlFlow : 1; // Useful on OpenGL, where we have a mix of support... + bool m_FakeSRGBWrite : 1; // Gotta do this on OpenGL. Mostly hidden, but some high level code needs to know + bool m_CanDoSRGBReadFromRTs : 1; // Gotta do this on OpenGL. Mostly hidden, but some high level code needs to know + bool m_bSupportsGLMixedSizeTargets : 1; // on OpenGL, are mixed size depth buffers supported - aka ARB_framebuffer_object + bool m_bCanStretchRectFromTextures : 1; // Does the device expose D3DDEVCAPS2_CAN_STRETCHRECT_FROM_TEXTURES (or is it >DX9?) + + HDRType_t m_MaxHDRType; +}; + + +//----------------------------------------------------------------------------- +// Contains the hardware configuration for the current device +//----------------------------------------------------------------------------- +class CHardwareConfig : public IHardwareConfigInternal +{ +public: + CHardwareConfig(); + + // Sets up the hardware caps given the specified DX level + void SetupHardwareCaps( const ShaderDeviceInfo_t& mode, const HardwareCaps_t &actualCaps ); + + // FIXME: This is for backward compat only.. don't use these + void SetupHardwareCaps( int nDXLevel, const HardwareCaps_t &actualCaps ); + HardwareCaps_t& ActualCapsForEdit() { return m_ActualCaps; } + HardwareCaps_t& CapsForEdit() { return m_Caps; } + + // Members of IMaterialSystemHardwareConfig + virtual bool HasDestAlphaBuffer() const; + virtual bool HasStencilBuffer() const; + virtual int GetFrameBufferColorDepth() const; + virtual int GetSamplerCount() const; + virtual bool HasSetDeviceGammaRamp() const; + virtual bool SupportsCompressedTextures() const; + virtual VertexCompressionType_t SupportsCompressedVertices() const; + virtual bool SupportsBorderColor() const; + virtual bool SupportsFetch4() const; + virtual bool CanStretchRectFromTextures() const; + virtual bool SupportsVertexAndPixelShaders() const; + virtual bool SupportsPixelShaders_1_4() const; + virtual bool SupportsPixelShaders_2_0() const; + virtual bool SupportsStaticControlFlow() const; + virtual bool SupportsVertexShaders_2_0() const; + virtual int MaximumAnisotropicLevel() const; + virtual int MaxTextureWidth() const; + virtual int MaxTextureHeight() const; + virtual int TextureMemorySize() const; + virtual bool SupportsOverbright() const; + virtual bool SupportsCubeMaps() const; + virtual bool SupportsMipmappedCubemaps() const; + virtual bool SupportsNonPow2Textures() const; + virtual int GetTextureStageCount() const; + virtual int NumVertexShaderConstants() const; + virtual int NumBooleanVertexShaderConstants() const; + virtual int NumIntegerVertexShaderConstants() const; + virtual int NumPixelShaderConstants() const; + virtual int NumBooleanPixelShaderConstants() const; + virtual int NumIntegerPixelShaderConstants() const; + virtual int MaxNumLights() const; + virtual bool SupportsHardwareLighting() const; + virtual int MaxBlendMatrices() const; + virtual int MaxBlendMatrixIndices() const; + virtual int MaxTextureAspectRatio() const; + virtual int MaxVertexShaderBlendMatrices() const; + virtual int MaxUserClipPlanes() const; + virtual bool UseFastClipping() const; + virtual int GetDXSupportLevel() const; + virtual const char *GetShaderDLLName() const; + virtual bool ReadPixelsFromFrontBuffer() const; + virtual bool PreferDynamicTextures() const; + virtual bool SupportsHDR() const; + virtual bool HasProjectedBumpEnv() const; + virtual bool SupportsSpheremapping() const; + virtual bool NeedsAAClamp() const; + virtual bool NeedsATICentroidHack() const; + virtual bool SupportsColorOnSecondStream() const; + virtual bool SupportsStaticPlusDynamicLighting() const; + virtual bool PreferReducedFillrate() const; + virtual int GetMaxDXSupportLevel() const; + virtual bool SpecifiesFogColorInLinearSpace() const; + virtual bool SupportsSRGB() const; + virtual bool FakeSRGBWrite() const; + virtual bool CanDoSRGBReadFromRTs() const; + virtual bool SupportsGLMixedSizeTargets() const; + virtual bool IsAAEnabled() const; + virtual int GetVertexTextureCount() const; + virtual int GetMaxVertexTextureDimension() const; + virtual int MaxTextureDepth() const; + virtual HDRType_t GetHDRType() const; + virtual HDRType_t GetHardwareHDRType() const; + virtual bool SupportsPixelShaders_2_b() const; + virtual bool SupportsShaderModel_3_0() const; + virtual bool SupportsStreamOffset() const; + virtual int StencilBufferBits() const; + virtual int MaxViewports() const; + virtual void OverrideStreamOffsetSupport( bool bOverrideEnabled, bool bEnableSupport ); + virtual int GetShadowFilterMode() const; + virtual int NeedsShaderSRGBConversion() const; + virtual bool UsesSRGBCorrectBlending() const; + virtual bool HasFastVertexTextures() const; + virtual int MaxHWMorphBatchCount() const; + + const char *GetHWSpecificShaderDLLName() const; + int GetActualSamplerCount() const; + int GetActualTextureStageCount() const; + bool SupportsMipmapping() const; + virtual bool ActuallySupportsPixelShaders_2_b() const; + + virtual bool SupportsHDRMode( HDRType_t nHDRMode ) const; + + const HardwareCaps_t& ActualCaps() const { return m_ActualCaps; } + const HardwareCaps_t& Caps() const { return m_Caps; } + virtual bool GetHDREnabled( void ) const; + virtual void SetHDREnabled( bool bEnable ); + +protected: + // Gets the recommended configuration associated with a particular dx level + void ForceCapsToDXLevel( HardwareCaps_t *pCaps, int nDxLevel, const HardwareCaps_t &actualCaps ); + + // Members related to capabilities + HardwareCaps_t m_ActualCaps; + HardwareCaps_t m_Caps; + HardwareCaps_t m_UnOverriddenCaps; + bool m_bHDREnabled; +}; + + +//----------------------------------------------------------------------------- +// Singleton hardware config +//----------------------------------------------------------------------------- +extern CHardwareConfig *g_pHardwareConfig; + + +#endif // HARDWARECONFIG_H diff --git a/materialsystem/shaderapidx9/imeshdx8.h b/materialsystem/shaderapidx9/imeshdx8.h new file mode 100644 index 0000000..96697a7 --- /dev/null +++ b/materialsystem/shaderapidx9/imeshdx8.h @@ -0,0 +1,98 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +// +//===========================================================================// + +#ifndef IMESHDX8_H +#define IMESHDX8_H + +#ifdef _WIN32 +#pragma once +#endif + + +#include "meshbase.h" +#include "shaderapi/ishaderapi.h" + + +abstract_class IMeshMgr +{ +public: + // Initialize, shutdown + virtual void Init() = 0; + virtual void Shutdown() = 0; + + // Task switch... + virtual void ReleaseBuffers() = 0; + virtual void RestoreBuffers() = 0; + + // Releases all dynamic vertex buffers + virtual void DestroyVertexBuffers() = 0; + + // Flushes the dynamic mesh. Should be called when state changes + virtual void Flush() = 0; + + // Discards the dynamic vertex and index buffer + virtual void DiscardVertexBuffers() = 0; + + // Creates, destroys static meshes + virtual IMesh* CreateStaticMesh( VertexFormat_t vertexFormat, const char *pTextureBudgetGroup, IMaterial *pMaterial = NULL ) = 0; + virtual void DestroyStaticMesh( IMesh* pMesh ) = 0; + + // Gets at the dynamic mesh + virtual IMesh* GetDynamicMesh( IMaterial* pMaterial, VertexFormat_t vertexFormat, int nHWSkinBoneCount, bool buffered = true, + IMesh* pVertexOverride = 0, IMesh* pIndexOverride = 0) = 0; + +// ------------ New Vertex/Index Buffer interface ---------------------------- + // Do we need support for bForceTempMesh and bSoftwareVertexShader? + // I don't think we use bSoftwareVertexShader anymore. .need to look into bForceTempMesh. + virtual IVertexBuffer *CreateVertexBuffer( ShaderBufferType_t type, VertexFormat_t fmt, int nVertexCount, const char *pBudgetGroup ) = 0; + virtual IIndexBuffer *CreateIndexBuffer( ShaderBufferType_t indexBufferType, MaterialIndexFormat_t fmt, int nIndexCount, const char *pBudgetGroup ) = 0; + virtual void DestroyVertexBuffer( IVertexBuffer * ) = 0; + virtual void DestroyIndexBuffer( IIndexBuffer * ) = 0; + // Do we need to specify the stream here in the case of locking multiple dynamic VBs on different streams? + virtual IVertexBuffer *GetDynamicVertexBuffer( int streamID, VertexFormat_t vertexFormat, bool bBuffered = true ) = 0; + virtual IIndexBuffer *GetDynamicIndexBuffer( MaterialIndexFormat_t fmt, bool bBuffered = true ) = 0; + virtual void BindVertexBuffer( int streamID, IVertexBuffer *pVertexBuffer, int nOffsetInBytes, int nFirstVertex, int nVertexCount, VertexFormat_t fmt, int nRepetitions = 1 ) = 0; + virtual void BindIndexBuffer( IIndexBuffer *pIndexBuffer, int nOffsetInBytes ) = 0; + virtual void Draw( MaterialPrimitiveType_t primitiveType, int nFirstIndex, int nIndexCount ) = 0; +// ------------ End ---------------------------- + virtual VertexFormat_t GetCurrentVertexFormat( void ) const = 0; + virtual void RenderPassWithVertexAndIndexBuffers( void ) = 0; + + // Computes the vertex format + virtual VertexFormat_t ComputeVertexFormat( unsigned int flags, + int numTexCoords, int* pTexCoordDimensions, int numBoneWeights, + int userDataSize ) const = 0; + + // Returns the number of buffers... + virtual int BufferCount() const = 0; + + // Use fat vertices (for tools) + virtual void UseFatVertices( bool bUseFat ) = 0; + + // Returns the number of vertices + indices we can render using the dynamic mesh + // Passing true in the second parameter will return the max # of vertices + indices + // we can use before a flush is provoked and may return different values + // if called multiple times in succession. + // Passing false into the second parameter will return + // the maximum possible vertices + indices that can be rendered in a single batch + virtual void GetMaxToRender( IMesh *pMesh, bool bMaxUntilFlush, int *pMaxVerts, int *pMaxIndices ) = 0; + + // Returns the max number of vertices we can render for a given material + virtual int GetMaxVerticesToRender( IMaterial *pMaterial ) = 0; + virtual int GetMaxIndicesToRender( ) = 0; + virtual IMesh *GetFlexMesh() = 0; + + virtual void ComputeVertexDescription( unsigned char* pBuffer, VertexFormat_t vertexFormat, MeshDesc_t& desc ) const = 0; + + virtual IVertexBuffer *GetDynamicVertexBuffer( IMaterial *pMaterial, bool buffered = true ) = 0; + virtual IIndexBuffer *GetDynamicIndexBuffer( IMaterial *pMaterial, bool buffered = true ) = 0; + + virtual void MarkUnusedVertexFields( unsigned int nFlags, int nTexCoordCount, bool *pUnusedTexCoords ) = 0; +}; + +#endif // IMESHDX8_H diff --git a/materialsystem/shaderapidx9/inputlayoutdx10.cpp b/materialsystem/shaderapidx9/inputlayoutdx10.cpp new file mode 100644 index 0000000..9482907 --- /dev/null +++ b/materialsystem/shaderapidx9/inputlayoutdx10.cpp @@ -0,0 +1,214 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +// +//===========================================================================// + +#include +#undef GetCommandLine + +#include "inputlayoutdx10.h" +#include "materialsystem/imesh.h" +#include "shaderdevicedx10.h" + +// NOTE: This has to be the last file included! +#include "tier0/memdbgon.h" + + +//----------------------------------------------------------------------------- +// Standard input layouts +//----------------------------------------------------------------------------- +static const DXGI_FORMAT s_pSizeLookup[] = +{ + DXGI_FORMAT_UNKNOWN, // Should be unused... + DXGI_FORMAT_R32_FLOAT, // D3DDECLTYPE_FLOAT1 + DXGI_FORMAT_R32G32_FLOAT, // D3DDECLTYPE_FLOAT2, + DXGI_FORMAT_R32G32B32_FLOAT, // D3DDECLTYPE_FLOAT3, + DXGI_FORMAT_R32G32B32A32_FLOAT, // D3DDECLTYPE_FLOAT4 +}; + +struct FieldInfo_t +{ + const char *m_pSemanticString; + unsigned int m_nSemanticIndex; + uint64 m_nFormatMask; + int m_nFieldSize; +}; + +static FieldInfo_t s_pFieldInfo[] = +{ + { "POSITION", 0, VERTEX_POSITION, sizeof( float ) * 3 }, + { "BLENDWEIGHT", 0, VERTEX_BONE_WEIGHT_MASK, 0 }, + { "BLENDINDICES", 0, VERTEX_BONE_INDEX, 4 }, + { "NORMAL", 0, VERTEX_NORMAL, sizeof( float ) * 3 }, + { "COLOR", 0, VERTEX_COLOR, 4 }, + { "SPECULAR", 0, VERTEX_SPECULAR, 4 }, + { "TEXCOORD", 0, VERTEX_TEXCOORD_MASK(0), 0 }, + { "TEXCOORD", 1, VERTEX_TEXCOORD_MASK(1), 0 }, + { "TEXCOORD", 2, VERTEX_TEXCOORD_MASK(2), 0 }, + { "TEXCOORD", 3, VERTEX_TEXCOORD_MASK(3), 0 }, + { "TEXCOORD", 4, VERTEX_TEXCOORD_MASK(4), 0 }, + { "TEXCOORD", 5, VERTEX_TEXCOORD_MASK(5), 0 }, + { "TEXCOORD", 6, VERTEX_TEXCOORD_MASK(6), 0 }, + { "TEXCOORD", 7, VERTEX_TEXCOORD_MASK(7), 0 }, + { "TANGENT", 0, VERTEX_TANGENT_S, sizeof( float ) * 3 }, + { "BINORMAL", 0, VERTEX_TANGENT_T, sizeof( float ) * 3 }, + { "USERDATA", 0, USER_DATA_SIZE_MASK, 0 }, + { NULL, 0, 0 }, +}; + +static D3D10_INPUT_ELEMENT_DESC s_pVertexDesc[] = +{ + { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 }, + { "BLENDWEIGHT", 0, DXGI_FORMAT_UNKNOWN, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 }, + { "BLENDINDICES", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 }, + { "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 }, + { "COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 }, + { "SPECULAR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 }, + { "TEXCOORD", 0, DXGI_FORMAT_UNKNOWN, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 }, + { "TEXCOORD", 1, DXGI_FORMAT_UNKNOWN, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 }, + { "TEXCOORD", 2, DXGI_FORMAT_UNKNOWN, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 }, + { "TEXCOORD", 3, DXGI_FORMAT_UNKNOWN, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 }, + { "TEXCOORD", 4, DXGI_FORMAT_UNKNOWN, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 }, + { "TEXCOORD", 5, DXGI_FORMAT_UNKNOWN, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 }, + { "TEXCOORD", 6, DXGI_FORMAT_UNKNOWN, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 }, + { "TEXCOORD", 7, DXGI_FORMAT_UNKNOWN, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 }, + { "TANGENT", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 }, + { "BINORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 }, + { "USERDATA", 0, DXGI_FORMAT_UNKNOWN, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 }, +}; + +static D3D10_INPUT_ELEMENT_DESC s_pFallbackVertexDesc[] = +{ + { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 15, 0, D3D10_INPUT_PER_INSTANCE_DATA, UINT_MAX }, + { "BLENDWEIGHT", 0, DXGI_FORMAT_R32G32_FLOAT, 15, 12, D3D10_INPUT_PER_INSTANCE_DATA, UINT_MAX }, + { "BLENDINDICES", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 15, 20, D3D10_INPUT_PER_INSTANCE_DATA, UINT_MAX }, + { "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 15, 24, D3D10_INPUT_PER_INSTANCE_DATA, UINT_MAX }, + { "COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 15, 36, D3D10_INPUT_PER_INSTANCE_DATA, UINT_MAX }, + { "SPECULAR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 15, 40, D3D10_INPUT_PER_INSTANCE_DATA, UINT_MAX }, + { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 15, 44, D3D10_INPUT_PER_INSTANCE_DATA, UINT_MAX }, + { "TEXCOORD", 1, DXGI_FORMAT_R32G32_FLOAT, 15, 52, D3D10_INPUT_PER_INSTANCE_DATA, UINT_MAX }, + { "TEXCOORD", 2, DXGI_FORMAT_R32G32_FLOAT, 15, 60, D3D10_INPUT_PER_INSTANCE_DATA, UINT_MAX }, + { "TEXCOORD", 3, DXGI_FORMAT_R32G32_FLOAT, 15, 68, D3D10_INPUT_PER_INSTANCE_DATA, UINT_MAX }, + { "TEXCOORD", 4, DXGI_FORMAT_R32G32_FLOAT, 15, 76, D3D10_INPUT_PER_INSTANCE_DATA, UINT_MAX }, + { "TEXCOORD", 5, DXGI_FORMAT_R32G32_FLOAT, 15, 84, D3D10_INPUT_PER_INSTANCE_DATA, UINT_MAX }, + { "TEXCOORD", 6, DXGI_FORMAT_R32G32_FLOAT, 15, 92, D3D10_INPUT_PER_INSTANCE_DATA, UINT_MAX }, + { "TEXCOORD", 7, DXGI_FORMAT_R32G32_FLOAT, 15, 100, D3D10_INPUT_PER_INSTANCE_DATA, UINT_MAX }, + { "TANGENT", 0, DXGI_FORMAT_R32G32B32_FLOAT, 15, 108, D3D10_INPUT_PER_INSTANCE_DATA, UINT_MAX }, + { "BINORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 15, 120, D3D10_INPUT_PER_INSTANCE_DATA, UINT_MAX }, + { "USERDATA", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 15, 132, D3D10_INPUT_PER_INSTANCE_DATA, UINT_MAX }, +}; + + +//----------------------------------------------------------------------------- +// Computes the required input desc based on the vertex format +//----------------------------------------------------------------------------- +static void PrintInputDesc( int nCount, const D3D10_INPUT_ELEMENT_DESC *pDecl ) +{ + for ( int i = 0; i < nCount; i++ ) + { + Msg( "%s (%d): Stream: %d, Offset: %d, Instanced? %c\n", + pDecl[i].SemanticName, + pDecl[i].SemanticIndex, + ( int )pDecl[i].InputSlot, + ( int )pDecl[i].AlignedByteOffset, + pDecl[i].InputSlotClass == D3D10_INPUT_PER_VERTEX_DATA ? 'n' : 'y' + ); + } +} + + +//----------------------------------------------------------------------------- +// Checks to see if a shader requires a particular field +//----------------------------------------------------------------------------- +static bool CheckShaderSignatureExpectations( ID3D10ShaderReflection* pReflection, const char* pSemantic, unsigned int nSemanticIndex ) +{ + D3D10_SHADER_DESC shaderDesc; + D3D10_SIGNATURE_PARAMETER_DESC paramDesc; + + Assert( pSemantic ); + Assert( pReflection ); + + pReflection->GetDesc( &shaderDesc ); + + for ( unsigned int k=0; k < shaderDesc.InputParameters; k++ ) + { + pReflection->GetInputParameterDesc( k, ¶mDesc ); + if ( ( nSemanticIndex == paramDesc.SemanticIndex ) && !Q_stricmp( pSemantic, paramDesc.SemanticName ) ) + return true; + } + + return false; +} + + +//----------------------------------------------------------------------------- +// Computes the required input desc based on the vertex format +//----------------------------------------------------------------------------- +static unsigned int ComputeInputDesc( VertexFormat_t fmt, D3D10_INPUT_ELEMENT_DESC *pDecl, ID3D10ShaderReflection* pReflection ) +{ + unsigned int nCount = 0; + int nOffset = 0; + + // Fix up the global table so we don't need special-case code + int nBoneCount = NumBoneWeights( fmt ); + s_pFieldInfo[1].m_nFieldSize = sizeof( float ) * nBoneCount; + s_pVertexDesc[1].Format = s_pSizeLookup[ nBoneCount ]; + + int nUserDataSize = UserDataSize( fmt ); + s_pFieldInfo[16].m_nFieldSize = sizeof( float ) * nUserDataSize; + s_pVertexDesc[16].Format = s_pSizeLookup[ nUserDataSize ]; + + // NOTE: Fix s_pFieldInfo, s_pVertexDesc, s_pFallbackVertexDesc if you add more fields + // As well as the fallback stream (stream #15) + COMPILE_TIME_ASSERT( VERTEX_MAX_TEXTURE_COORDINATES == 8 ); + for ( int i = 0; i < VERTEX_MAX_TEXTURE_COORDINATES; ++i ) + { + int nTexCoordCount = TexCoordSize( i, fmt ); + s_pFieldInfo[6+i].m_nFieldSize = sizeof( float ) * nTexCoordCount; + s_pVertexDesc[6+i].Format = s_pSizeLookup[ nTexCoordCount ]; + } + + // FIXME: Change this loop so CheckShaderSignatureExpectations is called once! + for ( int i = 0; s_pFieldInfo[i].m_pSemanticString; ++i ) + { + if ( fmt & s_pFieldInfo[i].m_nFormatMask ) + { + memcpy( &pDecl[nCount], &s_pVertexDesc[i], sizeof(D3D10_INPUT_ELEMENT_DESC) ); + pDecl[nCount].AlignedByteOffset = nOffset; + nOffset += s_pFieldInfo[i].m_nFieldSize; + ++nCount; + } + else if ( CheckShaderSignatureExpectations( pReflection, s_pFieldInfo[i].m_pSemanticString, s_pFieldInfo[i].m_nSemanticIndex ) ) + { + memcpy( &pDecl[nCount], &s_pFallbackVertexDesc[i], sizeof(D3D10_INPUT_ELEMENT_DESC) ); + ++nCount; + } + } + + // For debugging only... +// PrintInputDesc( nCount, pDecl ); + + return nCount; +} + + +//----------------------------------------------------------------------------- +// Gets the input layout associated with a vertex format +//----------------------------------------------------------------------------- +ID3D10InputLayout *CreateInputLayout( VertexFormat_t fmt, ID3D10ShaderReflection* pReflection, const void *pByteCode, size_t nByteCodeLen ) +{ + D3D10_INPUT_ELEMENT_DESC pDecl[32]; + unsigned int nDeclCount = ComputeInputDesc( fmt, pDecl, pReflection ); + + ID3D10InputLayout *pInputLayout; + HRESULT hr = D3D10Device()->CreateInputLayout( pDecl, nDeclCount, pByteCode, nByteCodeLen, &pInputLayout ); + if ( FAILED( hr ) ) + { + Warning( "CreateInputLayout::Unable to create input layout for format %llX!\n", fmt ); + return NULL; + } + return pInputLayout; +} diff --git a/materialsystem/shaderapidx9/inputlayoutdx10.h b/materialsystem/shaderapidx9/inputlayoutdx10.h new file mode 100644 index 0000000..b1ac116 --- /dev/null +++ b/materialsystem/shaderapidx9/inputlayoutdx10.h @@ -0,0 +1,35 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +// +//===========================================================================// + +#ifndef INPUTLAYOUTDX10_H +#define INPUTLAYOUTDX10_H + +#ifdef _WIN32 +#pragma once +#endif + +#include "materialsystem/imaterial.h" + + +//----------------------------------------------------------------------------- +// Forward declaration +//----------------------------------------------------------------------------- +struct ID3D10InputLayout; +struct ID3D10ShaderReflection; + + +//----------------------------------------------------------------------------- +// Gets the input layout associated with a vertex format +// FIXME: Note that we'll need to change this from a VertexFormat_t +//----------------------------------------------------------------------------- +ID3D10InputLayout *CreateInputLayout( VertexFormat_t fmt, + ID3D10ShaderReflection* pReflection, const void *pByteCode, size_t nByteCodeLen ); + + +#endif // INPUTLAYOUTDX10_H + diff --git a/materialsystem/shaderapidx9/ivertexbufferdx8.h b/materialsystem/shaderapidx9/ivertexbufferdx8.h new file mode 100644 index 0000000..dea00d7 --- /dev/null +++ b/materialsystem/shaderapidx9/ivertexbufferdx8.h @@ -0,0 +1,34 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +// +//=============================================================================// + +#ifndef IVERTEXBUFFERDX8_H +#define IVERTEXBUFFERDX8_H +#pragma once + +#include "IVertexBuffer.h" + +abstract_class IVertexBufferDX8 : public IVertexBuffer +{ +public: + // TEMPORARY! + virtual int Begin( int flags, int numVerts ) = 0; + + // Sets up the renderstate + virtual void SetRenderState( int stream ) = 0; + + // Gets FVF info + virtual void ComputeFVFInfo( int flags, int& fvf, int& size ) const = 0; + + // Cleans up the vertex buffers + virtual void CleanUp() = 0; + + // Flushes the vertex buffers + virtual void Flush() = 0; +}; + +#endif // IVERTEXBUFFERDX8_H diff --git a/materialsystem/shaderapidx9/locald3dtypes.h b/materialsystem/shaderapidx9/locald3dtypes.h new file mode 100644 index 0000000..ad45355 --- /dev/null +++ b/materialsystem/shaderapidx9/locald3dtypes.h @@ -0,0 +1,191 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//===========================================================================// + +#ifndef LOCALD3DTYPES_H +#define LOCALD3DTYPES_H + +#ifdef _WIN32 +#pragma once +#endif + +#if defined( DX10 ) && !defined( DX_TO_GL_ABSTRACTION ) + +#include +#include + +struct IDirect3D10BaseTexture +{ + ID3D10Resource *m_pBaseTexture; + ID3D10ShaderResourceView *m_pSRView; + ID3D10RenderTargetView *m_pRTView; +}; + +class CDx10Types +{ +public: + typedef struct IDirect3D10BaseTexture IDirect3DTexture; + // FIXME: What is this called now ? + // typedef ID3D10TextureCube IDirect3DCubeTexture; + typedef ID3D10Texture3D IDirect3DVolumeTexture; + typedef ID3D10Device IDirect3DDevice; + typedef D3D10_VIEWPORT D3DVIEWPORT; + typedef ID3D10Buffer IDirect3DIndexBuffer; + typedef ID3D10Buffer IDirect3DVertexBuffer; + typedef ID3D10VertexShader IDirect3DVertexShader; + typedef ID3D10PixelShader IDirect3DPixelShader; + typedef ID3D10ShaderResourceView IDirect3DSurface; + typedef ID3DX10Font ID3DXFont; + typedef ID3D10Query ID3DQuery; + + typedef ID3D10Device *LPDIRECT3DDEVICE; + typedef ID3D10Buffer *LPDIRECT3DINDEXBUFFER; + typedef ID3D10Buffer *LPDIRECT3DVERTEXBUFFER; +}; + +#endif // defined( DX10 ) && !defined( DX_TO_GL_ABSTRACTION ) + + +#if !defined( _X360 ) && !defined( DX_TO_GL_ABSTRACTION ) +#ifdef _DEBUG +#define D3D_DEBUG_INFO 1 +#endif +#endif + +struct IDirect3DTexture9; +struct IDirect3DBaseTexture9; +struct IDirect3DCubeTexture9; +struct IDirect3D9; +struct IDirect3DDevice9; +struct IDirect3DSurface9; +struct IDirect3DIndexBuffer9; +struct IDirect3DVertexBuffer9; +struct IDirect3DVertexShader9; +struct IDirect3DPixelShader9; +struct IDirect3DVolumeTexture9; + +typedef struct _D3DLIGHT9 D3DLIGHT9; +typedef struct _D3DADAPTER_IDENTIFIER9 D3DADAPTER_IDENTIFIER9; +typedef struct _D3DCAPS9 D3DCAPS9; +typedef struct _D3DVIEWPORT9 D3DVIEWPORT9; +typedef struct _D3DMATERIAL9 D3DMATERIAL9; +typedef IDirect3DTexture9 IDirect3DTexture; +typedef IDirect3DBaseTexture9 IDirect3DBaseTexture; +typedef IDirect3DCubeTexture9 IDirect3DCubeTexture; +typedef IDirect3DVolumeTexture9 IDirect3DVolumeTexture; +typedef IDirect3DDevice9 IDirect3DDevice; +typedef D3DMATERIAL9 D3DMATERIAL; +typedef D3DLIGHT9 D3DLIGHT; +typedef IDirect3DSurface9 IDirect3DSurface; +typedef D3DCAPS9 D3DCAPS; +typedef IDirect3DIndexBuffer9 IDirect3DIndexBuffer; +typedef IDirect3DVertexBuffer9 IDirect3DVertexBuffer; +typedef IDirect3DPixelShader9 IDirect3DPixelShader; +typedef IDirect3DDevice *LPDIRECT3DDEVICE; +typedef IDirect3DIndexBuffer *LPDIRECT3DINDEXBUFFER; +typedef IDirect3DVertexBuffer *LPDIRECT3DVERTEXBUFFER; + +class CDx9Types +{ +public: + typedef IDirect3DTexture9 IDirect3DTexture; + typedef IDirect3DBaseTexture9 IDirect3DBaseTexture; + typedef IDirect3DCubeTexture9 IDirect3DCubeTexture; + typedef IDirect3DVolumeTexture9 IDirect3DVolumeTexture; + typedef IDirect3DDevice9 IDirect3DDevice; + typedef D3DMATERIAL9 D3DMATERIAL; + typedef D3DLIGHT9 D3DLIGHT; + typedef IDirect3DSurface9 IDirect3DSurface; + typedef D3DCAPS9 D3DCAPS; + typedef IDirect3DIndexBuffer9 IDirect3DIndexBuffer; + typedef IDirect3DVertexBuffer9 IDirect3DVertexBuffer; + typedef IDirect3DPixelShader9 IDirect3DPixelShader; + typedef IDirect3DDevice *LPDIRECT3DDEVICE; + typedef IDirect3DIndexBuffer *LPDIRECT3DINDEXBUFFER; + typedef IDirect3DVertexBuffer *LPDIRECT3DVERTEXBUFFER; +}; + +typedef void *HardwareShader_t; + +//----------------------------------------------------------------------------- +// The vertex and pixel shader type +//----------------------------------------------------------------------------- +typedef int VertexShader_t; +typedef int PixelShader_t; + +//----------------------------------------------------------------------------- +// Bitpattern for an invalid shader +//----------------------------------------------------------------------------- +#define INVALID_SHADER ( 0xFFFFFFFF ) +#define INVALID_HARDWARE_SHADER ( NULL ) + +#define D3DSAMP_NOTSUPPORTED D3DSAMP_FORCE_DWORD +#define D3DRS_NOTSUPPORTED D3DRS_FORCE_DWORD + +#include "togl/rendermechanism.h" + +#if defined( _X360 ) + +// not supported, keeping for port ease +#define D3DSAMP_SRGBTEXTURE D3DSAMP_NOTSUPPORTED +#define D3DRS_LIGHTING D3DRS_NOTSUPPORTED +#define D3DRS_DIFFUSEMATERIALSOURCE D3DRS_NOTSUPPORTED +#define D3DRS_SPECULARENABLE D3DRS_NOTSUPPORTED +#define D3DRS_SHADEMODE D3DRS_NOTSUPPORTED +#define D3DRS_LASTPIXEL D3DRS_NOTSUPPORTED +#define D3DRS_DITHERENABLE D3DRS_NOTSUPPORTED +#define D3DRS_FOGENABLE D3DRS_NOTSUPPORTED +#define D3DRS_FOGCOLOR D3DRS_NOTSUPPORTED +#define D3DRS_FOGTABLEMODE D3DRS_NOTSUPPORTED +#define D3DRS_FOGSTART D3DRS_NOTSUPPORTED +#define D3DRS_FOGEND D3DRS_NOTSUPPORTED +#define D3DRS_FOGDENSITY D3DRS_NOTSUPPORTED +#define D3DRS_RANGEFOGENABLE D3DRS_NOTSUPPORTED +#define D3DRS_TEXTUREFACTOR D3DRS_NOTSUPPORTED +#define D3DRS_CLIPPING D3DRS_NOTSUPPORTED +#define D3DRS_AMBIENT D3DRS_NOTSUPPORTED +#define D3DRS_FOGVERTEXMODE D3DRS_NOTSUPPORTED +#define D3DRS_COLORVERTEX D3DRS_NOTSUPPORTED +#define D3DRS_LOCALVIEWER D3DRS_NOTSUPPORTED +#define D3DRS_NORMALIZENORMALS D3DRS_NOTSUPPORTED +#define D3DRS_SPECULARMATERIALSOURCE D3DRS_NOTSUPPORTED +#define D3DRS_AMBIENTMATERIALSOURCE D3DRS_NOTSUPPORTED +#define D3DRS_EMISSIVEMATERIALSOURCE D3DRS_NOTSUPPORTED +#define D3DRS_VERTEXBLEND D3DRS_NOTSUPPORTED +#define D3DRS_POINTSCALEENABLE D3DRS_NOTSUPPORTED +#define D3DRS_POINTSCALE_A D3DRS_NOTSUPPORTED +#define D3DRS_POINTSCALE_B D3DRS_NOTSUPPORTED +#define D3DRS_POINTSCALE_C D3DRS_NOTSUPPORTED +#define D3DRS_PATCHEDGESTYLE D3DRS_NOTSUPPORTED +#define D3DRS_DEBUGMONITORTOKEN D3DRS_NOTSUPPORTED +#define D3DRS_INDEXEDVERTEXBLENDENABLE D3DRS_NOTSUPPORTED +#define D3DRS_TWEENFACTOR D3DRS_NOTSUPPORTED +#define D3DRS_POSITIONDEGREE D3DRS_NOTSUPPORTED +#define D3DRS_NORMALDEGREE D3DRS_NOTSUPPORTED +#define D3DRS_ANTIALIASEDLINEENABLE D3DRS_NOTSUPPORTED +#define D3DRS_ADAPTIVETESS_X D3DRS_NOTSUPPORTED +#define D3DRS_ADAPTIVETESS_Y D3DRS_NOTSUPPORTED +#define D3DRS_ADAPTIVETESS_Z D3DRS_NOTSUPPORTED +#define D3DRS_ADAPTIVETESS_W D3DRS_NOTSUPPORTED +#define D3DRS_ENABLEADAPTIVETESSELLATION D3DRS_NOTSUPPORTED +#define D3DRS_SRGBWRITEENABLE D3DRS_NOTSUPPORTED +#define D3DLOCK_DISCARD 0 +#define D3DUSAGE_DYNAMIC 0 +#define D3DUSAGE_AUTOGENMIPMAP 0 +#define D3DDEVTYPE_REF D3DDEVTYPE_HAL +#define D3DENUM_WHQL_LEVEL 0 +#define D3DCREATE_SOFTWARE_VERTEXPROCESSING D3DCREATE_HARDWARE_VERTEXPROCESSING +#define D3DDMT_ENABLE 0 + +typedef enum D3DSHADEMODE +{ + D3DSHADE_FLAT = 0, + D3DSHADE_GOURAUD = 0, +}; + +#endif // _X360 + +#endif // LOCALD3DTYPES_H diff --git a/materialsystem/shaderapidx9/meshbase.cpp b/materialsystem/shaderapidx9/meshbase.cpp new file mode 100644 index 0000000..336f150 --- /dev/null +++ b/materialsystem/shaderapidx9/meshbase.cpp @@ -0,0 +1,419 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//===========================================================================// + +#include "meshbase.h" +#include "shaderapi_global.h" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + + +//----------------------------------------------------------------------------- +// Helpers with VertexDesc_t... +//----------------------------------------------------------------------------- +// FIXME: add compression-agnostic read-accessors (which decompress and return by value, checking desc.m_CompressionType) +inline Vector &Position( VertexDesc_t const &desc, int vert ) +{ + return *(Vector*)((unsigned char*)desc.m_pPosition + vert * desc.m_VertexSize_Position ); +} + +inline float Wrinkle( VertexDesc_t const &desc, int vert ) +{ + return *(float*)((unsigned char*)desc.m_pWrinkle + vert * desc.m_VertexSize_Wrinkle ); +} + +inline float *BoneWeight( VertexDesc_t const &desc, int vert ) +{ + Assert( desc.m_CompressionType == VERTEX_COMPRESSION_NONE ); + return (float*)((unsigned char*)desc.m_pBoneWeight + vert * desc.m_VertexSize_BoneWeight ); +} + +inline unsigned char *BoneIndex( VertexDesc_t const &desc, int vert ) +{ + return desc.m_pBoneMatrixIndex + vert * desc.m_VertexSize_BoneMatrixIndex; +} + +inline Vector &Normal( VertexDesc_t const &desc, int vert ) +{ + Assert( desc.m_CompressionType == VERTEX_COMPRESSION_NONE ); + return *(Vector*)((unsigned char*)desc.m_pNormal + vert * desc.m_VertexSize_Normal ); +} + +inline unsigned char *Color( VertexDesc_t const &desc, int vert ) +{ + return desc.m_pColor + vert * desc.m_VertexSize_Color; +} + +inline Vector2D &TexCoord( VertexDesc_t const &desc, int vert, int stage ) +{ + return *(Vector2D*)((unsigned char*)desc.m_pTexCoord[stage] + vert * desc.m_VertexSize_TexCoord[stage] ); +} + +inline Vector &TangentS( VertexDesc_t const &desc, int vert ) +{ + return *(Vector*)((unsigned char*)desc.m_pTangentS + vert * desc.m_VertexSize_TangentS ); +} + +inline Vector &TangentT( VertexDesc_t const &desc, int vert ) +{ + return *(Vector*)((unsigned char*)desc.m_pTangentT + vert * desc.m_VertexSize_TangentT ); +} + + +//----------------------------------------------------------------------------- +// +// Vertex Buffer implementations begin here +// +//----------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +// constructor, destructor +//----------------------------------------------------------------------------- +CVertexBufferBase::CVertexBufferBase( const char *pBudgetGroupName ) +{ + m_pBudgetGroupName = pBudgetGroupName; +} + +CVertexBufferBase::~CVertexBufferBase() +{ +} + +//----------------------------------------------------------------------------- +// Displays the vertex format +//----------------------------------------------------------------------------- +void CVertexBufferBase::PrintVertexFormat( VertexFormat_t vertexFormat ) +{ + VertexCompressionType_t compression = CompressionType( vertexFormat ); + if( vertexFormat & VERTEX_POSITION ) + { + Msg( "VERTEX_POSITION|" ); + } + if( vertexFormat & VERTEX_NORMAL ) + { + // FIXME: genericise this stuff using VertexElement_t data tables (so funcs like 'just work' if we make compression changes) + if ( compression == VERTEX_COMPRESSION_ON ) + Msg( "VERTEX_NORMAL|" ); + else + Msg( "VERTEX_NORMAL[COMPRESSED]|" ); + } + if( vertexFormat & VERTEX_COLOR ) + { + Msg( "VERTEX_COLOR|" ); + } + if( vertexFormat & VERTEX_SPECULAR ) + { + Msg( "VERTEX_SPECULAR|" ); + } + if( vertexFormat & VERTEX_TANGENT_S ) + { + Msg( "VERTEX_TANGENT_S|" ); + } + if( vertexFormat & VERTEX_TANGENT_T ) + { + Msg( "VERTEX_TANGENT_T|" ); + } + if( vertexFormat & VERTEX_BONE_INDEX ) + { + Msg( "VERTEX_BONE_INDEX|" ); + } + if( vertexFormat & VERTEX_FORMAT_VERTEX_SHADER ) + { + Msg( "VERTEX_FORMAT_VERTEX_SHADER|" ); + } + if( NumBoneWeights( vertexFormat ) > 0 ) + { + Msg( "VERTEX_BONEWEIGHT(%d)%s|", + NumBoneWeights( vertexFormat ), ( compression ? "[COMPRESSED]" : "" ) ); + } + if( UserDataSize( vertexFormat ) > 0 ) + { + Msg( "VERTEX_USERDATA_SIZE(%d)|", UserDataSize( vertexFormat ) ); + } + int i; + for( i = 0; i < VERTEX_MAX_TEXTURE_COORDINATES; i++ ) + { + int nDim = TexCoordSize( i, vertexFormat ); + if ( nDim == 0 ) + continue; + + Msg( "VERTEX_TEXCOORD_SIZE(%d,%d)", i, nDim ); + } + Msg( "\n" ); +} + + +//----------------------------------------------------------------------------- +// Used to construct vertex data +//----------------------------------------------------------------------------- +void CVertexBufferBase::ComputeVertexDescription( unsigned char *pBuffer, + VertexFormat_t vertexFormat, VertexDesc_t &desc ) +{ + ComputeVertexDesc( pBuffer, vertexFormat, desc ); +} + + +//----------------------------------------------------------------------------- +// Returns the vertex format size +//----------------------------------------------------------------------------- +int CVertexBufferBase::VertexFormatSize( VertexFormat_t vertexFormat ) +{ + // FIXME: We could make this much faster + MeshDesc_t temp; + ComputeVertexDescription( 0, vertexFormat, temp ); + return temp.m_ActualVertexSize; +} + + +//----------------------------------------------------------------------------- +// Spews the mesh data +//----------------------------------------------------------------------------- +void CVertexBufferBase::Spew( int nVertexCount, const VertexDesc_t &desc ) +{ + LOCK_SHADERAPI(); + + char pTempBuf[1024]; + Q_snprintf( pTempBuf, sizeof(pTempBuf), "\nVerts %d (First %d, Offset %d) :\n", nVertexCount, desc.m_nFirstVertex, desc.m_nOffset ); + Warning( "%s", pTempBuf ); + + Assert( ( desc.m_NumBoneWeights == 2 ) || ( desc.m_NumBoneWeights == 0 ) ); + + int nLen = 0; + int nBoneWeightCount = desc.m_NumBoneWeights; + for ( int i = 0; i < nVertexCount; ++i ) + { + nLen += Q_snprintf( &pTempBuf[nLen], sizeof(pTempBuf) - nLen, "[%4d] ", i + desc.m_nFirstVertex ); + if ( desc.m_VertexSize_Position ) + { + Vector &pos = Position( desc, i ); + nLen += Q_snprintf( &pTempBuf[nLen], sizeof(pTempBuf) - nLen, "P %8.2f %8.2f %8.2f ", + pos[0], pos[1], pos[2]); + } + + if ( desc.m_VertexSize_Wrinkle ) + { + float flWrinkle = Wrinkle( desc, i ); + nLen += Q_snprintf( &pTempBuf[nLen], sizeof(pTempBuf) - nLen, "Wr %8.2f ",flWrinkle ); + } + + if ( nBoneWeightCount ) + { + nLen += Q_snprintf( &pTempBuf[nLen], sizeof(pTempBuf) - nLen, "BW "); + float* pWeight = BoneWeight( desc, i ); + for ( int j = 0; j < nBoneWeightCount; ++j ) + { + nLen += Q_snprintf( &pTempBuf[nLen], sizeof(pTempBuf) - nLen, "%1.2f ", pWeight[j] ); + } + } + if ( desc.m_VertexSize_BoneMatrixIndex ) + { + unsigned char *pIndex = BoneIndex( desc, i ); + nLen += Q_snprintf( &pTempBuf[nLen], sizeof(pTempBuf) - nLen, "BI %d %d %d %d ", ( int )pIndex[0], ( int )pIndex[1], ( int )pIndex[2], ( int )pIndex[3] ); + Assert( pIndex[0] >= 0 && pIndex[0] < 16 ); + Assert( pIndex[1] >= 0 && pIndex[1] < 16 ); + Assert( pIndex[2] >= 0 && pIndex[2] < 16 ); + Assert( pIndex[3] >= 0 && pIndex[3] < 16 ); + } + + if ( desc.m_VertexSize_Normal ) + { + Vector & normal = Normal( desc, i ); + nLen += Q_snprintf( &pTempBuf[nLen], sizeof(pTempBuf) - nLen, "N %1.2f %1.2f %1.2f ", + normal[0], normal[1], normal[2]); + } + + if ( desc.m_VertexSize_Color ) + { + unsigned char* pColor = Color( desc, i ); + nLen += Q_snprintf( &pTempBuf[nLen], sizeof(pTempBuf) - nLen, "C b %3d g %3d r %3d a %3d ", + pColor[0], pColor[1], pColor[2], pColor[3]); + } + + for ( int j = 0; j < VERTEX_MAX_TEXTURE_COORDINATES; ++j ) + { + if ( desc.m_VertexSize_TexCoord[j] ) + { + Vector2D& texcoord = TexCoord( desc, i, j ); + nLen += Q_snprintf( &pTempBuf[nLen], sizeof(pTempBuf) - nLen, "T%d %.2f %.2f ", j,texcoord[0], texcoord[1]); + } + } + + if ( desc.m_VertexSize_TangentS ) + { + Vector& tangentS = TangentS( desc, i ); + nLen += Q_snprintf( &pTempBuf[nLen], sizeof(pTempBuf) - nLen, "S %1.2f %1.2f %1.2f ", + tangentS[0], tangentS[1], tangentS[2]); + } + + if ( desc.m_VertexSize_TangentT ) + { + Vector& tangentT = TangentT( desc, i ); + nLen += Q_snprintf( &pTempBuf[nLen], sizeof(pTempBuf) - nLen, "T %1.2f %1.2f %1.2f ", + tangentT[0], tangentT[1], tangentT[2]); + } + + Q_snprintf( &pTempBuf[nLen], sizeof(pTempBuf) - nLen, "\n" ); + Warning( "%s", pTempBuf ); + nLen = 0; + } +} + + +//----------------------------------------------------------------------------- +// Validates vertex buffer data +//----------------------------------------------------------------------------- +void CVertexBufferBase::ValidateData( int nVertexCount, const VertexDesc_t &spewDesc ) +{ + LOCK_SHADERAPI(); +#ifdef VALIDATE_DEBUG + int i; + + // This is needed so buffering can just use this + VertexFormat_t fmt = m_pMaterial->GetVertexUsage(); + + // Set up the vertex descriptor + VertexDesc_t desc = spewDesc; + + int numBoneWeights = NumBoneWeights( fmt ); + for ( i = 0; i < nVertexCount; ++i ) + { + if( fmt & VERTEX_POSITION ) + { + D3DXVECTOR3& pos = Position( desc, i ); + Assert( IsFinite( pos[0] ) && IsFinite( pos[1] ) && IsFinite( pos[2] ) ); + } + if( fmt & VERTEX_WRINKLE ) + { + float flWrinkle = Wrinkle( desc, i ); + Assert( IsFinite( flWrinkle ) ); + } + if (numBoneWeights > 0) + { + float* pWeight = BoneWeight( desc, i ); + for (int j = 0; j < numBoneWeights; ++j) + { + Assert( pWeight[j] >= 0.0f && pWeight[j] <= 1.0f ); + } + } + if( fmt & VERTEX_BONE_INDEX ) + { + unsigned char *pIndex = BoneIndex( desc, i ); + Assert( pIndex[0] >= 0 && pIndex[0] < 16 ); + Assert( pIndex[1] >= 0 && pIndex[1] < 16 ); + Assert( pIndex[2] >= 0 && pIndex[2] < 16 ); + Assert( pIndex[3] >= 0 && pIndex[3] < 16 ); + } + if( fmt & VERTEX_NORMAL ) + { + D3DXVECTOR3& normal = Normal( desc, i ); + Assert( normal[0] >= -1.05f && normal[0] <= 1.05f ); + Assert( normal[1] >= -1.05f && normal[1] <= 1.05f ); + Assert( normal[2] >= -1.05f && normal[2] <= 1.05f ); + } + + if (fmt & VERTEX_COLOR) + { + int* pColor = (int*)Color( desc, i ); + Assert( *pColor != FLOAT32_NAN_BITS ); + } + + for (int j = 0; j < VERTEX_MAX_TEXTURE_COORDINATES; ++j) + { + if( TexCoordSize( j, fmt ) > 0) + { + D3DXVECTOR2& texcoord = TexCoord( desc, i, j ); + Assert( IsFinite( texcoord[0] ) && IsFinite( texcoord[1] ) ); + } + } + + if (fmt & VERTEX_TANGENT_S) + { + D3DXVECTOR3& tangentS = TangentS( desc, i ); + Assert( IsFinite( tangentS[0] ) && IsFinite( tangentS[1] ) && IsFinite( tangentS[2] ) ); + } + + if (fmt & VERTEX_TANGENT_T) + { + D3DXVECTOR3& tangentT = TangentT( desc, i ); + Assert( IsFinite( tangentT[0] ) && IsFinite( tangentT[1] ) && IsFinite( tangentT[2] ) ); + } + } +#endif // _DEBUG +} + + +//----------------------------------------------------------------------------- +// +// Index Buffer implementations begin here +// +//----------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +// constructor, destructor +//----------------------------------------------------------------------------- +CIndexBufferBase::CIndexBufferBase( const char *pBudgetGroupName ) : m_pBudgetGroupName( pBudgetGroupName ) +{ +} + + +//----------------------------------------------------------------------------- +// Spews the mesh data +//----------------------------------------------------------------------------- +void CIndexBufferBase::Spew( int nIndexCount, const IndexDesc_t &indexDesc ) +{ + LOCK_SHADERAPI(); + + char pTempBuf[512]; + int nLen = 0; + pTempBuf[0] = '\0'; + char *pTemp = pTempBuf; + Q_snprintf( pTempBuf, sizeof(pTempBuf), "\nIndices: %d (First %d, Offset %d)\n", nIndexCount, indexDesc.m_nFirstIndex, indexDesc.m_nOffset ); + Warning( "%s", pTempBuf ); + for ( int i = 0; i < nIndexCount; ++i ) + { + nLen += Q_snprintf( pTemp, sizeof(pTempBuf) - nLen - 1, "%d ", ( int )indexDesc.m_pIndices[i] ); + pTemp = pTempBuf + nLen; + if ( (i & 0x0F) == 0x0F ) + { + Q_snprintf( pTemp, sizeof(pTempBuf) - nLen - 1, "\n" ); + Warning( "%s", pTempBuf ); + pTempBuf[0] = '\0'; + nLen = 0; + pTemp = pTempBuf; + } + } + Q_snprintf( pTemp, sizeof(pTempBuf) - nLen - 1, "\n" ); + Warning( "%s", pTempBuf ); +} + + +//----------------------------------------------------------------------------- +// Call this in debug mode to make sure our data is good. +//----------------------------------------------------------------------------- +void CIndexBufferBase::ValidateData( int nIndexCount, const IndexDesc_t& desc ) +{ + /* FIXME */ + // NOTE: Is there anything reasonable to do here at all? + // Or is this a bogus method altogether? +} + + + +//----------------------------------------------------------------------------- +// +// Base mesh +// +//----------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +// constructor, destructor +//----------------------------------------------------------------------------- +CMeshBase::CMeshBase() +{ +} + +CMeshBase::~CMeshBase() +{ +} diff --git a/materialsystem/shaderapidx9/meshbase.h b/materialsystem/shaderapidx9/meshbase.h new file mode 100644 index 0000000..b566099 --- /dev/null +++ b/materialsystem/shaderapidx9/meshbase.h @@ -0,0 +1,309 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +// +//===========================================================================// + +#ifndef MESHBASE_H +#define MESHBASE_H + +#ifdef _WIN32 +#pragma once +#endif + + +#include "materialsystem/imesh.h" +#include "materialsystem/imaterial.h" + + +//----------------------------------------------------------------------------- +// Base vertex buffer +//----------------------------------------------------------------------------- +abstract_class CVertexBufferBase : public IVertexBuffer +{ + // Methods of IVertexBuffer +public: + virtual void Spew( int nVertexCount, const VertexDesc_t &desc ); + virtual void ValidateData( int nVertexCount, const VertexDesc_t& desc ); + +public: + // constructor, destructor + CVertexBufferBase( const char *pBudgetGroupName ); + virtual ~CVertexBufferBase(); + + // Displays the vertex format + static void PrintVertexFormat( VertexFormat_t vertexFormat ); + + // Used to construct vertex data + static void ComputeVertexDescription( unsigned char *pBuffer, VertexFormat_t vertexFormat, VertexDesc_t &desc ); + + // Returns the vertex format size + static int VertexFormatSize( VertexFormat_t vertexFormat ); + +protected: + const char *m_pBudgetGroupName; +}; + + +//----------------------------------------------------------------------------- +// Base index buffer +//----------------------------------------------------------------------------- +abstract_class CIndexBufferBase : public IIndexBuffer +{ + // Methods of IIndexBuffer +public: + virtual void Spew( int nIndexCount, const IndexDesc_t &desc ); + virtual void ValidateData( int nIndexCount, const IndexDesc_t& desc ); + + // Other public methods +public: + // constructor, destructor + CIndexBufferBase( const char *pBudgetGroupName ); + virtual ~CIndexBufferBase() {} + +protected: + const char *m_pBudgetGroupName; +}; + + +//----------------------------------------------------------------------------- +// Base mesh +//----------------------------------------------------------------------------- +class CMeshBase : public IMesh +{ + // Methods of IMesh +public: + + // Other public methods that need to be overridden +public: + // Begins a pass + virtual void BeginPass( ) = 0; + + // Draws a single pass of the mesh + virtual void RenderPass() = 0; + + // Does it have a color mesh? + virtual bool HasColorMesh() const = 0; + + // Am I using morph data? + virtual bool IsUsingMorphData() const = 0; + + virtual bool HasFlexMesh() const = 0; + + virtual IMesh *GetMesh() { return this; } + +public: + // constructor, destructor + CMeshBase(); + virtual ~CMeshBase(); + +}; + +//----------------------------------------------------------------------------- +// Utility method for VertexDesc_t (don't want to expose it in public, in imesh.h) +//----------------------------------------------------------------------------- +inline void ComputeVertexDesc( unsigned char * pBuffer, VertexFormat_t vertexFormat, VertexDesc_t & desc ) +{ + int i; + int *pVertexSizesToSet[64]; + int nVertexSizesToSet = 0; + static ALIGN32 ModelVertexDX8_t temp[4]; + float *dummyData = (float*)&temp; // should be larger than any CMeshBuilder command can set. + + // Determine which vertex compression type this format specifies (affects element sizes/decls): + VertexCompressionType_t compression = CompressionType( vertexFormat ); + desc.m_CompressionType = compression; + + // We use fvf instead of flags here because we may pad out the fvf + // vertex structure to optimize performance + int offset = 0; + // NOTE: At the moment, we assume that if you specify wrinkle, you also specify position + Assert( ( ( vertexFormat & VERTEX_WRINKLE ) == 0 ) || ( ( vertexFormat & VERTEX_POSITION ) != 0 ) ); + if ( vertexFormat & VERTEX_POSITION ) + { + // UNDONE: compress position+wrinkle to SHORT4N, and roll the scale into the transform matrices + desc.m_pPosition = reinterpret_cast(pBuffer); + offset += GetVertexElementSize( VERTEX_ELEMENT_POSITION, compression ); + pVertexSizesToSet[nVertexSizesToSet++] = &desc.m_VertexSize_Position; + + if ( vertexFormat & VERTEX_WRINKLE ) + { + desc.m_pWrinkle = reinterpret_cast( pBuffer + offset ); + offset += GetVertexElementSize( VERTEX_ELEMENT_WRINKLE, compression ); + pVertexSizesToSet[nVertexSizesToSet++] = &desc.m_VertexSize_Wrinkle; + } + else + { + desc.m_pWrinkle = dummyData; + desc.m_VertexSize_Wrinkle = 0; + } + } + else + { + desc.m_pPosition = dummyData; + desc.m_VertexSize_Position = 0; + desc.m_pWrinkle = dummyData; + desc.m_VertexSize_Wrinkle = 0; + } + + // Bone weights/matrix indices + desc.m_NumBoneWeights = NumBoneWeights( vertexFormat ); + + Assert( ( desc.m_NumBoneWeights == 2 ) || ( desc.m_NumBoneWeights == 0 ) ); + + // We assume that if you have any indices/weights, you have exactly two of them + Assert( ( ( desc.m_NumBoneWeights == 2 ) && ( ( vertexFormat & VERTEX_BONE_INDEX ) != 0 ) ) || + ( ( desc.m_NumBoneWeights == 0 ) && ( ( vertexFormat & VERTEX_BONE_INDEX ) == 0 ) ) ); + + if ( ( vertexFormat & VERTEX_BONE_INDEX ) != 0 ) + { + if ( desc.m_NumBoneWeights > 0 ) + { + Assert( desc.m_NumBoneWeights == 2 ); + + // Always exactly two weights + desc.m_pBoneWeight = reinterpret_cast(pBuffer + offset); + offset += GetVertexElementSize( VERTEX_ELEMENT_BONEWEIGHTS2, compression ); + pVertexSizesToSet[nVertexSizesToSet++] = &desc.m_VertexSize_BoneWeight; + } + else + { + desc.m_pBoneWeight = dummyData; + desc.m_VertexSize_BoneWeight = 0; + } + + desc.m_pBoneMatrixIndex = pBuffer + offset; + offset += GetVertexElementSize( VERTEX_ELEMENT_BONEINDEX, compression ); + pVertexSizesToSet[nVertexSizesToSet++] = &desc.m_VertexSize_BoneMatrixIndex; + } + else + { + desc.m_pBoneWeight = dummyData; + desc.m_VertexSize_BoneWeight = 0; + + desc.m_pBoneMatrixIndex = (unsigned char*)dummyData; + desc.m_VertexSize_BoneMatrixIndex = 0; + } + + if ( vertexFormat & VERTEX_NORMAL ) + { + desc.m_pNormal = reinterpret_cast(pBuffer + offset); + // See PackNormal_[SHORT2|UBYTE4|HEND3N] in mathlib.h for the compression algorithm + offset += GetVertexElementSize( VERTEX_ELEMENT_NORMAL, compression ); + pVertexSizesToSet[nVertexSizesToSet++] = &desc.m_VertexSize_Normal; + } + else + { + desc.m_pNormal = dummyData; + desc.m_VertexSize_Normal = 0; + } + + if ( vertexFormat & VERTEX_COLOR ) + { + desc.m_pColor = pBuffer + offset; + offset += GetVertexElementSize( VERTEX_ELEMENT_COLOR, compression ); + pVertexSizesToSet[nVertexSizesToSet++] = &desc.m_VertexSize_Color; + } + else + { + desc.m_pColor = (unsigned char*)dummyData; + desc.m_VertexSize_Color = 0; + } + + if ( vertexFormat & VERTEX_SPECULAR ) + { + desc.m_pSpecular = pBuffer + offset; + offset += GetVertexElementSize( VERTEX_ELEMENT_SPECULAR, compression ); + pVertexSizesToSet[nVertexSizesToSet++] = &desc.m_VertexSize_Specular; + } + else + { + desc.m_pSpecular = (unsigned char*)dummyData; + desc.m_VertexSize_Specular = 0; + } + + // Set up texture coordinates + for ( i = 0; i < VERTEX_MAX_TEXTURE_COORDINATES; ++i ) + { + // FIXME: compress texcoords to SHORT2N/SHORT4N, with a scale rolled into the texture transform + VertexElement_t texCoordElements[4] = { VERTEX_ELEMENT_TEXCOORD1D_0, VERTEX_ELEMENT_TEXCOORD2D_0, VERTEX_ELEMENT_TEXCOORD3D_0, VERTEX_ELEMENT_TEXCOORD4D_0 }; + int nSize = TexCoordSize( i, vertexFormat ); + if ( nSize != 0 ) + { + desc.m_pTexCoord[i] = reinterpret_cast(pBuffer + offset); + VertexElement_t texCoordElement = (VertexElement_t)( texCoordElements[ nSize - 1 ] + i ); + offset += GetVertexElementSize( texCoordElement, compression ); + pVertexSizesToSet[nVertexSizesToSet++] = &desc.m_VertexSize_TexCoord[i]; + } + else + { + desc.m_pTexCoord[i] = dummyData; + desc.m_VertexSize_TexCoord[i] = 0; + } + } + + // Binormal + tangent... + // Note we have to put these at the end so the vertex is FVF + stuff at end + if ( vertexFormat & VERTEX_TANGENT_S ) + { + // UNDONE: use normal compression here (use mem_dumpvballocs to see if this uses much memory) + desc.m_pTangentS = reinterpret_cast(pBuffer + offset); + offset += GetVertexElementSize( VERTEX_ELEMENT_TANGENT_S, compression ); + pVertexSizesToSet[nVertexSizesToSet++] = &desc.m_VertexSize_TangentS; + } + else + { + desc.m_pTangentS = dummyData; + desc.m_VertexSize_TangentS = 0; + } + + if ( vertexFormat & VERTEX_TANGENT_T ) + { + // UNDONE: use normal compression here (use mem_dumpvballocs to see if this uses much memory) + desc.m_pTangentT = reinterpret_cast(pBuffer + offset); + offset += GetVertexElementSize( VERTEX_ELEMENT_TANGENT_T, compression ); + pVertexSizesToSet[nVertexSizesToSet++] = &desc.m_VertexSize_TangentT; + } + else + { + desc.m_pTangentT = dummyData; + desc.m_VertexSize_TangentT = 0; + } + + // User data.. + int userDataSize = UserDataSize( vertexFormat ); + if ( userDataSize > 0 ) + { + desc.m_pUserData = reinterpret_cast(pBuffer + offset); + VertexElement_t userDataElement = (VertexElement_t)( VERTEX_ELEMENT_USERDATA1 + ( userDataSize - 1 ) ); + // See PackNormal_[SHORT2|UBYTE4|HEND3N] in mathlib.h for the compression algorithm + offset += GetVertexElementSize( userDataElement, compression ); + + pVertexSizesToSet[nVertexSizesToSet++] = &desc.m_VertexSize_UserData; + } + else + { + desc.m_pUserData = dummyData; + desc.m_VertexSize_UserData = 0; + } + + // We always use vertex sizes which are half-cache aligned (16 bytes) + // x360 compressed vertexes are not compatible with forced alignments + bool bCacheAlign = ( vertexFormat & VERTEX_FORMAT_USE_EXACT_FORMAT ) == 0; + if ( bCacheAlign && ( offset > 16 ) && IsPC() ) + { + offset = (offset + 0xF) & (~0xF); + } + desc.m_ActualVertexSize = offset; + + // Now set the m_VertexSize for all the members that were actually valid. + Assert( nVertexSizesToSet < sizeof(pVertexSizesToSet)/sizeof(pVertexSizesToSet[0]) ); + for ( int iElement=0; iElement < nVertexSizesToSet; iElement++ ) + { + *pVertexSizesToSet[iElement] = offset; + } +} + +#endif // MESHBASE_H diff --git a/materialsystem/shaderapidx9/meshdx10.cpp b/materialsystem/shaderapidx9/meshdx10.cpp new file mode 100644 index 0000000..b1a892c --- /dev/null +++ b/materialsystem/shaderapidx9/meshdx10.cpp @@ -0,0 +1,775 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +// +//===========================================================================// + +#include +#undef GetCommandLine + +#include "meshdx10.h" +#include "utlvector.h" +#include "materialsystem/imaterialsystem.h" +#include "IHardwareConfigInternal.h" +#include "shaderapi_global.h" +#include "shaderapi/ishaderutil.h" +#include "shaderapi/ishaderapi.h" +#include "shaderdevicedx10.h" +#include "materialsystem/imesh.h" +#include "tier0/vprof.h" +#include "tier0/dbg.h" +#include "materialsystem/idebugtextureinfo.h" +#include "materialsystem/ivballoctracker.h" +#include "tier2/tier2.h" + + +//----------------------------------------------------------------------------- +// +// Dx10 implementation of a vertex buffer +// +//----------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +// globals +//----------------------------------------------------------------------------- +#ifdef _DEBUG +int CVertexBufferDx10::s_nBufferCount = 0; +#endif + + +//----------------------------------------------------------------------------- +// constructor, destructor +//----------------------------------------------------------------------------- +CVertexBufferDx10::CVertexBufferDx10( ShaderBufferType_t type, VertexFormat_t fmt, int nVertexCount, const char *pBudgetGroupName ) : + BaseClass( pBudgetGroupName ) +{ + Assert( nVertexCount != 0 ); + + m_pVertexBuffer = NULL; + m_VertexFormat = fmt; + m_nVertexCount = ( fmt == VERTEX_FORMAT_UNKNOWN ) ? 0 : nVertexCount; + m_nBufferSize = ( fmt == VERTEX_FORMAT_UNKNOWN ) ? nVertexCount : nVertexCount * VertexSize(); + m_nFirstUnwrittenOffset = 0; + m_bIsLocked = false; + m_bIsDynamic = ( type == SHADER_BUFFER_TYPE_DYNAMIC ) || ( type == SHADER_BUFFER_TYPE_DYNAMIC_TEMP ); + m_bFlush = false; +} + +CVertexBufferDx10::~CVertexBufferDx10() +{ + Free(); +} + + +//----------------------------------------------------------------------------- +// Creates, destroys the vertex buffer +//----------------------------------------------------------------------------- +bool CVertexBufferDx10::Allocate( ) +{ + Assert( !m_pVertexBuffer ); + + m_nFirstUnwrittenOffset = 0; + + D3D10_BUFFER_DESC bd; + bd.Usage = D3D10_USAGE_DYNAMIC; + bd.ByteWidth = m_nBufferSize; + bd.BindFlags = D3D10_BIND_VERTEX_BUFFER; + bd.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE; + bd.MiscFlags = 0; + + HRESULT hr = D3D10Device()->CreateBuffer( &bd, NULL, &m_pVertexBuffer ); + bool bOk = !FAILED( hr ) && ( m_pVertexBuffer != 0 ); + + if ( bOk ) + { + // Track VB allocations + g_VBAllocTracker->CountVB( m_pVertexBuffer, m_bIsDynamic, m_nBufferSize, VertexSize(), GetVertexFormat() ); + + if ( !m_bIsDynamic ) + { + VPROF_INCREMENT_GROUP_COUNTER( "TexGroup_global_" TEXTURE_GROUP_STATIC_INDEX_BUFFER, + COUNTER_GROUP_TEXTURE_GLOBAL, m_nBufferSize ); + } + else + { + VPROF_INCREMENT_GROUP_COUNTER( "TexGroup_global_" TEXTURE_GROUP_DYNAMIC_INDEX_BUFFER, + COUNTER_GROUP_TEXTURE_GLOBAL, m_nBufferSize ); + // Dynamic meshes should never be compressed (slows down writing to them) + Assert( CompressionType( GetVertexFormat() ) == VERTEX_COMPRESSION_NONE ); + } +#ifdef _DEBUG + ++s_nBufferCount; +#endif + } + + return bOk; +} + +void CVertexBufferDx10::Free() +{ + if ( m_pVertexBuffer ) + { +#ifdef _DEBUG + --s_nBufferCount; +#endif + + // Track VB allocations + g_VBAllocTracker->UnCountVB( m_pVertexBuffer ); + + m_pVertexBuffer->Release(); + m_pVertexBuffer = NULL; + + if ( !m_bIsDynamic ) + { + VPROF_INCREMENT_GROUP_COUNTER( "TexGroup_global_" TEXTURE_GROUP_STATIC_INDEX_BUFFER, + COUNTER_GROUP_TEXTURE_GLOBAL, - m_nBufferSize ); + } + else + { + VPROF_INCREMENT_GROUP_COUNTER( "TexGroup_global_" TEXTURE_GROUP_DYNAMIC_INDEX_BUFFER, + COUNTER_GROUP_TEXTURE_GLOBAL, - m_nBufferSize ); + } + } +} + + +//----------------------------------------------------------------------------- +// Vertex Buffer info +//----------------------------------------------------------------------------- +int CVertexBufferDx10::VertexCount() const +{ + Assert( !m_bIsDynamic ); + return m_nVertexCount; +} + + +//----------------------------------------------------------------------------- +// Returns the buffer format (only valid for static index buffers) +//----------------------------------------------------------------------------- +VertexFormat_t CVertexBufferDx10::GetVertexFormat() const +{ + Assert( !m_bIsDynamic ); + return m_VertexFormat; +} + + +//----------------------------------------------------------------------------- +// Returns true if the buffer is dynamic +//----------------------------------------------------------------------------- +bool CVertexBufferDx10::IsDynamic() const +{ + return m_bIsDynamic; +} + + +//----------------------------------------------------------------------------- +// Only used by dynamic buffers, indicates the next lock should perform a discard. +//----------------------------------------------------------------------------- +void CVertexBufferDx10::Flush() +{ + // This strange-looking line makes a flush only occur if the buffer is dynamic. + m_bFlush = m_bIsDynamic; +} + + +//----------------------------------------------------------------------------- +// Casts a dynamic buffer to be a particular vertex type +//----------------------------------------------------------------------------- +void CVertexBufferDx10::BeginCastBuffer( VertexFormat_t format ) +{ + Assert( format != MATERIAL_INDEX_FORMAT_UNKNOWN ); + Assert( m_bIsDynamic && ( m_VertexFormat == 0 || m_VertexFormat == format ) ); + if ( !m_bIsDynamic ) + return; + + m_VertexFormat = format; + m_nVertexCount = m_nBufferSize / VertexSize(); +} + +void CVertexBufferDx10::EndCastBuffer( ) +{ + Assert( m_bIsDynamic && m_VertexFormat != 0 ); + if ( !m_bIsDynamic ) + return; + m_VertexFormat = 0; + m_nVertexCount = 0; +} + + +//----------------------------------------------------------------------------- +// Returns the number of indices that can be written into the buffer +//----------------------------------------------------------------------------- +int CVertexBufferDx10::GetRoomRemaining() const +{ + return ( m_nBufferSize - m_nFirstUnwrittenOffset ) / VertexSize(); +} + + +//----------------------------------------------------------------------------- +// Lock, unlock +//----------------------------------------------------------------------------- +bool CVertexBufferDx10::Lock( int nMaxVertexCount, bool bAppend, VertexDesc_t &desc ) +{ + Assert( !m_bIsLocked && ( nMaxVertexCount != 0 ) && ( nMaxVertexCount <= m_nVertexCount ) ); + Assert( m_VertexFormat != 0 ); + + // FIXME: Why do we need to sync matrices now? + ShaderUtil()->SyncMatrices(); + g_ShaderMutex.Lock(); + + void *pLockedData = NULL; + HRESULT hr; + + // This can happen if the buffer was locked but a type wasn't bound + if ( m_VertexFormat == 0 ) + goto vertexBufferLockFailed; + + // Just give the app crap buffers to fill up while we're suppressed... + if ( g_pShaderDevice->IsDeactivated() || ( nMaxVertexCount == 0 ) ) + goto vertexBufferLockFailed; + + // Did we ask for something too large? + if ( nMaxVertexCount > m_nVertexCount ) + { + Warning( "Too many vertices for vertex buffer. . tell a programmer (%d>%d)\n", nMaxVertexCount, m_nVertexCount ); + goto vertexBufferLockFailed; + } + + // We might not have a buffer owing to alt-tab type stuff + if ( !m_pVertexBuffer ) + { + if ( !Allocate() ) + goto vertexBufferLockFailed; + } + + // Check to see if we have enough memory + int nMemoryRequired = nMaxVertexCount * VertexSize(); + bool bHasEnoughMemory = ( m_nFirstUnwrittenOffset + nMemoryRequired <= m_nBufferSize ); + + D3D10_MAP map; + if ( bAppend ) + { + // Can't have the first lock after a flush be an appending lock + Assert( !m_bFlush ); + + // If we're appending and we don't have enough room, then puke! + if ( !bHasEnoughMemory || m_bFlush ) + goto vertexBufferLockFailed; + map = ( m_nFirstUnwrittenOffset == 0 ) ? D3D10_MAP_WRITE_DISCARD : D3D10_MAP_WRITE_NO_OVERWRITE; + } + else + { + // If we're not appending, no overwrite unless we don't have enough room + // If we're a static buffer, always discard if we're not appending + if ( !m_bFlush && bHasEnoughMemory && m_bIsDynamic ) + { + map = ( m_nFirstUnwrittenOffset == 0 ) ? D3D10_MAP_WRITE_DISCARD : D3D10_MAP_WRITE_NO_OVERWRITE; + } + else + { + map = D3D10_MAP_WRITE_DISCARD; + m_nFirstUnwrittenOffset = 0; + m_bFlush = false; + } + } + + hr = m_pVertexBuffer->Map( map, 0, &pLockedData ); + if ( FAILED( hr ) ) + { + Warning( "Failed to lock vertex buffer in CVertexBufferDx10::Lock\n" ); + goto vertexBufferLockFailed; + } + + ComputeVertexDescription( (unsigned char*)pLockedData + m_nFirstUnwrittenOffset, m_VertexFormat, desc ); + desc.m_nFirstVertex = 0; + desc.m_nOffset = m_nFirstUnwrittenOffset; + m_bIsLocked = true; + return true; + +vertexBufferLockFailed: + g_ShaderMutex.Unlock(); + + // Set up a bogus index descriptor + ComputeVertexDescription( 0, 0, desc ); + desc.m_nFirstVertex = 0; + desc.m_nOffset = 0; + return false; +} + +void CVertexBufferDx10::Unlock( int nWrittenVertexCount, VertexDesc_t &desc ) +{ + Assert( nWrittenVertexCount <= m_nVertexCount ); + + // NOTE: This can happen if the lock occurs during alt-tab + // or if another application is initializing + if ( !m_bIsLocked ) + return; + + if ( m_pVertexBuffer ) + { + m_pVertexBuffer->Unmap(); + } + + m_nFirstUnwrittenOffset += nWrittenVertexCount * VertexSize(); + m_bIsLocked = false; + g_ShaderMutex.Unlock(); +} + + +//----------------------------------------------------------------------------- +// +// Dx10 implementation of an index buffer +// +//----------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +// globals +//----------------------------------------------------------------------------- + +// shove indices into this if you don't actually want indices +static unsigned int s_nScratchIndexBuffer = 0; + +#ifdef _DEBUG +int CIndexBufferDx10::s_nBufferCount = 0; +#endif + + +//----------------------------------------------------------------------------- +// constructor, destructor +//----------------------------------------------------------------------------- +CIndexBufferDx10::CIndexBufferDx10( ShaderBufferType_t type, MaterialIndexFormat_t fmt, int nIndexCount, const char *pBudgetGroupName ) : + BaseClass( pBudgetGroupName ) +{ + Assert( nIndexCount != 0 ); + Assert( IsDynamicBufferType( type ) || ( fmt != MATERIAL_INDEX_FORMAT_UNKNOWN ) ); + + m_pIndexBuffer = NULL; + m_IndexFormat = fmt; + m_nIndexCount = ( fmt == MATERIAL_INDEX_FORMAT_UNKNOWN ) ? 0 : nIndexCount; + m_nBufferSize = ( fmt == MATERIAL_INDEX_FORMAT_UNKNOWN ) ? nIndexCount : nIndexCount * IndexSize(); + m_nFirstUnwrittenOffset = 0; + m_bIsLocked = false; + m_bIsDynamic = IsDynamicBufferType( type ); + m_bFlush = false; + + // NOTE: This has to happen at the end since m_IndexFormat must be valid for IndexSize() to work + if ( m_bIsDynamic ) + { + m_IndexFormat = MATERIAL_INDEX_FORMAT_UNKNOWN; + m_nIndexCount = 0; + } +} + +CIndexBufferDx10::~CIndexBufferDx10() +{ + Free(); +} + + +//----------------------------------------------------------------------------- +// Creates, destroys the index buffer +//----------------------------------------------------------------------------- +bool CIndexBufferDx10::Allocate( ) +{ + Assert( !m_pIndexBuffer ); + + m_nFirstUnwrittenOffset = 0; + + D3D10_BUFFER_DESC bd; + bd.Usage = D3D10_USAGE_DYNAMIC; + bd.ByteWidth = m_nBufferSize; + bd.BindFlags = D3D10_BIND_INDEX_BUFFER; + bd.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE; + bd.MiscFlags = 0; + + HRESULT hr = D3D10Device()->CreateBuffer( &bd, NULL, &m_pIndexBuffer ); + bool bOk = !FAILED( hr ) && ( m_pIndexBuffer != NULL ); + + if ( bOk ) + { + if ( !m_bIsDynamic ) + { + VPROF_INCREMENT_GROUP_COUNTER( "TexGroup_global_" TEXTURE_GROUP_STATIC_INDEX_BUFFER, + COUNTER_GROUP_TEXTURE_GLOBAL, m_nBufferSize ); + } + else + { + VPROF_INCREMENT_GROUP_COUNTER( "TexGroup_global_" TEXTURE_GROUP_DYNAMIC_INDEX_BUFFER, + COUNTER_GROUP_TEXTURE_GLOBAL, m_nBufferSize ); + } +#ifdef _DEBUG + ++s_nBufferCount; +#endif + } + + return bOk; +} + +void CIndexBufferDx10::Free() +{ + if ( m_pIndexBuffer ) + { +#ifdef _DEBUG + --s_nBufferCount; +#endif + + m_pIndexBuffer->Release(); + m_pIndexBuffer = NULL; + + if ( !m_bIsDynamic ) + { + VPROF_INCREMENT_GROUP_COUNTER( "TexGroup_global_" TEXTURE_GROUP_STATIC_INDEX_BUFFER, + COUNTER_GROUP_TEXTURE_GLOBAL, - m_nBufferSize ); + } + else + { + VPROF_INCREMENT_GROUP_COUNTER( "TexGroup_global_" TEXTURE_GROUP_DYNAMIC_INDEX_BUFFER, + COUNTER_GROUP_TEXTURE_GLOBAL, - m_nBufferSize ); + } + } +} + + +//----------------------------------------------------------------------------- +// Returns the buffer size (only valid for static index buffers) +//----------------------------------------------------------------------------- +int CIndexBufferDx10::IndexCount() const +{ + Assert( !m_bIsDynamic ); + return m_nIndexCount; +} + + +//----------------------------------------------------------------------------- +// Returns the buffer format (only valid for static index buffers) +//----------------------------------------------------------------------------- +MaterialIndexFormat_t CIndexBufferDx10::IndexFormat() const +{ + Assert( !m_bIsDynamic ); + return m_IndexFormat; +} + + +//----------------------------------------------------------------------------- +// Returns true if the buffer is dynamic +//----------------------------------------------------------------------------- +bool CIndexBufferDx10::IsDynamic() const +{ + return m_bIsDynamic; +} + + +//----------------------------------------------------------------------------- +// Only used by dynamic buffers, indicates the next lock should perform a discard. +//----------------------------------------------------------------------------- +void CIndexBufferDx10::Flush() +{ + // This strange-looking line makes a flush only occur if the buffer is dynamic. + m_bFlush = m_bIsDynamic; +} + + +//----------------------------------------------------------------------------- +// Casts a dynamic buffer to be a particular index type +//----------------------------------------------------------------------------- +void CIndexBufferDx10::BeginCastBuffer( MaterialIndexFormat_t format ) +{ + Assert( format != MATERIAL_INDEX_FORMAT_UNKNOWN ); + Assert( m_bIsDynamic && ( m_IndexFormat == MATERIAL_INDEX_FORMAT_UNKNOWN || m_IndexFormat == format ) ); + if ( !m_bIsDynamic ) + return; + + m_IndexFormat = format; + m_nIndexCount = m_nBufferSize / IndexSize(); +} + +void CIndexBufferDx10::EndCastBuffer( ) +{ + Assert( m_bIsDynamic && m_IndexFormat != MATERIAL_INDEX_FORMAT_UNKNOWN ); + if ( !m_bIsDynamic ) + return; + m_IndexFormat = MATERIAL_INDEX_FORMAT_UNKNOWN; + m_nIndexCount = 0; +} + + +//----------------------------------------------------------------------------- +// Returns the number of indices that can be written into the buffer +//----------------------------------------------------------------------------- +int CIndexBufferDx10::GetRoomRemaining() const +{ + return ( m_nBufferSize - m_nFirstUnwrittenOffset ) / IndexSize(); +} + + +//----------------------------------------------------------------------------- +// Locks, unlocks the mesh +//----------------------------------------------------------------------------- +bool CIndexBufferDx10::Lock( int nMaxIndexCount, bool bAppend, IndexDesc_t &desc ) +{ + Assert( !m_bIsLocked && ( nMaxIndexCount != 0 ) && ( nMaxIndexCount <= m_nIndexCount ) ); + Assert( m_IndexFormat != MATERIAL_INDEX_FORMAT_UNKNOWN ); + + // FIXME: Why do we need to sync matrices now? + ShaderUtil()->SyncMatrices(); + g_ShaderMutex.Lock(); + + void *pLockedData = NULL; + HRESULT hr; + + // This can happen if the buffer was locked but a type wasn't bound + if ( m_IndexFormat == MATERIAL_INDEX_FORMAT_UNKNOWN ) + goto indexBufferLockFailed; + + // Just give the app crap buffers to fill up while we're suppressed... + if ( g_pShaderDevice->IsDeactivated() || ( nMaxIndexCount == 0 ) ) + goto indexBufferLockFailed; + + // Did we ask for something too large? + if ( nMaxIndexCount > m_nIndexCount ) + { + Warning( "Too many indices for index buffer. . tell a programmer (%d>%d)\n", nMaxIndexCount, m_nIndexCount ); + goto indexBufferLockFailed; + } + + // We might not have a buffer owing to alt-tab type stuff + if ( !m_pIndexBuffer ) + { + if ( !Allocate() ) + goto indexBufferLockFailed; + } + + // Check to see if we have enough memory + int nMemoryRequired = nMaxIndexCount * IndexSize(); + bool bHasEnoughMemory = ( m_nFirstUnwrittenOffset + nMemoryRequired <= m_nBufferSize ); + + D3D10_MAP map; + if ( bAppend ) + { + // Can't have the first lock after a flush be an appending lock + Assert( !m_bFlush ); + + // If we're appending and we don't have enough room, then puke! + if ( !bHasEnoughMemory || m_bFlush ) + goto indexBufferLockFailed; + map = ( m_nFirstUnwrittenOffset == 0 ) ? D3D10_MAP_WRITE_DISCARD : D3D10_MAP_WRITE_NO_OVERWRITE; + } + else + { + // If we're not appending, no overwrite unless we don't have enough room + if ( !m_bFlush && bHasEnoughMemory && m_bIsDynamic ) + { + map = ( m_nFirstUnwrittenOffset == 0 ) ? D3D10_MAP_WRITE_DISCARD : D3D10_MAP_WRITE_NO_OVERWRITE; + } + else + { + map = D3D10_MAP_WRITE_DISCARD; + m_nFirstUnwrittenOffset = 0; + m_bFlush = false; + } + } + + hr = m_pIndexBuffer->Map( map, 0, &pLockedData ); + if ( FAILED( hr ) ) + { + Warning( "Failed to lock index buffer in CIndexBufferDx10::Lock\n" ); + goto indexBufferLockFailed; + } + + desc.m_pIndices = (unsigned short*)( (unsigned char*)pLockedData + m_nFirstUnwrittenOffset ); + desc.m_nIndexSize = IndexSize() >> 1; + desc.m_nFirstIndex = 0; + desc.m_nOffset = m_nFirstUnwrittenOffset; + m_bIsLocked = true; + return true; + +indexBufferLockFailed: + g_ShaderMutex.Unlock(); + + // Set up a bogus index descriptor + desc.m_pIndices = (unsigned short*)( &s_nScratchIndexBuffer ); + desc.m_nFirstIndex = 0; + desc.m_nIndexSize = 0; + desc.m_nOffset = 0; + return false; +} + +void CIndexBufferDx10::Unlock( int nWrittenIndexCount, IndexDesc_t &desc ) +{ + Assert( nWrittenIndexCount <= m_nIndexCount ); + + // NOTE: This can happen if the lock occurs during alt-tab + // or if another application is initializing + if ( !m_bIsLocked ) + return; + + if ( m_pIndexBuffer ) + { + m_pIndexBuffer->Unmap(); + } + + m_nFirstUnwrittenOffset += nWrittenIndexCount * IndexSize(); + m_bIsLocked = false; + g_ShaderMutex.Unlock(); +} + + +//----------------------------------------------------------------------------- +// Locks, unlocks an existing mesh +//----------------------------------------------------------------------------- +void CIndexBufferDx10::ModifyBegin( bool bReadOnly, int nFirstIndex, int nIndexCount, IndexDesc_t& desc ) +{ + Assert( 0 ); +} + +void CIndexBufferDx10::ModifyEnd( IndexDesc_t& desc ) +{ + +} + + +//----------------------------------------------------------------------------- +// +// The empty mesh... +// +//----------------------------------------------------------------------------- +CMeshDx10::CMeshDx10() +{ + m_pVertexMemory = new unsigned char[VERTEX_BUFFER_SIZE]; +} + +CMeshDx10::~CMeshDx10() +{ + delete[] m_pVertexMemory; +} + +void CMeshDx10::LockMesh( int numVerts, int numIndices, MeshDesc_t& desc ) +{ + // Who cares about the data? + desc.m_pPosition = (float*)m_pVertexMemory; + desc.m_pNormal = (float*)m_pVertexMemory; + desc.m_pColor = m_pVertexMemory; + int i; + for ( i = 0; i < VERTEX_MAX_TEXTURE_COORDINATES; ++i) + desc.m_pTexCoord[i] = (float*)m_pVertexMemory; + desc.m_pIndices = (unsigned short*)m_pVertexMemory; + + desc.m_pBoneWeight = (float*)m_pVertexMemory; + desc.m_pBoneMatrixIndex = (unsigned char*)m_pVertexMemory; + desc.m_pTangentS = (float*)m_pVertexMemory; + desc.m_pTangentT = (float*)m_pVertexMemory; + desc.m_pUserData = (float*)m_pVertexMemory; + desc.m_NumBoneWeights = 2; + + desc.m_VertexSize_Position = 0; + desc.m_VertexSize_BoneWeight = 0; + desc.m_VertexSize_BoneMatrixIndex = 0; + desc.m_VertexSize_Normal = 0; + desc.m_VertexSize_Color = 0; + for( i=0; i < VERTEX_MAX_TEXTURE_COORDINATES; i++ ) + desc.m_VertexSize_TexCoord[i] = 0; + desc.m_VertexSize_TangentS = 0; + desc.m_VertexSize_TangentT = 0; + desc.m_VertexSize_UserData = 0; + desc.m_ActualVertexSize = 0; // Size of the vertices.. Some of the m_VertexSize_ elements above + + desc.m_nFirstVertex = 0; + desc.m_nIndexSize = 0; +} + +void CMeshDx10::UnlockMesh( int numVerts, int numIndices, MeshDesc_t& desc ) +{ +} + +void CMeshDx10::ModifyBeginEx( bool bReadOnly, int firstVertex, int numVerts, int firstIndex, int numIndices, MeshDesc_t& desc ) +{ + // Who cares about the data? + desc.m_pPosition = (float*)m_pVertexMemory; + desc.m_pNormal = (float*)m_pVertexMemory; + desc.m_pColor = m_pVertexMemory; + int i; + for ( i = 0; i < VERTEX_MAX_TEXTURE_COORDINATES; ++i) + desc.m_pTexCoord[i] = (float*)m_pVertexMemory; + desc.m_pIndices = (unsigned short*)m_pVertexMemory; + + desc.m_pBoneWeight = (float*)m_pVertexMemory; + desc.m_pBoneMatrixIndex = (unsigned char*)m_pVertexMemory; + desc.m_pTangentS = (float*)m_pVertexMemory; + desc.m_pTangentT = (float*)m_pVertexMemory; + desc.m_pUserData = (float*)m_pVertexMemory; + desc.m_NumBoneWeights = 2; + + desc.m_VertexSize_Position = 0; + desc.m_VertexSize_BoneWeight = 0; + desc.m_VertexSize_BoneMatrixIndex = 0; + desc.m_VertexSize_Normal = 0; + desc.m_VertexSize_Color = 0; + for( i=0; i < VERTEX_MAX_TEXTURE_COORDINATES; i++ ) + desc.m_VertexSize_TexCoord[i] = 0; + desc.m_VertexSize_TangentS = 0; + desc.m_VertexSize_TangentT = 0; + desc.m_VertexSize_UserData = 0; + desc.m_ActualVertexSize = 0; // Size of the vertices.. Some of the m_VertexSize_ elements above + + desc.m_nFirstVertex = 0; + desc.m_nIndexSize = 0; +} + +void CMeshDx10::ModifyBegin( int firstVertex, int numVerts, int firstIndex, int numIndices, MeshDesc_t& desc ) +{ + ModifyBeginEx( false, firstVertex, numVerts, firstIndex, numIndices, desc ); +} + +void CMeshDx10::ModifyEnd( MeshDesc_t& desc ) +{ +} + +// returns the # of vertices (static meshes only) +int CMeshDx10::VertexCount() const +{ + return 0; +} + +// Sets the primitive type +void CMeshDx10::SetPrimitiveType( MaterialPrimitiveType_t type ) +{ +} + +// Draws the entire mesh +void CMeshDx10::Draw( int firstIndex, int numIndices ) +{ +} + +void CMeshDx10::Draw(CPrimList *pPrims, int nPrims) +{ +} + +// Copy verts and/or indices to a mesh builder. This only works for temp meshes! +void CMeshDx10::CopyToMeshBuilder( + int iStartVert, // Which vertices to copy. + int nVerts, + int iStartIndex, // Which indices to copy. + int nIndices, + int indexOffset, // This is added to each index. + CMeshBuilder &builder ) +{ +} + +// Spews the mesh data +void CMeshDx10::Spew( int numVerts, int numIndices, const MeshDesc_t & desc ) +{ +} + +void CMeshDx10::ValidateData( int numVerts, int numIndices, const MeshDesc_t & desc ) +{ +} + +// gets the associated material +IMaterial* CMeshDx10::GetMaterial() +{ + // umm. this don't work none + Assert(0); + return 0; +} diff --git a/materialsystem/shaderapidx9/meshdx10.h b/materialsystem/shaderapidx9/meshdx10.h new file mode 100644 index 0000000..2279612 --- /dev/null +++ b/materialsystem/shaderapidx9/meshdx10.h @@ -0,0 +1,282 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +// +//===========================================================================// + + +#ifndef MESHDX10_H +#define MESHDX10_H + +#ifdef _WIN32 +#pragma once +#endif + +#include "meshbase.h" +#include "shaderapi/ishaderdevice.h" + + +//----------------------------------------------------------------------------- +// Forward declaration +//----------------------------------------------------------------------------- +struct ID3D10Buffer; + + +//----------------------------------------------------------------------------- +// Dx10 implementation of a vertex buffer +//----------------------------------------------------------------------------- +class CVertexBufferDx10 : public CVertexBufferBase +{ + typedef CVertexBufferBase BaseClass; + + // Methods of IVertexBuffer +public: + virtual int VertexCount() const; + virtual VertexFormat_t GetVertexFormat() const; + virtual bool Lock( int nMaxVertexCount, bool bAppend, VertexDesc_t &desc ); + virtual void Unlock( int nWrittenVertexCount, VertexDesc_t &desc ); + virtual bool IsDynamic() const; + virtual void BeginCastBuffer( VertexFormat_t format ); + virtual void EndCastBuffer( ); + virtual int GetRoomRemaining() const; + + // Other public methods +public: + // constructor, destructor + CVertexBufferDx10( ShaderBufferType_t type, VertexFormat_t fmt, int nVertexCount, const char *pBudgetGroupName ); + virtual ~CVertexBufferDx10(); + + ID3D10Buffer* GetDx10Buffer() const; + int VertexSize() const; + + // Only used by dynamic buffers, indicates the next lock should perform a discard. + void Flush(); + +protected: + // Creates, destroys the index buffer + bool Allocate( ); + void Free(); + + ID3D10Buffer *m_pVertexBuffer; + VertexFormat_t m_VertexFormat; + int m_nVertexCount; + int m_nBufferSize; + int m_nFirstUnwrittenOffset; + bool m_bIsLocked : 1; + bool m_bIsDynamic : 1; + bool m_bFlush : 1; // Used only for dynamic buffers, indicates to discard the next time + +#ifdef _DEBUG + static int s_nBufferCount; +#endif +}; + + +//----------------------------------------------------------------------------- +// inline methods for CVertexBufferDx10 +//----------------------------------------------------------------------------- +inline ID3D10Buffer* CVertexBufferDx10::GetDx10Buffer() const +{ + return m_pVertexBuffer; +} + +inline int CVertexBufferDx10::VertexSize() const +{ + return VertexFormatSize( m_VertexFormat ); +} + + +//----------------------------------------------------------------------------- +// Dx10 implementation of an index buffer +//----------------------------------------------------------------------------- +class CIndexBufferDx10 : public CIndexBufferBase +{ + typedef CIndexBufferBase BaseClass; + + // Methods of IIndexBuffer +public: + virtual int IndexCount() const; + virtual MaterialIndexFormat_t IndexFormat() const; + virtual int GetRoomRemaining() const; + virtual bool Lock( int nMaxIndexCount, bool bAppend, IndexDesc_t &desc ); + virtual void Unlock( int nWrittenIndexCount, IndexDesc_t &desc ); + virtual void ModifyBegin( bool bReadOnly, int nFirstIndex, int nIndexCount, IndexDesc_t& desc ); + virtual void ModifyEnd( IndexDesc_t& desc ); + virtual bool IsDynamic() const; + virtual void BeginCastBuffer( MaterialIndexFormat_t format ); + virtual void EndCastBuffer( ); + + // Other public methods +public: + // constructor, destructor + CIndexBufferDx10( ShaderBufferType_t type, MaterialIndexFormat_t fmt, int nIndexCount, const char *pBudgetGroupName ); + virtual ~CIndexBufferDx10(); + + ID3D10Buffer* GetDx10Buffer() const; + MaterialIndexFormat_t GetIndexFormat() const; + + // Only used by dynamic buffers, indicates the next lock should perform a discard. + void Flush(); + +protected: + // Creates, destroys the index buffer + bool Allocate( ); + void Free(); + + // Returns the size of the index in bytes + int IndexSize() const; + + ID3D10Buffer *m_pIndexBuffer; + MaterialIndexFormat_t m_IndexFormat; + int m_nIndexCount; + int m_nBufferSize; + int m_nFirstUnwrittenOffset; // Used only for dynamic buffers, indicates where it's safe to write (nooverwrite) + bool m_bIsLocked : 1; + bool m_bIsDynamic : 1; + bool m_bFlush : 1; // Used only for dynamic buffers, indicates to discard the next time + +#ifdef _DEBUG + static int s_nBufferCount; +#endif +}; + + +//----------------------------------------------------------------------------- +// Returns the size of the index in bytes +//----------------------------------------------------------------------------- +inline int CIndexBufferDx10::IndexSize() const +{ + switch( m_IndexFormat ) + { + default: + case MATERIAL_INDEX_FORMAT_UNKNOWN: + return 0; + case MATERIAL_INDEX_FORMAT_16BIT: + return 2; + case MATERIAL_INDEX_FORMAT_32BIT: + return 4; + } +} + +inline ID3D10Buffer* CIndexBufferDx10::GetDx10Buffer() const +{ + return m_pIndexBuffer; +} + +inline MaterialIndexFormat_t CIndexBufferDx10::GetIndexFormat() const +{ + return m_IndexFormat; +} + + +//----------------------------------------------------------------------------- +// Dx10 implementation of a mesh +//----------------------------------------------------------------------------- +class CMeshDx10 : public CMeshBase +{ +public: + CMeshDx10(); + virtual ~CMeshDx10(); + + // FIXME: Make this work! Unsupported methods of IIndexBuffer + virtual bool Lock( int nMaxIndexCount, bool bAppend, IndexDesc_t& desc ) { Assert(0); return false; } + virtual void Unlock( int nWrittenIndexCount, IndexDesc_t& desc ) { Assert(0); } + virtual int GetRoomRemaining() const { Assert(0); return 0; } + virtual void ModifyBegin( bool bReadOnly, int nFirstIndex, int nIndexCount, IndexDesc_t& desc ) { Assert(0); } + virtual void ModifyEnd( IndexDesc_t& desc ) { Assert(0); } + virtual void Spew( int nIndexCount, const IndexDesc_t & desc ) { Assert(0); } + virtual void ValidateData( int nIndexCount, const IndexDesc_t &desc ) { Assert(0); } + virtual bool Lock( int nVertexCount, bool bAppend, VertexDesc_t &desc ) { Assert(0); return false; } + virtual void Unlock( int nVertexCount, VertexDesc_t &desc ) { Assert(0); } + virtual void Spew( int nVertexCount, const VertexDesc_t &desc ) { Assert(0); } + virtual void ValidateData( int nVertexCount, const VertexDesc_t & desc ) { Assert(0); } + virtual bool IsDynamic() const { Assert(0); return false; } + virtual void BeginCastBuffer( MaterialIndexFormat_t format ) { Assert(0); } + virtual void BeginCastBuffer( VertexFormat_t format ) { Assert(0); } + virtual void EndCastBuffer( ) { Assert(0); } + + void LockMesh( int numVerts, int numIndices, MeshDesc_t& desc ); + void UnlockMesh( int numVerts, int numIndices, MeshDesc_t& desc ); + + void ModifyBeginEx( bool bReadOnly, int firstVertex, int numVerts, int firstIndex, int numIndices, MeshDesc_t& desc ); + void ModifyBegin( int firstVertex, int numVerts, int firstIndex, int numIndices, MeshDesc_t& desc ); + void ModifyEnd( MeshDesc_t& desc ); + + // returns the # of vertices (static meshes only) + int VertexCount() const; + + virtual void BeginPass( ) {} + virtual void RenderPass() {} + virtual bool HasColorMesh() const { return false; } + virtual bool IsUsingMorphData() const { return false; } + virtual bool HasFlexMesh() const { return false; } + + // Sets the primitive type + void SetPrimitiveType( MaterialPrimitiveType_t type ); + + // Draws the entire mesh + void Draw(int firstIndex, int numIndices); + + void Draw(CPrimList *pPrims, int nPrims); + + // Copy verts and/or indices to a mesh builder. This only works for temp meshes! + virtual void CopyToMeshBuilder( + int iStartVert, // Which vertices to copy. + int nVerts, + int iStartIndex, // Which indices to copy. + int nIndices, + int indexOffset, // This is added to each index. + CMeshBuilder &builder ); + + // Spews the mesh data + void Spew( int numVerts, int numIndices, const MeshDesc_t & desc ); + + void ValidateData( int numVerts, int numIndices, const MeshDesc_t & desc ); + + // gets the associated material + IMaterial* GetMaterial(); + + void SetColorMesh( IMesh *pColorMesh, int nVertexOffset ) + { + } + + + virtual int IndexCount() const + { + return 0; + } + + virtual MaterialIndexFormat_t IndexFormat() const + { + Assert( 0 ); + return MATERIAL_INDEX_FORMAT_UNKNOWN; + } + + virtual void SetFlexMesh( IMesh *pMesh, int nVertexOffset ) {} + + virtual void DisableFlexMesh() {} + + virtual void MarkAsDrawn() {} + + virtual unsigned ComputeMemoryUsed() { return 0; } + + virtual VertexFormat_t GetVertexFormat() const { return VERTEX_POSITION; } + + virtual IMesh *GetMesh() + { + return this; + } + +private: + enum + { + VERTEX_BUFFER_SIZE = 1024 * 1024 + }; + + unsigned char* m_pVertexMemory; +}; + +#endif // MESHDX10_H + diff --git a/materialsystem/shaderapidx9/meshdx8.cpp b/materialsystem/shaderapidx9/meshdx8.cpp new file mode 100644 index 0000000..9a4af9e --- /dev/null +++ b/materialsystem/shaderapidx9/meshdx8.cpp @@ -0,0 +1,5980 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//===========================================================================// + +#define DISABLE_PROTECTED_THINGS +#include "locald3dtypes.h" +#include "imeshdx8.h" +#include "shaderapidx8_global.h" +#include "materialsystem/IShader.h" +#include "tier0/vprof.h" +#include "studio.h" +#include "tier1/fmtstr.h" + +#include "tier0/platform.h" +#include "tier0/systeminformation.h" + +// fixme - stick this in a header file. +#if defined( _DEBUG ) && !defined( _X360 ) +// define this if you want to range check all indices when drawing +#define CHECK_INDICES +#endif +#ifdef CHECK_INDICES +#define CHECK_INDICES_MAX_NUM_STREAMS 2 +#endif + +#include "dynamicib.h" +#include "dynamicvb.h" +#include "utlvector.h" +#include "shaderapi/ishaderapi.h" +#include "imaterialinternal.h" +#include "imaterialsysteminternal.h" +#include "shaderapidx8.h" +#include "shaderapi/ishaderutil.h" +#include "materialsystem/imaterialsystemhardwareconfig.h" +#include "materialsystem/materialsystem_config.h" +#include "materialsystem/ivballoctracker.h" +#include "tier1/strtools.h" +#include "convar.h" +#include "shaderdevicedx8.h" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +//----------------------------------------------------------------------------- +// Uncomment this to test buffered state +//----------------------------------------------------------------------------- +//#define DEBUG_BUFFERED_MESHES 1 + +#define MAX_DX8_STREAMS 16 + +#define VERTEX_FORMAT_INVALID 0xFFFFFFFFFFFFFFFFull + +// this is hooked into the engines convar +extern ConVar mat_debugalttab; + +//#define DRAW_SELECTION 1 +static bool g_bDrawSelection = true; // only used in DRAW_SELECTION +static unsigned short g_nScratchIndexBuffer[6]; // large enough for a fast quad; used when device is not active +#ifdef _DEBUG +int CVertexBuffer::s_BufferCount = 0; +int CIndexBuffer::s_BufferCount = 0; +#endif + +//----------------------------------------------------------------------------- +// Important enumerations +//----------------------------------------------------------------------------- +enum +{ + VERTEX_BUFFER_SIZE = 32768, + MAX_QUAD_INDICES = 16384, +}; + + +//----------------------------------------------------------------------------- +// +// Code related to vertex buffers start here +// +//----------------------------------------------------------------------------- +class CVertexBufferDx8 : public CVertexBufferBase +{ + typedef CVertexBufferBase BaseClass; + + // Methods of IVertexBuffer +public: + virtual int VertexCount() const; + virtual VertexFormat_t GetVertexFormat() const; + virtual bool IsDynamic() const; + virtual void BeginCastBuffer( VertexFormat_t format ); + virtual void EndCastBuffer( ); + virtual int GetRoomRemaining() const; + virtual bool Lock( int nVertexCount, bool bAppend, VertexDesc_t &desc ); + virtual void Unlock( int nVertexCount, VertexDesc_t &desc ); + +public: + // constructor + CVertexBufferDx8( ShaderBufferType_t type, VertexFormat_t fmt, int nVertexCount, const char *pBudgetGroupName ); + virtual ~CVertexBufferDx8(); + + // Allocates, deallocates the index buffer + bool Allocate( ); + void Free(); + + // Returns the vertex size + int VertexSize() const; + + // Only used by dynamic buffers, indicates the next lock should perform a discard. + void Flush(); + + // Returns the D3D buffer + IDirect3DVertexBuffer9* GetDx9Buffer(); + + // Used to measure how much static buffer memory is touched each frame + void HandlePerFrameTextureStats( int nFrame ); + +protected: + IDirect3DVertexBuffer9 *m_pVertexBuffer; + VertexFormat_t m_VertexFormat; + int m_nVertexCount; + int m_nBufferSize; + int m_nFirstUnwrittenOffset; // Used only for dynamic buffers, indicates where it's safe to write (nooverwrite) + + // Is it locked? + bool m_bIsLocked : 1; + bool m_bIsDynamic : 1; + bool m_bFlush : 1; // Used only for dynamic buffers, indicates to discard the next time + +#ifdef VPROF_ENABLED + int m_nVProfFrame; + int *m_pFrameCounter; + int *m_pGlobalCounter; +#endif + +#ifdef _DEBUG + static int s_nBufferCount; +#endif +}; + + +//----------------------------------------------------------------------------- +// +// Code related to index buffers start here +// +//----------------------------------------------------------------------------- +class CIndexBufferDx8 : public CIndexBufferBase +{ + typedef CIndexBufferBase BaseClass; + + // Methods of IIndexBuffer +public: + virtual int IndexCount( ) const; + virtual MaterialIndexFormat_t IndexFormat() const; + virtual int GetRoomRemaining() const; + virtual bool Lock( int nIndexCount, bool bAppend, IndexDesc_t &desc ); + virtual void Unlock( int nIndexCount, IndexDesc_t &desc ); + virtual void BeginCastBuffer( MaterialIndexFormat_t format ); + virtual void EndCastBuffer( ); + virtual bool IsDynamic() const; + virtual void ModifyBegin( bool bReadOnly, int nFirstIndex, int nIndexCount, IndexDesc_t& desc ) { Assert(0); } + virtual void ModifyEnd( IndexDesc_t& desc ) { Assert(0); } + +public: + // constructor + CIndexBufferDx8( ShaderBufferType_t bufferType, MaterialIndexFormat_t fmt, int nIndexCount, const char *pBudgetGroupName ); + virtual ~CIndexBufferDx8(); + + // Allocates, deallocates the index buffer + bool Allocate( ); + void Free(); + + // Returns the index size + int IndexSize() const; + + // Only used by dynamic buffers, indicates the next lock should perform a discard. + void Flush(); + + // Returns the D3D buffer + IDirect3DIndexBuffer9* GetDx9Buffer(); + + // Used to measure how much static buffer memory is touched each frame + void HandlePerFrameTextureStats( int nFrame ); + +#ifdef CHECK_INDICES + unsigned short GetShadowIndex( int i ) const; +#endif + +private: + IDirect3DIndexBuffer9 *m_pIndexBuffer; + MaterialIndexFormat_t m_IndexFormat; + int m_nIndexCount; + int m_nBufferSize; + int m_nFirstUnwrittenOffset; // Used only for dynamic buffers, indicates where it's safe to write (nooverwrite) + + // Is it locked? + bool m_bIsLocked : 1; + bool m_bIsDynamic : 1; + bool m_bFlush : 1; // Used only for dynamic buffers, indicates to discard the next time + +#ifdef CHECK_INDICES + unsigned char *m_pShadowIndices; + void *m_pLockIndexBuffer; + int m_nLockIndexBufferSize; + int m_nLockIndexOffset; +#endif + +#ifdef VPROF_ENABLED + int m_nVProfFrame; +#endif + +#ifdef _DEBUG + static int s_nBufferCount; +#endif +}; + + +//----------------------------------------------------------------------------- +// +// Backward compat mesh code; will go away soon +// +//----------------------------------------------------------------------------- +abstract_class CBaseMeshDX8 : public CMeshBase +{ +public: + // constructor, destructor + CBaseMeshDX8(); + virtual ~CBaseMeshDX8(); + + // FIXME: Make this work! Unsupported methods of IIndexBuffer + IVertexBuffer + virtual bool Lock( int nMaxIndexCount, bool bAppend, IndexDesc_t& desc ) { Assert(0); return false; } + virtual void Unlock( int nWrittenIndexCount, IndexDesc_t& desc ) { Assert(0); } + virtual void ModifyBegin( bool bReadOnly, int nFirstIndex, int nIndexCount, IndexDesc_t& desc ) { Assert(0); } + virtual void ModifyEnd( IndexDesc_t& desc ) { Assert(0); } + virtual void Spew( int nIndexCount, const IndexDesc_t & desc ) { Assert(0); } + virtual void ValidateData( int nIndexCount, const IndexDesc_t &desc ) { Assert(0); } + virtual bool Lock( int nVertexCount, bool bAppend, VertexDesc_t &desc ) { Assert(0); return false; } + virtual void Unlock( int nVertexCount, VertexDesc_t &desc ) { Assert(0); } + virtual void Spew( int nVertexCount, const VertexDesc_t &desc ) { Assert(0); } + virtual void ValidateData( int nVertexCount, const VertexDesc_t & desc ) { Assert(0); } + + // Locks mesh for modifying + void ModifyBeginEx( bool bReadOnly, int nFirstVertex, int nVertexCount, int nFirstIndex, int nIndexCount, MeshDesc_t& desc ); + void ModifyBegin( int nFirstVertex, int nVertexCount, int nFirstIndex, int nIndexCount, MeshDesc_t& desc ); + void ModifyEnd( MeshDesc_t& desc ); + + // Sets/gets the vertex format + virtual void SetVertexFormat( VertexFormat_t format ); + virtual VertexFormat_t GetVertexFormat() const; + + // Sets/gets the morph format + virtual void SetMorphFormat( MorphFormat_t format ); + virtual MorphFormat_t GetMorphFormat() const; + // Am I using morph data? + virtual bool IsUsingMorphData() const; + bool IsUsingVertexID() const + { + return ShaderAPI()->GetBoundMaterial()->IsUsingVertexID(); + } + + // Sets the material + virtual void SetMaterial( IMaterial* pMaterial ); + + // returns the # of vertices (static meshes only) + int VertexCount() const { return 0; } + + void SetColorMesh( IMesh *pColorMesh, int nVertexOffsetInBytes ) + { + Assert( 0 ); + } + + void SetFlexMesh( IMesh *pMesh, int nVertexOffsetInBytes ) + { + Assert( pMesh == NULL && nVertexOffsetInBytes == 0 ); + } + + void DisableFlexMesh( ) + { + Assert( 0 ); + } + + void MarkAsDrawn() {} + + bool HasColorMesh( ) const { return false; } + bool HasFlexMesh( ) const { return false; } + + // Draws the mesh + void DrawMesh( ); + + // Begins a pass + void BeginPass( ); + + // Spews the mesh data + virtual void Spew( int nVertexCount, int nIndexCount, const MeshDesc_t & desc ); + + // Call this in debug mode to make sure our data is good. + virtual void ValidateData( int nVertexCount, int nIndexCount, const MeshDesc_t & desc ); + + virtual void HandleLateCreation( ) = 0; + + void Draw( CPrimList *pLists, int nLists ); + + // Copy verts and/or indices to a mesh builder. This only works for temp meshes! + virtual void CopyToMeshBuilder( + int iStartVert, // Which vertices to copy. + int nVerts, + int iStartIndex, // Which indices to copy. + int nIndices, + int indexOffset, // This is added to each index. + CMeshBuilder &builder ); + + // returns the primitive type + virtual MaterialPrimitiveType_t GetPrimitiveType() const = 0; + + // Returns the number of indices in a mesh.. + virtual int IndexCount( ) const = 0; + + // FIXME: Make this work! + virtual MaterialIndexFormat_t IndexFormat() const { return MATERIAL_INDEX_FORMAT_16BIT; } + + // NOTE: For dynamic index buffers only! + // Casts the memory of the dynamic index buffer to the appropriate type + virtual void BeginCastBuffer( MaterialIndexFormat_t format ) { Assert(0); } + virtual void BeginCastBuffer( VertexFormat_t format ) { Assert(0); } + virtual void EndCastBuffer( ) { Assert(0); } + virtual int GetRoomRemaining() const { Assert(0); return 0; } + + // returns a static vertex buffer... + virtual CVertexBuffer *GetVertexBuffer() { return 0; } + virtual CIndexBuffer *GetIndexBuffer() { return 0; } + + // Do I need to reset the vertex format? + virtual bool NeedsVertexFormatReset( VertexFormat_t fmt ) const; + + // Do I have enough room? + virtual bool HasEnoughRoom( int nVertexCount, int nIndexCount ) const; + + // Operation to do pre-lock + virtual void PreLock() {} + + virtual unsigned ComputeMemoryUsed(); + + bool m_bMeshLocked; + +protected: + bool DebugTrace() const; + + // The vertex format we're using... + VertexFormat_t m_VertexFormat; + + // The morph format we're using + MorphFormat_t m_MorphFormat; + +#ifdef DBGFLAG_ASSERT + IMaterialInternal* m_pMaterial; + bool m_IsDrawing; +#endif +}; + +//----------------------------------------------------------------------------- +// Implementation of the mesh +//----------------------------------------------------------------------------- +class CMeshDX8 : public CBaseMeshDX8 +{ +public: + // constructor + CMeshDX8( const char *pTextureGroupName ); + virtual ~CMeshDX8(); + + // Locks/unlocks the mesh + void LockMesh( int nVertexCount, int nIndexCount, MeshDesc_t& desc ); + void UnlockMesh( int nVertexCount, int nIndexCount, MeshDesc_t& desc ); + + // Locks mesh for modifying + void ModifyBeginEx( bool bReadOnly, int nFirstVertex, int nVertexCount, int nFirstIndex, int nIndexCount, MeshDesc_t& desc ); + void ModifyBegin( int nFirstVertex, int nVertexCount, int nFirstIndex, int nIndexCount, MeshDesc_t& desc ); + void ModifyEnd( MeshDesc_t& desc ); + + // returns the # of vertices (static meshes only) + int VertexCount() const; + + // returns the # of indices + virtual int IndexCount( ) const; + + // Sets up the vertex and index buffers + void UseIndexBuffer( CIndexBuffer* pBuffer ); + void UseVertexBuffer( CVertexBuffer* pBuffer ); + + // returns a static vertex buffer... + CVertexBuffer *GetVertexBuffer() { return m_pVertexBuffer; } + CIndexBuffer *GetIndexBuffer() { return m_pIndexBuffer; } + + void SetColorMesh( IMesh *pColorMesh, int nVertexOffsetInBytes ); + void SetFlexMesh( IMesh *pMesh, int nVertexOffsetInBytes ); + void DisableFlexMesh(); + + virtual void HandleLateCreation( ); + + bool HasColorMesh( ) const; + bool HasFlexMesh( ) const; + + // Draws the mesh + void Draw( int nFirstIndex, int nIndexCount ); + void Draw( CPrimList *pLists, int nLists ); + void DrawInternal( CPrimList *pLists, int nLists ); + + // Draws a single pass + void RenderPass(); + + // Sets the primitive type + void SetPrimitiveType( MaterialPrimitiveType_t type ); + MaterialPrimitiveType_t GetPrimitiveType() const; + + bool IsDynamic() const { return false; } + +protected: + // Sets the render state. + bool SetRenderState( int nVertexOffsetInBytes, int nFirstVertexIdx, VertexFormat_t vertexFormat = VERTEX_FORMAT_INVALID ); + + // Is the vertex format valid? + bool IsValidVertexFormat( VertexFormat_t vertexFormat = VERTEX_FORMAT_INVALID ); + + // Locks/ unlocks the vertex buffer + bool Lock( int nVertexCount, bool bAppend, VertexDesc_t &desc ); + void Unlock( int nVertexCount, VertexDesc_t &desc ); + + // Locks/unlocks the index buffer + // Pass in nFirstIndex=-1 to lock wherever the index buffer is. Pass in a value + // >= 0 to specify where to lock. + int Lock( bool bReadOnly, int nFirstIndex, int nIndexCount, IndexDesc_t &pIndices ); + void Unlock( int nIndexCount, IndexDesc_t &desc ); + + // computes how many primitives we've got + int NumPrimitives( int nVertexCount, int nIndexCount ) const; + + // Debugging output... + void SpewMaterialVerts( ); + + // Stream source setting methods + void SetVertexIDStreamState( ); + void SetColorStreamState( ); + void SetVertexStreamState( int nVertOffsetInBytes ); + void SetIndexStreamState( int firstVertexIdx ); + + void CheckIndices( CPrimList *pPrim, int numPrimitives ); + + // The vertex and index buffers + CVertexBuffer* m_pVertexBuffer; + CIndexBuffer* m_pIndexBuffer; + + // The current color mesh (to be bound to stream 1) + // The vertex offset allows use of a global, shared color mesh VB + CMeshDX8 * m_pColorMesh; + int m_nColorMeshVertOffsetInBytes; + + CVertexBuffer *m_pFlexVertexBuffer; + + bool m_bHasFlexVerts; + int m_nFlexVertOffsetInBytes; + int m_flexVertCount; + + // Primitive type + MaterialPrimitiveType_t m_Type; + + // Primitive mode + D3DPRIMITIVETYPE m_Mode; + + // Number of primitives + unsigned int m_NumIndices; + unsigned short m_NumVertices; + + // Is it locked? + bool m_IsVBLocked; + bool m_IsIBLocked; + + // Used in rendering sub-parts of the mesh + static CPrimList *s_pPrims; + static int s_nPrims; + static unsigned int s_FirstVertex; // Gets reset during CMeshDX8::DrawInternal + static unsigned int s_NumVertices; + int m_FirstIndex; + +#ifdef RECORDING + int m_LockVertexBufferSize; + void *m_LockVertexBuffer; +#endif + +#if defined( RECORDING ) || defined( CHECK_INDICES ) + void *m_LockIndexBuffer; + int m_LockIndexBufferSize; +#endif + const char *m_pTextureGroupName; + + friend class CMeshMgr; // MESHFIXME +}; + + +//----------------------------------------------------------------------------- +// A little extra stuff for the dynamic version +//----------------------------------------------------------------------------- +class CDynamicMeshDX8 : public CMeshDX8 +{ +public: + // constructor, destructor + CDynamicMeshDX8(); + virtual ~CDynamicMeshDX8(); + + // Initializes the dynamic mesh + void Init( int nBufferId ); + + // Sets the vertex format + virtual void SetVertexFormat( VertexFormat_t format ); + + // Resets the state in case of a task switch + void Reset(); + + // Do I have enough room in the buffer? + bool HasEnoughRoom( int nVertexCount, int nIndexCount ) const; + + // returns the # of indices + int IndexCount( ) const; + + // Locks the mesh + void LockMesh( int nVertexCount, int nIndexCount, MeshDesc_t& desc ); + + // Unlocks the mesh + void UnlockMesh( int nVertexCount, int nIndexCount, MeshDesc_t& desc ); + + // Override vertex + index buffer + void OverrideVertexBuffer( CVertexBuffer *pStaticVertexBuffer ); + void OverrideIndexBuffer( CIndexBuffer *pStaticIndexBuffer ); + + // Do I need to reset the vertex format? + bool NeedsVertexFormatReset(VertexFormat_t fmt) const; + + // Draws it + void Draw( int nFirstIndex, int nIndexCount ); + void MarkAsDrawn() { m_HasDrawn = true; } + // Simply draws what's been buffered up immediately, without state change + void DrawSinglePassImmediately(); + + // Operation to do pre-lock + void PreLock(); + + bool IsDynamic() const { return true; } + +private: + // Resets buffering state + void ResetVertexAndIndexCounts(); + + // Buffer Id + int m_nBufferId; + + // total queued vertices + int m_TotalVertices; + int m_TotalIndices; + + // the first vertex and index since the last draw + int m_nFirstVertex; + int m_FirstIndex; + + // Have we drawn since the last lock? + bool m_HasDrawn; + + // Any overrides? + bool m_VertexOverride; + bool m_IndexOverride; +}; + + +//----------------------------------------------------------------------------- +// A mesh that stores temporary vertex data in the correct format (for modification) +//----------------------------------------------------------------------------- +class CTempMeshDX8 : public CBaseMeshDX8 +{ +public: + // constructor, destructor + CTempMeshDX8( bool isDynamic ); + virtual ~CTempMeshDX8(); + + // Sets the material + virtual void SetVertexFormat( VertexFormat_t format ); + + // Locks/unlocks the mesh + void LockMesh( int nVertexCount, int nIndexCount, MeshDesc_t &desc ); + void UnlockMesh( int nVertexCount, int nIndexCount, MeshDesc_t &desc ); + + // Locks mesh for modifying + virtual void ModifyBeginEx( bool bReadOnly, int nFirstVertex, int nVertexCount, int nFirstIndex, int nIndexCount, MeshDesc_t& desc ); + virtual void ModifyBegin( int nFirstVertex, int nVertexCount, int nFirstIndex, int nIndexCount, MeshDesc_t& desc ); + virtual void ModifyEnd( MeshDesc_t& desc ); + + // Number of indices + vertices + int VertexCount() const; + virtual int IndexCount() const; + virtual bool IsDynamic() const; + + // Sets the primitive type + void SetPrimitiveType( MaterialPrimitiveType_t type ); + MaterialPrimitiveType_t GetPrimitiveType() const; + + // Begins a pass + void BeginPass( ); + + // Draws a single pass + void RenderPass(); + + virtual void HandleLateCreation() + { + Assert( !"TBD - CTempMeshDX8::HandleLateCreation()" ); + } + + // Draws the entire beast + void Draw( int nFirstIndex, int nIndexCount ); + + virtual void CopyToMeshBuilder( + int iStartVert, // Which vertices to copy. + int nVerts, + int iStartIndex, // Which indices to copy. + int nIndices, + int indexOffset, // This is added to each index. + CMeshBuilder &builder ); +private: + // Selection mode + void TestSelection( ); + void ClipTriangle( D3DXVECTOR3 **ppVert, float zNear, D3DXMATRIX &proj ); + + CDynamicMeshDX8 *GetDynamicMesh(); + + CUtlVector< unsigned char, CUtlMemoryAligned< unsigned char, 32 > > m_VertexData; + CUtlVector< unsigned short > m_IndexData; + + unsigned short m_VertexSize; + MaterialPrimitiveType_t m_Type; + int m_LockedVerts; + int m_LockedIndices; + bool m_IsDynamic; + + // Used in rendering sub-parts of the mesh + static unsigned int s_NumIndices; + static unsigned int s_FirstIndex; + +#ifdef DBGFLAG_ASSERT + bool m_Locked; + bool m_InPass; +#endif +}; + +#if 0 +//----------------------------------------------------------------------------- +// A mesh that stores temporary vertex data in the correct format (for modification) +//----------------------------------------------------------------------------- +class CTempIndexBufferDX8 : public CIndexBufferBase +{ +public: + // constructor, destructor + CTempIndexBufferDX8( bool isDynamic ); + virtual ~CTempIndexBufferDX8(); + + // Locks/unlocks the mesh + void LockIndexBuffer( int nIndexCount ); + void UnlockMesh( int nIndexCount ); + + // Locks mesh for modifying + virtual void ModifyBeginEx( bool bReadOnly, int nFirstIndex, int nIndexCount ); + virtual void ModifyEnd(); + + // Number of indices + virtual int IndexCount() const; + virtual bool IsDynamic() const; + + virtual void CopyToIndexBuilder( + int iStartIndex, // Which indices to copy. + int nIndices, + int indexOffset, // This is added to each index. + CIndexBuilder &builder ); +private: + // Selection mode + void TestSelection( ); + + CDynamicMeshDX8 *GetDynamicMesh(); + + CUtlVector< unsigned short > m_IndexData; + + MaterialPrimitiveType_t m_Type; + int m_LockedIndices; + bool m_IsDynamic; + + // Used in rendering sub-parts of the mesh + static unsigned int s_NumIndices; + static unsigned int s_FirstIndex; + +#ifdef DBGFLAG_ASSERT + bool m_Locked; + bool m_InPass; +#endif +}; +#endif +//----------------------------------------------------------------------------- +// This is a version that buffers up vertex data so we can blast through it later +//----------------------------------------------------------------------------- +class CBufferedMeshDX8 : public CBaseMeshDX8 +{ +public: + // constructor, destructor + CBufferedMeshDX8(); + virtual ~CBufferedMeshDX8(); + + // checks to see if it was rendered.. + void ResetRendered(); + bool WasNotRendered() const; + + // Sets the mesh we're really going to draw into + void SetMesh( CBaseMeshDX8* pMesh ); + const CBaseMeshDX8* GetMesh() const { return m_pMesh; } + + // Spews the mesh data + virtual void Spew( int nVertexCount, int nIndexCount, const MeshDesc_t &spewDesc ); + + // Sets the vertex format + virtual void SetVertexFormat( VertexFormat_t format ); + virtual VertexFormat_t GetVertexFormat() const; + + // Sets the morph format + virtual void SetMorphFormat( MorphFormat_t format ); + + // Sets the material + void SetMaterial( IMaterial *pMaterial ); + + // returns the number of indices (should never be called!) + virtual int IndexCount() const { Assert(0); return 0; } + virtual MaterialIndexFormat_t IndexFormat() const { Assert(0); return MATERIAL_INDEX_FORMAT_16BIT; } + virtual bool IsDynamic() const { Assert(0); return true; } + virtual void BeginCastBuffer( MaterialIndexFormat_t format ) { Assert(0); } + virtual void EndCastBuffer( ) { Assert(0); } + virtual int GetRoomRemaining() const { Assert(0); return 0; } + + // Locks the mesh + void LockMesh( int nVertexCount, int nIndexCount, MeshDesc_t& desc ); + void UnlockMesh( int nVertexCount, int nIndexCount, MeshDesc_t& desc ); + + // Sets the primitive type + void SetPrimitiveType( MaterialPrimitiveType_t type ); + MaterialPrimitiveType_t GetPrimitiveType( ) const; + + void ValidateData( int nVertexCount, int nIndexCount, const MeshDesc_t & spewDesc ); + + virtual void HandleLateCreation( ) + { + if ( m_pMesh ) + { + m_pMesh->HandleLateCreation(); + } + } + + // Draws it + void Draw( int nFirstIndex, int nIndexCount ); + + // Renders a pass + void RenderPass(); + + // Flushes queued data + void Flush( ); + + void SetFlexMesh( IMesh *pMesh, int nVertexOffsetInBytes ); + +private: + // The actual mesh we need to render.... + CBaseMeshDX8* m_pMesh; + + // The index of the last vertex (for tristrip fixup) + unsigned short m_LastIndex; + + // Extra padding indices for tristrips + unsigned short m_ExtraIndices; + + // Am I currently flushing? + bool m_IsFlushing; + + // has the dynamic mesh been rendered? + bool m_WasRendered; + + // Do I need to flush? + bool m_FlushNeeded; + +#ifdef DEBUG_BUFFERED_MESHES + // for debugging only + bool m_BufferedStateSet; + BufferedState_t m_BufferedState; +#endif +}; + + +//----------------------------------------------------------------------------- +// Implementation of the mesh manager +//----------------------------------------------------------------------------- +class CMeshMgr : public IMeshMgr +{ +public: + // constructor, destructor + CMeshMgr(); + virtual ~CMeshMgr(); + + // Initialize, shutdown + void Init(); + void Shutdown(); + + // Task switch... + void ReleaseBuffers(); + void RestoreBuffers(); + + // Releases all dynamic vertex buffers + void DestroyVertexBuffers(); + + // Flushes the dynamic mesh + void Flush(); + + // Flushes the vertex buffers + void DiscardVertexBuffers(); + + // Creates, destroys static meshes + IMesh *CreateStaticMesh( VertexFormat_t vertexFormat, const char *pTextureBudgetGroup, IMaterial *pMaterial = NULL ); + void DestroyStaticMesh( IMesh *pMesh ); + + // Gets at the dynamic mesh (spoofs it though) + IMesh *GetDynamicMesh( IMaterial *pMaterial, VertexFormat_t vertexFormat, int nHWSkinBoneCount, bool buffered, + IMesh *pVertexOverride, IMesh *pIndexOverride ); + +// ----------------------------------------------------------- +// ------------ New Vertex/Index Buffer interface ---------------------------- + // Do we need support for bForceTempMesh and bSoftwareVertexShader? + // I don't think we use bSoftwareVertexShader anymore. .need to look into bForceTempMesh. + IVertexBuffer *CreateVertexBuffer( ShaderBufferType_t type, VertexFormat_t fmt, int nVertexCount, const char *pBudgetGroup ); + IIndexBuffer *CreateIndexBuffer( ShaderBufferType_t bufferType, MaterialIndexFormat_t fmt, int nIndexCount, const char *pBudgetGroup ); + void DestroyVertexBuffer( IVertexBuffer * ); + void DestroyIndexBuffer( IIndexBuffer * ); + // Do we need to specify the stream here in the case of locking multiple dynamic VBs on different streams? + IVertexBuffer *GetDynamicVertexBuffer( int streamID, VertexFormat_t vertexFormat, bool bBuffered = true ); + IIndexBuffer *GetDynamicIndexBuffer( MaterialIndexFormat_t fmt, bool bBuffered = true ); + void BindVertexBuffer( int streamID, IVertexBuffer *pVertexBuffer, int nOffsetInBytes, int nFirstVertex, int nVertexCount, VertexFormat_t fmt, int nRepetitions = 1 ); + void BindIndexBuffer( IIndexBuffer *pIndexBuffer, int nOffsetInBytes ); + void Draw( MaterialPrimitiveType_t primitiveType, int nFirstIndex, int nIndexCount ); +// ------------ End ---------------------------- + void RenderPassWithVertexAndIndexBuffers( void ); + + VertexFormat_t GetCurrentVertexFormat( void ) const { return m_CurrentVertexFormat; } + + // Gets at the *actual* dynamic mesh + IMesh* GetActualDynamicMesh( VertexFormat_t vertexFormat ); + IMesh *GetFlexMesh(); + + // Computes vertex format from a list of ingredients + VertexFormat_t ComputeVertexFormat( unsigned int flags, + int numTexCoords, int *pTexCoordDimensions, int numBoneWeights, + int userDataSize ) const; + + // Use fat vertices (for tools) + virtual void UseFatVertices( bool bUseFat ); + + // Returns the number of vertices we can render using the dynamic mesh + virtual void GetMaxToRender( IMesh *pMesh, bool bMaxUntilFlush, int *pMaxVerts, int *pMaxIndices ); + virtual int GetMaxVerticesToRender( IMaterial *pMaterial ); + virtual int GetMaxIndicesToRender( ); + + // Returns a vertex buffer appropriate for the flags + CVertexBuffer *FindOrCreateVertexBuffer( int nDynamicBufferId, VertexFormat_t fmt ); + CIndexBuffer *GetDynamicIndexBuffer(); + + // Is the mesh dynamic? + bool IsDynamicMesh( IMesh *pMesh ) const; + bool IsBufferedDynamicMesh( IMesh *pMesh ) const; + + // Is the vertex buffer dynamic? + bool IsDynamicVertexBuffer( IVertexBuffer *pVertexBuffer ) const; + + // Is the index buffer dynamic? + bool IsDynamicIndexBuffer( IIndexBuffer *pIndexBuffer ) const; + + // Returns the vertex size + int VertexFormatSize( VertexFormat_t vertexFormat ) const + { + return CVertexBufferBase::VertexFormatSize( vertexFormat ); + } + + // Computes the vertex buffer pointers + void ComputeVertexDescription( unsigned char *pBuffer, + VertexFormat_t vertexFormat, MeshDesc_t &desc ) const; + + // Returns the number of buffers... + int BufferCount() const + { +#ifdef _DEBUG + return CVertexBuffer::BufferCount() + CIndexBuffer::BufferCount(); +#else + return 0; +#endif + } + + CVertexBuffer *GetVertexIDBuffer(); + + IVertexBuffer *GetDynamicVertexBuffer( IMaterial *pMaterial, bool buffered = true ); + IIndexBuffer *GetDynamicIndexBuffer( IMaterial *pMaterial, bool buffered = true ); + virtual void MarkUnusedVertexFields( unsigned int nFlags, int nTexCoordCount, bool *pUnusedTexCoords ); + + int UnusedVertexFields() const { return m_nUnusedVertexFields; } + int UnusedTextureCoords() const { return m_nUnusedTextureCoords; } + + IDirect3DVertexBuffer9 *GetZeroVertexBuffer() const { return m_pZeroVertexBuffer; } + +private: + void SetVertexIDStreamState( ); + void SetColorStreamState( ); + void SetVertexStreamState( int nVertOffsetInBytes, int nVertexStride ); + void SetIndexStreamState( int firstVertexIdx ); + bool SetRenderState( int nVertexOffsetInBytes, int nFirstVertexIdx, VertexFormat_t vertexFormat, int nVertexStride ); + + struct VertexBufferLookup_t + { + CVertexBuffer* m_pBuffer; + int m_VertexSize; + }; + + void CopyStaticMeshIndexBufferToTempMeshIndexBuffer( CTempMeshDX8 *pDstIndexMesh, CMeshDX8 *pSrcIndexMesh ); + + // Cleans up the class + void CleanUp(); + + // Creates, destroys the dynamic index + void CreateDynamicIndexBuffer(); + void DestroyDynamicIndexBuffer(); + + // Creates, destroys the vertexID buffer + void CreateVertexIDBuffer(); + void DestroyVertexIDBuffer(); + void CreateZeroVertexBuffer(); + void DestroyZeroVertexBuffer(); + + // Fills a vertexID buffer + void FillVertexIDBuffer( CVertexBuffer *pVertexIDBuffer, int nCount ); + + // The dynamic index buffer + CIndexBuffer *m_pDynamicIndexBuffer; + + // A static vertexID buffer + CVertexBuffer *m_pVertexIDBuffer; + + // The dynamic vertex buffers + CUtlVector< VertexBufferLookup_t > m_DynamicVertexBuffers; + + // The buffered mesh + CBufferedMeshDX8 m_BufferedMesh; + + // The current dynamic mesh + CDynamicMeshDX8 m_DynamicMesh; + CDynamicMeshDX8 m_DynamicFlexMesh; + + // The current dynamic vertex buffer + CVertexBufferDx8 m_DynamicVertexBuffer; + + // The current dynamic index buffer + CIndexBufferDx8 m_DynamicIndexBuffer; + + // The dynamic mesh temp version (for shaders that modify vertex data) + CTempMeshDX8 m_DynamicTempMesh; + + // Am I buffering or not? + bool m_BufferedMode; + + // Using fat vertices? + bool m_bUseFatVertices; + + CVertexBufferDx8 *m_pCurrentVertexBuffer; + VertexFormat_t m_CurrentVertexFormat; + int m_pVertexBufferOffset[MAX_DX8_STREAMS]; + int m_pCurrentVertexStride[MAX_DX8_STREAMS]; + int m_pFirstVertex[MAX_DX8_STREAMS]; + int m_pVertexCount[MAX_DX8_STREAMS]; + CIndexBufferBase *m_pCurrentIndexBuffer; + int m_nIndexBufferOffset; + MaterialPrimitiveType_t m_PrimitiveType; + int m_nFirstIndex; + int m_nNumIndices; + + unsigned int m_nUnusedVertexFields; + unsigned int m_nUnusedTextureCoords; + + // 4096 byte static VB containing all-zeros + IDirect3DVertexBuffer9 *m_pZeroVertexBuffer; +}; + +//----------------------------------------------------------------------------- +// Singleton... +//----------------------------------------------------------------------------- +static CMeshMgr g_MeshMgr; +IMeshMgr* MeshMgr() +{ + return &g_MeshMgr; +} + +//----------------------------------------------------------------------------- +// Tracks stream state and queued data +//----------------------------------------------------------------------------- +static CIndexBuffer *g_pLastIndex = NULL; +static IDirect3DIndexBuffer9 *g_pLastIndexBuffer = NULL; +static CVertexBuffer *g_pLastVertex = NULL; +static IDirect3DVertexBuffer9 *g_pLastVertexBuffer = NULL; +static int g_nLastVertOffsetInBytes = 0; +static int g_nLastVertStride = 0; +static int g_LastVertexIdx = -1; +static CMeshDX8 *g_pLastColorMesh = NULL; +static int g_nLastColorMeshVertOffsetInBytes = 0; +static bool g_bUsingVertexID = false; +static bool g_bFlexMeshStreamSet = false; +static VertexFormat_t g_LastVertexFormat = 0; + +inline void D3DSetStreamSource( unsigned int streamNumber, IDirect3DVertexBuffer9 *pStreamData, + unsigned int nVertexOffsetInBytes, unsigned int stride ) +{ + Dx9Device()->SetStreamSource( streamNumber, pStreamData, nVertexOffsetInBytes, stride ); +} + + +//----------------------------------------------------------------------------- +// Tracks stream state and queued data +//----------------------------------------------------------------------------- +void Unbind( IDirect3DIndexBuffer9 *pIndexBuffer ) +{ +#ifdef _X360 + IDirect3DIndexBuffer9 *pBoundBuffer; + Dx9Device()->GetIndices( &pBoundBuffer ); + if ( pBoundBuffer == pIndexBuffer ) + { + // xboxissue - cannot lock indexes set in a d3d device, clear possibly set indices + Dx9Device()->SetIndices( NULL ); + g_pLastIndex = NULL; + g_pLastIndexBuffer = NULL; + } + + if ( pBoundBuffer ) + { + pBoundBuffer->Release(); + } +#endif +} + +void Unbind( IDirect3DVertexBuffer9 *pVertexBuffer ) +{ +#ifdef _X360 + UINT nOffset, nStride; + IDirect3DVertexBuffer9 *pBoundBuffer; + for ( int i = 0; i < MAX_DX8_STREAMS; ++i ) + { + Dx9Device()->GetStreamSource( i, &pBoundBuffer, &nOffset, &nStride ); + if ( pBoundBuffer == pVertexBuffer ) + { + // xboxissue - cannot lock indexes set in a d3d device, clear possibly set indices + Dx9Device()->SetStreamSource( i, 0, 0, 0 ); + switch ( i ) + { + case 0: + g_pLastVertex = NULL; + g_pLastVertexBuffer = NULL; + break; + + case 1: + g_pLastColorMesh = NULL; + g_nLastColorMeshVertOffsetInBytes = 0; + break; + } + } + + if ( pBoundBuffer ) + { + pBoundBuffer->Release(); + } + } +#endif +} + + +//----------------------------------------------------------------------------- +// Helpers to count texture coordinates +//----------------------------------------------------------------------------- +static int NumTextureCoordinates( VertexFormat_t vertexFormat ) +{ + int nTexCoordCount = 0; + for ( int i = 0; i < VERTEX_MAX_TEXTURE_COORDINATES; ++i ) + { + if ( TexCoordSize( i, vertexFormat ) == 0 ) + continue; + ++nTexCoordCount; + } + return nTexCoordCount; +} + + +//----------------------------------------------------------------------------- +// Makes sure that the render state is always set next time +//----------------------------------------------------------------------------- +static void ResetMeshRenderState() +{ + SafeRelease( &g_pLastIndex ); + g_pLastIndexBuffer = 0; + g_pLastVertex = 0; + g_nLastVertOffsetInBytes = 0; + g_pLastColorMesh = 0; + g_nLastColorMeshVertOffsetInBytes = 0; + g_LastVertexIdx = -1; + g_bUsingVertexID = false; + g_bFlexMeshStreamSet = false; + g_LastVertexFormat = 0; +} + +//----------------------------------------------------------------------------- +// Makes sure that the render state is always set next time +//----------------------------------------------------------------------------- +static void ResetIndexBufferRenderState() +{ + SafeRelease( &g_pLastIndex ); + g_pLastIndexBuffer = 0; + g_LastVertexIdx = -1; +} + + +//----------------------------------------------------------------------------- +// +// Index Buffer implementations begin here +// +//----------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +// Globals +//----------------------------------------------------------------------------- +#ifdef _DEBUG +int CIndexBufferDx8::s_nBufferCount = 0; +#endif + + +//----------------------------------------------------------------------------- +// Constructor, destructor +//----------------------------------------------------------------------------- +CIndexBufferDx8::CIndexBufferDx8( ShaderBufferType_t bufferType, MaterialIndexFormat_t fmt, int nIndexCount, const char *pBudgetGroupName ) : + BaseClass( pBudgetGroupName ) +{ +// Debugger(); + + Assert( nIndexCount != 0 ); + + // NOTE: MATERIAL_INDEX_FORMAT_UNKNOWN can't be dealt with under dx9 + // because format is bound at buffer creation time. What we'll do + // is just arbitrarily choose to use a 16-bit index buffer of the same size + if ( fmt == MATERIAL_INDEX_FORMAT_UNKNOWN ) + { + fmt = MATERIAL_INDEX_FORMAT_16BIT; + nIndexCount /= 2; + } + + m_pIndexBuffer = NULL; + m_IndexFormat = fmt; + m_nBufferSize = nIndexCount * IndexSize(); + m_nIndexCount = nIndexCount; + m_nFirstUnwrittenOffset = 0; + m_bIsLocked = false; + m_bIsDynamic = IsDynamicBufferType( bufferType ); + m_bFlush = false; + +#ifdef CHECK_INDICES + m_pShadowIndices = NULL; +#endif + +#ifdef VPROF_ENABLED + m_nVProfFrame = -1; +#endif +} + +CIndexBufferDx8::~CIndexBufferDx8() +{ + Free(); +} + + +//----------------------------------------------------------------------------- +// Returns the index size +//----------------------------------------------------------------------------- +inline int CIndexBufferDx8::IndexSize() const +{ + Assert( m_IndexFormat != MATERIAL_INDEX_FORMAT_UNKNOWN ); + return ( m_IndexFormat == MATERIAL_INDEX_FORMAT_16BIT ) ? 2 : 4; +} + + +//----------------------------------------------------------------------------- +// Creates, destroys the index buffer +//----------------------------------------------------------------------------- +bool CIndexBufferDx8::Allocate() +{ +#ifdef OSX + Debugger(); +#endif + Assert( !m_pIndexBuffer ); + m_nFirstUnwrittenOffset = 0; + + // FIXME: This doesn't really work for dynamic buffers; dynamic buffers + // can't have mixed-type indices in them. Bleah. + D3DFORMAT format = ( m_IndexFormat == MATERIAL_INDEX_FORMAT_32BIT ) ? + D3DFMT_INDEX32 : D3DFMT_INDEX16; + + DWORD usage = D3DUSAGE_WRITEONLY; + if ( m_bIsDynamic ) + { + usage |= D3DUSAGE_DYNAMIC; + } + + HRESULT hr = Dx9Device()->CreateIndexBuffer( + m_nBufferSize, usage, format, D3DPOOL_DEFAULT, &m_pIndexBuffer, NULL ); + +#if !defined( _X360 ) + if ( ( hr == D3DERR_OUTOFVIDEOMEMORY ) || ( hr == E_OUTOFMEMORY ) ) + { + // Don't have the memory for this. Try flushing all managed resources + // out of vid mem and try again. + // FIXME: need to record this + Dx9Device()->EvictManagedResources(); + hr = Dx9Device()->CreateIndexBuffer( + m_nBufferSize, usage, format, D3DPOOL_DEFAULT, &m_pIndexBuffer, NULL ); + } +#endif // !X360 + + if ( FAILED(hr) || ( m_pIndexBuffer == NULL ) ) + { + Warning( "CIndexBufferDx8::Allocate: CreateIndexBuffer failed!\n" ); + return false; + } + + if ( !m_bIsDynamic ) + { + VPROF_INCREMENT_GROUP_COUNTER( "TexGroup_global_" TEXTURE_GROUP_STATIC_INDEX_BUFFER, + COUNTER_GROUP_TEXTURE_GLOBAL, m_nBufferSize ); + } + else + { + VPROF_INCREMENT_GROUP_COUNTER( "TexGroup_global_" TEXTURE_GROUP_DYNAMIC_INDEX_BUFFER, + COUNTER_GROUP_TEXTURE_GLOBAL, m_nBufferSize ); + } + +#ifdef CHECK_INDICES + Assert ( !m_pShadowIndices ); + m_pShadowIndices = new unsigned char[ m_nBufferSize ]; + memset( m_pShadowIndices, 0xFF, m_nBufferSize ); +#endif // CHECK_INDICES + +#ifdef _DEBUG + ++s_nBufferCount; +#endif + + return true; +} + +void CIndexBufferDx8::Free() +{ +// FIXME: Unlock(0); + if ( m_pIndexBuffer ) + { +#ifdef _DEBUG + --s_nBufferCount; +#endif + + m_pIndexBuffer->Release(); + m_pIndexBuffer = NULL; + + if ( !m_bIsDynamic ) + { + VPROF_INCREMENT_GROUP_COUNTER( "TexGroup_global_" TEXTURE_GROUP_STATIC_INDEX_BUFFER, + COUNTER_GROUP_TEXTURE_GLOBAL, - m_nBufferSize ); + } + else + { + VPROF_INCREMENT_GROUP_COUNTER( "TexGroup_global_" TEXTURE_GROUP_DYNAMIC_INDEX_BUFFER, + COUNTER_GROUP_TEXTURE_GLOBAL, - m_nBufferSize ); + } + } + +#ifdef CHECK_INDICES + if ( m_pShadowIndices ) + { + delete[] m_pShadowIndices; + m_pShadowIndices = NULL; + } +#endif // CHECK_INDICES +} + + +//----------------------------------------------------------------------------- +// Index buffer information +//----------------------------------------------------------------------------- +int CIndexBufferDx8::IndexCount( ) const +{ + Assert( !m_bIsDynamic ); + return m_nIndexCount; +} + +MaterialIndexFormat_t CIndexBufferDx8::IndexFormat() const +{ + Assert( !m_bIsDynamic ); + return m_IndexFormat; +} + + +//----------------------------------------------------------------------------- +// Returns true if the buffer is dynamic +//----------------------------------------------------------------------------- +bool CIndexBufferDx8::IsDynamic() const +{ + return m_bIsDynamic; +} + + +//----------------------------------------------------------------------------- +// Only used by dynamic buffers, indicates the next lock should perform a discard. +//----------------------------------------------------------------------------- +void CIndexBufferDx8::Flush() +{ + // This strange-looking line makes a flush only occur if the buffer is dynamic. + m_bFlush = m_bIsDynamic; +} + + +//----------------------------------------------------------------------------- +// Returns the D3D buffer +//----------------------------------------------------------------------------- +IDirect3DIndexBuffer9* CIndexBufferDx8::GetDx9Buffer() +{ + return m_pIndexBuffer; +} + + +//----------------------------------------------------------------------------- +// Returns a shadowed index, for validation +//----------------------------------------------------------------------------- +#ifdef CHECK_INDICES +unsigned short CIndexBufferDx8::GetShadowIndex( int i ) const +{ + Assert( i >= 0 && i < m_nIndexCount ); + Assert( m_IndexFormat == MATERIAL_INDEX_FORMAT_16BIT ); + return *(unsigned short*)( &m_pShadowIndices[ i * IndexSize() ] ); +} +#endif // CHECK_INDICES + + +//----------------------------------------------------------------------------- +// Used to measure how much static buffer memory is touched each frame +//----------------------------------------------------------------------------- +void CIndexBufferDx8::HandlePerFrameTextureStats( int nFrame ) +{ +#ifdef VPROF_ENABLED + if ( m_nVProfFrame != nFrame && !m_bIsDynamic ) + { + m_nVProfFrame = nFrame; + VPROF_INCREMENT_GROUP_COUNTER( "TexGroup_frame_" TEXTURE_GROUP_STATIC_INDEX_BUFFER, + COUNTER_GROUP_TEXTURE_PER_FRAME, m_nBufferSize ); + } +#endif +} + + +//----------------------------------------------------------------------------- +// Casts a dynamic buffer to be a particular index type +//----------------------------------------------------------------------------- +void CIndexBufferDx8::BeginCastBuffer( MaterialIndexFormat_t format ) +{ + // NOTE: This should have no effect under Dx9, since we can't recast index buffers. + Assert( format != MATERIAL_INDEX_FORMAT_UNKNOWN ); + Assert( m_bIsDynamic && ( m_IndexFormat == format ) ); +} + +void CIndexBufferDx8::EndCastBuffer( ) +{ + // NOTE: This should have no effect under Dx9, since we can't recast index buffers. +} + +int CIndexBufferDx8::GetRoomRemaining() const +{ + return ( m_nBufferSize - m_nFirstUnwrittenOffset ) / IndexSize(); +} + + +//----------------------------------------------------------------------------- +// Locks/unlocks the index buffer +//----------------------------------------------------------------------------- +bool CIndexBufferDx8::Lock( int nMaxIndexCount, bool bAppend, IndexDesc_t &desc ) +{ + Assert( !m_bIsLocked && ( nMaxIndexCount != 0 ) && ( nMaxIndexCount <= m_nIndexCount ) ); + Assert( m_IndexFormat != MATERIAL_INDEX_FORMAT_UNKNOWN ); + + // FIXME: Why do we need to sync matrices now? + ShaderUtil()->SyncMatrices(); + g_ShaderMutex.Lock(); + + VPROF( "CIndexBufferX8::Lock" ); + + void *pLockedData = NULL; + HRESULT hr; + int nMemoryRequired; + bool bHasEnoughMemory; + UINT nLockFlags; + + // This can happen if the buffer was locked but a type wasn't bound + if ( m_IndexFormat == MATERIAL_INDEX_FORMAT_UNKNOWN ) + goto indexBufferLockFailed; + + // Just give the app crap buffers to fill up while we're suppressed... + if ( g_pShaderDeviceDx8->IsDeactivated() || ( nMaxIndexCount == 0 ) ) + goto indexBufferLockFailed; + + // Did we ask for something too large? + if ( nMaxIndexCount > m_nIndexCount ) + { + Warning( "Too many indices for index buffer. . tell a programmer (%d>%d)\n", nMaxIndexCount, m_nIndexCount ); + goto indexBufferLockFailed; + } + + // We might not have a buffer owing to alt-tab type stuff + if ( !m_pIndexBuffer ) + { + if ( !Allocate() ) + goto indexBufferLockFailed; + } + + // Check to see if we have enough memory + nMemoryRequired = nMaxIndexCount * IndexSize(); + bHasEnoughMemory = ( m_nFirstUnwrittenOffset + nMemoryRequired <= m_nBufferSize ); + + nLockFlags = D3DLOCK_NOSYSLOCK; + if ( bAppend ) + { + // Can't have the first lock after a flush be an appending lock + Assert( !m_bFlush ); + + // If we're appending and we don't have enough room, then puke! + if ( !bHasEnoughMemory || m_bFlush ) + goto indexBufferLockFailed; + nLockFlags |= ( m_nFirstUnwrittenOffset == 0 ) ? D3DLOCK_DISCARD : D3DLOCK_NOOVERWRITE; + } + else + { + // If we're not appending, no overwrite unless we don't have enough room + // If we're a static buffer, always discard if we're not appending + if ( !m_bFlush && bHasEnoughMemory && m_bIsDynamic ) + { + nLockFlags |= ( m_nFirstUnwrittenOffset == 0 ) ? D3DLOCK_DISCARD : D3DLOCK_NOOVERWRITE; + } + else + { + if ( m_bIsDynamic ) + { + nLockFlags |= D3DLOCK_DISCARD; + } + m_nFirstUnwrittenOffset = 0; + m_bFlush = false; + } + } + +#if !defined( _X360 ) + hr = m_pIndexBuffer->Lock( m_nFirstUnwrittenOffset, nMemoryRequired, &pLockedData, nLockFlags ); +#else + hr = m_pIndexBuffer->Lock( 0, 0, &pLockedData, nLockFlags ); + pLockedData = ( ( unsigned char * )pLockedData + m_nFirstUnwrittenOffset ); +#endif + + if ( FAILED( hr ) ) + { + Warning( "Failed to lock index buffer in CIndexBufferDx8::LockIndexBuffer\n" ); + goto indexBufferLockFailed; + } + + desc.m_pIndices = (unsigned short*)( pLockedData ); + desc.m_nIndexSize = IndexSize() >> 1; + if ( g_pHardwareConfig->SupportsStreamOffset() ) + { + desc.m_nFirstIndex = 0; + desc.m_nOffset = m_nFirstUnwrittenOffset; + } + else + { + desc.m_nFirstIndex = m_nFirstUnwrittenOffset / IndexSize(); + Assert( (int)( desc.m_nFirstIndex * IndexSize() ) == m_nFirstUnwrittenOffset ); + desc.m_nOffset = 0; + } + m_bIsLocked = true; + +#ifdef CHECK_INDICES + m_nLockIndexBufferSize = nMemoryRequired; + m_pLockIndexBuffer = desc.m_pIndices; + m_nLockIndexOffset = m_nFirstUnwrittenOffset; +#endif // CHECK_INDICES + + return true; + +indexBufferLockFailed: + g_ShaderMutex.Unlock(); + + // Set up a bogus index descriptor + desc.m_pIndices = g_nScratchIndexBuffer; + desc.m_nIndexSize = 0; + desc.m_nFirstIndex = 0; + desc.m_nOffset = 0; + return false; +} + +void CIndexBufferDx8::Unlock( int nWrittenIndexCount, IndexDesc_t &desc ) +{ + Assert( nWrittenIndexCount <= m_nIndexCount ); + + // NOTE: This can happen if another application finishes + // initializing during the construction of a mesh + if ( !m_bIsLocked ) + return; + +#ifdef CHECK_INDICES + memcpy( (unsigned char*)m_pShadowIndices + m_nLockIndexOffset, m_pLockIndexBuffer, nWrittenIndexCount * IndexSize() ); +#endif // CHECK_INDICES + + if ( m_pIndexBuffer ) + { + m_pIndexBuffer->Unlock(); + } + + m_nFirstUnwrittenOffset += nWrittenIndexCount * IndexSize(); + m_bIsLocked = false; + g_ShaderMutex.Unlock(); +} + + +//----------------------------------------------------------------------------- +// +// Vertex Buffer implementations begin here +// +//----------------------------------------------------------------------------- + + +//----------------------------------------------------------------------------- +// globals +//----------------------------------------------------------------------------- +#ifdef _DEBUG +int CVertexBufferDx8::s_nBufferCount = 0; +#endif + + +//----------------------------------------------------------------------------- +// constructor +//----------------------------------------------------------------------------- +CVertexBufferDx8::CVertexBufferDx8( ShaderBufferType_t type, VertexFormat_t fmt, int nVertexCount, const char *pBudgetGroupName ) : + BaseClass( pBudgetGroupName ) +{ +// Debugger(); + Assert( nVertexCount != 0 ); + + m_pVertexBuffer = NULL; + m_VertexFormat = fmt; + m_nVertexCount = ( fmt == VERTEX_FORMAT_UNKNOWN ) ? 0 : nVertexCount; + m_nBufferSize = ( fmt == VERTEX_FORMAT_UNKNOWN ) ? nVertexCount : nVertexCount * VertexSize(); + m_nFirstUnwrittenOffset = 0; + m_bIsLocked = false; + m_bIsDynamic = ( type == SHADER_BUFFER_TYPE_DYNAMIC ) || ( type == SHADER_BUFFER_TYPE_DYNAMIC_TEMP ); + m_bFlush = false; + +#ifdef VPROF_ENABLED + if ( !m_bIsDynamic ) + { + char name[256]; + V_strcpy_safe( name, "TexGroup_global_" ); + V_strcat_safe( name, pBudgetGroupName, sizeof(name) ); + m_pGlobalCounter = g_VProfCurrentProfile.FindOrCreateCounter( name, COUNTER_GROUP_TEXTURE_GLOBAL ); + + V_strcpy_safe( name, "TexGroup_frame_" ); + V_strcat_safe( name, pBudgetGroupName, sizeof(name) ); + m_pFrameCounter = g_VProfCurrentProfile.FindOrCreateCounter( name, COUNTER_GROUP_TEXTURE_PER_FRAME ); + } + else + { + m_pGlobalCounter = g_VProfCurrentProfile.FindOrCreateCounter( "TexGroup_global_" TEXTURE_GROUP_DYNAMIC_VERTEX_BUFFER, COUNTER_GROUP_TEXTURE_GLOBAL ); + m_pFrameCounter = NULL; + } + m_nVProfFrame = -1; +#endif +} + +CVertexBufferDx8::~CVertexBufferDx8() +{ + Free(); +} + + +//----------------------------------------------------------------------------- +// Returns the vertex size +//----------------------------------------------------------------------------- +inline int CVertexBufferDx8::VertexSize() const +{ + Assert( m_VertexFormat != VERTEX_FORMAT_UNKNOWN ); + return VertexFormatSize( m_VertexFormat ); +} + +//----------------------------------------------------------------------------- +// Creates, destroys the vertex buffer +//----------------------------------------------------------------------------- +bool CVertexBufferDx8::Allocate() +{ + Assert( !m_pVertexBuffer ); + m_nFirstUnwrittenOffset = 0; + + D3DPOOL pool = D3DPOOL_MANAGED; + +#if defined(IS_WINDOWS_PC) && defined(SHADERAPIDX9) + extern bool g_ShaderDeviceUsingD3D9Ex; + if ( g_ShaderDeviceUsingD3D9Ex ) + { + pool = D3DPOOL_DEFAULT; + } +#endif + + DWORD usage = D3DUSAGE_WRITEONLY; + if ( m_bIsDynamic ) + { + usage |= D3DUSAGE_DYNAMIC; + pool = D3DPOOL_DEFAULT; + // Dynamic meshes should never be compressed (slows down writing to them) + Assert( CompressionType( GetVertexFormat() ) == VERTEX_COMPRESSION_NONE ); + } + + HRESULT hr = Dx9Device()->CreateVertexBuffer( + m_nBufferSize, usage, 0, pool, &m_pVertexBuffer, NULL ); + +#if !defined( _X360 ) + if ( ( hr == D3DERR_OUTOFVIDEOMEMORY ) || ( hr == E_OUTOFMEMORY ) ) + { + // Don't have the memory for this. Try flushing all managed resources + // out of vid mem and try again. + // FIXME: need to record this + Dx9Device()->EvictManagedResources(); + hr = Dx9Device()->CreateVertexBuffer( + m_nBufferSize, usage, 0, pool, &m_pVertexBuffer, NULL ); + } +#endif // !X360 + + if ( FAILED(hr) || ( m_pVertexBuffer == NULL ) ) + { + Warning( "CVertexBufferDx8::Allocate: CreateVertexBuffer failed!\n" ); + return false; + } + + // Track VB allocations + g_VBAllocTracker->CountVB( m_pVertexBuffer, m_bIsDynamic, m_nBufferSize, VertexSize(), GetVertexFormat() ); + +#ifdef VPROF_ENABLED + if ( IsX360() || !m_bIsDynamic ) + { + Assert( m_pGlobalCounter ); + *m_pGlobalCounter += m_nBufferSize; + } +#endif + +#ifdef _DEBUG + ++s_nBufferCount; +#endif + + return true; +} + +void CVertexBufferDx8::Free() +{ + // FIXME: Unlock(0); + if ( m_pVertexBuffer ) + { +#ifdef _DEBUG + --s_nBufferCount; +#endif + + // Track VB allocations + g_VBAllocTracker->UnCountVB( m_pVertexBuffer ); + +#ifdef VPROF_ENABLED + if ( IsX360() || !m_bIsDynamic ) + { + Assert( m_pGlobalCounter ); + *m_pGlobalCounter -= m_nBufferSize; + } +#endif + + m_pVertexBuffer->Release(); + m_pVertexBuffer = NULL; + } +} + + +//----------------------------------------------------------------------------- +// Vertex buffer information +//----------------------------------------------------------------------------- +int CVertexBufferDx8::VertexCount() const +{ + Assert( !m_bIsDynamic ); + return m_nVertexCount; +} + +VertexFormat_t CVertexBufferDx8::GetVertexFormat() const +{ + Assert( !m_bIsDynamic ); + return m_VertexFormat; +} + + +//----------------------------------------------------------------------------- +// Returns true if the buffer is dynamic +//----------------------------------------------------------------------------- +bool CVertexBufferDx8::IsDynamic() const +{ + return m_bIsDynamic; +} + + +//----------------------------------------------------------------------------- +// Only used by dynamic buffers, indicates the next lock should perform a discard. +//----------------------------------------------------------------------------- +void CVertexBufferDx8::Flush() +{ + // This strange-looking line makes a flush only occur if the buffer is dynamic. + m_bFlush = m_bIsDynamic; +} + + +//----------------------------------------------------------------------------- +// Returns the D3D buffer +//----------------------------------------------------------------------------- +IDirect3DVertexBuffer9* CVertexBufferDx8::GetDx9Buffer() +{ + return m_pVertexBuffer; +} + + +//----------------------------------------------------------------------------- +// Casts a dynamic buffer to be a particular vertex type +//----------------------------------------------------------------------------- +void CVertexBufferDx8::BeginCastBuffer( VertexFormat_t format ) +{ + Assert( format != MATERIAL_INDEX_FORMAT_UNKNOWN ); + Assert( m_bIsDynamic && ( m_VertexFormat == 0 || m_VertexFormat == format ) ); + if ( !m_bIsDynamic ) + return; + + m_VertexFormat = format; + int nVertexSize = VertexSize(); + m_nVertexCount = m_nBufferSize / nVertexSize; + + // snap current position up to the next position based on expected size + // so append can safely guarantee nooverwrite regardless of a format growth or shrinkage + if ( !g_pHardwareConfig->SupportsStreamOffset() ) + { + m_nFirstUnwrittenOffset = ( m_nFirstUnwrittenOffset + nVertexSize - 1 ) / nVertexSize; + m_nFirstUnwrittenOffset *= nVertexSize; + if ( m_nFirstUnwrittenOffset > m_nBufferSize ) + { + m_nFirstUnwrittenOffset = m_nBufferSize; + } + } +} + +void CVertexBufferDx8::EndCastBuffer( ) +{ + Assert( m_bIsDynamic && m_VertexFormat != 0 ); + if ( !m_bIsDynamic ) + return; + m_VertexFormat = 0; + m_nVertexCount = 0; +} + + +//----------------------------------------------------------------------------- +// Returns the number of vertices we can still write into the buffer +//----------------------------------------------------------------------------- +int CVertexBufferDx8::GetRoomRemaining() const +{ + return ( m_nBufferSize - m_nFirstUnwrittenOffset ) / VertexSize(); +} + + +//----------------------------------------------------------------------------- +// Locks/unlocks the vertex buffer mesh +//----------------------------------------------------------------------------- +bool CVertexBufferDx8::Lock( int nMaxVertexCount, bool bAppend, VertexDesc_t &desc ) +{ + Assert( !m_bIsLocked && ( nMaxVertexCount != 0 ) && ( nMaxVertexCount <= m_nVertexCount ) ); + Assert( m_VertexFormat != VERTEX_FORMAT_UNKNOWN ); + + // FIXME: Why do we need to sync matrices now? + ShaderUtil()->SyncMatrices(); + g_ShaderMutex.Lock(); + + VPROF( "CVertexBufferDx8::Lock" ); + + void *pLockedData = NULL; + HRESULT hr; + int nMemoryRequired; + bool bHasEnoughMemory; + UINT nLockFlags; + + // This can happen if the buffer was locked but a type wasn't bound + if ( m_VertexFormat == VERTEX_FORMAT_UNKNOWN ) + goto vertexBufferLockFailed; + + // Just give the app crap buffers to fill up while we're suppressed... + if ( g_pShaderDeviceDx8->IsDeactivated() || ( nMaxVertexCount == 0 ) ) + goto vertexBufferLockFailed; + + // Did we ask for something too large? + if ( nMaxVertexCount > m_nVertexCount ) + { + Warning( "Too many vertices for vertex buffer. . tell a programmer (%d>%d)\n", nMaxVertexCount, m_nVertexCount ); + goto vertexBufferLockFailed; + } + + // We might not have a buffer owing to alt-tab type stuff + if ( !m_pVertexBuffer ) + { + if ( !Allocate() ) + goto vertexBufferLockFailed; + } + + // Check to see if we have enough memory + nMemoryRequired = nMaxVertexCount * VertexSize(); + bHasEnoughMemory = ( m_nFirstUnwrittenOffset + nMemoryRequired <= m_nBufferSize ); + + nLockFlags = D3DLOCK_NOSYSLOCK; + if ( bAppend ) + { + // Can't have the first lock after a flush be an appending lock + Assert( !m_bFlush ); + + // If we're appending and we don't have enough room, then puke! + if ( !bHasEnoughMemory || m_bFlush ) + goto vertexBufferLockFailed; + nLockFlags |= ( m_nFirstUnwrittenOffset == 0 ) ? D3DLOCK_DISCARD : D3DLOCK_NOOVERWRITE; + } + else + { + // If we're not appending, no overwrite unless we don't have enough room + // If we're a static buffer, always discard if we're not appending + if ( !m_bFlush && bHasEnoughMemory && m_bIsDynamic ) + { + nLockFlags |= ( m_nFirstUnwrittenOffset == 0 ) ? D3DLOCK_DISCARD : D3DLOCK_NOOVERWRITE; + } + else + { + if ( m_bIsDynamic ) + { + nLockFlags |= D3DLOCK_DISCARD; + } + m_nFirstUnwrittenOffset = 0; + m_bFlush = false; + } + } + +#if !defined( _X360 ) + hr = m_pVertexBuffer->Lock( m_nFirstUnwrittenOffset, nMemoryRequired, &pLockedData, nLockFlags ); +#else + hr = m_pVertexBuffer->Lock( 0, 0, &pLockedData, nLockFlags ); + pLockedData = (unsigned char*)pLockedData + m_nFirstUnwrittenOffset; +#endif + + if ( FAILED( hr ) ) + { + // Check if paged pool is in critical state ( < 5% free ) + PAGED_POOL_INFO_t ppi; + if ( ( SYSCALL_SUCCESS == Plat_GetPagedPoolInfo( &ppi ) ) && + ( ( ppi.numPagesFree * 20 ) < ( ppi.numPagesUsed + ppi.numPagesFree ) ) ) + { + Error( "Out of OS Paged Pool Memory! For more information, please see\nhttp://support.steampowered.com/cgi-bin/steampowered.cfg/php/enduser/std_adp.php?p_faqid=150\n" ); + } + else + { + Warning( "Failed to lock vertex buffer in CVertexBufferDx8::Lock\n" ); + } + goto vertexBufferLockFailed; + } + + ComputeVertexDescription( (unsigned char*)pLockedData, m_VertexFormat, desc ); + if ( g_pHardwareConfig->SupportsStreamOffset() ) + { + desc.m_nFirstVertex = 0; + desc.m_nOffset = m_nFirstUnwrittenOffset; + } + else + { + desc.m_nFirstVertex = m_nFirstUnwrittenOffset / VertexSize(); + desc.m_nOffset = 0; + Assert( m_nFirstUnwrittenOffset == VertexSize() * desc.m_nFirstVertex ); + } + m_bIsLocked = true; + return true; + +vertexBufferLockFailed: + ComputeVertexDescription( 0, 0, desc ); + desc.m_nFirstVertex = 0; + desc.m_nOffset = 0; + return false; +} + + +void CVertexBufferDx8::Unlock( int nWrittenVertexCount, VertexDesc_t &desc ) +{ + Assert( nWrittenVertexCount <= m_nVertexCount ); + + // NOTE: This can happen if another application finishes + // initializing during the construction of a mesh + if ( !m_bIsLocked ) + return; + + if ( m_pVertexBuffer ) + { + m_pVertexBuffer->Unlock(); + } + + m_nFirstUnwrittenOffset += nWrittenVertexCount * VertexSize(); + m_bIsLocked = false; + g_ShaderMutex.Unlock(); +} + + +//----------------------------------------------------------------------------- +// Used to measure how much static buffer memory is touched each frame +//----------------------------------------------------------------------------- +void CVertexBufferDx8::HandlePerFrameTextureStats( int nFrame ) +{ +#ifdef VPROF_ENABLED + if ( m_nVProfFrame != nFrame && !m_bIsDynamic ) + { + m_nVProfFrame = nFrame; + m_pFrameCounter += m_nBufferSize; + } +#endif +} + + +//----------------------------------------------------------------------------- +// Helpers with meshdescs... +//----------------------------------------------------------------------------- +// FIXME: add compression-agnostic read-accessors (which decompress and return by value, checking desc.m_CompressionType) +inline D3DXVECTOR3 &Position( MeshDesc_t const &desc, int vert ) +{ + return *(D3DXVECTOR3*)((unsigned char*)desc.m_pPosition + vert * desc.m_VertexSize_Position ); +} + +inline float Wrinkle( MeshDesc_t const &desc, int vert ) +{ + return *(float*)((unsigned char*)desc.m_pWrinkle + vert * desc.m_VertexSize_Wrinkle ); +} + +inline D3DXVECTOR3 &BoneWeight( MeshDesc_t const &desc, int vert ) +{ + Assert( desc.m_CompressionType == VERTEX_COMPRESSION_NONE ); + return *(D3DXVECTOR3*)((unsigned char*)desc.m_pBoneWeight + vert * desc.m_VertexSize_BoneWeight ); +} + +inline unsigned char *BoneIndex( MeshDesc_t const &desc, int vert ) +{ + return desc.m_pBoneMatrixIndex + vert * desc.m_VertexSize_BoneMatrixIndex; +} + +inline D3DXVECTOR3 &Normal( MeshDesc_t const &desc, int vert ) +{ + Assert( desc.m_CompressionType == VERTEX_COMPRESSION_NONE ); + return *(D3DXVECTOR3*)((unsigned char*)desc.m_pNormal + vert * desc.m_VertexSize_Normal ); +} + +inline unsigned char *Color( MeshDesc_t const &desc, int vert ) +{ + return desc.m_pColor + vert * desc.m_VertexSize_Color; +} + +inline D3DXVECTOR2 &TexCoord( MeshDesc_t const &desc, int vert, int stage ) +{ + return *(D3DXVECTOR2*)((unsigned char*)desc.m_pTexCoord[stage] + vert * desc.m_VertexSize_TexCoord[stage] ); +} + +inline D3DXVECTOR3 &TangentS( MeshDesc_t const &desc, int vert ) +{ + return *(D3DXVECTOR3*)((unsigned char*)desc.m_pTangentS + vert * desc.m_VertexSize_TangentS ); +} + +inline D3DXVECTOR3 &TangentT( MeshDesc_t const &desc, int vert ) +{ + return *(D3DXVECTOR3*)((unsigned char*)desc.m_pTangentT + vert * desc.m_VertexSize_TangentT ); +} + + +//----------------------------------------------------------------------------- +// +// Base mesh +// +//----------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +// constructor, destructor +//----------------------------------------------------------------------------- + +CBaseMeshDX8::CBaseMeshDX8() : m_VertexFormat(0) +{ + m_bMeshLocked = false; +#ifdef DBGFLAG_ASSERT + m_IsDrawing = false; + m_pMaterial = 0; +#endif +} + +CBaseMeshDX8::~CBaseMeshDX8() +{ +} + + +//----------------------------------------------------------------------------- +// For debugging... +//----------------------------------------------------------------------------- +bool CBaseMeshDX8::DebugTrace() const +{ +#ifdef _DEBUG + if (m_pMaterial) + return m_pMaterial->PerformDebugTrace(); +#endif + + return false; +} + +void CBaseMeshDX8::SetMaterial( IMaterial *pMaterial ) +{ +#ifdef DBGFLAG_ASSERT + m_pMaterial = static_cast(pMaterial); +#endif +} + + +//----------------------------------------------------------------------------- +// Sets, gets the vertex format +//----------------------------------------------------------------------------- +void CBaseMeshDX8::SetVertexFormat( VertexFormat_t format ) +{ + m_VertexFormat = format; +} + +VertexFormat_t CBaseMeshDX8::GetVertexFormat() const +{ + return m_VertexFormat; +} + + +//----------------------------------------------------------------------------- +// Sets/gets the morph format +//----------------------------------------------------------------------------- +void CBaseMeshDX8::SetMorphFormat( MorphFormat_t format ) +{ + m_MorphFormat = format; +} + +MorphFormat_t CBaseMeshDX8::GetMorphFormat() const +{ + return m_MorphFormat; +} + + +//----------------------------------------------------------------------------- +// Am I using morph data? +//----------------------------------------------------------------------------- +bool CBaseMeshDX8::IsUsingMorphData() const +{ + LOCK_SHADERAPI(); + // We're not using a morph unless the bound morph is a superset of what the rendermesh needs + MorphFormat_t morphFormat = GetMorphFormat(); + if ( !morphFormat ) + return false; + + return ( ( morphFormat & ShaderUtil()->GetBoundMorphFormat() ) == morphFormat ); +} + +//----------------------------------------------------------------------------- +// Do I need to reset the vertex format? +//----------------------------------------------------------------------------- +bool CBaseMeshDX8::NeedsVertexFormatReset( VertexFormat_t fmt ) const +{ + return m_VertexFormat != fmt; +} + + +//----------------------------------------------------------------------------- +// Do I have enough room? +//----------------------------------------------------------------------------- +bool CBaseMeshDX8::HasEnoughRoom( int nVertexCount, int nIndexCount ) const +{ + // by default, we do + return true; +} + +//----------------------------------------------------------------------------- +// Estimate the memory used +//----------------------------------------------------------------------------- +unsigned CBaseMeshDX8::ComputeMemoryUsed() +{ + unsigned size = 0; + + if ( GetVertexBuffer() ) + { + size += GetVertexBuffer()->VertexCount() * GetVertexBuffer()->VertexSize(); + } + + if ( GetIndexBuffer() ) + { + size += GetIndexBuffer()->IndexCount() * GetIndexBuffer()->IndexSize(); + } + + return size; +} + + +//----------------------------------------------------------------------------- +// Locks mesh for modifying +//----------------------------------------------------------------------------- +void CBaseMeshDX8::ModifyBeginEx( bool bReadOnly, int nFirstVertex, int nVertexCount, int nFirstIndex, int nIndexCount, MeshDesc_t& desc ) +{ + LOCK_SHADERAPI(); + // for the time being, disallow for most cases + Assert(0); +} + +void CBaseMeshDX8::ModifyBegin( int nFirstVertex, int nVertexCount, int nFirstIndex, int nIndexCount, MeshDesc_t& desc ) +{ + LOCK_SHADERAPI(); + // for the time being, disallow for most cases + Assert(0); +} + +void CBaseMeshDX8::ModifyEnd( MeshDesc_t& desc ) +{ + LOCK_SHADERAPI(); + // for the time being, disallow for most cases + Assert(0); +} + + +//----------------------------------------------------------------------------- +// Begins a pass +//----------------------------------------------------------------------------- +void CBaseMeshDX8::BeginPass( ) +{ + LOCK_SHADERAPI(); +} + + +//----------------------------------------------------------------------------- +// Sets the render state and gets the drawing going +//----------------------------------------------------------------------------- +inline void CBaseMeshDX8::DrawMesh( ) +{ +#ifdef DBGFLAG_ASSERT + // Make sure we're not drawing... + Assert( !m_IsDrawing ); + m_IsDrawing = true; +#endif + + // This is going to cause RenderPass to get called a bunch + ShaderAPI()->DrawMesh( this ); + +#ifdef DBGFLAG_ASSERT + m_IsDrawing = false; +#endif +} + + +//----------------------------------------------------------------------------- +// Spews the mesh data +//----------------------------------------------------------------------------- +void CBaseMeshDX8::Spew( int nVertexCount, int nIndexCount, const MeshDesc_t &spewDesc ) +{ + LOCK_SHADERAPI(); + // This has regressed. + int i; + + + // FIXME: just fall back to the base class (CVertexBufferBase) version of this function! + + +#ifdef _DEBUG + if( m_pMaterial ) + { + Plat_DebugString( ( const char * )m_pMaterial->GetName() ); + Plat_DebugString( "\n" ); + } +#endif // _DEBUG + + // This is needed so buffering can just use this + VertexFormat_t fmt = m_VertexFormat; + + // Set up the vertex descriptor + MeshDesc_t desc = spewDesc; + + char tempbuf[256]; + char* temp = tempbuf; + sprintf( tempbuf,"\nVerts: (Vertex Format %llx)\n", fmt); + Plat_DebugString(tempbuf); + + CVertexBufferBase::PrintVertexFormat( fmt ); + + int numBoneWeights = NumBoneWeights( fmt ); + for ( i = 0; i < nVertexCount; ++i ) + { + temp += sprintf( temp, "[%4d] ", i + desc.m_nFirstVertex ); + if( fmt & VERTEX_POSITION ) + { + D3DXVECTOR3& pos = Position( desc, i ); + temp += sprintf(temp, "P %8.2f %8.2f %8.2f ", + pos[0], pos[1], pos[2]); + } + + if ( fmt & VERTEX_WRINKLE ) + { + float flWrinkle = Wrinkle( desc, i ); + temp += sprintf(temp, "Wr %8.2f ",flWrinkle ); + } + + if (numBoneWeights > 0) + { + temp += sprintf(temp, "BW "); + float* pWeight = BoneWeight( desc, i ); + for (int j = 0; j < numBoneWeights; ++j) + { + temp += sprintf(temp, "%1.2f ", pWeight[j]); + } + } + if ( fmt & VERTEX_BONE_INDEX ) + { + unsigned char *pIndex = BoneIndex( desc, i ); + temp += sprintf( temp, "BI %d %d %d %d ", ( int )pIndex[0], ( int )pIndex[1], ( int )pIndex[2], ( int )pIndex[3] ); + Assert( pIndex[0] < 16 ); + Assert( pIndex[1] < 16 ); + Assert( pIndex[2] < 16 ); + Assert( pIndex[3] < 16 ); + } + + if ( fmt & VERTEX_NORMAL ) + { + D3DXVECTOR3& normal = Normal( desc, i ); + temp += sprintf(temp, "N %1.2f %1.2f %1.2f ", + normal[0], normal[1], normal[2]); + } + + if (fmt & VERTEX_COLOR) + { + unsigned char* pColor = Color( desc, i ); + temp += sprintf(temp, "C b %3d g %3d r %3d a %3d ", + pColor[0], pColor[1], pColor[2], pColor[3]); + } + + for (int j = 0; j < VERTEX_MAX_TEXTURE_COORDINATES; ++j) + { + if( TexCoordSize( j, fmt ) > 0) + { + D3DXVECTOR2& texcoord = TexCoord( desc, i, j ); + temp += sprintf(temp, "T%d %.2f %.2f ", j,texcoord[0], texcoord[1]); + } + } + + if (fmt & VERTEX_TANGENT_S) + { + D3DXVECTOR3& tangentS = TangentS( desc, i ); + temp += sprintf(temp, "S %1.2f %1.2f %1.2f ", + tangentS[0], tangentS[1], tangentS[2]); + } + + if (fmt & VERTEX_TANGENT_T) + { + D3DXVECTOR3& tangentT = TangentT( desc, i ); + temp += sprintf(temp, "T %1.2f %1.2f %1.2f ", + tangentT[0], tangentT[1], tangentT[2]); + } + + sprintf(temp,"\n"); + Plat_DebugString(tempbuf); + temp = tempbuf; + } + + sprintf( tempbuf,"\nIndices: %d\n", nIndexCount ); + Plat_DebugString(tempbuf); + for ( i = 0; i < nIndexCount; ++i ) + { + temp += sprintf( temp, "%d ", ( int )desc.m_pIndices[i] ); + if ((i & 0x0F) == 0x0F) + { + sprintf( temp, "\n" ); + Plat_DebugString(tempbuf); + tempbuf[0] = '\0'; + temp = tempbuf; + } + } + sprintf(temp,"\n"); + Plat_DebugString( tempbuf ); +} + +void CBaseMeshDX8::ValidateData( int nVertexCount, int nIndexCount, const MeshDesc_t &spewDesc ) +{ + LOCK_SHADERAPI(); +#ifdef VALIDATE_DEBUG + int i; + + + // FIXME: just fall back to the base class (CVertexBufferBase) version of this function! + + + // This is needed so buffering can just use this + VertexFormat_t fmt = m_pMaterial->GetVertexUsage(); + + // Set up the vertex descriptor + MeshDesc_t desc = spewDesc; + + int numBoneWeights = NumBoneWeights( fmt ); + for ( i = 0; i < nVertexCount; ++i ) + { + if( fmt & VERTEX_POSITION ) + { + D3DXVECTOR3& pos = Position( desc, i ); + Assert( IsFinite( pos[0] ) && IsFinite( pos[1] ) && IsFinite( pos[2] ) ); + } + if( fmt & VERTEX_WRINKLE ) + { + float flWrinkle = Wrinkle( desc, i ); + Assert( IsFinite( flWrinkle ) ); + } + if (numBoneWeights > 0) + { + float* pWeight = BoneWeight( desc, i ); + for (int j = 0; j < numBoneWeights; ++j) + { + Assert( pWeight[j] >= 0.0f && pWeight[j] <= 1.0f ); + } + } + if( fmt & VERTEX_BONE_INDEX ) + { + unsigned char *pIndex = BoneIndex( desc, i ); + Assert( pIndex[0] >= 0 && pIndex[0] < 16 ); + Assert( pIndex[1] >= 0 && pIndex[1] < 16 ); + Assert( pIndex[2] >= 0 && pIndex[2] < 16 ); + Assert( pIndex[3] >= 0 && pIndex[3] < 16 ); + } + if( fmt & VERTEX_NORMAL ) + { + D3DXVECTOR3& normal = Normal( desc, i ); + Assert( normal[0] >= -1.05f && normal[0] <= 1.05f ); + Assert( normal[1] >= -1.05f && normal[1] <= 1.05f ); + Assert( normal[2] >= -1.05f && normal[2] <= 1.05f ); + } + + if (fmt & VERTEX_COLOR) + { + int* pColor = (int*)Color( desc, i ); + Assert( *pColor != FLOAT32_NAN_BITS ); + } + + for (int j = 0; j < VERTEX_MAX_TEXTURE_COORDINATES; ++j) + { + if( TexCoordSize( j, fmt ) > 0) + { + D3DXVECTOR2& texcoord = TexCoord( desc, i, j ); + Assert( IsFinite( texcoord[0] ) && IsFinite( texcoord[1] ) ); + } + } + + if (fmt & VERTEX_TANGENT_S) + { + D3DXVECTOR3& tangentS = TangentS( desc, i ); + Assert( IsFinite( tangentS[0] ) && IsFinite( tangentS[1] ) && IsFinite( tangentS[2] ) ); + } + + if (fmt & VERTEX_TANGENT_T) + { + D3DXVECTOR3& tangentT = TangentT( desc, i ); + Assert( IsFinite( tangentT[0] ) && IsFinite( tangentT[1] ) && IsFinite( tangentT[2] ) ); + } + } +#endif // _DEBUG +} + +void CBaseMeshDX8::Draw( CPrimList *pLists, int nLists ) +{ + LOCK_SHADERAPI(); + Assert( !"CBaseMeshDX8::Draw(CPrimList, int): should never get here." ); +} + + +// Copy verts and/or indices to a mesh builder. This only works for temp meshes! +void CBaseMeshDX8::CopyToMeshBuilder( + int iStartVert, // Which vertices to copy. + int nVerts, + int iStartIndex, // Which indices to copy. + int nIndices, + int indexOffset, // This is added to each index. + CMeshBuilder &builder ) +{ + LOCK_SHADERAPI(); + Assert( false ); + Warning( "CopyToMeshBuilder called on something other than a temp mesh.\n" ); +} + + +//----------------------------------------------------------------------------- +// +// static mesh +// +//----------------------------------------------------------------------------- + +CPrimList *CMeshDX8::s_pPrims; +int CMeshDX8::s_nPrims; +unsigned int CMeshDX8::s_FirstVertex; +unsigned int CMeshDX8::s_NumVertices; + + +//----------------------------------------------------------------------------- +// Computes the mode +//----------------------------------------------------------------------------- +inline D3DPRIMITIVETYPE ComputeMode( MaterialPrimitiveType_t type ) +{ + switch(type) + { +#ifdef _X360 + case MATERIAL_INSTANCED_QUADS: + return D3DPT_QUADLIST; +#endif + + case MATERIAL_POINTS: + return D3DPT_POINTLIST; + + case MATERIAL_LINES: + return D3DPT_LINELIST; + + case MATERIAL_TRIANGLES: + return D3DPT_TRIANGLELIST; + + case MATERIAL_TRIANGLE_STRIP: + return D3DPT_TRIANGLESTRIP; + + // Here, we expect to have the type set later. only works for static meshes + case MATERIAL_HETEROGENOUS: + return (D3DPRIMITIVETYPE)-1; + + default: + Assert(0); + return (D3DPRIMITIVETYPE)-1; + } +} + +//----------------------------------------------------------------------------- +// constructor +//----------------------------------------------------------------------------- +CMeshDX8::CMeshDX8( const char *pTextureGroupName ) : m_NumVertices(0), m_NumIndices(0), m_pVertexBuffer(0), + m_pColorMesh( 0 ), m_nColorMeshVertOffsetInBytes( 0 ), + m_pIndexBuffer(0), m_Type(MATERIAL_TRIANGLES), m_IsVBLocked(false), + m_IsIBLocked(false) +{ + m_pTextureGroupName = pTextureGroupName; + m_Mode = ComputeMode(m_Type); + + m_bHasFlexVerts = false; + m_pFlexVertexBuffer = NULL; + m_nFlexVertOffsetInBytes = 0; +} + +CMeshDX8::~CMeshDX8() +{ + // Don't release the vertex buffer + if (!g_MeshMgr.IsDynamicMesh(this)) + { + if (m_pVertexBuffer) + { + delete m_pVertexBuffer; + } + if (m_pIndexBuffer) + { + SafeRelease( &m_pIndexBuffer ); + } + } +} + +void CMeshDX8::SetFlexMesh( IMesh *pMesh, int nVertexOffsetInBytes ) +{ + if ( !ShaderUtil()->OnSetFlexMesh( this, pMesh, nVertexOffsetInBytes ) ) + return; + + LOCK_SHADERAPI(); + m_nFlexVertOffsetInBytes = nVertexOffsetInBytes; // Offset into dynamic mesh (in bytes) + + if ( pMesh ) + { + m_flexVertCount = pMesh->VertexCount(); + pMesh->MarkAsDrawn(); + + CBaseMeshDX8 *pBaseMesh = static_cast(pMesh); + m_pFlexVertexBuffer = pBaseMesh->GetVertexBuffer(); + + m_bHasFlexVerts = true; + } + else + { + m_flexVertCount = 0; + m_pFlexVertexBuffer = NULL; + m_bHasFlexVerts = false; + } +} + +void CMeshDX8::DisableFlexMesh( ) +{ + CMeshDX8::SetFlexMesh( NULL, 0 ); +} + +bool CMeshDX8::HasFlexMesh( ) const +{ + LOCK_SHADERAPI(); + return m_bHasFlexVerts; +} + +void CMeshDX8::SetColorMesh( IMesh *pColorMesh, int nVertexOffsetInBytes ) +{ + if ( !ShaderUtil()->OnSetColorMesh( this, pColorMesh, nVertexOffsetInBytes ) ) + return; + + LOCK_SHADERAPI(); + m_pColorMesh = ( CMeshDX8 * )pColorMesh; // dangerous conversion! garymcthack + m_nColorMeshVertOffsetInBytes = nVertexOffsetInBytes; + Assert( m_pColorMesh || ( nVertexOffsetInBytes == 0 ) ); + +#ifdef _DEBUG + if ( pColorMesh ) + { + int nVertexCount = VertexCount(); + int numVertsColorMesh = m_pColorMesh->VertexCount(); + Assert( numVertsColorMesh >= nVertexCount ); + } +#endif +} + + +void CMeshDX8::HandleLateCreation( ) +{ + if ( m_pVertexBuffer ) + { + m_pVertexBuffer->HandleLateCreation(); + } + if ( m_pIndexBuffer ) + { + m_pIndexBuffer->HandleLateCreation(); + } + if ( m_pFlexVertexBuffer ) + { + m_pFlexVertexBuffer->HandleLateCreation(); + } + + if ( m_pColorMesh ) + { + m_pColorMesh->HandleLateCreation(); + } +} + + +bool CMeshDX8::HasColorMesh( ) const +{ + LOCK_SHADERAPI(); + return (m_pColorMesh != NULL); +} + + +//----------------------------------------------------------------------------- +// Locks/ unlocks the vertex buffer +//----------------------------------------------------------------------------- +bool CMeshDX8::Lock( int nVertexCount, bool bAppend, VertexDesc_t &desc ) +{ + Assert( !m_IsVBLocked ); + + // Just give the app crap buffers to fill up while we're suppressed... + if ( g_pShaderDeviceDx8->IsDeactivated() || (nVertexCount == 0)) + { + // Set up the vertex descriptor + CVertexBufferBase::ComputeVertexDescription( 0, 0, desc ); + desc.m_nFirstVertex = 0; + return false; + } + + // Static vertex buffer case + if (!m_pVertexBuffer) + { + int size = g_MeshMgr.VertexFormatSize( m_VertexFormat ); + m_pVertexBuffer = new CVertexBuffer( Dx9Device(), m_VertexFormat, 0, size, nVertexCount, m_pTextureGroupName, ShaderAPI()->UsingSoftwareVertexProcessing() ); + } + + // Lock it baby + int nMaxVerts, nMaxIndices; + g_MeshMgr.GetMaxToRender( this, false, &nMaxVerts, &nMaxIndices ); + if ( !g_pHardwareConfig->SupportsStreamOffset() ) + { + // Without stream offset, we can't use VBs greater than 65535 verts (due to our using 16-bit indices) + Assert( nVertexCount <= nMaxVerts ); + } + + unsigned char *pVertexMemory = m_pVertexBuffer->Lock( nVertexCount, desc.m_nFirstVertex ); + if ( !pVertexMemory ) + { + if ( nVertexCount > nMaxVerts ) + { + Assert( 0 ); + Error( "Too many verts for a dynamic vertex buffer (%d>%d) Tell a programmer to up VERTEX_BUFFER_SIZE.\n", + ( int )nVertexCount, ( int )nMaxVerts ); + } + else + { + // Check if paged pool is in critical state ( < 5% free ) + PAGED_POOL_INFO_t ppi; + if ( ( SYSCALL_SUCCESS == Plat_GetPagedPoolInfo( &ppi ) ) && + ( ( ppi.numPagesFree * 20 ) < ( ppi.numPagesUsed + ppi.numPagesFree ) ) ) + { + Error( "Out of OS Paged Pool Memory! For more information, please see\nhttp://support.steampowered.com/cgi-bin/steampowered.cfg/php/enduser/std_adp.php?p_faqid=150\n" ); + } + else + { + Assert( 0 ); + Error( "failed to lock vertex buffer in CMeshDX8::LockVertexBuffer: nVertexCount=%d, nFirstVertex=%d\n", nVertexCount, desc.m_nFirstVertex ); + } + } + CVertexBufferBase::ComputeVertexDescription( 0, 0, desc ); + return false; + } + + // Set up the vertex descriptor + CVertexBufferBase::ComputeVertexDescription( pVertexMemory, m_VertexFormat, desc ); + m_IsVBLocked = true; + +#ifdef RECORDING + m_LockVertexBufferSize = nVertexCount * desc.m_ActualVertexSize; + m_LockVertexBuffer = pVertexMemory; +#endif + + return true; +} + +void CMeshDX8::Unlock( int nVertexCount, VertexDesc_t& desc ) +{ + // NOTE: This can happen if another application finishes + // initializing during the construction of a mesh + if (!m_IsVBLocked) + return; + + // This is recorded for debugging. . not sent to dx. + RECORD_COMMAND( DX8_SET_VERTEX_BUFFER_FORMAT, 2 ); + RECORD_INT( m_pVertexBuffer->UID() ); + RECORD_INT( m_VertexFormat ); + + RECORD_COMMAND( DX8_VERTEX_DATA, 3 ); + RECORD_INT( m_pVertexBuffer->UID() ); + RECORD_INT( m_LockVertexBufferSize ); + RECORD_STRUCT( m_LockVertexBuffer, m_LockVertexBufferSize ); + + Assert(m_pVertexBuffer); + m_pVertexBuffer->Unlock(nVertexCount); + m_IsVBLocked = false; +} + +//----------------------------------------------------------------------------- +// Locks/unlocks the index buffer +//----------------------------------------------------------------------------- +int CMeshDX8::Lock( bool bReadOnly, int nFirstIndex, int nIndexCount, IndexDesc_t &desc ) +{ + Assert( !m_IsIBLocked ); + + // Just give the app crap buffers to fill up while we're suppressed... + if ( g_pShaderDeviceDx8->IsDeactivated() || (nIndexCount == 0)) + { + // Set up a bogus index descriptor + desc.m_pIndices = g_nScratchIndexBuffer; + desc.m_nIndexSize = 0; + return 0; + } + + // Static vertex buffer case + if (!m_pIndexBuffer) + { + SafeAssign( &m_pIndexBuffer, new CIndexBuffer( Dx9Device(), nIndexCount, ShaderAPI()->UsingSoftwareVertexProcessing() ) ); + } + + int startIndex; + desc.m_pIndices = m_pIndexBuffer->Lock( bReadOnly, nIndexCount, startIndex, nFirstIndex ); + if( !desc.m_pIndices ) + { + desc.m_pIndices = g_nScratchIndexBuffer; + desc.m_nIndexSize = 0; + + // Check if paged pool is in critical state ( < 5% free ) + PAGED_POOL_INFO_t ppi; + if ( ( SYSCALL_SUCCESS == Plat_GetPagedPoolInfo( &ppi ) ) && + ( ( ppi.numPagesFree * 20 ) < ( ppi.numPagesUsed + ppi.numPagesFree ) ) ) + { + Error( "Out of OS Paged Pool Memory! For more information, please see\nhttp://support.steampowered.com/cgi-bin/steampowered.cfg/php/enduser/std_adp.php?p_faqid=150\n" ); + } + else + { + Assert( 0 ); + Error( "failed to lock index buffer in CMeshDX8::LockIndexBuffer\n" ); + } + + return 0; + } + + desc.m_nIndexSize = 1; + m_IsIBLocked = true; + +#if defined( RECORDING ) || defined( CHECK_INDICES ) + m_LockIndexBufferSize = nIndexCount * 2; + m_LockIndexBuffer = desc.m_pIndices; +#endif + + return startIndex; +} + + +void CMeshDX8::Unlock( int nIndexCount, IndexDesc_t &desc ) +{ + // NOTE: This can happen if another application finishes + // initializing during the construction of a mesh + if (!m_IsIBLocked) + return; + + RECORD_COMMAND( DX8_INDEX_DATA, 3 ); + RECORD_INT( m_pIndexBuffer->UID() ); + RECORD_INT( m_LockIndexBufferSize ); + RECORD_STRUCT( m_LockIndexBuffer, m_LockIndexBufferSize ); + + Assert(m_pIndexBuffer); + +#ifdef CHECK_INDICES + m_pIndexBuffer->UpdateShadowIndices( ( unsigned short * )m_LockIndexBuffer ); +#endif // CHECK_INDICES + + // Unlock, and indicate how many vertices we actually used + m_pIndexBuffer->Unlock(nIndexCount); + m_IsIBLocked = false; +} + + +//----------------------------------------------------------------------------- +// Locks/unlocks the entire mesh +//----------------------------------------------------------------------------- +void CMeshDX8::LockMesh( int nVertexCount, int nIndexCount, MeshDesc_t& desc ) +{ + ShaderUtil()->SyncMatrices(); + + g_ShaderMutex.Lock(); + VPROF( "CMeshDX8::LockMesh" ); + Lock( nVertexCount, false, *static_cast( &desc ) ); + if ( m_Type != MATERIAL_POINTS ) + { + Lock( false, -1, nIndexCount, *static_cast( &desc ) ); + } + else + { + desc.m_pIndices = g_nScratchIndexBuffer; + desc.m_nIndexSize = 0; + } + + CBaseMeshDX8::m_bMeshLocked = true; +} + + +void CMeshDX8::UnlockMesh( int nVertexCount, int nIndexCount, MeshDesc_t& desc ) +{ + VPROF( "CMeshDX8::UnlockMesh" ); + + Assert( CBaseMeshDX8::m_bMeshLocked ); + + Unlock( nVertexCount, *static_cast( &desc ) ); + if ( m_Type != MATERIAL_POINTS ) + { + Unlock( nIndexCount, *static_cast( &desc ) ); + } + + // The actual # we wrote + m_NumVertices = nVertexCount; + m_NumIndices = nIndexCount; + + CBaseMeshDX8::m_bMeshLocked = false; + g_ShaderMutex.Unlock(); +} + + +//----------------------------------------------------------------------------- +// Locks mesh for modifying +//----------------------------------------------------------------------------- +void CMeshDX8::ModifyBeginEx( bool bReadOnly, int nFirstVertex, int nVertexCount, int nFirstIndex, int nIndexCount, MeshDesc_t& desc ) +{ + VPROF( "CMeshDX8::ModifyBegin" ); + + // Just give the app crap buffers to fill up while we're suppressed... + if ( g_pShaderDeviceDx8->IsDeactivated()) + { + // Set up a bogus descriptor + g_MeshMgr.ComputeVertexDescription( 0, 0, desc ); + desc.m_pIndices = g_nScratchIndexBuffer; + desc.m_nIndexSize = 0; + return; + } + + Assert( m_pVertexBuffer ); + + // Lock it baby + unsigned char* pVertexMemory = m_pVertexBuffer->Modify( bReadOnly, nFirstVertex, nVertexCount ); + if ( pVertexMemory ) + { + m_IsVBLocked = true; + g_MeshMgr.ComputeVertexDescription( pVertexMemory, m_VertexFormat, desc ); + +#ifdef RECORDING + m_LockVertexBufferSize = nVertexCount * desc.m_ActualVertexSize; + m_LockVertexBuffer = pVertexMemory; +#endif + } + + desc.m_nFirstVertex = nFirstVertex; + + Lock( bReadOnly, nFirstIndex, nIndexCount, *static_cast( &desc ) ); +} + +void CMeshDX8::ModifyBegin( int nFirstVertex, int nVertexCount, int nFirstIndex, int nIndexCount, MeshDesc_t& desc ) +{ + ModifyBeginEx( false, nFirstVertex, nVertexCount, nFirstIndex, nIndexCount, desc ); +} + +void CMeshDX8::ModifyEnd( MeshDesc_t& desc ) +{ + VPROF( "CMeshDX8::ModifyEnd" ); + Unlock( 0, *static_cast( &desc ) ); + Unlock( 0, *static_cast( &desc ) ); +} + + +//----------------------------------------------------------------------------- +// returns the # of vertices (static meshes only) +//----------------------------------------------------------------------------- +int CMeshDX8::VertexCount() const +{ + return m_pVertexBuffer ? m_pVertexBuffer->VertexCount() : 0; +} + + +//----------------------------------------------------------------------------- +// returns the # of indices +//----------------------------------------------------------------------------- +int CMeshDX8::IndexCount( ) const +{ + return m_pIndexBuffer ? m_pIndexBuffer->IndexCount() : 0; +} + + +//----------------------------------------------------------------------------- +// Sets up the vertex and index buffers +//----------------------------------------------------------------------------- +void CMeshDX8::UseIndexBuffer( CIndexBuffer* pBuffer ) +{ + SafeAssign( &m_pIndexBuffer, pBuffer ); +} + +void CMeshDX8::UseVertexBuffer( CVertexBuffer* pBuffer ) +{ + m_pVertexBuffer = pBuffer; +} + + +//----------------------------------------------------------------------------- +// Sets the primitive type +//----------------------------------------------------------------------------- +void CMeshDX8::SetPrimitiveType( MaterialPrimitiveType_t type ) +{ + Assert( IsX360() || ( type != MATERIAL_INSTANCED_QUADS ) ); + if ( !ShaderUtil()->OnSetPrimitiveType( this, type ) ) + { + return; + } + + LOCK_SHADERAPI(); + m_Type = type; + m_Mode = ComputeMode( type ); +} + +MaterialPrimitiveType_t CMeshDX8::GetPrimitiveType( ) const +{ + return m_Type; +} + + +//----------------------------------------------------------------------------- +// Computes the number of primitives we're gonna draw +//----------------------------------------------------------------------------- +int CMeshDX8::NumPrimitives( int nVertexCount, int nIndexCount ) const +{ + switch(m_Mode) + { + case D3DPT_POINTLIST: + return nVertexCount; + + case D3DPT_LINELIST: + return nIndexCount / 2; + + case D3DPT_TRIANGLELIST: + return nIndexCount / 3; + + case D3DPT_TRIANGLESTRIP: + return nIndexCount - 2; + + default: + // invalid, baby! + Assert(0); + } + + return 0; +} + + +//----------------------------------------------------------------------------- +// Checks if it's a valid format +//----------------------------------------------------------------------------- +#ifdef _DEBUG +static void OutputVertexFormat( VertexFormat_t format ) +{ + // FIXME: this is a duplicate of the function in meshdx8.cpp + VertexCompressionType_t compressionType = CompressionType( format ); + + if ( format & VERTEX_POSITION ) + { + Warning( "VERTEX_POSITION|" ); + } + if ( format & VERTEX_NORMAL ) + { + if ( compressionType == VERTEX_COMPRESSION_ON ) + Warning( "VERTEX_NORMAL[COMPRESSED]|" ); + else + Warning( "VERTEX_NORMAL|" ); + } + if ( format & VERTEX_COLOR ) + { + Warning( "VERTEX_COLOR|" ); + } + if ( format & VERTEX_SPECULAR ) + { + Warning( "VERTEX_SPECULAR|" ); + } + if ( format & VERTEX_TANGENT_S ) + { + Warning( "VERTEX_TANGENT_S|" ); + } + if ( format & VERTEX_TANGENT_T ) + { + Warning( "VERTEX_TANGENT_T|" ); + } + if ( format & VERTEX_BONE_INDEX ) + { + Warning( "VERTEX_BONE_INDEX|" ); + } + if ( format & VERTEX_FORMAT_VERTEX_SHADER ) + { + Warning( "VERTEX_FORMAT_VERTEX_SHADER|" ); + } + Warning( "\nBone weights: %d (%s)\n", NumBoneWeights( format ), + ( CompressionType( format ) == VERTEX_COMPRESSION_ON ? "compressed" : "uncompressed" ) ); + Warning( "user data size: %d (%s)\n", UserDataSize( format ), + ( CompressionType( format ) == VERTEX_COMPRESSION_ON ? "compressed" : "uncompressed" ) ); + Warning( "num tex coords: %d\n", NumTextureCoordinates( format ) ); + // NOTE: This doesn't print texcoord sizes. +} +#endif + +bool CMeshDX8::IsValidVertexFormat( VertexFormat_t vertexFormat ) +{ + // FIXME: Make this a debug-only check on say 6th July 2007 (after a week or so's testing) + // (i.e. avoid the 360 release build perf. hit for when we ship) + bool bCheckCompression = ( m_VertexFormat & VERTEX_FORMAT_COMPRESSED ) && + ( ( vertexFormat == VERTEX_FORMAT_INVALID ) || ( ( vertexFormat & VERTEX_FORMAT_COMPRESSED ) == 0 ) ); + + if ( bCheckCompression || IsPC() || IsDebug() ) + { + IMaterialInternal* pMaterial = ShaderAPI()->GetBoundMaterial(); + Assert( pMaterial ); + + // the material format should match the vertex usage, unless another format is passed in + if ( vertexFormat == VERTEX_FORMAT_INVALID ) + { + vertexFormat = pMaterial->GetVertexUsage() & ~( VERTEX_FORMAT_VERTEX_SHADER | VERTEX_FORMAT_USE_EXACT_FORMAT ); + + // Blat out unused fields + vertexFormat &= ~g_MeshMgr.UnusedVertexFields(); + int nUnusedTextureCoords = g_MeshMgr.UnusedTextureCoords(); + for ( int i = 0; i < VERTEX_MAX_TEXTURE_COORDINATES; ++i ) + { + if ( nUnusedTextureCoords & ( 1 << i ) ) + { + vertexFormat &= ~VERTEX_TEXCOORD_MASK( i ); + } + } + } + else + { + vertexFormat &= ~( VERTEX_FORMAT_VERTEX_SHADER | VERTEX_FORMAT_USE_EXACT_FORMAT ); + } + + bool bIsValid = (( VERTEX_FORMAT_FIELD_MASK & vertexFormat ) & ( VERTEX_FORMAT_FIELD_MASK & ~m_VertexFormat )) == 0; + + if ( m_VertexFormat & VERTEX_FORMAT_COMPRESSED ) + { + // We shouldn't get compressed verts if this material doesn't support them! + if ( ( vertexFormat & VERTEX_FORMAT_COMPRESSED ) == 0 ) + { + static int numWarnings = 0; + if ( numWarnings++ == 0 ) + { + // NOTE: ComputeVertexFormat() will make sure no materials support VERTEX_FORMAT_COMPRESSED + // if vertex compression is disabled in the config + if ( g_pHardwareConfig->SupportsCompressedVertices() == VERTEX_COMPRESSION_NONE ) + Warning( "ERROR: Compressed vertices in use but vertex compression is disabled (or not supported on this hardware)!\n" ); + else + Warning( "ERROR: Compressed vertices in use but material does not support them!\n" ); + } + Assert( 0 ); + bIsValid = false; + } + } + + bIsValid = bIsValid && UserDataSize( m_VertexFormat ) >= UserDataSize( vertexFormat ); + + for ( int i=0; i < VERTEX_MAX_TEXTURE_COORDINATES; i++ ) + { + if ( TexCoordSize( i, m_VertexFormat ) < TexCoordSize( i, vertexFormat ) ) + { + bIsValid = false; + } + } + + // NOTE: It can totally be valid to have more weights than the current number of bones. + // The -1 here is because if we have N bones, we can have only (N-1) weights, + // since the Nth is implied (the weights sum to 1). + int nWeightCount = NumBoneWeights( m_VertexFormat ); + bIsValid = bIsValid && ( nWeightCount >= ( g_pShaderAPI->GetCurrentNumBones() - 1 ) ); + +#ifdef _DEBUG + if ( !bIsValid ) + { + Warning( "Material Format:" ); + if ( g_pShaderAPI->GetCurrentNumBones() > 0 ) + { + vertexFormat |= VERTEX_BONE_INDEX; + vertexFormat &= ~VERTEX_BONE_WEIGHT_MASK; + vertexFormat |= VERTEX_BONEWEIGHT( 2 ); + } + + OutputVertexFormat( vertexFormat ); + Warning( "Mesh Format:" ); + OutputVertexFormat( m_VertexFormat ); + } +#endif + return bIsValid; + } + + return true; +} + + +//----------------------------------------------------------------------------- +// Stream source setting methods +//----------------------------------------------------------------------------- +void CMeshDX8::SetVertexIDStreamState() +{ + // FIXME: this method duplicates the code in CMeshMgr::SetVertexIDStreamState + + if ( IsX360() ) + return; + + bool bUsingVertexID = IsUsingVertexID(); + if ( bUsingVertexID != g_bUsingVertexID ) + { + if ( bUsingVertexID ) + { + // NOTE: Morphing doesn't work with dynamic buffers!!! BLEAH + // It's because the indices (which are not 0 based for dynamic buffers) + // are accessing both the vertexID buffer + the regular vertex buffer. + // This *might* be fixable with baseVertexIndex? + + // NOTE: At the moment, vertex id is only used for hw morphing. I've got it + // set up so that a shader that supports hw morphing always says it uses vertex id. + // If we ever use vertex id for something other than hw morphing, we're going + // to have to revisit how those shaders say they want to use vertex id + // or fix this some other way + Assert( !g_pShaderAPI->IsHWMorphingEnabled() || !m_pVertexBuffer->IsDynamic() ); + + CVertexBuffer *pVertexIDBuffer = g_MeshMgr.GetVertexIDBuffer( ); + RECORD_COMMAND( DX8_SET_STREAM_SOURCE, 4 ); + RECORD_INT( pVertexIDBuffer->UID() ); + RECORD_INT( 3 ); + RECORD_INT( 0 ); + RECORD_INT( pVertexIDBuffer->VertexSize() ); + + D3DSetStreamSource( 3, pVertexIDBuffer->GetInterface(), 0, pVertexIDBuffer->VertexSize() ); + pVertexIDBuffer->HandlePerFrameTextureStats( ShaderAPI()->GetCurrentFrameCounter() ); + } + else + { + RECORD_COMMAND( DX8_SET_STREAM_SOURCE, 4 ); + RECORD_INT( -1 ); // vertex buffer id + RECORD_INT( 3 ); // stream + RECORD_INT( 0 ); // vertex offset + RECORD_INT( 0 ); // vertex size + + D3DSetStreamSource( 3, 0, 0, 0 ); + } + g_bUsingVertexID = bUsingVertexID; + } +} + +void CMeshDX8::SetColorStreamState() +{ + if ( ( m_pColorMesh != g_pLastColorMesh ) || ( m_nColorMeshVertOffsetInBytes != g_nLastColorMeshVertOffsetInBytes ) ) + { + if ( m_pColorMesh ) + { + RECORD_COMMAND( DX8_SET_STREAM_SOURCE, 4 ); + RECORD_INT( m_pColorMesh->GetVertexBuffer()->UID() ); + RECORD_INT( 1 ); + RECORD_INT( m_nColorMeshVertOffsetInBytes ); + RECORD_INT( m_pColorMesh->GetVertexBuffer()->VertexSize() ); + + D3DSetStreamSource( 1, m_pColorMesh->GetVertexBuffer()->GetInterface(), + m_nColorMeshVertOffsetInBytes, m_pColorMesh->GetVertexBuffer()->VertexSize() ); + m_pColorMesh->GetVertexBuffer()->HandlePerFrameTextureStats( ShaderAPI()->GetCurrentFrameCounter() ); + } + else + { + RECORD_COMMAND( DX8_SET_STREAM_SOURCE, 4 ); + RECORD_INT( -1 ); // vertex buffer id + RECORD_INT( 1 ); // stream + RECORD_INT( 0 ); // vertex offset + RECORD_INT( 0 ); // vertex size + + D3DSetStreamSource( 1, 0, 0, 0 ); + } + g_pLastColorMesh = m_pColorMesh; + g_nLastColorMeshVertOffsetInBytes = m_nColorMeshVertOffsetInBytes; + } +} + +void CMeshDX8::SetVertexStreamState( int nVertOffsetInBytes ) +{ + // Calls in here assume shader support... + if ( HardwareConfig()->SupportsVertexAndPixelShaders() ) + { + if ( HasFlexMesh() ) + { + // m_pFlexVertexBuffer is the flex buffer down inside the CMeshMgr singleton + D3DSetStreamSource( 2, m_pFlexVertexBuffer->GetInterface(), m_nFlexVertOffsetInBytes, m_pFlexVertexBuffer->VertexSize() ); + + if ( g_pHardwareConfig->Caps().m_SupportsVertexShaders_2_0 ) + { + float c[4] = { 1.0f, g_pMaterialSystemHardwareConfig->SupportsPixelShaders_2_b() ? 1.0f : 0.0f, 0.0f, 0.0f }; + ShaderAPI()->SetVertexShaderConstant( VERTEX_SHADER_FLEXSCALE, c, 1 ); + } + + g_bFlexMeshStreamSet = true; + } + else + { + Assert( nVertOffsetInBytes == 0 ); + Assert( m_pVertexBuffer ); + + // HACK...point stream 2 at the same VB which is bound to stream 0... + // NOTE: D3D debug DLLs will RIP if stream 0 has a smaller stride than the largest + // offset in the stream 2 vertex decl elements (which are position(12)+wrinkle(4)+normal(12)) + // If this fires, go find the material/shader which is requesting a really 'thin' + // stream 0 vertex, and fatten it up slightly (e.g. add a D3DCOLOR element) + int minimumStreamZeroStride = 4 * sizeof( float ); + Assert( m_pVertexBuffer->VertexSize() >= minimumStreamZeroStride ); + if ( m_pVertexBuffer->VertexSize() < minimumStreamZeroStride ) + { + static bool bWarned = false; + if( !bWarned ) + { + Warning( "Shader specifying too-thin vertex format, should be at least %d bytes! (Suppressing furthur warnings)\n", minimumStreamZeroStride ); + bWarned = true; + } + } + + // Set a 4kb all-zero static VB into the flex/wrinkle stream with a stride of 1 bytes, so the vertex shader always reads valid floating point values (otherwise it can get NaN's/Inf's, and under OpenGL this is bad on NVidia) + // togl requires non-zero strides, but on D3D9 we can set a stride of 0 for a little more efficiency. + D3DSetStreamSource( 2, g_MeshMgr.GetZeroVertexBuffer(), 0, IsOpenGL() ? 4 : 0 ); + + if ( g_pHardwareConfig->Caps().m_SupportsVertexShaders_2_0 ) + { + float c[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; + ShaderAPI()->SetVertexShaderConstant( VERTEX_SHADER_FLEXSCALE, c, 1 ); + } + + g_bFlexMeshStreamSet = false; + } + } + + // MESHFIXME: Make sure this jives between the mesh/ib/vb version. +#ifdef _X360 + if ( ( g_pLastVertex != m_pVertexBuffer ) || ( m_pVertexBuffer->IsDynamic() ) || ( g_nLastVertOffsetInBytes != nVertOffsetInBytes ) ) +#else + if ( ( g_pLastVertex != m_pVertexBuffer ) || ( g_nLastVertOffsetInBytes != nVertOffsetInBytes ) ) +#endif + { + Assert( m_pVertexBuffer ); + + RECORD_COMMAND( DX8_SET_STREAM_SOURCE, 4 ); + RECORD_INT( m_pVertexBuffer->UID() ); + RECORD_INT( 0 ); + RECORD_INT( nVertOffsetInBytes ); + RECORD_INT( m_pVertexBuffer->VertexSize() ); + + D3DSetStreamSource( 0, m_pVertexBuffer->GetInterface(), nVertOffsetInBytes, m_pVertexBuffer->VertexSize() ); + m_pVertexBuffer->HandlePerFrameTextureStats( ShaderAPI()->GetCurrentFrameCounter() ); + + g_pLastVertex = m_pVertexBuffer; + g_nLastVertOffsetInBytes = nVertOffsetInBytes; + } +} + +void CMeshDX8::SetIndexStreamState( int firstVertexIdx ) +{ +#ifdef _X360 + if ( ( g_pLastIndexBuffer != NULL ) || (g_pLastIndex != m_pIndexBuffer) || ( m_pIndexBuffer->IsDynamic() ) || ( firstVertexIdx != g_LastVertexIdx ) ) +#else + if ( ( g_pLastIndexBuffer != NULL ) || (g_pLastIndex != m_pIndexBuffer) || ( firstVertexIdx != g_LastVertexIdx ) ) +#endif + { + Assert( m_pIndexBuffer ); + + RECORD_COMMAND( DX8_SET_INDICES, 2 ); + RECORD_INT( m_pIndexBuffer->UID() ); + RECORD_INT( firstVertexIdx ); + + Dx9Device()->SetIndices( m_pIndexBuffer->GetInterface() ); + m_pIndexBuffer->HandlePerFrameTextureStats( ShaderAPI()->GetCurrentFrameCounter() ); + m_FirstIndex = firstVertexIdx; + + SafeAssign( &g_pLastIndex, m_pIndexBuffer ); + g_pLastIndexBuffer = NULL; + g_LastVertexIdx = firstVertexIdx; + } +} + +bool CMeshDX8::SetRenderState( int nVertexOffsetInBytes, int nFirstVertexIdx, VertexFormat_t vertexFormat ) +{ + // Can't set the state if we're deactivated + if ( g_pShaderDeviceDx8->IsDeactivated() ) + { + ResetMeshRenderState(); + return false; + } + + g_LastVertexFormat = vertexFormat; + + SetVertexIDStreamState(); + SetColorStreamState(); + SetVertexStreamState( nVertexOffsetInBytes ); + SetIndexStreamState( nFirstVertexIdx ); + + return true; +} + + +//----------------------------------------------------------------------------- +// Draws the static mesh +//----------------------------------------------------------------------------- +void CMeshDX8::Draw( int nFirstIndex, int nIndexCount ) +{ + Assert( m_pVertexBuffer ); + if ( !m_pVertexBuffer ) + { + return; + } + + if ( !ShaderUtil()->OnDrawMesh( this, nFirstIndex, nIndexCount ) ) + { + MarkAsDrawn(); + return; + } + + CPrimList primList; + if( nFirstIndex == -1 || nIndexCount == 0 ) + { + primList.m_FirstIndex = 0; + primList.m_NumIndices = m_NumIndices; + } + else + { + primList.m_FirstIndex = nFirstIndex; + primList.m_NumIndices = nIndexCount; + } + DrawInternal( &primList, 1 ); +} + +void CMeshDX8::Draw( CPrimList *pLists, int nLists ) +{ + Assert( m_pVertexBuffer ); + if ( !m_pVertexBuffer ) + { + return; + } + + if ( !ShaderUtil()->OnDrawMesh( this, pLists, nLists ) ) + { + MarkAsDrawn(); + return; + } + + DrawInternal( pLists, nLists ); +} + + +void CMeshDX8::DrawInternal( CPrimList *pLists, int nLists ) +{ + HandleLateCreation(); + + // Make sure there's something to draw.. + int i; + for ( i=0; i < nLists; i++ ) + { + if ( pLists[i].m_NumIndices > 0 ) + break; + } + if ( i == nLists ) + return; + + // can't do these in selection mode! + Assert( !ShaderAPI()->IsInSelectionMode() ); + + if ( !SetRenderState( 0, 0 ) ) + return; + + s_pPrims = pLists; + s_nPrims = nLists; + +#ifdef _DEBUG + for ( i = 0; i < nLists; ++i) + { + Assert( pLists[i].m_NumIndices > 0 ); + } +#endif + + s_FirstVertex = 0; + s_NumVertices = m_pVertexBuffer->VertexCount(); + + DrawMesh(); +} + + +#ifdef CHECK_INDICES +void CMeshDX8::CheckIndices( CPrimList *pPrim, int numPrimitives ) +{ + // g_pLastVertex - this is the current vertex buffer + // g_pLastColorMesh - this is the current color mesh, if there is one. + // g_pLastIndex - this is the current index buffer. + // vertoffset : m_FirstIndex + if( m_Mode == D3DPT_TRIANGLELIST || m_Mode == D3DPT_TRIANGLESTRIP ) + { + Assert( pPrim->m_FirstIndex >= 0 && pPrim->m_FirstIndex < g_pLastIndex->IndexCount() ); + int i; + for( i = 0; i < 2; i++ ) + { + CVertexBuffer *pMesh; + if( i == 0 ) + { + pMesh = g_pLastVertex; + Assert( pMesh ); + } + else + { + if( !g_pLastColorMesh ) + { + continue; + } + pMesh = g_pLastColorMesh->m_pVertexBuffer; + if( !pMesh ) + { + continue; + } + } + Assert( s_FirstVertex >= 0 && + (int)( s_FirstVertex + m_FirstIndex ) < pMesh->VertexCount() ); + int nIndexCount = 0; + if( m_Mode == D3DPT_TRIANGLELIST ) + { + nIndexCount = numPrimitives * 3; + } + else if( m_Mode == D3DPT_TRIANGLESTRIP ) + { + nIndexCount = numPrimitives + 2; + } + else + { + Assert( 0 ); + } + int j; + for( j = 0; j < nIndexCount; j++ ) + { + int index = g_pLastIndex->GetShadowIndex( j + pPrim->m_FirstIndex ); + if ( ( index < (int)s_FirstVertex ) || ( index >= (int)( s_FirstVertex + s_NumVertices ) ) ) + Warning("%s invalid index: %d [%u..%u]\n", __FUNCTION__, index, s_FirstVertex, s_FirstVertex + s_NumVertices - 1 ); + Assert( index >= (int)s_FirstVertex ); + Assert( index < (int)(s_FirstVertex + s_NumVertices) ); + } + } + } +} +#endif // CHECK_INDICES + + +//----------------------------------------------------------------------------- +// Actually does the dirty deed of rendering +//----------------------------------------------------------------------------- +void CMeshDX8::RenderPass() +{ + LOCK_SHADERAPI(); + VPROF( "CMeshDX8::RenderPass" ); + + HandleLateCreation(); + + Assert( m_Type != MATERIAL_HETEROGENOUS ); + + // make sure the vertex format is a superset of the current material's + // vertex format... + if ( !IsValidVertexFormat( g_LastVertexFormat ) ) + { + Warning( "Material %s does not support vertex format used by the mesh (maybe missing fields or mismatched vertex compression?), mesh will not be rendered. Grab a programmer!\n", + ShaderAPI()->GetBoundMaterial()->GetName() ); + return; + } + + for ( int iPrim=0; iPrim < s_nPrims; iPrim++ ) + { + CPrimList *pPrim = &s_pPrims[iPrim]; + + if ( pPrim->m_NumIndices == 0 ) + continue; + + if ( ( m_Type == MATERIAL_POINTS ) || ( m_Type == MATERIAL_INSTANCED_QUADS ) ) + { + tmZone( TELEMETRY_LEVEL1, TMZF_NONE, "Dx9Device_DrawPrimitive" ); + + // (For point/instanced-quad lists, we don't actually fill in indices, but we treat it as + // though there are indices for the list up until here). + Dx9Device()->DrawPrimitive( m_Mode, s_FirstVertex, pPrim->m_NumIndices ); + } + else + { + int numPrimitives = NumPrimitives( s_NumVertices, pPrim->m_NumIndices ); + +#ifdef CHECK_INDICES + CheckIndices( pPrim, numPrimitives ); +#endif // CHECK_INDICES + { + VPROF( "Dx9Device()->DrawIndexedPrimitive" ); + VPROF_INCREMENT_COUNTER( "DrawIndexedPrimitive", 1 ); + VPROF_INCREMENT_COUNTER( "numPrimitives", numPrimitives ); + VPROF_INCREMENT_GROUP_COUNTER( "render/DrawIndexedPrimitive", COUNTER_GROUP_TELEMETRY, 1 ); + VPROF_INCREMENT_GROUP_COUNTER( "render/numPrimitives", COUNTER_GROUP_TELEMETRY, 1 ); + + Dx9Device()->DrawIndexedPrimitive( + m_Mode, // Member of the D3DPRIMITIVETYPE enumerated type, describing the type of primitive to render. D3DPT_POINTLIST is not supported with this method. + + m_FirstIndex, // Offset from the start of the vertex buffer to the first vertex index. An index of 0 in the index buffer refers to this location in the vertex buffer. + + s_FirstVertex, // Minimum vertex index for vertices used during this call. This is a zero based index relative to BaseVertexIndex. + // The first Vertex in the vertexbuffer that we are currently using for the current batch. + + s_NumVertices, // Number of vertices used during this call. The first vertex is located at index: BaseVertexIndex + MinIndex. + + pPrim->m_FirstIndex, // Index of the first index to use when accesssing the vertex buffer. Beginning at StartIndex to index vertices from the vertex buffer. + + numPrimitives );// Number of primitives to render. The number of vertices used is a function of the primitive count and the primitive type. + } + } + } + + if ( g_pLastVertex ) + { + g_pLastVertex->MarkUsedInRendering(); + } + + if( g_pLastIndex ) + { + g_pLastIndex->MarkUsedInRendering(); + } +} + +//----------------------------------------------------------------------------- +// +// Dynamic mesh implementation +// +//----------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +// constructor, destructor +//----------------------------------------------------------------------------- +CDynamicMeshDX8::CDynamicMeshDX8() : CMeshDX8( "CDynamicMeshDX8" ) +{ + m_nBufferId = 0; + ResetVertexAndIndexCounts(); +} + +CDynamicMeshDX8::~CDynamicMeshDX8() +{ +} + + +//----------------------------------------------------------------------------- +// Initializes the dynamic mesh +//----------------------------------------------------------------------------- +void CDynamicMeshDX8::Init( int nBufferId ) +{ + m_nBufferId = nBufferId; +} + + +//----------------------------------------------------------------------------- +// Resets buffering state +//----------------------------------------------------------------------------- +void CDynamicMeshDX8::ResetVertexAndIndexCounts() +{ + m_TotalVertices = m_TotalIndices = 0; + m_FirstIndex = m_nFirstVertex = -1; + m_HasDrawn = false; +} + + +//----------------------------------------------------------------------------- +// Resets the state in case of a task switch +//----------------------------------------------------------------------------- +void CDynamicMeshDX8::Reset() +{ + m_VertexFormat = 0; + m_pVertexBuffer = 0; + SafeRelease( &m_pIndexBuffer ); + ResetVertexAndIndexCounts(); + + // Force the render state to be updated next time + ResetMeshRenderState(); +} + + +//----------------------------------------------------------------------------- +// Sets the vertex format associated with the dynamic mesh +//----------------------------------------------------------------------------- +void CDynamicMeshDX8::SetVertexFormat( VertexFormat_t format ) +{ + if ( g_pShaderDeviceDx8->IsDeactivated()) + return; + + if ( CompressionType( format ) != VERTEX_COMPRESSION_NONE ) + { + // UNDONE: support compressed dynamic meshes if needed (pro: less VB memory, con: CMeshBuilder gets slower) + Warning( "ERROR: dynamic meshes cannot use compressed vertices!\n" ); + Assert( 0 ); + format &= ~VERTEX_FORMAT_COMPRESSED; + } + + if ((format != m_VertexFormat) || m_VertexOverride || m_IndexOverride) + { + m_VertexFormat = format; + UseVertexBuffer( g_MeshMgr.FindOrCreateVertexBuffer( m_nBufferId, format ) ); + + if ( m_nBufferId == 0 ) + { + UseIndexBuffer( g_MeshMgr.GetDynamicIndexBuffer() ); + } + + m_VertexOverride = m_IndexOverride = false; + } +} + +void CDynamicMeshDX8::OverrideVertexBuffer( CVertexBuffer* pVertexBuffer ) +{ + UseVertexBuffer( pVertexBuffer ); + m_VertexOverride = true; +} + +void CDynamicMeshDX8::OverrideIndexBuffer( CIndexBuffer* pIndexBuffer ) +{ + UseIndexBuffer( pIndexBuffer ); + m_IndexOverride = true; +} + + +//----------------------------------------------------------------------------- +// Do I need to reset the vertex format? +//----------------------------------------------------------------------------- +bool CDynamicMeshDX8::NeedsVertexFormatReset( VertexFormat_t fmt ) const +{ + return m_VertexOverride || m_IndexOverride || (m_VertexFormat != fmt); +} + + + +//----------------------------------------------------------------------------- +// Locks/unlocks the entire mesh +//----------------------------------------------------------------------------- +bool CDynamicMeshDX8::HasEnoughRoom( int nVertexCount, int nIndexCount ) const +{ + if ( g_pShaderDeviceDx8->IsDeactivated() ) + return false; + + Assert( m_pVertexBuffer != NULL ); + + // We need space in both the vertex and index buffer + return m_pVertexBuffer->HasEnoughRoom( nVertexCount ) && + m_pIndexBuffer->HasEnoughRoom( nIndexCount ); +} + + +//----------------------------------------------------------------------------- +// returns the number of indices in the mesh +//----------------------------------------------------------------------------- +int CDynamicMeshDX8::IndexCount( ) const +{ + return m_TotalIndices; +} + + +//----------------------------------------------------------------------------- +// Operation to do pre-lock (only called for buffered meshes) +//----------------------------------------------------------------------------- +void CDynamicMeshDX8::PreLock() +{ + if (m_HasDrawn) + { + // Start again then + ResetVertexAndIndexCounts(); + } +} + + +//----------------------------------------------------------------------------- +// Locks/unlocks the entire mesh +//----------------------------------------------------------------------------- +void CDynamicMeshDX8::LockMesh( int nVertexCount, int nIndexCount, MeshDesc_t& desc ) +{ + tmZoneFiltered( TELEMETRY_LEVEL0, 50, TMZF_NONE, "%s %d %d", __FUNCTION__, nVertexCount, nIndexCount ); + + ShaderUtil()->SyncMatrices(); + + { + tmZoneFiltered( TELEMETRY_LEVEL0, 50, TMZF_NONE, "g_ShaderMutex.Lock" ); + g_ShaderMutex.Lock(); + } + + // Yes, this may well also be called from BufferedMesh but that's ok + { + tmZoneFiltered( TELEMETRY_LEVEL0, 50, TMZF_NONE, "PreLock" ); + PreLock(); + } + + if (m_VertexOverride) + { + nVertexCount = 0; + } + + if (m_IndexOverride) + { + nIndexCount = 0; + } + + { + tmZoneFiltered( TELEMETRY_LEVEL0, 50, TMZF_NONE, "Lock" ); + Lock( nVertexCount, false, *static_cast( &desc ) ); + } + + if (m_nFirstVertex < 0) + { + m_nFirstVertex = desc.m_nFirstVertex; + } + + // When we're using a static index buffer or a flex mesh, the indices assume vertices start at 0 + if ( m_IndexOverride || HasFlexMesh() ) + { + desc.m_nFirstVertex -= m_nFirstVertex; + } + + // Don't add indices for points; DrawIndexedPrimitive not supported for them. + if ( m_Type != MATERIAL_POINTS ) + { + int nFirstIndex; + { + tmZoneFiltered( TELEMETRY_LEVEL0, 50, TMZF_NONE, "Lock nFirstIndex" ); + nFirstIndex = Lock( false, -1, nIndexCount, *static_cast( &desc ) ); + } + if (m_FirstIndex < 0) + { + m_FirstIndex = nFirstIndex; + } + } + else + { + desc.m_pIndices = g_nScratchIndexBuffer; + desc.m_nIndexSize = 0; + } + + CBaseMeshDX8::m_bMeshLocked = true; +} + + +//----------------------------------------------------------------------------- +// Unlocks the mesh +//----------------------------------------------------------------------------- +void CDynamicMeshDX8::UnlockMesh( int nVertexCount, int nIndexCount, MeshDesc_t& desc ) +{ + m_TotalVertices += nVertexCount; + m_TotalIndices += nIndexCount; + + if (DebugTrace()) + { + Spew( nVertexCount, nIndexCount, desc ); + } + + CMeshDX8::UnlockMesh( nVertexCount, nIndexCount, desc ); + + // This is handled in the CMeshDX8::UnlockMesh above. + //CBaseMeshDX8::m_bMeshLocked = false; +} + + +//----------------------------------------------------------------------------- +// Draws it +//----------------------------------------------------------------------------- +void CDynamicMeshDX8::Draw( int nFirstIndex, int nIndexCount ) +{ + if ( !ShaderUtil()->OnDrawMesh( this, nFirstIndex, nIndexCount ) ) + { + MarkAsDrawn(); + return; + } + + VPROF( "CDynamicMeshDX8::Draw" ); + + m_HasDrawn = true; + + if (m_IndexOverride || m_VertexOverride || + ( ( m_TotalVertices > 0 ) && ( m_TotalIndices > 0 || m_Type == MATERIAL_POINTS || m_Type == MATERIAL_INSTANCED_QUADS ) ) ) + { + Assert( !m_IsDrawing ); + + HandleLateCreation( ); + + // only have a non-zero first vertex when we are using static indices + int nFirstVertex = m_VertexOverride ? 0 : m_nFirstVertex; + int actualFirstVertex = m_IndexOverride ? nFirstVertex : 0; + int nVertexOffsetInBytes = HasFlexMesh() ? nFirstVertex * g_MeshMgr.VertexFormatSize( GetVertexFormat() ) : 0; + int baseIndex = m_IndexOverride ? 0 : m_FirstIndex; + + // Overriding with the dynamic index buffer, preserve state! + if ( m_IndexOverride && m_pIndexBuffer == g_MeshMgr.GetDynamicIndexBuffer() ) + { + baseIndex = m_FirstIndex; + } + + VertexFormat_t fmt = m_VertexOverride ? GetVertexFormat() : VERTEX_FORMAT_INVALID; + if ( !SetRenderState( nVertexOffsetInBytes, actualFirstVertex, fmt ) ) + return; + + // Draws a portion of the mesh + int numVertices = m_VertexOverride ? m_pVertexBuffer->VertexCount() : m_TotalVertices; + if ((nFirstIndex != -1) && (nIndexCount != 0)) + { + nFirstIndex += baseIndex; + } + else + { + // by default we draw the whole thing + nFirstIndex = baseIndex; + if( m_IndexOverride ) + { + nIndexCount = m_pIndexBuffer->IndexCount(); + Assert( nIndexCount != 0 ); + } + else + { + nIndexCount = m_TotalIndices; + // Fake out the index count if we're drawing points/instanced-quads + if ( ( m_Type == MATERIAL_POINTS ) || ( m_Type == MATERIAL_INSTANCED_QUADS ) ) + { + nIndexCount = m_TotalVertices; + } + Assert( nIndexCount != 0 ); + } + } + + // Fix up nFirstVertex to indicate the first vertex used in the data + if ( !HasFlexMesh() ) + { + actualFirstVertex = nFirstVertex - actualFirstVertex; + } + + s_FirstVertex = actualFirstVertex; + s_NumVertices = numVertices; + + // Build a primlist with 1 element.. + CPrimList prim; + prim.m_FirstIndex = nFirstIndex; + prim.m_NumIndices = nIndexCount; + Assert( nIndexCount != 0 ); + s_pPrims = &prim; + s_nPrims = 1; + + DrawMesh(); + + s_pPrims = NULL; + } +} + + +//----------------------------------------------------------------------------- +// This is useful when we need to dynamically modify data; just set the +// render state and draw the pass immediately +//----------------------------------------------------------------------------- +void CDynamicMeshDX8::DrawSinglePassImmediately() +{ + if ((m_TotalVertices > 0) || (m_TotalIndices > 0)) + { + Assert( !m_IsDrawing ); + + // Set the render state + if ( SetRenderState( 0, 0 ) ) + { + s_FirstVertex = m_nFirstVertex; + s_NumVertices = m_TotalVertices; + + // Make a temporary PrimList to hold the indices. + CPrimList prim( m_FirstIndex, m_TotalIndices ); + Assert( m_TotalIndices != 0 ); + s_pPrims = &prim; + s_nPrims = 1; + + // Render it + RenderPass(); + } + + // We're done with our data + ResetVertexAndIndexCounts(); + } +} + +//----------------------------------------------------------------------------- +// +// A mesh that stores temporary vertex data in the correct format (for modification) +// +//----------------------------------------------------------------------------- +// Used in rendering sub-parts of the mesh +unsigned int CTempMeshDX8::s_NumIndices; +unsigned int CTempMeshDX8::s_FirstIndex; + +//----------------------------------------------------------------------------- +// constructor, destructor +//----------------------------------------------------------------------------- +CTempMeshDX8::CTempMeshDX8( bool isDynamic ) : m_VertexSize(0xFFFF), m_IsDynamic(isDynamic) +{ +#ifdef DBGFLAG_ASSERT + m_Locked = false; + m_InPass = false; +#endif +} + +CTempMeshDX8::~CTempMeshDX8() +{ +} + +//----------------------------------------------------------------------------- +// Is the temp mesh dynamic? +//----------------------------------------------------------------------------- +bool CTempMeshDX8::IsDynamic() const +{ + return m_IsDynamic; +} + + +//----------------------------------------------------------------------------- +// Sets the vertex format +//----------------------------------------------------------------------------- +void CTempMeshDX8::SetVertexFormat( VertexFormat_t format ) +{ + CBaseMeshDX8::SetVertexFormat(format); + m_VertexSize = g_MeshMgr.VertexFormatSize( format ); +} + +//----------------------------------------------------------------------------- +// returns the # of vertices (static meshes only) +//----------------------------------------------------------------------------- +int CTempMeshDX8::VertexCount() const +{ + return m_VertexSize ? m_VertexData.Count() / m_VertexSize : 0; +} + +//----------------------------------------------------------------------------- +// returns the # of indices +//----------------------------------------------------------------------------- +int CTempMeshDX8::IndexCount( ) const +{ + return m_IndexData.Count(); +} + +void CTempMeshDX8::ModifyBeginEx( bool bReadOnly, int nFirstVertex, int nVertexCount, int nFirstIndex, int nIndexCount, MeshDesc_t& desc ) +{ + Assert( !m_Locked ); + + m_LockedVerts = nVertexCount; + m_LockedIndices = nIndexCount; + + if( nVertexCount > 0 ) + { + int vertexByteOffset = m_VertexSize * nFirstVertex; + + // Lock it baby + unsigned char* pVertexMemory = &m_VertexData[vertexByteOffset]; + + // Compute the vertex index.. + desc.m_nFirstVertex = vertexByteOffset / m_VertexSize; + + // Set up the mesh descriptor + g_MeshMgr.ComputeVertexDescription( pVertexMemory, m_VertexFormat, desc ); + } + else + { + desc.m_nFirstVertex = 0; + // Set up the mesh descriptor + g_MeshMgr.ComputeVertexDescription( 0, 0, desc ); + } + + if (m_Type != MATERIAL_POINTS && nIndexCount > 0 ) + { + desc.m_pIndices = &m_IndexData[nFirstIndex]; + desc.m_nIndexSize = 1; + } + else + { + desc.m_pIndices = g_nScratchIndexBuffer; + desc.m_nIndexSize = 0; + } + +#ifdef DBGFLAG_ASSERT + m_Locked = true; +#endif +} + +void CTempMeshDX8::ModifyBegin( int nFirstVertex, int nVertexCount, int nFirstIndex, int nIndexCount, MeshDesc_t& desc ) +{ + ModifyBeginEx( false, nFirstVertex, nVertexCount, nFirstIndex, nIndexCount, desc ); +} + +void CTempMeshDX8::ModifyEnd( MeshDesc_t& desc ) +{ +#ifdef DBGFLAG_ASSERT + Assert( m_Locked ); + m_Locked = false; +#endif +} + +//----------------------------------------------------------------------------- +// Locks/unlocks the mesh +//----------------------------------------------------------------------------- +void CTempMeshDX8::LockMesh( int nVertexCount, int nIndexCount, MeshDesc_t& desc ) +{ + ShaderUtil()->SyncMatrices(); + + g_ShaderMutex.Lock(); + + Assert( !m_Locked ); + + m_LockedVerts = nVertexCount; + m_LockedIndices = nIndexCount; + + if( nVertexCount > 0 ) + { + int vertexByteOffset = m_VertexData.AddMultipleToTail( m_VertexSize * nVertexCount ); + + // Lock it baby + unsigned char* pVertexMemory = &m_VertexData[vertexByteOffset]; + + // Compute the vertex index.. + desc.m_nFirstVertex = vertexByteOffset / m_VertexSize; + + // Set up the mesh descriptor + g_MeshMgr.ComputeVertexDescription( pVertexMemory, m_VertexFormat, desc ); + } + else + { + desc.m_nFirstVertex = 0; + // Set up the mesh descriptor + g_MeshMgr.ComputeVertexDescription( 0, 0, desc ); + } + + if (m_Type != MATERIAL_POINTS && nIndexCount > 0 ) + { + int nFirstIndex = m_IndexData.AddMultipleToTail( nIndexCount ); + desc.m_pIndices = &m_IndexData[nFirstIndex]; + desc.m_nIndexSize = 1; + } + else + { + desc.m_pIndices = g_nScratchIndexBuffer; + desc.m_nIndexSize = 0; + } + +#ifdef DBGFLAG_ASSERT + m_Locked = true; +#endif + + CBaseMeshDX8::m_bMeshLocked = true; +} + +void CTempMeshDX8::UnlockMesh( int nVertexCount, int nIndexCount, MeshDesc_t& desc ) +{ + Assert( m_Locked ); + + // Remove unused vertices and indices + int verticesToRemove = m_LockedVerts - nVertexCount; + if( verticesToRemove != 0 ) + { + m_VertexData.RemoveMultiple( m_VertexData.Count() - verticesToRemove, verticesToRemove ); + } + + int indicesToRemove = m_LockedIndices - nIndexCount; + if( indicesToRemove != 0 ) + { + m_IndexData.RemoveMultiple( m_IndexData.Count() - indicesToRemove, indicesToRemove ); + } + +#ifdef DBGFLAG_ASSERT + m_Locked = false; +#endif + + CBaseMeshDX8::m_bMeshLocked = false; + + g_ShaderMutex.Unlock(); +} + +//----------------------------------------------------------------------------- +// Sets the primitive type +//----------------------------------------------------------------------------- +void CTempMeshDX8::SetPrimitiveType( MaterialPrimitiveType_t type ) +{ + // FIXME: Support MATERIAL_INSTANCED_QUADS for CTempMeshDX8 (X360 only) + Assert( ( type != MATERIAL_INSTANCED_QUADS ) /* || IsX360() */ ); + m_Type = type; +} + +MaterialPrimitiveType_t CTempMeshDX8::GetPrimitiveType( ) const +{ + return m_Type; +} + +//----------------------------------------------------------------------------- +// Gets the dynamic mesh +//----------------------------------------------------------------------------- +CDynamicMeshDX8* CTempMeshDX8::GetDynamicMesh( ) +{ + return static_cast(g_MeshMgr.GetActualDynamicMesh( m_VertexFormat )); +} + +//----------------------------------------------------------------------------- +// Draws the entire mesh +//----------------------------------------------------------------------------- +void CTempMeshDX8::Draw( int nFirstIndex, int nIndexCount ) +{ + if ( !ShaderUtil()->OnDrawMesh( this, nFirstIndex, nIndexCount ) ) + { + MarkAsDrawn(); + return; + } + + if (m_VertexData.Count() > 0) + { + if ( !g_pShaderDeviceDx8->IsDeactivated() ) + { +#ifdef DRAW_SELECTION + if (!g_bDrawSelection && !ShaderAPI()->IsInSelectionMode()) +#else + if (!ShaderAPI()->IsInSelectionMode()) +#endif + { + s_FirstIndex = nFirstIndex; + s_NumIndices = nIndexCount; + + DrawMesh( ); + + // This assertion fails if a BeginPass() call was not matched by + // a RenderPass() call + Assert(!m_InPass); + } + else + { + TestSelection(); + } + } + + // Clear out the data if this temp mesh is a dynamic one... + if (m_IsDynamic) + { + m_VertexData.RemoveAll(); + m_IndexData.RemoveAll(); + } + } +} + +void CTempMeshDX8::CopyToMeshBuilder( + int iStartVert, // Which vertices to copy. + int nVerts, + int iStartIndex, // Which indices to copy. + int nIndices, + int indexOffset, // This is added to each index. + CMeshBuilder &builder ) +{ + int startOffset = iStartVert * m_VertexSize; + int endOffset = (iStartVert + nVerts) * m_VertexSize; + Assert( startOffset >= 0 && startOffset <= m_VertexData.Count() ); + Assert( endOffset >= 0 && endOffset <= m_VertexData.Count() && endOffset >= startOffset ); + if ( endOffset > startOffset ) + { + // FIXME: make this a method of CMeshBuilder (so the 'Position' pointer accessor can be removed) + // make sure it takes a VertexFormat_t parameter for src/dest match validation + memcpy( (void*)builder.Position(), &m_VertexData[startOffset], endOffset - startOffset ); + builder.AdvanceVertices( nVerts ); + } + + for ( int i = 0; i < nIndices; ++i ) + { + builder.Index( m_IndexData[iStartIndex+i] + indexOffset ); + builder.AdvanceIndex(); + } +} + +//----------------------------------------------------------------------------- +// Selection mode helper functions +//----------------------------------------------------------------------------- +static void ComputeModelToView( D3DXMATRIX& modelToView ) +{ + // Get the modelview matrix... + D3DXMATRIX world, view; + ShaderAPI()->GetMatrix( MATERIAL_MODEL, (float*)&world ); + ShaderAPI()->GetMatrix( MATERIAL_VIEW, (float*)&view ); + D3DXMatrixMultiply( &modelToView, &world, &view ); +} + +static float ComputeCullFactor( ) +{ + D3DCULL cullMode = ShaderAPI()->GetCullMode(); + + float cullFactor; + switch(cullMode) + { + case D3DCULL_CCW: + cullFactor = -1.0f; + break; + + case D3DCULL_CW: + cullFactor = 1.0f; + break; + + default: + cullFactor = 0.0f; + break; + }; + + return cullFactor; +} + +//----------------------------------------------------------------------------- +// Clip to viewport +//----------------------------------------------------------------------------- +static int g_NumClipVerts; +static D3DXVECTOR3 g_ClipVerts[16]; + +static bool PointInsidePlane( D3DXVECTOR3* pVert, int normalInd, float val, bool nearClip ) +{ + if ((val > 0) || nearClip) + return (val - (*pVert)[normalInd] >= 0); + else + return ((*pVert)[normalInd] - val >= 0); +} + +static void IntersectPlane( D3DXVECTOR3* pStart, D3DXVECTOR3* pEnd, + int normalInd, float val, D3DXVECTOR3* pOutVert ) +{ + D3DXVECTOR3 dir; + D3DXVec3Subtract( &dir, pEnd, pStart ); + Assert( dir[normalInd] != 0.0f ); + float t = (val - (*pStart)[normalInd]) / dir[normalInd]; + pOutVert->x = pStart->x + dir.x * t; + pOutVert->y = pStart->y + dir.y * t; + pOutVert->z = pStart->z + dir.z * t; + + // Avoid any precision problems. + (*pOutVert)[normalInd] = val; +} + +static int ClipTriangleAgainstPlane( D3DXVECTOR3** ppVert, int nVertexCount, + D3DXVECTOR3** ppOutVert, int normalInd, float val, bool nearClip = false ) +{ + // Ye Olde Sutherland-Hodgman clipping algorithm + int numOutVerts = 0; + D3DXVECTOR3* pStart = ppVert[nVertexCount-1]; + bool startInside = PointInsidePlane( pStart, normalInd, val, nearClip ); + for (int i = 0; i < nVertexCount; ++i) + { + D3DXVECTOR3* pEnd = ppVert[i]; + bool endInside = PointInsidePlane( pEnd, normalInd, val, nearClip ); + if (endInside) + { + if (!startInside) + { + IntersectPlane( pStart, pEnd, normalInd, val, &g_ClipVerts[g_NumClipVerts] ); + ppOutVert[numOutVerts++] = &g_ClipVerts[g_NumClipVerts++]; + } + ppOutVert[numOutVerts++] = pEnd; + } + else + { + if (startInside) + { + IntersectPlane( pStart, pEnd, normalInd, val, &g_ClipVerts[g_NumClipVerts] ); + ppOutVert[numOutVerts++] = &g_ClipVerts[g_NumClipVerts++]; + } + } + pStart = pEnd; + startInside = endInside; + } + + return numOutVerts; +} + +void CTempMeshDX8::ClipTriangle( D3DXVECTOR3** ppVert, float zNear, D3DXMATRIX& projection ) +{ + int i; + int nVertexCount = 3; + D3DXVECTOR3* ppClipVert1[10]; + D3DXVECTOR3* ppClipVert2[10]; + + g_NumClipVerts = 0; + + // Clip against the near plane in view space to prevent negative w. + // Clip against each plane + nVertexCount = ClipTriangleAgainstPlane( ppVert, nVertexCount, ppClipVert1, 2, zNear, true ); + if (nVertexCount < 3) + return; + + // Sucks that I have to do this, but I have to clip near plane in view space + // Clipping in projection space is screwy when w < 0 + // Transform the clipped points into projection space + Assert( g_NumClipVerts <= 2 ); + for (i = 0; i < nVertexCount; ++i) + { + if (ppClipVert1[i] == &g_ClipVerts[0]) + { + D3DXVec3TransformCoord( &g_ClipVerts[0], ppClipVert1[i], &projection ); + } + else if (ppClipVert1[i] == &g_ClipVerts[1]) + { + D3DXVec3TransformCoord( &g_ClipVerts[1], ppClipVert1[i], &projection ); + } + else + { + D3DXVec3TransformCoord( &g_ClipVerts[g_NumClipVerts], ppClipVert1[i], &projection ); + ppClipVert1[i] = &g_ClipVerts[g_NumClipVerts]; + ++g_NumClipVerts; + } + } + + nVertexCount = ClipTriangleAgainstPlane( ppClipVert1, nVertexCount, ppClipVert2, 2, 1.0f ); + if (nVertexCount < 3) + return; + + nVertexCount = ClipTriangleAgainstPlane( ppClipVert2, nVertexCount, ppClipVert1, 0, 1.0f ); + if (nVertexCount < 3) + return; + + nVertexCount = ClipTriangleAgainstPlane( ppClipVert1, nVertexCount, ppClipVert2, 0, -1.0f ); + if (nVertexCount < 3) + return; + + nVertexCount = ClipTriangleAgainstPlane( ppClipVert2, nVertexCount, ppClipVert1, 1, 1.0f ); + if (nVertexCount < 3) + return; + + nVertexCount = ClipTriangleAgainstPlane( ppClipVert1, nVertexCount, ppClipVert2, 1, -1.0f ); + if (nVertexCount < 3) + return; + +#ifdef DRAW_SELECTION + if( 1 || g_bDrawSelection ) + { + srand( *(int*)(&ppClipVert2[0]->x) ); + unsigned char r = (unsigned char)(rand() * 191.0f / VALVE_RAND_MAX) + 64; + unsigned char g = (unsigned char)(rand() * 191.0f / VALVE_RAND_MAX) + 64; + unsigned char b = (unsigned char)(rand() * 191.0f / VALVE_RAND_MAX) + 64; + + ShaderAPI()->SetupSelectionModeVisualizationState(); + + CMeshBuilder* pMeshBuilder = ShaderAPI()->GetVertexModifyBuilder(); + IMesh* pMesh = GetDynamicMesh(); + pMeshBuilder->Begin( pMesh, MATERIAL_POLYGON, nVertexCount ); + + for ( i = 0; i < nVertexCount; ++i) + { + pMeshBuilder->Position3fv( *ppClipVert2[i] ); + pMeshBuilder->Color3ub( r, g, b ); + pMeshBuilder->AdvanceVertex(); + } + + pMeshBuilder->End(); + pMesh->Draw(); + + pMeshBuilder->Begin( pMesh, MATERIAL_LINE_LOOP, nVertexCount ); + + for ( i = 0; i < nVertexCount; ++i) + { + pMeshBuilder->Position3fv( *ppClipVert2[i] ); + pMeshBuilder->Color3ub( 255, 255, 255 ); + pMeshBuilder->AdvanceVertex(); + } + + pMeshBuilder->End(); + pMesh->Draw(); + } +#endif + + // Compute closest and furthest verts + float minz = ppClipVert2[0]->z; + float maxz = ppClipVert2[0]->z; + for ( i = 1; i < nVertexCount; ++i ) + { + if (ppClipVert2[i]->z < minz) + minz = ppClipVert2[i]->z; + else if (ppClipVert2[i]->z > maxz) + maxz = ppClipVert2[i]->z; + } + + ShaderAPI()->RegisterSelectionHit( minz, maxz ); +} + +//----------------------------------------------------------------------------- +// Selection mode +//----------------------------------------------------------------------------- +void CTempMeshDX8::TestSelection() +{ + // Note that this doesn't take into account any vertex modification + // done in a vertex shader. Also it doesn't take into account any clipping + // done in hardware + + // Blow off points and lines; they don't matter + if ((m_Type != MATERIAL_TRIANGLES) && (m_Type != MATERIAL_TRIANGLE_STRIP)) + return; + + D3DXMATRIX modelToView, projection; + ComputeModelToView( modelToView ); + ShaderAPI()->GetMatrix( MATERIAL_PROJECTION, (float*)&projection ); + float zNear = -projection.m[3][2] / projection.m[2][2]; + + D3DXVECTOR3* pPos[3]; + D3DXVECTOR3 edge[2]; + D3DXVECTOR3 normal; + + int numTriangles; + if (m_Type == MATERIAL_TRIANGLES) + numTriangles = m_IndexData.Count() / 3; + else + numTriangles = m_IndexData.Count() - 2; + + float cullFactor = ComputeCullFactor(); + + // Makes the lovely loop simpler + if (m_Type == MATERIAL_TRIANGLE_STRIP) + cullFactor *= -1.0f; + + // We'll need some temporary memory to tell us if we're transformed the vert + int nVertexCount = m_VertexData.Count() / m_VertexSize; + static CUtlVector< unsigned char > transformedVert; + int transformedVertSize = (nVertexCount + 7) >> 3; + transformedVert.RemoveAll(); + transformedVert.EnsureCapacity( transformedVertSize ); + transformedVert.AddMultipleToTail( transformedVertSize ); + memset( transformedVert.Base(), 0, transformedVertSize ); + + int indexPos; + for (int i = 0; i < numTriangles; ++i) + { + // Get the three indices + if (m_Type == MATERIAL_TRIANGLES) + { + indexPos = i * 3; + } + else + { + Assert( m_Type == MATERIAL_TRIANGLE_STRIP ); + cullFactor *= -1.0f; + indexPos = i; + } + + // BAH. Gotta clip to the near clip plane in view space to prevent + // negative w coords; negative coords throw off the projection-space clipper. + + // Get the three positions in view space + int inFrontIdx = -1; + for (int j = 0; j < 3; ++j) + { + int index = m_IndexData[indexPos]; + D3DXVECTOR3* pPosition = (D3DXVECTOR3*)&m_VertexData[index * m_VertexSize]; + if ((transformedVert[index >> 3] & (1 << (index & 0x7))) == 0) + { + D3DXVec3TransformCoord( pPosition, pPosition, &modelToView ); + transformedVert[index >> 3] |= (1 << (index & 0x7)); + } + + pPos[j] = pPosition; + if (pPos[j]->z < 0.0f) + inFrontIdx = j; + ++indexPos; + } + + // all points are behind the camera + if (inFrontIdx < 0) + continue; + + // backface cull.... + D3DXVec3Subtract( &edge[0], pPos[1], pPos[0] ); + D3DXVec3Subtract( &edge[1], pPos[2], pPos[0] ); + D3DXVec3Cross( &normal, &edge[0], &edge[1] ); + float dot = D3DXVec3Dot( &normal, pPos[inFrontIdx] ); + if (dot * cullFactor > 0.0f) + continue; + + // Clip to viewport + ClipTriangle( pPos, zNear, projection ); + } +} + +//----------------------------------------------------------------------------- +// Begins a render pass +//----------------------------------------------------------------------------- +void CTempMeshDX8::BeginPass( ) +{ + Assert( !m_InPass ); + +#ifdef DBGFLAG_ASSERT + m_InPass = true; +#endif + + CMeshBuilder* pMeshBuilder = ShaderAPI()->GetVertexModifyBuilder(); + + CDynamicMeshDX8* pMesh = GetDynamicMesh( ); + + int nIndexCount; + int nFirstIndex; + if ((s_FirstIndex == -1) && (s_NumIndices == 0)) + { + nIndexCount = m_IndexData.Count(); + nFirstIndex = 0; + } + else + { + nIndexCount = s_NumIndices; + nFirstIndex = s_FirstIndex; + } + + int i; + int nVertexCount = m_VertexData.Count() / m_VertexSize; + pMeshBuilder->Begin( pMesh, m_Type, nVertexCount, nIndexCount ); + + // Copy in the vertex data... + // Note that since we pad the vertices, it's faster for us to simply + // copy the fields we're using... + Assert( pMeshBuilder->BaseVertexData() ); + memcpy( pMeshBuilder->BaseVertexData(), m_VertexData.Base(), m_VertexData.Count() ); + pMeshBuilder->AdvanceVertices( m_VertexData.Count() / m_VertexSize ); + + for ( i = 0; i < nIndexCount; ++i ) + { + pMeshBuilder->Index( m_IndexData[nFirstIndex+i] ); + pMeshBuilder->AdvanceIndex(); + } + + // NOTE: The client is expected to modify the data after this call is made + pMeshBuilder->Reset(); +} + +//----------------------------------------------------------------------------- +// Draws a single pass +//----------------------------------------------------------------------------- +void CTempMeshDX8::RenderPass() +{ + Assert( m_InPass ); + +#ifdef DBGFLAG_ASSERT + m_InPass = false; +#endif + + // Have the shader API modify the vertex data as it needs + // This vertex data is modified based on state set by the material + ShaderAPI()->ModifyVertexData( ); + + // Done building the mesh + ShaderAPI()->GetVertexModifyBuilder()->End(); + + // Have the dynamic mesh render a single pass... + GetDynamicMesh()->DrawSinglePassImmediately(); +} + +//----------------------------------------------------------------------------- +// +// Buffered mesh implementation +// +//----------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +// constructor, destructor +//----------------------------------------------------------------------------- + +CBufferedMeshDX8::CBufferedMeshDX8() : m_IsFlushing(false), m_WasRendered(true) +{ + m_pMesh = NULL; +#ifdef DEBUG_BUFFERED_STATE + m_BufferedStateSet = false; +#endif +} + +CBufferedMeshDX8::~CBufferedMeshDX8() +{ +} + + +//----------------------------------------------------------------------------- +// Sets the mesh +//----------------------------------------------------------------------------- +void CBufferedMeshDX8::SetMesh( CBaseMeshDX8* pMesh ) +{ + if (m_pMesh != pMesh) + { + ShaderAPI()->FlushBufferedPrimitives(); + m_pMesh = pMesh; + } +} + + +//----------------------------------------------------------------------------- +// Spews the mesh data +//----------------------------------------------------------------------------- +void CBufferedMeshDX8::Spew( int nVertexCount, int nIndexCount, const MeshDesc_t &spewDesc ) +{ + if ( m_pMesh ) + { + m_pMesh->Spew( nVertexCount, nIndexCount, spewDesc ); + } +} + + +//----------------------------------------------------------------------------- +// Sets the material +//----------------------------------------------------------------------------- +void CBufferedMeshDX8::SetVertexFormat( VertexFormat_t format ) +{ + Assert( m_pMesh ); + if (m_pMesh->NeedsVertexFormatReset(format)) + { + ShaderAPI()->FlushBufferedPrimitives(); + m_pMesh->SetVertexFormat( format ); + } +} + +void CBufferedMeshDX8::SetMorphFormat( MorphFormat_t format ) +{ + Assert( m_pMesh ); + m_pMesh->SetMorphFormat( format ); +} + +VertexFormat_t CBufferedMeshDX8::GetVertexFormat( ) const +{ + Assert( m_pMesh ); + return m_pMesh->GetVertexFormat(); +} + +void CBufferedMeshDX8::SetMaterial( IMaterial* pMaterial ) +{ +#if _DEBUG + Assert( m_pMesh ); + m_pMesh->SetMaterial( pMaterial ); +#endif +} + +void CBufferedMeshDX8::ValidateData( int nVertexCount, int nIndexCount, const MeshDesc_t & spewDesc ) +{ +#if _DEBUG + Assert( m_pMesh ); + m_pMesh->ValidateData( nVertexCount, nIndexCount, spewDesc ); +#endif +} + + +//----------------------------------------------------------------------------- +// Sets the flex mesh to render with this mesh +//----------------------------------------------------------------------------- +void CBufferedMeshDX8::SetFlexMesh( IMesh *pMesh, int nVertexOffsetInBytes ) +{ + // FIXME: Probably are situations where we don't need to flush, + // but this is going to look different in a very short while, so I'm not going to bother + ShaderAPI()->FlushBufferedPrimitives(); + m_pMesh->SetFlexMesh( pMesh, nVertexOffsetInBytes ); +} + + +//----------------------------------------------------------------------------- +// checks to see if it was rendered.. +//----------------------------------------------------------------------------- +void CBufferedMeshDX8::ResetRendered() +{ + m_WasRendered = false; +} + +bool CBufferedMeshDX8::WasNotRendered() const +{ + return !m_WasRendered; +} + + +//----------------------------------------------------------------------------- +// "Draws" it +//----------------------------------------------------------------------------- +void CBufferedMeshDX8::Draw( int nFirstIndex, int nIndexCount ) +{ + if ( !ShaderUtil()->OnDrawMesh( this, nFirstIndex, nIndexCount ) ) + { + m_WasRendered = true; + MarkAsDrawn(); + return; + } + + Assert( !m_IsFlushing && !m_WasRendered ); + + // Gotta draw all of the buffered mesh + Assert( (nFirstIndex == -1) && (nIndexCount == 0) ); + + // No need to draw it more than once... + m_WasRendered = true; + + // We've got something to flush + m_FlushNeeded = true; + + // Less than 0 indices indicates we were using a standard buffer + if ( m_pMesh->HasFlexMesh() || !ShaderUtil()->GetConfig().bBufferPrimitives ) + { + ShaderAPI()->FlushBufferedPrimitives(); + } +} + + +//----------------------------------------------------------------------------- +// Sets the primitive mode +//----------------------------------------------------------------------------- + +void CBufferedMeshDX8::SetPrimitiveType( MaterialPrimitiveType_t type ) +{ + Assert( IsX360() || ( type != MATERIAL_INSTANCED_QUADS ) ); + Assert( type != MATERIAL_HETEROGENOUS ); + + if (type != GetPrimitiveType()) + { + ShaderAPI()->FlushBufferedPrimitives(); + m_pMesh->SetPrimitiveType(type); + } +} + +MaterialPrimitiveType_t CBufferedMeshDX8::GetPrimitiveType( ) const +{ + return m_pMesh->GetPrimitiveType(); +} + + +//----------------------------------------------------------------------------- +// Locks/unlocks the entire mesh +//----------------------------------------------------------------------------- +void CBufferedMeshDX8::LockMesh( int nVertexCount, int nIndexCount, MeshDesc_t& desc ) +{ + ShaderUtil()->SyncMatrices(); + + Assert( m_pMesh ); + Assert( m_WasRendered ); + + // Do some pre-lock processing + m_pMesh->PreLock(); + + // for tristrips, gotta make degenerate ones... + m_ExtraIndices = 0; + bool tristripFixup = (m_pMesh->IndexCount() != 0) && + (m_pMesh->GetPrimitiveType() == MATERIAL_TRIANGLE_STRIP); + if (tristripFixup) + { + m_ExtraIndices = (m_pMesh->IndexCount() & 0x1) != 0 ? 3 : 2; + nIndexCount += m_ExtraIndices; + } + + // Flush if we gotta + if (!m_pMesh->HasEnoughRoom(nVertexCount, nIndexCount)) + { + ShaderAPI()->FlushBufferedPrimitives(); + } + + m_pMesh->LockMesh( nVertexCount, nIndexCount, desc ); + +// This is taken care of in the function above. +// CBaseMeshDX8::m_bMeshLocked = true; + + // Deal with fixing up the tristrip.. + if ( tristripFixup && desc.m_nIndexSize ) + { + char buf[32]; + if (DebugTrace()) + { + if (m_ExtraIndices == 3) + sprintf(buf,"Link Index: %d %d\n", m_LastIndex, m_LastIndex); + else + sprintf(buf,"Link Index: %d\n", m_LastIndex); + Plat_DebugString(buf); + } + *desc.m_pIndices++ = m_LastIndex; + if (m_ExtraIndices == 3) + { + *desc.m_pIndices++ = m_LastIndex; + } + + // Leave room for the last padding index + ++desc.m_pIndices; + } + + m_WasRendered = false; + +#ifdef DEBUG_BUFFERED_MESHES + if (m_BufferedStateSet) + { + BufferedState_t compare; + ShaderAPI()->GetBufferedState( compare ); + Assert( !memcmp( &compare, &m_BufferedState, sizeof(compare) ) ); + } + else + { + ShaderAPI()->GetBufferedState( m_BufferedState ); + m_BufferedStateSet = true; + } +#endif +} + + +//----------------------------------------------------------------------------- +// Locks/unlocks the entire mesh +//----------------------------------------------------------------------------- +void CBufferedMeshDX8::UnlockMesh( int nVertexCount, int nIndexCount, MeshDesc_t& desc ) +{ + Assert( m_pMesh ); + + // Gotta fix up the first index to batch strips reasonably + if ((m_pMesh->GetPrimitiveType() == MATERIAL_TRIANGLE_STRIP) && desc.m_nIndexSize ) + { + if (m_ExtraIndices > 0) + { + *(desc.m_pIndices - 1) = *desc.m_pIndices; + + if (DebugTrace()) + { + char buf[32]; + sprintf(buf,"Link Index: %d\n", *desc.m_pIndices); + Plat_DebugString(buf); + } + } + + // Remember the last index for next time + m_LastIndex = desc.m_pIndices[nIndexCount - 1]; + + nIndexCount += m_ExtraIndices; + } + + m_pMesh->UnlockMesh( nVertexCount, nIndexCount, desc ); + +// This is taken care of in the function above. +// CBaseMeshDX8::m_bMeshLocked = false; +} + + +//----------------------------------------------------------------------------- +// Renders a pass +//----------------------------------------------------------------------------- + +void CBufferedMeshDX8::RenderPass() +{ + // this should never be called! + Assert(0); +} + +//----------------------------------------------------------------------------- +// Flushes queued data +//----------------------------------------------------------------------------- + +void CBufferedMeshDX8::Flush( ) +{ + // If you are hitting this assert you are causing a flush between a + // meshbuilder begin/end and you are more than likely losing rendering data. + AssertOnce( !CBaseMeshDX8::m_bMeshLocked ); + + if ( m_pMesh && !m_IsFlushing && m_FlushNeeded ) + { + VPROF( "CBufferedMeshDX8::Flush" ); + +#ifdef DEBUG_BUFFERED_MESHES + if( m_BufferedStateSet ) + { + BufferedState_t compare; + ShaderAPI()->GetBufferedState( compare ); + Assert( !memcmp( &compare, &m_BufferedState, sizeof(compare) ) ); + m_BufferedStateSet = false; + } +#endif + + m_IsFlushing = true; + + // Actually draws the data using the mesh's material + static_cast(m_pMesh)->Draw(); + + m_IsFlushing = false; + m_FlushNeeded = false; + + m_pMesh->SetFlexMesh( NULL, 0 ); + } +} + +//----------------------------------------------------------------------------- +// +// Mesh manager implementation +// +//----------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +// Constructor, destructor +//----------------------------------------------------------------------------- +CMeshMgr::CMeshMgr() : + m_pDynamicIndexBuffer(0), + m_DynamicTempMesh(true), + m_pVertexIDBuffer(0), + m_pCurrentVertexBuffer( NULL ), + m_CurrentVertexFormat( 0 ), + m_pCurrentIndexBuffer( NULL ), + m_DynamicIndexBuffer( SHADER_BUFFER_TYPE_DYNAMIC, MATERIAL_INDEX_FORMAT_16BIT, INDEX_BUFFER_SIZE, "dynamic" ), + m_DynamicVertexBuffer( SHADER_BUFFER_TYPE_DYNAMIC, VERTEX_FORMAT_UNKNOWN, DYNAMIC_VERTEX_BUFFER_MEMORY, "dynamic" ) +{ + m_bUseFatVertices = false; + m_nIndexBufferOffset = 0; + memset( m_pVertexBufferOffset, 0, sizeof(m_pVertexBufferOffset) ); + memset( m_pCurrentVertexStride, 0, sizeof(m_pCurrentVertexStride) ); + memset( m_pFirstVertex, 0, sizeof(m_pFirstVertex) ); + memset( m_pVertexCount, 0, sizeof(m_pVertexCount) ); + m_nUnusedVertexFields = 0; + m_nUnusedTextureCoords = 0; + m_pZeroVertexBuffer = NULL; +} + +CMeshMgr::~CMeshMgr() +{ +} + + +//----------------------------------------------------------------------------- +// Initialize, shutdown +//----------------------------------------------------------------------------- +void CMeshMgr::Init() +{ + m_DynamicMesh.Init( 0 ); + m_DynamicFlexMesh.Init( 1 ); + + CreateDynamicIndexBuffer(); + + // If we're running in vs3.0, allocate a vertexID buffer + CreateVertexIDBuffer(); + + CreateZeroVertexBuffer(); + + m_BufferedMode = !IsX360(); +} + +void CMeshMgr::Shutdown() +{ + CleanUp(); +} + + +//----------------------------------------------------------------------------- +// Task switch... +//----------------------------------------------------------------------------- +void CMeshMgr::ReleaseBuffers() +{ + if ( IsPC() && mat_debugalttab.GetBool() ) + { + Warning( "mat_debugalttab: CMeshMgr::ReleaseBuffers\n" ); + } + + CleanUp(); + m_DynamicMesh.Reset( ); + m_DynamicFlexMesh.Reset( ); +} + +void CMeshMgr::RestoreBuffers() +{ + if ( IsPC() && mat_debugalttab.GetBool() ) + { + Warning( "mat_debugalttab: CMeshMgr::RestoreBuffers\n" ); + } + Init(); +} + + +//----------------------------------------------------------------------------- +// Cleans up vertex and index buffers +//----------------------------------------------------------------------------- +void CMeshMgr::CleanUp() +{ + DestroyDynamicIndexBuffer(); + + DestroyVertexBuffers(); + + // If we're running in vs3.0, allocate a vertexID buffer + DestroyVertexIDBuffer(); + DestroyZeroVertexBuffer(); +} + +//----------------------------------------------------------------------------- +// Fills a vertexID buffer +//----------------------------------------------------------------------------- +void CMeshMgr::FillVertexIDBuffer( CVertexBuffer *pVertexIDBuffer, int nCount ) +{ + if ( IsX360() ) + return; + + // Fill the buffer with the values 0->(nCount-1) + int nBaseVertexIndex = 0; + float *pBuffer = (float*)pVertexIDBuffer->Lock( nCount, nBaseVertexIndex ); + for ( int i = 0; i < nCount; ++i ) + { + *pBuffer++ = (float)i; + } + pVertexIDBuffer->Unlock( nCount ); +} + +//----------------------------------------------------------------------------- +// Creates, destroys the dynamic index buffer +//----------------------------------------------------------------------------- +void CMeshMgr::CreateDynamicIndexBuffer() +{ + DestroyDynamicIndexBuffer(); + SafeAssign( &m_pDynamicIndexBuffer, new CIndexBuffer( Dx9Device(), INDEX_BUFFER_SIZE, ShaderAPI()->UsingSoftwareVertexProcessing(), true ) ); +} + +void CMeshMgr::DestroyDynamicIndexBuffer() +{ + SafeRelease( &m_pDynamicIndexBuffer ); +} + +//----------------------------------------------------------------------------- +// Creates, destroys the vertexID buffer +//----------------------------------------------------------------------------- +void CMeshMgr::CreateVertexIDBuffer() +{ + if ( IsX360() ) + return; + + DestroyVertexIDBuffer(); + + // Track mesh allocations + g_VBAllocTracker->TrackMeshAllocations( "CreateVertexIDBuffer" ); + if ( g_pHardwareConfig->HasFastVertexTextures() ) + { + m_pVertexIDBuffer = new CVertexBuffer( Dx9Device(), 0, 0, sizeof(float), + VERTEX_BUFFER_SIZE, TEXTURE_GROUP_STATIC_VERTEX_BUFFER_OTHER, ShaderAPI()->UsingSoftwareVertexProcessing() ); + FillVertexIDBuffer( m_pVertexIDBuffer, VERTEX_BUFFER_SIZE ); + } + g_VBAllocTracker->TrackMeshAllocations( NULL ); +} + +void CMeshMgr::CreateZeroVertexBuffer() +{ + if ( !m_pZeroVertexBuffer ) + { + // In GL glVertexAttribPointer() doesn't support strides of 0, so we need to allocate a dummy vertex buffer large enough to handle 16-bit indices with a stride of 4 byte per vertex, plus a bit more for safety (in case basevertexindex is > 0). + // We could also try just disabling any vertex attribs that fetch from stream 2 and need 0's, but AMD reports this could hit a slow path in the driver. Argh. + uint nBufSize = IsOpenGL() ? ( 65536 * 2 * 4 ) : 4096; + HRESULT hr = Dx9Device()->CreateVertexBuffer( nBufSize, D3DUSAGE_WRITEONLY, 0, D3DPOOL_DEFAULT, &m_pZeroVertexBuffer, NULL ); + if ( !FAILED( hr ) ) + { + void *pData = NULL; + m_pZeroVertexBuffer->Lock( 0, nBufSize, &pData, D3DLOCK_NOSYSLOCK ); + if ( pData ) + { + V_memset( pData, 0, nBufSize ); + m_pZeroVertexBuffer->Unlock(); + } + } + } +} + +void CMeshMgr::DestroyZeroVertexBuffer() +{ + if ( m_pZeroVertexBuffer ) + { + m_pZeroVertexBuffer->Release(); + m_pZeroVertexBuffer = NULL; + } +} + +void CMeshMgr::DestroyVertexIDBuffer() +{ + if ( m_pVertexIDBuffer ) + { + delete m_pVertexIDBuffer; + m_pVertexIDBuffer = NULL; + } +} + +CVertexBuffer *CMeshMgr::GetVertexIDBuffer( ) +{ + return m_pVertexIDBuffer; +} + + +//----------------------------------------------------------------------------- +// Unused vertex fields +//----------------------------------------------------------------------------- +void CMeshMgr::MarkUnusedVertexFields( unsigned int nFlags, int nTexCoordCount, bool *pUnusedTexCoords ) +{ + m_nUnusedVertexFields = nFlags; + m_nUnusedTextureCoords = 0; + for ( int i = 0; i < nTexCoordCount; ++i ) + { + if ( pUnusedTexCoords[i] ) + { + m_nUnusedTextureCoords |= ( 1 << i ); + } + } +} + + +//----------------------------------------------------------------------------- +// Is the mesh dynamic? +//----------------------------------------------------------------------------- +bool CMeshMgr::IsDynamicMesh( IMesh* pMesh ) const +{ + return ( pMesh == &m_DynamicMesh ) || ( pMesh == &m_DynamicFlexMesh ); +} + +bool CMeshMgr::IsBufferedDynamicMesh( IMesh* pMesh ) const +{ + return ( pMesh == &m_BufferedMesh ); +} + +bool CMeshMgr::IsDynamicVertexBuffer( IVertexBuffer *pVertexBuffer ) const +{ + return ( pVertexBuffer == &m_DynamicVertexBuffer ); +} + +bool CMeshMgr::IsDynamicIndexBuffer( IIndexBuffer *pIndexBuffer ) const +{ + return ( pIndexBuffer == &m_DynamicIndexBuffer ); +} + +//----------------------------------------------------------------------------- +// Discards the dynamic vertex and index buffer +//----------------------------------------------------------------------------- +void CMeshMgr::DiscardVertexBuffers() +{ + VPROF_BUDGET( "CMeshMgr::DiscardVertexBuffers", VPROF_BUDGETGROUP_SWAP_BUFFERS ); + // This shouldn't be necessary, but it seems to be on GeForce 2 + // It helps when running WC and the engine simultaneously. + ResetMeshRenderState(); + + if ( !g_pShaderDeviceDx8->IsDeactivated() ) + { + for (int i = m_DynamicVertexBuffers.Count(); --i >= 0; ) + { + m_DynamicVertexBuffers[i].m_pBuffer->FlushAtFrameStart(); + } + m_pDynamicIndexBuffer->FlushAtFrameStart(); + } +} + + +//----------------------------------------------------------------------------- +// Releases all dynamic vertex buffers +//----------------------------------------------------------------------------- +void CMeshMgr::DestroyVertexBuffers() +{ + // Necessary for cleanup + RECORD_COMMAND( DX8_SET_STREAM_SOURCE, 4 ); + RECORD_INT( -1 ); + RECORD_INT( 0 ); + RECORD_INT( 0 ); + RECORD_INT( 0 ); + D3DSetStreamSource( 0, 0, 0, 0 ); + + RECORD_COMMAND( DX8_SET_STREAM_SOURCE, 4 ); + RECORD_INT( -1 ); + RECORD_INT( 1 ); + RECORD_INT( 0 ); + RECORD_INT( 0 ); + D3DSetStreamSource( 1, 0, 0, 0 ); + + RECORD_COMMAND( DX8_SET_STREAM_SOURCE, 4 ); + RECORD_INT( -1 ); + RECORD_INT( 2 ); + RECORD_INT( 0 ); + RECORD_INT( 0 ); + D3DSetStreamSource( 2, 0, 0, 0 ); + +#ifndef _X360 + RECORD_COMMAND( DX8_SET_STREAM_SOURCE, 4 ); + RECORD_INT( -1 ); + RECORD_INT( 3 ); + RECORD_INT( 0 ); + RECORD_INT( 0 ); + D3DSetStreamSource( 3, 0, 0, 0 ); +#endif + + for (int i = m_DynamicVertexBuffers.Count(); --i >= 0; ) + { + if (m_DynamicVertexBuffers[i].m_pBuffer) + { + delete m_DynamicVertexBuffers[i].m_pBuffer; + } + } + m_DynamicVertexBuffers.RemoveAll(); + m_DynamicMesh.Reset(); + m_DynamicFlexMesh.Reset(); +} + + +//----------------------------------------------------------------------------- +// Flushes the dynamic mesh +//----------------------------------------------------------------------------- +void CMeshMgr::Flush() +{ + if ( IsPC() ) + { + m_BufferedMesh.HandleLateCreation(); + m_BufferedMesh.Flush(); + } +} + + +//----------------------------------------------------------------------------- +// Creates, destroys static meshes +//----------------------------------------------------------------------------- +IMesh* CMeshMgr::CreateStaticMesh( VertexFormat_t format, const char *pTextureBudgetGroup, IMaterial * pMaterial ) +{ + // FIXME: Use a fixed-size allocator + CMeshDX8* pNewMesh = new CMeshDX8( pTextureBudgetGroup ); + pNewMesh->SetVertexFormat( format ); + if ( pMaterial != NULL ) + { + pNewMesh->SetMorphFormat( pMaterial->GetMorphFormat() ); + pNewMesh->SetMaterial( pMaterial ); + } + return pNewMesh; +} + +void CMeshMgr::DestroyStaticMesh( IMesh* pMesh ) +{ + // Don't destroy the dynamic mesh! + Assert( !IsDynamicMesh( pMesh ) ); + CBaseMeshDX8* pMeshImp = static_cast(pMesh); + if (pMeshImp) + { + delete pMeshImp; + } +} + +//----------------------------------------------------------------------------- +// Gets at the *real* dynamic mesh +//----------------------------------------------------------------------------- +IMesh* CMeshMgr::GetActualDynamicMesh( VertexFormat_t format ) +{ + m_DynamicMesh.SetVertexFormat( format ); + return &m_DynamicMesh; +} + +//----------------------------------------------------------------------------- +// Copy a static mesh index buffer to a dynamic mesh index buffer +//----------------------------------------------------------------------------- +void CMeshMgr::CopyStaticMeshIndexBufferToTempMeshIndexBuffer( CTempMeshDX8 *pDstIndexMesh, + CMeshDX8 *pSrcIndexMesh ) +{ + tmZoneFiltered( TELEMETRY_LEVEL0, 50, TMZF_NONE, "%s", __FUNCTION__ ); + + Assert( !pSrcIndexMesh->IsDynamic() ); + int nIndexCount = pSrcIndexMesh->IndexCount(); + + CMeshBuilder dstMeshBuilder; + dstMeshBuilder.Begin( pDstIndexMesh, pSrcIndexMesh->GetPrimitiveType(), 0, nIndexCount ); + CIndexBuffer *srcIndexBuffer = pSrcIndexMesh->GetIndexBuffer(); + int dummy = 0; + unsigned short *srcIndexArray = srcIndexBuffer->Lock( false, nIndexCount, dummy, 0 ); + int i; + for( i = 0; i < nIndexCount; i++ ) + { + dstMeshBuilder.Index( srcIndexArray[i] ); + dstMeshBuilder.AdvanceIndex(); + } + srcIndexBuffer->Unlock( 0 ); + dstMeshBuilder.End(); +} + + +IMesh *CMeshMgr::GetFlexMesh() +{ + if ( g_pMaterialSystemHardwareConfig->SupportsPixelShaders_2_b() ) + { + // FIXME: Kinda ugly size.. 28 bytes + m_DynamicFlexMesh.SetVertexFormat( VERTEX_POSITION | VERTEX_NORMAL | VERTEX_WRINKLE | VERTEX_FORMAT_USE_EXACT_FORMAT ); + } + else + { + // Same size as a pair of float3s (24 bytes) + m_DynamicFlexMesh.SetVertexFormat( VERTEX_POSITION | VERTEX_NORMAL | VERTEX_FORMAT_USE_EXACT_FORMAT ); + } + return &m_DynamicFlexMesh; +} + +//----------------------------------------------------------------------------- +// Gets at the dynamic mesh +//----------------------------------------------------------------------------- +IMesh* CMeshMgr::GetDynamicMesh( IMaterial* pMaterial, VertexFormat_t vertexFormat, int nHWSkinBoneCount, + bool buffered, IMesh* pVertexOverride, IMesh* pIndexOverride ) +{ + tmZoneFiltered( TELEMETRY_LEVEL0, 50, TMZF_NONE, "%s", __FUNCTION__ ); + + Assert( (pMaterial == NULL) || ((IMaterialInternal *)pMaterial)->IsRealTimeVersion() ); + + if ( IsX360() ) + { + buffered = false; + } + + // Can't be buffered if we're overriding the buffers + if ( pVertexOverride || pIndexOverride ) + { + buffered = false; + } + + // When going from buffered to unbuffered mode, need to flush.. + if ((m_BufferedMode != buffered) && m_BufferedMode) + { + m_BufferedMesh.SetMesh(0); + } + m_BufferedMode = buffered; + + IMaterialInternal* pMatInternal = static_cast(pMaterial); + + bool needTempMesh = ShaderAPI()->IsInSelectionMode(); + +#ifdef DRAW_SELECTION + if( g_bDrawSelection ) + { + needTempMesh = true; + } +#endif + + CBaseMeshDX8* pMesh; + + if ( needTempMesh ) + { + // These haven't been implemented yet for temp meshes! + // I'm not a hundred percent sure how to implement them; it would + // involve a lock and a copy at least, which would stall the entire + // rendering pipeline. + Assert( !pVertexOverride ); + + if( pIndexOverride ) + { + CopyStaticMeshIndexBufferToTempMeshIndexBuffer( &m_DynamicTempMesh, + ( CMeshDX8 * )pIndexOverride ); + } + pMesh = &m_DynamicTempMesh; + } + else + { + pMesh = &m_DynamicMesh; + } + + if ( m_BufferedMode ) + { + Assert( !m_BufferedMesh.WasNotRendered() ); + m_BufferedMesh.SetMesh( pMesh ); + pMesh = &m_BufferedMesh; + } + + if( !pVertexOverride ) + { + // Remove VERTEX_FORMAT_COMPRESSED from the material's format (dynamic meshes don't + // support compression, and all materials should support uncompressed verts too) + VertexFormat_t materialFormat = pMatInternal->GetVertexFormat() & ~VERTEX_FORMAT_COMPRESSED; + VertexFormat_t fmt = ( vertexFormat != 0 ) ? vertexFormat : materialFormat; + if ( vertexFormat != 0 ) + { + int nVertexFormatBoneWeights = NumBoneWeights( vertexFormat ); + if ( nHWSkinBoneCount < nVertexFormatBoneWeights ) + { + nHWSkinBoneCount = nVertexFormatBoneWeights; + } + } + + // Force the requested number of bone weights + fmt &= ~VERTEX_BONE_WEIGHT_MASK; + if ( nHWSkinBoneCount > 0 ) + { + fmt |= VERTEX_BONEWEIGHT( 2 ); + fmt |= VERTEX_BONE_INDEX; + } + + pMesh->SetVertexFormat( fmt ); + } + else + { + CBaseMeshDX8 *pDX8Mesh = static_cast(pVertexOverride); + pMesh->SetVertexFormat( pDX8Mesh->GetVertexFormat() ); + } + pMesh->SetMorphFormat( pMatInternal->GetMorphFormat() ); + pMesh->SetMaterial( pMatInternal ); + + // Note this works because we're guaranteed to not be using a buffered mesh + // when we have overrides on + // FIXME: Make work for temp meshes + if ( pMesh == &m_DynamicMesh ) + { + CBaseMeshDX8* pBaseVertex = static_cast( pVertexOverride ); + if ( pBaseVertex ) + { + m_DynamicMesh.OverrideVertexBuffer( pBaseVertex->GetVertexBuffer() ); + } + + CBaseMeshDX8* pBaseIndex = static_cast( pIndexOverride ); + if ( pBaseIndex ) + { + m_DynamicMesh.OverrideIndexBuffer( pBaseIndex->GetIndexBuffer() ); + } + } + + return pMesh; +} + + +//----------------------------------------------------------------------------- +// Used to construct vertex data +//----------------------------------------------------------------------------- +void CMeshMgr::ComputeVertexDescription( unsigned char* pBuffer, + VertexFormat_t vertexFormat, MeshDesc_t& desc ) const +{ + ComputeVertexDesc( pBuffer, vertexFormat, (VertexDesc_t &)desc ); +} + + +//----------------------------------------------------------------------------- +// Computes the vertex format +//----------------------------------------------------------------------------- +VertexFormat_t CMeshMgr::ComputeVertexFormat( unsigned int flags, + int nTexCoordArraySize, int* pTexCoordDimensions, int numBoneWeights, + int userDataSize ) const +{ + // Construct a bitfield that makes sense and is unique from the standard FVF formats + VertexFormat_t fmt = flags & ~VERTEX_FORMAT_USE_EXACT_FORMAT; + + if ( g_pHardwareConfig->SupportsCompressedVertices() == VERTEX_COMPRESSION_NONE ) + { + // Vertex compression is disabled - make sure all materials + // say "No!" to compressed verts ( tested in IsValidVertexFormat() ) + fmt &= ~VERTEX_FORMAT_COMPRESSED; + } + + // This'll take 3 bits at most + Assert( numBoneWeights <= 4 ); + + if ( numBoneWeights > 0 ) + { + fmt |= VERTEX_BONEWEIGHT( 2 ); // Always exactly two weights + } + + // Size is measured in # of floats + Assert( userDataSize <= 4 ); + fmt |= VERTEX_USERDATA_SIZE(userDataSize); + + // NOTE: If pTexCoordDimensions isn't specified, then nTexCoordArraySize + // is interpreted as meaning that we have n 2D texcoords in the first N texcoord slots + nTexCoordArraySize = min( nTexCoordArraySize, (int)VERTEX_MAX_TEXTURE_COORDINATES ); + for ( int i = 0; i < nTexCoordArraySize; ++i ) + { + if ( pTexCoordDimensions ) + { + Assert( pTexCoordDimensions[i] >= 0 && pTexCoordDimensions[i] <= 4 ); + fmt |= VERTEX_TEXCOORD_SIZE( (TextureStage_t)i, pTexCoordDimensions[i] ); + } + else + { + fmt |= VERTEX_TEXCOORD_SIZE( (TextureStage_t)i, 2 ); + } + } + + return fmt; +} + + +//----------------------------------------------------------------------------- +// Use fat vertices (for tools) +//----------------------------------------------------------------------------- +void CMeshMgr::UseFatVertices( bool bUseFat ) +{ + m_bUseFatVertices = bUseFat; +} + + +//----------------------------------------------------------------------------- +// Returns the number of vertices we can render using the dynamic mesh +//----------------------------------------------------------------------------- +void CMeshMgr::GetMaxToRender( IMesh *pMesh, bool bMaxUntilFlush, int *pMaxVerts, int *pMaxIndices ) +{ + CBaseMeshDX8 *pBaseMesh = static_cast( pMesh ); + if ( !pBaseMesh ) + { + *pMaxVerts = 0; + *pMaxIndices = m_pDynamicIndexBuffer->IndexCount(); + return; + } + + if ( IsBufferedDynamicMesh( pMesh ) ) + { + pBaseMesh = (CBaseMeshDX8*)static_cast( pBaseMesh )->GetMesh(); + pMesh = pBaseMesh; + } + + // Static mesh? Max you can use is 65535 + if ( !IsDynamicMesh( pMesh ) ) + { + *pMaxVerts = 65535; + *pMaxIndices = 65535; + return; + } + + CVertexBuffer *pVertexBuffer = pBaseMesh->GetVertexBuffer(); + CIndexBuffer *pIndexBuffer = pBaseMesh->GetIndexBuffer(); + + if ( !pVertexBuffer ) + { + *pMaxVerts = 0; + *pMaxIndices = 0; + return; + } + + if ( !bMaxUntilFlush ) + { + *pMaxVerts = ShaderAPI()->GetCurrentDynamicVBSize() / pVertexBuffer->VertexSize(); + if ( *pMaxVerts > 65535 ) + { + *pMaxVerts = 65535; + } + *pMaxIndices = pIndexBuffer ? pIndexBuffer->IndexCount() : 0; + return; + } + + *pMaxVerts = pVertexBuffer->NumVerticesUntilFlush(); + *pMaxIndices = pIndexBuffer ? pIndexBuffer->IndexCount() - pIndexBuffer->IndexPosition() : 0; + if ( *pMaxVerts == 0 ) + { + *pMaxVerts = ShaderAPI()->GetCurrentDynamicVBSize() / pVertexBuffer->VertexSize(); + } + if ( *pMaxVerts > 65535 ) + { + *pMaxVerts = 65535; + } + if ( *pMaxIndices == 0 ) + { + *pMaxIndices = pIndexBuffer ? pIndexBuffer->IndexCount() : 0; + } +} + +int CMeshMgr::GetMaxVerticesToRender( IMaterial *pMaterial ) +{ + Assert( (pMaterial == NULL) || ((IMaterialInternal *)pMaterial)->IsRealTimeVersion() ); + + // Be conservative, assume no compression (in here, we don't know if the caller will used a compressed VB or not) + // FIXME: allow the caller to specify which compression type should be used to compute size from the vertex format + // (this can vary between multiple VBs/Meshes using the same material) + VertexFormat_t fmt = pMaterial->GetVertexFormat() & ~VERTEX_FORMAT_COMPRESSED; + int nVertexSize = VertexFormatSize( fmt ); + if ( nVertexSize == 0 ) + { + // unable to determine vertex format information, possibly due to device loss. + Warning( "bad vertex size for material %s\n", pMaterial->GetName() ); + return 0; + } + + int nMaxVerts = ShaderAPI()->GetCurrentDynamicVBSize() / nVertexSize; + return MIN( nMaxVerts, 65535 ); +} + +int CMeshMgr::GetMaxIndicesToRender( ) +{ + return INDEX_BUFFER_SIZE; +} + +//----------------------------------------------------------------------------- +// Returns a vertex buffer appropriate for the flags +//----------------------------------------------------------------------------- +CVertexBuffer *CMeshMgr::FindOrCreateVertexBuffer( int nDynamicBufferId, VertexFormat_t vertexFormat ) +{ + int vertexSize = VertexFormatSize( vertexFormat ); + + while ( m_DynamicVertexBuffers.Count() <= nDynamicBufferId ) + { + // Track VB allocations (override any prior allocator string set higher up on the callstack) + g_VBAllocTracker->TrackMeshAllocations( NULL ); + g_VBAllocTracker->TrackMeshAllocations( "CMeshMgr::FindOrCreateVertexBuffer (dynamic VB)" ); + + // create the single 1MB dynamic vb that will be shared amongst all consumers + // the correct thing is to use the largest expected vertex format size of max elements, but this + // creates an undesirably large buffer - instead create the buffer we want, and fix consumers that bork + // NOTE: GetCurrentDynamicVBSize returns a smaller value during level transitions + int nBufferMemory = ShaderAPI()->GetCurrentDynamicVBSize(); + int nIndex = m_DynamicVertexBuffers.AddToTail(); + m_DynamicVertexBuffers[nIndex].m_VertexSize = 0; + m_DynamicVertexBuffers[nIndex].m_pBuffer = new CVertexBuffer( Dx9Device(), 0, 0, + nBufferMemory / VERTEX_BUFFER_SIZE, VERTEX_BUFFER_SIZE, TEXTURE_GROUP_STATIC_VERTEX_BUFFER_OTHER, ShaderAPI()->UsingSoftwareVertexProcessing(), true ); + + g_VBAllocTracker->TrackMeshAllocations( NULL ); + } + + if ( m_DynamicVertexBuffers[nDynamicBufferId].m_VertexSize != vertexSize ) + { + // provide caller with dynamic vb in expected format + // NOTE: GetCurrentDynamicVBSize returns a smaller value during level transitions + int nBufferMemory = ShaderAPI()->GetCurrentDynamicVBSize(); + m_DynamicVertexBuffers[nDynamicBufferId].m_VertexSize = vertexSize; + m_DynamicVertexBuffers[nDynamicBufferId].m_pBuffer->ChangeConfiguration( vertexSize, nBufferMemory ); + + // size changed means stream stride needs update + // mark cached stream state as invalid to reset stream + if ( nDynamicBufferId == 0 ) + { + g_pLastVertex = NULL; + } + } + + return m_DynamicVertexBuffers[nDynamicBufferId].m_pBuffer; +} + +CIndexBuffer *CMeshMgr::GetDynamicIndexBuffer() +{ + return m_pDynamicIndexBuffer; +} + +IVertexBuffer *CMeshMgr::GetDynamicVertexBuffer( IMaterial *pMaterial, bool buffered ) +{ + Assert( 0 ); + return NULL; +// return ( IMeshDX8 * )GetDynamicMesh( pMaterial, buffered, NULL, NULL ); +} + +IIndexBuffer *CMeshMgr::GetDynamicIndexBuffer( IMaterial *pMaterial, bool buffered ) +{ + Assert( 0 ); + return NULL; +// return ( IMeshDX8 * )GetDynamicMesh( pMaterial, buffered, NULL, NULL ); +} + + +//----------------------------------------------------------------------------- +IVertexBuffer *CMeshMgr::CreateVertexBuffer( ShaderBufferType_t type, VertexFormat_t fmt, int nVertexCount, const char *pBudgetGroup ) +{ + // FIXME: Use a fixed-size allocator + CVertexBufferDx8 *pNewVertexBuffer = new CVertexBufferDx8( type, fmt, nVertexCount, pBudgetGroup ); + return pNewVertexBuffer; +} + +IIndexBuffer *CMeshMgr::CreateIndexBuffer( ShaderBufferType_t bufferType, MaterialIndexFormat_t fmt, int nIndexCount, const char *pBudgetGroup ) +{ + switch( bufferType ) + { + case SHADER_BUFFER_TYPE_STATIC: + case SHADER_BUFFER_TYPE_DYNAMIC: + { + CIndexBufferDx8 *pIndexBuffer = new CIndexBufferDx8( bufferType, fmt, nIndexCount, pBudgetGroup ); + return pIndexBuffer; + } + case SHADER_BUFFER_TYPE_STATIC_TEMP: + case SHADER_BUFFER_TYPE_DYNAMIC_TEMP: + Assert( 0 ); + return NULL; + default: + Assert( 0 ); + return NULL; + } +} + +void CMeshMgr::DestroyVertexBuffer( IVertexBuffer *pVertexBuffer ) +{ + if ( pVertexBuffer && !IsDynamicVertexBuffer( pVertexBuffer ) ) + { + delete pVertexBuffer; + } +} + +void CMeshMgr::DestroyIndexBuffer( IIndexBuffer *pIndexBuffer ) +{ + if ( pIndexBuffer && !IsDynamicIndexBuffer( pIndexBuffer ) ) + { + delete pIndexBuffer; + } +} + +// Do we need to specify the stream here in the case of locking multiple dynamic VBs on different streams? +IVertexBuffer *CMeshMgr::GetDynamicVertexBuffer( int streamID, VertexFormat_t vertexFormat, bool bBuffered ) +{ + if ( IsX360() ) + { + bBuffered = false; + } + + if ( CompressionType( vertexFormat ) != VERTEX_COMPRESSION_NONE ) + { + // UNDONE: support compressed dynamic meshes if needed (pro: less VB memory, con: time spent compressing) + DebuggerBreak(); + return NULL; + } + + // MESHFIXME +#if 0 + if ( ( m_BufferedMode != bBuffered ) && m_BufferedMode ) + { + m_BufferedIndexBuffer.SetIndexBuffer( NULL ); + } +#endif + + m_BufferedMode = bBuffered; + Assert( !m_BufferedMode ); // MESHFIXME: don't deal with buffered VBs yet. + + bool needTempMesh = ShaderAPI()->IsInSelectionMode(); + +#ifdef DRAW_SELECTION + if( g_bDrawSelection ) + { + needTempMesh = true; + } +#endif + + Assert( !needTempMesh ); // MESHFIXME: don't support temp meshes here yet. + + CVertexBufferDx8 *pVertexBuffer; + + if ( needTempMesh ) + { + Assert( 0 ); // MESHFIXME: don't do this yet. +// pVertexBuffer = &m_DynamicTempVertexBuffer; + pVertexBuffer = NULL; + } + else + { + pVertexBuffer = &m_DynamicVertexBuffer; + } + + if ( m_BufferedMode ) + { + Assert( 0 ); // don't support this yet. +#if 0 + Assert( !m_BufferedMesh.WasNotRendered() ); + m_BufferedMesh.SetMesh( pMesh ); + pMesh = &m_BufferedMesh; +#endif + } + + return pVertexBuffer; +} + +IIndexBuffer *CMeshMgr::GetDynamicIndexBuffer( MaterialIndexFormat_t fmt, bool bBuffered ) +{ + if ( IsX360() ) + { + bBuffered = false; + } + + m_BufferedMode = bBuffered; + + Assert( !m_BufferedMode ); + +#ifdef DBGFLAG_ASSERT + bool needTempMesh = +#endif + ShaderAPI()->IsInSelectionMode(); + +#ifdef DRAW_SELECTION + if( g_bDrawSelection ) + { + needTempMesh = true; + } +#endif + + Assert( !needTempMesh ); // don't handle this yet. MESHFIXME + + CIndexBufferBase *pIndexBuffer = &m_DynamicIndexBuffer; + return pIndexBuffer; +} + +void CMeshMgr::SetVertexIDStreamState() +{ + if ( IsX360() ) + return; + + // MESHFIXME : This path is only used for the new index/vertex buffer interfaces. + // MESHFIXME : This path is only used for the new index/vertex buffer interfaces. + bool bUsingVertexID = false;//IsUsingVertexID(); +// if ( bUsingVertexID != g_bUsingVertexID ) + { + if ( bUsingVertexID ) + { + // NOTE: Morphing doesn't work with dynamic buffers!!! BLEAH + // It's because the indices (which are not 0 based for dynamic buffers) + // are accessing both the vertexID buffer + the regular vertex buffer. + // This *might* be fixable with baseVertexIndex? + Assert( !m_pCurrentVertexBuffer->IsDynamic() ); + + CVertexBuffer *pVertexIDBuffer = g_MeshMgr.GetVertexIDBuffer( ); + RECORD_COMMAND( DX8_SET_STREAM_SOURCE, 4 ); + RECORD_INT( pVertexIDBuffer->UID() ); + RECORD_INT( 3 ); + RECORD_INT( 0 ); + RECORD_INT( pVertexIDBuffer->VertexSize() ); + + D3DSetStreamSource( 3, pVertexIDBuffer->GetInterface(), 0, pVertexIDBuffer->VertexSize() ); + pVertexIDBuffer->HandlePerFrameTextureStats( ShaderAPI()->GetCurrentFrameCounter() ); + } + else + { + RECORD_COMMAND( DX8_SET_STREAM_SOURCE, 4 ); + RECORD_INT( -1 ); // vertex buffer id + RECORD_INT( 3 ); // stream + RECORD_INT( 0 ); // vertex offset + RECORD_INT( 0 ); // vertex size + + D3DSetStreamSource( 3, 0, 0, 0 ); + } + g_bUsingVertexID = bUsingVertexID; + } +} + +void CMeshMgr::SetColorStreamState() +{ + if ( g_pLastColorMesh ) + { + RECORD_COMMAND( DX8_SET_STREAM_SOURCE, 4 ); + RECORD_INT( -1 ); // vertex buffer id + RECORD_INT( 1 ); // stream + RECORD_INT( 0 ); // vertex offset + RECORD_INT( 0 ); // vertex size + + D3DSetStreamSource( 1, 0, 0, 0 ); + } + g_pLastColorMesh = NULL; + g_nLastColorMeshVertOffsetInBytes = 0; +} + +void CMeshMgr::SetVertexStreamState( int nVertOffsetInBytes, int nVertexStride ) +{ + // Calls in here assume shader support... + if ( HardwareConfig()->SupportsVertexAndPixelShaders() ) + { + // Set a 4kb all-zero static VB into the flex/wrinkle stream with a stride of 0 bytes, so the vertex shader always reads valid floating point values (otherwise it can get NaN's/Inf's, and under OpenGL this is bad on NVidia) + // togl requires non-zero strides, but on D3D9 we can set a stride of 0 for a little more efficiency. + D3DSetStreamSource( 2, g_MeshMgr.GetZeroVertexBuffer(), 0, IsOpenGL() ? 4 : 0 ); + + // cFlexScale.x masks flex in vertex shader + if ( g_pHardwareConfig->Caps().m_SupportsVertexShaders_2_0 ) + { + float c[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; + ShaderAPI()->SetVertexShaderConstant( VERTEX_SHADER_FLEXSCALE, c, 1 ); + } + + g_bFlexMeshStreamSet = false; + } + + // MESHFIXME : This path is only used for the new index/vertex buffer interfaces. + if ( g_pLastVertex || ( g_pLastVertexBuffer != m_pCurrentVertexBuffer->GetDx9Buffer() ) || + ( g_nLastVertOffsetInBytes != nVertOffsetInBytes ) || ( g_nLastVertStride != nVertexStride )) + { + Assert( m_pCurrentVertexBuffer && m_pCurrentVertexBuffer->GetDx9Buffer() ); + + D3DSetStreamSource( 0, m_pCurrentVertexBuffer->GetDx9Buffer(), nVertOffsetInBytes, nVertexStride ); + m_pCurrentVertexBuffer->HandlePerFrameTextureStats( ShaderAPI()->GetCurrentFrameCounter() ); + + g_pLastVertex = NULL; + g_nLastVertStride = nVertexStride; + g_pLastVertexBuffer = m_pCurrentVertexBuffer->GetDx9Buffer(); + g_nLastVertOffsetInBytes = nVertOffsetInBytes; + } +} + +bool CMeshMgr::SetRenderState( int nVertexOffsetInBytes, int nFirstVertexIdx, VertexFormat_t vertexFormat, int nVertexStride ) +{ + // Can't set the state if we're deactivated + if ( g_pShaderDeviceDx8->IsDeactivated() ) + { + ResetMeshRenderState(); + return false; + } + + // make sure the vertex format is a superset of the current material's + // vertex format... + // MESHFIXME : This path is only used for the new index/vertex buffer interfaces. +#if 0 + // FIXME + if ( !IsValidVertexFormat( vertexFormat ) ) + { + Warning( "Material %s is being applied to a model, you need $model=1 in the .vmt file!\n", + ShaderAPI()->GetBoundMaterial()->GetName() ); + return false; + } +#endif + + SetVertexIDStreamState(); + SetColorStreamState(); + SetVertexStreamState( nVertexOffsetInBytes, nVertexStride ); + SetIndexStreamState( nFirstVertexIdx ); + + return true; +} + +void CMeshMgr::BindVertexBuffer( int nStreamID, IVertexBuffer *pVertexBuffer, int nOffsetInBytes, int nFirstVertex, int nVertexCount, VertexFormat_t fmt, int nRepetitions ) +{ + // FIXME: Multiple stream support isn't implemented yet + Assert( nStreamID == 0 ); + + m_pCurrentVertexBuffer = static_cast< CVertexBufferDx8 * >( pVertexBuffer ); + m_CurrentVertexFormat = fmt; + m_pVertexBufferOffset[nStreamID] = nOffsetInBytes; + m_pCurrentVertexStride[nStreamID] = m_pCurrentVertexBuffer->VertexSize(); + m_pFirstVertex[nStreamID] = nFirstVertex; + m_pVertexCount[nStreamID] = nVertexCount, + m_pVertexIDBuffer = NULL; +} + +void CMeshMgr::BindIndexBuffer( IIndexBuffer *pIndexBuffer, int nOffsetInBytes ) +{ + m_pCurrentIndexBuffer = static_cast< CIndexBufferBase * >( pIndexBuffer ); + m_nIndexBufferOffset = nOffsetInBytes; +} + +void CMeshMgr::Draw( MaterialPrimitiveType_t primitiveType, int nFirstIndex, int nIndexCount ) +{ + // MESHFIXME : This path is only used for the new index/vertex buffer interfaces. + // make sure we aren't using a morph stream for this path. +// Assert( !IsUsingMorphData() ); +// Assert( !m_pColorMesh ); + + SetRenderState( m_pVertexBufferOffset[0], /* nFirstVertexIdx */0, m_CurrentVertexFormat, m_pCurrentVertexStride[0] ); + + m_PrimitiveType = MATERIAL_TRIANGLES; + Assert( primitiveType == MATERIAL_TRIANGLES ); + + m_nFirstIndex = nFirstIndex; + m_nNumIndices = nIndexCount; + + ShaderAPI()->DrawWithVertexAndIndexBuffers(); +} + +void CMeshMgr::RenderPassWithVertexAndIndexBuffers( void ) +{ +// LOCK_SHADERAPI(); MESHFIXME + VPROF( "CShaderAPIDX8::RenderPassWithVertexAndIndexBuffers" ); + + Assert( m_PrimitiveType != MATERIAL_HETEROGENOUS ); + +// for ( int iPrim=0; iPrim < s_nPrims; iPrim++ ) + { +// CPrimList *pPrim = &s_pPrims[iPrim]; + +// if ( pPrim->m_NumIndices == 0 ) +// continue; + + if ( m_PrimitiveType == MATERIAL_POINTS ) + { + // (For point lists, we don't actually fill in indices, but we treat it as + // though there are indices for the list up until here). + Assert( 0 ); +// Dx9Device()->DrawPrimitive( ComputeMode( m_PrimitiveType ), s_FirstVertex, pPrim->m_NumIndices ); + } + else + { +// int numPrimitives = NumPrimitives( s_NumVertices, pPrim->m_NumIndices ); + +// Warning( "CMeshMgr::RenderPassWithVertexAndIndexBuffers: DrawIndexedPrimitive: m_nFirstIndex = %d numPrimitives = %d\n", ( int )( ( CDynamiCIndexBufferDx8 * )m_pCurrentIndexBuffer )->m_FirstIndex, ( int )( m_nNumIndices / 3 ) ); + { + VPROF( "Dx9Device()->DrawIndexedPrimitive" ); +// VPROF_INCREMENT_COUNTER( "DrawIndexedPrimitive", 1 ); +// VPROF_INCREMENT_COUNTER( "numPrimitives", numPrimitives ); + +// Dx9Device()->DrawIndexedPrimitive( +// m_Mode, +// m_FirstIndex, +// s_FirstVertex, +// s_NumVertices, +// pPrim->m_FirstIndex, +// numPrimitives ); + + Assert( m_nFirstIndex >= 0 ); + +#ifdef CHECK_INDICES + // g_pLastVertex - this is the current vertex buffer + // g_pLastColorMesh - this is the curent color mesh, if there is one. + // g_pLastIndex - this is the current index buffer. + // vertoffset : m_FirstIndex + CIndexBufferDx8 *pIndexBuffer = assert_cast< CIndexBufferDx8 * >( m_pCurrentIndexBuffer ); + if( m_PrimitiveType == MATERIAL_TRIANGLES || m_PrimitiveType == MATERIAL_TRIANGLE_STRIP ) + { + // FIXME: need to be able to deal with multiple stream here, but don't bother for now. + int j; + int numVerts = m_pVertexCount[0]; + for( j = 0; j < m_nNumIndices; j++ ) + { + int index = pIndexBuffer->GetShadowIndex( j + m_nFirstIndex ); + Assert( index >= m_pFirstVertex[0] ); + Assert( index < m_pFirstVertex[0] + numVerts ); + } + } +#endif // CHECK_INDICES + Dx9Device()->DrawIndexedPrimitive( + ComputeMode( m_PrimitiveType ), // Member of the D3DPRIMITIVETYPE enumerated type, describing the type of primitive to render. D3DPT_POINTLIST is not supported with this method. + + /*m_FirstIndex*/ 0, // Offset from the start of the vertex buffer to the first vertex index. An index of 0 in the index buffer refers to this location in the vertex buffer. + + /*s_FirstVertex*/ m_pFirstVertex[0],// Minimum vertex index for vertices used during this call. This is a zero based index relative to BaseVertexIndex. + // This is zero for now since we don't do more than one batch yet with the new mesh interface. + + /*s_NumVertices*/ m_pVertexCount[0], + // Number of vertices used during this call. The first vertex is located at index: BaseVertexIndex + MinIndex. + // This is simple the number of verts in the current vertex buffer for now since we don't do more than one batch with the new mesh interface. + + m_nFirstIndex /*pPrim->m_FirstIndex*/, // Index of the first index to use when accesssing the vertex buffer. Beginning at StartIndex to index vertices from the vertex buffer. + + m_nNumIndices / 3/*numPrimitives*/ // Number of primitives to render. The number of vertices used is a function of the primitive count and the primitive type. + ); + + Assert( CMeshDX8::s_FirstVertex == 0 ); + Assert( CMeshDX8::s_NumVertices == 0 ); + } + } + } +} + +//----------------------------------------------------------------------------- +void CMeshMgr::SetIndexStreamState( int firstVertexIdx ) +{ + CIndexBufferDx8 *pIndexBuffer = assert_cast< CIndexBufferDx8* >( m_pCurrentIndexBuffer ); + IDirect3DIndexBuffer9 *pDx9Buffer = pIndexBuffer ? pIndexBuffer->GetDx9Buffer() : NULL; + if ( g_pLastIndex || g_pLastIndexBuffer != pDx9Buffer ) + { + Dx9Device()->SetIndices( pDx9Buffer ); + pIndexBuffer->HandlePerFrameTextureStats( ShaderAPI()->GetCurrentFrameCounter() ); + + g_pLastIndexBuffer = pDx9Buffer; + SafeRelease( &g_pLastIndex ); + g_LastVertexIdx = -1; + } +} + + diff --git a/materialsystem/shaderapidx9/recording.cpp b/materialsystem/shaderapidx9/recording.cpp new file mode 100644 index 0000000..4d2344a --- /dev/null +++ b/materialsystem/shaderapidx9/recording.cpp @@ -0,0 +1,157 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +// +//=============================================================================// + +#include "togl/rendermechanism.h" +#include "recording.h" +#include "shaderapi/ishaderutil.h" +#include "materialsystem/imaterialsystem.h" +#include "shaderapidx8_global.h" +#include "utlvector.h" +#include + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +#ifdef RECORDING + +//----------------------------------------------------------------------------- +// Globals +//----------------------------------------------------------------------------- + +static CUtlVector g_pRecordingBuffer; +static int g_ArgsRemaining = 0; +static int g_CommandStartIdx = 0; + +//----------------------------------------------------------------------------- +// Opens the recording file +//----------------------------------------------------------------------------- + +static FILE* OpenRecordingFile() +{ +#ifdef CRASH_RECORDING + static FILE *fp = 0; +#else + FILE* fp = 0; +#endif + static bool g_CantOpenFile = false; + static bool g_NeverOpened = true; + if (!g_CantOpenFile) + { +#ifdef CRASH_RECORDING + if( g_NeverOpened ) + { + fp = fopen( "shaderdx8.rec", "wbc" ); + } +#else + fp = fopen( "shaderdx8.rec", g_NeverOpened ? "wb" : "ab" ); +#endif + if (!fp) + { + Warning("Unable to open recording file shaderdx8.rec!\n"); + g_CantOpenFile = true; + } + g_NeverOpened = false; + } + return fp; +} + +//----------------------------------------------------------------------------- +// Writes to the recording file +//----------------------------------------------------------------------------- + +#define COMMAND_BUFFER_SIZE 32768 + +static void WriteRecordingFile() +{ + // Store the command size + *(int*)&g_pRecordingBuffer[g_CommandStartIdx] = + g_pRecordingBuffer.Size() - g_CommandStartIdx; + +#ifndef CRASH_RECORDING + // When not crash recording, flush when buffer gets too big, + // or when Present() is called + if ((g_pRecordingBuffer.Size() < COMMAND_BUFFER_SIZE) && + (g_pRecordingBuffer[g_CommandStartIdx+4] != DX8_PRESENT)) + return; +#endif + + FILE* fp = OpenRecordingFile(); + if (fp) + { + // store the command size + fwrite( g_pRecordingBuffer.Base(), 1, g_pRecordingBuffer.Size(), fp ); + fflush( fp ); +#ifndef CRASH_RECORDING + fclose( fp ); +#endif + } + + g_pRecordingBuffer.RemoveAll(); +} + +// Write the buffered crap out on shutdown. +void FinishRecording() +{ +#ifndef CRASH_RECORDING + FILE* fp = OpenRecordingFile(); + if (fp) + { + // store the command size + fwrite( g_pRecordingBuffer.Base(), 1, g_pRecordingBuffer.Size(), fp ); + fflush( fp ); + } + + g_pRecordingBuffer.RemoveAll(); +#endif +} + +// set this to true in the debugger to actually record commands. +static bool g_bDoRecord = true; + +//----------------------------------------------------------------------------- +// Records a command +//----------------------------------------------------------------------------- + +void RecordCommand( RecordingCommands_t cmd, int numargs ) +{ + if( !g_bDoRecord ) + { + return; + } + Assert( g_ArgsRemaining == 0 ); + + g_CommandStartIdx = g_pRecordingBuffer.AddMultipleToTail( 6 ); + + // save space for the total command size + g_pRecordingBuffer[g_CommandStartIdx+4] = cmd; + g_pRecordingBuffer[g_CommandStartIdx+5] = numargs; + g_ArgsRemaining = numargs; + if (g_ArgsRemaining == 0) + WriteRecordingFile(); +} + +//----------------------------------------------------------------------------- +// Records an argument for a command, flushes when the command is done +//----------------------------------------------------------------------------- + +void RecordArgument( void const* pMemory, int size ) +{ + if( !g_bDoRecord ) + { + return; + } + Assert( g_ArgsRemaining > 0 ); + int tail = g_pRecordingBuffer.Size(); + g_pRecordingBuffer.AddMultipleToTail( size ); + memcpy( &g_pRecordingBuffer[tail], pMemory, size ); + if (--g_ArgsRemaining == 0) + WriteRecordingFile(); +} + + +#endif // RECORDING diff --git a/materialsystem/shaderapidx9/recording.h b/materialsystem/shaderapidx9/recording.h new file mode 100644 index 0000000..81c50fc --- /dev/null +++ b/materialsystem/shaderapidx9/recording.h @@ -0,0 +1,198 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +// +//=============================================================================// + +#ifndef RECORDING_H +#define RECORDING_H +#pragma once + +//----------------------------------------------------------------------------- +// Use this to put us into a 'recording' mode +//----------------------------------------------------------------------------- + +//#define RECORDING + +//----------------------------------------------------------------------------- +// Uncomment these to record special frames in the recording +// that reset the entire render state. +//----------------------------------------------------------------------------- + +//#define RECORD_KEYFRAMES 1 +#define KEYFRAME_INTERVAL 100 // number of actual frames between each keyframe + +//----------------------------------------------------------------------------- +// Use this to allow us to record crashes (write every command immediately) +//----------------------------------------------------------------------------- + +//#define CRASH_RECORDING + +//----------------------------------------------------------------------------- +// Use this to record textures (checkboards are used for textures otherwise) +//----------------------------------------------------------------------------- + +#define RECORD_TEXTURES + +//----------------------------------------------------------------------------- +// Use this to record debug strings . .these are only useful if you are doing "playback -list" +//----------------------------------------------------------------------------- + +#define RECORD_DEBUG_STRINGS + +//----------------------------------------------------------------------------- +// Recording state, if you change this, change the table in playback/playback.cpp +//----------------------------------------------------------------------------- + +enum RecordingCommands_t +{ + DX8_CREATE_DEVICE = 0, + DX8_DESTROY_DEVICE, + DX8_RESET, + DX8_SHOW_CURSOR, + DX8_BEGIN_SCENE, + DX8_END_SCENE, + DX8_PRESENT, + DX8_CREATE_TEXTURE, + DX8_DESTROY_TEXTURE, + DX8_SET_TEXTURE, + DX8_SET_TRANSFORM, + DX8_CREATE_VERTEX_SHADER, + DX8_CREATE_PIXEL_SHADER, + DX8_DESTROY_VERTEX_SHADER, + DX8_DESTROY_PIXEL_SHADER, + DX8_SET_VERTEX_SHADER, + DX8_SET_PIXEL_SHADER, + DX8_SET_VERTEX_SHADER_CONSTANT, + DX8_SET_PIXEL_SHADER_CONSTANT, + DX8_SET_MATERIAL, + DX8_LIGHT_ENABLE, + DX8_SET_LIGHT, + DX8_SET_VIEWPORT, + DX8_CLEAR, + DX8_VALIDATE_DEVICE, + DX8_SET_RENDER_STATE, + DX8_SET_TEXTURE_STAGE_STATE, + + DX8_CREATE_VERTEX_BUFFER, + DX8_DESTROY_VERTEX_BUFFER, + DX8_LOCK_VERTEX_BUFFER, + DX8_VERTEX_DATA, + DX8_UNLOCK_VERTEX_BUFFER, + + DX8_CREATE_INDEX_BUFFER, + DX8_DESTROY_INDEX_BUFFER, + DX8_LOCK_INDEX_BUFFER, + DX8_INDEX_DATA, + DX8_UNLOCK_INDEX_BUFFER, + + DX8_SET_STREAM_SOURCE, + DX8_SET_INDICES, + DX8_DRAW_PRIMITIVE, + DX8_DRAW_INDEXED_PRIMITIVE, + + DX8_LOCK_TEXTURE, + DX8_UNLOCK_TEXTURE, + + DX8_KEYFRAME, // isn't actually a dx8 command, used to help find particular frames + + DX8_SET_TEXTURE_DATA, + DX8_BLIT_TEXTURE_BITS, + + DX8_GET_DEVICE_CAPS, + DX8_GET_ADAPTER_IDENTIFIER, + + DX8_HARDWARE_SYNC, + + DX8_COPY_FRAMEBUFFER_TO_TEXTURE, + DX8_DEBUG_STRING, + DX8_CREATE_DEPTH_TEXTURE, + DX8_DESTROY_DEPTH_TEXTURE, + DX8_SET_RENDER_TARGET, + + DX8_TEST_COOPERATIVE_LEVEL, + + DX8_SET_VERTEX_BUFFER_FORMAT, // isn't actually a dx8 command. . let's playback know what format a buffer is for listing info + + DX8_SET_SAMPLER_STATE, + DX8_SET_VERTEX_DECLARATION, + DX8_CREATE_VERTEX_DECLARATION, + DX8_SET_FVF, + DX8_SET_CLIP_PLANE, + + DX8_SYNC_TOKEN, + + DX8_LOCK_VERTEX_TEXTURE, + DX8_UNLOCK_VERTEX_TEXTURE, + + DX8_SET_SCISSOR_RECT, + + DX8_NUM_RECORDING_COMMANDS +}; + +#ifdef RECORDING + +void RecordCommand( RecordingCommands_t cmd, int numargs ); +void RecordArgument( void const* pMemory, int size ); +void FinishRecording( void ); + +inline void RecordInt( int i ) +{ + RecordArgument( &i, sizeof(int) ); +} + +inline void RecordFloat( float f ) +{ + RecordArgument( &f, sizeof(float) ); +} + +# define RECORD_COMMAND( _cmd, _numargs ) RecordCommand( _cmd, _numargs ) +# define RECORD_INT( _int ) RecordInt( _int ) +# define RECORD_FLOAT( _float ) RecordFloat( _float ) +# define RECORD_STRING( _string ) RecordArgument( _string, strlen(_string) + 1 ) +# define RECORD_STRUCT( _struct, _size ) RecordArgument( _struct, _size ) + +# define RECORD_RENDER_STATE( _state, _val ) \ + RECORD_COMMAND( DX8_SET_RENDER_STATE, 2 ); \ + RECORD_INT( _state ); \ + RECORD_INT( _val ) + +# define RECORD_TEXTURE_STAGE_STATE( _stage, _state, _val ) \ + RECORD_COMMAND( DX8_SET_TEXTURE_STAGE_STATE, 3 ); \ + RECORD_INT( _stage ); \ + RECORD_INT( _state ); \ + RECORD_INT( _val ) + +# define RECORD_SAMPLER_STATE( _stage, _state, _val ) \ + RECORD_COMMAND( DX8_SET_SAMPLER_STATE, 3 ); \ + RECORD_INT( _stage ); \ + RECORD_INT( _state ); \ + RECORD_INT( _val ) + +# ifdef RECORD_DEBUG_STRINGS +# define RECORD_DEBUG_STRING( _str ) \ + RECORD_COMMAND( DX8_DEBUG_STRING, 1 ); \ + RECORD_STRING( _str ) +# else +# define RECORD_DEBUG_STRING( _str ) 0 +# endif + +#else // not RECORDING + +# undef RECORD_TEXTURES + +# define RECORD_COMMAND( _cmd, _numargs ) 0 +# define RECORD_INT( _int ) 0 +# define RECORD_FLOAT( _float ) 0 +# define RECORD_STRING( _string ) 0 +# define RECORD_STRUCT( _struct, _size ) 0 +# define RECORD_RENDER_STATE( _state, _val ) 0 +# define RECORD_TEXTURE_STAGE_STATE( _stage, _state, _val ) 0 +# define RECORD_SAMPLER_STATE( _stage, _state, _val ) 0 +# define RECORD_DEBUG_STRING( _str ) 0 + +#endif // RECORDING + +#endif // RECORDING_H diff --git a/materialsystem/shaderapidx9/shaderapi_global.h b/materialsystem/shaderapidx9/shaderapi_global.h new file mode 100644 index 0000000..ae8f6ab --- /dev/null +++ b/materialsystem/shaderapidx9/shaderapi_global.h @@ -0,0 +1,105 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +// +//===========================================================================// + +#ifndef SHADERAPI_GLOBAL_H +#define SHADERAPI_GLOBAL_H + +#ifdef _WIN32 +#pragma once +#endif + +#include "tier0/threadtools.h" + +//----------------------------------------------------------------------------- +// Use this to fill in structures with the current board state +//----------------------------------------------------------------------------- +#ifdef _DEBUG +#define DEBUG_BOARD_STATE 0 +#endif + + +//----------------------------------------------------------------------------- +// Forward declarations +//----------------------------------------------------------------------------- +class IShaderUtil; +class CShaderDeviceBase; +class CShaderDeviceMgrBase; +class CShaderAPIBase; +class IShaderShadow; + + +//----------------------------------------------------------------------------- +// Global interfaces +//----------------------------------------------------------------------------- +extern IShaderUtil* g_pShaderUtil; +inline IShaderUtil* ShaderUtil() +{ + return g_pShaderUtil; +} + +extern CShaderDeviceBase *g_pShaderDevice; +extern CShaderDeviceMgrBase *g_pShaderDeviceMgr; +extern CShaderAPIBase *g_pShaderAPI; +extern IShaderShadow *g_pShaderShadow; + + +//----------------------------------------------------------------------------- +// Memory debugging +//----------------------------------------------------------------------------- +#define MEM_ALLOC_D3D_CREDIT() MEM_ALLOC_CREDIT_("D3D:" __FILE__) +#define BEGIN_D3D_ALLOCATION() MemAlloc_PushAllocDbgInfo("D3D:" __FILE__, __LINE__) +#define END_D3D_ALLOCATION() MemAlloc_PopAllocDbgInfo() + + +//----------------------------------------------------------------------------- +// Threading +//----------------------------------------------------------------------------- +extern bool g_bUseShaderMutex; + +//#define USE_SHADER_DISALLOW 1 +//#define STRICT_MT_SHADERAPI 1 + +#if defined(_DEBUG) +#if !defined(STRICT_MT_SHADERAPI) +#define UNCONDITIONAL_MT_SHADERAPI 1 +#endif +#else +#if !defined(STRICT_MT_SHADERAPI) && !defined(UNCONDITIONAL_MT_SHADERAPI) +#define ST_SHADERAPI 1 +#endif +#endif + + +#if defined(ST_SHADERAPI) +typedef CThreadNullMutex CShaderMutex; +#elif defined(STRICT_MT_SHADERAPI) +typedef CThreadConditionalMutex, &g_bUseShaderMutex> CShaderMutex; +#elif defined(UNCONDITIONAL_MT_SHADERAPI) +typedef CThreadFastMutex CShaderMutex; +#else +typedef CThreadConditionalMutex CShaderMutex; +#endif + +extern CShaderMutex g_ShaderMutex; + +extern bool g_bShaderAccessDisallowed; + +#ifdef USE_SHADER_DISALLOW +#define TestShaderPermission() do { if ( (!g_bUseShaderMutex || g_ShaderMutex.GetDepth() == 0) && g_bShaderAccessDisallowed ) { ExecuteOnce( DebuggerBreakIfDebugging() ); } } while (0) +#define LOCK_SHADERAPI() TestShaderPermission(); AUTO_LOCK_( CShaderMutex, g_ShaderMutex ) +#define LockShaderMutex() TestShaderPermission(); g_ShaderMutex.Lock(); +#define UnlockShaderMutex() TestShaderPermission(); g_ShaderMutex.Unlock(); +#else +#define TestShaderPermission() ((void)0) +#define LOCK_SHADERAPI() ((void)0) +#define LockShaderMutex() ((void)0) +#define UnlockShaderMutex() ((void)0) +#endif + + +#endif // SHADERAPI_GLOBAL_H diff --git a/materialsystem/shaderapidx9/shaderapibase.cpp b/materialsystem/shaderapidx9/shaderapibase.cpp new file mode 100644 index 0000000..1563a12 --- /dev/null +++ b/materialsystem/shaderapidx9/shaderapibase.cpp @@ -0,0 +1,42 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +// +//===========================================================================// + +#undef PROTECTED_THINGS_ENABLE // prevent warnings when windows.h gets included + +#include "shaderapibase.h" +#include "shaderapi/ishaderutil.h" + + +//----------------------------------------------------------------------------- +// +// The Base implementation of the shader render class +// +//----------------------------------------------------------------------------- + + +//----------------------------------------------------------------------------- +// constructor, destructor +//----------------------------------------------------------------------------- +CShaderAPIBase::CShaderAPIBase() +{ +} + +CShaderAPIBase::~CShaderAPIBase() +{ +} + + +//----------------------------------------------------------------------------- +// Methods of IShaderDynamicAPI +//----------------------------------------------------------------------------- +void CShaderAPIBase::GetCurrentColorCorrection( ShaderColorCorrectionInfo_t* pInfo ) +{ + g_pShaderUtil->GetCurrentColorCorrection( pInfo ); +} + + diff --git a/materialsystem/shaderapidx9/shaderapibase.h b/materialsystem/shaderapidx9/shaderapibase.h new file mode 100644 index 0000000..fe8d928 --- /dev/null +++ b/materialsystem/shaderapidx9/shaderapibase.h @@ -0,0 +1,86 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +// +//===========================================================================// + +#ifndef SHADERRENDERBASE_H +#define SHADERRENDERBASE_H + +#ifdef _WIN32 +#pragma once +#endif + + +#include "togl/rendermechanism.h" +#include "shaderapi/ishaderapi.h" +#include "shaderapi_global.h" +#include "locald3dtypes.h" + +// Colors for PIX graphs +#define PIX_VALVE_ORANGE 0xFFF5940F + + +//----------------------------------------------------------------------------- +// The Base implementation of the shader rendering interface +//----------------------------------------------------------------------------- +class CShaderAPIBase : public IShaderAPI +{ +public: + // constructor, destructor + CShaderAPIBase(); + virtual ~CShaderAPIBase(); + + // Called when the device is initializing or shutting down + virtual bool OnDeviceInit() = 0; + virtual void OnDeviceShutdown() = 0; + + // Pix events + virtual void BeginPIXEvent( unsigned long color, const char *szName ) = 0; + virtual void EndPIXEvent() = 0; + virtual void AdvancePIXFrame() = 0; + + // Release, reacquire objects + virtual void ReleaseShaderObjects() = 0; + virtual void RestoreShaderObjects() = 0; + + // Resets the render state to its well defined initial value + virtual void ResetRenderState( bool bFullReset = true ) = 0; + + // Returns a d3d texture associated with a texture handle + virtual IDirect3DBaseTexture* GetD3DTexture( ShaderAPITextureHandle_t hTexture ) = 0; + + // Queues a non-full reset of render state next BeginFrame. + virtual void QueueResetRenderState() = 0; + + // Methods of IShaderDynamicAPI +public: + virtual void GetCurrentColorCorrection( ShaderColorCorrectionInfo_t* pInfo ); + +protected: +}; + + +//----------------------------------------------------------------------------- +// Pix measurement class +//----------------------------------------------------------------------------- +class CPixEvent +{ +public: + CPixEvent( unsigned long color, const char *szName ) + { + if ( g_pShaderAPI ) + g_pShaderAPI->BeginPIXEvent( color, szName ); + } + + ~CPixEvent() + { + if ( g_pShaderAPI ) + g_pShaderAPI->EndPIXEvent(); + } +}; + + +#endif // SHADERRENDERBASE_H diff --git a/materialsystem/shaderapidx9/shaderapidx10.cpp b/materialsystem/shaderapidx9/shaderapidx10.cpp new file mode 100644 index 0000000..9bd1039 --- /dev/null +++ b/materialsystem/shaderapidx9/shaderapidx10.cpp @@ -0,0 +1,1461 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +// +//===========================================================================// + +#include "shaderapidx10.h" +#include "shaderapibase.h" +#include "shaderapi/ishaderutil.h" +#include "materialsystem/idebugtextureinfo.h" +#include "materialsystem/materialsystem_config.h" +#include "meshdx10.h" +#include "shadershadowdx10.h" +#include "shaderdevicedx10.h" +#include "shaderapidx10_global.h" +#include "imaterialinternal.h" + + +//----------------------------------------------------------------------------- +// Methods related to queuing functions to be called prior to rendering +//----------------------------------------------------------------------------- +CFunctionCommit::CFunctionCommit() +{ + m_pCommitFlags = NULL; + m_nCommitBufferSize = 0; +} + +CFunctionCommit::~CFunctionCommit() +{ + if ( m_pCommitFlags ) + { + delete[] m_pCommitFlags; + m_pCommitFlags = NULL; + } +} + +void CFunctionCommit::Init( int nFunctionCount ) +{ + m_nCommitBufferSize = ( nFunctionCount + 7 ) >> 3; + Assert( !m_pCommitFlags ); + m_pCommitFlags = new unsigned char[ m_nCommitBufferSize ]; + memset( m_pCommitFlags, 0, m_nCommitBufferSize ); +} + + +//----------------------------------------------------------------------------- +// Methods related to queuing functions to be called per-(pMesh->Draw call) or per-pass +//----------------------------------------------------------------------------- +inline bool CFunctionCommit::IsCommitFuncInUse( int nFunc ) const +{ + Assert( nFunc >> 3 < m_nCommitBufferSize ); + return ( m_pCommitFlags[ nFunc >> 3 ] & ( 1 << ( nFunc & 0x7 ) ) ) != 0; +} + +inline void CFunctionCommit::MarkCommitFuncInUse( int nFunc ) +{ + Assert( nFunc >> 3 < m_nCommitBufferSize ); + m_pCommitFlags[ nFunc >> 3 ] |= 1 << ( nFunc & 0x7 ); +} + +inline void CFunctionCommit::AddCommitFunc( StateCommitFunc_t f ) +{ + m_CommitFuncs.AddToTail( f ); +} + + +//----------------------------------------------------------------------------- +// Clears all commit functions +//----------------------------------------------------------------------------- +inline void CFunctionCommit::ClearAllCommitFuncs( ) +{ + memset( m_pCommitFlags, 0, m_nCommitBufferSize ); + m_CommitFuncs.RemoveAll(); +} + + +//----------------------------------------------------------------------------- +// Calls all commit functions in a particular list +//----------------------------------------------------------------------------- +void CFunctionCommit::CallCommitFuncs( ID3D10Device *pDevice, const ShaderStateDx10_t &desiredState, ShaderStateDx10_t ¤tState, bool bForce ) +{ + int nCount = m_CommitFuncs.Count(); + for ( int i = 0; i < nCount; ++i ) + { + m_CommitFuncs[i]( pDevice, desiredState, currentState, bForce ); + } + + ClearAllCommitFuncs( ); +} + + +//----------------------------------------------------------------------------- +// Helpers for commit functions +//----------------------------------------------------------------------------- +#define ADD_COMMIT_FUNC( _func_name ) \ + if ( !m_Commit.IsCommitFuncInUse( COMMIT_FUNC_ ## _func_name ) ) \ + { \ + m_Commit.AddCommitFunc( _func_name ); \ + m_Commit.MarkCommitFuncInUse( COMMIT_FUNC_ ## _func_name ); \ + } + +#define ADD_RENDERSTATE_FUNC( _func_name, _state, _val ) \ + if ( m_bResettingRenderState || ( m_DesiredState. ## _state != _val ) ) \ + { \ + m_DesiredState. ## _state = _val; \ + ADD_COMMIT_FUNC( _func_name ) \ + } + +#define IMPLEMENT_RENDERSTATE_FUNC( _func_name, _state, _d3dFunc ) \ + static void _func_name( ID3D10Device *pDevice, const ShaderStateDx10_t &desiredState, ShaderStateDx10_t ¤tState, bool bForce ) \ + { \ + if ( bForce || ( desiredState. ## _state != currentState. ## _state ) ) \ + { \ + pDevice->_d3dFunc( desiredState. ## _state ); \ + currentState. ## _state = desiredState. ## _state; \ + } \ + } + +//----------------------------------------------------------------------------- +// D3D state setting methods +//----------------------------------------------------------------------------- + +// NOTE: For each commit func you create, add to this enumeration. +enum CommitFunc_t +{ + COMMIT_FUNC_CommitSetViewports = 0, + COMMIT_FUNC_CommitSetVertexShader, + COMMIT_FUNC_CommitSetGeometryShader, + COMMIT_FUNC_CommitSetPixelShader, + COMMIT_FUNC_CommitSetVertexBuffer, + COMMIT_FUNC_CommitSetIndexBuffer, + COMMIT_FUNC_CommitSetInputLayout, + COMMIT_FUNC_CommitSetTopology, + COMMIT_FUNC_CommitSetRasterState, + + COMMIT_FUNC_COUNT, +}; + +IMPLEMENT_RENDERSTATE_FUNC( CommitSetTopology, m_Topology, IASetPrimitiveTopology ) +IMPLEMENT_RENDERSTATE_FUNC( CommitSetVertexShader, m_pVertexShader, VSSetShader ) +IMPLEMENT_RENDERSTATE_FUNC( CommitSetGeometryShader, m_pGeometryShader, GSSetShader ) +IMPLEMENT_RENDERSTATE_FUNC( CommitSetPixelShader, m_pPixelShader, PSSetShader ) + +static void CommitSetInputLayout( ID3D10Device *pDevice, const ShaderStateDx10_t &desiredState, ShaderStateDx10_t ¤tState, bool bForce ) +{ + const ShaderInputLayoutStateDx10_t& newState = desiredState.m_InputLayout; + if ( bForce || memcmp( &newState, ¤tState.m_InputLayout, sizeof(ShaderInputLayoutStateDx10_t) ) ) + { + // FIXME: Deal with multiple streams + ID3D10InputLayout *pInputLayout = g_pShaderDeviceDx10->GetInputLayout( + newState.m_hVertexShader, newState.m_pVertexDecl[0] ); + pDevice->IASetInputLayout( pInputLayout ); + + currentState.m_InputLayout = newState; + } +} + +static void CommitSetViewports( ID3D10Device *pDevice, const ShaderStateDx10_t &desiredState, ShaderStateDx10_t ¤tState, bool bForce ) +{ + bool bChanged = bForce || ( desiredState.m_nViewportCount != currentState.m_nViewportCount ); + if ( !bChanged && desiredState.m_nViewportCount > 0 ) + { + bChanged = memcmp( desiredState.m_pViewports, currentState.m_pViewports, + desiredState.m_nViewportCount * sizeof( D3D10_VIEWPORT ) ) != 0; + } + + if ( !bChanged ) + return; + + pDevice->RSSetViewports( desiredState.m_nViewportCount, desiredState.m_pViewports ); + currentState.m_nViewportCount = desiredState.m_nViewportCount; + +#ifdef _DEBUG + memset( currentState.m_pViewports, 0xDD, sizeof( currentState.m_pViewports ) ); +#endif + + memcpy( currentState.m_pViewports, desiredState.m_pViewports, + desiredState.m_nViewportCount * sizeof( D3D10_VIEWPORT ) ); +} + +static void CommitSetIndexBuffer( ID3D10Device *pDevice, const ShaderStateDx10_t &desiredState, ShaderStateDx10_t ¤tState, bool bForce ) +{ + const ShaderIndexBufferStateDx10_t &newState = desiredState.m_IndexBuffer; + bool bChanged = bForce || memcmp( &newState, ¤tState.m_IndexBuffer, sizeof(ShaderIndexBufferStateDx10_t) ); + if ( !bChanged ) + return; + + pDevice->IASetIndexBuffer( newState.m_pBuffer, newState.m_Format, newState.m_nOffset ); + memcpy( ¤tState.m_IndexBuffer, &newState, sizeof( ShaderIndexBufferStateDx10_t ) ); +} + +static void CommitSetVertexBuffer( ID3D10Device *pDevice, const ShaderStateDx10_t &desiredState, ShaderStateDx10_t ¤tState, bool bForce ) +{ + ID3D10Buffer *ppVertexBuffers[ MAX_DX10_STREAMS ]; + UINT pStrides[ MAX_DX10_STREAMS ]; + UINT pOffsets[ MAX_DX10_STREAMS ]; + + UINT nFirstBuffer = 0; + UINT nBufferCount = 0; + bool bInMatch = true; + for ( int i = 0; i < MAX_DX10_STREAMS; ++i ) + { + const ShaderVertexBufferStateDx10_t &newState = desiredState.m_pVertexBuffer[i]; + bool bMatch = !bForce && !memcmp( &newState, ¤tState.m_pVertexBuffer[i], sizeof(ShaderVertexBufferStateDx10_t) ); + if ( !bMatch ) + { + ppVertexBuffers[i] = newState.m_pBuffer; + pStrides[i] = newState.m_nStride; + pOffsets[i] = newState.m_nOffset; + ++nBufferCount; + memcpy( ¤tState.m_pVertexBuffer[i], &newState, sizeof( ShaderVertexBufferStateDx10_t ) ); + } + + if ( bInMatch ) + { + if ( !bMatch ) + { + bInMatch = false; + nFirstBuffer = i; + } + continue; + } + + if ( bMatch ) + { + bInMatch = true; + pDevice->IASetVertexBuffers( nFirstBuffer, nBufferCount, + &ppVertexBuffers[nFirstBuffer], &pStrides[nFirstBuffer], &pOffsets[nFirstBuffer] ); + nBufferCount = 0; + } + } + + if ( !bInMatch ) + { + pDevice->IASetVertexBuffers( nFirstBuffer, nBufferCount, + &ppVertexBuffers[nFirstBuffer], &pStrides[nFirstBuffer], &pOffsets[nFirstBuffer] ); + } +} + +static void GenerateRasterizerDesc( D3D10_RASTERIZER_DESC* pDesc, const ShaderRasterState_t& state ) +{ + pDesc->FillMode = ( state.m_FillMode == SHADER_FILL_WIREFRAME ) ? D3D10_FILL_WIREFRAME : D3D10_FILL_SOLID; + + // Cull state + if ( state.m_bCullEnable ) + { + pDesc->CullMode = D3D10_CULL_NONE; + } + else + { + pDesc->CullMode = ( state.m_CullMode == MATERIAL_CULLMODE_CW ) ? D3D10_CULL_BACK : D3D10_CULL_FRONT; + } + pDesc->FrontCounterClockwise = TRUE; + + // Depth bias state + if ( !state.m_bDepthBias ) + { + pDesc->DepthBias = 0; + pDesc->DepthBiasClamp = 0.0f; + pDesc->SlopeScaledDepthBias = 0.0f; + pDesc->DepthClipEnable = FALSE; + } + else + { + // FIXME: Implement! Read ConVars + } + + pDesc->ScissorEnable = state.m_bScissorEnable ? TRUE : FALSE; + pDesc->MultisampleEnable = state.m_bMultisampleEnable ? TRUE : FALSE; + pDesc->AntialiasedLineEnable = FALSE; +} + +static void CommitSetRasterState( ID3D10Device *pDevice, const ShaderStateDx10_t &desiredState, ShaderStateDx10_t ¤tState, bool bForce ) +{ + const ShaderRasterState_t& newState = desiredState.m_RasterState; + if ( bForce || memcmp( &newState, ¤tState.m_RasterState, sizeof(ShaderRasterState_t) ) ) + { + // Clear out the existing state + if ( currentState.m_pRasterState ) + { + currentState.m_pRasterState->Release(); + } + + D3D10_RASTERIZER_DESC desc; + GenerateRasterizerDesc( &desc, newState ); + + // NOTE: This does a search for existing matching state objects + ID3D10RasterizerState *pState = NULL; + HRESULT hr = pDevice->CreateRasterizerState( &desc, &pState ); + if ( !FAILED(hr) ) + { + Warning( "Unable to create rasterizer state object!\n" ); + } + + pDevice->RSSetState( pState ); + + currentState.m_pRasterState = pState; + memcpy( ¤tState.m_RasterState, &newState, sizeof( ShaderRasterState_t ) ); + } +} + + +//----------------------------------------------------------------------------- +// +// Shader API Dx10 +// +//----------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +// Class Factory +//----------------------------------------------------------------------------- +static CShaderAPIDx10 s_ShaderAPIDx10; +CShaderAPIDx10* g_pShaderAPIDx10 = &s_ShaderAPIDx10; + +EXPOSE_SINGLE_INTERFACE_GLOBALVAR( CShaderAPIDx10, IShaderAPI, + SHADERAPI_INTERFACE_VERSION, s_ShaderAPIDx10 ) + +EXPOSE_SINGLE_INTERFACE_GLOBALVAR( CShaderAPIDx10, IDebugTextureInfo, + DEBUG_TEXTURE_INFO_VERSION, s_ShaderAPIDx10 ) + + +//----------------------------------------------------------------------------- +// Constructor, destructor +//----------------------------------------------------------------------------- +CShaderAPIDx10::CShaderAPIDx10() +{ + m_bResettingRenderState = false; + m_Commit.Init( COMMIT_FUNC_COUNT ); + ClearShaderState( &m_DesiredState ); + ClearShaderState( &m_CurrentState ); +} + +CShaderAPIDx10::~CShaderAPIDx10() +{ +} + + +//----------------------------------------------------------------------------- +// Clears the shader state to a well-defined value +//----------------------------------------------------------------------------- +void CShaderAPIDx10::ClearShaderState( ShaderStateDx10_t* pState ) +{ + memset( pState, 0, sizeof( ShaderStateDx10_t ) ); +} + + +//----------------------------------------------------------------------------- +// Resets the render state +//----------------------------------------------------------------------------- +void CShaderAPIDx10::ResetRenderState( bool bFullReset ) +{ + D3D10_RASTERIZER_DESC rDesc; + memset( &rDesc, 0, sizeof(rDesc) ); + rDesc.FillMode = D3D10_FILL_SOLID; + rDesc.CullMode = D3D10_CULL_NONE; + rDesc.FrontCounterClockwise = TRUE; // right-hand rule + + ID3D10RasterizerState *pRasterizerState; + HRESULT hr = D3D10Device()->CreateRasterizerState( &rDesc, &pRasterizerState ); + Assert( !FAILED(hr) ); + D3D10Device()->RSSetState( pRasterizerState ); + + D3D10_DEPTH_STENCIL_DESC dsDesc; + memset( &dsDesc, 0, sizeof(dsDesc) ); + + ID3D10DepthStencilState *pDepthStencilState; + hr = D3D10Device()->CreateDepthStencilState( &dsDesc, &pDepthStencilState ); + Assert( !FAILED(hr) ); + D3D10Device()->OMSetDepthStencilState( pDepthStencilState, 0 ); + + D3D10_BLEND_DESC bDesc; + memset( &bDesc, 0, sizeof(bDesc) ); + bDesc.SrcBlend = D3D10_BLEND_ONE; + bDesc.DestBlend = D3D10_BLEND_ZERO; + bDesc.BlendOp = D3D10_BLEND_OP_ADD; + bDesc.SrcBlendAlpha = D3D10_BLEND_ONE; + bDesc.DestBlendAlpha = D3D10_BLEND_ZERO; + bDesc.BlendOpAlpha = D3D10_BLEND_OP_ADD; + bDesc.RenderTargetWriteMask[0] = D3D10_COLOR_WRITE_ENABLE_ALL; + + FLOAT pBlendFactor[4] = { 1.0f, 1.0f, 1.0f, 1.0f }; + ID3D10BlendState *pBlendState; + hr = D3D10Device()->CreateBlendState( &bDesc, &pBlendState ); + Assert( !FAILED(hr) ); + D3D10Device()->OMSetBlendState( pBlendState, pBlendFactor, 0xFFFFFFFF ); +} + + +//----------------------------------------------------------------------------- +// Commits queued-up state change requests +//----------------------------------------------------------------------------- +void CShaderAPIDx10::CommitStateChanges( bool bForce ) +{ + // Don't bother committing anything if we're deactivated + if ( g_pShaderDevice->IsDeactivated() ) + return; + + m_Commit.CallCommitFuncs( D3D10Device(), m_DesiredState, m_CurrentState, bForce ); +} + + +//----------------------------------------------------------------------------- +// Methods of IShaderDynamicAPI +//----------------------------------------------------------------------------- +void CShaderAPIDx10::GetBackBufferDimensions( int& nWidth, int& nHeight ) const +{ + g_pShaderDeviceDx10->GetBackBufferDimensions( nWidth, nHeight ); +} + + +//----------------------------------------------------------------------------- +// Viewport-related methods +//----------------------------------------------------------------------------- +void CShaderAPIDx10::SetViewports( int nCount, const ShaderViewport_t* pViewports ) +{ + nCount = min( nCount, MAX_DX10_VIEWPORTS ); + m_DesiredState.m_nViewportCount = nCount; + + for ( int i = 0; i < nCount; ++i ) + { + Assert( pViewports[i].m_nVersion == SHADER_VIEWPORT_VERSION ); + + D3D10_VIEWPORT& viewport = m_DesiredState.m_pViewports[i]; + viewport.TopLeftX = pViewports[i].m_nTopLeftX; + viewport.TopLeftY = pViewports[i].m_nTopLeftY; + viewport.Width = pViewports[i].m_nWidth; + viewport.Height = pViewports[i].m_nHeight; + viewport.MinDepth = pViewports[i].m_flMinZ; + viewport.MaxDepth = pViewports[i].m_flMaxZ; + } + + ADD_COMMIT_FUNC( CommitSetViewports ); +} + +int CShaderAPIDx10::GetViewports( ShaderViewport_t* pViewports, int nMax ) const +{ + int nCount = m_DesiredState.m_nViewportCount; + if ( pViewports && nMax ) + { + nCount = min( nCount, nMax ); + memcpy( pViewports, m_DesiredState.m_pViewports, nCount * sizeof( ShaderViewport_t ) ); + } + return nCount; +} + + +//----------------------------------------------------------------------------- +// Methods related to state objects +//----------------------------------------------------------------------------- +void CShaderAPIDx10::SetRasterState( const ShaderRasterState_t& state ) +{ + if ( memcmp( &state, &m_DesiredState.m_RasterState, sizeof(ShaderRasterState_t) ) ) + { + memcpy( &m_DesiredState.m_RasterState, &state, sizeof(ShaderRasterState_t) ); + ADD_COMMIT_FUNC( CommitSetRasterState ); + } +} + + +//----------------------------------------------------------------------------- +// Methods related to clearing buffers +//----------------------------------------------------------------------------- +void CShaderAPIDx10::ClearColor3ub( unsigned char r, unsigned char g, unsigned char b ) +{ + m_DesiredState.m_ClearColor[0] = r / 255.0f; + m_DesiredState.m_ClearColor[1] = g / 255.0f; + m_DesiredState.m_ClearColor[2] = b / 255.0f; + m_DesiredState.m_ClearColor[3] = 1.0f; +} + +void CShaderAPIDx10::ClearColor4ub( unsigned char r, unsigned char g, unsigned char b, unsigned char a ) +{ + m_DesiredState.m_ClearColor[0] = r / 255.0f; + m_DesiredState.m_ClearColor[1] = g / 255.0f; + m_DesiredState.m_ClearColor[2] = b / 255.0f; + m_DesiredState.m_ClearColor[3] = a / 255.0f; +} + +void CShaderAPIDx10::ClearBuffers( bool bClearColor, bool bClearDepth, bool bClearStencil, int renderTargetWidth, int renderTargetHeight ) +{ + // NOTE: State change commit isn't necessary since clearing doesn't use state +// CommitStateChanges(); + + // FIXME: This implementation is totally bust0red [doesn't guarantee exact color specified] + if ( bClearColor ) + { + D3D10Device()->ClearRenderTargetView( D3D10RenderTargetView(), m_DesiredState.m_ClearColor ); + } +} + + +//----------------------------------------------------------------------------- +// Methods related to binding shaders +//----------------------------------------------------------------------------- +void CShaderAPIDx10::BindVertexShader( VertexShaderHandle_t hVertexShader ) +{ + ID3D10VertexShader *pVertexShader = g_pShaderDeviceDx10->GetVertexShader( hVertexShader ); + ADD_RENDERSTATE_FUNC( CommitSetVertexShader, m_pVertexShader, pVertexShader ); + + if ( m_bResettingRenderState || ( m_DesiredState.m_InputLayout.m_hVertexShader != hVertexShader ) ) + { + m_DesiredState.m_InputLayout.m_hVertexShader = hVertexShader; + ADD_COMMIT_FUNC( CommitSetInputLayout ); + } +} + +void CShaderAPIDx10::BindGeometryShader( GeometryShaderHandle_t hGeometryShader ) +{ + ID3D10GeometryShader *pGeometryShader = g_pShaderDeviceDx10->GetGeometryShader( hGeometryShader ); + ADD_RENDERSTATE_FUNC( CommitSetGeometryShader, m_pGeometryShader, pGeometryShader ); +} + +void CShaderAPIDx10::BindPixelShader( PixelShaderHandle_t hPixelShader ) +{ + ID3D10PixelShader *pPixelShader = g_pShaderDeviceDx10->GetPixelShader( hPixelShader ); + ADD_RENDERSTATE_FUNC( CommitSetPixelShader, m_pPixelShader, pPixelShader ); +} + +void CShaderAPIDx10::BindVertexBuffer( int nStreamID, IVertexBuffer *pVertexBuffer, int nOffsetInBytes, int nFirstVertex, int nVertexCount, VertexFormat_t fmt, int nRepetitions ) +{ + // FIXME: What to do about repetitions? + CVertexBufferDx10 *pVertexBufferDx10 = static_cast( pVertexBuffer ); + + ShaderVertexBufferStateDx10_t state; + if ( pVertexBufferDx10 ) + { + state.m_pBuffer = pVertexBufferDx10->GetDx10Buffer(); + state.m_nStride = pVertexBufferDx10->VertexSize(); + } + else + { + state.m_pBuffer = NULL; + state.m_nStride = 0; + } + state.m_nOffset = nOffsetInBytes; + + if ( m_bResettingRenderState || memcmp( &m_DesiredState.m_pVertexBuffer[ nStreamID ], &state, sizeof( ShaderVertexBufferStateDx10_t ) ) ) + { + m_DesiredState.m_pVertexBuffer[ nStreamID ] = state; + ADD_COMMIT_FUNC( CommitSetVertexBuffer ); + } + + if ( m_bResettingRenderState || ( m_DesiredState.m_InputLayout.m_pVertexDecl[ nStreamID ] != fmt ) ) + { + m_DesiredState.m_InputLayout.m_pVertexDecl[ nStreamID ] = fmt; + ADD_COMMIT_FUNC( CommitSetInputLayout ); + } +} + +void CShaderAPIDx10::BindIndexBuffer( IIndexBuffer *pIndexBuffer, int nOffsetInBytes ) +{ + CIndexBufferDx10 *pIndexBufferDx10 = static_cast( pIndexBuffer ); + + ShaderIndexBufferStateDx10_t state; + if ( pIndexBufferDx10 ) + { + state.m_pBuffer = pIndexBufferDx10->GetDx10Buffer(); + state.m_Format = ( pIndexBufferDx10->GetIndexFormat() == MATERIAL_INDEX_FORMAT_16BIT ) ? + DXGI_FORMAT_R16_UINT : DXGI_FORMAT_R32_UINT; + } + else + { + state.m_pBuffer = NULL; + state.m_Format = DXGI_FORMAT_R16_UINT; + } + state.m_nOffset = nOffsetInBytes; + + ADD_RENDERSTATE_FUNC( CommitSetIndexBuffer, m_IndexBuffer, state ); +} + + +//----------------------------------------------------------------------------- +// Unbinds resources because they are about to be deleted +//----------------------------------------------------------------------------- +void CShaderAPIDx10::Unbind( VertexShaderHandle_t hShader ) +{ + ID3D10VertexShader* pShader = g_pShaderDeviceDx10->GetVertexShader( hShader ); + Assert ( pShader ); + if ( m_DesiredState.m_pVertexShader == pShader ) + { + BindVertexShader( VERTEX_SHADER_HANDLE_INVALID ); + } + if ( m_CurrentState.m_pVertexShader == pShader ) + { + CommitStateChanges(); + } +} + +void CShaderAPIDx10::Unbind( GeometryShaderHandle_t hShader ) +{ + ID3D10GeometryShader* pShader = g_pShaderDeviceDx10->GetGeometryShader( hShader ); + Assert ( pShader ); + if ( m_DesiredState.m_pGeometryShader == pShader ) + { + BindGeometryShader( GEOMETRY_SHADER_HANDLE_INVALID ); + } + if ( m_CurrentState.m_pGeometryShader == pShader ) + { + CommitStateChanges(); + } +} + +void CShaderAPIDx10::Unbind( PixelShaderHandle_t hShader ) +{ + ID3D10PixelShader* pShader = g_pShaderDeviceDx10->GetPixelShader( hShader ); + Assert ( pShader ); + if ( m_DesiredState.m_pPixelShader == pShader ) + { + BindPixelShader( PIXEL_SHADER_HANDLE_INVALID ); + } + if ( m_CurrentState.m_pPixelShader == pShader ) + { + CommitStateChanges(); + } +} + +void CShaderAPIDx10::UnbindVertexBuffer( ID3D10Buffer *pBuffer ) +{ + Assert ( pBuffer ); + + for ( int i = 0; i < MAX_DX10_STREAMS; ++i ) + { + if ( m_DesiredState.m_pVertexBuffer[i].m_pBuffer == pBuffer ) + { + BindVertexBuffer( i, NULL, 0, 0, 0, VERTEX_POSITION, 0 ); + } + } + for ( int i = 0; i < MAX_DX10_STREAMS; ++i ) + { + if ( m_CurrentState.m_pVertexBuffer[i].m_pBuffer == pBuffer ) + { + CommitStateChanges(); + break; + } + } +} + +void CShaderAPIDx10::UnbindIndexBuffer( ID3D10Buffer *pBuffer ) +{ + Assert ( pBuffer ); + + if ( m_DesiredState.m_IndexBuffer.m_pBuffer == pBuffer ) + { + BindIndexBuffer( NULL, 0 ); + } + if ( m_CurrentState.m_IndexBuffer.m_pBuffer == pBuffer ) + { + CommitStateChanges(); + } +} + + +//----------------------------------------------------------------------------- +// Sets the topology state +//----------------------------------------------------------------------------- +void CShaderAPIDx10::SetTopology( MaterialPrimitiveType_t topology ) +{ + D3D10_PRIMITIVE_TOPOLOGY d3dTopology; + switch( topology ) + { + case MATERIAL_POINTS: + d3dTopology = D3D10_PRIMITIVE_TOPOLOGY_POINTLIST; + break; + + case MATERIAL_LINES: + d3dTopology = D3D10_PRIMITIVE_TOPOLOGY_LINELIST; + break; + + case MATERIAL_TRIANGLES: + d3dTopology = D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST; + break; + + case MATERIAL_TRIANGLE_STRIP: + d3dTopology = D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP; + break; + + case MATERIAL_LINE_STRIP: + d3dTopology = D3D10_PRIMITIVE_TOPOLOGY_LINESTRIP; + break; + + default: + case MATERIAL_LINE_LOOP: + case MATERIAL_POLYGON: + case MATERIAL_QUADS: + Assert( 0 ); + d3dTopology = D3D10_PRIMITIVE_TOPOLOGY_UNDEFINED; + break; + } + + ADD_RENDERSTATE_FUNC( CommitSetTopology, m_Topology, d3dTopology ); +} + + +//----------------------------------------------------------------------------- +// Main entry point for rendering +//----------------------------------------------------------------------------- +void CShaderAPIDx10::Draw( MaterialPrimitiveType_t primitiveType, int nFirstIndex, int nIndexCount ) +{ + SetTopology( primitiveType ); + + CommitStateChanges(); + + // FIXME: How do I set the base vertex location!? + D3D10Device()->DrawIndexed( (UINT)nIndexCount, (UINT)nFirstIndex, 0 ); +} + + +//----------------------------------------------------------------------------- +// +// Abandon all hope below this point +// +//----------------------------------------------------------------------------- + +bool CShaderAPIDx10::DoRenderTargetsNeedSeparateDepthBuffer() const +{ + return false; +} + +// Can we download textures? +bool CShaderAPIDx10::CanDownloadTextures() const +{ + return false; +} + +// Used to clear the transition table when we know it's become invalid. +void CShaderAPIDx10::ClearSnapshots() +{ +} + +// Sets the default *dynamic* state +void CShaderAPIDx10::SetDefaultState() +{ +} + + +// Returns the snapshot id for the shader state +StateSnapshot_t CShaderAPIDx10::TakeSnapshot( ) +{ + StateSnapshot_t id = 0; + if (g_pShaderShadowDx10->m_IsTranslucent) + id |= TRANSLUCENT; + if (g_pShaderShadowDx10->m_IsAlphaTested) + id |= ALPHATESTED; + if (g_pShaderShadowDx10->m_bUsesVertexAndPixelShaders) + id |= VERTEX_AND_PIXEL_SHADERS; + if (g_pShaderShadowDx10->m_bIsDepthWriteEnabled) + id |= DEPTHWRITE; + return id; +} + +// Returns true if the state snapshot is transparent +bool CShaderAPIDx10::IsTranslucent( StateSnapshot_t id ) const +{ + return (id & TRANSLUCENT) != 0; +} + +bool CShaderAPIDx10::IsAlphaTested( StateSnapshot_t id ) const +{ + return (id & ALPHATESTED) != 0; +} + +bool CShaderAPIDx10::IsDepthWriteEnabled( StateSnapshot_t id ) const +{ + return (id & DEPTHWRITE) != 0; +} + +bool CShaderAPIDx10::UsesVertexAndPixelShaders( StateSnapshot_t id ) const +{ + return (id & VERTEX_AND_PIXEL_SHADERS) != 0; +} + +// Gets the vertex format for a set of snapshot ids +VertexFormat_t CShaderAPIDx10::ComputeVertexFormat( int numSnapshots, StateSnapshot_t* pIds ) const +{ + return 0; +} + +// Gets the vertex format for a set of snapshot ids +VertexFormat_t CShaderAPIDx10::ComputeVertexUsage( int numSnapshots, StateSnapshot_t* pIds ) const +{ + return 0; +} + +// Uses a state snapshot +void CShaderAPIDx10::UseSnapshot( StateSnapshot_t snapshot ) +{ +} + +// Sets the color to modulate by +void CShaderAPIDx10::Color3f( float r, float g, float b ) +{ +} + +void CShaderAPIDx10::Color3fv( float const* pColor ) +{ +} + +void CShaderAPIDx10::Color4f( float r, float g, float b, float a ) +{ +} + +void CShaderAPIDx10::Color4fv( float const* pColor ) +{ +} + +// Faster versions of color +void CShaderAPIDx10::Color3ub( unsigned char r, unsigned char g, unsigned char b ) +{ +} + +void CShaderAPIDx10::Color3ubv( unsigned char const* rgb ) +{ +} + +void CShaderAPIDx10::Color4ub( unsigned char r, unsigned char g, unsigned char b, unsigned char a ) +{ +} + +void CShaderAPIDx10::Color4ubv( unsigned char const* rgba ) +{ +} + +void CShaderAPIDx10::GetStandardTextureDimensions( int *pWidth, int *pHeight, StandardTextureId_t id ) +{ + ShaderUtil()->GetStandardTextureDimensions( pWidth, pHeight, id ); +} + + +// The shade mode +void CShaderAPIDx10::ShadeMode( ShaderShadeMode_t mode ) +{ +} + +// Binds a particular material to render with +void CShaderAPIDx10::Bind( IMaterial* pMaterial ) +{ +} + +// Cull mode +void CShaderAPIDx10::CullMode( MaterialCullMode_t cullMode ) +{ +} + +void CShaderAPIDx10::ForceDepthFuncEquals( bool bEnable ) +{ +} + +// Forces Z buffering on or off +void CShaderAPIDx10::OverrideDepthEnable( bool bEnable, bool bDepthEnable ) +{ +} + +void CShaderAPIDx10::OverrideAlphaWriteEnable( bool bOverrideEnable, bool bAlphaWriteEnable ) +{ +} + +void CShaderAPIDx10::OverrideColorWriteEnable( bool bOverrideEnable, bool bColorWriteEnable ) +{ +} + + +//legacy fast clipping linkage +void CShaderAPIDx10::SetHeightClipZ( float z ) +{ +} + +void CShaderAPIDx10::SetHeightClipMode( enum MaterialHeightClipMode_t heightClipMode ) +{ +} + + +// Sets the lights +void CShaderAPIDx10::SetLight( int lightNum, const LightDesc_t& desc ) +{ +} + +void CShaderAPIDx10::SetAmbientLight( float r, float g, float b ) +{ +} + +void CShaderAPIDx10::SetAmbientLightCube( Vector4D cube[6] ) +{ +} + +// Get lights +int CShaderAPIDx10::GetMaxLights( void ) const +{ + return 0; +} + +const LightDesc_t& CShaderAPIDx10::GetLight( int lightNum ) const +{ + static LightDesc_t blah; + return blah; +} + +// Render state for the ambient light cube (vertex shaders) +void CShaderAPIDx10::SetVertexShaderStateAmbientLightCube() +{ +} + +void CShaderAPIDx10::SetSkinningMatrices() +{ +} + +// Lightmap texture binding +void CShaderAPIDx10::BindLightmap( TextureStage_t stage ) +{ +} + +void CShaderAPIDx10::BindBumpLightmap( TextureStage_t stage ) +{ +} + +void CShaderAPIDx10::BindFullbrightLightmap( TextureStage_t stage ) +{ +} + +void CShaderAPIDx10::BindWhite( TextureStage_t stage ) +{ +} + +void CShaderAPIDx10::BindBlack( TextureStage_t stage ) +{ +} + +void CShaderAPIDx10::BindGrey( TextureStage_t stage ) +{ +} + +// Gets the lightmap dimensions +void CShaderAPIDx10::GetLightmapDimensions( int *w, int *h ) +{ + g_pShaderUtil->GetLightmapDimensions( w, h ); +} + +// Special system flat normal map binding. +void CShaderAPIDx10::BindFlatNormalMap( TextureStage_t stage ) +{ +} + +void CShaderAPIDx10::BindNormalizationCubeMap( TextureStage_t stage ) +{ +} + +void CShaderAPIDx10::BindSignedNormalizationCubeMap( TextureStage_t stage ) +{ +} + +void CShaderAPIDx10::BindFBTexture( TextureStage_t stage, int textureIndex ) +{ +} + +// Flushes any primitives that are buffered +void CShaderAPIDx10::FlushBufferedPrimitives() +{ +} + +// Creates/destroys Mesh +IMesh* CShaderAPIDx10::CreateStaticMesh( VertexFormat_t fmt, const char *pTextureBudgetGroup, IMaterial * pMaterial ) +{ + return &m_Mesh; +} + +void CShaderAPIDx10::DestroyStaticMesh( IMesh* mesh ) +{ +} + +// Gets the dynamic mesh; note that you've got to render the mesh +// before calling this function a second time. Clients should *not* +// call DestroyStaticMesh on the mesh returned by this call. +IMesh* CShaderAPIDx10::GetDynamicMesh( IMaterial* pMaterial, int nHWSkinBoneCount, bool buffered, IMesh* pVertexOverride, IMesh* pIndexOverride ) +{ + Assert( (pMaterial == NULL) || ((IMaterialInternal *)pMaterial)->IsRealTimeVersion() ); + return &m_Mesh; +} + +IMesh* CShaderAPIDx10::GetDynamicMeshEx( IMaterial* pMaterial, VertexFormat_t fmt, int nHWSkinBoneCount, bool buffered, IMesh* pVertexOverride, IMesh* pIndexOverride ) +{ + // UNDONE: support compressed dynamic meshes if needed (pro: less VB memory, con: time spent compressing) + Assert( CompressionType( pVertexOverride->GetVertexFormat() ) != VERTEX_COMPRESSION_NONE ); + Assert( (pMaterial == NULL) || ((IMaterialInternal *)pMaterial)->IsRealTimeVersion() ); + return &m_Mesh; +} + +IMesh* CShaderAPIDx10::GetFlexMesh() +{ + return &m_Mesh; +} + +// Begins a rendering pass that uses a state snapshot +void CShaderAPIDx10::BeginPass( StateSnapshot_t snapshot ) +{ +} + +// Renders a single pass of a material +void CShaderAPIDx10::RenderPass( int nPass, int nPassCount ) +{ +} + +// stuff related to matrix stacks +void CShaderAPIDx10::MatrixMode( MaterialMatrixMode_t matrixMode ) +{ +} + +void CShaderAPIDx10::PushMatrix() +{ +} + +void CShaderAPIDx10::PopMatrix() +{ +} + +void CShaderAPIDx10::LoadMatrix( float *m ) +{ +} + +void CShaderAPIDx10::MultMatrix( float *m ) +{ +} + +void CShaderAPIDx10::MultMatrixLocal( float *m ) +{ +} + +void CShaderAPIDx10::GetMatrix( MaterialMatrixMode_t matrixMode, float *dst ) +{ +} + +void CShaderAPIDx10::LoadIdentity( void ) +{ +} + +void CShaderAPIDx10::LoadCameraToWorld( void ) +{ +} + +void CShaderAPIDx10::Ortho( double left, double top, double right, double bottom, double zNear, double zFar ) +{ +} + +void CShaderAPIDx10::PerspectiveX( double fovx, double aspect, double zNear, double zFar ) +{ +} + +void CShaderAPIDx10::PerspectiveOffCenterX( double fovx, double aspect, double zNear, double zFar, double bottom, double top, double left, double right ) +{ +} + +void CShaderAPIDx10::PickMatrix( int x, int y, int width, int height ) +{ +} + +void CShaderAPIDx10::Rotate( float angle, float x, float y, float z ) +{ +} + +void CShaderAPIDx10::Translate( float x, float y, float z ) +{ +} + +void CShaderAPIDx10::Scale( float x, float y, float z ) +{ +} + +void CShaderAPIDx10::ScaleXY( float x, float y ) +{ +} + +// Fog methods... +void CShaderAPIDx10::FogMode( MaterialFogMode_t fogMode ) +{ +} + +void CShaderAPIDx10::FogStart( float fStart ) +{ +} + +void CShaderAPIDx10::FogEnd( float fEnd ) +{ +} + +void CShaderAPIDx10::SetFogZ( float fogZ ) +{ +} + +void CShaderAPIDx10::FogMaxDensity( float flMaxDensity ) +{ +} + + +void CShaderAPIDx10::GetFogDistances( float *fStart, float *fEnd, float *fFogZ ) +{ +} + + +void CShaderAPIDx10::SceneFogColor3ub( unsigned char r, unsigned char g, unsigned char b ) +{ +} + + +void CShaderAPIDx10::SceneFogMode( MaterialFogMode_t fogMode ) +{ +} + +void CShaderAPIDx10::GetSceneFogColor( unsigned char *rgb ) +{ +} + +MaterialFogMode_t CShaderAPIDx10::GetSceneFogMode( ) +{ + return MATERIAL_FOG_NONE; +} + +int CShaderAPIDx10::GetPixelFogCombo( ) +{ + return 0; //FIXME +} + +void CShaderAPIDx10::FogColor3f( float r, float g, float b ) +{ +} + +void CShaderAPIDx10::FogColor3fv( float const* rgb ) +{ +} + +void CShaderAPIDx10::FogColor3ub( unsigned char r, unsigned char g, unsigned char b ) +{ +} + +void CShaderAPIDx10::FogColor3ubv( unsigned char const* rgb ) +{ +} + +void CShaderAPIDx10::Viewport( int x, int y, int width, int height ) +{ +} + +void CShaderAPIDx10::GetViewport( int& x, int& y, int& width, int& height ) const +{ +} + +// Sets the vertex and pixel shaders +void CShaderAPIDx10::SetVertexShaderIndex( int vshIndex ) +{ +} + +void CShaderAPIDx10::SetPixelShaderIndex( int pshIndex ) +{ +} + +// Sets the constant register for vertex and pixel shaders +void CShaderAPIDx10::SetVertexShaderConstant( int var, float const* pVec, int numConst, bool bForce ) +{ +} + +void CShaderAPIDx10::SetPixelShaderConstant( int var, float const* pVec, int numConst, bool bForce ) +{ +} + +void CShaderAPIDx10::InvalidateDelayedShaderConstants( void ) +{ +} + +//Set's the linear->gamma conversion textures to use for this hardware for both srgb writes enabled and disabled(identity) +void CShaderAPIDx10::SetLinearToGammaConversionTextures( ShaderAPITextureHandle_t hSRGBWriteEnabledTexture, ShaderAPITextureHandle_t hIdentityTexture ) +{ +} + + +// Returns the nearest supported format +ImageFormat CShaderAPIDx10::GetNearestSupportedFormat( ImageFormat fmt, bool bFilteringRequired /* = true */ ) const +{ + return fmt; +} + +ImageFormat CShaderAPIDx10::GetNearestRenderTargetFormat( ImageFormat fmt ) const +{ + return fmt; +} + +// Sets the texture state +void CShaderAPIDx10::BindTexture( Sampler_t stage, ShaderAPITextureHandle_t textureHandle ) +{ +} + +// Indicates we're going to be modifying this texture +// TexImage2D, TexSubImage2D, TexWrap, TexMinFilter, and TexMagFilter +// all use the texture specified by this function. +void CShaderAPIDx10::ModifyTexture( ShaderAPITextureHandle_t textureHandle ) +{ +} + +// Texture management methods +void CShaderAPIDx10::TexImage2D( int level, int cubeFace, ImageFormat dstFormat, int zOffset, int width, int height, + ImageFormat srcFormat, bool bSrcIsTiled, void *imageData ) +{ +} + +void CShaderAPIDx10::TexSubImage2D( int level, int cubeFace, int xOffset, int yOffset, int zOffset, int width, int height, + ImageFormat srcFormat, int srcStride, bool bSrcIsTiled, void *imageData ) +{ +} + +void CShaderAPIDx10::TexImageFromVTF( IVTFTexture *pVTF, int iVTFFrame ) +{ +} + +bool CShaderAPIDx10::TexLock( int level, int cubeFaceID, int xOffset, int yOffset, + int width, int height, CPixelWriter& writer ) +{ + return false; +} + +void CShaderAPIDx10::TexUnlock( ) +{ +} + + +// These are bound to the texture, not the texture environment +void CShaderAPIDx10::TexMinFilter( ShaderTexFilterMode_t texFilterMode ) +{ +} + +void CShaderAPIDx10::TexMagFilter( ShaderTexFilterMode_t texFilterMode ) +{ +} + +void CShaderAPIDx10::TexWrap( ShaderTexCoordComponent_t coord, ShaderTexWrapMode_t wrapMode ) +{ +} + +void CShaderAPIDx10::TexSetPriority( int priority ) +{ +} + +ShaderAPITextureHandle_t CShaderAPIDx10::CreateTexture( + int width, + int height, + int depth, + ImageFormat dstImageFormat, + int numMipLevels, + int numCopies, + int flags, + const char *pDebugName, + const char *pTextureGroupName ) +{ + ShaderAPITextureHandle_t handle; + CreateTextures( &handle, 1, width, height, depth, dstImageFormat, numMipLevels, numCopies, flags, pDebugName, pTextureGroupName ); + return handle; +} + +void CShaderAPIDx10::CreateTextures( + ShaderAPITextureHandle_t *pHandles, + int count, + int width, + int height, + int depth, + ImageFormat dstImageFormat, + int numMipLevels, + int numCopies, + int flags, + const char *pDebugName, + const char *pTextureGroupName ) +{ + for ( int k = 0; k < count; ++ k ) + { + pHandles[ k ] = 0; + } +} + +ShaderAPITextureHandle_t CShaderAPIDx10::CreateDepthTexture( ImageFormat renderFormat, int width, int height, const char *pDebugName, bool bTexture ) +{ + return 0; +} + +void CShaderAPIDx10::DeleteTexture( ShaderAPITextureHandle_t textureHandle ) +{ +} + +bool CShaderAPIDx10::IsTexture( ShaderAPITextureHandle_t textureHandle ) +{ + return true; +} + +bool CShaderAPIDx10::IsTextureResident( ShaderAPITextureHandle_t textureHandle ) +{ + return false; +} + +// stuff that isn't to be used from within a shader +void CShaderAPIDx10::ClearBuffersObeyStencil( bool bClearColor, bool bClearDepth ) +{ +} + +void CShaderAPIDx10::ClearBuffersObeyStencilEx( bool bClearColor, bool bClearAlpha, bool bClearDepth ) +{ +} + +void CShaderAPIDx10::PerformFullScreenStencilOperation( void ) +{ +} + +void CShaderAPIDx10::ReadPixels( int x, int y, int width, int height, unsigned char *data, ImageFormat dstFormat ) +{ +} + +void CShaderAPIDx10::ReadPixels( Rect_t *pSrcRect, Rect_t *pDstRect, unsigned char *data, ImageFormat dstFormat, int nDstStride ) +{ +} + +void CShaderAPIDx10::FlushHardware() +{ +} + +// Set the number of bone weights +void CShaderAPIDx10::SetNumBoneWeights( int numBones ) +{ +} + +// Selection mode methods +int CShaderAPIDx10::SelectionMode( bool selectionMode ) +{ + return 0; +} + +void CShaderAPIDx10::SelectionBuffer( unsigned int* pBuffer, int size ) +{ +} + +void CShaderAPIDx10::ClearSelectionNames( ) +{ +} + +void CShaderAPIDx10::LoadSelectionName( int name ) +{ +} + +void CShaderAPIDx10::PushSelectionName( int name ) +{ +} + +void CShaderAPIDx10::PopSelectionName() +{ +} + + +// Use this to get the mesh builder that allows us to modify vertex data +CMeshBuilder* CShaderAPIDx10::GetVertexModifyBuilder() +{ + return 0; +} + +// Board-independent calls, here to unify how shaders set state +// Implementations should chain back to IShaderUtil->BindTexture(), etc. + +// Use this to begin and end the frame +void CShaderAPIDx10::BeginFrame() +{ +} + +void CShaderAPIDx10::EndFrame() +{ +} + +// returns the current time in seconds.... +double CShaderAPIDx10::CurrentTime() const +{ + return Sys_FloatTime(); +} + +// Get the current camera position in world space. +void CShaderAPIDx10::GetWorldSpaceCameraPosition( float * pPos ) const +{ +} + +void CShaderAPIDx10::ForceHardwareSync( void ) +{ +} + +void CShaderAPIDx10::SetClipPlane( int index, const float *pPlane ) +{ +} + +void CShaderAPIDx10::EnableClipPlane( int index, bool bEnable ) +{ +} + +void CShaderAPIDx10::SetFastClipPlane( const float *pPlane ) +{ +} + +void CShaderAPIDx10::EnableFastClip( bool bEnable ) +{ +} + +int CShaderAPIDx10::GetCurrentNumBones( void ) const +{ + return 0; +} + +// Is hardware morphing enabled? +bool CShaderAPIDx10::IsHWMorphingEnabled( ) const +{ + return false; +} + +int CShaderAPIDx10::GetCurrentLightCombo( void ) const +{ + return 0; +} + +int CShaderAPIDx10::MapLightComboToPSLightCombo( int nLightCombo ) const +{ + return 0; +} + +MaterialFogMode_t CShaderAPIDx10::GetCurrentFogType( void ) const +{ + return MATERIAL_FOG_NONE; +} + +void CShaderAPIDx10::RecordString( const char *pStr ) +{ +} + +void CShaderAPIDx10::DestroyVertexBuffers( bool bExitingLevel ) +{ +} + +int CShaderAPIDx10::GetCurrentDynamicVBSize( void ) +{ + return 0; +} + +void CShaderAPIDx10::EvictManagedResources() +{ +} + +void CShaderAPIDx10::ReleaseShaderObjects() +{ +} + +void CShaderAPIDx10::RestoreShaderObjects() +{ +} + +void CShaderAPIDx10::SetTextureTransformDimension( TextureStage_t textureStage, int dimension, bool projected ) +{ +} + +void CShaderAPIDx10::SetBumpEnvMatrix( TextureStage_t textureStage, float m00, float m01, float m10, float m11 ) +{ +} + +void CShaderAPIDx10::SyncToken( const char *pToken ) +{ +} diff --git a/materialsystem/shaderapidx9/shaderapidx10.h b/materialsystem/shaderapidx9/shaderapidx10.h new file mode 100644 index 0000000..c6b131f --- /dev/null +++ b/materialsystem/shaderapidx9/shaderapidx10.h @@ -0,0 +1,940 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +// +//===========================================================================// + +#ifndef SHADERAPIDX10_H +#define SHADERAPIDX10_H + +#ifdef _WIN32 +#pragma once +#endif + +#include + +#include "shaderapibase.h" +#include "materialsystem/idebugtextureinfo.h" +#include "meshdx10.h" + + +//----------------------------------------------------------------------------- +// Forward declarations +//----------------------------------------------------------------------------- +struct MaterialSystemHardwareIdentifier_t; + + +//----------------------------------------------------------------------------- +// DX10 enumerations that don't appear to exist +//----------------------------------------------------------------------------- +#define MAX_DX10_VIEWPORTS 16 +#define MAX_DX10_STREAMS 16 + + +//----------------------------------------------------------------------------- +// A record describing the state on the board +//----------------------------------------------------------------------------- +struct ShaderIndexBufferStateDx10_t +{ + ID3D10Buffer *m_pBuffer; + DXGI_FORMAT m_Format; + UINT m_nOffset; + + bool operator!=( const ShaderIndexBufferStateDx10_t& src ) const + { + return memcmp( this, &src, sizeof(ShaderIndexBufferStateDx10_t) ) != 0; + } +}; + +struct ShaderVertexBufferStateDx10_t +{ + ID3D10Buffer *m_pBuffer; + UINT m_nStride; + UINT m_nOffset; +}; + +struct ShaderInputLayoutStateDx10_t +{ + VertexShaderHandle_t m_hVertexShader; + VertexFormat_t m_pVertexDecl[ MAX_DX10_STREAMS ]; +}; + +struct ShaderStateDx10_t +{ + int m_nViewportCount; + D3D10_VIEWPORT m_pViewports[ MAX_DX10_VIEWPORTS ]; + FLOAT m_ClearColor[4]; + ShaderRasterState_t m_RasterState; + ID3D10RasterizerState *m_pRasterState; + ID3D10VertexShader *m_pVertexShader; + ID3D10GeometryShader *m_pGeometryShader; + ID3D10PixelShader *m_pPixelShader; + ShaderVertexBufferStateDx10_t m_pVertexBuffer[ MAX_DX10_STREAMS ]; + ShaderIndexBufferStateDx10_t m_IndexBuffer; + ShaderInputLayoutStateDx10_t m_InputLayout; + D3D10_PRIMITIVE_TOPOLOGY m_Topology; +}; + + +//----------------------------------------------------------------------------- +// Commit function helper class +//----------------------------------------------------------------------------- +typedef void (*StateCommitFunc_t)( ID3D10Device *pDevice, const ShaderStateDx10_t &desiredState, ShaderStateDx10_t ¤tState, bool bForce ); + +class CFunctionCommit +{ +public: + CFunctionCommit(); + ~CFunctionCommit(); + + void Init( int nFunctionCount ); + + // Methods related to queuing functions to be called per-(pMesh->Draw call) or per-pass + void ClearAllCommitFuncs( ); + void CallCommitFuncs( bool bForce ); + bool IsCommitFuncInUse( int nFunc ) const; + void MarkCommitFuncInUse( int nFunc ); + void AddCommitFunc( StateCommitFunc_t f ); + void CallCommitFuncs( ID3D10Device *pDevice, const ShaderStateDx10_t &desiredState, ShaderStateDx10_t ¤tState, bool bForce = false ); + +private: + // A list of state commit functions to run as per-draw call commit time + unsigned char* m_pCommitFlags; + int m_nCommitBufferSize; + CUtlVector< StateCommitFunc_t > m_CommitFuncs; +}; + + +//----------------------------------------------------------------------------- +// The Dx10 implementation of the shader API +//----------------------------------------------------------------------------- +class CShaderAPIDx10 : public CShaderAPIBase, public IDebugTextureInfo +{ + typedef CShaderAPIBase BaseClass; + +public: + // constructor, destructor + CShaderAPIDx10( ); + virtual ~CShaderAPIDx10(); + + // Methods of IShaderAPI + // NOTE: These methods have been ported over +public: + virtual void SetViewports( int nCount, const ShaderViewport_t* pViewports ); + virtual int GetViewports( ShaderViewport_t* pViewports, int nMax ) const; + virtual void ClearBuffers( bool bClearColor, bool bClearDepth, bool bClearStencil, int renderTargetWidth, int renderTargetHeight ); + virtual void ClearColor3ub( unsigned char r, unsigned char g, unsigned char b ); + virtual void ClearColor4ub( unsigned char r, unsigned char g, unsigned char b, unsigned char a ); + virtual void SetRasterState( const ShaderRasterState_t& state ); + virtual void BindVertexShader( VertexShaderHandle_t hVertexShader ); + virtual void BindGeometryShader( GeometryShaderHandle_t hGeometryShader ); + virtual void BindPixelShader( PixelShaderHandle_t hPixelShader ); + virtual void BindVertexBuffer( int nStreamID, IVertexBuffer *pVertexBuffer, int nOffsetInBytes, int nFirstVertex, int nVertexCount, VertexFormat_t fmt, int nRepetitions = 1 ); + virtual void BindIndexBuffer( IIndexBuffer *pIndexBuffer, int nOffsetInBytes ); + virtual void Draw( MaterialPrimitiveType_t primitiveType, int nFirstIndex, int nIndexCount ); + + // Methods of IShaderDynamicAPI +public: + virtual void GetBackBufferDimensions( int& nWidth, int& nHeight ) const; + +public: + // Methods of CShaderAPIBase + virtual bool OnDeviceInit() { ResetRenderState(); return true; } + virtual void OnDeviceShutdown() {} + virtual void ReleaseShaderObjects(); + virtual void RestoreShaderObjects(); + virtual void BeginPIXEvent( unsigned long color, const char *szName ) {} + virtual void EndPIXEvent() {} + virtual void AdvancePIXFrame() {} + + // NOTE: These methods have not been ported over. + // IDebugTextureInfo implementation. +public: + + virtual bool IsDebugTextureListFresh( int numFramesAllowed = 1 ) { return false; } + virtual void EnableDebugTextureList( bool bEnable ) {} + virtual void EnableGetAllTextures( bool bEnable ) {} + virtual KeyValues* GetDebugTextureList() { return NULL; } + virtual int GetTextureMemoryUsed( TextureMemoryType eTextureMemory ) { return 0; } + virtual bool SetDebugTextureRendering( bool bEnable ) { return false; } + +public: + // Other public methods + void Unbind( VertexShaderHandle_t hShader ); + void Unbind( GeometryShaderHandle_t hShader ); + void Unbind( PixelShaderHandle_t hShader ); + void UnbindVertexBuffer( ID3D10Buffer *pBuffer ); + void UnbindIndexBuffer( ID3D10Buffer *pBuffer ); + + void PrintfVA( char *fmt, va_list vargs ) {} + void Printf( PRINTF_FORMAT_STRING const char *fmt, ... ) {} + float Knob( char *knobname, float *setvalue = NULL ) { return 0.0f;} + +private: + + // Returns a d3d texture associated with a texture handle + virtual IDirect3DBaseTexture* GetD3DTexture( ShaderAPITextureHandle_t hTexture ) { Assert(0); return NULL; } + virtual void QueueResetRenderState() {} + + void SetTopology( MaterialPrimitiveType_t topology ); + + virtual bool DoRenderTargetsNeedSeparateDepthBuffer() const; + + void SetHardwareGammaRamp( float fGamma ) + { + } + + // Used to clear the transition table when we know it's become invalid. + void ClearSnapshots(); + + // Sets the mode... + bool SetMode( void* hwnd, int nAdapter, const ShaderDeviceInfo_t &info ) + { + return true; + } + + void ChangeVideoMode( const ShaderDeviceInfo_t &info ) + { + } + + // Called when the dx support level has changed + virtual void DXSupportLevelChanged() {} + + virtual void EnableUserClipTransformOverride( bool bEnable ) {} + virtual void UserClipTransform( const VMatrix &worldToView ) {} + virtual bool GetUserClipTransform( VMatrix &worldToView ) { return false; } + + // Sets the default *dynamic* state + void SetDefaultState( ); + + // Returns the snapshot id for the shader state + StateSnapshot_t TakeSnapshot( ); + + // Returns true if the state snapshot is transparent + bool IsTranslucent( StateSnapshot_t id ) const; + bool IsAlphaTested( StateSnapshot_t id ) const; + bool UsesVertexAndPixelShaders( StateSnapshot_t id ) const; + virtual bool IsDepthWriteEnabled( StateSnapshot_t id ) const; + + // Gets the vertex format for a set of snapshot ids + VertexFormat_t ComputeVertexFormat( int numSnapshots, StateSnapshot_t* pIds ) const; + + // Gets the vertex format for a set of snapshot ids + VertexFormat_t ComputeVertexUsage( int numSnapshots, StateSnapshot_t* pIds ) const; + + // Begins a rendering pass that uses a state snapshot + void BeginPass( StateSnapshot_t snapshot ); + + // Uses a state snapshot + void UseSnapshot( StateSnapshot_t snapshot ); + + // Use this to get the mesh builder that allows us to modify vertex data + CMeshBuilder* GetVertexModifyBuilder(); + + // Sets the color to modulate by + void Color3f( float r, float g, float b ); + void Color3fv( float const* pColor ); + void Color4f( float r, float g, float b, float a ); + void Color4fv( float const* pColor ); + + // Faster versions of color + void Color3ub( unsigned char r, unsigned char g, unsigned char b ); + void Color3ubv( unsigned char const* rgb ); + void Color4ub( unsigned char r, unsigned char g, unsigned char b, unsigned char a ); + void Color4ubv( unsigned char const* rgba ); + + // Sets the lights + void SetLight( int lightNum, const LightDesc_t& desc ); + void SetAmbientLight( float r, float g, float b ); + void SetAmbientLightCube( Vector4D cube[6] ); + virtual void SetLightingOrigin( Vector vLightingOrigin ) {} + + // Get the lights + int GetMaxLights( void ) const; + const LightDesc_t& GetLight( int lightNum ) const; + + // Render state for the ambient light cube (vertex shaders) + void SetVertexShaderStateAmbientLightCube(); + virtual void SetPixelShaderStateAmbientLightCube( int pshReg, bool bForceToBlack = false ) {} + void SetPixelShaderStateAmbientLightCube( int pshReg ) + { + } + virtual void GetDX9LightState( LightState_t *state ) const {} + + float GetAmbientLightCubeLuminance(void) + { + return 0.0f; + } + + void SetSkinningMatrices(); + + // Lightmap texture binding + void BindLightmap( TextureStage_t stage ); + void BindLightmapAlpha( TextureStage_t stage ) + { + } + void BindBumpLightmap( TextureStage_t stage ); + void BindFullbrightLightmap( TextureStage_t stage ); + void BindWhite( TextureStage_t stage ); + void BindBlack( TextureStage_t stage ); + void BindGrey( TextureStage_t stage ); + void BindFBTexture( TextureStage_t stage, int textureIdex ); + void CopyRenderTargetToTexture( ShaderAPITextureHandle_t texID ) + { + } + + void CopyRenderTargetToTextureEx( ShaderAPITextureHandle_t texID, int nRenderTargetID, Rect_t *pSrcRect, Rect_t *pDstRect ) + { + } + + void CopyTextureToRenderTargetEx( int nRenderTargetID, ShaderAPITextureHandle_t textureHandle, Rect_t *pSrcRect = NULL, Rect_t *pDstRect = NULL ) + { + } + + // Special system flat normal map binding. + void BindFlatNormalMap( TextureStage_t stage ); + void BindNormalizationCubeMap( TextureStage_t stage ); + void BindSignedNormalizationCubeMap( TextureStage_t stage ); + + // Set the number of bone weights + void SetNumBoneWeights( int numBones ); + + // Flushes any primitives that are buffered + void FlushBufferedPrimitives(); + + // Creates/destroys Mesh + IMesh* CreateStaticMesh( VertexFormat_t fmt, const char *pTextureBudgetGroup, IMaterial * pMaterial = NULL ); + void DestroyStaticMesh( IMesh* mesh ); + + // Gets the dynamic mesh; note that you've got to render the mesh + // before calling this function a second time. Clients should *not* + // call DestroyStaticMesh on the mesh returned by this call. + IMesh* GetDynamicMesh( IMaterial* pMaterial, int nHWSkinBoneCount, bool buffered, IMesh* pVertexOverride, IMesh* pIndexOverride ); + IMesh* GetDynamicMeshEx( IMaterial* pMaterial, VertexFormat_t fmt, int nHWSkinBoneCount, bool buffered, IMesh* pVertexOverride, IMesh* pIndexOverride ); + IVertexBuffer *GetDynamicVertexBuffer( IMaterial* pMaterial, bool buffered ) + { + Assert( 0 ); + return NULL; + } + IIndexBuffer *GetDynamicIndexBuffer( IMaterial* pMaterial, bool buffered ) + { + Assert( 0 ); + return NULL; + } + IMesh* GetFlexMesh(); + + // Renders a single pass of a material + void RenderPass( int nPass, int nPassCount ); + + // stuff related to matrix stacks + void MatrixMode( MaterialMatrixMode_t matrixMode ); + void PushMatrix(); + void PopMatrix(); + void LoadMatrix( float *m ); + void LoadBoneMatrix( int boneIndex, const float *m ) {} + void MultMatrix( float *m ); + void MultMatrixLocal( float *m ); + void GetMatrix( MaterialMatrixMode_t matrixMode, float *dst ); + void LoadIdentity( void ); + void LoadCameraToWorld( void ); + void Ortho( double left, double top, double right, double bottom, double zNear, double zFar ); + void PerspectiveX( double fovx, double aspect, double zNear, double zFar ); + void PerspectiveOffCenterX( double fovx, double aspect, double zNear, double zFar, double bottom, double top, double left, double right ); + void PickMatrix( int x, int y, int width, int height ); + void Rotate( float angle, float x, float y, float z ); + void Translate( float x, float y, float z ); + void Scale( float x, float y, float z ); + void ScaleXY( float x, float y ); + + void Viewport( int x, int y, int width, int height ); + void GetViewport( int& x, int& y, int& width, int& height ) const; + + // Fog methods... + void FogMode( MaterialFogMode_t fogMode ); + void FogStart( float fStart ); + void FogEnd( float fEnd ); + void SetFogZ( float fogZ ); + void FogMaxDensity( float flMaxDensity ); + void GetFogDistances( float *fStart, float *fEnd, float *fFogZ ); + void FogColor3f( float r, float g, float b ); + void FogColor3fv( float const* rgb ); + void FogColor3ub( unsigned char r, unsigned char g, unsigned char b ); + void FogColor3ubv( unsigned char const* rgb ); + + virtual void SceneFogColor3ub( unsigned char r, unsigned char g, unsigned char b ); + virtual void SceneFogMode( MaterialFogMode_t fogMode ); + virtual void GetSceneFogColor( unsigned char *rgb ); + virtual MaterialFogMode_t GetSceneFogMode( ); + virtual int GetPixelFogCombo( ); + + void SetHeightClipZ( float z ); + void SetHeightClipMode( enum MaterialHeightClipMode_t heightClipMode ); + + void SetClipPlane( int index, const float *pPlane ); + void EnableClipPlane( int index, bool bEnable ); + + void SetFastClipPlane( const float *pPlane ); + void EnableFastClip( bool bEnable ); + + // We use smaller dynamic VBs during level transitions, to free up memory + virtual int GetCurrentDynamicVBSize( void ); + virtual void DestroyVertexBuffers( bool bExitingLevel = false ); + + // Sets the vertex and pixel shaders + void SetVertexShaderIndex( int vshIndex ); + void SetPixelShaderIndex( int pshIndex ); + + // Sets the constant register for vertex and pixel shaders + void SetVertexShaderConstant( int var, float const* pVec, int numConst = 1, bool bForce = false ); + void SetPixelShaderConstant( int var, float const* pVec, int numConst = 1, bool bForce = false ); + + void SetBooleanVertexShaderConstant( int var, BOOL const* pVec, int numBools = 1, bool bForce = false ) + { + Assert(0); + } + + + void SetIntegerVertexShaderConstant( int var, int const* pVec, int numIntVecs = 1, bool bForce = false ) + { + Assert(0); + } + + + void SetBooleanPixelShaderConstant( int var, BOOL const* pVec, int numBools = 1, bool bForce = false ) + { + Assert(0); + } + + void SetIntegerPixelShaderConstant( int var, int const* pVec, int numIntVecs = 1, bool bForce = false ) + { + Assert(0); + } + + bool ShouldWriteDepthToDestAlpha( void ) const + { + Assert(0); + return false; + } + + + void InvalidateDelayedShaderConstants( void ); + + // Gamma<->Linear conversions according to the video hardware we're running on + float GammaToLinear_HardwareSpecific( float fGamma ) const + { + return 0.; + } + + float LinearToGamma_HardwareSpecific( float fLinear ) const + { + return 0.; + } + + //Set's the linear->gamma conversion textures to use for this hardware for both srgb writes enabled and disabled(identity) + void SetLinearToGammaConversionTextures( ShaderAPITextureHandle_t hSRGBWriteEnabledTexture, ShaderAPITextureHandle_t hIdentityTexture ); + + // Cull mode + void CullMode( MaterialCullMode_t cullMode ); + + // Force writes only when z matches. . . useful for stenciling things out + // by rendering the desired Z values ahead of time. + void ForceDepthFuncEquals( bool bEnable ); + + // Forces Z buffering on or off + void OverrideDepthEnable( bool bEnable, bool bDepthEnable ); + // Forces alpha writes on or off + void OverrideAlphaWriteEnable( bool bOverrideEnable, bool bAlphaWriteEnable ); + //forces color writes on or off + void OverrideColorWriteEnable( bool bOverrideEnable, bool bColorWriteEnable ); + + // Sets the shade mode + void ShadeMode( ShaderShadeMode_t mode ); + + // Binds a particular material to render with + void Bind( IMaterial* pMaterial ); + + // Returns the nearest supported format + ImageFormat GetNearestSupportedFormat( ImageFormat fmt, bool bFilteringRequired = true ) const; + ImageFormat GetNearestRenderTargetFormat( ImageFormat fmt ) const; + + // Sets the texture state + void BindTexture( Sampler_t stage, ShaderAPITextureHandle_t textureHandle ); + + void SetRenderTarget( ShaderAPITextureHandle_t colorTextureHandle, ShaderAPITextureHandle_t depthTextureHandle ) + { + } + + void SetRenderTargetEx( int nRenderTargetID, ShaderAPITextureHandle_t colorTextureHandle, ShaderAPITextureHandle_t depthTextureHandle ) + { + } + + // Indicates we're going to be modifying this texture + // TexImage2D, TexSubImage2D, TexWrap, TexMinFilter, and TexMagFilter + // all use the texture specified by this function. + void ModifyTexture( ShaderAPITextureHandle_t textureHandle ); + + // Texture management methods + void TexImage2D( int level, int cubeFace, ImageFormat dstFormat, int zOffset, int width, int height, + ImageFormat srcFormat, bool bSrcIsTiled, void *imageData ); + void TexSubImage2D( int level, int cubeFace, int xOffset, int yOffset, int zOffset, int width, int height, + ImageFormat srcFormat, int srcStride, bool bSrcIsTiled, void *imageData ); + void TexImageFromVTF( IVTFTexture *pVTF, int iVTFFrame ); + + bool TexLock( int level, int cubeFaceID, int xOffset, int yOffset, + int width, int height, CPixelWriter& writer ); + void TexUnlock( ); + + // These are bound to the texture, not the texture environment + void TexMinFilter( ShaderTexFilterMode_t texFilterMode ); + void TexMagFilter( ShaderTexFilterMode_t texFilterMode ); + void TexWrap( ShaderTexCoordComponent_t coord, ShaderTexWrapMode_t wrapMode ); + void TexSetPriority( int priority ); + + ShaderAPITextureHandle_t CreateTexture( + int width, + int height, + int depth, + ImageFormat dstImageFormat, + int numMipLevels, + int numCopies, + int flags, + const char *pDebugName, + const char *pTextureGroupName ); + void CreateTextures( + ShaderAPITextureHandle_t *pHandles, + int count, + int width, + int height, + int depth, + ImageFormat dstImageFormat, + int numMipLevels, + int numCopies, + int flags, + const char *pDebugName, + const char *pTextureGroupName ); + ShaderAPITextureHandle_t CreateDepthTexture( ImageFormat renderFormat, int width, int height, const char *pDebugName, bool bTexture ); + void DeleteTexture( ShaderAPITextureHandle_t textureHandle ); + bool IsTexture( ShaderAPITextureHandle_t textureHandle ); + bool IsTextureResident( ShaderAPITextureHandle_t textureHandle ); + + // stuff that isn't to be used from within a shader + void ClearBuffersObeyStencil( bool bClearColor, bool bClearDepth ); + void ClearBuffersObeyStencilEx( bool bClearColor, bool bClearAlpha, bool bClearDepth ); + void PerformFullScreenStencilOperation( void ); + void ReadPixels( int x, int y, int width, int height, unsigned char *data, ImageFormat dstFormat ); + virtual void ReadPixels( Rect_t *pSrcRect, Rect_t *pDstRect, unsigned char *data, ImageFormat dstFormat, int nDstStride ); + + // Selection mode methods + int SelectionMode( bool selectionMode ); + void SelectionBuffer( unsigned int* pBuffer, int size ); + void ClearSelectionNames( ); + void LoadSelectionName( int name ); + void PushSelectionName( int name ); + void PopSelectionName(); + + void FlushHardware(); + void ResetRenderState( bool bFullReset = true ); + + // Can we download textures? + virtual bool CanDownloadTextures() const; + + // Board-independent calls, here to unify how shaders set state + // Implementations should chain back to IShaderUtil->BindTexture(), etc. + + // Use this to begin and end the frame + void BeginFrame(); + void EndFrame(); + + // returns current time + double CurrentTime() const; + + // Get the current camera position in world space. + void GetWorldSpaceCameraPosition( float * pPos ) const; + + void ForceHardwareSync( void ); + + int GetCurrentNumBones( void ) const; + bool IsHWMorphingEnabled( ) const; + int GetCurrentLightCombo( void ) const; + int MapLightComboToPSLightCombo( int nLightCombo ) const; + MaterialFogMode_t GetCurrentFogType( void ) const; + + void RecordString( const char *pStr ); + + void EvictManagedResources(); + + void SetTextureTransformDimension( TextureStage_t textureStage, int dimension, bool projected ); + void DisableTextureTransform( TextureStage_t textureStage ) + { + } + void SetBumpEnvMatrix( TextureStage_t textureStage, float m00, float m01, float m10, float m11 ); + + // Gets the lightmap dimensions + virtual void GetLightmapDimensions( int *w, int *h ); + + virtual void SyncToken( const char *pToken ); + + // Setup standard vertex shader constants (that don't change) + // This needs to be called anytime that overbright changes. + virtual void SetStandardVertexShaderConstants( float fOverbright ) + { + } + + // Scissor Rect + virtual void SetScissorRect( const int nLeft, const int nTop, const int nRight, const int nBottom, const bool bEnableScissor ) {} + + // Reports support for a given CSAA mode + bool SupportsCSAAMode( int nNumSamples, int nQualityLevel ) { return false; } + + // Level of anisotropic filtering + virtual void SetAnisotropicLevel( int nAnisotropyLevel ) + { + } + + void SetDefaultDynamicState() + { + } + virtual void CommitPixelShaderLighting( int pshReg ) + { + } + + virtual void MarkUnusedVertexFields( unsigned int nFlags, int nTexCoordCount, bool *pUnusedTexCoords ) + { + } + + ShaderAPIOcclusionQuery_t CreateOcclusionQueryObject( void ) + { + return INVALID_SHADERAPI_OCCLUSION_QUERY_HANDLE; + } + + void DestroyOcclusionQueryObject( ShaderAPIOcclusionQuery_t handle ) + { + } + + void BeginOcclusionQueryDrawing( ShaderAPIOcclusionQuery_t handle ) + { + } + + void EndOcclusionQueryDrawing( ShaderAPIOcclusionQuery_t handle ) + { + } + + int OcclusionQuery_GetNumPixelsRendered( ShaderAPIOcclusionQuery_t handle, bool bFlush ) + { + return 0; + } + + virtual void AcquireThreadOwnership() {} + virtual void ReleaseThreadOwnership() {} + + virtual bool SupportsBorderColor() const { return false; } + virtual bool SupportsFetch4() const { return false; } + virtual void EnableBuffer2FramesAhead( bool bEnable ) {} + + virtual void SetDepthFeatheringPixelShaderConstant( int iConstant, float fDepthBlendScale ) {} + + void SetPixelShaderFogParams( int reg ) + { + } + + virtual bool InFlashlightMode() const + { + return false; + } + + virtual bool InEditorMode() const + { + return false; + } + + // What fields in the morph do we actually use? + virtual MorphFormat_t ComputeMorphFormat( int numSnapshots, StateSnapshot_t* pIds ) const + { + return 0; + } + + // Gets the bound morph's vertex format; returns 0 if no morph is bound + virtual MorphFormat_t GetBoundMorphFormat() + { + return 0; + } + + void GetStandardTextureDimensions( int *pWidth, int *pHeight, StandardTextureId_t id ); + + // Binds a standard texture + virtual void BindStandardTexture( Sampler_t stage, StandardTextureId_t id ) + { + } + + virtual void BindStandardVertexTexture( VertexTextureSampler_t stage, StandardTextureId_t id ) + { + } + + virtual void SetFlashlightState( const FlashlightState_t &state, const VMatrix &worldToTexture ) + { + } + + virtual void SetFlashlightStateEx( const FlashlightState_t &state, const VMatrix &worldToTexture, ITexture *pFlashlightDepthTexture ) + { + } + + virtual const FlashlightState_t &GetFlashlightState( VMatrix &worldToTexture ) const + { + static FlashlightState_t blah; + return blah; + } + + virtual const FlashlightState_t &GetFlashlightStateEx( VMatrix &worldToTexture, ITexture **pFlashlightDepthTexture ) const + { + static FlashlightState_t blah; + return blah; + } + + virtual void SetModeChangeCallback( ModeChangeCallbackFunc_t func ) + { + } + + + virtual void ClearVertexAndPixelShaderRefCounts() + { + } + + virtual void PurgeUnusedVertexAndPixelShaders() + { + } + + // Binds a vertex texture to a particular texture stage in the vertex pipe + virtual void BindVertexTexture( VertexTextureSampler_t nStage, ShaderAPITextureHandle_t hTexture ) + { + } + + // Sets morph target factors + virtual void SetFlexWeights( int nFirstWeight, int nCount, const MorphWeight_t* pWeights ) + { + } + + // NOTE: Stuff after this is added after shipping HL2. + ITexture *GetRenderTargetEx( int nRenderTargetID ) + { + return NULL; + } + + void SetToneMappingScaleLinear( const Vector &scale ) + { + } + + const Vector &GetToneMappingScaleLinear( void ) const + { + static Vector dummy; + return dummy; + } + + virtual float GetLightMapScaleFactor( void ) const + { + return 1.0; + } + + // For dealing with device lost in cases where SwapBuffers isn't called all the time (Hammer) + virtual void HandleDeviceLost() + { + } + + virtual void EnableLinearColorSpaceFrameBuffer( bool bEnable ) + { + } + + // Lets the shader know about the full-screen texture so it can + virtual void SetFullScreenTextureHandle( ShaderAPITextureHandle_t h ) + { + } + + void SetFloatRenderingParameter(int parm_number, float value) + { + } + + void SetIntRenderingParameter(int parm_number, int value) + { + } + void SetVectorRenderingParameter(int parm_number, Vector const &value) + { + } + + float GetFloatRenderingParameter(int parm_number) const + { + return 0; + } + + int GetIntRenderingParameter(int parm_number) const + { + return 0; + } + + Vector GetVectorRenderingParameter(int parm_number) const + { + return Vector(0,0,0); + } + + // Methods related to stencil + void SetStencilEnable(bool onoff) + { + } + + void SetStencilFailOperation(StencilOperation_t op) + { + } + + void SetStencilZFailOperation(StencilOperation_t op) + { + } + + void SetStencilPassOperation(StencilOperation_t op) + { + } + + void SetStencilCompareFunction(StencilComparisonFunction_t cmpfn) + { + } + + void SetStencilReferenceValue(int ref) + { + } + + void SetStencilTestMask(uint32 msk) + { + } + + void SetStencilWriteMask(uint32 msk) + { + } + + void ClearStencilBufferRectangle( int xmin, int ymin, int xmax, int ymax,int value) + { + } + + virtual void GetDXLevelDefaults(uint &max_dxlevel,uint &recommended_dxlevel) + { + max_dxlevel=recommended_dxlevel=90; + } + + virtual void GetMaxToRender( IMesh *pMesh, bool bMaxUntilFlush, int *pMaxVerts, int *pMaxIndices ) + { + *pMaxVerts = 32768; + *pMaxIndices = 32768; + } + + // Returns the max possible vertices + indices to render in a single draw call + virtual int GetMaxVerticesToRender( IMaterial *pMaterial ) + { + return 32768; + } + + virtual int GetMaxIndicesToRender( ) + { + return 32768; + } + virtual int CompareSnapshots( StateSnapshot_t snapshot0, StateSnapshot_t snapshot1 ) { return 0; } + + virtual void DisableAllLocalLights() {} + + virtual bool SupportsMSAAMode( int nMSAAMode ) { return false; } + + // Hooks for firing PIX events from outside the Material System... + virtual void SetPIXMarker( unsigned long color, const char *szName ) {} + + virtual void ComputeVertexDescription( unsigned char* pBuffer, VertexFormat_t vertexFormat, MeshDesc_t& desc ) const {} + + virtual bool SupportsShadowDepthTextures() { return false; } + + virtual int NeedsShaderSRGBConversion(void) const { return 1; } + + virtual bool SupportsFetch4() { return false; } + + virtual void SetShadowDepthBiasFactors( float fShadowSlopeScaleDepthBias, float fShadowDepthBias ) {} + + virtual void SetDisallowAccess( bool ) {} + virtual void EnableShaderShaderMutex( bool ) {} + virtual void ShaderLock() {} + virtual void ShaderUnlock() {} + virtual void EnableHWMorphing( bool bEnable ) {} + ImageFormat GetNullTextureFormat( void ) { return IMAGE_FORMAT_ABGR8888; } // stub + virtual void PushDeformation( DeformationBase_t const *Deformation ) + { + } + + virtual void PopDeformation( ) + { + } + + virtual int GetNumActiveDeformations() const + { + return 0; + } + + + virtual void ExecuteCommandBuffer( uint8 *pBuf ) + { + } + + void SetStandardTextureHandle(StandardTextureId_t,ShaderAPITextureHandle_t) + { + } + + virtual void SetPSNearAndFarZ( int pshReg ) + { + } + + int GetPackedDeformationInformation( int nMaskOfUnderstoodDeformations, + float *pConstantValuesOut, + int nBufferSize, + int nMaximumDeformations, + int *pNumDefsOut ) const + { + *pNumDefsOut = 0; + return 0; + } + + virtual bool OwnGPUResources( bool bEnable ) + { + return false; + } + +private: + enum + { + TRANSLUCENT = 0x1, + ALPHATESTED = 0x2, + VERTEX_AND_PIXEL_SHADERS = 0x4, + DEPTHWRITE = 0x8, + }; + void EnableAlphaToCoverage() {} ; + void DisableAlphaToCoverage() {} ; + + ImageFormat GetShadowDepthTextureFormat() { return IMAGE_FORMAT_UNKNOWN; }; + + // + // NOTE: Under here are real methods being used by dx10 implementation + // above is stuff I still have to port over. + // +private: + void ClearShaderState( ShaderStateDx10_t* pState ); + void CommitStateChanges( bool bForce = false ); + +private: + CMeshDx10 m_Mesh; + + bool m_bResettingRenderState : 1; + CFunctionCommit m_Commit; + ShaderStateDx10_t m_DesiredState; + ShaderStateDx10_t m_CurrentState; +}; + + +//----------------------------------------------------------------------------- +// Singleton global +//----------------------------------------------------------------------------- +extern CShaderAPIDx10* g_pShaderAPIDx10; + +#endif // SHADERAPIDX10_H + diff --git a/materialsystem/shaderapidx9/shaderapidx10.vpc b/materialsystem/shaderapidx9/shaderapidx10.vpc new file mode 100644 index 0000000..20243b0 --- /dev/null +++ b/materialsystem/shaderapidx9/shaderapidx10.vpc @@ -0,0 +1,174 @@ +//----------------------------------------------------------------------------- +// SHADERAPIDX10.VPC +// +// Project Script +//----------------------------------------------------------------------------- + +$macro SRCDIR "..\.." +$Macro OUTBINDIR "$SRCDIR\..\game\bin" + +$Include "$SRCDIR\vpc_scripts\source_dll_base.vpc" + +$Configuration "Debug" +{ + $General + { + $OutputDirectory ".\Debug_dx10" + $IntermediateDirectory ".\Debug_dx10" + } +} + +$Configuration "Release" +{ + $General + { + $OutputDirectory ".\Release_dx10" + $IntermediateDirectory ".\Release_dx10" + } +} + +// Common Configuration +$Configuration +{ + $Compiler + { + $AdditionalIncludeDirectories "$BASE;$SRCDIR\dx10sdk\include;..\" + $PreprocessorDefinitions "$BASE;SHADERAPIDX10;SHADER_DLL_EXPORT;PROTECTED_THINGS_ENABLE;strncpy=use_Q_strncpy_instead;_snprintf=use_Q_snprintf_instead" + $PreprocessorDefinitions "$BASE;USE_ACTUAL_DX" [$WIN32] + +// $AdditionalOptions "/FC" + } +} + +$Project "shaderapidx10" +{ + $Folder "Source Files" + { + // Shared riles + $File "cvballoctracker.cpp" + $File "shaderdevicebase.cpp" + $File "shaderapibase.cpp" + $File "meshbase.cpp" + + // DX10 related files + $File "ShaderDeviceDx10.cpp" \ + "ShaderAPIDx10.cpp" \ + "MeshDx10.cpp" \ + "InputLayoutDx10.cpp" \ + "ShaderShadowDx10.cpp" + { + $Configuration + { + $Compiler + { + $PreprocessorDefinitions "$BASE;DX10" + } + } + } + + // DX9 related files + $File "ColorFormatDX8.cpp" + $File "d3d_async.cpp" + $File "$SRCDIR\public\filesystem_helpers.cpp" + $File "HardwareConfig.cpp" + $File "MeshDX8.cpp" + $File "Recording.cpp" + $File "ShaderAPIDX8.cpp" + $File "ShaderDeviceDX8.cpp" + $File "ShaderShadowDX8.cpp" + $File "TextureDX8.cpp" + $File "TransitionTable.cpp" + $File "vertexdecl.cpp" + $File "VertexShaderDX8.cpp" + $File "wmi.cpp" + } + + $Folder "DirectX Header Files" + { + $File "$SRCDIR\dx10sdk\include\d3d10.h" + $File "$SRCDIR\dx10sdk\include\d3dx10.h" + $File "$SRCDIR\dx10sdk\include\d3dx10core.h" + $File "$SRCDIR\dx10sdk\include\d3dx10math.h" + $File "$SRCDIR\dx10sdk\include\d3dx10math.inl" + $File "$SRCDIR\dx10sdk\include\d3dx10mesh.h" + $File "$SRCDIR\dx10sdk\include\d3dx10tex.h" + } + + $Folder "Public Header Files" + { + $File "$SRCDIR\public\shaderapi\ishaderdevice.h" + $File "$SRCDIR\public\shaderapi\ishaderutil.h" + $File "$SRCDIR\public\shaderapi\ishaderapi.h" + $File "$SRCDIR\public\shaderapi\ishaderdynamic.h" + $File "$SRCDIR\public\shaderapi\ishadershadow.h" + $File "$SRCDIR\public\materialsystem\idebugtextureinfo.h" + $File "$SRCDIR\public\materialsystem\ivballoctracker.h" + $File "$SRCDIR\public\materialsystem\shader_vcs_version.h" + } + + $Folder "Header Files" + { + // Shared files + $File "meshbase.h" + $File "shaderdevicebase.h" + $File "shaderapibase.h" + $File "shaderapi_global.h" + $File "HardwareConfig.h" + + // DX10 related files + $File "ShaderDeviceDx10.h" + $File "ShaderAPIDx10.h" + $File "MeshDx10.h" + $File "ShaderShadowDx10.h" + $File "shaderapidx10_global.h" + $File "inputlayoutdx10.h" + + // DX9 related files + $File "TransitionTable.h" + $File "vertexdecl.h" + $File "ColorFormatDX8.h" + $File "d3d_async.h" + $File "dynamicib.h" + $File "dynamicvb.h" + $File "IMeshDX8.h" + $File "locald3dtypes.h" + $File "Recording.h" + $File "ShaderAPIDX8.h" + $File "ShaderAPIDX8_Global.h" + $File "ShaderShadowDX8.h" + $File "stubd3ddevice.h" + $File "TextureDX8.h" + $File "VertexShaderDX8.h" + $File "wmi.h" + } + + $Folder "Link Libraries" + { + $DynamicFile "$SRCDIR\lib\public\tier2.lib" + $DynamicFile "$SRCDIR\lib\public\bitmap.lib" + $DynamicFile "$SRCDIR\lib\public\mathlib.lib" + $DynamicFile "$SRCDIR\lib\common\vc7\bzip2.lib" + + $File "$SRCDIR\dx10sdk\lib\x86\d3d9.lib" + $File "$SRCDIR\dx10sdk\lib\x86\d3d10.lib" + $File "$SRCDIR\dx10sdk\lib\x86\dxgi.lib" + + $File "$SRCDIR\dx10sdk\lib\x86\d3dx10.lib" \ + "$SRCDIR\dx10sdk\lib\x86\d3dx9.lib" + { + $Configuration "Debug" + { + $ExcludedFromBuild "Yes" + } + } + + $File "$SRCDIR\dx10sdk\lib\x86\d3dx10d.lib" \ + "$SRCDIR\dx10sdk\lib\x86\d3dx9d.lib" + { + $Configuration "Release" + { + $ExcludedFromBuild "Yes" + } + } + } +} diff --git a/materialsystem/shaderapidx9/shaderapidx10_global.h b/materialsystem/shaderapidx9/shaderapidx10_global.h new file mode 100644 index 0000000..62416b4 --- /dev/null +++ b/materialsystem/shaderapidx9/shaderapidx10_global.h @@ -0,0 +1,19 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +// +//===========================================================================// + +#ifndef SHADERAPIDX10_GLOBAL_H +#define SHADERAPIDX10_GLOBAL_H + +#ifdef _WIN32 +#pragma once +#endif + +#include "shaderapi_global.h" + + +#endif // SHADERAPIDX10_GLOBAL_H diff --git a/materialsystem/shaderapidx9/shaderapidx8.cpp b/materialsystem/shaderapidx9/shaderapidx8.cpp new file mode 100644 index 0000000..6aa025c --- /dev/null +++ b/materialsystem/shaderapidx9/shaderapidx8.cpp @@ -0,0 +1,14354 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// +// The dx8 implementation of the shader API +//===========================================================================// + +/* +DX9 todo: +-make the transforms in the older shaders match the transforms in lightmappedgeneric +-fix polyoffset for hardware that doesn't support D3DRS_SLOPESCALEDEPTHBIAS and D3DRS_DEPTHBIAS + - code is there, I think matrix offset just needs tweaking +-fix forcehardwaresync - implement texture locking for hardware that doesn't support async query +-get the format for GetAdapterModeCount and EnumAdapterModes from somewhere (shaderapidx8.cpp, GetModeCount, GetModeInfo) +-record frame sync objects (allocframesyncobjects, free framesync objects, ForceHardwareSync) +-Need to fix ENVMAPMASKSCALE, BUMPOFFSET in lightmappedgeneric*.cpp and vertexlitgeneric*.cpp +fix this: + // FIXME: This also depends on the vertex format and whether or not we are static lit in dx9 + #ifndef SHADERAPIDX9 + if (m_DynamicState.m_VertexShader != shader) // garymcthack + #endif // !SHADERAPIDX9 +unrelated to dx9: +mat_fullbright 1 doesn't work properly on alpha materials in testroom_standards +*/ +#define DISABLE_PROTECTED_THINGS +#include "shaderapidx8.h" +#include "shaderapidx8_global.h" +#include "shadershadowdx8.h" +#include "locald3dtypes.h" +#include "utlvector.h" +#include "IHardwareConfigInternal.h" +#include "utlstack.h" +#include "shaderapi/ishaderutil.h" +#include "shaderapi/commandbuffer.h" +#include "shaderapidx8_global.h" +#include "materialsystem/imaterialsystem.h" +#include "materialsystem/itexture.h" +#include "imaterialinternal.h" +#include "imeshdx8.h" +#include "materialsystem/imorph.h" +#include "colorformatdx8.h" +#include "texturedx8.h" +#include "textureheap.h" +#include +#include "interface.h" +#include "utlrbtree.h" +#include "utlsymbol.h" +#include "tier1/strtools.h" +#include "recording.h" +#ifndef _X360 +#include +#endif +#include "vertexshaderdx8.h" +#include "filesystem.h" +#include "mathlib/mathlib.h" +#include "materialsystem/materialsystem_config.h" +#include "worldsize.h" +#include "TransitionTable.h" +#include "tier0/vcrmode.h" +#include "tier0/vprof.h" +#include "tier1/tier1.h" +#include "tier1/utlbuffer.h" +#include "vertexdecl.h" +#include "tier0/icommandline.h" +#include "IShaderSystem.h" +#include "tier1/convar.h" +#include "tier1/KeyValues.h" +#include "Color.h" +#ifdef RECORDING +#include "materialsystem/IShader.h" +#endif +#include "../stdshaders/common_hlsl_cpp_consts.h" // hack hack hack! +#include "KeyValues.h" +#include "bitmap/imageformat.h" +#include "materialsystem/idebugtextureinfo.h" +#include "tier1/utllinkedlist.h" +#include "vtf/vtf.h" +#include "datacache/idatacache.h" +#include "renderparm.h" +#include "tier2/tier2.h" +#include "materialsystem/deformations.h" +#include "bitmap/tgawriter.h" +#include "tier0/icommandline.h" +#include "togl/rendermechanism.h" // provides GLMPRINTF/GLMPRINTSTR / GLMPRINTEXT macros which only activate if GLMDEBUG is nonzero and POSIX is defined. + +#if defined( _X360 ) +#include "xbox/xbox_console.h" +#include "xbox/xbox_win32stubs.h" +#include "xbox/xbox_launch.h" +#endif +#include "tier0/tslist.h" +#ifndef _X360 +#include "wmi.h" +#endif +#include "filesystem/IQueuedLoader.h" +#include "shaderdevicedx8.h" +#include "togl/rendermechanism.h" + +// Define this if you want to use a stubbed d3d. +//#define STUBD3D + +#ifdef STUBD3D +#include "stubd3ddevice.h" +#endif + +#include "winutils.h" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +#if defined( OSX ) + typedef unsigned int DWORD; + typedef DWORD* LPDWORD; +#endif + +#ifdef _WIN32 +#pragma warning (disable:4189) +#endif + +ConVar mat_texture_limit( "mat_texture_limit", "-1", FCVAR_NEVER_AS_STRING, + "If this value is not -1, the material system will limit the amount of texture memory it uses in a frame." + " Useful for identifying performance cliffs. The value is in kilobytes." ); + +ConVar mat_frame_sync_enable( "mat_frame_sync_enable", "1", FCVAR_CHEAT ); +ConVar mat_frame_sync_force_texture( "mat_frame_sync_force_texture", "0", FCVAR_CHEAT, "Force frame syncing to lock a managed texture." ); + + +#if defined( _X360 ) +ConVar mat_texturecachesize( "mat_texturecachesize", "176" ); +ConVar mat_force_flush_texturecache( "mat_force_flush_texturecache", "0" ); +#endif + +extern ConVar mat_debugalttab; + +#define ALLOW_SMP_ACCESS 0 + +#if ALLOW_SMP_ACCESS +static ConVar mat_use_smp( "mat_use_smp", "0" ); +#endif + +// Convars for driving PIX (not all hooked up yet...JasonM) +static ConVar r_pix_start( "r_pix_start", "0" ); +static ConVar r_pix_recordframes( "r_pix_recordframes", "0" ); + + +#define D3DDeviceWrapper IDirect3DDevice9 + +//----------------------------------------------------------------------------- +// Some important enumerations +//----------------------------------------------------------------------------- +enum +{ + MAX_VERTEX_TEXTURE_COUNT = 4, +}; + + +//----------------------------------------------------------------------------- +// These board states change with high frequency; are not shadowed +//----------------------------------------------------------------------------- +struct TextureStageState_t +{ + D3DTEXTURETRANSFORMFLAGS m_TextureTransformFlags; + float m_BumpEnvMat00; + float m_BumpEnvMat01; + float m_BumpEnvMat10; + float m_BumpEnvMat11; +}; + +struct SamplerState_t +{ + ShaderAPITextureHandle_t m_BoundTexture; + D3DTEXTUREADDRESS m_UTexWrap; + D3DTEXTUREADDRESS m_VTexWrap; + D3DTEXTUREADDRESS m_WTexWrap; + D3DTEXTUREFILTERTYPE m_MagFilter; + D3DTEXTUREFILTERTYPE m_MinFilter; + D3DTEXTUREFILTERTYPE m_MipFilter; + int m_FinestMipmapLevel; + float m_LodBias; + int m_nAnisotropicLevel; + bool m_TextureEnable; + bool m_SRGBReadEnable; +}; + + +//----------------------------------------------------------------------------- +// State related to vertex textures +//----------------------------------------------------------------------------- +struct VertexTextureState_t +{ + ShaderAPITextureHandle_t m_BoundTexture; + D3DTEXTUREADDRESS m_UTexWrap; + D3DTEXTUREADDRESS m_VTexWrap; + D3DTEXTUREFILTERTYPE m_MagFilter; + D3DTEXTUREFILTERTYPE m_MinFilter; + D3DTEXTUREFILTERTYPE m_MipFilter; +}; + + +enum TransformType_t +{ + TRANSFORM_IS_IDENTITY = 0, + TRANSFORM_IS_CAMERA_TO_WORLD, + TRANSFORM_IS_GENERAL, +}; + +enum TransformDirtyBits_t +{ + STATE_CHANGED_VERTEX_SHADER = 0x1, + STATE_CHANGED_FIXED_FUNCTION = 0x2, + STATE_CHANGED = 0x3 +}; + +enum +{ +#if !defined( _X360 ) + MAX_NUM_RENDERSTATES = ( D3DRS_BLENDOPALPHA+1 ), +#else + MAX_NUM_RENDERSTATES = D3DRS_MAX, +#endif +// MORPH_TARGET_FACTOR_COUNT = VERTEX_SHADER_MORPH_TARGET_FACTOR_COUNT * 4, +}; + +struct DynamicState_t +{ + // Constant color + unsigned int m_ConstantColor; + + // Normalize normals? + bool m_NormalizeNormals; + + // Viewport state + D3DVIEWPORT9 m_Viewport; + + // Transform state + D3DXMATRIX m_Transform[NUM_MATRIX_MODES]; + unsigned char m_TransformType[NUM_MATRIX_MODES]; + unsigned char m_TransformChanged[NUM_MATRIX_MODES]; + + // Ambient light color + D3DCOLOR m_Ambient; + D3DLIGHT m_Lights[MAX_NUM_LIGHTS]; + LightDesc_t m_LightDescs[MAX_NUM_LIGHTS]; + bool m_LightEnable[MAX_NUM_LIGHTS]; + Vector4D m_AmbientLightCube[6]; + unsigned char m_LightChanged[MAX_NUM_LIGHTS]; + unsigned char m_LightEnableChanged[MAX_NUM_LIGHTS]; + VertexShaderLightTypes_t m_LightType[MAX_NUM_LIGHTS]; + Vector m_vLightingOrigin; + int m_NumLights; + + // Shade mode + D3DSHADEMODE m_ShadeMode; + + // Clear color + D3DCOLOR m_ClearColor; + + // Fog + D3DCOLOR m_FogColor; + float m_PixelFogColor[4]; + bool m_bFogGammaCorrectionDisabled; + bool m_FogEnable; + MaterialFogMode_t m_SceneFog; + D3DFOGMODE m_FogMode; + float m_FogStart; + float m_FogEnd; + float m_FogZ; + float m_FogMaxDensity; + + float m_HeightClipZ; + MaterialHeightClipMode_t m_HeightClipMode; + + // user clip planes + int m_UserClipPlaneEnabled; + int m_UserClipPlaneChanged; + D3DXPLANE m_UserClipPlaneWorld[MAXUSERCLIPPLANES]; + D3DXPLANE m_UserClipPlaneProj[MAXUSERCLIPPLANES]; + bool m_UserClipLastUpdatedUsingFixedFunction; + + bool m_FastClipEnabled; + bool m_bFastClipPlaneChanged; + D3DXPLANE m_FastClipPlane; + + // Used when overriding the user clip plane + bool m_bUserClipTransformOverride; + D3DXMATRIX m_UserClipTransform; + + // Cull mode + D3DCULL m_DesiredCullMode; + D3DCULL m_CullMode; + bool m_bCullEnabled; + + // Skinning + D3DVERTEXBLENDFLAGS m_VertexBlend; + int m_NumBones; + + // Pixel and vertex shader constants... + Vector4D* m_pVectorVertexShaderConstant; + BOOL* m_pBooleanVertexShaderConstant; + IntVector4D* m_pIntegerVertexShaderConstant; + Vector4D* m_pVectorPixelShaderConstant; + BOOL* m_pBooleanPixelShaderConstant; + IntVector4D* m_pIntegerPixelShaderConstant; + + // Texture stage state + TextureStageState_t m_TextureStage[MAX_TEXTURE_STAGES]; + SamplerState_t m_SamplerState[MAX_SAMPLERS]; + + // Vertex texture stage state + VertexTextureState_t m_VertexTextureState[MAX_VERTEX_TEXTURE_COUNT]; + + DWORD m_RenderState[MAX_NUM_RENDERSTATES]; + + RECT m_ScissorRect; + + IDirect3DVertexDeclaration9 *m_pVertexDecl; + + bool m_bSRGBWritesEnabled; + bool m_bHWMorphingEnabled; + + float m_DestAlphaDepthRange; //Dest alpha writes compress the depth to get better results. This holds the default setting that can be overriden with r_destalpharange + +#if defined( _X360 ) + int m_iVertexShaderGPRAllocation; //only need to track vertex shader + bool m_bBuffer2Frames; +#endif + + DynamicState_t() {} + +private: + DynamicState_t( DynamicState_t const& ); +}; + +//----------------------------------------------------------------------------- +// Method to queue up dirty dynamic state change calls +//----------------------------------------------------------------------------- +typedef void (*StateCommitFunc_t)( IDirect3DDevice9 *pDevice, const DynamicState_t &desiredState, DynamicState_t ¤tState, bool bForce ); +static void CommitSetViewports( IDirect3DDevice9 *pDevice, const DynamicState_t &desiredState, DynamicState_t ¤tState, bool bForce ); + +// NOTE: It's slightly memory inefficient, and definitely not typesafe, +// to put all commit funcs into the same table (vs, ff, per-draw, per-pass), +// but it makes the code a heck of a lot simpler and smaller. +enum CommitFunc_t +{ + COMMIT_FUNC_CommitVertexTextures = 0, + COMMIT_FUNC_CommitFlexWeights, + COMMIT_FUNC_CommitSetScissorRect, + COMMIT_FUNC_CommitSetViewports, + +#if defined( _X360 ) + COMMIT_FUNC_CommitShaderGPRs, +#endif + + COMMIT_FUNC_COUNT, + COMMIT_FUNC_BYTE_COUNT = ( COMMIT_FUNC_COUNT + 0x7 ) >> 3, +}; + +enum CommitFuncType_t +{ + COMMIT_PER_DRAW = 0, + COMMIT_PER_PASS, + + COMMIT_FUNC_TYPE_COUNT, +}; + +enum CommitShaderType_t +{ + COMMIT_FIXED_FUNCTION = 0, + COMMIT_VERTEX_SHADER, + COMMIT_ALWAYS, + + COMMIT_SHADER_TYPE_COUNT, +}; + + +#define ADD_COMMIT_FUNC( _func, _shader, _func_name ) \ + if ( !IsCommitFuncInUse( _func, _shader, COMMIT_FUNC_ ## _func_name ) ) \ + { \ + AddCommitFunc( _func, _shader, _func_name ); \ + MarkCommitFuncInUse( _func, _shader, COMMIT_FUNC_ ## _func_name ); \ + } + +#define ADD_RENDERSTATE_FUNC( _func, _shader, _func_name, _state, _val ) \ + if ( m_bResettingRenderState || (m_DesiredState._state != _val) ) \ + { \ + m_DesiredState._state = _val; \ + ADD_COMMIT_FUNC( _func, _shader, _func_name ) \ + } + +#define ADD_VERTEX_TEXTURE_FUNC( _func, _shader, _func_name, _stage, _state, _val ) \ + Assert( ( int )_stage < MAX_VERTEX_TEXTURE_COUNT ); \ + if ( m_bResettingRenderState || (m_DesiredState.m_VertexTextureState[_stage]._state != _val) ) \ + { \ + m_DesiredState.m_VertexTextureState[_stage]._state = _val; \ + ADD_COMMIT_FUNC( _func, _shader, _func_name ) \ + } + + +//----------------------------------------------------------------------------- +// Check render state support at compile time instead of runtime +//----------------------------------------------------------------------------- +#define SetSupportedRenderState( _state, _val ) \ + { \ + if( _state != D3DRS_NOTSUPPORTED ) \ + { \ + SetRenderState( _state, _val, false ); \ + } \ + } + +#define SetSupportedRenderStateForce( _state, _val ) \ + { \ + if( _state != D3DRS_NOTSUPPORTED ) \ + { \ + SetRenderStateForce( _state, _val ); \ + } \ + } + +//----------------------------------------------------------------------------- +// Allocated textures +//----------------------------------------------------------------------------- +struct Texture_t +{ + Texture_t() + { + m_Flags = 0; + m_Count = 1; + m_CountIndex = 0; + m_nTimesBoundMax = 0; + m_nTimesBoundThisFrame = 0; + m_pTexture = NULL; + m_ppTexture = NULL; + m_ImageFormat = IMAGE_FORMAT_RGBA8888; + m_pTextureGroupCounterGlobal = NULL; + m_pTextureGroupCounterFrame = NULL; + m_FinestMipmapLevel = 0; + m_LodBias = 0.0f; + } + + // FIXME: Compress this info + D3DTEXTUREADDRESS m_UTexWrap; + D3DTEXTUREADDRESS m_VTexWrap; + D3DTEXTUREADDRESS m_WTexWrap; + D3DTEXTUREFILTERTYPE m_MagFilter; + D3DTEXTUREFILTERTYPE m_MinFilter; + D3DTEXTUREFILTERTYPE m_MipFilter; + int m_FinestMipmapLevel; + float m_LodBias; + + unsigned char m_NumLevels; + unsigned char m_SwitchNeeded; // Do we need to advance the current copy? + unsigned char m_NumCopies; // copies are used to optimize procedural textures + unsigned char m_CurrentCopy; // the current copy we're using... + + int m_CreationFlags; + + CUtlSymbol m_DebugName; + CUtlSymbol m_TextureGroupName; + int *m_pTextureGroupCounterGlobal; // Global counter for this texture's group. + int *m_pTextureGroupCounterFrame; // Per-frame global counter for this texture's group. + + // stats stuff + int m_SizeBytes; + int m_SizeTexels; + int m_LastBoundFrame; + int m_nTimesBoundMax; + int m_nTimesBoundThisFrame; + + enum Flags_t + { + IS_ALLOCATED = 0x0001, + IS_DEPTH_STENCIL = 0x0002, + IS_DEPTH_STENCIL_TEXTURE = 0x0004, // depth stencil texture, not surface + IS_RENDERABLE = ( IS_DEPTH_STENCIL | IS_ALLOCATED ), + IS_LOCKABLE = 0x0008, + IS_FINALIZED = 0x0010, // 360: completed async hi-res load + IS_FAILED = 0x0020, // 360: failed during load + CAN_CONVERT_FORMAT = 0x0040, // 360: allow format conversion + IS_LINEAR = 0x0080, // 360: unswizzled linear format + IS_RENDER_TARGET = 0x0100, // 360: marks a render target texture source + IS_RENDER_TARGET_SURFACE = 0x0200, // 360: marks a render target surface target + IS_VERTEX_TEXTURE = 0x0800, + }; + + short m_Width; + short m_Height; + short m_Depth; + unsigned short m_Flags; + + typedef IDirect3DBaseTexture *IDirect3DBaseTexturePtr; + typedef IDirect3DBaseTexture **IDirect3DBaseTexturePtrPtr; + typedef IDirect3DSurface *IDirect3DSurfacePtr; + + IDirect3DBaseTexturePtr GetTexture( void ) + { + Assert( m_NumCopies == 1 ); + Assert( !( m_Flags & IS_DEPTH_STENCIL ) ); + return m_pTexture; + } + IDirect3DBaseTexturePtr GetTexture( int copy ) + { + Assert( m_NumCopies > 1 ); + Assert( !( m_Flags & IS_DEPTH_STENCIL ) ); + return m_ppTexture[copy]; + } + IDirect3DBaseTexturePtrPtr &GetTextureArray( void ) + { + Assert( m_NumCopies > 1 ); + Assert( !( m_Flags & IS_DEPTH_STENCIL ) ); + return m_ppTexture; + } + + IDirect3DSurfacePtr &GetDepthStencilSurface( void ) + { + Assert( m_NumCopies == 1 ); + Assert( (m_Flags & IS_DEPTH_STENCIL) ); + return m_pDepthStencilSurface; + } + + IDirect3DSurfacePtr &GetRenderTargetSurface( bool bSRGB ) + { + Assert( m_NumCopies == 1 ); + Assert( m_Flags & IS_RENDER_TARGET_SURFACE ); + return m_pRenderTargetSurface[bSRGB]; + } + + void SetTexture( IDirect3DBaseTexturePtr pPtr ) + { + m_pTexture = pPtr; + } + void SetTexture( int copy, IDirect3DBaseTexturePtr pPtr ) + { + m_ppTexture[copy] = pPtr; + } + + int GetMemUsage() const + { + return m_SizeBytes; + } + + int GetWidth() const + { + return ( int )m_Width; + } + + int GetHeight() const + { + return ( int )m_Height; + } + + int GetDepth() const + { + return ( int )m_Depth; + } + + int GetLodClamp() const + { + return m_FinestMipmapLevel; + } + + void SetImageFormat( ImageFormat format ) + { + m_ImageFormat = format; + } + ImageFormat GetImageFormat() const + { + return m_ImageFormat; + } + +private: + union + { + IDirect3DBaseTexture *m_pTexture; // used when there's one copy + IDirect3DBaseTexture **m_ppTexture; // used when there are more than one copies + IDirect3DSurface *m_pDepthStencilSurface; // used when there's one depth stencil surface + IDirect3DSurface *m_pRenderTargetSurface[2]; + }; + + ImageFormat m_ImageFormat; + +public: + short m_Count; + short m_CountIndex; + + short GetCount() const + { + return m_Count; + } +}; + +#define MAX_DEFORMATION_PARAMETERS 16 +#define DEFORMATION_STACK_DEPTH 10 + +struct Deformation_t +{ + int m_nDeformationType; + int m_nNumParameters; + float m_flDeformationParameters[MAX_DEFORMATION_PARAMETERS]; +}; + + +//----------------------------------------------------------------------------- +// The DX8 implementation of the shader API +//----------------------------------------------------------------------------- +class CShaderAPIDx8 : public CShaderDeviceDx8, public IShaderAPIDX8, public IDebugTextureInfo +{ + typedef CShaderDeviceDx8 BaseClass; + +public: + // constructor, destructor + CShaderAPIDx8( ); + virtual ~CShaderAPIDx8(); + + // Methods of IShaderAPI +public: + virtual void SetViewports( int nCount, const ShaderViewport_t* pViewports ); + virtual int GetViewports( ShaderViewport_t* pViewports, int nMax ) const; + virtual void ClearBuffers( bool bClearColor, bool bClearDepth, bool bClearStencil, int renderTargetWidth, int renderTargetHeight ); + virtual void ClearColor3ub( unsigned char r, unsigned char g, unsigned char b ); + virtual void ClearColor4ub( unsigned char r, unsigned char g, unsigned char b, unsigned char a ); + virtual void BindVertexShader( VertexShaderHandle_t hVertexShader ); + virtual void BindGeometryShader( GeometryShaderHandle_t hGeometryShader ); + virtual void BindPixelShader( PixelShaderHandle_t hPixelShader ); + virtual void SetRasterState( const ShaderRasterState_t& state ); + virtual void SetFlexWeights( int nFirstWeight, int nCount, const MorphWeight_t* pWeights ); + + // Methods of IShaderDynamicAPI +public: + virtual void GetBackBufferDimensions( int &nWidth, int &nHeight ) const + { + // Chain to the device + BaseClass::GetBackBufferDimensions( nWidth, nHeight ); + } + virtual void MarkUnusedVertexFields( unsigned int nFlags, int nTexCoordCount, bool *pUnusedTexCoords ); + +public: + // Methods of CShaderAPIBase + virtual bool OnDeviceInit(); + virtual void OnDeviceShutdown(); + virtual void ReleaseShaderObjects(); + virtual void RestoreShaderObjects(); + virtual void BeginPIXEvent( unsigned long color, const char *szName ); + virtual void EndPIXEvent(); + virtual void AdvancePIXFrame(); + +public: + // Methods of IShaderAPIDX8 + virtual void QueueResetRenderState(); + + // + // Abandon all hope ye who pass below this line which hasn't been ported. + // + + // Sets the mode... + bool SetMode( void* VD3DHWND, int nAdapter, const ShaderDeviceInfo_t &info ); + + // Change the video mode after it's already been set. + void ChangeVideoMode( const ShaderDeviceInfo_t &info ); + + // Sets the default render state + void SetDefaultState(); + + // Methods to ask about particular state snapshots + virtual bool IsTranslucent( StateSnapshot_t id ) const; + virtual bool IsAlphaTested( StateSnapshot_t id ) const; + virtual bool UsesVertexAndPixelShaders( StateSnapshot_t id ) const; + virtual int CompareSnapshots( StateSnapshot_t snapshot0, StateSnapshot_t snapshot1 ); + + // Computes the vertex format for a particular set of snapshot ids + VertexFormat_t ComputeVertexFormat( int num, StateSnapshot_t* pIds ) const; + VertexFormat_t ComputeVertexUsage( int num, StateSnapshot_t* pIds ) const; + + // What fields in the morph do we actually use? + virtual MorphFormat_t ComputeMorphFormat( int numSnapshots, StateSnapshot_t* pIds ) const; + + // Uses a state snapshot + void UseSnapshot( StateSnapshot_t snapshot ); + + // Color state + void Color3f( float r, float g, float b ); + void Color4f( float r, float g, float b, float a ); + void Color3fv( float const* c ); + void Color4fv( float const* c ); + + void Color3ub( unsigned char r, unsigned char g, unsigned char b ); + void Color3ubv( unsigned char const* pColor ); + void Color4ub( unsigned char r, unsigned char g, unsigned char b, unsigned char a ); + void Color4ubv( unsigned char const* pColor ); + + // Set the number of bone weights + virtual void SetNumBoneWeights( int numBones ); + virtual void EnableHWMorphing( bool bEnable ); + + // Sets the vertex and pixel shaders + virtual void SetVertexShaderIndex( int vshIndex = -1 ); + virtual void SetPixelShaderIndex( int pshIndex = 0 ); + + // Matrix state + void MatrixMode( MaterialMatrixMode_t matrixMode ); + void PushMatrix(); + void PopMatrix(); + void LoadMatrix( float *m ); + void LoadBoneMatrix( int boneIndex, const float *m ); + void MultMatrix( float *m ); + void MultMatrixLocal( float *m ); + void GetMatrix( MaterialMatrixMode_t matrixMode, float *dst ); + void LoadIdentity( void ); + void LoadCameraToWorld( void ); + void Ortho( double left, double top, double right, double bottom, double zNear, double zFar ); + void PerspectiveX( double fovx, double aspect, double zNear, double zFar ); + void PerspectiveOffCenterX( double fovx, double aspect, double zNear, double zFar, double bottom, double top, double left, double right ); + void PickMatrix( int x, int y, int width, int height ); + void Rotate( float angle, float x, float y, float z ); + void Translate( float x, float y, float z ); + void Scale( float x, float y, float z ); + void ScaleXY( float x, float y ); + + // Binds a particular material to render with + void Bind( IMaterial* pMaterial ); + IMaterialInternal* GetBoundMaterial(); + + // Level of anisotropic filtering + virtual void SetAnisotropicLevel( int nAnisotropyLevel ); + + virtual void SyncToken( const char *pToken ); + + // Cull mode + void CullMode( MaterialCullMode_t cullMode ); + + // Force writes only when z matches. . . useful for stenciling things out + // by rendering the desired Z values ahead of time. + void ForceDepthFuncEquals( bool bEnable ); + + // Turns off Z buffering + void OverrideDepthEnable( bool bEnable, bool bDepthEnable ); + + void OverrideAlphaWriteEnable( bool bOverrideEnable, bool bAlphaWriteEnable ); + void OverrideColorWriteEnable( bool bOverrideEnable, bool bColorWriteEnable ); + + void SetHeightClipZ( float z ); + void SetHeightClipMode( enum MaterialHeightClipMode_t heightClipMode ); + + void SetClipPlane( int index, const float *pPlane ); + void EnableClipPlane( int index, bool bEnable ); + + void SetFastClipPlane(const float *pPlane); + void EnableFastClip(bool bEnable); + + // The shade mode + void ShadeMode( ShaderShadeMode_t mode ); + + // Vertex blend state + void SetVertexBlendState( int numBones ); + + // Gets the dynamic mesh + IMesh* GetDynamicMesh( IMaterial* pMaterial, int nHWSkinBoneCount, bool buffered, + IMesh* pVertexOverride, IMesh* pIndexOverride ); + IMesh* GetDynamicMeshEx( IMaterial* pMaterial, VertexFormat_t vertexFormat, int nHWSkinBoneCount, + bool bBuffered, IMesh* pVertexOverride, IMesh* pIndexOverride ); + IMesh *GetFlexMesh(); + + // Returns the number of vertices we can render using the dynamic mesh + virtual void GetMaxToRender( IMesh *pMesh, bool bMaxUntilFlush, int *pMaxVerts, int *pMaxIndices ); + virtual int GetMaxVerticesToRender( IMaterial *pMaterial ); + virtual int GetMaxIndicesToRender( ); + + // Draws the mesh + void DrawMesh( CMeshBase* mesh ); + + // modifies the vertex data when necessary + void ModifyVertexData( ); + + // Draws + void BeginPass( StateSnapshot_t snapshot ); + void RenderPass( int nPass, int nPassCount ); + + // We use smaller dynamic VBs during level transitions, to free up memory + virtual int GetCurrentDynamicVBSize( void ); + virtual void DestroyVertexBuffers( bool bExitingLevel = false ); + + void SetVertexDecl( VertexFormat_t vertexFormat, bool bHasColorMesh, bool bUsingFlex, bool bUsingMorph ); + + // Sets the constant register for vertex and pixel shaders + FORCEINLINE void SetVertexShaderConstantInternal( int var, float const* pVec, int numVecs = 1, bool bForce = false ); + + void SetVertexShaderConstant( int var, float const* pVec, int numVecs = 1, bool bForce = false ); + void SetBooleanVertexShaderConstant( int var, BOOL const* pVec, int numBools = 1, bool bForce = false ); + void SetIntegerVertexShaderConstant( int var, int const* pVec, int numIntVecs = 1, bool bForce = false ); + + void SetPixelShaderConstant( int var, float const* pVec, int numVecs = 1, bool bForce = false ); + FORCEINLINE void SetPixelShaderConstantInternal( int var, float const* pValues, int nNumConsts, bool bForce ); + + void SetBooleanPixelShaderConstant( int var, BOOL const* pVec, int numBools = 1, bool bForce = false ); + void SetIntegerPixelShaderConstant( int var, int const* pVec, int numIntVecs = 1, bool bForce = false ); + + void InvalidateDelayedShaderConstants( void ); + + // Returns the nearest supported format + ImageFormat GetNearestSupportedFormat( ImageFormat fmt, bool bFilteringRequired = true ) const; + ImageFormat GetNearestRenderTargetFormat( ImageFormat format ) const; + virtual bool DoRenderTargetsNeedSeparateDepthBuffer() const; + + // stuff that shouldn't be used from within a shader + void ModifyTexture( ShaderAPITextureHandle_t textureHandle ); + void BindTexture( Sampler_t sampler, ShaderAPITextureHandle_t textureHandle ); + virtual void BindVertexTexture( VertexTextureSampler_t nStage, ShaderAPITextureHandle_t textureHandle ); + void DeleteTexture( ShaderAPITextureHandle_t textureHandle ); + + void WriteTextureToFile( ShaderAPITextureHandle_t hTexture, const char *szFileName ); + + bool IsTexture( ShaderAPITextureHandle_t textureHandle ); + bool IsTextureResident( ShaderAPITextureHandle_t textureHandle ); + FORCEINLINE bool TextureIsAllocated( ShaderAPITextureHandle_t hTexture ) + { + return m_Textures.IsValidIndex( hTexture ) && ( GetTexture( hTexture ).m_Flags & Texture_t::IS_ALLOCATED ); + } + FORCEINLINE void AssertValidTextureHandle( ShaderAPITextureHandle_t textureHandle ) + { +#ifdef _DEBUG + Assert( TextureIsAllocated( textureHandle ) ); +#endif + } + + // Lets the shader know about the full-screen texture so it can + virtual void SetFullScreenTextureHandle( ShaderAPITextureHandle_t h ); + + virtual void SetLinearToGammaConversionTextures( ShaderAPITextureHandle_t hSRGBWriteEnabledTexture, ShaderAPITextureHandle_t hIdentityTexture ); + + // Set the render target to a texID. + // Set to SHADER_RENDERTARGET_BACKBUFFER if you want to use the regular framebuffer. + void SetRenderTarget( ShaderAPITextureHandle_t colorTextureHandle = SHADER_RENDERTARGET_BACKBUFFER, + ShaderAPITextureHandle_t depthTextureHandle = SHADER_RENDERTARGET_DEPTHBUFFER ); + // Set the render target to a texID. + // Set to SHADER_RENDERTARGET_BACKBUFFER if you want to use the regular framebuffer. + void SetRenderTargetEx( int nRenderTargetID, ShaderAPITextureHandle_t colorTextureHandle = SHADER_RENDERTARGET_BACKBUFFER, + ShaderAPITextureHandle_t depthTextureHandle = SHADER_RENDERTARGET_DEPTHBUFFER ); + + // These are bound to the texture, not the texture environment + void TexMinFilter( ShaderTexFilterMode_t texFilterMode ); + void TexMagFilter( ShaderTexFilterMode_t texFilterMode ); + void TexWrap( ShaderTexCoordComponent_t coord, ShaderTexWrapMode_t wrapMode ); + void TexSetPriority( int priority ); + void TexLodClamp( int finest ); + void TexLodBias( float bias ); + + ShaderAPITextureHandle_t CreateTextureHandle( void ); + void CreateTextureHandles( ShaderAPITextureHandle_t *handles, int count ); + + ShaderAPITextureHandle_t CreateTexture( + int width, + int height, + int depth, + ImageFormat dstImageFormat, + int numMipLevels, + int numCopies, + int creationFlags, + const char *pDebugName, + const char *pTextureGroupName ); + + // Create a multi-frame texture (equivalent to calling "CreateTexture" multiple times, but more efficient) + void CreateTextures( + ShaderAPITextureHandle_t *pHandles, + int count, + int width, + int height, + int depth, + ImageFormat dstImageFormat, + int numMipLevels, + int numCopies, + int flags, + const char *pDebugName, + const char *pTextureGroupName ); + + ShaderAPITextureHandle_t CreateDepthTexture( + ImageFormat renderTargetFormat, + int width, + int height, + const char *pDebugName, + bool bTexture ); + + void TexImage2D( + int level, + int cubeFaceID, + ImageFormat dstFormat, + int zOffset, + int width, + int height, + ImageFormat srcFormat, + bool bSrcIsTiled, + void *imageData ); + + void TexSubImage2D( + int level, + int cubeFaceID, + int xOffset, + int yOffset, + int zOffset, + int width, + int height, + ImageFormat srcFormat, + int srcStride, + bool bSrcIsTiled, + void *imageData ); + + void TexImageFromVTF( IVTFTexture *pVTF, int iVTFFrame ); + + bool TexLock( int level, int cubeFaceID, int xOffset, int yOffset, int width, int height, CPixelWriter& writer ); + void TexUnlock( ); + + // stuff that isn't to be used from within a shader + // what's the best way to hide this? subclassing? + virtual void ClearBuffersObeyStencil( bool bClearColor, bool bClearDepth ); + virtual void ClearBuffersObeyStencilEx( bool bClearColor, bool bClearAlpha, bool bClearDepth ); + virtual void PerformFullScreenStencilOperation( void ); + void ReadPixels( int x, int y, int width, int height, unsigned char *data, ImageFormat dstFormat ); + virtual void ReadPixels( Rect_t *pSrcRect, Rect_t *pDstRect, unsigned char *data, ImageFormat dstFormat, int nDstStride ); + + // Gets the current buffered state... (debug only) + void GetBufferedState( BufferedState_t& state ); + + // Buffered primitives + void FlushBufferedPrimitives(); + void FlushBufferedPrimitivesInternal( ); + + // Make sure we finish drawing everything that has been requested + void FlushHardware(); + + // Use this to begin and end the frame + void BeginFrame(); + void EndFrame(); + + // Used to clear the transition table when we know it's become invalid. + void ClearSnapshots(); + + // Backward compat + virtual int GetActualTextureStageCount() const; + virtual int GetActualSamplerCount() const; + virtual int StencilBufferBits() const; + virtual bool IsAAEnabled() const; // Is antialiasing being used? + virtual bool OnAdapterSet( ); + bool m_bAdapterSet; + + void UpdateFastClipUserClipPlane( void ); + bool ReadPixelsFromFrontBuffer() const; + + // returns the current time in seconds.... + double CurrentTime() const; + + // Get the current camera position in world space. + void GetWorldSpaceCameraPosition( float* pPos ) const; + + // Fog methods + void FogMode( MaterialFogMode_t fogMode ); + void FogStart( float fStart ); + void FogEnd( float fEnd ); + void FogMaxDensity( float flMaxDensity ); + void SetFogZ( float fogZ ); + void GetFogDistances( float *fStart, float *fEnd, float *fFogZ ); + + void SceneFogMode( MaterialFogMode_t fogMode ); + MaterialFogMode_t GetSceneFogMode( ); + MaterialFogMode_t GetPixelFogMode( ); + int GetPixelFogCombo( );//0 is either range fog, or no fog simulated with rigged range fog values. 1 is height fog + bool ShouldUsePixelFogForMode( MaterialFogMode_t fogMode ); + void SceneFogColor3ub( unsigned char r, unsigned char g, unsigned char b ); + void GetSceneFogColor( unsigned char *rgb ); + void GetSceneFogColor( unsigned char *r, unsigned char *g, unsigned char *b ); + + // Selection mode methods + int SelectionMode( bool selectionMode ); + void SelectionBuffer( unsigned int* pBuffer, int size ); + void ClearSelectionNames( ); + void LoadSelectionName( int name ); + void PushSelectionName( int name ); + void PopSelectionName(); + bool IsInSelectionMode() const; + void RegisterSelectionHit( float minz, float maxz ); + void WriteHitRecord(); + + // Binds a standard texture + virtual void BindStandardTexture( Sampler_t sampler, StandardTextureId_t id ); + virtual void BindStandardVertexTexture( VertexTextureSampler_t sampler, StandardTextureId_t id ); + virtual void GetStandardTextureDimensions( int *pWidth, int *pHeight, StandardTextureId_t id ); + + // Gets the lightmap dimensions + virtual void GetLightmapDimensions( int *w, int *h ); + + // Use this to get the mesh builder that allows us to modify vertex data + CMeshBuilder* GetVertexModifyBuilder(); + + virtual bool InFlashlightMode() const; + virtual bool InEditorMode() const; + + // Gets the bound morph's vertex format; returns 0 if no morph is bound + virtual MorphFormat_t GetBoundMorphFormat(); + + // Helper to get at the texture state stage + TextureStageState_t& TextureStage( int stage ) { return m_DynamicState.m_TextureStage[stage]; } + const TextureStageState_t& TextureStage( int stage ) const { return m_DynamicState.m_TextureStage[stage]; } + SamplerState_t& SamplerState( int nSampler ) { return m_DynamicState.m_SamplerState[nSampler]; } + const SamplerState_t& SamplerState( int nSampler ) const { return m_DynamicState.m_SamplerState[nSampler]; } + + void SetAmbientLight( float r, float g, float b ); + void SetLight( int lightNum, const LightDesc_t& desc ); + void SetLightingOrigin( Vector vLightingOrigin ); + void DisableAllLocalLights(); + void SetAmbientLightCube( Vector4D colors[6] ); + float GetAmbientLightCubeLuminance( void ); + + int GetMaxLights( void ) const; + const LightDesc_t& GetLight( int lightNum ) const; + + void SetVertexShaderStateAmbientLightCube(); + void SetPixelShaderStateAmbientLightCube( int pshReg, bool bForceToBlack = false ); + + void CopyRenderTargetToTexture( ShaderAPITextureHandle_t textureHandle ); + void CopyRenderTargetToTextureEx( ShaderAPITextureHandle_t textureHandle, int nRenderTargetID, Rect_t *pSrcRect = NULL, Rect_t *pDstRect = NULL ); + void CopyTextureToRenderTargetEx( int nRenderTargetID, ShaderAPITextureHandle_t textureHandle, Rect_t *pSrcRect = NULL, Rect_t *pDstRect = NULL ); + void CopyRenderTargetToScratchTexture( ShaderAPITextureHandle_t srcHandle, ShaderAPITextureHandle_t dstHandle, Rect_t *pSrcRect = NULL, Rect_t *pDstRect = NULL ); + + virtual void LockRect( void** pOutBits, int* pOutPitch, ShaderAPITextureHandle_t texHandle, int mipmap, int x, int y, int w, int h, bool bWrite, bool bRead ); + virtual void UnlockRect( ShaderAPITextureHandle_t texHandle, int mipmap ); + + virtual void CopyTextureToTexture( ShaderAPITextureHandle_t srcTex, ShaderAPITextureHandle_t dstTex ); + + // Returns the cull mode (for fill rate computation) + D3DCULL GetCullMode() const; + void SetCullModeState( bool bEnable, D3DCULL nDesiredCullMode ); + void ApplyCullEnable( bool bEnable ); + + // Alpha to coverage + void ApplyAlphaToCoverage( bool bEnable ); + +#if defined( _X360 ) + void ApplySRGBReadState( int iTextureStage, bool bSRGBReadEnabled ); +#endif + + // Applies Z Bias + void ApplyZBias( const ShadowState_t& shaderState ); + + // Applies texture enable + void ApplyTextureEnable( const ShadowState_t& state, int stage ); + + void ApplyFogMode( ShaderFogMode_t fogMode, bool bSRGBWritesEnabled, bool bDisableFogGammaCorrection ); + void UpdatePixelFogColorConstant( void ); + + void EnabledSRGBWrite( bool bEnabled ); + + // Gamma<->Linear conversions according to the video hardware we're running on + float GammaToLinear_HardwareSpecific( float fGamma ) const; + float LinearToGamma_HardwareSpecific( float fLinear ) const; + + // Applies alpha blending + void ApplyAlphaBlend( bool bEnable, D3DBLEND srcBlend, D3DBLEND destBlend ); + + // Applies alpha texture op + void ApplyColorTextureStage( int stage, D3DTEXTUREOP op, int arg1, int arg2 ); + void ApplyAlphaTextureStage( int stage, D3DTEXTUREOP op, int arg1, int arg2 ); + + // Sets texture stage stage + render stage state + void SetSamplerState( int stage, D3DSAMPLERSTATETYPE state, DWORD val ); + void SetTextureStageState( int stage, D3DTEXTURESTAGESTATETYPE state, DWORD val); + void SetRenderStateForce( D3DRENDERSTATETYPE state, DWORD val ); + void SetRenderState( D3DRENDERSTATETYPE state, DWORD val, + bool bFlushBufferedPrimitivesIfChanged = false); + + // Scissor Rect + void SetScissorRect( const int nLeft, const int nTop, const int nRight, const int nBottom, const bool bEnableScissor ); + // Can we download textures? + virtual bool CanDownloadTextures() const; + + void ForceHardwareSync_WithManagedTexture(); + void ForceHardwareSync( void ); + void UpdateFrameSyncQuery( int queryIndex, bool bIssue ); + + void EvictManagedResources(); + + virtual void EvictManagedResourcesInternal(); + + // Gets at a particular transform + inline D3DXMATRIX& GetTransform( int i ) + { + return *m_pMatrixStack[i]->GetTop(); + } + + int GetCurrentNumBones( void ) const; + bool IsHWMorphingEnabled( ) const; + int GetCurrentLightCombo( void ) const; // Used for DX8 only + void GetDX9LightState( LightState_t *state ) const; // Used for DX9 only + + MaterialFogMode_t GetCurrentFogType( void ) const; + + void RecordString( const char *pStr ); + + virtual bool IsRenderingMesh() const { return m_pRenderMesh != 0; } + + void SetTextureTransformDimension( TextureStage_t textureStage, int dimension, bool projected ); + void DisableTextureTransform( TextureStage_t textureMatrix ); + void SetBumpEnvMatrix( TextureStage_t textureStage, float m00, float m01, float m10, float m11 ); + + int GetCurrentFrameCounter( void ) const + { + return m_CurrentFrame; + } + + // Workaround hack for visualization of selection mode + virtual void SetupSelectionModeVisualizationState(); + + // Allocate and delete query objects. + virtual ShaderAPIOcclusionQuery_t CreateOcclusionQueryObject( void ); + virtual void DestroyOcclusionQueryObject( ShaderAPIOcclusionQuery_t h ); + + // Bracket drawing with begin and end so that we can get counts next frame. + virtual void BeginOcclusionQueryDrawing( ShaderAPIOcclusionQuery_t h ); + virtual void EndOcclusionQueryDrawing( ShaderAPIOcclusionQuery_t h ); + + // Get the number of pixels rendered between begin and end on an earlier frame. + // Calling this in the same frame is a huge perf hit! + virtual int OcclusionQuery_GetNumPixelsRendered( ShaderAPIOcclusionQuery_t h, bool bFlush ); + + void SetFlashlightState( const FlashlightState_t &state, const VMatrix &worldToTexture ); + void SetFlashlightStateEx( const FlashlightState_t &state, const VMatrix &worldToTexture, ITexture *pFlashlightDepthTexture ); + const FlashlightState_t &GetFlashlightState( VMatrix &worldToTexture ) const; + const FlashlightState_t &GetFlashlightStateEx( VMatrix &worldToTexture, ITexture **pFlashlightDepthTexture ) const; + + // Gets at the shadow state for a particular state snapshot + virtual bool IsDepthWriteEnabled( StateSnapshot_t id ) const; + +// IDebugTextureInfo implementation. + + virtual bool IsDebugTextureListFresh( int numFramesAllowed = 1 ); + virtual void EnableDebugTextureList( bool bEnable ); + virtual bool SetDebugTextureRendering( bool bEnable ); + virtual void EnableGetAllTextures( bool bEnable ); + virtual KeyValues* GetDebugTextureList(); + virtual int GetTextureMemoryUsed( TextureMemoryType eTextureMemory ); + + virtual void ClearVertexAndPixelShaderRefCounts(); + virtual void PurgeUnusedVertexAndPixelShaders(); + + // Called when the dx support level has changed + virtual void DXSupportLevelChanged(); + + // User clip plane override + virtual void EnableUserClipTransformOverride( bool bEnable ); + virtual void UserClipTransform( const VMatrix &worldToProjection ); + + bool UsingSoftwareVertexProcessing() const; + + // Mark all user clip planes as being dirty + void MarkAllUserClipPlanesDirty(); + + // Converts a D3DXMatrix to a VMatrix and back + void D3DXMatrixToVMatrix( const D3DXMATRIX &in, VMatrix &out ); + void VMatrixToD3DXMatrix( const VMatrix &in, D3DXMATRIX &out ); + + ITexture *GetRenderTargetEx( int nRenderTargetID ); + + virtual void SetToneMappingScaleLinear( const Vector &scale ); + virtual const Vector &GetToneMappingScaleLinear( void ) const; + float GetLightMapScaleFactor( void ) const; + + void SetFloatRenderingParameter(int parm_number, float value); + + void SetIntRenderingParameter(int parm_number, int value); + void SetVectorRenderingParameter(int parm_number, Vector const &value); + + float GetFloatRenderingParameter(int parm_number) const; + + int GetIntRenderingParameter(int parm_number) const; + + Vector GetVectorRenderingParameter(int parm_number) const; + + // For dealing with device lost in cases where Present isn't called all the time (Hammer) + virtual void HandleDeviceLost(); + + virtual void EnableLinearColorSpaceFrameBuffer( bool bEnable ); + + virtual void SetPSNearAndFarZ( int pshReg ); + + // stencil methods + void SetStencilEnable(bool onoff); + void SetStencilFailOperation(StencilOperation_t op); + void SetStencilZFailOperation(StencilOperation_t op); + void SetStencilPassOperation(StencilOperation_t op); + void SetStencilCompareFunction(StencilComparisonFunction_t cmpfn); + void SetStencilReferenceValue(int ref); + void SetStencilTestMask(uint32 msk); + void SetStencilWriteMask(uint32 msk); + void ClearStencilBufferRectangle(int xmin, int ymin, int xmax, int ymax,int value); + + virtual void GetDXLevelDefaults(uint &max_dxlevel,uint &recommended_dxlevel); + +#if defined( _X360 ) + HXUIFONT OpenTrueTypeFont( const char *pFontname, int tall, int style ); + void CloseTrueTypeFont( HXUIFONT hFont ); + bool GetTrueTypeFontMetrics( HXUIFONT hFont, XUIFontMetrics *pFontMetrics, XUICharMetrics charMetrics[256] ); + // Render a sequence of characters and extract the data into a buffer + // For each character, provide the width+height of the font texture subrect, + // an offset to apply when rendering the glyph, and an offset into a buffer to receive the RGBA data + bool GetTrueTypeGlyphs( HXUIFONT hFont, int numChars, wchar_t *pWch, int *pOffsetX, int *pOffsetY, int *pWidth, int *pHeight, unsigned char *pRGBA, int *pRGBAOffset ); + ShaderAPITextureHandle_t CreateRenderTargetSurface( int width, int height, ImageFormat format, const char *pDebugName, const char *pTextureGroupName ); + void PersistDisplay(); + bool PostQueuedTexture( const void *pData, int nSize, ShaderAPITextureHandle_t *pHandles, int nHandles, int nWidth, int nHeight, int nDepth, int nMips, int *pRefCount ); + void *GetD3DDevice(); + + void PushVertexShaderGPRAllocation( int iVertexShaderCount = 64 ); + void PopVertexShaderGPRAllocation( void ); + + void EnableVSync_360( bool bEnable ); +#endif + + virtual bool OwnGPUResources( bool bEnable ); + +// ------------ New Vertex/Index Buffer interface ---------------------------- + void BindVertexBuffer( int streamID, IVertexBuffer *pVertexBuffer, int nOffsetInBytes, int nFirstVertex, int nVertexCount, VertexFormat_t fmt, int nRepetitions = 1 ); + void BindIndexBuffer( IIndexBuffer *pIndexBuffer, int nOffsetInBytes ); + void Draw( MaterialPrimitiveType_t primitiveType, int nFirstIndex, int nIndexCount ); + + // Draw the mesh with the currently bound vertex and index buffers. + void DrawWithVertexAndIndexBuffers( void ); +// ------------ End ---------------------------- + + // deformations + virtual void PushDeformation( const DeformationBase_t *pDeformation ); + virtual void PopDeformation( ); + virtual int GetNumActiveDeformations( ) const ; + + + // for shaders to set vertex shader constants. returns a packed state which can be used to set the dynamic combo + virtual int GetPackedDeformationInformation( int nMaskOfUnderstoodDeformations, + float *pConstantValuesOut, + int nBufferSize, + int nMaximumDeformations, + int *pNumDefsOut ) const ; + + inline Texture_t &GetTexture( ShaderAPITextureHandle_t hTexture ) + { + return m_Textures[hTexture]; + } + + // Gets the texture + IDirect3DBaseTexture* GetD3DTexture( ShaderAPITextureHandle_t hTexture ); + + + virtual bool ShouldWriteDepthToDestAlpha( void ) const; + + virtual void AcquireThreadOwnership(); + virtual void ReleaseThreadOwnership(); +private: + enum + { + SMALL_BACK_BUFFER_SURFACE_WIDTH = 256, + SMALL_BACK_BUFFER_SURFACE_HEIGHT = 256, + }; + + bool m_bEnableDebugTextureList; + bool m_bDebugGetAllTextures; + bool m_bDebugTexturesRendering; + KeyValues *m_pDebugTextureList; + int m_nTextureMemoryUsedLastFrame, m_nTextureMemoryUsedTotal; + int m_nTextureMemoryUsedPicMip1, m_nTextureMemoryUsedPicMip2; + int m_nDebugDataExportFrame; + + FlashlightState_t m_FlashlightState; + VMatrix m_FlashlightWorldToTexture; + ITexture *m_pFlashlightDepthTexture; + + CShaderAPIDx8( CShaderAPIDx8 const& ); + + enum + { + INVALID_TRANSITION_OP = 0xFFFF + }; + + // State transition table for the device is as follows: + + // Other app init causes transition from OK to OtherAppInit, during transition we must release resources + // !Other app init causes transition from OtherAppInit to OK, during transition we must restore resources + // Minimized or device lost or device not reset causes transition from OK to LOST_DEVICE, during transition we must release resources + // Minimized or device lost or device not reset causes transition from OtherAppInit to LOST_DEVICE + + // !minimized AND !device lost causes transition from LOST_DEVICE to NEEDS_RESET + // minimized or device lost causes transition from NEEDS_RESET to LOST_DEVICE + + // Successful TryDeviceReset and !Other app init causes transition from NEEDS_RESET to OK, during transition we must restore resources + // Successful TryDeviceReset and Other app init causes transition from NEEDS_RESET to OtherAppInit + + void ExportTextureList(); + void AddBufferToTextureList( const char *pName, D3DSURFACE_DESC &desc ); + + void SetupTextureGroup( ShaderAPITextureHandle_t hTexture, const char *pTextureGroupName ); + + // Creates the matrix stack + void CreateMatrixStacks(); + + // Initializes the render state + void InitRenderState( ); + + // Resets all dx renderstates to dx default so that our shadows are correct. + void ResetDXRenderState( ); + + // Resets the render state + void ResetRenderState( bool bFullReset = true ); + + // Setup standard vertex shader constants (that don't change) + void SetStandardVertexShaderConstants( float fOverbright ); + + // Initializes vertex and pixel shaders + void InitVertexAndPixelShaders(); + + // Discards the vertex and index buffers + void DiscardVertexBuffers(); + + // Computes the fill rate + void ComputeFillRate(); + + // Takes a snapshot + virtual StateSnapshot_t TakeSnapshot( ); + + // Converts the clear color to be appropriate for HDR + D3DCOLOR GetActualClearColor( D3DCOLOR clearColor ); + + // We lost the device + void OnDeviceLost(); + + // Gets the matrix stack from the matrix mode + int GetMatrixStack( MaterialMatrixMode_t mode ) const; + + // Flushes the matrix state, returns false if we don't need to + // do any more work + bool MatrixIsChanging( TransformType_t transform = TRANSFORM_IS_GENERAL ); + + // Updates the matrix transform state + void UpdateMatrixTransform( TransformType_t transform = TRANSFORM_IS_GENERAL ); + + // Sets the vertex shader modelView state.. + // NOTE: GetProjectionMatrix should only be called from the Commit functions! + const D3DXMATRIX &GetProjectionMatrix( void ); + void SetVertexShaderViewProj(); + void SetVertexShaderModelViewProjAndModelView(); + + void SetPixelShaderFogParams( int reg ); + void SetPixelShaderFogParams( int reg, ShaderFogMode_t fogMode ); + + FORCEINLINE void UpdateVertexShaderFogParams( void ) + { + if ( g_pHardwareConfig->Caps().m_SupportsPixelShaders ) + { + float ooFogRange = 1.0f; + + float fStart = m_VertexShaderFogParams[0]; + float fEnd = m_VertexShaderFogParams[1]; + + // Check for divide by zero + if ( fEnd != fStart ) + { + ooFogRange = 1.0f / ( fEnd - fStart ); + } + + float fogParams[4]; + fogParams[0] = ooFogRange * fEnd; + fogParams[1] = 1.0f; + fogParams[2] = 1.0f - clamp( m_flFogMaxDensity, 0.0f, 1.0f ); // Max fog density + + fogParams[3] = ooFogRange; + + float vertexShaderCameraPos[4]; + vertexShaderCameraPos[0] = m_WorldSpaceCameraPositon[0]; + vertexShaderCameraPos[1] = m_WorldSpaceCameraPositon[1]; + vertexShaderCameraPos[2] = m_WorldSpaceCameraPositon[2]; + vertexShaderCameraPos[3] = m_DynamicState.m_FogZ; // waterheight + + // cFogEndOverFogRange, cFogOne, unused, cOOFogRange + SetVertexShaderConstant( VERTEX_SHADER_FOG_PARAMS, fogParams, 1 ); + + // eyepos.x eyepos.y eyepos.z cWaterZ + SetVertexShaderConstant( VERTEX_SHADER_CAMERA_POS, vertexShaderCameraPos ); + } + } + + // Compute stats info for a texture + void ComputeStatsInfo( ShaderAPITextureHandle_t hTexture, bool isCubeMap, bool isVolumeTexture ); + + // For procedural textures + void AdvanceCurrentCopy( ShaderAPITextureHandle_t hTexture ); + + // Deletes a D3D texture + void DeleteD3DTexture( ShaderAPITextureHandle_t hTexture ); + + // Unbinds a texture + void UnbindTexture( ShaderAPITextureHandle_t hTexture ); + + // Releases all D3D textures + void ReleaseAllTextures(); + + // Deletes all textures + void DeleteAllTextures(); + + // Gets the currently modified texture handle + ShaderAPITextureHandle_t GetModifyTextureHandle() const; + + // Gets the bind id + ShaderAPITextureHandle_t GetBoundTextureBindId( Sampler_t sampler ) const; + + // If mat_texture_limit is enabled, then this tells us if binding the specified texture would + // take us over the limit. + bool WouldBeOverTextureLimit( ShaderAPITextureHandle_t hTexture ); + + // Sets the texture state + void SetTextureState( Sampler_t sampler, ShaderAPITextureHandle_t hTexture, bool force = false ); + + // Grab/release the internal render targets such as the back buffer and the save game thumbnail + void AcquireInternalRenderTargets(); + void ReleaseInternalRenderTargets(); + + // create/release linear->gamma table texture lookups. Only used by hardware supporting pixel shader 2b and up + void AcquireLinearToGammaTableTextures(); + void ReleaseLinearToGammaTableTextures(); + + // Gets the texture being modified + IDirect3DBaseTexture* GetModifyTexture(); + void SetModifyTexture( IDirect3DBaseTexture *pTex ); + + // returns true if we're using texture coordinates at a given stage + bool IsUsingTextureCoordinates( int stage, int flags ) const; + + // Returns true if the board thinks we're generating spheremap coordinates + bool IsSpheremapRenderStateActive( int stage ) const; + + // Returns true if we're modulating constant color into the vertex color + bool IsModulatingVertexColor() const; + + // Recomputes ambient light cube + void RecomputeAmbientLightCube( ); + + // Debugging spew + void SpewBoardState(); + + // Compute and save the world space camera position. + void CacheWorldSpaceCameraPosition(); + + // Compute and save the projection atrix with polyoffset built in if we need it. + void CachePolyOffsetProjectionMatrix(); + + // Vertex shader helper functions + int FindVertexShader( VertexFormat_t fmt, char const* pFileName ) const; + int FindPixelShader( char const* pFileName ) const; + + // Returns copies of the front and back buffers + IDirect3DSurface* GetFrontBufferImage( ImageFormat& format ); + IDirect3DSurface* GetBackBufferImage( Rect_t *pSrcRect, Rect_t *pDstRect, ImageFormat& format ); + IDirect3DSurface* GetBackBufferImageHDR( Rect_t *pSrcRect, Rect_t *pDstRect, ImageFormat& format ); + + // Copy bits from a host-memory surface + void CopyBitsFromHostSurface( IDirect3DSurface* pSurfaceBits, + const Rect_t &dstRect, unsigned char *pData, ImageFormat srcFormat, ImageFormat dstFormat, int nDstStride ); + + FORCEINLINE void SetTransform( D3DTRANSFORMSTATETYPE State, CONST D3DXMATRIX *pMatrix ) + { +#if !defined( _X360 ) + Dx9Device()->SetTransform( State, pMatrix ); +#endif + } + + FORCEINLINE void SetLight( DWORD Index, CONST D3DLIGHT9 *pLight ) + { +#if !defined( _X360 ) + Dx9Device()->SetLight( Index, pLight ); +#endif + } + + FORCEINLINE void LightEnable( DWORD LightIndex, bool bEnable ) + { +#if !defined( _X360 ) + Dx9Device()->LightEnable( LightIndex, bEnable ); +#endif + } + + + void ExecuteCommandBuffer( uint8 *pCmdBuffer ); + void SetStandardTextureHandle( StandardTextureId_t nId, ShaderAPITextureHandle_t ); + + // Methods related to queuing functions to be called per-(pMesh->Draw call) or per-pass + void ClearAllCommitFuncs( CommitFuncType_t func, CommitShaderType_t shader ); + void CallCommitFuncs( CommitFuncType_t func, CommitShaderType_t shader, bool bForce ); + bool IsCommitFuncInUse( CommitFuncType_t func, CommitShaderType_t shader, int nFunc ) const; + void MarkCommitFuncInUse( CommitFuncType_t func, CommitShaderType_t shader, int nFunc ); + void AddCommitFunc( CommitFuncType_t func, CommitShaderType_t shader, StateCommitFunc_t f ); + void CallCommitFuncs( CommitFuncType_t func, bool bUsingFixedFunction, bool bForce = false ); + + // Commits transforms and lighting + void CommitStateChanges(); + + // Commits transforms that have to be dealt with on a per pass basis (ie. projection matrix for polyoffset) + void CommitPerPassStateChanges( StateSnapshot_t id ); + + // Need to handle fog mode on a per-pass basis + void CommitPerPassFogMode( bool bUsingVertexAndPixelShaders ); + + void CommitPerPassXboxFixups(); + + // Commits user clip planes + void CommitUserClipPlanes( bool bUsingFixedFunction ); + + // Gets the user clip transform (world->view) + D3DXMATRIX & GetUserClipTransform( ); + + // transform commit + bool VertexShaderTransformChanged( int i ); + bool FixedFunctionTransformChanged( int i ); + + void UpdateVertexShaderMatrix( int iMatrix ); + void SetVertexShaderStateSkinningMatrices(); + void CommitVertexShaderTransforms(); + void CommitPerPassVertexShaderTransforms(); + + void UpdateFixedFunctionMatrix( int iMatrix ); + void SetFixedFunctionStateSkinningMatrices(); + void CommitFixedFunctionTransforms(); + void CommitPerPassFixedFunctionTransforms(); + + // Recomputes the fast-clip plane matrices based on the current fast-clip plane + void CommitFastClipPlane( ); + + // Computes a matrix which includes the poly offset given an initial projection matrix + void ComputePolyOffsetMatrix( const D3DXMATRIX& matProjection, D3DXMATRIX &matProjectionOffset ); + + void SetSkinningMatrices(); + + // lighting commit + bool VertexShaderLightingChanged( int i ); + bool VertexShaderLightingEnableChanged( int i ); + bool FixedFunctionLightingChanged( int i ); + bool FixedFunctionLightingEnableChanged( int i ); + VertexShaderLightTypes_t ComputeLightType( int i ) const; + void SortLights( int* index ); + void CommitVertexShaderLighting(); + void CommitPixelShaderLighting( int pshReg ); + void CommitFixedFunctionLighting(); + + // Gets the surface associated with a texture (refcount of surface is increased) + IDirect3DSurface* GetTextureSurface( ShaderAPITextureHandle_t textureHandle ); + IDirect3DSurface* GetDepthTextureSurface( ShaderAPITextureHandle_t textureHandle ); + + // + // Methods related to hardware config + // + void SetDefaultConfigValuesForDxLevel( int dxLevelFromCaps, ShaderDeviceInfo_t &info, unsigned int nFlagsUsed ); + + // Determines hardware capabilities + bool DetermineHardwareCaps( ); + + // Alpha To Coverage entrypoints and states - much of this involves vendor-dependent paths and states... + bool CheckVendorDependentAlphaToCoverage(); + void EnableAlphaToCoverage(); + void DisableAlphaToCoverage(); + + // Vendor-dependent shadow mapping detection + void CheckVendorDependentShadowMappingSupport( bool &bSupportsShadowDepthTextures, bool &bSupportsFetch4 ); + + // Override caps based on a requested dx level + void OverrideCaps( int nForcedDXLevel ); + + // Reports support for a given MSAA mode + bool SupportsMSAAMode( int nMSAAMode ); + + // Reports support for a given CSAA mode + bool SupportsCSAAMode( int nNumSamples, int nQualityLevel ); + + // Gamma correction of fog color, or not... + D3DCOLOR ComputeGammaCorrectedFogColor( unsigned char r, unsigned char g, unsigned char b, bool bSRGBWritesEnabled ); + + void SetDefaultMaterial(); + + bool RestorePersistedDisplay( bool bUseFrontBuffer ); + + void ClearStdTextureHandles( void ); + + // debug logging + void PrintfVA( char *fmt, va_list vargs ); + void Printf( const char *fmt, ... ); + float Knob( char *knobname, float *setvalue = NULL ); + + // "normal" back buffer and depth buffer. Need to keep this around so that we + // know what to set the render target to when we are done rendering to a texture. + IDirect3DSurface *m_pBackBufferSurface; + IDirect3DSurface *m_pBackBufferSurfaceSRGB; + IDirect3DSurface *m_pZBufferSurface; + + // Optimization for screenshots + IDirect3DSurface *m_pSmallBackBufferFP16TempSurface; + + ShaderAPITextureHandle_t m_hFullScreenTexture; + + ShaderAPITextureHandle_t m_hLinearToGammaTableTexture; + ShaderAPITextureHandle_t m_hLinearToGammaTableIdentityTexture; + + // + // State needed at the time of rendering (after snapshots have been applied) + // + + // Interface for the D3DXMatrixStack + ID3DXMatrixStack* m_pMatrixStack[NUM_MATRIX_MODES]; + matrix3x4_t m_boneMatrix[NUM_MODEL_TRANSFORMS]; + int m_maxBoneLoaded; + + // Current matrix mode + D3DTRANSFORMSTATETYPE m_MatrixMode; + int m_CurrStack; + + // The current camera position in world space. + Vector4D m_WorldSpaceCameraPositon; + + // The current projection matrix with polyoffset baked into it. + D3DXMATRIX m_CachedPolyOffsetProjectionMatrix; + D3DXMATRIX m_CachedFastClipProjectionMatrix; + D3DXMATRIX m_CachedFastClipPolyOffsetProjectionMatrix; + + // The texture stage state that changes frequently + DynamicState_t m_DynamicState; + + // The *desired* dynamic state. Most dynamic state is committed into actual hardware state + // at either per-pass or per-material time. This can also be used to force the hardware + // to match the desired state after returning from alt-tab. + DynamicState_t m_DesiredState; + + // A list of state commit functions to run as per-draw call commit time + unsigned char m_pCommitFlags[COMMIT_FUNC_TYPE_COUNT][COMMIT_SHADER_TYPE_COUNT][ COMMIT_FUNC_BYTE_COUNT ]; + CUtlVector< StateCommitFunc_t > m_CommitFuncs[COMMIT_FUNC_TYPE_COUNT][COMMIT_SHADER_TYPE_COUNT]; + + // Render data + CMeshBase *m_pRenderMesh; + int m_nDynamicVBSize; + IMaterialInternal *m_pMaterial; + + // Shadow depth bias states + float m_fShadowSlopeScaleDepthBias; + float m_fShadowDepthBias; + + bool m_bReadPixelsEnabled; + + // Render-to-texture stuff... + bool m_UsingTextureRenderTarget; + + int m_ViewportMaxWidth; + int m_ViewportMaxHeight; + + ShaderAPITextureHandle_t m_hCachedRenderTarget; + bool m_bUsingSRGBRenderTarget; + + // Ambient cube map ok? + int m_CachedAmbientLightCube; + + // The current frame + int m_CurrentFrame; + + // The texture we're currently modifying + ShaderAPITextureHandle_t m_ModifyTextureHandle; + char m_ModifyTextureLockedLevel; + unsigned char m_ModifyTextureLockedFace; + + // Stores all textures + CUtlFixedLinkedList< Texture_t > m_Textures; + + // Mesh builder used to modify vertex data + CMeshBuilder m_ModifyBuilder; + + float m_VertexShaderFogParams[2]; + float m_flFogMaxDensity; + + // Shadow state transition table + CTransitionTable m_TransitionTable; + StateSnapshot_t m_nCurrentSnapshot; + + // Depth test override... + bool m_bOverrideMaterialIgnoreZ; + bool m_bIgnoreZValue; + + // Are we in the middle of resetting the render state? + bool m_bResettingRenderState; + + // Can we buffer 2 frames ahead? + bool m_bBuffer2FramesAhead; + + // Selection name stack + CUtlStack< int > m_SelectionNames; + bool m_InSelectionMode; + unsigned int* m_pSelectionBufferEnd; + unsigned int* m_pSelectionBuffer; + unsigned int* m_pCurrSelectionRecord; + float m_SelectionMinZ; + float m_SelectionMaxZ; + int m_NumHits; + + // fog + unsigned char m_SceneFogColor[3]; + MaterialFogMode_t m_SceneFogMode; + + // Tone Mapping state ( w is gamma scale ) + Vector4D m_ToneMappingScale; + + Deformation_t m_DeformationStack[DEFORMATION_STACK_DEPTH]; + + Deformation_t *m_pDeformationStackPtr; + + void WriteShaderConstantsToGPU(); + + // rendering parameter storage + int IntRenderingParameters[MAX_INT_RENDER_PARMS]; + float FloatRenderingParameters[MAX_FLOAT_RENDER_PARMS]; + Vector VectorRenderingParameters[MAX_VECTOR_RENDER_PARMS]; + + ShaderAPITextureHandle_t m_StdTextureHandles[TEXTURE_MAX_STD_TEXTURES]; + + // PIX instrumentation utlities...enable these with PIX_INSTRUMENTATION + void StartPIXInstrumentation(); + void EndPIXInstrumentation(); + void SetPIXMarker( unsigned long color, const char *szName ); + void IncrementPIXError(); + bool PIXError(); + int m_nPIXErrorCount; + int m_nPixFrame; + bool m_bPixCapturing; + + void ComputeVertexDescription( unsigned char* pBuffer, VertexFormat_t vertexFormat, MeshDesc_t& desc ) const + { + return MeshMgr()->ComputeVertexDescription( pBuffer, vertexFormat, desc ); + } + + // Reports support for shadow depth texturing + bool SupportsShadowDepthTextures( void ); + bool SupportsFetch4( void ); + + void SetShadowDepthBiasFactors( float fShadowSlopeScaleDepthBias, float fShadowDepthBias ); + + // Vendor-dependent depth stencil texture format + ImageFormat GetShadowDepthTextureFormat( void ); + + bool SupportsBorderColor( void ) const; + bool SupportsFetch4( void ) const; + + void EnableBuffer2FramesAhead( bool bEnable ); + + void SetDepthFeatheringPixelShaderConstant( int iConstant, float fDepthBlendScale ); + + void SetDisallowAccess( bool b ) + { + g_bShaderAccessDisallowed = b; + } + + void EnableShaderShaderMutex( bool b ) + { + Assert( g_ShaderMutex.GetOwnerId() == 0 ); + g_bUseShaderMutex = b; + } + + void ShaderLock() + { + g_ShaderMutex.Lock(); + } + + void ShaderUnlock() + { + g_ShaderMutex.Unlock(); + } + + // Vendor-dependent slim texture format + ImageFormat GetNullTextureFormat( void ); + + //The idea behind a delayed constant is this. + // Some shaders set constants based on rendering states, and some rendering states aren't updated until after a shader's already called Draw(). + // So, for some functions that are state based, we save the constant we set and if the state changes between when it's set in the shader setup code + // and when the shader is drawn, we update that constant. + struct DelayedConstants_t + { + int iPixelShaderFogParams; + + void Invalidate( void ) + { + iPixelShaderFogParams = -1; + } + DelayedConstants_t( void ) { this->Invalidate(); } + }; + DelayedConstants_t m_DelayedShaderConstants; + + bool SetRenderTargetInternalXbox( ShaderAPITextureHandle_t hTexture, bool bForce = false ); + +#if defined( _X360 ) + CUtlStack m_VertexShaderGPRAllocationStack; +#endif + + int m_MaxVectorVertexShaderConstant; + int m_MaxBooleanVertexShaderConstant; + int m_MaxIntegerVertexShaderConstant; + int m_MaxVectorPixelShaderConstant; + int m_MaxBooleanPixelShaderConstant; + int m_MaxIntegerPixelShaderConstant; + + bool m_bGPUOwned; + bool m_bResetRenderStateNeeded; + +#ifdef ENABLE_NULLREF_DEVICE_SUPPORT + bool m_NullDevice; +#endif +}; + + +//----------------------------------------------------------------------------- +// Class Factory +//----------------------------------------------------------------------------- +static CShaderAPIDx8 g_ShaderAPIDX8; +IShaderAPIDX8 *g_pShaderAPIDX8 = &g_ShaderAPIDX8; +CShaderDeviceDx8* g_pShaderDeviceDx8 = &g_ShaderAPIDX8; + +// FIXME: Remove IShaderAPI + IShaderDevice; they change after SetMode +EXPOSE_SINGLE_INTERFACE_GLOBALVAR( CShaderAPIDx8, IShaderAPI, + SHADERAPI_INTERFACE_VERSION, g_ShaderAPIDX8 ) + +EXPOSE_SINGLE_INTERFACE_GLOBALVAR( CShaderAPIDx8, IShaderDevice, + SHADER_DEVICE_INTERFACE_VERSION, g_ShaderAPIDX8 ) + +EXPOSE_SINGLE_INTERFACE_GLOBALVAR( CShaderAPIDx8, IDebugTextureInfo, + DEBUG_TEXTURE_INFO_VERSION, g_ShaderAPIDX8 ) + +//----------------------------------------------------------------------------- +// Accessors for major interfaces +//----------------------------------------------------------------------------- + +// Pix wants a max of 32 characters +// We'll give it the right-most substrings separated by slashes +static char s_pPIXMaterialName[32]; +void PIXifyName( char *pDst, int destSize, const char *pSrc ) +{ + char *pSrcWalk = (char *)pSrc; + + while ( V_strlen( pSrcWalk ) > 31 ) // While we still have too many characters + { + char *pTok = strpbrk( pSrcWalk, "/\\" ); // Find next token + + if ( pTok ) + pSrcWalk = pTok + 1; + else + break; + } + + V_strncpy( pDst, pSrcWalk, min( 32, destSize ) ); +} + +static int AdjustUpdateRange( float const* pVec, void const *pOut, int numVecs, int* pSkip ) +{ + int skip = 0; + uint32* pSrc = (uint32*)pVec; + uint32* pDst = (uint32*)pOut; + while( numVecs && !( ( pSrc[0] ^ pDst[0] ) | ( pSrc[1] ^ pDst[1] ) | ( pSrc[2] ^ pDst[2] ) | ( pSrc[3] ^ pDst[3] ) ) ) + { + pSrc += 4; + pDst += 4; + numVecs--; + skip++; + } + *pSkip = skip; + if ( !numVecs ) + return 0; + + uint32* pSrcLast = pSrc + numVecs * 4 - 4; + uint32* pDstLast = pDst + numVecs * 4 - 4; + while( numVecs > 1 && !( ( pSrcLast[0] ^ pDstLast[0] ) | ( pSrcLast[1] ^ pDstLast[1] ) | ( pSrcLast[2] ^ pDstLast[2] ) | ( pSrcLast[3] ^ pDstLast[3] ) ) ) + { + pSrcLast -= 4; + pDstLast -= 4; + numVecs--; + } + + return numVecs; +} + +//----------------------------------------------------------------------------- +// Constructor, destructor +//----------------------------------------------------------------------------- +CShaderAPIDx8::CShaderAPIDx8() : + m_Textures( 32 ), + m_CurrStack( -1 ), + m_ModifyTextureHandle( INVALID_SHADERAPI_TEXTURE_HANDLE ), + m_pRenderMesh( 0 ), + m_nDynamicVBSize( DYNAMIC_VERTEX_BUFFER_MEMORY ), + m_pMaterial( NULL ), + m_CurrentFrame( 0 ), + m_CachedAmbientLightCube( STATE_CHANGED ), + m_InSelectionMode( false ), + m_SelectionMinZ( FLT_MAX ), + m_SelectionMaxZ( FLT_MIN ), + m_pSelectionBuffer( 0 ), + m_pSelectionBufferEnd( 0 ), + m_bResetRenderStateNeeded( false ), + m_ModifyTextureLockedLevel( -1 ), + m_nPixFrame(0), + m_bPixCapturing(false), + m_nPIXErrorCount(0), + m_pBackBufferSurface( 0 ), + m_pBackBufferSurfaceSRGB( 0 ), + m_pZBufferSurface( 0 ), + m_bResettingRenderState( false ), + m_bReadPixelsEnabled( false ), + m_ToneMappingScale( 1.0f, 1.0f, 1.0f, 1.0f ), + m_hFullScreenTexture( INVALID_SHADERAPI_TEXTURE_HANDLE ), + m_hLinearToGammaTableTexture( INVALID_SHADERAPI_TEXTURE_HANDLE ), + m_hLinearToGammaTableIdentityTexture( INVALID_SHADERAPI_TEXTURE_HANDLE ), + m_fShadowSlopeScaleDepthBias( 16.0f ), + m_fShadowDepthBias( 0.00008f ), + m_hCachedRenderTarget( INVALID_SHADERAPI_TEXTURE_HANDLE ), + m_bUsingSRGBRenderTarget( false ) +{ + // FIXME: Remove! Backward compat + m_bAdapterSet = false; + m_bBuffer2FramesAhead = false; + m_bReadPixelsEnabled = true; + + memset( m_pMatrixStack, 0, sizeof(ID3DXMatrixStack*) * NUM_MATRIX_MODES ); + memset( &m_DynamicState, 0, sizeof(m_DynamicState) ); + //m_DynamicState.m_HeightClipMode = MATERIAL_HEIGHTCLIPMODE_DISABLE; + m_nWindowHeight = m_nWindowWidth = 0; + m_maxBoneLoaded = 0; + + m_bEnableDebugTextureList = 0; + m_bDebugTexturesRendering = 0; + m_pDebugTextureList = NULL; + m_nTextureMemoryUsedLastFrame = 0; + m_nTextureMemoryUsedTotal = 0; + m_nTextureMemoryUsedPicMip1 = 0; + m_nTextureMemoryUsedPicMip2 = 0; + m_nDebugDataExportFrame = 0; + + m_SceneFogColor[0] = 0; + m_SceneFogColor[1] = 0; + m_SceneFogColor[2] = 0; + m_SceneFogMode = MATERIAL_FOG_NONE; + + // We haven't yet detected whether we support CreateQuery or not yet. + memset(IntRenderingParameters,0,sizeof(IntRenderingParameters)); + memset(FloatRenderingParameters,0,sizeof(FloatRenderingParameters)); + memset(VectorRenderingParameters,0,sizeof(VectorRenderingParameters)); + + m_pDeformationStackPtr = m_DeformationStack + DEFORMATION_STACK_DEPTH; + + m_bGPUOwned = false; + m_MaxVectorVertexShaderConstant = 0; + m_MaxBooleanVertexShaderConstant = 0; + m_MaxIntegerVertexShaderConstant = 0; + m_MaxVectorPixelShaderConstant = 0; + m_MaxBooleanPixelShaderConstant = 0; + m_MaxIntegerPixelShaderConstant = 0; + + ClearStdTextureHandles(); + + //Debugger(); +#ifdef ENABLE_NULLREF_DEVICE_SUPPORT + m_NullDevice = !!CommandLine()->FindParm( "-nulldevice" ); +#endif +} + +CShaderAPIDx8::~CShaderAPIDx8() +{ + if ( m_DynamicState.m_pVectorVertexShaderConstant ) + { + delete[] m_DynamicState.m_pVectorVertexShaderConstant; + m_DynamicState.m_pVectorVertexShaderConstant = NULL; + } + + if ( m_DynamicState.m_pBooleanVertexShaderConstant ) + { + delete[] m_DynamicState.m_pBooleanVertexShaderConstant; + m_DynamicState.m_pBooleanVertexShaderConstant = NULL; + } + + if ( m_DynamicState.m_pIntegerVertexShaderConstant ) + { + delete[] m_DynamicState.m_pIntegerVertexShaderConstant; + m_DynamicState.m_pIntegerVertexShaderConstant = NULL; + } + + if ( m_DynamicState.m_pVectorPixelShaderConstant ) + { + delete[] m_DynamicState.m_pVectorPixelShaderConstant; + m_DynamicState.m_pVectorPixelShaderConstant = NULL; + } + + if ( m_DynamicState.m_pBooleanPixelShaderConstant ) + { + delete[] m_DynamicState.m_pBooleanPixelShaderConstant; + m_DynamicState.m_pBooleanPixelShaderConstant = NULL; + } + + if ( m_DynamicState.m_pIntegerPixelShaderConstant ) + { + delete[] m_DynamicState.m_pIntegerPixelShaderConstant; + m_DynamicState.m_pIntegerPixelShaderConstant = NULL; + } + + if ( m_pDebugTextureList ) + { + m_pDebugTextureList->deleteThis(); + m_pDebugTextureList = NULL; + } +} + + +void CShaderAPIDx8::ClearStdTextureHandles( void ) +{ + for(int i = 0 ; i < ARRAYSIZE( m_StdTextureHandles ) ; i++ ) + m_StdTextureHandles[i] = INVALID_SHADERAPI_TEXTURE_HANDLE; +} + + +//----------------------------------------------------------------------------- +// FIXME: Remove! Backward compat. +//----------------------------------------------------------------------------- +bool CShaderAPIDx8::OnAdapterSet() +{ + if ( !DetermineHardwareCaps( ) ) + return false; + + // Modify the caps based on requested DXlevels + int nForcedDXLevel = CommandLine()->ParmValue( "-dxlevel", 0 ); + + if ( nForcedDXLevel > 0 ) + { + nForcedDXLevel = MAX( nForcedDXLevel, ABSOLUTE_MINIMUM_DXLEVEL ); + } + + + // FIXME: Check g_pHardwareConfig->ActualCaps() for a preferred DX level + OverrideCaps( nForcedDXLevel ); + + m_bAdapterSet = true; + return true; +} + + +void CShaderAPIDx8::GetDXLevelDefaults(uint &max_dxlevel,uint &recommended_dxlevel) +{ + max_dxlevel=g_pHardwareConfig->ActualCaps().m_nMaxDXSupportLevel; + recommended_dxlevel=g_pHardwareConfig->ActualCaps().m_nDXSupportLevel; +} + +//----------------------------------------------------------------------------- +// Can we download textures? +//----------------------------------------------------------------------------- +bool CShaderAPIDx8::CanDownloadTextures() const +{ + if ( IsDeactivated() ) + return false; + + return IsActive(); +} + + +//----------------------------------------------------------------------------- +// Grab the render targets +//----------------------------------------------------------------------------- +void CShaderAPIDx8::AcquireInternalRenderTargets() +{ + GLMPRINTF(( ">-A- CShaderAPIDx8::AcquireInternalRenderTargets... ")); + if ( mat_debugalttab.GetBool() ) + { + Warning( "mat_debugalttab: CShaderAPIDx8::AcquireInternalRenderTargets\n" ); + } + + if ( !m_pBackBufferSurface ) + { + Dx9Device()->GetRenderTarget( 0, &m_pBackBufferSurface ); +#ifdef ENABLE_NULLREF_DEVICE_SUPPORT + if( !m_NullDevice ) +#endif + { + Assert( m_pBackBufferSurface ); + } + } + +#if defined( _X360 ) + if ( !m_pBackBufferSurfaceSRGB ) + { + // create a SRGB back buffer clone + int backWidth, backHeight; + ShaderAPI()->GetBackBufferDimensions( backWidth, backHeight ); + D3DFORMAT backBufferFormat = ImageLoader::ImageFormatToD3DFormat( g_pShaderDevice->GetBackBufferFormat() ); + m_pBackBufferSurfaceSRGB = g_TextureHeap.AllocRenderTargetSurface( backWidth, backHeight, (D3DFORMAT)MAKESRGBFMT( backBufferFormat ), true, 0 ); + } +#endif + +#ifdef ENABLE_NULLREF_DEVICE_SUPPORT + if ( !m_pZBufferSurface && !m_NullDevice ) +#else + if ( !m_pZBufferSurface ) +#endif + { + Dx9Device()->GetDepthStencilSurface( &m_pZBufferSurface ); + Assert( m_pZBufferSurface ); + } + GLMPRINTF(( "<-A- CShaderAPIDx8::AcquireInternalRenderTargets...complete ")); +} + + +//----------------------------------------------------------------------------- +// Release the render targets +//----------------------------------------------------------------------------- +void CShaderAPIDx8::ReleaseInternalRenderTargets( ) +{ + GLMPRINTF(( ">-A- CShaderAPIDx8::ReleaseInternalRenderTargets... ")); + if( mat_debugalttab.GetBool() ) + { + Warning( "mat_debugalttab: CShaderAPIDx8::ReleaseInternalRenderTargets\n" ); + } + + // Note: This function does not release renderable textures created elsewhere + // Those should be released separately via the texure manager + if ( m_pBackBufferSurface ) + { +#if POSIX + // dxabstract's AddRef/Release have optional args to help track usage + int nRetVal = m_pBackBufferSurface->Release( 0, "-B CShaderAPIDx8::ReleaseInternalRenderTargets public release color buffer"); +#else + int nRetVal = m_pBackBufferSurface->Release(); +#endif + //Assert( nRetVal == 0 ); + m_pBackBufferSurface = NULL; + } + + if ( m_pZBufferSurface ) + { +#if POSIX + // dxabstract's AddRef/Release have optional args to help track usage + int nRetVal = m_pZBufferSurface->Release( 0, "-B CShaderAPIDx8::ReleaseInternalRenderTargets public release zbuffer"); +#else + int nRetVal = m_pZBufferSurface->Release(); +#endif + + //Assert( nRetVal == 0 ); //FIXME not sure why we're seeing a refcount of 3 here + m_pZBufferSurface = NULL; + } + GLMPRINTF(( "<-A- CShaderAPIDx8::ReleaseInternalRenderTargets... complete")); +} + +//----------------------------------------------------------------------------- +// During init, places the persisted texture back into the back buffer. +// The initial 360 fixup present will then not flash. This routine has to be +// self contained, no other shader api systems are viable during init. +//----------------------------------------------------------------------------- +bool CShaderAPIDx8::RestorePersistedDisplay( bool bUseFrontBuffer ) +{ +#if defined( _X360 ) + if ( !( XboxLaunch()->GetLaunchFlags() & LF_INTERNALLAUNCH ) ) + { + // there is no persisted screen + return false; + } + + OwnGPUResources( false ); + + const char *strVertexShaderProgram = + " float4x4 matWVP : register(c0);" + " struct VS_IN" + " {" + " float4 ObjPos : POSITION;" + " float2 TexCoord : TEXCOORD;" + " };" + " struct VS_OUT" + " {" + " float4 ProjPos : POSITION;" + " float2 TexCoord : TEXCOORD;" + " };" + " VS_OUT main( VS_IN In )" + " {" + " VS_OUT Out; " + " Out.ProjPos = mul( matWVP, In.ObjPos );" + " Out.TexCoord = In.TexCoord;" + " return Out;" + " }"; + + const char *strPixelShaderProgram = + " struct PS_IN" + " {" + " float2 TexCoord : TEXCOORD;" + " };" + " sampler detail;" + " float4 main( PS_IN In ) : COLOR" + " {" + " return tex2D( detail, In.TexCoord );" + " }"; + + D3DVERTEXELEMENT9 VertexElements[3] = + { + { 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 }, + { 0, 12, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 }, + D3DDECL_END() + }; + + + IDirect3DTexture *pTexture; + if ( bUseFrontBuffer ) + { + Dx9Device()->GetFrontBuffer( &pTexture ); + } + else + { + // 360 holds a persistent image across restarts + Dx9Device()->GetPersistedTexture( &pTexture ); + } + + ID3DXBuffer *pErrorMsg = NULL; + ID3DXBuffer *pShaderCode = NULL; + + HRESULT hr = D3DXCompileShader( strVertexShaderProgram, (UINT)strlen( strVertexShaderProgram ), NULL, NULL, "main", "vs_2_0", 0, &pShaderCode, &pErrorMsg, NULL ); + if ( FAILED( hr ) ) + { + return false; + } + IDirect3DVertexShader9 *pVertexShader; + Dx9Device()->CreateVertexShader( (DWORD*)pShaderCode->GetBufferPointer(), &pVertexShader ); + pShaderCode->Release(); + + pErrorMsg = NULL; + pShaderCode = NULL; + hr = D3DXCompileShader( strPixelShaderProgram, (UINT)strlen( strPixelShaderProgram ), NULL, NULL, "main", "ps_2_0", 0, &pShaderCode, &pErrorMsg, NULL ); + if ( FAILED(hr) ) + { + return false; + } + IDirect3DPixelShader9 *pPixelShader; + Dx9Device()->CreatePixelShader( (DWORD*)pShaderCode->GetBufferPointer(), &pPixelShader ); + pShaderCode->Release(); + + int w, h; + GetBackBufferDimensions( w, h ); + + // Create a vertex declaration from the element descriptions. + IDirect3DVertexDeclaration9 *pVertexDecl; + Dx9Device()->CreateVertexDeclaration( VertexElements, &pVertexDecl ); + XMMATRIX matWVP = XMMatrixOrthographicOffCenterLH( 0, (FLOAT)w, (FLOAT)h, 0, 0, 1 ); + + ConVarRef mat_monitorgamma( "mat_monitorgamma" ); + ConVarRef mat_monitorgamma_tv_range_min( "mat_monitorgamma_tv_range_min" ); + ConVarRef mat_monitorgamma_tv_range_max( "mat_monitorgamma_tv_range_max" ); + ConVarRef mat_monitorgamma_tv_exp( "mat_monitorgamma_tv_exp" ); + ConVarRef mat_monitorgamma_tv_enabled( "mat_monitorgamma_tv_enabled" ); + g_pShaderDeviceDx8->SetHardwareGammaRamp( mat_monitorgamma.GetFloat(), mat_monitorgamma_tv_range_min.GetFloat(), mat_monitorgamma_tv_range_max.GetFloat(), + mat_monitorgamma_tv_exp.GetFloat(), mat_monitorgamma_tv_enabled.GetBool() ); + + // Structure to hold vertex data. + struct COLORVERTEX + { + FLOAT Position[3]; + float TexCoord[2]; + }; + COLORVERTEX Vertices[4]; + + Vertices[0].Position[0] = 0; + Vertices[0].Position[1] = 0; + Vertices[0].Position[2] = 0; + Vertices[0].TexCoord[0] = 0; + Vertices[0].TexCoord[1] = 0; + + Vertices[1].Position[0] = w-1; + Vertices[1].Position[1] = 0; + Vertices[1].Position[2] = 0; + Vertices[1].TexCoord[0] = 1; + Vertices[1].TexCoord[1] = 0; + + Vertices[2].Position[0] = w-1; + Vertices[2].Position[1] = h-1; + Vertices[2].Position[2] = 0; + Vertices[2].TexCoord[0] = 1; + Vertices[2].TexCoord[1] = 1; + + Vertices[3].Position[0] = 0; + Vertices[3].Position[1] = h-1; + Vertices[3].Position[2] = 0; + Vertices[3].TexCoord[0] = 0; + Vertices[3].TexCoord[1] = 1; + + Dx9Device()->SetTexture( 0, pTexture ); + Dx9Device()->SetVertexShader( pVertexShader ); + Dx9Device()->SetPixelShader( pPixelShader ); + Dx9Device()->SetVertexShaderConstantF( 0, (FLOAT*)&matWVP, 4 ); + Dx9Device()->SetVertexDeclaration( pVertexDecl ); + Dx9Device()->DrawPrimitiveUP( D3DPT_QUADLIST, 1, Vertices, sizeof( COLORVERTEX ) ); + + Dx9Device()->SetVertexShader( NULL ); + Dx9Device()->SetPixelShader( NULL ); + Dx9Device()->SetTexture( 0, NULL ); + Dx9Device()->SetVertexDeclaration( NULL ); + + pVertexShader->Release(); + pPixelShader->Release(); + pVertexDecl->Release(); + pTexture->Release(); + + OwnGPUResources( true ); + + return true; +#else + return false; +#endif +} + +//----------------------------------------------------------------------------- +// Initialize, shutdown the Device.... +//----------------------------------------------------------------------------- +bool CShaderAPIDx8::OnDeviceInit() +{ + AcquireInternalRenderTargets(); + + g_pHardwareConfig->CapsForEdit().m_TextureMemorySize = g_pShaderDeviceMgrDx8->GetVidMemBytes( m_nAdapter ); + + CreateMatrixStacks(); + + // Hide the cursor + RECORD_COMMAND( DX8_SHOW_CURSOR, 1 ); + RECORD_INT( false ); + +#if !defined( _X360 ) + Dx9Device()->ShowCursor( false ); +#endif + + // Initialize the shader manager + ShaderManager()->Init(); + + // Initialize the shader shadow + ShaderShadow()->Init(); + + // Initialize the mesh manager + MeshMgr()->Init(); + + bool bToolsMode = IsWindows() && ( CommandLine()->CheckParm( "-tools" ) != NULL ); + + // Use fat vertices when running in tools + MeshMgr()->UseFatVertices( bToolsMode ); + + // Initialize the transition table. + m_TransitionTable.Init(); + + // Initialize the render state + InitRenderState(); + + // Clear the z and color buffers + ClearBuffers( true, true, true, -1, -1 ); + + AllocFrameSyncObjects(); + AllocNonInteractiveRefreshObjects(); + + RECORD_COMMAND( DX8_BEGIN_SCENE, 0 ); + + // Apply mandatory initialization HW fixups, GPU state will be left as expected + if ( IsX360() ) + { + // place the possible persisted display into the back buffer, ready for present() + RestorePersistedDisplay( false ); + + // 360 MUST perform an initial swap to stabilize the state + // this ensures any states (e.g. gamma) are respected + // without this, the 360 resets to internal default state on the first swap + OwnGPUResources( false ); + Dx9Device()->Present( 0, 0, 0, 0 ); + + // present corrupts the GPU state and back buffer (according to docs) + // re-clear the back buffer in order to re-establish the expected contents + ResetRenderState( false ); + ClearBuffers( true, true, true, -1, -1 ); + + // place the front buffer image in the back buffer, later systems will detect and grab + // other systems will detect and grab + RestorePersistedDisplay( true ); + } + + Dx9Device()->BeginScene(); + + return true; +} + +void CShaderAPIDx8::OnDeviceShutdown() +{ + if ( !IsPC() || !IsActive() ) + return; + + // Deallocate all textures + DeleteAllTextures(); + + // Release render targets + ReleaseInternalRenderTargets(); + + // Free objects that are used for frame syncing. + FreeFrameSyncObjects(); + FreeNonInteractiveRefreshObjects(); + + for (int i = 0; i < NUM_MATRIX_MODES; ++i) + { + if (m_pMatrixStack[i]) + { + int ref = m_pMatrixStack[i]->Release(); + Assert( ref == 0 ); + } + } + + // Shutdown the transition table. + m_TransitionTable.Shutdown(); + + MeshMgr()->Shutdown(); + + ShaderManager()->Shutdown(); + + ReleaseAllVertexDecl( ); +} + + +//----------------------------------------------------------------------------- +// Sets the mode... +//----------------------------------------------------------------------------- +bool CShaderAPIDx8::SetMode( void* VD3DHWND, int nAdapter, const ShaderDeviceInfo_t &info ) +{ + // + // FIXME: Note that this entire function is backward compat and will go soon + // + + bool bRestoreNeeded = false; + + if ( IsActive() ) + { + ReleaseResources(); + OnDeviceShutdown(); + ShutdownDevice(); + bRestoreNeeded = true; + } + + LOCK_SHADERAPI(); + Assert( D3D() ); + Assert( nAdapter < g_pShaderDeviceMgr->GetAdapterCount() ); + + const HardwareCaps_t& actualCaps = g_pShaderDeviceMgr->GetHardwareCaps( nAdapter ); + + ShaderDeviceInfo_t actualInfo = info; + int nDXLevel = actualInfo.m_nDXLevel ? actualInfo.m_nDXLevel : actualCaps.m_nDXSupportLevel; + + static bool bSetModeOnce = false; + if ( !bSetModeOnce ) + { + nDXLevel = MAX( ABSOLUTE_MINIMUM_DXLEVEL, CommandLine()->ParmValue( "-dxlevel", nDXLevel ) ); + bSetModeOnce = true; + } + if ( nDXLevel > actualCaps.m_nMaxDXSupportLevel ) + { + nDXLevel = actualCaps.m_nMaxDXSupportLevel; + } + actualInfo.m_nDXLevel = g_pShaderDeviceMgr->GetClosestActualDXLevel( nDXLevel ); + + if ( !g_pShaderDeviceMgrDx8->ValidateMode( nAdapter, actualInfo ) ) + return false; + + g_pShaderAPI = this; + g_pShaderDevice = this; + g_pShaderShadow = ShaderShadow(); + bool bOk = InitDevice( VD3DHWND, nAdapter, actualInfo ); + if ( !bOk ) + return false; + + if ( !OnDeviceInit() ) + return false; + + if ( bRestoreNeeded && IsPC() ) + { + ReacquireResources(); + } + + return true; +} + + +//----------------------------------------------------------------------------- +// Creates the matrix stack +//----------------------------------------------------------------------------- +void CShaderAPIDx8::CreateMatrixStacks() +{ + MEM_ALLOC_D3D_CREDIT(); + + for (int i = 0; i < NUM_MATRIX_MODES; ++i) + { + HRESULT hr = D3DXCreateMatrixStack( 0, &m_pMatrixStack[i] ); + Assert( hr == D3D_OK ); + } +} + + +//----------------------------------------------------------------------------- +// Vendor-dependent code to turn on alpha to coverage +//----------------------------------------------------------------------------- +void CShaderAPIDx8::EnableAlphaToCoverage( void ) +{ + if( !g_pHardwareConfig->ActualCaps().m_bSupportsAlphaToCoverage || !IsAAEnabled() ) + return; + + D3DRENDERSTATETYPE renderState = (D3DRENDERSTATETYPE)g_pHardwareConfig->Caps().m_AlphaToCoverageState; + SetRenderState( renderState, g_pHardwareConfig->Caps().m_AlphaToCoverageEnableValue ); // Vendor dependent state +} + +//----------------------------------------------------------------------------- +// Vendor-dependent code to turn off alpha to coverage +//----------------------------------------------------------------------------- +void CShaderAPIDx8::DisableAlphaToCoverage() +{ + if( !g_pHardwareConfig->ActualCaps().m_bSupportsAlphaToCoverage || !IsAAEnabled() ) + return; + + D3DRENDERSTATETYPE renderState = (D3DRENDERSTATETYPE)g_pHardwareConfig->Caps().m_AlphaToCoverageState; + SetRenderState( renderState, g_pHardwareConfig->Caps().m_AlphaToCoverageDisableValue ); // Vendor dependent state +} + +//----------------------------------------------------------------------------- +// Determine capabilities +//----------------------------------------------------------------------------- +bool CShaderAPIDx8::DetermineHardwareCaps( ) +{ + HardwareCaps_t& actualCaps = g_pHardwareConfig->ActualCapsForEdit(); + if ( !g_pShaderDeviceMgrDx8->ComputeCapsFromD3D( &actualCaps, m_DisplayAdapter ) ) + return false; + + // See if the file tells us otherwise + g_pShaderDeviceMgrDx8->ReadDXSupportLevels( actualCaps ); + + // Read dxsupport.cfg which has config overrides for particular cards. + g_pShaderDeviceMgrDx8->ReadHardwareCaps( actualCaps, actualCaps.m_nMaxDXSupportLevel ); + + // What's in "-shader" overrides dxsupport.cfg + const char *pShaderParam = CommandLine()->ParmValue( "-shader" ); + if ( pShaderParam ) + { + Q_strncpy( actualCaps.m_pShaderDLL, pShaderParam, sizeof( actualCaps.m_pShaderDLL ) ); + } + + return true; +} + + +//----------------------------------------------------------------------------- +// Override caps based on a particular dx level +//----------------------------------------------------------------------------- +void CShaderAPIDx8::OverrideCaps( int nForcedDXLevel ) +{ + // Just use the actual caps if we can't use what was requested or if the default is requested + if ( nForcedDXLevel <= 0 ) + { + nForcedDXLevel = g_pHardwareConfig->ActualCaps().m_nDXSupportLevel; + } + nForcedDXLevel = g_pShaderDeviceMgr->GetClosestActualDXLevel( nForcedDXLevel ); + + g_pHardwareConfig->SetupHardwareCaps( nForcedDXLevel, g_pHardwareConfig->ActualCaps() ); +} + + +//----------------------------------------------------------------------------- +// Called when the dx support level has changed +//----------------------------------------------------------------------------- +void CShaderAPIDx8::DXSupportLevelChanged() +{ + LOCK_SHADERAPI(); + if ( IsPC() ) + { + OverrideCaps( ShaderUtil()->GetConfig().dxSupportLevel ); + } + else + { + Assert( 0 ); + } +} + + +//----------------------------------------------------------------------------- +// FIXME: Remove! Backward compat only +//----------------------------------------------------------------------------- +int CShaderAPIDx8::GetActualTextureStageCount() const +{ + return g_pHardwareConfig->GetActualTextureStageCount(); +} + +int CShaderAPIDx8::GetActualSamplerCount() const +{ + return g_pHardwareConfig->GetActualSamplerCount(); +} + +int CShaderAPIDx8::StencilBufferBits() const +{ + return m_bUsingStencil ? m_iStencilBufferBits : 0; +} + +bool CShaderAPIDx8::IsAAEnabled() const +{ + bool bAntialiasing = ( m_PresentParameters.MultiSampleType != D3DMULTISAMPLE_NONE ); + return bAntialiasing; +} + + +//----------------------------------------------------------------------------- +// Methods related to queuing functions to be called per-(pMesh->Draw call) or per-pass +//----------------------------------------------------------------------------- +bool CShaderAPIDx8::IsCommitFuncInUse( CommitFuncType_t func, CommitShaderType_t shader, int nFunc ) const +{ + Assert( nFunc < COMMIT_FUNC_COUNT ); + return ( m_pCommitFlags[func][shader][ nFunc >> 3 ] & ( 1 << ( nFunc & 0x7 ) ) ) != 0; +} + +void CShaderAPIDx8::MarkCommitFuncInUse( CommitFuncType_t func, CommitShaderType_t shader, int nFunc ) +{ + m_pCommitFlags[func][shader][ nFunc >> 3 ] |= 1 << ( nFunc & 0x7 ); +} + +void CShaderAPIDx8::AddCommitFunc( CommitFuncType_t func, CommitShaderType_t shader, StateCommitFunc_t f ) +{ + m_CommitFuncs[func][shader].AddToTail( f ); +} + + +//----------------------------------------------------------------------------- +// Clears all commit functions +//----------------------------------------------------------------------------- +void CShaderAPIDx8::ClearAllCommitFuncs( CommitFuncType_t func, CommitShaderType_t shader ) +{ + memset( m_pCommitFlags[func][shader], 0, COMMIT_FUNC_BYTE_COUNT ); + m_CommitFuncs[func][shader].RemoveAll(); +} + + +//----------------------------------------------------------------------------- +// Calls all commit functions in a particular list +//----------------------------------------------------------------------------- +void CShaderAPIDx8::CallCommitFuncs( CommitFuncType_t func, CommitShaderType_t shader, bool bForce ) +{ + // 360 does not have have a FF pipe + Assert ( IsPC() || ( IsX360() && shader != COMMIT_FIXED_FUNCTION ) ); + + // Don't bother committing anything if we're deactivated + if ( IsDeactivated() ) + return; + + CUtlVector< StateCommitFunc_t > &funcList = m_CommitFuncs[func][shader]; + int nCount = funcList.Count(); + if ( nCount == 0 ) + return; + + for ( int i = 0; i < nCount; ++i ) + { + funcList[i]( Dx9Device(), m_DesiredState, m_DynamicState, bForce ); + } + ClearAllCommitFuncs( func, shader ); +} + + +//----------------------------------------------------------------------------- +// Calls all per-mesh draw commit functions +//----------------------------------------------------------------------------- +void CShaderAPIDx8::CallCommitFuncs( CommitFuncType_t func, bool bUsingFixedFunction, bool bForce ) +{ + // Fixed-Function only funcs + if ( IsPC() && ( bUsingFixedFunction || bForce ) ) + { + CallCommitFuncs( func, COMMIT_FIXED_FUNCTION, bForce ); + } + + // Vertex-shader only funcs + if ( !bUsingFixedFunction || bForce ) + { + CallCommitFuncs( func, COMMIT_VERTEX_SHADER, bForce ); + } + + // State set in both FF + VS + CallCommitFuncs( func, COMMIT_ALWAYS, bForce ); +} + +//----------------------------------------------------------------------------- +// Sets the sampler state +//----------------------------------------------------------------------------- +static FORCEINLINE void SetSamplerState( IDirect3DDevice9 *pDevice, int stage, D3DSAMPLERSTATETYPE state, DWORD val ) +{ + RECORD_SAMPLER_STATE( stage, state, val ); + +#if defined( _X360 ) + if ( state == D3DSAMP_NOTSUPPORTED ) + return; +#endif + + pDevice->SetSamplerState( stage, state, val ); +} + +inline void CShaderAPIDx8::SetSamplerState( int stage, D3DSAMPLERSTATETYPE state, DWORD val ) +{ +#ifndef DX_TO_GL_ABSTRACTION + if ( IsDeactivated() ) + return; +#endif + + ::SetSamplerState( Dx9Device(), stage, state, val ); +} + +//----------------------------------------------------------------------------- +// Sets the texture stage state +//----------------------------------------------------------------------------- +inline void CShaderAPIDx8::SetTextureStageState( int stage, D3DTEXTURESTAGESTATETYPE state, DWORD val ) +{ +#if !defined( _X360 ) + if ( IsDeactivated() ) + return; + + Dx9Device()->SetTextureStageState( stage, state, val ); +#endif +} + +inline void CShaderAPIDx8::SetRenderState( D3DRENDERSTATETYPE state, DWORD val, bool bFlushIfChanged ) +{ +#if ( !defined( _X360 ) && !defined( DX_TO_GL_ABSTRACTION ) ) + { + if ( IsDeactivated() ) + return; + } +#else + { + Assert( state != D3DRS_NOTSUPPORTED ); //Use SetSupportedRenderState() macro to avoid this at compile time + //if ( state == D3DRS_NOTSUPPORTED ) + // return; + } +#endif + + Assert( state >= 0 && ( int )state < MAX_NUM_RENDERSTATES ); + if ( m_DynamicState.m_RenderState[state] != val ) + { + if ( bFlushIfChanged ) + { + FlushBufferedPrimitives(); + } +#ifdef DX_TO_GL_ABSTRACTION + Dx9Device()->SetRenderStateInline( state, val ); +#else + Dx9Device()->SetRenderState( state, val ); +#endif + m_DynamicState.m_RenderState[state] = val; + } +} + +#ifdef DX_TO_GL_ABSTRACTION + // Purposely always writing the new state (even if it's not changed), in case SetRenderStateConstInline() compiles away to nothing (it sometimes does) + #define SetRenderStateConstMacro(t, state, val ) \ + do \ + { \ + Assert( state >= 0 && ( int )state < MAX_NUM_RENDERSTATES ); \ + if ( t->m_DynamicState.m_RenderState[state] != (DWORD)val ) \ + { \ + Dx9Device()->SetRenderStateConstInline( state, val ); \ + } \ + t->m_DynamicState.m_RenderState[state] = val; \ + } while(0) +#else + #define SetRenderStateConstMacro(t, state, val ) t->SetRenderState( state, val ); +#endif + +//----------------------------------------------------------------------------- +// Commits viewports +//----------------------------------------------------------------------------- +static void CommitSetScissorRect( IDirect3DDevice9 *pDevice, const DynamicState_t &desiredState, DynamicState_t ¤tState, bool bForce ) +{ + // Set the enable/disable renderstate + + bool bEnableChanged = desiredState.m_RenderState[D3DRS_SCISSORTESTENABLE] != currentState.m_RenderState[D3DRS_SCISSORTESTENABLE]; + if ( bEnableChanged ) + { + Dx9Device()->SetRenderState( D3DRS_SCISSORTESTENABLE, desiredState.m_RenderState[D3DRS_SCISSORTESTENABLE] ); + currentState.m_RenderState[D3DRS_SCISSORTESTENABLE] = desiredState.m_RenderState[D3DRS_SCISSORTESTENABLE]; + } + + // Only bother with the rect if we're enabling + if ( desiredState.m_RenderState[D3DRS_SCISSORTESTENABLE] ) + { + int nWidth, nHeight; + ITexture *pTexture = ShaderAPI()->GetRenderTargetEx( 0 ); + if ( pTexture == NULL ) + { + ShaderAPI()->GetBackBufferDimensions( nWidth, nHeight ); + } + else + { + nWidth = pTexture->GetActualWidth(); + nHeight = pTexture->GetActualHeight(); + } + + Assert( (desiredState.m_ScissorRect.left <= nWidth) && (desiredState.m_ScissorRect.bottom <= nHeight) && + ( desiredState.m_ScissorRect.top >= 0 ) && (desiredState.m_ScissorRect.left >= 0) ); + + clamp( desiredState.m_ScissorRect.right, 0, nWidth ); + clamp( desiredState.m_ScissorRect.left, 0, nWidth ); + clamp( desiredState.m_ScissorRect.top, 0, nHeight ); + clamp( desiredState.m_ScissorRect.bottom, 0, nHeight ); + + Dx9Device()->SetScissorRect( &desiredState.m_ScissorRect ); + currentState.m_ScissorRect = desiredState.m_ScissorRect; + } +} + +// Routine for setting scissor rect +// If pScissorRect is NULL, disable scissoring by setting the render state +// If pScissorRect is non-NULL, set the RECT state in Direct3D AND set the renderstate +inline void CShaderAPIDx8::SetScissorRect( const int nLeft, const int nTop, const int nRight, const int nBottom, const bool bEnableScissor ) +{ + Assert( (nLeft <= nRight) && (nTop <= nBottom) ); //360 craps itself if this isn't true + if ( !g_pHardwareConfig->Caps().m_bScissorSupported ) + return; + + // If we're turning it on, check the validity of the rect + if ( bEnableScissor ) + { + int nWidth, nHeight; + ITexture *pTexture = GetRenderTargetEx( 0 ); + if ( pTexture == NULL ) + { + GetBackBufferDimensions( nWidth, nHeight ); + } + else + { + nWidth = pTexture->GetActualWidth(); + nHeight = pTexture->GetActualHeight(); + } + + Assert( (nRight <= nWidth) && (nBottom <= nHeight) && ( nTop >= 0 ) && (nLeft >= 0) ); + + clamp( nRight, 0, nWidth ); + clamp( nLeft, 0, nWidth ); + clamp( nTop, 0, nHeight ); + clamp( nBottom, 0, nHeight ); + } + + DWORD dwEnableScissor = bEnableScissor ? TRUE : FALSE; + RECT newScissorRect; + newScissorRect.left = nLeft; + newScissorRect.top = nTop; + newScissorRect.right = nRight; + newScissorRect.bottom = nBottom; + + if ( !m_bResettingRenderState ) + { + bool bEnableChanged = m_DesiredState.m_RenderState[D3DRS_SCISSORTESTENABLE] != dwEnableScissor; + bool bRectChanged = memcmp( &newScissorRect, &m_DesiredState.m_ScissorRect, sizeof(RECT) ) != 0; + + if ( !bEnableChanged && !bRectChanged ) + return; + } + + if ( !IsDeactivated() ) + { + // Do we need to do this always? + FlushBufferedPrimitives(); + } + + m_DesiredState.m_RenderState[D3DRS_SCISSORTESTENABLE] = dwEnableScissor; + memcpy( &m_DesiredState.m_ScissorRect, &newScissorRect, sizeof(RECT) ); + + ADD_COMMIT_FUNC( COMMIT_PER_DRAW, COMMIT_ALWAYS, CommitSetScissorRect ); +} + +inline void CShaderAPIDx8::SetRenderStateForce( D3DRENDERSTATETYPE state, DWORD val ) +{ +#if ( !defined( _X360 ) && !defined( DX_TO_GL_ABSTRACTION ) ) + { + if ( IsDeactivated() ) + return; + } +#else + { + Assert( state != D3DRS_NOTSUPPORTED ); //Use SetSupportedRenderStateForce() macro to avoid this at compile time + //if ( state == D3DRS_NOTSUPPORTED ) + // return; + } +#endif + + Dx9Device()->SetRenderState( state, val ); + m_DynamicState.m_RenderState[state] = val; +} + + +//----------------------------------------------------------------------------- +// Set the values for pixel shader constants that don't change. +//----------------------------------------------------------------------------- +void CShaderAPIDx8::SetStandardVertexShaderConstants( float fOverbright ) +{ + LOCK_SHADERAPI(); + if ( g_pHardwareConfig->GetDXSupportLevel() < 80 ) + return; + + // Set a couple standard constants.... + Vector4D standardVertexShaderConstant( 0.0f, 1.0f, 2.0f, 0.5f ); + SetVertexShaderConstant( VERTEX_SHADER_MATH_CONSTANTS0, standardVertexShaderConstant.Base(), 1 ); + + // [ gamma, overbright, 1/3, 1/overbright ] + standardVertexShaderConstant.Init( 1.0f/2.2f, fOverbright, 1.0f / 3.0f, 1.0f / fOverbright ); + SetVertexShaderConstant( VERTEX_SHADER_MATH_CONSTANTS1, standardVertexShaderConstant.Base(), 1 ); + + int nModelIndex = g_pHardwareConfig->Caps().m_nDXSupportLevel < 90 ? VERTEX_SHADER_MODEL - 10 : VERTEX_SHADER_MODEL; + +/* + if ( g_pHardwareConfig->Caps().m_SupportsVertexShaders_3_0 ) + { + Vector4D factors[4]; + factors[0].Init( 1, 0, 0, 0 ); + factors[1].Init( 0, 1, 0, 0 ); + factors[2].Init( 0, 0, 1, 0 ); + factors[3].Init( 0, 0, 0, 1 ); + SetVertexShaderConstant( VERTEX_SHADER_DOT_PRODUCT_FACTORS, factors[0].Base(), 4 ); + } +*/ + + if ( g_pHardwareConfig->Caps().m_SupportsVertexShaders_2_0 ) + { + float c[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; + SetVertexShaderConstant( VERTEX_SHADER_FLEXSCALE, c, 1 ); + } + else + { + // These point to the lighting and the transforms + standardVertexShaderConstant.Init( + VERTEX_SHADER_LIGHTS, + VERTEX_SHADER_LIGHTS + 5, + // Use COLOR instead of UBYTE4 since Geforce3 does not support it + // vConst.w should be 3, but due to about hack, mul by 255 and add epsilon + // 360 supports UBYTE4, so no fixup required + (IsPC() || !IsX360()) ? 765.01f : 3.0f, + nModelIndex ); // DX8 has different constant packing + + SetVertexShaderConstant( VERTEX_SHADER_LIGHT_INDEX, standardVertexShaderConstant.Base(), 1 ); + } +} + +//----------------------------------------------------------------------------- +// Initialize vertex and pixel shaders +//----------------------------------------------------------------------------- +void CShaderAPIDx8::InitVertexAndPixelShaders() +{ + // Allocate space for the pixel and vertex shader constants... + if ( g_pHardwareConfig->Caps().m_SupportsPixelShaders ) + { + // pixel shaders + { + if (m_DynamicState.m_pVectorPixelShaderConstant) + { + delete[] m_DynamicState.m_pVectorPixelShaderConstant; + } + m_DynamicState.m_pVectorPixelShaderConstant = new Vector4D[g_pHardwareConfig->Caps().m_NumPixelShaderConstants]; + + if (m_DesiredState.m_pVectorPixelShaderConstant) + { + delete[] m_DesiredState.m_pVectorPixelShaderConstant; + } + m_DesiredState.m_pVectorPixelShaderConstant = new Vector4D[g_pHardwareConfig->Caps().m_NumPixelShaderConstants]; + + if (m_DynamicState.m_pBooleanPixelShaderConstant) + { + delete[] m_DynamicState.m_pBooleanPixelShaderConstant; + } + m_DynamicState.m_pBooleanPixelShaderConstant = new BOOL[g_pHardwareConfig->Caps().m_NumBooleanPixelShaderConstants]; + + if (m_DesiredState.m_pBooleanPixelShaderConstant) + { + delete[] m_DesiredState.m_pBooleanPixelShaderConstant; + } + m_DesiredState.m_pBooleanPixelShaderConstant = new BOOL[g_pHardwareConfig->Caps().m_NumBooleanPixelShaderConstants]; + + if (m_DynamicState.m_pIntegerPixelShaderConstant) + { + delete[] m_DynamicState.m_pIntegerPixelShaderConstant; + } + m_DynamicState.m_pIntegerPixelShaderConstant = new IntVector4D[g_pHardwareConfig->Caps().m_NumIntegerPixelShaderConstants]; + + if (m_DesiredState.m_pIntegerPixelShaderConstant) + { + delete[] m_DesiredState.m_pIntegerPixelShaderConstant; + } + m_DesiredState.m_pIntegerPixelShaderConstant = new IntVector4D[g_pHardwareConfig->Caps().m_NumIntegerPixelShaderConstants]; + + // force reset vector pixel constants + int i; + for ( i = 0; i < g_pHardwareConfig->Caps().m_NumPixelShaderConstants; ++i ) + { + m_DesiredState.m_pVectorPixelShaderConstant[i].Init(); + } + SetPixelShaderConstant( 0, m_DesiredState.m_pVectorPixelShaderConstant[0].Base(), g_pHardwareConfig->Caps().m_NumPixelShaderConstants, true ); + + // force reset boolean pixel constants + int nNumBooleanPixelShaderConstants = g_pHardwareConfig->Caps().m_NumBooleanPixelShaderConstants; + if ( nNumBooleanPixelShaderConstants ) + { + for ( i = 0; i < nNumBooleanPixelShaderConstants; ++i ) + { + m_DesiredState.m_pBooleanPixelShaderConstant[i] = 0; + } + SetBooleanPixelShaderConstant( 0, m_DesiredState.m_pBooleanPixelShaderConstant, nNumBooleanPixelShaderConstants, true ); + } + + // force reset integer pixel constants + int nNumIntegerPixelShaderConstants = g_pHardwareConfig->Caps().m_NumIntegerPixelShaderConstants; + if ( nNumIntegerPixelShaderConstants ) + { + for ( i = 0; i < nNumIntegerPixelShaderConstants; ++i ) + { + m_DesiredState.m_pIntegerPixelShaderConstant[i].Init(); + } + SetIntegerPixelShaderConstant( 0, m_DesiredState.m_pIntegerPixelShaderConstant[0].Base(), nNumIntegerPixelShaderConstants, true ); + } + } + + // vertex shaders + { + if (m_DynamicState.m_pVectorVertexShaderConstant) + { + delete[] m_DynamicState.m_pVectorVertexShaderConstant; + } + m_DynamicState.m_pVectorVertexShaderConstant = new Vector4D[g_pHardwareConfig->Caps().m_NumVertexShaderConstants]; + + if (m_DesiredState.m_pVectorVertexShaderConstant) + { + delete[] m_DesiredState.m_pVectorVertexShaderConstant; + } + m_DesiredState.m_pVectorVertexShaderConstant = new Vector4D[g_pHardwareConfig->Caps().m_NumVertexShaderConstants]; + + if (m_DynamicState.m_pBooleanVertexShaderConstant) + { + delete[] m_DynamicState.m_pBooleanVertexShaderConstant; + } + m_DynamicState.m_pBooleanVertexShaderConstant = new BOOL[g_pHardwareConfig->Caps().m_NumBooleanVertexShaderConstants]; + + if (m_DesiredState.m_pBooleanVertexShaderConstant) + { + delete[] m_DesiredState.m_pBooleanVertexShaderConstant; + } + m_DesiredState.m_pBooleanVertexShaderConstant = new BOOL[g_pHardwareConfig->Caps().m_NumBooleanVertexShaderConstants]; + + if (m_DynamicState.m_pIntegerVertexShaderConstant) + { + delete[] m_DynamicState.m_pIntegerVertexShaderConstant; + } + m_DynamicState.m_pIntegerVertexShaderConstant = new IntVector4D[g_pHardwareConfig->Caps().m_NumIntegerVertexShaderConstants]; + + if (m_DesiredState.m_pIntegerVertexShaderConstant) + { + delete[] m_DesiredState.m_pIntegerVertexShaderConstant; + } + m_DesiredState.m_pIntegerVertexShaderConstant = new IntVector4D[g_pHardwareConfig->Caps().m_NumIntegerVertexShaderConstants]; + + // force reset vector vertex constants + int i; + for ( i = 0; i < g_pHardwareConfig->Caps().m_NumVertexShaderConstants; ++i ) + { + m_DesiredState.m_pVectorVertexShaderConstant[i].Init(); + } + SetVertexShaderConstant( 0, m_DesiredState.m_pVectorVertexShaderConstant[0].Base(), g_pHardwareConfig->Caps().m_NumVertexShaderConstants, true ); + + // force reset boolean vertex constants + for ( i = 0; i < g_pHardwareConfig->Caps().m_NumBooleanVertexShaderConstants; ++i ) + { + m_DesiredState.m_pBooleanVertexShaderConstant[i] = 0; + } + SetBooleanVertexShaderConstant( 0, m_DesiredState.m_pBooleanVertexShaderConstant, g_pHardwareConfig->Caps().m_NumBooleanVertexShaderConstants, true ); + + // force reset integer vertex constants + for ( i = 0; i < g_pHardwareConfig->Caps().m_NumIntegerVertexShaderConstants; ++i ) + { + m_DesiredState.m_pIntegerVertexShaderConstant[i].Init(); + } + SetIntegerVertexShaderConstant( 0, m_DesiredState.m_pIntegerVertexShaderConstant[0].Base(), g_pHardwareConfig->Caps().m_NumIntegerVertexShaderConstants, true ); + } + + if ( IsX360() ) + { + // to init/update all constants, must disable ownership + bool bPreviousState = OwnGPUResources( false ); + WriteShaderConstantsToGPU(); + OwnGPUResources( bPreviousState ); + } + SetStandardVertexShaderConstants( OVERBRIGHT ); + } + + // Set up the vertex and pixel shader stuff + ShaderManager()->ResetShaderState(); +} + + +//----------------------------------------------------------------------------- +// Initialize render state +//----------------------------------------------------------------------------- +void CShaderAPIDx8::InitRenderState() +{ + // Set the default shadow state + g_pShaderShadowDx8->SetDefaultState(); + + // Grab a snapshot of this state; we'll be using it to set the board + // state to something well defined. + m_TransitionTable.TakeDefaultStateSnapshot(); + + if ( !IsDeactivated() ) + { + ResetRenderState(); + } +} + + +//----------------------------------------------------------------------------- +// Commits vertex textures +//----------------------------------------------------------------------------- +static void CommitVertexTextures( IDirect3DDevice9 *pDevice, const DynamicState_t &desiredState, DynamicState_t ¤tState, bool bForce ) +{ + int nCount = g_pMaterialSystemHardwareConfig->GetVertexTextureCount(); + for ( int i = 0; i < nCount; ++i ) + { + VertexTextureState_t ¤tVTState = currentState.m_VertexTextureState[i]; + ShaderAPITextureHandle_t textureHandle = desiredState.m_VertexTextureState[i].m_BoundTexture; + + Texture_t *pTexture = ( textureHandle != INVALID_SHADERAPI_TEXTURE_HANDLE ) ? &g_ShaderAPIDX8.GetTexture( textureHandle ) : NULL; + if ( pTexture && ( pTexture->m_Flags & Texture_t::IS_VERTEX_TEXTURE ) == 0 ) + { + Warning( "Attempting to bind a vertex texture (%s) which was not created as a vertex texture!\n", pTexture->m_DebugName.String() ); + } + + if ( bForce || ( currentVTState.m_BoundTexture != textureHandle ) ) + { + currentVTState.m_BoundTexture = textureHandle; + +// RECORD_COMMAND( DX8_SET_VERTEXTEXTURE, 3 ); +// RECORD_INT( D3DVERTEXTEXTURESAMPLER0 + nStage ); +// RECORD_INT( pTexture ? pTexture->GetUniqueID() : 0xFFFF ); +// RECORD_INT( 0 ); + + IDirect3DBaseTexture *pD3DTexture = ( textureHandle >= 0 ) ? g_ShaderAPIDX8.GetD3DTexture( textureHandle ) : NULL; + + pDevice->SetTexture( D3DVERTEXTEXTURESAMPLER0 + i, pD3DTexture ); + } + + if ( !pTexture ) + continue; + + D3DTEXTUREADDRESS nNewUTexWrap = pTexture->m_UTexWrap; + if ( bForce || ( currentVTState.m_UTexWrap != nNewUTexWrap ) ) + { + currentVTState.m_UTexWrap = nNewUTexWrap; + SetSamplerState( pDevice, D3DVERTEXTEXTURESAMPLER0 + i, D3DSAMP_ADDRESSU, currentVTState.m_UTexWrap ); + } + + D3DTEXTUREADDRESS nNewVTexWrap = pTexture->m_VTexWrap; + if ( bForce || ( currentVTState.m_VTexWrap != nNewVTexWrap ) ) + { + currentVTState.m_VTexWrap = nNewVTexWrap; + SetSamplerState( pDevice, D3DVERTEXTEXTURESAMPLER0 + i, D3DSAMP_ADDRESSV, currentVTState.m_VTexWrap ); + } + + /* + D3DTEXTUREADDRESS nNewWTexWrap = pTexture->GetWTexWrap(); + if ( bForce || ( currentVTState.m_WTexWrap != nNewWTexWrap ) ) + { + currentVTState.m_WTexWrap = nNewWTexWrap; + SetSamplerState( pDevice, D3DVERTEXTEXTURESAMPLER0 + i, D3DSAMP_ADDRESSW, currentVTState.m_WTexWrap ); + } + */ + + D3DTEXTUREFILTERTYPE nNewMinFilter = pTexture->m_MinFilter; + if ( bForce || ( currentVTState.m_MinFilter != nNewMinFilter ) ) + { + currentVTState.m_MinFilter = nNewMinFilter; + SetSamplerState( pDevice, D3DVERTEXTEXTURESAMPLER0 + i, D3DSAMP_MINFILTER, currentVTState.m_MinFilter ); + } + + D3DTEXTUREFILTERTYPE nNewMagFilter = pTexture->m_MagFilter; + if ( bForce || ( currentVTState.m_MagFilter != nNewMagFilter ) ) + { + currentVTState.m_MagFilter = nNewMagFilter; + SetSamplerState( pDevice, D3DVERTEXTEXTURESAMPLER0 + i, D3DSAMP_MAGFILTER, currentVTState.m_MagFilter ); + } + + D3DTEXTUREFILTERTYPE nNewMipFilter = pTexture->m_MipFilter; + if ( bForce || ( currentVTState.m_MipFilter != nNewMipFilter ) ) + { + currentVTState.m_MipFilter = nNewMipFilter; + SetSamplerState( pDevice, D3DVERTEXTEXTURESAMPLER0 + i, D3DSAMP_MIPFILTER, currentVTState.m_MipFilter ); + } + } +} + + +//----------------------------------------------------------------------------- +// Returns true if the state snapshot is translucent +//----------------------------------------------------------------------------- +bool CShaderAPIDx8::IsTranslucent( StateSnapshot_t id ) const +{ + LOCK_SHADERAPI(); + return m_TransitionTable.GetSnapshot(id).m_AlphaBlendEnable; +} + + +//----------------------------------------------------------------------------- +// Returns true if the state snapshot is alpha tested +//----------------------------------------------------------------------------- +bool CShaderAPIDx8::IsAlphaTested( StateSnapshot_t id ) const +{ + LOCK_SHADERAPI(); + return m_TransitionTable.GetSnapshot(id).m_AlphaTestEnable; +} + + +//----------------------------------------------------------------------------- +// Gets at the shadow state for a particular state snapshot +//----------------------------------------------------------------------------- +bool CShaderAPIDx8::IsDepthWriteEnabled( StateSnapshot_t id ) const +{ + LOCK_SHADERAPI(); + return m_TransitionTable.GetSnapshot(id).m_ZWriteEnable; +} + + + +//----------------------------------------------------------------------------- +// Returns true if the state snapshot uses shaders +//----------------------------------------------------------------------------- +bool CShaderAPIDx8::UsesVertexAndPixelShaders( StateSnapshot_t id ) const +{ + LOCK_SHADERAPI(); + return m_TransitionTable.GetSnapshotShader(id).m_VertexShader != INVALID_SHADER; +} + + +//----------------------------------------------------------------------------- +// Takes a snapshot +//----------------------------------------------------------------------------- +StateSnapshot_t CShaderAPIDx8::TakeSnapshot( ) +{ + LOCK_SHADERAPI(); + + return m_TransitionTable.TakeSnapshot(); +} + +void CShaderAPIDx8::ResetDXRenderState( void ) +{ + float zero = 0.0f; + float one = 1.0f; + DWORD dZero = *((DWORD*)(&zero)); + DWORD dOne = *((DWORD*)(&one)); + + // Set default values for all dx render states. + // NOTE: this does not include states encapsulated by the transition table, + // which are reset in CTransitionTable::UseDefaultState + SetSupportedRenderStateForce( D3DRS_FILLMODE, D3DFILL_SOLID ); + SetSupportedRenderStateForce( D3DRS_SHADEMODE, D3DSHADE_GOURAUD ); + SetSupportedRenderStateForce( D3DRS_LASTPIXEL, TRUE ); + SetSupportedRenderStateForce( D3DRS_CULLMODE, D3DCULL_CCW ); + SetSupportedRenderStateForce( D3DRS_DITHERENABLE, FALSE ); + SetSupportedRenderStateForce( D3DRS_FOGENABLE, FALSE ); + SetSupportedRenderStateForce( D3DRS_SPECULARENABLE, FALSE ); + SetSupportedRenderStateForce( D3DRS_FOGCOLOR, 0 ); + SetSupportedRenderStateForce( D3DRS_FOGTABLEMODE, D3DFOG_NONE ); + SetSupportedRenderStateForce( D3DRS_FOGSTART, dZero ); + SetSupportedRenderStateForce( D3DRS_FOGEND, dOne ); + SetSupportedRenderStateForce( D3DRS_FOGDENSITY, dZero ); + SetSupportedRenderStateForce( D3DRS_RANGEFOGENABLE, FALSE ); + SetSupportedRenderStateForce( D3DRS_STENCILENABLE, FALSE); + SetSupportedRenderStateForce( D3DRS_STENCILFAIL, D3DSTENCILOP_KEEP ); + SetSupportedRenderStateForce( D3DRS_STENCILZFAIL, D3DSTENCILOP_KEEP ); + SetSupportedRenderStateForce( D3DRS_STENCILPASS, D3DSTENCILOP_KEEP ); + SetSupportedRenderStateForce( D3DRS_STENCILFUNC, D3DCMP_ALWAYS ); + SetSupportedRenderStateForce( D3DRS_STENCILREF, 0 ); + SetSupportedRenderStateForce( D3DRS_STENCILMASK, 0xFFFFFFFF ); + SetSupportedRenderStateForce( D3DRS_STENCILWRITEMASK, 0xFFFFFFFF ); + SetSupportedRenderStateForce( D3DRS_TEXTUREFACTOR, 0xFFFFFFFF ); + SetSupportedRenderStateForce( D3DRS_WRAP0, 0 ); + SetSupportedRenderStateForce( D3DRS_WRAP1, 0 ); + SetSupportedRenderStateForce( D3DRS_WRAP2, 0 ); + SetSupportedRenderStateForce( D3DRS_WRAP3, 0 ); + SetSupportedRenderStateForce( D3DRS_WRAP4, 0 ); + SetSupportedRenderStateForce( D3DRS_WRAP5, 0 ); + SetSupportedRenderStateForce( D3DRS_WRAP6, 0 ); + SetSupportedRenderStateForce( D3DRS_WRAP7, 0 ); + SetSupportedRenderStateForce( D3DRS_CLIPPING, TRUE ); + SetSupportedRenderStateForce( D3DRS_LIGHTING, TRUE ); + SetSupportedRenderStateForce( D3DRS_AMBIENT, 0 ); + SetSupportedRenderStateForce( D3DRS_FOGVERTEXMODE, D3DFOG_NONE); + SetSupportedRenderStateForce( D3DRS_COLORVERTEX, TRUE ); + SetSupportedRenderStateForce( D3DRS_LOCALVIEWER, TRUE ); + SetSupportedRenderStateForce( D3DRS_NORMALIZENORMALS, FALSE ); + SetSupportedRenderStateForce( D3DRS_SPECULARMATERIALSOURCE, D3DMCS_COLOR2 ); + SetSupportedRenderStateForce( D3DRS_AMBIENTMATERIALSOURCE, D3DMCS_MATERIAL ); + SetSupportedRenderStateForce( D3DRS_EMISSIVEMATERIALSOURCE, D3DMCS_MATERIAL ); + SetSupportedRenderStateForce( D3DRS_VERTEXBLEND, D3DVBF_DISABLE ); + SetSupportedRenderStateForce( D3DRS_CLIPPLANEENABLE, 0 ); + + // -disable_d3d9_hacks is for debugging. For example, the "CENT" driver hack thing causes the flashlight pass to appear much brighter on NVidia drivers. + if ( IsPC() && !IsOpenGL() && !CommandLine()->CheckParm( "-disable_d3d9_hacks" ) ) + { + if ( g_pHardwareConfig->Caps().m_bNeedsATICentroidHack && ( g_pHardwareConfig->Caps().m_VendorID == VENDORID_ATI ) ) + { + SetSupportedRenderStateForce( D3DRS_POINTSIZE, MAKEFOURCC( 'C', 'E', 'N', 'T' ) ); + } + + if( g_pHardwareConfig->Caps().m_bDisableShaderOptimizations ) + { + SetSupportedRenderStateForce( D3DRS_ADAPTIVETESS_Y, MAKEFOURCC( 'C', 'O', 'P', 'M' ) ); + } + } + SetSupportedRenderStateForce( D3DRS_POINTSIZE, dOne ); + SetSupportedRenderStateForce( D3DRS_POINTSIZE_MIN, dOne ); + SetSupportedRenderStateForce( D3DRS_POINTSPRITEENABLE, FALSE ); + SetSupportedRenderStateForce( D3DRS_POINTSCALEENABLE, FALSE ); + SetSupportedRenderStateForce( D3DRS_POINTSCALE_A, dOne ); + SetSupportedRenderStateForce( D3DRS_POINTSCALE_B, dZero ); + SetSupportedRenderStateForce( D3DRS_POINTSCALE_C, dZero ); + SetSupportedRenderStateForce( D3DRS_MULTISAMPLEANTIALIAS, TRUE ); + SetSupportedRenderStateForce( D3DRS_MULTISAMPLEMASK, 0xFFFFFFFF ); + SetSupportedRenderStateForce( D3DRS_PATCHEDGESTYLE, D3DPATCHEDGE_DISCRETE ); + SetSupportedRenderStateForce( D3DRS_DEBUGMONITORTOKEN, D3DDMT_ENABLE ); + float sixtyFour = 64.0f; + SetSupportedRenderStateForce( D3DRS_POINTSIZE_MAX, *((DWORD*)(&sixtyFour))); + SetSupportedRenderStateForce( D3DRS_INDEXEDVERTEXBLENDENABLE, FALSE ); + SetSupportedRenderStateForce( D3DRS_TWEENFACTOR, dZero ); + SetSupportedRenderStateForce( D3DRS_POSITIONDEGREE, D3DDEGREE_CUBIC ); + SetSupportedRenderStateForce( D3DRS_NORMALDEGREE, D3DDEGREE_LINEAR ); + SetSupportedRenderStateForce( D3DRS_SCISSORTESTENABLE, FALSE); + SetSupportedRenderStateForce( D3DRS_SLOPESCALEDEPTHBIAS, dZero ); + SetSupportedRenderStateForce( D3DRS_ANTIALIASEDLINEENABLE, FALSE ); + SetSupportedRenderStateForce( D3DRS_MINTESSELLATIONLEVEL, dOne ); + SetSupportedRenderStateForce( D3DRS_MAXTESSELLATIONLEVEL, dOne ); + SetSupportedRenderStateForce( D3DRS_ADAPTIVETESS_X, dZero ); + SetSupportedRenderStateForce( D3DRS_ADAPTIVETESS_Y, dZero ); + SetSupportedRenderStateForce( D3DRS_ADAPTIVETESS_Z, dOne ); + SetSupportedRenderStateForce( D3DRS_ADAPTIVETESS_W, dZero ); + SetSupportedRenderStateForce( D3DRS_ENABLEADAPTIVETESSELLATION, FALSE ); + SetSupportedRenderStateForce( D3DRS_TWOSIDEDSTENCILMODE, FALSE ); + SetSupportedRenderStateForce( D3DRS_CCW_STENCILFAIL, D3DSTENCILOP_KEEP ); + SetSupportedRenderStateForce( D3DRS_CCW_STENCILZFAIL, D3DSTENCILOP_KEEP ); + SetSupportedRenderStateForce( D3DRS_CCW_STENCILPASS, D3DSTENCILOP_KEEP ); + SetSupportedRenderStateForce( D3DRS_CCW_STENCILFUNC, D3DCMP_ALWAYS ); + SetSupportedRenderStateForce( D3DRS_COLORWRITEENABLE1, 0x0000000f ); + SetSupportedRenderStateForce( D3DRS_COLORWRITEENABLE2, 0x0000000f ); + SetSupportedRenderStateForce( D3DRS_COLORWRITEENABLE3, 0x0000000f ); + SetSupportedRenderStateForce( D3DRS_BLENDFACTOR, 0xffffffff ); + SetSupportedRenderStateForce( D3DRS_SRGBWRITEENABLE, 0); + SetSupportedRenderStateForce( D3DRS_DEPTHBIAS, dZero ); + SetSupportedRenderStateForce( D3DRS_WRAP8, 0 ); + SetSupportedRenderStateForce( D3DRS_WRAP9, 0 ); + SetSupportedRenderStateForce( D3DRS_WRAP10, 0 ); + SetSupportedRenderStateForce( D3DRS_WRAP11, 0 ); + SetSupportedRenderStateForce( D3DRS_WRAP12, 0 ); + SetSupportedRenderStateForce( D3DRS_WRAP13, 0 ); + SetSupportedRenderStateForce( D3DRS_WRAP14, 0 ); + SetSupportedRenderStateForce( D3DRS_WRAP15, 0 ); + SetSupportedRenderStateForce( D3DRS_BLENDOP, D3DBLENDOP_ADD ); + SetSupportedRenderStateForce( D3DRS_BLENDOPALPHA, D3DBLENDOP_ADD ); + +#if defined( _X360 ) + SetSupportedRenderStateForce( D3DRS_HIZENABLE, D3DHIZ_AUTOMATIC ); + SetSupportedRenderStateForce( D3DRS_HIZWRITEENABLE, D3DHIZ_AUTOMATIC ); + + SetSupportedRenderStateForce( D3DRS_HISTENCILENABLE, FALSE ); + SetSupportedRenderStateForce( D3DRS_HISTENCILWRITEENABLE, FALSE ); + SetSupportedRenderStateForce( D3DRS_HISTENCILFUNC, D3DHSCMP_EQUAL ); + SetSupportedRenderStateForce( D3DRS_HISTENCILREF, 0 ); +#endif +} + +//----------------------------------------------------------------------------- +// Own GPU Resources. Return previous state. +//----------------------------------------------------------------------------- +bool CShaderAPIDx8::OwnGPUResources( bool bEnable ) +{ +#if defined( _X360 ) + if ( m_bGPUOwned == bEnable ) + { + return m_bGPUOwned; + } + + if ( !bEnable ) + { + Dx9Device()->GpuDisownAll(); + } + else + { + // owned GPU constants can be set very fast, and must be in blocks of 4 + // there are 256, but the game only uses 217 (snapped to 220), leaving just enough room for shader literals + COMPILE_TIME_ASSERT( VERTEX_SHADER_MODEL + 3*NUM_MODEL_TRANSFORMS == 217 ); + Dx9Device()->GpuOwnVertexShaderConstantF( 0, AlignValue( VERTEX_SHADER_MODEL + 3*NUM_MODEL_TRANSFORMS, 4 ) ); + // there are 256, but the game only utilizes 32, leaving lots of room for shader literals + Dx9Device()->GpuOwnPixelShaderConstantF( 0, 32 ); + } + + bool bPrevious = m_bGPUOwned; + m_bGPUOwned = bEnable; + + return bPrevious; +#else + return false; +#endif +} + +//----------------------------------------------------------------------------- +// Reset render state (to its initial value) +//----------------------------------------------------------------------------- +void CShaderAPIDx8::ResetRenderState( bool bFullReset ) +{ + LOCK_SHADERAPI(); + RECORD_DEBUG_STRING( "BEGIN ResetRenderState" ); + + if ( !CanDownloadTextures() ) + { + QueueResetRenderState(); + return; + } + + m_bResettingRenderState = true; + + OwnGPUResources( true ); + + ResetDXRenderState(); + + // We're not currently rendering anything + m_nCurrentSnapshot = -1; + + D3DXMatrixIdentity( &m_CachedPolyOffsetProjectionMatrix ); + D3DXMatrixIdentity( &m_CachedFastClipProjectionMatrix ); + D3DXMatrixIdentity( &m_CachedFastClipPolyOffsetProjectionMatrix ); + m_UsingTextureRenderTarget = false; + + m_SceneFogColor[0] = 0; + m_SceneFogColor[1] = 0; + m_SceneFogColor[2] = 0; + m_SceneFogMode = MATERIAL_FOG_NONE; + + // This is state that isn't part of the snapshot per-se, because we + // don't need it when it's actually time to render. This just helps us + // to construct the shadow state. + m_DynamicState.m_ClearColor = D3DCOLOR_XRGB(0,0,0); + + if ( bFullReset ) + { + InitVertexAndPixelShaders(); + } + else + { + // just need to dirty the dynamic state, desired state gets copied into below + Q_memset( m_DynamicState.m_pVectorPixelShaderConstant, 0, g_pHardwareConfig->Caps().m_NumPixelShaderConstants * sizeof( Vector4D ) ); + Q_memset( m_DynamicState.m_pBooleanPixelShaderConstant, 0, g_pHardwareConfig->Caps().m_NumBooleanPixelShaderConstants * sizeof( BOOL ) ); + Q_memset( m_DynamicState.m_pIntegerPixelShaderConstant, 0, g_pHardwareConfig->Caps().m_NumIntegerPixelShaderConstants * sizeof( IntVector4D ) ); + + Q_memset( m_DynamicState.m_pVectorVertexShaderConstant, 0, g_pHardwareConfig->Caps().m_NumVertexShaderConstants * sizeof( Vector4D ) ); + Q_memset( m_DynamicState.m_pBooleanVertexShaderConstant, 0, g_pHardwareConfig->Caps().m_NumBooleanVertexShaderConstants * sizeof( BOOL ) ); + Q_memset( m_DynamicState.m_pIntegerVertexShaderConstant, 0, g_pHardwareConfig->Caps().m_NumIntegerVertexShaderConstants * sizeof( IntVector4D ) ); + + SetStandardVertexShaderConstants( OVERBRIGHT ); + } + + //Set the default compressed depth range written to dest alpha. Only need to compress it for 8bit alpha to get a useful gradient. + m_DynamicState.m_DestAlphaDepthRange = (g_pHardwareConfig->GetHDRType() == HDR_TYPE_FLOAT) ? 8192.0f : 192.0f; + + m_CachedAmbientLightCube = STATE_CHANGED; + + // Set the constant color + m_DynamicState.m_ConstantColor = 0xFFFFFFFF; + Color4ub( 255, 255, 255, 255 ); + + // Ambient light color + m_DynamicState.m_Ambient = 0; + SetSupportedRenderState( D3DRS_AMBIENT, m_DynamicState.m_Ambient ); + + // Fog + m_VertexShaderFogParams[0] = m_VertexShaderFogParams[1] = 0.0f; + m_WorldSpaceCameraPositon.Init( 0, 0, 0.01f, 0 ); // Don't let z be zero, as some pixel shaders will divide by this + m_DynamicState.m_FogColor = 0xFFFFFFFF; + m_DynamicState.m_PixelFogColor[0] = m_DynamicState.m_PixelFogColor[1] = + m_DynamicState.m_PixelFogColor[2] = m_DynamicState.m_PixelFogColor[3] = 0.0f; + m_DynamicState.m_bFogGammaCorrectionDisabled = false; + m_DynamicState.m_FogEnable = false; + m_DynamicState.m_SceneFog = MATERIAL_FOG_NONE; + m_DynamicState.m_FogMode = D3DFOG_NONE; + m_DynamicState.m_FogStart = -1; + m_DynamicState.m_FogEnd = -1; + m_DynamicState.m_FogMaxDensity = -1.0f; + m_DynamicState.m_FogZ = 0.0f; + + SetSupportedRenderState( D3DRS_FOGCOLOR, m_DynamicState.m_FogColor ); + SetSupportedRenderState( D3DRS_FOGENABLE, m_DynamicState.m_FogEnable ); + SetSupportedRenderState( D3DRS_FOGTABLEMODE, D3DFOG_NONE ); + SetSupportedRenderState( D3DRS_FOGVERTEXMODE, D3DFOG_NONE ); + SetSupportedRenderState( D3DRS_RANGEFOGENABLE, false ); + + FogStart( 0 ); + FogEnd( 0 ); + FogMaxDensity( 1.0f ); + + m_DynamicState.m_bSRGBWritesEnabled = false; + + // Set the cull mode + m_DynamicState.m_bCullEnabled = true; + m_DynamicState.m_CullMode = D3DCULL_CCW; + m_DynamicState.m_DesiredCullMode = D3DCULL_CCW; + SetRenderState( D3DRS_CULLMODE, D3DCULL_CCW ); + + // No shade mode yet + m_DynamicState.m_ShadeMode = (D3DSHADEMODE)-1; + ShadeMode( SHADER_SMOOTH ); + + m_DynamicState.m_bHWMorphingEnabled = false; + + // Skinning... + m_DynamicState.m_NumBones = 0; + m_DynamicState.m_VertexBlend = (D3DVERTEXBLENDFLAGS)-1; + SetSupportedRenderState( D3DRS_VERTEXBLEND, D3DVBF_DISABLE ); + SetSupportedRenderState( D3DRS_INDEXEDVERTEXBLENDENABLE, FALSE ); + + // No normal normalization + m_DynamicState.m_NormalizeNormals = false; + SetSupportedRenderState( D3DRS_NORMALIZENORMALS, m_DynamicState.m_NormalizeNormals ); + + bool bAntialiasing = ( m_PresentParameters.MultiSampleType != D3DMULTISAMPLE_NONE ); + if ( g_pHardwareConfig->GetHDRType() == HDR_TYPE_FLOAT ) + { + bAntialiasing = false; + } + SetRenderState( D3DRS_MULTISAMPLEANTIALIAS, bAntialiasing ); + + // Anisotropic filtering is disabled by default + if ( bFullReset ) + { + SetAnisotropicLevel( 1 ); + } + + int i; + for ( i = 0; i < g_pHardwareConfig->ActualCaps().m_NumTextureStages; ++i ) + { + TextureStage(i).m_TextureTransformFlags = D3DTTFF_DISABLE; + TextureStage(i).m_BumpEnvMat00 = 1.0f; + TextureStage(i).m_BumpEnvMat01 = 0.0f; + TextureStage(i).m_BumpEnvMat10 = 0.0f; + TextureStage(i).m_BumpEnvMat11 = 1.0f; + + SetTextureStageState( i, D3DTSS_TEXTURETRANSFORMFLAGS, TextureStage(i).m_TextureTransformFlags ); + SetTextureStageState( i, D3DTSS_BUMPENVMAT00, *( ( LPDWORD ) (&TextureStage(i).m_BumpEnvMat00) ) ); + SetTextureStageState( i, D3DTSS_BUMPENVMAT01, *( ( LPDWORD ) (&TextureStage(i).m_BumpEnvMat01) ) ); + SetTextureStageState( i, D3DTSS_BUMPENVMAT10, *( ( LPDWORD ) (&TextureStage(i).m_BumpEnvMat10) ) ); + SetTextureStageState( i, D3DTSS_BUMPENVMAT11, *( ( LPDWORD ) (&TextureStage(i).m_BumpEnvMat11) ) ); + } + + for ( i = 0; i < g_pHardwareConfig->ActualCaps().m_NumSamplers; ++i ) + { + SamplerState(i).m_BoundTexture = INVALID_SHADERAPI_TEXTURE_HANDLE; + SamplerState(i).m_UTexWrap = D3DTADDRESS_WRAP; + SamplerState(i).m_VTexWrap = D3DTADDRESS_WRAP; + SamplerState(i).m_WTexWrap = D3DTADDRESS_WRAP; + SamplerState(i).m_MagFilter = D3DTEXF_POINT; + SamplerState(i).m_MinFilter = D3DTEXF_POINT; + SamplerState(i).m_MipFilter = D3DTEXF_NONE; + SamplerState(i).m_FinestMipmapLevel = 0; + SamplerState(i).m_LodBias = 0.0f; + SamplerState(i).m_TextureEnable = false; + SamplerState(i).m_SRGBReadEnable = false; + + // Just some initial state... + Dx9Device()->SetTexture( i, 0 ); + + SetSamplerState( i, D3DSAMP_ADDRESSU, SamplerState(i).m_UTexWrap ); + SetSamplerState( i, D3DSAMP_ADDRESSV, SamplerState(i).m_VTexWrap ); + SetSamplerState( i, D3DSAMP_ADDRESSW, SamplerState(i).m_WTexWrap ); + SetSamplerState( i, D3DSAMP_MINFILTER, SamplerState(i).m_MinFilter ); + SetSamplerState( i, D3DSAMP_MAGFILTER, SamplerState(i).m_MagFilter ); + SetSamplerState( i, D3DSAMP_MIPFILTER, SamplerState(i).m_MipFilter ); + SetSamplerState( i, D3DSAMP_MAXMIPLEVEL, SamplerState(i).m_FinestMipmapLevel ); + SetSamplerState( i, D3DSAMP_MIPMAPLODBIAS, SamplerState(i).m_LodBias ); + + SetSamplerState( i, D3DSAMP_BORDERCOLOR, RGB( 0,0,0 ) ); + } + + // FIXME!!!!! : This barfs with the debug runtime on 6800. + for( i = 0; i < g_pHardwareConfig->ActualCaps().m_nVertexTextureCount; i++ ) + { + m_DynamicState.m_VertexTextureState[i].m_BoundTexture = INVALID_SHADERAPI_TEXTURE_HANDLE; + Dx9Device()->SetTexture( D3DVERTEXTEXTURESAMPLER0 + i, NULL ); + + m_DynamicState.m_VertexTextureState[i].m_UTexWrap = D3DTADDRESS_CLAMP; + m_DynamicState.m_VertexTextureState[i].m_VTexWrap = D3DTADDRESS_CLAMP; +// m_DynamicState.m_VertexTextureState[i].m_WTexWrap = D3DTADDRESS_CLAMP; + m_DynamicState.m_VertexTextureState[i].m_MinFilter = D3DTEXF_POINT; + m_DynamicState.m_VertexTextureState[i].m_MagFilter = D3DTEXF_POINT; + m_DynamicState.m_VertexTextureState[i].m_MipFilter = D3DTEXF_POINT; + SetSamplerState( D3DVERTEXTEXTURESAMPLER0 + i, D3DSAMP_ADDRESSU, m_DynamicState.m_VertexTextureState[i].m_UTexWrap ); + SetSamplerState( D3DVERTEXTEXTURESAMPLER0 + i, D3DSAMP_ADDRESSV, m_DynamicState.m_VertexTextureState[i].m_VTexWrap ); +// SetSamplerState( D3DVERTEXTEXTURESAMPLER0 + i, D3DSAMP_ADDRESSW, m_DynamicState.m_VertexTextureState[i].m_WTexWrap ); + SetSamplerState( D3DVERTEXTEXTURESAMPLER0 + i, D3DSAMP_MINFILTER, m_DynamicState.m_VertexTextureState[i].m_MinFilter ); + SetSamplerState( D3DVERTEXTEXTURESAMPLER0 + i, D3DSAMP_MAGFILTER, m_DynamicState.m_VertexTextureState[i].m_MagFilter ); + SetSamplerState( D3DVERTEXTEXTURESAMPLER0 + i, D3DSAMP_MIPFILTER, m_DynamicState.m_VertexTextureState[i].m_MipFilter ); + } + + m_DynamicState.m_NumLights = 0; + for ( i = 0; i < MAX_NUM_LIGHTS; ++i) + { + m_DynamicState.m_LightEnable[i] = false; + m_DynamicState.m_LightChanged[i] = STATE_CHANGED; + m_DynamicState.m_LightEnableChanged[i] = STATE_CHANGED; + } + + for ( i = 0; i < NUM_MATRIX_MODES; ++i) + { + // By setting this to *not* be identity, we force an update... + m_DynamicState.m_TransformType[i] = TRANSFORM_IS_GENERAL; + m_DynamicState.m_TransformChanged[i] = STATE_CHANGED; + } + + // set the board state to match the default state + m_TransitionTable.UseDefaultState(); + + // Set the default render state + SetDefaultState(); + + // Constant for all time + SetSupportedRenderState( D3DRS_CLIPPING, TRUE ); + SetSupportedRenderState( D3DRS_LOCALVIEWER, TRUE ); + SetSupportedRenderState( D3DRS_POINTSCALEENABLE, FALSE ); + SetSupportedRenderState( D3DRS_DIFFUSEMATERIALSOURCE, D3DMCS_MATERIAL ); + SetSupportedRenderState( D3DRS_SPECULARMATERIALSOURCE, D3DMCS_COLOR2 ); + SetSupportedRenderState( D3DRS_AMBIENTMATERIALSOURCE, D3DMCS_MATERIAL ); + SetSupportedRenderState( D3DRS_EMISSIVEMATERIALSOURCE, D3DMCS_MATERIAL ); + SetSupportedRenderState( D3DRS_COLORVERTEX, TRUE ); // This defaults to true anyways. . . + + // Set a default identity material. + SetDefaultMaterial(); + +#if 0 + float fBias = -1.0f; + SetTextureStageState( 0, D3DTSS_MIPMAPLODBIAS, *( ( LPDWORD ) (&fBias) ) ); + SetTextureStageState( 1, D3DTSS_MIPMAPLODBIAS, *( ( LPDWORD ) (&fBias) ) ); + SetTextureStageState( 2, D3DTSS_MIPMAPLODBIAS, *( ( LPDWORD ) (&fBias) ) ); + SetTextureStageState( 3, D3DTSS_MIPMAPLODBIAS, *( ( LPDWORD ) (&fBias) ) ); +#endif + + if ( bFullReset ) + { + // Set the modelview matrix to identity too + for ( i = 0; i < NUM_MODEL_TRANSFORMS; ++i ) + { + SetIdentityMatrix( m_boneMatrix[i] ); + } + MatrixMode( MATERIAL_VIEW ); + LoadIdentity(); + MatrixMode( MATERIAL_PROJECTION ); + LoadIdentity(); + } + +#ifdef _X360 + m_DynamicState.m_bBuffer2Frames = m_bBuffer2FramesAhead; + SetRenderState( D3DRS_BUFFER2FRAMES, m_DynamicState.m_bBuffer2Frames ); +#endif + + m_DynamicState.m_Viewport.X = m_DynamicState.m_Viewport.Y = + m_DynamicState.m_Viewport.Width = m_DynamicState.m_Viewport.Height = 0xFFFFFFFF; + m_DynamicState.m_Viewport.MinZ = m_DynamicState.m_Viewport.MaxZ = 0.0; + + // Be sure scissoring is off + m_DynamicState.m_RenderState[D3DRS_SCISSORTESTENABLE] = FALSE; + SetRenderState( D3DRS_SCISSORTESTENABLE, FALSE ); + m_DynamicState.m_ScissorRect.left = -1; + m_DynamicState.m_ScissorRect.top = -1; + m_DynamicState.m_ScissorRect.right = -1; + m_DynamicState.m_ScissorRect.bottom = -1; + + //SetHeightClipMode( MATERIAL_HEIGHTCLIPMODE_DISABLE ); + EnableFastClip( false ); + float fFakePlane[4]; + unsigned int iFakePlaneVal = 0xFFFFFFFF; + fFakePlane[0] = fFakePlane[1] = fFakePlane[2] = fFakePlane[3] = *((float *)&iFakePlaneVal); + SetFastClipPlane( fFakePlane ); //doing this to better wire up plane change detection + + float zero[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; + + // Make sure that our state is dirty. + m_DynamicState.m_UserClipPlaneEnabled = 0; + m_DynamicState.m_UserClipPlaneChanged = 0; + m_DynamicState.m_UserClipLastUpdatedUsingFixedFunction = false; + for( i = 0; i < g_pHardwareConfig->MaxUserClipPlanes(); i++ ) + { + // Make sure that our state is dirty. + m_DynamicState.m_UserClipPlaneWorld[i][0] = -1.0f; + m_DynamicState.m_UserClipPlaneProj[i][0] = -9999.0f; + m_DynamicState.m_UserClipPlaneEnabled |= ( 1 << i ); + SetClipPlane( i, zero ); + EnableClipPlane( i, false ); + Assert( m_DynamicState.m_UserClipPlaneEnabled == 0 ); + } + Assert( m_DynamicState.m_UserClipPlaneChanged == ((1 << g_pHardwareConfig->MaxUserClipPlanes()) - 1) ); + + m_DynamicState.m_FastClipEnabled = false; + m_DynamicState.m_bFastClipPlaneChanged = true; + + // User clip override + m_DynamicState.m_bUserClipTransformOverride = false; + D3DXMatrixIdentity( &m_DynamicState.m_UserClipTransform ); + + // Viewport defaults to the window size + RECT windowRect; +#if !defined( DX_TO_GL_ABSTRACTION ) + GetClientRect( (HWND)m_hWnd, &windowRect ); +#else + toglGetClientRect( (VD3DHWND)m_hWnd, &windowRect ); +#endif + + ShaderViewport_t viewport; + viewport.Init( windowRect.left, windowRect.top, + windowRect.right - windowRect.left, windowRect.bottom - windowRect.top ); + SetViewports( 1, &viewport ); + + // No render mesh + m_pRenderMesh = 0; + + // Reset cached vertex decl + m_DynamicState.m_pVertexDecl = NULL; + + // Reset the render target to be the normal backbuffer + if ( IsX360() ) + { + m_hCachedRenderTarget = INVALID_SHADERAPI_TEXTURE_HANDLE; + m_bUsingSRGBRenderTarget = false; + } + AcquireInternalRenderTargets(); + SetRenderTarget(); + + // Maintain vertex + pixel shader constant buffers + Vector4D *pVectorPixelShaderConstants = m_DesiredState.m_pVectorPixelShaderConstant; + int *pBooleanPixelShaderConstants = m_DesiredState.m_pBooleanPixelShaderConstant; + IntVector4D *pIntegerPixelShaderConstants = m_DesiredState.m_pIntegerPixelShaderConstant; + Vector4D *pVectorVertexShaderConstants = m_DesiredState.m_pVectorVertexShaderConstant; + int *pBooleanVertexShaderConstants = m_DesiredState.m_pBooleanVertexShaderConstant; + IntVector4D *pIntegerVertexShaderConstants = m_DesiredState.m_pIntegerVertexShaderConstant; + m_DesiredState = m_DynamicState; + m_DesiredState.m_pVectorPixelShaderConstant = pVectorPixelShaderConstants; + m_DesiredState.m_pBooleanPixelShaderConstant = pBooleanPixelShaderConstants; + m_DesiredState.m_pIntegerPixelShaderConstant = pIntegerPixelShaderConstants; + m_DesiredState.m_pVectorVertexShaderConstant = pVectorVertexShaderConstants; + m_DesiredState.m_pBooleanVertexShaderConstant = pBooleanVertexShaderConstants; + m_DesiredState.m_pIntegerVertexShaderConstant = pIntegerVertexShaderConstants; + if ( g_pHardwareConfig->Caps().m_SupportsPixelShaders ) + { + if ( !bFullReset ) + { + //Full resets init the values to defaults. Normal resets just leave them dirty. + if( g_pHardwareConfig->Caps().m_NumVertexShaderConstants != 0 ) + SetVertexShaderConstant( 0, m_DesiredState.m_pVectorVertexShaderConstant[0].Base(), IsX360() ? 217 : g_pHardwareConfig->Caps().m_NumVertexShaderConstants, true ); //217 on X360 to play nice with fast blatting code + + if( g_pHardwareConfig->Caps().m_NumIntegerVertexShaderConstants != 0 ) + SetIntegerVertexShaderConstant( 0, (int *)m_DesiredState.m_pIntegerVertexShaderConstant, g_pHardwareConfig->Caps().m_NumIntegerVertexShaderConstants, true ); + + if( g_pHardwareConfig->Caps().m_NumBooleanVertexShaderConstants != 0 ) + SetBooleanVertexShaderConstant( 0, m_DesiredState.m_pBooleanVertexShaderConstant, g_pHardwareConfig->Caps().m_NumBooleanVertexShaderConstants, true ); + + + if( g_pHardwareConfig->Caps().m_NumPixelShaderConstants != 0 ) + SetPixelShaderConstant( 0, m_DesiredState.m_pVectorPixelShaderConstant[0].Base(), g_pHardwareConfig->Caps().m_NumPixelShaderConstants, true ); + + if( g_pHardwareConfig->Caps().m_NumIntegerPixelShaderConstants != 0 ) + SetIntegerPixelShaderConstant( 0, (int *)m_DesiredState.m_pIntegerPixelShaderConstant, g_pHardwareConfig->Caps().m_NumIntegerPixelShaderConstants, true ); + + if( g_pHardwareConfig->Caps().m_NumBooleanPixelShaderConstants != 0 ) + SetBooleanPixelShaderConstant( 0, m_DesiredState.m_pBooleanPixelShaderConstant, g_pHardwareConfig->Caps().m_NumBooleanPixelShaderConstants, true ); + } + } + + RECORD_DEBUG_STRING( "END ResetRenderState" ); + + m_bResettingRenderState = false; +} + +//----------------------------------------------------------------------------- +// Sets the default render state +//----------------------------------------------------------------------------- +void CShaderAPIDx8::SetDefaultState() +{ + LOCK_SHADERAPI(); + + // NOTE: This used to be in the material system, but I want to avoid all the per pass/batch + // virtual function calls. + int numTextureStages = g_pHardwareConfig->GetTextureStageCount(); + + // FIXME: This is a brutal hack. We only need to load these transforms for fixed-function + // hardware. Cap the max here to 4. + if ( IsPC() ) + { + numTextureStages = min( numTextureStages, 4 ); + int i; + for( i = 0; i < numTextureStages; i++ ) + { + CShaderAPIDx8::DisableTextureTransform( (TextureStage_t)i ); + CShaderAPIDx8::MatrixMode( (MaterialMatrixMode_t)(MATERIAL_TEXTURE0 + i) ); + CShaderAPIDx8::LoadIdentity( ); + } + } + CShaderAPIDx8::MatrixMode( MATERIAL_MODEL ); + + CShaderAPIDx8::Color4ub( 255, 255, 255, 255 ); + CShaderAPIDx8::ShadeMode( SHADER_SMOOTH ); + CShaderAPIDx8::SetVertexShaderIndex( ); + CShaderAPIDx8::SetPixelShaderIndex( ); + + MeshMgr()->MarkUnusedVertexFields( 0, 0, NULL ); +} + + + +//----------------------------------------------------------------------------- +// +// Methods related to vertex format +// +//----------------------------------------------------------------------------- + + +//----------------------------------------------------------------------------- +// Sets the vertex +//----------------------------------------------------------------------------- +inline void CShaderAPIDx8::SetVertexDecl( VertexFormat_t vertexFormat, bool bHasColorMesh, bool bUsingFlex, bool bUsingMorph ) +{ + VPROF("CShaderAPIDx8::SetVertexDecl"); + IDirect3DVertexDeclaration9 *pDecl = FindOrCreateVertexDecl( vertexFormat, bHasColorMesh, bUsingFlex, bUsingMorph ); + Assert( pDecl ); + + if ( ( pDecl != m_DynamicState.m_pVertexDecl ) && pDecl ) + { + Dx9Device()->SetVertexDeclaration( pDecl ); + m_DynamicState.m_pVertexDecl = pDecl; + } +} + + + +//----------------------------------------------------------------------------- +// +// Methods related to vertex buffers +// +//----------------------------------------------------------------------------- + +IMesh *CShaderAPIDx8::GetFlexMesh() +{ + LOCK_SHADERAPI(); + return MeshMgr()->GetFlexMesh(); +} + +//----------------------------------------------------------------------------- +// Gets the dynamic mesh +//----------------------------------------------------------------------------- +IMesh* CShaderAPIDx8::GetDynamicMesh( IMaterial* pMaterial, int nHWSkinBoneCount, bool buffered, + IMesh* pVertexOverride, IMesh* pIndexOverride ) +{ + Assert( (pMaterial == NULL) || ((IMaterialInternal *)pMaterial)->IsRealTimeVersion() ); + + LOCK_SHADERAPI(); + return MeshMgr()->GetDynamicMesh( pMaterial, 0, nHWSkinBoneCount, buffered, pVertexOverride, pIndexOverride ); +} + +IMesh* CShaderAPIDx8::GetDynamicMeshEx( IMaterial* pMaterial, VertexFormat_t vertexFormat, int nHWSkinBoneCount, + bool bBuffered, IMesh* pVertexOverride, IMesh* pIndexOverride ) +{ + Assert( (pMaterial == NULL) || ((IMaterialInternal *)pMaterial)->IsRealTimeVersion() ); + + LOCK_SHADERAPI(); + return MeshMgr()->GetDynamicMesh( pMaterial, vertexFormat, nHWSkinBoneCount, bBuffered, pVertexOverride, pIndexOverride ); +} + +//----------------------------------------------------------------------------- +// Returns the number of vertices we can render using the dynamic mesh +//----------------------------------------------------------------------------- +void CShaderAPIDx8::GetMaxToRender( IMesh *pMesh, bool bMaxUntilFlush, int *pMaxVerts, int *pMaxIndices ) +{ + LOCK_SHADERAPI(); + MeshMgr()->GetMaxToRender( pMesh, bMaxUntilFlush, pMaxVerts, pMaxIndices ); +} + +int CShaderAPIDx8::GetMaxVerticesToRender( IMaterial *pMaterial ) +{ + pMaterial = ((IMaterialInternal *)pMaterial)->GetRealTimeVersion(); //always work with the realtime version internally + + LOCK_SHADERAPI(); + return MeshMgr()->GetMaxVerticesToRender( pMaterial ); +} + +int CShaderAPIDx8::GetMaxIndicesToRender( ) +{ + LOCK_SHADERAPI(); + return MeshMgr()->GetMaxIndicesToRender( ); +} + +void CShaderAPIDx8::MarkUnusedVertexFields( unsigned int nFlags, int nTexCoordCount, bool *pUnusedTexCoords ) +{ + LOCK_SHADERAPI(); + MeshMgr()->MarkUnusedVertexFields( nFlags, nTexCoordCount, pUnusedTexCoords ); +} + +//----------------------------------------------------------------------------- +// Draws the mesh +//----------------------------------------------------------------------------- +void CShaderAPIDx8::DrawMesh( CMeshBase *pMesh ) +{ + VPROF("CShaderAPIDx8::DrawMesh"); + if ( ShaderUtil()->GetConfig().m_bSuppressRendering ) + return; + +#if defined( PIX_INSTRUMENTATION ) || defined( NVPERFHUD ) + PIXifyName( s_pPIXMaterialName, sizeof( s_pPIXMaterialName ), m_pMaterial->GetName() ); + BeginPIXEvent( PIX_VALVE_ORANGE, s_pPIXMaterialName ); +#endif + + m_pRenderMesh = pMesh; + VertexFormat_t vertexFormat = m_pRenderMesh->GetVertexFormat(); + SetVertexDecl( vertexFormat, m_pRenderMesh->HasColorMesh(), m_pRenderMesh->HasFlexMesh(), m_pMaterial->IsUsingVertexID() ); + CommitStateChanges(); + Assert( m_pRenderMesh && m_pMaterial ); + m_pMaterial->DrawMesh( CompressionType( vertexFormat ) ); + m_pRenderMesh = NULL; + +#if defined( PIX_INSTRUMENTATION ) || defined( NVPERFHUD ) + EndPIXEvent(); +#endif +} + +void CShaderAPIDx8::DrawWithVertexAndIndexBuffers( void ) +{ + VPROF("CShaderAPIDx8::DrawWithVertexAndIndexBuffers"); + if ( ShaderUtil()->GetConfig().m_bSuppressRendering ) + return; + +#if defined( PIX_INSTRUMENTATION ) || defined( NVPERFHUD ) + PIXifyName( s_pPIXMaterialName, sizeof( s_pPIXMaterialName ), m_pMaterial->GetName()); + BeginPIXEvent( PIX_VALVE_ORANGE, s_pPIXMaterialName ); +#endif + +// m_pRenderMesh = pMesh; + // FIXME: need to make this deal with multiple streams, etc. + VertexFormat_t vertexFormat = MeshMgr()->GetCurrentVertexFormat(); + SetVertexDecl( vertexFormat, false /*m_pRenderMesh->HasColorMesh()*/, + false /*m_pRenderMesh->HasFlexMesh()*/, false /*m_pRenderMesh->IsUsingMorphData()*/ ); + CommitStateChanges(); + if ( m_pMaterial ) + { + m_pMaterial->DrawMesh( CompressionType( vertexFormat ) ); + } + else + { + MeshMgr()->RenderPassWithVertexAndIndexBuffers(); + } +// m_pRenderMesh = NULL; + +#if defined( PIX_INSTRUMENTATION ) || defined( NVPERFHUD ) + EndPIXEvent(); +#endif +} + +//----------------------------------------------------------------------------- +// Discards the vertex buffers +//----------------------------------------------------------------------------- +void CShaderAPIDx8::DiscardVertexBuffers() +{ + MeshMgr()->DiscardVertexBuffers(); +} + +void CShaderAPIDx8::ForceHardwareSync_WithManagedTexture() +{ + if ( IsX360() || !m_pFrameSyncTexture ) + return; + + // Set the default state for everything so we don't get more than we ask for here! + SetDefaultState(); + + D3DLOCKED_RECT rect; + + tmZone( TELEMETRY_LEVEL1, TMZF_NONE, "%s", __FUNCTION__ ); + + HRESULT hr = m_pFrameSyncTexture->LockRect( 0, &rect, NULL, 0 ); + if ( SUCCEEDED( hr ) ) + { + // modify.. + unsigned long *pData = (unsigned long*)rect.pBits; + (*pData)++; + + m_pFrameSyncTexture->UnlockRect( 0 ); + + // Now draw something with this texture. + DWORD iStage = 0; + IDirect3DBaseTexture9 *pOldTexture; + hr = Dx9Device()->GetTexture( iStage, &pOldTexture ); + if ( SUCCEEDED( hr ) ) + { + Dx9Device()->SetTexture( iStage, m_pFrameSyncTexture ); + // Remember the old FVF. + DWORD oldFVF; + hr = Dx9Device()->GetFVF( &oldFVF ); + if ( SUCCEEDED( hr ) ) + { + // Set the new FVF. + Dx9Device()->SetFVF( D3DFVF_XYZ ); + // Now, draw the simplest primitive D3D has ever seen. + unsigned short indices[3] = { 0, 1, 2 }; + Vector verts[3] = {vec3_origin, vec3_origin, vec3_origin}; + + tmZone( TELEMETRY_LEVEL1, TMZF_NONE, "DrawIndexedPrimitiveUP" ); + + Dx9Device()->DrawIndexedPrimitiveUP( + D3DPT_TRIANGLELIST, + 0, // Min vertex index + 3, // Num vertices used + 1, // # primitives + indices, // indices + D3DFMT_INDEX16, // index format + verts, // Vertices + sizeof( Vector )// Vertex stride + ); + + Dx9Device()->SetFVF( oldFVF ); + } + Dx9Device()->SetTexture( iStage, pOldTexture ); + } + } + // If this assert fails, then we failed somewhere above. + AssertOnce( SUCCEEDED( hr ) ); +} + +void CShaderAPIDx8::UpdateFrameSyncQuery( int queryIndex, bool bIssue ) +{ + Assert(queryIndex < NUM_FRAME_SYNC_QUERIES); + // wait if already issued + if ( m_bQueryIssued[queryIndex] ) + { + tmZone( TELEMETRY_LEVEL1, TMZF_NONE, "%s", __FUNCTION__ ); + + double flStartTime = Plat_FloatTime(); + BOOL dummyData = 0; + HRESULT hr = S_OK; + // NOTE: This fix helps out motherboards that are a little freaky. + // On such boards, sometimes the driver has to reset itself (an event which takes several seconds) + // and when that happens, the frame sync query object gets lost + for (;;) + { + hr = m_pFrameSyncQueryObject[queryIndex]->GetData( &dummyData, sizeof( dummyData ), D3DGETDATA_FLUSH ); + if ( hr != S_FALSE ) + break; + double flCurrTime = Plat_FloatTime(); + // don't wait more than 200ms (5fps) for these + if ( flCurrTime - flStartTime > 0.200f ) + break; + // Avoid burning a full core while waiting for the query. Spinning can actually harm performance + // because there might be driver threads that are trying to do work that end up starved, and the + // power drawn by the CPU may take away from the power available to the integrated graphics chip. + // A sleep of one millisecond should never be long enough to affect performance, especially since + // this should only trigger when the CPU is already ahead of the GPU. + // On L4D2/TF2 in GL mode this spinning was causing slowdowns. + ThreadSleep( 1 ); + } + m_bQueryIssued[queryIndex] = false; + Assert(hr == S_OK || hr == D3DERR_DEVICELOST); + + if ( hr == D3DERR_DEVICELOST ) + { + MarkDeviceLost( ); + return; + } + } + if ( bIssue ) + { + m_pFrameSyncQueryObject[queryIndex]->Issue( D3DISSUE_END ); + m_bQueryIssued[queryIndex] = true; + } +} + +void CShaderAPIDx8::ForceHardwareSync( void ) +{ + LOCK_SHADERAPI(); + VPROF( "CShaderAPIDx8::ForceHardwareSync" ); + +#ifdef DX_TO_GL_ABSTRACTION + if ( true ) +#else + if ( !mat_frame_sync_enable.GetInt() ) +#endif + return; + + // need to flush the dynamic buffer and make sure the entire image is there + FlushBufferedPrimitives(); + + RECORD_COMMAND( DX8_HARDWARE_SYNC, 0 ); + +#if !defined( _X360 ) + // How do you query dx9 for how many frames behind the hardware is or, alternatively, how do you tell the hardware to never be more than N frames behind? + // 1) The old QueryPendingFrameCount design was removed. It was + // a simple transaction with the driver through the + // GetDriverState, trivial for the drivers to lie. We came up + // with a much better scheme for tracking pending frames where + // the driver can not lie without a possible performance loss: + // use the asynchronous query system with D3DQUERYTYPE_EVENT and + // data size 0. When GetData returns S_OK for the query, you + // know that frame has finished. + if ( mat_frame_sync_force_texture.GetBool() ) + { + ForceHardwareSync_WithManagedTexture(); + } + else if ( m_pFrameSyncQueryObject[0] ) + { + // FIXME: Could install a callback into the materialsystem to do something while waiting for + // the frame to finish (update sound, etc.) + + // Disable VCR mode here or else it'll screw up (and we don't really care if this part plays back in exactly the same amount of time). + VCRSetEnabled( false ); + + m_currentSyncQuery ++; + if ( m_currentSyncQuery >= ARRAYSIZE(m_pFrameSyncQueryObject) ) + { + m_currentSyncQuery = 0; + } + double fStart = Plat_FloatTime(); + int waitIndex = ((m_currentSyncQuery + NUM_FRAME_SYNC_QUERIES) - (NUM_FRAME_SYNC_FRAMES_LATENCY+1)) % NUM_FRAME_SYNC_QUERIES; + UpdateFrameSyncQuery( waitIndex, false ); + UpdateFrameSyncQuery( m_currentSyncQuery, true ); + VCRSetEnabled( true ); + } +#else + DWORD hFence = Dx9Device()->InsertFence(); + Dx9Device()->BlockOnFence( hFence ); +#endif +} + + +//----------------------------------------------------------------------------- +// Needs render state +//----------------------------------------------------------------------------- +void CShaderAPIDx8::QueueResetRenderState() +{ + m_bResetRenderStateNeeded = true; +} + + +//----------------------------------------------------------------------------- +// Use this to begin and end the frame +//----------------------------------------------------------------------------- +void CShaderAPIDx8::BeginFrame() +{ + LOCK_SHADERAPI(); + + if ( m_bResetRenderStateNeeded ) + { + ResetRenderState( false ); + m_bResetRenderStateNeeded = false; + } + +#if ALLOW_SMP_ACCESS + Dx9Device()->SetASyncMode( mat_use_smp.GetInt() != 0 ); +#endif + + ++m_CurrentFrame; + m_nTextureMemoryUsedLastFrame = 0; +} + +void CShaderAPIDx8::EndFrame() +{ + LOCK_SHADERAPI(); + +#if !defined( _X360 ) + MEMCHECK; +#endif + + ExportTextureList(); +} + + +void CShaderAPIDx8::AddBufferToTextureList( const char *pName, D3DSURFACE_DESC &desc ) +{ +// ImageFormat imageFormat; +// imageFormat = ImageLoader::D3DFormatToImageFormat( desc.Format ); +// if( imageFormat < 0 ) +// { +// Assert( 0 ); +// return; +// } + KeyValues *pSubKey = m_pDebugTextureList->CreateNewKey(); + pSubKey->SetString( "Name", pName ); + pSubKey->SetString( "TexGroup", TEXTURE_GROUP_RENDER_TARGET ); + pSubKey->SetInt( "Size", +// ImageLoader::SizeInBytes( imageFormat ) * desc.Width * desc.Height ); + 4 * desc.Width * desc.Height ); + pSubKey->SetString( "Format", "32 bit buffer (hack)" );//ImageLoader::GetName( imageFormat ) ); + pSubKey->SetInt( "Width", desc.Width ); + pSubKey->SetInt( "Height", desc.Height ); + + pSubKey->SetInt( "BindsMax", 1 ); + pSubKey->SetInt( "BindsFrame", 1 ); +} + +void CShaderAPIDx8::ExportTextureList() +{ + if ( !m_bEnableDebugTextureList ) + return; + + if ( !m_pBackBufferSurface || !m_pZBufferSurface ) + // Device vanished... + return; + + m_nDebugDataExportFrame = m_CurrentFrame; + + if ( IsPC() || !IsX360() ) + { + if ( m_pDebugTextureList ) + m_pDebugTextureList->deleteThis(); + + m_pDebugTextureList = new KeyValues( "TextureList" ); + + m_nTextureMemoryUsedTotal = 0; + m_nTextureMemoryUsedPicMip1 = 0; + m_nTextureMemoryUsedPicMip2 = 0; + for ( ShaderAPITextureHandle_t hTexture = m_Textures.Head() ; hTexture != m_Textures.InvalidIndex(); hTexture = m_Textures.Next( hTexture ) ) + { + Texture_t &tex = m_Textures[hTexture]; + + if ( !( tex.m_Flags & Texture_t::IS_ALLOCATED ) ) + continue; + + // Compute total texture memory usage + m_nTextureMemoryUsedTotal += tex.GetMemUsage(); + + // Compute picmip memory usage + { + int numBytes = tex.GetMemUsage(); + + if ( tex.m_NumLevels > 1 ) + { + if ( tex.GetWidth() > 4 || tex.GetHeight() > 4 || tex.GetDepth() > 4 ) + { + int topmipsize = ImageLoader::GetMemRequired( tex.GetWidth(), tex.GetHeight(), tex.GetDepth(), tex.GetImageFormat(), false ); + numBytes -= topmipsize; + + m_nTextureMemoryUsedPicMip1 += numBytes; + + if ( tex.GetWidth() > 8 || tex.GetHeight() > 8 || tex.GetDepth() > 8 ) + { + int othermipsizeRatio = ( ( tex.GetWidth() > 8 ) ? 2 : 1 ) * ( ( tex.GetHeight() > 8 ) ? 2 : 1 ) * ( ( tex.GetDepth() > 8 ) ? 2 : 1 ); + int othermipsize = topmipsize / othermipsizeRatio; + numBytes -= othermipsize; + } + + m_nTextureMemoryUsedPicMip1 += numBytes; + } + else + { + m_nTextureMemoryUsedPicMip1 += numBytes; + m_nTextureMemoryUsedPicMip2 += numBytes; + } + } + else + { + m_nTextureMemoryUsedPicMip1 += numBytes; + m_nTextureMemoryUsedPicMip2 += numBytes; + } + } + + if ( !m_bDebugGetAllTextures && + tex.m_LastBoundFrame != m_CurrentFrame ) + continue; + + if ( tex.m_LastBoundFrame != m_CurrentFrame ) + tex.m_nTimesBoundThisFrame = 0; + + KeyValues *pSubKey = m_pDebugTextureList->CreateNewKey(); + pSubKey->SetString( "Name", tex.m_DebugName.String() ); + pSubKey->SetString( "TexGroup", tex.m_TextureGroupName.String() ); + pSubKey->SetInt( "Size", tex.GetMemUsage() ); + if ( tex.GetCount() > 1 ) + pSubKey->SetInt( "Count", tex.GetCount() ); + pSubKey->SetString( "Format", ImageLoader::GetName( tex.GetImageFormat() ) ); + pSubKey->SetInt( "Width", tex.GetWidth() ); + pSubKey->SetInt( "Height", tex.GetHeight() ); + + pSubKey->SetInt( "BindsMax", tex.m_nTimesBoundMax ); + pSubKey->SetInt( "BindsFrame", tex.m_nTimesBoundThisFrame ); + } + + D3DSURFACE_DESC desc; + m_pBackBufferSurface->GetDesc( &desc ); + AddBufferToTextureList( "BACKBUFFER", desc ); + AddBufferToTextureList( "FRONTBUFFER", desc ); + // ImageFormat imageFormat = ImageLoader::D3DFormatToImageFormat( desc.Format ); + // if( imageFormat >= 0 ) + { + VPROF_INCREMENT_GROUP_COUNTER( "TexGroup_frame_" TEXTURE_GROUP_RENDER_TARGET, + COUNTER_GROUP_TEXTURE_PER_FRAME, + // ImageLoader::SizeInBytes( imageFormat ) * desc.Width * desc.Height ); + 2 * 4 * desc.Width * desc.Height ); // hack (times 2 for front and back buffer) + } + + m_pZBufferSurface->GetDesc( &desc ); + AddBufferToTextureList( "DEPTHBUFFER", desc ); + // imageFormat = ImageLoader::D3DFormatToImageFormat( desc.Format ); + // if( imageFormat >= 0 ) + { + VPROF_INCREMENT_GROUP_COUNTER( "TexGroup_frame_" TEXTURE_GROUP_RENDER_TARGET, + COUNTER_GROUP_TEXTURE_PER_FRAME, + // ImageLoader::SizeInBytes( imageFormat ) * desc.Width * desc.Height ); + 4 * desc.Width * desc.Height ); // hack + } + } + +#if defined( _X360 ) + // toggle to do one shot transmission + m_bEnableDebugTextureList = false; + + int numTextures = m_Textures.Count() + 3; + xTextureList_t* pXTextureList = (xTextureList_t *)_alloca( numTextures * sizeof( xTextureList_t ) ); + memset( pXTextureList, 0, numTextures * sizeof( xTextureList_t ) ); + + numTextures = 0; + for ( ShaderAPITextureHandle_t hTexture = m_Textures.Head() ; hTexture != m_Textures.InvalidIndex(); hTexture = m_Textures.Next( hTexture ) ) + { + Texture_t &tex = m_Textures[hTexture]; + + if ( !m_bDebugGetAllTextures && tex.m_LastBoundFrame != m_CurrentFrame ) + { + continue; + } + if ( !( tex.m_Flags & Texture_t::IS_ALLOCATED ) ) + { + continue; + } + + int refCount; + if ( tex.m_Flags & Texture_t::IS_DEPTH_STENCIL ) + { + // interface forces us to ignore these + refCount = -1; + } + else + { + refCount = GetD3DTextureRefCount( CShaderAPIDx8::GetD3DTexture( hTexture ) ); + } + + pXTextureList[numTextures].pName = tex.m_DebugName.String(); + pXTextureList[numTextures].size = tex.m_SizeBytes * tex.m_NumCopies; + pXTextureList[numTextures].pGroupName = tex.m_TextureGroupName.String(); + pXTextureList[numTextures].pFormatName = D3DFormatName( ImageLoader::ImageFormatToD3DFormat( tex.GetImageFormat() ) ); + pXTextureList[numTextures].width = tex.GetWidth(); + pXTextureList[numTextures].height = tex.GetHeight(); + pXTextureList[numTextures].depth = tex.GetDepth(); + pXTextureList[numTextures].numLevels = tex.m_NumLevels; + pXTextureList[numTextures].binds = tex.m_nTimesBoundThisFrame; + pXTextureList[numTextures].refCount = refCount; + pXTextureList[numTextures].edram = ( tex.m_Flags & Texture_t::IS_RENDER_TARGET_SURFACE ) != 0; + pXTextureList[numTextures].procedural = tex.m_NumCopies > 1; + pXTextureList[numTextures].final = ( tex.m_Flags & Texture_t::IS_FINALIZED ) != 0; + pXTextureList[numTextures].failed = ( tex.m_Flags & Texture_t::IS_FAILED ) != 0; + numTextures++; + } + + // build special entries for implicit surfaces/textures + D3DSURFACE_DESC desc; + m_pBackBufferSurface->GetDesc( &desc ); + int size = ImageLoader::GetMemRequired( + desc.Width, + desc.Height, + 0, + ImageLoader::D3DFormatToImageFormat( desc.Format ), + false ); + pXTextureList[numTextures].pName = "_rt_BackBuffer"; + pXTextureList[numTextures].size = size; + pXTextureList[numTextures].pGroupName = TEXTURE_GROUP_RENDER_TARGET_SURFACE; + pXTextureList[numTextures].pFormatName = D3DFormatName( desc.Format ); + pXTextureList[numTextures].width = desc.Width; + pXTextureList[numTextures].height = desc.Height; + pXTextureList[numTextures].depth = 1; + pXTextureList[numTextures].binds = 1; + pXTextureList[numTextures].refCount = 1; + pXTextureList[numTextures].sRGB = IS_D3DFORMAT_SRGB( desc.Format ); + pXTextureList[numTextures].edram = true; + numTextures++; + + m_pZBufferSurface->GetDesc( &desc ); + pXTextureList[numTextures].pName = "_rt_DepthBuffer"; + pXTextureList[numTextures].size = size; + pXTextureList[numTextures].pGroupName = TEXTURE_GROUP_RENDER_TARGET_SURFACE; + pXTextureList[numTextures].pFormatName = D3DFormatName( desc.Format ); + pXTextureList[numTextures].width = desc.Width; + pXTextureList[numTextures].height = desc.Height; + pXTextureList[numTextures].depth = 1; + pXTextureList[numTextures].binds = 1; + pXTextureList[numTextures].refCount = 1; + pXTextureList[numTextures].sRGB = IS_D3DFORMAT_SRGB( desc.Format ); + pXTextureList[numTextures].edram = true; + numTextures++; + + // front buffer resides in DDR + pXTextureList[numTextures].pName = "_rt_FrontBuffer"; + pXTextureList[numTextures].size = size; + pXTextureList[numTextures].pGroupName = TEXTURE_GROUP_RENDER_TARGET; + pXTextureList[numTextures].pFormatName = D3DFormatName( desc.Format ); + pXTextureList[numTextures].width = desc.Width; + pXTextureList[numTextures].height = desc.Height; + pXTextureList[numTextures].depth = 1; + pXTextureList[numTextures].binds = 1; + pXTextureList[numTextures].refCount = 1; + pXTextureList[numTextures].sRGB = IS_D3DFORMAT_SRGB( desc.Format ); + numTextures++; + + int totalMemory = 0; + for ( int i = 0; i < numTextures; i++ ) + { + if ( pXTextureList[i].edram ) + { + // skip edram based items + continue; + } + totalMemory += pXTextureList[i].size; + } + Msg( "Total D3D Texture Memory: %.2f MB\n", (float)totalMemory/( 1024.0f * 1024.0f ) ); + + // transmit to console + XBX_rTextureList( numTextures, pXTextureList ); +#endif +} + + +//----------------------------------------------------------------------------- +// Releases/reloads resources when other apps want some memory +//----------------------------------------------------------------------------- +void CShaderAPIDx8::ReleaseShaderObjects() +{ + ReleaseInternalRenderTargets(); + EvictManagedResourcesInternal(); + + // FIXME: Move into shaderdevice when textures move over. + +#ifdef _DEBUG + // Helps to find the unreleased textures. + if ( TextureCount() > 0 ) + { + ShaderAPITextureHandle_t hTexture; + for ( hTexture = m_Textures.Head(); hTexture != m_Textures.InvalidIndex(); hTexture = m_Textures.Next( hTexture ) ) + { + if ( GetTexture( hTexture ).m_NumCopies == 1 ) + { + if ( GetTexture( hTexture ).GetTexture() ) + { + Warning( "Didn't correctly clean up texture 0x%8.8x (%s)\n", hTexture, GetTexture( hTexture ).m_DebugName.String() ); + } + } + else + { + for ( int k = GetTexture( hTexture ).m_NumCopies; --k >= 0; ) + { + if ( GetTexture( hTexture ).GetTexture( k ) != 0 ) + { + Warning( "Didn't correctly clean up texture 0x%8.8x (%s)\n", hTexture, GetTexture( hTexture ).m_DebugName.String() ); + break; + } + } + } + } + } +#endif + + Assert( TextureCount() == 0 ); +} + +void CShaderAPIDx8::RestoreShaderObjects() +{ + AcquireInternalRenderTargets(); + SetRenderTarget(); +} + + +//-------------------------------------------------------------------- +// PIX instrumentation routines +// Windows only for now. Turn these on with PIX_INSTRUMENTATION above +//-------------------------------------------------------------------- + +#if 0 // hack versions for OSX to be able to PIX log even when not built debug... +void CShaderAPIDx8::BeginPIXEvent( unsigned long color, const char* szName ) + { + LOCK_SHADERAPI(); + GLMBeginPIXEvent( szName ); // direct call no macro + return; + } + + void CShaderAPIDx8::EndPIXEvent( void ) + { + LOCK_SHADERAPI(); + GLMEndPIXEvent(); // direct call no macro + return; + } + +#else + +#if defined( PIX_INSTRUMENTATION ) || defined( NVPERFHUD ) +ConVar pix_break_on_event( "pix_break_on_event", "" ); +#endif + +void CShaderAPIDx8::BeginPIXEvent( unsigned long color, const char* szName ) +{ +#if ( defined( PIX_INSTRUMENTATION ) || defined( NVPERFHUD ) ) + //LOCK_SHADERAPI(); + + const char *p = pix_break_on_event.GetString(); + if ( p && V_strlen( p ) ) + { + if ( V_stristr( szName, p ) != NULL ) + { + DebuggerBreak(); + } + } + +#if defined ( DX_TO_GL_ABSTRACTION ) + GLMBeginPIXEvent( szName ); + +#if defined( _WIN32 ) + // AMD PerfStudio integration: Call into D3D9.DLL's D3DPERF_BeginEvent() (this gets intercepted by PerfStudio even in GL mode). + if ( g_pShaderDeviceMgrDx8->m_pBeginEvent ) + { + wchar_t wszName[128]; + mbstowcs( wszName, szName, 128 ); + + g_pShaderDeviceMgrDx8->m_pBeginEvent( 0x2F2F2F2F, wszName ); + } +#endif +#elif defined(_X360 ) +#ifndef _DEBUG + char szPIXEventName[32]; + PIXifyName( szPIXEventName, szName ); + PIXBeginNamedEvent( color, szPIXEventName ); +#endif +#else // PC + if ( PIXError() ) + return; + + wchar_t wszName[128]; + mbstowcs( wszName, szName, 128 ); + + // Fire the PIX event, trapping for errors... + if ( D3DPERF_BeginEvent( color, wszName ) < 0 ) + { + Warning( "PIX error Beginning %s event\n", szName ); + IncrementPIXError(); + } +#endif +#endif // #if defined( PIX_INSTRUMENTATION ) +} + +void CShaderAPIDx8::EndPIXEvent( void ) +{ +#if ( defined( PIX_INSTRUMENTATION ) || defined( NVPERFHUD ) ) + //LOCK_SHADERAPI(); + +#if defined ( DX_TO_GL_ABSTRACTION ) + GLMEndPIXEvent(); + +#if defined( _WIN32 ) + // AMD PerfStudio integration: Call into D3D9.DLL's D3DPERF_EndEvent() (this gets intercepted by PerfStudio even in GL mode). + if ( g_pShaderDeviceMgrDx8->m_pEndEvent ) + { + g_pShaderDeviceMgrDx8->m_pEndEvent(); + } +#endif +#elif defined( _X360 ) +#ifndef _DEBUG + PIXEndNamedEvent(); +#endif +#else // PC + if ( PIXError() ) + return; + +#if !defined( NVPERFHUD ) + // Fire the PIX event, trapping for errors... + if ( D3DPERF_EndEvent() < 0 ) + { + Warning("PIX error ending event\n"); + IncrementPIXError(); + } +#endif +#endif +#endif // #if defined( PIX_INSTRUMENTATION ) +} + +#endif + +void CShaderAPIDx8::AdvancePIXFrame() +{ +#if defined( PIX_INSTRUMENTATION ) + // Ping PIX when this bool goes from false to true + if ( r_pix_start.GetBool() && (!m_bPixCapturing) ) + { + StartPIXInstrumentation(); + m_bPixCapturing = true; + } + + // If we want to record frames... + if ( r_pix_recordframes.GetInt() ) + { + if ( m_nPixFrame == 0 ) // First frame to record + { + StartPIXInstrumentation(); + m_nPixFrame++; + } + else if( m_nPixFrame == r_pix_recordframes.GetInt() ) // Last frame to record + { + EndPIXInstrumentation(); + r_pix_recordframes.SetValue(0); + m_nPixFrame = 0; + } + else + { + m_nPixFrame++; // Recording frames... + } + } +#endif +} + +// No begin-end for this...use this to put discrete markers in the PIX stream +void CShaderAPIDx8::SetPIXMarker( unsigned long color, const char* szName ) +{ +#if defined( PIX_INSTRUMENTATION ) + LOCK_SHADERAPI(); + +#if defined( DX_TO_GL_ABSTRACTION ) + if ( g_pShaderDeviceMgrDx8->m_pSetMarker ) + { + wchar_t wszName[128]; + mbstowcs(wszName, szName, 128 ); + g_pShaderDeviceMgrDx8->m_pSetMarker( 0x2F2F2F2F, wszName ); + } +#elif defined( _X360 ) +#ifndef _DEBUG + char szPIXMarkerName[32]; + PIXifyName( szPIXMarkerName, szName ); + PIXSetMarker( color, szPIXMarkerName ); +#endif +#else // PC + if ( PIXError() ) + return; + wchar_t wszName[128]; + mbstowcs(wszName, szName, 128 ); + D3DPERF_SetMarker( color, wszName ); +#endif + +#endif // PIX_INSTRUMENTATION +} + +void CShaderAPIDx8::StartPIXInstrumentation() +{ +#if defined( PIX_INSTRUMENTATION ) + SetPIXMarker( PIX_VALVE_ORANGE, "Valve_PIX_Capture_Start" ); +#endif +} + +void CShaderAPIDx8::EndPIXInstrumentation() +{ +#if defined( PIX_INSTRUMENTATION ) + SetPIXMarker( PIX_VALVE_ORANGE, "Valve_PIX_Capture_End" ); +#endif +} + +void CShaderAPIDx8::IncrementPIXError() +{ +#if defined( PIX_INSTRUMENTATION ) && !defined( NVPERFHUD ) + m_nPIXErrorCount++; + if ( m_nPIXErrorCount >= MAX_PIX_ERRORS ) + { + Warning( "Source engine built with PIX instrumentation, but PIX doesn't seem to have been used to instantiate the game, which is necessary on PC.\n" ); + } +#endif +} + +// Have we already hit several PIX errors? +bool CShaderAPIDx8::PIXError() +{ +#if defined( PIX_INSTRUMENTATION ) && !defined( NVPERFHUD ) + return m_nPIXErrorCount >= MAX_PIX_ERRORS; +#else + return false; +#endif +} + + +//----------------------------------------------------------------------------- +// Check for device lost +//----------------------------------------------------------------------------- +void CShaderAPIDx8::ChangeVideoMode( const ShaderDeviceInfo_t &info ) +{ + if ( IsX360() ) + return; + + LOCK_SHADERAPI(); + + m_PendingVideoModeChangeConfig = info; + m_bPendingVideoModeChange = true; + + if ( info.m_DisplayMode.m_nWidth != 0 && info.m_DisplayMode.m_nHeight != 0 ) + { + m_nWindowWidth = info.m_DisplayMode.m_nWidth; + m_nWindowHeight = info.m_DisplayMode.m_nHeight; + } +} + + +//----------------------------------------------------------------------------- +// Compute fill rate +//----------------------------------------------------------------------------- +void CShaderAPIDx8::ComputeFillRate() +{ + if ( IsX360() ) + { + // not valid + return; + } + + static unsigned char* pBuf = 0; + + int width, height; + GetWindowSize( width, height ); + // Snapshot; look at total # pixels drawn... + if ( !pBuf ) + { + int memSize = ShaderUtil()->GetMemRequired( + width, + height, + 1, + IMAGE_FORMAT_RGB888, + false ) + 4; + + pBuf = (unsigned char*)malloc( memSize ); + } + + ReadPixels( + 0, + 0, + width, + height, + pBuf, + IMAGE_FORMAT_RGB888 ); + + int mask = 0xFF; + int count = 0; + unsigned char* pRead = pBuf; + for (int i = 0; i < height; ++i) + { + for (int j = 0; j < width; ++j) + { + int val = *(int*)pRead; + count += (val & mask); + pRead += 3; + } + } +} + +//----------------------------------------------------------------------------- +// Use this to get the mesh builder that allows us to modify vertex data +//----------------------------------------------------------------------------- +CMeshBuilder* CShaderAPIDx8::GetVertexModifyBuilder() +{ + return &m_ModifyBuilder; +} + +bool CShaderAPIDx8::InFlashlightMode() const +{ + return ShaderUtil()->InFlashlightMode(); +} + +bool CShaderAPIDx8::InEditorMode() const +{ + return ShaderUtil()->InEditorMode(); +} + +//----------------------------------------------------------------------------- +// Gets the bound morph's vertex format; returns 0 if no morph is bound +//----------------------------------------------------------------------------- +MorphFormat_t CShaderAPIDx8::GetBoundMorphFormat() +{ + return ShaderUtil()->GetBoundMorphFormat(); +} + +//----------------------------------------------------------------------------- +// returns the current time in seconds... +//----------------------------------------------------------------------------- +double CShaderAPIDx8::CurrentTime() const +{ + // FIXME: Return game time instead of real time! + // Or eliminate this altogether and put it into a material var + // (this is used by vertex modifiers in shader code at the moment) + return Plat_FloatTime(); +} + + +//----------------------------------------------------------------------------- +// Methods called by the transition table that use dynamic state... +//----------------------------------------------------------------------------- +void CShaderAPIDx8::ApplyZBias( const ShadowState_t& shaderState ) +{ + MaterialSystem_Config_t &config = ShaderUtil()->GetConfig(); + float a = (config.m_SlopeScaleDepthBias_Decal != 0.0f) ? 1.0f / config.m_SlopeScaleDepthBias_Decal : 0.0f; + float b = (config.m_SlopeScaleDepthBias_Normal != 0.0f) ? 1.0f / config.m_SlopeScaleDepthBias_Normal : 0.0f; + float c = (config.m_DepthBias_Decal != 0.0f) ? 1.0f / config.m_DepthBias_Decal : 0.0f; + float d = (config.m_DepthBias_Normal != 0.0f) ? 1.0f / config.m_DepthBias_Normal : 0.0f; + + // FIXME: No longer necessary; may be necessary if you want to use cat 4.3 drivers? + // GR - hack for R200 + bool bPS14Only = g_pHardwareConfig->Caps().m_SupportsPixelShaders_1_4 && !g_pHardwareConfig->Caps().m_SupportsPixelShaders_2_0; + if( ( g_pHardwareConfig->Caps().m_VendorID == 0x1002 ) && bPS14Only ) + { + // Slam to m_SlopeScaleDepthBias_Decal = 0, m_DepthBias_Decal = -4096 + // which empirically is what appears to look good on r200 + // NOTE: Slamming to 0 instead of -1.0 / 4096 because on Cat 4.9, WinXP, 8500, + // this causes the z values to be more than 50 units away from the original z values + + a = 0.0f; + c = -1.0/4096.0; + } + + // bias = (s * D3DRS_SLOPESCALEDEPTHBIAS) + D3DRS_DEPTHBIAS, where s is the maximum depth slope of the triangle being rendered + if ( g_pHardwareConfig->Caps().m_ZBiasAndSlopeScaledDepthBiasSupported ) + { + float fSlopeScaleDepthBias, fDepthBias; + if ( shaderState.m_ZBias == SHADER_POLYOFFSET_DECAL ) + { + fSlopeScaleDepthBias = a; + fDepthBias = c; + } + else if ( shaderState.m_ZBias == SHADER_POLYOFFSET_SHADOW_BIAS ) + { + fSlopeScaleDepthBias = m_fShadowSlopeScaleDepthBias; + fDepthBias = m_fShadowDepthBias; + } + else // assume SHADER_POLYOFFSET_DISABLE + { + fSlopeScaleDepthBias = b; + fDepthBias = d; + } + + if( ReverseDepthOnX360() ) + { + fSlopeScaleDepthBias = -fSlopeScaleDepthBias; + fDepthBias = -fDepthBias; + } + + SetRenderStateConstMacro( this, D3DRS_SLOPESCALEDEPTHBIAS, *((DWORD*) (&fSlopeScaleDepthBias)) ); + SetRenderStateConstMacro( this, D3DRS_DEPTHBIAS, *((DWORD*) (&fDepthBias)) ); + } + else + { + MarkAllUserClipPlanesDirty(); + m_DynamicState.m_TransformChanged[MATERIAL_PROJECTION] |= + STATE_CHANGED_VERTEX_SHADER | STATE_CHANGED_FIXED_FUNCTION; + } +} + +void CShaderAPIDx8::ApplyTextureEnable( const ShadowState_t& state, int nSampler ) +{ + if ( state.m_SamplerState[nSampler].m_TextureEnable == SamplerState(nSampler).m_TextureEnable ) + return; + + if ( state.m_SamplerState[nSampler].m_TextureEnable ) + { + SamplerState( nSampler ).m_TextureEnable = true; + + // Should not be necessary/possible (SetTextureState() calls D3D9/DXAbstract, so the calling thread must already own the device. + //LOCK_SHADERAPI(); + + // Don't do this here!! It ends up giving us extra texture sets. + // We'll Assert in debug mode if you enable a texture stage + // but don't bind a texture. + // see CShaderAPIDx8::RenderPass() for this check. + // NOTE: We aren't doing this optimization quite yet. There are situations + // where you want a texture stage enabled for its texture coordinates, but + // you don't actually bind a texture (texmvspec for example.) + SetTextureState( (Sampler_t)nSampler, SamplerState(nSampler).m_BoundTexture, true ); + } + else + { + SamplerState( nSampler ).m_TextureEnable = false; + SetTextureState( (Sampler_t)nSampler, INVALID_SHADERAPI_TEXTURE_HANDLE ); + } +} + + +//----------------------------------------------------------------------------- +// Used to clear the transition table when we know it's become invalid. +//----------------------------------------------------------------------------- +void CShaderAPIDx8::ClearSnapshots() +{ + LOCK_SHADERAPI(); + FlushBufferedPrimitives(); + m_TransitionTable.Reset(); + InitRenderState(); +} + + +static void KillTranslation( D3DXMATRIX& mat ) +{ + mat[3] = 0.0f; + mat[7] = 0.0f; + mat[11] = 0.0f; + mat[12] = 0.0f; + mat[13] = 0.0f; + mat[14] = 0.0f; + mat[15] = 1.0f; +} + +static void PrintMatrix( const char *name, const D3DXMATRIX& mat ) +{ + int row, col; + char buf[128]; + + Plat_DebugString( name ); + Plat_DebugString( "\n" ); + for( row = 0; row < 4; row++ ) + { + Plat_DebugString( " " ); + for( col = 0; col < 4; col++ ) + { + sprintf( buf, "%f ", ( float )mat( row, col ) ); + Plat_DebugString( buf ); + } + Plat_DebugString( "\n" ); + } + Plat_DebugString( "\n" ); +} + + +//----------------------------------------------------------------------------- +// Gets the vertex format for a particular snapshot id +//----------------------------------------------------------------------------- +VertexFormat_t CShaderAPIDx8::ComputeVertexUsage( int num, StateSnapshot_t* pIds ) const +{ + LOCK_SHADERAPI(); + if (num == 0) + return 0; + + // We don't have to all sorts of crazy stuff if there's only one snapshot + if ( num == 1 ) + { + const ShadowShaderState_t& state = m_TransitionTable.GetSnapshotShader( pIds[0] ); + return state.m_VertexUsage; + } + + Assert( pIds ); + + // Aggregating vertex formats is a little tricky; + // For example, what do we do when two passes want user data? + // Can we assume they are the same? For now, I'm going to + // just print a warning in debug. + + VertexCompressionType_t compression = VERTEX_COMPRESSION_INVALID; + int userDataSize = 0; + int numBones = 0; + int texCoordSize[VERTEX_MAX_TEXTURE_COORDINATES] = { 0, 0, 0, 0, 0, 0, 0, 0 }; + int flags = 0; + + for (int i = num; --i >= 0; ) + { + const ShadowShaderState_t& state = m_TransitionTable.GetSnapshotShader( pIds[i] ); + VertexFormat_t fmt = state.m_VertexUsage; + flags |= VertexFlags(fmt); + + VertexCompressionType_t newCompression = CompressionType( fmt ); + if ( ( compression != newCompression ) && ( compression != VERTEX_COMPRESSION_INVALID ) ) + { + Warning("Encountered a material with two passes that specify different vertex compression types!\n"); + compression = VERTEX_COMPRESSION_NONE; // Be safe, disable compression + } + + int newNumBones = NumBoneWeights(fmt); + if ((numBones != newNumBones) && (newNumBones != 0)) + { + if (numBones != 0) + { + Warning("Encountered a material with two passes that use different numbers of bones!\n"); + } + numBones = newNumBones; + } + + int newUserSize = UserDataSize(fmt); + if ((userDataSize != newUserSize) && (newUserSize != 0)) + { + if (userDataSize != 0) + { + Warning("Encountered a material with two passes that use different user data sizes!\n"); + } + userDataSize = newUserSize; + } + + for ( int j = 0; j < VERTEX_MAX_TEXTURE_COORDINATES; ++j ) + { + int newSize = TexCoordSize( (TextureStage_t)j, fmt ); + if ( ( texCoordSize[j] != newSize ) && ( newSize != 0 ) ) + { + if ( texCoordSize[j] != 0 ) + { + Warning("Encountered a material with two passes that use different texture coord sizes!\n"); + } + if ( texCoordSize[j] < newSize ) + { + texCoordSize[j] = newSize; + } + } + } + } + + return MeshMgr()->ComputeVertexFormat( flags, VERTEX_MAX_TEXTURE_COORDINATES, + texCoordSize, numBones, userDataSize ); +} + +VertexFormat_t CShaderAPIDx8::ComputeVertexFormat( int num, StateSnapshot_t* pIds ) const +{ + LOCK_SHADERAPI(); + VertexFormat_t fmt = ComputeVertexUsage( num, pIds ); + return fmt; +} + + +//----------------------------------------------------------------------------- +// What fields in the morph do we actually use? +//----------------------------------------------------------------------------- +MorphFormat_t CShaderAPIDx8::ComputeMorphFormat( int numSnapshots, StateSnapshot_t* pIds ) const +{ + LOCK_SHADERAPI(); + MorphFormat_t format = 0; + for ( int i = 0; i < numSnapshots; ++i ) + { + MorphFormat_t fmt = m_TransitionTable.GetSnapshotShader( pIds[i] ).m_MorphUsage; + format |= VertexFlags(fmt); + } + return format; +} + +//----------------------------------------------------------------------------- +// Commits a range of vertex shader constants +//----------------------------------------------------------------------------- +static void CommitVertexShaderConstantRange( IDirect3DDevice9 *pDevice, const DynamicState_t &desiredState, + DynamicState_t ¤tState, bool bForce, int nFirstConstant, int nCount ) +{ + if ( IsX360() ) + { + // invalid code path for 360, not coded for 360 GPU contant awareness + Assert( 0 ); + return; + } + + int nFirstCommit = nFirstConstant; + int nCommitCount = 0; + + for ( int i = 0; i < nCount; ++i ) + { + int nVar = nFirstConstant + i; + + bool bDifferentValue = bForce || ( desiredState.m_pVectorVertexShaderConstant[nVar] != currentState.m_pVectorVertexShaderConstant[nVar] ); + if ( !bDifferentValue ) + { + if ( nCommitCount != 0 ) + { + // flush the prior range + pDevice->SetVertexShaderConstantF( nFirstCommit, desiredState.m_pVectorVertexShaderConstant[nFirstCommit].Base(), nCommitCount ); + + memcpy( ¤tState.m_pVectorVertexShaderConstant[nFirstCommit], + &desiredState.m_pVectorVertexShaderConstant[nFirstCommit], nCommitCount * 4 * sizeof(float) ); + } + + // start of new range + nFirstCommit = nVar + 1; + nCommitCount = 0; + } + else + { + ++nCommitCount; + } + } + + if ( nCommitCount != 0 ) + { + // flush range + pDevice->SetVertexShaderConstantF( nFirstCommit, desiredState.m_pVectorVertexShaderConstant[nFirstCommit].Base(), nCommitCount ); + + memcpy( ¤tState.m_pVectorVertexShaderConstant[nFirstCommit], + &desiredState.m_pVectorVertexShaderConstant[nFirstCommit], nCommitCount * 4 * sizeof(float) ); + } +} + + +//----------------------------------------------------------------------------- +// Gets the current buffered state... (debug only) +//----------------------------------------------------------------------------- +void CShaderAPIDx8::GetBufferedState( BufferedState_t& state ) +{ + memcpy( &state.m_Transform[0], &GetTransform(MATERIAL_MODEL), sizeof(D3DXMATRIX) ); + memcpy( &state.m_Transform[1], &GetTransform(MATERIAL_VIEW), sizeof(D3DXMATRIX) ); + memcpy( &state.m_Transform[2], &GetTransform(MATERIAL_PROJECTION), sizeof(D3DXMATRIX) ); + memcpy( &state.m_Viewport, &m_DynamicState.m_Viewport, sizeof(state.m_Viewport) ); + state.m_PixelShader = ShaderManager()->GetCurrentPixelShader(); + state.m_VertexShader = ShaderManager()->GetCurrentVertexShader(); + for (int i = 0; i < g_pHardwareConfig->GetSamplerCount(); ++i) + { + state.m_BoundTexture[i] = m_DynamicState.m_SamplerState[i].m_BoundTexture; + } +} + + +//----------------------------------------------------------------------------- +// constant color methods +//----------------------------------------------------------------------------- + +void CShaderAPIDx8::Color3f( float r, float g, float b ) +{ + unsigned int color = D3DCOLOR_ARGB( 255, (int)(r * 255), + (int)(g * 255), (int)(b * 255) ); + if (color != m_DynamicState.m_ConstantColor) + { + m_DynamicState.m_ConstantColor = color; + SetSupportedRenderState( D3DRS_TEXTUREFACTOR, color ); + } +} + +void CShaderAPIDx8::Color4f( float r, float g, float b, float a ) +{ + unsigned int color = D3DCOLOR_ARGB( (int)(a * 255), (int)(r * 255), + (int)(g * 255), (int)(b * 255) ); + if (color != m_DynamicState.m_ConstantColor) + { + m_DynamicState.m_ConstantColor = color; + SetSupportedRenderState( D3DRS_TEXTUREFACTOR, color ); + } +} + +void CShaderAPIDx8::Color3fv( float const *c ) +{ + Assert( c ); + unsigned int color = D3DCOLOR_ARGB( 255, (int)(c[0] * 255), + (int)(c[1] * 255), (int)(c[2] * 255) ); + if (color != m_DynamicState.m_ConstantColor) + { + m_DynamicState.m_ConstantColor = color; + SetSupportedRenderState( D3DRS_TEXTUREFACTOR, color ); + } +} + +void CShaderAPIDx8::Color4fv( float const *c ) +{ + Assert( c ); + unsigned int color = D3DCOLOR_ARGB( (int)(c[3] * 255), (int)(c[0] * 255), + (int)(c[1] * 255), (int)(c[2] * 255) ); + if (color != m_DynamicState.m_ConstantColor) + { + m_DynamicState.m_ConstantColor = color; + SetSupportedRenderState( D3DRS_TEXTUREFACTOR, color ); + } +} + +void CShaderAPIDx8::Color3ub( unsigned char r, unsigned char g, unsigned char b ) +{ + unsigned int color = D3DCOLOR_ARGB( 255, r, g, b ); + if (color != m_DynamicState.m_ConstantColor) + { + m_DynamicState.m_ConstantColor = color; + SetSupportedRenderState( D3DRS_TEXTUREFACTOR, color ); + } +} + +void CShaderAPIDx8::Color3ubv( unsigned char const* pColor ) +{ + Assert( pColor ); + unsigned int color = D3DCOLOR_ARGB( 255, pColor[0], pColor[1], pColor[2] ); + if (color != m_DynamicState.m_ConstantColor) + { + m_DynamicState.m_ConstantColor = color; + SetSupportedRenderState( D3DRS_TEXTUREFACTOR, color ); + } +} + +void CShaderAPIDx8::Color4ub( unsigned char r, unsigned char g, unsigned char b, unsigned char a ) +{ + unsigned int color = D3DCOLOR_ARGB( a, r, g, b ); + if (color != m_DynamicState.m_ConstantColor) + { + m_DynamicState.m_ConstantColor = color; + SetSupportedRenderState( D3DRS_TEXTUREFACTOR, color ); + } +} + +void CShaderAPIDx8::Color4ubv( unsigned char const* pColor ) +{ + Assert( pColor ); + unsigned int color = D3DCOLOR_ARGB( pColor[3], pColor[0], pColor[1], pColor[2] ); + if (color != m_DynamicState.m_ConstantColor) + { + m_DynamicState.m_ConstantColor = color; + SetSupportedRenderState( D3DRS_TEXTUREFACTOR, color ); + } +} + + +//----------------------------------------------------------------------------- +// The shade mode +//----------------------------------------------------------------------------- +void CShaderAPIDx8::ShadeMode( ShaderShadeMode_t mode ) +{ + LOCK_SHADERAPI(); + D3DSHADEMODE shadeMode = (mode == SHADER_FLAT) ? D3DSHADE_FLAT : D3DSHADE_GOURAUD; + if (m_DynamicState.m_ShadeMode != shadeMode) + { + m_DynamicState.m_ShadeMode = shadeMode; + SetRenderStateConstMacro( this, D3DRS_SHADEMODE, shadeMode ); + } +} + + +//----------------------------------------------------------------------------- +// Buffering 2 frames ahead +//----------------------------------------------------------------------------- +void CShaderAPIDx8::EnableBuffer2FramesAhead( bool bEnable ) +{ +#ifdef _X360 + m_bBuffer2FramesAhead = bEnable; + if ( bEnable != m_DynamicState.m_bBuffer2Frames ) + { + SetRenderState( D3DRS_BUFFER2FRAMES, bEnable ); + m_DynamicState.m_bBuffer2Frames = bEnable; + } +#endif +} + +void CShaderAPIDx8::SetDepthFeatheringPixelShaderConstant( int iConstant, float fDepthBlendScale ) +{ + float fConstantValues[4]; + + if( IsX360() ) + { + const D3DMATRIX &projMatrix = GetProjectionMatrix(); + + fConstantValues[0] = 50.0f / fDepthBlendScale; + fConstantValues[1] = 1.0f / projMatrix.m[2][2]; + fConstantValues[2] = 1.0f / projMatrix.m[3][2]; + fConstantValues[3] = projMatrix.m[2][2]; + + /* + D3DXMATRIX invProjMatrix; + D3DXMatrixInverse( &invProjMatrix, NULL, (D3DXMATRIX *)&projMatrix ); + fConstantValues[1] = invProjMatrix.m[3][2]; + fConstantValues[2] = invProjMatrix.m[3][3]; + fConstantValues[3] = invProjMatrix.m[2][2]; + */ + } + else + { + fConstantValues[0] = m_DynamicState.m_DestAlphaDepthRange / fDepthBlendScale; + fConstantValues[1] = fConstantValues[2] = fConstantValues[3] = 0.0f; //empty + } + + SetPixelShaderConstant( iConstant, fConstantValues ); +} + + +//----------------------------------------------------------------------------- +// Cull mode.. +//----------------------------------------------------------------------------- +void CShaderAPIDx8::SetCullModeState( bool bEnable, D3DCULL nDesiredCullMode ) +{ + D3DCULL nCullMode = bEnable ? nDesiredCullMode : D3DCULL_NONE; + if ( nCullMode != m_DynamicState.m_CullMode ) + { + SetRenderStateConstMacro( this, D3DRS_CULLMODE, nCullMode ); + m_DynamicState.m_CullMode = nCullMode; + } +} + +void CShaderAPIDx8::ApplyCullEnable( bool bEnable ) +{ + m_DynamicState.m_bCullEnabled = bEnable; + SetCullModeState( m_DynamicState.m_bCullEnabled, m_DynamicState.m_DesiredCullMode ); +} + +void CShaderAPIDx8::CullMode( MaterialCullMode_t nCullMode ) +{ + LOCK_SHADERAPI(); + D3DCULL nNewCullMode; + switch( nCullMode ) + { + case MATERIAL_CULLMODE_CCW: + // Culls backfacing polys (normal) + nNewCullMode = D3DCULL_CCW; + break; + + case MATERIAL_CULLMODE_CW: + // Culls frontfacing polys + nNewCullMode = D3DCULL_CW; + break; + + default: + Warning( "CullMode: invalid cullMode\n" ); + return; + } + + if (m_DynamicState.m_DesiredCullMode != nNewCullMode) + { + FlushBufferedPrimitives(); + m_DynamicState.m_DesiredCullMode = nNewCullMode; + SetCullModeState( m_DynamicState.m_bCullEnabled, m_DynamicState.m_DesiredCullMode ); + } +} + +static ConVar mat_alphacoverage( "mat_alphacoverage", "1" ); +void CShaderAPIDx8::ApplyAlphaToCoverage( bool bEnable ) +{ + if ( mat_alphacoverage.GetBool() ) + { + if ( bEnable ) + EnableAlphaToCoverage(); + else + DisableAlphaToCoverage(); + } + else + { + DisableAlphaToCoverage(); + } +} + +//----------------------------------------------------------------------------- +// Returns the current cull mode of the current material (for selection mode only) +//----------------------------------------------------------------------------- +D3DCULL CShaderAPIDx8::GetCullMode() const +{ + Assert( m_pMaterial ); + if ( m_pMaterial->GetMaterialVarFlag( MATERIAL_VAR_NOCULL ) ) + return D3DCULL_NONE; + return m_DynamicState.m_DesiredCullMode; +} + +void CShaderAPIDx8::SetRasterState( const ShaderRasterState_t& state ) +{ + // FIXME: Implement! +} + + +void CShaderAPIDx8::ForceDepthFuncEquals( bool bEnable ) +{ + LOCK_SHADERAPI(); + if ( !g_pShaderDeviceDx8->IsDeactivated() ) + { + m_TransitionTable.ForceDepthFuncEquals( bEnable ); + } +} + +void CShaderAPIDx8::OverrideDepthEnable( bool bEnable, bool bDepthEnable ) +{ + LOCK_SHADERAPI(); + if ( !g_pShaderDeviceDx8->IsDeactivated() ) + { + m_TransitionTable.OverrideDepthEnable( bEnable, bDepthEnable ); + } +} + +void CShaderAPIDx8::OverrideAlphaWriteEnable( bool bOverrideEnable, bool bAlphaWriteEnable ) +{ + LOCK_SHADERAPI(); + if ( !g_pShaderDeviceDx8->IsDeactivated() ) + { + m_TransitionTable.OverrideAlphaWriteEnable( bOverrideEnable, bAlphaWriteEnable ); + } +} + +void CShaderAPIDx8::OverrideColorWriteEnable( bool bOverrideEnable, bool bColorWriteEnable ) +{ + LOCK_SHADERAPI(); + if ( !g_pShaderDeviceDx8->IsDeactivated() ) + { + m_TransitionTable.OverrideColorWriteEnable( bOverrideEnable, bColorWriteEnable ); + } +} + +void CShaderAPIDx8::UpdateFastClipUserClipPlane( void ) +{ + float plane[4]; + switch( m_DynamicState.m_HeightClipMode ) + { + case MATERIAL_HEIGHTCLIPMODE_DISABLE: + EnableFastClip( false ); + break; + case MATERIAL_HEIGHTCLIPMODE_RENDER_ABOVE_HEIGHT: + plane[0] = 0.0f; + plane[1] = 0.0f; + plane[2] = 1.0f; + plane[3] = m_DynamicState.m_HeightClipZ; + EnableFastClip( true ); + SetFastClipPlane(plane); + break; + case MATERIAL_HEIGHTCLIPMODE_RENDER_BELOW_HEIGHT: + plane[0] = 0.0f; + plane[1] = 0.0f; + plane[2] = -1.0f; + plane[3] = -m_DynamicState.m_HeightClipZ; + EnableFastClip( true ); + SetFastClipPlane(plane); + break; + } +} + +void CShaderAPIDx8::SetHeightClipZ( float z ) +{ + LOCK_SHADERAPI(); + if( z != m_DynamicState.m_HeightClipZ ) + { + FlushBufferedPrimitives(); + m_DynamicState.m_HeightClipZ = z; + UpdateVertexShaderFogParams(); + UpdateFastClipUserClipPlane(); + m_DynamicState.m_TransformChanged[MATERIAL_PROJECTION] |= + STATE_CHANGED_VERTEX_SHADER | STATE_CHANGED_FIXED_FUNCTION; + } +} + +void CShaderAPIDx8::SetHeightClipMode( MaterialHeightClipMode_t heightClipMode ) +{ + LOCK_SHADERAPI(); + if( heightClipMode != m_DynamicState.m_HeightClipMode ) + { + FlushBufferedPrimitives(); + m_DynamicState.m_HeightClipMode = heightClipMode; + UpdateVertexShaderFogParams(); + UpdateFastClipUserClipPlane(); + m_DynamicState.m_TransformChanged[MATERIAL_PROJECTION] |= + STATE_CHANGED_VERTEX_SHADER | STATE_CHANGED_FIXED_FUNCTION; + } +} + +void CShaderAPIDx8::SetClipPlane( int index, const float *pPlane ) +{ + LOCK_SHADERAPI(); + Assert( index < g_pHardwareConfig->MaxUserClipPlanes() && index >= 0 ); + + // NOTE: The plane here is specified in *world space* + // NOTE: This is done because they assume Ax+By+Cz+Dw = 0 (where w = 1 in real space) + // while we use Ax+By+Cz=D + D3DXPLANE plane; + plane.a = pPlane[0]; + plane.b = pPlane[1]; + plane.c = pPlane[2]; + plane.d = -pPlane[3]; + + if ( plane != m_DynamicState.m_UserClipPlaneWorld[index] ) + { + FlushBufferedPrimitives(); + + m_DynamicState.m_UserClipPlaneChanged |= ( 1 << index ); + m_DynamicState.m_UserClipPlaneWorld[index] = plane; + } +} + + +//----------------------------------------------------------------------------- +// Converts a D3DXMatrix to a VMatrix and back +//----------------------------------------------------------------------------- +void CShaderAPIDx8::D3DXMatrixToVMatrix( const D3DXMATRIX &in, VMatrix &out ) +{ + MatrixTranspose( *(const VMatrix*)&in, out ); +} + +void CShaderAPIDx8::VMatrixToD3DXMatrix( const VMatrix &in, D3DXMATRIX &out ) +{ + MatrixTranspose( in, *(VMatrix*)&out ); +} + + +//----------------------------------------------------------------------------- +// Mark all user clip planes as being dirty +//----------------------------------------------------------------------------- +void CShaderAPIDx8::MarkAllUserClipPlanesDirty() +{ + m_DynamicState.m_UserClipPlaneChanged |= ( 1 << g_pHardwareConfig->MaxUserClipPlanes() ) - 1; + m_DynamicState.m_bFastClipPlaneChanged = true; +} + + +//----------------------------------------------------------------------------- +// User clip plane override +//----------------------------------------------------------------------------- +void CShaderAPIDx8::EnableUserClipTransformOverride( bool bEnable ) +{ + LOCK_SHADERAPI(); + if ( m_DynamicState.m_bUserClipTransformOverride != bEnable ) + { + FlushBufferedPrimitives(); + m_DynamicState.m_bUserClipTransformOverride = bEnable; + MarkAllUserClipPlanesDirty(); + } +} + + +//----------------------------------------------------------------------------- +// Specify user clip transform +//----------------------------------------------------------------------------- +void CShaderAPIDx8::UserClipTransform( const VMatrix &worldToProjection ) +{ + LOCK_SHADERAPI(); + D3DXMATRIX dxWorldToProjection; + VMatrixToD3DXMatrix( worldToProjection, dxWorldToProjection ); + + if ( m_DynamicState.m_UserClipTransform != dxWorldToProjection ) + { + m_DynamicState.m_UserClipTransform = dxWorldToProjection; + if ( m_DynamicState.m_bUserClipTransformOverride ) + { + FlushBufferedPrimitives(); + MarkAllUserClipPlanesDirty(); + } + } +} + + +//----------------------------------------------------------------------------- +// Enables a user clip plane +//----------------------------------------------------------------------------- +void CShaderAPIDx8::EnableClipPlane( int index, bool bEnable ) +{ + LOCK_SHADERAPI(); + Assert( index < g_pHardwareConfig->MaxUserClipPlanes() && index >= 0 ); + if( ( m_DynamicState.m_UserClipPlaneEnabled & ( 1 << index ) ? true : false ) != bEnable ) + { + FlushBufferedPrimitives(); + if( bEnable ) + { + m_DynamicState.m_UserClipPlaneEnabled |= ( 1 << index ); + } + else + { + m_DynamicState.m_UserClipPlaneEnabled &= ~( 1 << index ); + } + SetRenderStateConstMacro( this, D3DRS_CLIPPLANEENABLE, m_DynamicState.m_UserClipPlaneEnabled ); + } +} + +//----------------------------------------------------------------------------- +// Recomputes the fast-clip plane matrices based on the current fast-clip plane +//----------------------------------------------------------------------------- +void CShaderAPIDx8::CommitFastClipPlane( ) +{ + // Don't bother recomputing if unchanged or disabled + if ( !m_DynamicState.m_bFastClipPlaneChanged || !m_DynamicState.m_FastClipEnabled ) + return; + + m_DynamicState.m_bFastClipPlaneChanged = false; + + D3DXMatrixIdentity( &m_CachedFastClipProjectionMatrix ); + + // Compute worldToProjection - need inv. transpose for transforming plane. + D3DXMATRIX viewToProjInvTrans, viewToProjInv, viewToProj = GetTransform(MATERIAL_PROJECTION); + viewToProj._43 *= 0.5f; // pull in zNear because the shear in effect + // moves it out: clipping artifacts when looking down at water + // could occur if this multiply is not done + + D3DXMATRIX worldToViewInvTrans, worldToViewInv, worldToView = GetUserClipTransform(); + + D3DXMatrixInverse( &worldToViewInv, NULL, &worldToView ); + D3DXMatrixTranspose( &worldToViewInvTrans, &worldToViewInv ); + + D3DXMatrixInverse( &viewToProjInv, NULL, &viewToProj ); + D3DXMatrixTranspose( &viewToProjInvTrans, &viewToProjInv ); + + D3DXPLANE plane; + D3DXPlaneNormalize( &plane, &m_DynamicState.m_FastClipPlane ); + D3DXVECTOR4 clipPlane( plane.a, plane.b, plane.c, plane.d ); + + // transform clip plane into view space + D3DXVec4Transform( &clipPlane, &clipPlane, &worldToViewInvTrans ); + + // transform clip plane into projection space + D3DXVec4Transform( &clipPlane, &clipPlane, &viewToProjInvTrans ); + +#define ALLOW_FOR_FASTCLIPDUMPS 0 + +#if (ALLOW_FOR_FASTCLIPDUMPS == 1) + static ConVar shader_dumpfastclipprojectioncoords( "shader_dumpfastclipprojectioncoords", "0", 0, "dump fast clip projected matrix" ); + if( shader_dumpfastclipprojectioncoords.GetBool() ) + DevMsg( "Fast clip plane projected coordinates: %f %f %f %f", clipPlane.x, clipPlane.y, clipPlane.z, clipPlane.w ); +#endif + + if( (clipPlane.z * clipPlane.w) <= -0.4f ) // a plane with (z*w) > -0.4 at this point is behind the camera and will cause graphical glitches. Toss it. (0.4 found through experimentation) + { +#if (ALLOW_FOR_FASTCLIPDUMPS == 1) + if( shader_dumpfastclipprojectioncoords.GetBool() ) + DevMsg( " %f %f %f %f\n", clipPlane.x, clipPlane.y, clipPlane.z, clipPlane.w ); +#endif + + D3DXVec4Normalize( &clipPlane, &clipPlane ); + + //if ((fabs(clipPlane.z) > 0.01) && (fabs(clipPlane.w) > 0.01f)) + { + // put projection space clip plane in Z column + m_CachedFastClipProjectionMatrix._13 = clipPlane.x; + m_CachedFastClipProjectionMatrix._23 = clipPlane.y; + m_CachedFastClipProjectionMatrix._33 = clipPlane.z; + m_CachedFastClipProjectionMatrix._43 = clipPlane.w; + } + } +#if (ALLOW_FOR_FASTCLIPDUMPS == 1) + else + { + if( shader_dumpfastclipprojectioncoords.GetBool() ) + DevMsg( "\n" ); //finish off the line above + } +#endif + + m_CachedFastClipProjectionMatrix = viewToProj * m_CachedFastClipProjectionMatrix; + + // Update the cached polyoffset matrix (with clip) too: + ComputePolyOffsetMatrix( m_CachedFastClipProjectionMatrix, m_CachedFastClipPolyOffsetProjectionMatrix ); +} + +//----------------------------------------------------------------------------- +// Sets the fast-clip plane; but doesn't update the matrices +//----------------------------------------------------------------------------- +void CShaderAPIDx8::SetFastClipPlane( const float *pPlane ) +{ + LOCK_SHADERAPI(); + D3DXPLANE plane; + plane.a = pPlane[0]; + plane.b = pPlane[1]; + plane.c = pPlane[2]; + plane.d = -pPlane[3]; + if ( plane != m_DynamicState.m_FastClipPlane ) + { + FlushBufferedPrimitives(); + UpdateVertexShaderFogParams(); + + m_DynamicState.m_FastClipPlane = plane; + + // Mark a dirty bit so when it comes time to commit view + projection transforms, + // we also update the fast clip matrices + m_DynamicState.m_bFastClipPlaneChanged = true; + + m_DynamicState.m_TransformChanged[MATERIAL_PROJECTION] |= + STATE_CHANGED_VERTEX_SHADER | STATE_CHANGED_FIXED_FUNCTION; + } +} + + +//----------------------------------------------------------------------------- +// Enables/disables fast-clip mode +//----------------------------------------------------------------------------- +void CShaderAPIDx8::EnableFastClip( bool bEnable ) +{ + LOCK_SHADERAPI(); + if( m_DynamicState.m_FastClipEnabled != bEnable ) + { + FlushBufferedPrimitives(); + UpdateVertexShaderFogParams(); + + m_DynamicState.m_FastClipEnabled = bEnable; + + m_DynamicState.m_TransformChanged[MATERIAL_PROJECTION] |= + STATE_CHANGED_VERTEX_SHADER | STATE_CHANGED_FIXED_FUNCTION; + } +} + +/* +// ----------------------------------------------------------------------------- +// SetInvariantClipVolume - This routine takes six planes as input and sets the +// appropriate Direct3D user clip plane state +// What we mean by "invariant clipping" here is that certain devices implement +// user clip planes at the raster level, which means that multi-pass rendering +// where one pass is unclipped (such as base geometry) and another pass *IS* +// clipped (such as flashlight geometry), there is no z-fighting since the +// clipping is implemented at the raster level in an "invariant" way +// ----------------------------------------------------------------------------- +void CShaderAPIDx8::SetInvariantClipVolume( Frustum_t *pFrustumPlanes ) +{ + // Only do this on modern nVidia hardware, which does invariant clipping + if ( m_VendorID == VENDORID_NVIDIA ) + { + if ( pFrustumPlanes ) + { +// if () +// { +// +// } + + for (int i=0; i<6; i++) + { + const cplane_t *pPlane = pFrustumPlanes->GetPlane(i); + + SetClipPlane( i, (float *) &pPlane->normal ); + EnableClipPlane( i, true ); + +// FRUSTUM_RIGHT = 0, +// FRUSTUM_LEFT = 1, +// FRUSTUM_TOP = 2, +// FRUSTUM_BOTTOM = 3, +// FRUSTUM_NEARZ = 4, +// FRUSTUM_FARZ = 5, + + } + } + else // NULL disables the invariant clip volume... + { + for (int i=0; i<6; i++) + { + EnableClipPlane( i, false ); + } + } + } +} +*/ + +//----------------------------------------------------------------------------- +// Vertex blending +//----------------------------------------------------------------------------- +void CShaderAPIDx8::SetVertexBlendState( int numBones ) +{ + if (numBones < 0) + { + numBones = m_DynamicState.m_NumBones; + } + + // For fixed-function, the number of weights is actually one less than + // the number of bones + if (numBones > 0) + --numBones; + + bool normalizeNormals = true; + D3DVERTEXBLENDFLAGS vertexBlend; + switch(numBones) + { + case 0: + vertexBlend = D3DVBF_DISABLE; + normalizeNormals = false; + break; + + case 1: + vertexBlend = D3DVBF_1WEIGHTS; + break; + + case 2: + vertexBlend = D3DVBF_2WEIGHTS; + break; + + case 3: + vertexBlend = D3DVBF_3WEIGHTS; + break; + + default: + vertexBlend = D3DVBF_DISABLE; + Assert(0); + break; + } + + if (m_DynamicState.m_VertexBlend != vertexBlend) + { + m_DynamicState.m_VertexBlend = vertexBlend; + SetSupportedRenderState( D3DRS_VERTEXBLEND, vertexBlend ); + } + + // Activate normalize normals when skinning is on + if (m_DynamicState.m_NormalizeNormals != normalizeNormals) + { + m_DynamicState.m_NormalizeNormals = normalizeNormals; + SetSupportedRenderState( D3DRS_NORMALIZENORMALS, normalizeNormals ); + } +} + + +//----------------------------------------------------------------------------- +// Vertex blending +//----------------------------------------------------------------------------- +void CShaderAPIDx8::SetNumBoneWeights( int numBones ) +{ + LOCK_SHADERAPI(); + if (m_DynamicState.m_NumBones != numBones) + { + FlushBufferedPrimitives(); + m_DynamicState.m_NumBones = numBones; + + if ( m_TransitionTable.CurrentShadowState() ) + { + SetVertexBlendState( m_TransitionTable.CurrentShadowState()->m_VertexBlendEnable ? -1 : 0 ); + } + } +} + +void CShaderAPIDx8::EnableHWMorphing( bool bEnable ) +{ + LOCK_SHADERAPI(); + if ( m_DynamicState.m_bHWMorphingEnabled != bEnable ) + { + FlushBufferedPrimitives(); + m_DynamicState.m_bHWMorphingEnabled = bEnable; + } +} + +void CShaderAPIDx8::EnabledSRGBWrite( bool bEnabled ) +{ + m_DynamicState.m_bSRGBWritesEnabled = bEnabled; + + if ( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + UpdatePixelFogColorConstant(); + + if ( bEnabled && g_pHardwareConfig->NeedsShaderSRGBConversion() ) + BindTexture( SHADER_SAMPLER15, m_hLinearToGammaTableTexture ); + else + BindTexture( SHADER_SAMPLER15, m_hLinearToGammaTableIdentityTexture ); + } +} + +#if defined( _X360 ) +void CShaderAPIDx8::ApplySRGBReadState( int iTextureStage, bool bSRGBReadEnabled ) +{ + Sampler_t sampler = (Sampler_t)iTextureStage; + SamplerState_t &samplerState = SamplerState( sampler ); + samplerState.m_SRGBReadEnable = bSRGBReadEnabled; + + if ( ( samplerState.m_BoundTexture == INVALID_SHADERAPI_TEXTURE_HANDLE ) || !samplerState.m_TextureEnable ) + { + return; + } + + IDirect3DBaseTexture *pBindTexture = CShaderAPIDx8::GetD3DTexture( samplerState.m_BoundTexture ); + if ( !pBindTexture ) + { + return; + } + + DWORD linearFormatBackup = pBindTexture->Format.dword[0]; //if we convert to srgb format, we need the original format for reverting. We only need the first DWORD of GPUTEXTURE_FETCH_CONSTANT. + if ( bSRGBReadEnabled ) + { + pBindTexture->Format.SignX = pBindTexture->Format.SignY = pBindTexture->Format.SignZ = 3; //convert to srgb format for the bind. This effectively emulates the old srgb read sampler state + } + + Dx9Device()->SetTexture( sampler, pBindTexture ); + + // copy back the format in case we changed it + pBindTexture->Format.dword[0] = linearFormatBackup; +} +#endif + +//----------------------------------------------------------------------------- +// Fog methods... +//----------------------------------------------------------------------------- +void CShaderAPIDx8::UpdatePixelFogColorConstant( void ) +{ + Assert( HardwareConfig()->SupportsPixelShaders_2_b() ); + float fogColor[4]; + + switch( GetPixelFogMode() ) + { + case MATERIAL_FOG_NONE: + { + for( int i = 0; i != 3; ++i ) + fogColor[i] = 0.0f; + } + break; + + case MATERIAL_FOG_LINEAR: + { + //setup the fog for mixing linear fog in the pixel shader so that it emulates ff range fog + for( int i = 0; i != 3; ++i ) + fogColor[i] = m_DynamicState.m_PixelFogColor[i]; + + if( m_DynamicState.m_bSRGBWritesEnabled ) + { + //since the fog color will assuredly get converted from linear to gamma, we should probably convert it from gamma to linear + for( int i = 0; i != 3; ++i ) + fogColor[i] = GammaToLinear_HardwareSpecific( fogColor[i] ); + } + + if( (!m_DynamicState.m_bFogGammaCorrectionDisabled) && (g_pHardwareConfig->GetHDRType() == HDR_TYPE_INTEGER) ) + { + for( int i = 0; i != 3; ++i ) + fogColor[i] *= m_ToneMappingScale.x; // Linear + } + } + break; + + case MATERIAL_FOG_LINEAR_BELOW_FOG_Z: + { + //water fog has been around a while and has never tonemap scaled, and has always been in linear space + if( g_pHardwareConfig->NeedsShaderSRGBConversion() ) + { + //srgb in ps2b uses the 2.2 curve + for( int i = 0; i != 3; ++i ) + fogColor[i] = pow( m_DynamicState.m_PixelFogColor[i], 2.2f ); + } + else + { + for( int i = 0; i != 3; ++i ) + fogColor[i] = GammaToLinear_HardwareSpecific( m_DynamicState.m_PixelFogColor[i] ); //this is how water fog color has always been setup in the past + } + + if( (!m_DynamicState.m_bFogGammaCorrectionDisabled) && (g_pHardwareConfig->GetHDRType() == HDR_TYPE_INTEGER) ) + { + for( int i = 0; i != 3; ++i ) + fogColor[i] *= m_ToneMappingScale.x; // Linear + } + } + break; + + NO_DEFAULT; + }; + + fogColor[3] = 1.0f / m_DynamicState.m_DestAlphaDepthRange; + + SetPixelShaderConstant( LINEAR_FOG_COLOR, fogColor ); +} + + +void CShaderAPIDx8::ApplyFogMode( ShaderFogMode_t fogMode, bool bSRGBWritesEnabled, bool bDisableFogGammaCorrection ) +{ + HDRType_t hdrType = g_pHardwareConfig->GetHDRType(); + + if ( fogMode == SHADER_FOGMODE_DISABLED ) + { + if( hdrType != HDR_TYPE_FLOAT ) + { + FogMode( MATERIAL_FOG_NONE ); + } + + if( m_DelayedShaderConstants.iPixelShaderFogParams != -1 ) + SetPixelShaderFogParams( m_DelayedShaderConstants.iPixelShaderFogParams, fogMode ); + + return; + } + + bool bShouldGammaCorrect = true; // By default, we'll gamma correct. + unsigned char r = 0, g = 0, b = 0; // Black fog + + + if( hdrType != HDR_TYPE_FLOAT ) + { + FogMode( m_SceneFogMode ); + } + + if( m_DelayedShaderConstants.iPixelShaderFogParams != -1 ) + SetPixelShaderFogParams( m_DelayedShaderConstants.iPixelShaderFogParams, fogMode ); + + switch( fogMode ) + { + case SHADER_FOGMODE_BLACK: // Additive decals + bShouldGammaCorrect = false; + break; + case SHADER_FOGMODE_OO_OVERBRIGHT: + case SHADER_FOGMODE_GREY: // Mod2x decals + r = g = b = 128; + break; + case SHADER_FOGMODE_WHITE: // Multiplicative decals + r = g = b = 255; + bShouldGammaCorrect = false; + break; + case SHADER_FOGMODE_FOGCOLOR: + GetSceneFogColor( &r, &g, &b ); // Scene fog color + break; + NO_DEFAULT + } + + bShouldGammaCorrect &= !bDisableFogGammaCorrection; + m_DynamicState.m_bFogGammaCorrectionDisabled = !bShouldGammaCorrect; + + D3DCOLOR color; + if ( bShouldGammaCorrect ) + { + color = ComputeGammaCorrectedFogColor( r, g, b, bSRGBWritesEnabled ); + } + else + { + color = D3DCOLOR_ARGB( 255, r, g, b ); + } + + + const float fColorScale = 1.0f / 255.0f; + m_DynamicState.m_PixelFogColor[0] = (float)(r) * fColorScale; + m_DynamicState.m_PixelFogColor[1] = (float)(g) * fColorScale; + m_DynamicState.m_PixelFogColor[2] = (float)(b) * fColorScale; + + if( g_pMaterialSystemHardwareConfig->SupportsPixelShaders_2_b() ) + { + UpdatePixelFogColorConstant(); + } + + if ( color != m_DynamicState.m_FogColor ) + { + if( hdrType != HDR_TYPE_FLOAT ) + { + m_DynamicState.m_FogColor = color; + SetRenderStateConstMacro( this, D3DRS_FOGCOLOR, m_DynamicState.m_FogColor ); + } + } +} + +void CShaderAPIDx8::SceneFogMode( MaterialFogMode_t fogMode ) +{ + LOCK_SHADERAPI(); + if( m_SceneFogMode != fogMode ) + { + FlushBufferedPrimitives(); + m_SceneFogMode = fogMode; + + if ( m_TransitionTable.CurrentShadowState() ) + { + // Get the shadow state in sync since it depends on SceneFogMode. + ApplyFogMode( m_TransitionTable.CurrentShadowState()->m_FogMode, m_TransitionTable.CurrentShadowState()->m_SRGBWriteEnable, m_TransitionTable.CurrentShadowState()->m_bDisableFogGammaCorrection ); + } + } +} + +MaterialFogMode_t CShaderAPIDx8::GetSceneFogMode() +{ + return m_SceneFogMode; +} + +MaterialFogMode_t CShaderAPIDx8::GetPixelFogMode() +{ + if( ShouldUsePixelFogForMode( m_SceneFogMode ) ) + return m_SceneFogMode; + else + return MATERIAL_FOG_NONE; +} + +int CShaderAPIDx8::GetPixelFogCombo( void ) +{ + if( (m_SceneFogMode != MATERIAL_FOG_NONE) && ShouldUsePixelFogForMode( m_SceneFogMode ) ) + return m_SceneFogMode - 1; //PIXELFOGTYPE dynamic combos are shifted down one. MATERIAL_FOG_NONE is simulated by range fog with rigged parameters. Gets rid of a dynamic combo across the ps2x set + else + return MATERIAL_FOG_NONE; +} + + +static ConVar r_pixelfog( "r_pixelfog", "1" ); + +bool CShaderAPIDx8::ShouldUsePixelFogForMode( MaterialFogMode_t fogMode ) +{ + if( fogMode == MATERIAL_FOG_NONE ) + return false; + + if( IsX360() || IsPosix() ) // Always use pixel fog on X360 and Posix + return true; + + if( g_pHardwareConfig->Caps().m_nDXSupportLevel < 90 ) //pixel fog not available until at least ps2.0 + return false; + + switch( m_SceneFogMode ) + { + case MATERIAL_FOG_LINEAR: + return (g_pHardwareConfig->SupportsPixelShaders_2_b() && //lightmappedgeneric_ps20.fxc can't handle the instruction count + r_pixelfog.GetBool()); //use pixel fog if preferred + + case MATERIAL_FOG_LINEAR_BELOW_FOG_Z: + return true; + }; + + return false; +} + +//----------------------------------------------------------------------------- +// Fog methods... +//----------------------------------------------------------------------------- +void CShaderAPIDx8::FogMode( MaterialFogMode_t fogMode ) +{ + bool bFogEnable; + + if ( IsX360() ) + { + // FF fog not applicable on 360 + return; + } + + m_DynamicState.m_SceneFog = fogMode; + switch( fogMode ) + { + default: + Assert( 0 ); + // fall through + + case MATERIAL_FOG_NONE: + bFogEnable = false; + break; + + case MATERIAL_FOG_LINEAR: + // use vertex fog to achieve linear range fog + bFogEnable = true; + break; + + case MATERIAL_FOG_LINEAR_BELOW_FOG_Z: + // use pixel fog on 9.0 and greater for height fog + bFogEnable = g_pHardwareConfig->Caps().m_nDXSupportLevel < 90; + break; + } + + if( ShouldUsePixelFogForMode( fogMode ) ) + { + bFogEnable = false; //disable FF fog when doing fog in the pixel shader + } + +#if 0 + // HACK - do this to disable fog always + bFogEnable = false; + m_DynamicState.m_SceneFog = MATERIAL_FOG_NONE; +#endif + + // These two are always set to this, so don't bother setting them. + // We are always using vertex fog. +// SetRenderState( D3DRS_FOGTABLEMODE, D3DFOG_NONE ); +// SetRenderState( D3DRS_RANGEFOGENABLE, false ); + + // Set fog enable if it's different than before. + if ( bFogEnable != m_DynamicState.m_FogEnable ) + { + SetSupportedRenderState( D3DRS_FOGENABLE, bFogEnable ); + m_DynamicState.m_FogEnable = bFogEnable; + } +} + + +void CShaderAPIDx8::FogStart( float fStart ) +{ + LOCK_SHADERAPI(); + if (fStart != m_DynamicState.m_FogStart) + { + // need to flush the dynamic buffer + FlushBufferedPrimitives(); + + SetRenderStateConstMacro( this, D3DRS_FOGSTART, *((DWORD*)(&fStart))); + m_VertexShaderFogParams[0] = fStart; + UpdateVertexShaderFogParams(); + m_DynamicState.m_FogStart = fStart; + } +} + +void CShaderAPIDx8::FogEnd( float fEnd ) +{ + LOCK_SHADERAPI(); + if (fEnd != m_DynamicState.m_FogEnd) + { + // need to flush the dynamic buffer + FlushBufferedPrimitives(); + + SetRenderStateConstMacro( this, D3DRS_FOGEND, *((DWORD*)(&fEnd))); + m_VertexShaderFogParams[1] = fEnd; + UpdateVertexShaderFogParams(); + m_DynamicState.m_FogEnd = fEnd; + } +} + +void CShaderAPIDx8::SetFogZ( float fogZ ) +{ + LOCK_SHADERAPI(); + if (fogZ != m_DynamicState.m_FogZ) + { + // need to flush the dynamic buffer + FlushBufferedPrimitives(); + m_DynamicState.m_FogZ = fogZ; + UpdateVertexShaderFogParams(); + } +} + +void CShaderAPIDx8::FogMaxDensity( float flMaxDensity ) +{ + LOCK_SHADERAPI(); + if (flMaxDensity != m_DynamicState.m_FogMaxDensity) + { + // need to flush the dynamic buffer + FlushBufferedPrimitives(); + +// SetRenderState(D3DRS_FOGDENSITY, *((DWORD*)(&flMaxDensity))); // ??? do I need to to this ??? + m_flFogMaxDensity = flMaxDensity; + UpdateVertexShaderFogParams(); + m_DynamicState.m_FogMaxDensity = flMaxDensity; + } +} + +void CShaderAPIDx8::GetFogDistances( float *fStart, float *fEnd, float *fFogZ ) +{ + LOCK_SHADERAPI(); + if( fStart ) + *fStart = m_DynamicState.m_FogStart; + + if( fEnd ) + *fEnd = m_DynamicState.m_FogEnd; + + if( fFogZ ) + *fFogZ = m_DynamicState.m_FogZ; +} + +void CShaderAPIDx8::SceneFogColor3ub( unsigned char r, unsigned char g, unsigned char b ) +{ + LOCK_SHADERAPI(); + if( m_SceneFogColor[0] != r || m_SceneFogColor[1] != g || m_SceneFogColor[2] != b ) + { + FlushBufferedPrimitives(); + m_SceneFogColor[0] = r; + m_SceneFogColor[1] = g; + m_SceneFogColor[2] = b; + + if ( m_TransitionTable.CurrentShadowState() ) + { + ApplyFogMode( m_TransitionTable.CurrentShadowState()->m_FogMode, m_TransitionTable.CurrentShadowState()->m_SRGBWriteEnable, m_TransitionTable.CurrentShadowState()->m_bDisableFogGammaCorrection ); + } + } +} + +void CShaderAPIDx8::GetSceneFogColor( unsigned char *rgb ) +{ + LOCK_SHADERAPI(); + rgb[0] = m_SceneFogColor[0]; + rgb[1] = m_SceneFogColor[1]; + rgb[2] = m_SceneFogColor[2]; +} + +void CShaderAPIDx8::GetSceneFogColor( unsigned char *r, unsigned char *g, unsigned char *b ) +{ + *r = m_SceneFogColor[0]; + *g = m_SceneFogColor[1]; + *b = m_SceneFogColor[2]; +} + + +//----------------------------------------------------------------------------- +// Gamma correction of fog color, or not... +//----------------------------------------------------------------------------- +D3DCOLOR CShaderAPIDx8::ComputeGammaCorrectedFogColor( unsigned char r, unsigned char g, unsigned char b, bool bSRGBWritesEnabled ) +{ +#ifdef _DEBUG + if( g_pHardwareConfig->GetHDRType() == HDR_TYPE_FLOAT && !bSRGBWritesEnabled ) + { +// Assert( 0 ); + } +#endif + bool bLinearSpace = g_pHardwareConfig->Caps().m_bFogColorAlwaysLinearSpace || + ( bSRGBWritesEnabled && ( g_pHardwareConfig->Caps().m_bFogColorSpecifiedInLinearSpace || g_pHardwareConfig->GetHDRType() == HDR_TYPE_FLOAT ) ); + + bool bScaleFogByToneMappingScale = g_pHardwareConfig->GetHDRType() == HDR_TYPE_INTEGER; + + float fr = ( r / 255.0f ); + float fg = ( g / 255.0f ); + float fb = ( b / 255.0f ); + if ( bLinearSpace ) + { + fr = GammaToLinear( fr ); + fg = GammaToLinear( fg ); + fb = GammaToLinear( fb ); + if ( bScaleFogByToneMappingScale ) + { + fr *= m_ToneMappingScale.x; // + fg *= m_ToneMappingScale.x; // Linear + fb *= m_ToneMappingScale.x; // + } + } + else if ( bScaleFogByToneMappingScale ) + { + fr *= m_ToneMappingScale.w; // + fg *= m_ToneMappingScale.w; // Gamma + fb *= m_ToneMappingScale.w; // + } + + fr = min( fr, 1.0f ); + fg = min( fg, 1.0f ); + fb = min( fb, 1.0f ); + r = (int)( fr * 255 ); + g = (int)( fg * 255 ); + b = (int)( fb * 255 ); + return D3DCOLOR_ARGB( 255, r, g, b ); +} + + +//----------------------------------------------------------------------------- +// Some methods chaining vertex + pixel shaders through to the shader manager +//----------------------------------------------------------------------------- +void CShaderAPIDx8::SetVertexShaderIndex( int vshIndex ) +{ + ShaderManager()->SetVertexShaderIndex( vshIndex ); +} + +void CShaderAPIDx8::SetPixelShaderIndex( int pshIndex ) +{ + ShaderManager()->SetPixelShaderIndex( pshIndex ); +} + +void CShaderAPIDx8::SyncToken( const char *pToken ) +{ + LOCK_SHADERAPI(); + RECORD_COMMAND( DX8_SYNC_TOKEN, 1 ); + RECORD_STRING( pToken ); +} + + +//----------------------------------------------------------------------------- +// Deals with vertex buffers +//----------------------------------------------------------------------------- +void CShaderAPIDx8::DestroyVertexBuffers( bool bExitingLevel ) +{ + LOCK_SHADERAPI(); + MeshMgr()->DestroyVertexBuffers( ); + // After a map is shut down, we switch to using smaller dynamic VBs + // (VGUI shouldn't need much), so that we have more memory free during map loading + m_nDynamicVBSize = bExitingLevel ? DYNAMIC_VERTEX_BUFFER_MEMORY_SMALL : DYNAMIC_VERTEX_BUFFER_MEMORY; +} + +int CShaderAPIDx8::GetCurrentDynamicVBSize( void ) +{ + return m_nDynamicVBSize; +} + +FORCEINLINE void CShaderAPIDx8::SetVertexShaderConstantInternal( int var, float const* pVec, int numVecs, bool bForce ) +{ + Assert( pVec ); + + // DX8 asm shaders use a constant mapping which has transforms and vertex shader + // specific constants shifted down by 10 constants (two 5-constant light structures) + if ( IsPC() ) + { + if ( (g_pHardwareConfig->Caps().m_nDXSupportLevel < 90) && (var >= VERTEX_SHADER_MODULATION_COLOR) ) + { + var -= 10; + } + Assert( var + numVecs <= g_pHardwareConfig->NumVertexShaderConstants() ); + + if ( !bForce ) + { + int skip = 0; + numVecs = AdjustUpdateRange( pVec, &m_DesiredState.m_pVectorVertexShaderConstant[var], numVecs, &skip ); + if ( !numVecs ) + return; + var += skip; + pVec += skip * 4; + } + Dx9Device()->SetVertexShaderConstantF( var, pVec, numVecs ); + memcpy( &m_DynamicState.m_pVectorVertexShaderConstant[var], pVec, numVecs * 4 * sizeof(float) ); + } + else + { + Assert( var + numVecs <= g_pHardwareConfig->NumVertexShaderConstants() ); + } + + memcpy( &m_DesiredState.m_pVectorVertexShaderConstant[var], pVec, numVecs * 4 * sizeof(float) ); + + if ( IsX360() ) + { + m_MaxVectorVertexShaderConstant = max( m_MaxVectorVertexShaderConstant, var + numVecs ); + } +} + + +//----------------------------------------------------------------------------- +// Sets the constant register for vertex and pixel shaders +//----------------------------------------------------------------------------- +void CShaderAPIDx8::SetVertexShaderConstant( int var, float const* pVec, int numVecs, bool bForce ) +{ + SetVertexShaderConstantInternal( var, pVec, numVecs, bForce ); +} + +//----------------------------------------------------------------------------- +// Sets the boolean registers for vertex shader control flow +//----------------------------------------------------------------------------- +void CShaderAPIDx8::SetBooleanVertexShaderConstant( int var, int const* pVec, int numBools, bool bForce ) +{ + Assert( pVec ); + Assert( var + numBools <= g_pHardwareConfig->NumBooleanVertexShaderConstants() ); + + if ( IsPC() && g_pHardwareConfig->GetDXSupportLevel() < 90 ) + { + return; + } + + if ( IsPC() && !bForce && memcmp( pVec, &m_DesiredState.m_pBooleanVertexShaderConstant[var], numBools * sizeof( BOOL ) ) == 0 ) + { + return; + } + + if ( IsPC() ) + { + Dx9Device()->SetVertexShaderConstantB( var, pVec, numBools ); + memcpy( &m_DynamicState.m_pBooleanVertexShaderConstant[var], pVec, numBools * sizeof(BOOL) ); + } + + memcpy( &m_DesiredState.m_pBooleanVertexShaderConstant[var], pVec, numBools * sizeof(BOOL) ); + + if ( IsX360() && var + numBools > m_MaxBooleanVertexShaderConstant ) + { + m_MaxBooleanVertexShaderConstant = var + numBools; + Assert( m_MaxBooleanVertexShaderConstant <= 16 ); + } +} + + +//----------------------------------------------------------------------------- +// Sets the integer registers for vertex shader control flow +//----------------------------------------------------------------------------- +void CShaderAPIDx8::SetIntegerVertexShaderConstant( int var, int const* pVec, int numIntVecs, bool bForce ) +{ + Assert( pVec ); + Assert( var + numIntVecs <= g_pHardwareConfig->NumIntegerVertexShaderConstants() ); + + if ( IsPC() && g_pHardwareConfig->GetDXSupportLevel() < 90 ) + { + return; + } + + if ( IsPC() && !bForce && memcmp( pVec, &m_DesiredState.m_pIntegerVertexShaderConstant[var], numIntVecs * sizeof( IntVector4D ) ) == 0 ) + { + return; + } + + if ( IsPC() ) + { + Dx9Device()->SetVertexShaderConstantI( var, pVec, numIntVecs ); + memcpy( &m_DynamicState.m_pIntegerVertexShaderConstant[var], pVec, numIntVecs * sizeof(IntVector4D) ); + } + memcpy( &m_DesiredState.m_pIntegerVertexShaderConstant[var], pVec, numIntVecs * sizeof(IntVector4D) ); + + if ( IsX360() && var + numIntVecs > m_MaxIntegerVertexShaderConstant ) + { + m_MaxIntegerVertexShaderConstant = var + numIntVecs; + Assert( m_MaxIntegerVertexShaderConstant <= 16 ); + } +} + +FORCEINLINE void CShaderAPIDx8::SetPixelShaderConstantInternal( int nStartConst, float const* pValues, int nNumConsts, bool bForce ) +{ + Assert( nStartConst + nNumConsts <= g_pHardwareConfig->NumPixelShaderConstants() ); + + if ( IsPC() ) + { + if ( ! bForce ) + { + int skip = 0; + nNumConsts = AdjustUpdateRange( pValues, &m_DesiredState.m_pVectorPixelShaderConstant[nStartConst], nNumConsts, &skip ); + if ( !nNumConsts ) + return; + nStartConst += skip; + pValues += skip * 4; + } + + Dx9Device()->SetPixelShaderConstantF( nStartConst, pValues, nNumConsts ); + memcpy( &m_DynamicState.m_pVectorPixelShaderConstant[nStartConst], pValues, nNumConsts * 4 * sizeof(float) ); + } + + memcpy( &m_DesiredState.m_pVectorPixelShaderConstant[nStartConst], pValues, nNumConsts * 4 * sizeof(float) ); + + if ( IsX360() ) + { + m_MaxVectorPixelShaderConstant = max( m_MaxVectorPixelShaderConstant, nStartConst + nNumConsts ); + Assert( m_MaxVectorPixelShaderConstant <= 32 ); + } +} + +void CShaderAPIDx8::SetPixelShaderConstant( int var, float const* pVec, int numVecs, bool bForce ) +{ + SetPixelShaderConstantInternal( var, pVec, numVecs, bForce ); +} + +template FORCEINLINE T GetData( uint8 const *pData ) +{ + return * ( reinterpret_cast< T const *>( pData ) ); +} + + + +void CShaderAPIDx8::SetStandardTextureHandle( StandardTextureId_t nId, ShaderAPITextureHandle_t nHandle ) +{ + Assert( nId < ARRAYSIZE( m_StdTextureHandles ) ); + m_StdTextureHandles[nId] = nHandle; +} + +void CShaderAPIDx8::ExecuteCommandBuffer( uint8 *pCmdBuf ) +{ + uint8 *pReturnStack[20]; + uint8 **pSP = &pReturnStack[ARRAYSIZE(pReturnStack)]; + uint8 *pLastCmd; + for(;;) + { + uint8 *pCmd=pCmdBuf; + int nCmd = GetData( pCmdBuf ); + switch( nCmd ) + { + case CBCMD_END: + { + if ( pSP == &pReturnStack[ARRAYSIZE(pReturnStack)] ) + return; + else + { + // pop pc + pCmdBuf = *( pSP ++ ); + break; + } + } + + case CBCMD_JUMP: + pCmdBuf = GetData( pCmdBuf + sizeof( int ) ); + break; + + case CBCMD_JSR: + { + Assert( pSP > &(pReturnStack[0] ) ); +// *(--pSP ) = pCmdBuf + sizeof( int ) + sizeof( uint8 *); +// pCmdBuf = GetData( pCmdBuf + sizeof( int ) ); + ExecuteCommandBuffer( GetData( pCmdBuf + sizeof( int ) ) ); + pCmdBuf = pCmdBuf + sizeof( int ) + sizeof( uint8 *); + break; + } + + case CBCMD_SET_PIXEL_SHADER_FLOAT_CONST: + { + int nStartConst = GetData( pCmdBuf + sizeof( int ) ); + int nNumConsts = GetData( pCmdBuf + 2 * sizeof( int ) ); + float const *pValues = reinterpret_cast< float const *> ( pCmdBuf + 3 * sizeof( int ) ); + pCmdBuf += nNumConsts * 4 * sizeof( float ) + 3 * sizeof( int ); + SetPixelShaderConstantInternal( nStartConst, pValues, nNumConsts, false ); + break; + } + + case CBCMD_SETPIXELSHADERFOGPARAMS: + { + int nReg = GetData( pCmdBuf + sizeof( int ) ); + pCmdBuf += 2 * sizeof( int ); + SetPixelShaderFogParams( nReg ); // !! speed fixme + break; + } + case CBCMD_STORE_EYE_POS_IN_PSCONST: + { + int nReg = GetData( pCmdBuf + sizeof( int ) ); + pCmdBuf += 2 * sizeof( int ); + SetPixelShaderConstantInternal( nReg, m_WorldSpaceCameraPositon.Base(), 1, false ); + break; + } + + case CBCMD_COMMITPIXELSHADERLIGHTING: + { + int nReg = GetData( pCmdBuf + sizeof( int ) ); + pCmdBuf += 2 * sizeof( int ); + CommitPixelShaderLighting( nReg ); + break; + } + + case CBCMD_SETPIXELSHADERSTATEAMBIENTLIGHTCUBE: + { + int nReg = GetData( pCmdBuf + sizeof( int ) ); + pCmdBuf += 2 * sizeof( int ); + float *pCubeBase = m_DynamicState.m_AmbientLightCube[0].Base(); + SetPixelShaderConstantInternal( nReg, pCubeBase, 6, false ); + break; + } + + case CBCMD_SETAMBIENTCUBEDYNAMICSTATEVERTEXSHADER: + { + pCmdBuf +=sizeof( int ); + SetVertexShaderStateAmbientLightCube(); + break; + } + + case CBCMD_SET_DEPTH_FEATHERING_CONST: + { + int nConst = GetData( pCmdBuf + sizeof( int ) ); + float fDepthBlendScale = GetData( pCmdBuf + 2 * sizeof( int ) ); + pCmdBuf += 2 * sizeof( int ) + sizeof( float ); + SetDepthFeatheringPixelShaderConstant( nConst, fDepthBlendScale ); + break; + } + + case CBCMD_SET_VERTEX_SHADER_FLOAT_CONST: + { + int nStartConst = GetData( pCmdBuf + sizeof( int ) ); + int nNumConsts = GetData( pCmdBuf + 2 * sizeof( int ) ); + float const *pValues = reinterpret_cast< float const *> ( pCmdBuf + 3 * sizeof( int ) ); + pCmdBuf += nNumConsts * 4 * sizeof( float ) + 3 * sizeof( int ); + SetVertexShaderConstantInternal( nStartConst, pValues, nNumConsts, false ); + break; + } + + case CBCMD_BIND_STANDARD_TEXTURE: + { + int nSampler = GetData( pCmdBuf + sizeof( int ) ); + int nTextureID = GetData( pCmdBuf + 2 * sizeof( int ) ); + pCmdBuf += 3 * sizeof( int ); + if ( m_StdTextureHandles[nTextureID] != INVALID_SHADERAPI_TEXTURE_HANDLE ) + { + BindTexture( (Sampler_t) nSampler, m_StdTextureHandles[nTextureID] ); + } + else + { + ShaderUtil()->BindStandardTexture( (Sampler_t) nSampler, (StandardTextureId_t ) nTextureID ); + } + break; + } + + case CBCMD_BIND_SHADERAPI_TEXTURE_HANDLE: + { + int nSampler = GetData( pCmdBuf + sizeof( int ) ); + ShaderAPITextureHandle_t hTexture = GetData( pCmdBuf + 2 * sizeof( int ) ); + Assert( hTexture != INVALID_SHADERAPI_TEXTURE_HANDLE ); + pCmdBuf += 2 * sizeof( int ) + sizeof( ShaderAPITextureHandle_t ); + BindTexture( (Sampler_t) nSampler, hTexture ); + break; + } + + case CBCMD_SET_PSHINDEX: + { + int nIdx = GetData( pCmdBuf + sizeof( int ) ); + ShaderManager()->SetPixelShaderIndex( nIdx ); + pCmdBuf += 2 * sizeof( int ); + break; + } + + case CBCMD_SET_VSHINDEX: + { + int nIdx = GetData( pCmdBuf + sizeof( int ) ); + ShaderManager()->SetVertexShaderIndex( nIdx ); + pCmdBuf += 2 * sizeof( int ); + break; + } + + + +#ifndef NDEBUG + default: + { + Assert(0); + } +#endif + + + } + pLastCmd = pCmd; + } +} + + +//----------------------------------------------------------------------------- +// Sets the boolean registers for pixel shader control flow +//----------------------------------------------------------------------------- +void CShaderAPIDx8::SetBooleanPixelShaderConstant( int var, int const* pVec, int numBools, bool bForce ) +{ + Assert( pVec ); + Assert( var + numBools <= g_pHardwareConfig->NumBooleanPixelShaderConstants() ); + + if ( IsPC() && !bForce && memcmp( pVec, &m_DesiredState.m_pBooleanPixelShaderConstant[var], numBools * sizeof( BOOL ) ) == 0 ) + { + return; + } + + if ( IsPC() ) + { + Dx9Device()->SetPixelShaderConstantB( var, pVec, numBools ); + memcpy( &m_DynamicState.m_pBooleanPixelShaderConstant[var], pVec, numBools * sizeof(BOOL) ); + } + + memcpy( &m_DesiredState.m_pBooleanPixelShaderConstant[var], pVec, numBools * sizeof(BOOL) ); + + if ( IsX360() && var + numBools > m_MaxBooleanPixelShaderConstant ) + { + m_MaxBooleanPixelShaderConstant = var + numBools; + Assert( m_MaxBooleanPixelShaderConstant <= 16 ); + } +} + + +//----------------------------------------------------------------------------- +// Sets the integer registers for pixel shader control flow +//----------------------------------------------------------------------------- +void CShaderAPIDx8::SetIntegerPixelShaderConstant( int var, int const* pVec, int numIntVecs, bool bForce ) +{ + Assert( pVec ); + Assert( var + numIntVecs <= g_pHardwareConfig->NumIntegerPixelShaderConstants() ); + + if ( IsPC() && !bForce && memcmp( pVec, &m_DesiredState.m_pIntegerPixelShaderConstant[var], numIntVecs * sizeof( IntVector4D ) ) == 0 ) + { + return; + } + + if ( IsPC() ) + { + Dx9Device()->SetPixelShaderConstantI( var, pVec, numIntVecs ); + memcpy( &m_DynamicState.m_pIntegerPixelShaderConstant[var], pVec, numIntVecs * sizeof(IntVector4D) ); + } + + memcpy( &m_DesiredState.m_pIntegerPixelShaderConstant[var], pVec, numIntVecs * sizeof(IntVector4D) ); + + if ( IsX360() && var + numIntVecs > m_MaxIntegerPixelShaderConstant ) + { + m_MaxIntegerPixelShaderConstant = var + numIntVecs; + Assert( m_MaxBooleanPixelShaderConstant <= 16 ); + } +} + + +void CShaderAPIDx8::InvalidateDelayedShaderConstants( void ) +{ + m_DelayedShaderConstants.Invalidate(); +} + +//----------------------------------------------------------------------------- +// +// Methods dealing with texture stage state +// +//----------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +// Gets the texture associated with a texture state... +//----------------------------------------------------------------------------- + +inline IDirect3DBaseTexture* CShaderAPIDx8::GetD3DTexture( ShaderAPITextureHandle_t hTexture ) +{ + if ( hTexture == INVALID_SHADERAPI_TEXTURE_HANDLE ) + { + return NULL; + } + + AssertValidTextureHandle( hTexture ); + + Texture_t& tex = GetTexture( hTexture ); + if ( tex.m_NumCopies == 1 ) + { + return tex.GetTexture(); + } + else + { + return tex.GetTexture( tex.m_CurrentCopy ); + } +} + +//----------------------------------------------------------------------------- +// Inline methods +//----------------------------------------------------------------------------- +inline ShaderAPITextureHandle_t CShaderAPIDx8::GetModifyTextureHandle() const +{ + return m_ModifyTextureHandle; +} + +inline IDirect3DBaseTexture* CShaderAPIDx8::GetModifyTexture() +{ + return CShaderAPIDx8::GetD3DTexture( m_ModifyTextureHandle ); +} + +void CShaderAPIDx8::SetModifyTexture( IDirect3DBaseTexture* pTex ) +{ + if ( m_ModifyTextureHandle == INVALID_SHADERAPI_TEXTURE_HANDLE ) + return; + + Texture_t& tex = GetTexture( m_ModifyTextureHandle ); + if ( tex.m_NumCopies == 1 ) + { + tex.SetTexture( pTex ); + } + else + { + tex.SetTexture( tex.m_CurrentCopy, pTex ); + } +} + +inline ShaderAPITextureHandle_t CShaderAPIDx8::GetBoundTextureBindId( Sampler_t sampler ) const +{ + return SamplerState( sampler ).m_BoundTexture; +} + +inline bool CShaderAPIDx8::WouldBeOverTextureLimit( ShaderAPITextureHandle_t hTexture ) +{ + if ( IsPC() ) + { + if ( mat_texture_limit.GetInt() < 0 ) + return false; + + Texture_t &tex = GetTexture( hTexture ); + if ( tex.m_LastBoundFrame == m_CurrentFrame ) + return false; + + return m_nTextureMemoryUsedLastFrame + tex.GetMemUsage() > (mat_texture_limit.GetInt() * 1024); + } + return false; +} + + +#define SETSAMPLESTATEANDMIRROR( sampler, samplerState, state_type, mirror_field, value ) \ + if ( samplerState.mirror_field != value ) \ + { \ + samplerState.mirror_field = value; \ + ::SetSamplerState( g_pD3DDevice, sampler, state_type, value ); \ + } + +#define SETSAMPLESTATEANDMIRROR_FLOAT( sampler, samplerState, state_type, mirror_field, value ) \ + if ( samplerState.mirror_field != value ) \ + { \ + samplerState.mirror_field = value; \ + ::SetSamplerState( g_pD3DDevice, sampler, state_type, *(DWORD*)&value ); \ + } + + +//----------------------------------------------------------------------------- +// Sets state on the board related to the texture state +//----------------------------------------------------------------------------- +void CShaderAPIDx8::SetTextureState( Sampler_t sampler, ShaderAPITextureHandle_t hTexture, bool force ) +{ + // Get the dynamic texture info + SamplerState_t &samplerState = SamplerState( sampler ); + + // Set the texture state, but only if it changes + if ( ( samplerState.m_BoundTexture == hTexture ) && !force ) + return; + + // Disabling texturing + if ( hTexture == INVALID_SHADERAPI_TEXTURE_HANDLE || WouldBeOverTextureLimit( hTexture ) ) + { + Dx9Device()->SetTexture( sampler, 0 ); + return; + } + + samplerState.m_BoundTexture = hTexture; + + // Don't set this if we're disabled + if ( !samplerState.m_TextureEnable ) + return; + + RECORD_COMMAND( DX8_SET_TEXTURE, 3 ); + RECORD_INT( stage ); + RECORD_INT( hTexture ); + RECORD_INT( GetTexture( hTexture).m_CurrentCopy ); + + IDirect3DBaseTexture *pTexture = CShaderAPIDx8::GetD3DTexture( hTexture ); + +#if defined( _X360 ) + DWORD linearFormatBackup = pTexture->Format.dword[0]; + if ( samplerState.m_SRGBReadEnable ) + { + // convert to srgb format for the bind. This effectively emulates the old srgb read sampler state + pTexture->Format.SignX = + pTexture->Format.SignY = + pTexture->Format.SignZ = 3; + } +#endif + + Dx9Device()->SetTexture( sampler, pTexture ); + +#if defined( _X360 ) + // put the format back in linear space + pTexture->Format.dword[0] = linearFormatBackup; +#endif + + Texture_t &tex = GetTexture( hTexture ); + if ( tex.m_LastBoundFrame != m_CurrentFrame ) + { + tex.m_LastBoundFrame = m_CurrentFrame; + tex.m_nTimesBoundThisFrame = 0; + + if ( tex.m_pTextureGroupCounterFrame ) + { + // Update the per-frame texture group counter. + *tex.m_pTextureGroupCounterFrame += tex.GetMemUsage(); + } + + // Track memory usage. + m_nTextureMemoryUsedLastFrame += tex.GetMemUsage(); + } + + if ( !m_bDebugTexturesRendering ) + ++tex.m_nTimesBoundThisFrame; + + tex.m_nTimesBoundMax = MAX( tex.m_nTimesBoundMax, tex.m_nTimesBoundThisFrame ); + + static MaterialSystem_Config_t &materialSystemConfig = ShaderUtil()->GetConfig(); + + D3DTEXTUREFILTERTYPE minFilter = tex.m_MinFilter; + D3DTEXTUREFILTERTYPE magFilter = tex.m_MagFilter; + D3DTEXTUREFILTERTYPE mipFilter = tex.m_MipFilter; + int finestMipmapLevel = tex.m_FinestMipmapLevel; + float lodBias = tex.m_LodBias; + + if ( materialSystemConfig.bMipMapTextures == 0 ) + { + mipFilter = D3DTEXF_NONE; + } + + if ( materialSystemConfig.bFilterTextures == 0 && tex.m_NumLevels > 1 ) + { + minFilter = D3DTEXF_NONE; + magFilter = D3DTEXF_NONE; + mipFilter = D3DTEXF_POINT; + } + + D3DTEXTUREADDRESS uTexWrap = tex.m_UTexWrap; + D3DTEXTUREADDRESS vTexWrap = tex.m_VTexWrap; + D3DTEXTUREADDRESS wTexWrap = tex.m_WTexWrap; + + // For now do this the old way on OSX since the dxabstract layer doesn't support SetSamplerStates + // ###OSX### punting on OSX for now +#if DX_TO_GL_ABSTRACTION && !OSX + if ( ( samplerState.m_MinFilter != minFilter ) || ( samplerState.m_MagFilter != magFilter ) || ( samplerState.m_MipFilter != mipFilter ) || + ( samplerState.m_UTexWrap != uTexWrap ) || ( samplerState.m_VTexWrap != vTexWrap ) || ( samplerState.m_WTexWrap != wTexWrap ) || + ( samplerState.m_FinestMipmapLevel != finestMipmapLevel ) || ( samplerState.m_LodBias != lodBias ) ) + { + samplerState.m_UTexWrap = uTexWrap; + samplerState.m_VTexWrap = vTexWrap; + samplerState.m_WTexWrap = wTexWrap; + samplerState.m_MinFilter = minFilter; + samplerState.m_MagFilter = magFilter; + samplerState.m_MipFilter = mipFilter; + samplerState.m_FinestMipmapLevel = finestMipmapLevel; + samplerState.m_LodBias = lodBias; + Dx9Device()->SetSamplerStates( sampler, uTexWrap, vTexWrap, wTexWrap, minFilter, magFilter, mipFilter, finestMipmapLevel, lodBias ); + } +#else + SETSAMPLESTATEANDMIRROR( sampler, samplerState, D3DSAMP_ADDRESSU, m_UTexWrap, uTexWrap ); + SETSAMPLESTATEANDMIRROR( sampler, samplerState, D3DSAMP_ADDRESSV, m_VTexWrap, vTexWrap ); + SETSAMPLESTATEANDMIRROR( sampler, samplerState, D3DSAMP_ADDRESSW, m_WTexWrap, wTexWrap ); + SETSAMPLESTATEANDMIRROR( sampler, samplerState, D3DSAMP_MINFILTER, m_MinFilter, minFilter ); + SETSAMPLESTATEANDMIRROR( sampler, samplerState, D3DSAMP_MAGFILTER, m_MagFilter, magFilter ); + SETSAMPLESTATEANDMIRROR( sampler, samplerState, D3DSAMP_MIPFILTER, m_MipFilter, mipFilter ); + SETSAMPLESTATEANDMIRROR( sampler, samplerState, D3DSAMP_MAXMIPLEVEL, m_FinestMipmapLevel, finestMipmapLevel ); + SETSAMPLESTATEANDMIRROR_FLOAT( sampler, samplerState, D3DSAMP_MIPMAPLODBIAS, m_LodBias, lodBias ); + +#endif +} + +void CShaderAPIDx8::BindTexture( Sampler_t sampler, ShaderAPITextureHandle_t textureHandle ) +{ + LOCK_SHADERAPI(); + SetTextureState( sampler, textureHandle ); +} + +void CShaderAPIDx8::BindVertexTexture( VertexTextureSampler_t nStage, ShaderAPITextureHandle_t textureHandle ) +{ + Assert( g_pMaterialSystemHardwareConfig->GetVertexTextureCount() != 0 ); + LOCK_SHADERAPI(); + ADD_VERTEX_TEXTURE_FUNC( COMMIT_PER_PASS, COMMIT_VERTEX_SHADER, + CommitVertexTextures, nStage, m_BoundTexture, textureHandle ); +} + + +//----------------------------------------------------------------------------- +// Texture allocation/deallocation +//----------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +// Computes stats info for a texture +//----------------------------------------------------------------------------- +void CShaderAPIDx8::ComputeStatsInfo( ShaderAPITextureHandle_t hTexture, bool isCubeMap, bool isVolumeTexture ) +{ + Texture_t &textureData = GetTexture( hTexture ); + + textureData.m_SizeBytes = 0; + textureData.m_SizeTexels = 0; + textureData.m_LastBoundFrame = -1; + if ( IsX360() ) + { + textureData.m_nTimesBoundThisFrame = 0; + } + + IDirect3DBaseTexture* pD3DTex = CShaderAPIDx8::GetD3DTexture( hTexture ); + + if ( IsPC() || !IsX360() ) + { + if ( isCubeMap ) + { + IDirect3DCubeTexture* pTex = static_cast(pD3DTex); + if ( !pTex ) + { + Assert( 0 ); + return; + } + + int numLevels = pTex->GetLevelCount(); + for (int i = 0; i < numLevels; ++i) + { + D3DSURFACE_DESC desc; + HRESULT hr = pTex->GetLevelDesc( i, &desc ); + Assert( !FAILED(hr) ); + textureData.m_SizeBytes += 6 * ImageLoader::GetMemRequired( desc.Width, desc.Height, 1, textureData.GetImageFormat(), false ); + textureData.m_SizeTexels += 6 * desc.Width * desc.Height; + } + } + else if ( isVolumeTexture ) + { + IDirect3DVolumeTexture9* pTex = static_cast(pD3DTex); + if ( !pTex ) + { + Assert( 0 ); + return; + } + int numLevels = pTex->GetLevelCount(); + for (int i = 0; i < numLevels; ++i) + { + D3DVOLUME_DESC desc; + HRESULT hr = pTex->GetLevelDesc( i, &desc ); + Assert( !FAILED( hr ) ); + textureData.m_SizeBytes += ImageLoader::GetMemRequired( desc.Width, desc.Height, desc.Depth, textureData.GetImageFormat(), false ); + textureData.m_SizeTexels += desc.Width * desc.Height; + } + } + else + { + IDirect3DTexture* pTex = static_cast(pD3DTex); + if ( !pTex ) + { + Assert( 0 ); + return; + } + + int numLevels = pTex->GetLevelCount(); + for (int i = 0; i < numLevels; ++i) + { + D3DSURFACE_DESC desc; + HRESULT hr = pTex->GetLevelDesc( i, &desc ); + Assert( !FAILED( hr ) ); + textureData.m_SizeBytes += ImageLoader::GetMemRequired( desc.Width, desc.Height, 1, textureData.GetImageFormat(), false ); + textureData.m_SizeTexels += desc.Width * desc.Height; + } + } + } + +#if defined( _X360 ) + // 360 uses gpu storage size (which accounts for page alignment bloat), not format size + textureData.m_SizeBytes = g_TextureHeap.GetSize( pD3DTex ); +#endif +} + +static D3DFORMAT ComputeFormat( IDirect3DBaseTexture* pTexture, bool isCubeMap ) +{ + Assert( pTexture ); + D3DSURFACE_DESC desc; + if (isCubeMap) + { + IDirect3DCubeTexture* pTex = static_cast(pTexture); + HRESULT hr = pTex->GetLevelDesc( 0, &desc ); + Assert( !FAILED(hr) ); + } + else + { + IDirect3DTexture* pTex = static_cast(pTexture); + HRESULT hr = pTex->GetLevelDesc( 0, &desc ); + Assert( !FAILED(hr) ); + } + return desc.Format; +} + +ShaderAPITextureHandle_t CShaderAPIDx8::CreateDepthTexture( + ImageFormat renderTargetFormat, + int width, + int height, + const char *pDebugName, + bool bTexture ) +{ + LOCK_SHADERAPI(); + + ShaderAPITextureHandle_t i = CreateTextureHandle(); + Texture_t *pTexture = &GetTexture( i ); + + pTexture->m_Flags = Texture_t::IS_ALLOCATED; + if( bTexture ) + { + pTexture->m_Flags |= Texture_t::IS_DEPTH_STENCIL_TEXTURE; + } + else + { + pTexture->m_Flags |= Texture_t::IS_DEPTH_STENCIL; + } + + pTexture->m_DebugName = pDebugName; + pTexture->m_Width = width; + pTexture->m_Height = height; + pTexture->m_Depth = 1; // fake + pTexture->m_Count = 1; // created single texture + pTexture->m_CountIndex = 0; // created single texture + pTexture->m_CreationFlags = 0; // fake + pTexture->m_NumCopies = 1; + pTexture->m_CurrentCopy = 0; + + ImageFormat renderFormat = FindNearestSupportedFormat( renderTargetFormat, false, true, false ); +#if defined( _X360 ) + D3DFORMAT nDepthFormat = ReverseDepthOnX360() ? D3DFMT_D24FS8 : D3DFMT_D24S8; +#else + D3DFORMAT nDepthFormat = m_bUsingStencil ? D3DFMT_D24S8 : D3DFMT_D24X8; +#endif + D3DFORMAT format = FindNearestSupportedDepthFormat( m_nAdapter, m_AdapterFormat, renderFormat, nDepthFormat ); + D3DMULTISAMPLE_TYPE multisampleType = D3DMULTISAMPLE_NONE; + + pTexture->m_NumLevels = 1; + pTexture->m_SizeTexels = width * height; + pTexture->m_SizeBytes = ImageLoader::GetMemRequired( width, height, 1, renderFormat, false ); + + RECORD_COMMAND( DX8_CREATE_DEPTH_TEXTURE, 5 ); + RECORD_INT( i ); + RECORD_INT( width ); + RECORD_INT( height ); + RECORD_INT( format ); + RECORD_INT( multisampleType ); + + HRESULT hr; + if ( !bTexture ) + { +#if defined( _X360 ) + int backWidth, backHeight; + ShaderAPI()->GetBackBufferDimensions( backWidth, backHeight ); + D3DFORMAT backBufferFormat = ImageLoader::ImageFormatToD3DFormat( g_pShaderDevice->GetBackBufferFormat() ); + // immediately follows back buffer in EDRAM + D3DSURFACE_PARAMETERS surfParameters; + surfParameters.Base = 2*XGSurfaceSize( backWidth, backHeight, backBufferFormat, D3DMULTISAMPLE_NONE ); + surfParameters.ColorExpBias = 0; + surfParameters.HierarchicalZBase = 0; + hr = Dx9Device()->CreateDepthStencilSurface( + width, height, format, multisampleType, 0, TRUE, &pTexture->GetDepthStencilSurface(), &surfParameters ); +#else + hr = Dx9Device()->CreateDepthStencilSurface( + width, height, format, multisampleType, 0, TRUE, &pTexture->GetDepthStencilSurface(), NULL ); +#endif + } + else + { + IDirect3DTexture9 *pTex; + hr = Dx9Device()->CreateTexture( width, height, 1, D3DUSAGE_DEPTHSTENCIL, format, D3DPOOL_DEFAULT, &pTex, NULL ); + pTexture->SetTexture( pTex ); + } + + if ( FAILED( hr ) ) + { + switch( hr ) + { + case D3DERR_INVALIDCALL: + Warning( "ShaderAPIDX8::CreateDepthStencilSurface: D3DERR_INVALIDCALL\n" ); + break; + case D3DERR_OUTOFVIDEOMEMORY: + Warning( "ShaderAPIDX8::CreateDepthStencilSurface: D3DERR_OUTOFVIDEOMEMORY\n" ); + break; + default: + break; + } + Assert( 0 ); + } + +#ifdef _XBOX + D3DSURFACE_DESC desc; + hr = pTexture->GetDepthStencilSurface()->GetDesc( &desc ); + Assert( !FAILED( hr ) ); + + pTexture->m_nTimesBoundThisFrame = 0; + pTexture->m_StaticSizeBytes = desc.Size; + pTexture->m_DynamicSizeBytes = 0; + pTexture->m_DebugName = pDebugName; + pTexture->m_TextureGroupName = TEXTURE_GROUP_RENDER_TARGET; + pTexture->SetImageFormat( IMAGE_FORMAT_UNKNOWN ); +#endif + + return i; +} + + +// FIXME!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +// Could keep a free-list for this instead of linearly searching. We +// don't create textures all the time, so this is probably fine for now. +// FIXME!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +ShaderAPITextureHandle_t CShaderAPIDx8::CreateTextureHandle( void ) +{ + ShaderAPITextureHandle_t handle; + CreateTextureHandles( &handle, 1 ); + return handle; +} + +void CShaderAPIDx8::CreateTextureHandles( ShaderAPITextureHandle_t *handles, int count ) +{ + TM_ZONE_DEFAULT( TELEMETRY_LEVEL0 ); + + if ( count <= 0 ) + return; + + MEM_ALLOC_CREDIT(); + + int idxCreating = 0; + ShaderAPITextureHandle_t hTexture; + + { + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s - Search", __FUNCTION__ ); + + for ( hTexture = m_Textures.Head(); hTexture != m_Textures.InvalidIndex(); hTexture = m_Textures.Next( hTexture ) ) + { + if ( !( m_Textures[hTexture].m_Flags & Texture_t::IS_ALLOCATED ) ) + { + handles[ idxCreating ++ ] = hTexture; + if ( idxCreating >= count ) + return; + } + } + } + + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s - Add", __FUNCTION__ ); + while ( idxCreating < count ) + handles[ idxCreating ++ ] = m_Textures.AddToTail(); +} + +//----------------------------------------------------------------------------- +// Creates a lovely texture +//----------------------------------------------------------------------------- + +ShaderAPITextureHandle_t CShaderAPIDx8::CreateTexture( + int width, + int height, + int depth, + ImageFormat dstImageFormat, + int numMipLevels, + int numCopies, + int creationFlags, + const char *pDebugName, + const char *pTextureGroupName ) +{ + ShaderAPITextureHandle_t handle = 0; + CreateTextures( &handle, 1, width, height, depth, dstImageFormat, numMipLevels, numCopies, creationFlags, pDebugName, pTextureGroupName ); + return handle; +} + +void CShaderAPIDx8::CreateTextures( + ShaderAPITextureHandle_t *pHandles, + int count, + int width, + int height, + int depth, + ImageFormat dstImageFormat, + int numMipLevels, + int numCopies, + int creationFlags, + const char *pDebugName, + const char *pTextureGroupName ) +{ + TM_ZONE_DEFAULT( TELEMETRY_LEVEL0 ); + + LOCK_SHADERAPI(); + + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s - PostLock", __FUNCTION__ ); + + Assert( this == g_pShaderAPI ); + + if ( depth == 0 ) + { + depth = 1; + } + + bool isCubeMap = (creationFlags & TEXTURE_CREATE_CUBEMAP) != 0; + bool isRenderTarget = (creationFlags & TEXTURE_CREATE_RENDERTARGET) != 0; + bool managed = (creationFlags & TEXTURE_CREATE_MANAGED) != 0; + bool isDepthBuffer = (creationFlags & TEXTURE_CREATE_DEPTHBUFFER) != 0; + bool isDynamic = (creationFlags & TEXTURE_CREATE_DYNAMIC) != 0; + bool isSRGB = (creationFlags & TEXTURE_CREATE_SRGB) != 0; // for Posix/GL only... not used here ? + +#if defined(IS_WINDOWS_PC) && defined(SHADERAPIDX9) + extern bool g_ShaderDeviceUsingD3D9Ex; + if ( g_ShaderDeviceUsingD3D9Ex && managed ) + { + // Managed textures aren't available under D3D9Ex, but we never lose + // texture data, so it's ok to use the default pool. Really. We can't + // lock default-pool textures like we normally would to upload, but we + // have special logic to blit full updates via D3DX helper functions + // in D3D9Ex mode (see texturedx8.cpp) + managed = false; + creationFlags &= ~TEXTURE_CREATE_MANAGED; + } +#endif + + // Can't be both managed + dynamic. Dynamic is an optimization, but + // if it's not managed, then we gotta do special client-specific stuff + // So, managed wins out! + if ( managed ) + { + creationFlags &= ~TEXTURE_CREATE_DYNAMIC; + isDynamic = false; + } + + + + // Create a set of texture handles + CreateTextureHandles( pHandles, count ); + Texture_t **arrTxp = ( Texture_t ** ) stackalloc( count * sizeof( Texture_t * ) ); + + unsigned short usSetFlags = 0; + usSetFlags |= ( IsPosix() || ( creationFlags & (TEXTURE_CREATE_DYNAMIC | TEXTURE_CREATE_MANAGED) ) ) ? Texture_t::IS_LOCKABLE : 0; + usSetFlags |= ( creationFlags & TEXTURE_CREATE_VERTEXTEXTURE) ? Texture_t::IS_VERTEX_TEXTURE : 0; +#if defined( _X360 ) + usSetFlags |= ( creationFlags & TEXTURE_CREATE_RENDERTARGET ) ? Texture_t::IS_RENDER_TARGET : 0; + usSetFlags |= ( creationFlags & TEXTURE_CREATE_CANCONVERTFORMAT ) ? Texture_t::CAN_CONVERT_FORMAT : 0; +#endif + + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s - CreateFrames", __FUNCTION__ ); + + for ( int idxFrame = 0; idxFrame < count; ++ idxFrame ) + { + arrTxp[ idxFrame ] = &GetTexture( pHandles[ idxFrame ] ); + Texture_t *pTexture = arrTxp[ idxFrame ]; + pTexture->m_Flags = Texture_t::IS_ALLOCATED; + pTexture->m_DebugName = pDebugName; + pTexture->m_Width = width; + pTexture->m_Height = height; + pTexture->m_Depth = depth; + pTexture->m_Count = count; + pTexture->m_CountIndex = idxFrame; + + pTexture->m_CreationFlags = creationFlags; + pTexture->m_Flags |= usSetFlags; + + RECORD_COMMAND( DX8_CREATE_TEXTURE, 12 ); + RECORD_INT( textureHandle ); + RECORD_INT( width ); + RECORD_INT( height ); + RECORD_INT( depth ); // depth for volume textures + RECORD_INT( ImageLoader::ImageFormatToD3DFormat( FindNearestSupportedFormat(dstImageFormat)) ); + RECORD_INT( numMipLevels ); + RECORD_INT( isCubeMap ); + RECORD_INT( numCopies <= 1 ? 1 : numCopies ); + RECORD_INT( isRenderTarget ? 1 : 0 ); + RECORD_INT( managed ); + RECORD_INT( isDepthBuffer ? 1 : 0 ); + RECORD_INT( isDynamic ? 1 : 0 ); + + IDirect3DBaseTexture* pD3DTex; + + // Set the initial texture state + if ( numCopies <= 1 ) + { + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s - CreateD3DTexture", __FUNCTION__ ); + + pTexture->m_NumCopies = 1; + pD3DTex = CreateD3DTexture( width, height, depth, dstImageFormat, numMipLevels, creationFlags, (char*)pDebugName ); + pTexture->SetTexture( pD3DTex ); + } + else + { + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s - CreateD3DTexture", __FUNCTION__ ); + + pTexture->m_NumCopies = numCopies; + { +// X360TEMP +// MEM_ALLOC_CREDIT(); + pTexture->GetTextureArray() = new IDirect3DBaseTexture* [numCopies]; + } + for (int k = 0; k < numCopies; ++k) + { + pD3DTex = CreateD3DTexture( width, height, depth, dstImageFormat, numMipLevels, creationFlags, (char*)pDebugName ); + pTexture->SetTexture( k, pD3DTex ); + } + } + pTexture->m_CurrentCopy = 0; + + pD3DTex = CShaderAPIDx8::GetD3DTexture( pHandles[ idxFrame ] ); + +#if defined( _X360 ) + if ( pD3DTex ) + { + D3DSURFACE_DESC desc; + HRESULT hr; + if ( creationFlags & TEXTURE_CREATE_CUBEMAP ) + { + hr = ((IDirect3DCubeTexture *)pD3DTex)->GetLevelDesc( 0, &desc ); + } + else + { + hr = ((IDirect3DTexture *)pD3DTex)->GetLevelDesc( 0, &desc ); + } + Assert( !FAILED( hr ) ); + + // for proper info get the actual format because the input format may have been redirected + dstImageFormat = ImageLoader::D3DFormatToImageFormat( desc.Format ); + Assert( dstImageFormat != IMAGE_FORMAT_UNKNOWN ); + + // track linear or tiled + if ( !XGIsTiledFormat( desc.Format ) ) + { + pTexture->m_Flags |= Texture_t::IS_LINEAR; + } + } +#endif + + pTexture->SetImageFormat( dstImageFormat ); + pTexture->m_UTexWrap = D3DTADDRESS_CLAMP; + pTexture->m_VTexWrap = D3DTADDRESS_CLAMP; + pTexture->m_WTexWrap = D3DTADDRESS_CLAMP; + + if ( isRenderTarget ) + { +#if !defined( _X360 ) + if ( ( dstImageFormat == IMAGE_FORMAT_NV_INTZ ) || ( dstImageFormat == IMAGE_FORMAT_NV_RAWZ ) || + ( dstImageFormat == IMAGE_FORMAT_ATI_DST16 ) || ( dstImageFormat == IMAGE_FORMAT_ATI_DST24 ) ) + { + pTexture->m_MinFilter = pTexture->m_MagFilter = D3DTEXF_POINT; + } + else +#endif + { + pTexture->m_MinFilter = pTexture->m_MagFilter = D3DTEXF_LINEAR; + } + + pTexture->m_NumLevels = 1; + pTexture->m_MipFilter = D3DTEXF_NONE; + } + else + { + pTexture->m_NumLevels = pD3DTex ? pD3DTex->GetLevelCount() : 1; + pTexture->m_MipFilter = (pTexture->m_NumLevels != 1) ? D3DTEXF_LINEAR : D3DTEXF_NONE; + pTexture->m_MinFilter = pTexture->m_MagFilter = D3DTEXF_LINEAR; + } + pTexture->m_SwitchNeeded = false; + + ComputeStatsInfo( pHandles[idxFrame], isCubeMap, (depth > 1) ); + SetupTextureGroup( pHandles[idxFrame], pTextureGroupName ); + } +} + +void CShaderAPIDx8::SetupTextureGroup( ShaderAPITextureHandle_t hTexture, const char *pTextureGroupName ) +{ + Texture_t *pTexture = &GetTexture( hTexture ); + + Assert( !pTexture->m_pTextureGroupCounterGlobal ); + + // Setup the texture group stuff. + if ( pTextureGroupName && pTextureGroupName[0] != 0 ) + { + pTexture->m_TextureGroupName = pTextureGroupName; + } + else + { + pTexture->m_TextureGroupName = TEXTURE_GROUP_UNACCOUNTED; + } + + // 360 cannot vprof due to multicore loading until vprof is reentrant and these counters are real. +#if defined( VPROF_ENABLED ) && !defined( _X360 ) + char counterName[256]; + Q_snprintf( counterName, sizeof( counterName ), "TexGroup_global_%s", pTexture->m_TextureGroupName.String() ); + pTexture->m_pTextureGroupCounterGlobal = g_VProfCurrentProfile.FindOrCreateCounter( counterName, COUNTER_GROUP_TEXTURE_GLOBAL ); + + Q_snprintf( counterName, sizeof( counterName ), "TexGroup_frame_%s", pTexture->m_TextureGroupName.String() ); + pTexture->m_pTextureGroupCounterFrame = g_VProfCurrentProfile.FindOrCreateCounter( counterName, COUNTER_GROUP_TEXTURE_PER_FRAME ); +#else + pTexture->m_pTextureGroupCounterGlobal = NULL; + pTexture->m_pTextureGroupCounterFrame = NULL; +#endif + + if ( pTexture->m_pTextureGroupCounterGlobal ) + { + *pTexture->m_pTextureGroupCounterGlobal += pTexture->GetMemUsage(); + } +} + +//----------------------------------------------------------------------------- +// Deletes a texture... +//----------------------------------------------------------------------------- +void CShaderAPIDx8::DeleteD3DTexture( ShaderAPITextureHandle_t hTexture ) +{ + int numDeallocated = 0; + Texture_t &texture = GetTexture( hTexture ); + + if ( texture.m_Flags & Texture_t::IS_DEPTH_STENCIL ) + { + // garymcthack - need to make sure that playback knows how to deal with these. + RECORD_COMMAND( DX8_DESTROY_DEPTH_TEXTURE, 1 ); + RECORD_INT( hTexture ); + + if ( texture.GetDepthStencilSurface() ) + { + int nRetVal = texture.GetDepthStencilSurface()->Release(); + Assert( nRetVal == 0 ); + texture.GetDepthStencilSurface() = 0; + numDeallocated = 1; + } + else + { + // FIXME: we hit this on shutdown of HLMV on some machines + Assert( 0 ); + } + } + else if ( texture.m_NumCopies == 1 ) + { + if ( texture.GetTexture() ) + { + RECORD_COMMAND( DX8_DESTROY_TEXTURE, 1 ); + RECORD_INT( hTexture ); + + DestroyD3DTexture( texture.GetTexture() ); + texture.SetTexture( 0 ); + numDeallocated = 1; + } + } + else + { + if ( texture.GetTextureArray() ) + { + RECORD_COMMAND( DX8_DESTROY_TEXTURE, 1 ); + RECORD_INT( hTexture ); + + // Multiple copy texture + for (int j = 0; j < texture.m_NumCopies; ++j) + { + if (texture.GetTexture( j )) + { + DestroyD3DTexture( texture.GetTexture( j ) ); + texture.SetTexture( j, 0 ); + ++numDeallocated; + } + } + + delete [] texture.GetTextureArray(); + texture.GetTextureArray() = 0; + } + } + + texture.m_NumCopies = 0; + + // Remove this texture from its global texture group counter. + if ( texture.m_pTextureGroupCounterGlobal ) + { + *texture.m_pTextureGroupCounterGlobal -= texture.GetMemUsage(); + Assert( *texture.m_pTextureGroupCounterGlobal >= 0 ); + texture.m_pTextureGroupCounterGlobal = NULL; + } + + // remove this texture from std textures + for( int i=0 ; i < ARRAYSIZE( m_StdTextureHandles ) ; i++ ) + { + if ( m_StdTextureHandles[i] == hTexture ) + m_StdTextureHandles[i] = INVALID_SHADERAPI_TEXTURE_HANDLE; + } + +} + + +//----------------------------------------------------------------------------- +// Unbinds a texture from all texture stages +//----------------------------------------------------------------------------- +void CShaderAPIDx8::UnbindTexture( ShaderAPITextureHandle_t hTexture ) +{ + // Make sure no texture units are currently bound to it... + for ( int unit = 0; unit < g_pHardwareConfig->GetSamplerCount(); ++unit ) + { + if ( hTexture == SamplerState( unit ).m_BoundTexture ) + { + // Gotta set this here because INVALID_SHADERAPI_TEXTURE_HANDLE means don't actually + // set bound texture (it's used for disabling texturemapping) + SamplerState( unit ).m_BoundTexture = INVALID_SHADERAPI_TEXTURE_HANDLE; + SetTextureState( (Sampler_t)unit, INVALID_SHADERAPI_TEXTURE_HANDLE ); + } + } + + int nVertexTextureCount = g_pHardwareConfig->GetVertexTextureCount(); + for ( int nSampler = 0; nSampler < nVertexTextureCount; ++nSampler ) + { + if ( hTexture == m_DynamicState.m_VertexTextureState[ nSampler ].m_BoundTexture ) + { + // Gotta set this here because INVALID_SHADERAPI_TEXTURE_HANDLE means don't actually + // set bound texture (it's used for disabling texturemapping) + BindVertexTexture( (VertexTextureSampler_t)nSampler, INVALID_SHADERAPI_TEXTURE_HANDLE ); + } + } +} + + +//----------------------------------------------------------------------------- +// Deletes a texture... +//----------------------------------------------------------------------------- +void CShaderAPIDx8::DeleteTexture( ShaderAPITextureHandle_t textureHandle ) +{ + LOCK_SHADERAPI(); + AssertValidTextureHandle( textureHandle ); + + if ( !TextureIsAllocated( textureHandle ) ) + { + // already deallocated + return; + } + + // Unbind it! + UnbindTexture( textureHandle ); + + // Delete it baby + DeleteD3DTexture( textureHandle ); + + // Now remove the texture from the list + // Mark as deallocated so that it can be reused. + GetTexture( textureHandle ).m_Flags = 0; +} + + +void CShaderAPIDx8::WriteTextureToFile( ShaderAPITextureHandle_t hTexture, const char *szFileName ) +{ + Texture_t *pTexInt = &GetTexture( hTexture ); + //Assert( pTexInt->IsCubeMap() == false ); + //Assert( pTexInt->IsVolumeTexture() == false ); + IDirect3DTexture *pD3DTexture = (IDirect3DTexture *)pTexInt->GetTexture(); + + // Get the level of the texture we want to read from + IDirect3DSurface* pTextureLevel; + HRESULT hr = pD3DTexture ->GetSurfaceLevel( 0, &pTextureLevel ); + if ( FAILED( hr ) ) + return; + + D3DSURFACE_DESC surfaceDesc; + pD3DTexture->GetLevelDesc( 0, &surfaceDesc ); + + D3DLOCKED_RECT lockedRect; + + + //if( pTexInt->m_Flags & Texture_t::IS_RENDER_TARGET ) +#if !defined( _X360 ) //TODO: x360 version + { + //render targets can't be locked, luckily we can copy the surface to system memory and lock that. + IDirect3DSurface *pSystemSurface; + + Assert( !IsX360() ); + + hr = Dx9Device()->CreateOffscreenPlainSurface( surfaceDesc.Width, surfaceDesc.Height, surfaceDesc.Format, D3DPOOL_SYSTEMMEM, &pSystemSurface, NULL ); + Assert( SUCCEEDED( hr ) ); + + pSystemSurface->GetDesc( &surfaceDesc ); + + hr = Dx9Device()->GetRenderTargetData( pTextureLevel, pSystemSurface ); + Assert( SUCCEEDED( hr ) ); + + //pretend this is the texture level we originally grabbed with GetSurfaceLevel() and continue on + pTextureLevel->Release(); + pTextureLevel = pSystemSurface; + } +#endif + + // lock the region + if ( FAILED( pTextureLevel->LockRect( &lockedRect, NULL, D3DLOCK_READONLY ) ) ) + { + Assert( 0 ); + pTextureLevel->Release(); + return; + } + + TGAWriter::WriteTGAFile( szFileName, surfaceDesc.Width, surfaceDesc.Height, pTexInt->GetImageFormat(), (const uint8 *)lockedRect.pBits, lockedRect.Pitch ); + + if ( FAILED( pTextureLevel->UnlockRect() ) ) + { + Assert( 0 ); + pTextureLevel->Release(); + return; + } + + pTextureLevel->Release(); +} + + +//----------------------------------------------------------------------------- +// Releases all textures +//----------------------------------------------------------------------------- +void CShaderAPIDx8::ReleaseAllTextures() +{ + ClearStdTextureHandles(); + ShaderAPITextureHandle_t hTexture; + for ( hTexture = m_Textures.Head(); hTexture != m_Textures.InvalidIndex(); hTexture = m_Textures.Next( hTexture ) ) + { + if ( TextureIsAllocated( hTexture ) ) + { + // Delete it baby + DeleteD3DTexture( hTexture ); + } + } + + // Make sure all texture units are pointing to nothing + for (int unit = 0; unit < g_pHardwareConfig->GetSamplerCount(); ++unit ) + { + SamplerState( unit ).m_BoundTexture = INVALID_SHADERAPI_TEXTURE_HANDLE; + SetTextureState( (Sampler_t)unit, INVALID_SHADERAPI_TEXTURE_HANDLE ); + } +} + +void CShaderAPIDx8::DeleteAllTextures() +{ + ReleaseAllTextures(); + m_Textures.Purge(); +} + +bool CShaderAPIDx8::IsTexture( ShaderAPITextureHandle_t textureHandle ) +{ + LOCK_SHADERAPI(); + + if ( !TextureIsAllocated( textureHandle ) ) + { + return false; + } + +#if !defined( _X360 ) + if ( GetTexture( textureHandle ).m_Flags & Texture_t::IS_DEPTH_STENCIL ) + { + return GetTexture( textureHandle ).GetDepthStencilSurface() != 0; + } + else if ( ( GetTexture( textureHandle ).m_NumCopies == 1 && GetTexture( textureHandle ).GetTexture() != 0 ) || + ( GetTexture( textureHandle ).m_NumCopies > 1 && GetTexture( textureHandle ).GetTexture( 0 ) != 0 ) ) + { + return true; + } + else + { + return false; + } +#else + // query is about texture handle validity, not presence + // texture handle is allocated, texture may or may not be present + return true; +#endif +} + + + +//----------------------------------------------------------------------------- +// Gets the surface associated with a texture (refcount of surface is increased) +//----------------------------------------------------------------------------- +IDirect3DSurface* CShaderAPIDx8::GetTextureSurface( ShaderAPITextureHandle_t textureHandle ) +{ + MEM_ALLOC_D3D_CREDIT(); + + IDirect3DSurface* pSurface; + + // We'll be modifying this sucka + AssertValidTextureHandle( textureHandle ); + Texture_t &tex = GetTexture( textureHandle ); + if ( !( tex.m_Flags & Texture_t::IS_ALLOCATED ) ) + { + return NULL; + } + + if ( IsX360() && ( tex.m_Flags & Texture_t::IS_RENDER_TARGET_SURFACE ) ) + { + pSurface = tex.GetRenderTargetSurface( false ); + +#if POSIX + // dxabstract's AddRef/Release have optional args to help track usage + pSurface->AddRef( 0, "CShaderAPIDx8::GetTextureSurface public addref"); +#else + pSurface->AddRef(); +#endif + + return pSurface; + } + + IDirect3DBaseTexture* pD3DTex = CShaderAPIDx8::GetD3DTexture( textureHandle ); + IDirect3DTexture* pTex = static_cast( pD3DTex ); + Assert( pTex ); + if ( !pTex ) + { + return NULL; + } + + HRESULT hr = pTex->GetSurfaceLevel( 0, &pSurface ); + Assert( hr == D3D_OK ); + + return pSurface; +} + +//----------------------------------------------------------------------------- +// Gets the surface associated with a texture (refcount of surface is increased) +//----------------------------------------------------------------------------- +IDirect3DSurface* CShaderAPIDx8::GetDepthTextureSurface( ShaderAPITextureHandle_t textureHandle ) +{ + AssertValidTextureHandle( textureHandle ); + if ( !TextureIsAllocated( textureHandle ) ) + { + return NULL; + } + return GetTexture( textureHandle ).GetDepthStencilSurface(); +} + +//----------------------------------------------------------------------------- +// Changes the render target +//----------------------------------------------------------------------------- +void CShaderAPIDx8::SetRenderTargetEx( int nRenderTargetID, ShaderAPITextureHandle_t colorTextureHandle, ShaderAPITextureHandle_t depthTextureHandle ) +{ + LOCK_SHADERAPI(); + if ( IsDeactivated( ) ) + { + return; + } + + // GR - need to flush batched geometry + FlushBufferedPrimitives(); + +#if defined( PIX_INSTRUMENTATION ) + { + const char *pRT = "Backbuffer"; + const char *pDS = "DefaultDepthStencil"; + + if ( colorTextureHandle == SHADER_RENDERTARGET_NONE ) + { + pRT = "None"; + } + else if ( colorTextureHandle != SHADER_RENDERTARGET_BACKBUFFER ) + { + Texture_t &tex = GetTexture( colorTextureHandle ); + pRT = tex.m_DebugName.String(); + } + + if ( depthTextureHandle == SHADER_RENDERTARGET_NONE ) + { + pDS = "None"; + } + else if ( depthTextureHandle != SHADER_RENDERTARGET_DEPTHBUFFER ) + { + Texture_t &tex = GetTexture( depthTextureHandle ); + pDS = tex.m_DebugName.String(); + } + + char buf[256]; + sprintf( buf, "SRT:%s %s", pRT ? pRT : "?", pDS ? pDS : "?" ); + BeginPIXEvent( 0xFFFFFFFF, buf ); + EndPIXEvent(); + } +#endif + +#if !defined( _X360 ) + RECORD_COMMAND( DX8_TEST_COOPERATIVE_LEVEL, 0 ); + HRESULT hr = Dx9Device()->TestCooperativeLevel(); + if ( hr != D3D_OK ) + { + MarkDeviceLost(); + return; + } +#endif + + IDirect3DSurface* pColorSurface = NULL; + IDirect3DSurface* pZSurface = NULL; + + RECORD_COMMAND( DX8_SET_RENDER_TARGET, 3 ); + RECORD_INT( nRenderTargetID ); + RECORD_INT( colorTextureHandle ); + RECORD_INT( depthTextureHandle ); + + // The 0th render target defines which depth buffer we are using, so + // don't bother if we are another render target + if ( nRenderTargetID > 0 ) + { + depthTextureHandle = SHADER_RENDERTARGET_NONE; + } + + // NOTE!!!! If this code changes, also change Dx8SetRenderTarget in playback.cpp + bool usingTextureTarget = false; + if ( colorTextureHandle == SHADER_RENDERTARGET_BACKBUFFER ) + { + pColorSurface = m_pBackBufferSurface; + +#ifdef ENABLE_NULLREF_DEVICE_SUPPORT + if( pColorSurface ) +#endif + { + // This is just to make the code a little simpler... + // (simplifies the release logic) +#if POSIX + // dxabstract's AddRef/Release have optional args to help track usage + pColorSurface->AddRef( 0, "+C CShaderAPIDx8::SetRenderTargetEx public addref 1"); +#else + pColorSurface->AddRef(); +#endif + } + } + else + { + // get the texture (Refcount increases) + UnbindTexture( colorTextureHandle ); + pColorSurface = GetTextureSurface( colorTextureHandle ); + if ( !pColorSurface ) + { + return; + } + + usingTextureTarget = true; + } + + if ( depthTextureHandle == SHADER_RENDERTARGET_DEPTHBUFFER ) + { + // using the default depth buffer + pZSurface = m_pZBufferSurface; + +#ifdef ENABLE_NULLREF_DEVICE_SUPPORT + if( pZSurface ) +#endif + { + // simplify the prologue logic +#if POSIX + // dxabstract's AddRef/Release have optional args to help track usage + pZSurface->AddRef( 0, "+D CShaderAPIDx8::SetRenderTargetEx public addref 1"); +#else + pZSurface->AddRef(); +#endif + } + } + else if ( depthTextureHandle == SHADER_RENDERTARGET_NONE ) + { + // GR - disable depth buffer + pZSurface = NULL; + } + else + { + UnbindTexture( depthTextureHandle ); + + Texture_t &tex = GetTexture( depthTextureHandle ); + + //Cannot use a depth/stencil surface derived from a texture. + //Asserting helps get the whole call stack instead of letting the 360 report an error with a partial stack + Assert( !( IsX360() && (tex.m_Flags & Texture_t::IS_DEPTH_STENCIL_TEXTURE) ) ); + + if ( tex.m_Flags & Texture_t::IS_DEPTH_STENCIL ) + { + pZSurface = GetDepthTextureSurface( depthTextureHandle ); + if ( pZSurface ) + { +#if POSIX + // dxabstract's AddRef/Release have optional args to help track usage + pZSurface->AddRef( 0, "+D CShaderAPIDx8::SetRenderTargetEx public addref 2"); +#else + pZSurface->AddRef(); +#endif + } + } + else + { + HRESULT hr = ((IDirect3DTexture9*)tex.GetTexture())->GetSurfaceLevel( 0, &pZSurface ); + } + + if ( !pZSurface ) + { + // Refcount of color surface was increased above +#if POSIX + // dxabstract's AddRef/Release have optional args to help track usage + pColorSurface->Release( 0, "-C CShaderAPIDx8::SetRenderTargetEx public release 1" ); +#else + pColorSurface->Release(); +#endif + return; + } + usingTextureTarget = true; + } + +#ifdef _DEBUG + if ( pZSurface ) + { + D3DSURFACE_DESC zSurfaceDesc, colorSurfaceDesc; + pZSurface->GetDesc( &zSurfaceDesc ); + pColorSurface->GetDesc( &colorSurfaceDesc ); + + if ( !HushAsserts() ) + { + Assert( colorSurfaceDesc.Width <= zSurfaceDesc.Width ); + Assert( colorSurfaceDesc.Height <= zSurfaceDesc.Height ); + } + } +#endif + + // we only set this flag for the 0th render target so that NULL + // render targets 1-3 don't mess with the viewport on the main RT + if( nRenderTargetID == 0 ) + m_UsingTextureRenderTarget = usingTextureTarget; + + // NOTE: The documentation says that SetRenderTarget increases the refcount + // but it doesn't appear to in practice. If this somehow changes (perhaps + // in a device-specific manner, we're in trouble). + if ( IsPC() || !IsX360() ) + { + if ( pColorSurface == m_pBackBufferSurface && nRenderTargetID > 0 ) + { + // SetRenderTargetEx is overloaded so that if you pass NULL in for anything that + // isn't the zeroth render target, you effectively disable that MRT index. + // (Passing in NULL for the zeroth render target means that you want to use the backbuffer + // as the render target.) + // hack hack hack!!!!! If the render target id > 0 and the user passed in NULL, disable the render target + Dx9Device()->SetRenderTarget( nRenderTargetID, NULL ); + } + else + { + Dx9Device()->SetRenderTarget( nRenderTargetID, pColorSurface ); + } + } + else + { + Assert( nRenderTargetID == 0 ); + SetRenderTargetInternalXbox( colorTextureHandle ); + } + + // The 0th render target defines which depth buffer we are using, so + // don't bother if we are another render target + if ( nRenderTargetID == 0 ) + { + Dx9Device()->SetDepthStencilSurface( pZSurface ); + } + + // The 0th render target defines the viewport, therefore it also defines + // the viewport limits. + if ( m_UsingTextureRenderTarget && nRenderTargetID == 0 ) + { + D3DSURFACE_DESC desc; + HRESULT hr; + if ( !pZSurface ) + { + hr = pColorSurface->GetDesc( &desc ); + } + else + { + hr = pZSurface->GetDesc( &desc ); + } + Assert( !FAILED(hr) ); + m_ViewportMaxWidth = desc.Width; + m_ViewportMaxHeight = desc.Height; + } + + static bool assert_on_refzero = false; + int ref; + if ( pZSurface ) + { +#if POSIX + ref = pZSurface->Release( 0, "-D CShaderAPIDx8::SetRenderTargetEx public release (z surface)"); +#else + ref = pZSurface->Release(); +#endif + + if(assert_on_refzero) + { + Assert( ref != 0 ); + } + } + +#ifdef ENABLE_NULLREF_DEVICE_SUPPORT + if( pColorSurface ) +#endif + { +#if POSIX + ref = pColorSurface->Release( 0, "-C CShaderAPIDx8::SetRenderTargetEx public release (color surface)"); +#else + ref = pColorSurface->Release(); +#endif + if(assert_on_refzero) + { + Assert( ref != 0 ); + } + } + + // Changing the render target sets a default viewport. Force rewrite to preserve the current desired state. + m_DynamicState.m_Viewport.X = 0; + m_DynamicState.m_Viewport.Y = 0; + m_DynamicState.m_Viewport.Width = (DWORD)-1; + m_DynamicState.m_Viewport.Height = (DWORD)-1; + + ADD_COMMIT_FUNC( COMMIT_PER_DRAW, COMMIT_ALWAYS, CommitSetViewports ); +} + + +//----------------------------------------------------------------------------- +// Changes the render target +//----------------------------------------------------------------------------- +void CShaderAPIDx8::SetRenderTarget( ShaderAPITextureHandle_t colorTextureHandle, ShaderAPITextureHandle_t depthTextureHandle ) +{ + LOCK_SHADERAPI(); + SetRenderTargetEx( 0, colorTextureHandle, depthTextureHandle ); +} + +//----------------------------------------------------------------------------- +// Returns the nearest supported format +//----------------------------------------------------------------------------- +ImageFormat CShaderAPIDx8::GetNearestSupportedFormat( ImageFormat fmt, bool bFilteringRequired /* = true */ ) const +{ + return FindNearestSupportedFormat( fmt, false, false, bFilteringRequired ); +} + + +ImageFormat CShaderAPIDx8::GetNearestRenderTargetFormat( ImageFormat fmt ) const +{ + return FindNearestSupportedFormat( fmt, false, true, false ); +} + + +bool CShaderAPIDx8::DoRenderTargetsNeedSeparateDepthBuffer() const +{ + LOCK_SHADERAPI(); + return m_PresentParameters.MultiSampleType != D3DMULTISAMPLE_NONE; +} + + +//----------------------------------------------------------------------------- +// Indicates we're modifying a texture +//----------------------------------------------------------------------------- +void CShaderAPIDx8::ModifyTexture( ShaderAPITextureHandle_t textureHandle ) +{ + tmZone( TELEMETRY_LEVEL2, TMZF_NONE, "%s", __FUNCTION__ ); + + LOCK_SHADERAPI(); + // Can't do this if we're locked! + Assert( m_ModifyTextureLockedLevel < 0 ); + + AssertValidTextureHandle( textureHandle ); + m_ModifyTextureHandle = textureHandle; + + // If we're got a multi-copy texture, we need to up the current copy count + Texture_t& tex = GetTexture( textureHandle ); + if (tex.m_NumCopies > 1) + { + // Each time we modify a texture, we'll want to switch texture + // as soon as a TexImage2D call is made... + tex.m_SwitchNeeded = true; + } +} + + +//----------------------------------------------------------------------------- +// Advances the current copy of a texture... +//----------------------------------------------------------------------------- +void CShaderAPIDx8::AdvanceCurrentCopy( ShaderAPITextureHandle_t hTexture ) +{ + // May need to switch textures.... + Texture_t& tex = GetTexture( hTexture ); + if (tex.m_NumCopies > 1) + { + if (++tex.m_CurrentCopy >= tex.m_NumCopies) + tex.m_CurrentCopy = 0; + + // When the current copy changes, we need to make sure this texture + // isn't bound to any stages any more; thereby guaranteeing the new + // copy will be re-bound. + UnbindTexture( hTexture ); + } +} + + +//----------------------------------------------------------------------------- +// Locks, unlocks the current texture +//----------------------------------------------------------------------------- + +bool CShaderAPIDx8::TexLock( int level, int cubeFaceID, int xOffset, int yOffset, + int width, int height, CPixelWriter& writer ) +{ + tmZone( TELEMETRY_LEVEL2, TMZF_NONE, "%s", __FUNCTION__ ); + + LOCK_SHADERAPI(); + + Assert( m_ModifyTextureLockedLevel < 0 ); + + ShaderAPITextureHandle_t hTexture = GetModifyTextureHandle(); + if ( !m_Textures.IsValidIndex( hTexture ) ) + return false; + + // Blow off mip levels if we don't support mipmapping + if ( !g_pHardwareConfig->SupportsMipmapping() && ( level > 0 ) ) + return false; + + // This test here just makes sure we don't try to download mipmap levels + // if we weren't able to create them in the first place + Texture_t& tex = GetTexture( hTexture ); + if ( level >= tex.m_NumLevels ) + { + return false; + } + + // May need to switch textures.... + if ( tex.m_SwitchNeeded ) + { + AdvanceCurrentCopy( hTexture ); + tex.m_SwitchNeeded = false; + } + + IDirect3DBaseTexture *pTexture = GetModifyTexture(); +#if defined( _X360 ) + // 360 can't lock a bound texture + if ( pTexture->IsSet( Dx9Device() ) ) + { + UnbindTexture( hTexture ); + } +#endif + + bool bOK = LockTexture( hTexture, tex.m_CurrentCopy, pTexture, + level, (D3DCUBEMAP_FACES)cubeFaceID, xOffset, yOffset, width, height, false, writer ); + if ( bOK ) + { + m_ModifyTextureLockedLevel = level; + m_ModifyTextureLockedFace = cubeFaceID; + } + return bOK; +} + +void CShaderAPIDx8::TexUnlock( ) +{ + tmZone( TELEMETRY_LEVEL2, TMZF_NONE, "%s", __FUNCTION__ ); + + LOCK_SHADERAPI(); + if ( m_ModifyTextureLockedLevel >= 0 ) + { + Texture_t& tex = GetTexture( GetModifyTextureHandle() ); + UnlockTexture( GetModifyTextureHandle(), tex.m_CurrentCopy, GetModifyTexture(), + m_ModifyTextureLockedLevel, (D3DCUBEMAP_FACES)m_ModifyTextureLockedFace ); + + m_ModifyTextureLockedLevel = -1; + } +} + +//----------------------------------------------------------------------------- +// Texture image upload +//----------------------------------------------------------------------------- +void CShaderAPIDx8::TexImage2D( + int level, + int cubeFaceID, + ImageFormat dstFormat, + int z, + int width, + int height, + ImageFormat srcFormat, + bool bSrcIsTiled, + void *pSrcData ) +{ + LOCK_SHADERAPI(); + + Assert( pSrcData ); + AssertValidTextureHandle( GetModifyTextureHandle() ); + + if ( !m_Textures.IsValidIndex( GetModifyTextureHandle() ) ) + { + return; + } + + Assert( (width <= g_pHardwareConfig->Caps().m_MaxTextureWidth) && (height <= g_pHardwareConfig->Caps().m_MaxTextureHeight) ); + + // Blow off mip levels if we don't support mipmapping + if ( !g_pHardwareConfig->SupportsMipmapping() && (level > 0)) + { + return; + } + + // This test here just makes sure we don't try to download mipmap levels + // if we weren't able to create them in the first place + Texture_t& tex = GetTexture( GetModifyTextureHandle() ); + if ( level >= tex.m_NumLevels ) + { + return; + } + + // May need to switch textures.... + if (tex.m_SwitchNeeded) + { + AdvanceCurrentCopy( GetModifyTextureHandle() ); + tex.m_SwitchNeeded = false; + } + + TextureLoadInfo_t info; + info.m_TextureHandle = GetModifyTextureHandle(); + info.m_pTexture = GetModifyTexture(); + info.m_nLevel = level; + info.m_nCopy = tex.m_CurrentCopy; + info.m_CubeFaceID = (D3DCUBEMAP_FACES)cubeFaceID; + info.m_nWidth = width; + info.m_nHeight = height; + info.m_nZOffset = z; + info.m_SrcFormat = srcFormat; + info.m_pSrcData = (unsigned char *)pSrcData; +#if defined( _X360 ) + info.m_bSrcIsTiled = bSrcIsTiled; + info.m_bCanConvertFormat = ( tex.m_Flags & Texture_t::CAN_CONVERT_FORMAT ) != 0; +#else + info.m_bTextureIsLockable = ( tex.m_Flags & Texture_t::IS_LOCKABLE ) != 0; +#endif + LoadTexture( info ); + SetModifyTexture( info.m_pTexture ); +} + +//----------------------------------------------------------------------------- +// Upload to a sub-piece of a texture +//----------------------------------------------------------------------------- +void CShaderAPIDx8::TexSubImage2D( + int level, + int cubeFaceID, + int xOffset, + int yOffset, + int zOffset, + int width, + int height, + ImageFormat srcFormat, + int srcStride, + bool bSrcIsTiled, + void *pSrcData ) +{ + LOCK_SHADERAPI(); + + Assert( pSrcData ); + AssertValidTextureHandle( GetModifyTextureHandle() ); + + if ( !m_Textures.IsValidIndex( GetModifyTextureHandle() ) ) + { + return; + } + + // Blow off mip levels if we don't support mipmapping + if ( !g_pHardwareConfig->SupportsMipmapping() && ( level > 0 ) ) + { + return; + } + + // NOTE: This can only be done with procedural textures if this method is + // being used to download the entire texture, cause last frame's partial update + // may be in a completely different texture! Sadly, I don't have all of the + // information I need, but I can at least check a couple things.... +#ifdef _DEBUG + if ( GetTexture( GetModifyTextureHandle() ).m_NumCopies > 1 ) + { + Assert( (xOffset == 0) && (yOffset == 0) ); + } +#endif + + // This test here just makes sure we don't try to download mipmap levels + // if we weren't able to create them in the first place + Texture_t& tex = GetTexture( GetModifyTextureHandle() ); + if ( level >= tex.m_NumLevels ) + { + return; + } + + // May need to switch textures.... + if ( tex.m_SwitchNeeded ) + { + AdvanceCurrentCopy( GetModifyTextureHandle() ); + tex.m_SwitchNeeded = false; + } + + TextureLoadInfo_t info; + info.m_TextureHandle = GetModifyTextureHandle(); + info.m_pTexture = GetModifyTexture(); + info.m_nLevel = level; + info.m_nCopy = tex.m_CurrentCopy; + info.m_CubeFaceID = (D3DCUBEMAP_FACES)cubeFaceID; + info.m_nWidth = width; + info.m_nHeight = height; + info.m_nZOffset = zOffset; + info.m_SrcFormat = srcFormat; + info.m_pSrcData = (unsigned char *)pSrcData; +#if defined( _X360 ) + info.m_bSrcIsTiled = bSrcIsTiled; + info.m_bCanConvertFormat = ( tex.m_Flags & Texture_t::CAN_CONVERT_FORMAT ) != 0; +#else + info.m_bTextureIsLockable = ( tex.m_Flags & Texture_t::IS_LOCKABLE ) != 0; +#endif + LoadSubTexture( info, xOffset, yOffset, srcStride ); +} + +//----------------------------------------------------------------------------- +// Volume texture upload +//----------------------------------------------------------------------------- +void CShaderAPIDx8::TexImageFromVTF( IVTFTexture *pVTF, int iVTFFrame ) +{ + LOCK_SHADERAPI(); + Assert( pVTF ); + AssertValidTextureHandle( GetModifyTextureHandle() ); + if ( !m_Textures.IsValidIndex( GetModifyTextureHandle() ) ) + { + return; + } + Texture_t& tex = GetTexture( GetModifyTextureHandle() ); + + // May need to switch textures.... + if (tex.m_SwitchNeeded) + { + AdvanceCurrentCopy( GetModifyTextureHandle() ); + tex.m_SwitchNeeded = false; + } + + TextureLoadInfo_t info; + info.m_TextureHandle = GetModifyTextureHandle(); + info.m_pTexture = GetModifyTexture(); + info.m_nLevel = 0; + info.m_nCopy = tex.m_CurrentCopy; + info.m_CubeFaceID = (D3DCUBEMAP_FACES)0; + info.m_nWidth = 0; + info.m_nHeight = 0; + info.m_nZOffset = 0; + info.m_SrcFormat = pVTF->Format(); + info.m_pSrcData = NULL; +#if defined( _X360 ) + info.m_bSrcIsTiled = pVTF->IsPreTiled(); + info.m_bCanConvertFormat = ( tex.m_Flags & Texture_t::CAN_CONVERT_FORMAT ) != 0; +#else + info.m_bTextureIsLockable = ( tex.m_Flags & Texture_t::IS_LOCKABLE ) != 0; +#endif + if ( pVTF->Depth() > 1 ) + { + LoadVolumeTextureFromVTF( info, pVTF, iVTFFrame ); + } + else if ( pVTF->IsCubeMap() ) + { + if ( HardwareConfig()->SupportsCubeMaps() ) + { + LoadCubeTextureFromVTF( info, pVTF, iVTFFrame ); + } + else + { + info.m_CubeFaceID = (D3DCUBEMAP_FACES)6; + LoadTextureFromVTF( info, pVTF, iVTFFrame ); + } + } + else + { + LoadTextureFromVTF( info, pVTF, iVTFFrame ); + } + SetModifyTexture( info.m_pTexture ); +} + + +//----------------------------------------------------------------------------- +// Is the texture resident? +//----------------------------------------------------------------------------- +bool CShaderAPIDx8::IsTextureResident( ShaderAPITextureHandle_t textureHandle ) +{ + return true; +} + + +//----------------------------------------------------------------------------- +// Level of anisotropic filtering +//----------------------------------------------------------------------------- +void CShaderAPIDx8::SetAnisotropicLevel( int nAnisotropyLevel ) +{ + LOCK_SHADERAPI(); + + // NOTE: This must be called before the rest of the code in this function so + // anisotropic can be set per-texture to force it on! This will also avoid + // a possible infinite loop that existed before. + g_pShaderUtil->NoteAnisotropicLevel( nAnisotropyLevel ); + + // Never set this to 1. In the case we want it set to 1, we will use this to override + // aniso per-texture, so set it to something reasonable + if ( nAnisotropyLevel > g_pHardwareConfig->Caps().m_nMaxAnisotropy || nAnisotropyLevel <= 1 ) + { + // Set it to 1/4 the max but between 2-8 + nAnisotropyLevel = max( 2, min( 8, ( g_pHardwareConfig->Caps().m_nMaxAnisotropy / 4 ) ) ); + } + + // Set the D3D max insotropy state for all samplers + for ( int i = 0; i < g_pHardwareConfig->Caps().m_NumSamplers; ++i) + { + SamplerState(i).m_nAnisotropicLevel = nAnisotropyLevel; + SetSamplerState( i, D3DSAMP_MAXANISOTROPY, SamplerState(i).m_nAnisotropicLevel ); + } +} + + +//----------------------------------------------------------------------------- +// Sets the priority +//----------------------------------------------------------------------------- +void CShaderAPIDx8::TexSetPriority( int priority ) +{ +#if !defined( _X360 ) + LOCK_SHADERAPI(); + + // A hint to the cacher... + ShaderAPITextureHandle_t hModifyTexture = GetModifyTextureHandle(); + if ( hModifyTexture == INVALID_SHADERAPI_TEXTURE_HANDLE ) + return; + + Texture_t& tex = GetTexture( hModifyTexture ); + if ( tex.m_NumCopies > 1 ) + { + for (int i = 0; i < tex.m_NumCopies; ++i) + tex.GetTexture( i )->SetPriority( priority ); + } + else + { + tex.GetTexture()->SetPriority( priority ); + } +#endif +} + +void CShaderAPIDx8::TexLodClamp( int finest ) +{ + LOCK_SHADERAPI(); + + ShaderAPITextureHandle_t hModifyTexture = GetModifyTextureHandle(); + if ( hModifyTexture == INVALID_SHADERAPI_TEXTURE_HANDLE ) + return; + + Texture_t& tex = GetTexture( hModifyTexture ); + tex.m_FinestMipmapLevel = finest; +} + +void CShaderAPIDx8::TexLodBias( float bias ) +{ + LOCK_SHADERAPI(); + + ShaderAPITextureHandle_t hModifyTexture = GetModifyTextureHandle(); + if ( hModifyTexture == INVALID_SHADERAPI_TEXTURE_HANDLE ) + return; + + Texture_t& tex = GetTexture( hModifyTexture ); + tex.m_LodBias = bias; +} + + + +//----------------------------------------------------------------------------- +// Texturemapping state +//----------------------------------------------------------------------------- +void CShaderAPIDx8::TexWrap( ShaderTexCoordComponent_t coord, ShaderTexWrapMode_t wrapMode ) +{ + LOCK_SHADERAPI(); + + ShaderAPITextureHandle_t hModifyTexture = GetModifyTextureHandle(); + if ( hModifyTexture == INVALID_SHADERAPI_TEXTURE_HANDLE ) + return; + + D3DTEXTUREADDRESS address; + switch( wrapMode ) + { + case SHADER_TEXWRAPMODE_CLAMP: + address = D3DTADDRESS_CLAMP; + break; + case SHADER_TEXWRAPMODE_REPEAT: + address = D3DTADDRESS_WRAP; + break; + case SHADER_TEXWRAPMODE_BORDER: + address = D3DTADDRESS_BORDER; + break; + default: + address = D3DTADDRESS_CLAMP; + Warning( "CShaderAPIDx8::TexWrap: unknown wrapMode\n" ); + break; + } + + switch( coord ) + { + case SHADER_TEXCOORD_S: + GetTexture( hModifyTexture ).m_UTexWrap = address; + break; + case SHADER_TEXCOORD_T: + GetTexture( hModifyTexture ).m_VTexWrap = address; + break; + case SHADER_TEXCOORD_U: + GetTexture( hModifyTexture ).m_WTexWrap = address; + break; + default: + Warning( "CShaderAPIDx8::TexWrap: unknown coord\n" ); + break; + } +} + +void CShaderAPIDx8::TexMinFilter( ShaderTexFilterMode_t texFilterMode ) +{ + LOCK_SHADERAPI(); + + ShaderAPITextureHandle_t hModifyTexture = GetModifyTextureHandle(); + if ( hModifyTexture == INVALID_SHADERAPI_TEXTURE_HANDLE ) + return; + + switch( texFilterMode ) + { + case SHADER_TEXFILTERMODE_NEAREST: + GetTexture( hModifyTexture ).m_MinFilter = D3DTEXF_POINT; + GetTexture( hModifyTexture ).m_MipFilter = D3DTEXF_NONE; + break; + case SHADER_TEXFILTERMODE_LINEAR: + GetTexture( hModifyTexture ).m_MinFilter = D3DTEXF_LINEAR; + GetTexture( hModifyTexture ).m_MipFilter = D3DTEXF_NONE; + break; + case SHADER_TEXFILTERMODE_NEAREST_MIPMAP_NEAREST: + GetTexture( hModifyTexture ).m_MinFilter = D3DTEXF_POINT; + GetTexture( hModifyTexture ).m_MipFilter = + GetTexture( hModifyTexture ).m_NumLevels != 1 ? D3DTEXF_POINT : D3DTEXF_NONE; + break; + case SHADER_TEXFILTERMODE_LINEAR_MIPMAP_NEAREST: + GetTexture( hModifyTexture ).m_MinFilter = D3DTEXF_LINEAR; + GetTexture( hModifyTexture ).m_MipFilter = + GetTexture( hModifyTexture ).m_NumLevels != 1 ? D3DTEXF_POINT : D3DTEXF_NONE; + break; + case SHADER_TEXFILTERMODE_NEAREST_MIPMAP_LINEAR: + GetTexture( hModifyTexture ).m_MinFilter = D3DTEXF_POINT; + GetTexture( hModifyTexture ).m_MipFilter = + GetTexture( hModifyTexture ).m_NumLevels != 1 ? D3DTEXF_LINEAR : D3DTEXF_NONE; + break; + case SHADER_TEXFILTERMODE_LINEAR_MIPMAP_LINEAR: + GetTexture( hModifyTexture ).m_MinFilter = D3DTEXF_LINEAR; + GetTexture( hModifyTexture ).m_MipFilter = + GetTexture( hModifyTexture ).m_NumLevels != 1 ? D3DTEXF_LINEAR : D3DTEXF_NONE; + break; + case SHADER_TEXFILTERMODE_ANISOTROPIC: + GetTexture( hModifyTexture ).m_MinFilter = D3DTEXF_ANISOTROPIC; + GetTexture( hModifyTexture ).m_MipFilter = + GetTexture( hModifyTexture ).m_NumLevels != 1 ? D3DTEXF_LINEAR : D3DTEXF_NONE; + break; + default: + Warning( "CShaderAPIDx8::TexMinFilter: Unknown texFilterMode\n" ); + break; + } +} + +void CShaderAPIDx8::TexMagFilter( ShaderTexFilterMode_t texFilterMode ) +{ + LOCK_SHADERAPI(); + + ShaderAPITextureHandle_t hModifyTexture = GetModifyTextureHandle(); + if ( hModifyTexture == INVALID_SHADERAPI_TEXTURE_HANDLE ) + return; + + switch( texFilterMode ) + { + case SHADER_TEXFILTERMODE_NEAREST: + GetTexture( hModifyTexture ).m_MagFilter = D3DTEXF_POINT; + break; + case SHADER_TEXFILTERMODE_LINEAR: + GetTexture( hModifyTexture ).m_MagFilter = D3DTEXF_LINEAR; + break; + case SHADER_TEXFILTERMODE_NEAREST_MIPMAP_NEAREST: + Warning( "CShaderAPIDx8::TexMagFilter: SHADER_TEXFILTERMODE_NEAREST_MIPMAP_NEAREST is invalid\n" ); + break; + case SHADER_TEXFILTERMODE_LINEAR_MIPMAP_NEAREST: + Warning( "CShaderAPIDx8::TexMagFilter: SHADER_TEXFILTERMODE_LINEAR_MIPMAP_NEAREST is invalid\n" ); + break; + case SHADER_TEXFILTERMODE_NEAREST_MIPMAP_LINEAR: + Warning( "CShaderAPIDx8::TexMagFilter: SHADER_TEXFILTERMODE_NEAREST_MIPMAP_LINEAR is invalid\n" ); + break; + case SHADER_TEXFILTERMODE_LINEAR_MIPMAP_LINEAR: + Warning( "CShaderAPIDx8::TexMagFilter: SHADER_TEXFILTERMODE_LINEAR_MIPMAP_LINEAR is invalid\n" ); + break; + case SHADER_TEXFILTERMODE_ANISOTROPIC: + GetTexture( hModifyTexture ).m_MagFilter = g_pHardwareConfig->Caps().m_bSupportsMagAnisotropicFiltering ? D3DTEXF_ANISOTROPIC : D3DTEXF_LINEAR; + break; + default: + Warning( "CShaderAPIDx8::TexMAGFilter: Unknown texFilterMode\n" ); + break; + } +} + + +//----------------------------------------------------------------------------- +// Gets the matrix stack from the matrix mode +//----------------------------------------------------------------------------- + +int CShaderAPIDx8::GetMatrixStack( MaterialMatrixMode_t mode ) const +{ + Assert( mode >= 0 && mode < NUM_MATRIX_MODES ); + return mode; +} + +//----------------------------------------------------------------------------- +// Returns true if we're modulating constant color into the vertex color +//----------------------------------------------------------------------------- +bool CShaderAPIDx8::IsModulatingVertexColor() const +{ + return m_TransitionTable.CurrentShadowShaderState()->m_ModulateConstantColor; +} + + +//----------------------------------------------------------------------------- +// Material property (used to deal with overbright for lights) +//----------------------------------------------------------------------------- +void CShaderAPIDx8::SetDefaultMaterial() +{ +#if !defined( _X360 ) + D3DMATERIAL mat; + mat.Diffuse.r = mat.Diffuse.g = mat.Diffuse.b = mat.Diffuse.a = 1.0f; + mat.Ambient.r = mat.Ambient.g = mat.Ambient.b = mat.Ambient.a = 0.0f; + mat.Specular.r = mat.Specular.g = mat.Specular.b = mat.Specular.a = 0.0f; + mat.Emissive.r = mat.Emissive.g = mat.Emissive.b = mat.Emissive.a = 0.0f; + mat.Power = 1.0f; + Dx9Device()->SetMaterial( &mat ); +#endif +} + +//----------------------------------------------------------------------------- +// lighting related methods +//----------------------------------------------------------------------------- + +void CShaderAPIDx8::SetAmbientLight( float r, float g, float b ) +{ + LOCK_SHADERAPI(); + unsigned int ambient = D3DCOLOR_ARGB( 255, (int)(r * 255), + (int)(g * 255), (int)(b * 255) ); + if (ambient != m_DynamicState.m_Ambient) + { + m_DynamicState.m_Ambient = ambient; + SetSupportedRenderState( D3DRS_AMBIENT, ambient ); + } +} + +void CShaderAPIDx8::SetLightingOrigin( Vector vLightingOrigin ) +{ + if ( vLightingOrigin != m_DynamicState.m_vLightingOrigin ) + { + FlushBufferedPrimitives(); + m_DynamicState.m_vLightingOrigin = vLightingOrigin; + } +} + +//#define NO_LOCAL_LIGHTS +void CShaderAPIDx8::SetLight( int lightNum, const LightDesc_t& desc_ ) +{ + LOCK_SHADERAPI(); +#ifdef NO_LOCAL_LIGHTS + LightDesc_t desc = desc_; + desc.m_Type = MATERIAL_LIGHT_DISABLE; +#else + LightDesc_t &desc = const_cast(desc_); // to permit '&' +#endif + Assert( lightNum < g_pHardwareConfig->Caps().m_MaxNumLights && lightNum >= 0 ); + + if( lightNum >= g_pHardwareConfig->Caps().m_MaxNumLights || lightNum < 0 ) + return; + + m_DynamicState.m_LightDescs[lightNum] = desc; + + FlushBufferedPrimitives(); + + if (desc.m_Type == MATERIAL_LIGHT_DISABLE) + { + if (m_DynamicState.m_LightEnable[lightNum]) + { + m_DynamicState.m_LightEnableChanged[lightNum] = STATE_CHANGED; + m_DynamicState.m_LightEnable[lightNum] = false; + } + return; + } + + if (!m_DynamicState.m_LightEnable[lightNum]) + { + m_DynamicState.m_LightEnableChanged[lightNum] = STATE_CHANGED; + m_DynamicState.m_LightEnable[lightNum] = true; + } + + D3DLIGHT light; + switch( desc.m_Type ) + { + case MATERIAL_LIGHT_POINT: + light.Type = D3DLIGHT_POINT; + light.Range = desc.m_Range; + break; + + case MATERIAL_LIGHT_DIRECTIONAL: + light.Type = D3DLIGHT_DIRECTIONAL; + light.Range = 1e12; // This is supposed to be ignored + break; + + case MATERIAL_LIGHT_SPOT: + light.Type = D3DLIGHT_SPOT; + light.Range = desc.m_Range; + break; + + default: + m_DynamicState.m_LightEnable[lightNum] = false; + return; + } + + // This is a D3D limitation + Assert( (light.Range >= 0) && (light.Range <= sqrt(FLT_MAX)) ); + + memcpy( &light.Diffuse, &desc.m_Color[0], 3*sizeof(float) ); + memcpy( &light.Specular, &desc.m_Color[0], 3*sizeof(float) ); + light.Diffuse.a = 1.0f; + light.Specular.a = 1.0f; + light.Ambient.a = light.Ambient.b = light.Ambient.g = light.Ambient.r = 0; + memcpy( &light.Position, &desc.m_Position[0], 3 * sizeof(float) ); + memcpy( &light.Direction, &desc.m_Direction[0], 3 * sizeof(float) ); + light.Falloff = desc.m_Falloff; + light.Attenuation0 = desc.m_Attenuation0; + light.Attenuation1 = desc.m_Attenuation1; + light.Attenuation2 = desc.m_Attenuation2; + + // normalize light color... + light.Theta = desc.m_Theta; + light.Phi = desc.m_Phi; + if (light.Phi > M_PI) + light.Phi = M_PI; + + // This piece of crap line of code is because if theta gets too close to phi, + // we get no light at all. + if (light.Theta - light.Phi > -1e-3) + light.Theta = light.Phi - 1e-3; + + m_DynamicState.m_LightChanged[lightNum] = STATE_CHANGED; + memcpy( &m_DynamicState.m_Lights[lightNum], &light, sizeof(light) ); +} + +void CShaderAPIDx8::DisableAllLocalLights() +{ + LOCK_SHADERAPI(); + bool bFlushed = false; + for ( int lightNum = 0; lightNum < MAX_NUM_LIGHTS; lightNum++ ) + { + if (m_DynamicState.m_LightEnable[lightNum]) + { + if ( !bFlushed ) + { + FlushBufferedPrimitives(); + bFlushed = true; + } + m_DynamicState.m_LightDescs[lightNum].m_Type = MATERIAL_LIGHT_DISABLE; + m_DynamicState.m_LightEnableChanged[lightNum] = STATE_CHANGED; + m_DynamicState.m_LightEnable[lightNum] = false; + } + } +} + +int CShaderAPIDx8::GetMaxLights( void ) const +{ + return g_pHardwareConfig->Caps().m_MaxNumLights; +} + +const LightDesc_t& CShaderAPIDx8::GetLight( int lightNum ) const +{ + Assert( lightNum < g_pHardwareConfig->Caps().m_MaxNumLights && lightNum >= 0 ); + return m_DynamicState.m_LightDescs[lightNum]; +} + +//----------------------------------------------------------------------------- +// Ambient cube +//----------------------------------------------------------------------------- + +//#define NO_AMBIENT_CUBE 1 +void CShaderAPIDx8::SetAmbientLightCube( Vector4D cube[6] ) +{ + LOCK_SHADERAPI(); +/* + int i; + for( i = 0; i < 6; i++ ) + { + ColorClamp( cube[i].AsVector3D() ); +// if( i == 0 ) +// { +// Warning( "%d: %f %f %f\n", i, cube[i][0], cube[i][1], cube[i][2] ); +// } + } +*/ + if (memcmp(&m_DynamicState.m_AmbientLightCube[0][0], cube, 6 * sizeof(Vector4D))) + { + memcpy( &m_DynamicState.m_AmbientLightCube[0][0], cube, 6 * sizeof(Vector4D) ); + +#ifdef NO_AMBIENT_CUBE + memset( &m_DynamicState.m_AmbientLightCube[0][0], 0, 6 * sizeof(Vector4D) ); +#endif + +//#define DEBUG_AMBIENT_CUBE + +#ifdef DEBUG_AMBIENT_CUBE + m_DynamicState.m_AmbientLightCube[0][0] = 1.0f; + m_DynamicState.m_AmbientLightCube[0][1] = 0.0f; + m_DynamicState.m_AmbientLightCube[0][2] = 0.0f; + + m_DynamicState.m_AmbientLightCube[1][0] = 0.0f; + m_DynamicState.m_AmbientLightCube[1][1] = 1.0f; + m_DynamicState.m_AmbientLightCube[1][2] = 0.0f; + + m_DynamicState.m_AmbientLightCube[2][0] = 0.0f; + m_DynamicState.m_AmbientLightCube[2][1] = 0.0f; + m_DynamicState.m_AmbientLightCube[2][2] = 1.0f; + + m_DynamicState.m_AmbientLightCube[3][0] = 1.0f; + m_DynamicState.m_AmbientLightCube[3][1] = 0.0f; + m_DynamicState.m_AmbientLightCube[3][2] = 1.0f; + + m_DynamicState.m_AmbientLightCube[4][0] = 1.0f; + m_DynamicState.m_AmbientLightCube[4][1] = 1.0f; + m_DynamicState.m_AmbientLightCube[4][2] = 0.0f; + + m_DynamicState.m_AmbientLightCube[5][0] = 0.0f; + m_DynamicState.m_AmbientLightCube[5][1] = 1.0f; + m_DynamicState.m_AmbientLightCube[5][2] = 1.0f; +#endif + + m_CachedAmbientLightCube = STATE_CHANGED; + } +} + +void CShaderAPIDx8::SetVertexShaderStateAmbientLightCube() +{ + if (m_CachedAmbientLightCube & STATE_CHANGED_VERTEX_SHADER) + { + SetVertexShaderConstant( VERTEX_SHADER_AMBIENT_LIGHT, m_DynamicState.m_AmbientLightCube[0].Base(), 6 ); + m_CachedAmbientLightCube &= ~STATE_CHANGED_VERTEX_SHADER; + } +} + + +void CShaderAPIDx8::SetPixelShaderStateAmbientLightCube( int pshReg, bool bForceToBlack ) +{ + float *pCubeBase; + Vector4D tempCube[6]; + + if( bForceToBlack ) + { + for ( int i=0; i<6 ; i++ ) + tempCube[i].Init(); + + pCubeBase = tempCube[0].Base(); + } + else + { + pCubeBase = m_DynamicState.m_AmbientLightCube[0].Base(); + } + + SetPixelShaderConstant( pshReg, pCubeBase, 6 ); +} + +float CShaderAPIDx8::GetAmbientLightCubeLuminance( void ) +{ + Vector4D vLuminance( 0.3f, 0.59f, 0.11f, 0.0f ); + float fLuminance = 0.0f; + + for (int i=0; i<6; i++) + { + fLuminance += vLuminance.Dot( m_DynamicState.m_AmbientLightCube[i] ); + } + + return fLuminance / 6.0f; +} + +static inline RECT* RectToRECT( Rect_t *pSrcRect, RECT &dstRect ) +{ + if ( !pSrcRect ) + return NULL; + + dstRect.left = pSrcRect->x; + dstRect.top = pSrcRect->y; + dstRect.right = pSrcRect->x + pSrcRect->width; + dstRect.bottom = pSrcRect->y + pSrcRect->height; + return &dstRect; +} + +void CShaderAPIDx8::CopyRenderTargetToTextureEx( ShaderAPITextureHandle_t textureHandle, int nRenderTargetID, Rect_t *pSrcRect, Rect_t *pDstRect ) +{ + LOCK_SHADERAPI(); + VPROF_BUDGET( "CShaderAPIDx8::CopyRenderTargetToTexture", "Refraction overhead" ); + + if ( !TextureIsAllocated( textureHandle ) ) + return; + +#if defined( PIX_INSTRUMENTATION ) + { + const char *pRT = ( nRenderTargetID < 0 ) ? "DS" : "RT"; + + if ( textureHandle == SHADER_RENDERTARGET_NONE ) + { + pRT = "None"; + } + else if ( textureHandle != SHADER_RENDERTARGET_BACKBUFFER ) + { + Texture_t &tex = GetTexture( textureHandle ); + pRT = tex.m_DebugName.String(); + } + + char buf[256]; + sprintf( buf, "CopyRTToTexture:%s", pRT ? pRT : "?" ); + BeginPIXEvent( 0xFFFFFFFF, buf ); + EndPIXEvent(); + } +#endif + + // Don't flush here!! If you have to flush here, then there is a driver bug. + // FlushHardware( ); + + AssertValidTextureHandle( textureHandle ); + Texture_t *pTexture = &GetTexture( textureHandle ); + Assert( pTexture ); + IDirect3DTexture *pD3DTexture = (IDirect3DTexture *)pTexture->GetTexture(); + Assert( pD3DTexture ); + +#if !defined( _X360 ) + IDirect3DSurface* pRenderTargetSurface; + HRESULT hr = Dx9Device()->GetRenderTarget( nRenderTargetID, &pRenderTargetSurface ); + if ( FAILED( hr ) ) + { + Assert( 0 ); + return; + } + + IDirect3DSurface *pDstSurf; + hr = pD3DTexture->GetSurfaceLevel( 0, &pDstSurf ); + Assert( !FAILED( hr ) ); + if ( FAILED( hr ) ) + { + pRenderTargetSurface->Release(); + return; + } + + bool tryblit = true; + if ( tryblit ) + { + RECORD_COMMAND( DX8_COPY_FRAMEBUFFER_TO_TEXTURE, 1 ); + RECORD_INT( textureHandle ); + + RECT srcRect, dstRect; + hr = Dx9Device()->StretchRect( pRenderTargetSurface, RectToRECT( pSrcRect, srcRect ), + pDstSurf, RectToRECT( pDstRect, dstRect ), D3DTEXF_LINEAR ); + Assert( !FAILED( hr ) ); + } + + pDstSurf->Release(); + pRenderTargetSurface->Release(); +#else + DWORD flags = 0; + switch( nRenderTargetID ) + { + case -1: + flags = D3DRESOLVE_DEPTHSTENCIL | D3DRESOLVE_FRAGMENT0; + break; + case 0: + flags = D3DRESOLVE_RENDERTARGET0; + break; + case 1: + case 2: + case 3: + // not supporting MRT + Assert( 0 ); + return; + NO_DEFAULT + }; + + // not prepared to handle mip mapping yet + Assert( pD3DTexture->GetLevelCount() == 1 ); + + D3DPOINT dstPoint = { 0 }; + if ( pDstRect ) + { + dstPoint.x = pDstRect->x; + dstPoint.y = pDstRect->y; + } + + int destWidth, destHeight; + if( pDstRect ) + { + destWidth = pDstRect->width; + destHeight = pDstRect->height; + + Assert( (destWidth <= pTexture->GetWidth()) && (destHeight <= pTexture->GetHeight()) ); + } + else + { + destWidth = pTexture->GetWidth(); + destHeight = pTexture->GetHeight(); + } + + RECT srcRect; + RECT *pResolveRect = NULL; + int srcWidth, srcHeight; + if ( pSrcRect ) + { + RectToRECT( pSrcRect, srcRect ); + pResolveRect = &srcRect; + + // resolve has no stretching ability, and we can only compensate when doing a resolve to a whole texture larger than the source + Assert( !pDstRect || ( pSrcRect->width <= pDstRect->width && pSrcRect->height <= pDstRect->height ) ); + + srcWidth = pSrcRect->width; + srcHeight = pSrcRect->height; + } + else + { + srcRect.left = srcRect.top = 0; + srcRect.right = m_DynamicState.m_Viewport.Width; + srcRect.bottom = m_DynamicState.m_Viewport.Height; + if( (srcRect.right < 0) || (srcRect.bottom < 0) ) + { + if( m_UsingTextureRenderTarget ) + { + srcRect.right = m_ViewportMaxWidth; + srcRect.bottom = m_ViewportMaxHeight; + } + else + { + int w,h; + GetBackBufferDimensions( w, h ); + srcRect.right = w; + srcRect.bottom = h; + } + } + srcWidth = srcRect.right; + srcHeight = srcRect.bottom; + } + + if( (srcWidth != destWidth) || (srcHeight != destHeight) ) + { + //Not a 1:1 resolve, we should only have gotten this far if we can downsize the target texture to compensate + Assert( (destWidth > srcWidth) && (destHeight > srcHeight) && (dstPoint.x == 0) && (dstPoint.y == 0) ); + + //What we're doing is telling D3D that this texture is smaller than it is so the resolve is 1:1. + //We leave the texture in this state until it resolves from something bigger. + //All outside code still thinks this texture is it's original size. And it still owns enough memory to go back to it's original size. + pD3DTexture->Format.Size.TwoD.Width = srcWidth - 1; + pD3DTexture->Format.Size.TwoD.Height = srcHeight - 1; //no idea why they store it as size-1, but they do + pResolveRect = NULL; + } + else + { + //restore D3D texture to full size in case it was previously downsized + pD3DTexture->Format.Size.TwoD.Width = pTexture->GetWidth() - 1; + pD3DTexture->Format.Size.TwoD.Height = pTexture->GetHeight() - 1; //no idea why they store it as size-1, but they do + } + + // if we convert to srgb format, we need the original format for reverting. We only need the first DWORD of GPUTEXTURE_FETCH_CONSTANT. + DWORD linearFormatBackup = pD3DTexture->Format.dword[0]; + if ( !( flags & D3DRESOLVE_DEPTHSTENCIL ) && ( m_DynamicState.m_bSRGBWritesEnabled ) ) + { + // we need a matched resolve regarding sRGB to get values transfered as-is + // when the surface is sRGB, use the corresponding sRGB texture + pD3DTexture->Format.SignX = pD3DTexture->Format.SignY = pD3DTexture->Format.SignZ = 3; + } + + HRESULT hr = Dx9Device()->Resolve( flags, (D3DRECT*)pResolveRect, pD3DTexture, &dstPoint, 0, 0, NULL, 0, 0, NULL ); + Assert( !FAILED( hr ) ); + + pD3DTexture->Format.dword[0] = linearFormatBackup; +#endif +} + +void CShaderAPIDx8::CopyRenderTargetToScratchTexture( ShaderAPITextureHandle_t srcRt, ShaderAPITextureHandle_t dstTex, Rect_t *pSrcRect, Rect_t *pDstRect ) +{ + LOCK_SHADERAPI(); + + if ( !TextureIsAllocated( srcRt ) || !TextureIsAllocated( dstTex ) ) + { + Assert( !"Fix that render target or dest texture aren't allocated." ); + return; + } + + HRESULT hr = D3D_OK; + + IDirect3DSurface9* srcSurf = NULL; + AssertValidTextureHandle( srcRt ); + Texture_t *pSrcRt = &GetTexture( srcRt ); + Assert( pSrcRt ); + IDirect3DTexture *pD3DSrcRt = ( IDirect3DTexture * ) pSrcRt->GetTexture(); + Assert( pD3DSrcRt ); + hr = pD3DSrcRt->GetSurfaceLevel( 0, &srcSurf ); + Assert( SUCCEEDED( hr ) && srcSurf ); + + IDirect3DSurface9* dstSurf = NULL; + AssertValidTextureHandle( dstTex ); + Texture_t *pDstTex = &GetTexture( dstTex ); + Assert( pDstTex ); + IDirect3DTexture *pD3DDstTex = ( IDirect3DTexture * ) pDstTex->GetTexture(); + Assert( pD3DDstTex ); + hr = pD3DDstTex->GetSurfaceLevel( 0, &dstSurf ); + Assert( SUCCEEDED( hr ) && dstSurf ); + + // This does it. + hr = Dx9Device()->GetRenderTargetData( srcSurf, dstSurf ); + Assert( SUCCEEDED( hr ) ); + + srcSurf->Release(); + dstSurf->Release(); +} + +//------------------------------------------------------------------------- +// Allows locking and unlocking of very specific surface types. pOutBits and pOutPitch will not be touched if +// the lock fails. +//------------------------------------------------------------------------- +void CShaderAPIDx8::LockRect( void** pOutBits, int* pOutPitch, ShaderAPITextureHandle_t texHandle, int mipmap, int x, int y, int w, int h, bool bWrite, bool bRead ) +{ + LOCK_SHADERAPI(); + + Assert( pOutBits ); + Assert( pOutPitch ); + + if ( !TextureIsAllocated( texHandle ) ) + { + Assert( !"Fix that texture isn't allocated." ); + return; + } + + HRESULT hr = D3D_OK; + IDirect3DSurface9* surf = NULL; + AssertValidTextureHandle( texHandle ); + Texture_t *pTex = &GetTexture( texHandle ); + Assert( pTex ); + IDirect3DTexture *pD3DTex = ( IDirect3DTexture * ) pTex->GetTexture(); + Assert( pD3DTex ); + + hr = pD3DTex->GetSurfaceLevel( mipmap, &surf ); + Assert( SUCCEEDED( hr ) && surf ); + + D3DLOCKED_RECT lockRect = { 0 }; + RECT srcRect = { x, y, w, h }; + DWORD flags = 0; + + if ( !bRead && !bWrite ) + { + Assert( !"Asking to neither read nor write? Probably a caller bug." ); + goto cleanup; + } + + if ( bRead && !bWrite ) + flags = D3DLOCK_READONLY; + + hr = surf->LockRect( &lockRect, &srcRect, flags ); + if ( FAILED( hr ) ) + { + Assert( !"Lock failed, look into why." ); + goto cleanup; + } + + (*pOutBits) = lockRect.pBits; + (*pOutPitch) = lockRect.Pitch; + +cleanup: + surf->Release(); +} + +void CShaderAPIDx8::UnlockRect( ShaderAPITextureHandle_t texHandle, int mipmap ) +{ + LOCK_SHADERAPI(); + + if ( !TextureIsAllocated( texHandle ) ) + { + Assert( !"Fix that texture isn't allocated." ); + return; + } + + HRESULT hr = D3D_OK; + IDirect3DSurface9* surf = NULL; + AssertValidTextureHandle( texHandle ); + Texture_t *pTex = &GetTexture( texHandle ); + Assert( pTex ); + IDirect3DTexture *pD3DTex = ( IDirect3DTexture * ) pTex->GetTexture(); + Assert( pD3DTex ); + + hr = pD3DTex->GetSurfaceLevel( mipmap, &surf ); + Assert( SUCCEEDED( hr ) && surf ); + + hr = surf->UnlockRect(); + Assert( SUCCEEDED( hr ) ); + + surf->Release(); +} + +static float GetAspectRatio( const Texture_t* pTex ) +{ + Assert( pTex ); + if ( pTex->m_Height != 0 ) + return float( pTex->m_Width ) / float( pTex->m_Height ); + + Assert( !"Height of texture is 0, that seems like a bug." ); + return 0.0f; +} + +struct TextureExtents_t +{ + int width; + int height; + int depth; + int mipmaps; + + int fine; + int coarse; + + TextureExtents_t() : width( 0 ), height( 0 ), depth( 0 ), mipmaps( 0 ), fine( 0 ), coarse( 0 ) { } +}; + +// Returns positive integer on success, 0 or <0 on failure. +static int FindCommonMipmapRange( int *pOutSrcFine, int *pOutDstFine, Texture_t *pSrcTex, Texture_t *pDstTex ) +{ + Assert( pOutSrcFine && pOutDstFine ); + Assert( pSrcTex && pDstTex ); + + if ( GetAspectRatio( pSrcTex ) != GetAspectRatio( pDstTex ) ) + return 0; + + TextureExtents_t src, + dst; + + // LOD Clamp indicates that there's no actual data in the finer mipmap levels yet, so respect it when determining + // the source and destination levels that could have data. + const int srcLodClamp = pSrcTex->GetLodClamp(); + src.width = Max( 1, pSrcTex->GetWidth() >> srcLodClamp ); + src.height = Max( 1, pSrcTex->GetHeight() >> srcLodClamp ); + src.depth = Max( 1, pSrcTex->GetDepth() >> srcLodClamp ); + src.mipmaps = pSrcTex->m_NumLevels - srcLodClamp; + Assert( src.mipmaps >= 1 ); + + + const int dstLodClamp = pDstTex->GetLodClamp(); + dst.width = Max( 1, pDstTex->GetWidth() >> dstLodClamp ); + dst.height = Max( 1, pDstTex->GetHeight() >> dstLodClamp ); + dst.depth = Max( 1, pDstTex->GetDepth() >> dstLodClamp ); + dst.mipmaps = pDstTex->m_NumLevels - dstLodClamp; + Assert( dst.mipmaps >= 1 ); + + TextureExtents_t *pLarger = NULL, + *pSmaller = NULL; + + if ( src.width >= dst.width && src.height >= dst.height && src.depth >= dst.depth ) + { + pLarger = &src; + pSmaller = &dst; + } + else + { + pLarger = &dst; + pSmaller = &src; + } + + // Since we are same aspect ratio, only need to test one dimension + while ( ( pLarger->width >> pLarger->fine ) > pSmaller->width ) + { + ++pLarger->fine; + --pLarger->mipmaps; + } + + ( *pOutSrcFine ) = src.fine; + ( *pOutDstFine ) = dst.fine; + + return Min( src.mipmaps, dst.mipmaps ); +} + +void CShaderAPIDx8::CopyTextureToTexture( ShaderAPITextureHandle_t srcTex, ShaderAPITextureHandle_t dstTex ) +{ + LOCK_SHADERAPI(); + + AssertValidTextureHandle( srcTex ); + AssertValidTextureHandle( dstTex ); + + Assert( TextureIsAllocated( srcTex ) && TextureIsAllocated( dstTex ) ); + + Texture_t *pSrcTex = &GetTexture( srcTex ); + Texture_t *pDstTex = &GetTexture( dstTex ); + + Assert( pSrcTex && pDstTex ); + + // Must have same image format + Assert( pSrcTex->GetImageFormat() == pDstTex->GetImageFormat() ); + + int srcFine = 0, + dstFine = 0; + + int mipmapCount = FindCommonMipmapRange( &srcFine, &dstFine, pSrcTex, pDstTex ); + + if ( mipmapCount <= 0 ) + { + // This is legit for things that are streamed in that are very small (near the 32x32 cutoff we do at the + // tip of the mipmap pyramid). But leaving it here because it's useful if you're tracking a specific bug. + // Warning( "Attempted to copy textures that had non-overlapping mipmap pyramids. This has failed and no copy has taken place.\n" ); + return; + } + + IDirect3DTexture* pSrcD3DTex = ( IDirect3DTexture * ) pSrcTex->GetTexture(); + IDirect3DTexture* pDstD3DTex = ( IDirect3DTexture * ) pDstTex->GetTexture(); + + HRESULT hr = S_OK; + for ( int i = 0; i < mipmapCount; ++i ) + { + int srcMipmap = srcFine + i; + int dstMipmap = dstFine + i; + + IDirect3DSurface9* pSrcSurf = NULL; + IDirect3DSurface9* pDstSurf = NULL; + + hr = pSrcD3DTex->GetSurfaceLevel( srcMipmap, &pSrcSurf ); + Assert( SUCCEEDED( hr ) && pSrcSurf ); + + hr = pDstD3DTex->GetSurfaceLevel( dstMipmap, &pDstSurf ); + Assert( SUCCEEDED( hr ) && pDstSurf ); + + hr = g_pD3DDevice->StretchRect( pSrcSurf, NULL, pDstSurf, NULL, D3DTEXF_NONE ); + Assert( SUCCEEDED( hr ) ); + + pSrcSurf->Release(); + pDstSurf->Release(); + } +} + + + +void CShaderAPIDx8::CopyRenderTargetToTexture( ShaderAPITextureHandle_t textureHandle ) +{ + LOCK_SHADERAPI(); + CopyRenderTargetToTextureEx( textureHandle, 0 ); +} + + +void CShaderAPIDx8::CopyTextureToRenderTargetEx( int nRenderTargetID, ShaderAPITextureHandle_t textureHandle, Rect_t *pSrcRect, Rect_t *pDstRect ) +{ + LOCK_SHADERAPI(); + VPROF( "CShaderAPIDx8::CopyRenderTargetToTexture" ); + + if ( !TextureIsAllocated( textureHandle ) ) + return; + + // Don't flush here!! If you have to flush here, then there is a driver bug. + // FlushHardware( ); + + AssertValidTextureHandle( textureHandle ); + Texture_t *pTexture = &GetTexture( textureHandle ); + Assert( pTexture ); + IDirect3DTexture *pD3DTexture = (IDirect3DTexture *)pTexture->GetTexture(); + Assert( pD3DTexture ); + +#if !defined( _X360 ) + IDirect3DSurface* pRenderTargetSurface; + HRESULT hr = Dx9Device()->GetRenderTarget( nRenderTargetID, &pRenderTargetSurface ); + if ( FAILED( hr ) ) + { + Assert( 0 ); + return; + } + + IDirect3DSurface *pDstSurf; + hr = pD3DTexture->GetSurfaceLevel( 0, &pDstSurf ); + Assert( !FAILED( hr ) ); + if ( FAILED( hr ) ) + { + pRenderTargetSurface->Release(); + return; + } + + bool tryblit = true; + if ( tryblit ) + { + RECORD_COMMAND( DX8_COPY_FRAMEBUFFER_TO_TEXTURE, 1 ); + RECORD_INT( textureHandle ); + + RECT srcRect, dstRect; + hr = Dx9Device()->StretchRect( pDstSurf, RectToRECT( pSrcRect, srcRect ), + pRenderTargetSurface, RectToRECT( pDstRect, dstRect ), D3DTEXF_LINEAR ); + Assert( !FAILED( hr ) ); + } + + pDstSurf->Release(); + pRenderTargetSurface->Release(); +#else + Assert( 0 ); +#endif +} + + +//----------------------------------------------------------------------------- +// modifies the vertex data when necessary +//----------------------------------------------------------------------------- +void CShaderAPIDx8::ModifyVertexData( ) +{ + // this should be a dead code path + Assert( 0 ); +#if 0 + // We have to modulate the vertex color by the constant color sometimes + if (IsModulatingVertexColor()) + { + m_ModifyBuilder.Reset(); + + float factor[4]; + unsigned char* pColor = (unsigned char*)&m_DynamicState.m_ConstantColor; + factor[0] = pColor[0] / 255.0f; + factor[1] = pColor[1] / 255.0f; + factor[2] = pColor[2] / 255.0f; + factor[3] = pColor[3] / 255.0f; + + for ( int i = 0; i < m_ModifyBuilder.VertexCount(); ++i ) + { + unsigned int color = m_ModifyBuilder.Color(); + unsigned char* pVertexColor = (unsigned char*)&color; + + pVertexColor[0] = (unsigned char)((float)pVertexColor[0] * factor[0]); + pVertexColor[1] = (unsigned char)((float)pVertexColor[1] * factor[1]); + pVertexColor[2] = (unsigned char)((float)pVertexColor[2] * factor[2]); + pVertexColor[3] = (unsigned char)((float)pVertexColor[3] * factor[3]); + m_ModifyBuilder.Color4ubv( pVertexColor ); + + m_ModifyBuilder.AdvanceVertex(); + } + } +#endif +} + +static const char *TextureArgToString( int arg ) +{ + static char buf[128]; + switch( arg & D3DTA_SELECTMASK ) + { + case D3DTA_DIFFUSE: + strcpy( buf, "D3DTA_DIFFUSE" ); + break; + case D3DTA_CURRENT: + strcpy( buf, "D3DTA_CURRENT" ); + break; + case D3DTA_TEXTURE: + strcpy( buf, "D3DTA_TEXTURE" ); + break; + case D3DTA_TFACTOR: + strcpy( buf, "D3DTA_TFACTOR" ); + break; + case D3DTA_SPECULAR: + strcpy( buf, "D3DTA_SPECULAR" ); + break; + case D3DTA_TEMP: + strcpy( buf, "D3DTA_TEMP" ); + break; + default: + strcpy( buf, "" ); + break; + } + + if( arg & D3DTA_COMPLEMENT ) + { + strcat( buf, "|D3DTA_COMPLEMENT" ); + } + if( arg & D3DTA_ALPHAREPLICATE ) + { + strcat( buf, "|D3DTA_ALPHAREPLICATE" ); + } + return buf; +} + +static const char *TextureOpToString( D3DTEXTUREOP op ) +{ + switch( op ) + { + case D3DTOP_DISABLE: + return "D3DTOP_DISABLE"; + case D3DTOP_SELECTARG1: + return "D3DTOP_SELECTARG1"; + case D3DTOP_SELECTARG2: + return "D3DTOP_SELECTARG2"; + case D3DTOP_MODULATE: + return "D3DTOP_MODULATE"; + case D3DTOP_MODULATE2X: + return "D3DTOP_MODULATE2X"; + case D3DTOP_MODULATE4X: + return "D3DTOP_MODULATE4X"; + case D3DTOP_ADD: + return "D3DTOP_ADD"; + case D3DTOP_ADDSIGNED: + return "D3DTOP_ADDSIGNED"; + case D3DTOP_ADDSIGNED2X: + return "D3DTOP_ADDSIGNED2X"; + case D3DTOP_SUBTRACT: + return "D3DTOP_SUBTRACT"; + case D3DTOP_ADDSMOOTH: + return "D3DTOP_ADDSMOOTH"; + case D3DTOP_BLENDDIFFUSEALPHA: + return "D3DTOP_BLENDDIFFUSEALPHA"; + case D3DTOP_BLENDTEXTUREALPHA: + return "D3DTOP_BLENDTEXTUREALPHA"; + case D3DTOP_BLENDFACTORALPHA: + return "D3DTOP_BLENDFACTORALPHA"; + case D3DTOP_BLENDTEXTUREALPHAPM: + return "D3DTOP_BLENDTEXTUREALPHAPM"; + case D3DTOP_BLENDCURRENTALPHA: + return "D3DTOP_BLENDCURRENTALPHA"; + case D3DTOP_PREMODULATE: + return "D3DTOP_PREMODULATE"; + case D3DTOP_MODULATEALPHA_ADDCOLOR: + return "D3DTOP_MODULATEALPHA_ADDCOLOR"; + case D3DTOP_MODULATECOLOR_ADDALPHA: + return "D3DTOP_MODULATECOLOR_ADDALPHA"; + case D3DTOP_MODULATEINVALPHA_ADDCOLOR: + return "D3DTOP_MODULATEINVALPHA_ADDCOLOR"; + case D3DTOP_MODULATEINVCOLOR_ADDALPHA: + return "D3DTOP_MODULATEINVCOLOR_ADDALPHA"; + case D3DTOP_BUMPENVMAP: + return "D3DTOP_BUMPENVMAP"; + case D3DTOP_BUMPENVMAPLUMINANCE: + return "D3DTOP_BUMPENVMAPLUMINANCE"; + case D3DTOP_DOTPRODUCT3: + return "D3DTOP_DOTPRODUCT3"; + case D3DTOP_MULTIPLYADD: + return "D3DTOP_MULTIPLYADD"; + case D3DTOP_LERP: + return "D3DTOP_LERP"; + default: + return ""; + } +} + +static const char *BlendModeToString( int blendMode ) +{ + switch( blendMode ) + { + case D3DBLEND_ZERO: + return "D3DBLEND_ZERO"; + case D3DBLEND_ONE: + return "D3DBLEND_ONE"; + case D3DBLEND_SRCCOLOR: + return "D3DBLEND_SRCCOLOR"; + case D3DBLEND_INVSRCCOLOR: + return "D3DBLEND_INVSRCCOLOR"; + case D3DBLEND_SRCALPHA: + return "D3DBLEND_SRCALPHA"; + case D3DBLEND_INVSRCALPHA: + return "D3DBLEND_INVSRCALPHA"; + case D3DBLEND_DESTALPHA: + return "D3DBLEND_DESTALPHA"; + case D3DBLEND_INVDESTALPHA: + return "D3DBLEND_INVDESTALPHA"; + case D3DBLEND_DESTCOLOR: + return "D3DBLEND_DESTCOLOR"; + case D3DBLEND_INVDESTCOLOR: + return "D3DBLEND_INVDESTCOLOR"; + case D3DBLEND_SRCALPHASAT: + return "D3DBLEND_SRCALPHASAT"; +#if !defined( _X360 ) + case D3DBLEND_BOTHSRCALPHA: + return "D3DBLEND_BOTHSRCALPHA"; + case D3DBLEND_BOTHINVSRCALPHA: + return "D3DBLEND_BOTHINVSRCALPHA"; +#endif + default: + return ""; + } +} + +//----------------------------------------------------------------------------- +// Spew Board State +//----------------------------------------------------------------------------- +void CShaderAPIDx8::SpewBoardState() +{ + // FIXME: This has regressed + return; +#ifdef DEBUG_BOARD_STATE +/* + { + static ID3DXFont* pFont = 0; + if (!pFont) + { + HFONT hFont = CreateFont( 0, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, + ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, + DEFAULT_PITCH | FF_MODERN, 0 ); + Assert( hFont != 0 ); + + HRESULT hr = D3DXCreateFont( Dx9Device(), hFont, &pFont ); + } + + static char buf[1024]; + static RECT r = { 0, 0, 640, 480 }; + + if (m_DynamicState.m_VertexBlend == 0) + return; + +#if 1 + D3DXMATRIX* m = &GetTransform(MATERIAL_MODEL); + D3DXMATRIX* m2 = &GetTransform(MATERIAL_MODEL + 1); + sprintf(buf,"FVF %x\n" + "[%6.3f %6.3f %6.3f %6.3f]\n[%6.3f %6.3f %6.3f %6.3f]\n" + "[%6.3f %6.3f %6.3f %6.3f]\n[%6.3f %6.3f %6.3f %6.3f]\n\n", + "[%6.3f %6.3f %6.3f %6.3f]\n[%6.3f %6.3f %6.3f %6.3f]\n", + "[%6.3f %6.3f %6.3f %6.3f]\n[%6.3f %6.3f %6.3f %6.3f]\n", + ShaderManager()->GetCurrentVertexShader(), + m->m[0][0], m->m[0][1], m->m[0][2], m->m[0][3], + m->m[1][0], m->m[1][1], m->m[1][2], m->m[1][3], + m->m[2][0], m->m[2][1], m->m[2][2], m->m[2][3], + m->m[3][0], m->m[3][1], m->m[3][2], m->m[3][3], + m2->m[0][0], m2->m[0][1], m2->m[0][2], m2->m[0][3], + m2->m[1][0], m2->m[1][1], m2->m[1][2], m2->m[1][3], + m2->m[2][0], m2->m[2][1], m2->m[2][2], m2->m[2][3], + m2->m[3][0], m2->m[3][1], m2->m[3][2], m2->m[3][3] + ); +#else + Vector4D *pVec2 = &m_DynamicState.m_pVectorVertexShaderConstant[VERTEX_SHADER_MODELVIEWPROJ]; + Vector4D *pVec3 = &m_DynamicState.m_pVectorVertexShaderConstant[VERTEX_SHADER_VIEWPROJ]; + Vector4D *pVec4 = &m_DynamicState.m_pVectorVertexShaderConstant[VERTEX_SHADER_MODEL]; + + sprintf(buf,"\n" + "[%6.3f %6.3f %6.3f %6.3f]\n[%6.3f %6.3f %6.3f %6.3f]\n" + "[%6.3f %6.3f %6.3f %6.3f]\n[%6.3f %6.3f %6.3f %6.3f]\n\n" + + "[%6.3f %6.3f %6.3f %6.3f]\n[%6.3f %6.3f %6.3f %6.3f]\n" + "[%6.3f %6.3f %6.3f %6.3f]\n[%6.3f %6.3f %6.3f %6.3f]\n\n" + + "[%6.3f %6.3f %6.3f %6.3f]\n[%6.3f %6.3f %6.3f %6.3f]\n" + "[%6.3f %6.3f %6.3f %6.3f]\n[%6.3f %6.3f %6.3f %6.3f]\n\n" + + "[%6.3f %6.3f %6.3f %6.3f]\n[%6.3f %6.3f %6.3f %6.3f]\n" + "[%6.3f %6.3f %6.3f %6.3f]\n[%6.3f %6.3f %6.3f %6.3f]\n", + + pVec1[0][0], pVec1[0][1], pVec1[0][2], pVec1[0][3], + pVec1[1][0], pVec1[1][1], pVec1[1][2], pVec1[1][3], + pVec1[2][0], pVec1[2][1], pVec1[2][2], pVec1[2][3], + pVec1[3][0], pVec1[3][1], pVec1[3][2], pVec1[3][3], + + pVec2[0][0], pVec2[0][1], pVec2[0][2], pVec2[0][3], + pVec2[1][0], pVec2[1][1], pVec2[1][2], pVec2[1][3], + pVec2[2][0], pVec2[2][1], pVec2[2][2], pVec2[2][3], + pVec2[3][0], pVec2[3][1], pVec2[3][2], pVec2[3][3], + + pVec3[0][0], pVec3[0][1], pVec3[0][2], pVec3[0][3], + pVec3[1][0], pVec3[1][1], pVec3[1][2], pVec3[1][3], + pVec3[2][0], pVec3[2][1], pVec3[2][2], pVec3[2][3], + pVec3[3][0], pVec3[3][1], pVec3[3][2], pVec3[3][3], + + pVec4[0][0], pVec4[0][1], pVec4[0][2], pVec4[0][3], + pVec4[1][0], pVec4[1][1], pVec4[1][2], pVec4[1][3], + pVec4[2][0], pVec4[2][1], pVec4[2][2], pVec4[2][3], + 0, 0, 0, 1 + ); +#endif + pFont->Begin(); + pFont->DrawText( buf, -1, &r, DT_LEFT | DT_TOP, + D3DCOLOR_RGBA( 255, 255, 255, 255 ) ); + pFont->End(); + + return; + } + +#if 0 + Vector4D *pVec2 = &m_DynamicState.m_pVectorVertexShaderConstant[VERTEX_SHADER_MODELVIEWPROJ]; + Vector4D *pVec3 = &m_DynamicState.m_pVectorVertexShaderConstant[VERTEX_SHADER_VIEWPROJ]; + Vector4D *pVec4 = &m_DynamicState.m_pVectorVertexShaderConstant[VERTEX_SHADER_MODEL]; + + static char buf2[1024]; + sprintf(buf2,"\n" + "[%6.3f %6.3f %6.3f %6.3f]\n[%6.3f %6.3f %6.3f %6.3f]\n" + "[%6.3f %6.3f %6.3f %6.3f]\n[%6.3f %6.3f %6.3f %6.3f]\n\n" + + "[%6.3f %6.3f %6.3f %6.3f]\n[%6.3f %6.3f %6.3f %6.3f]\n" + "[%6.3f %6.3f %6.3f %6.3f]\n[%6.3f %6.3f %6.3f %6.3f]\n\n" + + "[%6.3f %6.3f %6.3f %6.3f]\n[%6.3f %6.3f %6.3f %6.3f]\n" + "[%6.3f %6.3f %6.3f %6.3f]\n[%6.3f %6.3f %6.3f %6.3f]\n\n" + + "[%6.3f %6.3f %6.3f %6.3f]\n[%6.3f %6.3f %6.3f %6.3f]\n" + "[%6.3f %6.3f %6.3f %6.3f]\n[%6.3f %6.3f %6.3f %6.3f]\n", + + pVec1[0][0], pVec1[0][1], pVec1[0][2], pVec1[0][3], + pVec1[1][0], pVec1[1][1], pVec1[1][2], pVec1[1][3], + pVec1[2][0], pVec1[2][1], pVec1[2][2], pVec1[2][3], + pVec1[3][0], pVec1[3][1], pVec1[3][2], pVec1[3][3], + + pVec2[0][0], pVec2[0][1], pVec2[0][2], pVec2[0][3], + pVec2[1][0], pVec2[1][1], pVec2[1][2], pVec2[1][3], + pVec2[2][0], pVec2[2][1], pVec2[2][2], pVec2[2][3], + pVec2[3][0], pVec2[3][1], pVec2[3][2], pVec2[3][3], + + pVec3[0][0], pVec3[0][1], pVec3[0][2], pVec3[0][3], + pVec3[1][0], pVec3[1][1], pVec3[1][2], pVec3[1][3], + pVec3[2][0], pVec3[2][1], pVec3[2][2], pVec3[2][3], + pVec3[3][0], pVec3[3][1], pVec3[3][2], pVec3[3][3], + + pVec4[0][0], pVec4[0][1], pVec4[0][2], pVec4[0][3], + pVec4[1][0], pVec4[1][1], pVec4[1][2], pVec4[1][3], + pVec4[2][0], pVec4[2][1], pVec4[2][2], pVec4[2][3], + 0, 0, 0, 1.0f + ); + Plat_DebugString(buf2); + return; +#endif +*/ + + char buf[256]; + sprintf(buf, "\nSnapshot id %d : \n", m_TransitionTable.CurrentSnapshot() ); + Plat_DebugString(buf); + + ShadowState_t &boardState = m_TransitionTable.BoardState(); + ShadowShaderState_t &boardShaderState = m_TransitionTable.BoardShaderState(); + + sprintf(buf,"Depth States: ZFunc %d, ZWrite %d, ZEnable %d, ZBias %d\n", + boardState.m_ZFunc, boardState.m_ZWriteEnable, + boardState.m_ZEnable, boardState.m_ZBias ); + Plat_DebugString(buf); + sprintf(buf,"Cull Enable %d Cull Mode %d Color Write %d Fill %d Const Color Mod %d sRGBWriteEnable %d\n", + boardState.m_CullEnable, m_DynamicState.m_CullMode, boardState.m_ColorWriteEnable, + boardState.m_FillMode, boardShaderState.m_ModulateConstantColor, boardState.m_SRGBWriteEnable ); + Plat_DebugString(buf); + sprintf(buf,"Blend States: Blend Enable %d Test Enable %d Func %d SrcBlend %d (%s) DstBlend %d (%s)\n", + boardState.m_AlphaBlendEnable, boardState.m_AlphaTestEnable, + boardState.m_AlphaFunc, boardState.m_SrcBlend, BlendModeToString( boardState.m_SrcBlend ), + boardState.m_DestBlend, BlendModeToString( boardState.m_DestBlend ) ); + Plat_DebugString(buf); + int len = sprintf(buf,"Alpha Ref %d, Lighting: %d, Ambient Color %x, LightsEnabled ", + boardState.m_AlphaRef, boardState.m_Lighting, m_DynamicState.m_Ambient); + + int i; + for ( i = 0; i < g_pHardwareConfig->Caps().m_MaxNumLights; ++i) + { + len += sprintf(buf+len,"%d ", m_DynamicState.m_LightEnable[i] ); + } + sprintf(buf+len,"\n"); + Plat_DebugString(buf); + sprintf(buf,"Fixed Function: %d, VertexBlend %d\n", + boardState.m_UsingFixedFunction, m_DynamicState.m_VertexBlend ); + Plat_DebugString(buf); + + sprintf(buf,"Pass Vertex Usage: %llx Pixel Shader %p Vertex Shader %p\n", + boardShaderState.m_VertexUsage, ShaderManager()->GetCurrentPixelShader(), + ShaderManager()->GetCurrentVertexShader() ); + Plat_DebugString(buf); + + // REGRESSED!!!! + /* + D3DXMATRIX* m = &GetTransform(MATERIAL_MODEL); + sprintf(buf,"WorldMat [%4.3f %4.3f %4.3f %4.3f %4.3f %4.3f %4.3f %4.3f %4.3f %4.3f %4.3f %4.3f %4.3f %4.3f %4.3f %4.3f]\n", + m->m[0][0], m->m[0][1], m->m[0][2], m->m[0][3], + m->m[1][0], m->m[1][1], m->m[1][2], m->m[1][3], + m->m[2][0], m->m[2][1], m->m[2][2], m->m[2][3], + m->m[3][0], m->m[3][1], m->m[3][2], m->m[3][3] ); + Plat_DebugString(buf); + + m = &GetTransform(MATERIAL_MODEL + 1); + sprintf(buf,"WorldMat2 [%4.3f %4.3f %4.3f %4.3f %4.3f %4.3f %4.3f %4.3f %4.3f %4.3f %4.3f %4.3f %4.3f %4.3f %4.3f %4.3f]\n", + m->m[0][0], m->m[0][1], m->m[0][2], m->m[0][3], + m->m[1][0], m->m[1][1], m->m[1][2], m->m[1][3], + m->m[2][0], m->m[2][1], m->m[2][2], m->m[2][3], + m->m[3][0], m->m[3][1], m->m[3][2], m->m[3][3] ); + Plat_DebugString(buf); + + m = &GetTransform(MATERIAL_VIEW); + sprintf(buf,"ViewMat [%4.3f %4.3f %4.3f %4.3f %4.3f %4.3f %4.3f %4.3f %4.3f %4.3f %4.3f %4.3f]\n", + m->m[0][0], m->m[0][1], m->m[0][2], + m->m[1][0], m->m[1][1], m->m[1][2], + m->m[2][0], m->m[2][1], m->m[2][2], + m->m[3][0], m->m[3][1], m->m[3][2] ); + Plat_DebugString(buf); + + m = &GetTransform(MATERIAL_PROJECTION); + sprintf(buf,"ProjMat [%4.3f %4.3f %4.3f %4.3f %4.3f %4.3f %4.3f %4.3f %4.3f %4.3f %4.3f %4.3f]\n", + m->m[0][0], m->m[0][1], m->m[0][2], + m->m[1][0], m->m[1][1], m->m[1][2], + m->m[2][0], m->m[2][1], m->m[2][2], + m->m[3][0], m->m[3][1], m->m[3][2] ); + Plat_DebugString(buf); + + for (i = 0; i < GetTextureStageCount(); ++i) + { + m = &GetTransform(MATERIAL_TEXTURE0 + i); + sprintf(buf,"TexMat%d [%4.3f %4.3f %4.3f %4.3f %4.3f %4.3f %4.3f %4.3f %4.3f %4.3f %4.3f %4.3f]\n", + i, m->m[0][0], m->m[0][1], m->m[0][2], + m->m[1][0], m->m[1][1], m->m[1][2], + m->m[2][0], m->m[2][1], m->m[2][2], + m->m[3][0], m->m[3][1], m->m[3][2] ); + Plat_DebugString(buf); + } + */ + + sprintf(buf,"Viewport (%d %d) [%d %d] %4.3f %4.3f\n", + m_DynamicState.m_Viewport.X, m_DynamicState.m_Viewport.Y, + m_DynamicState.m_Viewport.Width, m_DynamicState.m_Viewport.Height, + m_DynamicState.m_Viewport.MinZ, m_DynamicState.m_Viewport.MaxZ); + Plat_DebugString(buf); + + for (i = 0; i < MAX_TEXTURE_STAGES; ++i) + { + sprintf(buf,"Stage %d :\n", i); + Plat_DebugString(buf); + sprintf(buf," Color Op: %d (%s) Color Arg1: %d (%s)", + boardState.m_TextureStage[i].m_ColorOp, + TextureOpToString( boardState.m_TextureStage[i].m_ColorOp ), + boardState.m_TextureStage[i].m_ColorArg1, + TextureArgToString( boardState.m_TextureStage[i].m_ColorArg1 ) ); + Plat_DebugString(buf); + sprintf( buf, " Color Arg2: %d (%s)\n", + boardState.m_TextureStage[i].m_ColorArg2, + TextureArgToString( boardState.m_TextureStage[i].m_ColorArg2 ) ); + Plat_DebugString(buf); + sprintf(buf," Alpha Op: %d (%s) Alpha Arg1: %d (%s)", + boardState.m_TextureStage[i].m_AlphaOp, + TextureOpToString( boardState.m_TextureStage[i].m_AlphaOp ), + boardState.m_TextureStage[i].m_AlphaArg1, + TextureArgToString( boardState.m_TextureStage[i].m_AlphaArg1 ) ); + Plat_DebugString(buf); + sprintf(buf," Alpha Arg2: %d (%s)\n", + boardState.m_TextureStage[i].m_AlphaArg2, + TextureArgToString( boardState.m_TextureStage[i].m_AlphaArg2 ) ); + Plat_DebugString(buf); + } + + for ( int i = 0; i < MAX_SAMPLERS; ++i ) + { + sprintf(buf," Texture Enabled: %d Bound Texture: %d UWrap: %d VWrap: %d\n", + SamplerState(i).m_TextureEnable, GetBoundTextureBindId( (Sampler_t)i ), + SamplerState(i).m_UTexWrap, SamplerState(i).m_VTexWrap ); + Plat_DebugString(buf); + sprintf(buf," Mag Filter: %d Min Filter: %d Mip Filter: %d\n", + SamplerState(i).m_MagFilter, SamplerState(i).m_MinFilter, + SamplerState(i).m_MipFilter ); + sprintf(buf," MaxMipLevel: %d\n", SamplerState(i).m_FinestMipmapLevel ); + Plat_DebugString(buf); + } +#else + Plat_DebugString("::SpewBoardState() Not Implemented Yet"); +#endif +} + +//----------------------------------------------------------------------------- +// Begin a render pass +//----------------------------------------------------------------------------- +void CShaderAPIDx8::BeginPass( StateSnapshot_t snapshot ) +{ + LOCK_SHADERAPI(); + VPROF("CShaderAPIDx8::BeginPass"); + if (IsDeactivated()) + return; + + m_nCurrentSnapshot = snapshot; +// Assert( m_pRenderMesh ); + // FIXME: This only does anything with temp meshes, so don't bother yet for the new code. + if( m_pRenderMesh ) + { + m_pRenderMesh->BeginPass( ); + } +} + + +//----------------------------------------------------------------------------- +// Render da polygon! +//----------------------------------------------------------------------------- +void CShaderAPIDx8::RenderPass( int nPass, int nPassCount ) +{ + if ( IsDeactivated() ) + return; + + Assert( m_nCurrentSnapshot != -1 ); +// Assert( m_pRenderMesh ); MESHFIXME + + m_TransitionTable.UseSnapshot( m_nCurrentSnapshot ); + CommitPerPassStateChanges( m_nCurrentSnapshot ); + + // Make sure that we bound a texture for every stage that is enabled + // NOTE: not enabled/finished yet... see comment in CShaderAPIDx8::ApplyTextureEnable +// int nSampler; +// for ( nSampler = 0; nSampler < g_pHardwareConfig->GetSamplerCount(); nSampler++ ) +// { +// if ( SamplerState( nSampler ).m_TextureEnable ) +// { +// } +// } + +#ifdef DEBUG_BOARD_STATE + // Spew out render state... + if ( m_pMaterial->PerformDebugTrace() ) + { + SpewBoardState(); + } +#endif + +#ifdef TEST_CACHE_LOCKS + g_pDataCache->Flush(); +#endif + +// Assert( m_pRenderMesh ); MESHFIXME + if ( m_pRenderMesh ) + { + m_pRenderMesh->RenderPass(); + } + else + { + MeshMgr()->RenderPassWithVertexAndIndexBuffers(); + } + m_nCurrentSnapshot = -1; +} + + +//----------------------------------------------------------------------------- +// Matrix mode +//----------------------------------------------------------------------------- +void CShaderAPIDx8::MatrixMode( MaterialMatrixMode_t matrixMode ) +{ + // NOTE!!!!!! + // The only time that m_MatrixMode is used is for texture matrices. Do not use + // it for anything else unless you change this code! + if ( matrixMode >= MATERIAL_TEXTURE0 && matrixMode <= MATERIAL_TEXTURE7 ) + { + m_MatrixMode = ( D3DTRANSFORMSTATETYPE )( matrixMode - MATERIAL_TEXTURE0 + D3DTS_TEXTURE0 ); + } + else + { + m_MatrixMode = (D3DTRANSFORMSTATETYPE)-1; + } + + m_CurrStack = GetMatrixStack( matrixMode ); +} + +//----------------------------------------------------------------------------- +// the current camera position in world space. +//----------------------------------------------------------------------------- +void CShaderAPIDx8::GetWorldSpaceCameraPosition( float* pPos ) const +{ + memcpy( pPos, m_WorldSpaceCameraPositon.Base(), sizeof( float[3] ) ); +} + +void CShaderAPIDx8::CacheWorldSpaceCameraPosition() +{ + D3DXMATRIX& view = GetTransform(MATERIAL_VIEW); + m_WorldSpaceCameraPositon[0] = + -( view( 3, 0 ) * view( 0, 0 ) + + view( 3, 1 ) * view( 0, 1 ) + + view( 3, 2 ) * view( 0, 2 ) ); + m_WorldSpaceCameraPositon[1] = + -( view( 3, 0 ) * view( 1, 0 ) + + view( 3, 1 ) * view( 1, 1 ) + + view( 3, 2 ) * view( 1, 2 ) ); + m_WorldSpaceCameraPositon[2] = + -( view( 3, 0 ) * view( 2, 0 ) + + view( 3, 1 ) * view( 2, 1 ) + + view( 3, 2 ) * view( 2, 2 ) ); + m_WorldSpaceCameraPositon[3] = 1.0f; + + // Protect against zero, as some pixel shaders will divide by this in CalcWaterFogAlpha() in common_ps_fxc.h + if ( fabs( m_WorldSpaceCameraPositon[2] ) <= 0.00001f ) + { + m_WorldSpaceCameraPositon[2] = 0.01f; + } +} + + +//----------------------------------------------------------------------------- +// Computes a matrix which includes the poly offset given an initial projection matrix +//----------------------------------------------------------------------------- +void CShaderAPIDx8::ComputePolyOffsetMatrix( const D3DXMATRIX& matProjection, D3DXMATRIX &matProjectionOffset ) +{ + // We never need to do this on hardware that can handle zbias + if ( g_pHardwareConfig->Caps().m_ZBiasAndSlopeScaledDepthBiasSupported ) + return; + + float offsetVal = + -1.0f * (m_DesiredState.m_Viewport.MaxZ - m_DesiredState.m_Viewport.MinZ) / + 16384.0f; + + D3DXMATRIX offset; + D3DXMatrixTranslation( &offset, 0.0f, 0.0f, offsetVal ); + D3DXMatrixMultiply( &matProjectionOffset, &matProjection, &offset ); +} + + +//----------------------------------------------------------------------------- +// Caches off the poly-offset projection matrix +//----------------------------------------------------------------------------- +void CShaderAPIDx8::CachePolyOffsetProjectionMatrix() +{ + ComputePolyOffsetMatrix( GetTransform(MATERIAL_PROJECTION), m_CachedPolyOffsetProjectionMatrix ); +} + + +//----------------------------------------------------------------------------- +// Performs a flush on the matrix state if necessary +//----------------------------------------------------------------------------- +bool CShaderAPIDx8::MatrixIsChanging( TransformType_t type ) +{ + if ( IsDeactivated() ) + { + return false; + } + + // early out if the transform is already one of our standard types + if ((type != TRANSFORM_IS_GENERAL) && (type == m_DynamicState.m_TransformType[m_CurrStack])) + return false; + + // Only flush state if we're changing something other than a texture transform + int textureMatrix = m_CurrStack - MATERIAL_TEXTURE0; + if (( textureMatrix < 0 ) || (textureMatrix >= NUM_TEXTURE_TRANSFORMS)) + FlushBufferedPrimitivesInternal(); + + return true; +} + +void CShaderAPIDx8::SetTextureTransformDimension( TextureStage_t textureMatrix, int dimension, bool projected ) +{ + D3DTEXTURETRANSFORMFLAGS textureTransformFlags = ( D3DTEXTURETRANSFORMFLAGS )dimension; + if( projected ) + { + Assert( sizeof( int ) == sizeof( D3DTEXTURETRANSFORMFLAGS ) ); + ( *( int * )&textureTransformFlags ) |= D3DTTFF_PROJECTED; + } + + if (TextureStage(textureMatrix).m_TextureTransformFlags != textureTransformFlags ) + { + SetTextureStageState( textureMatrix, D3DTSS_TEXTURETRANSFORMFLAGS, textureTransformFlags ); + TextureStage(textureMatrix).m_TextureTransformFlags = textureTransformFlags; + } +} + +void CShaderAPIDx8::DisableTextureTransform( TextureStage_t textureMatrix ) +{ + if (TextureStage(textureMatrix).m_TextureTransformFlags != D3DTTFF_DISABLE ) + { + SetTextureStageState( textureMatrix, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE ); + TextureStage(textureMatrix).m_TextureTransformFlags = D3DTTFF_DISABLE; + } +} + +void CShaderAPIDx8::SetBumpEnvMatrix( TextureStage_t textureStage, float m00, float m01, float m10, float m11 ) +{ + TextureStageState_t &textureStageState = TextureStage( textureStage ); + + if( textureStageState.m_BumpEnvMat00 != m00 || + textureStageState.m_BumpEnvMat01 != m01 || + textureStageState.m_BumpEnvMat10 != m10 || + textureStageState.m_BumpEnvMat11 != m11 ) + { + SetTextureStageState( textureStage, D3DTSS_BUMPENVMAT00, *( ( LPDWORD ) (&m00) ) ); + SetTextureStageState( textureStage, D3DTSS_BUMPENVMAT01, *( ( LPDWORD ) (&m01) ) ); + SetTextureStageState( textureStage, D3DTSS_BUMPENVMAT10, *( ( LPDWORD ) (&m10) ) ); + SetTextureStageState( textureStage, D3DTSS_BUMPENVMAT11, *( ( LPDWORD ) (&m11) ) ); + textureStageState.m_BumpEnvMat00 = m00; + textureStageState.m_BumpEnvMat01 = m01; + textureStageState.m_BumpEnvMat10 = m10; + textureStageState.m_BumpEnvMat11 = m11; + } +} + +//----------------------------------------------------------------------------- +// Sets the actual matrix state +//----------------------------------------------------------------------------- +void CShaderAPIDx8::UpdateMatrixTransform( TransformType_t type ) +{ + int textureMatrix = m_CurrStack - MATERIAL_TEXTURE0; + if (( textureMatrix >= 0 ) && (textureMatrix < NUM_TEXTURE_TRANSFORMS)) + { + // NOTE: Flush shouldn't happen here because we + // expect that texture transforms will be set within the shader + + // FIXME: We only want to use D3DTTFF_COUNT3 for cubemaps + // D3DTFF_COUNT2 is used for non-cubemaps. Of course, if there's + // no performance penalty for COUNT3, we should just use that. + D3DTEXTURETRANSFORMFLAGS transformFlags; + transformFlags = (type == TRANSFORM_IS_IDENTITY) ? D3DTTFF_DISABLE : D3DTTFF_COUNT3; + + if (TextureStage(textureMatrix).m_TextureTransformFlags != transformFlags ) + { + SetTextureStageState( textureMatrix, D3DTSS_TEXTURETRANSFORMFLAGS, transformFlags ); + TextureStage(textureMatrix).m_TextureTransformFlags = transformFlags; + } + } + + m_DynamicState.m_TransformType[m_CurrStack] = type; + m_DynamicState.m_TransformChanged[m_CurrStack] = STATE_CHANGED; + +#ifdef _DEBUG + // Store off the board state + D3DXMATRIX *pSrc = &GetTransform(m_CurrStack); + D3DXMATRIX *pDst = &m_DynamicState.m_Transform[m_CurrStack]; +// Assert( *pSrc != *pDst ); + memcpy( pDst, pSrc, sizeof(D3DXMATRIX) ); +#endif + + if ( m_CurrStack == MATERIAL_VIEW ) + { + CacheWorldSpaceCameraPosition(); + } + + if ( !IsX360() && m_CurrStack == MATERIAL_PROJECTION ) + { + CachePolyOffsetProjectionMatrix(); + } + + // Any time the view or projection matrix changes, the user clip planes need recomputing.... + // Assuming we're not overriding the user clip transform + if ( ( m_CurrStack == MATERIAL_PROJECTION ) || + ( ( m_CurrStack == MATERIAL_VIEW ) && ( !m_DynamicState.m_bUserClipTransformOverride ) ) ) + { + MarkAllUserClipPlanesDirty(); + } + + // Set the state if it's a texture transform + if ( (m_CurrStack >= MATERIAL_TEXTURE0) && (m_CurrStack <= MATERIAL_TEXTURE7) ) + { + SetTransform( m_MatrixMode, &GetTransform(m_CurrStack) ); + } +} + + +//-------------------------------------------------------------------------------- +// deformations +//-------------------------------------------------------------------------------- +void CShaderAPIDx8::PushDeformation( DeformationBase_t const *pDef ) +{ + Assert( m_pDeformationStackPtr > m_DeformationStack ); + --m_pDeformationStackPtr; + m_pDeformationStackPtr->m_nDeformationType = pDef->m_eType; + + switch( pDef->m_eType ) + { + case DEFORMATION_CLAMP_TO_BOX_IN_WORLDSPACE: + { + BoxDeformation_t const *pBox = reinterpret_cast< const BoxDeformation_t *>( pDef ); + m_pDeformationStackPtr->m_nNumParameters = 16; + memcpy( m_pDeformationStackPtr->m_flDeformationParameters, &( pBox->m_SourceMins.x ), 16 * sizeof( float ) ); + break; + } + break; + + default: + Assert( 0 ); + } +} + + +void CShaderAPIDx8::PopDeformation( ) +{ + Assert( m_pDeformationStackPtr != m_DeformationStack + DEFORMATION_STACK_DEPTH ); + ++m_pDeformationStackPtr; +} + +int CShaderAPIDx8::GetNumActiveDeformations( void ) const +{ + return ( m_DeformationStack + DEFORMATION_STACK_DEPTH ) - m_pDeformationStackPtr; +} + + +// for shaders to set vertex shader constants. returns a packed state which can be used to set the dynamic combo +int CShaderAPIDx8::GetPackedDeformationInformation( int nMaskOfUnderstoodDeformations, + float *pConstantValuesOut, + int nBufferSize, + int nMaximumDeformations, + int *pDefCombosOut ) const +{ + int nCombosFound = 0; + memset( pDefCombosOut, 0, sizeof( pDefCombosOut[0] ) * nMaximumDeformations ); + size_t nRemainingBufferSize = nBufferSize; + + for( const Deformation_t *i = m_DeformationStack + DEFORMATION_STACK_DEPTH -1; i >= m_pDeformationStackPtr; i-- ) + { + int nFloatsOut = 4 * ( ( i->m_nNumParameters + 3 )>> 2 ); + if ( + ( ( 1 << i->m_nDeformationType ) & nMaskOfUnderstoodDeformations ) && + ( nRemainingBufferSize >= ( nFloatsOut * sizeof( float ) ) ) ) + { + memcpy( pConstantValuesOut, i->m_flDeformationParameters, nFloatsOut * sizeof( float ) ); + pConstantValuesOut += nFloatsOut; + nRemainingBufferSize -= nFloatsOut * sizeof( float ); + ( *pDefCombosOut++ ) = i->m_nDeformationType; + nCombosFound++; + } + } + return nCombosFound; +} + + + + +//----------------------------------------------------------------------------- +// Matrix stack operations +//----------------------------------------------------------------------------- + +void CShaderAPIDx8::PushMatrix() +{ + // NOTE: No matrix transform update needed here. + m_pMatrixStack[m_CurrStack]->Push(); +} + +void CShaderAPIDx8::PopMatrix() +{ + if (MatrixIsChanging()) + { + m_pMatrixStack[m_CurrStack]->Pop(); + UpdateMatrixTransform(); + } +} + +void CShaderAPIDx8::LoadIdentity( ) +{ + if (MatrixIsChanging(TRANSFORM_IS_IDENTITY)) + { + m_pMatrixStack[m_CurrStack]->LoadIdentity( ); + UpdateMatrixTransform( TRANSFORM_IS_IDENTITY ); + } +} + +void CShaderAPIDx8::LoadCameraToWorld( ) +{ + if (MatrixIsChanging(TRANSFORM_IS_CAMERA_TO_WORLD)) + { + // could just use the transpose instead, if we know there's no scale + float det; + D3DXMATRIX inv; + D3DXMatrixInverse( &inv, &det, &GetTransform(MATERIAL_VIEW) ); + + // Kill translation + inv.m[3][0] = inv.m[3][1] = inv.m[3][2] = 0.0f; + + m_pMatrixStack[m_CurrStack]->LoadMatrix( &inv ); + UpdateMatrixTransform( TRANSFORM_IS_CAMERA_TO_WORLD ); + } +} + +void CShaderAPIDx8::LoadMatrix( float *m ) +{ + // Check for identity... + if ( (fabs(m[0] - 1.0f) < 1e-3) && (fabs(m[5] - 1.0f) < 1e-3) && (fabs(m[10] - 1.0f) < 1e-3) && (fabs(m[15] - 1.0f) < 1e-3) && + (fabs(m[1]) < 1e-3) && (fabs(m[2]) < 1e-3) && (fabs(m[3]) < 1e-3) && + (fabs(m[4]) < 1e-3) && (fabs(m[6]) < 1e-3) && (fabs(m[7]) < 1e-3) && + (fabs(m[8]) < 1e-3) && (fabs(m[9]) < 1e-3) && (fabs(m[11]) < 1e-3) && + (fabs(m[12]) < 1e-3) && (fabs(m[13]) < 1e-3) && (fabs(m[14]) < 1e-3) ) + { + LoadIdentity(); + return; + } + + if (MatrixIsChanging()) + { + m_pMatrixStack[m_CurrStack]->LoadMatrix( (D3DXMATRIX*)m ); + UpdateMatrixTransform(); + } +} + +void CShaderAPIDx8::LoadBoneMatrix( int boneIndex, const float *m ) +{ + if ( IsDeactivated() ) + return; + + memcpy( m_boneMatrix[boneIndex].Base(), m, sizeof(float)*12 ); + if ( boneIndex > m_maxBoneLoaded ) + { + m_maxBoneLoaded = boneIndex; + } + if ( boneIndex == 0 ) + { + MatrixMode( MATERIAL_MODEL ); + VMatrix transposeMatrix; + transposeMatrix.Init( *(matrix3x4_t *)m ); + MatrixTranspose( transposeMatrix, transposeMatrix ); + LoadMatrix( (float*)transposeMatrix.m ); + } +} + +//----------------------------------------------------------------------------- +// Commits morph target factors +//----------------------------------------------------------------------------- +static void CommitFlexWeights( IDirect3DDevice9 *pDevice, const DynamicState_t &desiredState, + DynamicState_t ¤tState, bool bForce ) +{ + if ( IsX360() ) + { + // not supporting for 360 + return; + } + + CommitVertexShaderConstantRange( pDevice, desiredState, currentState, bForce, + VERTEX_SHADER_FLEX_WEIGHTS, VERTEX_SHADER_MAX_FLEX_WEIGHT_COUNT ); +} + +void CShaderAPIDx8::SetFlexWeights( int nFirstWeight, int nCount, const MorphWeight_t* pWeights ) +{ + if ( IsX360() ) + { + // not supported for 360 + return; + } + + LOCK_SHADERAPI(); + if ( g_pHardwareConfig->Caps().m_NumVertexShaderConstants < VERTEX_SHADER_FLEX_WEIGHTS + VERTEX_SHADER_MAX_FLEX_WEIGHT_COUNT ) + return; + + if ( nFirstWeight + nCount > VERTEX_SHADER_MAX_FLEX_WEIGHT_COUNT ) + { + Warning( "Attempted to set too many flex weights! Max is %d\n", VERTEX_SHADER_MAX_FLEX_WEIGHT_COUNT ); + nCount = VERTEX_SHADER_MAX_FLEX_WEIGHT_COUNT - nFirstWeight; + } + + if ( nCount <= 0 ) + return; + + float *pDest = m_DesiredState.m_pVectorVertexShaderConstant[ VERTEX_SHADER_FLEX_WEIGHTS + nFirstWeight ].Base(); + memcpy( pDest, pWeights, nCount * sizeof(MorphWeight_t) ); + + ADD_COMMIT_FUNC( COMMIT_PER_DRAW, COMMIT_VERTEX_SHADER, CommitFlexWeights ); +} + +void CShaderAPIDx8::MultMatrix( float *m ) +{ + if (MatrixIsChanging()) + { + m_pMatrixStack[m_CurrStack]->MultMatrix( (D3DXMATRIX*)m ); + UpdateMatrixTransform(); + } +} + +void CShaderAPIDx8::MultMatrixLocal( float *m ) +{ + if (MatrixIsChanging()) + { + m_pMatrixStack[m_CurrStack]->MultMatrixLocal( (D3DXMATRIX*)m ); + UpdateMatrixTransform(); + } +} + +void CShaderAPIDx8::Rotate( float angle, float x, float y, float z ) +{ + if (MatrixIsChanging()) + { + D3DXVECTOR3 axis( x, y, z ); + m_pMatrixStack[m_CurrStack]->RotateAxisLocal( &axis, M_PI * angle / 180.0f ); + UpdateMatrixTransform(); + } +} + +void CShaderAPIDx8::Translate( float x, float y, float z ) +{ + if (MatrixIsChanging()) + { + m_pMatrixStack[m_CurrStack]->TranslateLocal( x, y, z ); + UpdateMatrixTransform(); + } +} + +void CShaderAPIDx8::Scale( float x, float y, float z ) +{ + if (MatrixIsChanging()) + { + m_pMatrixStack[m_CurrStack]->ScaleLocal( x, y, z ); + UpdateMatrixTransform(); + } +} + +void CShaderAPIDx8::ScaleXY( float x, float y ) +{ + if (MatrixIsChanging()) + { + m_pMatrixStack[m_CurrStack]->ScaleLocal( x, y, 1.0f ); + UpdateMatrixTransform(); + } +} + +void CShaderAPIDx8::Ortho( double left, double top, double right, double bottom, double zNear, double zFar ) +{ + if (MatrixIsChanging()) + { + D3DXMATRIX matrix; + + // FIXME: This is being used incorrectly! Should read: + // D3DXMatrixOrthoOffCenterRH( &matrix, left, right, bottom, top, zNear, zFar ); + // Which is certainly why we need these extra -1 scales in y. Bleah + + // NOTE: The camera can be imagined as the following diagram: + // /z + // / + // /____ x Z is going into the screen + // | + // | + // |y + // + // (0,0,z) represents the upper-left corner of the screen. + // Our projection transform needs to transform from this space to a LH coordinate + // system that looks thusly: + // + // y| /z + // | / + // |/____ x Z is going into the screen + // + // Where x,y lies between -1 and 1, and z lies from 0 to 1 + // This is because the viewport transformation from projection space to pixels + // introduces a -1 scale in the y coordinates +// D3DXMatrixOrthoOffCenterLH( &matrix, left, right, bottom, top, zNear, zFar ); + + D3DXMatrixOrthoOffCenterRH( &matrix, left, right, top, bottom, zNear, zFar ); + m_pMatrixStack[m_CurrStack]->MultMatrixLocal(&matrix); + Assert( m_CurrStack == MATERIAL_PROJECTION ); + UpdateMatrixTransform(); + } +} + +void CShaderAPIDx8::PerspectiveX( double fovx, double aspect, double zNear, double zFar ) +{ + if (MatrixIsChanging()) + { + float width = 2 * zNear * tan( fovx * M_PI / 360.0 ); + float height = width / aspect; + Assert( m_CurrStack == MATERIAL_PROJECTION ); + D3DXMATRIX rh; + D3DXMatrixPerspectiveRH( &rh, width, height, zNear, zFar ); + m_pMatrixStack[m_CurrStack]->MultMatrixLocal(&rh); + UpdateMatrixTransform(); + } +} + +void CShaderAPIDx8::PerspectiveOffCenterX( double fovx, double aspect, double zNear, double zFar, double bottom, double top, double left, double right ) +{ + if (MatrixIsChanging()) + { + float width = 2 * zNear * tan( fovx * M_PI / 360.0 ); + float height = width / aspect; + + // bottom, top, left, right are 0..1 so convert to -1..1 + float flFrontPlaneLeft = -(width/2.0f) * (1.0f - left) + left * (width/2.0f); + float flFrontPlaneRight = -(width/2.0f) * (1.0f - right) + right * (width/2.0f); + float flFrontPlaneBottom = -(height/2.0f) * (1.0f - bottom) + bottom * (height/2.0f); + float flFrontPlaneTop = -(height/2.0f) * (1.0f - top) + top * (height/2.0f); + + Assert( m_CurrStack == MATERIAL_PROJECTION ); + D3DXMATRIX rh; + D3DXMatrixPerspectiveOffCenterRH( &rh, flFrontPlaneLeft, flFrontPlaneRight, flFrontPlaneBottom, flFrontPlaneTop, zNear, zFar ); + m_pMatrixStack[m_CurrStack]->MultMatrixLocal(&rh); + UpdateMatrixTransform(); + } +} + +void CShaderAPIDx8::PickMatrix( int x, int y, int width, int height ) +{ + if (MatrixIsChanging()) + { + Assert( m_CurrStack == MATERIAL_PROJECTION ); + + // This is going to create a matrix to append to the standard projection. + // Projection space goes from -1 to 1 in x and y. This matrix we append + // will transform the pick region to -1 to 1 in projection space + ShaderViewport_t viewport; + GetViewports( &viewport, 1 ); + + int vx = viewport.m_nTopLeftX; + int vy = viewport.m_nTopLeftX; + int vwidth = viewport.m_nWidth; + int vheight = viewport.m_nHeight; + + // Compute the location of the pick region in projection space... + float px = 2.0 * (float)(x - vx) / (float)vwidth - 1; + float py = 2.0 * (float)(y - vy)/ (float)vheight - 1; + float pw = 2.0 * (float)width / (float)vwidth; + float ph = 2.0 * (float)height / (float)vheight; + + // we need to translate (px, py) to the origin + // and scale so (pw,ph) -> (2, 2) + D3DXMATRIX matrix; + D3DXMatrixIdentity( &matrix ); + matrix.m[0][0] = 2.0 / pw; + matrix.m[1][1] = 2.0 / ph; + matrix.m[3][0] = -2.0 * px / pw; + matrix.m[3][1] = -2.0 * py / ph; + + m_pMatrixStack[m_CurrStack]->MultMatrixLocal(&matrix); + UpdateMatrixTransform(); + } +} + +void CShaderAPIDx8::GetMatrix( MaterialMatrixMode_t matrixMode, float *dst ) +{ + memcpy( dst, (void*)(FLOAT*)GetTransform(matrixMode), sizeof(D3DXMATRIX) ); +} + + +//----------------------------------------------------------------------------- +// Did a transform change? +//----------------------------------------------------------------------------- +inline bool CShaderAPIDx8::VertexShaderTransformChanged( int i ) +{ + return (m_DynamicState.m_TransformChanged[i] & STATE_CHANGED_VERTEX_SHADER) != 0; +} + +inline bool CShaderAPIDx8::FixedFunctionTransformChanged( int i ) +{ + return (m_DynamicState.m_TransformChanged[i] & STATE_CHANGED_FIXED_FUNCTION) != 0; +} + + +const D3DXMATRIX &CShaderAPIDx8::GetProjectionMatrix( void ) +{ + bool bUsingZBiasProjectionMatrix = + !g_pHardwareConfig->Caps().m_ZBiasAndSlopeScaledDepthBiasSupported && + ( m_TransitionTable.CurrentSnapshot() != -1 ) && + m_TransitionTable.CurrentShadowState() && + m_TransitionTable.CurrentShadowState()->m_ZBias; + + if ( !m_DynamicState.m_FastClipEnabled ) + { + if ( bUsingZBiasProjectionMatrix ) + return m_CachedPolyOffsetProjectionMatrix; + + return GetTransform( MATERIAL_PROJECTION ); + } + + if ( bUsingZBiasProjectionMatrix ) + return m_CachedFastClipPolyOffsetProjectionMatrix; + + return m_CachedFastClipProjectionMatrix; +} + + +//----------------------------------------------------------------------------- +// Workaround hack for visualization of selection mode +//----------------------------------------------------------------------------- +void CShaderAPIDx8::SetupSelectionModeVisualizationState() +{ + Dx9Device()->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE ); + + D3DXMATRIX ident; + D3DXMatrixIdentity( &ident ); + SetTransform( D3DTS_WORLD, &ident ); + SetTransform( D3DTS_VIEW, &ident ); + SetTransform( D3DTS_PROJECTION, &ident ); + + if ( g_pHardwareConfig->Caps().m_SupportsPixelShaders ) + { + SetVertexShaderConstant( VERTEX_SHADER_VIEWPROJ, ident, 4 ); + SetVertexShaderConstant( VERTEX_SHADER_MODELVIEWPROJ, ident, 4 ); + float *pRowTwo = (float *)ident + 8; + SetVertexShaderConstant( VERTEX_SHADER_MODELVIEWPROJ_THIRD_ROW, pRowTwo, 1 ); // Row two of an identity matrix + SetVertexShaderConstant( VERTEX_SHADER_MODEL, ident, 3 * NUM_MODEL_TRANSFORMS ); + } +} + + +//----------------------------------------------------------------------------- +// Set view transforms +//----------------------------------------------------------------------------- + +static void printmat4x4( char *label, float *m00 ) +{ + // print label.. + // fetch 4 from row, print as a row + // fetch 4 from column, print as a row + +#ifdef DX_TO_GL_ABSTRACTION + float row[4]; + float col[4]; + + GLMPRINTF(("-M- -- %s --", label )); + for( int n=0; n<4; n++ ) + { + // extract row and column floats + for( int i=0; i<4;i++) + { + row[i] = m00[(n*4)+i]; + col[i] = m00[(i*4)+n]; + } + GLMPRINTF(( "-M- [ %7.4f %7.4f %7.4f %7.4f ] T=> [ %7.4f %7.4f %7.4f %7.4f ]", + row[0],row[1],row[2],row[3], + col[0],col[1],col[2],col[3] + )); + } + GLMPRINTF(("-M-")); +#endif +} + +void CShaderAPIDx8::SetVertexShaderViewProj() +{ + //GLM_FUNC; + //GLMPRINTF(( ">-M- SetVertexShaderViewProj" )); + + if (g_pHardwareConfig->Caps().m_SupportsPixelShaders) + { + D3DXMATRIX transpose; + if(0) + { + transpose = GetTransform(MATERIAL_VIEW) * GetProjectionMatrix(); + D3DXMatrixTranspose( &transpose, &transpose ); + } + else + { + // show work + D3DXMATRIX matView,matProj; + + matView = GetTransform(MATERIAL_VIEW); + matProj = GetProjectionMatrix(); + transpose = matView * matProj; + + //printmat4x4( "matView", (float*)&matView ); + //printmat4x4( "matProj", (float*)&matProj ); + //printmat4x4( "result (view * proj) pre-transpose", (float*)&transpose ); + + D3DXMatrixTranspose( &transpose, &transpose ); + + #if 0 // turned off while we try to do fixup-Y in shader translate + if (IsPosix()) // flip all shader projection matrices for Y on GL since you can't have an upside-down viewport specification + { + // flip Y + transpose._21 *= -1.0f; + transpose._22 *= -1.0f; + transpose._23 *= -1.0f; + transpose._24 *= -1.0f; + } + #endif + + //printmat4x4( "result (view * proj) post-transpose", (float*)&transpose ); + } + + + SetVertexShaderConstant( VERTEX_SHADER_VIEWPROJ, transpose, 4 ); + + // If we're doing FastClip, the above viewproj matrix won't work well for + // vertex shaders which compute projPos.z, hence we'll compute a more useful + // viewproj and put the third row of it in another constant + transpose = GetTransform( MATERIAL_VIEW ) * GetTransform( MATERIAL_PROJECTION ); // Get the non-FastClip projection matrix + D3DXMatrixTranspose( &transpose, &transpose ); + + float *pRowTwo = (float *)transpose + 8; + SetVertexShaderConstant( VERTEX_SHADER_VIEWPROJ_THIRD_ROW, pRowTwo, 1 ); + } + //GLMPRINTF(( "<-M- SetVertexShaderViewProj" )); +} + +void CShaderAPIDx8::SetVertexShaderModelViewProjAndModelView( void ) +{ + //GLM_FUNC; + //GLMPRINTF(( ">-M- SetVertexShaderModelViewProjAndModelView" )); + + if (g_pHardwareConfig->Caps().m_SupportsPixelShaders) + { + D3DXMATRIX modelView, transpose; + + if (0) + { + D3DXMatrixMultiply( &modelView, &GetTransform(MATERIAL_MODEL), &GetTransform(MATERIAL_VIEW) ); + D3DXMatrixMultiply( &transpose, &modelView, &GetProjectionMatrix() ); + } + else + { + // show work + D3DXMATRIX matView,matProj,matModel; + + matModel = GetTransform(MATERIAL_MODEL); + matView = GetTransform(MATERIAL_VIEW); + matProj = GetProjectionMatrix(); + + D3DXMatrixMultiply( &modelView, &matModel, &matView ); + D3DXMatrixMultiply( &transpose, &modelView, &matProj ); + + //printmat4x4( "matModel", (float*)&matModel ); + //printmat4x4( "matView", (float*)&matView ); + //printmat4x4( "matProj", (float*)&matProj ); + //printmat4x4( "result (model * view * proj) pre-transpose", (float*)&transpose ); + } + + D3DXMatrixTranspose( &transpose, &transpose ); + + #if 0 // turned off while we try to do fixup-Y in shader translate + if (IsPosix()) // flip all shader projection matrices for Y on GL since you can't have an upside-down viewport specification + { + // flip Y + transpose._21 *= -1.0f; + transpose._22 *= -1.0f; + transpose._23 *= -1.0f; + transpose._24 *= -1.0f; + } + #endif + + SetVertexShaderConstant( VERTEX_SHADER_MODELVIEWPROJ, transpose, 4 ); + + // If we're doing FastClip, the above modelviewproj matrix won't work well for + // vertex shaders which compute projPos.z, hence we'll compute a more useful + // modelviewproj and put the third row of it in another constant + D3DXMatrixMultiply( &transpose, &modelView, &GetTransform( MATERIAL_PROJECTION ) ); // Get the non-FastClip projection matrix + D3DXMatrixTranspose( &transpose, &transpose ); + + float *pRowTwo = (float *)transpose + 8; + SetVertexShaderConstant( VERTEX_SHADER_MODELVIEWPROJ_THIRD_ROW, pRowTwo, 1 ); + } + + //GLMPRINTF(( "<-M- SetVertexShaderModelViewProjAndModelView" )); +} + +void CShaderAPIDx8::UpdateVertexShaderMatrix( int iMatrix ) +{ + //GLM_FUNC; + if ( iMatrix == 0 ) + { + int matrix = MATERIAL_MODEL; + if (VertexShaderTransformChanged(matrix)) + { + int vertexShaderConstant = VERTEX_SHADER_MODEL + iMatrix * 3; + + // Put the transform into the vertex shader constants... + D3DXMATRIX transpose; + D3DXMatrixTranspose( &transpose, &GetTransform(matrix) ); + SetVertexShaderConstant( vertexShaderConstant, transpose, 3 ); + + // clear the change flag + m_DynamicState.m_TransformChanged[matrix] &= ~STATE_CHANGED_VERTEX_SHADER; + } + } + else + { + SetVertexShaderConstant( VERTEX_SHADER_MODEL + iMatrix, m_boneMatrix[iMatrix].Base(), 3 ); + } +} + + +void CShaderAPIDx8::SetVertexShaderStateSkinningMatrices() +{ + //GLM_FUNC; + // casting from 4x3 matrices to a 4x4 D3DXMATRIX, need 4 floats of overflow + float results[12+4]; + + // get the first one from the MATERIAL_MODEL matrix stack + D3DXMatrixTranspose( (D3DXMATRIX *)&results[0], &GetTransform( MATERIAL_MODEL ) ); + memcpy( m_boneMatrix[0].Base(), results, 12 * sizeof(float) ); + + m_maxBoneLoaded++; + int matricesLoaded = max( 1, m_maxBoneLoaded ); + m_maxBoneLoaded = 0; + + m_DynamicState.m_TransformChanged[MATERIAL_MODEL] &= ~STATE_CHANGED_VERTEX_SHADER; + SetVertexShaderConstant( VERTEX_SHADER_MODEL, m_boneMatrix[0].Base(), matricesLoaded * 3, true ); + + // ###OSX### punting on OSX for now +#if defined( DX_TO_GL_ABSTRACTION ) && !defined( OSX ) + Dx9Device()->SetMaxUsedVertexShaderConstantsHint( VERTEX_SHADER_MODEL + ( matricesLoaded * 3 ) ); +#endif + +} + +//----------------------------------------------------------------------------- +// Commits vertex shader transforms that can change on a per pass basis +//----------------------------------------------------------------------------- +void CShaderAPIDx8::CommitPerPassVertexShaderTransforms() +{ + //GLMPRINTF(( ">-M- CommitPerPassVertexShaderTransforms" )); + Assert( g_pHardwareConfig->Caps().m_SupportsPixelShaders ); + + bool projChanged = VertexShaderTransformChanged( MATERIAL_PROJECTION ); + //projChanged = true; //only for debug + if ( projChanged ) + { + //GLMPRINTF(( "-M- projChanged=true in CommitPerPassVertexShaderTransforms" )); + SetVertexShaderViewProj(); + SetVertexShaderModelViewProjAndModelView(); + + // Clear change flags + m_DynamicState.m_TransformChanged[MATERIAL_PROJECTION] &= ~STATE_CHANGED_VERTEX_SHADER; + } + else + { + //GLMPRINTF(( "-M- projChanged=false in CommitPerPassVertexShaderTransforms" )); + } + + //GLMPRINTF(( "<-M- CommitPerPassVertexShaderTransforms" )); +} + +//----------------------------------------------------------------------------- +// Commits vertex shader transforms +//----------------------------------------------------------------------------- +void CShaderAPIDx8::CommitVertexShaderTransforms() +{ + //GLMPRINTF(( ">-M- CommitVertexShaderTransforms" )); + + Assert( g_pHardwareConfig->Caps().m_SupportsPixelShaders ); + + bool viewChanged = VertexShaderTransformChanged(MATERIAL_VIEW); + bool projChanged = VertexShaderTransformChanged(MATERIAL_PROJECTION); + bool modelChanged = VertexShaderTransformChanged(MATERIAL_MODEL) && (m_DynamicState.m_NumBones < 1); + + //GLMPRINTF(( "-M- viewChanged=%s projChanged=%s modelChanged = %s in CommitVertexShaderTransforms", viewChanged?"Y":"N",projChanged?"Y":"N",modelChanged?"Y":"N" )); + if (viewChanged) + { + //GLMPRINTF(( "-M- viewChanged --> UpdateVertexShaderFogParams" )); + UpdateVertexShaderFogParams(); + } + + if( viewChanged || projChanged ) + { + // NOTE: We have to deal with fast-clip *before* + //GLMPRINTF(( "-M- viewChanged||projChanged --> SetVertexShaderViewProj" )); + SetVertexShaderViewProj(); + } + + if( viewChanged || modelChanged || projChanged ) + { + //GLMPRINTF(( "-M- viewChanged||projChanged||modelChanged --> SetVertexShaderModelViewProjAndModelView" )); + SetVertexShaderModelViewProjAndModelView(); + } + + if( modelChanged && m_DynamicState.m_NumBones < 1 ) + { + UpdateVertexShaderMatrix( 0 ); + } + + // Clear change flags + m_DynamicState.m_TransformChanged[MATERIAL_MODEL] &= ~STATE_CHANGED_VERTEX_SHADER; + m_DynamicState.m_TransformChanged[MATERIAL_VIEW] &= ~STATE_CHANGED_VERTEX_SHADER; + m_DynamicState.m_TransformChanged[MATERIAL_PROJECTION] &= ~STATE_CHANGED_VERTEX_SHADER; + + //GLMPRINTF(( "<-M- CommitVertexShaderTransforms" )); +} + + +void CShaderAPIDx8::UpdateFixedFunctionMatrix( int iMatrix ) +{ + if ( IsX360() ) + return; + + int matrix = MATERIAL_MODEL + iMatrix; + if ( FixedFunctionTransformChanged( matrix ) ) + { + SetTransform( D3DTS_WORLDMATRIX(iMatrix), &GetTransform(matrix) ); + + // clear the change flag + m_DynamicState.m_TransformChanged[matrix] &= ~STATE_CHANGED_FIXED_FUNCTION; + } +} + + +void CShaderAPIDx8::SetFixedFunctionStateSkinningMatrices() +{ + if ( IsX360() ) + return; + + for( int i=1; i < g_pHardwareConfig->MaxBlendMatrices(); i++ ) + { + UpdateFixedFunctionMatrix( i ); + } +} + +//----------------------------------------------------------------------------- +// Commits transforms for the fixed function pipeline that can happen on a per pass basis +//----------------------------------------------------------------------------- +void CShaderAPIDx8::CommitPerPassFixedFunctionTransforms() +{ + if ( IsX360() ) + return; + + // Update projection + if ( FixedFunctionTransformChanged( MATERIAL_PROJECTION ) ) + { + D3DTRANSFORMSTATETYPE matrix = D3DTS_PROJECTION; + + SetTransform( matrix, &GetProjectionMatrix() ); + // clear the change flag + m_DynamicState.m_TransformChanged[MATERIAL_PROJECTION] &= ~STATE_CHANGED_FIXED_FUNCTION; + } +} + + +//----------------------------------------------------------------------------- +// Commits transforms for the fixed function pipeline +//----------------------------------------------------------------------------- + +void CShaderAPIDx8::CommitFixedFunctionTransforms() +{ + if ( IsX360() ) + return; + + // Update view + projection + int i; + for ( i = MATERIAL_VIEW; i <= MATERIAL_PROJECTION; ++i) + { + if (FixedFunctionTransformChanged( i )) + { + D3DTRANSFORMSTATETYPE matrix = (i == MATERIAL_VIEW) ? D3DTS_VIEW : D3DTS_PROJECTION; + if ( i == MATERIAL_PROJECTION ) + { + SetTransform( matrix, &GetProjectionMatrix() ); + } + else + { + SetTransform( matrix, &GetTransform(i) ); + } + + // clear the change flag + m_DynamicState.m_TransformChanged[i] &= ~STATE_CHANGED_FIXED_FUNCTION; + } + } + + UpdateFixedFunctionMatrix( 0 ); +} + + +void CShaderAPIDx8::SetSkinningMatrices() +{ + LOCK_SHADERAPI(); + Assert( m_pMaterial ); + + if ( m_DynamicState.m_NumBones == 0 ) + { + // ###OSX### punting on OSX for now +#if defined( DX_TO_GL_ABSTRACTION ) && !defined( OSX) + Dx9Device()->SetMaxUsedVertexShaderConstantsHint( VERTEX_SHADER_BONE_TRANSFORM( 0 ) + 3 ); +#endif + return; + } + + uint nMaxVertexConstantIndex = 0; + + if ( IsX360() || UsesVertexShader(m_pMaterial->GetVertexFormat()) ) + { + SetVertexShaderStateSkinningMatrices(); + } + else if ( IsPC() ) + { +#if defined( DX_TO_GL_ABSTRACTION ) && !defined( OSX) + Assert( 0 ); +#else + SetFixedFunctionStateSkinningMatrices(); +#endif + } + else + { + Assert( 0 ); + } +} + + + +//----------------------------------------------------------------------------- +// Commits vertex shader lighting +//----------------------------------------------------------------------------- + +inline bool CShaderAPIDx8::VertexShaderLightingChanged( int i ) +{ + return (m_DynamicState.m_LightChanged[i] & STATE_CHANGED_VERTEX_SHADER) != 0; +} + +inline bool CShaderAPIDx8::VertexShaderLightingEnableChanged( int i ) +{ + return (m_DynamicState.m_LightEnableChanged[i] & STATE_CHANGED_VERTEX_SHADER) != 0; +} + +inline bool CShaderAPIDx8::FixedFunctionLightingChanged( int i ) +{ + return (m_DynamicState.m_LightChanged[i] & STATE_CHANGED_FIXED_FUNCTION) != 0; +} + +inline bool CShaderAPIDx8::FixedFunctionLightingEnableChanged( int i ) +{ + return (m_DynamicState.m_LightEnableChanged[i] & STATE_CHANGED_FIXED_FUNCTION) != 0; +} + + +//----------------------------------------------------------------------------- +// Computes the light type +//----------------------------------------------------------------------------- + +VertexShaderLightTypes_t CShaderAPIDx8::ComputeLightType( int i ) const +{ + if (!m_DynamicState.m_LightEnable[i]) + return LIGHT_NONE; + + switch( m_DynamicState.m_Lights[i].Type ) + { + case D3DLIGHT_POINT: + return LIGHT_POINT; + + case D3DLIGHT_DIRECTIONAL: + return LIGHT_DIRECTIONAL; + + case D3DLIGHT_SPOT: + return LIGHT_SPOT; + } + + Assert(0); + return LIGHT_NONE; +} + + +//----------------------------------------------------------------------------- +// Sort the lights by type +//----------------------------------------------------------------------------- + +void CShaderAPIDx8::SortLights( int* index ) +{ + m_DynamicState.m_NumLights = 0; + + for (int i = 0; i < MAX_NUM_LIGHTS; ++i) + { + VertexShaderLightTypes_t type = ComputeLightType(i); // returns LIGHT_NONE if the light is disabled + int j = m_DynamicState.m_NumLights; + if (type != LIGHT_NONE) + { + while ( --j >= 0 ) + { + if (m_DynamicState.m_LightType[j] <= type) + break; + + // shift... + m_DynamicState.m_LightType[j+1] = m_DynamicState.m_LightType[j]; + index[j+1] = index[j]; + } + ++j; + + m_DynamicState.m_LightType[j] = type; + index[j] = i; + + ++m_DynamicState.m_NumLights; + } + } +} + +//----------------------------------------------------------------------------- +// Vertex Shader lighting +//----------------------------------------------------------------------------- +void CShaderAPIDx8::CommitVertexShaderLighting() +{ + // If nothing changed, then don't bother. Otherwise, reload... + int i; + for ( i = 0; i < MAX_NUM_LIGHTS; ++i ) + { + if (VertexShaderLightingChanged(i) || VertexShaderLightingEnableChanged(i)) + break; + } + + // Yeah baby + if ( i == MAX_NUM_LIGHTS ) + return; + + // First, gotta sort the lights by their type + int lightIndex[MAX_NUM_LIGHTS]; + memset( lightIndex, 0, sizeof( lightIndex ) ); + SortLights( lightIndex ); + + // Clear the lighting enable flags + for ( i = 0; i < MAX_NUM_LIGHTS; ++i ) + { + m_DynamicState.m_LightEnableChanged[i] &= ~STATE_CHANGED_VERTEX_SHADER; + m_DynamicState.m_LightChanged[i] &= ~STATE_CHANGED_VERTEX_SHADER; + } + + bool bAtLeastDX90 = g_pHardwareConfig->GetDXSupportLevel() >= 90; + + // Set the lighting state + for ( i = 0; i < m_DynamicState.m_NumLights; ++i ) + { + D3DLIGHT& light = m_DynamicState.m_Lights[lightIndex[i]]; + + Vector4D lightState[5]; + + // The first one is the light color (and light type code on DX9) + float w = (light.Type == D3DLIGHT_DIRECTIONAL) && bAtLeastDX90 ? 1.0f : 0.0f; + lightState[0].Init( light.Diffuse.r, light.Diffuse.g, light.Diffuse.b, w); + + // The next constant holds the light direction (and light type code on DX9) + w = (light.Type == D3DLIGHT_SPOT) && bAtLeastDX90 ? 1.0f : 0.0f; + lightState[1].Init( light.Direction.x, light.Direction.y, light.Direction.z, w ); + + // The next constant holds the light position + lightState[2].Init( light.Position.x, light.Position.y, light.Position.z, 1.0f ); + + // The next constant holds exponent, stopdot, stopdot2, 1 / (stopdot - stopdot2) + if (light.Type == D3DLIGHT_SPOT) + { + float stopdot = cos( light.Theta * 0.5f ); + float stopdot2 = cos( light.Phi * 0.5f ); + float oodot = (stopdot > stopdot2) ? 1.0f / (stopdot - stopdot2) : 0.0f; + lightState[3].Init( light.Falloff, stopdot, stopdot2, oodot ); + } + else + { + lightState[3].Init( 0, 1, 1, 1 ); + } + + // The last constant holds attenuation0, attenuation1, attenuation2 + lightState[4].Init( light.Attenuation0, light.Attenuation1, light.Attenuation2, 0.0f ); + + // Set the state + SetVertexShaderConstant( VERTEX_SHADER_LIGHTS + i * 5, lightState[0].Base(), 5 ); + } + + if ( g_pHardwareConfig->NumIntegerVertexShaderConstants() > 0 && g_pHardwareConfig->NumBooleanVertexShaderConstants() > 0 ) + { + // Vertex Shader loop counter for number of lights (Only the .x component is used by our shaders) + // .x is the iteration count, .y is the initial value and .z is the increment step + int nLoopControl[4] = {m_DynamicState.m_NumLights, 0, 1, 0}; + SetIntegerVertexShaderConstant( 0, nLoopControl, 1 ); + + // Enable lights using vertex shader static flow control + int nLightEnable[VERTEX_SHADER_LIGHT_ENABLE_BOOL_CONST_COUNT] = {0, 0, 0, 0}; + for ( i = 0; i < m_DynamicState.m_NumLights; ++i ) + { + nLightEnable[i] = 1; + } + + SetBooleanVertexShaderConstant( VERTEX_SHADER_LIGHT_ENABLE_BOOL_CONST, nLightEnable, VERTEX_SHADER_LIGHT_ENABLE_BOOL_CONST_COUNT ); + } +} + +//----------------------------------------------------------------------------- +// Set the pixel shader constants for lights +//----------------------------------------------------------------------------- +void CShaderAPIDx8::CommitPixelShaderLighting( int pshReg ) +{ +#ifndef NDEBUG + char const *materialName = m_pMaterial->GetName(); +#endif + + // First, gotta sort the lights by their type + int lightIndex[MAX_NUM_LIGHTS]; + SortLights( lightIndex ); + + // Offset to create a point light from directional + const float fFarAway = 10000.0f; + + // Total pixel shader lighting state for four lights + Vector4D lightState[6]; + for ( int i = 0; i < 6; i++ ) + lightState[i].Init(); + + int nNumLights = m_DynamicState.m_NumLights; + if ( nNumLights > 0 ) + { + D3DLIGHT *light = &m_DynamicState.m_Lights[lightIndex[0]]; + lightState[0].Init( light->Diffuse.r, light->Diffuse.g, light->Diffuse.b, 0.0f ); + + if ( light->Type == D3DLIGHT_DIRECTIONAL ) + { + Vector vDir(light->Direction.x, light->Direction.y, light->Direction.z ); + Vector vPos = m_DynamicState.m_vLightingOrigin - vDir * fFarAway; + lightState[1].Init( vPos.x, vPos.y, vPos.z, 0.0f ); + } + else + { + lightState[1].Init( light->Position.x, light->Position.y, light->Position.z, 0.0f ); + } + + if ( nNumLights > 1 ) // At least two lights + { + light = &m_DynamicState.m_Lights[lightIndex[1]]; + lightState[2].Init( light->Diffuse.r, light->Diffuse.g, light->Diffuse.b, 0.0f ); + + if ( light->Type == D3DLIGHT_DIRECTIONAL ) + { + Vector vDir(light->Direction.x, light->Direction.y, light->Direction.z ); + Vector vPos = m_DynamicState.m_vLightingOrigin - vDir * fFarAway; + lightState[3].Init( vPos.x, vPos.y, vPos.z, 0.0f ); + } + else + { + lightState[3].Init( light->Position.x, light->Position.y, light->Position.z, 0.0f ); + } + + if ( nNumLights > 2 ) // At least three lights + { + light = &m_DynamicState.m_Lights[lightIndex[2]]; + lightState[4].Init( light->Diffuse.r, light->Diffuse.g, light->Diffuse.b, 0.0f ); + + if ( light->Type == D3DLIGHT_DIRECTIONAL ) + { + Vector vDir(light->Direction.x, light->Direction.y, light->Direction.z ); + Vector vPos = m_DynamicState.m_vLightingOrigin - vDir * fFarAway; + lightState[5].Init( vPos.x, vPos.y, vPos.z, 0.0f ); + } + else + { + lightState[5].Init( light->Position.x, light->Position.y, light->Position.z, 0.0f ); + } + + if ( nNumLights > 3 ) // At least four lights (our current max) + { + light = &m_DynamicState.m_Lights[lightIndex[3]]; // Spread 4th light's constants across w components + lightState[0].w = light->Diffuse.r; + lightState[1].w = light->Diffuse.g; + lightState[2].w = light->Diffuse.b; + + if ( light->Type == D3DLIGHT_DIRECTIONAL ) + { + Vector vDir(light->Direction.x, light->Direction.y, light->Direction.z ); + Vector vPos = m_DynamicState.m_vLightingOrigin - vDir * fFarAway; + lightState[3].w = vPos.x; + lightState[4].w = vPos.y; + lightState[5].w = vPos.z; + } + else + { + lightState[3].w = light->Position.x; + lightState[4].w = light->Position.y; + lightState[5].w = light->Position.z; + } + } + } + } + } + SetPixelShaderConstant( pshReg, lightState[0].Base(), 6 ); +} + +//----------------------------------------------------------------------------- +// Fixed function lighting +//----------------------------------------------------------------------------- +void CShaderAPIDx8::CommitFixedFunctionLighting() +{ + if ( IsX360() ) + { + return; + } + + // Commit each light + for (int i = 0; i < g_pHardwareConfig->MaxNumLights(); ++i) + { + // Change light enable + if ( FixedFunctionLightingEnableChanged( i ) ) + { + LightEnable( i, m_DynamicState.m_LightEnable[i] ); + + // Clear change flag + m_DynamicState.m_LightEnableChanged[i] &= ~STATE_CHANGED_FIXED_FUNCTION; + } + + // Change lighting state... + if ( m_DynamicState.m_LightEnable[i] ) + { + if ( FixedFunctionLightingChanged( i ) ) + { + // Store off the "correct" falloff... + D3DLIGHT& light = m_DynamicState.m_Lights[i]; + + float falloff = light.Falloff; + + SetLight( i, &light ); + + // Clear change flag + m_DynamicState.m_LightChanged[i] &= ~STATE_CHANGED_FIXED_FUNCTION; + + // restore the correct falloff + light.Falloff = falloff; + } + } + } +} + + +//----------------------------------------------------------------------------- +// Commits user clip planes +//----------------------------------------------------------------------------- +D3DXMATRIX& CShaderAPIDx8::GetUserClipTransform( ) +{ + if ( !m_DynamicState.m_bUserClipTransformOverride ) + return GetTransform(MATERIAL_VIEW); + + return m_DynamicState.m_UserClipTransform; +} + + +//----------------------------------------------------------------------------- +// Commits user clip planes +//----------------------------------------------------------------------------- +void CShaderAPIDx8::CommitUserClipPlanes( bool bUsingFixedFunction ) +{ + // We need to transform the clip planes, specified in world space, + // to be in projection space.. To transform the plane, we must transform + // the intercept and then transform the normal. + + if( bUsingFixedFunction != m_DynamicState.m_UserClipLastUpdatedUsingFixedFunction ) + { + //fixed function clip planes are in world space, vertex shader clip planes are in clip space, so we need to update every clip plane whenever there's a flip + m_DynamicState.m_UserClipPlaneChanged = (1 << g_pHardwareConfig->MaxUserClipPlanes()) - 1; + m_DynamicState.m_UserClipLastUpdatedUsingFixedFunction = bUsingFixedFunction; + } + + D3DXMATRIX worldToProjectionInvTrans; +#ifndef _DEBUG + if( m_DynamicState.m_UserClipPlaneChanged & m_DynamicState.m_UserClipPlaneEnabled & ((1 << g_pHardwareConfig->MaxUserClipPlanes()) - 1) ) +#endif + { + //we're going to need the transformation matrix at least once this call + if( bUsingFixedFunction ) + { + if( m_DynamicState.m_bUserClipTransformOverride ) + { + //D3DXMatrixIdentity( &worldToProjectionInvTrans ); //TODO: Test user clip transforms with this + //Since GetUserClipTransform() returns the view matrix if a user supplied transform doesn't exist, the general solution to this should be to transform the user transform by the inverse view matrix + //Since we don't know if the user clip is invertable, we'll premultiply by inverse view and cross our fingers that it's right more often than wrong + D3DXMATRIX viewInverse = GetTransform( MATERIAL_VIEW ); + D3DXMatrixInverse(&viewInverse, NULL, &viewInverse); + worldToProjectionInvTrans = viewInverse * GetUserClipTransform(); //taking a cue from the multiplication below, multiplication goes left into right + + D3DXMatrixInverse(&worldToProjectionInvTrans, NULL, &worldToProjectionInvTrans); + D3DXMatrixTranspose(&worldToProjectionInvTrans, &worldToProjectionInvTrans); + } + else + { + D3DXMatrixIdentity( &worldToProjectionInvTrans ); + } + } + else + { + worldToProjectionInvTrans = GetUserClipTransform( ) * GetTransform( MATERIAL_PROJECTION ); + D3DXMatrixInverse(&worldToProjectionInvTrans, NULL, &worldToProjectionInvTrans); + D3DXMatrixTranspose(&worldToProjectionInvTrans, &worldToProjectionInvTrans); + } + } + + for (int i = 0; i < g_pHardwareConfig->MaxUserClipPlanes(); ++i) + { + // Don't bother with the plane if it's not enabled + if ( (m_DynamicState.m_UserClipPlaneEnabled & (1 << i)) == 0 ) + continue; + + // Don't bother if it didn't change... + if ( (m_DynamicState.m_UserClipPlaneChanged & (1 << i)) == 0 ) + { +#ifdef _DEBUG + //verify that the plane has not actually changed + D3DXPLANE clipPlaneProj; + D3DXPlaneTransform( &clipPlaneProj, &m_DynamicState.m_UserClipPlaneWorld[i], &worldToProjectionInvTrans ); + Assert ( clipPlaneProj == m_DynamicState.m_UserClipPlaneProj[i] ); +#endif + continue; + } + + m_DynamicState.m_UserClipPlaneChanged &= ~(1 << i); + + D3DXPLANE clipPlaneProj; + D3DXPlaneTransform( &clipPlaneProj, &m_DynamicState.m_UserClipPlaneWorld[i], &worldToProjectionInvTrans ); + + if ( clipPlaneProj != m_DynamicState.m_UserClipPlaneProj[i] ) + { + Dx9Device()->SetClipPlane( i, (float*)clipPlaneProj ); + m_DynamicState.m_UserClipPlaneProj[i] = clipPlaneProj; + } + } +} + + +//----------------------------------------------------------------------------- +// Need to handle fog mode on a per-pass basis +//----------------------------------------------------------------------------- +void CShaderAPIDx8::CommitPerPassFogMode( bool bUsingVertexAndPixelShaders ) +{ + if ( IsX360() ) + { + // FF fog not applicable on 360 + return; + } + + D3DFOGMODE dxFogMode = D3DFOG_NONE; + if ( m_DynamicState.m_FogEnable ) + { + dxFogMode = bUsingVertexAndPixelShaders ? D3DFOG_NONE : D3DFOG_LINEAR; + } + + // Set fog mode if it's different than before. + if( m_DynamicState.m_FogMode != dxFogMode ) + { + SetRenderStateConstMacro( this, D3DRS_FOGVERTEXMODE, dxFogMode ); + m_DynamicState.m_FogMode = dxFogMode; + } +} + +//----------------------------------------------------------------------------- +// Handle Xbox GPU/DX API fixups necessary before actual draw. +//----------------------------------------------------------------------------- +void CShaderAPIDx8::CommitPerPassXboxFixups() +{ +#if defined( _X360 ) + // send updated shader constants to gpu + WriteShaderConstantsToGPU(); + + // sRGB write state may have changed after RT set, have to re-set correct RT + SetRenderTargetInternalXbox( m_hCachedRenderTarget ); +#endif +} + +//----------------------------------------------------------------------------- +// These states can change between each pass +//----------------------------------------------------------------------------- +void CShaderAPIDx8::CommitPerPassStateChanges( StateSnapshot_t id ) +{ + if ( IsX360() || UsesVertexAndPixelShaders(id) ) + { + CommitPerPassVertexShaderTransforms(); + CommitPerPassFogMode( true ); + CommitPerPassXboxFixups(); + CallCommitFuncs( COMMIT_PER_PASS, false ); + } + else if ( IsPC() ) + { + CommitPerPassFixedFunctionTransforms(); + CommitPerPassFogMode( false ); + CallCommitFuncs( COMMIT_PER_PASS, true ); + } + else + { + Assert( 0 ); + } +} + + +//----------------------------------------------------------------------------- +// Commits transforms and lighting +//----------------------------------------------------------------------------- +void CShaderAPIDx8::CommitStateChanges() +{ + VPROF("CShaderAPIDx8::CommitStateChanges"); + CommitFastClipPlane(); + + bool bUsingFixedFunction = !IsX360() && m_pMaterial && !UsesVertexShader( m_pMaterial->GetVertexFormat() ); + + // xboxissue - cannot support ff pipeline + Assert ( IsPC() || ( IsX360() && !bUsingFixedFunction ) ); + + if ( IsX360() || !bUsingFixedFunction ) + { + CommitVertexShaderTransforms(); + + if ( m_pMaterial && m_pMaterial->IsVertexLit() ) + { + CommitVertexShaderLighting(); + } + } + else if ( IsPC() ) + { + CommitFixedFunctionTransforms(); + + if ( m_pMaterial && ( m_pMaterial->IsVertexLit() || m_pMaterial->NeedsFixedFunctionFlashlight() ) ) + { + CommitFixedFunctionLighting(); + } + } + else + { + Assert( 0 ); + } + + if ( m_DynamicState.m_UserClipPlaneEnabled ) + { + CommitUserClipPlanes( bUsingFixedFunction ); + } + + CallCommitFuncs( COMMIT_PER_DRAW, bUsingFixedFunction ); +} + +//----------------------------------------------------------------------------- +// Commits viewports +//----------------------------------------------------------------------------- +static void CommitSetViewports( IDirect3DDevice9 *pDevice, const DynamicState_t &desiredState, DynamicState_t ¤tState, bool bForce ) +{ + bool bChanged = bForce || memcmp( &desiredState.m_Viewport, ¤tState.m_Viewport, sizeof(D3DVIEWPORT9) ); + + // The width + height can be zero at startup sometimes. + if ( bChanged && ( desiredState.m_Viewport.Width != 0 ) && ( desiredState.m_Viewport.Height != 0 ) ) + { + if( ReverseDepthOnX360() ) //reverse depth on 360 for better perf through hierarchical z + { + D3DVIEWPORT9 reverseDepthViewport; + reverseDepthViewport = desiredState.m_Viewport; + reverseDepthViewport.MinZ = 1.0f - desiredState.m_Viewport.MinZ; + reverseDepthViewport.MaxZ = 1.0f - desiredState.m_Viewport.MaxZ; + Dx9Device()->SetViewport( &reverseDepthViewport ); + } + else + { + Dx9Device()->SetViewport( &desiredState.m_Viewport ); + } + memcpy( ¤tState.m_Viewport, &desiredState.m_Viewport, sizeof( D3DVIEWPORT9 ) ); + } +} + + +void CShaderAPIDx8::SetViewports( int nCount, const ShaderViewport_t* pViewports ) +{ + Assert( nCount == 1 && pViewports[0].m_nVersion == SHADER_VIEWPORT_VERSION ); + if ( nCount != 1 ) + return; + + LOCK_SHADERAPI(); + + D3DVIEWPORT9 viewport; + viewport.X = pViewports[0].m_nTopLeftX; + viewport.Y = pViewports[0].m_nTopLeftY; + viewport.Width = pViewports[0].m_nWidth; + viewport.Height = pViewports[0].m_nHeight; + viewport.MinZ = pViewports[0].m_flMinZ; + viewport.MaxZ = pViewports[0].m_flMaxZ; + + // Clamp the viewport to the current render target... + if ( !m_UsingTextureRenderTarget ) + { + // Clamp to both the back buffer and the window, if it is resizing + int nMaxWidth = 0, nMaxHeight = 0; + GetBackBufferDimensions( nMaxWidth, nMaxHeight ); + if ( IsPC() && m_IsResizing ) + { + RECT viewRect; +#if !defined( DX_TO_GL_ABSTRACTION ) + GetClientRect( ( HWND )m_ViewHWnd, &viewRect ); +#else + toglGetClientRect( (VD3DHWND)m_ViewHWnd, &viewRect ); +#endif + m_nWindowWidth = viewRect.right - viewRect.left; + m_nWindowHeight = viewRect.bottom - viewRect.top; + nMaxWidth = min( m_nWindowWidth, nMaxWidth ); + nMaxHeight = min( m_nWindowHeight, nMaxHeight ); + } + + // Dimensions can freak out on app exit, so at least make sure the viewport is positive + if ( (viewport.Width > (unsigned int)nMaxWidth ) && (nMaxWidth > 0) ) + { + viewport.Width = nMaxWidth; + } + + // Dimensions can freak out on app exit, so at least make sure the viewport is positive + if ( ( viewport.Height > (unsigned int)nMaxHeight ) && (nMaxHeight > 0) ) + { + viewport.Height = nMaxHeight; + } + } + else + { + if ( viewport.Width > (unsigned int)m_ViewportMaxWidth ) + { + viewport.Width = m_ViewportMaxWidth; + } + if ( viewport.Height > (unsigned int)m_ViewportMaxHeight ) + { + viewport.Height = m_ViewportMaxHeight; + } + } + + // FIXME: Once we extract buffered primitives out, we can directly fill in desired state + // and avoid the memcmp and copy + if ( memcmp( &m_DesiredState.m_Viewport, &viewport, sizeof(D3DVIEWPORT9) ) ) + { + if ( !IsDeactivated() ) + { + // State changed... need to flush the dynamic buffer + FlushBufferedPrimitives(); + } + + memcpy( &m_DesiredState.m_Viewport, &viewport, sizeof(D3DVIEWPORT9) ); + } + + ADD_COMMIT_FUNC( COMMIT_PER_DRAW, COMMIT_ALWAYS, CommitSetViewports ); +} + + +//----------------------------------------------------------------------------- +// Gets the current viewport size +//----------------------------------------------------------------------------- +int CShaderAPIDx8::GetViewports( ShaderViewport_t* pViewports, int nMax ) const +{ + if ( !pViewports || nMax == 0 ) + return 1; + + LOCK_SHADERAPI(); + + pViewports[0].m_nTopLeftX = m_DesiredState.m_Viewport.X; + pViewports[0].m_nTopLeftY = m_DesiredState.m_Viewport.Y; + pViewports[0].m_nWidth = m_DesiredState.m_Viewport.Width; + pViewports[0].m_nHeight = m_DesiredState.m_Viewport.Height; + pViewports[0].m_flMinZ = m_DesiredState.m_Viewport.MinZ; + pViewports[0].m_flMaxZ = m_DesiredState.m_Viewport.MaxZ; + return 1; +} + + +//----------------------------------------------------------------------------- +// Flushes buffered primitives +//----------------------------------------------------------------------------- +void CShaderAPIDx8::FlushBufferedPrimitives( ) +{ + if ( ShaderUtil() ) + { + if ( !ShaderUtil()->OnFlushBufferedPrimitives() ) + { + return; + } + } + FlushBufferedPrimitivesInternal(); +} + +void CShaderAPIDx8::FlushBufferedPrimitivesInternal( ) +{ + LOCK_SHADERAPI(); + // This shouldn't happen in the inner rendering loop! + Assert( m_pRenderMesh == 0 ); + + // NOTE: We've gotta store off the matrix mode because + // it'll get reset by the default state application caused by the flush + int tempStack = m_CurrStack; + D3DTRANSFORMSTATETYPE tempMatrixMode = m_MatrixMode; + + MeshMgr()->Flush(); + + m_CurrStack = tempStack; + m_MatrixMode = tempMatrixMode; +} + + +//----------------------------------------------------------------------------- +// Flush the hardware +//----------------------------------------------------------------------------- +void CShaderAPIDx8::FlushHardware( ) +{ + LOCK_SHADERAPI(); + FlushBufferedPrimitives(); + + Dx9Device()->EndScene(); + + DiscardVertexBuffers(); + + Dx9Device()->BeginScene(); + + ForceHardwareSync(); +} + + + +//----------------------------------------------------------------------------- +// Deal with device lost (alt-tab) +//----------------------------------------------------------------------------- +void CShaderAPIDx8::HandleDeviceLost() +{ + if ( IsX360() ) + { + return; + } + + LOCK_SHADERAPI(); + + if ( !IsActive() ) + return; + + // need to flush the dynamic buffer + FlushBufferedPrimitives(); + + if ( !IsDeactivated() ) + { + Dx9Device()->EndScene(); + } + + CheckDeviceLost( m_bOtherAppInitializing ); + + if ( !IsDeactivated() ) + { + Dx9Device()->BeginScene(); + } +} + +//----------------------------------------------------------------------------- +// Buffer clear color +//----------------------------------------------------------------------------- +void CShaderAPIDx8::ClearColor3ub( unsigned char r, unsigned char g, unsigned char b ) +{ + LOCK_SHADERAPI(); + float a = 255;//(r * 0.30f + g * 0.59f + b * 0.11f) / MAX_HDR_OVERBRIGHT; + + // GR - need to force alpha to black for HDR + m_DynamicState.m_ClearColor = D3DCOLOR_ARGB((unsigned char)a,r,g,b); +} + +void CShaderAPIDx8::ClearColor4ub( unsigned char r, unsigned char g, unsigned char b, unsigned char a ) +{ + LOCK_SHADERAPI(); + m_DynamicState.m_ClearColor = D3DCOLOR_ARGB(a,r,g,b); +} + +// Converts the clear color to be appropriate for HDR +D3DCOLOR CShaderAPIDx8::GetActualClearColor( D3DCOLOR clearColor ) +{ + bool bConvert = !IsX360() && m_TransitionTable.CurrentState().m_bLinearColorSpaceFrameBufferEnable; + +#if defined( _X360 ) + // The PC disables SRGBWrite when clearing so that the clear color won't get gamma converted + // The 360 cannot disable that state, and thus compensates for the sRGB conversion + // the desired result is the clear color written to the RT as-is + if ( clearColor & D3DCOLOR_ARGB( 0, 255, 255, 255 ) ) + { + IDirect3DSurface *pRTSurface = NULL; + Dx9Device()->GetRenderTarget( 0, &pRTSurface ); + if ( pRTSurface ) + { + D3DSURFACE_DESC desc; + HRESULT hr = pRTSurface->GetDesc( &desc ); + if ( !FAILED( hr ) && IS_D3DFORMAT_SRGB( desc.Format ) ) + { + bConvert = true; + } + pRTSurface->Release(); + } + } +#endif + + if ( bConvert ) + { + // HDRFIXME: need to make sure this works this way. + // HDRFIXME: Is there a helper function that'll do this easier? + // convert clearColor from gamma to linear since our frame buffer is linear. + Vector vecGammaColor; + vecGammaColor.x = ( 1.0f / 255.0f ) * ( ( clearColor >> 16 ) & 0xff ); + vecGammaColor.y = ( 1.0f / 255.0f ) * ( ( clearColor >> 8 ) & 0xff ); + vecGammaColor.z = ( 1.0f / 255.0f ) * ( clearColor & 0xff ); + Vector vecLinearColor; + vecLinearColor.x = GammaToLinear( vecGammaColor.x ); + vecLinearColor.y = GammaToLinear( vecGammaColor.y ); + vecLinearColor.z = GammaToLinear( vecGammaColor.z ); + clearColor &= D3DCOLOR_RGBA( 0, 0, 0, 255 ); + clearColor |= D3DCOLOR_COLORVALUE( vecLinearColor.x, vecLinearColor.y, vecLinearColor.z, 0.0f ); + } + + return clearColor; +} + + +//----------------------------------------------------------------------------- +// Clear buffers while obeying stencil +//----------------------------------------------------------------------------- +void CShaderAPIDx8::ClearBuffersObeyStencil( bool bClearColor, bool bClearDepth ) +{ + //copy the clear color bool into the clear alpha bool + ClearBuffersObeyStencilEx( bClearColor, bClearColor, bClearDepth ); +} + +void CShaderAPIDx8::ClearBuffersObeyStencilEx( bool bClearColor, bool bClearAlpha, bool bClearDepth ) +{ + LOCK_SHADERAPI(); + + if ( !bClearColor && !bClearAlpha && !bClearDepth ) + return; + + FlushBufferedPrimitives(); + + // Before clearing can happen, user clip planes must be disabled + SetRenderState( D3DRS_CLIPPLANEENABLE, 0 ); + + D3DCOLOR clearColor = GetActualClearColor( m_DynamicState.m_ClearColor ); + + unsigned char r, g, b, a; + b = clearColor& 0xFF; + g = ( clearColor >> 8 ) & 0xFF; + r = ( clearColor >> 16 ) & 0xFF; + a = ( clearColor >> 24 ) & 0xFF; + + ShaderUtil()->DrawClearBufferQuad( r, g, b, a, bClearColor, bClearAlpha, bClearDepth ); + + // Reset user clip plane state + FlushBufferedPrimitives(); + SetRenderState( D3DRS_CLIPPLANEENABLE, m_DynamicState.m_UserClipPlaneEnabled ); +} + +//------------------------------------------------------------------------- +//Perform stencil operations to every pixel on the screen +//------------------------------------------------------------------------- +void CShaderAPIDx8::PerformFullScreenStencilOperation( void ) +{ + LOCK_SHADERAPI(); + + FlushBufferedPrimitives(); + + // We'll be drawing a large quad in altered worldspace, user clip planes must be disabled + SetRenderStateConstMacro( this, D3DRS_CLIPPLANEENABLE, 0 ); + + ShaderUtil()->DrawClearBufferQuad( 0, 0, 0, 0, false, false, false ); + + // Reset user clip plane state + FlushBufferedPrimitives(); + SetRenderStateConstMacro( this, D3DRS_CLIPPLANEENABLE, m_DynamicState.m_UserClipPlaneEnabled ); +} + + +//----------------------------------------------------------------------------- +// Buffer clear +//----------------------------------------------------------------------------- +void CShaderAPIDx8::ClearBuffers( bool bClearColor, bool bClearDepth, bool bClearStencil, int renderTargetWidth, int renderTargetHeight ) +{ + LOCK_SHADERAPI(); + if ( ShaderUtil()->GetConfig().m_bSuppressRendering ) + return; + + if ( IsDeactivated() ) + return; + + // State changed... need to flush the dynamic buffer + FlushBufferedPrimitives(); + CallCommitFuncs( COMMIT_PER_DRAW, true ); + + float depth = (ShaderUtil()->GetConfig().bReverseDepth ^ ReverseDepthOnX360()) ? 0.0f : 1.0f; + DWORD mask = 0; + + if ( bClearColor ) + { + mask |= D3DCLEAR_TARGET; + } + + if ( bClearDepth ) + { + mask |= D3DCLEAR_ZBUFFER; + } + + if ( bClearStencil && m_bUsingStencil ) + { + mask |= D3DCLEAR_STENCIL; + } + + // Only clear the current view... right!??! + D3DRECT clear; + clear.x1 = m_DesiredState.m_Viewport.X; + clear.y1 = m_DesiredState.m_Viewport.Y; + clear.x2 = clear.x1 + m_DesiredState.m_Viewport.Width; + clear.y2 = clear.y1 + m_DesiredState.m_Viewport.Height; + + // SRGBWrite is disabled when clearing so that the clear color won't get gamma converted + bool bSRGBWriteEnable = false; + if ( !IsX360() && bClearColor && m_TransitionTable.CurrentShadowState() ) + { + bSRGBWriteEnable = m_TransitionTable.CurrentShadowState()->m_SRGBWriteEnable; + } + +#if !defined( _X360 ) + if ( bSRGBWriteEnable ) + { + // This path used to be !IsPosix(), but this makes no sense and causes the clear color to differ in D3D9 vs. GL. + Dx9Device()->SetRenderState( D3DRS_SRGBWRITEENABLE, 0 ); + } +#endif + + D3DCOLOR clearColor = GetActualClearColor( m_DynamicState.m_ClearColor ); + + if ( mask != 0 ) + { + bool bRenderTargetMatchesViewport = + ( renderTargetWidth == -1 && renderTargetHeight == -1 ) || + ( m_DesiredState.m_Viewport.Width == -1 && m_DesiredState.m_Viewport.Height == -1 ) || + ( renderTargetWidth == ( int )m_DesiredState.m_Viewport.Width && + renderTargetHeight == ( int )m_DesiredState.m_Viewport.Height ); + + if ( bRenderTargetMatchesViewport ) + { + RECORD_COMMAND( DX8_CLEAR, 6 ); + RECORD_INT( 0 ); + RECORD_STRUCT( &clear, sizeof(clear) ); + RECORD_INT( mask ); + RECORD_INT( clearColor ); + RECORD_FLOAT( depth ); + RECORD_INT( 0 ); + + Dx9Device()->Clear( 0, NULL, mask, clearColor, depth, 0L ); + } + else + { + RECORD_COMMAND( DX8_CLEAR, 6 ); + RECORD_INT( 0 ); + RECORD_STRUCT( &clear, sizeof(clear) ); + RECORD_INT( mask ); + RECORD_INT( clearColor ); + RECORD_FLOAT( depth ); + RECORD_INT( 0 ); + + Dx9Device()->Clear( 1, &clear, mask, clearColor, depth, 0L ); + } + } + + // Restore state + if ( bSRGBWriteEnable ) + { + // sRGBWriteEnable shouldn't be true if we have no shadow state. . . Assert just in case. + Assert( m_TransitionTable.CurrentShadowState() ); + m_TransitionTable.ApplySRGBWriteEnable( *m_TransitionTable.CurrentShadowState() ); + } +} + + +//----------------------------------------------------------------------------- +// Bind +//----------------------------------------------------------------------------- +void CShaderAPIDx8::BindVertexShader( VertexShaderHandle_t hVertexShader ) +{ + ShaderManager()->BindVertexShader( hVertexShader ); +} + +void CShaderAPIDx8::BindGeometryShader( GeometryShaderHandle_t hGeometryShader ) +{ + Assert( hGeometryShader == GEOMETRY_SHADER_HANDLE_INVALID ); +} + +void CShaderAPIDx8::BindPixelShader( PixelShaderHandle_t hPixelShader ) +{ + ShaderManager()->BindPixelShader( hPixelShader ); +} + + +//----------------------------------------------------------------------------- +// Returns a copy of the front buffer +//----------------------------------------------------------------------------- +IDirect3DSurface* CShaderAPIDx8::GetFrontBufferImage( ImageFormat& format ) +{ +#if !defined( _X360 ) + // need to flush the dynamic buffer and make sure the entire image is there + FlushBufferedPrimitives(); + + int w, h; + GetBackBufferDimensions( w, h ); + + HRESULT hr; + IDirect3DSurface *pFullScreenSurfaceBits = 0; + hr = Dx9Device()->CreateOffscreenPlainSurface( w, h, + D3DFMT_A8R8G8B8, D3DPOOL_SCRATCH, &pFullScreenSurfaceBits, NULL ); + if (FAILED(hr)) + return 0; + + hr = Dx9Device()->GetFrontBufferData( 0, pFullScreenSurfaceBits ); + if (FAILED(hr)) + return 0; + + int windowWidth, windowHeight; + GetWindowSize( windowWidth, windowHeight ); + + IDirect3DSurface *pSurfaceBits = 0; + hr = Dx9Device()->CreateOffscreenPlainSurface( windowWidth, windowHeight, + D3DFMT_A8R8G8B8, D3DPOOL_SCRATCH, &pSurfaceBits, NULL ); + Assert( hr == D3D_OK ); + + POINT pnt; + pnt.x = pnt.y = 0; +#ifdef _WIN32 + BOOL result = ClientToScreen( ( HWND )m_hWnd, &pnt ); +#else + BOOL result = ClientToScreen( (VD3DHWND)m_hWnd, &pnt ); +#endif + Assert( result ); + + RECT srcRect; + srcRect.left = pnt.x; + srcRect.top = pnt.y; + srcRect.right = pnt.x + windowWidth; + srcRect.bottom = pnt.y + windowHeight; + + POINT dstPnt; + dstPnt.x = dstPnt.y = 0; + + D3DLOCKED_RECT lockedSrcRect; + hr = pFullScreenSurfaceBits->LockRect( &lockedSrcRect, &srcRect, D3DLOCK_READONLY ); + Assert( hr == D3D_OK ); + + D3DLOCKED_RECT lockedDstRect; + hr = pSurfaceBits->LockRect( &lockedDstRect, NULL, 0 ); + Assert( hr == D3D_OK ); + + int i; + for( i = 0; i < windowHeight; i++ ) + { + memcpy( ( unsigned char * )lockedDstRect.pBits + ( i * lockedDstRect.Pitch ), + ( unsigned char * )lockedSrcRect.pBits + ( i * lockedSrcRect.Pitch ), + windowWidth * 4 ); // hack . . what if this is a different format? + } + hr = pSurfaceBits->UnlockRect(); + Assert( hr == D3D_OK ); + hr = pFullScreenSurfaceBits->UnlockRect(); + Assert( hr == D3D_OK ); + + pFullScreenSurfaceBits->Release(); + + format = ImageLoader::D3DFormatToImageFormat( D3DFMT_A8R8G8B8 ); + return pSurfaceBits; +#else + Assert( 0 ); + return NULL; +#endif +} + + +//----------------------------------------------------------------------------- +// Lets the shader know about the full-screen texture so it can +//----------------------------------------------------------------------------- +void CShaderAPIDx8::SetFullScreenTextureHandle( ShaderAPITextureHandle_t h ) +{ + LOCK_SHADERAPI(); + m_hFullScreenTexture = h; +} + + +//----------------------------------------------------------------------------- +// Lets the shader know about the full-screen texture so it can +//----------------------------------------------------------------------------- +void CShaderAPIDx8::SetLinearToGammaConversionTextures( ShaderAPITextureHandle_t hSRGBWriteEnabledTexture, ShaderAPITextureHandle_t hIdentityTexture ) +{ + LOCK_SHADERAPI(); + + m_hLinearToGammaTableTexture = hSRGBWriteEnabledTexture; + m_hLinearToGammaTableIdentityTexture = hIdentityTexture; +} + +//----------------------------------------------------------------------------- +// Returns a copy of the back buffer +//----------------------------------------------------------------------------- +IDirect3DSurface* CShaderAPIDx8::GetBackBufferImageHDR( Rect_t *pSrcRect, Rect_t *pDstRect, ImageFormat& format ) +{ +#if !defined( _X360 ) + HRESULT hr; + IDirect3DSurface *pSurfaceBits = 0; + IDirect3DSurface *pTmpSurface = NULL; + + // Get the back buffer + IDirect3DSurface* pBackBuffer; + hr = Dx9Device()->GetRenderTarget( 0, &pBackBuffer ); + if (FAILED(hr)) + return 0; + + // Find about its size and format + D3DSURFACE_DESC desc; + D3DTEXTUREFILTERTYPE filter; + + hr = pBackBuffer->GetDesc( &desc ); + if (FAILED(hr)) + goto CleanUp; + + filter = ((pDstRect->width != pSrcRect->width) || (pDstRect->height != pSrcRect->height)) ? D3DTEXF_LINEAR : D3DTEXF_NONE; + + if ( ( pDstRect->x + pDstRect->width <= SMALL_BACK_BUFFER_SURFACE_WIDTH ) && + ( pDstRect->y + pDstRect->height <= SMALL_BACK_BUFFER_SURFACE_HEIGHT ) ) + { + if (!m_pSmallBackBufferFP16TempSurface) + { + hr = Dx9Device()->CreateRenderTarget( + SMALL_BACK_BUFFER_SURFACE_WIDTH, SMALL_BACK_BUFFER_SURFACE_HEIGHT, + desc.Format, D3DMULTISAMPLE_NONE, 0, TRUE, &m_pSmallBackBufferFP16TempSurface, + NULL ); + } + pTmpSurface = m_pSmallBackBufferFP16TempSurface; +#if POSIX + pTmpSurface->AddRef( 0, "CShaderAPIDx8::GetBackBufferImageHDR public addref"); +#else + pTmpSurface->AddRef(); +#endif + + desc.Width = SMALL_BACK_BUFFER_SURFACE_WIDTH; + desc.Height = SMALL_BACK_BUFFER_SURFACE_HEIGHT; + + RECT srcRect, destRect; + RectToRECT( pSrcRect, srcRect ); + RectToRECT( pDstRect, destRect ); + hr = Dx9Device()->StretchRect( pBackBuffer, &srcRect, pTmpSurface, &destRect, filter ); + if ( FAILED(hr) ) + goto CleanUp; + } + else + { + // Normally we would only have to create a separate render target here and StretchBlt to it first + // if AA was enabled, but certain machines/drivers get reboots if we do GetRenderTargetData + // straight off the backbuffer. + hr = Dx9Device()->CreateRenderTarget( desc.Width, desc.Height, desc.Format, + D3DMULTISAMPLE_NONE, 0, TRUE, &pTmpSurface, NULL ); + if ( FAILED(hr) ) + goto CleanUp; + + hr = Dx9Device()->StretchRect( pBackBuffer, NULL, pTmpSurface, NULL, filter ); + if ( FAILED(hr) ) + goto CleanUp; + } + + // Create a buffer the same size and format + hr = Dx9Device()->CreateOffscreenPlainSurface( desc.Width, desc.Height, + desc.Format, D3DPOOL_SYSTEMMEM, &pSurfaceBits, NULL ); + if (FAILED(hr)) + goto CleanUp; + + // Blit from the back buffer to our scratch buffer + hr = Dx9Device()->GetRenderTargetData( pTmpSurface ? pTmpSurface : pBackBuffer, pSurfaceBits ); + if (FAILED(hr)) + goto CleanUp2; + + format = ImageLoader::D3DFormatToImageFormat(desc.Format); + if ( pTmpSurface ) + { + pTmpSurface->Release(); + } + pBackBuffer->Release(); + return pSurfaceBits; + +CleanUp2: + pSurfaceBits->Release(); + +CleanUp: + if ( pTmpSurface ) + { + pTmpSurface->Release(); + } + + pBackBuffer->Release(); +#else + Assert( 0 ); +#endif + return 0; +} + + +//----------------------------------------------------------------------------- +// Returns a copy of the back buffer +//----------------------------------------------------------------------------- +IDirect3DSurface* CShaderAPIDx8::GetBackBufferImage( Rect_t *pSrcRect, Rect_t *pDstRect, ImageFormat& format ) +{ +#if !defined( _X360 ) + if ( !m_pBackBufferSurface || ( m_hFullScreenTexture == INVALID_SHADERAPI_TEXTURE_HANDLE ) ) + return NULL; + + HRESULT hr; + D3DSURFACE_DESC desc; + + FlushBufferedPrimitives(); + + // Get the current render target + IDirect3DSurface* pRenderTarget; + hr = Dx9Device()->GetRenderTarget( 0, &pRenderTarget ); + if (FAILED(hr)) + return 0; + + // Find about its size and format + hr = pRenderTarget->GetDesc( &desc ); + + if ( desc.Format == D3DFMT_A16B16G16R16F || desc.Format == D3DFMT_A32B32G32R32F ) + return GetBackBufferImageHDR( pSrcRect, pDstRect, format ); + + IDirect3DSurface *pSurfaceBits = NULL; + IDirect3DSurface *pTmpSurface = NULL; + int nRenderTargetRefCount; + nRenderTargetRefCount = 0; + + if ( (desc.MultiSampleType == D3DMULTISAMPLE_NONE) && (pRenderTarget != m_pBackBufferSurface) && + (pSrcRect->width == pDstRect->width) && (pSrcRect->height == pDstRect->height) ) + { + // Don't bother to blit through the full-screen texture if we don't + // have to stretch, we're not coming from the backbuffer, and we don't have to do AA resolve + pTmpSurface = pRenderTarget; +#if POSIX + pTmpSurface->AddRef( 0, "CShaderAPIDx8::GetBackBufferImage public addref"); +#else + pTmpSurface->AddRef(); +#endif + } + else + { + Texture_t *pTex = &GetTexture( m_hFullScreenTexture ); + IDirect3DTexture* pFullScreenTexture = (IDirect3DTexture*)pTex->GetTexture(); + + D3DTEXTUREFILTERTYPE filter = ((pDstRect->width != pSrcRect->width) || (pDstRect->height != pSrcRect->height)) ? D3DTEXF_LINEAR : D3DTEXF_NONE; + + hr = pFullScreenTexture->GetSurfaceLevel( 0, &pTmpSurface ); + if ( FAILED(hr) ) + goto CleanUp; + + if ( pTmpSurface == pRenderTarget ) + { + Warning( "Can't blit from full-sized offscreen buffer!\n" ); + goto CleanUp; + } + + RECT srcRect, destRect; + srcRect.left = pSrcRect->x; srcRect.right = pSrcRect->x + pSrcRect->width; + srcRect.top = pSrcRect->y; srcRect.bottom = pSrcRect->y + pSrcRect->height; + srcRect.left = clamp( srcRect.left, 0, (int)desc.Width ); + srcRect.right = clamp( srcRect.right, 0, (int)desc.Width ); + srcRect.top = clamp( srcRect.top, 0, (int)desc.Height ); + srcRect.bottom = clamp( srcRect.bottom, 0, (int)desc.Height ); + + destRect.left = pDstRect->x ; destRect.right = pDstRect->x + pDstRect->width; + destRect.top = pDstRect->y; destRect.bottom = pDstRect->y + pDstRect->height; + destRect.left = clamp( destRect.left, 0, (int)desc.Width ); + destRect.right = clamp( destRect.right, 0, (int)desc.Width ); + destRect.top = clamp( destRect.top, 0, (int)desc.Height ); + destRect.bottom = clamp( destRect.bottom, 0, (int)desc.Height ); + + hr = Dx9Device()->StretchRect( pRenderTarget, &srcRect, pTmpSurface, &destRect, filter ); + if ( FAILED(hr) ) + { + AssertOnce( "Error resizing pixels!\n" ); + goto CleanUp; + } + } + + D3DSURFACE_DESC tmpDesc; + hr = pTmpSurface->GetDesc( &tmpDesc ); + Assert( !FAILED(hr) ); + + // Create a buffer the same size and format + hr = Dx9Device()->CreateOffscreenPlainSurface( tmpDesc.Width, tmpDesc.Height, + desc.Format, D3DPOOL_SYSTEMMEM, &pSurfaceBits, NULL ); + if ( FAILED(hr) ) + { + AssertOnce( "Error creating offscreen surface!\n" ); + goto CleanUp; + } + + // Blit from the back buffer to our scratch buffer + hr = Dx9Device()->GetRenderTargetData( pTmpSurface, pSurfaceBits ); + if ( FAILED(hr) ) + { + AssertOnce( "Error copying bits into the offscreen surface!\n" ); + goto CleanUp; + } + + format = ImageLoader::D3DFormatToImageFormat( desc.Format ); + + pTmpSurface->Release(); +#ifdef _DEBUG + nRenderTargetRefCount = +#endif + pRenderTarget->Release(); + AssertOnce( nRenderTargetRefCount == 1 ); + return pSurfaceBits; + +CleanUp: + if ( pSurfaceBits ) + { + pSurfaceBits->Release(); + } + + if ( pTmpSurface ) + { + pTmpSurface->Release(); + } +#else + Assert( 0 ); +#endif + + return 0; +} + + +//----------------------------------------------------------------------------- +// Copy bits from a host-memory surface +//----------------------------------------------------------------------------- +void CShaderAPIDx8::CopyBitsFromHostSurface( IDirect3DSurface* pSurfaceBits, + const Rect_t &dstRect, unsigned char *pData, ImageFormat srcFormat, ImageFormat dstFormat, int nDstStride ) +{ + // Copy out the bits... + RECT rect; + rect.left = dstRect.x; + rect.right = dstRect.x + dstRect.width; + rect.top = dstRect.y; + rect.bottom = dstRect.y + dstRect.height; + + D3DLOCKED_RECT lockedRect; + HRESULT hr; + int flags = D3DLOCK_READONLY | D3DLOCK_NOSYSLOCK; + + tmZone( TELEMETRY_LEVEL1, TMZF_NONE, "%s", __FUNCTION__ ); + + hr = pSurfaceBits->LockRect( &lockedRect, &rect, flags ); + if ( !FAILED( hr ) ) + { + unsigned char *pImage = (unsigned char *)lockedRect.pBits; + ShaderUtil()->ConvertImageFormat( (unsigned char *)pImage, srcFormat, + pData, dstFormat, dstRect.width, dstRect.height, lockedRect.Pitch, nDstStride ); + + hr = pSurfaceBits->UnlockRect( ); + } +} + + +//----------------------------------------------------------------------------- +// Reads from the current read buffer + stretches +//----------------------------------------------------------------------------- +void CShaderAPIDx8::ReadPixels( Rect_t *pSrcRect, Rect_t *pDstRect, unsigned char *pData, ImageFormat dstFormat, int nDstStride ) +{ + LOCK_SHADERAPI(); + Assert( pDstRect ); + + if ( IsPC() || !IsX360() ) + { + Rect_t srcRect; + if ( !pSrcRect ) + { + srcRect.x = srcRect.y = 0; + srcRect.width = m_nWindowWidth; + srcRect.height = m_nWindowHeight; + pSrcRect = &srcRect; + } + + ImageFormat format; + IDirect3DSurface* pSurfaceBits = GetBackBufferImage( pSrcRect, pDstRect, format ); + if ( pSurfaceBits ) + { + CopyBitsFromHostSurface( pSurfaceBits, *pDstRect, pData, format, dstFormat, nDstStride ); + + // Release the temporary surface + pSurfaceBits->Release(); + } + } + else + { +#if defined( _X360 ) + // 360 requires material system to handle due to RT complexities + ShaderUtil()->ReadBackBuffer( pSrcRect, pDstRect, pData, dstFormat, nDstStride ); +#endif + } +} + + +//----------------------------------------------------------------------------- +// Reads from the current read buffer +//----------------------------------------------------------------------------- +void CShaderAPIDx8::ReadPixels( int x, int y, int width, int height, unsigned char *pData, ImageFormat dstFormat ) +{ + Rect_t rect; + rect.x = x; + rect.y = y; + rect.width = width; + rect.height = height; + + if ( IsPC() || !IsX360() ) + { + ImageFormat format; + IDirect3DSurface* pSurfaceBits = GetBackBufferImage( &rect, &rect, format ); + if (pSurfaceBits) + { + CopyBitsFromHostSurface( pSurfaceBits, rect, pData, format, dstFormat, 0 ); + + // Release the temporary surface + pSurfaceBits->Release(); + } + } + else + { +#if defined( _X360 ) + // 360 requires material system to handle due to RT complexities + ShaderUtil()->ReadBackBuffer( &rect, &rect, pData, dstFormat, 0 ); +#endif + } +} + + +//----------------------------------------------------------------------------- +// Binds a particular material to render with +//----------------------------------------------------------------------------- +void CShaderAPIDx8::Bind( IMaterial* pMaterial ) +{ + LOCK_SHADERAPI(); + IMaterialInternal* pMatInt = static_cast( pMaterial ); + + bool bMaterialChanged; + if ( m_pMaterial && pMatInt && m_pMaterial->InMaterialPage() && pMatInt->InMaterialPage() ) + { + bMaterialChanged = ( m_pMaterial->GetMaterialPage() != pMatInt->GetMaterialPage() ); + } + else + { + bMaterialChanged = ( m_pMaterial != pMatInt ) || ( m_pMaterial && m_pMaterial->InMaterialPage() ) || ( pMatInt && pMatInt->InMaterialPage() ); + } + + if ( bMaterialChanged ) + { + FlushBufferedPrimitives(); +#ifdef RECORDING + RECORD_DEBUG_STRING( ( char * )pMaterial->GetName() ); + IShader *pShader = pMatInt->GetShader(); + if( pShader && pShader->GetName() ) + { + RECORD_DEBUG_STRING( pShader->GetName() ); + } + else + { + RECORD_DEBUG_STRING( "" ); + } +#endif + m_pMaterial = pMatInt; + +#if ( defined( PIX_INSTRUMENTATION ) || defined( NVPERFHUD ) ) + PIXifyName( s_pPIXMaterialName, sizeof( s_pPIXMaterialName ), m_pMaterial->GetName() ); +#endif + } +} + +// Get the currently bound material +IMaterialInternal* CShaderAPIDx8::GetBoundMaterial() +{ + return m_pMaterial; +} + + +//----------------------------------------------------------------------------- +// Binds a standard texture +//----------------------------------------------------------------------------- +void CShaderAPIDx8::BindStandardTexture( Sampler_t sampler, StandardTextureId_t id ) +{ + if ( m_StdTextureHandles[id] != INVALID_SHADERAPI_TEXTURE_HANDLE ) + { + BindTexture( sampler, m_StdTextureHandles[id] ); + } + else + { + ShaderUtil()->BindStandardTexture( sampler, id ); + } +} + +void CShaderAPIDx8::BindStandardVertexTexture( VertexTextureSampler_t sampler, StandardTextureId_t id ) +{ + ShaderUtil()->BindStandardVertexTexture( sampler, id ); +} + +void CShaderAPIDx8::GetStandardTextureDimensions( int *pWidth, int *pHeight, StandardTextureId_t id ) +{ + ShaderUtil()->GetStandardTextureDimensions( pWidth, pHeight, id ); +} + + +//----------------------------------------------------------------------------- +// Gets the lightmap dimensions +//----------------------------------------------------------------------------- +void CShaderAPIDx8::GetLightmapDimensions( int *w, int *h ) +{ + ShaderUtil()->GetLightmapDimensions( w, h ); +} + + +//----------------------------------------------------------------------------- +// Selection mode methods +//----------------------------------------------------------------------------- +int CShaderAPIDx8::SelectionMode( bool selectionMode ) +{ + LOCK_SHADERAPI(); + int numHits = m_NumHits; + if (m_InSelectionMode) + { + WriteHitRecord(); + } + m_InSelectionMode = selectionMode; + m_pCurrSelectionRecord = m_pSelectionBuffer; + m_NumHits = 0; + return numHits; +} + +bool CShaderAPIDx8::IsInSelectionMode() const +{ + return m_InSelectionMode; +} + +void CShaderAPIDx8::SelectionBuffer( unsigned int* pBuffer, int size ) +{ + LOCK_SHADERAPI(); + Assert( !m_InSelectionMode ); + Assert( pBuffer && size ); + m_pSelectionBufferEnd = pBuffer + size; + m_pSelectionBuffer = pBuffer; + m_pCurrSelectionRecord = pBuffer; +} + +void CShaderAPIDx8::ClearSelectionNames( ) +{ + LOCK_SHADERAPI(); + if (m_InSelectionMode) + { + WriteHitRecord(); + } + m_SelectionNames.Clear(); +} + +void CShaderAPIDx8::LoadSelectionName( int name ) +{ + LOCK_SHADERAPI(); + if (m_InSelectionMode) + { + WriteHitRecord(); + Assert( m_SelectionNames.Count() > 0 ); + m_SelectionNames.Top() = name; + } +} + +void CShaderAPIDx8::PushSelectionName( int name ) +{ + LOCK_SHADERAPI(); + if (m_InSelectionMode) + { + WriteHitRecord(); + m_SelectionNames.Push(name); + } +} + +void CShaderAPIDx8::PopSelectionName() +{ + LOCK_SHADERAPI(); + if (m_InSelectionMode) + { + WriteHitRecord(); + m_SelectionNames.Pop(); + } +} + +void CShaderAPIDx8::WriteHitRecord( ) +{ + FlushBufferedPrimitives(); + + if (m_SelectionNames.Count() && (m_SelectionMinZ != FLT_MAX)) + { + Assert( m_pCurrSelectionRecord + m_SelectionNames.Count() + 3 < m_pSelectionBufferEnd ); + *m_pCurrSelectionRecord++ = m_SelectionNames.Count(); + // NOTE: because of rounding, "(uint32)(float)UINT32_MAX" yields zero(!), hence the use of doubles. + // [ ALSO: As of Nov 2011, VS2010 exhibits a debug build code-gen bug if we cast the result to int32 instead of uint32 ] + *m_pCurrSelectionRecord++ = (uint32)( 0.5 + m_SelectionMinZ*(double)((uint32)~0) ); + *m_pCurrSelectionRecord++ = (uint32)( 0.5 + m_SelectionMaxZ*(double)((uint32)~0) ); + for (int i = 0; i < m_SelectionNames.Count(); ++i) + { + *m_pCurrSelectionRecord++ = m_SelectionNames[i]; + } + + ++m_NumHits; + } + + m_SelectionMinZ = FLT_MAX; + m_SelectionMaxZ = FLT_MIN; +} + +// We hit somefin in selection mode +void CShaderAPIDx8::RegisterSelectionHit( float minz, float maxz ) +{ + if (minz < 0) + minz = 0; + if (maxz > 1) + maxz = 1; + if (m_SelectionMinZ > minz) + m_SelectionMinZ = minz; + if (m_SelectionMaxZ < maxz) + m_SelectionMaxZ = maxz; +} + +int CShaderAPIDx8::GetCurrentNumBones( void ) const +{ + return m_DynamicState.m_NumBones; +} + +bool CShaderAPIDx8::IsHWMorphingEnabled( ) const +{ + return m_DynamicState.m_bHWMorphingEnabled; +} + + +//----------------------------------------------------------------------------- +// Inserts the lighting block into the code +//----------------------------------------------------------------------------- + +// If you change the number of lighting combinations, change this enum +enum +{ + DX8_LIGHTING_COMBINATION_COUNT = 22, + DX9_LIGHTING_COMBINATION_COUNT = 35 +}; + +#define MAX_LIGHTS 4 + + +// NOTE: These should match g_lightType* in vsh_prep.pl! +static int g_DX8LightCombinations[][4] = +{ + // static ambient local1 local2 + + // This is a special case for no lighting at all. + { LIGHT_NONE, LIGHT_NONE, LIGHT_NONE, LIGHT_NONE }, + + // This is a special case so that we don't have to do the ambient cube + // when we only have static lighting + { LIGHT_STATIC, LIGHT_NONE, LIGHT_NONE, LIGHT_NONE }, + + { LIGHT_NONE, LIGHT_AMBIENTCUBE, LIGHT_NONE, LIGHT_NONE }, + { LIGHT_NONE, LIGHT_AMBIENTCUBE, LIGHT_SPOT, LIGHT_NONE }, + { LIGHT_NONE, LIGHT_AMBIENTCUBE, LIGHT_POINT, LIGHT_NONE }, + { LIGHT_NONE, LIGHT_AMBIENTCUBE, LIGHT_DIRECTIONAL, LIGHT_NONE }, + { LIGHT_NONE, LIGHT_AMBIENTCUBE, LIGHT_SPOT, LIGHT_SPOT }, + { LIGHT_NONE, LIGHT_AMBIENTCUBE, LIGHT_SPOT, LIGHT_POINT, }, + { LIGHT_NONE, LIGHT_AMBIENTCUBE, LIGHT_SPOT, LIGHT_DIRECTIONAL, }, + { LIGHT_NONE, LIGHT_AMBIENTCUBE, LIGHT_POINT, LIGHT_POINT, }, + { LIGHT_NONE, LIGHT_AMBIENTCUBE, LIGHT_POINT, LIGHT_DIRECTIONAL, }, + { LIGHT_NONE, LIGHT_AMBIENTCUBE, LIGHT_DIRECTIONAL, LIGHT_DIRECTIONAL, }, + + { LIGHT_STATIC, LIGHT_AMBIENTCUBE, LIGHT_NONE, LIGHT_NONE }, + { LIGHT_STATIC, LIGHT_AMBIENTCUBE, LIGHT_SPOT, LIGHT_NONE }, + { LIGHT_STATIC, LIGHT_AMBIENTCUBE, LIGHT_POINT, LIGHT_NONE }, + { LIGHT_STATIC, LIGHT_AMBIENTCUBE, LIGHT_DIRECTIONAL, LIGHT_NONE }, + { LIGHT_STATIC, LIGHT_AMBIENTCUBE, LIGHT_SPOT, LIGHT_SPOT }, + { LIGHT_STATIC, LIGHT_AMBIENTCUBE, LIGHT_SPOT, LIGHT_POINT, }, + { LIGHT_STATIC, LIGHT_AMBIENTCUBE, LIGHT_SPOT, LIGHT_DIRECTIONAL, }, + { LIGHT_STATIC, LIGHT_AMBIENTCUBE, LIGHT_POINT, LIGHT_POINT, }, + { LIGHT_STATIC, LIGHT_AMBIENTCUBE, LIGHT_POINT, LIGHT_DIRECTIONAL, }, + { LIGHT_STATIC, LIGHT_AMBIENTCUBE, LIGHT_DIRECTIONAL, LIGHT_DIRECTIONAL, } +}; + +// NOTE: These should match g_lightType* in vsh_prep.pl! +// They also correspond to the parallel g_LocalLightTypeXArray[] arrays in common_vs_fxc.h +static int g_DX9LightCombinations[][MAX_LIGHTS] = +{ + // local0 local1 local2 local3 + { LIGHT_NONE, LIGHT_NONE, LIGHT_NONE, LIGHT_NONE }, // Zero lights [ Combo 0] + + { LIGHT_SPOT, LIGHT_NONE, LIGHT_NONE, LIGHT_NONE }, // One light [ Combo 1] + { LIGHT_POINT, LIGHT_NONE, LIGHT_NONE, LIGHT_NONE }, + { LIGHT_DIRECTIONAL, LIGHT_NONE, LIGHT_NONE, LIGHT_NONE }, + + { LIGHT_SPOT, LIGHT_SPOT, LIGHT_NONE, LIGHT_NONE }, // Two lights [ Combo 4] + { LIGHT_SPOT, LIGHT_POINT, LIGHT_NONE, LIGHT_NONE }, + { LIGHT_SPOT, LIGHT_DIRECTIONAL, LIGHT_NONE, LIGHT_NONE }, + { LIGHT_POINT, LIGHT_POINT, LIGHT_NONE, LIGHT_NONE }, + { LIGHT_POINT, LIGHT_DIRECTIONAL, LIGHT_NONE, LIGHT_NONE }, + { LIGHT_DIRECTIONAL, LIGHT_DIRECTIONAL, LIGHT_NONE, LIGHT_NONE }, + + { LIGHT_SPOT, LIGHT_SPOT, LIGHT_SPOT, LIGHT_NONE }, // Three lights [ Combo 10] + { LIGHT_SPOT, LIGHT_SPOT, LIGHT_POINT, LIGHT_NONE }, + { LIGHT_SPOT, LIGHT_SPOT, LIGHT_DIRECTIONAL, LIGHT_NONE }, + { LIGHT_SPOT, LIGHT_POINT, LIGHT_POINT, LIGHT_NONE }, + { LIGHT_SPOT, LIGHT_POINT, LIGHT_DIRECTIONAL, LIGHT_NONE }, + { LIGHT_SPOT, LIGHT_DIRECTIONAL, LIGHT_DIRECTIONAL, LIGHT_NONE }, + { LIGHT_POINT, LIGHT_POINT, LIGHT_POINT, LIGHT_NONE }, + { LIGHT_POINT, LIGHT_POINT, LIGHT_DIRECTIONAL, LIGHT_NONE }, + { LIGHT_POINT, LIGHT_DIRECTIONAL, LIGHT_DIRECTIONAL, LIGHT_NONE }, + { LIGHT_DIRECTIONAL, LIGHT_DIRECTIONAL, LIGHT_DIRECTIONAL, LIGHT_NONE }, + + { LIGHT_SPOT, LIGHT_SPOT, LIGHT_SPOT, LIGHT_SPOT }, // Four lights [ Combo 20] + { LIGHT_SPOT, LIGHT_SPOT, LIGHT_SPOT, LIGHT_POINT }, + { LIGHT_SPOT, LIGHT_SPOT, LIGHT_SPOT, LIGHT_DIRECTIONAL }, + { LIGHT_SPOT, LIGHT_SPOT, LIGHT_POINT, LIGHT_POINT }, + { LIGHT_SPOT, LIGHT_SPOT, LIGHT_POINT, LIGHT_DIRECTIONAL }, + { LIGHT_SPOT, LIGHT_SPOT, LIGHT_DIRECTIONAL, LIGHT_DIRECTIONAL }, + { LIGHT_SPOT, LIGHT_POINT, LIGHT_POINT, LIGHT_POINT }, + { LIGHT_SPOT, LIGHT_POINT, LIGHT_POINT, LIGHT_DIRECTIONAL }, + { LIGHT_SPOT, LIGHT_POINT, LIGHT_DIRECTIONAL, LIGHT_DIRECTIONAL }, + { LIGHT_SPOT, LIGHT_DIRECTIONAL, LIGHT_DIRECTIONAL, LIGHT_DIRECTIONAL }, + { LIGHT_POINT, LIGHT_POINT, LIGHT_POINT, LIGHT_POINT }, + { LIGHT_POINT, LIGHT_POINT, LIGHT_POINT, LIGHT_DIRECTIONAL }, + { LIGHT_POINT, LIGHT_POINT, LIGHT_DIRECTIONAL, LIGHT_DIRECTIONAL }, + { LIGHT_POINT, LIGHT_DIRECTIONAL, LIGHT_DIRECTIONAL, LIGHT_DIRECTIONAL }, + { LIGHT_DIRECTIONAL, LIGHT_DIRECTIONAL, LIGHT_DIRECTIONAL, LIGHT_DIRECTIONAL } +}; + +// This is just for getting light combos for DX8 +// For DX9, use GetDX9LightState() +// It is up to the shader cpp files to use the right method +int CShaderAPIDx8::GetCurrentLightCombo( void ) const +{ + Assert( g_pHardwareConfig->Caps().m_nDXSupportLevel <= 81 ); + + Assert( m_DynamicState.m_NumLights <= 2 ); + + COMPILE_TIME_ASSERT( DX8_LIGHTING_COMBINATION_COUNT == + sizeof( g_DX8LightCombinations ) / sizeof( g_DX8LightCombinations[0] ) ); + + // hack . . do this a cheaper way. + bool bUseAmbientCube; + if( m_DynamicState.m_AmbientLightCube[0][0] == 0.0f && + m_DynamicState.m_AmbientLightCube[0][1] == 0.0f && + m_DynamicState.m_AmbientLightCube[0][2] == 0.0f && + m_DynamicState.m_AmbientLightCube[1][0] == 0.0f && + m_DynamicState.m_AmbientLightCube[1][1] == 0.0f && + m_DynamicState.m_AmbientLightCube[1][2] == 0.0f && + m_DynamicState.m_AmbientLightCube[2][0] == 0.0f && + m_DynamicState.m_AmbientLightCube[2][1] == 0.0f && + m_DynamicState.m_AmbientLightCube[2][2] == 0.0f && + m_DynamicState.m_AmbientLightCube[3][0] == 0.0f && + m_DynamicState.m_AmbientLightCube[3][1] == 0.0f && + m_DynamicState.m_AmbientLightCube[3][2] == 0.0f && + m_DynamicState.m_AmbientLightCube[4][0] == 0.0f && + m_DynamicState.m_AmbientLightCube[4][1] == 0.0f && + m_DynamicState.m_AmbientLightCube[4][2] == 0.0f && + m_DynamicState.m_AmbientLightCube[5][0] == 0.0f && + m_DynamicState.m_AmbientLightCube[5][1] == 0.0f && + m_DynamicState.m_AmbientLightCube[5][2] == 0.0f ) + { + bUseAmbientCube = false; + } + else + { + bUseAmbientCube = true; + } + + Assert( m_pRenderMesh ); + + const VertexShaderLightTypes_t *pLightType = m_DynamicState.m_LightType; + + if( m_DynamicState.m_NumLights == 0 && !bUseAmbientCube ) + { + if( m_pRenderMesh->HasColorMesh() ) + return 1; // special case for static lighting only + else + return 0; // special case for no lighting at all. + } + + int i; + // hack - skip the first two for now since we don't know if the ambient cube is needed or not. + for( i = 2; i < DX9_LIGHTING_COMBINATION_COUNT; ++i ) + { + int j; + for( j = 0; j < m_DynamicState.m_NumLights; ++j ) + { + if( pLightType[j] != g_DX8LightCombinations[i][j+2] ) + break; + } + if( j == m_DynamicState.m_NumLights ) + { + while( j < 2 ) + { + if (g_DX8LightCombinations[i][j+2] != LIGHT_NONE) + break; + ++j; + } + if( j == 2 ) + { + if( m_pRenderMesh->HasColorMesh() ) + { + return i + 10; + } + else + { + return i; + } + } + } + } + + // should never get here! + Assert( 0 ); + return 0; +} + +void CShaderAPIDx8::GetDX9LightState( LightState_t *state ) const +{ + // hack . . do this a cheaper way. + if( m_DynamicState.m_AmbientLightCube[0][0] == 0.0f && + m_DynamicState.m_AmbientLightCube[0][1] == 0.0f && + m_DynamicState.m_AmbientLightCube[0][2] == 0.0f && + m_DynamicState.m_AmbientLightCube[1][0] == 0.0f && + m_DynamicState.m_AmbientLightCube[1][1] == 0.0f && + m_DynamicState.m_AmbientLightCube[1][2] == 0.0f && + m_DynamicState.m_AmbientLightCube[2][0] == 0.0f && + m_DynamicState.m_AmbientLightCube[2][1] == 0.0f && + m_DynamicState.m_AmbientLightCube[2][2] == 0.0f && + m_DynamicState.m_AmbientLightCube[3][0] == 0.0f && + m_DynamicState.m_AmbientLightCube[3][1] == 0.0f && + m_DynamicState.m_AmbientLightCube[3][2] == 0.0f && + m_DynamicState.m_AmbientLightCube[4][0] == 0.0f && + m_DynamicState.m_AmbientLightCube[4][1] == 0.0f && + m_DynamicState.m_AmbientLightCube[4][2] == 0.0f && + m_DynamicState.m_AmbientLightCube[5][0] == 0.0f && + m_DynamicState.m_AmbientLightCube[5][1] == 0.0f && + m_DynamicState.m_AmbientLightCube[5][2] == 0.0f ) + { + state->m_bAmbientLight = false; + } + else + { + state->m_bAmbientLight = true; + } + + Assert( m_pRenderMesh ); + Assert( m_DynamicState.m_NumLights <= 4 ); + + if ( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + Assert( m_DynamicState.m_NumLights <= MAX_LIGHTS ); // 2b hardware gets four lights + } + else + { + Assert( m_DynamicState.m_NumLights <= (MAX_LIGHTS-2) ); // 2.0 hardware gets two less + } + +#ifdef OSX + state->m_nNumLights = MIN(MAX_NUM_LIGHTS,m_DynamicState.m_NumLights); +#else + state->m_nNumLights = m_DynamicState.m_NumLights; +#endif + + state->m_nNumLights = m_DynamicState.m_NumLights; + state->m_bStaticLightVertex = m_pRenderMesh->HasColorMesh(); + state->m_bStaticLightTexel = false; // For now +} + +MaterialFogMode_t CShaderAPIDx8::GetCurrentFogType( void ) const +{ + return m_DynamicState.m_SceneFog; +} + +void CShaderAPIDx8::RecordString( const char *pStr ) +{ + RECORD_STRING( pStr ); +} + +void CShaderAPIDx8::EvictManagedResourcesInternal() +{ + if ( IsX360() ) + return; + + if ( !ThreadOwnsDevice() || !ThreadInMainThread() ) + { + ShaderUtil()->OnThreadEvent( SHADER_THREAD_EVICT_RESOURCES ); + return; + } + if ( mat_debugalttab.GetBool() ) + { + Warning( "mat_debugalttab: CShaderAPIDx8::EvictManagedResourcesInternal\n" ); + } + +#if !defined( _X360 ) + if ( Dx9Device() ) + { + Dx9Device()->EvictManagedResources(); + } +#endif +} + +void CShaderAPIDx8::EvictManagedResources( void ) +{ + if ( IsX360() ) + { + return; + } + + LOCK_SHADERAPI(); + Assert(ThreadOwnsDevice()); + // Tell other material system applications to release resources + SendIPCMessage( EVICT_MESSAGE ); + EvictManagedResourcesInternal(); +} + +bool CShaderAPIDx8::IsDebugTextureListFresh( int numFramesAllowed /* = 1 */ ) +{ + return ( m_nDebugDataExportFrame <= m_CurrentFrame ) && ( m_nDebugDataExportFrame >= m_CurrentFrame - numFramesAllowed ); +} + +bool CShaderAPIDx8::SetDebugTextureRendering( bool bEnable ) +{ + bool bVal = m_bDebugTexturesRendering; + m_bDebugTexturesRendering = bEnable; + return bVal; +} + +void CShaderAPIDx8::EnableDebugTextureList( bool bEnable ) +{ + m_bEnableDebugTextureList = bEnable; +} + +void CShaderAPIDx8::EnableGetAllTextures( bool bEnable ) +{ + m_bDebugGetAllTextures = bEnable; +} + +KeyValues* CShaderAPIDx8::GetDebugTextureList() +{ + return m_pDebugTextureList; +} + +int CShaderAPIDx8::GetTextureMemoryUsed( TextureMemoryType eTextureMemory ) +{ + switch ( eTextureMemory ) + { + case MEMORY_BOUND_LAST_FRAME: + return m_nTextureMemoryUsedLastFrame; + case MEMORY_TOTAL_LOADED: + return m_nTextureMemoryUsedTotal; + case MEMORY_ESTIMATE_PICMIP_1: + return m_nTextureMemoryUsedPicMip1; + case MEMORY_ESTIMATE_PICMIP_2: + return m_nTextureMemoryUsedPicMip2; + default: + return 0; + } +} + + +// Allocate and delete query objects. +ShaderAPIOcclusionQuery_t CShaderAPIDx8::CreateOcclusionQueryObject( void ) +{ + // don't allow this on <80 because it falls back to wireframe in that case + if( m_DeviceSupportsCreateQuery == 0 || g_pHardwareConfig->Caps().m_nDXSupportLevel < 80 ) + return INVALID_SHADERAPI_OCCLUSION_QUERY_HANDLE; + + // While we're deactivated, m_OcclusionQueryObjects just holds NULL pointers. + // Create a dummy one here and let ReacquireResources create the actual D3D object. + if ( IsDeactivated() ) + return INVALID_SHADERAPI_OCCLUSION_QUERY_HANDLE; + + IDirect3DQuery9 *pQuery = NULL; + HRESULT hr = Dx9Device()->CreateQuery( D3DQUERYTYPE_OCCLUSION, &pQuery ); + return ( hr == D3D_OK ) ? (ShaderAPIOcclusionQuery_t)pQuery : INVALID_SHADERAPI_OCCLUSION_QUERY_HANDLE; +} + +void CShaderAPIDx8::DestroyOcclusionQueryObject( ShaderAPIOcclusionQuery_t handle ) +{ + IDirect3DQuery9 *pQuery = (IDirect3DQuery9 *)handle; + + int nRetVal = pQuery->Release(); + Assert( nRetVal == 0 ); +} + +// Bracket drawing with begin and end so that we can get counts next frame. +void CShaderAPIDx8::BeginOcclusionQueryDrawing( ShaderAPIOcclusionQuery_t handle ) +{ + IDirect3DQuery9 *pQuery = (IDirect3DQuery9 *)handle; + + HRESULT hResult = pQuery->Issue( D3DISSUE_BEGIN ); + Assert( hResult == D3D_OK ); +} + +void CShaderAPIDx8::EndOcclusionQueryDrawing( ShaderAPIOcclusionQuery_t handle ) +{ + IDirect3DQuery9 *pQuery = (IDirect3DQuery9 *)handle; + + HRESULT hResult = pQuery->Issue( D3DISSUE_END ); + Assert( hResult == D3D_OK ); +} + +// Get the number of pixels rendered between begin and end on an earlier frame. +// Calling this in the same frame is a huge perf hit! +int CShaderAPIDx8::OcclusionQuery_GetNumPixelsRendered( ShaderAPIOcclusionQuery_t handle, bool bFlush ) +{ + LOCK_SHADERAPI(); + IDirect3DQuery9 *pQuery = (IDirect3DQuery9 *)handle; + + tmZone( TELEMETRY_LEVEL1, TMZF_NONE, "%s", __FUNCTION__ ); + + DWORD nPixels; + HRESULT hResult = pQuery->GetData( &nPixels, sizeof( nPixels ), bFlush ? D3DGETDATA_FLUSH : 0 ); + + // This means that the query will not finish and resulted in an error, game should use + // the previous query's results and not reissue the query + if ( ( hResult == D3DERR_DEVICELOST ) || ( hResult == D3DERR_NOTAVAILABLE ) ) + return OCCLUSION_QUERY_RESULT_ERROR; + + // This means the query isn't finished yet, game will have to use the previous query's + // results and not reissue the query; wait for query to finish later. + if ( hResult == S_FALSE ) + return OCCLUSION_QUERY_RESULT_PENDING; + + // NOTE: This appears to work around a driver bug for ATI on Vista + if ( nPixels & 0x80000000 ) + { + nPixels = 0; + } + return nPixels; +} + + +void CShaderAPIDx8::SetPixelShaderFogParams( int reg, ShaderFogMode_t fogMode ) +{ + m_DelayedShaderConstants.iPixelShaderFogParams = reg; //save it off in case the ShaderFogMode_t disables fog. We only find out later. + float fogParams[4]; + + if( (GetPixelFogMode() != MATERIAL_FOG_NONE) && (fogMode != SHADER_FOGMODE_DISABLED) ) + { + float ooFogRange = 1.0f; + + float fStart = m_VertexShaderFogParams[0]; + float fEnd = m_VertexShaderFogParams[1]; + + // Check for divide by zero + if ( fEnd != fStart ) + { + ooFogRange = 1.0f / ( fEnd - fStart ); + } + + fogParams[0] = fStart * ooFogRange; // fogStart / ( fogEnd - fogStart ) + fogParams[1] = m_DynamicState.m_FogZ; // water height + fogParams[2] = clamp( m_flFogMaxDensity, 0.0f, 1.0f ); // Max fog density + fogParams[3] = ooFogRange; // 1 / ( fogEnd - fogStart ); + + if (GetPixelFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z) + { + // terms are unused for height fog, forcing 1.0 allows unified PS math + fogParams[0] = 0.0f; + fogParams[2] = 1.0f; + } + } + else + { + //emulating MATERIAL_FOG_NONE by setting the parameters so that CalcRangeFog() always returns 0. Gets rid of a dynamic combo across the ps2x set. + fogParams[0] = 0.0f; + fogParams[1] = m_DynamicState.m_FogZ; // water height + fogParams[2] = 1.0f; // Max fog density + fogParams[3] = 0.0f; + } + + // cFogEndOverFogRange, cFogOne, unused, cOOFogRange + SetPixelShaderConstant( reg, fogParams, 1 ); +} + +void CShaderAPIDx8::SetPixelShaderFogParams( int reg ) +{ + SetPixelShaderFogParams( reg, m_TransitionTable.CurrentShadowState()->m_FogMode ); +} + +void CShaderAPIDx8::SetFlashlightState( const FlashlightState_t &state, const VMatrix &worldToTexture ) +{ + LOCK_SHADERAPI(); + SetFlashlightStateEx( state, worldToTexture, NULL ); +} + +void CShaderAPIDx8::SetFlashlightStateEx( const FlashlightState_t &state, const VMatrix &worldToTexture, ITexture *pFlashlightDepthTexture ) +{ + LOCK_SHADERAPI(); + // fixme: do a test here. + FlushBufferedPrimitives(); + m_FlashlightState = state; + m_FlashlightWorldToTexture = worldToTexture; + m_pFlashlightDepthTexture = pFlashlightDepthTexture; + + if ( !g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + m_FlashlightState.m_bEnableShadows = false; + m_pFlashlightDepthTexture = NULL; + } +} + +const FlashlightState_t &CShaderAPIDx8::GetFlashlightState( VMatrix &worldToTexture ) const +{ + worldToTexture = m_FlashlightWorldToTexture; + return m_FlashlightState; +} + +const FlashlightState_t &CShaderAPIDx8::GetFlashlightStateEx( VMatrix &worldToTexture, ITexture **ppFlashlightDepthTexture ) const +{ + worldToTexture = m_FlashlightWorldToTexture; + *ppFlashlightDepthTexture = m_pFlashlightDepthTexture; + return m_FlashlightState; +} + +bool CShaderAPIDx8::SupportsMSAAMode( int nMSAAMode ) +{ + if ( IsX360() ) + { + return false; + } + + return ( D3D_OK == D3D()->CheckDeviceMultiSampleType( m_DisplayAdapter, m_DeviceType, + m_PresentParameters.BackBufferFormat, + m_PresentParameters.Windowed, + ComputeMultisampleType( nMSAAMode ), NULL ) ); +} + +bool CShaderAPIDx8::SupportsCSAAMode( int nNumSamples, int nQualityLevel ) +{ +#ifdef DX_TO_GL_ABSTRACTION + // GL_NV_framebuffer_multisample_coverage + return false; +#endif + + // Only nVidia does this kind of AA + if ( g_pHardwareConfig->Caps().m_VendorID != VENDORID_NVIDIA ) + return false; + + DWORD dwQualityLevels = 0; + HRESULT hr = D3D()->CheckDeviceMultiSampleType( m_DisplayAdapter, m_DeviceType, + m_PresentParameters.BackBufferFormat, + m_PresentParameters.Windowed, + ComputeMultisampleType( nNumSamples ), &dwQualityLevels ); + + return ( ( D3D_OK == hr ) && ( (int) dwQualityLevels >= nQualityLevel ) ); +} + +bool CShaderAPIDx8::SupportsShadowDepthTextures( void ) +{ + return g_pHardwareConfig->Caps().m_bSupportsShadowDepthTextures; +} + +bool CShaderAPIDx8::SupportsBorderColor( void ) const +{ + return g_pHardwareConfig->Caps().m_bSupportsBorderColor; +} + +bool CShaderAPIDx8::SupportsFetch4( void ) +{ + return IsPC() && g_pHardwareConfig->Caps().m_bSupportsFetch4; +} + +ImageFormat CShaderAPIDx8::GetShadowDepthTextureFormat( void ) +{ + return g_pHardwareConfig->Caps().m_ShadowDepthTextureFormat; +} + +ImageFormat CShaderAPIDx8::GetNullTextureFormat( void ) +{ + return g_pHardwareConfig->Caps().m_NullTextureFormat; +} + +void CShaderAPIDx8::SetShadowDepthBiasFactors( float fShadowSlopeScaleDepthBias, float fShadowDepthBias ) +{ + m_fShadowSlopeScaleDepthBias = fShadowSlopeScaleDepthBias; + m_fShadowDepthBias = fShadowDepthBias; +} + +void CShaderAPIDx8::ClearVertexAndPixelShaderRefCounts() +{ + LOCK_SHADERAPI(); + ShaderManager()->ClearVertexAndPixelShaderRefCounts(); +} + +void CShaderAPIDx8::PurgeUnusedVertexAndPixelShaders() +{ + LOCK_SHADERAPI(); + ShaderManager()->PurgeUnusedVertexAndPixelShaders(); +} + +bool CShaderAPIDx8::UsingSoftwareVertexProcessing() const +{ + return g_pHardwareConfig->Caps().m_bSoftwareVertexProcessing; +} + +ITexture *CShaderAPIDx8::GetRenderTargetEx( int nRenderTargetID ) +{ + return ShaderUtil()->GetRenderTargetEx( nRenderTargetID ); +} + +float CShaderAPIDx8::GetLightMapScaleFactor( void ) const +{ + switch( HardwareConfig()->GetHDRType() ) + { + + case HDR_TYPE_FLOAT: + return 1.0; + break; + + case HDR_TYPE_INTEGER: + return 16.0; + + case HDR_TYPE_NONE: + default: + return GammaToLinearFullRange( 2.0 ); // light map scale + } +} + +void CShaderAPIDx8::SetToneMappingScaleLinear( const Vector &scale ) +{ + if ( g_pHardwareConfig->SupportsPixelShaders_2_0() ) + { + // Flush buffered primitives before changing the tone map scalar! + FlushBufferedPrimitives(); + + Vector scale_to_use = scale; + m_ToneMappingScale.AsVector3D() = scale_to_use; + + bool mode_uses_srgb=false; + + switch( HardwareConfig()->GetHDRType() ) + { + case HDR_TYPE_NONE: + m_ToneMappingScale.x = 1.0; // output scale + m_ToneMappingScale.z = 1.0; // reflection map scale + break; + + case HDR_TYPE_FLOAT: + m_ToneMappingScale.x = scale_to_use.x; // output scale + m_ToneMappingScale.z = 1.0; // reflection map scale + break; + + case HDR_TYPE_INTEGER: + mode_uses_srgb = true; + m_ToneMappingScale.x = scale_to_use.x; // output scale + m_ToneMappingScale.z = 16.0; // reflection map scale + break; + } + + m_ToneMappingScale.y = GetLightMapScaleFactor(); // light map scale + + // w component gets gamma scale + m_ToneMappingScale.w = LinearToGammaFullRange( m_ToneMappingScale.x ); + SetPixelShaderConstant( TONE_MAPPING_SCALE_PSH_CONSTANT, m_ToneMappingScale.Base() ); + + // We have to change the fog color since we tone map directly in the shaders in integer HDR mode. + if ( HardwareConfig()->GetHDRType() == HDR_TYPE_INTEGER && m_TransitionTable.CurrentShadowState() ) + { + // Get the shadow state in sync since it depends on SetToneMappingScaleLinear. + ApplyFogMode( m_TransitionTable.CurrentShadowState()->m_FogMode, mode_uses_srgb, m_TransitionTable.CurrentShadowState()->m_bDisableFogGammaCorrection ); + } + } +} + +const Vector & CShaderAPIDx8::GetToneMappingScaleLinear( void ) const +{ + return m_ToneMappingScale.AsVector3D(); +} + +void CShaderAPIDx8::EnableLinearColorSpaceFrameBuffer( bool bEnable ) +{ + LOCK_SHADERAPI(); + m_TransitionTable.EnableLinearColorSpaceFrameBuffer( bEnable ); +} + + +void CShaderAPIDx8::SetPSNearAndFarZ( int pshReg ) +{ + VMatrix m; + GetMatrix( MATERIAL_PROJECTION, m.m[0] ); + + // m[2][2] = F/(N-F) (flip sign if RH) + // m[3][2] = NF/(N-F) + + float vNearFar[4]; + + float N = m[3][2] / m[2][2]; + float F = (m[3][2]*N) / (N + m[3][2]); + + vNearFar[0] = N; + vNearFar[1] = F; + + + SetPixelShaderConstant( pshReg, vNearFar, 1 ); +} + + +void CShaderAPIDx8::SetFloatRenderingParameter( int parm_number, float value ) +{ + LOCK_SHADERAPI(); + if ( parm_number < ARRAYSIZE( FloatRenderingParameters )) + FloatRenderingParameters[parm_number] = value; +} + +void CShaderAPIDx8::SetIntRenderingParameter( int parm_number, int value ) +{ + LOCK_SHADERAPI(); + if ( parm_number < ARRAYSIZE( IntRenderingParameters )) + IntRenderingParameters[parm_number] = value; +} + +void CShaderAPIDx8::SetVectorRenderingParameter( int parm_number, Vector const & value ) +{ + LOCK_SHADERAPI(); + if ( parm_number < ARRAYSIZE( VectorRenderingParameters )) + VectorRenderingParameters[parm_number] = value; +} + +float CShaderAPIDx8::GetFloatRenderingParameter( int parm_number ) const +{ + LOCK_SHADERAPI(); + if ( parm_number < ARRAYSIZE( FloatRenderingParameters )) + return FloatRenderingParameters[parm_number]; + else + return 0.0; +} + +int CShaderAPIDx8::GetIntRenderingParameter( int parm_number ) const +{ + LOCK_SHADERAPI(); + if ( parm_number < ARRAYSIZE( IntRenderingParameters )) + return IntRenderingParameters[parm_number]; + else + return 0; +} + +Vector CShaderAPIDx8::GetVectorRenderingParameter( int parm_number ) const +{ + LOCK_SHADERAPI(); + if ( parm_number < ARRAYSIZE( VectorRenderingParameters )) + return VectorRenderingParameters[parm_number]; + else + return Vector( 0, 0, 0 ); +} + +// stencil entry points +void CShaderAPIDx8::SetStencilEnable( bool onoff ) +{ + LOCK_SHADERAPI(); + SetRenderState( D3DRS_STENCILENABLE, onoff?TRUE:FALSE, true ); +} + +void CShaderAPIDx8::SetStencilFailOperation( StencilOperation_t op ) +{ + LOCK_SHADERAPI(); + SetRenderState( D3DRS_STENCILFAIL, op, true ); +} + +void CShaderAPIDx8::SetStencilZFailOperation( StencilOperation_t op ) +{ + LOCK_SHADERAPI(); + SetRenderState( D3DRS_STENCILZFAIL, op, true ); +} + +void CShaderAPIDx8::SetStencilPassOperation( StencilOperation_t op ) +{ + LOCK_SHADERAPI(); + SetRenderState( D3DRS_STENCILPASS, op, true ); +} + +void CShaderAPIDx8::SetStencilCompareFunction( StencilComparisonFunction_t cmpfn ) +{ + LOCK_SHADERAPI(); + SetRenderState( D3DRS_STENCILFUNC, cmpfn, true ); +} + +void CShaderAPIDx8::SetStencilReferenceValue( int ref ) +{ + LOCK_SHADERAPI(); + SetRenderState( D3DRS_STENCILREF, ref, true ); +} + +void CShaderAPIDx8::SetStencilTestMask( uint32 msk ) +{ + LOCK_SHADERAPI(); + SetRenderState( D3DRS_STENCILMASK, msk, true ); +} + +void CShaderAPIDx8::SetStencilWriteMask( uint32 msk ) +{ + LOCK_SHADERAPI(); + SetRenderState( D3DRS_STENCILWRITEMASK, msk, true ); +} + +void CShaderAPIDx8::ClearStencilBufferRectangle( + int xmin, int ymin, int xmax, int ymax,int value) +{ + LOCK_SHADERAPI(); + D3DRECT clear; + clear.x1 = xmin; + clear.y1 = ymin; + clear.x2 = xmax; + clear.y2 = ymax; + + Dx9Device()->Clear( + 1, &clear, D3DCLEAR_STENCIL, 0, 0, value ); +} + +int CShaderAPIDx8::CompareSnapshots( StateSnapshot_t snapshot0, StateSnapshot_t snapshot1 ) +{ + LOCK_SHADERAPI(); + const ShadowState_t &shadow0 = m_TransitionTable.GetSnapshot(snapshot0); + const ShadowState_t &shadow1 = m_TransitionTable.GetSnapshot(snapshot1); + const ShadowShaderState_t &shader0 = m_TransitionTable.GetSnapshotShader(snapshot0); + const ShadowShaderState_t &shader1 = m_TransitionTable.GetSnapshotShader(snapshot1); + + int dVertex = shader0.m_VertexShader - shader1.m_VertexShader; + if ( dVertex ) + return dVertex; + int dVCombo = shader0.m_nStaticVshIndex - shader1.m_nStaticVshIndex; + if ( dVCombo) + return dVCombo; + + int dPixel = shader0.m_PixelShader - shader1.m_PixelShader; + if ( dPixel ) + return dPixel; + int dPCombo = shader0.m_nStaticPshIndex - shader1.m_nStaticPshIndex; + if ( dPCombo) + return dPCombo; + + return snapshot0 - snapshot1; +} + +//----------------------------------------------------------------------------- +// X360 TTF support requires XUI state manipulation of d3d. +// Font support lives inside the shaderapi in order to maintain privacy of d3d. +//----------------------------------------------------------------------------- +#if defined( _X360 ) +HXUIFONT CShaderAPIDx8::OpenTrueTypeFont( const char *pFontname, int tall, int style ) +{ + LOCK_SHADERAPI(); + + struct fontTable_t + { + const char *pFontName; + const char *pPath; + }; + + // explicit mapping now required, dvd searching to expensive + static fontTable_t fontToFilename[] = + { + {"tf2", "tf/resource/tf2.ttf"}, + {"tf2 build", "tf/resource/tf2build.ttf"}, + {"tf2 professor", "tf/resource/tf2professor.ttf"}, + {"tf2 secondary", "tf/resource/tf2secondary.ttf"}, + {"team fortress", "tf/resource/tf.ttf"}, + {"tfd", "tf/resource/tfd.ttf"}, + {"tflogo", "tf/resource/tflogo.ttf"}, + {"hl2ep2", "ep2/resource/hl2ep2.ttf"}, + {"hl2ep1", "episodic/resource/hl2ep1.ttf"}, + {"halflife2", "hl2/resource/halflife2.ttf"}, + {"hl2cross", "hl2/resource/HL2Crosshairs.ttf"}, + {"courier new", "platform/vgui/fonts/cour.ttf"}, + {"times new roman", "platform/vgui/fonts/times.ttf"}, + {"trebuchet ms", "platform/vgui/fonts/trebuc.ttf"}, + {"verdana", "platform/vgui/fonts/verdana.ttf"}, + {"tahoma", "platform/vgui/fonts/tahoma.ttf"}, + }; + + // remap typeface to diskname + const char *pDiskname = NULL; + for ( int i=0; iszTypeface, wchFontname ) ) + { + bRegistered = true; + break; + } + } + + XuiDestroyTypefaceList( pDescriptors, numTypeFaces ); + + if ( !bRegistered ) + { + // unregistered type face, register type face and retry + // only file based resource locators work + char filename[MAX_PATH]; + V_snprintf( filename, sizeof( filename ), "file://d:/%s", pDiskname ); + Q_FixSlashes( filename, '/' ); + + wchar_t wchFilename[MAX_PATH]; + Q_UTF8ToUnicode( filename, wchFilename, sizeof( wchFilename ) ); + + TypefaceDescriptor desc; + desc.fBaselineAdjust = 0; + desc.szFallbackTypeface = NULL; + desc.szLocator = wchFilename; + desc.szReserved1 = 0; + desc.szTypeface = wchFontname; + hr = XuiRegisterTypeface( &desc, FALSE ); + if ( FAILED( hr ) ) + { + return NULL; + } + } + + // empirically derived factor to achieve desired cell height + float pointSize = tall * 0.59f; + HXUIFONT hFont = NULL; + hr = XuiCreateFont( wchFontname, pointSize, style, 0, &hFont ); + if ( FAILED( hr ) ) + { + return NULL; + } + + return hFont; +} +#endif + +//----------------------------------------------------------------------------- +// Release TTF +//----------------------------------------------------------------------------- +#if defined( _X360 ) +void CShaderAPIDx8::CloseTrueTypeFont( HXUIFONT hFont ) +{ + if ( !hFont ) + return; + LOCK_SHADERAPI(); + + XuiReleaseFont( hFont ); +} +#endif + +//----------------------------------------------------------------------------- +// Get the TTF Metrics +//----------------------------------------------------------------------------- +#if defined( _X360 ) +bool CShaderAPIDx8::GetTrueTypeFontMetrics( HXUIFONT hFont, XUIFontMetrics *pFontMetrics, XUICharMetrics charMetrics[256] ) +{ + if ( !hFont ) + return false; + + LOCK_SHADERAPI(); + + V_memset( charMetrics, 0, 256 * sizeof( XUICharMetrics ) ); + + HRESULT hr = XuiGetFontMetrics( hFont, pFontMetrics ); + if ( !FAILED( hr ) ) + { + // X360 issue: max character width may be too small. + // Run through each character and fixup + for ( int i = 1; i < 256; i++ ) + { + wchar_t wch = i; + hr = XuiGetCharMetrics( hFont, wch, &charMetrics[i] ); + if ( !FAILED( hr ) ) + { + float maxWidth = charMetrics[i].fMaxX; + if ( charMetrics[i].fMinX < 0 ) + { + maxWidth = charMetrics[i].fMaxX - charMetrics[i].fMinX; + } + if ( maxWidth > pFontMetrics->fMaxWidth ) + { + pFontMetrics->fMaxWidth = maxWidth; + } + if ( charMetrics[i].fAdvance > pFontMetrics->fMaxWidth ) + { + pFontMetrics->fMaxWidth = charMetrics[i].fAdvance; + } + } + } + + // fonts are getting cut off, MaxHeight seems to be misreported smaller + // take MaxHeight to be the larger of its reported value or (ascent + descent) + float maxHeight = 0; + if ( pFontMetrics->fMaxDescent <= 0 ) + { + // descent is negative for below baseline + maxHeight = pFontMetrics->fMaxAscent - pFontMetrics->fMaxDescent; + } + if ( maxHeight > pFontMetrics->fMaxHeight ) + { + pFontMetrics->fMaxHeight = maxHeight; + } + } + + return ( !FAILED( hr ) ); +} +#endif + +//----------------------------------------------------------------------------- +// Gets the glyph bits in rgba order. This function PURPOSELY hijacks D3D +// because XUI is involved. It is called at a very specific place in the VGUI +// render frame where its deleterious affects are going to be harmless. +//----------------------------------------------------------------------------- +#if defined( _X360 ) +bool CShaderAPIDx8::GetTrueTypeGlyphs( HXUIFONT hFont, int numChars, wchar_t *pWch, int *pOffsetX, int *pOffsetY, int *pWidth, int *pHeight, unsigned char *pRGBA, int *pRGBAOffset ) +{ + if ( !hFont ) + return false; + + // Ensure this doesn't talk to D3D at the same time as the loading bar + AUTO_LOCK_FM( m_nonInteractiveModeMutex ); + + + LOCK_SHADERAPI(); + bool bSuccess = false; + IDirect3DSurface *pRTSurface = NULL; + IDirect3DSurface *pSavedSurface = NULL; + IDirect3DSurface *pSavedDepthSurface = NULL; + IDirect3DTexture *pTexture = NULL; + D3DVIEWPORT9 savedViewport; + D3DXMATRIX matView; + D3DXMATRIX matXForm; + D3DLOCKED_RECT lockedRect; + + // have to reset to default state to rasterize glyph correctly + // state will get re-established during next mesh draw + ResetRenderState( false ); + Dx9Device()->SetRenderState( D3DRS_ZENABLE, FALSE ); + + Dx9Device()->GetRenderTarget( 0, &pSavedSurface ); + Dx9Device()->GetDepthStencilSurface( &pSavedDepthSurface ); + Dx9Device()->GetViewport( &savedViewport ); + + // Figure out the size of surface/texture we need to allocate + int rtWidth = 0; + int rtHeight = 0; + for ( int i = 0; i < numChars; i++ ) + { + rtWidth += pWidth[i]; + rtHeight = max( rtHeight, pHeight[i] ); + } + + // per resolve() restrictions + rtWidth = AlignValue( rtWidth, 32 ); + rtHeight = AlignValue( rtHeight, 32 ); + + // create a render target to capture the glyph render + pRTSurface = g_TextureHeap.AllocRenderTargetSurface( rtWidth, rtHeight, D3DFMT_A8R8G8B8 ); + if ( !pRTSurface ) + goto cleanUp; + + Dx9Device()->SetRenderTarget( 0, pRTSurface ); + // Disable depth here otherwise you get a colour/depth multisample mismatch error (in 480p) + Dx9Device()->SetDepthStencilSurface( NULL ); + Dx9Device()->Clear( 0, NULL, D3DCLEAR_TARGET, 0x00000000, ( ReverseDepthOnX360() ? 0.0 : 1.0f ), 0 ); + + // create texture to get glyph render from EDRAM + HRESULT hr = Dx9Device()->CreateTexture( rtWidth, rtHeight, 1, 0, D3DFMT_A8R8G8B8, 0, &pTexture, NULL ); + if ( FAILED( hr ) ) + goto cleanUp; + + + bool bPreviousOwnState = OwnGPUResources( false ); + XuiRenderBegin( m_hDC, 0x00000000 ); + + D3DXMatrixIdentity( &matView ); + XuiRenderSetViewTransform( m_hDC, &matView ); + XuiRenderSetTransform( m_hDC, &matView ); + + // rasterize the glyph + XuiSelectFont( m_hDC, hFont ); + XuiSetColorFactor( m_hDC, 0xFFFFFFFF ); + + // Draw the characters, stepping across the texture + int xCursor = 0; + for ( int i = 0; i < numChars; i++) + { + // FIXME: the drawRect params don't make much sense (should use "(xCursor+pWidth[i]), pHeight[i]", but then some characters disappear!) + XUIRect drawRect = XUIRect( xCursor + pOffsetX[i], pOffsetY[i], rtWidth, rtHeight ); + wchar_t text[2] = { pWch[i], 0 }; + XuiDrawText( m_hDC, text, XUI_FONT_STYLE_NORMAL|XUI_FONT_STYLE_SINGLE_LINE|XUI_FONT_STYLE_NO_WORDWRAP, 0, &drawRect ); + xCursor += pWidth[i]; + } + + XuiRenderEnd( m_hDC ); + OwnGPUResources( bPreviousOwnState ); + + + // transfer from edram to system + hr = Dx9Device()->Resolve( 0, NULL, pTexture, NULL, 0, 0, NULL, 0, 0, NULL ); + if ( FAILED( hr ) ) + goto cleanUp; + + hr = pTexture->LockRect( 0, &lockedRect, NULL, 0 ); + if ( FAILED( hr ) ) + goto cleanUp; + + // transfer to linear format, one character at a time + xCursor = 0; + for ( int i = 0;i < numChars; i++ ) + { + int destPitch = pWidth[i]*4; + unsigned char *pLinear = pRGBA + pRGBAOffset[i]; + RECT copyRect = { xCursor, 0, xCursor + pWidth[i], pHeight[i] }; + xCursor += pWidth[i]; + XGUntileSurface( pLinear, destPitch, NULL, lockedRect.pBits, rtWidth, rtHeight, ©Rect, 4 ); + + // convert argb to rgba + float r, g, b, a; + for ( int y = 0; y < pHeight[i]; y++ ) + { + unsigned char *pSrc = (unsigned char*)pLinear + y*destPitch; + for ( int x = 0; x < pWidth[i]; x++ ) + { + // undo pre-multiplied alpha since glyph bits will be sourced as a rgba texture + if ( !pSrc[0] ) + a = 1; + else + a = (float)pSrc[0] * 1.0f/255.0f; + + r = ((float)pSrc[1] * 1.0f/255.0f)/a * 255.0f; + if ( r > 255 ) + r = 255; + + g = ((float)pSrc[2] * 1.0f/255.0f)/a * 255.0f; + if ( g > 255 ) + g = 255; + + b = ((float)pSrc[3] * 1.0f/255.0f)/a * 255.0f; + if ( b > 255 ) + b = 255; + + pSrc[3] = pSrc[0]; + pSrc[2] = b; + pSrc[1] = g; + pSrc[0] = r; + + pSrc += 4; + } + } + } + + pTexture->UnlockRect( 0 ); + + bSuccess = true; + +cleanUp: + if ( pRTSurface ) + { + Dx9Device()->SetRenderTarget( 0, pSavedSurface ); + Dx9Device()->SetDepthStencilSurface( pSavedDepthSurface ); + Dx9Device()->SetViewport( &savedViewport ); + pRTSurface->Release(); + } + + if ( pTexture ) + pTexture->Release(); + + if ( pSavedSurface ) + pSavedSurface->Release(); + + // XUI changed renderstates behind our back, so we need to reset to defaults again to get back in synch: + ResetRenderState( false ); + + return bSuccess; +} +#endif + +//----------------------------------------------------------------------------- +// Create a 360 Render Target Surface +//----------------------------------------------------------------------------- +#if defined( _X360 ) +ShaderAPITextureHandle_t CShaderAPIDx8::CreateRenderTargetSurface( int width, int height, ImageFormat format, const char *pDebugName, const char *pTextureGroupName ) +{ + LOCK_SHADERAPI(); + ShaderAPITextureHandle_t textureHandle = CreateTextureHandle(); + Texture_t *pTexture = &GetTexture( textureHandle ); + + pTexture->m_Flags = (Texture_t::IS_ALLOCATED | Texture_t::IS_RENDER_TARGET_SURFACE); + + pTexture->m_DebugName = pDebugName; + pTexture->m_Width = width; + pTexture->m_Height = height; + pTexture->m_Depth = 1; + pTexture->m_NumCopies = 1; + pTexture->m_CurrentCopy = 0; + + ImageFormat dstImageFormat = FindNearestSupportedFormat( format, false, true, false ); + D3DFORMAT actualFormat = ImageLoader::ImageFormatToD3DFormat( dstImageFormat ); + + pTexture->GetRenderTargetSurface( false ) = g_TextureHeap.AllocRenderTargetSurface( width, height, actualFormat ); + pTexture->GetRenderTargetSurface( true ) = g_TextureHeap.AllocRenderTargetSurface( width, height, (D3DFORMAT)MAKESRGBFMT( actualFormat ) ); + + pTexture->SetImageFormat( dstImageFormat ); + + pTexture->m_UTexWrap = D3DTADDRESS_CLAMP; + pTexture->m_VTexWrap = D3DTADDRESS_CLAMP; + pTexture->m_WTexWrap = D3DTADDRESS_CLAMP; + pTexture->m_MagFilter = D3DTEXF_LINEAR; + + pTexture->m_NumLevels = 1; + pTexture->m_MipFilter = D3DTEXF_NONE; + pTexture->m_MinFilter = D3DTEXF_LINEAR; + + pTexture->m_SwitchNeeded = false; + + ComputeStatsInfo( textureHandle, false, false ); + SetupTextureGroup( textureHandle, pTextureGroupName ); + + return textureHandle; +} +#endif + +//----------------------------------------------------------------------------- +// Shader constants are batched and written to gpu once prior to draw. +//----------------------------------------------------------------------------- +void CShaderAPIDx8::WriteShaderConstantsToGPU() +{ +#if defined( _X360 ) + // vector vertex constants can just blast their set range + if ( m_MaxVectorVertexShaderConstant ) + { + if ( m_bGPUOwned ) + { + // faster path, write directly into GPU command buffer, bypassing shadow state + // can only set what is actually owned + Assert( m_MaxVectorVertexShaderConstant <= VERTEX_SHADER_MODEL + 3*NUM_MODEL_TRANSFORMS ); + int numVectors = AlignValue( m_MaxVectorVertexShaderConstant, 4 ); + BYTE* pCommandBufferData; + Dx9Device()->GpuBeginVertexShaderConstantF4( 0, (D3DVECTOR4**)&pCommandBufferData, numVectors ); + memcpy( pCommandBufferData, m_DesiredState.m_pVectorVertexShaderConstant[0].Base(), numVectors * (sizeof( float ) * 4) ); + Dx9Device()->GpuEndVertexShaderConstantF4(); + } + else + { + Dx9Device()->SetVertexShaderConstantF( 0, m_DesiredState.m_pVectorVertexShaderConstant[0].Base(), m_MaxVectorVertexShaderConstant ); + } + + memcpy( m_DynamicState.m_pVectorVertexShaderConstant[0].Base(), m_DesiredState.m_pVectorVertexShaderConstant[0].Base(), m_MaxVectorVertexShaderConstant * 4 * sizeof(float) ); + m_MaxVectorVertexShaderConstant = 0; + } + + if ( m_MaxVectorPixelShaderConstant ) + { + if ( m_bGPUOwned ) + { + // faster path, write directly into GPU command buffer, bypassing shadow state + // can only set what is actually owned + Assert( m_MaxVectorPixelShaderConstant <= 32 ); + int numVectors = AlignValue( m_MaxVectorPixelShaderConstant, 4 ); + BYTE* pCommandBufferData; + Dx9Device()->GpuBeginPixelShaderConstantF4( 0, (D3DVECTOR4**)&pCommandBufferData, numVectors ); + memcpy( pCommandBufferData, m_DesiredState.m_pVectorPixelShaderConstant[0].Base(), numVectors * (sizeof( float ) * 4) ); + Dx9Device()->GpuEndPixelShaderConstantF4(); + } + else + { + Dx9Device()->SetPixelShaderConstantF( 0, m_DesiredState.m_pVectorPixelShaderConstant[0].Base(), m_MaxVectorPixelShaderConstant ); + } + + memcpy( m_DynamicState.m_pVectorPixelShaderConstant[0].Base(), m_DesiredState.m_pVectorPixelShaderConstant[0].Base(), m_MaxVectorPixelShaderConstant * 4 * sizeof(float) ); + m_MaxVectorPixelShaderConstant = 0; + } + + // boolean and integer constants can just blast their set range + // these are currently extremely small in number, if this changes they may benefit from a fast path pattern + if ( m_MaxBooleanVertexShaderConstant ) + { + Dx9Device()->SetVertexShaderConstantB( 0, m_DesiredState.m_pBooleanVertexShaderConstant, m_MaxBooleanVertexShaderConstant ); + memcpy( m_DynamicState.m_pBooleanVertexShaderConstant, m_DesiredState.m_pBooleanVertexShaderConstant, m_MaxBooleanVertexShaderConstant * sizeof(BOOL) ); + m_MaxBooleanVertexShaderConstant = 0; + } + if ( m_MaxIntegerVertexShaderConstant ) + { + Dx9Device()->SetVertexShaderConstantI( 0, (int *)m_DesiredState.m_pIntegerVertexShaderConstant, m_MaxIntegerVertexShaderConstant ); + memcpy( m_DynamicState.m_pIntegerVertexShaderConstant[0].Base(), m_DesiredState.m_pIntegerVertexShaderConstant[0].Base(), m_MaxIntegerVertexShaderConstant * sizeof(IntVector4D) ); + m_MaxIntegerVertexShaderConstant = 0; + } + + if ( m_MaxBooleanPixelShaderConstant ) + { + Dx9Device()->SetPixelShaderConstantB( 0, m_DesiredState.m_pBooleanPixelShaderConstant, m_MaxBooleanPixelShaderConstant ); + memcpy( m_DynamicState.m_pBooleanPixelShaderConstant, m_DesiredState.m_pBooleanPixelShaderConstant, m_MaxBooleanPixelShaderConstant * sizeof(BOOL) ); + m_MaxBooleanPixelShaderConstant = 0; + } + + // integer pixel constants are not used, so not supporting +#if 0 + if ( m_MaxIntegerPixelShaderConstant ) + { + Dx9Device()->SetPixelShaderConstantI( 0, (int *)m_DesiredState.m_pIntegerPixelShaderConstant, m_MaxIntegerPixelShaderConstant ); + memcpy( m_DynamicState.m_pIntegerPixelShaderConstant[0].Base(), m_DesiredState.m_pIntegerPixelShaderConstant[0].Base(), m_MaxIntegerPixelShaderConstant * sizeof(IntVector4D) ); + m_MaxIntegerPixelShaderConstant = 0; + } +#endif +#endif +} + +//----------------------------------------------------------------------------- +// The application is about to perform a hard reboot, but wants to hide the screen flash +// by persisting the front buffer across a reboot boundary. The persisted frame buffer +// can be detected and restored. +//----------------------------------------------------------------------------- +#if defined( _X360 ) +void CShaderAPIDx8::PersistDisplay() +{ + if ( m_PresentParameters.FrontBufferFormat != D3DFMT_LE_X8R8G8B8 ) + { + // The format must be what PersistDisplay() expects, otherwise D3DRIP. + // If this hits due to sRGB bit set that confuses PersistDisplay(), + // the fix may be to slam the presentation parameters to the expected format, + // do a ResetDevice(), and then PersistDisplay(). + Assert( 0 ); + return; + } + + IDirect3DTexture *pTexture; + HRESULT hr = Dx9Device()->GetFrontBuffer( &pTexture ); + if ( !FAILED( hr ) ) + { + OwnGPUResources( false ); + Dx9Device()->PersistDisplay( pTexture, NULL ); + pTexture->Release(); + } +} +#endif + +#if defined( _X360 ) +bool CShaderAPIDx8::PostQueuedTexture( const void *pData, int nDataSize, ShaderAPITextureHandle_t *pHandles, int numHandles, int nWidth, int nHeight, int nDepth, int numMips, int *pRefCount ) +{ + CUtlBuffer vtfBuffer; + IVTFTexture *pVTFTexture = NULL; + bool bOK = false; + + if ( !pData || !nDataSize ) + { + // invalid + goto cleanUp; + } + + // get a unique vtf and mount texture + // vtf can expect non-volatile buffer data to be stable through vtf lifetime + // this prevents redundant copious amounts of image memory transfers + pVTFTexture = CreateVTFTexture(); + vtfBuffer.SetExternalBuffer( (void *)pData, nDataSize, nDataSize ); + if ( !pVTFTexture->UnserializeFromBuffer( vtfBuffer, false, false, false, 0 ) ) + { + goto cleanUp; + } + + // provided vtf buffer is all mips, determine top mip due to possible picmip + int iTopMip = 0; + int mipWidth, mipHeight, mipDepth; + do + { + pVTFTexture->ComputeMipLevelDimensions( iTopMip, &mipWidth, &mipHeight, &mipDepth ); + if ( nWidth == mipWidth && nHeight == mipHeight && nDepth == mipDepth ) + { + break; + } + iTopMip++; + } + while ( mipWidth != 1 || mipHeight != 1 || mipDepth != 1 ); + + // create and blit + for ( int iFrame = 0; iFrame < numHandles; iFrame++ ) + { + ShaderAPITextureHandle_t hTexture = pHandles[iFrame]; + Texture_t *pTexture = &GetTexture( hTexture ); + + int nFaceCount = ( pTexture->m_CreationFlags & TEXTURE_CREATE_CUBEMAP ) ? CUBEMAP_FACE_COUNT-1 : 1; + + IDirect3DBaseTexture *pD3DTexture; + if ( pTexture->m_CreationFlags & TEXTURE_CREATE_NOD3DMEMORY ) + { + pD3DTexture = pTexture->GetTexture(); + if ( !g_TextureHeap.AllocD3DMemory( pD3DTexture ) ) + { + goto cleanUp; + } + } + else + { + pD3DTexture = pTexture->GetTexture(); + } + + // blit the hi-res texture bits into d3d memory + for ( int iFace = 0; iFace < nFaceCount; ++iFace ) + { + for ( int iMip = 0; iMip < numMips; ++iMip ) + { + pVTFTexture->ComputeMipLevelDimensions( iTopMip + iMip, &mipWidth, &mipHeight, &mipDepth ); + unsigned char *pSourceBits = pVTFTexture->ImageData( iFrame, iFace, iTopMip + iMip, 0, 0, 0 ); + + TextureLoadInfo_t info; + info.m_TextureHandle = hTexture; + info.m_pTexture = pD3DTexture; + info.m_nLevel = iMip; + info.m_nCopy = 0; + info.m_CubeFaceID = (D3DCUBEMAP_FACES)iFace; + info.m_nWidth = mipWidth; + info.m_nHeight = mipHeight; + info.m_nZOffset = 0; + info.m_SrcFormat = pVTFTexture->Format(); + info.m_pSrcData = pSourceBits; + info.m_bSrcIsTiled = pVTFTexture->IsPreTiled(); + info.m_bCanConvertFormat = ( pTexture->m_Flags & Texture_t::CAN_CONVERT_FORMAT ) != 0; + LoadTexture( info ); + } + } + + pTexture->m_Flags |= Texture_t::IS_FINALIZED; + (*pRefCount)--; + } + + // success + bOK = true; + +cleanUp: + if ( pVTFTexture ) + { + DestroyVTFTexture( pVTFTexture ); + } + + if ( !bOK ) + { + // undo artificial lock + (*pRefCount) -= numHandles; + } + + return bOK; +} +#endif + +#if defined( _X360 ) +void *CShaderAPIDx8::GetD3DDevice() +{ + return Dx9Device(); +} +#endif + +#if defined( _X360 ) +static void r_enable_gpr_allocations_callback( IConVar *var, const char *pOldValue, float flOldValue ) +{ + if ( ((ConVar *)var)->GetBool() == false ) + { + //reset back the default 64/64 allocation before we stop updating + if( Dx9Device() != NULL ) + { + Dx9Device()->SetShaderGPRAllocation( 0, 0, 0 ); + } + } +} + +ConVar r_enable_gpr_allocations( "r_enable_gpr_allocations", "1", 0, "Enable usage of IDirect3DDevice9::SetShaderGPRAllocation()", r_enable_gpr_allocations_callback ); + +static void CommitShaderGPRs( IDirect3DDevice9 *pDevice, const DynamicState_t &desiredState, DynamicState_t ¤tState, bool bForce ) +{ + if( desiredState.m_iVertexShaderGPRAllocation != currentState.m_iVertexShaderGPRAllocation ) + { + pDevice->SetShaderGPRAllocation( 0, desiredState.m_iVertexShaderGPRAllocation, 128 - desiredState.m_iVertexShaderGPRAllocation ); + currentState.m_iVertexShaderGPRAllocation = desiredState.m_iVertexShaderGPRAllocation; + } +} + +void CShaderAPIDx8::PushVertexShaderGPRAllocation( int iVertexShaderCount ) +{ + Assert( (iVertexShaderCount >= 16) && (iVertexShaderCount <= 112) ); + m_VertexShaderGPRAllocationStack.Push( iVertexShaderCount ); + + if ( r_enable_gpr_allocations.GetBool() ) + { + if ( m_DynamicState.m_iVertexShaderGPRAllocation != iVertexShaderCount ) + { + m_DesiredState.m_iVertexShaderGPRAllocation = iVertexShaderCount; + ADD_COMMIT_FUNC( COMMIT_PER_DRAW, COMMIT_ALWAYS, CommitShaderGPRs ); + } + } +} + +void CShaderAPIDx8::PopVertexShaderGPRAllocation( void ) +{ + m_VertexShaderGPRAllocationStack.Pop(); + + if ( r_enable_gpr_allocations.GetBool() ) + { + int iVertexShaderCount; + if ( m_VertexShaderGPRAllocationStack.Count() ) + iVertexShaderCount = m_VertexShaderGPRAllocationStack.Top(); + else + iVertexShaderCount = 64; + + if ( m_DynamicState.m_iVertexShaderGPRAllocation != iVertexShaderCount ) + { + m_DesiredState.m_iVertexShaderGPRAllocation = iVertexShaderCount; + ADD_COMMIT_FUNC( COMMIT_PER_DRAW, COMMIT_ALWAYS, CommitShaderGPRs ); + } + } +} + +void CShaderAPIDx8::EnableVSync_360( bool bEnable ) +{ + if( bEnable ) + { + Dx9Device()->SetRenderState( D3DRS_PRESENTIMMEDIATETHRESHOLD, 0 ); //only swap on vertical blanks + } + else + { + Dx9Device()->SetRenderState( D3DRS_PRESENTIMMEDIATETHRESHOLD, 100 ); //allow a swap at any point in the DAC scan + } +} +#endif + +// ------------ New Vertex/Index Buffer interface ---------------------------- + +void CShaderAPIDx8::BindVertexBuffer( int streamID, IVertexBuffer *pVertexBuffer, int nOffsetInBytes, int nFirstVertex, int nVertexCount, VertexFormat_t fmt, int nRepetitions ) +{ + LOCK_SHADERAPI(); + MeshMgr()->BindVertexBuffer( streamID, pVertexBuffer, nOffsetInBytes, nFirstVertex, nVertexCount, fmt, nRepetitions ); +} + +void CShaderAPIDx8::BindIndexBuffer( IIndexBuffer *pIndexBuffer, int nOffsetInBytes ) +{ + LOCK_SHADERAPI(); + MeshMgr()->BindIndexBuffer( pIndexBuffer, nOffsetInBytes ); +} + +void CShaderAPIDx8::Draw( MaterialPrimitiveType_t primitiveType, int nFirstIndex, int nIndexCount ) +{ + LOCK_SHADERAPI(); + MeshMgr()->Draw( primitiveType, nFirstIndex, nIndexCount ); +} + +// ------------ End ---------------------------- + +float CShaderAPIDx8::GammaToLinear_HardwareSpecific( float fGamma ) const +{ + if( IsPC() ) + { + return SrgbGammaToLinear( fGamma ); + } + else if( IsX360() ) + { + return SrgbGammaToLinear( fGamma ); + } + else + { + // Unknown console + return pow( fGamma, 2.2f ); // Use a gamma 2.2 curve + } +} + +float CShaderAPIDx8::LinearToGamma_HardwareSpecific( float fLinear ) const +{ + if ( IsPC() ) + { + return SrgbLinearToGamma( fLinear ); + } + else if ( IsX360() ) + { + return SrgbLinearToGamma( fLinear ); + } + else + { + // Unknown console + return pow( fLinear, ( 1.0f / 2.2f ) ); // Use a gamma 2.2 curve + } +} + + +bool CShaderAPIDx8::ShouldWriteDepthToDestAlpha( void ) const +{ + return IsPC() && g_pHardwareConfig->SupportsPixelShaders_2_b() && + (m_SceneFogMode != MATERIAL_FOG_LINEAR_BELOW_FOG_Z) && + (GetIntRenderingParameter(INT_RENDERPARM_WRITE_DEPTH_TO_DESTALPHA) != 0); +} + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +void CShaderAPIDx8::AcquireThreadOwnership() +{ + SetCurrentThreadAsOwner(); +#if (defined( _X360 ) || defined( DX_TO_GL_ABSTRACTION )) + Dx9Device()->AcquireThreadOwnership(); +#endif +} + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +void CShaderAPIDx8::ReleaseThreadOwnership() +{ + RemoveThreadOwner(); +#if (defined( _X360 ) || defined( DX_TO_GL_ABSTRACTION )) + Dx9Device()->ReleaseThreadOwnership(); +#endif +} + + +//----------------------------------------------------------------------------- +// Actual low level setting of the color RT. All Xbox RT funnels here +// to track the actual RT state. Returns true if the RT gets set, otherwise false. +//----------------------------------------------------------------------------- +bool CShaderAPIDx8::SetRenderTargetInternalXbox( ShaderAPITextureHandle_t hRenderTargetTexture, bool bForce ) +{ + // valid for 360 only + if ( IsPC() ) + { + Assert( 0 ); + return false; + } + + if ( hRenderTargetTexture == INVALID_SHADERAPI_TEXTURE_HANDLE ) + { + // could be a reset, force to back buffer + hRenderTargetTexture = SHADER_RENDERTARGET_BACKBUFFER; + } + + if ( m_hCachedRenderTarget == INVALID_SHADERAPI_TEXTURE_HANDLE ) + { + // let the set go through to establish the initial state + bForce = true; + } + + if ( !bForce && ( hRenderTargetTexture == m_hCachedRenderTarget && m_DynamicState.m_bSRGBWritesEnabled == m_bUsingSRGBRenderTarget ) ) + { + // current RT matches expected state, leave state intact + return false; + } + + // track the updated state + m_bUsingSRGBRenderTarget = m_DynamicState.m_bSRGBWritesEnabled; + m_hCachedRenderTarget = hRenderTargetTexture; + + IDirect3DSurface *pSurface; + if ( m_hCachedRenderTarget == SHADER_RENDERTARGET_BACKBUFFER ) + { + if ( !m_bUsingSRGBRenderTarget ) + { + pSurface = m_pBackBufferSurface; + } + else + { + pSurface = m_pBackBufferSurfaceSRGB; + } + } + else + { + AssertValidTextureHandle( m_hCachedRenderTarget ); + Texture_t *pTexture = &GetTexture( m_hCachedRenderTarget ); + pSurface = pTexture->GetRenderTargetSurface( m_bUsingSRGBRenderTarget ); + } + + // the 360 does a wierd reset of some states on a SetRenderTarget() + // the viewport is a clobbered state, it may not be changed by later callers, so it MUST be put back as expected + // the other clobbered states are waiting to be discovered ... sigh +#if defined( _X360 ) + D3DVIEWPORT9 viewport; + Dx9Device()->GetViewport( &viewport ); + Dx9Device()->SetRenderTarget( 0, pSurface ); + Dx9Device()->SetViewport( &viewport ); +#endif + + return true; +} + + +//----------------------------------------------------------------------------- +// debug logging +//----------------------------------------------------------------------------- +void CShaderAPIDx8::PrintfVA( char *fmt, va_list vargs ) +{ +#ifdef DX_TO_GL_ABSTRACTION + #if GLMDEBUG + GLMPrintfVA( fmt, vargs ); + #endif +#else + AssertOnce( !"Impl me" ); +#endif +} + +void CShaderAPIDx8::Printf( const char *fmt, ... ) +{ +#ifdef DX_TO_GL_ABSTRACTION + #if GLMDEBUG + va_list vargs; + + va_start(vargs, fmt); + + GLMPrintfVA( fmt, vargs ); + + va_end( vargs ); + #endif +#else + AssertOnce( !"Impl me" ); +#endif +} + +float CShaderAPIDx8::Knob( char *knobname, float *setvalue ) +{ +#ifdef DX_TO_GL_ABSTRACTION + #if GLMDEBUG + return GLMKnob( knobname, setvalue ); + #else + return 0.0f; + #endif +#else + return 0.0f; +#endif +} + + + +#if defined( _X360 ) + +extern ConVar r_blocking_spew_threshold; +void D3DBlockingSpewCallback( DWORD Flags, D3DBLOCKTYPE BlockType, float ClockTime, DWORD ThreadTime ) +{ + if( ClockTime >= r_blocking_spew_threshold.GetFloat() ) + { + const char *pBlockType = ""; + switch( BlockType ) + { + case D3DBLOCKTYPE_NONE: + pBlockType = "D3DBLOCKTYPE_NONE"; + break; + case D3DBLOCKTYPE_PRIMARY_OVERRUN: + pBlockType = "D3DBLOCKTYPE_PRIMARY_OVERRUN"; + break; + case D3DBLOCKTYPE_SECONDARY_OVERRUN: + pBlockType = "D3DBLOCKTYPE_SECONDARY_OVERRUN"; + break; + case D3DBLOCKTYPE_SWAP_THROTTLE: + pBlockType = "D3DBLOCKTYPE_SWAP_THROTTLE"; + break; + case D3DBLOCKTYPE_BLOCK_UNTIL_IDLE: + pBlockType = "D3DBLOCKTYPE_BLOCK_UNTIL_IDLE"; + break; + case D3DBLOCKTYPE_BLOCK_UNTIL_NOT_BUSY: + pBlockType = "D3DBLOCKTYPE_BLOCK_UNTIL_NOT_BUSY"; + break; + case D3DBLOCKTYPE_BLOCK_ON_FENCE: + pBlockType = "D3DBLOCKTYPE_BLOCK_ON_FENCE"; + break; + case D3DBLOCKTYPE_VERTEX_SHADER_RELEASE: + pBlockType = "D3DBLOCKTYPE_VERTEX_SHADER_RELEASE"; + break; + case D3DBLOCKTYPE_PIXEL_SHADER_RELEASE: + pBlockType = "D3DBLOCKTYPE_PIXEL_SHADER_RELEASE"; + break; + case D3DBLOCKTYPE_VERTEX_BUFFER_RELEASE: + pBlockType = "D3DBLOCKTYPE_VERTEX_BUFFER_RELEASE"; + break; + case D3DBLOCKTYPE_VERTEX_BUFFER_LOCK: + pBlockType = "D3DBLOCKTYPE_VERTEX_BUFFER_LOCK"; + break; + case D3DBLOCKTYPE_INDEX_BUFFER_RELEASE: + pBlockType = "D3DBLOCKTYPE_INDEX_BUFFER_RELEASE"; + break; + case D3DBLOCKTYPE_INDEX_BUFFER_LOCK: + pBlockType = "D3DBLOCKTYPE_INDEX_BUFFER_LOCK"; + break; + case D3DBLOCKTYPE_TEXTURE_RELEASE: + pBlockType = "D3DBLOCKTYPE_TEXTURE_RELEASE"; + break; + case D3DBLOCKTYPE_TEXTURE_LOCK: + pBlockType = "D3DBLOCKTYPE_TEXTURE_LOCK"; + break; + case D3DBLOCKTYPE_COMMAND_BUFFER_RELEASE: + pBlockType = "D3DBLOCKTYPE_COMMAND_BUFFER_RELEASE"; + break; + case D3DBLOCKTYPE_COMMAND_BUFFER_LOCK: + pBlockType = "D3DBLOCKTYPE_COMMAND_BUFFER_LOCK"; + break; + case D3DBLOCKTYPE_CONSTANT_BUFFER_RELEASE: + pBlockType = "D3DBLOCKTYPE_CONSTANT_BUFFER_RELEASE"; + break; + case D3DBLOCKTYPE_CONSTANT_BUFFER_LOCK: + pBlockType = "D3DBLOCKTYPE_CONSTANT_BUFFER_LOCK"; + break; + + NO_DEFAULT; + }; + + Warning( "D3D Block: %s for %.2f ms\n", pBlockType, ClockTime ); + } +} + +static void r_blocking_spew_threshold_callback( IConVar *var, const char *pOldValue, float flOldValue ) +{ + if( Dx9Device() != NULL ) + { + if ( ((ConVar *)var)->GetFloat() >= 0.0f ) + { + Dx9Device()->SetBlockCallback( 0, D3DBlockingSpewCallback ); + } + else + { + Dx9Device()->SetBlockCallback( 0, NULL ); + } + } +} + +ConVar r_blocking_spew_threshold( "r_blocking_spew_threshold", "-1", 0, "Enable spew of Direct3D Blocks. Specify the minimum blocking time in milliseconds before spewing a warning.", r_blocking_spew_threshold_callback ); +#endif + diff --git a/materialsystem/shaderapidx9/shaderapidx8.h b/materialsystem/shaderapidx9/shaderapidx8.h new file mode 100644 index 0000000..fae297b --- /dev/null +++ b/materialsystem/shaderapidx9/shaderapidx8.h @@ -0,0 +1,118 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +// +//===========================================================================// + +#ifndef SHADERAPIDX8_H +#define SHADERAPIDX8_H + +#include "shaderapibase.h" +#include "shaderapi/ishadershadow.h" +#include "locald3dtypes.h" + +//----------------------------------------------------------------------------- +// Vendor-specific defines +//----------------------------------------------------------------------------- +#define ATI_FETCH4_ENABLE MAKEFOURCC('G','E','T','4') +#define ATI_FETCH4_DISABLE MAKEFOURCC('G','E','T','1') +#define ATISAMP_FETCH4 D3DSAMP_MIPMAPLODBIAS + +//----------------------------------------------------------------------------- +// Forward declarations +//----------------------------------------------------------------------------- +class CMeshBase; +class CMeshBuilder; +struct ShadowState_t; +class IMaterialInternal; + + +//----------------------------------------------------------------------------- +// State that matters to buffered meshes... (for debugging only) +//----------------------------------------------------------------------------- +struct BufferedState_t +{ + D3DXMATRIX m_Transform[3]; + D3DVIEWPORT9 m_Viewport; + int m_BoundTexture[16]; + void *m_VertexShader; + void *m_PixelShader; +}; + + +//----------------------------------------------------------------------------- +// The DX8 shader API +//----------------------------------------------------------------------------- +// FIXME: Remove this! Either move them into CShaderAPIBase or CShaderAPIDx8 +class IShaderAPIDX8 : public CShaderAPIBase +{ +public: + // Draws the mesh + virtual void DrawMesh( CMeshBase *pMesh ) = 0; + + // Draw the mesh with the currently bound vertex and index buffers. + virtual void DrawWithVertexAndIndexBuffers( void ) = 0; + + // modifies the vertex data when necessary + virtual void ModifyVertexData( ) = 0; + + // Gets the current buffered state... (debug only) + virtual void GetBufferedState( BufferedState_t &state ) = 0; + + // Gets the current backface cull state.... + virtual D3DCULL GetCullMode() const = 0; + + // Measures fill rate + virtual void ComputeFillRate() = 0; + + // Selection mode methods + virtual bool IsInSelectionMode() const = 0; + + // We hit somefin in selection mode + virtual void RegisterSelectionHit( float minz, float maxz ) = 0; + + // Get the currently bound material + virtual IMaterialInternal* GetBoundMaterial() = 0; + + // These methods are called by the transition table + // They depend on dynamic state so can't exist inside the transition table + virtual void ApplyZBias( const ShadowState_t &shaderState ) = 0; + virtual void ApplyTextureEnable( const ShadowState_t &state, int stage ) = 0; + virtual void ApplyCullEnable( bool bEnable ) = 0; + virtual void SetVertexBlendState( int numBones ) = 0; + virtual void ApplyFogMode( ShaderFogMode_t fogMode, bool bSRGBWritesEnabled, bool bDisableGammaCorrection ) = 0; + + virtual int GetActualTextureStageCount() const = 0; + virtual int GetActualSamplerCount() const = 0; + + virtual bool IsRenderingMesh() const = 0; + + // Fog methods... + virtual void FogMode( MaterialFogMode_t fogMode ) = 0; + + virtual int GetCurrentFrameCounter( void ) const = 0; + + // Workaround hack for visualization of selection mode + virtual void SetupSelectionModeVisualizationState() = 0; + + virtual bool UsingSoftwareVertexProcessing() const = 0; + + //notification that the SRGB write state is being changed + virtual void EnabledSRGBWrite( bool bEnabled ) = 0; + + // Alpha to coverage + virtual void ApplyAlphaToCoverage( bool bEnable ) = 0; + +#if defined( _X360 ) + virtual void ApplySRGBReadState( int iTextureStage, bool bSRGBReadEnabled ) = 0; //360 needs to rebind the texture over again instead of setting a sampler state +#endif + + virtual void PrintfVA( char *fmt, va_list vargs ) = 0; + virtual void Printf( PRINTF_FORMAT_STRING const char *fmt, ... ) = 0; + virtual float Knob( char *knobname, float *setvalue = NULL ) = 0; +}; + + +#endif // SHADERAPIDX8_H diff --git a/materialsystem/shaderapidx9/shaderapidx8_global.h b/materialsystem/shaderapidx9/shaderapidx8_global.h new file mode 100644 index 0000000..2dab1e3 --- /dev/null +++ b/materialsystem/shaderapidx9/shaderapidx8_global.h @@ -0,0 +1,100 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +// +//===========================================================================// + +#ifndef SHADERAPIDX8_GLOBAL_H +#define SHADERAPIDX8_GLOBAL_H + +#ifdef _WIN32 +#pragma once +#endif + +#include "tier0/dbg.h" +#include "tier0/memalloc.h" +#include "shaderapi_global.h" +#include "tier2/tier2.h" +#include "shaderdevicedx8.h" + + +//----------------------------------------------------------------------------- +// Use this to fill in structures with the current board state +//----------------------------------------------------------------------------- + +#ifdef _DEBUG +#define DEBUG_BOARD_STATE 0 +#endif + +#if !defined( _X360 ) +IDirect3DDevice9 *Dx9Device(); +IDirect3D9 *D3D(); +#endif + + +//----------------------------------------------------------------------------- +// Measures driver allocations +//----------------------------------------------------------------------------- +//#define MEASURE_DRIVER_ALLOCATIONS 1 + + +//----------------------------------------------------------------------------- +// Forward declarations +//----------------------------------------------------------------------------- +class IShaderUtil; +class IVertexBufferDX8; +class IShaderShadowDX8; +class IMeshMgr; +class IShaderAPIDX8; +class IFileSystem; +class IShaderManager; + + +//----------------------------------------------------------------------------- +// A new shader draw flag we need to workaround dx8 +//----------------------------------------------------------------------------- +enum +{ + SHADER_HAS_CONSTANT_COLOR = 0x80000000 +}; + +//----------------------------------------------------------------------------- +// The main shader API +//----------------------------------------------------------------------------- +extern IShaderAPIDX8 *g_pShaderAPIDX8; +inline IShaderAPIDX8* ShaderAPI() +{ + return g_pShaderAPIDX8; +} + +//----------------------------------------------------------------------------- +// The shader shadow +//----------------------------------------------------------------------------- +IShaderShadowDX8* ShaderShadow(); + +//----------------------------------------------------------------------------- +// Manager of all vertex + pixel shaders +//----------------------------------------------------------------------------- +inline IShaderManager *ShaderManager() +{ + extern IShaderManager *g_pShaderManager; + return g_pShaderManager; +} + +//----------------------------------------------------------------------------- +// The mesh manager +//----------------------------------------------------------------------------- +IMeshMgr* MeshMgr(); + +//----------------------------------------------------------------------------- +// The main hardware config interface +//----------------------------------------------------------------------------- +inline IMaterialSystemHardwareConfig* HardwareConfig() +{ + return g_pMaterialSystemHardwareConfig; +} + + +#endif // SHADERAPIDX8_GLOBAL_H diff --git a/materialsystem/shaderapidx9/shaderapidx9.vpc b/materialsystem/shaderapidx9/shaderapidx9.vpc new file mode 100644 index 0000000..167a719 --- /dev/null +++ b/materialsystem/shaderapidx9/shaderapidx9.vpc @@ -0,0 +1,146 @@ +//----------------------------------------------------------------------------- +// SHADERDX8.VPC +// +// Project Script +//----------------------------------------------------------------------------- + +$Macro SRCDIR "..\.." +$Macro OUTBINDIR "$SRCDIR\..\game\bin" +$Macro OUTBINNAME "shaderapidx9" + +$include "$SRCDIR\vpc_scripts\source_dll_base.vpc" + + +// Common Configuration +$Configuration +{ + $Compiler + { + $AdditionalIncludeDirectories "$BASE;$SRCDIR\dx9sdk\include" [$WIN32 && !$GL] + $AdditionalIncludeDirectories "$BASE;$SRCDIR\x360xdk\include\xbox" [$X360] + $AdditionalIncludeDirectories "$BASE;..\" + $PreprocessorDefinitions "$BASE;SHADERAPIDX9;SHADER_DLL_EXPORT;PROTECTED_THINGS_ENABLE;strncpy=use_Q_strncpy_instead;_snprintf=use_Q_snprintf_instead" + $PreprocessorDefinitions "$BASE;USE_ACTUAL_DX" [($WIN32||$X360) && !$GL] + $PreprocessorDefinitions "$BASE;GL_GLEXT_PROTOTYPES;DX_TO_GL_ABSTRACTION" [$GL] +// $AdditionalOptions "/FC" + } + + $Linker + { + $SystemLibraries "iconv" [$OSXALL] + $GCC_ExtraLinkerFlags "-L/usr/lib32" [$LINUXALL] + $SystemFrameworks "Carbon;OpenGL;Quartz;Cocoa;IOKit" [$OSXALL] + $AdditionalDependencies "$BASE ws2_32.lib" [$WIN32] + } +} + +$Configuration "Debug" +{ + $Linker [$X360] + { + $AdditionalDependencies "$BASE d3dx9d.lib xuirund.lib xuirenderd.lib xaudiod2.lib xmcored.lib" + } +} + +$Configuration "Release" +{ + $Linker [$X360] + { + $AdditionalDependencies "$BASE d3dx9.lib xuirun.lib xuirender.lib xaudio2.lib xmcore.lib" + } +} + +$Project "shaderapidx9" +{ + $Folder "Source Files" + { + $File "colorformatdx8.cpp" + $File "$SRCDIR\public\filesystem_helpers.cpp" + $File "hardwareconfig.cpp" + $File "meshbase.cpp" + $File "meshdx8.cpp" + $File "recording.cpp" [$WIN32 && !$GL] + $File "shaderapidx8.cpp" + $File "shaderdevicebase.cpp" + $File "shaderapibase.cpp" + $File "shaderdevicedx8.cpp" + $File "shadershadowdx8.cpp" + $File "texturedx8.cpp" + $File "TransitionTable.cpp" + $File "cvballoctracker.cpp" + $File "vertexdecl.cpp" + $File "vertexshaderdx8.cpp" + $File "wmi.cpp" [$WIN32 && !$GL] + $File "textureheap.cpp" [$X360] + $File "winutils.cpp" [!$WIN32] + } + + $Folder "DirectX Header Files" [$WIN32 && !$GL] + { + $File "$SRCDIR\dx9sdk\include\d3dx9.h" + $File "$SRCDIR\dx9sdk\include\d3dx9anim.h" + $File "$SRCDIR\dx9sdk\include\d3dx9core.h" + $File "$SRCDIR\dx9sdk\include\d3dx9effect.h" + $File "$SRCDIR\dx9sdk\include\d3dx9math.h" + $File "$SRCDIR\dx9sdk\include\d3dx9math.inl" + $File "$SRCDIR\dx9sdk\include\d3dx9mesh.h" + $File "$SRCDIR\dx9sdk\include\d3dx9shader.h" + $File "$SRCDIR\dx9sdk\include\d3dx9shape.h" + $File "$SRCDIR\dx9sdk\include\d3dx9tex.h" + } + + $Folder "Public Header Files" + { + $File "$SRCDIR\public\shaderapi\IShaderDevice.h" + $File "$SRCDIR\public\shaderapi\ishaderutil.h" + $File "$SRCDIR\public\shaderapi\ishaderapi.h" + $File "$SRCDIR\public\shaderapi\ishaderdynamic.h" + $File "$SRCDIR\public\shaderapi\ishadershadow.h" + $File "$SRCDIR\public\materialsystem\idebugtextureinfo.h" + $File "$SRCDIR\public\materialsystem\ivballoctracker.h" + $File "$SRCDIR\public\materialsystem\shader_vcs_version.h" + } + + $Folder "Header Files" + { + $File "TransitionTable.h" + $File "vertexdecl.h" + $File "colorformatdx8.h" + $File "dynamicib.h" + $File "dynamicvb.h" + $File "hardwareconfig.h" + $File "meshbase.h" + $File "imeshdx8.h" + $File "locald3dtypes.h" + $File "recording.h" + $File "shaderapidx8.h" + $File "shaderdevicebase.h" + $File "shaderapibase.h" + $File "shaderdevicedx8.h" + $File "shaderapidx8_global.h" + $File "shadershadowdx8.h" + $File "stubd3ddevice.h" + $File "texturedx8.h" + $File "vertexshaderdx8.h" + $File "wmi.h" [$WIN32 && !$GL] + $File "textureheap.h" [$X360] + $File "winutils.h" [!$WIN32] + } + + $Folder "Link Libraries" [$WIN32] + { + + $File "$SRCDIR\dx9sdk\lib\d3d9.lib" [$WIN32 && !$GL] + $File "$SRCDIR\dx9sdk\lib\d3dx9.lib" [$WIN32 && !$GL&&!$VS2015] + $File "$LIBCOMMON\d3dx9.lib" [$WIN32 && !$GL &&$VS2015] + } + + $Folder "Link Libraries" + { + $Lib bitmap + $Lib mathlib + $Lib tier2 + $Lib "$LIBCOMMON/bzip2" + $ImpLib togl [!$IS_LIB_PROJECT && $GL] + } +} diff --git a/materialsystem/shaderapidx9/shaderdevicebase.cpp b/materialsystem/shaderapidx9/shaderdevicebase.cpp new file mode 100644 index 0000000..aef5996 --- /dev/null +++ b/materialsystem/shaderapidx9/shaderdevicebase.cpp @@ -0,0 +1,1256 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +// +//=============================================================================// +#define DISABLE_PROTECTED_THINGS +#include "togl/rendermechanism.h" +#include "shaderdevicebase.h" +#include "tier1/KeyValues.h" +#include "tier1/convar.h" +#include "tier1/utlbuffer.h" +#include "tier0/icommandline.h" +#include "tier2/tier2.h" +#include "filesystem.h" +#include "datacache/idatacache.h" +#include "shaderapi/ishaderutil.h" +#include "shaderapibase.h" +#include "shaderapi/ishadershadow.h" +#include "shaderapi_global.h" +#include "winutils.h" + +#ifdef _X360 +#include "xbox/xbox_win32stubs.h" +#endif + +//----------------------------------------------------------------------------- +// Globals +//----------------------------------------------------------------------------- +IShaderUtil* g_pShaderUtil; // The main shader utility interface +CShaderDeviceBase *g_pShaderDevice; +CShaderDeviceMgrBase *g_pShaderDeviceMgr; +CShaderAPIBase *g_pShaderAPI; +IShaderShadow *g_pShaderShadow; + +bool g_bUseShaderMutex = false; // Shader mutex globals +bool g_bShaderAccessDisallowed; +CShaderMutex g_ShaderMutex; + +//----------------------------------------------------------------------------- +// FIXME: Hack related to setting command-line values for convars. Remove!!! +//----------------------------------------------------------------------------- +class CShaderAPIConVarAccessor : public IConCommandBaseAccessor +{ +public: + virtual bool RegisterConCommandBase( ConCommandBase *pCommand ) + { + // Link to engine's list instead + g_pCVar->RegisterConCommand( pCommand ); + + char const *pValue = g_pCVar->GetCommandLineValue( pCommand->GetName() ); + if( pValue && !pCommand->IsCommand() ) + { + ( ( ConVar * )pCommand )->SetValue( pValue ); + } + return true; + } +}; + +static void InitShaderAPICVars( ) +{ + static CShaderAPIConVarAccessor g_ConVarAccessor; + if ( g_pCVar ) + { + ConVar_Register( FCVAR_MATERIAL_SYSTEM_THREAD, &g_ConVarAccessor ); + } +} + + + +//----------------------------------------------------------------------------- +// Read dx support levels +//----------------------------------------------------------------------------- +#if defined( DX_TO_GL_ABSTRACTION ) + #if defined( OSX ) + // OSX + #define SUPPORT_CFG_FILE "dxsupport_mac.cfg" + // TODO: make this different for Mac? + #define SUPPORT_CFG_OVERRIDE_FILE "dxsupport_override.cfg" + #else + // Linux/Win GL + #define SUPPORT_CFG_FILE "dxsupport_linux.cfg" + // TODO: make this different for Linux? + #define SUPPORT_CFG_OVERRIDE_FILE "dxsupport_override.cfg" + #endif +#else + // D3D + #define SUPPORT_CFG_FILE "dxsupport.cfg" + #define SUPPORT_CFG_OVERRIDE_FILE "dxsupport_override.cfg" +#endif + + +//----------------------------------------------------------------------------- +// constructor, destructor +//----------------------------------------------------------------------------- +CShaderDeviceMgrBase::CShaderDeviceMgrBase() +{ + m_pDXSupport = NULL; +} + +CShaderDeviceMgrBase::~CShaderDeviceMgrBase() +{ +} + + +//----------------------------------------------------------------------------- +// Factory used to get at internal interfaces (used by shaderapi + shader dlls) +//----------------------------------------------------------------------------- +static CreateInterfaceFn s_TempFactory; +void *ShaderDeviceFactory( const char *pName, int *pReturnCode ) +{ + if (pReturnCode) + { + *pReturnCode = IFACE_OK; + } + + void *pInterface = s_TempFactory( pName, pReturnCode ); + if ( pInterface ) + return pInterface; + + pInterface = Sys_GetFactoryThis()( pName, pReturnCode ); + if ( pInterface ) + return pInterface; + + if ( pReturnCode ) + { + *pReturnCode = IFACE_FAILED; + } + return NULL; +} + +//----------------------------------------------------------------------------- +// Connect, disconnect +//----------------------------------------------------------------------------- +bool CShaderDeviceMgrBase::Connect( CreateInterfaceFn factory ) +{ + LOCK_SHADERAPI(); + + Assert( !g_pShaderDeviceMgr ); + + s_TempFactory = factory; + + // Connection/convar registration + CreateInterfaceFn actualFactory = ShaderDeviceFactory; + ConnectTier1Libraries( &actualFactory, 1 ); + InitShaderAPICVars(); + ConnectTier2Libraries( &actualFactory, 1 ); + g_pShaderUtil = (IShaderUtil*)ShaderDeviceFactory( SHADER_UTIL_INTERFACE_VERSION, NULL ); + g_pShaderDeviceMgr = this; + + s_TempFactory = NULL; + + if ( !g_pShaderUtil || !g_pFullFileSystem || !g_pShaderDeviceMgr ) + { + Warning( "ShaderAPIDx10 was unable to access the required interfaces!\n" ); + return false; + } + + // NOTE! : Overbright is 1.0 so that Hammer will work properly with the white bumped and unbumped lightmaps. + MathLib_Init( 2.2f, 2.2f, 0.0f, 2.0f ); + return true; +} + +void CShaderDeviceMgrBase::Disconnect() +{ + LOCK_SHADERAPI(); + + g_pShaderDeviceMgr = NULL; + g_pShaderUtil = NULL; + DisconnectTier2Libraries(); + ConVar_Unregister(); + DisconnectTier1Libraries(); + + if ( m_pDXSupport ) + { + m_pDXSupport->deleteThis(); + m_pDXSupport = NULL; + } +} + + +//----------------------------------------------------------------------------- +// Query interface +//----------------------------------------------------------------------------- +void *CShaderDeviceMgrBase::QueryInterface( const char *pInterfaceName ) +{ + if ( !Q_stricmp( pInterfaceName, SHADER_DEVICE_MGR_INTERFACE_VERSION ) ) + return ( IShaderDeviceMgr* )this; + if ( !Q_stricmp( pInterfaceName, MATERIALSYSTEM_HARDWARECONFIG_INTERFACE_VERSION ) ) + return ( IMaterialSystemHardwareConfig* )g_pHardwareConfig; + return NULL; +} + + +//----------------------------------------------------------------------------- +// Returns the hardware caps for a particular adapter +//----------------------------------------------------------------------------- +const HardwareCaps_t& CShaderDeviceMgrBase::GetHardwareCaps( int nAdapter ) const +{ + Assert( ( nAdapter >= 0 ) && ( nAdapter < GetAdapterCount() ) ); + return m_Adapters[nAdapter].m_ActualCaps; +} + + +//----------------------------------------------------------------------------- +// Utility methods for reading config scripts +//----------------------------------------------------------------------------- +static inline int ReadHexValue( KeyValues *pVal, const char *pName ) +{ + const char *pString = pVal->GetString( pName, NULL ); + if (!pString) + { + return -1; + } + + char *pTemp; + int nVal = strtol( pString, &pTemp, 16 ); + return (pTemp != pString) ? nVal : -1; +} + +static bool ReadBool( KeyValues *pGroup, const char *pKeyName, bool bDefault ) +{ + int nVal = pGroup->GetInt( pKeyName, -1 ); + if ( nVal != -1 ) + { + // Warning( "\t%s = %s\n", pKeyName, (nVal != false) ? "true" : "false" ); + return (nVal != false); + } + return bDefault; +} + +static void ReadInt( KeyValues *pGroup, const char *pKeyName, int nInvalidValue, int *pResult ) +{ + int nVal = pGroup->GetInt( pKeyName, nInvalidValue ); + if ( nVal != nInvalidValue ) + { + *pResult = nVal; + // Warning( "\t%s = %d\n", pKeyName, *pResult ); + } +} + + +//----------------------------------------------------------------------------- +// Utility method to copy over a keyvalue +//----------------------------------------------------------------------------- +static void AddKey( KeyValues *pDest, KeyValues *pSrc ) +{ + // Note this will replace already-existing values + switch( pSrc->GetDataType() ) + { + case KeyValues::TYPE_NONE: + break; + case KeyValues::TYPE_STRING: + pDest->SetString( pSrc->GetName(), pSrc->GetString() ); + break; + case KeyValues::TYPE_INT: + pDest->SetInt( pSrc->GetName(), pSrc->GetInt() ); + break; + case KeyValues::TYPE_FLOAT: + pDest->SetFloat( pSrc->GetName(), pSrc->GetFloat() ); + break; + case KeyValues::TYPE_PTR: + pDest->SetPtr( pSrc->GetName(), pSrc->GetPtr() ); + break; + case KeyValues::TYPE_WSTRING: + pDest->SetWString( pSrc->GetName(), pSrc->GetWString() ); + break; + case KeyValues::TYPE_COLOR: + pDest->SetColor( pSrc->GetName(), pSrc->GetColor() ); + break; + default: + Assert( 0 ); + break; + } +} + +//----------------------------------------------------------------------------- +// Finds if we have a dxlevel-specific config in the support keyvalues +//----------------------------------------------------------------------------- +KeyValues *CShaderDeviceMgrBase::FindDXLevelSpecificConfig( KeyValues *pKeyValues, int nDxLevel ) +{ + KeyValues *pGroup = pKeyValues->GetFirstSubKey(); + for( pGroup = pKeyValues->GetFirstSubKey(); pGroup; pGroup = pGroup->GetNextKey() ) + { + int nFoundDxLevel = pGroup->GetInt( "name", 0 ); + if( nFoundDxLevel == nDxLevel ) + return pGroup; + } + + return NULL; +} + +//----------------------------------------------------------------------------- +// Finds if we have a dxlevel and vendor-specific config in the support keyvalues +//----------------------------------------------------------------------------- +KeyValues *CShaderDeviceMgrBase::FindDXLevelAndVendorSpecificConfig( KeyValues *pKeyValues, int nDxLevel, int nVendorID ) +{ + if ( IsX360() ) + { + // 360 unique dxlevel implies hw config, vendor variance not applicable + return NULL; + } + + KeyValues *pGroup = pKeyValues->GetFirstSubKey(); + for( pGroup = pKeyValues->GetFirstSubKey(); pGroup; pGroup = pGroup->GetNextKey() ) + { + int nFoundDxLevel = pGroup->GetInt( "name", 0 ); + int nFoundVendorID = ReadHexValue( pGroup, "VendorID" ); + if( nFoundDxLevel == nDxLevel && nFoundVendorID == nVendorID ) + return pGroup; + } + + return NULL; +} + +//----------------------------------------------------------------------------- +// Finds if we have a vendor-specific config in the support keyvalues +//----------------------------------------------------------------------------- +KeyValues *CShaderDeviceMgrBase::FindCPUSpecificConfig( KeyValues *pKeyValues, int nCPUMhz, bool bAMD ) +{ + if ( IsX360() ) + { + // 360 unique dxlevel implies hw config, cpu variance not applicable + return NULL; + } + + for( KeyValues *pGroup = pKeyValues->GetFirstSubKey(); pGroup; pGroup = pGroup->GetNextKey() ) + { + const char *pName = pGroup->GetString( "name", NULL ); + if ( !pName ) + continue; + + if ( ( bAMD && Q_stristr( pName, "AMD" ) ) || + ( !bAMD && Q_stristr( pName, "Intel" ) ) ) + { + int nMinMegahertz = pGroup->GetInt( "min megahertz", -1 ); + int nMaxMegahertz = pGroup->GetInt( "max megahertz", -1 ); + if( nMinMegahertz == -1 || nMaxMegahertz == -1 ) + continue; + + if( nMinMegahertz <= nCPUMhz && nCPUMhz < nMaxMegahertz ) + return pGroup; + } + } + return NULL; +} + + +//----------------------------------------------------------------------------- +// Finds if we have a vendor-specific config in the support keyvalues +//----------------------------------------------------------------------------- +KeyValues *CShaderDeviceMgrBase::FindCardSpecificConfig( KeyValues *pKeyValues, int nVendorId, int nDeviceId ) +{ + if ( IsX360() ) + { + // 360 unique dxlevel implies hw config, vendor variance not applicable + return NULL; + } + + KeyValues *pGroup = pKeyValues->GetFirstSubKey(); + for( pGroup = pKeyValues->GetFirstSubKey(); pGroup; pGroup = pGroup->GetNextKey() ) + { + int nFoundVendorId = ReadHexValue( pGroup, "VendorID" ); + int nFoundDeviceIdMin = ReadHexValue( pGroup, "MinDeviceID" ); + int nFoundDeviceIdMax = ReadHexValue( pGroup, "MaxDeviceID" ); + if ( nFoundVendorId == nVendorId && nDeviceId >= nFoundDeviceIdMin && nDeviceId <= nFoundDeviceIdMax ) + return pGroup; + } + + return NULL; +} + + +//----------------------------------------------------------------------------- +// Finds if we have a vendor-specific config in the support keyvalues +//----------------------------------------------------------------------------- +KeyValues *CShaderDeviceMgrBase::FindMemorySpecificConfig( KeyValues *pKeyValues, int nSystemRamMB ) +{ + if ( IsX360() ) + { + // 360 unique dxlevel implies hw config, memory variance not applicable + return NULL; + } + + for( KeyValues *pGroup = pKeyValues->GetFirstSubKey(); pGroup; pGroup = pGroup->GetNextKey() ) + { + // Used to help us debug this code +// const char *pDebugName = pGroup->GetString( "name", "blah" ); + + int nMinMB = pGroup->GetInt( "min megabytes", -1 ); + int nMaxMB = pGroup->GetInt( "max megabytes", -1 ); + if ( nMinMB == -1 || nMaxMB == -1 ) + continue; + + if ( nMinMB <= nSystemRamMB && nSystemRamMB < nMaxMB ) + return pGroup; + } + return NULL; +} + + +//----------------------------------------------------------------------------- +// Finds if we have a texture mem size specific config +//----------------------------------------------------------------------------- +KeyValues *CShaderDeviceMgrBase::FindVidMemSpecificConfig( KeyValues *pKeyValues, int nVideoRamMB ) +{ + if ( IsX360() ) + { + // 360 unique dxlevel implies hw config, vidmem variance not applicable + return NULL; + } + + for( KeyValues *pGroup = pKeyValues->GetFirstSubKey(); pGroup; pGroup = pGroup->GetNextKey() ) + { + int nMinMB = pGroup->GetInt( "min megatexels", -1 ); + int nMaxMB = pGroup->GetInt( "max megatexels", -1 ); + if ( nMinMB == -1 || nMaxMB == -1 ) + continue; + + if ( nMinMB <= nVideoRamMB && nVideoRamMB < nMaxMB ) + return pGroup; + } + return NULL; +} + + +//----------------------------------------------------------------------------- +// Methods related to reading DX support levels given particular devices +//----------------------------------------------------------------------------- + + +//----------------------------------------------------------------------------- +// Reads in the dxsupport.cfg keyvalues +//----------------------------------------------------------------------------- +static void OverrideValues_R( KeyValues *pDest, KeyValues *pSrc ) +{ + // Any same-named values get overridden in pDest. + for ( KeyValues *pSrcValue=pSrc->GetFirstValue(); pSrcValue; pSrcValue=pSrcValue->GetNextValue() ) + { + // Shouldn't be a container for more keys. + Assert( pSrcValue->GetDataType() != KeyValues::TYPE_NONE ); + AddKey( pDest, pSrcValue ); + } + + // Recurse. + for ( KeyValues *pSrcDir=pSrc->GetFirstTrueSubKey(); pSrcDir; pSrcDir=pSrcDir->GetNextTrueSubKey() ) + { + Assert( pSrcDir->GetDataType() == KeyValues::TYPE_NONE ); + + KeyValues *pDestDir = pDest->FindKey( pSrcDir->GetName() ); + if ( pDestDir && pDestDir->GetDataType() == KeyValues::TYPE_NONE ) + { + OverrideValues_R( pDestDir, pSrcDir ); + } + } +} + +static KeyValues * FindMatchingGroup( KeyValues *pSrc, KeyValues *pMatch ) +{ + KeyValues *pMatchSubKey = pMatch->FindKey( "name" ); + bool bHasSubKey = ( pMatchSubKey && ( pMatchSubKey->GetDataType() != KeyValues::TYPE_NONE ) ); + const char *name = bHasSubKey ? pMatchSubKey->GetString() : NULL; + int nMatchVendorID = ReadHexValue( pMatch, "VendorID" ); + int nMatchMinDeviceID = ReadHexValue( pMatch, "MinDeviceID" ); + int nMatchMaxDeviceID = ReadHexValue( pMatch, "MaxDeviceID" ); + + KeyValues *pSrcGroup = NULL; + for ( pSrcGroup = pSrc->GetFirstTrueSubKey(); pSrcGroup; pSrcGroup = pSrcGroup->GetNextTrueSubKey() ) + { + if ( name ) + { + KeyValues *pSrcGroupName = pSrcGroup->FindKey( "name" ); + Assert( pSrcGroupName ); + Assert( pSrcGroupName->GetDataType() != KeyValues::TYPE_NONE ); + if ( Q_stricmp( pSrcGroupName->GetString(), name ) ) + continue; + } + + if ( nMatchVendorID >= 0 ) + { + int nVendorID = ReadHexValue( pSrcGroup, "VendorID" ); + if ( nMatchVendorID != nVendorID ) + continue; + } + + if ( nMatchMinDeviceID >= 0 && nMatchMaxDeviceID >= 0 ) + { + int nMinDeviceID = ReadHexValue( pSrcGroup, "MinDeviceID" ); + int nMaxDeviceID = ReadHexValue( pSrcGroup, "MaxDeviceID" ); + if ( nMinDeviceID < 0 || nMaxDeviceID < 0 ) + continue; + + if ( nMatchMinDeviceID > nMinDeviceID || nMatchMaxDeviceID < nMaxDeviceID ) + continue; + } + + return pSrcGroup; + } + return NULL; +} + +static void OverrideKeyValues( KeyValues *pDst, KeyValues *pSrc ) +{ + KeyValues *pSrcGroup = NULL; + for ( pSrcGroup = pSrc->GetFirstTrueSubKey(); pSrcGroup; pSrcGroup = pSrcGroup->GetNextTrueSubKey() ) + { + // Match each group in pSrc to one in pDst containing the same "name" value: + KeyValues * pDstGroup = FindMatchingGroup( pDst, pSrcGroup ); + //Assert( pDstGroup ); + if ( pDstGroup ) + { + OverrideValues_R( pDstGroup, pSrcGroup ); + } + } + + // if( CommandLine()->FindParm( "-debugdxsupport" ) ) + // { + // CUtlBuffer tmpBuf; + // pDst->RecursiveSaveToFile( tmpBuf, 0 ); + // g_pFullFileSystem->WriteFile( "gary.txt", NULL, tmpBuf ); + // } +} + +KeyValues *CShaderDeviceMgrBase::ReadDXSupportKeyValues() +{ + if ( CommandLine()->CheckParm( "-ignoredxsupportcfg" ) ) + return NULL; + + if ( m_pDXSupport ) + return m_pDXSupport; + + KeyValues *pCfg = new KeyValues( "dxsupport" ); + + const char *pPathID = "EXECUTABLE_PATH"; + if ( IsX360() && g_pFullFileSystem->GetDVDMode() == DVDMODE_STRICT ) + { + // 360 dvd optimzation, expect it inside the platform zip + pPathID = "PLATFORM"; + } + + // First try to read a game-specific config, if it exists + if ( !pCfg->LoadFromFile( g_pFullFileSystem, SUPPORT_CFG_FILE, pPathID ) ) + { + pCfg->deleteThis(); + return NULL; + } + + char pTempPath[1024]; + if ( g_pFullFileSystem->GetSearchPath( "GAME", false, pTempPath, sizeof(pTempPath) ) > 1 ) + { + // Is there a mod-specific override file? + KeyValues *pOverride = new KeyValues( "dxsupport_override" ); + if ( pOverride->LoadFromFile( g_pFullFileSystem, SUPPORT_CFG_OVERRIDE_FILE, "GAME" ) ) + { + OverrideKeyValues( pCfg, pOverride ); + } + + pOverride->deleteThis(); + } + + m_pDXSupport = pCfg; + return pCfg; +} + + + +//----------------------------------------------------------------------------- +// Returns the max dx support level achievable with this board +//----------------------------------------------------------------------------- +void CShaderDeviceMgrBase::ReadDXSupportLevels( HardwareCaps_t &caps ) +{ + // See if the file tells us otherwise + KeyValues *pCfg = ReadDXSupportKeyValues(); + if ( !pCfg ) + return; + + KeyValues *pDeviceKeyValues = FindCardSpecificConfig( pCfg, caps.m_VendorID, caps.m_DeviceID ); + if ( pDeviceKeyValues ) + { + // First, set the max dx level + int nMaxDXSupportLevel = 0; + ReadInt( pDeviceKeyValues, "MaxDXLevel", 0, &nMaxDXSupportLevel ); + if ( nMaxDXSupportLevel != 0 ) + { + caps.m_nMaxDXSupportLevel = nMaxDXSupportLevel; + } + + // Next, set the preferred dx level + int nDXSupportLevel = 0; + ReadInt( pDeviceKeyValues, "DXLevel", 0, &nDXSupportLevel ); + if ( nDXSupportLevel != 0 ) + { + caps.m_nDXSupportLevel = nDXSupportLevel; + // Don't slam up the dxlevel level to 92 on DX10 cards in OpenGL Linux/Win mode (otherwise Intel will get dxlevel 92 when we want 90) + if ( !( IsOpenGL() && ( IsLinux() || IsWindows() ) ) ) + { + if ( caps.m_bDX10Card ) + { + caps.m_nDXSupportLevel = 92; + } + } + } + else + { + caps.m_nDXSupportLevel = caps.m_nMaxDXSupportLevel; + } + } +} + + +//----------------------------------------------------------------------------- +// Loads the hardware caps, for cases in which the D3D caps lie or where we need to augment the caps +//----------------------------------------------------------------------------- +void CShaderDeviceMgrBase::LoadHardwareCaps( KeyValues *pGroup, HardwareCaps_t &caps ) +{ + if( !pGroup ) + return; + + // don't just blanket kill clip planes on POSIX, only shoot them down if we're running ARB, or asked for nouserclipplanes. + //FIXME need to take into account the caps bit that GLM can now provide, so NV can use normal clipping and ATI can fall back to fastclip. + + if ( CommandLine()->FindParm("-arbmode") || CommandLine()->CheckParm( "-nouserclip" ) ) + { + caps.m_UseFastClipping = true; + } + else + { + caps.m_UseFastClipping = ReadBool( pGroup, "NoUserClipPlanes", caps.m_UseFastClipping ); + } + + caps.m_bNeedsATICentroidHack = ReadBool( pGroup, "CentroidHack", caps.m_bNeedsATICentroidHack ); + caps.m_bDisableShaderOptimizations = ReadBool( pGroup, "DisableShaderOptimizations", caps.m_bDisableShaderOptimizations ); +} + + + +//----------------------------------------------------------------------------- +// Reads in the hardware caps from the dxsupport.cfg file +//----------------------------------------------------------------------------- +void CShaderDeviceMgrBase::ReadHardwareCaps( HardwareCaps_t &caps, int nDxLevel ) +{ + KeyValues *pCfg = ReadDXSupportKeyValues(); + if ( !pCfg ) + return; + + // Next, read the hardware caps for that dx support level. + KeyValues *pDxLevelKeyValues = FindDXLevelSpecificConfig( pCfg, nDxLevel ); + // Look for a vendor specific line for a given dxlevel. + KeyValues *pDXLevelAndVendorKeyValue = FindDXLevelAndVendorSpecificConfig( pCfg, nDxLevel, caps.m_VendorID ); + // Finally, override the hardware caps based on the specific card + KeyValues *pCardKeyValues = FindCardSpecificConfig( pCfg, caps.m_VendorID, caps.m_DeviceID ); + + // Apply + if( pCardKeyValues && ReadHexValue( pCardKeyValues, "MinDeviceID" ) == 0 && ReadHexValue( pCardKeyValues, "MaxDeviceID" ) == 0xffff ) + { + // The card specific case is a catch all for device ids, so run it before running the dxlevel and card specific stuff. + LoadHardwareCaps( pDxLevelKeyValues, caps ); + LoadHardwareCaps( pCardKeyValues, caps ); + LoadHardwareCaps( pDXLevelAndVendorKeyValue, caps ); + } + else + { + // The card specific case is a small range of cards, so run it last to override all other configs. + LoadHardwareCaps( pDxLevelKeyValues, caps ); + // don't run this one since we have a specific config for this card. + // LoadHardwareCaps( pDXLevelAndVendorKeyValue, caps ); + LoadHardwareCaps( pCardKeyValues, caps ); + } +} + + +//----------------------------------------------------------------------------- +// Reads in ConVars + config variables +//----------------------------------------------------------------------------- +void CShaderDeviceMgrBase::LoadConfig( KeyValues *pKeyValues, KeyValues *pConfiguration ) +{ + if( !pKeyValues ) + return; + + if( CommandLine()->FindParm( "-debugdxsupport" ) ) + { + CUtlBuffer tmpBuf; + pKeyValues->RecursiveSaveToFile( tmpBuf, 0 ); + Warning( "%s\n", ( const char * )tmpBuf.Base() ); + } + for( KeyValues *pGroup = pKeyValues->GetFirstSubKey(); pGroup; pGroup = pGroup->GetNextKey() ) + { + AddKey( pConfiguration, pGroup ); + } +} + + +//----------------------------------------------------------------------------- +// Computes amount of ram +//----------------------------------------------------------------------------- +static unsigned long GetRam() +{ + MEMORYSTATUS stat; + GlobalMemoryStatus( &stat ); + + char buf[256]; + V_snprintf( buf, sizeof( buf ), "GlobalMemoryStatus: %llu\n", (uint64)(stat.dwTotalPhys) ); + Plat_DebugString( buf ); + + return (stat.dwTotalPhys / (1024 * 1024)); +} + + +//----------------------------------------------------------------------------- +// Gets the recommended configuration associated with a particular dx level +//----------------------------------------------------------------------------- +bool CShaderDeviceMgrBase::GetRecommendedConfigurationInfo( int nAdapter, int nDXLevel, int nVendorID, int nDeviceID, KeyValues *pConfiguration ) +{ + LOCK_SHADERAPI(); + + const HardwareCaps_t& caps = GetHardwareCaps( nAdapter ); + if ( nDXLevel == 0 ) + { + nDXLevel = caps.m_nDXSupportLevel; + } + nDXLevel = GetClosestActualDXLevel( nDXLevel ); + if ( nDXLevel > caps.m_nMaxDXSupportLevel ) + return false; + + KeyValues *pCfg = ReadDXSupportKeyValues(); + if ( !pCfg ) + return true; + + // Look for a dxlevel specific line + KeyValues *pDxLevelKeyValues = FindDXLevelSpecificConfig( pCfg, nDXLevel ); + // Look for a vendor specific line for a given dxlevel. + KeyValues *pDXLevelAndVendorKeyValue = FindDXLevelAndVendorSpecificConfig( pCfg, nDXLevel, nVendorID ); + // Next, override with device-specific overrides + KeyValues *pCardKeyValues = FindCardSpecificConfig( pCfg, nVendorID, nDeviceID ); + + // Apply + if ( pCardKeyValues && ReadHexValue( pCardKeyValues, "MinDeviceID" ) == 0 && ReadHexValue( pCardKeyValues, "MaxDeviceID" ) == 0xffff ) + { + // The card specific case is a catch all for device ids, so run it before running the dxlevel and card specific stuff. + LoadConfig( pDxLevelKeyValues, pConfiguration ); + LoadConfig( pCardKeyValues, pConfiguration ); + LoadConfig( pDXLevelAndVendorKeyValue, pConfiguration ); + } + else + { + // The card specific case is a small range of cards, so run it last to override all other configs. + LoadConfig( pDxLevelKeyValues, pConfiguration ); + // don't run this one since we have a specific config for this card. + // LoadConfig( pDXLevelAndVendorKeyValue, pConfiguration ); + LoadConfig( pCardKeyValues, pConfiguration ); + } + + // Next, override with cpu-speed based overrides + const CPUInformation& pi = *GetCPUInformation(); + int nCPUSpeedMhz = (int)(pi.m_Speed / 1000000.0f); + + bool bAMD = Q_stristr( pi.m_szProcessorID, "amd" ) != NULL; + + char buf[256]; + V_snprintf( buf, sizeof( buf ), "CShaderDeviceMgrBase::GetRecommendedConfigurationInfo: CPU speed: %d MHz, Processor: %s\n", nCPUSpeedMhz, pi.m_szProcessorID ); + Plat_DebugString( buf ); + + KeyValues *pCPUKeyValues = FindCPUSpecificConfig( pCfg, nCPUSpeedMhz, bAMD ); + LoadConfig( pCPUKeyValues, pConfiguration ); + + // override with system memory-size based overrides + int nSystemMB = GetRam(); + DevMsg( "%d MB of system RAM\n", nSystemMB ); + KeyValues *pMemoryKeyValues = FindMemorySpecificConfig( pCfg, nSystemMB ); + LoadConfig( pMemoryKeyValues, pConfiguration ); + + // override with texture memory-size based overrides + int nTextureMemorySize = GetVidMemBytes( nAdapter ); + int vidMemMB = nTextureMemorySize / ( 1024 * 1024 ); + KeyValues *pVidMemKeyValues = FindVidMemSpecificConfig( pCfg, vidMemMB ); + if ( pVidMemKeyValues && nTextureMemorySize > 0 ) + { + if ( CommandLine()->FindParm( "-debugdxsupport" ) ) + { + CUtlBuffer tmpBuf; + pVidMemKeyValues->RecursiveSaveToFile( tmpBuf, 0 ); + Warning( "pVidMemKeyValues\n%s\n", ( const char * )tmpBuf.Base() ); + } + KeyValues *pMatPicmipKeyValue = pVidMemKeyValues->FindKey( "ConVar.mat_picmip", false ); + + // FIXME: Man, is this brutal. If it wasn't 1 day till orange box ship, I'd do something in dxsupport maybe + if ( pMatPicmipKeyValue && ( ( nDXLevel == caps.m_nMaxDXSupportLevel ) || ( vidMemMB < 100 ) ) ) + { + KeyValues *pConfigMatPicMip = pConfiguration->FindKey( "ConVar.mat_picmip", false ); + int newPicMip = pMatPicmipKeyValue->GetInt(); + int oldPicMip = pConfigMatPicMip ? pConfigMatPicMip->GetInt() : 0; + pConfiguration->SetInt( "ConVar.mat_picmip", max( newPicMip, oldPicMip ) ); + } + } + + // Hack to slam the mat_dxlevel ConVar to match the requested dxlevel + pConfiguration->SetInt( "ConVar.mat_dxlevel", nDXLevel ); + + if ( CommandLine()->FindParm( "-debugdxsupport" ) ) + { + CUtlBuffer tmpBuf; + pConfiguration->RecursiveSaveToFile( tmpBuf, 0 ); + Warning( "final config:\n%s\n", ( const char * )tmpBuf.Base() ); + } + + return true; +} + + +//----------------------------------------------------------------------------- +// Gets recommended congifuration for a particular adapter at a particular dx level +//----------------------------------------------------------------------------- +bool CShaderDeviceMgrBase::GetRecommendedConfigurationInfo( int nAdapter, int nDXLevel, KeyValues *pCongifuration ) +{ + Assert( nAdapter >= 0 && nAdapter <= GetAdapterCount() ); + MaterialAdapterInfo_t info; + GetAdapterInfo( nAdapter, info ); + return GetRecommendedConfigurationInfo( nAdapter, nDXLevel, info.m_VendorID, info.m_DeviceID, pCongifuration ); +} + + +//----------------------------------------------------------------------------- +// Returns only valid dx levels +//----------------------------------------------------------------------------- +int CShaderDeviceMgrBase::GetClosestActualDXLevel( int nDxLevel ) const +{ + if ( nDxLevel < ABSOLUTE_MINIMUM_DXLEVEL ) + return ABSOLUTE_MINIMUM_DXLEVEL; + + if ( nDxLevel == 80 ) + return 80; + if ( nDxLevel <= 89 ) + return 81; + + if ( IsOpenGL() ) + { + return ( nDxLevel <= 90 ) ? 90 : 92; + } + + if ( nDxLevel <= 94 ) + return 90; + + if ( IsX360() && nDxLevel <= 98 ) + return 98; + if ( nDxLevel <= 99 ) + return 95; + return 100; +} + + +//----------------------------------------------------------------------------- +// Mode change callback +//----------------------------------------------------------------------------- +void CShaderDeviceMgrBase::AddModeChangeCallback( ShaderModeChangeCallbackFunc_t func ) +{ + LOCK_SHADERAPI(); + Assert( func && m_ModeChangeCallbacks.Find( func ) < 0 ); + m_ModeChangeCallbacks.AddToTail( func ); +} + +void CShaderDeviceMgrBase::RemoveModeChangeCallback( ShaderModeChangeCallbackFunc_t func ) +{ + LOCK_SHADERAPI(); + m_ModeChangeCallbacks.FindAndRemove( func ); +} + +void CShaderDeviceMgrBase::InvokeModeChangeCallbacks() +{ + int nCount = m_ModeChangeCallbacks.Count(); + for ( int i = 0; i < nCount; ++i ) + { + m_ModeChangeCallbacks[i](); + } +} + + +//----------------------------------------------------------------------------- +// Factory to return from SetMode +//----------------------------------------------------------------------------- +void* CShaderDeviceMgrBase::ShaderInterfaceFactory( const char *pInterfaceName, int *pReturnCode ) +{ + if ( pReturnCode ) + { + *pReturnCode = IFACE_OK; + } + if ( !Q_stricmp( pInterfaceName, SHADER_DEVICE_INTERFACE_VERSION ) ) + return static_cast< IShaderDevice* >( g_pShaderDevice ); + if ( !Q_stricmp( pInterfaceName, SHADERAPI_INTERFACE_VERSION ) ) + return static_cast< IShaderAPI* >( g_pShaderAPI ); + if ( !Q_stricmp( pInterfaceName, SHADERSHADOW_INTERFACE_VERSION ) ) + return static_cast< IShaderShadow* >( g_pShaderShadow ); + + if ( pReturnCode ) + { + *pReturnCode = IFACE_FAILED; + } + return NULL; +} + + +//----------------------------------------------------------------------------- +// +// The Base implementation of the shader device +// +//----------------------------------------------------------------------------- + + +//----------------------------------------------------------------------------- +// constructor, destructor +//----------------------------------------------------------------------------- +CShaderDeviceBase::CShaderDeviceBase() +{ + m_bInitialized = false; + m_nAdapter = -1; + m_hWnd = NULL; + m_hWndCookie = NULL; + m_dwThreadId = ThreadGetCurrentId(); +} + +CShaderDeviceBase::~CShaderDeviceBase() +{ +} + +void CShaderDeviceBase::SetCurrentThreadAsOwner() +{ + m_dwThreadId = ThreadGetCurrentId(); +} + +void CShaderDeviceBase::RemoveThreadOwner() +{ + m_dwThreadId = 0xFFFFFFFF; +} + +bool CShaderDeviceBase::ThreadOwnsDevice() +{ + if ( ThreadGetCurrentId() == m_dwThreadId ) + return true; + return false; +} + + +// Methods of IShaderDevice +ImageFormat CShaderDeviceBase::GetBackBufferFormat() const +{ + return IMAGE_FORMAT_UNKNOWN; +} + +int CShaderDeviceBase::StencilBufferBits() const +{ + return 0; +} + +bool CShaderDeviceBase::IsAAEnabled() const +{ + return false; +} + + +//----------------------------------------------------------------------------- +// Methods for interprocess communication to release resources +//----------------------------------------------------------------------------- +#define MATERIAL_SYSTEM_WINDOW_ID 0xFEEDDEAD + +#ifdef USE_ACTUAL_DX +static VD3DHWND GetTopmostParentWindow( VD3DHWND hWnd ) +{ + // Find the parent window... + VD3DHWND hParent = GetParent( hWnd ); + while ( hParent ) + { + hWnd = hParent; + hParent = GetParent( hWnd ); + } + + return hWnd; +} + +static BOOL CALLBACK EnumChildWindowsProc( VD3DHWND hWnd, LPARAM lParam ) +{ + int windowId = GetWindowLongPtr( hWnd, GWLP_USERDATA ); + if (windowId == MATERIAL_SYSTEM_WINDOW_ID) + { + COPYDATASTRUCT copyData; + copyData.dwData = lParam; + copyData.cbData = 0; + copyData.lpData = 0; + + SendMessage(hWnd, WM_COPYDATA, 0, (LPARAM)©Data); + } + return TRUE; +} + +static BOOL CALLBACK EnumWindowsProc( VD3DHWND hWnd, LPARAM lParam ) +{ + EnumChildWindows( hWnd, EnumChildWindowsProc, lParam ); + return TRUE; +} + +static BOOL CALLBACK EnumWindowsProcNotThis( VD3DHWND hWnd, LPARAM lParam ) +{ + if ( g_pShaderDevice && ( GetTopmostParentWindow( (VD3DHWND)g_pShaderDevice->GetIPCHWnd() ) == hWnd ) ) + return TRUE; + + EnumChildWindows( hWnd, EnumChildWindowsProc, lParam ); + return TRUE; +} +#endif + +//----------------------------------------------------------------------------- +// Adds a hook to let us know when other instances are setting the mode +//----------------------------------------------------------------------------- + +#ifdef STRICT +#define WINDOW_PROC WNDPROC +#else +#define WINDOW_PROC FARPROC +#endif + +#ifdef USE_ACTUAL_DX +static LRESULT CALLBACK ShaderDX8WndProc(VD3DHWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ) +{ +#if !defined( _X360 ) + // FIXME: Should these IPC messages tell when an app has focus or not? + // If so, we'd want to totally disable the shader api layer when an app + // doesn't have focus. + + // Look for the special IPC message that tells us we're trying to set + // the mode.... + switch(msg) + { + case WM_COPYDATA: + { + if ( !g_pShaderDevice ) + break; + + COPYDATASTRUCT* pData = (COPYDATASTRUCT*)lParam; + + // that number is our magic cookie number + if ( pData->dwData == CShaderDeviceBase::RELEASE_MESSAGE ) + { + g_pShaderDevice->OtherAppInitializing(true); + } + else if ( pData->dwData == CShaderDeviceBase::REACQUIRE_MESSAGE ) + { + g_pShaderDevice->OtherAppInitializing(false); + } + else if ( pData->dwData == CShaderDeviceBase::EVICT_MESSAGE ) + { + g_pShaderDevice->EvictManagedResourcesInternal( ); + } + } + break; + } + + return DefWindowProc( hWnd, msg, wParam, lParam ); +#endif +} +#endif + + +//----------------------------------------------------------------------------- +// Install, remove ability to talk to other shaderapi apps +//----------------------------------------------------------------------------- +void CShaderDeviceBase::InstallWindowHook( void* hWnd ) +{ + Assert( m_hWndCookie == NULL ); +#ifdef USE_ACTUAL_DX +#if !defined( _X360 ) + VD3DHWND hParent = GetTopmostParentWindow( (VD3DHWND)hWnd ); + + // Attach a child window to the parent; we're gonna store special info there + // We can't use the USERDATA, cause other apps may want to use this. + HINSTANCE hInst = (HINSTANCE)GetWindowLongPtr( hParent, GWLP_HINSTANCE ); + WNDCLASS wc; + memset( &wc, 0, sizeof( wc ) ); + wc.style = CS_NOCLOSE | CS_PARENTDC; + wc.lpfnWndProc = ShaderDX8WndProc; + wc.hInstance = hInst; + wc.lpszClassName = "shaderdx8"; + + // In case an old one is sitting around still... + UnregisterClass( "shaderdx8", hInst ); + + RegisterClass( &wc ); + + // Create the window + m_hWndCookie = CreateWindow( "shaderdx8", "shaderdx8", WS_CHILD, + 0, 0, 0, 0, hParent, NULL, hInst, NULL ); + + // Marks it as a material system window + SetWindowLongPtr( (VD3DHWND)m_hWndCookie, GWLP_USERDATA, MATERIAL_SYSTEM_WINDOW_ID ); +#endif +#endif +} + +void CShaderDeviceBase::RemoveWindowHook( void* hWnd ) +{ +#ifdef USE_ACTUAL_DX +#if !defined( _X360 ) + if ( m_hWndCookie ) + { + DestroyWindow( (VD3DHWND)m_hWndCookie ); + m_hWndCookie = 0; + } + + VD3DHWND hParent = GetTopmostParentWindow( (VD3DHWND)hWnd ); + HINSTANCE hInst = (HINSTANCE)GetWindowLongPtr( hParent, GWLP_HINSTANCE ); + UnregisterClass( "shaderdx8", hInst ); +#endif +#endif +} + + +//----------------------------------------------------------------------------- +// Sends a message to other shaderapi applications +//----------------------------------------------------------------------------- +void CShaderDeviceBase::SendIPCMessage( IPCMessage_t msg ) +{ +#ifdef USE_ACTUAL_DX +#if !defined( _X360 ) + // Gotta send this to all windows, since we don't know which ones + // are material system apps... + if ( msg != EVICT_MESSAGE ) + { + EnumWindows( EnumWindowsProc, (DWORD)msg ); + } + else + { + EnumWindows( EnumWindowsProcNotThis, (DWORD)msg ); + } +#endif +#endif +} + + +//----------------------------------------------------------------------------- +// Find view +//----------------------------------------------------------------------------- +int CShaderDeviceBase::FindView( void* hWnd ) const +{ + /* FIXME: Is this necessary? + // Look for the view in the list of views + for (int i = m_Views.Count(); --i >= 0; ) + { + if (m_Views[i].m_HWnd == (VD3DHWND)hwnd) + return i; + } + */ + return -1; +} + +//----------------------------------------------------------------------------- +// Creates a child window +//----------------------------------------------------------------------------- +bool CShaderDeviceBase::AddView( void* hWnd ) +{ + LOCK_SHADERAPI(); + /* + // If we haven't created a device yet + if (!Dx9Device()) + return false; + + // Make sure no duplicate hwnds... + if (FindView(hwnd) >= 0) + return false; + + // In this case, we need to create the device; this is our + // default swap chain. This here says we're gonna use a part of the + // existing buffer and just grab that. + int view = m_Views.AddToTail(); + m_Views[view].m_HWnd = (VD3DHWND)hwnd; + // memcpy( &m_Views[view].m_PresentParamters, m_PresentParameters, sizeof(m_PresentParamters) ); + + HRESULT hr; + hr = Dx9Device()->CreateAdditionalSwapChain( &m_PresentParameters, + &m_Views[view].m_pSwapChain ); + return !FAILED(hr); + */ + + return true; +} + +void CShaderDeviceBase::RemoveView( void* hWnd ) +{ + LOCK_SHADERAPI(); + /* + // Look for the view in the list of views + int i = FindView(hwnd); + if (i >= 0) + { + // FIXME m_Views[i].m_pSwapChain->Release(); + m_Views.FastRemove(i); + } + */ +} + +//----------------------------------------------------------------------------- +// Activates a child window +//----------------------------------------------------------------------------- +void CShaderDeviceBase::SetView( void* hWnd ) +{ + LOCK_SHADERAPI(); + + ShaderViewport_t viewport; + g_pShaderAPI->GetViewports( &viewport, 1 ); + + // Get the window (*not* client) rect of the view window + m_ViewHWnd = (VD3DHWND)hWnd; + GetWindowSize( m_nWindowWidth, m_nWindowHeight ); + + // Reset the viewport (takes into account the view rect) + // Don't need to set the viewport if it's not ready + g_pShaderAPI->SetViewports( 1, &viewport ); +} + + +//----------------------------------------------------------------------------- +// Gets the window size +//----------------------------------------------------------------------------- +void CShaderDeviceBase::GetWindowSize( int& nWidth, int& nHeight ) const +{ +#if defined( USE_SDL ) + + // this matches up to what the threaded material system does + g_pShaderAPI->GetBackBufferDimensions( nWidth, nHeight ); + +#else + + // If the window was minimized last time swap buffers happened, or if it's iconic now, + // return 0 size +#ifdef _WIN32 + if ( !m_bIsMinimized && !IsIconic( ( HWND )m_hWnd ) ) +#else + if ( !m_bIsMinimized && !IsIconic( (VD3DHWND)m_hWnd ) ) +#endif + { + // NOTE: Use the 'current view' (which may be the same as the main window) + RECT rect; +#ifdef _WIN32 + GetClientRect( ( HWND )m_ViewHWnd, &rect ); +#else + toglGetClientRect( (VD3DHWND)m_ViewHWnd, &rect ); +#endif + nWidth = rect.right - rect.left; + nHeight = rect.bottom - rect.top; + } + else + { + nWidth = nHeight = 0; + } + +#endif +} + + diff --git a/materialsystem/shaderapidx9/shaderdevicebase.h b/materialsystem/shaderapidx9/shaderdevicebase.h new file mode 100644 index 0000000..37d7cc0 --- /dev/null +++ b/materialsystem/shaderapidx9/shaderdevicebase.h @@ -0,0 +1,234 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +// +//===========================================================================// + +#ifndef SHADERDEVICEBASE_H +#define SHADERDEVICEBASE_H + +#ifdef _WIN32 +#pragma once +#endif + + +#include "togl/rendermechanism.h" +#include "shaderapi/IShaderDevice.h" +#include "IHardwareConfigInternal.h" +#include "bitmap/imageformat.h" +#include "materialsystem/imaterialsystem.h" +#include "hardwareconfig.h" + + +//----------------------------------------------------------------------------- +// Forward declarations +//----------------------------------------------------------------------------- +class KeyValues; + + +//----------------------------------------------------------------------------- +// define this if you want to run with NVPERFHUD +//----------------------------------------------------------------------------- +//#define NVPERFHUD 1 + + +//----------------------------------------------------------------------------- +// Uncomment this to activate the reference rasterizer +//----------------------------------------------------------------------------- +//#define USE_REFERENCE_RASTERIZER 1 + +//----------------------------------------------------------------------------- +// Uncomment to check for -nulldevice on command line and use D3DDEVTYPE_NULLREF. +//----------------------------------------------------------------------------- +#define ENABLE_NULLREF_DEVICE_SUPPORT + +//----------------------------------------------------------------------------- +// The Base implementation of the shader device +//----------------------------------------------------------------------------- +class CShaderDeviceMgrBase : public IShaderDeviceMgr +{ +public: + // constructor, destructor + CShaderDeviceMgrBase(); + virtual ~CShaderDeviceMgrBase(); + + // Methods of IAppSystem + virtual bool Connect( CreateInterfaceFn factory ); + virtual void Disconnect(); + virtual void *QueryInterface( const char *pInterfaceName ); + + // Methods of IShaderDeviceMgr + virtual bool GetRecommendedConfigurationInfo( int nAdapter, int nDXLevel, KeyValues *pCongifuration ); + virtual void AddModeChangeCallback( ShaderModeChangeCallbackFunc_t func ); + virtual void RemoveModeChangeCallback( ShaderModeChangeCallbackFunc_t func ); + + // Reads in the hardware caps from the dxsupport.cfg file + void ReadHardwareCaps( HardwareCaps_t &caps, int nDxLevel ); + + // Reads in the max + preferred DX support level + void ReadDXSupportLevels( HardwareCaps_t &caps ); + + // Returns the hardware caps for a particular adapter + const HardwareCaps_t& GetHardwareCaps( int nAdapter ) const; + + // Invokes mode change callbacks + void InvokeModeChangeCallbacks(); + + // Factory to return from SetMode + static void* ShaderInterfaceFactory( const char *pInterfaceName, int *pReturnCode ); + + // Returns only valid dx levels + int GetClosestActualDXLevel( int nDxLevel ) const; + +protected: + struct AdapterInfo_t + { + HardwareCaps_t m_ActualCaps; + }; + +private: + // Reads in the dxsupport.cfg keyvalues + KeyValues *ReadDXSupportKeyValues(); + + // Reads in ConVars + config variables + void LoadConfig( KeyValues *pKeyValues, KeyValues *pConfiguration ); + + // Loads the hardware caps, for cases in which the D3D caps lie or where we need to augment the caps + void LoadHardwareCaps( KeyValues *pGroup, HardwareCaps_t &caps ); + + // Gets the recommended configuration associated with a particular dx level + bool GetRecommendedConfigurationInfo( int nAdapter, int nDXLevel, int nVendorID, int nDeviceID, KeyValues *pConfiguration ); + + // Returns the amount of video memory in bytes for a particular adapter + virtual int GetVidMemBytes( int nAdapter ) const = 0; + + // Looks for override keyvalues in the dxsupport cfg keyvalues + KeyValues *FindDXLevelSpecificConfig( KeyValues *pKeyValues, int nDxLevel ); + KeyValues *FindDXLevelAndVendorSpecificConfig( KeyValues *pKeyValues, int nDxLevel, int nVendorID ); + KeyValues *FindCPUSpecificConfig( KeyValues *pKeyValues, int nCPUMhz, bool bAMD ); + KeyValues *FindMemorySpecificConfig( KeyValues *pKeyValues, int nSystemRamMB ); + KeyValues *FindVidMemSpecificConfig( KeyValues *pKeyValues, int nVideoRamMB ); + KeyValues *FindCardSpecificConfig( KeyValues *pKeyValues, int nVendorID, int nDeviceID ); + +protected: + // Stores adapter info for all adapters + CUtlVector m_Adapters; + + // Installed mode change callbacks + CUtlVector< ShaderModeChangeCallbackFunc_t > m_ModeChangeCallbacks; + + KeyValues *m_pDXSupport; +}; + + +//----------------------------------------------------------------------------- +// The Base implementation of the shader device +//----------------------------------------------------------------------------- +class CShaderDeviceBase : public IShaderDevice +{ +public: + enum IPCMessage_t + { + RELEASE_MESSAGE = 0x5E740DE0, + REACQUIRE_MESSAGE = 0x5E740DE1, + EVICT_MESSAGE = 0x5E740DE2, + }; + + // Methods of IShaderDevice +public: + virtual ImageFormat GetBackBufferFormat() const; + virtual int StencilBufferBits() const; + virtual bool IsAAEnabled() const; + virtual bool AddView( void* hWnd ); + virtual void RemoveView( void* hWnd ); + virtual void SetView( void* hWnd ); + virtual void GetWindowSize( int& nWidth, int& nHeight ) const; + + // Methods exposed to the rest of shader api + virtual bool InitDevice( void *hWnd, int nAdapter, const ShaderDeviceInfo_t& mode ) = 0; + virtual void ShutdownDevice() = 0; + virtual bool IsDeactivated() const = 0; + +public: + // constructor, destructor + CShaderDeviceBase(); + virtual ~CShaderDeviceBase(); + + virtual void OtherAppInitializing( bool initializing ) {} + virtual void EvictManagedResourcesInternal() {} + + void* GetIPCHWnd(); + void SendIPCMessage( IPCMessage_t message ); + +protected: + // IPC communication for multiple shaderapi apps + void InstallWindowHook( void *hWnd ); + void RemoveWindowHook( void *hWnd ); + void SetCurrentThreadAsOwner(); + void RemoveThreadOwner(); + bool ThreadOwnsDevice(); + + // Finds a child window + int FindView( void* hWnd ) const; + + int m_nAdapter; + void *m_hWnd; + void* m_hWndCookie; + bool m_bInitialized : 1; + bool m_bIsMinimized : 1; + + // The current view hwnd + void* m_ViewHWnd; + + int m_nWindowWidth; + int m_nWindowHeight; + uint32 m_dwThreadId; +}; + + +//----------------------------------------------------------------------------- +// Inline methods +//----------------------------------------------------------------------------- +inline void* CShaderDeviceBase::GetIPCHWnd() +{ + return m_hWndCookie; +} + + +//----------------------------------------------------------------------------- +// Helper class to reduce code related to shader buffers +//----------------------------------------------------------------------------- +template< class T > +class CShaderBuffer : public IShaderBuffer +{ +public: + CShaderBuffer( T *pBlob ) : m_pBlob( pBlob ) {} + + virtual size_t GetSize() const + { + return m_pBlob ? m_pBlob->GetBufferSize() : 0; + } + + virtual const void* GetBits() const + { + return m_pBlob ? m_pBlob->GetBufferPointer() : NULL; + } + + virtual void Release() + { + if ( m_pBlob ) + { + m_pBlob->Release(); + } + delete this; + } + +private: + T *m_pBlob; +}; + + + +#endif // SHADERDEVICEBASE_H \ No newline at end of file diff --git a/materialsystem/shaderapidx9/shaderdevicedx10.cpp b/materialsystem/shaderapidx9/shaderdevicedx10.cpp new file mode 100644 index 0000000..39de5a1 --- /dev/null +++ b/materialsystem/shaderapidx9/shaderdevicedx10.cpp @@ -0,0 +1,1002 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +// +//===========================================================================// + +#include +#include + +#include "shaderdevicedx10.h" +#include "shaderdevicedx8.h" +#include "shaderapi/ishaderutil.h" +#include "shaderapidx10.h" +#include "shadershadowdx10.h" +#include "meshdx10.h" +#include "shaderapidx10_global.h" +#include "tier1/KeyValues.h" +#include "tier2/tier2.h" +#include "tier0/icommandline.h" +#include "inputlayoutdx10.h" +#include "shaderapibase.h" + + +//----------------------------------------------------------------------------- +// Explicit instantiation of shader buffer implementation +//----------------------------------------------------------------------------- +template class CShaderBuffer< ID3D10Blob >; + + +//----------------------------------------------------------------------------- +// +// Device manager +// +//----------------------------------------------------------------------------- +static CShaderDeviceMgrDx10 g_ShaderDeviceMgrDx10; + +EXPOSE_SINGLE_INTERFACE_GLOBALVAR( CShaderDeviceMgrDx10, IShaderDeviceMgr, + SHADER_DEVICE_MGR_INTERFACE_VERSION, g_ShaderDeviceMgrDx10 ) + +static CShaderDeviceDx10 g_ShaderDeviceDx10; +CShaderDeviceDx10* g_pShaderDeviceDx10 = &g_ShaderDeviceDx10; + +//----------------------------------------------------------------------------- +// constructor, destructor +//----------------------------------------------------------------------------- +CShaderDeviceMgrDx10::CShaderDeviceMgrDx10() +{ + m_pDXGIFactory = NULL; + m_bObeyDxCommandlineOverride = true; +} + +CShaderDeviceMgrDx10::~CShaderDeviceMgrDx10() +{ +} + + +//----------------------------------------------------------------------------- +// Connect, disconnect +//----------------------------------------------------------------------------- +bool CShaderDeviceMgrDx10::Connect( CreateInterfaceFn factory ) +{ + LOCK_SHADERAPI(); + + if ( !BaseClass::Connect( factory ) ) + return false; + + HRESULT hr = CreateDXGIFactory( __uuidof(IDXGIFactory), (void**)(&m_pDXGIFactory) ); + if ( FAILED( hr ) ) + { + Warning( "Failed to create the DXGI Factory!\n" ); + return false; + } + + InitAdapterInfo(); + return true; +} + +void CShaderDeviceMgrDx10::Disconnect() +{ + LOCK_SHADERAPI(); + + if ( m_pDXGIFactory ) + { + m_pDXGIFactory->Release(); + m_pDXGIFactory = NULL; + } + + BaseClass::Disconnect(); +} + + +//----------------------------------------------------------------------------- +// Initialization +//----------------------------------------------------------------------------- +InitReturnVal_t CShaderDeviceMgrDx10::Init( ) +{ + LOCK_SHADERAPI(); + + return INIT_OK; +} + + +//----------------------------------------------------------------------------- +// Shutdown +//----------------------------------------------------------------------------- +void CShaderDeviceMgrDx10::Shutdown( ) +{ + LOCK_SHADERAPI(); + + if ( g_pShaderDevice ) + { + g_pShaderDevice->ShutdownDevice(); + g_pShaderDevice = NULL; + } +} + + +//----------------------------------------------------------------------------- +// Initialize adapter information +//----------------------------------------------------------------------------- +void CShaderDeviceMgrDx10::InitAdapterInfo() +{ + m_Adapters.RemoveAll(); + + IDXGIAdapter *pAdapter; + for( UINT nCount = 0; m_pDXGIFactory->EnumAdapters( nCount, &pAdapter ) != DXGI_ERROR_NOT_FOUND; ++nCount ) + { + int j = m_Adapters.AddToTail(); + AdapterInfo_t &info = m_Adapters[j]; + +#ifdef _DEBUG + memset( &info.m_ActualCaps, 0xDD, sizeof(info.m_ActualCaps) ); +#endif + + IDXGIOutput *pOutput = GetAdapterOutput( nCount ); + info.m_ActualCaps.m_bDeviceOk = ComputeCapsFromD3D( &info.m_ActualCaps, pAdapter, pOutput ); + if ( !info.m_ActualCaps.m_bDeviceOk ) + continue; + + ReadDXSupportLevels( info.m_ActualCaps ); + + // Read dxsupport.cfg which has config overrides for particular cards. + ReadHardwareCaps( info.m_ActualCaps, info.m_ActualCaps.m_nMaxDXSupportLevel ); + + // What's in "-shader" overrides dxsupport.cfg + const char *pShaderParam = CommandLine()->ParmValue( "-shader" ); + if ( pShaderParam ) + { + Q_strncpy( info.m_ActualCaps.m_pShaderDLL, pShaderParam, sizeof( info.m_ActualCaps.m_pShaderDLL ) ); + } + } +} + + +//----------------------------------------------------------------------------- +// Determines hardware caps from D3D +//----------------------------------------------------------------------------- +bool CShaderDeviceMgrDx10::ComputeCapsFromD3D( HardwareCaps_t *pCaps, IDXGIAdapter *pAdapter, IDXGIOutput *pOutput ) +{ + HRESULT hr = pAdapter->CheckInterfaceSupport( __uuidof(ID3D10Device), NULL ); + if ( hr != S_OK ) + { + // Fall back to Dx9 + return false; + } + + DXGI_ADAPTER_DESC desc; + hr = pAdapter->GetDesc( &desc ); + Assert( !FAILED( hr ) ); + if ( FAILED(hr) ) + return false; + + bool bForceFloatHDR = ( CommandLine()->CheckParm( "-floathdr" ) != NULL ); + + // DX10 settings + // NOTE: We'll need to have different settings for dx10.1 and dx11 + Q_UnicodeToUTF8( desc.Description, pCaps->m_pDriverName, MATERIAL_ADAPTER_NAME_LENGTH ); + pCaps->m_VendorID = desc.VendorId; + pCaps->m_DeviceID = desc.DeviceId; + pCaps->m_SubSysID = desc.SubSysId; + pCaps->m_Revision = desc.Revision; + pCaps->m_NumSamplers = 16; + pCaps->m_NumTextureStages = 0; + pCaps->m_HasSetDeviceGammaRamp = true; + pCaps->m_bSoftwareVertexProcessing = false; + pCaps->m_SupportsVertexShaders = true; + pCaps->m_SupportsVertexShaders_2_0 = false; + pCaps->m_SupportsPixelShaders = true; + pCaps->m_SupportsPixelShaders_1_4 = false; + pCaps->m_SupportsPixelShaders_2_0 = false; + pCaps->m_SupportsPixelShaders_2_b = false; + pCaps->m_SupportsShaderModel_3_0 = false; + pCaps->m_SupportsCompressedTextures = COMPRESSED_TEXTURES_ON; + pCaps->m_SupportsCompressedVertices = VERTEX_COMPRESSION_ON; + pCaps->m_bSupportsAnisotropicFiltering = true; + pCaps->m_bSupportsMagAnisotropicFiltering = true; + pCaps->m_bSupportsVertexTextures = true; + pCaps->m_nMaxAnisotropy = 16; + pCaps->m_MaxTextureWidth = D3D10_REQ_TEXTURE2D_U_OR_V_DIMENSION; + pCaps->m_MaxTextureHeight = D3D10_REQ_TEXTURE2D_U_OR_V_DIMENSION; + pCaps->m_MaxTextureDepth = D3D10_REQ_TEXTURE3D_U_V_OR_W_DIMENSION; + pCaps->m_MaxTextureAspectRatio = 1024; // FIXME + pCaps->m_MaxPrimitiveCount = 65536; // FIXME + pCaps->m_ZBiasAndSlopeScaledDepthBiasSupported = true; + pCaps->m_SupportsMipmapping = true; + pCaps->m_SupportsOverbright = true; + pCaps->m_SupportsCubeMaps = true; + pCaps->m_NumPixelShaderConstants = 1024; // FIXME + pCaps->m_NumVertexShaderConstants = 1024; // FIXME + pCaps->m_TextureMemorySize = desc.DedicatedVideoMemory; + pCaps->m_MaxNumLights = 4; + pCaps->m_SupportsHardwareLighting = false; + pCaps->m_MaxBlendMatrices = 0; + pCaps->m_MaxBlendMatrixIndices = 0; + pCaps->m_MaxVertexShaderBlendMatrices = 53; // FIXME + pCaps->m_SupportsMipmappedCubemaps = true; + pCaps->m_SupportsNonPow2Textures = true; + pCaps->m_nDXSupportLevel = 100; + pCaps->m_PreferDynamicTextures = false; + pCaps->m_HasProjectedBumpEnv = true; + pCaps->m_MaxUserClipPlanes = 6; // FIXME + pCaps->m_HDRType = bForceFloatHDR ? HDR_TYPE_FLOAT : HDR_TYPE_INTEGER; + pCaps->m_SupportsSRGB = true; + pCaps->m_FakeSRGBWrite = true; + pCaps->m_CanDoSRGBReadFromRTs = true; + pCaps->m_bSupportsSpheremapping = true; + pCaps->m_UseFastClipping = false; + pCaps->m_pShaderDLL[0] = 0; + pCaps->m_bNeedsATICentroidHack = false; + pCaps->m_bColorOnSecondStream = true; + pCaps->m_bSupportsStreamOffset = true; + pCaps->m_nMaxDXSupportLevel = 100; + pCaps->m_bFogColorSpecifiedInLinearSpace = ( desc.VendorId == VENDORID_NVIDIA ); + pCaps->m_nVertexTextureCount = 16; + pCaps->m_nMaxVertexTextureDimension = D3D10_REQ_TEXTURE2D_U_OR_V_DIMENSION; + pCaps->m_bSupportsAlphaToCoverage = false; // FIXME + pCaps->m_bSupportsShadowDepthTextures = true; + pCaps->m_bSupportsFetch4 = ( desc.VendorId == VENDORID_ATI ); + pCaps->m_bSupportsBorderColor = true; + pCaps->m_ShadowDepthTextureFormat = IMAGE_FORMAT_UNKNOWN; + pCaps->m_nMaxViewports = 4; + + DXGI_GAMMA_CONTROL_CAPABILITIES gammaCaps; + pOutput->GetGammaControlCapabilities( &gammaCaps ); + pCaps->m_flMinGammaControlPoint = gammaCaps.MinConvertedValue; + pCaps->m_flMaxGammaControlPoint = gammaCaps.MaxConvertedValue; + pCaps->m_nGammaControlPointCount = gammaCaps.NumGammaControlPoints; + pCaps->m_bCanStretchRectFromTextures = true; + return true; +} + + +//----------------------------------------------------------------------------- +// Gets the number of adapters... +//----------------------------------------------------------------------------- +int CShaderDeviceMgrDx10::GetAdapterCount() const +{ + return m_Adapters.Count(); +} + + +//----------------------------------------------------------------------------- +// Returns info about each adapter +//----------------------------------------------------------------------------- +void CShaderDeviceMgrDx10::GetAdapterInfo( int nAdapter, MaterialAdapterInfo_t& info ) const +{ + Assert( ( nAdapter >= 0 ) && ( nAdapter < m_Adapters.Count() ) ); + const HardwareCaps_t &caps = m_Adapters[ nAdapter ].m_ActualCaps; + memcpy( &info, &caps, sizeof(MaterialAdapterInfo_t) ); +} + + +//----------------------------------------------------------------------------- +// Returns the adapter interface for a particular adapter +//----------------------------------------------------------------------------- +IDXGIAdapter* CShaderDeviceMgrDx10::GetAdapter( int nAdapter ) const +{ + Assert( m_pDXGIFactory && ( nAdapter < GetAdapterCount() ) ); + + IDXGIAdapter *pAdapter; + HRESULT hr = m_pDXGIFactory->EnumAdapters( nAdapter, &pAdapter ); + return ( FAILED(hr) ) ? NULL : pAdapter; +} + + +//----------------------------------------------------------------------------- +// Returns the amount of video memory in bytes for a particular adapter +//----------------------------------------------------------------------------- +int CShaderDeviceMgrDx10::GetVidMemBytes( int nAdapter ) const +{ + LOCK_SHADERAPI(); + IDXGIAdapter *pAdapter = GetAdapter( nAdapter ); + if ( !pAdapter ) + return 0; + + DXGI_ADAPTER_DESC desc; + +#ifdef DBGFLAG_ASSERT + HRESULT hr = +#endif + pAdapter->GetDesc( &desc ); + Assert( !FAILED( hr ) ); + return desc.DedicatedVideoMemory; +} + + +//----------------------------------------------------------------------------- +// Returns the appropriate adapter output to use +//----------------------------------------------------------------------------- +IDXGIOutput* CShaderDeviceMgrDx10::GetAdapterOutput( int nAdapter ) const +{ + LOCK_SHADERAPI(); + IDXGIAdapter *pAdapter = GetAdapter( nAdapter ); + if ( !pAdapter ) + return 0; + + IDXGIOutput *pOutput; + for( UINT i = 0; pAdapter->EnumOutputs( i, &pOutput ) != DXGI_ERROR_NOT_FOUND; ++i ) + { + DXGI_OUTPUT_DESC desc; + HRESULT hr = pOutput->GetDesc( &desc ); + if ( FAILED( hr ) ) + continue; + + // FIXME: Is this what I want? Or should I be looking at other fields, + // like DXGI_MODE_ROTATION_IDENTITY? + if ( !desc.AttachedToDesktop ) + continue; + + return pOutput; + } + + return NULL; +} + + +//----------------------------------------------------------------------------- +// Returns the number of modes +//----------------------------------------------------------------------------- +int CShaderDeviceMgrDx10::GetModeCount( int nAdapter ) const +{ + LOCK_SHADERAPI(); + Assert( m_pDXGIFactory && ( nAdapter < GetAdapterCount() ) ); + + IDXGIOutput *pOutput = GetAdapterOutput( nAdapter ); + if ( !pOutput ) + return 0; + + UINT num = 0; + DXGI_FORMAT format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB; //desired color format + UINT flags = 0; //desired scanline order and/or scaling + + // get the number of available display mode for the given format and scanline order + HRESULT hr = pOutput->GetDisplayModeList( format, flags, &num, 0 ); + return ( FAILED(hr) ) ? 0 : num; +} + + +//----------------------------------------------------------------------------- +// Returns mode information.. +//----------------------------------------------------------------------------- +void CShaderDeviceMgrDx10::GetModeInfo( ShaderDisplayMode_t* pInfo, int nAdapter, int nMode ) const +{ + // Default error state + pInfo->m_nWidth = pInfo->m_nHeight = 0; + pInfo->m_Format = IMAGE_FORMAT_UNKNOWN; + pInfo->m_nRefreshRateNumerator = pInfo->m_nRefreshRateDenominator = 0; + + LOCK_SHADERAPI(); + Assert( m_pDXGIFactory && ( nAdapter < GetAdapterCount() ) ); + + IDXGIOutput *pOutput = GetAdapterOutput( nAdapter ); + if ( !pOutput ) + return; + + UINT num = 0; + DXGI_FORMAT format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB; //desired color format + UINT flags = DXGI_ENUM_MODES_INTERLACED; //desired scanline order and/or scaling + + // get the number of available display mode for the given format and scanline order + HRESULT hr = pOutput->GetDisplayModeList( format, flags, &num, 0 ); + Assert( !FAILED( hr ) ); + + if ( (UINT)nMode >= num ) + return; + + DXGI_MODE_DESC *pDescs = (DXGI_MODE_DESC*)_alloca( num * sizeof( DXGI_MODE_DESC ) ); + hr = pOutput->GetDisplayModeList( format, flags, &num, pDescs ); + Assert( !FAILED( hr ) ); + + pInfo->m_nWidth = pDescs[nMode].Width; + pInfo->m_nHeight = pDescs[nMode].Height; +// pInfo->m_Format = ImageLoader::D3DFormatToImageFormat( pDescs[nMode].Format ); + pInfo->m_nRefreshRateNumerator = pDescs[nMode].RefreshRate.Numerator; + pInfo->m_nRefreshRateDenominator = pDescs[nMode].RefreshRate.Denominator; +} + + +//----------------------------------------------------------------------------- +// Returns the current mode for an adapter +//----------------------------------------------------------------------------- +void CShaderDeviceMgrDx10::GetCurrentModeInfo( ShaderDisplayMode_t* pInfo, int nAdapter ) const +{ + // FIXME: Implement! + Assert( 0 ); +} + + +//----------------------------------------------------------------------------- +// Initialization, shutdown +//----------------------------------------------------------------------------- +bool CShaderDeviceMgrDx10::SetAdapter( int nAdapter, int nFlags ) +{ + /* + if ( !g_pShaderDeviceDx10->Init() ) + { + Warning( "Unable to initialize dx10 device!\n" ); + return false; + } + + g_pMaterialSystemHardwareConfig = g_pShaderDeviceDx10; + g_pShaderDevice = g_pShaderDeviceDx10; + */ + return true; +} + + +//----------------------------------------------------------------------------- +// Sets the mode +//----------------------------------------------------------------------------- +CreateInterfaceFn CShaderDeviceMgrDx10::SetMode( void *hWnd, int nAdapter, const ShaderDeviceInfo_t& mode ) +{ + LOCK_SHADERAPI(); + + Assert( nAdapter < GetAdapterCount() ); + int nDXLevel = mode.m_nDXLevel != 0 ? mode.m_nDXLevel : m_Adapters[nAdapter].m_ActualCaps.m_nDXSupportLevel; + if ( m_bObeyDxCommandlineOverride ) + { + nDXLevel = CommandLine()->ParmValue( "-dxlevel", nDXLevel ); + m_bObeyDxCommandlineOverride = false; + } + if ( nDXLevel > m_Adapters[nAdapter].m_ActualCaps.m_nMaxDXSupportLevel ) + { + nDXLevel = m_Adapters[nAdapter].m_ActualCaps.m_nMaxDXSupportLevel; + } + nDXLevel = GetClosestActualDXLevel( nDXLevel ); + + if ( nDXLevel < 100 ) + { + // Fall back to the Dx9 implementations + return g_pShaderDeviceMgrDx8->SetMode( hWnd, nAdapter, mode ); + } + + if ( g_pShaderAPI ) + { + g_pShaderAPI->OnDeviceShutdown(); + g_pShaderAPI = NULL; + } + + if ( g_pShaderDevice ) + { + g_pShaderDevice->ShutdownDevice(); + g_pShaderDevice = NULL; + } + + g_pShaderShadow = NULL; + + ShaderDeviceInfo_t adjustedMode = mode; + adjustedMode.m_nDXLevel = nDXLevel; + if ( !g_pShaderDeviceDx10->InitDevice( hWnd, nAdapter, adjustedMode ) ) + return NULL; + + if ( !g_pShaderAPIDx10->OnDeviceInit() ) + return NULL; + + g_pShaderDevice = g_pShaderDeviceDx10; + g_pShaderAPI = g_pShaderAPIDx10; + g_pShaderShadow = g_pShaderShadowDx10; + + return ShaderInterfaceFactory; +} + + +//----------------------------------------------------------------------------- +// +// Device +// +//----------------------------------------------------------------------------- + + +//----------------------------------------------------------------------------- +// constructor, destructor +//----------------------------------------------------------------------------- +CShaderDeviceDx10::CShaderDeviceDx10() +{ + m_pDevice = NULL; + m_pOutput = NULL; + m_pSwapChain = NULL; + m_pRenderTargetView = NULL; +} + +CShaderDeviceDx10::~CShaderDeviceDx10() +{ +} + + +//----------------------------------------------------------------------------- +// Sets the mode +//----------------------------------------------------------------------------- +bool CShaderDeviceDx10::InitDevice( void *hWnd, int nAdapter, const ShaderDeviceInfo_t& mode ) +{ + // Make sure we've been shutdown previously + if ( m_nAdapter != -1 ) + { + Warning( "CShaderDeviceDx10::SetMode: Previous mode has not been shut down!\n" ); + return false; + } + + LOCK_SHADERAPI(); + IDXGIAdapter *pAdapter = g_ShaderDeviceMgrDx10.GetAdapter( nAdapter ); + if ( !pAdapter ) + return false; + + m_pOutput = g_ShaderDeviceMgrDx10.GetAdapterOutput( nAdapter ); + if ( !m_pOutput ) + return false; + m_pOutput->AddRef(); + + DXGI_SWAP_CHAIN_DESC sd; + ZeroMemory( &sd, sizeof(sd) ); + sd.BufferDesc.Width = mode.m_DisplayMode.m_nWidth; + sd.BufferDesc.Height = mode.m_DisplayMode.m_nHeight; + sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; + sd.BufferDesc.RefreshRate.Numerator = mode.m_DisplayMode.m_nRefreshRateNumerator; + sd.BufferDesc.RefreshRate.Denominator = mode.m_DisplayMode.m_nRefreshRateDenominator; + sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; + sd.BufferCount = mode.m_nBackBufferCount; + sd.OutputWindow = (HWND)hWnd; + sd.Windowed = mode.m_bWindowed ? TRUE : FALSE; + sd.Flags = mode.m_bWindowed ? 0 : DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH; + + // NOTE: Having more than 1 back buffer disables MSAA! + sd.SwapEffect = mode.m_nBackBufferCount > 1 ? DXGI_SWAP_EFFECT_SEQUENTIAL : DXGI_SWAP_EFFECT_DISCARD; + + // FIXME: Chicken + egg problem with SampleDesc. + sd.SampleDesc.Count = mode.m_nAASamples ? mode.m_nAASamples : 1; + sd.SampleDesc.Quality = mode.m_nAAQuality; + + UINT nDeviceFlags = 0; +#ifdef _DEBUG + nDeviceFlags |= D3D10_CREATE_DEVICE_DEBUG; +#endif + + HRESULT hr = D3D10CreateDeviceAndSwapChain( pAdapter, D3D10_DRIVER_TYPE_HARDWARE, + NULL, nDeviceFlags, D3D10_SDK_VERSION, &sd, &m_pSwapChain, &m_pDevice ); + + if ( FAILED( hr ) ) + return false; + + // Create a render target view + ID3D10Texture2D *pBackBuffer; + hr = m_pSwapChain->GetBuffer( 0, __uuidof( ID3D10Texture2D ), (LPVOID*)&pBackBuffer ); + if ( FAILED( hr ) ) + return FALSE; + + hr = m_pDevice->CreateRenderTargetView( pBackBuffer, NULL, &m_pRenderTargetView ); + pBackBuffer->Release(); + if( FAILED( hr ) ) + return FALSE; + + m_pDevice->OMSetRenderTargets( 1, &m_pRenderTargetView, NULL ); + + m_hWnd = hWnd; + m_nAdapter = nAdapter; + + // This is our current view. + m_ViewHWnd = hWnd; + GetWindowSize( m_nWindowWidth, m_nWindowHeight ); + + g_pHardwareConfig->SetupHardwareCaps( mode, g_ShaderDeviceMgrDx10.GetHardwareCaps( nAdapter ) ); + + return true; +} + + +//----------------------------------------------------------------------------- +// Shuts down the mode +//----------------------------------------------------------------------------- +void CShaderDeviceDx10::ShutdownDevice() +{ + if ( m_pRenderTargetView ) + { + m_pRenderTargetView->Release(); + m_pRenderTargetView = NULL; + } + + if ( m_pDevice ) + { + m_pDevice->Release(); + m_pDevice = NULL; + } + + if ( m_pSwapChain ) + { + m_pSwapChain->Release(); + m_pSwapChain = NULL; + } + + if ( m_pOutput ) + { + m_pOutput->Release(); + m_pOutput = NULL; + } + + m_hWnd = NULL; + m_nAdapter = -1; +} + + +//----------------------------------------------------------------------------- +// Are we using graphics? +//----------------------------------------------------------------------------- +bool CShaderDeviceDx10::IsUsingGraphics() const +{ + return ( m_nAdapter >= 0 ); +} + + +//----------------------------------------------------------------------------- +// Returns the adapter +//----------------------------------------------------------------------------- +int CShaderDeviceDx10::GetCurrentAdapter() const +{ + return m_nAdapter; +} + + +//----------------------------------------------------------------------------- +// Get back buffer information +//----------------------------------------------------------------------------- +ImageFormat CShaderDeviceDx10::GetBackBufferFormat() const +{ + return IMAGE_FORMAT_RGB888; +} + +void CShaderDeviceDx10::GetBackBufferDimensions( int& width, int& height ) const +{ + width = 1024; + height = 768; +} + + +//----------------------------------------------------------------------------- +// Use this to spew information about the 3D layer +//----------------------------------------------------------------------------- +void CShaderDeviceDx10::SpewDriverInfo() const +{ + Warning( "Dx10 Driver!\n" ); +} + + + +//----------------------------------------------------------------------------- +// Swap buffers +//----------------------------------------------------------------------------- +void CShaderDeviceDx10::Present() +{ + // FIXME: Deal with window occlusion, alt-tab, etc. + HRESULT hr = m_pSwapChain->Present( 0, 0 ); + if ( FAILED(hr) ) + { + Assert( 0 ); + } +} + + +//----------------------------------------------------------------------------- +// Camma ramp +//----------------------------------------------------------------------------- +void CShaderDeviceDx10::SetHardwareGammaRamp( float fGamma, float fGammaTVRangeMin, float fGammaTVRangeMax, float fGammaTVExponent, bool bTVEnabled ) +{ + DevMsg( "SetHardwareGammaRamp( %f )\n", fGamma ); + + Assert( m_pOutput ); + if( !m_pOutput ) + return; + + float flMin = g_pHardwareConfig->Caps().m_flMinGammaControlPoint; + float flMax = g_pHardwareConfig->Caps().m_flMaxGammaControlPoint; + int nGammaPoints = g_pHardwareConfig->Caps().m_nGammaControlPointCount; + + DXGI_GAMMA_CONTROL gammaControl; + gammaControl.Scale.Red = gammaControl.Scale.Green = gammaControl.Scale.Blue = 1.0f; + gammaControl.Offset.Red = gammaControl.Offset.Green = gammaControl.Offset.Blue = 0.0f; + float flOOCount = 1.0f / ( nGammaPoints - 1 ); + for ( int i = 0; i < nGammaPoints; i++ ) + { + float flGamma22 = i * flOOCount; + float flCorrection = pow( flGamma22, fGamma / 2.2f ); + flCorrection = clamp( flCorrection, flMin, flMax ); + + gammaControl.GammaCurve[i].Red = flCorrection; + gammaControl.GammaCurve[i].Green = flCorrection; + gammaControl.GammaCurve[i].Blue = flCorrection; + } + + HRESULT hr = m_pOutput->SetGammaControl( &gammaControl ); + if ( FAILED(hr) ) + { + Warning( "CShaderDeviceDx10::SetHardwareGammaRamp: Unable to set gamma controls!\n" ); + } +} + + +//----------------------------------------------------------------------------- +// Compiles all manner of shaders +//----------------------------------------------------------------------------- +IShaderBuffer* CShaderDeviceDx10::CompileShader( const char *pProgram, size_t nBufLen, const char *pShaderVersion ) +{ + int nCompileFlags = D3D10_SHADER_AVOID_FLOW_CONTROL; + nCompileFlags |= D3D10_SHADER_ENABLE_BACKWARDS_COMPATIBILITY; + +#ifdef _DEBUG + nCompileFlags |= D3D10_SHADER_DEBUG; +#endif + + ID3D10Blob *pCompiledShader, *pErrorMessages; + HRESULT hr = D3DX10CompileFromMemory( pProgram, nBufLen, "", + NULL, NULL, "main", pShaderVersion, nCompileFlags, 0, NULL, + &pCompiledShader, &pErrorMessages, NULL ); + + if ( FAILED( hr ) ) + { + if ( pErrorMessages ) + { + const char *pErrorMessage = (const char *)pErrorMessages->GetBufferPointer(); + Warning( "Vertex shader compilation failed! Reported the following errors:\n%s\n", pErrorMessage ); + pErrorMessages->Release(); + } + return NULL; + } + + // NOTE: This uses small block heap allocator; so I'm not going + // to bother creating a memory pool. + CShaderBuffer< ID3D10Blob > *pShaderBuffer = new CShaderBuffer< ID3D10Blob >( pCompiledShader ); + if ( pErrorMessages ) + { + pErrorMessages->Release(); + } + + return pShaderBuffer; +} + + +//----------------------------------------------------------------------------- +// Release input layouts +//----------------------------------------------------------------------------- +void CShaderDeviceDx10::ReleaseInputLayouts( VertexShaderIndex_t nIndex ) +{ + InputLayoutDict_t &dict = m_VertexShaderDict[nIndex].m_InputLayouts; + unsigned short hCurr = dict.FirstInorder(); + while( hCurr != dict.InvalidIndex() ) + { + if ( dict[hCurr].m_pInputLayout ) + { + dict[hCurr].m_pInputLayout->Release(); + dict[hCurr].m_pInputLayout = NULL; + } + hCurr = dict.NextInorder( hCurr ); + } +} + + +//----------------------------------------------------------------------------- +// Create, destroy vertex shader +//----------------------------------------------------------------------------- +VertexShaderHandle_t CShaderDeviceDx10::CreateVertexShader( IShaderBuffer* pShaderBuffer ) +{ + // Create the vertex shader + ID3D10VertexShader *pShader = NULL; + HRESULT hr = m_pDevice->CreateVertexShader( pShaderBuffer->GetBits(), + pShaderBuffer->GetSize(), &pShader ); + + if ( FAILED( hr ) || !pShader ) + return VERTEX_SHADER_HANDLE_INVALID; + + ID3D10ShaderReflection *pInfo; + hr = D3D10ReflectShader( pShaderBuffer->GetBits(), pShaderBuffer->GetSize(), &pInfo ); + if ( FAILED( hr ) || !pInfo ) + { + pShader->Release(); + return VERTEX_SHADER_HANDLE_INVALID; + } + + // Insert the shader into the dictionary of shaders + VertexShaderIndex_t i = m_VertexShaderDict.AddToTail( ); + VertexShader_t &dict = m_VertexShaderDict[i]; + dict.m_pShader = pShader; + dict.m_pInfo = pInfo; + dict.m_nByteCodeLen = pShaderBuffer->GetSize(); + dict.m_pByteCode = new unsigned char[ dict.m_nByteCodeLen ]; + memcpy( dict.m_pByteCode, pShaderBuffer->GetBits(), dict.m_nByteCodeLen ); + return (VertexShaderHandle_t)i; +} + +void CShaderDeviceDx10::DestroyVertexShader( VertexShaderHandle_t hShader ) +{ + if ( hShader == VERTEX_SHADER_HANDLE_INVALID ) + return; + + g_pShaderAPIDx10->Unbind( hShader ); + + VertexShaderIndex_t i = (VertexShaderIndex_t)hShader; + VertexShader_t &dict = m_VertexShaderDict[i]; + VerifyEquals( dict.m_pShader->Release(), 0 ); + VerifyEquals( dict.m_pInfo->Release(), 0 ); + delete[] dict.m_pByteCode; + ReleaseInputLayouts( i ); + m_VertexShaderDict.Remove( i ); +} + + +//----------------------------------------------------------------------------- +// Create, destroy geometry shader +//----------------------------------------------------------------------------- +GeometryShaderHandle_t CShaderDeviceDx10::CreateGeometryShader( IShaderBuffer* pShaderBuffer ) +{ + // Create the geometry shader + ID3D10GeometryShader *pShader = NULL; + HRESULT hr = m_pDevice->CreateGeometryShader( pShaderBuffer->GetBits(), + pShaderBuffer->GetSize(), &pShader ); + + if ( FAILED( hr ) || !pShader ) + return GEOMETRY_SHADER_HANDLE_INVALID; + + ID3D10ShaderReflection *pInfo; + hr = D3D10ReflectShader( pShaderBuffer->GetBits(), pShaderBuffer->GetSize(), &pInfo ); + if ( FAILED( hr ) || !pInfo ) + { + pShader->Release(); + return GEOMETRY_SHADER_HANDLE_INVALID; + } + + // Insert the shader into the dictionary of shaders + GeometryShaderIndex_t i = m_GeometryShaderDict.AddToTail( ); + m_GeometryShaderDict[i].m_pShader = pShader; + m_GeometryShaderDict[i].m_pInfo = pInfo; + return (GeometryShaderHandle_t)i; +} + +void CShaderDeviceDx10::DestroyGeometryShader( GeometryShaderHandle_t hShader ) +{ + if ( hShader == GEOMETRY_SHADER_HANDLE_INVALID ) + return; + + g_pShaderAPIDx10->Unbind( hShader ); + + GeometryShaderIndex_t i = (GeometryShaderIndex_t)hShader; + VerifyEquals( m_GeometryShaderDict[ i ].m_pShader->Release(), 0 ); + VerifyEquals( m_GeometryShaderDict[ i ].m_pInfo->Release(), 0 ); + m_GeometryShaderDict.Remove( i ); +} + + +//----------------------------------------------------------------------------- +// Create, destroy pixel shader +//----------------------------------------------------------------------------- +PixelShaderHandle_t CShaderDeviceDx10::CreatePixelShader( IShaderBuffer* pShaderBuffer ) +{ + // Create the pixel shader + ID3D10PixelShader *pShader = NULL; + HRESULT hr = m_pDevice->CreatePixelShader( pShaderBuffer->GetBits(), + pShaderBuffer->GetSize(), &pShader ); + + if ( FAILED( hr ) || !pShader ) + return PIXEL_SHADER_HANDLE_INVALID; + + ID3D10ShaderReflection *pInfo; + hr = D3D10ReflectShader( pShaderBuffer->GetBits(), pShaderBuffer->GetSize(), &pInfo ); + if ( FAILED( hr ) || !pInfo ) + { + pShader->Release(); + return PIXEL_SHADER_HANDLE_INVALID; + } + + // Insert the shader into the dictionary of shaders + PixelShaderIndex_t i = m_PixelShaderDict.AddToTail( ); + m_PixelShaderDict[i].m_pShader = pShader; + m_PixelShaderDict[i].m_pInfo = pInfo; + return (PixelShaderHandle_t)i; +} + +void CShaderDeviceDx10::DestroyPixelShader( PixelShaderHandle_t hShader ) +{ + if ( hShader == PIXEL_SHADER_HANDLE_INVALID ) + return; + + g_pShaderAPIDx10->Unbind( hShader ); + + PixelShaderIndex_t i = (PixelShaderIndex_t)hShader; + VerifyEquals( m_PixelShaderDict[ i ].m_pShader->Release(), 0 ); + VerifyEquals( m_PixelShaderDict[ i ].m_pInfo->Release(), 0 ); + m_PixelShaderDict.Remove( i ); +} + + +//----------------------------------------------------------------------------- +// Finds or creates an input layout for a given vertex shader + stream format +//----------------------------------------------------------------------------- +ID3D10InputLayout* CShaderDeviceDx10::GetInputLayout( VertexShaderHandle_t hShader, VertexFormat_t format ) +{ + if ( hShader == VERTEX_SHADER_HANDLE_INVALID ) + return NULL; + + // FIXME: VertexFormat_t is not the appropriate way of specifying this + // because it has no stream information + InputLayout_t insert; + insert.m_VertexFormat = format; + + VertexShaderIndex_t i = (VertexShaderIndex_t)hShader; + InputLayoutDict_t &dict = m_VertexShaderDict[i].m_InputLayouts; + unsigned short hIndex = dict.Find( insert ); + if ( hIndex != dict.InvalidIndex() ) + return dict[hIndex].m_pInputLayout; + + VertexShader_t &shader = m_VertexShaderDict[i]; + insert.m_pInputLayout = CreateInputLayout( format, shader.m_pInfo, shader.m_pByteCode, shader.m_nByteCodeLen ); + dict.Insert( insert ); + return insert.m_pInputLayout; +} + + +//----------------------------------------------------------------------------- +// Creates/destroys Mesh +//----------------------------------------------------------------------------- +IMesh* CShaderDeviceDx10::CreateStaticMesh( VertexFormat_t vertexFormat, const char *pBudgetGroup, IMaterial * pMaterial ) +{ + LOCK_SHADERAPI(); + return NULL; +} + +void CShaderDeviceDx10::DestroyStaticMesh( IMesh* pMesh ) +{ + LOCK_SHADERAPI(); +} + + +//----------------------------------------------------------------------------- +// Creates/destroys vertex buffers + index buffers +//----------------------------------------------------------------------------- +IVertexBuffer *CShaderDeviceDx10::CreateVertexBuffer( ShaderBufferType_t type, VertexFormat_t fmt, int nVertexCount, const char *pBudgetGroup ) +{ + LOCK_SHADERAPI(); + CVertexBufferDx10 *pVertexBuffer = new CVertexBufferDx10( type, fmt, nVertexCount, pBudgetGroup ); + return pVertexBuffer; +} + +void CShaderDeviceDx10::DestroyVertexBuffer( IVertexBuffer *pVertexBuffer ) +{ + LOCK_SHADERAPI(); + if ( pVertexBuffer ) + { + CVertexBufferDx10 *pVertexBufferBase = assert_cast( pVertexBuffer ); + g_pShaderAPIDx10->UnbindVertexBuffer( pVertexBufferBase->GetDx10Buffer() ); + delete pVertexBufferBase; + } +} + +IIndexBuffer *CShaderDeviceDx10::CreateIndexBuffer( ShaderBufferType_t type, MaterialIndexFormat_t fmt, int nIndexCount, const char *pBudgetGroup ) +{ + LOCK_SHADERAPI(); + CIndexBufferDx10 *pIndexBuffer = new CIndexBufferDx10( type, fmt, nIndexCount, pBudgetGroup ); + return pIndexBuffer; +} + +void CShaderDeviceDx10::DestroyIndexBuffer( IIndexBuffer *pIndexBuffer ) +{ + LOCK_SHADERAPI(); + if ( pIndexBuffer ) + { + CIndexBufferDx10 *pIndexBufferBase = assert_cast( pIndexBuffer ); + g_pShaderAPIDx10->UnbindIndexBuffer( pIndexBufferBase->GetDx10Buffer() ); + delete pIndexBufferBase; + } +} + +IVertexBuffer *CShaderDeviceDx10::GetDynamicVertexBuffer( int nStreamID, VertexFormat_t vertexFormat, bool bBuffered ) +{ + LOCK_SHADERAPI(); + return NULL; +} + +IIndexBuffer *CShaderDeviceDx10::GetDynamicIndexBuffer( MaterialIndexFormat_t fmt, bool bBuffered ) +{ + LOCK_SHADERAPI(); + return NULL; +} + + + diff --git a/materialsystem/shaderapidx9/shaderdevicedx10.h b/materialsystem/shaderapidx9/shaderdevicedx10.h new file mode 100644 index 0000000..ecf6a8d --- /dev/null +++ b/materialsystem/shaderapidx9/shaderdevicedx10.h @@ -0,0 +1,254 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +// +//===========================================================================// + +#ifndef SHADERDEVICEDX10_H +#define SHADERDEVICEDX10_H + +#ifdef _WIN32 +#pragma once +#endif + + +#include "shaderdevicebase.h" +#include "tier1/utlvector.h" +#include "tier1/utlrbtree.h" +#include "tier1/utllinkedlist.h" + + +//----------------------------------------------------------------------------- +// Forward declaration +//----------------------------------------------------------------------------- +struct IDXGIFactory; +struct IDXGIAdapter; +struct IDXGIOutput; +struct IDXGISwapChain; +struct ID3D10Device; +struct ID3D10RenderTargetView; +struct ID3D10VertexShader; +struct ID3D10PixelShader; +struct ID3D10GeometryShader; +struct ID3D10InputLayout; +struct ID3D10ShaderReflection; + + +//----------------------------------------------------------------------------- +// The Base implementation of the shader device +//----------------------------------------------------------------------------- +class CShaderDeviceMgrDx10 : public CShaderDeviceMgrBase +{ + typedef CShaderDeviceMgrBase BaseClass; + +public: + // constructor, destructor + CShaderDeviceMgrDx10(); + virtual ~CShaderDeviceMgrDx10(); + + // Methods of IAppSystem + virtual bool Connect( CreateInterfaceFn factory ); + virtual void Disconnect(); + virtual InitReturnVal_t Init(); + virtual void Shutdown(); + + // Methods of IShaderDeviceMgr + virtual int GetAdapterCount() const; + virtual void GetAdapterInfo( int adapter, MaterialAdapterInfo_t& info ) const; + virtual int GetModeCount( int nAdapter ) const; + virtual void GetModeInfo( ShaderDisplayMode_t* pInfo, int nAdapter, int mode ) const; + virtual void GetCurrentModeInfo( ShaderDisplayMode_t* pInfo, int nAdapter ) const; + virtual bool SetAdapter( int nAdapter, int nFlags ); + virtual CreateInterfaceFn SetMode( void *hWnd, int nAdapter, const ShaderDeviceInfo_t& mode ); + +private: + // Initialize adapter information + void InitAdapterInfo(); + + // Determines hardware caps from D3D + bool ComputeCapsFromD3D( HardwareCaps_t *pCaps, IDXGIAdapter *pAdapter, IDXGIOutput *pOutput ); + + // Returns the amount of video memory in bytes for a particular adapter + virtual int GetVidMemBytes( int nAdapter ) const; + + // Returns the appropriate adapter output to use + IDXGIOutput* GetAdapterOutput( int nAdapter ) const; + + // Returns the adapter interface for a particular adapter + IDXGIAdapter* GetAdapter( int nAdapter ) const; + + // Used to enumerate adapters, attach to windows + IDXGIFactory *m_pDXGIFactory; + + bool m_bObeyDxCommandlineOverride: 1; + + friend class CShaderDeviceDx10; +}; + + +//----------------------------------------------------------------------------- +// The Dx10 implementation of the shader device +//----------------------------------------------------------------------------- +class CShaderDeviceDx10 : public CShaderDeviceBase +{ +public: + // constructor, destructor + CShaderDeviceDx10(); + virtual ~CShaderDeviceDx10(); + +public: + // Methods of IShaderDevice + virtual bool IsUsingGraphics() const; + virtual int GetCurrentAdapter() const; + virtual ImageFormat GetBackBufferFormat() const; + virtual void GetBackBufferDimensions( int& width, int& height ) const; + virtual void SpewDriverInfo() const; + virtual void Present(); + virtual IShaderBuffer* CompileShader( const char *pProgram, size_t nBufLen, const char *pShaderVersion ); + virtual VertexShaderHandle_t CreateVertexShader( IShaderBuffer *pShader ); + virtual void DestroyVertexShader( VertexShaderHandle_t hShader ); + virtual GeometryShaderHandle_t CreateGeometryShader( IShaderBuffer* pShaderBuffer ); + virtual void DestroyGeometryShader( GeometryShaderHandle_t hShader ); + virtual PixelShaderHandle_t CreatePixelShader( IShaderBuffer* pShaderBuffer ); + virtual void DestroyPixelShader( PixelShaderHandle_t hShader ); + virtual void ReleaseResources() {} + virtual void ReacquireResources() {} + virtual IMesh* CreateStaticMesh( VertexFormat_t format, const char *pTextureBudgetGroup, IMaterial * pMaterial ); + virtual void DestroyStaticMesh( IMesh* mesh ); + virtual IVertexBuffer *CreateVertexBuffer( ShaderBufferType_t type, VertexFormat_t fmt, int nVertexCount, const char *pTextureBudgetGroup ); + virtual void DestroyVertexBuffer( IVertexBuffer *pVertexBuffer ); + virtual IIndexBuffer *CreateIndexBuffer( ShaderBufferType_t type, MaterialIndexFormat_t fmt, int nIndexCount, const char *pTextureBudgetGroup ); + virtual void DestroyIndexBuffer( IIndexBuffer *pIndexBuffer ); + virtual IVertexBuffer *GetDynamicVertexBuffer( int nStreamID, VertexFormat_t vertexFormat, bool bBuffered = true ); + virtual IIndexBuffer *GetDynamicIndexBuffer( MaterialIndexFormat_t fmt, bool bBuffered = true ); + virtual void SetHardwareGammaRamp( float fGamma, float fGammaTVRangeMin, float fGammaTVRangeMax, float fGammaTVExponent, bool bTVEnabled ); + + // A special path used to tick the front buffer while loading on the 360 + virtual void EnableNonInteractiveMode( MaterialNonInteractiveMode_t mode, ShaderNonInteractiveInfo_t *pInfo ) {} + virtual void RefreshFrontBufferNonInteractive( ) {} + virtual void HandleThreadEvent( uint32 threadEvent ) {} + +public: + // Methods of CShaderDeviceBase + virtual bool InitDevice( void *hWnd, int nAdapter, const ShaderDeviceInfo_t& mode ); + virtual void ShutdownDevice(); + virtual bool IsDeactivated() const { return false; } + + // Other public methods + ID3D10VertexShader* GetVertexShader( VertexShaderHandle_t hShader ) const; + ID3D10GeometryShader* GetGeometryShader( GeometryShaderHandle_t hShader ) const; + ID3D10PixelShader* GetPixelShader( PixelShaderHandle_t hShader ) const; + ID3D10InputLayout* GetInputLayout( VertexShaderHandle_t hShader, VertexFormat_t format ); + +private: + struct InputLayout_t + { + ID3D10InputLayout *m_pInputLayout; + VertexFormat_t m_VertexFormat; + }; + + typedef CUtlRBTree< InputLayout_t, unsigned short > InputLayoutDict_t; + + static bool InputLayoutLessFunc( const InputLayout_t &lhs, const InputLayout_t &rhs ) + { + return ( lhs.m_VertexFormat < rhs.m_VertexFormat ); + } + + struct VertexShader_t + { + ID3D10VertexShader *m_pShader; + ID3D10ShaderReflection *m_pInfo; + void *m_pByteCode; + size_t m_nByteCodeLen; + InputLayoutDict_t m_InputLayouts; + + VertexShader_t() : m_InputLayouts( 0, 0, InputLayoutLessFunc ) {} + }; + + struct GeometryShader_t + { + ID3D10GeometryShader *m_pShader; + ID3D10ShaderReflection *m_pInfo; + }; + + struct PixelShader_t + { + ID3D10PixelShader *m_pShader; + ID3D10ShaderReflection *m_pInfo; + }; + + typedef CUtlFixedLinkedList< VertexShader_t >::IndexType_t VertexShaderIndex_t; + typedef CUtlFixedLinkedList< GeometryShader_t >::IndexType_t GeometryShaderIndex_t; + typedef CUtlFixedLinkedList< PixelShader_t >::IndexType_t PixelShaderIndex_t; + + void SetupHardwareCaps(); + void ReleaseInputLayouts( VertexShaderIndex_t nIndex ); + + IDXGIOutput *m_pOutput; + ID3D10Device *m_pDevice; + IDXGISwapChain *m_pSwapChain; + ID3D10RenderTargetView *m_pRenderTargetView; + + CUtlFixedLinkedList< VertexShader_t > m_VertexShaderDict; + CUtlFixedLinkedList< GeometryShader_t > m_GeometryShaderDict; + CUtlFixedLinkedList< PixelShader_t > m_PixelShaderDict; + + friend ID3D10Device *D3D10Device(); + friend IDXGISwapChain *D3D10SwapChain(); + friend ID3D10RenderTargetView *D3D10RenderTargetView(); +}; + + +//----------------------------------------------------------------------------- +// Inline methods of CShaderDeviceDx10 +//----------------------------------------------------------------------------- +inline ID3D10VertexShader* CShaderDeviceDx10::GetVertexShader( VertexShaderHandle_t hShader ) const +{ + if ( hShader != VERTEX_SHADER_HANDLE_INVALID ) + return m_VertexShaderDict[ (VertexShaderIndex_t)hShader ].m_pShader; + return NULL; +} + +inline ID3D10GeometryShader* CShaderDeviceDx10::GetGeometryShader( GeometryShaderHandle_t hShader ) const +{ + if ( hShader != GEOMETRY_SHADER_HANDLE_INVALID ) + return m_GeometryShaderDict[ (GeometryShaderIndex_t)hShader ].m_pShader; + return NULL; +} + +inline ID3D10PixelShader* CShaderDeviceDx10::GetPixelShader( PixelShaderHandle_t hShader ) const +{ + if ( hShader != PIXEL_SHADER_HANDLE_INVALID ) + return m_PixelShaderDict[ (PixelShaderIndex_t)hShader ].m_pShader; + return NULL; +} + + +//----------------------------------------------------------------------------- +// Singleton +//----------------------------------------------------------------------------- +extern CShaderDeviceDx10* g_pShaderDeviceDx10; + + +//----------------------------------------------------------------------------- +// Utility methods +//----------------------------------------------------------------------------- +inline ID3D10Device *D3D10Device() +{ + return g_pShaderDeviceDx10->m_pDevice; +} + +inline IDXGISwapChain *D3D10SwapChain() +{ + return g_pShaderDeviceDx10->m_pSwapChain; +} + +inline ID3D10RenderTargetView *D3D10RenderTargetView() +{ + return g_pShaderDeviceDx10->m_pRenderTargetView; +} + + +#endif // SHADERDEVICEDX10_H \ No newline at end of file diff --git a/materialsystem/shaderapidx9/shaderdevicedx8.cpp b/materialsystem/shaderapidx9/shaderdevicedx8.cpp new file mode 100644 index 0000000..5b094e1 --- /dev/null +++ b/materialsystem/shaderapidx9/shaderdevicedx8.cpp @@ -0,0 +1,3707 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +// +//===========================================================================// +#define DISABLE_PROTECTED_THINGS +#include "locald3dtypes.h" + +#include "shaderdevicedx8.h" +#include "shaderapi/ishaderutil.h" +#include "shaderapidx8_global.h" +#include "filesystem.h" +#include "tier0/icommandline.h" +#include "tier2/tier2.h" +#include "shadershadowdx8.h" +#include "colorformatdx8.h" +#include "materialsystem/IShader.h" +#include "shaderapidx8.h" +#include "shaderapidx8_global.h" +#include "imeshdx8.h" +#include "materialsystem/materialsystem_config.h" +#include "vertexshaderdx8.h" +#include "recording.h" +#include "winutils.h" +#include "tier0/vprof_telemetry.h" + +#if defined ( DX_TO_GL_ABSTRACTION ) +// Placed here so inlines placed in dxabstract.h can access gGL +COpenGLEntryPoints *gGL = NULL; +#endif + +#define D3D_BATCH_PERF_ANALYSIS 0 + +#if D3D_BATCH_PERF_ANALYSIS +#if defined( DX_TO_GL_ABSTRACTION ) +#error Cannot enable D3D_BATCH_PERF_ANALYSIS when using DX_TO_GL_ABSTRACTION, use GL_BATCH_PERF_ANALYSIS instead. +#endif +// Define this if you want all d3d9 interfaces hooked and run through the dx9hook.h shim interfaces. For profiling, etc. +#define DO_DX9_HOOK +#endif + +#ifdef DO_DX9_HOOK + +#if D3D_BATCH_PERF_ANALYSIS +ConVar d3d_batch_vis( "d3d_batch_vis", "0" ); +ConVar d3d_batch_vis_abs_scale( "d3d_batch_vis_abs_scale", ".050" ); +ConVar d3d_present_vis_abs_scale( "d3d_batch_vis_abs_scale", ".050" ); +ConVar d3d_batch_vis_y_scale( "d3d_batch_vis_y_scale", "0.0" ); +uint64 g_nTotalD3DCalls, g_nTotalD3DCycles; +static double s_rdtsc_to_ms; +#endif + +#include "dx9hook.h" +#endif + +#ifndef _X360 +#include "wmi.h" +#endif + +#if defined( _X360 ) +#include "xbox/xbox_console.h" +#include "xbox/xbox_win32stubs.h" +#endif + + +//#define DX8_COMPATABILITY_MODE + +//----------------------------------------------------------------------------- +// Globals +//----------------------------------------------------------------------------- +static CShaderDeviceMgrDx8 g_ShaderDeviceMgrDx8; +CShaderDeviceMgrDx8* g_pShaderDeviceMgrDx8 = &g_ShaderDeviceMgrDx8; + +#ifndef SHADERAPIDX10 + +// In the shaderapidx10.dll, we use its version of IShaderDeviceMgr. +EXPOSE_SINGLE_INTERFACE_GLOBALVAR( CShaderDeviceMgrDx8, IShaderDeviceMgr, + SHADER_DEVICE_MGR_INTERFACE_VERSION, g_ShaderDeviceMgrDx8 ) + +#endif + +#if defined( _X360 ) +IDirect3D9 *m_pD3D; +#endif + +IDirect3DDevice *g_pD3DDevice = NULL; + +#if defined(IS_WINDOWS_PC) && defined(SHADERAPIDX9) +// HACK: need to pass knowledge of D3D9Ex usage into callers of D3D Create* methods +// so they do not try to specify D3DPOOL_MANAGED, which is unsupported in D3D9Ex +bool g_ShaderDeviceUsingD3D9Ex = false; +static ConVar mat_supports_d3d9ex( "mat_supports_d3d9ex", "0", FCVAR_HIDDEN ); +#endif + +// hook into mat_forcedynamic from the engine. +static ConVar mat_forcedynamic( "mat_forcedynamic", "0", FCVAR_CHEAT ); + +// this is hooked into the engines convar +ConVar mat_debugalttab( "mat_debugalttab", "0", FCVAR_CHEAT ); + + +//----------------------------------------------------------------------------- +// +// Device manager +// +//----------------------------------------------------------------------------- + + +//----------------------------------------------------------------------------- +// constructor, destructor +//----------------------------------------------------------------------------- +CShaderDeviceMgrDx8::CShaderDeviceMgrDx8() +{ + m_pD3D = NULL; + m_bObeyDxCommandlineOverride = true; + m_bAdapterInfoIntialized = false; + +#if defined( PIX_INSTRUMENTATION ) && defined ( DX_TO_GL_ABSTRACTION ) && defined( _WIN32 ) + m_hD3D9 = NULL; + m_pBeginEvent = NULL; + m_pEndEvent = NULL; + m_pSetMarker = NULL; + m_pSetOptions = NULL; +#endif +} + +CShaderDeviceMgrDx8::~CShaderDeviceMgrDx8() +{ +} + +#ifdef OSX +#include +#endif +//----------------------------------------------------------------------------- +// Connect, disconnect +//----------------------------------------------------------------------------- +bool CShaderDeviceMgrDx8::Connect( CreateInterfaceFn factory ) +{ + LOCK_SHADERAPI(); + + if ( !BaseClass::Connect( factory ) ) + return false; + +#if defined ( DX_TO_GL_ABSTRACTION ) + gGL = ToGLConnectLibraries( factory ); +#endif + +#if defined(IS_WINDOWS_PC) && defined(SHADERAPIDX9) && !defined(RECORDING) && !defined( DX_TO_GL_ABSTRACTION ) + m_pD3D = NULL; + + // Attempt to create a D3D9Ex device (Windows Vista and later) if possible + bool bD3D9ExForceDisable = ( CommandLine()->FindParm( "-nod3d9ex" ) != 0 ) || + ( CommandLine()->ParmValue( "-dxlevel", 95 ) < 90 ); + + bool bD3D9ExAvailable = false; + if ( HMODULE hMod = ::LoadLibraryA( "d3d9.dll" ) ) + { + typedef HRESULT ( WINAPI *CreateD3D9ExFunc_t )( UINT, IUnknown** ); + if ( CreateD3D9ExFunc_t pfnCreateD3D9Ex = (CreateD3D9ExFunc_t) ::GetProcAddress( hMod, "Direct3DCreate9Ex" ) ) + { + IUnknown *pD3D9Ex = NULL; + if ( (*pfnCreateD3D9Ex)( D3D_SDK_VERSION, &pD3D9Ex ) == S_OK && pD3D9Ex ) + { + bD3D9ExAvailable = true; + if ( bD3D9ExForceDisable ) + { + pD3D9Ex->Release(); + } + else + { + g_ShaderDeviceUsingD3D9Ex = true; + // The following is more "correct" but incompatible with the Steam overlay: + //pD3D9Ex->QueryInterface( IID_IDirect3D9, (void**) &m_pD3D ); + //pD3D9Ex->Release(); + m_pD3D = static_cast< IDirect3D9* >( pD3D9Ex ); + } + } + } + ::FreeLibrary( hMod ); + } + + if ( !m_pD3D ) + { + g_ShaderDeviceUsingD3D9Ex = false; + m_pD3D = Direct3DCreate9(D3D_SDK_VERSION); + } + + mat_supports_d3d9ex.SetValue( bD3D9ExAvailable ? 1 : 0 ); +#else + #if defined( DO_DX9_HOOK ) + m_pD3D = Direct3DCreate9Hook(D3D_SDK_VERSION); + #else + m_pD3D = Direct3DCreate9(D3D_SDK_VERSION); + #endif +#endif + + if ( !m_pD3D ) + { + Warning( "Failed to create D3D9!\n" ); + return false; + } + +#if defined( PIX_INSTRUMENTATION ) && defined ( DX_TO_GL_ABSTRACTION ) && defined( _WIN32 ) + // This is a little odd, but AMD PerfStudio hooks D3D9.DLL and intercepts all of the D3DPERF API's (even for OpenGL apps). + // So dynamically load d3d9.dll and get the address of these exported functions. + if ( !m_hD3D9 ) + { + m_hD3D9 = LoadLibraryA("d3d9.dll"); + } + if ( m_hD3D9 ) + { + Plat_DebugString( "PIX_INSTRUMENTATION: Loaded d3d9.dll\n" ); + printf( "PIX_INSTRUMENTATION: Loaded d3d9.dll\n" ); + + m_pBeginEvent = (D3DPERF_BeginEvent_FuncPtr)GetProcAddress( m_hD3D9, "D3DPERF_BeginEvent" ); + m_pEndEvent = (D3DPERF_EndEvent_FuncPtr)GetProcAddress( m_hD3D9, "D3DPERF_EndEvent" ); + m_pSetMarker = (D3DPERF_SetMarker_FuncPtr)GetProcAddress( m_hD3D9, "D3DPERF_SetOptions" ); + m_pSetOptions = (D3DPERF_SetOptions_FuncPtr)GetProcAddress( m_hD3D9, "D3DPERF_SetMarker" ); + } +#endif + + // FIXME: Want this to be here, but we can't because Steam + // hasn't had it's application ID set up yet. + +// InitAdapterInfo(); + return true; +} + +void CShaderDeviceMgrDx8::Disconnect() +{ + LOCK_SHADERAPI(); + +#if defined( PIX_INSTRUMENTATION ) && defined ( DX_TO_GL_ABSTRACTION ) && defined( _WIN32 ) + if ( m_hD3D9 ) + { + m_pBeginEvent = NULL; + m_pEndEvent = NULL; + m_pSetMarker = NULL; + m_pSetOptions = NULL; + + FreeLibrary( m_hD3D9 ); + m_hD3D9 = NULL; + } +#endif + + if ( m_pD3D ) + { + m_pD3D->Release(); + m_pD3D = 0; + } + +#if defined ( DX_TO_GL_ABSTRACTION ) + ToGLDisconnectLibraries(); +#endif + + BaseClass::Disconnect(); +} + + + +//----------------------------------------------------------------------------- +// Initialization +//----------------------------------------------------------------------------- +InitReturnVal_t CShaderDeviceMgrDx8::Init( ) +{ + // FIXME: Remove call to InitAdapterInfo once Steam startup issues are resolved. + // Do it in Connect instead. + InitAdapterInfo(); + + return INIT_OK; +} + + +//----------------------------------------------------------------------------- +// Shutdown +//----------------------------------------------------------------------------- +void CShaderDeviceMgrDx8::Shutdown( ) +{ + LOCK_SHADERAPI(); + +// FIXME: Make PIX work + +// BeginPIXEvent( PIX_VALVE_ORANGE, "Shutdown" ); + + if ( g_pShaderAPI ) + { + g_pShaderAPI->OnDeviceShutdown(); + } + + if ( g_pShaderDevice ) + { + g_pShaderDevice->ShutdownDevice(); + g_pMaterialSystemHardwareConfig = NULL; + } + +// EndPIXEvent(); + + +} + + + +//----------------------------------------------------------------------------- +// Inline methods +//----------------------------------------------------------------------------- + + +//----------------------------------------------------------------------------- +// Initialize adapter information +//----------------------------------------------------------------------------- +void CShaderDeviceMgrDx8::InitAdapterInfo() +{ + if ( m_bAdapterInfoIntialized ) + return; + + m_bAdapterInfoIntialized = true; + m_Adapters.RemoveAll(); + + Assert(m_pD3D); + int nCount = m_pD3D->GetAdapterCount( ); + for( int i = 0; i < nCount; ++i ) + { + int j = m_Adapters.AddToTail(); + AdapterInfo_t &info = m_Adapters[j]; + +#ifdef _DEBUG + memset( &info.m_ActualCaps, 0xDD, sizeof(info.m_ActualCaps) ); +#endif + + info.m_ActualCaps.m_bDeviceOk = ComputeCapsFromD3D( &info.m_ActualCaps, i ); + if ( !info.m_ActualCaps.m_bDeviceOk ) + continue; + + ReadDXSupportLevels( info.m_ActualCaps ); + + // Read dxsupport.cfg which has config overrides for particular cards. + ReadHardwareCaps( info.m_ActualCaps, info.m_ActualCaps.m_nMaxDXSupportLevel ); + + // What's in "-shader" overrides dxsupport.cfg + const char *pShaderParam = CommandLine()->ParmValue( "-shader" ); + if ( pShaderParam ) + { + Q_strncpy( info.m_ActualCaps.m_pShaderDLL, pShaderParam, sizeof( info.m_ActualCaps.m_pShaderDLL ) ); + } + } +} + +//-------------------------------------------------------------------------------- +// Code to detect support for texture border color (widely supported but the caps +// bit is messed up in drivers due to a stupid WHQL test that requires this to work +// with float textures which we don't generally care about wrt this address mode) +//-------------------------------------------------------------------------------- +void CShaderDeviceMgrDx8::CheckBorderColorSupport( HardwareCaps_t *pCaps, int nAdapter ) +{ +#ifdef DX_TO_GL_ABSTRACTION + if( true ) +#else + if( IsX360() ) +#endif + { + pCaps->m_bSupportsBorderColor = true; + } + else // Most PC parts do this, but let's not deal with that yet (JasonM) + { + pCaps->m_bSupportsBorderColor = false; + } +} + +//-------------------------------------------------------------------------------- +// Vendor-dependent code to detect support for various flavors of shadow mapping +//-------------------------------------------------------------------------------- +void CShaderDeviceMgrDx8::CheckVendorDependentShadowMappingSupport( HardwareCaps_t *pCaps, int nAdapter ) +{ + // Set a default null texture format...may be overridden below by IHV-specific surface type + pCaps->m_NullTextureFormat = IMAGE_FORMAT_ARGB8888; + if ( m_pD3D->CheckDeviceFormat( nAdapter, DX8_DEVTYPE, D3DFMT_X8R8G8B8, D3DUSAGE_RENDERTARGET, D3DRTYPE_TEXTURE, D3DFMT_R5G6B5 ) == S_OK ) + { + pCaps->m_NullTextureFormat = IMAGE_FORMAT_RGB565; + } + +#if defined( _X360 ) + pCaps->m_ShadowDepthTextureFormat = ReverseDepthOnX360() ? IMAGE_FORMAT_X360_DST24F : IMAGE_FORMAT_X360_DST24; + pCaps->m_bSupportsShadowDepthTextures = true; + pCaps->m_bSupportsFetch4 = false; + return; +#elif defined ( DX_TO_GL_ABSTRACTION ) + // We may want to only do this on the higher-end Mac SKUs, since it's not free... + pCaps->m_ShadowDepthTextureFormat = IMAGE_FORMAT_NV_DST16; // This format shunts us down the right shader combo path + + pCaps->m_bSupportsShadowDepthTextures = true; + + pCaps->m_bSupportsFetch4 = false; + return; +#endif + + if ( IsPC() || !IsX360() ) + { + bool bToolsMode = IsWindows() && ( CommandLine()->CheckParm( "-tools" ) != NULL ); + bool bFound16Bit = false; + + if ( ( pCaps->m_VendorID == VENDORID_NVIDIA ) && ( pCaps->m_SupportsShaderModel_3_0 ) ) // ps_3_0 parts from nVidia + { + // First, test for null texture support + if ( m_pD3D->CheckDeviceFormat( nAdapter, DX8_DEVTYPE, D3DFMT_X8R8G8B8, D3DUSAGE_RENDERTARGET, D3DRTYPE_TEXTURE, NVFMT_NULL ) == S_OK ) + { + pCaps->m_NullTextureFormat = IMAGE_FORMAT_NV_NULL; + } + + // + // NVIDIA has two no-PCF formats (these are not filtering modes, but surface formats + // NVFMT_RAWZ is supported by NV4x (not supported here yet...requires a dp3 to reconstruct in shader code, which doesn't seem to work) + // NVFMT_INTZ is supported on newer chips as of G8x (just read like ATI non-fetch4 mode) + // +/* + if ( m_pD3D->CheckDeviceFormat( nAdapter, DX8_DEVTYPE, D3DFMT_X8R8G8B8, D3DUSAGE_RENDERTARGET, D3DRTYPE_TEXTURE, NVFMT_INTZ ) == S_OK ) + { + pCaps->m_ShadowDepthTextureFormat = IMAGE_FORMAT_NV_INTZ; + pCaps->m_bSupportsFetch4 = false; + pCaps->m_bSupportsShadowDepthTextures = true; + return; + } +*/ + if ( m_pD3D->CheckDeviceFormat( nAdapter, DX8_DEVTYPE, D3DFMT_X8R8G8B8, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_TEXTURE, D3DFMT_D16 ) == S_OK ) + { + pCaps->m_ShadowDepthTextureFormat = IMAGE_FORMAT_NV_DST16; + pCaps->m_bSupportsFetch4 = false; + pCaps->m_bSupportsShadowDepthTextures = true; + bFound16Bit = true; + + if ( !bToolsMode ) // Tools will continue on and try for 24 bit... + return; + } + + if ( m_pD3D->CheckDeviceFormat( nAdapter, DX8_DEVTYPE, D3DFMT_X8R8G8B8, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_TEXTURE, D3DFMT_D24S8 ) == S_OK ) + { + pCaps->m_ShadowDepthTextureFormat = IMAGE_FORMAT_NV_DST24; + pCaps->m_bSupportsFetch4 = false; + pCaps->m_bSupportsShadowDepthTextures = true; + return; + } + + if ( bFound16Bit ) // Found 16 bit but not 24 + return; + } + else if ( ( pCaps->m_VendorID == VENDORID_ATI ) && pCaps->m_SupportsPixelShaders_2_b ) // ps_2_b parts from ATI + { + // Initially, check for Fetch4 (tied to ATIFMT_D24S8 support) + pCaps->m_bSupportsFetch4 = false; + if ( m_pD3D->CheckDeviceFormat( nAdapter, DX8_DEVTYPE, D3DFMT_X8R8G8B8, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_TEXTURE, ATIFMT_D24S8 ) == S_OK ) + { + pCaps->m_bSupportsFetch4 = true; + } + + if ( m_pD3D->CheckDeviceFormat( nAdapter, DX8_DEVTYPE, D3DFMT_X8R8G8B8, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_TEXTURE, ATIFMT_D16 ) == S_OK ) // Prefer 16-bit + { + pCaps->m_ShadowDepthTextureFormat = IMAGE_FORMAT_ATI_DST16; + pCaps->m_bSupportsShadowDepthTextures = true; + bFound16Bit = true; + + if ( !bToolsMode ) // Tools will continue on and try for 24 bit... + return; + } + + if ( m_pD3D->CheckDeviceFormat( nAdapter, DX8_DEVTYPE, D3DFMT_X8R8G8B8, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_TEXTURE, ATIFMT_D24S8 ) == S_OK ) + { + pCaps->m_ShadowDepthTextureFormat = IMAGE_FORMAT_ATI_DST24; + pCaps->m_bSupportsShadowDepthTextures = true; + return; + } + + if ( bFound16Bit ) // Found 16 bit but not 24 + return; + } + } + + // Other vendor or old hardware + pCaps->m_ShadowDepthTextureFormat = IMAGE_FORMAT_UNKNOWN; + pCaps->m_bSupportsShadowDepthTextures = false; + pCaps->m_bSupportsFetch4 = false; +} + + +//----------------------------------------------------------------------------- +// Vendor-dependent code to detect Alpha To Coverage Backdoors +//----------------------------------------------------------------------------- +void CShaderDeviceMgrDx8::CheckVendorDependentAlphaToCoverage( HardwareCaps_t *pCaps, int nAdapter ) +{ + pCaps->m_bSupportsAlphaToCoverage = false; + + // Bail out on OpenGL +#ifdef DX_TO_GL_ABSTRACTION + pCaps->m_bSupportsAlphaToCoverage = true; + pCaps->m_AlphaToCoverageEnableValue = TRUE; + pCaps->m_AlphaToCoverageDisableValue = FALSE; + pCaps->m_AlphaToCoverageState = D3DRS_ADAPTIVETESS_Y; // Just match the NVIDIA state hackery + return; +#endif + + if ( pCaps->m_nDXSupportLevel < 90 ) + return; + +#ifdef _X360 + { + pCaps->m_bSupportsAlphaToCoverage = true; + pCaps->m_AlphaToCoverageEnableValue = TRUE; + pCaps->m_AlphaToCoverageDisableValue = FALSE; + pCaps->m_AlphaToCoverageState = D3DRS_ALPHATOMASKENABLE; + return; + } +#endif // _X360 + + if ( pCaps->m_VendorID == VENDORID_NVIDIA ) + { + // nVidia has two modes...assume SSAA is superior to MSAA and hence more desirable (though it's probably not) + // + // Currently, they only seem to expose any of this on 7800 and up though older parts certainly + // support at least the MSAA mode since they support it on OpenGL via the arb_multisample extension + bool bNVIDIA_MSAA = false; + bool bNVIDIA_SSAA = false; + + if ( m_pD3D->CheckDeviceFormat( nAdapter, DX8_DEVTYPE, // Check MSAA version + D3DFMT_X8R8G8B8, 0, D3DRTYPE_SURFACE, + (D3DFORMAT)MAKEFOURCC('A', 'T', 'O', 'C')) == S_OK ) + { + bNVIDIA_MSAA = true; + } + + if ( m_pD3D->CheckDeviceFormat( nAdapter, DX8_DEVTYPE, // Check SSAA version + D3DFMT_X8R8G8B8, 0, D3DRTYPE_SURFACE, + (D3DFORMAT)MAKEFOURCC('S', 'S', 'A', 'A')) == S_OK ) + { + bNVIDIA_SSAA = true; + } + + // nVidia pitches SSAA but we prefer ATOC + if ( bNVIDIA_MSAA )// || bNVIDIA_SSAA ) + { + // if ( bNVIDIA_SSAA ) + // m_AlphaToCoverageEnableValue = MAKEFOURCC('S', 'S', 'A', 'A'); + // else + pCaps->m_AlphaToCoverageEnableValue = MAKEFOURCC('A', 'T', 'O', 'C'); + + pCaps->m_AlphaToCoverageState = D3DRS_ADAPTIVETESS_Y; + pCaps->m_AlphaToCoverageDisableValue = (DWORD)D3DFMT_UNKNOWN; + pCaps->m_bSupportsAlphaToCoverage = true; + return; + } + } + else if ( pCaps->m_VendorID == VENDORID_ATI ) + { + // Supported on all ATI parts...just go ahead and set the state when appropriate + pCaps->m_AlphaToCoverageState = D3DRS_POINTSIZE; + pCaps->m_AlphaToCoverageEnableValue = MAKEFOURCC('A','2','M','1'); + pCaps->m_AlphaToCoverageDisableValue = MAKEFOURCC('A','2','M','0'); + pCaps->m_bSupportsAlphaToCoverage = true; + return; + } +} + +ConVar mat_hdr_level( "mat_hdr_level", "2", FCVAR_ARCHIVE ); +ConVar mat_slopescaledepthbias_shadowmap( "mat_slopescaledepthbias_shadowmap", "16", FCVAR_CHEAT ); +#ifdef DX_TO_GL_ABSTRACTION +ConVar mat_depthbias_shadowmap( "mat_depthbias_shadowmap", "20", FCVAR_CHEAT | FCVAR_DEVELOPMENTONLY ); +#else +ConVar mat_depthbias_shadowmap( "mat_depthbias_shadowmap", "0.0005", FCVAR_CHEAT ); +#endif + +// For testing Fast Clip +ConVar mat_fastclip( "mat_fastclip", "0", FCVAR_CHEAT ); + +//----------------------------------------------------------------------------- +// Determine capabilities +//----------------------------------------------------------------------------- +bool CShaderDeviceMgrDx8::ComputeCapsFromD3D( HardwareCaps_t *pCaps, int nAdapter ) +{ + D3DCAPS caps; + D3DADAPTER_IDENTIFIER9 ident; + HRESULT hr; + + // NOTE: When getting the caps, we want to be limited by the hardware + // even if we're running with software T&L... + hr = m_pD3D->GetDeviceCaps( nAdapter, DX8_DEVTYPE, &caps ); + if ( FAILED( hr ) ) + return false; + + hr = m_pD3D->GetAdapterIdentifier( nAdapter, D3DENUM_WHQL_LEVEL, &ident ); + if ( FAILED( hr ) ) + return false; + + if ( IsOpenGL() ) + { + if ( !ident.DeviceId && !ident.VendorId ) + { + ident.DeviceId = 1; // fake default device/vendor ID for OpenGL + ident.VendorId = 1; + } + } + + // Intended for debugging only + if ( CommandLine()->CheckParm( "-force_device_id" ) ) + { + const char *pDevID = CommandLine()->ParmValue( "-force_device_id", "" ); + if ( pDevID ) + { + int nDevID = V_atoi( pDevID ); // use V_atoi for hex support + if ( nDevID > 0 ) + { + ident.DeviceId = nDevID; + } + } + } + + // Intended for debugging only + if ( CommandLine()->CheckParm( "-force_vendor_id" ) ) + { + const char *pVendorID = CommandLine()->ParmValue( "-force_vendor_id", "" ); + if ( pVendorID ) + { + int nVendorID = V_atoi( pVendorID ); // use V_atoi for hex support + if ( pVendorID > 0 ) + { + ident.VendorId = nVendorID; + } + } + } + + Q_strncpy( pCaps->m_pDriverName, ident.Description, MATERIAL_ADAPTER_NAME_LENGTH ); + pCaps->m_VendorID = ident.VendorId; + pCaps->m_DeviceID = ident.DeviceId; + pCaps->m_SubSysID = ident.SubSysId; + pCaps->m_Revision = ident.Revision; + + pCaps->m_nDriverVersionHigh = ident.DriverVersion.HighPart; + pCaps->m_nDriverVersionLow = ident.DriverVersion.LowPart; + + pCaps->m_pShaderDLL[0] = 0; + pCaps->m_nMaxViewports = 1; + + pCaps->m_PreferDynamicTextures = ( caps.Caps2 & D3DCAPS2_DYNAMICTEXTURES ) ? 1 : 0; + + pCaps->m_HasProjectedBumpEnv = ( caps.TextureCaps & D3DPTEXTURECAPS_NOPROJECTEDBUMPENV ) == 0; + + pCaps->m_HasSetDeviceGammaRamp = (caps.Caps2 & D3DCAPS2_CANCALIBRATEGAMMA) != 0; + pCaps->m_SupportsVertexShaders = ((caps.VertexShaderVersion >> 8) & 0xFF) >= 1; + pCaps->m_SupportsPixelShaders = ((caps.PixelShaderVersion >> 8) & 0xFF) >= 1; + + pCaps->m_bScissorSupported = ( caps.RasterCaps & D3DPRASTERCAPS_SCISSORTEST ) != 0; + +#if defined( DX8_COMPATABILITY_MODE ) + pCaps->m_SupportsPixelShaders_1_4 = false; + pCaps->m_SupportsPixelShaders_2_0 = false; + pCaps->m_SupportsPixelShaders_2_b = false; + pCaps->m_SupportsVertexShaders_2_0 = false; + pCaps->m_SupportsShaderModel_3_0 = false; + pCaps->m_SupportsMipmappedCubemaps = false; +#else + pCaps->m_SupportsPixelShaders_1_4 = ( caps.PixelShaderVersion & 0xffff ) >= 0x0104; + pCaps->m_SupportsPixelShaders_2_0 = ( caps.PixelShaderVersion & 0xffff ) >= 0x0200; + pCaps->m_SupportsPixelShaders_2_b = ( ( caps.PixelShaderVersion & 0xffff ) >= 0x0200) && (caps.PS20Caps.NumInstructionSlots >= 512); // More caps to this, but this will do + pCaps->m_SupportsVertexShaders_2_0 = ( caps.VertexShaderVersion & 0xffff ) >= 0x0200; + pCaps->m_SupportsShaderModel_3_0 = ( caps.PixelShaderVersion & 0xffff ) >= 0x0300; + pCaps->m_SupportsMipmappedCubemaps = ( caps.TextureCaps & D3DPTEXTURECAPS_MIPCUBEMAP ) ? true : false; +#endif + + // Slam this off for OpenGL + if ( IsOpenGL() ) + { + pCaps->m_SupportsShaderModel_3_0 = false; + } + + // Slam 3.0 shaders off for Intel + if ( pCaps->m_VendorID == VENDORID_INTEL ) + { + pCaps->m_SupportsShaderModel_3_0 = false; + } + + pCaps->m_MaxVertexShader30InstructionSlots = 0; + pCaps->m_MaxPixelShader30InstructionSlots = 0; + + if ( pCaps->m_SupportsShaderModel_3_0 ) + { + pCaps->m_MaxVertexShader30InstructionSlots = caps.MaxVertexShader30InstructionSlots; + pCaps->m_MaxPixelShader30InstructionSlots = caps.MaxPixelShader30InstructionSlots; + } + + if( CommandLine()->CheckParm( "-nops2b" ) ) + { + pCaps->m_SupportsPixelShaders_2_b = false; + } + + pCaps->m_bSoftwareVertexProcessing = false; + if ( IsWindows() && CommandLine()->CheckParm( "-mat_softwaretl" ) ) + { + pCaps->m_bSoftwareVertexProcessing = true; + } + + if ( IsWindows() && !( caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT ) ) + { + // no hardware t&l. . use software + pCaps->m_bSoftwareVertexProcessing = true; + } + + // Set mat_forcedynamic if software vertex processing since the software vp pipe has + // problems with sparse vertex buffers (it transforms the whole thing.) + if ( pCaps->m_bSoftwareVertexProcessing ) + { + mat_forcedynamic.SetValue( 1 ); + } + + if ( pCaps->m_bSoftwareVertexProcessing ) + { + pCaps->m_SupportsVertexShaders = true; + pCaps->m_SupportsVertexShaders_2_0 = true; + } + +#ifdef OSX + // Static control flow is disabled by default on OSX (the Mac version of togl has known bugs preventing this path from working properly that we've fixed in togl linux/win) + pCaps->m_bSupportsStaticControlFlow = CommandLine()->CheckParm( "-glslcontrolflow" ) != NULL; +#else + pCaps->m_bSupportsStaticControlFlow = !CommandLine()->CheckParm( "-noglslcontrolflow" ); +#endif + + // NOTE: Texture stages is a fixed-function concept + // NOTE: Normally, the number of texture units == the number of texture + // stages except for NVidia hardware, which reports more stages than units. + // The reason for this is because they expose the inner hardware pixel + // pipeline through the extra stages. The only thing we use stages for + // in the hardware is for configuring the color + alpha args + ops. + pCaps->m_NumSamplers = caps.MaxSimultaneousTextures; + pCaps->m_NumTextureStages = caps.MaxTextureBlendStages; + if ( pCaps->m_SupportsPixelShaders_2_0 ) + { + pCaps->m_NumSamplers = 16; + } + else + { + Assert( pCaps->m_NumSamplers <= pCaps->m_NumTextureStages ); + } + + // Clamp + pCaps->m_NumSamplers = min( pCaps->m_NumSamplers, (int)MAX_SAMPLERS ); + pCaps->m_NumTextureStages = min( pCaps->m_NumTextureStages, (int)MAX_TEXTURE_STAGES ); + + if ( D3DSupportsCompressedTextures() ) + { + pCaps->m_SupportsCompressedTextures = COMPRESSED_TEXTURES_ON; + } + else + { + pCaps->m_SupportsCompressedTextures = COMPRESSED_TEXTURES_OFF; + } + + pCaps->m_bSupportsAnisotropicFiltering = (caps.TextureFilterCaps & D3DPTFILTERCAPS_MINFANISOTROPIC) != 0; + pCaps->m_bSupportsMagAnisotropicFiltering = (caps.TextureFilterCaps & D3DPTFILTERCAPS_MAGFANISOTROPIC) != 0; + + // OpenGL does not support this--at least not on OSX which is the primary GL target, so just don't use that path on GL at all. +#if !defined( DX_TO_GL_ABSTRACTION ) + pCaps->m_bCanStretchRectFromTextures = ( ( caps.DevCaps2 & D3DDEVCAPS2_CAN_STRETCHRECT_FROM_TEXTURES ) != 0 ) && ( pCaps->m_VendorID != VENDORID_INTEL ); +#else + pCaps->m_bCanStretchRectFromTextures = false; +#endif + + pCaps->m_nMaxAnisotropy = pCaps->m_bSupportsAnisotropicFiltering ? caps.MaxAnisotropy : 1; + + pCaps->m_SupportsCubeMaps = ( caps.TextureCaps & D3DPTEXTURECAPS_CUBEMAP ) ? true : false; + pCaps->m_SupportsNonPow2Textures = + ( !( caps.TextureCaps & D3DPTEXTURECAPS_POW2 ) || + ( caps.TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL ) ); + + Assert( caps.TextureCaps & D3DPTEXTURECAPS_PROJECTED ); + + if ( pCaps->m_bSoftwareVertexProcessing ) + { + // This should be pushed down based on pixel shaders. + pCaps->m_NumVertexShaderConstants = 256; + pCaps->m_NumBooleanVertexShaderConstants = pCaps->m_SupportsPixelShaders_2_0 ? 16 : 0; // 2.0 parts have 16 bool vs registers + pCaps->m_NumBooleanPixelShaderConstants = pCaps->m_SupportsPixelShaders_2_0 ? 16 : 0; // 2.0 parts have 16 bool ps registers + pCaps->m_NumIntegerVertexShaderConstants = pCaps->m_SupportsPixelShaders_2_0 ? 16 : 0; // 2.0 parts have 16 bool vs registers + pCaps->m_NumIntegerPixelShaderConstants = pCaps->m_SupportsPixelShaders_2_0 ? 16 : 0; // 2.0 parts have 16 bool ps registers + } + else + { + pCaps->m_NumVertexShaderConstants = caps.MaxVertexShaderConst; + if ( CommandLine()->FindParm( "-limitvsconst" ) ) + { + pCaps->m_NumVertexShaderConstants = min( 256, pCaps->m_NumVertexShaderConstants ); + } + pCaps->m_NumBooleanVertexShaderConstants = pCaps->m_SupportsPixelShaders_2_0 ? 16 : 0; // 2.0 parts have 16 bool vs registers + pCaps->m_NumBooleanPixelShaderConstants = pCaps->m_SupportsPixelShaders_2_0 ? 16 : 0; // 2.0 parts have 16 bool ps registers + + // This is a little misleading...this is really 16 int4 registers + pCaps->m_NumIntegerVertexShaderConstants = pCaps->m_SupportsPixelShaders_2_0 ? 16 : 0; // 2.0 parts have 16 bool vs registers + pCaps->m_NumIntegerPixelShaderConstants = pCaps->m_SupportsPixelShaders_2_0 ? 16 : 0; // 2.0 parts have 16 bool ps registers + } + + if ( pCaps->m_SupportsPixelShaders ) + { + if ( pCaps->m_SupportsPixelShaders_2_0 ) + { + pCaps->m_NumPixelShaderConstants = 32; + } + else + { + pCaps->m_NumPixelShaderConstants = 8; + } + } + else + { + pCaps->m_NumPixelShaderConstants = 0; + } + + pCaps->m_SupportsHardwareLighting = (caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) != 0; + + pCaps->m_MaxNumLights = caps.MaxActiveLights; + if ( pCaps->m_MaxNumLights > MAX_NUM_LIGHTS ) + { + pCaps->m_MaxNumLights = MAX_NUM_LIGHTS; + } + + if ( IsOpenGL() ) + { + // Set according to control flow bit on OpenGL + pCaps->m_MaxNumLights = MIN( pCaps->m_MaxNumLights, ( pCaps->m_bSupportsStaticControlFlow && pCaps->m_SupportsPixelShaders_2_b ) ? MAX_NUM_LIGHTS : ( MAX_NUM_LIGHTS - 2 ) ); + } + + if ( pCaps->m_bSoftwareVertexProcessing ) + { + pCaps->m_SupportsHardwareLighting = true; + pCaps->m_MaxNumLights = 2; + } + pCaps->m_MaxTextureWidth = caps.MaxTextureWidth; + pCaps->m_MaxTextureHeight = caps.MaxTextureHeight; + pCaps->m_MaxTextureDepth = caps.MaxVolumeExtent ? caps.MaxVolumeExtent : 1; + pCaps->m_MaxTextureAspectRatio = caps.MaxTextureAspectRatio; + if ( pCaps->m_MaxTextureAspectRatio == 0 ) + { + pCaps->m_MaxTextureAspectRatio = max( pCaps->m_MaxTextureWidth, pCaps->m_MaxTextureHeight); + } + pCaps->m_MaxPrimitiveCount = caps.MaxPrimitiveCount; + pCaps->m_MaxBlendMatrices = caps.MaxVertexBlendMatrices; + pCaps->m_MaxBlendMatrixIndices = caps.MaxVertexBlendMatrixIndex; + + bool addSupported = (caps.TextureOpCaps & D3DTEXOPCAPS_ADD) != 0; + bool modSupported = (caps.TextureOpCaps & D3DTEXOPCAPS_MODULATE2X) != 0; + + pCaps->m_bNeedsATICentroidHack = false; + pCaps->m_bDisableShaderOptimizations = false; + + pCaps->m_SupportsMipmapping = true; + pCaps->m_SupportsOverbright = true; + + // Thank you to all you driver writers who actually correctly return caps + if ( !modSupported || !addSupported ) + { + Assert( 0 ); + pCaps->m_SupportsOverbright = false; + } + + // Check if ZBias and SlopeScaleDepthBias are supported. .if not, tweak the projection matrix instead + // for polyoffset. + pCaps->m_ZBiasAndSlopeScaledDepthBiasSupported = + ( ( caps.RasterCaps & D3DPRASTERCAPS_DEPTHBIAS) != 0 ) && + ( ( caps.RasterCaps & D3DPRASTERCAPS_SLOPESCALEDEPTHBIAS ) != 0 ); + if ( IsX360() ) + { + // driver lies, force it + pCaps->m_ZBiasAndSlopeScaledDepthBiasSupported = true; + } + + // Spheremapping supported? + pCaps->m_bSupportsSpheremapping = (caps.VertexProcessingCaps & D3DVTXPCAPS_TEXGEN_SPHEREMAP) != 0; + + // How many user clip planes? + pCaps->m_MaxUserClipPlanes = caps.MaxUserClipPlanes; + if ( CommandLine()->CheckParm( "-nouserclip" ) /* || (IsOpenGL() && (!CommandLine()->FindParm("-glslmode"))) || r_emulategl.GetBool() */ ) + { + // rbarris 03Feb10: this now ignores POSIX / -glslmode / r_emulategl because we're defaulting GLSL mode "on". + // so this will mean that the engine will always ask for user clip planes. + // this will misbehave under ARB mode, since ARB shaders won't respect that state. + // it's difficult to make this fluid without teaching the engine about a cap that could change during run. + + pCaps->m_MaxUserClipPlanes = 0; + } + + if ( pCaps->m_MaxUserClipPlanes > MAXUSERCLIPPLANES ) + { + pCaps->m_MaxUserClipPlanes = MAXUSERCLIPPLANES; + } + + pCaps->m_FakeSRGBWrite = false; + pCaps->m_CanDoSRGBReadFromRTs = true; + pCaps->m_bSupportsGLMixedSizeTargets = false; +#ifdef DX_TO_GL_ABSTRACTION + // using #if because we're referencing fields in the RHS which don't exist in Windows headers for the caps9 struct + pCaps->m_FakeSRGBWrite = caps.FakeSRGBWrite != 0; + pCaps->m_CanDoSRGBReadFromRTs = caps.CanDoSRGBReadFromRTs != 0; + pCaps->m_bSupportsGLMixedSizeTargets = caps.MixedSizeTargets != 0; +#endif + + // Query for SRGB support as needed for our DX 9 stuff + if ( IsPC() || !IsX360() ) + { + pCaps->m_SupportsSRGB = ( D3D()->CheckDeviceFormat( nAdapter, DX8_DEVTYPE, D3DFMT_X8R8G8B8, D3DUSAGE_QUERY_SRGBREAD, D3DRTYPE_TEXTURE, D3DFMT_DXT1 ) == S_OK); + + if ( pCaps->m_SupportsSRGB ) + { + pCaps->m_SupportsSRGB = ( D3D()->CheckDeviceFormat( nAdapter, DX8_DEVTYPE, D3DFMT_X8R8G8B8, D3DUSAGE_QUERY_SRGBREAD | D3DUSAGE_QUERY_SRGBWRITE, D3DRTYPE_TEXTURE, D3DFMT_A8R8G8B8 ) == S_OK); + } + } + else + { + // 360 does support it, but is queried in the wrong manner, so force it + pCaps->m_SupportsSRGB = true; + } + + if ( CommandLine()->CheckParm( "-nosrgb" ) ) + { + pCaps->m_SupportsSRGB = false; + } + + pCaps->m_bSupportsVertexTextures = ( D3D()->CheckDeviceFormat( nAdapter, DX8_DEVTYPE, D3DFMT_X8R8G8B8, + D3DUSAGE_QUERY_VERTEXTEXTURE, D3DRTYPE_TEXTURE, D3DFMT_R32F ) == S_OK ); + + if ( IsOpenGL() ) + { + pCaps->m_bSupportsVertexTextures = false; + } + + // FIXME: vs30 has a fixed setting here at 4. + // Future hardware will need some other way of computing this. + pCaps->m_nVertexTextureCount = pCaps->m_bSupportsVertexTextures ? 4 : 0; + + // FIXME: How do I actually compute this? + pCaps->m_nMaxVertexTextureDimension = pCaps->m_bSupportsVertexTextures ? 4096 : 0; + + // Does the device support filterable int16 textures? + bool bSupportsInteger16Textures = + ( D3D()->CheckDeviceFormat( nAdapter, DX8_DEVTYPE, + D3DFMT_X8R8G8B8, D3DUSAGE_QUERY_FILTER, + D3DRTYPE_TEXTURE, D3DFMT_A16B16G16R16 ) == S_OK ); + + // Does the device support filterable fp16 textures? + bool bSupportsFloat16Textures = + ( D3D()->CheckDeviceFormat( nAdapter, DX8_DEVTYPE, + D3DFMT_X8R8G8B8, D3DUSAGE_QUERY_FILTER, + D3DRTYPE_TEXTURE, D3DFMT_A16B16G16R16F ) == S_OK ); + + // Does the device support blendable fp16 render targets? + bool bSupportsFloat16RenderTargets = + ( D3D()->CheckDeviceFormat( nAdapter, DX8_DEVTYPE, + D3DFMT_X8R8G8B8, D3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING | D3DUSAGE_RENDERTARGET, + D3DRTYPE_TEXTURE, D3DFMT_A16B16G16R16F ) == S_OK ); + + // Essentially a proxy for a DX10 device running DX9 code path + pCaps->m_bSupportsFloat32RenderTargets = ( D3D()->CheckDeviceFormat( nAdapter, DX8_DEVTYPE, + D3DFMT_X8R8G8B8, D3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING | D3DUSAGE_RENDERTARGET, + D3DRTYPE_TEXTURE, D3DFMT_A32B32G32R32F ) == S_OK ); + + pCaps->m_bFogColorSpecifiedInLinearSpace = false; + pCaps->m_bFogColorAlwaysLinearSpace = false; + + // Assume not DX10. Check below. + pCaps->m_bDX10Card = false; + pCaps->m_bDX10Blending = false; + + if ( IsOpenGL() && ( pCaps->m_VendorID == 1 ) ) + { + // Linux/Win OpenGL - always assume the device supports DX10 style blending + pCaps->m_bFogColorAlwaysLinearSpace = true; + pCaps->m_bDX10Card = true; + pCaps->m_bDX10Blending = true; + } + + // NVidia wants fog color to be specified in linear space + if ( IsPC() && pCaps->m_SupportsSRGB ) + { + if ( pCaps->m_VendorID == VENDORID_NVIDIA ) + { + pCaps->m_bFogColorSpecifiedInLinearSpace = true; + + if ( IsOpenGL() ) + { + // If we're not the Quadro 4500 or GeForce 7x000, we're an NVIDIA DX10 part on MacOS + if ( !( (pCaps->m_DeviceID == 0x009d) || ( (pCaps->m_DeviceID >= 0x0391) && (pCaps->m_DeviceID <= 0x0395) ) ) ) + { + pCaps->m_bFogColorAlwaysLinearSpace = true; + pCaps->m_bDX10Card = true; + pCaps->m_bDX10Blending = true; + } + } + else + { + // On G80 and later, always specify in linear space + if ( pCaps->m_bSupportsFloat32RenderTargets ) + { + pCaps->m_bFogColorAlwaysLinearSpace = true; + pCaps->m_bDX10Card = true; + pCaps->m_bDX10Blending = true; + } + } + } + else if ( pCaps->m_VendorID == VENDORID_ATI ) + { + if ( IsOpenGL() ) + { + // If we're not a Radeon X1x00 (device IDs in this range), we're a DX10 chip + if ( !( (pCaps->m_DeviceID >= 0x7109) && (pCaps->m_DeviceID <= 0x7291) ) ) + { + pCaps->m_bFogColorSpecifiedInLinearSpace = true; + pCaps->m_bFogColorAlwaysLinearSpace = true; + pCaps->m_bDX10Card = true; + pCaps->m_bDX10Blending = true; + } + } + else + { + // Check for DX10 part + pCaps->m_bDX10Card = pCaps->m_SupportsShaderModel_3_0 && + ( pCaps->m_MaxVertexShader30InstructionSlots > 1024 ) && + ( pCaps->m_MaxPixelShader30InstructionSlots > 512 ) ; + + // On ATI, DX10 card means DX10 blending + pCaps->m_bDX10Blending = pCaps->m_bDX10Card; + + if( pCaps->m_bDX10Blending ) + { + pCaps->m_bFogColorSpecifiedInLinearSpace = true; + pCaps->m_bFogColorAlwaysLinearSpace = true; + } + } + } + else if ( pCaps->m_VendorID == VENDORID_INTEL ) + { + // Intel does not have performant vertex textures + pCaps->m_bDX10Card = false; + + // Intel supports DX10 SRGB on Broadwater and better + // The two checks are for devices from GMA generation (0x29A2-0x2A43) and HD graphics (0x0042-0x2500) + pCaps->m_bDX10Blending = ( ( pCaps->m_DeviceID >= 0x29A2 ) && ( pCaps->m_DeviceID <= 0x2A43 ) ) || + ( ( pCaps->m_DeviceID >= 0x0042 ) && ( pCaps->m_DeviceID <= 0x2500 ) ); + + if( pCaps->m_bDX10Blending ) + { + pCaps->m_bFogColorSpecifiedInLinearSpace = true; + pCaps->m_bFogColorAlwaysLinearSpace = true; + } + } + } + + // Do we have everything necessary to run with integer HDR? Note that + // even if we don't support integer 16-bit/component textures, we + // can still run in this mode if fp16 textures are supported. + bool bSupportsIntegerHDR = pCaps->m_SupportsPixelShaders_2_0 && + pCaps->m_SupportsVertexShaders_2_0 && + // (caps.Caps3 & D3DCAPS3_ALPHA_FULLSCREEN_FLIP_OR_DISCARD) && + // (caps.PrimitiveMiscCaps & D3DPMISCCAPS_SEPARATEALPHABLEND) && + ( bSupportsInteger16Textures || bSupportsFloat16Textures ) && + pCaps->m_SupportsSRGB; + + // Do we have everything necessary to run with float HDR? + bool bSupportsFloatHDR = pCaps->m_SupportsShaderModel_3_0 && + // (caps.Caps3 & D3DCAPS3_ALPHA_FULLSCREEN_FLIP_OR_DISCARD) && + // (caps.PrimitiveMiscCaps & D3DPMISCCAPS_SEPARATEALPHABLEND) && + bSupportsFloat16Textures && + bSupportsFloat16RenderTargets && + pCaps->m_SupportsSRGB && + !IsX360(); + + pCaps->m_MaxHDRType = HDR_TYPE_NONE; + if ( bSupportsFloatHDR ) + pCaps->m_MaxHDRType = HDR_TYPE_FLOAT; + else + if ( bSupportsIntegerHDR ) + pCaps->m_MaxHDRType = HDR_TYPE_INTEGER; + + if ( bSupportsFloatHDR && ( mat_hdr_level.GetInt() == 3 ) ) + { + pCaps->m_HDRType = HDR_TYPE_FLOAT; + } + else if ( bSupportsIntegerHDR ) + { + pCaps->m_HDRType = HDR_TYPE_INTEGER; + } + else + { + pCaps->m_HDRType = HDR_TYPE_NONE; + } + + pCaps->m_bColorOnSecondStream = caps.MaxStreams > 1; + + pCaps->m_bSupportsStreamOffset = ( ( caps.DevCaps2 & D3DDEVCAPS2_STREAMOFFSET ) && // Tie these caps together since we want to filter out + pCaps->m_SupportsPixelShaders_2_0 ); // any DX8 parts which export D3DDEVCAPS2_STREAMOFFSET + + pCaps->m_flMinGammaControlPoint = 0.0f; + pCaps->m_flMaxGammaControlPoint = 65535.0f; + pCaps->m_nGammaControlPointCount = 256; + + // Compute the effective DX support level based on all the other caps + ComputeDXSupportLevel( *pCaps ); + int nCmdlineMaxDXLevel = CommandLine()->ParmValue( "-maxdxlevel", 0 ); + if ( IsOpenGL() && ( nCmdlineMaxDXLevel > 0 ) ) + { + // Prevent customers from slamming us below DX level 90 in OpenGL mode. + nCmdlineMaxDXLevel = MAX( nCmdlineMaxDXLevel, 90 ); + } + if( nCmdlineMaxDXLevel > 0 ) + { + pCaps->m_nMaxDXSupportLevel = min( pCaps->m_nMaxDXSupportLevel, nCmdlineMaxDXLevel ); + } + pCaps->m_nDXSupportLevel = pCaps->m_nMaxDXSupportLevel; + + int nModelIndex = pCaps->m_nDXSupportLevel < 90 ? VERTEX_SHADER_MODEL - 10 : VERTEX_SHADER_MODEL; + pCaps->m_MaxVertexShaderBlendMatrices = (pCaps->m_NumVertexShaderConstants - nModelIndex) / 3; + + if ( pCaps->m_MaxVertexShaderBlendMatrices > NUM_MODEL_TRANSFORMS ) + { + pCaps->m_MaxVertexShaderBlendMatrices = NUM_MODEL_TRANSFORMS; + } + + CheckBorderColorSupport( pCaps, nAdapter ); + + // This may get more complex if we start using multiple flavors of compressed vertex - for now it's "on or off" + pCaps->m_SupportsCompressedVertices = ( pCaps->m_nDXSupportLevel >= 90 ) && ( pCaps->m_CanDoSRGBReadFromRTs ) ? VERTEX_COMPRESSION_ON : VERTEX_COMPRESSION_NONE; + if ( CommandLine()->CheckParm( "-no_compressed_verts" ) ) // m_CanDoSRGBReadFromRTs limits us to Snow Leopard or later on OSX + { + pCaps->m_SupportsCompressedVertices = VERTEX_COMPRESSION_NONE; + } + + // Various vendor-dependent checks... + CheckVendorDependentAlphaToCoverage( pCaps, nAdapter ); + CheckVendorDependentShadowMappingSupport( pCaps, nAdapter ); + + // If we're not on a 3.0 part, these values are more appropriate (X800 & X850 parts from ATI do shadow mapping but not 3.0 ) + if ( !IsOpenGL() ) + { + if ( !pCaps->m_SupportsShaderModel_3_0 ) + { + mat_slopescaledepthbias_shadowmap.SetValue( 5.9f ); + mat_depthbias_shadowmap.SetValue( 0.003f ); + } + } + + if( pCaps->m_MaxUserClipPlanes == 0 ) + { + pCaps->m_UseFastClipping = true; + } + + pCaps->m_MaxSimultaneousRenderTargets = caps.NumSimultaneousRTs; + + return true; +} + +//----------------------------------------------------------------------------- +// Compute the effective DX support level based on all the other caps +//----------------------------------------------------------------------------- +void CShaderDeviceMgrDx8::ComputeDXSupportLevel( HardwareCaps_t &caps ) +{ + // NOTE: Support level is actually DX level * 10 + subversion + // So, 70 = DX7, 80 = DX8, 81 = DX8 w/ 1.4 pixel shaders + // 90 = DX9 w/ 2.0 pixel shaders + // 95 = DX9 w/ 3.0 pixel shaders and vertex textures + // 98 = DX9 XBox360 + // NOTE: 82 = NVidia nv3x cards, which can't run dx9 fast + + // FIXME: Improve this!! There should be a whole list of features + // we require in order to be considered a DX7 board, DX8 board, etc. + + if ( IsX360() ) + { + caps.m_nMaxDXSupportLevel = 98; + return; + } + + bool bIsOpenGL = IsOpenGL(); + + if ( caps.m_SupportsShaderModel_3_0 && !bIsOpenGL ) // Note that we don't tie vertex textures to 30 shaders anymore + { + caps.m_nMaxDXSupportLevel = 95; + return; + } + + // NOTE: sRGB is currently required for DX90 because it isn't doing + // gamma correctly if that feature doesn't exist + if ( caps.m_SupportsVertexShaders_2_0 && caps.m_SupportsPixelShaders_2_0 && caps.m_SupportsSRGB ) + { + caps.m_nMaxDXSupportLevel = 90; + return; + } + + if ( caps.m_SupportsPixelShaders && caps.m_SupportsVertexShaders )// && caps.m_bColorOnSecondStream) + { + if (caps.m_SupportsPixelShaders_1_4) + { + caps.m_nMaxDXSupportLevel = 81; + return; + } + caps.m_nMaxDXSupportLevel = 80; + return; + } + + if( caps.m_SupportsCubeMaps && ( caps.m_MaxBlendMatrices >= 2 ) ) + { + caps.m_nMaxDXSupportLevel = 70; + return; + } + + if ( ( caps.m_NumSamplers >= 2) && caps.m_SupportsMipmapping ) + { + caps.m_nMaxDXSupportLevel = 60; + return; + } + + Assert( 0 ); + // we don't support this! + caps.m_nMaxDXSupportLevel = 50; +} + + + +//----------------------------------------------------------------------------- +// Gets the number of adapters... +//----------------------------------------------------------------------------- +int CShaderDeviceMgrDx8::GetAdapterCount() const +{ + // FIXME: Remove call to InitAdapterInfo once Steam startup issues are resolved. + const_cast( this )->InitAdapterInfo(); + + return m_Adapters.Count(); +} + + +//----------------------------------------------------------------------------- +// Returns info about each adapter +//----------------------------------------------------------------------------- +void CShaderDeviceMgrDx8::GetAdapterInfo( int nAdapter, MaterialAdapterInfo_t& info ) const +{ + // FIXME: Remove call to InitAdapterInfo once Steam startup issues are resolved. + const_cast( this )->InitAdapterInfo(); + + Assert( ( nAdapter >= 0 ) && ( nAdapter < m_Adapters.Count() ) ); + const HardwareCaps_t &caps = m_Adapters[ nAdapter ].m_ActualCaps; + memcpy( &info, &caps, sizeof(MaterialAdapterInfo_t) ); +} + + +//----------------------------------------------------------------------------- +// Sets the adapter +//----------------------------------------------------------------------------- +bool CShaderDeviceMgrDx8::SetAdapter( int nAdapter, int nAdapterFlags ) +{ + LOCK_SHADERAPI(); + + // FIXME: + // g_pShaderDeviceDx8->m_bReadPixelsEnabled = (nAdapterFlags & MATERIAL_INIT_READ_PIXELS_ENABLED) != 0; + + // Set up hardware information for this adapter... + g_pShaderDeviceDx8->m_DeviceType = (nAdapterFlags & MATERIAL_INIT_REFERENCE_RASTERIZER) ? + D3DDEVTYPE_REF : D3DDEVTYPE_HAL; + + g_pShaderDeviceDx8->m_DisplayAdapter = nAdapter; + if ( g_pShaderDeviceDx8->m_DisplayAdapter >= (UINT)GetAdapterCount() ) + { + g_pShaderDeviceDx8->m_DisplayAdapter = 0; + } + +#ifdef NVPERFHUD + // hack for nvperfhud + g_pShaderDeviceDx8->m_DisplayAdapter = m_pD3D->GetAdapterCount() - 1; + g_pShaderDeviceDx8->m_DeviceType = D3DDEVTYPE_REF; +#endif + + // backward compat + if ( !g_pShaderDeviceDx8->OnAdapterSet() ) + return false; + +// if ( !g_pShaderDeviceDx8->Init() ) +// { +// Warning( "Unable to initialize dx8 device!\n" ); +// return false; +// } + + g_pShaderDevice = g_pShaderDeviceDx8; + + return true; +} + + +//----------------------------------------------------------------------------- +// Returns the number of modes +//----------------------------------------------------------------------------- +int CShaderDeviceMgrDx8::GetModeCount( int nAdapter ) const +{ + LOCK_SHADERAPI(); + Assert( m_pD3D && (nAdapter < GetAdapterCount() ) ); + +#if !defined( _X360 ) + // fixme - what format should I use here? + return m_pD3D->GetAdapterModeCount( nAdapter, D3DFMT_X8R8G8B8 ); +#else + return 1; // Only one mode, which is the current mode set in the 360 dashboard. Going to fill it in with exactly what the 360 is set to. +#endif +} + + +//----------------------------------------------------------------------------- +// Returns mode information.. +//----------------------------------------------------------------------------- +void CShaderDeviceMgrDx8::GetModeInfo( ShaderDisplayMode_t* pInfo, int nAdapter, int nMode ) const +{ + Assert( pInfo->m_nVersion == SHADER_DISPLAY_MODE_VERSION ); + + LOCK_SHADERAPI(); + Assert( m_pD3D && (nAdapter < GetAdapterCount() ) ); + Assert( nMode < GetModeCount( nAdapter ) ); + +#if !defined( _X360 ) + HRESULT hr; + D3DDISPLAYMODE d3dInfo; + + // fixme - what format should I use here? + hr = D3D()->EnumAdapterModes( nAdapter, D3DFMT_X8R8G8B8, nMode, &d3dInfo ); + Assert( !FAILED(hr) ); + + pInfo->m_nWidth = d3dInfo.Width; + pInfo->m_nHeight = d3dInfo.Height; + pInfo->m_Format = ImageLoader::D3DFormatToImageFormat( d3dInfo.Format ); + pInfo->m_nRefreshRateNumerator = d3dInfo.RefreshRate; + pInfo->m_nRefreshRateDenominator = 1; +#else + pInfo->m_Format = ImageLoader::D3DFormatToImageFormat( D3DFMT_X8R8G8B8 ); + pInfo->m_nRefreshRateNumerator = 60; + pInfo->m_nRefreshRateDenominator = 1; + + pInfo->m_nWidth = GetSystemMetrics( SM_CXSCREEN ); + pInfo->m_nHeight = GetSystemMetrics( SM_CYSCREEN ); +#endif +} + + +//----------------------------------------------------------------------------- +// Returns the current mode information for an adapter +//----------------------------------------------------------------------------- +void CShaderDeviceMgrDx8::GetCurrentModeInfo( ShaderDisplayMode_t* pInfo, int nAdapter ) const +{ + Assert( pInfo->m_nVersion == SHADER_DISPLAY_MODE_VERSION ); + + LOCK_SHADERAPI(); + Assert( D3D() ); + + HRESULT hr; + D3DDISPLAYMODE mode = { 0 }; +#if !defined( _X360 ) + hr = D3D()->GetAdapterDisplayMode( nAdapter, &mode ); + Assert( !FAILED(hr) ); +#else + if ( !g_pD3DDevice ) + { + // the console has no prior display or mode until its created + mode.Width = GetSystemMetrics( SM_CXSCREEN ); + mode.Height = GetSystemMetrics( SM_CYSCREEN ); + mode.RefreshRate = 60; + mode.Format = D3DFMT_X8R8G8B8; + } + else + { + hr = g_pD3DDevice->GetDisplayMode( 0, &mode ); + Assert( !FAILED(hr) ); + } +#endif + + pInfo->m_nWidth = mode.Width; + pInfo->m_nHeight = mode.Height; + pInfo->m_Format = ImageLoader::D3DFormatToImageFormat( mode.Format ); + pInfo->m_nRefreshRateNumerator = mode.RefreshRate; + pInfo->m_nRefreshRateDenominator = 1; +} + + +//----------------------------------------------------------------------------- +// Sets the video mode +//----------------------------------------------------------------------------- +CreateInterfaceFn CShaderDeviceMgrDx8::SetMode( void *hWnd, int nAdapter, const ShaderDeviceInfo_t& mode ) +{ + LOCK_SHADERAPI(); + + Assert( nAdapter < GetAdapterCount() ); + int nDXLevel = mode.m_nDXLevel != 0 ? mode.m_nDXLevel : m_Adapters[nAdapter].m_ActualCaps.m_nDXSupportLevel; + if ( m_bObeyDxCommandlineOverride ) + { + nDXLevel = CommandLine()->ParmValue( "-dxlevel", nDXLevel ); + m_bObeyDxCommandlineOverride = false; + } + if ( nDXLevel > m_Adapters[nAdapter].m_ActualCaps.m_nMaxDXSupportLevel ) + { + nDXLevel = m_Adapters[nAdapter].m_ActualCaps.m_nMaxDXSupportLevel; + } + nDXLevel = GetClosestActualDXLevel( nDXLevel ); + + if ( nDXLevel >= 100 ) + return NULL; + + bool bReacquireResourcesNeeded = false; + if ( g_pShaderDevice ) + { + bReacquireResourcesNeeded = IsPC(); + g_pShaderDevice->ReleaseResources(); + } + + if ( g_pShaderAPI ) + { + g_pShaderAPI->OnDeviceShutdown(); + g_pShaderAPI = NULL; + } + + if ( g_pShaderDevice ) + { + g_pShaderDevice->ShutdownDevice(); + g_pShaderDevice = NULL; + } + + g_pShaderShadow = NULL; + + ShaderDeviceInfo_t adjustedMode = mode; + adjustedMode.m_nDXLevel = nDXLevel; + if ( !g_pShaderDeviceDx8->InitDevice( hWnd, nAdapter, adjustedMode ) ) + return NULL; + + if ( !g_pShaderAPIDX8->OnDeviceInit() ) + return NULL; + + g_pShaderDevice = g_pShaderDeviceDx8; + g_pShaderAPI = g_pShaderAPIDX8; + g_pShaderShadow = g_pShaderShadowDx8; + + if ( bReacquireResourcesNeeded ) + { + g_pShaderDevice->ReacquireResources(); + } + + return ShaderInterfaceFactory; +} + + +//----------------------------------------------------------------------------- +// Validates the mode... +//----------------------------------------------------------------------------- +bool CShaderDeviceMgrDx8::ValidateMode( int nAdapter, const ShaderDeviceInfo_t &info ) const +{ + if ( nAdapter >= (int)D3D()->GetAdapterCount() ) + return false; + + ShaderDisplayMode_t displayMode; + + if ( info.m_bWindowed ) + { + // windowed mode always appears on the primary display, so we should use that adapter's + // settings + GetCurrentModeInfo( &displayMode, 0 ); + + // make sure the window fits within the current video mode + if ( ( info.m_DisplayMode.m_nWidth > displayMode.m_nWidth ) || + ( info.m_DisplayMode.m_nHeight > displayMode.m_nHeight ) ) + return false; + } + else + { + GetCurrentModeInfo( &displayMode, nAdapter ); + } + + // Make sure the image format requested is valid + ImageFormat backBufferFormat = FindNearestSupportedBackBufferFormat( nAdapter, + DX8_DEVTYPE, displayMode.m_Format, info.m_DisplayMode.m_Format, info.m_bWindowed ); + return ( backBufferFormat != IMAGE_FORMAT_UNKNOWN ); +} + + +//----------------------------------------------------------------------------- +// Returns the amount of video memory in bytes for a particular adapter +//----------------------------------------------------------------------------- +int CShaderDeviceMgrDx8::GetVidMemBytes( int nAdapter ) const +{ +#if defined( _X360 ) + return 256*1024*1024; +#elif defined (DX_TO_GL_ABSTRACTION) + D3DADAPTER_IDENTIFIER9 devIndentifier; + D3D()->GetAdapterIdentifier( nAdapter, D3DENUM_WHQL_LEVEL, &devIndentifier ); + return devIndentifier.VideoMemory; +#else + // FIXME: This currently ignores the adapter + uint64 nBytes = ::GetVidMemBytes(); + if ( nBytes > INT_MAX ) + return INT_MAX; + return nBytes; +#endif +} + + + +//----------------------------------------------------------------------------- +// +// Shader device +// +//----------------------------------------------------------------------------- + +#if 0 +// FIXME: Enable after I've separated it out from shaderapidx8 a little better +static CShaderDeviceDx8 s_ShaderDeviceDX8; +CShaderDeviceDx8* g_pShaderDeviceDx8 = &s_ShaderDeviceDX8; +#endif + + +//----------------------------------------------------------------------------- +// Constructor, destructor +//----------------------------------------------------------------------------- +CShaderDeviceDx8::CShaderDeviceDx8() +{ + g_pD3DDevice = NULL; + for ( int i = 0; i < ARRAYSIZE(m_pFrameSyncQueryObject); i++ ) + { + m_pFrameSyncQueryObject[i] = NULL; + m_bQueryIssued[i] = false; + } + m_pFrameSyncTexture = NULL; + m_bQueuedDeviceLost = false; + m_DeviceState = DEVICE_STATE_OK; + m_bOtherAppInitializing = false; + m_IsResizing = false; + m_bPendingVideoModeChange = false; + m_DeviceSupportsCreateQuery = -1; + m_bUsingStencil = false; + m_bResourcesReleased = false; + m_iStencilBufferBits = 0; + m_NonInteractiveRefresh.m_Mode = MATERIAL_NON_INTERACTIVE_MODE_NONE; + m_NonInteractiveRefresh.m_pVertexShader = NULL; + m_NonInteractiveRefresh.m_pPixelShader = NULL; + m_NonInteractiveRefresh.m_pPixelShaderStartup = NULL; + m_NonInteractiveRefresh.m_pPixelShaderStartupPass2 = NULL; + m_NonInteractiveRefresh.m_pVertexDecl = NULL; + m_NonInteractiveRefresh.m_nPacifierFrame = 0; + m_numReleaseResourcesRefCount = 0; +} + +CShaderDeviceDx8::~CShaderDeviceDx8() +{ +} + + +//----------------------------------------------------------------------------- +// Computes device creation paramters +//----------------------------------------------------------------------------- +static DWORD ComputeDeviceCreationFlags( D3DCAPS& caps, bool bSoftwareVertexProcessing ) +{ + // Find out what type of device to make + bool bPureDeviceSupported = (caps.DevCaps & D3DDEVCAPS_PUREDEVICE) != 0; + + DWORD nDeviceCreationFlags; + if ( !bSoftwareVertexProcessing ) + { + nDeviceCreationFlags = D3DCREATE_HARDWARE_VERTEXPROCESSING; + if ( bPureDeviceSupported ) + { + nDeviceCreationFlags |= D3DCREATE_PUREDEVICE; + } + } + else + { + nDeviceCreationFlags = D3DCREATE_SOFTWARE_VERTEXPROCESSING; + } + nDeviceCreationFlags |= D3DCREATE_FPU_PRESERVE; + +#ifdef _X360 + nDeviceCreationFlags |= D3DCREATE_BUFFER_2_FRAMES; +#endif + + return nDeviceCreationFlags; +} + + +//----------------------------------------------------------------------------- +// Computes the supersample flags +//----------------------------------------------------------------------------- +D3DMULTISAMPLE_TYPE CShaderDeviceDx8::ComputeMultisampleType( int nSampleCount ) +{ + switch (nSampleCount) + { +#if !defined( _X360 ) + case 2: return D3DMULTISAMPLE_2_SAMPLES; + case 3: return D3DMULTISAMPLE_3_SAMPLES; + case 4: return D3DMULTISAMPLE_4_SAMPLES; + case 5: return D3DMULTISAMPLE_5_SAMPLES; + case 6: return D3DMULTISAMPLE_6_SAMPLES; + case 7: return D3DMULTISAMPLE_7_SAMPLES; + case 8: return D3DMULTISAMPLE_8_SAMPLES; + case 9: return D3DMULTISAMPLE_9_SAMPLES; + case 10: return D3DMULTISAMPLE_10_SAMPLES; + case 11: return D3DMULTISAMPLE_11_SAMPLES; + case 12: return D3DMULTISAMPLE_12_SAMPLES; + case 13: return D3DMULTISAMPLE_13_SAMPLES; + case 14: return D3DMULTISAMPLE_14_SAMPLES; + case 15: return D3DMULTISAMPLE_15_SAMPLES; + case 16: return D3DMULTISAMPLE_16_SAMPLES; +#else + case 2: return D3DMULTISAMPLE_2_SAMPLES; + case 4: return D3DMULTISAMPLE_4_SAMPLES; +#endif + default: + case 0: + case 1: + return D3DMULTISAMPLE_NONE; + } +} + + +//----------------------------------------------------------------------------- +// Sets the present parameters +//----------------------------------------------------------------------------- +void CShaderDeviceDx8::SetPresentParameters( void* hWnd, int nAdapter, const ShaderDeviceInfo_t &info ) +{ + ShaderDisplayMode_t mode; + g_pShaderDeviceMgr->GetCurrentModeInfo( &mode, nAdapter ); + + HRESULT hr; + ZeroMemory( &m_PresentParameters, sizeof(m_PresentParameters) ); + + m_PresentParameters.Windowed = info.m_bWindowed; + m_PresentParameters.SwapEffect = info.m_bUsingMultipleWindows ? D3DSWAPEFFECT_COPY : D3DSWAPEFFECT_DISCARD; + + // for 360, we want to create it ourselves for hierarchical z support + m_PresentParameters.EnableAutoDepthStencil = IsX360() ? FALSE : TRUE; + + // What back-buffer format should we use? + ImageFormat backBufferFormat = FindNearestSupportedBackBufferFormat( nAdapter, + DX8_DEVTYPE, m_AdapterFormat, info.m_DisplayMode.m_Format, info.m_bWindowed ); + + // What depth format should we use? + m_bUsingStencil = info.m_bUseStencil; + if ( info.m_nDXLevel >= 80 ) + { + // always stencil for dx9/hdr + m_bUsingStencil = true; + } +#if defined( _X360 ) + D3DFORMAT nDepthFormat = ReverseDepthOnX360() ? D3DFMT_D24FS8 : D3DFMT_D24S8; +#else + D3DFORMAT nDepthFormat = m_bUsingStencil ? D3DFMT_D24S8 : D3DFMT_D24X8; +#endif + m_PresentParameters.AutoDepthStencilFormat = FindNearestSupportedDepthFormat( + nAdapter, m_AdapterFormat, backBufferFormat, nDepthFormat ); + m_PresentParameters.hDeviceWindow = (VD3DHWND)hWnd; + + // store how many stencil buffer bits we have available with the depth/stencil buffer + switch( m_PresentParameters.AutoDepthStencilFormat ) + { + case D3DFMT_D24S8: + m_iStencilBufferBits = 8; + break; +#if defined( _X360 ) + case D3DFMT_D24FS8: + m_iStencilBufferBits = 8; + break; +#else + case D3DFMT_D24X4S4: + m_iStencilBufferBits = 4; + break; + case D3DFMT_D15S1: + m_iStencilBufferBits = 1; + break; +#endif + default: + m_iStencilBufferBits = 0; + m_bUsingStencil = false; //couldn't acquire a stencil buffer + }; + + if ( IsX360() || !info.m_bWindowed ) + { + bool useDefault = ( info.m_DisplayMode.m_nWidth == 0 ) || ( info.m_DisplayMode.m_nHeight == 0 ); + m_PresentParameters.BackBufferCount = 1; + m_PresentParameters.BackBufferWidth = useDefault ? mode.m_nWidth : info.m_DisplayMode.m_nWidth; + m_PresentParameters.BackBufferHeight = useDefault ? mode.m_nHeight : info.m_DisplayMode.m_nHeight; + m_PresentParameters.BackBufferFormat = ImageLoader::ImageFormatToD3DFormat( backBufferFormat ); +#if defined( _X360 ) + m_PresentParameters.FrontBufferFormat = D3DFMT_LE_X8R8G8B8; +#endif + if ( !info.m_bWaitForVSync || CommandLine()->FindParm( "-forcenovsync" ) ) + { + m_PresentParameters.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; + } + else + { + m_PresentParameters.PresentationInterval = D3DPRESENT_INTERVAL_ONE; + } + + m_PresentParameters.FullScreen_RefreshRateInHz = info.m_DisplayMode.m_nRefreshRateDenominator ? + info.m_DisplayMode.m_nRefreshRateNumerator / info.m_DisplayMode.m_nRefreshRateDenominator : D3DPRESENT_RATE_DEFAULT; + +#if defined( _X360 ) + XVIDEO_MODE videoMode; + XGetVideoMode( &videoMode ); + + // want 30 for 60Hz, and 25 for 50Hz (PAL) + int nNewFpsMax = ( ( int )( videoMode.RefreshRate + 0.5f ) ) >> 1; + // slam to either 30 or 25 so that we don't end up with any other cases. + if( nNewFpsMax < 26 ) + { + nNewFpsMax = 25; + } + else + { + nNewFpsMax = 30; + } + DevMsg( "*******Monitor refresh is %f, setting fps_max to %d*********\n", videoMode.RefreshRate, nNewFpsMax ); + ConVarRef fps_max( "fps_max" ); + fps_max.SetValue( nNewFpsMax ); + + // setup hardware scaling - should be native 720p upsampling to 1080i + if ( info.m_bScaleToOutputResolution ) + { + m_PresentParameters.VideoScalerParameters.ScalerSourceRect.x2 = m_PresentParameters.BackBufferWidth; + m_PresentParameters.VideoScalerParameters.ScalerSourceRect.y2 = m_PresentParameters.BackBufferHeight; + m_PresentParameters.VideoScalerParameters.ScaledOutputWidth = videoMode.dwDisplayWidth; + m_PresentParameters.VideoScalerParameters.ScaledOutputHeight = videoMode.dwDisplayHeight; + DevMsg( "VIDEO SCALING: scaling from %dx%d to %dx%d\n", ( int )m_PresentParameters.BackBufferWidth, ( int )m_PresentParameters.BackBufferHeight, + ( int )videoMode.dwDisplayWidth, ( int )videoMode.dwDisplayHeight ); + } + else + { + DevMsg( "VIDEO SCALING: No scaling: %dx%d\n", ( int )m_PresentParameters.BackBufferWidth, ( int )m_PresentParameters.BackBufferHeight ); + } +#endif + } + else + { + // NJS: We are seeing a lot of time spent in present in some cases when this isn't set. + m_PresentParameters.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; + if ( info.m_bResizing ) + { + if ( info.m_bLimitWindowedSize && + ( info.m_nWindowedSizeLimitWidth < mode.m_nWidth || info.m_nWindowedSizeLimitHeight < mode.m_nHeight ) ) + { + // When using material system in windowed resizing apps, it's + // sometimes not a good idea to allocate stuff as big as the screen + // video cards can soo run out of resources + m_PresentParameters.BackBufferWidth = info.m_nWindowedSizeLimitWidth; + m_PresentParameters.BackBufferHeight = info.m_nWindowedSizeLimitHeight; + } + else + { + // When in resizing windowed mode, + // we want to allocate enough memory to deal with any resizing... + m_PresentParameters.BackBufferWidth = mode.m_nWidth; + m_PresentParameters.BackBufferHeight = mode.m_nHeight; + } + } + else + { + m_PresentParameters.BackBufferWidth = info.m_DisplayMode.m_nWidth; + m_PresentParameters.BackBufferHeight = info.m_DisplayMode.m_nHeight; + } + m_PresentParameters.BackBufferFormat = ImageLoader::ImageFormatToD3DFormat( backBufferFormat ); + m_PresentParameters.BackBufferCount = 1; + } + + if ( info.m_nAASamples > 0 && ( m_PresentParameters.SwapEffect == D3DSWAPEFFECT_DISCARD ) ) + { + D3DMULTISAMPLE_TYPE multiSampleType = ComputeMultisampleType( info.m_nAASamples ); + DWORD nQualityLevel; + + // FIXME: Should we add the quality level to the ShaderAdapterMode_t struct? + // 16x on nVidia refers to CSAA or "Coverage Sampled Antialiasing" + const HardwareCaps_t &adapterCaps = g_ShaderDeviceMgrDx8.GetHardwareCaps( nAdapter ); + if ( ( info.m_nAASamples == 16 ) && ( adapterCaps.m_VendorID == VENDORID_NVIDIA ) ) + { + multiSampleType = ComputeMultisampleType(4); + hr = D3D()->CheckDeviceMultiSampleType( nAdapter, DX8_DEVTYPE, + m_PresentParameters.BackBufferFormat, m_PresentParameters.Windowed, + multiSampleType, &nQualityLevel ); // 4x at highest quality level + + if ( !FAILED( hr ) && ( nQualityLevel == 16 ) ) + { + nQualityLevel = nQualityLevel - 1; // Highest quality level triggers 16x CSAA + } + else + { + nQualityLevel = 0; // No CSAA + } + } + else // Regular MSAA on any old vendor + { + hr = D3D()->CheckDeviceMultiSampleType( nAdapter, DX8_DEVTYPE, + m_PresentParameters.BackBufferFormat, m_PresentParameters.Windowed, + multiSampleType, &nQualityLevel ); + + nQualityLevel = 0; + } + + if ( !FAILED( hr ) ) + { + m_PresentParameters.MultiSampleType = multiSampleType; + m_PresentParameters.MultiSampleQuality = nQualityLevel; + } + } + else + { + m_PresentParameters.MultiSampleType = D3DMULTISAMPLE_NONE; + m_PresentParameters.MultiSampleQuality = 0; + } +} + + +//----------------------------------------------------------------------------- +// Initializes, shuts down the D3D device +//----------------------------------------------------------------------------- +bool CShaderDeviceDx8::InitDevice( void* hwnd, int nAdapter, const ShaderDeviceInfo_t &info ) +{ + //Debugger(); + + // good place to run some self tests. + //#if OSX + //{ + // extern void GLMgrSelfTests( void ); + // GLMgrSelfTests(); + //} + //#endif + + // windowed + if ( !CreateD3DDevice( (VD3DHWND)hwnd, nAdapter, info ) ) + return false; + + // Hook up our own windows proc to get at messages to tell us when + // other instances of the material system are trying to set the mode + InstallWindowHook( (VD3DHWND)m_hWnd ); + return true; +} + +void CShaderDeviceDx8::ShutdownDevice() +{ + if ( IsPC() && IsActive() ) + { + Dx9Device()->Release(); + +#ifdef STUBD3D + delete ( CStubD3DDevice * )Dx9Device(); +#endif + + g_pD3DDevice = NULL; + + RemoveWindowHook( (VD3DHWND)m_hWnd ); + m_hWnd = 0; + } +} + + +//----------------------------------------------------------------------------- +// Are we using graphics? +//----------------------------------------------------------------------------- +bool CShaderDeviceDx8::IsUsingGraphics() const +{ + //*****LOCK_SHADERAPI(); + return IsActive(); +} + + +//----------------------------------------------------------------------------- +// Returns the current adapter in use +//----------------------------------------------------------------------------- +int CShaderDeviceDx8::GetCurrentAdapter() const +{ + LOCK_SHADERAPI(); + return m_DisplayAdapter; +} + + +//----------------------------------------------------------------------------- +// Returns the current adapter in use +//----------------------------------------------------------------------------- +char *CShaderDeviceDx8::GetDisplayDeviceName() +{ + if( m_sDisplayDeviceName.IsEmpty() ) + { + D3DADAPTER_IDENTIFIER9 ident; + // On Win10, this function is getting called with m_nAdapter still initialized to -1. + // It's failing, and m_sDisplayDeviceName has garbage, and tf2 fails to launch. + // To repro this, run "hl2.exe -dev -fullscreen -game tf" on Win10. + HRESULT hr = D3D()->GetAdapterIdentifier( Max( m_nAdapter, 0 ), 0, &ident ); + if ( FAILED(hr) ) + { + Assert( false ); + ident.DeviceName[0] = 0; + } + m_sDisplayDeviceName = ident.DeviceName; + } + return m_sDisplayDeviceName.GetForModify(); +} + + +//----------------------------------------------------------------------------- +// Use this to spew information about the 3D layer +//----------------------------------------------------------------------------- +void CShaderDeviceDx8::SpewDriverInfo() const +{ + LOCK_SHADERAPI(); + HRESULT hr; + D3DCAPS caps; + D3DADAPTER_IDENTIFIER9 ident; + + RECORD_COMMAND( DX8_GET_DEVICE_CAPS, 0 ); + + RECORD_COMMAND( DX8_GET_ADAPTER_IDENTIFIER, 2 ); + RECORD_INT( m_nAdapter ); + RECORD_INT( 0 ); + + Dx9Device()->GetDeviceCaps( &caps ); + hr = D3D()->GetAdapterIdentifier( m_nAdapter, D3DENUM_WHQL_LEVEL, &ident ); + + Warning("Shader API Driver Info:\n\nDriver : %s Version : %lld\n", + ident.Driver, ident.DriverVersion.QuadPart ); + Warning("Driver Description : %s\n", ident.Description ); + Warning("Chipset version %d %d %d %d\n\n", + ident.VendorId, ident.DeviceId, ident.SubSysId, ident.Revision ); + + ShaderDisplayMode_t mode; + g_pShaderDeviceMgr->GetCurrentModeInfo( &mode, m_nAdapter ); + Warning("Display mode : %d x %d (%s)\n", + mode.m_nWidth, mode.m_nHeight, ImageLoader::GetName( mode.m_Format ) ); + Warning("Vertex Shader Version : %d.%d Pixel Shader Version : %d.%d\n", + (caps.VertexShaderVersion >> 8) & 0xFF, caps.VertexShaderVersion & 0xFF, + (caps.PixelShaderVersion >> 8) & 0xFF, caps.PixelShaderVersion & 0xFF); + Warning("\nDevice Caps :\n"); + Warning("CANBLTSYSTONONLOCAL %s CANRENDERAFTERFLIP %s HWRASTERIZATION %s\n", + (caps.DevCaps & D3DDEVCAPS_CANBLTSYSTONONLOCAL) ? " Y " : " N ", + (caps.DevCaps & D3DDEVCAPS_CANRENDERAFTERFLIP) ? " Y " : " N ", + (caps.DevCaps & D3DDEVCAPS_HWRASTERIZATION) ? " Y " : "*N*" ); + Warning("HWTRANSFORMANDLIGHT %s NPATCHES %s PUREDEVICE %s\n", + (caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) ? " Y " : " N ", + (caps.DevCaps & D3DDEVCAPS_NPATCHES) ? " Y " : " N ", + (caps.DevCaps & D3DDEVCAPS_PUREDEVICE) ? " Y " : " N " ); + Warning("SEPARATETEXTUREMEMORIES %s TEXTURENONLOCALVIDMEM %s TEXTURESYSTEMMEMORY %s\n", + (caps.DevCaps & D3DDEVCAPS_SEPARATETEXTUREMEMORIES) ? "*Y*" : " N ", + (caps.DevCaps & D3DDEVCAPS_TEXTURENONLOCALVIDMEM) ? " Y " : " N ", + (caps.DevCaps & D3DDEVCAPS_TEXTURESYSTEMMEMORY) ? " Y " : " N " ); + Warning("TEXTUREVIDEOMEMORY %s TLVERTEXSYSTEMMEMORY %s TLVERTEXVIDEOMEMORY %s\n", + (caps.DevCaps & D3DDEVCAPS_TEXTUREVIDEOMEMORY) ? " Y " : "*N*", + (caps.DevCaps & D3DDEVCAPS_TLVERTEXSYSTEMMEMORY) ? " Y " : "*N*", + (caps.DevCaps & D3DDEVCAPS_TLVERTEXVIDEOMEMORY) ? " Y " : " N " ); + + Warning("\nPrimitive Caps :\n"); + Warning("BLENDOP %s CLIPPLANESCALEDPOINTS %s CLIPTLVERTS %s\n", + (caps.PrimitiveMiscCaps & D3DPMISCCAPS_BLENDOP) ? " Y " : " N ", + (caps.PrimitiveMiscCaps & D3DPMISCCAPS_CLIPPLANESCALEDPOINTS) ? " Y " : " N ", + (caps.PrimitiveMiscCaps & D3DPMISCCAPS_CLIPTLVERTS) ? " Y " : " N " ); + Warning("COLORWRITEENABLE %s MASKZ %s TSSARGTEMP %s\n", + (caps.PrimitiveMiscCaps & D3DPMISCCAPS_COLORWRITEENABLE) ? " Y " : " N ", + (caps.PrimitiveMiscCaps & D3DPMISCCAPS_MASKZ) ? " Y " : "*N*", + (caps.PrimitiveMiscCaps & D3DPMISCCAPS_TSSARGTEMP) ? " Y " : " N " ); + + Warning("\nRaster Caps :\n"); + Warning("FOGRANGE %s FOGTABLE %s FOGVERTEX %s ZFOG %s WFOG %s\n", + (caps.RasterCaps & D3DPRASTERCAPS_FOGRANGE) ? " Y " : " N ", + (caps.RasterCaps & D3DPRASTERCAPS_FOGTABLE) ? " Y " : " N ", + (caps.RasterCaps & D3DPRASTERCAPS_FOGVERTEX) ? " Y " : " N ", + (caps.RasterCaps & D3DPRASTERCAPS_ZFOG) ? " Y " : " N ", + (caps.RasterCaps & D3DPRASTERCAPS_WFOG) ? " Y " : " N " ); + Warning("MIPMAPLODBIAS %s WBUFFER %s ZBIAS %s ZTEST %s\n", + (caps.RasterCaps & D3DPRASTERCAPS_MIPMAPLODBIAS) ? " Y " : " N ", + (caps.RasterCaps & D3DPRASTERCAPS_WBUFFER) ? " Y " : " N ", + (caps.RasterCaps & D3DPRASTERCAPS_DEPTHBIAS) ? " Y " : " N ", + (caps.RasterCaps & D3DPRASTERCAPS_ZTEST) ? " Y " : "*N*" ); + + Warning("Size of Texture Memory : %d kb\n", g_pHardwareConfig->Caps().m_TextureMemorySize / 1024 ); + Warning("Max Texture Dimensions : %d x %d\n", + caps.MaxTextureWidth, caps.MaxTextureHeight ); + if (caps.MaxTextureAspectRatio != 0) + Warning("Max Texture Aspect Ratio : *%d*\n", caps.MaxTextureAspectRatio ); + Warning("Max Textures : %d Max Stages : %d\n", + caps.MaxSimultaneousTextures, caps.MaxTextureBlendStages ); + + Warning("\nTexture Caps :\n"); + Warning("ALPHA %s CUBEMAP %s MIPCUBEMAP %s SQUAREONLY %s\n", + (caps.TextureCaps & D3DPTEXTURECAPS_ALPHA) ? " Y " : " N ", + (caps.TextureCaps & D3DPTEXTURECAPS_CUBEMAP) ? " Y " : " N ", + (caps.TextureCaps & D3DPTEXTURECAPS_MIPCUBEMAP) ? " Y " : " N ", + (caps.TextureCaps & D3DPTEXTURECAPS_SQUAREONLY) ? "*Y*" : " N " ); + + Warning( "vendor id: 0x%x\n", g_pHardwareConfig->ActualCaps().m_VendorID ); + Warning( "device id: 0x%x\n", g_pHardwareConfig->ActualCaps().m_DeviceID ); + + Warning( "SHADERAPI CAPS:\n" ); + Warning( "m_NumSamplers: %d\n", g_pHardwareConfig->Caps().m_NumSamplers ); + Warning( "m_NumTextureStages: %d\n", g_pHardwareConfig->Caps().m_NumTextureStages ); + Warning( "m_HasSetDeviceGammaRamp: %s\n", g_pHardwareConfig->Caps().m_HasSetDeviceGammaRamp ? "yes" : "no" ); + Warning( "m_SupportsVertexShaders (1.1): %s\n", g_pHardwareConfig->Caps().m_SupportsVertexShaders ? "yes" : "no" ); + Warning( "m_SupportsVertexShaders_2_0: %s\n", g_pHardwareConfig->Caps().m_SupportsVertexShaders_2_0 ? "yes" : "no" ); + Warning( "m_SupportsPixelShaders (1.1): %s\n", g_pHardwareConfig->Caps().m_SupportsPixelShaders ? "yes" : "no" ); + Warning( "m_SupportsPixelShaders_1_4: %s\n", g_pHardwareConfig->Caps().m_SupportsPixelShaders_1_4 ? "yes" : "no" ); + Warning( "m_SupportsPixelShaders_2_0: %s\n", g_pHardwareConfig->Caps().m_SupportsPixelShaders_2_0 ? "yes" : "no" ); + Warning( "m_SupportsPixelShaders_2_b: %s\n", g_pHardwareConfig->Caps().m_SupportsPixelShaders_2_b ? "yes" : "no" ); + Warning( "m_SupportsShaderModel_3_0: %s\n", g_pHardwareConfig->Caps().m_SupportsShaderModel_3_0 ? "yes" : "no" ); + + switch( g_pHardwareConfig->Caps().m_SupportsCompressedTextures ) + { + case COMPRESSED_TEXTURES_ON: + Warning( "m_SupportsCompressedTextures: COMPRESSED_TEXTURES_ON\n" ); + break; + case COMPRESSED_TEXTURES_OFF: + Warning( "m_SupportsCompressedTextures: COMPRESSED_TEXTURES_ON\n" ); + break; + case COMPRESSED_TEXTURES_NOT_INITIALIZED: + Warning( "m_SupportsCompressedTextures: COMPRESSED_TEXTURES_NOT_INITIALIZED\n" ); + break; + default: + Assert( 0 ); + break; + } + Warning( "m_SupportsCompressedVertices: %d\n", g_pHardwareConfig->Caps().m_SupportsCompressedVertices ); + Warning( "m_bSupportsAnisotropicFiltering: %s\n", g_pHardwareConfig->Caps().m_bSupportsAnisotropicFiltering ? "yes" : "no" ); + Warning( "m_nMaxAnisotropy: %d\n", g_pHardwareConfig->Caps().m_nMaxAnisotropy ); + Warning( "m_MaxTextureWidth: %d\n", g_pHardwareConfig->Caps().m_MaxTextureWidth ); + Warning( "m_MaxTextureHeight: %d\n", g_pHardwareConfig->Caps().m_MaxTextureHeight ); + Warning( "m_MaxTextureAspectRatio: %d\n", g_pHardwareConfig->Caps().m_MaxTextureAspectRatio ); + Warning( "m_MaxPrimitiveCount: %d\n", g_pHardwareConfig->Caps().m_MaxPrimitiveCount ); + Warning( "m_ZBiasAndSlopeScaledDepthBiasSupported: %s\n", g_pHardwareConfig->Caps().m_ZBiasAndSlopeScaledDepthBiasSupported ? "yes" : "no" ); + Warning( "m_SupportsMipmapping: %s\n", g_pHardwareConfig->Caps().m_SupportsMipmapping ? "yes" : "no" ); + Warning( "m_SupportsOverbright: %s\n", g_pHardwareConfig->Caps().m_SupportsOverbright ? "yes" : "no" ); + Warning( "m_SupportsCubeMaps: %s\n", g_pHardwareConfig->Caps().m_SupportsCubeMaps ? "yes" : "no" ); + Warning( "m_NumPixelShaderConstants: %d\n", g_pHardwareConfig->Caps().m_NumPixelShaderConstants ); + Warning( "m_NumVertexShaderConstants: %d\n", g_pHardwareConfig->Caps().m_NumVertexShaderConstants ); + Warning( "m_NumBooleanVertexShaderConstants: %d\n", g_pHardwareConfig->Caps().m_NumBooleanVertexShaderConstants ); + Warning( "m_NumIntegerVertexShaderConstants: %d\n", g_pHardwareConfig->Caps().m_NumIntegerVertexShaderConstants ); + Warning( "m_TextureMemorySize: %d\n", g_pHardwareConfig->Caps().m_TextureMemorySize ); + Warning( "m_MaxNumLights: %d\n", g_pHardwareConfig->Caps().m_MaxNumLights ); + Warning( "m_SupportsHardwareLighting: %s\n", g_pHardwareConfig->Caps().m_SupportsHardwareLighting ? "yes" : "no" ); + Warning( "m_MaxBlendMatrices: %d\n", g_pHardwareConfig->Caps().m_MaxBlendMatrices ); + Warning( "m_MaxBlendMatrixIndices: %d\n", g_pHardwareConfig->Caps().m_MaxBlendMatrixIndices ); + Warning( "m_MaxVertexShaderBlendMatrices: %d\n", g_pHardwareConfig->Caps().m_MaxVertexShaderBlendMatrices ); + Warning( "m_SupportsMipmappedCubemaps: %s\n", g_pHardwareConfig->Caps().m_SupportsMipmappedCubemaps ? "yes" : "no" ); + Warning( "m_SupportsNonPow2Textures: %s\n", g_pHardwareConfig->Caps().m_SupportsNonPow2Textures ? "yes" : "no" ); + Warning( "m_nDXSupportLevel: %d\n", g_pHardwareConfig->Caps().m_nDXSupportLevel ); + Warning( "m_PreferDynamicTextures: %s\n", g_pHardwareConfig->Caps().m_PreferDynamicTextures ? "yes" : "no" ); + Warning( "m_HasProjectedBumpEnv: %s\n", g_pHardwareConfig->Caps().m_HasProjectedBumpEnv ? "yes" : "no" ); + Warning( "m_MaxUserClipPlanes: %d\n", g_pHardwareConfig->Caps().m_MaxUserClipPlanes ); + Warning( "m_SupportsSRGB: %s\n", g_pHardwareConfig->Caps().m_SupportsSRGB ? "yes" : "no" ); + switch( g_pHardwareConfig->Caps().m_HDRType ) + { + case HDR_TYPE_NONE: + Warning( "m_HDRType: HDR_TYPE_NONE\n" ); + break; + case HDR_TYPE_INTEGER: + Warning( "m_HDRType: HDR_TYPE_INTEGER\n" ); + break; + case HDR_TYPE_FLOAT: + Warning( "m_HDRType: HDR_TYPE_FLOAT\n" ); + break; + default: + Assert( 0 ); + break; + } + Warning( "m_bSupportsSpheremapping: %s\n", g_pHardwareConfig->Caps().m_bSupportsSpheremapping ? "yes" : "no" ); + Warning( "m_UseFastClipping: %s\n", g_pHardwareConfig->Caps().m_UseFastClipping ? "yes" : "no" ); + Warning( "m_pShaderDLL: %s\n", g_pHardwareConfig->Caps().m_pShaderDLL ); + Warning( "m_bNeedsATICentroidHack: %s\n", g_pHardwareConfig->Caps().m_bNeedsATICentroidHack ? "yes" : "no" ); + Warning( "m_bDisableShaderOptimizations: %s\n", g_pHardwareConfig->Caps().m_bDisableShaderOptimizations ? "yes" : "no" ); + Warning( "m_bColorOnSecondStream: %s\n", g_pHardwareConfig->Caps().m_bColorOnSecondStream ? "yes" : "no" ); + Warning( "m_MaxSimultaneousRenderTargets: %d\n", g_pHardwareConfig->Caps().m_MaxSimultaneousRenderTargets ); +} + + +//----------------------------------------------------------------------------- +// Back buffer information +//----------------------------------------------------------------------------- +ImageFormat CShaderDeviceDx8::GetBackBufferFormat() const +{ + return ImageLoader::D3DFormatToImageFormat( m_PresentParameters.BackBufferFormat ); +} + +void CShaderDeviceDx8::GetBackBufferDimensions( int& width, int& height ) const +{ + width = m_PresentParameters.BackBufferWidth; + height = m_PresentParameters.BackBufferHeight; +} + + +//----------------------------------------------------------------------------- +// Detects support for CreateQuery +//----------------------------------------------------------------------------- +void CShaderDeviceDx8::DetectQuerySupport( IDirect3DDevice9 *pD3DDevice ) +{ + // Do I need to detect whether this device supports CreateQuery before creating it? + if ( m_DeviceSupportsCreateQuery != -1 ) + return; + + IDirect3DQuery9 *pQueryObject = NULL; + + // Detect whether query is supported by creating and releasing: + HRESULT hr = pD3DDevice->CreateQuery( D3DQUERYTYPE_EVENT, &pQueryObject ); + if ( !FAILED(hr) && pQueryObject ) + { + pQueryObject->Release(); + m_DeviceSupportsCreateQuery = 1; + } + else + { + m_DeviceSupportsCreateQuery = 0; + } +} + + +const char *GetD3DErrorText( HRESULT hr ) +{ + const char *pszMoreInfo = NULL; + +#if defined( _WIN32 ) && !defined(DX_TO_GL_ABSTRACTION) + switch ( hr ) + { + case D3DERR_WRONGTEXTUREFORMAT: + pszMoreInfo = "D3DERR_WRONGTEXTUREFORMAT: The pixel format of the texture surface is not valid."; + break; + case D3DERR_UNSUPPORTEDCOLOROPERATION: + pszMoreInfo = "D3DERR_UNSUPPORTEDCOLOROPERATION: The device does not support a specified texture-blending operation for color values."; + break; + case D3DERR_UNSUPPORTEDCOLORARG: + pszMoreInfo = "D3DERR_UNSUPPORTEDCOLORARG: The device does not support a specified texture-blending argument for color values."; + break; + case D3DERR_UNSUPPORTEDALPHAOPERATION: + pszMoreInfo = "D3DERR_UNSUPPORTEDALPHAOPERATION: The device does not support a specified texture-blending operation for the alpha channel."; + break; + case D3DERR_UNSUPPORTEDALPHAARG: + pszMoreInfo = "D3DERR_UNSUPPORTEDALPHAARG: The device does not support a specified texture-blending argument for the alpha channel."; + break; + case D3DERR_TOOMANYOPERATIONS: + pszMoreInfo = "D3DERR_TOOMANYOPERATIONS: The application is requesting more texture-filtering operations than the device supports."; + break; + case D3DERR_CONFLICTINGTEXTUREFILTER: + pszMoreInfo = "D3DERR_CONFLICTINGTEXTUREFILTER: The current texture filters cannot be used together."; + break; + case D3DERR_UNSUPPORTEDFACTORVALUE: + pszMoreInfo = "D3DERR_UNSUPPORTEDFACTORVALUE: The device does not support the specified texture factor value."; + break; + case D3DERR_CONFLICTINGRENDERSTATE: + pszMoreInfo = "D3DERR_CONFLICTINGRENDERSTATE: The currently set render states cannot be used together."; + break; + case D3DERR_UNSUPPORTEDTEXTUREFILTER: + pszMoreInfo = "D3DERR_UNSUPPORTEDTEXTUREFILTER: The device does not support the specified texture filter."; + break; + case D3DERR_CONFLICTINGTEXTUREPALETTE: + pszMoreInfo = "D3DERR_CONFLICTINGTEXTUREPALETTE: The current textures cannot be used simultaneously."; + break; + case D3DERR_DRIVERINTERNALERROR: + pszMoreInfo = "D3DERR_DRIVERINTERNALERROR: Internal driver error."; + break; + case D3DERR_NOTFOUND: + pszMoreInfo = "D3DERR_NOTFOUND: The requested item was not found."; + break; + case D3DERR_DEVICELOST: + pszMoreInfo = "D3DERR_DEVICELOST: The device has been lost but cannot be reset at this time. Therefore, rendering is not possible."; + break; + case D3DERR_DEVICENOTRESET: + pszMoreInfo = "D3DERR_DEVICENOTRESET: The device has been lost."; + break; + case D3DERR_NOTAVAILABLE: + pszMoreInfo = "D3DERR_NOTAVAILABLE: This device does not support the queried technique."; + break; + case D3DERR_OUTOFVIDEOMEMORY: + pszMoreInfo = "D3DERR_OUTOFVIDEOMEMORY: Direct3D does not have enough display memory to perform the operation. The device is using more resources in a single scene than can fit simultaneously into video memory."; + break; + case D3DERR_INVALIDDEVICE: + pszMoreInfo = "D3DERR_INVALIDDEVICE: The requested device type is not valid."; + break; + case D3DERR_INVALIDCALL: + pszMoreInfo = "D3DERR_INVALIDCALL: The method call is invalid."; + break; + case D3DERR_DRIVERINVALIDCALL: + pszMoreInfo = "D3DERR_DRIVERINVALIDCALL"; + break; + case D3DERR_WASSTILLDRAWING: + pszMoreInfo = "D3DERR_WASSTILLDRAWING: The previous blit operation that is transferring information to or from this surface is incomplete."; + break; + } +#endif // _WIN32 + + return pszMoreInfo; +} + + +//----------------------------------------------------------------------------- +// Actually creates the D3D Device once the present parameters are set up +//----------------------------------------------------------------------------- +IDirect3DDevice9* CShaderDeviceDx8::InvokeCreateDevice( void* hWnd, int nAdapter, DWORD deviceCreationFlags ) +{ + IDirect3DDevice9 *pD3DDevice = NULL; + D3DDEVTYPE devType = DX8_DEVTYPE; + +#if NVPERFHUD + nAdapter = D3D()->GetAdapterCount()-1; + devType = D3DDEVTYPE_REF; + deviceCreationFlags = D3DCREATE_FPU_PRESERVE | D3DCREATE_HARDWARE_VERTEXPROCESSING; +#endif + +#if 1 // with the changes for opengl to enable threading, we no longer need the d3d device to have threading guards +#ifndef _X360 + // Create the device with multi-threaded safeguards if we're using mat_queue_mode 2. + // The logic to enable multithreaded rendering happens well after the device has been created, + // so we replicate some of that logic here. + ConVarRef mat_queue_mode( "mat_queue_mode" ); + if ( mat_queue_mode.GetInt() == 2 || + ( mat_queue_mode.GetInt() == -2 && GetCPUInformation()->m_nPhysicalProcessors >= 2 ) || + ( mat_queue_mode.GetInt() == -1 && GetCPUInformation()->m_nPhysicalProcessors >= 2 ) ) + { + deviceCreationFlags |= D3DCREATE_MULTITHREADED; + } +#endif +#endif + +#ifdef ENABLE_NULLREF_DEVICE_SUPPORT + devType = CommandLine()->FindParm( "-nulldevice" ) ? D3DDEVTYPE_NULLREF: devType; +#endif + + HRESULT hr = D3D()->CreateDevice( nAdapter, devType, + (VD3DHWND)hWnd, deviceCreationFlags, &m_PresentParameters, &pD3DDevice ); + + if ( !FAILED( hr ) && pD3DDevice ) + return pD3DDevice; + + if ( !IsPC() ) + return NULL; + + // try again, other applications may be taking their time + Sleep( 1000 ); + hr = D3D()->CreateDevice( nAdapter, devType, + (VD3DHWND)hWnd, deviceCreationFlags, &m_PresentParameters, &pD3DDevice ); + if ( !FAILED( hr ) && pD3DDevice ) + return pD3DDevice; + + // in this case, we actually are allocating too much memory.... + // This will cause us to use less buffers... + if ( m_PresentParameters.Windowed ) + { + m_PresentParameters.SwapEffect = D3DSWAPEFFECT_COPY; + m_PresentParameters.BackBufferCount = 0; + hr = D3D()->CreateDevice( nAdapter, devType, + (VD3DHWND)hWnd, deviceCreationFlags, &m_PresentParameters, &pD3DDevice ); + } + if ( !FAILED( hr ) && pD3DDevice ) + return pD3DDevice; + + const char *pszMoreInfo = NULL; + switch ( hr ) + { +#ifdef _WIN32 + case D3DERR_INVALIDCALL: + // Override the error text for this error since it has a known meaning for CreateDevice failures. + pszMoreInfo = "D3DERR_INVALIDCALL: The device or the device driver may not support Direct3D or may not support the resolution or color depth specified."; + break; +#endif // _WIN32 + default: + pszMoreInfo = GetD3DErrorText( hr ); + break; + } + + // Otherwise we failed, show a message and shutdown + if ( pszMoreInfo ) + { + DWarning( "init", 0, "Failed to create %s device!\nError 0x%lX: %s\n\nPlease see the following for more info.\n" + "http://support.steampowered.com/cgi-bin/steampowered.cfg/php/enduser/std_adp.php?p_faqid=772\n", IsOpenGL() ? "OpenGL" : "D3D", hr, pszMoreInfo ); + } + else + { + DWarning( "init", 0, "Failed to create %s device!\nError 0x%lX.\n\nPlease see the following for more info.\n" + "http://support.steampowered.com/cgi-bin/steampowered.cfg/php/enduser/std_adp.php?p_faqid=772\n", IsOpenGL() ? "OpenGL" : "D3D", hr ); + } + + return NULL; +} + + +//----------------------------------------------------------------------------- +// Creates the D3D Device +//----------------------------------------------------------------------------- +bool CShaderDeviceDx8::CreateD3DDevice( void* pHWnd, int nAdapter, const ShaderDeviceInfo_t &info ) +{ + Assert( info.m_nVersion == SHADER_DEVICE_INFO_VERSION ); + + MEM_ALLOC_CREDIT_( __FILE__ ": D3D Device" ); + + VD3DHWND hWnd = (VD3DHWND)pHWnd; + +#if ( !defined( PIX_INSTRUMENTATION ) && !defined( _X360 ) && !defined( NVPERFHUD ) ) + D3DPERF_SetOptions(1); // Explicitly disallow PIX instrumented profiling in external builds +#endif + + // Get some caps.... + D3DCAPS caps; + HRESULT hr = D3D()->GetDeviceCaps( nAdapter, DX8_DEVTYPE, &caps ); + if ( FAILED( hr ) ) + return false; + + // Determine the adapter format + ShaderDisplayMode_t mode; + g_pShaderDeviceMgrDx8->GetCurrentModeInfo( &mode, nAdapter ); + m_AdapterFormat = mode.m_Format; + + // FIXME: Need to do this prior to SetPresentParameters. Fix. + // Make it part of HardwareCaps_t + InitializeColorInformation( nAdapter, DX8_DEVTYPE, m_AdapterFormat ); + + const HardwareCaps_t &adapterCaps = g_ShaderDeviceMgrDx8.GetHardwareCaps( nAdapter ); + DWORD deviceCreationFlags = ComputeDeviceCreationFlags( caps, adapterCaps.m_bSoftwareVertexProcessing ); + SetPresentParameters( hWnd, nAdapter, info ); + + // Tell all other instances of the material system to let go of memory + SendIPCMessage( RELEASE_MESSAGE ); + + // Creates the device + IDirect3DDevice9 *pD3DDevice = InvokeCreateDevice( pHWnd, nAdapter, deviceCreationFlags ); + + if ( !pD3DDevice ) + return false; + + // Check to see if query is supported + DetectQuerySupport( pD3DDevice ); + +#ifdef STUBD3D + Dx9Device() = new CStubD3DDevice( pD3DDevice, g_pFullFileSystem ); +#else + g_pD3DDevice = pD3DDevice; +#endif + +#if defined( _X360 ) + // Create the depth buffer, created manually to enable hierarchical z + { + D3DSURFACE_PARAMETERS DepthStencilParams; + + // Depth is immediately after the back buffer in EDRAM + // allocate the hierarchical z tiles at the end of the area so all other allocations can trivially allocate at 0 + DepthStencilParams.Base = XGSurfaceSize( + m_PresentParameters.BackBufferWidth, + m_PresentParameters.BackBufferHeight, + m_PresentParameters.BackBufferFormat, + m_PresentParameters.MultiSampleType ); + DepthStencilParams.ColorExpBias = 0; + DepthStencilParams.HierarchicalZBase = GPU_HIERARCHICAL_Z_TILES - XGHierarchicalZSize( m_PresentParameters.BackBufferWidth, m_PresentParameters.BackBufferHeight, m_PresentParameters.MultiSampleType ); + + IDirect3DSurface *pDepthStencilSurface = NULL; + hr = Dx9Device()->CreateDepthStencilSurface( + m_PresentParameters.BackBufferWidth, + m_PresentParameters.BackBufferHeight, + m_PresentParameters.AutoDepthStencilFormat, + m_PresentParameters.MultiSampleType, + m_PresentParameters.MultiSampleQuality, + TRUE, + &pDepthStencilSurface, + &DepthStencilParams ); + Assert( SUCCEEDED( hr ) ); + if ( FAILED( hr ) ) + return false; + + hr = Dx9Device()->SetDepthStencilSurface( pDepthStencilSurface ); + Assert( SUCCEEDED( hr ) ); + if ( FAILED( hr ) ) + return false; + } + + // Initialize XUI, needed for TTF font rasterization + // xui requires and shares our d3d device + { + hr = XuiRenderInitShared( pD3DDevice, &m_PresentParameters, XuiD3DXTextureLoader ); + if ( FAILED( hr ) ) + return false; + + XUIInitParams xuiInit; + XUI_INIT_PARAMS( xuiInit ); + xuiInit.dwFlags = XUI_INIT_PARAMS_FLAGS_NONE; + xuiInit.pHooks = NULL; + hr = XuiInit( &xuiInit ); + if ( FAILED( hr ) ) + return false; + + hr = XuiRenderCreateDC( &m_hDC ); + if ( FAILED( hr ) ) + return false; + } +#endif + + // CheckDeviceLost(); + + // Tell all other instances of the material system it's ok to grab memory + SendIPCMessage( REACQUIRE_MESSAGE ); + + m_hWnd = pHWnd; + m_nAdapter = m_DisplayAdapter = nAdapter; + m_DeviceState = DEVICE_STATE_OK; + m_bIsMinimized = false; + m_bQueuedDeviceLost = false; + + m_IsResizing = info.m_bWindowed && info.m_bResizing; + + // This is our current view. + m_ViewHWnd = hWnd; + GetWindowSize( m_nWindowWidth, m_nWindowHeight ); + + g_pHardwareConfig->SetupHardwareCaps( info, g_ShaderDeviceMgrDx8.GetHardwareCaps( nAdapter ) ); + + // FIXME: Bake this into hardware config + // What texture formats do we support? + if ( D3DSupportsCompressedTextures() ) + { + g_pHardwareConfig->ActualCapsForEdit().m_SupportsCompressedTextures = COMPRESSED_TEXTURES_ON; + g_pHardwareConfig->CapsForEdit().m_SupportsCompressedTextures = COMPRESSED_TEXTURES_ON; + } + else + { + g_pHardwareConfig->ActualCapsForEdit().m_SupportsCompressedTextures = COMPRESSED_TEXTURES_OFF; + g_pHardwareConfig->CapsForEdit().m_SupportsCompressedTextures = COMPRESSED_TEXTURES_OFF; + } + + return ( !FAILED( hr ) ); +} + + +//----------------------------------------------------------------------------- +// Frame sync +//----------------------------------------------------------------------------- +void CShaderDeviceDx8::AllocFrameSyncTextureObject() +{ + if ( IsX360() ) + return; + + FreeFrameSyncTextureObject(); + + // Create a tiny managed texture. + HRESULT hr = Dx9Device()->CreateTexture( + 1, 1, // width, height + 0, // levels + D3DUSAGE_DYNAMIC, // usage + D3DFMT_A8R8G8B8, // format + D3DPOOL_DEFAULT, + &m_pFrameSyncTexture, + NULL ); + if ( FAILED( hr ) ) + { + m_pFrameSyncTexture = NULL; + } +} + +void CShaderDeviceDx8::FreeFrameSyncTextureObject() +{ + if ( IsX360() ) + return; + + if ( m_pFrameSyncTexture ) + { + m_pFrameSyncTexture->Release(); + m_pFrameSyncTexture = NULL; + } +} + +void CShaderDeviceDx8::AllocFrameSyncObjects( void ) +{ + if ( IsX360() ) + return; + + if ( mat_debugalttab.GetBool() ) + { + Warning( "mat_debugalttab: CShaderAPIDX8::AllocFrameSyncObjects\n" ); + } + + // Allocate the texture for frame syncing in case we force that to be on. + AllocFrameSyncTextureObject(); + + if ( m_DeviceSupportsCreateQuery == 0 ) + { + for ( int i = 0; i < ARRAYSIZE(m_pFrameSyncQueryObject); i++ ) + { + m_pFrameSyncQueryObject[i] = NULL; + m_bQueryIssued[i] = false; + } + return; + } + + // FIXME FIXME FIXME!!!!! Need to record this. + for ( int i = 0; i < ARRAYSIZE(m_pFrameSyncQueryObject); i++ ) + { + HRESULT hr = Dx9Device()->CreateQuery( D3DQUERYTYPE_EVENT, &m_pFrameSyncQueryObject[i] ); + if( hr == D3DERR_NOTAVAILABLE ) + { + Warning( "D3DQUERYTYPE_EVENT not available on this driver\n" ); + Assert( m_pFrameSyncQueryObject[i] == NULL ); + } + else + { + Assert( hr == D3D_OK ); + Assert( m_pFrameSyncQueryObject[i] ); + m_pFrameSyncQueryObject[i]->Issue( D3DISSUE_END ); + m_bQueryIssued[i] = true; + } + } +} + +void CShaderDeviceDx8::FreeFrameSyncObjects( void ) +{ + if ( IsX360() ) + return; + + if ( mat_debugalttab.GetBool() ) + { + Warning( "mat_debugalttab: CShaderAPIDX8::FreeFrameSyncObjects\n" ); + } + + FreeFrameSyncTextureObject(); + + // FIXME FIXME FIXME!!!!! Need to record this. + for ( int i = 0; i < ARRAYSIZE(m_pFrameSyncQueryObject); i++ ) + { + if ( m_pFrameSyncQueryObject[i] ) + { + if ( m_bQueryIssued[i] ) + { + tmZone( TELEMETRY_LEVEL1, TMZF_NONE, "D3DQueryGetData %t", tmSendCallStack( TELEMETRY_LEVEL0, 0 ) ); + + double flStartTime = Plat_FloatTime(); + BOOL dummyData = 0; + HRESULT hr = S_OK; + + // Make every attempt (within 2 seconds) to get the result from the query. Doing so may prevent + // crashes in the driver if we try to release outstanding queries. + do + { + hr = m_pFrameSyncQueryObject[i]->GetData( &dummyData, sizeof( dummyData ), D3DGETDATA_FLUSH ); + double flCurrTime = Plat_FloatTime(); + + // don't wait more than 2 seconds for these + if ( flCurrTime - flStartTime > 2.00 ) + break; + } while ( hr == S_FALSE ); + } +#ifdef DBGFLAG_ASSERT + int nRetVal = +#endif + m_pFrameSyncQueryObject[i]->Release(); + Assert( nRetVal == 0 ); + m_pFrameSyncQueryObject[i] = NULL; + m_bQueryIssued[i] = false; + } + } +} + + +//----------------------------------------------------------------------------- +// Occurs when another application is initializing +//----------------------------------------------------------------------------- +void CShaderDeviceDx8::OtherAppInitializing( bool initializing ) +{ + if ( !ThreadOwnsDevice() || !ThreadInMainThread() ) + { + if ( initializing ) + { + ShaderUtil()->OnThreadEvent( SHADER_THREAD_OTHER_APP_START ); + } + else + { + ShaderUtil()->OnThreadEvent( SHADER_THREAD_OTHER_APP_END ); + } + return; + } + Assert( m_bOtherAppInitializing != initializing ); + + if ( !IsDeactivated() ) + { + Dx9Device()->EndScene(); + } + + // NOTE: OtherApp is set in this way because we need to know we're + // active as we release and restore everything + CheckDeviceLost( initializing ); + + if ( !IsDeactivated() ) + { + Dx9Device()->BeginScene(); + } +} + + +void CShaderDeviceDx8::HandleThreadEvent( uint32 threadEvent ) +{ + Assert(ThreadOwnsDevice()); + switch ( threadEvent ) + { + case SHADER_THREAD_OTHER_APP_START: + OtherAppInitializing(true); + break; + case SHADER_THREAD_RELEASE_RESOURCES: + ReleaseResources(); + break; + case SHADER_THREAD_EVICT_RESOURCES: + EvictManagedResourcesInternal(); + break; + case SHADER_THREAD_RESET_RENDER_STATE: + ResetRenderState(); + break; + case SHADER_THREAD_ACQUIRE_RESOURCES: + ReacquireResources(); + break; + case SHADER_THREAD_OTHER_APP_END: + OtherAppInitializing(false); + break; + + } +} + +//----------------------------------------------------------------------------- +// We lost the device, but we have a chance to recover +//----------------------------------------------------------------------------- +bool CShaderDeviceDx8::TryDeviceReset() +{ + if ( IsX360() ) + return true; + + // Don't try to reset the device until we're sure our resources have been released + if ( !m_bResourcesReleased ) + { + return false; + } + + // FIXME: Make this rebuild the Dx9Device from scratch! + // Helps with compatibility + HRESULT hr = Dx9Device()->Reset( &m_PresentParameters ); + bool bResetSuccess = !FAILED(hr); + +#if defined(IS_WINDOWS_PC) && defined(SHADERAPIDX9) + if ( bResetSuccess && g_ShaderDeviceUsingD3D9Ex ) + { + bResetSuccess = SUCCEEDED( Dx9Device()->TestCooperativeLevel() ); + if ( bResetSuccess ) + { + Warning("video driver has crashed and been reset, re-uploading resources now"); + } + } +#endif + + if ( bResetSuccess ) + m_bResourcesReleased = false; + return bResetSuccess; +} + + +//----------------------------------------------------------------------------- +// Release, reacquire resources +//----------------------------------------------------------------------------- +void CShaderDeviceDx8::ReleaseResources() +{ + if ( !ThreadOwnsDevice() || !ThreadInMainThread() ) + { + // Set our resources as not being released yet. + // We reset this in two places since release resources can be called without a call to TryDeviceReset. + m_bResourcesReleased = false; + ShaderUtil()->OnThreadEvent( SHADER_THREAD_RELEASE_RESOURCES ); + return; + } + + // Only the initial "ReleaseResources" actually has effect + if ( m_numReleaseResourcesRefCount ++ != 0 ) + { + Warning( "ReleaseResources has no effect, now at level %d.\n", m_numReleaseResourcesRefCount ); + DevWarning( "ReleaseResources called twice is a bug: use IsDeactivated to check for a valid device.\n" ); + Assert( 0 ); + return; + } + + LOCK_SHADERAPI(); + CPixEvent( PIX_VALVE_ORANGE, "ReleaseResources" ); + + FreeFrameSyncObjects(); + FreeNonInteractiveRefreshObjects(); + ShaderUtil()->ReleaseShaderObjects(); + MeshMgr()->ReleaseBuffers(); + g_pShaderAPI->ReleaseShaderObjects(); + +#ifdef _DEBUG + if ( MeshMgr()->BufferCount() != 0 ) + { + for( int i = 0; i < MeshMgr()->BufferCount(); i++ ) + { + } + } +#endif + + // All meshes cleaned up? + Assert( MeshMgr()->BufferCount() == 0 ); + + // Signal that our resources have been released so that we can try to reset the device + m_bResourcesReleased = true; +} + + +void CShaderDeviceDx8::ReacquireResources() +{ + ReacquireResourcesInternal(); +} + +void CShaderDeviceDx8::ReacquireResourcesInternal( bool bResetState, bool bForceReacquire, char const *pszForceReason ) +{ + if ( !ThreadOwnsDevice() || !ThreadInMainThread() ) + { + if ( bResetState ) + { + ShaderUtil()->OnThreadEvent( SHADER_THREAD_RESET_RENDER_STATE ); + } + ShaderUtil()->OnThreadEvent( SHADER_THREAD_ACQUIRE_RESOURCES ); + return; + } + if ( bForceReacquire ) + { + // If we are forcing reacquire then warn if release calls are remaining unpaired + if ( m_numReleaseResourcesRefCount > 1 ) + { + Warning( "Forcefully resetting device (%s), resources release level was %d.\n", pszForceReason ? pszForceReason : "unspecified", m_numReleaseResourcesRefCount ); + Assert( 0 ); + } + m_numReleaseResourcesRefCount = 0; + } + else + { + // Only the final "ReacquireResources" actually has effect + if ( -- m_numReleaseResourcesRefCount != 0 ) + { + Warning( "ReacquireResources has no effect, now at level %d.\n", m_numReleaseResourcesRefCount ); + DevWarning( "ReacquireResources being discarded is a bug: use IsDeactivated to check for a valid device.\n" ); + Assert( 0 ); + + if ( m_numReleaseResourcesRefCount < 0 ) + { + m_numReleaseResourcesRefCount = 0; + } + + return; + } + } + + if ( bResetState ) + { + ResetRenderState(); + } + + LOCK_SHADERAPI(); + CPixEvent event( PIX_VALVE_ORANGE, "ReacquireResources" ); + + g_pShaderAPI->RestoreShaderObjects(); + AllocFrameSyncObjects(); + AllocNonInteractiveRefreshObjects(); + MeshMgr()->RestoreBuffers(); + ShaderUtil()->RestoreShaderObjects( CShaderDeviceMgrBase::ShaderInterfaceFactory ); +} + + +//----------------------------------------------------------------------------- +// Changes the window size +//----------------------------------------------------------------------------- +bool CShaderDeviceDx8::ResizeWindow( const ShaderDeviceInfo_t &info ) +{ + if ( IsX360() ) + return false; + + m_bPendingVideoModeChange = false; + + // We don't need to do crap if the window was set up to set up + // to be resizing... + if ( info.m_bResizing ) + return false; + + g_pShaderDeviceMgr->InvokeModeChangeCallbacks(); + + ReleaseResources(); + + SetPresentParameters( (VD3DHWND)m_hWnd, m_DisplayAdapter, info ); + HRESULT hr = Dx9Device()->Reset( &m_PresentParameters ); + if ( FAILED( hr ) ) + { + Warning( "ResizeWindow: Reset failed, hr = 0x%08lX.\n", hr ); + return false; + } + else + { + ReacquireResourcesInternal( true, true, "ResizeWindow" ); + } + + return true; +} + + +//----------------------------------------------------------------------------- +// Queue up the fact that the device was lost +//----------------------------------------------------------------------------- +void CShaderDeviceDx8::MarkDeviceLost( ) +{ + if ( IsX360() ) + return; + + m_bQueuedDeviceLost = true; +} + + +//----------------------------------------------------------------------------- +// Checks if the device was lost +//----------------------------------------------------------------------------- +#if defined( _DEBUG ) && !defined( _X360 ) +ConVar mat_forcelostdevice( "mat_forcelostdevice", "0" ); +#endif + +void CShaderDeviceDx8::CheckDeviceLost( bool bOtherAppInitializing ) +{ +#if !defined( _X360 ) + // FIXME: We could also queue up if WM_SIZE changes and look at that + // but that seems to only make sense if we have resizable windows where + // we do *not* allocate buffers as large as the entire current video mode + // which we're not doing +#ifdef _WIN32 + m_bIsMinimized = ( static_cast(IsIconic( ( HWND )m_hWnd )) == (BOOL)TRUE ); +#else + m_bIsMinimized = ( IsIconic( (VD3DHWND)m_hWnd ) == TRUE ); +#endif + m_bOtherAppInitializing = bOtherAppInitializing; + +#ifdef _DEBUG + if ( mat_forcelostdevice.GetBool() ) + { + mat_forcelostdevice.SetValue( 0 ); + MarkDeviceLost(); + } +#endif + + HRESULT hr = D3D_OK; +#if defined(IS_WINDOWS_PC) && defined(SHADERAPIDX9) + if ( g_ShaderDeviceUsingD3D9Ex && m_DeviceState == DEVICE_STATE_OK ) + { + // Steady state - PresentEx return value will mark us lost if necessary. + // We do not care if we are minimized in this state. + m_bIsMinimized = false; + } + else +#endif + { + RECORD_COMMAND( DX8_TEST_COOPERATIVE_LEVEL, 0 ); + hr = Dx9Device()->TestCooperativeLevel(); + } + + // If some other call returned device lost previously in the frame, spoof the return value from TCL + if ( m_bQueuedDeviceLost ) + { + hr = (hr != D3D_OK) ? hr : D3DERR_DEVICENOTRESET; + m_bQueuedDeviceLost = false; + } + + if ( m_DeviceState == DEVICE_STATE_OK ) + { + // We can transition out of ok if bOtherAppInitializing is set + // or if we become minimized, or if TCL returns anything other than D3D_OK. + if ( ( hr != D3D_OK ) || m_bIsMinimized ) + { + // purge unreferenced materials + g_pShaderUtil->UncacheUnusedMaterials( true ); + + // We were ok, now we're not. Release resources + ReleaseResources(); + m_DeviceState = DEVICE_STATE_LOST_DEVICE; + } + else if ( bOtherAppInitializing ) + { + // purge unreferenced materials + g_pShaderUtil->UncacheUnusedMaterials( true ); + + // We were ok, now we're not. Release resources + ReleaseResources(); + m_DeviceState = DEVICE_STATE_OTHER_APP_INIT; + } + } + + // Immediately checking devicelost after ok helps in the case where we got D3DERR_DEVICENOTRESET + // in which case we want to immdiately try to switch out of DEVICE_STATE_LOST and into DEVICE_STATE_NEEDS_RESET + if ( m_DeviceState == DEVICE_STATE_LOST_DEVICE ) + { + // We can only try to reset if we're not minimized and not lost + if ( !m_bIsMinimized && (hr != D3DERR_DEVICELOST) ) + { + m_DeviceState = DEVICE_STATE_NEEDS_RESET; + } + } + + // Immediately checking needs reset also helps for the case where we got D3DERR_DEVICENOTRESET + if ( m_DeviceState == DEVICE_STATE_NEEDS_RESET ) + { + if ( ( hr == D3DERR_DEVICELOST ) || m_bIsMinimized ) + { + m_DeviceState = DEVICE_STATE_LOST_DEVICE; + } + else + { + bool bResetSucceeded = TryDeviceReset(); + if ( bResetSucceeded ) + { + if ( !bOtherAppInitializing ) + { + m_DeviceState = DEVICE_STATE_OK; + + // We were bad, now we're ok. Restore resources and reset render state. + ReacquireResourcesInternal( true, true, "NeedsReset" ); + } + else + { + m_DeviceState = DEVICE_STATE_OTHER_APP_INIT; + } + } + } + } + + if ( m_DeviceState == DEVICE_STATE_OTHER_APP_INIT ) + { + if ( ( hr != D3D_OK ) || m_bIsMinimized ) + { + m_DeviceState = DEVICE_STATE_LOST_DEVICE; + } + else if ( !bOtherAppInitializing ) + { + m_DeviceState = DEVICE_STATE_OK; + + // We were bad, now we're ok. Restore resources and reset render state. + ReacquireResourcesInternal( true, true, "OtherAppInit" ); + } + } + + // Do mode change if we have a video mode change. + if ( m_bPendingVideoModeChange && !IsDeactivated() ) + { +#ifdef _DEBUG + Warning( "mode change!\n" ); +#endif + // now purge unreferenced materials + g_pShaderUtil->UncacheUnusedMaterials( true ); + + ResizeWindow( m_PendingVideoModeChangeConfig ); + } +#endif +} + + +//----------------------------------------------------------------------------- +// Special method to refresh the screen on the XBox360 +//----------------------------------------------------------------------------- +bool CShaderDeviceDx8::AllocNonInteractiveRefreshObjects() +{ +#if defined( _X360 ) + + const char *strVertexShaderProgram = + " float4x4 matWVP : register(c0);" + " struct VS_IN" + " {" + " float4 ObjPos : POSITION;" + " float2 TexCoord : TEXCOORD;" + " };" + " struct VS_OUT" + " {" + " float4 ProjPos : POSITION;" + " float2 TexCoord : TEXCOORD;" + " };" + " VS_OUT main( VS_IN In )" + " {" + " VS_OUT Out; " + " Out.ProjPos = mul( matWVP, In.ObjPos );" + " Out.TexCoord = In.TexCoord;" + " return Out;" + " }"; + + const char *strPixelShaderProgram = + " struct PS_IN" + " {" + " float2 TexCoord : TEXCOORD;" + " };" + " sampler detail : register( s0 );" + " float4 main( PS_IN In ) : COLOR" + " {" + " return tex2D( detail, In.TexCoord );" + " }"; + + const char *strPixelShaderProgram2 = + " struct PS_IN" + " {" + " float2 TexCoord : TEXCOORD;" + " };" + " sampler detail : register( s0 );" + " float4 main( PS_IN In ) : COLOR" + " {" + " return tex2D( detail, In.TexCoord );" + " }"; + + const char *strPixelShaderProgram3 = + " struct PS_IN" + " {" + " float2 TexCoord : TEXCOORD;" + " };" + " float SrgbGammaToLinear( float flSrgbGammaValue )" + " {" + " float x = saturate( flSrgbGammaValue );" + " return ( x <= 0.04045f ) ? ( x / 12.92f ) : ( pow( ( x + 0.055f ) / 1.055f, 2.4f ) );" + " }" + "float X360LinearToGamma( float flLinearValue )" + "{" + " float fl360GammaValue;" + "" + " flLinearValue = saturate( flLinearValue );" + " if ( flLinearValue < ( 128.0f / 1023.0f ) )" + " {" + " if ( flLinearValue < ( 64.0f / 1023.0f ) )" + " {" + " fl360GammaValue = flLinearValue * ( 1023.0f * ( 1.0f / 255.0f ) );" + " }" + " else" + " {" + " fl360GammaValue = flLinearValue * ( ( 1023.0f / 2.0f ) * ( 1.0f / 255.0f ) ) + ( 32.0f / 255.0f );" + " }" + " }" + " else" + " {" + " if ( flLinearValue < ( 512.0f / 1023.0f ) )" + " {" + " fl360GammaValue = flLinearValue * ( ( 1023.0f / 4.0f ) * ( 1.0f / 255.0f ) ) + ( 64.0f / 255.0f );" + " }" + " else" + " {" + " fl360GammaValue = flLinearValue * ( ( 1023.0f /8.0f ) * ( 1.0f / 255.0f ) ) + ( 128.0f /255.0f );" + " if ( fl360GammaValue > 1.0f )" + " {" + " fl360GammaValue = 1.0f;" + " }" + " }" + " }" + "" + " fl360GammaValue = saturate( fl360GammaValue );" + " return fl360GammaValue;" + "}" + " sampler detail : register( s0 );" + " float4 main( PS_IN In ) : COLOR" + " {" + " float4 vTextureColor = tex2D( detail, In.TexCoord );" + " vTextureColor.r = X360LinearToGamma( SrgbGammaToLinear( vTextureColor.r ) );" + " vTextureColor.g = X360LinearToGamma( SrgbGammaToLinear( vTextureColor.g ) );" + " vTextureColor.b = X360LinearToGamma( SrgbGammaToLinear( vTextureColor.b ) );" + " return vTextureColor;" + " }"; + + D3DVERTEXELEMENT9 VertexElements[4] = + { + { 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 }, + { 0, 12, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 }, + D3DDECL_END() + }; + + ID3DXBuffer *pErrorMsg = NULL; + ID3DXBuffer *pShaderCode = NULL; + + HRESULT hr = D3DXCompileShader( strVertexShaderProgram, (UINT)strlen( strVertexShaderProgram ), NULL, NULL, "main", "vs_2_0", 0, &pShaderCode, &pErrorMsg, NULL ); + if ( FAILED( hr ) ) + return false; + + Dx9Device()->CreateVertexShader( (DWORD*)pShaderCode->GetBufferPointer(), &m_NonInteractiveRefresh.m_pVertexShader ); + pShaderCode->Release(); + pShaderCode = NULL; + if ( pErrorMsg ) + { + pErrorMsg->Release(); + pErrorMsg = NULL; + } + + hr = D3DXCompileShader( strPixelShaderProgram, (UINT)strlen( strPixelShaderProgram ), NULL, NULL, "main", "ps_2_0", 0, &pShaderCode, &pErrorMsg, NULL ); + if ( FAILED(hr) ) + return false; + + Dx9Device()->CreatePixelShader( (DWORD*)pShaderCode->GetBufferPointer(), &m_NonInteractiveRefresh.m_pPixelShader ); + pShaderCode->Release(); + if ( pErrorMsg ) + { + pErrorMsg->Release(); + pErrorMsg = NULL; + } + + hr = D3DXCompileShader( strPixelShaderProgram3, (UINT)strlen( strPixelShaderProgram3 ), NULL, NULL, "main", "ps_2_0", 0, &pShaderCode, &pErrorMsg, NULL ); + if ( FAILED(hr) ) + return false; + + Dx9Device()->CreatePixelShader( (DWORD*)pShaderCode->GetBufferPointer(), &m_NonInteractiveRefresh.m_pPixelShaderStartup ); + pShaderCode->Release(); + if ( pErrorMsg ) + { + pErrorMsg->Release(); + pErrorMsg = NULL; + } + + hr = D3DXCompileShader( strPixelShaderProgram2, (UINT)strlen( strPixelShaderProgram2 ), NULL, NULL, "main", "ps_2_0", 0, &pShaderCode, &pErrorMsg, NULL ); + if ( FAILED(hr) ) + return false; + + Dx9Device()->CreatePixelShader( (DWORD*)pShaderCode->GetBufferPointer(), &m_NonInteractiveRefresh.m_pPixelShaderStartupPass2 ); + pShaderCode->Release(); + if ( pErrorMsg ) + { + pErrorMsg->Release(); + pErrorMsg = NULL; + } + + // Create a vertex declaration from the element descriptions. + Dx9Device()->CreateVertexDeclaration( VertexElements, &m_NonInteractiveRefresh.m_pVertexDecl ); + +#endif + + return true; +} + +void CShaderDeviceDx8::FreeNonInteractiveRefreshObjects() +{ + if ( m_NonInteractiveRefresh.m_pVertexShader ) + { + m_NonInteractiveRefresh.m_pVertexShader->Release(); + m_NonInteractiveRefresh.m_pVertexShader = NULL; + } + + if ( m_NonInteractiveRefresh.m_pPixelShader ) + { + m_NonInteractiveRefresh.m_pPixelShader->Release(); + m_NonInteractiveRefresh.m_pPixelShader = NULL; + } + + if ( m_NonInteractiveRefresh.m_pPixelShaderStartup ) + { + m_NonInteractiveRefresh.m_pPixelShaderStartup->Release(); + m_NonInteractiveRefresh.m_pPixelShaderStartup = NULL; + } + + if ( m_NonInteractiveRefresh.m_pPixelShaderStartupPass2 ) + { + m_NonInteractiveRefresh.m_pPixelShaderStartupPass2->Release(); + m_NonInteractiveRefresh.m_pPixelShaderStartupPass2 = NULL; + } + + if ( m_NonInteractiveRefresh.m_pVertexDecl ) + { + m_NonInteractiveRefresh.m_pVertexDecl->Release(); + m_NonInteractiveRefresh.m_pVertexDecl = NULL; + } +} + +bool CShaderDeviceDx8::InNonInteractiveMode() const +{ + return m_NonInteractiveRefresh.m_Mode != MATERIAL_NON_INTERACTIVE_MODE_NONE; +} + +void CShaderDeviceDx8::EnableNonInteractiveMode( MaterialNonInteractiveMode_t mode, ShaderNonInteractiveInfo_t *pInfo ) +{ + if ( !IsX360() ) + return; + if ( pInfo && ( pInfo->m_hTempFullscreenTexture == INVALID_SHADERAPI_TEXTURE_HANDLE ) ) + { + mode = MATERIAL_NON_INTERACTIVE_MODE_NONE; + } + m_NonInteractiveRefresh.m_Mode = mode; + if ( pInfo ) + { + m_NonInteractiveRefresh.m_Info = *pInfo; + } + m_NonInteractiveRefresh.m_nPacifierFrame = 0; + + if ( mode != MATERIAL_NON_INTERACTIVE_MODE_NONE ) + { + ConVarRef mat_monitorgamma( "mat_monitorgamma" ); + ConVarRef mat_monitorgamma_tv_range_min( "mat_monitorgamma_tv_range_min" ); + ConVarRef mat_monitorgamma_tv_range_max( "mat_monitorgamma_tv_range_max" ); + ConVarRef mat_monitorgamma_tv_exp( "mat_monitorgamma_tv_exp" ); + ConVarRef mat_monitorgamma_tv_enabled( "mat_monitorgamma_tv_enabled" ); + SetHardwareGammaRamp( mat_monitorgamma.GetFloat(), mat_monitorgamma_tv_range_min.GetFloat(), mat_monitorgamma_tv_range_max.GetFloat(), + mat_monitorgamma_tv_exp.GetFloat(), mat_monitorgamma_tv_enabled.GetBool() ); + } + +#ifdef _X360 + if ( mode != MATERIAL_NON_INTERACTIVE_MODE_NONE ) + { + // HACK: VSync off (prevents us wasting time blocking on VSync due to our irregular present intervals) + Dx9Device()->SetRenderState( D3DRS_PRESENTINTERVAL, D3DPRESENT_INTERVAL_IMMEDIATE ); + } + else + { + // HACK: VSync on (defaulting to on on 360 is fine, but really should save+restore this state) + Dx9Device()->SetRenderState( D3DRS_PRESENTINTERVAL, D3DPRESENT_INTERVAL_ONE ); + } +#endif + +// Msg( "Time elapsed: %.3f Peak %.3f Ave %.5f Count %d Count Above %d\n", Plat_FloatTime() - m_NonInteractiveRefresh.m_flStartTime, +// m_NonInteractiveRefresh.m_flPeakDt, m_NonInteractiveRefresh.m_flTotalDt / m_NonInteractiveRefresh.m_nSamples, m_NonInteractiveRefresh.m_nSamples, m_NonInteractiveRefresh.m_nCountAbove66 ); + + m_NonInteractiveRefresh.m_flStartTime = m_NonInteractiveRefresh.m_flLastPresentTime = + m_NonInteractiveRefresh.m_flLastPacifierTime = Plat_FloatTime(); + m_NonInteractiveRefresh.m_flPeakDt = 0.0f; + m_NonInteractiveRefresh.m_flTotalDt = 0.0f; + m_NonInteractiveRefresh.m_nSamples = 0; + m_NonInteractiveRefresh.m_nCountAbove66 = 0; +} + +void CShaderDeviceDx8::UpdatePresentStats() +{ + float t = Plat_FloatTime(); + float flActualDt = t - m_NonInteractiveRefresh.m_flLastPresentTime; + if ( flActualDt > m_NonInteractiveRefresh.m_flPeakDt ) + { + m_NonInteractiveRefresh.m_flPeakDt = flActualDt; + } + if ( flActualDt > 0.066 ) + { + ++m_NonInteractiveRefresh.m_nCountAbove66; + } + + m_NonInteractiveRefresh.m_flTotalDt += flActualDt; + ++m_NonInteractiveRefresh.m_nSamples; + + t = Plat_FloatTime(); + m_NonInteractiveRefresh.m_flLastPresentTime = t; +} + +void CShaderDeviceDx8::RefreshFrontBufferNonInteractive() +{ + if ( !IsX360() || !InNonInteractiveMode() ) + return; + + // Other code should not be talking to D3D at the same time as this + AUTO_LOCK( m_nonInteractiveModeMutex ); + +#ifdef _X360 + g_pShaderAPI->OwnGPUResources( false ); + IDirect3DBaseTexture *pTexture = g_pShaderAPI->GetD3DTexture( m_NonInteractiveRefresh.m_Info.m_hTempFullscreenTexture ); + + int w, h; + g_pShaderAPI->GetBackBufferDimensions( w, h ); + XMMATRIX matWVP = XMMatrixOrthographicOffCenterLH( 0, (FLOAT)w, (FLOAT)h, 0, 0, 1 ); + + // Structure to hold vertex data. + struct TEXVERTEX + { + FLOAT Position[3]; + FLOAT TexCoord[2]; + }; + TEXVERTEX Vertices[4]; + + Vertices[0].Position[0] = -0.5f; + Vertices[0].Position[1] = -0.5f; + Vertices[0].Position[2] = 0; + Vertices[0].TexCoord[0] = 0; + Vertices[0].TexCoord[1] = 0; + + Vertices[1].Position[0] = w-0.5f; + Vertices[1].Position[1] = -0.5f; + Vertices[1].Position[2] = 0; + Vertices[1].TexCoord[0] = 1; + Vertices[1].TexCoord[1] = 0; + + Vertices[2].Position[0] = w-0.5f; + Vertices[2].Position[1] = h-0.5f; + Vertices[2].Position[2] = 0; + Vertices[2].TexCoord[0] = 1; + Vertices[2].TexCoord[1] = 1; + + Vertices[3].Position[0] = -0.5f; + Vertices[3].Position[1] = h-0.5f; + Vertices[3].Position[2] = 0; + Vertices[3].TexCoord[0] = 0; + Vertices[3].TexCoord[1] = 1; + + D3DVIEWPORT9 viewport; + viewport.X = viewport.Y = 0; + viewport.Width = w; viewport.Height = h; + viewport.MinZ = ReverseDepthOnX360() ? 1.0f : 0.0f; + viewport.MaxZ = 1.0f - viewport.MinZ; + + bool bInStartupMode = ( m_NonInteractiveRefresh.m_Mode == MATERIAL_NON_INTERACTIVE_MODE_STARTUP ); + + float flDepth = (ShaderUtil()->GetConfig().bReverseDepth ^ ReverseDepthOnX360()) ? 0.0f : 1.0f; + Dx9Device()->Clear( 0, NULL, D3DCLEAR_ZBUFFER, 0, flDepth, 0L ); + + Dx9Device()->SetViewport( &viewport ); + Dx9Device()->SetTexture( 0, pTexture ); + Dx9Device()->SetVertexShader( m_NonInteractiveRefresh.m_pVertexShader ); + Dx9Device()->SetPixelShader( bInStartupMode ? m_NonInteractiveRefresh.m_pPixelShaderStartup : m_NonInteractiveRefresh.m_pPixelShader ); + Dx9Device()->SetVertexShaderConstantF( 0, (FLOAT*)&matWVP, 4 ); + Dx9Device()->SetVertexDeclaration( m_NonInteractiveRefresh.m_pVertexDecl ); + Dx9Device()->SetSamplerState( 0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP ); + Dx9Device()->SetSamplerState( 0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP ); + Dx9Device()->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR ); + Dx9Device()->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR ); + + tmZone( TELEMETRY_LEVEL1, TMZF_NONE, "%s", __FUNCTION__ ); + + Dx9Device()->DrawPrimitiveUP( D3DPT_QUADLIST, 1, Vertices, sizeof( TEXVERTEX ) ); + + if ( bInStartupMode ) + { + float flXPos = m_NonInteractiveRefresh.m_Info.m_flNormalizedX; + float flYPos = m_NonInteractiveRefresh.m_Info.m_flNormalizedY; + float flHeight = m_NonInteractiveRefresh.m_Info.m_flNormalizedSize; + int nSize = h * flHeight; + int x = w * flXPos - nSize * 0.5f; + int y = h * flYPos - nSize * 0.5f; + w = h = nSize; + + Vertices[0].Position[0] = x - 0.5f; + Vertices[0].Position[1] = y - 0.5f; + Vertices[1].Position[0] = x+w-0.5f; + Vertices[1].Position[1] = y - 0.5f; + Vertices[2].Position[0] = x+w-0.5f; + Vertices[2].Position[1] = y+h-0.5f; + Vertices[3].Position[0] = x - 0.5f; + Vertices[3].Position[1] = y+h-0.5f; + + float t = Plat_FloatTime(); + float flDt = t - m_NonInteractiveRefresh.m_flLastPacifierTime; + if ( flDt > 0.030f ) + { + if ( ++m_NonInteractiveRefresh.m_nPacifierFrame >= m_NonInteractiveRefresh.m_Info.m_nPacifierCount ) + { + m_NonInteractiveRefresh.m_nPacifierFrame = 0; + } + m_NonInteractiveRefresh.m_flLastPacifierTime = t; + } + + pTexture = g_pShaderAPI->GetD3DTexture( m_NonInteractiveRefresh.m_Info.m_pPacifierTextures[ m_NonInteractiveRefresh.m_nPacifierFrame ] ); + Dx9Device()->SetRenderState( D3DRS_ALPHABLENDENABLE, 1 ); + Dx9Device()->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA ); + Dx9Device()->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA ); + Dx9Device()->SetTexture( 0, pTexture ); + Dx9Device()->SetPixelShader( m_NonInteractiveRefresh.m_pPixelShaderStartupPass2 ); + Dx9Device()->DrawPrimitiveUP( D3DPT_QUADLIST, 1, Vertices, sizeof( TEXVERTEX ) ); + } + + Dx9Device()->SetVertexShader( NULL ); + Dx9Device()->SetPixelShader( NULL ); + Dx9Device()->SetTexture( 0, NULL ); + Dx9Device()->SetVertexDeclaration( NULL ); + + tmZone( TELEMETRY_LEVEL1, TMZF_NONE, "D3DPresent" ); + + Dx9Device()->Present( 0, 0, 0, 0 ); + g_pShaderAPI->QueueResetRenderState(); + g_pShaderAPI->OwnGPUResources( true ); + + UpdatePresentStats(); +#endif +} + + +//----------------------------------------------------------------------------- +// Page flip +//----------------------------------------------------------------------------- +void CShaderDeviceDx8::Present() +{ + LOCK_SHADERAPI(); + + // need to flush the dynamic buffer + g_pShaderAPI->FlushBufferedPrimitives(); + + if ( !IsDeactivated() ) + { + Dx9Device()->EndScene(); + } + + HRESULT hr = S_OK; + + // if we're in queued mode, don't present if the device is already lost + bool bValidPresent = true; + bool bInMainThread = ThreadInMainThread(); + if ( !bInMainThread ) + { + // don't present if the device is in an invalid state and in queued mode + if ( m_DeviceState != DEVICE_STATE_OK ) + { + bValidPresent = false; + } + // check for lost device early in threaded mode + CheckDeviceLost( m_bOtherAppInitializing ); + if ( m_DeviceState != DEVICE_STATE_OK ) + { + bValidPresent = false; + } + } + // Copy the back buffer into the non-interactive temp buffer + if ( m_NonInteractiveRefresh.m_Mode == MATERIAL_NON_INTERACTIVE_MODE_LEVEL_LOAD ) + { + g_pShaderAPI->CopyRenderTargetToTextureEx( m_NonInteractiveRefresh.m_Info.m_hTempFullscreenTexture, 0, NULL, NULL ); + } + + // If we're not iconified, try to present (without this check, we can flicker when Alt-Tabbed away) +#ifdef _WIN32 + if ( IsX360() || (IsIconic( ( HWND )m_hWnd ) == 0 && bValidPresent) ) +#else + if ( IsX360() || (IsIconic( (VD3DHWND)m_hWnd ) == 0 && bValidPresent) ) +#endif + { + if ( IsPC() && ( m_IsResizing || ( m_ViewHWnd != (VD3DHWND)m_hWnd ) ) ) + { + RECT destRect; + #ifndef DX_TO_GL_ABSTRACTION + GetClientRect( ( HWND )m_ViewHWnd, &destRect ); + #else + toglGetClientRect( (VD3DHWND)m_ViewHWnd, &destRect ); + #endif + + ShaderViewport_t viewport; + g_pShaderAPI->GetViewports( &viewport, 1 ); + + RECT srcRect; + srcRect.left = viewport.m_nTopLeftX; + srcRect.right = viewport.m_nTopLeftX + viewport.m_nWidth; + srcRect.top = viewport.m_nTopLeftY; + srcRect.bottom = viewport.m_nTopLeftY + viewport.m_nHeight; + + hr = Dx9Device()->Present( &srcRect, &destRect, (VD3DHWND)m_ViewHWnd, 0 ); + } + else + { + g_pShaderAPI->OwnGPUResources( false ); + hr = Dx9Device()->Present( 0, 0, 0, 0 ); + } + } + + UpdatePresentStats(); + + if ( IsWindows() ) + { + if ( hr == D3DERR_DRIVERINTERNALERROR ) + { + /* Usually this bug means that the driver has run out of internal video + memory, due to leaking it slowly over several application restarts. + As of summer 2007, IE in particular seemed to leak a lot of driver + memory for every image context it created in the browser window. A + reboot clears out the leaked memory and will generally allow the game + to be run again; occasionally (but not frequently) it's necessary to + reduce video settings in the game as well to run. But, this is too + fine a distinction to explain in a dialog, so place the guilt on the + user and ask them to reduce video settings regardless. + */ + + Error( "Internal driver error at Present.\n" + "You're likely out of OS Paged Pool Memory! For more info, see\n" + "http://support.steampowered.com/cgi-bin/steampowered.cfg/php/enduser/std_adp.php?p_faqid=150\n" ); + } + if ( hr == D3DERR_DEVICELOST ) + { + MarkDeviceLost(); + } + } + + MeshMgr()->DiscardVertexBuffers(); + + if ( bInMainThread ) + { + CheckDeviceLost( m_bOtherAppInitializing ); + } + + if ( IsX360() ) + { + // according to docs - "Mandatory Reset of GPU Registers" + // 360 must force the cached state to be dirty after any present() + g_pShaderAPI->ResetRenderState( false ); + } + +#ifdef RECORD_KEYFRAMES + static int frame = 0; + ++frame; + if (frame == KEYFRAME_INTERVAL) + { + RECORD_COMMAND( DX8_KEYFRAME, 0 ); + + g_pShaderAPI->ResetRenderState(); + frame = 0; + } +#endif + + g_pShaderAPI->AdvancePIXFrame(); + + if ( !IsDeactivated() ) + { +#ifndef DX_TO_GL_ABSTRACTION + if ( ( ShaderUtil()->GetConfig().bMeasureFillRate || ShaderUtil()->GetConfig().bVisualizeFillRate ) ) + { + g_pShaderAPI->ClearBuffers( true, true, true, -1, -1 ); + } +#endif + + Dx9Device()->BeginScene(); + } +} + + +// We need to scale our colors to the range [16, 235] to keep our colors within TV standards. Some colors might +// still be out of gamut if any of the R, G, or B channels are more than 191 units apart from each other in +// the 0-255 scale, but it looks like the 360 deals with this for us by lowering the bright saturated color components. +// NOTE: I'm leaving the max at 255 to retain whiter than whites. On most TV's, we seems a little dark in the bright colors +// compared to TV and movies when played in the same conditions. This keeps out brights on par with what customers are +// used to seeing. +// TV's generally have a 2.5 gamma, so we need to convert our 2.2 frame buffer into a 2.5 frame buffer for display on a TV + +void CShaderDeviceDx8::SetHardwareGammaRamp( float fGamma, float fGammaTVRangeMin, float fGammaTVRangeMax, float fGammaTVExponent, bool bTVEnabled ) +{ + DevMsg( 2, "SetHardwareGammaRamp( %f )\n", fGamma ); + + Assert( Dx9Device() ); + if( !Dx9Device() ) + return; + + D3DGAMMARAMP gammaRamp; + for ( int i = 0; i < 256; i++ ) + { + float flInputValue = float( i ) / 255.0f; + + // Since the 360's sRGB read/write is a piecewise linear approximation, we need to correct for the difference in gamma space here + float flSrgbGammaValue; + if ( IsX360() ) // Should we also do this for the PS3? + { + // First undo the 360 broken sRGB curve by bringing the value back into linear space + float flLinearValue = X360GammaToLinear( flInputValue ); + flLinearValue = clamp( flLinearValue, 0.0f, 1.0f ); + + // Now apply a true sRGB curve to mimic PC hardware + flSrgbGammaValue = SrgbLinearToGamma( flLinearValue ); // ( flLinearValue <= 0.0031308f ) ? ( flLinearValue * 12.92f ) : ( 1.055f * powf( flLinearValue, ( 1.0f / 2.4f ) ) ) - 0.055f; + flSrgbGammaValue = clamp( flSrgbGammaValue, 0.0f, 1.0f ); + } + else + { + flSrgbGammaValue = flInputValue; + } + + // Apply the user controlled exponent curve + float flCorrection = pow( flSrgbGammaValue, ( fGamma / 2.2f ) ); + flCorrection = clamp( flCorrection, 0.0f, 1.0f ); + + // TV adjustment - Apply an exp and a scale and bias + if ( bTVEnabled ) + { + // Adjust for TV gamma of 2.5 by applying an exponent of 2.2 / 2.5 = 0.88 + flCorrection = pow( flCorrection, 2.2f / fGammaTVExponent ); + flCorrection = clamp( flCorrection, 0.0f, 1.0f ); + + // Scale and bias to fit into the 16-235 range for TV's + flCorrection = ( flCorrection * ( fGammaTVRangeMax - fGammaTVRangeMin ) / 255.0f ) + ( fGammaTVRangeMin / 255.0f ); + flCorrection = clamp( flCorrection, 0.0f, 1.0f ); + } + + // Generate final int value + unsigned int val = ( int )( flCorrection * 65535.0f ); + gammaRamp.red[i] = val; + gammaRamp.green[i] = val; + gammaRamp.blue[i] = val; + } + + Dx9Device()->SetGammaRamp( 0, D3DSGR_NO_CALIBRATION, &gammaRamp ); +} + + +//----------------------------------------------------------------------------- +// Shader compilation +//----------------------------------------------------------------------------- +IShaderBuffer* CShaderDeviceDx8::CompileShader( const char *pProgram, size_t nBufLen, const char *pShaderVersion ) +{ + return ShaderManager()->CompileShader( pProgram, nBufLen, pShaderVersion ); +} + +VertexShaderHandle_t CShaderDeviceDx8::CreateVertexShader( IShaderBuffer *pBuffer ) +{ + return ShaderManager()->CreateVertexShader( pBuffer ); +} + +void CShaderDeviceDx8::DestroyVertexShader( VertexShaderHandle_t hShader ) +{ + ShaderManager()->DestroyVertexShader( hShader ); +} + +GeometryShaderHandle_t CShaderDeviceDx8::CreateGeometryShader( IShaderBuffer* pShaderBuffer ) +{ + Assert( 0 ); + return GEOMETRY_SHADER_HANDLE_INVALID; +} + +void CShaderDeviceDx8::DestroyGeometryShader( GeometryShaderHandle_t hShader ) +{ + Assert( hShader == GEOMETRY_SHADER_HANDLE_INVALID ); +} + +PixelShaderHandle_t CShaderDeviceDx8::CreatePixelShader( IShaderBuffer *pBuffer ) +{ + return ShaderManager()->CreatePixelShader( pBuffer ); +} + +void CShaderDeviceDx8::DestroyPixelShader( PixelShaderHandle_t hShader ) +{ + ShaderManager()->DestroyPixelShader( hShader ); +} + +#ifdef DX_TO_GL_ABSTRACTION +void CShaderDeviceDx8::DoStartupShaderPreloading( void ) +{ + ShaderManager()->DoStartupShaderPreloading(); +} +#endif + + +//----------------------------------------------------------------------------- +// Creates/destroys Mesh +// NOTE: Will be deprecated soon! +//----------------------------------------------------------------------------- +IMesh* CShaderDeviceDx8::CreateStaticMesh( VertexFormat_t vertexFormat, const char *pTextureBudgetGroup, IMaterial * pMaterial ) +{ + LOCK_SHADERAPI(); + return MeshMgr()->CreateStaticMesh( vertexFormat, pTextureBudgetGroup, pMaterial ); +} + +void CShaderDeviceDx8::DestroyStaticMesh( IMesh* pMesh ) +{ + LOCK_SHADERAPI(); + MeshMgr()->DestroyStaticMesh( pMesh ); +} + + +//----------------------------------------------------------------------------- +// Creates/destroys vertex buffers + index buffers +//----------------------------------------------------------------------------- +IVertexBuffer *CShaderDeviceDx8::CreateVertexBuffer( ShaderBufferType_t type, VertexFormat_t fmt, int nVertexCount, const char *pBudgetGroup ) +{ + LOCK_SHADERAPI(); + return MeshMgr()->CreateVertexBuffer( type, fmt, nVertexCount, pBudgetGroup ); +} + +void CShaderDeviceDx8::DestroyVertexBuffer( IVertexBuffer *pVertexBuffer ) +{ + LOCK_SHADERAPI(); + MeshMgr()->DestroyVertexBuffer( pVertexBuffer ); +} + +IIndexBuffer *CShaderDeviceDx8::CreateIndexBuffer( ShaderBufferType_t bufferType, MaterialIndexFormat_t fmt, int nIndexCount, const char *pBudgetGroup ) +{ + LOCK_SHADERAPI(); + return MeshMgr()->CreateIndexBuffer( bufferType, fmt, nIndexCount, pBudgetGroup ); +} + +void CShaderDeviceDx8::DestroyIndexBuffer( IIndexBuffer *pIndexBuffer ) +{ + LOCK_SHADERAPI(); + MeshMgr()->DestroyIndexBuffer( pIndexBuffer ); +} + +IVertexBuffer *CShaderDeviceDx8::GetDynamicVertexBuffer( int streamID, VertexFormat_t vertexFormat, bool bBuffered ) +{ + LOCK_SHADERAPI(); + return MeshMgr()->GetDynamicVertexBuffer( streamID, vertexFormat, bBuffered ); +} + +IIndexBuffer *CShaderDeviceDx8::GetDynamicIndexBuffer( MaterialIndexFormat_t fmt, bool bBuffered ) +{ + LOCK_SHADERAPI(); + return MeshMgr()->GetDynamicIndexBuffer( fmt, bBuffered ); +} + +#ifdef _X360 +void CShaderDeviceDx8::SpewVideoInfo360( const CCommand &args ) +{ + XVIDEO_MODE videoMode; + XGetVideoMode( &videoMode ); + + Warning( "back buffer size: %dx%d\n", m_PresentParameters.BackBufferWidth, m_PresentParameters.BackBufferHeight ); + Warning( "display resolution: %dx%d %s\n", videoMode.dwDisplayWidth, videoMode.dwDisplayHeight, videoMode.fIsInterlaced ? "interlaced" : "progressive" ); + Warning( "refresh rate: %f\n", videoMode.RefreshRate ); + Warning( "aspect: %s\n", videoMode.fIsWideScreen ? "16x9 (widescreen)" : "4x3 (normal)" ); + Warning( "%s\n", videoMode.fIsHiDef ? "hidef" : "lodef" ); + switch( videoMode.VideoStandard ) + { + case XC_VIDEO_STANDARD_NTSC_M: + Warning( "video standard: NTSC_M\n" ); + break; + case XC_VIDEO_STANDARD_NTSC_J: + Warning( "video standard: NTSC_J\n" ); + break; + case XC_VIDEO_STANDARD_PAL_I: + Warning( "video standard: PAL_I\n" ); + break; + default: + Warning( "error: UNKNOWN VIDEO STANDARD!\n" ); + Assert( 0 ); + break; + } + ConVarRef fps_max( "fps_max" ); + Warning( "fps_max: %f\n", fps_max.GetFloat() ); + switch( m_PresentParameters.MultiSampleType ) + { + case D3DMULTISAMPLE_NONE: + Warning( "multisample type: D3DMULTISAMPLE_NONE\n" ); + break; + case D3DMULTISAMPLE_2_SAMPLES: + Warning( "multisample type: D3DMULTISAMPLE_2_SAMPLES\n" ); + break; + case D3DMULTISAMPLE_4_SAMPLES: + Warning( "multisample type: D3DMULTISAMPLE_4_SAMPLES\n" ); + break; + } +} +#endif diff --git a/materialsystem/shaderapidx9/shaderdevicedx8.h b/materialsystem/shaderapidx9/shaderdevicedx8.h new file mode 100644 index 0000000..4e20efe --- /dev/null +++ b/materialsystem/shaderapidx9/shaderdevicedx8.h @@ -0,0 +1,382 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +// +//===========================================================================// + +#ifndef SHADERDEVICEDX8_H +#define SHADERDEVICEDX8_H + +#ifdef _WIN32 +#pragma once +#endif + + +#include "shaderdevicebase.h" +#include "shaderapidx8_global.h" +#include "tier1/utlvector.h" + + + +//----------------------------------------------------------------------------- +// Describes which D3DDEVTYPE to use +//----------------------------------------------------------------------------- +#ifndef USE_REFERENCE_RASTERIZER +#define DX8_DEVTYPE D3DDEVTYPE_HAL +#else +#define DX8_DEVTYPE D3DDEVTYPE_REF +#endif + + +// PC: By default, PIX profiling is explicitly disallowed using the D3DPERF_SetOptions(1) API on PC +// X360: PIX_INSTRUMENTATION will only generate PIX events in RELEASE builds on 360 +// Uncomment to use PIX instrumentation: +#if PIX_ENABLE +#define PIX_INSTRUMENTATION +#endif + +#define MAX_PIX_ERRORS 3 + +#if defined( PIX_INSTRUMENTATION ) && defined ( DX_TO_GL_ABSTRACTION ) && defined( _WIN32 ) +typedef int (WINAPI *D3DPERF_BeginEvent_FuncPtr)( D3DCOLOR col, LPCWSTR wszName ); +typedef int (WINAPI *D3DPERF_EndEvent_FuncPtr)( void ); +typedef void (WINAPI *D3DPERF_SetMarker_FuncPtr)( D3DCOLOR col, LPCWSTR wszName ); +typedef void (WINAPI *D3DPERF_SetOptions_FuncPtr)( DWORD dwOptions ); +#endif + +//----------------------------------------------------------------------------- +// The Base implementation of the shader device +//----------------------------------------------------------------------------- +class CShaderDeviceMgrDx8 : public CShaderDeviceMgrBase +{ + typedef CShaderDeviceMgrBase BaseClass; + +public: + // constructor, destructor + CShaderDeviceMgrDx8(); + virtual ~CShaderDeviceMgrDx8(); + + // Methods of IAppSystem + virtual bool Connect( CreateInterfaceFn factory ); + virtual void Disconnect(); + virtual InitReturnVal_t Init(); + virtual void Shutdown(); + + // Methods of IShaderDevice + virtual int GetAdapterCount() const; + virtual void GetAdapterInfo( int adapter, MaterialAdapterInfo_t& info ) const; + virtual int GetModeCount( int nAdapter ) const; + virtual void GetModeInfo( ShaderDisplayMode_t* pInfo, int nAdapter, int mode ) const; + virtual void GetCurrentModeInfo( ShaderDisplayMode_t* pInfo, int nAdapter ) const; + virtual bool SetAdapter( int nAdapter, int nFlags ); + virtual CreateInterfaceFn SetMode( void *hWnd, int nAdapter, const ShaderDeviceInfo_t& mode ); + + // Determines hardware caps from D3D + bool ComputeCapsFromD3D( HardwareCaps_t *pCaps, int nAdapter ); + + // Forces caps to a specific dx level + void ForceCapsToDXLevel( HardwareCaps_t *pCaps, int nDxLevel, const HardwareCaps_t &actualCaps ); + + // Validates the mode... + bool ValidateMode( int nAdapter, const ShaderDeviceInfo_t &info ) const; + + // Returns the amount of video memory in bytes for a particular adapter + virtual int GetVidMemBytes( int nAdapter ) const; + +#if !defined( _X360 ) + FORCEINLINE IDirect3D9 *D3D() const + { + return m_pD3D; + } +#endif + +#if defined( PIX_INSTRUMENTATION ) && defined ( DX_TO_GL_ABSTRACTION ) && defined( _WIN32 ) + HMODULE m_hD3D9; + D3DPERF_BeginEvent_FuncPtr m_pBeginEvent; + D3DPERF_EndEvent_FuncPtr m_pEndEvent; + D3DPERF_SetMarker_FuncPtr m_pSetMarker; + D3DPERF_SetOptions_FuncPtr m_pSetOptions; +#endif + +protected: + // Determine capabilities + bool DetermineHardwareCaps( ); + +private: + // Initialize adapter information + void InitAdapterInfo(); + + // Code to detect support for texture border mode (not a simple caps check) + void CheckBorderColorSupport( HardwareCaps_t *pCaps, int nAdapter ); + + // Vendor-dependent code to detect support for various flavors of shadow mapping + void CheckVendorDependentShadowMappingSupport( HardwareCaps_t *pCaps, int nAdapter ); + + // Vendor-dependent code to detect Alpha To Coverage Backdoors + void CheckVendorDependentAlphaToCoverage( HardwareCaps_t *pCaps, int nAdapter ); + + // Compute the effective DX support level based on all the other caps + void ComputeDXSupportLevel( HardwareCaps_t &caps ); + + // Used to enumerate adapters, attach to windows +#if !defined( _X360 ) + IDirect3D9 *m_pD3D; +#endif + + bool m_bObeyDxCommandlineOverride : 1; + bool m_bAdapterInfoIntialized : 1; +}; + +extern CShaderDeviceMgrDx8* g_pShaderDeviceMgrDx8; + + +//----------------------------------------------------------------------------- +// IDirect3D accessor +//----------------------------------------------------------------------------- +#if defined( _X360 ) + +extern IDirect3D9 *m_pD3D; +inline IDirect3D9* D3D() +{ + return m_pD3D; +} + +#else + +inline IDirect3D9* D3D() +{ + return g_pShaderDeviceMgrDx8->D3D(); +} + +#endif + +#define NUM_FRAME_SYNC_QUERIES 2 +#define NUM_FRAME_SYNC_FRAMES_LATENCY 0 + +//----------------------------------------------------------------------------- +// The Dx8implementation of the shader device +//----------------------------------------------------------------------------- +class CShaderDeviceDx8 : public CShaderDeviceBase +{ + // Methods of IShaderDevice +public: + virtual bool IsUsingGraphics() const; + virtual ImageFormat GetBackBufferFormat() const; + virtual void GetBackBufferDimensions( int& width, int& height ) const; + virtual void Present(); + virtual IShaderBuffer* CompileShader( const char *pProgram, size_t nBufLen, const char *pShaderVersion ); + virtual VertexShaderHandle_t CreateVertexShader( IShaderBuffer *pBuffer ); + virtual void DestroyVertexShader( VertexShaderHandle_t hShader ); + virtual GeometryShaderHandle_t CreateGeometryShader( IShaderBuffer* pShaderBuffer ); + virtual void DestroyGeometryShader( GeometryShaderHandle_t hShader ); + virtual PixelShaderHandle_t CreatePixelShader( IShaderBuffer* pShaderBuffer ); + virtual void DestroyPixelShader( PixelShaderHandle_t hShader ); + virtual void ReleaseResources(); + virtual void ReacquireResources(); + virtual IMesh* CreateStaticMesh( VertexFormat_t format, const char *pBudgetGroup, IMaterial * pMaterial = NULL ); + virtual void DestroyStaticMesh( IMesh* mesh ); + virtual IVertexBuffer *CreateVertexBuffer( ShaderBufferType_t type, VertexFormat_t fmt, int nVertexCount, const char *pBudgetGroup ); + virtual void DestroyVertexBuffer( IVertexBuffer *pVertexBuffer ); + virtual IIndexBuffer *CreateIndexBuffer( ShaderBufferType_t bufferType, MaterialIndexFormat_t fmt, int nIndexCount, const char *pBudgetGroup ); + virtual void DestroyIndexBuffer( IIndexBuffer *pIndexBuffer ); + virtual IVertexBuffer *GetDynamicVertexBuffer( int nStreamID, VertexFormat_t vertexFormat, bool bBuffered = true ); + virtual IIndexBuffer *GetDynamicIndexBuffer( MaterialIndexFormat_t fmt, bool bBuffered = true ); + virtual void SetHardwareGammaRamp( float fGamma, float fGammaTVRangeMin, float fGammaTVRangeMax, float fGammaTVExponent, bool bTVEnabled ); + virtual void SpewDriverInfo() const; + virtual int GetCurrentAdapter() const; + virtual void EnableNonInteractiveMode( MaterialNonInteractiveMode_t mode, ShaderNonInteractiveInfo_t *pInfo = NULL ); + virtual void RefreshFrontBufferNonInteractive(); + virtual char *GetDisplayDeviceName() OVERRIDE; + + // Alternative method for ib/vs + // NOTE: If this works, remove GetDynamicVertexBuffer/IndexBuffer + + // Methods of CShaderDeviceBase +public: + virtual bool InitDevice( void* hWnd, int nAdapter, const ShaderDeviceInfo_t &info ); + virtual void ShutdownDevice(); + virtual bool IsDeactivated() const; + + // Other public methods +public: + // constructor, destructor + CShaderDeviceDx8(); + virtual ~CShaderDeviceDx8(); + + // Call this when another app is initializing or finished initializing + virtual void OtherAppInitializing( bool initializing ); + + // This handles any events queued because they were called outside of the owning thread + virtual void HandleThreadEvent( uint32 threadEvent ); + + // FIXME: Make private + // Which device are we using? + UINT m_DisplayAdapter; + D3DDEVTYPE m_DeviceType; + +protected: + enum DeviceState_t + { + DEVICE_STATE_OK = 0, + DEVICE_STATE_OTHER_APP_INIT, + DEVICE_STATE_LOST_DEVICE, + DEVICE_STATE_NEEDS_RESET, + }; + + struct NonInteractiveRefreshState_t + { + IDirect3DVertexShader9 *m_pVertexShader; + IDirect3DPixelShader9 *m_pPixelShader; + IDirect3DPixelShader9 *m_pPixelShaderStartup; + IDirect3DPixelShader9 *m_pPixelShaderStartupPass2; + IDirect3DVertexDeclaration9 *m_pVertexDecl; + ShaderNonInteractiveInfo_t m_Info; + MaterialNonInteractiveMode_t m_Mode; + float m_flLastPacifierTime; + int m_nPacifierFrame; + + float m_flStartTime; + float m_flLastPresentTime; + float m_flPeakDt; + float m_flTotalDt; + int m_nSamples; + int m_nCountAbove66; + }; + +protected: + // Creates the D3D Device + bool CreateD3DDevice( void* pHWnd, int nAdapter, const ShaderDeviceInfo_t &info ); + + // Actually creates the D3D Device once the present parameters are set up + IDirect3DDevice9* InvokeCreateDevice( void* hWnd, int nAdapter, DWORD deviceCreationFlags ); + + // Checks for CreateQuery support + void DetectQuerySupport( IDirect3DDevice9* pD3DDevice ); + + // Computes the presentation parameters + void SetPresentParameters( void* hWnd, int nAdapter, const ShaderDeviceInfo_t &info ); + + // Computes the supersample flags + D3DMULTISAMPLE_TYPE ComputeMultisampleType( int nSampleCount ); + + // Is the device active? + bool IsActive() const; + + // Try to reset the device, returned true if it succeeded + bool TryDeviceReset(); + + // Queue up the fact that the device was lost + void MarkDeviceLost(); + + // Deals with lost devices + void CheckDeviceLost( bool bOtherAppInitializing ); + + // Changes the window size + bool ResizeWindow( const ShaderDeviceInfo_t &info ); + + // Deals with the frame synching object + void AllocFrameSyncObjects( void ); + void FreeFrameSyncObjects( void ); + + // Alloc and free objects that are necessary for frame syncing + void AllocFrameSyncTextureObject(); + void FreeFrameSyncTextureObject(); + + // Alloc and free objects necessary for noninteractive frame refresh on the x360 + bool AllocNonInteractiveRefreshObjects(); + void FreeNonInteractiveRefreshObjects(); + + // FIXME: This is for backward compat; I still haven't solved a way of decoupling this + virtual bool OnAdapterSet() = 0; + virtual void ResetRenderState( bool bFullReset = true ) = 0; + + // For measuring if we meed TCR 022 on the XBox (refreshing often enough) + void UpdatePresentStats(); + + bool InNonInteractiveMode() const; + + void ReacquireResourcesInternal( bool bResetState = false, bool bForceReacquire = false, char const *pszForceReason = NULL ); + +#ifdef DX_TO_GL_ABSTRACTION +public: + virtual void DoStartupShaderPreloading( void ); +protected: +#endif + + D3DPRESENT_PARAMETERS m_PresentParameters; + ImageFormat m_AdapterFormat; + + // Mode info + int m_DeviceSupportsCreateQuery; + + ShaderDeviceInfo_t m_PendingVideoModeChangeConfig; + DeviceState_t m_DeviceState; + + bool m_bOtherAppInitializing : 1; + bool m_bQueuedDeviceLost : 1; + bool m_IsResizing : 1; + bool m_bPendingVideoModeChange : 1; + bool m_bUsingStencil : 1; + bool m_bResourcesReleased : 1; + + // amount of stencil variation we have available + int m_iStencilBufferBits; + +#ifdef _X360 + CON_COMMAND_MEMBER_F( CShaderDeviceDx8, "360vidinfo", SpewVideoInfo360, "Get information on the video mode on the 360", 0 ); +#endif + + // Frame sync objects + IDirect3DQuery9 *m_pFrameSyncQueryObject[NUM_FRAME_SYNC_QUERIES]; + bool m_bQueryIssued[NUM_FRAME_SYNC_QUERIES]; + int m_currentSyncQuery; + IDirect3DTexture9 *m_pFrameSyncTexture; + +#if defined( _X360 ) + HXUIDC m_hDC; +#endif + + CUtlString m_sDisplayDeviceName; + + // Used for x360 only + NonInteractiveRefreshState_t m_NonInteractiveRefresh; + CThreadFastMutex m_nonInteractiveModeMutex; + friend class CShaderDeviceMgrDx8; + + int m_numReleaseResourcesRefCount; // This is holding the number of ReleaseResources calls queued up, + // for every ReleaseResources call there should be a matching call to + // ReacquireResources, only the last top-level ReacquireResources will + // have effect. Nested ReleaseResources calls are bugs. +}; + + +//----------------------------------------------------------------------------- +// Globals +//----------------------------------------------------------------------------- +extern IDirect3DDevice9 *g_pD3DDevice; +FORCEINLINE IDirect3DDevice9 *Dx9Device() +{ + return g_pD3DDevice; +} + +extern CShaderDeviceDx8* g_pShaderDeviceDx8; + + +//----------------------------------------------------------------------------- +// Inline methods +//----------------------------------------------------------------------------- +FORCEINLINE bool CShaderDeviceDx8::IsActive() const +{ + return ( g_pD3DDevice != NULL ); +} + +// used to determine if we're deactivated +FORCEINLINE bool CShaderDeviceDx8::IsDeactivated() const +{ + return ( IsPC() && ( ( m_DeviceState != DEVICE_STATE_OK ) || m_bQueuedDeviceLost || m_numReleaseResourcesRefCount ) ); +} + + +#endif // SHADERDEVICEDX8_H diff --git a/materialsystem/shaderapidx9/shadershadowdx10.cpp b/materialsystem/shaderapidx9/shadershadowdx10.cpp new file mode 100644 index 0000000..d67cc4b --- /dev/null +++ b/materialsystem/shaderapidx9/shadershadowdx10.cpp @@ -0,0 +1,227 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +// +//===========================================================================// + +#include "shadershadowdx10.h" +#include "utlvector.h" +#include "materialsystem/imaterialsystem.h" +#include "IHardwareConfigInternal.h" +#include "shadersystem.h" +#include "shaderapi/ishaderutil.h" +#include "materialsystem/imesh.h" +#include "tier0/dbg.h" +#include "materialsystem/idebugtextureinfo.h" + + +//----------------------------------------------------------------------------- +// Class Factory +//----------------------------------------------------------------------------- +static CShaderShadowDx10 s_ShaderShadow; +CShaderShadowDx10 *g_pShaderShadowDx10 = &s_ShaderShadow; + +EXPOSE_SINGLE_INTERFACE_GLOBALVAR( CShaderShadowDx10, IShaderShadow, + SHADERSHADOW_INTERFACE_VERSION, s_ShaderShadow ) + +//----------------------------------------------------------------------------- +// The shader shadow interface +//----------------------------------------------------------------------------- +CShaderShadowDx10::CShaderShadowDx10() +{ + m_IsTranslucent = false; + m_IsAlphaTested = false; + m_bIsDepthWriteEnabled = true; + m_bUsesVertexAndPixelShaders = false; +} + +CShaderShadowDx10::~CShaderShadowDx10() +{ +} + +// Sets the default *shadow* state +void CShaderShadowDx10::SetDefaultState() +{ + m_IsTranslucent = false; + m_IsAlphaTested = false; + m_bIsDepthWriteEnabled = true; + m_bUsesVertexAndPixelShaders = false; +} + +// Methods related to depth buffering +void CShaderShadowDx10::DepthFunc( ShaderDepthFunc_t depthFunc ) +{ +} + +void CShaderShadowDx10::EnableDepthWrites( bool bEnable ) +{ + m_bIsDepthWriteEnabled = bEnable; +} + +void CShaderShadowDx10::EnableDepthTest( bool bEnable ) +{ +} + +void CShaderShadowDx10::EnablePolyOffset( PolygonOffsetMode_t nOffsetMode ) +{ +} + +// Suppresses/activates color writing +void CShaderShadowDx10::EnableColorWrites( bool bEnable ) +{ +} + +// Suppresses/activates alpha writing +void CShaderShadowDx10::EnableAlphaWrites( bool bEnable ) +{ +} + +// Methods related to alpha blending +void CShaderShadowDx10::EnableBlending( bool bEnable ) +{ + m_IsTranslucent = bEnable; +} + +void CShaderShadowDx10::BlendFunc( ShaderBlendFactor_t srcFactor, ShaderBlendFactor_t dstFactor ) +{ +} + +void CShaderShadowDx10::BlendOp( ShaderBlendOp_t blendOp ) +{ +} + +void CShaderShadowDx10::BlendOpSeparateAlpha( ShaderBlendOp_t blendOp ) +{ +} + +// A simpler method of dealing with alpha modulation +void CShaderShadowDx10::EnableAlphaPipe( bool bEnable ) +{ +} + +void CShaderShadowDx10::EnableConstantAlpha( bool bEnable ) +{ +} + +void CShaderShadowDx10::EnableVertexAlpha( bool bEnable ) +{ +} + +void CShaderShadowDx10::EnableTextureAlpha( TextureStage_t stage, bool bEnable ) +{ +} + +void CShaderShadowDx10::SetShadowDepthFiltering( Sampler_t stage ) +{ +} + +// Alpha testing +void CShaderShadowDx10::EnableAlphaTest( bool bEnable ) +{ + m_IsAlphaTested = bEnable; +} + +void CShaderShadowDx10::AlphaFunc( ShaderAlphaFunc_t alphaFunc, float alphaRef /* [0-1] */ ) +{ +} + +// Wireframe/filled polygons +void CShaderShadowDx10::PolyMode( ShaderPolyModeFace_t face, ShaderPolyMode_t polyMode ) +{ +} + + +// Back face culling +void CShaderShadowDx10::EnableCulling( bool bEnable ) +{ +} + +// Alpha to coverage +void CShaderShadowDx10::EnableAlphaToCoverage( bool bEnable ) +{ +} + +// constant color + transparency +void CShaderShadowDx10::EnableConstantColor( bool bEnable ) +{ +} + + +// Indicates the vertex format for use with a vertex shader +// The flags to pass in here come from the VertexFormatFlags_t enum +// If pTexCoordDimensions is *not* specified, we assume all coordinates +// are 2-dimensional +void CShaderShadowDx10::VertexShaderVertexFormat( unsigned int flags, + int numTexCoords, int* pTexCoordDimensions, + int userDataSize ) +{ +} + +// Indicates we're going to light the model +void CShaderShadowDx10::EnableLighting( bool bEnable ) +{ +} + +void CShaderShadowDx10::EnableSpecular( bool bEnable ) +{ +} + +// Activate/deactivate skinning +void CShaderShadowDx10::EnableVertexBlend( bool bEnable ) +{ +} + +// per texture unit stuff +void CShaderShadowDx10::OverbrightValue( TextureStage_t stage, float value ) +{ +} + +void CShaderShadowDx10::EnableTexture( Sampler_t stage, bool bEnable ) +{ +} + +void CShaderShadowDx10::EnableCustomPixelPipe( bool bEnable ) +{ +} + +void CShaderShadowDx10::CustomTextureStages( int stageCount ) +{ +} + +void CShaderShadowDx10::CustomTextureOperation( TextureStage_t stage, ShaderTexChannel_t channel, + ShaderTexOp_t op, ShaderTexArg_t arg1, ShaderTexArg_t arg2 ) +{ +} + +void CShaderShadowDx10::EnableTexGen( TextureStage_t stage, bool bEnable ) +{ +} + +void CShaderShadowDx10::TexGen( TextureStage_t stage, ShaderTexGenParam_t param ) +{ +} + +// Sets the vertex and pixel shaders +void CShaderShadowDx10::SetVertexShader( const char *pShaderName, int vshIndex ) +{ + m_bUsesVertexAndPixelShaders = ( pShaderName != NULL ); +} + +void CShaderShadowDx10::EnableBlendingSeparateAlpha( bool bEnable ) +{ +} +void CShaderShadowDx10::SetPixelShader( const char *pShaderName, int pshIndex ) +{ + m_bUsesVertexAndPixelShaders = ( pShaderName != NULL ); +} + +void CShaderShadowDx10::BlendFuncSeparateAlpha( ShaderBlendFactor_t srcFactor, ShaderBlendFactor_t dstFactor ) +{ +} +// indicates what per-vertex data we're providing +void CShaderShadowDx10::DrawFlags( unsigned int drawFlags ) +{ +} + diff --git a/materialsystem/shaderapidx9/shadershadowdx8.cpp b/materialsystem/shaderapidx9/shadershadowdx8.cpp new file mode 100644 index 0000000..8c231c9 --- /dev/null +++ b/materialsystem/shaderapidx9/shadershadowdx8.cpp @@ -0,0 +1,1826 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +// +//===========================================================================// + +#define DISABLE_PROTECTED_THINGS +#include "togl/rendermechanism.h" +#include "shadershadowdx8.h" +#include "locald3dtypes.h" +#include "utlvector.h" +#include "shaderapi/ishaderutil.h" +#include "shaderapidx8_global.h" +#include "shaderapidx8.h" +#include "materialsystem/imaterialsystemhardwareconfig.h" +#include "materialsystem/imaterialsystem.h" +#include "imeshdx8.h" +#include "materialsystem/materialsystem_config.h" +#include "vertexshaderdx8.h" + +// NOTE: This must be the last file included! +#include "tier0/memdbgon.h" + + +//----------------------------------------------------------------------------- +// The DX8 implementation of the shader setup interface +//----------------------------------------------------------------------------- +class CShaderShadowDX8 : public IShaderShadowDX8 +{ +public: + // constructor, destructor + CShaderShadowDX8( ); + virtual ~CShaderShadowDX8(); + + // Initialize render state + void Init( ); + + // Sets the default state + void SetDefaultState(); + + // Methods related to depth buffering + void DepthFunc( ShaderDepthFunc_t depthFunc ); + void EnableDepthWrites( bool bEnable ); + void EnableDepthTest( bool bEnable ); + void EnablePolyOffset( PolygonOffsetMode_t nOffsetMode ); + + // Methods related to stencil. obsolete + virtual void EnableStencil( bool bEnable ) + { + } + virtual void StencilFunc( ShaderStencilFunc_t stencilFunc ) + { + } + virtual void StencilPassOp( ShaderStencilOp_t stencilOp ) + { + } + virtual void StencilFailOp( ShaderStencilOp_t stencilOp ) + { + } + virtual void StencilDepthFailOp( ShaderStencilOp_t stencilOp ) + { + } + virtual void StencilReference( int nReference ) + { + } + virtual void StencilMask( int nMask ) + { + } + virtual void StencilWriteMask( int nMask ) + { + } + + // Suppresses/activates color writing + void EnableColorWrites( bool bEnable ); + void EnableAlphaWrites( bool bEnable ); + + // Methods related to alpha blending + void EnableBlending( bool bEnable ); + + void BlendFunc( ShaderBlendFactor_t srcFactor, ShaderBlendFactor_t dstFactor ); + void BlendOp( ShaderBlendOp_t blendOp ); + void BlendOpSeparateAlpha( ShaderBlendOp_t blendOp ); + + // Alpha testing + void EnableAlphaTest( bool bEnable ); + void AlphaFunc( ShaderAlphaFunc_t alphaFunc, float alphaRef /* [0-1] */ ); + + // Wireframe/filled polygons + void PolyMode( ShaderPolyModeFace_t face, ShaderPolyMode_t polyMode ); + + // Back face culling + void EnableCulling( bool bEnable ); + + // constant color + void EnableConstantColor( bool bEnable ); + + // Indicates we're going to light the model + void EnableLighting( bool bEnable ); + + // Indicates specular lighting is going to be used + void EnableSpecular( bool bEnable ); + + // Convert from linear to gamma color space on writes to frame buffer. + void EnableSRGBWrite( bool bEnable ); + + // Convert from gamma to linear on texture fetch. + void EnableSRGBRead( Sampler_t stage, bool bEnable ); + + // Set up appropriate shadow filtering state (such as Fetch4 on ATI) + void SetShadowDepthFiltering( Sampler_t stage ); + + // Computes the vertex format + virtual void VertexShaderVertexFormat( unsigned int nFlags, + int nTexCoordCount, int* pTexCoordDimensions, int nUserDataSize ); + + // Pixel and vertex shader methods + virtual void SetVertexShader( const char* pFileName, int nStaticVshIndex ); + virtual void SetPixelShader( const char* pFileName, int nStaticPshIndex ); + + // Indicates we're going to be using the ambient cube + void EnableAmbientLightCubeOnStage0( bool bEnable ); + + // Activate/deactivate skinning + void EnableVertexBlend( bool bEnable ); + + // per texture unit stuff + void OverbrightValue( TextureStage_t stage, float value ); + void EnableTexture( Sampler_t stage, bool bEnable ); + void EnableTexGen( TextureStage_t stage, bool bEnable ); + void TexGen( TextureStage_t stage, ShaderTexGenParam_t param ); + void TextureCoordinate( TextureStage_t stage, int useCoord ); + + // alternate method of specifying per-texture unit stuff, more flexible and more complicated + // Can be used to specify different operation per channel (alpha/color)... + void EnableCustomPixelPipe( bool bEnable ); + void CustomTextureStages( int stageCount ); + void CustomTextureOperation( TextureStage_t stage, ShaderTexChannel_t channel, + ShaderTexOp_t op, ShaderTexArg_t arg1, ShaderTexArg_t arg2 ); + + // A simpler method of dealing with alpha modulation + void EnableAlphaPipe( bool bEnable ); + void EnableConstantAlpha( bool bEnable ); + void EnableVertexAlpha( bool bEnable ); + void EnableTextureAlpha( TextureStage_t stage, bool bEnable ); + + // helper functions + void EnableSphereMapping( TextureStage_t stage, bool bEnable ); + + // Last call to be make before snapshotting + void ComputeAggregateShadowState( ); + + // Gets at the shadow state + const ShadowState_t & GetShadowState(); + const ShadowShaderState_t & GetShadowShaderState(); + + // GR - Separate alpha blending + void EnableBlendingSeparateAlpha( bool bEnable ); + void BlendFuncSeparateAlpha( ShaderBlendFactor_t srcFactor, ShaderBlendFactor_t dstFactor ); + + void FogMode( ShaderFogMode_t fogMode ); + void DisableFogGammaCorrection( bool bDisable ); + + void SetDiffuseMaterialSource( ShaderMaterialSource_t materialSource ); + virtual void SetMorphFormat( MorphFormat_t flags ); + + // Alpha to coverage + void EnableAlphaToCoverage( bool bEnable ); + +private: + struct TextureStageState_t + { + int m_TexCoordIndex; + int m_TexCoordinate; + float m_OverbrightVal; + ShaderTexArg_t m_Arg[2][2]; + ShaderTexOp_t m_Op[2]; + unsigned char m_TexGenEnable:1; + unsigned char m_TextureAlphaEnable:1; + }; + + struct SamplerState_t + { + bool m_TextureEnable : 1; + }; + + // Computes the blend factor + D3DBLEND BlendFuncValue( ShaderBlendFactor_t factor ) const; + + // Computes the blend op + D3DBLENDOP BlendOpValue( ShaderBlendOp_t blendOp ) const; + + // Configures the FVF vertex shader + void ConfigureFVFVertexShader( unsigned int flags ); + void ConfigureCustomFVFVertexShader( unsigned int flags ); + + // Configures our texture indices + void ConfigureTextureCoordinates( unsigned int flags ); + + // Returns a blend value based on overbrighting + D3DTEXTUREOP OverbrightBlendValue( TextureStage_t stage ); + + // Sets the desired color and alpha op state + void DrawFlags( unsigned int flags ); + + // Computes a vertex format for the draw flags + VertexFormat_t FlagsToVertexFormat( int flags ) const; + + // Indicates we've got a constant color specified + bool HasConstantColor() const; + + // Configures the alpha pipe + void ConfigureAlphaPipe( unsigned int flags ); + + // returns true if we're using texture coordinates at a given stage + bool IsUsingTextureCoordinates( Sampler_t stage ) const; + + // Recomputes the tex coord index + void RecomputeTexCoordIndex( TextureStage_t stage ); + + + // State needed to create the snapshots + IMaterialSystemHardwareConfig* m_pHardwareConfig; + + // Separate alpha control? + bool m_AlphaPipe; + + // Constant color state + bool m_HasConstantColor; + bool m_HasConstantAlpha; + + // Vertex color state + bool m_HasVertexAlpha; + + // funky custom method of specifying shader state + bool m_CustomTextureStageState; + + // Number of stages used by the custom pipeline + int m_CustomTextureStages; + + // Number of bones... + int m_NumBlendVertices; + + // Draw flags + int m_DrawFlags; + + // Alpha blending... + D3DBLEND m_SrcBlend; + D3DBLEND m_DestBlend; + D3DBLENDOP m_BlendOp; + + // GR - Separate alpha blending... + D3DBLEND m_SrcBlendAlpha; + D3DBLEND m_DestBlendAlpha; + D3DBLENDOP m_BlendOpAlpha; + + // Alpha testing + D3DCMPFUNC m_AlphaFunc; + int m_AlphaRef; + + // Stencil + D3DCMPFUNC m_StencilFunc; + int m_StencilRef; + int m_StencilMask; + DWORD m_StencilFail; + DWORD m_StencilZFail; + DWORD m_StencilPass; + int m_StencilWriteMask; + + // The current shadow state + ShadowState_t m_ShadowState; + ShadowShaderState_t m_ShadowShaderState; + + // State info stores with each texture stage + TextureStageState_t m_TextureStage[MAX_TEXTURE_STAGES]; + SamplerState_t m_SamplerState[MAX_SAMPLERS]; +}; + + +//----------------------------------------------------------------------------- +// Class factory +//----------------------------------------------------------------------------- +static CShaderShadowDX8 g_ShaderShadow; +IShaderShadowDX8 *g_pShaderShadowDx8 = &g_ShaderShadow; + +EXPOSE_SINGLE_INTERFACE_GLOBALVAR( CShaderShadowDX8, IShaderShadow, + SHADERSHADOW_INTERFACE_VERSION, g_ShaderShadow ) + +//----------------------------------------------------------------------------- +// Global instance +//----------------------------------------------------------------------------- +IShaderShadowDX8* ShaderShadow() +{ + return &g_ShaderShadow; +} + + +//----------------------------------------------------------------------------- +// Constructor, destructor +//----------------------------------------------------------------------------- +CShaderShadowDX8::CShaderShadowDX8( ) : + m_DrawFlags(0), m_pHardwareConfig(0), m_HasConstantColor(false) +{ + memset( &m_ShadowState, 0, sizeof(m_ShadowState) ); + memset( &m_TextureStage, 0, sizeof(m_TextureStage) ); +} + +CShaderShadowDX8::~CShaderShadowDX8() +{ +} + + +//----------------------------------------------------------------------------- +// Initialize render state +//----------------------------------------------------------------------------- +void CShaderShadowDX8::Init( ) +{ + m_pHardwareConfig = HardwareConfig(); + + // Clear out the shadow state + memset( &m_ShadowState, 0, sizeof(m_ShadowState) ); + + // No funky custom methods.. + m_CustomTextureStageState = false; + + // No constant color modulation + m_HasConstantColor = false; + m_HasConstantAlpha = false; + m_HasVertexAlpha = false; + + m_ShadowShaderState.m_ModulateConstantColor = false; + + m_ShadowState.m_bDisableFogGammaCorrection = false; + + // By default we're using fixed function + m_ShadowState.m_UsingFixedFunction = true; + + // Lighting off by default + m_ShadowState.m_Lighting = false; + + // Pixel + vertex shaders + m_ShadowShaderState.m_VertexShader = INVALID_SHADER; + m_ShadowShaderState.m_PixelShader = INVALID_SHADER; + m_ShadowShaderState.m_nStaticPshIndex = 0; + m_ShadowShaderState.m_nStaticVshIndex = 0; + m_ShadowShaderState.m_VertexUsage = 0; + + // Drawing nothing.. + m_DrawFlags = 0; + + // No alpha control + m_AlphaPipe = false; + + // Vertex blending + m_NumBlendVertices = 0; + m_ShadowState.m_VertexBlendEnable = false; + + // NOTE: If you change these defaults, change the code in ComputeAggregateShadowState + CreateTransitionTableEntry + int i; + for (i = 0; i < MAX_TEXTURE_STAGES; ++i) + { + m_ShadowState.m_TextureStage[i].m_ColorOp = D3DTOP_DISABLE; + m_ShadowState.m_TextureStage[i].m_ColorArg1 = D3DTA_TEXTURE; + m_ShadowState.m_TextureStage[i].m_ColorArg2 = (i == 0) ? D3DTA_DIFFUSE : D3DTA_CURRENT; + m_ShadowState.m_TextureStage[i].m_AlphaOp = D3DTOP_DISABLE; + m_ShadowState.m_TextureStage[i].m_AlphaArg1 = D3DTA_TEXTURE; + m_ShadowState.m_TextureStage[i].m_AlphaArg2 = (i == 0) ? D3DTA_DIFFUSE : D3DTA_CURRENT; + m_ShadowState.m_TextureStage[i].m_TexCoordIndex = i; + } + + for (i = 0; i < MAX_SAMPLERS; ++i) + { + m_ShadowState.m_SamplerState[i].m_TextureEnable = false; + m_ShadowState.m_SamplerState[i].m_SRGBReadEnable = false; + m_ShadowState.m_SamplerState[i].m_Fetch4Enable = false; +#ifdef DX_TO_GL_ABSTRACTION + m_ShadowState.m_SamplerState[i].m_ShadowFilterEnable = false; +#endif + // A *real* measure if the texture stage is being used. + // we sometimes have to set the shadow state to not mirror this. + m_SamplerState[i].m_TextureEnable = false; + } +} + + +//----------------------------------------------------------------------------- +// Sets the default state +//----------------------------------------------------------------------------- +void CShaderShadowDX8::SetDefaultState() +{ + DepthFunc( SHADER_DEPTHFUNC_NEAREROREQUAL ); + EnableDepthWrites( true ); + EnableDepthTest( true ); + EnableColorWrites( true ); + EnableAlphaWrites( false ); + EnableAlphaTest( false ); + EnableLighting( false ); + EnableConstantColor( false ); + EnableBlending( false ); + BlendFunc( SHADER_BLEND_ONE, SHADER_BLEND_ZERO ); + BlendOp( SHADER_BLEND_OP_ADD ); + // GR - separate alpha + EnableBlendingSeparateAlpha( false ); + BlendFuncSeparateAlpha( SHADER_BLEND_ONE, SHADER_BLEND_ZERO ); + BlendOpSeparateAlpha( SHADER_BLEND_OP_ADD ); + AlphaFunc( SHADER_ALPHAFUNC_GEQUAL, 0.7f ); + PolyMode( SHADER_POLYMODEFACE_FRONT_AND_BACK, SHADER_POLYMODE_FILL ); + EnableCulling( true ); + EnableAlphaToCoverage( false ); + EnablePolyOffset( SHADER_POLYOFFSET_DISABLE ); + EnableVertexBlend( false ); + EnableSpecular( false ); + EnableSRGBWrite( false ); + DrawFlags( SHADER_DRAW_POSITION ); + EnableCustomPixelPipe( false ); + CustomTextureStages( 0 ); + EnableAlphaPipe( false ); + EnableConstantAlpha( false ); + EnableVertexAlpha( false ); + SetVertexShader( NULL, 0 ); + SetPixelShader( NULL, 0 ); + FogMode( SHADER_FOGMODE_DISABLED ); + DisableFogGammaCorrection( false ); + SetDiffuseMaterialSource( SHADER_MATERIALSOURCE_MATERIAL ); + EnableStencil( false ); + StencilFunc( SHADER_STENCILFUNC_ALWAYS ); + StencilPassOp( SHADER_STENCILOP_KEEP ); + StencilFailOp( SHADER_STENCILOP_KEEP ); + StencilDepthFailOp( SHADER_STENCILOP_KEEP ); + StencilReference( 0 ); + StencilMask( 0xFFFFFFFF ); + StencilWriteMask( 0xFFFFFFFF ); + m_ShadowShaderState.m_VertexUsage = 0; + + int i; + int nSamplerCount = HardwareConfig()->GetSamplerCount(); + for( i = 0; i < nSamplerCount; i++ ) + { + EnableTexture( (Sampler_t)i, false ); + EnableSRGBRead( (Sampler_t)i, false ); + } + + int nTextureStageCount = HardwareConfig()->GetTextureStageCount(); + for( i = 0; i < nTextureStageCount; i++ ) + { + EnableTexGen( (TextureStage_t)i, false ); + OverbrightValue( (TextureStage_t)i, 1.0f ); + EnableTextureAlpha( (TextureStage_t)i, false ); + CustomTextureOperation( (TextureStage_t)i, SHADER_TEXCHANNEL_COLOR, + SHADER_TEXOP_DISABLE, SHADER_TEXARG_TEXTURE, SHADER_TEXARG_PREVIOUSSTAGE ); + CustomTextureOperation( (TextureStage_t)i, SHADER_TEXCHANNEL_ALPHA, + SHADER_TEXOP_DISABLE, SHADER_TEXARG_TEXTURE, SHADER_TEXARG_PREVIOUSSTAGE ); + } +} + + +//----------------------------------------------------------------------------- +// Gets at the shadow state +//----------------------------------------------------------------------------- +const ShadowState_t &CShaderShadowDX8::GetShadowState() +{ + return m_ShadowState; +} + +const ShadowShaderState_t &CShaderShadowDX8::GetShadowShaderState() +{ + return m_ShadowShaderState; +} + + +//----------------------------------------------------------------------------- +// Depth functions... +//----------------------------------------------------------------------------- +void CShaderShadowDX8::DepthFunc( ShaderDepthFunc_t depthFunc ) +{ + D3DCMPFUNC zFunc; + + switch( depthFunc ) + { + case SHADER_DEPTHFUNC_NEVER: + zFunc = D3DCMP_NEVER; + break; + case SHADER_DEPTHFUNC_NEARER: + zFunc = (ShaderUtil()->GetConfig().bReverseDepth ^ ReverseDepthOnX360()) ? D3DCMP_GREATER : D3DCMP_LESS; + break; + case SHADER_DEPTHFUNC_EQUAL: + zFunc = D3DCMP_EQUAL; + break; + case SHADER_DEPTHFUNC_NEAREROREQUAL: + zFunc = (ShaderUtil()->GetConfig().bReverseDepth ^ ReverseDepthOnX360()) ? D3DCMP_GREATEREQUAL : D3DCMP_LESSEQUAL; + break; + case SHADER_DEPTHFUNC_FARTHER: + zFunc = (ShaderUtil()->GetConfig().bReverseDepth ^ ReverseDepthOnX360()) ? D3DCMP_LESS : D3DCMP_GREATER; + break; + case SHADER_DEPTHFUNC_NOTEQUAL: + zFunc = D3DCMP_NOTEQUAL; + break; + case SHADER_DEPTHFUNC_FARTHEROREQUAL: + zFunc = (ShaderUtil()->GetConfig().bReverseDepth ^ ReverseDepthOnX360()) ? D3DCMP_LESSEQUAL : D3DCMP_GREATEREQUAL; + break; + case SHADER_DEPTHFUNC_ALWAYS: + zFunc = D3DCMP_ALWAYS; + break; + default: + zFunc = D3DCMP_ALWAYS; + Warning( "DepthFunc: invalid param\n" ); + break; + } + + m_ShadowState.m_ZFunc = zFunc; +} + +void CShaderShadowDX8::EnableDepthWrites( bool bEnable ) +{ + m_ShadowState.m_ZWriteEnable = bEnable; +} + +void CShaderShadowDX8::EnableDepthTest( bool bEnable ) +{ + m_ShadowState.m_ZEnable = bEnable ? D3DZB_TRUE : D3DZB_FALSE; +} + +void CShaderShadowDX8::EnablePolyOffset( PolygonOffsetMode_t nOffsetMode ) +{ + m_ShadowState.m_ZBias = nOffsetMode; +} + +//----------------------------------------------------------------------------- +// Color write state +//----------------------------------------------------------------------------- +void CShaderShadowDX8::EnableColorWrites( bool bEnable ) +{ + if (bEnable) + { + m_ShadowState.m_ColorWriteEnable |= D3DCOLORWRITEENABLE_BLUE | + D3DCOLORWRITEENABLE_GREEN | D3DCOLORWRITEENABLE_RED; + } + else + { + m_ShadowState.m_ColorWriteEnable &= ~( D3DCOLORWRITEENABLE_BLUE | + D3DCOLORWRITEENABLE_GREEN | D3DCOLORWRITEENABLE_RED ); + } +} + +void CShaderShadowDX8::EnableAlphaWrites( bool bEnable ) +{ + if (bEnable) + { + m_ShadowState.m_ColorWriteEnable |= D3DCOLORWRITEENABLE_ALPHA; + } + else + { + m_ShadowState.m_ColorWriteEnable &= ~D3DCOLORWRITEENABLE_ALPHA; + } +} + + +//----------------------------------------------------------------------------- +// Alpha blending states +//----------------------------------------------------------------------------- +void CShaderShadowDX8::EnableBlending( bool bEnable ) +{ + m_ShadowState.m_AlphaBlendEnable = bEnable; +} + +// GR - separate alpha +void CShaderShadowDX8::EnableBlendingSeparateAlpha( bool bEnable ) +{ + m_ShadowState.m_SeparateAlphaBlendEnable = bEnable; +} + +void CShaderShadowDX8::EnableAlphaTest( bool bEnable ) +{ + m_ShadowState.m_AlphaTestEnable = bEnable; +} + +void CShaderShadowDX8::AlphaFunc( ShaderAlphaFunc_t alphaFunc, float alphaRef /* [0-1] */ ) +{ + D3DCMPFUNC d3dCmpFunc; + + switch( alphaFunc ) + { + case SHADER_ALPHAFUNC_NEVER: + d3dCmpFunc = D3DCMP_NEVER; + break; + case SHADER_ALPHAFUNC_LESS: + d3dCmpFunc = D3DCMP_LESS; + break; + case SHADER_ALPHAFUNC_EQUAL: + d3dCmpFunc = D3DCMP_EQUAL; + break; + case SHADER_ALPHAFUNC_LEQUAL: + d3dCmpFunc = D3DCMP_LESSEQUAL; + break; + case SHADER_ALPHAFUNC_GREATER: + d3dCmpFunc = D3DCMP_GREATER; + break; + case SHADER_ALPHAFUNC_NOTEQUAL: + d3dCmpFunc = D3DCMP_NOTEQUAL; + break; + case SHADER_ALPHAFUNC_GEQUAL: + d3dCmpFunc = D3DCMP_GREATEREQUAL; + break; + case SHADER_ALPHAFUNC_ALWAYS: + d3dCmpFunc = D3DCMP_ALWAYS; + break; + default: + Warning( "AlphaFunc: invalid param\n" ); + return; + } + + m_AlphaFunc = d3dCmpFunc; + m_AlphaRef = (int)(alphaRef * 255); +} + +D3DBLEND CShaderShadowDX8::BlendFuncValue( ShaderBlendFactor_t factor ) const +{ + switch( factor ) + { + case SHADER_BLEND_ZERO: + return D3DBLEND_ZERO; + + case SHADER_BLEND_ONE: + return D3DBLEND_ONE; + + case SHADER_BLEND_DST_COLOR: + return D3DBLEND_DESTCOLOR; + + case SHADER_BLEND_ONE_MINUS_DST_COLOR: + return D3DBLEND_INVDESTCOLOR; + + case SHADER_BLEND_SRC_ALPHA: + return D3DBLEND_SRCALPHA; + + case SHADER_BLEND_ONE_MINUS_SRC_ALPHA: + return D3DBLEND_INVSRCALPHA; + + case SHADER_BLEND_DST_ALPHA: + return D3DBLEND_DESTALPHA; + + case SHADER_BLEND_ONE_MINUS_DST_ALPHA: + return D3DBLEND_INVDESTALPHA; + + case SHADER_BLEND_SRC_ALPHA_SATURATE: + return D3DBLEND_SRCALPHASAT; + + case SHADER_BLEND_SRC_COLOR: + return D3DBLEND_SRCCOLOR; + + case SHADER_BLEND_ONE_MINUS_SRC_COLOR: + return D3DBLEND_INVSRCCOLOR; + } + + Warning( "BlendFunc: invalid factor\n" ); + return D3DBLEND_ONE; +} + +D3DBLENDOP CShaderShadowDX8::BlendOpValue( ShaderBlendOp_t blendOp ) const +{ + switch( blendOp ) + { + case SHADER_BLEND_OP_ADD: + return D3DBLENDOP_ADD; + + case SHADER_BLEND_OP_SUBTRACT: + return D3DBLENDOP_SUBTRACT; + + case SHADER_BLEND_OP_REVSUBTRACT: + return D3DBLENDOP_REVSUBTRACT; + + case SHADER_BLEND_OP_MIN: + return D3DBLENDOP_MIN; + + case SHADER_BLEND_OP_MAX: + return D3DBLENDOP_MAX; + } + + Warning( "BlendOp: invalid op\n" ); + return D3DBLENDOP_ADD; +} + +void CShaderShadowDX8::BlendFunc( ShaderBlendFactor_t srcFactor, ShaderBlendFactor_t dstFactor ) +{ + D3DBLEND d3dSrcFactor = BlendFuncValue( srcFactor ); + D3DBLEND d3dDstFactor = BlendFuncValue( dstFactor ); + m_SrcBlend = d3dSrcFactor; + m_DestBlend = d3dDstFactor; +} + +// GR - separate alpha blend +void CShaderShadowDX8::BlendFuncSeparateAlpha( ShaderBlendFactor_t srcFactor, ShaderBlendFactor_t dstFactor ) +{ + D3DBLEND d3dSrcFactor = BlendFuncValue( srcFactor ); + D3DBLEND d3dDstFactor = BlendFuncValue( dstFactor ); + m_SrcBlendAlpha = d3dSrcFactor; + m_DestBlendAlpha = d3dDstFactor; +} + +void CShaderShadowDX8::BlendOp( ShaderBlendOp_t blendOp ) +{ + m_BlendOp = BlendOpValue( blendOp ); +} + +void CShaderShadowDX8::BlendOpSeparateAlpha( ShaderBlendOp_t blendOp ) +{ + m_BlendOpAlpha = BlendOpValue( blendOp ); +} + +//----------------------------------------------------------------------------- +// Polygon fill mode states +//----------------------------------------------------------------------------- +void CShaderShadowDX8::PolyMode( ShaderPolyModeFace_t face, ShaderPolyMode_t polyMode ) +{ + // DX8 can't handle different modes on front and back faces +// FIXME: Assert( face == SHADER_POLYMODEFACE_FRONT_AND_BACK ); + if (face == SHADER_POLYMODEFACE_BACK) + return; + + D3DFILLMODE fillMode; + switch( polyMode ) + { + case SHADER_POLYMODE_POINT: + fillMode = D3DFILL_POINT; + break; + case SHADER_POLYMODE_LINE: + fillMode = D3DFILL_WIREFRAME; + break; + case SHADER_POLYMODE_FILL: + fillMode = D3DFILL_SOLID; + break; + default: + Warning( "PolyMode: invalid poly mode\n" ); + return; + } + + m_ShadowState.m_FillMode = fillMode; +} + + +//----------------------------------------------------------------------------- +// Backface cull states +//----------------------------------------------------------------------------- +void CShaderShadowDX8::EnableCulling( bool bEnable ) +{ + m_ShadowState.m_CullEnable = bEnable; +} + + +//----------------------------------------------------------------------------- +// Alpha to coverage +//----------------------------------------------------------------------------- +void CShaderShadowDX8::EnableAlphaToCoverage( bool bEnable ) +{ + m_ShadowState.m_EnableAlphaToCoverage = bEnable; +} + + +//----------------------------------------------------------------------------- +// Indicates we've got a constant color specified +//----------------------------------------------------------------------------- +bool CShaderShadowDX8::HasConstantColor() const +{ + return m_HasConstantColor; +} + +void CShaderShadowDX8::EnableConstantColor( bool bEnable ) +{ + m_HasConstantColor = bEnable; +} + + +//----------------------------------------------------------------------------- +// A simpler method of dealing with alpha modulation +//----------------------------------------------------------------------------- +void CShaderShadowDX8::EnableAlphaPipe( bool bEnable ) +{ + m_AlphaPipe = bEnable; +} + +void CShaderShadowDX8::EnableConstantAlpha( bool bEnable ) +{ + m_HasConstantAlpha = bEnable; +} + +void CShaderShadowDX8::EnableVertexAlpha( bool bEnable ) +{ + m_HasVertexAlpha = bEnable; +} + +void CShaderShadowDX8::EnableTextureAlpha( TextureStage_t stage, bool bEnable ) +{ + if ( stage < m_pHardwareConfig->GetSamplerCount() ) + { + m_TextureStage[stage].m_TextureAlphaEnable = bEnable; + } +} + + +//----------------------------------------------------------------------------- +// Indicates we're going to light the model +//----------------------------------------------------------------------------- +void CShaderShadowDX8::EnableLighting( bool bEnable ) +{ + m_ShadowState.m_Lighting = bEnable; +} + + +//----------------------------------------------------------------------------- +// Enables specular lighting (lighting has also got to be enabled) +//----------------------------------------------------------------------------- +void CShaderShadowDX8::EnableSpecular( bool bEnable ) +{ + m_ShadowState.m_SpecularEnable = bEnable; +} + +//----------------------------------------------------------------------------- +// Enables auto-conversion from linear to gamma space on write to framebuffer. +//----------------------------------------------------------------------------- +void CShaderShadowDX8::EnableSRGBWrite( bool bEnable ) +{ + if ( m_pHardwareConfig->SupportsSRGB() ) + { + m_ShadowState.m_SRGBWriteEnable = bEnable; + } + else + { + m_ShadowState.m_SRGBWriteEnable = false; + } +} + +//----------------------------------------------------------------------------- +// Activate/deactivate skinning +//----------------------------------------------------------------------------- +void CShaderShadowDX8::EnableVertexBlend( bool bEnable ) +{ + // Activate/deactivate skinning. Indexed blending is automatically + // enabled if it's available for this hardware. When blending is enabled, + // we allocate enough room for 3 weights (max allowed) + if ((m_pHardwareConfig->MaxBlendMatrices() > 0) || (!bEnable)) + { + m_ShadowState.m_VertexBlendEnable = bEnable; + } +} + + +//----------------------------------------------------------------------------- +// Texturemapping state +//----------------------------------------------------------------------------- +void CShaderShadowDX8::EnableTexture( Sampler_t sampler, bool bEnable ) +{ + if ( sampler < m_pHardwareConfig->GetSamplerCount() ) + { + m_SamplerState[sampler].m_TextureEnable = bEnable; + } + else + { + Warning( "Attempting to bind a texture to an invalid sampler (%d)!\n", sampler ); + } +} + +void CShaderShadowDX8::EnableSRGBRead( Sampler_t sampler, bool bEnable ) +{ + if ( !m_pHardwareConfig->SupportsSRGB() ) + { + m_ShadowState.m_SamplerState[sampler].m_SRGBReadEnable = false; + return; + } + + if ( sampler < m_pHardwareConfig->GetSamplerCount() ) + { + m_ShadowState.m_SamplerState[sampler].m_SRGBReadEnable = bEnable; + } + else + { + Warning( "Attempting set SRGBRead state on an invalid sampler (%d)!\n", sampler ); + } +} + +void CShaderShadowDX8::SetShadowDepthFiltering( Sampler_t stage ) +{ +#ifdef DX_TO_GL_ABSTRACTION + if ( stage < m_pHardwareConfig->GetSamplerCount() ) + { + m_ShadowState.m_SamplerState[stage].m_ShadowFilterEnable = true; + return; + } +#else + if ( !m_pHardwareConfig->SupportsFetch4() ) + { + m_ShadowState.m_SamplerState[stage].m_Fetch4Enable = false; + return; + } + + if ( stage < m_pHardwareConfig->GetSamplerCount() ) + { + m_ShadowState.m_SamplerState[stage].m_Fetch4Enable = true; + return; + } +#endif + + Warning( "Attempting set shadow filtering state on an invalid sampler (%d)!\n", stage ); +} + + +//----------------------------------------------------------------------------- +// Binds texture coordinates to a particular stage... +//----------------------------------------------------------------------------- +void CShaderShadowDX8::TextureCoordinate( TextureStage_t stage, int useTexCoord ) +{ + if ( stage < m_pHardwareConfig->GetTextureStageCount() ) + { + m_TextureStage[stage].m_TexCoordinate = useTexCoord; + + // Need to recompute the texCoordIndex, since that's affected by this + RecomputeTexCoordIndex(stage); + } +} + + +//----------------------------------------------------------------------------- +// Automatic texture coordinate generation +//----------------------------------------------------------------------------- +void CShaderShadowDX8::RecomputeTexCoordIndex( TextureStage_t stage ) +{ + int texCoordIndex = m_TextureStage[stage].m_TexCoordinate; + if (m_TextureStage[stage].m_TexGenEnable) + texCoordIndex |= m_TextureStage[stage].m_TexCoordIndex; + m_ShadowState.m_TextureStage[stage].m_TexCoordIndex = texCoordIndex; +} + + +//----------------------------------------------------------------------------- +// Automatic texture coordinate generation +//----------------------------------------------------------------------------- +void CShaderShadowDX8::EnableTexGen( TextureStage_t stage, bool bEnable ) +{ + if ( stage >= m_pHardwareConfig->GetTextureStageCount() ) + { + Assert( 0 ); + return; + } + + m_TextureStage[stage].m_TexGenEnable = bEnable; + RecomputeTexCoordIndex(stage); +} + +//----------------------------------------------------------------------------- +// Automatic texture coordinate generation +//----------------------------------------------------------------------------- +void CShaderShadowDX8::TexGen( TextureStage_t stage, ShaderTexGenParam_t param ) +{ +#ifdef FIXED_FUNCTION_PIPELINE + if ( stage >= m_pHardwareConfig->GetTextureStageCount() ) + return; + + switch( param ) + { + case SHADER_TEXGENPARAM_OBJECT_LINEAR: + m_TextureStage[stage].m_TexCoordIndex = 0; + break; + case SHADER_TEXGENPARAM_EYE_LINEAR: + m_TextureStage[stage].m_TexCoordIndex = D3DTSS_TCI_CAMERASPACEPOSITION; + break; + case SHADER_TEXGENPARAM_SPHERE_MAP: + if ( m_pHardwareConfig->SupportsSpheremapping() ) + { + m_TextureStage[stage].m_TexCoordIndex = D3DTSS_TCI_SPHEREMAP; + } + else + { + m_TextureStage[stage].m_TexCoordIndex = D3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR; + } + break; + case SHADER_TEXGENPARAM_CAMERASPACEREFLECTIONVECTOR: + m_TextureStage[stage].m_TexCoordIndex = D3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR; + break; + case SHADER_TEXGENPARAM_CAMERASPACENORMAL: + m_TextureStage[stage].m_TexCoordIndex = D3DTSS_TCI_CAMERASPACENORMAL; + break; + } + + // Set the board state... + RecomputeTexCoordIndex(stage); +#endif +} + + +//----------------------------------------------------------------------------- +// Overbrighting +//----------------------------------------------------------------------------- +void CShaderShadowDX8::OverbrightValue( TextureStage_t stage, float value ) +{ + if ( m_pHardwareConfig->SupportsOverbright() && + ( stage < m_pHardwareConfig->GetTextureStageCount() ) ) + { + m_TextureStage[stage].m_OverbrightVal = value; + } +} + + + + +//----------------------------------------------------------------------------- +// alternate method of specifying per-texture unit stuff, more flexible and more complicated +// Can be used to specify different operation per channel (alpha/color)... +//----------------------------------------------------------------------------- +void CShaderShadowDX8::EnableCustomPixelPipe( bool bEnable ) +{ + m_CustomTextureStageState = bEnable; +} + +void CShaderShadowDX8::CustomTextureStages( int stageCount ) +{ + m_CustomTextureStages = stageCount; + Assert( stageCount <= m_pHardwareConfig->GetTextureStageCount() ); + if ( stageCount > m_pHardwareConfig->GetTextureStageCount() ) + stageCount = m_pHardwareConfig->GetTextureStageCount(); +} + +void CShaderShadowDX8::CustomTextureOperation( TextureStage_t stage, + ShaderTexChannel_t channel, ShaderTexOp_t op, ShaderTexArg_t arg1, ShaderTexArg_t arg2 ) +{ + m_TextureStage[stage].m_Op[channel]= op; + m_TextureStage[stage].m_Arg[channel][0] = arg1; + m_TextureStage[stage].m_Arg[channel][1] = arg2; +} + + +//----------------------------------------------------------------------------- +// Compute the vertex format from vertex descriptor flags +//----------------------------------------------------------------------------- +void CShaderShadowDX8::VertexShaderVertexFormat( unsigned int nFlags, + int nTexCoordCount, int* pTexCoordDimensions, int nUserDataSize ) +{ + // Code that creates a Mesh should specify whether it contains bone weights+indices, *not* the shader. + Assert( ( nFlags & VERTEX_BONE_INDEX ) == 0 ); + nFlags &= ~VERTEX_BONE_INDEX; + + // This indicates we're using a vertex shader + nFlags |= VERTEX_FORMAT_VERTEX_SHADER; + m_ShadowShaderState.m_VertexUsage = MeshMgr()->ComputeVertexFormat( nFlags, nTexCoordCount, + pTexCoordDimensions, 0, nUserDataSize ); + m_ShadowState.m_UsingFixedFunction = false; + + // Avoid an error if vertex stream 0 is too narrow + if ( CVertexBufferBase::VertexFormatSize( m_ShadowShaderState.m_VertexUsage ) <= 16 ) + { + // FIXME: this is only necessary because we + // (a) put the flex normal/position stream in ALL vertex decls + // (b) bind stream 0's VB to stream 2 if there is no actual flex data + // ...it would be far more sensible to not add stream 2 to all vertex decls. + static bool bComplained = false; + if( !bComplained ) + { + Warning( "ERROR: shader asking for a too-narrow vertex format - you will see errors if running with debug D3D DLLs!\n\tPadding the vertex format with extra texcoords\n\tWill not warn again.\n" ); + bComplained = true; + } + // All vertex formats should contain position... + Assert( nFlags & VERTEX_POSITION ); + nFlags |= VERTEX_POSITION; + // This error should occur only if we have zero texcoords, or if we have a single, 1-D texcoord + Assert( ( nTexCoordCount == 0 ) || + ( ( nTexCoordCount == 1 ) && pTexCoordDimensions && ( pTexCoordDimensions[0] == 1 ) ) ); + nTexCoordCount = 1; + m_ShadowShaderState.m_VertexUsage = MeshMgr()->ComputeVertexFormat( nFlags, nTexCoordCount, NULL, 0, nUserDataSize ); + } +} + + +//----------------------------------------------------------------------------- +// Compute the vertex format from vertex descriptor flags +//----------------------------------------------------------------------------- +void CShaderShadowDX8::SetMorphFormat( MorphFormat_t flags ) +{ + m_ShadowShaderState.m_MorphUsage = flags; +} + +//----------------------------------------------------------------------------- +// Pixel and vertex shader methods +//----------------------------------------------------------------------------- +void CShaderShadowDX8::SetVertexShader( const char* pFileName, int nStaticVshIndex ) +{ + char debugLabel[500] = ""; +#ifdef DX_TO_GL_ABSTRACTION + Q_snprintf( debugLabel, sizeof(debugLabel), "vs-file %s vs-index %d", pFileName, nStaticVshIndex ); +#endif + + m_ShadowShaderState.m_VertexShader = ShaderManager()->CreateVertexShader( pFileName, nStaticVshIndex, debugLabel ); + m_ShadowShaderState.m_nStaticVshIndex = nStaticVshIndex; +} + +void CShaderShadowDX8::SetPixelShader( const char* pFileName, int nStaticPshIndex ) +{ + char debugLabel[500] = ""; +#ifdef DX_TO_GL_ABSTRACTION + Q_snprintf( debugLabel, sizeof(debugLabel), "ps-file %s ps-index %d", pFileName, nStaticPshIndex ); +#endif + + m_ShadowShaderState.m_PixelShader = ShaderManager()->CreatePixelShader( pFileName, nStaticPshIndex, debugLabel ); + m_ShadowShaderState.m_nStaticPshIndex = nStaticPshIndex; +} + + +//----------------------------------------------------------------------------- +// NOTE: See Version 5 of this file for NVidia 8-stage shader stuff +//----------------------------------------------------------------------------- +inline bool CShaderShadowDX8::IsUsingTextureCoordinates( Sampler_t sampler ) const +{ + return m_SamplerState[sampler].m_TextureEnable; +} + +inline D3DTEXTUREOP CShaderShadowDX8::OverbrightBlendValue( TextureStage_t stage ) +{ + D3DTEXTUREOP colorop; + if (m_TextureStage[stage].m_OverbrightVal < 2.0F) + colorop = D3DTOP_MODULATE; + else if (m_TextureStage[stage].m_OverbrightVal < 4.0F) + colorop = D3DTOP_MODULATE2X; + else + colorop = D3DTOP_MODULATE4X; + return colorop; +} + +static inline int ComputeArg( ShaderTexArg_t arg ) +{ + switch(arg) + { + case SHADER_TEXARG_TEXTURE: + return D3DTA_TEXTURE; + + case SHADER_TEXARG_ZERO: + return D3DTA_SPECULAR | D3DTA_COMPLEMENT; + + case SHADER_TEXARG_ONE: + return D3DTA_SPECULAR; + + case SHADER_TEXARG_TEXTUREALPHA: + return D3DTA_TEXTURE | D3DTA_ALPHAREPLICATE; + + case SHADER_TEXARG_INVTEXTUREALPHA: + return D3DTA_TEXTURE | D3DTA_ALPHAREPLICATE | D3DTA_COMPLEMENT; + + case SHADER_TEXARG_NONE: + case SHADER_TEXARG_VERTEXCOLOR: + return D3DTA_DIFFUSE; + + case SHADER_TEXARG_SPECULARCOLOR: + return D3DTA_SPECULAR; + + case SHADER_TEXARG_CONSTANTCOLOR: + return D3DTA_TFACTOR; + + case SHADER_TEXARG_PREVIOUSSTAGE: + return D3DTA_CURRENT; + } + + Assert(0); + return D3DTA_TEXTURE; +} + +static inline D3DTEXTUREOP ComputeOp( ShaderTexOp_t op ) +{ + switch(op) + { + case SHADER_TEXOP_MODULATE: + return D3DTOP_MODULATE; + + case SHADER_TEXOP_MODULATE2X: + return D3DTOP_MODULATE2X; + + case SHADER_TEXOP_MODULATE4X: + return D3DTOP_MODULATE4X; + + case SHADER_TEXOP_SELECTARG1: + return D3DTOP_SELECTARG1; + + case SHADER_TEXOP_SELECTARG2: + return D3DTOP_SELECTARG2; + + case SHADER_TEXOP_ADD: + return D3DTOP_ADD; + + case SHADER_TEXOP_SUBTRACT: + return D3DTOP_SUBTRACT; + + case SHADER_TEXOP_ADDSIGNED2X: + return D3DTOP_ADDSIGNED2X; + + case SHADER_TEXOP_BLEND_CONSTANTALPHA: + return D3DTOP_BLENDFACTORALPHA; + + case SHADER_TEXOP_BLEND_PREVIOUSSTAGEALPHA: + return D3DTOP_BLENDCURRENTALPHA; + + case SHADER_TEXOP_BLEND_TEXTUREALPHA: + return D3DTOP_BLENDTEXTUREALPHA; + + case SHADER_TEXOP_MODULATECOLOR_ADDALPHA: + return D3DTOP_MODULATECOLOR_ADDALPHA; + + case SHADER_TEXOP_MODULATEINVCOLOR_ADDALPHA: + return D3DTOP_MODULATEINVCOLOR_ADDALPHA; + + case SHADER_TEXOP_DOTPRODUCT3: + return D3DTOP_DOTPRODUCT3; + + case SHADER_TEXOP_DISABLE: + return D3DTOP_DISABLE; + } + + Assert(0); + return D3DTOP_MODULATE; +} + +void CShaderShadowDX8::ConfigureCustomFVFVertexShader( unsigned int flags ) +{ + int i; + for ( i = 0; i < m_CustomTextureStages; ++i) + { + m_ShadowState.m_TextureStage[i].m_ColorArg1 = ComputeArg( m_TextureStage[i].m_Arg[0][0] ); + m_ShadowState.m_TextureStage[i].m_ColorArg2 = ComputeArg( m_TextureStage[i].m_Arg[0][1] ); + m_ShadowState.m_TextureStage[i].m_AlphaArg1 = ComputeArg( m_TextureStage[i].m_Arg[1][0] ); + m_ShadowState.m_TextureStage[i].m_AlphaArg2 = ComputeArg( m_TextureStage[i].m_Arg[1][1] ); + m_ShadowState.m_TextureStage[i].m_ColorOp = ComputeOp( m_TextureStage[i].m_Op[0] ); + m_ShadowState.m_TextureStage[i].m_AlphaOp = ComputeOp( m_TextureStage[i].m_Op[1] ); + } + + // Deal with texture stage 1 -> n + for ( i = m_CustomTextureStages; i < m_pHardwareConfig->GetTextureStageCount(); ++i ) + { + m_ShadowState.m_TextureStage[i].m_ColorArg1 = D3DTA_TEXTURE; + m_ShadowState.m_TextureStage[i].m_ColorArg2 = D3DTA_CURRENT; + m_ShadowState.m_TextureStage[i].m_AlphaArg1 = D3DTA_TEXTURE; + m_ShadowState.m_TextureStage[i].m_AlphaArg2 = D3DTA_CURRENT; + m_ShadowState.m_TextureStage[i].m_ColorOp = D3DTOP_DISABLE; + m_ShadowState.m_TextureStage[i].m_AlphaOp = D3DTOP_DISABLE; + } +} + + +//----------------------------------------------------------------------------- +// Sets up the alpha texture stage state +//----------------------------------------------------------------------------- +void CShaderShadowDX8::ConfigureAlphaPipe( unsigned int flags ) +{ + // Are we using color? + bool isUsingVertexAlpha = m_HasVertexAlpha && ((flags & SHADER_DRAW_COLOR) != 0); + bool isUsingConstantAlpha = m_HasConstantAlpha; + + int lastTextureStage = m_pHardwareConfig->GetTextureStageCount() - 1; + while ( lastTextureStage >= 0 ) + { + if ( m_TextureStage[lastTextureStage].m_TextureAlphaEnable ) + break; + --lastTextureStage; + } + + for ( int i = 0; i < m_pHardwareConfig->GetTextureStageCount(); ++i ) + { + m_ShadowState.m_TextureStage[i].m_AlphaOp = D3DTOP_MODULATE; + if ( m_TextureStage[i].m_TextureAlphaEnable ) + { + if (i == 0) + { + m_ShadowState.m_TextureStage[i].m_AlphaArg1 = D3DTA_TEXTURE; + m_ShadowState.m_TextureStage[i].m_AlphaArg2 = + isUsingConstantAlpha ? D3DTA_TFACTOR : D3DTA_DIFFUSE; + if (!isUsingConstantAlpha && !isUsingVertexAlpha) + m_ShadowState.m_TextureStage[i].m_AlphaOp = D3DTOP_SELECTARG1; + if (isUsingConstantAlpha) + isUsingConstantAlpha = false; + else if (isUsingVertexAlpha) + isUsingVertexAlpha = false; + } + else + { + // Deal with texture stage 0 + m_ShadowState.m_TextureStage[i].m_AlphaArg1 = D3DTA_TEXTURE; + m_ShadowState.m_TextureStage[i].m_AlphaArg2 = D3DTA_CURRENT; + } + } + else + { + // Blat out unused stages + if ((i > lastTextureStage) && !isUsingVertexAlpha && !isUsingConstantAlpha) + { + m_ShadowState.m_TextureStage[i].m_AlphaArg1 = D3DTA_TEXTURE; + m_ShadowState.m_TextureStage[i].m_AlphaArg2 = D3DTA_CURRENT; + m_ShadowState.m_TextureStage[i].m_AlphaOp = D3DTOP_DISABLE; + continue; + } + + // No texture coordinates; try to fold in vertex or constant alpha + if (i == 0) + { + m_ShadowState.m_TextureStage[i].m_AlphaArg1 = D3DTA_TFACTOR; + m_ShadowState.m_TextureStage[i].m_AlphaArg2 = D3DTA_DIFFUSE; + if (isUsingVertexAlpha) + { + m_ShadowState.m_TextureStage[i].m_AlphaOp = + isUsingConstantAlpha ? D3DTOP_MODULATE : D3DTOP_SELECTARG2; + } + else + { + m_ShadowState.m_TextureStage[i].m_AlphaOp = D3DTOP_SELECTARG1; + } + isUsingVertexAlpha = false; + isUsingConstantAlpha = false; + } + else + { + m_ShadowState.m_TextureStage[i].m_AlphaArg1 = D3DTA_CURRENT; + if (isUsingConstantAlpha) + { + m_ShadowState.m_TextureStage[i].m_AlphaArg2 = D3DTA_TFACTOR; + isUsingConstantAlpha = false; + } + else if (isUsingVertexAlpha) + { + m_ShadowState.m_TextureStage[i].m_AlphaArg2 = D3DTA_DIFFUSE; + isUsingVertexAlpha = false; + } + else + { + m_ShadowState.m_TextureStage[i].m_AlphaArg2 = D3DTA_DIFFUSE; + m_ShadowState.m_TextureStage[i].m_AlphaOp = D3DTOP_SELECTARG1; + } + } + } + } +} + + +//----------------------------------------------------------------------------- +// Sets up the texture stage state +//----------------------------------------------------------------------------- +void CShaderShadowDX8::ConfigureFVFVertexShader( unsigned int flags ) +{ + // For non-modulation, we can't really use the path below... + if (m_CustomTextureStageState) + { + ConfigureCustomFVFVertexShader( flags ); + return; + } + + // Deal with texture stage 0 + m_ShadowState.m_TextureStage[0].m_ColorArg1 = D3DTA_TEXTURE; + m_ShadowState.m_TextureStage[0].m_ColorArg2 = D3DTA_DIFFUSE; + m_ShadowState.m_TextureStage[0].m_AlphaArg1 = D3DTA_TEXTURE; + m_ShadowState.m_TextureStage[0].m_AlphaArg2 = D3DTA_DIFFUSE; + + // Are we using color? + bool isUsingVertexColor = (flags & SHADER_DRAW_COLOR) != 0; + bool isUsingConstantColor = (flags & SHADER_HAS_CONSTANT_COLOR) != 0; + + // Are we using texture coordinates? + if ( IsUsingTextureCoordinates( SHADER_SAMPLER0 ) ) + { + if (isUsingVertexColor) + { + m_ShadowState.m_TextureStage[0].m_ColorOp = OverbrightBlendValue(SHADER_TEXTURE_STAGE0); + m_ShadowState.m_TextureStage[0].m_AlphaOp = D3DTOP_MODULATE; + } + else + { + // Just blend in the constant color here, and don't blend it in below + m_ShadowState.m_TextureStage[0].m_ColorArg2 = D3DTA_TFACTOR; + m_ShadowState.m_TextureStage[0].m_AlphaArg2 = D3DTA_TFACTOR; + isUsingConstantColor = false; + + m_ShadowState.m_TextureStage[0].m_ColorOp = OverbrightBlendValue(SHADER_TEXTURE_STAGE0); + m_ShadowState.m_TextureStage[0].m_AlphaOp = D3DTOP_MODULATE; + } + } + else + { + // Are we using color? + if (isUsingVertexColor) + { + // Color, but no texture + if ( m_TextureStage[0].m_OverbrightVal < 2.0f ) + { + // Use diffuse * constant color, if we have a constant color + if (isUsingConstantColor) + { + m_ShadowState.m_TextureStage[0].m_ColorArg1 = D3DTA_TFACTOR; + m_ShadowState.m_TextureStage[0].m_AlphaArg1 = D3DTA_TFACTOR; + m_ShadowState.m_TextureStage[0].m_ColorOp = OverbrightBlendValue((TextureStage_t)0); + m_ShadowState.m_TextureStage[0].m_AlphaOp = D3DTOP_MODULATE; + + // This'll make sure we don't apply the constant color again below + isUsingConstantColor = false; + } + else + { + m_ShadowState.m_TextureStage[0].m_ColorOp = D3DTOP_SELECTARG2; + m_ShadowState.m_TextureStage[0].m_AlphaOp = D3DTOP_SELECTARG2; + } + } + else if (m_TextureStage[0].m_OverbrightVal < 4.0f) + { + // Produce diffuse + diffuse + m_ShadowState.m_TextureStage[0].m_ColorArg1 = D3DTA_DIFFUSE; + m_ShadowState.m_TextureStage[0].m_ColorOp = D3DTOP_ADD; + m_ShadowState.m_TextureStage[0].m_AlphaOp = D3DTOP_SELECTARG2; + } + else + { + // no 4x overbright yet! + Assert(0); + } + } + else + { + // No texture, no color + if (isUsingConstantColor) + { + m_ShadowState.m_TextureStage[0].m_ColorArg1 = D3DTA_TFACTOR; + m_ShadowState.m_TextureStage[0].m_AlphaArg1 = D3DTA_TFACTOR; + m_ShadowState.m_TextureStage[0].m_ColorOp = D3DTOP_SELECTARG1; + m_ShadowState.m_TextureStage[0].m_AlphaOp = D3DTOP_SELECTARG1; + + // This'll make sure we don't apply the constant color again below + isUsingConstantColor = false; + } + else + { + // Deal with texture stage 0 + m_ShadowState.m_TextureStage[0].m_ColorArg1 = D3DTA_TFACTOR; + m_ShadowState.m_TextureStage[0].m_AlphaArg1 = D3DTA_TFACTOR; + m_ShadowState.m_TextureStage[0].m_ColorOp = D3DTOP_SELECTARG1; + m_ShadowState.m_TextureStage[0].m_AlphaOp = D3DTOP_SELECTARG1; + } + } + } + + // Deal with texture stage 1 -> n + int lastUsedTextureStage = 0; + for ( int i = 1; i < m_pHardwareConfig->GetTextureStageCount(); ++i ) + { + m_ShadowState.m_TextureStage[i].m_ColorArg1 = D3DTA_TEXTURE; + m_ShadowState.m_TextureStage[i].m_ColorArg2 = D3DTA_CURRENT; + m_ShadowState.m_TextureStage[i].m_AlphaArg1 = D3DTA_TEXTURE; + m_ShadowState.m_TextureStage[i].m_AlphaArg2 = D3DTA_CURRENT; + + // Not doing anything? Disable the stage + if ( !IsUsingTextureCoordinates( (Sampler_t)i ) ) + { + if (m_TextureStage[i].m_OverbrightVal < 2.0f) + { + m_ShadowState.m_TextureStage[i].m_ColorOp = D3DTOP_DISABLE; + m_ShadowState.m_TextureStage[i].m_AlphaOp = D3DTOP_DISABLE; + } + else + { + // Here, we're modulating. Add in the constant color if we need to... + m_ShadowState.m_TextureStage[i].m_ColorArg1 = D3DTA_TFACTOR; + m_ShadowState.m_TextureStage[i].m_AlphaArg1 = D3DTA_TFACTOR; + + m_ShadowState.m_TextureStage[i].m_ColorOp = OverbrightBlendValue((TextureStage_t)i); + m_ShadowState.m_TextureStage[i].m_AlphaOp = D3DTOP_MODULATE; + + isUsingConstantColor = false; + lastUsedTextureStage = i; + } + } + else + { + // Here, we're modulating. Keep track of the last modulation stage, + // cause the constant color modulation comes in the stage after that + lastUsedTextureStage = i; + m_ShadowState.m_TextureStage[i].m_ColorOp = OverbrightBlendValue((TextureStage_t)i); + m_ShadowState.m_TextureStage[i].m_AlphaOp = D3DTOP_MODULATE; + } + } + + // massive amounts of suck: gotta overbright here if we really + // wanted to overbright stage0 but couldn't because of the add. + // This isn't totally correct, but there's no way around putting it here + // because we can't texture out of stage2 on low or medium end hardware + m_ShadowShaderState.m_ModulateConstantColor = false; + if (isUsingConstantColor) + { + ++lastUsedTextureStage; + + if (isUsingConstantColor && + (lastUsedTextureStage >= m_pHardwareConfig->GetTextureStageCount())) + { + // This is the case where we'd want to modulate in a particular texture + // stage, but we can't because there aren't enough. In this case, we're gonna + // need to do the modulation in the per-vertex color. + m_ShadowShaderState.m_ModulateConstantColor = true; + } + else + { + AssertOnce (lastUsedTextureStage < 2); + + // Here, we've got enough texture stages to do the modulation + m_ShadowState.m_TextureStage[lastUsedTextureStage].m_ColorArg1 = D3DTA_TFACTOR; + m_ShadowState.m_TextureStage[lastUsedTextureStage].m_ColorArg2 = D3DTA_CURRENT; + m_ShadowState.m_TextureStage[lastUsedTextureStage].m_AlphaArg1 = D3DTA_TFACTOR; + m_ShadowState.m_TextureStage[lastUsedTextureStage].m_AlphaArg2 = D3DTA_CURRENT; + m_ShadowState.m_TextureStage[lastUsedTextureStage].m_ColorOp = D3DTOP_MODULATE; + m_ShadowState.m_TextureStage[lastUsedTextureStage].m_AlphaOp = D3DTOP_MODULATE; + } + } + + // Overwrite the alpha stuff if we asked to independently control it + if (m_AlphaPipe) + { + ConfigureAlphaPipe( flags ); + } +} + + +//----------------------------------------------------------------------------- +// Makes sure we report if we're getting garbage. +//----------------------------------------------------------------------------- +void CShaderShadowDX8::DrawFlags( unsigned int flags ) +{ + m_DrawFlags = flags; + m_ShadowState.m_UsingFixedFunction = true; +} + + +//----------------------------------------------------------------------------- +// Compute texture coordinates +//----------------------------------------------------------------------------- +void CShaderShadowDX8::ConfigureTextureCoordinates( unsigned int flags ) +{ + // default... + for (int i = 0; i < m_pHardwareConfig->GetTextureStageCount(); ++i) + { + TextureCoordinate( (TextureStage_t)i, i ); + } + + if (flags & SHADER_DRAW_TEXCOORD0) + { + Assert( (flags & SHADER_DRAW_LIGHTMAP_TEXCOORD0) == 0 ); + TextureCoordinate( SHADER_TEXTURE_STAGE0, 0 ); + } + else if (flags & SHADER_DRAW_LIGHTMAP_TEXCOORD0) + { + TextureCoordinate( SHADER_TEXTURE_STAGE0, 1 ); + } + else if (flags & SHADER_DRAW_SECONDARY_TEXCOORD0 ) + { + TextureCoordinate( SHADER_TEXTURE_STAGE0, 2 ); + } + + if (flags & SHADER_DRAW_TEXCOORD1) + { + Assert( (flags & SHADER_DRAW_LIGHTMAP_TEXCOORD1) == 0 ); + TextureCoordinate( SHADER_TEXTURE_STAGE1, 0 ); + } + else if (flags & SHADER_DRAW_LIGHTMAP_TEXCOORD1) + { + TextureCoordinate( SHADER_TEXTURE_STAGE1, 1 ); + } + else if (flags & SHADER_DRAW_SECONDARY_TEXCOORD1 ) + { + TextureCoordinate( SHADER_TEXTURE_STAGE1, 2 ); + } +} + + +//----------------------------------------------------------------------------- +// Converts draw flags into vertex format +//----------------------------------------------------------------------------- +VertexFormat_t CShaderShadowDX8::FlagsToVertexFormat( int flags ) const +{ + // Flags -1 occurs when there's an error condition; + // we'll just give em the max space and let them fill it in. + int formatFlags = 0; + int texCoordSize[VERTEX_MAX_TEXTURE_COORDINATES] = { 0, 0, 0, 0, 0, 0, 0, 0 }; + int userDataSize = 0; + int numBones = 0; + + // Flags -1 occurs when there's an error condition; + // we'll just give em the max space and let them fill it in. + if (flags == -1) + { + formatFlags = VERTEX_POSITION | VERTEX_NORMAL | VERTEX_COLOR | + VERTEX_TANGENT_S | VERTEX_TANGENT_T; + texCoordSize[0] = texCoordSize[1] = texCoordSize[2] = 2; + } + else + { + if (flags & SHADER_DRAW_POSITION) + formatFlags |= VERTEX_POSITION; + + if (flags & SHADER_DRAW_NORMAL) + formatFlags |= VERTEX_NORMAL; + + if (flags & SHADER_DRAW_COLOR) + formatFlags |= VERTEX_COLOR; + + if( flags & SHADER_DRAW_SPECULAR ) + formatFlags |= VERTEX_SPECULAR; + + if (flags & SHADER_TEXCOORD_MASK) + { + // normal texture coords into texture 0 + texCoordSize[0] = 2; + } + + if (flags & SHADER_LIGHTMAP_TEXCOORD_MASK) + { + // lightmaps go into texcoord 1 + texCoordSize[1] = 2; + } + + if (flags & SHADER_SECONDARY_TEXCOORD_MASK) + { + // any texgen, or secondary texture coordinate is put into texcoord 2 + texCoordSize[2] = 2; + } + } + + // Hardware skinning... always store space for up to 3 bones + // and always assume index blend enabled if available + if (m_ShadowState.m_VertexBlendEnable) + { + if (HardwareConfig()->MaxBlendMatrixIndices() > 0) + formatFlags |= VERTEX_BONE_INDEX; + + if (HardwareConfig()->MaxBlendMatrices() > 2) + numBones = 2; // the third bone weight is implied + else + numBones = HardwareConfig()->MaxBlendMatrices() - 1; + } + + return MeshMgr()->ComputeVertexFormat( formatFlags, VERTEX_MAX_TEXTURE_COORDINATES, + texCoordSize, numBones, userDataSize ); +} + + +//----------------------------------------------------------------------------- +// Computes shadow state based on bunches of other parameters +//----------------------------------------------------------------------------- +void CShaderShadowDX8::ComputeAggregateShadowState( ) +{ + unsigned int flags = 0; + + // Initialize the texture stage usage; this may get changed later + for (int i = 0; i < m_pHardwareConfig->GetSamplerCount(); ++i) + { + m_ShadowState.m_SamplerState[i].m_TextureEnable = + IsUsingTextureCoordinates( (Sampler_t)i ); + + // Deal with the alpha pipe + if ( m_ShadowState.m_UsingFixedFunction && m_AlphaPipe ) + { + if ( m_TextureStage[i].m_TextureAlphaEnable ) + { + m_ShadowState.m_SamplerState[i].m_TextureEnable = true; + } + } + } + + // Always use the same alpha src + dest if it's disabled + // NOTE: This is essential for stateblocks to work + if ( m_ShadowState.m_AlphaBlendEnable ) + { + m_ShadowState.m_SrcBlend = m_SrcBlend; + m_ShadowState.m_DestBlend = m_DestBlend; + m_ShadowState.m_BlendOp = m_BlendOp; + } + else + { + m_ShadowState.m_SrcBlend = D3DBLEND_ONE; + m_ShadowState.m_DestBlend = D3DBLEND_ZERO; + m_ShadowState.m_BlendOp = D3DBLENDOP_ADD; + } + + // GR + if (m_ShadowState.m_SeparateAlphaBlendEnable) + { + m_ShadowState.m_SrcBlendAlpha = m_SrcBlendAlpha; + m_ShadowState.m_DestBlendAlpha = m_DestBlendAlpha; + m_ShadowState.m_BlendOpAlpha = m_BlendOpAlpha; + } + else + { + m_ShadowState.m_SrcBlendAlpha = D3DBLEND_ONE; + m_ShadowState.m_DestBlendAlpha = D3DBLEND_ZERO; + m_ShadowState.m_BlendOpAlpha = D3DBLENDOP_ADD; + } + + // Use the same func if it's disabled + if (m_ShadowState.m_AlphaTestEnable) + { + // If alpha test is enabled, just use the values set + m_ShadowState.m_AlphaFunc = m_AlphaFunc; + m_ShadowState.m_AlphaRef = m_AlphaRef; + } + else + { + // A default value + m_ShadowState.m_AlphaFunc = D3DCMP_GREATEREQUAL; + m_ShadowState.m_AlphaRef = 0; + + // If not alpha testing and doing a standard alpha blend, force on alpha testing + if ( m_ShadowState.m_AlphaBlendEnable ) + { + if ( ( m_ShadowState.m_SrcBlend == D3DBLEND_SRCALPHA ) && ( m_ShadowState.m_DestBlend == D3DBLEND_INVSRCALPHA ) ) + { + m_ShadowState.m_AlphaFunc = D3DCMP_GREATEREQUAL; + m_ShadowState.m_AlphaRef = 1; + } + } + } + if ( m_ShadowState.m_UsingFixedFunction ) + { + flags = m_DrawFlags; + + // We need to take this bad boy into account + if (HasConstantColor()) + flags |= SHADER_HAS_CONSTANT_COLOR; + + // We need to take lighting into account.. + if ( m_ShadowState.m_Lighting ) + flags |= SHADER_DRAW_NORMAL; + + if (m_ShadowState.m_Lighting) + flags |= SHADER_DRAW_COLOR; + + // Look for inconsistency in the shadow state (can't have texgen & + // SHADER_DRAW_TEXCOORD or SHADER_DRAW_SECONDARY_TEXCOORD0 on the same stage) + if (flags & (SHADER_DRAW_TEXCOORD0 | SHADER_DRAW_SECONDARY_TEXCOORD0)) + { + Assert( (m_ShadowState.m_TextureStage[0].m_TexCoordIndex & 0xFFFF0000) == 0 ); + } + if (flags & (SHADER_DRAW_TEXCOORD1 | SHADER_DRAW_SECONDARY_TEXCOORD1)) + { + Assert( (m_ShadowState.m_TextureStage[1].m_TexCoordIndex & 0xFFFF0000) == 0 ); + } + if (flags & (SHADER_DRAW_TEXCOORD2 | SHADER_DRAW_SECONDARY_TEXCOORD2)) + { + Assert( (m_ShadowState.m_TextureStage[2].m_TexCoordIndex & 0xFFFF0000) == 0 ); + } + if (flags & (SHADER_DRAW_TEXCOORD3 | SHADER_DRAW_SECONDARY_TEXCOORD3)) + { + Assert( (m_ShadowState.m_TextureStage[3].m_TexCoordIndex & 0xFFFF0000) == 0 ); + } + + // Vertex usage has already been set for pixel + vertex shaders + m_ShadowShaderState.m_VertexUsage = FlagsToVertexFormat( flags ); + + // Configure the texture stages + ConfigureFVFVertexShader(flags); + +#if 0 +//#ifdef _DEBUG + // NOTE: This must be true for stateblocks to work + for ( i = 0; i < m_pHardwareConfig->GetTextureStageCount(); ++i ) + { + if ( m_ShadowState.m_TextureStage[i].m_ColorOp == D3DTOP_DISABLE ) + { + Assert( m_ShadowState.m_TextureStage[i].m_ColorArg1 == D3DTA_TEXTURE ); + Assert( m_ShadowState.m_TextureStage[i].m_ColorArg2 == ((i == 0) ? D3DTA_DIFFUSE : D3DTA_CURRENT) ); + } + + if ( m_ShadowState.m_TextureStage[i].m_AlphaOp == D3DTOP_DISABLE ) + { + Assert( m_ShadowState.m_TextureStage[i].m_AlphaArg1 == D3DTA_TEXTURE ); + Assert( m_ShadowState.m_TextureStage[i].m_AlphaArg2 == ((i == 0) ? D3DTA_DIFFUSE : D3DTA_CURRENT) ); + } + } +#endif + } + else + { + // Pixel shaders, disable everything so as to prevent unnecessary state changes.... + for ( int i = 0; i < m_pHardwareConfig->GetTextureStageCount(); ++i ) + { + m_ShadowState.m_TextureStage[i].m_ColorArg1 = D3DTA_TEXTURE; + m_ShadowState.m_TextureStage[i].m_ColorArg2 = (i == 0) ? D3DTA_DIFFUSE : D3DTA_CURRENT; + m_ShadowState.m_TextureStage[i].m_AlphaArg1 = D3DTA_TEXTURE; + m_ShadowState.m_TextureStage[i].m_AlphaArg2 = (i == 0) ? D3DTA_DIFFUSE : D3DTA_CURRENT; + m_ShadowState.m_TextureStage[i].m_ColorOp = D3DTOP_DISABLE; + m_ShadowState.m_TextureStage[i].m_AlphaOp = D3DTOP_DISABLE; + m_ShadowState.m_TextureStage[i].m_TexCoordIndex = i; + } + m_ShadowState.m_Lighting = false; + m_ShadowState.m_SpecularEnable = false; + m_ShadowState.m_VertexBlendEnable = false; + m_ShadowShaderState.m_ModulateConstantColor = false; + } + + // Compute texture coordinates + ConfigureTextureCoordinates(flags); + + // Alpha to coverage + if ( m_ShadowState.m_EnableAlphaToCoverage ) + { + // Only allow this to be enabled if blending is disabled and testing is enabled + if ( ( m_ShadowState.m_AlphaBlendEnable == true ) || ( m_ShadowState.m_AlphaTestEnable == false ) ) + { + m_ShadowState.m_EnableAlphaToCoverage = false; + } + } +} + +void CShaderShadowDX8::FogMode( ShaderFogMode_t fogMode ) +{ + Assert( fogMode >= 0 && fogMode < SHADER_FOGMODE_NUMFOGMODES ); + m_ShadowState.m_FogMode = fogMode; +} + +void CShaderShadowDX8::DisableFogGammaCorrection( bool bDisable ) +{ + m_ShadowState.m_bDisableFogGammaCorrection = bDisable; +} + +void CShaderShadowDX8::SetDiffuseMaterialSource( ShaderMaterialSource_t materialSource ) +{ + COMPILE_TIME_ASSERT( ( int )D3DMCS_MATERIAL == ( int )SHADER_MATERIALSOURCE_MATERIAL ); + COMPILE_TIME_ASSERT( ( int )D3DMCS_COLOR1 == ( int )SHADER_MATERIALSOURCE_COLOR1 ); + COMPILE_TIME_ASSERT( ( int )D3DMCS_COLOR2 == ( int )SHADER_MATERIALSOURCE_COLOR2 ); + Assert( materialSource == SHADER_MATERIALSOURCE_MATERIAL || + materialSource == SHADER_MATERIALSOURCE_COLOR1 || + materialSource == SHADER_MATERIALSOURCE_COLOR2 ); + m_ShadowState.m_DiffuseMaterialSource = ( D3DMATERIALCOLORSOURCE )materialSource; +} diff --git a/materialsystem/shaderapidx9/shadershadowdx8.h b/materialsystem/shaderapidx9/shadershadowdx8.h new file mode 100644 index 0000000..09b16ae --- /dev/null +++ b/materialsystem/shaderapidx9/shadershadowdx8.h @@ -0,0 +1,176 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +// +//===========================================================================// + +#ifndef SHADERSHADOWDX8_H +#define SHADERSHADOWDX8_H + +#ifdef _WIN32 +#pragma once +#endif + +#include "togl/rendermechanism.h" +#include "locald3dtypes.h" +#include "shaderapi/ishadershadow.h" + +class IShaderAPIDX8; + + +//----------------------------------------------------------------------------- +// Important enumerations +//----------------------------------------------------------------------------- +enum +{ + MAX_SAMPLERS = 16, + MAX_TEXTURE_STAGES = 16, +}; + + +//----------------------------------------------------------------------------- +// A structure maintaining the shadowed board state +//----------------------------------------------------------------------------- +struct TextureStageShadowState_t +{ + // State shadowing affects these + D3DTEXTUREOP m_ColorOp; + int m_ColorArg1; + int m_ColorArg2; + D3DTEXTUREOP m_AlphaOp; + int m_AlphaArg1; + int m_AlphaArg2; + int m_TexCoordIndex; +}; + +struct SamplerShadowState_t +{ + bool m_TextureEnable : 1; + bool m_SRGBReadEnable : 1; + bool m_Fetch4Enable : 1; + bool m_ShadowFilterEnable : 1; +}; + +struct ShadowState_t +{ + // Depth buffering state + D3DCMPFUNC m_ZFunc; + D3DZBUFFERTYPE m_ZEnable; + + // Write enable + DWORD m_ColorWriteEnable; + + // Fill mode + D3DFILLMODE m_FillMode; + + // Alpha state + D3DBLEND m_SrcBlend; + D3DBLEND m_DestBlend; + D3DBLENDOP m_BlendOp; + + // Separate alpha blend state + D3DBLEND m_SrcBlendAlpha; + D3DBLEND m_DestBlendAlpha; + D3DBLENDOP m_BlendOpAlpha; + + D3DCMPFUNC m_AlphaFunc; + int m_AlphaRef; + + // Texture stage state + TextureStageShadowState_t m_TextureStage[MAX_TEXTURE_STAGES]; + + // Sampler state + SamplerShadowState_t m_SamplerState[MAX_SAMPLERS]; + + ShaderFogMode_t m_FogMode; + + D3DMATERIALCOLORSOURCE m_DiffuseMaterialSource; + + unsigned char m_ZWriteEnable:1; + unsigned char m_ZBias:2; + // Cull State? + unsigned char m_CullEnable:1; + // Lighting in hardware? + unsigned char m_Lighting:1; + unsigned char m_SpecularEnable:1; + unsigned char m_AlphaBlendEnable:1; + unsigned char m_AlphaTestEnable:1; + + // Fixed function? + unsigned char m_UsingFixedFunction:1; + // Vertex blending? + unsigned char m_VertexBlendEnable:1; + // Auto-convert from linear to gamma upon writing to the frame buffer? + unsigned char m_SRGBWriteEnable:1; + // Seperate Alpha Blend? + unsigned char m_SeparateAlphaBlendEnable:1; + // Stencil? + unsigned char m_StencilEnable:1; + + unsigned char m_bDisableFogGammaCorrection:1; + + unsigned char m_EnableAlphaToCoverage:1; + + unsigned char m_Reserved : 1; + unsigned short m_nReserved2; +}; + + +//----------------------------------------------------------------------------- +// These are part of the "shadow" since they describe the shading algorithm +// but aren't actually captured in the state transition table +// because it would produce too many transitions +//----------------------------------------------------------------------------- +struct ShadowShaderState_t +{ + // The vertex + pixel shader group to use... + VertexShader_t m_VertexShader; + PixelShader_t m_PixelShader; + + // The static vertex + pixel shader indices + int m_nStaticVshIndex; + int m_nStaticPshIndex; + + // Vertex data used by this snapshot + // Note that the vertex format actually used will be the + // aggregate of the vertex formats used by all snapshots in a material + VertexFormat_t m_VertexUsage; + + // Morph data used by this snapshot + // Note that the morph format actually used will be the + // aggregate of the morph formats used by all snapshots in a material + MorphFormat_t m_MorphUsage; + + // Modulate constant color into the vertex color + bool m_ModulateConstantColor; + + bool m_nReserved[3]; +}; + + +//----------------------------------------------------------------------------- +// The shader setup API +//----------------------------------------------------------------------------- +abstract_class IShaderShadowDX8 : public IShaderShadow +{ +public: + // Initializes it + virtual void Init() = 0; + + // Gets at the shadow state + virtual ShadowState_t const& GetShadowState() = 0; + virtual ShadowShaderState_t const& GetShadowShaderState() = 0; + + // This must be called right before taking a snapshot + virtual void ComputeAggregateShadowState( ) = 0; + + // Class factory methods + static IShaderShadowDX8* Create( IShaderAPIDX8* pShaderAPIDX8 ); + static void Destroy( IShaderShadowDX8* pShaderShadow ); +}; + +extern IShaderShadowDX8 *g_pShaderShadowDx8; + +#endif // SHADERSHADOWDX8_H diff --git a/materialsystem/shaderapidx9/stubd3ddevice.h b/materialsystem/shaderapidx9/stubd3ddevice.h new file mode 100644 index 0000000..a97f015 --- /dev/null +++ b/materialsystem/shaderapidx9/stubd3ddevice.h @@ -0,0 +1,809 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//=============================================================================// + +#ifndef STUBD3DDEVICE_H +#define STUBD3DDEVICE_H +#ifdef _WIN32 +#pragma once +#endif + +#ifdef STUBD3D + +#include "locald3dtypes.h" +#include "filesystem.h" + +#ifdef USE_FOPEN +#include +#define FPRINTF fprintf +#else +#define FPRINTF s_pFileSystem->FPrintf +#endif + +#ifdef USE_FOPEN + +static FILE *s_FileHandle; + +#else + +static IFileSystem *s_pFileSystem; +static FileHandle_t s_FileHandle; + +#endif + + + +class CStubD3DTexture : public IDirect3DTexture8 +{ +private: + IDirect3DTexture8 *m_pTexture; + IDirect3DDevice8 *m_pDevice; + +public: + CStubD3DTexture( IDirect3DTexture8 *pTexture, IDirect3DDevice8 *pDevice ) + { + m_pTexture = pTexture; + m_pDevice = pDevice; + } + + /*** IUnknown methods ***/ + HRESULT __stdcall QueryInterface(REFIID riid, void** ppvObj) + { + FPRINTF( s_FileHandle, "IDirect3DTexture8::QueryInterface\n" ); + return m_pTexture->QueryInterface( riid, ppvObj ); + } + + ULONG __stdcall AddRef() + { + FPRINTF( s_FileHandle, "IDirect3DTexture8::AddRef\n" ); + return m_pTexture->AddRef(); + } + + ULONG __stdcall Release() + { + FPRINTF( s_FileHandle, "IDirect3DTexture8::Release\n" ); + return m_pTexture->Release(); + } + + /*** IDirect3DBaseTexture8 methods ***/ + HRESULT __stdcall GetDevice( IDirect3DDevice8** ppDevice ) + { + FPRINTF( s_FileHandle, "IDirect3DTexture8::GetDevice\n" ); +#if 0 + *ppDevice = m_pDevice; + return D3D_OK; +#else + return m_pTexture->GetDevice( ppDevice ); +#endif + } + + HRESULT __stdcall SetPrivateData( REFGUID refguid,CONST void* pData,DWORD SizeOfData,DWORD Flags) + { + FPRINTF( s_FileHandle, "IDirect3DTexture8::SetPrivateData\n" ); + return m_pTexture->SetPrivateData( refguid, pData, SizeOfData, Flags ); + } + + HRESULT __stdcall GetPrivateData( REFGUID refguid,void* pData,DWORD* pSizeOfData ) + { + FPRINTF( s_FileHandle, "IDirect3DTexture8::GetPrivateData\n" ); + return m_pTexture->GetPrivateData( refguid, pData, pSizeOfData ); + } + + HRESULT __stdcall FreePrivateData( REFGUID refguid ) + { + FPRINTF( s_FileHandle, "IDirect3DTexture8::GetPrivateData\n" ); + return m_pTexture->FreePrivateData( refguid ); + } + + DWORD __stdcall SetPriority( DWORD PriorityNew ) + { + FPRINTF( s_FileHandle, "IDirect3DTexture8::SetPriority\n" ); + return m_pTexture->SetPriority( PriorityNew ); + } + + DWORD __stdcall GetPriority() + { + FPRINTF( s_FileHandle, "IDirect3DTexture8::GetPriority\n" ); + return m_pTexture->GetPriority(); + } + + void __stdcall PreLoad() + { + FPRINTF( s_FileHandle, "IDirect3DTexture8::PreLoad\n" ); + m_pTexture->PreLoad(); + } + + D3DRESOURCETYPE __stdcall GetType() + { + FPRINTF( s_FileHandle, "IDirect3DTexture8::GetType\n" ); + return m_pTexture->GetType(); + } + + DWORD __stdcall SetLOD( DWORD LODNew ) + { + FPRINTF( s_FileHandle, "IDirect3DTexture8::SetLOD\n" ); + return m_pTexture->SetLOD( LODNew ); + } + + DWORD __stdcall GetLOD() + { + FPRINTF( s_FileHandle, "IDirect3DTexture8::GetLOD\n" ); + return m_pTexture->GetLOD(); + } + + DWORD __stdcall GetLevelCount() + { + FPRINTF( s_FileHandle, "IDirect3DTexture8::GetLevelCount\n" ); + return m_pTexture->GetLevelCount(); + } + + HRESULT __stdcall GetLevelDesc(UINT Level,D3DSURFACE_DESC *pDesc) + { + FPRINTF( s_FileHandle, "IDirect3DTexture8::GetLevelCount\n" ); + return m_pTexture->GetLevelDesc( Level, pDesc ); + } + + HRESULT __stdcall GetSurfaceLevel(UINT Level,IDirect3DSurface8** ppSurfaceLevel) + { + FPRINTF( s_FileHandle, "IDirect3DTexture8::GetSurfaceLevel\n" ); + return m_pTexture->GetSurfaceLevel( Level, ppSurfaceLevel ); + } + + HRESULT __stdcall LockRect(UINT Level,D3DLOCKED_RECT* pLockedRect,CONST RECT* pRect,DWORD Flags) + { + FPRINTF( s_FileHandle, "IDirect3DTexture8::LockRect\n" ); + return m_pTexture->LockRect( Level, pLockedRect, pRect, Flags ); + } + + HRESULT __stdcall UnlockRect(UINT Level) + { + FPRINTF( s_FileHandle, "IDirect3DTexture8::UnlockRect\n" ); + return m_pTexture->UnlockRect( Level ); + } + + HRESULT __stdcall AddDirtyRect( CONST RECT* pDirtyRect ) + { + FPRINTF( s_FileHandle, "IDirect3DTexture8::AddDirtyRect\n" ); + return m_pTexture->AddDirtyRect( pDirtyRect ); + } +}; + +class CStubD3DDevice : public IDirect3DDevice8 +{ +public: + CStubD3DDevice( IDirect3DDevice8 *pD3DDevice, IFileSystem *pFileSystem ) + { + Assert( pD3DDevice ); + m_pD3DDevice = pD3DDevice; +#ifdef USE_FOPEN + s_FileHandle = fopen( "stubd3d.txt", "w" ); +#else + Assert( pFileSystem ); + s_pFileSystem = pFileSystem; + s_FileHandle = pFileSystem->Open( "stubd3d.txt", "w" ); +#endif + } + + ~CStubD3DDevice() + { +#ifdef USE_FOPEN + fclose( s_FileHandle ); +#else + s_pFileSystem->Close( s_FileHandle ); +#endif + } + +private: + IDirect3DDevice8 *m_pD3DDevice; + +public: + /*** IUnknown methods ***/ + HRESULT __stdcall QueryInterface(REFIID riid, void** ppvObj) + { + FPRINTF( s_FileHandle, "QueryInterface\n" ); + return m_pD3DDevice->QueryInterface( riid, ppvObj ); + } + + ULONG __stdcall AddRef() + { + FPRINTF( s_FileHandle, "AddRef\n" ); + return m_pD3DDevice->AddRef(); + } + + ULONG __stdcall Release() + { + FPRINTF( s_FileHandle, "Release\n" ); + return m_pD3DDevice->Release(); + delete this; + } + + /*** IDirect3DDevice8 methods ***/ + HRESULT __stdcall TestCooperativeLevel() + { + FPRINTF( s_FileHandle, "TestCooperativeLevel\n" ); + return m_pD3DDevice->TestCooperativeLevel(); + } + + UINT __stdcall GetAvailableTextureMem() + { + FPRINTF( s_FileHandle, "GetAvailableTextureMem\n" ); + return m_pD3DDevice->GetAvailableTextureMem(); + } + + HRESULT __stdcall ResourceManagerDiscardBytes(DWORD Bytes) + { + FPRINTF( s_FileHandle, "ResourceManagerDiscardBytes\n" ); + return m_pD3DDevice->ResourceManagerDiscardBytes( Bytes ); + } + + HRESULT __stdcall GetDirect3D(IDirect3D8** ppD3D8) + { + FPRINTF( s_FileHandle, "GetDirect3D\n" ); + return m_pD3DDevice->GetDirect3D( ppD3D8 ); + } + + HRESULT __stdcall GetDeviceCaps(D3DCAPS8* pCaps) + { + FPRINTF( s_FileHandle, "GetDeviceCaps\n" ); + return m_pD3DDevice->GetDeviceCaps( pCaps ); + } + + HRESULT __stdcall GetDisplayMode(D3DDISPLAYMODE* pMode) + { + FPRINTF( s_FileHandle, "GetDisplayMode\n" ); + return m_pD3DDevice->GetDisplayMode( pMode ); + } + + HRESULT __stdcall GetCreationParameters(D3DDEVICE_CREATION_PARAMETERS *pParameters) + { + FPRINTF( s_FileHandle, "GetCreationParameters\n" ); + return m_pD3DDevice->GetCreationParameters( pParameters ); + } + + HRESULT __stdcall SetCursorProperties(UINT XHotSpot,UINT YHotSpot,IDirect3DSurface8* pCursorBitmap) + { + FPRINTF( s_FileHandle, "SetCursorProperties\n" ); + return m_pD3DDevice->SetCursorProperties( XHotSpot, YHotSpot, pCursorBitmap ); + } + + void __stdcall SetCursorPosition(UINT XScreenSpace,UINT YScreenSpace,DWORD Flags) + { + FPRINTF( s_FileHandle, "SetCursorPosition\n" ); + m_pD3DDevice->SetCursorPosition( XScreenSpace, YScreenSpace, Flags ); + } + + BOOL __stdcall ShowCursor(BOOL bShow) + { + FPRINTF( s_FileHandle, "ShowCursor\n" ); + return m_pD3DDevice->ShowCursor( bShow ); + } + + HRESULT __stdcall CreateAdditionalSwapChain(D3DPRESENT_PARAMETERS* pPresentationParameters,IDirect3DSwapChain8** pSwapChain) + { + FPRINTF( s_FileHandle, "CreateAdditionalSwapChain\n" ); + return m_pD3DDevice->CreateAdditionalSwapChain( pPresentationParameters, pSwapChain ); + } + + HRESULT __stdcall Reset(D3DPRESENT_PARAMETERS* pPresentationParameters) + { + FPRINTF( s_FileHandle, "Reset\n" ); + return m_pD3DDevice->Reset( pPresentationParameters ); + } + + HRESULT __stdcall Present(CONST RECT* pSourceRect,CONST RECT* pDestRect,HWND hDestWindowOverride,CONST RGNDATA* pDirtyRegion) + { + FPRINTF( s_FileHandle, "Present\n" ); + return m_pD3DDevice->Present( pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion ); + } + + HRESULT __stdcall GetBackBuffer(UINT BackBuffer,D3DBACKBUFFER_TYPE Type,IDirect3DSurface8** ppBackBuffer) + { + FPRINTF( s_FileHandle, "GetBackBuffer\n" ); + return m_pD3DDevice->GetBackBuffer( BackBuffer, Type, ppBackBuffer ); + } + + HRESULT __stdcall GetRasterStatus(D3DRASTER_STATUS* pRasterStatus) + { + FPRINTF( s_FileHandle, "GetRasterStatus\n" ); + return m_pD3DDevice->GetRasterStatus( pRasterStatus ); + } + + void __stdcall SetGammaRamp(DWORD Flags,CONST D3DGAMMARAMP* pRamp) + { + FPRINTF( s_FileHandle, "SetGammaRamp\n" ); + m_pD3DDevice->SetGammaRamp( Flags, pRamp ); + } + + void __stdcall GetGammaRamp(D3DGAMMARAMP* pRamp) + { + FPRINTF( s_FileHandle, "GetGammaRamp\n" ); + m_pD3DDevice->GetGammaRamp( pRamp ); + } + + HRESULT __stdcall CreateTexture(UINT Width,UINT Height,UINT Levels,DWORD Usage,D3DFORMAT Format,D3DPOOL Pool,IDirect3DTexture8** ppTexture) + { + FPRINTF( s_FileHandle, "CreateTexture\n" ); +#if 0 + HRESULT ret = m_pD3DDevice->CreateTexture( Width, Height, Levels, Usage, Format, Pool, ppTexture ); + if( ret == D3D_OK ) + { + *ppTexture = new CStubD3DTexture( *ppTexture, this ); + return ret; + } + else + { + return ret; + } +#else + return m_pD3DDevice->CreateTexture( Width, Height, Levels, Usage, Format, Pool, ppTexture ); +#endif + } + + HRESULT __stdcall CreateVolumeTexture(UINT Width,UINT Height,UINT Depth,UINT Levels,DWORD Usage,D3DFORMAT Format,D3DPOOL Pool,IDirect3DVolumeTexture8** ppVolumeTexture) + { + FPRINTF( s_FileHandle, "CreateVolumeTexture\n" ); + return m_pD3DDevice->CreateVolumeTexture( Width, Height, Depth, Levels, Usage, Format, Pool, ppVolumeTexture ); + } + + HRESULT __stdcall CreateCubeTexture(UINT EdgeLength,UINT Levels,DWORD Usage,D3DFORMAT Format,D3DPOOL Pool,IDirect3DCubeTexture8** ppCubeTexture) + { + FPRINTF( s_FileHandle, "CreateCubeTexture\n" ); + return m_pD3DDevice->CreateCubeTexture( EdgeLength, Levels, Usage, Format, Pool, ppCubeTexture ); + } + + HRESULT __stdcall CreateVertexBuffer(UINT Length,DWORD Usage,DWORD FVF,D3DPOOL Pool,IDirect3DVertexBuffer8** ppVertexBuffer) + { + FPRINTF( s_FileHandle, "CreateVertexBuffer\n" ); + return m_pD3DDevice->CreateVertexBuffer( Length, Usage, FVF, Pool, ppVertexBuffer ); + } + + HRESULT __stdcall CreateIndexBuffer(UINT Length,DWORD Usage,D3DFORMAT Format,D3DPOOL Pool,IDirect3DIndexBuffer8** ppIndexBuffer) + { + FPRINTF( s_FileHandle, "CreateIndexBuffer\n" ); + return m_pD3DDevice->CreateIndexBuffer( Length, Usage, Format, Pool, ppIndexBuffer ); + } + + HRESULT __stdcall CreateRenderTarget(UINT Width,UINT Height,D3DFORMAT Format,D3DMULTISAMPLE_TYPE MultiSample,BOOL Lockable,IDirect3DSurface8** ppSurface) + { + FPRINTF( s_FileHandle, "CreateRenderTarget\n" ); + return m_pD3DDevice->CreateRenderTarget( Width, Height, Format, MultiSample, Lockable, ppSurface ); + } + + HRESULT __stdcall CreateDepthStencilSurface(UINT Width,UINT Height,D3DFORMAT Format,D3DMULTISAMPLE_TYPE MultiSample,IDirect3DSurface8** ppSurface) + { + FPRINTF( s_FileHandle, "CreateDepthStencilSurface\n" ); + return m_pD3DDevice->CreateDepthStencilSurface( Width, Height, Format, MultiSample, ppSurface ); + } + + HRESULT __stdcall CreateImageSurface(UINT Width,UINT Height,D3DFORMAT Format,IDirect3DSurface8** ppSurface) + { + FPRINTF( s_FileHandle, "CreateImageSurface\n" ); + return m_pD3DDevice->CreateImageSurface( Width, Height, Format, ppSurface ); + } + + HRESULT __stdcall CopyRects(IDirect3DSurface8* pSourceSurface,CONST RECT* pSourceRectsArray,UINT cRects,IDirect3DSurface8* pDestinationSurface,CONST POINT* pDestPointsArray) + { + FPRINTF( s_FileHandle, "CopyRects\n" ); + return m_pD3DDevice->CopyRects( pSourceSurface, pSourceRectsArray, cRects, pDestinationSurface, pDestPointsArray ); + } + + HRESULT __stdcall UpdateTexture(IDirect3DBaseTexture8* pSourceTexture,IDirect3DBaseTexture8* pDestinationTexture) + { + FPRINTF( s_FileHandle, "UpdateTexture\n" ); + return m_pD3DDevice->UpdateTexture( pSourceTexture, pDestinationTexture ); + } + + HRESULT __stdcall GetFrontBuffer(IDirect3DSurface8* pDestSurface) + { + FPRINTF( s_FileHandle, "GetFrontBuffer\n" ); + return m_pD3DDevice->GetFrontBuffer( pDestSurface ); + } + + HRESULT __stdcall SetRenderTarget(IDirect3DSurface8* pRenderTarget,IDirect3DSurface8* pNewZStencil) + { + FPRINTF( s_FileHandle, "SetRenderTarget\n" ); + return m_pD3DDevice->SetRenderTarget( pRenderTarget, pNewZStencil ); + } + + HRESULT __stdcall GetRenderTarget(IDirect3DSurface8** ppRenderTarget) + { + FPRINTF( s_FileHandle, "GetRenderTarget\n" ); + return m_pD3DDevice->GetRenderTarget( ppRenderTarget ); + } + + HRESULT __stdcall GetDepthStencilSurface(IDirect3DSurface8** ppZStencilSurface) + { + FPRINTF( s_FileHandle, "GetDepthStencilSurface\n" ); + return m_pD3DDevice->GetDepthStencilSurface( ppZStencilSurface ); + } + + HRESULT __stdcall BeginScene( void ) + { + FPRINTF( s_FileHandle, "BeginScene\n" ); + return m_pD3DDevice->BeginScene(); + } + + HRESULT __stdcall EndScene() + { + FPRINTF( s_FileHandle, "EndScene\n" ); + return m_pD3DDevice->EndScene(); + } + + HRESULT __stdcall Clear(DWORD Count,CONST D3DRECT* pRects,DWORD Flags,D3DCOLOR Color,float Z,DWORD Stencil) + { + FPRINTF( s_FileHandle, "Clear\n" ); + return m_pD3DDevice->Clear( Count, pRects, Flags, Color, Z, Stencil ); + } + + HRESULT __stdcall SetTransform(D3DTRANSFORMSTATETYPE State,CONST D3DMATRIX* pMatrix) + { + FPRINTF( s_FileHandle, "SetTransform\n" ); + return m_pD3DDevice->SetTransform( State, pMatrix ); + } + + HRESULT __stdcall GetTransform(D3DTRANSFORMSTATETYPE State,D3DMATRIX* pMatrix) + { + FPRINTF( s_FileHandle, "GetTransform\n" ); + return m_pD3DDevice->GetTransform( State, pMatrix ); + } + + HRESULT __stdcall MultiplyTransform(D3DTRANSFORMSTATETYPE transformState,CONST D3DMATRIX* pMatrix) + { + FPRINTF( s_FileHandle, "MultiplyTransform\n" ); + return m_pD3DDevice->MultiplyTransform( transformState, pMatrix ); + } + + HRESULT __stdcall SetViewport(CONST D3DVIEWPORT8* pViewport) + { + FPRINTF( s_FileHandle, "SetViewport\n" ); + return m_pD3DDevice->SetViewport( pViewport ); + } + + HRESULT __stdcall GetViewport(D3DVIEWPORT8* pViewport) + { + FPRINTF( s_FileHandle, "GetViewport\n" ); + return m_pD3DDevice->GetViewport( pViewport ); + } + + HRESULT __stdcall SetMaterial(CONST D3DMATERIAL8* pMaterial) + { + FPRINTF( s_FileHandle, "SetMaterial\n" ); + return m_pD3DDevice->SetMaterial( pMaterial ); + } + + HRESULT __stdcall GetMaterial(D3DMATERIAL8* pMaterial) + { + FPRINTF( s_FileHandle, "GetMaterial\n" ); + return m_pD3DDevice->GetMaterial( pMaterial ); + } + + HRESULT __stdcall SetLight(DWORD Index,CONST D3DLIGHT8* pLight) + { + FPRINTF( s_FileHandle, "SetLight\n" ); + return m_pD3DDevice->SetLight( Index, pLight ); + } + + HRESULT __stdcall GetLight(DWORD Index,D3DLIGHT8* pLight) + { + FPRINTF( s_FileHandle, "GetLight\n" ); + return m_pD3DDevice->GetLight( Index, pLight ); + } + + HRESULT __stdcall LightEnable(DWORD Index,BOOL Enable) + { + FPRINTF( s_FileHandle, "LightEnable\n" ); + return m_pD3DDevice->LightEnable( Index, Enable ); + } + + HRESULT __stdcall GetLightEnable(DWORD Index,BOOL* pEnable) + { + FPRINTF( s_FileHandle, "GetLightEnable\n" ); + return m_pD3DDevice->GetLightEnable( Index, pEnable ); + } + + HRESULT __stdcall SetClipPlane(DWORD Index,CONST float* pPlane) + { + FPRINTF( s_FileHandle, "SetClipPlane\n" ); + return m_pD3DDevice->SetClipPlane( Index, pPlane ); + } + + HRESULT __stdcall GetClipPlane(DWORD Index,float* pPlane) + { + FPRINTF( s_FileHandle, "GetClipPlane\n" ); + return m_pD3DDevice->GetClipPlane( Index, pPlane ); + } + + HRESULT __stdcall SetRenderState(D3DRENDERSTATETYPE State,DWORD Value) + { + FPRINTF( s_FileHandle, "SetRenderState\n" ); + return m_pD3DDevice->SetRenderState( State, Value ); + } + + HRESULT __stdcall GetRenderState(D3DRENDERSTATETYPE State,DWORD* pValue) + { + FPRINTF( s_FileHandle, "GetRenderState\n" ); + return m_pD3DDevice->GetRenderState( State, pValue ); + } + + HRESULT __stdcall BeginStateBlock(void) + { + FPRINTF( s_FileHandle, "BeginStateBlock\n" ); + return m_pD3DDevice->BeginStateBlock(); + } + + HRESULT __stdcall EndStateBlock(DWORD* pToken) + { + FPRINTF( s_FileHandle, "EndStateBlock\n" ); + return m_pD3DDevice->EndStateBlock( pToken ); + } + + HRESULT __stdcall ApplyStateBlock(DWORD Token) + { + FPRINTF( s_FileHandle, "ApplyStateBlock\n" ); + return m_pD3DDevice->ApplyStateBlock( Token ); + } + + HRESULT __stdcall CaptureStateBlock(DWORD Token) + { + FPRINTF( s_FileHandle, "CaptureStateBlock\n" ); + return m_pD3DDevice->CaptureStateBlock( Token ); + } + + HRESULT __stdcall DeleteStateBlock(DWORD Token) + { + FPRINTF( s_FileHandle, "DeleteStateBlock\n" ); + return m_pD3DDevice->DeleteStateBlock( Token ); + } + + HRESULT __stdcall CreateStateBlock(D3DSTATEBLOCKTYPE Type,DWORD* pToken) + { + FPRINTF( s_FileHandle, "CreateStateBlock\n" ); + return m_pD3DDevice->CreateStateBlock( Type, pToken ); + } + + HRESULT __stdcall SetClipStatus(CONST D3DCLIPSTATUS8* pClipStatus) + { + FPRINTF( s_FileHandle, "SetClipStatus\n" ); + return m_pD3DDevice->SetClipStatus( pClipStatus ); + } + + HRESULT __stdcall GetClipStatus(D3DCLIPSTATUS8* pClipStatus) + { + FPRINTF( s_FileHandle, "GetClipStatus\n" ); + return m_pD3DDevice->GetClipStatus( pClipStatus ); + } + + HRESULT __stdcall GetTexture(DWORD Stage,IDirect3DBaseTexture8** ppTexture) + { + FPRINTF( s_FileHandle, "GetTexture\n" ); + return m_pD3DDevice->GetTexture( Stage, ppTexture ); + } + + HRESULT __stdcall SetTexture(DWORD Stage,IDirect3DBaseTexture8* pTexture) + { + FPRINTF( s_FileHandle, "SetTexture\n" ); + return m_pD3DDevice->SetTexture( Stage, pTexture ); + } + + HRESULT __stdcall GetTextureStageState(DWORD Stage,D3DTEXTURESTAGESTATETYPE Type,DWORD* pValue) + { + FPRINTF( s_FileHandle, "GetTextureStageState\n" ); + return m_pD3DDevice->GetTextureStageState( Stage, Type, pValue ); + } + + HRESULT __stdcall SetTextureStageState(DWORD Stage,D3DTEXTURESTAGESTATETYPE Type,DWORD Value) + { + FPRINTF( s_FileHandle, "SetTextureStageState\n" ); + return m_pD3DDevice->SetTextureStageState( Stage, Type, Value ); + } + + HRESULT __stdcall ValidateDevice(DWORD* pNumPasses) + { + FPRINTF( s_FileHandle, "ValidateDevice\n" ); +#if 0 + return m_pD3DDevice->ValidateDevice( pNumPasses ); +#else + return D3D_OK; +#endif + } + + HRESULT __stdcall GetInfo(DWORD DevInfoID,void* pDevInfoStruct,DWORD DevInfoStructSize) + { + FPRINTF( s_FileHandle, "GetInfo\n" ); + return m_pD3DDevice->GetInfo( DevInfoID, pDevInfoStruct, DevInfoStructSize ); + } + + HRESULT __stdcall SetPaletteEntries(UINT PaletteNumber,CONST PALETTEENTRY* pEntries) + { + FPRINTF( s_FileHandle, "SetPaletteEntries\n" ); + return m_pD3DDevice->SetPaletteEntries( PaletteNumber, pEntries ); + } + + HRESULT __stdcall GetPaletteEntries(UINT PaletteNumber,PALETTEENTRY* pEntries) + { + FPRINTF( s_FileHandle, "GetPaletteEntries\n" ); + return m_pD3DDevice->GetPaletteEntries( PaletteNumber, pEntries ); + } + + HRESULT __stdcall SetCurrentTexturePalette(UINT PaletteNumber) + { + FPRINTF( s_FileHandle, "SetCurrentTexturePalette\n" ); + return m_pD3DDevice->SetCurrentTexturePalette( PaletteNumber ); + } + + HRESULT __stdcall GetCurrentTexturePalette(UINT *PaletteNumber) + { + FPRINTF( s_FileHandle, "GetCurrentTexturePalette\n" ); + return m_pD3DDevice->GetCurrentTexturePalette( PaletteNumber ); + } + + HRESULT __stdcall DrawPrimitive(D3DPRIMITIVETYPE PrimitiveType,UINT StartVertex,UINT PrimitiveCount) + { + FPRINTF( s_FileHandle, "DrawPrimitive\n" ); + return m_pD3DDevice->DrawPrimitive( PrimitiveType, StartVertex, PrimitiveCount ); + } + + HRESULT __stdcall DrawIndexedPrimitive(D3DPRIMITIVETYPE primitiveType,UINT minIndex,UINT NumVertices,UINT startIndex,UINT primCount) + { + FPRINTF( s_FileHandle, "DrawIndexedPrimitive\n" ); + return m_pD3DDevice->DrawIndexedPrimitive( primitiveType,minIndex,NumVertices,startIndex,primCount ); + } + + HRESULT __stdcall DrawPrimitiveUP(D3DPRIMITIVETYPE PrimitiveType,UINT PrimitiveCount,CONST void* pVertexStreamZeroData,UINT VertexStreamZeroStride) + { + FPRINTF( s_FileHandle, "DrawPrimitiveUP\n" ); + return m_pD3DDevice->DrawPrimitiveUP( PrimitiveType, PrimitiveCount, pVertexStreamZeroData, VertexStreamZeroStride ); + } + + HRESULT __stdcall DrawIndexedPrimitiveUP(D3DPRIMITIVETYPE PrimitiveType,UINT MinVertexIndex,UINT NumVertexIndices,UINT PrimitiveCount,CONST void* pIndexData,D3DFORMAT IndexDataFormat,CONST void* pVertexStreamZeroData,UINT VertexStreamZeroStride) + { + FPRINTF( s_FileHandle, "DrawIndexedPrimitiveUP\n" ); + return m_pD3DDevice->DrawIndexedPrimitiveUP( PrimitiveType, MinVertexIndex, NumVertexIndices, PrimitiveCount, pIndexData, IndexDataFormat,pVertexStreamZeroData, VertexStreamZeroStride ); + } + + HRESULT __stdcall ProcessVertices(UINT SrcStartIndex,UINT DestIndex,UINT VertexCount,IDirect3DVertexBuffer8* pDestBuffer,DWORD Flags) + { + FPRINTF( s_FileHandle, "ProcessVertices\n" ); + return m_pD3DDevice->ProcessVertices( SrcStartIndex, DestIndex, VertexCount, pDestBuffer, Flags ); + } + + HRESULT __stdcall CreateVertexShader(CONST DWORD* pDeclaration,CONST DWORD* pFunction,DWORD* pHandle,DWORD Usage) + { + FPRINTF( s_FileHandle, "CreateVertexShader\n" ); + return m_pD3DDevice->CreateVertexShader( pDeclaration, pFunction, pHandle, Usage ); + } + + HRESULT __stdcall SetVertexShader(DWORD Handle) + { + FPRINTF( s_FileHandle, "SetVertexShader\n" ); + return m_pD3DDevice->SetVertexShader( Handle ); + } + + HRESULT __stdcall GetVertexShader(DWORD* pHandle) + { + FPRINTF( s_FileHandle, "GetVertexShader\n" ); + return m_pD3DDevice->GetVertexShader( pHandle ); + } + + HRESULT __stdcall DeleteVertexShader(DWORD Handle) + { + FPRINTF( s_FileHandle, "DeleteVertexShader\n" ); + return m_pD3DDevice->DeleteVertexShader( Handle ); + } + + HRESULT __stdcall SetVertexShaderConstant(DWORD Register,CONST void* pConstantData,DWORD ConstantCount) + { + FPRINTF( s_FileHandle, "SetVertexShaderConstant\n" ); + return m_pD3DDevice->SetVertexShaderConstant( Register, pConstantData, ConstantCount ); + } + + HRESULT __stdcall GetVertexShaderConstant(DWORD Register,void* pConstantData,DWORD ConstantCount) + { + FPRINTF( s_FileHandle, "GetVertexShaderConstant\n" ); + return m_pD3DDevice->GetVertexShaderConstant( Register, pConstantData, ConstantCount ); + } + + HRESULT __stdcall GetVertexShaderDeclaration(DWORD Handle,void* pData,DWORD* pSizeOfData) + { + FPRINTF( s_FileHandle, "GetVertexShaderDeclaration\n" ); + return m_pD3DDevice->GetVertexShaderDeclaration( Handle, pData, pSizeOfData ); + } + + HRESULT __stdcall GetVertexShaderFunction(DWORD Handle,void* pData,DWORD* pSizeOfData) + { + FPRINTF( s_FileHandle, "GetVertexShaderFunction\n" ); + return m_pD3DDevice->GetVertexShaderFunction( Handle, pData, pSizeOfData ); + } + + HRESULT __stdcall SetStreamSource(UINT StreamNumber,IDirect3DVertexBuffer8* pStreamData,UINT Stride) + { + FPRINTF( s_FileHandle, "SetStreamSource\n" ); + return m_pD3DDevice->SetStreamSource( StreamNumber, pStreamData, Stride ); + } + + HRESULT __stdcall GetStreamSource(UINT StreamNumber,IDirect3DVertexBuffer8** ppStreamData,UINT* pStride) + { + FPRINTF( s_FileHandle, "GetStreamSource\n" ); + return m_pD3DDevice->GetStreamSource( StreamNumber, ppStreamData, pStride ); + } + + HRESULT __stdcall SetIndices(IDirect3DIndexBuffer8* pIndexData,UINT BaseVertexIndex) + { + FPRINTF( s_FileHandle, "SetIndices\n" ); + return m_pD3DDevice->SetIndices( pIndexData, BaseVertexIndex ); + } + + HRESULT __stdcall GetIndices(IDirect3DIndexBuffer8** ppIndexData,UINT* pBaseVertexIndex) + { + FPRINTF( s_FileHandle, "GetIndices\n" ); + return m_pD3DDevice->GetIndices( ppIndexData, pBaseVertexIndex ); + } + + HRESULT __stdcall CreatePixelShader(CONST DWORD* pFunction,DWORD* pHandle) + { + FPRINTF( s_FileHandle, "CreatePixelShader\n" ); + return m_pD3DDevice->CreatePixelShader( pFunction, pHandle ); + } + + HRESULT __stdcall SetPixelShader(DWORD Handle) + { + FPRINTF( s_FileHandle, "SetPixelShader\n" ); + return m_pD3DDevice->SetPixelShader( Handle ); + } + + HRESULT __stdcall GetPixelShader(DWORD* pHandle) + { + FPRINTF( s_FileHandle, "GetPixelShader\n" ); + return m_pD3DDevice->GetPixelShader( pHandle ); + } + + HRESULT __stdcall DeletePixelShader(DWORD Handle) + { + FPRINTF( s_FileHandle, "DeletePixelShader\n" ); + return m_pD3DDevice->DeletePixelShader( Handle ); + } + + HRESULT __stdcall SetPixelShaderConstant(DWORD Register,CONST void* pConstantData,DWORD ConstantCount) + { + FPRINTF( s_FileHandle, "SetPixelShaderConstant\n" ); + return m_pD3DDevice->SetPixelShaderConstant( Register, pConstantData, ConstantCount ); + } + + HRESULT __stdcall GetPixelShaderConstant(DWORD Register,void* pConstantData,DWORD ConstantCount) + { + FPRINTF( s_FileHandle, "GetPixelShaderConstant\n" ); + return m_pD3DDevice->GetPixelShaderConstant( Register, pConstantData, ConstantCount ); + } + + HRESULT __stdcall GetPixelShaderFunction(DWORD Handle,void* pData,DWORD* pSizeOfData) + { + FPRINTF( s_FileHandle, "GetPixelShaderFunction\n" ); + return m_pD3DDevice->GetPixelShaderFunction( Handle, pData, pSizeOfData ); + } + + HRESULT __stdcall DrawRectPatch(UINT Handle,CONST float* pNumSegs,CONST D3DRECTPATCH_INFO* pRectPatchInfo) + { + FPRINTF( s_FileHandle, "DrawRectPatch\n" ); + return m_pD3DDevice->DrawRectPatch( Handle, pNumSegs, pRectPatchInfo ); + } + + HRESULT __stdcall DrawTriPatch(UINT Handle,CONST float* pNumSegs,CONST D3DTRIPATCH_INFO* pTriPatchInfo) + { + FPRINTF( s_FileHandle, "DrawTriPatch\n" ); + return m_pD3DDevice->DrawTriPatch( Handle, pNumSegs, pTriPatchInfo ); + } + + HRESULT __stdcall DeletePatch(UINT Handle) + { + FPRINTF( s_FileHandle, "DeletePatch\n" ); + return m_pD3DDevice->DeletePatch( Handle ); + } +}; + +#endif // STUBD3D + +#endif // STUBD3DDEVICE_H + diff --git a/materialsystem/shaderapidx9/texturedx8.cpp b/materialsystem/shaderapidx9/texturedx8.cpp new file mode 100644 index 0000000..d4dbede --- /dev/null +++ b/materialsystem/shaderapidx9/texturedx8.cpp @@ -0,0 +1,1545 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +// +//===========================================================================// + +#define DISABLE_PROTECTED_THINGS +#include "locald3dtypes.h" +#include "texturedx8.h" +#include "shaderapidx8_global.h" +#include "colorformatdx8.h" +#include "shaderapi/ishaderutil.h" +#include "materialsystem/imaterialsystem.h" +#include "utlvector.h" +#include "recording.h" +#include "shaderapi/ishaderapi.h" +#include "filesystem.h" +#include "locald3dtypes.h" +#include "textureheap.h" +#include "tier1/utlbuffer.h" +#include "tier1/callqueue.h" +#include "tier0/vprof.h" +#include "vtf/vtf.h" +#include "tier0/icommandline.h" + +#include "tier0/memdbgon.h" + +#ifdef _WIN32 +#pragma warning (disable:4189 4701) +#endif + +static int s_TextureCount = 0; +static bool s_bTestingVideoMemorySize = false; + +//----------------------------------------------------------------------------- +// Stats... +//----------------------------------------------------------------------------- + +int TextureCount() +{ + return s_TextureCount; +} + +static bool IsVolumeTexture( IDirect3DBaseTexture* pBaseTexture ) +{ + if ( !pBaseTexture ) + { + return false; + } + + return ( pBaseTexture->GetType() == D3DRTYPE_VOLUMETEXTURE ); +} + +static HRESULT GetLevelDesc( IDirect3DBaseTexture* pBaseTexture, UINT level, D3DSURFACE_DESC* pDesc ) +{ + MEM_ALLOC_D3D_CREDIT(); + + if ( !pBaseTexture ) + { + return ( HRESULT )-1; + } + + HRESULT hr; + switch( pBaseTexture->GetType() ) + { + case D3DRTYPE_TEXTURE: + hr = ( ( IDirect3DTexture * )pBaseTexture )->GetLevelDesc( level, pDesc ); + break; + case D3DRTYPE_CUBETEXTURE: + hr = ( ( IDirect3DCubeTexture * )pBaseTexture )->GetLevelDesc( level, pDesc ); + break; + default: + return ( HRESULT )-1; + } + return hr; +} + +static HRESULT GetSurfaceFromTexture( IDirect3DBaseTexture* pBaseTexture, UINT level, + D3DCUBEMAP_FACES cubeFaceID, IDirect3DSurface** ppSurfLevel ) +{ + MEM_ALLOC_D3D_CREDIT(); + + if ( !pBaseTexture ) + { + return ( HRESULT )-1; + } + + HRESULT hr; + + switch( pBaseTexture->GetType() ) + { + case D3DRTYPE_TEXTURE: + hr = ( ( IDirect3DTexture * )pBaseTexture )->GetSurfaceLevel( level, ppSurfLevel ); + break; + case D3DRTYPE_CUBETEXTURE: + if (cubeFaceID !=0) + { + //Debugger(); + } + + hr = ( ( IDirect3DCubeTexture * )pBaseTexture )->GetCubeMapSurface( cubeFaceID, level, ppSurfLevel ); + break; + default: + Assert(0); + return ( HRESULT )-1; + } + return hr; +} + +//----------------------------------------------------------------------------- +// Gets the image format of a texture +//----------------------------------------------------------------------------- +static ImageFormat GetImageFormat( IDirect3DBaseTexture* pTexture ) +{ + MEM_ALLOC_D3D_CREDIT(); + + if ( pTexture ) + { + HRESULT hr; + if ( !IsVolumeTexture( pTexture ) ) + { + D3DSURFACE_DESC desc; + hr = GetLevelDesc( pTexture, 0, &desc ); + if ( !FAILED( hr ) ) + return ImageLoader::D3DFormatToImageFormat( desc.Format ); + } + else + { + D3DVOLUME_DESC desc; + IDirect3DVolumeTexture *pVolumeTexture = static_cast( pTexture ); + hr = pVolumeTexture->GetLevelDesc( 0, &desc ); + if ( !FAILED( hr ) ) + return ImageLoader::D3DFormatToImageFormat( desc.Format ); + } + } + + // Bogus baby! + return (ImageFormat)-1; +} + + +//----------------------------------------------------------------------------- +// Allocates the D3DTexture +//----------------------------------------------------------------------------- +IDirect3DBaseTexture* CreateD3DTexture( int width, int height, int nDepth, + ImageFormat dstFormat, int numLevels, int nCreationFlags, char *debugLabel ) // OK to skip the last param +{ + if ( nDepth <= 0 ) + { + nDepth = 1; + } + + bool isCubeMap = ( nCreationFlags & TEXTURE_CREATE_CUBEMAP ) != 0; + bool bIsRenderTarget = ( nCreationFlags & TEXTURE_CREATE_RENDERTARGET ) != 0; + bool bManaged = ( nCreationFlags & TEXTURE_CREATE_MANAGED ) != 0; + bool bSysmem = ( nCreationFlags & TEXTURE_CREATE_SYSMEM ) != 0; + bool bIsDepthBuffer = ( nCreationFlags & TEXTURE_CREATE_DEPTHBUFFER ) != 0; + bool isDynamic = ( nCreationFlags & TEXTURE_CREATE_DYNAMIC ) != 0; + bool bAutoMipMap = ( nCreationFlags & TEXTURE_CREATE_AUTOMIPMAP ) != 0; + bool bVertexTexture = ( nCreationFlags & TEXTURE_CREATE_VERTEXTEXTURE ) != 0; + bool bAllowNonFilterable = ( nCreationFlags & TEXTURE_CREATE_UNFILTERABLE_OK ) != 0; + bool bVolumeTexture = ( nDepth > 1 ); + bool bIsFallback = ( nCreationFlags & TEXTURE_CREATE_FALLBACK ) != 0; + bool bNoD3DBits = ( nCreationFlags & TEXTURE_CREATE_NOD3DMEMORY ) != 0; + bool bSRGB = (nCreationFlags & TEXTURE_CREATE_SRGB) != 0; // for Posix/GL only + + // NOTE: This function shouldn't be used for creating depth buffers! + Assert( !bIsDepthBuffer ); + + D3DFORMAT d3dFormat = D3DFMT_UNKNOWN; + + D3DPOOL pool = bManaged ? D3DPOOL_MANAGED : D3DPOOL_DEFAULT; + if ( bSysmem ) + pool = D3DPOOL_SYSTEMMEM; + + if ( IsX360() ) + { + // 360 does not support vertex textures + // 360 render target creation path is for the target as a texture source (NOT the EDRAM version) + // use normal texture format rules + Assert( !bVertexTexture ); + if ( !bVertexTexture ) + { + d3dFormat = ImageLoader::ImageFormatToD3DFormat( FindNearestSupportedFormat( dstFormat, false, false, false ) ); + } + } + else + { + d3dFormat = ImageLoader::ImageFormatToD3DFormat( FindNearestSupportedFormat( dstFormat, bVertexTexture, bIsRenderTarget, bAllowNonFilterable ) ); + } + + if ( d3dFormat == D3DFMT_UNKNOWN ) + { + Warning( "ShaderAPIDX8::CreateD3DTexture: Invalid color format!\n" ); + Assert( 0 ); + return 0; + } + + IDirect3DBaseTexture* pBaseTexture = NULL; + IDirect3DTexture* pD3DTexture = NULL; + IDirect3DCubeTexture* pD3DCubeTexture = NULL; + IDirect3DVolumeTexture* pD3DVolumeTexture = NULL; + HRESULT hr = S_OK; + DWORD usage = 0; + + if ( bIsRenderTarget ) + { + usage |= D3DUSAGE_RENDERTARGET; + } + if ( isDynamic ) + { + usage |= D3DUSAGE_DYNAMIC; + } + if ( bAutoMipMap ) + { + usage |= D3DUSAGE_AUTOGENMIPMAP; + } + +#ifdef DX_TO_GL_ABSTRACTION + { + if (bSRGB) + { + usage |= D3DUSAGE_TEXTURE_SRGB; // does not exist in real DX9... just for GL to know that this is an SRGB tex + } + } +#endif + + if ( isCubeMap ) + { +#if !defined( _X360 ) + hr = Dx9Device()->CreateCubeTexture( + width, + numLevels, + usage, + d3dFormat, + pool, + &pD3DCubeTexture, + NULL + #if defined( DX_TO_GL_ABSTRACTION ) + , debugLabel // tex create funcs take extra arg for debug name on GL + #endif + ); +#else + pD3DCubeTexture = g_TextureHeap.AllocCubeTexture( width, numLevels, usage, d3dFormat, bIsFallback, bNoD3DBits ); +#endif + pBaseTexture = pD3DCubeTexture; + } + else if ( bVolumeTexture ) + { +#if !defined( _X360 ) + hr = Dx9Device()->CreateVolumeTexture( + width, + height, + nDepth, + numLevels, + usage, + d3dFormat, + pool, + &pD3DVolumeTexture, + NULL + #if defined( DX_TO_GL_ABSTRACTION ) + , debugLabel // tex create funcs take extra arg for debug name on GL + #endif + ); +#else + Assert( !bIsFallback && !bNoD3DBits ); + pD3DVolumeTexture = g_TextureHeap.AllocVolumeTexture( width, height, nDepth, numLevels, usage, d3dFormat ); +#endif + pBaseTexture = pD3DVolumeTexture; + } + else + { +#if !defined( _X360 ) + // Override usage and managed params if using special hardware shadow depth map formats... + if ( ( d3dFormat == NVFMT_RAWZ ) || ( d3dFormat == NVFMT_INTZ ) || + ( d3dFormat == D3DFMT_D16 ) || ( d3dFormat == D3DFMT_D24S8 ) || + ( d3dFormat == ATIFMT_D16 ) || ( d3dFormat == ATIFMT_D24S8 ) ) + { + // Not putting D3DUSAGE_RENDERTARGET here causes D3D debug spew later, but putting the flag causes this create to fail... + usage = D3DUSAGE_DEPTHSTENCIL; + bManaged = false; + } + + // Override managed param if using special null texture format + if ( d3dFormat == NVFMT_NULL ) + { + bManaged = false; + } + + hr = Dx9Device()->CreateTexture( + width, + height, + numLevels, + usage, + d3dFormat, + pool, + &pD3DTexture, + NULL + #if defined( DX_TO_GL_ABSTRACTION ) + , debugLabel // tex create funcs take extra arg for debug name on GL + #endif + ); + +#else + pD3DTexture = g_TextureHeap.AllocTexture( width, height, numLevels, usage, d3dFormat, bIsFallback, bNoD3DBits ); +#endif + pBaseTexture = pD3DTexture; + } + + if ( FAILED( hr ) ) + { +#ifdef ENABLE_NULLREF_DEVICE_SUPPORT + if( CommandLine()->FindParm( "-nulldevice" ) ) + { + Warning( "ShaderAPIDX8::CreateD3DTexture: Null device used. Texture not created.\n" ); + return 0; + } +#endif + + switch ( hr ) + { + case D3DERR_INVALIDCALL: + Warning( "ShaderAPIDX8::CreateD3DTexture: D3DERR_INVALIDCALL\n" ); + break; + case D3DERR_OUTOFVIDEOMEMORY: + // This conditional is here so that we don't complain when testing + // how much video memory we have. . this is kinda gross. + if ( !s_bTestingVideoMemorySize ) + { + Warning( "ShaderAPIDX8::CreateD3DTexture: D3DERR_OUTOFVIDEOMEMORY\n" ); + } + break; + case E_OUTOFMEMORY: + Warning( "ShaderAPIDX8::CreateD3DTexture: E_OUTOFMEMORY\n" ); + break; + default: + break; + } + return 0; + } + +#ifdef MEASURE_DRIVER_ALLOCATIONS + int nMipCount = numLevels; + if ( !nMipCount ) + { + while ( width > 1 || height > 1 ) + { + width >>= 1; + height >>= 1; + ++nMipCount; + } + } + + int nMemUsed = nMipCount * 1.1f * 1024; + if ( isCubeMap ) + { + nMemUsed *= 6; + } + + VPROF_INCREMENT_GROUP_COUNTER( "texture count", COUNTER_GROUP_NO_RESET, 1 ); + VPROF_INCREMENT_GROUP_COUNTER( "texture driver mem", COUNTER_GROUP_NO_RESET, nMemUsed ); + VPROF_INCREMENT_GROUP_COUNTER( "total driver mem", COUNTER_GROUP_NO_RESET, nMemUsed ); +#endif + + ++s_TextureCount; + + return pBaseTexture; +} + + +//----------------------------------------------------------------------------- +// Texture destruction +//----------------------------------------------------------------------------- +void ReleaseD3DTexture( IDirect3DBaseTexture* pD3DTex ) +{ + int ref = pD3DTex->Release(); + Assert( ref == 0 ); +} + +void DestroyD3DTexture( IDirect3DBaseTexture* pD3DTex ) +{ + if ( pD3DTex ) + { +#ifdef MEASURE_DRIVER_ALLOCATIONS + D3DRESOURCETYPE type = pD3DTex->GetType(); + int nMipCount = pD3DTex->GetLevelCount(); + if ( type == D3DRTYPE_CUBETEXTURE ) + { + nMipCount *= 6; + } + int nMemUsed = nMipCount * 1.1f * 1024; + VPROF_INCREMENT_GROUP_COUNTER( "texture count", COUNTER_GROUP_NO_RESET, -1 ); + VPROF_INCREMENT_GROUP_COUNTER( "texture driver mem", COUNTER_GROUP_NO_RESET, -nMemUsed ); + VPROF_INCREMENT_GROUP_COUNTER( "total driver mem", COUNTER_GROUP_NO_RESET, -nMemUsed ); +#endif + +#if !defined( _X360 ) + CMatRenderContextPtr pRenderContext( materials ); + ICallQueue *pCallQueue; + if ( ( pCallQueue = pRenderContext->GetCallQueue() ) != NULL ) + { + pCallQueue->QueueCall( ReleaseD3DTexture, pD3DTex ); + } + else + { + ReleaseD3DTexture( pD3DTex ); + } +#else + g_TextureHeap.FreeTexture( pD3DTex ); +#endif + --s_TextureCount; + } +} + +//----------------------------------------------------------------------------- +// Purpose: +// Input : *pTex - +// Output : int +//----------------------------------------------------------------------------- +int GetD3DTextureRefCount( IDirect3DBaseTexture *pTex ) +{ + if ( !pTex ) + return 0; + + pTex->AddRef(); + int ref = pTex->Release(); + + return ref; +} + +//----------------------------------------------------------------------------- +// See version 13 for a function that converts a texture to a mipmap (ConvertToMipmap) +//----------------------------------------------------------------------------- + + +//----------------------------------------------------------------------------- +// Lock, unlock a texture... +//----------------------------------------------------------------------------- + +static RECT s_LockedSrcRect; +static D3DLOCKED_RECT s_LockedRect; +#ifdef DBGFLAG_ASSERT +static bool s_bInLock = false; +#endif + +bool LockTexture( ShaderAPITextureHandle_t bindId, int copy, IDirect3DBaseTexture* pTexture, int level, + D3DCUBEMAP_FACES cubeFaceID, int xOffset, int yOffset, int width, int height, bool bDiscard, + CPixelWriter& writer ) +{ + Assert( !s_bInLock ); + + IDirect3DSurface* pSurf; + HRESULT hr = GetSurfaceFromTexture( pTexture, level, cubeFaceID, &pSurf ); + if ( FAILED( hr ) ) + return false; + + s_LockedSrcRect.left = xOffset; + s_LockedSrcRect.right = xOffset + width; + s_LockedSrcRect.top = yOffset; + s_LockedSrcRect.bottom = yOffset + height; + + unsigned int flags = D3DLOCK_NOSYSLOCK; + flags |= bDiscard ? D3DLOCK_DISCARD : 0; + RECORD_COMMAND( DX8_LOCK_TEXTURE, 6 ); + RECORD_INT( bindId ); + RECORD_INT( copy ); + RECORD_INT( level ); + RECORD_INT( cubeFaceID ); + RECORD_STRUCT( &s_LockedSrcRect, sizeof(s_LockedSrcRect) ); + RECORD_INT( flags ); + + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "D3DLockTexture" ); + + hr = pSurf->LockRect( &s_LockedRect, &s_LockedSrcRect, flags ); + pSurf->Release(); + + if ( FAILED( hr ) ) + return false; + + writer.SetPixelMemory( GetImageFormat(pTexture), s_LockedRect.pBits, s_LockedRect.Pitch ); + +#ifdef DBGFLAG_ASSERT + s_bInLock = true; +#endif + return true; +} + +void UnlockTexture( ShaderAPITextureHandle_t bindId, int copy, IDirect3DBaseTexture* pTexture, int level, + D3DCUBEMAP_FACES cubeFaceID ) +{ + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s", __FUNCTION__ ); + + Assert( s_bInLock ); + + IDirect3DSurface* pSurf; + HRESULT hr = GetSurfaceFromTexture( pTexture, level, cubeFaceID, &pSurf ); + if (FAILED(hr)) + return; + +#ifdef RECORD_TEXTURES + int width = s_LockedSrcRect.right - s_LockedSrcRect.left; + int height = s_LockedSrcRect.bottom - s_LockedSrcRect.top; + int imageFormatSize = ImageLoader::SizeInBytes( GetImageFormat( pTexture ) ); + Assert( imageFormatSize != 0 ); + int validDataBytesPerRow = imageFormatSize * width; + int storeSize = validDataBytesPerRow * height; + static CUtlVector< unsigned char > tmpMem; + if( tmpMem.Size() < storeSize ) + { + tmpMem.AddMultipleToTail( storeSize - tmpMem.Size() ); + } + unsigned char *pDst = tmpMem.Base(); + unsigned char *pSrc = ( unsigned char * )s_LockedRect.pBits; + RECORD_COMMAND( DX8_SET_TEXTURE_DATA, 3 ); + RECORD_INT( validDataBytesPerRow ); + RECORD_INT( height ); + int i; + for( i = 0; i < height; i++ ) + { + memcpy( pDst, pSrc, validDataBytesPerRow ); + pDst += validDataBytesPerRow; + pSrc += s_LockedRect.Pitch; + } + RECORD_STRUCT( tmpMem.Base(), storeSize ); +#endif // RECORD_TEXTURES + + RECORD_COMMAND( DX8_UNLOCK_TEXTURE, 4 ); + RECORD_INT( bindId ); + RECORD_INT( copy ); + RECORD_INT( level ); + RECORD_INT( cubeFaceID ); + + hr = pSurf->UnlockRect(); + pSurf->Release(); +#ifdef DBGFLAG_ASSERT + s_bInLock = false; +#endif +} + +//----------------------------------------------------------------------------- +// Compute texture size based on compression +//----------------------------------------------------------------------------- + +static inline int DetermineGreaterPowerOfTwo( int val ) +{ + int num = 1; + while (val > num) + { + num <<= 1; + } + + return num; +} + +inline int DeterminePowerOfTwo( int val ) +{ + int pow = 0; + while ((val & 0x1) == 0x0) + { + val >>= 1; + ++pow; + } + + return pow; +} + + +//----------------------------------------------------------------------------- +// Blit in bits +//----------------------------------------------------------------------------- +// NOTE: IF YOU CHANGE THIS, CHANGE THE VERSION IN PLAYBACK.CPP!!!! +// OPTIMIZE??: could lock the texture directly instead of the surface in dx9. +#if !defined( _X360 ) +static void BlitSurfaceBits( TextureLoadInfo_t &info, int xOffset, int yOffset, int srcStride ) +{ + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s", __FUNCTION__ ); + + // Get the level of the texture we want to write into + IDirect3DSurface* pTextureLevel; + + if (info.m_CubeFaceID !=0) + { + //Debugger(); + } + + + HRESULT hr = GetSurfaceFromTexture( info.m_pTexture, info.m_nLevel, info.m_CubeFaceID, &pTextureLevel ); + if ( FAILED( hr ) ) + return; + + RECT srcRect; + RECT *pSrcRect = NULL; + D3DLOCKED_RECT lockedRect; + + srcRect.left = xOffset; + srcRect.right = xOffset + info.m_nWidth; + srcRect.top = yOffset; + srcRect.bottom = yOffset + info.m_nHeight; + +#if defined( SHADERAPIDX9 ) && !defined( _X360 ) && !defined( DX_TO_GL_ABSTRACTION ) + if ( !info.m_bTextureIsLockable ) + { + // Copy from system memory to video memory using D3D9Device->UpdateSurface + bool bSuccess = false; + + D3DSURFACE_DESC desc; + Verify( pTextureLevel->GetDesc( &desc ) == S_OK ); + ImageFormat dstFormat = ImageLoader::D3DFormatToImageFormat( desc.Format ); + D3DFORMAT dstFormatD3D = ImageLoader::ImageFormatToD3DFormat( dstFormat ); + + IDirect3DSurface* pSrcSurface = NULL; + bool bCopyBitsToSrcSurface = true; + +#if defined(IS_WINDOWS_PC) && defined(SHADERAPIDX9) + // D3D9Ex fast path: create a texture wrapping our own system memory buffer + // if the source and destination formats are exactly the same and the stride + // is tightly packed. no locking/blitting required. + // NOTE: the fast path does not work on sub-4x4 DXT compressed textures. + extern bool g_ShaderDeviceUsingD3D9Ex; + if ( g_ShaderDeviceUsingD3D9Ex && + ( info.m_SrcFormat == dstFormat || ( info.m_SrcFormat == IMAGE_FORMAT_DXT1_ONEBITALPHA && dstFormat == IMAGE_FORMAT_DXT1 ) ) && + ( !ImageLoader::IsCompressed( dstFormat ) || (info.m_nWidth >= 4 || info.m_nHeight >= 4) ) ) + { + if ( srcStride == 0 || srcStride == info.m_nWidth * ImageLoader::SizeInBytes( info.m_SrcFormat ) ) + { + IDirect3DTexture9* pTempTex = NULL; + if ( Dx9Device()->CreateTexture( info.m_nWidth, info.m_nHeight, 1, 0, dstFormatD3D, D3DPOOL_SYSTEMMEM, &pTempTex, (HANDLE*) &info.m_pSrcData ) == S_OK ) + { + IDirect3DSurface* pTempSurf = NULL; + if ( pTempTex->GetSurfaceLevel( 0, &pTempSurf ) == S_OK ) + { + pSrcSurface = pTempSurf; + bCopyBitsToSrcSurface = false; + } + pTempTex->Release(); + } + } + } +#endif + + // If possible to create a texture of this size, create a temporary texture in + // system memory and then use the UpdateSurface method to copy between textures. + if ( !pSrcSurface && ( g_pHardwareConfig->Caps().m_SupportsNonPow2Textures || + ( IsPowerOfTwo( info.m_nWidth ) && IsPowerOfTwo( info.m_nHeight ) ) ) ) + { + int tempW = info.m_nWidth, tempH = info.m_nHeight, mip = 0; + if ( info.m_nLevel > 0 && ( ( tempW | tempH ) & 3 ) && ImageLoader::IsCompressed( dstFormat ) ) + { + // Loading lower mip levels of DXT compressed textures is sort of tricky + // because we can't create textures that aren't multiples of 4, and we can't + // pass subrectangles of DXT textures into UpdateSurface. Create a temporary + // texture which is 1 or 2 mip levels larger and then lock the appropriate + // mip level to grab its correctly-dimensioned surface. -henryg 11/18/2011 + mip = ( info.m_nLevel > 1 && ( ( tempW | tempH ) & 1 ) ) ? 2 : 1; + tempW <<= mip; + tempH <<= mip; + } + + IDirect3DTexture9* pTempTex = NULL; + IDirect3DSurface* pTempSurf = NULL; + if ( Dx9Device()->CreateTexture( tempW, tempH, mip+1, 0, dstFormatD3D, D3DPOOL_SYSTEMMEM, &pTempTex, NULL ) == S_OK ) + { + if ( pTempTex->GetSurfaceLevel( mip, &pTempSurf ) == S_OK ) + { + pSrcSurface = pTempSurf; + bCopyBitsToSrcSurface = true; + } + pTempTex->Release(); + } + } + + // Create an offscreen surface if the texture path wasn't an option. + if ( !pSrcSurface ) + { + IDirect3DSurface* pTempSurf = NULL; + if ( Dx9Device()->CreateOffscreenPlainSurface( info.m_nWidth, info.m_nHeight, dstFormatD3D, D3DPOOL_SYSTEMMEM, &pTempSurf, NULL ) == S_OK ) + { + pSrcSurface = pTempSurf; + bCopyBitsToSrcSurface = true; + } + } + + // Lock and fill the surface + if ( bCopyBitsToSrcSurface && pSrcSurface ) + { + if ( pSrcSurface->LockRect( &lockedRect, NULL, D3DLOCK_NOSYSLOCK ) == S_OK ) + { + unsigned char *pImage = (unsigned char *)lockedRect.pBits; + ShaderUtil()->ConvertImageFormat( info.m_pSrcData, info.m_SrcFormat, + pImage, dstFormat, info.m_nWidth, info.m_nHeight, srcStride, lockedRect.Pitch ); + pSrcSurface->UnlockRect(); + } + else + { + // Lock failed. + pSrcSurface->Release(); + pSrcSurface = NULL; + } + } + + // Perform the UpdateSurface call that blits between system and video memory + if ( pSrcSurface ) + { + POINT pt = { xOffset, yOffset }; + bSuccess = ( Dx9Device()->UpdateSurface( pSrcSurface, NULL, pTextureLevel, &pt ) == S_OK ); + pSrcSurface->Release(); + } + + if ( !bSuccess ) + { + Warning( "CShaderAPIDX8::BlitTextureBits: couldn't lock texture rect or use UpdateSurface\n" ); + } + + pTextureLevel->Release(); + return; + } +#endif + + Assert( info.m_bTextureIsLockable ); + +#ifndef RECORD_TEXTURES + RECORD_COMMAND( DX8_LOCK_TEXTURE, 6 ); + RECORD_INT( info.m_TextureHandle ); + RECORD_INT( info.m_nCopy ); + RECORD_INT( info.m_nLevel ); + RECORD_INT( info.m_CubeFaceID ); + RECORD_STRUCT( &srcRect, sizeof(srcRect) ); + RECORD_INT( D3DLOCK_NOSYSLOCK ); +#endif + + { + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s - D3DLockRect", __FUNCTION__ ); + + // lock the region (could be the full surface or less) + if ( FAILED( pTextureLevel->LockRect( &lockedRect, &srcRect, D3DLOCK_NOSYSLOCK ) ) ) + { + Warning( "CShaderAPIDX8::BlitTextureBits: couldn't lock texture rect\n" ); + pTextureLevel->Release(); + return; + } + } + + { + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s - ConvertImageFormat", __FUNCTION__ ); + + // garymcthack : need to make a recording command for this. + ImageFormat dstFormat = GetImageFormat( info.m_pTexture ); + unsigned char *pImage = (unsigned char *)lockedRect.pBits; + ShaderUtil()->ConvertImageFormat( info.m_pSrcData, info.m_SrcFormat, + pImage, dstFormat, info.m_nWidth, info.m_nHeight, srcStride, lockedRect.Pitch ); + } + +#ifndef RECORD_TEXTURES + RECORD_COMMAND( DX8_UNLOCK_TEXTURE, 4 ); + RECORD_INT( info.m_TextureHandle ); + RECORD_INT( info.m_nCopy ); + RECORD_INT( info.m_nLevel ); + RECORD_INT( info.m_CubeFaceID ); +#endif + + { + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s - UnlockRect", __FUNCTION__ ); + + if ( FAILED( pTextureLevel->UnlockRect() ) ) + { + Warning( "CShaderAPIDX8::BlitTextureBits: couldn't unlock texture rect\n" ); + pTextureLevel->Release(); + return; + } + } + + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s - pTextureLevel->Release", __FUNCTION__ ); + pTextureLevel->Release(); +} +#endif + +//----------------------------------------------------------------------------- +// Puts 2D texture data into 360 gpu memory. +//----------------------------------------------------------------------------- +#if defined( _X360 ) +static void BlitSurfaceBits( TextureLoadInfo_t &info, int xOffset, int yOffset, int srcStride ) +{ + // xbox textures are NOT backed in gpu memory contiguously + // stride details are critical - see [Xbox 360 Texture Storage] + // a d3dformat identifier on the xbox is tiled, the same d3dformat on the pc is expected linear to the app + // we purposely hide the tiling here, otherwise much confusion for the pc + // the *entire* target must be un-tiled *only* before any *subrect* blitting linear work + // the *entire* target must then be re-tiled after the *subrect* blit + // procedural textures require this to subrect blit their new portions correctly + // the tiling dance can be avoided if the source and target match in tiled state during a full rect blit + + if ( info.m_bSrcIsTiled ) + { + // not supporting subrect blitting from a tiled source + Assert( 0 ); + return; + } + + CUtlBuffer formatConvertMemory; + unsigned char *pSrcData = info.m_pSrcData; + + ImageFormat dstFormat = GetImageFormat( info.m_pTexture ); + if ( dstFormat != info.m_SrcFormat ) + { + if ( !info.m_bCanConvertFormat ) + { + // texture is expected to be in target format + // not supporting conversion of a tiled source + Assert( 0 ); + return; + } + + int srcSize = ImageLoader::GetMemRequired( info.m_nWidth, info.m_nHeight, 1, info.m_SrcFormat, false ); + int dstSize = ImageLoader::GetMemRequired( info.m_nWidth, info.m_nHeight, 1, dstFormat, false ); + formatConvertMemory.EnsureCapacity( dstSize ); + + // due to format conversion, source is in non-native order + ImageLoader::PreConvertSwapImageData( (unsigned char*)info.m_pSrcData, srcSize, info.m_SrcFormat, info.m_nWidth, srcStride ); + + // slow conversion operation + if ( !ShaderUtil()->ConvertImageFormat( + info.m_pSrcData, + info.m_SrcFormat, + (unsigned char*)formatConvertMemory.Base(), + dstFormat, + info.m_nWidth, + info.m_nHeight, + srcStride, + 0 ) ) + { + // conversion failed + Assert( 0 ); + return; + } + + // due to format conversion, source must have been in non-native order + ImageLoader::PostConvertSwapImageData( (unsigned char*)formatConvertMemory.Base(), dstSize, dstFormat ); + + pSrcData = (unsigned char*)formatConvertMemory.Base(); + } + + // get the top mip level info (needed for proper sub mip access) + XGTEXTURE_DESC baseDesc; + XGGetTextureDesc( info.m_pTexture, 0, &baseDesc ); + bool bDstIsTiled = XGIsTiledFormat( baseDesc.Format ) == TRUE; + + // get the target mip level info + XGTEXTURE_DESC mipDesc; + XGGetTextureDesc( info.m_pTexture, info.m_nLevel, &mipDesc ); + bool bFullSurfBlit = ( mipDesc.Width == (unsigned)info.m_nWidth && mipDesc.Height == (unsigned)info.m_nHeight ); + + // get the mip level of the texture we want to write into + IDirect3DSurface* pTextureLevel; + HRESULT hr = GetSurfaceFromTexture( info.m_pTexture, info.m_nLevel, info.m_CubeFaceID, &pTextureLevel ); + if ( FAILED( hr ) ) + { + Warning( "CShaderAPIDX8::BlitTextureBits: GetSurfaceFromTexture() failure\n" ); + return; + } + + CUtlBuffer scratchMemory; + D3DLOCKED_RECT lockedRect; + + hr = pTextureLevel->LockRect( &lockedRect, NULL, D3DLOCK_NOSYSLOCK ); + if ( FAILED( hr ) ) + { + Warning( "CShaderAPIDX8::BlitTextureBits: couldn't lock texture rect\n" ); + goto cleanUp; + } + unsigned char *pTargetImage = (unsigned char *)lockedRect.pBits; + + POINT p; + p.x = xOffset; + p.y = yOffset; + + RECT r; + r.left = 0; + r.top = 0; + r.right = info.m_nWidth; + r.bottom = info.m_nHeight; + + int blockSize = mipDesc.Width/mipDesc.WidthInBlocks; + if ( !srcStride ) + { + srcStride = (mipDesc.Width/blockSize)*mipDesc.BytesPerBlock; + } + + // subrect blitting path + if ( !bDstIsTiled ) + { + // Copy the subrect without conversion + hr = XGCopySurface( + pTargetImage, + mipDesc.RowPitch, + mipDesc.Width, + mipDesc.Height, + mipDesc.Format, + &p, + pSrcData, + srcStride, + mipDesc.Format, + &r, + 0, + 0 ); + if ( FAILED( hr ) ) + { + Warning( "CShaderAPIDX8::BlitTextureBits: failed subrect copy\n" ); + goto cleanUp; + } + } + else + { + int tileFlags = 0; + if ( !( mipDesc.Flags & XGTDESC_PACKED ) ) + tileFlags |= XGTILE_NONPACKED; + if ( mipDesc.Flags & XGTDESC_BORDERED ) + tileFlags |= XGTILE_BORDER; + + // tile the temp store back into the target surface + XGTileTextureLevel( + baseDesc.Width, + baseDesc.Height, + info.m_nLevel, + XGGetGpuFormat( baseDesc.Format ), + tileFlags, + pTargetImage, + &p, + pSrcData, + srcStride, + &r ); + } + + hr = pTextureLevel->UnlockRect(); + if ( FAILED( hr ) ) + { + Warning( "CShaderAPIDX8::BlitTextureBits: couldn't unlock texture rect\n" ); + goto cleanUp; + } + +cleanUp: + pTextureLevel->Release(); +} +#endif + +//----------------------------------------------------------------------------- +// Blit in bits +//----------------------------------------------------------------------------- +#if !defined( _X360 ) +static void BlitVolumeBits( TextureLoadInfo_t &info, int xOffset, int yOffset, int srcStride ) +{ + D3DBOX srcBox; + D3DLOCKED_BOX lockedBox; + srcBox.Left = xOffset; + srcBox.Right = xOffset + info.m_nWidth; + srcBox.Top = yOffset; + srcBox.Bottom = yOffset + info.m_nHeight; + srcBox.Front = info.m_nZOffset; + srcBox.Back = info.m_nZOffset + 1; + +#ifndef RECORD_TEXTURES + RECORD_COMMAND( DX8_LOCK_TEXTURE, 6 ); + RECORD_INT( info.m_TextureHandle ); + RECORD_INT( info.m_nCopy ); + RECORD_INT( info.m_nLevel ); + RECORD_INT( info.m_CubeFaceID ); + RECORD_STRUCT( &srcRect, sizeof(srcRect) ); + RECORD_INT( D3DLOCK_NOSYSLOCK ); +#endif + + IDirect3DVolumeTexture *pVolumeTexture = static_cast( info.m_pTexture ); + if ( FAILED( pVolumeTexture->LockBox( info.m_nLevel, &lockedBox, &srcBox, D3DLOCK_NOSYSLOCK ) ) ) + { + Warning( "BlitVolumeBits: couldn't lock volume texture rect\n" ); + return; + } + + // garymcthack : need to make a recording command for this. + ImageFormat dstFormat = GetImageFormat( info.m_pTexture ); + unsigned char *pImage = (unsigned char *)lockedBox.pBits; + ShaderUtil()->ConvertImageFormat( info.m_pSrcData, info.m_SrcFormat, + pImage, dstFormat, info.m_nWidth, info.m_nHeight, srcStride, lockedBox.RowPitch ); + +#ifndef RECORD_TEXTURES + RECORD_COMMAND( DX8_UNLOCK_TEXTURE, 4 ); + RECORD_INT( info.m_TextureHandle ); + RECORD_INT( info.m_nCopy ); + RECORD_INT( info.m_nLevel ); + RECORD_INT( info.m_CubeFaceID ); +#endif + + if ( FAILED( pVolumeTexture->UnlockBox( info.m_nLevel ) ) ) + { + Warning( "BlitVolumeBits: couldn't unlock volume texture rect\n" ); + return; + } +} +#endif + +//----------------------------------------------------------------------------- +// Puts 3D texture data into 360 gpu memory. +// Does not support any subvolume or slice blitting. +//----------------------------------------------------------------------------- +#if defined( _X360 ) +static void BlitVolumeBits( TextureLoadInfo_t &info, int xOffset, int yOffset, int srcStride ) +{ + if ( xOffset || yOffset || info.m_nZOffset || srcStride ) + { + // not supporting any subvolume blitting + // the entire volume per mip must be blitted + Assert( 0 ); + return; + } + + ImageFormat dstFormat = GetImageFormat( info.m_pTexture ); + if ( dstFormat != info.m_SrcFormat ) + { + // texture is expected to be in target format + // not supporting conversion + Assert( 0 ); + return; + } + + // get the top mip level info (needed for proper sub mip access) + XGTEXTURE_DESC baseDesc; + XGGetTextureDesc( info.m_pTexture, 0, &baseDesc ); + bool bDstIsTiled = XGIsTiledFormat( baseDesc.Format ) == TRUE; + if ( info.m_bSrcIsTiled && !bDstIsTiled ) + { + // not supporting a tiled source into an untiled target + Assert( 0 ); + return; + } + + // get the mip level info + XGTEXTURE_DESC mipDesc; + XGGetTextureDesc( info.m_pTexture, info.m_nLevel, &mipDesc ); + bool bFullSurfBlit = ( mipDesc.Width == (unsigned int)info.m_nWidth && mipDesc.Height == (unsigned int)info.m_nHeight ); + + if ( !bFullSurfBlit ) + { + // not supporting subrect blitting + Assert( 0 ); + return; + } + + D3DLOCKED_BOX lockedBox; + + // get the mip level of the volume we want to write into + IDirect3DVolumeTexture *pVolumeTexture = static_cast( info.m_pTexture ); + HRESULT hr = pVolumeTexture->LockBox( info.m_nLevel, &lockedBox, NULL, D3DLOCK_NOSYSLOCK ); + if ( FAILED( hr ) ) + { + Warning( "CShaderAPIDX8::BlitVolumeBits: Couldn't lock volume box\n" ); + return; + } + + unsigned char *pSrcData = info.m_pSrcData; + unsigned char *pTargetImage = (unsigned char *)lockedBox.pBits; + + int tileFlags = 0; + if ( !( mipDesc.Flags & XGTDESC_PACKED ) ) + tileFlags |= XGTILE_NONPACKED; + if ( mipDesc.Flags & XGTDESC_BORDERED ) + tileFlags |= XGTILE_BORDER; + + if ( !info.m_bSrcIsTiled && bDstIsTiled ) + { + // tile the source directly into the target surface + XGTileVolumeTextureLevel( + baseDesc.Width, + baseDesc.Height, + baseDesc.Depth, + info.m_nLevel, + XGGetGpuFormat( baseDesc.Format ), + tileFlags, + pTargetImage, + NULL, + pSrcData, + mipDesc.RowPitch, + mipDesc.SlicePitch, + NULL ); + } + else if ( !info.m_bSrcIsTiled && !bDstIsTiled ) + { + // not implemented yet + Assert( 0 ); + } + else + { + // not implemented yet + Assert( 0 ); + } + + hr = pVolumeTexture->UnlockBox( info.m_nLevel ); + if ( FAILED( hr ) ) + { + Warning( "CShaderAPIDX8::BlitVolumeBits: couldn't unlock volume box\n" ); + return; + } +} +#endif + +// FIXME: How do I blit from D3DPOOL_SYSTEMMEM to D3DPOOL_MANAGED? I used to use CopyRects for this. UpdateSurface doesn't work because it can't blit to anything besides D3DPOOL_DEFAULT. +// We use this only in the case where we need to create a < 4x4 miplevel for a compressed texture. We end up creating a 4x4 system memory texture, and blitting it into the proper miplevel. +// 6) LockRects should be used for copying between SYSTEMMEM and +// MANAGED. For such a small copy, you'd avoid a significant +// amount of overhead from the old CopyRects code. Ideally, you +// should just lock the bottom of MANAGED and generate your +// sub-4x4 data there. + +// NOTE: IF YOU CHANGE THIS, CHANGE THE VERSION IN PLAYBACK.CPP!!!! +static void BlitTextureBits( TextureLoadInfo_t &info, int xOffset, int yOffset, int srcStride ) +{ +#ifdef RECORD_TEXTURES + RECORD_COMMAND( DX8_BLIT_TEXTURE_BITS, 14 ); + RECORD_INT( info.m_TextureHandle ); + RECORD_INT( info.m_nCopy ); + RECORD_INT( info.m_nLevel ); + RECORD_INT( info.m_CubeFaceID ); + RECORD_INT( xOffset ); + RECORD_INT( yOffset ); + RECORD_INT( info.m_nZOffset ); + RECORD_INT( info.m_nWidth ); + RECORD_INT( info.m_nHeight ); + RECORD_INT( info.m_SrcFormat ); + RECORD_INT( srcStride ); + RECORD_INT( GetImageFormat( info.m_pTexture ) ); + // strides are in bytes. + int srcDataSize; + if ( srcStride == 0 ) + { + srcDataSize = ImageLoader::GetMemRequired( info.m_nWidth, info.m_nHeight, 1, info.m_SrcFormat, false ); + } + else + { + srcDataSize = srcStride * info.m_nHeight; + } + RECORD_INT( srcDataSize ); + RECORD_STRUCT( info.m_pSrcData, srcDataSize ); +#endif // RECORD_TEXTURES + + if ( !IsVolumeTexture( info.m_pTexture ) ) + { + Assert( info.m_nZOffset == 0 ); + BlitSurfaceBits( info, xOffset, yOffset, srcStride ); + } + else + { + BlitVolumeBits( info, xOffset, yOffset, srcStride ); + } +} + +//----------------------------------------------------------------------------- +// Texture image upload +//----------------------------------------------------------------------------- +void LoadTexture( TextureLoadInfo_t &info ) +{ + MEM_ALLOC_D3D_CREDIT(); + + Assert( info.m_pSrcData ); + Assert( info.m_pTexture ); + +#ifdef _DEBUG + ImageFormat format = GetImageFormat( info.m_pTexture ); + Assert( (format != -1) && (format == FindNearestSupportedFormat( format, false, false, false )) ); +#endif + + // Copy in the bits... + BlitTextureBits( info, 0, 0, 0 ); +} + +void LoadVolumeTextureFromVTF( TextureLoadInfo_t &info, IVTFTexture* pVTF, int iVTFFrame ) +{ + if ( !info.m_pTexture || info.m_pTexture->GetType() != D3DRTYPE_VOLUMETEXTURE ) + { + Assert( 0 ); + return; + } + + IDirect3DVolumeTexture9 *pVolTex = static_cast( info.m_pTexture ); + + D3DVOLUME_DESC desc; + if ( pVolTex->GetLevelDesc( 0, &desc ) != S_OK ) + { + Warning( "LoadVolumeTextureFromVTF: couldn't get texture level description\n" ); + return; + } + + int iMipCount = pVolTex->GetLevelCount(); + if ( pVTF->Depth() != (int)desc.Depth || pVTF->Width() != (int)desc.Width || pVTF->Height() != (int)desc.Height || pVTF->MipCount() < iMipCount ) + { + Warning( "LoadVolumeTextureFromVTF: VTF dimensions do not match texture\n" ); + return; + } + + TextureLoadInfo_t sliceInfo = info; + +#if !defined( _X360 ) && !defined( DX_TO_GL_ABSTRACTION ) + IDirect3DVolumeTexture9 *pStagingTexture = NULL; + if ( !info.m_bTextureIsLockable ) + { + IDirect3DVolumeTexture9 *pTemp; + if ( Dx9Device()->CreateVolumeTexture( desc.Width, desc.Height, desc.Depth, iMipCount, 0, desc.Format, D3DPOOL_SYSTEMMEM, &pTemp, NULL ) != S_OK ) + { + Warning( "LoadVolumeTextureFromVTF: failed to create temporary staging texture\n" ); + return; + } + sliceInfo.m_pTexture = static_cast( pTemp ); + sliceInfo.m_bTextureIsLockable = true; + pStagingTexture = pTemp; + } +#endif + + for ( int iMip = 0; iMip < iMipCount; ++iMip ) + { + int w, h, d; + pVTF->ComputeMipLevelDimensions( iMip, &w, &h, &d ); + sliceInfo.m_nLevel = iMip; + sliceInfo.m_nWidth = w; + sliceInfo.m_nHeight = h; + for ( int iSlice = 0; iSlice < d; ++iSlice ) + { + sliceInfo.m_nZOffset = iSlice; + sliceInfo.m_pSrcData = pVTF->ImageData( iVTFFrame, 0, iMip, 0, 0, iSlice ); + BlitTextureBits( sliceInfo, 0, 0, 0 ); + } + } + +#if !defined( _X360 ) && !defined( DX_TO_GL_ABSTRACTION ) + if ( pStagingTexture ) + { + if ( Dx9Device()->UpdateTexture( pStagingTexture, pVolTex ) != S_OK ) + { + Warning( "LoadVolumeTextureFromVTF: volume UpdateTexture failed\n" ); + } + pStagingTexture->Release(); + } +#endif +} + +void LoadCubeTextureFromVTF( TextureLoadInfo_t &info, IVTFTexture* pVTF, int iVTFFrame ) +{ + if ( !info.m_pTexture || info.m_pTexture->GetType() != D3DRTYPE_CUBETEXTURE ) + { + Assert( 0 ); + return; + } + + IDirect3DCubeTexture9 *pCubeTex = static_cast( info.m_pTexture ); + + D3DSURFACE_DESC desc; + if ( pCubeTex->GetLevelDesc( 0, &desc ) != S_OK ) + { + Warning( "LoadCubeTextureFromVTF: couldn't get texture level description\n" ); + return; + } + + int iMipCount = pCubeTex->GetLevelCount(); + if ( pVTF->Depth() != 1 || pVTF->Width() != (int)desc.Width || pVTF->Height() != (int)desc.Height || pVTF->FaceCount() < 6 || pVTF->MipCount() < iMipCount ) + { + Warning( "LoadCubeTextureFromVTF: VTF dimensions do not match texture\n" ); + return; + } + + TextureLoadInfo_t faceInfo = info; + +#if !defined( _X360 ) && !defined( DX_TO_GL_ABSTRACTION ) + IDirect3DCubeTexture9 *pStagingTexture = NULL; + if ( !info.m_bTextureIsLockable ) + { + IDirect3DCubeTexture9 *pTemp; + if ( Dx9Device()->CreateCubeTexture( desc.Width, iMipCount, 0, desc.Format, D3DPOOL_SYSTEMMEM, &pTemp, NULL ) != S_OK ) + { + Warning( "LoadCubeTextureFromVTF: failed to create temporary staging texture\n" ); + return; + } + faceInfo.m_pTexture = static_cast( pTemp ); + faceInfo.m_bTextureIsLockable = true; + pStagingTexture = pTemp; + } +#endif + + for ( int iMip = 0; iMip < iMipCount; ++iMip ) + { + int w, h, d; + pVTF->ComputeMipLevelDimensions( iMip, &w, &h, &d ); + faceInfo.m_nLevel = iMip; + faceInfo.m_nWidth = w; + faceInfo.m_nHeight = h; + for ( int iFace = 0; iFace < 6; ++iFace ) + { + faceInfo.m_CubeFaceID = (D3DCUBEMAP_FACES) iFace; + faceInfo.m_pSrcData = pVTF->ImageData( iVTFFrame, iFace, iMip ); + BlitTextureBits( faceInfo, 0, 0, 0 ); + } + } + +#if !defined( _X360 ) && !defined( DX_TO_GL_ABSTRACTION ) + if ( pStagingTexture ) + { + if ( Dx9Device()->UpdateTexture( pStagingTexture, pCubeTex ) != S_OK ) + { + Warning( "LoadCubeTextureFromVTF: cube UpdateTexture failed\n" ); + } + pStagingTexture->Release(); + } +#endif +} + +void LoadTextureFromVTF( TextureLoadInfo_t &info, IVTFTexture* pVTF, int iVTFFrame ) +{ + TM_ZONE_DEFAULT( TELEMETRY_LEVEL0 ); + + if ( !info.m_pTexture || info.m_pTexture->GetType() != D3DRTYPE_TEXTURE ) + { + Assert( 0 ); + return; + } + + IDirect3DTexture9 *pTex = static_cast( info.m_pTexture ); + + D3DSURFACE_DESC desc; + { + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s - GetLevelDesc", __FUNCTION__ ); + if ( pTex->GetLevelDesc( 0, &desc ) != S_OK ) + { + Warning( "LoadTextureFromVTF: couldn't get texture level description\n" ); + return; + } + } + + int iMipCount = pTex->GetLevelCount(); + if ( pVTF->Depth() != 1 || pVTF->Width() != (int)desc.Width || pVTF->Height() != (int)desc.Height || pVTF->MipCount() < iMipCount || pVTF->FaceCount() <= (int)info.m_CubeFaceID ) + { + Warning( "LoadTextureFromVTF: VTF dimensions do not match texture\n" ); + return; + } + + // Info may have a cube face ID if we are falling back to 2D sphere map support + TextureLoadInfo_t mipInfo = info; + int iVTFFaceNum = info.m_CubeFaceID; + mipInfo.m_CubeFaceID = (D3DCUBEMAP_FACES)0; + +#if !defined( _X360 ) && !defined( DX_TO_GL_ABSTRACTION ) + // If blitting more than one mip level of an unlockable texture, create a temporary + // texture for all mip levels only call UpdateTexture once. For textures with + // only a single mip level, fall back on the support in BlitSurfaceBits. -henryg + IDirect3DTexture9 *pStagingTexture = NULL; + if ( !info.m_bTextureIsLockable && iMipCount > 1 ) + { + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s - CreateSysmemTexture", __FUNCTION__ ); + + IDirect3DTexture9 *pTemp; + if ( Dx9Device()->CreateTexture( desc.Width, desc.Height, iMipCount, 0, desc.Format, D3DPOOL_SYSTEMMEM, &pTemp, NULL ) != S_OK ) + { + Warning( "LoadTextureFromVTF: failed to create temporary staging texture\n" ); + return; + } + + mipInfo.m_pTexture = static_cast( pTemp ); + mipInfo.m_bTextureIsLockable = true; + pStagingTexture = pTemp; + } +#endif + + // Get the clamped resolutions from the VTF, then apply any clamping we've done from the higher level code. + // (For example, we chop off the bottom of the mipmap pyramid at 32x32--that is reflected in iMipCount, so + // honor that here). + int finest = 0, coarsest = 0; + pVTF->GetMipmapRange( &finest, &coarsest ); + finest = Min( finest, iMipCount - 1 ); + coarsest = Min( coarsest, iMipCount - 1 ); + Assert( finest <= coarsest && coarsest < iMipCount ); + + { + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s - BlitTextureBits", __FUNCTION__ ); + for ( int iMip = finest; iMip <= coarsest; ++iMip ) + { + int w, h, d; + pVTF->ComputeMipLevelDimensions( iMip, &w, &h, &d ); + mipInfo.m_nLevel = iMip; + mipInfo.m_nWidth = w; + mipInfo.m_nHeight = h; + mipInfo.m_pSrcData = pVTF->ImageData( iVTFFrame, iVTFFaceNum, iMip ); + + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s - BlitTextureBits - %d", __FUNCTION__, iMip ); + + BlitTextureBits( mipInfo, 0, 0, 0 ); + } + } + +#if !defined( _X360 ) && !defined( DX_TO_GL_ABSTRACTION ) + if ( pStagingTexture ) + { + if ( ( coarsest - finest + 1 ) == iMipCount ) + { + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s - UpdateTexture", __FUNCTION__ ); + if ( Dx9Device()->UpdateTexture( pStagingTexture, pTex ) != S_OK ) + { + Warning( "LoadTextureFromVTF: UpdateTexture failed\n" ); + } + } + else + { + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s - UpdateSurface", __FUNCTION__ ); + + for ( int mip = finest; mip <= coarsest; ++mip ) + { + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s - UpdateSurface - %d", __FUNCTION__, mip ); + + IDirect3DSurface9 *pSrcSurf = NULL, + *pDstSurf = NULL; + + if ( pStagingTexture->GetSurfaceLevel( mip, &pSrcSurf ) != S_OK ) + Warning( "LoadTextureFromVTF: couldn't get surface level %d for system surface\n", mip ); + + if ( pTex->GetSurfaceLevel( mip, &pDstSurf ) != S_OK ) + Warning( "LoadTextureFromVTF: couldn't get surface level %d for dest surface\n", mip ); + + { + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s - UpdateSurface - Call ", __FUNCTION__, mip ); + if ( !pSrcSurf || !pDstSurf || Dx9Device()->UpdateSurface( pSrcSurf, NULL, pDstSurf, NULL ) != S_OK ) + Warning( "LoadTextureFromVTF: surface update failed.\n" ); + } + + if ( pSrcSurf ) + pSrcSurf->Release(); + + if ( pDstSurf ) + pDstSurf->Release(); + } + } + + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s - Cleanup", __FUNCTION__ ); + pStagingTexture->Release(); + } +#endif +} + + +//----------------------------------------------------------------------------- +// Upload to a sub-piece of a texture +//----------------------------------------------------------------------------- +void LoadSubTexture( TextureLoadInfo_t &info, int xOffset, int yOffset, int srcStride ) +{ + Assert( info.m_pSrcData ); + Assert( info.m_pTexture ); + +#if defined( _X360 ) + // xboxissue - not supporting subrect swizzling + Assert( !info.m_bSrcIsTiled ); +#endif + +#ifdef _DEBUG + ImageFormat format = GetImageFormat( info.m_pTexture ); + Assert( (format == FindNearestSupportedFormat(format, false, false, false )) && (format != -1) ); +#endif + + // Copy in the bits... + BlitTextureBits( info, xOffset, yOffset, srcStride ); +} + + +//----------------------------------------------------------------------------- +// Returns the size of texture memory, in MB +//----------------------------------------------------------------------------- +// Helps with startup time.. we don't use the texture memory size for anything anyways +#define DONT_CHECK_MEM + +int ComputeTextureMemorySize( const GUID &nDeviceGUID, D3DDEVTYPE deviceType ) +{ +#if defined( _X360 ) + return 0; +#elif defined( DONT_CHECK_MEM ) + return (deviceType == D3DDEVTYPE_REF) ? (64 * 1024 * 1024) : 102236160; +#else + + FileHandle_t file = g_pFullFileSystem->Open( "vidcfg.bin", "rb", "EXECUTABLE_PATH" ); + if ( file ) + { + GUID deviceId; + int texSize; + g_pFullFileSystem->Read( &deviceId, sizeof(deviceId), file ); + g_pFullFileSystem->Read( &texSize, sizeof(texSize), file ); + g_pFullFileSystem->Close( file ); + if ( nDeviceGUID == deviceId ) + { + return texSize; + } + } + // How much texture memory? + if (deviceType == D3DDEVTYPE_REF) + return 64 * 1024 * 1024; + + // Sadly, the only way to compute texture memory size + // is to allocate a crapload of textures until we can't any more + ImageFormat fmt = FindNearestSupportedFormat( IMAGE_FORMAT_BGR565, false, false, false ); + int textureSize = ShaderUtil()->GetMemRequired( 256, 256, 1, fmt, false ); + + int totalSize = 0; + CUtlVector< IDirect3DBaseTexture* > textures; + + s_bTestingVideoMemorySize = true; + while (true) + { + RECORD_COMMAND( DX8_CREATE_TEXTURE, 7 ); + RECORD_INT( textures.Count() ); + RECORD_INT( 256 ); + RECORD_INT( 256 ); + RECORD_INT( ImageLoader::ImageFormatToD3DFormat(fmt) ); + RECORD_INT( 1 ); + RECORD_INT( false ); + RECORD_INT( 1 ); + + IDirect3DBaseTexture* pTex = CreateD3DTexture( 256, 256, 1, fmt, 1, 0 ); + if (!pTex) + break; + totalSize += textureSize; + + textures.AddToTail( pTex ); + } + s_bTestingVideoMemorySize = false; + + // Free all the temp textures + for (int i = textures.Size(); --i >= 0; ) + { + RECORD_COMMAND( DX8_DESTROY_TEXTURE, 1 ); + RECORD_INT( i ); + + DestroyD3DTexture( textures[i] ); + } + + file = g_pFullFileSystem->Open( "vidcfg.bin", "wb", "EXECUTABLE_PATH" ); + if ( file ) + { + g_pFullFileSystem->Write( &nDeviceGUID, sizeof(GUID), file ); + g_pFullFileSystem->Write( &totalSize, sizeof(totalSize), file ); + g_pFullFileSystem->Close( file ); + } + + return totalSize; +#endif +} diff --git a/materialsystem/shaderapidx9/texturedx8.h b/materialsystem/shaderapidx9/texturedx8.h new file mode 100644 index 0000000..2901798 --- /dev/null +++ b/materialsystem/shaderapidx9/texturedx8.h @@ -0,0 +1,110 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +// +//=============================================================================// + +#ifndef TEXTUREDX8_H +#define TEXTUREDX8_H + +#ifdef _WIN32 +#pragma once +#endif + +#include "togl/rendermechanism.h" +#include "bitmap/imageformat.h" +#include "locald3dtypes.h" +#include "shaderapi/ishaderapi.h" + + +//----------------------------------------------------------------------------- +// Forward declarations +//----------------------------------------------------------------------------- +class CPixelWriter; + + +//----------------------------------------------------------------------------- +// Returns the size of texture memory +//----------------------------------------------------------------------------- +int ComputeTextureMemorySize( const GUID &nDeviceId, D3DDEVTYPE deviceType ); + + +//----------------------------------------------------------------------------- +// Texture creation +//----------------------------------------------------------------------------- +IDirect3DBaseTexture *CreateD3DTexture( int width, int height, int depth, + ImageFormat dstFormat, int numLevels, int creationFlags, char *debugLabel=NULL ); // OK to not-supply the last param + + +//----------------------------------------------------------------------------- +// Texture destruction +//----------------------------------------------------------------------------- +void DestroyD3DTexture( IDirect3DBaseTexture *pTex ); + +int GetD3DTextureRefCount( IDirect3DBaseTexture *pTex ); + + +//----------------------------------------------------------------------------- +// Texture heap methods +//----------------------------------------------------------------------------- +#if defined( _X360 ) +void SetD3DTextureImmobile( IDirect3DBaseTexture *pTex, bool bImmobile ); +void CompactTextureHeap(); +#endif + +//----------------------------------------------------------------------------- +// Stats... +//----------------------------------------------------------------------------- +int TextureCount(); + + +//----------------------------------------------------------------------------- +// Info for texture loading +//----------------------------------------------------------------------------- +struct TextureLoadInfo_t +{ + ShaderAPITextureHandle_t m_TextureHandle; + int m_nCopy; + IDirect3DBaseTexture *m_pTexture; + int m_nLevel; + D3DCUBEMAP_FACES m_CubeFaceID; + int m_nWidth; + int m_nHeight; + int16 m_nZOffset; // What z-slice of the volume texture are we loading? +#if defined( _X360 ) + bool m_bSrcIsTiled; // format may not be, but data could be + bool m_bCanConvertFormat; // allow format conversion +#else + bool m_bTextureIsLockable; +#endif + ImageFormat m_SrcFormat; + unsigned char *m_pSrcData; +}; + + +//----------------------------------------------------------------------------- +// Texture image upload +//----------------------------------------------------------------------------- +void LoadTexture( TextureLoadInfo_t &info ); +void LoadTextureFromVTF( TextureLoadInfo_t &info, IVTFTexture* pVTF, int iVTFFrame ); +void LoadCubeTextureFromVTF( TextureLoadInfo_t &info, IVTFTexture* pVTF, int iVTFFrame ); +void LoadVolumeTextureFromVTF( TextureLoadInfo_t &info, IVTFTexture* pVTF, int iVTFFrame ); + +//----------------------------------------------------------------------------- +// Upload to a sub-piece of a texture +//----------------------------------------------------------------------------- +void LoadSubTexture( TextureLoadInfo_t &info, int xOffset, int yOffset, int srcStride ); + +//----------------------------------------------------------------------------- +// Lock, unlock a texture... +//----------------------------------------------------------------------------- +bool LockTexture( ShaderAPITextureHandle_t textureHandle, int copy, IDirect3DBaseTexture* pTexture, int level, + D3DCUBEMAP_FACES cubeFaceID, int xOffset, int yOffset, int width, int height, bool bDiscard, + CPixelWriter& writer ); + +void UnlockTexture( ShaderAPITextureHandle_t textureHandle, int copy, IDirect3DBaseTexture* pTexture, int level, + D3DCUBEMAP_FACES cubeFaceID ); + +#endif // TEXTUREDX8_H \ No newline at end of file diff --git a/materialsystem/shaderapidx9/textureheap.cpp b/materialsystem/shaderapidx9/textureheap.cpp new file mode 100644 index 0000000..b2c9a66 --- /dev/null +++ b/materialsystem/shaderapidx9/textureheap.cpp @@ -0,0 +1,1258 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//============================================================================= + +#include "tier1/mempool.h" +#include "tier1/convar.h" +#include "tier1/utlmap.h" +#include "shaderapidx8.h" +#include "texturedx8.h" +#include "textureheap.h" +#include "shaderapidx8_global.h" + +#include "tier0/memdbgon.h" + +#define USE_STANDARD_ALLOCATOR +#ifdef USE_STANDARD_ALLOCATOR +#define UseStandardAllocator() (true) +#elif !defined(_RETAIL) +bool g_bUseStandardAllocator = false; +bool UseStandardAllocator() +{ + static bool bReadCommandLine; + if ( !bReadCommandLine ) + { + bReadCommandLine = true; + const char *pStr = Plat_GetCommandLine(); + if ( pStr ) + { + char tempStr[512]; + Q_strncpy( tempStr, pStr, sizeof( tempStr ) - 1 ); + tempStr[ sizeof( tempStr ) - 1 ] = 0; + _strlwr( tempStr ); + + if ( strstr( tempStr, "-notextureheap" ) ) + g_bUseStandardAllocator = true; + } + } + return g_bUseStandardAllocator; +} +#else +#define UseStandardAllocator() (false) +#endif + +#if !defined( _RELEASE ) && !defined( _RETAIL ) +#define StrongAssert( expr ) if ( (expr) ) ; else { DebuggerBreak(); } +#else +#define StrongAssert( expr ) ((void)0) +#endif + +//----------------------------------------------------------------------------- +// Get Texture HW base +//----------------------------------------------------------------------------- +void *GetD3DTextureBasePtr( IDirect3DBaseTexture* pTex ) +{ + // assumes base and mips are contiguous + return (void *)( (unsigned int)pTex->Format.BaseAddress << 12 ); +} + +class CD3DTextureAllocator +{ +public: + static void *Alloc( int bytes ) + { + DWORD attributes = MAKE_XALLOC_ATTRIBUTES( + 0, + false, + TRUE, + FALSE, + eXALLOCAllocatorId_D3D, + XALLOC_PHYSICAL_ALIGNMENT_4K, + XALLOC_MEMPROTECT_WRITECOMBINE, + FALSE, + XALLOC_MEMTYPE_PHYSICAL ); + m_nTotalAllocations++; + m_nTotalSize += AlignValue( bytes, 4096 ); + return XMemAlloc( bytes, attributes ); + } + + static void Free( void *p ) + { + DWORD attributes = MAKE_XALLOC_ATTRIBUTES( + 0, + false, + TRUE, + FALSE, + eXALLOCAllocatorId_D3D, + XALLOC_PHYSICAL_ALIGNMENT_4K, + XALLOC_MEMPROTECT_WRITECOMBINE, + FALSE, + XALLOC_MEMTYPE_PHYSICAL ); + m_nTotalAllocations--; + m_nTotalSize -= XMemSize( p, attributes ); + XMemFree( p, attributes ); + } + + static int GetAllocations() + { + return m_nTotalAllocations; + } + + static int GetSize() + { + return m_nTotalSize; + } + + static int m_nTotalSize; + static int m_nTotalAllocations; +}; + +int CD3DTextureAllocator::m_nTotalSize; +int CD3DTextureAllocator::m_nTotalAllocations; + +enum TextureAllocator_t +{ + TA_DEFAULT, + TA_MIXED, + TA_UNKNOWN, +}; + +struct THBaseInfo +{ + TextureAllocator_t m_fAllocator; + int m_TextureSize; // stored for delayed allocations +}; + +struct THInfo_t : public THBaseInfo +{ + // Mixed heap info + int nLogicalBytes; + int nBytes; + bool bFree:1; + bool bNonTexture:1; + + THInfo_t *pPrev, *pNext; +}; + +struct THFreeBlock_t +{ + THInfo_t heapInfo; + THFreeBlock_t *pPrevFree, *pNextFree; +}; + +class CXboxTexture : public IDirect3DTexture, public THInfo_t +{ +public: + CXboxTexture() + : bImmobile(false) + { + } + + bool bImmobile; + bool CanRelocate() { return ( !bImmobile && !IsBusy() ); } +}; + +class CXboxCubeTexture : public IDirect3DCubeTexture, public THBaseInfo +{ +}; + +class CXboxVolumeTexture : public IDirect3DVolumeTexture, public THBaseInfo +{ +}; + + +void SetD3DTextureImmobile( IDirect3DBaseTexture *pTexture, bool bImmobile ) +{ + if ( pTexture->GetType() == D3DRTYPE_TEXTURE ) + { + (( CXboxTexture *)pTexture)->bImmobile = bImmobile; + } +} + +CXboxTexture *GetTexture( THInfo_t *pInfo ) +{ + if ( !pInfo->bFree && !pInfo->bNonTexture ) + { + return (CXboxTexture *)((byte *)pInfo - offsetof( CXboxTexture, m_fAllocator )); + } + return NULL; +} + +inline THFreeBlock_t *GetFreeBlock( THInfo_t *pInfo ) +{ + if ( pInfo->bFree ) + { + return (THFreeBlock_t *)((byte *)pInfo - offsetof( THFreeBlock_t, heapInfo )); + } + return NULL; +} + +class CMixedTextureHeap +{ + enum + { + SIZE_ALIGNMENT = XBOX_HDD_SECTORSIZE, + MIN_BLOCK_SIZE = 1024, + }; +public: + + CMixedTextureHeap() : + m_nLogicalBytes( 0 ), + m_nActualBytes( 0 ), + m_nAllocs( 0 ), + m_nOldBytes( 0 ), + m_nNonTextureAllocs( 0 ), + m_nBytesTotal( 0 ), + m_pBase( NULL ), + m_pFirstFree( NULL ) + { + } + + void Init() + { + extern ConVar mat_texturecachesize; + MEM_ALLOC_CREDIT_("CMixedTextureHeap"); + + m_nBytesTotal = ( mat_texturecachesize.GetInt() * 1024 * 1024 ); +#if 0 + m_nBytesTotal = AlignValue( m_nBytesTotal, SIZE_ALIGNMENT ); + m_pBase = CD3DTextureAllocator::Alloc( m_nBytesTotal ); +#else + m_nBytesTotal = AlignValue( m_nBytesTotal, 16*1024*1024 ); + m_pBase = XPhysicalAlloc( m_nBytesTotal, MAXULONG_PTR, 4096, PAGE_READWRITE | PAGE_WRITECOMBINE | MEM_16MB_PAGES ); +#endif + m_pFirstFree = (THFreeBlock_t *)m_pBase; + + + m_pFirstFree->heapInfo.bFree = true; + m_pFirstFree->heapInfo.bNonTexture = false; + m_pFirstFree->heapInfo.nBytes = m_nBytesTotal; + m_pFirstFree->heapInfo.pNext = NULL; + m_pFirstFree->heapInfo.pPrev = NULL; + m_pFirstFree->pNextFree = NULL; + m_pFirstFree->pPrevFree = NULL; + + m_pLastFree = m_pFirstFree; + } + + void *Alloc( int bytes, THInfo_t *pInfo, bool bNonTexture = false ) + { + pInfo->nBytes = AlignValue( bytes, SIZE_ALIGNMENT ); + + if ( !m_pBase ) + { + Init(); + } + + if ( bNonTexture && m_nNonTextureAllocs == 0 ) + { + Compact(); + } + + void *p = FindBlock( pInfo ); + + if ( !p ) + { + p = ExpandToFindBlock( pInfo ); + } + + if ( p ) + { + pInfo->nLogicalBytes = bytes; + pInfo->bNonTexture = bNonTexture; + m_nLogicalBytes += bytes; + if ( !IsRetail() ) + { + m_nOldBytes += AlignValue( bytes, 4096 ); + } + m_nActualBytes += pInfo->nBytes; + m_nAllocs++; + + if ( bNonTexture ) + { + m_nNonTextureAllocs++; + } + } + return p; + } + + void Free( void *p, THInfo_t *pInfo ) + { + if ( !p ) + { + return; + } + + if ( !IsRetail() ) + { + m_nOldBytes -= AlignValue( pInfo->nLogicalBytes, 4096 ); + } + + if ( pInfo->bNonTexture ) + { + m_nNonTextureAllocs--; + } + + m_nLogicalBytes -= pInfo->nLogicalBytes; + m_nAllocs--; + m_nActualBytes -= pInfo->nBytes; + + THFreeBlock_t *pFree = (THFreeBlock_t *)p; + pFree->heapInfo = *pInfo; + pFree->heapInfo.bFree = true; + + AddToBlocksList( &pFree->heapInfo, pFree->heapInfo.pPrev, pFree->heapInfo.pNext ); + + pFree = MergeLeft( pFree ); + pFree = MergeRight( pFree ); + + AddToFreeList( pFree ); + + if ( pInfo->bNonTexture && m_nNonTextureAllocs == 0 ) + { + Compact(); + } + } + + int Size( void *p, THInfo_t *pInfo ) + { + return AlignValue( pInfo->nBytes, SIZE_ALIGNMENT ); + } + + bool IsOwner( void *p ) + { + return ( m_pBase && p >= m_pBase && p < (byte *)m_pBase + m_nBytesTotal ); + } + + //----------------------------------------------------- + + void *FindBlock( THInfo_t *pInfo ) + { + THFreeBlock_t *pCurrent = m_pFirstFree; + + int nBytesDesired = pInfo->nBytes; + + // Find the first block big enough to hold, then split it if appropriate + while ( pCurrent && pCurrent->heapInfo.nBytes < nBytesDesired ) + { + pCurrent = pCurrent->pNextFree; + } + + if ( pCurrent ) + { + return ClaimBlock( pCurrent, pInfo ); + } + + return NULL; + } + + void AddToFreeList( THFreeBlock_t *pFreeBlock ) + { + if ( !IsRetail() ) + { + pFreeBlock->heapInfo.nLogicalBytes = 0; + } + + if ( m_pFirstFree ) + { + THFreeBlock_t *pPrev = NULL; + THFreeBlock_t *pNext = m_pFirstFree; + + int nBytes = pFreeBlock->heapInfo.nBytes; + + while ( pNext && pNext->heapInfo.nBytes < nBytes ) + { + pPrev = pNext; + pNext = pNext->pNextFree; + } + + pFreeBlock->pPrevFree = pPrev; + pFreeBlock->pNextFree = pNext; + + if ( pPrev ) + { + pPrev->pNextFree = pFreeBlock; + } + else + { + m_pFirstFree = pFreeBlock; + } + + if ( pNext ) + { + pNext->pPrevFree = pFreeBlock; + } + else + { + m_pLastFree = pFreeBlock; + } + } + else + { + pFreeBlock->pPrevFree = pFreeBlock->pNextFree = NULL; + m_pLastFree = m_pFirstFree = pFreeBlock; + } + } + + void RemoveFromFreeList( THFreeBlock_t *pFreeBlock ) + { + if ( m_pFirstFree == pFreeBlock ) + { + m_pFirstFree = m_pFirstFree->pNextFree; + } + else if ( pFreeBlock->pPrevFree ) + { + pFreeBlock->pPrevFree->pNextFree = pFreeBlock->pNextFree; + } + + if ( m_pLastFree == pFreeBlock ) + { + m_pLastFree = pFreeBlock->pPrevFree; + } + else if ( pFreeBlock->pNextFree ) + { + pFreeBlock->pNextFree->pPrevFree = pFreeBlock->pPrevFree; + } + + pFreeBlock->pPrevFree = pFreeBlock->pNextFree = NULL; + } + + THFreeBlock_t *GetLastFree() + { + return m_pLastFree; + } + + void AddToBlocksList( THInfo_t *pBlock, THInfo_t *pPrev, THInfo_t *pNext ) + { + if ( pPrev ) + { + pPrev->pNext = pBlock; + } + + if ( pNext) + { + pNext->pPrev = pBlock; + } + + pBlock->pPrev = pPrev; + pBlock->pNext = pNext; + } + + void RemoveFromBlocksList( THInfo_t *pBlock ) + { + if ( pBlock->pPrev ) + { + pBlock->pPrev->pNext = pBlock->pNext; + } + + if ( pBlock->pNext ) + { + pBlock->pNext->pPrev = pBlock->pPrev; + } + } + + //----------------------------------------------------- + + void *ClaimBlock( THFreeBlock_t *pFreeBlock, THInfo_t *pInfo ) + { + RemoveFromFreeList( pFreeBlock ); + + int nBytesDesired = pInfo->nBytes; + int nBytesRemainder = pFreeBlock->heapInfo.nBytes - nBytesDesired; + *pInfo = pFreeBlock->heapInfo; + pInfo->bFree = false; + pInfo->bNonTexture = false; + if ( nBytesRemainder >= MIN_BLOCK_SIZE ) + { + pInfo->nBytes = nBytesDesired; + + THFreeBlock_t *pRemainder = (THFreeBlock_t *)(((byte *)(pFreeBlock)) + nBytesDesired); + pRemainder->heapInfo.bFree = true; + pRemainder->heapInfo.nBytes = nBytesRemainder; + + AddToBlocksList( &pRemainder->heapInfo, pInfo, pInfo->pNext ); + AddToFreeList( pRemainder ); + } + AddToBlocksList( pInfo, pInfo->pPrev, pInfo->pNext ); + return pFreeBlock; + } + + THFreeBlock_t *MergeLeft( THFreeBlock_t *pFree ) + { + THInfo_t *pPrev = pFree->heapInfo.pPrev; + if ( pPrev && pPrev->bFree ) + { + pPrev->nBytes += pFree->heapInfo.nBytes; + RemoveFromBlocksList( &pFree->heapInfo ); + pFree = GetFreeBlock( pPrev ); + RemoveFromFreeList( pFree ); + } + return pFree; + } + + THFreeBlock_t *MergeRight( THFreeBlock_t *pFree ) + { + THInfo_t *pNext = pFree->heapInfo.pNext; + if ( pNext && pNext->bFree ) + { + pFree->heapInfo.nBytes += pNext->nBytes; + RemoveFromBlocksList( pNext ); + RemoveFromFreeList( GetFreeBlock( pNext ) ); + } + return pFree; + } + + //----------------------------------------------------- + + bool GetExpansionList( THFreeBlock_t *pFreeBlock, THInfo_t **ppStart, THInfo_t **ppEnd, int depth = 1 ) + { + THInfo_t *pStart; + THInfo_t *pEnd; + int i; + + pStart = &pFreeBlock->heapInfo; + pEnd = &pFreeBlock->heapInfo; + + if ( m_nNonTextureAllocs > 0 ) + { + return false; + } + + // Walk backwards to start of expansion + i = depth; + while ( i > 0 && pStart->pPrev) + { + THInfo_t *pScan = pStart->pPrev; + + while ( i > 0 && pScan && !pScan->bFree && GetTexture( pScan )->CanRelocate() ) + { + pScan = pScan->pPrev; + i--; + } + + if ( !pScan || !pScan->bFree ) + { + break; + } + + pStart = pScan; + } + + // Walk forwards to start of expansion + i = depth; + while ( i > 0 && pEnd->pNext) + { + THInfo_t *pScan = pStart->pNext; + + while ( i > 0 && pScan && !pScan->bFree && GetTexture( pScan )->CanRelocate() ) + { + pScan = pScan->pNext; + i--; + } + + if ( !pScan || !pScan->bFree ) + { + break; + } + + pEnd = pScan; + } + + *ppStart = pStart; + *ppEnd = pEnd; + + return ( pStart != pEnd ); + } + + THFreeBlock_t *CompactExpansionList( THInfo_t *pStart, THInfo_t *pEnd ) + { +// X360TBD: +Assert( 0 ); +return NULL; +#if 0 +#ifdef TH_PARANOID + Validate(); +#endif + StrongAssert( pStart->bFree ); + StrongAssert( pEnd->bFree ); + byte *pNextBlock = (byte *)pStart; + + THInfo_t *pTextureBlock = pStart; + THInfo_t *pLastBlock = pStart->pPrev; + + while ( pTextureBlock != pEnd ) + { + CXboxTexture *pTexture = GetTexture( pTextureBlock ); + // If it's a texture, move it and thread it on. Otherwise, discard it + if ( pTexture ) + { + void *pTextureBits = GetD3DTextureBasePtr( pTexture ); + int nBytes = pTextureBlock->nBytes; + + if ( pNextBlock + nBytes <= pTextureBits) + { + memcpy( pNextBlock, pTextureBits, nBytes ); + } + else + { + memmove( pNextBlock, pTextureBits, nBytes ); + } + + pTexture->Data = 0; + pTexture->Register( pNextBlock ); + + pNextBlock += nBytes; + if ( pLastBlock) + { + pLastBlock->pNext = pTextureBlock; + } + pTextureBlock->pPrev = pLastBlock; + pLastBlock = pTextureBlock; + } + else + { + StrongAssert( pTextureBlock->bFree ); + RemoveFromFreeList( GetFreeBlock( pTextureBlock ) ); + } + pTextureBlock = pTextureBlock->pNext; + } + + RemoveFromFreeList( GetFreeBlock( pEnd ) ); + + // Make a new block and fix up the block lists + THFreeBlock_t *pFreeBlock = (THFreeBlock_t *)pNextBlock; + pFreeBlock->heapInfo.pPrev = pLastBlock; + pLastBlock->pNext = &pFreeBlock->heapInfo; + pFreeBlock->heapInfo.pNext = pEnd->pNext; + if ( pEnd->pNext ) + { + pEnd->pNext->pPrev = &pFreeBlock->heapInfo; + } + pFreeBlock->heapInfo.bFree = true; + pFreeBlock->heapInfo.nBytes = ( (byte *)pEnd - pNextBlock ) + pEnd->nBytes; + + AddToFreeList( pFreeBlock ); + +#ifdef TH_PARANOID + Validate(); +#endif + return pFreeBlock; +#endif + } + + THFreeBlock_t *ExpandBlock( THFreeBlock_t *pFreeBlock, int depth = 1 ) + { + THInfo_t *pStart; + THInfo_t *pEnd; + + if ( GetExpansionList( pFreeBlock, &pStart, &pEnd, depth ) ) + { + return CompactExpansionList( pStart, pEnd ); + } + + return pFreeBlock; + } + + THFreeBlock_t *ExpandBlockToFit( THFreeBlock_t *pFreeBlock, unsigned bytes ) + { + if ( pFreeBlock ) + { + THInfo_t *pStart; + THInfo_t *pEnd; + + if ( GetExpansionList( pFreeBlock, &pStart, &pEnd, 2 ) ) + { + unsigned sum = 0; + THInfo_t *pCurrent = pStart; + while( pCurrent != pEnd->pNext ) + { + if ( pCurrent->bFree ) + { + sum += pCurrent->nBytes; + } + pCurrent = pCurrent->pNext; + } + + if ( sum >= bytes ) + { + pFreeBlock = CompactExpansionList( pStart, pEnd ); + } + } + } + + return pFreeBlock; + } + + void *ExpandToFindBlock( THInfo_t *pInfo ) + { + THFreeBlock_t *pFreeBlock = ExpandBlockToFit( GetLastFree(), pInfo->nBytes ); + if ( pFreeBlock && pFreeBlock->heapInfo.nBytes >= pInfo->nBytes ) + { + return ClaimBlock( pFreeBlock, pInfo ); + } + return NULL; + } + + void Compact() + { + if ( m_nNonTextureAllocs > 0 ) + { + return; + } + + for (;;) + { + THFreeBlock_t *pCurrent = m_pFirstFree; + THFreeBlock_t *pNew; + while ( pCurrent ) + { + int nBytesOld = pCurrent->heapInfo.nBytes; + pNew = ExpandBlock( pCurrent, 999999 ); + + if ( pNew != pCurrent || pNew->heapInfo.nBytes != nBytesOld ) + { +#ifdef TH_PARANOID + Validate(); +#endif + break; + } + +#ifdef TH_PARANOID + pNew = ExpandBlock( pCurrent, 999999 ); + StrongAssert( pNew == pCurrent && pNew->heapInfo.nBytes == nBytesOld ); +#endif + + pCurrent = pCurrent->pNextFree; + } + + if ( !pCurrent ) + { + break; + } + } + } + + void Validate() + { + if ( !m_pFirstFree ) + { + return; + } + + if ( m_nNonTextureAllocs > 0 ) + { + return; + } + + THInfo_t *pLast = NULL; + THInfo_t *pInfo = &m_pFirstFree->heapInfo; + + while ( pInfo->pPrev ) + { + pInfo = pInfo->pPrev; + } + + void *pNextExpectedAddress = m_pBase; + + while ( pInfo ) + { + byte *pCurrentAddress = (byte *)(( pInfo->bFree ) ? GetFreeBlock( pInfo ) : GetD3DTextureBasePtr( GetTexture( pInfo ) ) ); + StrongAssert( pCurrentAddress == pNextExpectedAddress ); + StrongAssert( pInfo->pPrev == pLast ); + pNextExpectedAddress = pCurrentAddress + pInfo->nBytes; + pLast = pInfo; + pInfo = pInfo->pNext; + } + + THFreeBlock_t *pFree = m_pFirstFree; + THFreeBlock_t *pLastFree = NULL; + int nBytesHeap = XPhysicalSize( m_pBase ); + + while ( pFree ) + { + StrongAssert( pFree->pPrevFree == pLastFree ); + StrongAssert( (void *)pFree >= m_pBase && (void *)pFree < (byte *)m_pBase + nBytesHeap ); + StrongAssert( !pFree->pPrevFree || ( (void *)pFree->pPrevFree >= m_pBase && (void *)pFree->pPrevFree < (byte *)m_pBase + nBytesHeap ) ); + StrongAssert( !pFree->pNextFree || ( (void *)pFree->pNextFree >= m_pBase && (void *)pFree->pNextFree < (byte *)m_pBase + nBytesHeap ) ); + StrongAssert( !pFree->pPrevFree || pFree->pPrevFree->heapInfo.nBytes <= pFree->heapInfo.nBytes ); + pLastFree = pFree; + pFree = pFree->pNextFree; + } + } + + //----------------------------------------------------- + + THFreeBlock_t *m_pFirstFree; + THFreeBlock_t *m_pLastFree; + void *m_pBase; + + int m_nLogicalBytes; + int m_nActualBytes; + int m_nAllocs; + int m_nOldBytes; + int m_nNonTextureAllocs; + int m_nBytesTotal; +}; + +//----------------------------------------------------------------------------- + +inline TextureAllocator_t GetTextureAllocator( IDirect3DBaseTexture9 *pTexture ) +{ + return ( pTexture->GetType() == D3DRTYPE_CUBETEXTURE ) ? (( CXboxCubeTexture *)pTexture)->m_fAllocator : (( CXboxTexture *)pTexture)->m_fAllocator; +} + +//----------------------------------------------------------------------------- + +CMixedTextureHeap g_MixedTextureHeap; + +CON_COMMAND( mat_texture_heap_stats, "" ) +{ + if ( UseStandardAllocator() ) + { + Msg( "Texture heap stats: (Standard Allocator)\n" ); + Msg( "Allocations:%d Size:%d\n", CD3DTextureAllocator::GetAllocations(), CD3DTextureAllocator::GetSize() ); + } + else + { + Msg( "Texture heap stats:\n" ); + Msg( " Mixed textures: %dk/%dk allocated in %d textures\n", g_MixedTextureHeap.m_nLogicalBytes/1024, g_MixedTextureHeap.m_nActualBytes/1024, g_MixedTextureHeap.m_nAllocs ); + float oldFootprint = g_MixedTextureHeap.m_nOldBytes; + float newFootprint = g_MixedTextureHeap.m_nActualBytes; + Msg( "\n Old: %.3fmb, New: %.3fmb\n", oldFootprint / (1024.0*1024.0), newFootprint / (1024.0*1024.0) ); + } +} + +CON_COMMAND( mat_texture_heap_compact, "" ) +{ + Msg( "Validating texture heap...\n" ); + g_MixedTextureHeap.Validate(); + Msg( "Compacting texture heap...\n" ); + unsigned oldLargest = ( g_MixedTextureHeap.GetLastFree() ) ? g_MixedTextureHeap.GetLastFree()->heapInfo.nBytes : 0; + g_MixedTextureHeap.Compact(); + unsigned newLargest = ( g_MixedTextureHeap.GetLastFree() ) ? g_MixedTextureHeap.GetLastFree()->heapInfo.nBytes : 0; + + Msg( "\n Old largest block: %.3fk, New largest block: %.3fk\n\n", oldLargest / 1024.0, newLargest / 1024.0 ); + + Msg( "Validating texture heap...\n" ); + g_MixedTextureHeap.Validate(); + Msg( "Done.\n" ); +} + +//----------------------------------------------------------------------------- +// Nasty back doors +//----------------------------------------------------------------------------- + +void CompactTextureHeap() +{ + unsigned oldLargest = ( g_MixedTextureHeap.GetLastFree() ) ? g_MixedTextureHeap.GetLastFree()->heapInfo.nBytes : 0; + g_MixedTextureHeap.Compact(); + unsigned newLargest = ( g_MixedTextureHeap.GetLastFree() ) ? g_MixedTextureHeap.GetLastFree()->heapInfo.nBytes : 0; + + DevMsg( "Compacted texture heap. Old largest block: %.3fk, New largest block: %.3fk\n", oldLargest / 1024.0, newLargest / 1024.0 ); +} + +CTextureHeap g_TextureHeap; + +//----------------------------------------------------------------------------- +// Build and alloc a texture resource +//----------------------------------------------------------------------------- +IDirect3DTexture *CTextureHeap::AllocTexture( int width, int height, int levels, DWORD usage, D3DFORMAT d3dFormat, bool bFallback, bool bNoD3DMemory ) +{ + CXboxTexture* pD3DTexture = new CXboxTexture; + + // create a texture with contiguous mips and packed tails + DWORD dwTextureSize = XGSetTextureHeaderEx( + width, + height, + levels, + usage, + d3dFormat, + 0, + 0, + 0, + XGHEADER_CONTIGUOUS_MIP_OFFSET, + 0, + pD3DTexture, + NULL, + NULL ); + + // based on "Xbox 360 Texture Storage" + // can truncate the terminal tile using packed tails + // the terminal tile must be at 32x32 or 16x16 packed + if ( width == height && levels != 0 ) + { + int terminalWidth = width >> (levels - 1); + if ( d3dFormat == D3DFMT_DXT1 ) + { + if ( terminalWidth <= 32 ) + { + dwTextureSize -= 4*1024; + } + } + else if ( d3dFormat == D3DFMT_DXT5 ) + { + if ( terminalWidth == 32 ) + { + dwTextureSize -= 8*1024; + } + else if ( terminalWidth <= 16 ) + { + dwTextureSize -= 12*1024; + } + } + } + + pD3DTexture->m_TextureSize = dwTextureSize; + + if ( !bFallback && bNoD3DMemory ) + { + pD3DTexture->m_fAllocator = TA_UNKNOWN; + return pD3DTexture; + } + + void *pBuffer; + if ( UseStandardAllocator() ) + { + MEM_ALLOC_CREDIT_( __FILE__ ": Standard D3D" ); + pBuffer = CD3DTextureAllocator::Alloc( dwTextureSize ); + pD3DTexture->m_fAllocator = TA_DEFAULT; + } + else + { + MEM_ALLOC_CREDIT_( __FILE__ ": Mixed texture" ); + pBuffer = g_MixedTextureHeap.Alloc( dwTextureSize, pD3DTexture ); + if ( pBuffer ) + { + pD3DTexture->m_fAllocator = TA_MIXED; + } + else + { + g_MixedTextureHeap.Compact(); + pBuffer = g_MixedTextureHeap.Alloc( dwTextureSize, pD3DTexture ); + if ( pBuffer ) + { + pD3DTexture->m_fAllocator = TA_MIXED; + } + else + { + pBuffer = CD3DTextureAllocator::Alloc( dwTextureSize ); + pD3DTexture->m_fAllocator = TA_DEFAULT; + } + } + } + + if ( !pBuffer ) + { + delete pD3DTexture; + return NULL; + } + + XGOffsetResourceAddress( pD3DTexture, pBuffer ); + + return pD3DTexture; +} + +//----------------------------------------------------------------------------- +// Build and alloc a cube texture resource +//----------------------------------------------------------------------------- +IDirect3DCubeTexture *CTextureHeap::AllocCubeTexture( int width, int levels, DWORD usage, D3DFORMAT d3dFormat, bool bFallback, bool bNoD3DMemory ) +{ + CXboxCubeTexture* pD3DCubeTexture = new CXboxCubeTexture; + + // create a cube texture with contiguous mips and packed tails + DWORD dwTextureSize = XGSetCubeTextureHeaderEx( + width, + levels, + usage, + d3dFormat, + 0, + 0, + 0, + XGHEADER_CONTIGUOUS_MIP_OFFSET, + pD3DCubeTexture, + NULL, + NULL ); + pD3DCubeTexture->m_TextureSize = dwTextureSize; + + if ( !bFallback && bNoD3DMemory ) + { + pD3DCubeTexture->m_fAllocator = TA_UNKNOWN; + return pD3DCubeTexture; + } + + void *pBits; + if ( UseStandardAllocator() ) + { + MEM_ALLOC_CREDIT_( __FILE__ ": Cubemap standard D3D" ); + pBits = CD3DTextureAllocator::Alloc( dwTextureSize ); + pD3DCubeTexture->m_fAllocator = TA_DEFAULT; + } + else + { + // @todo: switch to texture heap + MEM_ALLOC_CREDIT_( __FILE__ ": Odd sized cubemap textures" ); + // Really only happens with environment map + pBits = CD3DTextureAllocator::Alloc( dwTextureSize ); + pD3DCubeTexture->m_fAllocator = TA_DEFAULT; + } + + if ( !pBits ) + { + delete pD3DCubeTexture; + return NULL; + } + + XGOffsetResourceAddress( pD3DCubeTexture, pBits ); + + return pD3DCubeTexture; +} + +//----------------------------------------------------------------------------- +// Allocate an Volume Texture +//----------------------------------------------------------------------------- +IDirect3DVolumeTexture *CTextureHeap::AllocVolumeTexture( int width, int height, int depth, int levels, DWORD usage, D3DFORMAT d3dFormat ) +{ + CXboxVolumeTexture *pD3DVolumeTexture = new CXboxVolumeTexture; + + // create a cube texture with contiguous mips and packed tails + DWORD dwTextureSize = XGSetVolumeTextureHeaderEx( + width, + height, + depth, + levels, + usage, + d3dFormat, + 0, + 0, + 0, + XGHEADER_CONTIGUOUS_MIP_OFFSET, + pD3DVolumeTexture, + NULL, + NULL ); + + void *pBits; + + MEM_ALLOC_CREDIT_( __FILE__ ": Volume standard D3D" ); + + pBits = CD3DTextureAllocator::Alloc( dwTextureSize ); + pD3DVolumeTexture->m_fAllocator = TA_DEFAULT; + pD3DVolumeTexture->m_TextureSize = dwTextureSize; + + if ( !pBits ) + { + delete pD3DVolumeTexture; + return NULL; + } + + XGOffsetResourceAddress( pD3DVolumeTexture, pBits ); + + return pD3DVolumeTexture; +} + +//----------------------------------------------------------------------------- +// Get current backbuffer multisample type (used in AllocRenderTargetSurface() ) +//----------------------------------------------------------------------------- +D3DMULTISAMPLE_TYPE CTextureHeap::GetBackBufferMultiSampleType() +{ + int backWidth, backHeight; + ShaderAPI()->GetBackBufferDimensions( backWidth, backHeight ); + + // 2xMSAA at 640x480 and 848x480 are the only supported multisample mode on 360 (2xMSAA for 720p would + // use predicated tiling, which would require a rewrite of *all* our render target code) + // FIXME: shuffle the EDRAM surfaces to allow 4xMSAA for standard def + // (they would overlap & trash each other with the current allocation scheme) + D3DMULTISAMPLE_TYPE backBufferMultiSampleType = g_pShaderDevice->IsAAEnabled() ? D3DMULTISAMPLE_2_SAMPLES : D3DMULTISAMPLE_NONE; + Assert( ( g_pShaderDevice->IsAAEnabled() == false ) || (backHeight == 480) ); + + return backBufferMultiSampleType; +} + +//----------------------------------------------------------------------------- +// Allocate an EDRAM surface +//----------------------------------------------------------------------------- +IDirect3DSurface *CTextureHeap::AllocRenderTargetSurface( int width, int height, D3DFORMAT d3dFormat, bool bMultiSample, int base ) +{ + // render target surfaces don't need to exist simultaneously + // force their allocations to overlap at the end of back buffer and zbuffer + // this should leave 3MB (of 10) free assuming 1280x720 (and 5MB with 640x480@2xMSAA) + D3DMULTISAMPLE_TYPE backBufferMultiSampleType = GetBackBufferMultiSampleType(); + D3DMULTISAMPLE_TYPE multiSampleType = bMultiSample ? backBufferMultiSampleType : D3DMULTISAMPLE_NONE; + if ( base < 0 ) + { + int backWidth, backHeight; + ShaderAPI()->GetBackBufferDimensions( backWidth, backHeight ); + D3DFORMAT backBufferFormat = ImageLoader::ImageFormatToD3DFormat( g_pShaderDevice->GetBackBufferFormat() ); + base = 2*XGSurfaceSize( backWidth, backHeight, backBufferFormat, backBufferMultiSampleType ); + } + + D3DSURFACE_PARAMETERS surfParameters; + surfParameters.Base = base; + surfParameters.ColorExpBias = 0; + + if ( ( d3dFormat == D3DFMT_D24FS8 ) || ( d3dFormat == D3DFMT_D24S8 ) || ( d3dFormat == D3DFMT_D16 ) ) + { + surfParameters.HierarchicalZBase = 0; + if ( ( surfParameters.HierarchicalZBase + XGHierarchicalZSize( width, height, multiSampleType ) ) > GPU_HIERARCHICAL_Z_TILES ) + { + // overflow, can't hold the tiles so disable + surfParameters.HierarchicalZBase = 0xFFFFFFFF; + } + } + else + { + // not using + surfParameters.HierarchicalZBase = 0xFFFFFFFF; + } + + HRESULT hr; + IDirect3DSurface9 *pSurface = NULL; + hr = Dx9Device()->CreateRenderTarget( width, height, d3dFormat, multiSampleType, 0, FALSE, &pSurface, &surfParameters ); + Assert( !FAILED( hr ) ); + + return pSurface; +} + +//----------------------------------------------------------------------------- +// Perform the real d3d allocation, returns true if succesful, false otherwise. +// Only valid for a texture created with no d3d bits, otherwise no-op. +//----------------------------------------------------------------------------- +bool CTextureHeap::AllocD3DMemory( IDirect3DBaseTexture *pD3DTexture ) +{ + if ( !pD3DTexture ) + { + return false; + } + + if ( pD3DTexture->GetType() == D3DRTYPE_SURFACE ) + { + // there are no d3d bits for a surface + return false; + } + + void *pBits = GetD3DTextureBasePtr( pD3DTexture ); + if ( pBits ) + { + // already have d3d bits + return true; + } + + if ( pD3DTexture->GetType() == D3DRTYPE_TEXTURE ) + { + MEM_ALLOC_CREDIT_( __FILE__ ": Standard D3D" ); + pBits = CD3DTextureAllocator::Alloc( ((CXboxTexture *)pD3DTexture)->m_TextureSize ); + ((CXboxTexture *)pD3DTexture)->m_fAllocator = TA_DEFAULT; + XGOffsetResourceAddress( (CXboxTexture *)pD3DTexture, pBits ); + return true; + } + else if ( pD3DTexture->GetType() == D3DRTYPE_CUBETEXTURE ) + { + MEM_ALLOC_CREDIT_( __FILE__ ": Cubemap standard D3D" ); + pBits = CD3DTextureAllocator::Alloc( ((CXboxCubeTexture *)pD3DTexture)->m_TextureSize ); + ((CXboxCubeTexture *)pD3DTexture)->m_fAllocator = TA_DEFAULT; + XGOffsetResourceAddress( (CXboxCubeTexture *)pD3DTexture, pBits ); + return true; + } + + return false; +} + +//----------------------------------------------------------------------------- +// Release the allocated store +//----------------------------------------------------------------------------- +void CTextureHeap::FreeTexture( IDirect3DBaseTexture *pD3DTexture ) +{ + if ( !pD3DTexture ) + { + return; + } + + if ( pD3DTexture->GetType() == D3DRTYPE_SURFACE ) + { + // texture heap doesn't own render target surfaces + // allow callers to call through for less higher level detection + int ref = ((IDirect3DSurface*)pD3DTexture)->Release(); + Assert( ref == 0 ); + ref = ref; // Quiet "unused variable" warning in release + return; + } + else + { + byte *pBits = (byte *)GetD3DTextureBasePtr( pD3DTexture ); + if ( pBits ) + { + switch ( GetTextureAllocator( pD3DTexture ) ) + { + case TA_DEFAULT: + CD3DTextureAllocator::Free( pBits ); + break; + + case TA_MIXED: + g_MixedTextureHeap.Free( pBits, ((CXboxTexture *)pD3DTexture) ); + break; + } + } + } + + if ( pD3DTexture->GetType() == D3DRTYPE_TEXTURE ) + { + delete (CXboxTexture *)pD3DTexture; + } + else if ( pD3DTexture->GetType() == D3DRTYPE_VOLUMETEXTURE ) + { + delete (CXboxVolumeTexture *)pD3DTexture; + } + else if ( pD3DTexture->GetType() == D3DRTYPE_CUBETEXTURE ) + { + delete (CXboxCubeTexture *)pD3DTexture; + } +} + +//----------------------------------------------------------------------------- +// Returns the allocated footprint +//----------------------------------------------------------------------------- +int CTextureHeap::GetSize( IDirect3DBaseTexture *pD3DTexture ) +{ + if( pD3DTexture == NULL ) + return 0; + + if ( pD3DTexture->GetType() == D3DRTYPE_SURFACE ) + { + D3DSURFACE_DESC surfaceDesc; + HRESULT hr = ((IDirect3DSurface*)pD3DTexture)->GetDesc( &surfaceDesc ); + Assert( !FAILED( hr ) ); + hr = hr; // Quiet "unused variable" warning in release + + int size = ImageLoader::GetMemRequired( + surfaceDesc.Width, + surfaceDesc.Height, + 0, + ImageLoader::D3DFormatToImageFormat( surfaceDesc.Format ), + false ); + + return size; + } + else if ( pD3DTexture->GetType() == D3DRTYPE_TEXTURE ) + { + return ((CXboxTexture *)pD3DTexture)->m_TextureSize; + } + else if ( pD3DTexture->GetType() == D3DRTYPE_CUBETEXTURE ) + { + return ((CXboxCubeTexture *)pD3DTexture)->m_TextureSize; + } + else if ( pD3DTexture->GetType() == D3DRTYPE_VOLUMETEXTURE ) + { + return ((CXboxVolumeTexture *)pD3DTexture)->m_TextureSize; + } + + return 0; +} + +//----------------------------------------------------------------------------- +// Crunch the pools +//----------------------------------------------------------------------------- +void CTextureHeap::Compact() +{ + g_MixedTextureHeap.Compact(); +} diff --git a/materialsystem/shaderapidx9/textureheap.h b/materialsystem/shaderapidx9/textureheap.h new file mode 100644 index 0000000..ceeb3a9 --- /dev/null +++ b/materialsystem/shaderapidx9/textureheap.h @@ -0,0 +1,42 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//============================================================================= + +#ifndef TEXTUREHEAP_H +#define TEXTUREHEAP_H + +#if defined( _X360 ) + +#include "locald3dtypes.h" + +class CTextureHeap +{ +public: + IDirect3DTexture *AllocTexture( int width, int height, int levels, DWORD usage, D3DFORMAT format, bool bFallback, bool bNoD3DMemory ); + IDirect3DCubeTexture *AllocCubeTexture( int width, int levels, DWORD usage, D3DFORMAT format, bool bFallback, bool bNoD3DMemory ); + IDirect3DVolumeTexture *AllocVolumeTexture( int width, int height, int depth, int levels, DWORD usage, D3DFORMAT format ); + IDirect3DSurface *AllocRenderTargetSurface( int width, int height, D3DFORMAT format, bool bMultiSample = false , int base = -1); + + // Perform the real d3d allocation, returns true if succesful, false otherwise. + // Only valid for a texture created with no d3d bits, otherwise no-op. + bool AllocD3DMemory( IDirect3DBaseTexture *pTexture ); + + // Release header and d3d bits. + void FreeTexture( IDirect3DBaseTexture *pTexture ); + + // Returns the amount of memory needed or allocated for the texture. + int GetSize( IDirect3DBaseTexture *pTexture ); + + // Crunch the heap. + void Compact(); + + // Get current backbuffer multisample type + D3DMULTISAMPLE_TYPE GetBackBufferMultiSampleType(); +}; + +extern CTextureHeap g_TextureHeap; + +#endif +#endif // TEXTUREHEAP_H diff --git a/materialsystem/shaderapidx9/vertexdecl.cpp b/materialsystem/shaderapidx9/vertexdecl.cpp new file mode 100644 index 0000000..3d70dbc --- /dev/null +++ b/materialsystem/shaderapidx9/vertexdecl.cpp @@ -0,0 +1,576 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +// +//===========================================================================// + +#undef PROTECTED_THINGS_ENABLE +#include "vertexdecl.h" // this includes inside the dx headers +#define PROTECTED_THINGS_ENABLE +#include "materialsystem/imaterialsystemhardwareconfig.h" +#include "shaderapidx8_global.h" +#include "tier0/dbg.h" +#include "utlrbtree.h" +#include "recording.h" +#include "tier1/strtools.h" +#include "tier0/vprof.h" +#include "materialsystem/imesh.h" +#include "shaderdevicedx8.h" + +// NOTE: This has to be the last file included! +#include "tier0/memdbgon.h" + +//----------------------------------------------------------------------------- +// Computes the DX8 vertex specification +//----------------------------------------------------------------------------- +static const char *DeclTypeToString( BYTE type ) +{ + switch( type ) + { + case D3DDECLTYPE_FLOAT1: + return "D3DDECLTYPE_FLOAT1"; + case D3DDECLTYPE_FLOAT2: + return "D3DDECLTYPE_FLOAT2"; + case D3DDECLTYPE_FLOAT3: + return "D3DDECLTYPE_FLOAT3"; + case D3DDECLTYPE_FLOAT4: + return "D3DDECLTYPE_FLOAT4"; + case D3DDECLTYPE_D3DCOLOR: + return "D3DDECLTYPE_D3DCOLOR"; + case D3DDECLTYPE_UBYTE4: + return "D3DDECLTYPE_UBYTE4"; + case D3DDECLTYPE_SHORT2: + return "D3DDECLTYPE_SHORT2"; + case D3DDECLTYPE_SHORT4: + return "D3DDECLTYPE_SHORT4"; + case D3DDECLTYPE_UBYTE4N: + return "D3DDECLTYPE_UBYTE4N"; + case D3DDECLTYPE_SHORT2N: + return "D3DDECLTYPE_SHORT2N"; + case D3DDECLTYPE_SHORT4N: + return "D3DDECLTYPE_SHORT4N"; + case D3DDECLTYPE_USHORT2N: + return "D3DDECLTYPE_USHORT2N"; + case D3DDECLTYPE_USHORT4N: + return "D3DDECLTYPE_USHORT4N"; + case D3DDECLTYPE_UDEC3: + return "D3DDECLTYPE_UDEC3"; + case D3DDECLTYPE_DEC3N: + return "D3DDECLTYPE_DEC3N"; + case D3DDECLTYPE_FLOAT16_2: + return "D3DDECLTYPE_FLOAT16_2"; + case D3DDECLTYPE_FLOAT16_4: + return "D3DDECLTYPE_FLOAT16_4"; + default: + Assert( 0 ); + return "ERROR"; + } +} + +static const char *DeclMethodToString( BYTE method ) +{ + switch( method ) + { + case D3DDECLMETHOD_DEFAULT: + return "D3DDECLMETHOD_DEFAULT"; + case D3DDECLMETHOD_PARTIALU: + return "D3DDECLMETHOD_PARTIALU"; + case D3DDECLMETHOD_PARTIALV: + return "D3DDECLMETHOD_PARTIALV"; + case D3DDECLMETHOD_CROSSUV: + return "D3DDECLMETHOD_CROSSUV"; + case D3DDECLMETHOD_UV: + return "D3DDECLMETHOD_UV"; + case D3DDECLMETHOD_LOOKUP: + return "D3DDECLMETHOD_LOOKUP"; + case D3DDECLMETHOD_LOOKUPPRESAMPLED: + return "D3DDECLMETHOD_LOOKUPPRESAMPLED"; + default: + Assert( 0 ); + return "ERROR"; + } +} + +static const char *DeclUsageToString( BYTE usage ) +{ + switch( usage ) + { + case D3DDECLUSAGE_POSITION: + return "D3DDECLUSAGE_POSITION"; + case D3DDECLUSAGE_BLENDWEIGHT: + return "D3DDECLUSAGE_BLENDWEIGHT"; + case D3DDECLUSAGE_BLENDINDICES: + return "D3DDECLUSAGE_BLENDINDICES"; + case D3DDECLUSAGE_NORMAL: + return "D3DDECLUSAGE_NORMAL"; + case D3DDECLUSAGE_PSIZE: + return "D3DDECLUSAGE_PSIZE"; + case D3DDECLUSAGE_COLOR: + return "D3DDECLUSAGE_COLOR"; + case D3DDECLUSAGE_TEXCOORD: + return "D3DDECLUSAGE_TEXCOORD"; + case D3DDECLUSAGE_TANGENT: + return "D3DDECLUSAGE_TANGENT"; + case D3DDECLUSAGE_BINORMAL: + return "D3DDECLUSAGE_BINORMAL"; + case D3DDECLUSAGE_TESSFACTOR: + return "D3DDECLUSAGE_TESSFACTOR"; +// case D3DDECLUSAGE_POSITIONTL: +// return "D3DDECLUSAGE_POSITIONTL"; + default: + Assert( 0 ); + return "ERROR"; + } +} + +static D3DDECLTYPE VertexElementToDeclType( VertexElement_t element, VertexCompressionType_t compressionType ) +{ + Detect_VertexElement_t_Changes( element ); + + if ( compressionType == VERTEX_COMPRESSION_ON ) + { + // Compressed-vertex element sizes + switch ( element ) + { +#if ( COMPRESSED_NORMALS_TYPE == COMPRESSED_NORMALS_SEPARATETANGENTS_SHORT2 ) + case VERTEX_ELEMENT_NORMAL: return D3DDECLTYPE_SHORT2; + case VERTEX_ELEMENT_USERDATA4: return D3DDECLTYPE_SHORT2; +#else //( COMPRESSED_NORMALS_TYPE == COMPRESSED_NORMALS_COMBINEDTANGENTS_UBYTE4 ) + case VERTEX_ELEMENT_NORMAL: return D3DDECLTYPE_UBYTE4; + case VERTEX_ELEMENT_USERDATA4: return D3DDECLTYPE_UBYTE4; +#endif + case VERTEX_ELEMENT_BONEWEIGHTS1: return D3DDECLTYPE_SHORT2; + case VERTEX_ELEMENT_BONEWEIGHTS2: return D3DDECLTYPE_SHORT2; + default: + break; + } + } + + // Uncompressed-vertex element sizes + switch ( element ) + { + case VERTEX_ELEMENT_POSITION: return D3DDECLTYPE_FLOAT3; + case VERTEX_ELEMENT_NORMAL: return D3DDECLTYPE_FLOAT3; + case VERTEX_ELEMENT_COLOR: return D3DDECLTYPE_D3DCOLOR; + case VERTEX_ELEMENT_SPECULAR: return D3DDECLTYPE_D3DCOLOR; + case VERTEX_ELEMENT_TANGENT_S: return D3DDECLTYPE_FLOAT3; + case VERTEX_ELEMENT_TANGENT_T: return D3DDECLTYPE_FLOAT3; + case VERTEX_ELEMENT_WRINKLE: + // Wrinkle is packed into Position.W, it is not specified as a separate vertex element + Assert( 0 ); + return D3DDECLTYPE_UNUSED; +#if !defined( _X360 ) + case VERTEX_ELEMENT_BONEINDEX: return D3DDECLTYPE_D3DCOLOR; +#else + // UBYTE4 comes in as [0,255] in the shader, which is ideal for bone indices + // (unfortunately, UBYTE4 is not universally supported on PC DX8 GPUs) + case VERTEX_ELEMENT_BONEINDEX: return D3DDECLTYPE_UBYTE4; +#endif + case VERTEX_ELEMENT_BONEWEIGHTS1: return D3DDECLTYPE_FLOAT1; + case VERTEX_ELEMENT_BONEWEIGHTS2: return D3DDECLTYPE_FLOAT2; + case VERTEX_ELEMENT_BONEWEIGHTS3: return D3DDECLTYPE_FLOAT3; + case VERTEX_ELEMENT_BONEWEIGHTS4: return D3DDECLTYPE_FLOAT4; + case VERTEX_ELEMENT_USERDATA1: return D3DDECLTYPE_FLOAT1; + case VERTEX_ELEMENT_USERDATA2: return D3DDECLTYPE_FLOAT2; + case VERTEX_ELEMENT_USERDATA3: return D3DDECLTYPE_FLOAT3; + case VERTEX_ELEMENT_USERDATA4: return D3DDECLTYPE_FLOAT4; + case VERTEX_ELEMENT_TEXCOORD1D_0: return D3DDECLTYPE_FLOAT1; + case VERTEX_ELEMENT_TEXCOORD1D_1: return D3DDECLTYPE_FLOAT1; + case VERTEX_ELEMENT_TEXCOORD1D_2: return D3DDECLTYPE_FLOAT1; + case VERTEX_ELEMENT_TEXCOORD1D_3: return D3DDECLTYPE_FLOAT1; + case VERTEX_ELEMENT_TEXCOORD1D_4: return D3DDECLTYPE_FLOAT1; + case VERTEX_ELEMENT_TEXCOORD1D_5: return D3DDECLTYPE_FLOAT1; + case VERTEX_ELEMENT_TEXCOORD1D_6: return D3DDECLTYPE_FLOAT1; + case VERTEX_ELEMENT_TEXCOORD1D_7: return D3DDECLTYPE_FLOAT1; + case VERTEX_ELEMENT_TEXCOORD2D_0: return D3DDECLTYPE_FLOAT2; + case VERTEX_ELEMENT_TEXCOORD2D_1: return D3DDECLTYPE_FLOAT2; + case VERTEX_ELEMENT_TEXCOORD2D_2: return D3DDECLTYPE_FLOAT2; + case VERTEX_ELEMENT_TEXCOORD2D_3: return D3DDECLTYPE_FLOAT2; + case VERTEX_ELEMENT_TEXCOORD2D_4: return D3DDECLTYPE_FLOAT2; + case VERTEX_ELEMENT_TEXCOORD2D_5: return D3DDECLTYPE_FLOAT2; + case VERTEX_ELEMENT_TEXCOORD2D_6: return D3DDECLTYPE_FLOAT2; + case VERTEX_ELEMENT_TEXCOORD2D_7: return D3DDECLTYPE_FLOAT2; + case VERTEX_ELEMENT_TEXCOORD3D_0: return D3DDECLTYPE_FLOAT3; + case VERTEX_ELEMENT_TEXCOORD3D_1: return D3DDECLTYPE_FLOAT3; + case VERTEX_ELEMENT_TEXCOORD3D_2: return D3DDECLTYPE_FLOAT3; + case VERTEX_ELEMENT_TEXCOORD3D_3: return D3DDECLTYPE_FLOAT3; + case VERTEX_ELEMENT_TEXCOORD3D_4: return D3DDECLTYPE_FLOAT3; + case VERTEX_ELEMENT_TEXCOORD3D_5: return D3DDECLTYPE_FLOAT3; + case VERTEX_ELEMENT_TEXCOORD3D_6: return D3DDECLTYPE_FLOAT3; + case VERTEX_ELEMENT_TEXCOORD3D_7: return D3DDECLTYPE_FLOAT3; + case VERTEX_ELEMENT_TEXCOORD4D_0: return D3DDECLTYPE_FLOAT4; + case VERTEX_ELEMENT_TEXCOORD4D_1: return D3DDECLTYPE_FLOAT4; + case VERTEX_ELEMENT_TEXCOORD4D_2: return D3DDECLTYPE_FLOAT4; + case VERTEX_ELEMENT_TEXCOORD4D_3: return D3DDECLTYPE_FLOAT4; + case VERTEX_ELEMENT_TEXCOORD4D_4: return D3DDECLTYPE_FLOAT4; + case VERTEX_ELEMENT_TEXCOORD4D_5: return D3DDECLTYPE_FLOAT4; + case VERTEX_ELEMENT_TEXCOORD4D_6: return D3DDECLTYPE_FLOAT4; + case VERTEX_ELEMENT_TEXCOORD4D_7: return D3DDECLTYPE_FLOAT4; + default: + Assert(0); + return D3DDECLTYPE_UNUSED; + }; +} + +void PrintVertexDeclaration( const D3DVERTEXELEMENT9 *pDecl ) +{ + int i; + static D3DVERTEXELEMENT9 declEnd = D3DDECL_END(); + for ( i = 0; ; i++ ) + { + if ( memcmp( &pDecl[i], &declEnd, sizeof( declEnd ) ) == 0 ) + { + Warning( "D3DDECL_END\n" ); + break; + } + Msg( "%d: Stream: %d, Offset: %d, Type: %s, Method: %s, Usage: %s, UsageIndex: %d\n", + i, ( int )pDecl[i].Stream, ( int )pDecl[i].Offset, + DeclTypeToString( pDecl[i].Type ), + DeclMethodToString( pDecl[i].Method ), + DeclUsageToString( pDecl[i].Usage ), + ( int )pDecl[i].UsageIndex ); + } +} + +//----------------------------------------------------------------------------- +// Converts format to a vertex decl +//----------------------------------------------------------------------------- +void ComputeVertexSpec( VertexFormat_t fmt, D3DVERTEXELEMENT9 *pDecl, bool bStaticLit, bool bUsingFlex, bool bUsingMorph ) +{ + int i = 0; + int offset = 0; + + VertexCompressionType_t compressionType = CompressionType( fmt ); + + if ( IsX360() ) + { + // On 360, there's a performance penalty for reading more than 2 streams in the vertex shader + // (we don't do this yet, but we should be aware if we start doing it) +#ifdef _DEBUG + int numStreams = 1 + ( bStaticLit ? 1 : 0 ) + ( bUsingFlex ? 1 : 0 ) + ( bUsingMorph ? 1 : 0 ); + Assert( numStreams <= 2 ); +#endif + } + + if ( fmt & VERTEX_POSITION ) + { + pDecl[i].Stream = 0; + pDecl[i].Offset = offset; + pDecl[i].Method = D3DDECLMETHOD_DEFAULT; + pDecl[i].Usage = D3DDECLUSAGE_POSITION; + pDecl[i].UsageIndex = 0; + pDecl[i].Type = VertexElementToDeclType( VERTEX_ELEMENT_POSITION, compressionType ); + offset += GetVertexElementSize( VERTEX_ELEMENT_POSITION, compressionType ); + ++i; + } + + int numBones = NumBoneWeights(fmt); + if ( numBones > 0 ) + { + pDecl[i].Stream = 0; + pDecl[i].Offset = offset; + pDecl[i].Method = D3DDECLMETHOD_DEFAULT; + pDecl[i].Usage = D3DDECLUSAGE_BLENDWEIGHT; + pDecl[i].UsageIndex = 0; + + // Always exactly two weights + pDecl[i].Type = VertexElementToDeclType( VERTEX_ELEMENT_BONEWEIGHTS2, compressionType ); + offset += GetVertexElementSize( VERTEX_ELEMENT_BONEWEIGHTS2, compressionType ); + ++i; + } + + if ( fmt & VERTEX_BONE_INDEX ) + { + // this isn't FVF!!!!! + pDecl[i].Stream = 0; + pDecl[i].Offset = offset; + pDecl[i].Method = D3DDECLMETHOD_DEFAULT; + pDecl[i].Usage = D3DDECLUSAGE_BLENDINDICES; + pDecl[i].UsageIndex = 0; + pDecl[i].Type = VertexElementToDeclType( VERTEX_ELEMENT_BONEINDEX, compressionType ); + offset += GetVertexElementSize( VERTEX_ELEMENT_BONEINDEX, compressionType ); + ++i; + } + + int normalOffset = -1; + if ( fmt & VERTEX_NORMAL ) + { + pDecl[i].Stream = 0; + pDecl[i].Offset = offset; + normalOffset = offset; + pDecl[i].Method = D3DDECLMETHOD_DEFAULT; + pDecl[i].Usage = D3DDECLUSAGE_NORMAL; + pDecl[i].UsageIndex = 0; + pDecl[i].Type = VertexElementToDeclType( VERTEX_ELEMENT_NORMAL, compressionType ); + offset += GetVertexElementSize( VERTEX_ELEMENT_NORMAL, compressionType ); + ++i; + } + + if ( fmt & VERTEX_COLOR ) + { + pDecl[i].Stream = 0; + pDecl[i].Offset = offset; + pDecl[i].Method = D3DDECLMETHOD_DEFAULT; + pDecl[i].Usage = D3DDECLUSAGE_COLOR; + pDecl[i].UsageIndex = 0; + pDecl[i].Type = VertexElementToDeclType( VERTEX_ELEMENT_COLOR, compressionType ); + offset += GetVertexElementSize( VERTEX_ELEMENT_COLOR, compressionType ); + ++i; + } + + if ( fmt & VERTEX_SPECULAR ) + { + Assert( !bStaticLit ); + pDecl[i].Stream = 0; + pDecl[i].Offset = offset; + pDecl[i].Method = D3DDECLMETHOD_DEFAULT; + pDecl[i].Usage = D3DDECLUSAGE_COLOR; + pDecl[i].UsageIndex = 1; // SPECULAR goes in the second COLOR slot + pDecl[i].Type = VertexElementToDeclType( VERTEX_ELEMENT_SPECULAR, compressionType ); + offset += GetVertexElementSize( VERTEX_ELEMENT_SPECULAR, compressionType ); + ++i; + } + + VertexElement_t texCoordDimensions[4] = { VERTEX_ELEMENT_TEXCOORD1D_0, + VERTEX_ELEMENT_TEXCOORD2D_0, + VERTEX_ELEMENT_TEXCOORD3D_0, + VERTEX_ELEMENT_TEXCOORD4D_0 }; + for ( int j = 0; j < VERTEX_MAX_TEXTURE_COORDINATES; ++j ) + { + int nCoordSize = TexCoordSize( j, fmt ); + if ( nCoordSize <= 0 ) + continue; + Assert( nCoordSize <= 4 ); + + pDecl[i].Stream = 0; + pDecl[i].Offset = offset; + pDecl[i].Method = D3DDECLMETHOD_DEFAULT; + pDecl[i].Usage = D3DDECLUSAGE_TEXCOORD; + pDecl[i].UsageIndex = j; + VertexElement_t texCoordElement = (VertexElement_t)( texCoordDimensions[ nCoordSize - 1 ] + j ); + pDecl[i].Type = VertexElementToDeclType( texCoordElement, compressionType ); + offset += GetVertexElementSize( texCoordElement, compressionType ); + ++i; + } + + if ( fmt & VERTEX_TANGENT_S ) + { + pDecl[i].Stream = 0; + pDecl[i].Offset = offset; + pDecl[i].Method = D3DDECLMETHOD_DEFAULT; + pDecl[i].Usage = D3DDECLUSAGE_TANGENT; + pDecl[i].UsageIndex = 0; + // NOTE: this is currently *not* compressed + pDecl[i].Type = VertexElementToDeclType( VERTEX_ELEMENT_TANGENT_S, compressionType ); + offset += GetVertexElementSize( VERTEX_ELEMENT_TANGENT_S, compressionType ); + ++i; + } + + if ( fmt & VERTEX_TANGENT_T ) + { + pDecl[i].Stream = 0; + pDecl[i].Offset = offset; + pDecl[i].Method = D3DDECLMETHOD_DEFAULT; + pDecl[i].Usage = D3DDECLUSAGE_BINORMAL; + pDecl[i].UsageIndex = 0; + // NOTE: this is currently *not* compressed + pDecl[i].Type = VertexElementToDeclType( VERTEX_ELEMENT_TANGENT_T, compressionType ); + offset += GetVertexElementSize( VERTEX_ELEMENT_TANGENT_T, compressionType ); + ++i; + } + + int userDataSize = UserDataSize(fmt); + if ( userDataSize > 0 ) + { + Assert( userDataSize == 4 ); // This is actually only ever used for tangents + pDecl[i].Stream = 0; + if ( ( compressionType == VERTEX_COMPRESSION_ON ) && + ( COMPRESSED_NORMALS_TYPE == COMPRESSED_NORMALS_COMBINEDTANGENTS_UBYTE4 ) ) + { + // FIXME: Normals and tangents are packed together into a single UBYTE4 element, + // so just point this back at the same data while we're testing UBYTE4 out. + pDecl[i].Offset = normalOffset; + } + else + { + pDecl[i].Offset = offset; + } + pDecl[i].Method = D3DDECLMETHOD_DEFAULT; + pDecl[i].Usage = D3DDECLUSAGE_TANGENT; + pDecl[i].UsageIndex = 0; + VertexElement_t userDataElement = (VertexElement_t)( VERTEX_ELEMENT_USERDATA1 + ( userDataSize - 1 ) ); + pDecl[i].Type = VertexElementToDeclType( userDataElement, compressionType ); + offset += GetVertexElementSize( userDataElement, compressionType ); + ++i; + } + + if ( bStaticLit ) + { + // force stream 1 to have specular color in it, which is used for baked static lighting + pDecl[i].Stream = 1; + pDecl[i].Offset = 0; + pDecl[i].Method = D3DDECLMETHOD_DEFAULT; + pDecl[i].Usage = D3DDECLUSAGE_COLOR; + pDecl[i].UsageIndex = 1; // SPECULAR goes into the second COLOR slot + pDecl[i].Type = VertexElementToDeclType( VERTEX_ELEMENT_SPECULAR, compressionType ); + ++i; + } + + if ( HardwareConfig()->SupportsVertexAndPixelShaders() ) + { + // FIXME: There needs to be a better way of doing this + // In 2.0b, assume position is 4d, storing wrinkle in pos.w. + bool bUseWrinkle = HardwareConfig()->SupportsPixelShaders_2_b(); + + // Force stream 2 to have flex deltas in it + pDecl[i].Stream = 2; + pDecl[i].Offset = 0; + pDecl[i].Method = D3DDECLMETHOD_DEFAULT; + pDecl[i].Usage = D3DDECLUSAGE_POSITION; + pDecl[i].UsageIndex = 1; + // FIXME: unify this with VertexElementToDeclType(): + pDecl[i].Type = bUseWrinkle ? D3DDECLTYPE_FLOAT4 : D3DDECLTYPE_FLOAT3; + ++i; + + int normalOffset = GetVertexElementSize( VERTEX_ELEMENT_POSITION, compressionType ); + if ( bUseWrinkle ) + { + normalOffset += GetVertexElementSize( VERTEX_ELEMENT_WRINKLE, compressionType ); + } + + // Normal deltas + pDecl[i].Stream = 2; + pDecl[i].Offset = normalOffset; + pDecl[i].Method = D3DDECLMETHOD_DEFAULT; + pDecl[i].Usage = D3DDECLUSAGE_NORMAL; + pDecl[i].UsageIndex = 1; + // NOTE: this is currently *not* compressed + pDecl[i].Type = VertexElementToDeclType( VERTEX_ELEMENT_NORMAL, VERTEX_COMPRESSION_NONE ); + ++i; + } + + if ( bUsingMorph ) + { + // force stream 3 to have vertex index in it, which is used for doing vertex texture reads + pDecl[i].Stream = 3; + pDecl[i].Offset = 0; + pDecl[i].Method = D3DDECLMETHOD_DEFAULT; + pDecl[i].Usage = D3DDECLUSAGE_POSITION; + pDecl[i].UsageIndex = 2; + pDecl[i].Type = VertexElementToDeclType( VERTEX_ELEMENT_USERDATA1, compressionType ); + ++i; + } + + static D3DVERTEXELEMENT9 declEnd = D3DDECL_END(); + pDecl[i] = declEnd; + + //PrintVertexDeclaration( pDecl ); +} + +//----------------------------------------------------------------------------- +// Gets the declspec associated with a vertex format +//----------------------------------------------------------------------------- +struct VertexDeclLookup_t +{ + enum LookupFlags_t + { + STATIC_LIT = 0x1, + USING_MORPH = 0x2, + USING_FLEX = 0x4, + }; + + VertexFormat_t m_VertexFormat; + int m_nFlags; + IDirect3DVertexDeclaration9 *m_pDecl; + + bool operator==( const VertexDeclLookup_t &src ) const + { + return ( m_VertexFormat == src.m_VertexFormat ) && ( m_nFlags == src.m_nFlags ); + } +}; + + +//----------------------------------------------------------------------------- +// Dictionary of vertex decls +// FIXME: stick this in the class? +// FIXME: Does anything cause this to get flushed? +//----------------------------------------------------------------------------- +static bool VertexDeclLessFunc( const VertexDeclLookup_t &src1, const VertexDeclLookup_t &src2 ) +{ + if ( src1.m_nFlags == src2.m_nFlags ) + return src1.m_VertexFormat < src2.m_VertexFormat; + + return ( src1.m_nFlags < src2.m_nFlags ); +} + +static CUtlRBTree s_VertexDeclDict( 0, 256, VertexDeclLessFunc ); + +//----------------------------------------------------------------------------- +// Gets the declspec associated with a vertex format +//----------------------------------------------------------------------------- +IDirect3DVertexDeclaration9 *FindOrCreateVertexDecl( VertexFormat_t fmt, bool bStaticLit, bool bUsingFlex, bool bUsingMorph ) +{ + MEM_ALLOC_D3D_CREDIT(); + + VertexDeclLookup_t lookup; + lookup.m_VertexFormat = fmt; + lookup.m_nFlags = 0; + if ( bStaticLit ) + { + lookup.m_nFlags |= VertexDeclLookup_t::STATIC_LIT; + } + if ( bUsingMorph ) + { + lookup.m_nFlags |= VertexDeclLookup_t::USING_MORPH; + } + if ( bUsingFlex ) + { + lookup.m_nFlags |= VertexDeclLookup_t::USING_FLEX; + } + + int i = s_VertexDeclDict.Find( lookup ); + if ( i != s_VertexDeclDict.InvalidIndex() ) + { + // found + return s_VertexDeclDict[i].m_pDecl; + } + + D3DVERTEXELEMENT9 decl[32]; + ComputeVertexSpec( fmt, decl, bStaticLit, bUsingFlex, bUsingMorph ); + + HRESULT hr = + Dx9Device()->CreateVertexDeclaration( decl, &lookup.m_pDecl ); + + // NOTE: can't record until we have m_pDecl! + RECORD_COMMAND( DX8_CREATE_VERTEX_DECLARATION, 2 ); + RECORD_INT( ( int )lookup.m_pDecl ); + RECORD_STRUCT( decl, sizeof( decl ) ); + COMPILE_TIME_ASSERT( sizeof( decl ) == sizeof( D3DVERTEXELEMENT9 ) * 32 ); + + Assert( hr == D3D_OK ); + if ( hr != D3D_OK ) + { + Warning( " ERROR: failed to create vertex decl for vertex format 0x%08llX! You'll probably see messed-up mesh rendering - to diagnose, build shaderapidx9.dll in debug.\n", fmt ); + } + + s_VertexDeclDict.Insert( lookup ); + return lookup.m_pDecl; +} + + +//----------------------------------------------------------------------------- +// Clears out all declspecs +//----------------------------------------------------------------------------- +void ReleaseAllVertexDecl() +{ + int i = s_VertexDeclDict.FirstInorder(); + while ( i != s_VertexDeclDict.InvalidIndex() ) + { + if ( s_VertexDeclDict[i].m_pDecl ) + s_VertexDeclDict[i].m_pDecl->Release(); + i = s_VertexDeclDict.NextInorder( i ); + } +} + diff --git a/materialsystem/shaderapidx9/vertexdecl.h b/materialsystem/shaderapidx9/vertexdecl.h new file mode 100644 index 0000000..d275fdb --- /dev/null +++ b/materialsystem/shaderapidx9/vertexdecl.h @@ -0,0 +1,32 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +// +//=============================================================================// + +#ifndef VERTEXDECL_H +#define VERTEXDECL_H + +#ifdef _WIN32 +#pragma once +#endif + +#include "locald3dtypes.h" +#include "materialsystem/imaterial.h" + + +//----------------------------------------------------------------------------- +// Gets the declspec associated with a vertex format +//----------------------------------------------------------------------------- +IDirect3DVertexDeclaration9 *FindOrCreateVertexDecl( VertexFormat_t fmt, bool bStaticLit, bool bUsingFlex, bool bUsingMorph ); + +//----------------------------------------------------------------------------- +// Clears out all declspecs +//----------------------------------------------------------------------------- +void ReleaseAllVertexDecl( ); + + +#endif // VERTEXDECL_H + diff --git a/materialsystem/shaderapidx9/vertexshaderdx8.cpp b/materialsystem/shaderapidx9/vertexshaderdx8.cpp new file mode 100644 index 0000000..b3f1063 --- /dev/null +++ b/materialsystem/shaderapidx9/vertexshaderdx8.cpp @@ -0,0 +1,3783 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Vertex/Pixel Shaders +// +//===========================================================================// +#define DISABLE_PROTECTED_THINGS +#if ( defined(_WIN32) && !defined( _X360 ) ) +#elif POSIX +#include +#include +#include +#include +#include +#include +#include +#define closesocket close +#define WSAGetLastError() errno +#undef SOCKET +typedef int SOCKET; +#define SOCKET_ERROR (-1) +#define SD_SEND 0x01 +#define INVALID_SOCKET (~0) +#endif + +#include "togl/rendermechanism.h" +#include "vertexshaderdx8.h" +#include "tier1/utlsymbol.h" +#include "tier1/utlvector.h" +#include "tier1/utldict.h" +#include "tier1/utllinkedlist.h" +#include "tier1/utlbuffer.h" +#include "tier1/UtlStringMap.h" +#include "locald3dtypes.h" +#include "shaderapidx8_global.h" +#include "recording.h" +#include "tier0/vprof.h" +#include "materialsystem/imaterialsystem.h" +#include "materialsystem/imaterialsystemhardwareconfig.h" +#include "KeyValues.h" +#include "shaderapidx8.h" +#include "materialsystem/IShader.h" +#include "IShaderSystem.h" +#include "tier0/fasttimer.h" +#include +#include +#include +#include "filesystem.h" +#include "convar.h" +#include "materialsystem/shader_vcs_version.h" +#include "tier1/lzmaDecoder.h" +#include "tier1/utlmap.h" + +#include "datacache/idatacache.h" +#include "tier1/diff.h" +#include "shaderdevicedx8.h" +#include "filesystem/IQueuedLoader.h" +#include "tier2/tier2.h" +#include "shaderapi/ishaderutil.h" +#include "tier0/icommandline.h" + +#include "Color.h" +#include "tier0/dbg.h" + +#ifdef REMOTE_DYNAMIC_SHADER_COMPILE + +# if defined (POSIX) + +# include +# include + +# else + +# include +# include + +# endif + +#endif + +// NOTE: This has to be the last file included! +#include "tier0/memdbgon.h" + + +// It currently includes windows.h and we don't want that. +#ifdef USE_ACTUAL_DX + +#include "../utils/bzip2/bzlib.h" + +#else + +int BZ2_bzBuffToBuffDecompress( + char* dest, + unsigned int* destLen, + char* source, + unsigned int sourceLen, + int small, + int verbosity + ) +{ + return 0; +} + +#endif + +static ConVar mat_remoteshadercompile( "mat_remoteshadercompile", "127.0.0.1", FCVAR_CHEAT ); + +//#define PROFILE_SHADER_CREATE + +//#define NO_AMBIENT_CUBE +#define MAX_BONES 3 + +// debugging aid +#define MAX_SHADER_HISTORY 16 + +#if !defined( _X360 ) +#define SHADER_FNAME_EXTENSION ".vcs" +#else +#define SHADER_FNAME_EXTENSION ".360.vcs" +#endif + +#ifdef DYNAMIC_SHADER_COMPILE +volatile static char s_ShaderCompileString[]="dynamic_shader_compile_is_on"; +#endif + +#ifdef DYNAMIC_SHADER_COMPILE +static void MatFlushShaders( void ); +#endif + +// D3D to OpenGL translator +//static D3DToGL_ASM sg_D3DToOpenGLTranslator; // Remove the _ASM to switch to the new translator +//static D3DToGL sg_NewD3DToOpenGLTranslator; // Remove the _ASM to switch to the new translator + +static const char *GetLightTypeName( VertexShaderLightTypes_t type ) +{ + static const char *s_VertexShaderLightTypeNames[] = + { + "LIGHT_NONE", + "LIGHT_SPOT", + "LIGHT_POINT", + "LIGHT_DIRECTIONAL", + "LIGHT_STATIC", + "LIGHT_AMBIENTCUBE", + }; + return s_VertexShaderLightTypeNames[type+1]; +} + +#ifdef PROFILE_SHADER_CREATE +static FILE *GetDebugFileHandle( void ) +{ + static FILE *fp = NULL; + if( !fp ) + { + fp = fopen( "shadercreate.txt", "w" ); + Assert( fp ); + } + return fp; +} +#endif // PROFILE_SHADER_CREATE + +#ifdef DX_TO_GL_ABSTRACTION + // mat_autoload_glshaders instructs the engine to load a cached shader table at startup + // it will try for glshaders.cfg first, then fall back to glbaseshaders.cfg if not found +ConVar mat_autoload_glshaders( "mat_autoload_glshaders", "1" ); + + // mat_autosave_glshaders instructs the engine to save out the shader table at key points + // to the filename glshaders.cfg + // +ConVar mat_autosave_glshaders( "mat_autosave_glshaders", "1" ); + + +#endif +//----------------------------------------------------------------------------- +// Explicit instantiation of shader buffer implementation +//----------------------------------------------------------------------------- +template class CShaderBuffer< ID3DXBuffer >; + + +//----------------------------------------------------------------------------- +// Used to find unique shaders +//----------------------------------------------------------------------------- +#ifdef MEASURE_DRIVER_ALLOCATIONS +static CUtlMap< CRC32_t, int, int > s_UniqueVS( 0, 0, DefLessFunc( CRC32_t ) ); +static CUtlMap< CRC32_t, int, int > s_UniquePS( 0, 0, DefLessFunc( CRC32_t ) ); +static CUtlMap< IDirect3DVertexShader9*, CRC32_t, int > s_VSLookup( 0, 0, DefLessFunc( IDirect3DVertexShader9* ) ); +static CUtlMap< IDirect3DPixelShader9*, CRC32_t, int > s_PSLookup( 0, 0, DefLessFunc( IDirect3DPixelShader9* ) ); +#endif + +static int s_NumPixelShadersCreated = 0; +static int s_NumVertexShadersCreated = 0; + +static void RegisterVS( const void* pShaderBits, int nShaderSize, IDirect3DVertexShader9* pShader ) +{ +#ifdef MEASURE_DRIVER_ALLOCATIONS + CRC32_t crc; + CRC32_Init( &crc ); + CRC32_ProcessBuffer( &crc, pShaderBits, nShaderSize ); + CRC32_Final( &crc ); + + s_VSLookup.Insert( pShader, crc ); + + int nIndex = s_UniqueVS.Find( crc ); + if ( nIndex != s_UniqueVS.InvalidIndex() ) + { + ++s_UniqueVS[nIndex]; + } + else + { + int nMemUsed = 23 * 1024; + s_UniqueVS.Insert( crc, 1 ); + VPROF_INCREMENT_GROUP_COUNTER( "unique vs count", COUNTER_GROUP_NO_RESET, 1 ); + VPROF_INCREMENT_GROUP_COUNTER( "vs driver mem", COUNTER_GROUP_NO_RESET, nMemUsed ); + VPROF_INCREMENT_GROUP_COUNTER( "total driver mem", COUNTER_GROUP_NO_RESET, nMemUsed ); + } +#endif +} + +static void RegisterPS( const void* pShaderBits, int nShaderSize, IDirect3DPixelShader9* pShader ) +{ +#ifdef MEASURE_DRIVER_ALLOCATIONS + CRC32_t crc; + CRC32_Init( &crc ); + CRC32_ProcessBuffer( &crc, pShaderBits, nShaderSize ); + CRC32_Final( &crc ); + + s_PSLookup.Insert( pShader, crc ); + + int nIndex = s_UniquePS.Find( crc ); + if ( nIndex != s_UniquePS.InvalidIndex() ) + { + ++s_UniquePS[nIndex]; + } + else + { + int nMemUsed = 400; + s_UniquePS.Insert( crc, 1 ); + VPROF_INCREMENT_GROUP_COUNTER( "unique ps count", COUNTER_GROUP_NO_RESET, 1 ); + VPROF_INCREMENT_GROUP_COUNTER( "ps driver mem", COUNTER_GROUP_NO_RESET, nMemUsed ); + VPROF_INCREMENT_GROUP_COUNTER( "total driver mem", COUNTER_GROUP_NO_RESET, nMemUsed ); + } +#endif +} + +static void UnregisterVS( IDirect3DVertexShader9* pShader ) +{ +#ifdef MEASURE_DRIVER_ALLOCATIONS + int nCRCIndex = s_VSLookup.Find( pShader ); + if ( nCRCIndex == s_VSLookup.InvalidIndex() ) + return; + + CRC32_t crc = s_VSLookup[nCRCIndex]; + s_VSLookup.RemoveAt( nCRCIndex ); + + int nIndex = s_UniqueVS.Find( crc ); + if ( nIndex != s_UniqueVS.InvalidIndex() ) + { + if ( --s_UniqueVS[nIndex] <= 0 ) + { + int nMemUsed = 23 * 1024; + VPROF_INCREMENT_GROUP_COUNTER( "unique vs count", COUNTER_GROUP_NO_RESET, -1 ); + VPROF_INCREMENT_GROUP_COUNTER( "vs driver mem", COUNTER_GROUP_NO_RESET, -nMemUsed ); + VPROF_INCREMENT_GROUP_COUNTER( "total driver mem", COUNTER_GROUP_NO_RESET, -nMemUsed ); + s_UniqueVS.Remove( nIndex ); + } + } +#endif +} + +static void UnregisterPS( IDirect3DPixelShader9* pShader ) +{ +#ifdef MEASURE_DRIVER_ALLOCATIONS + int nCRCIndex = s_PSLookup.Find( pShader ); + if ( nCRCIndex == s_PSLookup.InvalidIndex() ) + return; + + CRC32_t crc = s_PSLookup[nCRCIndex]; + s_PSLookup.RemoveAt( nCRCIndex ); + + int nIndex = s_UniquePS.Find( crc ); + if ( nIndex != s_UniquePS.InvalidIndex() ) + { + if ( --s_UniquePS[nIndex] <= 0 ) + { + int nMemUsed = 400; + VPROF_INCREMENT_GROUP_COUNTER( "unique ps count", COUNTER_GROUP_NO_RESET, -1 ); + VPROF_INCREMENT_GROUP_COUNTER( "ps driver mem", COUNTER_GROUP_NO_RESET, -nMemUsed ); + VPROF_INCREMENT_GROUP_COUNTER( "total driver mem", COUNTER_GROUP_NO_RESET, -nMemUsed ); + s_UniquePS.Remove( nIndex ); + } + } +#endif +} + +//----------------------------------------------------------------------------- +// The lovely low-level dx call to create a vertex shader +//----------------------------------------------------------------------------- +static HardwareShader_t CreateD3DVertexShader( DWORD *pByteCode, int numBytes, const char *pShaderName, char *debugLabel = NULL ) +{ + MEM_ALLOC_D3D_CREDIT(); + + if ( !pByteCode ) + { + Assert( 0 ); + return INVALID_HARDWARE_SHADER; + } + + // Compute the vertex specification + HardwareShader_t hShader; + + #ifdef DX_TO_GL_ABSTRACTION + HRESULT hr = Dx9Device()->CreateVertexShader( pByteCode, (IDirect3DVertexShader9 **)&hShader, pShaderName, debugLabel ); + #else + if ( IsEmulatingGL() ) + { + DWORD dwVersion = D3DXGetShaderVersion( pByteCode ); + REFERENCE( dwVersion ); + Assert ( D3DSHADER_VERSION_MAJOR( dwVersion ) == 2 ); + } + + #if defined(_X360) || !defined(DX_TO_GL_ABSTRACTION) + HRESULT hr = Dx9Device()->CreateVertexShader( pByteCode, (IDirect3DVertexShader9 **)&hShader ); + #else + HRESULT hr = Dx9Device()->CreateVertexShader( pByteCode, (IDirect3DVertexShader9 **)&hShader, pShaderName ); +#endif + + #endif + + // NOTE: This isn't recorded before the CreateVertexShader because + // we don't know the value of shader until after the CreateVertexShader. + RECORD_COMMAND( DX8_CREATE_VERTEX_SHADER, 3 ); + RECORD_INT( ( int )hShader ); // hack hack hack + RECORD_INT( numBytes ); + RECORD_STRUCT( pByteCode, numBytes ); + + if ( FAILED( hr ) ) + { + Assert( 0 ); + hShader = INVALID_HARDWARE_SHADER; + } + else + { + s_NumVertexShadersCreated++; + RegisterVS( pByteCode, numBytes, (IDirect3DVertexShader9 *)hShader ); + } + return hShader; +} + +static void PatchPixelShaderForAtiMsaaHack(DWORD *pShader, DWORD dwTexCoordMask) +{ + if ( IsPC() ) + { + bool bIsSampler, bIsTexCoord; + + // Should be able to patch only ps2.0 + if (*pShader != 0xFFFF0200) + return; + + pShader++; + + while (pShader) + { + switch (*pShader & D3DSI_OPCODE_MASK) + { + case D3DSIO_COMMENT: + // Process comment + pShader = pShader + (*pShader >> 16) + 1; + break; + + case D3DSIO_END: + // End of shader + return; + + case D3DSIO_DCL: + bIsSampler = (*(pShader + 1) & D3DSP_TEXTURETYPE_MASK) != D3DSTT_UNKNOWN; + bIsTexCoord = (((*(pShader + 2) & D3DSP_REGTYPE_MASK) >> D3DSP_REGTYPE_SHIFT) + + ((*(pShader + 2) & D3DSP_REGTYPE_MASK2) >> D3DSP_REGTYPE_SHIFT2)) == D3DSPR_TEXTURE; + + if (!bIsSampler && bIsTexCoord) + { + DWORD dwTexCoord = *(pShader + 2) & D3DSP_REGNUM_MASK; + DWORD mask = 0x01; + for (DWORD i = 0; i < 16; i++) + { + if (((dwTexCoordMask & mask) == mask) && (dwTexCoord == i)) + { + // If found -- patch and get out + // *(pShader + 2) |= D3DSPDM_PARTIALPRECISION; + *(pShader + 2) |= D3DSPDM_MSAMPCENTROID; + break; + } + mask <<= 1; + } + } + // Intentionally fall through... + + default: + // Skip instruction + pShader = pShader + ((*pShader & D3DSI_INSTLENGTH_MASK) >> D3DSI_INSTLENGTH_SHIFT) + 1; + } + } + } +} + +static ConVar mat_force_ps_patch( "mat_force_ps_patch", "0" ); +static ConVar mat_disable_ps_patch( "mat_disable_ps_patch", "0", FCVAR_ALLOWED_IN_COMPETITIVE ); + +//----------------------------------------------------------------------------- +// The lovely low-level dx call to create a pixel shader +//----------------------------------------------------------------------------- +static HardwareShader_t CreateD3DPixelShader( DWORD *pByteCode, unsigned int nCentroidMask, int numBytes, const char* pShaderName, char *debugLabel = NULL ) +{ + MEM_ALLOC_D3D_CREDIT(); + + if ( !pByteCode ) + return INVALID_HARDWARE_SHADER; + + if ( IsPC() && nCentroidMask && + ( HardwareConfig()->NeedsATICentroidHack() || + mat_force_ps_patch.GetInt() ) ) + { + if ( !mat_disable_ps_patch.GetInt() ) + { + PatchPixelShaderForAtiMsaaHack( pByteCode, nCentroidMask ); + } + } + + HardwareShader_t shader; + #if defined( DX_TO_GL_ABSTRACTION ) + #if defined( OSX ) + HRESULT hr = Dx9Device()->CreatePixelShader( pByteCode, ( IDirect3DPixelShader ** )&shader, pShaderName, debugLabel ); + #else + HRESULT hr = Dx9Device()->CreatePixelShader( pByteCode, ( IDirect3DPixelShader ** )&shader, pShaderName, debugLabel, &nCentroidMask ); + #endif + #else + if ( IsEmulatingGL() ) + { + DWORD dwVersion; + dwVersion = D3DXGetShaderVersion( pByteCode ); + Assert ( D3DSHADER_VERSION_MAJOR( dwVersion ) == 2 ); + } +#if defined(_X360) || !defined(DX_TO_GL_ABSTRACTION) + HRESULT hr = Dx9Device()->CreatePixelShader( pByteCode, ( IDirect3DPixelShader ** )&shader ); +#else + HRESULT hr = Dx9Device()->CreatePixelShader( pByteCode, ( IDirect3DPixelShader ** )&shader, pShaderName ); + #endif + #endif + + // NOTE: We have to do this after creating the pixel shader since we don't know + // lookup.m_PixelShader yet!!!!!!! + RECORD_COMMAND( DX8_CREATE_PIXEL_SHADER, 3 ); + RECORD_INT( ( int )shader ); // hack hack hack + RECORD_INT( numBytes ); + RECORD_STRUCT( pByteCode, numBytes ); + + if ( FAILED( hr ) ) + { + Assert(0); + shader = INVALID_HARDWARE_SHADER; + } + else + { + s_NumPixelShadersCreated++; + RegisterPS( pByteCode, numBytes, ( IDirect3DPixelShader9* )shader ); + } + + return shader; +} + +template int BinarySearchCombos( uint32 nStaticComboID, int nCombos, T const *pRecords ) +{ + // Use binary search - data is sorted + int nLowerIdx = 1; + int nUpperIdx = nCombos; + for (;;) + { + if ( nUpperIdx < nLowerIdx ) + return -1; + + int nMiddleIndex = ( nLowerIdx + nUpperIdx ) / 2; + uint32 nProbe = pRecords[nMiddleIndex-1].m_nStaticComboID; + if ( nStaticComboID < nProbe ) + { + nUpperIdx = nMiddleIndex - 1; + } + else + { + if ( nStaticComboID > nProbe ) + nLowerIdx = nMiddleIndex + 1; + else + return nMiddleIndex - 1; + } + } +} + +inline int FindShaderStaticCombo( uint32 nStaticComboID, const ShaderHeader_t& header, StaticComboRecord_t *pRecords ) +{ + if ( header.m_nVersion < 5 ) + return -1; + + return BinarySearchCombos( nStaticComboID, header.m_nNumStaticCombos, pRecords ); +} + +// cache redundant i/o fetched components of the vcs files +struct ShaderFileCache_t +{ + CUtlSymbol m_Name; + CUtlSymbol m_Filename; + ShaderHeader_t m_Header; + bool m_bVertexShader; + + // valid for diff version only - contains the microcode used as the reference for diff algorithm + CUtlBuffer m_ReferenceCombo; + + // valid for ver5 only - contains the directory + CUtlVector< StaticComboRecord_t > m_StaticComboRecords; + CUtlVector< StaticComboAliasRecord_t > m_StaticComboDupRecords; + + ShaderFileCache_t() + { + // invalid until version established + m_Header.m_nVersion = 0; + } + + bool IsValid() const + { + return m_Header.m_nVersion != 0; + } + + bool IsOldVersion() const + { + return m_Header.m_nVersion < 5; + } + + int IsVersion6() const + { + return ( m_Header.m_nVersion == 6 ); + } + + int FindCombo( uint32 nStaticComboID ) + { + int nSearchAliases = BinarySearchCombos( nStaticComboID, m_StaticComboDupRecords.Count(), m_StaticComboDupRecords.Base() ); + if ( nSearchAliases != -1 ) + nStaticComboID = m_StaticComboDupRecords[nSearchAliases].m_nSourceStaticCombo; + return FindShaderStaticCombo( nStaticComboID, m_Header, m_StaticComboRecords.Base() ); + } + + bool operator==( const ShaderFileCache_t& a ) const + { + return m_Name == a.m_Name && m_bVertexShader == a.m_bVertexShader; + } +}; + + +//----------------------------------------------------------------------------- +// Vertex + pixel shader manager +//----------------------------------------------------------------------------- +class CShaderManager : public IShaderManager +{ +public: + CShaderManager(); + virtual ~CShaderManager(); + + // Methods of IShaderManager + virtual void Init(); + virtual void Shutdown(); + virtual IShaderBuffer *CompileShader( const char *pProgram, size_t nBufLen, const char *pShaderVersion ); + virtual VertexShaderHandle_t CreateVertexShader( IShaderBuffer* pShaderBuffer ); + virtual void DestroyVertexShader( VertexShaderHandle_t hShader ); + virtual PixelShaderHandle_t CreatePixelShader( IShaderBuffer* pShaderBuffer ); + virtual void DestroyPixelShader( PixelShaderHandle_t hShader ); + virtual VertexShader_t CreateVertexShader( const char *pVertexShaderFile, int nStaticVshIndex = 0, char *debugLabel = NULL ); + virtual PixelShader_t CreatePixelShader( const char *pPixelShaderFile, int nStaticPshIndex = 0, char *debugLabel = NULL ); + virtual void SetVertexShader( VertexShader_t shader ); + virtual void SetPixelShader( PixelShader_t shader ); + virtual void BindVertexShader( VertexShaderHandle_t shader ); + virtual void BindPixelShader( PixelShaderHandle_t shader ); + virtual void *GetCurrentVertexShader(); + virtual void *GetCurrentPixelShader(); + virtual void ResetShaderState(); + void FlushShaders(); + virtual void ClearVertexAndPixelShaderRefCounts(); + virtual void PurgeUnusedVertexAndPixelShaders(); + void SpewVertexAndPixelShaders(); + const char *GetActiveVertexShaderName(); + const char *GetActivePixelShaderName(); + bool CreateDynamicCombos_Ver4( void *pContext, uint8 *pComboBuffer ); + bool CreateDynamicCombos_Ver5( void *pContext, uint8 *pComboBuffer, char *debugLabel = NULL ); + +#if defined( DX_TO_GL_ABSTRACTION ) + virtual void DoStartupShaderPreloading(); +#endif + + static void QueuedLoaderCallback( void *pContext, void *pContext2, const void *pData, int nSize, LoaderError_t loaderError ); + +private: + typedef CUtlFixedLinkedList< IDirect3DVertexShader9* >::IndexType_t VertexShaderIndex_t; + typedef CUtlFixedLinkedList< IDirect3DPixelShader9* >::IndexType_t PixelShaderIndex_t; + + struct ShaderStaticCombos_t + { + int m_nCount; + + // Can't use CUtlVector here since you CUtlLinkedList> doesn't work. + HardwareShader_t *m_pHardwareShaders; + struct ShaderCreationData_t + { + CUtlVector ByteCode; + uint32 iCentroidMask; + }; + + ShaderCreationData_t *m_pCreationData; + }; + + struct ShaderLookup_t + { + CUtlSymbol m_Name; + int m_nStaticIndex; + ShaderStaticCombos_t m_ShaderStaticCombos; + DWORD m_Flags; + int m_nRefCount; + unsigned int m_hShaderFileCache; + + // for queued loading, bias an aligned optimal buffer forward to correct location + int m_nDataOffset; + + // diff version, valid during load only + ShaderDictionaryEntry_t *m_pComboDictionary; + + ShaderLookup_t() + { + m_Flags = 0; + m_nRefCount = 0; + m_ShaderStaticCombos.m_nCount = 0; + m_ShaderStaticCombos.m_pHardwareShaders = 0; + m_ShaderStaticCombos.m_pCreationData = 0; + m_pComboDictionary = NULL; + } + void IncRefCount() + { + m_nRefCount++; + } + bool operator==( const ShaderLookup_t& a ) const + { + return m_Name == a.m_Name && m_nStaticIndex == a.m_nStaticIndex; + } + }; + +#ifdef DYNAMIC_SHADER_COMPILE + struct Combo_t + { + CUtlSymbol m_ComboName; + int m_nMin; + int m_nMax; + }; + + struct ShaderCombos_t + { + CUtlVector m_StaticCombos; + CUtlVector m_DynamicCombos; + int GetNumDynamicCombos( void ) const + { + int combos = 1; + int i; + for( i = 0; i < m_DynamicCombos.Count(); i++ ) + { + combos *= ( m_DynamicCombos[i].m_nMax - m_DynamicCombos[i].m_nMin + 1 ); + } + return combos; + } + int GetNumStaticCombos( void ) const + { + int combos = 1; + int i; + for( i = 0; i < m_StaticCombos.Count(); i++ ) + { + combos *= ( m_StaticCombos[i].m_nMax - m_StaticCombos[i].m_nMin + 1 ); + } + return combos; + } + }; +#endif + +private: + void CreateStaticShaders(); + void DestroyStaticShaders(); + +#if defined ( DYNAMIC_SHADER_COMPILE ) && defined( REMOTE_DYNAMIC_SHADER_COMPILE ) + void InitRemoteShaderCompile(); + void DeinitRemoteShaderCompile(); +#endif + + // The low-level dx call to set the vertex shader state + void SetVertexShaderState( HardwareShader_t shader, DataCacheHandle_t hCachedShader = DC_INVALID_HANDLE ); + + // The low-level dx call to set the pixel shader state + void SetPixelShaderState( HardwareShader_t shader, DataCacheHandle_t hCachedShader = DC_INVALID_HANDLE ); + + // Destroys all shaders + void DestroyAllShaders(); + + // Destroy a particular vertex shader + void DestroyVertexShader( VertexShader_t shader ); + // Destroy a particular pixel shader + void DestroyPixelShader( PixelShader_t shader ); + + bool LoadAndCreateShaders( ShaderLookup_t &lookup, bool bVertexShader, char *debugLabel = NULL ); + FileHandle_t OpenFileAndLoadHeader( const char *pFileName, ShaderHeader_t *pHeader ); + +#ifdef DYNAMIC_SHADER_COMPILE + bool LoadAndCreateShaders_Dynamic( ShaderLookup_t &lookup, bool bVertexShader ); + const ShaderCombos_t *FindOrCreateShaderCombos( const char *pShaderName ); + HardwareShader_t CompileShader( const char *pShaderName, int nStaticIndex, int nDynamicIndex, bool bVertexShader ); +#endif + + void DisassembleShader( ShaderLookup_t *pLookup, int dynamicCombo, uint8 *pByteCode ); + void WriteTranslatedFile( ShaderLookup_t *pLookup, int dynamicCombo, char *pFileContents, char *pFileExtension ); + + // DX_TO_GL_ABSTRACTION only, no-op otherwise + + void SaveShaderCache( char *cacheName ); // query GLM pair cache for all active shader pairs and write them to disk in named file + bool LoadShaderCache( char *cacheName ); // read named file, establish compiled shader sets for each vertex+static and pixel+static, then link pairs as listed in table + // return true on success, false if file not found + + // old void WarmShaderCache(); + + CUtlFixedLinkedList< ShaderLookup_t > m_VertexShaderDict; + CUtlFixedLinkedList< ShaderLookup_t > m_PixelShaderDict; + + CUtlSymbolTable m_ShaderSymbolTable; + +#ifdef DYNAMIC_SHADER_COMPILE + typedef HRESULT (__stdcall *ShaderCompileFromFileFunc_t)( LPCSTR pSrcFile, CONST D3DXMACRO* pDefines, + LPD3DXINCLUDE pInclude, LPCSTR pFunctionName, LPCSTR pProfile, DWORD Flags, + LPD3DXBUFFER* ppShader, LPD3DXBUFFER * ppErrorMsgs, LPD3DXCONSTANTTABLE * ppConstantTable ); + CUtlStringMap m_ShaderNameToCombos; + CSysModule *m_pShaderCompiler30; + ShaderCompileFromFileFunc_t m_ShaderCompileFileFunc30; +#endif + + // The current vertex and pixel shader + HardwareShader_t m_HardwareVertexShader; + HardwareShader_t m_HardwarePixelShader; + + CUtlFixedLinkedList< IDirect3DVertexShader9* > m_RawVertexShaderDict; + CUtlFixedLinkedList< IDirect3DPixelShader9* > m_RawPixelShaderDict; + + CUtlFixedLinkedList< ShaderFileCache_t > m_ShaderFileCache; + + // false, creates during init. + // true, creates on access, helps reduce d3d memory for tools, but causes i/o hitches. + bool m_bCreateShadersOnDemand; + +#if defined( _DEBUG ) + // for debugging (can't resolve UtlSym) + // need some history because 360 d3d has rips related to sequencing + char vshDebugName[MAX_SHADER_HISTORY][64]; + int vshDebugIndex; + char pshDebugName[MAX_SHADER_HISTORY][64]; + int pshDebugIndex; +#endif + +#if defined ( DYNAMIC_SHADER_COMPILE ) && defined( REMOTE_DYNAMIC_SHADER_COMPILE ) + SOCKET m_RemoteShaderCompileSocket; +#endif + +}; + + +//----------------------------------------------------------------------------- +// Singleton accessor +//----------------------------------------------------------------------------- +static CShaderManager s_ShaderManager; +IShaderManager *g_pShaderManager = &s_ShaderManager; + +//----------------------------------------------------------------------------- +// Constructor, destructor +//----------------------------------------------------------------------------- +CShaderManager::CShaderManager() : + m_ShaderSymbolTable( 0, 32, true /* caseInsensitive */ ), + m_VertexShaderDict( 32 ), + m_PixelShaderDict( 32 ), + m_ShaderFileCache( 32 ) +{ + m_bCreateShadersOnDemand = false; + +#ifdef DYNAMIC_SHADER_COMPILE + m_pShaderCompiler30 = 0; + m_ShaderCompileFileFunc30 = 0; +#ifdef REMOTE_DYNAMIC_SHADER_COMPILE + m_RemoteShaderCompileSocket = INVALID_SOCKET; +#endif +#endif + +#ifdef _DEBUG + vshDebugIndex = 0; + pshDebugIndex = 0; +#endif +} + +CShaderManager::~CShaderManager() +{ +#if defined ( DYNAMIC_SHADER_COMPILE ) && defined( REMOTE_DYNAMIC_SHADER_COMPILE ) + DeinitRemoteShaderCompile(); +#endif +} + +#define REMOTE_SHADER_COMPILE_PORT "20000" + +#if defined ( DYNAMIC_SHADER_COMPILE ) && defined( REMOTE_DYNAMIC_SHADER_COMPILE ) +void CShaderManager::InitRemoteShaderCompile() +{ + DeinitRemoteShaderCompile(); + + int nResult = 0; + #ifdef _WIN32 + WSADATA wsaData; + nResult = WSAStartup( 0x101, &wsaData ); + if ( nResult != 0 ) + { + Warning( "CShaderManager::Init - Could not init socket for remote dynamic shader compilation\n" ); + } + #endif + + struct addrinfo hints; + ZeroMemory( &hints, sizeof(hints) ); + hints.ai_family = AF_UNSPEC; + hints.ai_socktype = SOCK_STREAM; + hints.ai_protocol = IPPROTO_TCP; + + // Resolve the server address and port + struct addrinfo *result = NULL; + nResult = getaddrinfo( mat_remoteshadercompile.GetString(), REMOTE_SHADER_COMPILE_PORT, &hints, &result ); + if ( nResult != 0 ) + { + Warning( "getaddrinfo failed: %d\n", nResult ); + #ifdef _WIN32 + WSACleanup(); + #endif + Assert( 0 ); + } + + // Attempt to connect to an address until one succeeds + for( struct addrinfo *ptr = result; ptr != NULL; ptr = ptr->ai_next ) + { + // Create a SOCKET for connecting to remote shader compilation server + m_RemoteShaderCompileSocket = socket( ptr->ai_family, ptr->ai_socktype, ptr->ai_protocol ); + if ( m_RemoteShaderCompileSocket == INVALID_SOCKET ) + { + Warning( "Error at socket(): %ld\n", WSAGetLastError() ); + freeaddrinfo( result ); + #ifdef _WIN32 + WSACleanup(); + #endif + Assert( 0 ); + continue; + } + + // Connect to server. + nResult = connect( m_RemoteShaderCompileSocket, ptr->ai_addr, (int)ptr->ai_addrlen); + if ( nResult == SOCKET_ERROR ) + { + closesocket( m_RemoteShaderCompileSocket ); + m_RemoteShaderCompileSocket = INVALID_SOCKET; + continue; + } + break; + } + + freeaddrinfo( result ); + + if ( m_RemoteShaderCompileSocket == INVALID_SOCKET ) + { + Warning( "Unable to connect to remote shader compilation server!\n" ); + #ifdef _WIN32 + WSACleanup(); + #endif + Assert ( 0 ); + } +} + +void CShaderManager::DeinitRemoteShaderCompile() +{ + if ( m_RemoteShaderCompileSocket != INVALID_SOCKET ) + { + if ( shutdown( m_RemoteShaderCompileSocket, SD_SEND ) == SOCKET_ERROR ) + { + Warning( "Remote shader compilation shutdown failed: %d\n", WSAGetLastError() ); + } + closesocket( m_RemoteShaderCompileSocket ); + m_RemoteShaderCompileSocket = INVALID_SOCKET; + } +} +#endif // defined ( DYNAMIC_SHADER_COMPILE ) && defined( REMOTE_DYNAMIC_SHADER_COMPILE ) + +//----------------------------------------------------------------------------- +// Initialization, shutdown +//----------------------------------------------------------------------------- +void CShaderManager::Init() +{ + // incompatible with the 360, violates loading system + // only used by PC to help tools reduce d3d footprint + m_bCreateShadersOnDemand = IsPC() && ( ShaderUtil()->InEditorMode() || CommandLine()->CheckParm( "-shadersondemand" ) ); + +#ifdef DYNAMIC_SHADER_COMPILE + if( !IsX360() ) + { + +#ifdef REMOTE_DYNAMIC_SHADER_COMPILE + InitRemoteShaderCompile(); +#else // REMOTE_DYNAMIC_SHADER_COMPILE + +#ifdef _DEBUG + m_pShaderCompiler30 = Sys_LoadModule( "d3dx9d_33.dll" ); +#endif + if (!m_pShaderCompiler30) + { + m_pShaderCompiler30 = Sys_LoadModule( "d3dx9_33.dll" ); + } + + if ( m_pShaderCompiler30 ) + { + m_ShaderCompileFileFunc30 = (ShaderCompileFromFileFunc_t)GetProcAddress( (HMODULE)m_pShaderCompiler30, "D3DXCompileShaderFromFileA" ); + } + +#endif + + } +#endif // DYNAMIC_SHADER_COMPILE + + CreateStaticShaders(); +} + +void CShaderManager::Shutdown() +{ +#ifdef DYNAMIC_SHADER_COMPILE + if ( m_pShaderCompiler30 ) + { + Sys_UnloadModule( m_pShaderCompiler30 ); + m_pShaderCompiler30 = 0; + m_ShaderCompileFileFunc30 = 0; + } +#endif + +#ifdef DX_TO_GL_ABSTRACTION + if (mat_autosave_glshaders.GetInt()) + { + SaveShaderCache("glshaders.cfg"); + } +#endif + + DestroyAllShaders(); + DestroyStaticShaders(); +} + + +//----------------------------------------------------------------------------- +// Compiles shaders +//----------------------------------------------------------------------------- +IShaderBuffer *CShaderManager::CompileShader( const char *pProgram, size_t nBufLen, const char *pShaderVersion ) +{ + int nCompileFlags = D3DXSHADER_AVOID_FLOW_CONTROL; + +#ifdef _DEBUG + nCompileFlags |= D3DXSHADER_DEBUG; +#endif + + LPD3DXBUFFER pCompiledShader, pErrorMessages; + HRESULT hr = D3DXCompileShader( pProgram, nBufLen, + NULL, NULL, "main", pShaderVersion, nCompileFlags, + &pCompiledShader, &pErrorMessages, NULL ); + + if ( FAILED( hr ) ) + { + if ( pErrorMessages ) + { + const char *pErrorMessage = (const char *)pErrorMessages->GetBufferPointer(); + Warning( "Shader compilation failed! Reported the following errors:\n%s\n", pErrorMessage ); + pErrorMessages->Release(); + } + return NULL; + } + + // NOTE: This uses small block heap allocator; so I'm not going + // to bother creating a memory pool. + CShaderBuffer< ID3DXBuffer > *pShaderBuffer = new CShaderBuffer< ID3DXBuffer >( pCompiledShader ); + if ( pErrorMessages ) + { + pErrorMessages->Release(); + } + + return pShaderBuffer; +} + + +VertexShaderHandle_t CShaderManager::CreateVertexShader( IShaderBuffer* pShaderBuffer ) +{ + // Create the vertex shader + IDirect3DVertexShader9 *pVertexShader = NULL; + +#if defined(_X360) || !defined(DX_TO_GL_ABSTRACTION) + HRESULT hr = Dx9Device()->CreateVertexShader( (const DWORD*)pShaderBuffer->GetBits(), &pVertexShader ); +#else + HRESULT hr = Dx9Device()->CreateVertexShader( (const DWORD*)pShaderBuffer->GetBits(), &pVertexShader, NULL ); +#endif + + if ( FAILED( hr ) || !pVertexShader ) + return VERTEX_SHADER_HANDLE_INVALID; + + s_NumVertexShadersCreated++; + RegisterVS( pShaderBuffer->GetBits(), pShaderBuffer->GetSize(), pVertexShader ); + + // Insert the shader into the dictionary of shaders + VertexShaderIndex_t i = m_RawVertexShaderDict.AddToTail( pVertexShader ); + return (VertexShaderHandle_t)i; +} + +void CShaderManager::DestroyVertexShader( VertexShaderHandle_t hShader ) +{ + if ( hShader == VERTEX_SHADER_HANDLE_INVALID ) + return; + + VertexShaderIndex_t i = (VertexShaderIndex_t)hShader; + IDirect3DVertexShader9 *pVertexShader = m_RawVertexShaderDict[ i ]; + + UnregisterVS( pVertexShader ); + + VerifyEquals( (int)pVertexShader->Release(), 0 ); + m_RawVertexShaderDict.Remove( i ); +} + +PixelShaderHandle_t CShaderManager::CreatePixelShader( IShaderBuffer* pShaderBuffer ) +{ + // Create the vertex shader + IDirect3DPixelShader9 *pPixelShader = NULL; +#if defined(_X360) || !defined(DX_TO_GL_ABSTRACTION) + HRESULT hr = Dx9Device()->CreatePixelShader( (const DWORD*)pShaderBuffer->GetBits(), &pPixelShader ); +#else + HRESULT hr = Dx9Device()->CreatePixelShader( (const DWORD*)pShaderBuffer->GetBits(), &pPixelShader, NULL ); +#endif + + if ( FAILED( hr ) || !pPixelShader ) + return PIXEL_SHADER_HANDLE_INVALID; + + s_NumPixelShadersCreated++; + + RegisterPS( pShaderBuffer->GetBits(), pShaderBuffer->GetSize(), pPixelShader ); + + // Insert the shader into the dictionary of shaders + PixelShaderIndex_t i = m_RawPixelShaderDict.AddToTail( pPixelShader ); + return (PixelShaderHandle_t)i; +} + +void CShaderManager::DestroyPixelShader( PixelShaderHandle_t hShader ) +{ + if ( hShader == PIXEL_SHADER_HANDLE_INVALID ) + return; + + PixelShaderIndex_t i = (PixelShaderIndex_t)hShader; + IDirect3DPixelShader9 *pPixelShader = m_RawPixelShaderDict[ i ]; + + UnregisterPS( pPixelShader ); + + VerifyEquals( (int)pPixelShader->Release(), 0 ); + m_RawPixelShaderDict.Remove( i ); +} + + +//----------------------------------------------------------------------------- +// Globals +//----------------------------------------------------------------------------- +HardwareShader_t s_pIllegalMaterialPS = INVALID_HARDWARE_SHADER; + +//----------------------------------------------------------------------------- +// Static methods +//----------------------------------------------------------------------------- +void CShaderManager::CreateStaticShaders() +{ + MEM_ALLOC_D3D_CREDIT(); + + if ( !HardwareConfig()->SupportsVertexAndPixelShaders() ) + { + return; + } + + if ( IsPC() ) + { + // GR - hack for illegal materials + const DWORD psIllegalMaterial[] = + { + #ifdef DX_TO_GL_ABSTRACTION + // Use a PS 2.0 binary shader on DX_TO_GL_ABSTRACTION + 0xffff0200, 0x05000051, 0xa00f0000, 0x3f800000, + 0x00000000, 0x3f800000, 0x3f800000, 0x02000001, + 0x800f0000, 0xa0e40000, 0x02000001, 0x800f0800, + 0x80e40000, 0x0000ffff + #else + 0xffff0101, 0x00000051, 0xa00f0000, 0x00000000, 0x3f800000, 0x00000000, + 0x3f800000, 0x00000001, 0x800f0000, 0xa0e40000, 0x0000ffff + #endif + }; + // create default shader +#if defined(_X360) || !defined(DX_TO_GL_ABSTRACTION) + Dx9Device()->CreatePixelShader( psIllegalMaterial, ( IDirect3DPixelShader9 ** )&s_pIllegalMaterialPS ); +#else + Dx9Device()->CreatePixelShader( psIllegalMaterial, ( IDirect3DPixelShader9 ** )&s_pIllegalMaterialPS, NULL ); +#endif + } +} + +void CShaderManager::DestroyStaticShaders() +{ + // GR - invalid material hack + // destroy internal shader + if ( s_pIllegalMaterialPS != INVALID_HARDWARE_SHADER ) + { + ( ( IDirect3DPixelShader9 * )s_pIllegalMaterialPS )->Release(); + s_pIllegalMaterialPS = INVALID_HARDWARE_SHADER; + } +} + +#ifdef DYNAMIC_SHADER_COMPILE +static const char *GetShaderSourcePath( void ) +{ + static char shaderDir[MAX_PATH]; + // GR - just in case init this... + static bool bHaveShaderDir = false; + if( !bHaveShaderDir ) + { + bHaveShaderDir = true; +# if ( defined( DYNAMIC_SHADER_COMPILE_CUSTOM_PATH ) ) + { + Q_strncpy( shaderDir, DYNAMIC_SHADER_COMPILE_CUSTOM_PATH, MAX_PATH ); + } +# else + { +# if ( defined( _X360 ) ) + { + char hostName[128] = ""; + const char *pHostName = CommandLine()->ParmValue( "-host" ); + if ( !pHostName ) + { + // the 360 machine name must be _360 + DWORD length = sizeof( hostName ); + DmGetXboxName( hostName, &length ); + char *p = strstr( hostName, "_360" ); + *p = '\0'; + pHostName = hostName; + } + + Q_snprintf( shaderDir, MAX_PATH, "net:\\smb\\%s\\stdshaders", pHostName ); + } +# else + { + Q_strncpy( shaderDir, __FILE__, MAX_PATH ); + Q_StripFilename( shaderDir ); + Q_StripLastDir( shaderDir, MAX_PATH ); + Q_strncat( shaderDir, "stdshaders", MAX_PATH, COPY_ALL_CHARACTERS ); + } +# endif + } +# endif + } + return shaderDir; +} +#endif + +#ifdef DYNAMIC_SHADER_COMPILE +const CShaderManager::ShaderCombos_t *CShaderManager::FindOrCreateShaderCombos( const char *pShaderName ) +{ + if( m_ShaderNameToCombos.Defined( pShaderName ) ) + { + return &m_ShaderNameToCombos[pShaderName]; + } + ShaderCombos_t &combos = m_ShaderNameToCombos[pShaderName]; + char filename[MAX_PATH]; + // try the vsh dir first. + Q_strncpy( filename, GetShaderSourcePath(), MAX_PATH ); + Q_strncat( filename, "\\", MAX_PATH, COPY_ALL_CHARACTERS ); + Q_strncat( filename, pShaderName, MAX_PATH, COPY_ALL_CHARACTERS ); + Q_strncat( filename, ".vsh", MAX_PATH, COPY_ALL_CHARACTERS ); + CUtlInplaceBuffer bffr( 0, 0, CUtlInplaceBuffer::TEXT_BUFFER ); + + bool bOpenResult = g_pFullFileSystem->ReadFile( filename, NULL, bffr ); + + if ( bOpenResult ) + { + NULL; + } + else + { + // try the fxc dir. + Q_strncpy( filename, GetShaderSourcePath(), MAX_PATH ); + Q_strncat( filename, "\\", MAX_PATH, COPY_ALL_CHARACTERS ); + Q_strncat( filename, pShaderName, MAX_PATH, COPY_ALL_CHARACTERS ); + Q_strncat( filename, ".fxc", MAX_PATH, COPY_ALL_CHARACTERS ); + bOpenResult = g_pFullFileSystem->ReadFile( filename, NULL, bffr ); + + if ( !bOpenResult ) + { + // Maybe this is a specific version [20 & 20b] -> [2x] + if ( Q_strlen( pShaderName ) >= 3 ) + { + char *pszEndFilename = filename + strlen( filename ); + if ( !Q_stricmp( pszEndFilename - 6, "30.fxc" ) ) + { + // Total hack. Who knows what builds that 30 shader? + strcpy( pszEndFilename - 6, "20b.fxc" ); + bOpenResult = g_pFullFileSystem->ReadFile( filename, NULL, bffr ); + if ( !bOpenResult ) + { + strcpy( pszEndFilename - 6, "2x.fxc" ); + bOpenResult = g_pFullFileSystem->ReadFile( filename, NULL, bffr ); + } + if ( !bOpenResult ) + { + strcpy( pszEndFilename - 6, "20.fxc" ); + bOpenResult = g_pFullFileSystem->ReadFile( filename, NULL, bffr ); + } + } + else + { + if ( !stricmp( pszEndFilename - 6, "20.fxc" ) ) + { + pszEndFilename[ -5 ] = 'x'; + } + else if ( !stricmp( pszEndFilename - 7, "20b.fxc" ) ) + { + strcpy( pszEndFilename - 7, "2x.fxc" ); + --pszEndFilename; + } + else if ( !stricmp( pszEndFilename - 6, "11.fxc" ) ) + { + strcpy( pszEndFilename - 6, "xx.fxc" ); + } + + bOpenResult = g_pFullFileSystem->ReadFile( filename, NULL, bffr ); + if ( !bOpenResult ) + { + if ( !stricmp( pszEndFilename - 6, "2x.fxc" ) ) + { + pszEndFilename[ -6 ] = 'x'; + bOpenResult = g_pFullFileSystem->ReadFile( filename, NULL, bffr ); + } + } + } + } + } + + if ( !bOpenResult ) + { + Assert( 0 ); + return NULL; + } + } + + while( char *line = bffr.InplaceGetLinePtr() ) + { + // dear god perl is better at this kind of shit! + int begin = 0; + int end = 0; + + // check if the line starts with '//' + if( line[0] != '/' || line[1] != '/' ) + { + continue; + } + + // Check if line intended for platform lines + if( IsX360() ) + { + if ( Q_stristr( line, "[PC]" ) ) + continue; + } + else + { + if ( Q_stristr( line, "[360]" ) || Q_stristr( line, "[XBOX]" ) ) + continue; + } + + // Skip any lines intended for other shader version + if ( Q_stristr( pShaderName, "_ps20" ) && !Q_stristr( pShaderName, "_ps20b" ) && + Q_stristr( line, "[ps" ) && !Q_stristr( line, "[ps20]" ) ) + continue; + if ( Q_stristr( pShaderName, "_ps20b" ) && + Q_stristr( line, "[ps" ) && !Q_stristr( line, "[ps20b]" ) ) + continue; + if ( Q_stristr( pShaderName, "_ps30" ) && + Q_stristr( line, "[ps" ) && !Q_stristr( line, "[ps30]" ) ) + continue; + if ( Q_stristr( pShaderName, "_vs20" ) && + Q_stristr( line, "[vs" ) && !Q_stristr( line, "[vs20]" ) ) + continue; + if ( Q_stristr( pShaderName, "_vs30" ) && + Q_stristr( line, "[vs" ) && !Q_stristr( line, "[vs30]" ) ) + continue; + + char *pScan = &line[2]; + while( *pScan == ' ' || *pScan == '\t' ) + { + pScan++; + } + + bool bDynamic; + if( Q_strncmp( pScan, "DYNAMIC", 7 ) == 0 ) + { + bDynamic = true; + pScan += 7; + } + else if( Q_strncmp( pScan, "STATIC", 6 ) == 0 ) + { + bDynamic = false; + pScan += 6; + } + else + { + continue; + } + + // skip whitespace + while( *pScan == ' ' || *pScan == '\t' ) + { + pScan++; + } + + // check for colon + if( *pScan != ':' ) + { + continue; + } + pScan++; + + // skip whitespace + while( *pScan == ' ' || *pScan == '\t' ) + { + pScan++; + } + + // check for quote + if( *pScan != '\"' ) + { + continue; + } + pScan++; + + char *pBeginningOfName = pScan; + while( 1 ) + { + if( *pScan == '\0' ) + { + break; + } + if( *pScan == '\"' ) + { + break; + } + pScan++; + } + + if( *pScan == '\0' ) + { + continue; + } + + // must have hit a quote. .done with string. + // slam a NULL at the end quote of the string so that we have the string at pBeginningOfName. + *pScan = '\0'; + pScan++; + + // skip whitespace + while( *pScan == ' ' || *pScan == '\t' ) + { + pScan++; + } + + // check for quote + if( *pScan != '\"' ) + { + continue; + } + pScan++; + + // make sure that we have a number after the quote. + if( !isdigit( *pScan ) ) + { + continue; + } + + while( isdigit( *pScan ) ) + { + begin = begin * 10 + ( *pScan - '0' ); + pScan++; + } + + if( pScan[0] != '.' || pScan[1] != '.' ) + { + continue; + } + pScan += 2; + + // make sure that we have a number + if( !isdigit( *pScan ) ) + { + continue; + } + + while( isdigit( *pScan ) ) + { + end = end * 10 + ( *pScan - '0' ); + pScan++; + } + + if( pScan[0] != '\"' ) + { + continue; + } + + // sweet freaking jesus. .done parsing the line. +// char buf[1024]; +// sprintf( buf, "\"%s\" \"%s\" %d %d\n", bDynamic ? "DYNAMIC" : "STATIC", pBeginningOfName, begin, end ); +// Plat_DebugString( buf ); + + Combo_t *pCombo = NULL; + if( bDynamic ) + { + pCombo = &combos.m_DynamicCombos[combos.m_DynamicCombos.AddToTail()]; + } + else + { + pCombo = &combos.m_StaticCombos[combos.m_StaticCombos.AddToTail()]; + } + + pCombo->m_ComboName = m_ShaderSymbolTable.AddString( pBeginningOfName ); + pCombo->m_nMin = begin; + pCombo->m_nMax = end; + } + + return &combos; +} +#endif // DYNAMIC_SHADER_COMPILE + +#ifdef DYNAMIC_SHADER_COMPILE +#ifndef DX_TO_GL_ABSTRACTION +//----------------------------------------------------------------------------- +// Used to deal with include files +//----------------------------------------------------------------------------- +class CDxInclude : public ID3DXInclude +{ +public: + CDxInclude( const char *pMainFileName ); + +#if defined( _X360 ) + virtual HRESULT WINAPI Open( D3DXINCLUDE_TYPE IncludeType, LPCSTR pFileName, LPCVOID pParentData, LPCVOID * ppData, UINT * pBytes, LPSTR pFullPath, DWORD cbFullPath ); +#else + STDMETHOD(Open)(THIS_ D3DXINCLUDE_TYPE IncludeType, LPCSTR pFileName, LPCVOID pParentData, LPCVOID *ppData, UINT *pBytes); +#endif + + STDMETHOD(Close)(THIS_ LPCVOID pData); + +private: + char m_pBasePath[MAX_PATH]; + +#if defined( _X360 ) + char m_pFullPath[MAX_PATH]; +#endif +}; + +CDxInclude::CDxInclude( const char *pMainFileName ) +{ + Q_ExtractFilePath( pMainFileName, m_pBasePath, sizeof(m_pBasePath) ); +} + + +#if defined( _X360 ) +HRESULT CDxInclude::Open( D3DXINCLUDE_TYPE IncludeType, LPCSTR pFileName, LPCVOID pParentData, LPCVOID * ppData, UINT * pBytes, LPSTR pFullPath, DWORD cbFullPath ) +#else +HRESULT CDxInclude::Open( D3DXINCLUDE_TYPE IncludeType, LPCSTR pFileName, LPCVOID pParentData, LPCVOID * ppData, UINT * pBytes ) +#endif +{ + char pTemp[MAX_PATH]; + if ( !Q_IsAbsolutePath( pFileName ) && ( IncludeType == D3DXINC_LOCAL ) ) + { + Q_ComposeFileName( m_pBasePath, pFileName, pTemp, sizeof(pTemp) ); + pFileName = pTemp; + } + + CUtlBuffer buf( 0, 0, CUtlBuffer::TEXT_BUFFER ); + if ( !g_pFullFileSystem->ReadFile( pFileName, NULL, buf ) ) + return E_FAIL; + + *pBytes = buf.TellMaxPut(); + void *pMem = malloc( *pBytes ); + memcpy( pMem, buf.Base(), *pBytes ); + *ppData = pMem; + +# if ( defined( _X360 ) ) + { + Q_ComposeFileName( m_pBasePath, pFileName, m_pFullPath, sizeof(m_pFullPath) ); + pFullPath = m_pFullPath; + cbFullPath = MAX_PATH; + } +# endif + + return S_OK; +} + +HRESULT CDxInclude::Close( LPCVOID pData ) +{ + void *pMem = const_cast( pData ); + free( pMem ); + return S_OK; +} +#endif // not DX_TO_GL_ABSTRACTION + +static const char *FileNameToShaderModel( const char *pShaderName, bool bVertexShader ) +{ + // Figure out the shader model + const char *pShaderModel = NULL; + if( bVertexShader ) + { + if( Q_stristr( pShaderName, "vs20" ) ) + { + pShaderModel = "vs_2_0"; + bVertexShader = true; + } + else if( Q_stristr( pShaderName, "vs11" ) ) + { + pShaderModel = "vs_1_1"; + bVertexShader = true; + } + else if( Q_stristr( pShaderName, "vs14" ) ) + { + pShaderModel = "vs_1_1"; + bVertexShader = true; + } + else if( Q_stristr( pShaderName, "vs30" ) ) + { + pShaderModel = "vs_3_0"; + bVertexShader = true; + } + else + { +#ifdef _DEBUG + Error( "Failed dynamic shader compiled\nBuild shaderapidx9.dll in debug to find problem\n" ); +#else + Assert( 0 ); +#endif + } + } + else + { + if( Q_stristr( pShaderName, "ps20b" ) ) + { + pShaderModel = "ps_2_b"; + } + else if( Q_stristr( pShaderName, "ps20" ) ) + { + pShaderModel = "ps_2_0"; + } + else if( Q_stristr( pShaderName, "ps11" ) ) + { + pShaderModel = "ps_1_1"; + } + else if( Q_stristr( pShaderName, "ps14" ) ) + { + pShaderModel = "ps_1_4"; + } + else if( Q_stristr( pShaderName, "ps30" ) ) + { + pShaderModel = "ps_3_0"; + } + else + { +#ifdef _DEBUG + Error( "Failed dynamic shader compiled\nBuild shaderapidx9.dll in debug to find problem\n" ); +#else + Assert( 0 ); +#endif + } + } + return pShaderModel; +} +#endif + +#ifdef DYNAMIC_SHADER_COMPILE + +#if defined( _X360 ) +static ConVar mat_flushshaders_generate_updbs( "mat_flushshaders_generate_updbs", "0", 0, "Generates UPDBs whenever you flush shaders." ); +#endif + +HardwareShader_t CShaderManager::CompileShader( const char *pShaderName, + int nStaticIndex, int nDynamicIndex, bool bVertexShader ) +{ + VPROF_BUDGET( "CompileShader", "CompileShader" ); + Assert( m_ShaderNameToCombos.Defined( pShaderName ) ); + if( !m_ShaderNameToCombos.Defined( pShaderName ) ) + { + return INVALID_HARDWARE_SHADER; + } + const ShaderCombos_t &combos = m_ShaderNameToCombos[pShaderName]; +#ifdef _DEBUG + int numStaticCombos = combos.GetNumStaticCombos(); + int numDynamicCombos = combos.GetNumDynamicCombos(); +#endif + Assert( nStaticIndex % numDynamicCombos == 0 ); + Assert( ( nStaticIndex % numDynamicCombos ) >= 0 && ( nStaticIndex % numDynamicCombos ) < numStaticCombos ); + Assert( nDynamicIndex >= 0 && nDynamicIndex < numDynamicCombos ); + +# ifdef DYNAMIC_SHADER_COMPILE_VERBOSE + + //Warning( "Compiling %s %s\n\tdynamic:", bVertexShader ? "vsh" : "psh", pShaderName ); + Warning( "Compiling " ); + if ( bVertexShader ) + ConColorMsg( Color( 0, 255, 0, 255 ), "vsh - %s ", pShaderName ); + else + ConColorMsg( Color( 0, 255, 255, 255 ), "psh - %s ", pShaderName ); + Warning( "\n\tdynamic:" ); + +# endif + + CUtlVector macros; + // plus 1 for null termination, plus 1 for #define SHADER_MODEL_*, and plus 1 for #define _X360 on 360 + macros.SetCount( combos.m_DynamicCombos.Count() + combos.m_StaticCombos.Count() + 2 + ( IsX360() ? 1 : 0 ) ); + + int nCombo = nStaticIndex + nDynamicIndex; + int macroIndex = 0; + int i; + for( i = 0; i < combos.m_DynamicCombos.Count(); i++ ) + { + int countForCombo = combos.m_DynamicCombos[i].m_nMax - combos.m_DynamicCombos[i].m_nMin + 1; + int val = nCombo % countForCombo + combos.m_DynamicCombos[i].m_nMin; + nCombo /= countForCombo; + macros[macroIndex].Name = m_ShaderSymbolTable.String( combos.m_DynamicCombos[i].m_ComboName ); + char buf[16]; + sprintf( buf, "%d", val ); + CUtlSymbol valSymbol( buf ); + macros[macroIndex].Definition = valSymbol.String(); +# ifdef DYNAMIC_SHADER_COMPILE_VERBOSE + Warning( " %s=%s", macros[macroIndex].Name, macros[macroIndex].Definition ); +# endif + macroIndex++; + } + +# ifdef DYNAMIC_SHADER_COMPILE_VERBOSE + Warning( "\n\tstatic:" ); +# endif + for( i = 0; i < combos.m_StaticCombos.Count(); i++ ) + { + int countForCombo = combos.m_StaticCombos[i].m_nMax - combos.m_StaticCombos[i].m_nMin + 1; + int val = nCombo % countForCombo + combos.m_StaticCombos[i].m_nMin; + nCombo /= countForCombo; + macros[macroIndex].Name = m_ShaderSymbolTable.String( combos.m_StaticCombos[i].m_ComboName ); + char buf[16]; + sprintf( buf, "%d", val ); + CUtlSymbol valSymbol( buf ); + macros[macroIndex].Definition = valSymbol.String(); +# ifdef DYNAMIC_SHADER_COMPILE_VERBOSE + Warning( " %s=%s", macros[macroIndex].Name, macros[macroIndex].Definition ); +# endif + macroIndex++; + } + +# ifdef DYNAMIC_SHADER_COMPILE_VERBOSE + Warning( "\n" ); +# endif + + char filename[MAX_PATH]; + Q_strncpy( filename, GetShaderSourcePath(), MAX_PATH ); + Q_strncat( filename, "\\", MAX_PATH, COPY_ALL_CHARACTERS ); + Q_strncat( filename, pShaderName, MAX_PATH, COPY_ALL_CHARACTERS ); + Q_strncat( filename, ".fxc", MAX_PATH, COPY_ALL_CHARACTERS ); + + const char *pShaderModel = FileNameToShaderModel( pShaderName, bVertexShader ); + + // define the shader model + char shaderModelDefineString[1024]; + Q_snprintf( shaderModelDefineString, 1024, "SHADER_MODEL_%s", pShaderModel ); + Q_strupr( shaderModelDefineString ); + macros[macroIndex].Name = shaderModelDefineString; + macros[macroIndex].Definition = "1"; + macroIndex++; + + char x360DefineString[1024]; + if( IsX360() ) + { + Q_snprintf( x360DefineString, 1024, "_X360", pShaderModel ); + Q_strupr( x360DefineString ); + macros[macroIndex].Name = x360DefineString; + macros[macroIndex].Definition = "1"; + macroIndex++; + } + + // NULL terminate. + macros[macroIndex].Name = NULL; + macros[macroIndex].Definition = NULL; + + // Instead of erroring out, infinite-loop on shader compilation + // (i.e. give developers a chance to fix the shader code w/out restarting the game) +#ifndef _DEBUG + int retriesLeft = 20; +retry_compile: +#endif + + // Try and open the file to see if it exists + FileHandle_t fp = g_pFullFileSystem->Open( filename, "r" ); + + if ( fp == FILESYSTEM_INVALID_HANDLE ) + { + // Maybe this is a specific version [20 & 20b] -> [2x] + if ( strlen( pShaderName ) >= 3 ) + { + char *pszEndFilename = filename + strlen( filename ); + if ( !Q_stricmp( pszEndFilename - 6, "30.fxc" ) ) + { + strcpy( pszEndFilename - 6, "20b.fxc" ); + fp = g_pFullFileSystem->Open( filename, "r" ); + if ( fp == FILESYSTEM_INVALID_HANDLE ) + { + strcpy( pszEndFilename - 6, "2x.fxc" ); + fp = g_pFullFileSystem->Open( filename, "r" ); + } + if ( fp == FILESYSTEM_INVALID_HANDLE ) + { + strcpy( pszEndFilename - 6, "20.fxc" ); + fp = g_pFullFileSystem->Open( filename, "r" ); + } + } + else + { + if ( !Q_stricmp( pszEndFilename - 6, "20.fxc" ) ) + { + pszEndFilename[ -5 ] = 'x'; + fp = g_pFullFileSystem->Open( filename, "r" ); + } + else if ( !Q_stricmp( pszEndFilename - 7, "20b.fxc" ) ) + { + strcpy( pszEndFilename - 7, "2x.fxc" ); + fp = g_pFullFileSystem->Open( filename, "r" ); + } + else if ( !stricmp( pszEndFilename - 6, "11.fxc" ) ) + { + strcpy( pszEndFilename - 6, "xx.fxc" ); + fp = g_pFullFileSystem->Open( filename, "r" ); + } + + if ( fp == FILESYSTEM_INVALID_HANDLE ) + { + if ( !stricmp( pszEndFilename - 6, "2x.fxc" ) ) + { + pszEndFilename[ -6 ] = 'x'; + fp = g_pFullFileSystem->Open( filename, "r" ); + } + } + } + } + } + + if ( fp != FILESYSTEM_INVALID_HANDLE ) + { + g_pFullFileSystem->Close( fp ); + } + +#ifdef REMOTE_DYNAMIC_SHADER_COMPILE + #define SEND_BUF_SIZE 40000 + #define RECV_BUF_SIZE 40000 + + // Remotely-compiled shader code + uint32 *pRemotelyCompiledShader = NULL; + uint32 nRemotelyCompiledShaderLength = 0; + + if ( m_RemoteShaderCompileSocket == INVALID_SOCKET ) + { + InitRemoteShaderCompile(); + } + + // In this case, we're going to use a remote service to do our compiling + if ( m_RemoteShaderCompileSocket != INVALID_SOCKET ) + { + // Build up command list for remote shader compiler + char pSendbuf[SEND_BUF_SIZE], pRecvbuf[RECV_BUF_SIZE], pFixedFilename[MAX_PATH], buf[MAX_PATH]; + V_FixupPathName( pFixedFilename, MAX_PATH, filename ); + V_FileBase( pFixedFilename, buf, MAX_PATH ); // Just find base filename + V_strncat( buf, ".fxc", MAX_PATH ); + V_snprintf( pSendbuf, SEND_BUF_SIZE, "%s\n", buf ); + V_strncat( pSendbuf, pShaderModel, SEND_BUF_SIZE ); + V_strncat( pSendbuf, "\n", SEND_BUF_SIZE ); + V_snprintf( buf, MAX_PATH, "%d\n", macros.Count() ); + V_strncat( pSendbuf, buf, SEND_BUF_SIZE ); + for ( int i=0; i < macros.Count(); i++ ) + { + V_snprintf( buf, MAX_PATH, "%s\n%s\n", macros[i].Name, macros[i].Definition ); + V_strncat( pSendbuf, buf, SEND_BUF_SIZE ); + } + V_strncat( pSendbuf, "", SEND_BUF_SIZE ); + + // Send commands to remote shader compiler + int nResult = send( m_RemoteShaderCompileSocket, pSendbuf, (int)strlen( pSendbuf ), 0 ); + if ( nResult == SOCKET_ERROR ) + { + Warning( "send failed: %d\n", WSAGetLastError() ); + DeinitRemoteShaderCompile(); + } + + if ( m_RemoteShaderCompileSocket != INVALID_SOCKET ) + { + // Block here until we get a result back from the server + nResult = recv( m_RemoteShaderCompileSocket, pRecvbuf, RECV_BUF_SIZE, 0 ); + if ( nResult == 0 ) + { + Warning( "Connection closed\n" ); + DeinitRemoteShaderCompile(); + } + else if ( nResult < 0 ) + { + Warning( "recv failed: %d\n", WSAGetLastError() ); + DeinitRemoteShaderCompile(); + } + + if ( m_RemoteShaderCompileSocket != INVALID_SOCKET ) + { + // Grab the first 32 bits, which tell us what the rest of the data is + uint32 nCompileResultCode; + memcpy( &nCompileResultCode, pRecvbuf, sizeof( nCompileResultCode ) ); + + // If is zero, we have an error, so the rest of the data is a text string from the compiler + if ( nCompileResultCode == 0x00000000 ) + { + Warning( "Remote shader compile error: %s\n", pRecvbuf+4 ); + } + else // we have an actual binary shader blob coming back + { + nRemotelyCompiledShaderLength = nCompileResultCode; + pRemotelyCompiledShader = (uint32 *) pRecvbuf; + pRemotelyCompiledShader++; + } + } + } + } // End using remote compile service +#endif // REMOTE_DYNAMIC_SHADER_COMPILE + +#if defined( DYNAMIC_SHADER_COMPILE ) + bool bShadersNeedFlush = false; +#endif + +#if defined( DYNAMIC_SHADER_COMPILE ) && !defined( REMOTE_DYNAMIC_SHADER_COMPILE ) + LPD3DXBUFFER pShader = NULL; + LPD3DXBUFFER pErrorMessages = NULL; + HRESULT hr = S_OK; + bool b30Shader = !Q_stricmp( pShaderModel, "vs_3_0" ) || !Q_stricmp( pShaderModel, "ps_3_0" ); + + if ( m_ShaderCompileFileFunc30 && b30Shader ) + { + CDxInclude dxInclude( filename ); + hr = m_ShaderCompileFileFunc30( filename, macros.Base(), &dxInclude, + "main", pShaderModel, 0 /* DWORD Flags */, &pShader, &pErrorMessages, NULL /* LPD3DXCONSTANTTABLE *ppConstantTable */ ); + } + else + { +# if ( !defined( _X360 ) ) + { + if ( b30Shader ) + { + Warning( "Compiling with a stale version of d3dx. Should have d3d9x_33.dll installed (Apr 2007)\n" ); + } + hr = D3DXCompileShaderFromFile( filename, macros.Base(), NULL /* LPD3DXINCLUDE */, + "main", pShaderModel, 0 /* DWORD Flags */, &pShader, &pErrorMessages, NULL /* LPD3DXCONSTANTTABLE *ppConstantTable */ ); + + +#ifdef REMOTE_DYNAMIC_SHADER_COMPILE + // If we're using the remote compiling service, let's double-check against a local compile + if ( ( m_RemoteShaderCompileSocket != INVALID_SOCKET ) && pRemotelyCompiledShader ) + { + if ( ( memcmp( pRemotelyCompiledShader, pShader->GetBufferPointer(), pShader->GetBufferSize() ) != 0 ) || + ( pShader->GetBufferSize() != nRemotelyCompiledShaderLength) ) + { + Warning( "Remote and local shaders don't match!\n" ); + return INVALID_HARDWARE_SHADER; + } + } +#endif // REMOTE_DYNAMIC_SHADER_COMPILE + + } +# else + { + D3DXSHADER_COMPILE_PARAMETERS compileParams; + memset( &compileParams, 0, sizeof( compileParams ) ); + + char pUPDBOutputFile[MAX_PATH] = ""; //where we write the file + char pUPDBPIXLookup[MAX_PATH] = ""; //where PIX (on a pc) looks for the file + + compileParams.Flags |= D3DXSHADEREX_OPTIMIZE_UCODE; + + if( mat_flushshaders_generate_updbs.GetBool() ) + { + //UPDB generation for PIX debugging + compileParams.Flags |= D3DXSHADEREX_GENERATE_UPDB; + compileParams.UPDBPath = pUPDBPIXLookup; + + Q_snprintf( pUPDBOutputFile, MAX_PATH, "%s\\UPDB_X360\\%s_S%d_D%d.updb", GetShaderSourcePath(), pShaderName, nStaticIndex, nDynamicIndex ); + + //replace "net:\smb" with another "\" turning the xbox network address format into the pc network address format + V_strcpy_safe( pUPDBPIXLookup, &pUPDBOutputFile[7] ); + pUPDBPIXLookup[0] = '\\'; + } + + hr = D3DXCompileShaderFromFileEx( filename, macros.Base(), NULL /* LPD3DXINCLUDE */, + "main", pShaderModel, 0 /* DWORD Flags */, &pShader, &pErrorMessages, NULL /* LPD3DXCONSTANTTABLE *ppConstantTable */, &compileParams ); + + if( (pUPDBOutputFile[0] != '\0') && compileParams.pUPDBBuffer ) //Did we generate a updb? + { + CUtlBuffer outbuffer; + DWORD dataSize = compileParams.pUPDBBuffer->GetBufferSize(); + outbuffer.EnsureCapacity( dataSize ); + memcpy( outbuffer.Base(), compileParams.pUPDBBuffer->GetBufferPointer(), dataSize ); + outbuffer.SeekPut( CUtlBuffer::SEEK_CURRENT, dataSize ); + g_pFullFileSystem->WriteFile( pUPDBOutputFile, NULL, outbuffer ); + + compileParams.pUPDBBuffer->Release(); + } + } +# endif + } + + if ( hr != D3D_OK ) + { + const char *pErrorMessageString = ( const char * )pErrorMessages->GetBufferPointer(); + Plat_DebugString( pErrorMessageString ); + Plat_DebugString( "\n" ); + +#ifndef _DEBUG + if ( retriesLeft-- > 0 ) + { + DevMsg( 0, "Failed dynamic shader compiled - fix the shader while the debugger is at the breakpoint, then continue\n" ); + DebuggerBreakIfDebugging(); +#if defined( DYNAMIC_SHADER_COMPILE ) + bShadersNeedFlush = true; +#endif + goto retry_compile; + } + if( !IsX360() ) //errors make the 360 puke and die. We have a better solution for this particular error + Error( "Failed dynamic shader compile\nBuild shaderapidx9.dll in debug to find problem\n" ); +#else + Assert( 0 ); + +#endif // _DEBUG + + return INVALID_HARDWARE_SHADER; + } + else +#endif // #if defined( DYNAMIC_SHADER_COMPILE ) && !defined( REMOTE_DYNAMIC_SHADER_COMPILE ) + + { +#ifdef DYNAMIC_SHADER_COMPILE_WRITE_ASSEMBLY + // enable to dump the disassembly for shader validation + char exampleCommandLine[2048]; + Q_strncpy( exampleCommandLine, "// Run from stdshaders\n// ..\\..\\dx9sdk\\utilities\\fxc.exe ", sizeof( exampleCommandLine ) ); + int i; + for( i = 0; macros[i].Name; i++ ) + { + Q_strncat( exampleCommandLine, "/D", sizeof( exampleCommandLine ) ); + Q_strncat( exampleCommandLine, macros[i].Name, sizeof( exampleCommandLine ) ); + Q_strncat( exampleCommandLine, "=", sizeof( exampleCommandLine ) ); + Q_strncat( exampleCommandLine, macros[i].Definition, sizeof( exampleCommandLine ) ); + Q_strncat( exampleCommandLine, " ", sizeof( exampleCommandLine ) ); + } + + Q_strncat( exampleCommandLine, "/T", sizeof( exampleCommandLine ) ); + Q_strncat( exampleCommandLine, pShaderModel, sizeof( exampleCommandLine ) ); + Q_strncat( exampleCommandLine, " ", sizeof( exampleCommandLine ) ); + Q_strncat( exampleCommandLine, filename, sizeof( exampleCommandLine ) ); + Q_strncat( exampleCommandLine, "\n", sizeof( exampleCommandLine ) ); + + ID3DXBuffer *pd3dxBuffer; + HRESULT hr; + hr = D3DXDisassembleShader( ( DWORD* )pShader->GetBufferPointer(), false, NULL, &pd3dxBuffer ); + Assert( hr == D3D_OK ); + CUtlBuffer tempBuffer; + tempBuffer.SetBufferType( true, false ); + int exampleCommandLineLength = strlen( exampleCommandLine ); + tempBuffer.EnsureCapacity( pd3dxBuffer->GetBufferSize() + exampleCommandLineLength ); + memcpy( tempBuffer.Base(), exampleCommandLine, exampleCommandLineLength ); + memcpy( ( char * )tempBuffer.Base() + exampleCommandLineLength, pd3dxBuffer->GetBufferPointer(), pd3dxBuffer->GetBufferSize() ); + tempBuffer.SeekPut( CUtlBuffer::SEEK_CURRENT, pd3dxBuffer->GetBufferSize() + exampleCommandLineLength ); + char filename[MAX_PATH]; + sprintf( filename, "%s_%d_%d.asm", pShaderName, nStaticIndex, nDynamicIndex ); + g_pFullFileSystem->WriteFile( filename, "DEFAULT_WRITE_PATH", tempBuffer ); +#endif + +#ifdef REMOTE_DYNAMIC_SHADER_COMPILE + if ( bVertexShader ) + { + return CreateD3DVertexShader( ( DWORD * )pRemotelyCompiledShader, nRemotelyCompiledShaderLength, pShaderName ); + } + else + { + return CreateD3DPixelShader( ( DWORD * )pRemotelyCompiledShader, 0, nRemotelyCompiledShaderLength, pShaderName ); // hack hack hack! need to get centroid info from the source + } +#else // local compile, not remote + if ( bVertexShader ) + { + return CreateD3DVertexShader( ( DWORD * )pShader->GetBufferPointer(), pShader->GetBufferSize(), pShaderName ); + } + else + { + return CreateD3DPixelShader( ( DWORD * )pShader->GetBufferPointer(), 0, pShader->GetBufferSize(), pShaderName ); // hack hack hack! need to get centroid info from the source + } +#endif + +#if defined( DYNAMIC_SHADER_COMPILE ) + // We keep up with whether we hit a compile error above. If we did, then we likely need to recompile everything again since we could have changed global code. + if ( bShadersNeedFlush ) + { + MatFlushShaders(); + } +#endif + } + +#ifndef REMOTE_DYNAMIC_SHADER_COMPILE + if ( pShader ) + { + pShader->Release(); + } +#endif + +#if defined( DYNAMIC_SHADER_COMPILE ) && !defined( REMOTE_DYNAMIC_SHADER_COMPILE ) + if ( pErrorMessages ) + { + pErrorMessages->Release(); + } +#endif + +} +#endif + +#ifdef DYNAMIC_SHADER_COMPILE +bool CShaderManager::LoadAndCreateShaders_Dynamic( ShaderLookup_t &lookup, bool bVertexShader ) +{ + const char *pName = m_ShaderSymbolTable.String( lookup.m_Name ); + const ShaderCombos_t *pCombos = FindOrCreateShaderCombos( pName ); + if ( !pCombos ) + { + return false; + } + + int numDynamicCombos = pCombos->GetNumDynamicCombos(); + lookup.m_ShaderStaticCombos.m_pHardwareShaders = new HardwareShader_t[numDynamicCombos]; + lookup.m_ShaderStaticCombos.m_nCount = numDynamicCombos; + lookup.m_ShaderStaticCombos.m_pCreationData = new ShaderStaticCombos_t::ShaderCreationData_t[numDynamicCombos]; + + int i; + for( i = 0; i < numDynamicCombos; i++ ) + { + lookup.m_ShaderStaticCombos.m_pHardwareShaders[i] = INVALID_HARDWARE_SHADER; + } + return true; +} +#endif + +//----------------------------------------------------------------------------- +// Open the shader file, optionally gets the header +//----------------------------------------------------------------------------- +FileHandle_t CShaderManager::OpenFileAndLoadHeader( const char *pFileName, ShaderHeader_t *pHeader ) +{ + FileHandle_t fp = g_pFullFileSystem->Open( pFileName, "rb", "GAME" ); + if ( fp == FILESYSTEM_INVALID_HANDLE ) + { + return FILESYSTEM_INVALID_HANDLE; + } + + if ( pHeader ) + { + // read the header + g_pFullFileSystem->Read( pHeader, sizeof( ShaderHeader_t ), fp ); + + switch ( pHeader->m_nVersion ) + { + case 4: + // version with combos done as diffs vs a reference combo + // vsh/psh or older fxc + break; + + case 5: + case 6: + // version with optimal dictionary and compressed combo block + break; + + default: + Assert( 0 ); + Warning( "Shader %s is the wrong version %d, expecting %d\n", pFileName, pHeader->m_nVersion, SHADER_VCS_VERSION_NUMBER ); + g_pFullFileSystem->Close( fp ); + return FILESYSTEM_INVALID_HANDLE; + } + } + + return fp; +} + +//--------------------------------------------------------------------------------------------------------- +// Writes text files named for looked-up shaders. Used by GL shader translator to dump code for debugging +//--------------------------------------------------------------------------------------------------------- +void CShaderManager::WriteTranslatedFile( ShaderLookup_t *pLookup, int dynamicCombo, char *pFileContents, char *pFileExtension ) +{ + const char *pName = m_ShaderSymbolTable.String( pLookup->m_Name ); + int nNumChars = V_strlen( pFileContents ); + + CUtlBuffer tempBuffer; + tempBuffer.SetBufferType( true, false ); + tempBuffer.EnsureCapacity( nNumChars ); + memcpy( ( char * )tempBuffer.Base(), pFileContents, nNumChars ); + tempBuffer.SeekPut( CUtlBuffer::SEEK_CURRENT, nNumChars ); + + char filename[MAX_PATH]; + sprintf( filename, "%s_%d_%d.%s", pName, pLookup->m_nStaticIndex, dynamicCombo, pFileExtension ); + g_pFullFileSystem->WriteFile( filename, "DEFAULT_WRITE_PATH", tempBuffer ); +} + +//----------------------------------------------------------------------------- +// Disassemble a shader for debugging. Writes .asm files. +//----------------------------------------------------------------------------- +void CShaderManager::DisassembleShader( ShaderLookup_t *pLookup, int dynamicCombo, uint8 *pByteCode ) +{ +#if defined( WRITE_ASSEMBLY ) + const char *pName = m_ShaderSymbolTable.String( pLookup->m_Name ); + + ID3DXBuffer *pd3dxBuffer; + HRESULT hr; + hr = D3DXDisassembleShader( (DWORD*)pByteCode, false, NULL, &pd3dxBuffer ); + Assert( hr == D3D_OK ); + + CUtlBuffer tempBuffer; + tempBuffer.SetBufferType( true, false ); + tempBuffer.EnsureCapacity( pd3dxBuffer->GetBufferSize() ); + memcpy( ( char * )tempBuffer.Base(), pd3dxBuffer->GetBufferPointer(), pd3dxBuffer->GetBufferSize() ); + tempBuffer.SeekPut( CUtlBuffer::SEEK_CURRENT, pd3dxBuffer->GetBufferSize() ); + + char filename[MAX_PATH]; + sprintf( filename, "%s_%d_%d.asm", pName, pLookup->m_nStaticIndex, dynamicCombo ); + g_pFullFileSystem->WriteFile( filename, "DEFAULT_WRITE_PATH", tempBuffer ); +#endif +} + +//----------------------------------------------------------------------------- +// Create dynamic combos +//----------------------------------------------------------------------------- +bool CShaderManager::CreateDynamicCombos_Ver4( void *pContext, uint8 *pComboBuffer ) +{ + ShaderLookup_t* pLookup = (ShaderLookup_t *)pContext; + + ShaderFileCache_t *pFileCache = &m_ShaderFileCache[pLookup->m_hShaderFileCache]; + ShaderHeader_t *pHeader = &pFileCache->m_Header; + + int nReferenceComboSizeForDiffs = ((ShaderHeader_t_v4 *)pHeader)->m_nDiffReferenceSize; + + uint8 *pReferenceShader = NULL; + uint8 *pDiffOutputBuffer = NULL; + if ( nReferenceComboSizeForDiffs ) + { + // reference combo is *always* the largest combo, so safe worst case size for uncompression buffer + pReferenceShader = (uint8 *)pFileCache->m_ReferenceCombo.Base(); + pDiffOutputBuffer = (uint8 *)_alloca( nReferenceComboSizeForDiffs ); + } + + // build this shader's dynamic combos + bool bOK = true; + int nStartingOffset = 0; + for ( int i = 0; i < pHeader->m_nDynamicCombos; i++ ) + { + if ( pLookup->m_pComboDictionary[i].m_Offset == -1 ) + { + // skipped + continue; + } + + if ( !nStartingOffset ) + { + nStartingOffset = pLookup->m_pComboDictionary[i].m_Offset; + } + + // offsets better be sequentially ascending + Assert( nStartingOffset <= pLookup->m_pComboDictionary[i].m_Offset ); + + if ( pLookup->m_pComboDictionary[i].m_Size <= 0 ) + { + // skipped + continue; + } + + // get the right byte code from the monolithic buffer + uint8 *pByteCode = (uint8 *)pComboBuffer + pLookup->m_nDataOffset + pLookup->m_pComboDictionary[i].m_Offset - nStartingOffset; + int nByteCodeSize = pLookup->m_pComboDictionary[i].m_Size; + + if ( pReferenceShader ) + { + // reference combo better be the largest combo, otherwise memory corruption + Assert( nReferenceComboSizeForDiffs >= nByteCodeSize ); + + // use the differencing algorithm to recover the full shader + int nOriginalSize; + ApplyDiffs( + pReferenceShader, + pByteCode, + nReferenceComboSizeForDiffs, + nByteCodeSize, + nOriginalSize, + pDiffOutputBuffer, + nReferenceComboSizeForDiffs ); + + pByteCode = pDiffOutputBuffer; + nByteCodeSize = nOriginalSize; + } + +#if defined( WRITE_ASSEMBLY ) + DisassembleShader( pLookup, i, pByteCode ); +#endif + HardwareShader_t hardwareShader = INVALID_HARDWARE_SHADER; + + if ( IsPC() && m_bCreateShadersOnDemand ) + { + // cache the code off for later + pLookup->m_ShaderStaticCombos.m_pCreationData[i].ByteCode.SetSize( nByteCodeSize ); + V_memcpy( pLookup->m_ShaderStaticCombos.m_pCreationData[i].ByteCode.Base(), pByteCode, nByteCodeSize ); + pLookup->m_ShaderStaticCombos.m_pCreationData[i].iCentroidMask = pFileCache->m_bVertexShader ? 0 : pHeader->m_nCentroidMask; + } + else + { + const char *pShaderName = m_ShaderSymbolTable.String( pLookup->m_Name ); + if ( pFileCache->m_bVertexShader ) + { + hardwareShader = CreateD3DVertexShader( reinterpret_cast< DWORD *>( pByteCode ), nByteCodeSize, pShaderName ); + } + else + { + hardwareShader = CreateD3DPixelShader( reinterpret_cast< DWORD *>( pByteCode ), pHeader->m_nCentroidMask, nByteCodeSize, pShaderName ); + } + + if ( hardwareShader == INVALID_HARDWARE_SHADER ) + { + Assert( 0 ); + bOK = false; + break; + } + } + pLookup->m_ShaderStaticCombos.m_pHardwareShaders[i] = hardwareShader; + } + + delete [] pLookup->m_pComboDictionary; + pLookup->m_pComboDictionary = NULL; + + return bOK; +} + +//----------------------------------------------------------------------------- +// Create dynamic combos +//----------------------------------------------------------------------------- +static uint32 NextULONG( uint8 * &pData ) +{ + // handle unaligned read + uint32 nRet; + memcpy( &nRet, pData, sizeof( nRet ) ); + pData += sizeof( nRet ); + return nRet; +} + + +bool CShaderManager::CreateDynamicCombos_Ver5( void *pContext, uint8 *pComboBuffer, char *debugLabel ) +{ + ShaderLookup_t* pLookup = (ShaderLookup_t *)pContext; + ShaderFileCache_t *pFileCache = &m_ShaderFileCache[pLookup->m_hShaderFileCache]; + uint8 *pCompressedShaders = pComboBuffer + pLookup->m_nDataOffset; + + uint8 *pUnpackBuffer = new uint8[MAX_SHADER_UNPACKED_BLOCK_SIZE]; + + char *debugLabelPtr = debugLabel; // can be moved to point at something else if need be + + // now, loop through all blocks + bool bOK = true; + while ( bOK ) + { + uint32 nBlockSize = NextULONG( pCompressedShaders ); + if ( nBlockSize == 0xffffffff ) + { + // any more blocks? + break; + } + + switch( nBlockSize & 0xc0000000 ) + { + case 0: // bzip2 + { + // uncompress + uint32 nOutsize = MAX_SHADER_UNPACKED_BLOCK_SIZE; + int nRslt = BZ2_bzBuffToBuffDecompress( + reinterpret_cast( pUnpackBuffer ), + &nOutsize, + reinterpret_cast( pCompressedShaders ), + nBlockSize, 1, 0 ); + if ( nRslt < 0 ) + { + // errors are negative for bzip + Assert( 0 ); + Warning( "BZIP Error (%d) decompressing shader", nRslt ); + bOK = false; + } + + pCompressedShaders += nBlockSize; + nBlockSize = nOutsize; // how much data there is + } + break; + + case 0x80000000: // uncompressed + { + // not compressed, as is + nBlockSize &= 0x3fffffff; + memcpy( pUnpackBuffer, pCompressedShaders, nBlockSize ); + pCompressedShaders += nBlockSize; + } + break; + + case 0x40000000: // lzma compressed + { + nBlockSize &= 0x3fffffff; + + size_t nOutsize = CLZMA::Uncompress( + reinterpret_cast( pCompressedShaders ), + pUnpackBuffer ); + pCompressedShaders += nBlockSize; + nBlockSize = nOutsize; // how much data there is + } + break; + + default: + { + Assert( 0 ); + Error(" unrecognized shader compression type = file corrupt?"); + bOK = false; + } + } + + uint8 *pReadPtr = pUnpackBuffer; + while ( pReadPtr < pUnpackBuffer+nBlockSize ) + { + uint32 nCombo_ID = NextULONG( pReadPtr ); + uint32 nShaderSize = NextULONG( pReadPtr ); + +#if defined( WRITE_ASSEMBLY ) + DisassembleShader( pLookup, nCombo_ID, pReadPtr ); +#endif + HardwareShader_t hardwareShader = INVALID_HARDWARE_SHADER; + + int iIndex = nCombo_ID; + if ( iIndex >= pLookup->m_nStaticIndex ) + iIndex -= pLookup->m_nStaticIndex; // ver5 stores combos as full combo, ver6 as dynamic combo # only + if ( IsPC() && m_bCreateShadersOnDemand ) + { + // cache the code off for later + pLookup->m_ShaderStaticCombos.m_pCreationData[iIndex].ByteCode.SetSize( nShaderSize ); + V_memcpy( pLookup->m_ShaderStaticCombos.m_pCreationData[iIndex].ByteCode.Base(), pReadPtr, nShaderSize ); + pLookup->m_ShaderStaticCombos.m_pCreationData[iIndex].iCentroidMask = pFileCache->m_bVertexShader ? 0 : pFileCache->m_Header.m_nCentroidMask; + } + else + { + const char *pShaderName = m_ShaderSymbolTable.String( pLookup->m_Name ); + + if ( pFileCache->m_bVertexShader ) + { +#if 0 + // this is all test code + CUtlBuffer bufGLCode( 1000, 50000, CUtlBuffer::TEXT_BUFFER ); + CUtlBuffer bufNewGLCode( 1000, 50000, CUtlBuffer::TEXT_BUFFER ); + CUtlBuffer bufGLSLCode( 1000, 50000, CUtlBuffer::TEXT_BUFFER ); + bool bVertexShader; + + uint32 nOptions = 0; + nOptions |= D3DToGL_OptionUseEnvParams; + nOptions |= D3DToGL_OptionDoFixupZ; + nOptions |= D3DToGL_OptionDoFixupY; + //options |= D3DToGL_OptionSpew; + +// sg_D3DToOpenGLTranslator.TranslateShader( (uint32 *) pReadPtr, (char *)bufGLCode.Base(), bufGLCode.Size(), &bVertexShader, nOptions, -1, debugLabel ); +// sg_NewD3DToOpenGLTranslator.TranslateShader( (uint32 *) pReadPtr, &bufNewGLCode, &bVertexShader, nOptions, -1, debugLabel ); + + +// bool bDumpGLSL = false; +// if ( !stricmp( "vs-file vertexlit_and_unlit_generic_bump_vs20 vs-index 144", debugLabel ) && ( iIndex == 0 ) ) +// { +// DisassembleShader( pLookup, iIndex, pReadPtr ); // Direct3D +// bDumpGLSL = true; +// } + + + // GLSL options + nOptions |= D3DToGL_OptionGLSL; // | D3DToGL_AddHexComments | D3DToGL_PutHexCommentsAfterLines; + if ( !IsOSX() ) + { + nOptions |= D3DToGL_OptionAllowStaticControlFlow; + } + sg_NewD3DToOpenGLTranslator.TranslateShader( (uint32 *) pReadPtr, &bufGLSLCode, &bVertexShader, nOptions, -1, 0, debugLabel ); + Assert( bVertexShader ); + + // Test to make sure these are identical +// if ( bDumpGLSL )//V_strcmp( (char *)bufGLCode.Base(), (char *)bufNewGLCode.Base() ) ) +// { +// WriteTranslatedFile( pLookup, iIndex, (char *)bufGLCode.Base(), "avp" ); // Old +// WriteTranslatedFile( pLookup, iIndex, (char *)bufNewGLCode.Base(), "avp2" ); // New + WriteTranslatedFile( pLookup, iIndex, (char *)bufGLSLCode.Base(), "glsl_v" ); // GLSL +// DisassembleShader( pLookup, iIndex, pReadPtr ); // Direct3D +// } + + #if defined( WRITE_ASSEMBLY ) + WriteTranslatedFile( pLookup, iIndex, (char *)bufGLCode.Base(), "avp" ); + #endif +#endif // 0 + +#ifdef DX_TO_GL_ABSTRACTION + // munge the debug label a bit to aid in decoding... catenate the iIndex on the end + char temp[1024]; + sprintf(temp, "%s vs-combo %d", (debugLabel)?debugLabel:"none", iIndex ); + debugLabelPtr = temp; +#endif + // pass binary code to d3d interface, on GL it will invoke the translator back to asm + hardwareShader = CreateD3DVertexShader( reinterpret_cast< DWORD *>( pReadPtr ), nShaderSize, pShaderName, debugLabelPtr ); + } + else + { +#if 0 + // this is all test code +// CUtlBuffer bufGLCode( 1000, 50000, CUtlBuffer::TEXT_BUFFER ); +// CUtlBuffer bufNewGLCode( 1000, 50000, CUtlBuffer::TEXT_BUFFER ); + CUtlBuffer bufGLSLCode( 1000, 50000, CUtlBuffer::TEXT_BUFFER ); + bool bVertexShader; + + + uint32 nOptions = D3DToGL_OptionUseEnvParams; + +// sg_D3DToOpenGLTranslator.TranslateShader( (uint32 *) pReadPtr, (char *)bufGLCode.Base(), bufGLCode.Size(), &bVertexShader, D3DToGL_OptionUseEnvParams, -1, debugLabel ); +// sg_NewD3DToOpenGLTranslator.TranslateShader( (uint32 *) pReadPtr, &bufNewGLCode, &bVertexShader, D3DToGL_OptionUseEnvParams, -1, debugLabel ); + + // GLSL options + nOptions |= D3DToGL_OptionGLSL;// | D3DToGL_OptionSRGBWriteSuffix | D3DToGL_AddHexComments | D3DToGL_PutHexCommentsAfterLines; + if ( !IsOSX() ) + { + nOptions |= D3DToGL_OptionAllowStaticControlFlow; + } + sg_NewD3DToOpenGLTranslator.TranslateShader( (uint32 *) pReadPtr, &bufGLSLCode, &bVertexShader, nOptions, -1, 0, debugLabel ); + + Assert( !bVertexShader ); + + // Test to make sure these are identical +// if ( V_strcmp( (char *)bufGLCode.Base(), (char *)bufNewGLCode.Base() ) ) +// { +// WriteTranslatedFile( pLookup, iIndex, (char *)bufGLCode.Base(), "afp" ); // Old +// WriteTranslatedFile( pLookup, iIndex, (char *)bufNewGLCode.Base(), "afp2" ); // New + WriteTranslatedFile( pLookup, iIndex, (char *)bufGLSLCode.Base(), "glsl_p" ); // GLSL +// DisassembleShader( pLookup, iIndex, pReadPtr ); // Direct3D +// } + + #if defined( WRITE_ASSEMBLY ) + WriteTranslatedFile( pLookup, iIndex, (char *)bufGLCode.Base(), "afp" ); + #endif +#endif // 0 + +#ifdef DX_TO_GL_ABSTRACTION + // munge the debug label a bit to aid in decoding... catenate the iIndex on the end + char temp[1024]; + sprintf(temp, "%s ps-combo %d", (debugLabel)?debugLabel:"", iIndex ); + debugLabelPtr = temp; +#endif + + // pass binary code to d3d interface, on GL it will invoke the translator back to asm + hardwareShader = CreateD3DPixelShader( reinterpret_cast< DWORD *>( pReadPtr ), pFileCache->m_Header.m_nCentroidMask, nShaderSize, pShaderName, debugLabelPtr ); + } + if ( hardwareShader == INVALID_HARDWARE_SHADER ) + { + Warning( "failed to create shader\n" ); + Assert( 0 ); + bOK = false; + break; + } + } + pLookup->m_ShaderStaticCombos.m_pHardwareShaders[iIndex] = hardwareShader; + pReadPtr += nShaderSize; + } + } + + delete[] pUnpackBuffer; + + return bOK; +} + +//----------------------------------------------------------------------------- +// Static method, called by thread, don't call anything non-threadsafe from handler!!! +//----------------------------------------------------------------------------- +void CShaderManager::QueuedLoaderCallback( void *pContext, void *pContext2, const void *pData, int nSize, LoaderError_t loaderError ) +{ + ShaderLookup_t* pLookup = (ShaderLookup_t *)pContext; + + bool bOK = ( loaderError == LOADERERROR_NONE ); + if ( bOK ) + { + if ( pContext2 ) + { + // presence denotes diff version + bOK = s_ShaderManager.CreateDynamicCombos_Ver4( pContext, (uint8 *)pData ); + } + else + { + bOK = s_ShaderManager.CreateDynamicCombos_Ver5( pContext, (uint8 *)pData ); + } + } + if ( !bOK ) + { + pLookup->m_Flags |= SHADER_FAILED_LOAD; + } +} + +//----------------------------------------------------------------------------- +// Loads all shaders +//----------------------------------------------------------------------------- +bool CShaderManager::LoadAndCreateShaders( ShaderLookup_t &lookup, bool bVertexShader, char *debugLabel ) +{ + const char *pName = m_ShaderSymbolTable.String( lookup.m_Name ); + + // find it in the cache + // a cache hit prevents costly i/o for static components, i.e. header, ref combo, etc. + ShaderFileCache_t fileCacheLookup; + fileCacheLookup.m_Name = lookup.m_Name; + fileCacheLookup.m_bVertexShader = bVertexShader; + int fileCacheIndex = m_ShaderFileCache.Find( fileCacheLookup ); + if ( fileCacheIndex == m_ShaderFileCache.InvalidIndex() ) + { + // not found, create a new entry + fileCacheIndex = m_ShaderFileCache.AddToTail(); + } + + lookup.m_hShaderFileCache = fileCacheIndex; + + // fetch from cache + ShaderFileCache_t *pFileCache = &m_ShaderFileCache[fileCacheIndex]; + ShaderHeader_t *pHeader = &pFileCache->m_Header; + + FileHandle_t hFile = FILESYSTEM_INVALID_HANDLE; + if ( pFileCache->IsValid() ) + { + // using cached header, just open file, no read of header needed + hFile = OpenFileAndLoadHeader( m_ShaderSymbolTable.String( pFileCache->m_Filename ), NULL ); + if ( hFile == FILESYSTEM_INVALID_HANDLE ) + { + // shouldn't happen + Assert( 0 ); + return false; + } + } + else + { + V_memset( pHeader, 0, sizeof( ShaderHeader_t ) ); + + // try the vsh/psh dir first + char filename[MAX_PATH]; + Q_snprintf( filename, MAX_PATH, "shaders\\%s\\%s" SHADER_FNAME_EXTENSION, bVertexShader ? "vsh" : "psh", pName ); + hFile = OpenFileAndLoadHeader( filename, pHeader ); + if ( hFile == FILESYSTEM_INVALID_HANDLE ) + { +#ifdef DYNAMIC_SHADER_COMPILE + // Dynamically compile if it's HLSL. + if ( LoadAndCreateShaders_Dynamic( lookup, bVertexShader ) ) + { + return true; + } + else + { + return false; + } +#endif + // next, try the fxc dir + Q_snprintf( filename, MAX_PATH, "shaders\\fxc\\%s" SHADER_FNAME_EXTENSION, pName ); + hFile = OpenFileAndLoadHeader( filename, pHeader ); + if ( hFile == FILESYSTEM_INVALID_HANDLE ) + { + lookup.m_Flags |= SHADER_FAILED_LOAD; + Warning( "Couldn't load %s shader %s\n", bVertexShader ? "vertex" : "pixel", pName ); + return false; + } + } + + lookup.m_Flags = pHeader->m_nFlags; + + pFileCache->m_Name = lookup.m_Name; + pFileCache->m_Filename = m_ShaderSymbolTable.AddString( filename ); + pFileCache->m_bVertexShader = bVertexShader; + + if ( pFileCache->IsOldVersion() ) + { + int referenceComboSize = ((ShaderHeader_t_v4 *)pHeader)->m_nDiffReferenceSize; + if ( referenceComboSize ) + { + // cache the reference combo + pFileCache->m_ReferenceCombo.EnsureCapacity( referenceComboSize ); + g_pFullFileSystem->Read( pFileCache->m_ReferenceCombo.Base(), referenceComboSize, hFile ); + } + } + else + { + // cache the dictionary + pFileCache->m_StaticComboRecords.EnsureCount( pHeader->m_nNumStaticCombos ); + g_pFullFileSystem->Read( pFileCache->m_StaticComboRecords.Base(), pHeader->m_nNumStaticCombos * sizeof( StaticComboRecord_t ), hFile ); + if ( pFileCache->IsVersion6() ) + { + // read static combo alias records + int nNumDups; + g_pFullFileSystem->Read( &nNumDups, sizeof( nNumDups ), hFile ); + if ( nNumDups ) + { + pFileCache->m_StaticComboDupRecords.EnsureCount( nNumDups ); + g_pFullFileSystem->Read( pFileCache->m_StaticComboDupRecords.Base(), nNumDups * sizeof( StaticComboAliasRecord_t ), hFile ); + } + } + + } + } + + // FIXME: should make lookup and ShaderStaticCombos_t are pool allocated. + int i; + lookup.m_ShaderStaticCombos.m_nCount = pHeader->m_nDynamicCombos; + lookup.m_ShaderStaticCombos.m_pHardwareShaders = new HardwareShader_t[pHeader->m_nDynamicCombos]; + if ( IsPC() && m_bCreateShadersOnDemand ) + { + lookup.m_ShaderStaticCombos.m_pCreationData = new ShaderStaticCombos_t::ShaderCreationData_t[pHeader->m_nDynamicCombos]; + } + for ( i = 0; i < pHeader->m_nDynamicCombos; i++ ) + { + lookup.m_ShaderStaticCombos.m_pHardwareShaders[i] = INVALID_HARDWARE_SHADER; + } + + int nStartingOffset = 0; + int nEndingOffset = 0; + + if ( pFileCache->IsOldVersion() ) + { + int nDictionaryOffset = sizeof( ShaderHeader_t ) + ((ShaderHeader_t_v4 *)pHeader)->m_nDiffReferenceSize; + + // read in shader's dynamic combos directory + lookup.m_pComboDictionary = new ShaderDictionaryEntry_t[pHeader->m_nDynamicCombos]; + g_pFullFileSystem->Seek( hFile, nDictionaryOffset + lookup.m_nStaticIndex * sizeof( ShaderDictionaryEntry_t ), FILESYSTEM_SEEK_HEAD ); + g_pFullFileSystem->Read( lookup.m_pComboDictionary, pHeader->m_nDynamicCombos * sizeof( ShaderDictionaryEntry_t ), hFile ); + + // want single read of all this shader's dynamic combos into a target buffer + // shaders are written sequentially, determine starting offset and length + for ( i = 0; i < pHeader->m_nDynamicCombos; i++ ) + { + if ( lookup.m_pComboDictionary[i].m_Offset == -1 ) + { + // skipped + continue; + } + + // ensure offsets are in fact sequentially ascending + Assert( lookup.m_pComboDictionary[i].m_Offset >= nStartingOffset && lookup.m_pComboDictionary[i].m_Size >= 0 ); + + if ( !nStartingOffset ) + { + nStartingOffset = lookup.m_pComboDictionary[i].m_Offset; + } + nEndingOffset = lookup.m_pComboDictionary[i].m_Offset + lookup.m_pComboDictionary[i].m_Size; + } + if ( !nStartingOffset ) + { + g_pFullFileSystem->Close( hFile ); + Warning( "Shader '%s' - All dynamic combos skipped. This is bad!\n", m_ShaderSymbolTable.String( pFileCache->m_Filename ) ); + return false; + } + } + else + { + int nStaticComboIdx = pFileCache->FindCombo( lookup.m_nStaticIndex / pFileCache->m_Header.m_nDynamicCombos ); + if ( nStaticComboIdx == -1 ) + { + g_pFullFileSystem->Close( hFile ); + lookup.m_Flags |= SHADER_FAILED_LOAD; + Warning( "Shader '%s' - Couldn't load combo %d of shader (dyn=%d)\n", m_ShaderSymbolTable.String( pFileCache->m_Filename ), lookup.m_nStaticIndex, pFileCache->m_Header.m_nDynamicCombos ); + return false; + } + + nStartingOffset = pFileCache->m_StaticComboRecords[nStaticComboIdx].m_nFileOffset; + nEndingOffset = pFileCache->m_StaticComboRecords[nStaticComboIdx+1].m_nFileOffset; + } + + // align offsets for unbuffered optimal i/o - fastest i/o possible + unsigned nOffsetAlign, nSizeAlign, nBufferAlign; + g_pFullFileSystem->GetOptimalIOConstraints( hFile, &nOffsetAlign, &nSizeAlign, &nBufferAlign ); + unsigned int nAlignedOffset = AlignValue( ( nStartingOffset - nOffsetAlign ) + 1, nOffsetAlign ); + unsigned int nAlignedBytesToRead = AlignValue( nEndingOffset - nAlignedOffset, nSizeAlign ); + + // used for adjusting provided buffer to actual data + lookup.m_nDataOffset = nStartingOffset - nAlignedOffset; + + bool bOK = true; + if ( IsX360() && g_pQueuedLoader->IsMapLoading() ) + { + LoaderJob_t loaderJob; + loaderJob.m_pFilename = m_ShaderSymbolTable.String( pFileCache->m_Filename ); + loaderJob.m_pPathID = "GAME"; + loaderJob.m_pCallback = QueuedLoaderCallback; + loaderJob.m_pContext = (void *)&lookup; + loaderJob.m_pContext2 = (void *)pFileCache->IsOldVersion(); + loaderJob.m_Priority = LOADERPRIORITY_DURINGPRELOAD; + loaderJob.m_nBytesToRead = nAlignedBytesToRead; + loaderJob.m_nStartOffset = nAlignedOffset; + g_pQueuedLoader->AddJob( &loaderJob ); + } + else + { + //printf("\n CShaderManager::LoadAndCreateShaders - reading %d bytes from file offset %d", nAlignedBytesToRead, nAlignedOffset); + // single optimal read of all dynamic combos into monolithic buffer + uint8 *pOptimalBuffer = (uint8 *)g_pFullFileSystem->AllocOptimalReadBuffer( hFile, nAlignedBytesToRead, nAlignedOffset ); + g_pFullFileSystem->Seek( hFile, nAlignedOffset, FILESYSTEM_SEEK_HEAD ); + g_pFullFileSystem->Read( pOptimalBuffer, nAlignedBytesToRead, hFile ); + + if ( pFileCache->IsOldVersion() ) + { + bOK = CreateDynamicCombos_Ver4( &lookup, pOptimalBuffer ); + } + else + { + bOK = CreateDynamicCombos_Ver5( &lookup, pOptimalBuffer, debugLabel ); + } + + g_pFullFileSystem->FreeOptimalReadBuffer( pOptimalBuffer ); + } + + g_pFullFileSystem->Close( hFile ); + + if ( !bOK ) + { + lookup.m_Flags |= SHADER_FAILED_LOAD; + } + + return bOK; +} + + +//----------------------------------------------------------------------------------old code + +#if 0 + + // Set this convar internally to build or add to the shader cache file + // We really only expect this to work on DX_TO_GL_ABSTRACTION + ConVar mat_cacheshaders( "mat_cacheshaders", "0", FCVAR_DEVELOPMENTONLY ); + + #define SHADER_CACHE_FILE "shader_cache.cfg" + #define PROGRAM_CACHE_FILE "program_cache.cfg" + + static void WriteToShaderCache( const char *pShaderName, const int nIndex ) + { +#ifndef DX_TO_GL_ABSTRACTION + return; +#endif + + KeyValues *pShaderCache = new KeyValues( "shadercache" ); + // we don't load anything, it starts empty.. pShaderCache->LoadFromFile( g_pFullFileSystem, SHADER_CACHE_FILE, "MOD" ); + + if ( !pShaderCache ) + { + Warning( "Could not write to shader cache file!\n" ); + return; + } + + // Subkey for specific shader + KeyValues *pShaderKey = pShaderCache->FindKey( pShaderName, true ); + Assert( pShaderKey ); + + bool bFound = false; + int nKeys = 0; + char szIndex[8]; + FOR_EACH_VALUE( pShaderKey, pValues ) + { + if ( pValues->GetInt() == nIndex ) + { + bFound = true; + } + nKeys++; + } + + if ( !bFound ) + { + V_snprintf( szIndex, 8, "%d", nKeys ); + pShaderKey->SetInt( szIndex, nIndex ); + } + + pShaderCache->SaveToFile( g_pFullFileSystem, SHADER_CACHE_FILE, "MOD" ); + pShaderCache->deleteThis(); + } + +void CShaderManager::WarmShaderCache() + { +#ifndef DX_TO_GL_ABSTRACTION + return; +#endif + + // Don't access the cache if we're building it! + if ( mat_cacheshaders.GetBool() ) + return; + + // Don't warm the cache if we're just going to monkey with the shaders anyway + #ifdef DYNAMIC_SHADER_COMPILE + return; + #endif + + double st = Sys_FloatTime(); + + + // + // First we warm SHADERS =============================================== + // + + KeyValues *pShaderCache = new KeyValues( "shadercache" ); + pShaderCache->LoadFromFile( g_pFullFileSystem, SHADER_CACHE_FILE, "MOD" ); + + if ( !pShaderCache ) + { + Warning( "Could not find shader cache file!\n" ); + return; + } + + // Run through each shader in the cache + FOR_EACH_SUBKEY( pShaderCache, pShaderKey ) + { + const char *pShaderName = pShaderKey->GetName(); + bool bVertexShader = Q_stristr( pShaderName, "_vs20" ) || Q_stristr( pShaderName, "_vs30" ); + + FOR_EACH_VALUE( pShaderKey, pValue ) + { + char temp[1024]; + int staticIndex = pValue->GetInt(); + + if ( bVertexShader ) + { + V_snprintf( temp, sizeof(temp), "vs-file %s vs-index %d", pShaderName, staticIndex ); + CreateVertexShader( pShaderName, staticIndex, temp ); + } + else + { + V_snprintf( temp, sizeof(temp), "ps-file %s ps-index %d", pShaderName, staticIndex ); + CreatePixelShader( pShaderName, staticIndex, temp ); + } + } + } + + pShaderCache->deleteThis(); + + + // + // Next, we warm PROGRAMS (which are pairs of shaders) ================= + // + + KeyValues *pProgramCache = new KeyValues( "programcache" ); + pProgramCache->LoadFromFile( g_pFullFileSystem, PROGRAM_CACHE_FILE, "MOD" ); + + if ( !pProgramCache ) + { + Warning( "Could not find program cache file!\n" ); + return; + } + + // Run through each program in the cache + FOR_EACH_SUBKEY( pProgramCache, pProgramKey ) + { + KeyValues *pValue = pProgramKey->GetFirstValue(); + const char *pVertexShaderName = pValue->GetString(); + pValue = pValue->GetNextValue(); + const char *pPixelShaderName = pValue->GetString(); + pValue = pValue->GetNextValue(); + int nVertexShaderStaticIndex = pValue->GetInt(); + pValue = pValue->GetNextValue(); + int nPixelShaderStaticIndex = pValue->GetInt(); + pValue = pValue->GetNextValue(); + int nVertexShaderDynamicIndex = pValue->GetInt(); + pValue = pValue->GetNextValue(); + int nPixelShaderDynamicIndex = pValue->GetInt(); + + ShaderLookup_t vshLookup; + vshLookup.m_Name = m_ShaderSymbolTable.AddString( pVertexShaderName ); // TODO: use String() here and catch this odd case + vshLookup.m_nStaticIndex = nVertexShaderStaticIndex; + VertexShader_t vertexShader = m_VertexShaderDict.Find( vshLookup ); + + ShaderLookup_t pshLookup; + pshLookup.m_Name = m_ShaderSymbolTable.AddString( pPixelShaderName ); + pshLookup.m_nStaticIndex = nPixelShaderStaticIndex; + PixelShader_t pixelShader = m_PixelShaderDict.Find( pshLookup ); + + // If we found both shaders, do the link! + if ( ( vertexShader != m_VertexShaderDict.InvalidIndex() ) && ( pixelShader != m_PixelShaderDict.InvalidIndex() ) ) + { + #ifdef DX_TO_GL_ABSTRACTION + //HardwareShader_t hardwareVertexShader = vshLookup.m_ShaderStaticCombos.m_pHardwareShaders[nVertexShaderDynamicIndex]; + //HardwareShader_t hardwarePixelShader = pshLookup.m_ShaderStaticCombos.m_pHardwareShaders[nPixelShaderDynamicIndex]; + + HardwareShader_t hardwareVertexShader = m_VertexShaderDict[vertexShader].m_ShaderStaticCombos.m_pHardwareShaders[nVertexShaderDynamicIndex]; + HardwareShader_t hardwarePixelShader = m_PixelShaderDict[pixelShader].m_ShaderStaticCombos.m_pHardwareShaders[nPixelShaderDynamicIndex]; + + if ( ( hardwareVertexShader != INVALID_HARDWARE_SHADER ) && ( hardwarePixelShader != INVALID_HARDWARE_SHADER ) ) + { + if ( S_OK != Dx9Device()->LinkShaderPair( (IDirect3DVertexShader9 *)hardwareVertexShader, (IDirect3DPixelShader9 *)hardwarePixelShader ) ) + { + Warning( "Could not link OpenGL shaders: %s (%d, %d) : %s (%d, %d)\n", pVertexShaderName, nVertexShaderStaticIndex, nVertexShaderDynamicIndex, pPixelShaderName, nPixelShaderStaticIndex, nPixelShaderDynamicIndex ); + } + } + #endif + } + else + { + Warning( "Invalid shader linkage: %s (%d, %d) : %s (%d, %d)\n", pVertexShaderName, nVertexShaderStaticIndex, nVertexShaderDynamicIndex, pPixelShaderName, nPixelShaderStaticIndex, nPixelShaderDynamicIndex ); + } + } + + pProgramCache->deleteThis(); + + float elapsed = ( float )( Sys_FloatTime() - st ) * 1000.0; + DevMsg( "WarmShaderCache took %.3f msec\n", elapsed ); + } + +#endif +//----------------------------------------------------------------------------------old code + +#ifdef DX_TO_GL_ABSTRACTION +// if shaders are changed in a way that requires the client-side cache to be invalidated, +// increment this string - such changes include combo changes (skips, adding combos) +const char *k_pszShaderCacheRootKey = "glshadercachev002"; +#endif + +void CShaderManager::SaveShaderCache( char *cacheName ) +{ +#ifdef DX_TO_GL_ABSTRACTION // must ifdef, it uses calls which don't exist in the real DX9 interface + + KeyValues *pProgramCache = new KeyValues( k_pszShaderCacheRootKey ); + + if ( !pProgramCache ) + { + Warning( "Could not write to program cache file!\n" ); + return; + } + + int i=0; + GLMShaderPairInfo info; + + do + { + Dx9Device()->QueryShaderPair( i, &info ); + + if (info.m_status==1) + { + // found one + // extract values of interest which represent a pair of shaders + + if (info.m_vsName[0] && info.m_psName[0] && (info.m_vsDynamicIndex > -1) && (info.m_psDynamicIndex > -1) ) + { + // make up a key - this thing is really a list of tuples, so need not be keyed by anything particular + KeyValues *pProgramKey = pProgramCache->CreateNewKey(); + Assert( pProgramKey ); + + pProgramKey->SetString ( "vs", info.m_vsName ); + pProgramKey->SetString ( "ps", info.m_psName ); + + pProgramKey->SetInt ( "vs_static", info.m_vsStaticIndex ); + pProgramKey->SetInt ( "ps_static", info.m_psStaticIndex ); + + pProgramKey->SetInt ( "vs_dynamic", info.m_vsDynamicIndex ); + pProgramKey->SetInt ( "ps_dynamic", info.m_psDynamicIndex ); + } + } + i++; + } while( info.m_status >= 0 ); + + pProgramCache->SaveToFile( g_pFullFileSystem, cacheName, "MOD" ); + pProgramCache->deleteThis(); + + // done! whew +#endif +} + +bool CShaderManager::LoadShaderCache( char *cacheName ) +{ +#ifdef DX_TO_GL_ABSTRACTION + KeyValues *pProgramCache = new KeyValues( "" ); + bool found = pProgramCache->LoadFromFile( g_pFullFileSystem, cacheName, "MOD" ); + + if ( !found ) + { + Warning( "Could not load program cache file %s\n", cacheName ); + return false; + } + + if ( Q_stricmp( pProgramCache->GetName(), k_pszShaderCacheRootKey ) ) + { + Warning( "Ignoring out-of-date shader cache (%s) with root key %s\n", cacheName, pProgramCache->GetName() ); + return false; + } + + int nTotalLinkedShaders = 0; + int nTotalKeyValues = 0; + + // walk the table.. + FOR_EACH_SUBKEY( pProgramCache, pProgramKey ) + { + nTotalKeyValues++; + + // extract values decribing the specific active pair + // then see if either stage needs a compilation done + // then proceed to link + + KeyValues *pValue = pProgramKey->GetFirstValue(); + if (!pValue) + continue; + const char *pVertexShaderName = pValue->GetString(); + + pValue = pValue->GetNextValue(); + if (!pValue) + continue; + const char *pPixelShaderName = pValue->GetString(); + + pValue = pValue->GetNextValue(); + if (!pValue) + continue; + int nVertexShaderStaticIndex = pValue->GetInt(); + + pValue = pValue->GetNextValue(); + if (!pValue) + continue; + int nPixelShaderStaticIndex = pValue->GetInt(); + + pValue = pValue->GetNextValue(); + if (!pValue) + continue; + int nVertexShaderDynamicIndex = pValue->GetInt(); + + pValue = pValue->GetNextValue(); + if (!pValue) + continue; + int nPixelShaderDynamicIndex = pValue->GetInt(); + + ShaderLookup_t vshLookup; + vshLookup.m_Name = m_ShaderSymbolTable.AddString( pVertexShaderName ); // TODO: use String() here and catch this odd case + vshLookup.m_nStaticIndex = nVertexShaderStaticIndex; + VertexShader_t vertexShader = m_VertexShaderDict.Find( vshLookup ); + + // if the VS was not found - now is the time to build it + if( vertexShader == m_VertexShaderDict.InvalidIndex()) + { + char temp[1024]; + + V_snprintf( temp, sizeof(temp), "vs-file %s vs-index %d", pVertexShaderName, nVertexShaderStaticIndex ); + CreateVertexShader( pVertexShaderName, nVertexShaderStaticIndex, temp ); + + // this one should not fail + vertexShader = m_VertexShaderDict.Find( vshLookup ); + Assert( vertexShader != m_VertexShaderDict.InvalidIndex()); + } + + ShaderLookup_t pshLookup; + pshLookup.m_Name = m_ShaderSymbolTable.AddString( pPixelShaderName ); + pshLookup.m_nStaticIndex = nPixelShaderStaticIndex; + PixelShader_t pixelShader = m_PixelShaderDict.Find( pshLookup ); + + if( pixelShader == m_PixelShaderDict.InvalidIndex()) + { + char temp[1024]; + + V_snprintf( temp, sizeof(temp), "ps-file %s ps-index %d", pPixelShaderName, nPixelShaderStaticIndex ); + CreatePixelShader( pPixelShaderName, nPixelShaderStaticIndex, temp ); + + // this one should not fail + pixelShader = m_PixelShaderDict.Find( pshLookup ); + Assert( pixelShader != m_PixelShaderDict.InvalidIndex()); + } + + // If we found both shaders, do the link! + if ( ( vertexShader != m_VertexShaderDict.InvalidIndex() ) && ( pixelShader != m_PixelShaderDict.InvalidIndex() ) ) + { + // double check that the hardware shader arrays are actually instantiated.. bail on the attempt if not (odd...) + if (m_VertexShaderDict[vertexShader].m_ShaderStaticCombos.m_pHardwareShaders && m_PixelShaderDict[pixelShader].m_ShaderStaticCombos.m_pHardwareShaders) + { + // and sanity check the indices.. + if ( (nVertexShaderDynamicIndex>=0) && (nPixelShaderDynamicIndex>=0) ) + { + HardwareShader_t hardwareVertexShader = m_VertexShaderDict[vertexShader].m_ShaderStaticCombos.m_pHardwareShaders[nVertexShaderDynamicIndex]; + HardwareShader_t hardwarePixelShader = m_PixelShaderDict[pixelShader].m_ShaderStaticCombos.m_pHardwareShaders[nPixelShaderDynamicIndex]; + + if ( ( hardwareVertexShader != INVALID_HARDWARE_SHADER ) && ( hardwarePixelShader != INVALID_HARDWARE_SHADER ) ) + { + if ( S_OK != Dx9Device()->LinkShaderPair( (IDirect3DVertexShader9 *)hardwareVertexShader, (IDirect3DPixelShader9 *)hardwarePixelShader ) ) + { + Warning( "Could not link OpenGL shaders: %s (%d, %d) : %s (%d, %d)\n", pVertexShaderName, nVertexShaderStaticIndex, nVertexShaderDynamicIndex, pPixelShaderName, nPixelShaderStaticIndex, nPixelShaderDynamicIndex ); + } + else + { + nTotalLinkedShaders++; + } + } + } + else + { + Warning( "nVertexShaderDynamicIndex or nPixelShaderDynamicIndex was negative\n" ); + } + } + else + { + Warning( "m_pHardwareShaders was null\n" ); + } + } + else + { + Warning( "Invalid shader linkage: %s (%d, %d) : %s (%d, %d)\n", pVertexShaderName, nVertexShaderStaticIndex, nVertexShaderDynamicIndex, pPixelShaderName, nPixelShaderStaticIndex, nPixelShaderDynamicIndex ); + } + } + + Msg( "Loaded program cache file \"%s\", total keyvalues: %i, total successfully linked: %i\n", cacheName, nTotalKeyValues, nTotalLinkedShaders ); + + return true; + +#else + return false; // have to return a value on Windows build to appease compiler +#endif +} + + + +//----------------------------------------------------------------------------- +// Creates and destroys vertex shaders +//----------------------------------------------------------------------------- +VertexShader_t CShaderManager::CreateVertexShader( const char *pFileName, int nStaticVshIndex, char *debugLabel ) +{ + MEM_ALLOC_CREDIT(); + + if ( !pFileName ) + { + return INVALID_SHADER; + } + + #if 0 //old + if ( mat_cacheshaders.GetBool() ) + { + WriteToShaderCache( pFileName, nStaticVshIndex ); + } + #endif + + VertexShader_t shader; + ShaderLookup_t lookup; + lookup.m_Name = m_ShaderSymbolTable.AddString( pFileName ); + lookup.m_nStaticIndex = nStaticVshIndex; + shader = m_VertexShaderDict.Find( lookup ); + if ( shader == m_VertexShaderDict.InvalidIndex() ) + { + //printf("\nCShaderManager::CreateVertexShader( filename = %s, staticVshIndex = %d - not in cache", pFileName, nStaticVshIndex ); + + shader = m_VertexShaderDict.AddToTail( lookup ); + if ( !LoadAndCreateShaders( m_VertexShaderDict[shader], true, debugLabel ) ) + { + return INVALID_SHADER; + } + } + m_VertexShaderDict[shader].IncRefCount(); + return shader; +} + +//----------------------------------------------------------------------------- +// Create pixel shader +//----------------------------------------------------------------------------- +PixelShader_t CShaderManager::CreatePixelShader( const char *pFileName, int nStaticPshIndex, char *debugLabel ) +{ + MEM_ALLOC_CREDIT(); + + if ( !pFileName ) + { + return INVALID_SHADER; + } + + #if 0 //old + if ( mat_cacheshaders.GetBool() ) + { + WriteToShaderCache( pFileName, nStaticPshIndex ); + } + #endif + + PixelShader_t shader; + ShaderLookup_t lookup; + lookup.m_Name = m_ShaderSymbolTable.AddString( pFileName ); + lookup.m_nStaticIndex = nStaticPshIndex; + shader = m_PixelShaderDict.Find( lookup ); + if ( shader == m_PixelShaderDict.InvalidIndex() ) + { + shader = m_PixelShaderDict.AddToTail( lookup ); + if ( !LoadAndCreateShaders( m_PixelShaderDict[shader], false, debugLabel ) ) + { + return INVALID_SHADER; + } + } + m_PixelShaderDict[shader].IncRefCount(); + return shader; +} + +//----------------------------------------------------------------------------- +// Clear the refCounts to zero +//----------------------------------------------------------------------------- +void CShaderManager::ClearVertexAndPixelShaderRefCounts() +{ + for ( VertexShader_t vshIndex = m_VertexShaderDict.Head(); + vshIndex != m_VertexShaderDict.InvalidIndex(); + vshIndex = m_VertexShaderDict.Next( vshIndex ) ) + { + m_VertexShaderDict[vshIndex].m_nRefCount = 0; + } + + for ( PixelShader_t pshIndex = m_PixelShaderDict.Head(); + pshIndex != m_PixelShaderDict.InvalidIndex(); + pshIndex = m_PixelShaderDict.Next( pshIndex ) ) + { + m_PixelShaderDict[pshIndex].m_nRefCount = 0; + } +} + +//----------------------------------------------------------------------------- +// Destroy all shaders that have no reference +//----------------------------------------------------------------------------- +void CShaderManager::PurgeUnusedVertexAndPixelShaders() +{ + #ifdef DX_TO_GL_ABSTRACTION + if (mat_autosave_glshaders.GetInt()) + { + SaveShaderCache("glshaders.cfg"); + } + return; // don't purge shaders, it's too costly to put them back + #endif + + // iterate vertex shaders + for ( VertexShader_t vshIndex = m_VertexShaderDict.Head(); vshIndex != m_VertexShaderDict.InvalidIndex(); ) + { + Assert( m_VertexShaderDict[vshIndex].m_nRefCount >= 0 ); + + // Get the next one before we potentially delete the current one. + VertexShader_t next = m_VertexShaderDict.Next( vshIndex ); + if ( m_VertexShaderDict[vshIndex].m_nRefCount <= 0 ) + { + DestroyVertexShader( vshIndex ); + } + vshIndex = next; + } + + // iterate pixel shaders + for ( PixelShader_t pshIndex = m_PixelShaderDict.Head(); pshIndex != m_PixelShaderDict.InvalidIndex(); ) + { + Assert( m_PixelShaderDict[pshIndex].m_nRefCount >= 0 ); + + // Get the next one before we potentially delete the current one. + PixelShader_t next = m_PixelShaderDict.Next( pshIndex ); + if ( m_PixelShaderDict[pshIndex].m_nRefCount <= 0 ) + { + DestroyPixelShader( pshIndex ); + } + pshIndex = next; + } +} + + + +void* CShaderManager::GetCurrentVertexShader() +{ + return (void*)m_HardwareVertexShader; +} + +void* CShaderManager::GetCurrentPixelShader() +{ + return (void*)m_HardwarePixelShader; +} + + +//----------------------------------------------------------------------------- +// The low-level dx call to set the vertex shader state +//----------------------------------------------------------------------------- +void CShaderManager::SetVertexShaderState( HardwareShader_t shader, DataCacheHandle_t hCachedShader ) +{ + if ( m_HardwareVertexShader != shader ) + { + RECORD_COMMAND( DX8_SET_VERTEX_SHADER, 1 ); + RECORD_INT( ( int )shader ); // hack hack hack + + Dx9Device()->SetVertexShader( (IDirect3DVertexShader9*)shader ); + m_HardwareVertexShader = shader; + } +} + +void CShaderManager::BindVertexShader( VertexShaderHandle_t hVertexShader ) +{ + HardwareShader_t hHardwareShader = m_RawVertexShaderDict[ (VertexShaderIndex_t)hVertexShader] ; + SetVertexShaderState( hHardwareShader ); +} + + +//----------------------------------------------------------------------------- +// Sets a particular vertex shader as the current shader +//----------------------------------------------------------------------------- +void CShaderManager::SetVertexShader( VertexShader_t shader ) +{ + // Determine which vertex shader to use... + if ( shader == INVALID_SHADER ) + { + SetVertexShaderState( 0 ); + return; + } + + int vshIndex = m_nVertexShaderIndex; + Assert( vshIndex >= 0 ); + if( vshIndex < 0 ) + { + vshIndex = 0; + } + + ShaderLookup_t &vshLookup = m_VertexShaderDict[shader]; +// Warning( "vsh: %s static: %d dynamic: %d\n", m_ShaderSymbolTable.String( vshLookup.m_Name ), +// vshLookup.m_nStaticIndex, m_nVertexShaderIndex ); + +#ifdef DYNAMIC_SHADER_COMPILE + HardwareShader_t &dxshader = m_VertexShaderDict[shader].m_ShaderStaticCombos.m_pHardwareShaders[vshIndex]; + if ( dxshader == INVALID_HARDWARE_SHADER ) + { + // compile it since we haven't already! + dxshader = CompileShader( m_ShaderSymbolTable.String( vshLookup.m_Name ), vshLookup.m_nStaticIndex, vshIndex, true ); + Assert( dxshader != INVALID_HARDWARE_SHADER ); + + if( IsX360() ) + { + //360 does not respond well at all to bad shaders or Error() calls. So we're staying here until we get something that compiles + while( dxshader == INVALID_HARDWARE_SHADER ) + { + Warning( "A dynamically compiled vertex shader has failed to build. Pausing for 5 seconds and attempting rebuild.\n" ); +#ifdef _WIN32 + Sleep( 5000 ); +#elif POSIX + usleep( 5000 ); +#endif + dxshader = CompileShader( m_ShaderSymbolTable.String( vshLookup.m_Name ), vshLookup.m_nStaticIndex, vshIndex, true ); + } + } + } +#else + if ( vshLookup.m_Flags & SHADER_FAILED_LOAD ) + { + Assert( 0 ); + return; + } +#ifdef _DEBUG + vshDebugIndex = (vshDebugIndex + 1) % MAX_SHADER_HISTORY; + Q_strncpy( vshDebugName[vshDebugIndex], m_ShaderSymbolTable.String( vshLookup.m_Name ), sizeof( vshDebugName[0] ) ); +#endif + Assert( vshIndex < vshLookup.m_ShaderStaticCombos.m_nCount ); + HardwareShader_t dxshader = vshLookup.m_ShaderStaticCombos.m_pHardwareShaders[vshIndex]; +#endif + + if ( IsPC() && ( dxshader == INVALID_HARDWARE_SHADER ) && m_bCreateShadersOnDemand ) + { +#ifdef DYNAMIC_SHADER_COMPILE + ShaderStaticCombos_t::ShaderCreationData_t *pCreationData = &m_VertexShaderDict[shader].m_ShaderStaticCombos.m_pCreationData[vshIndex]; +#else + ShaderStaticCombos_t::ShaderCreationData_t *pCreationData = &vshLookup.m_ShaderStaticCombos.m_pCreationData[vshIndex]; +#endif + + dxshader = CreateD3DVertexShader( ( DWORD * )pCreationData->ByteCode.Base(), pCreationData->ByteCode.Count(), m_ShaderSymbolTable.String( vshLookup.m_Name ) ); + +#ifdef DYNAMIC_SHADER_COMPILE + // copy the compiled shader handle back to wherever it's supposed to be stored + m_VertexShaderDict[shader].m_ShaderStaticCombos.m_pHardwareShaders[vshIndex] = dxshader; +#else + vshLookup.m_ShaderStaticCombos.m_pHardwareShaders[vshIndex] = dxshader; +#endif + } + + Assert( dxshader ); + +#ifndef DYNAMIC_SHADER_COMPILE + if( !dxshader ) + { + Error( "!!!!!Using invalid shader combo!!!!! Consult a programmer and tell them to build debug materialsystem.dll and stdshader*.dll. Run with \"mat_bufferprimitives 0\" and look for CMaterial in the call stack and see what m_pDebugName is. You are likely using a shader combo that has been skipped.\n" ); + } +#endif + + SetVertexShaderState( dxshader ); +} + +//----------------------------------------------------------------------------- +// The low-level dx call to set the pixel shader state +//----------------------------------------------------------------------------- +void CShaderManager::SetPixelShaderState( HardwareShader_t shader, DataCacheHandle_t hCachedShader ) +{ + if ( m_HardwarePixelShader != shader ) + { + Dx9Device()->SetPixelShader( (IDirect3DPixelShader*)shader ); + m_HardwarePixelShader = shader; + } +} + +void CShaderManager::BindPixelShader( PixelShaderHandle_t hPixelShader ) +{ + HardwareShader_t hHardwareShader = m_RawPixelShaderDict[ (PixelShaderIndex_t)hPixelShader ]; + SetPixelShaderState( hHardwareShader ); +} + + +//----------------------------------------------------------------------------- +// Sets a particular pixel shader as the current shader +//----------------------------------------------------------------------------- +void CShaderManager::SetPixelShader( PixelShader_t shader ) +{ + if ( shader == INVALID_SHADER ) + { + SetPixelShaderState( 0 ); + return; + } + + int pshIndex = m_nPixelShaderIndex; + Assert( pshIndex >= 0 ); + ShaderLookup_t &pshLookup = m_PixelShaderDict[shader]; +// Warning( "psh: %s static: %d dynamic: %d\n", m_ShaderSymbolTable.String( pshLookup.m_Name ), +// pshLookup.m_nStaticIndex, m_nPixelShaderIndex ); + +#ifdef DYNAMIC_SHADER_COMPILE + HardwareShader_t &dxshader = m_PixelShaderDict[shader].m_ShaderStaticCombos.m_pHardwareShaders[pshIndex]; + if ( dxshader == INVALID_HARDWARE_SHADER ) + { + // compile it since we haven't already! + dxshader = CompileShader( m_ShaderSymbolTable.String( pshLookup.m_Name ), pshLookup.m_nStaticIndex, pshIndex, false ); +// Assert( dxshader != INVALID_HARDWARE_SHADER ); + + if( IsX360() ) + { + //360 does not respond well at all to bad shaders or Error() calls. So we're staying here until we get something that compiles + while( dxshader == INVALID_HARDWARE_SHADER ) + { + Warning( "A dynamically compiled pixel shader has failed to build. Pausing for 5 seconds and attempting rebuild.\n" ); +#ifdef _WIN32 + Sleep( 5000 ); +#elif POSIX + usleep( 5000 ); +#endif + dxshader = CompileShader( m_ShaderSymbolTable.String( pshLookup.m_Name ), pshLookup.m_nStaticIndex, pshIndex, false ); + } + } + } +#else + if ( pshLookup.m_Flags & SHADER_FAILED_LOAD ) + { + Assert( 0 ); + return; + } +#ifdef _DEBUG + pshDebugIndex = (pshDebugIndex + 1) % MAX_SHADER_HISTORY; + Q_strncpy( pshDebugName[pshDebugIndex], m_ShaderSymbolTable.String( pshLookup.m_Name ), sizeof( pshDebugName[0] ) ); +#endif + HardwareShader_t dxshader = pshLookup.m_ShaderStaticCombos.m_pHardwareShaders[pshIndex]; +#endif + + if ( IsPC() && ( dxshader == INVALID_HARDWARE_SHADER ) && m_bCreateShadersOnDemand ) + { +#ifdef DYNAMIC_SHADER_COMPILE + ShaderStaticCombos_t::ShaderCreationData_t *pCreationData = &m_PixelShaderDict[shader].m_ShaderStaticCombos.m_pCreationData[pshIndex]; +#else + ShaderStaticCombos_t::ShaderCreationData_t *pCreationData = &pshLookup.m_ShaderStaticCombos.m_pCreationData[pshIndex]; +#endif + + const char *pShaderName = m_ShaderSymbolTable.String( pshLookup.m_Name ); + dxshader = CreateD3DPixelShader( ( DWORD * )pCreationData->ByteCode.Base(), pCreationData->iCentroidMask, pCreationData->ByteCode.Count(), pShaderName ); + +#ifdef DYNAMIC_SHADER_COMPILE + // copy the compiled shader handle back to wherever it's supposed to be stored + m_PixelShaderDict[shader].m_ShaderStaticCombos.m_pHardwareShaders[pshIndex] = dxshader; +#else + pshLookup.m_ShaderStaticCombos.m_pHardwareShaders[pshIndex] = dxshader; +#endif + } + + AssertMsg( dxshader != INVALID_HARDWARE_SHADER, "Failed to set pixel shader." ); + SetPixelShaderState( dxshader ); +} + +//----------------------------------------------------------------------------- +// Resets the shader state +//----------------------------------------------------------------------------- +void CShaderManager::ResetShaderState() +{ + // This will force the calls to SetVertexShader + SetPixelShader to actually set the state + m_HardwareVertexShader = (HardwareShader_t)-1; + m_HardwarePixelShader = (HardwareShader_t)-1; + + SetVertexShader( INVALID_SHADER ); + SetPixelShader( INVALID_SHADER ); +} + +//----------------------------------------------------------------------------- +// Destroy a particular vertex shader +//----------------------------------------------------------------------------- +void CShaderManager::DestroyVertexShader( VertexShader_t shader ) +{ + ShaderStaticCombos_t &combos = m_VertexShaderDict[shader].m_ShaderStaticCombos; + int i; + for ( i = 0; i < combos.m_nCount; i++ ) + { + if ( combos.m_pHardwareShaders[i] != INVALID_HARDWARE_SHADER ) + { + IDirect3DVertexShader9* pShader = ( IDirect3DVertexShader9 * )combos.m_pHardwareShaders[i]; + UnregisterVS( pShader ); +#ifdef DBGFLAG_ASSERT + int nRetVal = +#endif + pShader->Release(); + Assert( nRetVal == 0 ); + } + } + delete [] combos.m_pHardwareShaders; + combos.m_pHardwareShaders = NULL; + + if ( combos.m_pCreationData != NULL ) + { + delete [] combos.m_pCreationData; + combos.m_pCreationData = NULL; + } + + m_VertexShaderDict.Remove( shader ); +} + +//----------------------------------------------------------------------------- +// Destroy a particular pixel shader +//----------------------------------------------------------------------------- +void CShaderManager::DestroyPixelShader( PixelShader_t pixelShader ) +{ + ShaderStaticCombos_t &combos = m_PixelShaderDict[pixelShader].m_ShaderStaticCombos; + int i; + for ( i = 0; i < combos.m_nCount; i++ ) + { + if ( combos.m_pHardwareShaders[i] != INVALID_HARDWARE_SHADER ) + { + IDirect3DPixelShader* pShader = ( IDirect3DPixelShader * )combos.m_pHardwareShaders[i]; + UnregisterPS( pShader ); +#ifdef DBGFLAG_ASSERT + int nRetVal = +#endif + pShader->Release(); + Assert( nRetVal == 0 ); + } + } + delete [] combos.m_pHardwareShaders; + combos.m_pHardwareShaders = NULL; + + if ( combos.m_pCreationData != NULL ) + { + delete [] combos.m_pCreationData; + combos.m_pCreationData = NULL; + } + + m_PixelShaderDict.Remove( pixelShader ); +} + + +//----------------------------------------------------------------------------- +// Destroys all shaders +//----------------------------------------------------------------------------- +void CShaderManager::DestroyAllShaders( void ) +{ + // Remarking this out because it's conflicting with dxabstract's shutdown resource leak detection code (we leak thousands of shaders at shutdown with this in place). + // I see no reason why we would want to do this in D3D9 but not GL? +//#ifdef DX_TO_GL_ABSTRACTION +// return; +//#endif + + for ( VertexShader_t vshIndex = m_VertexShaderDict.Head(); + vshIndex != m_VertexShaderDict.InvalidIndex(); ) + { + Assert( m_VertexShaderDict[vshIndex].m_nRefCount >= 0 ); + VertexShader_t next = m_VertexShaderDict.Next( vshIndex ); + DestroyVertexShader( vshIndex ); + vshIndex = next; + } + + for ( PixelShader_t pshIndex = m_PixelShaderDict.Head(); + pshIndex != m_PixelShaderDict.InvalidIndex(); ) + { + Assert( m_PixelShaderDict[pshIndex].m_nRefCount >= 0 ); + PixelShader_t next = m_PixelShaderDict.Next( pshIndex ); + DestroyPixelShader( pshIndex ); + pshIndex = next; + } + + // invalidate the file cache + m_ShaderFileCache.Purge(); +} + +//----------------------------------------------------------------------------- +// print all vertex and pixel shaders along with refcounts to the console +//----------------------------------------------------------------------------- +void CShaderManager::SpewVertexAndPixelShaders( void ) +{ + // only spew a populated shader file cache + Msg( "\nShader File Cache:\n" ); + for ( int cacheIndex = m_ShaderFileCache.Head(); + cacheIndex != m_ShaderFileCache.InvalidIndex(); + cacheIndex = m_ShaderFileCache.Next( cacheIndex ) ) + { + ShaderFileCache_t *pCache = &m_ShaderFileCache[cacheIndex]; + Msg( "Total Combos:%9d Static:%9d Dynamic:%7d SeekTable:%7d Ver:%d '%s'\n", + pCache->m_Header.m_nTotalCombos, + pCache->m_Header.m_nTotalCombos/pCache->m_Header.m_nDynamicCombos, + pCache->m_Header.m_nDynamicCombos, + pCache->IsOldVersion() ? 0 : pCache->m_Header.m_nNumStaticCombos, + pCache->m_Header.m_nVersion, + m_ShaderSymbolTable.String( pCache->m_Filename ) ); + } + Msg( "\n" ); + + // spew vertex shader dictionary + int totalVertexShaders = 0; + int totalVertexShaderSets = 0; + for ( VertexShader_t vshIndex = m_VertexShaderDict.Head(); + vshIndex != m_VertexShaderDict.InvalidIndex(); + vshIndex = m_VertexShaderDict.Next( vshIndex ) ) + { + const ShaderLookup_t &lookup = m_VertexShaderDict[vshIndex]; + const char *pName = m_ShaderSymbolTable.String( lookup.m_Name ); + Msg( "vsh 0x%8.8x: static combo:%9d dynamic combos:%6d refcount:%4d \"%s\"\n", vshIndex, + ( int )lookup.m_nStaticIndex, ( int )lookup.m_ShaderStaticCombos.m_nCount, + lookup.m_nRefCount, pName ); + totalVertexShaders += lookup.m_ShaderStaticCombos.m_nCount; + totalVertexShaderSets++; + } + + // spew pixel shader dictionary + int totalPixelShaders = 0; + int totalPixelShaderSets = 0; + for ( PixelShader_t pshIndex = m_PixelShaderDict.Head(); + pshIndex != m_PixelShaderDict.InvalidIndex(); + pshIndex = m_PixelShaderDict.Next( pshIndex ) ) + { + const ShaderLookup_t &lookup = m_PixelShaderDict[pshIndex]; + const char *pName = m_ShaderSymbolTable.String( lookup.m_Name ); + Msg( "psh 0x%8.8x: static combo:%9d dynamic combos:%6d refcount:%4d \"%s\"\n", pshIndex, + ( int )lookup.m_nStaticIndex, ( int )lookup.m_ShaderStaticCombos.m_nCount, + lookup.m_nRefCount, pName ); + totalPixelShaders += lookup.m_ShaderStaticCombos.m_nCount; + totalPixelShaderSets++; + } + + Msg( "Total unique vertex shaders: %d\n", totalVertexShaders ); + Msg( "Total vertex shader sets: %d\n", totalVertexShaderSets ); + Msg( "Total unique pixel shaders: %d\n", totalPixelShaders ); + Msg( "Total pixel shader sets: %d\n", totalPixelShaderSets ); +} + +CON_COMMAND( mat_spewvertexandpixelshaders, "Print all vertex and pixel shaders currently loaded to the console" ) +{ + ( ( CShaderManager * )ShaderManager() )->SpewVertexAndPixelShaders(); +} + +const char *CShaderManager::GetActiveVertexShaderName() +{ +#if !defined( _DEBUG ) + return ""; +#else + if ( !m_HardwareVertexShader ) + { + return "NULL"; + } + return vshDebugName[vshDebugIndex]; +#endif +} + +const char *CShaderManager::GetActivePixelShaderName() +{ +#if !defined( _DEBUG ) + return ""; +#else + if ( !m_HardwarePixelShader ) + { + return "NULL"; + } + return pshDebugName[pshDebugIndex]; +#endif +} + +#ifdef DYNAMIC_SHADER_COMPILE +void CShaderManager::FlushShaders( void ) +{ + for( VertexShader_t shader = m_VertexShaderDict.Head(); + shader != m_VertexShaderDict.InvalidIndex(); + shader = m_VertexShaderDict.Next( shader ) ) + { + int i; + ShaderStaticCombos_t &combos = m_VertexShaderDict[shader].m_ShaderStaticCombos; + for( i = 0; i < combos.m_nCount; i++ ) + { + if( combos.m_pHardwareShaders[i] != INVALID_HARDWARE_SHADER ) + { +#ifdef _DEBUG + int nRetVal= +#endif + ( ( IDirect3DVertexShader9 * )combos.m_pHardwareShaders[i] )->Release(); + Assert( nRetVal == 0 ); + } + combos.m_pHardwareShaders[i] = INVALID_HARDWARE_SHADER; + } + } + + for( PixelShader_t shader = m_PixelShaderDict.Head(); + shader != m_PixelShaderDict.InvalidIndex(); + shader = m_PixelShaderDict.Next( shader ) ) + { + int i; + ShaderStaticCombos_t &combos = m_PixelShaderDict[shader].m_ShaderStaticCombos; + for( i = 0; i < combos.m_nCount; i++ ) + { + if( combos.m_pHardwareShaders[i] != INVALID_HARDWARE_SHADER ) + { +#ifdef _DEBUG + int nRetVal = +#endif + ( ( IDirect3DPixelShader * )combos.m_pHardwareShaders[i] )->Release(); + Assert( nRetVal == 0 ); + } + combos.m_pHardwareShaders[i] = INVALID_HARDWARE_SHADER; + } + } + + // invalidate the file cache + m_ShaderFileCache.Purge(); +} +#endif + +#ifdef DYNAMIC_SHADER_COMPILE +static void MatFlushShaders( void ) +{ +#if defined( _X360 ) + XBX_rSyncShaderCache(); +#endif + ( ( CShaderManager * )ShaderManager() )->FlushShaders(); +} +#endif + +#ifdef DYNAMIC_SHADER_COMPILE +CON_COMMAND( mat_flushshaders, "flush all hardware shaders when using DYNAMIC_SHADER_COMPILE" ) +{ + MatFlushShaders(); +} +#endif + +CON_COMMAND( mat_shadercount, "display count of all shaders and reset that count" ) +{ + Warning( "Num Pixel Shaders = %d Vertex Shaders=%d\n", s_NumPixelShadersCreated, s_NumVertexShadersCreated ); + s_NumVertexShadersCreated = 0; + s_NumPixelShadersCreated = 0; +} + +#if defined( DX_TO_GL_ABSTRACTION ) +void CShaderManager::DoStartupShaderPreloading() +{ + if (mat_autoload_glshaders.GetInt()) + { + double flStartTime = Plat_FloatTime(); + + s_NumVertexShadersCreated = s_NumPixelShadersCreated = 0; + + // try base file +#ifdef OSX + if ( !LoadShaderCache("glbaseshaders_osx.cfg") ) // factory cache +#else + if ( !LoadShaderCache("glbaseshaders.cfg") ) // factory cache +#endif + { + Warning( "Could not find base GL shader cache file\n" ); + } + + if ( !LoadShaderCache("glshaders.cfg") ) // user mutable cache + { + Warning( "Could not find user GL shader cache file\n" ); + } + + double flEndTime = Plat_FloatTime(); + Msg( "Precache: Took %d ms, Vertex %d, Pixel %d\n", ( int )( ( flEndTime - flStartTime ) * 1000.0 ), s_NumVertexShadersCreated, s_NumPixelShadersCreated ); + } +} +#endif + diff --git a/materialsystem/shaderapidx9/vertexshaderdx8.h b/materialsystem/shaderapidx9/vertexshaderdx8.h new file mode 100644 index 0000000..5483eec --- /dev/null +++ b/materialsystem/shaderapidx9/vertexshaderdx8.h @@ -0,0 +1,135 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +// +//===========================================================================// + +#ifndef VERTEXSHADERDX8_H +#define VERTEXSHADERDX8_H + +#ifdef _WIN32 +#pragma once +#endif + +#include "shaderapi/ishaderapi.h" +#include "locald3dtypes.h" + + +// uncomment to get dynamic compilation for HLSL shaders +// X360 NOTE: By default, the system looks for a shared folder named "stdshaders" on the host machine and is completely compatible with -dvd. Ensure that the share is writable if you plan on generating UPDB's. +//#define DYNAMIC_SHADER_COMPILE + +// Uncomment to use remoteshadercompiler.exe as a shader compile server +// Must also set mat_remoteshadercompile to remote shader compile machine name +//#define REMOTE_DYNAMIC_SHADER_COMPILE + +// uncomment to get spew about what combos are being compiled. +//#define DYNAMIC_SHADER_COMPILE_VERBOSE + +// Uncomment to use remoteshadercompiler.exe as a shader compile server +// Must also set mat_remoteshadercompile to remote shader compile machine name +//#define REMOTE_DYNAMIC_SHADER_COMPILE + +// uncomment and fill in with a path to use a specific set of shader source files. Meant for network use. +// PC path format is of style "\\\\somemachine\\sourcetreeshare\\materialsystem\\stdshaders" +// Xbox path format is of style "net:\\smb\\somemachine\\sourcetreeshare\\materialsystem\\stdshaders" +// - Xbox dynamic compiles without a custom path default to look directly for "stdshaders" share on host pc + +//#define DYNAMIC_SHADER_COMPILE_CUSTOM_PATH "" + +// uncomment to get disassembled (asm) shader code in your game dir as *.asm +//#define DYNAMIC_SHADER_COMPILE_WRITE_ASSEMBLY + +// uncomment to get disassembled (asm) shader code in your game dir as *.asm +//#define WRITE_ASSEMBLY + + +enum VertexShaderLightTypes_t +{ + LIGHT_NONE = -1, + LIGHT_SPOT = 0, + LIGHT_POINT = 1, + LIGHT_DIRECTIONAL = 2, + LIGHT_STATIC = 3, + LIGHT_AMBIENTCUBE = 4, +}; + +//----------------------------------------------------------------------------- +// Vertex + pixel shader manager +//----------------------------------------------------------------------------- +abstract_class IShaderManager +{ +protected: + + // The current vertex and pixel shader index + int m_nVertexShaderIndex; + int m_nPixelShaderIndex; + +public: + // Initialize, shutdown + virtual void Init() = 0; + virtual void Shutdown() = 0; + + // Compiles vertex shaders + virtual IShaderBuffer *CompileShader( const char *pProgram, size_t nBufLen, const char *pShaderVersion ) = 0; + + // New version of these methods [dx10 port] + virtual VertexShaderHandle_t CreateVertexShader( IShaderBuffer* pShaderBuffer ) = 0; + virtual void DestroyVertexShader( VertexShaderHandle_t hShader ) = 0; + virtual PixelShaderHandle_t CreatePixelShader( IShaderBuffer* pShaderBuffer ) = 0; + virtual void DestroyPixelShader( PixelShaderHandle_t hShader ) = 0; + + // Creates vertex, pixel shaders + virtual VertexShader_t CreateVertexShader( const char *pVertexShaderFile, int nStaticVshIndex = 0, char *debugLabel = NULL ) = 0; + virtual PixelShader_t CreatePixelShader( const char *pPixelShaderFile, int nStaticPshIndex = 0, char *debugLabel = NULL ) = 0; + + // Sets which dynamic version of the vertex + pixel shader to use + FORCEINLINE void SetVertexShaderIndex( int vshIndex ); + FORCEINLINE void SetPixelShaderIndex( int pshIndex ); + + // Sets the vertex + pixel shader render state + virtual void SetVertexShader( VertexShader_t shader ) = 0; + virtual void SetPixelShader( PixelShader_t shader ) = 0; + + // Resets the vertex + pixel shader state + virtual void ResetShaderState() = 0; + + // Returns the current vertex + pixel shaders + virtual void *GetCurrentVertexShader() = 0; + virtual void *GetCurrentPixelShader() = 0; + + virtual void ClearVertexAndPixelShaderRefCounts() = 0; + virtual void PurgeUnusedVertexAndPixelShaders() = 0; + + // The low-level dx call to set the vertex shader state + virtual void BindVertexShader( VertexShaderHandle_t shader ) = 0; + virtual void BindPixelShader( PixelShaderHandle_t shader ) = 0; + +#if defined( _X360 ) + virtual const char *GetActiveVertexShaderName() = 0; + virtual const char *GetActivePixelShaderName() = 0; +#endif + +#if defined( DX_TO_GL_ABSTRACTION ) + virtual void DoStartupShaderPreloading() = 0; +#endif +}; + +//----------------------------------------------------------------------------- +// +// Methods related to setting vertex + pixel shader state +// +//----------------------------------------------------------------------------- +FORCEINLINE void IShaderManager::SetVertexShaderIndex( int vshIndex ) +{ + m_nVertexShaderIndex = vshIndex; +} + +FORCEINLINE void IShaderManager::SetPixelShaderIndex( int pshIndex ) +{ + m_nPixelShaderIndex = pshIndex; +} + +#endif // VERTEXSHADERDX8_H diff --git a/materialsystem/shaderapidx9/winutils.cpp b/materialsystem/shaderapidx9/winutils.cpp new file mode 100644 index 0000000..5da2493 --- /dev/null +++ b/materialsystem/shaderapidx9/winutils.cpp @@ -0,0 +1,93 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// winutils.cpp +// +//===========================================================================// + +#include "winutils.h" + +#ifndef _WIN32 + +#include "appframework/ilaunchermgr.h" + +// LINUX path taken from //Steam/main/src/tier0/platform_posix.cpp - Returns installed RAM in MB. +static unsigned long GetInstalledRAM() +{ + unsigned long ulTotalRamMB = 2047; + +#ifdef LINUX + char rgchLine[256]; + FILE *fpMemInfo = fopen( "/proc/meminfo", "r" ); + if ( !fpMemInfo ) + return ulTotalRamMB; + + const char *pszSearchString = "MemTotal:"; + const uint cchSearchString = strlen( pszSearchString ); + while ( fgets( rgchLine, sizeof(rgchLine), fpMemInfo ) ) + { + if ( !strncasecmp( pszSearchString, rgchLine, cchSearchString ) ) + { + char *pszVal = rgchLine+cchSearchString; + while( isspace(*pszVal) ) + ++pszVal; + ulTotalRamMB = atol( pszVal ) / 1024; // go from kB to MB + break; + } + } + fclose( fpMemInfo ); +#endif + + // 128 Gb limit for now (should future proof us for a while) + ulTotalRamMB = MIN( ulTotalRamMB, 1024 * 128 ); + return ulTotalRamMB; +} + +void GlobalMemoryStatus( MEMORYSTATUS *pOut ) +{ + unsigned long nInstalledRamInMB = GetInstalledRAM(); + + // For safety assume at least 128MB + nInstalledRamInMB = MAX( nInstalledRamInMB, 128 ); + + uint64 ulTotalRam = static_cast( nInstalledRamInMB ) * ( 1024 * 1024 ); + ulTotalRam = MIN( ulTotalRam, 0xFFFFFFFF ); + + pOut->dwTotalPhys = static_cast( ulTotalRam ); +} + +void Sleep( unsigned int ms ) +{ + DebuggerBreak(); + ThreadSleep( ms ); +} + +bool IsIconic( VD3DHWND hWnd ) +{ + // FIXME for now just act non-minimized all the time + //DebuggerBreak(); + return false; +} + +BOOL ClientToScreen( VD3DHWND hWnd, LPPOINT pPoint ) +{ + DebuggerBreak(); + return true; +} + +void* GetCurrentThread() +{ + DebuggerBreak(); + return 0; +} + +void SetThreadAffinityMask( void *hThread, int nMask ) +{ + DebuggerBreak(); +} + +bool GUID::operator==( const struct _GUID &other ) const +{ + DebuggerBreak(); + return memcmp( this, &other, sizeof( GUID ) ) == 0; +} +#endif diff --git a/materialsystem/shaderapidx9/winutils.h b/materialsystem/shaderapidx9/winutils.h new file mode 100644 index 0000000..0874fba --- /dev/null +++ b/materialsystem/shaderapidx9/winutils.h @@ -0,0 +1,21 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// +// +//================================================================================================== +#ifndef WINUTILS_H +#define WINUTILS_H + +#include "togl/rendermechanism.h" // for win types + +#if !defined(_WIN32) + + void Sleep( unsigned int ms ); + bool IsIconic( VD3DHWND hWnd ); + BOOL ClientToScreen( VD3DHWND hWnd, LPPOINT pPoint ); + void* GetCurrentThread(); + void SetThreadAffinityMask( void *hThread, int nMask ); + void GlobalMemoryStatus( MEMORYSTATUS *pOut ); +#endif + +#endif // WINUTILS_H diff --git a/materialsystem/shaderapidx9/wmi.cpp b/materialsystem/shaderapidx9/wmi.cpp new file mode 100644 index 0000000..1b0644f --- /dev/null +++ b/materialsystem/shaderapidx9/wmi.cpp @@ -0,0 +1,182 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//============================================================================= + +#include "resource.h" + +// Avoid conflicts with MSVC headers and memdbgon.h +#undef PROTECTED_THINGS_ENABLE +#include "basetypes.h" + +#define _WIN32_DCOM +#include +#pragma warning( disable : 4127 ) // VS 2010 warning? +#pragma warning( disable : 4805 ) // VS 2013 warning: warning C4805: '==' : unsafe mix of type 'INT' and type 'bool' in operation +#include +#pragma warning( default : 4805 ) +#pragma warning( default : 4127 ) +#include + +// NOTE: This has to be the last file included! +#include "tier0/memdbgon.h" + + +# pragma comment(lib, "wbemuuid.lib") + +uint64 GetVidMemBytes( void ) +{ + static int bBeenHere = false; + static uint64 nBytes = 0; + + if( bBeenHere ) + { + return nBytes; + } + + bBeenHere = true; + + // Initialize COM + HRESULT hr = CoInitialize( NULL ); + if ( FAILED( hr ) ) + { + OutputDebugString ( "GetWMIDeviceStats - Unable to initialize COM library.\n"); + return 0; + } + + // Obtain the initial locator to WMI + IWbemLocator *pLoc = NULL; + + hr = CoCreateInstance( + CLSID_WbemLocator, + 0, + CLSCTX_INPROC_SERVER, + IID_IWbemLocator, (LPVOID *) &pLoc); + + if ( FAILED( hr ) ) + { + OutputDebugString ( "GetWMIDeviceStats - Failed to create IWbemLocator object.\n"); + CoUninitialize(); + return 0; + } + + // Connect to WMI through the IWbemLocator::ConnectServer method + + IWbemServices *pSvc = NULL; + + // Connect to the root\cimv2 namespace with + // the current user and obtain pointer pSvc + // to make IWbemServices calls. + hr = pLoc->ConnectServer( + _bstr_t(L"ROOT\\CIMV2"), // Object path of WMI namespace + NULL, // User name. NULL = current user + NULL, // User password. NULL = current + 0, // Locale. NULL indicates current + NULL, // Security flags. + 0, // Authority (e.g. Kerberos) + 0, // Context object + &pSvc // pointer to IWbemServices proxy + ); + + if ( FAILED( hr ) ) + { + OutputDebugString ( "GetWMIDeviceStats - Could not connect.\n"); + pLoc->Release(); + CoUninitialize(); + return 0; + } + +// OutputDebugString ( L"GetWMIDeviceStats - Connected to ROOT\\CIMV2 WMI namespace\n"); + + + // Set security levels on the proxy + + hr = CoSetProxyBlanket( + pSvc, // Indicates the proxy to set + RPC_C_AUTHN_WINNT, // RPC_C_AUTHN_xxx + RPC_C_AUTHZ_NONE, // RPC_C_AUTHZ_xxx + NULL, // Server principal name + RPC_C_AUTHN_LEVEL_CALL, // RPC_C_AUTHN_LEVEL_xxx + RPC_C_IMP_LEVEL_IMPERSONATE, // RPC_C_IMP_LEVEL_xxx + NULL, // client identity + EOAC_NONE // proxy capabilities + ); + + if ( FAILED( hr ) ) + { + OutputDebugString ( "GetWMIDeviceStats - Could not set proxy blanket.\n"); + pSvc->Release(); + pLoc->Release(); + CoUninitialize(); + return 0; + } + + + // Use the IWbemServices pointer to make requests of WMI + + // + // --- Win32_VideoController -------------------------------------------------- + // + + IEnumWbemClassObject* pEnumerator = NULL; + hr = pSvc->ExecQuery( bstr_t("WQL"), bstr_t("SELECT * FROM Win32_VideoController"), + WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, NULL, &pEnumerator); + + if ( FAILED( hr ) ) + { + OutputDebugString ( "GetWMIDeviceStats - Query for Win32_VideoController failed.\n"); + + pSvc->Release(); + pLoc->Release(); + CoUninitialize(); + return 0; + } + + + // Get the data from the above query + IWbemClassObject *pclsObj = NULL; + ULONG uReturn = 0; + + while ( pEnumerator ) + { + HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn); + + if(0 == uReturn) + { + break; + } + + VARIANT vtProp; + VariantInit(&vtProp); + + // Pluck a series of properties out of the query from Win32_VideoController + +// hr = pclsObj->Get(L"Description", 0, &vtProp, 0, 0); // Basically the same as "VideoProcessor" +// if ( SUCCEEDED( hr ) ) +// { +// wsprintf( pAdapter->m_szPrimaryAdapterDescription, vtProp.bstrVal ); +// } + + hr = pclsObj->Get(L"AdapterRAM", 0, &vtProp, 0, 0); + if ( SUCCEEDED( hr ) ) + { + nBytes = vtProp.ulVal; // Video RAM in bytes, AdatperRam is returned as the I4 type so we read it out as unsigned int, + // see http://msdn.microsoft.com/en-us/library/windows/desktop/aa394512(v=vs.85).aspx + } + + VariantClear(&vtProp); + } + + // Cleanup + pSvc->Release(); + pLoc->Release(); + pEnumerator->Release(); + if ( pclsObj ) + { + pclsObj->Release(); + } + CoUninitialize(); + + return nBytes; +} diff --git a/materialsystem/shaderapidx9/wmi.h b/materialsystem/shaderapidx9/wmi.h new file mode 100644 index 0000000..8f8fe13 --- /dev/null +++ b/materialsystem/shaderapidx9/wmi.h @@ -0,0 +1,17 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//============================================================================= + +#ifndef WMI_H +#define WMI_H +#ifdef _WIN32 +#pragma once +#endif + + +uint64 GetVidMemBytes( void ); + + +#endif // WMI_H diff --git a/materialsystem/shaderapidx9/xbox/xbox.def b/materialsystem/shaderapidx9/xbox/xbox.def new file mode 100644 index 0000000..231fd7c --- /dev/null +++ b/materialsystem/shaderapidx9/xbox/xbox.def @@ -0,0 +1,3 @@ +LIBRARY shaderapidx9_360.dll +EXPORTS + CreateInterface @1 diff --git a/materialsystem/shaderapiempty/shaderapiempty.cpp b/materialsystem/shaderapiempty/shaderapiempty.cpp new file mode 100644 index 0000000..850088c --- /dev/null +++ b/materialsystem/shaderapiempty/shaderapiempty.cpp @@ -0,0 +1,2956 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +// +//===========================================================================// + +#include "utlvector.h" +#include "materialsystem/imaterialsystem.h" +#include "IHardwareConfigInternal.h" +#include "shadersystem.h" +#include "shaderapi/ishaderutil.h" +#include "shaderapi/ishaderapi.h" +#include "materialsystem/imesh.h" +#include "tier0/dbg.h" +#include "materialsystem/idebugtextureinfo.h" +#include "materialsystem/deformations.h" + + +//----------------------------------------------------------------------------- +// The empty mesh +//----------------------------------------------------------------------------- +class CEmptyMesh : public IMesh +{ +public: + CEmptyMesh( bool bIsDynamic ); + virtual ~CEmptyMesh(); + + // FIXME: Make this work! Unsupported methods of IIndexBuffer + IVertexBuffer + virtual bool Lock( int nMaxIndexCount, bool bAppend, IndexDesc_t& desc ); + virtual void Unlock( int nWrittenIndexCount, IndexDesc_t& desc ); + virtual void ModifyBegin( bool bReadOnly, int nFirstIndex, int nIndexCount, IndexDesc_t& desc ); + virtual void ModifyEnd( IndexDesc_t& desc ); + virtual void Spew( int nIndexCount, const IndexDesc_t & desc ); + virtual void ValidateData( int nIndexCount, const IndexDesc_t &desc ); + virtual bool Lock( int nVertexCount, bool bAppend, VertexDesc_t &desc ); + virtual void Unlock( int nVertexCount, VertexDesc_t &desc ); + virtual void Spew( int nVertexCount, const VertexDesc_t &desc ); + virtual void ValidateData( int nVertexCount, const VertexDesc_t & desc ); + virtual bool IsDynamic() const { return m_bIsDynamic; } + virtual void BeginCastBuffer( VertexFormat_t format ) {} + virtual void BeginCastBuffer( MaterialIndexFormat_t format ) {} + virtual void EndCastBuffer( ) {} + virtual int GetRoomRemaining() const { return 0; } + virtual MaterialIndexFormat_t IndexFormat() const { return MATERIAL_INDEX_FORMAT_UNKNOWN; } + + void LockMesh( int numVerts, int numIndices, MeshDesc_t& desc ); + void UnlockMesh( int numVerts, int numIndices, MeshDesc_t& desc ); + + void ModifyBeginEx( bool bReadOnly, int firstVertex, int numVerts, int firstIndex, int numIndices, MeshDesc_t& desc ); + void ModifyBegin( int firstVertex, int numVerts, int firstIndex, int numIndices, MeshDesc_t& desc ); + void ModifyEnd( MeshDesc_t& desc ); + + // returns the # of vertices (static meshes only) + int VertexCount() const; + + // Sets the primitive type + void SetPrimitiveType( MaterialPrimitiveType_t type ); + + // Draws the entire mesh + void Draw(int firstIndex, int numIndices); + + void Draw(CPrimList *pPrims, int nPrims); + + // Copy verts and/or indices to a mesh builder. This only works for temp meshes! + virtual void CopyToMeshBuilder( + int iStartVert, // Which vertices to copy. + int nVerts, + int iStartIndex, // Which indices to copy. + int nIndices, + int indexOffset, // This is added to each index. + CMeshBuilder &builder ); + + // Spews the mesh data + void Spew( int numVerts, int numIndices, const MeshDesc_t & desc ); + + void ValidateData( int numVerts, int numIndices, const MeshDesc_t & desc ); + + // gets the associated material + IMaterial* GetMaterial(); + + void SetColorMesh( IMesh *pColorMesh, int nVertexOffset ) + { + } + + + virtual int IndexCount() const + { + return 0; + } + + virtual void SetFlexMesh( IMesh *pMesh, int nVertexOffset ) {} + + virtual void DisableFlexMesh() {} + + virtual void MarkAsDrawn() {} + + virtual unsigned ComputeMemoryUsed() { return 0; } + + virtual VertexFormat_t GetVertexFormat() const { return VERTEX_POSITION; } + + virtual IMesh *GetMesh() + { + return this; + } + +private: + enum + { + VERTEX_BUFFER_SIZE = 1024 * 1024 + }; + + unsigned char* m_pVertexMemory; + bool m_bIsDynamic; +}; + + +//----------------------------------------------------------------------------- +// The empty shader shadow +//----------------------------------------------------------------------------- +class CShaderShadowEmpty : public IShaderShadow +{ +public: + CShaderShadowEmpty(); + virtual ~CShaderShadowEmpty(); + + // Sets the default *shadow* state + void SetDefaultState(); + + // Methods related to depth buffering + void DepthFunc( ShaderDepthFunc_t depthFunc ); + void EnableDepthWrites( bool bEnable ); + void EnableDepthTest( bool bEnable ); + void EnablePolyOffset( PolygonOffsetMode_t nOffsetMode ); + + // Suppresses/activates color writing + void EnableColorWrites( bool bEnable ); + void EnableAlphaWrites( bool bEnable ); + + // Methods related to alpha blending + void EnableBlending( bool bEnable ); + void BlendFunc( ShaderBlendFactor_t srcFactor, ShaderBlendFactor_t dstFactor ); + + // Alpha testing + void EnableAlphaTest( bool bEnable ); + void AlphaFunc( ShaderAlphaFunc_t alphaFunc, float alphaRef /* [0-1] */ ); + + // Wireframe/filled polygons + void PolyMode( ShaderPolyModeFace_t face, ShaderPolyMode_t polyMode ); + + // Back face culling + void EnableCulling( bool bEnable ); + + // constant color + transparency + void EnableConstantColor( bool bEnable ); + + // Indicates the vertex format for use with a vertex shader + // The flags to pass in here come from the VertexFormatFlags_t enum + // If pTexCoordDimensions is *not* specified, we assume all coordinates + // are 2-dimensional + void VertexShaderVertexFormat( unsigned int nFlags, + int nTexCoordCount, int* pTexCoordDimensions, int nUserDataSize ); + + // Indicates we're going to light the model + void EnableLighting( bool bEnable ); + void EnableSpecular( bool bEnable ); + + // vertex blending + void EnableVertexBlend( bool bEnable ); + + // per texture unit stuff + void OverbrightValue( TextureStage_t stage, float value ); + void EnableTexture( Sampler_t stage, bool bEnable ); + void EnableTexGen( TextureStage_t stage, bool bEnable ); + void TexGen( TextureStage_t stage, ShaderTexGenParam_t param ); + + // alternate method of specifying per-texture unit stuff, more flexible and more complicated + // Can be used to specify different operation per channel (alpha/color)... + void EnableCustomPixelPipe( bool bEnable ); + void CustomTextureStages( int stageCount ); + void CustomTextureOperation( TextureStage_t stage, ShaderTexChannel_t channel, + ShaderTexOp_t op, ShaderTexArg_t arg1, ShaderTexArg_t arg2 ); + + // indicates what per-vertex data we're providing + void DrawFlags( unsigned int drawFlags ); + + // A simpler method of dealing with alpha modulation + void EnableAlphaPipe( bool bEnable ); + void EnableConstantAlpha( bool bEnable ); + void EnableVertexAlpha( bool bEnable ); + void EnableTextureAlpha( TextureStage_t stage, bool bEnable ); + + // GR - Separate alpha blending + void EnableBlendingSeparateAlpha( bool bEnable ); + void BlendFuncSeparateAlpha( ShaderBlendFactor_t srcFactor, ShaderBlendFactor_t dstFactor ); + + // Sets the vertex and pixel shaders + void SetVertexShader( const char *pFileName, int vshIndex ); + void SetPixelShader( const char *pFileName, int pshIndex ); + + // Convert from linear to gamma color space on writes to frame buffer. + void EnableSRGBWrite( bool bEnable ) + { + } + + void EnableSRGBRead( Sampler_t stage, bool bEnable ) + { + } + + virtual void FogMode( ShaderFogMode_t fogMode ) + { + } + + virtual void DisableFogGammaCorrection( bool bDisable ) + { + } + + virtual void SetDiffuseMaterialSource( ShaderMaterialSource_t materialSource ) + { + } + + virtual void SetMorphFormat( MorphFormat_t flags ) + { + } + + virtual void EnableStencil( bool bEnable ) + { + } + virtual void StencilFunc( ShaderStencilFunc_t stencilFunc ) + { + } + virtual void StencilPassOp( ShaderStencilOp_t stencilOp ) + { + } + virtual void StencilFailOp( ShaderStencilOp_t stencilOp ) + { + } + virtual void StencilDepthFailOp( ShaderStencilOp_t stencilOp ) + { + } + virtual void StencilReference( int nReference ) + { + } + virtual void StencilMask( int nMask ) + { + } + virtual void StencilWriteMask( int nMask ) + { + } + + virtual void ExecuteCommandBuffer( uint8 *pBuf ) + { + } + // Alpha to coverage + void EnableAlphaToCoverage( bool bEnable ); + + virtual void SetShadowDepthFiltering( Sampler_t stage ) + { + } + + virtual void BlendOp( ShaderBlendOp_t blendOp ) {} + virtual void BlendOpSeparateAlpha( ShaderBlendOp_t blendOp ) {} + + bool m_IsTranslucent; + bool m_IsAlphaTested; + bool m_bIsDepthWriteEnabled; + bool m_bUsesVertexAndPixelShaders; +}; + + +//----------------------------------------------------------------------------- +// The DX8 implementation of the shader device +//----------------------------------------------------------------------------- +class CShaderDeviceEmpty : public IShaderDevice +{ +public: + CShaderDeviceEmpty() : m_DynamicMesh( true ), m_Mesh( false ) {} + + // Methods of IShaderDevice + virtual int GetCurrentAdapter() const { return 0; } + virtual bool IsUsingGraphics() const { return false; } + virtual void SpewDriverInfo() const; + virtual ImageFormat GetBackBufferFormat() const { return IMAGE_FORMAT_RGB888; } + virtual void GetBackBufferDimensions( int& width, int& height ) const; + virtual int StencilBufferBits() const { return 0; } + virtual bool IsAAEnabled() const { return false; } + virtual void Present( ) {} + virtual void GetWindowSize( int &width, int &height ) const; + virtual bool AddView( void* hwnd ); + virtual void RemoveView( void* hwnd ); + virtual void SetView( void* hwnd ); + virtual void ReleaseResources(); + virtual void ReacquireResources(); + virtual IMesh* CreateStaticMesh( VertexFormat_t fmt, const char *pTextureBudgetGroup, IMaterial * pMaterial = NULL ); + virtual void DestroyStaticMesh( IMesh* mesh ); + virtual IShaderBuffer* CompileShader( const char *pProgram, size_t nBufLen, const char *pShaderVersion ) { return NULL; } + virtual VertexShaderHandle_t CreateVertexShader( IShaderBuffer* pShaderBuffer ) { return VERTEX_SHADER_HANDLE_INVALID; } + virtual void DestroyVertexShader( VertexShaderHandle_t hShader ) {} + virtual GeometryShaderHandle_t CreateGeometryShader( IShaderBuffer* pShaderBuffer ) { return GEOMETRY_SHADER_HANDLE_INVALID; } + virtual void DestroyGeometryShader( GeometryShaderHandle_t hShader ) {} + virtual PixelShaderHandle_t CreatePixelShader( IShaderBuffer* pShaderBuffer ) { return PIXEL_SHADER_HANDLE_INVALID; } + virtual void DestroyPixelShader( PixelShaderHandle_t hShader ) {} + virtual IVertexBuffer *CreateVertexBuffer( ShaderBufferType_t type, VertexFormat_t fmt, int nVertexCount, const char *pBudgetGroup ); + virtual void DestroyVertexBuffer( IVertexBuffer *pVertexBuffer ); + virtual IIndexBuffer *CreateIndexBuffer( ShaderBufferType_t bufferType, MaterialIndexFormat_t fmt, int nIndexCount, const char *pBudgetGroup ); + virtual void DestroyIndexBuffer( IIndexBuffer *pIndexBuffer ); + virtual IVertexBuffer *GetDynamicVertexBuffer( int streamID, VertexFormat_t vertexFormat, bool bBuffered ); + virtual IIndexBuffer *GetDynamicIndexBuffer( MaterialIndexFormat_t fmt, bool bBuffered ); + virtual void SetHardwareGammaRamp( float fGamma, float fGammaTVRangeMin, float fGammaTVRangeMax, float fGammaTVExponent, bool bTVEnabled ) {} + virtual void EnableNonInteractiveMode( MaterialNonInteractiveMode_t mode, ShaderNonInteractiveInfo_t *pInfo ) {} + virtual void RefreshFrontBufferNonInteractive( ) {} + virtual void HandleThreadEvent( uint32 threadEvent ) {} + +#ifdef DX_TO_GL_ABSTRACTION + virtual void DoStartupShaderPreloading( void ) {} +#endif + + virtual char *GetDisplayDeviceName() OVERRIDE { return ""; } + +private: + CEmptyMesh m_Mesh; + CEmptyMesh m_DynamicMesh; +}; + +static CShaderDeviceEmpty s_ShaderDeviceEmpty; + +// FIXME: Remove; it's for backward compat with the materialsystem only for now +EXPOSE_SINGLE_INTERFACE_GLOBALVAR( CShaderDeviceEmpty, IShaderDevice, + SHADER_DEVICE_INTERFACE_VERSION, s_ShaderDeviceEmpty ) + + +//----------------------------------------------------------------------------- +// The DX8 implementation of the shader device +//----------------------------------------------------------------------------- +class CShaderDeviceMgrEmpty : public IShaderDeviceMgr +{ +public: + // Methods of IAppSystem + virtual bool Connect( CreateInterfaceFn factory ); + virtual void Disconnect(); + virtual void *QueryInterface( const char *pInterfaceName ); + virtual InitReturnVal_t Init(); + virtual void Shutdown(); + +public: + // Methods of IShaderDeviceMgr + virtual int GetAdapterCount() const; + virtual void GetAdapterInfo( int adapter, MaterialAdapterInfo_t& info ) const; + virtual bool GetRecommendedConfigurationInfo( int nAdapter, int nDXLevel, KeyValues *pKeyValues ); + virtual int GetModeCount( int adapter ) const; + virtual void GetModeInfo( ShaderDisplayMode_t *pInfo, int nAdapter, int mode ) const; + virtual void GetCurrentModeInfo( ShaderDisplayMode_t* pInfo, int nAdapter ) const; + virtual bool SetAdapter( int nAdapter, int nFlags ); + virtual CreateInterfaceFn SetMode( void *hWnd, int nAdapter, const ShaderDeviceInfo_t& mode ); + virtual void AddModeChangeCallback( ShaderModeChangeCallbackFunc_t func ) {} + virtual void RemoveModeChangeCallback( ShaderModeChangeCallbackFunc_t func ) {} +}; + +static CShaderDeviceMgrEmpty s_ShaderDeviceMgrEmpty; + +EXPOSE_SINGLE_INTERFACE_GLOBALVAR( CShaderDeviceMgrEmpty, IShaderDeviceMgr, + SHADER_DEVICE_MGR_INTERFACE_VERSION, s_ShaderDeviceMgrEmpty ) + + +//----------------------------------------------------------------------------- +// The DX8 implementation of the shader API +//----------------------------------------------------------------------------- +class CShaderAPIEmpty : public IShaderAPI, public IHardwareConfigInternal, public IDebugTextureInfo +{ +public: + // constructor, destructor + CShaderAPIEmpty( ); + virtual ~CShaderAPIEmpty(); + + // IDebugTextureInfo implementation. +public: + + virtual bool IsDebugTextureListFresh( int numFramesAllowed = 1 ) { return false; } + virtual bool SetDebugTextureRendering( bool bEnable ) { return false; } + virtual void EnableDebugTextureList( bool bEnable ) {} + virtual void EnableGetAllTextures( bool bEnable ) {} + virtual KeyValues* GetDebugTextureList() { return NULL; } + virtual int GetTextureMemoryUsed( TextureMemoryType eTextureMemory ) { return 0; } + + // Methods of IShaderDynamicAPI + virtual void GetBackBufferDimensions( int& width, int& height ) const + { + s_ShaderDeviceEmpty.GetBackBufferDimensions( width, height ); + } + virtual void GetCurrentColorCorrection( ShaderColorCorrectionInfo_t* pInfo ) + { + pInfo->m_bIsEnabled = false; + pInfo->m_nLookupCount = 0; + pInfo->m_flDefaultWeight = 0.0f; + } + + + // Methods of IShaderAPI +public: + virtual void SetViewports( int nCount, const ShaderViewport_t* pViewports ); + virtual int GetViewports( ShaderViewport_t* pViewports, int nMax ) const; + virtual void ClearBuffers( bool bClearColor, bool bClearDepth, bool bClearStencil, int renderTargetWidth, int renderTargetHeight ); + virtual void ClearColor3ub( unsigned char r, unsigned char g, unsigned char b ); + virtual void ClearColor4ub( unsigned char r, unsigned char g, unsigned char b, unsigned char a ); + virtual void BindVertexShader( VertexShaderHandle_t hVertexShader ) {} + virtual void BindGeometryShader( GeometryShaderHandle_t hGeometryShader ) {} + virtual void BindPixelShader( PixelShaderHandle_t hPixelShader ) {} + virtual void SetRasterState( const ShaderRasterState_t& state ) {} + virtual void MarkUnusedVertexFields( unsigned int nFlags, int nTexCoordCount, bool *pUnusedTexCoords ) {} + virtual bool OwnGPUResources( bool bEnable ) { return false; } + + virtual bool DoRenderTargetsNeedSeparateDepthBuffer() const; + + // Used to clear the transition table when we know it's become invalid. + void ClearSnapshots(); + + // Sets the mode... + bool SetMode( void* hwnd, int nAdapter, const ShaderDeviceInfo_t &info ) + { + return true; + } + + void ChangeVideoMode( const ShaderDeviceInfo_t &info ) + { + } + + // Called when the dx support level has changed + virtual void DXSupportLevelChanged() {} + + virtual void EnableUserClipTransformOverride( bool bEnable ) {} + virtual void UserClipTransform( const VMatrix &worldToView ) {} + + // Sets the default *dynamic* state + void SetDefaultState( ); + + // Returns the snapshot id for the shader state + StateSnapshot_t TakeSnapshot( ); + + // Returns true if the state snapshot is transparent + bool IsTranslucent( StateSnapshot_t id ) const; + bool IsAlphaTested( StateSnapshot_t id ) const; + bool UsesVertexAndPixelShaders( StateSnapshot_t id ) const; + virtual bool IsDepthWriteEnabled( StateSnapshot_t id ) const; + + // Gets the vertex format for a set of snapshot ids + VertexFormat_t ComputeVertexFormat( int numSnapshots, StateSnapshot_t* pIds ) const; + + // Gets the vertex format for a set of snapshot ids + VertexFormat_t ComputeVertexUsage( int numSnapshots, StateSnapshot_t* pIds ) const; + + // Begins a rendering pass that uses a state snapshot + void BeginPass( StateSnapshot_t snapshot ); + + // Uses a state snapshot + void UseSnapshot( StateSnapshot_t snapshot ); + + // Use this to get the mesh builder that allows us to modify vertex data + CMeshBuilder* GetVertexModifyBuilder(); + + // Sets the color to modulate by + void Color3f( float r, float g, float b ); + void Color3fv( float const* pColor ); + void Color4f( float r, float g, float b, float a ); + void Color4fv( float const* pColor ); + + // Faster versions of color + void Color3ub( unsigned char r, unsigned char g, unsigned char b ); + void Color3ubv( unsigned char const* rgb ); + void Color4ub( unsigned char r, unsigned char g, unsigned char b, unsigned char a ); + void Color4ubv( unsigned char const* rgba ); + + // Sets the lights + void SetLight( int lightNum, const LightDesc_t& desc ); + void SetLightingOrigin( Vector vLightingOrigin ); + void SetAmbientLight( float r, float g, float b ); + void SetAmbientLightCube( Vector4D cube[6] ); + + // Get the lights + int GetMaxLights( void ) const; + const LightDesc_t& GetLight( int lightNum ) const; + + // Render state for the ambient light cube (vertex shaders) + void SetVertexShaderStateAmbientLightCube(); + void SetPixelShaderStateAmbientLightCube( int pshReg, bool bForceToBlack = false ) + { + } + + float GetAmbientLightCubeLuminance(void) + { + return 0.0f; + } + + void SetSkinningMatrices(); + + // Lightmap texture binding + void BindLightmap( TextureStage_t stage ); + void BindLightmapAlpha( TextureStage_t stage ) + { + } + void BindBumpLightmap( TextureStage_t stage ); + void BindFullbrightLightmap( TextureStage_t stage ); + void BindWhite( TextureStage_t stage ); + void BindBlack( TextureStage_t stage ); + void BindGrey( TextureStage_t stage ); + void BindFBTexture( TextureStage_t stage, int textureIdex ); + void CopyRenderTargetToTexture( ShaderAPITextureHandle_t texID ) + { + } + + void CopyRenderTargetToTextureEx( ShaderAPITextureHandle_t texID, int nRenderTargetID, Rect_t *pSrcRect, Rect_t *pDstRect ) + { + } + + void CopyTextureToRenderTargetEx( int nRenderTargetID, ShaderAPITextureHandle_t textureHandle, Rect_t *pSrcRect, Rect_t *pDstRect ) + { + } + + // Special system flat normal map binding. + void BindFlatNormalMap( TextureStage_t stage ); + void BindNormalizationCubeMap( TextureStage_t stage ); + void BindSignedNormalizationCubeMap( TextureStage_t stage ); + + // Set the number of bone weights + void SetNumBoneWeights( int numBones ); + void EnableHWMorphing( bool bEnable ); + + // Flushes any primitives that are buffered + void FlushBufferedPrimitives(); + + // Gets the dynamic mesh; note that you've got to render the mesh + // before calling this function a second time. Clients should *not* + // call DestroyStaticMesh on the mesh returned by this call. + IMesh* GetDynamicMesh( IMaterial* pMaterial, int nHWSkinBoneCount, bool buffered, IMesh* pVertexOverride, IMesh* pIndexOverride ); + IMesh* GetDynamicMeshEx( IMaterial* pMaterial, VertexFormat_t fmt, int nHWSkinBoneCount, bool buffered, IMesh* pVertexOverride, IMesh* pIndexOverride ); + + IMesh* GetFlexMesh(); + + // Renders a single pass of a material + void RenderPass( int nPass, int nPassCount ); + + // stuff related to matrix stacks + void MatrixMode( MaterialMatrixMode_t matrixMode ); + void PushMatrix(); + void PopMatrix(); + void LoadMatrix( float *m ); + void LoadBoneMatrix( int boneIndex, const float *m ) {} + void MultMatrix( float *m ); + void MultMatrixLocal( float *m ); + void GetMatrix( MaterialMatrixMode_t matrixMode, float *dst ); + void LoadIdentity( void ); + void LoadCameraToWorld( void ); + void Ortho( double left, double top, double right, double bottom, double zNear, double zFar ); + void PerspectiveX( double fovx, double aspect, double zNear, double zFar ); + void PerspectiveOffCenterX( double fovx, double aspect, double zNear, double zFar, double bottom, double top, double left, double right ); + void PickMatrix( int x, int y, int width, int height ); + void Rotate( float angle, float x, float y, float z ); + void Translate( float x, float y, float z ); + void Scale( float x, float y, float z ); + void ScaleXY( float x, float y ); + + // Fog methods... + void FogMode( MaterialFogMode_t fogMode ); + void FogStart( float fStart ); + void FogEnd( float fEnd ); + void SetFogZ( float fogZ ); + void FogMaxDensity( float flMaxDensity ); + void GetFogDistances( float *fStart, float *fEnd, float *fFogZ ); + void FogColor3f( float r, float g, float b ); + void FogColor3fv( float const* rgb ); + void FogColor3ub( unsigned char r, unsigned char g, unsigned char b ); + void FogColor3ubv( unsigned char const* rgb ); + + virtual void SceneFogColor3ub( unsigned char r, unsigned char g, unsigned char b ); + virtual void SceneFogMode( MaterialFogMode_t fogMode ); + virtual void GetSceneFogColor( unsigned char *rgb ); + virtual MaterialFogMode_t GetSceneFogMode( ); + virtual int GetPixelFogCombo( ); + + void SetHeightClipZ( float z ); + void SetHeightClipMode( enum MaterialHeightClipMode_t heightClipMode ); + + void SetClipPlane( int index, const float *pPlane ); + void EnableClipPlane( int index, bool bEnable ); + + void SetFastClipPlane( const float *pPlane ); + void EnableFastClip( bool bEnable ); + + // We use smaller dynamic VBs during level transitions, to free up memory + virtual int GetCurrentDynamicVBSize( void ); + virtual void DestroyVertexBuffers( bool bExitingLevel = false ); + + // Sets the vertex and pixel shaders + void SetVertexShaderIndex( int vshIndex ); + void SetPixelShaderIndex( int pshIndex ); + + // Sets the constant register for vertex and pixel shaders + void SetVertexShaderConstant( int var, float const* pVec, int numConst = 1, bool bForce = false ); + void SetBooleanVertexShaderConstant( int var, BOOL const* pVec, int numConst = 1, bool bForce = false ); + void SetIntegerVertexShaderConstant( int var, int const* pVec, int numConst = 1, bool bForce = false ); + void SetPixelShaderConstant( int var, float const* pVec, int numConst = 1, bool bForce = false ); + void SetBooleanPixelShaderConstant( int var, BOOL const* pVec, int numBools = 1, bool bForce = false ); + void SetIntegerPixelShaderConstant( int var, int const* pVec, int numIntVecs = 1, bool bForce = false ); + + void InvalidateDelayedShaderConstants( void ); + + // Gamma<->Linear conversions according to the video hardware we're running on + float GammaToLinear_HardwareSpecific( float fGamma ) const; + float LinearToGamma_HardwareSpecific( float fLinear ) const; + + //Set's the linear->gamma conversion textures to use for this hardware for both srgb writes enabled and disabled(identity) + void SetLinearToGammaConversionTextures( ShaderAPITextureHandle_t hSRGBWriteEnabledTexture, ShaderAPITextureHandle_t hIdentityTexture ); + + // Cull mode + void CullMode( MaterialCullMode_t cullMode ); + + // Force writes only when z matches. . . useful for stenciling things out + // by rendering the desired Z values ahead of time. + void ForceDepthFuncEquals( bool bEnable ); + + // Forces Z buffering on or off + void OverrideDepthEnable( bool bEnable, bool bDepthEnable ); + void OverrideAlphaWriteEnable( bool bOverrideEnable, bool bAlphaWriteEnable ); + void OverrideColorWriteEnable( bool bOverrideEnable, bool bColorWriteEnable ); + + // Sets the shade mode + void ShadeMode( ShaderShadeMode_t mode ); + + // Binds a particular material to render with + void Bind( IMaterial* pMaterial ); + + // Returns the nearest supported format + ImageFormat GetNearestSupportedFormat( ImageFormat fmt, bool bFilteringRequired = true ) const; + ImageFormat GetNearestRenderTargetFormat( ImageFormat fmt ) const; + + // Sets the texture state + void BindTexture( Sampler_t stage, ShaderAPITextureHandle_t textureHandle ); + + void SetRenderTarget( ShaderAPITextureHandle_t colorTextureHandle, ShaderAPITextureHandle_t depthTextureHandle ) + { + } + + void SetRenderTargetEx( int nRenderTargetID, ShaderAPITextureHandle_t colorTextureHandle, ShaderAPITextureHandle_t depthTextureHandle ) + { + } + + // Indicates we're going to be modifying this texture + // TexImage2D, TexSubImage2D, TexWrap, TexMinFilter, and TexMagFilter + // all use the texture specified by this function. + void ModifyTexture( ShaderAPITextureHandle_t textureHandle ); + + // Texture management methods + void TexImage2D( int level, int cubeFace, ImageFormat dstFormat, int zOffset, int width, int height, + ImageFormat srcFormat, bool bSrcIsTiled, void *imageData ); + void TexSubImage2D( int level, int cubeFace, int xOffset, int yOffset, int zOffset, int width, int height, + ImageFormat srcFormat, int srcStride, bool bSrcIsTiled, void *imageData ); + + void TexImageFromVTF( IVTFTexture *pVTF, int iVTFFrame ); + + bool TexLock( int level, int cubeFaceID, int xOffset, int yOffset, + int width, int height, CPixelWriter& writer ); + void TexUnlock( ); + + // These are bound to the texture, not the texture environment + void TexMinFilter( ShaderTexFilterMode_t texFilterMode ); + void TexMagFilter( ShaderTexFilterMode_t texFilterMode ); + void TexWrap( ShaderTexCoordComponent_t coord, ShaderTexWrapMode_t wrapMode ); + void TexSetPriority( int priority ); + + ShaderAPITextureHandle_t CreateTexture( + int width, + int height, + int depth, + ImageFormat dstImageFormat, + int numMipLevels, + int numCopies, + int flags, + const char *pDebugName, + const char *pTextureGroupName ); + // Create a multi-frame texture (equivalent to calling "CreateTexture" multiple times, but more efficient) + void CreateTextures( + ShaderAPITextureHandle_t *pHandles, + int count, + int width, + int height, + int depth, + ImageFormat dstImageFormat, + int numMipLevels, + int numCopies, + int flags, + const char *pDebugName, + const char *pTextureGroupName ); + ShaderAPITextureHandle_t CreateDepthTexture( ImageFormat renderFormat, int width, int height, const char *pDebugName, bool bTexture ); + void DeleteTexture( ShaderAPITextureHandle_t textureHandle ); + bool IsTexture( ShaderAPITextureHandle_t textureHandle ); + bool IsTextureResident( ShaderAPITextureHandle_t textureHandle ); + + // stuff that isn't to be used from within a shader + void ClearBuffersObeyStencil( bool bClearColor, bool bClearDepth ); + void ClearBuffersObeyStencilEx( bool bClearColor, bool bClearAlpha, bool bClearDepth ); + void PerformFullScreenStencilOperation( void ); + void ReadPixels( int x, int y, int width, int height, unsigned char *data, ImageFormat dstFormat ); + virtual void ReadPixels( Rect_t *pSrcRect, Rect_t *pDstRect, unsigned char *data, ImageFormat dstFormat, int nDstStride ); + + // Selection mode methods + int SelectionMode( bool selectionMode ); + void SelectionBuffer( unsigned int* pBuffer, int size ); + void ClearSelectionNames( ); + void LoadSelectionName( int name ); + void PushSelectionName( int name ); + void PopSelectionName(); + + void FlushHardware(); + void ResetRenderState( bool bFullReset = true ); + + void SetScissorRect( const int nLeft, const int nTop, const int nRight, const int nBottom, const bool bEnableScissor ); + + // Can we download textures? + virtual bool CanDownloadTextures() const; + + // Board-independent calls, here to unify how shaders set state + // Implementations should chain back to IShaderUtil->BindTexture(), etc. + + // Use this to begin and end the frame + void BeginFrame(); + void EndFrame(); + + // returns current time + double CurrentTime() const; + + // Get the current camera position in world space. + void GetWorldSpaceCameraPosition( float * pPos ) const; + + // Members of IMaterialSystemHardwareConfig + bool HasDestAlphaBuffer() const; + bool HasStencilBuffer() const; + virtual int MaxViewports() const; + virtual void OverrideStreamOffsetSupport( bool bOverrideEnabled, bool bEnableSupport ) {} + virtual int GetShadowFilterMode() const; + int StencilBufferBits() const; + int GetFrameBufferColorDepth() const; + int GetSamplerCount() const; + bool HasSetDeviceGammaRamp() const; + bool SupportsCompressedTextures() const; + VertexCompressionType_t SupportsCompressedVertices() const; + bool SupportsVertexAndPixelShaders() const; + bool SupportsPixelShaders_1_4() const; + bool SupportsPixelShaders_2_0() const; + bool SupportsPixelShaders_2_b() const; + bool ActuallySupportsPixelShaders_2_b() const; + bool SupportsStaticControlFlow() const; + bool SupportsVertexShaders_2_0() const; + bool SupportsShaderModel_3_0() const; + int MaximumAnisotropicLevel() const; + int MaxTextureWidth() const; + int MaxTextureHeight() const; + int MaxTextureAspectRatio() const; + int GetDXSupportLevel() const; + const char *GetShaderDLLName() const + { + return "UNKNOWN"; + } + int TextureMemorySize() const; + bool SupportsOverbright() const; + bool SupportsCubeMaps() const; + bool SupportsMipmappedCubemaps() const; + bool SupportsNonPow2Textures() const; + int GetTextureStageCount() const; + int NumVertexShaderConstants() const; + int NumBooleanVertexShaderConstants() const; + int NumIntegerVertexShaderConstants() const; + int NumPixelShaderConstants() const; + int MaxNumLights() const; + bool SupportsHardwareLighting() const; + int MaxBlendMatrices() const; + int MaxBlendMatrixIndices() const; + int MaxVertexShaderBlendMatrices() const; + int MaxUserClipPlanes() const; + bool UseFastClipping() const + { + return false; + } + bool SpecifiesFogColorInLinearSpace() const; + virtual bool SupportsSRGB() const; + virtual bool FakeSRGBWrite() const; + virtual bool CanDoSRGBReadFromRTs() const; + virtual bool SupportsGLMixedSizeTargets() const; + + const char *GetHWSpecificShaderDLLName() const; + bool NeedsAAClamp() const + { + return false; + } + bool SupportsSpheremapping() const; + virtual int MaxHWMorphBatchCount() const { return 0; } + + // This is the max dx support level supported by the card + virtual int GetMaxDXSupportLevel() const; + + bool ReadPixelsFromFrontBuffer() const; + bool PreferDynamicTextures() const; + virtual bool PreferReducedFillrate() const; + bool HasProjectedBumpEnv() const; + void ForceHardwareSync( void ); + + int GetCurrentNumBones( void ) const; + bool IsHWMorphingEnabled( void ) const; + int GetCurrentLightCombo( void ) const; + void GetDX9LightState( LightState_t *state ) const; + MaterialFogMode_t GetCurrentFogType( void ) const; + + void RecordString( const char *pStr ); + + void EvictManagedResources(); + + void SetTextureTransformDimension( TextureStage_t textureStage, int dimension, bool projected ); + void DisableTextureTransform( TextureStage_t textureStage ) + { + } + void SetBumpEnvMatrix( TextureStage_t textureStage, float m00, float m01, float m10, float m11 ); + + // Gets the lightmap dimensions + virtual void GetLightmapDimensions( int *w, int *h ); + + virtual void SyncToken( const char *pToken ); + + // Setup standard vertex shader constants (that don't change) + // This needs to be called anytime that overbright changes. + virtual void SetStandardVertexShaderConstants( float fOverbright ) + { + } + + // Level of anisotropic filtering + virtual void SetAnisotropicLevel( int nAnisotropyLevel ); + + bool SupportsHDR() const + { + return false; + } + HDRType_t GetHDRType() const + { + return HDR_TYPE_NONE; + } + HDRType_t GetHardwareHDRType() const + { + return HDR_TYPE_NONE; + } + virtual bool NeedsATICentroidHack() const + { + return false; + } + virtual bool SupportsColorOnSecondStream() const + { + return false; + } + virtual bool SupportsStaticPlusDynamicLighting() const + { + return false; + } + virtual bool SupportsStreamOffset() const + { + return false; + } + void SetDefaultDynamicState() + { + } + virtual void CommitPixelShaderLighting( int pshReg ) + { + } + + ShaderAPIOcclusionQuery_t CreateOcclusionQueryObject( void ) + { + return INVALID_SHADERAPI_OCCLUSION_QUERY_HANDLE; + } + + void DestroyOcclusionQueryObject( ShaderAPIOcclusionQuery_t handle ) + { + } + + void BeginOcclusionQueryDrawing( ShaderAPIOcclusionQuery_t handle ) + { + } + + void EndOcclusionQueryDrawing( ShaderAPIOcclusionQuery_t handle ) + { + } + + int OcclusionQuery_GetNumPixelsRendered( ShaderAPIOcclusionQuery_t handle, bool bFlush ) + { + return 0; + } + + virtual void AcquireThreadOwnership() {} + virtual void ReleaseThreadOwnership() {} + + virtual bool SupportsBorderColor() const { return false; } + virtual bool SupportsFetch4() const { return false; } + virtual bool CanStretchRectFromTextures( void ) const { return false; } + virtual void EnableBuffer2FramesAhead( bool bEnable ) {} + + virtual void SetPSNearAndFarZ( int pshReg ) { } + + virtual void SetDepthFeatheringPixelShaderConstant( int iConstant, float fDepthBlendScale ) {} + + void SetPixelShaderFogParams( int reg ) + { + } + + virtual bool InFlashlightMode() const + { + return false; + } + + virtual bool InEditorMode() const + { + return false; + } + + // What fields in the morph do we actually use? + virtual MorphFormat_t ComputeMorphFormat( int numSnapshots, StateSnapshot_t* pIds ) const + { + return 0; + } + + // Gets the bound morph's vertex format; returns 0 if no morph is bound + virtual MorphFormat_t GetBoundMorphFormat() + { + return 0; + } + + // Binds a standard texture + virtual void BindStandardTexture( Sampler_t stage, StandardTextureId_t id ) + { + } + + virtual void BindStandardVertexTexture( VertexTextureSampler_t stage, StandardTextureId_t id ) + { + } + + virtual void GetStandardTextureDimensions( int *pWidth, int *pHeight, StandardTextureId_t id ) + { + *pWidth = *pHeight = 0; + } + + + virtual void SetFlashlightState( const FlashlightState_t &state, const VMatrix &worldToTexture ) + { + } + + virtual void SetFlashlightStateEx( const FlashlightState_t &state, const VMatrix &worldToTexture, ITexture *pFlashlightDepthTexture ) + { + } + + virtual const FlashlightState_t &GetFlashlightState( VMatrix &worldToTexture ) const + { + static FlashlightState_t blah; + return blah; + } + + virtual const FlashlightState_t &GetFlashlightStateEx( VMatrix &worldToTexture, ITexture **pFlashlightDepthTexture ) const + { + static FlashlightState_t blah; + return blah; + } + + virtual void ClearVertexAndPixelShaderRefCounts() + { + } + + virtual void PurgeUnusedVertexAndPixelShaders() + { + } + + virtual bool IsAAEnabled() const + { + return false; + } + + virtual int GetVertexTextureCount() const + { + return 0; + } + + virtual int GetMaxVertexTextureDimension() const + { + return 0; + } + + virtual int MaxTextureDepth() const + { + return 0; + } + + // Binds a vertex texture to a particular texture stage in the vertex pipe + virtual void BindVertexTexture( VertexTextureSampler_t nSampler, ShaderAPITextureHandle_t hTexture ) + { + } + + // Sets morph target factors + virtual void SetFlexWeights( int nFirstWeight, int nCount, const MorphWeight_t* pWeights ) + { + } + + // NOTE: Stuff after this is added after shipping HL2. + ITexture *GetRenderTargetEx( int nRenderTargetID ) + { + return NULL; + } + + void SetToneMappingScaleLinear( const Vector &scale ) + { + } + + const Vector &GetToneMappingScaleLinear( void ) const + { + static Vector dummy; + return dummy; + } + + virtual float GetLightMapScaleFactor( void ) const + { + return 1.0; + } + + + // For dealing with device lost in cases where SwapBuffers isn't called all the time (Hammer) + virtual void HandleDeviceLost() + { + } + + virtual void EnableLinearColorSpaceFrameBuffer( bool bEnable ) + { + } + + // Lets the shader know about the full-screen texture so it can + virtual void SetFullScreenTextureHandle( ShaderAPITextureHandle_t h ) + { + } + + void SetFloatRenderingParameter(int parm_number, float value) + { + } + + void SetIntRenderingParameter(int parm_number, int value) + { + } + void SetVectorRenderingParameter(int parm_number, Vector const &value) + { + } + + float GetFloatRenderingParameter(int parm_number) const + { + return 0; + } + + int GetIntRenderingParameter(int parm_number) const + { + return 0; + } + + Vector GetVectorRenderingParameter(int parm_number) const + { + return Vector(0,0,0); + } + + // Methods related to stencil + void SetStencilEnable(bool onoff) + { + } + + void SetStencilFailOperation(StencilOperation_t op) + { + } + + void SetStencilZFailOperation(StencilOperation_t op) + { + } + + void SetStencilPassOperation(StencilOperation_t op) + { + } + + void SetStencilCompareFunction(StencilComparisonFunction_t cmpfn) + { + } + + void SetStencilReferenceValue(int ref) + { + } + + void SetStencilTestMask(uint32 msk) + { + } + + void SetStencilWriteMask(uint32 msk) + { + } + + void ClearStencilBufferRectangle( int xmin, int ymin, int xmax, int ymax,int value) + { + } + + virtual void GetDXLevelDefaults(uint &max_dxlevel,uint &recommended_dxlevel) + { + max_dxlevel=recommended_dxlevel=90; + } + + virtual void GetMaxToRender( IMesh *pMesh, bool bMaxUntilFlush, int *pMaxVerts, int *pMaxIndices ) + { + *pMaxVerts = 32768; + *pMaxIndices = 32768; + } + + // Returns the max possible vertices + indices to render in a single draw call + virtual int GetMaxVerticesToRender( IMaterial *pMaterial ) + { + return 32768; + } + + virtual int GetMaxIndicesToRender( ) + { + return 32768; + } + virtual int CompareSnapshots( StateSnapshot_t snapshot0, StateSnapshot_t snapshot1 ) { return 0; } + + virtual void DisableAllLocalLights() {} + + virtual bool SupportsMSAAMode( int nMSAAMode ) { return false; } + + virtual bool SupportsCSAAMode( int nNumSamples, int nQualityLevel ) { return false; } + + // Hooks for firing PIX events from outside the Material System... + virtual void BeginPIXEvent( unsigned long color, const char *szName ) {} + virtual void EndPIXEvent() {} + virtual void SetPIXMarker( unsigned long color, const char *szName ) {} + + virtual void ComputeVertexDescription( unsigned char* pBuffer, VertexFormat_t vertexFormat, MeshDesc_t& desc ) const {} + + virtual bool SupportsShadowDepthTextures() { return false; } + + virtual bool SupportsFetch4() { return false; } + + virtual int NeedsShaderSRGBConversion(void) const { return 0; } + virtual bool UsesSRGBCorrectBlending() const { return false; } + + virtual bool HasFastVertexTextures() const { return false; } + + virtual void SetShadowDepthBiasFactors( float fShadowSlopeScaleDepthBias, float fShadowDepthBias ) {} + + virtual void SetDisallowAccess( bool ) {} + virtual void EnableShaderShaderMutex( bool ) {} + virtual void ShaderLock() {} + virtual void ShaderUnlock() {} + +// ------------ New Vertex/Index Buffer interface ---------------------------- + void BindVertexBuffer( int streamID, IVertexBuffer *pVertexBuffer, int nOffsetInBytes, int nFirstVertex, int nVertexCount, VertexFormat_t fmt, int nRepetitions1 ) + { + } + void BindIndexBuffer( IIndexBuffer *pIndexBuffer, int nOffsetInBytes ) + { + } + void Draw( MaterialPrimitiveType_t primitiveType, int firstIndex, int numIndices ) + { + } +// ------------ End ---------------------------- + + virtual int GetVertexBufferCompression( void ) const { return 0; }; + + virtual bool ShouldWriteDepthToDestAlpha( void ) const { return false; }; + virtual bool SupportsHDRMode( HDRType_t nHDRMode ) const { return false; }; + virtual bool IsDX10Card() const { return false; }; + + void PushDeformation( const DeformationBase_t *pDeformation ) + { + } + + virtual void PopDeformation( ) + { + } + + int GetNumActiveDeformations( ) const + { + return 0; + } + + // for shaders to set vertex shader constants. returns a packed state which can be used to set the dynamic combo + int GetPackedDeformationInformation( int nMaskOfUnderstoodDeformations, + float *pConstantValuesOut, + int nBufferSize, + int nMaximumDeformations, + int *pNumDefsOut ) const + { + *pNumDefsOut = 0; + return 0; + } + + void SetStandardTextureHandle(StandardTextureId_t,ShaderAPITextureHandle_t) + { + } + + virtual void ExecuteCommandBuffer( uint8 *pData ) + { + } + virtual bool GetHDREnabled( void ) const { return true; } + virtual void SetHDREnabled( bool bEnable ) {} + + virtual void CopyRenderTargetToScratchTexture( ShaderAPITextureHandle_t srcRt, ShaderAPITextureHandle_t dstTex, Rect_t *pSrcRect = NULL, Rect_t *pDstRect = NULL ) + { + } + + // Allows locking and unlocking of very specific surface types. + virtual void LockRect( void** pOutBits, int* pOutPitch, ShaderAPITextureHandle_t texHandle, int mipmap, int x, int y, int w, int h, bool bWrite, bool bRead ) + { + } + + virtual void UnlockRect( ShaderAPITextureHandle_t texHandle, int mipmap ) + { + } + + virtual void TexLodClamp( int finest ) {} + + virtual void TexLodBias( float bias ) {} + + virtual void CopyTextureToTexture( ShaderAPITextureHandle_t srcTex, ShaderAPITextureHandle_t dstTex ) {} + + void PrintfVA( char *fmt, va_list vargs ) {} + void Printf( const char *fmt, ... ) {} + float Knob( char *knobname, float *setvalue = NULL ) { return 0.0f; }; + +private: + enum + { + TRANSLUCENT = 0x1, + ALPHATESTED = 0x2, + VERTEX_AND_PIXEL_SHADERS = 0x4, + DEPTHWRITE = 0x8, + }; + + CEmptyMesh m_Mesh; + + void EnableAlphaToCoverage() {} ; + void DisableAlphaToCoverage() {} ; + + ImageFormat GetShadowDepthTextureFormat() { return IMAGE_FORMAT_UNKNOWN; }; + ImageFormat GetNullTextureFormat() { return IMAGE_FORMAT_UNKNOWN; }; +}; + + +//----------------------------------------------------------------------------- +// Class Factory +//----------------------------------------------------------------------------- + +static CShaderAPIEmpty g_ShaderAPIEmpty; +static CShaderShadowEmpty g_ShaderShadow; + +// FIXME: Remove; it's for backward compat with the materialsystem only for now +EXPOSE_SINGLE_INTERFACE_GLOBALVAR( CShaderAPIEmpty, IShaderAPI, + SHADERAPI_INTERFACE_VERSION, g_ShaderAPIEmpty ) + +EXPOSE_SINGLE_INTERFACE_GLOBALVAR( CShaderShadowEmpty, IShaderShadow, + SHADERSHADOW_INTERFACE_VERSION, g_ShaderShadow ) + +EXPOSE_SINGLE_INTERFACE_GLOBALVAR( CShaderAPIEmpty, IMaterialSystemHardwareConfig, + MATERIALSYSTEM_HARDWARECONFIG_INTERFACE_VERSION, g_ShaderAPIEmpty ) + +EXPOSE_SINGLE_INTERFACE_GLOBALVAR( CShaderAPIEmpty, IDebugTextureInfo, + DEBUG_TEXTURE_INFO_VERSION, g_ShaderAPIEmpty ) + + +//----------------------------------------------------------------------------- +// The main GL Shader util interface +//----------------------------------------------------------------------------- +IShaderUtil* g_pShaderUtil; + + +//----------------------------------------------------------------------------- +// Factory to return from SetMode +//----------------------------------------------------------------------------- +static void* ShaderInterfaceFactory( const char *pInterfaceName, int *pReturnCode ) +{ + if ( pReturnCode ) + { + *pReturnCode = IFACE_OK; + } + if ( !Q_stricmp( pInterfaceName, SHADER_DEVICE_INTERFACE_VERSION ) ) + return static_cast< IShaderDevice* >( &s_ShaderDeviceEmpty ); + if ( !Q_stricmp( pInterfaceName, SHADERAPI_INTERFACE_VERSION ) ) + return static_cast< IShaderAPI* >( &g_ShaderAPIEmpty ); + if ( !Q_stricmp( pInterfaceName, SHADERSHADOW_INTERFACE_VERSION ) ) + return static_cast< IShaderShadow* >( &g_ShaderShadow ); + + if ( pReturnCode ) + { + *pReturnCode = IFACE_FAILED; + } + return NULL; +} + + +//----------------------------------------------------------------------------- +// +// CShaderDeviceMgrEmpty +// +//----------------------------------------------------------------------------- +bool CShaderDeviceMgrEmpty::Connect( CreateInterfaceFn factory ) +{ + // So others can access it + g_pShaderUtil = (IShaderUtil*)factory( SHADER_UTIL_INTERFACE_VERSION, NULL ); + + return true; +} + +void CShaderDeviceMgrEmpty::Disconnect() +{ + g_pShaderUtil = NULL; +} + +void *CShaderDeviceMgrEmpty::QueryInterface( const char *pInterfaceName ) +{ + if ( !Q_stricmp( pInterfaceName, SHADER_DEVICE_MGR_INTERFACE_VERSION ) ) + return static_cast< IShaderDeviceMgr* >( this ); + if ( !Q_stricmp( pInterfaceName, MATERIALSYSTEM_HARDWARECONFIG_INTERFACE_VERSION ) ) + return static_cast< IMaterialSystemHardwareConfig* >( &g_ShaderAPIEmpty ); + return NULL; +} + +InitReturnVal_t CShaderDeviceMgrEmpty::Init() +{ + return INIT_OK; +} + +void CShaderDeviceMgrEmpty::Shutdown() +{ + +} + +// Sets the adapter +bool CShaderDeviceMgrEmpty::SetAdapter( int nAdapter, int nFlags ) +{ + return true; +} + +// FIXME: Is this a public interface? Might only need to be private to shaderapi +CreateInterfaceFn CShaderDeviceMgrEmpty::SetMode( void *hWnd, int nAdapter, const ShaderDeviceInfo_t& mode ) +{ + return ShaderInterfaceFactory; +} + +// Gets the number of adapters... +int CShaderDeviceMgrEmpty::GetAdapterCount() const +{ + return 0; +} + +bool CShaderDeviceMgrEmpty::GetRecommendedConfigurationInfo( int nAdapter, int nDXLevel, KeyValues *pKeyValues ) +{ + return true; +} + +// Returns info about each adapter +void CShaderDeviceMgrEmpty::GetAdapterInfo( int adapter, MaterialAdapterInfo_t& info ) const +{ + memset( &info, 0, sizeof( info ) ); + info.m_nDXSupportLevel = 90; +} + +// Returns the number of modes +int CShaderDeviceMgrEmpty::GetModeCount( int nAdapter ) const +{ + return 0; +} + +// Returns mode information.. +void CShaderDeviceMgrEmpty::GetModeInfo( ShaderDisplayMode_t *pInfo, int nAdapter, int nMode ) const +{ +} + +void CShaderDeviceMgrEmpty::GetCurrentModeInfo( ShaderDisplayMode_t* pInfo, int nAdapter ) const +{ +} + + +//----------------------------------------------------------------------------- +// +// Shader device empty +// +//----------------------------------------------------------------------------- +void CShaderDeviceEmpty::GetWindowSize( int &width, int &height ) const +{ + width = 0; + height = 0; +} + +void CShaderDeviceEmpty::GetBackBufferDimensions( int& width, int& height ) const +{ + width = 1024; + height = 768; +} + +// Use this to spew information about the 3D layer +void CShaderDeviceEmpty::SpewDriverInfo() const +{ + Warning("Empty shader\n"); +} + +// Creates/ destroys a child window +bool CShaderDeviceEmpty::AddView( void* hwnd ) +{ + return true; +} + +void CShaderDeviceEmpty::RemoveView( void* hwnd ) +{ +} + +// Activates a view +void CShaderDeviceEmpty::SetView( void* hwnd ) +{ +} + +void CShaderDeviceEmpty::ReleaseResources() +{ +} + +void CShaderDeviceEmpty::ReacquireResources() +{ +} + +// Creates/destroys Mesh +IMesh* CShaderDeviceEmpty::CreateStaticMesh( VertexFormat_t fmt, const char *pTextureBudgetGroup, IMaterial * pMaterial ) +{ + return &m_Mesh; +} + +void CShaderDeviceEmpty::DestroyStaticMesh( IMesh* mesh ) +{ +} + +// Creates/destroys static vertex + index buffers +IVertexBuffer *CShaderDeviceEmpty::CreateVertexBuffer( ShaderBufferType_t type, VertexFormat_t fmt, int nVertexCount, const char *pTextureBudgetGroup ) +{ + return ( type == SHADER_BUFFER_TYPE_STATIC || type == SHADER_BUFFER_TYPE_STATIC_TEMP ) ? &m_Mesh : &m_DynamicMesh; +} + +void CShaderDeviceEmpty::DestroyVertexBuffer( IVertexBuffer *pVertexBuffer ) +{ + +} + +IIndexBuffer *CShaderDeviceEmpty::CreateIndexBuffer( ShaderBufferType_t bufferType, MaterialIndexFormat_t fmt, int nIndexCount, const char *pTextureBudgetGroup ) +{ + switch( bufferType ) + { + case SHADER_BUFFER_TYPE_STATIC: + case SHADER_BUFFER_TYPE_STATIC_TEMP: + return &m_Mesh; + default: + Assert( 0 ); + case SHADER_BUFFER_TYPE_DYNAMIC: + case SHADER_BUFFER_TYPE_DYNAMIC_TEMP: + return &m_DynamicMesh; + } +} + +void CShaderDeviceEmpty::DestroyIndexBuffer( IIndexBuffer *pIndexBuffer ) +{ + +} + +IVertexBuffer *CShaderDeviceEmpty::GetDynamicVertexBuffer( int streamID, VertexFormat_t vertexFormat, bool bBuffered ) +{ + return &m_DynamicMesh; +} + +IIndexBuffer *CShaderDeviceEmpty::GetDynamicIndexBuffer( MaterialIndexFormat_t fmt, bool bBuffered ) +{ + return &m_Mesh; +} + + + +//----------------------------------------------------------------------------- +// +// The empty mesh... +// +//----------------------------------------------------------------------------- +CEmptyMesh::CEmptyMesh( bool bIsDynamic ) : m_bIsDynamic( bIsDynamic ) +{ + m_pVertexMemory = new unsigned char[VERTEX_BUFFER_SIZE]; +} + +CEmptyMesh::~CEmptyMesh() +{ + delete[] m_pVertexMemory; +} + +bool CEmptyMesh::Lock( int nMaxIndexCount, bool bAppend, IndexDesc_t& desc ) +{ + static int s_BogusIndex; + desc.m_pIndices = (unsigned short*)&s_BogusIndex; + desc.m_nIndexSize = 0; + desc.m_nFirstIndex = 0; + desc.m_nOffset = 0; + return true; +} + +void CEmptyMesh::Unlock( int nWrittenIndexCount, IndexDesc_t& desc ) +{ +} + +void CEmptyMesh::ModifyBegin( bool bReadOnly, int nFirstIndex, int nIndexCount, IndexDesc_t& desc ) +{ + Lock( nIndexCount, false, desc ); +} + +void CEmptyMesh::ModifyEnd( IndexDesc_t& desc ) +{ +} + +void CEmptyMesh::Spew( int nIndexCount, const IndexDesc_t & desc ) +{ +} + +void CEmptyMesh::ValidateData( int nIndexCount, const IndexDesc_t &desc ) +{ +} + +bool CEmptyMesh::Lock( int nVertexCount, bool bAppend, VertexDesc_t &desc ) +{ + // Who cares about the data? + desc.m_pPosition = (float*)m_pVertexMemory; + desc.m_pNormal = (float*)m_pVertexMemory; + desc.m_pColor = m_pVertexMemory; + + int i; + for ( i = 0; i < VERTEX_MAX_TEXTURE_COORDINATES; ++i) + { + desc.m_pTexCoord[i] = (float*)m_pVertexMemory; + } + + desc.m_pBoneWeight = (float*)m_pVertexMemory; + desc.m_pBoneMatrixIndex = (unsigned char*)m_pVertexMemory; + desc.m_pTangentS = (float*)m_pVertexMemory; + desc.m_pTangentT = (float*)m_pVertexMemory; + desc.m_pUserData = (float*)m_pVertexMemory; + desc.m_NumBoneWeights = 2; + + desc.m_VertexSize_Position = 0; + desc.m_VertexSize_BoneWeight = 0; + desc.m_VertexSize_BoneMatrixIndex = 0; + desc.m_VertexSize_Normal = 0; + desc.m_VertexSize_Color = 0; + for( i=0; i < VERTEX_MAX_TEXTURE_COORDINATES; i++ ) + { + desc.m_VertexSize_TexCoord[i] = 0; + } + desc.m_VertexSize_TangentS = 0; + desc.m_VertexSize_TangentT = 0; + desc.m_VertexSize_UserData = 0; + desc.m_ActualVertexSize = 0; // Size of the vertices.. Some of the m_VertexSize_ elements above + + desc.m_nFirstVertex = 0; + desc.m_nOffset = 0; + return true; +} + +void CEmptyMesh::Unlock( int nVertexCount, VertexDesc_t &desc ) +{ +} + +void CEmptyMesh::Spew( int nVertexCount, const VertexDesc_t &desc ) +{ +} + +void CEmptyMesh::ValidateData( int nVertexCount, const VertexDesc_t & desc ) +{ +} + +void CEmptyMesh::LockMesh( int numVerts, int numIndices, MeshDesc_t& desc ) +{ + Lock( numVerts, false, *static_cast( &desc ) ); + Lock( numIndices, false, *static_cast( &desc ) ); +} + +void CEmptyMesh::UnlockMesh( int numVerts, int numIndices, MeshDesc_t& desc ) +{ +} + +void CEmptyMesh::ModifyBeginEx( bool bReadOnly, int firstVertex, int numVerts, int firstIndex, int numIndices, MeshDesc_t& desc ) +{ + Lock( numVerts, false, *static_cast( &desc ) ); + Lock( numIndices, false, *static_cast( &desc ) ); +} + +void CEmptyMesh::ModifyBegin( int firstVertex, int numVerts, int firstIndex, int numIndices, MeshDesc_t& desc ) +{ + ModifyBeginEx( false, firstVertex, numVerts, firstIndex, numIndices, desc ); +} + +void CEmptyMesh::ModifyEnd( MeshDesc_t& desc ) +{ +} + +// returns the # of vertices (static meshes only) +int CEmptyMesh::VertexCount() const +{ + return 0; +} + +// Sets the primitive type +void CEmptyMesh::SetPrimitiveType( MaterialPrimitiveType_t type ) +{ +} + +// Draws the entire mesh +void CEmptyMesh::Draw( int firstIndex, int numIndices ) +{ +} + +void CEmptyMesh::Draw(CPrimList *pPrims, int nPrims) +{ +} + +// Copy verts and/or indices to a mesh builder. This only works for temp meshes! +void CEmptyMesh::CopyToMeshBuilder( + int iStartVert, // Which vertices to copy. + int nVerts, + int iStartIndex, // Which indices to copy. + int nIndices, + int indexOffset, // This is added to each index. + CMeshBuilder &builder ) +{ +} + +// Spews the mesh data +void CEmptyMesh::Spew( int numVerts, int numIndices, const MeshDesc_t & desc ) +{ +} + +void CEmptyMesh::ValidateData( int numVerts, int numIndices, const MeshDesc_t & desc ) +{ +} + +// gets the associated material +IMaterial* CEmptyMesh::GetMaterial() +{ + // umm. this don't work none + Assert(0); + return 0; +} + +//----------------------------------------------------------------------------- +// The shader shadow interface +//----------------------------------------------------------------------------- +CShaderShadowEmpty::CShaderShadowEmpty() +{ + m_IsTranslucent = false; + m_IsAlphaTested = false; + m_bIsDepthWriteEnabled = true; + m_bUsesVertexAndPixelShaders = false; +} + +CShaderShadowEmpty::~CShaderShadowEmpty() +{ +} + +// Sets the default *shadow* state +void CShaderShadowEmpty::SetDefaultState() +{ + m_IsTranslucent = false; + m_IsAlphaTested = false; + m_bIsDepthWriteEnabled = true; + m_bUsesVertexAndPixelShaders = false; +} + +// Methods related to depth buffering +void CShaderShadowEmpty::DepthFunc( ShaderDepthFunc_t depthFunc ) +{ +} + +void CShaderShadowEmpty::EnableDepthWrites( bool bEnable ) +{ + m_bIsDepthWriteEnabled = bEnable; +} + +void CShaderShadowEmpty::EnableDepthTest( bool bEnable ) +{ +} + +void CShaderShadowEmpty::EnablePolyOffset( PolygonOffsetMode_t nOffsetMode ) +{ +} + +// Suppresses/activates color writing +void CShaderShadowEmpty::EnableColorWrites( bool bEnable ) +{ +} + +// Suppresses/activates alpha writing +void CShaderShadowEmpty::EnableAlphaWrites( bool bEnable ) +{ +} + +// Methods related to alpha blending +void CShaderShadowEmpty::EnableBlending( bool bEnable ) +{ + m_IsTranslucent = bEnable; +} + +void CShaderShadowEmpty::BlendFunc( ShaderBlendFactor_t srcFactor, ShaderBlendFactor_t dstFactor ) +{ +} + +// A simpler method of dealing with alpha modulation +void CShaderShadowEmpty::EnableAlphaPipe( bool bEnable ) +{ +} + +void CShaderShadowEmpty::EnableConstantAlpha( bool bEnable ) +{ +} + +void CShaderShadowEmpty::EnableVertexAlpha( bool bEnable ) +{ +} + +void CShaderShadowEmpty::EnableTextureAlpha( TextureStage_t stage, bool bEnable ) +{ +} + + +// Alpha testing +void CShaderShadowEmpty::EnableAlphaTest( bool bEnable ) +{ + m_IsAlphaTested = bEnable; +} + +void CShaderShadowEmpty::AlphaFunc( ShaderAlphaFunc_t alphaFunc, float alphaRef /* [0-1] */ ) +{ +} + + +// Wireframe/filled polygons +void CShaderShadowEmpty::PolyMode( ShaderPolyModeFace_t face, ShaderPolyMode_t polyMode ) +{ +} + + +// Back face culling +void CShaderShadowEmpty::EnableCulling( bool bEnable ) +{ +} + + +// Alpha to coverage +void CShaderShadowEmpty::EnableAlphaToCoverage( bool bEnable ) +{ +} + + +// constant color + transparency +void CShaderShadowEmpty::EnableConstantColor( bool bEnable ) +{ +} + +// Indicates the vertex format for use with a vertex shader +// The flags to pass in here come from the VertexFormatFlags_t enum +// If pTexCoordDimensions is *not* specified, we assume all coordinates +// are 2-dimensional +void CShaderShadowEmpty::VertexShaderVertexFormat( unsigned int nFlags, + int nTexCoordCount, + int* pTexCoordDimensions, + int nUserDataSize ) +{ +} + +// Indicates we're going to light the model +void CShaderShadowEmpty::EnableLighting( bool bEnable ) +{ +} + +void CShaderShadowEmpty::EnableSpecular( bool bEnable ) +{ +} + +// Activate/deactivate skinning +void CShaderShadowEmpty::EnableVertexBlend( bool bEnable ) +{ +} + +// per texture unit stuff +void CShaderShadowEmpty::OverbrightValue( TextureStage_t stage, float value ) +{ +} + +void CShaderShadowEmpty::EnableTexture( Sampler_t stage, bool bEnable ) +{ +} + +void CShaderShadowEmpty::EnableCustomPixelPipe( bool bEnable ) +{ +} + +void CShaderShadowEmpty::CustomTextureStages( int stageCount ) +{ +} + +void CShaderShadowEmpty::CustomTextureOperation( TextureStage_t stage, ShaderTexChannel_t channel, + ShaderTexOp_t op, ShaderTexArg_t arg1, ShaderTexArg_t arg2 ) +{ +} + +void CShaderShadowEmpty::EnableTexGen( TextureStage_t stage, bool bEnable ) +{ +} + +void CShaderShadowEmpty::TexGen( TextureStage_t stage, ShaderTexGenParam_t param ) +{ +} + +// Sets the vertex and pixel shaders +void CShaderShadowEmpty::SetVertexShader( const char *pShaderName, int vshIndex ) +{ + m_bUsesVertexAndPixelShaders = ( pShaderName != NULL ); +} + +void CShaderShadowEmpty::EnableBlendingSeparateAlpha( bool bEnable ) +{ +} +void CShaderShadowEmpty::SetPixelShader( const char *pShaderName, int pshIndex ) +{ + m_bUsesVertexAndPixelShaders = ( pShaderName != NULL ); +} + +void CShaderShadowEmpty::BlendFuncSeparateAlpha( ShaderBlendFactor_t srcFactor, ShaderBlendFactor_t dstFactor ) +{ +} +// indicates what per-vertex data we're providing +void CShaderShadowEmpty::DrawFlags( unsigned int drawFlags ) +{ +} + + + +//----------------------------------------------------------------------------- +// +// Shader API Empty +// +//----------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +// Constructor, destructor +//----------------------------------------------------------------------------- + +CShaderAPIEmpty::CShaderAPIEmpty() : m_Mesh( false ) +{ +} + +CShaderAPIEmpty::~CShaderAPIEmpty() +{ +} + + +bool CShaderAPIEmpty::DoRenderTargetsNeedSeparateDepthBuffer() const +{ + return false; +} + +// Can we download textures? +bool CShaderAPIEmpty::CanDownloadTextures() const +{ + return false; +} + +// Used to clear the transition table when we know it's become invalid. +void CShaderAPIEmpty::ClearSnapshots() +{ +} + +// Members of IMaterialSystemHardwareConfig +bool CShaderAPIEmpty::HasDestAlphaBuffer() const +{ + return false; +} + +bool CShaderAPIEmpty::HasStencilBuffer() const +{ + return false; +} + +int CShaderAPIEmpty::MaxViewports() const +{ + return 1; +} + +int CShaderAPIEmpty::GetShadowFilterMode() const +{ + return 0; +} + +int CShaderAPIEmpty::StencilBufferBits() const +{ + return 0; +} + +int CShaderAPIEmpty::GetFrameBufferColorDepth() const +{ + return 0; +} + +int CShaderAPIEmpty::GetSamplerCount() const +{ + if ((ShaderUtil()->GetConfig().dxSupportLevel > 0) && + (ShaderUtil()->GetConfig().dxSupportLevel < 60)) + return 1; + if (( ShaderUtil()->GetConfig().dxSupportLevel >= 60 ) && ( ShaderUtil()->GetConfig().dxSupportLevel < 80 )) + return 2; + return 4; +} + +bool CShaderAPIEmpty::HasSetDeviceGammaRamp() const +{ + return false; +} + +bool CShaderAPIEmpty::SupportsCompressedTextures() const +{ + return false; +} + +VertexCompressionType_t CShaderAPIEmpty::SupportsCompressedVertices() const +{ + return VERTEX_COMPRESSION_NONE; +} + +bool CShaderAPIEmpty::SupportsVertexAndPixelShaders() const +{ + if ((ShaderUtil()->GetConfig().dxSupportLevel > 0) && + (ShaderUtil()->GetConfig().dxSupportLevel < 80)) + return false; + + return true; +} + +bool CShaderAPIEmpty::SupportsPixelShaders_1_4() const +{ + if ((ShaderUtil()->GetConfig().dxSupportLevel > 0) && + (ShaderUtil()->GetConfig().dxSupportLevel < 81)) + return false; + + return true; +} + +bool CShaderAPIEmpty::SupportsPixelShaders_2_0() const +{ + if ((ShaderUtil()->GetConfig().dxSupportLevel > 0) && + (ShaderUtil()->GetConfig().dxSupportLevel < 90)) + return false; + + return true; +} + +bool CShaderAPIEmpty::SupportsPixelShaders_2_b() const +{ + if ((ShaderUtil()->GetConfig().dxSupportLevel > 0) && + (ShaderUtil()->GetConfig().dxSupportLevel < 90)) + return false; + + return true; +} + +bool CShaderAPIEmpty::ActuallySupportsPixelShaders_2_b() const +{ + return true; +} + +bool CShaderAPIEmpty::SupportsShaderModel_3_0() const +{ + if ((ShaderUtil()->GetConfig().dxSupportLevel > 0) && + (ShaderUtil()->GetConfig().dxSupportLevel < 95)) + return false; + + return true; +} + +bool CShaderAPIEmpty::SupportsStaticControlFlow() const +{ + if ( IsOpenGL() ) + return false; + + return SupportsVertexShaders_2_0(); +} + +bool CShaderAPIEmpty::SupportsVertexShaders_2_0() const +{ + if ((ShaderUtil()->GetConfig().dxSupportLevel > 0) && + (ShaderUtil()->GetConfig().dxSupportLevel < 90)) + return false; + + return true; +} + +int CShaderAPIEmpty::MaximumAnisotropicLevel() const +{ + return 0; +} + +void CShaderAPIEmpty::SetAnisotropicLevel( int nAnisotropyLevel ) +{ +} + +int CShaderAPIEmpty::MaxTextureWidth() const +{ + // Should be big enough to cover all cases + return 16384; +} + +int CShaderAPIEmpty::MaxTextureHeight() const +{ + // Should be big enough to cover all cases + return 16384; +} + +int CShaderAPIEmpty::MaxTextureAspectRatio() const +{ + // Should be big enough to cover all cases + return 16384; +} + + +int CShaderAPIEmpty::TextureMemorySize() const +{ + // fake it + return 64 * 1024 * 1024; +} + +int CShaderAPIEmpty::GetDXSupportLevel() const +{ + return 90; +} + +bool CShaderAPIEmpty::SupportsOverbright() const +{ + return false; +} + +bool CShaderAPIEmpty::SupportsCubeMaps() const +{ + if ((ShaderUtil()->GetConfig().dxSupportLevel > 0) && + (ShaderUtil()->GetConfig().dxSupportLevel < 70)) + return false; + + return true; +} + +bool CShaderAPIEmpty::SupportsNonPow2Textures() const +{ + return true; +} + +bool CShaderAPIEmpty::SupportsMipmappedCubemaps() const +{ + if ((ShaderUtil()->GetConfig().dxSupportLevel > 0) && + (ShaderUtil()->GetConfig().dxSupportLevel < 70)) + return false; + + return true; +} + +int CShaderAPIEmpty::GetTextureStageCount() const +{ + return 4; +} + +int CShaderAPIEmpty::NumVertexShaderConstants() const +{ + return 128; +} + +int CShaderAPIEmpty::NumBooleanVertexShaderConstants() const +{ + return 0; +} + +int CShaderAPIEmpty::NumIntegerVertexShaderConstants() const +{ + return 0; +} + +int CShaderAPIEmpty::NumPixelShaderConstants() const +{ + return 8; +} + +int CShaderAPIEmpty::MaxNumLights() const +{ + return 4; +} + +bool CShaderAPIEmpty::SupportsSpheremapping() const +{ + return false; +} + + +// This is the max dx support level supported by the card +int CShaderAPIEmpty::GetMaxDXSupportLevel() const +{ + return 90; +} + +bool CShaderAPIEmpty::SupportsHardwareLighting() const +{ + if ((ShaderUtil()->GetConfig().dxSupportLevel > 0) && + (ShaderUtil()->GetConfig().dxSupportLevel < 70)) + return false; + + return true; +} + +int CShaderAPIEmpty::MaxBlendMatrices() const +{ + if ((ShaderUtil()->GetConfig().dxSupportLevel > 0) && + (ShaderUtil()->GetConfig().dxSupportLevel < 70)) + { + return 1; + } + + return 0; +} + +int CShaderAPIEmpty::MaxBlendMatrixIndices() const +{ + if ((ShaderUtil()->GetConfig().dxSupportLevel > 0) && + (ShaderUtil()->GetConfig().dxSupportLevel < 70)) + { + return 1; + } + + return 0; +} + +int CShaderAPIEmpty::MaxVertexShaderBlendMatrices() const +{ + return 0; +} + +int CShaderAPIEmpty::MaxUserClipPlanes() const +{ + return 0; +} + +bool CShaderAPIEmpty::SpecifiesFogColorInLinearSpace() const +{ + return false; +} + +bool CShaderAPIEmpty::SupportsSRGB() const +{ + return false; +} + +bool CShaderAPIEmpty::FakeSRGBWrite() const +{ + return false; +} + +bool CShaderAPIEmpty::CanDoSRGBReadFromRTs() const +{ + return true; +} + +bool CShaderAPIEmpty::SupportsGLMixedSizeTargets() const +{ + return false; +} + +const char *CShaderAPIEmpty::GetHWSpecificShaderDLLName() const +{ + return 0; +} + +// Sets the default *dynamic* state +void CShaderAPIEmpty::SetDefaultState() +{ +} + + +// Returns the snapshot id for the shader state +StateSnapshot_t CShaderAPIEmpty::TakeSnapshot( ) +{ + StateSnapshot_t id = 0; + if (g_ShaderShadow.m_IsTranslucent) + id |= TRANSLUCENT; + if (g_ShaderShadow.m_IsAlphaTested) + id |= ALPHATESTED; + if (g_ShaderShadow.m_bUsesVertexAndPixelShaders) + id |= VERTEX_AND_PIXEL_SHADERS; + if (g_ShaderShadow.m_bIsDepthWriteEnabled) + id |= DEPTHWRITE; + return id; +} + +// Returns true if the state snapshot is transparent +bool CShaderAPIEmpty::IsTranslucent( StateSnapshot_t id ) const +{ + return (id & TRANSLUCENT) != 0; +} + +bool CShaderAPIEmpty::IsAlphaTested( StateSnapshot_t id ) const +{ + return (id & ALPHATESTED) != 0; +} + +bool CShaderAPIEmpty::IsDepthWriteEnabled( StateSnapshot_t id ) const +{ + return (id & DEPTHWRITE) != 0; +} + +bool CShaderAPIEmpty::UsesVertexAndPixelShaders( StateSnapshot_t id ) const +{ + return (id & VERTEX_AND_PIXEL_SHADERS) != 0; +} + +// Gets the vertex format for a set of snapshot ids +VertexFormat_t CShaderAPIEmpty::ComputeVertexFormat( int numSnapshots, StateSnapshot_t* pIds ) const +{ + return 0; +} + +// Gets the vertex format for a set of snapshot ids +VertexFormat_t CShaderAPIEmpty::ComputeVertexUsage( int numSnapshots, StateSnapshot_t* pIds ) const +{ + return 0; +} + +// Uses a state snapshot +void CShaderAPIEmpty::UseSnapshot( StateSnapshot_t snapshot ) +{ +} + +// Sets the color to modulate by +void CShaderAPIEmpty::Color3f( float r, float g, float b ) +{ +} + +void CShaderAPIEmpty::Color3fv( float const* pColor ) +{ +} + +void CShaderAPIEmpty::Color4f( float r, float g, float b, float a ) +{ +} + +void CShaderAPIEmpty::Color4fv( float const* pColor ) +{ +} + +// Faster versions of color +void CShaderAPIEmpty::Color3ub( unsigned char r, unsigned char g, unsigned char b ) +{ +} + +void CShaderAPIEmpty::Color3ubv( unsigned char const* rgb ) +{ +} + +void CShaderAPIEmpty::Color4ub( unsigned char r, unsigned char g, unsigned char b, unsigned char a ) +{ +} + +void CShaderAPIEmpty::Color4ubv( unsigned char const* rgba ) +{ +} + +// The shade mode +void CShaderAPIEmpty::ShadeMode( ShaderShadeMode_t mode ) +{ +} + +// Binds a particular material to render with +void CShaderAPIEmpty::Bind( IMaterial* pMaterial ) +{ +} + +// Cull mode +void CShaderAPIEmpty::CullMode( MaterialCullMode_t cullMode ) +{ +} + +void CShaderAPIEmpty::ForceDepthFuncEquals( bool bEnable ) +{ +} + +// Forces Z buffering on or off +void CShaderAPIEmpty::OverrideDepthEnable( bool bEnable, bool bDepthEnable ) +{ +} + +void CShaderAPIEmpty::OverrideAlphaWriteEnable( bool bOverrideEnable, bool bAlphaWriteEnable ) +{ +} + +void CShaderAPIEmpty::OverrideColorWriteEnable( bool bOverrideEnable, bool bColorWriteEnable ) +{ +} + +//legacy fast clipping linkage +void CShaderAPIEmpty::SetHeightClipZ( float z ) +{ +} + +void CShaderAPIEmpty::SetHeightClipMode( enum MaterialHeightClipMode_t heightClipMode ) +{ +} + +// Sets the lights +void CShaderAPIEmpty::SetLight( int lightNum, const LightDesc_t& desc ) +{ +} + +// Sets lighting origin for the current model +void CShaderAPIEmpty::SetLightingOrigin( Vector vLightingOrigin ) +{ +} + +void CShaderAPIEmpty::SetAmbientLight( float r, float g, float b ) +{ +} + +void CShaderAPIEmpty::SetAmbientLightCube( Vector4D cube[6] ) +{ +} + +// Get lights +int CShaderAPIEmpty::GetMaxLights( void ) const +{ + return 0; +} + +const LightDesc_t& CShaderAPIEmpty::GetLight( int lightNum ) const +{ + static LightDesc_t blah; + return blah; +} + +// Render state for the ambient light cube (vertex shaders) +void CShaderAPIEmpty::SetVertexShaderStateAmbientLightCube() +{ +} + +void CShaderAPIEmpty::SetSkinningMatrices() +{ +} + +// Lightmap texture binding +void CShaderAPIEmpty::BindLightmap( TextureStage_t stage ) +{ +} + +void CShaderAPIEmpty::BindBumpLightmap( TextureStage_t stage ) +{ +} + +void CShaderAPIEmpty::BindFullbrightLightmap( TextureStage_t stage ) +{ +} + +void CShaderAPIEmpty::BindWhite( TextureStage_t stage ) +{ +} + +void CShaderAPIEmpty::BindBlack( TextureStage_t stage ) +{ +} + +void CShaderAPIEmpty::BindGrey( TextureStage_t stage ) +{ +} + +// Gets the lightmap dimensions +void CShaderAPIEmpty::GetLightmapDimensions( int *w, int *h ) +{ + g_pShaderUtil->GetLightmapDimensions( w, h ); +} + +// Special system flat normal map binding. +void CShaderAPIEmpty::BindFlatNormalMap( TextureStage_t stage ) +{ +} + +void CShaderAPIEmpty::BindNormalizationCubeMap( TextureStage_t stage ) +{ +} + +void CShaderAPIEmpty::BindSignedNormalizationCubeMap( TextureStage_t stage ) +{ +} + +void CShaderAPIEmpty::BindFBTexture( TextureStage_t stage, int textureIndex ) +{ +} + +// Flushes any primitives that are buffered +void CShaderAPIEmpty::FlushBufferedPrimitives() +{ +} + +// Gets the dynamic mesh; note that you've got to render the mesh +// before calling this function a second time. Clients should *not* +// call DestroyStaticMesh on the mesh returned by this call. +IMesh* CShaderAPIEmpty::GetDynamicMesh( IMaterial* pMaterial, int nHWSkinBoneCount, bool buffered, IMesh* pVertexOverride, IMesh* pIndexOverride ) +{ + return &m_Mesh; +} + +IMesh* CShaderAPIEmpty::GetDynamicMeshEx( IMaterial* pMaterial, VertexFormat_t fmt, int nHWSkinBoneCount, bool buffered, IMesh* pVertexOverride, IMesh* pIndexOverride ) +{ + return &m_Mesh; +} + +IMesh* CShaderAPIEmpty::GetFlexMesh() +{ + return &m_Mesh; +} + +// Begins a rendering pass that uses a state snapshot +void CShaderAPIEmpty::BeginPass( StateSnapshot_t snapshot ) +{ +} + +// Renders a single pass of a material +void CShaderAPIEmpty::RenderPass( int nPass, int nPassCount ) +{ +} + +// stuff related to matrix stacks +void CShaderAPIEmpty::MatrixMode( MaterialMatrixMode_t matrixMode ) +{ +} + +void CShaderAPIEmpty::PushMatrix() +{ +} + +void CShaderAPIEmpty::PopMatrix() +{ +} + +void CShaderAPIEmpty::LoadMatrix( float *m ) +{ +} + +void CShaderAPIEmpty::MultMatrix( float *m ) +{ +} + +void CShaderAPIEmpty::MultMatrixLocal( float *m ) +{ +} + +void CShaderAPIEmpty::GetMatrix( MaterialMatrixMode_t matrixMode, float *dst ) +{ +} + +void CShaderAPIEmpty::LoadIdentity( void ) +{ +} + +void CShaderAPIEmpty::LoadCameraToWorld( void ) +{ +} + +void CShaderAPIEmpty::Ortho( double left, double top, double right, double bottom, double zNear, double zFar ) +{ +} + +void CShaderAPIEmpty::PerspectiveX( double fovx, double aspect, double zNear, double zFar ) +{ +} + +void CShaderAPIEmpty::PerspectiveOffCenterX( double fovx, double aspect, double zNear, double zFar, double bottom, double top, double left, double right ) +{ +} + +void CShaderAPIEmpty::PickMatrix( int x, int y, int width, int height ) +{ +} + +void CShaderAPIEmpty::Rotate( float angle, float x, float y, float z ) +{ +} + +void CShaderAPIEmpty::Translate( float x, float y, float z ) +{ +} + +void CShaderAPIEmpty::Scale( float x, float y, float z ) +{ +} + +void CShaderAPIEmpty::ScaleXY( float x, float y ) +{ +} + +// Fog methods... +void CShaderAPIEmpty::FogMode( MaterialFogMode_t fogMode ) +{ +} + +void CShaderAPIEmpty::FogStart( float fStart ) +{ +} + +void CShaderAPIEmpty::FogEnd( float fEnd ) +{ +} + +void CShaderAPIEmpty::SetFogZ( float fogZ ) +{ +} + +void CShaderAPIEmpty::FogMaxDensity( float flMaxDensity ) +{ +} + +void CShaderAPIEmpty::GetFogDistances( float *fStart, float *fEnd, float *fFogZ ) +{ +} + + +void CShaderAPIEmpty::SceneFogColor3ub( unsigned char r, unsigned char g, unsigned char b ) +{ +} + + +void CShaderAPIEmpty::SceneFogMode( MaterialFogMode_t fogMode ) +{ +} + +void CShaderAPIEmpty::GetSceneFogColor( unsigned char *rgb ) +{ +} + +MaterialFogMode_t CShaderAPIEmpty::GetSceneFogMode( ) +{ + return MATERIAL_FOG_NONE; +} + +int CShaderAPIEmpty::GetPixelFogCombo( ) +{ + return 0; +} + +void CShaderAPIEmpty::FogColor3f( float r, float g, float b ) +{ +} + +void CShaderAPIEmpty::FogColor3fv( float const* rgb ) +{ +} + +void CShaderAPIEmpty::FogColor3ub( unsigned char r, unsigned char g, unsigned char b ) +{ +} + +void CShaderAPIEmpty::FogColor3ubv( unsigned char const* rgb ) +{ +} + +void CShaderAPIEmpty::SetViewports( int nCount, const ShaderViewport_t* pViewports ) +{ +} + +int CShaderAPIEmpty::GetViewports( ShaderViewport_t* pViewports, int nMax ) const +{ + return 1; +} + +// Sets the vertex and pixel shaders +void CShaderAPIEmpty::SetVertexShaderIndex( int vshIndex ) +{ +} + +void CShaderAPIEmpty::SetPixelShaderIndex( int pshIndex ) +{ +} + +// Sets the constant registers for vertex and pixel shaders +void CShaderAPIEmpty::SetVertexShaderConstant( int var, float const* pVec, int numConst, bool bForce ) +{ +} + +void CShaderAPIEmpty::SetBooleanVertexShaderConstant( int var, BOOL const* pVec, int numConst, bool bForce ) +{ +} + +void CShaderAPIEmpty::SetIntegerVertexShaderConstant( int var, int const* pVec, int numConst, bool bForce ) +{ +} + +void CShaderAPIEmpty::SetPixelShaderConstant( int var, float const* pVec, int numConst, bool bForce ) +{ +} + +void CShaderAPIEmpty::SetBooleanPixelShaderConstant( int var, BOOL const* pVec, int numBools, bool bForce ) +{ +} + +void CShaderAPIEmpty::SetIntegerPixelShaderConstant( int var, int const* pVec, int numIntVecs, bool bForce ) +{ +} + +void CShaderAPIEmpty::InvalidateDelayedShaderConstants( void ) +{ +} + +float CShaderAPIEmpty::GammaToLinear_HardwareSpecific( float fGamma ) const +{ + return 0.0f; +} + +float CShaderAPIEmpty::LinearToGamma_HardwareSpecific( float fLinear ) const +{ + return 0.0f; +} + +void CShaderAPIEmpty::SetLinearToGammaConversionTextures( ShaderAPITextureHandle_t hSRGBWriteEnabledTexture, ShaderAPITextureHandle_t hIdentityTexture ) +{ +} + + +// Returns the nearest supported format +ImageFormat CShaderAPIEmpty::GetNearestSupportedFormat( ImageFormat fmt, bool bFilteringRequired /* = true */ ) const +{ + return fmt; +} + +ImageFormat CShaderAPIEmpty::GetNearestRenderTargetFormat( ImageFormat fmt ) const +{ + return fmt; +} + +// Sets the texture state +void CShaderAPIEmpty::BindTexture( Sampler_t stage, ShaderAPITextureHandle_t textureHandle ) +{ +} + +void CShaderAPIEmpty::ClearColor3ub( unsigned char r, unsigned char g, unsigned char b ) +{ +} + +void CShaderAPIEmpty::ClearColor4ub( unsigned char r, unsigned char g, unsigned char b, unsigned char a ) +{ +} + +// Indicates we're going to be modifying this texture +// TexImage2D, TexSubImage2D, TexWrap, TexMinFilter, and TexMagFilter +// all use the texture specified by this function. +void CShaderAPIEmpty::ModifyTexture( ShaderAPITextureHandle_t textureHandle ) +{ +} + +// Texture management methods +void CShaderAPIEmpty::TexImage2D( int level, int cubeFace, ImageFormat dstFormat, int zOffset, int width, int height, + ImageFormat srcFormat, bool bSrcIsTiled, void *imageData ) +{ +} + +void CShaderAPIEmpty::TexSubImage2D( int level, int cubeFace, int xOffset, int yOffset, int zOffset, int width, int height, + ImageFormat srcFormat, int srcStride, bool bSrcIsTiled, void *imageData ) +{ +} + +void CShaderAPIEmpty::TexImageFromVTF( IVTFTexture *pVTF, int iVTFFrame ) +{ +} + +bool CShaderAPIEmpty::TexLock( int level, int cubeFaceID, int xOffset, int yOffset, + int width, int height, CPixelWriter& writer ) +{ + return false; +} + +void CShaderAPIEmpty::TexUnlock( ) +{ +} + + +// These are bound to the texture, not the texture environment +void CShaderAPIEmpty::TexMinFilter( ShaderTexFilterMode_t texFilterMode ) +{ +} + +void CShaderAPIEmpty::TexMagFilter( ShaderTexFilterMode_t texFilterMode ) +{ +} + +void CShaderAPIEmpty::TexWrap( ShaderTexCoordComponent_t coord, ShaderTexWrapMode_t wrapMode ) +{ +} + +void CShaderAPIEmpty::TexSetPriority( int priority ) +{ +} + +ShaderAPITextureHandle_t CShaderAPIEmpty::CreateTexture( + int width, + int height, + int depth, + ImageFormat dstImageFormat, + int numMipLevels, + int numCopies, + int flags, + const char *pDebugName, + const char *pTextureGroupName ) +{ + return 0; +} + +// Create a multi-frame texture (equivalent to calling "CreateTexture" multiple times, but more efficient) +void CShaderAPIEmpty::CreateTextures( + ShaderAPITextureHandle_t *pHandles, + int count, + int width, + int height, + int depth, + ImageFormat dstImageFormat, + int numMipLevels, + int numCopies, + int flags, + const char *pDebugName, + const char *pTextureGroupName ) +{ + for ( int k = 0; k < count; ++ k ) + pHandles[ k ] = 0; +} + + +ShaderAPITextureHandle_t CShaderAPIEmpty::CreateDepthTexture( ImageFormat renderFormat, int width, int height, const char *pDebugName, bool bTexture ) +{ + return 0; +} + +void CShaderAPIEmpty::DeleteTexture( ShaderAPITextureHandle_t textureHandle ) +{ +} + +bool CShaderAPIEmpty::IsTexture( ShaderAPITextureHandle_t textureHandle ) +{ + return true; +} + +bool CShaderAPIEmpty::IsTextureResident( ShaderAPITextureHandle_t textureHandle ) +{ + return false; +} + +// stuff that isn't to be used from within a shader +void CShaderAPIEmpty::ClearBuffers( bool bClearColor, bool bClearDepth, bool bClearStencil, int renderTargetWidth, int renderTargetHeight ) +{ +} + +void CShaderAPIEmpty::ClearBuffersObeyStencil( bool bClearColor, bool bClearDepth ) +{ +} + +void CShaderAPIEmpty::ClearBuffersObeyStencilEx( bool bClearColor, bool bClearAlpha, bool bClearDepth ) +{ +} + +void CShaderAPIEmpty::PerformFullScreenStencilOperation( void ) +{ +} + +void CShaderAPIEmpty::SetScissorRect( const int nLeft, const int nTop, const int nRight, const int nBottom, const bool bEnableScissor ) +{ +} + +void CShaderAPIEmpty::ReadPixels( int x, int y, int width, int height, unsigned char *data, ImageFormat dstFormat ) +{ +} + +void CShaderAPIEmpty::ReadPixels( Rect_t *pSrcRect, Rect_t *pDstRect, unsigned char *data, ImageFormat dstFormat, int nDstStride ) +{ +} + +void CShaderAPIEmpty::FlushHardware() +{ +} + +void CShaderAPIEmpty::ResetRenderState( bool bFullReset ) +{ +} + +// Set the number of bone weights +void CShaderAPIEmpty::SetNumBoneWeights( int numBones ) +{ +} + +void CShaderAPIEmpty::EnableHWMorphing( bool bEnable ) +{ +} + +// Selection mode methods +int CShaderAPIEmpty::SelectionMode( bool selectionMode ) +{ + return 0; +} + +void CShaderAPIEmpty::SelectionBuffer( unsigned int* pBuffer, int size ) +{ +} + +void CShaderAPIEmpty::ClearSelectionNames( ) +{ +} + +void CShaderAPIEmpty::LoadSelectionName( int name ) +{ +} + +void CShaderAPIEmpty::PushSelectionName( int name ) +{ +} + +void CShaderAPIEmpty::PopSelectionName() +{ +} + + +// Use this to get the mesh builder that allows us to modify vertex data +CMeshBuilder* CShaderAPIEmpty::GetVertexModifyBuilder() +{ + return 0; +} + +// Board-independent calls, here to unify how shaders set state +// Implementations should chain back to IShaderUtil->BindTexture(), etc. + +// Use this to begin and end the frame +void CShaderAPIEmpty::BeginFrame() +{ +} + +void CShaderAPIEmpty::EndFrame() +{ +} + +// returns the current time in seconds.... +double CShaderAPIEmpty::CurrentTime() const +{ + return Sys_FloatTime(); +} + +// Get the current camera position in world space. +void CShaderAPIEmpty::GetWorldSpaceCameraPosition( float * pPos ) const +{ +} + +void CShaderAPIEmpty::ForceHardwareSync( void ) +{ +} + +void CShaderAPIEmpty::SetClipPlane( int index, const float *pPlane ) +{ +} + +void CShaderAPIEmpty::EnableClipPlane( int index, bool bEnable ) +{ +} + +void CShaderAPIEmpty::SetFastClipPlane( const float *pPlane ) +{ +} + +void CShaderAPIEmpty::EnableFastClip( bool bEnable ) +{ +} + +int CShaderAPIEmpty::GetCurrentNumBones( void ) const +{ + return 0; +} + +bool CShaderAPIEmpty::IsHWMorphingEnabled( void ) const +{ + return false; +} + +int CShaderAPIEmpty::GetCurrentLightCombo( void ) const +{ + return 0; +} + +void CShaderAPIEmpty::GetDX9LightState( LightState_t *state ) const +{ + state->m_nNumLights = 0; + state->m_bAmbientLight = false; + state->m_bStaticLightVertex = false; + state->m_bStaticLightTexel = false; +} + +MaterialFogMode_t CShaderAPIEmpty::GetCurrentFogType( void ) const +{ + return MATERIAL_FOG_NONE; +} + +void CShaderAPIEmpty::RecordString( const char *pStr ) +{ +} + +bool CShaderAPIEmpty::ReadPixelsFromFrontBuffer() const +{ + return true; +} + +bool CShaderAPIEmpty::PreferDynamicTextures() const +{ + return false; +} + +bool CShaderAPIEmpty::PreferReducedFillrate() const +{ + return false; +} + +bool CShaderAPIEmpty::HasProjectedBumpEnv() const +{ + return true; +} + +int CShaderAPIEmpty::GetCurrentDynamicVBSize( void ) +{ + return 0; +} + +void CShaderAPIEmpty::DestroyVertexBuffers( bool bExitingLevel ) +{ +} + +void CShaderAPIEmpty::EvictManagedResources() +{ +} + +void CShaderAPIEmpty::SetTextureTransformDimension( TextureStage_t textureStage, int dimension, bool projected ) +{ +} + +void CShaderAPIEmpty::SetBumpEnvMatrix( TextureStage_t textureStage, float m00, float m01, float m10, float m11 ) +{ +} + +void CShaderAPIEmpty::SyncToken( const char *pToken ) +{ +} diff --git a/materialsystem/shaderapiempty/shaderapiempty.vpc b/materialsystem/shaderapiempty/shaderapiempty.vpc new file mode 100644 index 0000000..fc7b9a9 --- /dev/null +++ b/materialsystem/shaderapiempty/shaderapiempty.vpc @@ -0,0 +1,38 @@ +//----------------------------------------------------------------------------- +// SHADEREMPTY.VPC +// +// Project Script +//----------------------------------------------------------------------------- + +$Macro SRCDIR "..\.." +$Macro OUTBINDIR "$SRCDIR\..\game\bin" + +$Include "$SRCDIR\vpc_scripts\source_dll_base.vpc" + +$Configuration +{ + $Compiler + { + $AdditionalIncludeDirectories "$BASE;..\" + $PreprocessorDefinitions "$BASE;SHADER_DLL_EXPORT;PROTECTED_THINGS_ENABLE" + } + + $Linker + { + $AdditionalDependencies "$BASE odbc32.lib odbccp32.lib" + $SystemLibraries "iconv" [$OSXALL] + } +} + +$Project "shaderapiempty" +{ + $Folder "Source Files" + { + $File "shaderapiempty.cpp" + } + + $Folder "Header Files" + { + $File "$SRCDIR\public\tier0\platform.h" + } +} diff --git a/materialsystem/shaderlib/BaseShader.cpp b/materialsystem/shaderlib/BaseShader.cpp new file mode 100644 index 0000000..dcd1cc0 --- /dev/null +++ b/materialsystem/shaderlib/BaseShader.cpp @@ -0,0 +1,1791 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//=====================================================================================// + +#include "shaderlib/BaseShader.h" +#include "shaderlib/ShaderDLL.h" +#include "tier0/dbg.h" +#include "shaderDLL_Global.h" +#include "IShaderSystem.h" +#include "materialsystem/imaterial.h" +#include "materialsystem/itexture.h" +#include "materialsystem/ishaderapi.h" +#include "materialsystem/materialsystem_config.h" +#include "shaderlib/cshader.h" +#include "mathlib/vmatrix.h" +#include "tier1/strtools.h" +#include "convar.h" +#include "tier0/vprof.h" + +// NOTE: This must be the last include file in a .cpp file! +#include "tier0/memdbgon.h" + + +//----------------------------------------------------------------------------- +// Globals +//----------------------------------------------------------------------------- +const char *CBaseShader::s_pTextureGroupName = NULL; +IMaterialVar **CBaseShader::s_ppParams; +IShaderShadow *CBaseShader::s_pShaderShadow; +IShaderDynamicAPI *CBaseShader::s_pShaderAPI; +IShaderInit *CBaseShader::s_pShaderInit; +int CBaseShader::s_nModulationFlags; +CMeshBuilder *CBaseShader::s_pMeshBuilder; +static ConVar mat_fullbright( "mat_fullbright","0", FCVAR_CHEAT ); + +bool g_shaderConfigDumpEnable = false; //true; //DO NOT CHECK IN ENABLED FIXME + +//----------------------------------------------------------------------------- +// constructor +//----------------------------------------------------------------------------- +CBaseShader::CBaseShader() +{ + GetShaderDLL()->InsertShader( this ); +} + + +//----------------------------------------------------------------------------- +// Shader parameter info +//----------------------------------------------------------------------------- +// Look in BaseShader.h for the enumeration for these. +// Update there if you update here. +static ShaderParamInfo_t s_StandardParams[NUM_SHADER_MATERIAL_VARS] = +{ + { "$flags", "flags", SHADER_PARAM_TYPE_INTEGER, "0", SHADER_PARAM_NOT_EDITABLE }, + { "$flags_defined", "flags_defined", SHADER_PARAM_TYPE_INTEGER, "0", SHADER_PARAM_NOT_EDITABLE }, + { "$flags2", "flags2", SHADER_PARAM_TYPE_INTEGER, "0", SHADER_PARAM_NOT_EDITABLE }, + { "$flags_defined2", "flags2_defined", SHADER_PARAM_TYPE_INTEGER, "0", SHADER_PARAM_NOT_EDITABLE }, + { "$color", "color", SHADER_PARAM_TYPE_COLOR, "[1 1 1]", 0 }, + { "$alpha", "alpha", SHADER_PARAM_TYPE_FLOAT, "1.0", 0 }, + { "$basetexture", "Base Texture with lighting built in", SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", 0 }, + { "$frame", "Animation Frame", SHADER_PARAM_TYPE_INTEGER, "0", 0 }, + { "$basetexturetransform", "Base Texture Texcoord Transform",SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", 0 }, + { "$flashlighttexture", "flashlight spotlight shape texture", SHADER_PARAM_TYPE_TEXTURE, "effects/flashlight001", SHADER_PARAM_NOT_EDITABLE }, + { "$flashlighttextureframe", "Animation Frame for $flashlight", SHADER_PARAM_TYPE_INTEGER, "0", SHADER_PARAM_NOT_EDITABLE }, + { "$color2", "color2", SHADER_PARAM_TYPE_COLOR, "[1 1 1]", 0 }, + { "$srgbtint", "tint value to be applied when running on new-style srgb parts", SHADER_PARAM_TYPE_COLOR, "[1 1 1]", 0 }, +}; + + +//----------------------------------------------------------------------------- +// Gets the standard shader parameter names +// FIXME: Turn this into one function? +//----------------------------------------------------------------------------- +int CBaseShader::GetNumParams( ) const +{ + return NUM_SHADER_MATERIAL_VARS; +} + +char const* CBaseShader::GetParamName( int nParamIndex ) const +{ + Assert( nParamIndex < NUM_SHADER_MATERIAL_VARS ); + return s_StandardParams[nParamIndex].m_pName; +} + +const char *CBaseShader::GetParamHelp( int nParamIndex ) const +{ + Assert( nParamIndex < NUM_SHADER_MATERIAL_VARS ); + return s_StandardParams[nParamIndex].m_pHelp; +} + +ShaderParamType_t CBaseShader::GetParamType( int nParamIndex ) const +{ + Assert( nParamIndex < NUM_SHADER_MATERIAL_VARS ); + return s_StandardParams[nParamIndex].m_Type; +} + +const char *CBaseShader::GetParamDefault( int nParamIndex ) const +{ + Assert( nParamIndex < NUM_SHADER_MATERIAL_VARS ); + return s_StandardParams[nParamIndex].m_pDefaultValue; +} + +int CBaseShader::GetParamFlags( int nParamIndex ) const +{ + Assert( nParamIndex < NUM_SHADER_MATERIAL_VARS ); + return s_StandardParams[nParamIndex].m_nFlags; +} + +//----------------------------------------------------------------------------- +// Necessary to snag ahold of some important data for the helper methods +//----------------------------------------------------------------------------- +void CBaseShader::InitShaderParams( IMaterialVar** ppParams, const char *pMaterialName ) +{ + // Re-entrancy check + Assert( !s_ppParams ); + + s_ppParams = ppParams; + + OnInitShaderParams( ppParams, pMaterialName ); + + s_ppParams = NULL; +} + +void CBaseShader::InitShaderInstance( IMaterialVar** ppParams, IShaderInit *pShaderInit, const char *pMaterialName, const char *pTextureGroupName ) +{ + // Re-entrancy check + Assert( !s_ppParams ); + + s_ppParams = ppParams; + s_pShaderInit = pShaderInit; + s_pTextureGroupName = pTextureGroupName; + + OnInitShaderInstance( ppParams, pShaderInit, pMaterialName ); + + s_pTextureGroupName = NULL; + s_ppParams = NULL; + s_pShaderInit = NULL; +} + +void CBaseShader::DrawElements( IMaterialVar **ppParams, int nModulationFlags, + IShaderShadow* pShaderShadow, IShaderDynamicAPI* pShaderAPI, VertexCompressionType_t vertexCompression, CBasePerMaterialContextData **pContextDataPtr ) +{ + VPROF("CBaseShader::DrawElements"); + // Re-entrancy check + Assert( !s_ppParams ); + + s_ppParams = ppParams; + s_pShaderAPI = pShaderAPI; + s_pShaderShadow = pShaderShadow; + s_nModulationFlags = nModulationFlags; + s_pMeshBuilder = pShaderAPI ? pShaderAPI->GetVertexModifyBuilder() : NULL; + + if ( IsSnapshotting() ) + { + // Set up the shadow state + SetInitialShadowState( ); + } + + OnDrawElements( ppParams, pShaderShadow, pShaderAPI, vertexCompression, pContextDataPtr ); + + s_nModulationFlags = 0; + s_ppParams = NULL; + s_pShaderAPI = NULL; + s_pShaderShadow = NULL; + s_pMeshBuilder = NULL; +} + + +//----------------------------------------------------------------------------- +// Sets the default shadow state +//----------------------------------------------------------------------------- +void CBaseShader::SetInitialShadowState( ) +{ + // Set the default state + s_pShaderShadow->SetDefaultState(); + + // Init the standard states... + int flags = s_ppParams[FLAGS]->GetIntValue(); + if (flags & MATERIAL_VAR_IGNOREZ) + { + s_pShaderShadow->EnableDepthTest( false ); + s_pShaderShadow->EnableDepthWrites( false ); + } + + if (flags & MATERIAL_VAR_DECAL) + { + s_pShaderShadow->EnablePolyOffset( SHADER_POLYOFFSET_DECAL ); + s_pShaderShadow->EnableDepthWrites( false ); + } + + if (flags & MATERIAL_VAR_NOCULL) + { + s_pShaderShadow->EnableCulling( false ); + } + + if (flags & MATERIAL_VAR_ZNEARER) + { + s_pShaderShadow->DepthFunc( SHADER_DEPTHFUNC_NEARER ); + } + + if (flags & MATERIAL_VAR_WIREFRAME) + { + s_pShaderShadow->PolyMode( SHADER_POLYMODEFACE_FRONT_AND_BACK, SHADER_POLYMODE_LINE ); + } + + // Set alpha to coverage + if (flags & MATERIAL_VAR_ALLOWALPHATOCOVERAGE) + { + // Force the bit on and then check against alpha blend and test states in CShaderShadowDX8::ComputeAggregateShadowState() + s_pShaderShadow->EnableAlphaToCoverage( true ); + } +} + + +//----------------------------------------------------------------------------- +// Draws a snapshot +//----------------------------------------------------------------------------- +void CBaseShader::Draw( bool bMakeActualDrawCall ) +{ + if ( IsSnapshotting() ) + { + // Turn off transparency if we're asked to.... + if (g_pConfig->bNoTransparency && + ((s_ppParams[FLAGS]->GetIntValue() & MATERIAL_VAR_NO_DEBUG_OVERRIDE) == 0)) + { + s_pShaderShadow->EnableDepthWrites( true ); + s_pShaderShadow->EnableBlending( false ); + } + + GetShaderSystem()->TakeSnapshot(); + } + else + { + GetShaderSystem()->DrawSnapshot( bMakeActualDrawCall ); + } +} + + +//----------------------------------------------------------------------------- +// Finds a particular parameter (works because the lowest parameters match the shader) +//----------------------------------------------------------------------------- +int CBaseShader::FindParamIndex( const char *pName ) const +{ + int numParams = GetNumParams(); + for( int i = 0; i < numParams; i++ ) + { + if( Q_strnicmp( GetParamName( i ), pName, 64 ) == 0 ) + { + return i; + } + } + return -1; +} + + +//----------------------------------------------------------------------------- +// Are we using graphics? +//----------------------------------------------------------------------------- +bool CBaseShader::IsUsingGraphics() +{ + return GetShaderSystem()->IsUsingGraphics(); +} + + +//----------------------------------------------------------------------------- +// Are we using graphics? +//----------------------------------------------------------------------------- +bool CBaseShader::CanUseEditorMaterials() +{ + return GetShaderSystem()->CanUseEditorMaterials(); +} + + +//----------------------------------------------------------------------------- +// Gets the builder... +//----------------------------------------------------------------------------- +CMeshBuilder* CBaseShader::MeshBuilder() +{ + return s_pMeshBuilder; +} + + +//----------------------------------------------------------------------------- +// Loads a texture +//----------------------------------------------------------------------------- +void CBaseShader::LoadTexture( int nTextureVar, int nAdditionalCreationFlags /* = 0 */ ) +{ + if ((!s_ppParams) || (nTextureVar == -1)) + return; + + IMaterialVar* pNameVar = s_ppParams[nTextureVar]; + if( pNameVar && pNameVar->IsDefined() ) + { + s_pShaderInit->LoadTexture( pNameVar, s_pTextureGroupName, nAdditionalCreationFlags ); + } +} + + +//----------------------------------------------------------------------------- +// Loads a bumpmap +//----------------------------------------------------------------------------- +void CBaseShader::LoadBumpMap( int nTextureVar ) +{ + if ((!s_ppParams) || (nTextureVar == -1)) + return; + + IMaterialVar* pNameVar = s_ppParams[nTextureVar]; + if( pNameVar && pNameVar->IsDefined() ) + { + s_pShaderInit->LoadBumpMap( pNameVar, s_pTextureGroupName ); + } +} + + +//----------------------------------------------------------------------------- +// Loads a cubemap +//----------------------------------------------------------------------------- +void CBaseShader::LoadCubeMap( int nTextureVar, int nAdditionalCreationFlags /* = 0 */ ) +{ + if ((!s_ppParams) || (nTextureVar == -1)) + return; + + IMaterialVar* pNameVar = s_ppParams[nTextureVar]; + if( pNameVar && pNameVar->IsDefined() ) + { + s_pShaderInit->LoadCubeMap( s_ppParams, pNameVar, nAdditionalCreationFlags ); + } +} + + +ShaderAPITextureHandle_t CBaseShader::GetShaderAPITextureBindHandle( int nTextureVar, int nFrameVar, int nTextureChannel ) +{ +// Assert( !IsSnapshotting() ); + Assert( nTextureVar != -1 ); + Assert ( s_ppParams ); + + IMaterialVar* pTextureVar = s_ppParams[nTextureVar]; + IMaterialVar* pFrameVar = (nFrameVar != -1) ? s_ppParams[nFrameVar] : NULL; + int nFrame = pFrameVar ? pFrameVar->GetIntValue() : 0; + return GetShaderSystem()->GetShaderAPITextureBindHandle( pTextureVar->GetTextureValue(), nFrame, nTextureChannel ); +} + + +//----------------------------------------------------------------------------- +// Four different flavors of BindTexture(), handling the two-sampler +// case as well as ITexture* versus textureVar forms +//----------------------------------------------------------------------------- + +void CBaseShader::BindTexture( Sampler_t sampler1, int nTextureVar, int nFrameVar /* = -1 */ ) +{ + BindTexture( sampler1, (Sampler_t) -1, nTextureVar, nFrameVar ); +} + + +void CBaseShader::BindTexture( Sampler_t sampler1, Sampler_t sampler2, int nTextureVar, int nFrameVar /* = -1 */ ) +{ + Assert( !IsSnapshotting() ); + Assert( nTextureVar != -1 ); + Assert ( s_ppParams ); + + IMaterialVar* pTextureVar = s_ppParams[nTextureVar]; + IMaterialVar* pFrameVar = (nFrameVar != -1) ? s_ppParams[nFrameVar] : NULL; + if (pTextureVar) + { + int nFrame = pFrameVar ? pFrameVar->GetIntValue() : 0; + + if ( sampler2 == Sampler_t(-1) ) + { + GetShaderSystem()->BindTexture( sampler1, pTextureVar->GetTextureValue(), nFrame ); + } + else + { + GetShaderSystem()->BindTexture( sampler1, sampler2, pTextureVar->GetTextureValue(), nFrame ); + } + } +} + + +void CBaseShader::BindTexture( Sampler_t sampler1, ITexture *pTexture, int nFrame /* = 0 */ ) +{ + BindTexture( sampler1, (Sampler_t) -1, pTexture, nFrame ); +} + +void CBaseShader::BindTexture( Sampler_t sampler1, Sampler_t sampler2, ITexture *pTexture, int nFrame /* = 0 */ ) +{ + Assert( !IsSnapshotting() ); + + if ( sampler2 == Sampler_t(-1 ) ) + { + GetShaderSystem()->BindTexture( sampler1, pTexture, nFrame ); + } + else + { + GetShaderSystem()->BindTexture( sampler1, sampler2, pTexture, nFrame ); + } +} + +void CBaseShader::GetTextureDimensions( float* pOutWidth, float* pOutHeight, int nTextureVar ) +{ + Assert( pOutWidth && pOutHeight ); // Outputs must be provided. + Assert( nTextureVar != -1 ); + + IMaterialVar* pTextureVar = s_ppParams[nTextureVar]; + + if (pTextureVar && pTextureVar->GetTextureValue()) + { + *pOutWidth = (float) (pTextureVar->GetTextureValue()->GetActualWidth()); + *pOutHeight = (float) (pTextureVar->GetTextureValue()->GetActualHeight()); + } +} + + +//----------------------------------------------------------------------------- +// Does the texture store translucency in its alpha channel? +//----------------------------------------------------------------------------- +bool CBaseShader::TextureIsTranslucent( int textureVar, bool isBaseTexture ) +{ + if (textureVar < 0) + return false; + + IMaterialVar** params = s_ppParams; + if (params[textureVar]->GetType() == MATERIAL_VAR_TYPE_TEXTURE) + { + if (!isBaseTexture) + { + return params[textureVar]->GetTextureValue()->IsTranslucent(); + } + else + { + // Override translucency settings if this flag is set. + if (IS_FLAG_SET(MATERIAL_VAR_OPAQUETEXTURE)) + return false; + + if ( (CurrentMaterialVarFlags() & (MATERIAL_VAR_SELFILLUM | MATERIAL_VAR_BASEALPHAENVMAPMASK)) == 0) + { + if ((CurrentMaterialVarFlags() & MATERIAL_VAR_TRANSLUCENT) || + (CurrentMaterialVarFlags() & MATERIAL_VAR_ALPHATEST)) + { + return params[textureVar]->GetTextureValue()->IsTranslucent(); + } + } + } + } + + return false; +} + + +//----------------------------------------------------------------------------- +// +// Helper methods for color modulation +// +//----------------------------------------------------------------------------- + + +//----------------------------------------------------------------------------- +// Are we alpha or color modulating? +//----------------------------------------------------------------------------- +bool CBaseShader::IsAlphaModulating() +{ + return (s_nModulationFlags & SHADER_USING_ALPHA_MODULATION) != 0; +} + +bool CBaseShader::IsColorModulating() +{ + return (s_nModulationFlags & SHADER_USING_COLOR_MODULATION) != 0; +} + + +void CBaseShader::GetColorParameter( IMaterialVar **params, float *pColorOut ) const +{ + float flColor2[3]; + params[COLOR]->GetVecValue( pColorOut, 3 ); + params[COLOR2]->GetVecValue( flColor2, 3 ); + + pColorOut[0] *= flColor2[0]; + pColorOut[1] *= flColor2[1]; + pColorOut[2] *= flColor2[2]; + + if ( g_pHardwareConfig->UsesSRGBCorrectBlending() ) + { + float flSRGBTint[3]; + params[SRGBTINT]->GetVecValue( flSRGBTint, 3 ); + + pColorOut[0] *= flSRGBTint[0]; + pColorOut[1] *= flSRGBTint[1]; + pColorOut[2] *= flSRGBTint[2]; + } + +} + +//----------------------------------------------------------------------------- +// FIXME: Figure out a better way to do this? +//----------------------------------------------------------------------------- +int CBaseShader::ComputeModulationFlags( IMaterialVar** params, IShaderDynamicAPI* pShaderAPI ) +{ + s_pShaderAPI = pShaderAPI; + + int mod = 0; + if ( GetAlpha(params) < 1.0f ) + { + mod |= SHADER_USING_ALPHA_MODULATION; + } + + float color[3]; + GetColorParameter( params, color ); + + if ((color[0] != 1.0) || (color[1] != 1.0) || (color[2] != 1.0)) + { + mod |= SHADER_USING_COLOR_MODULATION; + } + + if( UsingFlashlight(params) ) + { + mod |= SHADER_USING_FLASHLIGHT; + } + + if ( UsingEditor(params) ) + { + mod |= SHADER_USING_EDITOR; + } + + if( IS_FLAG2_SET( MATERIAL_VAR2_USE_FIXED_FUNCTION_BAKED_LIGHTING ) ) + { + AssertOnce( IS_FLAG2_SET( MATERIAL_VAR2_NEEDS_BAKED_LIGHTING_SNAPSHOTS ) ); + if( IS_FLAG2_SET( MATERIAL_VAR2_NEEDS_BAKED_LIGHTING_SNAPSHOTS ) ) + { + mod |= SHADER_USING_FIXED_FUNCTION_BAKED_LIGHTING; + } + } + + s_pShaderAPI = NULL; + + return mod; +} + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +bool CBaseShader::NeedsPowerOfTwoFrameBufferTexture( IMaterialVar **params, bool bCheckSpecificToThisFrame ) const +{ + return CShader_IsFlag2Set( params, MATERIAL_VAR2_NEEDS_POWER_OF_TWO_FRAME_BUFFER_TEXTURE ); +} + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +bool CBaseShader::NeedsFullFrameBufferTexture( IMaterialVar **params, bool bCheckSpecificToThisFrame ) const +{ + return CShader_IsFlag2Set( params, MATERIAL_VAR2_NEEDS_FULL_FRAME_BUFFER_TEXTURE ); +} + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +bool CBaseShader::IsTranslucent( IMaterialVar **params ) const +{ + return IS_FLAG_SET( MATERIAL_VAR_TRANSLUCENT ); +} + +//----------------------------------------------------------------------------- +// Returns the translucency... +//----------------------------------------------------------------------------- +float CBaseShader::GetAlpha( IMaterialVar** ppParams ) +{ + if ( !ppParams ) + { + ppParams = s_ppParams; + } + + if (!ppParams) + return 1.0f; + + if ( ppParams[FLAGS]->GetIntValue() & MATERIAL_VAR_NOALPHAMOD ) + return 1.0f; + + float flAlpha = ppParams[ALPHA]->GetFloatValue(); + return clamp( flAlpha, 0.0f, 1.0f ); +} + + +//----------------------------------------------------------------------------- +// Sets the color + transparency +//----------------------------------------------------------------------------- +void CBaseShader::SetColorState( int colorVar, bool setAlpha ) +{ + Assert( !IsSnapshotting() ); + if ( !s_ppParams ) + return; + + // Use tint instead of color if it was specified... + IMaterialVar* pColorVar = (colorVar != -1) ? s_ppParams[colorVar] : 0; + + float color[4] = { 1.0, 1.0, 1.0, 1.0 }; + if (pColorVar) + { + if (pColorVar->GetType() == MATERIAL_VAR_TYPE_VECTOR) + { + pColorVar->GetVecValue( color, 3 ); + } + else + { + color[0] = color[1] = color[2] = pColorVar->GetFloatValue(); + } + + if ( !g_pHardwareConfig->SupportsPixelShaders_1_4() ) // Clamp 0..1 for ps_1_1 and below + { + color[0] = clamp( color[0], 0.0f, 1.0f ); + color[1] = clamp( color[1], 0.0f, 1.0f ); + color[2] = clamp( color[2], 0.0f, 1.0f ); + } + else if ( !g_pHardwareConfig->SupportsPixelShaders_2_0() ) // Clamp 0..8 for ps_1_4 + { + color[0] = clamp( color[0], 0.0f, 8.0f ); + color[1] = clamp( color[1], 0.0f, 8.0f ); + color[2] = clamp( color[2], 0.0f, 8.0f ); + } + } + ApplyColor2Factor( color ); + color[3] = setAlpha ? GetAlpha() : 1.0f; + s_pShaderAPI->Color4fv( color ); +} + + +void CBaseShader::SetModulationShadowState( int tintVar ) +{ + // Have have no control over the tint var... + bool doModulation = (tintVar != -1); + + // We activate color modulating when we're alpha or color modulating + doModulation = doModulation || IsAlphaModulating() || IsColorModulating(); + + s_pShaderShadow->EnableConstantColor( doModulation ); +} + +void CBaseShader::SetModulationDynamicState( int tintVar ) +{ + if (tintVar != -1) + { + SetColorState( tintVar, true ); + } + else + { + SetColorState( COLOR, true ); + } +} + +void CBaseShader::ApplyColor2Factor( float *pColorOut ) const // (*pColorOut) *= COLOR2 +{ + IMaterialVar* pColor2Var = s_ppParams[COLOR2]; + if (pColor2Var->GetType() == MATERIAL_VAR_TYPE_VECTOR) + { + float flColor2[3]; + pColor2Var->GetVecValue( flColor2, 3 ); + + pColorOut[0] *= flColor2[0]; + pColorOut[1] *= flColor2[1]; + pColorOut[2] *= flColor2[2]; + } + if ( g_pHardwareConfig->UsesSRGBCorrectBlending() ) + { + IMaterialVar* pSRGBVar = s_ppParams[SRGBTINT]; + if (pSRGBVar->GetType() == MATERIAL_VAR_TYPE_VECTOR) + { + float flSRGB[3]; + pSRGBVar->GetVecValue( flSRGB, 3 ); + + pColorOut[0] *= flSRGB[0]; + pColorOut[1] *= flSRGB[1]; + pColorOut[2] *= flSRGB[2]; + } + } +} + +void CBaseShader::ComputeModulationColor( float* color ) +{ + Assert( !IsSnapshotting() ); + if (!s_ppParams) + return; + + IMaterialVar* pColorVar = s_ppParams[COLOR]; + if (pColorVar->GetType() == MATERIAL_VAR_TYPE_VECTOR) + { + pColorVar->GetVecValue( color, 3 ); + } + else + { + color[0] = color[1] = color[2] = pColorVar->GetFloatValue(); + } + + ApplyColor2Factor( color ); + + if( !g_pConfig->bShowDiffuse ) + { + color[0] = color[1] = color[2] = 0.0f; + } + if( mat_fullbright.GetInt() == 2 ) + { + color[0] = color[1] = color[2] = 1.0f; + } + color[3] = GetAlpha(); +} + + +//----------------------------------------------------------------------------- +// +// Helper methods for alpha blending.... +// +//----------------------------------------------------------------------------- +void CBaseShader::EnableAlphaBlending( ShaderBlendFactor_t src, ShaderBlendFactor_t dst ) +{ + Assert( IsSnapshotting() ); + s_pShaderShadow->EnableBlending( true ); + s_pShaderShadow->BlendFunc( src, dst ); + s_pShaderShadow->EnableDepthWrites(false); +} + +void CBaseShader::DisableAlphaBlending() +{ + Assert( IsSnapshotting() ); + s_pShaderShadow->EnableBlending( false ); +} + +void CBaseShader::SetNormalBlendingShadowState( int textureVar, bool isBaseTexture ) +{ + Assert( IsSnapshotting() ); + + // Either we've got a constant modulation + bool isTranslucent = IsAlphaModulating(); + + // Or we've got a vertex alpha + isTranslucent = isTranslucent || (CurrentMaterialVarFlags() & MATERIAL_VAR_VERTEXALPHA); + + // Or we've got a texture alpha + isTranslucent = isTranslucent || ( TextureIsTranslucent( textureVar, isBaseTexture ) && + !(CurrentMaterialVarFlags() & MATERIAL_VAR_ALPHATEST ) ); + + if (isTranslucent) + { + EnableAlphaBlending( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA ); + } + else + { + DisableAlphaBlending(); + } +} + +//ConVar mat_debug_flashlight_only( "mat_debug_flashlight_only", "0" ); +void CBaseShader::SetAdditiveBlendingShadowState( int textureVar, bool isBaseTexture ) +{ + Assert( IsSnapshotting() ); + + // Either we've got a constant modulation + bool isTranslucent = IsAlphaModulating(); + + // Or we've got a vertex alpha + isTranslucent = isTranslucent || (CurrentMaterialVarFlags() & MATERIAL_VAR_VERTEXALPHA); + + // Or we've got a texture alpha + isTranslucent = isTranslucent || ( TextureIsTranslucent( textureVar, isBaseTexture ) && + !(CurrentMaterialVarFlags() & MATERIAL_VAR_ALPHATEST ) ); + + /* + if ( mat_debug_flashlight_only.GetBool() ) + { + if (isTranslucent) + { + EnableAlphaBlending( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA); + //s_pShaderShadow->EnableAlphaTest( true ); + //s_pShaderShadow->AlphaFunc( SHADER_ALPHAFUNC_GREATER, 0.99f ); + } + else + { + EnableAlphaBlending( SHADER_BLEND_ONE, SHADER_BLEND_ZERO); + } + } + else + */ + { + if (isTranslucent) + { + EnableAlphaBlending( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE ); + } + else + { + EnableAlphaBlending( SHADER_BLEND_ONE, SHADER_BLEND_ONE ); + } + } +} + +void CBaseShader::SetDefaultBlendingShadowState( int textureVar, bool isBaseTexture ) +{ + if ( CurrentMaterialVarFlags() & MATERIAL_VAR_ADDITIVE ) + { + SetAdditiveBlendingShadowState( textureVar, isBaseTexture ); + } + else + { + SetNormalBlendingShadowState( textureVar, isBaseTexture ); + } +} + +void CBaseShader::SetBlendingShadowState( BlendType_t nMode ) +{ + switch ( nMode ) + { + case BT_NONE: + DisableAlphaBlending(); + break; + + case BT_BLEND: + EnableAlphaBlending( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA ); + break; + + case BT_ADD: + EnableAlphaBlending( SHADER_BLEND_ONE, SHADER_BLEND_ONE ); + break; + + case BT_BLENDADD: + EnableAlphaBlending( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE ); + break; + } +} + + + +//----------------------------------------------------------------------------- +// Sets lightmap blending mode for single texturing +//----------------------------------------------------------------------------- +void CBaseShader::SingleTextureLightmapBlendMode( ) +{ + Assert( IsSnapshotting() ); + + s_pShaderShadow->EnableBlending( true ); + s_pShaderShadow->BlendFunc( SHADER_BLEND_DST_COLOR, SHADER_BLEND_SRC_COLOR ); +} + + +//----------------------------------------------------------------------------- +// Loads the identity transform into a matrix +//----------------------------------------------------------------------------- +void CBaseShader::LoadIdentity( MaterialMatrixMode_t matrixMode ) +{ + Assert( !IsSnapshotting() ); + + s_pShaderAPI->MatrixMode( matrixMode ); + s_pShaderAPI->LoadIdentity( ); +} + + +//----------------------------------------------------------------------------- +// Loads the camera to world transform into a matrix +//----------------------------------------------------------------------------- +void CBaseShader::LoadCameraToWorldTransform( MaterialMatrixMode_t matrixMode ) +{ + s_pShaderAPI->MatrixMode( matrixMode ); + s_pShaderAPI->LoadCameraToWorld(); +} + +void CBaseShader::LoadCameraSpaceSphereMapTransform( MaterialMatrixMode_t matrixMode ) +{ + static float mat[4][4] = + { + { 0.5f, 0.0f, 0.0f, 0.0f }, + { 0.0f, -0.5f, 0.0f, 0.0f }, + { 0.0f, 0.0f, 0.0f, 0.0f }, + { 0.5f, -0.5f, 0.0f, 1.0f }, + }; + + s_pShaderAPI->MatrixMode( matrixMode ); + s_pShaderAPI->LoadMatrix( (float*)mat ); +} + + +//----------------------------------------------------------------------------- +// +// Sets a texture translation transform +// +//----------------------------------------------------------------------------- +void CBaseShader::SetFixedFunctionTextureTranslation( MaterialMatrixMode_t textureTransform, int translationVar ) +{ + Assert( !IsSnapshotting() ); + + // handle scrolling of base texture + Vector2D vDelta( 0, 0 ); + + if (translationVar != -1) + { + s_ppParams[translationVar]->GetVecValue( vDelta.Base(), 2 ); + } + + if( vDelta[0] != 0.0f || vDelta[1] != 0.0f ) + { + s_pShaderAPI->MatrixMode( textureTransform ); + + // only do the upper 3x3 since this is a 2D matrix + float mat[16]; + mat[0] = 1.0f; mat[1] = 0.0f; mat[2] = 0.0f; + mat[4] = 0.0f; mat[5] = 1.0f; mat[6] = 0.0f; + mat[8] = vDelta[0]; mat[9] = vDelta[1]; mat[10] = 1.0f; + + // Better set the stuff we don't set with some sort of value! + mat[3] = mat[7] = mat[11] = 0; + mat[12] = mat[13] = mat[14] = 0; + mat[15] = 1; + + s_pShaderAPI->LoadMatrix( mat ); + } + else + { + LoadIdentity( textureTransform ); + } +} + +void CBaseShader::SetFixedFunctionTextureScale( MaterialMatrixMode_t textureTransform, int scaleVar ) +{ + Assert( !IsSnapshotting() ); + + // handle scrolling of base texture + Vector2D vScale; + s_ppParams[scaleVar]->GetVecValue( vScale.Base(), 2 ); + if( vScale[0] != 0.0f || vScale[1] != 0.0f ) + { + s_pShaderAPI->MatrixMode( textureTransform ); + + // only do the upper 3x3 since this is a 2D matrix + float mat[16]; + mat[0] = vScale[0]; mat[1] = 0.0f; mat[2] = 0.0f; + mat[4] = 0.0f; mat[5] = vScale[1]; mat[6] = 0.0f; + mat[8] = 0.0f; mat[9] = 0.0f; mat[10] = 1.0f; + + // Better set the stuff we don't set with some sort of value! + mat[3] = mat[7] = mat[11] = 0; + mat[12] = mat[13] = mat[14] = 0; + mat[15] = 1; + + s_pShaderAPI->LoadMatrix( mat ); + } + else + { + LoadIdentity( textureTransform ); + } +} + +void CBaseShader::SetFixedFunctionTextureTransform( MaterialMatrixMode_t textureTransform, int transformVar ) +{ + Assert( !IsSnapshotting() ); + + IMaterialVar* pTransformationVar = s_ppParams[transformVar]; + if (pTransformationVar && (pTransformationVar->GetType() == MATERIAL_VAR_TYPE_MATRIX)) + { + s_pShaderAPI->MatrixMode( textureTransform ); + + const VMatrix &transformation = pTransformationVar->GetMatrixValue(); + + // only do the upper 3x3 since this is a 2D matrix + float mat[16]; + mat[0] = transformation[0][0]; mat[1] = transformation[1][0]; mat[2] = transformation[3][0]; + mat[4] = transformation[0][1]; mat[5] = transformation[1][1]; mat[6] = transformation[3][1]; + mat[8] = transformation[0][3]; mat[9] = transformation[1][3]; mat[10] = transformation[3][3]; + + // Better set the stuff we don't set with some sort of value! + mat[3] = mat[7] = mat[11] = 0; + mat[12] = mat[13] = mat[14] = 0; + mat[15] = 1; + + s_pShaderAPI->LoadMatrix( mat ); + } + else + { + LoadIdentity( textureTransform ); + } +} + +void CBaseShader::SetFixedFunctionTextureScaledTransform( MaterialMatrixMode_t textureTransform, + int transformVar, int scaleVar ) +{ + Assert( !IsSnapshotting() ); + + float mat[16]; + IMaterialVar* pTransformationVar = s_ppParams[transformVar]; + if (pTransformationVar && (pTransformationVar->GetType() == MATERIAL_VAR_TYPE_MATRIX)) + { + Vector2D scale( 1, 1 ); + IMaterialVar* pScaleVar = s_ppParams[scaleVar]; + if (pScaleVar) + { + if (pScaleVar->GetType() == MATERIAL_VAR_TYPE_VECTOR) + pScaleVar->GetVecValue( scale.Base(), 2 ); + else if (pScaleVar->IsDefined()) + scale[0] = scale[1] = pScaleVar->GetFloatValue(); + } + + s_pShaderAPI->MatrixMode( textureTransform ); + + const VMatrix &transformation = pTransformationVar->GetMatrixValue(); + + // only do the upper 3x3 since this is a 2D matrix + mat[0] = transformation[0][0] * scale[0]; mat[1] = transformation[1][0] * scale[0]; mat[2] = transformation[3][0] * scale[0]; + mat[4] = transformation[0][1] * scale[1]; mat[5] = transformation[1][1] * scale[1]; mat[6] = transformation[3][1] * scale[1]; + mat[8] = transformation[0][3]; mat[9] = transformation[1][3]; mat[10] = transformation[3][3]; + + // Better set the stuff we don't set with some sort of value! + mat[3] = mat[7] = mat[11] = 0; + mat[12] = mat[13] = mat[14] = 0; + mat[15] = 1; + + s_pShaderAPI->LoadMatrix( mat ); + } + else + { + SetFixedFunctionTextureScale( textureTransform, scaleVar ); + } +} + + +//----------------------------------------------------------------------------- +// +// Helper methods for fog +// +//----------------------------------------------------------------------------- +void CBaseShader::FogToOOOverbright( void ) +{ + Assert( IsSnapshotting() ); + if (( CurrentMaterialVarFlags() & MATERIAL_VAR_NOFOG ) == 0) + { + s_pShaderShadow->FogMode( SHADER_FOGMODE_OO_OVERBRIGHT ); + } + else + { + s_pShaderShadow->FogMode( SHADER_FOGMODE_DISABLED ); + } +} + +void CBaseShader::FogToWhite( void ) +{ + Assert( IsSnapshotting() ); + if (( CurrentMaterialVarFlags() & MATERIAL_VAR_NOFOG ) == 0) + { + s_pShaderShadow->FogMode( SHADER_FOGMODE_WHITE ); + } + else + { + s_pShaderShadow->FogMode( SHADER_FOGMODE_DISABLED ); + } +} +void CBaseShader::FogToBlack( void ) +{ + Assert( IsSnapshotting() ); + if (( CurrentMaterialVarFlags() & MATERIAL_VAR_NOFOG ) == 0) + { + s_pShaderShadow->FogMode( SHADER_FOGMODE_BLACK ); + } + else + { + s_pShaderShadow->FogMode( SHADER_FOGMODE_DISABLED ); + } +} + +void CBaseShader::FogToGrey( void ) +{ + Assert( IsSnapshotting() ); + if (( CurrentMaterialVarFlags() & MATERIAL_VAR_NOFOG ) == 0) + { + s_pShaderShadow->FogMode( SHADER_FOGMODE_GREY ); + } + else + { + s_pShaderShadow->FogMode( SHADER_FOGMODE_DISABLED ); + } +} + +void CBaseShader::FogToFogColor( void ) +{ + Assert( IsSnapshotting() ); + if (( CurrentMaterialVarFlags() & MATERIAL_VAR_NOFOG ) == 0) + { + s_pShaderShadow->FogMode( SHADER_FOGMODE_FOGCOLOR ); + } + else + { + s_pShaderShadow->FogMode( SHADER_FOGMODE_DISABLED ); + } +} + +void CBaseShader::DisableFog( void ) +{ + Assert( IsSnapshotting() ); + s_pShaderShadow->FogMode( SHADER_FOGMODE_DISABLED ); +} + +void CBaseShader::DefaultFog( void ) +{ + if ( CurrentMaterialVarFlags() & MATERIAL_VAR_ADDITIVE ) + { + FogToBlack(); + } + else + { + FogToFogColor(); + } +} + + +//----------------------------------------------------------------------------- +// Fixed function multiply by detail texture pass +//----------------------------------------------------------------------------- +void CBaseShader::FixedFunctionMultiplyByDetailPass( int baseTextureVar, int frameVar, + int textureTransformVar, int detailVar, int detailScaleVar ) +{ + IMaterialVar** params = s_ppParams; + + if (!params[detailVar]->IsDefined()) + return; + + if (IsSnapshotting()) + { + SetInitialShadowState(); + + s_pShaderShadow->EnableAlphaTest( IS_FLAG_SET(MATERIAL_VAR_ALPHATEST) ); + + bool translucentTexture = TextureIsTranslucent( baseTextureVar, true ) || + IS_FLAG_SET(MATERIAL_VAR_ALPHATEST); + s_pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + s_pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + s_pShaderShadow->EnableTexGen( SHADER_TEXTURE_STAGE0, false ); + s_pShaderShadow->EnableTexGen( SHADER_TEXTURE_STAGE1, false ); + + // Mod 2x blend here + EnableAlphaBlending( SHADER_BLEND_DST_COLOR, SHADER_BLEND_SRC_COLOR ); + + s_pShaderShadow->EnableCustomPixelPipe( true ); + s_pShaderShadow->CustomTextureStages( 2 ); + + // We need to blend towards grey based on alpha... + // We can never get the perfect alpha (vertex alpha * cc alpha * texture alpha) + // so we'll just choose to use cc alpha * texture alpha + + int flags = SHADER_DRAW_POSITION | SHADER_DRAW_TEXCOORD1; + + // Compute alpha, stage 0 is used, stage 1 isn't. + if ( translucentTexture ) + { + s_pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE0, + SHADER_TEXCHANNEL_ALPHA, SHADER_TEXOP_MODULATE, + SHADER_TEXARG_TEXTURE, SHADER_TEXARG_CONSTANTCOLOR ); + flags |= SHADER_DRAW_TEXCOORD0; + } + else + { + bool hasVertexAlpha = (CurrentMaterialVarFlags() & MATERIAL_VAR_VERTEXALPHA) != 0; + if (hasVertexAlpha) + { + flags |= SHADER_DRAW_COLOR; + } + + s_pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE0, + SHADER_TEXCHANNEL_ALPHA, hasVertexAlpha ? SHADER_TEXOP_MODULATE : SHADER_TEXOP_SELECTARG1, + SHADER_TEXARG_CONSTANTCOLOR, SHADER_TEXARG_VERTEXCOLOR ); + } + + s_pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE1, + SHADER_TEXCHANNEL_ALPHA, SHADER_TEXOP_SELECTARG1, + SHADER_TEXARG_PREVIOUSSTAGE, SHADER_TEXARG_NONE ); + + // This here will perform color = vertex light * alpha + 0.5f * (1 - alpha) + // Stage 0 really doesn't do anything + s_pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE0, + SHADER_TEXCHANNEL_COLOR, SHADER_TEXOP_SELECTARG1, + SHADER_TEXARG_TEXTURE, SHADER_TEXARG_CONSTANTCOLOR ); + + s_pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE1, + SHADER_TEXCHANNEL_COLOR, SHADER_TEXOP_BLEND_PREVIOUSSTAGEALPHA, + SHADER_TEXARG_TEXTURE, SHADER_TEXARG_CONSTANTCOLOR ); + + s_pShaderShadow->DrawFlags( flags ); + FogToGrey(); + Draw( ); + + s_pShaderShadow->EnableCustomPixelPipe( false ); + DisableAlphaBlending(); + } + else + { + if (TextureIsTranslucent( baseTextureVar, true ) ) + { + SetFixedFunctionTextureTransform( MATERIAL_TEXTURE0, textureTransformVar ); + BindTexture( SHADER_SAMPLER0, baseTextureVar, frameVar ); + } + else + { + // Unnecessary... but we get strange colors if we don't put something on stage 0 + BindTexture( SHADER_SAMPLER0, detailVar, frameVar ); + } + + BindTexture( SHADER_SAMPLER1, detailVar, frameVar ); + SetFixedFunctionTextureScaledTransform( MATERIAL_TEXTURE1, textureTransformVar, detailScaleVar ); + float alpha = GetAlpha(); + s_pShaderAPI->Color4ub( 128, 128, 128, 255 * alpha ); + + Draw( ); + } +} + + +//----------------------------------------------------------------------------- +// Multiply by lightmap pass +//----------------------------------------------------------------------------- +void CBaseShader::FixedFunctionMultiplyByLightmapPass( int baseTextureVar, + int frameVar, int baseTextureTransformVar, float alphaOverride ) +{ + if (IsSnapshotting()) + { + SetInitialShadowState(); + + s_pShaderShadow->EnableAlphaTest( false ); + + s_pShaderShadow->EnableBlending( true ); + SingleTextureLightmapBlendMode(); + + s_pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + s_pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + s_pShaderShadow->EnableTexGen( SHADER_TEXTURE_STAGE0, false ); + s_pShaderShadow->EnableTexGen( SHADER_TEXTURE_STAGE1, false ); + + s_pShaderShadow->EnableCustomPixelPipe( true ); + s_pShaderShadow->CustomTextureStages( 2 ); + + // Stage zero color is not used, this op doesn't matter + s_pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE0, + SHADER_TEXCHANNEL_COLOR, SHADER_TEXOP_SELECTARG1, + SHADER_TEXARG_CONSTANTCOLOR, SHADER_TEXARG_CONSTANTCOLOR ); + + // This here will perform color = lightmap * (cc alpha) + 1 * (1- cc alpha) + s_pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE1, + SHADER_TEXCHANNEL_COLOR, SHADER_TEXOP_BLEND_PREVIOUSSTAGEALPHA, + SHADER_TEXARG_TEXTURE, SHADER_TEXARG_CONSTANTCOLOR ); + + int flags = SHADER_DRAW_POSITION | SHADER_DRAW_LIGHTMAP_TEXCOORD1; + + // Multiply the constant alpha by the texture alpha for total alpha + if (TextureIsTranslucent(baseTextureVar, true)) + { + s_pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE0, + SHADER_TEXCHANNEL_ALPHA, SHADER_TEXOP_MODULATE, + SHADER_TEXARG_TEXTURE, SHADER_TEXARG_CONSTANTCOLOR ); + + flags |= SHADER_DRAW_TEXCOORD0; + } + else + { + s_pShaderShadow->EnableTexture( SHADER_SAMPLER0, false ); + s_pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE0, + SHADER_TEXCHANNEL_ALPHA, SHADER_TEXOP_SELECTARG2, + SHADER_TEXARG_TEXTURE, SHADER_TEXARG_CONSTANTCOLOR ); + } + + // Alpha isn't used, it doesn't matter what we set it to. + s_pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE1, + SHADER_TEXCHANNEL_ALPHA, SHADER_TEXOP_SELECTARG1, + SHADER_TEXARG_PREVIOUSSTAGE, SHADER_TEXARG_NONE ); + + s_pShaderShadow->DrawFlags( flags ); + + FogToOOOverbright(); + Draw(); + + s_pShaderShadow->EnableCustomPixelPipe( false ); + } + else + { + s_pShaderAPI->SetDefaultState(); + + // Put the alpha in the color channel to modulate the color down.... + float alpha = (alphaOverride < 0) ? GetAlpha() : alphaOverride; + + // NOTE: 128 is a more exact OO_OVERBRIGHT; it prevents some artifacts +// s_pShaderAPI->Color4f( OO_OVERBRIGHT, OO_OVERBRIGHT, OO_OVERBRIGHT, alpha ); + s_pShaderAPI->Color4ub( 128, 128, 128, (int)(alpha * 255)); + + if (TextureIsTranslucent(baseTextureVar, true)) + { + SetFixedFunctionTextureTransform( MATERIAL_TEXTURE0, baseTextureTransformVar ); + BindTexture( SHADER_SAMPLER0, baseTextureVar, frameVar ); + } + + LoadIdentity( MATERIAL_TEXTURE1 ); + s_pShaderAPI->BindStandardTexture( SHADER_SAMPLER1, TEXTURE_LIGHTMAP ); + + Draw(); + } +} + + +//----------------------------------------------------------------------------- +// Fixed function Self illumination pass +//----------------------------------------------------------------------------- +void CBaseShader::FixedFunctionSelfIlluminationPass( Sampler_t sampler, + int baseTextureVar, int frameVar, int baseTextureTransformVar, int selfIllumTintVar ) +{ +// IMaterialVar** params = s_ppParams; + + if ( IsSnapshotting() ) + { + SetInitialShadowState(); + + // A little setup for self illum here... + SetModulationShadowState( selfIllumTintVar ); + + s_pShaderShadow->EnableTexture( sampler, true ); + + // No overbrighting + s_pShaderShadow->OverbrightValue( SHADER_TEXTURE_STAGE0, 1.0f ); + s_pShaderShadow->OverbrightValue( SHADER_TEXTURE_STAGE1, 1.0f ); + + // Don't bother with z writes here... + s_pShaderShadow->EnableDepthWrites( false ); + + // We're always blending + EnableAlphaBlending( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA ); + + int flags = SHADER_DRAW_POSITION; + if ( sampler == SHADER_SAMPLER0 ) + flags |= SHADER_DRAW_TEXCOORD0; + else + flags |= SHADER_DRAW_TEXCOORD1; + + s_pShaderShadow->DrawFlags( flags ); + FogToFogColor(); + } + else + { + s_pShaderAPI->SetDefaultState(); + + SetFixedFunctionTextureTransform( + (sampler == SHADER_SAMPLER0) ? MATERIAL_TEXTURE0 : MATERIAL_TEXTURE1, + baseTextureTransformVar ); + BindTexture( sampler, baseTextureVar, frameVar ); + + // NOTE: Texture + texture offset are set from BaseTimesLightmap + SetModulationDynamicState( selfIllumTintVar ); + } + Draw(); +} + + +//----------------------------------------------------------------------------- +// Fixed function Base * detail pass +//----------------------------------------------------------------------------- +void CBaseShader::FixedFunctionBaseTimesDetailPass( int baseTextureVar, + int frameVar, int baseTextureTransformVar, int detailVar, int detailScaleVar ) +{ + IMaterialVar** params = s_ppParams; + + // We can't do this one one pass if CC and VC are both active... + bool hasDetail = (detailVar != -1) && params[detailVar]->IsDefined(); + bool detailInSecondPass = hasDetail && IsColorModulating() && + (IS_FLAG_SET(MATERIAL_VAR_VERTEXCOLOR) || IS_FLAG_SET(MATERIAL_VAR_VERTEXALPHA)); + + if (IsSnapshotting()) + { + s_pShaderShadow->EnableTexGen( SHADER_TEXTURE_STAGE0, false ); + s_pShaderShadow->EnableTexGen( SHADER_TEXTURE_STAGE1, false ); + + // alpha test + s_pShaderShadow->EnableAlphaTest( IS_FLAG_SET(MATERIAL_VAR_ALPHATEST) ); + + // Alpha blending + SetDefaultBlendingShadowState( baseTextureVar, true ); + + // independently configure alpha and color + s_pShaderShadow->EnableAlphaPipe( true ); + + // Here's the color states (NOTE: SHADER_DRAW_COLOR == use Vertex Color) + s_pShaderShadow->EnableConstantColor( IsColorModulating() ); + s_pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + + int flags = SHADER_DRAW_POSITION | SHADER_DRAW_TEXCOORD0; + + // Detail texture.. + if (hasDetail && (!detailInSecondPass)) + { + s_pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + + // Force mod2x + s_pShaderShadow->OverbrightValue( SHADER_TEXTURE_STAGE1, 2.0f ); + + flags |= SHADER_DRAW_TEXCOORD1; + } + + // Here's the alpha states + s_pShaderShadow->EnableConstantAlpha( IsAlphaModulating() ); + s_pShaderShadow->EnableVertexAlpha( IS_FLAG_SET(MATERIAL_VAR_VERTEXALPHA) ); + s_pShaderShadow->EnableTextureAlpha( SHADER_TEXTURE_STAGE0, TextureIsTranslucent(baseTextureVar, true) ); + + if (IS_FLAG_SET(MATERIAL_VAR_VERTEXCOLOR)) + flags |= SHADER_DRAW_COLOR; + s_pShaderShadow->DrawFlags( flags ); + + DefaultFog(); + + Draw(); + + s_pShaderShadow->EnableAlphaPipe( false ); + } + else + { + SetFixedFunctionTextureTransform( MATERIAL_TEXTURE0, baseTextureTransformVar ); + BindTexture( SHADER_SAMPLER0, baseTextureVar, frameVar ); + + // Detail texture.. + if (hasDetail && (!detailInSecondPass)) + { + BindTexture( SHADER_SAMPLER1, detailVar, frameVar ); + SetFixedFunctionTextureScaledTransform( MATERIAL_TEXTURE1, baseTextureTransformVar, detailScaleVar ); + } + + SetModulationDynamicState(); + + Draw(); + } + + if (detailInSecondPass) + { + FixedFunctionMultiplyByDetailPass( baseTextureVar, frameVar, baseTextureTransformVar, detailVar, detailScaleVar ); + } +} + + +//----------------------------------------------------------------------------- +// Helpers for environment mapping... +//----------------------------------------------------------------------------- +int CBaseShader::SetShadowEnvMappingState( int envMapMaskVar, int tintVar ) +{ + Assert( IsSnapshotting() ); + IMaterialVar** params = s_ppParams; + + int varFlags = params[FLAGS]->GetIntValue(); + + s_pShaderShadow->EnableAlphaTest( false ); + + // envmap on stage 0 + s_pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + s_pShaderShadow->EnableTexGen( SHADER_TEXTURE_STAGE0, true ); + if ( (varFlags & MATERIAL_VAR_ENVMAPSPHERE) == 0 ) + s_pShaderShadow->TexGen( SHADER_TEXTURE_STAGE0, SHADER_TEXGENPARAM_CAMERASPACEREFLECTIONVECTOR ); + else + s_pShaderShadow->TexGen( SHADER_TEXTURE_STAGE0, SHADER_TEXGENPARAM_SPHERE_MAP ); + + int flags = SHADER_DRAW_POSITION | SHADER_DRAW_NORMAL; + + // mask on stage 1 + if (params[envMapMaskVar]->IsDefined() || (varFlags & MATERIAL_VAR_BASEALPHAENVMAPMASK)) + { + s_pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + flags |= SHADER_DRAW_TEXCOORD1; + } + else + { + s_pShaderShadow->EnableTexture( SHADER_SAMPLER1, false ); + } + + if (varFlags & MATERIAL_VAR_BASEALPHAENVMAPMASK) + { + s_pShaderShadow->EnableCustomPixelPipe( true ); + s_pShaderShadow->CustomTextureStages( 2 ); + + // Color = base texture * envmaptint * (1 - mask alpha) + s_pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE0, + SHADER_TEXCHANNEL_COLOR, SHADER_TEXOP_MODULATE, SHADER_TEXARG_TEXTURE, SHADER_TEXARG_CONSTANTCOLOR ); + s_pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE1, + SHADER_TEXCHANNEL_COLOR, SHADER_TEXOP_MODULATE, SHADER_TEXARG_PREVIOUSSTAGE, SHADER_TEXARG_INVTEXTUREALPHA ); + + // Use alpha modulation * vertex alpha * env map alpha + s_pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE0, + SHADER_TEXCHANNEL_ALPHA, SHADER_TEXOP_MODULATE, SHADER_TEXARG_VERTEXCOLOR, SHADER_TEXARG_TEXTURE ); + s_pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE1, + SHADER_TEXCHANNEL_ALPHA, SHADER_TEXOP_SELECTARG1, SHADER_TEXARG_PREVIOUSSTAGE, SHADER_TEXARG_CONSTANTCOLOR ); + } + else + { + s_pShaderShadow->EnableAlphaPipe( true ); + + // Color = base texture * envmaptint * mask + s_pShaderShadow->EnableConstantColor( tintVar >= 0 ); + + // Alpha = vertex alpha * constant alpha * env map alpha * mask alpha (only if it's not a base alpha mask) + s_pShaderShadow->EnableConstantAlpha( IsAlphaModulating() ); + s_pShaderShadow->EnableVertexAlpha( (varFlags & MATERIAL_VAR_VERTEXALPHA) != 0 ); + s_pShaderShadow->EnableTextureAlpha( SHADER_TEXTURE_STAGE0, true ); + s_pShaderShadow->EnableTextureAlpha( SHADER_TEXTURE_STAGE1, params[envMapMaskVar]->IsTexture() ); + } + + return flags; +} + +void CBaseShader::SetDynamicEnvMappingState( int envMapVar, int envMapMaskVar, + int baseTextureVar, int envMapFrameVar, int envMapMaskFrameVar, int frameVar, + int maskOffsetVar, int maskScaleVar, int tintVar ) +{ + Assert( !IsSnapshotting() ); + + IMaterialVar** params = s_ppParams; + int varFlags = params[FLAGS]->GetIntValue(); + + if( (varFlags & MATERIAL_VAR_ENVMAPSPHERE) == 0 ) + { + if ( (varFlags & MATERIAL_VAR_ENVMAPCAMERASPACE) == 0 ) + { + LoadCameraToWorldTransform( MATERIAL_TEXTURE0 ); + } + else + { + LoadIdentity( MATERIAL_TEXTURE0 ); + } + } + else + { + LoadCameraSpaceSphereMapTransform( MATERIAL_TEXTURE0 ); + } + + BindTexture( SHADER_SAMPLER0, envMapVar, envMapFrameVar ); + + if (params[envMapMaskVar]->IsTexture()) + { + SetFixedFunctionTextureScaledTransform( MATERIAL_TEXTURE1, + maskOffsetVar, maskScaleVar ); + BindTexture( SHADER_SAMPLER1, envMapMaskVar, envMapMaskFrameVar ); + } + else if (varFlags & MATERIAL_VAR_BASEALPHAENVMAPMASK) + { + SetFixedFunctionTextureScaledTransform( MATERIAL_TEXTURE1, + maskOffsetVar, maskScaleVar ); + BindTexture( SHADER_SAMPLER1, baseTextureVar, frameVar ); + } + + SetModulationDynamicState( tintVar ); +} + + +//----------------------------------------------------------------------------- +// Masked environment map +//----------------------------------------------------------------------------- +void CBaseShader::FixedFunctionMaskedEnvmapPass( int envMapVar, int envMapMaskVar, + int baseTextureVar, int envMapFrameVar, int envMapMaskFrameVar, + int frameVar, int maskOffsetVar, int maskScaleVar, int envMapTintVar ) +{ +// IMaterialVar** params = ShaderState().m_ppParams; + + if (IsSnapshotting()) + { + // Alpha blending + SetDefaultBlendingShadowState( envMapMaskVar, false ); + + // Disable overbright + s_pShaderShadow->OverbrightValue( SHADER_TEXTURE_STAGE0, 1.0f ); + s_pShaderShadow->OverbrightValue( SHADER_TEXTURE_STAGE1, 1.0f ); + + int flags = SetShadowEnvMappingState( envMapMaskVar, envMapTintVar ); + s_pShaderShadow->DrawFlags( flags ); + + DefaultFog(); + Draw(); + + s_pShaderShadow->EnableCustomPixelPipe( false ); + s_pShaderShadow->EnableAlphaPipe( false ); + } + else + { + SetDynamicEnvMappingState( envMapVar, envMapMaskVar, baseTextureVar, + envMapFrameVar, envMapMaskFrameVar, frameVar, + maskOffsetVar, maskScaleVar, envMapTintVar ); + + Draw(); + } +} + + +//----------------------------------------------------------------------------- +// Add masked environment map +//----------------------------------------------------------------------------- +void CBaseShader::FixedFunctionAdditiveMaskedEnvmapPass( int envMapVar, int envMapMaskVar, + int baseTextureVar, int envMapFrameVar, int envMapMaskFrameVar, + int frameVar, int maskOffsetVar, int maskScaleVar, int envMapTintVar ) +{ +// IMaterialVar** params = ShaderState().m_ppParams; + + if (IsSnapshotting()) + { + SetInitialShadowState(); + + // Alpha blending + SetAdditiveBlendingShadowState( envMapMaskVar, false ); + + // Disable overbright + s_pShaderShadow->OverbrightValue( SHADER_TEXTURE_STAGE0, 1.0f ); + s_pShaderShadow->OverbrightValue( SHADER_TEXTURE_STAGE1, 1.0f ); + + // Don't bother with z writes here... + s_pShaderShadow->EnableDepthWrites( false ); + + int flags = SetShadowEnvMappingState( envMapMaskVar, envMapTintVar ); + s_pShaderShadow->DrawFlags( flags ); + + FogToBlack(); + Draw(); + + s_pShaderShadow->EnableCustomPixelPipe( false ); + s_pShaderShadow->EnableAlphaPipe( false ); + } + else + { + SetDynamicEnvMappingState( envMapVar, envMapMaskVar, baseTextureVar, + envMapFrameVar, envMapMaskFrameVar, frameVar, + maskOffsetVar, maskScaleVar, envMapTintVar ); + + Draw(); + } +} + + +void CBaseShader::CleanupDynamicStateFixedFunction( ) +{ + Assert( !IsSnapshotting() ); + LoadIdentity( MATERIAL_TEXTURE0 ); +} + +bool CBaseShader::UsingFlashlight( IMaterialVar **params ) const +{ + if( IsSnapshotting() ) + { + return CShader_IsFlag2Set( params, MATERIAL_VAR2_USE_FLASHLIGHT ); + } + else + { + return s_pShaderAPI->InFlashlightMode(); + } +} + +bool CBaseShader::UsingEditor( IMaterialVar **params ) const +{ + if( IsSnapshotting() ) + { + return CShader_IsFlag2Set( params, MATERIAL_VAR2_USE_EDITOR ); + } + else + { + return s_pShaderAPI->InEditorMode(); + } +} + +void CBaseShader::DrawFlashlight_dx70( + IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow, + int flashlightTextureVar, int flashlightTextureFrameVar, + bool suppress_lighting ) +{ + SHADOW_STATE + { + SET_FLAGS2( MATERIAL_VAR2_NEEDS_FIXED_FUNCTION_FLASHLIGHT ); + pShaderShadow->EnableDepthWrites( false ); + pShaderShadow->EnableAlphaWrites( false ); + + // Alpha test +// pShaderShadow->EnableAlphaTest( IS_FLAG_SET( MATERIAL_VAR_ALPHATEST ) ); + bool bIsAlphaTested = IS_FLAG_SET( MATERIAL_VAR_ALPHATEST ) != 0; + if( bIsAlphaTested ) + { + // disable alpha test and use the zfunc zequals since alpha isn't guaranteed to + // be the same on both the regular pass and the flashlight pass. + s_pShaderShadow->EnableAlphaTest( false ); + s_pShaderShadow->DepthFunc( SHADER_DEPTHFUNC_EQUAL ); + } + + // Alpha blend + SetAdditiveBlendingShadowState( BASETEXTURE, true ); + + int flags = SHADER_DRAW_POSITION | SHADER_DRAW_TEXCOORD1 | SHADER_DRAW_COLOR | SHADER_DRAW_NORMAL; + pShaderShadow->DrawFlags( flags ); + FogToBlack(); + + if ( !suppress_lighting ) + pShaderShadow->EnableLighting( true ); + + pShaderShadow->EnableCustomPixelPipe( true ); + pShaderShadow->CustomTextureStages( 2 ); + + // color stage 0 + // projected texture * vertex color (lighting) + pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE0, + SHADER_TEXCHANNEL_COLOR, + SHADER_TEXOP_MODULATE, + SHADER_TEXARG_TEXTURE, + SHADER_TEXARG_VERTEXCOLOR ); + + // color stage 1 + // * base texture + pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE1, + SHADER_TEXCHANNEL_COLOR, + SHADER_TEXOP_MODULATE, + SHADER_TEXARG_TEXTURE, SHADER_TEXARG_PREVIOUSSTAGE ); + + // alpha stage 0 + // get alpha from constant alpha + pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE0, + SHADER_TEXCHANNEL_ALPHA, + SHADER_TEXOP_SELECTARG1, + SHADER_TEXARG_CONSTANTCOLOR, SHADER_TEXARG_NONE ); + + // alpha stage 1 + // get alpha from $basetexture + pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE1, + SHADER_TEXCHANNEL_ALPHA, + SHADER_TEXOP_MODULATE, + SHADER_TEXARG_TEXTURE, SHADER_TEXARG_PREVIOUSSTAGE ); + + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + + // Shove the view position into texcoord 0 before the texture matrix. + pShaderShadow->TexGen( SHADER_TEXTURE_STAGE0, SHADER_TEXGENPARAM_EYE_LINEAR ); + pShaderShadow->EnableTexGen( SHADER_TEXTURE_STAGE0, true ); + } + DYNAMIC_STATE + { + SetFlashlightFixedFunctionTextureTransform( MATERIAL_TEXTURE0 ); + + // NOTE: This has to come after the loadmatrix since the loadmatrix screws with the + // transform flags!!!!!! + // Specify that we have XYZ texcoords that need to be divided by W before the pixel shader. + // NOTE Tried to divide XY by Z, but doesn't work. + pShaderAPI->SetTextureTransformDimension( SHADER_TEXTURE_STAGE0, 3, true ); + + BindTexture( SHADER_SAMPLER0, flashlightTextureVar, flashlightTextureFrameVar ); + if( params[BASETEXTURE]->IsTexture() ) + { + BindTexture( SHADER_SAMPLER1, BASETEXTURE, FRAME ); + } + else + { + pShaderAPI->BindStandardTexture( SHADER_SAMPLER1, TEXTURE_GREY ); + } + + SetModulationDynamicState(); + } + Draw(); +} + +void CBaseShader::SetFlashlightFixedFunctionTextureTransform( MaterialMatrixMode_t matrix ) +{ + VMatrix worldToTexture; + s_pShaderAPI->GetFlashlightState( worldToTexture ); + + VMatrix worldToView, viewToWorld, viewToTexture; + s_pShaderAPI->GetMatrix( MATERIAL_VIEW, &worldToView[0][0] ); + // The matrix that we get back from the shader api is transposed. . . yuck. + MatrixTranspose( worldToView, worldToView ); + MatrixInverseGeneral( worldToView, viewToWorld ); + MatrixMultiply( worldToTexture, viewToWorld, viewToTexture ); + + s_pShaderAPI->MatrixMode( matrix ); + // tranpose before going into the shaderapi. . . suck + MatrixTranspose( viewToTexture, viewToTexture ); + s_pShaderAPI->LoadMatrix( &viewToTexture[0][0] ); +} + +bool CBaseShader::IsHDREnabled( void ) +{ + // HDRFIXME! Need to fix this for vgui materials + HDRType_t hdr_mode=g_pHardwareConfig->GetHDRType(); + switch(hdr_mode) + { + case HDR_TYPE_NONE: + return false; + + case HDR_TYPE_INTEGER: + return true; + + case HDR_TYPE_FLOAT: + { + ITexture *pRT = s_pShaderAPI->GetRenderTargetEx( 0 ); + if( pRT && pRT->GetImageFormat() == IMAGE_FORMAT_RGBA16161616F ) + { + return true; + } + } + } + return false; +} + diff --git a/materialsystem/shaderlib/ShaderDLL.cpp b/materialsystem/shaderlib/ShaderDLL.cpp new file mode 100644 index 0000000..e52b601 --- /dev/null +++ b/materialsystem/shaderlib/ShaderDLL.cpp @@ -0,0 +1,169 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//===========================================================================// + +#include "shaderlib/ShaderDLL.h" +#include "materialsystem/IShader.h" +#include "tier1/utlvector.h" +#include "tier0/dbg.h" +#include "materialsystem/imaterialsystemhardwareconfig.h" +#include "materialsystem/materialsystem_config.h" +#include "IShaderSystem.h" +#include "materialsystem/ishaderapi.h" +#include "shaderlib_cvar.h" +#include "mathlib/mathlib.h" +#include "tier1/tier1.h" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +//----------------------------------------------------------------------------- +// The standard implementation of CShaderDLL +//----------------------------------------------------------------------------- +class CShaderDLL : public IShaderDLLInternal, public IShaderDLL +{ +public: + CShaderDLL(); + + // methods of IShaderDLL + virtual bool Connect( CreateInterfaceFn factory ); + virtual void Disconnect(); + virtual int ShaderCount() const; + virtual IShader *GetShader( int nShader ); + + // methods of IShaderDLLInternal + virtual bool Connect( CreateInterfaceFn factory, bool bIsMaterialSystem ); + virtual void Disconnect( bool bIsMaterialSystem ); + virtual void InsertShader( IShader *pShader ); + +private: + CUtlVector< IShader * > m_ShaderList; +}; + + +//----------------------------------------------------------------------------- +// Global interfaces/structures +//----------------------------------------------------------------------------- +IMaterialSystemHardwareConfig* g_pHardwareConfig; +const MaterialSystem_Config_t *g_pConfig; + + +//----------------------------------------------------------------------------- +// Interfaces/structures local to shaderlib +//----------------------------------------------------------------------------- +IShaderSystem* g_pSLShaderSystem; + + +// Pattern necessary because shaders register themselves in global constructors +static CShaderDLL *s_pShaderDLL; + + +//----------------------------------------------------------------------------- +// Global accessor +//----------------------------------------------------------------------------- +IShaderDLL *GetShaderDLL() +{ + // Pattern necessary because shaders register themselves in global constructors + if ( !s_pShaderDLL ) + { + s_pShaderDLL = new CShaderDLL; + } + + return s_pShaderDLL; +} + +IShaderDLLInternal *GetShaderDLLInternal() +{ + // Pattern necessary because shaders register themselves in global constructors + if ( !s_pShaderDLL ) + { + s_pShaderDLL = new CShaderDLL; + } + + return static_cast( s_pShaderDLL ); +} + +//----------------------------------------------------------------------------- +// Singleton interface +//----------------------------------------------------------------------------- +EXPOSE_INTERFACE_FN( (InstantiateInterfaceFn)GetShaderDLLInternal, IShaderDLLInternal, SHADER_DLL_INTERFACE_VERSION ); + +//----------------------------------------------------------------------------- +// Connect, disconnect... +//----------------------------------------------------------------------------- +CShaderDLL::CShaderDLL() +{ + MathLib_Init( 2.2f, 2.2f, 0.0f, 2.0f ); +} + + +//----------------------------------------------------------------------------- +// Connect, disconnect... +//----------------------------------------------------------------------------- +bool CShaderDLL::Connect( CreateInterfaceFn factory, bool bIsMaterialSystem ) +{ + g_pHardwareConfig = (IMaterialSystemHardwareConfig*)factory( MATERIALSYSTEM_HARDWARECONFIG_INTERFACE_VERSION, NULL ); + g_pConfig = (const MaterialSystem_Config_t*)factory( MATERIALSYSTEM_CONFIG_VERSION, NULL ); + g_pSLShaderSystem = (IShaderSystem*)factory( SHADERSYSTEM_INTERFACE_VERSION, NULL ); + + if ( !bIsMaterialSystem ) + { + ConnectTier1Libraries( &factory, 1 ); + InitShaderLibCVars( factory ); + } + + return ( g_pConfig != NULL ) && (g_pHardwareConfig != NULL) && ( g_pSLShaderSystem != NULL ); +} + +void CShaderDLL::Disconnect( bool bIsMaterialSystem ) +{ + if ( !bIsMaterialSystem ) + { + ConVar_Unregister(); + DisconnectTier1Libraries(); + } + + g_pHardwareConfig = NULL; + g_pConfig = NULL; + g_pSLShaderSystem = NULL; +} + +bool CShaderDLL::Connect( CreateInterfaceFn factory ) +{ + return Connect( factory, false ); +} + +void CShaderDLL::Disconnect() +{ + Disconnect( false ); +} + + +//----------------------------------------------------------------------------- +// Iterates over all shaders +//----------------------------------------------------------------------------- +int CShaderDLL::ShaderCount() const +{ + return m_ShaderList.Count(); +} + +IShader *CShaderDLL::GetShader( int nShader ) +{ + if ( ( nShader < 0 ) || ( nShader >= m_ShaderList.Count() ) ) + return NULL; + + return m_ShaderList[nShader]; +} + + +//----------------------------------------------------------------------------- +// Adds to the shader lists +//----------------------------------------------------------------------------- +void CShaderDLL::InsertShader( IShader *pShader ) +{ + Assert( pShader ); + m_ShaderList.AddToTail( pShader ); +} + diff --git a/materialsystem/shaderlib/shaderDLL_Global.h b/materialsystem/shaderlib/shaderDLL_Global.h new file mode 100644 index 0000000..ae1ff0b --- /dev/null +++ b/materialsystem/shaderlib/shaderDLL_Global.h @@ -0,0 +1,33 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $Header: $ +// $NoKeywords: $ +//=============================================================================// + +#ifndef SHADERDLL_GLOBAL_H +#define SHADERDLL_GLOBAL_H + +#ifdef _WIN32 +#pragma once +#endif + + +//----------------------------------------------------------------------------- +// forward declarations +//----------------------------------------------------------------------------- +class IShaderSystem; + + +//----------------------------------------------------------------------------- +// forward declarations +//----------------------------------------------------------------------------- +inline IShaderSystem *GetShaderSystem() +{ + extern IShaderSystem* g_pSLShaderSystem; + return g_pSLShaderSystem; +} + + +#endif // SHADERDLL_GLOBAL_H \ No newline at end of file diff --git a/materialsystem/shaderlib/shaderlib.vpc b/materialsystem/shaderlib/shaderlib.vpc new file mode 100644 index 0000000..810d3fd --- /dev/null +++ b/materialsystem/shaderlib/shaderlib.vpc @@ -0,0 +1,70 @@ +//----------------------------------------------------------------------------- +// SHADERLIB.VPC +// +// Project Script +//----------------------------------------------------------------------------- + +$macro SRCDIR "..\.." +$include "$SRCDIR\vpc_scripts\source_lib_base.vpc" + +$Configuration +{ + $Compiler + { + $AdditionalIncludeDirectories "$BASE;..\" + $PreprocessorDefinitions "$BASE;FAST_MATERIALVAR_ACCESS" + $PreprocessorDefinitions "$BASE;fopen=dont_use_fopen" [$WINDOWS] + } +} + + +$Project "shaderlib" +{ + $Folder "Source Files" + { + $File "BaseShader.cpp" + $File "ShaderDLL.cpp" + $File "shaderlib_cvar.cpp" + } + + $Folder "Header Files" + { + $File "shaderDLL_Global.h" + $File "shaderlib_cvar.h" + $File "$SRCDIR\public\shaderlib\BaseShader.h" + $File "$SRCDIR\public\tier0\basetypes.h" + $File "$SRCDIR\public\tier0\commonmacros.h" + $File "$SRCDIR\public\shaderlib\cshader.h" + $File "$SRCDIR\public\tier0\dbg.h" + $File "$SRCDIR\public\tier0\fasttimer.h" + $File "$SRCDIR\public\appframework\IAppSystem.h" + $File "$SRCDIR\public\tier0\icommandline.h" + $File "$SRCDIR\public\icvar.h" + $File "$SRCDIR\public\materialsystem\imaterial.h" + $File "$SRCDIR\public\materialsystem\imaterialsystem.h" + $File "$SRCDIR\public\materialsystem\imaterialsystemhardwareconfig.h" + $File "$SRCDIR\public\materialsystem\imaterialvar.h" + $File "$SRCDIR\public\materialsystem\imesh.h" + $File "$SRCDIR\public\materialsystem\IShader.h" + $File "$SRCDIR\public\materialsystem\ishaderapi.h" + $File "..\IShaderSystem.h" + $File "$SRCDIR\public\materialsystem\itexture.h" + $File "$SRCDIR\public\materialsystem\materialsystem_config.h" + $File "$SRCDIR\public\mathlib\mathlib.h" + $File "$SRCDIR\public\tier0\memdbgoff.h" + $File "$SRCDIR\public\tier0\memdbgon.h" + $File "$SRCDIR\public\tier0\platform.h" + $File "$SRCDIR\public\tier0\protected_things.h" + $File "$SRCDIR\public\shaderlib\ShaderDLL.h" + $File "$SRCDIR\public\string_t.h" + $File "$SRCDIR\public\tier1\strtools.h" + $File "$SRCDIR\public\tier1\utlmemory.h" + $File "$SRCDIR\public\tier1\utlvector.h" + $File "$SRCDIR\public\mathlib\vector.h" + $File "$SRCDIR\public\mathlib\vector2d.h" + $File "$SRCDIR\public\mathlib\vector4d.h" + $File "$SRCDIR\public\mathlib\vmatrix.h" + $File "$SRCDIR\public\mathlib\vplane.h" + $File "$SRCDIR\public\vstdlib\vstdlib.h" + } +} diff --git a/materialsystem/shaderlib/shaderlib_cvar.cpp b/materialsystem/shaderlib/shaderlib_cvar.cpp new file mode 100644 index 0000000..e84d6fe --- /dev/null +++ b/materialsystem/shaderlib/shaderlib_cvar.cpp @@ -0,0 +1,42 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//===========================================================================// + +#include "icvar.h" +#include "tier1/tier1.h" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +// ------------------------------------------------------------------------------------------- // +// ConVar stuff. +// ------------------------------------------------------------------------------------------- // +class CShaderLibConVarAccessor : public IConCommandBaseAccessor +{ +public: + virtual bool RegisterConCommandBase( ConCommandBase *pCommand ) + { + // Link to engine's list instead + g_pCVar->RegisterConCommand( pCommand ); + + char const *pValue = g_pCVar->GetCommandLineValue( pCommand->GetName() ); + if( pValue && !pCommand->IsCommand() ) + { + ( ( ConVar * )pCommand )->SetValue( pValue ); + } + return true; + } +}; + +CShaderLibConVarAccessor g_ConVarAccessor; + + +void InitShaderLibCVars( CreateInterfaceFn cvarFactory ) +{ + if ( g_pCVar ) + { + ConVar_Register( FCVAR_MATERIAL_SYSTEM_THREAD, &g_ConVarAccessor ); + } +} diff --git a/materialsystem/shaderlib/shaderlib_cvar.h b/materialsystem/shaderlib/shaderlib_cvar.h new file mode 100644 index 0000000..4416aba --- /dev/null +++ b/materialsystem/shaderlib/shaderlib_cvar.h @@ -0,0 +1,20 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//=============================================================================// + +#ifndef SHADERLIB_CVAR_H +#define SHADERLIB_CVAR_H +#ifdef _WIN32 +#pragma once +#endif + + +#include "interface.h" + + +void InitShaderLibCVars( CreateInterfaceFn cvarFactory ); + + +#endif // SHADERLIB_CVAR_H diff --git a/materialsystem/shadersystem.cpp b/materialsystem/shadersystem.cpp new file mode 100644 index 0000000..7d53060 --- /dev/null +++ b/materialsystem/shadersystem.cpp @@ -0,0 +1,2057 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//===========================================================================// + +#include "shadersystem.h" +#include +#include "materialsystem_global.h" +#include "filesystem.h" +#include "tier1/utldict.h" +#include "shaderlib/ShaderDLL.h" +#include "texturemanager.h" +#include "itextureinternal.h" +#include "IHardwareConfigInternal.h" +#include "tier1/utlstack.h" +#include "tier1/utlbuffer.h" +#include "mathlib/vmatrix.h" +#include "imaterialinternal.h" +#include "tier1/strtools.h" +#include "tier0/icommandline.h" +#include "shaderlib/cshader.h" +#include "tier1/convar.h" +#include "tier1/KeyValues.h" +#include "shader_dll_verify.h" +#include "tier0/vprof.h" + +// NOTE: This must be the last file included! +#include "tier0/memdbgon.h" + + +//#define DEBUG_DEPTH 1 + +//----------------------------------------------------------------------------- +// Lovely convars +//----------------------------------------------------------------------------- +static ConVar mat_showenvmapmask( "mat_showenvmapmask", "0" ); +static ConVar mat_debugdepth( "mat_debugdepth", "0" ); +extern ConVar mat_supportflashlight; + + +//----------------------------------------------------------------------------- +// Implementation of the shader system +//----------------------------------------------------------------------------- +class CShaderSystem : public IShaderSystemInternal +{ +public: + CShaderSystem(); + + // Methods of IShaderSystem + virtual ShaderAPITextureHandle_t GetShaderAPITextureBindHandle( ITexture *pTexture, int nFrameVar, int nTextureChannel = 0 ); + + virtual void BindTexture( Sampler_t sampler1, ITexture *pTexture, int nFrame = 0 ); + virtual void BindTexture( Sampler_t sampler1, Sampler_t sampler2, ITexture *pTexture, int nFrame = 0 ); + + virtual void TakeSnapshot( ); + virtual void DrawSnapshot( bool bMakeActualDrawCall = true ); + virtual bool IsUsingGraphics() const; + virtual bool CanUseEditorMaterials() const; + + // Methods of IShaderSystemInternal + virtual void Init(); + virtual void Shutdown(); + virtual void ModInit(); + virtual void ModShutdown(); + + virtual bool LoadShaderDLL( const char *pFullPath ); + virtual bool LoadShaderDLL( const char *pFullPath, const char *pPathID, bool bModShaderDLL ); + virtual void UnloadShaderDLL( const char *pFullPath ); + + virtual IShader* FindShader( char const* pShaderName ); + virtual void CreateDebugMaterials(); + virtual void CleanUpDebugMaterials(); + virtual char const* ShaderStateString( int i ) const; + virtual int ShaderStateCount( ) const; + + virtual void InitShaderParameters( IShader *pShader, IMaterialVar **params, const char *pMaterialName ); + virtual void InitShaderInstance( IShader *pShader, IMaterialVar **params, const char *pMaterialName, const char *pTextureGroupName ); + virtual bool InitRenderState( IShader *pShader, int numParams, IMaterialVar **params, ShaderRenderState_t* pRenderState, char const* pMaterialName ); + virtual void CleanupRenderState( ShaderRenderState_t* pRenderState ); + virtual void DrawElements( IShader *pShader, IMaterialVar **params, ShaderRenderState_t* pShaderState, VertexCompressionType_t vertexCompression, uint32 nVarChangeID ); + + // Used to iterate over all shaders for editing purposes + virtual int ShaderCount() const; + virtual int GetShaders( int nFirstShader, int nMaxCount, IShader **ppShaderList ) const; + + // Methods of IShaderInit + virtual void LoadTexture( IMaterialVar *pTextureVar, const char *pTextureGroupName, int nAdditionalCreationFlags = 0 ); + virtual void LoadBumpMap( IMaterialVar *pTextureVar, const char *pTextureGroupName ); + virtual void LoadCubeMap( IMaterialVar **ppParams, IMaterialVar *pTextureVar, int nAdditionalCreationFlags = 0 ); + + // Used to prevent re-entrant rendering from warning messages + void BufferSpew( SpewType_t spewType, const Color &c, const char *pMsg ); + +private: + struct ShaderDLLInfo_t + { + char *m_pFileName; + CSysModule *m_hInstance; + IShaderDLLInternal *m_pShaderDLL; + ShaderDLL_t m_hShaderDLL; + + // True if this is a mod's shader DLL, in which case it's not allowed to + // override any existing shader names. + bool m_bModShaderDLL; + CUtlDict< IShader *, unsigned short > m_ShaderDict; + }; + +private: + // hackhack: remove this when VAC2 is online. + void VerifyBaseShaderDLL( CSysModule *pModule ); + + // Load up the shader DLLs... + void LoadAllShaderDLLs(); + + // Load the "mshader_" DLLs. + void LoadModShaderDLLs( int dxSupportLevel ); + + // Unload all the shader DLLs... + void UnloadAllShaderDLLs(); + + // Sets up the shader dictionary. + void SetupShaderDictionary( int nShaderDLLIndex ); + + // Cleans up the shader dictionary. + void CleanupShaderDictionary( int nShaderDLLIndex ); + + // Finds an already loaded shader DLL + int FindShaderDLL( const char *pFullPath ); + + // Unloads a particular shader DLL + void UnloadShaderDLL( int nShaderDLLIndex ); + + // Sets up the current ShaderState_t for rendering + void PrepForShaderDraw( IShader *pShader, IMaterialVar** ppParams, + ShaderRenderState_t* pRenderState, int modulation ); + void DoneWithShaderDraw(); + + // Initializes state snapshots + void InitStateSnapshots( IShader *pShader, IMaterialVar **params, ShaderRenderState_t* pRenderState ); + + // Compute snapshots for all combinations of alpha + color modulation + void InitRenderStateFlags( ShaderRenderState_t* pRenderState, int numParams, IMaterialVar **params ); + + // Computes flags from a particular snapshot + void ComputeRenderStateFlagsFromSnapshot( ShaderRenderState_t* pRenderState ); + + // Computes vertex format + usage from a particular snapshot + bool ComputeVertexFormatFromSnapshot( IMaterialVar **params, ShaderRenderState_t* pRenderState ); + + // Used to prevent re-entrant rendering from warning messages + void PrintBufferedSpew( void ); + + // Gets at the current snapshot + StateSnapshot_t CurrentStateSnapshot(); + + // Draws using a particular material.. + void DrawUsingMaterial( IMaterialInternal *pMaterial, VertexCompressionType_t vertexCompression ); + + // Copies material vars + void CopyMaterialVarToDebugShader( IMaterialInternal *pDebugMaterial, IShader *pShader, IMaterialVar **ppParams, const char *pSrcVarName, const char *pDstVarName = NULL ); + + // Debugging draw methods... + void DrawMeasureFillRate( ShaderRenderState_t* pRenderState, int mod, VertexCompressionType_t vertexCompression ); + void DrawNormalMap( IShader *pShader, IMaterialVar **ppParams, VertexCompressionType_t vertexCompression ); + bool DrawEnvmapMask( IShader *pShader, IMaterialVar **ppParams, ShaderRenderState_t* pRenderState, VertexCompressionType_t vertexCompression ); + + int GetModulationSnapshotCount( IMaterialVar **params ); + +private: + // List of all DLLs containing shaders + CUtlVector< ShaderDLLInfo_t > m_ShaderDLLs; + + // Used to prevent re-entrant rendering from warning messages + SpewOutputFunc_t m_SaveSpewOutput; + + CUtlBuffer m_StoredSpew; + + // Render state we're drawing with + ShaderRenderState_t* m_pRenderState; + unsigned short m_hShaderDLL; + unsigned char m_nModulation; + unsigned char m_nRenderPass; + + // Debugging materials + // If you add to this, add to the list of debug shader names (s_pDebugShaderName) below + enum + { + MATERIAL_FILL_RATE = 0, + MATERIAL_DEBUG_NORMALMAP, + MATERIAL_DEBUG_ENVMAPMASK, + MATERIAL_DEBUG_DEPTH, + MATERIAL_DEBUG_DEPTH_DECAL, + MATERIAL_DEBUG_WIREFRAME, + + MATERIAL_DEBUG_COUNT, + }; + + IMaterialInternal* m_pDebugMaterials[MATERIAL_DEBUG_COUNT]; + static const char *s_pDebugShaderName[MATERIAL_DEBUG_COUNT]; + + bool m_bForceUsingGraphicsReturnTrue; +}; + + +//----------------------------------------------------------------------------- +// Singleton +//----------------------------------------------------------------------------- +static CShaderSystem s_ShaderSystem; +IShaderSystemInternal *g_pShaderSystem = &s_ShaderSystem; +EXPOSE_SINGLE_INTERFACE_GLOBALVAR( CShaderSystem, IShaderSystem, + SHADERSYSTEM_INTERFACE_VERSION, s_ShaderSystem ); + + +//----------------------------------------------------------------------------- +// Debugging shader names +//----------------------------------------------------------------------------- +const char *CShaderSystem::s_pDebugShaderName[MATERIAL_DEBUG_COUNT] = +{ + "FillRate", + "DebugNormalMap", + "DebugDrawEnvmapMask", + "DebugDepth", + "DebugDepth", + "Wireframe_DX9" +}; + +//----------------------------------------------------------------------------- +// Constructor +//----------------------------------------------------------------------------- +CShaderSystem::CShaderSystem() : m_StoredSpew( 0, 512, 0 ), m_bForceUsingGraphicsReturnTrue( false ) +{ +} + + +//----------------------------------------------------------------------------- +// Initialization, shutdown +//----------------------------------------------------------------------------- +void CShaderSystem::Init() +{ + m_SaveSpewOutput = NULL; + + m_bForceUsingGraphicsReturnTrue = false; + if ( CommandLine()->FindParm( "-noshaderapi" ) || + CommandLine()->FindParm( "-makereslists" ) ) + { + m_bForceUsingGraphicsReturnTrue = true; + } + + for ( int i = 0; i < MATERIAL_DEBUG_COUNT; ++i ) + { + m_pDebugMaterials[i] = NULL; + } + + LoadAllShaderDLLs(); +} + +void CShaderSystem::Shutdown() +{ + UnloadAllShaderDLLs(); +} + + +//----------------------------------------------------------------------------- +// Load/unload mod-specific shader DLLs +//----------------------------------------------------------------------------- +void CShaderSystem::ModInit() +{ + // Load up standard shader DLLs... + int dxSupportLevel = HardwareConfig()->GetMaxDXSupportLevel(); + Assert( dxSupportLevel >= 60 ); + dxSupportLevel /= 10; + + LoadModShaderDLLs( dxSupportLevel ); +} + + +void CShaderSystem::ModShutdown() +{ + // Unload only MOD dlls + for ( int i = m_ShaderDLLs.Count(); --i >= 0; ) + { + if ( m_ShaderDLLs[i].m_bModShaderDLL ) + { + UnloadShaderDLL(i); + delete[] m_ShaderDLLs[i].m_pFileName; + m_ShaderDLLs.Remove( i ); + } + } +} + + +//----------------------------------------------------------------------------- +// Load up the shader DLLs... +//----------------------------------------------------------------------------- +void CShaderSystem::LoadAllShaderDLLs( ) +{ + UnloadAllShaderDLLs(); + + GetShaderDLLInternal()->Connect( Sys_GetFactoryThis(), true ); + + // Loads local defined or statically linked shaders + int i = m_ShaderDLLs.AddToHead(); + + m_ShaderDLLs[i].m_pFileName = new char[1]; + m_ShaderDLLs[i].m_pFileName[0] = 0; + m_ShaderDLLs[i].m_hInstance = NULL; + m_ShaderDLLs[i].m_pShaderDLL = GetShaderDLLInternal(); + m_ShaderDLLs[i].m_bModShaderDLL = false; + + // Add the shaders to the dictionary of shaders... + SetupShaderDictionary( i ); + + // 360 has the the debug shaders in its dx9 dll + if ( IsPC() || !IsX360() ) + { + // Always need the debug shaders + LoadShaderDLL( "stdshader_dbg" DLL_EXT_STRING ); + } + + // Load up standard shader DLLs... + int dxSupportLevel = HardwareConfig()->GetMaxDXSupportLevel(); + Assert( dxSupportLevel >= 60 ); + dxSupportLevel /= 10; + + // 360 only supports its dx9 dll + int dxStart = IsX360() ? 9 : 6; + char buf[32]; + for ( i = dxStart; i <= dxSupportLevel; ++i ) + { + Q_snprintf( buf, sizeof( buf ), "stdshader_dx%d%s", i, DLL_EXT_STRING ); + LoadShaderDLL( buf ); + } + + const char *pShaderName = NULL; +#ifdef _DEBUG + pShaderName = CommandLine()->ParmValue( "-shader" ); +#endif + if ( !pShaderName ) + { + pShaderName = HardwareConfig()->GetHWSpecificShaderDLLName(); + } + if ( pShaderName ) + { + LoadShaderDLL( pShaderName ); + } + +#ifdef _DEBUG + // For fast-iteration debugging + if ( CommandLine()->FindParm( "-testshaders" ) ) + { + LoadShaderDLL( "shader_test" DLL_EXT_STRING ); + } +#endif +} + +const char *COM_GetModDirectory() +{ + static char modDir[MAX_PATH]; + if ( Q_strlen( modDir ) == 0 ) + { + const char *gamedir = CommandLine()->ParmValue("-game", CommandLine()->ParmValue( "-defaultgamedir", "hl2" ) ); + Q_strncpy( modDir, gamedir, sizeof(modDir) ); + if ( strchr( modDir, '/' ) || strchr( modDir, '\\' ) ) + { + Q_StripLastDir( modDir, sizeof(modDir) ); + int dirlen = Q_strlen( modDir ); + Q_strncpy( modDir, gamedir + dirlen, sizeof(modDir) - dirlen ); + } + } + + return modDir; +} + +void CShaderSystem::LoadModShaderDLLs( int dxSupportLevel ) +{ + if ( IsX360() ) + return; + + // Don't do this for Valve mods. They don't need them, and attempting to load them is an opportunity for cheaters to get their code into the process + const char *pGameDir = COM_GetModDirectory(); + if ( !Q_stricmp( pGameDir, "hl2" ) || !Q_stricmp( pGameDir, "cstrike" ) || !Q_stricmp( pGameDir, "cstrike_beta" ) || + !Q_stricmp( pGameDir, "hl2mp" ) || !Q_stricmp( pGameDir, "lostcoast" ) || !Q_stricmp( pGameDir, "episodic" ) || + !Q_stricmp( pGameDir, "portal" ) || !Q_stricmp( pGameDir, "ep2" ) || !Q_stricmp( pGameDir, "dod" ) || + !Q_stricmp( pGameDir, "tf" ) || !Q_stricmp( pGameDir, "tf_beta" ) || !Q_stricmp( pGameDir, "hl1" ) ) + { + return; + } + + const char *pModShaderPathID = "GAMEBIN"; + + // First load the ones with dx_ prefix. + char buf[256]; + + int dxStart = 6; + for ( int i = dxStart; i <= dxSupportLevel; ++i ) + { + Q_snprintf( buf, sizeof( buf ), "game_shader_dx%d%s", i, DLL_EXT_STRING ); + LoadShaderDLL( buf, pModShaderPathID, true ); + } + + // Now load the ones with any dx_ prefix. + FileFindHandle_t findHandle; + const char *pFilename = g_pFullFileSystem->FindFirstEx( "game_shader_generic*", pModShaderPathID, &findHandle ); + while ( pFilename ) + { + Q_snprintf( buf, sizeof( buf ), "%s%s", pFilename, DLL_EXT_STRING ); + LoadShaderDLL( buf, pModShaderPathID, true ); + + pFilename = g_pFullFileSystem->FindNext( findHandle ); + } +} + + +//----------------------------------------------------------------------------- +// Unload all the shader DLLs... +//----------------------------------------------------------------------------- +void CShaderSystem::UnloadAllShaderDLLs() +{ + if ( m_ShaderDLLs.Count() == 0 ) + return; + + for ( int i = m_ShaderDLLs.Count(); --i >= 0; ) + { + UnloadShaderDLL(i); + delete[] m_ShaderDLLs[i].m_pFileName; + } + + m_ShaderDLLs.RemoveAll(); +} + +bool CShaderSystem::LoadShaderDLL( const char *pFullPath ) +{ + return LoadShaderDLL( pFullPath, NULL, false ); +} + +// HACKHACK: remove me when VAC2 is online. +#if defined( _WIN32 ) && !defined( _X360 ) +// Instead of including windows.h +extern "C" +{ + extern void * __stdcall GetProcAddress( void *hModule, const char *pszProcName ); +}; +#endif + +void CShaderSystem::VerifyBaseShaderDLL( CSysModule *pModule ) +{ +#if defined( _WIN32 ) && !defined( _X360 ) + const char *pErrorStr = "Corrupt save data settings."; + + unsigned char *testData1 = new unsigned char[SHADER_DLL_VERIFY_DATA_LEN1]; + + ShaderDLLVerifyFn fn = (ShaderDLLVerifyFn)GetProcAddress( (void *)pModule, SHADER_DLL_FNNAME_1 ); + if ( !fn ) + Error( pErrorStr ); + + IShaderDLLVerification *pVerify; + char *pPtr = (char*)(void*)&pVerify; + pPtr -= SHADER_DLL_VERIFY_DATA_PTR_OFFSET; + fn( pPtr ); + + // Test the first CRC. + CRC32_t testCRC; + CRC32_Init( &testCRC ); + CRC32_ProcessBuffer( &testCRC, testData1, SHADER_DLL_VERIFY_DATA_LEN1 ); + CRC32_ProcessBuffer( &testCRC, &pModule, 4 ); + CRC32_ProcessBuffer( &testCRC, &pVerify, 4 ); + CRC32_Final( &testCRC ); + if ( testCRC != pVerify->Function1( testData1 - SHADER_DLL_VERIFY_DATA_PTR_OFFSET ) ) + Error( pErrorStr ); + + // Test the next one. + unsigned char digest[MD5_DIGEST_LENGTH]; + MD5Context_t md5Context; + MD5Init( &md5Context ); + MD5Update( &md5Context, testData1 + SHADER_DLL_VERIFY_DATA_PTR_OFFSET, SHADER_DLL_VERIFY_DATA_LEN1 - SHADER_DLL_VERIFY_DATA_PTR_OFFSET ); + MD5Final( digest, &md5Context ); + pVerify->Function2( 2, 3, 3 ); // fn2 is supposed to place the result in testData1. + if ( memcmp( digest, testData1, MD5_DIGEST_LENGTH ) != 0 ) + Error( pErrorStr ); + + pVerify->Function5(); + + delete [] testData1; +#endif +} + +//----------------------------------------------------------------------------- +// Methods related to reading in shader DLLs +//----------------------------------------------------------------------------- +bool CShaderSystem::LoadShaderDLL( const char *pFullPath, const char *pPathID, bool bModShaderDLL ) +{ + if ( !pFullPath && !pFullPath[0] ) + return true; + + // Load the new shader + bool bValidatedDllOnly = true; + if ( bModShaderDLL ) + bValidatedDllOnly = false; + + CSysModule *hInstance = g_pFullFileSystem->LoadModule( pFullPath, pPathID, bValidatedDllOnly ); + if ( !hInstance ) + return false; + + // Get at the shader DLL interface + CreateInterfaceFn factory = Sys_GetFactory( hInstance ); + if (!factory) + { + g_pFullFileSystem->UnloadModule( hInstance ); + return false; + } + + IShaderDLLInternal *pShaderDLL = (IShaderDLLInternal*)factory( SHADER_DLL_INTERFACE_VERSION, NULL ); + if ( !pShaderDLL ) + { + g_pFullFileSystem->UnloadModule( hInstance ); + return false; + } + + // Make sure it's a valid base shader DLL if necessary. + //HACKHACK get rid of this when VAC2 comes online. + if ( !bModShaderDLL ) + { + VerifyBaseShaderDLL( hInstance ); + } + + // Allow the DLL to try to connect to interfaces it needs + if ( !pShaderDLL->Connect( Sys_GetFactoryThis(), false ) ) + { + g_pFullFileSystem->UnloadModule( hInstance ); + return false; + } + + // FIXME: We need to do some sort of shader validation here for anticheat. + + // Now replace any existing shader + int nShaderDLLIndex = FindShaderDLL( pFullPath ); + if ( nShaderDLLIndex >= 0 ) + { + UnloadShaderDLL( nShaderDLLIndex ); + } + else + { + nShaderDLLIndex = m_ShaderDLLs.AddToTail(); + int nLen = Q_strlen(pFullPath) + 1; + m_ShaderDLLs[nShaderDLLIndex].m_pFileName = new char[ nLen ]; + Q_strncpy( m_ShaderDLLs[nShaderDLLIndex].m_pFileName, pFullPath, nLen ); + } + + // Ok, the shader DLL's good! + m_ShaderDLLs[nShaderDLLIndex].m_hInstance = hInstance; + m_ShaderDLLs[nShaderDLLIndex].m_pShaderDLL = pShaderDLL; + m_ShaderDLLs[nShaderDLLIndex].m_bModShaderDLL = bModShaderDLL; + + // Add the shaders to the dictionary of shaders... + SetupShaderDictionary( nShaderDLLIndex ); + + // FIXME: Fix up existing materials that were using shaders that have + // been reloaded? + + return true; +} + +//----------------------------------------------------------------------------- +// Finds an already loaded shader DLL +//----------------------------------------------------------------------------- +int CShaderSystem::FindShaderDLL( const char *pFullPath ) +{ + for ( int i = m_ShaderDLLs.Count(); --i >= 0; ) + { + if ( !Q_stricmp( pFullPath, m_ShaderDLLs[i].m_pFileName ) ) + return i; + } + + return -1; +} + +//----------------------------------------------------------------------------- +// Unloads a particular shader DLL +//----------------------------------------------------------------------------- +void CShaderSystem::UnloadShaderDLL( int nShaderDLLIndex ) +{ + if ( nShaderDLLIndex < 0 ) + return; + + // FIXME: Do some sort of fixup of materials to determine which + // materials are referencing shaders in this DLL? + CleanupShaderDictionary( nShaderDLLIndex ); + IShaderDLLInternal *pShaderDLL = m_ShaderDLLs[nShaderDLLIndex].m_pShaderDLL; + pShaderDLL->Disconnect( pShaderDLL == GetShaderDLLInternal() ); + if ( m_ShaderDLLs[nShaderDLLIndex].m_hInstance ) + { + g_pFullFileSystem->UnloadModule( m_ShaderDLLs[nShaderDLLIndex].m_hInstance ); + } +} + +//----------------------------------------------------------------------------- +// Unloads a particular shader DLL +//----------------------------------------------------------------------------- +void CShaderSystem::UnloadShaderDLL( const char *pFullPath ) +{ + int nShaderDLLIndex = FindShaderDLL( pFullPath ); + if ( nShaderDLLIndex >= 0 ) + { + UnloadShaderDLL( nShaderDLLIndex ); + delete[] m_ShaderDLLs[nShaderDLLIndex].m_pFileName; + m_ShaderDLLs.Remove( nShaderDLLIndex ); + } +} + + +//----------------------------------------------------------------------------- +// Make sure these match the bits in imaterial.h +//----------------------------------------------------------------------------- +static const char* s_pShaderStateString[] = +{ + "$debug", + "$no_fullbright", + "$no_draw", + "$use_in_fillrate_mode", + + "$vertexcolor", + "$vertexalpha", + "$selfillum", + "$additive", + "$alphatest", + "$multipass", + "$znearer", + "$model", + "$flat", + "$nocull", + "$nofog", + "$ignorez", + "$decal", + "$envmapsphere", + "$noalphamod", + "$envmapcameraspace", + "$basealphaenvmapmask", + "$translucent", + "$normalmapalphaenvmapmask", + "$softwareskin", + "$opaquetexture", + "$envmapmode", + "$nodecal", + "$halflambert", + "$wireframe", + "$allowalphatocoverage", + + "" // last one must be null +}; + + +//----------------------------------------------------------------------------- +// returns strings associated with the shader state flags... +// If you modify this, make sure and modify MaterialVarFlags_t in imaterial.h +//----------------------------------------------------------------------------- +int CShaderSystem::ShaderStateCount( ) const +{ + return sizeof( s_pShaderStateString ) / sizeof( char* ) - 1; +} + + +//----------------------------------------------------------------------------- +// returns strings associated with the shader state flags... +// If you modify this, make sure and modify MaterialVarFlags_t in imaterial.h +//----------------------------------------------------------------------------- +char const* CShaderSystem::ShaderStateString( int i ) const +{ + return s_pShaderStateString[i]; +} + + +//----------------------------------------------------------------------------- +// Sets up the shader dictionary. +//----------------------------------------------------------------------------- +void CShaderSystem::SetupShaderDictionary( int nShaderDLLIndex ) +{ + // We could have put the shader dictionary into each shader DLL + // I'm not sure if that makes this system any less secure than it already is + int i; + ShaderDLLInfo_t &info = m_ShaderDLLs[nShaderDLLIndex]; + int nCount = info.m_pShaderDLL->ShaderCount(); + for ( i = 0; i < nCount; ++i ) + { + IShader *pShader = info.m_pShaderDLL->GetShader( i ); + const char *pShaderName = pShader->GetName(); + +#ifdef POSIX + if (CommandLine()->FindParm("-glmspew")) + printf("CShaderSystem::SetupShaderDictionary: %s", pShaderName ); +#endif + + // Make sure it doesn't try to override another shader DLL's names. + if ( info.m_bModShaderDLL ) + { + for ( int iTestDLL=0; iTestDLL < m_ShaderDLLs.Count(); iTestDLL++ ) + { + ShaderDLLInfo_t *pTestDLL = &m_ShaderDLLs[iTestDLL]; + if ( !pTestDLL->m_bModShaderDLL ) + { + if ( pTestDLL->m_ShaderDict.Find( pShaderName ) != pTestDLL->m_ShaderDict.InvalidIndex() ) + { + Error( "Game shader '%s' trying to override a base shader '%s'.", info.m_pFileName, pShaderName ); + } + } + } + } + + info.m_ShaderDict.Insert( pShaderName, pShader ); + } +} + +//----------------------------------------------------------------------------- +// Cleans up the shader dictionary. +//----------------------------------------------------------------------------- +void CShaderSystem::CleanupShaderDictionary( int nShaderDLLIndex ) +{ +} + +//----------------------------------------------------------------------------- +// Finds a shader in the shader dictionary +//----------------------------------------------------------------------------- +IShader* CShaderSystem::FindShader( char const* pShaderName ) +{ + // FIXME: What kind of search order should we use here? + // I'm currently assuming last added, first searched. + for (int i = m_ShaderDLLs.Count(); --i >= 0; ) + { + ShaderDLLInfo_t &info = m_ShaderDLLs[i]; + unsigned short idx = info.m_ShaderDict.Find( pShaderName ); + if ( idx != info.m_ShaderDict.InvalidIndex() ) + { + return info.m_ShaderDict[idx]; + } + } + + return NULL; +} + + +//----------------------------------------------------------------------------- +// Used to iterate over all shaders for editing purposes +//----------------------------------------------------------------------------- +int CShaderSystem::ShaderCount() const +{ + return GetShaders( 0, 65536, NULL ); +} + +int CShaderSystem::GetShaders( int nFirstShader, int nMaxCount, IShader **ppShaderList ) const +{ + CUtlSymbolTable uniqueNames( 0, 512, true ); + + int nCount = 0; + int nActualCount = 0; + for ( int i = m_ShaderDLLs.Count(); --i >= 0; ) + { + const ShaderDLLInfo_t &info = m_ShaderDLLs[i]; + for ( unsigned short j = info.m_ShaderDict.First(); + j != info.m_ShaderDict.InvalidIndex(); + j = info.m_ShaderDict.Next( j ) ) + { + // Don't add shaders twice + const char *pShaderName = info.m_ShaderDict.GetElementName( j ); + if ( uniqueNames.Find( pShaderName ) != UTL_INVAL_SYMBOL ) + continue; + + // Indicate we've seen this shader + uniqueNames.AddString( pShaderName ); + + ++nActualCount; + if ( nActualCount > nFirstShader ) + { + if ( ppShaderList ) + { + ppShaderList[ nCount ] = info.m_ShaderDict[j]; + } + ++nCount; + if ( nCount >= nMaxCount ) + return nCount; + } + } + } + + return nCount; +} + + +//----------------------------------------------------------------------------- +// +// Methods of IShaderInit lie below +// +//----------------------------------------------------------------------------- + + +//----------------------------------------------------------------------------- +// Gets at the render pass info for this pass... +//----------------------------------------------------------------------------- +inline StateSnapshot_t CShaderSystem::CurrentStateSnapshot() +{ + Assert( m_pRenderState ); + Assert( m_nRenderPass < MAX_RENDER_PASSES ); + Assert( m_nRenderPass < m_pRenderState->m_pSnapshots[m_nModulation].m_nPassCount ); + return m_pRenderState->m_pSnapshots[m_nModulation].m_Snapshot[m_nRenderPass]; +} + + +//----------------------------------------------------------------------------- +// Create debugging materials +//----------------------------------------------------------------------------- +void CShaderSystem::CreateDebugMaterials() +{ + if (m_pDebugMaterials[0]) + return; + + KeyValues *pVMTKeyValues[MATERIAL_DEBUG_COUNT]; + + int i; + for ( i = 0; i < MATERIAL_DEBUG_COUNT; ++i ) + { + pVMTKeyValues[i] = new KeyValues( s_pDebugShaderName[i] ); + } + + pVMTKeyValues[MATERIAL_DEBUG_DEPTH_DECAL]->SetInt( "$decal", 1 ); + + for ( i = 0; i < MATERIAL_DEBUG_COUNT; ++i ) + { + char shaderName[64]; + Q_snprintf( shaderName, sizeof( shaderName ), "___%s_%d.vmt", s_pDebugShaderName[i], i ); + m_pDebugMaterials[i] = static_cast(MaterialSystem()->CreateMaterial( shaderName, pVMTKeyValues[i] )); + if( m_pDebugMaterials[i] ) + m_pDebugMaterials[i] = m_pDebugMaterials[i]->GetRealTimeVersion(); + } +} + + +//----------------------------------------------------------------------------- +// Cleans up the debugging materials +//----------------------------------------------------------------------------- +void CShaderSystem::CleanUpDebugMaterials() +{ + if (m_pDebugMaterials[0]) + { + for ( int i = 0; i < MATERIAL_DEBUG_COUNT; ++i ) + { + m_pDebugMaterials[i]->DecrementReferenceCount(); + if ( m_pDebugMaterials[i]->InMaterialPage() ) + { + MaterialSystem()->RemoveMaterialSubRect( m_pDebugMaterials[i] ); + } + else + { + MaterialSystem()->RemoveMaterial( m_pDebugMaterials[i] ); + } + m_pDebugMaterials[i] = NULL; + } + } +} + + +//----------------------------------------------------------------------------- +// Deal with buffering of spew while doing shader draw so that we don't get +// recursive spew during precache due to fonts not being loaded, etc. +//----------------------------------------------------------------------------- +CThreadFastMutex g_StgoredSpewMutex; +void CShaderSystem::BufferSpew( SpewType_t spewType, const Color &c, const char *pMsg ) +{ + AUTO_LOCK( g_StgoredSpewMutex ); + m_StoredSpew.PutInt( spewType ); + m_StoredSpew.PutChar( c.r() ); + m_StoredSpew.PutChar( c.g() ); + m_StoredSpew.PutChar( c.b() ); + m_StoredSpew.PutChar( c.a() ); + m_StoredSpew.PutString( pMsg ); +} + +void CShaderSystem::PrintBufferedSpew( void ) +{ + AUTO_LOCK( g_StgoredSpewMutex ); + while ( m_StoredSpew.GetBytesRemaining() > 0 ) + { + SpewType_t spewType = (SpewType_t)m_StoredSpew.GetInt(); + + unsigned char r, g, b, a; + r = m_StoredSpew.GetChar(); + g = m_StoredSpew.GetChar(); + b = m_StoredSpew.GetChar(); + a = m_StoredSpew.GetChar(); + + Color c( r, g, b, a ); + + int nLen = m_StoredSpew.PeekStringLength(); + if ( nLen ) + { + char *pBuf = (char*)_alloca( nLen ); + m_StoredSpew.GetStringManualCharCount( pBuf, nLen ); + ColorSpewMessage( spewType, &c, "%s", pBuf ); + } + else + { + break; + } + } + + m_StoredSpew.Clear(); +} + +static SpewRetval_t MySpewOutputFunc( SpewType_t spewType, char const *pMsg ) +{ + AUTO_LOCK( g_StgoredSpewMutex ); + Color c = *GetSpewOutputColor(); + s_ShaderSystem.BufferSpew( spewType, c, pMsg ); + + switch( spewType ) + { + case SPEW_MESSAGE: + case SPEW_WARNING: + case SPEW_LOG: + return SPEW_CONTINUE; + + case SPEW_ASSERT: + case SPEW_ERROR: + default: + return SPEW_DEBUGGER; + } +} + + +//----------------------------------------------------------------------------- +// Deals with shader draw +//----------------------------------------------------------------------------- +void CShaderSystem::PrepForShaderDraw( IShader *pShader, + IMaterialVar** ppParams, ShaderRenderState_t* pRenderState, int nModulation ) +{ + Assert( !m_pRenderState ); + + // 360 runs the console remotely, spew cannot cause the matsys to be reentrant + // 360 sidesteps the other negative affect that *all* buffered spew redirects as warning text + if ( IsPC() || !IsX360() ) + { + Assert( !m_SaveSpewOutput ); + m_SaveSpewOutput = GetSpewOutputFunc(); + SpewOutputFunc( MySpewOutputFunc ); + } + + m_pRenderState = pRenderState; + m_nModulation = nModulation; + m_nRenderPass = 0; +} + +void CShaderSystem::DoneWithShaderDraw() +{ + if ( IsPC() || !IsX360() ) + { + SpewOutputFunc( m_SaveSpewOutput ); + PrintBufferedSpew(); + m_SaveSpewOutput = NULL; + } + + m_pRenderState = NULL; +} + + +//----------------------------------------------------------------------------- +// Call the SHADER_PARAM_INIT block of the shaders +//----------------------------------------------------------------------------- +void CShaderSystem::InitShaderParameters( IShader *pShader, IMaterialVar **params, const char *pMaterialName ) +{ + // Let the derived class do its thing + PrepForShaderDraw( pShader, params, 0, 0 ); + pShader->InitShaderParams( params, pMaterialName ); + DoneWithShaderDraw(); + + // Set up color + alpha defaults + if (!params[COLOR]->IsDefined()) + { + params[COLOR]->SetVecValue( 1.0f, 1.0f, 1.0f ); + } + + if (!params[ALPHA]->IsDefined()) + { + params[ALPHA]->SetFloatValue( 1.0f ); + } + + // Initialize all shader params based on their type... + int i; + for ( i = pShader->GetNumParams(); --i >= 0; ) + { + // Don't initialize parameters that are already set up + if (params[i]->IsDefined()) + continue; + + int type = pShader->GetParamType( i ); + switch( type ) + { + case SHADER_PARAM_TYPE_TEXTURE: + // Do nothing; we'll be loading in a string later + break; + case SHADER_PARAM_TYPE_STRING: + // Do nothing; we'll be loading in a string later + break; + case SHADER_PARAM_TYPE_MATERIAL: + params[i]->SetMaterialValue( NULL ); + break; + case SHADER_PARAM_TYPE_BOOL: + case SHADER_PARAM_TYPE_INTEGER: + params[i]->SetIntValue( 0 ); + break; + case SHADER_PARAM_TYPE_COLOR: + params[i]->SetVecValue( 1.0f, 1.0f, 1.0f ); + break; + case SHADER_PARAM_TYPE_VEC2: + params[i]->SetVecValue( 0.0f, 0.0f ); + break; + case SHADER_PARAM_TYPE_VEC3: + params[i]->SetVecValue( 0.0f, 0.0f, 0.0f ); + break; + case SHADER_PARAM_TYPE_VEC4: + params[i]->SetVecValue( 0.0f, 0.0f, 0.0f, 0.0f ); + break; + case SHADER_PARAM_TYPE_FLOAT: + params[i]->SetFloatValue( 0 ); + break; + case SHADER_PARAM_TYPE_FOURCC: + params[i]->SetFourCCValue( 0, 0 ); + break; + case SHADER_PARAM_TYPE_MATRIX: + { + VMatrix identity; + MatrixSetIdentity( identity ); + params[i]->SetMatrixValue( identity ); + } + break; + case SHADER_PARAM_TYPE_MATRIX4X2: + { + VMatrix identity; + MatrixSetIdentity( identity ); + params[i]->SetMatrixValue( identity ); + } + break; + + + default: + Assert(0); + } + } +} + + +//----------------------------------------------------------------------------- +// Call the SHADER_INIT block of the shaders +//----------------------------------------------------------------------------- +void CShaderSystem::InitShaderInstance( IShader *pShader, IMaterialVar **params, const char *pMaterialName, const char *pTextureGroupName ) +{ + // Let the derived class do its thing + PrepForShaderDraw( pShader, params, 0, 0 ); + pShader->InitShaderInstance( params, ShaderSystem(), pMaterialName, pTextureGroupName ); + DoneWithShaderDraw(); +} + + +//----------------------------------------------------------------------------- +// Compute snapshots for all combinations of alpha + color modulation +//----------------------------------------------------------------------------- +void CShaderSystem::InitRenderStateFlags( ShaderRenderState_t* pRenderState, int numParams, IMaterialVar **params ) +{ + // Compute vertex format and flags + pRenderState->m_Flags = 0; + + // Make sure the shader don't force these flags. . they are automatically computed. + Assert( !( pRenderState->m_Flags & SHADER_OPACITY_TRANSLUCENT ) ); + Assert( !( pRenderState->m_Flags & SHADER_OPACITY_ALPHATEST ) ); + Assert( !( pRenderState->m_Flags & SHADER_OPACITY_OPAQUE ) ); + + // If we are in release mode, just go ahead and clear in case the above is screwed up. + pRenderState->m_Flags &= ~SHADER_OPACITY_MASK; + +/* + // HACK: Also kind of gross; turn off bump lightmapping for low-end + if (g_config.bUseGraphics && !HardwareConfig()->SupportsVertexAndPixelShaders()) + { + pRenderState->m_Flags &= ~SHADER_NEEDS_BUMPED_LIGHTMAPS; + } +*/ +/* + // HACK: more grossness!!! turn off bump lightmapping if we don't have a bumpmap + // Shaders should specify SHADER_NEEDS_BUMPED_LIGHTMAPS if they might need a bumpmap, + // and this'll take care of getting rid of it if it isn't there. + if( pRenderState->m_Flags & SHADER_NEEDS_BUMPED_LIGHTMAPS ) + { + pRenderState->m_Flags &= ~SHADER_NEEDS_BUMPED_LIGHTMAPS; + for( int i = 0; i < numParams; i++ ) + { + if( stricmp( params[i]->GetName(), "$bumpmap" ) == 0 ) + { + if( params[i]->IsDefined() ) + { + const char *blah = params[i]->GetStringValue(); + pRenderState->m_Flags |= SHADER_NEEDS_BUMPED_LIGHTMAPS; + break; + } + } + } + } +*/ +} + + +//----------------------------------------------------------------------------- +// Computes flags from a particular snapshot +//----------------------------------------------------------------------------- +void CShaderSystem::ComputeRenderStateFlagsFromSnapshot( ShaderRenderState_t* pRenderState ) +{ + // When computing the flags, use the snapshot that has no alpha or color + // modulation. When asking for translucency, we'll have to check for + // alpha modulation in addition to checking the TRANSLUCENT flag. + + // I have to do it this way because I'm really wanting to treat alpha + // modulation as a dynamic state, even though it's being used to compute + // shadow state. I still want to use it to compute shadow state though + // because it's somewhat complicated code that I'd rather precache. + + StateSnapshot_t snapshot = pRenderState->m_pSnapshots[0].m_Snapshot[0]; + + // Automatically compute if the snapshot is transparent or not + if ( g_pShaderAPI->IsTranslucent( snapshot ) ) + { + pRenderState->m_Flags |= SHADER_OPACITY_TRANSLUCENT; + } + else + { + if ( g_pShaderAPI->IsAlphaTested( snapshot ) ) + { + pRenderState->m_Flags |= SHADER_OPACITY_ALPHATEST; + } + else + { + pRenderState->m_Flags |= SHADER_OPACITY_OPAQUE; + } + } + +#ifdef _DEBUG + if( pRenderState->m_Flags & SHADER_OPACITY_TRANSLUCENT ) + { + Assert( !( pRenderState->m_Flags & SHADER_OPACITY_ALPHATEST ) ); + Assert( !( pRenderState->m_Flags & SHADER_OPACITY_OPAQUE ) ); + } + if( pRenderState->m_Flags & SHADER_OPACITY_ALPHATEST ) + { + Assert( !( pRenderState->m_Flags & SHADER_OPACITY_TRANSLUCENT ) ); + Assert( !( pRenderState->m_Flags & SHADER_OPACITY_OPAQUE ) ); + } + if( pRenderState->m_Flags & SHADER_OPACITY_OPAQUE ) + { + Assert( !( pRenderState->m_Flags & SHADER_OPACITY_ALPHATEST ) ); + Assert( !( pRenderState->m_Flags & SHADER_OPACITY_TRANSLUCENT ) ); + } +#endif +} + + +//----------------------------------------------------------------------------- +// Initializes state snapshots +//----------------------------------------------------------------------------- +#ifdef _DEBUG +#pragma warning (disable:4189) +#endif + +int CShaderSystem::GetModulationSnapshotCount( IMaterialVar **params ) +{ + int nSnapshotCount = SnapshotTypeCount(); + if ( !MaterialSystem()->CanUseEditorMaterials() ) + { + if( !IsFlag2Set( params, MATERIAL_VAR2_NEEDS_BAKED_LIGHTING_SNAPSHOTS ) ) + { + nSnapshotCount /= 2; + } + } + + return nSnapshotCount; +} + +void CShaderSystem::InitStateSnapshots( IShader *pShader, IMaterialVar **params, ShaderRenderState_t* pRenderState ) +{ +#ifdef _DEBUG + if ( IsFlagSet( params, MATERIAL_VAR_DEBUG ) ) + { + // Putcher breakpoint here to catch the rendering of a material + // marked for debugging ($debug = 1 in a .vmt file) shadow state version + int x = 0; + } +#endif + + // Store off the current alpha + color modulations + float alpha; + float color[3]; + params[COLOR]->GetVecValue( color, 3 ); + alpha = params[ALPHA]->GetFloatValue( ); + bool bBakedLighting = IsFlag2Set( params, MATERIAL_VAR2_USE_FIXED_FUNCTION_BAKED_LIGHTING ); + bool bFlashlight = IsFlag2Set( params, MATERIAL_VAR2_USE_FLASHLIGHT ); + bool bEditor = IsFlag2Set( params, MATERIAL_VAR2_USE_EDITOR ); +// bool bSupportsFlashlight = IsFlag2Set( params, MATERIAL_VAR2_SUPPORTS_FLASHLIGHT ); + float white[3] = { 1, 1, 1 }; + float grey[3] = { .5, .5, .5 }; + + int nSnapshotCount = GetModulationSnapshotCount( params ); + + // If the current mod does not use the flashlight, skip all flashlight snapshots (saves a ton of memory) + bool bModUsesFlashlight = ( mat_supportflashlight.GetInt() != 0 ); + + for (int i = 0; i < nSnapshotCount; ++i) + { + if ( ( i & SHADER_USING_FLASHLIGHT ) && + !bModUsesFlashlight ) + { + pRenderState->m_pSnapshots[i].m_nPassCount = 0; + continue; + } + + // Set modulation to force particular code paths + if (i & SHADER_USING_COLOR_MODULATION) + { + params[COLOR]->SetVecValue( grey, 3 ); + } + else + { + params[COLOR]->SetVecValue( white, 3 ); + } + + if (i & SHADER_USING_ALPHA_MODULATION) + { + params[ALPHA]->SetFloatValue( grey[0] ); + } + else + { + params[ALPHA]->SetFloatValue( white[0] ); + } + + if ( i & SHADER_USING_FLASHLIGHT ) + { +// if ( !bSupportsFlashlight ) +// { +// pRenderState->m_pSnapshots[i].m_nPassCount = 0; +// continue; +// } + SET_FLAGS2( MATERIAL_VAR2_USE_FLASHLIGHT ); + } + else + { + CLEAR_FLAGS2( MATERIAL_VAR2_USE_FLASHLIGHT ); + } + + if ( i & SHADER_USING_EDITOR ) + { + SET_FLAGS2( MATERIAL_VAR2_USE_EDITOR ); + } + else + { + CLEAR_FLAGS2( MATERIAL_VAR2_USE_EDITOR ); + } + + if ( i & SHADER_USING_FIXED_FUNCTION_BAKED_LIGHTING ) + { + SET_FLAGS2( MATERIAL_VAR2_USE_FIXED_FUNCTION_BAKED_LIGHTING ); + } + else + { + CLEAR_FLAGS2( MATERIAL_VAR2_USE_FIXED_FUNCTION_BAKED_LIGHTING ); + } + + PrepForShaderDraw( pShader, params, pRenderState, i ); + + // Now snapshot how we're going to draw + pRenderState->m_pSnapshots[i].m_nPassCount = 0; + pShader->DrawElements( params, i, g_pShaderShadow, 0, VERTEX_COMPRESSION_NONE, &(pRenderState->m_pSnapshots[i].m_pContextData[0] ) ); + DoneWithShaderDraw(); + } + + // Restore alpha + color modulation + params[COLOR]->SetVecValue( color, 3 ); + params[ALPHA]->SetFloatValue( alpha ); + if( bBakedLighting ) + { + SET_FLAGS2( MATERIAL_VAR2_USE_FIXED_FUNCTION_BAKED_LIGHTING ); + } + else + { + CLEAR_FLAGS2( MATERIAL_VAR2_USE_FIXED_FUNCTION_BAKED_LIGHTING ); + } + + if( bEditor ) + { + SET_FLAGS2( MATERIAL_VAR2_USE_EDITOR ); + } + else + { + CLEAR_FLAGS2( MATERIAL_VAR2_USE_EDITOR ); + } + + if( bFlashlight ) + { + SET_FLAGS2( MATERIAL_VAR2_USE_FLASHLIGHT ); + } + else + { + CLEAR_FLAGS2( MATERIAL_VAR2_USE_FLASHLIGHT ); + } +} + +#ifdef _DEBUG +#pragma warning (default:4189) +#endif + +//----------------------------------------------------------------------------- +// Helper to count texture coordinates +//----------------------------------------------------------------------------- +static int NumTextureCoordinates( VertexFormat_t vertexFormat ) +{ + // FIXME: this is a duplicate of the function in meshdx8.cpp + int nTexCoordCount = 0; + for ( int i = 0; i < VERTEX_MAX_TEXTURE_COORDINATES; ++i ) + { + if ( TexCoordSize( i, vertexFormat ) == 0 ) + continue; + ++nTexCoordCount; + } + return nTexCoordCount; +} + +//----------------------------------------------------------------------------- +// Displays the vertex format +//----------------------------------------------------------------------------- +static void OutputVertexFormat( VertexFormat_t format ) +{ + // FIXME: this is a duplicate of the function in meshdx8.cpp + VertexCompressionType_t compressionType = CompressionType( format ); + + if( format & VERTEX_POSITION ) + { + Warning( "VERTEX_POSITION|" ); + } + if( format & VERTEX_NORMAL ) + { + if ( compressionType == VERTEX_COMPRESSION_ON ) + Warning( "VERTEX_NORMAL[COMPRESSED]|" ); + else + Warning( "VERTEX_NORMAL|" ); + } + if( format & VERTEX_COLOR ) + { + Warning( "VERTEX_COLOR|" ); + } + if( format & VERTEX_SPECULAR ) + { + Warning( "VERTEX_SPECULAR|" ); + } + if( format & VERTEX_TANGENT_S ) + { + Warning( "VERTEX_TANGENT_S|" ); + } + if( format & VERTEX_TANGENT_T ) + { + Warning( "VERTEX_TANGENT_T|" ); + } + if( format & VERTEX_BONE_INDEX ) + { + Warning( "VERTEX_BONE_INDEX|" ); + } + if( format & VERTEX_FORMAT_VERTEX_SHADER ) + { + Warning( "VERTEX_FORMAT_VERTEX_SHADER|" ); + } + Warning( "\nBone weights: %d\n", NumBoneWeights( format ) ); + Warning( "user data size: %d (%s)\n", UserDataSize( format ), + ( CompressionType( format ) == VERTEX_COMPRESSION_ON ? "compressed" : "uncompressed" ) ); + Warning( "num tex coords: %d\n", NumTextureCoordinates( format ) ); + // NOTE: This doesn't print texcoord sizes. +} + + +#ifdef _DEBUG +static bool IsVertexFormatSubsetOfVertexformat( VertexFormat_t subset, VertexFormat_t superset ) +{ + subset &= ~VERTEX_FORMAT_USE_EXACT_FORMAT; + superset &= ~VERTEX_FORMAT_USE_EXACT_FORMAT; + + // Test the flags + if( VertexFlags( subset ) & VertexFlags( ~superset ) ) + return false; + + // Test bone weights + if( NumBoneWeights( subset ) > NumBoneWeights( superset ) ) + return false; + + // Test user data size + if( UserDataSize( subset ) > UserDataSize( superset ) ) + return false; + + // Test the texcoord dimensions + for( int i = 0; i < VERTEX_MAX_TEXTURE_COORDINATES; i++ ) + { + if( TexCoordSize( i, subset ) > TexCoordSize( i, superset ) ) + return false; + } + + return true; +} +#endif + + +//----------------------------------------------------------------------------- +// Adds state snapshots to the render list +//----------------------------------------------------------------------------- +static void AddSnapshotsToList( RenderPassList_t *pPassList, int &nSnapshotID, StateSnapshot_t *pSnapshots ) +{ + int nNumPassSnapshots = pPassList->m_nPassCount; + for( int i = 0; i < nNumPassSnapshots; ++i ) + { + pSnapshots[nSnapshotID] = pPassList->m_Snapshot[i]; + nSnapshotID++; + } +} + + +//----------------------------------------------------------------------------- +// Computes vertex format + usage from a particular snapshot +//----------------------------------------------------------------------------- +bool CShaderSystem::ComputeVertexFormatFromSnapshot( IMaterialVar **params, ShaderRenderState_t* pRenderState ) +{ + // When computing the usage, use the snapshot that has no alpha or color + // modulation. We need the usage + format to be the same for all + // combinations of alpha + color modulation, though, or we are asking for + // trouble. + int nModulationSnapshotCount = GetModulationSnapshotCount( params ); + int numSnapshots = pRenderState->m_pSnapshots[0].m_nPassCount; + if (nModulationSnapshotCount >= SHADER_USING_FLASHLIGHT) + { + numSnapshots += pRenderState->m_pSnapshots[SHADER_USING_FLASHLIGHT].m_nPassCount; + } + if ( MaterialSystem()->CanUseEditorMaterials() ) + { + numSnapshots += pRenderState->m_pSnapshots[SHADER_USING_EDITOR].m_nPassCount; + } + + StateSnapshot_t* pSnapshots = (StateSnapshot_t*)stackalloc( + numSnapshots * sizeof(StateSnapshot_t) ); + + int snapshotID = 0; + AddSnapshotsToList( &pRenderState->m_pSnapshots[0], snapshotID, pSnapshots ); + if (nModulationSnapshotCount >= SHADER_USING_FLASHLIGHT) + { + AddSnapshotsToList( &pRenderState->m_pSnapshots[SHADER_USING_FLASHLIGHT], snapshotID, pSnapshots ); + } + if ( MaterialSystem()->CanUseEditorMaterials() ) + { + AddSnapshotsToList( &pRenderState->m_pSnapshots[SHADER_USING_EDITOR], snapshotID, pSnapshots ); + } + + Assert( snapshotID == numSnapshots ); + + pRenderState->m_VertexUsage = g_pShaderAPI->ComputeVertexUsage( numSnapshots, pSnapshots ); + pRenderState->m_MorphFormat = g_pShaderAPI->ComputeMorphFormat( numSnapshots, pSnapshots ); + +#ifdef _DEBUG + // Make sure all modulation combinations match vertex usage + for ( int mod = 1; mod < nModulationSnapshotCount; ++mod ) + { + int numSnapshotsTest = pRenderState->m_pSnapshots[mod].m_nPassCount; + StateSnapshot_t* pSnapshotsTest = (StateSnapshot_t*)_alloca( + numSnapshotsTest * sizeof(StateSnapshot_t) ); + + for (int i = 0; i < numSnapshotsTest; ++i) + { + pSnapshotsTest[i] = pRenderState->m_pSnapshots[mod].m_Snapshot[i]; + } + + VertexFormat_t usageTest = g_pShaderAPI->ComputeVertexUsage( numSnapshotsTest, pSnapshotsTest ); + Assert( IsVertexFormatSubsetOfVertexformat( usageTest, pRenderState->m_VertexUsage ) ); + } +#endif + + if ( IsPC() ) + { + pRenderState->m_VertexFormat = g_pShaderAPI->ComputeVertexFormat( numSnapshots, pSnapshots ); + } + else + { + pRenderState->m_VertexFormat = pRenderState->m_VertexUsage; + } + + return true; +} + + +//----------------------------------------------------------------------------- +// go through each param and make sure it is the right type, load textures, +// compute state snapshots and vertex types, etc. +//----------------------------------------------------------------------------- +bool CShaderSystem::InitRenderState( IShader *pShader, int numParams, IMaterialVar **params, ShaderRenderState_t* pRenderState, char const* pMaterialName ) +{ + Assert( !m_pRenderState ); + + // Initialize render state flags + InitRenderStateFlags( pRenderState, numParams, params ); + + // Compute state snapshots for each combination of alpha + color + InitStateSnapshots( pShader, params, pRenderState ); + + // Compute other infomation for the render state based on snapshots + if (pRenderState->m_pSnapshots[0].m_nPassCount == 0) + { + Warning( "Material \"%s\":\n No render states in shader \"%s\"\n", pMaterialName, pShader->GetName() ); + return false; + } + + // Set a couple additional flags based on the render state + ComputeRenderStateFlagsFromSnapshot( pRenderState ); + + // Compute the vertex format + usage from the snapshot + if ( !ComputeVertexFormatFromSnapshot( params, pRenderState ) ) + { + // warn.. return a null render state... + Warning("Material \"%s\":\n Shader \"%s\" can't be used with models!\n", pMaterialName, pShader->GetName() ); + CleanupRenderState( pRenderState ); + return false; + } + return true; +} + +// When you're done with the shader, be sure to call this to clean up +void CShaderSystem::CleanupRenderState( ShaderRenderState_t* pRenderState ) +{ + if (pRenderState) + { + int nSnapshotCount = SnapshotTypeCount(); + // kill context data + // Indicate no passes for any of the snapshot lists + RenderPassList_t *pTemp = pRenderState->m_pSnapshots; + for(int i = 0; i < nSnapshotCount; i++ ) + { + for(int j = 0 ; j < pRenderState->m_pSnapshots[i].m_nPassCount; j++ ) + if ( pTemp[i].m_pContextData[j] ) + { + delete pTemp[i].m_pContextData[j]; + pTemp[i].m_pContextData[j] = NULL; + } + pRenderState->m_pSnapshots[i].m_nPassCount = 0; + } + } +} + + +//----------------------------------------------------------------------------- +// Does the rendering! +//----------------------------------------------------------------------------- +void CShaderSystem::DrawElements( IShader *pShader, IMaterialVar **params, + ShaderRenderState_t* pRenderState, + VertexCompressionType_t vertexCompression, + uint32 nMaterialVarChangeTimeStamp ) +{ + VPROF("CShaderSystem::DrawElements"); + + g_pShaderAPI->InvalidateDelayedShaderConstants(); + // Compute modulation... + int mod = pShader->ComputeModulationFlags( params, g_pShaderAPI ); + + // No snapshots? do nothing. + if ( pRenderState->m_pSnapshots[mod].m_nPassCount == 0 ) + return; + + // If we're rendering a model, gotta have skinning matrices + int materialVarFlags = params[FLAGS]->GetIntValue(); + if ( (( materialVarFlags & MATERIAL_VAR_MODEL ) != 0) || + ( IsFlag2Set( params, MATERIAL_VAR2_SUPPORTS_HW_SKINNING ) && ( g_pShaderAPI->GetCurrentNumBones() > 0 )) ) + { + g_pShaderAPI->SetSkinningMatrices( ); + } + + // FIXME: need one conditional that we calculate once a frame for debug or not with everything debug under that. +#ifndef DX_TO_GL_ABSTRACTION + if ( ( ( g_config.bMeasureFillRate || g_config.bVisualizeFillRate ) && + ( ( materialVarFlags & MATERIAL_VAR_USE_IN_FILLRATE_MODE ) == 0 ) ) ) + { + DrawMeasureFillRate( pRenderState, mod, vertexCompression ); + } + else +#endif + if( ( g_config.bShowNormalMap || g_config.nShowMipLevels == 2 ) && + ( IsFlag2Set( params, MATERIAL_VAR2_LIGHTING_BUMPED_LIGHTMAP ) || + IsFlag2Set( params, MATERIAL_VAR2_DIFFUSE_BUMPMAPPED_MODEL ) ) ) + { + DrawNormalMap( pShader, params, vertexCompression ); + } +#if defined(DEBUG_DEPTH) + else if ( mat_debugdepth.GetInt() && ((materialVarFlags & MATERIAL_VAR_NO_DEBUG_OVERRIDE) == 0) ) + { + int nIndex = 0; + if ( IsFlagSet( params, MATERIAL_VAR_DECAL ) ) + { + nIndex |= 0x1; + } + IMaterialInternal *pDebugMaterial = m_pDebugMaterials[ MATERIAL_DEBUG_DEPTH + nIndex ]; + if ( !g_pShaderAPI->IsDepthWriteEnabled( pRenderState->m_Snapshots[mod].m_Snapshot[0] ) ) + { + pDebugMaterial = m_pDebugMaterials[MATERIAL_DEBUG_WIREFRAME]; + } + + DrawUsingMaterial( pDebugMaterial, vertexCompression ); + } +#endif + else + { + g_pShaderAPI->SetDefaultState(); + + // If we're rendering flat, turn on flat mode... + if (materialVarFlags & MATERIAL_VAR_FLAT) + { + g_pShaderAPI->ShadeMode( SHADER_FLAT ); + } + + PrepForShaderDraw( pShader, params, pRenderState, mod ); + g_pShaderAPI->BeginPass( CurrentStateSnapshot() ); + + CBasePerMaterialContextData ** pContextDataPtr = + &( m_pRenderState->m_pSnapshots[m_nModulation].m_pContextData[m_nRenderPass] ); + + if ( *pContextDataPtr && ( (*pContextDataPtr)->m_nVarChangeID != nMaterialVarChangeTimeStamp ) ) + { + (*pContextDataPtr)->m_bMaterialVarsChanged = true; + (*pContextDataPtr)->m_nVarChangeID = nMaterialVarChangeTimeStamp; + } + + pShader->DrawElements( + params, mod, 0, g_pShaderAPI, vertexCompression, + &( m_pRenderState->m_pSnapshots[m_nModulation].m_pContextData[m_nRenderPass] ) ); + DoneWithShaderDraw(); + } + + MaterialSystem()->ForceDepthFuncEquals( false ); +} + + +//----------------------------------------------------------------------------- +// Are we using graphics? +//----------------------------------------------------------------------------- +bool CShaderSystem::IsUsingGraphics() const +{ + // YWB Hack if running with -noshaderapi/-makereslists this forces materials to "precache" which means they will resolve their .vtf files for + // things like normal/height/dudv maps... + if ( m_bForceUsingGraphicsReturnTrue ) + return true; + + return g_pShaderDevice->IsUsingGraphics(); +} + + +//----------------------------------------------------------------------------- +// Are we using the editor materials? +//----------------------------------------------------------------------------- +bool CShaderSystem::CanUseEditorMaterials() const +{ + return MaterialSystem()->CanUseEditorMaterials(); +} + + +//----------------------------------------------------------------------------- +// Takes a snapshot +//----------------------------------------------------------------------------- +void CShaderSystem::TakeSnapshot( ) +{ + Assert( m_pRenderState ); + Assert( m_nModulation < SnapshotTypeCount() ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + //enable linear->gamma srgb conversion lookup texture + g_pShaderShadow->EnableTexture( SHADER_SAMPLER15, true ); + g_pShaderShadow->EnableSRGBRead( SHADER_SAMPLER15, true ); + } + + RenderPassList_t& snapshotList = m_pRenderState->m_pSnapshots[m_nModulation]; + + // Take a snapshot... + snapshotList.m_Snapshot[snapshotList.m_nPassCount] = g_pShaderAPI->TakeSnapshot(); + ++snapshotList.m_nPassCount; +} + + +//----------------------------------------------------------------------------- +// Draws a snapshot +//----------------------------------------------------------------------------- +void CShaderSystem::DrawSnapshot( bool bMakeActualDrawCall ) +{ + Assert( m_pRenderState ); + RenderPassList_t& snapshotList = m_pRenderState->m_pSnapshots[m_nModulation]; + + int nPassCount = snapshotList.m_nPassCount; + Assert( m_nRenderPass < nPassCount ); + + if ( bMakeActualDrawCall ) + { + g_pShaderAPI->RenderPass( m_nRenderPass, nPassCount ); + } + + g_pShaderAPI->InvalidateDelayedShaderConstants(); + if (++m_nRenderPass < nPassCount) + { + g_pShaderAPI->BeginPass( CurrentStateSnapshot() ); + } +} + + + +//----------------------------------------------------------------------------- +// +// Debugging material methods below +// +//----------------------------------------------------------------------------- + + +//----------------------------------------------------------------------------- +// Draws a using a particular material.. +//----------------------------------------------------------------------------- +void CShaderSystem::DrawUsingMaterial( IMaterialInternal *pMaterial, VertexCompressionType_t vertexCompression ) +{ + ShaderRenderState_t *pRenderState = pMaterial->GetRenderState(); + g_pShaderAPI->SetDefaultState( ); + + IShader *pShader = pMaterial->GetShader(); + int nMod = pShader->ComputeModulationFlags( pMaterial->GetShaderParams(), g_pShaderAPI ); + PrepForShaderDraw( pShader, pMaterial->GetShaderParams(), pRenderState, nMod ); + g_pShaderAPI->BeginPass( pRenderState->m_pSnapshots[nMod].m_Snapshot[0] ); + pShader->DrawElements( pMaterial->GetShaderParams(), nMod, 0, g_pShaderAPI, vertexCompression, + &( pRenderState->m_pSnapshots[nMod].m_pContextData[0] ) ); + DoneWithShaderDraw( ); +} + + +//----------------------------------------------------------------------------- +// Copies material vars +//----------------------------------------------------------------------------- +void CShaderSystem::CopyMaterialVarToDebugShader( IMaterialInternal *pDebugMaterial, IShader *pShader, IMaterialVar **ppParams, const char *pSrcVarName, const char *pDstVarName ) +{ + bool bFound; + IMaterialVar *pMaterialVar = pDebugMaterial->FindVar( pDstVarName ? pDstVarName : pSrcVarName, &bFound ); + Assert( bFound ); + + for( int i = pShader->GetNumParams(); --i >= 0; ) + { + if( !Q_stricmp( ppParams[i]->GetName( ), pSrcVarName ) ) + { + pMaterialVar->CopyFrom( ppParams[i] ); + return; + } + } + + pMaterialVar->SetUndefined(); +} + + +//----------------------------------------------------------------------------- +// Draws the puppy in fill rate mode... +//----------------------------------------------------------------------------- +void CShaderSystem::DrawMeasureFillRate( ShaderRenderState_t* pRenderState, int mod, VertexCompressionType_t vertexCompression ) +{ + int nPassCount = pRenderState->m_pSnapshots[mod].m_nPassCount; + + // We require the use of a vertex shader rather than fixed function transforms + Assert( (VertexFlags(pRenderState->m_VertexFormat) & VERTEX_FORMAT_VERTEX_SHADER) != 0 ); + + IMaterialInternal *pMaterial = m_pDebugMaterials[ MATERIAL_FILL_RATE ]; + + bool bFound; + IMaterialVar *pMaterialVar = pMaterial->FindVar( "$passcount", &bFound ); + pMaterialVar->SetIntValue( nPassCount ); + DrawUsingMaterial( pMaterial, vertexCompression ); +} + + +//----------------------------------------------------------------------------- +// Draws normalmaps +//----------------------------------------------------------------------------- +void CShaderSystem::DrawNormalMap( IShader *pShader, IMaterialVar **ppParams, VertexCompressionType_t vertexCompression ) +{ + IMaterialInternal *pDebugMaterial = m_pDebugMaterials[MATERIAL_DEBUG_NORMALMAP]; + + if( !g_config.m_bFastNoBump ) + { + CopyMaterialVarToDebugShader( pDebugMaterial, pShader, ppParams, "$bumpmap" ); + CopyMaterialVarToDebugShader( pDebugMaterial, pShader, ppParams, "$bumpframe" ); + CopyMaterialVarToDebugShader( pDebugMaterial, pShader, ppParams, "$bumptransform" ); + } + else + { + bool bFound; + IMaterialVar *pMaterialVar = pDebugMaterial->FindVar( "$bumpmap", &bFound ); + Assert( bFound ); + + pMaterialVar->SetUndefined(); + } + + DrawUsingMaterial( pDebugMaterial, vertexCompression ); +} + +//----------------------------------------------------------------------------- +// Draws envmapmask +//----------------------------------------------------------------------------- +bool CShaderSystem::DrawEnvmapMask( IShader *pShader, IMaterialVar **ppParams, + ShaderRenderState_t* pRenderState, VertexCompressionType_t vertexCompression ) +{ + // FIXME! Make this work with fixed function. + int vertexFormat = pRenderState->m_VertexFormat; + bool bUsesVertexShader = (VertexFlags(vertexFormat) & VERTEX_FORMAT_VERTEX_SHADER) != 0; + if( !bUsesVertexShader ) + { + Assert( 0 ); + return false; + } + IMaterialInternal *pDebugMaterial = m_pDebugMaterials[ MATERIAL_DEBUG_ENVMAPMASK ]; + + bool bFound; + IMaterialVar *pMaterialVar = pDebugMaterial->FindVar( "$showalpha", &bFound ); + Assert( bFound ); + + if( IsFlagSet( ppParams, MATERIAL_VAR_NORMALMAPALPHAENVMAPMASK ) ) + { + // $bumpmap + CopyMaterialVarToDebugShader( pDebugMaterial, pShader, ppParams, "$bumpmap", "$basetexture" ); + CopyMaterialVarToDebugShader( pDebugMaterial, pShader, ppParams, "$bumpframe", "$frame" ); + CopyMaterialVarToDebugShader( pDebugMaterial, pShader, ppParams, "$bumptransform", "$basetexturetransform" ); + pMaterialVar->SetIntValue( 1 ); + } + else if( IsFlagSet( ppParams, MATERIAL_VAR_BASEALPHAENVMAPMASK ) ) + { + // $basealphaenvmapmask + CopyMaterialVarToDebugShader( pDebugMaterial, pShader, ppParams, "$basetexture" ); + CopyMaterialVarToDebugShader( pDebugMaterial, pShader, ppParams, "$frame" ); + CopyMaterialVarToDebugShader( pDebugMaterial, pShader, ppParams, "$basetexturetransform" ); + pMaterialVar->SetIntValue( 1 ); + } + else + { + // $envmapmask + CopyMaterialVarToDebugShader( pDebugMaterial, pShader, ppParams, "$envmapmask", "$basetexture" ); + CopyMaterialVarToDebugShader( pDebugMaterial, pShader, ppParams, "$envmapmaskframe", "$frame" ); + CopyMaterialVarToDebugShader( pDebugMaterial, pShader, ppParams, "$envmapmasktransform", "$basetexturetransform" ); + pMaterialVar->SetIntValue( 0 ); + } + + if( pDebugMaterial->FindVar( "$basetexture", NULL )->IsTexture() ) + { + DrawUsingMaterial( pDebugMaterial, vertexCompression ); + return true; + } + else + { + return false; + } +} + +//----------------------------------------------------------------------------- +// +// Methods of IShaderSystem lie below +// +//----------------------------------------------------------------------------- + + +ShaderAPITextureHandle_t CShaderSystem::GetShaderAPITextureBindHandle( ITexture *pTexture, int nFrame, int nTextureChannel ) +{ + Assert( !IsTextureInternalEnvCubemap( static_cast(pTexture) ) ); + + // Bind away baby + if( pTexture ) + { + // This is ugly. Basically, this is yet another way that textures can be bound. They don't get bound here, + // but the return is only used to bind them for semistatic command buffer building, which doesn't go through + // CTexture::Bind for whatever reason. So let's request the mipmaps here. If you run into this, in a situation + // where we shouldn't be doing the request, we could relocate this code to the appropriate callsites instead. + ITextureInternal* pTex = assert_cast< ITextureInternal* >( pTexture ); + TextureManager()->RequestAllMipmaps( pTex ); + + return pTex->GetTextureHandle( nFrame, nTextureChannel ); + } + else + return INVALID_SHADERAPI_TEXTURE_HANDLE; +} + +//----------------------------------------------------------------------------- +// Binds a texture +//----------------------------------------------------------------------------- +void CShaderSystem::BindTexture( Sampler_t sampler1, ITexture *pTexture, int nFrame /* = 0 */ ) +{ + // The call to IMaterialVar::GetTextureValue should have converted this to a real thing + Assert( !IsTextureInternalEnvCubemap( static_cast(pTexture) ) ); + + // Bind away baby + if( pTexture ) + { + static_cast(pTexture)->Bind( sampler1, nFrame ); + } +} + + +void CShaderSystem::BindTexture( Sampler_t sampler1, Sampler_t sampler2, ITexture *pTexture, int nFrame /* = 0 */ ) +{ + // The call to IMaterialVar::GetTextureValue should have converted this to a real thing + Assert( !IsTextureInternalEnvCubemap( static_cast(pTexture) ) ); + + // Bind away baby + if( pTexture ) + { + if ( sampler2 == Sampler_t(-1) ) + { + static_cast(pTexture)->Bind( sampler1, nFrame ); + } + else + { + static_cast(pTexture)->Bind( sampler1, nFrame, sampler2 ); + } + } +} + + +//----------------------------------------------------------------------------- +// +// Methods of IShaderInit lie below +// +//----------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +// Loads a texture +//----------------------------------------------------------------------------- +void CShaderSystem::LoadTexture( IMaterialVar *pTextureVar, const char *pTextureGroupName, int nAdditionalCreationFlags /* = 0 */ ) +{ + if (pTextureVar->GetType() != MATERIAL_VAR_TYPE_STRING) + { + // This here will cause 'UNDEFINED' material vars + if (pTextureVar->GetType() != MATERIAL_VAR_TYPE_TEXTURE) + { + pTextureVar->SetTextureValue( TextureManager()->ErrorTexture() ); + } + return; + } + + // In this case, we have to convert the string into a texture value + const char *pName = pTextureVar->GetStringValue(); + + // Fix cases where people stupidly put a slash at the front of the vtf filename in a vmt. Causes trouble elsewhere. + if ( pName[0] == CORRECT_PATH_SEPARATOR || pName[1] == CORRECT_PATH_SEPARATOR ) + ++pName; + + ITextureInternal *pTexture; + + // Force local cubemaps when using the editor + if ( MaterialSystem()->CanUseEditorMaterials() && ( stricmp( pName, "env_cubemap" ) == 0 ) ) + { + pTexture = (ITextureInternal*)-1; + } + else + { + pTexture = static_cast< ITextureInternal * >( MaterialSystem()->FindTexture( pName, pTextureGroupName, false, nAdditionalCreationFlags ) ); + } + + if( !pTexture ) + { + if( !g_pShaderDevice->IsUsingGraphics() && ( stricmp( pName, "env_cubemap" ) != 0 ) ) + { + Warning( "Shader_t::LoadTexture: texture \"%s.vtf\" doesn't exist\n", pName ); + } + pTexture = TextureManager()->ErrorTexture(); + } + + pTextureVar->SetTextureValue( pTexture ); +} + + +//----------------------------------------------------------------------------- +// Loads a bumpmap +//----------------------------------------------------------------------------- +void CShaderSystem::LoadBumpMap( IMaterialVar *pTextureVar, const char *pTextureGroupName ) +{ + Assert( pTextureVar ); + + if (pTextureVar->GetType() != MATERIAL_VAR_TYPE_STRING) + { + // This here will cause 'UNDEFINED' material vars + if (pTextureVar->GetType() != MATERIAL_VAR_TYPE_TEXTURE) + { + pTextureVar->SetTextureValue( TextureManager()->ErrorTexture() ); + } + return; + } + + // Convert a string to the actual texture + ITexture *pTexture; + pTexture = MaterialSystem()->FindTexture( pTextureVar->GetStringValue(), pTextureGroupName, false, 0 ); + + // FIXME: Make a bumpmap error texture + if (!pTexture) + { + pTexture = TextureManager()->ErrorTexture(); + } + + pTextureVar->SetTextureValue( pTexture ); +} + + +//----------------------------------------------------------------------------- +// Loads a cubemap +//----------------------------------------------------------------------------- +void CShaderSystem::LoadCubeMap( IMaterialVar **ppParams, IMaterialVar *pTextureVar, int nAdditionalCreationFlags /* = 0 */ ) +{ + if ( !HardwareConfig()->SupportsCubeMaps() ) + return; + + if ( pTextureVar->GetType() != MATERIAL_VAR_TYPE_STRING ) + { + // This here will cause 'UNDEFINED' material vars + if (pTextureVar->GetType() != MATERIAL_VAR_TYPE_TEXTURE) + { + pTextureVar->SetTextureValue( TextureManager()->ErrorTexture() ); + } + return; + } + + if ( stricmp( pTextureVar->GetStringValue(), "env_cubemap" ) == 0 ) + { + // garymcthack + // don't have to load anything here. . just set the texture value to something + // special that says to use the cubemap entity. + pTextureVar->SetTextureValue( ( ITexture * )-1 ); + SetFlags2( ppParams, MATERIAL_VAR2_USES_ENV_CUBEMAP ); + } + else + { + ITexture *pTexture; + char textureName[MAX_PATH]; + Q_strncpy( textureName, pTextureVar->GetStringValue(), MAX_PATH ); + if ( HardwareConfig()->GetHDRType() != HDR_TYPE_NONE ) + { + // Overload the texture name to ".hdr.vtf" (instead of .vtf) if we are running with + // HDR enabled. + Q_strncat( textureName, ".hdr", MAX_PATH, COPY_ALL_CHARACTERS ); + } + pTexture = MaterialSystem()->FindTexture( textureName, TEXTURE_GROUP_CUBE_MAP, false, nAdditionalCreationFlags ); + + // FIXME: Make a cubemap error texture + if ( !pTexture ) + { + pTexture = TextureManager()->ErrorTexture(); + } + + pTextureVar->SetTextureValue( pTexture ); + } +} + + + diff --git a/materialsystem/shadersystem.h b/materialsystem/shadersystem.h new file mode 100644 index 0000000..bc9bb2e --- /dev/null +++ b/materialsystem/shadersystem.h @@ -0,0 +1,216 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $Header: $ +// $NoKeywords: $ +// +// Shader system: +// The shader system makes a few fundamental assumptions about when +// certain types of state get set. +// +// 1) Anything that can potentially affect vertex format must be set up +// during the shader shadow/snapshot phase +// 2) Anything that we can dynamically mess with (through a material var) +// should happen in the dynamic/render phase +// 3) In general, we try to cache off expensive state pre-processing in +// the shader shadow phase (like texture stage pipeline). +// +//=============================================================================// + +#ifndef SHADERSYSTEM_H +#define SHADERSYSTEM_H + +#ifdef _WIN32 +#pragma once +#endif + +#include "IShaderSystem.h" +#include "shaderlib/BaseShader.h" +#include "materialsystem/materialsystem_config.h" +#include "shaderapi/ishaderapi.h" +#include "materialsystem_global.h" + + +//----------------------------------------------------------------------------- +// forward declarations +//----------------------------------------------------------------------------- +class IMaterialVar; +class TextureManager_t; +class ITextureInternal; +class ShaderSystem_t; +class IMesh; +class IVertexBuffer; +class IIndexBuffer; +class Vector; +enum MaterialPrimitiveType_t; +enum MaterialPropertyTypes_t; +enum MaterialIndexFormat_t; +enum ShaderParamType_t; + + +//----------------------------------------------------------------------------- +// for ShaderRenderState_t::m_flags +//----------------------------------------------------------------------------- +enum +{ + // The flags up here are computed from the shaders themselves + +/* + // lighting flags + SHADER_UNLIT = 0x0000, + SHADER_VERTEX_LIT = 0x0001, + SHADER_NEEDS_LIGHTMAP = 0x0002, + SHADER_NEEDS_BUMPED_LIGHTMAPS = 0x0004, + SHADER_LIGHTING_MASK = 0x0007, +*/ + + // opacity flags + SHADER_OPACITY_ALPHATEST = 0x0010, + SHADER_OPACITY_OPAQUE = 0x0020, + SHADER_OPACITY_TRANSLUCENT = 0x0040, + SHADER_OPACITY_MASK = 0x0070, +}; + + +enum +{ + MAX_RENDER_PASSES = 4 +}; + + +//----------------------------------------------------------------------------- +// Information for a single render pass +//----------------------------------------------------------------------------- +struct RenderPassList_t +{ + int m_nPassCount; + StateSnapshot_t m_Snapshot[MAX_RENDER_PASSES]; + // per material shader-defined state + CBasePerMaterialContextData *m_pContextData[MAX_RENDER_PASSES]; +}; + +struct ShaderRenderState_t +{ + // These are the same, regardless of whether alpha or color mod is used + int m_Flags; // Can't shrink this to a short + VertexFormat_t m_VertexFormat; + VertexFormat_t m_VertexUsage; + MorphFormat_t m_MorphFormat; + + // List of all snapshots + RenderPassList_t *m_pSnapshots; + + +}; + + +//----------------------------------------------------------------------------- +// Used to get the snapshot count +//----------------------------------------------------------------------------- +enum +{ + SNAPSHOT_COUNT_NORMAL = 16, + SNAPSHOT_COUNT_EDITOR = 32, +}; + +inline int SnapshotTypeCount() +{ + return MaterialSystem()->CanUseEditorMaterials() ? SNAPSHOT_COUNT_EDITOR : SNAPSHOT_COUNT_NORMAL; +} + + +//----------------------------------------------------------------------------- +// Utility methods +//----------------------------------------------------------------------------- +inline void SetFlags( IMaterialVar **params, MaterialVarFlags_t _flag ) +{ + params[FLAGS]->SetIntValue( params[FLAGS]->GetIntValueFast() | (_flag) ); +} + +inline void SetFlags2( IMaterialVar **params, MaterialVarFlags2_t _flag ) +{ + params[FLAGS2]->SetIntValue( params[FLAGS2]->GetIntValueFast() | (_flag) ); +} + +inline bool IsFlagSet( IMaterialVar **params, MaterialVarFlags_t _flag ) +{ + return ((params[FLAGS]->GetIntValueFast() & (_flag) ) != 0); +} + +inline bool IsFlag2Set( IMaterialVar **params, MaterialVarFlags2_t _flag ) +{ + return ((params[FLAGS2]->GetIntValueFast() & (_flag) ) != 0); +} + + + +//----------------------------------------------------------------------------- +// Poll params + renderstate +//----------------------------------------------------------------------------- +inline bool IsTranslucent( const ShaderRenderState_t* pRenderState ) +{ + return (pRenderState->m_Flags & SHADER_OPACITY_TRANSLUCENT) != 0; +} + +inline bool IsAlphaTested( ShaderRenderState_t* pRenderState ) +{ + return (pRenderState->m_Flags & SHADER_OPACITY_ALPHATEST) != 0; +} + + +//----------------------------------------------------------------------------- +// The shader system (a singleton) +//----------------------------------------------------------------------------- +abstract_class IShaderSystemInternal : public IShaderInit, public IShaderSystem +{ +public: + // Initialization, shutdown + virtual void Init() = 0; + virtual void Shutdown() = 0; + virtual void ModInit() = 0; + virtual void ModShutdown() = 0; + + // Methods related to reading in shader DLLs + virtual bool LoadShaderDLL( const char *pFullPath ) = 0; + virtual void UnloadShaderDLL( const char *pFullPath ) = 0; + + // Find me a shader! + virtual IShader* FindShader( char const* pShaderName ) = 0; + + // returns strings associated with the shader state flags... + virtual char const* ShaderStateString( int i ) const = 0; + virtual int ShaderStateCount( ) const = 0; + + // Rendering related methods + + // Create debugging materials + virtual void CreateDebugMaterials() = 0; + + // Cleans up the debugging materials + virtual void CleanUpDebugMaterials() = 0; + + // Call the SHADER_PARAM_INIT block of the shaders + virtual void InitShaderParameters( IShader *pShader, IMaterialVar **params, const char *pMaterialName ) = 0; + + // Call the SHADER_INIT block of the shaders + virtual void InitShaderInstance( IShader *pShader, IMaterialVar **params, const char *pMaterialName, const char *pTextureGroupName ) = 0; + + // go through each param and make sure it is the right type, load textures, + // compute state snapshots and vertex types, etc. + virtual bool InitRenderState( IShader *pShader, int numParams, IMaterialVar **params, ShaderRenderState_t* pRenderState, char const* pMaterialName ) = 0; + + // When you're done with the shader, be sure to call this to clean up + virtual void CleanupRenderState( ShaderRenderState_t* pRenderState ) = 0; + + // Draws the shader + virtual void DrawElements( IShader *pShader, IMaterialVar **params, ShaderRenderState_t* pShaderState, VertexCompressionType_t vertexCompression, + uint32 nMaterialVarTimeStamp ) = 0; + + // Used to iterate over all shaders for editing purposes + virtual int ShaderCount() const = 0; + virtual int GetShaders( int nFirstShader, int nCount, IShader **ppShaderList ) const = 0; +}; + + +#endif // SHADERSYSTEM_H diff --git a/materialsystem/stdshaders/AccumBuff4Sample.cpp b/materialsystem/stdshaders/AccumBuff4Sample.cpp new file mode 100644 index 0000000..d20ca3c --- /dev/null +++ b/materialsystem/stdshaders/AccumBuff4Sample.cpp @@ -0,0 +1,114 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//============================================================================= + +#include "BaseVSShader.h" +#include "common_hlsl_cpp_consts.h" +#include "screenspaceeffect_vs20.inc" +#include "accumbuff4sample_ps20.inc" +#include "accumbuff4sample_ps20b.inc" +#include "convar.h" + +BEGIN_VS_SHADER_FLAGS( accumbuff4sample, "Help for AccumBuff4Sample", SHADER_NOT_EDITABLE ) + BEGIN_SHADER_PARAMS + + // Four textures to sample + SHADER_PARAM( TEXTURE0, SHADER_PARAM_TYPE_TEXTURE, "", "" ) + SHADER_PARAM( TEXTURE1, SHADER_PARAM_TYPE_TEXTURE, "", "" ) + SHADER_PARAM( TEXTURE2, SHADER_PARAM_TYPE_TEXTURE, "", "" ) + SHADER_PARAM( TEXTURE3, SHADER_PARAM_TYPE_TEXTURE, "", "" ) + + // Corresponding weights for the four input textures + SHADER_PARAM( WEIGHTS, SHADER_PARAM_TYPE_VEC4, "", "Weight for Samples" ) + + END_SHADER_PARAMS + + SHADER_INIT + { + LoadTexture( TEXTURE0 ); + LoadTexture( TEXTURE1 ); + LoadTexture( TEXTURE2 ); + LoadTexture( TEXTURE3 ); + } + + SHADER_FALLBACK + { + // Requires DX9 + above + if (!g_pHardwareConfig->SupportsVertexAndPixelShaders()) + { + Assert( 0 ); + return "Wireframe"; + } + return 0; + } + + SHADER_DRAW + { + SHADOW_STATE + { + pShaderShadow->EnableDepthWrites( false ); + pShaderShadow->EnableDepthTest( false ); + pShaderShadow->EnableAlphaWrites( false ); + pShaderShadow->EnableBlending( false ); + pShaderShadow->EnableCulling( false ); +// pShaderShadow->PolyMode( SHADER_POLYMODEFACE_FRONT_AND_BACK, SHADER_POLYMODE_LINE ); + + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER2, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER3, true ); + int fmt = VERTEX_POSITION; + pShaderShadow->VertexShaderVertexFormat( fmt, 1, 0, 0 ); + + // Render targets are pegged as sRGB on OSX togl, so just force these reads and writes + bool bForceSRGBReadAndWrite = IsOSX() && g_pHardwareConfig->CanDoSRGBReadFromRTs(); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, bForceSRGBReadAndWrite ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER1, bForceSRGBReadAndWrite ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER2, bForceSRGBReadAndWrite ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER3, bForceSRGBReadAndWrite ); + pShaderShadow->EnableSRGBWrite( bForceSRGBReadAndWrite ); + + DECLARE_STATIC_VERTEX_SHADER( screenspaceeffect_vs20 ); + SET_STATIC_VERTEX_SHADER( screenspaceeffect_vs20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_STATIC_PIXEL_SHADER( accumbuff4sample_ps20b ); + SET_STATIC_PIXEL_SHADER( accumbuff4sample_ps20b ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( accumbuff4sample_ps20 ); + SET_STATIC_PIXEL_SHADER( accumbuff4sample_ps20 ); + } + } + + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER0, TEXTURE0, -1 ); + BindTexture( SHADER_SAMPLER1, TEXTURE1, -1 ); + BindTexture( SHADER_SAMPLER2, TEXTURE2, -1 ); + BindTexture( SHADER_SAMPLER3, TEXTURE3, -1 ); + + SetPixelShaderConstant( 0, WEIGHTS ); + + DECLARE_DYNAMIC_VERTEX_SHADER( screenspaceeffect_vs20 ); + SET_DYNAMIC_VERTEX_SHADER( screenspaceeffect_vs20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_DYNAMIC_PIXEL_SHADER( accumbuff4sample_ps20b ); + SET_DYNAMIC_PIXEL_SHADER( accumbuff4sample_ps20b ); + } + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( accumbuff4sample_ps20 ); + SET_DYNAMIC_PIXEL_SHADER( accumbuff4sample_ps20 ); + } + } + Draw(); + } +END_SHADER diff --git a/materialsystem/stdshaders/AccumBuff4Sample_ps2x.fxc b/materialsystem/stdshaders/AccumBuff4Sample_ps2x.fxc new file mode 100644 index 0000000..2b32e30 --- /dev/null +++ b/materialsystem/stdshaders/AccumBuff4Sample_ps2x.fxc @@ -0,0 +1,32 @@ +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX] + +#define HDRTYPE HDR_TYPE_NONE +#include "common_ps_fxc.h" + +sampler TexSampler0 : register( s0 ); +sampler TexSampler1 : register( s1 ); +sampler TexSampler2 : register( s2 ); +sampler TexSampler3 : register( s3 ); + +struct PS_INPUT +{ + float2 texCoord : TEXCOORD0; +}; + +const float4 weights : register( c0 ); + +float4 main( PS_INPUT i ) : COLOR +{ + // Just sample the four input textures + float4 sample0 = tex2D( TexSampler0, i.texCoord ); + float4 sample1 = tex2D( TexSampler1, i.texCoord ); + float4 sample2 = tex2D( TexSampler2, i.texCoord ); + float4 sample3 = tex2D( TexSampler3, i.texCoord ); + + // Compute weighted average and return + return FinalOutput( weights.x * sample0 + + weights.y * sample1 + + weights.z * sample2 + + weights.w * sample3, 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE ); +} diff --git a/materialsystem/stdshaders/BaseVSShader.cpp b/materialsystem/stdshaders/BaseVSShader.cpp new file mode 100644 index 0000000..fdaeb56 --- /dev/null +++ b/materialsystem/stdshaders/BaseVSShader.cpp @@ -0,0 +1,2249 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +// This is what all vs/ps (dx8+) shaders inherit from. +//===========================================================================// +#if !defined(_STATIC_LINKED) || defined(STDSHADER_DX8_DLL_EXPORT) || defined(STDSHADER_DX9_DLL_EXPORT) + +#include "BaseVSShader.h" +#include "mathlib/vmatrix.h" +#include "mathlib/bumpvects.h" +#include "cpp_shader_constant_register_map.h" +#include "convar.h" + +#ifndef GAME_SHADER_DLL +#ifdef HDR +#include "vertexlit_and_unlit_generic_hdr_ps20.inc" +#include "vertexlit_and_unlit_generic_hdr_ps20b.inc" +#endif + +#if SUPPORT_DX8 +#include "lightmappedgeneric_flashlight_vs11.inc" +#include "flashlight_ps11.inc" +#endif + +#ifdef STDSHADER_DX9_DLL_EXPORT +#include "lightmappedgeneric_flashlight_vs20.inc" +#endif +#ifdef STDSHADER_DX9_DLL_EXPORT +#include "flashlight_ps20.inc" +#include "flashlight_ps20b.inc" +#endif +#include "unlitgeneric_vs11.inc" +#include "VertexLitGeneric_EnvmappedBumpmap_NoLighting_ps14.inc" +#include "VertexLitGeneric_EnvmappedBumpmap_NoLighting.inc" +#include "vertexlitgeneric_flashlight_vs11.inc" +#include "LightmappedGeneric_BaseTexture.inc" +#include "LightmappedGeneric_BumpmappedLightmap_Base_ps14.inc" +#include "LightmappedGeneric_BumpmappedLightmap_Blend_ps14.inc" +#include "lightmappedgeneric_bumpmappedenvmap_ps14.inc" +#include "lightmappedgeneric_bumpmappedenvmap.inc" +#include "lightmappedgeneric_basetextureblend.inc" +#include "lightmappedgeneric_bumpmappedlightmap.inc" +#endif // GAME_SHADER_DLL + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +static ConVar mat_fullbright( "mat_fullbright","0", FCVAR_CHEAT ); + +// These functions are to be called from the shaders. + +//----------------------------------------------------------------------------- +// Pixel and vertex shader constants.... +//----------------------------------------------------------------------------- +void CBaseVSShader::SetPixelShaderConstant( int pixelReg, int constantVar, int constantVar2 ) +{ + Assert( !IsSnapshotting() ); + if ((!s_ppParams) || (constantVar == -1) || (constantVar2 == -1)) + return; + + IMaterialVar* pPixelVar = s_ppParams[constantVar]; + Assert( pPixelVar ); + IMaterialVar* pPixelVar2 = s_ppParams[constantVar2]; + Assert( pPixelVar2 ); + + float val[4]; + if (pPixelVar->GetType() == MATERIAL_VAR_TYPE_VECTOR) + { + pPixelVar->GetVecValue( val, 3 ); + } + else + { + val[0] = val[1] = val[2] = pPixelVar->GetFloatValue(); + } + + val[3] = pPixelVar2->GetFloatValue(); + s_pShaderAPI->SetPixelShaderConstant( pixelReg, val ); +} + +void CBaseVSShader::SetPixelShaderConstantGammaToLinear( int pixelReg, int constantVar, int constantVar2 ) +{ + Assert( !IsSnapshotting() ); + if ((!s_ppParams) || (constantVar == -1) || (constantVar2 == -1)) + return; + + IMaterialVar* pPixelVar = s_ppParams[constantVar]; + Assert( pPixelVar ); + IMaterialVar* pPixelVar2 = s_ppParams[constantVar2]; + Assert( pPixelVar2 ); + + float val[4]; + if (pPixelVar->GetType() == MATERIAL_VAR_TYPE_VECTOR) + { + pPixelVar->GetVecValue( val, 3 ); + } + else + { + val[0] = val[1] = val[2] = pPixelVar->GetFloatValue(); + } + + val[3] = pPixelVar2->GetFloatValue(); + val[0] = val[0] > 1.0f ? val[0] : GammaToLinear( val[0] ); + val[1] = val[1] > 1.0f ? val[1] : GammaToLinear( val[1] ); + val[2] = val[2] > 1.0f ? val[2] : GammaToLinear( val[2] ); + + s_pShaderAPI->SetPixelShaderConstant( pixelReg, val ); +} + +void CBaseVSShader::SetPixelShaderConstant_W( int pixelReg, int constantVar, float fWValue ) +{ + Assert( !IsSnapshotting() ); + if ((!s_ppParams) || (constantVar == -1)) + return; + + IMaterialVar* pPixelVar = s_ppParams[constantVar]; + Assert( pPixelVar ); + + float val[4]; + if (pPixelVar->GetType() == MATERIAL_VAR_TYPE_VECTOR) + pPixelVar->GetVecValue( val, 4 ); + else + val[0] = val[1] = val[2] = val[3] = pPixelVar->GetFloatValue(); + val[3]=fWValue; + s_pShaderAPI->SetPixelShaderConstant( pixelReg, val ); +} + +void CBaseVSShader::SetPixelShaderConstant( int pixelReg, int constantVar ) +{ + Assert( !IsSnapshotting() ); + if ((!s_ppParams) || (constantVar == -1)) + return; + + IMaterialVar* pPixelVar = s_ppParams[constantVar]; + Assert( pPixelVar ); + + float val[4]; + if (pPixelVar->GetType() == MATERIAL_VAR_TYPE_VECTOR) + pPixelVar->GetVecValue( val, 4 ); + else + val[0] = val[1] = val[2] = val[3] = pPixelVar->GetFloatValue(); + s_pShaderAPI->SetPixelShaderConstant( pixelReg, val ); +} + +void CBaseVSShader::SetPixelShaderConstantGammaToLinear( int pixelReg, int constantVar ) +{ + Assert( !IsSnapshotting() ); + if ((!s_ppParams) || (constantVar == -1)) + return; + + IMaterialVar* pPixelVar = s_ppParams[constantVar]; + Assert( pPixelVar ); + + float val[4]; + if (pPixelVar->GetType() == MATERIAL_VAR_TYPE_VECTOR) + pPixelVar->GetVecValue( val, 4 ); + else + val[0] = val[1] = val[2] = val[3] = pPixelVar->GetFloatValue(); + + val[0] = val[0] > 1.0f ? val[0] : GammaToLinear( val[0] ); + val[1] = val[1] > 1.0f ? val[1] : GammaToLinear( val[1] ); + val[2] = val[2] > 1.0f ? val[2] : GammaToLinear( val[2] ); + + s_pShaderAPI->SetPixelShaderConstant( pixelReg, val ); +} + +void CBaseVSShader::SetVertexShaderConstantGammaToLinear( int var, float const* pVec, int numConst, bool bForce ) +{ + int i; + for( i = 0; i < numConst; i++ ) + { + float vec[4]; + vec[0] = pVec[i*4+0] > 1.0f ? pVec[i*4+0] : GammaToLinear( pVec[i*4+0] ); + vec[1] = pVec[i*4+1] > 1.0f ? pVec[i*4+1] : GammaToLinear( pVec[i*4+1] ); + vec[2] = pVec[i*4+2] > 1.0f ? pVec[i*4+2] : GammaToLinear( pVec[i*4+2] ); + vec[3] = pVec[i*4+3]; + + s_pShaderAPI->SetVertexShaderConstant( var + i, vec, 1, bForce ); + } +} + +void CBaseVSShader::SetPixelShaderConstantGammaToLinear( int var, float const* pVec, int numConst, bool bForce ) +{ + int i; + for( i = 0; i < numConst; i++ ) + { + float vec[4]; + vec[0] = pVec[i*4+0] > 1.0f ? pVec[i*4+0] : GammaToLinear( pVec[i*4+0] ); + vec[1] = pVec[i*4+1] > 1.0f ? pVec[i*4+1] : GammaToLinear( pVec[i*4+1] ); + vec[2] = pVec[i*4+2] > 1.0f ? pVec[i*4+2] : GammaToLinear( pVec[i*4+2] ); + + vec[3] = pVec[i*4+3]; + + s_pShaderAPI->SetPixelShaderConstant( var + i, vec, 1, bForce ); + } +} + +// GR - special version with fix for const/lerp issue +void CBaseVSShader::SetPixelShaderConstantFudge( int pixelReg, int constantVar ) +{ + Assert( !IsSnapshotting() ); + if ((!s_ppParams) || (constantVar == -1)) + return; + + IMaterialVar* pPixelVar = s_ppParams[constantVar]; + Assert( pPixelVar ); + + float val[4]; + if (pPixelVar->GetType() == MATERIAL_VAR_TYPE_VECTOR) + { + pPixelVar->GetVecValue( val, 4 ); + val[0] = val[0] * 0.992f + 0.0078f; + val[1] = val[1] * 0.992f + 0.0078f; + val[2] = val[2] * 0.992f + 0.0078f; + val[3] = val[3] * 0.992f + 0.0078f; + } + else + val[0] = val[1] = val[2] = val[3] = pPixelVar->GetFloatValue() * 0.992f + 0.0078f; + s_pShaderAPI->SetPixelShaderConstant( pixelReg, val ); +} + +void CBaseVSShader::SetVertexShaderConstant( int vertexReg, int constantVar ) +{ + Assert( !IsSnapshotting() ); + if ((!s_ppParams) || (constantVar == -1)) + return; + + IMaterialVar* pVertexVar = s_ppParams[constantVar]; + Assert( pVertexVar ); + + float val[4]; + if (pVertexVar->GetType() == MATERIAL_VAR_TYPE_VECTOR) + pVertexVar->GetVecValue( val, 4 ); + else + val[0] = val[1] = val[2] = val[3] = pVertexVar->GetFloatValue(); + s_pShaderAPI->SetVertexShaderConstant( vertexReg, val ); +} + +//----------------------------------------------------------------------------- +// Sets normalized light color for pixel shaders. +//----------------------------------------------------------------------------- +void CBaseVSShader::SetPixelShaderLightColors( int pixelReg ) +{ + int i; + int maxLights = s_pShaderAPI->GetMaxLights(); + for( i = 0; i < maxLights; i++ ) + { + const LightDesc_t & lightDesc = s_pShaderAPI->GetLight( i ); + if( lightDesc.m_Type != MATERIAL_LIGHT_DISABLE ) + { + Vector color( lightDesc.m_Color[0], lightDesc.m_Color[1], lightDesc.m_Color[2] ); + VectorNormalize( color ); + float val[4] = { color[0], color[1], color[2], 1.0f }; + s_pShaderAPI->SetPixelShaderConstant( pixelReg + i, val, 1 ); + } + else + { + float zero[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; + s_pShaderAPI->SetPixelShaderConstant( pixelReg + i, zero, 1 ); + } + } +} + + +//----------------------------------------------------------------------------- +// Sets vertex shader texture transforms +//----------------------------------------------------------------------------- +void CBaseVSShader::SetVertexShaderTextureTranslation( int vertexReg, int translationVar ) +{ + float offset[2] = {0, 0}; + + IMaterialVar* pTranslationVar = s_ppParams[translationVar]; + if (pTranslationVar) + { + if (pTranslationVar->GetType() == MATERIAL_VAR_TYPE_VECTOR) + pTranslationVar->GetVecValue( offset, 2 ); + else + offset[0] = offset[1] = pTranslationVar->GetFloatValue(); + } + + Vector4D translation[2]; + translation[0].Init( 1.0f, 0.0f, 0.0f, offset[0] ); + translation[1].Init( 0.0f, 1.0f, 0.0f, offset[1] ); + s_pShaderAPI->SetVertexShaderConstant( vertexReg, translation[0].Base(), 2 ); +} + +void CBaseVSShader::SetVertexShaderTextureScale( int vertexReg, int scaleVar ) +{ + float scale[2] = {1, 1}; + + IMaterialVar* pScaleVar = s_ppParams[scaleVar]; + if (pScaleVar) + { + if (pScaleVar->GetType() == MATERIAL_VAR_TYPE_VECTOR) + pScaleVar->GetVecValue( scale, 2 ); + else if (pScaleVar->IsDefined()) + scale[0] = scale[1] = pScaleVar->GetFloatValue(); + } + + Vector4D scaleMatrix[2]; + scaleMatrix[0].Init( scale[0], 0.0f, 0.0f, 0.0f ); + scaleMatrix[1].Init( 0.0f, scale[1], 0.0f, 0.0f ); + s_pShaderAPI->SetVertexShaderConstant( vertexReg, scaleMatrix[0].Base(), 2 ); +} + +void CBaseVSShader::SetVertexShaderTextureTransform( int vertexReg, int transformVar ) +{ + Vector4D transformation[2]; + IMaterialVar* pTransformationVar = s_ppParams[transformVar]; + if (pTransformationVar && (pTransformationVar->GetType() == MATERIAL_VAR_TYPE_MATRIX)) + { + const VMatrix &mat = pTransformationVar->GetMatrixValue(); + transformation[0].Init( mat[0][0], mat[0][1], mat[0][2], mat[0][3] ); + transformation[1].Init( mat[1][0], mat[1][1], mat[1][2], mat[1][3] ); + } + else + { + transformation[0].Init( 1.0f, 0.0f, 0.0f, 0.0f ); + transformation[1].Init( 0.0f, 1.0f, 0.0f, 0.0f ); + } + s_pShaderAPI->SetVertexShaderConstant( vertexReg, transformation[0].Base(), 2 ); +} + +void CBaseVSShader::SetVertexShaderTextureScaledTransform( int vertexReg, int transformVar, int scaleVar ) +{ + Vector4D transformation[2]; + IMaterialVar* pTransformationVar = s_ppParams[transformVar]; + if (pTransformationVar && (pTransformationVar->GetType() == MATERIAL_VAR_TYPE_MATRIX)) + { + const VMatrix &mat = pTransformationVar->GetMatrixValue(); + transformation[0].Init( mat[0][0], mat[0][1], mat[0][2], mat[0][3] ); + transformation[1].Init( mat[1][0], mat[1][1], mat[1][2], mat[1][3] ); + } + else + { + transformation[0].Init( 1.0f, 0.0f, 0.0f, 0.0f ); + transformation[1].Init( 0.0f, 1.0f, 0.0f, 0.0f ); + } + + Vector2D scale( 1, 1 ); + IMaterialVar* pScaleVar = s_ppParams[scaleVar]; + if (pScaleVar) + { + if (pScaleVar->GetType() == MATERIAL_VAR_TYPE_VECTOR) + pScaleVar->GetVecValue( scale.Base(), 2 ); + else if (pScaleVar->IsDefined()) + scale[0] = scale[1] = pScaleVar->GetFloatValue(); + } + + // Apply the scaling + transformation[0][0] *= scale[0]; + transformation[0][1] *= scale[1]; + transformation[1][0] *= scale[0]; + transformation[1][1] *= scale[1]; + transformation[0][3] *= scale[0]; + transformation[1][3] *= scale[1]; + s_pShaderAPI->SetVertexShaderConstant( vertexReg, transformation[0].Base(), 2 ); +} + + +//----------------------------------------------------------------------------- +// Sets pixel shader texture transforms +//----------------------------------------------------------------------------- +void CBaseVSShader::SetPixelShaderTextureTranslation( int pixelReg, int translationVar ) +{ + float offset[2] = {0, 0}; + + IMaterialVar* pTranslationVar = s_ppParams[translationVar]; + if (pTranslationVar) + { + if (pTranslationVar->GetType() == MATERIAL_VAR_TYPE_VECTOR) + pTranslationVar->GetVecValue( offset, 2 ); + else + offset[0] = offset[1] = pTranslationVar->GetFloatValue(); + } + + Vector4D translation[2]; + translation[0].Init( 1.0f, 0.0f, 0.0f, offset[0] ); + translation[1].Init( 0.0f, 1.0f, 0.0f, offset[1] ); + s_pShaderAPI->SetPixelShaderConstant( pixelReg, translation[0].Base(), 2 ); +} + +void CBaseVSShader::SetPixelShaderTextureScale( int pixelReg, int scaleVar ) +{ + float scale[2] = {1, 1}; + + IMaterialVar* pScaleVar = s_ppParams[scaleVar]; + if (pScaleVar) + { + if (pScaleVar->GetType() == MATERIAL_VAR_TYPE_VECTOR) + pScaleVar->GetVecValue( scale, 2 ); + else if (pScaleVar->IsDefined()) + scale[0] = scale[1] = pScaleVar->GetFloatValue(); + } + + Vector4D scaleMatrix[2]; + scaleMatrix[0].Init( scale[0], 0.0f, 0.0f, 0.0f ); + scaleMatrix[1].Init( 0.0f, scale[1], 0.0f, 0.0f ); + s_pShaderAPI->SetPixelShaderConstant( pixelReg, scaleMatrix[0].Base(), 2 ); +} + +void CBaseVSShader::SetPixelShaderTextureTransform( int pixelReg, int transformVar ) +{ + Vector4D transformation[2]; + IMaterialVar* pTransformationVar = s_ppParams[transformVar]; + if (pTransformationVar && (pTransformationVar->GetType() == MATERIAL_VAR_TYPE_MATRIX)) + { + const VMatrix &mat = pTransformationVar->GetMatrixValue(); + transformation[0].Init( mat[0][0], mat[0][1], mat[0][2], mat[0][3] ); + transformation[1].Init( mat[1][0], mat[1][1], mat[1][2], mat[1][3] ); + } + else + { + transformation[0].Init( 1.0f, 0.0f, 0.0f, 0.0f ); + transformation[1].Init( 0.0f, 1.0f, 0.0f, 0.0f ); + } + s_pShaderAPI->SetPixelShaderConstant( pixelReg, transformation[0].Base(), 2 ); +} + +void CBaseVSShader::SetPixelShaderTextureScaledTransform( int pixelReg, int transformVar, int scaleVar ) +{ + Vector4D transformation[2]; + IMaterialVar* pTransformationVar = s_ppParams[transformVar]; + if (pTransformationVar && (pTransformationVar->GetType() == MATERIAL_VAR_TYPE_MATRIX)) + { + const VMatrix &mat = pTransformationVar->GetMatrixValue(); + transformation[0].Init( mat[0][0], mat[0][1], mat[0][2], mat[0][3] ); + transformation[1].Init( mat[1][0], mat[1][1], mat[1][2], mat[1][3] ); + } + else + { + transformation[0].Init( 1.0f, 0.0f, 0.0f, 0.0f ); + transformation[1].Init( 0.0f, 1.0f, 0.0f, 0.0f ); + } + + Vector2D scale( 1, 1 ); + IMaterialVar* pScaleVar = s_ppParams[scaleVar]; + if (pScaleVar) + { + if (pScaleVar->GetType() == MATERIAL_VAR_TYPE_VECTOR) + pScaleVar->GetVecValue( scale.Base(), 2 ); + else if (pScaleVar->IsDefined()) + scale[0] = scale[1] = pScaleVar->GetFloatValue(); + } + + // Apply the scaling + transformation[0][0] *= scale[0]; + transformation[0][1] *= scale[1]; + transformation[1][0] *= scale[0]; + transformation[1][1] *= scale[1]; + transformation[0][3] *= scale[0]; + transformation[1][3] *= scale[1]; + s_pShaderAPI->SetPixelShaderConstant( pixelReg, transformation[0].Base(), 2 ); +} + + +//----------------------------------------------------------------------------- +// Moves a matrix into vertex shader constants +//----------------------------------------------------------------------------- +void CBaseVSShader::SetVertexShaderMatrix2x4( int vertexReg, int matrixVar ) +{ + IMaterialVar* pTranslationVar = s_ppParams[ matrixVar ]; + if ( pTranslationVar ) + { + s_pShaderAPI->SetVertexShaderConstant( vertexReg, &pTranslationVar->GetMatrixValue()[ 0 ][ 0 ], 2 ); + } + else + { + VMatrix matrix; + MatrixSetIdentity( matrix ); + s_pShaderAPI->SetVertexShaderConstant( vertexReg, &matrix[ 0 ][ 0 ], 2 ); + } +} + +void CBaseVSShader::SetVertexShaderMatrix3x4( int vertexReg, int matrixVar ) +{ + IMaterialVar* pTranslationVar = s_ppParams[matrixVar]; + if (pTranslationVar) + { + s_pShaderAPI->SetVertexShaderConstant( vertexReg, &pTranslationVar->GetMatrixValue( )[0][0], 3 ); + } + else + { + VMatrix matrix; + MatrixSetIdentity( matrix ); + s_pShaderAPI->SetVertexShaderConstant( vertexReg, &matrix[0][0], 3 ); + } +} + +void CBaseVSShader::SetVertexShaderMatrix4x4( int vertexReg, int matrixVar ) +{ + IMaterialVar* pTranslationVar = s_ppParams[matrixVar]; + if (pTranslationVar) + { + s_pShaderAPI->SetVertexShaderConstant( vertexReg, &pTranslationVar->GetMatrixValue( )[0][0], 4 ); + } + else + { + VMatrix matrix; + MatrixSetIdentity( matrix ); + s_pShaderAPI->SetVertexShaderConstant( vertexReg, &matrix[0][0], 4 ); + } +} + + +//----------------------------------------------------------------------------- +// Loads the view matrix into pixel shader constants +//----------------------------------------------------------------------------- +void CBaseVSShader::LoadViewMatrixIntoVertexShaderConstant( int vertexReg ) +{ + VMatrix mat, transpose; + s_pShaderAPI->GetMatrix( MATERIAL_VIEW, mat.m[0] ); + + MatrixTranspose( mat, transpose ); + s_pShaderAPI->SetVertexShaderConstant( vertexReg, transpose.m[0], 3 ); +} + + +//----------------------------------------------------------------------------- +// Loads the projection matrix into pixel shader constants +//----------------------------------------------------------------------------- +void CBaseVSShader::LoadProjectionMatrixIntoVertexShaderConstant( int vertexReg ) +{ + VMatrix mat, transpose; + s_pShaderAPI->GetMatrix( MATERIAL_PROJECTION, mat.m[0] ); + + MatrixTranspose( mat, transpose ); + s_pShaderAPI->SetVertexShaderConstant( vertexReg, transpose.m[0], 4 ); +} + + +//----------------------------------------------------------------------------- +// Loads the projection matrix into pixel shader constants +//----------------------------------------------------------------------------- +void CBaseVSShader::LoadModelViewMatrixIntoVertexShaderConstant( int vertexReg ) +{ + VMatrix view, model, modelView, transpose; + s_pShaderAPI->GetMatrix( MATERIAL_MODEL, model.m[0] ); + MatrixTranspose( model, model ); + s_pShaderAPI->GetMatrix( MATERIAL_VIEW, view.m[0] ); + MatrixTranspose( view, view ); + + MatrixMultiply( view, model, modelView ); + s_pShaderAPI->SetVertexShaderConstant( vertexReg, modelView.m[0], 3 ); +} + +//----------------------------------------------------------------------------- +// Loads a scale/offset version of the viewport transform into the specified constant. +//----------------------------------------------------------------------------- +void CBaseVSShader::LoadViewportTransformScaledIntoVertexShaderConstant( int vertexReg ) +{ + ShaderViewport_t viewport; + + s_pShaderAPI->GetViewports( &viewport, 1 ); + + int bbWidth = 0, + bbHeight = 0; + + s_pShaderAPI->GetBackBufferDimensions( bbWidth, bbHeight ); + + // (x, y, z, w) = (Width / bbWidth, Height / bbHeight, MinX / bbWidth, MinY / bbHeight) + Vector4D viewportTransform( + 1.0f * viewport.m_nWidth / bbWidth, + 1.0f * viewport.m_nHeight / bbHeight, + 1.0f * viewport.m_nTopLeftX / bbWidth, + 1.0f * viewport.m_nTopLeftY / bbHeight + ); + + s_pShaderAPI->SetVertexShaderConstant( vertexReg, viewportTransform.Base() ); +} + + + +//----------------------------------------------------------------------------- +// Loads bump lightmap coordinates into the pixel shader +//----------------------------------------------------------------------------- +void CBaseVSShader::LoadBumpLightmapCoordinateAxes_PixelShader( int pixelReg ) +{ + Vector4D basis[3]; + for (int i = 0; i < 3; ++i) + { + memcpy( &basis[i], &g_localBumpBasis[i], 3 * sizeof(float) ); + basis[i][3] = 0.0f; + } + s_pShaderAPI->SetPixelShaderConstant( pixelReg, (float*)basis, 3 ); +} + + +//----------------------------------------------------------------------------- +// Loads bump lightmap coordinates into the pixel shader +//----------------------------------------------------------------------------- +void CBaseVSShader::LoadBumpLightmapCoordinateAxes_VertexShader( int vertexReg ) +{ + Vector4D basis[3]; + + // transpose + int i; + for (i = 0; i < 3; ++i) + { + basis[i][0] = g_localBumpBasis[0][i]; + basis[i][1] = g_localBumpBasis[1][i]; + basis[i][2] = g_localBumpBasis[2][i]; + basis[i][3] = 0.0f; + } + s_pShaderAPI->SetVertexShaderConstant( vertexReg, (float*)basis, 3 ); + for (i = 0; i < 3; ++i) + { + memcpy( &basis[i], &g_localBumpBasis[i], 3 * sizeof(float) ); + basis[i][3] = 0.0f; + } + s_pShaderAPI->SetVertexShaderConstant( vertexReg + 3, (float*)basis, 3 ); +} + + +//----------------------------------------------------------------------------- +// Helper methods for pixel shader overbrighting +//----------------------------------------------------------------------------- +void CBaseVSShader::EnablePixelShaderOverbright( int reg, bool bEnable, bool bDivideByTwo ) +{ + // can't have other overbright values with pixel shaders as it stands. + float v[4]; + if( bEnable ) + { + v[0] = v[1] = v[2] = v[3] = bDivideByTwo ? OVERBRIGHT / 2.0f : OVERBRIGHT; + } + else + { + v[0] = v[1] = v[2] = v[3] = bDivideByTwo ? 1.0f / 2.0f : 1.0f; + } + s_pShaderAPI->SetPixelShaderConstant( reg, v, 1 ); +} + + +//----------------------------------------------------------------------------- +// Helper for dealing with modulation +//----------------------------------------------------------------------------- +void CBaseVSShader::SetModulationVertexShaderDynamicState() +{ + float color[4] = { 1.0, 1.0, 1.0, 1.0 }; + ComputeModulationColor( color ); + s_pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_MODULATION_COLOR, color ); +} + +void CBaseVSShader::SetModulationPixelShaderDynamicState( int modulationVar ) +{ + float color[4] = { 1.0, 1.0, 1.0, 1.0 }; + ComputeModulationColor( color ); + s_pShaderAPI->SetPixelShaderConstant( modulationVar, color ); +} + +void CBaseVSShader::SetModulationPixelShaderDynamicState_LinearColorSpace( int modulationVar ) +{ + float color[4] = { 1.0, 1.0, 1.0, 1.0 }; + ComputeModulationColor( color ); + color[0] = color[0] > 1.0f ? color[0] : GammaToLinear( color[0] ); + color[1] = color[1] > 1.0f ? color[1] : GammaToLinear( color[1] ); + color[2] = color[2] > 1.0f ? color[2] : GammaToLinear( color[2] ); + + s_pShaderAPI->SetPixelShaderConstant( modulationVar, color ); +} + +void CBaseVSShader::SetModulationPixelShaderDynamicState_LinearColorSpace_LinearScale( int modulationVar, float flScale ) +{ + float color[4] = { 1.0, 1.0, 1.0, 1.0 }; + ComputeModulationColor( color ); + color[0] = ( color[0] > 1.0f ? color[0] : GammaToLinear( color[0] ) ) * flScale; + color[1] = ( color[1] > 1.0f ? color[1] : GammaToLinear( color[1] ) ) * flScale; + color[2] = ( color[2] > 1.0f ? color[2] : GammaToLinear( color[2] ) ) * flScale; + + s_pShaderAPI->SetPixelShaderConstant( modulationVar, color ); +} + + +//----------------------------------------------------------------------------- +// Converts a color + alpha into a vector4 +//----------------------------------------------------------------------------- +void CBaseVSShader::ColorVarsToVector( int colorVar, int alphaVar, Vector4D &color ) +{ + color.Init( 1.0, 1.0, 1.0, 1.0 ); + if ( colorVar != -1 ) + { + IMaterialVar* pColorVar = s_ppParams[colorVar]; + if ( pColorVar->GetType() == MATERIAL_VAR_TYPE_VECTOR ) + { + pColorVar->GetVecValue( color.Base(), 3 ); + } + else + { + color[0] = color[1] = color[2] = pColorVar->GetFloatValue(); + } + } + if ( alphaVar != -1 ) + { + float flAlpha = s_ppParams[alphaVar]->GetFloatValue(); + color[3] = clamp( flAlpha, 0.0f, 1.0f ); + } +} + + +//----------------------------------------------------------------------------- +// Sets a color + alpha into shader constants +//----------------------------------------------------------------------------- +void CBaseVSShader::SetColorVertexShaderConstant( int nVertexReg, int colorVar, int alphaVar ) +{ + Vector4D color; + ColorVarsToVector( colorVar, alphaVar, color ); + s_pShaderAPI->SetVertexShaderConstant( nVertexReg, color.Base() ); +} + +void CBaseVSShader::SetColorPixelShaderConstant( int nPixelReg, int colorVar, int alphaVar ) +{ + Vector4D color; + ColorVarsToVector( colorVar, alphaVar, color ); + s_pShaderAPI->SetPixelShaderConstant( nPixelReg, color.Base() ); +} + +#ifdef _DEBUG +ConVar mat_envmaptintoverride( "mat_envmaptintoverride", "-1" ); +ConVar mat_envmaptintscale( "mat_envmaptintscale", "-1" ); +#endif + +//----------------------------------------------------------------------------- +// Helpers for dealing with envmap tint +//----------------------------------------------------------------------------- +// set alphaVar to -1 to ignore it. +void CBaseVSShader::SetEnvMapTintPixelShaderDynamicState( int pixelReg, int tintVar, int alphaVar, bool bConvertFromGammaToLinear ) +{ + float color[4] = { 1.0f, 1.0f, 1.0f, 1.0f }; + if( g_pConfig->bShowSpecular && mat_fullbright.GetInt() != 2 ) + { + IMaterialVar* pAlphaVar = NULL; + if( alphaVar >= 0 ) + { + pAlphaVar = s_ppParams[alphaVar]; + } + if( pAlphaVar ) + { + color[3] = pAlphaVar->GetFloatValue(); + } + + IMaterialVar* pTintVar = s_ppParams[tintVar]; +#ifdef _DEBUG + pTintVar->GetVecValue( color, 3 ); + + float envmapTintOverride = mat_envmaptintoverride.GetFloat(); + float envmapTintScaleOverride = mat_envmaptintscale.GetFloat(); + + if( envmapTintOverride != -1.0f ) + { + color[0] = color[1] = color[2] = envmapTintOverride; + } + if( envmapTintScaleOverride != -1.0f ) + { + color[0] *= envmapTintScaleOverride; + color[1] *= envmapTintScaleOverride; + color[2] *= envmapTintScaleOverride; + } + + if( bConvertFromGammaToLinear ) + { + color[0] = color[0] > 1.0f ? color[0] : GammaToLinear( color[0] ); + color[1] = color[1] > 1.0f ? color[1] : GammaToLinear( color[1] ); + color[2] = color[2] > 1.0f ? color[2] : GammaToLinear( color[2] ); + } +#else + if( bConvertFromGammaToLinear ) + { + pTintVar->GetLinearVecValue( color, 3 ); + } + else + { + pTintVar->GetVecValue( color, 3 ); + } +#endif + } + else + { + color[0] = color[1] = color[2] = color[3] = 0.0f; + } + s_pShaderAPI->SetPixelShaderConstant( pixelReg, color, 1 ); +} + +void CBaseVSShader::SetAmbientCubeDynamicStateVertexShader( ) +{ + s_pShaderAPI->SetVertexShaderStateAmbientLightCube(); +} + +float CBaseVSShader::GetAmbientLightCubeLuminance( ) +{ + return s_pShaderAPI->GetAmbientLightCubeLuminance(); +} + +#ifndef GAME_SHADER_DLL +const char *CBaseVSShader::UnlitGeneric_ComputePixelShaderName( bool bMask, + bool bEnvmap, + bool bBaseTexture, + bool bBaseAlphaEnvmapMask, + bool bDetail, + bool bDetailMultiplyMode, + bool bMaskBaseByDetailAlpha ) +{ + static char const* s_pPixelShaders[] = + { + "UnlitGeneric_NoTexture", + "UnlitGeneric", + "UnlitGeneric_EnvMapNoTexture", + "UnlitGeneric_EnvMap", + "UnlitGeneric_NoTexture", + "UnlitGeneric", + "UnlitGeneric_EnvMapMaskNoTexture", + "UnlitGeneric_EnvMapMask", + + // Detail texture + // The other commented-out versions are used if we want to + // apply the detail *after* the environment map is added + "UnlitGeneric_DetailNoTexture", + "UnlitGeneric_Detail", + "UnlitGeneric_EnvMapNoTexture", //"UnlitGeneric_DetailEnvMapNoTexture", + "UnlitGeneric_DetailEnvMap", + "UnlitGeneric_DetailNoTexture", + "UnlitGeneric_Detail", + "UnlitGeneric_EnvMapMaskNoTexture", //"UnlitGeneric_DetailEnvMapMaskNoTexture", + "UnlitGeneric_DetailEnvMapMask", + }; + + // handle hud elements + if ( bDetail & bDetailMultiplyMode ) + return "alphadist_ps11"; + + if ( bDetail & bMaskBaseByDetailAlpha ) + return "UnlitGeneric_MaskBaseByDetailAlpha_ps11"; + + if (!bMask && bEnvmap && bBaseTexture && bBaseAlphaEnvmapMask) + { + if (!bDetail) + return "UnlitGeneric_BaseAlphaMaskedEnvMap"; + else + return "UnlitGeneric_DetailBaseAlphaMaskedEnvMap"; + } + else + { + int pshIndex = 0; + if (bBaseTexture) + pshIndex |= 0x1; + if (bEnvmap) + pshIndex |= 0x2; + if (bMask) + pshIndex |= 0x4; + if (bDetail) + pshIndex |= 0x8; + return s_pPixelShaders[pshIndex]; + } +} + + +//----------------------------------------------------------------------------- +// Sets up hw morphing state for the vertex shader +//----------------------------------------------------------------------------- +void CBaseVSShader::SetHWMorphVertexShaderState( int nDimConst, int nSubrectConst, VertexTextureSampler_t morphSampler ) +{ +#ifndef _X360 + if ( !s_pShaderAPI->IsHWMorphingEnabled() ) + return; + + int nMorphWidth, nMorphHeight; + s_pShaderAPI->GetStandardTextureDimensions( &nMorphWidth, &nMorphHeight, TEXTURE_MORPH_ACCUMULATOR ); + + int nDim = s_pShaderAPI->GetIntRenderingParameter( INT_RENDERPARM_MORPH_ACCUMULATOR_4TUPLE_COUNT ); + float pMorphAccumSize[4] = { (float)nMorphWidth, (float)nMorphHeight, (float)nDim, 0.0f }; + s_pShaderAPI->SetVertexShaderConstant( nDimConst, pMorphAccumSize ); + + int nXOffset = s_pShaderAPI->GetIntRenderingParameter( INT_RENDERPARM_MORPH_ACCUMULATOR_X_OFFSET ); + int nYOffset = s_pShaderAPI->GetIntRenderingParameter( INT_RENDERPARM_MORPH_ACCUMULATOR_Y_OFFSET ); + int nWidth = s_pShaderAPI->GetIntRenderingParameter( INT_RENDERPARM_MORPH_ACCUMULATOR_SUBRECT_WIDTH ); + int nHeight = s_pShaderAPI->GetIntRenderingParameter( INT_RENDERPARM_MORPH_ACCUMULATOR_SUBRECT_HEIGHT ); + float pMorphAccumSubrect[4] = { (float)nXOffset, (float)nYOffset, (float)nWidth, (float)nHeight }; + s_pShaderAPI->SetVertexShaderConstant( nSubrectConst, pMorphAccumSubrect ); + + s_pShaderAPI->BindStandardVertexTexture( morphSampler, TEXTURE_MORPH_ACCUMULATOR ); +#endif +} + + +//----------------------------------------------------------------------------- +// Vertex shader unlit generic pass +//----------------------------------------------------------------------------- +void CBaseVSShader::VertexShaderUnlitGenericPass( int baseTextureVar, int frameVar, + int baseTextureTransformVar, + int detailVar, int detailTransform, + bool bDetailTransformIsScale, + int envmapVar, int envMapFrameVar, + int envmapMaskVar, int envmapMaskFrameVar, + int envmapMaskScaleVar, int envmapTintVar, + int alphaTestReferenceVar, + int nDetailBlendModeVar, + int nOutlineVar, + int nOutlineColorVar, + int nOutlineStartVar, + int nOutlineEndVar, + int nSeparateDetailUVsVar ) +{ + IMaterialVar** params = s_ppParams; + + bool bBaseAlphaEnvmapMask = IS_FLAG_SET(MATERIAL_VAR_BASEALPHAENVMAPMASK); + bool bEnvmap = (envmapVar >= 0) && params[envmapVar]->IsTexture(); + bool bMask = false; + if (bEnvmap && (envmapMaskVar >= 0)) + { + bMask = params[envmapMaskVar]->IsTexture(); + } + bool bDetail = (detailVar >= 0) && params[detailVar]->IsTexture(); + bool bBaseTexture = (baseTextureVar >= 0) && params[baseTextureVar]->IsTexture(); + bool bVertexColor = IS_FLAG_SET(MATERIAL_VAR_VERTEXCOLOR); + bool bEnvmapCameraSpace = IS_FLAG_SET(MATERIAL_VAR_ENVMAPCAMERASPACE); + bool bEnvmapSphere = IS_FLAG_SET(MATERIAL_VAR_ENVMAPSPHERE); + + bool bDetailMultiply = ( nDetailBlendModeVar >= 0 ) && ( params[nDetailBlendModeVar]->GetIntValue() == 8 ); + bool bMaskBaseByDetailAlpha = ( nDetailBlendModeVar >= 0 ) && ( params[nDetailBlendModeVar]->GetIntValue() == 9 ); + bool bSeparateDetailUVs = ( nSeparateDetailUVsVar >= 0 ) && ( params[nSeparateDetailUVsVar]->GetIntValue() != 0 ); + + if (IsSnapshotting()) + { + // Alpha test + s_pShaderShadow->EnableAlphaTest( IS_FLAG_SET(MATERIAL_VAR_ALPHATEST) ); + + if( alphaTestReferenceVar != -1 && params[alphaTestReferenceVar]->GetFloatValue() > 0.0f ) + { + s_pShaderShadow->AlphaFunc( SHADER_ALPHAFUNC_GEQUAL, params[alphaTestReferenceVar]->GetFloatValue() ); + } + + // Base texture on stage 0 + if (bBaseTexture) + { + s_pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + } + + if (bDetail) + { + s_pShaderShadow->EnableTexture( SHADER_SAMPLER3, true ); + } + + if (bEnvmap) + { + // envmap on stage 1 + s_pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + + // envmapmask on stage 2 + if (bMask || bBaseAlphaEnvmapMask ) + s_pShaderShadow->EnableTexture( SHADER_SAMPLER2, true ); + } + + if (bBaseTexture) + SetDefaultBlendingShadowState( baseTextureVar, true ); + else if (bMask) + SetDefaultBlendingShadowState( envmapMaskVar, false ); + else + SetDefaultBlendingShadowState(); + + int fmt = VERTEX_POSITION; + if( bEnvmap ) + fmt |= VERTEX_NORMAL; + if ( bVertexColor ) + fmt |= VERTEX_COLOR; + + int numTexCoords = 1; + if( bSeparateDetailUVs ) + { + numTexCoords = 2; + } + + s_pShaderShadow->VertexShaderVertexFormat( fmt, numTexCoords, 0, 0 ); + const char *pshName = UnlitGeneric_ComputePixelShaderName( + bMask, + bEnvmap, + bBaseTexture, + bBaseAlphaEnvmapMask, + bDetail, + bDetailMultiply, + bMaskBaseByDetailAlpha ); + s_pShaderShadow->SetPixelShader( pshName ); + + // Compute the vertex shader index. + unlitgeneric_vs11_Static_Index vshIndex; + vshIndex.SetDETAIL( bDetail ); + vshIndex.SetENVMAP( bEnvmap ); + vshIndex.SetENVMAPCAMERASPACE( bEnvmap && bEnvmapCameraSpace ); + vshIndex.SetENVMAPSPHERE( bEnvmap && bEnvmapSphere ); + vshIndex.SetVERTEXCOLOR( bVertexColor ); + vshIndex.SetSEPARATEDETAILUVS( bSeparateDetailUVs ); + s_pShaderShadow->SetVertexShader( "unlitgeneric_vs11", vshIndex.GetIndex() ); + + DefaultFog(); + } + else + { + if ( s_pShaderAPI->InFlashlightMode() ) // Not snapshotting && flashlight pass + { + Draw( false ); + return; + } + + if (bBaseTexture) + { + BindTexture( SHADER_SAMPLER0, baseTextureVar, frameVar ); + SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, baseTextureTransformVar ); + } + + if (bDetail) + { + BindTexture( SHADER_SAMPLER3, detailVar, frameVar ); + + if (bDetailTransformIsScale) + { + SetVertexShaderTextureScaledTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_4, baseTextureTransformVar, detailTransform ); + } + else + { + SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_4, detailTransform ); + } + } + + if (bEnvmap) + { + BindTexture( SHADER_SAMPLER1, envmapVar, envMapFrameVar ); + + if (bMask || bBaseAlphaEnvmapMask) + { + if (bMask) + BindTexture( SHADER_SAMPLER2, envmapMaskVar, envmapMaskFrameVar ); + else + BindTexture( SHADER_SAMPLER2, baseTextureVar, frameVar ); + + SetVertexShaderTextureScaledTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_2, baseTextureTransformVar, envmapMaskScaleVar ); + } + + SetEnvMapTintPixelShaderDynamicState( 2, envmapTintVar, -1 ); + + if (bEnvmapSphere || IS_FLAG_SET(MATERIAL_VAR_ENVMAPCAMERASPACE)) + { + LoadViewMatrixIntoVertexShaderConstant( VERTEX_SHADER_VIEWMODEL ); + } + } + + SetModulationVertexShaderDynamicState(); + + float flConsts[12]={ 0, 0, 0, 1, // color + 0, 0, 0, 0, // max + 0, 0, 0, .5, // min + }; + + // set up outline pixel shader constants + if ( bDetailMultiply && ( nOutlineVar != -1 ) && ( params[nOutlineVar]->GetIntValue() ) ) + { + if ( nOutlineColorVar != -1 ) + params[nOutlineColorVar]->GetVecValue( flConsts, 3 ); + if ( nOutlineEndVar != -1 ) + flConsts[7] = params[nOutlineEndVar]->GetFloatValue(); + if ( nOutlineStartVar != -1 ) + flConsts[11] = params[nOutlineStartVar]->GetFloatValue(); + } + + s_pShaderAPI->SetPixelShaderConstant( 0, flConsts, 3 ); + + // Compute the vertex shader index. + unlitgeneric_vs11_Dynamic_Index vshIndex; + vshIndex.SetDOWATERFOG( s_pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + vshIndex.SetSKINNING( s_pShaderAPI->GetCurrentNumBones() > 0 ); + s_pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() ); + } + + Draw(); +} + + +void CBaseVSShader::DrawWorldBaseTexture( int baseTextureVar, int baseTextureTransformVar, + int frameVar, int colorVar, int alphaVar ) +{ + if( IsSnapshotting() ) + { + s_pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + s_pShaderShadow->VertexShaderVertexFormat( + VERTEX_POSITION, 1, 0, 0 ); + s_pShaderShadow->SetPixelShader( "LightmappedGeneric_BaseTexture" ); + SetNormalBlendingShadowState(); + lightmappedgeneric_basetexture_Static_Index vshIndex; + s_pShaderShadow->SetVertexShader( "LightmappedGeneric_BaseTexture", vshIndex.GetIndex() ); + + FogToOOOverbright(); + } + else + { + IMaterialVar** params = s_ppParams; + bool bLightingOnly = mat_fullbright.GetInt() == 2 && !IS_FLAG_SET( MATERIAL_VAR_NO_DEBUG_OVERRIDE ); + if( bLightingOnly ) + { + s_pShaderAPI->BindStandardTexture( SHADER_SAMPLER1, TEXTURE_GREY ); + } + else + { + BindTexture( SHADER_SAMPLER0, baseTextureVar, frameVar ); + } + SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, baseTextureTransformVar ); + SetColorPixelShaderConstant( 0, colorVar, alphaVar ); + lightmappedgeneric_basetexture_Dynamic_Index vshIndex; + vshIndex.SetDOWATERFOG( s_pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + s_pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() ); + } + Draw(); +} + +void CBaseVSShader::DrawWorldBumpedDiffuseLighting( int bumpmapVar, int bumpFrameVar, + int bumpTransformVar, bool bMultiply, + bool bSSBump ) +{ + if( IsSnapshotting() ) + { + s_pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + s_pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + s_pShaderShadow->EnableTexture( SHADER_SAMPLER2, true ); + s_pShaderShadow->EnableTexture( SHADER_SAMPLER3, true ); + if( bMultiply ) + { + s_pShaderShadow->EnableBlending( true ); + SingleTextureLightmapBlendMode(); + } + s_pShaderShadow->VertexShaderVertexFormat( VERTEX_POSITION, 3, 0, 0 ); + + lightmappedgeneric_bumpmappedlightmap_Static_Index vshIndex; + s_pShaderShadow->SetVertexShader( "LightmappedGeneric_BumpmappedLightmap", vshIndex.GetIndex() ); + + if ( bSSBump ) + s_pShaderShadow->SetPixelShader( "LightmappedGeneric_SSBumpmappedLightmap" ); + else + s_pShaderShadow->SetPixelShader( "LightmappedGeneric_BumpmappedLightmap" ); + FogToFogColor(); + } + else + { + if( !g_pConfig->m_bFastNoBump ) + { + BindTexture( SHADER_SAMPLER0, bumpmapVar, bumpFrameVar ); + } + else + { + s_pShaderAPI->BindStandardTexture( SHADER_SAMPLER0, TEXTURE_NORMALMAP_FLAT ); + } + LoadBumpLightmapCoordinateAxes_PixelShader( 0 ); + s_pShaderAPI->BindStandardTexture( SHADER_SAMPLER1, TEXTURE_LIGHTMAP_BUMPED ); + SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, bumpTransformVar ); + SetModulationPixelShaderDynamicState( 3 ); + + lightmappedgeneric_bumpmappedlightmap_Dynamic_Index vshIndex; + vshIndex.SetDOWATERFOG( s_pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + s_pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() ); + } + Draw(); +} + +void CBaseVSShader::DrawWorldBumpedDiffuseLighting_Base_ps14( int bumpmapVar, int bumpFrameVar, + int bumpTransformVar, + int baseTextureVar, int baseTextureTransformVar, int frameVar ) +{ + if( IsSnapshotting() ) + { + s_pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + s_pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + s_pShaderShadow->EnableTexture( SHADER_SAMPLER2, true ); + s_pShaderShadow->EnableTexture( SHADER_SAMPLER3, true ); + s_pShaderShadow->EnableTexture( SHADER_SAMPLER4, true ); + s_pShaderShadow->VertexShaderVertexFormat( VERTEX_POSITION, 3, 0, 0 ); + + lightmappedgeneric_bumpmappedlightmap_base_ps14_Static_Index vshIndex; + s_pShaderShadow->SetVertexShader( "LightmappedGeneric_BumpmappedLightmap_Base_ps14", vshIndex.GetIndex() ); + + s_pShaderShadow->SetPixelShader( "LightmappedGeneric_BumpmappedLightmap_Base_ps14" ); + FogToFogColor(); + } + else + { + if( !g_pConfig->m_bFastNoBump ) + { + BindTexture( SHADER_SAMPLER0, bumpmapVar, bumpFrameVar ); + } + else + { + s_pShaderAPI->BindStandardTexture( SHADER_SAMPLER0, TEXTURE_NORMALMAP_FLAT ); + } + LoadBumpLightmapCoordinateAxes_PixelShader( 0 ); + s_pShaderAPI->BindStandardTexture( SHADER_SAMPLER1, TEXTURE_LIGHTMAP_BUMPED ); + BindTexture( SHADER_SAMPLER4, baseTextureVar, frameVar ); + SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, bumpTransformVar ); + SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_2, baseTextureTransformVar ); + SetModulationPixelShaderDynamicState( 3 ); + + lightmappedgeneric_bumpmappedlightmap_base_ps14_Dynamic_Index vshIndex; + vshIndex.SetDOWATERFOG( s_pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + s_pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() ); + } + Draw(); +} + +void CBaseVSShader::DrawWorldBumpedDiffuseLighting_Blend_ps14( int bumpmapVar, int bumpFrameVar, + int bumpTransformVar, + int baseTextureVar, int baseTextureTransformVar, + int baseTextureFrameVar, + int baseTexture2Var, int baseTextureTransform2Var, + int baseTextureFrame2Var) +{ + if( IsSnapshotting() ) + { + s_pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + s_pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + s_pShaderShadow->EnableTexture( SHADER_SAMPLER2, true ); + s_pShaderShadow->EnableTexture( SHADER_SAMPLER3, true ); + s_pShaderShadow->EnableTexture( SHADER_SAMPLER4, true ); + s_pShaderShadow->EnableTexture( SHADER_SAMPLER5, true ); + s_pShaderShadow->VertexShaderVertexFormat( VERTEX_POSITION, 3, 0, 0 ); + + lightmappedgeneric_bumpmappedlightmap_blend_ps14_Static_Index vshIndex; + s_pShaderShadow->SetVertexShader( "LightmappedGeneric_BumpmappedLightmap_Blend_ps14", vshIndex.GetIndex() ); + + s_pShaderShadow->SetPixelShader( "LightmappedGeneric_BumpmappedLightmap_Blend_ps14" ); + FogToFogColor(); + } + else + { + if( !g_pConfig->m_bFastNoBump ) + { + BindTexture( SHADER_SAMPLER0, bumpmapVar, bumpFrameVar ); + } + else + { + s_pShaderAPI->BindStandardTexture( SHADER_SAMPLER0, TEXTURE_NORMALMAP_FLAT ); + } + LoadBumpLightmapCoordinateAxes_PixelShader( 0 ); + s_pShaderAPI->BindStandardTexture( SHADER_SAMPLER1, TEXTURE_LIGHTMAP_BUMPED ); + BindTexture( SHADER_SAMPLER4, baseTextureVar, baseTextureFrameVar ); + BindTexture( SHADER_SAMPLER5, baseTexture2Var, baseTextureFrame2Var ); + SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, bumpTransformVar ); + SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_2, baseTextureTransformVar ); + SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_4, baseTextureTransform2Var ); + SetModulationPixelShaderDynamicState( 3 ); + + lightmappedgeneric_bumpmappedlightmap_blend_ps14_Dynamic_Index vshIndex; + vshIndex.SetDOWATERFOG( s_pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + s_pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() ); + } + Draw(); +} + +//#define USE_DEST_ALPHA +#define USE_NORMALMAP_ALPHA + +void CBaseVSShader::DrawWorldBumpedSpecularLighting( int bumpmapVar, int envmapVar, + int bumpFrameVar, int envmapFrameVar, + int envmapTintVar, int alphaVar, + int envmapContrastVar, int envmapSaturationVar, + int bumpTransformVar, int fresnelReflectionVar, + bool bBlend, bool bNoWriteZ ) +{ + // + BUMPED CUBEMAP + if( IsSnapshotting() ) + { + SetInitialShadowState( ); + if ( bNoWriteZ ) + { + s_pShaderShadow->EnableDepthWrites( false ); + } + s_pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + s_pShaderShadow->EnableTexture( SHADER_SAMPLER3, true ); + if( g_pHardwareConfig->SupportsPixelShaders_1_4() ) + { + s_pShaderShadow->EnableTexture( SHADER_SAMPLER4, true ); + } + if( bBlend ) + { + s_pShaderShadow->EnableBlending( true ); + s_pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE ); + } + // FIXME: Remove the normal (needed for tangent space gen) + s_pShaderShadow->VertexShaderVertexFormat( + VERTEX_POSITION | VERTEX_NORMAL | VERTEX_TANGENT_S | + VERTEX_TANGENT_T, 1, 0, 0 ); + + IMaterialVar** params = s_ppParams; + bool bHasNormalMapAlphaEnvMapMask = IS_FLAG_SET( MATERIAL_VAR_NORMALMAPALPHAENVMAPMASK ); + + if( g_pHardwareConfig->SupportsPixelShaders_1_4() ) + { + lightmappedgeneric_bumpmappedenvmap_ps14_Static_Index vshIndex; + s_pShaderShadow->SetVertexShader( "LightmappedGeneric_BumpmappedEnvmap_ps14", vshIndex.GetIndex() ); + + int nPshIndex = bHasNormalMapAlphaEnvMapMask ? 1 : 0; + s_pShaderShadow->SetPixelShader( "LightmappedGeneric_BumpmappedEnvmap_ps14", nPshIndex ); + } + else + { + lightmappedgeneric_bumpmappedenvmap_Static_Index vshIndex; + s_pShaderShadow->SetVertexShader( "LightmappedGeneric_BumpmappedEnvmap", vshIndex.GetIndex() ); + + int nPshIndex = bHasNormalMapAlphaEnvMapMask ? 1 : 0; + s_pShaderShadow->SetPixelShader( "LightmappedGeneric_BumpmappedEnvmap", nPshIndex ); + } + FogToBlack(); + } + else + { + IMaterialVar** params = s_ppParams; + s_pShaderAPI->SetDefaultState(); + BindTexture( SHADER_SAMPLER0, bumpmapVar, bumpFrameVar ); + BindTexture( SHADER_SAMPLER3, envmapVar, envmapFrameVar ); + + if( g_pHardwareConfig->SupportsPixelShaders_1_4() ) + { + s_pShaderAPI->BindStandardTexture( SHADER_SAMPLER4, TEXTURE_NORMALIZATION_CUBEMAP ); + + lightmappedgeneric_bumpmappedenvmap_ps14_Dynamic_Index vshIndex; + vshIndex.SetDOWATERFOG( s_pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + s_pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() ); + } + else + { + lightmappedgeneric_bumpmappedenvmap_Dynamic_Index vshIndex; + vshIndex.SetDOWATERFOG( s_pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + s_pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() ); + } + + SetEnvMapTintPixelShaderDynamicState( 0, envmapTintVar, alphaVar ); + // GR - fudge consts a bit to fix const/lerp issues + SetPixelShaderConstantFudge( 1, envmapContrastVar ); + SetPixelShaderConstantFudge( 2, envmapSaturationVar ); + float greyWeights[4] = { 0.299f, 0.587f, 0.114f, 0.0f }; + s_pShaderAPI->SetPixelShaderConstant( 3, greyWeights ); + + // [ 0, 0 ,0, R(0) ] + float fresnel[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; + fresnel[3] = params[fresnelReflectionVar]->GetFloatValue(); + s_pShaderAPI->SetPixelShaderConstant( 4, fresnel ); + // [ 0, 0 ,0, 1-R(0) ] + fresnel[3] = 1.0f - fresnel[3]; + s_pShaderAPI->SetPixelShaderConstant( 6, fresnel ); + + float one[4] = { 1.0f, 1.0f, 1.0f, 1.0f }; + s_pShaderAPI->SetPixelShaderConstant( 5, one ); + SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, bumpTransformVar ); + } + Draw(); +} + +void CBaseVSShader::DrawModelBumpedSpecularLighting( int bumpMapVar, int bumpMapFrameVar, + int envMapVar, int envMapVarFrame, + int envMapTintVar, int alphaVar, + int envMapContrastVar, int envMapSaturationVar, + int bumpTransformVar, + bool bBlendSpecular, bool bNoWriteZ ) +{ + IMaterialVar** params = s_ppParams; + + if( IsSnapshotting() ) + { + SetInitialShadowState( ); + if ( bNoWriteZ ) + { + s_pShaderShadow->EnableDepthWrites( false ); + } + s_pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + s_pShaderShadow->EnableTexture( SHADER_SAMPLER3, true ); + if( g_pHardwareConfig->SupportsPixelShaders_1_4() ) + { + s_pShaderShadow->EnableTexture( SHADER_SAMPLER4, true ); + } + s_pShaderShadow->EnableAlphaTest( false ); + if( bBlendSpecular ) + { + s_pShaderShadow->EnableBlending( true ); + SetAdditiveBlendingShadowState( -1, false ); + } + else + { + s_pShaderShadow->EnableBlending( false ); + SetNormalBlendingShadowState( -1, false ); + } + + s_pShaderShadow->VertexShaderVertexFormat( + VERTEX_POSITION | VERTEX_NORMAL, 1, 0, 4 /* userDataSize */ ); + + bool bHasNormalMapAlphaEnvMapMask = IS_FLAG_SET( MATERIAL_VAR_NORMALMAPALPHAENVMAPMASK ); + + if( g_pHardwareConfig->SupportsPixelShaders_1_4() ) + { + vertexlitgeneric_envmappedbumpmap_nolighting_ps14_Static_Index vshIndex; + s_pShaderShadow->SetVertexShader( "VertexLitGeneric_EnvmappedBumpmap_NoLighting_ps14", vshIndex.GetIndex() ); + if( bHasNormalMapAlphaEnvMapMask ) + { + s_pShaderShadow->SetPixelShader( "VertexLitGeneric_EnvmappedBumpmapV2_MultByAlpha_ps14" ); + } + else + { + s_pShaderShadow->SetPixelShader( "VertexLitGeneric_EnvmappedBumpmapV2_ps14" ); + } + } + else + { + vertexlitgeneric_envmappedbumpmap_nolighting_Static_Index vshIndex; + s_pShaderShadow->SetVertexShader( "VertexLitGeneric_EnvmappedBumpmap_NoLighting", vshIndex.GetIndex() ); + // This version does not multiply by lighting + // NOTE: We don't support multiplying by lighting for bumped specular stuff. + if( bHasNormalMapAlphaEnvMapMask ) + { + s_pShaderShadow->SetPixelShader( "VertexLitGeneric_EnvmappedBumpmapV2_MultByAlpha" ); + } + else + { + s_pShaderShadow->SetPixelShader( "VertexLitGeneric_EnvmappedBumpmapV2" ); + } + } + FogToBlack(); + } + else + { + s_pShaderAPI->SetDefaultState(); + BindTexture( SHADER_SAMPLER0, bumpMapVar, bumpMapFrameVar ); + BindTexture( SHADER_SAMPLER3, envMapVar, envMapVarFrame ); + if( g_pHardwareConfig->SupportsPixelShaders_1_4() ) + { + s_pShaderAPI->BindStandardTexture( SHADER_SAMPLER4, TEXTURE_NORMALIZATION_CUBEMAP ); + } + + if( bBlendSpecular ) + { + SetEnvMapTintPixelShaderDynamicState( 0, envMapTintVar, -1 ); + } + else + { + SetEnvMapTintPixelShaderDynamicState( 0, envMapTintVar, alphaVar ); + } + // GR - fudge consts a bit to fix const/lerp issues + SetPixelShaderConstantFudge( 1, envMapContrastVar ); + SetPixelShaderConstantFudge( 2, envMapSaturationVar ); + float greyWeights[4] = { 0.299f, 0.587f, 0.114f, 0.0f }; + s_pShaderAPI->SetPixelShaderConstant( 3, greyWeights ); + + // handle scrolling of bump texture + SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_4, bumpTransformVar ); + + if( g_pHardwareConfig->SupportsPixelShaders_1_4() ) + { + vertexlitgeneric_envmappedbumpmap_nolighting_ps14_Dynamic_Index vshIndex; + vshIndex.SetDOWATERFOG( s_pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + vshIndex.SetSKINNING( s_pShaderAPI->GetCurrentNumBones() > 0 ); + s_pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() ); + } + else + { + vertexlitgeneric_envmappedbumpmap_nolighting_Dynamic_Index vshIndex; + vshIndex.SetDOWATERFOG( s_pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + vshIndex.SetSKINNING( s_pShaderAPI->GetCurrentNumBones() > 0 ); + s_pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() ); + } + } + Draw(); +} + +void CBaseVSShader::DrawBaseTextureBlend( int baseTextureVar, int baseTextureTransformVar, + int baseTextureFrameVar, + int baseTexture2Var, int baseTextureTransform2Var, + int baseTextureFrame2Var, int colorVar, int alphaVar ) +{ + if( IsSnapshotting() ) + { + SetInitialShadowState(); + s_pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + s_pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + s_pShaderShadow->EnableTexture( SHADER_SAMPLER2, true ); + s_pShaderShadow->DrawFlags( SHADER_DRAW_POSITION | SHADER_DRAW_TEXCOORD0 | + SHADER_DRAW_LIGHTMAP_TEXCOORD1 ); + // FIXME: Remove the normal (needed for tangent space gen) + s_pShaderShadow->VertexShaderVertexFormat( + VERTEX_POSITION, 2, 0, 0 ); + + lightmappedgeneric_basetextureblend_Static_Index vshIndex; + s_pShaderShadow->SetVertexShader( "lightmappedgeneric_basetextureblend", vshIndex.GetIndex() ); + + s_pShaderShadow->SetPixelShader( "lightmappedgeneric_basetextureblend", 0 ); + FogToOOOverbright(); + } + else + { + IMaterialVar** params = s_ppParams; + bool bLightingOnly = mat_fullbright.GetInt() == 2 && !IS_FLAG_SET( MATERIAL_VAR_NO_DEBUG_OVERRIDE ); + + s_pShaderAPI->SetDefaultState(); + if( bLightingOnly ) + { + s_pShaderAPI->BindStandardTexture( SHADER_SAMPLER0, TEXTURE_GREY ); + s_pShaderAPI->BindStandardTexture( SHADER_SAMPLER1, TEXTURE_GREY ); + } + else + { + BindTexture( SHADER_SAMPLER0, baseTextureVar, baseTextureFrameVar ); + BindTexture( SHADER_SAMPLER1, baseTexture2Var, baseTextureFrame2Var ); + } + s_pShaderAPI->BindStandardTexture( SHADER_SAMPLER2, TEXTURE_LIGHTMAP ); + SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, baseTextureTransformVar ); + SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_2, baseTextureTransform2Var ); + SetColorPixelShaderConstant( 0, colorVar, alphaVar ); + lightmappedgeneric_basetextureblend_Dynamic_Index vshIndex; + vshIndex.SetDOWATERFOG( s_pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + s_pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() ); + } + Draw(); +} + +void CBaseVSShader::DrawWorldBumpedUsingVertexShader( int baseTextureVar, int baseTextureTransformVar, + int bumpmapVar, int bumpFrameVar, + int bumpTransformVar, + int envmapMaskVar, int envmapMaskFrame, + int envmapVar, + int envmapFrameVar, + int envmapTintVar, int colorVar, int alphaVar, + int envmapContrastVar, int envmapSaturationVar, + int frameVar, int fresnelReflectionVar, + bool doBaseTexture2, + int baseTexture2Var, int baseTextureTransform2Var, + int baseTextureFrame2Var, + bool bSSBump + ) +{ + IMaterialVar** params = s_ppParams; + // Draw base texture + bool bMultiplyDiffuseLighting = false; + bool bBlendSpecular = false; + + // Draw base texture(s) + if( doBaseTexture2 && params[baseTexture2Var]->IsTexture() && params[baseTextureVar]->IsTexture() ) + { + DrawBaseTextureBlend( baseTextureVar, baseTextureTransformVar, frameVar, + baseTexture2Var, baseTextureTransform2Var, baseTextureFrame2Var, colorVar, alphaVar ); + bMultiplyDiffuseLighting = true; + bBlendSpecular = true; + } + else if( params[baseTextureVar]->IsTexture() ) + { + DrawWorldBaseTexture( baseTextureVar, baseTextureTransformVar, frameVar, colorVar, alphaVar ); + bMultiplyDiffuseLighting = true; + bBlendSpecular = true; + } + else + { + // Just use color here + } + + // Draw diffuse lighting + if( params[baseTextureVar]->IsTexture() || !params[envmapVar]->IsTexture() ) + { + DrawWorldBumpedDiffuseLighting( bumpmapVar, bumpFrameVar, bumpTransformVar, + bMultiplyDiffuseLighting, bSSBump ); + bBlendSpecular = true; + } + + // Add specular lighting + if( params[envmapVar]->IsTexture() ) + { + DrawWorldBumpedSpecularLighting( + bumpmapVar, envmapVar, + bumpFrameVar, envmapFrameVar, + envmapTintVar, alphaVar, + envmapContrastVar, envmapSaturationVar, + bumpTransformVar, fresnelReflectionVar, + bBlendSpecular ); + } +} +#endif // GAME_SHADER_DLL + + +//----------------------------------------------------------------------------- +// GR - translucency query +//----------------------------------------------------------------------------- +BlendType_t CBaseVSShader::EvaluateBlendRequirements( int textureVar, bool isBaseTexture, + int detailTextureVar ) +{ + // Either we've got a constant modulation + bool isTranslucent = IsAlphaModulating(); + + // Or we've got a vertex alpha + isTranslucent = isTranslucent || (CurrentMaterialVarFlags() & MATERIAL_VAR_VERTEXALPHA); + + // Or we've got a texture alpha (for blending or alpha test) + isTranslucent = isTranslucent || ( TextureIsTranslucent( textureVar, isBaseTexture ) && + !(CurrentMaterialVarFlags() & MATERIAL_VAR_ALPHATEST ) ); + + if ( ( detailTextureVar != -1 ) && ( ! isTranslucent ) ) + { + isTranslucent = TextureIsTranslucent( detailTextureVar, isBaseTexture ); + } + + if ( CurrentMaterialVarFlags() & MATERIAL_VAR_ADDITIVE ) + { + return isTranslucent ? BT_BLENDADD : BT_ADD; // Additive + } + else + { + return isTranslucent ? BT_BLEND : BT_NONE; // Normal blending + } +} + +#ifndef GAME_SHADER_DLL + +void CBaseVSShader::SetFlashlightVertexShaderConstants( bool bBump, int bumpTransformVar, bool bDetail, int detailScaleVar, bool bSetTextureTransforms ) +{ + Assert( !IsSnapshotting() ); + + VMatrix worldToTexture; + const FlashlightState_t &flashlightState = s_pShaderAPI->GetFlashlightState( worldToTexture ); + + // Set the flashlight origin + float pos[4]; + pos[0] = flashlightState.m_vecLightOrigin[0]; + pos[1] = flashlightState.m_vecLightOrigin[1]; + pos[2] = flashlightState.m_vecLightOrigin[2]; + pos[3] = 1.0f / ( ( 0.6f * flashlightState.m_FarZ ) - flashlightState.m_FarZ ); // DX8 needs this + + s_pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, pos, 1 ); + + s_pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_1, worldToTexture.Base(), 4 ); + + // Set the flashlight attenuation factors + float atten[4]; + atten[0] = flashlightState.m_fConstantAtten; + atten[1] = flashlightState.m_fLinearAtten; + atten[2] = flashlightState.m_fQuadraticAtten; + atten[3] = flashlightState.m_FarZ; + s_pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_5, atten, 1 ); + + if ( bDetail ) + { + SetVertexShaderTextureScaledTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_8, BASETEXTURETRANSFORM, detailScaleVar ); + } + + if( bSetTextureTransforms ) + { + SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_6, BASETEXTURETRANSFORM ); + if( !bDetail && bBump && bumpTransformVar != -1 ) + { + SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_8, bumpTransformVar ); // aliased on top of detail transform + } + } +} + +#if SUPPORT_DX8 +void CBaseVSShader::DrawFlashlight_dx80( IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow, bool bBump, + int bumpmapVar, int bumpmapFrame, int bumpTransform, int flashlightTextureVar, int flashlightTextureFrameVar, + bool bLightmappedGeneric, bool bWorldVertexTransition, int nWorldVertexTransitionPassID, int baseTexture2Var, + int baseTexture2FrameVar, bool bTeeth, int nTeethForwardVar, int nTeethIllumFactorVar ) +{ + // FLASHLIGHTFIXME: hack . . need to fix the vertex shader so that it can deal with and without bumps for vertexlitgeneric + if( !bLightmappedGeneric ) + { + bBump = false; + } + if( pShaderShadow ) + { + SetInitialShadowState(); + pShaderShadow->EnableDepthWrites( false ); + + // Be sure not to write to dest alpha + pShaderShadow->EnableAlphaWrites( false ); + + // Never alpha test the flashlight pass + pShaderShadow->EnableAlphaTest( false ); + + if ( IS_FLAG_SET( MATERIAL_VAR_ALPHATEST ) ) + { + // use zfunc zequals since alpha isn't guaranteed to + // be the same on both the regular pass and the flashlight pass. + pShaderShadow->DepthFunc( SHADER_DEPTHFUNC_EQUAL ); + } + + // Alpha blend + if( bWorldVertexTransition ) + { + // use separate alpha blend to make sure that we aren't adding alpha from source + if( nWorldVertexTransitionPassID == 0 ) + { + EnableAlphaBlending( SHADER_BLEND_DST_ALPHA, SHADER_BLEND_ONE ); + } + else + { + EnableAlphaBlending( SHADER_BLEND_ONE_MINUS_DST_ALPHA, SHADER_BLEND_ONE ); + } + } + else + { + SetAdditiveBlendingShadowState( BASETEXTURE, true ); + } + + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER2, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER3, true ); + + if( bLightmappedGeneric ) + { + bool bUsingVertexColor = IS_FLAG_SET( MATERIAL_VAR_VERTEXCOLOR ); + lightmappedgeneric_flashlight_vs11_Static_Index vshIndex; + vshIndex.SetNORMALMAP( bBump ); + vshIndex.SetWORLDVERTEXTRANSITION( bWorldVertexTransition ); + vshIndex.SetVERTEXCOLOR( bUsingVertexColor ); + pShaderShadow->SetVertexShader( "lightmappedgeneric_flashlight_vs11", vshIndex.GetIndex() ); + + unsigned int flags = VERTEX_POSITION | VERTEX_NORMAL; + if( bBump ) + { + flags |= VERTEX_TANGENT_S | VERTEX_TANGENT_T; + } + if ( bWorldVertexTransition || bUsingVertexColor ) + { + flags |= VERTEX_COLOR; + } + pShaderShadow->VertexShaderVertexFormat( flags, 1, 0, 0 ); + } + else + { + vertexlitgeneric_flashlight_vs11_Static_Index vshIndex; + vshIndex.SetTEETH( bTeeth ); + pShaderShadow->SetVertexShader( "vertexlitgeneric_flashlight_vs11", vshIndex.GetIndex() ); + + unsigned int flags = VERTEX_POSITION | VERTEX_NORMAL; + pShaderShadow->VertexShaderVertexFormat( flags, 1, 0, bBump ? 4 : 0 ); + } + + bool bNoCull = IS_FLAG_SET( MATERIAL_VAR_NOCULL ); + + flashlight_ps11_Static_Index pshIndex; + pshIndex.SetNORMALMAP( bBump ); + pshIndex.SetNOCULL( bNoCull ); + pShaderShadow->SetPixelShader( "flashlight_ps11", pshIndex.GetIndex() ); + + FogToBlack(); + } + else + { + // Specify that we have XYZ texcoords that need to be divided by W before the pixel shader. + // NOTE Tried to divide XY by Z, but doesn't work. + // The dx9.0c runtime says that we shouldn't have a non-zero dimension when using vertex and pixel shaders. + pShaderAPI->SetTextureTransformDimension( SHADER_TEXTURE_STAGE0, 0, true ); + BindTexture( SHADER_SAMPLER0, flashlightTextureVar, flashlightTextureFrameVar ); + + if( bWorldVertexTransition && ( nWorldVertexTransitionPassID == 1 ) ) + { + BindTexture( SHADER_SAMPLER1, baseTexture2Var, baseTexture2FrameVar ); + } + else + { + if( params[BASETEXTURE]->IsTexture() ) + { + BindTexture( SHADER_SAMPLER1, BASETEXTURE, FRAME ); + } + else + { + pShaderAPI->BindStandardTexture( SHADER_SAMPLER1, TEXTURE_GREY ); + } + } + pShaderAPI->BindStandardTexture( SHADER_SAMPLER2, TEXTURE_NORMALIZATION_CUBEMAP ); + if( bBump ) + { + BindTexture( SHADER_SAMPLER3, bumpmapVar, bumpmapFrame ); + } + else + { + pShaderAPI->BindStandardTexture( SHADER_SAMPLER3, TEXTURE_NORMALIZATION_CUBEMAP ); + } + + if( bLightmappedGeneric ) + { + lightmappedgeneric_flashlight_vs11_Dynamic_Index vshIndex; + vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() ); + } + else + { + vertexlitgeneric_flashlight_vs11_Dynamic_Index vshIndex; + vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + + if( bTeeth ) + { + Assert( nTeethForwardVar >= 0 ); + Assert( nTeethIllumFactorVar >= 0 ); + Vector4D lighting; + params[nTeethForwardVar]->GetVecValue( lighting.Base(), 3 ); + lighting[3] = params[nTeethIllumFactorVar]->GetFloatValue(); + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_10, lighting.Base() ); + } + + vshIndex.SetSKINNING( pShaderAPI->GetCurrentNumBones() > 0 ); + pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() ); + } + + flashlight_ps11_Dynamic_Index pshIndex; + pShaderAPI->SetPixelShaderIndex( pshIndex.GetIndex() ); + + SetFlashlightVertexShaderConstants( bBump, bumpTransform, false, -1, true ); + } + Draw(); +} +#endif // support_dx8 + +#ifdef STDSHADER_DX9_DLL_EXPORT +void CBaseVSShader::DrawFlashlight_dx90( IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, + IShaderShadow* pShaderShadow, DrawFlashlight_dx90_Vars_t &vars ) +{ + // FLASHLIGHTFIXME: hack . . need to fix the vertex shader so that it can deal with and without bumps for vertexlitgeneric + if( !vars.m_bLightmappedGeneric ) + { + vars.m_bBump = false; + } + bool bBump2 = vars.m_bWorldVertexTransition && vars.m_bBump && vars.m_nBumpmap2Var != -1 && params[vars.m_nBumpmap2Var]->IsTexture(); + bool bSeamless = vars.m_fSeamlessScale != 0.0; + bool bDetail = vars.m_bLightmappedGeneric && (vars.m_nDetailVar != -1) && params[vars.m_nDetailVar]->IsDefined() && (vars.m_nDetailScale != -1); + + int nDetailBlendMode = 0; + if ( bDetail ) + { + nDetailBlendMode = GetIntParam( vars.m_nDetailTextureCombineMode, params ); + nDetailBlendMode = nDetailBlendMode > 1 ? 1 : nDetailBlendMode; + } + + if( pShaderShadow ) + { + SetInitialShadowState(); + pShaderShadow->EnableDepthWrites( false ); + pShaderShadow->EnableAlphaWrites( false ); + + // Alpha blend + SetAdditiveBlendingShadowState( BASETEXTURE, true ); + + // Alpha test + pShaderShadow->EnableAlphaTest( IS_FLAG_SET( MATERIAL_VAR_ALPHATEST ) ); + if ( vars.m_nAlphaTestReference != -1 && params[vars.m_nAlphaTestReference]->GetFloatValue() > 0.0f ) + { + pShaderShadow->AlphaFunc( SHADER_ALPHAFUNC_GEQUAL, params[vars.m_nAlphaTestReference]->GetFloatValue() ); + } + + // Spot sampler + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, true ); + + // Base sampler + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER1, true ); + + // Normalizing cubemap sampler + pShaderShadow->EnableTexture( SHADER_SAMPLER2, true ); + + // Normalizing cubemap sampler2 or normal map sampler + pShaderShadow->EnableTexture( SHADER_SAMPLER3, true ); + + // RandomRotation sampler + pShaderShadow->EnableTexture( SHADER_SAMPLER5, true ); + + // Flashlight depth sampler + pShaderShadow->EnableTexture( SHADER_SAMPLER7, true ); + pShaderShadow->SetShadowDepthFiltering( SHADER_SAMPLER7 ); + + if( vars.m_bWorldVertexTransition ) + { + // $basetexture2 + pShaderShadow->EnableTexture( SHADER_SAMPLER4, true ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER4, true ); + } + if( bBump2 ) + { + // Normalmap2 sampler + pShaderShadow->EnableTexture( SHADER_SAMPLER6, true ); + } + if( bDetail ) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER8, true ); // detail sampler + if ( nDetailBlendMode != 0 ) //Not Mod2X + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER8, true ); + } + + pShaderShadow->EnableSRGBWrite( true ); + + if( vars.m_bLightmappedGeneric ) + { + lightmappedgeneric_flashlight_vs20_Static_Index vshIndex; + vshIndex.SetWORLDVERTEXTRANSITION( vars.m_bWorldVertexTransition ); + vshIndex.SetNORMALMAP( vars.m_bBump ); + vshIndex.SetSEAMLESS( bSeamless ); + vshIndex.SetDETAIL( bDetail ); + pShaderShadow->SetVertexShader( "lightmappedgeneric_flashlight_vs20", vshIndex.GetIndex() ); + + unsigned int flags = VERTEX_POSITION | VERTEX_NORMAL; + if( vars.m_bBump ) + { + flags |= VERTEX_TANGENT_S | VERTEX_TANGENT_T; + } + int numTexCoords = 1; + if( vars.m_bWorldVertexTransition ) + { + flags |= VERTEX_COLOR; + numTexCoords = 2; // need lightmap texcoords to get alpha. + } + pShaderShadow->VertexShaderVertexFormat( flags, numTexCoords, 0, 0 ); + } + else + { + vertexlitgeneric_flashlight_vs11_Static_Index vshIndex; + vshIndex.SetTEETH( vars.m_bTeeth ); + pShaderShadow->SetVertexShader( "vertexlitgeneric_flashlight_vs11", vshIndex.GetIndex() ); + + unsigned int flags = VERTEX_POSITION | VERTEX_NORMAL; + int numTexCoords = 1; + pShaderShadow->VertexShaderVertexFormat( flags, numTexCoords, 0, vars.m_bBump ? 4 : 0 ); + } + + int nBumpMapVariant = 0; + if ( vars.m_bBump ) + { + nBumpMapVariant = ( vars.m_bSSBump ) ? 2 : 1; + } + if ( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + int nShadowFilterMode = g_pHardwareConfig->GetShadowFilterMode(); + + flashlight_ps20b_Static_Index pshIndex; + pshIndex.SetNORMALMAP( nBumpMapVariant ); + pshIndex.SetNORMALMAP2( bBump2 ); + pshIndex.SetWORLDVERTEXTRANSITION( vars.m_bWorldVertexTransition ); + pshIndex.SetSEAMLESS( bSeamless ); + pshIndex.SetDETAILTEXTURE( bDetail ); + pshIndex.SetDETAIL_BLEND_MODE( nDetailBlendMode ); + pshIndex.SetFLASHLIGHTDEPTHFILTERMODE( nShadowFilterMode ); + pShaderShadow->SetPixelShader( "flashlight_ps20b", pshIndex.GetIndex() ); + } + else + { + flashlight_ps20_Static_Index pshIndex; + pshIndex.SetNORMALMAP( nBumpMapVariant ); + pshIndex.SetNORMALMAP2( bBump2 ); + pshIndex.SetWORLDVERTEXTRANSITION( vars.m_bWorldVertexTransition ); + pshIndex.SetSEAMLESS( bSeamless ); + pshIndex.SetDETAILTEXTURE( bDetail ); + pshIndex.SetDETAIL_BLEND_MODE( nDetailBlendMode ); + pShaderShadow->SetPixelShader( "flashlight_ps20", pshIndex.GetIndex() ); + } + FogToBlack(); + } + else + { + VMatrix worldToTexture; + ITexture *pFlashlightDepthTexture; + FlashlightState_t flashlightState = pShaderAPI->GetFlashlightStateEx( worldToTexture, &pFlashlightDepthTexture ); + + SetFlashLightColorFromState( flashlightState, pShaderAPI ); + + BindTexture( SHADER_SAMPLER0, flashlightState.m_pSpotlightTexture, flashlightState.m_nSpotlightTextureFrame ); + + if( pFlashlightDepthTexture && g_pConfig->ShadowDepthTexture() && flashlightState.m_bEnableShadows ) + { + BindTexture( SHADER_SAMPLER7, pFlashlightDepthTexture, 0 ); + pShaderAPI->BindStandardTexture( SHADER_SAMPLER5, TEXTURE_SHADOW_NOISE_2D ); + + // Tweaks associated with a given flashlight + float tweaks[4]; + tweaks[0] = ShadowFilterFromState( flashlightState ); + tweaks[1] = ShadowAttenFromState( flashlightState ); + HashShadow2DJitter( flashlightState.m_flShadowJitterSeed, &tweaks[2], &tweaks[3] ); + pShaderAPI->SetPixelShaderConstant( PSREG_ENVMAP_TINT__SHADOW_TWEAKS, tweaks, 1 ); + + // Dimensions of screen, used for screen-space noise map sampling + float vScreenScale[4] = {1280.0f / 32.0f, 720.0f / 32.0f, 0, 0}; + int nWidth, nHeight; + pShaderAPI->GetBackBufferDimensions( nWidth, nHeight ); + vScreenScale[0] = (float) nWidth / 32.0f; + vScreenScale[1] = (float) nHeight / 32.0f; + pShaderAPI->SetPixelShaderConstant( PSREG_FLASHLIGHT_SCREEN_SCALE, vScreenScale, 1 ); + } + + if( params[BASETEXTURE]->IsTexture() && mat_fullbright.GetInt() != 2 ) + { + BindTexture( SHADER_SAMPLER1, BASETEXTURE, FRAME ); + } + else + { + pShaderAPI->BindStandardTexture( SHADER_SAMPLER1, TEXTURE_GREY ); + } + if( vars.m_bWorldVertexTransition ) + { + Assert( vars.m_nBaseTexture2Var >= 0 && vars.m_nBaseTexture2FrameVar >= 0 ); + BindTexture( SHADER_SAMPLER4, vars.m_nBaseTexture2Var, vars.m_nBaseTexture2FrameVar ); + } + pShaderAPI->BindStandardTexture( SHADER_SAMPLER2, TEXTURE_NORMALIZATION_CUBEMAP ); + if( vars.m_bBump ) + { + BindTexture( SHADER_SAMPLER3, vars.m_nBumpmapVar, vars.m_nBumpmapFrame ); + } + else + { + pShaderAPI->BindStandardTexture( SHADER_SAMPLER3, TEXTURE_NORMALIZATION_CUBEMAP ); + } + + if( bDetail ) + { + BindTexture( SHADER_SAMPLER8, vars.m_nDetailVar ); + } + + if( vars.m_bWorldVertexTransition ) + { + if( bBump2 ) + { + BindTexture( SHADER_SAMPLER6, vars.m_nBumpmap2Var, vars.m_nBumpmap2Frame ); + } + } + + if( vars.m_bLightmappedGeneric ) + { + DECLARE_DYNAMIC_VERTEX_SHADER( lightmappedgeneric_flashlight_vs20 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( DOWATERFOG, pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + SET_DYNAMIC_VERTEX_SHADER( lightmappedgeneric_flashlight_vs20 ); + if ( bSeamless ) + { + float const0[4]={ vars.m_fSeamlessScale,0,0,0}; + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_6, const0 ); + } + + if ( bDetail ) + { + float vDetailConstants[4] = {1,1,1,1}; + + if ( vars.m_nDetailTint != -1 ) + { + params[vars.m_nDetailTint]->GetVecValue( vDetailConstants, 3 ); + } + + if ( vars.m_nDetailTextureBlendFactor != -1 ) + { + vDetailConstants[3] = params[vars.m_nDetailTextureBlendFactor]->GetFloatValue(); + } + + pShaderAPI->SetPixelShaderConstant( 0, vDetailConstants, 1 ); + } + } + else + { + vertexlitgeneric_flashlight_vs11_Dynamic_Index vshIndex; + vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + vshIndex.SetSKINNING( pShaderAPI->GetCurrentNumBones() > 0 ); + pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() ); + + if( vars.m_bTeeth ) + { + Assert( vars.m_nTeethForwardVar >= 0 ); + Assert( vars.m_nTeethIllumFactorVar >= 0 ); + Vector4D lighting; + params[vars.m_nTeethForwardVar]->GetVecValue( lighting.Base(), 3 ); + lighting[3] = params[vars.m_nTeethIllumFactorVar]->GetFloatValue(); + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, lighting.Base() ); + } + } + + pShaderAPI->SetPixelShaderFogParams( PSREG_FOG_PARAMS ); + + float vEyePos_SpecExponent[4]; + pShaderAPI->GetWorldSpaceCameraPosition( vEyePos_SpecExponent ); + vEyePos_SpecExponent[3] = 0.0f; + pShaderAPI->SetPixelShaderConstant( PSREG_EYEPOS_SPEC_EXPONENT, vEyePos_SpecExponent, 1 ); + + if ( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_DYNAMIC_PIXEL_SHADER( flashlight_ps20b ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( FLASHLIGHTSHADOWS, flashlightState.m_bEnableShadows && ( pFlashlightDepthTexture != NULL ) ); + SET_DYNAMIC_PIXEL_SHADER( flashlight_ps20b ); + } + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( flashlight_ps20 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + SET_DYNAMIC_PIXEL_SHADER( flashlight_ps20 ); + } + + float atten[4]; // Set the flashlight attenuation factors + atten[0] = flashlightState.m_fConstantAtten; + atten[1] = flashlightState.m_fLinearAtten; + atten[2] = flashlightState.m_fQuadraticAtten; + atten[3] = flashlightState.m_FarZ; + s_pShaderAPI->SetPixelShaderConstant( PSREG_FLASHLIGHT_ATTENUATION, atten, 1 ); + + SetFlashlightVertexShaderConstants( vars.m_bBump, vars.m_nBumpTransform, bDetail, vars.m_nDetailScale, bSeamless ? false : true ); + } + Draw(); +} + +#endif + +void CBaseVSShader::InitParamsUnlitGeneric_DX8( + int baseTextureVar, + int detailScaleVar, + int envmapOptionalVar, + int envmapVar, + int envmapTintVar, + int envmapMaskScaleVar, + int nDetailBlendMode ) +{ + IMaterialVar** params = s_ppParams; + + SET_FLAGS2( MATERIAL_VAR2_SUPPORTS_HW_SKINNING ); + + if( envmapTintVar >= 0 && !params[envmapTintVar]->IsDefined() ) + { + params[envmapTintVar]->SetVecValue( 1.0f, 1.0f, 1.0f ); + } + + if( envmapMaskScaleVar >= 0 && !params[envmapMaskScaleVar]->IsDefined() ) + { + params[envmapMaskScaleVar]->SetFloatValue( 1.0f ); + } + + if( detailScaleVar >= 0 && !params[detailScaleVar]->IsDefined() ) + { + params[detailScaleVar]->SetFloatValue( 4.0f ); + } + + // No texture means no self-illum or env mask in base alpha + if ( baseTextureVar >= 0 && !params[baseTextureVar]->IsDefined() ) + { + CLEAR_FLAGS( MATERIAL_VAR_BASEALPHAENVMAPMASK ); + } + + // If in decal mode, no debug override... + if (IS_FLAG_SET(MATERIAL_VAR_DECAL)) + { + SET_FLAGS( MATERIAL_VAR_NO_DEBUG_OVERRIDE ); + } + + // Get rid of the envmap if it's optional for this dx level. + if( envmapOptionalVar >= 0 && params[envmapOptionalVar]->IsDefined() && params[envmapOptionalVar]->GetIntValue() ) + { + if (envmapVar >= 0) + { + params[envmapVar]->SetUndefined(); + } + } + + // If mat_specular 0, then get rid of envmap + if( envmapVar >= 0 && baseTextureVar >= 0 && !g_pConfig->UseSpecular() && params[envmapVar]->IsDefined() && params[baseTextureVar]->IsDefined() ) + { + params[envmapVar]->SetUndefined(); + } +} + +void CBaseVSShader::InitUnlitGeneric_DX8( + int baseTextureVar, + int detailVar, + int envmapVar, + int envmapMaskVar ) +{ + IMaterialVar** params = s_ppParams; + + if (baseTextureVar >= 0 && params[baseTextureVar]->IsDefined()) + { + LoadTexture( baseTextureVar ); + + if (!params[baseTextureVar]->GetTextureValue()->IsTranslucent()) + { + if (IS_FLAG_SET(MATERIAL_VAR_BASEALPHAENVMAPMASK)) + CLEAR_FLAGS( MATERIAL_VAR_BASEALPHAENVMAPMASK ); + } + } + + // Don't alpha test if the alpha channel is used for other purposes + if ( IS_FLAG_SET(MATERIAL_VAR_BASEALPHAENVMAPMASK) ) + CLEAR_FLAGS( MATERIAL_VAR_ALPHATEST ); + + // the second texture (if there is one) + if (detailVar >= 0 && params[detailVar]->IsDefined()) + { + LoadTexture( detailVar ); + } + + if (envmapVar >= 0 && params[envmapVar]->IsDefined()) + { + if( !IS_FLAG_SET(MATERIAL_VAR_ENVMAPSPHERE) ) + LoadCubeMap( envmapVar ); + else + LoadTexture( envmapVar ); + + if( !g_pHardwareConfig->SupportsCubeMaps() ) + SET_FLAGS(MATERIAL_VAR_ENVMAPSPHERE); + + if (envmapMaskVar >= 0 && params[envmapMaskVar]->IsDefined()) + LoadTexture( envmapMaskVar ); + } +} +#endif // GAME_SHADER_DLL + +#endif // !_STATIC_LINKED || STDSHADER_DX8_DLL_EXPORT + + +// Take 0..1 seed and map to (u, v) coordinate to be used in shadow filter jittering... +void CBaseVSShader::HashShadow2DJitter( const float fJitterSeed, float *fU, float* fV ) +{ + const int nTexRes = 32; + int nSeed = fmod (fJitterSeed, 1.0f) * nTexRes * nTexRes; + + int nRow = nSeed / nTexRes; + int nCol = nSeed % nTexRes; + + // Div and mod to get an individual texel in the fTexRes x fTexRes grid + *fU = nRow / (float) nTexRes; // Row + *fV = nCol / (float) nTexRes; // Column +} + + +void CBaseVSShader::DrawEqualDepthToDestAlpha( void ) +{ +#ifdef STDSHADER_DX9_DLL_EXPORT + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + bool bMakeActualDrawCall = false; + if( s_pShaderShadow ) + { + s_pShaderShadow->EnableColorWrites( false ); + s_pShaderShadow->EnableAlphaWrites( true ); + s_pShaderShadow->EnableDepthWrites( false ); + s_pShaderShadow->EnableAlphaTest( false ); + s_pShaderShadow->EnableBlending( false ); + + s_pShaderShadow->DepthFunc( SHADER_DEPTHFUNC_EQUAL ); + + s_pShaderShadow->SetVertexShader( "depthtodestalpha_vs20", 0 ); + s_pShaderShadow->SetPixelShader( "depthtodestalpha_ps20b", 0 ); + } + if( s_pShaderAPI ) + { + s_pShaderAPI->SetVertexShaderIndex( 0 ); + s_pShaderAPI->SetPixelShaderIndex( 0 ); + + bMakeActualDrawCall = s_pShaderAPI->ShouldWriteDepthToDestAlpha(); + } + Draw( bMakeActualDrawCall ); + } +#else + Assert( 0 ); //probably just needs a shader update to the latest +#endif +} diff --git a/materialsystem/stdshaders/BaseVSShader.h b/materialsystem/stdshaders/BaseVSShader.h new file mode 100644 index 0000000..860c687 --- /dev/null +++ b/materialsystem/stdshaders/BaseVSShader.h @@ -0,0 +1,440 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +// This is what all vs/ps (dx8+) shaders inherit from. +//===========================================================================// + +#ifndef BASEVSSHADER_H +#define BASEVSSHADER_H + +#ifdef _WIN32 +#pragma once +#endif + +#include "shaderlib/cshader.h" +#include "shaderlib/BaseShader.h" +#include "convar.h" +#include + +#ifdef _X360 +#define SUPPORT_DX8 0 +#define SUPPORT_DX7 0 +#else +#define SUPPORT_DX8 1 +#define SUPPORT_DX7 1 +#endif +//----------------------------------------------------------------------------- +// Helper macro for vertex shaders +//----------------------------------------------------------------------------- +#define BEGIN_VS_SHADER_FLAGS(_name, _help, _flags) __BEGIN_SHADER_INTERNAL( CBaseVSShader, _name, _help, _flags ) +#define BEGIN_VS_SHADER(_name,_help) __BEGIN_SHADER_INTERNAL( CBaseVSShader, _name, _help, 0 ) + + +// useful parameter initialization macro +#define INIT_FLOAT_PARM( parm, value ) \ + if ( !params[(parm)]->IsDefined() ) \ + { \ + params[(parm)]->SetFloatValue( (value) ); \ + } + +// useful pixel shader declaration macro for ps20/20b c++ code +#define SET_STATIC_PS2X_PIXEL_SHADER_NO_COMBOS( basename ) \ + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) \ + { \ + DECLARE_STATIC_PIXEL_SHADER( basename##_ps20b ); \ + SET_STATIC_PIXEL_SHADER( basename##_ps20b ); \ + } \ + else \ + { \ + DECLARE_STATIC_PIXEL_SHADER( basename##_ps20 ); \ + SET_STATIC_PIXEL_SHADER( basename##_ps20 ); \ + } + +#define SET_DYNAMIC_PS2X_PIXEL_SHADER_NO_COMBOS( basename ) \ + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) \ + { \ + DECLARE_DYNAMIC_PIXEL_SHADER( basename##_ps20b ); \ + SET_DYNAMIC_PIXEL_SHADER( basename##_ps20b ); \ + } \ + else \ + { \ + DECLARE_DYNAMIC_PIXEL_SHADER( basename##_ps20 ); \ + SET_DYNAMIC_PIXEL_SHADER( basename##_ps20 ); \ + } + + +//----------------------------------------------------------------------------- +// Base class for shaders, contains helper methods. +//----------------------------------------------------------------------------- +class CBaseVSShader : public CBaseShader +{ +public: + + // Loads bump lightmap coordinates into the pixel shader + void LoadBumpLightmapCoordinateAxes_PixelShader( int pixelReg ); + + // Loads bump lightmap coordinates into the vertex shader + void LoadBumpLightmapCoordinateAxes_VertexShader( int vertexReg ); + + // Pixel and vertex shader constants.... + void SetPixelShaderConstant( int pixelReg, int constantVar ); + + // Pixel and vertex shader constants.... + void SetPixelShaderConstantGammaToLinear( int pixelReg, int constantVar ); + + // This version will put constantVar into x,y,z, and constantVar2 into the w + void SetPixelShaderConstant( int pixelReg, int constantVar, int constantVar2 ); + void SetPixelShaderConstantGammaToLinear( int pixelReg, int constantVar, int constantVar2 ); + + // Helpers for setting constants that need to be converted to linear space (from gamma space). + void SetVertexShaderConstantGammaToLinear( int var, float const* pVec, int numConst = 1, bool bForce = false ); + void SetPixelShaderConstantGammaToLinear( int var, float const* pVec, int numConst = 1, bool bForce = false ); + + void SetVertexShaderConstant( int vertexReg, int constantVar ); + + // set rgb components of constant from a color parm and give an explicit w value + void SetPixelShaderConstant_W( int pixelReg, int constantVar, float fWValue ); + + // GR - fix for const/lerp issues + void SetPixelShaderConstantFudge( int pixelReg, int constantVar ); + + // Sets light direction for pixel shaders. + void SetPixelShaderLightColors( int pixelReg ); + + // Sets vertex shader texture transforms + void SetVertexShaderTextureTranslation( int vertexReg, int translationVar ); + void SetVertexShaderTextureScale( int vertexReg, int scaleVar ); + void SetVertexShaderTextureTransform( int vertexReg, int transformVar ); + void SetVertexShaderTextureScaledTransform( int vertexReg, + int transformVar, int scaleVar ); + + // Set pixel shader texture transforms + void SetPixelShaderTextureTranslation( int pixelReg, int translationVar ); + void SetPixelShaderTextureScale( int pixelReg, int scaleVar ); + void SetPixelShaderTextureTransform( int pixelReg, int transformVar ); + void SetPixelShaderTextureScaledTransform( int pixelReg, + int transformVar, int scaleVar ); + + // Moves a matrix into vertex shader constants + void SetVertexShaderMatrix2x4( int vertexReg, int matrixVar ); + void SetVertexShaderMatrix3x4( int vertexReg, int matrixVar ); + void SetVertexShaderMatrix4x4( int vertexReg, int matrixVar ); + + // Loads the view matrix into vertex shader constants + void LoadViewMatrixIntoVertexShaderConstant( int vertexReg ); + + // Loads the projection matrix into vertex shader constants + void LoadProjectionMatrixIntoVertexShaderConstant( int vertexReg ); + + // Loads the model->view matrix into vertex shader constants + void LoadModelViewMatrixIntoVertexShaderConstant( int vertexReg ); + + // Loads a scale/offset version of the viewport transform into the specified constant. + void LoadViewportTransformScaledIntoVertexShaderConstant( int vertexReg ); + + // Sets up ambient light cube... + void SetAmbientCubeDynamicStateVertexShader( ); + float GetAmbientLightCubeLuminance( ); + + // Helpers for dealing with envmaptint + void SetEnvMapTintPixelShaderDynamicState( int pixelReg, int tintVar, int alphaVar, bool bConvertFromGammaToLinear = false ); + + // Helper methods for pixel shader overbrighting + void EnablePixelShaderOverbright( int reg, bool bEnable, bool bDivideByTwo ); + + // Helper for dealing with modulation + void SetModulationVertexShaderDynamicState(); + void SetModulationPixelShaderDynamicState( int modulationVar ); + void SetModulationPixelShaderDynamicState_LinearColorSpace( int modulationVar ); + void SetModulationPixelShaderDynamicState_LinearColorSpace_LinearScale( int modulationVar, float flScale ); + + // Sets a color + alpha into shader constants + void SetColorVertexShaderConstant( int nVertexReg, int colorVar, int alphaVar ); + void SetColorPixelShaderConstant( int nPixelReg, int colorVar, int alphaVar ); + + +#ifndef GAME_SHADER_DLL + // + // Standard shader passes! + // + + void InitParamsUnlitGeneric_DX8( + int baseTextureVar, + int detailScaleVar, + int envmapOptionalVar, + int envmapVar, + int envmapTintVar, + int envmapMaskScaleVar, + int nDetailBlendMode ); + + void InitUnlitGeneric_DX8( + int baseTextureVar, + int detailVar, + int envmapVar, + int envmapMaskVar ); + + // Dx8 Unlit Generic pass + void VertexShaderUnlitGenericPass( int baseTextureVar, int frameVar, + int baseTextureTransformVar, + int detailVar, int detailTransform, bool bDetailTransformIsScale, + int envmapVar, int envMapFrameVar, int envmapMaskVar, + int envmapMaskFrameVar, int envmapMaskScaleVar, int envmapTintVar, + int alphaTestReferenceVar, + int nDetailBlendModeVar, + int nOutlineVar, + int nOutlineColorVar, + int nOutlineStartVar, + int nOutlineEndVar, + int nSeparateDetailUVsVar + ); + + // Helpers for drawing world bump mapped stuff. + void DrawModelBumpedSpecularLighting( int bumpMapVar, int bumpMapFrameVar, + int envMapVar, int envMapVarFrame, + int envMapTintVar, int alphaVar, + int envMapContrastVar, int envMapSaturationVar, + int bumpTransformVar, + bool bBlendSpecular, bool bNoWriteZ = false ); + void DrawWorldBumpedSpecularLighting( int bumpmapVar, int envmapVar, + int bumpFrameVar, int envmapFrameVar, + int envmapTintVar, int alphaVar, + int envmapContrastVar, int envmapSaturationVar, + int bumpTransformVar, int fresnelReflectionVar, + bool bBlend, bool bNoWriteZ = false ); + + const char *UnlitGeneric_ComputeVertexShaderName( bool bMask, + bool bEnvmap, + bool bBaseTexture, + bool bBaseAlphaEnvmapMask, + bool bDetail, + bool bVertexColor, + bool bEnvmapCameraSpace, + bool bEnvmapSphere ); + + const char *UnlitGeneric_ComputePixelShaderName( bool bMask, + bool bEnvmap, + bool bBaseTexture, + bool bBaseAlphaEnvmapMask, + bool bDetail, + bool bMultiplyDetail, + bool bMaskBaseByDetailAlpha ); + + void DrawWorldBaseTexture( int baseTextureVar, int baseTextureTransformVar, int frameVar, int colorVar, int alphaVar ); + void DrawWorldBumpedDiffuseLighting( int bumpmapVar, int bumpFrameVar, + int bumpTransformVar, bool bMultiply, bool bSSBump ); + void DrawWorldBumpedSpecularLighting( int envmapMaskVar, int envmapMaskFrame, + int bumpmapVar, int envmapVar, + int bumpFrameVar, int envmapFrameVar, + int envmapTintVar, int alphaVar, + int envmapContrastVar, int envmapSaturationVar, + int bumpTransformVar, int fresnelReflectionVar, + bool bBlend ); + void DrawBaseTextureBlend( int baseTextureVar, int baseTextureTransformVar, + int baseTextureFrameVar, + int baseTexture2Var, int baseTextureTransform2Var, + int baseTextureFrame2Var, int colorVar, int alphaVar ); + void DrawWorldBumpedDiffuseLighting_Base_ps14( int bumpmapVar, int bumpFrameVar, + int bumpTransformVar, int baseTextureVar, int baseTextureTransformVar, int frameVar ); + void DrawWorldBumpedDiffuseLighting_Blend_ps14( int bumpmapVar, int bumpFrameVar, int bumpTransformVar, + int baseTextureVar, int baseTextureTransformVar, int baseTextureFrameVar, + int baseTexture2Var, int baseTextureTransform2Var, int baseTextureFrame2Var); + void DrawWorldBumpedUsingVertexShader( int baseTextureVar, int baseTextureTransformVar, + int bumpmapVar, int bumpFrameVar, + int bumpTransformVar, + int envmapMaskVar, int envmapMaskFrame, + int envmapVar, + int envmapFrameVar, + int envmapTintVar, int colorVar, int alphaVar, + int envmapContrastVar, int envmapSaturationVar, int frameVar, int fresnelReflectionVar, + bool doBaseTexture2, + int baseTexture2Var, + int baseTextureTransform2Var, + int baseTextureFrame2Var, + bool bSSBump + ); + + // Sets up hw morphing state for the vertex shader + void SetHWMorphVertexShaderState( int nDimConst, int nSubrectConst, VertexTextureSampler_t morphSampler ); + + // Computes the shader index for vertex lit materials + int ComputeVertexLitShaderIndex( bool bVertexLitGeneric, bool hasBump, bool hasEnvmap, bool hasVertexColor, bool bHasNormal ) const; + + // Helper for setting up flashlight constants + void SetFlashlightVertexShaderConstants( bool bBump, int bumpTransformVar, bool bDetail, int detailScaleVar, bool bSetTextureTransforms ); + +#if SUPPORT_DX8 + void DrawFlashlight_dx80( IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow, + bool bBump, int bumpmapVar, int bumpmapFrame, int bumpTransform, int flashlightTextureVar, + int flashlightTextureFrameVar, bool bLightmappedGeneric, bool bWorldVertexTransition, + int nWorldVertexTransitionPassID, int baseTexture2Var, int baseTexture2FrameVar, + bool bTeeth=false, int nTeethForwardVar=0, int nTeethIllumFactorVar=0 ); +#endif + + struct DrawFlashlight_dx90_Vars_t + { + DrawFlashlight_dx90_Vars_t() + { + // set all ints to -1 + memset( this, 0xFF, sizeof(DrawFlashlight_dx90_Vars_t) ); + // set all bools to a default value. + m_bBump = false; + m_bLightmappedGeneric = false; + m_bWorldVertexTransition = false; + m_bTeeth = false; + m_bSSBump = false; + m_fSeamlessScale = 0.0; + } + bool m_bBump; + bool m_bLightmappedGeneric; + bool m_bWorldVertexTransition; + bool m_bTeeth; + int m_nBumpmapVar; + int m_nBumpmapFrame; + int m_nBumpTransform; + int m_nFlashlightTextureVar; + int m_nFlashlightTextureFrameVar; + int m_nBaseTexture2Var; + int m_nBaseTexture2FrameVar; + int m_nBumpmap2Var; + int m_nBumpmap2Frame; + int m_nBump2Transform; + int m_nDetailVar; + int m_nDetailScale; + int m_nDetailTextureCombineMode; + int m_nDetailTextureBlendFactor; + int m_nDetailTint; + int m_nTeethForwardVar; + int m_nTeethIllumFactorVar; + int m_nAlphaTestReference; + bool m_bSSBump; + float m_fSeamlessScale; // 0.0 = not seamless + }; + void DrawFlashlight_dx90( IMaterialVar** params, + IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow, DrawFlashlight_dx90_Vars_t &vars ); +#endif // GAME_SHADER_DLL + + BlendType_t EvaluateBlendRequirements( int textureVar, bool isBaseTexture, int detailTextureVar = -1 ); + + void HashShadow2DJitter( const float fJitterSeed, float *fU, float* fV ); + + //Alpha tested materials can end up leaving garbage in the dest alpha buffer if they write depth. + //This pass fills in the areas that passed the alpha test with depth in dest alpha + //by writing only equal depth pixels and only if we should be writing depth to dest alpha + void DrawEqualDepthToDestAlpha( void ); + +private: + // Helper methods for VertexLitGenericPass +// void UnlitGenericShadowState( int baseTextureVar, int detailVar, int envmapVar, int envmapMaskVar, bool doSkin ); + void UnlitGenericDynamicState( int baseTextureVar, int frameVar, int baseTextureTransformVar, + int detailVar, int detailTransform, bool bDetailTransformIsScale, int envmapVar, + int envMapFrameVar, int envmapMaskVar, int envmapMaskFrameVar, + int envmapMaskScaleVar, int envmapTintVar ); + + // Converts a color + alpha into a vector4 + void ColorVarsToVector( int colorVar, int alphaVar, Vector4D &color ); + +}; + +FORCEINLINE void SetFlashLightColorFromState( FlashlightState_t const &state, IShaderDynamicAPI *pShaderAPI, int nPSRegister=28, bool bFlashlightNoLambert=false ) +{ + // Old code + //float flToneMapScale = ( pShaderAPI->GetToneMappingScaleLinear() ).x; + //float flFlashlightScale = 1.0f / flToneMapScale; + + // Fix to old code to keep flashlight from ever getting brighter than 1.0 + //float flToneMapScale = ( pShaderAPI->GetToneMappingScaleLinear() ).x; + //if ( flToneMapScale < 1.0f ) + // flToneMapScale = 1.0f; + //float flFlashlightScale = 1.0f / flToneMapScale; + + // Force flashlight to 25% bright always + float flFlashlightScale = 0.25f; + + if ( !g_pHardwareConfig->GetHDREnabled() ) + { + // Non-HDR path requires 2.0 flashlight + flFlashlightScale = 2.0f; + } + + // DX10 requires some hackery due to sRGB/blend ordering change from DX9 + if ( g_pHardwareConfig->UsesSRGBCorrectBlending() ) + { + flFlashlightScale *= 2.5f; // Magic number that works well on the NVIDIA 8800 + } + + // Generate pixel shader constant + float const *pFlashlightColor = state.m_Color; + float vPsConst[4] = { flFlashlightScale * pFlashlightColor[0], flFlashlightScale * pFlashlightColor[1], flFlashlightScale * pFlashlightColor[2], pFlashlightColor[3] }; + vPsConst[3] = bFlashlightNoLambert ? 2.0f : 0.0f; // This will be added to N.L before saturate to force a 1.0 N.L term + + // Red flashlight for testing + //vPsConst[0] = 0.5f; vPsConst[1] = 0.0f; vPsConst[2] = 0.0f; + + pShaderAPI->SetPixelShaderConstant( nPSRegister, ( float * )vPsConst ); +} + +FORCEINLINE float ShadowAttenFromState( FlashlightState_t const &state ) +{ + // DX10 requires some hackery due to sRGB/blend ordering change from DX9, which makes the shadows too light + if ( g_pHardwareConfig->UsesSRGBCorrectBlending() ) + return state.m_flShadowAtten * 0.1f; // magic number + + return state.m_flShadowAtten; +} + +FORCEINLINE float ShadowFilterFromState( FlashlightState_t const &state ) +{ + // We developed shadow maps at 1024, so we expect the penumbra size to have been tuned relative to that + return state.m_flShadowFilterSize / 1024.0f; +} + + +// convenient material variable access functions for helpers to use. +FORCEINLINE bool IsTextureSet( int nVar, IMaterialVar **params ) +{ + return ( nVar != -1 ) && ( params[nVar]->IsTexture() ); +} + +FORCEINLINE bool IsBoolSet( int nVar, IMaterialVar **params ) +{ + return ( nVar != -1 ) && ( params[nVar]->GetIntValue() ); +} + +FORCEINLINE int GetIntParam( int nVar, IMaterialVar **params, int nDefaultValue = 0 ) +{ + return ( nVar != -1 ) ? ( params[nVar]->GetIntValue() ) : nDefaultValue; +} + +FORCEINLINE float GetFloatParam( int nVar, IMaterialVar **params, float flDefaultValue = 0.0 ) +{ + return ( nVar != -1 ) ? ( params[nVar]->GetFloatValue() ) : flDefaultValue; +} + +FORCEINLINE void InitFloatParam( int nIndex, IMaterialVar **params, float flValue ) +{ + if ( (nIndex != -1) && !params[nIndex]->IsDefined() ) + { + params[nIndex]->SetFloatValue( flValue ); + } +} + +FORCEINLINE void InitIntParam( int nIndex, IMaterialVar **params, int nValue ) +{ + if ( (nIndex != -1) && !params[nIndex]->IsDefined() ) + { + params[nIndex]->SetIntValue( nValue ); + } +} + + +class ConVar; + +#ifdef _DEBUG +extern ConVar mat_envmaptintoverride; +extern ConVar mat_envmaptintscale; +#endif + + +#endif // BASEVSSHADER_H diff --git a/materialsystem/stdshaders/Bloom.cpp b/materialsystem/stdshaders/Bloom.cpp new file mode 100644 index 0000000..37bab32 --- /dev/null +++ b/materialsystem/stdshaders/Bloom.cpp @@ -0,0 +1,90 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//===========================================================================// + +#include "BaseVSShader.h" + +#include "screenspaceeffect_vs20.inc" +#include "Bloom_ps20.inc" +#include "Bloom_ps20b.inc" + +BEGIN_VS_SHADER_FLAGS( Bloom, "Help for Bloom", SHADER_NOT_EDITABLE ) + BEGIN_SHADER_PARAMS + SHADER_PARAM( FBTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "_rt_FullFrameFB", "" ) + SHADER_PARAM( BLURTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "_rt_SmallHDR0", "" ) + END_SHADER_PARAMS + + SHADER_INIT + { + if( params[FBTEXTURE]->IsDefined() ) + { + LoadTexture( FBTEXTURE ); + } + if( params[BLURTEXTURE]->IsDefined() ) + { + LoadTexture( BLURTEXTURE ); + } + } + + SHADER_FALLBACK + { + // Requires DX9 + above + if ( g_pHardwareConfig->GetDXSupportLevel() < 90 ) + { + Assert( 0 ); + return "Wireframe"; + } + return 0; + } + + SHADER_DRAW + { + SHADOW_STATE + { + pShaderShadow->EnableDepthWrites( false ); + + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + int fmt = VERTEX_POSITION; + pShaderShadow->VertexShaderVertexFormat( fmt, 1, 0, 0 ); + + // Pre-cache shaders + DECLARE_STATIC_VERTEX_SHADER( screenspaceeffect_vs20 ); + SET_STATIC_VERTEX_SHADER( screenspaceeffect_vs20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_STATIC_PIXEL_SHADER( bloom_ps20b ); + SET_STATIC_PIXEL_SHADER( bloom_ps20b ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( bloom_ps20 ); + SET_STATIC_PIXEL_SHADER( bloom_ps20 ); + } + } + + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER0, FBTEXTURE, -1 ); + BindTexture( SHADER_SAMPLER1, BLURTEXTURE, -1 ); + DECLARE_DYNAMIC_VERTEX_SHADER( screenspaceeffect_vs20 ); + SET_DYNAMIC_VERTEX_SHADER( screenspaceeffect_vs20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_DYNAMIC_PIXEL_SHADER( bloom_ps20b ); + SET_DYNAMIC_PIXEL_SHADER( bloom_ps20b ); + } + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( bloom_ps20 ); + SET_DYNAMIC_PIXEL_SHADER( bloom_ps20 ); + } + } + Draw(); + } +END_SHADER diff --git a/materialsystem/stdshaders/Bloom_ps2x.fxc b/materialsystem/stdshaders/Bloom_ps2x.fxc new file mode 100644 index 0000000..1bad205 --- /dev/null +++ b/materialsystem/stdshaders/Bloom_ps2x.fxc @@ -0,0 +1,21 @@ +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX] + +#define HDRTYPE HDR_TYPE_NONE +#include "common_ps_fxc.h" + +sampler FBSampler : register( s0 ); +sampler BlurSampler : register( s1 ); + +struct PS_INPUT +{ + float2 texCoord : TEXCOORD0; +}; + +float4 main( PS_INPUT i ) : COLOR +{ + float4 fbSample = tex2D( FBSampler, i.texCoord ); + float4 blurSample = tex2D( BlurSampler, i.texCoord ); + + return FinalOutput( float4( fbSample + blurSample.rgb * blurSample.a * MAX_HDR_OVERBRIGHT, 1.0f ), 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE ); +} \ No newline at end of file diff --git a/materialsystem/stdshaders/BlurFilterX.cpp b/materialsystem/stdshaders/BlurFilterX.cpp new file mode 100644 index 0000000..f462423 --- /dev/null +++ b/materialsystem/stdshaders/BlurFilterX.cpp @@ -0,0 +1,122 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//===========================================================================// + +#include "BaseVSShader.h" +#include "BlurFilter_vs20.inc" +#include "BlurFilter_ps20.inc" +#include "BlurFilter_ps20b.inc" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +BEGIN_VS_SHADER_FLAGS( BlurFilterX, "Help for BlurFilterX", SHADER_NOT_EDITABLE ) + BEGIN_SHADER_PARAMS + END_SHADER_PARAMS + + SHADER_INIT + { + if( params[BASETEXTURE]->IsDefined() ) + { + LoadTexture( BASETEXTURE ); + } + } + + SHADER_FALLBACK + { + if ( g_pHardwareConfig->GetDXSupportLevel() < 90 ) + { + return "BlurFilterX_DX80"; + } + return 0; + } + + SHADER_DRAW + { + SHADOW_STATE + { + pShaderShadow->EnableDepthWrites( false ); + pShaderShadow->EnableAlphaWrites( true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->VertexShaderVertexFormat( VERTEX_POSITION, 1, 0, 0 ); + + // Render targets are pegged as sRGB on POSIX, so just force these reads and writes + bool bForceSRGBReadAndWrite = IsOSX() && g_pHardwareConfig->CanDoSRGBReadFromRTs(); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, bForceSRGBReadAndWrite ); + pShaderShadow->EnableSRGBWrite( bForceSRGBReadAndWrite ); + + // Pre-cache shaders + blurfilter_vs20_Static_Index vshIndex; + pShaderShadow->SetVertexShader( "BlurFilter_vs20", vshIndex.GetIndex() ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() || g_pHardwareConfig->ShouldAlwaysUseShaderModel2bShaders() ) + { + DECLARE_STATIC_PIXEL_SHADER( blurfilter_ps20b ); +#ifndef _X360 + SET_STATIC_PIXEL_SHADER_COMBO( APPROX_SRGB_ADAPTER, bForceSRGBReadAndWrite ); +#endif + SET_STATIC_PIXEL_SHADER( blurfilter_ps20b ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( blurfilter_ps20 ); + SET_STATIC_PIXEL_SHADER( blurfilter_ps20 ); + } + + if ( IS_FLAG_SET( MATERIAL_VAR_ADDITIVE ) ) + EnableAlphaBlending( SHADER_BLEND_ONE, SHADER_BLEND_ONE ); + } + + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER0, BASETEXTURE, -1 ); + + float v[4]; + + // The temp buffer is 1/4 back buffer size + ITexture *src_texture = params[BASETEXTURE]->GetTextureValue(); + int width = src_texture->GetActualWidth(); + float dX = 1.0f / width; + + // Tap offsets + v[0] = 1.3366f * dX; + v[1] = 0.0f; + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, v, 1 ); + v[0] = 3.4295f * dX; + v[1] = 0.0f; + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_1, v, 1 ); + v[0] = 5.4264f * dX; + v[1] = 0.0f; + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_2, v, 1 ); + + v[0] = 7.4359f * dX; + v[1] = 0.0f; + pShaderAPI->SetPixelShaderConstant( 0, v, 1 ); + v[0] = 9.4436f * dX; + v[1] = 0.0f; + pShaderAPI->SetPixelShaderConstant( 1, v, 1 ); + v[0] = 11.4401f * dX; + v[1] = 0.0f; + pShaderAPI->SetPixelShaderConstant( 2, v, 1 ); + v[0] = v[1] = v[2] = v[3] = 1.0; + pShaderAPI->SetPixelShaderConstant( 3, v, 1 ); + + pShaderAPI->SetVertexShaderIndex( 0 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() || g_pHardwareConfig->ShouldAlwaysUseShaderModel2bShaders() ) + { + DECLARE_DYNAMIC_PIXEL_SHADER( blurfilter_ps20b ); + SET_DYNAMIC_PIXEL_SHADER( blurfilter_ps20b ); + } + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( blurfilter_ps20 ); + SET_DYNAMIC_PIXEL_SHADER( blurfilter_ps20 ); + } + } + Draw(); + } +END_SHADER diff --git a/materialsystem/stdshaders/BlurFilterX_dx80.cpp b/materialsystem/stdshaders/BlurFilterX_dx80.cpp new file mode 100644 index 0000000..6eecfef --- /dev/null +++ b/materialsystem/stdshaders/BlurFilterX_dx80.cpp @@ -0,0 +1,86 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//===========================================================================// + +#include "BaseVSShader.h" +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +DEFINE_FALLBACK_SHADER( BlurFilterX, BlurFilterX_DX80 ) + +BEGIN_VS_SHADER_FLAGS( BlurFilterX_DX80, "Help for BlurFilterX_DX80", SHADER_NOT_EDITABLE ) + BEGIN_SHADER_PARAMS + END_SHADER_PARAMS + + SHADER_INIT + { + if( params[BASETEXTURE]->IsDefined() ) + { + LoadTexture( BASETEXTURE ); + } + } + + SHADER_FALLBACK + { + if ( g_pHardwareConfig->GetDXSupportLevel() < 80 ) + { + return "Wireframe"; + } + return 0; + } + + SHADER_DRAW + { + SHADOW_STATE + { + pShaderShadow->EnableDepthWrites( false ); + pShaderShadow->EnableAlphaWrites( true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER2, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER3, true ); + pShaderShadow->VertexShaderVertexFormat( VERTEX_POSITION, 1, 0, 0 ); + + // Pre-cache shaders + pShaderShadow->SetVertexShader( "BlurFilter_vs11", 0 ); + pShaderShadow->SetPixelShader( "BlurFilter_ps11", 0 ); + + if ( IS_FLAG_SET( MATERIAL_VAR_ADDITIVE ) ) + EnableAlphaBlending( SHADER_BLEND_ONE, SHADER_BLEND_ONE ); + } + + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER0, BASETEXTURE, -1 ); + BindTexture( SHADER_SAMPLER1, BASETEXTURE, -1 ); + BindTexture( SHADER_SAMPLER2, BASETEXTURE, -1 ); + BindTexture( SHADER_SAMPLER3, BASETEXTURE, -1 ); + + // The temp buffer is 1/4 back buffer size + ITexture *src_texture=params[BASETEXTURE]->GetTextureValue(); + int width = src_texture->GetActualWidth(); + float dX = 2.0f / width; + + // 4 Tap offsets, expected from pixel center + float v[4][4]; + v[0][0] = -1.5f * dX; + v[0][1] = 0; + v[1][0] = -0.5f * dX; + v[1][1] = 0; + v[2][0] = 0.5f * dX; + v[2][1] = 0; + v[3][0] = 1.5f * dX; + v[3][1] = 0; + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, &v[0][0], 4 ); + + v[0][0] = v[0][1] = v[0][2] = v[0][3] = 1.0f; + pShaderAPI->SetPixelShaderConstant( 1, v[0], 1 ); + + pShaderAPI->SetVertexShaderIndex( 0 ); + pShaderAPI->SetPixelShaderIndex( 0 ); + } + Draw(); + } +END_SHADER diff --git a/materialsystem/stdshaders/BlurFilterY.cpp b/materialsystem/stdshaders/BlurFilterY.cpp new file mode 100644 index 0000000..57db29c --- /dev/null +++ b/materialsystem/stdshaders/BlurFilterY.cpp @@ -0,0 +1,136 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//===========================================================================// + +#include "BaseVSShader.h" +#include "BlurFilter_vs20.inc" +#include "BlurFilter_ps20.inc" +#include "BlurFilter_ps20b.inc" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +BEGIN_VS_SHADER_FLAGS( BlurFilterY, "Help for BlurFilterY", SHADER_NOT_EDITABLE ) + BEGIN_SHADER_PARAMS + SHADER_PARAM( BLOOMAMOUNT, SHADER_PARAM_TYPE_FLOAT, "1.0", "" ) + SHADER_PARAM( FRAMETEXTURE, SHADER_PARAM_TYPE_TEXTURE, "_rt_SmallHDR0", "" ) + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + if ( !( params[BLOOMAMOUNT]->IsDefined() ) ) + { + params[BLOOMAMOUNT]->SetFloatValue( 1.0 ); + } + } + + SHADER_INIT + { + if ( params[BASETEXTURE]->IsDefined() ) + { + LoadTexture( BASETEXTURE ); + } + } + + SHADER_FALLBACK + { + if ( g_pHardwareConfig->GetDXSupportLevel() < 90 ) + { + return "BlurFilterY_DX80"; + } + return 0; + } + + SHADER_DRAW + { + SHADOW_STATE + { + pShaderShadow->EnableDepthWrites( false ); + pShaderShadow->EnableAlphaWrites( true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->VertexShaderVertexFormat( VERTEX_POSITION, 1, 0, 0 ); + + // Render targets are pegged as sRGB on POSIX, so just force these reads and writes + bool bForceSRGBReadAndWrite = IsOSX() && g_pHardwareConfig->CanDoSRGBReadFromRTs(); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, bForceSRGBReadAndWrite ); + pShaderShadow->EnableSRGBWrite( bForceSRGBReadAndWrite ); + + // Pre-cache shaders + DECLARE_STATIC_VERTEX_SHADER( blurfilter_vs20 ); + SET_STATIC_VERTEX_SHADER( blurfilter_vs20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() || g_pHardwareConfig->ShouldAlwaysUseShaderModel2bShaders() ) + { + DECLARE_STATIC_PIXEL_SHADER( blurfilter_ps20b ); +#ifndef _X360 + SET_STATIC_PIXEL_SHADER_COMBO( APPROX_SRGB_ADAPTER, bForceSRGBReadAndWrite ); +#endif + SET_STATIC_PIXEL_SHADER( blurfilter_ps20b ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( blurfilter_ps20 ); + SET_STATIC_PIXEL_SHADER( blurfilter_ps20 ); + } + + if ( IS_FLAG_SET( MATERIAL_VAR_ADDITIVE ) ) + EnableAlphaBlending( SHADER_BLEND_ONE, SHADER_BLEND_ONE ); + } + + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER0, BASETEXTURE, -1 ); + + // The temp buffer is 1/4 back buffer size + ITexture *src_texture = params[BASETEXTURE]->GetTextureValue(); + int height = src_texture->GetActualWidth(); + float dY = 1.0f / height; +// dY *= 0.4; + float v[4]; + + // Tap offsets + v[0] = 0.0f; + v[1] = 1.3366f * dY; + v[2] = 0; + v[3] = 0; + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, v, 1 ); + v[0] = 0.0f; + v[1] = 3.4295f * dY; + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_1, v, 1 ); + v[0] = 0.0f; + v[1] = 5.4264f * dY; + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_2, v, 1 ); + + v[0] = 0.0f; + v[1] = 7.4359f * dY; + pShaderAPI->SetPixelShaderConstant( 0, v, 1 ); + v[0] = 0.0f; + v[1] = 9.4436f * dY; + pShaderAPI->SetPixelShaderConstant( 1, v, 1 ); + v[0] = 0.0f; + v[1] = 11.4401f * dY; + pShaderAPI->SetPixelShaderConstant( 2, v, 1 ); + + v[0]=v[1]=v[2]=params[BLOOMAMOUNT]->GetFloatValue(); + + pShaderAPI->SetPixelShaderConstant( 3, v, 1 ); + + DECLARE_DYNAMIC_VERTEX_SHADER( blurfilter_ps20 ); + SET_DYNAMIC_VERTEX_SHADER( blurfilter_ps20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() || g_pHardwareConfig->ShouldAlwaysUseShaderModel2bShaders() ) + { + DECLARE_DYNAMIC_PIXEL_SHADER( blurfilter_ps20b ); + SET_DYNAMIC_PIXEL_SHADER( blurfilter_ps20b ); + } + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( blurfilter_ps20 ); + SET_DYNAMIC_PIXEL_SHADER( blurfilter_ps20 ); + } + } + Draw(); + } +END_SHADER diff --git a/materialsystem/stdshaders/BlurFilterY_dx80.cpp b/materialsystem/stdshaders/BlurFilterY_dx80.cpp new file mode 100644 index 0000000..5e01d60 --- /dev/null +++ b/materialsystem/stdshaders/BlurFilterY_dx80.cpp @@ -0,0 +1,91 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//===========================================================================// + +#include "BaseVSShader.h" +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +DEFINE_FALLBACK_SHADER( BlurFilterY, BlurFilterY_DX80 ) + +BEGIN_VS_SHADER_FLAGS( BlurFilterY_DX80, "Help for BlurFilterY_DX80", SHADER_NOT_EDITABLE ) + BEGIN_SHADER_PARAMS + SHADER_PARAM( BLOOMAMOUNT, SHADER_PARAM_TYPE_FLOAT, "1.0", "" ) + SHADER_PARAM( FRAMETEXTURE, SHADER_PARAM_TYPE_TEXTURE, "_rt_SmallHDR0", "" ) + END_SHADER_PARAMS + + SHADER_INIT + { + if ( params[BASETEXTURE]->IsDefined() ) + { + LoadTexture( BASETEXTURE ); + } + if ( !( params[BLOOMAMOUNT]->IsDefined() ) ) + params[BLOOMAMOUNT]->SetFloatValue(1.0); + } + + SHADER_FALLBACK + { + if ( g_pHardwareConfig->GetDXSupportLevel() < 80 ) + { + return "Wireframe"; + } + return 0; + } + + SHADER_DRAW + { + SHADOW_STATE + { + pShaderShadow->EnableDepthWrites( false ); + pShaderShadow->EnableAlphaWrites( true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER2, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER3, true ); + pShaderShadow->VertexShaderVertexFormat( VERTEX_POSITION, 1, 0, 0 ); + + // Pre-cache shaders + pShaderShadow->SetVertexShader( "BlurFilter_vs11", 0 ); + pShaderShadow->SetPixelShader( "BlurFilter_ps11", 0 ); + + if ( IS_FLAG_SET( MATERIAL_VAR_ADDITIVE ) ) + EnableAlphaBlending( SHADER_BLEND_ONE, SHADER_BLEND_ONE ); + } + + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER0, BASETEXTURE, -1 ); + BindTexture( SHADER_SAMPLER1, BASETEXTURE, -1 ); + BindTexture( SHADER_SAMPLER2, BASETEXTURE, -1 ); + BindTexture( SHADER_SAMPLER3, BASETEXTURE, -1 ); + + int width, height; + pShaderAPI->GetBackBufferDimensions( width, height ); + + // The temp buffer is 1/4 back buffer size + float dY = 2.0f / height; + + // 4 Tap offsets, expected from pixel center + float v[4][4]; + v[0][0] = 0; + v[0][1] = -1.5f * dY; + v[1][0] = 0; + v[1][1] = -0.5f * dY; + v[2][0] = 0; + v[2][1] = 0.5f * dY; + v[3][0] = 0; + v[3][1] = 1.5f * dY; + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, &v[0][0], 4 ); + + v[0][0] = v[0][1] = v[0][2] = params[BLOOMAMOUNT]->GetFloatValue(); + pShaderAPI->SetPixelShaderConstant( 1, v[0], 1 ); + + pShaderAPI->SetVertexShaderIndex( 0 ); + pShaderAPI->SetPixelShaderIndex( 0 ); + } + Draw(); + } +END_SHADER diff --git a/materialsystem/stdshaders/BlurFilter_ps11.psh b/materialsystem/stdshaders/BlurFilter_ps11.psh new file mode 100644 index 0000000..ee58a65 --- /dev/null +++ b/materialsystem/stdshaders/BlurFilter_ps11.psh @@ -0,0 +1,18 @@ +ps.1.1 + +// 1221 filter constants +def c0, 0.1667f, 0.1667f, 0.1667f, 0.3333f + +tex t0 +tex t1 +tex t2 +tex t3 + +mul r0.rgb, t0, c0 +mad r0.rgb, t1, c0.a, r0 +mad r0.rgb, t2, c0.a, r0 +mad r0.rgb, t3, c0, r0 + +mul r0.rgb, r0, c1 + +mov r0.a, t0.a + diff --git a/materialsystem/stdshaders/BlurFilter_ps2x.fxc b/materialsystem/stdshaders/BlurFilter_ps2x.fxc new file mode 100644 index 0000000..bfd082b --- /dev/null +++ b/materialsystem/stdshaders/BlurFilter_ps2x.fxc @@ -0,0 +1,91 @@ +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX] +// STATIC: "APPROX_SRGB_ADAPTER" "0..1" [ps20b] [PC] + +#define HDRTYPE HDR_TYPE_NONE +#include "common_ps_fxc.h" + +sampler TexSampler : register( s0 ); + +struct PS_INPUT +{ + float2 coordTap0 : TEXCOORD0; + float2 coordTap1 : TEXCOORD1; + float2 coordTap2 : TEXCOORD2; + float2 coordTap3 : TEXCOORD3; + float2 coordTap1Neg : TEXCOORD4; + float2 coordTap2Neg : TEXCOORD5; + float2 coordTap3Neg : TEXCOORD6; +}; + +float2 psTapOffs[3] : register( c0 ); +float3 scale_factor : register( c3 ); + +float4 SampleTexture( sampler texSampler, float2 uv ) +{ + float4 cSample = tex2D( texSampler, uv ); + + #if ( APPROX_SRGB_ADAPTER ) + { + cSample.rgb = max( cSample.rgb, float3( 0.00001f, 0.00001f, 0.00001f ) ); // rsqrt doesn't like inputs of zero + + float3 ooSQRT; // + ooSQRT.r = rsqrt( cSample.r ); // + ooSQRT.g = rsqrt( cSample.g ); // Approximate linear-to-sRGB conversion + ooSQRT.b = rsqrt( cSample.b ); // + cSample.rgb *= ooSQRT.rgb; // + } + #endif + + return cSample; +} + +float4 main( PS_INPUT i ) : COLOR +{ + float4 s0, s1, s2, s3, s4, s5, s6, color; + + // Sample taps with coordinates from VS + s0 = SampleTexture( TexSampler, i.coordTap0 ); + s1 = SampleTexture( TexSampler, i.coordTap1 ); + s2 = SampleTexture( TexSampler, i.coordTap2 ); + s3 = SampleTexture( TexSampler, i.coordTap3 ); + s4 = SampleTexture( TexSampler, i.coordTap1Neg ); + s5 = SampleTexture( TexSampler, i.coordTap2Neg ); + s6 = SampleTexture( TexSampler, i.coordTap3Neg ); + + color = s0 * 0.2013f; + color += ( s1 + s4 ) * 0.2185f; + color += ( s2 + s5 ) * 0.0821f; + color += ( s3 + s6 ) * 0.0461f; + + // Compute tex coords for other taps + float2 coordTap4 = i.coordTap0 + psTapOffs[0]; + float2 coordTap5 = i.coordTap0 + psTapOffs[1]; + float2 coordTap6 = i.coordTap0 + psTapOffs[2]; + float2 coordTap4Neg = i.coordTap0 - psTapOffs[0]; + float2 coordTap5Neg = i.coordTap0 - psTapOffs[1]; + float2 coordTap6Neg = i.coordTap0 - psTapOffs[2]; + + // Sample the taps + s1 = SampleTexture( TexSampler, coordTap4 ); + s2 = SampleTexture( TexSampler, coordTap5 ); + s3 = SampleTexture( TexSampler, coordTap6 ); + s4 = SampleTexture( TexSampler, coordTap4Neg ); + s5 = SampleTexture( TexSampler, coordTap5Neg ); + s6 = SampleTexture( TexSampler, coordTap6Neg ); + + color += ( s1 + s4 ) * 0.0262f; + color += ( s2 + s5 ) * 0.0162f; + color += ( s3 + s6 ) * 0.0102f; + color.xyz*=scale_factor.xyz; + + #if ( APPROX_SRGB_ADAPTER ) + { + color.xyz *= color.xyz; // Approximate sRGB-to-linear conversion + } + #endif + + return color; + //return FinalOutput( color, 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE ); +} + diff --git a/materialsystem/stdshaders/BlurFilter_vs11.fxc b/materialsystem/stdshaders/BlurFilter_vs11.fxc new file mode 100644 index 0000000..0a21352 --- /dev/null +++ b/materialsystem/stdshaders/BlurFilter_vs11.fxc @@ -0,0 +1,34 @@ +#include "common_vs_fxc.h" + +struct VS_INPUT +{ + float3 vPos : POSITION; + float2 vBaseTexCoord : TEXCOORD0; +}; + +struct VS_OUTPUT +{ + float4 projPos : POSITION; + float2 coordTap0 : TEXCOORD0; + float2 coordTap1 : TEXCOORD1; + float2 coordTap2 : TEXCOORD2; + float2 coordTap3 : TEXCOORD3; +}; + +float2 vsTapOffs[4] : register ( SHADER_SPECIFIC_CONST_0 ); + +VS_OUTPUT main( const VS_INPUT v ) +{ + VS_OUTPUT o = ( VS_OUTPUT )0; + + o.projPos = float4( v.vPos, 1.0f ); + + o.coordTap0 = v.vBaseTexCoord + vsTapOffs[0]; + o.coordTap1 = v.vBaseTexCoord + vsTapOffs[1]; + o.coordTap2 = v.vBaseTexCoord + vsTapOffs[2]; + o.coordTap3 = v.vBaseTexCoord + vsTapOffs[3]; + + return o; +} + + diff --git a/materialsystem/stdshaders/BlurFilter_vs20.fxc b/materialsystem/stdshaders/BlurFilter_vs20.fxc new file mode 100644 index 0000000..3c37fa7 --- /dev/null +++ b/materialsystem/stdshaders/BlurFilter_vs20.fxc @@ -0,0 +1,39 @@ +#include "common_vs_fxc.h" + +struct VS_INPUT +{ + float3 vPos : POSITION; + float2 vBaseTexCoord : TEXCOORD0; +}; + +struct VS_OUTPUT +{ + float4 projPos : POSITION; + float2 coordTap0 : TEXCOORD0; + float2 coordTap1 : TEXCOORD1; + float2 coordTap2 : TEXCOORD2; + float2 coordTap3 : TEXCOORD3; + float2 coordTap1Neg : TEXCOORD4; + float2 coordTap2Neg : TEXCOORD5; + float2 coordTap3Neg : TEXCOORD6; +}; + +float2 vsTapOffs[3] : register ( SHADER_SPECIFIC_CONST_0 ); + +VS_OUTPUT main( const VS_INPUT v ) +{ + VS_OUTPUT o = ( VS_OUTPUT )0; + + o.projPos = float4( v.vPos, 1.0f ); + o.coordTap0 = v.vBaseTexCoord; + o.coordTap1 = v.vBaseTexCoord + vsTapOffs[0]; + o.coordTap2 = v.vBaseTexCoord + vsTapOffs[1]; + o.coordTap3 = v.vBaseTexCoord + vsTapOffs[2]; + o.coordTap1Neg = v.vBaseTexCoord - vsTapOffs[0]; + o.coordTap2Neg = v.vBaseTexCoord - vsTapOffs[1]; + o.coordTap3Neg = v.vBaseTexCoord - vsTapOffs[2]; + + return o; +} + + diff --git a/materialsystem/stdshaders/BufferClearObeyStencil_dx6.cpp b/materialsystem/stdshaders/BufferClearObeyStencil_dx6.cpp new file mode 100644 index 0000000..b0f1696 --- /dev/null +++ b/materialsystem/stdshaders/BufferClearObeyStencil_dx6.cpp @@ -0,0 +1,51 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: Clears color/depth, but obeys stencil while doing so +// +// $Header: $ +// $NoKeywords: $ +//=============================================================================// + +#include "shaderlib/cshader.h" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +DEFINE_FALLBACK_SHADER( BufferClearObeyStencil, BufferClearObeyStencil_DX6 ) + +BEGIN_SHADER_FLAGS( BufferClearObeyStencil_DX6, "Help for BufferClearObeyStencil_DX6", SHADER_NOT_EDITABLE ) + + BEGIN_SHADER_PARAMS + SHADER_PARAM( CLEARCOLOR, SHADER_PARAM_TYPE_INTEGER, "1", "activates clearing of color" ) + SHADER_PARAM( CLEARDEPTH, SHADER_PARAM_TYPE_INTEGER, "1", "activates clearing of depth" ) + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + } + + SHADER_INIT + { + } + + SHADER_DRAW + { + SHADOW_STATE + { + pShaderShadow->DepthFunc( SHADER_DEPTHFUNC_ALWAYS ); + bool bEnableDepthWrites = params[CLEARDEPTH]->GetIntValue() != 0; + pShaderShadow->EnableDepthWrites( bEnableDepthWrites ); + bool bEnableColorWrites = params[CLEARCOLOR]->GetIntValue() != 0; + pShaderShadow->EnableColorWrites( bEnableColorWrites ); + pShaderShadow->EnableAlphaWrites( bEnableColorWrites ); + + pShaderShadow->DrawFlags( SHADER_DRAW_POSITION | SHADER_DRAW_COLOR ); + + DisableFog(); + } + DYNAMIC_STATE + { + } + Draw( ); + } +END_SHADER diff --git a/materialsystem/stdshaders/BufferClearObeyStencil_dx8.cpp b/materialsystem/stdshaders/BufferClearObeyStencil_dx8.cpp new file mode 100644 index 0000000..fcf43b8 --- /dev/null +++ b/materialsystem/stdshaders/BufferClearObeyStencil_dx8.cpp @@ -0,0 +1,67 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: Clears color/depth, but obeys stencil while doing so +// +//=============================================================================// + +#include "BaseVSShader.h" +#include "BufferClearObeyStencil_vs11.inc" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +DEFINE_FALLBACK_SHADER( BufferClearObeyStencil, BufferClearObeyStencil_DX8 ) + +BEGIN_VS_SHADER_FLAGS( BufferClearObeyStencil_DX8, "", SHADER_NOT_EDITABLE ) + + BEGIN_SHADER_PARAMS + SHADER_PARAM( CLEARCOLOR, SHADER_PARAM_TYPE_INTEGER, "1", "activates clearing of color" ) + SHADER_PARAM( CLEARDEPTH, SHADER_PARAM_TYPE_INTEGER, "1", "activates clearing of depth" ) + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + } + + SHADER_FALLBACK + { + if ( g_pHardwareConfig->GetDXSupportLevel() < 80 ) + { + return "BufferClearObeyStencil_DX6"; + } + return 0; + } + + SHADER_INIT + { + } + + SHADER_DRAW + { + SHADOW_STATE + { + pShaderShadow->DepthFunc( SHADER_DEPTHFUNC_ALWAYS ); + bool bEnableDepthWrites = params[CLEARDEPTH]->GetIntValue() != 0; + pShaderShadow->EnableDepthWrites( bEnableDepthWrites ); + + bool bEnableColorWrites = params[CLEARCOLOR]->GetIntValue() != 0; + pShaderShadow->EnableColorWrites( bEnableColorWrites ); + pShaderShadow->EnableAlphaWrites( bEnableColorWrites ); + + pShaderShadow->VertexShaderVertexFormat( VERTEX_POSITION|VERTEX_COLOR, 1, 0, 0 ); + + bufferclearobeystencil_vs11_Static_Index vshIndex; + pShaderShadow->SetVertexShader( "BufferClearObeyStencil_vs11", vshIndex.GetIndex() ); + pShaderShadow->SetPixelShader( "BufferClearObeyStencil_ps11", 0 ); + } + + DYNAMIC_STATE + { + pShaderAPI->SetVertexShaderIndex( 0 ); + pShaderAPI->SetPixelShaderIndex( 0 ); + } + + Draw( ); + } + +END_SHADER diff --git a/materialsystem/stdshaders/BufferClearObeyStencil_dx9.cpp b/materialsystem/stdshaders/BufferClearObeyStencil_dx9.cpp new file mode 100644 index 0000000..ed871a9 --- /dev/null +++ b/materialsystem/stdshaders/BufferClearObeyStencil_dx9.cpp @@ -0,0 +1,112 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: Clears color/depth, but obeys stencil while doing so +// +//=============================================================================// + +#include "BaseVSShader.h" + +#include "bufferclearobeystencil_vs20.inc" +#include "bufferclearobeystencil_ps20.inc" +#include "bufferclearobeystencil_ps20b.inc" + + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +DEFINE_FALLBACK_SHADER( BufferClearObeyStencil, BufferClearObeyStencil_DX9 ) + +BEGIN_VS_SHADER_FLAGS( BufferClearObeyStencil_DX9, "", SHADER_NOT_EDITABLE ) + + BEGIN_SHADER_PARAMS + SHADER_PARAM( CLEARCOLOR, SHADER_PARAM_TYPE_INTEGER, "1", "activates clearing of color" ) + SHADER_PARAM( CLEARALPHA, SHADER_PARAM_TYPE_INTEGER, "-1", "activates clearing of alpha. -1 == copy CLEARCOLOR setting" ) + SHADER_PARAM( CLEARDEPTH, SHADER_PARAM_TYPE_INTEGER, "1", "activates clearing of depth" ) + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + } + + SHADER_FALLBACK + { + if ( g_pHardwareConfig->GetDXSupportLevel() < 90 ) + { + return "BufferClearObeyStencil_DX8"; + } + return 0; + } + + SHADER_INIT + { + if ( !params[CLEARALPHA]->IsDefined() ) + params[CLEARALPHA]->SetIntValue( -1 ); + } + + SHADER_DRAW + { + bool bEnableColorWrites = params[CLEARCOLOR]->GetIntValue() != 0; + bool bEnableAlphaWrites = (params[CLEARALPHA]->GetIntValue() >= 0) ? (params[CLEARALPHA]->GetIntValue() != 0) : bEnableColorWrites; + + bool bUsesColor = bEnableColorWrites || bEnableAlphaWrites; + SHADOW_STATE + { + pShaderShadow->DepthFunc( SHADER_DEPTHFUNC_ALWAYS ); + bool bEnableDepthWrites = params[CLEARDEPTH]->GetIntValue() != 0; + pShaderShadow->EnableDepthWrites( bEnableDepthWrites ); + + pShaderShadow->EnableColorWrites( bEnableColorWrites ); + pShaderShadow->EnableAlphaWrites( bEnableAlphaWrites ); + + pShaderShadow->VertexShaderVertexFormat( VERTEX_POSITION | VERTEX_COLOR, 1, NULL, 0 ); + + DECLARE_STATIC_VERTEX_SHADER( bufferclearobeystencil_vs20 ); + SET_STATIC_VERTEX_SHADER_COMBO( USESCOLOR, bUsesColor || g_pHardwareConfig->PlatformRequiresNonNullPixelShaders() ); + SET_STATIC_VERTEX_SHADER( bufferclearobeystencil_vs20 ); + + //avoid setting a pixel shader when only doing depth/stencil operations, as recommended by PIX + if( bUsesColor || g_pHardwareConfig->PlatformRequiresNonNullPixelShaders() ) + { + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_STATIC_PIXEL_SHADER( bufferclearobeystencil_ps20b ); + SET_STATIC_PIXEL_SHADER( bufferclearobeystencil_ps20b ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( bufferclearobeystencil_ps20 ); + SET_STATIC_PIXEL_SHADER( bufferclearobeystencil_ps20 ); + } + } + + pShaderShadow->EnableBlending( true ); + pShaderShadow->BlendFunc( SHADER_BLEND_ONE, SHADER_BLEND_ZERO ); + pShaderShadow->EnableAlphaTest( true ); + pShaderShadow->AlphaFunc( SHADER_ALPHAFUNC_ALWAYS, 0 ); + } + + DYNAMIC_STATE + { + DECLARE_DYNAMIC_VERTEX_SHADER( bufferclearobeystencil_vs20 ); + SET_DYNAMIC_VERTEX_SHADER( bufferclearobeystencil_vs20 ); + + //avoid setting a pixel shader when only doing depth/stencil operations, as recommended by PIX + if( bUsesColor || g_pHardwareConfig->PlatformRequiresNonNullPixelShaders() ) + { + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_DYNAMIC_PIXEL_SHADER( bufferclearobeystencil_ps20b ); + SET_DYNAMIC_PIXEL_SHADER( bufferclearobeystencil_ps20b ); + } + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( bufferclearobeystencil_ps20 ); + SET_DYNAMIC_PIXEL_SHADER( bufferclearobeystencil_ps20 ); + } + } + } + + Draw( ); + } + +END_SHADER diff --git a/materialsystem/stdshaders/BufferClearObeyStencil_ps11.psh b/materialsystem/stdshaders/BufferClearObeyStencil_ps11.psh new file mode 100644 index 0000000..6d4662c --- /dev/null +++ b/materialsystem/stdshaders/BufferClearObeyStencil_ps11.psh @@ -0,0 +1,3 @@ +ps.1.1 + +mov r0, v0 \ No newline at end of file diff --git a/materialsystem/stdshaders/BufferClearObeyStencil_vs11.vsh b/materialsystem/stdshaders/BufferClearObeyStencil_vs11.vsh new file mode 100644 index 0000000..7458979 --- /dev/null +++ b/materialsystem/stdshaders/BufferClearObeyStencil_vs11.vsh @@ -0,0 +1,8 @@ +vs.1.1 + +#include "macros.vsh" + +mov oPos.xyz, $vPos.xyz +mov oPos.w, $cOne + +mov oD0, $vColor diff --git a/materialsystem/stdshaders/BumpmappedEnvmap.psh b/materialsystem/stdshaders/BumpmappedEnvmap.psh new file mode 100644 index 0000000..f57309e --- /dev/null +++ b/materialsystem/stdshaders/BumpmappedEnvmap.psh @@ -0,0 +1,32 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; Environment mapping on a bumped surface +; t0 - Normalmap +; t3 - Cube environment map (*must* be a cube map!) +; +; c0 - color to multiply the results by +; Input texture coords required here are a little wonky. +; tc0.uv <- U,V into the normal map +; tc1.uvw, tc2.uvw, tc3.uvw <- 3x3 matrix transform +; from tangent space->env map space +; tc1.q, tc2.q, tc3.q <- eye vector in env map space +;------------------------------------------------------------------------------ + +; Get the 3-vector from the normal map +tex t0 + +; Perform matrix multiply to get a local normal bump. Then +; reflect the eye vector through the normal and sample from +; a cubic environment map. +texm3x3pad t1, t0_bx2 +texm3x3pad t2, t0_bx2 +texm3x3vspec t3, t0_bx2 + +; result goes in output color (multiply by constant color c0) +mul r0, t3, c0 + +; The output alpha comes from the normal map. +mov r0.w, t0.a ; don't need this if we aren't alpha blending! + + diff --git a/materialsystem/stdshaders/BumpmappedEnvmap.vsh b/materialsystem/stdshaders/BumpmappedEnvmap.vsh new file mode 100644 index 0000000..4356145 --- /dev/null +++ b/materialsystem/stdshaders/BumpmappedEnvmap.vsh @@ -0,0 +1,83 @@ +vs.1.1 + +# DYNAMIC: "DOWATERFOG" "0..1" + +;------------------------------------------------------------------------------ +; Shader specific constant: +; $SHADER_SPECIFIC_CONST_4, $SHADER_SPECIFIC_CONST_5 = normal map transform +;------------------------------------------------------------------------------ + +#include "macros.vsh" + +;------------------------------------------------------------------------------ +; Vertex blending +;------------------------------------------------------------------------------ + +&AllocateRegister( \$worldPos ); + +; Transform position from object to world +dp4 $worldPos.x, $vPos, $cModel0 +dp4 $worldPos.y, $vPos, $cModel1 +dp4 $worldPos.z, $vPos, $cModel2 + +&AllocateRegister( \$projPos ); + +; Transform position from object to projection space +dp4 $projPos.x, $vPos, $cModelViewProj0 +dp4 $projPos.y, $vPos, $cModelViewProj1 +dp4 $projPos.z, $vPos, $cModelViewProj2 +dp4 $projPos.w, $vPos, $cModelViewProj3 + +mov oPos, $projPos + +;------------------------------------------------------------------------------ +; Lighting +;------------------------------------------------------------------------------ + +; Transform tangent space basis vectors to env map space (world space) +; This will produce a set of vectors mapping from tangent space to env space +; We'll use this to transform normals from the normal map from tangent space +; to environment map space. +; NOTE: use dp3 here since the basis vectors are vectors, not points + +dp3 oT1.x, $vTangentS, $cModel0 +dp3 oT2.x, $vTangentS, $cModel1 +dp3 oT3.x, $vTangentS, $cModel2 + +dp3 oT1.y, $vTangentT, $cModel0 +dp3 oT2.y, $vTangentT, $cModel1 +dp3 oT3.y, $vTangentT, $cModel2 + +dp3 oT1.z, $vNormal, $cModel0 +dp3 oT2.z, $vNormal, $cModel1 +dp3 oT3.z, $vNormal, $cModel2 + +&AllocateRegister( \$worldToEye ); + +; Compute the vector from vertex to camera +sub $worldToEye.xyz, $cEyePos, $worldPos + +;------------------------------------------------------------------------------ +; Fog +;------------------------------------------------------------------------------ + +&CalcFog( $worldPos, $projPos ); + +&FreeRegister( \$worldPos ); + +; Move it into the w component of the texture coords, as the wacky +; pixel shader wants it there. +mov oT1.w, $worldToEye.x +mov oT2.w, $worldToEye.y +mov oT3.w, $worldToEye.z + +&FreeRegister( \$worldToEye ); + +;------------------------------------------------------------------------------ +; Texture coordinates (normal map) +;------------------------------------------------------------------------------ +dp4 oT0.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_4 +dp4 oT0.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_5 + + +&FreeRegister( \$projPos ); diff --git a/materialsystem/stdshaders/BumpmappedLightmap.vsh b/materialsystem/stdshaders/BumpmappedLightmap.vsh new file mode 100644 index 0000000..16ba0a5 --- /dev/null +++ b/materialsystem/stdshaders/BumpmappedLightmap.vsh @@ -0,0 +1,57 @@ +vs.1.1 + +# DYNAMIC: "DOWATERFOG" "0..1" + +#include "macros.vsh" + +;------------------------------------------------------------------------------ +; Vertex blending +;------------------------------------------------------------------------------ + +alloc $projPos + +; Transform position from object to projection space +; put in r1 now since we need it for fog. +dp4 $projPos.x, $vPos, $cModelViewProj0 +dp4 $projPos.y, $vPos, $cModelViewProj1 +dp4 $projPos.z, $vPos, $cModelViewProj2 +dp4 $projPos.w, $vPos, $cModelViewProj3 + +mov oPos, $projPos + +alloc $worldPos +if( $DOWATERFOG == 1 ) +{ + ; Get the worldpos z component only since that's all we need for height fog + dp4 $worldPos.z, $vPos, $cModel2 +} +&CalcFog( $worldPos, $projPos ); +free $worldPos + + +;------------------------------------------------------------------------------ +; Texture coordinates +;------------------------------------------------------------------------------ + +; Compute the texture coordinates given the offset between +; each bumped lightmap + +&AllocateRegister( \$bumpOffset ); + +mov $bumpOffset.xy, $vTexCoord2 +mov oT0, $vTexCoord0 ; bumpmap texcoords +add oT1.xy, $bumpOffset, $vTexCoord1 ; first lightmap texcoord +mad oT2.xy, $bumpOffset, $cTwo, $vTexCoord1 ; second lightmap texcoord +; make a 3 +alloc $three +add $three, $cOne, $cTwo +mad oT3.xy, $bumpOffset, $three, $vTexCoord1 ; third lightmap texcoord +free $three + +&FreeRegister( \$bumpOffset ); + +;------------------------------------------------------------------------------ +; Fog +;------------------------------------------------------------------------------ + +free $projPos diff --git a/materialsystem/stdshaders/BumpmappedLightmap_LightingOnly_OverBright2.psh b/materialsystem/stdshaders/BumpmappedLightmap_LightingOnly_OverBright2.psh new file mode 100644 index 0000000..f3a6301 --- /dev/null +++ b/materialsystem/stdshaders/BumpmappedLightmap_LightingOnly_OverBright2.psh @@ -0,0 +1,43 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; Computes the diffuse component of lighting using lightmap + bumpmap +; t0 - Normalmap +; t1 - Lightmap1 +; t2 - Lightmap2 +; t3 - Lightmap3 +; +; The texture coordinates need to be defined as follows: +; tc0 - Normalmap and lightmap texture coordinates +; c0, c1, c2 - Axes of the lightmap coordinate system in tangent space +; c3 = a +; c4 = b +; c5 = c in a quadratic approx to pow( 1/2.2 ) +;------------------------------------------------------------------------------ + +; Get the 3-vector from the normal map +tex t0 + +; Sample the lightmaps +tex t1 +tex t2 +tex t3 + +; Compute the dot product of axis 1 and the normal +dp3_sat r1, t0_bx2, c0 +; Modulate the lightmap color by N dot Axis 1 +mul r0, t1, r1 + +; Do the same for the other two axes +dp3_sat r1, t0_bx2, c1 +mad r0, r1, t2, r0 + +dp3_sat r1, t0_bx2, c2 +mad r0, r1, t3, r0 + +; Do quadratic approximation to pow( x, 1 / 2.2 ) +;mad r1, c3, r0, c4 ; r1 = a*x + b +;mad_x4_sat r0, r1, r0, c5 ; r0 = r1*x + c = a*x*x + b*x + c + + + diff --git a/materialsystem/stdshaders/BumpmappedLightmap_OverBright2.psh b/materialsystem/stdshaders/BumpmappedLightmap_OverBright2.psh new file mode 100644 index 0000000..29d9192 --- /dev/null +++ b/materialsystem/stdshaders/BumpmappedLightmap_OverBright2.psh @@ -0,0 +1,43 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; Computes the diffuse component of lighting using lightmap + bumpmap +; t0 - Normalmap +; t1 - Lightmap1 +; t2 - Lightmap2 +; t3 - Lightmap3 +; +; The texture coordinates need to be defined as follows: +; tc0 - Normalmap and lightmap texture coordinates +; c0, c1, c2 - Axes of the lightmap coordinate system in tangent space +; c3 = a +; c4 = b +; c5 = c in a quadratic approx to pow( 1/2.2 ) +;------------------------------------------------------------------------------ + +; Get the 3-vector from the normal map +tex t0 + +; Sample the lightmaps +tex t1 +tex t2 +tex t3 + +; Compute the dot product of axis 1 and the normal +dp3_sat r1, t0_bx2, c0 +; Modulate the lightmap color by N dot Axis 1 +mul r0, t1, r1 + +; Do the same for the other two axes +dp3_sat r1, t0_bx2, c1 +mad r0, r1, t2, r0 + +dp3_sat r1, t0_bx2, c2 +mad r0, r1, t3, r0 + +; Do quadratic approximation to pow( x, 1 / 2.2 ) +;mad r1, c3, r0, c4 ; r1 = a*x + b +;mad_x2_sat r0, r1, r0, c5 ; r0 = r1*x + c = a*x*x + b*x + c + + + diff --git a/materialsystem/stdshaders/Cable.psh b/materialsystem/stdshaders/Cable.psh new file mode 100644 index 0000000..6ba9263 --- /dev/null +++ b/materialsystem/stdshaders/Cable.psh @@ -0,0 +1,27 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; See the vertex shader for info +; +; This shader takes: +; t0 = normal map +; t1 = base texture +; v0 = directional light color +; t2 = directional light direction (biased into 0-1) +; c0 = percent of dirlight to add as ambient +; +; Output: +; (t0 dot t1) * v0 +;------------------------------------------------------------------------------ + +tex t0 ; Get the 3-vector from the normal map +tex t1 ; Interpret tcoord t1 as color data. +texcoord t2 + +dp3 r1, t0_bx2, t2_bx2 ; r1 = normalMap dot dirLightDir +add r0, r1, c0 ; + 0.5 + +mul r1, v0, r0 ; scale the dot product by the dirlight's actual color +mul r0.rgb, r1, t1 + ; scale by the texture color + +mul r0.a, t1.a, v0.a diff --git a/materialsystem/stdshaders/Cable.vsh b/materialsystem/stdshaders/Cable.vsh new file mode 100644 index 0000000..857a2e3 --- /dev/null +++ b/materialsystem/stdshaders/Cable.vsh @@ -0,0 +1,117 @@ +vs.1.1 + +#include "macros.vsh" + +# DYNAMIC: "DOWATERFOG" "0..1" + +;------------------------------------------------------------------------------ +; The cable equation is: +; [L dot N] * C * T +; +; where: +; C = directional light color +; T = baseTexture +; N = particle normal (stored in the normal map) +; L = directional light direction +; +; $SHADER_SPECIFIC_CONST_0 = Directional light direction +;------------------------------------------------------------------------------ + + +;------------------------------------------------------------------------------ +; Transform position from object to projection space +;------------------------------------------------------------------------------ + +&AllocateRegister( \$projPos ); + +dp4 $projPos.x, $vPos, $cModelViewProj0 +dp4 $projPos.y, $vPos, $cModelViewProj1 +dp4 $projPos.z, $vPos, $cModelViewProj2 +dp4 $projPos.w, $vPos, $cModelViewProj3 + +mov oPos, $projPos + + +;------------------------------------------------------------------------------ +; Fog +;------------------------------------------------------------------------------ + +alloc $worldPos +if( $DOWATERFOG == 1 ) +{ + ; Get the worldpos z component only since that's all we need for height fog + dp4 $worldPos.z, $vPos, $cModel2 +} +&CalcFog( $worldPos, $projPos ); +free $worldPos + +&FreeRegister( \$projPos ); + +;------------------------------------------------------------------------------ +; Setup the tangent space +;------------------------------------------------------------------------------ + +&AllocateRegister( \$tmp1 ); +&AllocateRegister( \$tmp2 ); +&AllocateRegister( \$tmp3 ); +&AllocateRegister( \$r ); + +; Get S crossed with T (call it R) +mov $tmp1, $vTangentS +mov $tmp2, $vTangentT + +mul $tmp3, $vTangentS.yzxw, $tmp2.zxyw +mad $r, -$vTangentS.zxyw, $tmp2.yzxw, $tmp3 + +&FreeRegister( \$tmp2 ); +&FreeRegister( \$tmp3 ); + +&AllocateRegister( \$s ); + +; Normalize S (into $s) +dp3 $s.w, $vTangentS, $vTangentS +rsq $s.w, $s.w +mul $s.xyz, $vTangentS, $s.w + +; Normalize R (into $r) +dp3 $r.w, $r, $r +rsq $r.w, $r.w +mul $r.xyz, $r, $r.w + +&AllocateRegister( \$t ); + +; Regenerate T (into $t) +mul $t, $r.yzxw, $tmp1.zxyw +mad $t, -$r.zxyw, $tmp1.yzxw, $t + +&FreeRegister( \$tmp1 ); + +;------------------------------------------------------------------------------ +; Transform the light direction (into oD1) +;------------------------------------------------------------------------------ + +&AllocateRegister( \$lightDirection ); + +dp3 $lightDirection.x, $s, $SHADER_SPECIFIC_CONST_0 +dp3 $lightDirection.y, $t, $SHADER_SPECIFIC_CONST_0 +dp3 $lightDirection.z, $r, $SHADER_SPECIFIC_CONST_0 + +&FreeRegister( \$r ); +&FreeRegister( \$s ); +&FreeRegister( \$t ); + +; Scale into 0-1 range (we're assuming light direction was normalized prior to here) +add oT2, $lightDirection, $cHalf ; + 0.5 +&FreeRegister( \$lightDirection ); + +;------------------------------------------------------------------------------ +; Copy texcoords for the normal map and base texture +;------------------------------------------------------------------------------ + +mov oT0, $vTexCoord0 +mov oT1, $vTexCoord1 + +; Pass the dirlight color through +mov oD0.xyzw, $vColor + + diff --git a/materialsystem/stdshaders/DebugDrawDepth_ps2x.fxc b/materialsystem/stdshaders/DebugDrawDepth_ps2x.fxc new file mode 100644 index 0000000..c90ef08 --- /dev/null +++ b/materialsystem/stdshaders/DebugDrawDepth_ps2x.fxc @@ -0,0 +1,23 @@ +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX] + +#define HDRTYPE HDR_TYPE_NONE +#include "common_ps_fxc.h" + +struct PS_INPUT +{ + float4 projPos : POSITION; + float3 zValue : TEXCOORD0; +}; + +const float3 g_ZFilter : register( c1 ); +const float3 g_ModulationColor : register( c2 ); + +float4 main( PS_INPUT i ) : COLOR +{ + float z = dot( i.zValue, g_ZFilter ); + z = saturate( z ); + float4 color = float4( z, z, z, 1.0f ); + color.rgb *= g_ModulationColor; + return FinalOutput( color, 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE ); +} diff --git a/materialsystem/stdshaders/DebugDrawDepth_vs20.fxc b/materialsystem/stdshaders/DebugDrawDepth_vs20.fxc new file mode 100644 index 0000000..647acde --- /dev/null +++ b/materialsystem/stdshaders/DebugDrawDepth_vs20.fxc @@ -0,0 +1,38 @@ +// DYNAMIC: "COMPRESSED_VERTS" "0..1" +// DYNAMIC: "SKINNING" "0..1" + +#include "common_vs_fxc.h" + +static const bool g_bSkinning = SKINNING ? true : false; + +const float2 cDepthFactor : register( SHADER_SPECIFIC_CONST_0 ); + +struct VS_INPUT +{ + float4 vPos : POSITION; + float4 vBoneWeights : BLENDWEIGHT; + float4 vBoneIndices : BLENDINDICES; +}; + +struct VS_OUTPUT +{ + float4 projPos : POSITION; + float2 zValue : TEXCOORD0; +}; + +VS_OUTPUT main( const VS_INPUT v ) +{ + VS_OUTPUT o = ( VS_OUTPUT )0; + + float3 worldPos; + SkinPosition( g_bSkinning, v.vPos, v.vBoneWeights, v.vBoneIndices, worldPos ); + float4 projPos = mul( float4( worldPos, 1 ), cViewProj ); + o.projPos = projPos; + o.zValue.x = (o.projPos.z - cDepthFactor.y) / cDepthFactor.x; + o.zValue.y = (o.projPos.w - cDepthFactor.y) / cDepthFactor.x; + return o; +} + + + + diff --git a/materialsystem/stdshaders/DebugDrawEnvmapMask.cpp b/materialsystem/stdshaders/DebugDrawEnvmapMask.cpp new file mode 100644 index 0000000..9f3c34b --- /dev/null +++ b/materialsystem/stdshaders/DebugDrawEnvmapMask.cpp @@ -0,0 +1,94 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//===========================================================================// + +#include "BaseVSShader.h" +#include "debugdrawenvmapmask_vs20.inc" +#include "debugdrawenvmapmask_ps20.inc" +#include "debugdrawenvmapmask_ps20b.inc" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +BEGIN_VS_SHADER_FLAGS( DebugDrawEnvmapMask, "Help for DebugDrawEnvmapMask", SHADER_NOT_EDITABLE ) + + BEGIN_SHADER_PARAMS + SHADER_PARAM( SHOWALPHA, SHADER_PARAM_TYPE_INTEGER, "0", "" ) + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + SET_FLAGS2( MATERIAL_VAR2_SUPPORTS_HW_SKINNING ); + } + + SHADER_INIT + { + } + + SHADER_FALLBACK + { + if( g_pHardwareConfig->GetDXSupportLevel() < 90 ) + { +// Assert( 0 ); + return "Wireframe"; + } + return 0; + } + + SHADER_DRAW + { + SHADOW_STATE + { + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + + // Set stream format (note that this shader supports compression) + unsigned int flags = VERTEX_POSITION | VERTEX_FORMAT_COMPRESSED; + int nTexCoordCount = 1; + int userDataSize = 0; + pShaderShadow->VertexShaderVertexFormat( flags, nTexCoordCount, NULL, userDataSize ); + + DECLARE_STATIC_VERTEX_SHADER( debugdrawenvmapmask_vs20 ); + SET_STATIC_VERTEX_SHADER( debugdrawenvmapmask_vs20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_STATIC_PIXEL_SHADER( debugdrawenvmapmask_ps20b ); + SET_STATIC_PIXEL_SHADER( debugdrawenvmapmask_ps20b ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( debugdrawenvmapmask_ps20 ); + SET_STATIC_PIXEL_SHADER( debugdrawenvmapmask_ps20 ); + } + } + DYNAMIC_STATE + { + int numBones = s_pShaderAPI->GetCurrentNumBones(); + + DECLARE_DYNAMIC_VERTEX_SHADER( debugdrawenvmapmask_vs20 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, numBones > 0 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression ); + SET_DYNAMIC_VERTEX_SHADER( debugdrawenvmapmask_vs20 ); + + bool bShowAlpha = params[SHOWALPHA]->GetIntValue() ? true : false; + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_DYNAMIC_PIXEL_SHADER( debugdrawenvmapmask_ps20b ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( SHOWALPHA, bShowAlpha ); + SET_DYNAMIC_PIXEL_SHADER( debugdrawenvmapmask_ps20b ); + } + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( debugdrawenvmapmask_ps20 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( SHOWALPHA, bShowAlpha ); + SET_DYNAMIC_PIXEL_SHADER( debugdrawenvmapmask_ps20 ); + } + + BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME ); + SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, BASETEXTURETRANSFORM ); + } + Draw(); + } +END_SHADER diff --git a/materialsystem/stdshaders/DebugDrawEnvmapMask_ps2x.fxc b/materialsystem/stdshaders/DebugDrawEnvmapMask_ps2x.fxc new file mode 100644 index 0000000..f97589a --- /dev/null +++ b/materialsystem/stdshaders/DebugDrawEnvmapMask_ps2x.fxc @@ -0,0 +1,26 @@ +// DYNAMIC: "SHOWALPHA" "0..1" + +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX] + +#define HDRTYPE HDR_TYPE_NONE +#include "common_ps_fxc.h" + +sampler BaseTextureSampler : register( s0 ); + +struct PS_INPUT +{ + float4 projPos : POSITION; + float2 baseTexCoord : TEXCOORD0; +}; + +float4 main( PS_INPUT i ) : COLOR +{ + float4 baseColor = tex2D( BaseTextureSampler, i.baseTexCoord ); +#if SHOWALPHA + float4 result = float4( baseColor.a, baseColor.a, baseColor.a, 1.0f ); +#else + float4 result = float4( baseColor.rgb, 1.0f ); +#endif + return FinalOutput( result, 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE ); +} diff --git a/materialsystem/stdshaders/DebugDrawEnvmapMask_vs20.fxc b/materialsystem/stdshaders/DebugDrawEnvmapMask_vs20.fxc new file mode 100644 index 0000000..33aa5da --- /dev/null +++ b/materialsystem/stdshaders/DebugDrawEnvmapMask_vs20.fxc @@ -0,0 +1,39 @@ +// DYNAMIC: "COMPRESSED_VERTS" "0..1" +// DYNAMIC: "SKINNING" "0..1" + +#include "common_vs_fxc.h" + +static const bool g_bSkinning = SKINNING ? true : false; + +const float4 cBaseTexCoordTransform[2] : register( SHADER_SPECIFIC_CONST_0 ); + +struct VS_INPUT +{ + float4 vPos : POSITION; + float4 vBoneWeights : BLENDWEIGHT; + float4 vBoneIndices : BLENDINDICES; + float4 vTexCoord0 : TEXCOORD0; +}; + +struct VS_OUTPUT +{ + float4 projPos : POSITION; + float2 baseTexCoord : TEXCOORD0; +}; + +VS_OUTPUT main( const VS_INPUT v ) +{ + VS_OUTPUT o = ( VS_OUTPUT )0; + + float3 worldPos; + SkinPosition( g_bSkinning, v.vPos, v.vBoneWeights, v.vBoneIndices, worldPos ); + float4 projPos = mul( float4( worldPos, 1 ), cViewProj ); + o.projPos = projPos; + o.baseTexCoord.x = dot( v.vTexCoord0, cBaseTexCoordTransform[0] ); + o.baseTexCoord.y = dot( v.vTexCoord0, cBaseTexCoordTransform[1] ); + return o; +} + + + + diff --git a/materialsystem/stdshaders/DebugTextureView.cpp b/materialsystem/stdshaders/DebugTextureView.cpp new file mode 100644 index 0000000..70d73d3 --- /dev/null +++ b/materialsystem/stdshaders/DebugTextureView.cpp @@ -0,0 +1,104 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// + +#include "BaseVSShader.h" +#include "shaderlib/cshader.h" + +#include "debugtextureview_vs20.inc" +#include "debugtextureview_ps20.inc" +#include "debugtextureview_ps20b.inc" + +DEFINE_FALLBACK_SHADER( DebugTextureView, DebugTextureView_dx9 ) +BEGIN_VS_SHADER( DebugTextureView_dx9, "Help for DebugTextureView" ) + BEGIN_SHADER_PARAMS + SHADER_PARAM( SHOWALPHA, SHADER_PARAM_TYPE_BOOL, "0", "" ) + END_SHADER_PARAMS + + SHADER_INIT + { + if ( params[BASETEXTURE]->IsDefined() ) + { + LoadTexture( BASETEXTURE ); + } + } + + SHADER_FALLBACK + { + if ( g_pHardwareConfig->GetDXSupportLevel() < 90 ) + { + return "UnlitGeneric"; + } + return 0; + } + + SHADER_DRAW + { + SHADOW_STATE + { + pShaderShadow->EnableDepthWrites( false ); + pShaderShadow->EnableAlphaTest( true ); + + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + + // Set stream format (note that this shader supports compression) + unsigned int flags = VERTEX_POSITION | VERTEX_FORMAT_COMPRESSED; + int nTexCoordCount = 1; + int userDataSize = 0; + pShaderShadow->VertexShaderVertexFormat( flags, nTexCoordCount, NULL, userDataSize ); + + DECLARE_STATIC_VERTEX_SHADER( debugtextureview_vs20 ); + SET_STATIC_VERTEX_SHADER( debugtextureview_vs20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_STATIC_PIXEL_SHADER( debugtextureview_ps20b ); + SET_STATIC_PIXEL_SHADER_COMBO( SHOWALPHA, params[SHOWALPHA]->GetIntValue() != 0 ); + SET_STATIC_PIXEL_SHADER( debugtextureview_ps20b ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( debugtextureview_ps20 ); + SET_STATIC_PIXEL_SHADER_COMBO( SHOWALPHA, params[SHOWALPHA]->GetIntValue() != 0 ); + SET_STATIC_PIXEL_SHADER( debugtextureview_ps20 ); + } + } + + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME ); + //pShaderAPI->BindStandardTexture( SHADER_SAMPLER1, TEXTURE_LIGHTMAP ); + + ITexture *pTexture = params[BASETEXTURE]->GetTextureValue(); + + float cPsConst0[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; + if ( ( pTexture->GetImageFormat() == IMAGE_FORMAT_RGBA16161616F ) || + ( pTexture->GetImageFormat() == IMAGE_FORMAT_RGBA16161616 ) || + ( pTexture->GetImageFormat() == IMAGE_FORMAT_RGB323232F ) || + ( pTexture->GetImageFormat() == IMAGE_FORMAT_RGBA32323232F ) ) + { + if ( pTexture->IsCubeMap() ) + cPsConst0[0] = 1.0f; + else + cPsConst0[1] = 1.0f; + } + pShaderAPI->SetPixelShaderConstant( 0, cPsConst0 ); + + DECLARE_DYNAMIC_VERTEX_SHADER( debugtextureview_vs20 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression ); + SET_DYNAMIC_VERTEX_SHADER( debugtextureview_vs20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_DYNAMIC_PIXEL_SHADER( debugtextureview_ps20b ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( ISCUBEMAP, pTexture->IsCubeMap() ); + SET_DYNAMIC_PIXEL_SHADER( debugtextureview_ps20b ); + } + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( debugtextureview_ps20 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( ISCUBEMAP, pTexture->IsCubeMap() ); + SET_DYNAMIC_PIXEL_SHADER( debugtextureview_ps20 ); + } + } + Draw(); + } +END_SHADER diff --git a/materialsystem/stdshaders/DebugTextureView_ps2x.fxc b/materialsystem/stdshaders/DebugTextureView_ps2x.fxc new file mode 100644 index 0000000..4b22d55 --- /dev/null +++ b/materialsystem/stdshaders/DebugTextureView_ps2x.fxc @@ -0,0 +1,81 @@ +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX] +// STATIC: "SHOWALPHA" "0..1" +// DYNAMIC: "ISCUBEMAP" "0..1" + +#define HDRTYPE HDR_TYPE_NONE +#include "common_ps_fxc.h" + +sampler g_tSampler : register( s0 ); + +struct PS_INPUT +{ + float2 texCoord : TEXCOORD0; +}; + +const float3 g_vConst0 : register( c0 ); +#define g_flIsHdrCube g_vConst0.x +#define g_flIsHdr2D g_vConst0.y + +float4 main( PS_INPUT i ) : COLOR +{ + float4 sample = tex2D( g_tSampler, i.texCoord ); + float4 result = { 0.0f, 0.0f, 0.0f, 1.0f }; + + result.rgb = sample.rgb; + #if SHOWALPHA + result.rgb = sample.a; + #endif + + if ( g_flIsHdr2D ) + result.rgb *= MAX_HDR_OVERBRIGHT; + + #if ISCUBEMAP + bool bNoDataForThisPixel = false; + float3 vec = float3( 0, 0, 0 ); + float x = i.texCoord.x; + float y = i.texCoord.y; + float x2 = frac( ( i.texCoord.x ) * 3.0f ) * 2.0f - 1.0f; + float y2 = frac( ( i.texCoord.y ) * 4.0f ) * 2.0f - 1.0f; + if ( ( x >= 0.3333f ) && ( x <= 0.6666f ) ) //Center row + { + if ( y >= 0.75f ) + vec = float3( x2, 1.0, y2 ); + else if ( y >= 0.5f ) + vec = float3( x2, y2, -1.0 ); + else if ( y >= 0.25f ) + vec = float3( x2, -1.0, -y2 ); + else if ( y >= 0.0f ) + vec = float3( x2, -y2, 1.0 ); + } + else if ( ( y >= 0.25f ) && ( y <= 0.5f ) ) + { + if ( x <= 0.3333f ) + vec = float3( -1.0f, -x2, -y2 ); + else if (x >= 0.6666f) + vec = float3( 1.0f, x2, -y2 ); + else + bNoDataForThisPixel = true; + } + else + { + bNoDataForThisPixel = true; + } + + float4 cBase = texCUBE( g_tSampler, vec ); + #if SHOWALPHA + cBase.rgb = cBase.a; + #endif + + if ( g_flIsHdrCube ) + cBase.rgb *= ENV_MAP_SCALE; + + if ( bNoDataForThisPixel == true ) + cBase.rgb = float3( 0.9f, 0.4f, 0.15f ); + + result.rgb = cBase.rgb; + result.a = 1.0f; // - bNoDataForThisPixel; + #endif + + return FinalOutput( result, 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE ); +} diff --git a/materialsystem/stdshaders/DebugTextureView_vs20.fxc b/materialsystem/stdshaders/DebugTextureView_vs20.fxc new file mode 100644 index 0000000..48c3b7e --- /dev/null +++ b/materialsystem/stdshaders/DebugTextureView_vs20.fxc @@ -0,0 +1,23 @@ +// DYNAMIC: "COMPRESSED_VERTS" "0..1" + +#include "common_vs_fxc.h" + +struct VS_INPUT +{ + float4 vPos : POSITION; + float4 vTexCoord0 : TEXCOORD0; +}; + +struct VS_OUTPUT +{ + float4 vProjPos : POSITION; + float2 vUv0 : TEXCOORD0; +}; + +VS_OUTPUT main( const VS_INPUT i ) +{ + VS_OUTPUT o; + o.vProjPos.xyzw = mul( i.vPos.xyzw, cModelViewProj ); + o.vUv0.xy = i.vTexCoord0.xy; + return o; +} diff --git a/materialsystem/stdshaders/DecalBaseTimesLightmapAlphaBlendSelfIllum1_ps11.psh b/materialsystem/stdshaders/DecalBaseTimesLightmapAlphaBlendSelfIllum1_ps11.psh new file mode 100644 index 0000000..abd97c7 --- /dev/null +++ b/materialsystem/stdshaders/DecalBaseTimesLightmapAlphaBlendSelfIllum1_ps11.psh @@ -0,0 +1,9 @@ +ps.1.1 + +tex t0 ; base texture +tex t1 ; lightmap + +mul r0.rgb, t0, t1 ++ mov r0.a, t0.a + + diff --git a/materialsystem/stdshaders/DecalBaseTimesLightmapAlphaBlendSelfIllum2_ps11.psh b/materialsystem/stdshaders/DecalBaseTimesLightmapAlphaBlendSelfIllum2_ps11.psh new file mode 100644 index 0000000..28ef913 --- /dev/null +++ b/materialsystem/stdshaders/DecalBaseTimesLightmapAlphaBlendSelfIllum2_ps11.psh @@ -0,0 +1,5 @@ +ps.1.1 + +tex t0 ; selfillum + +mov r0, t0 diff --git a/materialsystem/stdshaders/DecalBaseTimesLightmapAlphaBlendSelfIllum_dx6.cpp b/materialsystem/stdshaders/DecalBaseTimesLightmapAlphaBlendSelfIllum_dx6.cpp new file mode 100644 index 0000000..d8ccd56 --- /dev/null +++ b/materialsystem/stdshaders/DecalBaseTimesLightmapAlphaBlendSelfIllum_dx6.cpp @@ -0,0 +1,83 @@ +//========= 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" + +DEFINE_FALLBACK_SHADER( DecalBaseTimesLightmapAlphaBlendSelfIllum, DecalBaseTimesLightmapAlphaBlendSelfIllum_DX6 ) + +BEGIN_SHADER( DecalBaseTimesLightmapAlphaBlendSelfIllum_DX6, + "Help for DecalBaseTimesLightmapAlphaBlendSelfIllum_DX6" ) + + BEGIN_SHADER_PARAMS + SHADER_PARAM_OVERRIDE( BASETEXTURE, SHADER_PARAM_TYPE_TEXTURE, "decals/decalporthole001b", "decal base texture", 0 ) + SHADER_PARAM( SELFILLUMTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "decals/decalporthole001b_mask", "self-illum texture" ) + SHADER_PARAM( SELFILLUMTEXTUREFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "self-illum texture frame" ) + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + SET_FLAGS( MATERIAL_VAR_NO_DEBUG_OVERRIDE ); + SET_FLAGS2( MATERIAL_VAR2_LIGHTING_LIGHTMAP ); + } + + SHADER_INIT + { + LoadTexture( BASETEXTURE ); + LoadTexture( SELFILLUMTEXTURE ); + } + + SHADER_DRAW + { + if( g_pHardwareConfig->GetSamplerCount() < 2 ) + { + ShaderWarning( "DecalBaseTimesLightmapAlphaBlendSelfIllum: not implemented for single-texturing hardware\n" ); + return; + } + + + SHADOW_STATE + { + pShaderShadow->EnableDepthWrites( false ); + pShaderShadow->EnablePolyOffset( SHADER_POLYOFFSET_DECAL ); + pShaderShadow->EnableBlending( true ); + pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA ); + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + pShaderShadow->OverbrightValue( SHADER_TEXTURE_STAGE1, OVERBRIGHT ); + pShaderShadow->DrawFlags( SHADER_DRAW_POSITION | + SHADER_DRAW_TEXCOORD1 | SHADER_DRAW_LIGHTMAP_TEXCOORD0 ); + FogToFogColor(); + } + DYNAMIC_STATE + { + pShaderAPI->BindStandardTexture( SHADER_SAMPLER0, TEXTURE_LIGHTMAP ); + BindTexture( SHADER_SAMPLER1, BASETEXTURE, FRAME ); + } + Draw(); + + SHADOW_STATE + { + SetInitialShadowState( ); + pShaderShadow->EnableDepthWrites( false ); + pShaderShadow->EnablePolyOffset( SHADER_POLYOFFSET_DECAL ); + pShaderShadow->EnableBlending( true ); + pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA ); + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->DrawFlags( SHADER_DRAW_POSITION | SHADER_DRAW_TEXCOORD0 ); + FogToBlack(); + } + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER0, SELFILLUMTEXTURE, SELFILLUMTEXTUREFRAME ); + } + Draw(); + } +END_SHADER diff --git a/materialsystem/stdshaders/DecalBaseTimesLightmapAlphaBlendSelfIllum_dx8.cpp b/materialsystem/stdshaders/DecalBaseTimesLightmapAlphaBlendSelfIllum_dx8.cpp new file mode 100644 index 0000000..42e5ef7 --- /dev/null +++ b/materialsystem/stdshaders/DecalBaseTimesLightmapAlphaBlendSelfIllum_dx8.cpp @@ -0,0 +1,142 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//===========================================================================// + +#include "BaseVSShader.h" +#include "lightmappedgeneric_vs11.inc" +#include "lightmappedgeneric_decal.inc" +#include "mathlib/bumpvects.h" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +DEFINE_FALLBACK_SHADER( DecalBaseTimesLightmapAlphaBlendSelfIllum, DecalBaseTimesLightmapAlphaBlendSelfIllum_DX8 ) + +BEGIN_VS_SHADER( DecalBaseTimesLightmapAlphaBlendSelfIllum_DX8, "" ) + + BEGIN_SHADER_PARAMS + SHADER_PARAM_OVERRIDE( BASETEXTURE, SHADER_PARAM_TYPE_TEXTURE, "decals/decalporthole001b", "decal base texture", 0 ) + SHADER_PARAM( SELFILLUMTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "decals/decalporthole001b_mask", "self-illum texture" ) + SHADER_PARAM( SELFILLUMTEXTUREFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "self-illum texture frame" ) + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + // FLASHLIGHTFIXME + params[FLASHLIGHTTEXTURE]->SetStringValue( "effects/flashlight001" ); + SET_FLAGS( MATERIAL_VAR_NO_DEBUG_OVERRIDE ); + SET_FLAGS( MATERIAL_VAR_TRANSLUCENT ); + SET_FLAGS2( MATERIAL_VAR2_LIGHTING_LIGHTMAP ); + } + + SHADER_FALLBACK + { + if ( IsPC() && ( g_pHardwareConfig->GetDXSupportLevel() < 80 ) ) + { + return "DecalBaseTimesLightmapAlphaBlendSelfIllum_DX6"; + } + return 0; + } + + SHADER_INIT + { + LoadTexture( FLASHLIGHTTEXTURE ); + LoadTexture( BASETEXTURE ); + LoadTexture( SELFILLUMTEXTURE ); + } + + void DrawDecal( IMaterialVar **params, IShaderDynamicAPI *pShaderAPI, IShaderShadow *pShaderShadow ) + { + if( IsSnapshotting() ) + { + pShaderShadow->EnableDepthWrites( false ); + pShaderShadow->EnablePolyOffset( SHADER_POLYOFFSET_DECAL ); + pShaderShadow->EnableBlending( true ); + pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA ); + + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER2, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER3, true ); + + int pTexCoords[3] = { 2, 2, 1 }; + pShaderShadow->VertexShaderVertexFormat( VERTEX_POSITION | VERTEX_COLOR, 3, pTexCoords, 0 ); + + lightmappedgeneric_decal_Static_Index vshIndex; + pShaderShadow->SetVertexShader( "LightmappedGeneric_Decal", vshIndex.GetIndex() ); + pShaderShadow->SetPixelShader( "LightmappedGeneric_Decal" ); + FogToFogColor(); + } + else + { + BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME ); + + // Load the z^2 components of the lightmap coordinate axes only + // This is (N dot basis)^2 + Vector vecZValues( g_localBumpBasis[0].z, g_localBumpBasis[1].z, g_localBumpBasis[2].z ); + vecZValues *= vecZValues; + + Vector4D basis[3]; + basis[0].Init( vecZValues.x, vecZValues.x, vecZValues.x, 0.0f ); + basis[1].Init( vecZValues.y, vecZValues.y, vecZValues.y, 0.0f ); + basis[2].Init( vecZValues.z, vecZValues.z, vecZValues.z, 0.0f ); + pShaderAPI->SetPixelShaderConstant( 0, (float*)basis, 3 ); + + pShaderAPI->BindStandardTexture( SHADER_SAMPLER1, TEXTURE_LIGHTMAP_BUMPED ); + SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, BASETEXTURETRANSFORM ); + SetModulationPixelShaderDynamicState( 3 ); + + lightmappedgeneric_decal_Dynamic_Index vshIndex; + vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() ); + } + Draw(); + + if( IsSnapshotting() ) + { + SetInitialShadowState( ); + pShaderShadow->EnableDepthWrites( false ); + pShaderShadow->EnablePolyOffset( SHADER_POLYOFFSET_DECAL ); + pShaderShadow->EnableBlending( true ); + pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA ); + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + + pShaderShadow->VertexShaderVertexFormat( VERTEX_POSITION, 1, 0, 0 ); + lightmappedgeneric_vs11_Static_Index vshIndex; + vshIndex.SetDETAIL( false ); + vshIndex.SetENVMAP( false ); + vshIndex.SetENVMAPCAMERASPACE( false ); + vshIndex.SetENVMAPSPHERE( false ); + vshIndex.SetVERTEXCOLOR( false ); + pShaderShadow->SetVertexShader( "LightmappedGeneric_vs11", vshIndex.GetIndex() ); + pShaderShadow->SetPixelShader( "DecalBaseTimesLightmapAlphaBlendSelfIllum2_ps11" ); + + FogToFogColor(); + } + else + { + BindTexture( SHADER_SAMPLER0, SELFILLUMTEXTURE, SELFILLUMTEXTUREFRAME ); + + lightmappedgeneric_vs11_Dynamic_Index vshIndex; + vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() ); + } + Draw(); + } + + SHADER_DRAW + { + if( UsingFlashlight( params ) ) + { + DrawFlashlight_dx80( params, pShaderAPI, pShaderShadow, false, -1, -1, -1, + FLASHLIGHTTEXTURE, FLASHLIGHTTEXTUREFRAME, true, false, 0, -1, -1 ); + } + else + { + DrawDecal( params, pShaderAPI, pShaderShadow ); + } + } + +END_SHADER diff --git a/materialsystem/stdshaders/DecalBaseTimesLightmapAlphaBlendSelfIllum_dx9.cpp b/materialsystem/stdshaders/DecalBaseTimesLightmapAlphaBlendSelfIllum_dx9.cpp new file mode 100644 index 0000000..2adb42d --- /dev/null +++ b/materialsystem/stdshaders/DecalBaseTimesLightmapAlphaBlendSelfIllum_dx9.cpp @@ -0,0 +1,270 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//===========================================================================// + +#include "BaseVSShader.h" +#include "mathlib/bumpvects.h" +#include "cpp_shader_constant_register_map.h" + +#include "lightmappedgeneric_vs20.inc" +#include "lightmappedgeneric_decal_vs20.inc" +#include "lightmappedgeneric_decal_ps20.inc" +#include "lightmappedgeneric_decal_ps20b.inc" +#include "decalbasetimeslightmapalphablendselfillum2_ps20.inc" +#include "decalbasetimeslightmapalphablendselfillum2_ps20b.inc" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +DEFINE_FALLBACK_SHADER( DecalBaseTimesLightmapAlphaBlendSelfIllum, DecalBaseTimesLightmapAlphaBlendSelfIllum_DX9 ) + +extern ConVar r_flashlight_version2; + +BEGIN_VS_SHADER( DecalBaseTimesLightmapAlphaBlendSelfIllum_DX9, "" ) + + BEGIN_SHADER_PARAMS + SHADER_PARAM_OVERRIDE( BASETEXTURE, SHADER_PARAM_TYPE_TEXTURE, "decals/decalporthole001b", "decal base texture", 0 ) + SHADER_PARAM( SELFILLUMTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "decals/decalporthole001b_mask", "self-illum texture" ) + SHADER_PARAM( SELFILLUMTEXTUREFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "self-illum texture frame" ) + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + if ( g_pHardwareConfig->SupportsBorderColor() ) + { + params[FLASHLIGHTTEXTURE]->SetStringValue( "effects/flashlight_border" ); + } + else + { + params[FLASHLIGHTTEXTURE]->SetStringValue( "effects/flashlight001" ); + } + + SET_FLAGS( MATERIAL_VAR_NO_DEBUG_OVERRIDE ); + SET_FLAGS( MATERIAL_VAR_TRANSLUCENT ); + SET_FLAGS2( MATERIAL_VAR2_LIGHTING_LIGHTMAP ); + } + + SHADER_FALLBACK + { + if ( g_pHardwareConfig->GetDXSupportLevel() < 90 ) + { + return "DecalBaseTimesLightmapAlphaBlendSelfIllum_DX8"; + } + return 0; + } + + SHADER_INIT + { + LoadTexture( FLASHLIGHTTEXTURE, TEXTUREFLAGS_SRGB ); + LoadTexture( BASETEXTURE, TEXTUREFLAGS_SRGB ); + LoadTexture( SELFILLUMTEXTURE ); + } + + void DrawDecal( IMaterialVar **params, IShaderDynamicAPI *pShaderAPI, IShaderShadow *pShaderShadow ) + { + if( IsSnapshotting() ) + { + pShaderShadow->EnableDepthWrites( false ); + pShaderShadow->EnablePolyOffset( SHADER_POLYOFFSET_DECAL ); + pShaderShadow->EnableBlending( true ); + pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA ); + pShaderShadow->EnableSRGBWrite( true ); + + // Base Texture + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, true ); + + // Lightmaps + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER1, g_pHardwareConfig->GetHDRType() == HDR_TYPE_NONE ); + pShaderShadow->EnableTexture( SHADER_SAMPLER2, true ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER2, g_pHardwareConfig->GetHDRType() == HDR_TYPE_NONE ); + pShaderShadow->EnableTexture( SHADER_SAMPLER3, true ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER3, g_pHardwareConfig->GetHDRType() == HDR_TYPE_NONE ); + + int pTexCoords[3] = { 2, 2, 1 }; + pShaderShadow->VertexShaderVertexFormat( VERTEX_POSITION | VERTEX_COLOR, 3, pTexCoords, 0 ); + + DECLARE_STATIC_VERTEX_SHADER( lightmappedgeneric_decal_vs20 ); + SET_STATIC_VERTEX_SHADER( lightmappedgeneric_decal_vs20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_STATIC_PIXEL_SHADER( lightmappedgeneric_decal_ps20b ); + SET_STATIC_PIXEL_SHADER( lightmappedgeneric_decal_ps20b ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( lightmappedgeneric_decal_ps20 ); + SET_STATIC_PIXEL_SHADER( lightmappedgeneric_decal_ps20 ); + } + + FogToFogColor(); + } + else + { + BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME ); + + // Load the z^2 components of the lightmap coordinate axes only + // This is (N dot basis)^2 + Vector vecZValues( g_localBumpBasis[0].z, g_localBumpBasis[1].z, g_localBumpBasis[2].z ); + vecZValues *= vecZValues; + + Vector4D basis[3]; + basis[0].Init( vecZValues.x, vecZValues.x, vecZValues.x, 0.0f ); + basis[1].Init( vecZValues.y, vecZValues.y, vecZValues.y, 0.0f ); + basis[2].Init( vecZValues.z, vecZValues.z, vecZValues.z, 0.0f ); + pShaderAPI->SetPixelShaderConstant( 0, (float*)basis, 3 ); + + pShaderAPI->BindStandardTexture( SHADER_SAMPLER1, TEXTURE_LIGHTMAP_BUMPED ); + SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, BASETEXTURETRANSFORM ); + SetModulationPixelShaderDynamicState( 3 ); + + DECLARE_DYNAMIC_VERTEX_SHADER( lightmappedgeneric_decal_vs20 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( DOWATERFOG, pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + SET_DYNAMIC_VERTEX_SHADER( lightmappedgeneric_decal_vs20 ); + + pShaderAPI->SetPixelShaderFogParams( PSREG_FOG_PARAMS ); + + float vEyePos_SpecExponent[4]; + pShaderAPI->GetWorldSpaceCameraPosition( vEyePos_SpecExponent ); + vEyePos_SpecExponent[3] = 0.0f; + pShaderAPI->SetPixelShaderConstant( PSREG_EYEPOS_SPEC_EXPONENT, vEyePos_SpecExponent, 1 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_DYNAMIC_PIXEL_SHADER( lightmappedgeneric_decal_ps20b ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + SET_DYNAMIC_PIXEL_SHADER( lightmappedgeneric_decal_ps20b ); + } + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( lightmappedgeneric_decal_ps20 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + SET_DYNAMIC_PIXEL_SHADER( lightmappedgeneric_decal_ps20 ); + } + } + Draw(); + + if( IsSnapshotting() ) + { + SetInitialShadowState( ); + pShaderShadow->EnableDepthWrites( false ); + pShaderShadow->EnablePolyOffset( SHADER_POLYOFFSET_DECAL ); + pShaderShadow->EnableBlending( true ); + pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA ); + + // Base texture + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, true ); + + pShaderShadow->EnableSRGBWrite( true ); + + pShaderShadow->VertexShaderVertexFormat( VERTEX_POSITION, 1, 0, 0 ); + + DECLARE_STATIC_VERTEX_SHADER( lightmappedgeneric_vs20 ); + SET_STATIC_VERTEX_SHADER_COMBO( ENVMAP_MASK, false ); + SET_STATIC_VERTEX_SHADER_COMBO( TANGENTSPACE, false ); + SET_STATIC_VERTEX_SHADER_COMBO( BUMPMAP, false ); + SET_STATIC_VERTEX_SHADER_COMBO( DIFFUSEBUMPMAP, false ); + SET_STATIC_VERTEX_SHADER_COMBO( VERTEXCOLOR, false ); + SET_STATIC_VERTEX_SHADER_COMBO( VERTEXALPHATEXBLENDFACTOR, false ); + SET_STATIC_VERTEX_SHADER_COMBO( RELIEF_MAPPING, false ); + SET_STATIC_VERTEX_SHADER_COMBO( SEAMLESS, false ); + SET_STATIC_VERTEX_SHADER_COMBO( BUMPMASK, false ); +#ifdef _X360 + SET_STATIC_VERTEX_SHADER_COMBO( FLASHLIGHT, 0 ); +#endif + SET_STATIC_VERTEX_SHADER( lightmappedgeneric_vs20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_STATIC_PIXEL_SHADER( decalbasetimeslightmapalphablendselfillum2_ps20b ); + SET_STATIC_PIXEL_SHADER( decalbasetimeslightmapalphablendselfillum2_ps20b ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( decalbasetimeslightmapalphablendselfillum2_ps20 ); + SET_STATIC_PIXEL_SHADER( decalbasetimeslightmapalphablendselfillum2_ps20 ); + } + + FogToFogColor(); + } + else + { + BindTexture( SHADER_SAMPLER0, SELFILLUMTEXTURE, SELFILLUMTEXTUREFRAME ); + + DECLARE_DYNAMIC_VERTEX_SHADER( lightmappedgeneric_vs20 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( FASTPATH, false ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( DOWATERFOG, pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( LIGHTING_PREVIEW, false ); + SET_DYNAMIC_VERTEX_SHADER( lightmappedgeneric_vs20 ); + + pShaderAPI->SetPixelShaderFogParams( PSREG_FOG_PARAMS ); + + float vEyePos_SpecExponent[4]; + pShaderAPI->GetWorldSpaceCameraPosition( vEyePos_SpecExponent ); + vEyePos_SpecExponent[3] = 0.0f; + pShaderAPI->SetPixelShaderConstant( PSREG_EYEPOS_SPEC_EXPONENT, vEyePos_SpecExponent, 1 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_DYNAMIC_PIXEL_SHADER( decalbasetimeslightmapalphablendselfillum2_ps20b ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + SET_DYNAMIC_PIXEL_SHADER( decalbasetimeslightmapalphablendselfillum2_ps20b ); + } + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( decalbasetimeslightmapalphablendselfillum2_ps20 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + SET_DYNAMIC_PIXEL_SHADER( decalbasetimeslightmapalphablendselfillum2_ps20 ); + } + } + Draw(); + } + + void DrawPass( IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow, bool bUsingFlashlight ) + { + if( bUsingFlashlight ) + { + DrawFlashlight_dx90_Vars_t flashlightVars; + flashlightVars.m_bBump = false; + flashlightVars.m_nBumpmapVar = -1; + flashlightVars.m_nBumpmapFrame = -1; + flashlightVars.m_nBumpTransform = -1; + flashlightVars.m_nFlashlightTextureVar = FLASHLIGHTTEXTURE; + flashlightVars.m_nFlashlightTextureFrameVar = FLASHLIGHTTEXTUREFRAME; + flashlightVars.m_bLightmappedGeneric = true; + flashlightVars.m_bWorldVertexTransition = false; + // int nWorldVertexTransitionPassID = 0 + flashlightVars.m_nBaseTexture2Var = -1; + flashlightVars.m_nBaseTexture2FrameVar = -1; + flashlightVars.m_bTeeth = false; + flashlightVars.m_nTeethForwardVar = 0; + flashlightVars.m_nTeethIllumFactorVar = 0; + + DrawFlashlight_dx90( params, pShaderAPI, pShaderShadow, flashlightVars ); + } + else + { + DrawDecal( params, pShaderAPI, pShaderShadow ); + } + } + + SHADER_DRAW + { + bool bUsingFlashlight = UsingFlashlight( params ); + if ( bUsingFlashlight && ( IsX360() || r_flashlight_version2.GetInt() ) ) + { + DrawPass( params, pShaderAPI, pShaderShadow, false ); + if ( pShaderShadow ) + { + SetInitialShadowState( ); + } + } + DrawPass( params, pShaderAPI, pShaderShadow, bUsingFlashlight ); + } + +END_SHADER diff --git a/materialsystem/stdshaders/DecalModulate_dx9.cpp b/materialsystem/stdshaders/DecalModulate_dx9.cpp new file mode 100644 index 0000000..ecb1c79 --- /dev/null +++ b/materialsystem/stdshaders/DecalModulate_dx9.cpp @@ -0,0 +1,232 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $Header: $ +// $NoKeywords: $ +//===========================================================================// + +#include "BaseVSShader.h" +#include "cpp_shader_constant_register_map.h" + +#include "VertexLit_and_unlit_Generic_vs20.inc" +#include "decalmodulate_ps20.inc" +#include "decalmodulate_ps20b.inc" + +#ifndef _X360 +#include "vertexlit_and_unlit_generic_vs30.inc" +#include "decalmodulate_ps30.inc" +#endif + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +DEFINE_FALLBACK_SHADER( DecalModulate, DecalModulate_DX9 ) + +extern ConVar r_flashlight_version2; + +BEGIN_VS_SHADER( DecalModulate_dx9, + "Help for DecalModulate_dx9" ) + + BEGIN_SHADER_PARAMS + END_SHADER_PARAMS + + SHADER_FALLBACK + { + if (g_pHardwareConfig->GetDXSupportLevel() < 90) + return "DecalModulate_DX6"; + return 0; + } + + SHADER_INIT_PARAMS() + { + SET_FLAGS( MATERIAL_VAR_NO_DEBUG_OVERRIDE ); + +#ifndef _X360 + if ( g_pHardwareConfig->HasFastVertexTextures() ) + { + // The vertex shader uses the vertex id stream + SET_FLAGS2( MATERIAL_VAR2_USES_VERTEXID ); + SET_FLAGS2( MATERIAL_VAR2_SUPPORTS_HW_SKINNING ); + } +#endif + } + + SHADER_INIT + { + LoadTexture( BASETEXTURE ); + } + + SHADER_DRAW + { + SHADOW_STATE + { + pShaderShadow->EnableAlphaTest( true ); + pShaderShadow->AlphaFunc( SHADER_ALPHAFUNC_GREATER, 0.0f ); + pShaderShadow->EnableDepthWrites( false ); + pShaderShadow->EnablePolyOffset( SHADER_POLYOFFSET_DECAL ); + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + + // Be sure not to write to dest alpha + pShaderShadow->EnableAlphaWrites( false ); + + // SRGB conversions hose the blend on some hardware, so keep we everything in gamma space + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, false ); + pShaderShadow->EnableSRGBWrite( false ); + + pShaderShadow->EnableBlending( true ); + pShaderShadow->BlendFunc( SHADER_BLEND_DST_COLOR, SHADER_BLEND_SRC_COLOR ); + pShaderShadow->DisableFogGammaCorrection( true ); //fog should stay exactly middle grey + FogToGrey(); + +#ifndef _X360 + if ( !g_pHardwareConfig->HasFastVertexTextures() ) +#endif + { + bool bUseStaticControlFlow = g_pHardwareConfig->SupportsStaticControlFlow(); + + DECLARE_STATIC_VERTEX_SHADER( vertexlit_and_unlit_generic_vs20 ); + SET_STATIC_VERTEX_SHADER_COMBO( VERTEXCOLOR, false ); + SET_STATIC_VERTEX_SHADER_COMBO( CUBEMAP, false ); + SET_STATIC_VERTEX_SHADER_COMBO( HALFLAMBERT, false ); + SET_STATIC_VERTEX_SHADER_COMBO( FLASHLIGHT, false ); + SET_STATIC_VERTEX_SHADER_COMBO( SEAMLESS_BASE, false ); + SET_STATIC_VERTEX_SHADER_COMBO( SEAMLESS_DETAIL, false ); + SET_STATIC_VERTEX_SHADER_COMBO( SEPARATE_DETAIL_UVS, false ); + SET_STATIC_VERTEX_SHADER_COMBO( USE_STATIC_CONTROL_FLOW, bUseStaticControlFlow ); + SET_STATIC_VERTEX_SHADER_COMBO( DONT_GAMMA_CONVERT_VERTEX_COLOR, 0 ); + SET_STATIC_VERTEX_SHADER( vertexlit_and_unlit_generic_vs20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_STATIC_PIXEL_SHADER( decalmodulate_ps20b ); + SET_STATIC_PIXEL_SHADER( decalmodulate_ps20b ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( decalmodulate_ps20 ); + SET_STATIC_PIXEL_SHADER( decalmodulate_ps20 ); + } + } +#ifndef _X360 + else + { + DECLARE_STATIC_VERTEX_SHADER( vertexlit_and_unlit_generic_vs30 ); + SET_STATIC_VERTEX_SHADER_COMBO( VERTEXCOLOR, false ); + SET_STATIC_VERTEX_SHADER_COMBO( CUBEMAP, false ); + SET_STATIC_VERTEX_SHADER_COMBO( HALFLAMBERT, false ); + SET_STATIC_VERTEX_SHADER_COMBO( FLASHLIGHT, false ); + SET_STATIC_VERTEX_SHADER_COMBO( SEAMLESS_BASE, false ); + SET_STATIC_VERTEX_SHADER_COMBO( SEAMLESS_DETAIL, false ); + SET_STATIC_VERTEX_SHADER_COMBO( SEPARATE_DETAIL_UVS, false ); + SET_STATIC_VERTEX_SHADER_COMBO( DECAL, true ); + SET_STATIC_VERTEX_SHADER_COMBO( DONT_GAMMA_CONVERT_VERTEX_COLOR, 0 ); + SET_STATIC_VERTEX_SHADER( vertexlit_and_unlit_generic_vs30 ); + + DECLARE_STATIC_PIXEL_SHADER( decalmodulate_ps30 ); + SET_STATIC_PIXEL_SHADER( decalmodulate_ps30 ); + } +#endif + + // Set stream format (note that this shader supports compression) + unsigned int flags = VERTEX_POSITION | VERTEX_FORMAT_COMPRESSED; +#ifndef _X360 + // The VS30 shader offsets decals along the normal (for morphed geom) + flags |= g_pHardwareConfig->HasFastVertexTextures() ? VERTEX_NORMAL : 0; +#endif + int pTexCoordDim[3] = { 2, 0, 3 }; + int nTexCoordCount = 1; + int userDataSize = 0; + +#ifndef _X360 + if ( g_pHardwareConfig->HasFastVertexTextures() ) + { + nTexCoordCount = 3; + } +#endif + + pShaderShadow->VertexShaderVertexFormat( flags, nTexCoordCount, pTexCoordDim, userDataSize ); + } + DYNAMIC_STATE + { + if ( pShaderAPI->InFlashlightMode() && ( !IsX360() && ( r_flashlight_version2.GetInt() == 0 ) ) ) + { + // Don't draw anything for the flashlight pass + Draw( false ); + return; + } + + BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME ); + + // Set an identity base texture transformation + Vector4D transformation[2]; + transformation[0].Init( 1.0f, 0.0f, 0.0f, 0.0f ); + transformation[1].Init( 0.0f, 1.0f, 0.0f, 0.0f ); + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, transformation[0].Base(), 2 ); + + MaterialFogMode_t fogType = s_pShaderAPI->GetSceneFogMode(); + int fogIndex = ( fogType == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ) ? 1 : 0; + + pShaderAPI->SetPixelShaderFogParams( PSREG_FOG_PARAMS ); + + float vEyePos_SpecExponent[4]; + pShaderAPI->GetWorldSpaceCameraPosition( vEyePos_SpecExponent ); + vEyePos_SpecExponent[3] = 0.0f; + pShaderAPI->SetPixelShaderConstant( PSREG_EYEPOS_SPEC_EXPONENT, vEyePos_SpecExponent, 1 ); + +#ifndef _X360 + if ( !g_pHardwareConfig->HasFastVertexTextures() ) +#endif + { + DECLARE_DYNAMIC_VERTEX_SHADER( vertexlit_and_unlit_generic_vs20 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( DYNAMIC_LIGHT, 0 ); // Use simplest possible vertex lighting, since ps is so simple + SET_DYNAMIC_VERTEX_SHADER_COMBO( STATIC_LIGHT_VERTEX, 0 ); // + SET_DYNAMIC_VERTEX_SHADER_COMBO( STATIC_LIGHT_LIGHTMAP, 0); // + SET_DYNAMIC_VERTEX_SHADER_COMBO( DOWATERFOG, fogIndex ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, 0 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( LIGHTING_PREVIEW, 0 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( NUM_LIGHTS, 0 ); + SET_DYNAMIC_VERTEX_SHADER( vertexlit_and_unlit_generic_vs20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_DYNAMIC_PIXEL_SHADER( decalmodulate_ps20b ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + SET_DYNAMIC_PIXEL_SHADER( decalmodulate_ps20b ); + } + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( decalmodulate_ps20 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + SET_DYNAMIC_PIXEL_SHADER( decalmodulate_ps20 ); + } + } +#ifndef _X360 + else + { + SetHWMorphVertexShaderState( VERTEX_SHADER_SHADER_SPECIFIC_CONST_6, VERTEX_SHADER_SHADER_SPECIFIC_CONST_7, SHADER_VERTEXTEXTURE_SAMPLER0 ); + + DECLARE_DYNAMIC_VERTEX_SHADER( vertexlit_and_unlit_generic_vs30 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( DYNAMIC_LIGHT, 0 ); // Use simplest possible vertex lighting, since ps is so simple + SET_DYNAMIC_VERTEX_SHADER_COMBO( STATIC_LIGHT_VERTEX, 0 ); // + SET_DYNAMIC_VERTEX_SHADER_COMBO( STATIC_LIGHT_LIGHTMAP, 0); // + SET_DYNAMIC_VERTEX_SHADER_COMBO( DOWATERFOG, fogIndex ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, pShaderAPI->GetCurrentNumBones() > 0 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( LIGHTING_PREVIEW, 0 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( MORPHING, pShaderAPI->IsHWMorphingEnabled() ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression ); + SET_DYNAMIC_VERTEX_SHADER( vertexlit_and_unlit_generic_vs30 ); + + DECLARE_DYNAMIC_PIXEL_SHADER( decalmodulate_ps30 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + SET_DYNAMIC_PIXEL_SHADER( decalmodulate_ps30 ); + + bool bUnusedTexCoords[3] = { false, false, !pShaderAPI->IsHWMorphingEnabled() }; + pShaderAPI->MarkUnusedVertexFields( 0, 3, bUnusedTexCoords ); + } +#endif + } + Draw( ); + } +END_SHADER diff --git a/materialsystem/stdshaders/Downsample.cpp b/materialsystem/stdshaders/Downsample.cpp new file mode 100644 index 0000000..69c5724 --- /dev/null +++ b/materialsystem/stdshaders/Downsample.cpp @@ -0,0 +1,110 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//===========================================================================// + +#include "BaseVSShader.h" +#include "common_hlsl_cpp_consts.h" + +#include "Downsample_ps20.inc" +#include "Downsample_ps20b.inc" + + +BEGIN_VS_SHADER_FLAGS( Downsample, "Help for Downsample", SHADER_NOT_EDITABLE ) + BEGIN_SHADER_PARAMS + END_SHADER_PARAMS + + SHADER_INIT + { + LoadTexture( BASETEXTURE ); + } + + SHADER_FALLBACK + { + // Requires DX9 + above + if ( !g_pHardwareConfig->SupportsVertexAndPixelShaders() ) + { +// Assert( 0 ); + return "Wireframe"; + } + return 0; + } + + SHADER_DRAW + { + SHADOW_STATE + { + pShaderShadow->EnableDepthWrites( false ); + pShaderShadow->EnableAlphaWrites( true ); + + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + + // Render targets are pegged as sRGB on OSX GL, so just force these reads and writes + bool bForceSRGBReadAndWrite = IsOSX() && g_pHardwareConfig->CanDoSRGBReadFromRTs(); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, bForceSRGBReadAndWrite ); + pShaderShadow->EnableSRGBWrite( bForceSRGBReadAndWrite ); + + int fmt = VERTEX_POSITION; + pShaderShadow->VertexShaderVertexFormat( fmt, 1, 0, 0 ); + + pShaderShadow->SetVertexShader( "Downsample_vs20", 0 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_STATIC_PIXEL_SHADER( downsample_ps20b ); + SET_STATIC_PIXEL_SHADER( downsample_ps20b ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( downsample_ps20 ); + SET_STATIC_PIXEL_SHADER( downsample_ps20 ); + } + } + + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER0, BASETEXTURE, -1 ); + + int width, height; + pShaderAPI->GetBackBufferDimensions( width, height ); + + float v[4]; + float dX = 1.0f / width; + float dY = 1.0f / height; + + v[0] = -dX; + v[1] = -dY; + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, v, 1 ); + v[0] = -dX; + v[1] = dY; + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_1, v, 1 ); + v[0] = dX; + v[1] = -dY; + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_2, v, 1 ); + v[0] = dX; + v[1] = dY; + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_3, v, 1 ); + + // Setup luminance threshold (all values are scaled down by max luminance) +// v[0] = 1.0f / MAX_HDR_OVERBRIGHT; + v[0] = 0.0f; + pShaderAPI->SetPixelShaderConstant( 0, v, 1 ); + + pShaderAPI->SetVertexShaderIndex( 0 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_DYNAMIC_PIXEL_SHADER( downsample_ps20b ); + SET_DYNAMIC_PIXEL_SHADER( downsample_ps20b ); + } + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( downsample_ps20 ); + SET_DYNAMIC_PIXEL_SHADER( downsample_ps20 ); + } + } + Draw(); + } +END_SHADER diff --git a/materialsystem/stdshaders/Downsample_nohdr_ps11.psh b/materialsystem/stdshaders/Downsample_nohdr_ps11.psh new file mode 100644 index 0000000..94750dd --- /dev/null +++ b/materialsystem/stdshaders/Downsample_nohdr_ps11.psh @@ -0,0 +1,23 @@ +ps.1.1 + +def c0, 0.00f, 0.00f, 0.00f, 0.25f +def c1, 0.30f, 0.59f, 0.11f, 0.00f + +tex t0 +tex t1 +tex t2 +tex t3 + + +// r1 = average = ( t0 + t1 + t2 + t3 ) * 0.25 +mul r1.rgb, t0, c0.a +mad r1.rgb, t1, c0.a, r1 +mad r1.rgb, t2, c0.a, r1 +mad r1.rgb, t3, c0.a, r1 + +// r0.a = avg luminance +dp3 r0, r1, c1 + +// r0.rgb = color = average*(luminance) +mul r0.rgb, r1, r0.a + diff --git a/materialsystem/stdshaders/Downsample_nohdr_ps2x.fxc b/materialsystem/stdshaders/Downsample_nohdr_ps2x.fxc new file mode 100644 index 0000000..64eeaef --- /dev/null +++ b/materialsystem/stdshaders/Downsample_nohdr_ps2x.fxc @@ -0,0 +1,82 @@ +// STATIC: "SRGB_ADAPTER" "0..1" [ps20b] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b] [= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX] +// STATIC: "CSTRIKE" "0..1" + +#define HDRTYPE HDR_TYPE_NONE +#include "common_ps_fxc.h" + +sampler TexSampler : register( s0 ); +float4 params : register( c0 ); + +struct PS_INPUT +{ + float2 coordTap0 : TEXCOORD0; + float2 coordTap1 : TEXCOORD1; + float2 coordTap2 : TEXCOORD2; + float2 coordTap3 : TEXCOORD3; +}; + +#if ( CSTRIKE == 0 ) + //---------------------------------------// + // Everything but Counter-Strike: Source // + //---------------------------------------// + float4 Shape( float2 uv ) + { + float4 pixel = tex2D( TexSampler, uv ); + + #if ( SRGB_ADAPTER == 1 ) + { + pixel.rgb = LinearToGamma( pixel.rgb ); + } + #endif + + float lum = dot( pixel.xyz, params.xyz ); + pixel.xyz = pow( pixel.xyz, params.w ) * lum; + + #if ( SRGB_ADAPTER == 1 ) + { + pixel.rgb = GammaToLinear( pixel.rgb ); + } + #endif + + return pixel; + } + + float4 main( PS_INPUT i ) : COLOR + { + float4 s0, s1, s2, s3; + + // Sample 4 taps + s0 = Shape( i.coordTap0 ); + s1 = Shape( i.coordTap1 ); + s2 = Shape( i.coordTap2 ); + s3 = Shape( i.coordTap3 ); + + float4 avgColor = ( s0 + s1 + s2 + s3 ) * 0.25f; + return FinalOutput( avgColor, 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE ); + } +#else + //------------------------// + // Counter-Strike: Source // + //------------------------// + float3 Shape( float3 s ) + { + float lum = ( 0.3f * s.x ) + ( 0.59f * s.y ) + ( 0.11f * s.z ); + return lum * s; + } + + float4 main( PS_INPUT i ) : COLOR + { + float3 s0, s1, s2, s3; + + // Sample 4 taps + s0 = Shape( GammaToLinear( tex2D( TexSampler, i.coordTap0 ) ) ); + s1 = Shape( GammaToLinear( tex2D( TexSampler, i.coordTap1 ) ) ); + s2 = Shape( GammaToLinear( tex2D( TexSampler, i.coordTap2 ) ) ); + s3 = Shape( GammaToLinear( tex2D( TexSampler, i.coordTap3 ) ) ); + + float3 avgColor = ( s0 + s1 + s2 + s3 ) * 0.25f; + return float4( avgColor, 1.0f ); + } +#endif diff --git a/materialsystem/stdshaders/Downsample_ps2x.fxc b/materialsystem/stdshaders/Downsample_ps2x.fxc new file mode 100644 index 0000000..e103edb --- /dev/null +++ b/materialsystem/stdshaders/Downsample_ps2x.fxc @@ -0,0 +1,30 @@ +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX] + +#define HDRTYPE HDR_TYPE_NONE +#include "common_ps_fxc.h" + +sampler TexSampler : register( s0 ); + +struct PS_INPUT +{ + float2 coordTap0 : TEXCOORD0; + float2 coordTap1 : TEXCOORD1; + float2 coordTap2 : TEXCOORD2; + float2 coordTap3 : TEXCOORD3; +}; + +float4 main( PS_INPUT i ) : COLOR +{ + float3 s0, s1, s2, s3; + + // Sample 4 taps + s0 = tex2D( TexSampler, i.coordTap0); + s1 = tex2D( TexSampler, i.coordTap1); + s2 = tex2D( TexSampler, i.coordTap2); + s3 = tex2D( TexSampler, i.coordTap3); + + float3 avgColor = ( s0 + s1 + s2 + s3 ) * 0.25f; + return FinalOutput( float4( avgColor, 1 ), 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE ); +} + diff --git a/materialsystem/stdshaders/Downsample_vs11.fxc b/materialsystem/stdshaders/Downsample_vs11.fxc new file mode 100644 index 0000000..1027de7 --- /dev/null +++ b/materialsystem/stdshaders/Downsample_vs11.fxc @@ -0,0 +1,40 @@ +//====== Copyright © 1996-2004, Valve Corporation, All rights reserved. ======= +// +// Purpose: +// +//============================================================================= + +#include "common_vs_fxc.h" + +struct VS_INPUT +{ + float3 vPos : POSITION; + float2 vBaseTexCoord : TEXCOORD0; +}; + +struct VS_OUTPUT +{ + float4 projPos : POSITION; + float2 coordTap0 : TEXCOORD0; + float2 coordTap1 : TEXCOORD1; + float2 coordTap2 : TEXCOORD2; + float2 coordTap3 : TEXCOORD3; +}; + +float2 vsTapOffs[4] : register ( SHADER_SPECIFIC_CONST_0 ); + +VS_OUTPUT main( const VS_INPUT v ) +{ + VS_OUTPUT o = ( VS_OUTPUT )0; + + o.projPos = float4( v.vPos, 1.0f ); + + o.coordTap0 = v.vBaseTexCoord + vsTapOffs[0]; + o.coordTap1 = v.vBaseTexCoord + vsTapOffs[1]; + o.coordTap2 = v.vBaseTexCoord + vsTapOffs[2]; + o.coordTap3 = v.vBaseTexCoord + vsTapOffs[3]; + + return o; +} + + diff --git a/materialsystem/stdshaders/Downsample_vs20.fxc b/materialsystem/stdshaders/Downsample_vs20.fxc new file mode 100644 index 0000000..06b1a1c --- /dev/null +++ b/materialsystem/stdshaders/Downsample_vs20.fxc @@ -0,0 +1,34 @@ +#include "common_vs_fxc.h" + +struct VS_INPUT +{ + float3 vPos : POSITION; + float2 vBaseTexCoord : TEXCOORD0; +}; + +struct VS_OUTPUT +{ + float4 projPos : POSITION; + float2 coordTap0 : TEXCOORD0; + float2 coordTap1 : TEXCOORD1; + float2 coordTap2 : TEXCOORD2; + float2 coordTap3 : TEXCOORD3; +}; + +float2 vsTapOffs[4] : register ( SHADER_SPECIFIC_CONST_0 ); + +VS_OUTPUT main( const VS_INPUT v ) +{ + VS_OUTPUT o = ( VS_OUTPUT )0; + + o.projPos = float4( v.vPos, 1.0f ); + + o.coordTap0 = v.vBaseTexCoord + vsTapOffs[0]; + o.coordTap1 = v.vBaseTexCoord + vsTapOffs[1]; + o.coordTap2 = v.vBaseTexCoord + vsTapOffs[2]; + o.coordTap3 = v.vBaseTexCoord + vsTapOffs[3]; + + return o; +} + + diff --git a/materialsystem/stdshaders/Engine_Post_dx9.cpp b/materialsystem/stdshaders/Engine_Post_dx9.cpp new file mode 100644 index 0000000..66a290f --- /dev/null +++ b/materialsystem/stdshaders/Engine_Post_dx9.cpp @@ -0,0 +1,227 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//============================================================================= + +#include "BaseVSShader.h" + +#include "screenspaceeffect_vs20.inc" +#include "engine_post_ps20.inc" +#include "engine_post_ps20b.inc" + +#include "../materialsystem_global.h" + + +DEFINE_FALLBACK_SHADER( Engine_Post, Engine_Post_dx9 ) +BEGIN_VS_SHADER_FLAGS( Engine_Post_dx9, "Engine post-processing effects (software anti-aliasing, bloom, color-correction", SHADER_NOT_EDITABLE ) + BEGIN_SHADER_PARAMS + SHADER_PARAM( FBTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "_rt_FullFrameFB", "Full framebuffer texture" ) + SHADER_PARAM( AAENABLE, SHADER_PARAM_TYPE_BOOL, "0", "Enable software anti-aliasing" ) + SHADER_PARAM( AAINTERNAL1, SHADER_PARAM_TYPE_VEC4, "[0 0 0 0]", "Internal anti-aliasing values set via material proxy" ) + SHADER_PARAM( AAINTERNAL2, SHADER_PARAM_TYPE_VEC4, "[0 0 0 0]", "Internal anti-aliasing values set via material proxy" ) + SHADER_PARAM( AAINTERNAL3, SHADER_PARAM_TYPE_VEC4, "[0 0 0 0]", "Internal anti-aliasing values set via material proxy" ) + SHADER_PARAM( BLOOMENABLE, SHADER_PARAM_TYPE_BOOL, "1", "Enable bloom" ) + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + if( !params[ AAENABLE ]->IsDefined() ) + { + params[ AAENABLE ]->SetIntValue( 0 ); + } + if( !params[ AAINTERNAL1 ]->IsDefined() ) + { + params[ AAINTERNAL1 ]->SetVecValue( 0, 0, 0, 0 ); + } + if( !params[ AAINTERNAL2 ]->IsDefined() ) + { + params[ AAINTERNAL2 ]->SetVecValue( 0, 0, 0, 0 ); + } + if( !params[ AAINTERNAL3 ]->IsDefined() ) + { + params[ AAINTERNAL3 ]->SetVecValue( 0, 0, 0, 0 ); + } + if( !params[ BLOOMENABLE ]->IsDefined() ) + { + params[ BLOOMENABLE ]->SetIntValue( 1 ); + } + SET_FLAGS2( MATERIAL_VAR2_NEEDS_FULL_FRAME_BUFFER_TEXTURE ); + } + + SHADER_FALLBACK + { + // This shader should not be *used* unless we're >= DX9 (bloomadd.vmt/screenspace_general_dx8 should be used for DX8) + return 0; + } + + SHADER_INIT + { + if ( params[BASETEXTURE]->IsDefined() ) + { + LoadTexture( BASETEXTURE ); + } + if ( params[FBTEXTURE]->IsDefined() ) + { + LoadTexture( FBTEXTURE ); + } + } + + SHADER_DRAW + { + SHADOW_STATE + { + // This shader uses opaque blending, but needs to match the behaviour of bloom_add/screen_spacegeneral, + // which uses additive blending (and is used when bloom is enabled but col-correction and AA are not). + // BUT! + // Hardware sRGB blending is incorrect (on pre-DX10 cards, sRGB values are added directly). + // SO... + // When doing the bloom addition in the pixel shader, we need to emulate that incorrect + // behaviour - by turning sRGB read OFF for the FB texture and by turning sRGB write OFF + // (which is fine, since the AA process works better on an sRGB framebuffer than a linear + // one; gamma colours more closely match luminance perception. The color-correction process + // has always taken gamma-space values as input anyway). + + // On OpenGL OSX, we MUST do sRGB reads from the bloom and full framebuffer textures AND sRGB + // writes on the way out to the framebuffer. Hence, our colors are linear in the shader. + // Given this, we use the LINEAR_INPUTS combo to convert to sRGB for the purposes of color + // correction, since that is how the color correction textures are authored. + bool bLinearInput = IsOSX() && g_pHardwareConfig->CanDoSRGBReadFromRTs(); + bool bLinearOutput = IsOSX() && !g_pHardwareConfig->FakeSRGBWrite() && g_pHardwareConfig->CanDoSRGBReadFromRTs(); + + bool bForceSRGBReadsAndWrites = IsOSX() && g_pHardwareConfig->CanDoSRGBReadFromRTs(); + + pShaderShadow->EnableBlending( false ); + + // The (sRGB) bloom texture is bound to sampler 0 + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, bForceSRGBReadsAndWrites ); + pShaderShadow->EnableSRGBWrite( bForceSRGBReadsAndWrites ); + + // The (sRGB) full framebuffer texture is bound to sampler 1: + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER1, bForceSRGBReadsAndWrites ); + + // Up to 4 (sRGB) color-correction lookup textures are bound to samplers 2-5: + pShaderShadow->EnableTexture( SHADER_SAMPLER2, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER3, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER4, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER5, true ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER2, false ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER3, false ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER4, false ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER5, false ); + + int format = VERTEX_POSITION; + int numTexCoords = 1; + int * pTexCoordDimensions = NULL; + int userDataSize = 0; + pShaderShadow->VertexShaderVertexFormat( format, numTexCoords, pTexCoordDimensions, userDataSize ); + + DECLARE_STATIC_VERTEX_SHADER( screenspaceeffect_vs20 ); + SET_STATIC_VERTEX_SHADER( screenspaceeffect_vs20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() || g_pHardwareConfig->ShouldAlwaysUseShaderModel2bShaders() ) // GL always goes the ps2b way for this shader, even on "ps20" parts + { + DECLARE_STATIC_PIXEL_SHADER( engine_post_ps20b ); + SET_STATIC_PIXEL_SHADER_COMBO( LINEAR_INPUT, bLinearInput ); + SET_STATIC_PIXEL_SHADER_COMBO( LINEAR_OUTPUT, bLinearOutput ); + SET_STATIC_PIXEL_SHADER( engine_post_ps20b ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( engine_post_ps20 ); + SET_STATIC_PIXEL_SHADER( engine_post_ps20 ); + } + } + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER0, BASETEXTURE, -1 ); + // FIXME: need to set FBTEXTURE to be point-sampled (will speed up this shader significantly on 360) + // and assert that it's set to SHADER_TEXWRAPMODE_CLAMP (since the shader will sample offscreen) + BindTexture( SHADER_SAMPLER1, FBTEXTURE, -1 ); + + ShaderColorCorrectionInfo_t ccInfo; + pShaderAPI->GetCurrentColorCorrection( &ccInfo ); + int colCorrectNumLookups = ccInfo.m_nLookupCount; + for( int i = 0; i < colCorrectNumLookups; i++ ) + { + pShaderAPI->BindStandardTexture( (Sampler_t)(SHADER_SAMPLER2 + i), (StandardTextureId_t)(TEXTURE_COLOR_CORRECTION_VOLUME_0 + i) ); + } + + // Upload 1-pixel X&Y offsets [ (+dX,0,+dY,-dX) is chosen to work with the allowed ps20 swizzles ] + // The shader will sample in a cross (up/down/left/right from the current sample), for 5-tap + // (quality 0) mode and add another 4 samples in a diagonal cross, for 9-tap (quality 1) mode + ITexture * pTarget = params[FBTEXTURE]->GetTextureValue(); + int width = pTarget->GetActualWidth(); + int height = pTarget->GetActualHeight(); + float dX = 1.0f / width; + float dY = 1.0f / height; + float offsets[4] = { +dX, 0, +dY, -dX }; + pShaderAPI->SetPixelShaderConstant( 0, &offsets[0], 1 ); + // Upload AA tweakables: + // x - strength (this can be used to toggle the AA off, or to weaken it where pathological cases are showing) + // y - reduction of 1-pixel-line blurring (blurring of 1-pixel lines causes issues, so it's tunable) + // z - edge threshold multiplier (default 1.0, < 1.0 => more edges softened, > 1.0 => fewer edges softened) + // w - tap offset multiplier (default 1.0, < 1.0 => sharper image, > 1.0 => blurrier image) + float tweakables[4] = { params[ AAINTERNAL1 ]->GetVecValue()[0], + params[ AAINTERNAL1 ]->GetVecValue()[1], + params[ AAINTERNAL3 ]->GetVecValue()[0], + params[ AAINTERNAL3 ]->GetVecValue()[1] }; + pShaderAPI->SetPixelShaderConstant( 1, &tweakables[0], 1 ); + // Upload AA UV transform (converts bloom texture UVs to framebuffer texture UVs) + // NOTE: we swap the order of the z and w components since 'wz' is an allowed ps20 swizzle, but 'zw' is not: + float uvTrans[4] = { params[ AAINTERNAL2 ]->GetVecValue()[0], + params[ AAINTERNAL2 ]->GetVecValue()[1], + params[ AAINTERNAL2 ]->GetVecValue()[3], + params[ AAINTERNAL2 ]->GetVecValue()[2] }; + pShaderAPI->SetPixelShaderConstant( 2, &uvTrans[0], 1 ); + + // Upload color-correction weights: + pShaderAPI->SetPixelShaderConstant( 3, &ccInfo.m_flDefaultWeight ); + pShaderAPI->SetPixelShaderConstant( 4, ccInfo.m_pLookupWeights ); + + int aaEnabled = ( params[ AAINTERNAL1 ]->GetVecValue()[0] == 0.0f ) ? 0 : 1; + int aaReduceOnePixelLineBlur = ( params[ AAINTERNAL1 ]->GetVecValue()[1] == 0.0f ) ? 0 : 1; + int aaQualityMode = (int)params[ AAINTERNAL1 ]->GetVecValue()[2]; +// int aaDebugMode = (int)params[ AAINTERNAL1 ]->GetVecValue()[3]; + int bloomEnabled = ( params[ BLOOMENABLE ]->GetIntValue() == 0 ) ? 0 : 1; + int colCorrectEnabled = ccInfo.m_bIsEnabled; + + float flBloomFactor = bloomEnabled ? 1.0f : 0.0f; + float bloomConstant[4] = { flBloomFactor, flBloomFactor, flBloomFactor, flBloomFactor }; + pShaderAPI->SetPixelShaderConstant( 5, bloomConstant ); + + if ( !colCorrectEnabled ) + { + colCorrectNumLookups = 0; + } + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() || g_pHardwareConfig->ShouldAlwaysUseShaderModel2bShaders() ) // GL always goes the ps2b way for this shader, even on "ps20" parts + { + DECLARE_DYNAMIC_PIXEL_SHADER( engine_post_ps20b ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( AA_ENABLE, aaEnabled ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( AA_QUALITY_MODE, aaQualityMode ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( AA_REDUCE_ONE_PIXEL_LINE_BLUR, aaReduceOnePixelLineBlur ); +// SET_DYNAMIC_PIXEL_SHADER_COMBO( AA_DEBUG_MODE, aaDebugMode ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( COL_CORRECT_NUM_LOOKUPS, colCorrectNumLookups ); + SET_DYNAMIC_PIXEL_SHADER( engine_post_ps20b ); + } + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( engine_post_ps20 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( AA_ENABLE, aaEnabled ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( AA_QUALITY_MODE, 0 ); // Only enough instruction slots in ps2b + SET_DYNAMIC_PIXEL_SHADER_COMBO( AA_REDUCE_ONE_PIXEL_LINE_BLUR, 0 ); +// SET_DYNAMIC_PIXEL_SHADER_COMBO( AA_DEBUG_MODE, aaDebugMode ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( COL_CORRECT_NUM_LOOKUPS, colCorrectNumLookups ); + SET_DYNAMIC_PIXEL_SHADER( engine_post_ps20 ); + } + + DECLARE_DYNAMIC_VERTEX_SHADER( screenspaceeffect_vs20 ); + SET_DYNAMIC_VERTEX_SHADER( screenspaceeffect_vs20 ); + } + Draw(); + } +END_SHADER diff --git a/materialsystem/stdshaders/Engine_Post_ps2x.fxc b/materialsystem/stdshaders/Engine_Post_ps2x.fxc new file mode 100644 index 0000000..7845c6c --- /dev/null +++ b/materialsystem/stdshaders/Engine_Post_ps2x.fxc @@ -0,0 +1,433 @@ +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX] +// STATIC: "LINEAR_INPUT" "0..1" [ps20b] +// STATIC: "LINEAR_OUTPUT" "0..1" [ps20b] + +// DYNAMIC: "AA_ENABLE" "0..1" +// rem DYNAMIC: "AA_DEBUG_MODE" "0..3" +#define AA_DEBUG_MODE 0 +// DYNAMIC: "AA_QUALITY_MODE" "0..0" [ps20] +// DYNAMIC: "AA_QUALITY_MODE" "0..1" [ps20b] +// DYNAMIC: "AA_QUALITY_MODE" "0..1" [ps30] +// DYNAMIC: "AA_REDUCE_ONE_PIXEL_LINE_BLUR" "0..0" [ps20] +// DYNAMIC: "AA_REDUCE_ONE_PIXEL_LINE_BLUR" "0..1" [ps20b] +// DYNAMIC: "AA_REDUCE_ONE_PIXEL_LINE_BLUR" "0..1" [ps30] +// DYNAMIC: "COL_CORRECT_NUM_LOOKUPS" "0..4" + +#define HDRTYPE HDR_TYPE_NONE +#include "common_ps_fxc.h" + + +#if !(defined(SHADER_MODEL_PS_2_B) || defined(SHADER_MODEL_PS_3_0)) +// Only allow debug modes and high-quality mode if in ps2b or higher (not enough instruction slots in ps20) +#undef AA_DEBUG_MODE +#define AA_DEBUG_MODE 0 +#endif + + +/* + * Engine_Post combines bloom (the final simple addition) with software anti-aliasing + * and colour-correction. Combining them has these benefits: + * (a) saves fillrate+bandwidth (big on PC) + * (b) saves calls to UpdateScreenEffectTexture (big on 360) + * (c) reduces quantization errors caused by multiple passes + * (d) improves AA quality (it works better on sRGB values than linear) + * + * + * Software AA Summary + * ------------------- + * + * This AA process works by sampling neighbour pixels (4 or 8 of them): + * + * 5-tap filter: # 9-tap filter: ### + * (AA_QUALITY_MODE 0) ### (AA_QUALITY_MODE 1) ### + * # ### + * + * It then figures out which of these neighbours are 'unlike' the centre pixel. + * This is based on RGB distance, weighted by the maximum luminance of the samples + * (so the difference between 0.1 and 0.2 is the same as between 0.5 and 1.0). + * This detects high-contrast edges in both dark and bright scenes. + * + * It then counts how many 'unlike' samples there are. Some example cases for 5-tap: + * + * O # # # # # + * OOO OOO #OO OOO #O# #O# + * O O O # O # + * Zero One TwoA TwoB Three Four + * + * We then blend towards the average of the unlike neighbours, based on how many + * unlike neighbours there are. The key case is 'TwoA' - this detects stairstep pixels + * on non-axis-aligned edges. In that case, we blend the output colour towards the + * average of the unlike samples by 33%. This yields a 3-pixel transition (0->33->66->100) + * where before there was a 1-pixel transition (0->100). + * + * The 9-tap filter (which works the same as 5-tap, just with more samples and different + * weights) has two advantages over the 5-tap filter: + * - it can differentiate between stairsteps on 45-degree edges and near-horizontal edges + * (so the 5-tap version smudges 45-degree edges more than you want, e.g. chain-link fences) + * - it blurs less texture detail, by virtue of averaging out noise over more samples + * + * One problem case that both filters have to consider is one-pixel-thick lines (this is + * case 'TwoB' above). Sometimes you do want to soften these lines (for slivers of brightly-lit + * geometry in a dark area, e.g. a window frame), but sometimes you do NOT want to soften them + * (for thin geometry which is alternating between 1-pixel and 2-pixel thickness, e.g. cables, + * and also where 1-pixel lines appear in textures, e.g. roof tiles). So, blurring of 1-pixel + * lines is tunable (it defaults to half-blurred as a compromise between the want/don't cases), + * in the 'AA_REDUCE_ONE_PIXEL_LINE_BLUR' section below. Case TwoB is differentiated from TwoA by + * computing the centroid of the unlike samples (the centroid will be at zero for case TwoB, + * but not for TwoA). + * + */ + +sampler BaseTextureSampler : register( s0 ); +sampler FBTextureSampler : register( s1 ); +sampler ColorCorrectionVolumeTexture0 : register( s2 ); +sampler ColorCorrectionVolumeTexture1 : register( s3 ); +sampler ColorCorrectionVolumeTexture2 : register( s4 ); +sampler ColorCorrectionVolumeTexture3 : register( s5 ); + +float4 psTapOffs_Packed : register( c0 ); // psTapOffs_packed contains 1-pixel offsets: ( +dX, 0, +dY, -dX ) +float4 tweakables : register( c1 ); // (x - AA strength/unused) (y - reduction of 1-pixel-line blur) + // (z - edge threshold multipler) (w - tap offset multiplier) +float4 uvTransform : register( c2 ); // Transform BaseTexture UVs for use with the FBTexture + +float ColorCorrectionDefaultWeight : register( c3 ); +float4 ColorCorrectionVolumeWeights : register( c4 ); +float BloomFactor : register( c5 ); + +float4 GetBloomColor( float2 bloomUV ) +{ + #if ( LINEAR_INPUT == 1 ) + { + // In this case, which is only used on OpenGL, we want sRGB data from this tex2D. + // Hence, we have to undo the sRGB conversion that we are forced to apply by OpenGL + return LinearToGamma( tex2D( BaseTextureSampler, bloomUV ) ); + } + #else + { + return tex2D( BaseTextureSampler, bloomUV ); + } + #endif +} + +float4 PerformColorCorrection( float4 outColor, float2 fbTexCoord ) +{ + #if ( COL_CORRECT_NUM_LOOKUPS > 0 ) + { + // NOTE: This code requires the color correction texture to be 32 units to be correct. + // This code will cause (0,0,0) to be read from 0.5f/32 + // and (1,1,1) to be read from 31.5f/32 + float4 offsetOutColor = outColor*(31.0f/32.0f) + (0.5f/32.0f); + + outColor.rgb = outColor.rgb * ColorCorrectionDefaultWeight; + outColor.rgb += tex3D( ColorCorrectionVolumeTexture0, offsetOutColor.rgb ) * ColorCorrectionVolumeWeights.x; + #if ( COL_CORRECT_NUM_LOOKUPS > 1 ) + { + outColor.rgb += tex3D( ColorCorrectionVolumeTexture1, offsetOutColor.rgb ) * ColorCorrectionVolumeWeights.y; + #if ( COL_CORRECT_NUM_LOOKUPS > 2 ) + { + outColor.rgb += tex3D( ColorCorrectionVolumeTexture2, offsetOutColor.rgb ) * ColorCorrectionVolumeWeights.z; + #if ( COL_CORRECT_NUM_LOOKUPS > 3 ) + { + outColor.rgb += tex3D( ColorCorrectionVolumeTexture3, offsetOutColor.rgb ) * ColorCorrectionVolumeWeights.w; + } + #endif + } + #endif + } + #endif + } + #endif + + return outColor; +} + +float3 PerformAA( float3 baseColor, float2 fbTexCoord, out float3 unlike, out float unlikeSum, out float lerpFactor ) +{ + float3 a, b, c, d, e, f, g, h; + float3 dA, dB, dC, dD, dE, dF, dG, dH; + float4 deltas, deltas2; + float4 weights, weights2; + float4 lumS; + float maxLumS; + + // Set FAST_DELTAS to '1' to use Manhattan distance (in colour-space) rather than Euclidean distance: + const int FAST_DELTAS = 1; +#if AA_QUALITY_MODE == 0 + const float COLOUR_DELTA_BASE = (FAST_DELTAS == 0) ? 0.11f : 0.5f; + const float COLOUR_DELTA_CONTRAST = 100; + // Scaling down colour deltas (DELTA_SCALE) reduces the over-blurring of 45-degree edges + // by the 5-tap filter. Conversely, increasing it smooths stairsteps more strongly. + const float DELTA_SCALE = 0.75f; +#else // AA_QUALITY_MODE == 0 + const float COLOUR_DELTA_BASE = (FAST_DELTAS == 0) ? 0.24f : 0.65f; + const float COLOUR_DELTA_CONTRAST = 100; + const float DELTA_SCALE = 1.0f; +#endif // AA_QUALITY_MODE == 0 + const float MAX_LERP_FACTOR = 0.66f; + const float SQRT3 = 1.73205080757f; + float onePixelLineBlurReduction = tweakables.y; + + + // psTapOffs_packed contains 1-pixel offsets: ( +dX, 0, +dY, -dX ) + float4 texelDelta = psTapOffs_Packed*tweakables.w; + + // Allowed ps20 swizzles: + // .xyzw on (+dX,0,+dY,-dX) gives: (+dX, 0) & (-dX, 0) (former with 'add', latter with 'sub') + // .yzxw on (+dX,0,+dY,-dX) gives: ( 0,+dY) & ( 0,-dY) + // .wzyx on (+dX,0,+dY,-dX) gives: (-dX,+dY) & (+dX,-dY) + // .zxyw on (not used) + // NOTE: These don't give us (+dX,+dY) and (-dX,-dY), we need to copy +dY: ( +dX, 0, +dY, -dX ) -> ( +dX, +dY, +dY, -dX ) + // NOTE: tex2D() can't swizzle the source register in ps2x, so we have no + // choice but to add each float2 offset to fbTexCoord one at a time :o/ + a = tex2D( FBTextureSampler, fbTexCoord + texelDelta.yz ).rgb; // ( 0,+1) + b = tex2D( FBTextureSampler, fbTexCoord + texelDelta.xy ).rgb; // (+1, 0) + c = tex2D( FBTextureSampler, fbTexCoord - texelDelta.yz ).rgb; // ( 0,-1) + d = tex2D( FBTextureSampler, fbTexCoord - texelDelta.xy ).rgb; // (-1, 0) +#if AA_QUALITY_MODE == 1 + // 9-tap method (do diagonal neighbours too) + e = tex2D( FBTextureSampler, fbTexCoord + texelDelta.wz ).rgb; // (-1,+1) + f = tex2D( FBTextureSampler, fbTexCoord - texelDelta.wz ).rgb; // (+1,-1) + texelDelta.y = texelDelta.z; // Can't quite get all 8 sample offsets from a single float4 with the allowed swizzles! :o/ + g = tex2D( FBTextureSampler, fbTexCoord + texelDelta.xy ).rgb; // (+1,+1) + h = tex2D( FBTextureSampler, fbTexCoord - texelDelta.xy ).rgb; // (-1,-1) +#endif // AA_QUALITY_MODE == 1 + + // Compute the like<-->unlike weights + dA = a - baseColor; + dB = b - baseColor; + dC = c - baseColor; + dD = d - baseColor; +#if AA_QUALITY_MODE == 1 + dE = e - baseColor; + dF = f - baseColor; + dG = g - baseColor; + dH = h - baseColor; +#endif // AA_QUALITY_MODE == 1 + #if ( FAST_DELTAS == 0 ) + { + // Colour-space Euclidean distance + deltas = float4( dot(dA, dA), dot(dB, dB), dot(dC, dC), dot(dD, dD) ); + deltas = DELTA_SCALE*DELTA_SCALE*(deltas / 3); + deltas = sqrt(deltas); + } + #else + { + // Colour-space Manhattan distance + // OPT: to avoid the 'abs', try dividing colours by maxLumS then dotprodding w/ baseColor + deltas.x = dot( abs( dA ), 1 ); + deltas.y = dot( abs( dB ), 1 ); + deltas.z = dot( abs( dC ), 1 ); + deltas.w = dot( abs( dD ), 1 ); + deltas *= DELTA_SCALE; + } + #endif + + weights = deltas; +#if AA_QUALITY_MODE == 1 + #if ( FAST_DELTAS == 0 ) + { + deltas2 = float4( dot(dE, dE), dot(dF, dF), dot(dG, dG), dot(dH, dH) ); + deltas2 = DELTA_SCALE*DELTA_SCALE*(deltas2 / 3); + deltas2 = sqrt(deltas2); + } + #else + { + deltas2.x = dot( abs( dE ), 1); + deltas2.y = dot( abs( dF ), 1); + deltas2.z = dot( abs( dG ), 1); + deltas2.w = dot( abs( dH ), 1); + deltas2 *= DELTA_SCALE; + } + #endif + + weights2 = deltas2; +#endif // AA_QUALITY_MODE == 1 + + // Adjust weights relative to maximum sample luminance (local, relative contrast: 0.1 Vs 0.2 is the same as 0.5 Vs 1.0) + lumS = float4( dot(a, a), dot(b, b), dot(c, c), dot(d, d) ); + lumS.xy = max( lumS.xy, lumS.wz ); + lumS.x = max( lumS.x, lumS.y ); + maxLumS = max( lumS.x, dot( baseColor, baseColor ) ); +#if AA_QUALITY_MODE == 1 + lumS = float4( dot(e, e), dot(f, f), dot(g, g), dot(h, h) ); + lumS.xy = max( lumS.xy, lumS.wz ); + lumS.x = max( lumS.x, lumS.y ); + maxLumS = max( lumS.x, maxLumS ); +#endif // AA_QUALITY_MODE == 1 + float lumScale = 1.0f / sqrt( maxLumS ); + weights *= lumScale; +#if AA_QUALITY_MODE == 1 + weights2 *= lumScale; +#endif // AA_QUALITY_MODE == 1 + + // Contrast-adjust weights such that only large contrast differences are taken into account + // (pushes weights to 0.0 for 'like' neighbours and to 1.0 for 'unlike' neighbours) + float colourDeltaBase = tweakables.z*COLOUR_DELTA_BASE; + weights = saturate(colourDeltaBase + COLOUR_DELTA_CONTRAST*(weights - colourDeltaBase)); +#if AA_QUALITY_MODE == 1 + weights2 = saturate(colourDeltaBase + COLOUR_DELTA_CONTRAST*(weights2 - colourDeltaBase)); +#endif // AA_QUALITY_MODE == 1 + + // Determine the average 'unlike' colour + unlikeSum = dot(weights, 1); + unlike = weights.x*a + weights.y*b + weights.z*c + weights.w*d; +#if AA_QUALITY_MODE == 1 + unlikeSum += dot(weights2, 1); + unlike += weights2.x*e + weights2.y*f + weights2.z*g + weights2.w*h; +#endif // AA_QUALITY_MODE == 1 + // NOTE: this can cause div-by-zero, but lerpFactor ends up at zero in that case so it doesn't matter + unlike = unlike / unlikeSum; + + +#if AA_REDUCE_ONE_PIXEL_LINE_BLUR + // Reduce lerpFactor for 1-pixel-thick lines - otherwise you lose texture detail, and it looks + // really weird where geometry (e.g. cables) alternates between being 1 and 2 pixels thick. + // [ The "*2" below is because the values here were tuned to reduce blurring one 1-pixel lines + // by about half (which is a good compromise between the bad cases at either end). So you + // want the controlling convar to default to 0.5 ] + const float ONE_PIXEL_LINE_BIAS_BASE = 0.4f; + const float ONE_PIXEL_LINE_BIAS_CONTRAST = 16.0f; + float2 unlikeCentroid = 0; + unlikeCentroid.x += dot( 1-weights, float4( 0, +1, 0, -1 ) ); // This 2x4 matrix is the transpose of + unlikeCentroid.y += dot( 1-weights, float4( +1, 0, -1, 0 ) ); // the neighbour sample texel offsets +#if AA_QUALITY_MODE == 0 + unlikeCentroid /= 4 - unlikeSum; +#else // AA_QUALITY_MODE == 0 + unlikeCentroid.x += dot( 1-weights2, float4( -1, +1, +1, -1 ) ); + unlikeCentroid.y += dot( 1-weights2, float4( +1, -1, +1, -1 ) ); + unlikeCentroid /= 8 - unlikeSum; +#endif // AA_QUALITY_MODE == 0 + float onePixelLineBias = 1 - saturate( length(unlikeCentroid) ); // OPTIMIZE: try using distSquared, remove this sqrt + onePixelLineBias = onePixelLineBlurReduction*saturate(ONE_PIXEL_LINE_BIAS_BASE + ONE_PIXEL_LINE_BIAS_CONTRAST*(onePixelLineBias - ONE_PIXEL_LINE_BIAS_BASE)); +#if AA_QUALITY_MODE == 0 + unlikeSum -= 2*onePixelLineBias*0.4f*saturate( 3 - unlikeSum ); // The 'min' thing avoids this affecting lone/pair pixels +#else // AA_QUALITY_MODE == 0 + unlikeSum -= 2*onePixelLineBias*1.9f*saturate( 7 - unlikeSum ); +#endif // AA_QUALITY_MODE == 0 +#endif // AA_REDUCE_ONE_PIXEL_LINE_BLUR + + + // Compute the lerp factor we use to blend between 'baseColor' and 'unlike'. + // We want to lerp 'stairstep' pixels (which have 2 unlike neighbours) + // 33% towards the 'unlike' colour, such that these hard, 1-pixel transitions + // (0% -> 100%) become soft, 3-pixel transitions (0% -> 33% -> 66% -> 100%). + float strengthMultiplier = tweakables.x; + #if ( AA_QUALITY_MODE == 0 ) + { + lerpFactor = saturate( strengthMultiplier*DELTA_SCALE*( (unlikeSum - 1) / 3 ) ); + // Uncomment the following to blend slightly across vertical/horizontal edges (better for 45-degree edges, worse for 90-degree edges) + //lerpFactor = saturate( strengthMultiplier*DELTA_SCALE*( unlikeSum / 6 ) ); + } + #else // AA_QUALITY_MODE != 0 + { + lerpFactor = saturate( strengthMultiplier*DELTA_SCALE*( (unlikeSum - 3) / 3 ) ); + } + #endif + + // Clamp the blend factor so that lone dot pixels aren't blurred into oblivion + lerpFactor = min( lerpFactor, MAX_LERP_FACTOR ); + baseColor = lerp( baseColor, unlike, lerpFactor ); + + return baseColor; +} + +float4 GenerateAADebugColor( float4 outColor, float3 unlike, float unlikeSum, float lerpFactor ) +{ + #if ( AA_DEBUG_MODE == 1 ) + { + // Debug: Visualize the number of 'unlike' samples + outColor.rgb = 0; + if ( AA_QUALITY_MODE == 0 ) + { + if (unlikeSum >= 0.95f) outColor.rgb = float3(1,0,0); + if (unlikeSum >= 1.95f) outColor.rgb = float3(0,1,0); + if (unlikeSum >= 2.95f) outColor.rgb = float3(0,0,1); + } + else + { + if (unlikeSum >= 2.95f) outColor.rgb = float3(1,0,0); + if (unlikeSum >= 3.95f) outColor.rgb = float3(0,1,0); + if (unlikeSum >= 4.95f) outColor.rgb = float3(0,0,1); + } + // Don't sRGB-write + } + #elif ( AA_DEBUG_MODE == 2 ) + { + // Debug: Visualize the strength of lerpFactor + outColor.rgb = 0; + outColor.g = lerpFactor; + // Don't sRGB-write + } + #elif ( AA_DEBUG_MODE == 3 ) + { + // Debug: Visualize the 'unlike' colour that we blend towards + outColor.rgb = lerp( 0, unlike, saturate(5*lerpFactor) ); + // Do sRGB-write (if it's enabled) + outColor = FinalOutput( outColor, 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE ); + } + #endif + + return outColor; +} + +float2 PerformUVTransform( float2 bloomUVs ) +{ + // NOTE: 'wz' is used since 'zw' is not a valid swizzle for ps20 shaders + return bloomUVs*uvTransform.wz + uvTransform.xy; +} + +struct PS_INPUT +{ + float2 baseTexCoord : TEXCOORD0; + +#if defined( _X360 ) //avoid a shader patch on 360 due to pixel shader inputs being fewer than vertex shader outputs + float2 ZeroTexCoord : TEXCOORD1; + float2 bloomTexCoord : TEXCOORD2; +#endif +}; + +float4 main( PS_INPUT i ) : COLOR +{ + float2 fbTexCoord = PerformUVTransform( i.baseTexCoord ); + float3 baseColor = tex2D( FBTextureSampler, fbTexCoord ).rgb; + + #if ( LINEAR_INPUT == 1 ) + { + // In this case, which is only used on OpenGL, we want sRGB data from this tex2D. + // Hence, we have to undo the sRGB conversion that we are forced to apply by OpenGL + baseColor = LinearToGamma( baseColor ); + } + #endif + + float4 outColor = float4( baseColor, 1 ); + + #if ( AA_ENABLE == 1 ) + { + float unlikeSum, lerpFactor; + float3 unlike; + + outColor.rgb = PerformAA( outColor.rgb, fbTexCoord, unlike, unlikeSum, lerpFactor ); + + #if ( AA_DEBUG_MODE > 0 ) + { + return GenerateAADebugColor( outColor, unlike, unlikeSum, lerpFactor ); + } + #endif + } + #endif + + float4 bloomColor = BloomFactor * GetBloomColor( i.baseTexCoord ); + outColor.rgb += bloomColor.rgb; + outColor = PerformColorCorrection( outColor, fbTexCoord ); + outColor = FinalOutput( outColor, 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE ); + + // Go to linear since we're forced to do an sRGB write on OpenGL in ps2b + #if ( LINEAR_OUTPUT == 1 ) + { + outColor = GammaToLinear( outColor ); + } + #endif + + return outColor; +} diff --git a/materialsystem/stdshaders/Eyes.psh b/materialsystem/stdshaders/Eyes.psh new file mode 100644 index 0000000..6909dcf --- /dev/null +++ b/materialsystem/stdshaders/Eyes.psh @@ -0,0 +1,16 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; Draw the eyes +; t0 - texture +; t1 - iris +; t2 - glint +;------------------------------------------------------------------------------ + +tex t0 +tex t1 +tex t2 + +lrp r0, t1.a, t1, t0 ; Blend in the iris with the background +mad r0.rgb, r0, v0, t2 + ; Modulate by the illumination, add in the glint +mov r0.a, t0.a diff --git a/materialsystem/stdshaders/Eyes_Overbright2.psh b/materialsystem/stdshaders/Eyes_Overbright2.psh new file mode 100644 index 0000000..f7fae25 --- /dev/null +++ b/materialsystem/stdshaders/Eyes_Overbright2.psh @@ -0,0 +1,18 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; Draw the eyes +; t0 - texture +; t1 - iris +; t2 - glint +;------------------------------------------------------------------------------ + +tex t0 +tex t1 +tex t2 + +lrp r0, t1.a, t1, t0 ; Blend in the iris with the background +mul_x2 r0, v0, r0 ; Modulate by the illumination with overbright + +add r0.rgb, r0, t2 + ; Add in the glint +mov r0.a, t0.a diff --git a/materialsystem/stdshaders/Eyes_vs20.fxc b/materialsystem/stdshaders/Eyes_vs20.fxc new file mode 100644 index 0000000..b055eed --- /dev/null +++ b/materialsystem/stdshaders/Eyes_vs20.fxc @@ -0,0 +1,145 @@ +//======= Copyright © 1996-2006, Valve Corporation, All rights reserved. ====== +// $SHADER_SPECIFIC_CONST_0 = eyeball origin +// $SHADER_SPECIFIC_CONST_1 = eyeball up * 0.5 +// $SHADER_SPECIFIC_CONST_2 = iris projection U +// $SHADER_SPECIFIC_CONST_3 = iris projection V +// $SHADER_SPECIFIC_CONST_4 = glint projection U +// $SHADER_SPECIFIC_CONST_5 = glint projection V +//============================================================================= + +// STATIC: "INTRO" "0..1" +// STATIC: "HALFLAMBERT" "0..1" +// STATIC: "USE_STATIC_CONTROL_FLOW" "0..1" [vs20] + +// DYNAMIC: "COMPRESSED_VERTS" "0..1" +// DYNAMIC: "SKINNING" "0..1" +// DYNAMIC: "DOWATERFOG" "0..1" +// DYNAMIC: "DYNAMIC_LIGHT" "0..1" +// DYNAMIC: "STATIC_LIGHT" "0..1" +// DYNAMIC: "MORPHING" "0..1" [vs30] +// DYNAMIC: "NUM_LIGHTS" "0..2" [vs20] + +// If using static control flow on Direct3D, we should use the NUM_LIGHTS=0 combo +// SKIP: $USE_STATIC_CONTROL_FLOW && ( $NUM_LIGHTS > 0 ) [vs20] + +#include "vortwarp_vs20_helper.h" + +static const int g_bSkinning = SKINNING ? true : false; +static const int g_FogType = DOWATERFOG; +static const bool g_bHalfLambert = HALFLAMBERT ? true : false; + +const float3 cEyeOrigin : register( SHADER_SPECIFIC_CONST_0 ); +const float3 cHalfEyeballUp : register( SHADER_SPECIFIC_CONST_1 ); +const float4 cIrisProjectionU : register( SHADER_SPECIFIC_CONST_2 ); +const float4 cIrisProjectionV : register( SHADER_SPECIFIC_CONST_3 ); +const float4 cGlintProjectionU : register( SHADER_SPECIFIC_CONST_4 ); +const float4 cGlintProjectionV : register( SHADER_SPECIFIC_CONST_5 ); +#if INTRO +const float4 const4 : register( SHADER_SPECIFIC_CONST_6 ); +#define g_Time const4.w +#define modelOrigin const4.xyz +#endif + +#ifdef SHADER_MODEL_VS_3_0 +// NOTE: cMorphTargetTextureDim.xy = target dimensions, +// cMorphTargetTextureDim.z = 4tuples/morph +const float3 cMorphTargetTextureDim : register( SHADER_SPECIFIC_CONST_7 ); +const float4 cMorphSubrect : register( SHADER_SPECIFIC_CONST_8 ); + +sampler2D morphSampler : register( D3DVERTEXTEXTURESAMPLER0, s0 ); +#endif + +struct VS_INPUT +{ + float4 vPos : POSITION; // Position + float4 vBoneWeights : BLENDWEIGHT; // Skin weights + float4 vBoneIndices : BLENDINDICES; // Skin indices + float4 vTexCoord0 : TEXCOORD0; // Base (sclera) texture coordinates + + float3 vPosFlex : POSITION1; // Delta positions for flexing +#ifdef SHADER_MODEL_VS_3_0 + float vVertexID : POSITION2; +#endif +}; + +struct VS_OUTPUT +{ + float4 projPos : POSITION; // Projection-space position +#if !defined( _X360 ) + float fog : FOG; // Fixed-function fog factor +#endif + float2 baseTC : TEXCOORD0; // Base texture coordinate + float2 irisTC : TEXCOORD1; // Iris texture coordinates + float2 glintTC : TEXCOORD2; // Glint texture coordinates + float3 vColor : TEXCOORD3; // Vertex-lit color + + float4 worldPos_projPosZ : TEXCOORD7; // Necessary for pixel fog + +}; + +VS_OUTPUT main( const VS_INPUT v ) +{ + VS_OUTPUT o; + + bool bDynamicLight = DYNAMIC_LIGHT ? true : false; + bool bStaticLight = STATIC_LIGHT ? true : false; + + float4 vPosition = v.vPos; + float3 dummy = v.vPos.xyz; // dummy values that can't be optimized out + +#if !defined( SHADER_MODEL_VS_3_0 ) || !MORPHING + ApplyMorph( v.vPosFlex, vPosition.xyz ); +#else + ApplyMorph( morphSampler, cMorphTargetTextureDim, cMorphSubrect, v.vVertexID, dummy, vPosition.xyz ); +#endif + + // Transform the position and dummy normal (not doing the dummy normal causes invariance issues with the flashlight!) + float3 worldNormal, worldPos; + SkinPositionAndNormal( + g_bSkinning, + vPosition, dummy, + v.vBoneWeights, v.vBoneIndices, + worldPos, worldNormal ); + +#if INTRO + WorldSpaceVertexProcess( g_Time, modelOrigin, worldPos, dummy, dummy, dummy ); +#endif + + // Transform into projection space + float4 vProjPos = mul( float4( worldPos, 1 ), cViewProj ); + o.projPos = vProjPos; + vProjPos.z = dot( float4( worldPos, 1 ), cViewProjZ ); + o.worldPos_projPosZ = float4( worldPos.xyz, vProjPos.z ); + +#if !defined( _X360 ) + // Set fixed-function fog factor + o.fog = CalcFog( worldPos, vProjPos, g_FogType ); +#endif + + // Normal = (Pos - Eye origin) - just step on dummy normal created above + worldNormal = worldPos - cEyeOrigin; + + // Normal -= 0.5f * (Normal dot Eye Up) * Eye Up + float normalDotUp = -dot( worldNormal, cHalfEyeballUp) * 0.5f; + worldNormal = normalize(normalDotUp * cHalfEyeballUp + worldNormal); + + // Vertex lighting +#if ( USE_STATIC_CONTROL_FLOW || defined ( SHADER_MODEL_VS_3_0 ) ) + o.vColor = DoLighting( worldPos, worldNormal, float3(0.0f, 0.0f, 0.0f), bStaticLight, bDynamicLight, g_bHalfLambert ); +#else + o.vColor = DoLightingUnrolled( worldPos, worldNormal, float3(0.0f, 0.0f, 0.0f), bStaticLight, bDynamicLight, g_bHalfLambert, NUM_LIGHTS ); +#endif + + // Texture 0 is the base texture + // Texture 1 is a planar projection used for the iris + // Texture 2 is a planar projection used for the glint + o.baseTC = v.vTexCoord0; + o.irisTC.x = dot( cIrisProjectionU, float4(worldPos, 1) ); + o.irisTC.y = dot( cIrisProjectionV, float4(worldPos, 1) ); + o.glintTC.x = dot( cGlintProjectionU, float4(worldPos, 1) ); + o.glintTC.y = dot( cGlintProjectionV, float4(worldPos, 1) ); + + return o; +} + + diff --git a/materialsystem/stdshaders/HDRCombineTo16Bit.cpp b/materialsystem/stdshaders/HDRCombineTo16Bit.cpp new file mode 100644 index 0000000..4486f8c --- /dev/null +++ b/materialsystem/stdshaders/HDRCombineTo16Bit.cpp @@ -0,0 +1,83 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//============================================================================= + +#include "BaseVSShader.h" +#include "common_hlsl_cpp_consts.h" +#include "HDRCombineTo16Bit_ps20.inc" +#include "HDRCombineTo16Bit_ps20b.inc" +#include "HDRCombineTo16Bit_vs20.inc" +#include "convar.h" + +BEGIN_VS_SHADER_FLAGS( HDRCombineTo16Bit, "Help for HDRCombineTo16Bit", SHADER_NOT_EDITABLE ) + BEGIN_SHADER_PARAMS + SHADER_PARAM( SOURCEMRTRENDERTARGET, SHADER_PARAM_TYPE_TEXTURE, "", "" ) + END_SHADER_PARAMS + + SHADER_INIT + { + LoadTexture( SOURCEMRTRENDERTARGET ); + } + + SHADER_FALLBACK + { + // Requires DX9 + above + if (!g_pHardwareConfig->SupportsVertexAndPixelShaders()) + { + Assert( 0 ); + return "Wireframe"; + } + return 0; + } + + SHADER_DRAW + { + SHADOW_STATE + { + pShaderShadow->EnableDepthWrites( false ); + pShaderShadow->EnableAlphaWrites( false ); + pShaderShadow->EnableDepthTest( false ); + + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + int fmt = VERTEX_POSITION; + pShaderShadow->VertexShaderVertexFormat( fmt, 1, 0, 0 ); + + DECLARE_STATIC_VERTEX_SHADER( hdrcombineto16bit_vs20 ); + SET_STATIC_VERTEX_SHADER( hdrcombineto16bit_vs20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_STATIC_PIXEL_SHADER( hdrcombineto16bit_ps20b ); + SET_STATIC_PIXEL_SHADER( hdrcombineto16bit_ps20b ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( hdrcombineto16bit_ps20 ); + SET_STATIC_PIXEL_SHADER( hdrcombineto16bit_ps20 ); + } + } + + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER0, SOURCEMRTRENDERTARGET, -1 ); + DECLARE_DYNAMIC_VERTEX_SHADER( hdrcombineto16bit_vs20 ); + SET_DYNAMIC_VERTEX_SHADER( hdrcombineto16bit_vs20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_DYNAMIC_PIXEL_SHADER( hdrcombineto16bit_ps20b ); + SET_DYNAMIC_PIXEL_SHADER( hdrcombineto16bit_ps20b ); + } + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( hdrcombineto16bit_ps20 ); + SET_DYNAMIC_PIXEL_SHADER( hdrcombineto16bit_ps20 ); + } + } + Draw(); + } +END_SHADER diff --git a/materialsystem/stdshaders/HDRCombineTo16Bit_ps2x.fxc b/materialsystem/stdshaders/HDRCombineTo16Bit_ps2x.fxc new file mode 100644 index 0000000..ec8cf1b --- /dev/null +++ b/materialsystem/stdshaders/HDRCombineTo16Bit_ps2x.fxc @@ -0,0 +1,25 @@ +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX] + +#define HDRTYPE HDR_TYPE_NONE +#include "common_ps_fxc.h" + +sampler LowSampler : register( s0 ); +sampler HiSampler : register( s1 ); + +struct PS_INPUT +{ + float2 texCoord : TEXCOORD0; +}; + +float4 main( PS_INPUT i ) : COLOR +{ + float4 lowColor = tex2D( LowSampler, i.texCoord ); + float3 hiColor = tex2D( HiSampler, i.texCoord ); + + lowColor.rgb = GammaToLinear( lowColor.rgb ); + hiColor.rgb = GammaToLinear( hiColor.rgb ); + + float4 result = float4( ( 1.0f / MAX_HDR_OVERBRIGHT ) * max( lowColor.xyz, hiColor.xyz * MAX_HDR_OVERBRIGHT ), lowColor.a ); + return FinalOutput( result, 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE ); +} diff --git a/materialsystem/stdshaders/HDRCombineTo16Bit_vs20.fxc b/materialsystem/stdshaders/HDRCombineTo16Bit_vs20.fxc new file mode 100644 index 0000000..d591a77 --- /dev/null +++ b/materialsystem/stdshaders/HDRCombineTo16Bit_vs20.fxc @@ -0,0 +1,24 @@ +#include "common_vs_fxc.h" + +struct VS_INPUT +{ + float3 vPos : POSITION; + float2 vBaseTexCoord : TEXCOORD0; +}; + +struct VS_OUTPUT +{ + float4 projPos : POSITION; + float2 texCoord : TEXCOORD0; +}; + +VS_OUTPUT main( const VS_INPUT v ) +{ + VS_OUTPUT o = ( VS_OUTPUT )0; + + o.projPos = float4( v.vPos, 1.0f ); + o.texCoord = v.vBaseTexCoord; + return o; +} + + diff --git a/materialsystem/stdshaders/HDRSelectRange.cpp b/materialsystem/stdshaders/HDRSelectRange.cpp new file mode 100644 index 0000000..96ca660 --- /dev/null +++ b/materialsystem/stdshaders/HDRSelectRange.cpp @@ -0,0 +1,82 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//============================================================================= + +#include "BaseVSShader.h" +#include "common_hlsl_cpp_consts.h" + +#include "HDRSelectRange_ps20.inc" +#include "HDRSelectRange_ps20b.inc" + + +BEGIN_VS_SHADER_FLAGS( HDRSelectRange, "Help for HDRSelectRange", SHADER_NOT_EDITABLE ) + BEGIN_SHADER_PARAMS + SHADER_PARAM( SOURCEMRTRENDERTARGET, SHADER_PARAM_TYPE_TEXTURE, "", "" ) + END_SHADER_PARAMS + + SHADER_INIT + { + LoadTexture( SOURCEMRTRENDERTARGET ); + } + + SHADER_FALLBACK + { + // Requires DX9 + above + if (!g_pHardwareConfig->SupportsVertexAndPixelShaders()) + { + Assert( 0 ); + return "Wireframe"; + } + return 0; + } + + SHADER_DRAW + { + SHADOW_STATE + { + pShaderShadow->EnableDepthWrites( false ); + pShaderShadow->EnableAlphaWrites( false ); + pShaderShadow->EnableDepthTest( false ); + + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + int fmt = VERTEX_POSITION; + pShaderShadow->VertexShaderVertexFormat( fmt, 1, 0, 0 ); + + pShaderShadow->SetVertexShader( "HDRSelectRange_vs20", 0 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_STATIC_PIXEL_SHADER( hdrselectrange_ps20b ); + SET_STATIC_PIXEL_SHADER( hdrselectrange_ps20b ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( hdrselectrange_ps20 ); + SET_STATIC_PIXEL_SHADER( hdrselectrange_ps20 ); + } + + } + + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER0, SOURCEMRTRENDERTARGET, -1 ); + pShaderAPI->SetVertexShaderIndex( 0 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_DYNAMIC_PIXEL_SHADER( hdrselectrange_ps20b ); + SET_DYNAMIC_PIXEL_SHADER( hdrselectrange_ps20b ); + } + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( hdrselectrange_ps20 ); + SET_DYNAMIC_PIXEL_SHADER( hdrselectrange_ps20 ); + } + } + Draw(); + } +END_SHADER diff --git a/materialsystem/stdshaders/HDRSelectRange_ps2x.fxc b/materialsystem/stdshaders/HDRSelectRange_ps2x.fxc new file mode 100644 index 0000000..a891fee --- /dev/null +++ b/materialsystem/stdshaders/HDRSelectRange_ps2x.fxc @@ -0,0 +1,45 @@ +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX] + +#define HDRTYPE HDR_TYPE_NONE +#include "common_ps_fxc.h" + +sampler LowSampler : register( s0 ); +sampler HiSampler : register( s1 ); + +struct PS_INPUT +{ + float2 texCoord : TEXCOORD0; +}; + +struct MYHDR_PS_OUTPUT +{ + float4 color[2] : COLOR0; +}; + +MYHDR_PS_OUTPUT main( PS_INPUT i ) : COLOR +{ + float3 lowColor = GammaToLinear( tex2D( LowSampler, i.texCoord ) ); + float3 hiColor = GammaToLinear( tex2D( HiSampler, i.texCoord ) ); + + float4 lowOut; + lowOut.a = 1.0f; + float4 hiOut; + hiOut.a = 1.0f; + + float3 hdrColor = max( lowColor, hiColor * MAX_HDR_OVERBRIGHT ); + + float fMax = max( hdrColor.b, max( hdrColor.r, hdrColor.g ) ); + + float blendFactor = saturate( ( fMax - 0.9f ) * 10.0f ); + + blendFactor = 1.0f; + + lowOut.rgb = LinearToGamma( lowColor * ( 1.0f - blendFactor ) ); + hiOut.rgb = LinearToGamma( hiColor * ( blendFactor ) ); + MYHDR_PS_OUTPUT output; + output.color[0] = lowOut; + output.color[1] = hiOut; + return output; +} + diff --git a/materialsystem/stdshaders/HDRSelectRange_vs20.fxc b/materialsystem/stdshaders/HDRSelectRange_vs20.fxc new file mode 100644 index 0000000..d591a77 --- /dev/null +++ b/materialsystem/stdshaders/HDRSelectRange_vs20.fxc @@ -0,0 +1,24 @@ +#include "common_vs_fxc.h" + +struct VS_INPUT +{ + float3 vPos : POSITION; + float2 vBaseTexCoord : TEXCOORD0; +}; + +struct VS_OUTPUT +{ + float4 projPos : POSITION; + float2 texCoord : TEXCOORD0; +}; + +VS_OUTPUT main( const VS_INPUT v ) +{ + VS_OUTPUT o = ( VS_OUTPUT )0; + + o.projPos = float4( v.vPos, 1.0f ); + o.texCoord = v.vBaseTexCoord; + return o; +} + + diff --git a/materialsystem/stdshaders/IntroScreenSpaceEffect_ps11.fxc b/materialsystem/stdshaders/IntroScreenSpaceEffect_ps11.fxc new file mode 100644 index 0000000..7945de0 --- /dev/null +++ b/materialsystem/stdshaders/IntroScreenSpaceEffect_ps11.fxc @@ -0,0 +1,111 @@ +// DYNAMIC: "MODE" "0..9" + +#include "common_ps_fxc.h" + +const float g_Alpha : register( c0 ); + +sampler BaseTextureSampler : register( s0 ); +sampler BaseTextureSampler2 : register( s1 ); + +struct PS_INPUT +{ + float2 baseTexCoord : TEXCOORD0; + float2 baseTexCoord2 : TEXCOORD1; +}; + +HALF Grey( HALF3 input ) +{ + return dot( ( float3 )( 1.0f / 3.0f ), input ); +} + +HALF4 main( PS_INPUT i ) : COLOR +{ + float3 scene = tex2D( BaseTextureSampler, i.baseTexCoord ); + float3 gman = tex2D( BaseTextureSampler2, i.baseTexCoord2 ); + +#if MODE == 0 + // negative greyscale of scene * gman + float scale = 1.0f / 3.0f; + scene.xyz = dot( float3( scale, scale, scale), scene.xyz ); + scene = 1.0f - scene; + + return float4( scene * gman, g_Alpha ); +#endif + +#if MODE == 1 + if( Grey( gman ) < 0.3 ) + { + return float4( 1.0f - gman, g_Alpha ); + } + else + { + return float4( ( 1.0f - gman ) * scene, g_Alpha ); + } +#endif + +#if MODE == 2 + return float4( lerp( scene, gman, g_Alpha ), g_Alpha ); +#endif + +#if MODE == 3 + return float4( lerp( scene, Grey( gman ), Grey( gman ) ), g_Alpha ); +#endif + +#if MODE == 4 + return float4( lerp( scene, gman, g_Alpha ), g_Alpha ); +#endif + +#if MODE == 5 + float sceneLum = scene.r; + if( sceneLum > 0.0f ) + { + return float4( scene, g_Alpha ); + } + else + { + return float4( gman, g_Alpha ); + } +#endif + +#if MODE == 6 + return float4( scene + gman, g_Alpha ); +#endif + +#if MODE == 7 + return float4( scene, g_Alpha ); +#endif + +#if MODE == 8 + return float4( lerp( scene, gman, g_Alpha ), g_Alpha ); +#endif + +#if MODE == 9 + /* + float3 cGammaLayer1 = scene; + float3 cGammaLayer2 = gman; + + float flLayer1Brightness = saturate( dot( cGammaLayer1.rgb, float3( 0.333f, 0.334f, 0.333f ) ) ); + + float3 cGammaOverlayResult; + if ( flLayer1Brightness < 0.5f ) + { + cGammaOverlayResult.rgb = ( 2.0f * cGammaLayer1.rgb * cGammaLayer2.rgb ); + } + else + { + cGammaOverlayResult.rgb = ( 1.0f - ( 2.0f * ( 1.0f - cGammaLayer1.rgb ) * ( 1.0f - cGammaLayer2.rgb ) ) ); + } + //*/ + + float3 cLayer1 = scene; + float3 cLayer2 = gman; + + float flLayer1Brightness = saturate( dot( cLayer1.rgb, float3( 0.333f, 0.334f, 0.333f ) ) ); + + // Modify layer 1 to be more contrasty. + cLayer1.rgb = saturate( cLayer1.rgb * cLayer1.rgb * 2.0f ); + float3 cGammaOverlayResult = cLayer1.rgb + cLayer2.rgb * saturate( 1.0f - flLayer1Brightness * 2.0f ); + + return float4( cGammaOverlayResult.rgb, g_Alpha ); +#endif +} diff --git a/materialsystem/stdshaders/IntroScreenSpaceEffect_ps11_asm.psh b/materialsystem/stdshaders/IntroScreenSpaceEffect_ps11_asm.psh new file mode 100644 index 0000000..618ce22 --- /dev/null +++ b/materialsystem/stdshaders/IntroScreenSpaceEffect_ps11_asm.psh @@ -0,0 +1,159 @@ +; DYNAMIC: "MODE" "0..8" + +ps.1.1 + +//HALF Grey( HALF3 input ) +//{ +// return dot( ( float3 )( 1.0f / 3.0f ), input ); +//} + +#if MODE == 0 +// negative greyscale of scene * gman +// float scale = 1.0f / 3.0f; +// scene.xyz = dot( float3( scale, scale, scale), scene.xyz ); +// scene = 1.0f - scene; +// return float4( scene * gman, g_Alpha ); +def c1, 0.333333343, 0.333333343, 0.333333343, 1 +def c2, 1, 0, 0, 0 +tex t0 +tex t1 +dp3 r0, c1, t0 +add r0.w, -r0.w, c1.w +mul r0.xyz, t1, r0.w +dp3 r1, c2, c0 +mov r0.w, r1.w +#endif + +#if MODE == 1 +//if( Grey( gman ) < 0.3 ) +// return float4( 1.0f - gman, g_Alpha ); +//else +// return float4( ( 1.0f - gman ) * scene, g_Alpha ); +def c1, 0.333333343, 0.333333343, 0.333333343, 0.300000012 +def c2, 1, 1, 1, 1 +def c3, 1, 0, 0, 0.5 +tex t0 +tex t1 +dp3 r1, c1, t1 +add t0.w, r1.w, -c1.w ++ add r1.xyz, -t1, c2 +dp3 t1, c3, c0 +mov t1.w, t1.w ++ mul t1.xyz, t0, r1 +dp3 t2, c3, c0 +mov r1.w, t2.w +mad r0.w, t0.w, -c2.w, c3.w +cnd r0, r0.w, r1, t1 +#endif + +#if MODE == 2 +// return float4( lerp( scene, gman, g_Alpha ), g_Alpha ); +def c1, 1, 0, 0, 1 +def c2, 0, 0, 0, 1 +tex t0 +tex t1 +dp3 r0, c1, c0 +mul r0.w, r0.w, -c1.w +add r0.w, r0.w, c2.w +add r1.w, -r0.w, c2.w ++ mul r0.xyz, t0, r0.w +mad r0.xyz, t1, r1.w, r0 +dp3 r1, c1, c0 +mov r0.w, r1.w +#endif + +#if MODE == 3 +// return float4( lerp( scene, Grey( gman ), Grey( gman ) ), g_Alpha ); +def c1, 0.333333343, 0.333333343, 0.333333343, 1 +def c2, 1, 0, 0, 0 +tex t0 +tex t1 +dp3 r0, c1, t1 +add r1.w, -r0.w, c1.w +mul r1.xyz, t0, r1.w +mad r0.xyz, r0, r0, r1 +dp3 r1, c2, c0 +mov r0.w, r1.w +#endif + +#if MODE == 4 +// return float4( lerp( scene, gman, g_Alpha ), g_Alpha ); +def c1, 1, 0, 0, 1 +def c2, 0, 0, 0, 1 +tex t0 +tex t1 +dp3 r0, c1, c0 +mul r0.w, r0.w, -c1.w +add r0.w, r0.w, c2.w +add r1.w, -r0.w, c2.w ++ mul r0.xyz, t0, r0.w +mad r0.xyz, t1, r1.w, r0 +dp3 r1, c1, c0 +mov r0.w, r1.w +#endif + +#if MODE == 5 +//float sceneLum = scene.r; +//if( sceneLum > 0.0f ) +// return float4( scene, g_Alpha ); +//else +// return float4( gman, g_Alpha ); +def c1, 1, 0, 0, 1 +def c2, 0, 0, 0, 0.45 +tex t0 ; gman (sceneLum) +tex t1 ; scene +dp3 r1, c1, c0 +mov t1.w, r1.w ; t1.w = alpha +dp3 r1, c1, c0 +mov t0.w, r1.w ; t0.w = alpha +dp3 r1, c1, t0 ; r1.w = gman.r +add r0, r1.w, c2.w +cnd r0, r0.w, t0, t1 +#endif + +#if MODE == 6 +// return float4( scene + gman, g_Alpha ); +def c1, 1, 0, 0, 0 +tex t0 +tex t1 +add r0.xyz, t0, t1 +dp3 r1, c1, c0 +mov r0.w, r1.w +#endif + +#if MODE == 7 +// return float4( lerp( scene, gman, g_Alpha ), g_Alpha ); +def c1, 1, 0, 0, 1 +def c2, 0, 0, 0, 1 +tex t0 +tex t1 +dp3 r0, c1, c0 +mul r0.w, r0.w, -c1.w +add r0.w, r0.w, c2.w +add r1.w, -r0.w, c2.w ++ mul r0.xyz, t0, r0.w +mad r0.xyz, t1, r1.w, r0 +dp3 r1, c1, c0 +mov r0.w, r1.w +#endif + +#if MODE == 8 +// return float4( lerp( scene, gman, g_Alpha ), g_Alpha ); +def c1, 1, 0, 0, 1 +def c2, 0, 0, 0, 1 +tex t0 +tex t1 +dp3 r0, c1, c0 +mul r0.w, r0.w, -c1.w +add r0.w, r0.w, c2.w +add r1.w, -r0.w, c2.w ++ mul r0.xyz, t0, r0.w +mad r0.xyz, t1, r1.w, r0 +dp3 r1, c1, c0 +mov r0.w, r1.w +#endif + + + + + diff --git a/materialsystem/stdshaders/IntroScreenSpaceEffect_ps2x.fxc b/materialsystem/stdshaders/IntroScreenSpaceEffect_ps2x.fxc new file mode 100644 index 0000000..ebeb150 --- /dev/null +++ b/materialsystem/stdshaders/IntroScreenSpaceEffect_ps2x.fxc @@ -0,0 +1,339 @@ +// DYNAMIC: "MODE" "0..9" + +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX] +// STATIC: "LINEAR_TO_SRGB" "0..1" [ps20b] + +#define HDRTYPE HDR_TYPE_NONE +#include "common_ps_fxc.h" + +const float g_Alpha : register( c0 ); + +sampler BaseTextureSampler : register( s0 ); +sampler BaseTextureSampler2 : register( s1 ); + +struct PS_INPUT +{ + float2 baseTexCoord : TEXCOORD0; +}; + +float3 RGBtoHSV( in float3 rgb ) +{ + float3 hsv; + float fmin, fmax, delta; + fmin = min( min( rgb.r, rgb.g ), rgb.b ); + fmax = max( max( rgb.r, rgb.g) , rgb.b ); + hsv.b = fmax; // v + delta = fmax - fmin; + if( delta != 0 ) + { + hsv.g = delta / fmax; // s + if( rgb.r == fmax ) + hsv.r = ( rgb.g - rgb.b ) / delta; // between yellow & magenta + else if( rgb.g == fmax ) + hsv.r = 2 + ( rgb.b - rgb.r ) / delta; // between cyan & yellow + else + hsv.r = 4 + ( rgb.r - rgb.g ) / delta; // between magenta & cyan + hsv.r *= 60; // degrees + if( hsv.r < 0 ) + hsv.r += 360; + } + else + { + // r = g = b = 0 // s = 0, v is undefined + hsv.g = 0; + hsv.r = -1; + } + return hsv; +} + +float3 HSVtoRGB( in float3 hsv ) +{ + int i; + float3 rgb; + float h = hsv.r; + float s = hsv.g; + float v = hsv.b; + float f, p, q, t; + if( s == 0 ) + { + // achromatic (grey) + rgb.rgb = v; + } + else + { + h /= 60; // sector 0 to 5 + i = floor( h ); + f = h - i; // factorial part of h + p = v * ( 1 - s ); + q = v * ( 1 - s * f ); + t = v * ( 1 - s * ( 1 - f ) ); + if( h < 1) + { + rgb.r = v; + rgb.g = t; + rgb.b = p; + } + else if( h >= 1 && h < 2 ) + { + rgb.r = q; + rgb.g = v; + rgb.b = p; + } + else if( h >= 2 && h < 3 ) + { + rgb.r = p; + rgb.g = v; + rgb.b = t; + } + else if( h >= 3 && h < 4 ) + { + rgb.r = p; + rgb.g = q; + rgb.b = v; + } + else if( h >= 4 && h < 5 ) + { + rgb.r = t; + rgb.g = p; + rgb.b = v; + } + else // if ( h >= 5 ) + { + rgb.r = v; + rgb.g = p; + rgb.b = q; + } + } + return rgb; +} + +// We have to run through this input converter on OpenGL if the +// rest of the shader code is expecting sRGB values +float3 SampleTexture( sampler texSampler, float2 tc ) +{ + float3 c = tex2D( texSampler, tc ).xyz; + + #if ( LINEAR_TO_SRGB ) + { + c = LinearToGamma( c ); + } + #endif + + return c; +} + +// We have to run through this output converter on OpenGL if we +// expect to be writing out sRGB values (since sRGB will be forced on) +float3 OutputColor( float3 result ) +{ + #if ( LINEAR_TO_SRGB ) + { + return GammaToLinear( result ); + } + #endif + + return result; +} + + +float4 main( PS_INPUT i ) : COLOR +{ + float3 result; +#if MODE == 0 + // negative greyscale of scene * gman + float3 scene = SampleTexture( BaseTextureSampler, i.baseTexCoord ); + float3 gman = SampleTexture( BaseTextureSampler2, i.baseTexCoord ); + + float scale = 1.0f / 3.0f; + scene.xyz = dot( float3( scale, scale, scale), scene.xyz ); + scene = float3( 1, 1, 1 ) - scene; + + return FinalOutput( float4( OutputColor( scene * gman ), g_Alpha ), 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE ); +#endif + +#if MODE == 1 + float3 scene = SampleTexture( BaseTextureSampler, i.baseTexCoord ); + float3 gman = SampleTexture( BaseTextureSampler2, i.baseTexCoord ); + float scale = 1.0f / 3.0f; + scene.xyz = dot( float3( scale, scale, scale ), scene.xyz ); + + float gmanLum = dot( float3( scale, scale, scale ), gman ); + if( gmanLum < 0.3 ) + { + result = OutputColor( float3( 1, 1, 1 ) - gman ); + return FinalOutput( float4( result, g_Alpha ), 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE ); + } + else + { + result = OutputColor( ( float3( 1, 1, 1 ) - gman ) * scene ); + return FinalOutput( float4( result, g_Alpha ), 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE ); + } +#endif + +#if MODE == 2 + float3 scene = SampleTexture( BaseTextureSampler, i.baseTexCoord ); + float3 gman = SampleTexture( BaseTextureSampler2, i.baseTexCoord ); + + float startRamp = .2; + float endRamp = .5; + + float scale = 1.0f / 3.0f; + float gmanLum = dot( float3( scale, scale, scale ), gman ); + float sceneLum = dot( float3( scale, scale, scale ), scene ); + + float blend = ( gmanLum - startRamp ) * ( 1.0f / ( endRamp - startRamp ) ); + blend = saturate( blend ); + +// return gmanLum * ( 1.0f - blend ) + scene * blend; + + result = OutputColor( min( gmanLum.xxx, scene ) ); + return FinalOutput( float4( result, g_Alpha ), 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE ); +#endif + +#if MODE == 3 + float3 scene = SampleTexture( BaseTextureSampler, i.baseTexCoord ); + float3 gman = SampleTexture( BaseTextureSampler2, i.baseTexCoord ); + float scale = 1.0f / 3.0f; + float gmanLum = dot( float3( scale, scale, scale ), gman ); + float sceneLum = dot( float3( scale, scale, scale ), scene ); + + float a = 0.0f; + float b = 0.4f; + float c = 0.7f; + float d = 1.0f; + + float blend; + if( gmanLum < b ) + { + blend = ( gmanLum - a ) / ( b - a ); + } + else if( gmanLum > c ) + { + blend = 1.0f - ( ( gmanLum - c) / ( d - c ) ); + } + else + { + blend = 1.0f; + } + + blend = saturate( blend ); + + result = OutputColor( gmanLum.xxx * ( float3( 1, 1, 1 ) - blend.xxx ) + scene * blend.xxx ); + return FinalOutput( float4( result, g_Alpha ), 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE ); +#endif + +#if MODE == 4 + float3 scene = SampleTexture( BaseTextureSampler, i.baseTexCoord ); + float3 gman = SampleTexture( BaseTextureSampler2, i.baseTexCoord ); + float scale = 1.0f / 3.0f; + float gmanLum = dot( float3( scale, scale, scale ), gman ); + float sceneLum = dot( float3( scale, scale, scale ), scene ); + + float a = 0.0f; + float b = 0.4f; + float c = 0.7f; + float d = 1.0f; + + float blend; + if( gmanLum < b ) + { + blend = ( gmanLum - a ) / ( b - a ); + } + else if( gmanLum > c ) + { + blend = 1.0f - ( ( gmanLum - c) / ( d - c ) ); + } + else + { + blend = 1.0f; + } + + blend = saturate( blend ); + + result = OutputColor( gman * ( float3( 1, 1, 1 ) - blend.xxx ) + scene * blend.xxx ); + return FinalOutput( float4( result, g_Alpha ), 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE ); +#endif + +#if MODE == 5 + float3 scene = SampleTexture( BaseTextureSampler, i.baseTexCoord ); + float3 gman = SampleTexture( BaseTextureSampler2, i.baseTexCoord ); + float scale = 1.0f / 3.0f; +// float sceneLum = dot( float3( scale, scale, scale ), scene ); + float sceneLum = scene.r; + + if( sceneLum > 0.0f ) + { + return FinalOutput( float4( OutputColor( scene ), g_Alpha ), 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE ); + } + else + { + float3 hsv = RGBtoHSV( gman ); + +// float blend = saturate( hsv.b - .5 ); + float blend = hsv.b - .5; + + hsv.b *= 1.0f + blend; + hsv.g *= 1.0f - blend; + return FinalOutput( float4( OutputColor( HSVtoRGB( hsv ) ), g_Alpha ), 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE ); + } +#endif + +#if MODE == 6 + float3 scene = SampleTexture( BaseTextureSampler, i.baseTexCoord ); + float3 gman = SampleTexture( BaseTextureSampler2, i.baseTexCoord ); + return FinalOutput( float4( OutputColor( scene + gman ), g_Alpha ), 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE ); +#endif + +#if MODE == 7 + float3 scene = SampleTexture( BaseTextureSampler, i.baseTexCoord ); + return FinalOutput( float4( OutputColor( scene ), g_Alpha ), 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE ); +#endif + +#if MODE == 8 + float3 gman = SampleTexture( BaseTextureSampler2, i.baseTexCoord ); + return FinalOutput( float4( OutputColor( gman ), g_Alpha ), 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE ); +#endif + +#if MODE == 9 + // Fetch textures + float3 cLayer1 = SampleTexture( BaseTextureSampler, i.baseTexCoord.xy ); + float3 cLayer2 = SampleTexture( BaseTextureSampler2, i.baseTexCoord.xy ); + + /* + // Put colors roughly back into gamma space + float3 cGammaLayer1 = pow( cLayer1, 0.454545f ); + float3 cGammaLayer2 = pow( cLayer2, 0.454545f ); + + // Brightness + //float flLayer1Brightness = saturate( dot( cGammaLayer1.rgb, float3( 0.3f, 0.59f, 0.11f ) ) ); + //float flLayer2Brightness = saturate( dot( cGammaLayer2.rgb, float3( 0.3f, 0.59f, 0.11f ) ) ); + float flLayer1Brightness = saturate( dot( cGammaLayer1.rgb, float3( 0.333f, 0.334f, 0.333f ) ) ); + float flLayer2Brightness = saturate( dot( cGammaLayer2.rgb, float3( 0.333f, 0.334f, 0.333f ) ) ); + + // Blend layers in rough gamma space + float3 cGammaOverlayResult; + if ( flLayer1Brightness < 0.5f ) + { + cGammaOverlayResult.rgb = ( 2.0f * cGammaLayer1.rgb * cGammaLayer2.rgb ); + } + else + { + cGammaOverlayResult.rgb = ( 1.0f - ( 2.0f * ( 1.0f - cGammaLayer1.rgb ) * ( 1.0f - cGammaLayer2.rgb ) ) ); + } + + // Convert back to linear space + float3 cLinearOverlayResult = pow( cGammaOverlayResult.rgb, 2.2f ); + //*/ + + float flLayer1Brightness = saturate( dot( cLayer1.rgb, float3( 0.333f, 0.334f, 0.333f ) ) ); + float flLayer2Brightness = saturate( dot( cLayer2.rgb, float3( 0.333f, 0.334f, 0.333f ) ) ); + + // Modify layer 1 to be more contrasty + cLayer1.rgb = saturate( cLayer1.rgb * cLayer1.rgb * 2.0f ); + float3 cLinearOverlayResult = cLayer1.rgb + cLayer2.rgb * saturate( 1.0f - flLayer1Brightness * 2.0f ); + + // Tonemap, fog, etc. + return FinalOutput( float4( OutputColor( cLinearOverlayResult.rgb ), g_Alpha ), 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE ); +#endif +} diff --git a/materialsystem/stdshaders/JellyFish.psh b/materialsystem/stdshaders/JellyFish.psh new file mode 100644 index 0000000..a8c9b92 --- /dev/null +++ b/materialsystem/stdshaders/JellyFish.psh @@ -0,0 +1,17 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; Draw a texture . . woo hoo! +; t0 - texture +; +; The texture coordinates need to be defined as follows: +; tc0 - texcoords +;------------------------------------------------------------------------------ + +; Get the color from the texture +tex t0 +tex t1 + +add r0, t0, t1 +;mov r0, t1 + diff --git a/materialsystem/stdshaders/JellyFish.vsh b/materialsystem/stdshaders/JellyFish.vsh new file mode 100644 index 0000000..0ad7e1a --- /dev/null +++ b/materialsystem/stdshaders/JellyFish.vsh @@ -0,0 +1,82 @@ +vs.1.1 + +# DYNAMIC: "DOWATERFOG" "0..1" +# DYNAMIC: "SKINNING" "0..1" + +#include "macros.vsh" + +;------------------------------------------------------------------------------ +; Vertex blending +;------------------------------------------------------------------------------ + +$cView0 = $SHADER_SPECIFIC_CONST_0; +$cView1 = $SHADER_SPECIFIC_CONST_1; +$cView2 = $SHADER_SPECIFIC_CONST_2; + +&AllocateRegister( \$worldPos ); +&AllocateRegister( \$worldNormal ); +&SkinPositionAndNormal( $worldPos, $worldNormal ); + +;------------------------------------------------------------------------------ +; Transform the position from world to view space +;------------------------------------------------------------------------------ + +&AllocateRegister( \$projPos ); + +dp4 $projPos.x, $worldPos, $cViewProj0 +dp4 $projPos.y, $worldPos, $cViewProj1 +dp4 $projPos.z, $worldPos, $cViewProj2 +dp4 $projPos.w, $worldPos, $cViewProj3 +mov oPos, $projPos + +;------------------------------------------------------------------------------ +; Fog +;------------------------------------------------------------------------------ + +&CalcFog( $worldPos, $projPos ); + +&FreeRegister( \$projPos ); + +&AllocateRegister( \$viewNormal ); + +; Transform the normal from object to view space +dp3 $viewNormal.x, $worldNormal, $cView0 +dp3 $viewNormal.y, $worldNormal, $cView1 +dp3 $viewNormal.z, $worldNormal, $cView2 + +&FreeRegister( \$worldNormal ); +; normalize normal (do we need to do this?) +&Normalize( $viewNormal ); + + +&AllocateRegister( \$viewPos ); + +; Transform position from object to view space +dp4 $viewPos.x, $worldPos, $cView0 +dp4 $viewPos.y, $worldPos, $cView1 +dp4 $viewPos.z, $worldPos, $cView2 + +&FreeRegister( \$worldPos ); +&AllocateRegister( \$vertToEye ); + +; vector from point to eye in view space +mov $vertToEye.xyz, -$viewPos + +&FreeRegister( \$viewPos ); + +; normalize +&Normalize( $vertToEye ); + +dp3 $viewNormal.x, $vertToEye, $viewNormal +add $viewNormal.x, $viewNormal.x, $SHADER_SPECIFIC_CONST_5 ; FIXME + +&FreeRegister( \$vertToEye ); + +;------------------------------------------------------------------------------ +; Texture coordinates +;------------------------------------------------------------------------------ + +mov oT0, $viewNormal +mov oT1, $vTexCoord0 + +&FreeRegister( \$viewNormal ); diff --git a/materialsystem/stdshaders/LightingOnly.vsh b/materialsystem/stdshaders/LightingOnly.vsh new file mode 100644 index 0000000..c0f1b90 --- /dev/null +++ b/materialsystem/stdshaders/LightingOnly.vsh @@ -0,0 +1,40 @@ +vs.1.1 + +# STATIC: "HALF_LAMBERT" "0..1" +# DYNAMIC: "DOWATERFOG" "0..1" +# DYNAMIC: "LIGHT_COMBO" "0..21" +# DYNAMIC: "SKINNING" "0..1" + +#include "macros.vsh" + +;------------------------------------------------------------------------------ +; Vertex blending +;------------------------------------------------------------------------------ +&AllocateRegister( \$worldPos ); +&AllocateRegister( \$worldNormal ); +&SkinPositionAndNormal( $worldPos, $worldNormal ); + +;------------------------------------------------------------------------------ +; Transform the position from model to proj +;------------------------------------------------------------------------------ + +&AllocateRegister( \$projPos ); + +dp4 $projPos.x, $worldPos, $cViewProj0 +dp4 $projPos.y, $worldPos, $cViewProj1 +dp4 $projPos.z, $worldPos, $cViewProj2 +dp4 $projPos.w, $worldPos, $cViewProj3 +mov oPos, $projPos + +&CalcFog( $worldPos, $projPos ); + +&FreeRegister( \$projPos ); + +;------------------------------------------------------------------------------ +; Lighting +;------------------------------------------------------------------------------ +&DoLighting( $worldPos, $worldNormal ); + +&FreeRegister( \$worldPos ); +&FreeRegister( \$worldNormal ); + diff --git a/materialsystem/stdshaders/LightmappedGeneric.psh b/materialsystem/stdshaders/LightmappedGeneric.psh new file mode 100644 index 0000000..6ec78dd --- /dev/null +++ b/materialsystem/stdshaders/LightmappedGeneric.psh @@ -0,0 +1,15 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; Draw a texture . . woo hoo! +; t0 - texture +; +; The texture coordinates need to be defined as follows: +; tc0 - texcoords +;------------------------------------------------------------------------------ + +tex t0 +tex t1 +mul r0, t0, v0 ; base times vertex color (with alpha) +mul r0.rgb, t1, r0 ; fold in lightmap (color only) +mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2) diff --git a/materialsystem/stdshaders/LightmappedGeneric_AddBaseAlphaMaskedEnvMap.psh b/materialsystem/stdshaders/LightmappedGeneric_AddBaseAlphaMaskedEnvMap.psh new file mode 100644 index 0000000..b31054c --- /dev/null +++ b/materialsystem/stdshaders/LightmappedGeneric_AddBaseAlphaMaskedEnvMap.psh @@ -0,0 +1,17 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; Draw a texture . . woo hoo! +; t0 - texture +; +; The texture coordinates need to be defined as follows: +; tc0 - texcoords +; c2 - envmaptint +;------------------------------------------------------------------------------ + +tex t2 ; cube map +tex t3 ; envmap mask + +mul r0.rgb, t2, 1-t3.a +mul r0.rgb, c2, r0 ; apply the envmaptint ++ mul r0.a, c2.a, v0.a diff --git a/materialsystem/stdshaders/LightmappedGeneric_AddEnvMapMaskNoTexture.psh b/materialsystem/stdshaders/LightmappedGeneric_AddEnvMapMaskNoTexture.psh new file mode 100644 index 0000000..ad09a6d --- /dev/null +++ b/materialsystem/stdshaders/LightmappedGeneric_AddEnvMapMaskNoTexture.psh @@ -0,0 +1,17 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; Draw a texture . . woo hoo! +; t0 - texture +; +; The texture coordinates need to be defined as follows: +; tc0 - texcoords +; c2 - envmaptint +;------------------------------------------------------------------------------ + +tex t2 ; cube map +tex t3 ; envmap mask + +mul r0.rgb, t2, t3 +mul r0.rgb, c2, r0 ++ mul r0.a, c2.a, v0.a diff --git a/materialsystem/stdshaders/LightmappedGeneric_AddEnvMapNoTexture.psh b/materialsystem/stdshaders/LightmappedGeneric_AddEnvMapNoTexture.psh new file mode 100644 index 0000000..16b47fe --- /dev/null +++ b/materialsystem/stdshaders/LightmappedGeneric_AddEnvMapNoTexture.psh @@ -0,0 +1,15 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; Draw a texture . . woo hoo! +; t0 - texture +; +; The texture coordinates need to be defined as follows: +; tc0 - texcoords +; c2 - envmaptint +;------------------------------------------------------------------------------ + +tex t2 ; cube map + +mul r0.rgb, t2, c2 ++ mul r0.a, v0.a, c2.a diff --git a/materialsystem/stdshaders/LightmappedGeneric_BaseAlphaMaskedEnvMapV2.psh b/materialsystem/stdshaders/LightmappedGeneric_BaseAlphaMaskedEnvMapV2.psh new file mode 100644 index 0000000..c8279e7 --- /dev/null +++ b/materialsystem/stdshaders/LightmappedGeneric_BaseAlphaMaskedEnvMapV2.psh @@ -0,0 +1,22 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; Draw a texture . . woo hoo! +; t0 - texture +; +; The texture coordinates need to be defined as follows: +; tc0 - texcoords +; c1 - self-illum tint +; c2 - envmap tint +;------------------------------------------------------------------------------ + +tex t0 +tex t1 +tex t2 +tex t3 + +mul r0, t0, v0 ; base times vertex color (with alpha) +mul r0.rgb, t1, r0 ; fold in lighting (color only) +mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2) +mul r1, t2, 1-t3.a ; envmap * envmapmask (alpha) +mad r0.rgb, r1, c2, r0 ; + envmap * envmapmask * envmaptint (color only) diff --git a/materialsystem/stdshaders/LightmappedGeneric_BaseTexture.psh b/materialsystem/stdshaders/LightmappedGeneric_BaseTexture.psh new file mode 100644 index 0000000..0401218 --- /dev/null +++ b/materialsystem/stdshaders/LightmappedGeneric_BaseTexture.psh @@ -0,0 +1,14 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; Draw a texture . . woo hoo! +; t0 - texture +; +; The texture coordinates need to be defined as follows: +; tc0 - texcoords +;------------------------------------------------------------------------------ + +; Get the color from the texture +tex t0 +mul r0, t0, c0 + diff --git a/materialsystem/stdshaders/LightmappedGeneric_BaseTexture.vsh b/materialsystem/stdshaders/LightmappedGeneric_BaseTexture.vsh new file mode 100644 index 0000000..6cef1e5 --- /dev/null +++ b/materialsystem/stdshaders/LightmappedGeneric_BaseTexture.vsh @@ -0,0 +1,38 @@ +vs.1.1 + +# DYNAMIC: "DOWATERFOG" "0..1" + +#include "macros.vsh" + +;------------------------------------------------------------------------------ +; Vertex blending +;------------------------------------------------------------------------------ + +&AllocateRegister( \$projPos ); + +dp4 $projPos.x, $vPos, $cModelViewProj0 +dp4 $projPos.y, $vPos, $cModelViewProj1 +dp4 $projPos.z, $vPos, $cModelViewProj2 +dp4 $projPos.w, $vPos, $cModelViewProj3 +mov oPos, $projPos + +alloc $worldPos +if( $DOWATERFOG == 1 ) +{ + ; Get the worldpos z component only since that's all we need for height fog + dp4 $worldPos.z, $vPos, $cModel2 +} +&CalcFog( $worldPos, $projPos ); +free $worldPos + +&FreeRegister( \$projPos ); + +;------------------------------------------------------------------------------ +; Texture coordinates +;------------------------------------------------------------------------------ + +dp4 oT0.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_0 +dp4 oT0.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_1 + + + diff --git a/materialsystem/stdshaders/LightmappedGeneric_BaseTextureBlend.vsh b/materialsystem/stdshaders/LightmappedGeneric_BaseTextureBlend.vsh new file mode 100644 index 0000000..8eea421 --- /dev/null +++ b/materialsystem/stdshaders/LightmappedGeneric_BaseTextureBlend.vsh @@ -0,0 +1,43 @@ +vs.1.1 + +# DYNAMIC: "DOWATERFOG" "0..1" + +#include "macros.vsh" + +;------------------------------------------------------------------------------ +; Vertex blending +;------------------------------------------------------------------------------ + +&AllocateRegister( \$projPos ); + +dp4 $projPos.x, $vPos, $cModelViewProj0 +dp4 $projPos.y, $vPos, $cModelViewProj1 +dp4 $projPos.z, $vPos, $cModelViewProj2 +dp4 $projPos.w, $vPos, $cModelViewProj3 +mov oPos, $projPos + +alloc $worldPos +if( $DOWATERFOG == 1 ) +{ + ; Get the worldpos z component only since that's all we need for height fog + dp4 $worldPos.z, $vPos, $cModel2 +} +&CalcFog( $worldPos, $projPos ); +free $worldPos + +&FreeRegister( \$projPos ); + +;------------------------------------------------------------------------------ +; Texture coordinates +;------------------------------------------------------------------------------ + +dp4 oT0.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_0 +dp4 oT0.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_1 + +dp4 oT1.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_2 +dp4 oT1.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_3 + +mov oT2, $vTexCoord1 + +; Now the basetexture/basetexture2 blend uses vertex color, so send it into the psh. +mov oD0, $vColor diff --git a/materialsystem/stdshaders/LightmappedGeneric_BumpmappedEnvmap.psh b/materialsystem/stdshaders/LightmappedGeneric_BumpmappedEnvmap.psh new file mode 100644 index 0000000..6f06127 --- /dev/null +++ b/materialsystem/stdshaders/LightmappedGeneric_BumpmappedEnvmap.psh @@ -0,0 +1,66 @@ +; STATIC: "NORMALMAPALPHAENVMAPMASK" "0..1" +ps.1.1 + +;------------------------------------------------------------------------------ +; Environment mapping on a bumped surface +; t0 - Normalmap +; t3 - Cube environment map (*must* be a cube map!) +; +; c0 - color to multiply the results by +; c1 - envmap contrast +; c2 - envmap saturation +; c3 - grey weights +; c4 - fresnel amount +; Input texture coords required here are a little wonky. +; tc0.uv <- U,V into the normal map +; tc1.uvw, tc2.uvw, tc3.uvw <- 3x3 matrix transform +; from tangent space->env map space +; tc1.q, tc2.q, tc3.q <- eye vector in env map space +;------------------------------------------------------------------------------ + +; Get the 3-vector from the normal map +tex t0 + +; Perform matrix multiply to get a local normal bump. Then +; reflect the eye vector through the normal and sample from +; a cubic environment map. +texm3x3pad t1, t0_bx2 +texm3x3pad t2, t0_bx2 +texm3x3vspec t3, t0_bx2 + +; FIXME FIXME - Need to do specialized versions of this with and without: +; - constant color +; - fresnel amount of exactly 0 or 1 or in between +; - envmap contrast of 0, 1, or in between +; - envmap saturation of 0, 1, or in between + +; r0 = constant color * result of bump into envmap +mul r0.rgb, t3, c0 + +; dot eye-vector with per-pixel normal from t0 +dp3_sat r1, v0_bx2, t0_bx2 + +; run Fresnel approx. on it: R0 + (1-R0) (1-cos(q))^5 in alpha channel +mul r1.rgb, r0, r0 ; color squared ++mul r0.a, 1-r1.a, 1-r1.a ; squared + +lrp r0.rgb, c1, r1, r0 ; blend between color and color * color ++mul r0.a, r0.a, r0.a ; quartic + +dp3 r1.rgb, r0, c3 ; color greyscaled ++mul r0.a, r0.a, 1-r1.a ; quintic + +; FIXME - these should be able to pair (I think), but don't on nvidia for some reason. +; (I think) cannot pair due to use of >2 constants in single stage +lrp r0.rgb, c2, r0, r1 ; blend between color and greyscale +mad r0.a, r0.a, c6.a, c4.a ; Take Fresnel R(0) into consideration + +mul r0.rgb, r0, r0.a ; multiply output color by result of fresnel calc + +#if NORMALMAPALPHAENVMAPMASK ++mul r0.a, c0.a, t0.a ; Fade amount * alpha from the texture +#else ++mov r0.a, c0.a ; Just use the fade amount +#endif + + diff --git a/materialsystem/stdshaders/LightmappedGeneric_BumpmappedEnvmap.vsh b/materialsystem/stdshaders/LightmappedGeneric_BumpmappedEnvmap.vsh new file mode 100644 index 0000000..73769dc --- /dev/null +++ b/materialsystem/stdshaders/LightmappedGeneric_BumpmappedEnvmap.vsh @@ -0,0 +1,96 @@ +vs.1.1 + +# DYNAMIC: "DOWATERFOG" "0..1" + +;------------------------------------------------------------------------------ +; Shader specific constant: +; $SHADER_SPECIFIC_CONST_5 = [sOffset, tOffset, 0, 0] +;------------------------------------------------------------------------------ + +#include "macros.vsh" + +;------------------------------------------------------------------------------ +; Vertex blending +;------------------------------------------------------------------------------ + +&AllocateRegister( \$worldPos ); + +; Transform position from object to world +dp4 $worldPos.x, $vPos, $cModel0 +dp4 $worldPos.y, $vPos, $cModel1 +dp4 $worldPos.z, $vPos, $cModel2 + +&AllocateRegister( \$projPos ); + +; Transform position from object to projection space +dp4 $projPos.x, $vPos, $cModelViewProj0 +dp4 $projPos.y, $vPos, $cModelViewProj1 +dp4 $projPos.z, $vPos, $cModelViewProj2 +dp4 $projPos.w, $vPos, $cModelViewProj3 + +mov oPos, $projPos + +;------------------------------------------------------------------------------ +; Fog +;------------------------------------------------------------------------------ +&CalcFog( $worldPos, $projPos ); + +&FreeRegister( \$projPos ); + +;------------------------------------------------------------------------------ +; Lighting +;------------------------------------------------------------------------------ + +; Transform tangent space basis vectors to env map space (world space) +; This will produce a set of vectors mapping from tangent space to env space +; We'll use this to transform normals from the normal map from tangent space +; to environment map space. +; NOTE: use dp3 here since the basis vectors are vectors, not points + +dp3 oT1.x, $vTangentS, $cModel0 +dp3 oT2.x, $vTangentS, $cModel1 +dp3 oT3.x, $vTangentS, $cModel2 + +dp3 oT1.y, $vTangentT, $cModel0 +dp3 oT2.y, $vTangentT, $cModel1 +dp3 oT3.y, $vTangentT, $cModel2 + +dp3 oT1.z, $vNormal, $cModel0 +dp3 oT2.z, $vNormal, $cModel1 +dp3 oT3.z, $vNormal, $cModel2 + +; Compute the vector from vertex to camera +&AllocateRegister( \$worldEyeVect ); +sub $worldEyeVect.xyz, $cEyePos, $worldPos +&FreeRegister( \$worldPos ); + +; Move it into the w component of the texture coords, as the wacky +; pixel shader wants it there. +mov oT1.w, $worldEyeVect.x +mov oT2.w, $worldEyeVect.y +mov oT3.w, $worldEyeVect.z + +alloc $tangentEyeVect + +; transform the eye vector to tangent space +dp3 $tangentEyeVect.x, $worldEyeVect, $vTangentS +dp3 $tangentEyeVect.y, $worldEyeVect, $vTangentT +dp3 $tangentEyeVect.z, $worldEyeVect, $vNormal + +&FreeRegister( \$worldEyeVect ); + +&Normalize( $tangentEyeVect ); + +; stick the tangent space eye vector into oD0 +mad oD0.xyz, $tangentEyeVect, $cHalf, $cHalf + +&FreeRegister( \$tangentEyeVect ); + +;------------------------------------------------------------------------------ +; Texture coordinates +;------------------------------------------------------------------------------ +dp4 oT0.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_0 +dp4 oT0.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_1 + + + diff --git a/materialsystem/stdshaders/LightmappedGeneric_BumpmappedEnvmap_ps14.psh b/materialsystem/stdshaders/LightmappedGeneric_BumpmappedEnvmap_ps14.psh new file mode 100644 index 0000000..dbd03fa --- /dev/null +++ b/materialsystem/stdshaders/LightmappedGeneric_BumpmappedEnvmap_ps14.psh @@ -0,0 +1,72 @@ +; STATIC: "NORMALMAPALPHAENVMAPMASK" "0..1" +ps.1.4 +;------------------------------------------------------------------------------ +; Phase 1 +;------------------------------------------------------------------------------ +; Get the 3-vector from the normal map +texld r0, t0 +; Get environment matrix +texcrd r1.rgb, t1 +texcrd r2.rgb, t2 +texcrd r3.rgb, t3 +; Normalize eye-ray vector through normalizer cube map +texld r4, t4 ; <---- CUBE MAP here!!! +;mov r0.rgba, r4 + +; Transform normal +dp3 r5.r, r1, r0_bx2 +dp3 r5.g, r2, r0_bx2 +dp3 r5.b, r3, r0_bx2 +; Reflection calculatiom +dp3_x2 r3.rgb, r5, r4_bx2 ; 2(N.Eye) +mul r3.rgb, r5, r3 ; 2N(N.Eye) +dp3 r2.rgb, r5, r5 ; N.N +mad r2.rgb, -r4_bx2, r2, r3 ; 2N(N.Eye) - Eye(N.N) + +#if NORMALMAPALPHAENVMAPMASK +; Alpha gets lost after phase marker, so store it here +mov r5, r0.a +#endif + +;------------------------------------------------------------------------------ +; Phase 2 +;------------------------------------------------------------------------------ +; What's left over from the last phase: +; r0 - normal +; r1 - free +; r2 - vector to sample in envmap +; r3 - free +; r4 - normal +; r5 - normal map alpha (rgba) + +phase + +; Sample environment map +texld r3, r2 + +; dot eye-vector with per-pixel normal from r0 +dp3_sat r1, v0_bx2, r0_bx2 + +; Result goes in output color (multiply by constant color c0) +mul r0.rgb, r3, c0 + +; run Fresnel approx. on it: R0 + (1-R0) (1-cos(q))^5 in alpha channel +mul r1.rgb, r0, r0 ++mul r0.a, 1-r1.a, 1-r1.a ; squared + +lrp r0.rgb, c1, r1, r0 ; blend between color and color * color ++mul r0.a, r0.a, r0.a ; quartic + +dp3 r1.rgb, r0, c3 ++mul r0.a, r0.a, 1-r1.a ; quintic + +lrp r0.rgb, c2, r0, r1 ; blend between color and greyscale +mad r0.a, r0.a, c6.a, c4.a ; Take Fresnel R(0) into consideration + +mul r0.rgb, r0, r0.a ; multiply output color by result of fresnel calc + +#if NORMALMAPALPHAENVMAPMASK ++mul r0.a, c0.a, r5.r ; Fade amount * alpha from the texture +#else ++mov r0.a, c0.a ; Just use the fade amount +#endif diff --git a/materialsystem/stdshaders/LightmappedGeneric_BumpmappedEnvmap_ps14.vsh b/materialsystem/stdshaders/LightmappedGeneric_BumpmappedEnvmap_ps14.vsh new file mode 100644 index 0000000..ea0f143 --- /dev/null +++ b/materialsystem/stdshaders/LightmappedGeneric_BumpmappedEnvmap_ps14.vsh @@ -0,0 +1,92 @@ +vs.1.1 + +# DYNAMIC: "DOWATERFOG" "0..1" + +;------------------------------------------------------------------------------ +; Shader specific constant: +; $SHADER_SPECIFIC_CONST_5 = [sOffset, tOffset, 0, 0] +;------------------------------------------------------------------------------ + +#include "macros.vsh" + +;------------------------------------------------------------------------------ +; Vertex blending +;------------------------------------------------------------------------------ + +&AllocateRegister( \$worldPos ); + +; Transform position from object to world +dp4 $worldPos.x, $vPos, $cModel0 +dp4 $worldPos.y, $vPos, $cModel1 +dp4 $worldPos.z, $vPos, $cModel2 + +&AllocateRegister( \$projPos ); + +; Transform position from object to projection space +dp4 $projPos.x, $vPos, $cModelViewProj0 +dp4 $projPos.y, $vPos, $cModelViewProj1 +dp4 $projPos.z, $vPos, $cModelViewProj2 +dp4 $projPos.w, $vPos, $cModelViewProj3 + +mov oPos, $projPos + +;------------------------------------------------------------------------------ +; Fog +;------------------------------------------------------------------------------ + +&CalcFog( $worldPos, $projPos ); + +&FreeRegister( \$projPos ); + +;------------------------------------------------------------------------------ +; Lighting +;------------------------------------------------------------------------------ + +; Transform tangent space basis vectors to env map space (world space) +; This will produce a set of vectors mapping from tangent space to env space +; We'll use this to transform normals from the normal map from tangent space +; to environment map space. +; NOTE: use dp3 here since the basis vectors are vectors, not points + +dp3 oT1.x, $vTangentS, $cModel0 +dp3 oT2.x, $vTangentS, $cModel1 +dp3 oT3.x, $vTangentS, $cModel2 + +dp3 oT1.y, $vTangentT, $cModel0 +dp3 oT2.y, $vTangentT, $cModel1 +dp3 oT3.y, $vTangentT, $cModel2 + +dp3 oT1.z, $vNormal, $cModel0 +dp3 oT2.z, $vNormal, $cModel1 +dp3 oT3.z, $vNormal, $cModel2 + +; Compute the vector from vertex to camera +&AllocateRegister( \$worldEyeVect ); +sub $worldEyeVect.xyz, $cEyePos, $worldPos +&FreeRegister( \$worldPos ); + +; eye vector +mov oT4.xyz, $worldEyeVect + +alloc $tangentEyeVect + +; transform the eye vector to tangent space +dp3 $tangentEyeVect.x, $worldEyeVect, $vTangentS +dp3 $tangentEyeVect.y, $worldEyeVect, $vTangentT +dp3 $tangentEyeVect.z, $worldEyeVect, $vNormal + +&FreeRegister( \$worldEyeVect ); + +&Normalize( $tangentEyeVect ); + +; stick the tangent space eye vector into oD0 +mad oD0.xyz, $tangentEyeVect, $cHalf, $cHalf + +&FreeRegister( \$tangentEyeVect ); + +;------------------------------------------------------------------------------ +; Texture coordinates +;------------------------------------------------------------------------------ +dp4 oT0.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_0 +dp4 oT0.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_1 + diff --git a/materialsystem/stdshaders/LightmappedGeneric_BumpmappedLightmap.psh b/materialsystem/stdshaders/LightmappedGeneric_BumpmappedLightmap.psh new file mode 100644 index 0000000..82b83a4 --- /dev/null +++ b/materialsystem/stdshaders/LightmappedGeneric_BumpmappedLightmap.psh @@ -0,0 +1,79 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; Computes the diffuse component of lighting using lightmap + bumpmap +; t0 - Normalmap +; t1 - Lightmap1 +; t2 - Lightmap2 +; t3 - Lightmap3 +; +; The texture coordinates need to be defined as follows: +; tc0 - Normalmap and lightmap texture coordinates +; c0, c1, c2 - Axes of the lightmap coordinate system in tangent space +;------------------------------------------------------------------------------ + +; Get the 3-vector from the normal map +tex t0 + +; Sample the lightmaps +tex t1 +tex t2 +tex t3 + +; output = lightmapColor[0] * ( ( N dot basis[0] )^2 ) + +; lightmapColor[1] * ( ( N dot basis[1] )^2 ) + +; lightmapColor[2] * ( ( N dot basis[2] )^2 ) + + +; r0 = ( N dot basis[0] ) +; don't "_sat" here so that everything adds up to one even if the normal is outside of the basis!!!!! +dp3 r0, t0_bx2, c0 + +; r1 = ( N dot basis[1] ) +dp3 r1, t0_bx2, c1 + +;---- +; r0 = ( N dot basis[0] ) +; r1 = ( N dot basis[1] ) +;---- + +; r0.rgb = ( N dot basis[0] )^2 +mul r0.rgb, r0, r0 + +; r1.a = ( N dot basis[1] )^2 ++mul r1.a, r1, r1 + +;---- +; r0.rgb = ( N dot basis[0] )^2 +; r1.a = ( N dot basis[1] )^2 +;---- + +mul t1, r0, t1 + +;---- +; r1.a = ( N dot basis[1] )^2 +; t1 = lightmapColor[0] * ( N dot basis[0] )^2 +;---- + +dp3 r0, t0_bx2, c2 + +;---- +; r1.a = ( N dot basis[1] )^2 +; t1 = lightmapColor[0] * ( N dot basis[0] )^2 +; r0 = ( N dot basis[2] ) +;---- + +mad t1.rgb, r1.a, t2, t1 ++mul r0.a, r0, r0 + +;---- +; t1.rgb = lightmapColor[0] * ( N dot basis[0] )^2 + lightmapColor[1] * ( N dot basis[1] )^2 +; r0.a = ( N dot basis[2] )^2 +;---- + +mad r0.rgba, r0.a, t3, t1 + +;---- +; r0.rgb = lightmapColor[0] * ( N dot basis[0] )^2 + +; lightmapColor[1] * ( N dot basis[1] )^2 + +; lightmapColor[2] * ( N dot basis[2] )^2 +;---- diff --git a/materialsystem/stdshaders/LightmappedGeneric_BumpmappedLightmap.vsh b/materialsystem/stdshaders/LightmappedGeneric_BumpmappedLightmap.vsh new file mode 100644 index 0000000..229a839 --- /dev/null +++ b/materialsystem/stdshaders/LightmappedGeneric_BumpmappedLightmap.vsh @@ -0,0 +1,54 @@ +vs.1.1 + +# DYNAMIC: "DOWATERFOG" "0..1" + +#include "macros.vsh" + +;------------------------------------------------------------------------------ +; Vertex blending +;------------------------------------------------------------------------------ + +&AllocateRegister( \$projPos ); + +; Transform position from object to projection space +dp4 $projPos.x, $vPos, $cModelViewProj0 +dp4 $projPos.y, $vPos, $cModelViewProj1 +dp4 $projPos.z, $vPos, $cModelViewProj2 +dp4 $projPos.w, $vPos, $cModelViewProj3 + +mov oPos, $projPos + +;------------------------------------------------------------------------------ +; Fog +;------------------------------------------------------------------------------ + +alloc $worldPos +if( $DOWATERFOG == 1 ) +{ + ; Get the worldpos z component only since that's all we need for height fog + dp4 $worldPos.z, $vPos, $cModel2 +} +&CalcFog( $worldPos, $projPos ); +free $worldPos + +&FreeRegister( \$projPos ); + +;------------------------------------------------------------------------------ +; Texture coordinates +;------------------------------------------------------------------------------ + +; Compute the texture coordinates given the offset between +; each bumped lightmap +&AllocateRegister( \$offset ); +mov $offset.xy, $vTexCoord2 +dp4 oT0.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_0 +dp4 oT0.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_1 +add oT1.xy, $offset, $vTexCoord1 +mad oT2.xy, $offset, $cTwo, $vTexCoord1 +; make a 3 +alloc $three +add $three, $cOne, $cTwo +mad oT3.xy, $offset, $three, $vTexCoord1 +free $three + +&FreeRegister( \$offset ); diff --git a/materialsystem/stdshaders/LightmappedGeneric_BumpmappedLightmap_base_ps14.psh b/materialsystem/stdshaders/LightmappedGeneric_BumpmappedLightmap_base_ps14.psh new file mode 100644 index 0000000..4756b5b --- /dev/null +++ b/materialsystem/stdshaders/LightmappedGeneric_BumpmappedLightmap_base_ps14.psh @@ -0,0 +1,39 @@ +;------------------------------------------------------------------------------ +; Computes the diffuse component of lighting using lightmap + bumpmap +; t0 - Normalmap +; t1 - Lightmap1 +; t2 - Lightmap2 +; t3 - Lightmap3 +; t4 - Base +; +; The texture coordinates need to be defined as follows: +; tc0 - Normalmap and lightmap texture coordinates +; c0, c1, c2 - Axes of the lightmap coordinate system in tangent space +;------------------------------------------------------------------------------ +ps.1.4 + +; Get the 3-vector from the normal map +texld r0, t0 + +; Sample the lightmaps +texld r1, t1 +texld r2, t2 +texld r3, t3 + +; Sample the base texture +texld r4, t4 + +; output = (lightmapColor[0] * ( ( N dot basis[0] )^2 ) + +; lightmapColor[1] * ( ( N dot basis[1] )^2 ) + +; lightmapColor[2] * ( ( N dot basis[2] )^2 ) ) * base + +dp3 r5.r, r0_bx2, c0 +dp3 r5.g, r0_bx2, c1 +dp3 r5.b, r0_bx2, c2 +mul r5.rgb, r5, r5 +mul r1, r1, r5.r +mad r1, r2, r5.g, r1 +mad r1, r3, r5.g, r1 + +; assume overbright_2 !!! +mul_x2 r0, r1, r4 diff --git a/materialsystem/stdshaders/LightmappedGeneric_BumpmappedLightmap_base_ps14.vsh b/materialsystem/stdshaders/LightmappedGeneric_BumpmappedLightmap_base_ps14.vsh new file mode 100644 index 0000000..a78d085 --- /dev/null +++ b/materialsystem/stdshaders/LightmappedGeneric_BumpmappedLightmap_base_ps14.vsh @@ -0,0 +1,55 @@ +vs.1.1 + +# DYNAMIC: "DOWATERFOG" "0..1" + +#include "macros.vsh" + +;------------------------------------------------------------------------------ +; Vertex blending +;------------------------------------------------------------------------------ + +&AllocateRegister( \$projPos ); + +; Transform position from object to projection space +dp4 $projPos.x, $vPos, $cModelViewProj0 +dp4 $projPos.y, $vPos, $cModelViewProj1 +dp4 $projPos.z, $vPos, $cModelViewProj2 +dp4 $projPos.w, $vPos, $cModelViewProj3 + +mov oPos, $projPos + +;------------------------------------------------------------------------------ +; Fog +;------------------------------------------------------------------------------ + +alloc $worldPos +if( $DOWATERFOG == 1 ) +{ + ; Get the worldpos z component only since that's all we need for height fog + dp4 $worldPos.z, $vPos, $cModel2 +} +&CalcFog( $worldPos, $projPos ); +free $worldPos + +&FreeRegister( \$projPos ); + +;------------------------------------------------------------------------------ +; Texture coordinates +;------------------------------------------------------------------------------ + +; Compute the texture coordinates given the offset between +; each bumped lightmap +&AllocateRegister( \$offset ); +mov $offset.xy, $vTexCoord2 +dp4 oT0.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_0 +dp4 oT0.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_1 +add oT1.xy, $offset, $vTexCoord1 +mad oT2.xy, $offset, $cTwo, $vTexCoord1 +alloc $three +add $three, $cOne, $cTwo +mad oT3.xy, $offset, $three, $vTexCoord1 +free $three +dp4 oT4.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_2 +dp4 oT4.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_3 + +&FreeRegister( \$offset ); diff --git a/materialsystem/stdshaders/LightmappedGeneric_BumpmappedLightmap_blend_ps14.psh b/materialsystem/stdshaders/LightmappedGeneric_BumpmappedLightmap_blend_ps14.psh new file mode 100644 index 0000000..2b43ee3 --- /dev/null +++ b/materialsystem/stdshaders/LightmappedGeneric_BumpmappedLightmap_blend_ps14.psh @@ -0,0 +1,47 @@ +;------------------------------------------------------------------------------ +; Computes the diffuse component of lighting using lightmap + bumpmap +; t0 - Normalmap +; t1 - Lightmap1 +; t2 - Lightmap2 +; t3 - Lightmap3 +; t4 - Base1 +; t5 - Base2 +; +; The texture coordinates need to be defined as follows: +; tc0 - Normalmap and lightmap texture coordinates +; c0, c1, c2 - Axes of the lightmap coordinate system in tangent space +;------------------------------------------------------------------------------ +ps.1.4 + +; output = (lightmapColor[0] * ( ( N dot basis[0] )^2 ) + +; lightmapColor[1] * ( ( N dot basis[1] )^2 ) + +; lightmapColor[2] * ( ( N dot basis[2] )^2 ) ) * lerp(base1, base2, lightmapColor[0].a) + +; Get the 3-vector from the normal map +texld r0, t0 + +dp3 r5.r, r0_bx2, c0 +dp3 r5.g, r0_bx2, c1 +dp3 r5.b, r0_bx2, c2 +mul r5.rgb, r5, r5 + +phase + +; Sample the lightmaps +texld r1, t1 +texld r2, t2 +texld r3, t3 + +; Sample the base textures +texld r4, t4 +texld r5, t5 + +mul r1, r1, r5.r +mad r1, r2, r5.g, r1 +mad r1, r3, r5.g, r1 + +; blend base textures +lrp r4, r4, r5, r1.a + +; assume overbright_2 !!! +mul_x2 r0, r1, r4 diff --git a/materialsystem/stdshaders/LightmappedGeneric_BumpmappedLightmap_blend_ps14.vsh b/materialsystem/stdshaders/LightmappedGeneric_BumpmappedLightmap_blend_ps14.vsh new file mode 100644 index 0000000..7773d33 --- /dev/null +++ b/materialsystem/stdshaders/LightmappedGeneric_BumpmappedLightmap_blend_ps14.vsh @@ -0,0 +1,57 @@ +vs.1.1 + +# DYNAMIC: "DOWATERFOG" "0..1" + +#include "macros.vsh" + +;------------------------------------------------------------------------------ +; Vertex blending +;------------------------------------------------------------------------------ + +&AllocateRegister( \$projPos ); + +; Transform position from object to projection space +dp4 $projPos.x, $vPos, $cModelViewProj0 +dp4 $projPos.y, $vPos, $cModelViewProj1 +dp4 $projPos.z, $vPos, $cModelViewProj2 +dp4 $projPos.w, $vPos, $cModelViewProj3 + +mov oPos, $projPos + +;------------------------------------------------------------------------------ +; Fog +;------------------------------------------------------------------------------ + +alloc $worldPos +if( $DOWATERFOG == 1 ) +{ + ; Get the worldpos z component only since that's all we need for height fog + dp4 $worldPos.z, $vPos, $cModel2 +} +&CalcFog( $worldPos, $projPos ); +free $worldPos + +&FreeRegister( \$projPos ); + +;------------------------------------------------------------------------------ +; Texture coordinates +;------------------------------------------------------------------------------ + +; Compute the texture coordinates given the offset between +; each bumped lightmap +&AllocateRegister( \$offset ); +mov $offset.xy, $vTexCoord2 +dp4 oT0.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_0 +dp4 oT0.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_1 +add oT1.xy, $offset, $vTexCoord1 +mad oT2.xy, $offset, $cTwo, $vTexCoord1 +alloc $three +add $three, $cOne, $cTwo +mad oT3.xy, $offset, $three, $vTexCoord1 +free $three +dp4 oT4.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_2 +dp4 oT4.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_3 +dp4 oT5.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_4 +dp4 oT5.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_5 + +&FreeRegister( \$offset ); diff --git a/materialsystem/stdshaders/LightmappedGeneric_Decal.psh b/materialsystem/stdshaders/LightmappedGeneric_Decal.psh new file mode 100644 index 0000000..0198420 --- /dev/null +++ b/materialsystem/stdshaders/LightmappedGeneric_Decal.psh @@ -0,0 +1,47 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; Computes the diffuse component of lighting using lightmap + bumpmap +; t0 - decal texture +; t1 - Lightmap1 +; t2 - Lightmap2 +; t3 - Lightmap3 +; +; The texture coordinates need to be defined as follows: +; tc0 - Normalmap and lightmap texture coordinates +; c0, c1, c2 - ( ( N dot basis[0] )^2 ), ( ( N dot basis[1] )^2 ), ( ( N dot basis[2] )^2 ) +;------------------------------------------------------------------------------ + +; Get the decal color +tex t0 + +; Sample the lightmaps +tex t1 +tex t2 +tex t3 + +; output = lightmapColor[0] * ( ( N dot basis[0] )^2 ) + +; lightmapColor[1] * ( ( N dot basis[1] )^2 ) + +; lightmapColor[2] * ( ( N dot basis[2] )^2 ) + + +; r0 = lightmapColor[0] * ( ( N dot basis[0] )^2 ) +mul r0, t1, c0 + +; r0 = lightmapColor[0] * ( ( N dot basis[0] )^2 ) + lightmapColor[1] * ( ( N dot basis[1] )^2 ) +mad r0, t2, c1, r0 + +; r0 = lightmapColor[0] * ( ( N dot basis[0] )^2 ) + +; lightmapColor[1] * ( ( N dot basis[1] )^2 ) + +; lightmapColor[2] * ( ( N dot basis[2] )^2 ) +mad r0, t3, c2, r0 + +; Modulate by decal texture +mul r0.rgb, r0, t0 ++ mov r0.a, t0.a + +; Modulate by constant color +mul r0, r0, c3 + +; Modulate by per-vertex factor +mul r0, r0, v0 + diff --git a/materialsystem/stdshaders/LightmappedGeneric_Decal.vsh b/materialsystem/stdshaders/LightmappedGeneric_Decal.vsh new file mode 100644 index 0000000..a9db9fa --- /dev/null +++ b/materialsystem/stdshaders/LightmappedGeneric_Decal.vsh @@ -0,0 +1,56 @@ +vs.1.1 + +# DYNAMIC: "DOWATERFOG" "0..1" + +#include "macros.vsh" + +;------------------------------------------------------------------------------ +; Vertex blending +;------------------------------------------------------------------------------ + +&AllocateRegister( \$projPos ); + +; Transform position from object to projection space +dp4 $projPos.x, $vPos, $cModelViewProj0 +dp4 $projPos.y, $vPos, $cModelViewProj1 +dp4 $projPos.z, $vPos, $cModelViewProj2 +dp4 $projPos.w, $vPos, $cModelViewProj3 + +mov oPos, $projPos + +;------------------------------------------------------------------------------ +; Fog +;------------------------------------------------------------------------------ + +alloc $worldPos +if( $DOWATERFOG == 1 ) +{ + ; Get the worldpos z component only since that's all we need for height fog + dp4 $worldPos.z, $vPos, $cModel2 +} +&CalcFog( $worldPos, $projPos ); +free $worldPos + +&FreeRegister( \$projPos ); + +;------------------------------------------------------------------------------ +; Texture coordinates +;------------------------------------------------------------------------------ + +; Compute the texture coordinates given the offset between +; each bumped lightmap +&AllocateRegister( \$offset ); +mov $offset.x, $vTexCoord2.x +mov $offset.y, $cZero +dp4 oT0.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_0 +dp4 oT0.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_1 +add oT1.xy, $offset, $vTexCoord1 +mad oT2.xy, $offset, $cTwo, $vTexCoord1 +; make a 3 +alloc $three +add $three, $cOne, $cTwo +mad oT3.xy, $offset, $three, $vTexCoord1 +free $three +mov oD0, $vColor + +&FreeRegister( \$offset ); diff --git a/materialsystem/stdshaders/LightmappedGeneric_Detail.psh b/materialsystem/stdshaders/LightmappedGeneric_Detail.psh new file mode 100644 index 0000000..4e3625f --- /dev/null +++ b/materialsystem/stdshaders/LightmappedGeneric_Detail.psh @@ -0,0 +1,18 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; Draw a texture . . woo hoo! +; t0 - texture +; +; The texture coordinates need to be defined as follows: +; tc0 - texcoords +;------------------------------------------------------------------------------ + +tex t0 +tex t1 +tex t2 +mul r0, t0, v0 ; base times vertex color (with alpha) +mul r0.rgb, t1, r0 ; fold in lightmap (color only) +mul_x2 r1.rgb, r0, t2 ; detail texture +lrp r0.rgb, c2, r1, r0 +mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2) diff --git a/materialsystem/stdshaders/LightmappedGeneric_DetailNoTexture.psh b/materialsystem/stdshaders/LightmappedGeneric_DetailNoTexture.psh new file mode 100644 index 0000000..a1d6c4e --- /dev/null +++ b/materialsystem/stdshaders/LightmappedGeneric_DetailNoTexture.psh @@ -0,0 +1,16 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; Draw a texture . . woo hoo! +; t0 - texture +; +; The texture coordinates need to be defined as follows: +; tc0 - texcoords +;------------------------------------------------------------------------------ + +tex t1 +tex t2 +mul r0.rgb, t1, v0 + ; base times vertex color (with alpha) +mov r0.a, v0.a +mul_x2 r0.rgb, r0, t2 ; detail texture +mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2) diff --git a/materialsystem/stdshaders/LightmappedGeneric_DetailSelfIlluminated.psh b/materialsystem/stdshaders/LightmappedGeneric_DetailSelfIlluminated.psh new file mode 100644 index 0000000..575585b --- /dev/null +++ b/materialsystem/stdshaders/LightmappedGeneric_DetailSelfIlluminated.psh @@ -0,0 +1,23 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; Draw a texture . . woo hoo! +; t0 - texture +; +; The texture coordinates need to be defined as follows: +; tc0 - texcoords +;------------------------------------------------------------------------------ + +tex t0 +tex t1 +tex t2 +mul r0.rgb, t0, v0 + ; base times vertex color (no alpha) +mov r0.a, v0.a ; Grab alpha from vertex color + +mul r0.rgb, t1, r0 ; fold in lighting (color only) +mul_x2 r1.rgb, r0, t2 ; detail texture +lrp r0.rgb, c2, r1, r0 +mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2) + +mul r1, c1, t0 ; Self illum * tint +lrp r0.rgb, t0.a, r1, r0 ; Blend between self-illum + base * lightmap diff --git a/materialsystem/stdshaders/LightmappedGeneric_EnvMapNoTexture.psh b/materialsystem/stdshaders/LightmappedGeneric_EnvMapNoTexture.psh new file mode 100644 index 0000000..706ba7c --- /dev/null +++ b/materialsystem/stdshaders/LightmappedGeneric_EnvMapNoTexture.psh @@ -0,0 +1,21 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; Draw a texture . . woo hoo! +; t0 - texture +; +; The texture coordinates need to be defined as follows: +; tc0 - texcoords +; c1 - self-illum tint +; c2 - envmap tint +;------------------------------------------------------------------------------ + +tex t1 +tex t2 + +mov r0.rgb, v0 + ; vertex color +mul r0.a, v0.a, t2.a ; vertex alpha * envmap alpha + +mad r0.rgb, t2, c2, r0 ; + envmap * envmaptint (color only) +mul r0.rgb, t1, r0 ; fold in lightmap (color only) +mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2) diff --git a/materialsystem/stdshaders/LightmappedGeneric_EnvMapV2.psh b/materialsystem/stdshaders/LightmappedGeneric_EnvMapV2.psh new file mode 100644 index 0000000..05812ff --- /dev/null +++ b/materialsystem/stdshaders/LightmappedGeneric_EnvMapV2.psh @@ -0,0 +1,20 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; Draw a texture . . woo hoo! +; t0 - texture +; +; The texture coordinates need to be defined as follows: +; tc0 - texcoords +; c1 - self-illum tint +; c2 - envmap tint +;------------------------------------------------------------------------------ + +tex t0 +tex t1 +tex t2 + +mul r0, t0, v0 ; base times vertex color (with alpha) +mul r0.rgb, t1, r0 ; fold in lightmap (color only) +mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2) +mad r0.rgb, t2, c2, r0 ; + envmap * envmaptint (color only) diff --git a/materialsystem/stdshaders/LightmappedGeneric_LightingOnly.vsh b/materialsystem/stdshaders/LightmappedGeneric_LightingOnly.vsh new file mode 100644 index 0000000..5f740f8 --- /dev/null +++ b/materialsystem/stdshaders/LightmappedGeneric_LightingOnly.vsh @@ -0,0 +1,45 @@ +vs.1.1 + +# DYNAMIC: "DOWATERFOG" "0..1" + +#include "macros.vsh" + +;------------------------------------------------------------------------------ +; $SHADER_SPECIFIC_CONST_0-$SHADER_SPECIFIC_CONST_1 = Base texture transform +; $SHADER_SPECIFIC_CONST_2-$SHADER_SPECIFIC_CONST_3 = Mask texture transform +; $SHADER_SPECIFIC_CONST_4 = Modulation color +;------------------------------------------------------------------------------ + +&AllocateRegister( \$projPos ); + +; Transform position from object to projection space +dp4 $projPos.x, $vPos, $cModelViewProj0 +dp4 $projPos.y, $vPos, $cModelViewProj1 +dp4 $projPos.z, $vPos, $cModelViewProj2 +dp4 $projPos.w, $vPos, $cModelViewProj3 + +mov oPos, $projPos + +;------------------------------------------------------------------------------ +; Fog +;------------------------------------------------------------------------------ + +alloc $worldPos +if( $DOWATERFOG == 1 ) +{ + ; Get the worldpos z component only since that's all we need for height fog + dp4 $worldPos.z, $vPos, $cModel2 +} +&CalcFog( $worldPos, $projPos ); +free $worldPos + +&FreeRegister( \$projPos ); + +; YUCK! This is to make texcoords continuous for mat_softwaretl +mov oT0, $cZero +; Texture coordinates +mov oT1, $vTexCoord1 + +mov oD0, $cOne + + diff --git a/materialsystem/stdshaders/LightmappedGeneric_LightingOnly_Overbright2.psh b/materialsystem/stdshaders/LightmappedGeneric_LightingOnly_Overbright2.psh new file mode 100644 index 0000000..c4f2ba2 --- /dev/null +++ b/materialsystem/stdshaders/LightmappedGeneric_LightingOnly_Overbright2.psh @@ -0,0 +1,6 @@ +ps.1.1 + +tex t1 + +mov r0.rgba, t1 + diff --git a/materialsystem/stdshaders/LightmappedGeneric_MaskedEnvMapNoTexture.psh b/materialsystem/stdshaders/LightmappedGeneric_MaskedEnvMapNoTexture.psh new file mode 100644 index 0000000..a1e6374 --- /dev/null +++ b/materialsystem/stdshaders/LightmappedGeneric_MaskedEnvMapNoTexture.psh @@ -0,0 +1,24 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; Draw a texture . . woo hoo! +; t0 - texture +; +; The texture coordinates need to be defined as follows: +; tc0 - texcoords +; c1 - self-illum tint +; c2 - envmap tint +;------------------------------------------------------------------------------ + +tex t1 +tex t2 +tex t3 + +mov r0.rgb, v0 ; vertex color +mul r1, t2, t3 ; envmap * envmapmask + +mad r0.rgb, r1, c2, r0 + ; + envmap * envmapmask * envmaptint (color only) +mul r0.a, v0.a, r1.a ; alpha = vertex alpha * envmap alpha * envmapmask alpha + +mul r0.rgb, t1, r0 ; fold in lightmap (color only) +mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2) diff --git a/materialsystem/stdshaders/LightmappedGeneric_MaskedEnvMapV2.psh b/materialsystem/stdshaders/LightmappedGeneric_MaskedEnvMapV2.psh new file mode 100644 index 0000000..83553ac --- /dev/null +++ b/materialsystem/stdshaders/LightmappedGeneric_MaskedEnvMapV2.psh @@ -0,0 +1,22 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; Draw a texture . . woo hoo! +; t0 - texture +; +; The texture coordinates need to be defined as follows: +; tc0 - texcoords +; c1 - self-illum tint +; c2 - envmap tint +;------------------------------------------------------------------------------ + +tex t0 +tex t1 +tex t2 +tex t3 + +mul r0, t0, v0 ; base times vertex color (with alpha) +mul r0.rgb, t1, r0 ; fold in lighting (color only) +mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2) +mul r1, t2, t3 ; envmap * envmapmask +mad r0.rgb, r1, c2, r0 ; + envmap * envmapmask * envmaptint (color only) diff --git a/materialsystem/stdshaders/LightmappedGeneric_MultiplyByLighting.psh b/materialsystem/stdshaders/LightmappedGeneric_MultiplyByLighting.psh new file mode 100644 index 0000000..9f09397 --- /dev/null +++ b/materialsystem/stdshaders/LightmappedGeneric_MultiplyByLighting.psh @@ -0,0 +1,20 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; Draw a texture . . woo hoo! +; t0 - texture +; +; The texture coordinates need to be defined as follows: +; tc0 - texcoords +;------------------------------------------------------------------------------ + +def c2, 1.0f, 1.0f, 1.0f, 1.0f + +tex t0 +tex t1 + +; Blend between grey and lightmap color based on total alpha + +mul_x2 r1.rgb, c0, t1 ; Apply overbright to lightmap ++ mul_sat r1.a, t0, v0 ; base times vertex alpha +lrp r0, r1.a, r1, c2 ; interpolate between white + color diff --git a/materialsystem/stdshaders/LightmappedGeneric_MultiplyByLightingNoTexture.psh b/materialsystem/stdshaders/LightmappedGeneric_MultiplyByLightingNoTexture.psh new file mode 100644 index 0000000..0e52ed8 --- /dev/null +++ b/materialsystem/stdshaders/LightmappedGeneric_MultiplyByLightingNoTexture.psh @@ -0,0 +1,20 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; Draw a texture . . woo hoo! +; t0 - texture +; +; The texture coordinates need to be defined as follows: +; tc0 - texcoords +;------------------------------------------------------------------------------ + +def c2, 1.0f, 1.0f, 1.0f, 1.0f + +tex t0 +tex t1 + +; Blend between grey and lightmap color based on total alpha + +mul_x2 r1.rgb, c0, t1 ; Apply overbright to lightmap ++ mov_sat r1.a, v0 ; vertex alpha +lrp r0, r1.a, r1, c2 ; interpolate between white + color diff --git a/materialsystem/stdshaders/LightmappedGeneric_MultiplyByLightingSelfIllum.psh b/materialsystem/stdshaders/LightmappedGeneric_MultiplyByLightingSelfIllum.psh new file mode 100644 index 0000000..6c939a4 --- /dev/null +++ b/materialsystem/stdshaders/LightmappedGeneric_MultiplyByLightingSelfIllum.psh @@ -0,0 +1,23 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; Draw a texture . . woo hoo! +; t0 - texture +; +; The texture coordinates need to be defined as follows: +; tc0 - texcoords +;------------------------------------------------------------------------------ + +def c2, 1.0f, 1.0f, 1.0f, 1.0f + +tex t0 +tex t1 + +; Blend between white and lightmap color based on total alpha +mul_x2 r1.rgb, c0, t1 ; Apply overbright to lightmap ++ mov_sat r1.a, v0 ; opacity == vertex opacity (no alpha in texture) + +lrp r0.rgb, t0.a, c1, r1 ; Blend between self-illum + lightmap ++ mov r0.a, c2.a + +lrp r0.rgb, r1.a, r0, c2 ; interpolate between white + color diff --git a/materialsystem/stdshaders/LightmappedGeneric_NoTexture.psh b/materialsystem/stdshaders/LightmappedGeneric_NoTexture.psh new file mode 100644 index 0000000..01b2071 --- /dev/null +++ b/materialsystem/stdshaders/LightmappedGeneric_NoTexture.psh @@ -0,0 +1,14 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; Draw a texture . . woo hoo! +; t0 - texture +; +; The texture coordinates need to be defined as follows: +; tc0 - texcoords +;------------------------------------------------------------------------------ + +tex t1 +mul r0.rgb, t1, v0 + ; base times vertex color (with alpha) +mov r0.a, v0.a +mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2) diff --git a/materialsystem/stdshaders/LightmappedGeneric_SSBumpmappedLightmap.psh b/materialsystem/stdshaders/LightmappedGeneric_SSBumpmappedLightmap.psh new file mode 100644 index 0000000..29be70c --- /dev/null +++ b/materialsystem/stdshaders/LightmappedGeneric_SSBumpmappedLightmap.psh @@ -0,0 +1,34 @@ +ps.1.1 +def c0, 1,0,0,0 +def c1, 0,1,0,0 +def c2, 0,0,1,0 + +;------------------------------------------------------------------------------ +; Computes the diffuse component of lighting using lightmap + bumpmap +; t0 - Normalmap +; t1 - Lightmap1 +; t2 - Lightmap2 +; t3 - Lightmap3 +; +; The texture coordinates need to be defined as follows: +; tc0 - Normalmap and lightmap texture coordinates +;------------------------------------------------------------------------------ + +; Get the 3-vector from the normal map +tex t0 + +; Sample the lightmaps +tex t1 +tex t2 +tex t3 + +; output = lightmapColor[0] * n.r + lightmapColor[1] * n.g + lightmapColor[2] * n.b + + +mov r0, t0 +dp3 r1, t0, c0 +mul r0.rgb, r1, t1 +dp3 r1, t0, c1 +mad r0.rgb, r1, t2, r0 +dp3 r1, t0, c2 +mad r0.rgb, r1, t3, r0 diff --git a/materialsystem/stdshaders/LightmappedGeneric_SelfIlluminated.psh b/materialsystem/stdshaders/LightmappedGeneric_SelfIlluminated.psh new file mode 100644 index 0000000..1ac3326 --- /dev/null +++ b/materialsystem/stdshaders/LightmappedGeneric_SelfIlluminated.psh @@ -0,0 +1,21 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; Draw a texture . . woo hoo! +; t0 - texture +; +; The texture coordinates need to be defined as follows: +; tc0 - texcoords +;------------------------------------------------------------------------------ + +tex t0 +tex t1 + +mul r0.rgb, t0, v0 + ; base times vertex color (no alpha) +mov r0.a, v0.a ; Grab alpha from vertex color + +mul r0.rgb, t1, r0 ; fold in lighting (color only) +mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2) + +mul r1, c1, t0 ; Self illum * tint +lrp r0.rgb, t0.a, r1, r0 ; Blend between self-illum + base * lightmap diff --git a/materialsystem/stdshaders/LightmappedGeneric_SelfIlluminatedEnvMapV2.psh b/materialsystem/stdshaders/LightmappedGeneric_SelfIlluminatedEnvMapV2.psh new file mode 100644 index 0000000..0121e92 --- /dev/null +++ b/materialsystem/stdshaders/LightmappedGeneric_SelfIlluminatedEnvMapV2.psh @@ -0,0 +1,27 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; Draw a texture . . woo hoo! +; t0 - texture +; +; The texture coordinates need to be defined as follows: +; tc0 - texcoords +; c1 - self-illum tint +; c2 - envmap tint +;------------------------------------------------------------------------------ + +tex t0 +tex t1 +tex t2 + +mul r0.rgb, t0, v0 + ; base times vertex color (no alpha) +mov r0.a, v0.a ; Grab alpha from vertex color + +mul r1, t0.a, t0 ; Self illum +mad r1, c1, r1, t1 ; Self illum * tint + lightmap + +mul r0.rgb, r1, r0 ; fold in lighting (color only) +mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2) + +mad r0.rgb, t2, c2, r0 ; + envmap * envmaptint (color only) + diff --git a/materialsystem/stdshaders/LightmappedGeneric_SelfIlluminatedMaskedEnvMapV2.psh b/materialsystem/stdshaders/LightmappedGeneric_SelfIlluminatedMaskedEnvMapV2.psh new file mode 100644 index 0000000..4d32a71 --- /dev/null +++ b/materialsystem/stdshaders/LightmappedGeneric_SelfIlluminatedMaskedEnvMapV2.psh @@ -0,0 +1,28 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; Draw a texture . . woo hoo! +; t0 - texture +; +; The texture coordinates need to be defined as follows: +; tc0 - texcoords +; c1 - self-illum tint +; c2 - envmap tint +;------------------------------------------------------------------------------ + +tex t0 +tex t1 +tex t2 +tex t3 + +mul r0.rgb, t0, v0 + ; base times vertex color (with alpha) +mov r0.a, v0.a ; Grab alpha from vertex color + +mul r1, c1, t0.a ; Self illum alpha * tint +mad r1, t0, r1, t1 ; Self illum * tint + lightmap +mul r0.rgb, r1, r0 ; fold in lighting (color only) +mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2) + +mul r1, t2, t3 ; envmap * envmapmask +mad r0.rgb, r1, c2, r0 ; + envmap * envmapmask * envmaptint (color only) + diff --git a/materialsystem/stdshaders/LightmappedGeneric_VertexColor.vsh b/materialsystem/stdshaders/LightmappedGeneric_VertexColor.vsh new file mode 100644 index 0000000..a434a94 --- /dev/null +++ b/materialsystem/stdshaders/LightmappedGeneric_VertexColor.vsh @@ -0,0 +1,15 @@ +vs.1.1 + +# DYNAMIC: "DOWATERFOG" "0..1" + +#include "LightmappedGeneric_inc.vsh" + +$detail = 0; +$envmap = 0; +$envmapcameraspace = 0; +$envmapsphere = 0; +$vertexcolor = 1; + +&LightmappedGeneric( $detail, $envmap, $envmapcameraspace, $envmapsphere, + $vertexcolor ); + diff --git a/materialsystem/stdshaders/LightmappedTranslucentTexture.psh b/materialsystem/stdshaders/LightmappedTranslucentTexture.psh new file mode 100644 index 0000000..4dcd7af --- /dev/null +++ b/materialsystem/stdshaders/LightmappedTranslucentTexture.psh @@ -0,0 +1,19 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; Draw a alpha blended, translucent (alpha in texture) texture. +; t0 - texture +; +; c0 - overbright value +; +; The texture coordinates need to be defined as follows: +; tc0 - texcoords +;------------------------------------------------------------------------------ + +; Get the color from the texture +tex t0 +tex t1 +mul r0.rgb, t0, t1 ; base * lightmap +mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2) + +mov r0.a, t0.a diff --git a/materialsystem/stdshaders/LightmappedTranslucentTexture.vsh b/materialsystem/stdshaders/LightmappedTranslucentTexture.vsh new file mode 100644 index 0000000..1319fd0 --- /dev/null +++ b/materialsystem/stdshaders/LightmappedTranslucentTexture.vsh @@ -0,0 +1,16 @@ +vs.1.1 + +# DYNAMIC: "DOWATERFOG" "0..1" +; FIXME - this is the same as LightmappedGeneric.vsh!!! + +#include "LightmappedGeneric_inc.vsh" + +$detail = 0; +$envmap = 0; +$envmapcameraspace = 0; +$envmapsphere = 0; +$vertexcolor = 0; + +&LightmappedGeneric( $detail, $envmap, $envmapcameraspace, $envmapsphere, + $vertexcolor ); + diff --git a/materialsystem/stdshaders/Modulate_ps11.psh b/materialsystem/stdshaders/Modulate_ps11.psh new file mode 100644 index 0000000..1ef708b --- /dev/null +++ b/materialsystem/stdshaders/Modulate_ps11.psh @@ -0,0 +1,8 @@ +ps.1.1 + +; c0 is grey or white depending on if this is mod2x or not. + +tex t0 ; base color + +mul_sat r0.rgba, t0, v0 +lrp r0.rgb, r0.a, r0, c0 diff --git a/materialsystem/stdshaders/MonitorScreen.psh b/materialsystem/stdshaders/MonitorScreen.psh new file mode 100644 index 0000000..fd5cd52 --- /dev/null +++ b/materialsystem/stdshaders/MonitorScreen.psh @@ -0,0 +1,17 @@ +; STATIC: "TEXTURE2" "0..1" +ps.1.1 + +def c4, 0.33333f, 0.33333f, 0.33333f, 0.33333f + +tex t0 ; base color +tex t1 ; texture 2 + +mul r0, t0, v0 +#if TEXTURE2 +mul r0, t1, r0 +#endif +mul r1.rgb, r0, r0 ; base * base +lrp r0.rgb, c1, r1, r0 ; blend between color and color * color +dp3 r1.rgb, r0, c4 ; color greyscaled +lrp r0.rgb, c2, r0, r1 ; blend between color and greyscale +mul r0.rgb, r0, c3 ; tint diff --git a/materialsystem/stdshaders/MonitorScreen_dx8.cpp b/materialsystem/stdshaders/MonitorScreen_dx8.cpp new file mode 100644 index 0000000..f141290 --- /dev/null +++ b/materialsystem/stdshaders/MonitorScreen_dx8.cpp @@ -0,0 +1,150 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//=============================================================================// + +#include "BaseVSShader.h" + +#include "unlittwotexture.inc" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +DEFINE_FALLBACK_SHADER( MonitorScreen, MonitorScreen_DX8 ) + +BEGIN_VS_SHADER( MonitorScreen_DX8, + "This is a shader that does a contrast/saturation version of base times lightmap." ) + + BEGIN_SHADER_PARAMS + SHADER_PARAM( CONTRAST, SHADER_PARAM_TYPE_FLOAT, "0.0", "contrast 0 == normal 1 == color*color" ) + SHADER_PARAM( SATURATION, SHADER_PARAM_TYPE_FLOAT, "1.0", "saturation 0 == greyscale 1 == normal" ) + SHADER_PARAM( TINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "monitor tint" ) + SHADER_PARAM( TEXTURE2, SHADER_PARAM_TYPE_TEXTURE, "shadertest/lightmappedtexture", "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 + + // Set up anything that is necessary to make decisions in SHADER_FALLBACK. + SHADER_INIT_PARAMS() + { + SET_FLAGS2( MATERIAL_VAR2_SUPPORTS_HW_SKINNING ); + + if( !params[CONTRAST]->IsDefined() ) + { + params[CONTRAST]->SetFloatValue( 0.0f ); + } + if( !params[SATURATION]->IsDefined() ) + { + params[SATURATION]->SetFloatValue( 1.0f ); + } + if( !params[TINT]->IsDefined() ) + { + params[TINT]->SetVecValue( 1.0f, 1.0f, 1.0f ); + } + if (!IS_FLAG_DEFINED( MATERIAL_VAR_MODEL )) + { + CLEAR_FLAGS( MATERIAL_VAR_MODEL ); + } + } + + SHADER_FALLBACK + { + if( IsPC() && g_pHardwareConfig->GetDXSupportLevel() < 80 || (params && !params[BASETEXTURE]->IsDefined()) ) + { + if( IS_FLAG_DEFINED( MATERIAL_VAR_MODEL ) ) + { + return "VertexLitGeneric_DX6"; + } + else + { + return "LightmappedGeneric_DX6"; + } + } + return 0; + } + + SHADER_INIT + { + if (params[BASETEXTURE]->IsDefined()) + { + LoadTexture( BASETEXTURE ); + } + if (params[TEXTURE2]->IsDefined()) + { + LoadTexture( TEXTURE2 ); + } + } + + SHADER_DRAW + { + bool bHasTexture2 = params[TEXTURE2]->IsTexture(); + SHADOW_STATE + { + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, true ); + if ( bHasTexture2 ) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER1, true ); + } + + pShaderShadow->EnableSRGBWrite( true ); + + // 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 ); + else + DisableAlphaBlending( ); + } + + int fmt = VERTEX_POSITION | VERTEX_NORMAL; + if (IS_FLAG_SET( MATERIAL_VAR_VERTEXCOLOR )) + fmt |= VERTEX_COLOR; + + pShaderShadow->VertexShaderVertexFormat( fmt, 1, 0, 0 ); + + unlittwotexture_Static_Index vshIndex; + pShaderShadow->SetVertexShader( "UnlitTwoTexture", vshIndex.GetIndex() ); + + int pshIndex = bHasTexture2 ? 1 : 0; + pShaderShadow->SetPixelShader( "MonitorScreen", pshIndex ); + DefaultFog(); + } + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME ); + if( bHasTexture2 ) + { + BindTexture( SHADER_SAMPLER1, TEXTURE2, FRAME2 ); + SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_2, TEXTURE2TRANSFORM ); + } + SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, BASETEXTURETRANSFORM ); + SetPixelShaderConstant( 1, CONTRAST ); + SetPixelShaderConstant( 2, SATURATION ); + SetPixelShaderConstant( 3, TINT ); + SetModulationVertexShaderDynamicState(); + + unlittwotexture_Dynamic_Index vshIndex; + vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + vshIndex.SetSKINNING( pShaderAPI->GetCurrentNumBones() > 0 ); + pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() ); + } + Draw(); + } +END_SHADER diff --git a/materialsystem/stdshaders/MonitorScreen_dx9.cpp b/materialsystem/stdshaders/MonitorScreen_dx9.cpp new file mode 100644 index 0000000..389d128 --- /dev/null +++ b/materialsystem/stdshaders/MonitorScreen_dx9.cpp @@ -0,0 +1,197 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//=============================================================================// + +#include "BaseVSShader.h" +#include "unlittwotexture_vs20.inc" +#include "monitorscreen_ps20.inc" +#include "monitorscreen_ps20b.inc" +#include "cpp_shader_constant_register_map.h" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +DEFINE_FALLBACK_SHADER( MonitorScreen, MonitorScreen_DX9 ) + +BEGIN_VS_SHADER( MonitorScreen_DX9, + "This is a shader that does a contrast/saturation version of base times lightmap." ) + + BEGIN_SHADER_PARAMS + SHADER_PARAM( CONTRAST, SHADER_PARAM_TYPE_FLOAT, "0.0", "contrast 0 == normal 1 == color*color" ) + SHADER_PARAM( SATURATION, SHADER_PARAM_TYPE_FLOAT, "1.0", "saturation 0 == greyscale 1 == normal" ) + SHADER_PARAM( TINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "monitor tint" ) + SHADER_PARAM( TEXTURE2, SHADER_PARAM_TYPE_TEXTURE, "shadertest/lightmappedtexture", "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 + + // Set up anything that is necessary to make decisions in SHADER_FALLBACK. + SHADER_INIT_PARAMS() + { + SET_FLAGS2( MATERIAL_VAR2_SUPPORTS_HW_SKINNING ); + if( !params[CONTRAST]->IsDefined() ) + { + params[CONTRAST]->SetFloatValue( 0.0f ); + } + if( !params[SATURATION]->IsDefined() ) + { + params[SATURATION]->SetFloatValue( 1.0f ); + } + if( !params[TINT]->IsDefined() ) + { + params[TINT]->SetVecValue( 1.0f, 1.0f, 1.0f ); + } + if (!IS_FLAG_DEFINED( MATERIAL_VAR_MODEL )) + { + CLEAR_FLAGS( MATERIAL_VAR_MODEL ); + } + } + + SHADER_FALLBACK + { + if( params && !params[BASETEXTURE]->IsDefined() ) + { + if( IS_FLAG_DEFINED( MATERIAL_VAR_MODEL ) ) + { + return "VertexLitGeneric_DX6"; + } + else + { + return "LightmappedGeneric_DX6"; + } + } + + if ( !(g_pHardwareConfig->SupportsPixelShaders_2_0() && g_pHardwareConfig->SupportsVertexShaders_2_0()) || + (g_pHardwareConfig->GetDXSupportLevel() < 90) ) + { + return "MonitorScreen_DX8"; + } + + return 0; + } + + SHADER_INIT + { + if (params[BASETEXTURE]->IsDefined()) + { + LoadTexture( BASETEXTURE, TEXTUREFLAGS_SRGB ); + } + if (params[TEXTURE2]->IsDefined()) + { + LoadTexture( TEXTURE2, TEXTUREFLAGS_SRGB ); + } + } + + SHADER_DRAW + { + bool bHasTexture2 = params[TEXTURE2]->IsTexture(); + BlendType_t nBlendType = EvaluateBlendRequirements( BASETEXTURE, true ); + bool bFullyOpaque = (nBlendType != BT_BLENDADD) && (nBlendType != BT_BLEND) && !IS_FLAG_SET(MATERIAL_VAR_ALPHATEST); //dest alpha is free for special use + + SHADOW_STATE + { + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, true ); + if ( bHasTexture2 ) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER1, true ); + } + + pShaderShadow->EnableSRGBWrite( true ); + + // 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 ); + else + DisableAlphaBlending( ); + } + + // Set stream format (note that this shader supports compression) + unsigned int flags = VERTEX_POSITION | VERTEX_NORMAL | VERTEX_FORMAT_COMPRESSED; + int nTexCoordCount = 1; + int userDataSize = 0; + pShaderShadow->VertexShaderVertexFormat( flags, nTexCoordCount, NULL, userDataSize ); + + DECLARE_STATIC_VERTEX_SHADER( unlittwotexture_vs20 ); + SET_STATIC_VERTEX_SHADER( unlittwotexture_vs20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_STATIC_PIXEL_SHADER( monitorscreen_ps20b ); + SET_STATIC_PIXEL_SHADER_COMBO( TEXTURE2, (bHasTexture2)?(1):(0) ); + SET_STATIC_PIXEL_SHADER( monitorscreen_ps20b ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( monitorscreen_ps20 ); + SET_STATIC_PIXEL_SHADER_COMBO( TEXTURE2, (bHasTexture2)?(1):(0) ); + SET_STATIC_PIXEL_SHADER( monitorscreen_ps20 ); + } + + DefaultFog(); + + pShaderShadow->EnableAlphaWrites( bFullyOpaque ); + } + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME ); + if( bHasTexture2 ) + { + BindTexture( SHADER_SAMPLER1, TEXTURE2, FRAME2 ); + SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_2, TEXTURE2TRANSFORM ); + } + SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, BASETEXTURETRANSFORM ); + SetPixelShaderConstant( 1, CONTRAST ); + SetPixelShaderConstant( 2, SATURATION ); + SetPixelShaderConstant( 3, TINT ); + SetModulationVertexShaderDynamicState(); + + pShaderAPI->SetPixelShaderFogParams( PSREG_FOG_PARAMS ); + + float vEyePos_SpecExponent[4]; + pShaderAPI->GetWorldSpaceCameraPosition( vEyePos_SpecExponent ); + vEyePos_SpecExponent[3] = 0.0f; + pShaderAPI->SetPixelShaderConstant( PSREG_EYEPOS_SPEC_EXPONENT, vEyePos_SpecExponent, 1 ); + + + DECLARE_DYNAMIC_VERTEX_SHADER( unlittwotexture_vs20 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( DOWATERFOG, pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, pShaderAPI->GetCurrentNumBones() > 0 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression ); + SET_DYNAMIC_VERTEX_SHADER( unlittwotexture_vs20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_DYNAMIC_PIXEL_SHADER( monitorscreen_ps20b ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( WRITE_DEPTH_TO_DESTALPHA, bFullyOpaque && pShaderAPI->ShouldWriteDepthToDestAlpha() ); + SET_DYNAMIC_PIXEL_SHADER( monitorscreen_ps20b ); + } + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( monitorscreen_ps20 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + SET_DYNAMIC_PIXEL_SHADER( monitorscreen_ps20 ); + } + } + Draw(); + } +END_SHADER diff --git a/materialsystem/stdshaders/ParticleSphere.vsh b/materialsystem/stdshaders/ParticleSphere.vsh new file mode 100644 index 0000000..b2d8384 --- /dev/null +++ b/materialsystem/stdshaders/ParticleSphere.vsh @@ -0,0 +1,163 @@ +vs.1.1 + +# DYNAMIC: "DOWATERFOG" "0..1" + +#include "macros.vsh" + +$cQuarter = "c91.x"; + +;------------------------------------------------------------------------------ +; Constants specified by the app +; c0 = (0, 1, 2, 0.5) +; c1 = (1/2.2, 0, 0, 0) +; 2 = camera position *in world space* +; c4-c7 = modelViewProj matrix (transpose) +; c8-c11 = ViewProj matrix (transpose) +; c12-c15 = model->world matrix (transpose) +; c16 = [fogStart, fogEnd, fogRange, undefined] +; c17-c20 = model->view matrix (transpose) +; +; The ParticleSphere lighting equation is: +; A + [N dot ||L - P||] * C * r / |L - P|^2 +; +; where: +; A = ambient light color +; N = particle normal (stored in the texture) +; L = directional light position +; P = point on surface +; C = directional light color +; r = directional light intensity +; +; This shader just does the |L - P| part and the pixel shader does the rest. +; +; Vertex components +; $vPos = Position +; $vSpecular = Directional light color +; $vColor = Ambient color (and alpha) +; $vTexCoord0 = Texture coordinates for normal map +; $vTexCoord0.z = Index into the light list for light info + + + +;------------------------------------------------------------------------------ +; Constant registers +;------------------------------------------------------------------------------ + +;------------------------------------------------------------------------------ +; Vertex blending +;------------------------------------------------------------------------------ + +&AllocateRegister( \$projPos ); + +; Transform position from object to projection space +dp4 $projPos.x, $vPos, $cModelViewProj0 +dp4 $projPos.y, $vPos, $cModelViewProj1 +dp4 $projPos.z, $vPos, $cModelViewProj2 +dp4 $projPos.w, $vPos, $cModelViewProj3 + +mov oPos, $projPos + +;------------------------------------------------------------------------------ +; Fog +;------------------------------------------------------------------------------ + +alloc $worldPos +if( $DOWATERFOG == 1 ) +{ + ; Get the worldpos z component only since that's all we need for height fog + dp4 $worldPos.z, $vPos, $cModel2 +} +&CalcFog( $worldPos, $projPos ); +free $worldPos + +&FreeRegister( \$projPos ); + +;------------------------------------------------------------------------------ +; Setup to index our directional light. +;------------------------------------------------------------------------------ +mov a0.x, $vTexCoord0.z + + +;------------------------------------------------------------------------------ +; Copy texcoords for the normal map texture +;------------------------------------------------------------------------------ + +mov oT0, $vTexCoord0 +mov oT2.xyz, $vColor + +; FIXME : the rest of this needs to use AllocateRegister + +;------------------------------------------------------------------------------ +; Generate a tangent space and rotate L. +; This can be thought of as rotating the normal map to face the viewer. +; +; This is useful when a particle is way off to the side of the screen. +; You should be looking at the half-sphere with a normal pointing from the +; particle to the viewer. Instead, you're looking at the half-sphere with +; a normal along Z. This tangent space builder code fixes the problem. +; +; Note that since the model and view matrices are identity, the coordinate +; system has X=right, Y=up, and Z=behind you (negative Z goes into the screen). +;------------------------------------------------------------------------------ + ; r5 (forward) = normalized P +dp3 r1, $vPos, $vPos +rsq r5, r1 +mul r5, r5, $vPos +mov r5.z, -r5.z ; This basis wants Z positive going into the screen + ; so flip it here. + + ; r1 (up) = r5 x c24 +mul r1, r5.xzyw, $SHADER_SPECIFIC_CONST_0; (This effectively does a cross product with [1,0,0,0] + ; You wind up with [0, r5.z, -r5.y, 1] +dp3 r2, r1, r1 +rsq r2, r2 +mul r1, r1, r2 + + ; r2 (right) = r1 x r5 +mul r2, r1.yzxw, r5.zxyw +mad r2, -r1.zxyw, r5.yzxw, r2 + +sub r3, c[45 + a0.x], $vPos ; r3 = L - P + +; transposed matrix mul +mul r0, r2, r3.xxxx ; x * right +mad r0, r1, r3.yyyy, r0 ; + y * up +mad r0, r5, r3.zzzz, r0 ; + z * forward + + +;------------------------------------------------------------------------------ +; Put ||L - P|| into t1 +;------------------------------------------------------------------------------ +dp3 r2, r0, r0 ; r2 = Length(L - P)^2 +rsq r3, r2 ; r3 = 1 / Length(L - P) +mul r8, r0, r3 ; r8 = Normalize(L - P) +mul r9, r8, $cQuarter ; r9 = Normalize(L - P) * 0.25 +add oT1, r9, c0.w ; oT1 = Normalize(L - P) * 0.25 + 0.5 + + +;------------------------------------------------------------------------------ +; Setup the diffuse light color (C * r / ||L - P||^2) +;------------------------------------------------------------------------------ + +mul r8, c[46 + a0.x], $vSpecular ; r8 = C * r +rcp r7, r2 ; r7 = 1 / Length(L - P)^2 + +; rescale the color if necessary +mul r8, r8, r7 ; r8 = C * r / Length(L - P)^2 + +; We're doing both parts of an if statement here, with each part scaled by 0 or 1. +mul r9, r7, c[46 + a0.x] ; r9 = r / Length(L - P)^2 + +; If the light intensity scales the color > 1 + sge r10, r9.xxxx, $cOne ; r10.x = 1 if the color's max component > 1 + rcp r6, r9.xxxx + mul r6, r6, r10.xxxx ; r6 = 1 / max_component or [0,0,0,0] if max_component < 1 + mul r2, r8, r6 ; rescaled color (all zeros if no component was > 1) +; else + slt r11, r9.xxxx, $cOne ; r11.x = 1 if the color's max component < 1 + mad oD0.xyz, r8, r11, r2 ; if it was rescaled, then r8*r11 = 0 + ; if not, then r8*r11 = the original color + +mov oD0.a, $vColor.a ; Pass in vertex alpha so the pixel shader can use it. + + diff --git a/materialsystem/stdshaders/Refract_model_vs11.vsh b/materialsystem/stdshaders/Refract_model_vs11.vsh new file mode 100644 index 0000000..a6eea2b --- /dev/null +++ b/materialsystem/stdshaders/Refract_model_vs11.vsh @@ -0,0 +1,105 @@ +vs.1.1 + +# DYNAMIC: "DOWATERFOG" "0..1" +# DYNAMIC: "SKINNING" "0..1" + +;------------------------------------------------------------------------------ +; Constants specified by the app +; c0 = (0, 1, 2, 0.5) +; c1 = (1/2.2, 0, 0, 0) +; c2 = camera position *in world space* +; c4-c7 = modelViewProj matrix (transpose) +; c8-c11 = ViewProj matrix (transpose) +; c12-c15 = model->view matrix (transpose) +; c16 = [fogStart, fogEnd, fogRange, undefined] +; +; Vertex components (as specified in the vertex DECL) +; $vPos = Position +; $vTexCoord0.xy = TexCoord0 +;------------------------------------------------------------------------------ + +#include "macros.vsh" + +; Vertex components +; $vPos = Position +; $vNormal = normal +; $vTexCoord0.xy = TexCoord0 +; $vTangentS = S axis of Texture space +; $vTangentT = T axis of Texture space + +;------------------------------------------------------------------------------ +; Transform the position from world to view space +;------------------------------------------------------------------------------ + +alloc $worldPos +alloc $worldNormal +alloc $worldTangentS +alloc $worldTangentT + +&SkinPositionNormalAndTangentSpace( $worldPos, $worldNormal, + $worldTangentS, $worldTangentT ); + +alloc $projPos + +; Transform position from world to projection space +dp4 $projPos.x, $worldPos, $cViewProj0 +dp4 $projPos.y, $worldPos, $cViewProj1 +dp4 $projPos.z, $worldPos, $cViewProj2 +dp4 $projPos.w, $worldPos, $cViewProj3 + +&CalcFog( $worldPos, $projPos ); + +alloc $worldEyeVect + +; Get the eye vector in world space +add $worldEyeVect.xyz, -$worldPos, $cEyePos + +alloc $tangentEyeVect +; transform the eye vector to tangent space +dp3 oT3.x, $worldEyeVect, $worldTangentS +dp3 oT3.y, $worldEyeVect, $worldTangentT +dp3 oT3.z, $worldEyeVect, $worldNormal + +alloc $bumpTexCoord + +dp4 $bumpTexCoord.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_1 +dp4 $bumpTexCoord.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_2 + +; dudv map +mov oT0.xy, $bumpTexCoord + +; refract tint + alpha channel +mov oT2.xy, $bumpTexCoord +mov oT3.xy, $bumpTexCoord + +free $bumpTexCoord + +mov oPos, $projPos + +; special case perspective correct texture projection so that the texture fits exactly on the screen + +; flip Y by multiplying by -1 +mul $projPos.y, $projPos.y, $SHADER_SPECIFIC_CONST_4.w + +; transform from [-w,w] to [0,2*w] +; The reason this is w is because we are in perspective space/homogenous clip space. +add $projPos.xy, $projPos.xy, $projPos.w + +; transform from [0,2*w] to [0,w] +; We'll end up dividing by w in the pixel shader to get to [0,1] +mul $projPos.xy, $projPos.xy, $cHalf + +mov oT1.xy, $projPos.xy + +; emit w to both z and w in case the driver screws up and divides by z +mov oT1.z, $projPos.w +mov oT1.w, $projPos.w + +free $projPos +free $worldPos +free $worldEyeVect +free $tangentEyeVect +free $w +free $worldNormal +free $worldTangentS +free $worldTangentT diff --git a/materialsystem/stdshaders/Refract_ps11.psh b/materialsystem/stdshaders/Refract_ps11.psh new file mode 100644 index 0000000..a4e59bf --- /dev/null +++ b/materialsystem/stdshaders/Refract_ps11.psh @@ -0,0 +1,36 @@ +; STATIC: "REFRACTTINTTEXTURE" "0..1" +; STATIC: "NORMALMAPALPHA" "0..1" + +ps.1.1 + +; t0: +; texture: dudv map +; texcoords: dudvmap texcoords +; t1: +; texture: refraction render target +; texcoords: + +tex t0 ; sample dudv map +texbem t1, t0 ; refraction + +#if REFRACTTINTTEXTURE +tex t2 +#endif + +#if NORMALMAPALPHA +tex t3 +#endif + +; refracttint +#if REFRACTTINTTEXTURE +mul_x2 r0, t1, t2 +#else +mov r0, t1 +#endif + +#if NORMALMAPALPHA +mul r0.rgb, r0, c0 + +mov r0.a, t3.a +#else +mul r0.rgb, r0, c0 +#endif diff --git a/materialsystem/stdshaders/Refract_vs20.fxc b/materialsystem/stdshaders/Refract_vs20.fxc new file mode 100644 index 0000000..698dd19 --- /dev/null +++ b/materialsystem/stdshaders/Refract_vs20.fxc @@ -0,0 +1,140 @@ +//====== Copyright © 1996-2005, Valve Corporation, All rights reserved. ======= +// +// Purpose: +// +//============================================================================= + +// STATIC: "MODEL" "0..1" +// STATIC: "COLORMODULATE" "0..1" + +// DYNAMIC: "COMPRESSED_VERTS" "0..1" +// DYNAMIC: "SKINNING" "0..1" + +#include "common_vs_fxc.h" + +static const bool g_bSkinning = SKINNING ? true : false; +static const bool g_bModel = MODEL ? true : false; + +const float4 cBumpTexCoordTransform[4] : register( SHADER_SPECIFIC_CONST_1 ); + +const float g_flTime : register( SHADER_SPECIFIC_CONST_5 ); + +struct VS_INPUT +{ + float4 vPos : POSITION; + float4 vBoneWeights : BLENDWEIGHT; + float4 vBoneIndices : BLENDINDICES; + float4 vNormal : NORMAL; + float4 vBaseTexCoord : TEXCOORD0; +#if !MODEL + float3 vTangentS : TANGENT; + float3 vTangentT : BINORMAL0; +#else + float4 vUserData : TANGENT; +#endif +#if COLORMODULATE + float4 vColor : COLOR0; +#endif +}; + +struct VS_OUTPUT +{ + float4 vProjPos_POSITION : POSITION; +#if !defined( _X360 ) + float vFog : FOG; +#endif + float4 vBumpTexCoord : TEXCOORD0; + float3 vTangentEyeVect : TEXCOORD1; + float3 vWorldNormal : TEXCOORD2; + float3 vWorldTangent : TEXCOORD3; + float3 vWorldBinormal : TEXCOORD4; + float3 vRefractXYW : TEXCOORD5; + float3 vWorldViewVector : TEXCOORD6; +#if COLORMODULATE + float4 vColor : COLOR0; +#endif + float4 fogFactorW : COLOR1; + + float4 worldPos_projPosZ : TEXCOORD7; // Necessary for pixel fog +}; + +VS_OUTPUT main( const VS_INPUT v ) +{ + VS_OUTPUT o = ( VS_OUTPUT )0; + +#if COLORMODULATE + o.vColor = v.vColor; +#endif + + float3 worldNormal, worldPos, worldTangentS, worldTangentT; + + float3 vObjNormal; +#if MODEL + float4 vObjTangent; + DecompressVertex_NormalTangent( v.vNormal, v.vUserData, vObjNormal, vObjTangent ); + + SkinPositionNormalAndTangentSpace( + g_bSkinning, + v.vPos, vObjNormal, vObjTangent, + v.vBoneWeights, v.vBoneIndices, + worldPos, worldNormal, worldTangentS, worldTangentT ); +#else + DecompressVertex_Normal( v.vNormal, vObjNormal ); + + worldPos = mul( v.vPos, cModel[0] ); + worldTangentS = mul( v.vTangentS, ( const float3x3 )cModel[0] ); + worldTangentT = mul( v.vTangentT, ( const float3x3 )cModel[0] ); + worldNormal = mul( vObjNormal, ( float3x3 )cModel[0] ); +#endif + + // World normal + o.vWorldNormal.xyz = normalize( worldNormal.xyz ); + + // Projected position + float4 vProjPos = mul( float4( worldPos, 1 ), cViewProj ); + o.vProjPos_POSITION = vProjPos; + vProjPos.z = dot( float4( worldPos, 1 ), cViewProjZ ); + o.worldPos_projPosZ = float4( worldPos.xyz, vProjPos.z ); + //o.projNormal.xyz = mul( worldNormal, cViewProj ); + + // Map projected position to the refraction texture + float2 vRefractPos; + vRefractPos.x = vProjPos.x; + vRefractPos.y = -vProjPos.y; // invert Y + vRefractPos = (vRefractPos + vProjPos.w) * 0.5f; + + // Refraction transform + o.vRefractXYW = float3(vRefractPos.x, vRefractPos.y, vProjPos.w); + + // Compute fog based on the position + float3 vWorldPos = mul( v.vPos, cModel[0] ); + o.fogFactorW = CalcFog( vWorldPos, vProjPos, FOGTYPE_RANGE ); +#if !defined( _X360 ) + o.vFog = o.fogFactorW; +#endif + + // Eye vector + float3 vWorldEyeVect = normalize( cEyePos - vWorldPos ); + o.vWorldViewVector.xyz = -vWorldEyeVect.xyz; + + // Transform to the tangent space + o.vTangentEyeVect.x = dot( vWorldEyeVect, worldTangentS ); + o.vTangentEyeVect.y = dot( vWorldEyeVect, worldTangentT ); + o.vTangentEyeVect.z = dot( vWorldEyeVect, worldNormal ); + + // Tranform bump coordinates + o.vBumpTexCoord.x = dot( v.vBaseTexCoord, cBumpTexCoordTransform[0] ); + o.vBumpTexCoord.y = dot( v.vBaseTexCoord, cBumpTexCoordTransform[1] ); + + // Tranform bump coordinates (note wz, not zw) + o.vBumpTexCoord.w = dot( v.vBaseTexCoord, cBumpTexCoordTransform[2] ); + o.vBumpTexCoord.z = dot( v.vBaseTexCoord, cBumpTexCoordTransform[3] ); + + + // Tangent space transform + o.vWorldNormal.xyz = normalize( worldNormal.xyz ); + o.vWorldTangent.xyz = worldTangentS.xyz; + o.vWorldBinormal.xyz = worldTangentT.xyz; + + return o; +} diff --git a/materialsystem/stdshaders/Refract_world_vs11.vsh b/materialsystem/stdshaders/Refract_world_vs11.vsh new file mode 100644 index 0000000..90f0deb --- /dev/null +++ b/materialsystem/stdshaders/Refract_world_vs11.vsh @@ -0,0 +1,168 @@ +vs.1.1 + +# DYNAMIC: "DOWATERFOG" "0..1" + +;------------------------------------------------------------------------------ +; Constants specified by the app +; c0 = (0, 1, 2, 0.5) +; c1 = (1/2.2, 0, 0, 0) +; c2 = camera position *in world space* +; c4-c7 = modelViewProj matrix (transpose) +; c8-c11 = ViewProj matrix (transpose) +; c12-c15 = model->view matrix (transpose) +; c16 = [fogStart, fogEnd, fogRange, undefined] +; +; Vertex components (as specified in the vertex DECL) +; $vPos = Position +; $vTexCoord0.xy = TexCoord0 +;------------------------------------------------------------------------------ + +#include "macros.vsh" + +; Vertex components +; $vPos = Position +; $vNormal = normal +; $vTexCoord0.xy = TexCoord0 +; $vTangentS = S axis of Texture space +; $vTangentT = T axis of Texture space + +;------------------------------------------------------------------------------ +; Transform the position from world to view space +;------------------------------------------------------------------------------ + +alloc $worldPos +alloc $worldNormal +alloc $worldTangentS +alloc $worldTangentT +alloc $projPos + +dp4 $projPos.x, $vPos, $cModelViewProj0 +dp4 $projPos.y, $vPos, $cModelViewProj1 +dp4 $projPos.z, $vPos, $cModelViewProj2 +dp4 $projPos.w, $vPos, $cModelViewProj3 +mov oPos, $projPos + +dp3 $worldPos.x, $vPos, $cModel0 +dp3 $worldPos.y, $vPos, $cModel1 +dp3 $worldPos.z, $vPos, $cModel2 + +dp3 $worldNormal.x, $vNormal, $cModel0 +dp3 $worldNormal.y, $vNormal, $cModel1 +dp3 $worldNormal.z, $vNormal, $cModel2 + +dp3 $worldTangentS.x, $vTangentS, $cModel0 +dp3 $worldTangentS.y, $vTangentS, $cModel1 +dp3 $worldTangentS.z, $vTangentS, $cModel2 + +dp3 $worldTangentT.x, $vTangentT, $cModel0 +dp3 $worldTangentT.y, $vTangentT, $cModel1 +dp3 $worldTangentT.z, $vTangentT, $cModel2 + +&CalcFog( $worldPos, $projPos ); + +alloc $worldEyeVect + +; Get the eye vector in world space +add $worldEyeVect.xyz, -$worldPos, $cEyePos + +alloc $tangentEyeVect +alloc $bumpTexCoord + +; transform the eye vector to tangent space +dp3 $tangentEyeVect.x, $worldEyeVect, $worldTangentS +dp3 $tangentEyeVect.y, $worldEyeVect, $worldTangentT +dp3 $tangentEyeVect.z, $worldEyeVect, $worldNormal + +&Normalize( $tangentEyeVect ); + +; stick the tangent space eye vector into oD0 +mad oD0.xyz, $tangentEyeVect, $cHalf, $cHalf + +dp4 $bumpTexCoord.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_1 +dp4 $bumpTexCoord.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_2 + +; dudv map +mov oT0.xy, $bumpTexCoord + +; refract tint +mov oT3.xy, $bumpTexCoord + +free $bumpTexCoord + +alloc $newProjPos +alloc $w + +mov oPos, $projPos + +; special case perspective correct texture projection so that the texture fits exactly on the screen +mul $projPos.y, $projPos.y, $SHADER_SPECIFIC_CONST_4.w +add $projPos.xy, $projPos.xy, $projPos.w +mul $projPos.xy, $projPos.xy, $cHalf + +; Do the perspective divide here. .yuck . . we aren't going to be perspective correct +rcp $w.w, $projPos.w +mul $projPos, $projPos, $w.w + +#max $projPos.x, $projPos.x, -$cOne +#min $projPos.x, $projPos.x, $cOne +#max $projPos.z, $projPos.z, $cZero +#min $projPos.z, $projPos.z, $cOne + +;------------------------------------------------------------------------------ +; Transform the tangentS from world to view space +;------------------------------------------------------------------------------ + +alloc $projTangentS + +; we only care about x and y +dp3 $projTangentS.x, $worldTangentS, $cViewProj0 +dp3 $projTangentS.y, $worldTangentS, $cViewProj1 + +; project tangentS +mul $projTangentS.xy, $projTangentS.xy, $w.w + +;max $projTangentS.xy, $projTangentS.xy, $cOne +;min $projTangentS.xy, $projTangentS.xy, -$cOne + +;------------------------------------------------------------------------------ +; Transform the tangentT from world to view space +;------------------------------------------------------------------------------ + +alloc $projTangentT +alloc $texCoord + +; we only care about x and y +dp3 $projTangentT.x, $worldTangentT, $cViewProj0 +dp3 $projTangentT.y, $worldTangentT, $cViewProj1 + +; project tangentT +mul $projTangentT.xy, $projTangentT.xy, $w.w + +;max $projTangentT.xy, $projTangentT.xy, $cOne +;min $projTangentT.xy, $projTangentT.xy, -$cOne + +;max $projPos.xy, $projPos.xy, $cOne +;min $projPos.xy, $projPos.xy, -$cOne + +mul oT1.x, $projTangentS.x, $SHADER_SPECIFIC_CONST_3.x +mul oT1.y, $projTangentT.x, $SHADER_SPECIFIC_CONST_3.x +mov oT1.z, $projPos.x ; huh? + +mul $texCoord.x, $projTangentS.y, -$SHADER_SPECIFIC_CONST_3.x +mul $texCoord.y, $projTangentT.y, -$SHADER_SPECIFIC_CONST_3.x +mov $texCoord.z, $projPos.y +mov oT2.xyz, $texCoord +mov oT3.xyz, $texCoord + +free $texCoord +free $projPos +free $worldPos +free $worldEyeVect +free $tangentEyeVect +free $w +free $projTangentS +free $projTangentT +free $newProjPos +free $worldNormal +free $worldTangentS +free $worldTangentT diff --git a/materialsystem/stdshaders/ScreenSpaceEffect.vsh b/materialsystem/stdshaders/ScreenSpaceEffect.vsh new file mode 100644 index 0000000..8fd8113 --- /dev/null +++ b/materialsystem/stdshaders/ScreenSpaceEffect.vsh @@ -0,0 +1,29 @@ +vs.1.1 + +# DYNAMIC: "DOWATERFOG" "0..1" + +;------------------------------------------------------------------------------ +; Constants specified by the app +; c0 = (0, 1, 2, 0.5) +; c1 = (1/2.2, 3, 255, overbright factor) +; c2 = camera position *in world space* +; c4-c7 = modelViewProj matrix (transpose) +; c8-c11 = ViewProj matrix (transpose) +; c12-c15 = model->view matrix (transpose) +; c16 = [fogStart, fogEnd, fogRange, 1.0/fogRange] +; $SHADER_SPECIFIC_CONST_0-$SHADER_SPECIFIC_CONST_1 = Base texture transform +; $SHADER_SPECIFIC_CONST_2-$SHADER_SPECIFIC_CONST_3 = Mask texture transform +;------------------------------------------------------------------------------ + +#include "macros.vsh" + +;------------------------------------------------------------------------------ +; No vertex blending required. Input vertex data is in screen space +;------------------------------------------------------------------------------ +mov oPos.xyz, $vPos.xyz +mov oPos.w, $cOne + +;------------------------------------------------------------------------------ +; Pass any and all texture coordinates through +;------------------------------------------------------------------------------ +mov oT0, $vTexCoord0 diff --git a/materialsystem/stdshaders/SetZ.cpp b/materialsystem/stdshaders/SetZ.cpp new file mode 100644 index 0000000..43db384 --- /dev/null +++ b/materialsystem/stdshaders/SetZ.cpp @@ -0,0 +1,43 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: Naively sets the depth buffer values without testing the old values and without writing to alpha or color +// +// $NoKeywords: $ +//=============================================================================// + +#include "shaderlib/cshader.h" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +DEFINE_FALLBACK_SHADER( SetZ, SetZ_DX6 ) + +BEGIN_SHADER_FLAGS( SetZ_DX6, "Help for SetZ_DX6", SHADER_NOT_EDITABLE ) + BEGIN_SHADER_PARAMS + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + } + + SHADER_INIT + { + } + + SHADER_DRAW + { + SHADOW_STATE + { + pShaderShadow->EnableColorWrites( false ); + pShaderShadow->EnableAlphaWrites( false ); + pShaderShadow->DepthFunc( SHADER_DEPTHFUNC_ALWAYS ); + + pShaderShadow->DrawFlags( SHADER_DRAW_POSITION ); + } + DYNAMIC_STATE + { + } + Draw(); + } +END_SHADER + diff --git a/materialsystem/stdshaders/Shadow.psh b/materialsystem/stdshaders/Shadow.psh new file mode 100644 index 0000000..de9726b --- /dev/null +++ b/materialsystem/stdshaders/Shadow.psh @@ -0,0 +1,12 @@ +ps.1.1 + +def c0, 1.0f, 1.0f, 1.0f, 1.0f + +tex t0 + +; To accomplish shadow fading, subtract vertex alpha from texture alpha +; color channel isn't used... +sub_sat r0.a, t0.a, v0.a + +; Blend between white and the constant color... +lrp r0.rgba, 1-r0.a, c0, c1 diff --git a/materialsystem/stdshaders/ShadowBuildTexture.psh b/materialsystem/stdshaders/ShadowBuildTexture.psh new file mode 100644 index 0000000..a0d2f11 --- /dev/null +++ b/materialsystem/stdshaders/ShadowBuildTexture.psh @@ -0,0 +1,12 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; Use the vertex color, modulate vertex alpha by texture alpha +;------------------------------------------------------------------------------ +def c0, 1.0f, 1.0f, 1.0f, 1.0f + +tex t0 + +; relevant data is in alpha channel +mov r0.rgb, c0 + +mul r0.a, v0.a, t0.a diff --git a/materialsystem/stdshaders/ShadowModel.psh b/materialsystem/stdshaders/ShadowModel.psh new file mode 100644 index 0000000..31b6d78 --- /dev/null +++ b/materialsystem/stdshaders/ShadowModel.psh @@ -0,0 +1,22 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; Draw a texture . . woo hoo! +; t0 - texture +; +; The texture coordinates need to be defined as follows: +; tc0 - texcoords +;------------------------------------------------------------------------------ + +def c0,1.0f, 1.0f, 1.0f, 1.0f + +tex t0 ; shadow color +texkill t1 ; Clip +texkill t2 +texkill t3 ; backface cull + +; Darkening equation, compute a color = (shadow color * shadow alpha + 1- shadow alpha) +;sub r1, t0, v0.a ; r1 = shadow alpha +lrp r0.rgb, t0.a, v0, c0 + ; r0.rgb = (shadow color * shadow alpha + 1 - shadow alpha) +mov r0.a, c0.a ; r0.a = 1 + diff --git a/materialsystem/stdshaders/ShadowModel.vsh b/materialsystem/stdshaders/ShadowModel.vsh new file mode 100644 index 0000000..3e4b9eb --- /dev/null +++ b/materialsystem/stdshaders/ShadowModel.vsh @@ -0,0 +1,85 @@ +vs.1.1 + +# DYNAMIC: "DOWATERFOG" "0..1" +# DYNAMIC: "SKINNING" "0..1" + +;------------------------------------------------------------------------------ +; Constants specified by the app +; $SHADER_SPECIFIC_CONST_0-$SHADER_SPECIFIC_CONST_2 = Shadow texture matrix +; $SHADER_SPECIFIC_CONST_3 = Tex origin +; $SHADER_SPECIFIC_CONST_4 = Tex Scale +; $SHADER_SPECIFIC_CONST_5 = [Shadow falloff offset, 1/Shadow distance, Shadow scale, 0 ] +;------------------------------------------------------------------------------ + +#include "macros.vsh" + +;------------------------------------------------------------------------------ +; Vertex blending (whacks r1-r7, positions in r7, normals in r8) +;------------------------------------------------------------------------------ +&AllocateRegister( \$worldPos ); +&AllocateRegister( \$worldNormal ); +&SkinPositionAndNormal( $worldPos, $worldNormal ); + +; Transform the position from world to view space +&AllocateRegister( \$projPos ); + +dp4 $projPos.x, $worldPos, $cViewProj0 +dp4 $projPos.y, $worldPos, $cViewProj1 +dp4 $projPos.z, $worldPos, $cViewProj2 +dp4 $projPos.w, $worldPos, $cViewProj3 +mov oPos, $projPos + +;------------------------------------------------------------------------------ +; Fog +;------------------------------------------------------------------------------ +&CalcFog( $worldPos, $projPos ); +&FreeRegister( \$projPos ); + +;------------------------------------------------------------------------------ +; Transform position into texture space (from 0 to 1) +;------------------------------------------------------------------------------ +&AllocateRegister( \$texturePos ); +dp4 $texturePos.x, $worldPos, $SHADER_SPECIFIC_CONST_0 +dp4 $texturePos.y, $worldPos, $SHADER_SPECIFIC_CONST_1 +dp4 $texturePos.z, $worldPos, $SHADER_SPECIFIC_CONST_2 +&FreeRegister( \$worldPos ); + +;------------------------------------------------------------------------------ +; Figure out the shadow fade amount +;------------------------------------------------------------------------------ +&AllocateRegister( \$shadowFade ); +sub $shadowFade, $texturePos.z, $SHADER_SPECIFIC_CONST_5.x +mul $shadowFade, $shadowFade, $SHADER_SPECIFIC_CONST_5.y + +;------------------------------------------------------------------------------ +; Offset it into the texture +;------------------------------------------------------------------------------ +&AllocateRegister( \$actualTextureCoord ); +mul $actualTextureCoord.xyz, $SHADER_SPECIFIC_CONST_4, $texturePos +add oT0.xyz, $actualTextureCoord, $SHADER_SPECIFIC_CONST_3 +;mov oT0.xyz, $texturePos +&FreeRegister( \$actualTextureCoord ); + +;------------------------------------------------------------------------------ +; We're doing clipping by using texkill +;------------------------------------------------------------------------------ +mov oT1.xyz, $texturePos ; also clips when shadow z < 0 ! +sub oT2.xyz, $cOne, $texturePos +sub oT2.z, $cOne, $shadowFade.z ; clips when shadow z > shadow distance +&FreeRegister( \$texturePos ); + +;------------------------------------------------------------------------------ +; We're doing backface culling by using texkill also (wow yucky) +;------------------------------------------------------------------------------ +; Transform z component of normal in texture space +; If it's negative, then don't draw the pixel +dp3 oT3, $worldNormal, -$SHADER_SPECIFIC_CONST_2 +&FreeRegister( \$worldNormal ); + +;------------------------------------------------------------------------------ +; Shadow color, falloff +;------------------------------------------------------------------------------ +mov oD0, $cModulationColor +mul oD0.w, $shadowFade.x, $SHADER_SPECIFIC_CONST_5.z +&FreeRegister( \$shadowFade ); + diff --git a/materialsystem/stdshaders/ShatteredGlass.psh b/materialsystem/stdshaders/ShatteredGlass.psh new file mode 100644 index 0000000..30aa7d3 --- /dev/null +++ b/materialsystem/stdshaders/ShatteredGlass.psh @@ -0,0 +1,21 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; Draw a texture . . woo hoo! +; t0 - texture +; +; The texture coordinates need to be defined as follows: +; tc0 - texcoords +;------------------------------------------------------------------------------ + +def c1, 0.5f, 0.5f, 0.5f, 0.5f + +tex t0 +tex t1 +tex t3 + +mul r0, t0, v0 ; base times vertex color (with alpha) +mul r0, r0, t3 ; detail texture (with alpha) +lrp r1.rgb, c3, c1, t1 ; Blend between unlit + lightmap lighting +mul r0.rgb, r1, r0 ; fold in lightmap (color only) +mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2) diff --git a/materialsystem/stdshaders/ShatteredGlass.vsh b/materialsystem/stdshaders/ShatteredGlass.vsh new file mode 100644 index 0000000..76671ed --- /dev/null +++ b/materialsystem/stdshaders/ShatteredGlass.vsh @@ -0,0 +1,15 @@ +vs.1.1 + +# DYNAMIC: "DOWATERFOG" "0..1" + +#include "ShatteredGlass_inc.vsh" + +$detail = 1; +$envmap = 0; +$envmapcameraspace = 0; +$envmapsphere = 0; +$vertexcolor = 0; + +&ShatteredGlass( $detail, $envmap, $envmapcameraspace, $envmapsphere, + $vertexcolor ); + diff --git a/materialsystem/stdshaders/ShatteredGlass_EnvMap.psh b/materialsystem/stdshaders/ShatteredGlass_EnvMap.psh new file mode 100644 index 0000000..850f8e9 --- /dev/null +++ b/materialsystem/stdshaders/ShatteredGlass_EnvMap.psh @@ -0,0 +1,26 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; Draw a texture . . woo hoo! +; t0 - texture +; +; The texture coordinates need to be defined as follows: +; tc0 - texcoords +; c1 - self-illum tint +; c2 - envmap tint +;------------------------------------------------------------------------------ + +def c1, 0.5f, 0.5f, 0.5f, 0.5f + +tex t0 +tex t1 +tex t2 +tex t3 + +mul r0, t0, v0 ; base times vertex color (with alpha) +mul r0, r0, t3 ; detail texture (with alpha) +lrp r1.rgb, c3, c1, t1 ; Blend between unlit + lightmap lighting +mul r0.rgb, r1, r0 ; fold in lightmap (color only) +mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2) +mul r1, t2, t0 ; envmap * envmapmask (base == envmapmask) +mad r0.rgb, r1, c2, r0 ; + envmap * envmapmask * envmaptint (color only) diff --git a/materialsystem/stdshaders/ShatteredGlass_EnvMap.vsh b/materialsystem/stdshaders/ShatteredGlass_EnvMap.vsh new file mode 100644 index 0000000..ae8d297 --- /dev/null +++ b/materialsystem/stdshaders/ShatteredGlass_EnvMap.vsh @@ -0,0 +1,15 @@ +vs.1.1 + +# DYNAMIC: "DOWATERFOG" "0..1" + +#include "ShatteredGlass_inc.vsh" + +$detail = 1; +$envmap = 1; +$envmapcameraspace = 0; +$envmapsphere = 0; +$vertexcolor = 0; + +&ShatteredGlass( $detail, $envmap, $envmapcameraspace, $envmapsphere, + $vertexcolor ); + diff --git a/materialsystem/stdshaders/ShatteredGlass_EnvMapSphere.vsh b/materialsystem/stdshaders/ShatteredGlass_EnvMapSphere.vsh new file mode 100644 index 0000000..aa31ad1 --- /dev/null +++ b/materialsystem/stdshaders/ShatteredGlass_EnvMapSphere.vsh @@ -0,0 +1,15 @@ +vs.1.1 + +# DYNAMIC: "DOWATERFOG" "0..1" + +#include "ShatteredGlass_inc.vsh" + +$detail = 1; +$envmap = 1; +$envmapcameraspace = 0; +$envmapsphere = 1; +$vertexcolor = 0; + +&ShatteredGlass( $detail, $envmap, $envmapcameraspace, $envmapsphere, + $vertexcolor ); + diff --git a/materialsystem/stdshaders/ShatteredGlass_inc.vsh b/materialsystem/stdshaders/ShatteredGlass_inc.vsh new file mode 100644 index 0000000..608bb2a --- /dev/null +++ b/materialsystem/stdshaders/ShatteredGlass_inc.vsh @@ -0,0 +1,105 @@ +#include "macros.vsh" + +;------------------------------------------------------------------------------ +; $SHADER_SPECIFIC_CONST_0-$SHADER_SPECIFIC_CONST_1 = Base texture transform + envmap mask transform +; $SHADER_SPECIFIC_CONST_2-$SHADER_SPECIFIC_CONST_3 = Detail texture transform +;------------------------------------------------------------------------------ + +sub ShatteredGlass +{ + local( $detail ) = shift; + local( $envmap ) = shift; + local( $envmapcameraspace ) = shift; + local( $envmapsphere ) = shift; + local( $vertexcolor ) = shift; + + local( $worldPos, $worldNormal, $projPos, $reflectionVector ); + + &AllocateRegister( \$projPos ); + + dp4 $projPos.x, $vPos, $cModelViewProj0 + dp4 $projPos.y, $vPos, $cModelViewProj1 + dp4 $projPos.z, $vPos, $cModelViewProj2 + dp4 $projPos.w, $vPos, $cModelViewProj3 + mov oPos, $projPos + + &AllocateRegister( \$worldPos ); + + if( $DOWATERFOG == 1 ) + { + ; Get the worldpos z component only since that's all we need for height fog + dp4 $worldPos.z, $vPos, $cModel2 + } + &CalcFog( $worldPos, $projPos ); + &FreeRegister( \$projPos ); + + ;------------------------------------------------------------------------------ + ; Texture coordinates + ;------------------------------------------------------------------------------ + ; base texcoords + dp4 oT0.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_0 + dp4 oT0.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_1 + + ; lightmap texcoords + mov oT1, $vTexCoord1 + + if( $envmap ) + { + &AllocateRegister( \$worldNormal ); + + ; Transform the position + normal to world space + dp4 $worldPos.x, $vPos, $cModel0 + dp4 $worldPos.y, $vPos, $cModel1 + if( $DOWATERFOG == 0 ) + { + dp4 $worldPos.z, $vPos, $cModel2 + } + + dp3 $worldNormal.x, $vNormal, $cModel0 + dp3 $worldNormal.y, $vNormal, $cModel1 + dp3 $worldNormal.z, $vNormal, $cModel2 + + if( $envmapcameraspace ) + { + &AllocateRegister( \$reflectionVector ); + &ComputeReflectionVector( $worldPos, $worldNormal, $reflectionVector ); + ; transform reflection vector into view space + dp3 oT2.x, $reflectionVector, $cViewModel0 + dp3 oT2.y, $reflectionVector, $cViewModel1 + dp3 oT2.z, $reflectionVector, $cViewModel2 + &FreeRegister( \$reflectionVector ); + } + elsif( $envmapsphere ) + { + &AllocateRegister( \$reflectionVector ); + &ComputeReflectionVector( $worldPos, $worldNormal, $reflectionVector ); + &ComputeSphereMapTexCoords( $reflectionVector, "oT2" ); + &FreeRegister( \$reflectionVector ); + } + else + { + &ComputeReflectionVector( $worldPos, $worldNormal, "oT2" ); + } + + &FreeRegister( \$worldNormal ); + } + + &FreeRegister( \$worldPos ); + + if( $detail ) + { + dp4 oT3.x, $vTexCoord2, $SHADER_SPECIFIC_CONST_2 + dp4 oT3.y, $vTexCoord2, $SHADER_SPECIFIC_CONST_3 + } + + if( $vertexcolor ) + { + ; Modulation color + mul oD0, $vColor, $cModulationColor + } + else + { + ; Modulation color + mov oD0, $cModulationColor + } +} diff --git a/materialsystem/stdshaders/ShatteredGlass_ps2x.fxc b/materialsystem/stdshaders/ShatteredGlass_ps2x.fxc new file mode 100644 index 0000000..c0df044 --- /dev/null +++ b/materialsystem/stdshaders/ShatteredGlass_ps2x.fxc @@ -0,0 +1,130 @@ +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX] +// STATIC: "CUBEMAP" "0..1" +// STATIC: "VERTEXCOLOR" "0..1" +// STATIC: "ENVMAPMASK" "0..1" +// STATIC: "BASEALPHAENVMAPMASK" "0..1" +// STATIC: "HDRTYPE" "0..2" + +// DYNAMIC: "HDRENABLED" "0..1" +// DYNAMIC: "PIXELFOGTYPE" "0..1" + +// HDRFIXME: Need to make this work. + +#define USE_32BIT_LIGHTMAPS_ON_360 //uncomment to use 32bit lightmaps, be sure to keep this in sync with the same #define in materialsystem/cmatlightmaps.cpp + +#include "common_ps_fxc.h" +#include "common_lightmappedgeneric_fxc.h" + +const HALF4 g_EnvmapTint : register( c0 ); +const HALF3 g_DiffuseModulation : register( c1 ); +const HALF3 g_EnvmapContrast : register( c2 ); +const HALF3 g_EnvmapSaturation : register( c3 ); +const HALF4 g_FresnelReflection : register( c4 ); +const HALF3 g_EyePos : register( c5 ); +const HALF3 g_OverbrightFactor : register( c6 ); + +const HALF4 g_FogParams : register( c12 ); + +// CENTROID: TEXCOORD2 + +sampler BaseTextureSampler : register( s0 ); +sampler LightmapSampler : register( s1 ); +sampler EnvmapSampler : register( s2 ); +sampler DetailSampler : register( s3 ); +sampler EnvmapMaskSampler : register( s5 ); + +sampler NormalizeSampler : register( s6 ); + +struct PS_INPUT +{ + HALF2 baseTexCoord : TEXCOORD0; + HALF2 detailTexCoord : TEXCOORD1; + HALF2 lightmapTexCoord : TEXCOORD2; + HALF2 envmapMaskTexCoord : TEXCOORD3; + HALF4 worldPos_projPosZ : TEXCOORD4; + HALF3 worldSpaceNormal : TEXCOORD5; + HALF4 vertexColor : COLOR; + HALF4 fogFactorW : COLOR1; +}; + +float4 main( PS_INPUT i ) : COLOR +{ + bool bCubemap = CUBEMAP ? true : false; + bool bVertexColor = VERTEXCOLOR ? true : false; + bool bEnvmapMask = ENVMAPMASK ? true : false; + bool bBaseAlphaEnvmapMask = BASEALPHAENVMAPMASK ? true : false; + + HALF4 baseColor = tex2D( BaseTextureSampler, i.baseTexCoord ); + HALF4 detailColor = tex2D( DetailSampler, i.detailTexCoord ); + + HALF2 lightmapCoordinates = i.lightmapTexCoord; + HALF3 lightmapColor = LightMapSample( LightmapSampler, lightmapCoordinates ); + + HALF3 specularFactor = 1.0f; + if( bEnvmapMask ) + { + specularFactor = tex2D( EnvmapMaskSampler, i.detailTexCoord ).xyz; + } + + if( bBaseAlphaEnvmapMask ) + { + specularFactor *= 1.0 - baseColor.a; // this blows! + } + + HALF3 diffuseLighting = lightmapColor; + diffuseLighting *= g_DiffuseModulation; + diffuseLighting *= LIGHT_MAP_SCALE; + + HALF3 albedo = baseColor; + HALF alpha = 1.0f; + + if( !bBaseAlphaEnvmapMask ) + { + alpha *= baseColor.a; + } + + albedo *= detailColor; + alpha *= detailColor.a; + + // FIXME: seperate vertexcolor and vertexalpha? + // vertex alpha is ignored if vertexcolor isn't set. . need to check other version. + if( bVertexColor ) + { + albedo *= i.vertexColor; + alpha *= i.vertexColor.a; // not sure about this one + } + + HALF3 specularLighting = HALF3( 0.0f, 0.0f, 0.0f ); + if( bCubemap ) + { + float3 worldVertToEyeVector = g_EyePos - i.worldPos_projPosZ.xyz; + worldVertToEyeVector = NormalizeWithCubemap( NormalizeSampler, worldVertToEyeVector ); + HALF3 reflectVect = CalcReflectionVectorUnnormalized( i.worldSpaceNormal, worldVertToEyeVector ); + + // Calc Fresnel factor + HALF3 worldSpaceNormal = NormalizeWithCubemap( NormalizeSampler, i.worldSpaceNormal ); + HALF fresnel = 1.0 - dot( worldSpaceNormal, worldVertToEyeVector ); + fresnel = pow( fresnel, 5.0 ); + fresnel = fresnel * g_FresnelReflection.b + g_FresnelReflection.a; + + specularLighting = texCUBE( EnvmapSampler, reflectVect ); + specularLighting *= specularFactor; + + specularLighting *= g_EnvmapTint; +#if HDRTYPE == HDR_TYPE_NONE + HALF3 specularLightingSquared = specularLighting * specularLighting; + specularLighting = lerp( specularLighting, specularLightingSquared, g_EnvmapContrast ); + HALF3 greyScale = dot( specularLighting, HALF3( 0.299f, 0.587f, 0.114f ) ); + specularLighting = lerp( greyScale, specularLighting, g_EnvmapSaturation ); +#endif + specularLighting *= fresnel; + } + + // Do it somewhat unlit + HALF3 result = albedo*(g_OverbrightFactor.z*diffuseLighting + g_OverbrightFactor.y) + specularLighting; + + float fogFactor = CalcPixelFogFactor( PIXELFOGTYPE, g_FogParams, g_EyePos.z, i.worldPos_projPosZ.z, i.worldPos_projPosZ.w ); + return FinalOutput( HALF4( result, alpha ), fogFactor, PIXELFOGTYPE, TONEMAP_SCALE_LINEAR ); +} + diff --git a/materialsystem/stdshaders/ShatteredGlass_vs20.fxc b/materialsystem/stdshaders/ShatteredGlass_vs20.fxc new file mode 100644 index 0000000..33fa004 --- /dev/null +++ b/materialsystem/stdshaders/ShatteredGlass_vs20.fxc @@ -0,0 +1,70 @@ +// DYNAMIC: "DOWATERFOG" "0..1" +// STATIC: "ENVMAP_MASK" "0..1" +#include "common_vs_fxc.h" + +static const int g_FogType = DOWATERFOG; +static const bool g_UseSeparateEnvmapMask = ENVMAP_MASK; + +const float4 cBaseTexCoordTransform[2] : register( SHADER_SPECIFIC_CONST_0 ); +const float4 cDetailTexCoordTransform[2] : register( SHADER_SPECIFIC_CONST_2 ); + +struct VS_INPUT +{ + float3 vPos : POSITION; + float4 vNormal : NORMAL; + float2 vBaseTexCoord : TEXCOORD0; + float2 vLightmapTexCoord : TEXCOORD1; + float2 vDetailTexCoord : TEXCOORD2; +}; + +struct VS_OUTPUT +{ + float4 projPos : POSITION; +#if !defined( _X360 ) + float fog : FOG; +#endif + float2 baseTexCoord : TEXCOORD0; + float2 detailTexCoord : TEXCOORD1; + float2 lightmapTexCoord : TEXCOORD2; + float2 envmapMaskTexCoord : TEXCOORD3; + float4 worldPos_projPosZ : TEXCOORD4; + float3 worldNormal : TEXCOORD5; + float4 vertexColor : COLOR; + float4 fogFactorW : COLOR1; +}; + +VS_OUTPUT main( const VS_INPUT v ) +{ + VS_OUTPUT o = ( VS_OUTPUT )0; + + float3 vObjNormal; + DecompressVertex_Normal( v.vNormal, vObjNormal ); + + float4 projPos; + projPos = mul( float4( v.vPos, 1 ), cModelViewProj ); + o.projPos = projPos; + projPos.z = dot( float4( v.vPos, 1 ), cModelViewProjZ ); + + o.worldPos_projPosZ.w = projPos.z; + o.worldPos_projPosZ.xyz = mul( float4( v.vPos, 1 ), cModel[0] ); + o.worldNormal = mul( vObjNormal, ( float3x3 )cModel[0] ); + o.baseTexCoord.x = dot( v.vBaseTexCoord, cBaseTexCoordTransform[0] ) + cBaseTexCoordTransform[0].w; + o.baseTexCoord.y = dot( v.vBaseTexCoord, cBaseTexCoordTransform[1] ) + cBaseTexCoordTransform[1].w; + o.detailTexCoord.x = dot( v.vDetailTexCoord, cDetailTexCoordTransform[0] ) + cDetailTexCoordTransform[0].w; + o.detailTexCoord.y = dot( v.vDetailTexCoord, cDetailTexCoordTransform[1] ) + cDetailTexCoordTransform[1].w; + o.envmapMaskTexCoord.x = dot( v.vDetailTexCoord, cDetailTexCoordTransform[0] ) + cDetailTexCoordTransform[0].w; + o.envmapMaskTexCoord.y = dot( v.vDetailTexCoord, cDetailTexCoordTransform[1] ) + cDetailTexCoordTransform[1].w; + o.lightmapTexCoord = v.vLightmapTexCoord; + + + + o.fogFactorW = CalcFog( o.worldPos_projPosZ.xyz, projPos, g_FogType ); +#if !defined( _X360 ) + o.fog = o.fogFactorW; +#endif + o.vertexColor = cModulationColor; + + return o; +} + + diff --git a/materialsystem/stdshaders/SpriteRenderNormal.psh b/materialsystem/stdshaders/SpriteRenderNormal.psh new file mode 100644 index 0000000..0321ffb --- /dev/null +++ b/materialsystem/stdshaders/SpriteRenderNormal.psh @@ -0,0 +1,5 @@ +ps.1.1 + +tex t0 + +mov r0, t0 diff --git a/materialsystem/stdshaders/SpriteRenderTransAdd.psh b/materialsystem/stdshaders/SpriteRenderTransAdd.psh new file mode 100644 index 0000000..5447082 --- /dev/null +++ b/materialsystem/stdshaders/SpriteRenderTransAdd.psh @@ -0,0 +1,7 @@ +ps.1.1 + +tex t0 + +;mul r0, t0, v0 +mul r0, t0, c0 + diff --git a/materialsystem/stdshaders/SpriteRenderTransColor.psh b/materialsystem/stdshaders/SpriteRenderTransColor.psh new file mode 100644 index 0000000..b8debbd --- /dev/null +++ b/materialsystem/stdshaders/SpriteRenderTransColor.psh @@ -0,0 +1,5 @@ +ps.1.1 + +tex t0 + +mul r0, t0, v0 diff --git a/materialsystem/stdshaders/Teeth.vsh b/materialsystem/stdshaders/Teeth.vsh new file mode 100644 index 0000000..065f070 --- /dev/null +++ b/materialsystem/stdshaders/Teeth.vsh @@ -0,0 +1,97 @@ +vs.1.1 + +# STATIC: "INTRO" "0..1" +# STATIC: "HALF_LAMBERT" "0..1" +# DYNAMIC: "DOWATERFOG" "0..1" +# DYNAMIC: "LIGHT_COMBO" "0..21" +# DYNAMIC: "SKINNING" "0..1" + +;------------------------------------------------------------------------------ +; $SHADER_SPECIFIC_CONST_0 = xyz = mouth forward direction vector, w = illum factor +;------------------------------------------------------------------------------ + +#include "macros.vsh" + +$WARPPARAM = $SHADER_SPECIFIC_CONST_2; +$ENTITY_ORIGIN = $SHADER_SPECIFIC_CONST_3; + +;------------------------------------------------------------------------------ +; Vertex blending +;------------------------------------------------------------------------------ +alloc $worldPos +alloc $worldNormal +&SkinPositionAndNormal( $worldPos, $worldNormal ); + +;------------------------------------------------------------------------------ +; Optional intro warping +;------------------------------------------------------------------------------ +if ( $INTRO == 1 ) +{ + alloc $tmp + sub $tmp.xyz, $worldPos, $ENTITY_ORIGIN + mul $tmp.xy, $tmp, $WARPPARAM + add $worldPos.xyz, $tmp, $ENTITY_ORIGIN + free $tmp +} + +;------------------------------------------------------------------------------ +; Transform the position from world to view space +;------------------------------------------------------------------------------ + +alloc $projPos + +dp4 $projPos.x, $worldPos, $cViewProj0 +dp4 $projPos.y, $worldPos, $cViewProj1 +dp4 $projPos.z, $worldPos, $cViewProj2 +dp4 $projPos.w, $worldPos, $cViewProj3 +mov oPos, $projPos + +;------------------------------------------------------------------------------ +; Fog +;------------------------------------------------------------------------------ + +&CalcFog( $worldPos, $projPos ); + +free $projPos + +;------------------------------------------------------------------------------ +; Lighting +;------------------------------------------------------------------------------ +alloc $linearColor +&DoDynamicLightingToLinear( $worldPos, $worldNormal, $linearColor ); + +;------------------------------------------------------------------------------ +; Factor in teeth darkening factors +;------------------------------------------------------------------------------ + +alloc $tmp + +mul $linearColor.xyz, $SHADER_SPECIFIC_CONST_0.w, $linearColor ; FIXME Color darkened by illumination factor +dp3 $tmp, $worldNormal, $SHADER_SPECIFIC_CONST_0 ; Figure out mouth forward dot normal +max $tmp, $cZero, $tmp ; clamp from 0 to 1 +mul $linearColor.xyz, $tmp, $linearColor ; Darken by forward dot normal too + +;------------------------------------------------------------------------------ +; Output color (gamma correction) +;------------------------------------------------------------------------------ + +alloc $gammaColor +&LinearToGamma( $linearColor, $gammaColor ); +free $linearColor +mul oD0.xyz, $gammaColor.xyz, $cOverbrightFactor +mov oD0.w, $cOne ; make sure all components are defined + + +free $gammaColor +free $worldPos +free $worldNormal +free $tmp + +;------------------------------------------------------------------------------ +; Texture coordinates +;------------------------------------------------------------------------------ + +mov oT0, $vTexCoord0 + + + diff --git a/materialsystem/stdshaders/TreeLeaf.cpp b/materialsystem/stdshaders/TreeLeaf.cpp new file mode 100644 index 0000000..5f87f1b --- /dev/null +++ b/materialsystem/stdshaders/TreeLeaf.cpp @@ -0,0 +1,102 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $Header: $ +// $NoKeywords: $ +//=============================================================================// + +#include "BaseVSShader.h" + +#include "treeleaf_ps20.inc" +#include "treeleaf_ps20b.inc" +#include "treeleaf_vs20.inc" + +BEGIN_VS_SHADER_FLAGS( TreeLeaf, "Help for TreeLeaf", SHADER_NOT_EDITABLE ) + + BEGIN_SHADER_PARAMS + SHADER_PARAM( LEAFCENTER, SHADER_PARAM_TYPE_VEC3, "[0 0 0]", "Center of leaf cluster for lighting" ) + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + } + + SHADER_FALLBACK + { + if ( g_pHardwareConfig->GetDXSupportLevel() < 90 ) + { + return "Wireframe"; + } + return 0; + } + + SHADER_INIT + { + SET_FLAGS2( MATERIAL_VAR2_LIGHTING_VERTEX_LIT ); + + if ( params[BASETEXTURE]->IsDefined() ) + { + LoadTexture( BASETEXTURE ); + } + } + + SHADER_DRAW + { + SHADOW_STATE + { + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + + pShaderShadow->EnableAlphaTest( true ); + pShaderShadow->AlphaFunc( SHADER_ALPHAFUNC_GREATER, 0.5f ); + + unsigned int flags = VERTEX_POSITION | VERTEX_NORMAL; + int numTexCoords = 1; + pShaderShadow->VertexShaderVertexFormat( flags, numTexCoords, 0, 0 ); + + bool bUseStaticControlFlow = g_pHardwareConfig->SupportsStaticControlFlow(); + + DECLARE_STATIC_VERTEX_SHADER( treeleaf_vs20 ); + SET_STATIC_VERTEX_SHADER_COMBO( HALFLAMBERT, true ); + SET_STATIC_VERTEX_SHADER_COMBO( USE_STATIC_CONTROL_FLOW, bUseStaticControlFlow ); + SET_STATIC_VERTEX_SHADER( treeleaf_vs20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_STATIC_PIXEL_SHADER( treeleaf_ps20b ); + SET_STATIC_PIXEL_SHADER( treeleaf_ps20b ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( treeleaf_ps20 ); + SET_STATIC_PIXEL_SHADER( treeleaf_ps20 ); + } + + // we are writing linear values from this shader. + // This is kinda wrong. We are writing linear or gamma depending on "IsHDREnabled" below. + // The COLOR really decides if we are gamma or linear. + pShaderShadow->EnableSRGBWrite( false ); + } + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME ); + + // We need the view matrix + LoadViewMatrixIntoVertexShaderConstant( VERTEX_SHADER_VIEWMODEL ); + + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, params[ LEAFCENTER ]->GetVecValue() ); + + LightState_t lightState; + pShaderAPI->GetDX9LightState( &lightState ); + + bool bUseStaticControlFlow = g_pHardwareConfig->SupportsStaticControlFlow(); + + DECLARE_DYNAMIC_VERTEX_SHADER( treeleaf_vs20 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( DYNAMIC_LIGHT, lightState.HasDynamicLight() ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( STATIC_LIGHT, lightState.m_bStaticLightVertex ? 1 : 0 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( NUM_LIGHTS, bUseStaticControlFlow ? 0 : lightState.m_nNumLights ); + SET_DYNAMIC_VERTEX_SHADER( treeleaf_vs20 ); + } + Draw( ); + } +END_SHADER diff --git a/materialsystem/stdshaders/TreeLeaf_ps2x.fxc b/materialsystem/stdshaders/TreeLeaf_ps2x.fxc new file mode 100644 index 0000000..4e9aa00 --- /dev/null +++ b/materialsystem/stdshaders/TreeLeaf_ps2x.fxc @@ -0,0 +1,20 @@ +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX] + +#define HDRTYPE HDR_TYPE_NONE +#include "common_ps_fxc.h" + +struct PS_INPUT +{ + float2 texCoord0 : TEXCOORD0; + float3 color : COLOR; +}; + +sampler BaseTextureSampler : register( s0 ); + +HALF4 main( PS_INPUT i ) : COLOR +{ + float4 baseTex = tex2D( BaseTextureSampler, i.texCoord0 ); + return FinalOutput( baseTex * float4( i.color, 1 ), 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE ); +} + diff --git a/materialsystem/stdshaders/TreeLeaf_vs20.fxc b/materialsystem/stdshaders/TreeLeaf_vs20.fxc new file mode 100644 index 0000000..a097592 --- /dev/null +++ b/materialsystem/stdshaders/TreeLeaf_vs20.fxc @@ -0,0 +1,72 @@ +// STATIC: "HALFLAMBERT" "0..1" +// STATIC: "USE_STATIC_CONTROL_FLOW" "0..1" [vs20] + +// DYNAMIC: "DYNAMIC_LIGHT" "0..1" +// DYNAMIC: "STATIC_LIGHT" "0..1" +// DYNAMIC: "NUM_LIGHTS" "0..2" [vs20] + +// If using static control flow on Direct3D, we should use the NUM_LIGHTS=0 combo +// SKIP: $USE_STATIC_CONTROL_FLOW && ( $NUM_LIGHTS > 0 ) [vs20] + +#include "common_vs_fxc.h" + +static const bool g_bHalfLambert = HALFLAMBERT ? true : false; + +const float3 cLeafCenter : register(SHADER_SPECIFIC_CONST_0); + +struct VS_INPUT +{ + // This is all of the stuff that we ever use. + float4 vPos : POSITION; + float4 vNormal : NORMAL; + float2 vTexCoord : TEXCOORD0; +}; + +struct VS_OUTPUT +{ + float4 projPos : POSITION; + float2 texCoord : TEXCOORD0; + float3 color : COLOR; +}; + +VS_OUTPUT main( const VS_INPUT v ) +{ + VS_OUTPUT o = ( VS_OUTPUT )0; + + bool bDynamicLight = DYNAMIC_LIGHT ? true : false; + bool bStaticLight = STATIC_LIGHT ? true : false; + + float3 worldPos; + worldPos = mul( v.vPos, cModel[0] ); + + float3 normal = v.vPos.xyz - cLeafCenter.xyz; + normal = normalize( normal ); + + float3 worldNormal = mul( float4( normal, 0.0f ), cModel[0] ); + +#if ( USE_STATIC_CONTROL_FLOW ) || defined ( SHADER_MODEL_VS_3_0 ) + float3 lighting = DoLighting( worldPos, worldNormal, float3(0,0,0), bStaticLight, bDynamicLight, g_bHalfLambert ); +#else + float3 lighting = DoLightingUnrolled( worldPos, worldNormal, float3(0,0,0), bStaticLight, bDynamicLight, g_bHalfLambert, NUM_LIGHTS ); +#endif + + float3 xAxis = float3( cViewModel[0].x, cViewModel[1].x, cViewModel[2].x ); + float3 yAxis = float3( cViewModel[0].y, cViewModel[1].y, cViewModel[2].y ); + + worldPos += xAxis * v.vTexCoord.x; + worldPos += yAxis * (1.0f-v.vTexCoord.y); + + float4 projPos = mul( float4(worldPos, 1.0f), cViewProj ); + + float3 light_vec = float3( 1.0f, 0.0, 1.0 ); + light_vec = normalize( light_vec ); + + o.projPos = projPos; + // FIXME: if this shader gets put back into use, be sure this usage of normals jives with compressed verts + o.texCoord = v.vNormal.xy; + o.color = lighting; + + return o; +} + + diff --git a/materialsystem/stdshaders/UPDB_X360/dummy.txt b/materialsystem/stdshaders/UPDB_X360/dummy.txt new file mode 100644 index 0000000..6b3fb4d --- /dev/null +++ b/materialsystem/stdshaders/UPDB_X360/dummy.txt @@ -0,0 +1,3 @@ +This directory needs to pre-exist for dynamic shader compile updb generation on Xbox 360. + +I was unsuccessful at creating the directory at runtime in code across the network. So I'm letting perforce create it with this file. \ No newline at end of file diff --git a/materialsystem/stdshaders/UnlitGeneric.psh b/materialsystem/stdshaders/UnlitGeneric.psh new file mode 100644 index 0000000..409ee0d --- /dev/null +++ b/materialsystem/stdshaders/UnlitGeneric.psh @@ -0,0 +1,13 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; Draw a texture . . woo hoo! +; t0 - texture +; +; The texture coordinates need to be defined as follows: +; tc0 - texcoords +;------------------------------------------------------------------------------ + +tex t0 ; base color + +mul r0, t0, v0 \ No newline at end of file diff --git a/materialsystem/stdshaders/UnlitGeneric_BaseAlphaMaskedEnvMap.psh b/materialsystem/stdshaders/UnlitGeneric_BaseAlphaMaskedEnvMap.psh new file mode 100644 index 0000000..32ec9c6 --- /dev/null +++ b/materialsystem/stdshaders/UnlitGeneric_BaseAlphaMaskedEnvMap.psh @@ -0,0 +1,19 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; Draw a texture . . woo hoo! +; t0 - texture +; +; The texture coordinates need to be defined as follows: +; tc0 - texcoords +; c2 - envmaptint +;------------------------------------------------------------------------------ + +tex t0 ; base color +tex t1 ; cube map +tex t2 ; envmap mask + +mul r0.rgb, t1, 1-t2.a ; can't use mad cause can't use 3 texture registers +mul r0.rgb, c2, r0 ; apply the envmaptint +mad r0.rgb, t0, v0, r0 ++ mul r0.a, t0, v0 diff --git a/materialsystem/stdshaders/UnlitGeneric_Detail.psh b/materialsystem/stdshaders/UnlitGeneric_Detail.psh new file mode 100644 index 0000000..421d2d3 --- /dev/null +++ b/materialsystem/stdshaders/UnlitGeneric_Detail.psh @@ -0,0 +1,15 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; Draw a texture . . woo hoo! +; t0 - texture +; +; The texture coordinates need to be defined as follows: +; tc0 - texcoords +;------------------------------------------------------------------------------ + +tex t0 ; base color +tex t3 ; detail texture + +mul r0, t0, v0 +mul_x2 r0.rgb, r0, t3 \ No newline at end of file diff --git a/materialsystem/stdshaders/UnlitGeneric_DetailBaseAlphaMaskedEnvMap.psh b/materialsystem/stdshaders/UnlitGeneric_DetailBaseAlphaMaskedEnvMap.psh new file mode 100644 index 0000000..7d234bb --- /dev/null +++ b/materialsystem/stdshaders/UnlitGeneric_DetailBaseAlphaMaskedEnvMap.psh @@ -0,0 +1,29 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; Draw a texture . . woo hoo! +; t0 - texture +; +; The texture coordinates need to be defined as follows: +; tc0 - texcoords +; c2 - envmaptint +;------------------------------------------------------------------------------ + +tex t0 ; base color +tex t1 ; cube map +tex t2 ; envmap mask +tex t3 ; detail texture + +; version 1: applies the mod2x *after* environment map +;mul r0.rgb, t1, 1-t2.a ; can't use mad cause can't use 3 texture registers +;mul r0.rgb, c2, r0 ; apply the envmaptint +;mad r0.rgb, t0, v0, r0 +;+ mul r0.a, t0, v0 +;mul_x2 r0.rgb, r0, t3 ; mod2x detail texture + +; version 2: applies the mod2x *before* environment map +mul r0, t0, v0 ; Base times modulation color +mul_x2 r0.rgb, r0, t3 ; mod2x detail texture +mul r1, t1, 1-t2.a ; Have to invert the alpha for basealpha (feh!) +mul r1, c2, r1 ; apply the envmaptint +add r0.rgb, r0, r1 ; add in the envmap diff --git a/materialsystem/stdshaders/UnlitGeneric_DetailEnvMap.psh b/materialsystem/stdshaders/UnlitGeneric_DetailEnvMap.psh new file mode 100644 index 0000000..6e8fde9 --- /dev/null +++ b/materialsystem/stdshaders/UnlitGeneric_DetailEnvMap.psh @@ -0,0 +1,25 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; Draw a texture . . woo hoo! +; t0 - texture +; +; The texture coordinates need to be defined as follows: +; tc0 - texcoords +; c2 - envmaptint +;------------------------------------------------------------------------------ + +tex t0 ; base color +tex t1 ; cube map +tex t3 ; detail texture + +; version 1: applies the mod2x *after* environment map +;mul r1, c2, t1 +;mad r0.rgb, t0, v0, r1 +;+ mul r0.a, t0, v0 +;mul_x2 r0.rgb, r0, t3 ; mod2x detail texture + +; version 2: applies the mod2x *before* environment map +mul r0, t0, v0 ; Base times modulation color +mul_x2 r0.rgb, r0, t3 ; mod2x detail texture +mad r0.rgb, c2, t1, r0 ; add in tinted envmap diff --git a/materialsystem/stdshaders/UnlitGeneric_DetailEnvMapMask.psh b/materialsystem/stdshaders/UnlitGeneric_DetailEnvMapMask.psh new file mode 100644 index 0000000..93786ad --- /dev/null +++ b/materialsystem/stdshaders/UnlitGeneric_DetailEnvMapMask.psh @@ -0,0 +1,29 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; Draw a texture . . woo hoo! +; t0 - texture +; +; The texture coordinates need to be defined as follows: +; tc0 - texcoords +; c2 - envmaptint +;------------------------------------------------------------------------------ + +tex t0 ; base color +tex t1 ; cube map +tex t2 ; envmap mask +tex t3 ; detail texture + +; version 1: applies the mod2x *after* environment map +;mul r0.rgb, t1, t2 ; can't use mad cause can't use 3 texture registers +;mul r0.rgb, c2, r0 ; apply the envmaptint +;mad r0.rgb, t0, v0, r0 +;+ mul r0.a, t0, v0 +;mul_x2 r0.rgb, r0, t3 ; mod2x detail texture + +; version 2: applies the mod2x *before* environment map +mul r0, t0, v0 ; Base times modulation color +mul_x2 r0.rgb, r0, t3 ; mod2x detail texture +mul r1, t1, t2 ; Envmap * envmapmask +mul r1, c2, r1 ; apply the envmaptint +add r0.rgb, r0, r1 ; add in the envmap diff --git a/materialsystem/stdshaders/UnlitGeneric_DetailEnvMapMaskNoTexture.psh b/materialsystem/stdshaders/UnlitGeneric_DetailEnvMapMaskNoTexture.psh new file mode 100644 index 0000000..be67890 --- /dev/null +++ b/materialsystem/stdshaders/UnlitGeneric_DetailEnvMapMaskNoTexture.psh @@ -0,0 +1,21 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; Draw a texture . . woo hoo! +; t0 - texture +; +; The texture coordinates need to be defined as follows: +; tc0 - texcoords +; c2 - envmaptint +;------------------------------------------------------------------------------ + +tex t1 ; cube map +tex t2 ; envmap mask +tex t3 ; detail texture + +; version 1: applies the mod2x *after* environment map +; version 2 doesn't make sense here! +mul r0, t1, t2 +mul r0.rgb, c2, r0 +mul r0, r0, v0 +mul_x2 r0.rgb, r0, t3 ; mod2x detail texture \ No newline at end of file diff --git a/materialsystem/stdshaders/UnlitGeneric_DetailEnvMapNoTexture.psh b/materialsystem/stdshaders/UnlitGeneric_DetailEnvMapNoTexture.psh new file mode 100644 index 0000000..d3796bf --- /dev/null +++ b/materialsystem/stdshaders/UnlitGeneric_DetailEnvMapNoTexture.psh @@ -0,0 +1,19 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; Draw a texture . . woo hoo! +; t0 - texture +; +; The texture coordinates need to be defined as follows: +; tc0 - texcoords +; c2 - envmaptint +;------------------------------------------------------------------------------ + +tex t1 ; cube map +tex t3 ; detail texture + +; version 1: applies the mod2x *after* environment map +; version 2 doesn't make sense here! +mul r0, v0, t1 +mul r0.rgb, r0, c2 +mul_x2 r0.rgb, r0, t3 ; mod2x detail texture \ No newline at end of file diff --git a/materialsystem/stdshaders/UnlitGeneric_DetailNoTexture.psh b/materialsystem/stdshaders/UnlitGeneric_DetailNoTexture.psh new file mode 100644 index 0000000..193de81 --- /dev/null +++ b/materialsystem/stdshaders/UnlitGeneric_DetailNoTexture.psh @@ -0,0 +1,10 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; Just use the vertex color +;------------------------------------------------------------------------------ + +tex t3 + +mul_x2 r0.rgb, v0, t3 ++ mov r0.a, v0.a \ No newline at end of file diff --git a/materialsystem/stdshaders/UnlitGeneric_EnvMap.psh b/materialsystem/stdshaders/UnlitGeneric_EnvMap.psh new file mode 100644 index 0000000..6c08ace --- /dev/null +++ b/materialsystem/stdshaders/UnlitGeneric_EnvMap.psh @@ -0,0 +1,17 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; Draw a texture . . woo hoo! +; t0 - texture +; +; The texture coordinates need to be defined as follows: +; tc0 - texcoords +; c2 - envmaptint +;------------------------------------------------------------------------------ + +tex t0 ; base color +tex t1 ; cube map + +mul r1, c2, t1 +mad r0.rgb, t0, v0, r1 ++ mul r0.a, t0, v0 diff --git a/materialsystem/stdshaders/UnlitGeneric_EnvMapMask.psh b/materialsystem/stdshaders/UnlitGeneric_EnvMapMask.psh new file mode 100644 index 0000000..d00dca7 --- /dev/null +++ b/materialsystem/stdshaders/UnlitGeneric_EnvMapMask.psh @@ -0,0 +1,19 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; Draw a texture . . woo hoo! +; t0 - texture +; +; The texture coordinates need to be defined as follows: +; tc0 - texcoords +; c2 - envmaptint +;------------------------------------------------------------------------------ + +tex t0 ; base color +tex t1 ; cube map +tex t2 ; envmap mask + +mul r0.rgb, t1, t2 ; can't use mad cause can't use 3 texture registers +mul r0.rgb, c2, r0 ; apply the envmaptint +mad r0.rgb, t0, v0, r0 ++ mul r0.a, t0, v0 diff --git a/materialsystem/stdshaders/UnlitGeneric_EnvMapMaskNoTexture.psh b/materialsystem/stdshaders/UnlitGeneric_EnvMapMaskNoTexture.psh new file mode 100644 index 0000000..87daff5 --- /dev/null +++ b/materialsystem/stdshaders/UnlitGeneric_EnvMapMaskNoTexture.psh @@ -0,0 +1,17 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; Draw a texture . . woo hoo! +; t0 - texture +; +; The texture coordinates need to be defined as follows: +; tc0 - texcoords +; c2 - envmaptint +;------------------------------------------------------------------------------ + +tex t1 ; cube map +tex t2 ; envmap mask + +mul r0, t1, t2 +mul r0.rgb, c2, r0 +mul r0, r0, v0 diff --git a/materialsystem/stdshaders/UnlitGeneric_EnvMapNoTexture.psh b/materialsystem/stdshaders/UnlitGeneric_EnvMapNoTexture.psh new file mode 100644 index 0000000..4225a9e --- /dev/null +++ b/materialsystem/stdshaders/UnlitGeneric_EnvMapNoTexture.psh @@ -0,0 +1,15 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; Draw a texture . . woo hoo! +; t0 - texture +; +; The texture coordinates need to be defined as follows: +; tc0 - texcoords +; c2 - envmaptint +;------------------------------------------------------------------------------ + +tex t1 ; cube map + +mul r0, v0, t1 +mul r0.rgb, r0, c2 diff --git a/materialsystem/stdshaders/UnlitGeneric_LightingOnly.vsh b/materialsystem/stdshaders/UnlitGeneric_LightingOnly.vsh new file mode 100644 index 0000000..6361c81 --- /dev/null +++ b/materialsystem/stdshaders/UnlitGeneric_LightingOnly.vsh @@ -0,0 +1,21 @@ +vs.1.1 + +# DYNAMIC: "DOWATERFOG" "0..1" +# DYNAMIC: "SKINNING" "0..1" + +#include "macros.vsh" + +&AllocateRegister( \$worldPos ); +&SkinPosition( $worldPos ); + +; Transform the position from world to view space +dp4 oPos.x, $worldPos, $cViewProj0 +dp4 oPos.y, $worldPos, $cViewProj1 +dp4 oPos.z, $worldPos, $cViewProj2 +dp4 oPos.w, $worldPos, $cViewProj3 + +&FreeRegister( \$worldPos ); + +mov oD0, $cOne + + diff --git a/materialsystem/stdshaders/UnlitGeneric_MaskBaseByDetailAlpha_ps11.fxc b/materialsystem/stdshaders/UnlitGeneric_MaskBaseByDetailAlpha_ps11.fxc new file mode 100644 index 0000000..f46a761 --- /dev/null +++ b/materialsystem/stdshaders/UnlitGeneric_MaskBaseByDetailAlpha_ps11.fxc @@ -0,0 +1,20 @@ +#define HDRTYPE HDR_TYPE_NONE +#include "common_ps_fxc.h" + +struct PS_INPUT +{ + float2 texCoord0 : TEXCOORD0; + float2 texCoord1 : TEXCOORD3; +}; + +sampler BaseTextureSampler : register( s0 ); +sampler DetailTextureSampler : register( s3 ); + +float4 main( PS_INPUT i ) : COLOR +{ + // Sample frames from texture 0 + float4 base= tex2D( BaseTextureSampler, i.texCoord0 ); + float4 detail=tex2D( DetailTextureSampler, i.texCoord1 ); + + return float4(base.rgb, base.a * detail.a); +} diff --git a/materialsystem/stdshaders/UnlitGeneric_NoTexture.psh b/materialsystem/stdshaders/UnlitGeneric_NoTexture.psh new file mode 100644 index 0000000..7e2274d --- /dev/null +++ b/materialsystem/stdshaders/UnlitGeneric_NoTexture.psh @@ -0,0 +1,7 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; Just use the vertex color +;------------------------------------------------------------------------------ + +mov r0, v0 diff --git a/materialsystem/stdshaders/UnlitTwoTexture.psh b/materialsystem/stdshaders/UnlitTwoTexture.psh new file mode 100644 index 0000000..252e8d3 --- /dev/null +++ b/materialsystem/stdshaders/UnlitTwoTexture.psh @@ -0,0 +1,15 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; Draw a texture . . woo hoo! +; t0 - texture +; +; The texture coordinates need to be defined as follows: +; tc0 - texcoords +;------------------------------------------------------------------------------ + +tex t0 ; base color +tex t1 ; texture 2 + +mul r0, t0, v0 +mul r0, t1, r0 diff --git a/materialsystem/stdshaders/UnlitTwoTexture.vsh b/materialsystem/stdshaders/UnlitTwoTexture.vsh new file mode 100644 index 0000000..5e509a1 --- /dev/null +++ b/materialsystem/stdshaders/UnlitTwoTexture.vsh @@ -0,0 +1,10 @@ +vs.1.1 + +# DYNAMIC: "DOWATERFOG" "0..1" +# DYNAMIC: "SKINNING" "0..1" + +#include "unlittwotexture_inc.vsh" + +$vertexcolor = 0; + +&UnlitTwoTexture( $vertexcolor ); diff --git a/materialsystem/stdshaders/VertexLitGeneric.psh b/materialsystem/stdshaders/VertexLitGeneric.psh new file mode 100644 index 0000000..5aea47c --- /dev/null +++ b/materialsystem/stdshaders/VertexLitGeneric.psh @@ -0,0 +1,13 @@ +; DYNAMIC: "WRITEONETODESTALPHA" "0..1" +ps.1.1 + +; Get the color from the texture +tex t0 + +mul r0, t0, c3 +mul r0.rgb, v0, r0 ; Apply lighting +mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2) + +#if WRITEONETODESTALPHA ++mov r0.a, c4 ; make alpha 255 +#endif diff --git a/materialsystem/stdshaders/VertexLitGeneric_BaseAlphaMaskedEnvMapV2.psh b/materialsystem/stdshaders/VertexLitGeneric_BaseAlphaMaskedEnvMapV2.psh new file mode 100644 index 0000000..95b80ef --- /dev/null +++ b/materialsystem/stdshaders/VertexLitGeneric_BaseAlphaMaskedEnvMapV2.psh @@ -0,0 +1,17 @@ +; DYNAMIC: "WRITEONETODESTALPHA" "0..1" +ps.1.1 + +tex t0 ; base color +tex t1 ; cube map +tex t2 ; envmap mask + +mul r0, t0, c3 ; Base times modulation +mul r1, t1, 1-t2.a ; Envmap * mask (in alpha channel) +mul r0.rgb, v0, r0 ; apply vertex lighting +mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2) +mad r0.rgb, r1, c2, r0 ; + envmap * mask * tint + +#if WRITEONETODESTALPHA ++mov r0.a, c4 ; make alpha 255 +#endif + diff --git a/materialsystem/stdshaders/VertexLitGeneric_BlendTint.psh b/materialsystem/stdshaders/VertexLitGeneric_BlendTint.psh new file mode 100644 index 0000000..e74a527 --- /dev/null +++ b/materialsystem/stdshaders/VertexLitGeneric_BlendTint.psh @@ -0,0 +1,17 @@ +; DYNAMIC: "WRITEONETODESTALPHA" "0..1" +ps.1.1 + +; Get the color from the texture +tex t0 + +mul r0, c3, t0 +lrp r0.rgb, c1, c3, r0 +lrp r0.rgb, t0.a, r0, t0 +mul r0.rgb, v0, r0 ; Apply lighting +mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2) + +#if WRITEONETODESTALPHA ++mov r0.a, c4 ; make alpha 255 +#else ++mov r0.a, c3 +#endif diff --git a/materialsystem/stdshaders/VertexLitGeneric_Detail.psh b/materialsystem/stdshaders/VertexLitGeneric_Detail.psh new file mode 100644 index 0000000..cdb39b7 --- /dev/null +++ b/materialsystem/stdshaders/VertexLitGeneric_Detail.psh @@ -0,0 +1,16 @@ +; DYNAMIC: "WRITEONETODESTALPHA" "0..1" +ps.1.1 + +; Get the color from the texture +tex t0 +tex t3 + +mul r0, t0, c3 +mul r0.rgb, v0, r0 ; Apply lighting +mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2) +mul_x2 r1.rgb, r0, t3 ; detail texture +lrp r0.rgb, c1, r1, r0 + +#if WRITEONETODESTALPHA ++mov r0.a, c4 ; make alpha 255 +#endif diff --git a/materialsystem/stdshaders/VertexLitGeneric_DetailBaseAlphaMaskedEnvMapV2.psh b/materialsystem/stdshaders/VertexLitGeneric_DetailBaseAlphaMaskedEnvMapV2.psh new file mode 100644 index 0000000..3a329f2 --- /dev/null +++ b/materialsystem/stdshaders/VertexLitGeneric_DetailBaseAlphaMaskedEnvMapV2.psh @@ -0,0 +1,18 @@ +; DYNAMIC: "WRITEONETODESTALPHA" "0..1" +ps.1.1 + +tex t0 ; base color +tex t1 ; cube map +tex t2 ; envmap mask +tex t3 ; detail texture + +mul r0, t0, c3 ; Base times modulation +mul r1, t1, 1-t2.a ; Envmap * mask (in alpha channel) +mul r0.rgb, v0, r0 ; apply vertex lighting +mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2) +mul_x2 r0.rgb, r0, t3 ; detail texture +mad r0.rgb, r1, c2, r0 ; + envmap * mask * tint + +#if WRITEONETODESTALPHA ++mov r0.a, c4 ; make alpha 255 +#endif diff --git a/materialsystem/stdshaders/VertexLitGeneric_DetailEnvMapV2.psh b/materialsystem/stdshaders/VertexLitGeneric_DetailEnvMapV2.psh new file mode 100644 index 0000000..ce9ade8 --- /dev/null +++ b/materialsystem/stdshaders/VertexLitGeneric_DetailEnvMapV2.psh @@ -0,0 +1,16 @@ +; DYNAMIC: "WRITEONETODESTALPHA" "0..1" +ps.1.1 + +tex t0 ; base color +tex t1 ; cube map +tex t3 ; detail texture + +mul r0, t0, c3 ; base times modulation +mul r0.rgb, v0, r0 ; apply vertex lighting +mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2) +mul_x2 r0.rgb, r0, t3 ; detail texture +mad r0.rgb, t1, c2, r0 ; + envmap * envmaptint (color only) + +#if WRITEONETODESTALPHA ++mov r0.a, c4 ; make alpha 255 +#endif diff --git a/materialsystem/stdshaders/VertexLitGeneric_DetailMaskedEnvMapV2.psh b/materialsystem/stdshaders/VertexLitGeneric_DetailMaskedEnvMapV2.psh new file mode 100644 index 0000000..0094523 --- /dev/null +++ b/materialsystem/stdshaders/VertexLitGeneric_DetailMaskedEnvMapV2.psh @@ -0,0 +1,18 @@ +; DYNAMIC: "WRITEONETODESTALPHA" "0..1" +ps.1.1 + +tex t0 ; base color +tex t1 ; cube map +tex t2 ; envmap mask +tex t3 ; detail texture + +mul r0, t0, c3 ; Base times modulation +mul r1, t1, t2 ; Envmap * mask +mul r0.rgb, v0, r0 ; apply vertex lighting +mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2) +mul_x2 r0.rgb, r0, t3 ; detail texture +mad r0.rgb, r1, c2, r0 ; + envmap * mask * tint + +#if WRITEONETODESTALPHA ++mov r0.a, c4 ; make alpha 255 +#endif diff --git a/materialsystem/stdshaders/VertexLitGeneric_DetailNoTexture.psh b/materialsystem/stdshaders/VertexLitGeneric_DetailNoTexture.psh new file mode 100644 index 0000000..f22d557 --- /dev/null +++ b/materialsystem/stdshaders/VertexLitGeneric_DetailNoTexture.psh @@ -0,0 +1,12 @@ +; DYNAMIC: "WRITEONETODESTALPHA" "0..1" +ps.1.1 + +tex t3 + +mul r0, v0, c3 +mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2) +mul_x2 r0.rgb, r0, t3 ; detail texture + +#if WRITEONETODESTALPHA ++mov r0.a, c4 ; make alpha 255 +#endif diff --git a/materialsystem/stdshaders/VertexLitGeneric_DetailSelfIlluminated.psh b/materialsystem/stdshaders/VertexLitGeneric_DetailSelfIlluminated.psh new file mode 100644 index 0000000..898393e --- /dev/null +++ b/materialsystem/stdshaders/VertexLitGeneric_DetailSelfIlluminated.psh @@ -0,0 +1,22 @@ +; DYNAMIC: "WRITEONETODESTALPHA" "0..1" +ps.1.1 + +; Get the color from the texture +tex t0 +tex t3 + +; interpolate between illuminated + non-selfilluminated +mul r0.rgb, t0, c3 + ; base times modulation +mov r0.a, c3.a + +mul r0.rgb, v0, r0 ; Apply lighting +mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2) + +mul_x2 r0.rgb, r0, t3 ; detail texture + +mul r1, t0, c1 ; Self illum * tint +lrp r0.rgb, t0.a, r1, r0 ; Blend between self-illum + base * lighting + +#if WRITEONETODESTALPHA +mov r0.a, c4 ; make alpha 255 +#endif diff --git a/materialsystem/stdshaders/VertexLitGeneric_DetailSelfIlluminatedEnvMapV2.psh b/materialsystem/stdshaders/VertexLitGeneric_DetailSelfIlluminatedEnvMapV2.psh new file mode 100644 index 0000000..42befc1 --- /dev/null +++ b/materialsystem/stdshaders/VertexLitGeneric_DetailSelfIlluminatedEnvMapV2.psh @@ -0,0 +1,24 @@ +; DYNAMIC: "WRITEONETODESTALPHA" "0..1" +ps.1.1 + +; Get the color from the texture +tex t0 +tex t1 +tex t3 + +mul r0.rgb, t0, c3 + ; base times modulation +mov r0.a, c3.a ; use modulation alpha (don't use texture alpha) + +mul r0.rgb, v0, r0 ; Apply lighting +mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2) + +mul_x2 r0.rgb, r0, t3 ; detail texture + +mul r1, t0, c1 ; Self illum * tint +lrp r0.rgb, t0.a, r1, r0 ; Blend between self-illum + base * lighting + +mad r0.rgb, t1, c2, r0 ; + envmap * envmaptint (color only) + +#if WRITEONETODESTALPHA ++mov r0.a, c4 ; make alpha 255 +#endif diff --git a/materialsystem/stdshaders/VertexLitGeneric_DetailSelfIlluminatedMaskedEnvMapV2.psh b/materialsystem/stdshaders/VertexLitGeneric_DetailSelfIlluminatedMaskedEnvMapV2.psh new file mode 100644 index 0000000..666acb6 --- /dev/null +++ b/materialsystem/stdshaders/VertexLitGeneric_DetailSelfIlluminatedMaskedEnvMapV2.psh @@ -0,0 +1,26 @@ +; DYNAMIC: "WRITEONETODESTALPHA" "0..1" +ps.1.1 + +; Get the color from the texture +tex t0 ; base +tex t1 ; env map +tex t2 ; mask +tex t3 ; detail + +mul r0.rgb, t0, c3 + ; base times modulation +mul r0.a, c3.a, t2.a ; alpha = mod alpha * mask alpha + +mul r0.rgb, v0, r0 ; Apply lighting +mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2) + +mul_x2 r0.rgb, r0, t3 ; detail texture + +mul r1, t0, c1 ; Self illum * tint +lrp r0.rgb, t0.a, r1, r0 ; Blend between self-illum + base * lighting + +mul r1, t2, t1 ; envmapmask * envmap +mad r0.rgb, r1, c2, r0 ; + envmapmask * envmap * envmaptint (color only) + +#if WRITEONETODESTALPHA ++mov r0.a, c4 ; make alpha 255 +#endif diff --git a/materialsystem/stdshaders/VertexLitGeneric_Detail_LerpBase.psh b/materialsystem/stdshaders/VertexLitGeneric_Detail_LerpBase.psh new file mode 100644 index 0000000..8fcae48 --- /dev/null +++ b/materialsystem/stdshaders/VertexLitGeneric_Detail_LerpBase.psh @@ -0,0 +1,15 @@ +; DYNAMIC: "WRITEONETODESTALPHA" "0..1" +ps.1.1 + +; Get the color from the texture +tex t0 +tex t3 + +lrp r0, c1, t3, t0 ; Lerp between textures +mul r0, r0, c3 +mul r0.rgb, v0, r0 ; Apply lighting +mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2) + +#if WRITEONETODESTALPHA ++mov r0.a, c4 ; make alpha 255 +#endif diff --git a/materialsystem/stdshaders/VertexLitGeneric_Detail_additive.psh b/materialsystem/stdshaders/VertexLitGeneric_Detail_additive.psh new file mode 100644 index 0000000..586a5c0 --- /dev/null +++ b/materialsystem/stdshaders/VertexLitGeneric_Detail_additive.psh @@ -0,0 +1,15 @@ +; DYNAMIC: "WRITEONETODESTALPHA" "0..1" +ps.1.1 + +; Get the color from the texture +tex t0 +tex t3 + +mul r1, c1, t3 +mad r0, t0, c3, r1 +mul r0.rgb, v0, r0 ; Apply lighting +mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2) + +#if WRITEONETODESTALPHA ++mov r0.a, c4 ; make alpha 255 +#endif diff --git a/materialsystem/stdshaders/VertexLitGeneric_Detail_additive_selfillum.psh b/materialsystem/stdshaders/VertexLitGeneric_Detail_additive_selfillum.psh new file mode 100644 index 0000000..e40041f --- /dev/null +++ b/materialsystem/stdshaders/VertexLitGeneric_Detail_additive_selfillum.psh @@ -0,0 +1,15 @@ +; DYNAMIC: "WRITEONETODESTALPHA" "0..1" +ps.1.1 + +; Get the color from the texture +tex t0 +tex t3 + +mul r0, c3, t0 +mul r0.rgb, v0, r0 ; Apply lighting +mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2) +mad r0.rgb, c1, t3, r0 + +#if WRITEONETODESTALPHA ++mov r0.a, c4 ; make alpha 255 +#endif diff --git a/materialsystem/stdshaders/VertexLitGeneric_EnvMapNoTexture.psh b/materialsystem/stdshaders/VertexLitGeneric_EnvMapNoTexture.psh new file mode 100644 index 0000000..8e864ab --- /dev/null +++ b/materialsystem/stdshaders/VertexLitGeneric_EnvMapNoTexture.psh @@ -0,0 +1,14 @@ +; DYNAMIC: "WRITEONETODESTALPHA" "0..1" +ps.1.1 + +tex t1 ; cube map + +mul r0.rgb, t1, c2 + ; envmap * envmaptint (color only) + +mov r0.a, c3.a ; Use alpha from modulation... (?) + +mul r0.rgb, v0, r0 ; apply vertex lighting +mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2) + +#if WRITEONETODESTALPHA ++mov r0.a, c4 ; make alpha 255 +#endif diff --git a/materialsystem/stdshaders/VertexLitGeneric_EnvMapV2.psh b/materialsystem/stdshaders/VertexLitGeneric_EnvMapV2.psh new file mode 100644 index 0000000..cfc6e67 --- /dev/null +++ b/materialsystem/stdshaders/VertexLitGeneric_EnvMapV2.psh @@ -0,0 +1,14 @@ +; DYNAMIC: "WRITEONETODESTALPHA" "0..1" +ps.1.1 + +tex t0 ; base color +tex t1 ; cube map + +mul r0, t0, c3 ; base times modulation +mul r0.rgb, v0, r0 ; apply vertex lighting +mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2) +mad r0.rgb, t1, c2, r0 ; + envmap * envmaptint (color only) + +#if WRITEONETODESTALPHA ++mov r0.a, c4 ; make alpha 255 +#endif diff --git a/materialsystem/stdshaders/VertexLitGeneric_EnvmappedBumpmapV2.psh b/materialsystem/stdshaders/VertexLitGeneric_EnvmappedBumpmapV2.psh new file mode 100644 index 0000000..7cbd38f --- /dev/null +++ b/materialsystem/stdshaders/VertexLitGeneric_EnvmappedBumpmapV2.psh @@ -0,0 +1,36 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; Environment mapping on a bumped surface +; t0 - Normalmap +; t3 - Cube environment map (*must* be a cube map!) +; +; c0 - color to multiply the results by +; Input texture coords required here are a little wonky. +; tc0.uv <- U,V into the normal map +; tc1.uvw, tc2.uvw, tc3.uvw <- 3x3 matrix transform +; from tangent space->env map space +; tc1.q, tc2.q, tc3.q <- eye vector in env map space +;------------------------------------------------------------------------------ +; This version doesn't multiply by lighting. + +; Get the 3-vector from the normal map +tex t0 + +; Perform matrix multiply to get a local normal bump. Then +; reflect the eye vector through the normal and sample from +; a cubic environment map. +texm3x3pad t1, t0_bx2 +texm3x3pad t2, t0_bx2 +texm3x3vspec t3, t0_bx2 + +; result goes in output color +mul r0.rgb, t3, c0 ; constant color ++mov r0.a, c0.a + +mul r1.rgb, r0, r0 +lrp r0.rgb, c1, r1, r0 ; blend between color and color * color +dp3 r1.rgb, r0, c3 +lrp r0.rgb, c2, r0, r1 ; blend between color and greyscale + + diff --git a/materialsystem/stdshaders/VertexLitGeneric_EnvmappedBumpmapV2_MultByAlpha.psh b/materialsystem/stdshaders/VertexLitGeneric_EnvmappedBumpmapV2_MultByAlpha.psh new file mode 100644 index 0000000..9b72f0e --- /dev/null +++ b/materialsystem/stdshaders/VertexLitGeneric_EnvmappedBumpmapV2_MultByAlpha.psh @@ -0,0 +1,42 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; Environment mapping on a bumped surface +; t0 - Normalmap +; t3 - Cube environment map (*must* be a cube map!) +; +; c0 - color to multiply the results by +; Input texture coords required here are a little wonky. +; tc0.uv <- U,V into the normal map +; tc1.uvw, tc2.uvw, tc3.uvw <- 3x3 matrix transform +; from tangent space->env map space +; tc1.q, tc2.q, tc3.q <- eye vector in env map space +;------------------------------------------------------------------------------ +; This version doesn't multiply by lighting. + +; Get the 3-vector from the normal map +tex t0 + +; Perform matrix multiply to get a local normal bump. Then +; reflect the eye vector through the normal and sample from +; a cubic environment map. +texm3x3pad t1, t0_bx2 +texm3x3pad t2, t0_bx2 +texm3x3vspec t3, t0_bx2 + +; result goes in output color +mul r0.rgb, t3, c0 ; constant color ++mov r0.a, c0.a + +mul r1.rgb, r0, r0 +lrp r0.rgb, c1, r1, r0 ; blend between color and color * color +dp3 r1.rgb, r0, c3 +lrp r0.rgb, c2, r0, r1 ; blend between color and greyscale + +; Multiply the output color by the alpha channel of the normal map. +mul r0.rgb, t0.a, r0 + + + + + diff --git a/materialsystem/stdshaders/VertexLitGeneric_EnvmappedBumpmapV2_MultByAlpha_ps14.psh b/materialsystem/stdshaders/VertexLitGeneric_EnvmappedBumpmapV2_MultByAlpha_ps14.psh new file mode 100644 index 0000000..912143f --- /dev/null +++ b/materialsystem/stdshaders/VertexLitGeneric_EnvmappedBumpmapV2_MultByAlpha_ps14.psh @@ -0,0 +1,42 @@ +ps.1.4 +;------------------------------------------------------------------------------ +; Phase 1 +;------------------------------------------------------------------------------ +; Get the 3-vector from the normal map +texld r0, t0 +; Get environment matrix +texcrd r1.rgb, t1 +texcrd r2.rgb, t2 +texcrd r3.rgb, t3 +; Normalize eye-ray vector through normalizer cube map +texld r4, t4 ; <---- CUBE MAP here!!! +;mov r0.rgba, r4 + +; Transform normal +dp3 r5.r, r1, r0_bx2 +dp3 r5.g, r2, r0_bx2 +dp3 r5.b, r3, r0_bx2 +; Reflection calculatiom +dp3_x2 r3.rgb, r5, r4_bx2 ; 2(N.Eye) +mul r3.rgb, r5, r3 ; 2N(N.Eye) +dp3 r2.rgb, r5, r5 ; N.N +mad r2.rgb, -r4_bx2, r2, r3 ; 2N(N.Eye) - Eye(N.N) +; Alpha gets lost after phase marker, so store it here +mov r5, r0.a +;------------------------------------------------------------------------------ +; Phase 2 +;------------------------------------------------------------------------------ +phase +; Sample environment map +texld r3, r2 +; Result goes in output color (multiply by constant color c0) +mul r0.rgb, r3, c0 ++mov r0.a, c0.a + +mul r1.rgb, r0, r0 +lrp r0.rgb, c1, r1, r0 ; blend between color and color * color +dp3 r1.rgb, r0, c3 +lrp r0.rgb, c2, r0, r1 ; blend between color and greyscale + +; mult by alpha +mul r0.rgb, r0, r5 diff --git a/materialsystem/stdshaders/VertexLitGeneric_EnvmappedBumpmapV2_ps14.psh b/materialsystem/stdshaders/VertexLitGeneric_EnvmappedBumpmapV2_ps14.psh new file mode 100644 index 0000000..7dec5f7 --- /dev/null +++ b/materialsystem/stdshaders/VertexLitGeneric_EnvmappedBumpmapV2_ps14.psh @@ -0,0 +1,39 @@ +ps.1.4 +;------------------------------------------------------------------------------ +; Phase 1 +;------------------------------------------------------------------------------ +; Get the 3-vector from the normal map +texld r0, t0 +; Get environment matrix +texcrd r1.rgb, t1 +texcrd r2.rgb, t2 +texcrd r3.rgb, t3 +; Normalize eye-ray vector through normalizer cube map +texld r4, t4 ; <---- CUBE MAP here!!! + +; Transform normal +dp3 r5.r, r1, r0_bx2 +dp3 r5.g, r2, r0_bx2 +dp3 r5.b, r3, r0_bx2 +; Reflection calculatiom +dp3_x2 r3.rgb, r5, r4_bx2 ; 2(N.Eye) +mul r3.rgb, r5, r3 ; 2N(N.Eye) +dp3 r2.rgb, r5, r5 ; N.N +mad r2.rgb, -r4_bx2, r2, r3 ; 2N(N.Eye) - Eye(N.N) +; Alpha gets lost after phase marker, so store it here +mov r5, r0.a +;------------------------------------------------------------------------------ +; Phase 2 +;------------------------------------------------------------------------------ +phase +; Sample environment map +texld r3, r2 +; Result goes in output color (multiply by constant color c0) +mul r0.rgb, r3, c0 ++mov r0.a, c0.a + +mul r1.rgb, r0, r0 +lrp r0.rgb, c1, r1, r0 ; blend between color and color * color +dp3 r1.rgb, r0, c3 +lrp r0.rgb, c2, r0, r1 ; blend between color and greyscale + diff --git a/materialsystem/stdshaders/VertexLitGeneric_EnvmappedBumpmap_NoLighting.vsh b/materialsystem/stdshaders/VertexLitGeneric_EnvmappedBumpmap_NoLighting.vsh new file mode 100644 index 0000000..576e31c --- /dev/null +++ b/materialsystem/stdshaders/VertexLitGeneric_EnvmappedBumpmap_NoLighting.vsh @@ -0,0 +1,93 @@ +vs.1.1 + +# DYNAMIC: "DOWATERFOG" "0..1" +# DYNAMIC: "SKINNING" "0..1" + +;------------------------------------------------------------------------------ +; Shader specific constant: +; $SHADER_SPECIFIC_CONST_5 = [sOffset, tOffset, 0, 0] +;------------------------------------------------------------------------------ + +#include "macros.vsh" + +;------------------------------------------------------------------------------ +; Vertex blending +;------------------------------------------------------------------------------ + +&AllocateRegister( \$worldPos ); +&AllocateRegister( \$worldNormal ); +&AllocateRegister( \$worldTangentS ); +&AllocateRegister( \$worldTangentT ); + +&SkinPositionNormalAndTangentSpace( $worldPos, $worldNormal, + $worldTangentS, $worldTangentT ); + +;------------------------------------------------------------------------------ +; Transform the position from world to proj space +;------------------------------------------------------------------------------ + +&AllocateRegister( \$projPos ); + +dp4 $projPos.x, $worldPos, $cViewProj0 +dp4 $projPos.y, $worldPos, $cViewProj1 +dp4 $projPos.z, $worldPos, $cViewProj2 +dp4 $projPos.w, $worldPos, $cViewProj3 +mov oPos, $projPos + +;------------------------------------------------------------------------------ +; Fog +;------------------------------------------------------------------------------ +&CalcFog( $worldPos, $projPos ); + +&FreeRegister( \$projPos ); + +;------------------------------------------------------------------------------ +; Lighting +;------------------------------------------------------------------------------ + +; Transform tangent space basis vectors to env map space (world space) +; This will produce a set of vectors mapping from tangent space to env space +; We'll use this to transform normals from the normal map from tangent space +; to environment map space. +; NOTE: use dp3 here since the basis vectors are vectors, not points + +; svect +mov oT1.x, $worldTangentS.x +mov oT2.x, $worldTangentS.y +mov oT3.x, $worldTangentS.z +&FreeRegister( \$worldTangentS ); + +; tvect +mov oT1.y, $worldTangentT.x +mov oT2.y, $worldTangentT.y +mov oT3.y, $worldTangentT.z +&FreeRegister( \$worldTangentT ); + +; normal +mov oT1.z, $worldNormal.x +mov oT2.z, $worldNormal.y +mov oT3.z, $worldNormal.z + +&FreeRegister( \$worldNormal ); + +; Compute the vector from vertex to camera +&AllocateRegister( \$eyeVector ); +sub $eyeVector.xyz, $cEyePos, $worldPos + +&FreeRegister( \$worldPos ); + +; Move it into the w component of the texture coords, as the wacky +; pixel shader wants it there. +mov oT1.w, $eyeVector.x +mov oT2.w, $eyeVector.y +mov oT3.w, $eyeVector.z + +&FreeRegister( \$eyeVector ); + +;------------------------------------------------------------------------------ +; Texture coordinates +;------------------------------------------------------------------------------ +dp4 oT0.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_4 +dp4 oT0.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_5 + + diff --git a/materialsystem/stdshaders/VertexLitGeneric_EnvmappedBumpmap_NoLighting_ps14.vsh b/materialsystem/stdshaders/VertexLitGeneric_EnvmappedBumpmap_NoLighting_ps14.vsh new file mode 100644 index 0000000..2ac6616 --- /dev/null +++ b/materialsystem/stdshaders/VertexLitGeneric_EnvmappedBumpmap_NoLighting_ps14.vsh @@ -0,0 +1,90 @@ +vs.1.1 + +# DYNAMIC: "DOWATERFOG" "0..1" +# DYNAMIC: "SKINNING" "0..1" + +;------------------------------------------------------------------------------ +; Shader specific constant: +; $SHADER_SPECIFIC_CONST_5 = [sOffset, tOffset, 0, 0] +;------------------------------------------------------------------------------ + +#include "macros.vsh" + +;------------------------------------------------------------------------------ +; Vertex blending +;------------------------------------------------------------------------------ + +&AllocateRegister( \$worldPos ); +&AllocateRegister( \$worldNormal ); +&AllocateRegister( \$worldTangentS ); +&AllocateRegister( \$worldTangentT ); + +&SkinPositionNormalAndTangentSpace( $worldPos, $worldNormal, + $worldTangentS, $worldTangentT ); + +;------------------------------------------------------------------------------ +; Transform the position from world to proj space +;------------------------------------------------------------------------------ + +&AllocateRegister( \$projPos ); + +dp4 $projPos.x, $worldPos, $cViewProj0 +dp4 $projPos.y, $worldPos, $cViewProj1 +dp4 $projPos.z, $worldPos, $cViewProj2 +dp4 $projPos.w, $worldPos, $cViewProj3 +mov oPos, $projPos + +;------------------------------------------------------------------------------ +; Fog +;------------------------------------------------------------------------------ +&CalcFog( $worldPos, $projPos ); + +&FreeRegister( \$projPos ); + +;------------------------------------------------------------------------------ +; Lighting +;------------------------------------------------------------------------------ + +; Transform tangent space basis vectors to env map space (world space) +; This will produce a set of vectors mapping from tangent space to env space +; We'll use this to transform normals from the normal map from tangent space +; to environment map space. +; NOTE: use dp3 here since the basis vectors are vectors, not points + +; svect +mov oT1.x, $worldTangentS.x +mov oT2.x, $worldTangentS.y +mov oT3.x, $worldTangentS.z +&FreeRegister( \$worldTangentS ); + +; tvect +mov oT1.y, $worldTangentT.x +mov oT2.y, $worldTangentT.y +mov oT3.y, $worldTangentT.z +&FreeRegister( \$worldTangentT ); + +; normal +mov oT1.z, $worldNormal.x +mov oT2.z, $worldNormal.y +mov oT3.z, $worldNormal.z + +&FreeRegister( \$worldNormal ); + +; Compute the vector from vertex to camera +&AllocateRegister( \$eyeVector ); +sub $eyeVector.xyz, $cEyePos, $worldPos + +&FreeRegister( \$worldPos ); + +; eye vector +mov oT4.xyz, $eyeVector + +&FreeRegister( \$eyeVector ); + +;------------------------------------------------------------------------------ +; Texture coordinates +;------------------------------------------------------------------------------ +dp4 oT0.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_4 +dp4 oT0.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_5 + + diff --git a/materialsystem/stdshaders/VertexLitGeneric_MaskedEnvMapNoTexture.psh b/materialsystem/stdshaders/VertexLitGeneric_MaskedEnvMapNoTexture.psh new file mode 100644 index 0000000..a6209ab --- /dev/null +++ b/materialsystem/stdshaders/VertexLitGeneric_MaskedEnvMapNoTexture.psh @@ -0,0 +1,15 @@ +; DYNAMIC: "WRITEONETODESTALPHA" "0..1" +ps.1.1 + +tex t1 ; cube map +tex t2 ; envmap mask + +mul r1, t1, t2 ; Envmap * mask +mul r0.rgb, r1, c2 ; envmap * mask * tint +mul r0.rgb, v0, r0 ; apply vertex lighting +mul_x2 r0.rgb, c0, r0 + ; * 2 * (overbrightFactor/2) +mul r0.a, c3.a, t2.a ; alpha = modulation * mask alpha + +#if WRITEONETODESTALPHA +mov r0.a, c4 ; make alpha 255 +#endif diff --git a/materialsystem/stdshaders/VertexLitGeneric_MaskedEnvMapV2.psh b/materialsystem/stdshaders/VertexLitGeneric_MaskedEnvMapV2.psh new file mode 100644 index 0000000..53519d9 --- /dev/null +++ b/materialsystem/stdshaders/VertexLitGeneric_MaskedEnvMapV2.psh @@ -0,0 +1,16 @@ +; DYNAMIC: "WRITEONETODESTALPHA" "0..1" +ps.1.1 + +tex t0 ; base color +tex t1 ; cube map +tex t2 ; envmap mask + +mul r0, t0, c3 ; Base times modulation +mul r1, t1, t2 ; Envmap * mask +mul r0.rgb, v0, r0 ; apply vertex lighting +mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2) +mad r0.rgb, r1, c2, r0 ; + envmap * mask * tint + +#if WRITEONETODESTALPHA ++mov r0.a, c4 ; make alpha 255 +#endif diff --git a/materialsystem/stdshaders/VertexLitGeneric_NoTexture.psh b/materialsystem/stdshaders/VertexLitGeneric_NoTexture.psh new file mode 100644 index 0000000..0bc2e45 --- /dev/null +++ b/materialsystem/stdshaders/VertexLitGeneric_NoTexture.psh @@ -0,0 +1,9 @@ +; DYNAMIC: "WRITEONETODESTALPHA" "0..1" +ps.1.1 + +mul r0, v0, c3 +mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2) + +#if WRITEONETODESTALPHA ++mov r0.a, c4 ; make alpha 255 +#endif diff --git a/materialsystem/stdshaders/VertexLitGeneric_SelfIllumOnly.psh b/materialsystem/stdshaders/VertexLitGeneric_SelfIllumOnly.psh new file mode 100644 index 0000000..198ad9e --- /dev/null +++ b/materialsystem/stdshaders/VertexLitGeneric_SelfIllumOnly.psh @@ -0,0 +1,5 @@ +ps.1.1 + +tex t0 + +mul r0.rgba, c0, t0 diff --git a/materialsystem/stdshaders/VertexLitGeneric_SelfIllumOnly.vsh b/materialsystem/stdshaders/VertexLitGeneric_SelfIllumOnly.vsh new file mode 100644 index 0000000..40eb8d2 --- /dev/null +++ b/materialsystem/stdshaders/VertexLitGeneric_SelfIllumOnly.vsh @@ -0,0 +1,41 @@ +vs.1.1 + +# DYNAMIC: "DOWATERFOG" "0..1" +# DYNAMIC: "SKINNING" "0..1" + +#include "macros.vsh" + +;------------------------------------------------------------------------------ +; Vertex blending +;------------------------------------------------------------------------------ +&AllocateRegister( \$worldPos ); +&SkinPosition( $worldPos ); + +;------------------------------------------------------------------------------ +; Transform the position from world to view space +;------------------------------------------------------------------------------ + +&AllocateRegister( \$projPos ); + +dp4 $projPos.x, $worldPos, $cViewProj0 +dp4 $projPos.y, $worldPos, $cViewProj1 +dp4 $projPos.z, $worldPos, $cViewProj2 +dp4 $projPos.w, $worldPos, $cViewProj3 +mov oPos, $projPos + +;------------------------------------------------------------------------------ +; Fog +;------------------------------------------------------------------------------ + +&CalcFog( $worldPos, $projPos ); +&FreeRegister( \$projPos ); +&FreeRegister( \$worldPos ); + +;------------------------------------------------------------------------------ +; Texture coordinates +;------------------------------------------------------------------------------ + +dp4 oT0.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_0 +dp4 oT0.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_1 + + diff --git a/materialsystem/stdshaders/VertexLitGeneric_SelfIlluminated.psh b/materialsystem/stdshaders/VertexLitGeneric_SelfIlluminated.psh new file mode 100644 index 0000000..3d14e4b --- /dev/null +++ b/materialsystem/stdshaders/VertexLitGeneric_SelfIlluminated.psh @@ -0,0 +1,19 @@ +; DYNAMIC: "WRITEONETODESTALPHA" "0..1" +ps.1.1 + +; Get the color from the texture +tex t0 + +; interpolate between illuminated + non-selfilluminated +mul r0.rgb, t0, c3 + ; base times modulation +mov r0.a, c3.a + +mul r0.rgb, v0, r0 ; Apply lighting +mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2) + +mul r1, t0, c1 ; Self illum * tint +lrp r0.rgb, t0.a, r1, r0 ; Blend between self-illum + base * lighting + +#if WRITEONETODESTALPHA ++mov r0.a, c4 ; make alpha 255 +#endif diff --git a/materialsystem/stdshaders/VertexLitGeneric_SelfIlluminatedEnvMapV2.psh b/materialsystem/stdshaders/VertexLitGeneric_SelfIlluminatedEnvMapV2.psh new file mode 100644 index 0000000..b8ba4d1 --- /dev/null +++ b/materialsystem/stdshaders/VertexLitGeneric_SelfIlluminatedEnvMapV2.psh @@ -0,0 +1,21 @@ +; DYNAMIC: "WRITEONETODESTALPHA" "0..1" +ps.1.1 + +; Get the color from the texture +tex t0 +tex t1 + +mul r0.rgb, t0, c3 + ; base times modulation +mov r0.a, c3.a ; use modulation alpha (don't use texture alpha) + +mul r0.rgb, v0, r0 ; Apply lighting +mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2) + +mul r1, t0, c1 ; Self illum * tint +lrp r0.rgb, t0.a, r1, r0 ; Blend between self-illum + base * lighting + +mad r0.rgb, t1, c2, r0 ; + envmap * envmaptint (color only) + +#if WRITEONETODESTALPHA ++mov r0.a, c4 ; make alpha 255 +#endif diff --git a/materialsystem/stdshaders/VertexLitGeneric_SelfIlluminatedMaskedEnvMapV2.psh b/materialsystem/stdshaders/VertexLitGeneric_SelfIlluminatedMaskedEnvMapV2.psh new file mode 100644 index 0000000..44fe15d --- /dev/null +++ b/materialsystem/stdshaders/VertexLitGeneric_SelfIlluminatedMaskedEnvMapV2.psh @@ -0,0 +1,23 @@ +; DYNAMIC: "WRITEONETODESTALPHA" "0..1" +ps.1.1 + +; Get the color from the texture +tex t0 ; base +tex t1 ; env map +tex t2 ; mask + +mul r0.rgb, t0, c3 + ; base times modulation +mul r0.a, c3.a, t2.a ; alpha = mod alpha * mask alpha + +mul r0.rgb, v0, r0 ; Apply lighting +mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2) + +mul r1, t0, c1 ; Self illum * tint +lrp r0.rgb, t0.a, r1, r0 ; Blend between self-illum + base * lighting + +mul r1, t2, t1 ; envmapmask * envmap +mad r0.rgb, r1, c2, r0 ; + envmapmask * envmap * envmaptint (color only) + +#if WRITEONETODESTALPHA ++mov r0.a, c4 ; make alpha 255 +#endif diff --git a/materialsystem/stdshaders/VertexLitTexture.psh b/materialsystem/stdshaders/VertexLitTexture.psh new file mode 100644 index 0000000..628cfc6 --- /dev/null +++ b/materialsystem/stdshaders/VertexLitTexture.psh @@ -0,0 +1,15 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; Draw a texture . . woo hoo! +; t0 - texture +; +; The texture coordinates need to be defined as follows: +; tc0 - texcoords +;------------------------------------------------------------------------------ + +; Get the color from the texture +tex t0 + +mul r0, t0, v0 + diff --git a/materialsystem/stdshaders/VertexLitTexture_Overbright2.psh b/materialsystem/stdshaders/VertexLitTexture_Overbright2.psh new file mode 100644 index 0000000..db2c4e2 --- /dev/null +++ b/materialsystem/stdshaders/VertexLitTexture_Overbright2.psh @@ -0,0 +1,16 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; Draw a texture . . woo hoo! +; t0 - texture +; +; The texture coordinates need to be defined as follows: +; tc0 - texcoords +;------------------------------------------------------------------------------ + +; Get the color from the texture +tex t0 + +mul_x2 r0.rgb, t0, v0 ++ mul r0.a, t0, v0 + diff --git a/materialsystem/stdshaders/VertexTextureTest.cpp b/materialsystem/stdshaders/VertexTextureTest.cpp new file mode 100644 index 0000000..5fc9afe --- /dev/null +++ b/materialsystem/stdshaders/VertexTextureTest.cpp @@ -0,0 +1,84 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $Header: $ +// $NoKeywords: $ +//============================================================================= + +// don't merge into main!!!!!!!!!!!! +#if 0 +#include "BaseVSShader.h" +#include "vertextexturetest_vs30.inc" +#include "vertextexturetest_ps30.inc" + +BEGIN_VS_SHADER_FLAGS( VertexTextureTest, "Help for VertexTextureTest", SHADER_NOT_EDITABLE ) + + BEGIN_SHADER_PARAMS + SHADER_PARAM( BASETEXTURE2, SHADER_PARAM_TYPE_TEXTURE, "shadertest/detail", "detail texture" ) + SHADER_PARAM( FRAME2, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $basetexture2" ) + SHADER_PARAM( BASETEXTURE3, SHADER_PARAM_TYPE_TEXTURE, "shadertest/detail", "detail texture" ) + SHADER_PARAM( FRAME3, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $basetexture2" ) + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + } + + SHADER_FALLBACK + { + if ( g_pHardwareConfig->GetDXSupportLevel() < 95 ) + { + Assert( 0 ); + return "Wireframe"; + } + + return 0; + } + + SHADER_INIT + { + LoadTexture( BASETEXTURE ); + LoadTexture( BASETEXTURE2 ); + LoadTexture( BASETEXTURE3 ); + } + + SHADER_DRAW + { + SHADOW_STATE + { + pShaderShadow->EnableTexture( SHADER_TEXTURE_STAGE0, true ); + pShaderShadow->EnableTexture( SHADER_TEXTURE_STAGE1, true ); + pShaderShadow->EnableTexture( SHADER_TEXTURE_STAGE2, true ); + + unsigned int flags = VERTEX_POSITION; + pShaderShadow->VertexShaderVertexFormat( flags, 1, 0, 0, 0 ); + + pShaderShadow->SetMorphFormat( MORPH_POSITION | MORPH_NORMAL | MORPH_WRINKLE ); + + DECLARE_STATIC_VERTEX_SHADER( vertextexturetest_vs30 ); + SET_STATIC_VERTEX_SHADER( vertextexturetest_vs30 ); + + DECLARE_STATIC_PIXEL_SHADER( vertextexturetest_ps30 ); + SET_STATIC_PIXEL_SHADER( vertextexturetest_ps30 ); + + FogToFogColor(); + } + DYNAMIC_STATE + { + BindTexture( SHADER_TEXTURE_STAGE0, BASETEXTURE, FRAME ); + BindTexture( SHADER_TEXTURE_STAGE1, BASETEXTURE2, FRAME2 ); + BindTexture( SHADER_TEXTURE_STAGE2, BASETEXTURE3, FRAME3 ); + + SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, BASETEXTURETRANSFORM ); + + DECLARE_DYNAMIC_VERTEX_SHADER( vertextexturetest_vs30 ); + SET_DYNAMIC_VERTEX_SHADER( vertextexturetest_vs30 ); + + DECLARE_DYNAMIC_PIXEL_SHADER( vertextexturetest_ps30 ); + SET_DYNAMIC_PIXEL_SHADER( vertextexturetest_ps30 ); + } + Draw( ); + } +END_SHADER +#endif \ No newline at end of file diff --git a/materialsystem/stdshaders/WaterCheapFresnelOpaque_ps14.psh b/materialsystem/stdshaders/WaterCheapFresnelOpaque_ps14.psh new file mode 100644 index 0000000..2aff6a4 --- /dev/null +++ b/materialsystem/stdshaders/WaterCheapFresnelOpaque_ps14.psh @@ -0,0 +1,40 @@ +ps.1.4 + +; Get the 3-vector from the normal map +texld r0, t0 +; Get environment matrix +texcrd r1.rgb, t1 +texcrd r2.rgb, t2 +texcrd r3.rgb, t3 +; Normalize eye-ray vector through normalizer cube map +texld r4, t4 ; <---- CUBE MAP here!!! + +; Transform normal +dp3 r5.r, r1, r0_bx2 +dp3 r5.g, r2, r0_bx2 +dp3 r5.b, r3, r0_bx2 +; Reflection calculatiom +dp3_x2 r3.rgb, r5, r4_bx2 ; 2(N.Eye) +mul r3.rgb, r5, r3 ; 2N(N.Eye) +dp3 r2.rgb, r5, r5 ; N.N +mad r2.rgb, -r4_bx2, r2, r3 ; 2N(N.Eye) - Eye(N.N) + +phase + +; Sample environment map +texld r3, r2 +texld r4, t5 ; Normalize the tangent-space eye vector + +; dot eye-vector with per-pixel normal from r0 +dp3_sat r1, r4_bx2, r0_bx2 + +; run Fresnel approx. on it: R0 + (1-R0) (1-cos(q))^5 in alpha channel +mul r0.a, 1-r1.a, 1-r1.a ; squared +mul r0.a, r0.a, r0.a ; quartic +mul_sat r1.a, r0.a, 1-r1.a ; quintic + +; multiply color by reflecttint +mul r0, r3, c1 + +; blend between reflected color and fog color based on fresnel +lrp r0.rgb, r1.a, r0, c0 \ No newline at end of file diff --git a/materialsystem/stdshaders/WaterCheapFresnel_ps14.psh b/materialsystem/stdshaders/WaterCheapFresnel_ps14.psh new file mode 100644 index 0000000..741881b --- /dev/null +++ b/materialsystem/stdshaders/WaterCheapFresnel_ps14.psh @@ -0,0 +1,39 @@ +ps.1.4 + +; Get the 3-vector from the normal map +texld r0, t0 +; Get environment matrix +texcrd r1.rgb, t1 +texcrd r2.rgb, t2 +texcrd r3.rgb, t3 +; Normalize eye-ray vector through normalizer cube map +texld r4, t4 ; <---- CUBE MAP here!!! + +; Transform normal +dp3 r5.r, r1, r0_bx2 +dp3 r5.g, r2, r0_bx2 +dp3 r5.b, r3, r0_bx2 +; Reflection calculatiom +dp3_x2 r3.rgb, r5, r4_bx2 ; 2(N.Eye) +mul r3.rgb, r5, r3 ; 2N(N.Eye) +dp3 r2.rgb, r5, r5 ; N.N +mad r2.rgb, -r4_bx2, r2, r3 ; 2N(N.Eye) - Eye(N.N) + +phase + +; Sample environment map +texld r3, r2 +texld r4, t5 ; Normalize the tangent-space eye vector + +; dot eye-vector with per-pixel normal from r0 +dp3_sat r1, r4_bx2, r0_bx2 + +; run Fresnel approx. on it: R0 + (1-R0) (1-cos(q))^5 in alpha channel +mul r0.a, 1-r1.a, 1-r1.a ; squared +mul r0.a, r0.a, r0.a ; quartic +mul_sat r1.a, r0.a, 1-r1.a ; quintic + +; multiply color by reflecttint +mul r0.rgb, r3, c1 ++mov_sat r0.a, v0.a +add_sat r0.a, r1.a, r0.a diff --git a/materialsystem/stdshaders/WaterCheapNoFresnelOpaque_ps11.psh b/materialsystem/stdshaders/WaterCheapNoFresnelOpaque_ps11.psh new file mode 100644 index 0000000..c1a28c1 --- /dev/null +++ b/materialsystem/stdshaders/WaterCheapNoFresnelOpaque_ps11.psh @@ -0,0 +1,19 @@ +ps.1.1 + +; Get the 3-vector from the normal map +tex t0 + +; Perform matrix multiply to get a local normal bump. Then +; reflect the eye vector through the normal and sample from +; a cubic environment map. +texm3x3pad t1, t0_bx2 +texm3x3pad t2, t0_bx2 +texm3x3vspec t3, t0_bx2 + +mul r0, t3, c1 ; multiply color by reflecttint +lrp r0.rgb, c1.a, r0, c0 ; blend between reflected color and fog color based on constant factor + + + + + diff --git a/materialsystem/stdshaders/WaterCheapNoFresnel_ps11.psh b/materialsystem/stdshaders/WaterCheapNoFresnel_ps11.psh new file mode 100644 index 0000000..d63151b --- /dev/null +++ b/materialsystem/stdshaders/WaterCheapNoFresnel_ps11.psh @@ -0,0 +1,18 @@ +ps.1.1 + +; Get the 3-vector from the normal map +tex t0 + +; Perform matrix multiply to get a local normal bump. Then +; reflect the eye vector through the normal and sample from +; a cubic environment map. +texm3x3pad t1, t0_bx2 +texm3x3pad t2, t0_bx2 +texm3x3vspec t3, t0_bx2 + +mul r0.rgb, t3, c1 ; multiply color by reflecttint ++mov_sat r0.a, v0.a ; NOTE: This is necessary since v0.a can be outside 0 - 1! +add_sat r0.a, c1.a, r0.a ; cheap water blend factor + constant blend factor + + + diff --git a/materialsystem/stdshaders/WaterCheapOpaque_ps11.psh b/materialsystem/stdshaders/WaterCheapOpaque_ps11.psh new file mode 100644 index 0000000..9704bfd --- /dev/null +++ b/materialsystem/stdshaders/WaterCheapOpaque_ps11.psh @@ -0,0 +1,26 @@ +ps.1.1 + +; Get the 3-vector from the normal map +tex t0 + +; Perform matrix multiply to get a local normal bump. Then +; reflect the eye vector through the normal and sample from +; a cubic environment map. +texm3x3pad t1, t0_bx2 +texm3x3pad t2, t0_bx2 +texm3x3vspec t3, t0_bx2 + +mul r0, t3, c1 ; envmap color * envmaptint + +dp3_sat t2, v0_bx2, t0_bx2 ; dot eye-vector with per-pixel normal from t0 + +; run Fresnel approx. on it: R0 + (1-R0) (1-cos(q))^5 in alpha channel +; NOTE: This is not perspective-correct and results in strange artifacts +mul r1.a, 1-t2.a, 1-t2.a ; squared +mul r1.a, r1.a, r1.a ; quartic +mul_sat r1.a, r1.a, 1-t2.a ; quintic + +; t1.a is now the fresnel factor +lrp r0.rgb, r1.a, r0, c0 ; blend between reflected color and fog color based on fresnel + + diff --git a/materialsystem/stdshaders/WaterCheapOpaque_ps14.psh b/materialsystem/stdshaders/WaterCheapOpaque_ps14.psh new file mode 100644 index 0000000..a1b5262 --- /dev/null +++ b/materialsystem/stdshaders/WaterCheapOpaque_ps14.psh @@ -0,0 +1,31 @@ +ps.1.4 + +; Get the 3-vector from the normal map +texld r0, t0 +; Get environment matrix +texcrd r1.rgb, t1 +texcrd r2.rgb, t2 +texcrd r3.rgb, t3 +; Normalize eye-ray vector through normalizer cube map +texld r4, t4 ; <---- CUBE MAP here!!! + +; Transform normal +dp3 r5.r, r1, r0_bx2 +dp3 r5.g, r2, r0_bx2 +dp3 r5.b, r3, r0_bx2 +; Reflection calculatiom +dp3_x2 r3.rgb, r5, r4_bx2 ; 2(N.Eye) +mul r3.rgb, r5, r3 ; 2N(N.Eye) +dp3 r2.rgb, r5, r5 ; N.N +mad r2.rgb, -r4_bx2, r2, r3 ; 2N(N.Eye) - Eye(N.N) + +phase + +; Sample environment map +texld r3, r2 + +; multiply color by reflecttint +mul r0, r3, c1 + +; blend between reflected color and fog color based on constant factor +lrp r0.rgb, c1.a, r0, c0 diff --git a/materialsystem/stdshaders/WaterCheapPerVertexFresnel_vs11.vsh b/materialsystem/stdshaders/WaterCheapPerVertexFresnel_vs11.vsh new file mode 100644 index 0000000..6ca504c --- /dev/null +++ b/materialsystem/stdshaders/WaterCheapPerVertexFresnel_vs11.vsh @@ -0,0 +1,100 @@ +vs.1.1 + +# DYNAMIC: "DOWATERFOG" "0..1" + +#include "macros.vsh" + +;------------------------------------------------------------------------------ +; Vertex blending +;------------------------------------------------------------------------------ + +&AllocateRegister( \$worldPos ); + +; Transform position from object to world +dp4 $worldPos.x, $vPos, $cModel0 +dp4 $worldPos.y, $vPos, $cModel1 +dp4 $worldPos.z, $vPos, $cModel2 + +&AllocateRegister( \$projPos ); + +; Transform position from object to projection space +dp4 $projPos.x, $vPos, $cModelViewProj0 +dp4 $projPos.y, $vPos, $cModelViewProj1 +dp4 $projPos.z, $vPos, $cModelViewProj2 +dp4 $projPos.w, $vPos, $cModelViewProj3 + +mov oPos, $projPos + +;------------------------------------------------------------------------------ +; Fog +;------------------------------------------------------------------------------ +&CalcFog( $worldPos, $projPos ); + +&FreeRegister( \$projPos ); + +;------------------------------------------------------------------------------ +; Lighting +;------------------------------------------------------------------------------ + +; Transform tangent space basis vectors to env map space (world space) +; This will produce a set of vectors mapping from tangent space to env space +; We'll use this to transform normals from the normal map from tangent space +; to environment map space. +; NOTE: use dp3 here since the basis vectors are vectors, not points + +dp3 oT1.x, $vTangentS, $cModel0 +dp3 oT2.x, $vTangentS, $cModel1 +dp3 oT3.x, $vTangentS, $cModel2 + +dp3 oT1.y, $vTangentT, $cModel0 +dp3 oT2.y, $vTangentT, $cModel1 +dp3 oT3.y, $vTangentT, $cModel2 + +dp3 oT1.z, $vNormal, $cModel0 +dp3 oT2.z, $vNormal, $cModel1 +dp3 oT3.z, $vNormal, $cModel2 + +; Compute the vector from vertex to camera +&AllocateRegister( \$worldEyeVect ); +sub $worldEyeVect.xyz, $cEyePos, $worldPos +&FreeRegister( \$worldPos ); + +; Move it into the w component of the texture coords, as the wacky +; pixel shader wants it there. +mov oT1.w, $worldEyeVect.x +mov oT2.w, $worldEyeVect.y +mov oT3.w, $worldEyeVect.z + +&AllocateRegister( \$tangentEyeVect ); + +; transform the eye vector to tangent space +dp3 $tangentEyeVect.x, $worldEyeVect, $vTangentS +dp3 $tangentEyeVect.y, $worldEyeVect, $vTangentT +dp3 $tangentEyeVect.z, $worldEyeVect, $vNormal + +&Normalize( $tangentEyeVect ); +mov oD0.xyz, $tangentEyeVect + +&FreeRegister( \$tangentEyeVect ); + +; Get the magnitude of worldEyeVect +dp3 $worldEyeVect.w, $worldEyeVect, $worldEyeVect +rsq $worldEyeVect.w, $worldEyeVect.w +rcp $worldEyeVect.w, $worldEyeVect.w + +; calculate the cheap water blend factor and stick it into oD0.a +; NOTE: This won't be perspective correct!!!!! +; OPTIMIZE: This could turn into a mad. +add $worldEyeVect.w, $worldEyeVect.w, -$SHADER_SPECIFIC_CONST_2.x +mul oD0.w, $worldEyeVect.w, $SHADER_SPECIFIC_CONST_2.y + +&FreeRegister( \$worldEyeVect ); + +;------------------------------------------------------------------------------ +; Texture coordinates +;------------------------------------------------------------------------------ +dp4 oT0.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_0 +dp4 oT0.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_1 + + + diff --git a/materialsystem/stdshaders/WaterCheap_ps11.psh b/materialsystem/stdshaders/WaterCheap_ps11.psh new file mode 100644 index 0000000..f12a1bc --- /dev/null +++ b/materialsystem/stdshaders/WaterCheap_ps11.psh @@ -0,0 +1,26 @@ +ps.1.1 + +; Get the 3-vector from the normal map +tex t0 + +; Perform matrix multiply to get a local normal bump. Then +; reflect the eye vector through the normal and sample from +; a cubic environment map. +texm3x3pad t1, t0_bx2 +texm3x3pad t2, t0_bx2 +texm3x3vspec t3, t0_bx2 + +mul r0.rgb, t3, c1 ; envmap color * envmaptint ++mov_sat r0.a, v0.a ; Put the cheap water blend factor here + +dp3_sat t2, v0_bx2, t0_bx2 ; dot eye-vector with per-pixel normal from t0 + +; run Fresnel approx. on it: R0 + (1-R0) (1-cos(q))^5 in alpha channel +; NOTE: This is not perspective-correct and results in strange artifacts +mul r1.a, 1-t2.a, 1-t2.a ; squared +mul r1.a, r1.a, r1.a ; quartic +mul_sat r1.a, r1.a, 1-t2.a ; quintic + +; t1.a is now the fresnel factor +add_sat r0.a, r1.a, r0.a ; Now we have the final blend factor between cheap water + refraction + diff --git a/materialsystem/stdshaders/WaterCheap_ps14.psh b/materialsystem/stdshaders/WaterCheap_ps14.psh new file mode 100644 index 0000000..e38f65e --- /dev/null +++ b/materialsystem/stdshaders/WaterCheap_ps14.psh @@ -0,0 +1,30 @@ +ps.1.4 + +; Get the 3-vector from the normal map +texld r0, t0 +; Get environment matrix +texcrd r1.rgb, t1 +texcrd r2.rgb, t2 +texcrd r3.rgb, t3 +; Normalize eye-ray vector through normalizer cube map +texld r4, t4 ; <---- CUBE MAP here!!! + +; Transform normal +dp3 r5.r, r1, r0_bx2 +dp3 r5.g, r2, r0_bx2 +dp3 r5.b, r3, r0_bx2 +; Reflection calculatiom +dp3_x2 r3.rgb, r5, r4_bx2 ; 2(N.Eye) +mul r3.rgb, r5, r3 ; 2N(N.Eye) +dp3 r2.rgb, r5, r5 ; N.N +mad r2.rgb, -r4_bx2, r2, r3 ; 2N(N.Eye) - Eye(N.N) + +phase + +; Sample environment map +texld r3, r2 + +; multiply color by reflecttint +mul r0.rgb, r3, c1 ++mov_sat r0.a, v0.a ; Necessary since v0.a may be negative +add_sat r0.a, c1.a, r0.a diff --git a/materialsystem/stdshaders/WaterCheap_ps2x.fxc b/materialsystem/stdshaders/WaterCheap_ps2x.fxc new file mode 100644 index 0000000..4ca6657 --- /dev/null +++ b/materialsystem/stdshaders/WaterCheap_ps2x.fxc @@ -0,0 +1,152 @@ +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX] +// STATIC: "MULTITEXTURE" "0..1" +// STATIC: "FRESNEL" "0..1" +// STATIC: "BLEND" "0..1" +// STATIC: "REFRACTALPHA" "0..1" +// STATIC: "HDRTYPE" "0..2" +// STATIC: "NORMAL_DECODE_MODE" "0..0" [XBOX] +// STATIC: "NORMAL_DECODE_MODE" "0..0" [PC] + +// DYNAMIC: "HDRENABLED" "0..1" +// DYNAMIC: "PIXELFOGTYPE" "0..1" + +#include "common_ps_fxc.h" + +const HALF3 g_WaterFogColor : register( c0 ); +const HALF4 g_CheapWaterParams : register( c1 ); +const HALF4 g_ReflectTint : register( c2 ); +const float4 g_PixelFogParams : register( c3 ); + +#define g_CheapWaterStart g_CheapWaterParams.x +#define g_CheapWaterEnd g_CheapWaterParams.y +#define g_CheapWaterDeltaRecip g_CheapWaterParams.z +#define g_CheapWaterStartDivDelta g_CheapWaterParams.w + +sampler EnvmapSampler : register( s0 ); +sampler NormalMapSampler : register( s1 ); +#if REFRACTALPHA +sampler RefractSampler : register( s2 ); +#endif +sampler NormalizeSampler : register( s6 ); + +struct PS_INPUT +{ + float2 normalMapTexCoord : TEXCOORD0; + HALF3 worldSpaceEyeVect : TEXCOORD1; + HALF3x3 tangentSpaceTranspose : TEXCOORD2; + float4 vRefract_W_ProjZ : TEXCOORD5; + +#if MULTITEXTURE + float4 vExtraBumpTexCoord : TEXCOORD6; +#endif + float4 fogFactorW : COLOR1; +}; + +float4 main( PS_INPUT i ) : COLOR +{ + bool bBlend = BLEND ? true : false; + +#if MULTITEXTURE + float3 vNormal = tex2D( NormalMapSampler, i.normalMapTexCoord ); + float3 vNormal1 = tex2D( NormalMapSampler, i.vExtraBumpTexCoord.xy ); + float3 vNormal2 = tex2D( NormalMapSampler, i.vExtraBumpTexCoord.zw ); + vNormal = 0.33 * ( vNormal + vNormal1 + vNormal2 ); + +#if ( NORMAL_DECODE_MODE == NORM_DECODE_ATI2N ) + vNormal.xy = vNormal.xy * 2.0f - 1.0f; + vNormal.z = sqrt( 1.0f - dot(vNormal.xy, vNormal.xy) ); +#else + vNormal = 2.0 * vNormal - 1.0; +#endif + +#else + float3 vNormal = DecompressNormal( NormalMapSampler, i.normalMapTexCoord, NORMAL_DECODE_MODE ); +#endif + + HALF3 worldSpaceNormal = mul( vNormal, i.tangentSpaceTranspose ); + HALF3 worldSpaceEye; + + HALF flWorldSpaceDist = 1.0f; + +#ifdef NV3X + // for some reason, fxc doesn't convert length( half3 v ) into all _pp opcodes. + if (bBlend) + { + worldSpaceEye = i.worldSpaceEyeVect; + HALF worldSpaceDistSqr = dot( worldSpaceEye, worldSpaceEye ); + HALF rcpWorldSpaceDist = rsqrt( worldSpaceDistSqr ); + worldSpaceEye *= rcpWorldSpaceDist; + flWorldSpaceDist = worldSpaceDistSqr * rcpWorldSpaceDist; + } + else + { + worldSpaceEye = NormalizeWithCubemap( NormalizeSampler, i.worldSpaceEyeVect ); + } +#else // !NV3X + if (bBlend) + { + worldSpaceEye = i.worldSpaceEyeVect; + flWorldSpaceDist = length( worldSpaceEye ); + worldSpaceEye /= flWorldSpaceDist; + } + else + { + worldSpaceEye = NormalizeWithCubemap( NormalizeSampler, i.worldSpaceEyeVect ); + } +#endif + + HALF3 reflectVect = CalcReflectionVectorUnnormalized( worldSpaceNormal, worldSpaceEye ); + HALF3 specularLighting = ENV_MAP_SCALE * texCUBE( EnvmapSampler, reflectVect ); + specularLighting *= g_ReflectTint; + +#if FRESNEL + // FIXME: It's unclear that we want to do this for cheap water + // but the code did this previously and I didn't want to change it + HALF flDotResult = dot( worldSpaceEye, worldSpaceNormal ); + flDotResult = 1.0f - max( 0.0f, flDotResult ); + + HALF flFresnelFactor = flDotResult * flDotResult; + flFresnelFactor *= flFresnelFactor; + flFresnelFactor *= flDotResult; +#else + HALF flFresnelFactor = g_ReflectTint.a; +#endif + + HALF flAlpha; + if (bBlend) + { + HALF flReflectAmount = saturate( flWorldSpaceDist * g_CheapWaterDeltaRecip - g_CheapWaterStartDivDelta ); + flAlpha = saturate( flFresnelFactor + flReflectAmount ); + +#if REFRACTALPHA + // Perform division by W only once + float ooW = 1.0f / i.vRefract_W_ProjZ.z; + float2 unwarpedRefractTexCoord = i.vRefract_W_ProjZ * ooW; + float fogDepthValue = tex2D( RefractSampler, unwarpedRefractTexCoord ).a; + // Fade on the border between the water and land. + flAlpha *= saturate( ( fogDepthValue - .05f ) * 20.0f ); +#endif + } + else + { + flAlpha = 1.0f; +#if HDRTYPE == 0 || HDRENABLED == 0 + specularLighting = lerp( g_WaterFogColor, specularLighting, flFresnelFactor ); +#else + specularLighting = lerp( GammaToLinear( g_WaterFogColor ), specularLighting, flFresnelFactor ); +#endif + } + + // multiply the color by alpha.since we are using alpha blending to blend against dest alpha for borders. + + + +#if (PIXELFOGTYPE == PIXEL_FOG_TYPE_RANGE) + float fogFactor = CalcRangeFog( i.vRefract_W_ProjZ.w, g_PixelFogParams.x, g_PixelFogParams.z, g_PixelFogParams.w ); +#else + float fogFactor = 0; +#endif + + return FinalOutput( float4( specularLighting, flAlpha ), fogFactor, PIXELFOGTYPE, TONEMAP_SCALE_LINEAR ); +} diff --git a/materialsystem/stdshaders/WaterCheap_vs11.vsh b/materialsystem/stdshaders/WaterCheap_vs11.vsh new file mode 100644 index 0000000..b1cdd61 --- /dev/null +++ b/materialsystem/stdshaders/WaterCheap_vs11.vsh @@ -0,0 +1,88 @@ +vs.1.1 + +# DYNAMIC: "DOWATERFOG" "0..1" + +#include "macros.vsh" + +;------------------------------------------------------------------------------ +; Vertex blending +;------------------------------------------------------------------------------ + +&AllocateRegister( \$worldPos ); + +; Transform position from object to world +dp4 $worldPos.x, $vPos, $cModel0 +dp4 $worldPos.y, $vPos, $cModel1 +dp4 $worldPos.z, $vPos, $cModel2 + +&AllocateRegister( \$projPos ); + +; Transform position from object to projection space +dp4 $projPos.x, $vPos, $cModelViewProj0 +dp4 $projPos.y, $vPos, $cModelViewProj1 +dp4 $projPos.z, $vPos, $cModelViewProj2 +dp4 $projPos.w, $vPos, $cModelViewProj3 + +mov oPos, $projPos + +;------------------------------------------------------------------------------ +; Fog +;------------------------------------------------------------------------------ +&CalcFog( $worldPos, $projPos ); + +&FreeRegister( \$projPos ); + +;------------------------------------------------------------------------------ +; Lighting +;------------------------------------------------------------------------------ + +; Transform tangent space basis vectors to env map space (world space) +; This will produce a set of vectors mapping from tangent space to env space +; We'll use this to transform normals from the normal map from tangent space +; to environment map space. +; NOTE: use dp3 here since the basis vectors are vectors, not points + +dp3 oT1.x, $vTangentS, $cModel0 +dp3 oT2.x, $vTangentS, $cModel1 +dp3 oT3.x, $vTangentS, $cModel2 + +dp3 oT1.y, $vTangentT, $cModel0 +dp3 oT2.y, $vTangentT, $cModel1 +dp3 oT3.y, $vTangentT, $cModel2 + +dp3 oT1.z, $vNormal, $cModel0 +dp3 oT2.z, $vNormal, $cModel1 +dp3 oT3.z, $vNormal, $cModel2 + +; Compute the vector from vertex to camera +&AllocateRegister( \$worldEyeVect ); +sub $worldEyeVect.xyz, $cEyePos, $worldPos +&FreeRegister( \$worldPos ); + +; Move it into the w component of the texture coords, as the wacky +; pixel shader wants it there. +mov oT1.w, $worldEyeVect.x +mov oT2.w, $worldEyeVect.y +mov oT3.w, $worldEyeVect.z + +; Get the magnitude of worldEyeVect +dp3 $worldEyeVect.w, $worldEyeVect, $worldEyeVect +rsq $worldEyeVect.w, $worldEyeVect.w +rcp $worldEyeVect.w, $worldEyeVect.w + +; calculate the cheap water blend factor and stick it into oD0.a +; NOTE: This won't be perspective correct!!!!! +; OPTIMIZE: This could turn into a mad. +add $worldEyeVect.w, $worldEyeVect.w, -$SHADER_SPECIFIC_CONST_2.x +mul oD0, $worldEyeVect.w, $SHADER_SPECIFIC_CONST_2.y + +&FreeRegister( \$worldEyeVect ); + +;------------------------------------------------------------------------------ +; Texture coordinates +;------------------------------------------------------------------------------ +dp4 oT0.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_0 +dp4 oT0.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_1 + + + diff --git a/materialsystem/stdshaders/WaterCheap_vs14.vsh b/materialsystem/stdshaders/WaterCheap_vs14.vsh new file mode 100644 index 0000000..0e5a107 --- /dev/null +++ b/materialsystem/stdshaders/WaterCheap_vs14.vsh @@ -0,0 +1,96 @@ +vs.1.1 + +# DYNAMIC: "DOWATERFOG" "0..1" + +#include "macros.vsh" + +;------------------------------------------------------------------------------ +; Vertex blending +;------------------------------------------------------------------------------ + +&AllocateRegister( \$worldPos ); + +; Transform position from object to world +dp4 $worldPos.x, $vPos, $cModel0 +dp4 $worldPos.y, $vPos, $cModel1 +dp4 $worldPos.z, $vPos, $cModel2 + +&AllocateRegister( \$projPos ); + +; Transform position from object to projection space +dp4 $projPos.x, $vPos, $cModelViewProj0 +dp4 $projPos.y, $vPos, $cModelViewProj1 +dp4 $projPos.z, $vPos, $cModelViewProj2 +dp4 $projPos.w, $vPos, $cModelViewProj3 + +mov oPos, $projPos + +;------------------------------------------------------------------------------ +; Fog +;------------------------------------------------------------------------------ +&CalcFog( $worldPos, $projPos ); + +&FreeRegister( \$projPos ); + +;------------------------------------------------------------------------------ +; Lighting +;------------------------------------------------------------------------------ + +; Transform tangent space basis vectors to env map space (world space) +; This will produce a set of vectors mapping from tangent space to env space +; We'll use this to transform normals from the normal map from tangent space +; to environment map space. +; NOTE: use dp3 here since the basis vectors are vectors, not points + +dp3 oT1.x, $vTangentS, $cModel0 +dp3 oT2.x, $vTangentS, $cModel1 +dp3 oT3.x, $vTangentS, $cModel2 + +dp3 oT1.y, $vTangentT, $cModel0 +dp3 oT2.y, $vTangentT, $cModel1 +dp3 oT3.y, $vTangentT, $cModel2 + +dp3 oT1.z, $vNormal, $cModel0 +dp3 oT2.z, $vNormal, $cModel1 +dp3 oT3.z, $vNormal, $cModel2 + +; Compute the vector from vertex to camera +&AllocateRegister( \$worldEyeVect ); +sub $worldEyeVect.xyz, $cEyePos, $worldPos +&FreeRegister( \$worldPos ); + +; eye vector +mov oT4.xyz, $worldEyeVect + +alloc $tangentEyeVect + +; transform the eye vector to tangent space +dp3 $tangentEyeVect.x, $worldEyeVect, $vTangentS +dp3 $tangentEyeVect.y, $worldEyeVect, $vTangentT +dp3 $tangentEyeVect.z, $worldEyeVect, $vNormal + +; Get the magnitude of worldEyeVect +dp3 $worldEyeVect.w, $worldEyeVect, $worldEyeVect +rsq $worldEyeVect.w, $worldEyeVect.w +rcp $worldEyeVect.w, $worldEyeVect.w + +; calculate the cheap water blend factor and stick it into oD0.a +; NOTE: This won't be perspective correct!!!!! +; OPTIMIZE: This could turn into a mad. +add $worldEyeVect.w, $worldEyeVect.w, -$SHADER_SPECIFIC_CONST_2.x +mul oD0, $worldEyeVect.w, $SHADER_SPECIFIC_CONST_2.y + +; stick the tangent space eye vector into oT5.xyz +mov oT5.xyz, $tangentEyeVect + +&FreeRegister( \$worldEyeVect ); +&FreeRegister( \$tangentEyeVect ); + +;------------------------------------------------------------------------------ +; Texture coordinates +;------------------------------------------------------------------------------ +dp4 oT0.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_0 +dp4 oT0.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_1 + + + diff --git a/materialsystem/stdshaders/WaterCheap_vs20.fxc b/materialsystem/stdshaders/WaterCheap_vs20.fxc new file mode 100644 index 0000000..bae0238 --- /dev/null +++ b/materialsystem/stdshaders/WaterCheap_vs20.fxc @@ -0,0 +1,84 @@ +// STATIC: "BLEND" "0..1" +#include "common_vs_fxc.h" + +struct VS_INPUT +{ + float4 vPos : POSITION; + float4 vNormal : NORMAL; + float2 vNormalMapCoord : TEXCOORD0; + float3 vTangentS : TANGENT; + float3 vTangentT : BINORMAL; +}; + +struct VS_OUTPUT +{ + float4 projPos : POSITION; +#if !defined( _X360 ) + float fog : FOG; +#endif + float2 normalMapTexCoord : TEXCOORD0; + float3 worldVertToEyeVector : TEXCOORD1; + float3x3 tangentSpaceTranspose : TEXCOORD2; + float4 vRefract_W_ProjZ : TEXCOORD5; + float4 vExtraBumpTexCoord : TEXCOORD6; + float4 fogFactorW : COLOR1; +}; + +const float4 cNormalMapTransform[2] : register( SHADER_SPECIFIC_CONST_0 ); +const float4 TexOffsets : register( SHADER_SPECIFIC_CONST_3 ); + +VS_OUTPUT main( const VS_INPUT v ) +{ + VS_OUTPUT o = ( VS_OUTPUT )0; + + float3 vObjNormal; + DecompressVertex_Normal( v.vNormal, vObjNormal ); + + float4 projPos; + float3 worldPos; + + projPos = mul( v.vPos, cModelViewProj ); + o.projPos = projPos; + +#if BLEND + // Map projected position to the reflection texture + o.vRefract_W_ProjZ.x = projPos.x; + o.vRefract_W_ProjZ.y = -projPos.y; // invert Y + o.vRefract_W_ProjZ.xy = (o.vRefract_W_ProjZ + projPos.w) * 0.5f; + o.vRefract_W_ProjZ.z = projPos.w; +#endif + + o.vRefract_W_ProjZ.w = projPos.z; + + worldPos = mul( v.vPos, cModel[0] ); + + float3 worldTangentS = mul( v.vTangentS, ( const float3x3 )cModel[0] ); + float3 worldTangentT = mul( v.vTangentT, ( const float3x3 )cModel[0] ); + float3 worldNormal = mul( vObjNormal, ( float3x3 )cModel[0] ); + o.tangentSpaceTranspose[0] = worldTangentS; + o.tangentSpaceTranspose[1] = worldTangentT; + o.tangentSpaceTranspose[2] = worldNormal; + + float3 worldVertToEyeVector = VSHADER_VECT_SCALE * (cEyePos - worldPos); + o.worldVertToEyeVector = worldVertToEyeVector; + + // FIXME: need to add a normalMapTransform to all of the water shaders. + //o.normalMapTexCoord.x = dot( v.vNormalMapCoord, cNormalMapTransform[0] ) + cNormalMapTransform[0].w; + //o.normalMapTexCoord.y = dot( v.vNormalMapCoord, cNormalMapTransform[1] ) + cNormalMapTransform[1].w; + o.normalMapTexCoord = v.vNormalMapCoord; + + float f45x=v.vNormalMapCoord.x+v.vNormalMapCoord.y; + float f45y=v.vNormalMapCoord.y-v.vNormalMapCoord.x; + o.vExtraBumpTexCoord.x=f45x*0.1+TexOffsets.x; + o.vExtraBumpTexCoord.y=f45y*0.1+TexOffsets.y; + o.vExtraBumpTexCoord.z=v.vNormalMapCoord.y*0.45+TexOffsets.z; + o.vExtraBumpTexCoord.w=v.vNormalMapCoord.x*0.45+TexOffsets.w; + + o.fogFactorW = CalcFog( worldPos, projPos, FOGTYPE_RANGE ); +#if !defined( _X360 ) + o.fog = o.fogFactorW; +#endif + return o; +} + + diff --git a/materialsystem/stdshaders/WaterReflect_ps11.psh b/materialsystem/stdshaders/WaterReflect_ps11.psh new file mode 100644 index 0000000..785ced6 --- /dev/null +++ b/materialsystem/stdshaders/WaterReflect_ps11.psh @@ -0,0 +1,27 @@ +ps.1.1 + +; t0: +; texture: dudv map +; texcoords: dudvmap texcoords +; t1: +; texture: reflection render target +; texcoords: +; t2: +; texture: normal map (usef for fresnel calculation) +; texcoords: +; t4: texture: normalization cube map +; texcoords: eye vect + +tex t0 ; sample dudv map +texbem t1, t0 ; reflection +tex t2 ; normal map +tex t3 ; eye vector (through normalization cubemap) + +; dot eye-vector with per-pixel normal from t2 +dp3_sat r1.rgba, t3_bx2, t2_bx2 + +; run Fresnel approx. on it: R0 + (1-R0) (1-cos(q))^5 +mul r0.a, 1-r1.a, 1-r1.a // squared +mul r0.a, r0.a, r0.a // quartic +mul r0.rgb, t1, c0 // shove color from reflection render target into r0 ++mul_sat r0.a, r0.a, 1-r1.a // quintic \ No newline at end of file diff --git a/materialsystem/stdshaders/WaterRefractFresnel_ps11.psh b/materialsystem/stdshaders/WaterRefractFresnel_ps11.psh new file mode 100644 index 0000000..efade0f --- /dev/null +++ b/materialsystem/stdshaders/WaterRefractFresnel_ps11.psh @@ -0,0 +1,24 @@ +ps.1.1 + +; t0: +; texture: dudv map +; texcoords: dudvmap texcoords +; t1: +; texture: refraction render target +; texcoords: + +tex t0 ; sample dudv map +texbem t1, t0 ; refraction +tex t2 ; The normal map +tex t3 ; Normalize the tangent-space vector to the eye + +; dot eye-vector with per-pixel normal from t2 +dp3_sat r1.rgba, t2_bx2, t3_bx2 + +mul r0.a, 1-r1.a, 1-r1.a ; squared +mul r0.a, r0.a, r0.a ; quartic + +mul r0.rgb, t1, c0 ++mul_sat r0.a, r0.a, 1-r1.a ; quintic + +add_sat r0.a, r0.a, v0.a ; cheap water distance diff --git a/materialsystem/stdshaders/WaterRefract_ps11.psh b/materialsystem/stdshaders/WaterRefract_ps11.psh new file mode 100644 index 0000000..fbe7547 --- /dev/null +++ b/materialsystem/stdshaders/WaterRefract_ps11.psh @@ -0,0 +1,13 @@ +ps.1.1 + +; t0: +; texture: dudv map +; texcoords: dudvmap texcoords +; t1: +; texture: refraction render target +; texcoords: + +tex t0 ; sample dudv map +texbem t1, t0 ; refraction + +mul r0, t1, c0 diff --git a/materialsystem/stdshaders/Water_ps14.psh b/materialsystem/stdshaders/Water_ps14.psh new file mode 100644 index 0000000..55e6b0c --- /dev/null +++ b/materialsystem/stdshaders/Water_ps14.psh @@ -0,0 +1,96 @@ +; STATIC: "REFLECT" "0..1" +; STATIC: "REFRACT" "0..1" +ps.1.4 +; T2 - refraction +; T3 - normal map +; T4 - reflection +; TC0 - normal map coords +; TC1 - proj tex coords (reflection) +; TC2 - proj tex coords (refraction) +; TC3 - tangent space view vec +; TC4 - displacement scale + +; sample normal map +texld r3, t0 + +#if REFLECT +; reflection coords +texcrd r4.xy, t1_dw.xyw +#endif +#if REFRACT +; refraction coords +texcrd r2.xy, t2_dw.xyw +#endif +; tangent space eye vector +texld r1, t5 ; <---- Normalizing CUBE MAP here!!! +; reflection/refraction scale (x,y) +texcrd r0.xyz, t4.xyz + +; perturb coords by constant displacement +; and by normal map alpha (which has 1/(2**miplevel in it) +mul r0.rg, r0, r3.a +#if REFLECT +mad r4.rg, r3_bx2, r0.x, r4 +#endif + +#if REFRACT +mad r2.rg, r3_bx2, r0.y, r2 +#endif + +; stuff something into z so that texld will deal +#if REFLECT +mov r4.b, c5 +#endif +#if REFRACT +mov r2.b, c5 +#endif + +phase + +#if REFLECT +; reflection +texld r4, r4 +#endif +#if REFRACT +; refraction +texld r2, r2 +#endif + +#if REFLECT +; N.V +dp3_sat r1.a, r3_bx2, r1_bx2 +#endif + +#if REFRACT +; tint refraction +mul r2.rgb, r2, c1 +#endif + +#if REFLECT +; tint reflction +mul r4.rgb, r4, c4 + +; (1-N.V) ^ 5 ++mul r0.a, 1-r1.a, 1-r1.a +mul r0.a, r0.a, r0.a +mul_sat r0.a, r0.a, 1-r1.a +#endif + +#if !REFLECT && !REFRACT +; This is wrong!!!! +mov r0.rgba, c0 +#endif + +#if !REFLECT && REFRACT +mov r0.rgba, r2 +#endif + +#if REFLECT && !REFRACT +mov r0.rgba, r4 +#endif + +#if REFLECT && REFRACT +; reflection * fresnel + refraction * ( 1 - fresnel ) +lrp r0.rgba, r0.a, r4, r2 +#endif + diff --git a/materialsystem/stdshaders/Water_ps14.vsh b/materialsystem/stdshaders/Water_ps14.vsh new file mode 100644 index 0000000..0ec30aa --- /dev/null +++ b/materialsystem/stdshaders/Water_ps14.vsh @@ -0,0 +1,95 @@ +vs.1.1 + +# DYNAMIC: "DOWATERFOG" "0..1" + +;------------------------------------------------------------------------------ +; Constants specified by the app +; c0 = (0, 1, 2, 0.5) +; c1 = (1/2.2, 0, 0, 0) +; c2 = camera position *in world space* +; c4-c7 = modelViewProj matrix (transpose) +; c8-c11 = ViewProj matrix (transpose) +; c12-c15 = model->view matrix (transpose) +; c16 = [fogStart, fogEnd, fogRange, undefined] +; +; $SHADER_SPECIFIC_CONST_0..$SHADER_SPECIFIC_CONST_3 - special proj matrix +; +; Vertex components (as specified in the vertex DECL) +; $vPos = Position +; $vTexCoord0.xy = TexCoord0 +;------------------------------------------------------------------------------ + +#include "macros.vsh" + +; Vertex components +; $vPos = Position +; $vNormal = normal +; $vTexCoord0.xy = TexCoord0 +; $vTangentS = S axis of Texture space +; $vTangentT = T axis of Texture space + + +;------------------------------------------------------------------------------ +; Transform the position from world to view space +;------------------------------------------------------------------------------ + + +alloc $projPos + +; Transform position from object to projection space +dp4 $projPos.x, $vPos, $cModelViewProj0 +dp4 $projPos.y, $vPos, $cModelViewProj1 +dp4 $projPos.z, $vPos, $cModelViewProj2 +dp4 $projPos.w, $vPos, $cModelViewProj3 +mov oPos, $projPos + +alloc $worldPos + +; Transform position from object to world space +dp4 $worldPos.x, $vPos, $cModel0 +dp4 $worldPos.y, $vPos, $cModel1 +dp4 $worldPos.z, $vPos, $cModel2 + +&CalcFog( $worldPos, $projPos ); + +alloc $worldEyeVect + +; Get the eye vector in world space +add $worldEyeVect.xyz, -$worldPos, $cEyePos + +alloc $tangentEyeVect + +; transform the eye vector to tangent space +dp3 $tangentEyeVect.x, $worldEyeVect, $vTangentS +dp3 $tangentEyeVect.y, $worldEyeVect, $vTangentT +dp3 $tangentEyeVect.z, $worldEyeVect, $vNormal +mov $tangentEyeVect.w, $cZero + +mov oT5, $tangentEyeVect + +; base coordinates +dp4 oT0.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_1 +dp4 oT0.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_2 + +; reflection +alloc $projPosReflect + +mov $projPosReflect, $projPos +add $projPosReflect.xy, $projPosReflect, $projPosReflect.w +mul $projPosReflect.xy, $projPosReflect, $cHalf +mov oT1, $projPosReflect + +; refraction +mov $projPos.y, -$projPos.y +add $projPos.xy, $projPos, $projPos.w +mul $projPos.xy, $projPos, $cHalf +mov oT2, $projPos + +; reflectionscale, refractionscale +mov oT4, $SHADER_SPECIFIC_CONST_4 + +free $worldEyeVect +free $tangentEyeVect +free $projPosReflect +free $worldPos +free $projPos \ No newline at end of file diff --git a/materialsystem/stdshaders/Water_vs11.vsh b/materialsystem/stdshaders/Water_vs11.vsh new file mode 100644 index 0000000..3b0131b --- /dev/null +++ b/materialsystem/stdshaders/Water_vs11.vsh @@ -0,0 +1,102 @@ +vs.1.1 + +# DYNAMIC: "DOWATERFOG" "0..1" + +;------------------------------------------------------------------------------ +; Constants specified by the app +; c0 = (0, 1, 2, 0.5) +; c1 = (1/2.2, 0, 0, 0) +; c2 = camera position *in world space* +; c4-c7 = modelViewProj matrix (transpose) +; c8-c11 = ViewProj matrix (transpose) +; c12-c15 = model->view matrix (transpose) +; c16 = [fogStart, fogEnd, fogRange, undefined] +; +; Vertex components (as specified in the vertex DECL) +; $vPos = Position +; $vTexCoord0.xy = TexCoord0 +;------------------------------------------------------------------------------ + +#include "macros.vsh" + +; Vertex components +; $vPos = Position +; $vNormal = normal +; $vTexCoord0.xy = TexCoord0 +; $vTangentS = S axis of Texture space +; $vTangentT = T axis of Texture space + +;------------------------------------------------------------------------------ +; Transform the position from world to view space +;------------------------------------------------------------------------------ + +alloc $projPos + +; Transform position from object to projection space +dp4 $projPos.x, $vPos, $cModelViewProj0 +dp4 $projPos.y, $vPos, $cModelViewProj1 +dp4 $projPos.z, $vPos, $cModelViewProj2 +dp4 $projPos.w, $vPos, $cModelViewProj3 + +alloc $worldPos + +; Transform position from object to world space +dp4 $worldPos.x, $vPos, $cModel0 +dp4 $worldPos.y, $vPos, $cModel1 +dp4 $worldPos.z, $vPos, $cModel2 + +&CalcFog( $worldPos, $projPos ); + +alloc $worldEyeVect + +; Get the eye vector in world space +add $worldEyeVect.xyz, -$worldPos, $cEyePos + +; transform the eye vector to tangent space +dp3 oT3.x, $worldEyeVect, $vTangentS +dp3 oT3.y, $worldEyeVect, $vTangentT +dp3 oT3.z, $worldEyeVect, $vNormal + +; Get the magnitude of worldEyeVect +dp3 $worldEyeVect.w, $worldEyeVect, $worldEyeVect +rsq $worldEyeVect.w, $worldEyeVect.w +rcp $worldEyeVect.w, $worldEyeVect.w + +; calculate the cheap water blend factor and stick it into oD0.a +; NOTE: This won't be perspective correct!!!!! +; OPTIMIZE: This could turn into a mad. +add $worldEyeVect.w, $worldEyeVect.w, -$SHADER_SPECIFIC_CONST_3.x +mul oD0, $worldEyeVect.w, $SHADER_SPECIFIC_CONST_3.y + +; dudv map +alloc $bumpTexCoord + +dp4 $bumpTexCoord.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_1 +dp4 $bumpTexCoord.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_2 + +mov oT0.xy, $bumpTexCoord + +; normal map +mov oT2.xy, $bumpTexCoord + +free $bumpTexCoord + +alloc $newProjPos + +mov oPos, $projPos + +; special case perspective correct texture projection so that the texture fits exactly on the screen +mul $projPos.y, $projPos.y, $SHADER_SPECIFIC_CONST_4.w +add $projPos.xy, $projPos.xy, $projPos.w +mul $projPos.xy, $projPos.xy, $cHalf + +mov oT1.xy, $projPos.xy +mov oT1.z, $cZero +mov oT1.w, $projPos.w + +free $projPos +free $worldPos +free $worldEyeVect +free $projTangentS +free $projTangentT +free $newProjPos diff --git a/materialsystem/stdshaders/Water_vs20.fxc b/materialsystem/stdshaders/Water_vs20.fxc new file mode 100644 index 0000000..8f3a7a8 --- /dev/null +++ b/materialsystem/stdshaders/Water_vs20.fxc @@ -0,0 +1,117 @@ +// STATIC: "BASETEXTURE" "0..1" +// STATIC: "MULTITEXTURE" "0..1" + +// SKIP: $MULTITEXTURE && $BASETEXTURE + +#include "common_vs_fxc.h" + +const float4 cBumpTexCoordTransform[2] : register( SHADER_SPECIFIC_CONST_1 ); +const float4 TexOffsets : register( SHADER_SPECIFIC_CONST_3 ); + +struct VS_INPUT +{ + float4 vPos : POSITION; + float4 vNormal : NORMAL; + float4 vBaseTexCoord : TEXCOORD0; + float2 vLightmapTexCoord : TEXCOORD1; + float2 vLightmapTexCoordOffset : TEXCOORD2; + float3 vTangentS : TANGENT; + float3 vTangentT : BINORMAL0; +}; + +struct VS_OUTPUT +{ + float4 vProjPos_POSITION : POSITION; +#if !defined( _X360 ) + float vFog : FOG; +#endif + float2 vBumpTexCoord : TEXCOORD0; + float3 vTangentEyeVect : TEXCOORD1; + float4 vReflectXY_vRefractYX : TEXCOORD2; + float W : TEXCOORD3; + float4 vProjPos : TEXCOORD4; + float screenCoord : TEXCOORD5; +#if MULTITEXTURE + float4 vExtraBumpTexCoord : TEXCOORD6; +#endif +#if BASETEXTURE + HALF4 lightmapTexCoord1And2 : TEXCOORD6; + HALF4 lightmapTexCoord3 : TEXCOORD7; +#endif + float4 fogFactorW : COLOR1; +}; + +VS_OUTPUT main( const VS_INPUT v ) +{ + VS_OUTPUT o = ( VS_OUTPUT )0; + + float3 vObjNormal; + DecompressVertex_Normal( v.vNormal, vObjNormal ); + + // Projected position + float4 vProjPos = mul( v.vPos, cModelViewProj ); + o.vProjPos = o.vProjPos_POSITION = vProjPos; + + // Project tangent basis + float2 vProjTangentS = mul( v.vTangentS, cViewProj ); + float2 vProjTangentT = mul( v.vTangentT, cViewProj ); + + // Map projected position to the reflection texture + float2 vReflectPos; + vReflectPos = (vProjPos.xy + vProjPos.w) * 0.5f; + + // Map projected position to the refraction texture + float2 vRefractPos; + vRefractPos.x = vProjPos.x; + vRefractPos.y = -vProjPos.y; // invert Y + vRefractPos = (vRefractPos + vProjPos.w) * 0.5f; + + // Reflection transform + o.vReflectXY_vRefractYX = float4( vReflectPos.x, vReflectPos.y, vRefractPos.y, vRefractPos.x ); + o.W = vProjPos.w; + + o.screenCoord = vProjPos.x; + + // Compute fog based on the position + float3 vWorldPos = mul( v.vPos, cModel[0] ); + o.fogFactorW = CalcFog( vWorldPos, vProjPos, FOGTYPE_RANGE ); +#if !defined( _X360 ) + o.vFog = o.fogFactorW; +#endif + + // Eye vector + float3 vWorldEyeVect = cEyePos - vWorldPos; + // Transform to the tangent space + o.vTangentEyeVect.x = dot( vWorldEyeVect, v.vTangentS ); + o.vTangentEyeVect.y = dot( vWorldEyeVect, v.vTangentT ); + o.vTangentEyeVect.z = dot( vWorldEyeVect, vObjNormal ); + + // Tranform bump coordinates + o.vBumpTexCoord.x = dot( v.vBaseTexCoord, cBumpTexCoordTransform[0] ); + o.vBumpTexCoord.y = dot( v.vBaseTexCoord, cBumpTexCoordTransform[1] ); + float f45x=v.vBaseTexCoord.x+v.vBaseTexCoord.y; + float f45y=v.vBaseTexCoord.y-v.vBaseTexCoord.x; +#if MULTITEXTURE + o.vExtraBumpTexCoord.x=f45x*0.1+TexOffsets.x; + o.vExtraBumpTexCoord.y=f45y*0.1+TexOffsets.y; + o.vExtraBumpTexCoord.z=v.vBaseTexCoord.y*0.45+TexOffsets.z; + o.vExtraBumpTexCoord.w=v.vBaseTexCoord.x*0.45+TexOffsets.w; +#endif + +#if BASETEXTURE + o.lightmapTexCoord1And2.xy = v.vLightmapTexCoord + v.vLightmapTexCoordOffset; + + float2 lightmapTexCoord2 = o.lightmapTexCoord1And2.xy + v.vLightmapTexCoordOffset; + float2 lightmapTexCoord3 = lightmapTexCoord2 + v.vLightmapTexCoordOffset; + + // reversed component order + o.lightmapTexCoord1And2.w = lightmapTexCoord2.x; + o.lightmapTexCoord1And2.z = lightmapTexCoord2.y; + + o.lightmapTexCoord3.xy = lightmapTexCoord3; +#endif + + return o; +} + + diff --git a/materialsystem/stdshaders/WorldTexture.psh b/materialsystem/stdshaders/WorldTexture.psh new file mode 100644 index 0000000..933435b --- /dev/null +++ b/materialsystem/stdshaders/WorldTexture.psh @@ -0,0 +1,14 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; Draw a texture . . woo hoo! +; t0 - texture +; +; The texture coordinates need to be defined as follows: +; tc0 - texcoords +;------------------------------------------------------------------------------ + +; Get the color from the texture +tex t0 +mov r0, t0 + diff --git a/materialsystem/stdshaders/WorldTwoTextureBlend.psh b/materialsystem/stdshaders/WorldTwoTextureBlend.psh new file mode 100644 index 0000000..a3f3c6a --- /dev/null +++ b/materialsystem/stdshaders/WorldTwoTextureBlend.psh @@ -0,0 +1,21 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; Draw a texture . . woo hoo! +; t0 - texture +; +; The texture coordinates need to be defined as follows: +; tc0 - texcoords +;------------------------------------------------------------------------------ + +tex t0 +tex t1 +tex t2 + +mov r0.rgb, t0 + +mul r0.a, t0.a, v0.a ; Grab alpha from vertex color + +lrp r0.rgb, t2.a, t2, r0 ; Base = base * (1 - detail alpha) + detail * detail alpha +mul r0.rgb, r0, v0 ; modulate by vertex color +mul r0.rgb, t1, r0 ; fold in lightmap (color only) +mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2) diff --git a/materialsystem/stdshaders/WorldTwoTextureBlend_DetailAlpha.psh b/materialsystem/stdshaders/WorldTwoTextureBlend_DetailAlpha.psh new file mode 100644 index 0000000..d5e0736 --- /dev/null +++ b/materialsystem/stdshaders/WorldTwoTextureBlend_DetailAlpha.psh @@ -0,0 +1,25 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; Draw a texture . . woo hoo! +; t0 - texture +; +; The texture coordinates need to be defined as follows: +; tc0 - texcoords +;------------------------------------------------------------------------------ + +def c1, 1.0f, 1.0f, 1.0f, 1.0f + +tex t0 +tex t1 +tex t2 + +mov_x2_sat r0.rgb, t0 + ; r0 = sat( t0 * 2 ) +mul r0.a, t0.a, v0.a ; Grab alpha from vertex color + +lrp_sat r0.rgb, t2.a, r0, c1 ; r0 = B*Da + (1-Da) + +mul r0.rgb, r0, t2 ; modulate by detail color +mul r0.rgb, r0, v0 ; modulate by vertex color +mul r0.rgb, t1, r0 ; fold in lightmap (color only) +mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2) diff --git a/materialsystem/stdshaders/WorldTwoTextureBlend_SelfIlluminated.psh b/materialsystem/stdshaders/WorldTwoTextureBlend_SelfIlluminated.psh new file mode 100644 index 0000000..75ce4b5 --- /dev/null +++ b/materialsystem/stdshaders/WorldTwoTextureBlend_SelfIlluminated.psh @@ -0,0 +1,27 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; Draw a texture . . woo hoo! +; t0 - texture +; +; The texture coordinates need to be defined as follows: +; tc0 - texcoords +;------------------------------------------------------------------------------ + +tex t0 +tex t1 +tex t2 + +mov r0.rgb, t0 + +mov r0.a, v0.a ; Grab alpha from vertex color + +lrp r0.rgb, t2.a, t2, r0 ; Base = base * (1 - detail alpha) + detail * detail alpha +mul r0.rgb, r0, v0 ; modulate by vertex color +mul r0.rgb, t1, r0 ; fold in lightmap (color only) +mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2) + +mul r1.rgb, c1, t0 ; Self illum * tint ++ mul r1.a, t0.a, 1-t2.a ; Reduce self-illum amount based on 1 - detailalpha + +lrp r0.rgb, t0.a, r1, r0 ; Blend between self-illum + base * lightmap + diff --git a/materialsystem/stdshaders/WorldVertexAlpha.psh b/materialsystem/stdshaders/WorldVertexAlpha.psh new file mode 100644 index 0000000..67e6a1e --- /dev/null +++ b/materialsystem/stdshaders/WorldVertexAlpha.psh @@ -0,0 +1,10 @@ +ps.1.1 + +tex t0 ; basetexture +tex t1 ; lightmap + +mov r0.a, 1-t1.a +;mov r0.rgb, t0 ; * 2 * (overbrightFactor/2) +;mov_x2 r0.rgb, t0 ; * 2 * (overbrightFactor/2) +mul r0.rgb, t0, t1; +mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2) diff --git a/materialsystem/stdshaders/WorldVertexAlpha.vsh b/materialsystem/stdshaders/WorldVertexAlpha.vsh new file mode 100644 index 0000000..ae2566a --- /dev/null +++ b/materialsystem/stdshaders/WorldVertexAlpha.vsh @@ -0,0 +1,37 @@ +vs.1.1 + +# DYNAMIC: "DOWATERFOG" "0..1" + +#include "macros.vsh" + +local( $worldPos, $worldNormal, $projPos, $reflectionVector ); + +&AllocateRegister( \$projPos ); + +dp4 $projPos.x, $vPos, $cModelViewProj0 +dp4 $projPos.y, $vPos, $cModelViewProj1 +dp4 $projPos.z, $vPos, $cModelViewProj2 +dp4 $projPos.w, $vPos, $cModelViewProj3 +mov oPos, $projPos + +&AllocateRegister( \$worldPos ); + +; garymcthack +dp4 $worldPos.z, $vPos, $cModel2 + +&CalcFog( $worldPos, $projPos ); + +&FreeRegister( \$worldPos ); +&FreeRegister( \$projPos ); + +;------------------------------------------------------------------------------ +; Texture coordinates +;------------------------------------------------------------------------------ +; base texcoords +mov oT0, $vTexCoord0 + +; lightmap texcoords +mov oT1, $vTexCoord1 + +&FreeRegister( \$worldPos ); # garymcthack + diff --git a/materialsystem/stdshaders/WorldVertexAlpha_ps2x.fxc b/materialsystem/stdshaders/WorldVertexAlpha_ps2x.fxc new file mode 100644 index 0000000..7ccc584 --- /dev/null +++ b/materialsystem/stdshaders/WorldVertexAlpha_ps2x.fxc @@ -0,0 +1,43 @@ +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX] +// STATIC: "PASS" "0..1" + +#define HDRTYPE HDR_TYPE_NONE +#include "common_ps_fxc.h" + +// CENTROID: TEXCOORD1 + +sampler BaseSampler : register( s0 ); +sampler LightmapSampler: register( s1 ); +sampler LightmapAlphaSampler: register( s2 ); + +struct PS_INPUT +{ + float2 baseCoord : TEXCOORD0; + float2 lightmapCoord : TEXCOORD1; +}; + +float4 main( PS_INPUT i ) : COLOR +{ + bool bAlphaPass = PASS ? true : false; + + float4 base = tex2D( BaseSampler, i.baseCoord ); + float4 lightmap = tex2D( LightmapSampler, i.lightmapCoord ); + float4 alpha = tex2D( LightmapAlphaSampler, i.lightmapCoord ); + + float4 color; + + base.a = dot( base, HALF3( HALF_CONSTANT(0.33333f), HALF_CONSTANT(0.33333f), HALF_CONSTANT(0.33333f) ) ); + color = 2.0f * base * lightmap; // The 2x is for an assumed overbright 2 (it's always 2 on dx9) + + if( bAlphaPass ) + { + // Don't care about color, just return pre-multiplied alpha + return FinalOutput( float4( 0.0f, 0.0f, 1.0f, (1.0f - alpha.a) * color.a ), 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE ); + } + else + { + return FinalOutput( float4( color.rgb, (1.0f - alpha.a) ), 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE ); + } +} + diff --git a/materialsystem/stdshaders/WorldVertexTransition.psh b/materialsystem/stdshaders/WorldVertexTransition.psh new file mode 100644 index 0000000..76249b3 --- /dev/null +++ b/materialsystem/stdshaders/WorldVertexTransition.psh @@ -0,0 +1,18 @@ +; STATIC: "DETAIL" "0..1" +ps.1.1 + +tex t0 ; basetexture +tex t1 ; basetexture2 +tex t2 ; lightmap +#if DETAIL +tex t3 ; detail +#endif + +mov_sat r1.a, v0.a +lrp r0, r1.a, t1, t0 + +mul r0, r0, t2 +#if DETAIL +mul_x2 r0.rgb, r0, t3 +#endif +mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2) diff --git a/materialsystem/stdshaders/WorldVertexTransition.vsh b/materialsystem/stdshaders/WorldVertexTransition.vsh new file mode 100644 index 0000000..81e56db --- /dev/null +++ b/materialsystem/stdshaders/WorldVertexTransition.vsh @@ -0,0 +1,48 @@ +vs.1.1 + +# DYNAMIC: "DOWATERFOG" "0..1" + +#include "macros.vsh" + +local( $worldPos, $worldNormal, $projPos, $reflectionVector ); + +&AllocateRegister( \$projPos ); + +dp4 $projPos.x, $vPos, $cModelViewProj0 +dp4 $projPos.y, $vPos, $cModelViewProj1 +dp4 $projPos.z, $vPos, $cModelViewProj2 +dp4 $projPos.w, $vPos, $cModelViewProj3 +mov oPos, $projPos + +&AllocateRegister( \$worldPos ); + +; garymcthack +dp4 $worldPos.z, $vPos, $cModel2 + +&CalcFog( $worldPos, $projPos ); + +&FreeRegister( \$worldPos ); +&FreeRegister( \$projPos ); + +;------------------------------------------------------------------------------ +; Texture coordinates +;------------------------------------------------------------------------------ +; base texcoords +dp4 oT0.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_0 +dp4 oT0.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_1 + +dp4 oT1.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_2 +dp4 oT1.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_3 + +; lightmap texcoords +mov oT2, $vTexCoord1 + +; detail +dp4 oT3.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_4 +dp4 oT3.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_5 + +; Now the basetexture/basetexture2 blend uses vertex color, so send it into the psh. +mov oD0, $vColor + +&FreeRegister( \$worldPos ); # garymcthack + diff --git a/materialsystem/stdshaders/WorldVertexTransition_BlendBase2.psh b/materialsystem/stdshaders/WorldVertexTransition_BlendBase2.psh new file mode 100644 index 0000000..6c959f1 --- /dev/null +++ b/materialsystem/stdshaders/WorldVertexTransition_BlendBase2.psh @@ -0,0 +1,16 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; Draw a texture . . woo hoo! +; t0 - texture +; +; The texture coordinates need to be defined as follows: +; tc0 - texcoords +;------------------------------------------------------------------------------ + +tex t0 +tex t1 +mul r0.rgb, t1, t0 ; fold in lightmap (color) ++mov r0.a, v0.a ; fold in lightmap (alpha) +mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2) + diff --git a/materialsystem/stdshaders/WorldVertexTransition_Editor.psh b/materialsystem/stdshaders/WorldVertexTransition_Editor.psh new file mode 100644 index 0000000..a818128 --- /dev/null +++ b/materialsystem/stdshaders/WorldVertexTransition_Editor.psh @@ -0,0 +1,10 @@ +ps.1.1 + +tex t0 ; basetexture +tex t1 ; basetexture2 +tex t2 ; lightmap + +; The editor uses vertex alpha as the blend factor +lrp r0, 1-v0.a, t1, t0 +mul r0, r0, t2 +mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2) diff --git a/materialsystem/stdshaders/WorldVertexTransition_Seamless.psh b/materialsystem/stdshaders/WorldVertexTransition_Seamless.psh new file mode 100644 index 0000000..db9d0cd --- /dev/null +++ b/materialsystem/stdshaders/WorldVertexTransition_Seamless.psh @@ -0,0 +1,23 @@ +ps.1.1 + +def c0, 1.0f, 0.0f, 0.0f, 0.0f +def c1, 0.0f, 1.0f, 0.0f, 0.0f +def c2, 0.0f, 0.0f, 1.0f, 0.0f + +tex t0 ; basetexture zy +tex t1 ; basetexture xz +tex t2 ; basetexture xy +tex t3 ; lightmap + +dp3_sat r1, v0, c0 +mul r0, t0, r1 + +dp3_sat r1, v0, c1 +mad r0, t1, r1, r0 + +dp3_sat r1, v0, c2 +mad r0, t2, r1, r0 + +; multiply by lightmap +mul_x2 r0.rgb, r0, t3 ++mov r0.a, v0 ; $vColor diff --git a/materialsystem/stdshaders/WorldVertexTransition_Seamless.vsh b/materialsystem/stdshaders/WorldVertexTransition_Seamless.vsh new file mode 100644 index 0000000..dd0cc99 --- /dev/null +++ b/materialsystem/stdshaders/WorldVertexTransition_Seamless.vsh @@ -0,0 +1,54 @@ +vs.1.1 + +# DYNAMIC: "DOWATERFOG" "0..1" + +#include "macros.vsh" + +local( $worldPos, $worldNormal, $projPos, $reflectionVector ); + +alloc $projPos + +dp4 $projPos.x, $vPos, $cModelViewProj0 +dp4 $projPos.y, $vPos, $cModelViewProj1 +dp4 $projPos.z, $vPos, $cModelViewProj2 +dp4 $projPos.w, $vPos, $cModelViewProj3 +mov oPos, $projPos + +alloc $worldPos +alloc $worldNormal + +dp4 $worldPos.x, $vPos, $cModel0 +dp4 $worldPos.y, $vPos, $cModel1 +dp4 $worldPos.z, $vPos, $cModel2 + +dp3 $worldNormal.x, $vNormal, $cModel0 +dp3 $worldNormal.y, $vNormal, $cModel1 +dp3 $worldNormal.z, $vNormal, $cModel2 + +&CalcFog( $worldPos, $projPos ); + +free $projPos + +;------------------------------------------------------------------------------ +; Texture coordinates +;------------------------------------------------------------------------------ +; base texcoords +alloc $texcoord +mul $texcoord.xyz, $worldPos, $SHADER_SPECIFIC_CONST_0 + +mov oT0.xy, $texcoord.zy; +mov oT1.xy, $texcoord.xz; +mov oT2.xy, $texcoord.xy; + +free $texcoord + +; lightmap texcoords +mov oT3, $vTexCoord1 + +mul oD0.rgb, $worldNormal, $worldNormal + +; Now the basetexture/basetexture2 blend uses vertex color, so send it into the psh. +mov oD0.a, $vColor + +free $worldPos +free $worldNormal diff --git a/materialsystem/stdshaders/WorldVertexTransition_dx8.cpp b/materialsystem/stdshaders/WorldVertexTransition_dx8.cpp new file mode 100644 index 0000000..331f8f1 --- /dev/null +++ b/materialsystem/stdshaders/WorldVertexTransition_dx8.cpp @@ -0,0 +1,537 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $Header: $ +// $NoKeywords: $ +//===========================================================================// + +#include "BaseVSShader.h" +#include "convar.h" + +#include "worldvertextransition.inc" +#include "worldvertextransition_vs14.inc" +#include "worldvertextransition_seamless.inc" +#include "lightmappedgeneric_vs11.inc" +#include "writevertexalphatodestalpha_vs11.inc" +#include "worldvertextransition_dx8_helper.h" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +DEFINE_FALLBACK_SHADER( WorldVertexTransition, WorldVertexTransition_DX8 ) + +ConVar mat_fullbright( "mat_fullbright","0", FCVAR_CHEAT ); + +BEGIN_VS_SHADER( WorldVertexTransition_DX8, + "Help for WorldVertexTransition_DX8" ) + + BEGIN_SHADER_PARAMS + SHADER_PARAM( BASETEXTURE2, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture2", "base texture2 help" ) + SHADER_PARAM( FRAME2, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $baseTexture" ) + SHADER_PARAM( BASETEXTURETRANSFORM2, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$baseTexture texcoord transform" ) + SHADER_PARAM( SELFILLUMTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "Self-illumination tint" ) + SHADER_PARAM( DETAIL, SHADER_PARAM_TYPE_TEXTURE, "shadertest/detail", "detail texture" ) + SHADER_PARAM( DETAILFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $detail" ) + SHADER_PARAM( DETAILSCALE, SHADER_PARAM_TYPE_FLOAT, "4", "scale of the detail texture" ) + SHADER_PARAM( ENVMAP, SHADER_PARAM_TYPE_TEXTURE, "shadertest/shadertest_env", "envmap" ) + SHADER_PARAM( ENVMAPFRAME, SHADER_PARAM_TYPE_INTEGER, "", "" ) + SHADER_PARAM( ENVMAPMASK, SHADER_PARAM_TYPE_TEXTURE, "shadertest/shadertest_envmask", "envmap mask" ) + SHADER_PARAM( ENVMAPMASKFRAME, SHADER_PARAM_TYPE_INTEGER, "", "" ) + SHADER_PARAM( ENVMAPMASKSCALE, SHADER_PARAM_TYPE_FLOAT, "1", "envmap mask scale" ) + SHADER_PARAM( ENVMAPTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "envmap tint" ) + SHADER_PARAM( BUMPMAP, SHADER_PARAM_TYPE_TEXTURE, "models/shadertest/shader1_normal", "bump map for BASETEXTURE" ) + SHADER_PARAM( BUMPFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $bumpmap" ) + SHADER_PARAM( BUMPTRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$bumpmap texcoord transform" ) + SHADER_PARAM( ENVMAPCONTRAST, SHADER_PARAM_TYPE_FLOAT, "0.0", "contrast 0 == normal 1 == color*color" ) + SHADER_PARAM( ENVMAPSATURATION, SHADER_PARAM_TYPE_FLOAT, "1.0", "saturation 0 == greyscale 1 == normal" ) + SHADER_PARAM( BUMPBASETEXTURE2WITHBUMPMAP, SHADER_PARAM_TYPE_BOOL, "0", "" ) + SHADER_PARAM( FRESNELREFLECTION, SHADER_PARAM_TYPE_FLOAT, "0.0", "1.0 == mirror, 0.0 == water" ) + SHADER_PARAM( SSBUMP, SHADER_PARAM_TYPE_INTEGER, "0", "whether or not to use alternate bumpmap format with height" ) + SHADER_PARAM( SEAMLESS_SCALE, SHADER_PARAM_TYPE_FLOAT, "0", "Scale factor for 'seamless' texture mapping. 0 means to use ordinary mapping" ) + SHADER_PARAM( BLENDMODULATETEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "texture to use r/g channels for blend range for" ) + SHADER_PARAM( BLENDMASKTRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$blendmodulatetexture texcoord transform" ) + END_SHADER_PARAMS + + SHADER_FALLBACK + { + if ( IsPC() && g_pHardwareConfig->GetDXSupportLevel() < 80 ) + return "WorldVertexTransition_DX6"; + return 0; + } + + void SetupVars( WorldVertexTransitionEditor_DX8_Vars_t& info ) + { + info.m_nBaseTextureVar = BASETEXTURE; + info.m_nBaseTextureFrameVar = FRAME; + info.m_nBaseTextureTransformVar = BASETEXTURETRANSFORM; + info.m_nBaseTexture2Var = BASETEXTURE2; + info.m_nBaseTexture2FrameVar = FRAME2; + info.m_nBaseTexture2TransformVar = BASETEXTURETRANSFORM2; + } + + SHADER_INIT_PARAMS() + { + // Initializes FLASHLIGHTTEXTURE + MATERIAL_VAR2_LIGHTING_LIGHTMAP + WorldVertexTransitionEditor_DX8_Vars_t info; + SetupVars( info ); + InitParamsWorldVertexTransitionEditor_DX8( params, info ); + + // FLASHLIGHTFIXME + params[FLASHLIGHTTEXTURE]->SetStringValue( "effects/flashlight001" ); + + if( IsUsingGraphics() && params[ENVMAP]->IsDefined() && !CanUseEditorMaterials() ) + { + if( stricmp( params[ENVMAP]->GetStringValue(), "env_cubemap" ) == 0 ) + { + Warning( "env_cubemap used on world geometry without rebuilding map. . ignoring: %s\n", pMaterialName ); + params[ENVMAP]->SetUndefined(); + } + } + + if( !params[ENVMAPMASKSCALE]->IsDefined() ) + { + params[ENVMAPMASKSCALE]->SetFloatValue( 1.0f ); + } + + if( !params[ENVMAPTINT]->IsDefined() ) + { + params[ENVMAPTINT]->SetVecValue( 1.0f, 1.0f, 1.0f ); + } + + if( !params[SELFILLUMTINT]->IsDefined() ) + { + params[SELFILLUMTINT]->SetVecValue( 1.0f, 1.0f, 1.0f ); + } + + if( !params[DETAILSCALE]->IsDefined() ) + { + params[DETAILSCALE]->SetFloatValue( 4.0f ); + } + + if( !params[FRESNELREFLECTION]->IsDefined() ) + { + params[FRESNELREFLECTION]->SetFloatValue( 1.0f ); + } + + if( !params[ENVMAPMASKFRAME]->IsDefined() ) + { + params[ENVMAPMASKFRAME]->SetIntValue( 0 ); + } + + if( !params[ENVMAPFRAME]->IsDefined() ) + { + params[ENVMAPFRAME]->SetIntValue( 0 ); + } + + if( !params[BUMPFRAME]->IsDefined() ) + { + params[BUMPFRAME]->SetIntValue( 0 ); + } + + if( !params[ENVMAPCONTRAST]->IsDefined() ) + { + params[ENVMAPCONTRAST]->SetFloatValue( 0.0f ); + } + + if( !params[ENVMAPSATURATION]->IsDefined() ) + { + params[ENVMAPSATURATION]->SetFloatValue( 1.0f ); + } + + // No texture means no self-illum or env mask in base alpha + if ( !params[BASETEXTURE]->IsDefined() ) + { + CLEAR_FLAGS( MATERIAL_VAR_SELFILLUM ); + CLEAR_FLAGS( MATERIAL_VAR_BASEALPHAENVMAPMASK ); + } + + // If in decal mode, no debug override... + if (IS_FLAG_SET(MATERIAL_VAR_DECAL)) + { + SET_FLAGS( MATERIAL_VAR_NO_DEBUG_OVERRIDE ); + } + + SET_FLAGS2( MATERIAL_VAR2_LIGHTING_LIGHTMAP ); + if( g_pConfig->UseBumpmapping() && params[BUMPMAP]->IsDefined() ) + { + SET_FLAGS2( MATERIAL_VAR2_LIGHTING_BUMPED_LIGHTMAP ); + } + + if( !params[BUMPBASETEXTURE2WITHBUMPMAP]->IsDefined() ) + { + params[BUMPBASETEXTURE2WITHBUMPMAP]->SetIntValue( 0 ); + } + + if( !params[DETAILSCALE]->IsDefined() ) + { + params[DETAILSCALE]->SetFloatValue( 4.0f ); + } + + if( !params[DETAILFRAME]->IsDefined() ) + { + params[DETAILFRAME]->SetIntValue( 0 ); + } + + if( params[SEAMLESS_SCALE]->IsDefined() && params[SEAMLESS_SCALE]->GetFloatValue() != 0.0f ) + { + // seamless scale is going to be used, so kill some other features. . might implement with these features later. + params[DETAIL]->SetUndefined(); + params[BUMPMAP]->SetUndefined(); + params[ENVMAP]->SetUndefined(); + } + + if ( !params[SEAMLESS_SCALE]->IsDefined() ) + { + // zero means don't do seamless mapping. + params[SEAMLESS_SCALE]->SetFloatValue( 0.0f ); + } + + if( params[SSBUMP]->IsDefined() && params[SSBUMP]->GetIntValue() != 0 ) + { + // turn of normal mapping since we have ssbump defined, which + // means that we didn't make a dx8 fallback for this material. + params[BUMPMAP]->SetUndefined(); + } + } + SHADER_INIT + { + // Loads BASETEXTURE, BASETEXTURE2 + WorldVertexTransitionEditor_DX8_Vars_t info; + SetupVars( info ); + InitWorldVertexTransitionEditor_DX8( this, params, info ); + + // FLASHLIGHTFIXME + if ( params[FLASHLIGHTTEXTURE]->IsDefined() ) + { + LoadTexture( FLASHLIGHTTEXTURE ); + } + + if (params[DETAIL]->IsDefined()) + { + LoadTexture( DETAIL ); + } + + if ( g_pHardwareConfig->SupportsPixelShaders_1_4() && params[BLENDMODULATETEXTURE]->IsDefined() ) + { + LoadTexture( BLENDMODULATETEXTURE ); + } + + SET_FLAGS2( MATERIAL_VAR2_LIGHTING_LIGHTMAP ); + if( params[ENVMAP]->IsDefined() && !params[BUMPMAP]->IsDefined() ) + { + Warning( "must have $bumpmap if you have $envmap for worldvertextransition\n" ); + params[ENVMAP]->SetUndefined(); + params[BUMPMAP]->SetUndefined(); + } + if( g_pConfig->UseBumpmapping() && params[BUMPMAP]->IsDefined() ) + { + SET_FLAGS2( MATERIAL_VAR2_NEEDS_TANGENT_SPACES ); + SET_FLAGS2( MATERIAL_VAR2_LIGHTING_BUMPED_LIGHTMAP ); + LoadBumpMap( BUMPMAP ); + } + if( params[ENVMAP]->IsDefined() ) + { + if( !IS_FLAG_SET( MATERIAL_VAR_ENVMAPSPHERE ) ) + { + LoadCubeMap( ENVMAP ); + } + else + { + Warning( "$envmapsphere not supported by worldvertextransition\n" ); + params[ENVMAP]->SetUndefined(); + } + } + } + + void WriteVertexAlphaToDestAlpha( IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow ) + { + if( pShaderShadow ) + { + pShaderShadow->EnableDepthWrites( false ); + pShaderShadow->EnableAlphaWrites( true ); + pShaderShadow->EnableColorWrites( false ); + + writevertexalphatodestalpha_vs11_Static_Index vshIndex; + pShaderShadow->SetVertexShader( "writevertexalphatodestalpha_vs11", vshIndex.GetIndex() ); + + pShaderShadow->SetPixelShader( "writevertexalphatodestalpha_ps11" ); + pShaderShadow->VertexShaderVertexFormat( + VERTEX_POSITION | VERTEX_COLOR, 2, 0, 0 ); + } + else + { + writevertexalphatodestalpha_vs11_Dynamic_Index vshIndex; + pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() ); + } + Draw(); + } + + void DrawFlashlightPass( IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow, int passID ) + { + bool bBump = ( passID == 0 ) && ShouldUseBumpmapping( params ) && params[BUMPMAP]->IsTexture(); + DrawFlashlight_dx80( params, pShaderAPI, pShaderShadow, bBump, BUMPMAP, BUMPFRAME, BUMPTRANSFORM, + FLASHLIGHTTEXTURE, FLASHLIGHTTEXTUREFRAME, true, true, passID, BASETEXTURE2, FRAME2 ); + } + + bool ShouldUseBumpmapping( IMaterialVar **params ) + { + return g_pConfig->UseBumpmapping() && params[BUMPMAP]->IsDefined(); + } + + void DrawFlashlight( IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow ) + { + WriteVertexAlphaToDestAlpha( params, pShaderAPI, pShaderShadow ); + DrawFlashlightPass( params, pShaderAPI, pShaderShadow, 0 ); + DrawFlashlightPass( params, pShaderAPI, pShaderShadow, 1 ); + } + + SHADER_DRAW + { + bool bLightingOnly = mat_fullbright.GetInt() == 2 && !IS_FLAG_SET( MATERIAL_VAR_NO_DEBUG_OVERRIDE ); + bool bSupports14 = g_pHardwareConfig->SupportsPixelShaders_1_4(); + + // FLASHLIGHTFIXME: need to make these the same. + bool hasFlashlight = UsingFlashlight( params ); + if( hasFlashlight ) + { + DrawFlashlight( params, pShaderAPI, pShaderShadow ); + } + else if ( params[SEAMLESS_SCALE]->GetFloatValue() != 0.0f ) + { + // This is the seamless_scale version, which doesn't use $detail or $bumpmap + SHADOW_STATE + { + // three copies of the base texture for seamless blending + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER2, true ); + + // lightmap + pShaderShadow->EnableTexture( SHADER_SAMPLER3, true ); + + int fmt = VERTEX_POSITION; + pShaderShadow->VertexShaderVertexFormat( fmt, 2, 0, 0 ); + + worldvertextransition_seamless_Static_Index vshIndex; + pShaderShadow->SetVertexShader( "WorldVertexTransition_Seamless", vshIndex.GetIndex() ); + + int pshIndex = 0; + pShaderShadow->SetPixelShader( "WorldVertexTransition_Seamless", pshIndex ); + + FogToFogColor(); + } + DYNAMIC_STATE + { + // Texture 0..2 + if( bLightingOnly ) + { + pShaderAPI->BindStandardTexture( SHADER_SAMPLER0, TEXTURE_GREY ); + pShaderAPI->BindStandardTexture( SHADER_SAMPLER1, TEXTURE_GREY ); + pShaderAPI->BindStandardTexture( SHADER_SAMPLER2, TEXTURE_GREY ); + } + else + { + BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME ); + BindTexture( SHADER_SAMPLER1, BASETEXTURE, FRAME ); + BindTexture( SHADER_SAMPLER2, BASETEXTURE, FRAME ); + } + + // Texture 3 = lightmap + pShaderAPI->BindStandardTexture( SHADER_SAMPLER3, TEXTURE_LIGHTMAP ); + + EnablePixelShaderOverbright( 0, true, true ); + + float fSeamlessScale = params[SEAMLESS_SCALE]->GetFloatValue(); + float map_scale[4]= { fSeamlessScale, fSeamlessScale, fSeamlessScale, fSeamlessScale }; + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, map_scale ); + + worldvertextransition_seamless_Dynamic_Index vshIndex; + vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() ); + } + Draw(); + SHADOW_STATE + { + // inherit state from previous pass + + EnableAlphaBlending( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA ); + } + DYNAMIC_STATE + { + if( !bLightingOnly ) + { + BindTexture( SHADER_SAMPLER0, BASETEXTURE2, FRAME2 ); + BindTexture( SHADER_SAMPLER1, BASETEXTURE2, FRAME2 ); + BindTexture( SHADER_SAMPLER2, BASETEXTURE2, FRAME2 ); + } + } + Draw(); + } + else if( !params[BUMPMAP]->IsTexture() || !g_pConfig->UseBumpmapping() ) + { + bool bDetail = params[DETAIL]->IsTexture(); + bool bBlendModulate = params[BLENDMODULATETEXTURE]->IsTexture(); + SHADOW_STATE + { + // This is the dx8, non-worldcraft version, non-bumped version + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER2, true ); + if( bDetail ) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER3, true ); + } + if ( bSupports14 && bBlendModulate ) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER4, true ); + } + + int fmt = VERTEX_POSITION | VERTEX_COLOR; + pShaderShadow->VertexShaderVertexFormat( fmt, 2, 0, 0 ); + + if ( !bSupports14 ) + { + worldvertextransition_Static_Index vshIndex; + pShaderShadow->SetVertexShader( "WorldVertexTransition", vshIndex.GetIndex() ); + + int pshIndex = bDetail ? 1 : 0; + pShaderShadow->SetPixelShader( "WorldVertexTransition", pshIndex ); + } + else + { + worldvertextransition_vs14_Static_Index vshIndex; + pShaderShadow->SetVertexShader( "WorldVertexTransition_vs14", vshIndex.GetIndex() ); + + int pshIndex = bDetail ? 1 : 0; + pshIndex += bBlendModulate ? 2 : 0; + pShaderShadow->SetPixelShader( "WorldVertexTransition_ps14", pshIndex ); + } + + FogToFogColor(); + } + + DYNAMIC_STATE + { + // Texture 1 + if( bLightingOnly ) + { + pShaderAPI->BindStandardTexture( SHADER_SAMPLER0, TEXTURE_GREY ); + pShaderAPI->BindStandardTexture( SHADER_SAMPLER1, TEXTURE_GREY ); + } + else + { + BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME ); + BindTexture( SHADER_SAMPLER1, BASETEXTURE2, FRAME2 ); + } + if( bDetail ) + { + BindTexture( SHADER_SAMPLER3, DETAIL, DETAILFRAME ); + } + if ( bSupports14 && bBlendModulate ) + { + BindTexture( SHADER_SAMPLER4, BLENDMODULATETEXTURE ); + } + + // always set the transform for detail textures since I'm assuming that you'll + // always have a detailscale. + // go ahead and set this even if we don't have a detail texture so the vertex shader doesn't + // barf chunks with unitialized data. + SetVertexShaderTextureScaledTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_4, BASETEXTURETRANSFORM, DETAILSCALE ); + + if ( bSupports14 ) + { + SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_6, BLENDMASKTRANSFORM ); + } + + // Texture 3 = lightmap + pShaderAPI->BindStandardTexture( SHADER_SAMPLER2, TEXTURE_LIGHTMAP ); + + EnablePixelShaderOverbright( 0, true, true ); + + SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, BASETEXTURETRANSFORM ); + SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_2, BASETEXTURETRANSFORM2 ); + if ( !bSupports14 ) + { + worldvertextransition_Dynamic_Index vshIndex; + vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() ); + } + else + { + worldvertextransition_vs14_Dynamic_Index vshIndex; + vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() ); + } + } + Draw(); + } + else + { + if( params[BUMPBASETEXTURE2WITHBUMPMAP]->GetIntValue() ) + { + DrawWorldBumpedUsingVertexShader( BASETEXTURE, BASETEXTURETRANSFORM, + BUMPMAP, BUMPFRAME, BUMPTRANSFORM, ENVMAPMASK, ENVMAPMASKFRAME, ENVMAP, + ENVMAPFRAME, ENVMAPTINT, COLOR, ALPHA, ENVMAPCONTRAST, ENVMAPSATURATION, FRAME, + FRESNELREFLECTION, true, BASETEXTURE2, BASETEXTURETRANSFORM2, FRAME2, false ); + } + else + { + // draw the base texture with everything else you normally would for + // bumped world materials + DrawWorldBumpedUsingVertexShader( + BASETEXTURE, BASETEXTURETRANSFORM, + BUMPMAP, BUMPFRAME, BUMPTRANSFORM, + ENVMAPMASK, ENVMAPMASKFRAME, ENVMAP, ENVMAPFRAME, ENVMAPTINT, + COLOR, ALPHA, ENVMAPCONTRAST, ENVMAPSATURATION, FRAME, + FRESNELREFLECTION, + false, -1, -1, -1, false ); + + // blend basetexture 2 on top of everything using lightmap alpha. + SHADOW_STATE + { + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + pShaderShadow->VertexShaderVertexFormat( + VERTEX_POSITION | VERTEX_COLOR, 2, 0, 0 ); + pShaderShadow->EnableBlending( true ); + pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA ); + + lightmappedgeneric_vs11_Static_Index vshIndex; + vshIndex.SetDETAIL( false ); + vshIndex.SetENVMAP( false ); + vshIndex.SetENVMAPCAMERASPACE( false ); + vshIndex.SetENVMAPSPHERE( false ); + vshIndex.SetVERTEXCOLOR( true ); + pShaderShadow->SetVertexShader( "LightmappedGeneric_vs11", vshIndex.GetIndex() ); + + pShaderShadow->SetPixelShader( "WorldVertexTransition_BlendBase2" ); + FogToFogColor(); + } + DYNAMIC_STATE + { + if( bLightingOnly ) + { + pShaderAPI->BindStandardTexture( SHADER_SAMPLER0, TEXTURE_GREY ); + } + else + { + BindTexture( SHADER_SAMPLER0, BASETEXTURE2, FRAME2 ); + } + pShaderAPI->BindStandardTexture( SHADER_SAMPLER1, TEXTURE_LIGHTMAP ); + + float half[4] = { 0.5f, 0.5f, 0.5f, 0.5f }; + pShaderAPI->SetPixelShaderConstant( 4, half ); + EnablePixelShaderOverbright( 0, true, true ); + SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, BASETEXTURETRANSFORM2 ); + + lightmappedgeneric_vs11_Dynamic_Index vshIndex; + vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() ); + } + Draw(); + } + } + } +END_SHADER + diff --git a/materialsystem/stdshaders/WorldVertexTransition_ps14.psh b/materialsystem/stdshaders/WorldVertexTransition_ps14.psh new file mode 100644 index 0000000..3ddfa02 --- /dev/null +++ b/materialsystem/stdshaders/WorldVertexTransition_ps14.psh @@ -0,0 +1,32 @@ +; STATIC: "DETAIL" "0..1" +; STATIC: "BLENDMODULATETEXTURE" "0..1" +ps.1.4 + +def c1, 3.0, -2.0, 0.5, 0.5 + +texld r0, t0 +texld r1, t1 +texld r2, t2 +#if DETAIL +texld r3, t3 ; detail +#endif +#if BLENDMODULATETEXTURE +texld r4, t4 ; detail +#endif + +#if BLEND_MODULATETEXTURE +sub r5.a, v0.a, r4.g +add_sat r5.a, r5.a, c1.a +mad r6.a, c1.g, r5.a, c1.r +mul r6.a, r6.a, r5.a +mul r5.a, r6.a, r5.a +#else +mov_sat r5.a, v0.a +#endif +lrp r0, r5.a, r1, r0 + +mul r0, r0, r2 +#if DETAIL +mul_x2 r0.rgb, r0, r3 +#endif +mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2) diff --git a/materialsystem/stdshaders/WorldVertexTransition_ps2x.fxc b/materialsystem/stdshaders/WorldVertexTransition_ps2x.fxc new file mode 100644 index 0000000..f27e870 --- /dev/null +++ b/materialsystem/stdshaders/WorldVertexTransition_ps2x.fxc @@ -0,0 +1,47 @@ +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX] +// STATIC: "MACROS" "0..1" + +#define HDRTYPE HDR_TYPE_NONE +#include "common_ps_fxc.h" + + +sampler BaseSampler : register( s0 ); +// NOTE: LightmapSampler is at the same place as the lightmap sampler in lightmappedgeneric so that we have +// generally the same texture state here. +// CENTROID: TEXCOORD1 +sampler LightmapSampler: register( s1 ); +sampler BaseSampler2: register( s2 ); +sampler LightmapAlphaSampler: register( s3 ); +sampler MacrosSampler: register( s4 ); + +struct PS_INPUT +{ + float2 baseCoord : TEXCOORD0; + float2 baseCoord2 : TEXCOORD1; + float2 lightmapCoord : TEXCOORD2; + float2 macrosCoord : TEXCOORD3; +}; + +float4 main( PS_INPUT i ) : COLOR +{ + bool bMacros = MACROS ? true : false; + + float4 base = tex2D( BaseSampler, i.baseCoord ); + float4 base2 = tex2D( BaseSampler2, i.baseCoord2 ); + + float4 lightmap = tex2D( LightmapSampler, i.lightmapCoord ); + float blendFactor = lightmap.a; + + float4 color = 2.0f * lightmap * lerp( base2, base, blendFactor ); + if( bMacros ) + { + float4 macros = tex2D( MacrosSampler, i.macrosCoord ); + + // Not sure what to do with macro alpha + color.rgb *= 2.0f * lerp( macros.a, macros.b, blendFactor ); + } + + return FinalOutput( color, 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE ); +} + diff --git a/materialsystem/stdshaders/WorldVertexTransition_vs14.vsh b/materialsystem/stdshaders/WorldVertexTransition_vs14.vsh new file mode 100644 index 0000000..eecc1c8 --- /dev/null +++ b/materialsystem/stdshaders/WorldVertexTransition_vs14.vsh @@ -0,0 +1,52 @@ +vs.1.1 + +# DYNAMIC: "DOWATERFOG" "0..1" + +#include "macros.vsh" + +local( $worldPos, $worldNormal, $projPos, $reflectionVector ); + +&AllocateRegister( \$projPos ); + +dp4 $projPos.x, $vPos, $cModelViewProj0 +dp4 $projPos.y, $vPos, $cModelViewProj1 +dp4 $projPos.z, $vPos, $cModelViewProj2 +dp4 $projPos.w, $vPos, $cModelViewProj3 +mov oPos, $projPos + +&AllocateRegister( \$worldPos ); + +; garymcthack +dp4 $worldPos.z, $vPos, $cModel2 + +&CalcFog( $worldPos, $projPos ); + +&FreeRegister( \$worldPos ); +&FreeRegister( \$projPos ); + +;------------------------------------------------------------------------------ +; Texture coordinates +;------------------------------------------------------------------------------ +; base texcoords +dp4 oT0.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_0 +dp4 oT0.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_1 + +dp4 oT1.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_2 +dp4 oT1.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_3 + +; lightmap texcoords +mov oT2, $vTexCoord1 + +; detail +dp4 oT3.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_4 +dp4 oT3.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_5 + +; mask +dp4 oT4.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_6 +dp4 oT4.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_7 + +; Now the basetexture/basetexture2 blend uses vertex color, so send it into the psh. +mov oD0, $vColor + +&FreeRegister( \$worldPos ); # garymcthack + diff --git a/materialsystem/stdshaders/WorldVertexTransition_vs20.fxc b/materialsystem/stdshaders/WorldVertexTransition_vs20.fxc new file mode 100644 index 0000000..5f18ca8 --- /dev/null +++ b/materialsystem/stdshaders/WorldVertexTransition_vs20.fxc @@ -0,0 +1,64 @@ +// DYNAMIC: "DOWATERFOG" "0..1" + +#include "common_vs_fxc.h" + +static const int g_FogType = DOWATERFOG; + +const float4 cBaseTexCoordTransform[2] : register( SHADER_SPECIFIC_CONST_0 ); +const float4 cBaseTexCoordTransform2[2] : register( SHADER_SPECIFIC_CONST_2 ); +const float4 cMacrosTexCoordTransform[2] : register( SHADER_SPECIFIC_CONST_4 ); + +struct VS_INPUT +{ + // This is all of the stuff that we ever use. + float4 vPos : POSITION; + float4 vColor : COLOR0; + float4 vTexCoord0 : TEXCOORD0; + float4 vTexCoord1 : TEXCOORD1; +}; + +struct VS_OUTPUT +{ + float4 projPos : POSITION; +#if !defined( _X360 ) + float fog : FOG; +#endif + float2 baseCoord : TEXCOORD0; + float2 baseCoord2 : TEXCOORD1; + float2 lightmapCoord : TEXCOORD2; + float2 macrosCoord : TEXCOORD3; + float4 color : COLOR0; + float4 fogFactorW : COLOR1; +}; + +VS_OUTPUT main( const VS_INPUT v ) +{ + VS_OUTPUT o = ( VS_OUTPUT )0; + + float3 worldNormal, worldPos; + float2 texCoord; + worldPos = mul( v.vPos, cModel[0] ); + float4 vProjPos = mul( float4( worldPos, 1 ), cViewProj ); + o.projPos = projPos; + vProjPos.z = dot( float4( worldPos, 1 ), cViewProjZ ); + o.fogFactorW = CalcFog( worldPos, vProjPos, g_FogType ); +#if !defined( _X360 ) + o.fog = o.fogFactorW; +#endif + o.color = v.vColor; + + o.baseCoord.x = dot( v.vTexCoord0, cBaseTexCoordTransform[0] ); + o.baseCoord.y = dot( v.vTexCoord0, cBaseTexCoordTransform[1] ); + + o.baseCoord2.x = dot( v.vTexCoord0, cBaseTexCoordTransform2[0] ); + o.baseCoord2.y = dot( v.vTexCoord0, cBaseTexCoordTransform2[1] ); + + o.lightmapCoord = v.vTexCoord1; + + o.macrosCoord.x = dot( v.vTexCoord0, cMacrosTexCoordTransform[0] ); + o.macrosCoord.y = dot( v.vTexCoord0, cMacrosTexCoordTransform[1] ); + + return o; +} + + diff --git a/materialsystem/stdshaders/accumbuff5sample.cpp b/materialsystem/stdshaders/accumbuff5sample.cpp new file mode 100644 index 0000000..1d12dfd --- /dev/null +++ b/materialsystem/stdshaders/accumbuff5sample.cpp @@ -0,0 +1,110 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//============================================================================= + +#include "BaseVSShader.h" +#include "common_hlsl_cpp_consts.h" +#include "screenspaceeffect_vs20.inc" +#include "accumbuff5sample_ps20.inc" +#include "accumbuff5sample_ps20b.inc" +#include "convar.h" + +BEGIN_VS_SHADER_FLAGS( accumbuff5sample, "Help for AccumBuff5Sample", SHADER_NOT_EDITABLE ) + BEGIN_SHADER_PARAMS + + // Four textures to sample + SHADER_PARAM( TEXTURE0, SHADER_PARAM_TYPE_TEXTURE, "", "" ) + SHADER_PARAM( TEXTURE1, SHADER_PARAM_TYPE_TEXTURE, "", "" ) + SHADER_PARAM( TEXTURE2, SHADER_PARAM_TYPE_TEXTURE, "", "" ) + SHADER_PARAM( TEXTURE3, SHADER_PARAM_TYPE_TEXTURE, "", "" ) + SHADER_PARAM( TEXTURE4, SHADER_PARAM_TYPE_TEXTURE, "", "" ) + + // Corresponding weights for the four input textures + SHADER_PARAM( WEIGHTS, SHADER_PARAM_TYPE_VEC4, "", "Weight for Samples" ) + + END_SHADER_PARAMS + + SHADER_INIT + { + LoadTexture( TEXTURE0 ); + LoadTexture( TEXTURE1 ); + LoadTexture( TEXTURE2 ); + LoadTexture( TEXTURE3 ); + LoadTexture( TEXTURE4 ); + } + + SHADER_FALLBACK + { + // Requires DX9 + above + if (!g_pHardwareConfig->SupportsVertexAndPixelShaders()) + { + Assert( 0 ); + return "Wireframe"; + } + return 0; + } + + SHADER_DRAW + { + SHADOW_STATE + { + pShaderShadow->EnableDepthWrites( false ); + pShaderShadow->EnableDepthTest( false ); + pShaderShadow->EnableAlphaWrites( false ); + pShaderShadow->EnableBlending( false ); + pShaderShadow->EnableCulling( false ); +// pShaderShadow->PolyMode( SHADER_POLYMODEFACE_FRONT_AND_BACK, SHADER_POLYMODE_LINE ); + + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER2, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER3, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER4, true ); + int fmt = VERTEX_POSITION; + pShaderShadow->VertexShaderVertexFormat( fmt, 1, 0, 0 ); + + DECLARE_STATIC_VERTEX_SHADER( screenspaceeffect_vs20 ); + SET_STATIC_VERTEX_SHADER( screenspaceeffect_vs20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_STATIC_PIXEL_SHADER( accumbuff5sample_ps20b ); + SET_STATIC_PIXEL_SHADER( accumbuff5sample_ps20b ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( accumbuff5sample_ps20 ); + SET_STATIC_PIXEL_SHADER( accumbuff5sample_ps20 ); + } + } + + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER0, TEXTURE0, -1 ); + BindTexture( SHADER_SAMPLER1, TEXTURE1, -1 ); + BindTexture( SHADER_SAMPLER2, TEXTURE2, -1 ); + BindTexture( SHADER_SAMPLER3, TEXTURE3, -1 ); + BindTexture( SHADER_SAMPLER4, TEXTURE4, -1 ); + + SetPixelShaderConstant( 0, WEIGHTS ); + + DECLARE_DYNAMIC_VERTEX_SHADER( screenspaceeffect_vs20 ); + SET_DYNAMIC_VERTEX_SHADER( screenspaceeffect_vs20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_DYNAMIC_PIXEL_SHADER( accumbuff5sample_ps20b ); + SET_DYNAMIC_PIXEL_SHADER( accumbuff5sample_ps20b ); + } + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( accumbuff5sample_ps20 ); + SET_DYNAMIC_PIXEL_SHADER( accumbuff5sample_ps20 ); + } + } + Draw(); + } +END_SHADER diff --git a/materialsystem/stdshaders/accumbuff5sample_ps2x.fxc b/materialsystem/stdshaders/accumbuff5sample_ps2x.fxc new file mode 100644 index 0000000..231ac8e --- /dev/null +++ b/materialsystem/stdshaders/accumbuff5sample_ps2x.fxc @@ -0,0 +1,35 @@ +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX] + +#define HDRTYPE HDR_TYPE_NONE +#include "common_ps_fxc.h" + +sampler TexSampler0 : register( s0 ); +sampler TexSampler1 : register( s1 ); +sampler TexSampler2 : register( s2 ); +sampler TexSampler3 : register( s3 ); +sampler TexSampler4 : register( s4 ); + +struct PS_INPUT +{ + float2 texCoord : TEXCOORD0; +}; + +const float4 weights : register( c0 ); + +float4 main( PS_INPUT i ) : COLOR +{ + // Just sample the four input textures + float4 sample0 = tex2D( TexSampler0, i.texCoord ); + float4 sample1 = tex2D( TexSampler1, i.texCoord ); + float4 sample2 = tex2D( TexSampler2, i.texCoord ); + float4 sample3 = tex2D( TexSampler3, i.texCoord ); + float4 sample4 = tex2D( TexSampler4, i.texCoord ); + + // Compute weighted average and return + return FinalOutput( weights.x * sample0 + + weights.x * sample1 + + weights.x * sample2 + + weights.x * sample3 + + weights.y * sample4, 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE ); +} diff --git a/materialsystem/stdshaders/aftershock.cpp b/materialsystem/stdshaders/aftershock.cpp new file mode 100644 index 0000000..d0c7778 --- /dev/null +++ b/materialsystem/stdshaders/aftershock.cpp @@ -0,0 +1,76 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// + +#include "BaseVSShader.h" +#include "aftershock_helper.h" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +DEFINE_FALLBACK_SHADER( Aftershock, Aftershock_dx9 ) +BEGIN_VS_SHADER( Aftershock_dx9, "Aftershock" ) + BEGIN_SHADER_PARAMS + SHADER_PARAM( COLORTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "Color tint" ) + SHADER_PARAM( REFRACTAMOUNT, SHADER_PARAM_TYPE_FLOAT, "2", "" ) + + SHADER_PARAM( NORMALMAP, SHADER_PARAM_TYPE_TEXTURE, "models/shadertest/shader1_normal", "normal map" ) + SHADER_PARAM( BUMPFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $bumpmap" ) + SHADER_PARAM( BUMPTRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$bumpmap texcoord transform" ) + + SHADER_PARAM( SILHOUETTETHICKNESS, SHADER_PARAM_TYPE_FLOAT, "1", "" ) + SHADER_PARAM( SILHOUETTECOLOR, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "Silhouette color tint" ) + SHADER_PARAM( GROUNDMIN, SHADER_PARAM_TYPE_FLOAT, "1", "" ) + SHADER_PARAM( GROUNDMAX, SHADER_PARAM_TYPE_FLOAT, "1", "" ) + SHADER_PARAM( BLURAMOUNT, SHADER_PARAM_TYPE_FLOAT, "1", "" ) + + SHADER_PARAM( TIME, SHADER_PARAM_TYPE_FLOAT, "0.0", "Needs CurrentTime Proxy" ) + END_SHADER_PARAMS + + void SetupVarsAftershock( AftershockVars_t &info ) + { + info.m_nColorTint = COLORTINT; + info.m_nRefractAmount = REFRACTAMOUNT; + + info.m_nBumpmap = NORMALMAP; + info.m_nBumpFrame = BUMPFRAME; + info.m_nBumpTransform = BUMPTRANSFORM; + + info.m_nSilhouetteThickness = SILHOUETTETHICKNESS; + info.m_nSilhouetteColor = SILHOUETTECOLOR; + info.m_nGroundMin = GROUNDMIN; + info.m_nGroundMax = GROUNDMAX; + info.m_nBlurAmount = BLURAMOUNT; + + info.m_nTime = TIME; + } + + SHADER_INIT_PARAMS() + { + AftershockVars_t info; + SetupVarsAftershock( info ); + InitParamsAftershock( this, params, pMaterialName, info ); + } + + SHADER_FALLBACK + { + if ( g_pHardwareConfig->GetDXSupportLevel() < 90 ) + { + return "Aftershock_dx8"; + } + + return 0; + } + + SHADER_INIT + { + AftershockVars_t info; + SetupVarsAftershock( info ); + InitAftershock( this, params, info ); + } + + SHADER_DRAW + { + AftershockVars_t info; + SetupVarsAftershock( info ); + DrawAftershock( this, params, pShaderAPI, pShaderShadow, info, vertexCompression ); + } +END_SHADER diff --git a/materialsystem/stdshaders/aftershock_helper.cpp b/materialsystem/stdshaders/aftershock_helper.cpp new file mode 100644 index 0000000..cb0c19b --- /dev/null +++ b/materialsystem/stdshaders/aftershock_helper.cpp @@ -0,0 +1,196 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// + +#include "BaseVSShader.h" +#include "mathlib/vmatrix.h" +#include "aftershock_helper.h" +#include "convar.h" + +// Auto generated inc files +#include "aftershock_vs20.inc" +#include "aftershock_ps20.inc" +#include "aftershock_ps20b.inc" + + +void InitParamsAftershock( CBaseVSShader *pShader, IMaterialVar** params, const char *pMaterialName, AftershockVars_t &info ) +{ + // Set material flags + SET_FLAGS2( MATERIAL_VAR2_SUPPORTS_HW_SKINNING ); + SET_FLAGS2( MATERIAL_VAR2_NEEDS_TANGENT_SPACES ); + + SET_FLAGS( MATERIAL_VAR_TRANSLUCENT ); + SET_FLAGS2( MATERIAL_VAR2_NEEDS_POWER_OF_TWO_FRAME_BUFFER_TEXTURE ); + + // Set material parameter default values + if ( ( info.m_nRefractAmount != -1 ) && ( !params[info.m_nRefractAmount]->IsDefined() ) ) + { + params[info.m_nRefractAmount]->SetFloatValue( kDefaultRefractAmount ); + } + + if ( ( info.m_nColorTint != -1 ) && ( !params[info.m_nColorTint]->IsDefined() ) ) + { + params[info.m_nColorTint]->SetVecValue( kDefaultColorTint[0], kDefaultColorTint[1], kDefaultColorTint[2], kDefaultColorTint[3] ); + } + + if( (info.m_nBumpFrame != -1 ) && !params[info.m_nBumpFrame]->IsDefined() ) + { + params[info.m_nBumpFrame]->SetIntValue( 0 ); + } + + if ( ( info.m_nSilhouetteThickness != -1 ) && ( !params[info.m_nSilhouetteThickness]->IsDefined() ) ) + { + params[info.m_nSilhouetteThickness]->SetFloatValue( kDefaultSilhouetteThickness ); + } + + if ( ( info.m_nSilhouetteColor != -1 ) && ( !params[info.m_nSilhouetteColor]->IsDefined() ) ) + { + params[info.m_nSilhouetteColor]->SetVecValue( kDefaultSilhouetteColor[0], kDefaultSilhouetteColor[1], kDefaultSilhouetteColor[2], kDefaultSilhouetteColor[3] ); + } + + if ( ( info.m_nGroundMin != -1 ) && ( !params[info.m_nGroundMin]->IsDefined() ) ) + { + params[info.m_nGroundMin]->SetFloatValue( kDefaultGroundMin ); + } + + if ( ( info.m_nGroundMax != -1 ) && ( !params[info.m_nGroundMax]->IsDefined() ) ) + { + params[info.m_nGroundMax]->SetFloatValue( kDefaultGroundMax ); + } + + if ( ( info.m_nBlurAmount != -1 ) && ( !params[info.m_nBlurAmount]->IsDefined() ) ) + { + params[info.m_nBlurAmount]->SetFloatValue( kDefaultBlurAmount ); + } + + SET_PARAM_FLOAT_IF_NOT_DEFINED( info.m_nTime, 0.0f ); +} + +void InitAftershock( CBaseVSShader *pShader, IMaterialVar** params, AftershockVars_t &info ) +{ + // Load textures + if ( (info.m_nBumpmap != -1) && params[info.m_nBumpmap]->IsDefined() ) + { + pShader->LoadTexture( info.m_nBumpmap ); + } +} + +void DrawAftershock( CBaseVSShader *pShader, IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, + IShaderShadow* pShaderShadow, AftershockVars_t &info, VertexCompressionType_t vertexCompression ) +{ + bool bBumpMapping = ( info.m_nBumpmap == -1 ) || !params[info.m_nBumpmap]->IsTexture() ? 0 : 1; + + SHADOW_STATE + { + // Set stream format (note that this shader supports compression) + unsigned int flags = VERTEX_POSITION | VERTEX_NORMAL | VERTEX_FORMAT_COMPRESSED; + int nTexCoordCount = 1; + int userDataSize = 0; + pShaderShadow->VertexShaderVertexFormat( flags, nTexCoordCount, NULL, userDataSize ); + + // Vertex Shader + DECLARE_STATIC_VERTEX_SHADER( aftershock_vs20 ); + SET_STATIC_VERTEX_SHADER( aftershock_vs20 ); + + // Pixel Shader + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_STATIC_PIXEL_SHADER( aftershock_ps20b ); + SET_STATIC_PIXEL_SHADER( aftershock_ps20b ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( aftershock_ps20 ); + SET_STATIC_PIXEL_SHADER( aftershock_ps20 ); + } + + // Textures + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); // Refraction texture + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); // Bump + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER1, false ); // Not sRGB + pShaderShadow->EnableSRGBWrite( true ); + + // Blending + pShader->EnableAlphaBlending( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA ); + pShaderShadow->EnableAlphaWrites( false ); + + // !!! We need to turn this back on because EnableAlphaBlending() above disables it! + //pShaderShadow->EnableDepthWrites( true ); + } + DYNAMIC_STATE + { + // Set Vertex Shader Combos + DECLARE_DYNAMIC_VERTEX_SHADER( aftershock_vs20 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, pShaderAPI->GetCurrentNumBones() > 0 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression ); + SET_DYNAMIC_VERTEX_SHADER( aftershock_vs20 ); + + // Set Vertex Shader Constants + if ( info.m_nBumpTransform != -1 ) + { + pShader->SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_1, info.m_nBumpTransform ); + } + + // Time % 1000 + float vPackedVsConst1[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; + float flTime = IS_PARAM_DEFINED( info.m_nTime ) && params[info.m_nTime]->GetFloatValue() > 0.0f ? params[info.m_nTime]->GetFloatValue() : pShaderAPI->CurrentTime(); + vPackedVsConst1[0] = flTime; + vPackedVsConst1[0] -= (float)( (int)( vPackedVsConst1[0] / 1000.0f ) ) * 1000.0f; + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, vPackedVsConst1, 1 ); + + // Set Pixel Shader Combos + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_DYNAMIC_PIXEL_SHADER( aftershock_ps20b ); + SET_DYNAMIC_PIXEL_SHADER( aftershock_ps20b ); + } + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( aftershock_ps20 ); + SET_DYNAMIC_PIXEL_SHADER( aftershock_ps20 ); + } + + // Bind textures + pShaderAPI->BindStandardTexture( SHADER_SAMPLER0, TEXTURE_FRAME_BUFFER_FULL_TEXTURE_0 ); // Refraction Map + if ( bBumpMapping ) + { + pShader->BindTexture( SHADER_SAMPLER1, info.m_nBumpmap, info.m_nBumpFrame ); + } + + // Set Pixel Shader Constants + float vEyePos[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; + pShaderAPI->GetWorldSpaceCameraPosition( vEyePos ); + pShaderAPI->SetPixelShaderConstant( 5, vEyePos, 1 ); + + float vPackedConst1[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; + vPackedConst1[0] = IS_PARAM_DEFINED( info.m_nBlurAmount ) ? params[info.m_nBlurAmount]->GetFloatValue() : kDefaultBlurAmount; + vPackedConst1[1] = IS_PARAM_DEFINED( info.m_nRefractAmount ) ? params[info.m_nRefractAmount]->GetFloatValue() : kDefaultRefractAmount; + vPackedConst1[3] = vPackedVsConst1[0]; // Time + pShaderAPI->SetPixelShaderConstant( 6, vPackedConst1, 1 ); + + // Refract color tint + pShaderAPI->SetPixelShaderConstant( 7, IS_PARAM_DEFINED( info.m_nColorTint ) ? params[info.m_nColorTint]->GetVecValue() : kDefaultColorTint, 1 ); + + // Silhouette values + float vPackedConst8[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; + vPackedConst8[0] = IS_PARAM_DEFINED( info.m_nSilhouetteColor ) ? params[info.m_nSilhouetteColor]->GetVecValue()[0] : kDefaultSilhouetteColor[0]; + vPackedConst8[1] = IS_PARAM_DEFINED( info.m_nSilhouetteColor ) ? params[info.m_nSilhouetteColor]->GetVecValue()[1] : kDefaultSilhouetteColor[1]; + vPackedConst8[2] = IS_PARAM_DEFINED( info.m_nSilhouetteColor ) ? params[info.m_nSilhouetteColor]->GetVecValue()[2] : kDefaultSilhouetteColor[2]; + vPackedConst8[3] = IS_PARAM_DEFINED( info.m_nSilhouetteThickness ) ? params[info.m_nSilhouetteThickness]->GetFloatValue() : kDefaultSilhouetteThickness; + pShaderAPI->SetPixelShaderConstant( 8, vPackedConst8, 1 ); + + // Ground min/max + float vPackedConst9[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; + vPackedConst9[0] = IS_PARAM_DEFINED( info.m_nGroundMin ) ? params[info.m_nGroundMin]->GetFloatValue() : kDefaultGroundMin; + vPackedConst9[1] = IS_PARAM_DEFINED( info.m_nGroundMax ) ? params[info.m_nGroundMax]->GetFloatValue() : kDefaultGroundMax; + pShaderAPI->SetPixelShaderConstant( 9, vPackedConst9, 1 ); + + // Set c0 and c1 to contain first two rows of ViewProj matrix + VMatrix mView, mProj; + pShaderAPI->GetMatrix( MATERIAL_VIEW, mView.m[0] ); + pShaderAPI->GetMatrix( MATERIAL_PROJECTION, mProj.m[0] ); + VMatrix mViewProj = mView * mProj; + mViewProj = mViewProj.Transpose3x3(); + pShaderAPI->SetPixelShaderConstant( 0, mViewProj.m[0], 2 ); + } + pShader->Draw(); +} diff --git a/materialsystem/stdshaders/aftershock_helper.h b/materialsystem/stdshaders/aftershock_helper.h new file mode 100644 index 0000000..219eb85 --- /dev/null +++ b/materialsystem/stdshaders/aftershock_helper.h @@ -0,0 +1,56 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// + +#ifndef AFTERSHOCK_HELPER_H +#define AFTERSHOCK_HELPER_H +#ifdef _WIN32 +#pragma once +#endif + +#include + +//----------------------------------------------------------------------------- +// Forward declarations +//----------------------------------------------------------------------------- +class CBaseVSShader; +class IMaterialVar; +class IShaderDynamicAPI; +class IShaderShadow; + +//----------------------------------------------------------------------------- +// Init params/ init/ draw methods +//----------------------------------------------------------------------------- +struct AftershockVars_t +{ + AftershockVars_t() { memset( this, 0xFF, sizeof(AftershockVars_t) ); } + + int m_nColorTint; + int m_nRefractAmount; + + int m_nBumpmap; + int m_nBumpFrame; + int m_nBumpTransform; + + int m_nSilhouetteThickness; + int m_nSilhouetteColor; + int m_nGroundMin; + int m_nGroundMax; + int m_nBlurAmount; + + int m_nTime; +}; + +// Default values (Arrays should only be vec[4]) +static const float kDefaultColorTint[4] = { 1.0f, 1.0f, 1.0f, 1.0f }; +static const float kDefaultRefractAmount = 0.1f; +static const float kDefaultSilhouetteThickness = 0.2f; +static const float kDefaultSilhouetteColor[4] = { 0.3f, 0.3f, 0.5f, 1.0f }; +static const float kDefaultGroundMin = -0.3f; +static const float kDefaultGroundMax = -0.1f; +static const float kDefaultBlurAmount = 0.01f; + +void InitParamsAftershock( CBaseVSShader *pShader, IMaterialVar** params, const char *pMaterialName, AftershockVars_t &info ); +void InitAftershock( CBaseVSShader *pShader, IMaterialVar** params, AftershockVars_t &info ); +void DrawAftershock( CBaseVSShader *pShader, IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, + IShaderShadow* pShaderShadow, AftershockVars_t &info, VertexCompressionType_t vertexCompression ); + +#endif // AFTERSHOCK_HELPER_H diff --git a/materialsystem/stdshaders/aftershock_ps2x.fxc b/materialsystem/stdshaders/aftershock_ps2x.fxc new file mode 100644 index 0000000..24efa6a --- /dev/null +++ b/materialsystem/stdshaders/aftershock_ps2x.fxc @@ -0,0 +1,162 @@ +//========= Copyright © 1996-2006, Valve Corporation, All rights reserved. ============// + +// Includes ======================================================================================= +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX] + +#include "common_vertexlitgeneric_dx9.h" + +// Texture Samplers =============================================================================== +sampler g_tRefractionSampler : register( s0 ); +sampler g_tBumpSampler : register( s1 ); + +// Shaders Constants and Globals ================================================================== +const float4 g_mViewProj0 : register( c0 ); // 1st row of matrix +const float4 g_mViewProj1 : register( c1 ); // 2nd row of matrix + +const float4 g_vCameraPosition : register( c5 ); +const float4 g_vPackedConst6 : register( c6 ); +#define g_flBlurAmount g_vPackedConst6.x // 0.01f; +#define g_flRefractAmount g_vPackedConst6.y // Default = 1.0f +#define g_flTime g_vPackedConst6.w + +const float4 g_cColorTint : register( c7 ); + +const float4 g_vPackedConst8 : register( c8 ); +#define g_cSilhouetteColor g_vPackedConst8 //= { 0.3, 0.3, 0.5 }; +#define g_flSilhouetteThickness g_vPackedConst8.w //= 0.2f; + +const float2 g_vGroundMinMax : register( c9 ); //= { -0.3, -0.1 }; + +// 8 2D Poisson offsets (designed to use .xy and .wz swizzles (not .zw) +static const float4 g_vPoissonOffset[4] = { float4 (-0.0876f, 0.9703f, 0.5651f, 0.4802f ), + float4 ( 0.1851f, 0.1580f, -0.0617f, -0.2616f ), + float4 (-0.5477f, -0.6603f, 0.0711f, -0.5325f ), + float4 (-0.0751f, -0.8954f, 0.4054f, 0.6384f ) }; + +// Interpolated values ============================================================================ +struct PS_INPUT +{ + float3 vWorldNormal : TEXCOORD0; // World-space normal + float3 vWorldTangent : TEXCOORD1; + float3 vWorldBinormal : TEXCOORD2; + float3 vProjPosForRefract : TEXCOORD3; + float3 vWorldViewVector : TEXCOORD4; + float4 vUv0 : TEXCOORD5; // uv.xy, uvScroll.xy + float4 vUv1 : TEXCOORD6; // uv.xy, uvScroll.xy + float2 vUvGroundNoise : TEXCOORD7; +}; + +// Main =========================================================================================== +float4 main( PS_INPUT i ) : COLOR +{ + /* + // Bump layer 0 + float2 vUv0 = i.vUv0Uv1.xy; + float2 vUv0Scroll = i.vUv0Uv1.xy * 3.0f; + vUv0Scroll.y -= g_flTime * 0.1f; + + float4 vBumpTexel0 = tex2D( g_tBumpSampler, vUv0Scroll.xy ); + vBumpTexel0 = tex2D( g_tBumpSampler, vUv0.xy + (vBumpTexel0.xy*0.03) ); + + // Bump layer 1 + float2 vUv1 = i.vUv0Uv1.xy * 10.0f; + float2 vUv1Scroll = i.vUv0Uv1.xy * 32.0f; + vUv1Scroll.y -= g_flTime * 0.1f; + + float4 vBumpTexel1 = tex2D( g_tBumpSampler, vUv1Scroll.xy ); + vBumpTexel1 = tex2D( g_tBumpSampler, vUv1.xy + (vBumpTexel1.xy*0.03) ); + //*/ + + // Bump layer 0 + float4 vBumpTexel0 = tex2D( g_tBumpSampler, i.vUv0.wz ); + vBumpTexel0 = tex2D( g_tBumpSampler, i.vUv0.xy + ( vBumpTexel0.xy*0.03 ) ); + + // Bump layer 1 + float4 vBumpTexel1 = tex2D( g_tBumpSampler, i.vUv1.wz ); + vBumpTexel1 = tex2D( g_tBumpSampler, i.vUv1.xy + ( vBumpTexel1.xy*0.03 ) ); + + // Combine bump layers into tangetn normal + float3 vTangentNormal = ( vBumpTexel0 * 2.0f ) - 1.0f; + vTangentNormal.xyz += ( vBumpTexel1 * 2.0f - 1.0f ) * 0.5f; // * 0.5f; + + // Transform into world space + float3 vWorldNormal = Vec3TangentToWorld( vTangentNormal.xyz, i.vWorldNormal, i.vWorldTangent, i.vWorldBinormal ); + + // Effect mask + //float flEffectMask = saturate( dot( -i.vWorldViewVector.xyz, i.vWorldNormal.xyz ) * lerp( 2.0f, 1.0f, g_flSilhouetteThickness ) ); + float flEffectMask = saturate( dot( -i.vWorldViewVector.xyz, i.vWorldNormal.xyz ) * ( (2.0f - g_flSilhouetteThickness) ) ); + + // Simulate ground intersection + flEffectMask *= smoothstep( g_vGroundMinMax.x, g_vGroundMinMax.y, i.vWorldNormal.z ); + + // Soften mask by squaring term + flEffectMask *= flEffectMask; + + // Silhouette mask + float flSilhouetteHighlightMask = saturate( flEffectMask * ( 1.0f - flEffectMask ) * 4.0f ); + flSilhouetteHighlightMask *= flSilhouetteHighlightMask * flSilhouetteHighlightMask; + + // Transform world space normal into clip space and project + float3 vProjNormal; + vProjNormal.x = dot( vWorldNormal.xyz, g_mViewProj0.xyz ); // 1st row + vProjNormal.y = dot( vWorldNormal.xyz, g_mViewProj1.xyz ); // 2nd row + + // Compute coordinates for sampling refraction + float2 vRefractTexCoordNoWarp = i.vProjPosForRefract.xy / i.vProjPosForRefract.z; + float2 vRefractTexCoord = vProjNormal.xy; + float scale = lerp( 0.0f, g_flRefractAmount, flEffectMask );// * flEffectMask * flEffectMask ); // Using flEffectMask^3 + vRefractTexCoord.xy *= scale; + vRefractTexCoord.xy += vRefractTexCoordNoWarp.xy; + + // Blur by scalable Poisson filter + float flBlurAmount = g_flBlurAmount * flEffectMask; + float3 cRefract = tex2D( g_tRefractionSampler, vRefractTexCoord.xy ); + cRefract += tex2D( g_tRefractionSampler, vRefractTexCoord.xy + ( g_vPoissonOffset[0].xy * flBlurAmount ) ); + cRefract += tex2D( g_tRefractionSampler, vRefractTexCoord.xy + ( g_vPoissonOffset[0].wz * flBlurAmount ) ); + cRefract += tex2D( g_tRefractionSampler, vRefractTexCoord.xy + ( g_vPoissonOffset[1].xy * flBlurAmount ) ); + cRefract += tex2D( g_tRefractionSampler, vRefractTexCoord.xy + ( g_vPoissonOffset[1].wz * flBlurAmount ) ); + cRefract += tex2D( g_tRefractionSampler, vRefractTexCoord.xy + ( g_vPoissonOffset[2].xy * flBlurAmount ) ); + cRefract += tex2D( g_tRefractionSampler, vRefractTexCoord.xy + ( g_vPoissonOffset[2].wz * flBlurAmount ) ); + cRefract += tex2D( g_tRefractionSampler, vRefractTexCoord.xy + ( g_vPoissonOffset[3].xy * flBlurAmount ) ); + cRefract += tex2D( g_tRefractionSampler, vRefractTexCoord.xy + ( g_vPoissonOffset[3].wz * flBlurAmount ) ); + cRefract /= 9.0f; + + // Undo tone mapping + cRefract /= LINEAR_LIGHT_SCALE; + + // Refract color tint + float fColorTintStrength = 1.0f - flEffectMask; + float3 cRefractColorTint = lerp( g_cColorTint, 1.0f, fColorTintStrength ); + + // Ground noise + //float flGroundNoise = tex2D( g_tBumpSampler, i.vUvGroundNoise.xy ).g; + //flGroundNoise *= smoothstep( g_vGroundMinMax.y, g_vGroundMinMax.y+0.4, -i.vWorldNormal.z ); + //flGroundNoise = smoothstep( 0.2, 0.9, flGroundNoise ); + + //===============// + // Combine terms // + //===============// + float4 result; + result.rgb = cRefract.rgb * cRefractColorTint.rgb; + result.rgb += result.rgb * ( flSilhouetteHighlightMask * g_cSilhouetteColor.rgb ); + //result.rgb += flGroundNoise; + +//result.rgb = float3( 0.0, 0.0, 0.0 ); +//result.rg = vRefractTexCoord.xy; +//result.rg = i.vUv0Uv1.xy; +//result.rgb = vBumpTexel0.rgb; +//result.rgb = vTangentNormal; +//result.rgb = vWorldNormal; +//result = flEffectMask; +//result = flSilhouetteHighlightMask; + +//result = tex2D( g_tBumpSampler, i.vUvGroundNoise.xy ).y; +//result.rgb = flGroundNoise; + + // Set alpha to... + result.a = flEffectMask; + + + return FinalOutput( result, 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_LINEAR ); //go back to final output when it'll fit. +} diff --git a/materialsystem/stdshaders/aftershock_vs20.fxc b/materialsystem/stdshaders/aftershock_vs20.fxc new file mode 100644 index 0000000..a032f43 --- /dev/null +++ b/materialsystem/stdshaders/aftershock_vs20.fxc @@ -0,0 +1,110 @@ +//========= Copyright (c) 1996-2006, Valve Corporation, All rights reserved. ============// + +// DYNAMIC: "COMPRESSED_VERTS" "0..1" +// DYNAMIC: "SKINNING" "0..1" + +// Includes +#include "common_vs_fxc.h" + +// Globals +static const bool g_bSkinning = SKINNING ? true : false; +const float g_flTime : register( SHADER_SPECIFIC_CONST_0 ); +const float4 cBaseTexCoordTransform[2] : register( SHADER_SPECIFIC_CONST_1 ); + +// Structs +struct VS_INPUT +{ + float4 vPos : POSITION; // Position + float4 vNormal : NORMAL; // Normal + float4 vBoneWeights : BLENDWEIGHT; // Skin weights + float4 vBoneIndices : BLENDINDICES; // Skin indices + float4 vTexCoord0 : TEXCOORD0; // Base texture coordinates + float4 vTangent : TANGENT; +}; + +struct VS_OUTPUT +{ + float4 vProjPosition : POSITION; // Projection-space position + float3 vWorldNormal : TEXCOORD0; // World-space normal + float3 vWorldTangent : TEXCOORD1; + float3 vWorldBinormal : TEXCOORD2; + float3 vProjPosForRefract : TEXCOORD3; + float3 vWorldViewVector : TEXCOORD4; + float4 vUv0 : TEXCOORD5; + float4 vUv1 : TEXCOORD6; + float2 vUvGroundNoise : TEXCOORD7; +}; + +// Main +VS_OUTPUT main( const VS_INPUT i ) +{ + VS_OUTPUT o; + + float4 vObjPosition = i.vPos; + float4 vObjTangent = i.vTangent; + float3 vObjNormal; + DecompressVertex_Normal( i.vNormal, vObjNormal ); + + // Transform the position + float3 vWorldPosition = { 0.0f, 0.0f, 0.0f }; + float3 vWorldNormal = { 0.0f, 0.0f, 0.0f }; + float3 vWorldTangent = { 0.0f, 0.0f, 0.0f }; + float3 vWorldBinormal = { 0.0f, 0.0f, 0.0f }; + SkinPositionNormalAndTangentSpace( g_bSkinning, vObjPosition, vObjNormal.xyz, vObjTangent.xyzw, i.vBoneWeights, i.vBoneIndices, vWorldPosition, vWorldNormal, vWorldTangent, vWorldBinormal ); + vWorldNormal.xyz = normalize( vWorldNormal.xyz ); + vWorldTangent.xyz = normalize( vWorldTangent.xyz ); + vWorldBinormal.xyz = normalize( vWorldBinormal.xyz ); + + o.vWorldNormal.xyz = vWorldNormal.xyz; + o.vWorldTangent.xyz = vWorldTangent.xyz; + o.vWorldBinormal.xyz = vWorldBinormal.xyz; + + // Transform into projection space + float4 vProjPosition = mul( float4( vWorldPosition, 1.0f ), cViewProj ); + o.vProjPosition = vProjPosition; + + // Map projected position to the refraction texture + float2 vRefractPos; + vRefractPos.x = vProjPosition.x; + vRefractPos.y = -vProjPosition.y; // Invert Y + vRefractPos = (vRefractPos + vProjPosition.w) * 0.5f; + o.vProjPosForRefract.xyz = float3(vRefractPos.x, vRefractPos.y, vProjPosition.w); + + // View vector + float3 vWorldViewVector = normalize (vWorldPosition.xyz - cEyePos.xyz); + o.vWorldViewVector.xyz = vWorldViewVector.xyz; + + // Tangent space transform + //o.mTangentSpaceTranspose[0] = float3( vWorldTangent.x, vWorldBinormal.x, vWorldNormal.x ); + //o.mTangentSpaceTranspose[1] = float3( vWorldTangent.y, vWorldBinormal.y, vWorldNormal.y ); + //o.mTangentSpaceTranspose[2] = float3( vWorldTangent.z, vWorldBinormal.z, vWorldNormal.z ); + + // Texture coordinates + float2 vBaseUv; + vBaseUv.x = dot( i.vTexCoord0.xy, cBaseTexCoordTransform[0] ); + vBaseUv.y = dot( i.vTexCoord0.xy, cBaseTexCoordTransform[1] ); + + // Bump layer 0 + float2 vUv0 = vBaseUv.xy; + float2 vUv0Scroll = vBaseUv.xy * 3.0f; + vUv0Scroll.y -= g_flTime * 0.1f; + + o.vUv0.xy = vUv0.xy; + o.vUv0.wz = vUv0Scroll.xy; + + // Bump layer 1 + float2 vUv1 = vBaseUv.xy * 8.0f; + float2 vUv1Scroll = vBaseUv.xy * 16.0f; + vUv1Scroll.y -= g_flTime * 0.1f; + + o.vUv1.xy = vUv1.xy; + o.vUv1.wz = vUv1Scroll.xy; + + // Ground noise + o.vUvGroundNoise.xy = vBaseUv.xy; + o.vUvGroundNoise.x *= 3.5f; + o.vUvGroundNoise.y *= 0.2105f; + o.vUvGroundNoise.y -= g_flTime * 0.04f; + + return o; +} diff --git a/materialsystem/stdshaders/alphadist_ps11.fxc b/materialsystem/stdshaders/alphadist_ps11.fxc new file mode 100644 index 0000000..cab3765 --- /dev/null +++ b/materialsystem/stdshaders/alphadist_ps11.fxc @@ -0,0 +1,27 @@ +#define HDRTYPE HDR_TYPE_NONE +#include "common_ps_fxc.h" + +struct PS_INPUT +{ + float2 texCoord0 : TEXCOORD0; + float2 texCoord1 : TEXCOORD3; +}; + +sampler BaseTextureSampler : register( s0 ); +sampler DetailTextureSampler : register( s3 ); + +const float4 g_OutlineColor : register( c0 ); +const float4 g_OutlineEnd : register( c1 ); // a comp +const float4 g_OutlineStart : register( c2 ); // a comp + +float4 main( PS_INPUT i ) : COLOR +{ + // Sample frames from texture 0 + float4 base= tex2D( BaseTextureSampler, i.texCoord0 ); + float4 detail=tex2D( DetailTextureSampler, i.texCoord1 ); + if ( detail.a < g_OutlineEnd.a ) + base = g_OutlineColor; + base.a *= ( detail.a > g_OutlineStart.a ); + return base; +} + diff --git a/materialsystem/stdshaders/appchooser360movie_ps2x.fxc b/materialsystem/stdshaders/appchooser360movie_ps2x.fxc new file mode 100644 index 0000000..ee9930b --- /dev/null +++ b/materialsystem/stdshaders/appchooser360movie_ps2x.fxc @@ -0,0 +1,31 @@ +//======= Copyright © 1996-2006, Valve Corporation, All rights reserved. ====== +#define CONVERT_TO_SRGB 0 +#include "common_ps_fxc.h" + +sampler TexSampler : register( s0 ); + +struct PS_INPUT +{ + float2 baseTexCoord : TEXCOORD0; // Base texture coordinate + +#if defined( _X360 ) //matching pixel shader inputs to vertex shader outputs to avoid shader patches + float2 ZeroTexCoord : TEXCOORD1; + float2 bloomTexCoord : TEXCOORD2; +#endif + + float4 vColor : TEXCOORD3; +}; + +float4 main( PS_INPUT i ) : COLOR +{ + float4 vTextureColor = tex2D( TexSampler, i.baseTexCoord ); + vTextureColor.r = SrgbGammaToLinear( vTextureColor.r ); + vTextureColor.g = SrgbGammaToLinear( vTextureColor.g ); + vTextureColor.b = SrgbGammaToLinear( vTextureColor.b ); + + float4 result; + result.rgb = vTextureColor.rgb * i.vColor.rgb; + result.a = i.vColor.a; + + return result; +} diff --git a/materialsystem/stdshaders/bik_dx80.cpp b/materialsystem/stdshaders/bik_dx80.cpp new file mode 100644 index 0000000..74538d4 --- /dev/null +++ b/materialsystem/stdshaders/bik_dx80.cpp @@ -0,0 +1,95 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $Header: $ +// $NoKeywords: $ +//=============================================================================// + +#include "BaseVSShader.h" +#include "cpp_shader_constant_register_map.h" + +BEGIN_VS_SHADER( Bik_dx80, "Help for Bik_dx80" ) + BEGIN_SHADER_PARAMS + SHADER_PARAM( YTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "Y Bink Texture" ) +// SHADER_PARAM( ATEXTURE, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "A Bink Texture" ) + SHADER_PARAM( CRTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "Cr Bink Texture" ) + SHADER_PARAM( CBTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "Cb Bink Texture" ) + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + } + + SHADER_FALLBACK + { + if ( g_pHardwareConfig->GetDXSupportLevel() < 80 ) + { + return "wireframe"; + } + return 0; + } + + SHADER_INIT + { + if ( params[YTEXTURE]->IsDefined() ) + { + LoadTexture( YTEXTURE ); + } +// if ( params[ATEXTURE]->IsDefined() ) +// { +// LoadTexture( ATEXTURE ); +// } + if ( params[CRTEXTURE]->IsDefined() ) + { + LoadTexture( CRTEXTURE ); + } + if ( params[CBTEXTURE]->IsDefined() ) + { + LoadTexture( CBTEXTURE ); + } + } + + SHADER_DRAW + { + int nPass; + for( nPass = 0; nPass < 2; nPass++ ) + { + SHADOW_STATE + { + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER2, true ); + // we don't do alpha for these on dx8 + // pShaderShadow->EnableTexture( SHADER_SAMPLER3, true ); + + unsigned int flags = VERTEX_POSITION; + int numTexCoords = 1; + pShaderShadow->VertexShaderVertexFormat( flags, numTexCoords, 0, 0 ); + + pShaderShadow->SetVertexShader( "bik_vs11", 0 ); + pShaderShadow->SetPixelShader( "bik_ps11", 0 ); + if( nPass > 0 ) + { + EnableAlphaBlending( SHADER_BLEND_ONE, SHADER_BLEND_ONE ); + } + } + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER0, YTEXTURE, FRAME ); + BindTexture( SHADER_SAMPLER1, CRTEXTURE, FRAME ); + BindTexture( SHADER_SAMPLER2, CBTEXTURE, FRAME ); + // we don't do alpha for these on dx8 + // BindTexture( SHADER_SAMPLER3, ATEXTURE, FRAME ); + + pShaderAPI->SetVertexShaderIndex( 0 ); + pShaderAPI->SetPixelShaderIndex( nPass ); + + // We need the view matrix + LoadViewMatrixIntoVertexShaderConstant( VERTEX_SHADER_VIEWMODEL ); + } + Draw( ); + + } + } +END_SHADER diff --git a/materialsystem/stdshaders/bik_dx81.cpp b/materialsystem/stdshaders/bik_dx81.cpp new file mode 100644 index 0000000..3d0c27f --- /dev/null +++ b/materialsystem/stdshaders/bik_dx81.cpp @@ -0,0 +1,86 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $Header: $ +// $NoKeywords: $ +//=============================================================================// + +#include "BaseVSShader.h" +#include "cpp_shader_constant_register_map.h" + +BEGIN_VS_SHADER( Bik_dx81, "Help for Bik_dx81" ) + BEGIN_SHADER_PARAMS + SHADER_PARAM( YTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "Y Bink Texture" ) +// SHADER_PARAM( ATEXTURE, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "A Bink Texture" ) + SHADER_PARAM( CRTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "Cr Bink Texture" ) + SHADER_PARAM( CBTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "Cb Bink Texture" ) + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + } + + SHADER_FALLBACK + { + if ( g_pHardwareConfig->GetDXSupportLevel() < 81 ) + { + return "bik_dx80"; + } + return 0; + } + + SHADER_INIT + { + if ( params[YTEXTURE]->IsDefined() ) + { + LoadTexture( YTEXTURE ); + } +// if ( params[ATEXTURE]->IsDefined() ) +// { +// LoadTexture( ATEXTURE ); +// } + if ( params[CRTEXTURE]->IsDefined() ) + { + LoadTexture( CRTEXTURE ); + } + if ( params[CBTEXTURE]->IsDefined() ) + { + LoadTexture( CBTEXTURE ); + } + } + + SHADER_DRAW + { + SHADOW_STATE + { + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER2, true ); + // we don't do alpha for these on dx8 + // pShaderShadow->EnableTexture( SHADER_SAMPLER3, true ); + + unsigned int flags = VERTEX_POSITION; + int numTexCoords = 1; + pShaderShadow->VertexShaderVertexFormat( flags, numTexCoords, 0, 0 ); + + pShaderShadow->SetVertexShader( "bik_vs11", 0 ); + pShaderShadow->SetPixelShader( "bik_ps14", 0 ); + } + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER0, YTEXTURE, FRAME ); + BindTexture( SHADER_SAMPLER1, CRTEXTURE, FRAME ); + BindTexture( SHADER_SAMPLER2, CBTEXTURE, FRAME ); + // we don't do alpha for these on dx8 + // BindTexture( SHADER_SAMPLER3, ATEXTURE, FRAME ); + + pShaderAPI->SetVertexShaderIndex( 0 ); + pShaderAPI->SetPixelShaderIndex( 0 ); + + // We need the view matrix + LoadViewMatrixIntoVertexShaderConstant( VERTEX_SHADER_VIEWMODEL ); + } + Draw( ); + } +END_SHADER diff --git a/materialsystem/stdshaders/bik_dx90.cpp b/materialsystem/stdshaders/bik_dx90.cpp new file mode 100644 index 0000000..970de89 --- /dev/null +++ b/materialsystem/stdshaders/bik_dx90.cpp @@ -0,0 +1,132 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $Header: $ +// $NoKeywords: $ +//=============================================================================// + +#include "BaseVSShader.h" +#include "cpp_shader_constant_register_map.h" + +#include "bik_ps20.inc" +#include "bik_ps20b.inc" +#include "bik_vs20.inc" + +BEGIN_VS_SHADER( Bik, "Help for Bik" ) + BEGIN_SHADER_PARAMS + SHADER_PARAM( YTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "Y Bink Texture" ) + // re-enable this if we want alpha blending +// SHADER_PARAM( ATEXTURE, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "A Bink Texture" ) + SHADER_PARAM( CRTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "Cr Bink Texture" ) + SHADER_PARAM( CBTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "Cb Bink Texture" ) + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + } + + SHADER_FALLBACK + { + if ( g_pHardwareConfig->GetDXSupportLevel() < 90 ) + { + return "bik_dx81"; + } + return 0; + } + + SHADER_INIT + { + if ( params[YTEXTURE]->IsDefined() ) + { + LoadTexture( YTEXTURE ); + } +// if ( params[ATEXTURE]->IsDefined() ) +// { +// LoadTexture( ATEXTURE ); +// } + if ( params[CRTEXTURE]->IsDefined() ) + { + LoadTexture( CRTEXTURE ); + } + if ( params[CBTEXTURE]->IsDefined() ) + { + LoadTexture( CBTEXTURE ); + } + } + + SHADER_DRAW + { + SHADOW_STATE + { + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER2, true ); +// pShaderShadow->EnableTexture( SHADER_SAMPLER3, true ); + + unsigned int flags = VERTEX_POSITION; + int numTexCoords = 1; + pShaderShadow->VertexShaderVertexFormat( flags, numTexCoords, 0, 0 ); + + DECLARE_STATIC_VERTEX_SHADER( bik_vs20 ); + SET_STATIC_VERTEX_SHADER( bik_vs20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_STATIC_PIXEL_SHADER( bik_ps20b ); + SET_STATIC_PIXEL_SHADER( bik_ps20b ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( bik_ps20 ); + SET_STATIC_PIXEL_SHADER( bik_ps20 ); + } + + // The 360 needs an sRGB write, but NOT an sRGB read! + if ( IsX360() ) + pShaderShadow->EnableSRGBWrite( true ); + else + pShaderShadow->EnableSRGBWrite( false ); + +// EnableAlphaBlending( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA ); + } + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER0, YTEXTURE, FRAME ); + BindTexture( SHADER_SAMPLER1, CRTEXTURE, FRAME ); + BindTexture( SHADER_SAMPLER2, CBTEXTURE, FRAME ); +// BindTexture( SHADER_SAMPLER3, ATEXTURE, FRAME ); + + // We need the view matrix + LoadViewMatrixIntoVertexShaderConstant( VERTEX_SHADER_VIEWMODEL ); + + MaterialFogMode_t fogType = pShaderAPI->GetSceneFogMode(); + int fogIndex = ( fogType == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ) ? 1 : 0; + + DECLARE_DYNAMIC_VERTEX_SHADER( bik_vs20 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( DOWATERFOG, fogIndex ); + SET_DYNAMIC_VERTEX_SHADER( bik_vs20 ); + + pShaderAPI->SetPixelShaderFogParams( PSREG_FOG_PARAMS ); + + float vEyePos_SpecExponent[4]; + pShaderAPI->GetWorldSpaceCameraPosition( vEyePos_SpecExponent ); + vEyePos_SpecExponent[3] = 0.0f; + pShaderAPI->SetPixelShaderConstant( PSREG_EYEPOS_SPEC_EXPONENT, vEyePos_SpecExponent, 1 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_DYNAMIC_PIXEL_SHADER( bik_ps20b ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + SET_DYNAMIC_PIXEL_SHADER( bik_ps20b ); + } + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( bik_ps20 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + SET_DYNAMIC_PIXEL_SHADER( bik_ps20 ); + } + } + Draw( ); + } +END_SHADER diff --git a/materialsystem/stdshaders/bik_ps11.psh b/materialsystem/stdshaders/bik_ps11.psh new file mode 100644 index 0000000..5ff32a0 --- /dev/null +++ b/materialsystem/stdshaders/bik_ps11.psh @@ -0,0 +1,53 @@ +; DYNAMIC: "PASS" "0..1" +ps.1.1 + +; NOTE: If we ever need to alpha blend this, we'll need to set the right mask to RG on the first pass and B on the second. + +; premultiplied by .25 so that they fit in [-1,1] and use _x4 to scale back up. +; note that the 4th component of each isn't used and is instead in c6 and c7. +def c0, 0.29103088375, 0.3989486695, 0.0f, -0.217663765 +def c1, 0.29103088375, -0.20336914075, -0.09786224375, 0.132426262 +def c2, 0.29103088375, 0.0f, 0.5044555665, -0.2704172135 + +; masks for component selection since ps_1_1 doesn't have general write masking. +def c3, 1.0f, 0.0f, 0.0f, 1.0f +def c4, 0.0f, 1.0f, 0.0f, 0.0f +def c5, 0.0f, 0.0f, 1.0f, 0.0f + +def c6, -0.217663765, 0.132426262, 0.0f, 0.0f +def c7, 0.0f, 0.0f, -0.2704172135, 0.0f + +tex t0 ; Y +tex t1 ; cR +tex t2 ; cB + +; could save an instruction by putting cR and cB in the same texture in the x and y components. +mul r1.rgb, c3, t0 ; get Y into x +mad r1.rgb, c4, t1, r1 ; get cR into y +mad r1.rgb, c5, t2, r1 ; get cB into z ++mov r0.a, c3.a ; set output alpha to one. . .don't really care since we aren't alpha blending. + +#if PASS == 0 +; do the dot3 part of the dot4 for to convert from YcRCb->Red +dp3 t1.rgb, r1, c0 +; Mask into the red channel +mul r0.rgb, t1, c3 + +; do the dot3 part of the dot4 for to convert from YcRCb->Green +dp3 t1.rgb, r1, c1 +; Mask into the green channel +mad r0.rgb, t1, c4, r0 + +; Add the 4th component for the dp4 to convert from YcRCb->[Red,Green] +add_x4_sat r0.rgb, c6, r0 +#endif + +#if PASS == 1 +; do the dot3 part of the dot4 for to convert from YcRCb->Blue +dp3 t1.rgb, r1, c2 +; Mask into the blue channel +mul r0.rgb, t1, c5 + +; Add the 4th component for the dp4 to convert from YcRCb->Blue +add_x4_sat r0.rgb, c7, r0 +#endif diff --git a/materialsystem/stdshaders/bik_ps14.psh b/materialsystem/stdshaders/bik_ps14.psh new file mode 100644 index 0000000..03ba8e4 --- /dev/null +++ b/materialsystem/stdshaders/bik_ps14.psh @@ -0,0 +1,22 @@ +ps.1.4 + +; premultiplied by .25 so that they fit in [-1,1] and use _x4 to scale back up. +def c0, 0.29103088375, 0.3989486695, 0.0f, -0.217663765 +def c1, 0.29103088375, -0.20336914075, -0.09786224375, 0.132426262 +def c2, 0.29103088375, 0.0f, 0.5044555665, -0.2704172135 + +def c3, 1.0f, 0.0f, 0.0f, 1.0f + +texld r0, t0 ; Y +texld r1, t1 ; cR +texld r2, t2 ; cB + +mov r3.x, r0 ; get Y into x +mov r3.y, r1 ; get cR into y ++mov r3.w, c3.x ; set w to 1 for the 4th component of the dp4 +mov r3.z, r2 ; get cB into z ++mov r0.a, c3.a ; set output alpha to one. . .don't really care since we aren't alpha blending. + +dp4_x4_sat r0.r, r3, c0 +dp4_x4_sat r0.g, r3, c1 +dp4_x4_sat r0.b, r3, c2 diff --git a/materialsystem/stdshaders/bik_ps2x.fxc b/materialsystem/stdshaders/bik_ps2x.fxc new file mode 100644 index 0000000..e70c876 --- /dev/null +++ b/materialsystem/stdshaders/bik_ps2x.fxc @@ -0,0 +1,96 @@ +// DYNAMIC: "PIXELFOGTYPE" "0..1" + +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX] + +#include "common_ps_fxc.h" +#include "shader_constant_register_map.h" + +const float4 g_FogParams : register( PSREG_FOG_PARAMS ); +const float4 g_EyePos_SpecExponent : register( PSREG_EYEPOS_SPEC_EXPONENT ); + +sampler YTextureSampler : register( s0 ); +sampler cRTextureSampler : register( s1 ); +sampler cBTextureSampler : register( s2 ); +//sampler ATextureSampler : register( s3 ); + +struct PS_INPUT +{ + HALF2 baseTexCoord : TEXCOORD0; + HALF4 worldPos_projPosZ : TEXCOORD1; + float4 fogFactorW : COLOR1; +}; + +#if 0 +static float yuvtorgb[] = +{ + 1.164123535f, 1.595794678f, 0.0f, -0.87065506f, + 1.164123535f, -0.813476563f, -0.391448975f, 0.529705048f, + 1.164123535f, 0.0f, 2.017822266f, -1.081668854f, + 1.0f, 0.0f, 0.0f, 0.0f +}; +" sampler tex0 : register( s0 ); " +" sampler tex1 : register( s1 ); " +" sampler tex2 : register( s2 ); " +" sampler tex3 : register( s3 ); " +" float4 tor : register( c0 ); " +" float4 tog : register( c1 ); " +" float4 tob : register( c2 ); " +" float4 consts : register( c3 ); " +" " +" struct VS_OUT " +" { " +" float2 T0: TEXCOORD0; " +" }; " +" " +" float4 main( VS_OUT In ) : COLOR " +" { " +" float4 c; " +" float4 p; " +" c.x = tex2D( tex0, In.T0 ).x; " +" c.y = tex2D( tex1, In.T0 ).x; " +" c.z = tex2D( tex2, In.T0 ).x; " +" c.w = consts.x; " +" p.w = tex2D( tex3, In.T0 ).x; " +" p.x = dot( tor, c ); " +" p.y = dot( tog, c ); " +" p.z = dot( tob, c ); " +" p.w *= consts.w; " +" return p; " +" } "; +#endif + +float4 main( PS_INPUT i ) : COLOR +{ + half y, cR, cB; + y = tex2D( YTextureSampler, i.baseTexCoord.xy ); + cR = tex2D( cRTextureSampler, i.baseTexCoord.xy ); + cB = tex2D( cBTextureSampler, i.baseTexCoord.xy ); +// half a = tex2D( ATextureSampler, i.baseTexCoord.xy ); + + HALF4 c; + c = float4( y, cR, cB, 1.0f ); + + float4 tor = float4( 1.164123535f, 1.595794678f, 0.0f, -0.87065506f ); + float4 tog = float4( 1.164123535f, -0.813476563f, -0.391448975f, 0.529705048f ); + float4 tob = float4( 1.164123535f, 0.0f, 2.017822266f, -1.081668854f ); + + HALF4 rgba; + + rgba.r = dot( c, tor ); + rgba.g = dot( c, tog ); + rgba.b = dot( c, tob ); + rgba.a = 1.0f; + + float fogFactor = CalcPixelFogFactor( PIXELFOGTYPE, g_FogParams, g_EyePos_SpecExponent.z, i.worldPos_projPosZ.z, i.worldPos_projPosZ.w ); + float4 result = FinalOutput( rgba, fogFactor, PIXELFOGTYPE, TONEMAP_SCALE_NONE ); + + // The 360 will do an sRGB write to put the linear values into 360 gamma space, but the PC just outputs gamma values directly + #if defined( _X360 ) + result.r = SrgbGammaToLinear( result.r ); + result.g = SrgbGammaToLinear( result.g ); + result.b = SrgbGammaToLinear( result.b ); + #endif + + return result.rgba; +} diff --git a/materialsystem/stdshaders/bik_vs11.vsh b/materialsystem/stdshaders/bik_vs11.vsh new file mode 100644 index 0000000..d15e15b --- /dev/null +++ b/materialsystem/stdshaders/bik_vs11.vsh @@ -0,0 +1,19 @@ +vs.1.1 + +#include "macros.vsh" + +&AllocateRegister( \$projPos ); + +dp4 $projPos.x, $vPos, $cModelViewProj0 +dp4 $projPos.y, $vPos, $cModelViewProj1 +dp4 $projPos.z, $vPos, $cModelViewProj2 +dp4 $projPos.w, $vPos, $cModelViewProj3 +mov oPos, $projPos + +mov oT0, $vTexCoord0 +mov oT1, $vTexCoord0 +mov oT2, $vTexCoord0 +mov oT3, $vTexCoord0 + +&FreeRegister( \$projPos ); + diff --git a/materialsystem/stdshaders/bik_vs20.fxc b/materialsystem/stdshaders/bik_vs20.fxc new file mode 100644 index 0000000..f6be719 --- /dev/null +++ b/materialsystem/stdshaders/bik_vs20.fxc @@ -0,0 +1,45 @@ +// DYNAMIC: "DOWATERFOG" "0..1" +#include "common_vs_fxc.h" + +static const int g_FogType = DOWATERFOG; + +struct VS_INPUT +{ + float4 vPos : POSITION; + float4 vTexCoord0 : TEXCOORD0; +}; + +struct VS_OUTPUT +{ + float4 projPos : POSITION; // Projection-space position +#if !defined( _X360 ) + float fog : FOG; +#endif + HALF2 baseTexCoord : TEXCOORD0; // Base texture coordinate + float4 worldPos_projPosZ : TEXCOORD1; // Necessary for water fog dest alpha + float4 fogFactorW : COLOR1; +}; + +VS_OUTPUT main( const VS_INPUT v ) +{ + VS_OUTPUT o = ( VS_OUTPUT )0; + + float4 projPos; + float3 worldPos; + + projPos = mul( float4( v.vPos.xyz, 1 ), cModelViewProj ); + o.projPos = projPos; + + worldPos = mul( float4( v.vPos.xyz, 1 ), cModel[0] ); + + o.fogFactorW.w = CalcFog( worldPos, projPos, g_FogType ); +#if !defined( _X360 ) + o.fog = o.fogFactorW.w; +#endif + + o.worldPos_projPosZ = float4( worldPos, projPos.z ); + o.baseTexCoord.xy = v.vTexCoord0; + return o; +} + + diff --git a/materialsystem/stdshaders/bloomadd_ps11.fxc b/materialsystem/stdshaders/bloomadd_ps11.fxc new file mode 100644 index 0000000..745c92f --- /dev/null +++ b/materialsystem/stdshaders/bloomadd_ps11.fxc @@ -0,0 +1,18 @@ +//======= Copyright © 1996-2006, Valve Corporation, All rights reserved. ====== +#define CONVERT_TO_SRGB 0 + +#include "common_ps_fxc.h" + +sampler TexSampler : register( s0 ); + +struct PS_INPUT +{ + HALF2 baseTexCoord : TEXCOORD0; // Base texture coordinate +}; + +float4 main( PS_INPUT i ) : COLOR +{ + float4 result = tex2D( TexSampler, i.baseTexCoord ); + result.a = 1.0f; + return result; //FinalOutput( result, 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE ); +} diff --git a/materialsystem/stdshaders/bloomadd_ps2x.fxc b/materialsystem/stdshaders/bloomadd_ps2x.fxc new file mode 100644 index 0000000..aa434b4 --- /dev/null +++ b/materialsystem/stdshaders/bloomadd_ps2x.fxc @@ -0,0 +1,23 @@ +//======= Copyright © 1996-2006, Valve Corporation, All rights reserved. ====== +#define CONVERT_TO_SRGB 0 + +#include "common_ps_fxc.h" + +sampler TexSampler : register( s0 ); + +struct PS_INPUT +{ + HALF2 baseTexCoord : TEXCOORD0; // Base texture coordinate + +#if defined( _X360 ) //matching pixel shader inputs to vertex shader outputs to avoid shader patches + float2 ZeroTexCoord : TEXCOORD1; + float2 bloomTexCoord : TEXCOORD2; +#endif +}; + +float4 main( PS_INPUT i ) : COLOR +{ + float4 result = tex2D( TexSampler, i.baseTexCoord ); + result.a = 1.0f; + return result; //FinalOutput( result, 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE ); +} diff --git a/materialsystem/stdshaders/bufferclearobeystencil_ps2x.fxc b/materialsystem/stdshaders/bufferclearobeystencil_ps2x.fxc new file mode 100644 index 0000000..d18f45c --- /dev/null +++ b/materialsystem/stdshaders/bufferclearobeystencil_ps2x.fxc @@ -0,0 +1,14 @@ +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX] + +#include "common_ps_fxc.h" + +struct PS_INPUT +{ + float4 vColor : COLOR0; +}; + +HALF4 main( PS_INPUT i ) : COLOR +{ + return i.vColor; +} diff --git a/materialsystem/stdshaders/bufferclearobeystencil_vs20.fxc b/materialsystem/stdshaders/bufferclearobeystencil_vs20.fxc new file mode 100644 index 0000000..170e75b --- /dev/null +++ b/materialsystem/stdshaders/bufferclearobeystencil_vs20.fxc @@ -0,0 +1,35 @@ +#include "common_vs_fxc.h" +// STATIC: "USESCOLOR" "0..1" + +struct VS_INPUT +{ + float4 vPos : POSITION; +# if (USESCOLOR == 1) + float4 vColor : COLOR0; +# endif +}; + +struct VS_OUTPUT +{ + float4 vProjPos : POSITION; +# if (USESCOLOR == 1) + float4 vColor : COLOR0; +# endif +}; + + +VS_OUTPUT main( const VS_INPUT v ) +{ + VS_OUTPUT o = ( VS_OUTPUT )0; + + o.vProjPos.xyz = v.vPos.xyz; + o.vProjPos.w = 1.0f; + +# if (USESCOLOR == 1) + { + o.vColor = v.vColor; + } +# endif + + return o; +} \ No newline at end of file diff --git a/materialsystem/stdshaders/buildallshaders.bat b/materialsystem/stdshaders/buildallshaders.bat new file mode 100644 index 0000000..66970d9 --- /dev/null +++ b/materialsystem/stdshaders/buildallshaders.bat @@ -0,0 +1,77 @@ +@echo off +setlocal + +set TTEXE=..\..\devtools\bin\timeprecise.exe +if not exist %TTEXE% goto no_ttexe +goto no_ttexe_end + +:no_ttexe +set TTEXE=time /t +:no_ttexe_end + + +rem echo. +rem echo ~~~~~~ buildallshaders %* ~~~~~~ +%TTEXE% -cur-Q +set tt_all_start=%ERRORLEVEL% +set tt_all_chkpt=%tt_start% + + + +set sourcedir="shaders" +set targetdir="..\..\..\game\hl2\shaders" + +set BUILD_SHADER=call buildshaders.bat + +set ARG_X360=-x360 +set ARG_EXTRA= + + + +REM **************** +REM usage: buildallshaders [-pc | -x360] +REM **************** +set ALLSHADERS_CONFIG=pc +if /i "%1" == "-x360" goto shcfg_x360 +goto shcfg_end +:shcfg_x360 + set ALLSHADERS_CONFIG=x360 +:shcfg_end + + +REM **************** +REM PC SHADERS +REM **************** +if /i "%ALLSHADERS_CONFIG%" == "pc" ( + %BUILD_SHADER% stdshader_dx9_20b + %BUILD_SHADER% stdshader_dx9_20b_new -dx9_30 + %BUILD_SHADER% stdshader_dx9_30 -dx9_30 -force30 + rem %BUILD_SHADER% stdshader_dx10 -dx10 +) + +REM **************** +REM X360 SHADERS +REM **************** +if /i "%ALLSHADERS_CONFIG%" == "x360" ( + %BUILD_SHADER% stdshader_dx9_20b %ARG_X360% %ARG_EXTRA% + %BUILD_SHADER% stdshader_dx9_20b_new %ARG_X360% %ARG_EXTRA% + rem %BUILD_SHADER% stdshader_dx9_30 %ARG_X360% %ARG_EXTRA% + rem %BUILD_SHADER% stdshader_dx10 %ARG_X360% %ARG_EXTRA% +) + +REM **************** +REM END +REM **************** +:end + + + +rem echo. +if not "%dynamic_shaders%" == "1" ( + rem echo Finished full buildallshaders %* +) else ( + rem echo Finished dynamic buildallshaders %* +) + +rem %TTEXE% -diff %tt_all_start% -cur +rem echo. diff --git a/materialsystem/stdshaders/builddynamic.bat b/materialsystem/stdshaders/builddynamic.bat new file mode 100644 index 0000000..356199d --- /dev/null +++ b/materialsystem/stdshaders/builddynamic.bat @@ -0,0 +1,3 @@ +set dynamic_shaders=1 +call buildallshaders.bat +set dynamic_shaders= diff --git a/materialsystem/stdshaders/buildshaders.bat b/materialsystem/stdshaders/buildshaders.bat new file mode 100644 index 0000000..cc1bc6b --- /dev/null +++ b/materialsystem/stdshaders/buildshaders.bat @@ -0,0 +1,258 @@ +@echo off + +set TTEXE=..\..\devtools\bin\timeprecise.exe +if not exist %TTEXE% goto no_ttexe +goto no_ttexe_end + +:no_ttexe +set TTEXE=time /t +:no_ttexe_end + +echo. +rem echo ==================== buildshaders %* ================== +%TTEXE% -cur-Q +set tt_start=%ERRORLEVEL% +set tt_chkpt=%tt_start% + + +REM **************** +REM usage: buildshaders [-x360] +REM **************** + +setlocal +set arg_filename=%1 +rem set shadercompilecommand=echo shadercompile.exe -mpi_graphics -mpi_TrackEvents +set shadercompilecommand=shadercompile.exe +set shadercompileworkers=128 +set x360_args= +set targetdir=..\..\..\game\hl2\shaders +set SrcDirBase=..\.. +set ChangeToDir=../../../game/bin +set shaderDir=shaders +set SDKArgs= +set SHADERINCPATH=vshtmp9/... fxctmp9/... + + +set DIRECTX_SDK_VER=pc09.00 +set DIRECTX_SDK_BIN_DIR=dx9sdk\utilities + +if /i "%2" == "-x360" goto dx_sdk_x360 +if /i "%2" == "-dx9_30" goto dx_sdk_dx9_30 +if /i "%2" == "-dx10" goto dx_sdk_dx10 +goto dx_sdk_end +:dx_sdk_x360 + set DIRECTX_SDK_VER=x360.00 + set DIRECTX_SDK_BIN_DIR=x360xdk\bin\win32 + goto dx_sdk_end +:dx_sdk_dx9_30 + set DIRECTX_SDK_VER=pc09.30 + set DIRECTX_SDK_BIN_DIR=dx10sdk\utilities\dx9_30 + goto dx_sdk_end +:dx_sdk_dx10 + set DIRECTX_SDK_VER=pc10.00 + set DIRECTX_SDK_BIN_DIR=dx10sdk\utilities\dx10_40 + goto dx_sdk_end +:dx_sdk_end + +if "%1" == "" goto usage +set inputbase=%1 + +if /i "%3" == "-force30" goto set_force30_arg +goto set_force_end +:set_force30_arg + set DIRECTX_FORCE_MODEL=30 + goto set_force_end +:set_force_end + +if /i "%2" == "-x360" goto set_x360_args +if /i "%2" == "-game" goto set_mod_args +goto build_shaders + +REM **************** +REM USAGE +REM **************** +:usage +echo. +echo "usage: buildshaders [-x360 or -dx10 or -game] [gameDir if -game was specified] [-source sourceDir]" +echo " gameDir is where gameinfo.txt is (where it will store the compiled shaders)." +echo " sourceDir is where the source code is (where it will find scripts and compilers)." +echo "ex : buildshaders myshaders" +echo "ex : buildshaders myshaders -game c:\steam\steamapps\sourcemods\mymod -source c:\mymod\src" +goto :end + +REM **************** +REM X360 ARGS +REM **************** +:set_x360_args +set x360_args=-x360 +set SHADERINCPATH=vshtmp9_360/... fxctmp9_360/... +goto build_shaders + +REM **************** +REM MOD ARGS - look for -game or the vproject environment variable +REM **************** +:set_mod_args + +if not exist %sourcesdk%\bin\shadercompile.exe goto NoShaderCompile +set ChangeToDir=%sourcesdk%\bin + +if /i "%4" NEQ "-source" goto NoSourceDirSpecified +set SrcDirBase=%~5 + +REM ** use the -game parameter to tell us where to put the files +set targetdir=%~3\shaders +set SDKArgs=-nompi -game "%~3" + +if not exist "%~3\gameinfo.txt" goto InvalidGameDirectory +goto build_shaders + +REM **************** +REM ERRORS +REM **************** +:InvalidGameDirectory +echo - +echo Error: "%~3" is not a valid game directory. +echo (The -game directory must have a gameinfo.txt file) +echo - +goto end + +:NoSourceDirSpecified +echo ERROR: If you specify -game on the command line, you must specify -source. +goto usage +goto end + +:NoShaderCompile +echo - +echo - ERROR: shadercompile.exe doesn't exist in %sourcesdk%\bin +echo - +goto end + +REM **************** +REM BUILD SHADERS +REM **************** +:build_shaders + +rem echo -------------------------------- +rem echo %inputbase% +rem echo -------------------------------- +REM make sure that target dirs exist +REM files will be built in these targets and copied to their final destination +if not exist %shaderDir% mkdir %shaderDir% +if not exist %shaderDir%\fxc mkdir %shaderDir%\fxc +if not exist %shaderDir%\vsh mkdir %shaderDir%\vsh +if not exist %shaderDir%\psh mkdir %shaderDir%\psh +REM Nuke some files that we will add to later. +if exist filelist.txt del /f /q filelist.txt +if exist filestocopy.txt del /f /q filestocopy.txt +if exist filelistgen.txt del /f /q filelistgen.txt +if exist inclist.txt del /f /q inclist.txt +if exist vcslist.txt del /f /q vcslist.txt + + +REM **************** +REM Revert any targets (vcs or inc) that are opened for integrate. +REM **************** +perl "%SrcDirBase%\devtools\bin\p4revertshadertargets.pl" %x360_args% -source "%SrcDirBase%" %inputbase% + +REM **************** +REM Generate a makefile for the shader project +REM **************** +perl "%SrcDirBase%\devtools\bin\updateshaders.pl" %x360_args% -source "%SrcDirBase%" %inputbase% + + +REM **************** +REM Run the makefile, generating minimal work/build list for fxc files, go ahead and compile vsh and psh files. +REM **************** +rem nmake /S /C -f makefile.%inputbase% clean > clean.txt 2>&1 +echo Building inc files, asm vcs files, and VMPI worklist for %inputbase%... +nmake /S /C -f makefile.%inputbase% + +REM **************** +REM Copy the inc files to their target +REM **************** +if exist "inclist.txt" ( + echo Publishing shader inc files to target... + perl %SrcDirBase%\devtools\bin\copyshaderincfiles.pl inclist.txt %x360_args% +) + +REM **************** +REM Deal with perforce operations for inc files +REM **************** +if exist inclist.txt if not "%VALVE_NO_AUTO_P4_SHADERS%" == "1" ( + echo Executing perforce operations on .inc files. + perl ..\..\devtools\bin\p4autocheckout.pl inclist.txt "Shader Auto Checkout INC" . %SHADERINCPATH% +) + +REM **************** +REM Add the executables to the worklist. +REM **************** +if /i "%DIRECTX_SDK_VER%" == "pc09.00" ( + rem echo "Copy extra files for dx 9 std +) +if /i "%DIRECTX_SDK_VER%" == "pc09.30" ( + echo %SrcDirBase%\devtools\bin\d3dx9_33.dll >> filestocopy.txt +) +if /i "%DIRECTX_SDK_VER%" == "pc10.00" ( + echo %SrcDirBase%\devtools\bin\d3dx10_33.dll >> filestocopy.txt +) +if /i "%DIRECTX_SDK_VER%" == "x360.00" ( + rem echo "Copy extra files for xbox360 +) + +echo %SrcDirBase%\%DIRECTX_SDK_BIN_DIR%\dx_proxy.dll >> filestocopy.txt + +echo %SrcDirBase%\..\game\bin\shadercompile.exe >> filestocopy.txt +echo %SrcDirBase%\..\game\bin\shadercompile_dll.dll >> filestocopy.txt +echo %SrcDirBase%\..\game\bin\vstdlib.dll >> filestocopy.txt +echo %SrcDirBase%\..\game\bin\tier0.dll >> filestocopy.txt + +REM **************** +REM Cull duplicate entries in work/build list +REM **************** +if exist filestocopy.txt type filestocopy.txt | perl "%SrcDirBase%\devtools\bin\uniqifylist.pl" > uniquefilestocopy.txt +if exist filelistgen.txt if not "%dynamic_shaders%" == "1" ( + echo Generating action list... + copy filelistgen.txt filelist.txt >nul + rem %SrcDirBase%\devtools\bin\fxccombogen.exe nul 2>filelist.txt +) + +REM **************** +REM Execute distributed process on work/build list +REM **************** + +set shader_path_cd=%cd% +if exist "filelist.txt" if exist "uniquefilestocopy.txt" if not "%dynamic_shaders%" == "1" ( + echo Running distributed shader compilation... + cd %ChangeToDir% + %shadercompilecommand% -mpi_workercount %shadercompileworkers% -allowdebug -shaderpath "%shader_path_cd:/=\%" %x360_args% %SDKArgs% + cd %shader_path_cd% +) + + +REM **************** +REM PC and 360 Shader copy +REM Publish the generated files to the output dir using ROBOCOPY (smart copy) or XCOPY +REM This batch file may have been invoked standalone or slaved (master does final smart mirror copy) +REM **************** +if not "%dynamic_shaders%" == "1" ( + if exist makefile.%inputbase%.copy echo Publishing shaders to target... + if exist makefile.%inputbase%.copy perl %SrcDirBase%\devtools\bin\copyshaders.pl makefile.%inputbase%.copy %x360_args% +) + +REM **************** +REM Deal with perforce operations for vcs files +REM **************** +if not "%dynamic_shaders%" == "1" if exist vcslist.txt if not "%VALVE_NO_AUTO_P4_SHADERS%" == "1" ( + echo Executing perforce operations on .vcs files. + perl ..\..\devtools\bin\p4autocheckout.pl vcslist.txt "Shader Auto Checkout VCS" ../../../game/hl2/shaders ../../../game/hl2/shaders/... +) + +REM **************** +REM END +REM **************** +:end + + +%TTEXE% -diff %tt_start% +echo. + diff --git a/materialsystem/stdshaders/bumpmappedlightmap_vs11.fxc b/materialsystem/stdshaders/bumpmappedlightmap_vs11.fxc new file mode 100644 index 0000000..56e1513 --- /dev/null +++ b/materialsystem/stdshaders/bumpmappedlightmap_vs11.fxc @@ -0,0 +1,59 @@ +// DYNAMIC: "DOWATERFOG" "0..1" + +#include "common_vs_fxc.h" + +static const int g_FogType = DOWATERFOG; + +struct VS_INPUT +{ + float4 vPos : POSITION; + float2 vTexCoord0 : TEXCOORD0; + float2 vTexCoord1 : TEXCOORD1; + float2 vTexCoord2 : TEXCOORD2; +}; + +struct VS_OUTPUT +{ + float4 vProjPos : POSITION; + float2 vTexCoord0 : TEXCOORD0; + float2 vTexCoord1 : TEXCOORD1; + float2 vTexCoord2 : TEXCOORD2; + float2 vTexCoord3 : TEXCOORD3; + + + float4 fogFactorW : COLOR1; + +#if !defined( _X360 ) + float fog : FOG; +#endif +}; + + +VS_OUTPUT main( const VS_INPUT v ) +{ + VS_OUTPUT o = ( VS_OUTPUT )0; + + float3 worldPos; + worldPos = mul( v.vPos, cModel[0] ); + o.vProjPos = mul( float4( worldPos, 1 ), cViewProj ); + + o.fogFactorW = CalcFog( worldPos, o.vProjPos, g_FogType ); +#if !defined( _X360 ) + o.fog = o.fogFactorW; +#endif + + + // Compute the texture coordinates given the offset between each bumped lightmap + + float2 bumpOffset; + bumpOffset = v.vTexCoord2; + + o.vTexCoord0 = v.vTexCoord0; // bumpmap texcoords + + o.vTexCoord1 = bumpOffset + v.vTexCoord1; // first lightmap texcoord + o.vTexCoord2 = (bumpOffset * 2.0) + v.vTexCoord1; // second lightmap texcoord + + o.vTexCoord3 = (bumpOffset * 3.0) + v.vTexCoord1; // third lightmpa texcoord + + return o; +} \ No newline at end of file diff --git a/materialsystem/stdshaders/cable_dx6.cpp b/materialsystem/stdshaders/cable_dx6.cpp new file mode 100644 index 0000000..9b11551 --- /dev/null +++ b/materialsystem/stdshaders/cable_dx6.cpp @@ -0,0 +1,62 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//=============================================================================// + +#include "shaderlib/cshader.h" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +DEFINE_FALLBACK_SHADER( Cable, Cable_DX6 ) + +BEGIN_SHADER( Cable_DX6, + "Help for Cable_DX6" ) + + BEGIN_SHADER_PARAMS + SHADER_PARAM( MINLIGHT, SHADER_PARAM_TYPE_FLOAT, "0.25", "Minimum amount of light (0-1 value)" ) + SHADER_PARAM( MAXLIGHT, SHADER_PARAM_TYPE_FLOAT, "0.25", "Maximum amount of light" ) + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + } + + SHADER_INIT + { + LoadTexture( BASETEXTURE ); + } + + int GetDrawFlagsPass1(IMaterialVar** params ) + { + int flags = SHADER_DRAW_POSITION; + if (IS_FLAG_SET(MATERIAL_VAR_VERTEXCOLOR)) + flags |= SHADER_DRAW_COLOR; + flags |= SHADER_DRAW_TEXCOORD0; + return flags; + } + + SHADER_DRAW + { + SHADOW_STATE + { + pShaderShadow->EnableConstantColor( true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + SetNormalBlendingShadowState( BASETEXTURE, true ); + pShaderShadow->DrawFlags( GetDrawFlagsPass1(params) ); + FogToFogColor(); + } + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME ); + SetFixedFunctionTextureTransform( MATERIAL_TEXTURE0, BASETEXTURETRANSFORM ); + Vector min, max; + params[MINLIGHT]->GetVecValue( &min.x, 3 ); + params[MAXLIGHT]->GetVecValue( &max.x, 3 ); + Vector avg = ( min + max ) * 0.5f; + pShaderAPI->Color3fv( &avg.x ); + } + Draw( ); + } +END_SHADER diff --git a/materialsystem/stdshaders/cable_dx8.cpp b/materialsystem/stdshaders/cable_dx8.cpp new file mode 100644 index 0000000..9e3c98d --- /dev/null +++ b/materialsystem/stdshaders/cable_dx8.cpp @@ -0,0 +1,132 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: A wet version of base * lightmap +// +// $Header: $ +// $NoKeywords: $ +//===========================================================================// + +#include "BaseVSShader.h" + +#include "cable.inc" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +DEFINE_FALLBACK_SHADER( Cable, Cable_DX8 ) + +BEGIN_VS_SHADER( Cable_DX8, + "Help for Cable shader" ) + BEGIN_SHADER_PARAMS + SHADER_PARAM( BUMPMAP, SHADER_PARAM_TYPE_TEXTURE, "cable/cablenormalmap", "bumpmap texture" ) + SHADER_PARAM( MINLIGHT, SHADER_PARAM_TYPE_FLOAT, "0.1", "Minimum amount of light (0-1 value)" ) + SHADER_PARAM( MAXLIGHT, SHADER_PARAM_TYPE_FLOAT, "0.3", "Maximum amount of light" ) + END_SHADER_PARAMS + + SHADER_FALLBACK + { + if ( IsPC() && !g_pHardwareConfig->SupportsVertexAndPixelShaders()) + { + return "UnlitGeneric_DX6"; + } + return 0; + } + + SHADER_INIT + { + LoadBumpMap( BUMPMAP ); + LoadTexture( BASETEXTURE ); + } + + SHADER_DRAW + { + SHADOW_STATE + { + // Enable blending? + if ( IS_FLAG_SET( MATERIAL_VAR_TRANSLUCENT ) ) + { + pShaderShadow->EnableDepthWrites( false ); + pShaderShadow->EnableBlending( true ); + pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA ); + } + + pShaderShadow->EnableAlphaTest( IS_FLAG_SET(MATERIAL_VAR_ALPHATEST) ); + + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + if ( g_pHardwareConfig->GetDXSupportLevel() >= 90) + { + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER1, true ); + } + + int tCoordDimensions[] = {2,2}; + pShaderShadow->VertexShaderVertexFormat( + VERTEX_POSITION | VERTEX_COLOR | VERTEX_TANGENT_S | VERTEX_TANGENT_T, + 2, tCoordDimensions, 0 ); + + cable_Static_Index vshIndex; + pShaderShadow->SetVertexShader( "Cable", vshIndex.GetIndex() ); + + pShaderShadow->SetPixelShader( "Cable" ); + + // we are writing linear values from this shader. + // This is kinda wrong. We are writing linear or gamma depending on "IsHDREnabled" below. + // The COLOR really decides if we are gamma or linear. + if ( g_pHardwareConfig->GetDXSupportLevel() >= 90) + { + pShaderShadow->EnableSRGBWrite( true ); + } + + FogToFogColor(); + } + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER0, BUMPMAP ); + BindTexture( SHADER_SAMPLER1, BASETEXTURE ); + + + // The dot product with the light is remapped from the range + // [-1,1] to [MinLight, MaxLight]. + + // Given: + // -A + B = MinLight + // A + B = MaxLight + // then A = (MaxLight - MinLight) / 2 + // and B = (MaxLight + MinLight) / 2 + + // So here, we multiply the light direction by A to scale the dot product. + // Then in the pixel shader we add by B. + float flMinLight = params[MINLIGHT]->GetFloatValue(); + float flMaxLight = params[MAXLIGHT]->GetFloatValue(); + + float A = (flMaxLight - flMinLight) * 0.5f; + float B = (flMaxLight + flMinLight) * 0.5f; + + float b4[4] = {B,B,B,B}; + if( g_pHardwareConfig->GetDXSupportLevel() >= 90) + { + SetPixelShaderConstantGammaToLinear( 0, b4 ); + } + else + { + pShaderAPI->SetPixelShaderConstant( 0, b4 ); + } + + // This is the light direction [0,1,0,0] * A * 0.5 + float lightDir[4] = {0, A*0.5, 0, 0}; + if( g_pHardwareConfig->GetDXSupportLevel() >= 90) + { + SetVertexShaderConstantGammaToLinear( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, lightDir ); + } + else + { + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, lightDir ); + } + + cable_Dynamic_Index vshIndex; + vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() ); + } + Draw(); + } +END_SHADER diff --git a/materialsystem/stdshaders/cable_dx9.cpp b/materialsystem/stdshaders/cable_dx9.cpp new file mode 100644 index 0000000..5b25ed6 --- /dev/null +++ b/materialsystem/stdshaders/cable_dx9.cpp @@ -0,0 +1,141 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: A wet version of base * lightmap +// +// $Header: $ +// $NoKeywords: $ +//===========================================================================// + +#include "BaseVSShader.h" + +#include "cable_vs20.inc" +#include "cable_ps20.inc" +#include "cable_ps20b.inc" +#include "cpp_shader_constant_register_map.h" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +extern ConVar mat_fullbright; + +DEFINE_FALLBACK_SHADER( Cable, Cable_DX9 ) + +BEGIN_VS_SHADER( Cable_DX9, + "Help for Cable shader" ) + BEGIN_SHADER_PARAMS + SHADER_PARAM( BUMPMAP, SHADER_PARAM_TYPE_TEXTURE, "cable/cablenormalmap", "bumpmap texture" ) + SHADER_PARAM( MINLIGHT, SHADER_PARAM_TYPE_FLOAT, "0.1", "Minimum amount of light (0-1 value)" ) + SHADER_PARAM( MAXLIGHT, SHADER_PARAM_TYPE_FLOAT, "0.3", "Maximum amount of light" ) + END_SHADER_PARAMS + + SHADER_FALLBACK + { + if ( !(g_pHardwareConfig->SupportsPixelShaders_2_0() && g_pHardwareConfig->SupportsVertexShaders_2_0()) || + (g_pHardwareConfig->GetDXSupportLevel() < 90) ) + { + return "Cable_DX8"; + } + return 0; + } + + SHADER_INIT + { + LoadBumpMap( BUMPMAP ); + LoadTexture( BASETEXTURE, TEXTUREFLAGS_SRGB ); + } + + SHADER_DRAW + { + BlendType_t nBlendType = EvaluateBlendRequirements( BASETEXTURE, true ); + bool bFullyOpaque = (nBlendType != BT_BLENDADD) && (nBlendType != BT_BLEND) && !IS_FLAG_SET(MATERIAL_VAR_ALPHATEST); //dest alpha is free for special use + + SHADOW_STATE + { + // Enable blending? + if ( IS_FLAG_SET( MATERIAL_VAR_TRANSLUCENT ) ) + { + pShaderShadow->EnableDepthWrites( false ); + pShaderShadow->EnableBlending( true ); + pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA ); + } + + pShaderShadow->EnableAlphaTest( IS_FLAG_SET(MATERIAL_VAR_ALPHATEST) ); + + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + if ( g_pHardwareConfig->GetDXSupportLevel() >= 90) + { + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER1, true ); + } + + int tCoordDimensions[] = {2,2}; + pShaderShadow->VertexShaderVertexFormat( + VERTEX_POSITION | VERTEX_COLOR | VERTEX_TANGENT_S | VERTEX_TANGENT_T, + 2, tCoordDimensions, 0 ); + + DECLARE_STATIC_VERTEX_SHADER( cable_vs20 ); + SET_STATIC_VERTEX_SHADER( cable_vs20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_STATIC_PIXEL_SHADER( cable_ps20b ); + SET_STATIC_PIXEL_SHADER( cable_ps20b ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( cable_ps20 ); + SET_STATIC_PIXEL_SHADER( cable_ps20 ); + } + + // we are writing linear values from this shader. + // This is kinda wrong. We are writing linear or gamma depending on "IsHDREnabled" below. + // The COLOR really decides if we are gamma or linear. + pShaderShadow->EnableSRGBWrite( true ); + + FogToFogColor(); + + pShaderShadow->EnableAlphaWrites( bFullyOpaque ); + } + DYNAMIC_STATE + { + bool bLightingOnly = mat_fullbright.GetInt() == 2 && !IS_FLAG_SET( MATERIAL_VAR_NO_DEBUG_OVERRIDE ); + + BindTexture( SHADER_SAMPLER0, BUMPMAP ); + if ( bLightingOnly ) + { + pShaderAPI->BindStandardTexture( SHADER_SAMPLER1, TEXTURE_GREY ); + + } + else + { + BindTexture( SHADER_SAMPLER1, BASETEXTURE ); + } + + pShaderAPI->SetPixelShaderFogParams( PSREG_FOG_PARAMS ); + + float vEyePos_SpecExponent[4]; + pShaderAPI->GetWorldSpaceCameraPosition( vEyePos_SpecExponent ); + vEyePos_SpecExponent[3] = 0.0f; + pShaderAPI->SetPixelShaderConstant( PSREG_EYEPOS_SPEC_EXPONENT, vEyePos_SpecExponent, 1 ); + + DECLARE_DYNAMIC_VERTEX_SHADER( cable_vs20 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( DOWATERFOG, pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + SET_DYNAMIC_VERTEX_SHADER( cable_vs20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_DYNAMIC_PIXEL_SHADER( cable_ps20b ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( WRITE_DEPTH_TO_DESTALPHA, bFullyOpaque && pShaderAPI->ShouldWriteDepthToDestAlpha() ); + SET_DYNAMIC_PIXEL_SHADER( cable_ps20b ); + } + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( cable_ps20 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + SET_DYNAMIC_PIXEL_SHADER( cable_ps20 ); + } + } + Draw(); + } +END_SHADER diff --git a/materialsystem/stdshaders/cable_ps2x.fxc b/materialsystem/stdshaders/cable_ps2x.fxc new file mode 100644 index 0000000..a3c7ff1 --- /dev/null +++ b/materialsystem/stdshaders/cable_ps2x.fxc @@ -0,0 +1,54 @@ +// DYNAMIC: "PIXELFOGTYPE" "0..1" +// DYNAMIC: "WRITE_DEPTH_TO_DESTALPHA" "0..1" [ps20b] [PC] +// DYNAMIC: "WRITE_DEPTH_TO_DESTALPHA" "0..0" [ps20b] [XBOX] + +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX] + +#if defined( SHADER_MODEL_PS_2_0 ) +# define WRITE_DEPTH_TO_DESTALPHA 0 +#endif + +#include "common_ps_fxc.h" +#include "shader_constant_register_map.h" + +sampler NormalSampler : register( s0 ); +sampler BaseTextureSampler : register( s1 ); + +const float4 g_FogParams : register( PSREG_FOG_PARAMS ); +const float4 g_EyePos_SpecExponent : register( PSREG_EYEPOS_SPEC_EXPONENT ); + +struct PS_INPUT +{ + float2 vTexCoord0 : TEXCOORD0; + float2 vTexCoord1 : TEXCOORD1; + + float4 worldPos_projPosZ : TEXCOORD7; // Necessary for pixel fog + + float4 directionalLightColor : COLOR0; + float4 fogFactorW : COLOR1; +}; + +float4 main( PS_INPUT i ) : COLOR +{ + float3 vNormalMapDir = tex2D( NormalSampler, i.vTexCoord0 ); // Get the 3-vector from the normal map + float4 textureColor = tex2D( BaseTextureSampler, i.vTexCoord1 ); // Interpret tcoord t1 as color data. + + //Expand compacted vectors + //TODO: find if there's a better way to expand a color normal to a full vector ( _bx2 was used in the assembly code ) + vNormalMapDir = (vNormalMapDir - 0.5) * 2.0; + float3 vLightDir = float3( 0.0f, 0.0f, 1.0f ); + + float lightDirDotNormalMap = dot( vNormalMapDir, vLightDir ); //normalMap dot dirLightDir + + // do half-lambert on the dot + lightDirDotNormalMap = lightDirDotNormalMap * 0.5 + 0.5; + lightDirDotNormalMap = lightDirDotNormalMap * lightDirDotNormalMap; + + float4 resultColor; + resultColor.xyz = lightDirDotNormalMap * ( textureColor.rgb * i.directionalLightColor.rgb ); + resultColor.a = textureColor.a * i.directionalLightColor.a; + + float fogFactor = CalcPixelFogFactor( PIXELFOGTYPE, g_FogParams, g_EyePos_SpecExponent.z, i.worldPos_projPosZ.z, i.worldPos_projPosZ.w ); + return FinalOutput( resultColor, fogFactor, PIXELFOGTYPE, TONEMAP_SCALE_LINEAR, (WRITE_DEPTH_TO_DESTALPHA != 0), i.worldPos_projPosZ.w ); +} diff --git a/materialsystem/stdshaders/cable_vs20.fxc b/materialsystem/stdshaders/cable_vs20.fxc new file mode 100644 index 0000000..adb3559 --- /dev/null +++ b/materialsystem/stdshaders/cable_vs20.fxc @@ -0,0 +1,80 @@ +// DYNAMIC: "DOWATERFOG" "0..1" + +#include "common_vs_fxc.h" + +static const int g_FogType = DOWATERFOG; + +struct VS_INPUT +{ + float4 vPos : POSITION; + float2 vTexCoord0 : TEXCOORD0; + float2 vTexCoord1 : TEXCOORD1; + + float4 directionalLightColor : COLOR0; + + float3 vTangentS : TANGENT; + float3 vTangentT : BINORMAL; +}; + +struct VS_OUTPUT +{ + float4 vProjPos : POSITION; + float2 vTexCoord0 : TEXCOORD0; + float2 vTexCoord1 : TEXCOORD1; + + float4 worldPos_projPosZ : TEXCOORD7; // Necessary for pixel fog + + float4 directionalLightColor : COLOR0; + + float4 fogFactorW : COLOR1; + +#if !defined( _X360 ) + float fog : FOG; +#endif +}; + + +VS_OUTPUT main( const VS_INPUT v ) +{ + VS_OUTPUT o = ( VS_OUTPUT )0; + + float3 worldPos; + worldPos = mul( v.vPos, cModel[0] ); + float4 vProjPos = mul( float4( worldPos, 1 ), cViewProj ); + o.vProjPos = vProjPos; + vProjPos.z = dot( float4( worldPos, 1 ), cViewProjZ ); + + o.worldPos_projPosZ = float4( worldPos.xyz, vProjPos.z ); + + o.fogFactorW = CalcFog( worldPos, vProjPos, g_FogType ); +#if !defined( _X360 ) + o.fog = o.fogFactorW; +#endif + + //------------------------------------------------------------------------------ + // Setup the tangent space + //------------------------------------------------------------------------------ + + // Get S crossed with T (call it R) + float3 r = cross( v.vTangentS, v.vTangentT ); + + // Normalize S (into s) + float3 s = normalize( v.vTangentS ); + + // Normalize R (into r) + r = normalize( r ); + + // Regenerate T (into t) + float3 t = cross( r, v.vTangentS ); + + //------------------------------------------------------------------------------ + // Copy texcoords for the normal map and base texture + //------------------------------------------------------------------------------ + o.vTexCoord0 = v.vTexCoord0; + o.vTexCoord1 = v.vTexCoord1; + + // Pass the dirlight color through + o.directionalLightColor = v.directionalLightColor; + + return o; +} \ No newline at end of file diff --git a/materialsystem/stdshaders/clean.bat b/materialsystem/stdshaders/clean.bat new file mode 100644 index 0000000..29f8298 --- /dev/null +++ b/materialsystem/stdshaders/clean.bat @@ -0,0 +1,43 @@ +@echo off +setlocal + +if /i "%1" == "-game" goto CleanGameDir + +rem Clean out hl2 +if exist ..\..\..\game\hl2\shaders rd /s /q ..\..\..\game\hl2\shaders +goto CleanOtherStuff + +:CleanGameDir +set __GameDir=%~2 +if not exist "%__GameDir%\gameinfo.txt" goto MissingGameInfo +if exist "%__GameDir%\shaders" rd /s /q "%2\shaders" +goto CleanOtherStuff + +:CleanOtherStuff +if exist debug_dx9 rd /s /q debug_dx9 + +if exist fxctmp9 rd /s /q fxctmp9 +if exist vshtmp9 rd /s /q vshtmp9 +if exist pshtmp9 rd /s /q pshtmp9 + +if exist fxctmp9_360 rd /s /q fxctmp9_360 +if exist vshtmp9_360 rd /s /q vshtmp9_360 +if exist pshtmp9_360 rd /s /q pshtmp9_360 + +if exist fxctmp9_tmp rd /s /q fxctmp9_tmp +if exist vshtmp9_tmp rd /s /q vshtmp9_tmp +if exist pshtmp9_tmp rd /s /q pshtmp9_tmp + +if exist fxctmp9_360_tmp rd /s /q fxctmp9_360_tmp +if exist vshtmp9_360_tmp rd /s /q vshtmp9_360_tmp +if exist pshtmp9_360_tmp rd /s /q pshtmp9_360_tmp + +if exist shaders rd /s /q shaders +goto end + +:MissingGameInfo +echo Invalid -game parameter specified (no "%__GameDir%\gameinfo.txt" exists). +goto end + + +:end \ No newline at end of file diff --git a/materialsystem/stdshaders/cleantemps.bat b/materialsystem/stdshaders/cleantemps.bat new file mode 100644 index 0000000..7055aaf --- /dev/null +++ b/materialsystem/stdshaders/cleantemps.bat @@ -0,0 +1,12 @@ +@echo off +setlocal + +if exist fxctmp9_tmp rd /s /q fxctmp9_tmp +if exist vshtmp9_tmp rd /s /q vshtmp9_tmp +if exist pshtmp9_tmp rd /s /q pshtmp9_tmp + +if exist fxctmp9_360_tmp rd /s /q fxctmp9_360_tmp +if exist vshtmp9_360_tmp rd /s /q vshtmp9_360_tmp +if exist pshtmp9_360_tmp rd /s /q pshtmp9_360_tmp + +if exist shaders rd /s /q shaders diff --git a/materialsystem/stdshaders/cloak.cpp b/materialsystem/stdshaders/cloak.cpp new file mode 100644 index 0000000..e4b3ed9 --- /dev/null +++ b/materialsystem/stdshaders/cloak.cpp @@ -0,0 +1,122 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: Cloaking shader for Spy in TF2 (and probably many other things to come) +// +// $NoKeywords: $ +//=====================================================================================// + +#include "BaseVSShader.h" +#include "convar.h" +#include "cloak_dx9_helper.h" + +DEFINE_FALLBACK_SHADER( Cloak, Cloak_DX90 ) + +BEGIN_VS_SHADER( Cloak_DX90, "Help for Cloak" ) + + BEGIN_SHADER_PARAMS + SHADER_PARAM_OVERRIDE( COLOR, SHADER_PARAM_TYPE_COLOR, "{255 255 255}", "unused", SHADER_PARAM_NOT_EDITABLE ) + SHADER_PARAM_OVERRIDE( ALPHA, SHADER_PARAM_TYPE_FLOAT, "1.0", "unused", SHADER_PARAM_NOT_EDITABLE ) + SHADER_PARAM( REFRACTAMOUNT, SHADER_PARAM_TYPE_FLOAT, "2", "" ) + SHADER_PARAM( REFRACTTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "refraction tint" ) + SHADER_PARAM( NORMALMAP, SHADER_PARAM_TYPE_TEXTURE, "models/shadertest/shader1_normal", "normal map" ) + SHADER_PARAM( BUMPFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $bumpmap" ) + SHADER_PARAM( BUMPTRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$bumpmap texcoord transform" ) + SHADER_PARAM( TIME, SHADER_PARAM_TYPE_FLOAT, "0.0f", "" ) + SHADER_PARAM( REFRACTTINTTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "models/shadertest/shield", "" ) + SHADER_PARAM( REFRACTTINTTEXTUREFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "" ) + SHADER_PARAM( FRESNELREFLECTION, SHADER_PARAM_TYPE_FLOAT, "1.0", "1.0 == mirror, 0.0 == water" ) + SHADER_PARAM( NOWRITEZ, SHADER_PARAM_TYPE_INTEGER, "0", "0 == write z, 1 = no write z" ) + SHADER_PARAM( MASKED, SHADER_PARAM_TYPE_BOOL, "0", "mask using dest alpha" ) + SHADER_PARAM( CLOAKFACTOR, SHADER_PARAM_TYPE_FLOAT, "0", "How cloaked? Zero is not cloaked, 1 is fully cloaked." ) + SHADER_PARAM( LIGHTWARPTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "1D ramp texture for tinting scalar diffuse term" ) + SHADER_PARAM( PHONGEXPONENT, SHADER_PARAM_TYPE_FLOAT, "5.0", "Phong exponent for local specular lights" ) + SHADER_PARAM( PHONGTINT, SHADER_PARAM_TYPE_VEC3, "5.0", "Phong tint for local specular lights" ) + SHADER_PARAM( PHONGALBEDOTINT, SHADER_PARAM_TYPE_BOOL, "1.0", "Apply tint by albedo (controlled by spec exponent texture" ) + SHADER_PARAM( PHONGFRESNELRANGES, SHADER_PARAM_TYPE_VEC3, "[0 0.5 1]", "Parameters for remapping fresnel output" ) + SHADER_PARAM( PHONGBOOST, SHADER_PARAM_TYPE_FLOAT, "1.0", "Phong overbrightening factor (specular mask channel should be authored to account for this)" ) + SHADER_PARAM( PHONGEXPONENTTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "Phong Exponent map" ) + + // Rim lighting terms + SHADER_PARAM( RIMLIGHT, SHADER_PARAM_TYPE_BOOL, "0", "enables rim lighting" ) + SHADER_PARAM( RIMLIGHTEXPONENT, SHADER_PARAM_TYPE_FLOAT, "4.0", "Exponent for rim lights" ) + SHADER_PARAM( RIMLIGHTBOOST, SHADER_PARAM_TYPE_FLOAT, "1.0", "Boost for rim lights" ) + SHADER_PARAM( RIMMASK, SHADER_PARAM_TYPE_BOOL, "0", "Indicates whether or not to use alpha channel of exponent texture to mask the rim term" ) + END_SHADER_PARAMS +// FIXME: doesn't support Fresnel! + + void SetupVars( Cloak_DX9_Vars_t& info ) + { + info.m_nBaseTexture = BASETEXTURE; + info.m_nRefractAmount = REFRACTAMOUNT; + info.m_nRefractTint = REFRACTTINT; + info.m_nNormalMap = NORMALMAP; + info.m_nBumpFrame = BUMPFRAME; + info.m_nBumpTransform = BUMPTRANSFORM; + info.m_nRefractTintTexture = REFRACTTINTTEXTURE; + info.m_nRefractTintTextureFrame = REFRACTTINTTEXTUREFRAME; + info.m_nFresnelReflection = FRESNELREFLECTION; + info.m_nMasked = MASKED; + info.m_nCloakFactor = CLOAKFACTOR; + info.m_nDiffuseWarpTexture = LIGHTWARPTEXTURE; + info.m_nPhongExponent = PHONGEXPONENT; + info.m_nPhongTint = PHONGTINT; + info.m_nPhongAlbedoTint = PHONGALBEDOTINT; + info.m_nPhongExponentTexture = PHONGEXPONENTTEXTURE; + info.m_nPhongBoost = PHONGBOOST; + info.m_nPhongFresnelRanges = PHONGFRESNELRANGES; + + // Rim lighting parameters + info.m_nRimLight = RIMLIGHT; + info.m_nRimLightPower = RIMLIGHTEXPONENT; + info.m_nRimLightBoost = RIMLIGHTBOOST; + info.m_nRimMask = RIMMASK; + } + + bool NeedsPowerOfTwoFrameBufferTexture( IMaterialVar **params, bool bCheckSpecificToThisFrame ) const + { + if ( bCheckSpecificToThisFrame == false ) // For setting model flag at load time + return true; + else if ( ( params[CLOAKFACTOR]->GetFloatValue() > 0.0f ) && ( params[CLOAKFACTOR]->GetFloatValue() < 1.0f ) ) // Per-frame check + return true; + else + return false; + } + + bool IsTranslucent( IMaterialVar **params ) const + { + if ( ( params[CLOAKFACTOR]->GetFloatValue() > 0.0f ) && ( params[CLOAKFACTOR]->GetFloatValue() < 1.0f ) ) // Per-frame check + return true; + else + return false; + } + + SHADER_INIT_PARAMS() + { + Cloak_DX9_Vars_t info; + SetupVars( info ); + InitParamsCloak_DX9( this, params, pMaterialName, info ); + } + + SHADER_FALLBACK + { + if( g_pHardwareConfig->GetDXSupportLevel() < 82 ) + return "Refract_DX80"; + + return 0; + } + + SHADER_INIT + { + Cloak_DX9_Vars_t info; + SetupVars( info ); + InitCloak_DX9( this, params, info ); + } + + SHADER_DRAW + { + Cloak_DX9_Vars_t info; + SetupVars( info ); + DrawCloak_DX9( this, params, pShaderAPI, pShaderShadow, info, vertexCompression ); + } +END_SHADER + diff --git a/materialsystem/stdshaders/cloak_blended_pass_dx8_helper.cpp b/materialsystem/stdshaders/cloak_blended_pass_dx8_helper.cpp new file mode 100644 index 0000000..e3d82c6 --- /dev/null +++ b/materialsystem/stdshaders/cloak_blended_pass_dx8_helper.cpp @@ -0,0 +1,252 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// + +/* Example how to plug this into an existing shader: + + In the VMT: + // Cloak Pass + "$cloakPassEnabled" "1" + + #include "cloak_blended_pass_helper.h" + + In BEGIN_SHADER_PARAMS: + // Cloak Pass + SHADER_PARAM( CLOAKPASSENABLED, SHADER_PARAM_TYPE_BOOL, "0", "Enables cloak render in a second pass" ) + SHADER_PARAM( CLOAKFACTOR, SHADER_PARAM_TYPE_FLOAT, "0.0", "" ) + SHADER_PARAM( CLOAKCOLORTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "Cloak color tint" ) + SHADER_PARAM( REFRACTAMOUNT, SHADER_PARAM_TYPE_FLOAT, "2", "" ) + + Add this above SHADER_INIT_PARAMS() + // Cloak Pass + void SetupVarsCloakBlendedPass( CloakBlendedPassVars_t &info ) + { + info.m_nCloakFactor = CLOAKFACTOR; + info.m_nCloakColorTint = CLOAKCOLORTINT; + info.m_nRefractAmount = REFRACTAMOUNT; + } + + bool NeedsPowerOfTwoFrameBufferTexture( IMaterialVar **params, bool bCheckSpecificToThisFrame ) const + { + if ( params[CLOAKPASSENABLED]->GetIntValue() ) // If material supports cloaking + { + if ( bCheckSpecificToThisFrame == false ) // For setting model flag at load time + return true; + else if ( ( params[CLOAKFACTOR]->GetFloatValue() > 0.0f ) && ( params[CLOAKFACTOR]->GetFloatValue() < 1.0f ) ) // Per-frame check + return true; + // else, not cloaking this frame, so check flag2 in case the base material still needs it + } + + // Check flag2 if not drawing cloak pass + return IS_FLAG2_SET( MATERIAL_VAR2_NEEDS_POWER_OF_TWO_FRAME_BUFFER_TEXTURE ); + } + + bool IsTranslucent( IMaterialVar **params ) const + { + if ( params[CLOAKPASSENABLED]->GetIntValue() ) // If material supports cloaking + { + if ( ( params[CLOAKFACTOR]->GetFloatValue() > 0.0f ) && ( params[CLOAKFACTOR]->GetFloatValue() < 1.0f ) ) // Per-frame check + return true; + // else, not cloaking this frame, so check flag in case the base material still needs it + } + + // Check flag if not drawing cloak pass + return IS_FLAG_SET( MATERIAL_VAR_TRANSLUCENT ); + } + + In SHADER_INIT_PARAMS() + // Cloak Pass + if ( !params[CLOAKPASSENABLED]->IsDefined() ) + { + params[CLOAKPASSENABLED]->SetIntValue( 0 ); + } + else if ( params[CLOAKPASSENABLED]->GetIntValue() ) + { + CloakBlendedPassVars_t info; + SetupVarsCloakBlendedPass( info ); + InitParamsCloakBlendedPass( this, params, pMaterialName, info ); + } + + In SHADER_INIT + // Cloak Pass + if ( params[CLOAKPASSENABLED]->GetIntValue() ) + { + CloakBlendedPassVars_t info; + SetupVarsCloakBlendedPass( info ); + InitCloakBlendedPass( this, params, info ); + } + + Modify SHADER_DRAW to look something like this: + // Skip the standard rendering if cloak pass is fully opaque + bool bDrawStandardPass = true; + if ( params[CLOAKPASSENABLED]->GetIntValue() && ( pShaderShadow == NULL ) ) // && not snapshotting + { + CloakBlendedPassVars_t info; + SetupVarsCloakBlendedPass( info ); + if ( CloakBlendedPassIsFullyOpaque( params, info ) ) + { + bDrawStandardPass = false; + } + } + + // Standard rendering pass + if ( bDrawStandardPass ) + { + Eye_Refract_Vars_t info; + SetupVarsEyeRefract( info ); + Draw_Eyes_Refract( this, params, pShaderAPI, pShaderShadow, info ); + } + else + { + // Skip this pass! + Draw( false ); + } + + // Cloak Pass + if ( params[CLOAKPASSENABLED]->GetIntValue() ) + { + // If ( snapshotting ) or ( we need to draw this frame ) + if ( ( pShaderShadow != NULL ) || ( ( params[CLOAKFACTOR]->GetFloatValue() > 0.0f ) && ( params[CLOAKFACTOR]->GetFloatValue() < 1.0f ) ) ) + { + CloakBlendedPassVars_t info; + SetupVarsCloakBlendedPass( info ); + DrawCloakBlendedPass( this, params, pShaderAPI, pShaderShadow, info, vertexCompression ); + } + else // We're not snapshotting and we don't need to draw this frame + { + // Skip this pass! + Draw( false ); + } + } + +==================================================================================================== */ + +#include "BaseVSShader.h" +#include "mathlib/vmatrix.h" +#include "cloak_blended_pass_helper.h" +#include "convar.h" + +// Auto generated inc files +#include "cloak_blended_pass_dx8_vs11.inc" + +void InitParamsCloakBlendedPass( CBaseVSShader *pShader, IMaterialVar** params, const char *pMaterialName, CloakBlendedPassVars_t &info ) +{ + // Set material flags + SET_FLAGS2( MATERIAL_VAR2_SUPPORTS_HW_SKINNING ); + SET_FLAGS( MATERIAL_VAR_MODEL ); + SET_FLAGS2( MATERIAL_VAR2_NEEDS_TANGENT_SPACES ); + + // Set material parameter default values + if ( ( info.m_nCloakFactor != -1 ) && ( !params[info.m_nCloakFactor]->IsDefined() ) ) + { + params[info.m_nCloakFactor]->SetFloatValue( kDefaultCloakFactor ); + } + + if ( ( info.m_nRefractAmount != -1 ) && ( !params[info.m_nRefractAmount]->IsDefined() ) ) + { + params[info.m_nRefractAmount]->SetFloatValue( kDefaultRefractAmount ); + } + + if ( ( info.m_nCloakColorTint != -1 ) && ( !params[info.m_nCloakColorTint]->IsDefined() ) ) + { + params[info.m_nCloakColorTint]->SetVecValue( kDefaultCloakColorTint[0], kDefaultCloakColorTint[1], kDefaultCloakColorTint[2], kDefaultCloakColorTint[3] ); + } +} + +void InitCloakBlendedPass( CBaseVSShader *pShader, IMaterialVar** params, CloakBlendedPassVars_t &info ) +{ + // No textures +} + +void DrawCloakBlendedPass( CBaseVSShader *pShader, IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, + IShaderShadow* pShaderShadow, CloakBlendedPassVars_t &info, VertexCompressionType_t vertexCompression ) +{ + SHADOW_STATE + { + // Reset shadow state manually since we're drawing from two materials + pShader->SetInitialShadowState( ); + + // Set stream format (note that this shader supports compression) + unsigned int flags = VERTEX_POSITION | VERTEX_NORMAL | VERTEX_FORMAT_COMPRESSED; + int nTexCoordCount = 1; + int userDataSize = 0; + pShaderShadow->VertexShaderVertexFormat( flags, nTexCoordCount, NULL, userDataSize ); + + // Vertex Shader + cloak_blended_pass_dx8_vs11_Static_Index vshIndex; + pShaderShadow->SetVertexShader( "cloak_blended_pass_dx8_vs11", vshIndex.GetIndex() ); + + // Pixel Shader + pShaderShadow->SetPixelShader( "cloak_blended_pass_dx8_ps11", 0 ); + + // Textures + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); // Renderable texture for refraction + + // Blending + pShader->EnableAlphaBlending( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA ); + pShaderShadow->EnableAlphaWrites( false ); + + // !!! We need to turn this back on because EnableAlphaBlending() above disables it! + pShaderShadow->EnableDepthWrites( true ); + } + DYNAMIC_STATE + { + // Reset render state manually since we're drawing from two materials + pShaderAPI->SetDefaultState(); + + // Set Vertex Shader Combos + cloak_blended_pass_dx8_vs11_Dynamic_Index vshIndex; + vshIndex.SetSKINNING( pShaderAPI->GetCurrentNumBones() > 0 ); + pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() ); + + // Set Vertex Shader Constants + float vVsConst3[4] = { 1.35f, 0.0f, 0.4f, ( 1.0f / ( 0.425f - 0.4f ) ) }; + vVsConst3[1] = clamp( IS_PARAM_DEFINED( info.m_nCloakFactor ) ? params[info.m_nCloakFactor]->GetFloatValue() : kDefaultCloakFactor, 0.0f, 1.0f ); + + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_3, vVsConst3 ); + + float vVsConst4[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; + vVsConst4[0] = params[info.m_nRefractAmount]->GetFloatValue() * ( 1.0f - clamp( params[info.m_nCloakFactor]->GetFloatValue(), 0.0f, 1.0f ) ); + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_4, vVsConst4 ); + + float vVsConst5[4] = { 1.0f, 1.0f, 0.0f, 0.0f }; + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_5, vVsConst5, 1 ); + + // Bind textures + pShaderAPI->BindStandardTexture( SHADER_SAMPLER0, TEXTURE_FRAME_BUFFER_FULL_TEXTURE_0 ); // Refraction Map + + // Set Pixel Shader Constants + + // Refract color tint + float vPsConst0[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; + float fColorTintStrength = clamp( ( clamp( IS_PARAM_DEFINED( info.m_nCloakFactor ) ? params[info.m_nCloakFactor]->GetFloatValue() : kDefaultCloakFactor, 0.0f, 1.0f ) - 0.75f ) * 4.0f, 0.0f, 1.0f ); + vPsConst0[0] = IS_PARAM_DEFINED( info.m_nCloakColorTint ) ? params[info.m_nCloakColorTint]->GetVecValue()[0] : kDefaultCloakColorTint[0]; + vPsConst0[1] = IS_PARAM_DEFINED( info.m_nCloakColorTint ) ? params[info.m_nCloakColorTint]->GetVecValue()[1] : kDefaultCloakColorTint[1]; + vPsConst0[2] = IS_PARAM_DEFINED( info.m_nCloakColorTint ) ? params[info.m_nCloakColorTint]->GetVecValue()[2] : kDefaultCloakColorTint[2]; + + vPsConst0[0] = SrgbLinearToGamma( vPsConst0[0] ); + vPsConst0[1] = SrgbLinearToGamma( vPsConst0[1] ); + vPsConst0[2] = SrgbLinearToGamma( vPsConst0[2] ); + + vPsConst0[0] = ( vPsConst0[0] * ( 1.0f - fColorTintStrength ) ) + ( fColorTintStrength ); + vPsConst0[1] = ( vPsConst0[1] * ( 1.0f - fColorTintStrength ) ) + ( fColorTintStrength ); + vPsConst0[2] = ( vPsConst0[2] * ( 1.0f - fColorTintStrength ) ) + ( fColorTintStrength ); + + pShaderAPI->SetPixelShaderConstant( 0, vPsConst0, 1 ); + } + pShader->Draw(); +} + +bool CloakBlendedPassIsFullyOpaque ( IMaterialVar** params, CloakBlendedPassVars_t &info ) +{ + float flCloakFactor = IS_PARAM_DEFINED( info.m_nCloakFactor ) ? params[info.m_nCloakFactor]->GetFloatValue() : kDefaultCloakFactor; + //float flRefractAmount = IS_PARAM_DEFINED( info.m_nRefractAmount ) ? params[info.m_nRefractAmount]->GetFloatValue() : kDefaultRefractAmount; + + // NOTE: If this math changes, you need to update the pixel shader code! + float flFresnel = 1.0f - ( 0.0f ); // Assume V.N = 0.0f; + float flCloakLerpFactor = clamp( Lerp( clamp( flCloakFactor, 0.0f, 1.0f ), 1.0f, flFresnel - 1.35f ), 0.0f, 1.0f ); + //flCloakLerpFactor = 1.0f - smoothstep( 0.4f, 0.425f, flCloakLerpFactor ); + + if ( flCloakLerpFactor <= 0.4f ) + return true; + + return false; +} diff --git a/materialsystem/stdshaders/cloak_blended_pass_dx8_ps11.psh b/materialsystem/stdshaders/cloak_blended_pass_dx8_ps11.psh new file mode 100644 index 0000000..b4dc5d1 --- /dev/null +++ b/materialsystem/stdshaders/cloak_blended_pass_dx8_ps11.psh @@ -0,0 +1,12 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; c0 refract color tint +; c5 1, 1, 0, 0 +;------------------------------------------------------------------------------ +def c1, 1, 1, 1, 1 + +tex t0 ; Base color + +mul r0.rgb, t0, c0 +mov r0.a, v0.a diff --git a/materialsystem/stdshaders/cloak_blended_pass_dx8_vs11.vsh b/materialsystem/stdshaders/cloak_blended_pass_dx8_vs11.vsh new file mode 100644 index 0000000..6333357 --- /dev/null +++ b/materialsystem/stdshaders/cloak_blended_pass_dx8_vs11.vsh @@ -0,0 +1,104 @@ +# DYNAMIC: "SKINNING" "0..1" + +vs.1.1 +#include "macros.vsh" + +;------------------------------------------------------------------------------ +; Vertex blending +;------------------------------------------------------------------------------ +&AllocateRegister( \$worldPos ); +&AllocateRegister( \$worldNormal ); +&AllocateRegister( \$projPos ); + +&SkinPositionAndNormal( $worldPos, $worldNormal ); + +if( $SKINNING == 1 ) +{ + &Normalize( $worldNormal ); +} + +;------------------------------------------------------------------------------ +; Transform the position from world to view space +;------------------------------------------------------------------------------ +dp4 $projPos.x, $worldPos, $cViewProj0 +dp4 $projPos.y, $worldPos, $cViewProj1 +dp4 $projPos.z, $worldPos, $cViewProj2 +dp4 $projPos.w, $worldPos, $cViewProj3 + +mov oPos, $projPos + +;------------------------------------------------------------------------------ +; Fog - don't bother with water fog for intro effects +;------------------------------------------------------------------------------ +&DepthFog( $projPos, "oFog" ); + +;------------------------------------------------------------------------------ +; Refract uv's (Code copied from predator.vsh) +;------------------------------------------------------------------------------ +; NOTE: projPos isn't projPos after this point. :) + +&AllocateRegister( \$projNormal ); + +; only do X and Y since that's all we care about +dp3 $projNormal.x, $worldNormal, $cViewProj0 +dp3 $projNormal.y, $worldNormal, $cViewProj1 + +; divide by z +rcp $projPos.w, $projPos.w +mul $projPos.xy, $projPos.w, $projPos.xy + +; map from -1..1 to 0..1 +mad $projPos.xy, $projPos.xy, $cHalf, $cHalf + +; tweak with the texcoords based on the normal and $refractionamount +mad $projPos.xy, $projNormal.xy, -$SHADER_SPECIFIC_CONST_4.xy, $projPos.xy ; FIXME + +; invert y +add $projPos.y, $cOne, -$projPos.y + +; hack scale for nvidia (Power of two texcoords are screwed.) +mul oT0.xy, $projPos.xy, $SHADER_SPECIFIC_CONST_5.xy + +; YUCK! This is to make texcoords continuous for mat_softwaretl +mov oT2, $cZero + +&FreeRegister( \$projPos ); +&FreeRegister( \$projNormal ); + +;------------------------------------------------------------------------------ +; Refract mask +;------------------------------------------------------------------------------ + +; // float flFresnel = 1.0f - saturate( dot( i.vWorldNormal.xyz, normalize( -i.vWorldViewVector.xyz ) ) ); +&AllocateRegister( \$flFresnel ); +&AllocateRegister( \$tmp1 ); + +sub $flFresnel, $worldPos, $cEyePos +&Normalize( $flFresnel ); +dp3 $flFresnel, -$flFresnel, $worldNormal +max $flFresnel, $flFresnel, $cZero +sub $flFresnel, $cOne, $flFresnel + +; // float flCloakLerpFactor = saturate( lerp( 1.0f, flFresnel - 1.35f, saturate( g_flCloakFactor ) ) ); +&AllocateRegister( \$flCloakLerpFactor ); + +sub $flCloakLerpFactor, $flFresnel, $SHADER_SPECIFIC_CONST_3.x ; // flFresnel - 1.35f +mov $tmp1, $cOne +sub $flCloakLerpFactor, $flCloakLerpFactor, $tmp1 +mad $flCloakLerpFactor, $flCloakLerpFactor, $SHADER_SPECIFIC_CONST_3.y, $tmp1 +max $flCloakLerpFactor, $flCloakLerpFactor, $cZero +min $flCloakLerpFactor, $flCloakLerpFactor, $cOne + +; // flCloakLerpFactor = 1.0f - smoothstep( 0.4f, 0.425f, flCloakLerpFactor ); +sub $flCloakLerpFactor, $flCloakLerpFactor, $SHADER_SPECIFIC_CONST_3.z +mul $flCloakLerpFactor, $flCloakLerpFactor, $SHADER_SPECIFIC_CONST_3.w +sub $flCloakLerpFactor, $cOne, $flCloakLerpFactor + +mov oD0, $flCloakLerpFactor + +&FreeRegister( \$tmp1 ); +&FreeRegister( \$flFresnel ); +&FreeRegister( \$flCloakLerpFactor ); + +&FreeRegister( \$worldPos ); +&FreeRegister( \$worldNormal ); diff --git a/materialsystem/stdshaders/cloak_blended_pass_helper.cpp b/materialsystem/stdshaders/cloak_blended_pass_helper.cpp new file mode 100644 index 0000000..6fe9e58 --- /dev/null +++ b/materialsystem/stdshaders/cloak_blended_pass_helper.cpp @@ -0,0 +1,358 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// + +/* Example how to plug this into an existing shader: + + In the VMT: + // Cloak Pass + "$cloakPassEnabled" "1" + + #include "cloak_blended_pass_helper.h" + + In BEGIN_SHADER_PARAMS: + // Cloak Pass + SHADER_PARAM( CLOAKPASSENABLED, SHADER_PARAM_TYPE_BOOL, "0", "Enables cloak render in a second pass" ) + SHADER_PARAM( CLOAKFACTOR, SHADER_PARAM_TYPE_FLOAT, "0.0", "" ) + SHADER_PARAM( CLOAKCOLORTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "Cloak color tint" ) + SHADER_PARAM( REFRACTAMOUNT, SHADER_PARAM_TYPE_FLOAT, "2", "" ) + + // This should already exist + //SHADER_PARAM( BUMPMAP, SHADER_PARAM_TYPE_TEXTURE, "models/shadertest/shader1_normal", "bump map" ) + //SHADER_PARAM( BUMPFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $bumpmap" ) + //SHADER_PARAM( BUMPTRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$bumpmap texcoord transform" ) + + Add this above SHADER_INIT_PARAMS() + // Cloak Pass + void SetupVarsCloakBlendedPass( CloakBlendedPassVars_t &info ) + { + info.m_nCloakFactor = CLOAKFACTOR; + info.m_nCloakColorTint = CLOAKCOLORTINT; + info.m_nRefractAmount = REFRACTAMOUNT; + + // Delete these lines if not bump mapping! + info.m_nBumpmap = BUMPMAP; + info.m_nBumpFrame = BUMPFRAME; + info.m_nBumpTransform = BUMPTRANSFORM; + } + + bool NeedsPowerOfTwoFrameBufferTexture( IMaterialVar **params, bool bCheckSpecificToThisFrame ) const + { + if ( params[CLOAKPASSENABLED]->GetIntValue() ) // If material supports cloaking + { + if ( bCheckSpecificToThisFrame == false ) // For setting model flag at load time + return true; + else if ( ( params[CLOAKFACTOR]->GetFloatValue() > 0.0f ) && ( params[CLOAKFACTOR]->GetFloatValue() < 1.0f ) ) // Per-frame check + return true; + // else, not cloaking this frame, so check flag2 in case the base material still needs it + } + + // Check flag2 if not drawing cloak pass + return IS_FLAG2_SET( MATERIAL_VAR2_NEEDS_POWER_OF_TWO_FRAME_BUFFER_TEXTURE ); + } + + bool IsTranslucent( IMaterialVar **params ) const + { + if ( params[CLOAKPASSENABLED]->GetIntValue() ) // If material supports cloaking + { + if ( ( params[CLOAKFACTOR]->GetFloatValue() > 0.0f ) && ( params[CLOAKFACTOR]->GetFloatValue() < 1.0f ) ) // Per-frame check + return true; + // else, not cloaking this frame, so check flag in case the base material still needs it + } + + // Check flag if not drawing cloak pass + return IS_FLAG_SET( MATERIAL_VAR_TRANSLUCENT ); + } + + In SHADER_INIT_PARAMS() + // Cloak Pass + if ( !params[CLOAKPASSENABLED]->IsDefined() ) + { + params[CLOAKPASSENABLED]->SetIntValue( 0 ); + } + else if ( params[CLOAKPASSENABLED]->GetIntValue() ) + { + CloakBlendedPassVars_t info; + SetupVarsCloakBlendedPass( info ); + InitParamsCloakBlendedPass( this, params, pMaterialName, info ); + } + + In SHADER_INIT + // Cloak Pass + if ( params[CLOAKPASSENABLED]->GetIntValue() ) + { + CloakBlendedPassVars_t info; + SetupVarsCloakBlendedPass( info ); + InitCloakBlendedPass( this, params, info ); + } + + Modify SHADER_DRAW to look something like this: + // Skip the standard rendering if cloak pass is fully opaque + bool bDrawStandardPass = true; + if ( params[CLOAKPASSENABLED]->GetIntValue() && ( pShaderShadow == NULL ) ) // && not snapshotting + { + CloakBlendedPassVars_t info; + SetupVarsCloakBlendedPass( info ); + if ( CloakBlendedPassIsFullyOpaque( params, info ) ) + { + bDrawStandardPass = false; + } + } + + // Standard rendering pass + if ( bDrawStandardPass ) + { + Eye_Refract_Vars_t info; + SetupVarsEyeRefract( info ); + Draw_Eyes_Refract( this, params, pShaderAPI, pShaderShadow, info ); + } + else + { + // Skip this pass! + Draw( false ); + } + + // Cloak Pass + if ( params[CLOAKPASSENABLED]->GetIntValue() ) + { + // If ( snapshotting ) or ( we need to draw this frame ) + if ( ( pShaderShadow != NULL ) || ( ( params[CLOAKFACTOR]->GetFloatValue() > 0.0f ) && ( params[CLOAKFACTOR]->GetFloatValue() < 1.0f ) ) ) + { + CloakBlendedPassVars_t info; + SetupVarsCloakBlendedPass( info ); + DrawCloakBlendedPass( this, params, pShaderAPI, pShaderShadow, info ); + } + else // We're not snapshotting and we don't need to draw this frame + { + // Skip this pass! + Draw( false ); + } + } + +==================================================================================================== */ + +#include "BaseVSShader.h" +#include "mathlib/vmatrix.h" +#include "cloak_blended_pass_helper.h" +#include "convar.h" + +// Auto generated inc files +#include "cloak_blended_pass_vs20.inc" +#include "cloak_blended_pass_ps20.inc" +#include "cloak_blended_pass_ps20b.inc" + +#ifndef _X360 +#include "cloak_blended_pass_vs30.inc" +#include "cloak_blended_pass_ps30.inc" +#endif + +void InitParamsCloakBlendedPass( CBaseVSShader *pShader, IMaterialVar** params, const char *pMaterialName, CloakBlendedPassVars_t &info ) +{ + // Set material flags + SET_FLAGS2( MATERIAL_VAR2_SUPPORTS_HW_SKINNING ); + SET_FLAGS( MATERIAL_VAR_MODEL ); + SET_FLAGS2( MATERIAL_VAR2_NEEDS_TANGENT_SPACES ); + + // Set material parameter default values + if ( ( info.m_nCloakFactor != -1 ) && ( !params[info.m_nCloakFactor]->IsDefined() ) ) + { + params[info.m_nCloakFactor]->SetFloatValue( kDefaultCloakFactor ); + } + + if ( ( info.m_nRefractAmount != -1 ) && ( !params[info.m_nRefractAmount]->IsDefined() ) ) + { + params[info.m_nRefractAmount]->SetFloatValue( kDefaultRefractAmount ); + } + + if ( ( info.m_nCloakColorTint != -1 ) && ( !params[info.m_nCloakColorTint]->IsDefined() ) ) + { + params[info.m_nCloakColorTint]->SetVecValue( kDefaultCloakColorTint[0], kDefaultCloakColorTint[1], kDefaultCloakColorTint[2], kDefaultCloakColorTint[3] ); + } + + if( (info.m_nBumpFrame != -1 ) && !params[info.m_nBumpFrame]->IsDefined() ) + { + params[info.m_nBumpFrame]->SetIntValue( 0 ); + } +} + +void InitCloakBlendedPass( CBaseVSShader *pShader, IMaterialVar** params, CloakBlendedPassVars_t &info ) +{ + // Load textures + if ( g_pConfig->UseBumpmapping() ) + { + if ( (info.m_nBumpmap != -1) && params[info.m_nBumpmap]->IsDefined() ) + { + pShader->LoadTexture( info.m_nBumpmap ); + } + } +} + +void DrawCloakBlendedPass( CBaseVSShader *pShader, IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, + IShaderShadow* pShaderShadow, CloakBlendedPassVars_t &info, VertexCompressionType_t vertexCompression ) +{ + bool bBumpMapping = ( !g_pConfig->UseBumpmapping() ) || ( info.m_nBumpmap == -1 ) || !params[info.m_nBumpmap]->IsTexture() ? 0 : 1; + + SHADOW_STATE + { + // Reset shadow state manually since we're drawing from two materials + pShader->SetInitialShadowState( ); + + // Set stream format (note that this shader supports compression) + unsigned int flags = VERTEX_POSITION | VERTEX_NORMAL | VERTEX_FORMAT_COMPRESSED; + int nTexCoordCount = 1; + int userDataSize = 0; + pShaderShadow->VertexShaderVertexFormat( flags, nTexCoordCount, NULL, userDataSize ); + +#ifndef _X360 + if ( !g_pHardwareConfig->HasFastVertexTextures() ) +#endif + { + // Vertex Shader + DECLARE_STATIC_VERTEX_SHADER( cloak_blended_pass_vs20 ); + SET_STATIC_VERTEX_SHADER_COMBO( BUMPMAP, bBumpMapping ? 1 : 0 ); + SET_STATIC_VERTEX_SHADER( cloak_blended_pass_vs20 ); + + // Pixel Shader + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_STATIC_PIXEL_SHADER( cloak_blended_pass_ps20b ); + SET_STATIC_PIXEL_SHADER_COMBO( BUMPMAP, bBumpMapping ? 1 : 0 ); + SET_STATIC_PIXEL_SHADER( cloak_blended_pass_ps20b ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( cloak_blended_pass_ps20 ); + SET_STATIC_PIXEL_SHADER_COMBO( BUMPMAP, bBumpMapping ? 1 : 0 ); + SET_STATIC_PIXEL_SHADER( cloak_blended_pass_ps20 ); + } + } +#ifndef _X360 + else + { + // The vertex shader uses the vertex id stream + SET_FLAGS2( MATERIAL_VAR2_USES_VERTEXID ); + + // Vertex Shader + DECLARE_STATIC_VERTEX_SHADER( cloak_blended_pass_vs30 ); + SET_STATIC_VERTEX_SHADER_COMBO( BUMPMAP, bBumpMapping ? 1 : 0 ); + SET_STATIC_VERTEX_SHADER( cloak_blended_pass_vs30 ); + + // Pixel Shader + DECLARE_STATIC_PIXEL_SHADER( cloak_blended_pass_ps30 ); + SET_STATIC_PIXEL_SHADER_COMBO( BUMPMAP, bBumpMapping ? 1 : 0 ); + SET_STATIC_PIXEL_SHADER( cloak_blended_pass_ps30 ); + } +#endif + + // Textures + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); // Refraction texture + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, true ); + if ( bBumpMapping ) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); // Bump + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER1, false ); // Not sRGB + } + pShaderShadow->EnableSRGBWrite( true ); + + // Blending + pShader->EnableAlphaBlending( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA ); + pShaderShadow->EnableAlphaWrites( false ); + + // !!! We need to turn this back on because EnableAlphaBlending() above disables it! + pShaderShadow->EnableDepthWrites( true ); + } + DYNAMIC_STATE + { + // Reset render state manually since we're drawing from two materials + pShaderAPI->SetDefaultState(); + + // Set Vertex Shader Constants + if ( ( bBumpMapping ) && ( info.m_nBumpTransform != -1 ) ) + { + pShader->SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, info.m_nBumpTransform ); + } + +#ifndef _X360 + if ( !g_pHardwareConfig->HasFastVertexTextures() ) +#endif + { + // Set Vertex Shader Combos + DECLARE_DYNAMIC_VERTEX_SHADER( cloak_blended_pass_vs20 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, pShaderAPI->GetCurrentNumBones() > 0 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression ); + SET_DYNAMIC_VERTEX_SHADER( cloak_blended_pass_vs20 ); + + // Set Pixel Shader Combos + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_DYNAMIC_PIXEL_SHADER( cloak_blended_pass_ps20b ); + SET_DYNAMIC_PIXEL_SHADER( cloak_blended_pass_ps20b ); + } + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( cloak_blended_pass_ps20 ); + SET_DYNAMIC_PIXEL_SHADER( cloak_blended_pass_ps20 ); + } + } +#ifndef _X360 + else + { + pShader->SetHWMorphVertexShaderState( VERTEX_SHADER_SHADER_SPECIFIC_CONST_6, VERTEX_SHADER_SHADER_SPECIFIC_CONST_7, SHADER_VERTEXTEXTURE_SAMPLER0 ); + + // Set Vertex Shader Combos + DECLARE_DYNAMIC_VERTEX_SHADER( cloak_blended_pass_vs30 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, pShaderAPI->GetCurrentNumBones() > 0 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( MORPHING, pShaderAPI->IsHWMorphingEnabled() ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression ); + SET_DYNAMIC_VERTEX_SHADER( cloak_blended_pass_vs30 ); + + // Set Pixel Shader Combos + DECLARE_DYNAMIC_PIXEL_SHADER( cloak_blended_pass_ps30 ); + SET_DYNAMIC_PIXEL_SHADER( cloak_blended_pass_ps30 ); + } +#endif + + // Bind textures + pShaderAPI->BindStandardTexture( SHADER_SAMPLER0, TEXTURE_FRAME_BUFFER_FULL_TEXTURE_0 ); // Refraction Map + if ( bBumpMapping ) + { + pShader->BindTexture( SHADER_SAMPLER1, info.m_nBumpmap, info.m_nBumpFrame ); + } + + // Set Pixel Shader Constants + float vEyePos[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; + pShaderAPI->GetWorldSpaceCameraPosition( vEyePos ); + pShaderAPI->SetPixelShaderConstant( 5, vEyePos, 1 ); + + float vPackedConst1[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; + vPackedConst1[0] = IS_PARAM_DEFINED( info.m_nCloakFactor ) ? params[info.m_nCloakFactor]->GetFloatValue() : kDefaultCloakFactor; + vPackedConst1[1] = IS_PARAM_DEFINED( info.m_nRefractAmount ) ? params[info.m_nRefractAmount]->GetFloatValue() : kDefaultRefractAmount; + pShaderAPI->SetPixelShaderConstant( 6, vPackedConst1, 1 ); + + // Refract color tint + pShaderAPI->SetPixelShaderConstant( 7, IS_PARAM_DEFINED( info.m_nCloakColorTint ) ? params[info.m_nCloakColorTint]->GetVecValue() : kDefaultCloakColorTint, 1 ); + + // Set c0 and c1 to contain first two rows of ViewProj matrix + VMatrix mView, mProj; + pShaderAPI->GetMatrix( MATERIAL_VIEW, mView.m[0] ); + pShaderAPI->GetMatrix( MATERIAL_PROJECTION, mProj.m[0] ); + VMatrix mViewProj = mView * mProj; + mViewProj = mViewProj.Transpose3x3(); + pShaderAPI->SetPixelShaderConstant( 0, mViewProj.m[0], 2 ); + } + pShader->Draw(); +} + +bool CloakBlendedPassIsFullyOpaque ( IMaterialVar** params, CloakBlendedPassVars_t &info ) +{ + float flCloakFactor = IS_PARAM_DEFINED( info.m_nCloakFactor ) ? params[info.m_nCloakFactor]->GetFloatValue() : kDefaultCloakFactor; + //float flRefractAmount = IS_PARAM_DEFINED( info.m_nRefractAmount ) ? params[info.m_nRefractAmount]->GetFloatValue() : kDefaultRefractAmount; + + // NOTE: If this math changes, you need to update the pixel shader code! + float flFresnel = 1.0f - ( 0.0f ); // Assume V.N = 0.0f; + float flCloakLerpFactor = clamp( Lerp( clamp( flCloakFactor, 0.0f, 1.0f ), 1.0f, flFresnel - 1.35f ), 0.0f, 1.0f ); + //flCloakLerpFactor = 1.0f - smoothstep( 0.4f, 0.425f, flCloakLerpFactor ); + + if ( flCloakLerpFactor <= 0.4f ) + return true; + + return false; +} diff --git a/materialsystem/stdshaders/cloak_blended_pass_helper.h b/materialsystem/stdshaders/cloak_blended_pass_helper.h new file mode 100644 index 0000000..2b60703 --- /dev/null +++ b/materialsystem/stdshaders/cloak_blended_pass_helper.h @@ -0,0 +1,46 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// + +#ifndef CLOAK_BLENDED_PASS_HELPER_H +#define CLOAK_BLENDED_PASS_HELPER_H +#ifdef _WIN32 +#pragma once +#endif + +#include + +//----------------------------------------------------------------------------- +// Forward declarations +//----------------------------------------------------------------------------- +class CBaseVSShader; +class IMaterialVar; +class IShaderDynamicAPI; +class IShaderShadow; + +//----------------------------------------------------------------------------- +// Init params/ init/ draw methods +//----------------------------------------------------------------------------- +struct CloakBlendedPassVars_t +{ + CloakBlendedPassVars_t() { memset( this, 0xFF, sizeof(CloakBlendedPassVars_t) ); } + + int m_nCloakFactor; + int m_nCloakColorTint; + int m_nRefractAmount; + + int m_nBumpmap; + int m_nBumpFrame; + int m_nBumpTransform; +}; + +// Default values (Arrays should only be vec[4]) +static const float kDefaultCloakFactor = 0.0f; +static const float kDefaultCloakColorTint[4] = { 1.0f, 1.0f, 1.0f, 1.0f }; +static const float kDefaultRefractAmount = 0.1f; + +void InitParamsCloakBlendedPass( CBaseVSShader *pShader, IMaterialVar** params, const char *pMaterialName, CloakBlendedPassVars_t &info ); +void InitCloakBlendedPass( CBaseVSShader *pShader, IMaterialVar** params, CloakBlendedPassVars_t &info ); +void DrawCloakBlendedPass( CBaseVSShader *pShader, IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, + IShaderShadow* pShaderShadow, CloakBlendedPassVars_t &info, VertexCompressionType_t vertexCompression ); +bool CloakBlendedPassIsFullyOpaque ( IMaterialVar** params, CloakBlendedPassVars_t &info ); + +#endif // CLOAK_BLENDED_PASS_HELPER_H diff --git a/materialsystem/stdshaders/cloak_blended_pass_ps2x.fxc b/materialsystem/stdshaders/cloak_blended_pass_ps2x.fxc new file mode 100644 index 0000000..bf69b80 --- /dev/null +++ b/materialsystem/stdshaders/cloak_blended_pass_ps2x.fxc @@ -0,0 +1,106 @@ +//========= Copyright © 1996-2006, Valve Corporation, All rights reserved. ============// + +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps30][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX] +// STATIC: "BUMPMAP" "0..1" + +// Includes ======================================================================================= +#include "common_vertexlitgeneric_dx9.h" + +// Texture Samplers =============================================================================== +sampler g_tRefractionSampler : register( s0 ); +#if BUMPMAP + sampler g_tBumpSampler : register( s1 ); +#endif + +// Shaders Constants and Globals ================================================================== +const float4 g_mViewProj0 : register( c0 ); // 1st row of matrix +const float4 g_mViewProj1 : register( c1 ); // 2nd row of matrix + +const float4 g_vCameraPosition : register( c5 ); +const float4 g_vPackedConst6 : register( c6 ); +#define g_flCloakFactor g_vPackedConst6.x // Default = 1.0f +#define g_flRefractAmount g_vPackedConst6.y // Default = 1.0f + +const float4 g_cCloakColorTint : register( c7 ); + +// 8 2D Poisson offsets (designed to use .xy and .wz swizzles (not .zw) +static const float4 g_vPoissonOffset[4] = { float4 (-0.0876f, 0.9703f, 0.5651f, 0.4802f ), + float4 ( 0.1851f, 0.1580f, -0.0617f, -0.2616f ), + float4 (-0.5477f, -0.6603f, 0.0711f, -0.5325f ), + float4 (-0.0751f, -0.8954f, 0.4054f, 0.6384f ) }; + +// Interpolated values ============================================================================ +struct PS_INPUT +{ + float3 vWorldNormal : TEXCOORD0; // World-space normal + float3 vProjPosForRefract : TEXCOORD1; + float3 vWorldViewVector : TEXCOORD2; + #if BUMPMAP + float3x3 mTangentSpaceTranspose : TEXCOORD3; + // second row : TEXCOORD4; + // third row : TEXCOORD5; + float2 vTexCoord0 : TEXCOORD6; + #endif +}; + +// Main =========================================================================================== +float4 main( PS_INPUT i ) : COLOR +{ + float3 vWorldNormal = normalize( i.vWorldNormal.xyz ); + + #if BUMPMAP + float4 vBumpTexel = tex2D( g_tBumpSampler, i.vTexCoord0.xy ); + float3 vTangentNormal = ( 2.0f * vBumpTexel ) - 1.0f; + vWorldNormal.xyz = mul( i.mTangentSpaceTranspose, vTangentNormal.xyz ); + #endif + + // Transform world space normal into clip space and project + float3 vProjNormal; + vProjNormal.x = dot( vWorldNormal.xyz, g_mViewProj0.xyz ); // 1st row + vProjNormal.y = dot( vWorldNormal.xyz, g_mViewProj1.xyz ); // 2nd row + + // Compute coordinates for sampling refraction + float2 vRefractTexCoordNoWarp = i.vProjPosForRefract.xy / i.vProjPosForRefract.z; + float2 vRefractTexCoord = vProjNormal.xy; + float scale = lerp( g_flRefractAmount, 0.0f, saturate( g_flCloakFactor ) ); + vRefractTexCoord.xy *= scale; + vRefractTexCoord.xy += vRefractTexCoordNoWarp.xy; + + // Blur by scalable Poisson filter + float flBlurAmount = lerp( 0.05f, 0.0f, saturate( g_flCloakFactor ) ); + float3 cRefract = tex2D( g_tRefractionSampler, vRefractTexCoord.xy ); + cRefract += tex2D( g_tRefractionSampler, vRefractTexCoord.xy + ( g_vPoissonOffset[0].xy * flBlurAmount ) ); + cRefract += tex2D( g_tRefractionSampler, vRefractTexCoord.xy + ( g_vPoissonOffset[0].wz * flBlurAmount ) ); + cRefract += tex2D( g_tRefractionSampler, vRefractTexCoord.xy + ( g_vPoissonOffset[1].xy * flBlurAmount ) ); + cRefract += tex2D( g_tRefractionSampler, vRefractTexCoord.xy + ( g_vPoissonOffset[1].wz * flBlurAmount ) ); + cRefract += tex2D( g_tRefractionSampler, vRefractTexCoord.xy + ( g_vPoissonOffset[2].xy * flBlurAmount ) ); + cRefract += tex2D( g_tRefractionSampler, vRefractTexCoord.xy + ( g_vPoissonOffset[2].wz * flBlurAmount ) ); + cRefract += tex2D( g_tRefractionSampler, vRefractTexCoord.xy + ( g_vPoissonOffset[3].xy * flBlurAmount ) ); + cRefract += tex2D( g_tRefractionSampler, vRefractTexCoord.xy + ( g_vPoissonOffset[3].wz * flBlurAmount ) ); + cRefract /= 9.0f; + + // 1-(N.V) for Fresnel term (NOTE: If this math changes, you need to update the C code that mimics this on the CPU) + float flFresnel = 1.0f - saturate( dot( i.vWorldNormal.xyz, normalize( -i.vWorldViewVector.xyz ) ) ); + float flCloakLerpFactor = saturate( lerp( 1.0f, flFresnel - 1.35f, saturate( g_flCloakFactor ) ) ); + flCloakLerpFactor = 1.0f - smoothstep( 0.4f, 0.425f, flCloakLerpFactor ); + + // Slightly dim the facing pixels and brighten the silhouette pixels + cRefract.rgb *= lerp( flFresnel * 0.4 + 0.8, 1.0f, saturate( g_flCloakFactor ) * saturate( g_flCloakFactor ) ); // This gives a scalar in the range [0.8 1.2] + + // Refract color tint + float fColorTintStrength = saturate( ( saturate( g_flCloakFactor ) - 0.75f ) * 4.0f ); + cRefract.rgb *= lerp( g_cCloakColorTint, 1.0f, fColorTintStrength ); + + //===============// + // Combine terms // + //===============// + float4 result; + result.rgb = cRefract.rgb; + + // Set alpha to cloak mask + result.a = flCloakLerpFactor; + + return FinalOutput( result, 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE ); +} diff --git a/materialsystem/stdshaders/cloak_blended_pass_vs20.fxc b/materialsystem/stdshaders/cloak_blended_pass_vs20.fxc new file mode 100644 index 0000000..dff4054 --- /dev/null +++ b/materialsystem/stdshaders/cloak_blended_pass_vs20.fxc @@ -0,0 +1,132 @@ +//========= Copyright © 1996-2006, Valve Corporation, All rights reserved. ============// + +// STATIC: "BUMPMAP" "0..1" + +// DYNAMIC: "COMPRESSED_VERTS" "0..1" +// DYNAMIC: "SKINNING" "0..1" +// DYNAMIC: "MORPHING" "0..1" [vs30] + +// Includes +#include "common_vs_fxc.h" + +// Globals +static const bool g_bSkinning = SKINNING ? true : false; +const float4 cBaseTexCoordTransform[2] : register( SHADER_SPECIFIC_CONST_0 ); + +#ifdef SHADER_MODEL_VS_3_0 +// NOTE: cMorphTargetTextureDim.xy = target dimensions, +// cMorphTargetTextureDim.z = 4tuples/morph +const float3 cMorphTargetTextureDim : register( SHADER_SPECIFIC_CONST_6 ); +const float4 cMorphSubrect : register( SHADER_SPECIFIC_CONST_7 ); + +sampler2D morphSampler : register( D3DVERTEXTEXTURESAMPLER0, s0 ); +#endif + +// Structs +struct VS_INPUT +{ + float4 vPos : POSITION; // Position + float4 vNormal : NORMAL; // Normal + float4 vBoneWeights : BLENDWEIGHT; // Skin weights + float4 vBoneIndices : BLENDINDICES; // Skin indices + float4 vTexCoord0 : TEXCOORD0; // Base texture coordinates + + #if BUMPMAP + float4 vTangent : TANGENT; + #endif + + // Position and normal/tangent deltas + float3 vPosFlex : POSITION1; + float3 vNormalFlex : NORMAL1; + + #ifdef SHADER_MODEL_VS_3_0 + float vVertexID : POSITION2; + #endif +}; + +struct VS_OUTPUT +{ + float4 vProjPosition : POSITION; // Projection-space position + float3 vWorldNormal : TEXCOORD0; // World-space normal + float3 vProjPosForRefract : TEXCOORD1; + float3 vWorldViewVector : TEXCOORD2; + + #if BUMPMAP + float3x3 mTangentSpaceTranspose : TEXCOORD3; + // second row : TEXCOORD4; + // third row : TEXCOORD5; + float2 vTexCoord0 : TEXCOORD6; + #endif +}; + +// Main +VS_OUTPUT main( const VS_INPUT i ) +{ + VS_OUTPUT o; + + // Flexes coming in from a separate stream (contribution masked by cFlexScale.x) + float4 vObjPosition = i.vPos; + float3 vObjNormal; + + #if BUMPMAP + float4 vObjTangent; + DecompressVertex_NormalTangent( i.vNormal, i.vTangent, vObjNormal, vObjTangent ); + + #if !defined( SHADER_MODEL_VS_3_0 ) || !MORPHING + ApplyMorph( i.vPosFlex, i.vNormalFlex, vObjPosition.xyz, vObjNormal, vObjTangent.xyz ); + #else + ApplyMorph( morphSampler, cMorphTargetTextureDim, cMorphSubrect, i.vVertexID, float3( 0, 0, 0 ), vObjPosition.xyz, vObjNormal, vObjTangent.xyz ); + #endif + #else // !BUMPMAP + DecompressVertex_Normal( i.vNormal, vObjNormal ); + + #if !defined( SHADER_MODEL_VS_3_0 ) || !MORPHING + ApplyMorph( i.vPosFlex, i.vNormalFlex, vObjPosition.xyz, vObjNormal ); + #else + ApplyMorph( morphSampler, cMorphTargetTextureDim, cMorphSubrect, i.vVertexID, float3( 0, 0, 0 ), + vObjPosition.xyz, vObjNormal ); + #endif + #endif + + // Transform the position + float3 vWorldPosition = { 0.0f, 0.0f, 0.0f }; + float3 vWorldNormal = { 0.0f, 0.0f, 0.0f }; + #if BUMPMAP + float3 vWorldTangent = { 0.0f, 0.0f, 0.0f }; + float3 vWorldBinormal = { 0.0f, 0.0f, 0.0f }; + SkinPositionNormalAndTangentSpace( g_bSkinning, vObjPosition, vObjNormal.xyz, vObjTangent.xyzw, i.vBoneWeights, i.vBoneIndices, vWorldPosition, vWorldNormal, vWorldTangent, vWorldBinormal ); + #else + SkinPositionAndNormal( g_bSkinning, vObjPosition, vObjNormal.xyz, i.vBoneWeights, i.vBoneIndices, vWorldPosition, vWorldNormal ); + #endif + o.vWorldNormal.xyz = normalize( vWorldNormal.xyz ); + + // Transform into projection space + float4 vProjPosition = mul( float4( vWorldPosition, 1.0f ), cViewProj ); + o.vProjPosition = vProjPosition; + + // Map projected position to the refraction texture + float2 vRefractPos; + vRefractPos.x = vProjPosition.x; + vRefractPos.y = -vProjPosition.y; // Invert Y + vRefractPos = (vRefractPos + vProjPosition.w) * 0.5f; + o.vProjPosForRefract.xyz = float3(vRefractPos.x, vRefractPos.y, vProjPosition.w); + + // View vector + float3 vWorldViewVector = normalize (vWorldPosition.xyz - cEyePos.xyz); + o.vWorldViewVector.xyz = vWorldViewVector.xyz; + + // Tangent space transform + #if BUMPMAP + o.mTangentSpaceTranspose[0] = float3( vWorldTangent.x, vWorldBinormal.x, vWorldNormal.x ); + o.mTangentSpaceTranspose[1] = float3( vWorldTangent.y, vWorldBinormal.y, vWorldNormal.y ); + o.mTangentSpaceTranspose[2] = float3( vWorldTangent.z, vWorldBinormal.z, vWorldNormal.z ); + #endif + + // Texture coordinates + #if BUMPMAP + o.vTexCoord0.x = dot( i.vTexCoord0.xy, cBaseTexCoordTransform[0] ); + o.vTexCoord0.y = dot( i.vTexCoord0.xy, cBaseTexCoordTransform[1] ); + #endif + + return o; +} diff --git a/materialsystem/stdshaders/cloak_dx9_helper.cpp b/materialsystem/stdshaders/cloak_dx9_helper.cpp new file mode 100644 index 0000000..623a0e5 --- /dev/null +++ b/materialsystem/stdshaders/cloak_dx9_helper.cpp @@ -0,0 +1,341 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//===========================================================================// + +#include "BaseVSShader.h" +#include "cloak_dx9_helper.h" +#include "../shaderapidx9/locald3dtypes.h" +#include "convar.h" +#include "cpp_shader_constant_register_map.h" +#include "cloak_vs20.inc" +#include "cloak_ps20.inc" +#include "cloak_ps20b.inc" + +#ifndef _X360 +#include "cloak_vs30.inc" +#include "cloak_ps30.inc" +#endif + +static ConVar r_lightwarpidentity( "r_lightwarpidentity", "0", FCVAR_CHEAT ); + +// FIXME: doesn't support fresnel! +void InitParamsCloak_DX9( CBaseVSShader *pShader, IMaterialVar** params, const char *pMaterialName, Cloak_DX9_Vars_t &info ) +{ + SET_FLAGS2( MATERIAL_VAR2_NEEDS_TANGENT_SPACES ); + SET_FLAGS( MATERIAL_VAR_TRANSLUCENT ); + + SET_FLAGS2( MATERIAL_VAR2_LIGHTING_VERTEX_LIT ); + + if( !params[info.m_nFresnelReflection]->IsDefined() ) + { + params[info.m_nFresnelReflection]->SetFloatValue( 1.0f ); + } + if( !params[info.m_nMasked]->IsDefined() ) + { + params[info.m_nMasked]->SetIntValue( 0 ); + } + SET_FLAGS2( MATERIAL_VAR2_NEEDS_POWER_OF_TWO_FRAME_BUFFER_TEXTURE ); +} + +void InitCloak_DX9( CBaseVSShader *pShader, IMaterialVar** params, Cloak_DX9_Vars_t &info ) +{ + if (params[info.m_nBaseTexture]->IsDefined() ) + { + pShader->LoadTexture( info.m_nBaseTexture, TEXTUREFLAGS_SRGB ); + } + + if (params[info.m_nNormalMap]->IsDefined() ) + { + pShader->LoadBumpMap( info.m_nNormalMap ); + } + + if ( (info.m_nDiffuseWarpTexture != -1) && params[info.m_nDiffuseWarpTexture]->IsDefined() ) + { + pShader->LoadTexture( info.m_nDiffuseWarpTexture ); + } + + SET_FLAGS2( MATERIAL_VAR2_LIGHTING_VERTEX_LIT ); +} + +void DrawCloak_DX9( CBaseVSShader *pShader, IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, + IShaderShadow* pShaderShadow, Cloak_DX9_Vars_t &info, VertexCompressionType_t vertexCompression ) +{ + bool bIsModel = IS_FLAG_SET( MATERIAL_VAR_MODEL ); + bool bMasked = (params[info.m_nMasked]->GetIntValue() != 0); + bool hasDiffuseWarp = (info.m_nDiffuseWarpTexture != -1) && params[info.m_nDiffuseWarpTexture]->IsTexture(); + bool hasPhongExponentTexture = (info.m_nPhongExponentTexture != -1) && params[info.m_nPhongExponentTexture]->IsTexture(); + bool hasPhongTintMap = hasPhongExponentTexture && (info.m_nPhongAlbedoTint != -1) && ( params[info.m_nPhongAlbedoTint]->GetIntValue() != 0 ); + bool bHasRimLight = (info.m_nRimLight != -1) && ( params[info.m_nRimLight]->GetIntValue() != 0 ); + bool bHasRimMaskMap = hasPhongExponentTexture && bHasRimLight && (info.m_nRimMask != -1) && ( params[info.m_nRimMask]->GetIntValue() != 0 ); + + SHADOW_STATE + { + SET_FLAGS2( MATERIAL_VAR2_LIGHTING_VERTEX_LIT ); + + pShader->SetInitialShadowState( ); + + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, true ); // Always SRGB read on base map + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER2, true ); // Refraction map sampler... + + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER2, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER3, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER5, true ); + + pShaderShadow->EnableSRGBWrite( true ); + + unsigned int flags = VERTEX_POSITION | VERTEX_NORMAL; + int nTexCoordCount = 1; + int userDataSize = 0; + if( bIsModel ) + { + userDataSize = 4; + } + else + { + flags |= VERTEX_TANGENT_S | VERTEX_TANGENT_T; + } + + // This shader supports compressed vertices, so OR in that flag: + flags |= VERTEX_FORMAT_COMPRESSED; + + pShaderShadow->VertexShaderVertexFormat( flags, nTexCoordCount, NULL, userDataSize ); + +#ifndef _X360 + if ( !g_pHardwareConfig->HasFastVertexTextures() ) +#endif + { + bool bUseStaticControlFlow = g_pHardwareConfig->SupportsStaticControlFlow(); + + DECLARE_STATIC_VERTEX_SHADER( cloak_vs20 ); + SET_STATIC_VERTEX_SHADER_COMBO( MODEL, bIsModel ); + SET_STATIC_VERTEX_SHADER_COMBO( USE_STATIC_CONTROL_FLOW, bUseStaticControlFlow ); + SET_STATIC_VERTEX_SHADER( cloak_vs20 ); + + // Bind ps_2_b shader so we can get Phong terms + if ( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_STATIC_PIXEL_SHADER( cloak_ps20b ); + SET_STATIC_PIXEL_SHADER_COMBO( LIGHTWARPTEXTURE, hasDiffuseWarp ); + SET_STATIC_PIXEL_SHADER( cloak_ps20b ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( cloak_ps20 ); + SET_STATIC_PIXEL_SHADER_COMBO( LIGHTWARPTEXTURE, hasDiffuseWarp ); + SET_STATIC_PIXEL_SHADER( cloak_ps20 ); + } + } +#ifndef _X360 + else + { + // The vertex shader uses the vertex id stream + SET_FLAGS2( MATERIAL_VAR2_USES_VERTEXID ); + + DECLARE_STATIC_VERTEX_SHADER( cloak_vs30 ); + SET_STATIC_VERTEX_SHADER_COMBO( MODEL, bIsModel ); + SET_STATIC_VERTEX_SHADER( cloak_vs30 ); + + // Bind ps_2_b shader so we can get Phong terms + DECLARE_STATIC_PIXEL_SHADER( cloak_ps30 ); + SET_STATIC_PIXEL_SHADER_COMBO( LIGHTWARPTEXTURE, hasDiffuseWarp ); + SET_STATIC_PIXEL_SHADER( cloak_ps30 ); + } +#endif + + pShader->DefaultFog(); + + if( bMasked ) + { + pShader->EnableAlphaBlending( SHADER_BLEND_ONE_MINUS_SRC_ALPHA, SHADER_BLEND_SRC_ALPHA ); + } + } + DYNAMIC_STATE + { + pShaderAPI->SetDefaultState(); + + // Bind textures + pShader->BindTexture( SHADER_SAMPLER0, info.m_nBaseTexture, 0 ); // Base Map + pShaderAPI->BindStandardTexture( SHADER_SAMPLER2, TEXTURE_FRAME_BUFFER_FULL_TEXTURE_0 ); // Refraction Map + pShader->BindTexture( SHADER_SAMPLER3, info.m_nNormalMap, info.m_nBumpFrame ); // Normal Map + pShaderAPI->BindStandardTexture( SHADER_SAMPLER5, TEXTURE_NORMALIZATION_CUBEMAP_SIGNED ); // Normalization cube map + + if ( hasDiffuseWarp ) + { + if ( r_lightwarpidentity.GetBool() ) + { + pShaderAPI->BindStandardTexture( SHADER_SAMPLER1, TEXTURE_IDENTITY_LIGHTWARP ); + } + else + { + pShader->BindTexture( SHADER_SAMPLER1, info.m_nDiffuseWarpTexture ); // Light warp texture + } + } + + MaterialFogMode_t fogType = pShaderAPI->GetSceneFogMode(); + int fogIndex = ( fogType == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ) ? 1 : 0; + + LightState_t lightState; + pShaderAPI->GetDX9LightState( &lightState ); + +#ifndef _X360 + if ( !g_pHardwareConfig->HasFastVertexTextures() ) +#endif + { + bool bUseStaticControlFlow = g_pHardwareConfig->SupportsStaticControlFlow(); + + DECLARE_DYNAMIC_VERTEX_SHADER( cloak_vs20 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( DOWATERFOG, fogIndex ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, pShaderAPI->GetCurrentNumBones() > 0 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( NUM_LIGHTS, bUseStaticControlFlow ? 0 : lightState.m_nNumLights ); + SET_DYNAMIC_VERTEX_SHADER( cloak_vs20 ); + + // Bind ps_2_b shader so we can get Phong, rim and a cloudier refraction + if ( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_DYNAMIC_PIXEL_SHADER( cloak_ps20b ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( NUM_LIGHTS, lightState.m_nNumLights ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( WRITEWATERFOGTODESTALPHA, fogType == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + SET_DYNAMIC_PIXEL_SHADER( cloak_ps20b ); + } + else + { + // JasonM Hack + // + // In general, cloaking on ps_2_0 needs re-working for multipass...yuck... + // + int nPS20NumLights = max( lightState.m_nNumLights, 1 ); + DECLARE_DYNAMIC_PIXEL_SHADER( cloak_ps20 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( NUM_LIGHTS, nPS20NumLights ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( WRITEWATERFOGTODESTALPHA, fogType == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + SET_DYNAMIC_PIXEL_SHADER( cloak_ps20 ); + } + } +#ifndef _X360 + else + { + pShader->SetHWMorphVertexShaderState( VERTEX_SHADER_SHADER_SPECIFIC_CONST_6, VERTEX_SHADER_SHADER_SPECIFIC_CONST_7, SHADER_VERTEXTEXTURE_SAMPLER0 ); + + DECLARE_DYNAMIC_VERTEX_SHADER( cloak_vs30 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( DOWATERFOG, fogIndex ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, pShaderAPI->GetCurrentNumBones() > 0 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( MORPHING, pShaderAPI->IsHWMorphingEnabled() ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression ); + SET_DYNAMIC_VERTEX_SHADER( cloak_vs30 ); + + DECLARE_DYNAMIC_PIXEL_SHADER( cloak_ps30 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( NUM_LIGHTS, lightState.m_nNumLights ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( WRITEWATERFOGTODESTALPHA, fogType == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + SET_DYNAMIC_PIXEL_SHADER( cloak_ps30 ); + } +#endif + + pShader->SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_1, info.m_nBumpTransform ); + + if( g_pHardwareConfig->GetHDRType() == HDR_TYPE_NONE ) + { + pShader->SetPixelShaderConstant( 27, info.m_nRefractTint ); + } + else + { + pShader->SetPixelShaderConstantGammaToLinear( 27, info.m_nRefractTint ); + } + + pShaderAPI->SetPixelShaderFogParams( PSREG_FOG_PARAMS ); + + // Pack phong exponent in with the eye position + float vEyePos_SpecExponent[4], vFresnelRanges_SpecBoost[4] = {1, 0.5, 1, 1}; + float vSpecularTint[4] = {1, 1, 1, 1}, vRimBoost[4] = {1, 1, 1, 1}; + pShaderAPI->GetWorldSpaceCameraPosition( vEyePos_SpecExponent ); + + if ( (info.m_nPhongExponent != -1) && params[info.m_nPhongExponent]->IsDefined() ) + vEyePos_SpecExponent[3] = params[info.m_nPhongExponent]->GetFloatValue(); // This overrides the channel in the map + else + vEyePos_SpecExponent[3] = 0; // Use the alpha channel of the normal map for the exponent + + if ( (info.m_nPhongTint != -1 ) && params[info.m_nPhongTint]->IsDefined() ) // Get the tint parameter + params[info.m_nPhongTint]->GetVecValue(vSpecularTint, 4); + + // Get the rim light power (goes in w of Phong tint) + if ( bHasRimLight && (info.m_nRimLightPower != -1) && params[info.m_nRimLightPower]->IsDefined() ) + { + vSpecularTint[3] = params[info.m_nRimLightPower]->GetFloatValue(); + vSpecularTint[3] = max(vSpecularTint[3], 1.0f); // Make sure this is at least 1 + } + + // Get the rim boost power (goes in w of flashlight position) + if ( bHasRimLight && (info.m_nRimLightBoost != -1) && params[info.m_nRimLightBoost]->IsDefined() ) + { + vRimBoost[3] = params[info.m_nRimLightBoost]->GetFloatValue(); + } + + // Rim mask...if this is true, use alpha channel of spec exponent texture to mask the rim term + if ( bHasRimMaskMap ) + { + float vRimMaskControl[4] = {0, 0, 0, 0}; // Only x is relevant in shader code + vRimMaskControl[0] = params[info.m_nRimMask]->GetFloatValue(); + pShaderAPI->SetPixelShaderConstant( PSREG_FLASHLIGHT_ATTENUATION, vRimMaskControl, 1 ); + } + + // If it's all zeros, there was no constant tint in the vmt + if ( (vSpecularTint[0] == 0.0f) && (vSpecularTint[1] == 0.0f) && (vSpecularTint[2] == 0.0f) ) + { + if ( hasPhongTintMap ) // If we have a map to use, tell the shader + { + vSpecularTint[0] = -1; + } + else // Otherwise, just tint with white + { + vSpecularTint[0] = 1.0f; + vSpecularTint[1] = 1.0f; + vSpecularTint[2] = 1.0f; + } + } + + if ( (info.m_nPhongFresnelRanges != -1 ) && params[info.m_nPhongFresnelRanges]->IsDefined() ) + { + params[info.m_nPhongFresnelRanges]->GetVecValue( vFresnelRanges_SpecBoost, 3 ); // Grab optional fresnel range parameters + // Change fresnel range encoding from (min, mid, max) to ((mid-min)*2, mid, (max-mid)*2) + vFresnelRanges_SpecBoost[0] = (vFresnelRanges_SpecBoost[1] - vFresnelRanges_SpecBoost[0]) * 2; + vFresnelRanges_SpecBoost[2] = (vFresnelRanges_SpecBoost[2] - vFresnelRanges_SpecBoost[1]) * 2; + } + + if ( ( info.m_nPhongBoost != -1 ) &¶ms[info.m_nPhongBoost]->IsDefined() ) // Grab optional phong boost param + vFresnelRanges_SpecBoost[3] = params[info.m_nPhongBoost]->GetFloatValue(); + else + vFresnelRanges_SpecBoost[3] = 1.0f; + + pShaderAPI->SetPixelShaderConstant( PSREG_EYEPOS_SPEC_EXPONENT, vEyePos_SpecExponent, 1 ); + pShaderAPI->SetPixelShaderConstant( PSREG_FRESNEL_SPEC_PARAMS, vFresnelRanges_SpecBoost, 1 ); + + pShaderAPI->SetPixelShaderConstant( PSREG_SPEC_RIM_PARAMS, vSpecularTint, 1 ); + pShaderAPI->SetPixelShaderConstant( PSREG_FLASHLIGHT_POSITION_RIM_BOOST, vRimBoost, 1 ); // Rim boost in w on non-flashlight pass + + pShaderAPI->SetPixelShaderFogParams( PSREG_FOG_PARAMS ); + + // Lighting constants + + pShaderAPI->SetPixelShaderStateAmbientLightCube( PSREG_AMBIENT_CUBE, !lightState.m_bAmbientLight ); + pShaderAPI->CommitPixelShaderLighting( PSREG_LIGHT_INFO_ARRAY ); + + // Set c0 and c1 to contain first two rows of ViewProj matrix + VMatrix matView, matProj, matViewProj; + pShaderAPI->GetMatrix( MATERIAL_VIEW, matView.m[0] ); + pShaderAPI->GetMatrix( MATERIAL_PROJECTION, matProj.m[0] ); + matViewProj = matView * matProj; + pShaderAPI->SetPixelShaderConstant( 0, matViewProj.m[0], 2 ); + + // Cloaking control constants + float vCloakControls[4] = { params[info.m_nRefractAmount]->GetFloatValue(), params[info.m_nCloakFactor]->GetFloatValue(), 0.0f, 0.0f }; + pShaderAPI->SetPixelShaderConstant( 3, vCloakControls, 1 ); + } + pShader->Draw(); +} diff --git a/materialsystem/stdshaders/cloak_dx9_helper.h b/materialsystem/stdshaders/cloak_dx9_helper.h new file mode 100644 index 0000000..ad72367 --- /dev/null +++ b/materialsystem/stdshaders/cloak_dx9_helper.h @@ -0,0 +1,63 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//============================================================================= + +#ifndef CLOAK_DX9_HELPER_H +#define CLOAK_DX9_HELPER_H +#ifdef _WIN32 +#pragma once +#endif + +#include + +//----------------------------------------------------------------------------- +// Forward declarations +//----------------------------------------------------------------------------- +class CBaseVSShader; +class IMaterialVar; +class IShaderDynamicAPI; +class IShaderShadow; + +//----------------------------------------------------------------------------- +// Init params/ init/ draw methods +//----------------------------------------------------------------------------- +struct Cloak_DX9_Vars_t +{ + Cloak_DX9_Vars_t() { memset( this, 0xFF, sizeof( *this ) ); } + + int m_nBaseTexture; + int m_nRefractAmount; + int m_nRefractTint; + int m_nNormalMap; + int m_nBumpFrame; + int m_nBumpTransform; + int m_nRefractTintTexture; + int m_nRefractTintTextureFrame; + int m_nFresnelReflection; + int m_nMasked; + int m_nCloakFactor; + int m_nDiffuseWarpTexture; + + int m_nPhongExponent; + int m_nPhongTint; + int m_nPhongAlbedoTint; + int m_nPhongExponentTexture; + int m_nPhongBoost; + int m_nPhongFresnelRanges; + + // Rim lighting parameters + int m_nRimLight; + int m_nRimLightPower; + int m_nRimLightBoost; + int m_nRimMask; +}; + +void InitParamsCloak_DX9( CBaseVSShader *pShader, IMaterialVar** params, const char *pMaterialName, + Cloak_DX9_Vars_t &info ); +void InitCloak_DX9( CBaseVSShader *pShader, IMaterialVar** params, Cloak_DX9_Vars_t &info ); +void DrawCloak_DX9( CBaseVSShader *pShader, IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, + IShaderShadow* pShaderShadow, Cloak_DX9_Vars_t &info, VertexCompressionType_t vertexCompression ); + +#endif // CLOAK_DX9_HELPER_H diff --git a/materialsystem/stdshaders/cloak_ps2x.fxc b/materialsystem/stdshaders/cloak_ps2x.fxc new file mode 100644 index 0000000..66c332b --- /dev/null +++ b/materialsystem/stdshaders/cloak_ps2x.fxc @@ -0,0 +1,201 @@ +//====== Copyright © 1996-2005, Valve Corporation, All rights reserved. ======= +// +// Purpose: +// +//============================================================================= + +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps30][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX] +// STATIC: "LIGHTWARPTEXTURE" "0..1" +// DYNAMIC: "PIXELFOGTYPE" "0..1" +// DYNAMIC: "WRITEWATERFOGTODESTALPHA" "0..1" +// DYNAMIC: "NUM_LIGHTS" "0..2" [ps20] +// DYNAMIC: "NUM_LIGHTS" "0..4" [ps20b] +// DYNAMIC: "NUM_LIGHTS" "0..4" [ps30] + + +#include "shader_constant_register_map.h" + +sampler BaseSampler : register( s0 ); // Base map +sampler DiffuseWarpSampler : register( s1 ); // 1D texture for diffuse lighting modification +sampler RefractSampler : register( s2 ); // Refraction map copied from back buffer +sampler NormalSampler : register( s3 ); // Normal map +sampler SpecExponentSampler : register( s4 ); // Flashlight cookie +sampler NormalizeSampler : register( s5 ); // Normalization cube map + +const float3x3 g_ViewProj : register( c0 ); // 1st row of Projection matrix +// c1 // 2nd row +// c2 // 4th row +const float2 g_CloakControl : register( c3 ); // { refract amount, cloak, ?, ? } +const float3 cAmbientCube[6] : register( PSREG_AMBIENT_CUBE ); +const float4 g_EyePos_SpecExponent : register( PSREG_EYEPOS_SPEC_EXPONENT ); +const float4 g_FogParams : register( PSREG_FOG_PARAMS ); +const float4 g_FlashlightAttenuationFactors_RimMask : register( PSREG_FLASHLIGHT_ATTENUATION ); // On non-flashlight pass, x has rim mask control +const float4 g_RimBoost : register( PSREG_FLASHLIGHT_POSITION_RIM_BOOST ); +const float4 g_FresnelSpecParams : register( PSREG_FRESNEL_SPEC_PARAMS ); // xyz are fresnel, w is specular boost +const float4 g_SpecularRimParams : register( PSREG_SPEC_RIM_PARAMS ); // xyz are specular tint color, w is rim power +PixelShaderLightInfo cLightInfo[3] : register( PSREG_LIGHT_INFO_ARRAY ); // 2 registers each - 6 registers total + +#define g_fRimBoost g_RimBoost.w +#define g_FresnelRanges g_FresnelSpecParams.xyz +#define g_SpecularBoost g_FresnelSpecParams.w +#define g_SpecularTint g_SpecularRimParams.xyz +#define g_RimExponent g_SpecularRimParams.w +#define g_FlashlightAttenuationFactors g_FlashlightAttenuationFactors_RimMask +#define g_RimMaskControl g_FlashlightAttenuationFactors_RimMask.x + +// 8 2D Poisson offsets (designed to use .xy and .wz swizzles (not .zw) +static const float4 gPoissonOffset[4] = { float4 (-0.0876f, 0.9703f, 0.5651f, 0.4802f ), + float4 ( 0.1851f, 0.1580f, -0.0617f, -0.2616f ), + float4 (-0.5477f, -0.6603f, 0.0711f, -0.5325f ), + float4 (-0.0751f, -0.8954f, 0.4054f, 0.6384f ) }; + +struct PS_INPUT +{ + float2 vBaseTexCoord : TEXCOORD0; + float3x3 tangentSpaceTranspose : TEXCOORD1; + // second row : TEXCOORD2; + // third row : TEXCOORD3; + float3 worldPos : TEXCOORD4; + float3 projPos : TEXCOORD5; + float4 lightAtten : TEXCOORD6; +}; + +float4 main( PS_INPUT i ) : COLOR +{ + float3 vSpecular = float3( 0.0f, 0.0f, 0.0f ); + bool bDoDiffuseWarp = LIGHTWARPTEXTURE ? true : false; + int nNumLights = NUM_LIGHTS; + + // Base color + float4 albedo = tex2D( BaseSampler, i.vBaseTexCoord ); + + // Load normal and expand range + float4 vNormalSample = tex2D( NormalSampler, i.vBaseTexCoord ); + float3 tangentSpaceNormal = 2.0f * vNormalSample.xyz - 1.0f; + + // We need a world space normal if we're doing any lighting + float3 vWorldNormal = normalize( mul( i.tangentSpaceTranspose, tangentSpaceNormal ) ); + float3 vWorldEyeDir = normalize( g_EyePos_SpecExponent.xyz - i.worldPos ); + + // Vanilla 1-(N.V) fresnel term used later in transition lerp + float fresnel = 1-saturate( dot( vWorldNormal, vWorldEyeDir ) ); + + // Summation of diffuse illumination from all local lights + float3 diffuseLighting = PixelShaderDoLighting( i.worldPos, vWorldNormal, + float3( 0.0f, 0.0f, 0.0f ), false, + true, i.lightAtten, cAmbientCube, NormalizeSampler, + nNumLights, cLightInfo, true, false, 1.0f, + bDoDiffuseWarp, DiffuseWarpSampler ); + + + + + + // Transform world space normal into clip space and project + float2 vProjNormal; + vProjNormal.x = dot( vWorldNormal, g_ViewProj[0] ); // 1st row + vProjNormal.y = dot( vWorldNormal, g_ViewProj[1] ); // 2nd row + + // Compute coordinates for sampling refraction + float2 vRefractTexCoordNoWarp = i.projPos.xy / i.projPos.z; + float2 vRefractTexCoord = vProjNormal.xy; + float scale = lerp( g_CloakControl.x, 0.0f, g_CloakControl.y ); + vRefractTexCoord *= scale; + vRefractTexCoord += vRefractTexCoordNoWarp; + +#ifdef SHADER_MODEL_PS_2_0 + float3 vRefract = tex2D( RefractSampler, vRefractTexCoordNoWarp ); +#endif + + // Extra refraction rays, specular, rim etc are only done on ps_2_b +#if defined( SHADER_MODEL_PS_2_B ) || defined( SHADER_MODEL_PS_3_0 ) + // Blur by scalable Poisson filter + float fBlurAmount = lerp( 0.05f, 0.0f, g_CloakControl.y ); + float3 vRefract = tex2D( RefractSampler, vRefractTexCoord ); + vRefract += tex2D( RefractSampler, vRefractTexCoord + gPoissonOffset[0].xy * fBlurAmount ); + vRefract += tex2D( RefractSampler, vRefractTexCoord + gPoissonOffset[0].wz * fBlurAmount ); + vRefract += tex2D( RefractSampler, vRefractTexCoord + gPoissonOffset[1].xy * fBlurAmount ); + vRefract += tex2D( RefractSampler, vRefractTexCoord + gPoissonOffset[1].wz * fBlurAmount ); + vRefract += tex2D( RefractSampler, vRefractTexCoord + gPoissonOffset[2].xy * fBlurAmount ); + vRefract += tex2D( RefractSampler, vRefractTexCoord + gPoissonOffset[2].wz * fBlurAmount ); + +// We're right at the hairy edge of constant register usage and hence have to drop these taps... +// vRefract += tex2D( RefractSampler, vRefractTexCoord + gPoissonOffset[3].xy * fBlurAmount ); +// vRefract += tex2D( RefractSampler, vRefractTexCoord + gPoissonOffset[3].wz * fBlurAmount ); + vRefract /= 7.0f; + + float3 rimLighting = float3( 0.0f, 0.0f, 0.0f ); + float3 specularLighting = float3( 0.0f, 0.0f, 0.0f ); + float fSpecExp = g_EyePos_SpecExponent.w; + float fSpecMask = vNormalSample.a; + + float4 vSpecExpMap = tex2D( SpecExponentSampler, i.vBaseTexCoord ); + float fSpecExpMap = vSpecExpMap.r; + float fRimMask = 1.0f;//lerp( 1.0f, vSpecExpMap.a, g_RimMaskControl ); // Select rim mask + float3 vSpecularTint; + + // If the exponent passed in as a constant is zero, use the value from the map as the exponent + if ( fSpecExp == 0 ) + fSpecExp = 1.0f - fSpecExpMap + 150.0f * fSpecExpMap; + + // If constant tint is negative, tint with albedo, based upon scalar tint map + if ( g_SpecularTint.r == -1 ) + vSpecularTint = lerp( float3(1.0f, 1.0f, 1.0f), albedo, vSpecExpMap.g ); + else + vSpecularTint = g_SpecularTint.rgb; + + // Fresnel to match regular specular lighting + float fFresnelRanges = Fresnel( vWorldNormal, vWorldEyeDir, g_FresnelRanges ); + + // Summation of specular from all local lights besides the flashlight + PixelShaderDoSpecularLighting( i.worldPos, vWorldNormal, fSpecExp, vWorldEyeDir, + i.lightAtten, nNumLights, cLightInfo, false, 1.0f, false, + NormalizeSampler, 1.0f, true, g_RimExponent, + + // Outputs + specularLighting, rimLighting ); + + // Modulate with spec mask, boost, tint and fresnel ranges + specularLighting *= fSpecMask * g_SpecularBoost * fFresnelRanges * vSpecularTint; + + float fRimFresnel = Fresnel4( vWorldNormal, vWorldEyeDir ); + + // Add in rim light modulated with tint, mask and traditional Fresnel (not using Fresnel ranges) + rimLighting *= vSpecularTint * fRimMask * fRimFresnel; + + // Fold rim lighting into specular term by using the max so that we don't really add light twice... + specularLighting = max (specularLighting, rimLighting); + + // Add in view-ray lookup from ambient cube + specularLighting += fRimFresnel * fRimMask * vSpecularTint /* g_fRimBoost */ * PixelShaderAmbientLight( vWorldEyeDir, cAmbientCube) * saturate(dot(vWorldNormal, float3(0, 0 , 1)) ); + + float tintLerpFactor = saturate(lerp( 1, fresnel-1.1, saturate(g_CloakControl.y))); + tintLerpFactor = smoothstep( 0.4f, 0.425f, tintLerpFactor ); + float3 vTintedRefract = lerp( vRefract, albedo * vRefract, 0.7f ); + vRefract = lerp( vRefract, vTintedRefract, tintLerpFactor ); + + vSpecular = specularLighting * smoothstep( 0.98, 0.8, saturate(g_CloakControl.y )); +#endif + + // Blend refraction component with diffusely lit model + float diffuseLerpFactor = saturate(lerp( 1, fresnel - 1.35, saturate(g_CloakControl.y))); + diffuseLerpFactor = smoothstep( 0.4f, 0.425f, diffuseLerpFactor ); + + float3 fDiffuse = lerp( vRefract, albedo * diffuseLighting, diffuseLerpFactor ); + float3 result = fDiffuse + vSpecular; + + float alpha = 1.0f; + + // Emulate LinearColorToHDROutput() when uncloaked + result = lerp( result.xyz * LINEAR_LIGHT_SCALE, result, saturate(g_CloakControl.y) ); + + float fogFactor = CalcPixelFogFactor( PIXELFOGTYPE, g_FogParams, g_EyePos_SpecExponent.z, i.worldPos.z, i.projPos.z ); + +#if WRITEWATERFOGTODESTALPHA && (PIXELFOGTYPE == PIXEL_FOG_TYPE_HEIGHT) + alpha = fogFactor; +#endif + + return FinalOutput( float4( result, alpha ), fogFactor, PIXELFOGTYPE, TONEMAP_SCALE_NONE ); +} diff --git a/materialsystem/stdshaders/cloak_vs20.fxc b/materialsystem/stdshaders/cloak_vs20.fxc new file mode 100644 index 0000000..12b44f4 --- /dev/null +++ b/materialsystem/stdshaders/cloak_vs20.fxc @@ -0,0 +1,147 @@ +//====== Copyright © 1996-2005, Valve Corporation, All rights reserved. ======= +// +// Purpose: +// +//============================================================================= + +// STATIC: "MODEL" "0..1" +// STATIC: "USE_STATIC_CONTROL_FLOW" "0..1" [vs20] + +// DYNAMIC: "COMPRESSED_VERTS" "0..1" +// DYNAMIC: "DOWATERFOG" "0..1" +// DYNAMIC: "SKINNING" "0..1" +// DYNAMIC: "MORPHING" "0..1" [vs30] +// DYNAMIC: "NUM_LIGHTS" "0..2" [vs20] + +// If using static control flow on Direct3D, we should use the NUM_LIGHTS=0 combo +// SKIP: $USE_STATIC_CONTROL_FLOW && ( $NUM_LIGHTS > 0 ) [vs20] + +#include "common_vs_fxc.h" + +static const bool g_bSkinning = SKINNING ? true : false; +static const int g_FogType = DOWATERFOG; + +#ifdef SHADER_MODEL_VS_3_0 +// NOTE: cMorphTargetTextureDim.xy = target dimensions, +// cMorphTargetTextureDim.z = 4tuples/morph +const float3 cMorphTargetTextureDim : register( SHADER_SPECIFIC_CONST_6 ); +const float4 cMorphSubrect : register( SHADER_SPECIFIC_CONST_7 ); + +sampler2D morphSampler : register( D3DVERTEXTEXTURESAMPLER0, s0 ); +#endif + +struct VS_INPUT +{ + float4 vPos : POSITION; + float4 vBoneWeights : BLENDWEIGHT; + float4 vBoneIndices : BLENDINDICES; + float4 vNormal : NORMAL; + float4 vBaseTexCoord : TEXCOORD0; + float4 vUserData : TANGENT; + + // Position and normal/tangent deltas + float3 vPosFlex : POSITION1; + float3 vNormalFlex : NORMAL1; + +#ifdef SHADER_MODEL_VS_3_0 + float vVertexID : POSITION2; +#endif +}; + +struct VS_OUTPUT +{ + float4 vSetupProjPos : POSITION; + float fFog : FOG; + float2 vBaseTexCoord : TEXCOORD0; + float3x3 tangentSpaceTranspose : TEXCOORD1; + // second row : TEXCOORD2; + // third row : TEXCOORD3; + float3 worldPos : TEXCOORD4; + float3 projPos : TEXCOORD5; + float4 lightAtten : TEXCOORD6; + float3 vRefract : TEXCOORD7; +}; + +VS_OUTPUT main( const VS_INPUT v ) +{ + VS_OUTPUT o = ( VS_OUTPUT )0; + + float4 vPosition = v.vPos; + float3 vNormal; + float4 vTangent; + + DecompressVertex_NormalTangent( v.vNormal, v.vUserData, vNormal, vTangent ); + +#if !defined( SHADER_MODEL_VS_3_0 ) || !MORPHING + ApplyMorph( v.vPosFlex, v.vNormalFlex, vPosition.xyz, vNormal, vTangent.xyz ); +#else + ApplyMorph( morphSampler, cMorphTargetTextureDim, cMorphSubrect, v.vVertexID, float3( 0, 0, 0 ), + vPosition.xyz, vNormal, vTangent.xyz ); +#endif + + // Perform skinning + float3 worldNormal, worldPos, worldTangentS, worldTangentT; + SkinPositionNormalAndTangentSpace( g_bSkinning, vPosition, vNormal, vTangent, + v.vBoneWeights, v.vBoneIndices, worldPos, + worldNormal, worldTangentS, worldTangentT ); + + // Always normalize since flex path is controlled by runtime + // constant not a shader combo and will always generate the normalization + worldNormal = normalize( worldNormal ); + worldTangentS = normalize( worldTangentS ); + worldTangentT = normalize( worldTangentT ); + + // Projected position + float4 vProjPos = mul( float4( worldPos, 1 ), cViewProj ); + o.vSetupProjPos = vProjPos; + + // Map projected position to the refraction texture + float2 vRefractPos; + vRefractPos.x = vProjPos.x; + vRefractPos.y = -vProjPos.y; // invert Y + vRefractPos = (vRefractPos + vProjPos.w) * 0.5f; + +#if defined ( SHADER_MODEL_VS_2_0 ) && ( !USE_STATIC_CONTROL_FLOW ) + o.lightAtten = float4(0,0,0,0); + #if ( NUM_LIGHTS > 0 ) + o.lightAtten.x = GetVertexAttenForLight( worldPos, 0, false ); + #endif + #if ( NUM_LIGHTS > 1 ) + o.lightAtten.y = GetVertexAttenForLight( worldPos, 1, false ); + #endif + #if ( NUM_LIGHTS > 2 ) + o.lightAtten.z = GetVertexAttenForLight( worldPos, 2, false ); + #endif + #if ( NUM_LIGHTS > 3 ) + o.lightAtten.w = GetVertexAttenForLight( worldPos, 3, false ); + #endif +#else + // Scalar light attenuation + o.lightAtten.x = GetVertexAttenForLight( worldPos, 0, true ); + o.lightAtten.y = GetVertexAttenForLight( worldPos, 1, true ); + o.lightAtten.z = GetVertexAttenForLight( worldPos, 2, true ); + o.lightAtten.w = GetVertexAttenForLight( worldPos, 3, true ); +#endif + + // Compute fog based on the position + float3 vWorldPos = mul( v.vPos, cModel[0] ); +#if !defined( _X360 ) + o.fFog = CalcFog( vWorldPos, vProjPos, FOGTYPE_RANGE ); +#endif + + // World position + o.worldPos = worldPos; + + // Refract position + o.projPos = float3(vRefractPos.x, vRefractPos.y, vProjPos.w); + + // Tranform bump coordinates + o.vBaseTexCoord = v.vBaseTexCoord; + + // Tangent space transform + o.tangentSpaceTranspose[0] = float3( worldTangentS.x, worldTangentT.x, worldNormal.x ); + o.tangentSpaceTranspose[1] = float3( worldTangentS.y, worldTangentT.y, worldNormal.y ); + o.tangentSpaceTranspose[2] = float3( worldTangentS.z, worldTangentT.z, worldNormal.z ); + + return o; +} diff --git a/materialsystem/stdshaders/cloud.cpp b/materialsystem/stdshaders/cloud.cpp new file mode 100644 index 0000000..810e6c4 --- /dev/null +++ b/materialsystem/stdshaders/cloud.cpp @@ -0,0 +1,76 @@ +//========= 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( Cloud, + "Help for Cloud" ) + BEGIN_SHADER_PARAMS + SHADER_PARAM_OVERRIDE( BASETEXTURE, SHADER_PARAM_TYPE_TEXTURE, "shadertest/cloud", "cloud texture", 0 ) + SHADER_PARAM( CLOUDALPHATEXTURE, SHADER_PARAM_TYPE_TEXTURE, "shadertest/cloudalpha", "cloud alpha texture" ) + SHADER_PARAM( CLOUDSCALE, SHADER_PARAM_TYPE_VEC2, "[1 1]", "cloudscale" ) + SHADER_PARAM( MASKSCALE, SHADER_PARAM_TYPE_VEC2, "[1 1]", "maskscale" ) + END_SHADER_PARAMS + SHADER_INIT + { + LoadTexture( BASETEXTURE ); + LoadTexture( CLOUDALPHATEXTURE ); + if( !params[CLOUDSCALE]->IsDefined() ) + { + params[CLOUDSCALE]->SetVecValue( 1.0f, 1.0f ); + } + if( !params[MASKSCALE]->IsDefined() ) + { + params[MASKSCALE]->SetVecValue( 1.0f, 1.0f ); + } + } + + SHADER_DRAW + { + if( g_pHardwareConfig->GetSamplerCount() >= 2 ) + { + SHADOW_STATE + { + pShaderShadow->EnableDepthWrites( false ); + pShaderShadow->EnableBlending( true ); + if ( IS_FLAG_SET( MATERIAL_VAR_ADDITIVE ) ) + { + pShaderShadow->BlendFunc( SHADER_BLEND_ONE, SHADER_BLEND_ONE ); + } + else + { + pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA ); + } + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + + pShaderShadow->DrawFlags( SHADER_DRAW_POSITION | + SHADER_DRAW_TEXCOORD0 | SHADER_DRAW_TEXCOORD1 ); + DefaultFog(); + } + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME ); + BindTexture( SHADER_SAMPLER1, CLOUDALPHATEXTURE ); + + // handle scrolling of base texture + SetFixedFunctionTextureScaledTransform( MATERIAL_TEXTURE0, + BASETEXTURETRANSFORM, CLOUDSCALE ); + SetFixedFunctionTextureScale( MATERIAL_TEXTURE1, MASKSCALE ); + } + Draw(); + } + else + { + ShaderWarning("Cloud not supported for single-texturing boards!\n"); + } + } +END_SHADER diff --git a/materialsystem/stdshaders/cloud_dx8.cpp b/materialsystem/stdshaders/cloud_dx8.cpp new file mode 100644 index 0000000..d3bc253 --- /dev/null +++ b/materialsystem/stdshaders/cloud_dx8.cpp @@ -0,0 +1,77 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $Header: $ +// $NoKeywords: $ +//=============================================================================// + +#include "BaseVSShader.h" +#include "cloud_vs11.inc" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +BEGIN_VS_SHADER( Cloud_dx8, "Help for Cloud" ) + + BEGIN_SHADER_PARAMS + SHADER_PARAM_OVERRIDE( BASETEXTURE, SHADER_PARAM_TYPE_TEXTURE, "shadertest/cloud", "cloud texture", 0 ) + SHADER_PARAM( CLOUDALPHATEXTURE, SHADER_PARAM_TYPE_TEXTURE, "shadertest/cloudalpha", "cloud alpha texture" ) + SHADER_PARAM( CLOUDSCALE, SHADER_PARAM_TYPE_VEC2, "[1 1]", "cloudscale" ) + SHADER_PARAM( MASKSCALE, SHADER_PARAM_TYPE_VEC2, "[1 1]", "maskscale" ) + END_SHADER_PARAMS + + SHADER_INIT + { + LoadTexture( BASETEXTURE, TEXTUREFLAGS_SRGB ); + LoadTexture( CLOUDALPHATEXTURE, TEXTUREFLAGS_SRGB ); + if ( !params[CLOUDSCALE]->IsDefined() ) + { + params[CLOUDSCALE]->SetVecValue( 1.0f, 1.0f ); + } + if ( !params[MASKSCALE]->IsDefined() ) + { + params[MASKSCALE]->SetVecValue( 1.0f, 1.0f ); + } + } + + SHADER_DRAW + { + SHADOW_STATE + { + pShaderShadow->EnableDepthWrites( false ); + pShaderShadow->EnableBlending( true ); + if ( IS_FLAG_SET( MATERIAL_VAR_ADDITIVE ) ) + { + pShaderShadow->BlendFunc( SHADER_BLEND_ONE, SHADER_BLEND_ONE ); + } + else + { + pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA ); + } + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + + pShaderShadow->VertexShaderVertexFormat( VERTEX_POSITION, 2, 0, 0 ); + + cloud_vs11_Static_Index vshIndex; + pShaderShadow->SetVertexShader( "cloud_vs11", vshIndex.GetIndex() ); + pShaderShadow->SetPixelShader( "cloud_ps11" ); + + DefaultFog(); + } + + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME ); + BindTexture( SHADER_SAMPLER1, CLOUDALPHATEXTURE ); + + // handle scrolling of base texture + SetVertexShaderTextureScaledTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, BASETEXTURETRANSFORM, CLOUDSCALE ); + SetVertexShaderTextureScale( VERTEX_SHADER_SHADER_SPECIFIC_CONST_2, MASKSCALE ); + + pShaderAPI->SetVertexShaderIndex( 0 ); + } + Draw(); + } +END_SHADER diff --git a/materialsystem/stdshaders/cloud_dx9.cpp b/materialsystem/stdshaders/cloud_dx9.cpp new file mode 100644 index 0000000..4b04b8b --- /dev/null +++ b/materialsystem/stdshaders/cloud_dx9.cpp @@ -0,0 +1,94 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// DirectX 9 Cloud shader +// +//=============================================================================== + +#include "BaseVSShader.h" +#include "cloud_vs20.inc" +#include "cloud_ps20.inc" + + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +DEFINE_FALLBACK_SHADER( Cloud, Cloud_dx9 ) + +BEGIN_VS_SHADER( Cloud_dx9, "Help for Cloud" ) + + BEGIN_SHADER_PARAMS + SHADER_PARAM_OVERRIDE( BASETEXTURE, SHADER_PARAM_TYPE_TEXTURE, "shadertest/cloud", "cloud texture", 0 ) + SHADER_PARAM( CLOUDALPHATEXTURE, SHADER_PARAM_TYPE_TEXTURE, "shadertest/cloudalpha", "cloud alpha texture" ) + SHADER_PARAM( CLOUDSCALE, SHADER_PARAM_TYPE_VEC2, "[1 1]", "cloudscale" ) + SHADER_PARAM( MASKSCALE, SHADER_PARAM_TYPE_VEC2, "[1 1]", "maskscale" ) + END_SHADER_PARAMS + + SHADER_FALLBACK + { + if( g_pHardwareConfig->GetDXSupportLevel() < 90 ) + return "Cloud_dx8"; + + return 0; + } + + SHADER_INIT + { + LoadTexture( BASETEXTURE, TEXTUREFLAGS_SRGB ); + LoadTexture( CLOUDALPHATEXTURE, TEXTUREFLAGS_SRGB ); + if ( !params[CLOUDSCALE]->IsDefined() ) + { + params[CLOUDSCALE]->SetVecValue( 1.0f, 1.0f ); + } + if ( !params[MASKSCALE]->IsDefined() ) + { + params[MASKSCALE]->SetVecValue( 1.0f, 1.0f ); + } + } + + SHADER_DRAW + { + SHADOW_STATE + { + pShaderShadow->EnableDepthWrites( false ); + pShaderShadow->EnableBlending( true ); + if ( IS_FLAG_SET( MATERIAL_VAR_ADDITIVE ) ) + { + pShaderShadow->BlendFunc( SHADER_BLEND_ONE, SHADER_BLEND_ONE ); + } + else + { + pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA ); + } + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + + pShaderShadow->VertexShaderVertexFormat( VERTEX_POSITION, 2, 0, 0 ); + + DECLARE_STATIC_VERTEX_SHADER( cloud_vs20 ); + SET_STATIC_VERTEX_SHADER( cloud_vs20 ); + + DECLARE_STATIC_PIXEL_SHADER( cloud_ps20 ); + SET_STATIC_PIXEL_SHADER( cloud_ps20 ); + + DefaultFog(); + } + + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME ); + BindTexture( SHADER_SAMPLER1, CLOUDALPHATEXTURE ); + + // Handle scrolling of base texture + SetVertexShaderTextureScaledTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, BASETEXTURETRANSFORM, CLOUDSCALE ); + SetVertexShaderTextureScale( VERTEX_SHADER_SHADER_SPECIFIC_CONST_2, MASKSCALE ); + + DECLARE_DYNAMIC_VERTEX_SHADER( cloud_vs20 ); + SET_DYNAMIC_VERTEX_SHADER( cloud_vs20 ); + + DECLARE_DYNAMIC_PIXEL_SHADER( cloud_ps20 ); + SET_DYNAMIC_PIXEL_SHADER( cloud_ps20 ); + } + + Draw(); + } +END_SHADER diff --git a/materialsystem/stdshaders/cloud_ps11.psh b/materialsystem/stdshaders/cloud_ps11.psh new file mode 100644 index 0000000..82ed1d6 --- /dev/null +++ b/materialsystem/stdshaders/cloud_ps11.psh @@ -0,0 +1,6 @@ +ps.1.1 + +tex t0 +tex t1 + +mul r0, t0, t1 diff --git a/materialsystem/stdshaders/cloud_ps20.fxc b/materialsystem/stdshaders/cloud_ps20.fxc new file mode 100644 index 0000000..31f8bbd --- /dev/null +++ b/materialsystem/stdshaders/cloud_ps20.fxc @@ -0,0 +1,26 @@ +#define HDRTYPE HDR_TYPE_NONE +#include "common_ps_fxc.h" + +sampler BaseTextureSampler : register( s0 ); +sampler CloudAlphaSampler : register( s1 ); + +struct PS_INPUT +{ + float2 baseCoords : TEXCOORD0; + float2 cloudAlphaCoords : TEXCOORD1; + float fogFactor : TEXCOORD2; +}; + +float4 main( PS_INPUT i ) : COLOR +{ + float4 vBase = tex2D( BaseTextureSampler, i.baseCoords ); + float4 vCloudAlpha = tex2D( CloudAlphaSampler, i.cloudAlphaCoords ); + + float fogFactor = 2.0f * smoothstep( 0.3f, 0.6f, i.fogFactor ); + + float4 result = vBase * vCloudAlpha; + result.a *= fogFactor; + + // No actual fog. Use the "fog factor" to modulate alpha (after some smoothstep mojo) + return FinalOutput( result, 1.0f, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_LINEAR ); +} diff --git a/materialsystem/stdshaders/cloud_vs11.vsh b/materialsystem/stdshaders/cloud_vs11.vsh new file mode 100644 index 0000000..6348937 --- /dev/null +++ b/materialsystem/stdshaders/cloud_vs11.vsh @@ -0,0 +1,26 @@ +vs.1.1 + +# DYNAMIC: "DOWATERFOG" "0..0" + +#include "macros.vsh" + +&AllocateRegister( \$projPos ); + +dp4 $projPos.x, $vPos, $cModelViewProj0 +dp4 $projPos.y, $vPos, $cModelViewProj1 +dp4 $projPos.z, $vPos, $cModelViewProj2 +dp4 $projPos.w, $vPos, $cModelViewProj3 +mov oPos, $projPos + +&AllocateRegister( \$worldPos ); +; $worldPos unused, for above water, range fog calcs +&CalcFog( $worldPos, $projPos ); + +&FreeRegister( \$projPos ); +&FreeRegister( \$worldPos ); + +dp4 oT0.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_0 +dp4 oT0.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_1 +dp4 oT1.x, $vTexCoord1, $SHADER_SPECIFIC_CONST_2 +dp4 oT1.y, $vTexCoord1, $SHADER_SPECIFIC_CONST_3 + diff --git a/materialsystem/stdshaders/cloud_vs20.fxc b/materialsystem/stdshaders/cloud_vs20.fxc new file mode 100644 index 0000000..3655e9f --- /dev/null +++ b/materialsystem/stdshaders/cloud_vs20.fxc @@ -0,0 +1,37 @@ +#include "common_vs_fxc.h" + +const float4 g_matBaseTexCoordTransform[2] : register( SHADER_SPECIFIC_CONST_0 ); +const float4 g_matCloudTexCoordTransform[2] : register( SHADER_SPECIFIC_CONST_2 ); + +struct VS_INPUT +{ + float4 vPos : POSITION; + float4 vTexCoord0 : TEXCOORD0; + float4 vTexCoord1 : TEXCOORD1; +}; + +struct VS_OUTPUT +{ + float4 projPos : POSITION; + float2 baseCoords : TEXCOORD0; + float2 cloudAlphaCoords : TEXCOORD1; + float fogFactor : TEXCOORD2; +}; + +VS_OUTPUT main( const VS_INPUT v ) +{ + VS_OUTPUT o; + o.projPos = mul( v.vPos, cModelViewProj ); + + // Compute fog based on the position + float3 vWorldPos = mul( v.vPos, cModel[0] ); + o.fogFactor = CalcFog( vWorldPos, o.projPos, FOGTYPE_RANGE ); + + // Texture coordinate transforms + o.baseCoords.x = dot( v.vTexCoord0.xyzw, g_matBaseTexCoordTransform[0] ); + o.baseCoords.y = dot( v.vTexCoord0.xyzw, g_matBaseTexCoordTransform[1] ); + o.cloudAlphaCoords.x = dot( v.vTexCoord1.xyzw, g_matCloudTexCoordTransform[0] ); + o.cloudAlphaCoords.y = dot( v.vTexCoord1.xyzw, g_matCloudTexCoordTransform[1] ); + + return o; +} diff --git a/materialsystem/stdshaders/color_projection.cpp b/materialsystem/stdshaders/color_projection.cpp new file mode 100644 index 0000000..e8d0a50 --- /dev/null +++ b/materialsystem/stdshaders/color_projection.cpp @@ -0,0 +1,290 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//============================================================================= + +#include "BaseVSShader.h" + +#include "color_projection_ps20.inc" +#include "color_projection_vs20.inc" + +#include "../materialsystem_global.h" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +static ConVar *mat_color_projection = NULL; + +typedef struct SProjectionInfo +{ + bool m_bNeedBlindMK; + bool m_bNeedMonochrome; + bool m_bNeedAnomylize; + float m_flCPU; + float m_flCPV; + float m_flAM; + float m_flAYI; +} TProjectionInfo; + +#define MAX_PROJECTIONS 8 + +TProjectionInfo ProjectionInfo[ MAX_PROJECTIONS ] = +{ + { true, false, false, 0.735f, 0.265f, 1.273463f, -0.073894f }, // protanopia red-green blindness (no red cones) + { true, false, false, 1.14f, -0.14f, 0.968437f, 0.003331f }, // deutanopia red-green blindness (no green cones) + { true, false, false, 0.171f, -0.003f, 0.062921f, 0.292119f }, // tritanopia blue-yellow blindness (no blue cones) + { false, true, false, 0.0f, 0.0f, 0.0f, 0.0f }, // typical achromatopsia (no cones; rod monochromat) + { true, false, true, 0.735f, 0.265f, 1.273463f, -0.073894f }, // protanomaly (anomalous red cones) + { true, false, true, 1.14f, -0.14f, 0.968437f, 0.003331f }, // deutanomaly (anomalous green cones) + { true, false, true, 0.171f, -0.003f, 0.062921f, 0.292119f }, // tritanomaly (anomalous blue cones) + { false, true, true, 0.0f, 0.0f, 0.0f, 0.0f } // atypical achromatopsia (low cones; cone monochromat) +}; + +#if 0 + +#define cpu ProjectionInfo[ 2 ].m_flCPU +#define cpv ProjectionInfo[ 2 ].m_flCPV +#define am ProjectionInfo[ 2 ].m_flAM +#define ayi ProjectionInfo[ 2 ].m_flAYI + + +Vector rgb_from_xyz( Vector vNum ) +{ + Vector vResult; + + vResult.x=( 3.063218*vNum.x-1.393325*vNum.y-0.475802*vNum.z); + vResult.y=(-0.969243*vNum.x+1.875966*vNum.y+0.041555*vNum.z); + vResult.z=( 0.067871*vNum.x-0.228834*vNum.y+1.069251*vNum.z); + + return vResult; +} + +Vector xyz_from_rgb( Vector vNum ) +{ + Vector vResult; + + vResult.x=(0.430574*vNum.x+0.341550*vNum.y+0.178325*vNum.z); + vResult.y=(0.222015*vNum.x+0.706655*vNum.y+0.071330*vNum.z); + vResult.z=(0.020183*vNum.x+0.129553*vNum.y+0.939180*vNum.z); + + return vResult; +} + +Vector anomylize( Vector a, Vector b ) +{ + return ( ( 1.75f * b ) + a ) / 2.75f; +} + +Vector monochrome( Vector r) +{ + float z = (r.x*0.299+r.y*0.587+r.z*0.114); + + return Vector( z, z, z );; +} + + +Vector blindMK( Vector vColor ) +{ + const float wx=0.312713; + const float wy=0.329016; + const float wz=0.358271; + + Vector c_xyz = xyz_from_rgb( vColor ); + + float sum_xyz=c_xyz.x+c_xyz.y+c_xyz.z; + + Vector2D c_uv; + c_uv.x=0; + c_uv.y=0; + + if ( sum_xyz!=0 ) + { + c_uv.x=c_xyz.x/sum_xyz; + c_uv.y=c_xyz.y/sum_xyz; + } + + float nx=wx*c_xyz.y/wy; + float nz=wz*c_xyz.y/wy; + + Vector d_xyz; + d_xyz.y=0; + + float clm; + if ( c_uv.x< cpu ) + { + clm=(cpv-c_uv.y)/(cpu-c_uv.x); + } + else + { + clm=(c_uv.y-cpv)/(c_uv.x-cpu); + } + + float clyi=c_uv.y-c_uv.x*clm; + Vector2D d_uv; + d_uv.x=(ayi-clyi)/(clm-am); + d_uv.y=(clm*d_uv.x)+clyi; + + Vector s_xyz; + s_xyz.x=d_uv.x*c_xyz.y/d_uv.y; + s_xyz.y=c_xyz.y; + s_xyz.z=(1-(d_uv.x+d_uv.y))*c_xyz.y/d_uv.y; + + Vector s_rgb = rgb_from_xyz( s_xyz ); + + d_xyz.x=nx-s_xyz.x; + d_xyz.z=nz-s_xyz.z; + + Vector d_rgb = rgb_from_xyz( d_xyz ); + + Vector adj_rgb; + + adj_rgb.Init(); + + if ( d_rgb.x!=0 ) + { + adj_rgb.x=( s_rgb.x<0 ? 0 : 1)-s_rgb.x/d_rgb.x; + } + if ( d_rgb.y!=0 ) + { + adj_rgb.y=( s_rgb.y<0 ? 0 : 1)-s_rgb.y/d_rgb.y; + } + if ( d_rgb.z!=0 ) + { + adj_rgb.z=( s_rgb.z<0 ? 0 : 1)-s_rgb.z/d_rgb.z; + } + + float adjust = 0; + if ( adj_rgb.x >= 0 && adj_rgb.x <= 1 ) + { + adjust = adj_rgb.x; + } + if ( adj_rgb.y >= 0 && adj_rgb.y <= 1 && adj_rgb.y > adjust ) + { + adjust = adj_rgb.y; + } + if ( adj_rgb.z >= 0 && adj_rgb.z <= 1 && adj_rgb.z > adjust ) + { + adjust = adj_rgb.z; + } + + s_rgb.x=s_rgb.x+(adjust*d_rgb.x); + s_rgb.y=s_rgb.y+(adjust*d_rgb.y); + s_rgb.z=s_rgb.z+(adjust*d_rgb.z); + + return s_rgb; +} + +#endif + + +BEGIN_VS_SHADER( color_projection, "Help for deferred color correction" ) + BEGIN_SHADER_PARAMS + SHADER_PARAM( FRAME_TEXTURE, SHADER_PARAM_TYPE_TEXTURE, "_rt_FullFrameFB1", "" ) + + SHADER_PARAM( HSV_CORRECTION, SHADER_PARAM_TYPE_VEC3, "[ 0.0 0.0 0.0 ]", "" ) + SHADER_PARAM( CONTRAST_CORRECTION, SHADER_PARAM_TYPE_FLOAT, "0.0", "" ) + + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + SET_FLAGS2( MATERIAL_VAR2_NEEDS_FULL_FRAME_BUFFER_TEXTURE ); + +#if 0 + Vector vResult; + vResult = blindMK( Vector( 1, 0, 0 ) ); + vResult = blindMK( Vector( 1, 0, 0 ) ); + vResult = blindMK( Vector( 1, 0, 0 ) ); + vResult = blindMK( Vector( 1, 0, 0 ) ); + vResult = blindMK( Vector( 1, 0, 0 ) ); + vResult = blindMK( Vector( 1, 0, 0 ) ); + + Msg( "%g %g %g", vResult.x, vResult.y, vResult.z ); + +#endif + } + + SHADER_FALLBACK + { + return 0; + } + + SHADER_INIT + { + if ( mat_color_projection == NULL ) + { + mat_color_projection = cvar->FindVar( "mat_color_projection" ); + } + + if ( params[ FRAME_TEXTURE ]->IsDefined() == false ) + { + params[ FRAME_TEXTURE ]->SetStringValue( "_rt_FullFrameFB1" ); + } +// params[ FRAME_TEXTURE ]->SetStringValue( "rj/colors" ); + LoadTexture( FRAME_TEXTURE ); + } + + SHADER_DRAW + { + SHADOW_STATE + { + SetInitialShadowState( ); + + pShaderShadow->EnableDepthWrites( false ); + pShaderShadow->EnableDepthTest( false ); +// pShaderShadow->EnableBlending( true ); +// pShaderShadow->BlendOp( SHADER_BLEND_OP_REVSUBTRACT ); +// EnableAlphaBlending( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE ); + + pShaderShadow->EnableTexture( SHADER_SAMPLER4, true ); + + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER4, false ); + + pShaderShadow->EnableSRGBWrite( false ); + pShaderShadow->EnableAlphaWrites( true ); // writing water fog alpha always. + + int fmt = VERTEX_POSITION; + int nTexCoordDims[ 2 ] = { 2, 3 }; + pShaderShadow->VertexShaderVertexFormat( fmt, 2, nTexCoordDims, 0 ); + + DECLARE_STATIC_VERTEX_SHADER( color_projection_vs20 ); + SET_STATIC_VERTEX_SHADER( color_projection_vs20 ); + + DECLARE_STATIC_PIXEL_SHADER( color_projection_ps20 ); + SET_STATIC_PIXEL_SHADER( color_projection_ps20 ); + } + + DYNAMIC_STATE + { + pShaderAPI->SetDefaultState(); + + BindTexture( SHADER_SAMPLER4, FRAME_TEXTURE, -1 ); + + int nIndex = mat_color_projection->GetInt() - 1; + if ( nIndex < 0 || nIndex >= MAX_PROJECTIONS ) + { + nIndex = 0; + } + + Vector4D vCorrectionParms; + + vCorrectionParms.x = ProjectionInfo[ nIndex ].m_flCPU; + vCorrectionParms.y = ProjectionInfo[ nIndex ].m_flCPV; + vCorrectionParms.z = ProjectionInfo[ nIndex ].m_flAM; + vCorrectionParms.w = ProjectionInfo[ nIndex ].m_flAYI; + pShaderAPI->SetPixelShaderConstant( 1, vCorrectionParms.Base() ); + + DECLARE_DYNAMIC_VERTEX_SHADER( color_projection_vs20 ); + SET_DYNAMIC_VERTEX_SHADER( color_projection_vs20 ); + + DECLARE_DYNAMIC_PIXEL_SHADER( color_projection_ps20 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( NEED_BLINDMK, ProjectionInfo[ nIndex ].m_bNeedBlindMK ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( NEED_MONOCHROME, ProjectionInfo[ nIndex ].m_bNeedMonochrome ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( NEED_ANOMYLIZE, ProjectionInfo[ nIndex ].m_bNeedAnomylize ); + SET_DYNAMIC_PIXEL_SHADER( color_projection_ps20 ); + } + Draw(); + } +END_SHADER diff --git a/materialsystem/stdshaders/color_projection_ps2x.fxc b/materialsystem/stdshaders/color_projection_ps2x.fxc new file mode 100644 index 0000000..be47337 --- /dev/null +++ b/materialsystem/stdshaders/color_projection_ps2x.fxc @@ -0,0 +1,133 @@ +// based upon http://kaioa.com/node/91 + +// DYNAMIC: "NEED_BLINDMK" "0..1" +// DYNAMIC: "NEED_ANOMYLIZE" "0..1" +// DYNAMIC: "NEED_MONOCHROME" "0..1" + +#include "shader_constant_register_map.h" +#include "common_ps_fxc.h" + + +struct PS_INPUT +{ + float2 vScreenUV : TEXCOORD0; +}; + +sampler FrameSampler : register( s4 ); + +const float4 g_vColorParms : register( c1 ); + #define cpu g_vColorParms.x + #define cpv g_vColorParms.y + #define am g_vColorParms.z + #define ayi g_vColorParms.w + + +float3 rgb_from_xyz( float3 vNum ) +{ + float3 vResult; + + vResult.r = dot( vNum, float3( 3.063218f, -1.393325f, -0.475802f ) ); + vResult.g = dot( vNum, float3( -0.969243f, 1.875966f, 0.041555f ) ); + vResult.b = dot( vNum, float3( 0.067871f, -0.228834f, 1.069251f ) ); + + return vResult; +} + +float3 xyz_from_rgb( float3 vNum ) +{ + float3 vResult; + + vResult.x = dot( vNum, float3( 0.430574f, 0.341550f, 0.178325f ) ); + vResult.y = dot( vNum, float3( 0.222015f, 0.706655f, 0.071330f ) ); + vResult.z = dot( vNum, float3( 0.020183f, 0.129553f, 0.939180f ) ); + + return vResult; +} + +float3 anomylize( float3 a, float3 b ) +{ + return ( ( 1.75f * b ) + a ) / 2.75f; +} + +float3 monochrome( float3 r ) +{ + return dot( r, float3( 0.299f, 0.587f, 0.114f ) ); +} + +const static float3 w_xyz = float3( 0.312713f, 0.329016f, 0.358271f ); + +float3 blindMK( float3 vColor ) +{ + float3 c_xyz = xyz_from_rgb( vColor ); + + float sum_xyz = c_xyz.x + c_xyz.y + c_xyz.z; + + float2 c_uv = 0.0f; + + if ( sum_xyz != 0.0f ) + { + c_uv = c_xyz.xy / sum_xyz; + } + + float2 n_xz = w_xyz.xz * c_xyz.y / w_xyz.y; + + float clm; + if ( c_uv.x < cpu ) + { + clm = ( cpv - c_uv.y ) / ( cpu - c_uv.x ); + } + else + { + clm = ( c_uv.y - cpv ) / ( c_uv.x - cpu ); + } + + float clyi = c_uv.y - c_uv.x * clm; + float2 d_uv; + d_uv.x = ( ayi - clyi ) / ( clm - am ); + d_uv.y = ( clm * d_uv.x ) + clyi; + + float3 s_xyz; + s_xyz.x = d_uv.x * c_xyz.y / d_uv.y; + s_xyz.y = c_xyz.y; + s_xyz.z = ( 1.0f - ( d_uv.x + d_uv.y ) ) * c_xyz.y / d_uv.y; + + float3 s_rgb = rgb_from_xyz( s_xyz ); + + float3 d_xyz = 0.0f; + d_xyz.xz = n_xz - s_xyz.xz; + + float3 d_rgb = rgb_from_xyz( d_xyz ); + + float3 adj_rgb = ( d_rgb != 0.0f ? ( ( s_rgb < 0.0f ? 0.0f : 1.0f ) - s_rgb / d_rgb ) : 0.0f ); + + adj_rgb = ( adj_rgb < 0.0f ? 0.0f : adj_rgb > 1.0f ? 0.0f : adj_rgb ); + float adjust = max( max( adj_rgb.r, adj_rgb.g ), adj_rgb.b ); + + s_rgb = s_rgb + ( adjust * d_rgb ); + + return s_rgb; +} + + +float4 main( PS_INPUT i ) : COLOR +{ + float4 vDiffuse = tex2D( FrameSampler, i.vScreenUV ); + +// vDiffuse = float4( 1, 0, 0, 1 ); + + float4 vResult = vDiffuse; + +#if ( NEED_BLINDMK == 1 ) + vResult.rgb = blindMK( vResult.rgb ); +#endif + +#if ( NEED_MONOCHROME == 1 ) + vResult.rgb = monochrome( vResult.rgb ); +#endif + +#if ( NEED_ANOMYLIZE == 1 ) + vResult.rgb = anomylize( vDiffuse.rgb, vResult.rgb ); +#endif + + return vResult; +} diff --git a/materialsystem/stdshaders/color_projection_vs20.fxc b/materialsystem/stdshaders/color_projection_vs20.fxc new file mode 100644 index 0000000..65cca51 --- /dev/null +++ b/materialsystem/stdshaders/color_projection_vs20.fxc @@ -0,0 +1,24 @@ +#include "common_vs_fxc.h" + +struct VS_INPUT +{ + float3 vPos : POSITION; + float2 vScreenCoord : TEXCOORD0; +}; + +struct VS_OUTPUT +{ + float4 vProjPos : POSITION; + float2 vScreenUV : TEXCOORD0; +}; + + +VS_OUTPUT main( const VS_INPUT v ) +{ + VS_OUTPUT o = ( VS_OUTPUT )0; + + o.vProjPos = float4( v.vPos, 1.0f ); + o.vScreenUV = v.vScreenCoord; + + return o; +} diff --git a/materialsystem/stdshaders/colorcorrection.cpp b/materialsystem/stdshaders/colorcorrection.cpp new file mode 100644 index 0000000..28ec36c --- /dev/null +++ b/materialsystem/stdshaders/colorcorrection.cpp @@ -0,0 +1,151 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//============================================================================= + +#include "BaseVSShader.h" + +#include "screenspaceeffect_vs20.inc" +#include "colorcorrection_ps20.inc" +#include "colorcorrection_ps20b.inc" + +#include "../materialsystem_global.h" + + +BEGIN_VS_SHADER_FLAGS( ColorCorrection, "Help for ColorCorrection", SHADER_NOT_EDITABLE ) + BEGIN_SHADER_PARAMS + SHADER_PARAM( WEIGHT_DEFAULT, SHADER_PARAM_TYPE_FLOAT, "1", "Volume Texture Default Weight" ) + SHADER_PARAM( WEIGHT0, SHADER_PARAM_TYPE_FLOAT, "0", "Volume Texture Weight 0" ) + SHADER_PARAM( WEIGHT1, SHADER_PARAM_TYPE_FLOAT, "0", "Volume Texture Weight 1" ) + SHADER_PARAM( WEIGHT2, SHADER_PARAM_TYPE_FLOAT, "0", "Volume Texture Weight 2" ) + SHADER_PARAM( WEIGHT3, SHADER_PARAM_TYPE_FLOAT, "0", "Volume Texture Weight 3" ) + SHADER_PARAM( NUM_LOOKUPS, SHADER_PARAM_TYPE_INTEGER, "0", "Number of lookup maps" ) + SHADER_PARAM( USE_FB_TEXTURE, SHADER_PARAM_TYPE_BOOL, "0", "Use frame buffer texture as input" ) + SHADER_PARAM( INPUT_TEXTURE, SHADER_PARAM_TYPE_TEXTURE, "0", "Input texture" ) + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + if( !params[ WEIGHT_DEFAULT ]->IsDefined() ) + { + params[ WEIGHT_DEFAULT ]->SetFloatValue( 1.0f) ; + } + if( !params[ WEIGHT0 ]->IsDefined() ) + { + params[ WEIGHT0 ]->SetFloatValue( 1.0f ); + } + if( !params[ WEIGHT1 ]->IsDefined() ) + { + params[ WEIGHT1 ]->SetFloatValue( 1.0f ); + } + if( !params[ WEIGHT2 ]->IsDefined() ) + { + params[ WEIGHT2 ]->SetFloatValue( 1.0f ); + } + if( !params[ WEIGHT3 ]->IsDefined() ) + { + params[ WEIGHT3 ]->SetFloatValue( 1.0f ); + } + if( !params[ NUM_LOOKUPS ]->IsDefined() ) + { + params[ NUM_LOOKUPS ]->SetIntValue( 0 ); + } + SET_FLAGS2( MATERIAL_VAR2_NEEDS_FULL_FRAME_BUFFER_TEXTURE ); + } + + SHADER_FALLBACK + { + // Requires DX9 + above + if ( g_pHardwareConfig->GetDXSupportLevel() < 90 ) + { + return "wireframe"; + } + return 0; + } + + SHADER_INIT + { + } + + SHADER_DRAW + { + SHADOW_STATE + { + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER2, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER3, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER4, true ); + + int fmt = VERTEX_POSITION; + pShaderShadow->VertexShaderVertexFormat( fmt, 1, 0, 0 ); + + if ( IsOpenGL() ) + { + // JasonM...do we use this shader? If so, it needs some sRGB adapter love + Assert(0); + } + + // Render targets are always sRGB on OSX GL + bool bForceSRGBWrite = IsOSX() && g_pHardwareConfig->CanDoSRGBReadFromRTs(); + pShaderShadow->EnableSRGBWrite( bForceSRGBWrite ); + + DECLARE_STATIC_VERTEX_SHADER( screenspaceeffect_vs20 ); + SET_STATIC_VERTEX_SHADER( screenspaceeffect_vs20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_STATIC_PIXEL_SHADER( colorcorrection_ps20b ); + SET_STATIC_PIXEL_SHADER( colorcorrection_ps20b ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( colorcorrection_ps20 ); + SET_STATIC_PIXEL_SHADER( colorcorrection_ps20 ); + } + } + DYNAMIC_STATE + { + if( params[ USE_FB_TEXTURE ]->GetIntValue() ) + pShaderAPI->BindStandardTexture( SHADER_SAMPLER0, TEXTURE_FRAME_BUFFER_FULL_TEXTURE_0 ); + else + BindTexture( SHADER_SAMPLER0, INPUT_TEXTURE, -1 ); + + for( int i=0;iGetIntValue();i++ ) + { + pShaderAPI->BindStandardTexture( (Sampler_t)(SHADER_SAMPLER1+i), (StandardTextureId_t)(TEXTURE_COLOR_CORRECTION_VOLUME_0+i) ); + } + + float default_weight = params[ WEIGHT_DEFAULT ]->GetFloatValue(); + float weights[4] = { params[ WEIGHT0 ]->GetFloatValue(), + params[ WEIGHT1 ]->GetFloatValue(), + params[ WEIGHT2 ]->GetFloatValue(), + params[ WEIGHT3 ]->GetFloatValue() }; + + pShaderAPI->SetPixelShaderConstant( 0, &default_weight ); + pShaderAPI->SetPixelShaderConstant( 1, &weights[0] ); + pShaderAPI->SetPixelShaderConstant( 2, &weights[1] ); + pShaderAPI->SetPixelShaderConstant( 3, &weights[2] ); + pShaderAPI->SetPixelShaderConstant( 4, &weights[3] ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_DYNAMIC_PIXEL_SHADER( colorcorrection_ps20b ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( NUM_LOOKUPS, params[ NUM_LOOKUPS ]->GetIntValue() ); + SET_DYNAMIC_PIXEL_SHADER( colorcorrection_ps20b ); + } + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( colorcorrection_ps20 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( NUM_LOOKUPS, params[ NUM_LOOKUPS ]->GetIntValue() ); + SET_DYNAMIC_PIXEL_SHADER( colorcorrection_ps20 ); + } + + DECLARE_DYNAMIC_VERTEX_SHADER( screenspaceeffect_vs20 ); + SET_DYNAMIC_VERTEX_SHADER( screenspaceeffect_vs20 ); + } + Draw(); + } +END_SHADER diff --git a/materialsystem/stdshaders/colorcorrection_ps2x.fxc b/materialsystem/stdshaders/colorcorrection_ps2x.fxc new file mode 100644 index 0000000..6487525 --- /dev/null +++ b/materialsystem/stdshaders/colorcorrection_ps2x.fxc @@ -0,0 +1,55 @@ +// DYNAMIC: "NUM_LOOKUPS" "0..4" + +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX] + +#define HDRTYPE HDR_TYPE_NONE +#include "common_ps_fxc.h" + +sampler BaseTextureSampler : register( s0 ); +sampler ColorCorrectionVolumeTexture0 : register( s1 ); +sampler ColorCorrectionVolumeTexture1 : register( s2 ); +sampler ColorCorrectionVolumeTexture2 : register( s3 ); +sampler ColorCorrectionVolumeTexture3 : register( s4 ); + +float ColorCorrectionDefaultWeight : register( c0 ); +float ColorCorrectionVolumeWeight0 : register( c1 ); +float ColorCorrectionVolumeWeight1 : register( c2 ); +float ColorCorrectionVolumeWeight2 : register( c3 ); +float ColorCorrectionVolumeWeight3 : register( c4 ); + +struct PS_INPUT +{ + float2 baseTexCoord : TEXCOORD0; +}; + +float4 main( PS_INPUT i ) : COLOR +{ + float4 baseColor = tex2D( BaseTextureSampler, i.baseTexCoord ); + + // NOTE: This code requires the color correction texture to be 32 units to be correct. + // This code will cause (0,0,0) to be read from 0.5f/32 + // and (1,1,1) to be read from 31.5f/32 + float4 offsetBaseColor = baseColor*( 31.0f / 32.0f ) + ( 0.5f / 32.0f ); + + float4 outColor = float4( 0.0f, 0.0f, 0.0f, baseColor.a ); + outColor.rgb = baseColor * ColorCorrectionDefaultWeight; + if (NUM_LOOKUPS > 0) + { + outColor.rgb += tex3D( ColorCorrectionVolumeTexture0, offsetBaseColor.rgb ) * ColorCorrectionVolumeWeight0; + if (NUM_LOOKUPS > 1) + { + outColor.rgb += tex3D( ColorCorrectionVolumeTexture1, offsetBaseColor.rgb ) * ColorCorrectionVolumeWeight1; + if (NUM_LOOKUPS > 2) + { + outColor.rgb += tex3D( ColorCorrectionVolumeTexture2, offsetBaseColor.rgb ) * ColorCorrectionVolumeWeight2; + if (NUM_LOOKUPS > 3) + { + outColor.rgb += tex3D( ColorCorrectionVolumeTexture3, offsetBaseColor.rgb ) * ColorCorrectionVolumeWeight3; + } + } + } + } + + return FinalOutput( outColor, 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE ); +} diff --git a/materialsystem/stdshaders/commandbuilder.h b/materialsystem/stdshaders/commandbuilder.h new file mode 100644 index 0000000..278f2dc --- /dev/null +++ b/materialsystem/stdshaders/commandbuilder.h @@ -0,0 +1,407 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +// Utility class for building command buffers into memory +//===========================================================================// + +#ifndef COMMANDBUILDER_H +#define COMMANDBUILDER_H + +#ifndef COMMANDBUFFER_H +#include "shaderapi/commandbuffer.h" +#endif + +#include "BaseVSShader.h" +#include "shaderapi/ishaderapi.h" + +#ifdef _WIN32 +#pragma once +#endif + +extern ConVar my_mat_fullbright; + +template class CFixedCommandStorageBuffer +{ +public: + uint8 m_Data[N]; + + uint8 *m_pDataOut; +#ifdef DBGFLAG_ASSERT + size_t m_nNumBytesRemaining; +#endif + + FORCEINLINE CFixedCommandStorageBuffer( void ) + { + m_pDataOut = m_Data; +#ifdef DBGFLAG_ASSERT + m_nNumBytesRemaining = N; +#endif + + } + + FORCEINLINE void EnsureCapacity( size_t sz ) + { + Assert( m_nNumBytesRemaining >= sz ); + } + + template FORCEINLINE void Put( T const &nValue ) + { + EnsureCapacity( sizeof( T ) ); + *( reinterpret_cast( m_pDataOut ) ) = nValue; + m_pDataOut += sizeof( nValue ); +#ifdef DBGFLAG_ASSERT + m_nNumBytesRemaining -= sizeof( nValue ); +#endif + } + + FORCEINLINE void PutInt( int nValue ) + { + Put( nValue ); + } + + FORCEINLINE void PutFloat( float nValue ) + { + Put( nValue ); + } + + FORCEINLINE void PutPtr( void * pPtr ) + { + Put( pPtr ); + } + + FORCEINLINE void PutMemory( const void *pMemory, size_t nBytes ) + { + EnsureCapacity( nBytes ); + memcpy( m_pDataOut, pMemory, nBytes ); + m_pDataOut += nBytes; + } + + FORCEINLINE uint8 *Base( void ) + { + return m_Data; + } + + FORCEINLINE void Reset( void ) + { + m_pDataOut = m_Data; +#ifdef DBGFLAG_ASSERT + m_nNumBytesRemaining = N; +#endif + } + + FORCEINLINE size_t Size( void ) const + { + return m_pDataOut - m_Data; + } + +}; + +template class CCommandBufferBuilder +{ +public: + S m_Storage; + + FORCEINLINE void End( void ) + { + m_Storage.PutInt( CBCMD_END ); + } + + + FORCEINLINE IMaterialVar *Param( int nVar ) const + { + return CBaseShader::s_ppParams[nVar]; + } + + FORCEINLINE void SetPixelShaderConstants( int nFirstConstant, int nConstants ) + { + m_Storage.PutInt( CBCMD_SET_PIXEL_SHADER_FLOAT_CONST ); + m_Storage.PutInt( nFirstConstant ); + m_Storage.PutInt( nConstants ); + } + + FORCEINLINE void OutputConstantData( float const *pSrcData ) + { + m_Storage.PutFloat( pSrcData[0] ); + m_Storage.PutFloat( pSrcData[1] ); + m_Storage.PutFloat( pSrcData[2] ); + m_Storage.PutFloat( pSrcData[3] ); + } + + FORCEINLINE void OutputConstantData4( float flVal0, float flVal1, float flVal2, float flVal3 ) + { + m_Storage.PutFloat( flVal0 ); + m_Storage.PutFloat( flVal1 ); + m_Storage.PutFloat( flVal2 ); + m_Storage.PutFloat( flVal3 ); + } + + FORCEINLINE void SetPixelShaderConstant( int nFirstConstant, float const *pSrcData, int nNumConstantsToSet ) + { + SetPixelShaderConstants( nFirstConstant, nNumConstantsToSet ); + m_Storage.PutMemory( pSrcData, 4 * sizeof( float ) * nNumConstantsToSet ); + } + + FORCEINLINE void SetPixelShaderConstant( int nFirstConstant, int nVar ) + { + SetPixelShaderConstant( nFirstConstant, Param( nVar )->GetVecValue() ); + } + + void SetPixelShaderConstantGammaToLinear( int pixelReg, int constantVar ) + { + float val[4]; + Param(constantVar)->GetVecValue( val, 3 ); + val[0] = val[0] > 1.0f ? val[0] : GammaToLinear( val[0] ); + val[1] = val[1] > 1.0f ? val[1] : GammaToLinear( val[1] ); + val[2] = val[2] > 1.0f ? val[2] : GammaToLinear( val[2] ); + val[3] = 1.0; + SetPixelShaderConstant( pixelReg, val ); + } + + FORCEINLINE void SetPixelShaderConstant( int nFirstConstant, float const *pSrcData ) + { + SetPixelShaderConstants( nFirstConstant, 1 ); + OutputConstantData( pSrcData ); + } + + FORCEINLINE void SetPixelShaderConstant4( int nFirstConstant, float flVal0, float flVal1, float flVal2, float flVal3 ) + { + SetPixelShaderConstants( nFirstConstant, 1 ); + OutputConstantData4( flVal0, flVal1, flVal2, flVal3 ); + } + + FORCEINLINE void SetPixelShaderConstant_W( int pixelReg, int constantVar, float fWValue ) + { + if ( constantVar != -1 ) + { + float val[3]; + Param(constantVar)->GetVecValue( val, 3); + SetPixelShaderConstant4( pixelReg, val[0], val[1], val[2], fWValue ); + } + } + + FORCEINLINE void SetVertexShaderConstant( int nFirstConstant, float const *pSrcData ) + { + m_Storage.PutInt( CBCMD_SET_VERTEX_SHADER_FLOAT_CONST ); + m_Storage.PutInt( nFirstConstant ); + m_Storage.PutInt( 1 ); + OutputConstantData( pSrcData ); + } + + FORCEINLINE void SetVertexShaderConstant( int nFirstConstant, float const *pSrcData, int nConsts ) + { + m_Storage.PutInt( CBCMD_SET_VERTEX_SHADER_FLOAT_CONST ); + m_Storage.PutInt( nFirstConstant ); + m_Storage.PutInt( nConsts ); + m_Storage.PutMemory( pSrcData, 4 * nConsts * sizeof( float ) ); + } + + + FORCEINLINE void SetVertexShaderConstant4( int nFirstConstant, float flVal0, float flVal1, float flVal2, float flVal3 ) + { + m_Storage.PutInt( CBCMD_SET_VERTEX_SHADER_FLOAT_CONST ); + m_Storage.PutInt( nFirstConstant ); + m_Storage.PutInt( 1 ); + m_Storage.PutFloat( flVal0 ); + m_Storage.PutFloat( flVal1 ); + m_Storage.PutFloat( flVal2 ); + m_Storage.PutFloat( flVal3 ); + } + + void SetVertexShaderTextureTransform( int vertexReg, int transformVar ) + { + Vector4D transformation[2]; + IMaterialVar* pTransformationVar = Param( transformVar ); + if (pTransformationVar && (pTransformationVar->GetType() == MATERIAL_VAR_TYPE_MATRIX)) + { + const VMatrix &mat = pTransformationVar->GetMatrixValue(); + transformation[0].Init( mat[0][0], mat[0][1], mat[0][2], mat[0][3] ); + transformation[1].Init( mat[1][0], mat[1][1], mat[1][2], mat[1][3] ); + } + else + { + transformation[0].Init( 1.0f, 0.0f, 0.0f, 0.0f ); + transformation[1].Init( 0.0f, 1.0f, 0.0f, 0.0f ); + } + SetVertexShaderConstant( vertexReg, transformation[0].Base(), 2 ); + } + + + void SetVertexShaderTextureScaledTransform( int vertexReg, int transformVar, int scaleVar ) + { + Vector4D transformation[2]; + IMaterialVar* pTransformationVar = Param( transformVar ); + if (pTransformationVar && (pTransformationVar->GetType() == MATERIAL_VAR_TYPE_MATRIX)) + { + const VMatrix &mat = pTransformationVar->GetMatrixValue(); + transformation[0].Init( mat[0][0], mat[0][1], mat[0][2], mat[0][3] ); + transformation[1].Init( mat[1][0], mat[1][1], mat[1][2], mat[1][3] ); + } + else + { + transformation[0].Init( 1.0f, 0.0f, 0.0f, 0.0f ); + transformation[1].Init( 0.0f, 1.0f, 0.0f, 0.0f ); + } + + Vector2D scale( 1, 1 ); + IMaterialVar* pScaleVar = Param( scaleVar ); + if (pScaleVar) + { + if (pScaleVar->GetType() == MATERIAL_VAR_TYPE_VECTOR) + pScaleVar->GetVecValue( scale.Base(), 2 ); + else if (pScaleVar->IsDefined()) + scale[0] = scale[1] = pScaleVar->GetFloatValue(); + } + + // Apply the scaling + transformation[0][0] *= scale[0]; + transformation[0][1] *= scale[1]; + transformation[1][0] *= scale[0]; + transformation[1][1] *= scale[1]; + transformation[0][3] *= scale[0]; + transformation[1][3] *= scale[1]; + SetVertexShaderConstant( vertexReg, transformation[0].Base(), 2 ); + } + + FORCEINLINE void SetEnvMapTintPixelShaderDynamicState( int pixelReg, int tintVar ) + { + if( g_pConfig->bShowSpecular && my_mat_fullbright.GetInt() != 2 ) + { + SetPixelShaderConstant( pixelReg, Param( tintVar)->GetVecValue() ); + } + else + { + SetPixelShaderConstant4( pixelReg, 0.0, 0.0, 0.0, 0.0 ); + } + } + + FORCEINLINE void SetEnvMapTintPixelShaderDynamicStateGammaToLinear( int pixelReg, int tintVar, float flAlphaValue = 1.0 ) + { + if( ( tintVar != -1 ) && g_pConfig->bShowSpecular && my_mat_fullbright.GetInt() != 2 ) + { + float color[4]; + color[3] = flAlphaValue; + Param( tintVar)->GetLinearVecValue( color, 3 ); + SetPixelShaderConstant( pixelReg, color ); + } + else + { + SetPixelShaderConstant4( pixelReg, 0.0, 0.0, 0.0, flAlphaValue ); + } + } + + FORCEINLINE void StoreEyePosInPixelShaderConstant( int nConst ) + { + m_Storage.PutInt( CBCMD_STORE_EYE_POS_IN_PSCONST ); + m_Storage.PutInt( nConst ); + } + + FORCEINLINE void CommitPixelShaderLighting( int nConst ) + { + m_Storage.PutInt( CBCMD_COMMITPIXELSHADERLIGHTING ); + m_Storage.PutInt( nConst ); + } + + FORCEINLINE void SetPixelShaderStateAmbientLightCube( int nConst ) + { + m_Storage.PutInt( CBCMD_SETPIXELSHADERSTATEAMBIENTLIGHTCUBE ); + m_Storage.PutInt( nConst ); + } + + FORCEINLINE void SetAmbientCubeDynamicStateVertexShader( void ) + { + m_Storage.PutInt( CBCMD_SETAMBIENTCUBEDYNAMICSTATEVERTEXSHADER ); + } + + FORCEINLINE void SetPixelShaderFogParams( int nReg ) + { + m_Storage.PutInt( CBCMD_SETPIXELSHADERFOGPARAMS ); + m_Storage.PutInt( nReg ); + } + + FORCEINLINE void BindStandardTexture( Sampler_t nSampler, StandardTextureId_t nTextureId ) + { + m_Storage.PutInt( CBCMD_BIND_STANDARD_TEXTURE ); + m_Storage.PutInt( nSampler ); + m_Storage.PutInt( nTextureId ); + } + + + FORCEINLINE void BindTexture( Sampler_t nSampler, ShaderAPITextureHandle_t hTexture ) + { + Assert( hTexture != INVALID_SHADERAPI_TEXTURE_HANDLE ); + if ( hTexture != INVALID_SHADERAPI_TEXTURE_HANDLE ) + { + m_Storage.PutInt( CBCMD_BIND_SHADERAPI_TEXTURE_HANDLE ); + m_Storage.PutInt( nSampler ); + m_Storage.PutInt( hTexture ); + } + } + + FORCEINLINE void BindTexture( CBaseVSShader *pShader, Sampler_t nSampler, int nTextureVar, int nFrameVar ) + { + ShaderAPITextureHandle_t hTexture = pShader->GetShaderAPITextureBindHandle( nTextureVar, nFrameVar ); + BindTexture( nSampler, hTexture ); + } + + FORCEINLINE void BindMultiTexture( CBaseVSShader *pShader, Sampler_t nSampler1, Sampler_t nSampler2, int nTextureVar, int nFrameVar ) + { + ShaderAPITextureHandle_t hTexture = pShader->GetShaderAPITextureBindHandle( nTextureVar, nFrameVar, 0 ); + BindTexture( nSampler1, hTexture ); + hTexture = pShader->GetShaderAPITextureBindHandle( nTextureVar, nFrameVar, 1 ); + BindTexture( nSampler2, hTexture ); + } + + FORCEINLINE void SetPixelShaderIndex( int nIndex ) + { + m_Storage.PutInt( CBCMD_SET_PSHINDEX ); + m_Storage.PutInt( nIndex ); + } + + FORCEINLINE void SetVertexShaderIndex( int nIndex ) + { + m_Storage.PutInt( CBCMD_SET_VSHINDEX ); + m_Storage.PutInt( nIndex ); + } + + FORCEINLINE void SetDepthFeatheringPixelShaderConstant( int iConstant, float fDepthBlendScale ) + { + m_Storage.PutInt( CBCMD_SET_DEPTH_FEATHERING_CONST ); + m_Storage.PutInt( iConstant ); + m_Storage.PutFloat( fDepthBlendScale ); + } + + FORCEINLINE void Goto( uint8 *pCmdBuf ) + { + m_Storage.PutInt( CBCMD_JUMP ); + m_Storage.PutPtr( pCmdBuf ); + } + + FORCEINLINE void Call( uint8 *pCmdBuf ) + { + m_Storage.PutInt( CBCMD_JSR ); + m_Storage.PutPtr( pCmdBuf ); + } + + FORCEINLINE void Reset( void ) + { + m_Storage.Reset(); + } + + FORCEINLINE size_t Size( void ) const + { + return m_Storage.Size(); + } + + FORCEINLINE uint8 *Base( void ) + { + return m_Storage.Base(); + } + + + +}; + + +#endif // commandbuilder_h diff --git a/materialsystem/stdshaders/common_flashlight_fxc.h b/materialsystem/stdshaders/common_flashlight_fxc.h new file mode 100644 index 0000000..098f184 --- /dev/null +++ b/materialsystem/stdshaders/common_flashlight_fxc.h @@ -0,0 +1,821 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: Common pixel shader code specific to flashlights +// +// $NoKeywords: $ +// +//=============================================================================// +#ifndef COMMON_FLASHLIGHT_FXC_H_ +#define COMMON_FLASHLIGHT_FXC_H_ + +#include "common_ps_fxc.h" + + +// JasonM - TODO: remove this simpleton version +float DoShadow( sampler DepthSampler, float4 texCoord ) +{ + const float g_flShadowBias = 0.0005f; + float2 uoffset = float2( 0.5f/512.f, 0.0f ); + float2 voffset = float2( 0.0f, 0.5f/512.f ); + float3 projTexCoord = texCoord.xyz / texCoord.w; + float4 flashlightDepth = float4( tex2D( DepthSampler, projTexCoord + uoffset + voffset ).x, + tex2D( DepthSampler, projTexCoord + uoffset - voffset ).x, + tex2D( DepthSampler, projTexCoord - uoffset + voffset ).x, + tex2D( DepthSampler, projTexCoord - uoffset - voffset ).x ); + +# if ( defined( REVERSE_DEPTH_ON_X360 ) ) + { + flashlightDepth = 1.0f - flashlightDepth; + } +# endif + + float shadowed = 0.0f; + float z = texCoord.z/texCoord.w; + float4 dz = float4(z,z,z,z) - (flashlightDepth + float4( g_flShadowBias, g_flShadowBias, g_flShadowBias, g_flShadowBias)); + float4 shadow = float4(0.25f,0.25f,0.25f,0.25f); + + if( dz.x <= 0.0f ) + shadowed += shadow.x; + if( dz.y <= 0.0f ) + shadowed += shadow.y; + if( dz.z <= 0.0f ) + shadowed += shadow.z; + if( dz.w <= 0.0f ) + shadowed += shadow.w; + + return shadowed; +} + + +float DoShadowNvidiaRAWZOneTap( sampler DepthSampler, const float4 shadowMapPos ) +{ + float ooW = 1.0f / shadowMapPos.w; // 1 / w + float3 shadowMapCenter_objDepth = shadowMapPos.xyz * ooW; // Do both projections at once + + float2 shadowMapCenter = shadowMapCenter_objDepth.xy; // Center of shadow filter + float objDepth = shadowMapCenter_objDepth.z; // Object depth in shadow space + + float fDepth = dot(tex2D(DepthSampler, shadowMapCenter).arg, float3(0.996093809371817670572857294849, 0.0038909914428586627756752238080039, 1.5199185323666651467481343000015e-5)); + + return fDepth > objDepth; +} + + +float DoShadowNvidiaRAWZ( sampler DepthSampler, const float4 shadowMapPos ) +{ + float fE = 1.0f / 512.0f; // Epsilon + + float ooW = 1.0f / shadowMapPos.w; // 1 / w + float3 shadowMapCenter_objDepth = shadowMapPos.xyz * ooW; // Do both projections at once + + float2 shadowMapCenter = shadowMapCenter_objDepth.xy; // Center of shadow filter + float objDepth = shadowMapCenter_objDepth.z; // Object depth in shadow space + + float4 vDepths; + vDepths.x = dot(tex2D(DepthSampler, shadowMapCenter + float2( fE, fE )).arg, float3(0.996093809371817670572857294849, 0.0038909914428586627756752238080039, 1.5199185323666651467481343000015e-5)); + vDepths.y = dot(tex2D(DepthSampler, shadowMapCenter + float2( -fE, fE )).arg, float3(0.996093809371817670572857294849, 0.0038909914428586627756752238080039, 1.5199185323666651467481343000015e-5)); + vDepths.z = dot(tex2D(DepthSampler, shadowMapCenter + float2( fE, -fE )).arg, float3(0.996093809371817670572857294849, 0.0038909914428586627756752238080039, 1.5199185323666651467481343000015e-5)); + vDepths.w = dot(tex2D(DepthSampler, shadowMapCenter + float2( -fE, -fE )).arg, float3(0.996093809371817670572857294849, 0.0038909914428586627756752238080039, 1.5199185323666651467481343000015e-5)); + + return dot(vDepths > objDepth.xxxx, float4(0.25, 0.25, 0.25, 0.25)); +} + + +float DoShadowNvidiaCheap( sampler DepthSampler, const float4 shadowMapPos ) +{ + float fTexelEpsilon = 1.0f / 1024.0f; + + float ooW = 1.0f / shadowMapPos.w; // 1 / w + float3 shadowMapCenter_objDepth = shadowMapPos.xyz * ooW; // Do both projections at once + + float2 shadowMapCenter = shadowMapCenter_objDepth.xy; // Center of shadow filter + float objDepth = shadowMapCenter_objDepth.z; // Object depth in shadow space + + float4 vTaps; + vTaps.x = tex2Dproj( DepthSampler, float4( shadowMapCenter + float2( fTexelEpsilon, fTexelEpsilon), objDepth, 1 ) ).x; + vTaps.y = tex2Dproj( DepthSampler, float4( shadowMapCenter + float2( -fTexelEpsilon, fTexelEpsilon), objDepth, 1 ) ).x; + vTaps.z = tex2Dproj( DepthSampler, float4( shadowMapCenter + float2( fTexelEpsilon, -fTexelEpsilon), objDepth, 1 ) ).x; + vTaps.w = tex2Dproj( DepthSampler, float4( shadowMapCenter + float2( -fTexelEpsilon, -fTexelEpsilon), objDepth, 1 ) ).x; + + return dot(vTaps, float4(0.25, 0.25, 0.25, 0.25)); +} + +float DoShadowNvidiaPCF3x3Box( sampler DepthSampler, const float4 shadowMapPos ) +{ + float fTexelEpsilon = 1.0f / 1024.0f; + + float ooW = 1.0f / shadowMapPos.w; // 1 / w + float3 shadowMapCenter_objDepth = shadowMapPos.xyz * ooW; // Do both projections at once + + float2 shadowMapCenter = shadowMapCenter_objDepth.xy; // Center of shadow filter + float objDepth = shadowMapCenter_objDepth.z; // Object depth in shadow space + + float4 vOneTaps; + vOneTaps.x = tex2Dproj( DepthSampler, float4( shadowMapCenter + float2( fTexelEpsilon, fTexelEpsilon ), objDepth, 1 ) ).x; + vOneTaps.y = tex2Dproj( DepthSampler, float4( shadowMapCenter + float2( -fTexelEpsilon, fTexelEpsilon ), objDepth, 1 ) ).x; + vOneTaps.z = tex2Dproj( DepthSampler, float4( shadowMapCenter + float2( fTexelEpsilon, -fTexelEpsilon ), objDepth, 1 ) ).x; + vOneTaps.w = tex2Dproj( DepthSampler, float4( shadowMapCenter + float2( -fTexelEpsilon, -fTexelEpsilon ), objDepth, 1 ) ).x; + float flOneTaps = dot( vOneTaps, float4(1.0f / 9.0f, 1.0f / 9.0f, 1.0f / 9.0f, 1.0f / 9.0f)); + + float4 vTwoTaps; + vTwoTaps.x = tex2Dproj( DepthSampler, float4( shadowMapCenter + float2( fTexelEpsilon, 0 ), objDepth, 1 ) ).x; + vTwoTaps.y = tex2Dproj( DepthSampler, float4( shadowMapCenter + float2( -fTexelEpsilon, 0 ), objDepth, 1 ) ).x; + vTwoTaps.z = tex2Dproj( DepthSampler, float4( shadowMapCenter + float2( 0, -fTexelEpsilon ), objDepth, 1 ) ).x; + vTwoTaps.w = tex2Dproj( DepthSampler, float4( shadowMapCenter + float2( 0, -fTexelEpsilon ), objDepth, 1 ) ).x; + float flTwoTaps = dot( vTwoTaps, float4(1.0f / 9.0f, 1.0f / 9.0f, 1.0f / 9.0f, 1.0f / 9.0f)); + + float flCenterTap = tex2Dproj( DepthSampler, float4( shadowMapCenter, objDepth, 1 ) ).x * (1.0f / 9.0f); + + // Sum all 9 Taps + return flOneTaps + flTwoTaps + flCenterTap; +} + + +// +// 1 4 7 4 1 +// 4 20 33 20 4 +// 7 33 55 33 7 +// 4 20 33 20 4 +// 1 4 7 4 1 +// +float DoShadowNvidiaPCF5x5Gaussian( sampler DepthSampler, const float4 shadowMapPos ) +{ + float fEpsilon = 1.0f / 512.0f; + float fTwoEpsilon = 2.0f * fEpsilon; + + float ooW = 1.0f / shadowMapPos.w; // 1 / w + float3 shadowMapCenter_objDepth = shadowMapPos.xyz * ooW; // Do both projections at once + + float2 shadowMapCenter = shadowMapCenter_objDepth.xy; // Center of shadow filter + float objDepth = shadowMapCenter_objDepth.z; // Object depth in shadow space + + float4 vOneTaps; + vOneTaps.x = tex2Dproj( DepthSampler, float4( shadowMapCenter + float2( fTwoEpsilon, fTwoEpsilon ), objDepth, 1 ) ).x; + vOneTaps.y = tex2Dproj( DepthSampler, float4( shadowMapCenter + float2( -fTwoEpsilon, fTwoEpsilon ), objDepth, 1 ) ).x; + vOneTaps.z = tex2Dproj( DepthSampler, float4( shadowMapCenter + float2( fTwoEpsilon, -fTwoEpsilon ), objDepth, 1 ) ).x; + vOneTaps.w = tex2Dproj( DepthSampler, float4( shadowMapCenter + float2( -fTwoEpsilon, -fTwoEpsilon ), objDepth, 1 ) ).x; + float flOneTaps = dot( vOneTaps, float4(1.0f / 331.0f, 1.0f / 331.0f, 1.0f / 331.0f, 1.0f / 331.0f)); + + float4 vSevenTaps; + vSevenTaps.x = tex2Dproj( DepthSampler, float4( shadowMapCenter + float2( fTwoEpsilon, 0 ), objDepth, 1 ) ).x; + vSevenTaps.y = tex2Dproj( DepthSampler, float4( shadowMapCenter + float2( -fTwoEpsilon, 0 ), objDepth, 1 ) ).x; + vSevenTaps.z = tex2Dproj( DepthSampler, float4( shadowMapCenter + float2( 0, -fTwoEpsilon ), objDepth, 1 ) ).x; + vSevenTaps.w = tex2Dproj( DepthSampler, float4( shadowMapCenter + float2( 0, -fTwoEpsilon ), objDepth, 1 ) ).x; + float flSevenTaps = dot( vSevenTaps, float4( 7.0f / 331.0f, 7.0f / 331.0f, 7.0f / 331.0f, 7.0f / 331.0f ) ); + + float4 vFourTapsA, vFourTapsB; + vFourTapsA.x = tex2Dproj( DepthSampler, float4( shadowMapCenter + float2( fTwoEpsilon, fEpsilon ), objDepth, 1 ) ).x; + vFourTapsA.y = tex2Dproj( DepthSampler, float4( shadowMapCenter + float2( fEpsilon, fTwoEpsilon ), objDepth, 1 ) ).x; + vFourTapsA.z = tex2Dproj( DepthSampler, float4( shadowMapCenter + float2( -fEpsilon, fTwoEpsilon ), objDepth, 1 ) ).x; + vFourTapsA.w = tex2Dproj( DepthSampler, float4( shadowMapCenter + float2( -fTwoEpsilon, fEpsilon ), objDepth, 1 ) ).x; + vFourTapsB.x = tex2Dproj( DepthSampler, float4( shadowMapCenter + float2( -fTwoEpsilon, -fEpsilon ), objDepth, 1 ) ).x; + vFourTapsB.y = tex2Dproj( DepthSampler, float4( shadowMapCenter + float2( -fEpsilon, -fTwoEpsilon ), objDepth, 1 ) ).x; + vFourTapsB.z = tex2Dproj( DepthSampler, float4( shadowMapCenter + float2( fEpsilon, -fTwoEpsilon ), objDepth, 1 ) ).x; + vFourTapsB.w = tex2Dproj( DepthSampler, float4( shadowMapCenter + float2( fTwoEpsilon, -fEpsilon ), objDepth, 1 ) ).x; + float flFourTapsA = dot( vFourTapsA, float4( 4.0f / 331.0f, 4.0f / 331.0f, 4.0f / 331.0f, 4.0f / 331.0f ) ); + float flFourTapsB = dot( vFourTapsB, float4( 4.0f / 331.0f, 4.0f / 331.0f, 4.0f / 331.0f, 4.0f / 331.0f ) ); + + float4 v20Taps; + v20Taps.x = tex2Dproj( DepthSampler, float4( shadowMapCenter + float2( fEpsilon, fEpsilon ), objDepth, 1 ) ).x; + v20Taps.y = tex2Dproj( DepthSampler, float4( shadowMapCenter + float2( -fEpsilon, fEpsilon ), objDepth, 1 ) ).x; + v20Taps.z = tex2Dproj( DepthSampler, float4( shadowMapCenter + float2( fEpsilon, -fEpsilon ), objDepth, 1 ) ).x; + v20Taps.w = tex2Dproj( DepthSampler, float4( shadowMapCenter + float2( -fEpsilon, -fEpsilon ), objDepth, 1 ) ).x; + float fl20Taps = dot( v20Taps, float4(20.0f / 331.0f, 20.0f / 331.0f, 20.0f / 331.0f, 20.0f / 331.0f)); + + float4 v33Taps; + v33Taps.x = tex2Dproj( DepthSampler, float4( shadowMapCenter + float2( fEpsilon, 0 ), objDepth, 1 ) ).x; + v33Taps.y = tex2Dproj( DepthSampler, float4( shadowMapCenter + float2( -fEpsilon, 0 ), objDepth, 1 ) ).x; + v33Taps.z = tex2Dproj( DepthSampler, float4( shadowMapCenter + float2( 0, -fEpsilon ), objDepth, 1 ) ).x; + v33Taps.w = tex2Dproj( DepthSampler, float4( shadowMapCenter + float2( 0, -fEpsilon ), objDepth, 1 ) ).x; + float fl33Taps = dot( v33Taps, float4(33.0f / 331.0f, 33.0f / 331.0f, 33.0f / 331.0f, 33.0f / 331.0f)); + + float flCenterTap = tex2Dproj( DepthSampler, float4( shadowMapCenter, objDepth, 1 ) ).x * (55.0f / 331.0f); + + // Sum all 25 Taps + return flOneTaps + flSevenTaps + +flFourTapsA + flFourTapsB + fl20Taps + fl33Taps + flCenterTap; +} + + +float DoShadowATICheap( sampler DepthSampler, const float4 shadowMapPos ) +{ + float2 shadowMapCenter = shadowMapPos.xy/shadowMapPos.w; + float objDepth = shadowMapPos.z / shadowMapPos.w; + float fSampleDepth = tex2D( DepthSampler, shadowMapCenter ).x; + + objDepth = min( objDepth, 0.99999 ); //HACKHACK: On 360, surfaces at or past the far flashlight plane have an abrupt cutoff. This is temp until a smooth falloff is implemented + + return fSampleDepth > objDepth; +} + + +// Poisson disc, randomly rotated at different UVs +float DoShadowPoisson16Sample( sampler DepthSampler, sampler RandomRotationSampler, const float3 vProjCoords, const float2 vScreenPos, const float4 vShadowTweaks, bool bNvidiaHardwarePCF, bool bFetch4 ) +{ + float2 vPoissonOffset[8] = { float2( 0.3475f, 0.0042f ), + float2( 0.8806f, 0.3430f ), + float2( -0.0041f, -0.6197f ), + float2( 0.0472f, 0.4964f ), + float2( -0.3730f, 0.0874f ), + float2( -0.9217f, -0.3177f ), + float2( -0.6289f, 0.7388f ), + float2( 0.5744f, -0.7741f ) }; + + float flScaleOverMapSize = vShadowTweaks.x * 2; // Tweak parameters to shader + float2 vNoiseOffset = vShadowTweaks.zw; + float4 vLightDepths = 0, accum = 0.0f; + float2 rotOffset = 0; + + float2 shadowMapCenter = vProjCoords.xy; // Center of shadow filter + float objDepth = min( vProjCoords.z, 0.99999 ); // Object depth in shadow space + + // 2D Rotation Matrix setup + float3 RMatTop = 0, RMatBottom = 0; +#if defined(SHADER_MODEL_PS_2_0) || defined(SHADER_MODEL_PS_2_B) || defined(SHADER_MODEL_PS_3_0) + RMatTop.xy = tex2D( RandomRotationSampler, cFlashlightScreenScale.xy * (vScreenPos * 0.5 + 0.5) + vNoiseOffset) * 2.0 - 1.0; + RMatBottom.xy = float2(-1.0, 1.0) * RMatTop.yx; // 2x2 rotation matrix in 4-tuple +#endif + + RMatTop *= flScaleOverMapSize; // Scale up kernel while accounting for texture resolution + RMatBottom *= flScaleOverMapSize; + + RMatTop.z = shadowMapCenter.x; // To be added in d2adds generated below + RMatBottom.z = shadowMapCenter.y; + + float fResult = 0.0f; + + if ( bNvidiaHardwarePCF ) + { + rotOffset.x = dot (RMatTop.xy, vPoissonOffset[0].xy) + RMatTop.z; + rotOffset.y = dot (RMatBottom.xy, vPoissonOffset[0].xy) + RMatBottom.z; + vLightDepths.x += tex2Dproj( DepthSampler, float4(rotOffset, objDepth, 1) ).x; + + rotOffset.x = dot (RMatTop.xy, vPoissonOffset[1].xy) + RMatTop.z; + rotOffset.y = dot (RMatBottom.xy, vPoissonOffset[1].xy) + RMatBottom.z; + vLightDepths.y += tex2Dproj( DepthSampler, float4(rotOffset, objDepth, 1) ).x; + + rotOffset.x = dot (RMatTop.xy, vPoissonOffset[2].xy) + RMatTop.z; + rotOffset.y = dot (RMatBottom.xy, vPoissonOffset[2].xy) + RMatBottom.z; + vLightDepths.z += tex2Dproj( DepthSampler, float4(rotOffset, objDepth, 1) ).x; + + rotOffset.x = dot (RMatTop.xy, vPoissonOffset[3].xy) + RMatTop.z; + rotOffset.y = dot (RMatBottom.xy, vPoissonOffset[3].xy) + RMatBottom.z; + vLightDepths.w += tex2Dproj( DepthSampler, float4(rotOffset, objDepth, 1) ).x; + + rotOffset.x = dot (RMatTop.xy, vPoissonOffset[4].xy) + RMatTop.z; + rotOffset.y = dot (RMatBottom.xy, vPoissonOffset[4].xy) + RMatBottom.z; + vLightDepths.x += tex2Dproj( DepthSampler, float4(rotOffset, objDepth, 1) ).x; + + rotOffset.x = dot (RMatTop.xy, vPoissonOffset[5].xy) + RMatTop.z; + rotOffset.y = dot (RMatBottom.xy, vPoissonOffset[5].xy) + RMatBottom.z; + vLightDepths.y += tex2Dproj( DepthSampler, float4(rotOffset, objDepth, 1) ).x; + + rotOffset.x = dot (RMatTop.xy, vPoissonOffset[6].xy) + RMatTop.z; + rotOffset.y = dot (RMatBottom.xy, vPoissonOffset[6].xy) + RMatBottom.z; + vLightDepths.z += tex2Dproj( DepthSampler, float4(rotOffset, objDepth, 1) ).x; + + rotOffset.x = dot (RMatTop.xy, vPoissonOffset[7].xy) + RMatTop.z; + rotOffset.y = dot (RMatBottom.xy, vPoissonOffset[7].xy) + RMatBottom.z; + vLightDepths.w += tex2Dproj( DepthSampler, float4(rotOffset, objDepth, 1) ).x; + + fResult = dot( vLightDepths, float4( 0.25, 0.25, 0.25, 0.25) ); + } + else if ( bFetch4 ) + { +/* + +TODO: Fix this contact hardening stuff + + float flNumCloserSamples = 1; + float flAccumulatedCloserSamples = objDepth; + float4 vBlockerDepths; + + // First, search for blockers + for( int j=0; j<8; j++ ) + { + rotOffset.x = dot (RMatTop.xy, vPoissonOffset[j].xy) + RMatTop.z; + rotOffset.y = dot (RMatBottom.xy, vPoissonOffset[j].xy) + RMatBottom.z; + vBlockerDepths = tex2D( DepthSampler, rotOffset.xy ); + + // Which samples are closer than the pixel we're rendering? + float4 vCloserSamples = (vBlockerDepths < objDepth.xxxx ); // Binary comparison results + flNumCloserSamples += dot( vCloserSamples, float4(1, 1, 1, 1) ); // How many samples are closer than receiver? + flAccumulatedCloserSamples += dot (vCloserSamples, vBlockerDepths ); // Total depths from samples closer than receiver + } + + float flBlockerDepth = flAccumulatedCloserSamples / flNumCloserSamples; + float flContactHardeningScale = (objDepth - flBlockerDepth) / flBlockerDepth; + + // Scale the kernel + RMatTop.xy *= flContactHardeningScale; + RMatBottom.xy *= flContactHardeningScale; +*/ + + for( int i=0; i<8; i++ ) + { + rotOffset.x = dot (RMatTop.xy, vPoissonOffset[i].xy) + RMatTop.z; + rotOffset.y = dot (RMatBottom.xy, vPoissonOffset[i].xy) + RMatBottom.z; + vLightDepths = tex2D( DepthSampler, rotOffset.xy ); + accum += (vLightDepths > objDepth.xxxx); + } + + fResult = dot( accum, float4( 1.0f/32.0f, 1.0f/32.0f, 1.0f/32.0f, 1.0f/32.0f) ); + } + else // ATI vanilla hardware shadow mapping + { + for( int i=0; i<2; i++ ) + { + rotOffset.x = dot (RMatTop.xy, vPoissonOffset[4*i+0].xy) + RMatTop.z; + rotOffset.y = dot (RMatBottom.xy, vPoissonOffset[4*i+0].xy) + RMatBottom.z; + vLightDepths.x = tex2D( DepthSampler, rotOffset.xy ).x; + + rotOffset.x = dot (RMatTop.xy, vPoissonOffset[4*i+1].xy) + RMatTop.z; + rotOffset.y = dot (RMatBottom.xy, vPoissonOffset[4*i+1].xy) + RMatBottom.z; + vLightDepths.y = tex2D( DepthSampler, rotOffset.xy ).x; + + rotOffset.x = dot (RMatTop.xy, vPoissonOffset[4*i+2].xy) + RMatTop.z; + rotOffset.y = dot (RMatBottom.xy, vPoissonOffset[4*i+2].xy) + RMatBottom.z; + vLightDepths.z = tex2D( DepthSampler, rotOffset.xy ).x; + + rotOffset.x = dot (RMatTop.xy, vPoissonOffset[4*i+3].xy) + RMatTop.z; + rotOffset.y = dot (RMatBottom.xy, vPoissonOffset[4*i+3].xy) + RMatBottom.z; + vLightDepths.w = tex2D( DepthSampler, rotOffset.xy ).x; + + accum += (vLightDepths > objDepth.xxxx); + } + + fResult = dot( accum, float4( 0.125, 0.125, 0.125, 0.125) ); + } + + return fResult; +} + +#if defined( _X360 ) + +// Poisson disc, randomly rotated at different UVs +float DoShadow360Simple( sampler DepthSampler, const float3 vProjCoords ) +{ + float fLOD; + float2 shadowMapCenter = vProjCoords.xy; // Center of shadow filter + float objDepth = min( vProjCoords.z, 0.99999 ); // Object depth in shadow space + +#if defined( REVERSE_DEPTH_ON_X360 ) + objDepth = 1.0f - objDepth; +#endif + + float4 vSampledDepths, vWeights; + + asm { + getCompTexLOD2D fLOD.x, shadowMapCenter.xy, DepthSampler, AnisoFilter=max16to1 + setTexLOD fLOD.x + + tfetch2D vSampledDepths.x___, shadowMapCenter, DepthSampler, OffsetX = -0.5, OffsetY = -0.5, UseComputedLOD=false, UseRegisterLOD=true, MagFilter = point, MinFilter = point + tfetch2D vSampledDepths._x__, shadowMapCenter, DepthSampler, OffsetX = 0.5, OffsetY = -0.5, UseComputedLOD=false, UseRegisterLOD=true, MagFilter = point, MinFilter = point + tfetch2D vSampledDepths.__x_, shadowMapCenter, DepthSampler, OffsetX = -0.5, OffsetY = 0.5, UseComputedLOD=false, UseRegisterLOD=true, MagFilter = point, MinFilter = point + tfetch2D vSampledDepths.___x, shadowMapCenter, DepthSampler, OffsetX = 0.5, OffsetY = 0.5, UseComputedLOD=false, UseRegisterLOD=true, MagFilter = point, MinFilter = point + + getWeights2D vWeights, shadowMapCenter.xy, DepthSampler, MagFilter=linear, MinFilter=linear, UseComputedLOD=false, UseRegisterLOD=true + }; + + vWeights = float4( (1-vWeights.x)*(1-vWeights.y), vWeights.x*(1-vWeights.y), (1-vWeights.x)*vWeights.y, vWeights.x*vWeights.y ); + +#if defined( REVERSE_DEPTH_ON_X360 ) + float4 vCompare = (vSampledDepths < objDepth.xxxx); +#else + float4 vCompare = (vSampledDepths > objDepth.xxxx); +#endif + + return dot( vCompare, vWeights ); +} + + +float Do360PCFFetch( sampler DepthSampler, float2 tc, float objDepth ) +{ + float fLOD; + float4 vSampledDepths, vWeights; + + asm { + getCompTexLOD2D fLOD.x, tc.xy, DepthSampler, AnisoFilter=max16to1 + setTexLOD fLOD.x + + tfetch2D vSampledDepths.x___, tc, DepthSampler, OffsetX = -0.5, OffsetY = -0.5, UseComputedLOD=false, UseRegisterLOD=true, MagFilter = point, MinFilter = point + tfetch2D vSampledDepths._x__, tc, DepthSampler, OffsetX = 0.5, OffsetY = -0.5, UseComputedLOD=false, UseRegisterLOD=true, MagFilter = point, MinFilter = point + tfetch2D vSampledDepths.__x_, tc, DepthSampler, OffsetX = -0.5, OffsetY = 0.5, UseComputedLOD=false, UseRegisterLOD=true, MagFilter = point, MinFilter = point + tfetch2D vSampledDepths.___x, tc, DepthSampler, OffsetX = 0.5, OffsetY = 0.5, UseComputedLOD=false, UseRegisterLOD=true, MagFilter = point, MinFilter = point + + getWeights2D vWeights, tc.xy, DepthSampler, MagFilter=linear, MinFilter=linear, UseComputedLOD=false, UseRegisterLOD=true + }; + + vWeights = float4( (1-vWeights.x)*(1-vWeights.y), vWeights.x*(1-vWeights.y), (1-vWeights.x)*vWeights.y, vWeights.x*vWeights.y ); + +#if defined( REVERSE_DEPTH_ON_X360 ) + float4 vCompare = (vSampledDepths < objDepth.xxxx); +#else + float4 vCompare = (vSampledDepths > objDepth.xxxx); +#endif + + return dot( vCompare, vWeights ); +} + + + +float Do360NearestFetch( sampler DepthSampler, float2 tc, float objDepth ) +{ + float fLOD; + float4 vSampledDepth; + + asm { + getCompTexLOD2D fLOD.x, tc.xy, DepthSampler, AnisoFilter=max16to1 + setTexLOD fLOD.x + + tfetch2D vSampledDepth.x___, tc, DepthSampler, UseComputedLOD=false, UseRegisterLOD=true, MagFilter = point, MinFilter = point + }; + +#if defined( REVERSE_DEPTH_ON_X360 ) + return (vSampledDepth.x < objDepth.x); +#else + return (vSampledDepth.x > objDepth.x); +#endif + +} + + +float AmountShadowed_8Tap_360( sampler DepthSampler, float2 tc, float objDepth ) +{ + float fLOD; + float4 vSampledDepthsA, vSampledDepthsB; + + // Optimal 8 rooks pattern to get an idea about whether we're at a penumbra or not + // From [Kallio07] "Scanline Edge-Flag Algorithm for Antialiasing" + // + // +---+---+---+---+---+---+---+---+ + // | | | | | | o | | | + // +---+---+---+---+---+---+---+---+ + // | o | | | | | | | | + // +---+---+---+---+---+---+---+---+ + // | | | | o | | | | | + // +---+---+---+---+---+---+---+---+ + // | | | | | | | o | | + // +---+---+---+---+---+---+---+---+ + // | | o | | | | | | | + // +---+---+---+---+---+---+---+---+ + // | | | | | o | | | | + // +---+---+---+---+---+---+---+---+ + // | | | | | | | | o | + // +---+---+---+---+---+---+---+---+ + // | | | o | | | | | | + // +---+---+---+---+---+---+---+---+ + // + asm { + getCompTexLOD2D fLOD.x, tc.xy, DepthSampler, AnisoFilter=max16to1 + setTexLOD fLOD.x + + tfetch2D vSampledDepthsA.x___, tc, DepthSampler, OffsetX = -2.0, OffsetY = -1.5, UseComputedLOD=false, UseRegisterLOD=true, MagFilter = point, MinFilter = point + tfetch2D vSampledDepthsA._x__, tc, DepthSampler, OffsetX = -1.5, OffsetY = 0.5, UseComputedLOD=false, UseRegisterLOD=true, MagFilter = point, MinFilter = point + tfetch2D vSampledDepthsA.__x_, tc, DepthSampler, OffsetX = -1.0, OffsetY = 2.0, UseComputedLOD=false, UseRegisterLOD=true, MagFilter = point, MinFilter = point + tfetch2D vSampledDepthsA.___x, tc, DepthSampler, OffsetX = -0.5, OffsetY = -1.0, UseComputedLOD=false, UseRegisterLOD=true, MagFilter = point, MinFilter = point + + tfetch2D vSampledDepthsB.x___, tc, DepthSampler, OffsetX = 0.5, OffsetY = 1.0, UseComputedLOD=false, UseRegisterLOD=true, MagFilter = point, MinFilter = point + tfetch2D vSampledDepthsB._x__, tc, DepthSampler, OffsetX = 1.0, OffsetY = -2.0, UseComputedLOD=false, UseRegisterLOD=true, MagFilter = point, MinFilter = point + tfetch2D vSampledDepthsB.__x_, tc, DepthSampler, OffsetX = 1.5, OffsetY = -0.5, UseComputedLOD=false, UseRegisterLOD=true, MagFilter = point, MinFilter = point + tfetch2D vSampledDepthsB.___x, tc, DepthSampler, OffsetX = 2.0, OffsetY = 1.5, UseComputedLOD=false, UseRegisterLOD=true, MagFilter = point, MinFilter = point + }; + +#if defined( REVERSE_DEPTH_ON_X360 ) + float4 vCompareA = (vSampledDepthsA < objDepth.xxxx); + float4 vCompareB = (vSampledDepthsB < objDepth.xxxx); +#else + float4 vCompareA = (vSampledDepthsA > objDepth.xxxx); + float4 vCompareB = (vSampledDepthsB > objDepth.xxxx); +#endif + + return dot( vCompareA, float4(0.125,0.125,0.125,0.125) ) + dot( vCompareB, float4(0.125,0.125,0.125,0.125) ); +} + + +float AmountShadowed_4Tap_360( sampler DepthSampler, float2 tc, float objDepth ) +{ + float fLOD; + float4 vSampledDepths; + + // Rotated grid pattern to get an idea about whether we're at a penumbra or not + asm { + getCompTexLOD2D fLOD.x, tc.xy, DepthSampler, AnisoFilter=max16to1 + setTexLOD fLOD.x + + tfetch2D vSampledDepths.x___, tc, DepthSampler, OffsetX = -1.0, OffsetY = 0.5, UseComputedLOD=false, UseRegisterLOD=true, MagFilter = point, MinFilter = point + tfetch2D vSampledDepths._x__, tc, DepthSampler, OffsetX = -0.5, OffsetY = -1.0, UseComputedLOD=false, UseRegisterLOD=true, MagFilter = point, MinFilter = point + tfetch2D vSampledDepths.__x_, tc, DepthSampler, OffsetX = 0.5, OffsetY = 1.0, UseComputedLOD=false, UseRegisterLOD=true, MagFilter = point, MinFilter = point + tfetch2D vSampledDepths.___x, tc, DepthSampler, OffsetX = 1.0, OffsetY = -0.5, UseComputedLOD=false, UseRegisterLOD=true, MagFilter = point, MinFilter = point + }; + +#if defined( REVERSE_DEPTH_ON_X360 ) + float4 vCompare = (vSampledDepths < objDepth.xxxx); +#else + float4 vCompare = (vSampledDepths > objDepth.xxxx); +#endif + + return dot( vCompare, float4(0.25,0.25,0.25,0.25) ); +} + +// Poisson disc, randomly rotated at different UVs +float DoShadowPoisson360( sampler DepthSampler, sampler RandomRotationSampler, const float3 vProjCoords, const float2 vScreenPos, const float4 vShadowTweaks ) +{ + float2 vPoissonOffset[8] = { float2( 0.3475f, 0.0042f ), float2( 0.8806f, 0.3430f ), + float2( -0.0041f, -0.6197f ), float2( 0.0472f, 0.4964f ), + float2( -0.3730f, 0.0874f ), float2( -0.9217f, -0.3177f ), + float2( -0.6289f, 0.7388f ), float2( 0.5744f, -0.7741f ) }; + + float2 shadowMapCenter = vProjCoords.xy; // Center of shadow filter + float objDepth = min( vProjCoords.z, 0.99999 ); // Object depth in shadow space + +#if defined( REVERSE_DEPTH_ON_X360 ) + objDepth = 1.0f - objDepth; +#endif + + float fAmountShadowed = AmountShadowed_4Tap_360( DepthSampler, shadowMapCenter, objDepth ); + + if ( fAmountShadowed >= 1.0f ) // Fully in light + { + return 1.0f; + } + else // Do the expensive filtering since we're at least partially shadowed + { + float flScaleOverMapSize = 1.7f / 512.0f; // Tweak parameters to shader + + // 2D Rotation Matrix setup + float3 RMatTop = 0, RMatBottom = 0; +#if defined(SHADER_MODEL_PS_2_0) || defined(SHADER_MODEL_PS_2_B) || defined(SHADER_MODEL_PS_3_0) + RMatTop.xy = tex2D( RandomRotationSampler, cFlashlightScreenScale.xy * (vScreenPos * 0.5 + 0.5)) * 2.0 - 1.0; + RMatBottom.xy = float2(-1.0, 1.0) * RMatTop.yx; // 2x2 rotation matrix in 4-tuple +#endif + + RMatTop *= flScaleOverMapSize; // Scale up kernel while accounting for texture resolution + RMatBottom *= flScaleOverMapSize; + RMatTop.z = shadowMapCenter.x; // To be added in d2adds generated below + RMatBottom.z = shadowMapCenter.y; + float2 rotOffset = float2(0,0); + float4 vAccum = 0; + + rotOffset.x = dot (RMatTop.xy, vPoissonOffset[0].xy) + RMatTop.z; + rotOffset.y = dot (RMatBottom.xy, vPoissonOffset[0].xy) + RMatBottom.z; + vAccum.x = Do360NearestFetch( DepthSampler, rotOffset, objDepth ); + + rotOffset.x = dot (RMatTop.xy, vPoissonOffset[1].xy) + RMatTop.z; + rotOffset.y = dot (RMatBottom.xy, vPoissonOffset[1].xy) + RMatBottom.z; + vAccum.y = Do360NearestFetch( DepthSampler, rotOffset, objDepth ); + + rotOffset.x = dot (RMatTop.xy, vPoissonOffset[2].xy) + RMatTop.z; + rotOffset.y = dot (RMatBottom.xy, vPoissonOffset[2].xy) + RMatBottom.z; + vAccum.z = Do360NearestFetch( DepthSampler, rotOffset, objDepth ); + + rotOffset.x = dot (RMatTop.xy, vPoissonOffset[3].xy) + RMatTop.z; + rotOffset.y = dot (RMatBottom.xy, vPoissonOffset[3].xy) + RMatBottom.z; + vAccum.w = Do360NearestFetch( DepthSampler, rotOffset, objDepth ); + + rotOffset.x = dot (RMatTop.xy, vPoissonOffset[4].xy) + RMatTop.z; + rotOffset.y = dot (RMatBottom.xy, vPoissonOffset[4].xy) + RMatBottom.z; + vAccum.x += Do360NearestFetch( DepthSampler, rotOffset, objDepth ); + + rotOffset.x = dot (RMatTop.xy, vPoissonOffset[5].xy) + RMatTop.z; + rotOffset.y = dot (RMatBottom.xy, vPoissonOffset[5].xy) + RMatBottom.z; + vAccum.y += Do360NearestFetch( DepthSampler, rotOffset, objDepth ); + + rotOffset.x = dot (RMatTop.xy, vPoissonOffset[6].xy) + RMatTop.z; + rotOffset.y = dot (RMatBottom.xy, vPoissonOffset[6].xy) + RMatBottom.z; + vAccum.z += Do360NearestFetch( DepthSampler, rotOffset, objDepth ); + + rotOffset.x = dot (RMatTop.xy, vPoissonOffset[7].xy) + RMatTop.z; + rotOffset.y = dot (RMatBottom.xy, vPoissonOffset[7].xy) + RMatBottom.z; + vAccum.w += Do360NearestFetch( DepthSampler, rotOffset, objDepth ); + + return dot( vAccum, float4( 0.25, 0.25, 0.25, 0.25) ); + } +} + +#endif // _X360 + + +float DoFlashlightShadow( sampler DepthSampler, sampler RandomRotationSampler, float3 vProjCoords, float2 vScreenPos, int nShadowLevel, float4 vShadowTweaks, bool bAllowHighQuality ) +{ + float flShadow = 1.0f; + +#if !defined( _X360 ) //PC + if( nShadowLevel == NVIDIA_PCF_POISSON ) + flShadow = DoShadowPoisson16Sample( DepthSampler, RandomRotationSampler, vProjCoords, vScreenPos, vShadowTweaks, true, false ); + else if( nShadowLevel == ATI_NOPCF ) + flShadow = DoShadowPoisson16Sample( DepthSampler, RandomRotationSampler, vProjCoords, vScreenPos, vShadowTweaks, false, false ); + else if( nShadowLevel == ATI_NO_PCF_FETCH4 ) + flShadow = DoShadowPoisson16Sample( DepthSampler, RandomRotationSampler, vProjCoords, vScreenPos, vShadowTweaks, false, true ); + + return flShadow; +#else + + // Compile-time switch for shaders which allow high quality modes on 360 + if ( bAllowHighQuality ) + { + // Static control flow switch for shadow quality. Some non-interactive sequences use the high quality path + if ( g_bHighQualityShadows ) + { + flShadow = DoShadowPoisson360( DepthSampler, RandomRotationSampler, vProjCoords, vScreenPos, vShadowTweaks ); + } + else + { + flShadow = DoShadow360Simple( DepthSampler, vProjCoords ); + } + } + else + { + flShadow = DoShadow360Simple( DepthSampler, vProjCoords ); + } + + return flShadow; + +#endif +} + +float3 SpecularLight( const float3 vWorldNormal, const float3 vLightDir, const float fSpecularExponent, + const float3 vEyeDir, const bool bDoSpecularWarp, in sampler specularWarpSampler, float fFresnel ) +{ + float3 result = float3(0.0f, 0.0f, 0.0f); + + //float3 vReflect = reflect( -vEyeDir, vWorldNormal ); + float3 vReflect = 2 * vWorldNormal * dot( vWorldNormal , vEyeDir ) - vEyeDir; // Reflect view through normal + float3 vSpecular = saturate(dot( vReflect, vLightDir )); // L.R (use half-angle instead?) + vSpecular = pow( vSpecular.x, fSpecularExponent ); // Raise to specular power + + // Optionally warp as function of scalar specular and fresnel + if ( bDoSpecularWarp ) + vSpecular *= tex2D( specularWarpSampler, float2(vSpecular.x, fFresnel) ); // Sample at { (L.R)^k, fresnel } + + return vSpecular; +} + +void DoSpecularFlashlight( float3 flashlightPos, float3 worldPos, float4 flashlightSpacePosition, float3 worldNormal, + float3 attenuationFactors, float farZ, sampler FlashlightSampler, sampler FlashlightDepthSampler, sampler RandomRotationSampler, + int nShadowLevel, bool bDoShadows, bool bAllowHighQuality, const float2 vScreenPos, const float fSpecularExponent, const float3 vEyeDir, + const bool bDoSpecularWarp, sampler specularWarpSampler, float fFresnel, float4 vShadowTweaks, + + // Outputs of this shader...separate shadowed diffuse and specular from the flashlight + out float3 diffuseLighting, out float3 specularLighting ) +{ + float3 vProjCoords = flashlightSpacePosition.xyz / flashlightSpacePosition.w; + float3 flashlightColor = float3(1,1,1); + +#if ( defined( _X360 ) ) + + float3 ltz = vProjCoords.xyz < float3( 0.0f, 0.0f, 0.0f ); + float3 gto = vProjCoords.xyz > float3( 1.0f, 1.0f, 1.0f ); + + [branch] + if ( dot(ltz + gto, float3(1,1,1)) > 0 ) + { + clip(-1); + diffuseLighting = specularLighting = float3(0,0,0); + return; + } + else + { + flashlightColor = tex2D( FlashlightSampler, vProjCoords ); + + [branch] + if ( dot(flashlightColor.xyz, float3(1,1,1)) <= 0 ) + { + clip(-1); + diffuseLighting = specularLighting = float3(0,0,0); + return; + } + } +#else + flashlightColor = tex2D( FlashlightSampler, vProjCoords ); +#endif + + +#if defined(SHADER_MODEL_PS_2_0) || defined(SHADER_MODEL_PS_2_B) || defined(SHADER_MODEL_PS_3_0) + flashlightColor *= cFlashlightColor.xyz; // Flashlight color +#endif + + float3 delta = flashlightPos - worldPos; + float3 L = normalize( delta ); + float distSquared = dot( delta, delta ); + float dist = sqrt( distSquared ); + + float endFalloffFactor = RemapValClamped( dist, farZ, 0.6f * farZ, 0.0f, 1.0f ); + + // Attenuation for light and to fade out shadow over distance + float fAtten = saturate( dot( attenuationFactors, float3( 1.0f, 1.0f/dist, 1.0f/distSquared ) ) ); + + // Shadowing and coloring terms +#if (defined(SHADER_MODEL_PS_2_B) || defined(SHADER_MODEL_PS_3_0)) + if ( bDoShadows ) + { + float flShadow = DoFlashlightShadow( FlashlightDepthSampler, RandomRotationSampler, vProjCoords, vScreenPos, nShadowLevel, vShadowTweaks, bAllowHighQuality ); + float flAttenuated = lerp( flShadow, 1.0f, vShadowTweaks.y ); // Blend between fully attenuated and not attenuated + flShadow = saturate( lerp( flAttenuated, flShadow, fAtten ) ); // Blend between shadow and above, according to light attenuation + flashlightColor *= flShadow; // Shadow term + } +#endif + + diffuseLighting = fAtten; +#if defined(SHADER_MODEL_PS_2_0) || defined(SHADER_MODEL_PS_2_B) || defined(SHADER_MODEL_PS_3_0) + diffuseLighting *= saturate( dot( L.xyz, worldNormal.xyz ) + flFlashlightNoLambertValue ); // Lambertian term +#else + diffuseLighting *= saturate( dot( L.xyz, worldNormal.xyz ) ); // Lambertian (not Half-Lambert) term +#endif + diffuseLighting *= flashlightColor; + diffuseLighting *= endFalloffFactor; + + // Specular term (masked by diffuse) + specularLighting = diffuseLighting * SpecularLight ( worldNormal, L, fSpecularExponent, vEyeDir, bDoSpecularWarp, specularWarpSampler, fFresnel ); +} + +// Diffuse only version +float3 DoFlashlight( float3 flashlightPos, float3 worldPos, float4 flashlightSpacePosition, float3 worldNormal, + float3 attenuationFactors, float farZ, sampler FlashlightSampler, sampler FlashlightDepthSampler, + sampler RandomRotationSampler, int nShadowLevel, bool bDoShadows, bool bAllowHighQuality, + const float2 vScreenPos, bool bClip, float4 vShadowTweaks = float4(3/1024.0f, 0.0005f, 0.0f, 0.0f), bool bHasNormal = true ) +{ + float3 vProjCoords = flashlightSpacePosition.xyz / flashlightSpacePosition.w; + float3 flashlightColor = float3(1,1,1); + +#if ( defined( _X360 ) ) + + float3 ltz = vProjCoords.xyz < float3( 0.0f, 0.0f, 0.0f ); + float3 gto = vProjCoords.xyz > float3( 1.0f, 1.0f, 1.0f ); + + [branch] + if ( dot(ltz + gto, float3(1,1,1)) > 0 ) + { + if ( bClip ) + { + clip(-1); + } + return float3(0,0,0); + } + else + { + flashlightColor = tex2D( FlashlightSampler, vProjCoords ); + + [branch] + if ( dot(flashlightColor.xyz, float3(1,1,1)) <= 0 ) + { + if ( bClip ) + { + clip(-1); + } + return float3(0,0,0); + } + } +#else + flashlightColor = tex2D( FlashlightSampler, vProjCoords ); +#endif + +#if defined(SHADER_MODEL_PS_2_0) || defined(SHADER_MODEL_PS_2_B) || defined(SHADER_MODEL_PS_3_0) + flashlightColor *= cFlashlightColor.xyz; // Flashlight color +#endif + + float3 delta = flashlightPos - worldPos; + float3 L = normalize( delta ); + float distSquared = dot( delta, delta ); + float dist = sqrt( distSquared ); + + float endFalloffFactor = RemapValClamped( dist, farZ, 0.6f * farZ, 0.0f, 1.0f ); + + // Attenuation for light and to fade out shadow over distance + float fAtten = saturate( dot( attenuationFactors, float3( 1.0f, 1.0f/dist, 1.0f/distSquared ) ) ); + + // Shadowing and coloring terms +#if (defined(SHADER_MODEL_PS_2_B) || defined(SHADER_MODEL_PS_3_0)) + if ( bDoShadows ) + { + float flShadow = DoFlashlightShadow( FlashlightDepthSampler, RandomRotationSampler, vProjCoords, vScreenPos, nShadowLevel, vShadowTweaks, bAllowHighQuality ); + float flAttenuated = lerp( flShadow, 1.0f, vShadowTweaks.y ); // Blend between fully attenuated and not attenuated + flShadow = saturate( lerp( flAttenuated, flShadow, fAtten ) ); // Blend between shadow and above, according to light attenuation + flashlightColor *= flShadow; // Shadow term + } +#endif + + float3 diffuseLighting = fAtten; + + float flLDotWorldNormal; + if ( bHasNormal ) + { + flLDotWorldNormal = dot( L.xyz, worldNormal.xyz ); + } + else + { + flLDotWorldNormal = 1.0f; + } + +#if defined(SHADER_MODEL_PS_2_0) || defined(SHADER_MODEL_PS_2_B) || defined(SHADER_MODEL_PS_3_0) + diffuseLighting *= saturate( flLDotWorldNormal + flFlashlightNoLambertValue ); // Lambertian term +#else + diffuseLighting *= saturate( flLDotWorldNormal ); // Lambertian (not Half-Lambert) term +#endif + + diffuseLighting *= flashlightColor; + diffuseLighting *= endFalloffFactor; + + return diffuseLighting; +} + +#endif //#ifndef COMMON_FLASHLIGHT_FXC_H_ diff --git a/materialsystem/stdshaders/common_fxc.h b/materialsystem/stdshaders/common_fxc.h new file mode 100644 index 0000000..2103b3f --- /dev/null +++ b/materialsystem/stdshaders/common_fxc.h @@ -0,0 +1,326 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +// +//=============================================================================// +#ifndef COMMON_FXC_H_ +#define COMMON_FXC_H_ + +#include "common_pragmas.h" +#include "common_hlsl_cpp_consts.h" + +#ifdef NV3X +# define HALF half +# define HALF2 half2 +# define HALF3 half3 +# define HALF4 half4 +# define HALF3x3 half3x3 +# define HALF3x4 half3x4 +# define HALF4x3 half4x3 +# define HALF_CONSTANT( _constant ) ((HALF)_constant) +#else +# define HALF float +# define HALF2 float2 +# define HALF3 float3 +# define HALF4 float4 +# define HALF3x3 float3x3 +# define HALF3x4 float3x4 +# define HALF4x3 float4x3 +# define HALF_CONSTANT( _constant ) _constant +#endif + +// This is where all common code for both vertex and pixel shaders. +#define OO_SQRT_3 0.57735025882720947f +static const HALF3 bumpBasis[3] = { + HALF3( 0.81649661064147949f, 0.0f, OO_SQRT_3 ), + HALF3( -0.40824833512306213f, 0.70710676908493042f, OO_SQRT_3 ), + HALF3( -0.40824821591377258f, -0.7071068286895752f, OO_SQRT_3 ) +}; +static const HALF3 bumpBasisTranspose[3] = { + HALF3( 0.81649661064147949f, -0.40824833512306213f, -0.40824833512306213f ), + HALF3( 0.0f, 0.70710676908493042f, -0.7071068286895752f ), + HALF3( OO_SQRT_3, OO_SQRT_3, OO_SQRT_3 ) +}; + +#if defined( _X360 ) +#define REVERSE_DEPTH_ON_X360 //uncomment to use D3DFMT_D24FS8 with an inverted depth viewport for better performance. Keep this in sync with the same named #define in public/shaderapi/shareddefs.h +//Note that the reversal happens in the viewport. So ONLY reading back from a depth texture should be affected. Projected math is unaffected. +#endif + +HALF3 CalcReflectionVectorNormalized( HALF3 normal, HALF3 eyeVector ) +{ + // FIXME: might be better of normalizing with a normalizing cube map and + // get rid of the dot( normal, normal ) + // compute reflection vector r = 2 * ((n dot v)/(n dot n)) n - v + return 2.0 * ( dot( normal, eyeVector ) / dot( normal, normal ) ) * normal - eyeVector; +} + +HALF3 CalcReflectionVectorUnnormalized( HALF3 normal, HALF3 eyeVector ) +{ + // FIXME: might be better of normalizing with a normalizing cube map and + // get rid of the dot( normal, normal ) + // compute reflection vector r = 2 * ((n dot v)/(n dot n)) n - v + // multiply all values through by N.N. uniformly scaling reflection vector won't affect result + // since it is used in a cubemap lookup + return (2.0*(dot( normal, eyeVector ))*normal) - (dot( normal, normal )*eyeVector); +} + +float3 HuePreservingColorClamp( float3 c ) +{ + // Get the max of all of the color components and a specified maximum amount + float maximum = max( max( c.x, c.y ), max( c.z, 1.0f ) ); + + return (c / maximum); +} + +HALF3 HuePreservingColorClamp( HALF3 c, HALF maxVal ) +{ + // Get the max of all of the color components and a specified maximum amount + float maximum = max( max( c.x, c.y ), max( c.z, maxVal ) ); + return (c * ( maxVal / maximum ) ); +} + +#if (AA_CLAMP==1) +HALF2 ComputeLightmapCoordinates( HALF4 Lightmap1and2Coord, HALF2 Lightmap3Coord ) +{ + HALF2 result = saturate(Lightmap1and2Coord.xy) * Lightmap1and2Coord.wz * 0.99; + result += Lightmap3Coord; + return result; +} + +void ComputeBumpedLightmapCoordinates( HALF4 Lightmap1and2Coord, HALF2 Lightmap3Coord, + out HALF2 bumpCoord1, + out HALF2 bumpCoord2, + out HALF2 bumpCoord3 ) +{ + HALF2 result = saturate(Lightmap1and2Coord.xy) * Lightmap1and2Coord.wz * 0.99; + result += Lightmap3Coord; + bumpCoord1 = result + HALF2(Lightmap1and2Coord.z, 0); + bumpCoord2 = result + 2*HALF2(Lightmap1and2Coord.z, 0); + bumpCoord3 = result + 3*HALF2(Lightmap1and2Coord.z, 0); +} +#else +HALF2 ComputeLightmapCoordinates( HALF4 Lightmap1and2Coord, HALF2 Lightmap3Coord ) +{ + return Lightmap1and2Coord.xy; +} + +void ComputeBumpedLightmapCoordinates( HALF4 Lightmap1and2Coord, HALF2 Lightmap3Coord, + out HALF2 bumpCoord1, + out HALF2 bumpCoord2, + out HALF2 bumpCoord3 ) +{ + bumpCoord1 = Lightmap1and2Coord.xy; + bumpCoord2 = Lightmap1and2Coord.wz; // reversed order!!! + bumpCoord3 = Lightmap3Coord.xy; +} +#endif + +// Versions of matrix multiply functions which force HLSL compiler to explictly use DOTs, +// not giving it the option of using MAD expansion. In a perfect world, the compiler would +// always pick the best strategy, and these shouldn't be needed.. but.. well.. umm.. +// +// lorenmcq + +float3 mul3x3(float3 v, float3x3 m) +{ +#if !defined( _X360 ) + return float3(dot(v, transpose(m)[0]), dot(v, transpose(m)[1]), dot(v, transpose(m)[2])); +#else + // xbox360 fxc.exe (new back end) borks with transposes, generates bad code + return mul( v, m ); +#endif +} + +float3 mul4x3(float4 v, float4x3 m) +{ +#if !defined( _X360 ) + return float3(dot(v, transpose(m)[0]), dot(v, transpose(m)[1]), dot(v, transpose(m)[2])); +#else + // xbox360 fxc.exe (new back end) borks with transposes, generates bad code + return mul( v, m ); +#endif +} + +float3 DecompressHDR( float4 input ) +{ + return input.rgb * input.a * MAX_HDR_OVERBRIGHT; +} + +float4 CompressHDR( float3 input ) +{ + // FIXME: want to use min so that we clamp to white, but what happens if we + // have an albedo component that's less than 1/MAX_HDR_OVERBRIGHT? + // float fMax = max( max( color.r, color.g ), color.b ); + float4 output; + float fMax = min( min( input.r, input.g ), input.b ); + if( fMax > 1.0f ) + { + float oofMax = 1.0f / fMax; + output.rgb = oofMax * input.rgb; + output.a = min( fMax / MAX_HDR_OVERBRIGHT, 1.0f ); + } + else + { + output.rgb = input.rgb; + output.a = 0.0f; + } + return output; +} + + +float3 LinearToGamma( const float3 f3linear ) +{ + return pow( f3linear, 1.0f / 2.2f ); +} + +float4 LinearToGamma( const float4 f4linear ) +{ + return float4( pow( f4linear.xyz, 1.0f / 2.2f ), f4linear.w ); +} + +float LinearToGamma( const float f1linear ) +{ + return pow( f1linear, 1.0f / 2.2f ); +} + +float3 GammaToLinear( const float3 gamma ) +{ + return pow( gamma, 2.2f ); +} + +float4 GammaToLinear( const float4 gamma ) +{ + return float4( pow( gamma.xyz, 2.2f ), gamma.w ); +} + +float GammaToLinear( const float gamma ) +{ + return pow( gamma, 2.2f ); +} + +// These two functions use the actual sRGB math +float SrgbGammaToLinear( float flSrgbGammaValue ) +{ + float x = saturate( flSrgbGammaValue ); + return ( x <= 0.04045f ) ? ( x / 12.92f ) : ( pow( ( x + 0.055f ) / 1.055f, 2.4f ) ); +} + +float SrgbLinearToGamma( float flLinearValue ) +{ + float x = saturate( flLinearValue ); + return ( x <= 0.0031308f ) ? ( x * 12.92f ) : ( 1.055f * pow( x, ( 1.0f / 2.4f ) ) ) - 0.055f; +} + +// These twofunctions use the XBox 360's exact piecewise linear algorithm +float X360GammaToLinear( float fl360GammaValue ) +{ + float flLinearValue; + + fl360GammaValue = saturate( fl360GammaValue ); + if ( fl360GammaValue < ( 96.0f / 255.0f ) ) + { + if ( fl360GammaValue < ( 64.0f / 255.0f ) ) + { + flLinearValue = fl360GammaValue * 255.0f; + } + else + { + flLinearValue = fl360GammaValue * ( 255.0f * 2.0f ) - 64.0f; + flLinearValue += floor( flLinearValue * ( 1.0f / 512.0f ) ); + } + } + else + { + if( fl360GammaValue < ( 192.0f / 255.0f ) ) + { + flLinearValue = fl360GammaValue * ( 255.0f * 4.0f ) - 256.0f; + flLinearValue += floor( flLinearValue * ( 1.0f / 256.0f ) ); + } + else + { + flLinearValue = fl360GammaValue * ( 255.0f * 8.0f ) - 1024.0f; + flLinearValue += floor( flLinearValue * ( 1.0f / 128.0f ) ); + } + } + + flLinearValue *= 1.0f / 1023.0f; + + flLinearValue = saturate( flLinearValue ); + return flLinearValue; +} + +float X360LinearToGamma( float flLinearValue ) +{ + float fl360GammaValue; + + flLinearValue = saturate( flLinearValue ); + if ( flLinearValue < ( 128.0f / 1023.0f ) ) + { + if ( flLinearValue < ( 64.0f / 1023.0f ) ) + { + fl360GammaValue = flLinearValue * ( 1023.0f * ( 1.0f / 255.0f ) ); + } + else + { + fl360GammaValue = flLinearValue * ( ( 1023.0f / 2.0f ) * ( 1.0f / 255.0f ) ) + ( 32.0f / 255.0f ); + } + } + else + { + if ( flLinearValue < ( 512.0f / 1023.0f ) ) + { + fl360GammaValue = flLinearValue * ( ( 1023.0f / 4.0f ) * ( 1.0f / 255.0f ) ) + ( 64.0f / 255.0f ); + } + else + { + fl360GammaValue = flLinearValue * ( ( 1023.0f /8.0f ) * ( 1.0f / 255.0f ) ) + ( 128.0f /255.0f ); // 1.0 -> 1.0034313725490196078431372549016 + if ( fl360GammaValue > 1.0f ) + { + fl360GammaValue = 1.0f; + } + } + } + + fl360GammaValue = saturate( fl360GammaValue ); + return fl360GammaValue; +} + +float SrgbGammaTo360Gamma( float flSrgbGammaValue ) +{ + float flLinearValue = SrgbGammaToLinear( flSrgbGammaValue ); + float fl360GammaValue = X360LinearToGamma( flLinearValue ); + return fl360GammaValue; +} + +float3 Vec3WorldToTangent( float3 iWorldVector, float3 iWorldNormal, float3 iWorldTangent, float3 iWorldBinormal ) +{ + float3 vTangentVector; + vTangentVector.x = dot( iWorldVector.xyz, iWorldTangent.xyz ); + vTangentVector.y = dot( iWorldVector.xyz, iWorldBinormal.xyz ); + vTangentVector.z = dot( iWorldVector.xyz, iWorldNormal.xyz ); + return vTangentVector.xyz; // Return without normalizing +} + +float3 Vec3WorldToTangentNormalized( float3 iWorldVector, float3 iWorldNormal, float3 iWorldTangent, float3 iWorldBinormal ) +{ + return normalize( Vec3WorldToTangent( iWorldVector, iWorldNormal, iWorldTangent, iWorldBinormal ) ); +} + +float3 Vec3TangentToWorld( float3 iTangentVector, float3 iWorldNormal, float3 iWorldTangent, float3 iWorldBinormal ) +{ + float3 vWorldVector; + vWorldVector.xyz = iTangentVector.x * iWorldTangent.xyz; + vWorldVector.xyz += iTangentVector.y * iWorldBinormal.xyz; + vWorldVector.xyz += iTangentVector.z * iWorldNormal.xyz; + return vWorldVector.xyz; // Return without normalizing +} + +float3 Vec3TangentToWorldNormalized( float3 iTangentVector, float3 iWorldNormal, float3 iWorldTangent, float3 iWorldBinormal ) +{ + return normalize( Vec3TangentToWorld( iTangentVector, iWorldNormal, iWorldTangent, iWorldBinormal ) ); +} + +#endif //#ifndef COMMON_FXC_H_ diff --git a/materialsystem/stdshaders/common_fxc2.h b/materialsystem/stdshaders/common_fxc2.h new file mode 100644 index 0000000..33a25aa --- /dev/null +++ b/materialsystem/stdshaders/common_fxc2.h @@ -0,0 +1,19 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +// +//=============================================================================// +#ifndef COMMON_FXC2_H_ +#define COMMON_FXC2_H_ + +// This file is here so you can add new utility functions without +// changing common_fxc.h and causing a recompile of the entire universe. + +float LinearToMonochrome ( float3 r ) +{ + return dot( r, float3( 0.299f, 0.587f, 0.114f ) ); +} + +#endif //#ifndef COMMON_FXC2_H_ diff --git a/materialsystem/stdshaders/common_hlsl_cpp_consts.h b/materialsystem/stdshaders/common_hlsl_cpp_consts.h new file mode 100644 index 0000000..41bc715 --- /dev/null +++ b/materialsystem/stdshaders/common_hlsl_cpp_consts.h @@ -0,0 +1,27 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +// +//=============================================================================// +#ifndef COMMON_HLSL_CONSTS_H_ +#define COMMON_HLSL_CONSTS_H_ + +#ifdef NV3X + #define PSHADER_VECT_SCALE 20.0 + #define VSHADER_VECT_SCALE (1.0 / (PSHADER_VECT_SCALE) ) +#else + #define PSHADER_VECT_SCALE 1.0 + #define VSHADER_VECT_SCALE 1.0 +#endif + +// GR - HDR luminance maps to 0..n range +// IMPORTANT: Keep the same value as in materialsystem_global.h +// HDRFIXME: Make this a pixel shader constant? +#define MAX_HDR_OVERBRIGHT 16.0f + +#define LINEAR_FOG_COLOR 29 +#define TONE_MAPPING_SCALE_PSH_CONSTANT 30 + +#endif //#ifndef COMMON_HLSL_CONSTS_H_ diff --git a/materialsystem/stdshaders/common_lightmappedgeneric_fxc.h b/materialsystem/stdshaders/common_lightmappedgeneric_fxc.h new file mode 100644 index 0000000..aa67074 --- /dev/null +++ b/materialsystem/stdshaders/common_lightmappedgeneric_fxc.h @@ -0,0 +1,202 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// + + +#if defined( _X360 ) + +void GetBaseTextureAndNormal( sampler base, sampler base2, sampler bump, bool bBase2, bool bBump, float3 coords, float3 vWeights, + out float4 vResultBase, out float4 vResultBase2, out float4 vResultBump ) +{ + vResultBase = 0; + vResultBase2 = 0; + vResultBump = 0; + + if ( !bBump ) + { + vResultBump = float4(0, 0, 1, 1); + } + +#if SEAMLESS + + vWeights = max( vWeights - 0.3, 0 ); + + vWeights *= 1.0f / dot( vWeights, float3(1,1,1) ); + + [branch] + if (vWeights.x > 0) + { + vResultBase += vWeights.x * tex2D( base, coords.zy ); + + if ( bBase2 ) + { + vResultBase2 += vWeights.x * tex2D( base2, coords.zy ); + } + + if ( bBump ) + { + vResultBump += vWeights.x * tex2D( bump, coords.zy ); + } + } + + [branch] + if (vWeights.y > 0) + { + vResultBase += vWeights.y * tex2D( base, coords.xz ); + + if ( bBase2 ) + { + vResultBase2 += vWeights.y * tex2D( base2, coords.xz ); + } + if ( bBump ) + { + vResultBump += vWeights.y * tex2D( bump, coords.xz ); + } + } + + [branch] + if (vWeights.z > 0) + { + vResultBase += vWeights.z * tex2D( base, coords.xy ); + if ( bBase2 ) + { + vResultBase2 += vWeights.z * tex2D( base2, coords.xy ); + } + + if ( bBump ) + { + vResultBump += vWeights.z * tex2D( bump, coords.xy ); + } + } + +#else // not seamless + + vResultBase = tex2D( base, coords.xy ); + + if ( bBase2 ) + { + vResultBase2 = tex2D( base2, coords.xy ); + } + + if ( bBump ) + { + vResultBump = tex2D( bump, coords.xy ); + } + +#endif + + +} + +#else // PC + +void GetBaseTextureAndNormal( sampler base, sampler base2, sampler bump, bool bBase2, bool bBump, float3 coords, float3 vWeights, + out float4 vResultBase, out float4 vResultBase2, out float4 vResultBump ) +{ + vResultBase = 0; + vResultBase2 = 0; + vResultBump = 0; + + if ( !bBump ) + { + vResultBump = float4(0, 0, 1, 1); + } + +#if SEAMLESS + + vResultBase += vWeights.x * tex2D( base, coords.zy ); + if ( bBase2 ) + { + vResultBase2 += vWeights.x * tex2D( base2, coords.zy ); + } + if ( bBump ) + { + vResultBump += vWeights.x * tex2D( bump, coords.zy ); + } + + vResultBase += vWeights.y * tex2D( base, coords.xz ); + if ( bBase2 ) + { + vResultBase2 += vWeights.y * tex2D( base2, coords.xz ); + } + if ( bBump ) + { + vResultBump += vWeights.y * tex2D( bump, coords.xz ); + } + + vResultBase += vWeights.z * tex2D( base, coords.xy ); + if ( bBase2 ) + { + vResultBase2 += vWeights.z * tex2D( base2, coords.xy ); + } + if ( bBump ) + { + vResultBump += vWeights.z * tex2D( bump, coords.xy ); + } + +#else // not seamless + + vResultBase = tex2D( base, coords.xy ); + if ( bBase2 ) + { + vResultBase2 = tex2D( base2, coords.xy ); + } + if ( bBump ) + { + vResultBump = tex2D( bump, coords.xy ); + } +#endif + +} + +#endif + + + + +float3 LightMapSample( sampler LightmapSampler, float2 vTexCoord ) +{ +# if ( !defined( _X360 ) || !defined( USE_32BIT_LIGHTMAPS_ON_360 ) ) + { + float3 sample = tex2D( LightmapSampler, vTexCoord ); + + return sample; + } +# else + { +# if 0 //1 for cheap sampling, 0 for accurate scaling from the individual samples + { + float4 sample = tex2D( LightmapSampler, vTexCoord ); + + return sample.rgb * sample.a; + } +# else + { + float4 Weights; + float4 samples_0; //no arrays allowed in inline assembly + float4 samples_1; + float4 samples_2; + float4 samples_3; + + asm { + tfetch2D samples_0, vTexCoord.xy, LightmapSampler, OffsetX = -0.5, OffsetY = -0.5, MinFilter=point, MagFilter=point, MipFilter=keep, UseComputedLOD=false + tfetch2D samples_1, vTexCoord.xy, LightmapSampler, OffsetX = 0.5, OffsetY = -0.5, MinFilter=point, MagFilter=point, MipFilter=keep, UseComputedLOD=false + tfetch2D samples_2, vTexCoord.xy, LightmapSampler, OffsetX = -0.5, OffsetY = 0.5, MinFilter=point, MagFilter=point, MipFilter=keep, UseComputedLOD=false + tfetch2D samples_3, vTexCoord.xy, LightmapSampler, OffsetX = 0.5, OffsetY = 0.5, MinFilter=point, MagFilter=point, MipFilter=keep, UseComputedLOD=false + + getWeights2D Weights, vTexCoord.xy, LightmapSampler + }; + + Weights = float4( (1-Weights.x)*(1-Weights.y), Weights.x*(1-Weights.y), (1-Weights.x)*Weights.y, Weights.x*Weights.y ); + + float3 result; + 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); + + return result; + } +# endif + } +# endif +} + diff --git a/materialsystem/stdshaders/common_pragmas.h b/materialsystem/stdshaders/common_pragmas.h new file mode 100644 index 0000000..c22a76b --- /dev/null +++ b/materialsystem/stdshaders/common_pragmas.h @@ -0,0 +1,38 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: Common shader compiler pragmas +// +// $NoKeywords: $ +// +//=============================================================================// +#ifndef COMMON_PRAGMAS_H_ +#define COMMON_PRAGMAS_H_ + +// +// Validated shader models: +// +// SHADER_MODEL_VS_1_1 +// SHADER_MODEL_VS_2_0 +// SHADER_MODEL_VS_3_0 +// +// SHADER_MODEL_PS_1_1 +// SHADER_MODEL_PS_1_4 +// SHADER_MODEL_PS_2_0 +// SHADER_MODEL_PS_2_B +// SHADER_MODEL_PS_3_0 +// +// +// +// Platforms: +// +// PC +// _X360 +// + +// Special pragmas silencing common warnings +#pragma warning ( disable : 3557 ) // warning X3557: Loop only executes for N iteration(s), forcing loop to unroll +#pragma warning ( disable : 3595 ) // warning X3595: Microcode Compiler possible performance issue: pixel shader input semantic ___ is unused +#pragma warning ( disable : 3596 ) // warning X3596: Microcode Compiler possible performance issue: pixel shader input semantic ___ is unused +#pragma warning ( disable : 4702 ) // warning X4702: complement opportunity missed because input result WAS clamped from 0 to 1 + +#endif //#ifndef COMMON_PRAGMAS_H_ diff --git a/materialsystem/stdshaders/common_ps_fxc.h b/materialsystem/stdshaders/common_ps_fxc.h new file mode 100644 index 0000000..fca6511 --- /dev/null +++ b/materialsystem/stdshaders/common_ps_fxc.h @@ -0,0 +1,804 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: Common pixel shader code +// +// $NoKeywords: $ +// +//=============================================================================// +#ifndef COMMON_PS_FXC_H_ +#define COMMON_PS_FXC_H_ + +#include "common_fxc.h" + +// Put global skip commands here. . make sure and check that the appropriate vars are defined +// so these aren't used on the wrong shaders! + +// -------------------------------------------------------------------------------- +// HDR should never be enabled if we don't aren't running in float or integer HDR mode. +// SKIP: defined $HDRTYPE && defined $HDRENABLED && !$HDRTYPE && $HDRENABLED +// -------------------------------------------------------------------------------- +// We don't ever write water fog to dest alpha if we aren't doing water fog. +// SKIP: defined $PIXELFOGTYPE && defined $WRITEWATERFOGTODESTALPHA && ( $PIXELFOGTYPE != 1 ) && $WRITEWATERFOGTODESTALPHA +// -------------------------------------------------------------------------------- +// We don't need fog in the pixel shader if we aren't in float fog mode2 +// NOSKIP: defined $HDRTYPE && defined $HDRENABLED && defined $PIXELFOGTYPE && $HDRTYPE != HDR_TYPE_FLOAT && $FOGTYPE != 0 +// -------------------------------------------------------------------------------- +// We don't do HDR and LIGHTING_PREVIEW at the same time since it's running LDR in hammer. +// SKIP: defined $LIGHTING_PREVIEW && defined $HDRTYPE && $LIGHTING_PREVIEW && $HDRTYPE != 0 +// -------------------------------------------------------------------------------- +// Ditch all fastpath attempts if we are doing LIGHTING_PREVIEW. +// SKIP: defined $LIGHTING_PREVIEW && defined $FASTPATHENVMAPTINT && $LIGHTING_PREVIEW && $FASTPATHENVMAPTINT +// SKIP: defined $LIGHTING_PREVIEW && defined $FASTPATHENVMAPCONTRAST && $LIGHTING_PREVIEW && $FASTPATHENVMAPCONTRAST +// SKIP: defined $LIGHTING_PREVIEW && defined $FASTPATH && $LIGHTING_PREVIEW && $FASTPATH +// -------------------------------------------------------------------------------- +// Ditch flashlight depth when flashlight is disabled +// SKIP: ($FLASHLIGHT || $FLASHLIGHTSHADOWS) && $LIGHTING_PREVIEW +// -------------------------------------------------------------------------------- + +// System defined pixel shader constants + +#if defined( _X360 ) +const bool g_bHighQualityShadows : register( b0 ); +#endif + +// NOTE: w == 1.0f / (Dest alpha compressed depth range). +const float4 g_LinearFogColor : register( c29 ); +#define OO_DESTALPHA_DEPTH_RANGE (g_LinearFogColor.w) + +// Linear and gamma light scale values +const float4 cLightScale : register( c30 ); +#define LINEAR_LIGHT_SCALE (cLightScale.x) +#define LIGHT_MAP_SCALE (cLightScale.y) +#define ENV_MAP_SCALE (cLightScale.z) +#define GAMMA_LIGHT_SCALE (cLightScale.w) + +// Flashlight constants +#if defined(SHADER_MODEL_PS_2_0) || defined(SHADER_MODEL_PS_2_B) || defined(SHADER_MODEL_PS_3_0) + const float4 cFlashlightColor : register( c28 ); + const float4 cFlashlightScreenScale : register( c31 ); // .zw are currently unused + #define flFlashlightNoLambertValue cFlashlightColor.w // This is either 0.0 or 2.0 +#endif + +#define HDR_INPUT_MAP_SCALE 16.0f + +#define TONEMAP_SCALE_NONE 0 +#define TONEMAP_SCALE_LINEAR 1 +#define TONEMAP_SCALE_GAMMA 2 + +#define PIXEL_FOG_TYPE_NONE -1 //MATERIAL_FOG_NONE is handled by PIXEL_FOG_TYPE_RANGE, this is for explicitly disabling fog in the shader +#define PIXEL_FOG_TYPE_RANGE 0 //range+none packed together in ps2b. Simply none in ps20 (instruction limits) +#define PIXEL_FOG_TYPE_HEIGHT 1 + +// If you change these, make the corresponding change in hardwareconfig.cpp +#define NVIDIA_PCF_POISSON 0 +#define ATI_NOPCF 1 +#define ATI_NO_PCF_FETCH4 2 + +struct LPREVIEW_PS_OUT +{ + float4 color : COLOR0; + float4 normal : COLOR1; + float4 position : COLOR2; + float4 flags : COLOR3; +}; + +/* +// unused +HALF Luminance( HALF3 color ) +{ + return dot( color, HALF3( HALF_CONSTANT(0.30f), HALF_CONSTANT(0.59f), HALF_CONSTANT(0.11f) ) ); +} +*/ + +/* +// unused +HALF LuminanceScaled( HALF3 color ) +{ + return dot( color, HALF3( HALF_CONSTANT(0.30f) / MAX_HDR_OVERBRIGHT, HALF_CONSTANT(0.59f) / MAX_HDR_OVERBRIGHT, HALF_CONSTANT(0.11f) / MAX_HDR_OVERBRIGHT ) ); +} +*/ + +/* +// unused +HALF AvgColor( HALF3 color ) +{ + return dot( color, HALF3( HALF_CONSTANT(0.33333f), HALF_CONSTANT(0.33333f), HALF_CONSTANT(0.33333f) ) ); +} +*/ + +/* +// unused +HALF4 DiffuseBump( sampler lightmapSampler, + float2 lightmapTexCoord1, + float2 lightmapTexCoord2, + float2 lightmapTexCoord3, + HALF3 normal ) +{ + HALF3 lightmapColor1 = tex2D( lightmapSampler, lightmapTexCoord1 ); + HALF3 lightmapColor2 = tex2D( lightmapSampler, lightmapTexCoord2 ); + HALF3 lightmapColor3 = tex2D( lightmapSampler, lightmapTexCoord3 ); + + HALF3 diffuseLighting; + diffuseLighting = saturate( dot( normal, bumpBasis[0] ) ) * lightmapColor1 + + saturate( dot( normal, bumpBasis[1] ) ) * lightmapColor2 + + saturate( dot( normal, bumpBasis[2] ) ) * lightmapColor3; + + return HALF4( diffuseLighting, LuminanceScaled( diffuseLighting ) ); +} +*/ + + +/* +// unused +HALF Fresnel( HALF3 normal, + HALF3 eye, + HALF2 scaleBias ) +{ + HALF fresnel = HALF_CONSTANT(1.0f) - dot( normal, eye ); + fresnel = pow( fresnel, HALF_CONSTANT(5.0f) ); + + return fresnel * scaleBias.x + scaleBias.y; +} +*/ + +/* +// unused +HALF4 GetNormal( sampler normalSampler, + float2 normalTexCoord ) +{ + HALF4 normal = tex2D( normalSampler, normalTexCoord ); + normal.rgb = HALF_CONSTANT(2.0f) * normal.rgb - HALF_CONSTANT(1.0f); + + return normal; +} +*/ + +// Needs to match NormalDecodeMode_t enum in imaterialsystem.h +#define NORM_DECODE_NONE 0 +#define NORM_DECODE_ATI2N 1 +#define NORM_DECODE_ATI2N_ALPHA 2 + +float4 DecompressNormal( sampler NormalSampler, float2 tc, int nDecompressionMode, sampler AlphaSampler ) +{ + float4 normalTexel = tex2D( NormalSampler, tc ); + float4 result; + + if ( nDecompressionMode == NORM_DECODE_NONE ) + { + result = float4(normalTexel.xyz * 2.0f - 1.0f, normalTexel.a ); + } + else if ( nDecompressionMode == NORM_DECODE_ATI2N ) + { + result.xy = normalTexel.xy * 2.0f - 1.0f; + result.z = sqrt( 1.0f - dot(result.xy, result.xy) ); + result.a = 1.0f; + } + else // ATI2N plus ATI1N for alpha + { + result.xy = normalTexel.xy * 2.0f - 1.0f; + result.z = sqrt( 1.0f - dot(result.xy, result.xy) ); + result.a = tex2D( AlphaSampler, tc ).x; // Note that this comes in on the X channel + } + + return result; +} + +float4 DecompressNormal( sampler NormalSampler, float2 tc, int nDecompressionMode ) +{ + return DecompressNormal( NormalSampler, tc, nDecompressionMode, NormalSampler ); +} + + +HALF3 NormalizeWithCubemap( sampler normalizeSampler, HALF3 input ) +{ +// return texCUBE( normalizeSampler, input ) * 2.0f - 1.0f; + return texCUBE( normalizeSampler, input ); +} + +/* +HALF4 EnvReflect( sampler envmapSampler, + sampler normalizeSampler, + HALF3 normal, + float3 eye, + HALF2 fresnelScaleBias ) +{ + HALF3 normEye = NormalizeWithCubemap( normalizeSampler, eye ); + HALF fresnel = Fresnel( normal, normEye, fresnelScaleBias ); + HALF3 reflect = CalcReflectionVectorUnnormalized( normal, eye ); + return texCUBE( envmapSampler, reflect ); +} +*/ + +float CalcWaterFogAlpha( const float flWaterZ, const float flEyePosZ, const float flWorldPosZ, const float flProjPosZ, const float flFogOORange ) +{ +// float flDepthFromWater = flWaterZ - flWorldPosZ + 2.0f; // hackity hack . .this is for the DF_FUDGE_UP in view_scene.cpp + float flDepthFromWater = flWaterZ - flWorldPosZ; + + // if flDepthFromWater < 0, then set it to 0 + // This is the equivalent of moving the vert to the water surface if it's above the water surface + // We'll do this with the saturate at the end instead. +// flDepthFromWater = max( 0.0f, flDepthFromWater ); + + // Calculate the ratio of water fog to regular fog (ie. how much of the distance from the viewer + // to the vert is actually underwater. + float flDepthFromEye = flEyePosZ - flWorldPosZ; + float f = saturate(flDepthFromWater * (1.0/flDepthFromEye)); + + // $tmp.w is now the distance that we see through water. + return saturate(f * flProjPosZ * flFogOORange); +} + +float CalcRangeFog( const float flProjPosZ, const float flFogStartOverRange, const float flFogMaxDensity, const float flFogOORange ) +{ +#if !(defined(SHADER_MODEL_PS_1_1) || defined(SHADER_MODEL_PS_1_4) || defined(SHADER_MODEL_PS_2_0)) //Minimum requirement of ps2b + return saturate( min( flFogMaxDensity, (flProjPosZ * flFogOORange) - flFogStartOverRange ) ); +#else + return 0.0f; //ps20 shaders will never have range fog enabled because too many ran out of slots. +#endif +} + +float CalcPixelFogFactor( int iPIXELFOGTYPE, const float4 fogParams, const float flEyePosZ, const float flWorldPosZ, const float flProjPosZ ) +{ + float retVal; + if ( iPIXELFOGTYPE == PIXEL_FOG_TYPE_NONE ) + { + retVal = 0.0f; + } + if ( iPIXELFOGTYPE == PIXEL_FOG_TYPE_RANGE ) //range fog, or no fog depending on fog parameters + { + retVal = CalcRangeFog( flProjPosZ, fogParams.x, fogParams.z, fogParams.w ); + } + else if ( iPIXELFOGTYPE == PIXEL_FOG_TYPE_HEIGHT ) //height fog + { + retVal = CalcWaterFogAlpha( fogParams.y, flEyePosZ, flWorldPosZ, flProjPosZ, fogParams.w ); + } + + return retVal; +} + +//g_FogParams not defined by default, but this is the same layout for every shader that does define it +#define g_FogEndOverRange g_FogParams.x +#define g_WaterZ g_FogParams.y +#define g_FogMaxDensity g_FogParams.z +#define g_FogOORange g_FogParams.w + +float3 BlendPixelFog( const float3 vShaderColor, float pixelFogFactor, const float3 vFogColor, const int iPIXELFOGTYPE ) +{ + if( iPIXELFOGTYPE == PIXEL_FOG_TYPE_RANGE ) //either range fog or no fog depending on fog parameters and whether this is ps20 or ps2b + { +# if !(defined(SHADER_MODEL_PS_1_1) || defined(SHADER_MODEL_PS_1_4) || defined(SHADER_MODEL_PS_2_0)) //Minimum requirement of ps2b + pixelFogFactor = saturate( pixelFogFactor ); + return lerp( vShaderColor.rgb, vFogColor.rgb, pixelFogFactor * pixelFogFactor ); //squaring the factor will get the middle range mixing closer to hardware fog +# else + return vShaderColor; +# endif + } + else if( iPIXELFOGTYPE == PIXEL_FOG_TYPE_HEIGHT ) + { + return lerp( vShaderColor.rgb, vFogColor.rgb, saturate( pixelFogFactor ) ); + } + else if( iPIXELFOGTYPE == PIXEL_FOG_TYPE_NONE ) + { + return vShaderColor; + } +} + + +#if ((defined(SHADER_MODEL_PS_2_B) || defined(SHADER_MODEL_PS_3_0)) && ( CONVERT_TO_SRGB != 0 ) ) +sampler1D GammaTableSampler : register( s15 ); + +float3 SRGBOutput( const float3 vShaderColor ) +{ + //On ps2b capable hardware we always have the linear->gamma conversion table texture in sampler s15. + float3 result; + result.r = tex1D( GammaTableSampler, vShaderColor.r ).r; + result.g = tex1D( GammaTableSampler, vShaderColor.g ).r; + result.b = tex1D( GammaTableSampler, vShaderColor.b ).r; + return result; +} + +#else + +float3 SRGBOutput( const float3 vShaderColor ) +{ + return vShaderColor; //ps 1.1, 1.4, and 2.0 never do srgb conversion in the pixel shader +} + +#endif + + +float SoftParticleDepth( float flDepth ) +{ + return flDepth * OO_DESTALPHA_DEPTH_RANGE; +} + + +float DepthToDestAlpha( const float flProjZ ) +{ +#if !(defined(SHADER_MODEL_PS_1_1) || defined(SHADER_MODEL_PS_1_4) || defined(SHADER_MODEL_PS_2_0)) //Minimum requirement of ps2b + return SoftParticleDepth( flProjZ ); +#else + return 1.0f; +#endif +} + + +float4 FinalOutput( const float4 vShaderColor, float pixelFogFactor, const int iPIXELFOGTYPE, const int iTONEMAP_SCALE_TYPE, const bool bWriteDepthToDestAlpha = false, const float flProjZ = 1.0f ) +{ + float4 result; + if( iTONEMAP_SCALE_TYPE == TONEMAP_SCALE_LINEAR ) + { + result.rgb = vShaderColor.rgb * LINEAR_LIGHT_SCALE; + } + else if( iTONEMAP_SCALE_TYPE == TONEMAP_SCALE_GAMMA ) + { + result.rgb = vShaderColor.rgb * GAMMA_LIGHT_SCALE; + } + else if( iTONEMAP_SCALE_TYPE == TONEMAP_SCALE_NONE ) + { + result.rgb = vShaderColor.rgb; + } + + if( bWriteDepthToDestAlpha ) + result.a = DepthToDestAlpha( flProjZ ); + else + result.a = vShaderColor.a; + + result.rgb = BlendPixelFog( result.rgb, pixelFogFactor, g_LinearFogColor.rgb, iPIXELFOGTYPE ); + +#if !(defined(SHADER_MODEL_PS_1_1) || defined(SHADER_MODEL_PS_1_4) || defined(SHADER_MODEL_PS_2_0)) //Minimum requirement of ps2b + result.rgb = SRGBOutput( result.rgb ); //SRGB in pixel shader conversion +#endif + + return result; +} + +LPREVIEW_PS_OUT FinalOutput( const LPREVIEW_PS_OUT vShaderColor, float pixelFogFactor, const int iPIXELFOGTYPE, const int iTONEMAP_SCALE_TYPE ) +{ + LPREVIEW_PS_OUT result; + result.color = FinalOutput( vShaderColor.color, pixelFogFactor, iPIXELFOGTYPE, iTONEMAP_SCALE_TYPE ); + result.normal.rgb = SRGBOutput( vShaderColor.normal.rgb ); + result.normal.a = vShaderColor.normal.a; + + result.position.rgb = SRGBOutput( vShaderColor.position.rgb ); + result.position.a = vShaderColor.position.a; + + result.flags.rgb = SRGBOutput( vShaderColor.flags.rgb ); + result.flags.a = vShaderColor.flags.a; + + return result; +} + + + + +float RemapValClamped( float val, float A, float B, float C, float D) +{ + float cVal = (val - A) / (B - A); + cVal = saturate( cVal ); + + return C + (D - C) * cVal; +} + + +//===================================================================================// +// This is based on Natasha Tatarchuk's Parallax Occlusion Mapping (ATI) +//===================================================================================// +// INPUT: +// inTexCoord: +// the texcoord for the height/displacement map before parallaxing +// +// vParallax: +// Compute initial parallax displacement direction: +// float2 vParallaxDirection = normalize( vViewTS.xy ); +// float fLength = length( vViewTS ); +// float fParallaxLength = sqrt( fLength * fLength - vViewTS.z * vViewTS.z ) / vViewTS.z; +// Out.vParallax = vParallaxDirection * fParallaxLength * fProjectedBumpHeight; +// +// vNormal: +// tangent space normal +// +// vViewW: +// float3 vViewW = /*normalize*/(mul( matViewInverse, float4( 0, 0, 0, 1)) - inPosition ); +// +// OUTPUT: +// the new texcoord after parallaxing +float2 CalcParallaxedTexCoord( float2 inTexCoord, float2 vParallax, float3 vNormal, + float3 vViewW, sampler HeightMapSampler ) +{ + const int nMinSamples = 8; + const int nMaxSamples = 50; + + // Normalize the incoming view vector to avoid artifacts: +// vView = normalize( vView ); + vViewW = normalize( vViewW ); +// vLight = normalize( vLight ); + + // Change the number of samples per ray depending on the viewing angle + // for the surface. Oblique angles require smaller step sizes to achieve + // more accurate precision + int nNumSteps = (int) lerp( nMaxSamples, nMinSamples, dot( vViewW, vNormal ) ); + + float4 cResultColor = float4( 0, 0, 0, 1 ); + + //===============================================// + // Parallax occlusion mapping offset computation // + //===============================================// + float fCurrHeight = 0.0; + float fStepSize = 1.0 / (float) nNumSteps; + float fPrevHeight = 1.0; + float fNextHeight = 0.0; + + int nStepIndex = 0; +// bool bCondition = true; + + float2 dx = ddx( inTexCoord ); + float2 dy = ddy( inTexCoord ); + + float2 vTexOffsetPerStep = fStepSize * vParallax; + + float2 vTexCurrentOffset = inTexCoord; + float fCurrentBound = 1.0; + + float x = 0; + float y = 0; + float xh = 0; + float yh = 0; + + float2 texOffset2 = 0; + + bool bCondition = true; + while ( bCondition == true && nStepIndex < nNumSteps ) + { + vTexCurrentOffset -= vTexOffsetPerStep; + + fCurrHeight = tex2Dgrad( HeightMapSampler, vTexCurrentOffset, dx, dy ).r; + + fCurrentBound -= fStepSize; + + if ( fCurrHeight > fCurrentBound ) + { + x = fCurrentBound; + y = fCurrentBound + fStepSize; + xh = fCurrHeight; + yh = fPrevHeight; + + texOffset2 = vTexCurrentOffset - vTexOffsetPerStep; + + bCondition = false; + } + else + { + nStepIndex++; + fPrevHeight = fCurrHeight; + } + + } // End of while ( bCondition == true && nStepIndex > -1 )#else + + fCurrentBound -= fStepSize; + + float fParallaxAmount; + float numerator = (x * (y - yh) - y * (x - xh)); + float denomenator = ((y - yh) - (x - xh)); + // avoid NaN generation + if( ( numerator == 0.0f ) && ( denomenator == 0.0f ) ) + { + fParallaxAmount = 0.0f; + } + else + { + fParallaxAmount = numerator / denomenator; + } + + float2 vParallaxOffset = vParallax * (1 - fParallaxAmount ); + + // Sample the height at the next possible step: + fNextHeight = tex2Dgrad( HeightMapSampler, texOffset2, dx, dy ).r; + + // Original offset: + float2 texSampleBase = inTexCoord - vParallaxOffset; + + return texSampleBase; + +#if 0 + cResultColor.rgb = ComputeDiffuseColor( texSampleBase, vLight ); + + float fBound = 1.0 - fStepSize * nStepIndex; + if ( fNextHeight < fCurrentBound ) +// if( 0 ) + { + //void DoIteration( in float2 vParallaxJittered, in float3 vLight, inout float4 cResultColor ) + //cResultColor.rgb = float3(1,0,0); + DoIteration( vParallax + vPixelSize, vLight, fStepSize, inTexCoord, nStepIndex, dx, dy, fBound, cResultColor ); + DoIteration( vParallax - vPixelSize, vLight, fStepSize, inTexCoord, nStepIndex, dx, dy, fBound, cResultColor ); + DoIteration( vParallax + float2( -vPixelSize.x, vPixelSize.y ), vLight, fStepSize, inTexCoord, nStepIndex, dx, dy, fBound, cResultColor ); + DoIteration( vParallax + float2( vPixelSize.x, -vPixelSize.y ), vLight, fStepSize, inTexCoord, nStepIndex, dx, dy, fBound, cResultColor ); + + cResultColor.rgb /= 5; +// cResultColor.rgb = float3( 1.0f, 0.0f, 0.0f ); + } // End of if ( fNextHeight < fCurrentBound ) + +#if DOSHADOWS + { + //============================================// + // Soft shadow and self-occlusion computation // + //============================================// + // Compute the blurry shadows (note that this computation takes into + // account self-occlusion for shadow computation): + float sh0 = tex2D( sNormalMap, texSampleBase).w; + float shA = (tex2D( sNormalMap, texSampleBase + inXY * 0.88 ).w - sh0 - 0.88 ) * 1 * fShadowSoftening; + float sh9 = (tex2D( sNormalMap, texSampleBase + inXY * 0.77 ).w - sh0 - 0.77 ) * 2 * fShadowSoftening; + float sh8 = (tex2D( sNormalMap, texSampleBase + inXY * 0.66 ).w - sh0 - 0.66 ) * 4 * fShadowSoftening; + float sh7 = (tex2D( sNormalMap, texSampleBase + inXY * 0.55 ).w - sh0 - 0.55 ) * 6 * fShadowSoftening; + float sh6 = (tex2D( sNormalMap, texSampleBase + inXY * 0.44 ).w - sh0 - 0.44 ) * 8 * fShadowSoftening; + float sh5 = (tex2D( sNormalMap, texSampleBase + inXY * 0.33 ).w - sh0 - 0.33 ) * 10 * fShadowSoftening; + float sh4 = (tex2D( sNormalMap, texSampleBase + inXY * 0.22 ).w - sh0 - 0.22 ) * 12 * fShadowSoftening; + + // Compute the actual shadow strength: + float fShadow = 1 - max( max( max( max( max( max( shA, sh9 ), sh8 ), sh7 ), sh6 ), sh5 ), sh4 ); + + cResultColor.rgb *= fShadow * 0.6 + 0.4; + } +#endif + + return cResultColor; +#endif +} + + +//======================================// +// HSL Color space conversion routines // +//======================================// + +#define HUE 0 +#define SATURATION 1 +#define LIGHTNESS 2 + +// Convert from RGB to HSL color space +float4 RGBtoHSL( float4 inColor ) +{ + float h, s; + float flMax = max( inColor.r, max( inColor.g, inColor.b ) ); + float flMin = min( inColor.r, min( inColor.g, inColor.b ) ); + + float l = (flMax + flMin) / 2.0f; + + if (flMax == flMin) // achromatic case + { + s = h = 0; + } + else // chromatic case + { + // Next, calculate the hue + float delta = flMax - flMin; + + // First, calculate the saturation + if (l < 0.5f) // If we're in the lower hexcone + { + s = delta/(flMax + flMin); + } + else + { + s = delta/(2 - flMax - flMin); + } + + if ( inColor.r == flMax ) + { + h = (inColor.g - inColor.b)/delta; // color between yellow and magenta + } + else if ( inColor.g == flMax ) + { + h = 2 + (inColor.b - inColor.r)/delta; // color between cyan and yellow + } + else // blue must be max + { + h = 4 + (inColor.r - inColor.g)/delta; // color between magenta and cyan + } + + h *= 60.0f; + + if (h < 0.0f) + { + h += 360.0f; + } + + h /= 360.0f; + } + + return float4 (h, s, l, 1.0f); +} + +float HueToRGB( float v1, float v2, float vH ) +{ + float fResult = v1; + + vH = fmod (vH + 1.0f, 1.0f); + + if ( ( 6.0f * vH ) < 1.0f ) + { + fResult = ( v1 + ( v2 - v1 ) * 6.0f * vH ); + } + else if ( ( 2.0f * vH ) < 1.0f ) + { + fResult = ( v2 ); + } + else if ( ( 3.0f * vH ) < 2.0f ) + { + fResult = ( v1 + ( v2 - v1 ) * ( ( 2.0f / 3.0f ) - vH ) * 6.0f ); + } + + return fResult; +} + +// Convert from HSL to RGB color space +float4 HSLtoRGB( float4 hsl ) +{ + float r, g, b; + float h = hsl[HUE]; + float s = hsl[SATURATION]; + float l = hsl[LIGHTNESS]; + + if ( s == 0 ) + { + r = g = b = l; + } + else + { + float v1, v2; + + if ( l < 0.5f ) + v2 = l * ( 1.0f + s ); + else + v2 = ( l + s ) - ( s * l ); + + v1 = 2 * l - v2; + + r = HueToRGB( v1, v2, h + ( 1.0f / 3.0f ) ); + g = HueToRGB( v1, v2, h ); + b = HueToRGB( v1, v2, h - ( 1.0f / 3.0f ) ); + } + + return float4( r, g, b, 1.0f ); +} + + +// texture combining modes for combining base and detail/basetexture2 +#define TCOMBINE_RGB_EQUALS_BASE_x_DETAILx2 0 // original mode +#define TCOMBINE_RGB_ADDITIVE 1 // base.rgb+detail.rgb*fblend +#define TCOMBINE_DETAIL_OVER_BASE 2 +#define TCOMBINE_FADE 3 // straight fade between base and detail. +#define TCOMBINE_BASE_OVER_DETAIL 4 // use base alpha for blend over detail +#define TCOMBINE_RGB_ADDITIVE_SELFILLUM 5 // add detail color post lighting +#define TCOMBINE_RGB_ADDITIVE_SELFILLUM_THRESHOLD_FADE 6 +#define TCOMBINE_MOD2X_SELECT_TWO_PATTERNS 7 // use alpha channel of base to select between mod2x channels in r+a of detail +#define TCOMBINE_MULTIPLY 8 +#define TCOMBINE_MASK_BASE_BY_DETAIL_ALPHA 9 // use alpha channel of detail to mask base +#define TCOMBINE_SSBUMP_BUMP 10 // use detail to modulate lighting as an ssbump +#define TCOMBINE_SSBUMP_NOBUMP 11 // detail is an ssbump but use it as an albedo. shader does the magic here - no user needs to specify mode 11 + +float4 TextureCombine( float4 baseColor, float4 detailColor, int combine_mode, + float fBlendFactor ) +{ + if ( combine_mode == TCOMBINE_MOD2X_SELECT_TWO_PATTERNS) + { + float3 dc=lerp(detailColor.r,detailColor.a, baseColor.a); + baseColor.rgb*=lerp(float3(1,1,1),2.0*dc,fBlendFactor); + } + if ( combine_mode == TCOMBINE_RGB_EQUALS_BASE_x_DETAILx2) + baseColor.rgb*=lerp(float3(1,1,1),2.0*detailColor.rgb,fBlendFactor); + if ( combine_mode == TCOMBINE_RGB_ADDITIVE ) + baseColor.rgb += fBlendFactor * detailColor.rgb; + if ( combine_mode == TCOMBINE_DETAIL_OVER_BASE ) + { + float fblend=fBlendFactor * detailColor.a; + baseColor.rgb = lerp( baseColor.rgb, detailColor.rgb, fblend); + } + if ( combine_mode == TCOMBINE_FADE ) + { + baseColor = lerp( baseColor, detailColor, fBlendFactor); + } + if ( combine_mode == TCOMBINE_BASE_OVER_DETAIL ) + { + float fblend=fBlendFactor * (1-baseColor.a); + baseColor.rgb = lerp( baseColor.rgb, detailColor.rgb, fblend ); + baseColor.a = detailColor.a; + } + if ( combine_mode == TCOMBINE_MULTIPLY ) + { + baseColor = lerp( baseColor, baseColor*detailColor, fBlendFactor); + } + + if (combine_mode == TCOMBINE_MASK_BASE_BY_DETAIL_ALPHA ) + { + baseColor.a = lerp( baseColor.a, baseColor.a*detailColor.a, fBlendFactor ); + } + if ( combine_mode == TCOMBINE_SSBUMP_NOBUMP ) + { + baseColor.rgb = baseColor.rgb * dot( detailColor.rgb, 2.0/3.0 ); + } + return baseColor; +} + +float3 lerp5(float3 f1, float3 f2, float i1, float i2, float x) +{ + return f1+(f2-f1)*(x-i1)/(i2-i1); +} + +float3 TextureCombinePostLighting( float3 lit_baseColor, float4 detailColor, int combine_mode, + float fBlendFactor ) +{ + if ( combine_mode == TCOMBINE_RGB_ADDITIVE_SELFILLUM ) + lit_baseColor += fBlendFactor * detailColor.rgb; + if ( combine_mode == TCOMBINE_RGB_ADDITIVE_SELFILLUM_THRESHOLD_FADE ) + { + // fade in an unusual way - instead of fading out color, remap an increasing band of it from + // 0..1 + //if (fBlendFactor > 0.5) + // lit_baseColor += min(1, (1.0/fBlendFactor)*max(0, detailColor.rgb-(1-fBlendFactor) ) ); + //else + // lit_baseColor += 2*fBlendFactor*2*max(0, detailColor.rgb-.5); + + float f = fBlendFactor - 0.5; + float fMult = (f >= 0) ? 1.0/fBlendFactor : 4*fBlendFactor; + float fAdd = (f >= 0) ? 1.0-fMult : -0.5*fMult; + lit_baseColor += saturate(fMult * detailColor.rgb + fAdd); + } + return lit_baseColor; +} + +//NOTE: On X360. fProjZ is expected to be pre-reversed for cheaper math here in the pixel shader +float DepthFeathering( sampler DepthSampler, const float2 vScreenPos, float fProjZ, float fProjW, float4 vDepthBlendConstants ) +{ +# if ( !(defined(SHADER_MODEL_PS_1_1) || defined(SHADER_MODEL_PS_1_4) || defined(SHADER_MODEL_PS_2_0)) ) //minimum requirement of ps2b + { + float flFeatheredAlpha; + float2 flDepths; +#define flSceneDepth flDepths.x +#define flSpriteDepth flDepths.y + +# if ( defined( _X360 ) ) + { + //Get depth from the depth texture. Need to sample with the offset of (0.5, 0.5) to fix rounding errors + asm { + tfetch2D flDepths.x___, vScreenPos, DepthSampler, OffsetX=0.5, OffsetY=0.5, MinFilter=point, MagFilter=point, MipFilter=point + }; + +# if( !defined( REVERSE_DEPTH_ON_X360 ) ) + flSceneDepth = 1.0f - flSceneDepth; +# endif + + //get the sprite depth into the same range as the texture depth + flSpriteDepth = fProjZ / fProjW; + + //unproject to get at the pre-projection z. This value is much more linear than depth + flDepths = vDepthBlendConstants.z / flDepths; + flDepths = vDepthBlendConstants.y - flDepths; + + flFeatheredAlpha = flSceneDepth - flSpriteDepth; + flFeatheredAlpha *= vDepthBlendConstants.x; + flFeatheredAlpha = saturate( flFeatheredAlpha ); + } +# else + { + flSceneDepth = tex2D( DepthSampler, vScreenPos ).a; // PC uses dest alpha of the frame buffer + flSpriteDepth = SoftParticleDepth( fProjZ ); + + flFeatheredAlpha = abs(flSceneDepth - flSpriteDepth) * vDepthBlendConstants.x; + flFeatheredAlpha = max( smoothstep( 0.75f, 1.0f, flSceneDepth ), flFeatheredAlpha ); //as the sprite approaches the edge of our compressed depth space, the math stops working. So as the sprite approaches the far depth, smoothly remove feathering. + flFeatheredAlpha = saturate( flFeatheredAlpha ); + } +# endif + +#undef flSceneDepth +#undef flSpriteDepth + + return flFeatheredAlpha; + } +# else + { + return 1.0f; + } +# endif +} + +#endif //#ifndef COMMON_PS_FXC_H_ diff --git a/materialsystem/stdshaders/common_vertexlitgeneric_dx9.h b/materialsystem/stdshaders/common_vertexlitgeneric_dx9.h new file mode 100644 index 0000000..2eb7bb3 --- /dev/null +++ b/materialsystem/stdshaders/common_vertexlitgeneric_dx9.h @@ -0,0 +1,423 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +#ifndef COMMON_VERTEXLITGENERIC_DX9_H_ +#define COMMON_VERTEXLITGENERIC_DX9_H_ + +#include "common_ps_fxc.h" + +// We store four light colors and positions in an +// array of three of these structures like so: +// +// x y z w +// +------+------+------+------+ +// | L0.rgb | | +// +------+------+------+ | +// | L0.pos | L3 | +// +------+------+------+ rgb | +// | L1.rgb | | +// +------+------+------+------+ +// | L1.pos | | +// +------+------+------+ | +// | L2.rgb | L3 | +// +------+------+------+ pos | +// | L2.pos | | +// +------+------+------+------+ +// +struct PixelShaderLightInfo +{ + float4 color; + float4 pos; +}; + +#define cOverbright 2.0f +#define cOOOverbright 0.5f + +#define LIGHTTYPE_NONE 0 +#define LIGHTTYPE_SPOT 1 +#define LIGHTTYPE_POINT 2 +#define LIGHTTYPE_DIRECTIONAL 3 + +// Better suited to Pixel shader models, 11 instructions in pixel shader +// ... actually, now only 9: mul, cmp, cmp, mul, mad, mad, mad, mad, mad +float3 PixelShaderAmbientLight( const float3 worldNormal, const float3 cAmbientCube[6] ) +{ + float3 linearColor, nSquared = worldNormal * worldNormal; + float3 isNegative = ( worldNormal >= 0.0 ) ? 0 : nSquared; + float3 isPositive = ( worldNormal >= 0.0 ) ? nSquared : 0; + linearColor = isPositive.x * cAmbientCube[0] + isNegative.x * cAmbientCube[1] + + isPositive.y * cAmbientCube[2] + isNegative.y * cAmbientCube[3] + + isPositive.z * cAmbientCube[4] + isNegative.z * cAmbientCube[5]; + return linearColor; +} + +// Better suited to Vertex shader models +// Six VS instructions due to use of constant indexing (slt, mova, mul, mul, mad, mad) +float3 VertexShaderAmbientLight( const float3 worldNormal, const float3 cAmbientCube[6] ) +{ + float3 nSquared = worldNormal * worldNormal; + int3 isNegative = ( worldNormal < 0.0 ); + float3 linearColor; + linearColor = nSquared.x * cAmbientCube[isNegative.x] + + nSquared.y * cAmbientCube[isNegative.y+2] + + nSquared.z * cAmbientCube[isNegative.z+4]; + return linearColor; +} + +float3 AmbientLight( const float3 worldNormal, const float3 cAmbientCube[6] ) +{ + // Vertex shader cases +#ifdef SHADER_MODEL_VS_1_0 + return VertexShaderAmbientLight( worldNormal, cAmbientCube ); +#elif SHADER_MODEL_VS_1_1 + return VertexShaderAmbientLight( worldNormal, cAmbientCube ); +#elif SHADER_MODEL_VS_2_0 + return VertexShaderAmbientLight( worldNormal, cAmbientCube ); +#elif SHADER_MODEL_VS_3_0 + return VertexShaderAmbientLight( worldNormal, cAmbientCube ); +#else + // Pixel shader case + return PixelShaderAmbientLight( worldNormal, cAmbientCube ); +#endif +} + +//----------------------------------------------------------------------------- +// Purpose: Compute scalar diffuse term with various optional tweaks such as +// Half Lambert and ambient occlusion +//----------------------------------------------------------------------------- +float3 DiffuseTerm(const bool bHalfLambert, const float3 worldNormal, const float3 lightDir, + const bool bDoAmbientOcclusion, const float fAmbientOcclusion, + const bool bDoLightingWarp, in sampler lightWarpSampler ) +{ + float fResult; + + float NDotL = dot( worldNormal, lightDir ); // Unsaturated dot (-1 to 1 range) + + if ( bHalfLambert ) + { + fResult = saturate(NDotL * 0.5 + 0.5); // Scale and bias to 0 to 1 range + + if ( !bDoLightingWarp ) + { + fResult *= fResult; // Square + } + } + else + { + fResult = saturate( NDotL ); // Saturate pure Lambertian term + } + + if ( bDoAmbientOcclusion ) + { + // Raise to higher powers for darker AO values +// float fAOPower = lerp( 4.0f, 1.0f, fAmbientOcclusion ); +// result *= pow( NDotL * 0.5 + 0.5, fAOPower ); + fResult *= fAmbientOcclusion; + } + + float3 fOut = float3( fResult, fResult, fResult ); + if ( bDoLightingWarp ) + { + fOut = 2.0f * tex1D( lightWarpSampler, fResult ); + } + + return fOut; +} + +float3 PixelShaderDoGeneralDiffuseLight( const float fAtten, const float3 worldPos, const float3 worldNormal, + in sampler NormalizeSampler, + const float3 vPosition, const float3 vColor, const bool bHalfLambert, + const bool bDoAmbientOcclusion, const float fAmbientOcclusion, + const bool bDoLightingWarp, in sampler lightWarpSampler ) +{ +#if (defined(SHADER_MODEL_PS_2_B) || defined(SHADER_MODEL_PS_3_0)) + float3 lightDir = normalize( vPosition - worldPos ); +#else + float3 lightDir = NormalizeWithCubemap( NormalizeSampler, vPosition - worldPos ); +#endif + return vColor * fAtten * DiffuseTerm( bHalfLambert, worldNormal, lightDir, bDoAmbientOcclusion, fAmbientOcclusion, bDoLightingWarp, lightWarpSampler ); +} + +float3 PixelShaderGetLightVector( const float3 worldPos, PixelShaderLightInfo cLightInfo[3], int nLightIndex ) +{ + if ( nLightIndex == 3 ) + { + // Unpack light 3 from w components... + float3 vLight3Pos = float3( cLightInfo[1].pos.w, cLightInfo[2].color.w, cLightInfo[2].pos.w ); + return normalize( vLight3Pos - worldPos ); + } + else + { + return normalize( cLightInfo[nLightIndex].pos - worldPos ); + } +} + +float3 PixelShaderGetLightColor( PixelShaderLightInfo cLightInfo[3], int nLightIndex ) +{ + if ( nLightIndex == 3 ) + { + // Unpack light 3 from w components... + return float3( cLightInfo[0].color.w, cLightInfo[0].pos.w, cLightInfo[1].color.w ); + } + else + { + return cLightInfo[nLightIndex].color.rgb; + } +} + + +void SpecularAndRimTerms( const float3 vWorldNormal, const float3 vLightDir, const float fSpecularExponent, + const float3 vEyeDir, const bool bDoAmbientOcclusion, const float fAmbientOcclusion, + const bool bDoSpecularWarp, in sampler specularWarpSampler, const float fFresnel, + const float3 color, const bool bDoRimLighting, const float fRimExponent, + + // Outputs + out float3 specularLighting, out float3 rimLighting ) +{ + rimLighting = float3(0.0f, 0.0f, 0.0f); + + //float3 vReflect = reflect( -vEyeDir, vWorldNormal ); // Reflect view through normal + float3 vReflect = 2 * vWorldNormal * dot( vWorldNormal , vEyeDir ) - vEyeDir; // Reflect view through normal + float LdotR = saturate(dot( vReflect, vLightDir )); // L.R (use half-angle instead?) + specularLighting = pow( LdotR, fSpecularExponent ); // Raise to specular exponent + + // Optionally warp as function of scalar specular and fresnel + if ( bDoSpecularWarp ) + specularLighting *= tex2D( specularWarpSampler, float2(specularLighting.x, fFresnel) ); // Sample at { (L.R)^k, fresnel } + + specularLighting *= saturate(dot( vWorldNormal, vLightDir )); // Mask with N.L + specularLighting *= color; // Modulate with light color + + if ( bDoAmbientOcclusion ) // Optionally modulate with ambient occlusion + specularLighting *= fAmbientOcclusion; + + if ( bDoRimLighting ) // Optionally do rim lighting + { + rimLighting = pow( LdotR, fRimExponent ); // Raise to rim exponent + rimLighting *= saturate(dot( vWorldNormal, vLightDir )); // Mask with N.L + rimLighting *= color; // Modulate with light color + } +} + +// Traditional fresnel term approximation +float Fresnel( const float3 vNormal, const float3 vEyeDir ) +{ + float fresnel = saturate( 1 - dot( vNormal, vEyeDir ) ); // 1-(N.V) for Fresnel term + return fresnel * fresnel; // Square for a more subtle look +} + +// Traditional fresnel term approximation which uses 4th power (square twice) +float Fresnel4( const float3 vNormal, const float3 vEyeDir ) +{ + float fresnel = saturate( 1 - dot( vNormal, vEyeDir ) ); // 1-(N.V) for Fresnel term + fresnel = fresnel * fresnel; // Square + return fresnel * fresnel; // Square again for a more subtle look +} + + +// +// Custom Fresnel with low, mid and high parameters defining a piecewise continuous function +// with traditional fresnel (0 to 1 range) as input. The 0 to 0.5 range blends between +// low and mid while the 0.5 to 1 range blends between mid and high +// +// | +// | . M . . . H +// | . +// L +// | +// +---------------- +// 0 1 +// +float Fresnel( const float3 vNormal, const float3 vEyeDir, float3 vRanges ) +{ + //float result, f = Fresnel( vNormal, vEyeDir ); // Traditional Fresnel + //if ( f > 0.5f ) + // result = lerp( vRanges.y, vRanges.z, (2*f)-1 ); // Blend between mid and high values + //else + // result = lerp( vRanges.x, vRanges.y, 2*f ); // Blend between low and mid values + + // note: vRanges is now encoded as ((mid-min)*2, mid, (max-mid)*2) to optimize math + float f = saturate( 1 - dot( vNormal, vEyeDir ) ); + f = f*f - 0.5; + return vRanges.y + (f >= 0.0 ? vRanges.z : vRanges.x) * f; +} + +void PixelShaderDoSpecularLight( const float3 vWorldPos, const float3 vWorldNormal, const float fSpecularExponent, const float3 vEyeDir, + const float fAtten, const float3 vLightColor, const float3 vLightDir, + const bool bDoAmbientOcclusion, const float fAmbientOcclusion, + const bool bDoSpecularWarp, in sampler specularWarpSampler, float fFresnel, + const bool bDoRimLighting, const float fRimExponent, + + // Outputs + out float3 specularLighting, out float3 rimLighting ) +{ + // Compute Specular and rim terms + SpecularAndRimTerms( vWorldNormal, vLightDir, fSpecularExponent, + vEyeDir, bDoAmbientOcclusion, fAmbientOcclusion, + bDoSpecularWarp, specularWarpSampler, fFresnel, vLightColor * fAtten, + bDoRimLighting, fRimExponent, specularLighting, rimLighting ); +} + +float3 PixelShaderDoLightingLinear( const float3 worldPos, const float3 worldNormal, + const float3 staticLightingColor, const bool bStaticLight, + const bool bAmbientLight, const float4 lightAtten, const float3 cAmbientCube[6], + in sampler NormalizeSampler, const int nNumLights, PixelShaderLightInfo cLightInfo[3], + const bool bHalfLambert, const bool bDoAmbientOcclusion, const float fAmbientOcclusion, + const bool bDoLightingWarp, in sampler lightWarpSampler ) +{ + float3 linearColor = 0.0f; + + if ( bStaticLight ) + { + // The static lighting comes in in gamma space and has also been premultiplied by $cOOOverbright + // need to get it into + // linear space so that we can do adds. + linearColor += GammaToLinear( staticLightingColor * cOverbright ); + } + + if ( bAmbientLight ) + { + float3 ambient = AmbientLight( worldNormal, cAmbientCube ); + + if ( bDoAmbientOcclusion ) + ambient *= fAmbientOcclusion * fAmbientOcclusion; // Note squaring... + + linearColor += ambient; + } + + if ( nNumLights > 0 ) + { + linearColor += PixelShaderDoGeneralDiffuseLight( lightAtten.x, worldPos, worldNormal, NormalizeSampler, + cLightInfo[0].pos, cLightInfo[0].color, bHalfLambert, + bDoAmbientOcclusion, fAmbientOcclusion, + bDoLightingWarp, lightWarpSampler ); + if ( nNumLights > 1 ) + { + linearColor += PixelShaderDoGeneralDiffuseLight( lightAtten.y, worldPos, worldNormal, NormalizeSampler, + cLightInfo[1].pos, cLightInfo[1].color, bHalfLambert, + bDoAmbientOcclusion, fAmbientOcclusion, + bDoLightingWarp, lightWarpSampler ); + if ( nNumLights > 2 ) + { + linearColor += PixelShaderDoGeneralDiffuseLight( lightAtten.z, worldPos, worldNormal, NormalizeSampler, + cLightInfo[2].pos, cLightInfo[2].color, bHalfLambert, + bDoAmbientOcclusion, fAmbientOcclusion, + bDoLightingWarp, lightWarpSampler ); + if ( nNumLights > 3 ) + { + // Unpack the 4th light's data from tight constant packing + float3 vLight3Color = float3( cLightInfo[0].color.w, cLightInfo[0].pos.w, cLightInfo[1].color.w ); + float3 vLight3Pos = float3( cLightInfo[1].pos.w, cLightInfo[2].color.w, cLightInfo[2].pos.w ); + linearColor += PixelShaderDoGeneralDiffuseLight( lightAtten.w, worldPos, worldNormal, NormalizeSampler, + vLight3Pos, vLight3Color, bHalfLambert, + bDoAmbientOcclusion, fAmbientOcclusion, + bDoLightingWarp, lightWarpSampler ); + } + } + } + } + + return linearColor; +} + +void PixelShaderDoSpecularLighting( const float3 worldPos, const float3 worldNormal, const float fSpecularExponent, const float3 vEyeDir, + const float4 lightAtten, const int nNumLights, PixelShaderLightInfo cLightInfo[3], + const bool bDoAmbientOcclusion, const float fAmbientOcclusion, + const bool bDoSpecularWarp, in sampler specularWarpSampler, float fFresnel, + const bool bDoRimLighting, const float fRimExponent, + + // Outputs + out float3 specularLighting, out float3 rimLighting ) +{ + specularLighting = rimLighting = float3( 0.0f, 0.0f, 0.0f ); + float3 localSpecularTerm, localRimTerm; + + if( nNumLights > 0 ) + { + PixelShaderDoSpecularLight( worldPos, worldNormal, fSpecularExponent, vEyeDir, + lightAtten.x, PixelShaderGetLightColor( cLightInfo, 0 ), + PixelShaderGetLightVector( worldPos, cLightInfo, 0 ), + bDoAmbientOcclusion, fAmbientOcclusion, + bDoSpecularWarp, specularWarpSampler, fFresnel, + bDoRimLighting, fRimExponent, + localSpecularTerm, localRimTerm ); + + specularLighting += localSpecularTerm; // Accumulate specular and rim terms + rimLighting += localRimTerm; + } + + if( nNumLights > 1 ) + { + PixelShaderDoSpecularLight( worldPos, worldNormal, fSpecularExponent, vEyeDir, + lightAtten.y, PixelShaderGetLightColor( cLightInfo, 1 ), + PixelShaderGetLightVector( worldPos, cLightInfo, 1 ), + bDoAmbientOcclusion, fAmbientOcclusion, + bDoSpecularWarp, specularWarpSampler, fFresnel, + bDoRimLighting, fRimExponent, + localSpecularTerm, localRimTerm ); + + specularLighting += localSpecularTerm; // Accumulate specular and rim terms + rimLighting += localRimTerm; + } + + + if( nNumLights > 2 ) + { + PixelShaderDoSpecularLight( worldPos, worldNormal, fSpecularExponent, vEyeDir, + lightAtten.z, PixelShaderGetLightColor( cLightInfo, 2 ), + PixelShaderGetLightVector( worldPos, cLightInfo, 2 ), + bDoAmbientOcclusion, fAmbientOcclusion, + bDoSpecularWarp, specularWarpSampler, fFresnel, + bDoRimLighting, fRimExponent, + localSpecularTerm, localRimTerm ); + + specularLighting += localSpecularTerm; // Accumulate specular and rim terms + rimLighting += localRimTerm; + } + + if( nNumLights > 3 ) + { + PixelShaderDoSpecularLight( worldPos, worldNormal, fSpecularExponent, vEyeDir, + lightAtten.w, PixelShaderGetLightColor( cLightInfo, 3 ), + PixelShaderGetLightVector( worldPos, cLightInfo, 3 ), + bDoAmbientOcclusion, fAmbientOcclusion, + bDoSpecularWarp, specularWarpSampler, fFresnel, + bDoRimLighting, fRimExponent, + localSpecularTerm, localRimTerm ); + + specularLighting += localSpecularTerm; // Accumulate specular and rim terms + rimLighting += localRimTerm; + } + +} + +float3 PixelShaderDoRimLighting( const float3 worldNormal, const float3 vEyeDir, const float3 cAmbientCube[6], float fFresnel ) +{ + float3 vReflect = reflect( -vEyeDir, worldNormal ); // Reflect view through normal + + return fFresnel * PixelShaderAmbientLight( vEyeDir, cAmbientCube ); +} + +// Called directly by newer shaders or through the following wrapper for older shaders +float3 PixelShaderDoLighting( const float3 worldPos, const float3 worldNormal, + const float3 staticLightingColor, const bool bStaticLight, + const bool bAmbientLight, const float4 lightAtten, const float3 cAmbientCube[6], + in sampler NormalizeSampler, const int nNumLights, PixelShaderLightInfo cLightInfo[3], + const bool bHalfLambert, + + // New optional/experimental parameters + const bool bDoAmbientOcclusion, const float fAmbientOcclusion, + const bool bDoLightingWarp, in sampler lightWarpSampler ) +{ + float3 linearColor = PixelShaderDoLightingLinear( worldPos, worldNormal, staticLightingColor, + bStaticLight, bAmbientLight, lightAtten, + cAmbientCube, NormalizeSampler, nNumLights, cLightInfo, bHalfLambert, + bDoAmbientOcclusion, fAmbientOcclusion, + bDoLightingWarp, lightWarpSampler ); + + // go ahead and clamp to the linear space equivalent of overbright 2 so that we match + // everything else. +// linearColor = HuePreservingColorClamp( linearColor, pow( 2.0f, 2.2 ) ); + + return linearColor; +} + +#endif //#ifndef COMMON_VERTEXLITGENERIC_DX9_H_ diff --git a/materialsystem/stdshaders/common_vertexlitgeneric_vs20.fxc b/materialsystem/stdshaders/common_vertexlitgeneric_vs20.fxc new file mode 100644 index 0000000..e69de29 diff --git a/materialsystem/stdshaders/common_vs_fxc.h b/materialsystem/stdshaders/common_vs_fxc.h new file mode 100644 index 0000000..ac966b6 --- /dev/null +++ b/materialsystem/stdshaders/common_vs_fxc.h @@ -0,0 +1,955 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: This is where all common code for vertex shaders go. +// +// $NoKeywords: $ +// +//===========================================================================// + + + +#ifndef COMMON_VS_FXC_H_ +#define COMMON_VS_FXC_H_ + +#include "common_fxc.h" + +// Put global skip commands here. . make sure and check that the appropriate vars are defined +// so these aren't used on the wrong shaders! +// -------------------------------------------------------------------------------- +// Ditch all fastpath attemps if we are doing LIGHTING_PREVIEW. +// SKIP: defined $LIGHTING_PREVIEW && defined $FASTPATH && $LIGHTING_PREVIEW && $FASTPATH +// -------------------------------------------------------------------------------- + + +#ifndef COMPRESSED_VERTS +// Default to no vertex compression +#define COMPRESSED_VERTS 0 +#endif + +#if ( !defined( SHADER_MODEL_VS_2_0 ) && !defined( SHADER_MODEL_VS_3_0 ) ) +#if COMPRESSED_VERTS == 1 +#error "Vertex compression is only for DX9 and up!" +#endif +#endif + +// We're testing 2 normal compression methods +// One compressed normals+tangents into a SHORT2 each (8 bytes total) +// The other compresses them together, into a single UBYTE4 (4 bytes total) +// FIXME: pick one or the other, compare lighting quality in important cases +#define COMPRESSED_NORMALS_SEPARATETANGENTS_SHORT2 0 +#define COMPRESSED_NORMALS_COMBINEDTANGENTS_UBYTE4 1 +//#define COMPRESSED_NORMALS_TYPE COMPRESSED_NORMALS_SEPARATETANGENTS_SHORT2 +#define COMPRESSED_NORMALS_TYPE COMPRESSED_NORMALS_COMBINEDTANGENTS_UBYTE4 + + +#define FOGTYPE_RANGE 0 +#define FOGTYPE_HEIGHT 1 + +#define COMPILE_ERROR ( 1/0; ) + +// ------------------------- +// CONSTANTS +// ------------------------- + +#pragma def ( vs, c0, 0.0f, 1.0f, 2.0f, 0.5f ) + +const float4 cConstants1 : register(c1); +#define cOOGamma cConstants1.x +#define cOverbright 2.0f +#define cOneThird cConstants1.z +#define cOOOverbright ( 1.0f / 2.0f ) + + +// The g_bLightEnabled registers and g_nLightCountRegister hold the same information regarding +// enabling lights, but callers internal to this file tend to use the loops, while external +// callers will end up using the booleans +const bool g_bLightEnabled[4] : register(b0); + // through b3 + +const int g_nLightCountRegister : register(i0); + + +#define g_nLightCount g_nLightCountRegister.x + +const float4 cEyePosWaterZ : register(c2); +#define cEyePos cEyePosWaterZ.xyz + +// Only cFlexScale.x is used +// It is a binary value used to switch on/off the addition of the flex delta stream +const float4 cFlexScale : register( c3 ); + +const float4x4 cModelViewProj : register(c4); +const float4x4 cViewProj : register(c8); + +// Used to compute projPosZ in shaders without skinning +// Using cModelViewProj with FastClip generates incorrect results +// This is just row two of the non-FastClip cModelViewProj matrix +const float4 cModelViewProjZ : register(c12); + +// More constants working back from the top... +const float4 cViewProjZ : register(c13); + +const float4 cFogParams : register(c16); +#define cFogEndOverFogRange cFogParams.x +#define cFogOne cFogParams.y +#define cFogMaxDensity cFogParams.z +#define cOOFogRange cFogParams.w + +const float4x4 cViewModel : register(c17); + +const float3 cAmbientCubeX [ 2 ] : register ( c21 ) ; +const float3 cAmbientCubeY [ 2 ] : register ( c23 ) ; +const float3 cAmbientCubeZ [ 2 ] : register ( c25 ) ; + +#if defined ( SHADER_MODEL_VS_3_0 ) +const float4 cFlexWeights [ 512 ] : register ( c1024 ) ; +#endif + +struct LightInfo +{ + float4 color; // {xyz} is color w is light type code (see comment below) + float4 dir; // {xyz} is dir w is light type code + float4 pos; + float4 spotParams; + float4 atten; +}; + +// w components of color and dir indicate light type: +// 1x - directional +// 01 - spot +// 00 - point + +// Four lights x 5 constants each = 20 constants +LightInfo cLightInfo[4] : register(c27); +#define LIGHT_0_POSITION_REG c29 + +#ifdef SHADER_MODEL_VS_1_1 + +const float4 cModulationColor : register(c37); + +#define SHADER_SPECIFIC_CONST_0 c38 +#define SHADER_SPECIFIC_CONST_1 c39 +#define SHADER_SPECIFIC_CONST_2 c40 +#define SHADER_SPECIFIC_CONST_3 c41 +#define SHADER_SPECIFIC_CONST_4 c42 +#define SHADER_SPECIFIC_CONST_5 c43 +#define SHADER_SPECIFIC_CONST_6 c44 +#define SHADER_SPECIFIC_CONST_7 c45 +#define SHADER_SPECIFIC_CONST_8 c46 +#define SHADER_SPECIFIC_CONST_9 c47 +#define SHADER_SPECIFIC_CONST_10 c14 +#define SHADER_SPECIFIC_CONST_11 c15 + +static const int cModel0Index = 48; +const float4x3 cModel[16] : register(c48); +// last cmodel is c105 for dx80, c214 for dx90 + +#else // DX9 shaders (vs20 and beyond) + +const float4 cModulationColor : register( c47 ); + +#define SHADER_SPECIFIC_CONST_0 c48 +#define SHADER_SPECIFIC_CONST_1 c49 +#define SHADER_SPECIFIC_CONST_2 c50 +#define SHADER_SPECIFIC_CONST_3 c51 +#define SHADER_SPECIFIC_CONST_4 c52 +#define SHADER_SPECIFIC_CONST_5 c53 +#define SHADER_SPECIFIC_CONST_6 c54 +#define SHADER_SPECIFIC_CONST_7 c55 +#define SHADER_SPECIFIC_CONST_8 c56 +#define SHADER_SPECIFIC_CONST_9 c57 +#define SHADER_SPECIFIC_CONST_10 c14 +#define SHADER_SPECIFIC_CONST_11 c15 + +static const int cModel0Index = 58; +const float4x3 cModel[53] : register( c58 ); +// last cmodel is c105 for dx80, c216 for dx90 + + +#define SHADER_SPECIFIC_BOOL_CONST_0 b4 +#define SHADER_SPECIFIC_BOOL_CONST_1 b5 +#define SHADER_SPECIFIC_BOOL_CONST_2 b6 +#define SHADER_SPECIFIC_BOOL_CONST_3 b7 +#define SHADER_SPECIFIC_BOOL_CONST_4 b8 +#define SHADER_SPECIFIC_BOOL_CONST_5 b9 +#define SHADER_SPECIFIC_BOOL_CONST_6 b10 +#define SHADER_SPECIFIC_BOOL_CONST_7 b11 +#endif // vertex shader model constant packing changes + + +//======================================================================================= +// Methods to decompress vertex normals +//======================================================================================= + +//----------------------------------------------------------------------------------- +// Decompress a normal from two-component compressed format +// We expect this data to come from a signed SHORT2 stream in the range of -32768..32767 +// +// -32678 and 0 are invalid encodings +// w contains the sign to use in the cross product when generating a binormal +void _DecompressShort2Tangent( float2 inputTangent, out float4 outputTangent ) +{ + float2 ztSigns = sign( inputTangent ); // sign bits for z and tangent (+1 or -1) + float2 xyAbs = abs( inputTangent ); // 1..32767 + outputTangent.xy = (xyAbs - 16384.0f) / 16384.0f; // x and y + outputTangent.z = ztSigns.x * sqrt( saturate( 1.0f - dot( outputTangent.xy, outputTangent.xy ) ) ); + outputTangent.w = ztSigns.y; +} + +//----------------------------------------------------------------------------------- +// Same code as _DecompressShort2Tangent, just one returns a float4, one a float3 +void _DecompressShort2Normal( float2 inputNormal, out float3 outputNormal ) +{ + float4 result; + _DecompressShort2Tangent( inputNormal, result ); + outputNormal = result.xyz; +} + +//----------------------------------------------------------------------------------- +// Decompress normal+tangent together +void _DecompressShort2NormalTangent( float2 inputNormal, float2 inputTangent, out float3 outputNormal, out float4 outputTangent ) +{ + // FIXME: if we end up sticking with the SHORT2 format, pack the normal and tangent into a single SHORT4 element + // (that would make unpacking normal+tangent here together much cheaper than the sum of their parts) + _DecompressShort2Normal( inputNormal, outputNormal ); + _DecompressShort2Tangent( inputTangent, outputTangent ); +} + +//======================================================================================= +// Decompress a normal and tangent from four-component compressed format +// We expect this data to come from an unsigned UBYTE4 stream in the range of 0..255 +// The final vTangent.w contains the sign to use in the cross product when generating a binormal +void _DecompressUByte4NormalTangent( float4 inputNormal, + out float3 outputNormal, // {nX, nY, nZ} + out float4 outputTangent ) // {tX, tY, tZ, sign of binormal} +{ + float fOne = 1.0f; + + float4 ztztSignBits = ( inputNormal - 128.0f ) < 0; // sign bits for zs and binormal (1 or 0) set-less-than (slt) asm instruction + float4 xyxyAbs = abs( inputNormal - 128.0f ) - ztztSignBits; // 0..127 + float4 xyxySignBits = ( xyxyAbs - 64.0f ) < 0; // sign bits for xs and ys (1 or 0) + float4 normTan = (abs( xyxyAbs - 64.0f ) - xyxySignBits) / 63.0f; // abs({nX, nY, tX, tY}) + outputNormal.xy = normTan.xy; // abs({nX, nY, __, __}) + outputTangent.xy = normTan.zw; // abs({tX, tY, __, __}) + + float4 xyxySigns = 1 - 2*xyxySignBits; // Convert sign bits to signs + float4 ztztSigns = 1 - 2*ztztSignBits; // ( [1,0] -> [-1,+1] ) + + outputNormal.z = 1.0f - outputNormal.x - outputNormal.y; // Project onto x+y+z=1 + outputNormal.xyz = normalize( outputNormal.xyz ); // Normalize onto unit sphere + outputNormal.xy *= xyxySigns.xy; // Restore x and y signs + outputNormal.z *= ztztSigns.x; // Restore z sign + + outputTangent.z = 1.0f - outputTangent.x - outputTangent.y; // Project onto x+y+z=1 + outputTangent.xyz = normalize( outputTangent.xyz ); // Normalize onto unit sphere + outputTangent.xy *= xyxySigns.zw; // Restore x and y signs + outputTangent.z *= ztztSigns.z; // Restore z sign + outputTangent.w = ztztSigns.w; // Binormal sign +} + + +//----------------------------------------------------------------------------------- +// Decompress just a normal from four-component compressed format (same as above) +// We expect this data to come from an unsigned UBYTE4 stream in the range of 0..255 +// [ When compiled, this works out to approximately 17 asm instructions ] +void _DecompressUByte4Normal( float4 inputNormal, + out float3 outputNormal) // {nX, nY, nZ} +{ + float fOne = 1.0f; + + float2 ztSigns = ( inputNormal.xy - 128.0f ) < 0; // sign bits for zs and binormal (1 or 0) set-less-than (slt) asm instruction + float2 xyAbs = abs( inputNormal.xy - 128.0f ) - ztSigns; // 0..127 + float2 xySigns = ( xyAbs - 64.0f ) < 0; // sign bits for xs and ys (1 or 0) + outputNormal.xy = ( abs( xyAbs - 64.0f ) - xySigns ) / 63.0f; // abs({nX, nY}) + + outputNormal.z = 1.0f - outputNormal.x - outputNormal.y; // Project onto x+y+z=1 + outputNormal.xyz = normalize( outputNormal.xyz ); // Normalize onto unit sphere + + outputNormal.xy *= lerp( fOne.xx, -fOne.xx, xySigns ); // Restore x and y signs + outputNormal.z *= lerp( fOne.x, -fOne.x, ztSigns.x ); // Restore z sign +} + + +void DecompressVertex_Normal( float4 inputNormal, out float3 outputNormal ) +{ + if ( COMPRESSED_VERTS == 1 ) + { + if ( COMPRESSED_NORMALS_TYPE == COMPRESSED_NORMALS_SEPARATETANGENTS_SHORT2 ) + { + _DecompressShort2Normal( inputNormal.xy, outputNormal ); + } + else // ( COMPRESSED_NORMALS_TYPE == COMPRESSED_NORMALS_COMBINEDTANGENTS_UBYTE4 ) + { + _DecompressUByte4Normal( inputNormal, outputNormal ); + } + } + else + { + outputNormal = inputNormal.xyz; + } +} + +void DecompressVertex_NormalTangent( float4 inputNormal, float4 inputTangent, out float3 outputNormal, out float4 outputTangent ) +{ + if ( COMPRESSED_VERTS == 1 ) + { + if ( COMPRESSED_NORMALS_TYPE == COMPRESSED_NORMALS_SEPARATETANGENTS_SHORT2 ) + { + _DecompressShort2NormalTangent( inputNormal.xy, inputTangent.xy, outputNormal, outputTangent ); + } + else // ( COMPRESSED_NORMALS_TYPE == COMPRESSED_NORMALS_COMBINEDTANGENTS_UBYTE4 ) + { + _DecompressUByte4NormalTangent( inputNormal, outputNormal, outputTangent ); + } + } + else + { + outputNormal = inputNormal.xyz; + outputTangent = inputTangent; + } +} + + +#ifdef SHADER_MODEL_VS_3_0 + +//----------------------------------------------------------------------------- +// Methods to sample morph data from a vertex texture +// NOTE: vMorphTargetTextureDim.x = width, cVertexTextureDim.y = height, cVertexTextureDim.z = # of float4 fields per vertex +// For position + normal morph for example, there will be 2 fields. +//----------------------------------------------------------------------------- +float4 SampleMorphDelta( sampler2D vt, const float3 vMorphTargetTextureDim, const float4 vMorphSubrect, const float flVertexID, const float flField ) +{ + float flColumn = floor( flVertexID / vMorphSubrect.w ); + + float4 t; + t.x = vMorphSubrect.x + vMorphTargetTextureDim.z * flColumn + flField + 0.5f; + t.y = vMorphSubrect.y + flVertexID - flColumn * vMorphSubrect.w + 0.5f; + t.xy /= vMorphTargetTextureDim.xy; + t.z = t.w = 0.f; + + return tex2Dlod( vt, t ); +} + +// Optimized version which reads 2 deltas +void SampleMorphDelta2( sampler2D vt, const float3 vMorphTargetTextureDim, const float4 vMorphSubrect, const float flVertexID, out float4 delta1, out float4 delta2 ) +{ + float flColumn = floor( flVertexID / vMorphSubrect.w ); + + float4 t; + t.x = vMorphSubrect.x + vMorphTargetTextureDim.z * flColumn + 0.5f; + t.y = vMorphSubrect.y + flVertexID - flColumn * vMorphSubrect.w + 0.5f; + t.xy /= vMorphTargetTextureDim.xy; + t.z = t.w = 0.f; + + delta1 = tex2Dlod( vt, t ); + t.x += 1.0f / vMorphTargetTextureDim.x; + delta2 = tex2Dlod( vt, t ); +} + +#endif // SHADER_MODEL_VS_3_0 + + +#if ( defined( SHADER_MODEL_VS_2_0 ) || defined( SHADER_MODEL_VS_3_0 ) ) + +//----------------------------------------------------------------------------- +// Method to apply morphs +//----------------------------------------------------------------------------- +bool ApplyMorph( float3 vPosFlex, inout float3 vPosition ) +{ + // Flexes coming in from a separate stream + float3 vPosDelta = vPosFlex.xyz * cFlexScale.x; + vPosition.xyz += vPosDelta; + return true; +} + +bool ApplyMorph( float3 vPosFlex, float3 vNormalFlex, inout float3 vPosition, inout float3 vNormal ) +{ + // Flexes coming in from a separate stream + float3 vPosDelta = vPosFlex.xyz * cFlexScale.x; + float3 vNormalDelta = vNormalFlex.xyz * cFlexScale.x; + vPosition.xyz += vPosDelta; + vNormal += vNormalDelta; + return true; +} + +bool ApplyMorph( float3 vPosFlex, float3 vNormalFlex, + inout float3 vPosition, inout float3 vNormal, inout float3 vTangent ) +{ + // Flexes coming in from a separate stream + float3 vPosDelta = vPosFlex.xyz * cFlexScale.x; + float3 vNormalDelta = vNormalFlex.xyz * cFlexScale.x; + vPosition.xyz += vPosDelta; + vNormal += vNormalDelta; + vTangent.xyz += vNormalDelta; + return true; +} + +bool ApplyMorph( float4 vPosFlex, float3 vNormalFlex, + inout float3 vPosition, inout float3 vNormal, inout float3 vTangent, out float flWrinkle ) +{ + // Flexes coming in from a separate stream + float3 vPosDelta = vPosFlex.xyz * cFlexScale.x; + float3 vNormalDelta = vNormalFlex.xyz * cFlexScale.x; + flWrinkle = vPosFlex.w * cFlexScale.y; + vPosition.xyz += vPosDelta; + vNormal += vNormalDelta; + vTangent.xyz += vNormalDelta; + return true; +} + +#endif // defined( SHADER_MODEL_VS_2_0 ) || defined( SHADER_MODEL_VS_3_0 ) + + +#ifdef SHADER_MODEL_VS_3_0 + +bool ApplyMorph( sampler2D morphSampler, const float3 vMorphTargetTextureDim, const float4 vMorphSubrect, + const float flVertexID, const float3 vMorphTexCoord, + inout float3 vPosition ) +{ +#if MORPHING + +#if !DECAL + // Flexes coming in from a separate stream + float4 vPosDelta = SampleMorphDelta( morphSampler, vMorphTargetTextureDim, vMorphSubrect, flVertexID, 0 ); + vPosition += vPosDelta.xyz; +#else + float4 t = float4( vMorphTexCoord.x, vMorphTexCoord.y, 0.0f, 0.0f ); + float3 vPosDelta = tex2Dlod( morphSampler, t ); + vPosition += vPosDelta.xyz * vMorphTexCoord.z; +#endif // DECAL + + return true; + +#else // !MORPHING + return false; +#endif +} + +bool ApplyMorph( sampler2D morphSampler, const float3 vMorphTargetTextureDim, const float4 vMorphSubrect, + const float flVertexID, const float3 vMorphTexCoord, + inout float3 vPosition, inout float3 vNormal ) +{ +#if MORPHING + +#if !DECAL + float4 vPosDelta, vNormalDelta; + SampleMorphDelta2( morphSampler, vMorphTargetTextureDim, vMorphSubrect, flVertexID, vPosDelta, vNormalDelta ); + vPosition += vPosDelta.xyz; + vNormal += vNormalDelta.xyz; +#else + float4 t = float4( vMorphTexCoord.x, vMorphTexCoord.y, 0.0f, 0.0f ); + float3 vPosDelta = tex2Dlod( morphSampler, t ); + t.x += 1.0f / vMorphTargetTextureDim.x; + float3 vNormalDelta = tex2Dlod( morphSampler, t ); + vPosition += vPosDelta.xyz * vMorphTexCoord.z; + vNormal += vNormalDelta.xyz * vMorphTexCoord.z; +#endif // DECAL + + return true; + +#else // !MORPHING + return false; +#endif +} + +bool ApplyMorph( sampler2D morphSampler, const float3 vMorphTargetTextureDim, const float4 vMorphSubrect, + const float flVertexID, const float3 vMorphTexCoord, + inout float3 vPosition, inout float3 vNormal, inout float3 vTangent ) +{ +#if MORPHING + +#if !DECAL + float4 vPosDelta, vNormalDelta; + SampleMorphDelta2( morphSampler, vMorphTargetTextureDim, vMorphSubrect, flVertexID, vPosDelta, vNormalDelta ); + vPosition += vPosDelta.xyz; + vNormal += vNormalDelta.xyz; + vTangent += vNormalDelta.xyz; +#else + float4 t = float4( vMorphTexCoord.x, vMorphTexCoord.y, 0.0f, 0.0f ); + float3 vPosDelta = tex2Dlod( morphSampler, t ); + t.x += 1.0f / vMorphTargetTextureDim.x; + float3 vNormalDelta = tex2Dlod( morphSampler, t ); + vPosition += vPosDelta.xyz * vMorphTexCoord.z; + vNormal += vNormalDelta.xyz * vMorphTexCoord.z; + vTangent += vNormalDelta.xyz * vMorphTexCoord.z; +#endif // DECAL + + return true; + +#else // MORPHING + + return false; +#endif +} + +bool ApplyMorph( sampler2D morphSampler, const float3 vMorphTargetTextureDim, const float4 vMorphSubrect, + const float flVertexID, const float3 vMorphTexCoord, + inout float3 vPosition, inout float3 vNormal, inout float3 vTangent, out float flWrinkle ) +{ +#if MORPHING + +#if !DECAL + float4 vPosDelta, vNormalDelta; + SampleMorphDelta2( morphSampler, vMorphTargetTextureDim, vMorphSubrect, flVertexID, vPosDelta, vNormalDelta ); + vPosition += vPosDelta.xyz; + vNormal += vNormalDelta.xyz; + vTangent += vNormalDelta.xyz; + flWrinkle = vPosDelta.w; +#else + float4 t = float4( vMorphTexCoord.x, vMorphTexCoord.y, 0.0f, 0.0f ); + float4 vPosDelta = tex2Dlod( morphSampler, t ); + t.x += 1.0f / vMorphTargetTextureDim.x; + float3 vNormalDelta = tex2Dlod( morphSampler, t ); + + vPosition += vPosDelta.xyz * vMorphTexCoord.z; + vNormal += vNormalDelta.xyz * vMorphTexCoord.z; + vTangent += vNormalDelta.xyz * vMorphTexCoord.z; + flWrinkle = vPosDelta.w * vMorphTexCoord.z; +#endif // DECAL + + return true; + +#else // MORPHING + + flWrinkle = 0.0f; + return false; + +#endif +} + +#endif // SHADER_MODEL_VS_3_0 + + +float RangeFog( const float3 projPos ) +{ + return max( cFogMaxDensity, ( -projPos.z * cOOFogRange + cFogEndOverFogRange ) ); +} + +float WaterFog( const float3 worldPos, const float3 projPos ) +{ + float4 tmp; + + tmp.xy = cEyePosWaterZ.wz - worldPos.z; + + // tmp.x is the distance from the water surface to the vert + // tmp.y is the distance from the eye position to the vert + + // if $tmp.x < 0, then set it to 0 + // This is the equivalent of moving the vert to the water surface if it's above the water surface + + tmp.x = max( 0.0f, tmp.x ); + + // $tmp.w = $tmp.x / $tmp.y + tmp.w = tmp.x / tmp.y; + + tmp.w *= projPos.z; + + // $tmp.w is now the distance that we see through water. + + return max( cFogMaxDensity, ( -tmp.w * cOOFogRange + cFogOne ) ); +} + +float CalcFog( const float3 worldPos, const float3 projPos, const int fogType ) +{ +#if defined( _X360 ) + // 360 only does pixel fog + return 1.0f; +#endif + + if( fogType == FOGTYPE_RANGE ) + { + return RangeFog( projPos ); + } + else + { +#if SHADERMODEL_VS_2_0 == 1 + // We do this work in the pixel shader in dx9, so don't do any fog here. + return 1.0f; +#else + return WaterFog( worldPos, projPos ); +#endif + } +} + +float CalcFog( const float3 worldPos, const float3 projPos, const bool bWaterFog ) +{ +#if defined( _X360 ) + // 360 only does pixel fog + return 1.0f; +#endif + + float flFog; + if( !bWaterFog ) + { + flFog = RangeFog( projPos ); + } + else + { +#if SHADERMODEL_VS_2_0 == 1 + // We do this work in the pixel shader in dx9, so don't do any fog here. + flFog = 1.0f; +#else + flFog = WaterFog( worldPos, projPos ); +#endif + } + + return flFog; +} + +float4 DecompressBoneWeights( const float4 weights ) +{ + float4 result = weights; + + if ( COMPRESSED_VERTS ) + { + // Decompress from SHORT2 to float. In our case, [-1, +32767] -> [0, +1] + // NOTE: we add 1 here so we can divide by 32768 - which is exact (divide by 32767 is not). + // This avoids cracking between meshes with different numbers of bone weights. + // We use SHORT2 instead of SHORT2N for a similar reason - the GPU's conversion + // from [-32768,+32767] to [-1,+1] is imprecise in the same way. + result += 1; + result /= 32768; + } + + return result; +} + +void SkinPosition( bool bSkinning, const float4 modelPos, + const float4 boneWeights, float4 fBoneIndices, + out float3 worldPos ) +{ +#if !defined( _X360 ) + int3 boneIndices = D3DCOLORtoUBYTE4( fBoneIndices ); +#else + int3 boneIndices = fBoneIndices; +#endif + + // Needed for invariance issues caused by multipass rendering +#if defined( _X360 ) + [isolate] +#endif + { + if ( !bSkinning ) + { + worldPos = mul4x3( modelPos, cModel[0] ); + } + else // skinning - always three bones + { + float4x3 mat1 = cModel[boneIndices[0]]; + float4x3 mat2 = cModel[boneIndices[1]]; + float4x3 mat3 = cModel[boneIndices[2]]; + + float3 weights = DecompressBoneWeights( boneWeights ).xyz; + weights[2] = 1 - (weights[0] + weights[1]); + + float4x3 blendMatrix = mat1 * weights[0] + mat2 * weights[1] + mat3 * weights[2]; + worldPos = mul4x3( modelPos, blendMatrix ); + } + } +} + +void SkinPositionAndNormal( bool bSkinning, const float4 modelPos, const float3 modelNormal, + const float4 boneWeights, float4 fBoneIndices, + out float3 worldPos, out float3 worldNormal ) +{ + // Needed for invariance issues caused by multipass rendering +#if defined( _X360 ) + [isolate] +#endif + { + +#if !defined( _X360 ) + int3 boneIndices = D3DCOLORtoUBYTE4( fBoneIndices ); +#else + int3 boneIndices = fBoneIndices; +#endif + + if ( !bSkinning ) + { + worldPos = mul4x3( modelPos, cModel[0] ); + worldNormal = mul3x3( modelNormal, ( const float3x3 )cModel[0] ); + } + else // skinning - always three bones + { + float4x3 mat1 = cModel[boneIndices[0]]; + float4x3 mat2 = cModel[boneIndices[1]]; + float4x3 mat3 = cModel[boneIndices[2]]; + + float3 weights = DecompressBoneWeights( boneWeights ).xyz; + weights[2] = 1 - (weights[0] + weights[1]); + + float4x3 blendMatrix = mat1 * weights[0] + mat2 * weights[1] + mat3 * weights[2]; + worldPos = mul4x3( modelPos, blendMatrix ); + worldNormal = mul3x3( modelNormal, ( float3x3 )blendMatrix ); + } + + } // end [isolate] +} + +// Is it worth keeping SkinPosition and SkinPositionAndNormal around since the optimizer +// gets rid of anything that isn't used? +void SkinPositionNormalAndTangentSpace( + bool bSkinning, + const float4 modelPos, const float3 modelNormal, + const float4 modelTangentS, + const float4 boneWeights, float4 fBoneIndices, + out float3 worldPos, out float3 worldNormal, + out float3 worldTangentS, out float3 worldTangentT ) +{ +#if !defined( _X360 ) + int3 boneIndices = D3DCOLORtoUBYTE4( fBoneIndices ); +#else + int3 boneIndices = fBoneIndices; +#endif + + // Needed for invariance issues caused by multipass rendering +#if defined( _X360 ) + [isolate] +#endif + { + if ( !bSkinning ) + { + worldPos = mul4x3( modelPos, cModel[0] ); + worldNormal = mul3x3( modelNormal, ( const float3x3 )cModel[0] ); + worldTangentS = mul3x3( ( float3 )modelTangentS, ( const float3x3 )cModel[0] ); + } + else // skinning - always three bones + { + float4x3 mat1 = cModel[boneIndices[0]]; + float4x3 mat2 = cModel[boneIndices[1]]; + float4x3 mat3 = cModel[boneIndices[2]]; + + float3 weights = DecompressBoneWeights( boneWeights ).xyz; + weights[2] = 1 - (weights[0] + weights[1]); + + float4x3 blendMatrix = mat1 * weights[0] + mat2 * weights[1] + mat3 * weights[2]; + worldPos = mul4x3( modelPos, blendMatrix ); + worldNormal = mul3x3( modelNormal, ( const float3x3 )blendMatrix ); + worldTangentS = mul3x3( ( float3 )modelTangentS, ( const float3x3 )blendMatrix ); + } + worldTangentT = cross( worldNormal, worldTangentS ) * modelTangentS.w; + } +} + + +//----------------------------------------------------------------------------- +// Lighting helper functions +//----------------------------------------------------------------------------- + +float3 AmbientLight( const float3 worldNormal ) +{ + float3 nSquared = worldNormal * worldNormal; + int3 isNegative = ( worldNormal < 0.0 ); + float3 linearColor; + linearColor = nSquared.x * cAmbientCubeX[isNegative.x] + + nSquared.y * cAmbientCubeY[isNegative.y] + + nSquared.z * cAmbientCubeZ[isNegative.z]; + return linearColor; +} + +// The following "internal" routines are called "privately" by other routines in this file which +// handle the particular flavor of vs20 control flow appropriate to the original caller +float VertexAttenInternal( const float3 worldPos, int lightNum ) +{ + float result = 0.0f; + + // Get light direction + float3 lightDir = cLightInfo[lightNum].pos - worldPos; + + // Get light distance squared. + float lightDistSquared = dot( lightDir, lightDir ); + + // Get 1/lightDistance + float ooLightDist = rsqrt( lightDistSquared ); + + // Normalize light direction + lightDir *= ooLightDist; + + float3 vDist; +# if defined( _X360 ) + { + //X360 dynamic compile hits an internal compiler error using dst(), this is the breakdown of how dst() works from the 360 docs. + vDist.x = 1; + vDist.y = lightDistSquared * ooLightDist; + vDist.z = lightDistSquared; + //flDist.w = ooLightDist; + } +# else + { + vDist = dst( lightDistSquared, ooLightDist ); + } +# endif + + float flDistanceAtten = 1.0f / dot( cLightInfo[lightNum].atten.xyz, vDist ); + + // Spot attenuation + float flCosTheta = dot( cLightInfo[lightNum].dir.xyz, -lightDir ); + float flSpotAtten = (flCosTheta - cLightInfo[lightNum].spotParams.z) * cLightInfo[lightNum].spotParams.w; + flSpotAtten = max( 0.0001f, flSpotAtten ); + flSpotAtten = pow( flSpotAtten, cLightInfo[lightNum].spotParams.x ); + flSpotAtten = saturate( flSpotAtten ); + + // Select between point and spot + float flAtten = lerp( flDistanceAtten, flDistanceAtten * flSpotAtten, cLightInfo[lightNum].dir.w ); + + // Select between above and directional (no attenuation) + result = lerp( flAtten, 1.0f, cLightInfo[lightNum].color.w ); + + return result; +} + +float CosineTermInternal( const float3 worldPos, const float3 worldNormal, int lightNum, bool bHalfLambert ) +{ + // Calculate light direction assuming this is a point or spot + float3 lightDir = normalize( cLightInfo[lightNum].pos - worldPos ); + + // Select the above direction or the one in the structure, based upon light type + lightDir = lerp( lightDir, -cLightInfo[lightNum].dir, cLightInfo[lightNum].color.w ); + + // compute N dot L + float NDotL = dot( worldNormal, lightDir ); + + if ( !bHalfLambert ) + { + NDotL = max( 0.0f, NDotL ); + } + else // Half-Lambert + { + NDotL = NDotL * 0.5 + 0.5; + NDotL = NDotL * NDotL; + } + return NDotL; +} + +// This routine uses booleans to do early-outs and is meant to be called by routines OUTSIDE of this file +float GetVertexAttenForLight( const float3 worldPos, int lightNum, bool bUseStaticControlFlow ) +{ + float result = 0.0f; + + // Direct3D uses static control flow but OpenGL currently does not + if ( bUseStaticControlFlow ) + { + if ( g_bLightEnabled[lightNum] ) + { + result = VertexAttenInternal( worldPos, lightNum ); + } + } + else // OpenGL non-static-control-flow path + { + result = VertexAttenInternal( worldPos, lightNum ); + } + + return result; +} + +float3 DoLightInternal( const float3 worldPos, const float3 worldNormal, int lightNum, bool bHalfLambert ) +{ + return cLightInfo[lightNum].color * + CosineTermInternal( worldPos, worldNormal, lightNum, bHalfLambert ) * + VertexAttenInternal( worldPos, lightNum ); +} + +float3 DoLighting( const float3 worldPos, const float3 worldNormal, + const float3 staticLightingColor, const bool bStaticLight, + const bool bDynamicLight, bool bHalfLambert ) +{ + float3 linearColor = float3( 0.0f, 0.0f, 0.0f ); + + if( bStaticLight ) // Static light + { + float3 col = staticLightingColor * cOverbright; +#if defined ( _X360 ) + linearColor += col * col; +#else + linearColor += GammaToLinear( col ); +#endif + } + + if( bDynamicLight ) // Dynamic light + { + for (int i = 0; i < g_nLightCount; i++) + { + linearColor += DoLightInternal( worldPos, worldNormal, i, bHalfLambert ); + } + } + + if( bDynamicLight ) + { + linearColor += AmbientLight( worldNormal ); //ambient light is already remapped + } + + return linearColor; +} + +float3 DoLightingUnrolled( const float3 worldPos, const float3 worldNormal, + const float3 staticLightingColor, const bool bStaticLight, + const bool bDynamicLight, bool bHalfLambert, const int nNumLights ) +{ + float3 linearColor = float3( 0.0f, 0.0f, 0.0f ); + + if( bStaticLight ) // Static light + { + linearColor += GammaToLinear( staticLightingColor * cOverbright ); + } + + if( bDynamicLight ) // Ambient light + { + if ( nNumLights >= 1 ) + linearColor += DoLightInternal( worldPos, worldNormal, 0, bHalfLambert ); + if ( nNumLights >= 2 ) + linearColor += DoLightInternal( worldPos, worldNormal, 1, bHalfLambert ); + if ( nNumLights >= 3 ) + linearColor += DoLightInternal( worldPos, worldNormal, 2, bHalfLambert ); + if ( nNumLights >= 4 ) + linearColor += DoLightInternal( worldPos, worldNormal, 3, bHalfLambert ); + } + + if( bDynamicLight ) + { + linearColor += AmbientLight( worldNormal ); //ambient light is already remapped + } + + return linearColor; +} + +int4 FloatToInt( in float4 floats ) +{ + return D3DCOLORtoUBYTE4( floats.zyxw / 255.001953125 ); +} + +float2 ComputeSphereMapTexCoords( in float3 reflectionVector ) +{ + // transform reflection vector into view space + reflectionVector = mul( reflectionVector, ( float3x3 )cViewModel ); + + // generate + float3 tmp = float3( reflectionVector.x, reflectionVector.y, reflectionVector.z + 1.0f ); + + // find 1 / len + float ooLen = dot( tmp, tmp ); + ooLen = 1.0f / sqrt( ooLen ); + + // tmp = tmp/|tmp| + 1 + tmp.xy = ooLen * tmp.xy + 1.0f; + + return tmp.xy * 0.5f; +} + + +#define DEFORMATION_CLAMP_TO_BOX_IN_WORLDSPACE 1 + // minxyz.minsoftness / maxxyz.maxsoftness +float3 ApplyDeformation( float3 worldpos, int deftype, float4 defparms0, float4 defparms1, + float4 defparms2, float4 defparms3 ) +{ + float3 ret = worldpos; + if ( deftype == DEFORMATION_CLAMP_TO_BOX_IN_WORLDSPACE ) + { + ret=max( ret, defparms2.xyz ); + ret=min( ret, defparms3.xyz ); + } + + return ret; +} + + +#endif //#ifndef COMMON_VS_FXC_H_ diff --git a/materialsystem/stdshaders/compositor.cpp b/materialsystem/stdshaders/compositor.cpp new file mode 100644 index 0000000..21aa033 --- /dev/null +++ b/materialsystem/stdshaders/compositor.cpp @@ -0,0 +1,455 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//============================================================================= + +#include "BaseVSShader.h" + +#include "compositor_ps20.inc" +#include "compositor_ps20b.inc" +#include "materialsystem/combineoperations.h" + +#include "tier0/memdbgon.h" + +struct CompositorInfo_t +{ + static const int cTextureCount = 4; + static const int cSelectorCount = 16; + + CompositorInfo_t( ) { memset( this, -1, sizeof( *this ) ); } + + int m_nCombineMode; + int m_nTextureInputCount; + int m_nTexTransform[ cTextureCount ]; + int m_nTexAdjustLevels[ cTextureCount ]; + int m_nSrcTexture[ cTextureCount ]; + int m_nSelector[ cSelectorCount ]; + + int m_nTexturesPerPass; + int m_bDebug; +}; + +#ifdef STAGING_ONLY + ConVar r_texcomp_debug_stickers( "r_texcomp_debug_stickers", "0" ); +#endif + +static void DrawCompositorStage_ps20( CBaseVSShader *pShader, IMaterialVar **params, IShaderShadow* pShaderShadow, IShaderDynamicAPI* pShaderAPI, VertexCompressionType_t vertexCompression, const CompositorInfo_t &info ); +static void DrawCompositorStage_ps20b( CBaseVSShader *pShader, IMaterialVar **params, IShaderShadow* pShaderShadow, IShaderDynamicAPI* pShaderAPI, VertexCompressionType_t vertexCompression, const CompositorInfo_t &info ); + +BEGIN_VS_SHADER( Compositor, "Help for Compositor" ) + BEGIN_SHADER_PARAMS + SHADER_PARAM( COMBINE_MODE, SHADER_PARAM_TYPE_INTEGER, "", "Which mode should the combiner operate in? 0: Mul, 1: Add, 2: Lerp, 3: Select" ) + SHADER_PARAM( TEXTUREINPUTCOUNT, SHADER_PARAM_TYPE_INTEGER, "", "" ) + + SHADER_PARAM( TEXTRANSFORM0, SHADER_PARAM_TYPE_MATRIX4X2, "", "" ) + SHADER_PARAM( TEXTRANSFORM1, SHADER_PARAM_TYPE_MATRIX4X2, "", "" ) + SHADER_PARAM( TEXTRANSFORM2, SHADER_PARAM_TYPE_MATRIX4X2, "", "" ) + SHADER_PARAM( TEXTRANSFORM3, SHADER_PARAM_TYPE_MATRIX4X2, "", "" ) + + SHADER_PARAM( TEXADJUSTLEVELS0, SHADER_PARAM_TYPE_VEC3, "", "" ) + SHADER_PARAM( TEXADJUSTLEVELS1, SHADER_PARAM_TYPE_VEC3, "", "" ) + SHADER_PARAM( TEXADJUSTLEVELS2, SHADER_PARAM_TYPE_VEC3, "", "" ) + SHADER_PARAM( TEXADJUSTLEVELS3, SHADER_PARAM_TYPE_VEC3, "", "" ) + + SHADER_PARAM( SRCTEXTURE0, SHADER_PARAM_TYPE_TEXTURE, "", "" ) + SHADER_PARAM( SRCTEXTURE1, SHADER_PARAM_TYPE_TEXTURE, "", "" ) + SHADER_PARAM( SRCTEXTURE2, SHADER_PARAM_TYPE_TEXTURE, "", "" ) + SHADER_PARAM( SRCTEXTURE3, SHADER_PARAM_TYPE_TEXTURE, "", "" ) + + SHADER_PARAM( SELECTOR0, SHADER_PARAM_TYPE_INTEGER, "", "" ) + SHADER_PARAM( SELECTOR1, SHADER_PARAM_TYPE_INTEGER, "", "" ) + SHADER_PARAM( SELECTOR2, SHADER_PARAM_TYPE_INTEGER, "", "" ) + SHADER_PARAM( SELECTOR3, SHADER_PARAM_TYPE_INTEGER, "", "" ) + SHADER_PARAM( SELECTOR4, SHADER_PARAM_TYPE_INTEGER, "", "" ) + SHADER_PARAM( SELECTOR5, SHADER_PARAM_TYPE_INTEGER, "", "" ) + SHADER_PARAM( SELECTOR6, SHADER_PARAM_TYPE_INTEGER, "", "" ) + SHADER_PARAM( SELECTOR7, SHADER_PARAM_TYPE_INTEGER, "", "" ) + SHADER_PARAM( SELECTOR8, SHADER_PARAM_TYPE_INTEGER, "", "" ) + SHADER_PARAM( SELECTOR9, SHADER_PARAM_TYPE_INTEGER, "", "" ) + SHADER_PARAM( SELECTOR10, SHADER_PARAM_TYPE_INTEGER, "", "" ) + SHADER_PARAM( SELECTOR11, SHADER_PARAM_TYPE_INTEGER, "", "" ) + SHADER_PARAM( SELECTOR12, SHADER_PARAM_TYPE_INTEGER, "", "" ) + SHADER_PARAM( SELECTOR13, SHADER_PARAM_TYPE_INTEGER, "", "" ) + SHADER_PARAM( SELECTOR14, SHADER_PARAM_TYPE_INTEGER, "", "" ) + SHADER_PARAM( SELECTOR15, SHADER_PARAM_TYPE_INTEGER, "", "" ) + + SHADER_PARAM( DEBUG_MODE, SHADER_PARAM_TYPE_BOOL, "", "" ) + END_SHADER_PARAMS + + void SetupVarsCompositorInfo( CompositorInfo_t* pOutInfo ) + { + Assert( pOutInfo != NULL ); + + ( *pOutInfo ).m_nCombineMode = COMBINE_MODE; + ( *pOutInfo ).m_nTextureInputCount = TEXTUREINPUTCOUNT; + ( *pOutInfo ).m_nTexTransform[ 0 ] = TEXTRANSFORM0; + ( *pOutInfo ).m_nTexTransform[ 1 ] = TEXTRANSFORM1; + ( *pOutInfo ).m_nTexTransform[ 2 ] = TEXTRANSFORM2; + ( *pOutInfo ).m_nTexTransform[ 3 ] = TEXTRANSFORM3; + ( *pOutInfo ).m_nTexAdjustLevels[ 0 ] = TEXADJUSTLEVELS0; + ( *pOutInfo ).m_nTexAdjustLevels[ 1 ] = TEXADJUSTLEVELS1; + ( *pOutInfo ).m_nTexAdjustLevels[ 2 ] = TEXADJUSTLEVELS2; + ( *pOutInfo ).m_nTexAdjustLevels[ 3 ] = TEXADJUSTLEVELS3; + ( *pOutInfo ).m_nSrcTexture[ 0 ] = SRCTEXTURE0; + ( *pOutInfo ).m_nSrcTexture[ 1 ] = SRCTEXTURE1; + ( *pOutInfo ).m_nSrcTexture[ 2 ] = SRCTEXTURE2; + ( *pOutInfo ).m_nSrcTexture[ 3 ] = SRCTEXTURE3; + ( *pOutInfo ).m_nSelector[ 0 ] = SELECTOR0; + ( *pOutInfo ).m_nSelector[ 1 ] = SELECTOR1; + ( *pOutInfo ).m_nSelector[ 2 ] = SELECTOR2; + ( *pOutInfo ).m_nSelector[ 3 ] = SELECTOR3; + ( *pOutInfo ).m_nSelector[ 4 ] = SELECTOR4; + ( *pOutInfo ).m_nSelector[ 5 ] = SELECTOR5; + ( *pOutInfo ).m_nSelector[ 6 ] = SELECTOR6; + ( *pOutInfo ).m_nSelector[ 7 ] = SELECTOR7; + ( *pOutInfo ).m_nSelector[ 8 ] = SELECTOR8; + ( *pOutInfo ).m_nSelector[ 9 ] = SELECTOR9; + ( *pOutInfo ).m_nSelector[ 10 ] = SELECTOR10; + ( *pOutInfo ).m_nSelector[ 11 ] = SELECTOR11; + ( *pOutInfo ).m_nSelector[ 12 ] = SELECTOR12; + ( *pOutInfo ).m_nSelector[ 13 ] = SELECTOR13; + ( *pOutInfo ).m_nSelector[ 14 ] = SELECTOR14; + ( *pOutInfo ).m_nSelector[ 15 ] = SELECTOR15; + ( *pOutInfo ).m_bDebug = DEBUG_MODE; + + if ( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + ( *pOutInfo).m_nTexturesPerPass = 4; + else + ( *pOutInfo).m_nTexturesPerPass = 2; + } + + + SHADER_INIT + { + + } + + SHADER_FALLBACK + { + // Requires DX9 + above + if ( !g_pHardwareConfig->SupportsVertexAndPixelShaders() ) + { + Assert( 0 ); + return "Wireframe"; + } + return 0; + } + + SHADER_DRAW + { + CompositorInfo_t info; + SetupVarsCompositorInfo( &info ); + + if ( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + DrawCompositorStage_ps20b( this, params, pShaderShadow, pShaderAPI, vertexCompression, info ); + else + DrawCompositorStage_ps20( this, params, pShaderShadow, pShaderAPI, vertexCompression, info ); + } +END_SHADER + +static void DrawCompositorStage_common( CBaseVSShader *pShader, IMaterialVar **params, IShaderShadow* pShaderShadow, IShaderDynamicAPI* pShaderAPI, VertexCompressionType_t vertexCompression, const CompositorInfo_t &info ) +{ + int nCombineMode = params[ info.m_nCombineMode ]->GetIntValue(); + + SHADOW_STATE + { + pShader->SetInitialShadowState(); + + // It's a quad, don't cull me bro. + pShaderShadow->EnableCulling( false ); + pShaderShadow->EnablePolyOffset( SHADER_POLYOFFSET_DISABLE ); + + pShaderShadow->EnableDepthWrites( false ); + pShaderShadow->EnableDepthTest( false ); + + // In 2.0b shaders, we use the skin shader and alpha carries specular mask information-- + // so we need to write it + // But with 2.0 shaders used by at least one customer in 2015, we fall back to + // vertexlitgeneric and it doesn't do the same transforms as skin to the alpha shader + // Since it won't be used anyways and it breaks the item model panel icons to write alpha + // DON'T when we're running with 2.0 shaders. + pShaderShadow->EnableAlphaWrites( g_pHardwareConfig->SupportsPixelShaders_2_b() ); + + pShaderShadow->EnableSRGBWrite( true ); + + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, nCombineMode != ECO_Select ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER1, true ); + + int fmt = VERTEX_POSITION; + pShaderShadow->VertexShaderVertexFormat( fmt, 1, 0, 0 ); + + pShaderShadow->SetVertexShader( "compositor_vs20", 0 ); + } + + DYNAMIC_STATE + { + pShaderAPI->SetDefaultState(); + + pShaderAPI->SetVertexShaderIndex( 0 ); + + int textureCount = GetIntParam( info.m_nTextureInputCount, params ); + int textureCountThisPass = Min( textureCount, info.m_nTexturesPerPass ); + + float f4TextureCountThisPass[] = { ( float ) textureCountThisPass, 0.0f, 0.0f, 0.0f }; + Assert( ARRAYSIZE( f4TextureCountThisPass ) == 4 ); + + pShaderAPI->SetPixelShaderConstant( 6, f4TextureCountThisPass ); + + if ( textureCountThisPass > 0 ) pShader->BindTexture( SHADER_SAMPLER0, info.m_nSrcTexture[0] ); + if ( textureCountThisPass > 0 ) pShader->SetVertexShaderMatrix2x4( 2, info.m_nTexTransform[0] ); + + if ( nCombineMode == ECO_Select ) + { + static const float cFac = 1.0f / 16.0f; + + float selectors[] = + { + cFac * GetIntParam( info.m_nSelector[ 0 ], params ), + cFac * GetIntParam( info.m_nSelector[ 1 ], params ), + cFac * GetIntParam( info.m_nSelector[ 2 ], params ), + cFac * GetIntParam( info.m_nSelector[ 3 ], params ), + cFac * GetIntParam( info.m_nSelector[ 4 ], params ), + cFac * GetIntParam( info.m_nSelector[ 5 ], params ), + cFac * GetIntParam( info.m_nSelector[ 6 ], params ), + cFac * GetIntParam( info.m_nSelector[ 7 ], params ), + cFac * GetIntParam( info.m_nSelector[ 8 ], params ), + cFac * GetIntParam( info.m_nSelector[ 9 ], params ), + cFac * GetIntParam( info.m_nSelector[ 10 ], params ), + cFac * GetIntParam( info.m_nSelector[ 11 ], params ), + cFac * GetIntParam( info.m_nSelector[ 12 ], params ), + cFac * GetIntParam( info.m_nSelector[ 13 ], params ), + cFac * GetIntParam( info.m_nSelector[ 14 ], params ), + cFac * GetIntParam( info.m_nSelector[ 15 ], params ) + }; + + pShaderAPI->SetPixelShaderConstant( 7, selectors, 4 ); + } + } +} + +// Helper function when using ps20 and performing multiply and add operations. +static void DrawCompositorStage_ps20_muladdblend( CBaseVSShader *pShader, IMaterialVar **params, IShaderShadow* pShaderShadow, IShaderDynamicAPI* pShaderAPI, VertexCompressionType_t vertexCompression, const CompositorInfo_t &info ) +{ + int nCombineMode = params[ info.m_nCombineMode ]->GetIntValue(); + + SHADOW_STATE + { + { + DECLARE_STATIC_PIXEL_SHADER( compositor_ps20 ); + SET_STATIC_PIXEL_SHADER_COMBO( COMBINE_MODE, nCombineMode ); + SET_STATIC_PIXEL_SHADER( compositor_ps20 ); + } + pShader->Draw(); + + // We can blend on top for second and subsequent writes. + pShaderShadow->EnableBlending( true ); + if ( nCombineMode == ECO_Multiply ) + pShaderShadow->BlendFunc( SHADER_BLEND_DST_COLOR, SHADER_BLEND_ZERO ); + else + pShaderShadow->BlendFunc( SHADER_BLEND_ONE, SHADER_BLEND_ONE ); + + pShader->Draw(); + } + + DYNAMIC_STATE + { + int textureCount = GetIntParam( info.m_nTextureInputCount, params ); + int textureCountThisPass = Min( textureCount, info.m_nTexturesPerPass ); + Assert( textureCount > 0 ); // Valid, but would be really weird. + Assert( textureCountThisPass > 0 ); // That's bogus + + if ( textureCountThisPass > 0 ) pShader->SetPixelShaderConstantGammaToLinear( 2, info.m_nTexAdjustLevels[ 0 ] ); + + if ( textureCountThisPass > 1 ) pShader->BindTexture( SHADER_SAMPLER1, info.m_nSrcTexture[ 1 ] ); + if ( textureCountThisPass > 1 ) pShader->SetVertexShaderMatrix2x4( 4, info.m_nTexTransform[ 1 ] ); + if ( textureCountThisPass > 1 ) pShader->SetPixelShaderConstantGammaToLinear( 3, info.m_nTexAdjustLevels[ 1 ] ); + + { + DECLARE_DYNAMIC_PIXEL_SHADER( compositor_ps20 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( DEBUG_MODE, 0 ); + SET_DYNAMIC_PIXEL_SHADER( compositor_ps20 ); + } + pShader->Draw(); + + textureCountThisPass = Max( 0, textureCount - textureCountThisPass ); + Assert( textureCountThisPass <= info.m_nTexturesPerPass ); + + float f4TextureCountThisPass[] = { (float)textureCountThisPass, 0.0f, 0.0f, 0.0f }; + Assert( ARRAYSIZE( f4TextureCountThisPass ) == 4 ); + + pShaderAPI->SetPixelShaderConstant( 6, f4TextureCountThisPass ); + + if ( textureCountThisPass > 0 ) pShader->BindTexture( SHADER_SAMPLER0, info.m_nSrcTexture[ 2 ] ); + if ( textureCountThisPass > 0 ) pShader->SetVertexShaderMatrix2x4( 2, info.m_nTexTransform[ 2 ] ); + if ( textureCountThisPass > 0 ) pShader->SetPixelShaderConstantGammaToLinear( 2, info.m_nTexAdjustLevels[ 2 ] ); + + if ( textureCountThisPass > 1 ) pShader->BindTexture( SHADER_SAMPLER1, info.m_nSrcTexture[ 3 ] ); + if ( textureCountThisPass > 1 ) pShader->SetVertexShaderMatrix2x4( 4, info.m_nTexTransform[ 3 ] ); + if ( textureCountThisPass > 1 ) pShader->SetPixelShaderConstantGammaToLinear( 3, info.m_nTexAdjustLevels[ 3 ] ); + + pShader->Draw( textureCountThisPass > 0 ); + } +} + +// Helper function when using ps20 and performing lerp operations. +static void DrawCompositorStage_ps20_lerp( CBaseVSShader *pShader, IMaterialVar **params, IShaderShadow* pShaderShadow, IShaderDynamicAPI* pShaderAPI, VertexCompressionType_t vertexCompression, const CompositorInfo_t &info ) +{ + SHADOW_STATE + { + { + DECLARE_STATIC_PIXEL_SHADER( compositor_ps20 ); + SET_STATIC_PIXEL_SHADER_COMBO( COMBINE_MODE, ECO_Legacy_Lerp_FirstPass ); + SET_STATIC_PIXEL_SHADER( compositor_ps20 ); + } + pShader->Draw(); + + // We can blend on top for second write. + pShaderShadow->EnableBlending( true ); + pShaderShadow->BlendFunc( SHADER_BLEND_ONE, SHADER_BLEND_ONE ); + + { + DECLARE_STATIC_PIXEL_SHADER( compositor_ps20 ); + SET_STATIC_PIXEL_SHADER_COMBO( COMBINE_MODE, ECO_Legacy_Lerp_SecondPass ); + SET_STATIC_PIXEL_SHADER( compositor_ps20 ); + } + pShader->Draw(); + } + + DYNAMIC_STATE + { + Assert( GetIntParam( info.m_nTextureInputCount, params ) == 3 ); + + pShader->SetPixelShaderConstantGammaToLinear( 2, info.m_nTexAdjustLevels[ 0 ] ); + + pShader->BindTexture( SHADER_SAMPLER1, info.m_nSrcTexture[ 2 ] ); + pShader->SetVertexShaderMatrix2x4( 4, info.m_nTexTransform[ 2 ] ); + pShader->SetPixelShaderConstantGammaToLinear( 3, info.m_nTexAdjustLevels[ 2 ] ); + + { + DECLARE_DYNAMIC_PIXEL_SHADER( compositor_ps20 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( DEBUG_MODE, 0 ); + SET_DYNAMIC_PIXEL_SHADER( compositor_ps20 ); + } + pShader->Draw(); + + pShader->BindTexture( SHADER_SAMPLER0, info.m_nSrcTexture[ 1 ] ); + pShader->SetVertexShaderMatrix2x4( 2, info.m_nTexTransform[ 1 ] ); + pShader->SetPixelShaderConstantGammaToLinear( 2, info.m_nTexAdjustLevels[ 1 ] ); + + pShader->Draw(); + } +} + +// Helper function when using ps20 and performing lerp operations. +static void DrawCompositorStage_ps20_select( CBaseVSShader *pShader, IMaterialVar **params, IShaderShadow* pShaderShadow, IShaderDynamicAPI* pShaderAPI, VertexCompressionType_t vertexCompression, const CompositorInfo_t &info ) +{ + int nCombineMode = params[ info.m_nCombineMode ]->GetIntValue(); + + SHADOW_STATE + { + { + DECLARE_STATIC_PIXEL_SHADER( compositor_ps20 ); + SET_STATIC_PIXEL_SHADER_COMBO( COMBINE_MODE, nCombineMode ); + SET_STATIC_PIXEL_SHADER( compositor_ps20 ); + } + pShader->Draw(); + } + + DYNAMIC_STATE + { + Assert( GetIntParam( info.m_nTextureInputCount, params ) == 1 ); + + pShader->SetPixelShaderConstantGammaToLinear( 2, info.m_nTexAdjustLevels[ 0 ] ); + { + DECLARE_DYNAMIC_PIXEL_SHADER( compositor_ps20 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( DEBUG_MODE, 0 ); + SET_DYNAMIC_PIXEL_SHADER( compositor_ps20 ); + } + pShader->Draw(); + } +} + +static void DrawCompositorStage_ps20( CBaseVSShader *pShader, IMaterialVar **params, IShaderShadow* pShaderShadow, IShaderDynamicAPI* pShaderAPI, VertexCompressionType_t vertexCompression, const CompositorInfo_t &info ) +{ + DrawCompositorStage_common( pShader, params, pShaderShadow, pShaderAPI, vertexCompression, info ); + + int nCombineMode = params[ info.m_nCombineMode ]->GetIntValue(); + + switch ( nCombineMode ) + { + case ECO_Multiply: + case ECO_Add: + case ECO_Blend: + DrawCompositorStage_ps20_muladdblend( pShader, params, pShaderShadow, pShaderAPI, vertexCompression, info ); + return; + case ECO_Lerp: + DrawCompositorStage_ps20_lerp( pShader, params, pShaderShadow, pShaderAPI, vertexCompression, info ); + return; + case ECO_Select: + DrawCompositorStage_ps20_select( pShader, params, pShaderShadow, pShaderAPI, vertexCompression, info ); + return; + default: + Assert( !"Need to update DrawCompositoreStage_ps20 with how to draw this mode." ); + break; + } +} + +static void DrawCompositorStage_ps20b( CBaseVSShader *pShader, IMaterialVar **params, IShaderShadow* pShaderShadow, IShaderDynamicAPI* pShaderAPI, VertexCompressionType_t vertexCompression, const CompositorInfo_t &info ) +{ + int nCombineMode = params[ info.m_nCombineMode ]->GetIntValue(); + + DrawCompositorStage_common( pShader, params, pShaderShadow, pShaderAPI, vertexCompression, info ); + + SHADOW_STATE + { + pShaderShadow->EnableTexture( SHADER_SAMPLER2, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER3, true ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER2, true ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER3, true ); + + DECLARE_STATIC_PIXEL_SHADER( compositor_ps20b ); + SET_STATIC_PIXEL_SHADER_COMBO( COMBINE_MODE, nCombineMode ); + SET_STATIC_PIXEL_SHADER( compositor_ps20b ); + + pShader->Draw(); + } + + DYNAMIC_STATE + { + int textureCount = GetIntParam( info.m_nTextureInputCount, params ); + int textureCountThisPass = Min( textureCount, info.m_nTexturesPerPass ); + Assert( textureCount > 0 ); // Valid, but would be really weird. + Assert( textureCountThisPass > 0 ); // That's bogus + + // Slot 0 is mostly already handled by common + if ( textureCountThisPass > 0 ) pShader->SetPixelShaderConstant( 2, info.m_nTexAdjustLevels[ 0 ] ); + + if ( textureCountThisPass > 1 ) pShader->BindTexture( SHADER_SAMPLER1, info.m_nSrcTexture[ 1 ] ); + if ( textureCountThisPass > 1 ) pShader->SetVertexShaderMatrix2x4( 4, info.m_nTexTransform[ 1 ] ); + if ( textureCountThisPass > 1 ) pShader->SetPixelShaderConstant( 3, info.m_nTexAdjustLevels[ 1 ] ); + + if ( textureCountThisPass > 2 ) pShader->BindTexture( SHADER_SAMPLER2, info.m_nSrcTexture[ 2 ] ); + if ( textureCountThisPass > 2 ) pShader->SetVertexShaderMatrix2x4( 6, info.m_nTexTransform[ 2 ] ); + if ( textureCountThisPass > 2 ) pShader->SetPixelShaderConstant( 4, info.m_nTexAdjustLevels[ 2 ] ); + + if ( textureCountThisPass > 3 ) pShader->BindTexture( SHADER_SAMPLER3, info.m_nSrcTexture[ 3 ] ); + if ( textureCountThisPass > 3 ) pShader->SetVertexShaderMatrix2x4( 8, info.m_nTexTransform[ 3 ] ); + if ( textureCountThisPass > 3 ) pShader->SetPixelShaderConstant( 5, info.m_nTexAdjustLevels[ 3 ] ); + + DECLARE_DYNAMIC_PIXEL_SHADER( compositor_ps20b ); + #ifdef STAGING_ONLY + SET_DYNAMIC_PIXEL_SHADER_COMBO( DEBUG_MODE, r_texcomp_debug_stickers.GetBool() ? 1 : 0 ); + #else + SET_DYNAMIC_PIXEL_SHADER_COMBO( DEBUG_MODE, 0 ); + #endif + SET_DYNAMIC_PIXEL_SHADER( compositor_ps20b ); + + pShader->Draw(); + } +} + diff --git a/materialsystem/stdshaders/compositor_ps2x.fxc b/materialsystem/stdshaders/compositor_ps2x.fxc new file mode 100644 index 0000000..87a62ab --- /dev/null +++ b/materialsystem/stdshaders/compositor_ps2x.fxc @@ -0,0 +1,340 @@ +//======= Copyright © 1996-2015, Valve Corporation, All rights reserved. ====== +// STATIC: "COMBINE_MODE" "0..6" // See below for meanings of combine modes. +// DYNAMIC: "DEBUG_MODE" "0..0" [ps20] +// DYNAMIC: "DEBUG_MODE" "0..1" [ps20b] [ps30] + +// Lerps are implemented by a multiply / blend / multiply inverse on ps20 +// SKIP: ( $COMBINE_MODE == 2 ) [ps20] +// SKIP: ( $COMBINE_MODE == 4 || $COMBINE_MODE == 5 ) [ps20b] +// SKIP: ( $COMBINE_MODE == 4 || $COMBINE_MODE == 5 ) [ps30] +// SKIP: ( $COMBINE_MODE != 6 && $DEBUG_MODE == 1 ) + +#include "common_ps_fxc.h" + +struct PS_INPUT +{ + float4 texCoord01 : TEXCOORD0; + float4 texCoord23 : TEXCOORD1; +}; + +#define COMBINE_MODE_MULTIPLY 0 +#define COMBINE_MODE_ADD 1 +#define COMBINE_MODE_LERP 2 +#define COMBINE_MODE_SELECTOR 3 +#define COMBINE_MODE_LERP_TEX_FIRST 4 +#define COMBINE_MODE_LERP_TEX_SECOND 5 +#define COMBINE_MODE_BLEND 6 + +#if ( !defined( SHADER_MODEL_PS_2_0 ) ) + #define SKIP_SRGB_ENC_DEC 0 + #define ALLOW_FOUR_TEX_LOOKUPS_PER_STAGE 1 +#else + #define SKIP_SRGB_ENC_DEC 1 + #define ALLOW_FOUR_TEX_LOOKUPS_PER_STAGE 0 +#endif + +const float4 cAdjustInLevel[4] : register( c2 ); +const int cNumTextures : register( c6 ); +const float4 cSelectValues[4] : register( c7 ); + +sampler InSampler0 : register( s0 ); +sampler InSampler1 : register( s1 ); +#if ( ALLOW_FOUR_TEX_LOOKUPS_PER_STAGE ) + sampler InSampler2 : register( s2 ); + sampler InSampler3 : register( s3 ); +#endif + +#define texCoord0 texCoord01.xy +#define texCoord1 texCoord01.zw +#if ( ALLOW_FOUR_TEX_LOOKUPS_PER_STAGE ) + #define texCoord2 texCoord23.xy + #define texCoord3 texCoord23.zw +#endif + +#define g_AdjustInBlack(n) cAdjustInLevel[n].x +#define g_AdjustInWhite(n) cAdjustInLevel[n].y +#define g_AdjustGamma(n) cAdjustInLevel[n].z + +static const float4 cErrColor = float4( 0.0, 1.0, 0.0, 1.0 ); + +#if ( COMBINE_MODE == COMBINE_MODE_MULTIPLY ) + static const float4 cSafeColor = float4( 1.0, 1.0, 1.0, 1.0 ); +#elif ( COMBINE_MODE == COMBINE_MODE_ADD ) + static const float4 cSafeColor = float4( 0.0, 0.0, 0.0, 0.0 ); +#elif ( COMBINE_MODE == COMBINE_MODE_LERP ) + static const float4 cSafeColor = float4( 1.0, 1.0, 1.0, 1.0 ); +#elif ( COMBINE_MODE == COMBINE_MODE_SELECTOR ) + static const float4 cSafeColor = float4( 0.0, 0.0, 0.0, 0.0 ); +#elif ( COMBINE_MODE == COMBINE_MODE_LERP_TEX_FIRST ) || ( COMBINE_MODE == COMBINE_MODE_LERP_TEX_SECOND ) +#elif ( COMBINE_MODE == COMBINE_MODE_BLEND ) + static const float4 cSafeColor = float4( 0.0, 0.0, 0.0, 0.0 ); +#else + #error "Need to add mode selection here." +#endif + +float invlerp( float x, float y, float r ) +{ + return ( r - x ) / ( y - x ); +} + +float4 invlerp( float x, float y, float4 r ) +{ + return ( r - x ) / ( y - x ); +} + +float4 ConvertLinearTosRGB( float4 lin ) +{ + #if ( SKIP_SRGB_ENC_DEC ) + // If we're in ps 2.0, we don't have the instruction slots to do this correctly + return lin; + #else + float3 col_lin = lin.xyz; + float3 col_srgb; + for (int i = 0; i < 3; ++i) + { + if ( col_lin[i] <= 0.0031308f ) + col_srgb[i] = 12.92 * col_lin[i]; + else + col_srgb[i] = 1.055 * pow( col_lin[i], 1.0 / 2.4 ) - 0.055; + } + + return float4( col_srgb.xyz, lin.a ); + #endif +} + +float4 ConvertsRGBToLinear( float4 srgb ) +{ + #if ( SKIP_SRGB_ENC_DEC ) + // If we're in ps 2.0, we don't have the instruction slots to do this correctly + return srgb; + #else + float3 col_srgb = srgb.xyz; + float3 col_lin; + + for (int i = 0; i < 3; ++i) + { + if ( col_srgb[i] <= 0.04045 ) + col_lin[i] = col_srgb[i] / 12.92; + else + col_lin[i] = pow( ( col_srgb[i] + 0.055 ) / 1.055, 2.4 ); + } + + return float4( col_lin.xyz, srgb.a ); + #endif +} + + +// Uses photoshop math to perform level adjustment. +// Note: Photoshop does this math in sRGB space, even though that is mathematically wrong. +// To match photoshop, we have to convert our textures from linear space (they're always linear in the shader) +// to sRGB, perform the calculations and then return to linear space for output from the shader. +// Yuck. +float AdjustLevels( float inSrc, float inBlackPoint, float inWhitePoint, float inGammaValue ) +{ + if ( inBlackPoint == 0.0 && inWhitePoint == 1.0 && inGammaValue == 1.0 ) + return inSrc; + else + { + inSrc = ConvertLinearTosRGB( inSrc ); + + float pcg = saturate( invlerp( inBlackPoint, inWhitePoint, inSrc ) ); + float gammaAdjusted = pow( pcg, inGammaValue ); + + gammaAdjusted = ConvertsRGBToLinear( gammaAdjusted ); + + return saturate( gammaAdjusted ); + } +} + +float4 AdjustLevels( float4 inSrc, float inBlackPoint, float inWhitePoint, float inGammaValue ) +{ + if ( inBlackPoint == 0.0 && inWhitePoint == 1.0 && inGammaValue == 1.0 ) + return inSrc; + else + { + inSrc = ConvertLinearTosRGB( inSrc ); + + float4 pcg = saturate( invlerp( inBlackPoint, inWhitePoint, inSrc ) ); + float4 gammaAdjusted = pow( pcg, inGammaValue ); + + gammaAdjusted = ConvertsRGBToLinear( gammaAdjusted ); + + return saturate( gammaAdjusted ); + } +} + +#if ( COMBINE_MODE == COMBINE_MODE_MULTIPLY || COMBINE_MODE == COMBINE_MODE_ADD ) || ( COMBINE_MODE == COMBINE_MODE_BLEND ) + float4 main_simple( PS_INPUT i ) + { + float4 color0 = cNumTextures > 0 ? tex2D( InSampler0, i.texCoord0 ) : cSafeColor; + float4 color1 = cNumTextures > 1 ? tex2D( InSampler1, i.texCoord1 ) : cSafeColor; + #if ALLOW_FOUR_TEX_LOOKUPS_PER_STAGE + float4 color2 = cNumTextures > 2 ? tex2D( InSampler2, i.texCoord2 ) : cSafeColor; + float4 color3 = cNumTextures > 3 ? tex2D( InSampler3, i.texCoord3 ) : cSafeColor; + #endif + + color0 = cNumTextures > 0 ? AdjustLevels( color0, g_AdjustInBlack(0), g_AdjustInWhite(0), g_AdjustGamma(0) ) : cSafeColor; + color1 = cNumTextures > 1 ? AdjustLevels( color1, g_AdjustInBlack(1), g_AdjustInWhite(1), g_AdjustGamma(1) ) : cSafeColor; + #if ALLOW_FOUR_TEX_LOOKUPS_PER_STAGE + color2 = cNumTextures > 2 ? AdjustLevels( color2, g_AdjustInBlack(2), g_AdjustInWhite(2), g_AdjustGamma(2) ) : cSafeColor; + color3 = cNumTextures > 3 ? AdjustLevels( color3, g_AdjustInBlack(3), g_AdjustInWhite(3), g_AdjustGamma(3) ) : cSafeColor; + #endif + #if ( COMBINE_MODE == COMBINE_MODE_MULTIPLY ) + return color0 + * color1 + #if ALLOW_FOUR_TEX_LOOKUPS_PER_STAGE + * color2 + * color3 + #endif + ; + #elif ( COMBINE_MODE == COMBINE_MODE_ADD ) + return color0 + + color1 + #if ALLOW_FOUR_TEX_LOOKUPS_PER_STAGE + + color2 + + color3 + #endif + ; + #elif ( COMBINE_MODE == COMBINE_MODE_BLEND ) + // color0 is the previous frame's data. + // color1 is the sticker's data, with alpha as transparency. + // If we're on PS 2.0b, color2 has specular info as a grayscale texture--make sure to write that out. + + #if ( DEBUG_MODE == 0 ) + #if ALLOW_FOUR_TEX_LOOKUPS_PER_STAGE + float srcSpecular = color2.r; + #else + float srcSpecular = 1; + #endif + + + float3 tmpColor = ( 1.0 - color1.a ) * color0.xyz + + ( color1.a ) * color1.xyz; + + float tmpSpecular = ( 1.0 - color1.a ) * color0.w + + ( color1.a ) * srcSpecular; + + return float4( tmpColor.xyz, tmpSpecular ); + #else + if ( i.texCoord1.x < 0 || i.texCoord1.y < 0 + || i.texCoord1.x > 1 || i.texCoord1.y > 1 ) + { + return color0; + } + else + return float4( i.texCoord1.xy, 0, color0.a ); + #endif + #else + #error "Surprising combine mode in function, update code." + #endif + } +#endif + +#if ( COMBINE_MODE == COMBINE_MODE_LERP ) + float4 main_lerp( PS_INPUT i ) + { + if (cNumTextures == 3) + { + float4 color0 = tex2D( InSampler0, i.texCoord0 ); + float4 color1 = tex2D( InSampler1, i.texCoord1 ); + float4 colSel = tex2D( InSampler2, i.texCoord2 ); + + color0 = AdjustLevels( color0, g_AdjustInBlack(0), g_AdjustInWhite(0), g_AdjustGamma(0) ); + color1 = AdjustLevels( color1, g_AdjustInBlack(1), g_AdjustInWhite(1), g_AdjustGamma(1) ); + colSel = AdjustLevels( colSel, g_AdjustInBlack(2), g_AdjustInWhite(2), g_AdjustGamma(2) ); + + #if ( COMBINE_MODE == COMBINE_MODE_LERP ) + return lerp( color0, color1, colSel.xxxx ); + #else + #error "Surprising combine mode in function, update code." + #endif + } + else + { + return float4( 1, 0, 0, 1 ); + } + } +#endif + +#if ( COMBINE_MODE == COMBINE_MODE_SELECTOR ) + float4 main_selector( PS_INPUT i ) + { + if ( cNumTextures == 1 ) + { + float fNormalizedColor = tex2D( InSampler0, i.texCoord0 ).x; + float fTestColor = round( ( fNormalizedColor * 255.0 / 16.0f ) ); + + bool4 bTestVec[4]; + for ( int i = 0; i < 4; ++i ) + { + bTestVec[i] = cSelectValues[i] != 0 + ? round( cSelectValues[i] ) == fTestColor + : false; + } + + bool4 bAny = bool4( + any( bTestVec[0] ), + any( bTestVec[1] ), + any( bTestVec[2] ), + any( bTestVec[3] ) + ); + + #if ( COMBINE_MODE == COMBINE_MODE_SELECTOR ) + return any( bAny ) + ? float4( 1, 1, 1, 1 ) + : float4( 0, 0, 0, 0 ); + #else + #error "Surprising combine mode in function, update code." + #endif + } + else + { + return float4( 1, 1, 0, 1 ); + } + } +#endif + +#if ( COMBINE_MODE == COMBINE_MODE_LERP_TEX_FIRST || COMBINE_MODE == COMBINE_MODE_LERP_TEX_SECOND ) + float4 main_lerp_multipass( PS_INPUT i ) + { + if (cNumTextures == 2) + { + float4 colorN = tex2D( InSampler0, i.texCoord0 ); + float4 colSel = tex2D( InSampler1, i.texCoord1 ); + + colorN = AdjustLevels( colorN, g_AdjustInBlack(0), g_AdjustInWhite(0), g_AdjustGamma(0) ); + colSel = AdjustLevels( colSel, g_AdjustInBlack(1), g_AdjustInWhite(1), g_AdjustGamma(1) ); + + #if ( COMBINE_MODE == COMBINE_MODE_LERP_TEX_FIRST ) + return colorN * ( 1.0 - colSel.xxxx ); + #elif ( COMBINE_MODE == COMBINE_MODE_LERP_TEX_SECOND ) + return colorN * ( colSel.xxxx ); + #else + #error "Surprising combine mode in function, update code." + #endif + } + else + { + return float4( 1, 0, 0, 1 ); + } + } +#endif + +float4 main( PS_INPUT i ) : COLOR +{ + #if ( COMBINE_MODE == COMBINE_MODE_MULTIPLY ) + return main_simple( i ); + #elif ( COMBINE_MODE == COMBINE_MODE_ADD ) + return main_simple( i ); + #elif ( COMBINE_MODE == COMBINE_MODE_LERP ) + return main_lerp( i ); + #elif ( COMBINE_MODE == COMBINE_MODE_SELECTOR ) + return main_selector( i ); + #elif ( COMBINE_MODE == COMBINE_MODE_LERP_TEX_FIRST || COMBINE_MODE == COMBINE_MODE_LERP_TEX_SECOND ) + return main_lerp_multipass( i ); + #elif ( COMBINE_MODE == COMBINE_MODE_BLEND ) + return main_simple( i ); + #else + #error "Need to add mode selection here." + #endif +} diff --git a/materialsystem/stdshaders/compositor_vs20.fxc b/materialsystem/stdshaders/compositor_vs20.fxc new file mode 100644 index 0000000..bb9c6be --- /dev/null +++ b/materialsystem/stdshaders/compositor_vs20.fxc @@ -0,0 +1,41 @@ +//======= Copyright © 1996-2007, Valve Corporation, All rights reserved. ====== + +#include "common_vs_fxc.h" + +// This could be packed more efficiently if needed. +const float4x2 cXformTexCoord0 : register( c2 ); +const float4x2 cXformTexCoord1 : register( c4 ); +const float4x2 cXformTexCoord2 : register( c6 ); +const float4x2 cXformTexCoord3 : register( c8 ); + +struct VS_INPUT +{ + float3 vPos : POSITION; + float2 vBaseTexCoord : TEXCOORD0; +}; + +struct VS_OUTPUT +{ + float4 projPos : POSITION; + float4 texCoord01 : TEXCOORD0; + float4 texCoord23 : TEXCOORD1; +}; + +#define texCoord0 texCoord01.xy +#define texCoord1 texCoord01.zw +#define texCoord2 texCoord23.xy +#define texCoord3 texCoord23.zw + +VS_OUTPUT main( const VS_INPUT v ) +{ + VS_OUTPUT o = ( VS_OUTPUT )0; + + o.projPos = float4( v.vPos, 1.0f ); + + o.texCoord0 = mul( float3( v.vBaseTexCoord, 1 ), (float3x2)cXformTexCoord0 ); + o.texCoord1 = mul( float3( v.vBaseTexCoord, 1 ), (float3x2)cXformTexCoord1 ); + o.texCoord2 = mul( float3( v.vBaseTexCoord, 1 ), (float3x2)cXformTexCoord2 ); + o.texCoord3 = mul( float3( v.vBaseTexCoord, 1 ), (float3x2)cXformTexCoord3 ); + + return o; +} diff --git a/materialsystem/stdshaders/constant_color_ps2x.fxc b/materialsystem/stdshaders/constant_color_ps2x.fxc new file mode 100644 index 0000000..c197dd9 --- /dev/null +++ b/materialsystem/stdshaders/constant_color_ps2x.fxc @@ -0,0 +1,26 @@ +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX] + +#define HDRTYPE HDR_TYPE_NONE +#include "common_ps_fxc.h" + +// this pixel shader compares the luminance against a conatnt value and retruns all 1s when +// greater. + +struct PS_INPUT +{ + float2 coordTap0 : TEXCOORD0; + +#if defined( _X360 ) //matching pixel shader inputs to vertex shader outputs to avoid shader patches + float2 ZeroTexCoord : TEXCOORD1; + float2 bloomTexCoord : TEXCOORD2; +#endif +}; + +float4 Constant_color : register( c0 ); + +float4 main( PS_INPUT i ) : COLOR +{ + return FinalOutput( float4(0,1,0,1), 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE ); //Constant_color; +} + diff --git a/materialsystem/stdshaders/copy_fp_rt_ps2x.fxc b/materialsystem/stdshaders/copy_fp_rt_ps2x.fxc new file mode 100644 index 0000000..ee3a135 --- /dev/null +++ b/materialsystem/stdshaders/copy_fp_rt_ps2x.fxc @@ -0,0 +1,21 @@ +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX] + +#define HDRTYPE HDR_TYPE_NONE +#define HDRENABLED 0 +#include "common_ps_fxc.h" + +sampler InputTexture : register( s0 ); + +struct PS_INPUT +{ + float2 texCoord : TEXCOORD0; +}; + + +float4 main( PS_INPUT i ) : COLOR +{ + float4 input=tex2D( InputTexture, i.texCoord ); + + return FinalOutput( float4(input.xyz,1), 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE ); +} diff --git a/materialsystem/stdshaders/core_dx7.cpp b/materialsystem/stdshaders/core_dx7.cpp new file mode 100644 index 0000000..76bf464 --- /dev/null +++ b/materialsystem/stdshaders/core_dx7.cpp @@ -0,0 +1,43 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//=============================================================================// + + +#include "BaseVSShader.h" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +DEFINE_FALLBACK_SHADER( Core, Core_dx70 ) + +// This is here so that you can use $fallbackmaterial for Core_dx7 +DEFINE_FALLBACK_SHADER( Core_dx70, Wireframe ) + +#if 0 +BEGIN_VS_SHADER( Core_DX70, + "Help for Core_DX70" ) + + BEGIN_SHADER_PARAMS + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + } + + SHADER_FALLBACK + { + return 0; + } + + SHADER_INIT + { + } + + SHADER_DRAW + { + } +END_SHADER +#endif diff --git a/materialsystem/stdshaders/core_dx8.cpp b/materialsystem/stdshaders/core_dx8.cpp new file mode 100644 index 0000000..79d0dcd --- /dev/null +++ b/materialsystem/stdshaders/core_dx8.cpp @@ -0,0 +1,249 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//=============================================================================// + + +#include "BaseVSShader.h" + +#include "core_vs11.inc" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +#define MAXBLUR 1 + +DEFINE_FALLBACK_SHADER( Core, Core_DX80 ) + +BEGIN_VS_SHADER( Core_DX80, + "Help for Core_DX80" ) + + BEGIN_SHADER_PARAMS + SHADER_PARAM_OVERRIDE( COLOR, SHADER_PARAM_TYPE_COLOR, "{255 255 255}", "unused", SHADER_PARAM_NOT_EDITABLE ) + SHADER_PARAM_OVERRIDE( ALPHA, SHADER_PARAM_TYPE_FLOAT, "1.0", "unused", SHADER_PARAM_NOT_EDITABLE ) + SHADER_PARAM( REFRACTAMOUNT, SHADER_PARAM_TYPE_FLOAT, "2", "" ) + SHADER_PARAM( REFRACTTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "refraction tint" ) + SHADER_PARAM( DUDVMAP, SHADER_PARAM_TYPE_TEXTURE, "models/shadertest/shader1_dudv", "dudv bump map" ) + SHADER_PARAM( NORMALMAP, SHADER_PARAM_TYPE_TEXTURE, "models/shadertest/shader1_normal", "normal map" ) + SHADER_PARAM( BUMPFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $bumpmap" ) + SHADER_PARAM( DUDVFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $dudvmap" ) + SHADER_PARAM( BUMPTRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$bumpmap texcoord transform" ) + SHADER_PARAM( TIME, SHADER_PARAM_TYPE_FLOAT, "0.0f", "" ) + SHADER_PARAM( BLURAMOUNT, SHADER_PARAM_TYPE_INTEGER, "1", "0, 1, or 2 for how much blur you want" ) + SHADER_PARAM( FADEOUTONSILHOUETTE, SHADER_PARAM_TYPE_BOOL, "1", "0 for no fade out on silhouette, 1 for fade out on sillhouette" ) + SHADER_PARAM( ENVMAP, SHADER_PARAM_TYPE_TEXTURE, "shadertest/shadertest_env", "envmap" ) + SHADER_PARAM( ENVMAPFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "envmap frame number" ) + SHADER_PARAM( ENVMAPTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "envmap tint" ) + SHADER_PARAM( ENVMAPCONTRAST, SHADER_PARAM_TYPE_FLOAT, "0.0", "contrast 0 == normal 1 == color*color" ) + SHADER_PARAM( ENVMAPSATURATION, SHADER_PARAM_TYPE_FLOAT, "1.0", "saturation 0 == greyscale 1 == normal" ) + SHADER_PARAM( REFRACTTINTTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "models/shadertest/shield", "" ) + SHADER_PARAM( REFRACTTINTTEXTUREFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "" ) + SHADER_PARAM( FRESNELREFLECTION, SHADER_PARAM_TYPE_FLOAT, "1.0", "1.0 == mirror, 0.0 == water" ) + SHADER_PARAM( FALLBACK, SHADER_PARAM_TYPE_STRING, "", "Name of the fallback shader" ) + SHADER_PARAM( FORCEREFRACT, SHADER_PARAM_TYPE_BOOL, "0", "Forces refraction on boards that have poor performance" ) + SHADER_PARAM( NOWRITEZ, SHADER_PARAM_TYPE_INTEGER, "0", "0 == write z, 1 = no write z" ) + SHADER_PARAM( MASKED, SHADER_PARAM_TYPE_BOOL, "0", "mask using dest alpha" ) + SHADER_PARAM( CORECOLORTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "" ); + SHADER_PARAM( CORECOLORTEXTUREFRAME, SHADER_PARAM_TYPE_INTEGER, "", "" ); + SHADER_PARAM( FLOWMAPTEXCOORDOFFSET, SHADER_PARAM_TYPE_FLOAT, "0.0", "" ); + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + SET_FLAGS2( MATERIAL_VAR2_NEEDS_TANGENT_SPACES ); + SET_FLAGS( MATERIAL_VAR_TRANSLUCENT ); + SET_FLAGS2( MATERIAL_VAR2_SUPPORTS_HW_SKINNING ); + if( !params[ENVMAPTINT]->IsDefined() ) + { + params[ENVMAPTINT]->SetVecValue( 1.0f, 1.0f, 1.0f ); + } + if( !params[ENVMAPCONTRAST]->IsDefined() ) + { + params[ENVMAPCONTRAST]->SetFloatValue( 0.0f ); + } + if( !params[ENVMAPSATURATION]->IsDefined() ) + { + params[ENVMAPSATURATION]->SetFloatValue( 1.0f ); + } + if( !params[ENVMAPFRAME]->IsDefined() ) + { + params[ENVMAPFRAME]->SetIntValue( 0 ); + } + if( !params[FRESNELREFLECTION]->IsDefined() ) + { + params[FRESNELREFLECTION]->SetFloatValue( 1.0f ); + } + if( !params[MASKED]->IsDefined() ) + { + params[MASKED]->SetIntValue( 0 ); + } + if( !params[BLURAMOUNT]->IsDefined() ) + { + params[BLURAMOUNT]->SetIntValue( 0 ); + } + if( !params[FADEOUTONSILHOUETTE]->IsDefined() ) + { + params[FADEOUTONSILHOUETTE]->SetIntValue( 0 ); + } + if( !params[BASETEXTURE]->IsDefined() ) + { + SET_FLAGS2( MATERIAL_VAR2_NEEDS_POWER_OF_TWO_FRAME_BUFFER_TEXTURE ); + } + } + + SHADER_FALLBACK + { + if( g_pHardwareConfig->GetDXSupportLevel() < 80 || !g_pHardwareConfig->HasProjectedBumpEnv() ) + return "Core_DX70"; + return NULL; + } + + SHADER_INIT + { + if (params[BASETEXTURE]->IsDefined() ) + { + LoadTexture( BASETEXTURE ); + } + if (params[DUDVMAP]->IsDefined() ) + { + LoadTexture( DUDVMAP ); + } + if (params[NORMALMAP]->IsDefined() ) + { + LoadBumpMap( NORMALMAP ); + } + if( params[ENVMAP]->IsDefined() ) + { + LoadCubeMap( ENVMAP ); + } + if( params[CORECOLORTEXTURE]->IsDefined() ) + { + LoadTexture( CORECOLORTEXTURE ); + } + } + + SHADER_DRAW + { + bool bHasEnvmap = params[ENVMAP]->IsTexture(); + int blurAmount = params[BLURAMOUNT]->GetIntValue(); + if( blurAmount < 0 ) + { + blurAmount = 0; + } + else if( blurAmount > MAXBLUR ) + { + blurAmount = MAXBLUR; + } + bool bMasked = params[MASKED]->GetIntValue()!= 0; + + SHADOW_STATE + { + if ( params[NOWRITEZ]->GetIntValue() != 0 ) + { + pShaderShadow->EnableDepthWrites( false ); + } + + // Alpha test: FIXME: shouldn't this be handled in Shader_t::SetInitialShadowState + pShaderShadow->EnableAlphaTest( IS_FLAG_SET(MATERIAL_VAR_ALPHATEST) ); + + // If envmap is not specified, the alpha channel is the translucency + // (If envmap *is* specified, alpha channel is the reflection amount) + bool bNormalMapAlpha = false; + if ( params[NORMALMAP]->IsTexture() && !bHasEnvmap ) + { + SetDefaultBlendingShadowState( NORMALMAP, false ); + if ( !bMasked && TextureIsTranslucent( NORMALMAP, false ) ) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER3, true ); + bNormalMapAlpha = true; + } + } + + // dudv map + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + + // renderable texture for refraction + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + + // core color texture + pShaderShadow->EnableTexture( SHADER_SAMPLER2, true ); + + int fmt = VERTEX_POSITION | VERTEX_NORMAL; + int userDataSize = 0; + userDataSize = 4; + pShaderShadow->VertexShaderVertexFormat( fmt, 1, 0, userDataSize ); + + DECLARE_STATIC_VERTEX_SHADER( core_vs11 ); + SET_STATIC_VERTEX_SHADER( core_vs11 ); + + int pshIndex = 0; + pShaderShadow->SetPixelShader( "Core_ps11", pshIndex ); + + if( bMasked ) + { + EnableAlphaBlending( SHADER_BLEND_ONE_MINUS_SRC_ALPHA, SHADER_BLEND_SRC_ALPHA ); + } + DefaultFog(); + } + DYNAMIC_STATE + { + pShaderAPI->SetDefaultState(); + + // The dx9.0c runtime says that we shouldn't have a non-zero dimension when using vertex and pixel shaders. + pShaderAPI->SetTextureTransformDimension( SHADER_TEXTURE_STAGE1, 0, true ); + + if ( params[DUDVFRAME]->GetIntValue() == 0 ) + { + BindTexture( SHADER_SAMPLER0, DUDVMAP, BUMPFRAME ); + } + else + { + BindTexture( SHADER_SAMPLER0, DUDVMAP, DUDVFRAME ); + } + + if ( params[BASETEXTURE]->IsTexture() ) + { + BindTexture( SHADER_SAMPLER1, BASETEXTURE, FRAME ); + } + else + { + pShaderAPI->BindStandardTexture( SHADER_SAMPLER1, TEXTURE_FRAME_BUFFER_FULL_TEXTURE_0 ); + } + + BindTexture( SHADER_SAMPLER2, CORECOLORTEXTURE, CORECOLORTEXTUREFRAME ); + + if ( params[NORMALMAP]->IsTexture() ) + { + BindTexture( SHADER_SAMPLER3, NORMALMAP, BUMPFRAME ); + } + + float fRefractionAmount = params[REFRACTAMOUNT]->GetFloatValue(); + pShaderAPI->SetBumpEnvMatrix( SHADER_TEXTURE_STAGE1, fRefractionAmount, 0.0f, 0.0f, fRefractionAmount ); + + SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_1, BUMPTRANSFORM ); + + SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_3, FLOWMAPTEXCOORDOFFSET ); + + DECLARE_DYNAMIC_VERTEX_SHADER( core_vs11 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, pShaderAPI->GetCurrentNumBones() > 0 ); + SET_DYNAMIC_VERTEX_SHADER( core_vs11 ); + } + + Draw(); + + if( bHasEnvmap ) + { + bool bNoWriteZ = (params[NOWRITEZ]->GetIntValue() != 0); + const bool bBlendSpecular = true; + DrawModelBumpedSpecularLighting( NORMALMAP, BUMPFRAME, + ENVMAP, ENVMAPFRAME, + ENVMAPTINT, ALPHA, + ENVMAPCONTRAST, ENVMAPSATURATION, + BUMPTRANSFORM, + bBlendSpecular, bNoWriteZ ); + } + } +END_SHADER + diff --git a/materialsystem/stdshaders/core_dx9.cpp b/materialsystem/stdshaders/core_dx9.cpp new file mode 100644 index 0000000..4be8f3c --- /dev/null +++ b/materialsystem/stdshaders/core_dx9.cpp @@ -0,0 +1,298 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//=============================================================================// + +#include "BaseVSShader.h" +#include "core_vs20.inc" +#include "core_ps20.inc" +#include "core_ps20b.inc" + +#define MAXBLUR 1 + +DEFINE_FALLBACK_SHADER( Core, Core_DX90 ) + +BEGIN_VS_SHADER( Core_DX90, + "Help for Core" ) + + BEGIN_SHADER_PARAMS + SHADER_PARAM_OVERRIDE( COLOR, SHADER_PARAM_TYPE_COLOR, "{255 255 255}", "unused", SHADER_PARAM_NOT_EDITABLE ) + SHADER_PARAM_OVERRIDE( ALPHA, SHADER_PARAM_TYPE_FLOAT, "1.0", "unused", SHADER_PARAM_NOT_EDITABLE ) + SHADER_PARAM( REFRACTAMOUNT, SHADER_PARAM_TYPE_FLOAT, "2", "" ) + SHADER_PARAM( REFRACTTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "refraction tint" ) + SHADER_PARAM( NORMALMAP, SHADER_PARAM_TYPE_TEXTURE, "models/shadertest/shader1_normal", "normal map" ) + SHADER_PARAM( BUMPFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $bumpmap" ) + SHADER_PARAM( BUMPTRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$bumpmap texcoord transform" ) + SHADER_PARAM( TIME, SHADER_PARAM_TYPE_FLOAT, "0.0f", "" ) + SHADER_PARAM( ENVMAP, SHADER_PARAM_TYPE_TEXTURE, "shadertest/shadertest_env", "envmap" ) + SHADER_PARAM( ENVMAPFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "envmap frame number" ) + SHADER_PARAM( ENVMAPTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "envmap tint" ) + SHADER_PARAM( ENVMAPCONTRAST, SHADER_PARAM_TYPE_FLOAT, "0.0", "contrast 0 == normal 1 == color*color" ) + SHADER_PARAM( ENVMAPSATURATION, SHADER_PARAM_TYPE_FLOAT, "1.0", "saturation 0 == greyscale 1 == normal" ) + SHADER_PARAM( FLOWMAP, SHADER_PARAM_TYPE_TEXTURE, "", "flowmap" ) + SHADER_PARAM( FLOWMAPFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $flowmap" ) + SHADER_PARAM( FLOWMAPSCROLLRATE, SHADER_PARAM_TYPE_VEC2, "[0 0", "2D rate to scroll $flowmap" ) + SHADER_PARAM( CORECOLORTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "" ); + SHADER_PARAM( CORECOLORTEXTUREFRAME, SHADER_PARAM_TYPE_INTEGER, "", "" ); + SHADER_PARAM( FLOWMAPTEXCOORDOFFSET, SHADER_PARAM_TYPE_FLOAT, "0.0", "" ); + END_SHADER_PARAMS + SHADER_INIT_PARAMS() + { + SET_FLAGS2( MATERIAL_VAR2_NEEDS_TANGENT_SPACES ); + SET_FLAGS( MATERIAL_VAR_TRANSLUCENT ); + if( !params[ENVMAPTINT]->IsDefined() ) + { + params[ENVMAPTINT]->SetVecValue( 1.0f, 1.0f, 1.0f ); + } + if( !params[ENVMAPCONTRAST]->IsDefined() ) + { + params[ENVMAPCONTRAST]->SetFloatValue( 0.0f ); + } + if( !params[ENVMAPSATURATION]->IsDefined() ) + { + params[ENVMAPSATURATION]->SetFloatValue( 1.0f ); + } + if( !params[ENVMAPFRAME]->IsDefined() ) + { + params[ENVMAPFRAME]->SetIntValue( 0 ); + } + if( !params[BASETEXTURE]->IsDefined() ) + { + SET_FLAGS2( MATERIAL_VAR2_NEEDS_POWER_OF_TWO_FRAME_BUFFER_TEXTURE ); + } + } + + SHADER_FALLBACK + { + if( g_pHardwareConfig->GetDXSupportLevel() < 90 ) + return "Core_dx80"; + + return 0; + } + + SHADER_INIT + { + if (params[BASETEXTURE]->IsDefined() ) + { + LoadTexture( BASETEXTURE, TEXTUREFLAGS_SRGB ); + } + if (params[NORMALMAP]->IsDefined() ) + { + LoadBumpMap( NORMALMAP ); + } + if ( params[ENVMAP]->IsDefined() ) + { + LoadCubeMap( ENVMAP, TEXTUREFLAGS_SRGB ); + } + if ( params[FLOWMAP]->IsDefined() ) + { + LoadTexture( FLOWMAP ); + } + if ( params[CORECOLORTEXTURE]->IsDefined() ) + { + LoadTexture( CORECOLORTEXTURE ); + } + } + + inline void DrawPass( IMaterialVar **params, IShaderShadow* pShaderShadow, + IShaderDynamicAPI* pShaderAPI, int nPass, VertexCompressionType_t vertexCompression ) + { + bool bIsModel = IS_FLAG_SET( MATERIAL_VAR_MODEL ); + bool bHasEnvmap = params[ENVMAP]->IsTexture(); + bool bHasFlowmap = params[FLOWMAP]->IsTexture(); + bool bHasCoreColorTexture = params[CORECOLORTEXTURE]->IsTexture(); + + SHADOW_STATE + { + SetInitialShadowState( ); + + if( nPass == 0 ) + { + // Alpha test: FIXME: shouldn't this be handled in Shader_t::SetInitialShadowState + pShaderShadow->EnableAlphaTest( IS_FLAG_SET(MATERIAL_VAR_ALPHATEST) ); + } + else + { + pShaderShadow->DepthFunc( SHADER_DEPTHFUNC_EQUAL ); + EnableAlphaBlending( SHADER_BLEND_ONE, SHADER_BLEND_ONE ); + } + + // If envmap is not specified, the alpha channel is the translucency + // (If envmap *is* specified, alpha channel is the reflection amount) + if ( params[NORMALMAP]->IsTexture() && !bHasEnvmap ) + { + SetDefaultBlendingShadowState( NORMALMAP, false ); + } + + // source render target that contains the image that we are warping. + pShaderShadow->EnableTexture( SHADER_SAMPLER2, true ); + if( g_pHardwareConfig->GetHDRType() == HDR_TYPE_INTEGER ) + { + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER2, true ); + } + + // normal map + pShaderShadow->EnableTexture( SHADER_SAMPLER3, true ); + if( bHasEnvmap ) + { + // envmap + pShaderShadow->EnableTexture( SHADER_SAMPLER4, true ); + if( g_pHardwareConfig->GetHDRType() == HDR_TYPE_INTEGER ) + { + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER4, true ); + } + } + + if( bHasFlowmap ) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER6, true ); + } + + if( bHasCoreColorTexture ) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER7, true ); + } + + if( g_pHardwareConfig->GetHDRType() != HDR_TYPE_NONE ) + { + pShaderShadow->EnableSRGBWrite( true ); + } + + unsigned int flags = VERTEX_POSITION | VERTEX_NORMAL; + int userDataSize = 0; + int nTexCoordCount = 1; + if( bIsModel ) + { + userDataSize = 4; + } + else + { + flags |= VERTEX_TANGENT_S | VERTEX_TANGENT_T; + } + + // This shader supports compressed vertices, so OR in that flag: + flags |= VERTEX_FORMAT_COMPRESSED; + + pShaderShadow->VertexShaderVertexFormat( flags, nTexCoordCount, NULL, userDataSize ); + + DECLARE_STATIC_VERTEX_SHADER( core_vs20 ); + SET_STATIC_VERTEX_SHADER_COMBO( MODEL, bIsModel ); + SET_STATIC_VERTEX_SHADER( core_vs20 ); + + if ( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_STATIC_PIXEL_SHADER( core_ps20b ); + SET_STATIC_PIXEL_SHADER_COMBO( CUBEMAP, bHasEnvmap && ( nPass == 1 ) ); + SET_STATIC_PIXEL_SHADER_COMBO( FLOWMAP, bHasFlowmap ); + SET_STATIC_PIXEL_SHADER_COMBO( CORECOLORTEXTURE, bHasCoreColorTexture && ( nPass == 0 ) ); + SET_STATIC_PIXEL_SHADER_COMBO( REFRACT, nPass == 0 ); + SET_STATIC_PIXEL_SHADER( core_ps20b ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( core_ps20 ); + SET_STATIC_PIXEL_SHADER_COMBO( CUBEMAP, bHasEnvmap && ( nPass == 1 ) ); + SET_STATIC_PIXEL_SHADER_COMBO( FLOWMAP, bHasFlowmap ); + SET_STATIC_PIXEL_SHADER_COMBO( CORECOLORTEXTURE, bHasCoreColorTexture && ( nPass == 0 ) ); + SET_STATIC_PIXEL_SHADER_COMBO( REFRACT, nPass == 0 ); + SET_STATIC_PIXEL_SHADER( core_ps20 ); + } + + DefaultFog(); + } + DYNAMIC_STATE + { + pShaderAPI->SetDefaultState(); + + if ( params[BASETEXTURE]->IsTexture() ) + { + BindTexture( SHADER_SAMPLER2, BASETEXTURE, FRAME ); + } + else + { + pShaderAPI->BindStandardTexture( SHADER_SAMPLER2, TEXTURE_FRAME_BUFFER_FULL_TEXTURE_0 ); + } + + BindTexture( SHADER_SAMPLER3, NORMALMAP, BUMPFRAME ); + + if( bHasEnvmap ) + { + BindTexture( SHADER_SAMPLER4, ENVMAP, ENVMAPFRAME ); + } + + if( bHasFlowmap ) + { + BindTexture( SHADER_SAMPLER6, FLOWMAP, FLOWMAPFRAME ); + } + + if( bHasCoreColorTexture ) + { + BindTexture( SHADER_SAMPLER7, CORECOLORTEXTURE, CORECOLORTEXTUREFRAME ); + } + + DECLARE_DYNAMIC_VERTEX_SHADER( core_vs20 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, pShaderAPI->GetCurrentNumBones() > 0 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression ); + SET_DYNAMIC_VERTEX_SHADER( core_vs20 ); + + if ( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_DYNAMIC_PIXEL_SHADER( core_ps20b ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + SET_DYNAMIC_PIXEL_SHADER( core_ps20b ); + } + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( core_ps20 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + SET_DYNAMIC_PIXEL_SHADER( core_ps20 ); + } + + SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_1, BUMPTRANSFORM ); + + if( g_pHardwareConfig->GetHDRType() == HDR_TYPE_NONE ) + { + SetPixelShaderConstant( 0, ENVMAPTINT ); + SetPixelShaderConstant( 1, REFRACTTINT ); + } + else + { + SetPixelShaderConstantGammaToLinear( 0, ENVMAPTINT ); + SetPixelShaderConstantGammaToLinear( 1, REFRACTTINT ); + } + SetPixelShaderConstant( 2, ENVMAPCONTRAST ); + SetPixelShaderConstant( 3, ENVMAPSATURATION ); + float c5[4] = { params[REFRACTAMOUNT]->GetFloatValue(), + params[REFRACTAMOUNT]->GetFloatValue(), 0.0f, 0.0f }; + pShaderAPI->SetPixelShaderConstant( 5, c5, 1 ); + + float eyePos[4]; + s_pShaderAPI->GetWorldSpaceCameraPosition( eyePos ); + s_pShaderAPI->SetPixelShaderConstant( 8, eyePos, 1 ); + pShaderAPI->SetPixelShaderFogParams( 11 ); + + + + if( bHasFlowmap ) + { + float curTime = pShaderAPI->CurrentTime(); + float timeVec[4] = { curTime, curTime, curTime, curTime }; + pShaderAPI->SetPixelShaderConstant( 6, timeVec, 1 ); + + SetPixelShaderConstant( 7, FLOWMAPSCROLLRATE ); + + SetPixelShaderConstant( 9, FLOWMAPTEXCOORDOFFSET ); + } + } + Draw(); + } + + SHADER_DRAW + { + DrawPass( params, pShaderShadow, pShaderAPI, 0, vertexCompression ); + DrawPass( params, pShaderShadow, pShaderAPI, 1, vertexCompression ); + } +END_SHADER + diff --git a/materialsystem/stdshaders/core_ps11.psh b/materialsystem/stdshaders/core_ps11.psh new file mode 100644 index 0000000..ba738bd --- /dev/null +++ b/materialsystem/stdshaders/core_ps11.psh @@ -0,0 +1,27 @@ +ps.1.1 + +; t0: +; texture: dudv map +; texcoords: dudvmap texcoords +; t1: +; texture: refraction render target +; texcoords: + +#if 1 + +tex t0 ; sample dudv map +texbem t1, t0 ; refraction +tex t2 + +mov r0, t1 +mul r0.rgb, r0, c0 +lrp r0.rgb, t2.a, t2, r0 +;mov r0, t2 + +#else + +texcoord t0 + +mov r0.rgba, t0 + +#endif diff --git a/materialsystem/stdshaders/core_ps2x.fxc b/materialsystem/stdshaders/core_ps2x.fxc new file mode 100644 index 0000000..9591aa8 --- /dev/null +++ b/materialsystem/stdshaders/core_ps2x.fxc @@ -0,0 +1,218 @@ +//====== Copyright © 1996-2005, Valve Corporation, All rights reserved. ======= +// +// Purpose: +// +//============================================================================= + +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX] +// STATIC: "CUBEMAP" "0..1" +// STATIC: "FLOWMAP" "0..1" +// STATIC: "CORECOLORTEXTURE" "0..1" +// STATIC: "REFRACT" "0..1" +// DYNAMIC: "PIXELFOGTYPE" "0..1" + +// SKIP: ( $REFRACT || $CORECOLORTEXTURE ) && $CUBEMAP + +#include "common_ps_fxc.h" + +sampler RefractSampler : register( s2 ); +sampler NormalSampler : register( s3 ); +#if CUBEMAP +sampler EnvmapSampler : register( s4 ); +#endif +#if FLOWMAP +sampler FlowmapSampler : register( s6 ); +#endif + +#if CORECOLORTEXTURE +sampler CoreColorSampler : register( s7 ); +#endif + +const HALF3 g_EnvmapTint : register( c0 ); +const HALF3 g_RefractTint : register( c1 ); +const HALF3 g_EnvmapContrast : register( c2 ); +const HALF3 g_EnvmapSaturation : register( c3 ); +const HALF2 g_RefractScale : register( c5 ); +#if FLOWMAP +const float g_Time : register( c6 ); +const float2 g_FlowScrollRate : register( c7 ); +//const float3 g_SphereCenter : register( c9 ); +//const float3 g_SphereRadius : register( c10 ); +const float g_CoreColorTexCoordOffset : register( c9 ); +#endif + +const float3 g_EyePos : register( c8 ); +const float4 g_FogParams : register( c11 ); + +float LengthThroughSphere( float3 vecRayOrigin, float3 vecRayDelta, + float3 vecSphereCenter, float flRadius, out float alpha ) +{ + // Solve using the ray equation + the sphere equation + // P = o + dt + // (x - xc)^2 + (y - yc)^2 + (z - zc)^2 = r^2 + // (ox + dx * t - xc)^2 + (oy + dy * t - yc)^2 + (oz + dz * t - zc)^2 = r^2 + // (ox - xc)^2 + 2 * (ox-xc) * dx * t + dx^2 * t^2 + + // (oy - yc)^2 + 2 * (oy-yc) * dy * t + dy^2 * t^2 + + // (oz - zc)^2 + 2 * (oz-zc) * dz * t + dz^2 * t^2 = r^2 + // (dx^2 + dy^2 + dz^2) * t^2 + 2 * ((ox-xc)dx + (oy-yc)dy + (oz-zc)dz) t + + // (ox-xc)^2 + (oy-yc)^2 + (oz-zc)^2 - r^2 = 0 + // or, t = (-b +/- sqrt( b^2 - 4ac)) / 2a + // a = DotProduct( vecRayDelta, vecRayDelta ); + // b = 2 * DotProduct( vecRayOrigin - vecCenter, vecRayDelta ) + // c = DotProduct(vecRayOrigin - vecCenter, vecRayOrigin - vecCenter) - flRadius * flRadius; + + float3 vecSphereToRay; + vecSphereToRay = vecRayOrigin - vecSphereCenter; + + float a = dot( vecRayDelta, vecRayDelta ); + + // This would occur in the case of a zero-length ray + // if ( a == 0.0f ) + // { + // *pT1 = *pT2 = 0.0f; + // return vecSphereToRay.LengthSqr() <= flRadius * flRadius; + // } + + float b = 2 * dot( vecSphereToRay, vecRayDelta ); + float c = dot( vecSphereToRay, vecSphereToRay ) - flRadius * flRadius; + float flDiscrim = b * b - 4 * a * c; + // if ( flDiscrim < 0.0f ) + // return 0.0f; + + float hack = flDiscrim; + flDiscrim = sqrt( flDiscrim ); + float oo2a = 0.5f / a; + + + //if( hack < 0.0f ) + //{ + // alpha = 0.0f; + // return 0.0f; + //} + //else + //{ + // alpha = 1.0f; + // return abs( flDiscrim ) * 2 * oo2a; + //} + + //replacing the if's above because if's in hlsl are bad..... + float fHackGreaterThanZero = step( 0.0f, hack ); + alpha = fHackGreaterThanZero; + return (fHackGreaterThanZero * (abs( flDiscrim ) * 2 * oo2a)); + + + // *pT1 = ( - b - flDiscrim ) * oo2a; + // *pT2 = ( - b + flDiscrim ) * oo2a; + // return true; +} + + +struct PS_INPUT +{ + float2 vBumpTexCoord : TEXCOORD0; // dudvMapAndNormalMapTexCoord + HALF3 vWorldVertToEyeVector : TEXCOORD1; + HALF3x3 tangentSpaceTranspose : TEXCOORD2; + float3 vRefractXYW : TEXCOORD5; + float3 projNormal : TEXCOORD6; + float4 worldPos_projPosZ : TEXCOORD7; +}; + +float4 main( PS_INPUT i ) : COLOR +{ + HALF3 result = 0.0f; + + HALF blend = 1.0f; + +#if FLOWMAP + // hack + float3 g_SphereCenter = { 2688.0f, 12139.0f, 5170.0f }; + float g_SphereDiameter = 430.0f; + float g_SphereRadius = g_SphereDiameter * 0.5f; + + float3 tmp = i.worldPos_projPosZ.xyz - g_SphereCenter; + float hackRadius = 1.05f * sqrt( dot( tmp, tmp ) ); + + float sphereAlpha; + float lengthThroughSphere = LengthThroughSphere( g_EyePos, normalize( i.worldPos_projPosZ.xyz - g_EyePos ), + g_SphereCenter, /*g_SphereRadius*/ hackRadius, sphereAlpha ); + + float normalizedLengthThroughSphere = lengthThroughSphere / g_SphereDiameter; + + + float3 hackWorldSpaceNormal = normalize( i.worldPos_projPosZ.xyz - g_SphereCenter ); + float3 realFuckingNormal = abs( hackWorldSpaceNormal ); + hackWorldSpaceNormal = 0.5f * ( hackWorldSpaceNormal + 1.0f ); + + // hackWorldSpaceNormal = abs( hackWorldSpaceNormal ); + + // return float4( hackWorldSpaceNormal.x, 0.0f, 0.0f, 1.0f ); + + i.vBumpTexCoord.xy = 0.0f; + i.vBumpTexCoord.xy = realFuckingNormal.z * tex2D( FlowmapSampler, hackWorldSpaceNormal.xy ); + i.vBumpTexCoord.xy += realFuckingNormal.y * tex2D( FlowmapSampler, hackWorldSpaceNormal.xz ); + i.vBumpTexCoord.xy += realFuckingNormal.x * tex2D( FlowmapSampler, hackWorldSpaceNormal.yz ); + i.vBumpTexCoord.xy += g_Time * g_FlowScrollRate; + // return float4( i.vBumpTexCoord.xy, 0.0f, 0.0f ); +#endif + + // Load normal and expand range + HALF4 vNormalSample = tex2D( NormalSampler, i.vBumpTexCoord ); + // return vNormalSample; + HALF3 tangentSpaceNormal = vNormalSample * 2.0 - 1.0; + + HALF3 refractTintColor = g_RefractTint; + + // Perform division by W only once + float ooW = 1.0f / i.vRefractXYW.z; + + // Compute coordinates for sampling refraction + float2 vRefractTexCoordNoWarp = i.vRefractXYW.xy * ooW; + float2 vRefractTexCoord = tangentSpaceNormal.xy; + HALF scale = vNormalSample.a * g_RefractScale.x; +#if FLOWMAP + scale *= normalizedLengthThroughSphere; +#endif + vRefractTexCoord *= scale; +#if FLOWMAP + float2 hackOffset = vRefractTexCoord; +#endif + vRefractTexCoord += vRefractTexCoordNoWarp; + + float3 colorWarp = tex2D( RefractSampler, vRefractTexCoord.xy ); + float3 colorNoWarp = tex2D( RefractSampler, vRefractTexCoordNoWarp.xy ); + + colorWarp *= refractTintColor; +#if REFRACT + result = lerp( colorNoWarp, colorWarp, blend ); + // return float4( 1.0f, 0.0f, 0.0f, 1.0f ); +#endif + +#if CUBEMAP + HALF specularFactor = vNormalSample.a; + + HALF3 worldSpaceNormal = mul( i.tangentSpaceTranspose, tangentSpaceNormal ); + + HALF3 reflectVect = CalcReflectionVectorUnnormalized( worldSpaceNormal, i.vWorldVertToEyeVector ); + HALF3 specularLighting = texCUBE( EnvmapSampler, reflectVect ); + specularLighting *= specularFactor; + specularLighting *= g_EnvmapTint; + HALF3 specularLightingSquared = specularLighting * specularLighting; + specularLighting = lerp( specularLighting, specularLightingSquared, g_EnvmapContrast ); + HALF3 greyScale = dot( specularLighting, HALF3( 0.299f, 0.587f, 0.114f ) ); + specularLighting = lerp( greyScale, specularLighting, g_EnvmapSaturation ); + result += specularLighting; +#endif + +#if CORECOLORTEXTURE && FLOWMAP + float4 coreColorTexel = tex2D( CoreColorSampler, hackOffset + float2( normalizedLengthThroughSphere, g_CoreColorTexCoordOffset ) ); + HALF4 rgba = HALF4( lerp( result, coreColorTexel, coreColorTexel.a /*normalizedLengthThroughSphere*/ ), sphereAlpha ); +#else + HALF4 rgba = HALF4( result, vNormalSample.a ); +#endif + + + float fogFactor = CalcPixelFogFactor( PIXELFOGTYPE, g_FogParams, g_EyePos.z, i.worldPos_projPosZ.z, i.worldPos_projPosZ.w ); + return FinalOutput( rgba, fogFactor, PIXELFOGTYPE, TONEMAP_SCALE_NONE ); +} + diff --git a/materialsystem/stdshaders/core_vs11.fxc b/materialsystem/stdshaders/core_vs11.fxc new file mode 100644 index 0000000..3db7a15 --- /dev/null +++ b/materialsystem/stdshaders/core_vs11.fxc @@ -0,0 +1,156 @@ +// DYNAMIC: "SKINNING" "0..1" + +#include "common_vs_fxc.h" + +static const bool g_bSkinning = SKINNING ? true : false; + +const float4 cBumpTexCoordTransform[2] : register( SHADER_SPECIFIC_CONST_1 ); +const float g_CoreColorTexCoordOffset : register( SHADER_SPECIFIC_CONST_3 ); + +struct VS_INPUT +{ + float4 vPos : POSITION; + float4 vBoneWeights : BLENDWEIGHT; + float4 vBoneIndices : BLENDINDICES; + float3 vNormal : NORMAL; + float4 vBaseTexCoord : TEXCOORD0; + float4 vUserData : TANGENT; +}; + +struct VS_OUTPUT +{ + float4 vProjPos : POSITION; + float vFog : FOG; + + float4 oT0 : TEXCOORD0; + float4 oT1 : TEXCOORD1; + float4 oT2 : TEXCOORD2; +// float3 oT3 : TEXCOORD3; + + float4 fogFactorW : COLOR1; +}; + +float LengthThroughSphere( float3 vecRayOrigin, float3 vecRayDelta, + float3 vecSphereCenter, float flRadius, out float alpha ) +{ + // Solve using the ray equation + the sphere equation + // P = o + dt + // (x - xc)^2 + (y - yc)^2 + (z - zc)^2 = r^2 + // (ox + dx * t - xc)^2 + (oy + dy * t - yc)^2 + (oz + dz * t - zc)^2 = r^2 + // (ox - xc)^2 + 2 * (ox-xc) * dx * t + dx^2 * t^2 + + // (oy - yc)^2 + 2 * (oy-yc) * dy * t + dy^2 * t^2 + + // (oz - zc)^2 + 2 * (oz-zc) * dz * t + dz^2 * t^2 = r^2 + // (dx^2 + dy^2 + dz^2) * t^2 + 2 * ((ox-xc)dx + (oy-yc)dy + (oz-zc)dz) t + + // (ox-xc)^2 + (oy-yc)^2 + (oz-zc)^2 - r^2 = 0 + // or, t = (-b +/- sqrt( b^2 - 4ac)) / 2a + // a = DotProduct( vecRayDelta, vecRayDelta ); + // b = 2 * DotProduct( vecRayOrigin - vecCenter, vecRayDelta ) + // c = DotProduct(vecRayOrigin - vecCenter, vecRayOrigin - vecCenter) - flRadius * flRadius; + + float3 vecSphereToRay; + vecSphereToRay = vecRayOrigin - vecSphereCenter; + + float a = dot( vecRayDelta, vecRayDelta ); + + // This would occur in the case of a zero-length ray +// if ( a == 0.0f ) +// { +// *pT1 = *pT2 = 0.0f; +// return vecSphereToRay.LengthSqr() <= flRadius * flRadius; +// } + + float b = 2 * dot( vecSphereToRay, vecRayDelta ); + float c = dot( vecSphereToRay, vecSphereToRay ) - flRadius * flRadius; + float flDiscrim = b * b - 4 * a * c; +// if ( flDiscrim < 0.0f ) +// return 0.0f; + + float hack = flDiscrim; + flDiscrim = sqrt( flDiscrim ); + float oo2a = 0.5f / a; + if( hack < 0.0f ) + { + alpha = 0.0f; + return 0.0f; + } + else + { + alpha = 1.0f; + return abs( flDiscrim ) * 2 * oo2a; + } +// *pT1 = ( - b - flDiscrim ) * oo2a; +// *pT2 = ( - b + flDiscrim ) * oo2a; +// return true; +} + +VS_OUTPUT main( const VS_INPUT v ) +{ + VS_OUTPUT o = ( VS_OUTPUT )0; + + float4 projPos; + float3 worldNormal, worldPos, worldTangentS, worldTangentT; + + SkinPositionNormalAndTangentSpace( + g_bSkinning, + v.vPos, v.vNormal, v.vUserData, + v.vBoneWeights, v.vBoneIndices, + worldPos, worldNormal, worldTangentS, worldTangentT ); + + // Projected position + o.vProjPos = projPos = mul( float4( worldPos, 1 ), cViewProj ); + + // calculate fog + o.fogFactorW = o.vFog = CalcFog( worldPos, projPos, FOGTYPE_RANGE ); + + // Eye vector + float3 vWorldEyeVect = cEyePos - worldPos; + + // Transform to the tangent space + o.oT1.x = dot( vWorldEyeVect, worldTangentS ); + o.oT1.y = dot( vWorldEyeVect, worldTangentT ); + o.oT1.z = dot( vWorldEyeVect, worldNormal ); + + // Tranform bump coordinates + float2 bumpTexCoord; + bumpTexCoord.x = dot( v.vBaseTexCoord, cBumpTexCoordTransform[0] ); + bumpTexCoord.y = dot( v.vBaseTexCoord, cBumpTexCoordTransform[1] ); + + // dudv map + o.oT0.xy = bumpTexCoord; + + // flip Y by multiplying by -1 + projPos.y *= -1.0f; + + // transform from [-w,w] to [0,2*w] + // The reason this is w is because we are in perspective space/homogenous clip space. + projPos.xy += projPos.w; + + // transform from [0,2*w] to [0,w] + // We'll end up dividing by w in the pixel shader to get to [0,1] + projPos.xy *= 0.5f; + + o.oT1.xy = projPos.xy; + + // emit w to both z and w in case the driver screws up and divides by z + o.oT1.z = o.oT1.w = projPos.w; + + // hack + float3 g_SphereCenter = { 2688.0f, 12139.0f, 5170.0f }; +// float g_SphereDiameter = 430.0f; + float g_SphereDiameter = 530.0f; + float g_SphereRadius = g_SphereDiameter * 0.5f; + + float dummyAlpha; + float lengthThroughSphere = LengthThroughSphere( cEyePos, normalize( vWorldEyeVect ), + g_SphereCenter, g_SphereRadius, dummyAlpha ); + + float normalizedLengthThroughSphere = saturate( lengthThroughSphere / g_SphereDiameter ); + o.oT2.xy = saturate( float2( normalizedLengthThroughSphere, g_CoreColorTexCoordOffset ) ); + + // hack texcoord shit +// o.oT0.xy = 3.0f * ( worldPos.xy - g_SphereCenter.xy ) / g_SphereRadius; + + return o; +} + + diff --git a/materialsystem/stdshaders/core_vs20.fxc b/materialsystem/stdshaders/core_vs20.fxc new file mode 100644 index 0000000..9b7c965 --- /dev/null +++ b/materialsystem/stdshaders/core_vs20.fxc @@ -0,0 +1,103 @@ +// STATIC: "MODEL" "0..1" + +// DYNAMIC: "COMPRESSED_VERTS" "0..1" +// DYNAMIC: "SKINNING" "0..1" + +#include "common_vs_fxc.h" + +static const bool g_bSkinning = SKINNING ? true : false; +static const bool g_bModel = MODEL ? true : false; + +const float4 cBumpTexCoordTransform[2] : register( SHADER_SPECIFIC_CONST_1 ); + +struct VS_INPUT +{ + float4 vPos : POSITION; + float4 vBoneWeights : BLENDWEIGHT; + float4 vBoneIndices : BLENDINDICES; + float4 vNormal : NORMAL; + float4 vBaseTexCoord : TEXCOORD0; +#if !MODEL + float3 vTangentS : TANGENT; + float3 vTangentT : BINORMAL0; +#else + float4 vUserData : TANGENT; +#endif +}; + +struct VS_OUTPUT +{ + float4 vProjPos_POSITION : POSITION; + float vFog : FOG; + float2 vBumpTexCoord : TEXCOORD0; + float3 vTangentEyeVect : TEXCOORD1; + float3x3 tangentSpaceTranspose : TEXCOORD2; + float3 vRefractXYW : TEXCOORD5; + float4 projNormal_screenCoordW : TEXCOORD6; + float4 worldPos_projPosZ : TEXCOORD7; + float4 fogFactorW : COLOR1; +}; + +VS_OUTPUT main( const VS_INPUT v ) +{ + VS_OUTPUT o = ( VS_OUTPUT )0; + + float3 worldNormal, worldPos, worldTangentS, worldTangentT; + + float3 vObjNormal; +#if MODEL + float4 vObjTangent; + DecompressVertex_NormalTangent( v.vNormal, v.vUserData, vObjNormal, vObjTangent ); + + SkinPositionNormalAndTangentSpace( + g_bSkinning, + v.vPos, vObjNormal, vObjTangent, + v.vBoneWeights, v.vBoneIndices, + worldPos, worldNormal, worldTangentS, worldTangentT ); +#else + DecompressVertex_Normal( v.vNormal, vObjNormal ); + + worldPos = mul( v.vPos, cModel[0] ); + worldTangentS = mul( v.vTangentS, ( const float3x3 )cModel[0] ); + worldTangentT = mul( v.vTangentT, ( const float3x3 )cModel[0] ); + worldNormal = mul( vObjNormal, ( float3x3 )cModel[0] ); +#endif + + + // Projected position + float4 vProjPos = mul( float4( worldPos, 1 ), cViewProj ); + o.vProjPos_POSITION = vProjPos; + o.projNormal_screenCoordW.xyz = mul( worldNormal, cViewProj ); + + o.worldPos_projPosZ = float4( worldPos.xyz, vProjPos.z ); + + // Map projected position to the refraction texture + float2 vRefractPos; + vRefractPos.x = vProjPos.x; + vRefractPos.y = -vProjPos.y; // invert Y + vRefractPos = (vRefractPos + vProjPos.w) * 0.5f; + + // Refraction transform + o.vRefractXYW = float3(vRefractPos.x, vRefractPos.y, vProjPos.w); + + // Compute fog based on the position + float3 vWorldPos = mul( v.vPos, cModel[0] ); + o.fogFactorW = o.vFog = CalcFog( vWorldPos, vProjPos, FOGTYPE_RANGE ); + + // Eye vector + float3 vWorldEyeVect = cEyePos - vWorldPos; + // Transform to the tangent space + o.vTangentEyeVect.x = dot( vWorldEyeVect, worldTangentS ); + o.vTangentEyeVect.y = dot( vWorldEyeVect, worldTangentT ); + o.vTangentEyeVect.z = dot( vWorldEyeVect, worldNormal ); + + // Tranform bump coordinates + o.vBumpTexCoord.x = dot( v.vBaseTexCoord, cBumpTexCoordTransform[0] ); + o.vBumpTexCoord.y = dot( v.vBaseTexCoord, cBumpTexCoordTransform[1] ); + + o.tangentSpaceTranspose[0] = worldTangentS; + o.tangentSpaceTranspose[1] = worldTangentT; + o.tangentSpaceTranspose[2] = worldNormal; + + return o; +} diff --git a/materialsystem/stdshaders/cpp_shader_constant_register_map.h b/materialsystem/stdshaders/cpp_shader_constant_register_map.h new file mode 100644 index 0000000..a89e8ea --- /dev/null +++ b/materialsystem/stdshaders/cpp_shader_constant_register_map.h @@ -0,0 +1,45 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: Provide convenient mapping for shader constants +// +// $NoKeywords: $ +//============================================================================= + +#define C_CODE_HACK +#include "shader_constant_register_map.h" +#undef C_CODE_HACK + +// For the C code, map the above file's defines back to integers... +#define PSREG_CONSTANT_00 0 +#define PSREG_CONSTANT_01 1 +#define PSREG_CONSTANT_02 2 +#define PSREG_CONSTANT_03 3 +#define PSREG_CONSTANT_04 4 +#define PSREG_CONSTANT_05 5 +#define PSREG_CONSTANT_06 6 +#define PSREG_CONSTANT_07 7 +#define PSREG_CONSTANT_08 8 +#define PSREG_CONSTANT_09 9 +#define PSREG_CONSTANT_10 10 +#define PSREG_CONSTANT_11 11 +#define PSREG_CONSTANT_12 12 +#define PSREG_CONSTANT_13 13 +#define PSREG_CONSTANT_14 14 +#define PSREG_CONSTANT_15 15 +#define PSREG_CONSTANT_16 16 +#define PSREG_CONSTANT_17 17 +#define PSREG_CONSTANT_18 18 +#define PSREG_CONSTANT_19 19 +#define PSREG_CONSTANT_20 20 +#define PSREG_CONSTANT_21 21 +#define PSREG_CONSTANT_22 22 +#define PSREG_CONSTANT_23 23 +#define PSREG_CONSTANT_24 24 +#define PSREG_CONSTANT_25 25 +#define PSREG_CONSTANT_26 26 +#define PSREG_CONSTANT_27 27 +#define PSREG_CONSTANT_28 28 +#define PSREG_CONSTANT_29 29 +#define PSREG_CONSTANT_30 30 +#define PSREG_CONSTANT_31 31 + diff --git a/materialsystem/stdshaders/debugdepth.cpp b/materialsystem/stdshaders/debugdepth.cpp new file mode 100644 index 0000000..65e55e0 --- /dev/null +++ b/materialsystem/stdshaders/debugdepth.cpp @@ -0,0 +1,113 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $Header: $ +// $NoKeywords: $ +//===========================================================================// + +#include "shaderlib/cshader.h" +#include "convar.h" +#include "debugdrawdepth_vs20.inc" +#include "debugdrawdepth_ps20.inc" +#include "debugdrawdepth_ps20b.inc" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +static ConVar mat_debugdepthmode( "mat_debugdepthmode", "0" ); +static ConVar mat_debugdepthval( "mat_debugdepthval", "128.0f" ); +static ConVar mat_debugdepthvalmax( "mat_debugdepthvalmax", "256.0f" ); + +BEGIN_SHADER_FLAGS( DebugDepth, "Help for DebugDepth", SHADER_NOT_EDITABLE ) + BEGIN_SHADER_PARAMS + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + SET_FLAGS2( MATERIAL_VAR2_SUPPORTS_HW_SKINNING ); + } + + SHADER_INIT + { + } + + SHADER_FALLBACK + { + if( g_pHardwareConfig->GetDXSupportLevel() < 90 ) + { +// Assert( 0 ); + return "WireFrame"; + } + return 0; + } + + SHADER_DRAW + { + SHADOW_STATE + { + // Set stream format (note that this shader supports compression) + unsigned int flags = VERTEX_POSITION | VERTEX_FORMAT_COMPRESSED; + int nTexCoordCount = 1; + int userDataSize = 0; + pShaderShadow->VertexShaderVertexFormat( flags, nTexCoordCount, NULL, userDataSize ); + + DECLARE_STATIC_VERTEX_SHADER( debugdrawdepth_vs20 ); + SET_STATIC_VERTEX_SHADER( debugdrawdepth_vs20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_STATIC_PIXEL_SHADER( debugdrawdepth_ps20b ); + SET_STATIC_PIXEL_SHADER( debugdrawdepth_ps20b ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( debugdrawdepth_ps20 ); + SET_STATIC_PIXEL_SHADER( debugdrawdepth_ps20 ); + } + } + DYNAMIC_STATE + { + DECLARE_DYNAMIC_VERTEX_SHADER( debugdrawdepth_vs20 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, s_pShaderAPI->GetCurrentNumBones() > 0 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression ); + SET_DYNAMIC_VERTEX_SHADER( debugdrawdepth_vs20 ); + + Vector4D vecZFilter( 0, 0, 0, 1 ); + int nDepthMode = mat_debugdepthmode.GetInt(); + if ( nDepthMode > 1 ) + { + nDepthMode = 0; + } + + vecZFilter[nDepthMode] = 1; + s_pShaderAPI->SetPixelShaderConstant( 1, vecZFilter.Base() ); + + Vector4D vecModulationColor( 0, 0, 0, 1 ); + if ( IS_FLAG_SET( MATERIAL_VAR_DECAL ) ) + { + vecModulationColor[0] = 0; + vecModulationColor[1] = 1; + vecModulationColor[2] = 1; + } + else + { + vecModulationColor[0] = 1; + vecModulationColor[1] = 1; + vecModulationColor[2] = 1; + } + s_pShaderAPI->SetPixelShaderConstant( 2, vecModulationColor.Base() ); + + float flDepthFactor = mat_debugdepthval.GetFloat(); + float flDepthFactorMax = mat_debugdepthvalmax.GetFloat(); + if ( flDepthFactor == 0 ) + { + flDepthFactor = 1.0f; + } + Vector4D vecZFactor( (flDepthFactorMax - flDepthFactor), flDepthFactor, 1, 1 ); + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, vecZFactor.Base() ); + } + Draw(); + } +END_SHADER + diff --git a/materialsystem/stdshaders/debugluxel.cpp b/materialsystem/stdshaders/debugluxel.cpp new file mode 100644 index 0000000..328dfb6 --- /dev/null +++ b/materialsystem/stdshaders/debugluxel.cpp @@ -0,0 +1,97 @@ +//===== Copyright (c) 1996-2005, Valve Corporation, All rights reserved. ======// +// +// Purpose: +// +// $Header: $ +// $NoKeywords: $ +//===========================================================================// + +#include "shaderlib/CShader.h" + +#include "debugluxel_ps20b.inc" +#include "debugluxel_ps20.inc" +#include "debugluxel_vs20.inc" + + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +BEGIN_SHADER_FLAGS( DebugLuxels, "Help for DebugLuxels", SHADER_NOT_EDITABLE ) + + BEGIN_SHADER_PARAMS + SHADER_PARAM( NOSCALE, SHADER_PARAM_TYPE_BOOL, "0", "fixme" ) + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + SET_FLAGS( MATERIAL_VAR_NO_DEBUG_OVERRIDE ); + SET_FLAGS2( MATERIAL_VAR2_LIGHTING_LIGHTMAP ); + + if( g_pHardwareConfig->GetDXSupportLevel() >= 90 ) + { + SET_FLAGS2( MATERIAL_VAR2_SUPPORTS_HW_SKINNING ); + } + } + + SHADER_INIT + { + LoadTexture( BASETEXTURE ); + } + + SHADER_DRAW + { + SHADOW_STATE + { + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + + DECLARE_STATIC_VERTEX_SHADER( debugluxel_vs20 ); + SET_STATIC_VERTEX_SHADER( debugluxel_vs20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_STATIC_PIXEL_SHADER( debugluxel_ps20b ); + SET_STATIC_PIXEL_SHADER( debugluxel_ps20b ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( debugluxel_ps20 ); + SET_STATIC_PIXEL_SHADER( debugluxel_ps20 ); + } + + SetDefaultBlendingShadowState( BASETEXTURE ); + DisableFog(); + pShaderShadow->VertexShaderVertexFormat( VERTEX_POSITION, 2, NULL, 0 ); + } + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME ); + + int texCoordScaleX = 1, texCoordScaleY = 1; + if (!params[NOSCALE]->GetIntValue()) + { + pShaderAPI->GetLightmapDimensions( &texCoordScaleX, &texCoordScaleY ); + } + + DECLARE_DYNAMIC_VERTEX_SHADER( debugluxel_vs20 ); + SET_DYNAMIC_VERTEX_SHADER( debugluxel_vs20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_DYNAMIC_PIXEL_SHADER( debugluxel_ps20b ); + SET_DYNAMIC_PIXEL_SHADER( debugluxel_ps20b ); + } + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( debugluxel_ps20 ); + SET_DYNAMIC_PIXEL_SHADER( debugluxel_ps20 ); + } + + //texture scale transform + Vector4D transformation[2]; + transformation[0].Init( texCoordScaleX, 0.0f, 0.0f, 0.0f ); + transformation[1].Init( 0.0f, texCoordScaleY, 0.0f, 0.0f ); + s_pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, transformation[0].Base(), 2 ); + } + Draw(); + } +END_SHADER diff --git a/materialsystem/stdshaders/debugluxel_ps2x.fxc b/materialsystem/stdshaders/debugluxel_ps2x.fxc new file mode 100644 index 0000000..81c8ae0 --- /dev/null +++ b/materialsystem/stdshaders/debugluxel_ps2x.fxc @@ -0,0 +1,15 @@ +#include "common_ps_fxc.h" + +sampler TextureSampler : register( s0 ); + +struct PS_INPUT +{ + float2 baseTexCoord : TEXCOORD0; +}; + +float4 main( PS_INPUT i ) : COLOR +{ + float4 result = tex2D( TextureSampler, i.baseTexCoord ); + return FinalOutput( result, 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE ); +} + diff --git a/materialsystem/stdshaders/debugluxel_vs20.fxc b/materialsystem/stdshaders/debugluxel_vs20.fxc new file mode 100644 index 0000000..3edee90 --- /dev/null +++ b/materialsystem/stdshaders/debugluxel_vs20.fxc @@ -0,0 +1,40 @@ +#include "common_vs_fxc.h" + +const float4 cLightmapTexCoordTransform[2] : register( SHADER_SPECIFIC_CONST_0 ); + +struct VS_INPUT +{ + float3 vPos : POSITION; + float2 vBaseTexCoord : TEXCOORD0; + float2 vLightmapTexCoord : TEXCOORD1; +}; + +struct VS_OUTPUT +{ + float4 projPos : POSITION; + float2 baseTexCoord : TEXCOORD0; +}; + + +VS_OUTPUT main( const VS_INPUT v ) +{ + VS_OUTPUT o = ( VS_OUTPUT )0; + + float4 projPos; + float3 worldPos; + + worldPos = mul4x3( float4( v.vPos, 1 ), cModel[0] ); + projPos = mul( float4( worldPos, 1 ), cViewProj ); + o.projPos = projPos; + + o.baseTexCoord.x = dot( v.vLightmapTexCoord, cLightmapTexCoordTransform[0].xy ) + cLightmapTexCoordTransform[0].w; + o.baseTexCoord.y = dot( v.vLightmapTexCoord, cLightmapTexCoordTransform[1].xy ) + cLightmapTexCoordTransform[1].w; + +#ifdef _PS3 + // Account for OpenGL's flipped y coordinate and expanded z range [-1,1] instead of [0,1] + o.projPos.y = -o.projPos.y; + o.projPos.z = 2.0f * o.projPos.z - o.projPos.w; +#endif // _PS3 + + return o; +} diff --git a/materialsystem/stdshaders/debugmodifyvertex.cpp b/materialsystem/stdshaders/debugmodifyvertex.cpp new file mode 100644 index 0000000..c497ca9 --- /dev/null +++ b/materialsystem/stdshaders/debugmodifyvertex.cpp @@ -0,0 +1,93 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: This is an example of a material that modifies vertex data +// in the shader. NOTE: Every pass is given a clean set of vertex data. +// Modifications made in the first pass are *not* carried over to the next pass +// Modifications must take place during the DYNAMIC_STATE block. +// Use the function MeshBuilder() to build the mesh +// +// Also note: Using thie feature is *really expensive*! It makes a copy of +// the vertex data *per pass!* If you wish to modify vertex data to be used +// with all passes, your best bet is to construct a dynamic mesh instead. +// +// $Header: $ +// $NoKeywords: $ +//===========================================================================// + +#include "shaderlib/cshader.h" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +BEGIN_SHADER_FLAGS( DebugModifyVertex, "Help for DebugModifyVertex", SHADER_NOT_EDITABLE ) + BEGIN_SHADER_PARAMS + SHADER_PARAM( WAVE, SHADER_PARAM_TYPE_FLOAT, "1.0", "wave amplitude" ) + END_SHADER_PARAMS + + SHADER_INIT + { + LoadTexture( BASETEXTURE ); + } + + SHADER_DRAW + { + if( g_pHardwareConfig->GetSamplerCount() >= 2 ) + { + // lightmap + SHADOW_STATE + { + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableVertexDataPreprocess( true ); + pShaderShadow->DrawFlags( SHADER_DRAW_POSITION | SHADER_DRAW_TEXCOORD0 ); + FogToFogColor(); + } + + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME ); + + float amp = params[WAVE]->GetFloatValue(); + float currTime = pShaderAPI->CurrentTime(); + for (int i = 0; i < MeshBuilder()->NumVertices(); ++i) + { + float const* pPos = MeshBuilder()->Position(); + MeshBuilder()->Position3f( pPos[0] + amp * sin( currTime + pPos[2] / 4 ), + pPos[1] + amp * sin( currTime + pPos[2] / 4 + 2 * 3.14 / 3 ), + pPos[2] + amp * sin( currTime + pPos[2] / 4 + 4 * 3.14 / 3 ) ); + MeshBuilder()->AdvanceVertex(); + } + } + Draw(); + + // base * vertex color + SHADOW_STATE + { + pShaderShadow->DrawFlags( SHADER_DRAW_POSITION | SHADER_DRAW_COLOR | + SHADER_DRAW_TEXCOORD0 ); + FogToFogColor(); + } + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME ); + + // Notice here that since we didn't modify the position, and this is a second + // pass, the position has been reset to it's initial, unmodified position + float currTime = pShaderAPI->CurrentTime(); + for (int i = 0; i < MeshBuilder()->NumVertices(); ++i) + { + float const* pPos = MeshBuilder()->Position(); + MeshBuilder()->Color3f( ( sin( currTime + pPos[0] ) + 1.0F) * 0.5, + ( sin( currTime + pPos[1] ) + 1.0F) * 0.5, + ( sin( currTime + pPos[2] ) + 1.0F) * 0.5 ); + MeshBuilder()->AdvanceVertex(); + } + } + Draw(); + } + else + { + ShaderWarning( "DebugModifyVertex: not " + "implemented for single-texturing hardware\n" ); + } + } +END_SHADER diff --git a/materialsystem/stdshaders/debugmorphaccumulator_dx9.cpp b/materialsystem/stdshaders/debugmorphaccumulator_dx9.cpp new file mode 100644 index 0000000..2f5c6a8 --- /dev/null +++ b/materialsystem/stdshaders/debugmorphaccumulator_dx9.cpp @@ -0,0 +1,64 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $Header: $ +// $NoKeywords: $ +//===========================================================================// + +#include "BaseVSShader.h" + +#include "debugmorphaccumulator_ps30.inc" +#include "debugmorphaccumulator_vs30.inc" + +BEGIN_VS_SHADER_FLAGS( DebugMorphAccumulator, "Help for Debug Morph Accumulator", SHADER_NOT_EDITABLE ) + + BEGIN_SHADER_PARAMS + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + } + + SHADER_FALLBACK + { + return 0; + } + + SHADER_INIT + { + LoadTexture( BASETEXTURE ); + } + + SHADER_DRAW + { + SHADOW_STATE + { + pShaderShadow->EnableDepthTest( false ); + pShaderShadow->EnableDepthWrites( false ); + pShaderShadow->EnableCulling( false ); + pShaderShadow->FogMode( SHADER_FOGMODE_DISABLED ); + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableSRGBWrite( false ); + + pShaderShadow->VertexShaderVertexFormat( VERTEX_POSITION, 1, 0, 0 ); + + DECLARE_STATIC_VERTEX_SHADER( debugmorphaccumulator_vs30 ); + SET_STATIC_VERTEX_SHADER( debugmorphaccumulator_vs30 ); + + DECLARE_STATIC_PIXEL_SHADER( debugmorphaccumulator_ps30 ); + SET_STATIC_PIXEL_SHADER( debugmorphaccumulator_ps30 ); + } + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER0, BASETEXTURE ); + + DECLARE_DYNAMIC_VERTEX_SHADER( debugmorphaccumulator_vs30 ); + SET_DYNAMIC_VERTEX_SHADER( debugmorphaccumulator_vs30 ); + + DECLARE_DYNAMIC_PIXEL_SHADER( debugmorphaccumulator_ps30 ); + SET_DYNAMIC_PIXEL_SHADER( debugmorphaccumulator_ps30 ); + } + Draw( ); + } +END_SHADER diff --git a/materialsystem/stdshaders/debugmorphaccumulator_ps30.fxc b/materialsystem/stdshaders/debugmorphaccumulator_ps30.fxc new file mode 100644 index 0000000..b479085 --- /dev/null +++ b/materialsystem/stdshaders/debugmorphaccumulator_ps30.fxc @@ -0,0 +1,16 @@ +#define HDRTYPE HDR_TYPE_NONE +#include "common_ps_fxc.h" + +struct PS_INPUT +{ + float2 vTexCoord : TEXCOORD0; +}; + +sampler MorphAccumulator : register( s0 ); + +HALF4 main( PS_INPUT i ) : COLOR +{ + float4 vDeltas = tex2D( MorphAccumulator, i.vTexCoord ); + return float4( abs( vDeltas.x ), abs( vDeltas.z ), abs( vDeltas.y ) + abs( vDeltas.w ), 1.0f ); +} + diff --git a/materialsystem/stdshaders/debugmorphaccumulator_vs30.fxc b/materialsystem/stdshaders/debugmorphaccumulator_vs30.fxc new file mode 100644 index 0000000..4ff8a74 --- /dev/null +++ b/materialsystem/stdshaders/debugmorphaccumulator_vs30.fxc @@ -0,0 +1,23 @@ +#include "common_vs_fxc.h" + +struct VS_INPUT +{ + float4 vPos : POSITION; + float2 vTexCoord : TEXCOORD0; +}; + +struct VS_OUTPUT +{ + float4 vProjPos : POSITION; + float2 vTexCoord : TEXCOORD0; +}; + +VS_OUTPUT main( const VS_INPUT v ) +{ + VS_OUTPUT o = ( VS_OUTPUT )0; + + o.vProjPos = mul( v.vPos, cModelViewProj ); + o.vTexCoord = v.vTexCoord; + + return o; +} \ No newline at end of file diff --git a/materialsystem/stdshaders/debugmrttexture.cpp b/materialsystem/stdshaders/debugmrttexture.cpp new file mode 100644 index 0000000..04a1128 --- /dev/null +++ b/materialsystem/stdshaders/debugmrttexture.cpp @@ -0,0 +1,86 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $Header: $ +// $NoKeywords: $ +//===========================================================================// + +#include "BaseVSShader.h" + +#include "debugmrttexture_ps20.inc" +#include "debugmrttexture_ps20b.inc" +#include "debugmrttexture_vs20.inc" + +BEGIN_VS_SHADER_FLAGS( DebugMRTTexture, "Help for DebugMRTTexture", SHADER_NOT_EDITABLE ) + + BEGIN_SHADER_PARAMS + SHADER_PARAM( MRTINDEX, SHADER_PARAM_TYPE_INTEGER, "", "" ) + END_SHADER_PARAMS + + SHADER_FALLBACK + { +// if( g_pHardwareConfig->GetDXSupportLevel() < 90 ) +// { +// return "UnlitGeneric_DX8"; +// } + return 0; + } + + SHADER_INIT_PARAMS() + { + } + + SHADER_INIT + { + LoadTexture( BASETEXTURE ); + } + + SHADER_DRAW + { + SHADOW_STATE + { + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + + DECLARE_STATIC_VERTEX_SHADER( debugmrttexture_vs20 ); + SET_STATIC_VERTEX_SHADER( debugmrttexture_vs20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_STATIC_PIXEL_SHADER( debugmrttexture_ps20b ); + SET_STATIC_PIXEL_SHADER_COMBO( MRTINDEX, params[MRTINDEX]->GetIntValue() ); + SET_STATIC_PIXEL_SHADER( debugmrttexture_ps20b ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( debugmrttexture_ps20 ); + SET_STATIC_PIXEL_SHADER_COMBO( MRTINDEX, params[MRTINDEX]->GetIntValue() ); + SET_STATIC_PIXEL_SHADER( debugmrttexture_ps20 ); + } + + int numTexCoords = 2; + pShaderShadow->VertexShaderVertexFormat( VERTEX_POSITION, numTexCoords, 0, 0 ); + } + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME ); + + DECLARE_DYNAMIC_VERTEX_SHADER( debugmrttexture_vs20 ); + SET_DYNAMIC_VERTEX_SHADER( debugmrttexture_vs20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_DYNAMIC_PIXEL_SHADER( debugmrttexture_ps20b ); + SET_DYNAMIC_PIXEL_SHADER( debugmrttexture_ps20b ); + } + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( debugmrttexture_ps20 ); + SET_DYNAMIC_PIXEL_SHADER( debugmrttexture_ps20 ); + } + } + Draw(); + } +END_SHADER + diff --git a/materialsystem/stdshaders/debugmrttexture_ps2x.fxc b/materialsystem/stdshaders/debugmrttexture_ps2x.fxc new file mode 100644 index 0000000..7764e52 --- /dev/null +++ b/materialsystem/stdshaders/debugmrttexture_ps2x.fxc @@ -0,0 +1,26 @@ +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX] +// STATIC: "MRTINDEX" "0..1" + +#define HDRTYPE HDR_TYPE_NONE +#include "common_ps_fxc.h" + +struct PS_INPUT +{ + float2 baseTexCoord : TEXCOORD0; +}; + +sampler BaseTextureSampler1 : register( s0 ); +sampler BaseTextureSampler2 : register( s1 ); + +float4 main( PS_INPUT i ) : COLOR +{ +#if MRTINDEX == 0 + float4 result = tex2D( BaseTextureSampler1, i.baseTexCoord ); +#else + float4 result = tex2D( BaseTextureSampler2, i.baseTexCoord ); +#endif + + return FinalOutput( result, 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE ); +} + diff --git a/materialsystem/stdshaders/debugmrttexture_vs20.fxc b/materialsystem/stdshaders/debugmrttexture_vs20.fxc new file mode 100644 index 0000000..db5c486 --- /dev/null +++ b/materialsystem/stdshaders/debugmrttexture_vs20.fxc @@ -0,0 +1,29 @@ +#include "common_vs_fxc.h" + +struct VS_INPUT +{ + float3 vPos : POSITION; + float2 vBaseTexCoord : TEXCOORD0; +}; + +struct VS_OUTPUT +{ + float4 projPos : POSITION; + float2 baseTexCoord : TEXCOORD0; +}; + +VS_OUTPUT main( const VS_INPUT v ) +{ + VS_OUTPUT o = ( VS_OUTPUT )0; + + float4 projPos; + float3 worldPos; + + projPos = mul( float4( v.vPos, 1 ), cModelViewProj ); + o.projPos = projPos; + + o.baseTexCoord = v.vBaseTexCoord; + return o; +} + + diff --git a/materialsystem/stdshaders/debugnormalmap.cpp b/materialsystem/stdshaders/debugnormalmap.cpp new file mode 100644 index 0000000..0be5246 --- /dev/null +++ b/materialsystem/stdshaders/debugnormalmap.cpp @@ -0,0 +1,148 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $Header: $ +// $NoKeywords: $ +//===========================================================================// + +#include "BaseVSShader.h" + +#define USE_NEW_SHADER //Updating assembly shaders to fxc, this is for A/B testing. + + + +#ifdef USE_NEW_SHADER + +#include "unlitgeneric_vs20.inc" +#include "unlitgeneric_ps20.inc" +#include "unlitgeneric_ps20b.inc" + +#endif + +#include "unlitgeneric_vs11.inc" + + + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +BEGIN_VS_SHADER_FLAGS( DebugNormalMap, "Help for DebugNormalMap", SHADER_NOT_EDITABLE ) + + BEGIN_SHADER_PARAMS + SHADER_PARAM( BUMPMAP, SHADER_PARAM_TYPE_TEXTURE, "shadertest/WorldDiffuseBumpMap_bump", "bump map" ) + SHADER_PARAM( BUMPFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $bumpmap" ) + SHADER_PARAM( BUMPTRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$bumpmap texcoord transform" ) + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + SET_FLAGS2( MATERIAL_VAR2_SUPPORTS_HW_SKINNING ); + } + + SHADER_INIT + { + } + + SHADER_FALLBACK + { + if( g_pHardwareConfig->GetDXSupportLevel() < 80 ) + { +// Assert( 0 ); + return "Wireframe"; + } + return 0; + } + + SHADER_DRAW + { + SHADOW_STATE + { + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + + // Set stream format (note that this shader supports compression) + unsigned int flags = VERTEX_POSITION | VERTEX_FORMAT_COMPRESSED; + int nTexCoordCount = 1; + int userDataSize = 0; + pShaderShadow->VertexShaderVertexFormat( flags, nTexCoordCount, NULL, userDataSize ); + +#ifdef USE_NEW_SHADER + if( g_pHardwareConfig->GetDXSupportLevel() >= 90 ) + { + DECLARE_STATIC_VERTEX_SHADER( unlitgeneric_vs20 ); + SET_STATIC_VERTEX_SHADER_COMBO( VERTEXCOLOR, 0 ); + SET_STATIC_VERTEX_SHADER( unlitgeneric_vs20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_STATIC_PIXEL_SHADER( unlitgeneric_ps20b ); + SET_STATIC_PIXEL_SHADER( unlitgeneric_ps20b ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( unlitgeneric_ps20 ); + SET_STATIC_PIXEL_SHADER( unlitgeneric_ps20 ); + } + } + else +#endif + { + unlitgeneric_vs11_Static_Index vshIndex; + vshIndex.SetDETAIL( false ); + vshIndex.SetENVMAP( false ); + vshIndex.SetENVMAPCAMERASPACE( false ); + vshIndex.SetENVMAPSPHERE( false ); + vshIndex.SetVERTEXCOLOR( false ); + vshIndex.SetSEPARATEDETAILUVS( false ); + pShaderShadow->SetVertexShader( "unlitgeneric_vs11", vshIndex.GetIndex() ); + + pShaderShadow->SetPixelShader( "unlitgeneric" ); + } + } + DYNAMIC_STATE + { + if ( params[BUMPMAP]->IsTexture() ) + { + BindTexture( SHADER_SAMPLER0, BUMPMAP, BUMPFRAME ); + } + else + { + pShaderAPI->BindStandardTexture( SHADER_SAMPLER0, TEXTURE_NORMALMAP_FLAT ); + } + SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, BUMPTRANSFORM ); +#ifdef USE_NEW_SHADER + if( g_pHardwareConfig->GetDXSupportLevel() >= 90 ) + { + float vVertexColor[4] = { 0, 0, 0, 0 }; + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_6, vVertexColor, 1 ); + + DECLARE_DYNAMIC_VERTEX_SHADER( unlitgeneric_vs20 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( DOWATERFOG, pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, pShaderAPI->GetCurrentNumBones() > 0 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression ); + SET_DYNAMIC_VERTEX_SHADER( unlitgeneric_vs20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_DYNAMIC_PIXEL_SHADER( unlitgeneric_ps20b ); + SET_DYNAMIC_PIXEL_SHADER( unlitgeneric_ps20b ); + } + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( unlitgeneric_ps20 ); + SET_DYNAMIC_PIXEL_SHADER( unlitgeneric_ps20 ); + } + } + else +#endif + { + unlitgeneric_vs11_Dynamic_Index vshIndex; + vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + vshIndex.SetSKINNING( pShaderAPI->GetCurrentNumBones() > 0 ); + pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() ); + } + } + Draw(); + } +END_SHADER + diff --git a/materialsystem/stdshaders/debugsoftwarevertexshader.cpp b/materialsystem/stdshaders/debugsoftwarevertexshader.cpp new file mode 100644 index 0000000..be7cedf --- /dev/null +++ b/materialsystem/stdshaders/debugsoftwarevertexshader.cpp @@ -0,0 +1,56 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//=============================================================================// + +#include "shaderlib/cshader.h" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +SOFTWARE_VERTEX_SHADER( myHappyLittleSoftwareVertexShader ) +{ + float t = pShaderAPI->CurrentTime(); + for( int i = 0; i < meshBuilder.NumVertices(); i++ ) + { + const float *pPos = meshBuilder.Position(); + meshBuilder.Position3f( pPos[0], pPos[1], pPos[2] + 10.0f * sin( t + pPos[0] ) ); + meshBuilder.AdvanceVertex(); + } +} + +FORWARD_DECLARE_SOFTWARE_VERTEX_SHADER( myHappyLittleSoftwareVertexShader ); + +BEGIN_SHADER_FLAGS( DebugSoftwareVertexShader, "blah", SHADER_NOT_EDITABLE ) + BEGIN_SHADER_PARAMS + SHADER_PARAM_OVERRIDE( BASETEXTURE, SHADER_PARAM_TYPE_TEXTURE, "shadertest/basetexture", "unused", SHADER_PARAM_NOT_EDITABLE ) + SHADER_PARAM_OVERRIDE( FRAME, SHADER_PARAM_TYPE_INTEGER, "0", "unused", SHADER_PARAM_NOT_EDITABLE ) + SHADER_PARAM_OVERRIDE( BASETEXTURETRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "unused", SHADER_PARAM_NOT_EDITABLE ) + SHADER_PARAM_OVERRIDE( COLOR, SHADER_PARAM_TYPE_COLOR, "{255 255 255}", "unused", SHADER_PARAM_NOT_EDITABLE ) + SHADER_PARAM_OVERRIDE( ALPHA, SHADER_PARAM_TYPE_FLOAT, "1.0", "unused", SHADER_PARAM_NOT_EDITABLE ) + END_SHADER_PARAMS + + SHADER_INIT + { + if( g_pHardwareConfig->SupportsVertexAndPixelShaders() ) + { + USE_SOFTWARE_VERTEX_SHADER( myHappyLittleSoftwareVertexShader ); + } + else + { + USE_SOFTWARE_VERTEX_SHADER( myHappyLittleSoftwareVertexShader ); + } + } + SHADER_DRAW + { + SHADOW_STATE + { + } + DYNAMIC_STATE + { + } + Draw(); + } +END_SHADER diff --git a/materialsystem/stdshaders/debugtangentspace.cpp b/materialsystem/stdshaders/debugtangentspace.cpp new file mode 100644 index 0000000..3027901 --- /dev/null +++ b/materialsystem/stdshaders/debugtangentspace.cpp @@ -0,0 +1,133 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $Header: $ +// $NoKeywords: $ +//=============================================================================// + +#include "shaderlib/cshader.h" + +#define USE_NEW_SHADER //Updating assembly shaders to fxc, this is for A/B testing. + +#ifdef USE_NEW_SHADER +#include "debugtangentspace_vs11.inc" +#include "debugtangentspace_vs20.inc" +#include "unlitgeneric_notexture_ps11.inc" +#include "unlitgeneric_notexture_ps20.inc" +#include "unlitgeneric_notexture_ps20b.inc" + +#else +#include "debugtangentspace.inc" +#endif + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +BEGIN_SHADER( DebugTangentSpace, "Help for DebugTangentSpace" ) + BEGIN_SHADER_PARAMS + SHADER_PARAM_OVERRIDE( BASETEXTURE, SHADER_PARAM_TYPE_TEXTURE, "shadertest/basetexture", "unused", SHADER_PARAM_NOT_EDITABLE ) + SHADER_PARAM_OVERRIDE( FRAME, SHADER_PARAM_TYPE_INTEGER, "0", "unused", SHADER_PARAM_NOT_EDITABLE ) + SHADER_PARAM_OVERRIDE( BASETEXTURETRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "unused", SHADER_PARAM_NOT_EDITABLE ) + SHADER_PARAM_OVERRIDE( COLOR, SHADER_PARAM_TYPE_COLOR, "{255 255 255}", "unused", SHADER_PARAM_NOT_EDITABLE ) + SHADER_PARAM_OVERRIDE( ALPHA, SHADER_PARAM_TYPE_FLOAT, "1.0", "unused", SHADER_PARAM_NOT_EDITABLE ) + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + SET_FLAGS2( MATERIAL_VAR2_SUPPORTS_HW_SKINNING ); + } + + SHADER_INIT + { + } + + SHADER_DRAW + { + if (g_pHardwareConfig->SupportsVertexAndPixelShaders()) + { + SHADOW_STATE + { + // Set stream format (note that this shader supports compression) + unsigned int flags = VERTEX_POSITION | VERTEX_NORMAL | VERTEX_FORMAT_COMPRESSED; + int nTexCoordCount = 0; + int userDataSize = 4; + pShaderShadow->VertexShaderVertexFormat( flags, nTexCoordCount, NULL, userDataSize ); + +#ifdef USE_NEW_SHADER + if( g_pHardwareConfig->GetDXSupportLevel() >= 90 ) + { + DECLARE_STATIC_VERTEX_SHADER( debugtangentspace_vs20 ); + SET_STATIC_VERTEX_SHADER( debugtangentspace_vs20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_STATIC_PIXEL_SHADER( unlitgeneric_notexture_ps20b ); + SET_STATIC_PIXEL_SHADER( unlitgeneric_notexture_ps20b ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( unlitgeneric_notexture_ps20 ); + SET_STATIC_PIXEL_SHADER( unlitgeneric_notexture_ps20 ); + } + } + else + { + DECLARE_STATIC_VERTEX_SHADER( debugtangentspace_vs11 ); + SET_STATIC_VERTEX_SHADER( debugtangentspace_vs11 ); + + DECLARE_STATIC_PIXEL_SHADER( unlitgeneric_notexture_ps11 ); + SET_STATIC_PIXEL_SHADER( unlitgeneric_notexture_ps11 ); + } +#else + debugtangentspace_Static_Index vshIndex; + pShaderShadow->SetVertexShader( "DebugTangentSpace", vshIndex.GetIndex() ); + + pShaderShadow->SetPixelShader( "UnlitGeneric_NoTexture" ); +#endif + } + DYNAMIC_STATE + { + +#ifdef USE_NEW_SHADER + if( g_pHardwareConfig->GetDXSupportLevel() >= 90 ) + { + DECLARE_DYNAMIC_VERTEX_SHADER( debugtangentspace_vs20 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( DOWATERFOG, pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, pShaderAPI->GetCurrentNumBones() > 0 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression ); + SET_DYNAMIC_VERTEX_SHADER( debugtangentspace_vs20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_DYNAMIC_PIXEL_SHADER( unlitgeneric_notexture_ps20b ); + SET_DYNAMIC_PIXEL_SHADER( unlitgeneric_notexture_ps20b ); + } + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( unlitgeneric_notexture_ps20 ); + SET_DYNAMIC_PIXEL_SHADER( unlitgeneric_notexture_ps20 ); + } + } + else // legacy hardware + { + DECLARE_DYNAMIC_VERTEX_SHADER( debugtangentspace_vs11 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( DOWATERFOG, pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, pShaderAPI->GetCurrentNumBones() > 0 ); + SET_DYNAMIC_VERTEX_SHADER( debugtangentspace_vs11 ); + + DECLARE_DYNAMIC_PIXEL_SHADER( unlitgeneric_notexture_ps11 ); + SET_DYNAMIC_PIXEL_SHADER( unlitgeneric_notexture_ps11 ); + } +#else + debugtangentspace_Dynamic_Index vshIndex; + vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + vshIndex.SetSKINNING( pShaderAPI->GetCurrentNumBones() > 0 ); + pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() ); +#endif + } + Draw(); + } + } +END_SHADER + diff --git a/materialsystem/stdshaders/debugtangentspace.vsh b/materialsystem/stdshaders/debugtangentspace.vsh new file mode 100644 index 0000000..cb38a23 --- /dev/null +++ b/materialsystem/stdshaders/debugtangentspace.vsh @@ -0,0 +1,34 @@ +vs.1.1 + +# DYNAMIC: "DOWATERFOG" "0..1" +# DYNAMIC: "SKINNING" "0..1" + +#include "macros.vsh" + +;------------------------------------------------------------------------------ +; Vertex blending +;------------------------------------------------------------------------------ +&AllocateRegister( \$worldPos ); +&AllocateRegister( \$worldNormal ); +&SkinPositionAndNormal( $worldPos, $worldNormal ); + +;------------------------------------------------------------------------------ +; Transform the position from world to view space +;------------------------------------------------------------------------------ + +&AllocateRegister( \$projPos ); + +dp4 $projPos.x, $worldPos, $cViewProj0 +dp4 $projPos.y, $worldPos, $cViewProj1 +dp4 $projPos.z, $worldPos, $cViewProj2 +dp4 $projPos.w, $worldPos, $cViewProj3 +mov oPos, $projPos + +&FreeRegister( \$worldPos ); + +; stick the normal in the color channel +mov oD0.xyz, $worldNormal.xyz +mov oD0.w, $cOne ; make sure all components are defined + +&FreeRegister( \$projPos ); +&FreeRegister( \$worldNormal ); diff --git a/materialsystem/stdshaders/debugtangentspace_vs11.fxc b/materialsystem/stdshaders/debugtangentspace_vs11.fxc new file mode 100644 index 0000000..1584ef2 --- /dev/null +++ b/materialsystem/stdshaders/debugtangentspace_vs11.fxc @@ -0,0 +1,51 @@ +// DYNAMIC: "DOWATERFOG" "0..1" +// DYNAMIC: "SKINNING" "0..1" + +#include "common_vs_fxc.h" + +static const int g_FogType = DOWATERFOG; +static const bool g_bSkinning = SKINNING ? true : false; + + +struct VS_INPUT +{ + float4 vPos : POSITION; + float4 vBoneWeights : BLENDWEIGHT; + float4 vBoneIndices : BLENDINDICES; + float3 vNormal : NORMAL; +}; + +struct VS_OUTPUT +{ + float4 vProjPos : POSITION; + + float4 vDiffuse : COLOR0; + + float4 fogFactorW : COLOR1; + +#if !defined( _X360 ) + float fog : FOG; +#endif +}; + + +VS_OUTPUT main( const VS_INPUT v ) +{ + VS_OUTPUT o = ( VS_OUTPUT )0; + + float3 worldPos, worldNormal; + SkinPositionAndNormal( g_bSkinning, v.vPos, v.vNormal, v.vBoneWeights, v.vBoneIndices, worldPos, worldNormal ); + + o.vProjPos = mul( float4( worldPos, 1 ), cViewProj ); + + o.fogFactorW = CalcFog( worldPos, o.vProjPos, g_FogType ); +#if !defined( _X360 ) + o.fog = o.fogFactorW; +#endif + + // stick the normal in the color channel + o.vDiffuse.rgb = worldNormal; + o.vDiffuse.a = 1.0f; + + return o; +} \ No newline at end of file diff --git a/materialsystem/stdshaders/debugtangentspace_vs20.fxc b/materialsystem/stdshaders/debugtangentspace_vs20.fxc new file mode 100644 index 0000000..f829bde --- /dev/null +++ b/materialsystem/stdshaders/debugtangentspace_vs20.fxc @@ -0,0 +1,55 @@ +// DYNAMIC: "COMPRESSED_VERTS" "0..1" +// DYNAMIC: "DOWATERFOG" "0..1" +// DYNAMIC: "SKINNING" "0..1" + +#include "common_vs_fxc.h" + +static const int g_FogType = DOWATERFOG; +static const bool g_bSkinning = SKINNING ? true : false; + + +struct VS_INPUT +{ + float4 vPos : POSITION; + float4 vBoneWeights : BLENDWEIGHT; + float4 vBoneIndices : BLENDINDICES; + float4 vNormal : NORMAL; +}; + +struct VS_OUTPUT +{ + float4 vProjPos : POSITION; + + float4 vDiffuse : COLOR0; + + float4 fogFactorW : COLOR1; + +#if !defined( _X360 ) + float fog : FOG; +#endif +}; + + +VS_OUTPUT main( const VS_INPUT v ) +{ + VS_OUTPUT o = ( VS_OUTPUT )0; + + float3 vObjNormal; + DecompressVertex_Normal( v.vNormal, vObjNormal ); + + float3 worldPos, worldNormal; + SkinPositionAndNormal( g_bSkinning, v.vPos, vObjNormal, v.vBoneWeights, v.vBoneIndices, worldPos, worldNormal ); + + o.vProjPos = mul( float4( worldPos, 1 ), cViewProj ); + + o.fogFactorW = CalcFog( worldPos, o.vProjPos, g_FogType ); +#if !defined( _X360 ) + o.fog = o.fogFactorW; +#endif + + // stick the normal in the color channel + o.vDiffuse.rgb = worldNormal; + o.vDiffuse.a = 1.0f; + + return o; +} \ No newline at end of file diff --git a/materialsystem/stdshaders/decal.cpp b/materialsystem/stdshaders/decal.cpp new file mode 100644 index 0000000..3f1f90e --- /dev/null +++ b/materialsystem/stdshaders/decal.cpp @@ -0,0 +1,127 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//=============================================================================// + +#include "shaderlib/cshader.h" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +BEGIN_SHADER_FLAGS( Decal, "Help for Decal", SHADER_NOT_EDITABLE ) + + BEGIN_SHADER_PARAMS + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + SET_FLAGS( MATERIAL_VAR_NO_DEBUG_OVERRIDE ); + } + + SHADER_INIT + { + LoadTexture( BASETEXTURE ); + } + + SHADER_DRAW + { + // vertex alpha 0 = mod2x, vertex alpha 1 = src_alpha,1-src_alpha + // need to set constant color to grey + SHADOW_STATE + { + // common stuff + pShaderShadow->EnableDepthWrites( false ); + pShaderShadow->EnablePolyOffset( SHADER_POLYOFFSET_DECAL ); + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + pShaderShadow->EnableBlending( true ); + } + // MOD2X pass + SHADOW_STATE + { + pShaderShadow->EnableCustomPixelPipe( true ); + pShaderShadow->CustomTextureStages( 2 ); + + // color = texture + // alpha = vertexalpha + pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE0, + SHADER_TEXCHANNEL_COLOR, SHADER_TEXOP_SELECTARG1, + SHADER_TEXARG_TEXTURE, SHADER_TEXARG_NONE ); + pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE0, + SHADER_TEXCHANNEL_ALPHA, SHADER_TEXOP_SELECTARG1, + SHADER_TEXARG_SPECULARCOLOR, SHADER_TEXARG_NONE ); + + // color = texture + // alpha = blend + pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE1, + SHADER_TEXCHANNEL_COLOR, SHADER_TEXOP_BLEND_PREVIOUSSTAGEALPHA, + SHADER_TEXARG_CONSTANTCOLOR, SHADER_TEXARG_PREVIOUSSTAGE ); + + pShaderShadow->BlendFunc( SHADER_BLEND_DST_COLOR, SHADER_BLEND_SRC_COLOR ); + FogToGrey(); + + pShaderShadow->DrawFlags( SHADER_DRAW_POSITION | SHADER_DRAW_TEXCOORD0 | SHADER_DRAW_SPECULAR + | SHADER_DRAW_LIGHTMAP_TEXCOORD1 ); + } + DYNAMIC_STATE + { + pShaderAPI->Color3f( 0.5f, 0.5f, 0.5f ); + BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME ); + pShaderAPI->BindStandardTexture( SHADER_SAMPLER1, TEXTURE_LIGHTMAP ); + } + Draw(); + + // srcalpha,1-srcalpha pass + SHADOW_STATE + { + pShaderShadow->EnableCustomPixelPipe( true ); + pShaderShadow->CustomTextureStages( 2 ); + + // color = texture + // alpha = texture + if (IS_FLAG_SET( MATERIAL_VAR_VERTEXCOLOR )) + { + pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE0, + SHADER_TEXCHANNEL_COLOR, SHADER_TEXOP_MODULATE, + SHADER_TEXARG_TEXTURE, SHADER_TEXARG_VERTEXCOLOR ); + } + else + { + pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE0, + SHADER_TEXCHANNEL_COLOR, SHADER_TEXOP_SELECTARG1, + SHADER_TEXARG_TEXTURE, SHADER_TEXARG_NONE ); + } + + if( IS_FLAG_SET( MATERIAL_VAR_VERTEXALPHA ) ) + { + pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE0, + SHADER_TEXCHANNEL_ALPHA, SHADER_TEXOP_MODULATE, + SHADER_TEXARG_TEXTURE, SHADER_TEXARG_VERTEXCOLOR ); + } + else + { + pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE0, + SHADER_TEXCHANNEL_ALPHA, SHADER_TEXOP_SELECTARG1, + SHADER_TEXARG_TEXTURE, SHADER_TEXARG_NONE ); + } + + // color = texture [* vertex color] * lightmap color + // alpha = texture alpha [* vertex alpha] * specular alpha + pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE1, + SHADER_TEXCHANNEL_COLOR, SHADER_TEXOP_MODULATE2X, + SHADER_TEXARG_PREVIOUSSTAGE, SHADER_TEXARG_TEXTURE ); + pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE1, + SHADER_TEXCHANNEL_ALPHA, SHADER_TEXOP_MODULATE, + SHADER_TEXARG_PREVIOUSSTAGE, SHADER_TEXARG_SPECULARCOLOR ); + + pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA ); + FogToFogColor(); + } + DYNAMIC_STATE + { + SetColorState( COLOR ); + } + Draw(); + } +END_SHADER diff --git a/materialsystem/stdshaders/decalbasetimeslightmapalphablendselfillum2_ps2x.fxc b/materialsystem/stdshaders/decalbasetimeslightmapalphablendselfillum2_ps2x.fxc new file mode 100644 index 0000000..f8489d7 --- /dev/null +++ b/materialsystem/stdshaders/decalbasetimeslightmapalphablendselfillum2_ps2x.fxc @@ -0,0 +1,26 @@ +// DYNAMIC: "PIXELFOGTYPE" "0..1" + +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX] + +#include "shader_constant_register_map.h" +#include "common_ps_fxc.h" + +sampler BaseTextureSampler : register( s0 ); + +const float4 g_FogParams : register( PSREG_FOG_PARAMS ); +const float4 g_EyePos_SpecExponent : register( PSREG_EYEPOS_SPEC_EXPONENT ); + +struct PS_INPUT +{ + float2 vTexCoord0 : TEXCOORD0; + float4 worldPos_projPosZ : TEXCOORD4; // Necessary for pixel fog +}; + +float4 main( PS_INPUT i ) : COLOR +{ + HALF4 result = tex2D( BaseTextureSampler, i.vTexCoord0 ); + + float fogFactor = CalcPixelFogFactor( PIXELFOGTYPE, g_FogParams, g_EyePos_SpecExponent.z, i.worldPos_projPosZ.z, i.worldPos_projPosZ.w ); + return FinalOutput( result, fogFactor, PIXELFOGTYPE, TONEMAP_SCALE_LINEAR ); +} diff --git a/materialsystem/stdshaders/decalmodulate.cpp b/materialsystem/stdshaders/decalmodulate.cpp new file mode 100644 index 0000000..8484ccd --- /dev/null +++ b/materialsystem/stdshaders/decalmodulate.cpp @@ -0,0 +1,63 @@ +//========= 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" + +DEFINE_FALLBACK_SHADER( DecalModulate, DecalModulate_DX6 ) + +BEGIN_SHADER( DecalModulate_dx6, + "Help for DecalModulate_dx6" ) + + BEGIN_SHADER_PARAMS + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + SET_FLAGS( MATERIAL_VAR_NO_DEBUG_OVERRIDE ); + } + + SHADER_INIT + { + LoadTexture( BASETEXTURE ); + } + + SHADER_DRAW + { + SHADOW_STATE + { + pShaderShadow->EnableAlphaTest( true ); + pShaderShadow->AlphaFunc( SHADER_ALPHAFUNC_GREATER, 0.0f ); + pShaderShadow->EnableDepthWrites( false ); + pShaderShadow->EnablePolyOffset( SHADER_POLYOFFSET_DECAL ); + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableBlending( true ); + pShaderShadow->BlendFunc( SHADER_BLEND_DST_COLOR, SHADER_BLEND_SRC_COLOR ); + pShaderShadow->DrawFlags( SHADER_DRAW_POSITION | SHADER_DRAW_TEXCOORD0 ); + FogToGrey(); + } + DYNAMIC_STATE + { + // This is kinda gross. We really don't want to render anything here for the flashlight + // pass since we are multiplying by what is already flashlight lit in the framebuffer. + // There is no easy way to draw nothing conditionally, so I'll bind grey and multiply + // which shouldn't change the contents of the framebuffer much. + if( pShaderAPI->InFlashlightMode() ) + { + pShaderAPI->BindStandardTexture( SHADER_SAMPLER0, TEXTURE_GREY ); + } + else + { + BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME ); + } + } + Draw( ); + } +END_SHADER diff --git a/materialsystem/stdshaders/decalmodulate_dx8.cpp b/materialsystem/stdshaders/decalmodulate_dx8.cpp new file mode 100644 index 0000000..be4b715 --- /dev/null +++ b/materialsystem/stdshaders/decalmodulate_dx8.cpp @@ -0,0 +1,86 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $Header: $ +// $NoKeywords: $ +//=============================================================================// + +#include "BaseVSShader.h" + +#include "decalmodulate_vs11.inc" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +DEFINE_FALLBACK_SHADER( DecalModulate, DecalModulate_DX8 ) + +BEGIN_VS_SHADER( DecalModulate_DX8, "" ) + + BEGIN_SHADER_PARAMS + END_SHADER_PARAMS + + SHADER_FALLBACK + { + if ( IsPC() && g_pHardwareConfig->GetDXSupportLevel() < 80 ) + return "DecalModulate_DX6"; + return 0; + } + + SHADER_INIT_PARAMS() + { + SET_FLAGS( MATERIAL_VAR_NO_DEBUG_OVERRIDE ); + } + + SHADER_INIT + { + LoadTexture( BASETEXTURE ); + } + + SHADER_DRAW + { + SHADOW_STATE + { + pShaderShadow->EnableAlphaTest( true ); + pShaderShadow->EnableDepthWrites( false ); + pShaderShadow->EnablePolyOffset( SHADER_POLYOFFSET_DECAL ); + pShaderShadow->EnableTexture( SHADER_TEXTURE_STAGE0, true ); + pShaderShadow->EnableBlending( true ); + pShaderShadow->BlendFunc( SHADER_BLEND_DST_COLOR, SHADER_BLEND_SRC_COLOR ); + FogToGrey(); + + decalmodulate_vs11_Static_Index vshIndex; + s_pShaderShadow->SetVertexShader( "decalmodulate_vs11", vshIndex.GetIndex() ); + + s_pShaderShadow->SetPixelShader( "decalmodulate_ps11", 0 ); + + pShaderShadow->VertexShaderVertexFormat( VERTEX_POSITION, 1, 0, 0, 0 ); + } + DYNAMIC_STATE + { + if ( pShaderAPI->InFlashlightMode() ) + { + // Don't draw anything for the flashlight pass + Draw( false ); + return; + } + + BindTexture( SHADER_TEXTURE_STAGE0, BASETEXTURE, FRAME ); + + // Set an identity base texture transformation + Vector4D transformation[2]; + transformation[0].Init( 1.0f, 0.0f, 0.0f, 0.0f ); + transformation[1].Init( 0.0f, 1.0f, 0.0f, 0.0f ); + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, transformation[0].Base(), 2 ); + + MaterialFogMode_t fogType = s_pShaderAPI->GetSceneFogMode(); + int fogIndex = ( fogType == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ) ? 1 : 0; + decalmodulate_vs11_Dynamic_Index vshIndex; + vshIndex.SetDOWATERFOG( fogIndex ); + vshIndex.SetSKINNING( 0 ); + s_pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() ); + } + Draw(); + + } +END_SHADER diff --git a/materialsystem/stdshaders/decalmodulate_ps11.psh b/materialsystem/stdshaders/decalmodulate_ps11.psh new file mode 100644 index 0000000..fe6b479 --- /dev/null +++ b/materialsystem/stdshaders/decalmodulate_ps11.psh @@ -0,0 +1,4 @@ +ps.1.1 + +tex t0 +mov r0, t0 \ No newline at end of file diff --git a/materialsystem/stdshaders/decalmodulate_ps2x.fxc b/materialsystem/stdshaders/decalmodulate_ps2x.fxc new file mode 100644 index 0000000..a756865 --- /dev/null +++ b/materialsystem/stdshaders/decalmodulate_ps2x.fxc @@ -0,0 +1,45 @@ +//======= Copyright © 1996-2006, Valve Corporation, All rights reserved. ====== + +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps30][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX] + +// DYNAMIC: "PIXELFOGTYPE" "0..1" + +#include "common_ps_fxc.h" +#include "shader_constant_register_map.h" + +sampler TexSampler : register( s0 ); + +const float4 g_FogParams : register( PSREG_FOG_PARAMS ); +const float4 g_EyePos_SpecExponent : register( PSREG_EYEPOS_SPEC_EXPONENT ); + +struct PS_INPUT +{ + HALF2 baseTexCoord : TEXCOORD0; // Base texture coordinate + + float4 worldPos_projPosZ : TEXCOORD7; // Necessary for pixel fog + float4 fogFactorW : COLOR1; + +#if defined( _X360 ) //matching pixel shader inputs to vertex shader outputs to avoid shader patches + HALF2 detailTexCoord : TEXCOORD1; + float4 color : TEXCOORD2; + float3 worldVertToEyeVector : TEXCOORD3; + float3 worldSpaceNormal : TEXCOORD4; + float4 vProjPos : TEXCOORD6; +#endif +}; + +float4 main( PS_INPUT i ) : COLOR +{ + float4 result = tex2D( TexSampler, i.baseTexCoord ); + + float fogFactor = CalcPixelFogFactor( PIXELFOGTYPE, g_FogParams, g_EyePos_SpecExponent.z, i.worldPos_projPosZ.z, i.worldPos_projPosZ.w ); + + // Since we're blending with a mod2x, we need to compensate with this hack + // NOTE: If the fog color (not fog density) is extremely dark, this can makes some decals seem + // a little transparent, but it's better than not doing this + fogFactor = pow( saturate( fogFactor ), 0.4f ); + + return FinalOutput( result, fogFactor, PIXELFOGTYPE, TONEMAP_SCALE_NONE ); +} diff --git a/materialsystem/stdshaders/decalmodulate_vs11.vsh b/materialsystem/stdshaders/decalmodulate_vs11.vsh new file mode 100644 index 0000000..d083754 --- /dev/null +++ b/materialsystem/stdshaders/decalmodulate_vs11.vsh @@ -0,0 +1,8 @@ +vs.1.1 + +# DYNAMIC: "SKINNING" "0..0" +# DYNAMIC: "DOWATERFOG" "0..1" + +#include "UnlitGeneric_inc.vsh" + +&UnlitGeneric( 0, 0, 0, 0, 0 ); diff --git a/materialsystem/stdshaders/depthtodestalpha_ps20b.fxc b/materialsystem/stdshaders/depthtodestalpha_ps20b.fxc new file mode 100644 index 0000000..61daa23 --- /dev/null +++ b/materialsystem/stdshaders/depthtodestalpha_ps20b.fxc @@ -0,0 +1,11 @@ +#include "common_ps_fxc.h" + +struct PS_INPUT +{ + float projPosZ : TEXCOORD0; +}; + +float4 main( PS_INPUT i ) : COLOR +{ + return FinalOutput( float4( 0, 0, 0, 1.0f ), 0.0f, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE, true, i.projPosZ ); +} diff --git a/materialsystem/stdshaders/depthtodestalpha_vs20.fxc b/materialsystem/stdshaders/depthtodestalpha_vs20.fxc new file mode 100644 index 0000000..9891502 --- /dev/null +++ b/materialsystem/stdshaders/depthtodestalpha_vs20.fxc @@ -0,0 +1,23 @@ +#include "common_vs_fxc.h" + +struct VS_INPUT +{ + float4 vPos : POSITION; +}; + +struct VS_OUTPUT +{ + float4 vProjPos : POSITION; + float projPosZ : TEXCOORD0; +}; + + +VS_OUTPUT main( const VS_INPUT v ) +{ + VS_OUTPUT o = ( VS_OUTPUT )0; + + o.vProjPos = mul( v.vPos, cModelViewProj ); + o.projPosZ = o.vProjPos.z; + + return o; +} diff --git a/materialsystem/stdshaders/depthwrite.cpp b/materialsystem/stdshaders/depthwrite.cpp new file mode 100644 index 0000000..06d7690 --- /dev/null +++ b/materialsystem/stdshaders/depthwrite.cpp @@ -0,0 +1,207 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $Header: $ +// $NoKeywords: $ +//=============================================================================// + +#include "BaseVSShader.h" + +#include "depthwrite_ps20.inc" +#include "depthwrite_ps20b.inc" +#include "depthwrite_vs20.inc" + +#if !defined( _X360 ) +#include "depthwrite_ps30.inc" +#include "depthwrite_vs30.inc" +#endif + +BEGIN_VS_SHADER_FLAGS( DepthWrite, "Help for Depth Write", SHADER_NOT_EDITABLE ) + + BEGIN_SHADER_PARAMS + SHADER_PARAM( ALPHATESTREFERENCE, SHADER_PARAM_TYPE_FLOAT, "", "Alpha reference value" ) + SHADER_PARAM( COLOR_DEPTH, SHADER_PARAM_TYPE_BOOL, "0", "Write depth as color") + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + SET_FLAGS2( MATERIAL_VAR2_SUPPORTS_HW_SKINNING ); + } + + SHADER_FALLBACK + { + if ( g_pHardwareConfig->GetDXSupportLevel() < 90 ) + { + return "Wireframe"; + } + return 0; + } + + SHADER_INIT + { + } + + SHADER_DRAW + { + bool bAlphaClip = IS_FLAG_SET( MATERIAL_VAR_ALPHATEST ); + int nColorDepth = GetIntParam( COLOR_DEPTH, params, 0 ); + + SHADOW_STATE + { + // Set stream format (note that this shader supports compression) + unsigned int flags = VERTEX_POSITION | VERTEX_FORMAT_COMPRESSED; + int nTexCoordCount = 1; + int userDataSize = 0; + pShaderShadow->VertexShaderVertexFormat( flags, nTexCoordCount, NULL, userDataSize ); + + if ( nColorDepth == 0 ) + { + // Bias primitives when rendering into shadow map so we get slope-scaled depth bias + // rather than having to apply a constant bias in the filtering shader later + pShaderShadow->EnablePolyOffset( SHADER_POLYOFFSET_SHADOW_BIAS ); + } + + // Turn off writes to color buffer since we always sample shadows from the DEPTH texture later + // This gives us double-speed fill when rendering INTO the shadow map + pShaderShadow->EnableColorWrites( ( nColorDepth == 1 ) ); + pShaderShadow->EnableAlphaWrites( false ); + + // Don't backface cull unless alpha clipping, since this can cause artifacts when the + // geometry is clipped by the flashlight near plane + // If a material was already marked nocull, don't cull it + pShaderShadow->EnableCulling( IS_FLAG_SET(MATERIAL_VAR_ALPHATEST) && !IS_FLAG_SET(MATERIAL_VAR_NOCULL) ); + +#ifndef _X360 + if ( !g_pHardwareConfig->HasFastVertexTextures() ) +#endif + { + DECLARE_STATIC_VERTEX_SHADER( depthwrite_vs20 ); + SET_STATIC_VERTEX_SHADER_COMBO( ONLY_PROJECT_POSITION, !bAlphaClip && IsX360() && !nColorDepth ); //360 needs to know if it *shouldn't* output texture coordinates to avoid shader patches + SET_STATIC_VERTEX_SHADER_COMBO( COLOR_DEPTH, nColorDepth ); + SET_STATIC_VERTEX_SHADER( depthwrite_vs20 ); + + if ( bAlphaClip || g_pHardwareConfig->PlatformRequiresNonNullPixelShaders() || nColorDepth ) + { + if( bAlphaClip ) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, true ); + } + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_STATIC_PIXEL_SHADER( depthwrite_ps20b ); + SET_STATIC_PIXEL_SHADER_COMBO( COLOR_DEPTH, nColorDepth ); + SET_STATIC_PIXEL_SHADER( depthwrite_ps20b ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( depthwrite_ps20 ); + SET_STATIC_PIXEL_SHADER_COMBO( COLOR_DEPTH, nColorDepth ); + SET_STATIC_PIXEL_SHADER( depthwrite_ps20 ); + } + } + } +#ifndef _X360 + else + { + SET_FLAGS2( MATERIAL_VAR2_USES_VERTEXID ); + + DECLARE_STATIC_VERTEX_SHADER( depthwrite_vs30 ); + SET_STATIC_VERTEX_SHADER_COMBO( ONLY_PROJECT_POSITION, 0 ); //360 only combo, and this is a PC path + SET_STATIC_VERTEX_SHADER_COMBO( COLOR_DEPTH, nColorDepth ); + SET_STATIC_VERTEX_SHADER( depthwrite_vs30 ); + + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, true ); + + DECLARE_STATIC_PIXEL_SHADER( depthwrite_ps30 ); + SET_STATIC_PIXEL_SHADER_COMBO( COLOR_DEPTH, nColorDepth ); + SET_STATIC_PIXEL_SHADER( depthwrite_ps30 ); + } +#endif + } + DYNAMIC_STATE + { + +#ifndef _X360 + if ( !g_pHardwareConfig->HasFastVertexTextures() ) +#endif + { + depthwrite_vs20_Dynamic_Index vshIndex; + vshIndex.SetSKINNING( pShaderAPI->GetCurrentNumBones() > 0 ); + vshIndex.SetCOMPRESSED_VERTS( (int)vertexCompression ); + pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() ); + + if ( bAlphaClip ) + { + BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME ); + + float vAlphaThreshold[4] = {0.7f, 0.7f, 0.7f, 0.7f}; + if ( ALPHATESTREFERENCE != -1 && ( params[ALPHATESTREFERENCE]->GetFloatValue() > 0.0f ) ) + { + vAlphaThreshold[0] = vAlphaThreshold[1] = vAlphaThreshold[2] = vAlphaThreshold[3] = params[ALPHATESTREFERENCE]->GetFloatValue(); + } + + pShaderAPI->SetPixelShaderConstant( 0, vAlphaThreshold, 1 ); + } + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_DYNAMIC_PIXEL_SHADER( depthwrite_ps20b ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( ALPHACLIP, bAlphaClip ); + SET_DYNAMIC_PIXEL_SHADER( depthwrite_ps20b ); + } + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( depthwrite_ps20 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( ALPHACLIP, bAlphaClip ); + SET_DYNAMIC_PIXEL_SHADER( depthwrite_ps20 ); + } + } +#ifndef _X360 + else // 3.0 shader case (PC only) + { + SetHWMorphVertexShaderState( VERTEX_SHADER_SHADER_SPECIFIC_CONST_6, VERTEX_SHADER_SHADER_SPECIFIC_CONST_7, SHADER_VERTEXTEXTURE_SAMPLER0 ); + + depthwrite_vs30_Dynamic_Index vshIndex; + vshIndex.SetSKINNING( pShaderAPI->GetCurrentNumBones() > 0 ); + vshIndex.SetMORPHING( pShaderAPI->IsHWMorphingEnabled() ); + vshIndex.SetCOMPRESSED_VERTS( (int)vertexCompression ); + pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() ); + + if ( bAlphaClip ) + { + BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME ); + + float vAlphaThreshold[4] = {0.7f, 0.7f, 0.7f, 0.7f}; + if ( ALPHATESTREFERENCE != -1 && ( params[ALPHATESTREFERENCE]->GetFloatValue() > 0.0f ) ) + { + vAlphaThreshold[0] = vAlphaThreshold[1] = vAlphaThreshold[2] = vAlphaThreshold[3] = params[ALPHATESTREFERENCE]->GetFloatValue(); + } + + pShaderAPI->SetPixelShaderConstant( 0, vAlphaThreshold, 1 ); + } + + DECLARE_DYNAMIC_PIXEL_SHADER( depthwrite_ps30 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( ALPHACLIP, bAlphaClip ); + SET_DYNAMIC_PIXEL_SHADER( depthwrite_ps30 ); + } +#endif + + Vector4D vParms; + + // set up arbitrary far planes, as the real ones are too far ( 30,000 ) +// pShaderAPI->SetPSNearAndFarZ( 1 ); + vParms.x = 7.0f; // arbitrary near + vParms.y = 4000.0f; // arbitrary far + vParms.z = 0.0f; + vParms.w = 0.0f; + pShaderAPI->SetPixelShaderConstant( 1, vParms.Base(), 2 ); + + } // DYNAMIC_STATE + + Draw( ); + } +END_SHADER diff --git a/materialsystem/stdshaders/depthwrite_ps2x.fxc b/materialsystem/stdshaders/depthwrite_ps2x.fxc new file mode 100644 index 0000000..1baabcf --- /dev/null +++ b/materialsystem/stdshaders/depthwrite_ps2x.fxc @@ -0,0 +1,44 @@ +// STATIC: "COLOR_DEPTH" "0..1" + +// DYNAMIC: "ALPHACLIP" "0..1" + +const float g_AlphaThreshold : register( c0 ); + +const float2 g_vNearFarPlanes : register( c1 ); + #define g_flNearPlane g_vNearFarPlanes.x + #define g_flFarPlane g_vNearFarPlanes.y + +struct PS_INPUT +{ +#if ALPHACLIP + float2 texCoord0 : TEXCOORD0; +#endif + +#if COLOR_DEPTH + float4 vWorldPos_projPosZ : TEXCOORD1; +#endif +}; + +sampler BaseTextureSampler : register( s0 ); + +float4 main( PS_INPUT i ) : COLOR +{ + float4 color = float4( 1, 0, 0, 1 ); // opaque alpha....the color doesn't matter for this shader + +#if ALPHACLIP + color = tex2D( BaseTextureSampler, i.texCoord0 ); + + clip( color.a - g_AlphaThreshold ); + +#endif + +#if ( COLOR_DEPTH == 1 ) + + return float4( i.vWorldPos_projPosZ.w / g_flFarPlane, 0.0, 0.0, 1.0 ); + +#else + + return color; + +#endif +} diff --git a/materialsystem/stdshaders/depthwrite_vs20.fxc b/materialsystem/stdshaders/depthwrite_vs20.fxc new file mode 100644 index 0000000..f98e40e --- /dev/null +++ b/materialsystem/stdshaders/depthwrite_vs20.fxc @@ -0,0 +1,83 @@ +// STATIC: "ONLY_PROJECT_POSITION" "0..1" [XBOX] +// STATIC: "ONLY_PROJECT_POSITION" "0..0" [PC] +// STATIC: "COLOR_DEPTH" "0..1" + +// DYNAMIC: "COMPRESSED_VERTS" "0..1" +// DYNAMIC: "SKINNING" "0..1" +// DYNAMIC: "MORPHING" "0..1" [vs30] + +#include "common_vs_fxc.h" + +static const bool g_bSkinning = SKINNING ? true : false; + +#ifdef SHADER_MODEL_VS_3_0 +// NOTE: cMorphTargetTextureDim.xy = target dimensions, +// cMorphTargetTextureDim.z = 4tuples/morph +const float3 cMorphTargetTextureDim : register( SHADER_SPECIFIC_CONST_6 ); +const float4 cMorphSubrect : register( SHADER_SPECIFIC_CONST_7 ); + +sampler2D morphSampler : register( D3DVERTEXTEXTURESAMPLER0, s0 ); +#endif + + +struct VS_INPUT +{ + float4 vPos : POSITION; + float2 vTexCoord : TEXCOORD0; + float4 vBoneWeights : BLENDWEIGHT; + float4 vBoneIndices : BLENDINDICES; + + // Position delta stream + float3 vPosFlex : POSITION1; + +#ifdef SHADER_MODEL_VS_3_0 + float vVertexID : POSITION2; +#endif +}; + +struct VS_OUTPUT +{ + float4 vProjPos : POSITION; + +#if (ONLY_PROJECT_POSITION == 0) //360 sometimes runs without the pixel shader component, but has to patch this output if it does. + float2 texCoord : TEXCOORD0; +#endif + +#if COLOR_DEPTH + float4 vWorldPos_projPosZ : TEXCOORD1; +#endif + +}; + +VS_OUTPUT main( const VS_INPUT v ) +{ + VS_OUTPUT o = ( VS_OUTPUT )0; + float3 vWorldPos; + float4 vPosition = v.vPos; + +#if !defined( SHADER_MODEL_VS_3_0 ) || !MORPHING + ApplyMorph( v.vPosFlex, vPosition.xyz ); +#else + ApplyMorph( morphSampler, cMorphTargetTextureDim, cMorphSubrect, + v.vVertexID, float3(0, 0, 0), vPosition.xyz ); +#endif + + SkinPosition( g_bSkinning, vPosition, v.vBoneWeights, v.vBoneIndices, vWorldPos ); + + float4 vProjPos = mul( float4( vWorldPos, 1.0f ), cViewProj ); + + o.vProjPos = vProjPos; + +#if (ONLY_PROJECT_POSITION == 0) + o.texCoord = v.vTexCoord; +#endif + +#if ( COLOR_DEPTH && !ONLY_PROJECT_POSITION ) + o.vWorldPos_projPosZ.z = vProjPos.z; + o.vWorldPos_projPosZ.w = vProjPos.w; +#endif + + return o; +} + + diff --git a/materialsystem/stdshaders/detail.cpp b/materialsystem/stdshaders/detail.cpp new file mode 100644 index 0000000..956bf51 --- /dev/null +++ b/materialsystem/stdshaders/detail.cpp @@ -0,0 +1,37 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//===========================================================================// + +#include "BaseVSShader.h" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +BEGIN_VS_SHADER( Detail, "Help for Detail" ) + + BEGIN_SHADER_PARAMS + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + SET_FLAGS( MATERIAL_VAR_TRANSLUCENT ); + } + + SHADER_FALLBACK + { + return "UnlitGeneric"; + } + + SHADER_INIT + { + } + + SHADER_DRAW + { + } + +END_SHADER + diff --git a/materialsystem/stdshaders/detail_ps11.psh b/materialsystem/stdshaders/detail_ps11.psh new file mode 100644 index 0000000..8c49af1 --- /dev/null +++ b/materialsystem/stdshaders/detail_ps11.psh @@ -0,0 +1,12 @@ +ps.1.1 + +tex t0 +tex t1 + +mul r0.rgb, t0, v0 + + +; handle distance fade +sub r0.a, t0.a, 1-v0.a + +sub r0.a, r0.a, t1_bias.a +cnd r0.a, r0.a, c0.a, c1.a diff --git a/materialsystem/stdshaders/detail_vs11.vsh b/materialsystem/stdshaders/detail_vs11.vsh new file mode 100644 index 0000000..28dee2f --- /dev/null +++ b/materialsystem/stdshaders/detail_vs11.vsh @@ -0,0 +1,56 @@ +vs.1.1 + +# DYNAMIC: "DOWATERFOG" "0..1" + +#include "macros.vsh" + +;------------------------------------------------------------------------------ +; Vertex blending +;------------------------------------------------------------------------------ +&AllocateRegister( \$worldPos ); +dp4 $worldPos.x, $vPos, $cModel0 +dp4 $worldPos.y, $vPos, $cModel1 +dp4 $worldPos.z, $vPos, $cModel2 +mov $worldPos.w, $cOne + + +;------------------------------------------------------------------------------ +; Transform the position from world to proj space +;------------------------------------------------------------------------------ +&AllocateRegister( \$projPos ); +dp4 $projPos.x, $vPos, $cModelViewProj0 +dp4 $projPos.y, $vPos, $cModelViewProj1 +dp4 $projPos.z, $vPos, $cModelViewProj2 +dp4 $projPos.w, $vPos, $cModelViewProj3 +mov oPos, $projPos + + +;------------------------------------------------------------------------------ +; Fog +;------------------------------------------------------------------------------ +&CalcFog( $worldPos, $projPos ); +&FreeRegister( \$worldPos ); + + +;------------------------------------------------------------------------------ +; Texture coordinates +;------------------------------------------------------------------------------ +mov oT0.xy, $vTexCoord0.xy + +; special case perspective correct texture projection so that the texture fits exactly on the screen +mul $projPos.y, $projPos.y, $SHADER_SPECIFIC_CONST_0.w +add $projPos.xy, $projPos.xy, $projPos.w +mul $projPos.xy, $projPos.xy, $cHalf +mul $projPos.xy, $projPos.xy, $SHADER_SPECIFIC_CONST_0.xy +mad $projPos.xy, $projPos.w, $SHADER_SPECIFIC_CONST_1.xy, $projPos.xy + +mov oT1.xy, $projPos.xy +mov oT1.z, $projPos.w +mov oT1.w, $projPos.w + +&FreeRegister( \$projPos ); + +;------------------------------------------------------------------------------ +; Modulation color +;------------------------------------------------------------------------------ +mov oD0, $vColor diff --git a/materialsystem/stdshaders/downsample_nohdr.cpp b/materialsystem/stdshaders/downsample_nohdr.cpp new file mode 100644 index 0000000..114b207 --- /dev/null +++ b/materialsystem/stdshaders/downsample_nohdr.cpp @@ -0,0 +1,135 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//============================================================================// + +#include "BaseVSShader.h" +#include "common_hlsl_cpp_consts.h" +#include "convar.h" + +#include "Downsample_nohdr_ps20.inc" +#include "Downsample_nohdr_ps20b.inc" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + + +static ConVar r_bloomtintr( "r_bloomtintr", "0.3" ); +static ConVar r_bloomtintg( "r_bloomtintg", "0.59" ); +static ConVar r_bloomtintb( "r_bloomtintb", "0.11" ); +static ConVar r_bloomtintexponent( "r_bloomtintexponent", "2.2" ); + +BEGIN_VS_SHADER_FLAGS( Downsample_nohdr, "Help for Downsample_nohdr", SHADER_NOT_EDITABLE ) + + BEGIN_SHADER_PARAMS + SHADER_PARAM( BLOOMTINTENABLE, SHADER_PARAM_TYPE_INTEGER, "1", "" ) + SHADER_PARAM( CSTRIKE, SHADER_PARAM_TYPE_INTEGER, "0", "" ) + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + if ( !params[ BLOOMTINTENABLE ]->IsDefined() ) + { + params[ BLOOMTINTENABLE ]->SetIntValue( 1 ); + } + } + + SHADER_INIT + { + LoadTexture( BASETEXTURE ); + } + + SHADER_FALLBACK + { + if ( g_pHardwareConfig->GetDXSupportLevel() < 90 ) + { + return "Downsample_nohdr_DX80"; + } + return 0; + } + + SHADER_DRAW + { + SHADOW_STATE + { + pShaderShadow->EnableDepthWrites( false ); + pShaderShadow->EnableAlphaWrites( true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + + // Render targets are pegged as sRGB on OSX, so just force these reads and writes + bool bForceSRGBReadAndWrite = IsOSX() && g_pHardwareConfig->CanDoSRGBReadFromRTs(); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, bForceSRGBReadAndWrite ); + pShaderShadow->EnableSRGBWrite( bForceSRGBReadAndWrite ); + + pShaderShadow->VertexShaderVertexFormat( VERTEX_POSITION, 1, 0, 0 ); + + pShaderShadow->SetVertexShader( "Downsample_vs20", 0 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() || g_pHardwareConfig->ShouldAlwaysUseShaderModel2bShaders() ) + { + DECLARE_STATIC_PIXEL_SHADER( downsample_nohdr_ps20b ); + SET_STATIC_PIXEL_SHADER_COMBO( CSTRIKE, params[CSTRIKE]->GetIntValue() ? 1 : 0 ); +#ifndef _X360 + SET_STATIC_PIXEL_SHADER_COMBO( SRGB_ADAPTER, bForceSRGBReadAndWrite ); +#endif + SET_STATIC_PIXEL_SHADER( downsample_nohdr_ps20b ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( downsample_nohdr_ps20 ); + SET_STATIC_PIXEL_SHADER_COMBO( CSTRIKE, params[CSTRIKE]->GetIntValue() ? 1 : 0 ); + SET_STATIC_PIXEL_SHADER( downsample_nohdr_ps20 ); + } + } + + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER0, BASETEXTURE, -1 ); + + int width, height; + pShaderAPI->GetBackBufferDimensions( width, height ); + + float v[4][4]; + float dX = 1.0f/width; + float dY = 1.0f/height; + + v[0][0] = .5*dX; + v[0][1] = .5*dY; + v[1][0] = 2.5*dX; + v[1][1] = .5*dY; + v[2][0] = .5*dX; + v[2][1] = 2.5*dY; + v[3][0] = 2.5*dX; + v[3][1] = 2.5*dY; + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, &v[0][0], 4 ); + + pShaderAPI->SetVertexShaderIndex( 0 ); + + float flPixelShaderParams[4] = { r_bloomtintr.GetFloat(), + r_bloomtintg.GetFloat(), + r_bloomtintb.GetFloat(), + r_bloomtintexponent.GetFloat() }; + if ( params[ BLOOMTINTENABLE ]->GetIntValue() == 0 ) + { + flPixelShaderParams[0] = 0.333f; + flPixelShaderParams[1] = 0.333f; + flPixelShaderParams[2] = 0.333f; + flPixelShaderParams[3] = 1.0f; + } + pShaderAPI->SetPixelShaderConstant( 0, flPixelShaderParams, 1 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() || g_pHardwareConfig->ShouldAlwaysUseShaderModel2bShaders() ) + { + DECLARE_DYNAMIC_PIXEL_SHADER( downsample_nohdr_ps20b ); + SET_DYNAMIC_PIXEL_SHADER( downsample_nohdr_ps20b ); + } + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( downsample_nohdr_ps20 ); + SET_DYNAMIC_PIXEL_SHADER( downsample_nohdr_ps20 ); + } + } + Draw(); + } +END_SHADER diff --git a/materialsystem/stdshaders/downsample_nohdr_dx80.cpp b/materialsystem/stdshaders/downsample_nohdr_dx80.cpp new file mode 100644 index 0000000..e26390b --- /dev/null +++ b/materialsystem/stdshaders/downsample_nohdr_dx80.cpp @@ -0,0 +1,81 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//=============================================================================// + +#include "BaseVSShader.h" +#include "common_hlsl_cpp_consts.h" +#include "convar.h" +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +DEFINE_FALLBACK_SHADER( Downsample_nohdr, Downsample_nohdr_DX80 ) + +BEGIN_VS_SHADER_FLAGS( Downsample_nohdr_DX80, "Help for Downsample_nohdr_DX80", SHADER_NOT_EDITABLE ) + + BEGIN_SHADER_PARAMS + END_SHADER_PARAMS + + SHADER_INIT + { + LoadTexture( BASETEXTURE ); + } + + SHADER_FALLBACK + { + if ( g_pHardwareConfig->GetDXSupportLevel() < 80 ) + { + return "Wireframe"; + } + return 0; + } + + SHADER_DRAW + { + SHADOW_STATE + { + pShaderShadow->EnableDepthWrites( false ); + pShaderShadow->EnableAlphaWrites( true ); + + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER2, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER3, true ); + + pShaderShadow->VertexShaderVertexFormat( VERTEX_POSITION, 1, 0, 0 ); + + pShaderShadow->SetVertexShader( "Downsample_vs11", 0 ); + pShaderShadow->SetPixelShader( "Downsample_nohdr_ps11" ); + } + + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER0, BASETEXTURE, -1 ); + BindTexture( SHADER_SAMPLER1, BASETEXTURE, -1 ); + BindTexture( SHADER_SAMPLER2, BASETEXTURE, -1 ); + BindTexture( SHADER_SAMPLER3, BASETEXTURE, -1 ); + + int width, height; + pShaderAPI->GetBackBufferDimensions( width, height ); + + float v[4][4]; + float dX = 1.0f/width; + float dY = 1.0f/height; + + v[0][0] = .5*dX; + v[0][1] = .5*dY; + v[1][0] = 2.5*dX; + v[1][1] = .5*dY; + v[2][0] = .5*dX; + v[2][1] = 2.5*dY; + v[3][0] = 2.5*dX; + v[3][1] = 2.5*dY; + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, &v[0][0], 4 ); + + pShaderAPI->SetVertexShaderIndex( 0 ); + pShaderAPI->SetPixelShaderIndex( 0 ); + } + Draw(); + } +END_SHADER diff --git a/materialsystem/stdshaders/dx8fallbacks.cpp b/materialsystem/stdshaders/dx8fallbacks.cpp new file mode 100644 index 0000000..9558987 --- /dev/null +++ b/materialsystem/stdshaders/dx8fallbacks.cpp @@ -0,0 +1,14 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +#include "BaseVSShader.h" + +// This one isn't supported on dx8 +DEFINE_FALLBACK_SHADER( DepthWrite, Wireframe ) + +DEFINE_FALLBACK_SHADER( EyeRefract, Eyes_dx8 ) +DEFINE_FALLBACK_SHADER( bik, bik_dx81 ) +DEFINE_FALLBACK_SHADER( VolumeClouds, UnlitGeneric_DX8 ) +DEFINE_FALLBACK_SHADER( DebugTextureView, UnlitGeneric_DX8 ) + +// FIXME: These aren't supported on dx8, but need to be. +DEFINE_FALLBACK_SHADER( EyeGlint, Wireframe ) +DEFINE_FALLBACK_SHADER( AfterShock, Wireframe ) diff --git a/materialsystem/stdshaders/emissive_scroll_blended_pass_dx8_helper.cpp b/materialsystem/stdshaders/emissive_scroll_blended_pass_dx8_helper.cpp new file mode 100644 index 0000000..3e78d7f --- /dev/null +++ b/materialsystem/stdshaders/emissive_scroll_blended_pass_dx8_helper.cpp @@ -0,0 +1,201 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// + +/* Example how to plug this into an existing shader: + + In the VMT: + // Emissive Scroll Pass + "$emissiveBlendEnabled" "1" // Enables effect + "$emissiveBlendTexture" "models/vortigaunt/vortigaunt_illum" + "$emissiveBlendBaseTexture" "Models/Vortigaunt/vortigaunt_blue" + "$emissiveBlendFlowTexture" "models/vortigaunt/vortigaunt_flow" + "$emissiveBlendTint" "[10 10 10]" + "$emissiveBlendStrength" "1.0" // Set by game code + "$emissiveBlendScrollVector" "[0.11 0.124]" + "Proxies" + { + "VortEmissive" // For setting $selfillumstrength + { + } + } + + #include "emissive_scroll_blended_pass_helper.h" + + In BEGIN_SHADER_PARAMS: + // Emissive Scroll Pass + SHADER_PARAM( EMISSIVEBLENDENABLED, SHADER_PARAM_TYPE_BOOL, "0", "Enable emissive blend pass" ) + SHADER_PARAM( EMISSIVEBLENDBASETEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "self-illumination map" ) + SHADER_PARAM( EMISSIVEBLENDSCROLLVECTOR, SHADER_PARAM_TYPE_VEC2, "[0.11 0.124]", "Emissive scroll vec" ) + SHADER_PARAM( EMISSIVEBLENDSTRENGTH, SHADER_PARAM_TYPE_FLOAT, "1.0", "Emissive blend strength" ) + SHADER_PARAM( EMISSIVEBLENDTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "self-illumination map" ) + SHADER_PARAM( EMISSIVEBLENDTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "Self-illumination tint" ) + + Add this above SHADER_INIT_PARAMS() + // Emissive Scroll Pass + void SetupVarsEmissiveScrollBlendedPass( EmissiveScrollBlendedPassVars_t &info ) + { + info.m_nBlendStrength = EMISSIVEBLENDSTRENGTH; + info.m_nBaseTexture = EMISSIVEBLENDBASETEXTURE; + info.m_nFlowTexture = -1; // Not used in DX8 + info.m_nEmissiveTexture = EMISSIVEBLENDTEXTURE; + info.m_nEmissiveTint = EMISSIVEBLENDTINT; + info.m_nEmissiveScrollVector = EMISSIVEBLENDSCROLLVECTOR; + } + + In SHADER_INIT_PARAMS() + // Emissive Scroll Pass + if ( !params[EMISSIVEBLENDENABLED]->IsDefined() ) + { + params[EMISSIVEBLENDENABLED]->SetIntValue( 0 ); + } + else if ( params[EMISSIVEBLENDENABLED]->GetIntValue() ) + { + EmissiveScrollBlendedPassVars_t info; + SetupVarsEmissiveScrollBlendedPass( info ); + InitParamsEmissiveScrollBlendedPass( this, params, pMaterialName, info ); + } + + In SHADER_INIT + // Emissive Scroll Pass + if ( params[EMISSIVEBLENDENABLED]->GetIntValue() ) + { + EmissiveScrollBlendedPassVars_t info; + SetupVarsEmissiveScrollBlendedPass( info ); + InitEmissiveScrollBlendedPass( this, params, info ); + } + + At the very end of SHADER_DRAW + // Emissive Scroll Pass + if ( params[EMISSIVEBLENDENABLED]->GetIntValue() ) + { + // If ( snapshotting ) or ( we need to draw this frame ) + if ( ( pShaderShadow != NULL ) || ( params[EMISSIVEBLENDSTRENGTH]->GetFloatValue() > 0.0f ) ) + { + EmissiveScrollBlendedPassVars_t info; + SetupVarsEmissiveScrollBlendedPass( info ); + DrawEmissiveScrollBlendedPass( this, params, pShaderAPI, pShaderShadow, info ); + } + else // We're not snapshotting and we don't need to draw this frame + { + // Skip this pass! + Draw( false ); + } + } + +==================================================================================================== */ + +#include "BaseVSShader.h" +#include "mathlib/vmatrix.h" +#include "emissive_scroll_blended_pass_helper.h" +#include "convar.h" + +// Auto generated inc files +#include "emissive_scroll_blended_pass_dx8_vs11.inc" + +void InitParamsEmissiveScrollBlendedPass( CBaseVSShader *pShader, IMaterialVar** params, const char *pMaterialName, EmissiveScrollBlendedPassVars_t &info ) +{ + SET_FLAGS2( MATERIAL_VAR2_SUPPORTS_HW_SKINNING ); + + if ( ( info.m_nEmissiveScrollVector >= 0 ) && ( !params[info.m_nEmissiveScrollVector]->IsDefined() ) ) + { + params[info.m_nEmissiveScrollVector]->SetVecValue( kDefaultEmissiveScrollVector, 4 ); + } + + if ( ( info.m_nBlendStrength >= 0 ) && ( !params[info.m_nBlendStrength]->IsDefined() ) ) + { + params[info.m_nBlendStrength]->SetFloatValue( kDefaultEmissiveBlendStrength ); + } + + if ( ( info.m_nEmissiveTint >= 0 ) && ( !params[info.m_nEmissiveTint]->IsDefined() ) ) + { + params[info.m_nEmissiveTint]->SetVecValue( kDefaultEmissiveTint, 4 ); + } + + SET_PARAM_FLOAT_IF_NOT_DEFINED( info.m_nTime, 0.0f ); +} + +void InitEmissiveScrollBlendedPass( CBaseVSShader *pShader, IMaterialVar** params, EmissiveScrollBlendedPassVars_t &info ) +{ + // Load textures + pShader->LoadTexture( info.m_nBaseTexture ); + pShader->LoadTexture( info.m_nEmissiveTexture ); +} + +void DrawEmissiveScrollBlendedPass( CBaseVSShader *pShader, IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, + IShaderShadow* pShaderShadow, EmissiveScrollBlendedPassVars_t &info, VertexCompressionType_t vertexCompression ) +{ + SHADOW_STATE + { + // Reset shadow state manually since we're drawing from two materials + pShader->SetInitialShadowState(); + + // Set stream format + pShaderShadow->VertexShaderVertexFormat( VERTEX_POSITION | VERTEX_NORMAL, 1, 0, 0 ); + + // Vertex Shader + emissive_scroll_blended_pass_dx8_vs11_Static_Index vshIndex; + pShaderShadow->SetVertexShader( "emissive_scroll_blended_pass_dx8_vs11", vshIndex.GetIndex() ); + + // Pixel Shader + pShaderShadow->SetPixelShader( "emissive_scroll_blended_pass_dx8_ps11", 0 ); + + // Textures + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER2, true ); + + // Blending + pShader->EnableAlphaBlending( SHADER_BLEND_ONE, SHADER_BLEND_ONE ); + pShaderShadow->EnableAlphaWrites( false ); + } + DYNAMIC_STATE + { + // Reset render state manually since we're drawing from two materials + pShaderAPI->SetDefaultState(); + + // Set Vertex Shader Combos + emissive_scroll_blended_pass_dx8_vs11_Dynamic_Index vshIndex; + vshIndex.SetSKINNING( pShaderAPI->GetCurrentNumBones() > 0 ); + pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() ); + + // Set Vertex Shader Constants + pShader->SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, BASETEXTURETRANSFORM ); + + float vEmissiveScrollVector[4] = { kDefaultEmissiveScrollVector[0], kDefaultEmissiveScrollVector[1], 0.0f, 0.0f }; + if ( IS_PARAM_DEFINED( info.m_nEmissiveScrollVector ) ) + { + const float *flPtr = params[info.m_nEmissiveScrollVector]->GetVecValue(); + if ( flPtr != NULL ) + { + vEmissiveScrollVector[0] = flPtr[0]; + vEmissiveScrollVector[1] = flPtr[1]; + } + } + + float curTime = IS_PARAM_DEFINED( info.m_nTime ) && params[info.m_nTime]->GetFloatValue() > 0.0f ? params[info.m_nTime]->GetFloatValue() : pShaderAPI->CurrentTime(); + float selfIllumScroll[4] = { vEmissiveScrollVector[0] * curTime, vEmissiveScrollVector[1] * curTime, 0.0f, 0.0f }; + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_4, selfIllumScroll, 1 ); + + // Set Pixel Shader Combos + /* None */ + + // Bind textures + pShader->BindTexture( SHADER_SAMPLER0, info.m_nBaseTexture ); + pShader->BindTexture( SHADER_SAMPLER1, info.m_nEmissiveTexture ); + + // Set Pixel Shader Constants (Copied from vortwarp code) + pShader->SetModulationPixelShaderDynamicState( 3 ); + pShader->EnablePixelShaderOverbright( 0, true, true ); + + pShaderAPI->SetPixelShaderConstant( 1, IS_PARAM_DEFINED( info.m_nEmissiveTint ) ? params[info.m_nEmissiveTint]->GetVecValue() : kDefaultEmissiveTint, 1 ); + + float c4[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; // NOTE: w is written to dest alpha + c4[0] = IS_PARAM_DEFINED( info.m_nBlendStrength ) ? params[info.m_nBlendStrength]->GetFloatValue() : kDefaultEmissiveBlendStrength; + c4[1] = c4[0]; + c4[2] = c4[0]; + pShaderAPI->SetPixelShaderConstant( 4, c4, 1 ); + + float c5[4] = { 1.0f, 1.0f, 1.0f, 1.0f }; + pShaderAPI->SetPixelShaderConstant( 5, c5, 1 ); + } + pShader->Draw(); +} diff --git a/materialsystem/stdshaders/emissive_scroll_blended_pass_dx8_ps11.psh b/materialsystem/stdshaders/emissive_scroll_blended_pass_dx8_ps11.psh new file mode 100644 index 0000000..c0dfcb0 --- /dev/null +++ b/materialsystem/stdshaders/emissive_scroll_blended_pass_dx8_ps11.psh @@ -0,0 +1,20 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; c0 EnablePixelShaderOverbright() +; c1 SELFILLUMTINT +; c2 ? +; c3 ComputeModulationColor() +; c4 flEmissiveBlendStrength, flEmissiveBlendStrength, flEmissiveBlendStrength, bWarping +; c5 1, 1, 1, 1 +;------------------------------------------------------------------------------ + +tex t0 ; Base color +tex t1 ; Emissive texture + +mul_sat t1, c1, t1 ; Emissive texture * selfIllumTint +mul r0, t0, c3 ; Base color +mul r0.rgb, t1, r0 ; Base * emissive +mul r0.rgb, r0, c4 ; * flEmissiveBlendStrength +mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2) +mov r0.a, c4.a ; Should this be 0 for the refract effect? diff --git a/materialsystem/stdshaders/emissive_scroll_blended_pass_dx8_vs11.vsh b/materialsystem/stdshaders/emissive_scroll_blended_pass_dx8_vs11.vsh new file mode 100644 index 0000000..2d3e7fa --- /dev/null +++ b/materialsystem/stdshaders/emissive_scroll_blended_pass_dx8_vs11.vsh @@ -0,0 +1,61 @@ +# DYNAMIC: "SKINNING" "0..1" + +vs.1.1 +#include "macros.vsh" + +;------------------------------------------------------------------------------ +; Vertex blending +;------------------------------------------------------------------------------ +&AllocateRegister( \$worldPos ); +&AllocateRegister( \$worldNormal ); +&AllocateRegister( \$projPos ); + +&SkinPositionAndNormal( $worldPos, $worldNormal ); + +if( $SKINNING == 1 ) +{ + &Normalize( $worldNormal ); +} + +;------------------------------------------------------------------------------ +; Transform the position from world to view space +;------------------------------------------------------------------------------ +dp4 $projPos.x, $worldPos, $cViewProj0 +dp4 $projPos.y, $worldPos, $cViewProj1 +dp4 $projPos.z, $worldPos, $cViewProj2 +dp4 $projPos.w, $worldPos, $cViewProj3 + +mov oPos, $projPos + +;------------------------------------------------------------------------------ +; Fog - don't bother with water fog for intro effects +;------------------------------------------------------------------------------ +&DepthFog( $projPos, "oFog" ); +&FreeRegister( \$projPos ); + +;------------------------------------------------------------------------------ +; Lighting +;------------------------------------------------------------------------------ +mov oD0, $cHalf + +;------------------------------------------------------------------------------ +; Texture coordinates +;------------------------------------------------------------------------------ + +dp4 oT0.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_0 +dp4 oT0.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_1 + +alloc $tmp2 + +dp4 $tmp2.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_0 +dp4 $tmp2.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_1 + +add oT1.xy, $tmp2, $SHADER_SPECIFIC_CONST_4 + +free $tmp2 + +; YUCK! This is to make texcoords continuous for mat_softwaretl +mov oT2, $cZero + +&FreeRegister( \$worldPos ); +&FreeRegister( \$worldNormal ); diff --git a/materialsystem/stdshaders/emissive_scroll_blended_pass_helper.cpp b/materialsystem/stdshaders/emissive_scroll_blended_pass_helper.cpp new file mode 100644 index 0000000..d1bd5ff --- /dev/null +++ b/materialsystem/stdshaders/emissive_scroll_blended_pass_helper.cpp @@ -0,0 +1,278 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// + +/* Example how to plug this into an existing shader: + + In the VMT: + // Emissive Scroll Pass + "$emissiveBlendEnabled" "1" // Enables effect + "$emissiveBlendTexture" "models/vortigaunt/vortigaunt_illum" + "$emissiveBlendBaseTexture" "Models/Vortigaunt/vortigaunt_blue" + "$emissiveBlendFlowTexture" "models/vortigaunt/vortigaunt_flow" + "$emissiveBlendTint" "[10 10 10]" + "$emissiveBlendStrength" "1.0" // Set by game code + "$emissiveBlendScrollVector" "[0.11 0.124]" + "Proxies" + { + "VortEmissive" // For setting $selfillumstrength + { + } + } + + #include "emissive_scroll_blended_pass_helper.h" + + In BEGIN_SHADER_PARAMS: + // Emissive Scroll Pass + SHADER_PARAM( EMISSIVEBLENDENABLED, SHADER_PARAM_TYPE_BOOL, "0", "Enable emissive blend pass" ) + SHADER_PARAM( EMISSIVEBLENDBASETEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "self-illumination map" ) + SHADER_PARAM( EMISSIVEBLENDSCROLLVECTOR, SHADER_PARAM_TYPE_VEC2, "[0.11 0.124]", "Emissive scroll vec" ) + SHADER_PARAM( EMISSIVEBLENDSTRENGTH, SHADER_PARAM_TYPE_FLOAT, "1.0", "Emissive blend strength" ) + SHADER_PARAM( EMISSIVEBLENDTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "self-illumination map" ) + SHADER_PARAM( EMISSIVEBLENDTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "Self-illumination tint" ) + SHADER_PARAM( EMISSIVEBLENDFLOWTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "flow map" ) + + Add this above SHADER_INIT_PARAMS() + // Emissive Scroll Pass + void SetupVarsEmissiveScrollBlendedPass( EmissiveScrollBlendedPassVars_t &info ) + { + info.m_nBlendStrength = EMISSIVEBLENDSTRENGTH; + info.m_nBaseTexture = EMISSIVEBLENDBASETEXTURE; + info.m_nFlowTexture = EMISSIVEBLENDFLOWTEXTURE; + info.m_nEmissiveTexture = EMISSIVEBLENDTEXTURE; + info.m_nEmissiveTint = EMISSIVEBLENDTINT; + info.m_nEmissiveScrollVector = EMISSIVEBLENDSCROLLVECTOR; + } + + In SHADER_INIT_PARAMS() + // Emissive Scroll Pass + if ( !params[EMISSIVEBLENDENABLED]->IsDefined() ) + { + params[EMISSIVEBLENDENABLED]->SetIntValue( 0 ); + } + else if ( params[EMISSIVEBLENDENABLED]->GetIntValue() ) + { + EmissiveScrollBlendedPassVars_t info; + SetupVarsEmissiveScrollBlendedPass( info ); + InitParamsEmissiveScrollBlendedPass( this, params, pMaterialName, info ); + } + + In SHADER_INIT + // Emissive Scroll Pass + if ( params[EMISSIVEBLENDENABLED]->GetIntValue() ) + { + EmissiveScrollBlendedPassVars_t info; + SetupVarsEmissiveScrollBlendedPass( info ); + InitEmissiveScrollBlendedPass( this, params, info ); + } + + At the very end of SHADER_DRAW + // Emissive Scroll Pass + if ( params[EMISSIVEBLENDENABLED]->GetIntValue() ) + { + // If ( snapshotting ) or ( we need to draw this frame ) + if ( ( pShaderShadow != NULL ) || ( params[EMISSIVEBLENDSTRENGTH]->GetFloatValue() > 0.0f ) ) + { + EmissiveScrollBlendedPassVars_t info; + SetupVarsEmissiveScrollBlendedPass( info ); + DrawEmissiveScrollBlendedPass( this, params, pShaderAPI, pShaderShadow, info ); + } + else // We're not snapshotting and we don't need to draw this frame + { + // Skip this pass! + Draw( false ); + } + } + +==================================================================================================== */ + +#include "BaseVSShader.h" +#include "mathlib/vmatrix.h" +#include "emissive_scroll_blended_pass_helper.h" +#include "convar.h" + +// Auto generated inc files +#include "emissive_scroll_blended_pass_vs20.inc" +#include "emissive_scroll_blended_pass_ps20.inc" +#include "emissive_scroll_blended_pass_ps20b.inc" + +#ifndef _X360 +#include "emissive_scroll_blended_pass_vs30.inc" +#include "emissive_scroll_blended_pass_ps30.inc" +#endif + +void InitParamsEmissiveScrollBlendedPass( CBaseVSShader *pShader, IMaterialVar** params, const char *pMaterialName, EmissiveScrollBlendedPassVars_t &info ) +{ + SET_FLAGS2( MATERIAL_VAR2_SUPPORTS_HW_SKINNING ); + + if ( ( info.m_nEmissiveScrollVector != -1 ) && ( !params[info.m_nEmissiveScrollVector]->IsDefined() ) ) + { + params[info.m_nEmissiveScrollVector]->SetVecValue( kDefaultEmissiveScrollVector, 4 ); + } + + if ( ( info.m_nBlendStrength != -1 ) && ( !params[info.m_nBlendStrength]->IsDefined() ) ) + { + params[info.m_nBlendStrength]->SetFloatValue( kDefaultEmissiveBlendStrength ); + } + + if ( ( info.m_nEmissiveTint != -1 ) && ( !params[info.m_nEmissiveTint]->IsDefined() ) ) + { + params[info.m_nEmissiveTint]->SetVecValue( kDefaultEmissiveTint, 4 ); + } + + SET_PARAM_FLOAT_IF_NOT_DEFINED( info.m_nTime, 0.0f ); +} + +void InitEmissiveScrollBlendedPass( CBaseVSShader *pShader, IMaterialVar** params, EmissiveScrollBlendedPassVars_t &info ) +{ + // Load textures + pShader->LoadTexture( info.m_nBaseTexture, TEXTUREFLAGS_SRGB ); + pShader->LoadTexture( info.m_nFlowTexture ); + pShader->LoadTexture( info.m_nEmissiveTexture, TEXTUREFLAGS_SRGB ); +} + +void DrawEmissiveScrollBlendedPass( CBaseVSShader *pShader, IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, + IShaderShadow* pShaderShadow, EmissiveScrollBlendedPassVars_t &info, VertexCompressionType_t vertexCompression ) +{ + SHADOW_STATE + { + // Reset shadow state manually since we're drawing from two materials + pShader->SetInitialShadowState(); + + // Set stream format (note that this shader supports compression) + unsigned int flags = VERTEX_POSITION | VERTEX_NORMAL | VERTEX_FORMAT_COMPRESSED; + int nTexCoordCount = 1; + int userDataSize = 0; + pShaderShadow->VertexShaderVertexFormat( flags, nTexCoordCount, NULL, userDataSize ); + +#ifndef _X360 + if ( !g_pHardwareConfig->HasFastVertexTextures() ) +#endif + { + // Vertex Shader + DECLARE_STATIC_VERTEX_SHADER( emissive_scroll_blended_pass_vs20 ); + SET_STATIC_VERTEX_SHADER( emissive_scroll_blended_pass_vs20 ); + + // Pixel Shader + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_STATIC_PIXEL_SHADER( emissive_scroll_blended_pass_ps20b ); + SET_STATIC_PIXEL_SHADER( emissive_scroll_blended_pass_ps20b ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( emissive_scroll_blended_pass_ps20 ); + SET_STATIC_PIXEL_SHADER( emissive_scroll_blended_pass_ps20 ); + } + } +#ifndef _X360 + else + { + // The vertex shader uses the vertex id stream + SET_FLAGS2( MATERIAL_VAR2_USES_VERTEXID ); + + DECLARE_STATIC_VERTEX_SHADER( emissive_scroll_blended_pass_vs30 ); + SET_STATIC_VERTEX_SHADER( emissive_scroll_blended_pass_vs30 ); + + DECLARE_STATIC_PIXEL_SHADER( emissive_scroll_blended_pass_ps30 ); + SET_STATIC_PIXEL_SHADER( emissive_scroll_blended_pass_ps30 ); + } +#endif + + // Textures + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER1, false ); // Flow texture not sRGB + pShaderShadow->EnableTexture( SHADER_SAMPLER2, true ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER2, true ); + pShaderShadow->EnableSRGBWrite( true ); + + // Blending + pShader->EnableAlphaBlending( SHADER_BLEND_ONE, SHADER_BLEND_ONE ); + pShaderShadow->EnableAlphaWrites( false ); + } + DYNAMIC_STATE + { + // Reset render state manually since we're drawing from two materials + pShaderAPI->SetDefaultState(); + +#ifndef _X360 + if ( !g_pHardwareConfig->HasFastVertexTextures() ) +#endif + { + // Set Vertex Shader Combos + DECLARE_DYNAMIC_VERTEX_SHADER( emissive_scroll_blended_pass_vs20 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, pShaderAPI->GetCurrentNumBones() > 0 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression ); + SET_DYNAMIC_VERTEX_SHADER( emissive_scroll_blended_pass_vs20 ); + + // Set Vertex Shader Constants + // None? + + // Set Pixel Shader Combos + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_DYNAMIC_PIXEL_SHADER( emissive_scroll_blended_pass_ps20b ); + SET_DYNAMIC_PIXEL_SHADER( emissive_scroll_blended_pass_ps20b ); + } + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( emissive_scroll_blended_pass_ps20 ); + SET_DYNAMIC_PIXEL_SHADER( emissive_scroll_blended_pass_ps20 ); + } + } +#ifndef _X360 + else + { + pShader->SetHWMorphVertexShaderState( VERTEX_SHADER_SHADER_SPECIFIC_CONST_6, VERTEX_SHADER_SHADER_SPECIFIC_CONST_7, SHADER_VERTEXTEXTURE_SAMPLER0 ); + + // Set Vertex Shader Combos + DECLARE_DYNAMIC_VERTEX_SHADER( emissive_scroll_blended_pass_vs30 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, pShaderAPI->GetCurrentNumBones() > 0 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( MORPHING, pShaderAPI->IsHWMorphingEnabled() ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression ); + SET_DYNAMIC_VERTEX_SHADER( emissive_scroll_blended_pass_vs30 ); + + DECLARE_DYNAMIC_PIXEL_SHADER( emissive_scroll_blended_pass_ps30 ); + SET_DYNAMIC_PIXEL_SHADER( emissive_scroll_blended_pass_ps30 ); + } +#endif + + // Bind textures + pShader->BindTexture( SHADER_SAMPLER0, info.m_nBaseTexture ); + pShader->BindTexture( SHADER_SAMPLER1, info.m_nFlowTexture ); + pShader->BindTexture( SHADER_SAMPLER2, info.m_nEmissiveTexture ); + + // Set Pixel Shader Constants + //float vConstZero[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; + + // This brings in the electricity and the second base texture when the second base texture is present + float vPsConst0[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; + if (1) + { + // Overall blend strength + vPsConst0[0] = IS_PARAM_DEFINED( info.m_nBlendStrength ) ? params[info.m_nBlendStrength]->GetFloatValue() : kDefaultEmissiveBlendStrength; + if ( vPsConst0[0] < 0.0f ) + vPsConst0[0] = 0.0f; + if ( vPsConst0[0] > 1.0f ) + vPsConst0[0] = 1.0f; + + // Time % 1000 for scrolling + vPsConst0[1] = IS_PARAM_DEFINED( info.m_nTime ) && params[info.m_nTime]->GetFloatValue() > 0.0f ? params[info.m_nTime]->GetFloatValue() : pShaderAPI->CurrentTime(); + vPsConst0[1] -= (float)( (int)( vPsConst0[1] / 1000.0f ) ) * 1000.0f; + + // Dest alpha value for warping mask - NOTE: If we want to use this, we have to modify the blending mode above! + //if ( ( params[info.m_nWarpParam]->GetFloatValue() > 0.0f ) && ( params[info.m_nWarpParam]->GetFloatValue() < 1.0f ) ) + // tmpVec[2] = 1.0f; + //else + // tmpVec[2] = 0.0f; + } + pShaderAPI->SetPixelShaderConstant( 0, vPsConst0, 1 ); + + // Scroll vector + pShaderAPI->SetPixelShaderConstant( 1, IS_PARAM_DEFINED( info.m_nEmissiveScrollVector ) ? params[info.m_nEmissiveScrollVector]->GetVecValue() : kDefaultEmissiveScrollVector, 1 ); + + // Self illum tint + pShaderAPI->SetPixelShaderConstant( 2, IS_PARAM_DEFINED( info.m_nEmissiveTint ) ? params[info.m_nEmissiveTint]->GetVecValue() : kDefaultEmissiveTint, 1 ); + } + pShader->Draw(); +} diff --git a/materialsystem/stdshaders/emissive_scroll_blended_pass_helper.h b/materialsystem/stdshaders/emissive_scroll_blended_pass_helper.h new file mode 100644 index 0000000..a8fdd03 --- /dev/null +++ b/materialsystem/stdshaders/emissive_scroll_blended_pass_helper.h @@ -0,0 +1,45 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// + +#ifndef EMISSIVE_SCROLL_BLENDED_PASS_HELPER_H +#define EMISSIVE_SCROLL_BLENDED_PASS_HELPER_H +#ifdef _WIN32 +#pragma once +#endif + +#include + +//----------------------------------------------------------------------------- +// Forward declarations +//----------------------------------------------------------------------------- +class CBaseVSShader; +class IMaterialVar; +class IShaderDynamicAPI; +class IShaderShadow; + +//----------------------------------------------------------------------------- +// Init params/ init/ draw methods +//----------------------------------------------------------------------------- +struct EmissiveScrollBlendedPassVars_t +{ + EmissiveScrollBlendedPassVars_t() { memset( this, 0xFF, sizeof(EmissiveScrollBlendedPassVars_t) ); } + + int m_nBlendStrength; // Amount this layer is blended in globally + int m_nBaseTexture; + int m_nFlowTexture; + int m_nEmissiveTexture; + int m_nEmissiveTint; + int m_nEmissiveScrollVector; + int m_nTime; +}; + +// Default values (Arrays should only be vec[4]) +static const float kDefaultEmissiveBlendStrength = 0.0f; +static const float kDefaultEmissiveTint[4] = { 1.0f, 1.0f, 1.0f, 0.0f } ; +static const float kDefaultEmissiveScrollVector[4] = { 0.11f, 0.124f, 0.0f, 0.0f } ; + +void InitParamsEmissiveScrollBlendedPass( CBaseVSShader *pShader, IMaterialVar** params, const char *pMaterialName, EmissiveScrollBlendedPassVars_t &info ); +void InitEmissiveScrollBlendedPass( CBaseVSShader *pShader, IMaterialVar** params, EmissiveScrollBlendedPassVars_t &info ); +void DrawEmissiveScrollBlendedPass( CBaseVSShader *pShader, IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, + IShaderShadow* pShaderShadow, EmissiveScrollBlendedPassVars_t &info, VertexCompressionType_t vertexCompression ); + +#endif // EMISSIVE_SCROLL_BLENDED_PASS_HELPER_H diff --git a/materialsystem/stdshaders/emissive_scroll_blended_pass_ps2x.fxc b/materialsystem/stdshaders/emissive_scroll_blended_pass_ps2x.fxc new file mode 100644 index 0000000..0a0c6fd --- /dev/null +++ b/materialsystem/stdshaders/emissive_scroll_blended_pass_ps2x.fxc @@ -0,0 +1,51 @@ +//========= Copyright © 1996-2006, Valve Corporation, All rights reserved. ============// + +// Includes ======================================================================================= +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps30][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX] +#include "common_vertexlitgeneric_dx9.h" + +// Texture Samplers =============================================================================== +sampler g_tBaseSampler : register( s0 ); +sampler g_tFlowSampler : register( s1 ); +sampler g_tSelfIllumSampler : register( s2 ); + +// Shaders Constants and Globals ================================================================== +const float4 g_vPackedConst0 : register( c0 ); +#define g_flBlendStrength g_vPackedConst0.x +#define g_flTime g_vPackedConst0.y + +const float2 g_vEmissiveScrollVector : register( c1 ); +const float3 g_cSelfIllumTint : register( c2 ); + +// Interpolated values ============================================================================ +struct PS_INPUT +{ + float2 vTexCoord0 : TEXCOORD0; +}; + +// Main =========================================================================================== +//float4 main( PS_INPUT i ) : COLOR // Non-HDR for debugging +float4 main( PS_INPUT i ) : COLOR +{ + // Color texture + float4 cBaseColor = tex2D( g_tBaseSampler, i.vTexCoord0.xy ); + + // Fetch from dudv map and then fetch from emissive texture with new uv's & scroll + float4 vFlowValue = tex2D( g_tFlowSampler, i.vTexCoord0.xy ); + float2 vEmissiveTexCoord = vFlowValue.xy + ( g_vEmissiveScrollVector.xy * g_flTime ); + float4 cEmissiveColor = tex2D( g_tSelfIllumSampler, vEmissiveTexCoord.xy ); + + //===============// + // Combine terms // + //===============// + float4 result; + result.rgb = cBaseColor.rgb * cEmissiveColor.rgb * g_cSelfIllumTint.rgb; + result.rgb *= g_flBlendStrength; + + // Set alpha to 0.0f so it doesn't change dest alpha (I should probably disable dest alpha writes) + result.a = 0.0f; + + return FinalOutput( result, 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_LINEAR ); +} diff --git a/materialsystem/stdshaders/emissive_scroll_blended_pass_vs20.fxc b/materialsystem/stdshaders/emissive_scroll_blended_pass_vs20.fxc new file mode 100644 index 0000000..6c28dd2 --- /dev/null +++ b/materialsystem/stdshaders/emissive_scroll_blended_pass_vs20.fxc @@ -0,0 +1,68 @@ +//========= Copyright © 1996-2006, Valve Corporation, All rights reserved. ============// + +// DYNAMIC: "COMPRESSED_VERTS" "0..1" +// DYNAMIC: "SKINNING" "0..1" +// DYNAMIC: "MORPHING" "0..1" [vs30] + +// Includes +#include "common_vs_fxc.h" + +// Globals +static const bool g_bSkinning = SKINNING ? true : false; + +#ifdef SHADER_MODEL_VS_3_0 +// NOTE: cMorphTargetTextureDim.xy = target dimensions, +// cMorphTargetTextureDim.z = 4tuples/morph +const float3 cMorphTargetTextureDim : register( SHADER_SPECIFIC_CONST_6 ); +const float4 cMorphSubrect : register( SHADER_SPECIFIC_CONST_7 ); + +sampler2D morphSampler : register( D3DVERTEXTEXTURESAMPLER0, s0 ); +#endif + +// Structs +struct VS_INPUT +{ + float4 vPos : POSITION; // Position + float4 vBoneWeights : BLENDWEIGHT; // Skin weights + float4 vBoneIndices : BLENDINDICES; // Skin indices + float4 vTexCoord0 : TEXCOORD0; // Base texture coordinates + + float3 vPosFlex : POSITION1; // Delta positions for flexing + +#ifdef SHADER_MODEL_VS_3_0 + float vVertexID : POSITION2; +#endif +}; + +struct VS_OUTPUT +{ + float4 vProjPosition : POSITION; // Projection-space position + float2 vTexCoord0 : TEXCOORD0; +}; + +// Main +VS_OUTPUT main( const VS_INPUT i ) +{ + VS_OUTPUT o; + + float4 vObjPosition = i.vPos; + +#if !defined( SHADER_MODEL_VS_3_0 ) || !MORPHING + ApplyMorph( i.vPosFlex, vObjPosition.xyz ); +#else + ApplyMorph( morphSampler, cMorphTargetTextureDim, cMorphSubrect, i.vVertexID, float3( 0, 0, 0 ), vObjPosition.xyz ); +#endif + + // Transform the position + float3 vWorldPosition = { 0.0f, 0.0f, 0.0f }; + SkinPosition( g_bSkinning, vObjPosition, i.vBoneWeights, i.vBoneIndices, vWorldPosition ); + + // Transform into projection space + float4 vProjPosition = mul( float4( vWorldPosition, 1.0f ), cViewProj ); + o.vProjPosition = vProjPosition; + + // Pass through tex coords + o.vTexCoord0.xy = i.vTexCoord0.xy; + + return o; +} diff --git a/materialsystem/stdshaders/example_model_dx9.cpp b/materialsystem/stdshaders/example_model_dx9.cpp new file mode 100644 index 0000000..12b6ee1 --- /dev/null +++ b/materialsystem/stdshaders/example_model_dx9.cpp @@ -0,0 +1,60 @@ +//===================== Copyright (c) Valve Corporation. All Rights Reserved. ====================== +// +// Example shader that can be applied to models +// +//================================================================================================== + +#include "BaseVSShader.h" +#include "convar.h" +#include "example_model_dx9_helper.h" + +#ifdef GAME_SHADER_DLL +DEFINE_FALLBACK_SHADER( Mod_Example_Model, Mod_Example_Model_DX9 ) +BEGIN_VS_SHADER( Mod_Example_Model_DX9, "Help for Example Model Shader" ) +#else +DEFINE_FALLBACK_SHADER( Example_Model, Example_Model_DX9 ) +BEGIN_VS_SHADER( Example_Model_DX9, "Help for Example Model Shader" ) +#endif + + BEGIN_SHADER_PARAMS + SHADER_PARAM( ALPHATESTREFERENCE, SHADER_PARAM_TYPE_FLOAT, "0.0", "" ) + END_SHADER_PARAMS + + void SetupVars( ExampleModel_DX9_Vars_t& info ) + { + info.m_nBaseTexture = BASETEXTURE; + info.m_nBaseTextureFrame = FRAME; + info.m_nBaseTextureTransform = BASETEXTURETRANSFORM; + info.m_nAlphaTestReference = ALPHATESTREFERENCE; + info.m_nFlashlightTexture = FLASHLIGHTTEXTURE; + info.m_nFlashlightTextureFrame = FLASHLIGHTTEXTUREFRAME; + } + + SHADER_INIT_PARAMS() + { + ExampleModel_DX9_Vars_t info; + SetupVars( info ); + InitParamsExampleModel_DX9( this, params, pMaterialName, info ); + } + + SHADER_FALLBACK + { + return 0; + } + + SHADER_INIT + { + ExampleModel_DX9_Vars_t info; + SetupVars( info ); + InitExampleModel_DX9( this, params, info ); + } + + SHADER_DRAW + { + ExampleModel_DX9_Vars_t info; + SetupVars( info ); + DrawExampleModel_DX9( this, params, pShaderAPI, pShaderShadow, info, vertexCompression, pContextDataPtr ); + } + +END_SHADER + diff --git a/materialsystem/stdshaders/example_model_dx9_helper.cpp b/materialsystem/stdshaders/example_model_dx9_helper.cpp new file mode 100644 index 0000000..fc6a720 --- /dev/null +++ b/materialsystem/stdshaders/example_model_dx9_helper.cpp @@ -0,0 +1,341 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +// +//===========================================================================// +#include "BaseVSShader.h" +#include "example_model_dx9_helper.h" +#include "convar.h" +#include "cpp_shader_constant_register_map.h" +#include "example_model_vs20.inc" +#include "example_model_ps20b.inc" +#include "commandbuilder.h" + + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +static ConVar mat_fullbright( "mat_fullbright", "0", FCVAR_CHEAT ); +static ConVar r_lightwarpidentity( "r_lightwarpidentity", "0", FCVAR_CHEAT ); +static ConVar r_rimlight( "r_rimlight", "1", FCVAR_NONE ); + +// Textures may be bound to the following samplers: +// SHADER_SAMPLER0 Base (Albedo) / Gloss in alpha +// SHADER_SAMPLER4 Flashlight Shadow Depth Map +// SHADER_SAMPLER5 Normalization cube map +// SHADER_SAMPLER6 Flashlight Cookie + + +//----------------------------------------------------------------------------- +// Initialize shader parameters +//----------------------------------------------------------------------------- +void InitParamsExampleModel_DX9( CBaseVSShader *pShader, IMaterialVar** params, const char *pMaterialName, ExampleModel_DX9_Vars_t &info ) +{ + // FLASHLIGHTFIXME: Do ShaderAPI::BindFlashlightTexture + Assert( info.m_nFlashlightTexture >= 0 ); + + if ( g_pHardwareConfig->SupportsBorderColor() ) + { + params[FLASHLIGHTTEXTURE]->SetStringValue( "effects/flashlight_border" ); + } + else + { + params[FLASHLIGHTTEXTURE]->SetStringValue( "effects/flashlight001" ); + } + + // This shader can be used with hw skinning + SET_FLAGS2( MATERIAL_VAR2_SUPPORTS_HW_SKINNING ); + SET_FLAGS2( MATERIAL_VAR2_LIGHTING_VERTEX_LIT ); +} + +//----------------------------------------------------------------------------- +// Initialize shader +//----------------------------------------------------------------------------- +void InitExampleModel_DX9( CBaseVSShader *pShader, IMaterialVar** params, ExampleModel_DX9_Vars_t &info ) +{ + Assert( info.m_nFlashlightTexture >= 0 ); + pShader->LoadTexture( info.m_nFlashlightTexture, TEXTUREFLAGS_SRGB ); + + bool bIsBaseTextureTranslucent = false; + if ( params[info.m_nBaseTexture]->IsDefined() ) + { + pShader->LoadTexture( info.m_nBaseTexture, TEXTUREFLAGS_SRGB ); + + if ( params[info.m_nBaseTexture]->GetTextureValue()->IsTranslucent() ) + { + bIsBaseTextureTranslucent = true; + } + } +} + +class CExampleModel_DX9_Context : public CBasePerMaterialContextData +{ +public: + CCommandBufferBuilder< CFixedCommandStorageBuffer< 800 > > m_SemiStaticCmdsOut; + bool m_bFastPath; + +}; + +//----------------------------------------------------------------------------- +// Draws the shader +//----------------------------------------------------------------------------- +void DrawExampleModel_DX9_Internal( CBaseVSShader *pShader, IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow, + bool bHasFlashlight, ExampleModel_DX9_Vars_t &info, VertexCompressionType_t vertexCompression, + CBasePerMaterialContextData **pContextDataPtr ) +{ + bool bHasBaseTexture = (info.m_nBaseTexture != -1) && params[info.m_nBaseTexture]->IsTexture(); + bool bIsAlphaTested = IS_FLAG_SET( MATERIAL_VAR_ALPHATEST ) != 0; + + BlendType_t nBlendType= pShader->EvaluateBlendRequirements( info.m_nBaseTexture, true ); + bool bFullyOpaque = ( nBlendType != BT_BLENDADD ) && ( nBlendType != BT_BLEND ) && !bIsAlphaTested && !bHasFlashlight; + + CExampleModel_DX9_Context *pContextData = reinterpret_cast< CExampleModel_DX9_Context *> ( *pContextDataPtr ); + if ( !pContextData ) + { + pContextData = new CExampleModel_DX9_Context; + *pContextDataPtr = pContextData; + } + + if( pShader->IsSnapshotting() ) + { + pShaderShadow->EnableAlphaTest( bIsAlphaTested ); + + if( info.m_nAlphaTestReference != -1 && params[info.m_nAlphaTestReference]->GetFloatValue() > 0.0f ) + { + pShaderShadow->AlphaFunc( SHADER_ALPHAFUNC_GEQUAL, params[info.m_nAlphaTestReference]->GetFloatValue() ); + } + + int nShadowFilterMode = 0; + if( bHasFlashlight ) + { + if (params[info.m_nBaseTexture]->IsTexture()) + { + pShader->SetAdditiveBlendingShadowState( info.m_nBaseTexture, true ); + } + + if( bIsAlphaTested ) + { + // disable alpha test and use the zfunc zequals since alpha isn't guaranteed to + // be the same on both the regular pass and the flashlight pass. + pShaderShadow->EnableAlphaTest( false ); + pShaderShadow->DepthFunc( SHADER_DEPTHFUNC_EQUAL ); + } + pShaderShadow->EnableBlending( true ); + pShaderShadow->EnableDepthWrites( false ); + + // Be sure not to write to dest alpha + pShaderShadow->EnableAlphaWrites( false ); + + nShadowFilterMode = g_pHardwareConfig->GetShadowFilterMode(); // Based upon vendor and device dependent formats + } + else // not flashlight pass + { + if (params[info.m_nBaseTexture]->IsTexture()) + { + pShader->SetDefaultBlendingShadowState( info.m_nBaseTexture, true ); + } + } + + unsigned int flags = VERTEX_POSITION | VERTEX_NORMAL; + int userDataSize = 0; + + // Always enable...will bind white if nothing specified... + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); // Base (albedo) map + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, true ); + + if( bHasFlashlight ) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER4, true ); // Shadow depth map + pShaderShadow->SetShadowDepthFiltering( SHADER_SAMPLER4 ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER4, false ); + pShaderShadow->EnableTexture( SHADER_SAMPLER5, true ); // Noise map + pShaderShadow->EnableTexture( SHADER_SAMPLER6, true ); // Flashlight cookie + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER6, true ); + userDataSize = 4; // tangent S + } + + // Always enable, since flat normal will be bound + pShaderShadow->EnableTexture( SHADER_SAMPLER3, true ); // Normal map + userDataSize = 4; // tangent S + pShaderShadow->EnableTexture( SHADER_SAMPLER5, true ); // Normalizing cube map + pShaderShadow->EnableSRGBWrite( true ); + + // texcoord0 : base texcoord, texcoord2 : decal hw morph delta + int pTexCoordDim[3] = { 2, 0, 3 }; + int nTexCoordCount = 1; + + // This shader supports compressed vertices, so OR in that flag: + flags |= VERTEX_FORMAT_COMPRESSED; + + pShaderShadow->VertexShaderVertexFormat( flags, nTexCoordCount, pTexCoordDim, userDataSize ); + + DECLARE_STATIC_VERTEX_SHADER( example_model_vs20 ); + SET_STATIC_VERTEX_SHADER( example_model_vs20 ); + + // Assume we're only going to get in here if we support 2b + DECLARE_STATIC_PIXEL_SHADER( example_model_ps20b ); + SET_STATIC_PIXEL_SHADER_COMBO( FLASHLIGHT, bHasFlashlight ); + SET_STATIC_PIXEL_SHADER_COMBO( FLASHLIGHTDEPTHFILTERMODE, nShadowFilterMode ); + SET_STATIC_PIXEL_SHADER_COMBO( CONVERT_TO_SRGB, 0 ); + SET_STATIC_PIXEL_SHADER( example_model_ps20b ); + + if( bHasFlashlight ) + { + pShader->FogToBlack(); + } + else + { + pShader->DefaultFog(); + } + + // HACK HACK HACK - enable alpha writes all the time so that we have them for underwater stuff + pShaderShadow->EnableAlphaWrites( bFullyOpaque ); + } + else // not snapshotting -- begin dynamic state + { + bool bLightingOnly = mat_fullbright.GetInt() == 2 && !IS_FLAG_SET( MATERIAL_VAR_NO_DEBUG_OVERRIDE ); + + if( bHasBaseTexture ) + { + pShader->BindTexture( SHADER_SAMPLER0, info.m_nBaseTexture, info.m_nBaseTextureFrame ); + } + else + { + pShaderAPI->BindStandardTexture( SHADER_SAMPLER0, TEXTURE_WHITE ); + } + + LightState_t lightState = { 0, false, false }; + bool bFlashlightShadows = false; + if( bHasFlashlight ) + { + Assert( info.m_nFlashlightTexture >= 0 && info.m_nFlashlightTextureFrame >= 0 ); + pShader->BindTexture( SHADER_SAMPLER6, info.m_nFlashlightTexture, info.m_nFlashlightTextureFrame ); + VMatrix worldToTexture; + ITexture *pFlashlightDepthTexture; + FlashlightState_t state = pShaderAPI->GetFlashlightStateEx( worldToTexture, &pFlashlightDepthTexture ); + bFlashlightShadows = state.m_bEnableShadows && ( pFlashlightDepthTexture != NULL ); + + SetFlashLightColorFromState( state, pShaderAPI, PSREG_FLASHLIGHT_COLOR ); + + if( pFlashlightDepthTexture && g_pConfig->ShadowDepthTexture() && state.m_bEnableShadows ) + { + pShader->BindTexture( SHADER_SAMPLER4, pFlashlightDepthTexture, 0 ); + pShaderAPI->BindStandardTexture( SHADER_SAMPLER5, TEXTURE_SHADOW_NOISE_2D ); + } + } + else // no flashlight + { + pShaderAPI->GetDX9LightState( &lightState ); + } + + MaterialFogMode_t fogType = pShaderAPI->GetSceneFogMode(); + int fogIndex = ( fogType == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ) ? 1 : 0; + int numBones = pShaderAPI->GetCurrentNumBones(); + + bool bWriteDepthToAlpha = false; + bool bWriteWaterFogToAlpha = false; + if( bFullyOpaque ) + { + bWriteDepthToAlpha = pShaderAPI->ShouldWriteDepthToDestAlpha(); + bWriteWaterFogToAlpha = (fogType == MATERIAL_FOG_LINEAR_BELOW_FOG_Z); + AssertMsg( !(bWriteDepthToAlpha && bWriteWaterFogToAlpha), "Can't write two values to alpha at the same time." ); + } + + DECLARE_DYNAMIC_VERTEX_SHADER( example_model_vs20 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( DOWATERFOG, fogIndex ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, numBones > 0 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( LIGHTING_PREVIEW, pShaderAPI->GetIntRenderingParameter(INT_RENDERPARM_ENABLE_FIXED_LIGHTING)!=0); + SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( NUM_LIGHTS, lightState.m_nNumLights ); + SET_DYNAMIC_VERTEX_SHADER( example_model_vs20 ); + + DECLARE_DYNAMIC_PIXEL_SHADER( example_model_ps20b ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( NUM_LIGHTS, lightState.m_nNumLights ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( WRITEWATERFOGTODESTALPHA, bWriteWaterFogToAlpha ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( WRITE_DEPTH_TO_DESTALPHA, bWriteDepthToAlpha ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( FLASHLIGHTSHADOWS, bFlashlightShadows ); + SET_DYNAMIC_PIXEL_SHADER( example_model_ps20b ); + + pShader->SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, info.m_nBaseTextureTransform ); + pShader->SetModulationPixelShaderDynamicState_LinearColorSpace( 1 ); + pShader->SetAmbientCubeDynamicStateVertexShader(); + + if( !bHasFlashlight ) + { + pShaderAPI->BindStandardTexture( SHADER_SAMPLER5, TEXTURE_NORMALIZATION_CUBEMAP_SIGNED ); + } + + pShaderAPI->SetPixelShaderStateAmbientLightCube( PSREG_AMBIENT_CUBE, !lightState.m_bAmbientLight ); // Force to black if not bAmbientLight + pShaderAPI->CommitPixelShaderLighting( PSREG_LIGHT_INFO_ARRAY ); + + // handle mat_fullbright 2 (diffuse lighting only) + if( bLightingOnly ) + { + pShaderAPI->BindStandardTexture( SHADER_SAMPLER0, TEXTURE_GREY ); + } + + pShaderAPI->SetPixelShaderFogParams( PSREG_FOG_PARAMS ); + + if( bHasFlashlight ) + { + VMatrix worldToTexture; + float atten[4], pos[4], tweaks[4]; + + const FlashlightState_t &flashlightState = pShaderAPI->GetFlashlightState( worldToTexture ); + SetFlashLightColorFromState( flashlightState, pShaderAPI, PSREG_FLASHLIGHT_COLOR ); + + pShader->BindTexture( SHADER_SAMPLER6, flashlightState.m_pSpotlightTexture, flashlightState.m_nSpotlightTextureFrame ); + + atten[0] = flashlightState.m_fConstantAtten; // Set the flashlight attenuation factors + atten[1] = flashlightState.m_fLinearAtten; + atten[2] = flashlightState.m_fQuadraticAtten; + atten[3] = flashlightState.m_FarZ; + pShaderAPI->SetPixelShaderConstant( PSREG_FLASHLIGHT_ATTENUATION, atten, 1 ); + + pos[0] = flashlightState.m_vecLightOrigin[0]; // Set the flashlight origin + pos[1] = flashlightState.m_vecLightOrigin[1]; + pos[2] = flashlightState.m_vecLightOrigin[2]; + pShaderAPI->SetPixelShaderConstant( PSREG_FLASHLIGHT_POSITION_RIM_BOOST, pos, 1 ); + + pShaderAPI->SetPixelShaderConstant( PSREG_FLASHLIGHT_TO_WORLD_TEXTURE, worldToTexture.Base(), 4 ); + + // Tweaks associated with a given flashlight + tweaks[0] = ShadowFilterFromState( flashlightState ); + tweaks[1] = ShadowAttenFromState( flashlightState ); + pShader->HashShadow2DJitter( flashlightState.m_flShadowJitterSeed, &tweaks[2], &tweaks[3] ); + pShaderAPI->SetPixelShaderConstant( PSREG_ENVMAP_TINT__SHADOW_TWEAKS, tweaks, 1 ); + + // Dimensions of screen, used for screen-space noise map sampling + float vScreenScale[4] = {1280.0f / 32.0f, 720.0f / 32.0f, 0, 0}; + int nWidth, nHeight; + pShaderAPI->GetBackBufferDimensions( nWidth, nHeight ); + vScreenScale[0] = (float) nWidth / 32.0f; + vScreenScale[1] = (float) nHeight / 32.0f; + pShaderAPI->SetPixelShaderConstant( PSREG_FLASHLIGHT_SCREEN_SCALE, vScreenScale, 1 ); + } + } + pShader->Draw(); +} + + +//----------------------------------------------------------------------------- +// Draws the shader +//----------------------------------------------------------------------------- +void DrawExampleModel_DX9( CBaseVSShader *pShader, IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow, + ExampleModel_DX9_Vars_t &info, VertexCompressionType_t vertexCompression, CBasePerMaterialContextData **pContextDataPtr ) + +{ + bool bHasFlashlight = pShader->UsingFlashlight( params ); + if ( bHasFlashlight ) + { + DrawExampleModel_DX9_Internal( pShader, params, pShaderAPI, pShaderShadow, false, info, vertexCompression, pContextDataPtr++ ); + if ( pShaderShadow ) + { + pShader->SetInitialShadowState( ); + } + } + DrawExampleModel_DX9_Internal( pShader, params, pShaderAPI, pShaderShadow, bHasFlashlight, info, vertexCompression, pContextDataPtr ); +} diff --git a/materialsystem/stdshaders/example_model_dx9_helper.h b/materialsystem/stdshaders/example_model_dx9_helper.h new file mode 100644 index 0000000..dfe2579 --- /dev/null +++ b/materialsystem/stdshaders/example_model_dx9_helper.h @@ -0,0 +1,46 @@ +//===================== Copyright (c) Valve Corporation. All Rights Reserved. ====================== +// +// Example shader that can be applied to models +// +//================================================================================================== + +#ifndef EXAMPLE_MODEL_DX9_HELPER_H +#define EXAMPLE_MODEL_DX9_HELPER_H + +#include + +//----------------------------------------------------------------------------- +// Forward declarations +//----------------------------------------------------------------------------- +class CBaseVSShader; +class IMaterialVar; +class IShaderDynamicAPI; +class IShaderShadow; + +//----------------------------------------------------------------------------- +// Init params/ init/ draw methods +//----------------------------------------------------------------------------- +struct ExampleModel_DX9_Vars_t +{ + ExampleModel_DX9_Vars_t() { memset( this, 0xFF, sizeof(*this) ); } + + int m_nBaseTexture; + int m_nBaseTextureFrame; + int m_nBaseTextureTransform; + int m_nAlphaTestReference; + int m_nFlashlightTexture; + int m_nFlashlightTextureFrame; +}; + +void InitParamsExampleModel_DX9( CBaseVSShader *pShader, IMaterialVar** params, + const char *pMaterialName, ExampleModel_DX9_Vars_t &info ); + +void InitExampleModel_DX9( CBaseVSShader *pShader, IMaterialVar** params, + ExampleModel_DX9_Vars_t &info ); + +void DrawExampleModel_DX9( CBaseVSShader *pShader, IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, + IShaderShadow* pShaderShadow, + ExampleModel_DX9_Vars_t &info, VertexCompressionType_t vertexCompression, + CBasePerMaterialContextData **pContextDataPtr ); + +#endif // EXAMPLE_MODEL_DX9_HELPER_H diff --git a/materialsystem/stdshaders/example_model_ps20b.fxc b/materialsystem/stdshaders/example_model_ps20b.fxc new file mode 100644 index 0000000..29ed629 --- /dev/null +++ b/materialsystem/stdshaders/example_model_ps20b.fxc @@ -0,0 +1,92 @@ +//===================== Copyright (c) Valve Corporation. All Rights Reserved. ====================== +// +// Example pixel shader that can be applied to models +// +//================================================================================================== + +// STATIC: "CONVERT_TO_SRGB" "0..0" +// STATIC: "FLASHLIGHT" "0..1" +// STATIC: "FLASHLIGHTDEPTHFILTERMODE" "0..2" [ps20b] + +// DYNAMIC: "WRITEWATERFOGTODESTALPHA" "0..1" +// DYNAMIC: "PIXELFOGTYPE" "0..1" +// DYNAMIC: "NUM_LIGHTS" "0..4" +// DYNAMIC: "WRITE_DEPTH_TO_DESTALPHA" "0..1" [ps20b] +// DYNAMIC: "FLASHLIGHTSHADOWS" "0..1" [ps20b] + +// SKIP: ($PIXELFOGTYPE == 0) && ($WRITEWATERFOGTODESTALPHA != 0) + +// We don't care about flashlight depth unless the flashlight is on +// SKIP: ( $FLASHLIGHT == 0 ) && ( $FLASHLIGHTSHADOWS == 1 ) + +// Flashlight shadow filter mode is irrelevant if there is no flashlight +// SKIP: ( $FLASHLIGHT == 0 ) && ( $FLASHLIGHTDEPTHFILTERMODE != 0 ) [ps20b] + +#include "common_flashlight_fxc.h" +#include "shader_constant_register_map.h" + +const float4 g_DiffuseModulation : register( PSREG_DIFFUSE_MODULATION ); +const float4 g_ShadowTweaks : register( PSREG_ENVMAP_TINT__SHADOW_TWEAKS ); +const float3 cAmbientCube[6] : register( PSREG_AMBIENT_CUBE ); +const float4 g_EyePos : register( PSREG_EYEPOS_SPEC_EXPONENT ); +const float4 g_FogParams : register( PSREG_FOG_PARAMS ); +const float4 g_FlashlightAttenuationFactors : register( PSREG_FLASHLIGHT_ATTENUATION ); // On non-flashlight pass +const float4 g_FlashlightPos_RimBoost : register( PSREG_FLASHLIGHT_POSITION_RIM_BOOST ); +const float4x4 g_FlashlightWorldToTexture : register( PSREG_FLASHLIGHT_TO_WORLD_TEXTURE ); +PixelShaderLightInfo cLightInfo[3] : register( PSREG_LIGHT_INFO_ARRAY ); // 2 registers each - 6 registers total (4th light spread across w's) + +#define g_FlashlightPos g_FlashlightPos_RimBoost.xyz + +sampler BaseTextureSampler : register( s0 ); // Base map, selfillum in alpha +sampler ShadowDepthSampler : register( s4 ); // Flashlight shadow depth map sampler +sampler NormalizeRandRotSampler : register( s5 ); // Normalization / RandomRotation samplers +sampler FlashlightSampler : register( s6 ); // Flashlight cookie + +struct PS_INPUT +{ + float2 baseTexCoord : TEXCOORD0; + float4 lightAtten : TEXCOORD1; + float3 worldNormal : TEXCOORD2; + float3 worldPos : TEXCOORD3; + float3 projPos : TEXCOORD4; +}; + +float4 main( PS_INPUT i ) : COLOR +{ + float4 baseColor = tex2D( BaseTextureSampler, i.baseTexCoord ); + + float3 diffuseLighting; + if ( FLASHLIGHT != 0 ) + { + float4 flashlightSpacePosition = mul( float4( i.worldPos, 1.0f ), g_FlashlightWorldToTexture ); + + diffuseLighting = DoFlashlight( g_FlashlightPos, i.worldPos, flashlightSpacePosition, + i.worldNormal, g_FlashlightAttenuationFactors.xyz, + g_FlashlightAttenuationFactors.w, FlashlightSampler, ShadowDepthSampler, + NormalizeRandRotSampler, FLASHLIGHTDEPTHFILTERMODE, FLASHLIGHTSHADOWS, true, i.projPos, false, g_ShadowTweaks ); + } + else // non-flashlight path + { + // Summation of diffuse illumination from all local lights + diffuseLighting = PixelShaderDoLighting( i.worldPos, i.worldNormal, + float3( 0.0f, 0.0f, 0.0f ), false, true, i.lightAtten, + cAmbientCube, NormalizeRandRotSampler, NUM_LIGHTS, cLightInfo, true, + + // These are dummy parameters: + false, 1.0f, + false, BaseTextureSampler ); + } + + float3 result = baseColor.rgb * g_DiffuseModulation.rgb * diffuseLighting; + float alpha = g_DiffuseModulation.a * baseColor.a; + + float fogFactor = CalcPixelFogFactor( PIXELFOGTYPE, g_FogParams, g_EyePos.z, i.worldPos.z, i.projPos.z ); + +#if WRITEWATERFOGTODESTALPHA && ( PIXELFOGTYPE == PIXEL_FOG_TYPE_HEIGHT ) + alpha = fogFactor; +#endif + + bool bWriteDepthToAlpha = ( WRITE_DEPTH_TO_DESTALPHA != 0 ) && ( WRITEWATERFOGTODESTALPHA == 0 ); + + return FinalOutput( float4( result, alpha ), fogFactor, PIXELFOGTYPE, TONEMAP_SCALE_LINEAR, bWriteDepthToAlpha, i.projPos.z ); +} diff --git a/materialsystem/stdshaders/example_model_vs20.fxc b/materialsystem/stdshaders/example_model_vs20.fxc new file mode 100644 index 0000000..6248f2b --- /dev/null +++ b/materialsystem/stdshaders/example_model_vs20.fxc @@ -0,0 +1,91 @@ +//===================== Copyright (c) Valve Corporation. All Rights Reserved. ====================== +// +// Example vertex shader that can be applied to models +// +//================================================================================================== + +// DYNAMIC: "COMPRESSED_VERTS" "0..1" +// DYNAMIC: "DOWATERFOG" "0..1" +// DYNAMIC: "SKINNING" "0..1" +// DYNAMIC: "LIGHTING_PREVIEW" "0..1" +// DYNAMIC: "NUM_LIGHTS" "0..4" + +#include "common_vs_fxc.h" + +static const bool g_bSkinning = SKINNING ? true : false; +static const int g_FogType = DOWATERFOG; + +const float4 cBaseTexCoordTransform[2] : register( SHADER_SPECIFIC_CONST_0 ); + +//----------------------------------------------------------------------------- +// Input vertex format +//----------------------------------------------------------------------------- +struct VS_INPUT +{ + // This is all of the stuff that we ever use. + float4 vPos : POSITION; + float4 vBoneWeights : BLENDWEIGHT; + float4 vBoneIndices : BLENDINDICES; + float4 vNormal : NORMAL; + float2 vTexCoord0 : TEXCOORD0; +}; + +struct VS_OUTPUT +{ + // Stuff that isn't seen by the pixel shader + float4 projPosSetup : POSITION; + float fog : FOG; + // Stuff that is seen by the pixel shader + float2 baseTexCoord : TEXCOORD0; + float4 lightAtten : TEXCOORD1; + float3 worldNormal : TEXCOORD2; + float3 worldPos : TEXCOORD3; + float3 projPos : TEXCOORD4; +}; + +//----------------------------------------------------------------------------- +// Main shader entry point +//----------------------------------------------------------------------------- +VS_OUTPUT main( const VS_INPUT v ) +{ + VS_OUTPUT o = ( VS_OUTPUT )0; + + float3 vNormal; + DecompressVertex_Normal( v.vNormal, vNormal ); + + float3 worldNormal, worldPos; + SkinPositionAndNormal( g_bSkinning, v.vPos, vNormal, v.vBoneWeights, v.vBoneIndices, worldPos, worldNormal ); + + // Transform into projection space + float4 vProjPos = mul( float4( worldPos, 1 ), cViewProj ); + o.projPosSetup = vProjPos; + vProjPos.z = dot( float4( worldPos, 1 ), cViewProjZ ); + + o.projPos = vProjPos.xyz; + o.fog = CalcFog( worldPos, vProjPos.xyz, g_FogType ); + + // Needed for water fog alpha and diffuse lighting + o.worldPos = worldPos; + o.worldNormal = normalize( worldNormal ); + + // Scalar attenuations for four lights + o.lightAtten.xyz = float4(0,0,0,0); + #if ( NUM_LIGHTS > 0 ) + o.lightAtten.x = GetVertexAttenForLight( worldPos, 0, false ); + #endif + #if ( NUM_LIGHTS > 1 ) + o.lightAtten.y = GetVertexAttenForLight( worldPos, 1, false ); + #endif + #if ( NUM_LIGHTS > 2 ) + o.lightAtten.z = GetVertexAttenForLight( worldPos, 2, false ); + #endif + #if ( NUM_LIGHTS > 3 ) + o.lightAtten.w = GetVertexAttenForLight( worldPos, 3, false ); + #endif + + // Base texture coordinate transform + o.baseTexCoord.x = dot( v.vTexCoord0, cBaseTexCoordTransform[0] ); + o.baseTexCoord.y = dot( v.vTexCoord0, cBaseTexCoordTransform[1] ); + + return o; +} diff --git a/materialsystem/stdshaders/eye_refract.cpp b/materialsystem/stdshaders/eye_refract.cpp new file mode 100644 index 0000000..8752802 --- /dev/null +++ b/materialsystem/stdshaders/eye_refract.cpp @@ -0,0 +1,253 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// + +#include "BaseVSShader.h" +#include "eye_refract_helper.h" +#include "cloak_blended_pass_helper.h" +#include "emissive_scroll_blended_pass_helper.h" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +DEFINE_FALLBACK_SHADER( EyeRefract, EyeRefract_dx9 ) +BEGIN_VS_SHADER( EyeRefract_dx9, "Help for Eyes" ) + BEGIN_SHADER_PARAMS + SHADER_PARAM( IRIS, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "iris texture" ) + SHADER_PARAM( IRISFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "frame for the iris texture" ) + SHADER_PARAM( CORNEATEXTURE, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "cornea texture" ) + SHADER_PARAM( AMBIENTOCCLTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "reflection texture" ) + SHADER_PARAM( ENVMAP, SHADER_PARAM_TYPE_TEXTURE, "shadertest/shadertest_env", "envmap" ) + + SHADER_PARAM( EYEORIGIN, SHADER_PARAM_TYPE_VEC3, "[0 0 0]", "origin for the eyes" ) + + SHADER_PARAM( IRISU, SHADER_PARAM_TYPE_VEC4, "[0 1 0 0 ]", "U projection vector for the iris" ) + SHADER_PARAM( IRISV, SHADER_PARAM_TYPE_VEC4, "[0 0 1 0]", "V projection vector for the iris" ) + + SHADER_PARAM( DILATION, SHADER_PARAM_TYPE_FLOAT, "0", "Pupil dilation (0 is none, 1 is maximal)" ) + SHADER_PARAM( GLOSSINESS, SHADER_PARAM_TYPE_FLOAT, "1", "Glossiness of eye (1 is default, 0 is not glossy at all)" ) + SHADER_PARAM( SPHERETEXKILLCOMBO, SHADER_PARAM_TYPE_BOOL, "1", "texkill pixels not on sphere" ) + SHADER_PARAM( RAYTRACESPHERE, SHADER_PARAM_TYPE_BOOL, "1", "Raytrace sphere" ) + SHADER_PARAM( PARALLAXSTRENGTH, SHADER_PARAM_TYPE_FLOAT, "1", "Parallax strength" ) + SHADER_PARAM( CORNEABUMPSTRENGTH, SHADER_PARAM_TYPE_FLOAT, "1", "Cornea strength" ) + + SHADER_PARAM( AMBIENTOCCLCOLOR, SHADER_PARAM_TYPE_VEC3, "[1 1 1]", "Ambient occlusion color" ) + SHADER_PARAM( EYEBALLRADIUS, SHADER_PARAM_TYPE_FLOAT, "0", "Eyeball radius for ray casting" ) + + SHADER_PARAM( INTRO, SHADER_PARAM_TYPE_BOOL, "0", "is eyes in the ep1 intro" ) + SHADER_PARAM( ENTITYORIGIN, SHADER_PARAM_TYPE_VEC3,"0.0","center if the model in world space" ) + SHADER_PARAM( WARPPARAM, SHADER_PARAM_TYPE_FLOAT,"0.0","animation param between 0 and 1" ) + + SHADER_PARAM( LIGHTWARPTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "1D ramp texture for tinting scalar diffuse term" ) + + // Cloak Pass + SHADER_PARAM( CLOAKPASSENABLED, SHADER_PARAM_TYPE_BOOL, "0", "Enables cloak render in a second pass" ) + SHADER_PARAM( CLOAKFACTOR, SHADER_PARAM_TYPE_FLOAT, "0.0", "" ) + SHADER_PARAM( CLOAKCOLORTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "Cloak color tint" ) + SHADER_PARAM( REFRACTAMOUNT, SHADER_PARAM_TYPE_FLOAT, "2", "" ) + + // Emissive Scroll Pass + SHADER_PARAM( EMISSIVEBLENDENABLED, SHADER_PARAM_TYPE_BOOL, "0", "Enable emissive blend pass" ) + SHADER_PARAM( EMISSIVEBLENDSCROLLVECTOR, SHADER_PARAM_TYPE_VEC2, "[0.11 0.124]", "Emissive scroll vec" ) + SHADER_PARAM( EMISSIVEBLENDSTRENGTH, SHADER_PARAM_TYPE_FLOAT, "1.0", "Emissive blend strength" ) + SHADER_PARAM( EMISSIVEBLENDTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "self-illumination map" ) + SHADER_PARAM( EMISSIVEBLENDTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "Self-illumination tint" ) + SHADER_PARAM( EMISSIVEBLENDFLOWTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "flow map" ) + END_SHADER_PARAMS + + void SetupVarsEyeRefract( Eye_Refract_Vars_t &info ) + { + info.m_nFrame = FRAME; + info.m_nIris = IRIS; + info.m_nIrisFrame = IRISFRAME; + info.m_nEyeOrigin = EYEORIGIN; + info.m_nIrisU = IRISU; + info.m_nIrisV = IRISV; + info.m_nDilation = DILATION; + info.m_nGlossiness = GLOSSINESS; + info.m_nIntro = INTRO; + info.m_nEntityOrigin = ENTITYORIGIN; + info.m_nWarpParam = WARPPARAM; + info.m_nCorneaTexture = CORNEATEXTURE; + info.m_nAmbientOcclTexture = AMBIENTOCCLTEXTURE; + info.m_nEnvmap = ENVMAP; + info.m_nSphereTexKillCombo = SPHERETEXKILLCOMBO; + info.m_nRaytraceSphere = RAYTRACESPHERE; + info.m_nParallaxStrength = PARALLAXSTRENGTH; + info.m_nCorneaBumpStrength = CORNEABUMPSTRENGTH; + info.m_nAmbientOcclColor = AMBIENTOCCLCOLOR; + info.m_nEyeballRadius = EYEBALLRADIUS; + info.m_nDiffuseWarpTexture = LIGHTWARPTEXTURE; + } + + // Cloak Pass + void SetupVarsCloakBlendedPass( CloakBlendedPassVars_t &info ) + { + info.m_nCloakFactor = CLOAKFACTOR; + info.m_nCloakColorTint = CLOAKCOLORTINT; + info.m_nRefractAmount = REFRACTAMOUNT; + } + + bool NeedsPowerOfTwoFrameBufferTexture( IMaterialVar **params, bool bCheckSpecificToThisFrame ) const + { + if ( params[CLOAKPASSENABLED]->GetIntValue() ) // If material supports cloaking + { + if ( bCheckSpecificToThisFrame == false ) // For setting model flag at load time + return true; + else if ( ( params[CLOAKFACTOR]->GetFloatValue() > 0.0f ) && ( params[CLOAKFACTOR]->GetFloatValue() < 1.0f ) ) // Per-frame check + return true; + // else, not cloaking this frame, so check flag2 in case the base material still needs it + } + + // Check flag2 if not drawing cloak pass + return IS_FLAG2_SET( MATERIAL_VAR2_NEEDS_POWER_OF_TWO_FRAME_BUFFER_TEXTURE ); + } + + bool IsTranslucent( IMaterialVar **params ) const + { + if ( params[CLOAKPASSENABLED]->GetIntValue() ) // If material supports cloaking + { + if ( ( params[CLOAKFACTOR]->GetFloatValue() > 0.0f ) && ( params[CLOAKFACTOR]->GetFloatValue() < 1.0f ) ) // Per-frame check + return true; + // else, not cloaking this frame, so check flag in case the base material still needs it + } + + // Check flag if not drawing cloak pass + return IS_FLAG_SET( MATERIAL_VAR_TRANSLUCENT ); + } + + // Emissive Scroll Pass + void SetupVarsEmissiveScrollBlendedPass( EmissiveScrollBlendedPassVars_t &info ) + { + info.m_nBlendStrength = EMISSIVEBLENDSTRENGTH; + info.m_nBaseTexture = IRIS; + info.m_nFlowTexture = EMISSIVEBLENDFLOWTEXTURE; + info.m_nEmissiveTexture = EMISSIVEBLENDTEXTURE; + info.m_nEmissiveTint = EMISSIVEBLENDTINT; + info.m_nEmissiveScrollVector = EMISSIVEBLENDSCROLLVECTOR; + } + + SHADER_INIT_PARAMS() + { + Eye_Refract_Vars_t info; + SetupVarsEyeRefract( info ); + InitParams_Eyes_Refract( this, params, pMaterialName, info ); + + // Cloak Pass + if ( !params[CLOAKPASSENABLED]->IsDefined() ) + { + params[CLOAKPASSENABLED]->SetIntValue( 0 ); + } + else if ( params[CLOAKPASSENABLED]->GetIntValue() ) + { + CloakBlendedPassVars_t info; + SetupVarsCloakBlendedPass( info ); + InitParamsCloakBlendedPass( this, params, pMaterialName, info ); + } + + // Emissive Scroll Pass + if ( !params[EMISSIVEBLENDENABLED]->IsDefined() ) + { + params[EMISSIVEBLENDENABLED]->SetIntValue( 0 ); + } + else if ( params[EMISSIVEBLENDENABLED]->GetIntValue() ) + { + EmissiveScrollBlendedPassVars_t info; + SetupVarsEmissiveScrollBlendedPass( info ); + InitParamsEmissiveScrollBlendedPass( this, params, pMaterialName, info ); + } + } + + SHADER_FALLBACK + { + if ( g_pHardwareConfig->GetDXSupportLevel() < 90 ) + { + return "Eyes_dx8"; + } + + return 0; + } + + SHADER_INIT + { + Eye_Refract_Vars_t info; + SetupVarsEyeRefract( info ); + Init_Eyes_Refract( this, params, info ); + + // Cloak Pass + if ( params[CLOAKPASSENABLED]->GetIntValue() ) + { + CloakBlendedPassVars_t info; + SetupVarsCloakBlendedPass( info ); + InitCloakBlendedPass( this, params, info ); + } + + // Emissive Scroll Pass + if ( params[EMISSIVEBLENDENABLED]->GetIntValue() ) + { + EmissiveScrollBlendedPassVars_t info; + SetupVarsEmissiveScrollBlendedPass( info ); + InitEmissiveScrollBlendedPass( this, params, info ); + } + } + + SHADER_DRAW + { + // Skip the standard rendering if cloak pass is fully opaque + bool bDrawStandardEye = true; + if ( params[CLOAKPASSENABLED]->GetIntValue() && ( pShaderShadow == NULL ) ) // && not snapshotting + { + CloakBlendedPassVars_t info; + SetupVarsCloakBlendedPass( info ); + if ( CloakBlendedPassIsFullyOpaque( params, info ) ) + { + bDrawStandardEye = false; + } + } + + // Standard rendering pass + if ( bDrawStandardEye ) + { + Eye_Refract_Vars_t info; + SetupVarsEyeRefract( info ); + Draw_Eyes_Refract( this, params, pShaderAPI, pShaderShadow, info, vertexCompression ); + } + else + { + // Skip this pass! + Draw( false ); + } + + // Cloak Pass + if ( params[CLOAKPASSENABLED]->GetIntValue() ) + { + // If ( snapshotting ) or ( we need to draw this frame ) + if ( ( pShaderShadow != NULL ) || ( ( params[CLOAKFACTOR]->GetFloatValue() > 0.0f ) && ( params[CLOAKFACTOR]->GetFloatValue() < 1.0f ) ) ) + { + CloakBlendedPassVars_t info; + SetupVarsCloakBlendedPass( info ); + DrawCloakBlendedPass( this, params, pShaderAPI, pShaderShadow, info, vertexCompression ); + } + else // We're not snapshotting and we don't need to draw this frame + { + // Skip this pass! + Draw( false ); + } + } + + // Emissive Scroll Pass + if ( params[EMISSIVEBLENDENABLED]->GetIntValue() ) + { + // If ( snapshotting ) or ( we need to draw this frame ) + if ( ( pShaderShadow != NULL ) || ( params[EMISSIVEBLENDSTRENGTH]->GetFloatValue() > 0.0f ) ) + { + EmissiveScrollBlendedPassVars_t info; + SetupVarsEmissiveScrollBlendedPass( info ); + DrawEmissiveScrollBlendedPass( this, params, pShaderAPI, pShaderShadow, info, vertexCompression ); + } + else // We're not snapshotting and we don't need to draw this frame + { + // Skip this pass! + Draw( false ); + } + } + } +END_SHADER diff --git a/materialsystem/stdshaders/eye_refract_helper.cpp b/materialsystem/stdshaders/eye_refract_helper.cpp new file mode 100644 index 0000000..b7aa4ca --- /dev/null +++ b/materialsystem/stdshaders/eye_refract_helper.cpp @@ -0,0 +1,461 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// + +#include "BaseVSShader.h" +#include "mathlib/vmatrix.h" +#include "eye_refract_helper.h" + +#include "cpp_shader_constant_register_map.h" + +#include "eyes_flashlight_vs11.inc" +#include "eyes_flashlight_ps11.inc" + +#include "eye_refract_vs20.inc" +#include "eye_refract_ps20.inc" +#include "eye_refract_ps20b.inc" + +#ifndef _X360 +#include "eye_refract_vs30.inc" +#include "eye_refract_ps30.inc" +#endif + +#include "convar.h" + +static ConVar r_lightwarpidentity( "r_lightwarpidentity","0", FCVAR_CHEAT ); + +void InitParams_Eyes_Refract( CBaseVSShader *pShader, IMaterialVar** params, const char *pMaterialName, Eye_Refract_Vars_t &info ) +{ + // FLASHLIGHTFIXME + + if ( g_pHardwareConfig->SupportsBorderColor() ) + { + params[FLASHLIGHTTEXTURE]->SetStringValue( "effects/flashlight_border" ); + } + else + { + params[FLASHLIGHTTEXTURE]->SetStringValue( "effects/flashlight001" ); + } + + + // Set material flags + SET_FLAGS2( MATERIAL_VAR2_SUPPORTS_HW_SKINNING ); + SET_FLAGS2( MATERIAL_VAR2_LIGHTING_VERTEX_LIT ); + + // Set material parameter default values + if ( ( info.m_nIntro >= 0 ) && ( !params[info.m_nIntro]->IsDefined() ) ) + { + params[info.m_nIntro]->SetIntValue( kDefaultIntro ); + } + + if ( ( info.m_nDilation >= 0 ) && ( !params[info.m_nDilation]->IsDefined() ) ) + { + params[info.m_nDilation]->SetFloatValue( kDefaultDilation ); + } + + if ( ( info.m_nGlossiness >= 0 ) && ( !params[info.m_nGlossiness]->IsDefined() ) ) + { + params[info.m_nGlossiness]->SetFloatValue( kDefaultGlossiness ); + } + + if ( ( info.m_nSphereTexKillCombo >= 0 ) && ( !params[info.m_nSphereTexKillCombo]->IsDefined() ) ) + { + params[info.m_nSphereTexKillCombo]->SetIntValue( kDefaultSphereTexKillCombo ); + } + + if ( ( info.m_nRaytraceSphere >= 0 ) && ( !params[info.m_nRaytraceSphere]->IsDefined() ) ) + { + params[info.m_nRaytraceSphere]->SetIntValue( kDefaultRaytraceSphere ); + } + + if ( ( info.m_nAmbientOcclColor >= 0 ) && ( !params[info.m_nAmbientOcclColor]->IsDefined() ) ) + { + params[info.m_nAmbientOcclColor]->SetVecValue( kDefaultAmbientOcclColor, 4 ); + } + + if ( ( info.m_nEyeballRadius >= 0 ) && ( !params[info.m_nEyeballRadius]->IsDefined() ) ) + { + params[info.m_nEyeballRadius]->SetFloatValue( kDefaultEyeballRadius ); + } + + if ( ( info.m_nParallaxStrength >= 0 ) && ( !params[info.m_nParallaxStrength]->IsDefined() ) ) + { + params[info.m_nParallaxStrength]->SetFloatValue( kDefaultParallaxStrength ); + } + + if ( ( info.m_nCorneaBumpStrength >= 0 ) && ( !params[info.m_nCorneaBumpStrength]->IsDefined() ) ) + { + params[info.m_nCorneaBumpStrength]->SetFloatValue( kDefaultCorneaBumpStrength ); + } +} + +void Init_Eyes_Refract( CBaseVSShader *pShader, IMaterialVar** params, Eye_Refract_Vars_t &info ) +{ + pShader->LoadTexture( info.m_nCorneaTexture ); // SHADER_SAMPLER0 (this is a normal, hence not sRGB) + pShader->LoadTexture( info.m_nIris, TEXTUREFLAGS_SRGB ); // SHADER_SAMPLER1 + pShader->LoadCubeMap( info.m_nEnvmap, TEXTUREFLAGS_SRGB ); // SHADER_SAMPLER2 + pShader->LoadTexture( info.m_nAmbientOcclTexture, TEXTUREFLAGS_SRGB ); // SHADER_SAMPLER3 + + if ( IS_PARAM_DEFINED( info.m_nDiffuseWarpTexture ) ) + { + pShader->LoadTexture( info.m_nDiffuseWarpTexture ); // SHADER_SAMPLER4 + } + + pShader->LoadTexture( FLASHLIGHTTEXTURE, TEXTUREFLAGS_SRGB ); // SHADER_SAMPLER5 +} + +void Draw_Eyes_Refract_Internal( CBaseVSShader *pShader, IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, + IShaderShadow* pShaderShadow, bool bDrawFlashlightAdditivePass, Eye_Refract_Vars_t &info, VertexCompressionType_t vertexCompression ) +{ + bool bDiffuseWarp = IS_PARAM_DEFINED( info.m_nDiffuseWarpTexture ); + bool bIntro = IS_PARAM_DEFINED( info.m_nIntro ) ? ( params[info.m_nIntro]->GetIntValue() ? true : false ) : false; + + SHADOW_STATE + { + SET_FLAGS2( MATERIAL_VAR2_LIGHTING_VERTEX_LIT ); + + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); // Cornea normal + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); // Iris + pShaderShadow->EnableTexture( SHADER_SAMPLER2, true ); // Cube reflection + pShaderShadow->EnableTexture( SHADER_SAMPLER3, true ); // Ambient occlusion + + // Set stream format (note that this shader supports compression) + unsigned int flags = VERTEX_POSITION | VERTEX_NORMAL | VERTEX_FORMAT_COMPRESSED; + int nTexCoordCount = 1; + int userDataSize = 0; + pShaderShadow->VertexShaderVertexFormat( flags, nTexCoordCount, NULL, userDataSize ); + + if ( bDiffuseWarp ) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER4, true ); // Light warp + } + + int nShadowFilterMode = 0; + if ( bDrawFlashlightAdditivePass == true ) + { + if ( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + nShadowFilterMode = g_pHardwareConfig->GetShadowFilterMode(); // Based upon vendor and device dependent formats + } + + pShaderShadow->EnableDepthWrites( false ); + pShader->EnableAlphaBlending( SHADER_BLEND_ONE, SHADER_BLEND_ONE ); // Write over the eyes that were already there + pShaderShadow->EnableTexture( SHADER_SAMPLER5, true ); // Flashlight cookie + } + +#ifndef _X360 + if ( !g_pHardwareConfig->HasFastVertexTextures() ) +#endif + { + DECLARE_STATIC_VERTEX_SHADER( eye_refract_vs20 ); + SET_STATIC_VERTEX_SHADER_COMBO( HALFLAMBERT, IS_FLAG_SET( MATERIAL_VAR_HALFLAMBERT ) ); + SET_STATIC_VERTEX_SHADER_COMBO( INTRO, bIntro ? 1 : 0 ); + SET_STATIC_VERTEX_SHADER_COMBO( FLASHLIGHT, bDrawFlashlightAdditivePass ? 1 : 0 ); + SET_STATIC_VERTEX_SHADER_COMBO( LIGHTWARPTEXTURE, bDiffuseWarp ? 1 : 0 ); + SET_STATIC_VERTEX_SHADER( eye_refract_vs20 ); + + if ( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + bool bSphereTexKillCombo = IS_PARAM_DEFINED( info.m_nSphereTexKillCombo ) ? ( params[info.m_nSphereTexKillCombo]->GetIntValue() ? true : false ) : ( kDefaultSphereTexKillCombo ? true : false ); + bool bRayTraceSphere = IS_PARAM_DEFINED( info.m_nRaytraceSphere ) ? ( params[info.m_nRaytraceSphere]->GetIntValue() ? true : false ) : ( kDefaultRaytraceSphere ? true : false ); + + DECLARE_STATIC_PIXEL_SHADER( eye_refract_ps20b ); + SET_STATIC_PIXEL_SHADER_COMBO( SPHERETEXKILLCOMBO, bSphereTexKillCombo ? 1 : 0 ); + SET_STATIC_PIXEL_SHADER_COMBO( RAYTRACESPHERE, bRayTraceSphere ? 1 : 0 ); + SET_STATIC_PIXEL_SHADER_COMBO( FLASHLIGHT, bDrawFlashlightAdditivePass ? 1 : 0 ); + SET_STATIC_PIXEL_SHADER_COMBO( LIGHTWARPTEXTURE, bDiffuseWarp ? 1 : 0 ); + SET_STATIC_PIXEL_SHADER_COMBO( FLASHLIGHTDEPTHFILTERMODE, nShadowFilterMode ); + SET_STATIC_PIXEL_SHADER( eye_refract_ps20b ); + + if ( bDrawFlashlightAdditivePass == true ) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER6, true ); // Shadow depth map + pShaderShadow->SetShadowDepthFiltering( SHADER_SAMPLER6 ); + pShaderShadow->EnableTexture( SHADER_SAMPLER7, true ); // Noise map + } + } + else + { + DECLARE_STATIC_PIXEL_SHADER( eye_refract_ps20 ); + SET_STATIC_PIXEL_SHADER_COMBO( FLASHLIGHT, bDrawFlashlightAdditivePass ? 1 : 0 ); + SET_STATIC_PIXEL_SHADER_COMBO( LIGHTWARPTEXTURE, bDiffuseWarp ? 1 : 0 ); + SET_STATIC_PIXEL_SHADER( eye_refract_ps20 ); + } + } +#ifndef _X360 + else + { + // The vertex shader uses the vertex id stream + SET_FLAGS2( MATERIAL_VAR2_USES_VERTEXID ); + + DECLARE_STATIC_VERTEX_SHADER( eye_refract_vs30 ); + SET_STATIC_VERTEX_SHADER_COMBO( HALFLAMBERT, IS_FLAG_SET( MATERIAL_VAR_HALFLAMBERT ) ); + SET_STATIC_VERTEX_SHADER_COMBO( INTRO, bIntro ? 1 : 0 ); + SET_STATIC_VERTEX_SHADER_COMBO( FLASHLIGHT, bDrawFlashlightAdditivePass ? 1 : 0 ); + SET_STATIC_VERTEX_SHADER_COMBO( LIGHTWARPTEXTURE, bDiffuseWarp ? 1 : 0 ); + SET_STATIC_VERTEX_SHADER( eye_refract_vs30 ); + + bool bSphereTexKillCombo = IS_PARAM_DEFINED( info.m_nSphereTexKillCombo ) ? ( params[info.m_nSphereTexKillCombo]->GetIntValue() ? true : false ) : ( kDefaultSphereTexKillCombo ? true : false ); + bool bRayTraceSphere = IS_PARAM_DEFINED( info.m_nRaytraceSphere ) ? ( params[info.m_nRaytraceSphere]->GetIntValue() ? true : false ) : ( kDefaultRaytraceSphere ? true : false ); + + DECLARE_STATIC_PIXEL_SHADER( eye_refract_ps30 ); + SET_STATIC_PIXEL_SHADER_COMBO( SPHERETEXKILLCOMBO, bSphereTexKillCombo ? 1 : 0 ); + SET_STATIC_PIXEL_SHADER_COMBO( RAYTRACESPHERE, bRayTraceSphere ? 1 : 0 ); + SET_STATIC_PIXEL_SHADER_COMBO( FLASHLIGHT, bDrawFlashlightAdditivePass ? 1 : 0 ); + SET_STATIC_PIXEL_SHADER_COMBO( LIGHTWARPTEXTURE, bDiffuseWarp ? 1 : 0 ); + SET_STATIC_PIXEL_SHADER_COMBO( FLASHLIGHTDEPTHFILTERMODE, nShadowFilterMode ); + SET_STATIC_PIXEL_SHADER( eye_refract_ps30 ); + + if ( bDrawFlashlightAdditivePass == true ) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER6, true ); // Shadow depth map + pShaderShadow->EnableTexture( SHADER_SAMPLER7, true ); // Noise map + } + } +#endif + + // On DX9, get the gamma read and write correct + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER1, true ); // Iris + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER2, true ); // Cube map reflection + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER3, true ); // Ambient occlusion + pShaderShadow->EnableSRGBWrite( true ); + + if ( bDrawFlashlightAdditivePass == true ) + { + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER5, true ); // Flashlight cookie + } + + // Fog + if ( bDrawFlashlightAdditivePass == true ) + { + pShader->FogToBlack(); + } + else + { + pShader->FogToFogColor(); + } + } + DYNAMIC_STATE + { + VMatrix worldToTexture; + ITexture *pFlashlightDepthTexture = NULL; + FlashlightState_t flashlightState; + bool bFlashlightShadows = false; + if ( bDrawFlashlightAdditivePass == true ) + { + flashlightState = pShaderAPI->GetFlashlightStateEx( worldToTexture, &pFlashlightDepthTexture ); + bFlashlightShadows = flashlightState.m_bEnableShadows && ( pFlashlightDepthTexture != NULL ); + } + + pShader->BindTexture( SHADER_SAMPLER0, info.m_nCorneaTexture ); // Cornea normal + pShader->BindTexture( SHADER_SAMPLER1, info.m_nIris, info.m_nIrisFrame ); + pShader->BindTexture( SHADER_SAMPLER2, info.m_nEnvmap ); + pShader->BindTexture( SHADER_SAMPLER3, info.m_nAmbientOcclTexture ); + + if ( bDiffuseWarp ) + { + if ( r_lightwarpidentity.GetBool() ) + { + pShaderAPI->BindStandardTexture( SHADER_SAMPLER4, TEXTURE_IDENTITY_LIGHTWARP ); + } + else + { + pShader->BindTexture( SHADER_SAMPLER4, info.m_nDiffuseWarpTexture ); + } + } + + if ( bDrawFlashlightAdditivePass == true ) + pShader->BindTexture( SHADER_SAMPLER5, flashlightState.m_pSpotlightTexture, flashlightState.m_nSpotlightTextureFrame ); + + pShader->SetAmbientCubeDynamicStateVertexShader(); + + pShader->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, info.m_nEyeOrigin ); + pShader->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_2, info.m_nIrisU ); + pShader->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_3, info.m_nIrisV ); + + if ( bDrawFlashlightAdditivePass == true ) + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_4, flashlightState.m_vecLightOrigin.Base(), 1 ); + + LightState_t lightState = { 0, false, false }; + if ( bDrawFlashlightAdditivePass == false ) + { + pShaderAPI->GetDX9LightState( &lightState ); + } + +#ifndef _X360 + if ( !g_pHardwareConfig->HasFastVertexTextures() ) +#endif + { + DECLARE_DYNAMIC_VERTEX_SHADER( eye_refract_vs20 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( DOWATERFOG, pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, pShaderAPI->GetCurrentNumBones() > 0 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( DYNAMIC_LIGHT, lightState.HasDynamicLight() ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( STATIC_LIGHT, lightState.m_bStaticLightVertex ? 1 : 0 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( NUM_LIGHTS, lightState.m_nNumLights ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression ); + SET_DYNAMIC_VERTEX_SHADER( eye_refract_vs20 ); + } +#ifndef _X360 + else + { + pShader->SetHWMorphVertexShaderState( VERTEX_SHADER_SHADER_SPECIFIC_CONST_10, VERTEX_SHADER_SHADER_SPECIFIC_CONST_11, SHADER_VERTEXTEXTURE_SAMPLER0 ); + + DECLARE_DYNAMIC_VERTEX_SHADER( eye_refract_vs30 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( DOWATERFOG, pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, pShaderAPI->GetCurrentNumBones() > 0 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( DYNAMIC_LIGHT, lightState.HasDynamicLight() ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( STATIC_LIGHT, lightState.m_bStaticLightVertex ? 1 : 0 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( NUM_LIGHTS, lightState.m_nNumLights ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( MORPHING, pShaderAPI->IsHWMorphingEnabled() ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression ); + SET_DYNAMIC_VERTEX_SHADER( eye_refract_vs30 ); + } +#endif + + // Get luminance of ambient cube and saturate it + float fAverageAmbient = max(0.0f, min( pShaderAPI->GetAmbientLightCubeLuminance(), 1.0f ) ); + + // Special constant for DX9 eyes: { Dilation, Glossiness, x, x }; + float vPSConst[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; + vPSConst[0] = IS_PARAM_DEFINED( info.m_nDilation ) ? params[info.m_nDilation]->GetFloatValue() : kDefaultDilation; + vPSConst[1] = IS_PARAM_DEFINED( info.m_nGlossiness ) ? params[info.m_nGlossiness]->GetFloatValue() : kDefaultGlossiness; + vPSConst[2] = fAverageAmbient; + vPSConst[3] = IS_PARAM_DEFINED( info.m_nCorneaBumpStrength ) ? params[info.m_nCorneaBumpStrength]->GetFloatValue() : kDefaultCorneaBumpStrength; + pShaderAPI->SetPixelShaderConstant( 0, vPSConst, 1 ); + + pShaderAPI->SetPixelShaderConstant( 1, IS_PARAM_DEFINED( info.m_nEyeOrigin ) ? params[info.m_nEyeOrigin]->GetVecValue() : kDefaultEyeOrigin, 1 ); + pShaderAPI->SetPixelShaderConstant( 2, IS_PARAM_DEFINED( info.m_nIrisU ) ? params[info.m_nIrisU]->GetVecValue() : kDefaultIrisU, 1 ); + pShaderAPI->SetPixelShaderConstant( 3, IS_PARAM_DEFINED( info.m_nIrisV ) ? params[info.m_nIrisV]->GetVecValue() : kDefaultIrisV, 1 ); + + float vEyePos[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; + pShaderAPI->GetWorldSpaceCameraPosition( vEyePos ); + pShaderAPI->SetPixelShaderConstant( 4, vEyePos, 1 ); + pShaderAPI->SetPixelShaderConstant( 5, IS_PARAM_DEFINED( info.m_nAmbientOcclColor ) ? params[info.m_nAmbientOcclColor]->GetVecValue() : kDefaultAmbientOcclColor, 1 ); + + float vPackedConst6[4] = { 1.0f, 1.0f, 1.0f, 1.0f }; + //vPackedConst6[0] Unused + vPackedConst6[1] = IS_PARAM_DEFINED( info.m_nEyeballRadius ) ? params[info.m_nEyeballRadius]->GetFloatValue() : kDefaultEyeballRadius; + //vPackedConst6[2] = IS_PARAM_DEFINED( info.m_nRaytraceSphere ) ? params[info.m_nRaytraceSphere]->GetFloatValue() : kDefaultRaytraceSphere; + vPackedConst6[3] = IS_PARAM_DEFINED( info.m_nParallaxStrength ) ? params[info.m_nParallaxStrength]->GetFloatValue() : kDefaultParallaxStrength; + pShaderAPI->SetPixelShaderConstant( 6, vPackedConst6, 1 ); + + float fPixelFogType = pShaderAPI->GetPixelFogCombo() == 1 ? 1 : 0; + + // Controls for lerp-style paths through shader code + float vShaderControls[4] = { fPixelFogType, 0, 0, 0 }; + pShaderAPI->SetPixelShaderConstant( 10, vShaderControls, 1 ); + + if ( bDrawFlashlightAdditivePass == true ) + { + SetFlashLightColorFromState( flashlightState, pShaderAPI ); + + if ( pFlashlightDepthTexture && g_pConfig->ShadowDepthTexture() && flashlightState.m_bEnableShadows ) + { + pShader->BindTexture( SHADER_SAMPLER6, pFlashlightDepthTexture, 0 ); + pShaderAPI->BindStandardTexture( SHADER_SAMPLER7, TEXTURE_SHADOW_NOISE_2D ); + } + } + + // Flashlight tax +#ifndef _X360 + if ( !g_pHardwareConfig->HasFastVertexTextures() ) +#endif + { + if ( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_DYNAMIC_PIXEL_SHADER( eye_refract_ps20b ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( NUM_LIGHTS, lightState.m_nNumLights ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( FLASHLIGHTSHADOWS, bFlashlightShadows ); + SET_DYNAMIC_PIXEL_SHADER( eye_refract_ps20b ); + } + else // ps.2.0 + { + DECLARE_DYNAMIC_PIXEL_SHADER( eye_refract_ps20 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( NUM_LIGHTS, lightState.m_nNumLights ); + SET_DYNAMIC_PIXEL_SHADER( eye_refract_ps20 ); + } + } +#ifndef _X360 + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( eye_refract_ps30 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( NUM_LIGHTS, lightState.m_nNumLights ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( FLASHLIGHTSHADOWS, bFlashlightShadows ); + SET_DYNAMIC_PIXEL_SHADER( eye_refract_ps30 ); + } +#endif + + pShaderAPI->SetPixelShaderFogParams( PSREG_FOG_PARAMS ); + + if ( bDrawFlashlightAdditivePass == true ) + { + float atten[4], pos[4], tweaks[4]; + atten[0] = flashlightState.m_fConstantAtten; // Set the flashlight attenuation factors + atten[1] = flashlightState.m_fLinearAtten; + atten[2] = flashlightState.m_fQuadraticAtten; + atten[3] = flashlightState.m_FarZ; + pShaderAPI->SetPixelShaderConstant( 7, atten, 1 ); + + pos[0] = flashlightState.m_vecLightOrigin[0]; // Set the flashlight origin + pos[1] = flashlightState.m_vecLightOrigin[1]; + pos[2] = flashlightState.m_vecLightOrigin[2]; + pShaderAPI->SetPixelShaderConstant( 8, pos, 1 ); + + //pShaderAPI->SetPixelShaderConstant( 9, worldToTexture.Base(), 4 ); + //10 + //11 + //12 + + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_6, worldToTexture[0], 1 ); + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_7, worldToTexture[1], 1 ); + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_8, worldToTexture[2], 1 ); + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_9, worldToTexture[3], 1 ); + + // Tweaks associated with a given flashlight + tweaks[0] = flashlightState.m_flShadowFilterSize / flashlightState.m_flShadowMapResolution; + tweaks[1] = ShadowAttenFromState( flashlightState ); + pShader->HashShadow2DJitter( flashlightState.m_flShadowJitterSeed, &tweaks[2], &tweaks[3] ); + pShaderAPI->SetPixelShaderConstant( 9, tweaks, 1 ); + + // Dimensions of screen, used for screen-space noise map sampling + float vScreenScale[4] = {1280.0f / 32.0f, 720.0f / 32.0f, 0, 0}; + int nWidth, nHeight; + pShaderAPI->GetBackBufferDimensions( nWidth, nHeight ); + vScreenScale[0] = (float) nWidth / 32.0f; + vScreenScale[1] = (float) nHeight / 32.0f; + pShaderAPI->SetPixelShaderConstant( PSREG_FLASHLIGHT_SCREEN_SCALE, vScreenScale, 1 ); + } + else // Lighting constants when not drawing flashlight + { + pShaderAPI->CommitPixelShaderLighting( PSREG_LIGHT_INFO_ARRAY ); + } + + // Intro tax + if ( bIntro ) + { + float curTime = params[info.m_nWarpParam]->GetFloatValue(); + float timeVec[4] = { 0.0f, 0.0f, 0.0f, curTime }; + if ( IS_PARAM_DEFINED( info.m_nEntityOrigin ) ) + { + params[info.m_nEntityOrigin]->GetVecValue( timeVec, 3 ); + } + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_6, timeVec, 1 ); + } + } + pShader->Draw(); +} + + +extern ConVar r_flashlight_version2; +void Draw_Eyes_Refract( CBaseVSShader *pShader, IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, + IShaderShadow* pShaderShadow, Eye_Refract_Vars_t &info, VertexCompressionType_t vertexCompression ) +{ + bool bHasFlashlight = pShader->UsingFlashlight( params ); + if( bHasFlashlight && ( IsX360() || r_flashlight_version2.GetInt() ) ) + { + Draw_Eyes_Refract_Internal( pShader, params, pShaderAPI, pShaderShadow, false, info, vertexCompression ); + if ( pShaderShadow ) + { + pShader->SetInitialShadowState( ); + } + } + Draw_Eyes_Refract_Internal( pShader, params, pShaderAPI, pShaderShadow, bHasFlashlight, info, vertexCompression ); +} diff --git a/materialsystem/stdshaders/eye_refract_helper.h b/materialsystem/stdshaders/eye_refract_helper.h new file mode 100644 index 0000000..ce62a33 --- /dev/null +++ b/materialsystem/stdshaders/eye_refract_helper.h @@ -0,0 +1,69 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// + +#ifndef EYE_REFRACT_HELPER_H +#define EYE_REFRACT_HELPER_H +#ifdef _WIN32 +#pragma once +#endif + +#include + +//----------------------------------------------------------------------------- +// Forward declarations +//----------------------------------------------------------------------------- +class CBaseVSShader; +class IMaterialVar; +class IShaderDynamicAPI; +class IShaderShadow; + +//----------------------------------------------------------------------------- +// Init params/ init/ draw methods +//----------------------------------------------------------------------------- +struct Eye_Refract_Vars_t +{ + Eye_Refract_Vars_t() { memset( this, 0xFF, sizeof(Eye_Refract_Vars_t) ); } + + int m_nFrame; + int m_nIris; + int m_nIrisFrame; + int m_nEyeOrigin; + int m_nIrisU; + int m_nIrisV; + int m_nDilation; + int m_nGlossiness; + int m_nIntro; + int m_nEntityOrigin; // Needed for intro + int m_nWarpParam; + int m_nCorneaTexture; + int m_nAmbientOcclTexture; + int m_nEnvmap; + int m_nSphereTexKillCombo; + int m_nRaytraceSphere; + int m_nParallaxStrength; + int m_nCorneaBumpStrength; + int m_nAmbientOcclColor; + int m_nEyeballRadius; + int m_nDiffuseWarpTexture; +}; + +// Default values (Arrays should only be vec[4]) +static const int kDefaultIntro = 0; +static const float kDefaultEyeOrigin[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; +static const float kDefaultIrisU[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; +static const float kDefaultIrisV[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; +static const float kDefaultDilation = 0.5f; +static const float kDefaultGlossiness = 1.0f; +static const float kDefaultWarpParam = 0.0f; +static const int kDefaultSphereTexKillCombo = 0; +static const int kDefaultRaytraceSphere = 0; +static const float kDefaultParallaxStrength = 0.25f; +static const float kDefaultCorneaBumpStrength = 1.0f; +static const float kDefaultAmbientOcclColor[4] = { 0.33f, 0.33f, 0.33f, 0.0f }; +static const float kDefaultEyeballRadius = 0.5f; + +void InitParams_Eyes_Refract( CBaseVSShader *pShader, IMaterialVar** params, const char *pMaterialName, Eye_Refract_Vars_t &info ); +void Init_Eyes_Refract( CBaseVSShader *pShader, IMaterialVar** params, Eye_Refract_Vars_t &info ); +void Draw_Eyes_Refract( CBaseVSShader *pShader, IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, + IShaderShadow* pShaderShadow, Eye_Refract_Vars_t &info, VertexCompressionType_t vertexCompression ); + +#endif // EYES_DX8_DX9_HELPER_H diff --git a/materialsystem/stdshaders/eye_refract_ps2x.fxc b/materialsystem/stdshaders/eye_refract_ps2x.fxc new file mode 100644 index 0000000..da053d2 --- /dev/null +++ b/materialsystem/stdshaders/eye_refract_ps2x.fxc @@ -0,0 +1,494 @@ +//====== Copyright © 1996-2007, Valve Corporation, All rights reserved. =========================== + +// STATIC: "FLASHLIGHT" "0..1" +// STATIC: "LIGHTWARPTEXTURE" "0..1" + +// STATIC: "SPHERETEXKILLCOMBO" "0..1" [ps20b] +// STATIC: "SPHERETEXKILLCOMBO" "0..1" [ps30] + +// STATIC: "RAYTRACESPHERE" "0..1" [ps20b] +// STATIC: "RAYTRACESPHERE" "0..1" [ps30] + +// STATIC: "FLASHLIGHTDEPTHFILTERMODE" "0..2" [ps20b] [PC] +// STATIC: "FLASHLIGHTDEPTHFILTERMODE" "0..2" [ps30] [PC] +// STATIC: "FLASHLIGHTDEPTHFILTERMODE" "0..0" [ps20b] [XBOX] + +// DYNAMIC: "NUM_LIGHTS" "0..2" [ps20] +// DYNAMIC: "NUM_LIGHTS" "0..4" [ps20b] +// DYNAMIC: "NUM_LIGHTS" "0..4" [ps30] + +// DYNAMIC: "FLASHLIGHTSHADOWS" "0..1" [ps20b] +// DYNAMIC: "FLASHLIGHTSHADOWS" "0..1" [ps30] + +// We don't use other lights when doing the flashlight +// SKIP: ( $FLASHLIGHT != 0 ) && ( $NUM_LIGHTS > 0 ) + +// We don't care about flashlight depth unless the flashlight is on +// SKIP: ( $FLASHLIGHT == 0 ) && ( $FLASHLIGHTSHADOWS == 1 ) [ps20b] +// SKIP: ( $FLASHLIGHT == 0 ) && ( $FLASHLIGHTSHADOWS == 1 ) [ps30] + +// SKIP: ( $RAYTRACESPHERE == 0 ) && ( $SPHERETEXKILLCOMBO == 1 ) [ps30] +// SKIP: ( $RAYTRACESPHERE == 0 ) && ( $SPHERETEXKILLCOMBO == 1 ) [ps20b] + +// Debug 2.0 shader locally +//#ifdef SHADER_MODEL_PS_2_B +//#undef SHADER_MODEL_PS_2_B +//#define SHADER_MODEL_PS_2_0 +//#endif + + +// Includes ======================================================================================= +#include "common_flashlight_fxc.h" +#include "shader_constant_register_map.h" + +// Texture Samplers =============================================================================== +sampler g_tCorneaSampler : register( s0 ); +sampler g_tIrisSampler : register( s1 ); +sampler g_tEyeReflectionCubemapSampler : register( s2 ); +sampler g_tEyeAmbientOcclSampler : register( s3 ); +sampler g_tLightwarpSampler : register( s4 ); // 1D texture for TF NPR lighting + +sampler g_tFlashlightCookieSampler : register( s5 ); +sampler g_tFlashlightDepthSampler : register( s6 ); +sampler g_tRandomRotationSampler : register( s7 ); + +// Shaders Constants and Globals ================================================================== +const float4 g_vPackedConst0 : register( c0 ); +#define g_flDilationFactor g_vPackedConst0.x +#define g_flGlossiness g_vPackedConst0.y +#define g_flAverageAmbient g_vPackedConst0.z +#define g_flCorneaBumpStrength g_vPackedConst0.w + +const float3 g_vEyeOrigin : register( c1 ); +const float4 g_vIrisProjectionU : register( c2 ); +const float4 g_vIrisProjectionV : register( c3 ); +const float4 g_vCameraPosition : register( c4 ); +const float3 g_cAmbientOcclColor : register( c5 ); + +const float4 g_vPackedConst6 : register( c6 ); +#define g_flEyeballRadius g_vPackedConst6.y //0.51f +//#define g_bRaytraceSphere g_vPackedConst6.z //1.0f +#define g_flParallaxStrength g_vPackedConst6.w //0.25f + +// Flashlight constants +const float4 g_vFlashlightAttenuationFactors : register( c7 ); // FarZ in w +const float3 g_vFlashlightPos : register( c8 ); +const float4 g_vShadowTweaks : register( c9 ); +const float4 g_ShaderControls : register( c10 ); +#define g_fPixelFogType g_ShaderControls.x + +const float4 g_FogParams : register( PSREG_FOG_PARAMS ); + +PixelShaderLightInfo g_sLightInfo[3] : register( PSREG_LIGHT_INFO_ARRAY ); // 2 registers each - 6 registers total + +// Interpolated values ============================================================================ +struct PS_INPUT +{ + float4 vAmbientOcclUv_fallbackCorneaUv : TEXCOORD0; + float4 cVertexLight : TEXCOORD1; // w is used for the flashlight pass + float4 vTangentViewVector : TEXCOORD2; // Tangent view vector (Note: w is used for flashlight pass) + float4 vWorldPosition_ProjPosZ : TEXCOORD3; + float3 vWorldNormal : TEXCOORD4; // World-space normal + float3 vWorldTangent : TEXCOORD5; // World-space tangent + float4 vLightFalloffCosine01 : TEXCOORD6; // Light falloff and cosine terms for first two local lights + float4 vLightFalloffCosine23 : TEXCOORD7; // Light falloff and cosine terms for next two local lights + + float3 vWorldBinormal : COLOR0; // World-space normal +}; + +// Ray sphere intersect returns distance along ray to intersection ================================ +float IntersectRaySphere ( float3 cameraPos, float3 ray, float3 sphereCenter, float sphereRadius) +{ + float3 dst = cameraPos.xyz - sphereCenter.xyz; + float B = dot(dst, ray); + float C = dot(dst, dst) - (sphereRadius * sphereRadius); + float D = B*B - C; + return (D > 0) ? (-B - sqrt(D)) : 0; +} + +// Calculate both types of Fog and lerp to get result +float CalcPixelFogFactorConst( float fPixelFogType, const float4 fogParams, const float flEyePosZ, const float flWorldPosZ, const float flProjPosZ ) +{ + float fRangeFog = CalcRangeFog( flProjPosZ, fogParams.x, fogParams.z, fogParams.w ); + float fHeightFog = CalcWaterFogAlpha( fogParams.y, flEyePosZ, flWorldPosZ, flProjPosZ, fogParams.w ); + return lerp( fRangeFog, fHeightFog, fPixelFogType ); +} + +// Blend both types of Fog and lerp to get result +float3 BlendPixelFogConst( const float3 vShaderColor, float pixelFogFactor, const float3 vFogColor, float fPixelFogType ) +{ + pixelFogFactor = saturate( pixelFogFactor ); + float3 fRangeResult = lerp( vShaderColor.rgb, vFogColor.rgb, pixelFogFactor * pixelFogFactor ); //squaring the factor will get the middle range mixing closer to hardware fog + float3 fHeightResult = lerp( vShaderColor.rgb, vFogColor.rgb, saturate( pixelFogFactor ) ); + return lerp( fRangeResult, fHeightResult, fPixelFogType ); +} + +float4 FinalOutputConst( const float4 vShaderColor, float pixelFogFactor, float fPixelFogType, const int iTONEMAP_SCALE_TYPE ) +{ + float4 result = vShaderColor; + if( iTONEMAP_SCALE_TYPE == TONEMAP_SCALE_LINEAR ) + { + result.rgb *= LINEAR_LIGHT_SCALE; + } + else if( iTONEMAP_SCALE_TYPE == TONEMAP_SCALE_GAMMA ) + { + result.rgb *= GAMMA_LIGHT_SCALE; + } + + result.rgb = BlendPixelFogConst( result.rgb, pixelFogFactor, g_LinearFogColor.rgb, fPixelFogType ); + result.rgb = SRGBOutput( result.rgb ); //SRGB in pixel shader conversion + + return result; +} + + +// Main =========================================================================================== +float4 main( PS_INPUT i ) : COLOR +{ + // Set bools to compile out code + bool bFlashlight = ( FLASHLIGHT != 0 ) ? true : false; + bool bDoDiffuseWarp = LIGHTWARPTEXTURE ? true : false; + int nNumLights = FLASHLIGHT ? 1 : NUM_LIGHTS; // Flashlight is considered one light, otherwise, use numlights combo + +#if !defined( SHADER_MODEL_PS_2_0 ) + bool bRayCast = RAYTRACESPHERE ? true : false; + bool bRayCastTexKill = SPHERETEXKILLCOMBO ? true : false; +#endif + + float flFlashlightNDotL = i.vTangentViewVector.w; + float4 vFlashlightTexCoord = { 0.0f, 0.0f, 0.0f, 0.0f }; + if ( bFlashlight ) + { + vFlashlightTexCoord.xyzw = i.cVertexLight.xyzw; // This was hidden in this interpolator + i.cVertexLight.rgba = float4( 0.0f, 0.0f, 0.0f, 0.0f ); + } + + // Interpolated vectors + float3 vWorldNormal = i.vWorldNormal.xyz; + float3 vWorldTangent = i.vWorldTangent.xyz; + float3 vWorldBinormal = ( i.vWorldBinormal.xyz * 2.0f ) - 1.0f; // normalize( cross( vWorldNormal.xyz, vWorldTangent.xyz ) ); + + float3 vTangentViewVector = i.vTangentViewVector.xyz; + + // World position + float3 vWorldPosition = i.vWorldPosition_ProjPosZ.xyz; + + // World view vector to pixel + float3 vWorldViewVector = normalize( vWorldPosition.xyz - g_vCameraPosition.xyz ); + + //=================// + // TF NPR lighting // + //=================// + if ( bDoDiffuseWarp ) + { + // Replace the interpolated vertex light + if ( bFlashlight == true ) + { + // Deal with this below in the flashlight section + } + else + { + if ( nNumLights > 0 ) + { + float3 cWarpedLight = 2.0f * tex1D( g_tLightwarpSampler, i.vLightFalloffCosine01.z ).rgb; + i.cVertexLight.rgb += i.vLightFalloffCosine01.x * PixelShaderGetLightColor( g_sLightInfo, 0 ) * cWarpedLight.rgb; + } + + if ( nNumLights > 1 ) + { + float3 cWarpedLight = 2.0f * tex1D( g_tLightwarpSampler, i.vLightFalloffCosine01.w ).rgb; + i.cVertexLight.rgb += i.vLightFalloffCosine01.y * PixelShaderGetLightColor( g_sLightInfo, 1 ) * cWarpedLight.rgb; + } + + if ( nNumLights > 2 ) + { + float3 cWarpedLight = 2.0f * tex1D( g_tLightwarpSampler, i.vLightFalloffCosine23.z ).rgb; + i.cVertexLight.rgb += i.vLightFalloffCosine23.x * PixelShaderGetLightColor( g_sLightInfo, 2 ) * cWarpedLight.rgb; + } + + if ( nNumLights > 3 ) + { + float3 cWarpedLight = 2.0f * tex1D( g_tLightwarpSampler, i.vLightFalloffCosine23.w ).rgb; + i.cVertexLight.rgb += i.vLightFalloffCosine23.y * PixelShaderGetLightColor( g_sLightInfo, 3 ) * cWarpedLight.rgb; + } + } + } + + //==========================================================================================================// + // Ray cast against sphere representing eyeball to reduce artifacts from non-spherical morphed eye geometry // + //==========================================================================================================// +#if !defined( SHADER_MODEL_PS_2_0 ) + if ( bRayCast ) + { + float fSphereRayCastDistance = IntersectRaySphere( g_vCameraPosition.xyz, vWorldViewVector.xyz, g_vEyeOrigin.xyz, g_flEyeballRadius ); + vWorldPosition.xyz = g_vCameraPosition.xyz + ( vWorldViewVector.xyz * fSphereRayCastDistance ); + if (fSphereRayCastDistance == 0) + { + if ( bRayCastTexKill ) + clip(-1); // texkill to get a better silhouette + vWorldPosition.xyz = g_vEyeOrigin.xyz + ( vWorldNormal.xyz * g_flEyeballRadius ); + } + } +#endif + + //=================================// + // Generate sphere and cornea uv's // + //=================================// +#if !defined( SHADER_MODEL_PS_2_0 ) + float2 vCorneaUv; // Note: Cornea texture is a cropped version of the iris texture + vCorneaUv.x = dot( g_vIrisProjectionU, float4( vWorldPosition, 1.0f ) ); + vCorneaUv.y = dot( g_vIrisProjectionV, float4( vWorldPosition, 1.0f ) ); + float2 vSphereUv = ( vCorneaUv.xy * 0.5f ) + 0.25f; +#else // ps_20 + float2 vCorneaUv = i.vAmbientOcclUv_fallbackCorneaUv.wz; // Note: Cornea texture is a cropped version of the iris texture + float2 vSphereUv = ( vCorneaUv.xy * 0.5f ) + 0.25f; +#endif + + //=================================// + // Hacked parallax mapping on iris // + //=================================// + float fIrisOffset = tex2D( g_tCorneaSampler, vCorneaUv.xy ).b; + +#if !defined( SHADER_MODEL_PS_2_0 ) + float2 vParallaxVector = ( ( vTangentViewVector.xy * fIrisOffset * g_flParallaxStrength ) / ( 1.0f - vTangentViewVector.z ) ); // Note: 0.25 is a magic number + vParallaxVector.x = -vParallaxVector.x; //Need to flip x...not sure why. + //vParallaxVector.x *= -1.0; //Need to flip x...not sure why. + //vParallaxVector = 0.0f; //Disable parallax for debugging +#else // Disable parallax effect in 2.0 version + float2 vParallaxVector = { 0.0f, 0.0f }; +#endif + + float2 vIrisUv = vSphereUv.xy - vParallaxVector.xy; + + // Note: We fetch from this texture twice right now with different uv's for the color and alpha + float2 vCorneaNoiseUv = vSphereUv.xy + ( vParallaxVector.xy * 0.5 ); + float fCorneaNoise = tex2D( g_tIrisSampler, vCorneaNoiseUv.xy ).a; + + //===============// + // Cornea normal // + //===============// + // Sample 2D normal from texture + float3 vCorneaTangentNormal = { 0.0, 0.0, 1.0 }; + float4 vCorneaSample = tex2D( g_tCorneaSampler, vCorneaUv.xy ); + vCorneaTangentNormal.xy = vCorneaSample.rg - 0.5f; // Note: This scales the bump to 50% strength + + // Scale strength of normal + vCorneaTangentNormal.xy *= g_flCorneaBumpStrength; + + // Add in surface noise and imperfections (NOTE: This should be baked into the normal map!) + vCorneaTangentNormal.xy += fCorneaNoise * 0.1f; + + // Normalize tangent vector +#if !defined( SHADER_MODEL_PS_2_0 ) + // Since this isn't used later in 2.0, skip the normalize to save shader instructions + vCorneaTangentNormal.xyz = normalize( vCorneaTangentNormal.xyz ); +#endif + + // Transform into world space + float3 vCorneaWorldNormal = Vec3TangentToWorldNormalized( vCorneaTangentNormal.xyz, vWorldNormal.xyz, vWorldTangent.xyz, vWorldBinormal.xyz ); + + //============// + // Flashlight // + //============// + float3 vFlashlightVector = { 0.0f, 0.0f, 0.0f }; + float3 cFlashlightColorFalloff = { 0.0f, 0.0f, 0.0f }; + if ( bFlashlight == true ) + { + // Flashlight vector + vFlashlightVector.xyz = normalize( g_vFlashlightPos.xyz - i.vWorldPosition_ProjPosZ.xyz ); + + // Distance attenuation for flashlight and to fade out shadow over distance + float3 vDelta = g_vFlashlightPos.xyz - i.vWorldPosition_ProjPosZ.xyz; + float flDistSquared = dot( vDelta, vDelta ); + float flDist = sqrt( flDistSquared ); + float flFlashlightAttenuation = dot( g_vFlashlightAttenuationFactors.xyz, float3( 1.0f, 1.0f/flDist, 1.0f/flDistSquared ) ); + + // Flashlight cookie +#if !defined( SHADER_MODEL_PS_2_0 ) + float3 vProjCoords = vFlashlightTexCoord.xyz / vFlashlightTexCoord.w; + float3 cFlashlightCookieColor = tex2D( g_tFlashlightCookieSampler, vProjCoords ); +#else + float3 cFlashlightCookieColor = tex2Dproj( g_tFlashlightCookieSampler, vFlashlightTexCoord.xyzw ); +#endif + + // Shadow depth map +#if FLASHLIGHTSHADOWS && !defined( SHADER_MODEL_PS_2_0 ) + int nShadowLevel = FLASHLIGHTDEPTHFILTERMODE; + float flShadow = DoFlashlightShadow( g_tFlashlightDepthSampler, g_tRandomRotationSampler, vProjCoords, float2(0,0), nShadowLevel, g_vShadowTweaks, false ); + float flAttenuated = lerp( flShadow, 1.0f, g_vShadowTweaks.y ); // Blend between fully attenuated and not attenuated + flShadow = lerp( flAttenuated, flShadow, flFlashlightAttenuation ); // Blend between shadow and above, according to light attenuation + cFlashlightCookieColor *= flShadow; // Apply shadow term to cookie color +#endif + + // Flashlight color intensity (needs to be multiplied by global flashlight color later) + cFlashlightColorFalloff.rgb = flFlashlightAttenuation * cFlashlightCookieColor.rgb; + + // Add this into the interpolated lighting + if ( bDoDiffuseWarp ) + { + //float3 cWarpedLight = 2.0f * tex1D( g_tLightwarpSampler, flFlashlightNDotL ).rgb; + //i.cVertexLight.rgb += cFlashlightColorFalloff.rgb * cFlashlightColor.rgb * cWarpedLight.rgb; + i.cVertexLight.rgb += cFlashlightColorFalloff.rgb * cFlashlightColor.rgb * flFlashlightNDotL; // No light warp for now + } + else + { + i.cVertexLight.rgb += cFlashlightColorFalloff.rgb * cFlashlightColor.rgb * flFlashlightNDotL; + } + } + + //==============// + // Dilate pupil // + //==============// +#if !defined( SHADER_MODEL_PS_2_0 ) + vIrisUv.xy -= 0.5f; // Center around (0,0) + float fPupilCenterToBorder = saturate( length( vIrisUv.xy ) / 0.2f ); //Note: 0.2 is the uv radius of the iris + float fPupilDilateFactor = g_flDilationFactor; // This value should be between 0-1 + vIrisUv.xy *= lerp (1.0f, fPupilCenterToBorder, saturate( fPupilDilateFactor ) * 2.5f - 1.25f ); + vIrisUv.xy += 0.5f; +#endif + + //============// + // Iris color // + //============// + float4 cIrisColor = tex2D( g_tIrisSampler, vIrisUv.xy ); + + //==========================// + // Iris lighting highlights // + //==========================// + float3 cIrisLighting = float3( 0.0f, 0.0f, 0.0f ); + +#if !defined( SHADER_MODEL_PS_2_0 ) + // Mask off everything but the iris pixels + float fIrisHighlightMask = tex2D( g_tCorneaSampler, vCorneaUv.xy ).a; + + // Generate the normal + float3 vIrisTangentNormal = vCorneaTangentNormal.xyz; + vIrisTangentNormal.xy *= -2.5f; // I'm not normalizing on purpose + + for ( int j=0; j < nNumLights; j++ ) + { + // World light vector + float3 vWorldLightVector; + if ( ( j == 0 ) && ( bFlashlight == true ) ) + vWorldLightVector = vFlashlightVector.xyz; + else + vWorldLightVector = PixelShaderGetLightVector( i.vWorldPosition_ProjPosZ.xyz, g_sLightInfo, j ); + + // Tangent light vector + float3 vTangentLightVector = Vec3WorldToTangent( vWorldLightVector.xyz, vWorldNormal.xyz, vWorldTangent.xyz, vWorldBinormal.xyz ); + + // Adjust the tangent light vector to generate the iris lighting + float3 tmpv = -vTangentLightVector.xyz; + tmpv.xy *= -0.5f; //Flatten tangent view + tmpv.z = max( tmpv.z, 0.5f ); //Clamp z of tangent view to help maintain highlight + tmpv.xyz = normalize( tmpv.xyz ); + + // Core iris lighting math + float fIrisFacing = pow( abs( dot( vIrisTangentNormal.xyz, tmpv.xyz ) ), 6.0f ) * 0.5f; // Yes, 6.0 and 0.5 are magic numbers + + // Cone of darkness to darken iris highlights when light falls behind eyeball past a certain point + float flConeOfDarkness = pow( 1.0f - saturate( ( -vTangentLightVector.z - 0.25f ) / 0.75f ), 4.0f ); + //float flConeOfDarkness = pow( 1.0f - saturate( ( -dot( vIrisTangentNormal.xyz, vTangentLightVector.xyz ) - 0.15f ) / 0.85f ), 8.0f ); + + // Tint by iris color and cone of darkness + float3 cIrisLightingTmp = fIrisFacing * fIrisHighlightMask * flConeOfDarkness; + + // Attenuate by light color and light falloff + if ( ( j == 0 ) && ( bFlashlight == true ) ) + cIrisLightingTmp.rgb *= cFlashlightColorFalloff.rgb * cFlashlightColor.rgb; + else if ( j == 0 ) + cIrisLightingTmp.rgb *= i.vLightFalloffCosine01.x * PixelShaderGetLightColor( g_sLightInfo, 0 ); + else if ( j == 1 ) + cIrisLightingTmp.rgb *= i.vLightFalloffCosine01.y * PixelShaderGetLightColor( g_sLightInfo, 1 ); + else if ( j == 2 ) + cIrisLightingTmp.rgb *= i.vLightFalloffCosine23.x * PixelShaderGetLightColor( g_sLightInfo, 2 ); + else + cIrisLightingTmp.rgb *= i.vLightFalloffCosine23.y * PixelShaderGetLightColor( g_sLightInfo, 3 ); + + // Sum into final variable + cIrisLighting.rgb += cIrisLightingTmp.rgb; + } + + // Add slight view dependent iris lighting based on ambient light intensity to enhance situations with no local lights (0.5f is to help keep it subtle) + cIrisLighting.rgb += saturate( dot( vIrisTangentNormal.xyz, -vTangentViewVector.xyz ) ) * g_flAverageAmbient * fIrisHighlightMask * 0.5f; +#else + // Else, intensify light over cornea to simulate the brightening that happens above + cIrisLighting.rgb += i.cVertexLight.rgb * vCorneaSample.a; +#endif + + //===================// + // Ambient occlusion // + //===================// + float3 cAmbientOcclFromTexture = tex2D( g_tEyeAmbientOcclSampler, i.vAmbientOcclUv_fallbackCorneaUv.xy ).rgb; + float3 cAmbientOcclColor = lerp( g_cAmbientOcclColor, 1.0f, cAmbientOcclFromTexture.rgb ); // Color the ambient occlusion + i.cVertexLight.rgb *= cAmbientOcclColor.rgb; + + //==========================// + // Reflection from cube map // + //==========================// + float3 vCorneaReflectionVector = reflect ( vWorldViewVector.xyz, vCorneaWorldNormal.xyz ); + + //float3 cReflection = ENV_MAP_SCALE * texCUBE( g_tEyeReflectionCubemapSampler, vCorneaReflectionVector.xyz ).rgb; + float3 cReflection = g_flGlossiness * texCUBE( g_tEyeReflectionCubemapSampler, vCorneaReflectionVector.xyz ).rgb; + + // Hack: Only add in half of the env map for the flashlight pass. This looks reasonable. + if ( bFlashlight ) + { + cReflection.rgb *= 0.5f; + } + + //===========================// + // Glint specular highlights // + //===========================// + float3 cSpecularHighlights = 0.0f; + if ( bFlashlight ) + { + cSpecularHighlights.rgb += pow( saturate( dot( vCorneaReflectionVector.xyz, vFlashlightVector.xyz ) ), 128.0f ) * cFlashlightColorFalloff.rgb * cFlashlightColor.rgb; + } + else // no flashlight + { + if ( nNumLights > 0 ) + cSpecularHighlights.rgb += pow( saturate( dot( vCorneaReflectionVector.xyz, PixelShaderGetLightVector( i.vWorldPosition_ProjPosZ.xyz, g_sLightInfo, 0 ) ) ), 128.0f ) * i.vLightFalloffCosine01.x * PixelShaderGetLightColor( g_sLightInfo, 0 ); + + if ( nNumLights > 1 ) + cSpecularHighlights.rgb += pow( saturate( dot( vCorneaReflectionVector.xyz, PixelShaderGetLightVector( i.vWorldPosition_ProjPosZ.xyz, g_sLightInfo, 1 ) ) ), 128.0f ) * i.vLightFalloffCosine01.y * PixelShaderGetLightColor( g_sLightInfo, 1 ); + + if ( nNumLights > 2 ) + cSpecularHighlights.rgb += pow( saturate( dot( vCorneaReflectionVector.xyz, PixelShaderGetLightVector( i.vWorldPosition_ProjPosZ.xyz, g_sLightInfo, 2 ) ) ), 128.0f ) * i.vLightFalloffCosine23.x * PixelShaderGetLightColor( g_sLightInfo, 2 ); + + if ( nNumLights > 3 ) + cSpecularHighlights.rgb += pow( saturate( dot( vCorneaReflectionVector.xyz, PixelShaderGetLightVector( i.vWorldPosition_ProjPosZ.xyz, g_sLightInfo, 3 ) ) ), 128.0f ) * i.vLightFalloffCosine23.y * PixelShaderGetLightColor( g_sLightInfo, 3 ); + } + + //===============// + // Combine terms // + //===============// + float4 result; + + // Unlit iris, pupil, and sclera color + result.rgb = cIrisColor.rgb; + + // Add in slight cornea noise to help define raised cornea layer for close-ups + result.rgb += fCorneaNoise * 0.1f; + + // Diffuse light (Vertex lighting + extra iris caustic lighting) + result.rgb *= i.cVertexLight.rgb + cIrisLighting.rgb; + + // Environment map + result.rgb += cReflection.rgb * i.cVertexLight.rgb; + + // Local light glints + result.rgb += cSpecularHighlights.rgb; + + // Set alpha to 1.0 by default + result.a = 1.0; + +#if !defined( SHADER_MODEL_PS_2_0 ) + float fogFactor = CalcPixelFogFactorConst( g_fPixelFogType, g_FogParams, g_vCameraPosition.z, i.vWorldPosition_ProjPosZ.z, i.vWorldPosition_ProjPosZ.w ); + return FinalOutputConst( result, fogFactor, g_fPixelFogType, TONEMAP_SCALE_LINEAR ); +#else + float fogFactor = CalcPixelFogFactor( PIXEL_FOG_TYPE_NONE, g_FogParams, g_vCameraPosition.z, i.vWorldPosition_ProjPosZ.z, i.vWorldPosition_ProjPosZ.w ); + return FinalOutput( result, fogFactor, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_LINEAR ); +#endif + +} diff --git a/materialsystem/stdshaders/eye_refract_vs20.fxc b/materialsystem/stdshaders/eye_refract_vs20.fxc new file mode 100644 index 0000000..af975f9 --- /dev/null +++ b/materialsystem/stdshaders/eye_refract_vs20.fxc @@ -0,0 +1,217 @@ +//========= Copyright © 1996-2006, Valve Corporation, All rights reserved. ============// + +// STATIC: "INTRO" "0..1" +// STATIC: "HALFLAMBERT" "0..1" +// STATIC: "FLASHLIGHT" "0..1" +// STATIC: "LIGHTWARPTEXTURE" "0..1" + +// DYNAMIC: "COMPRESSED_VERTS" "0..1" +// DYNAMIC: "SKINNING" "0..1" +// DYNAMIC: "DOWATERFOG" "0..1" +// DYNAMIC: "DYNAMIC_LIGHT" "0..1" +// DYNAMIC: "STATIC_LIGHT" "0..1" +// DYNAMIC: "NUM_LIGHTS" "0..4" +// DYNAMIC: "MORPHING" "0..1" [vs30] + +#include "vortwarp_vs20_helper.h" + +static const bool g_bSkinning = SKINNING ? true : false; +static const int g_iFogType = DOWATERFOG; +static const bool g_bHalfLambert = HALFLAMBERT ? true : false; + +const float3 g_cEyeOrigin : register( SHADER_SPECIFIC_CONST_0 ); +const float4 g_vIrisProjectionU : register( SHADER_SPECIFIC_CONST_2 ); +const float4 g_vIrisProjectionV : register( SHADER_SPECIFIC_CONST_3 ); +const float4 g_vFlashlightPosition : register( SHADER_SPECIFIC_CONST_4 ); + +#if INTRO +const float4 g_vConst4 : register( SHADER_SPECIFIC_CONST_5 ); +#define g_vModelOrigin g_vConst4.xyz +#define g_flTime g_vConst4.w +#endif + +const float4 g_vFlashlightMatrixRow1 : register( SHADER_SPECIFIC_CONST_6 ); +const float4 g_vFlashlightMatrixRow2 : register( SHADER_SPECIFIC_CONST_7 ); +const float4 g_vFlashlightMatrixRow3 : register( SHADER_SPECIFIC_CONST_8 ); +const float4 g_vFlashlightMatrixRow4 : register( SHADER_SPECIFIC_CONST_9 ); + +#ifdef SHADER_MODEL_VS_3_0 +// NOTE: cMorphTargetTextureDim.xy = target dimensions, +// cMorphTargetTextureDim.z = 4tuples/morph +const float3 cMorphTargetTextureDim : register( SHADER_SPECIFIC_CONST_10 ); +const float4 cMorphSubrect : register( SHADER_SPECIFIC_CONST_11 ); + +sampler2D morphSampler : register( D3DVERTEXTEXTURESAMPLER0, s0 ); +#endif + +struct VS_INPUT +{ + float4 vPos : POSITION; // Position + float4 vBoneWeights : BLENDWEIGHT; // Skin weights + float4 vBoneIndices : BLENDINDICES; // Skin indices + float4 vTexCoord0 : TEXCOORD0; // Base (sclera) texture coordinates + + // Position deltas + float3 vPosFlex : POSITION1; + +#ifdef SHADER_MODEL_VS_3_0 + float vVertexID : POSITION2; +#endif +}; + +struct VS_OUTPUT +{ + float4 projPos : POSITION; // Projection-space position +#if !defined( _X360 ) + float fog : FOG; // Fixed-function fog factor +#endif + float4 vAmbientOcclUv_fallbackCorneaUv : TEXCOORD0; // Base texture coordinate + float4 cVertexLight : TEXCOORD1; // Vertex-lit color (Note: w is used for flashlight pass) + float4 vTangentViewVector : TEXCOORD2; // Tangent view vector (Note: w is used for flashlight pass) + float4 vWorldPosition_ProjPosZ : TEXCOORD3; + float3 vWorldNormal : TEXCOORD4; // World-space normal + float3 vWorldTangent : TEXCOORD5; // World-space tangent + float4 vLightFalloffCosine01 : TEXCOORD6; // Light falloff and cosine terms for first two local lights + float4 vLightFalloffCosine23 : TEXCOORD7; // Light falloff and cosine terms for next two local lights + + float3 vWorldBinormal : COLOR0; // World-space normal +}; + +VS_OUTPUT main( const VS_INPUT v ) +{ + VS_OUTPUT o; + + bool bDynamicLight = DYNAMIC_LIGHT ? true : false; + bool bStaticLight = STATIC_LIGHT ? true : false; + int nNumLights = NUM_LIGHTS; + + float4 vPosition = v.vPos; + +#if !defined( SHADER_MODEL_VS_3_0 ) || !MORPHING + ApplyMorph( v.vPosFlex, vPosition.xyz ); +#else + ApplyMorph( morphSampler, cMorphTargetTextureDim, cMorphSubrect, v.vVertexID, float3( 0, 0, 0 ), vPosition.xyz ); +#endif + + // Transform the position + float3 vWorldPosition; + SkinPosition( g_bSkinning, vPosition, v.vBoneWeights, v.vBoneIndices, vWorldPosition ); + + // Note: I'm relying on the iris projection vector math not changing or this will break + float3 vEyeSocketUpVector = normalize( -g_vIrisProjectionV.xyz ); + float3 vEyeSocketLeftVector = normalize( -g_vIrisProjectionU.xyz ); + +#if INTRO + float3 dummy = float3( 0.0f, 0.0f, 0.0f ); + WorldSpaceVertexProcess( g_flTime, g_vModelOrigin, vWorldPosition, dummy, dummy, dummy ); +#endif + + o.vWorldPosition_ProjPosZ.xyz = vWorldPosition.xyz; + + // Transform into projection space + //vWorldPosition -= ( vWorldPosition - g_cEyeOrigin ) * 0.9; //Debug to visualize eye origin + float4 vProjPos = mul( float4( vWorldPosition, 1.0f ), cViewProj ); + o.projPos = vProjPos; + vProjPos.z = dot( float4( vWorldPosition, 1.0f ), cViewProjZ ); + + + o.vWorldPosition_ProjPosZ.w = vProjPos.z; + +#if !defined( _X360 ) + // Set fixed-function fog factor + o.fog = CalcFog( vWorldPosition, vProjPos, g_iFogType ); +#endif + + // Normal = (Pos - Eye origin) + float3 vWorldNormal = normalize( vWorldPosition.xyz - g_cEyeOrigin.xyz ); + o.vWorldNormal.xyz = vWorldNormal.xyz; + + // Tangent & binormal + /* + float3 vWorldBinormal = normalize( cross( vWorldNormal.xyz, vEyeSocketLeftVector.xyz ) ); + o.vWorldBinormal.xyz = vWorldBinormal.xyz * 0.5f + 0.5f; + + float3 vWorldTangent = normalize( cross( vWorldBinormal.xyz, vWorldNormal.xyz ) ); + o.vWorldTangent.xyz = vWorldTangent.xyz; + //*/ + + //* + float3 vWorldTangent = normalize( cross( vEyeSocketUpVector.xyz, vWorldNormal.xyz ) ); + o.vWorldTangent.xyz = vWorldTangent.xyz; + + float3 vWorldBinormal = normalize( cross( vWorldNormal.xyz, vWorldTangent.xyz ) ); + o.vWorldBinormal.xyz = vWorldBinormal.xyz * 0.5f + 0.5f; + //*/ + + float3 vWorldViewVector = normalize (vWorldPosition.xyz - cEyePos.xyz); + o.vTangentViewVector.xyz = Vec3WorldToTangentNormalized (vWorldViewVector.xyz, vWorldNormal.xyz, vWorldTangent.xyz, vWorldBinormal.xyz); + + // AV - I think this will effectively make the eyeball less rounded left to right to help vertext lighting quality + // AV - Note: This probably won't look good if put on an exposed eyeball + //float vNormalDotSideVec = -dot( vWorldNormal, g_vEyeballUp ) * 0.5f; + float vNormalDotSideVec = -dot( vWorldNormal, vEyeSocketLeftVector) * 0.5f; + float3 vBentWorldNormal = normalize(vNormalDotSideVec * vEyeSocketLeftVector + vWorldNormal); + + // Compute vertex lighting + o.cVertexLight.a = 0.0f; //Only used for flashlight pass + o.cVertexLight.rgb = DoLightingUnrolled( vWorldPosition, vBentWorldNormal, float3(0.0f, 0.0f, 0.0f), bStaticLight, bDynamicLight, g_bHalfLambert, nNumLights ); + + // Only interpolate ambient light for TF NPR lighting + bool bDoDiffuseWarp = LIGHTWARPTEXTURE ? true : false; + if ( bDoDiffuseWarp ) + { + if( bDynamicLight ) + { + o.cVertexLight.rgb = AmbientLight( vBentWorldNormal.xyz ); + } + else + { + o.cVertexLight.rgb = float3( 0.0f, 0.0f, 0.0f ); + } + } + +// NOTE: it appears that o.vLightFalloffCosine01 and o.vLightFalloffCosine23 are filled in even if +// we don't have enough lights, meaning we pass garbage to the pixel shader which then throws it away + + // Light falloff for first two local lights + o.vLightFalloffCosine01.x = VertexAttenInternal( vWorldPosition.xyz, 0 ); + o.vLightFalloffCosine01.y = VertexAttenInternal( vWorldPosition.xyz, 1 ); + o.vLightFalloffCosine01.z = CosineTermInternal( vWorldPosition.xyz, vWorldNormal.xyz, 0, g_bHalfLambert ); + o.vLightFalloffCosine01.w = CosineTermInternal( vWorldPosition.xyz, vWorldNormal.xyz, 1, g_bHalfLambert ); + + // Light falloff for next two local lights + o.vLightFalloffCosine23.x = VertexAttenInternal( vWorldPosition.xyz, 2 ); + o.vLightFalloffCosine23.y = VertexAttenInternal( vWorldPosition.xyz, 3 ); + o.vLightFalloffCosine23.z = CosineTermInternal( vWorldPosition.xyz, vWorldNormal.xyz, 2, g_bHalfLambert ); + o.vLightFalloffCosine23.w = CosineTermInternal( vWorldPosition.xyz, vWorldNormal.xyz, 3, g_bHalfLambert ); + + // Texture coordinates set by artists for ambient occlusion + o.vAmbientOcclUv_fallbackCorneaUv.xy = v.vTexCoord0.xy; + + // Cornea uv for ps.2.0 fallback + float2 vCorneaUv; // Note: Cornea texture is a cropped version of the iris texture + vCorneaUv.x = dot( g_vIrisProjectionU, float4( vWorldPosition, 1.0f ) ); + vCorneaUv.y = dot( g_vIrisProjectionV, float4( vWorldPosition, 1.0f ) ); + float2 vSphereUv = ( vCorneaUv.xy * 0.5f ) + 0.25f; + o.vAmbientOcclUv_fallbackCorneaUv.wz = vCorneaUv.xy; // Note: wz unpacks faster than zw in ps.2.0! + + // Step on the vertex light interpolator for the flashlight tex coords + bool bFlashlight = ( FLASHLIGHT != 0 ) ? true : false; + o.vTangentViewVector.w = 0.0f; + if ( bFlashlight ) + { + o.cVertexLight.x = dot( g_vFlashlightMatrixRow1.xyzw, float4( vWorldPosition, 1.0f ) ); + o.cVertexLight.y = dot( g_vFlashlightMatrixRow2.xyzw, float4( vWorldPosition, 1.0f ) ); + o.cVertexLight.z = dot( g_vFlashlightMatrixRow3.xyzw, float4( vWorldPosition, 1.0f ) ); + o.cVertexLight.w = dot( g_vFlashlightMatrixRow4.xyzw, float4( vWorldPosition, 1.0f ) ); + + o.vTangentViewVector.w = saturate( dot( vBentWorldNormal.xyz, normalize ( g_vFlashlightPosition.xyz - vWorldPosition.xyz ) ) ); // Flashlight N.L with modified normal + + // Half lambert version + //o.cVertexLight.z = dot( vBentWorldNormal.xyz, normalize ( g_vFlashlightPosition.xyz - vWorldPosition.xyz ) ); // Flashlight N.L with modified normal + //o.cVertexLight.z = ( o.cVertexLight.z * 0.5f ) + 0.5f; + //o.cVertexLight.z *= o.cVertexLight.z; + } + + return o; +} diff --git a/materialsystem/stdshaders/eyeball.cpp b/materialsystem/stdshaders/eyeball.cpp new file mode 100644 index 0000000..7113585 --- /dev/null +++ b/materialsystem/stdshaders/eyeball.cpp @@ -0,0 +1,37 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: Eyeball shader +// +//=============================================================================// + +#include "BaseVSShader.h" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +BEGIN_VS_SHADER( Eyeball, "Help for EyeBall" ) + + BEGIN_SHADER_PARAMS + SHADER_PARAM_OVERRIDE( BASETEXTURE, SHADER_PARAM_TYPE_TEXTURE, "models/alyx/pupil_l", "iris texture", 0 ) + SHADER_PARAM_OVERRIDE( BASETEXTURETRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "unused", SHADER_PARAM_NOT_EDITABLE ) + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + } + + SHADER_FALLBACK + { + // This should be a dead shader... + return "Wireframe"; + } + + SHADER_INIT + { + } + + SHADER_DRAW + { + } + +END_SHADER diff --git a/materialsystem/stdshaders/eyeglint_dx9.cpp b/materialsystem/stdshaders/eyeglint_dx9.cpp new file mode 100644 index 0000000..d2662e6 --- /dev/null +++ b/materialsystem/stdshaders/eyeglint_dx9.cpp @@ -0,0 +1,66 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Run procedural glint generation inner loop in pixel shader +// +// $Header: $ +// $NoKeywords: $ +//===========================================================================// + +#include "BaseVSShader.h" +#include "shaderlib/cshader.h" + +#include "eyeglint_vs20.inc" +#include "eyeglint_ps20.inc" +#include "eyeglint_ps20b.inc" + +DEFINE_FALLBACK_SHADER( EyeGlint, EyeGlint_dx9 ) +BEGIN_VS_SHADER( EyeGlint_dx9, "Help for EyeGlint" ) + +BEGIN_SHADER_PARAMS +END_SHADER_PARAMS + +SHADER_INIT +{ +} + +SHADER_FALLBACK +{ + if ( g_pHardwareConfig->GetDXSupportLevel() < 90 ) + { + return "Wireframe"; + } + return 0; +} + +SHADER_DRAW +{ + SHADOW_STATE + { + pShaderShadow->EnableDepthWrites( false ); + + pShaderShadow->EnableBlending( true ); + pShaderShadow->BlendFunc( SHADER_BLEND_ONE, SHADER_BLEND_ONE ); // Additive blending + + int pTexCoords[3] = { 2, 2, 3 }; + pShaderShadow->VertexShaderVertexFormat( VERTEX_POSITION, 3, pTexCoords, 0 ); + + pShaderShadow->EnableCulling( false ); + + pShaderShadow->EnableSRGBWrite( false ); // linear texture + + DECLARE_STATIC_VERTEX_SHADER( eyeglint_vs20 ); + SET_STATIC_VERTEX_SHADER( eyeglint_vs20 ); + + SET_STATIC_PS2X_PIXEL_SHADER_NO_COMBOS( eyeglint ); + } + + DYNAMIC_STATE + { + DECLARE_DYNAMIC_VERTEX_SHADER( eyeglint_vs20 ); + SET_DYNAMIC_VERTEX_SHADER( eyeglint_vs20 ); + + SET_DYNAMIC_PS2X_PIXEL_SHADER_NO_COMBOS( eyeglint ); + } + Draw(); +} +END_SHADER diff --git a/materialsystem/stdshaders/eyeglint_ps2x.fxc b/materialsystem/stdshaders/eyeglint_ps2x.fxc new file mode 100644 index 0000000..bc39f07 --- /dev/null +++ b/materialsystem/stdshaders/eyeglint_ps2x.fxc @@ -0,0 +1,32 @@ +// ======= Copyright © 1996-2007, Valve Corporation, All rights reserved. ====== +// +// Run procedural glint generation inner loop in pixel shader (ps_2_0) +// +// ============================================================================= + +struct PS_INPUT +{ + float2 tc : TEXCOORD0; // Interpolated coordinate of current texel + float2 glintCenter : TEXCOORD1; // Uniform value containing center of glint + float3 glintColor : TEXCOORD2; // Uniform value of color of glint +}; + +float GlintGaussSpotCoefficient( float2 d ) +{ + return saturate( exp( -25.0f * dot(d, d) ) ); +} + +float4 main( PS_INPUT i ) : COLOR +{ + float2 uv = i.tc - i.glintCenter; // This texel relative to glint center + + float intensity = GlintGaussSpotCoefficient( uv + float2(-0.25f, -0.25f) ) + + GlintGaussSpotCoefficient( uv + float2( 0.25f, -0.25f) ) + + 5 * GlintGaussSpotCoefficient( uv ) + + GlintGaussSpotCoefficient( uv + float2(-0.25f, 0.25f) ) + + GlintGaussSpotCoefficient( uv + float2( 0.25f, 0.25f) ); + + intensity *= 4.0f/9.0f; + + return float4( intensity * i.glintColor, 1.0f ); +} \ No newline at end of file diff --git a/materialsystem/stdshaders/eyeglint_vs20.fxc b/materialsystem/stdshaders/eyeglint_vs20.fxc new file mode 100644 index 0000000..cf1ccb9 --- /dev/null +++ b/materialsystem/stdshaders/eyeglint_vs20.fxc @@ -0,0 +1,38 @@ +//===== Copyright © 1996-2007, Valve Corporation, All rights reserved. ======// +// +// Vertex shader to pass through texcoords needed to run the +// procedural glint generation inner loop in the pixel shader +// +// $Header: $ +// $NoKeywords: $ +//===========================================================================// + +#include "common_vs_fxc.h" + +struct VS_INPUT +{ + float3 vPos : POSITION; + float2 tc : TEXCOORD0; // Interpolated coordinate of current texel in 3x3 quad + float2 glintCenter : TEXCOORD1; // Uniform value containing center of glint in local 3x3 quad + float3 glintColor : TEXCOORD2; // Uniform value of color of glint +}; + +struct VS_OUTPUT +{ + float4 projPos : POSITION; + float2 tc : TEXCOORD0; // Interpolated coordinate of current texel in 3x3 quad + float2 glintCenter : TEXCOORD1; // Uniform value containing center of glint in local 3x3 quad + float3 glintColor : TEXCOORD2; // Uniform value of color of glint +}; + +VS_OUTPUT main( const VS_INPUT v ) +{ + VS_OUTPUT o = ( VS_OUTPUT )0; + o.projPos = float4( v.vPos, 1.0f ); + o.tc = v.tc; + o.glintCenter = v.glintCenter; + o.glintColor = v.glintColor; + return o; +} + + diff --git a/materialsystem/stdshaders/eyes.cpp b/materialsystem/stdshaders/eyes.cpp new file mode 100644 index 0000000..7aa4738 --- /dev/null +++ b/materialsystem/stdshaders/eyes.cpp @@ -0,0 +1,186 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: eye renderer +// +// $Header: $ +// $NoKeywords: $ +//=============================================================================// + +#include "BaseVSShader.h" +#include "eyes_dx8_dx9_helper.h" +#include "cloak_blended_pass_helper.h" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +DEFINE_FALLBACK_SHADER( eyes, Eyes_dx8 ) + +BEGIN_VS_SHADER( Eyes_dx8, + "Help for Eyes" ) + + BEGIN_SHADER_PARAMS + SHADER_PARAM_OVERRIDE( BASETEXTURE, SHADER_PARAM_TYPE_TEXTURE, "models/alyx/eyeball_l", "iris texture", 0 ) + SHADER_PARAM( IRIS, SHADER_PARAM_TYPE_TEXTURE, "models/alyx/pupil_l", "iris texture" ) + SHADER_PARAM( IRISFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "frame for the iris texture" ) + SHADER_PARAM( GLINT, SHADER_PARAM_TYPE_TEXTURE, "models/humans/male/glint", "glint texture" ) + SHADER_PARAM( EYEORIGIN, SHADER_PARAM_TYPE_VEC3, "[0 0 0]", "origin for the eyes" ) + SHADER_PARAM( EYEUP, SHADER_PARAM_TYPE_VEC3, "[0 0 1]", "up vector for the eyes" ) + SHADER_PARAM( IRISU, SHADER_PARAM_TYPE_VEC4, "[0 1 0 0]", "U projection vector for the iris" ) + SHADER_PARAM( IRISV, SHADER_PARAM_TYPE_VEC4, "[0 0 1 0]", "V projection vector for the iris" ) + SHADER_PARAM( GLINTU, SHADER_PARAM_TYPE_VEC4, "[0 1 0 0]", "U projection vector for the glint" ) + SHADER_PARAM( GLINTV, SHADER_PARAM_TYPE_VEC4, "[0 0 1 0]", "V projection vector for the glint" ) + SHADER_PARAM( DILATION, SHADER_PARAM_TYPE_FLOAT, "0", "Iris dilation" ) + SHADER_PARAM( INTRO, SHADER_PARAM_TYPE_BOOL, "0", "is eyes in the ep1 intro" ) + SHADER_PARAM( ENTITYORIGIN, SHADER_PARAM_TYPE_VEC3,"0.0","center if the model in world space" ) + SHADER_PARAM( WARPPARAM, SHADER_PARAM_TYPE_FLOAT,"0.0","animation param between 0 and 1" ) + + // Cloak Pass + SHADER_PARAM( CLOAKPASSENABLED, SHADER_PARAM_TYPE_BOOL, "0", "Enables cloak render in a second pass" ) + SHADER_PARAM( CLOAKFACTOR, SHADER_PARAM_TYPE_FLOAT, "0.0", "" ) + SHADER_PARAM( CLOAKCOLORTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "Cloak color tint" ) + SHADER_PARAM( REFRACTAMOUNT, SHADER_PARAM_TYPE_FLOAT, "2", "" ) + END_SHADER_PARAMS + + void SetupVars( Eyes_DX8_DX9_Vars_t &info ) + { + info.m_nBaseTexture = BASETEXTURE; + info.m_nFrame = FRAME; + info.m_nIris = IRIS; + info.m_nIrisFrame = IRISFRAME; + info.m_nGlint = GLINT; + info.m_nEyeOrigin = EYEORIGIN; + info.m_nEyeUp = EYEUP; + info.m_nIrisU = IRISU; + info.m_nIrisV = IRISV; + info.m_nGlintU = GLINTU; + info.m_nGlintV = GLINTV; + info.m_nDilation = DILATION; + info.m_nIntro = INTRO; + info.m_nEntityOrigin = ENTITYORIGIN; + info.m_nWarpParam = WARPPARAM; + } + + // Cloak Pass + void SetupVarsCloakBlendedPass( CloakBlendedPassVars_t &info ) + { + info.m_nCloakFactor = CLOAKFACTOR; + info.m_nCloakColorTint = CLOAKCOLORTINT; + info.m_nRefractAmount = REFRACTAMOUNT; + } + + bool NeedsPowerOfTwoFrameBufferTexture( IMaterialVar **params, bool bCheckSpecificToThisFrame ) const + { + if ( params[CLOAKPASSENABLED]->GetIntValue() ) // If material supports cloaking + { + if ( bCheckSpecificToThisFrame == false ) // For setting model flag at load time + return true; + else if ( ( params[CLOAKFACTOR]->GetFloatValue() > 0.0f ) && ( params[CLOAKFACTOR]->GetFloatValue() < 1.0f ) ) // Per-frame check + return true; + // else, not cloaking this frame, so check flag2 in case the base material still needs it + } + + // Check flag2 if not drawing cloak pass + return IS_FLAG2_SET( MATERIAL_VAR2_NEEDS_POWER_OF_TWO_FRAME_BUFFER_TEXTURE ); + } + + bool IsTranslucent( IMaterialVar **params ) const + { + if ( params[CLOAKPASSENABLED]->GetIntValue() ) // If material supports cloaking + { + if ( ( params[CLOAKFACTOR]->GetFloatValue() > 0.0f ) && ( params[CLOAKFACTOR]->GetFloatValue() < 1.0f ) ) // Per-frame check + return true; + // else, not cloaking this frame, so check flag in case the base material still needs it + } + + // Check flag if not drawing cloak pass + return IS_FLAG_SET( MATERIAL_VAR_TRANSLUCENT ); + } + + SHADER_INIT_PARAMS() + { + Eyes_DX8_DX9_Vars_t info; + SetupVars( info ); + InitParamsEyes_DX8_DX9( this, params, pMaterialName, info ); + + // Cloak Pass + if ( !params[CLOAKPASSENABLED]->IsDefined() ) + { + params[CLOAKPASSENABLED]->SetIntValue( 0 ); + } + else if ( params[CLOAKPASSENABLED]->GetIntValue() ) + { + CloakBlendedPassVars_t info; + SetupVarsCloakBlendedPass( info ); + InitParamsCloakBlendedPass( this, params, pMaterialName, info ); + } + } + + SHADER_FALLBACK + { + if ( IsPC() && g_pHardwareConfig->GetDXSupportLevel() < 80 ) + return "Eyes_dx6"; + + return 0; + } + + SHADER_INIT + { + Eyes_DX8_DX9_Vars_t info; + SetupVars( info ); + InitEyes_DX8_DX9( this, params, info ); + + // Cloak Pass + if ( params[CLOAKPASSENABLED]->GetIntValue() ) + { + CloakBlendedPassVars_t info; + SetupVarsCloakBlendedPass( info ); + InitCloakBlendedPass( this, params, info ); + } + } + + SHADER_DRAW + { + // Skip the standard rendering if cloak pass is fully opaque + bool bDrawStandardPass = true; + if ( params[CLOAKPASSENABLED]->GetIntValue() && ( pShaderShadow == NULL ) ) // && not snapshotting + { + CloakBlendedPassVars_t info; + SetupVarsCloakBlendedPass( info ); + if ( CloakBlendedPassIsFullyOpaque( params, info ) ) + { + // There is some strangeness in DX8 when trying to skip the main pass, so leave this alone for now + //bDrawStandardPass = false; + } + } + + // Standard rendering pass + if ( bDrawStandardPass ) + { + Eyes_DX8_DX9_Vars_t info; + SetupVars( info ); + DrawEyes_DX8_DX9( false, this, params, pShaderAPI, pShaderShadow, info, vertexCompression ); + } + else + { + // Skip this pass! + Draw( false ); + } + + // Cloak Pass + if ( params[CLOAKPASSENABLED]->GetIntValue() ) + { + // If ( snapshotting ) or ( we need to draw this frame ) + if ( ( pShaderShadow != NULL ) || ( ( params[CLOAKFACTOR]->GetFloatValue() > 0.0f ) && ( params[CLOAKFACTOR]->GetFloatValue() < 1.0f ) ) ) + { + CloakBlendedPassVars_t info; + SetupVarsCloakBlendedPass( info ); + DrawCloakBlendedPass( this, params, pShaderAPI, pShaderShadow, info, vertexCompression ); + } + else // We're not snapshotting and we don't need to draw this frame + { + // Skip this pass! + Draw( false ); + } + } + } +END_SHADER diff --git a/materialsystem/stdshaders/eyes.vsh b/materialsystem/stdshaders/eyes.vsh new file mode 100644 index 0000000..58ae021 --- /dev/null +++ b/materialsystem/stdshaders/eyes.vsh @@ -0,0 +1,80 @@ +vs.1.1 +;------------------------------------------------------------------------------ +; $SHADER_SPECIFIC_CONST_0 = eyeball origin +; $SHADER_SPECIFIC_CONST_1 = eyeball up * 0.5 +; $SHADER_SPECIFIC_CONST_2 = iris projection U +; $SHADER_SPECIFIC_CONST_3 = iris projection V +; $SHADER_SPECIFIC_CONST_4 = glint projection U +; $SHADER_SPECIFIC_CONST_5 = glint projection V +;------------------------------------------------------------------------------ + +# STATIC: "HALF_LAMBERT" "0..1" +# DYNAMIC: "DOWATERFOG" "0..1" +# DYNAMIC: "LIGHT_COMBO" "0..21" +# DYNAMIC: "SKINNING" "0..1" + +#include "macros.vsh" + +;------------------------------------------------------------------------------ +; Vertex blending (whacks r1-r7, positions in r7) +;------------------------------------------------------------------------------ +&AllocateRegister( \$worldPos ); +&SkinPosition( $worldPos ); + +;------------------------------------------------------------------------------ +; Transform the position from world to view space +;------------------------------------------------------------------------------ + +&AllocateRegister( \$projPos ); + +dp4 $projPos.x, $worldPos, $cViewProj0 +dp4 $projPos.y, $worldPos, $cViewProj1 +dp4 $projPos.z, $worldPos, $cViewProj2 +dp4 $projPos.w, $worldPos, $cViewProj3 +mov oPos, $projPos + +;------------------------------------------------------------------------------ +; Normal is based on vertex position +;------------------------------------------------------------------------------ +&AllocateRegister( \$worldNormal ); +&AllocateRegister( \$normalDotUp ); + +sub $worldNormal, $worldPos, $SHADER_SPECIFIC_CONST_0 ; Normal = (Pos - Eye origin) +dp3 $normalDotUp, $worldNormal, $SHADER_SPECIFIC_CONST_1 ; Normal -= 0.5f * (Normal dot Eye Up) * Eye Up +mul $normalDotUp, $normalDotUp, $cHalf +mad $worldNormal, -$normalDotUp, $SHADER_SPECIFIC_CONST_1, $worldNormal + +&FreeRegister( \$normalDotUp ); + +; normalize the normal +&Normalize( $worldNormal ); + +;------------------------------------------------------------------------------ +; Lighting +;------------------------------------------------------------------------------ +&DoLighting( $worldPos, $worldNormal ); + +&FreeRegister( \$worldNormal ); + +;------------------------------------------------------------------------------ +; Fog +;------------------------------------------------------------------------------ + +&CalcFog( $worldPos, $projPos ); + +&FreeRegister( \$projPos ); + +;------------------------------------------------------------------------------ +; Texture coordinates +; Texture 0 is the base texture +; Texture 1 is a planar projection used for the iris +; Texture 2 is a planar projection used for the glint +;------------------------------------------------------------------------------ + +mov oT0, $vTexCoord0 +dp4 oT1.x, $SHADER_SPECIFIC_CONST_2, $worldPos +dp4 oT1.y, $SHADER_SPECIFIC_CONST_3, $worldPos +dp4 oT2.x, $SHADER_SPECIFIC_CONST_4, $worldPos +dp4 oT2.y, $SHADER_SPECIFIC_CONST_5, $worldPos + +&FreeRegister( \$worldPos ); diff --git a/materialsystem/stdshaders/eyes_dx6.cpp b/materialsystem/stdshaders/eyes_dx6.cpp new file mode 100644 index 0000000..f545459 --- /dev/null +++ b/materialsystem/stdshaders/eyes_dx6.cpp @@ -0,0 +1,251 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: Teeth renderer +// +// $Header: $ +// $NoKeywords: $ +//=============================================================================// + +#include "BaseVSShader.h" +#include "mathlib/vmatrix.h" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +DEFINE_FALLBACK_SHADER( Eyes, Eyes_dx6 ) + +BEGIN_VS_SHADER( Eyes_dx6, + "Help for Eyes" ) + + BEGIN_SHADER_PARAMS + SHADER_PARAM( IRIS, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "iris texture" ) + SHADER_PARAM( IRISFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "frame for the iris texture" ) + SHADER_PARAM( GLINT, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "glint texture" ) + SHADER_PARAM( EYEORIGIN, SHADER_PARAM_TYPE_VEC3, "[0 0 0]", "origin for the eyes" ) + SHADER_PARAM( EYEUP, SHADER_PARAM_TYPE_VEC3, "[0 0 1]", "up vector for the eyes" ) + SHADER_PARAM( IRISU, SHADER_PARAM_TYPE_VEC4, "[0 1 0 0 ]", "U projection vector for the iris" ) + SHADER_PARAM( IRISV, SHADER_PARAM_TYPE_VEC4, "[0 0 1 0]", "V projection vector for the iris" ) + SHADER_PARAM( GLINTU, SHADER_PARAM_TYPE_VEC4, "[0 1 0 0]", "U projection vector for the glint" ) + SHADER_PARAM( GLINTV, SHADER_PARAM_TYPE_VEC4, "[0 0 1 0]", "V projection vector for the glint" ) + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + // FLASHLIGHTFIXME + params[FLASHLIGHTTEXTURE]->SetStringValue( "effects/flashlight001" ); + + SET_FLAGS2( MATERIAL_VAR2_SUPPORTS_HW_SKINNING ); + } + + SHADER_INIT + { + LoadTexture( FLASHLIGHTTEXTURE ); + LoadTexture( BASETEXTURE ); + LoadTexture( IRIS ); + } + + void SetTextureTransform( IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, + MaterialMatrixMode_t textureTransform, int uparam, int vparam ) + { + Vector4D u, v; + params[uparam]->GetVecValue( u.Base(), 4 ); + params[vparam]->GetVecValue( v.Base(), 4 ); + + // Need to transform these puppies into camera space + // they are defined in world space + VMatrix mat, invTrans; + pShaderAPI->GetMatrix( MATERIAL_VIEW, mat.m[0] ); + mat = mat.Transpose(); + + // Compute the inverse transpose of the matrix + // NOTE: I only have to invert it here because VMatrix is transposed + // with respect to what gets returned from GetMatrix. + mat.InverseGeneral( invTrans ); + invTrans = invTrans.Transpose(); + + // Transform the u and v planes into view space + Vector4D uview, vview; + uview.AsVector3D() = invTrans.VMul3x3( u.AsVector3D() ); + vview.AsVector3D() = invTrans.VMul3x3( v.AsVector3D() ); + uview[3] = u[3] - DotProduct( mat.GetTranslation(), uview.AsVector3D() ); + vview[3] = v[3] - DotProduct( mat.GetTranslation(), vview.AsVector3D() ); + + float m[16]; + m[0] = uview[0]; m[1] = vview[0]; m[2] = 0.0f; m[3] = 0.0f; + m[4] = uview[1]; m[5] = vview[1]; m[6] = 0.0f; m[7] = 0.0f; + m[8] = uview[2]; m[9] = vview[2]; m[10] = 1.0f; m[11] = 0.0f; + m[12] = uview[3]; m[13] = vview[3]; m[14] = 0.0f; m[15] = 1.0f; + + pShaderAPI->MatrixMode( textureTransform ); + pShaderAPI->LoadMatrix( m ); + } + + void DrawFlashlight_Iris( IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow ) + { + SHADOW_STATE + { + SET_FLAGS2( MATERIAL_VAR2_NEEDS_FIXED_FUNCTION_FLASHLIGHT ); + + // Alpha blend + pShaderShadow->EnableBlending( true ); + pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA ); + + pShaderShadow->EnableDepthWrites( false ); + pShaderShadow->EnableAlphaWrites( false ); + + int flags = SHADER_DRAW_POSITION | SHADER_DRAW_COLOR | SHADER_DRAW_NORMAL; + pShaderShadow->DrawFlags( flags ); + FogToBlack(); + + pShaderShadow->EnableLighting( true ); + + pShaderShadow->EnableCustomPixelPipe( true ); + pShaderShadow->CustomTextureStages( 2 ); + + pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE0, + SHADER_TEXCHANNEL_COLOR, + SHADER_TEXOP_MODULATE, + SHADER_TEXARG_TEXTURE, + SHADER_TEXARG_VERTEXCOLOR ); + + pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE1, + SHADER_TEXCHANNEL_COLOR, + SHADER_TEXOP_MODULATE, + SHADER_TEXARG_TEXTURE, SHADER_TEXARG_PREVIOUSSTAGE ); + + // alpha stage 0 + // get alpha from constant alpha + pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE0, + SHADER_TEXCHANNEL_ALPHA, + SHADER_TEXOP_SELECTARG1, + SHADER_TEXARG_CONSTANTCOLOR, SHADER_TEXARG_NONE ); + + // alpha stage 1 + // get alpha from $basetexture + pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE1, + SHADER_TEXCHANNEL_ALPHA, + SHADER_TEXOP_MODULATE, + SHADER_TEXARG_TEXTURE, SHADER_TEXARG_PREVIOUSSTAGE ); + + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + + // Shove the view position into texcoord 0 before the texture matrix. + pShaderShadow->TexGen( SHADER_TEXTURE_STAGE0, SHADER_TEXGENPARAM_EYE_LINEAR ); + pShaderShadow->EnableTexGen( SHADER_TEXTURE_STAGE0, true ); + + // iris transform + pShaderShadow->EnableTexGen( SHADER_TEXTURE_STAGE1, true ); + pShaderShadow->TexGen( SHADER_TEXTURE_STAGE1, SHADER_TEXGENPARAM_EYE_LINEAR ); + + } + DYNAMIC_STATE + { + SetFlashlightFixedFunctionTextureTransform( MATERIAL_TEXTURE0 ); + + // NOTE: This has to come after the loadmatrix since the loadmatrix screws with the + // transform flags!!!!!! + // Specify that we have XYZ texcoords that need to be divided by W before the pixel shader. + // NOTE Tried to divide XY by Z, but doesn't work. + pShaderAPI->SetTextureTransformDimension( SHADER_TEXTURE_STAGE0, 3, true ); + + BindTexture( SHADER_SAMPLER0, FLASHLIGHTTEXTURE, FLASHLIGHTTEXTUREFRAME ); + + BindTexture( SHADER_SAMPLER1, IRIS, IRISFRAME ); + SetTextureTransform( params, pShaderAPI, MATERIAL_TEXTURE1, IRISU, IRISV ); + } + Draw(); + } + + void DrawFlashlight( IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow ) + { + // whites + DrawFlashlight_dx70( params, pShaderAPI, pShaderShadow, + FLASHLIGHTTEXTURE, FLASHLIGHTTEXTUREFRAME, true ); + + // iris + DrawFlashlight_Iris( params, pShaderAPI, pShaderShadow ); + } + + void DrawUsingSoftwareLighting( IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow ) + { + // whites + SHADOW_STATE + { + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->OverbrightValue( SHADER_TEXTURE_STAGE0, OVERBRIGHT ); + pShaderShadow->DrawFlags( SHADER_DRAW_POSITION | SHADER_DRAW_COLOR | SHADER_DRAW_TEXCOORD0 ); + FogToFogColor(); + } + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME ); + } + Draw(); + + // iris + SHADOW_STATE + { + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->OverbrightValue( SHADER_TEXTURE_STAGE0, OVERBRIGHT ); + pShaderShadow->DrawFlags( SHADER_DRAW_POSITION | SHADER_DRAW_COLOR ); + pShaderShadow->EnableTexGen( SHADER_TEXTURE_STAGE0, true ); + pShaderShadow->TexGen( SHADER_TEXTURE_STAGE0, SHADER_TEXGENPARAM_EYE_LINEAR ); + pShaderShadow->EnableBlending( true ); + pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA ); + FogToFogColor(); + } + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER0, IRIS, IRISFRAME ); + SetTextureTransform( params, pShaderAPI, MATERIAL_TEXTURE0, IRISU, IRISV ); + } + Draw(); + + // Glint + SHADOW_STATE + { + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER1, false ); + pShaderShadow->OverbrightValue( SHADER_TEXTURE_STAGE0, 1.0f ); + pShaderShadow->OverbrightValue( SHADER_TEXTURE_STAGE1, 1.0f ); + + pShaderShadow->EnableConstantColor( true ); + pShaderShadow->EnableDepthWrites( false ); + pShaderShadow->EnableBlending( true ); + pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE ); + + pShaderShadow->EnableTexGen( SHADER_TEXTURE_STAGE0, true ); + pShaderShadow->TexGen( SHADER_TEXTURE_STAGE0, SHADER_TEXGENPARAM_EYE_LINEAR ); + + pShaderShadow->DrawFlags( SHADER_DRAW_POSITION ); + FogToBlack(); + } + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER0, GLINT ); + SetTextureTransform( params, pShaderAPI, MATERIAL_TEXTURE0, GLINTU, GLINTV ); + } + Draw( ); + } + + SHADER_DRAW + { + SHADOW_STATE + { + SET_FLAGS2( MATERIAL_VAR2_LIGHTING_VERTEX_LIT ); + } + bool hasFlashlight = UsingFlashlight( params ); + + if( hasFlashlight ) + { + DrawFlashlight( params, pShaderAPI, pShaderShadow ); + } + else + { + DrawUsingSoftwareLighting( params, pShaderAPI, pShaderShadow ); + } + + } +END_SHADER + diff --git a/materialsystem/stdshaders/eyes_dx8_dx9_helper.cpp b/materialsystem/stdshaders/eyes_dx8_dx9_helper.cpp new file mode 100644 index 0000000..e1edda0 --- /dev/null +++ b/materialsystem/stdshaders/eyes_dx8_dx9_helper.cpp @@ -0,0 +1,550 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//============================================================================= + +#include "BaseVSShader.h" +#include "tier1/convar.h" +#include "mathlib/vmatrix.h" +#include "eyes_dx8_dx9_helper.h" +#include "cpp_shader_constant_register_map.h" +#include "Eyes.inc" +#include "eyes_flashlight_vs11.inc" +#include "eyes_flashlight_ps11.inc" + +#ifdef STDSHADER_DX9_DLL_EXPORT + +#include "eyes_vs20.inc" +#include "eyes_ps20.inc" +#include "eyes_ps20b.inc" +#include "eyes_flashlight_vs20.inc" +#include "eyes_flashlight_ps20.inc" +#include "eyes_flashlight_ps20b.inc" + +#ifndef _X360 +#include "eyes_vs30.inc" +#include "eyes_ps30.inc" +#include "eyes_flashlight_vs30.inc" +#include "eyes_flashlight_ps30.inc" +#endif + +#endif + +ConVar r_flashlight_version2( "r_flashlight_version2", "0", FCVAR_CHEAT | FCVAR_DEVELOPMENTONLY ); + +void InitParamsEyes_DX8_DX9( CBaseVSShader *pShader, IMaterialVar** params, const char *pMaterialName, + Eyes_DX8_DX9_Vars_t &info ) +{ + if ( g_pHardwareConfig->SupportsBorderColor() ) + { + params[FLASHLIGHTTEXTURE]->SetStringValue( "effects/flashlight_border" ); + } + else + { + params[FLASHLIGHTTEXTURE]->SetStringValue( "effects/flashlight001" ); + } + + SET_FLAGS2( MATERIAL_VAR2_SUPPORTS_HW_SKINNING ); + SET_FLAGS2( MATERIAL_VAR2_LIGHTING_VERTEX_LIT ); + + Assert( info.m_nIntro != -1 ); + if( info.m_nIntro != -1 && !params[info.m_nIntro]->IsDefined() ) + { + params[info.m_nIntro]->SetIntValue( 0 ); + } +} + +void InitEyes_DX8_DX9( CBaseVSShader *pShader, IMaterialVar** params, Eyes_DX8_DX9_Vars_t &info ) +{ + pShader->LoadTexture( FLASHLIGHTTEXTURE, TEXTUREFLAGS_SRGB ); + pShader->LoadTexture( info.m_nBaseTexture, TEXTUREFLAGS_SRGB ); + pShader->LoadTexture( info.m_nIris, TEXTUREFLAGS_SRGB ); + pShader->LoadTexture( info.m_nGlint ); + + // Be sure dilation is zeroed if undefined + if( !params[info.m_nDilation]->IsDefined() ) + { + params[info.m_nDilation]->SetFloatValue( 0.0f ); + } +} + +static void SetDepthFlashlightParams( CBaseVSShader *pShader, IShaderDynamicAPI *pShaderAPI, const VMatrix& worldToTexture, const FlashlightState_t& flashlightState ) +{ + float atten[4], pos[4], tweaks[4]; + atten[0] = flashlightState.m_fConstantAtten; // Set the flashlight attenuation factors + atten[1] = flashlightState.m_fLinearAtten; + atten[2] = flashlightState.m_fQuadraticAtten; + atten[3] = flashlightState.m_FarZ; + pShaderAPI->SetPixelShaderConstant( PSREG_FLASHLIGHT_ATTENUATION, atten, 1 ); + + pos[0] = flashlightState.m_vecLightOrigin[0]; // Set the flashlight origin + pos[1] = flashlightState.m_vecLightOrigin[1]; + pos[2] = flashlightState.m_vecLightOrigin[2]; + pShaderAPI->SetPixelShaderConstant( PSREG_FLASHLIGHT_POSITION_RIM_BOOST, pos, 1 ); + + pShaderAPI->SetPixelShaderConstant( PSREG_FLASHLIGHT_TO_WORLD_TEXTURE, worldToTexture.Base(), 4 ); + + // Tweaks associated with a given flashlight + tweaks[0] = ShadowFilterFromState( flashlightState ); + tweaks[1] = ShadowAttenFromState( flashlightState ); + pShader->HashShadow2DJitter( flashlightState.m_flShadowJitterSeed, &tweaks[2], &tweaks[3] ); + pShaderAPI->SetPixelShaderConstant( PSREG_ENVMAP_TINT__SHADOW_TWEAKS, tweaks, 1 ); + + // Dimensions of screen, used for screen-space noise map sampling + float vScreenScale[4] = {1280.0f / 32.0f, 720.0f / 32.0f, 0, 0}; + int nWidth, nHeight; + pShaderAPI->GetBackBufferDimensions( nWidth, nHeight ); + vScreenScale[0] = (float) nWidth / 32.0f; + vScreenScale[1] = (float) nHeight / 32.0f; + pShaderAPI->SetPixelShaderConstant( PSREG_FLASHLIGHT_SCREEN_SCALE, vScreenScale, 1 ); + + if ( IsX360() ) + { + pShaderAPI->SetBooleanPixelShaderConstant( 0, &flashlightState.m_nShadowQuality, 1 ); + } +} + + +static void DrawFlashlight( bool bDX9, CBaseVSShader *pShader, IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, + IShaderShadow* pShaderShadow, Eyes_DX8_DX9_Vars_t &info, VertexCompressionType_t vertexCompression ) +{ + if( pShaderShadow ) + { + pShaderShadow->EnableDepthWrites( false ); + + pShader->EnableAlphaBlending( SHADER_BLEND_ONE, SHADER_BLEND_ONE ); // Write over the eyes that were already there + + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); // Spot + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); // Base + pShaderShadow->EnableTexture( SHADER_SAMPLER2, true ); // Normalizing cubemap + pShaderShadow->EnableTexture( SHADER_SAMPLER3, true ); // Iris + + // Set stream format (note that this shader supports compression) + int flags = VERTEX_POSITION | VERTEX_NORMAL | VERTEX_FORMAT_COMPRESSED; + int nTexCoordCount = 1; + int userDataSize = 0; + pShaderShadow->VertexShaderVertexFormat( flags, nTexCoordCount, NULL, userDataSize ); + + // Be sure not to write to dest alpha + pShaderShadow->EnableAlphaWrites( false ); + +#ifdef STDSHADER_DX9_DLL_EXPORT + if ( bDX9 ) + { + int nShadowFilterMode = g_pHardwareConfig->GetShadowFilterMode(); // Based upon vendor and device dependent formats +#ifndef _X360 + if ( !g_pHardwareConfig->HasFastVertexTextures() ) +#endif + { + DECLARE_STATIC_VERTEX_SHADER( eyes_flashlight_vs20 ); + SET_STATIC_VERTEX_SHADER( eyes_flashlight_vs20 ); + + if ( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_STATIC_PIXEL_SHADER( eyes_flashlight_ps20b ); + SET_STATIC_PIXEL_SHADER_COMBO( FLASHLIGHTDEPTHFILTERMODE, nShadowFilterMode ); + SET_STATIC_PIXEL_SHADER( eyes_flashlight_ps20b ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( eyes_flashlight_ps20 ); + SET_STATIC_PIXEL_SHADER( eyes_flashlight_ps20 ); + } + } +#ifndef _X360 + else + { + // The vertex shader uses the vertex id stream + SET_FLAGS2( MATERIAL_VAR2_USES_VERTEXID ); + + DECLARE_STATIC_VERTEX_SHADER( eyes_flashlight_vs30 ); + SET_STATIC_VERTEX_SHADER( eyes_flashlight_vs30 ); + + DECLARE_STATIC_PIXEL_SHADER( eyes_flashlight_ps30 ); + SET_STATIC_PIXEL_SHADER_COMBO( FLASHLIGHTDEPTHFILTERMODE, nShadowFilterMode ); + SET_STATIC_PIXEL_SHADER( eyes_flashlight_ps30 ); + } +#endif + + // On DX9, get the gamma read and write correct + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, true ); // Spot + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER1, true ); // Base + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER3, true ); // Iris + pShaderShadow->EnableSRGBWrite( true ); + + if ( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER4, true ); // Shadow depth map + pShaderShadow->SetShadowDepthFiltering( SHADER_SAMPLER4 ); + pShaderShadow->EnableTexture( SHADER_SAMPLER5, true ); // Shadow noise rotation map + } + } + else +#endif + { + // DX8 uses old asm shaders + eyes_flashlight_vs11_Static_Index vshIndex; + pShaderShadow->SetVertexShader( "eyes_flashlight_vs11", vshIndex.GetIndex() ); + + eyes_flashlight_ps11_Static_Index pshIndex; + pShaderShadow->SetPixelShader( "eyes_flashlight_ps11", pshIndex.GetIndex() ); + } + + pShader->FogToBlack(); + } + else + { + // Specify that we have XYZ texcoords that need to be divided by W before the pixel shader. + // NOTE Tried to divide XY by Z, but doesn't work. + // The dx9.0c runtime says that we shouldn't have a non-zero dimension when using vertex and pixel shaders. + if ( !bDX9 ) + { + pShaderAPI->SetTextureTransformDimension( SHADER_TEXTURE_STAGE0, 0, true ); + } + + VMatrix worldToTexture; + ITexture *pFlashlightDepthTexture; + FlashlightState_t flashlightState = pShaderAPI->GetFlashlightStateEx( worldToTexture, &pFlashlightDepthTexture ); + + pShader->BindTexture( SHADER_SAMPLER0, flashlightState.m_pSpotlightTexture, flashlightState.m_nSpotlightTextureFrame ); + pShader->BindTexture( SHADER_SAMPLER1, info.m_nBaseTexture, info.m_nFrame ); + pShaderAPI->BindStandardTexture( SHADER_SAMPLER2, TEXTURE_NORMALIZATION_CUBEMAP ); + pShader->BindTexture( SHADER_SAMPLER3, info.m_nIris, info.m_nIrisFrame ); + +#ifdef STDSHADER_DX9_DLL_EXPORT + if ( bDX9 ) + { + +#ifndef _X360 + if ( !g_pHardwareConfig->HasFastVertexTextures() ) +#endif + { + DECLARE_DYNAMIC_VERTEX_SHADER( eyes_flashlight_vs20 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( DOWATERFOG, pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, pShaderAPI->GetCurrentNumBones() > 0 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression ); + SET_DYNAMIC_VERTEX_SHADER( eyes_flashlight_vs20 ); + } +#ifndef _X360 + else + { + pShader->SetHWMorphVertexShaderState( VERTEX_SHADER_SHADER_SPECIFIC_CONST_10, VERTEX_SHADER_SHADER_SPECIFIC_CONST_11, SHADER_VERTEXTEXTURE_SAMPLER0 ); + + DECLARE_DYNAMIC_VERTEX_SHADER( eyes_flashlight_vs30 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( DOWATERFOG, pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, pShaderAPI->GetCurrentNumBones() > 0 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( MORPHING, pShaderAPI->IsHWMorphingEnabled() ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression ); + SET_DYNAMIC_VERTEX_SHADER( eyes_flashlight_vs30 ); + } +#endif + +// float vPSConst[4] = {params[info.m_nDilation]->GetFloatValue(), 0.0f, 0.0f, 0.0f}; +// pShaderAPI->SetPixelShaderConstant( 0, vPSConst, 1 ); + + VMatrix worldToTexture; + ITexture *pFlashlightDepthTexture; + FlashlightState_t flashlightState = pShaderAPI->GetFlashlightStateEx( worldToTexture, &pFlashlightDepthTexture ); + SetFlashLightColorFromState( flashlightState, pShaderAPI ); + + if( pFlashlightDepthTexture && g_pConfig->ShadowDepthTexture() && flashlightState.m_bEnableShadows ) + { + pShader->BindTexture( SHADER_SAMPLER4, pFlashlightDepthTexture, 0 ); + pShaderAPI->BindStandardTexture( SHADER_SAMPLER5, TEXTURE_SHADOW_NOISE_2D ); + } + + pShaderAPI->SetPixelShaderFogParams( PSREG_FOG_PARAMS ); + + float vEyePos_SpecExponent[4]; + pShaderAPI->GetWorldSpaceCameraPosition( vEyePos_SpecExponent ); + vEyePos_SpecExponent[3] = 0.0f; + pShaderAPI->SetPixelShaderConstant( PSREG_EYEPOS_SPEC_EXPONENT, vEyePos_SpecExponent, 1 ); + +#ifndef _X360 + if ( !g_pHardwareConfig->HasFastVertexTextures() ) +#endif + { + if ( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_DYNAMIC_PIXEL_SHADER( eyes_flashlight_ps20b ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( FLASHLIGHTSHADOWS, flashlightState.m_bEnableShadows && ( pFlashlightDepthTexture != NULL ) ); + SET_DYNAMIC_PIXEL_SHADER( eyes_flashlight_ps20b ); + + SetDepthFlashlightParams( pShader, pShaderAPI, worldToTexture, flashlightState ); + } + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( eyes_flashlight_ps20 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + SET_DYNAMIC_PIXEL_SHADER( eyes_flashlight_ps20 ); + } + } +#ifndef _X360 + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( eyes_flashlight_ps30 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( FLASHLIGHTSHADOWS, flashlightState.m_bEnableShadows && ( pFlashlightDepthTexture != NULL ) ); + SET_DYNAMIC_PIXEL_SHADER( eyes_flashlight_ps30 ); + + SetDepthFlashlightParams( pShader, pShaderAPI, worldToTexture, flashlightState ); + } +#endif + } + else // older asm shaders for DX8 +#endif + { + eyes_flashlight_vs11_Dynamic_Index vshIndex; + vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + vshIndex.SetSKINNING( pShaderAPI->GetCurrentNumBones() > 0 ); + pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() ); + + eyes_flashlight_ps11_Dynamic_Index pshIndex; + pShaderAPI->SetPixelShaderIndex( pshIndex.GetIndex() ); + } + + // This uses from VERTEX_SHADER_SHADER_SPECIFIC_CONST_0 to VERTEX_SHADER_SHADER_SPECIFIC_CONST_5 + pShader->SetFlashlightVertexShaderConstants( false, -1, false, -1, false ); + + pShader->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_6, info.m_nEyeOrigin ); + pShader->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_7, info.m_nEyeUp ); + pShader->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_8, info.m_nIrisU ); + pShader->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_9, info.m_nIrisV ); + } + pShader->Draw(); +} + +static void DrawUsingVertexShader( bool bDX9, CBaseVSShader *pShader, IMaterialVar** params, + IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow, + Eyes_DX8_DX9_Vars_t &info, VertexCompressionType_t vertexCompression ) +{ + SHADOW_STATE + { + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); // Base + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); // Iris + pShaderShadow->EnableTexture( SHADER_SAMPLER2, true ); // Glint + + // Set stream format (note that this shader supports compression) + int flags = VERTEX_POSITION | VERTEX_NORMAL | VERTEX_FORMAT_COMPRESSED; + int nTexCoordCount = 1; + int userDataSize = 0; + pShaderShadow->VertexShaderVertexFormat( flags, nTexCoordCount, NULL, userDataSize ); + + pShaderShadow->EnableAlphaWrites( true ); //we end up hijacking destination alpha for opaques most of the time. + +#ifdef STDSHADER_DX9_DLL_EXPORT + if ( bDX9 ) + { +#ifndef _X360 + if ( !g_pHardwareConfig->HasFastVertexTextures() ) +#endif + { + bool bUseStaticControlFlow = g_pHardwareConfig->SupportsStaticControlFlow(); + + DECLARE_STATIC_VERTEX_SHADER( eyes_vs20 ); + SET_STATIC_VERTEX_SHADER_COMBO( HALFLAMBERT, IS_FLAG_SET( MATERIAL_VAR_HALFLAMBERT ) ); + SET_STATIC_VERTEX_SHADER_COMBO( INTRO, params[info.m_nIntro]->GetIntValue() ? 1 : 0 ); + SET_STATIC_VERTEX_SHADER_COMBO( USE_STATIC_CONTROL_FLOW, bUseStaticControlFlow ); + SET_STATIC_VERTEX_SHADER( eyes_vs20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_STATIC_PIXEL_SHADER( eyes_ps20b ); + SET_STATIC_PIXEL_SHADER( eyes_ps20b ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( eyes_ps20 ); + SET_STATIC_PIXEL_SHADER( eyes_ps20 ); + } + } +#ifndef _X360 + else + { + // The vertex shader uses the vertex id stream + SET_FLAGS2( MATERIAL_VAR2_USES_VERTEXID ); + + DECLARE_STATIC_VERTEX_SHADER( eyes_vs30 ); + SET_STATIC_VERTEX_SHADER_COMBO( HALFLAMBERT, IS_FLAG_SET( MATERIAL_VAR_HALFLAMBERT ) ); + SET_STATIC_VERTEX_SHADER_COMBO( INTRO, params[info.m_nIntro]->GetIntValue() ? 1 : 0 ); + SET_STATIC_VERTEX_SHADER( eyes_vs30 ); + + DECLARE_STATIC_PIXEL_SHADER( eyes_ps30 ); + SET_STATIC_PIXEL_SHADER( eyes_ps30 ); + } +#endif + // On DX9, get the gamma read and write correct + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, true ); // Base + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER1, true ); // White + pShaderShadow->EnableSRGBWrite( true ); + } + else +#endif + { + eyes_Static_Index vshIndex; + vshIndex.SetHALF_LAMBERT( IS_FLAG_SET( MATERIAL_VAR_HALFLAMBERT ) ); + pShaderShadow->SetVertexShader( "Eyes", vshIndex.GetIndex() ); + + pShaderShadow->SetPixelShader( "Eyes_Overbright2" ); + } + + pShader->FogToFogColor(); + } + DYNAMIC_STATE + { + pShader->BindTexture( SHADER_SAMPLER0, info.m_nBaseTexture, info.m_nFrame ); + pShader->BindTexture( SHADER_SAMPLER1, info.m_nIris, info.m_nIrisFrame ); + pShader->BindTexture( SHADER_SAMPLER2, info.m_nGlint ); + pShader->SetAmbientCubeDynamicStateVertexShader(); + pShader->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, info.m_nEyeOrigin ); + pShader->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_1, info.m_nEyeUp ); + pShader->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_2, info.m_nIrisU ); + pShader->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_3, info.m_nIrisV ); + pShader->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_4, info.m_nGlintU ); + pShader->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_5, info.m_nGlintV ); + +#ifdef STDSHADER_DX9_DLL_EXPORT + if( bDX9 ) + { + LightState_t lightState; + pShaderAPI->GetDX9LightState( &lightState ); + +#ifndef _X360 + if ( !g_pHardwareConfig->HasFastVertexTextures() ) +#endif + { + bool bUseStaticControlFlow = g_pHardwareConfig->SupportsStaticControlFlow(); + + DECLARE_DYNAMIC_VERTEX_SHADER( eyes_vs20 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( DOWATERFOG, pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, pShaderAPI->GetCurrentNumBones() > 0 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( DYNAMIC_LIGHT, lightState.HasDynamicLight() ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( STATIC_LIGHT, lightState.m_bStaticLightVertex ? 1 : 0 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( NUM_LIGHTS, bUseStaticControlFlow ? 0 : lightState.m_nNumLights ); + SET_DYNAMIC_VERTEX_SHADER( eyes_vs20 ); + } +#ifndef _X360 + else + { + pShader->SetHWMorphVertexShaderState( VERTEX_SHADER_SHADER_SPECIFIC_CONST_7, VERTEX_SHADER_SHADER_SPECIFIC_CONST_8, SHADER_VERTEXTEXTURE_SAMPLER0 ); + + DECLARE_DYNAMIC_VERTEX_SHADER( eyes_vs30 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( DOWATERFOG, pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, pShaderAPI->GetCurrentNumBones() > 0 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( DYNAMIC_LIGHT, lightState.HasDynamicLight() ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( STATIC_LIGHT, lightState.m_bStaticLightVertex ? 1 : 0 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( MORPHING, pShaderAPI->IsHWMorphingEnabled() ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression ); + SET_DYNAMIC_VERTEX_SHADER( eyes_vs30 ); + } +#endif + + // Get luminance of ambient cube and saturate it + float fGlintDamping = max(0.0f, min( pShaderAPI->GetAmbientLightCubeLuminance(), 1.0f ) ); + const float fDimGlint = 0.01f; + + // Remap so that glint damping smooth steps to zero for low luminances + if ( fGlintDamping > fDimGlint ) + fGlintDamping = 1.0f; + else + fGlintDamping *= SimpleSplineRemapVal( fGlintDamping, 0.0f, fDimGlint, 0.0f, 1.0f ); + + // Special constant for DX9 eyes: { Dilation, ambient, x, x }; + float vPSConst[4] = {params[info.m_nDilation]->GetFloatValue(), fGlintDamping, 0.0f, 0.0f}; + pShaderAPI->SetPixelShaderConstant( 0, vPSConst, 1 ); + + pShaderAPI->SetPixelShaderFogParams( PSREG_FOG_PARAMS ); + + float vEyePos_SpecExponent[4]; + pShaderAPI->GetWorldSpaceCameraPosition( vEyePos_SpecExponent ); + vEyePos_SpecExponent[3] = 0.0f; + pShaderAPI->SetPixelShaderConstant( PSREG_EYEPOS_SPEC_EXPONENT, vEyePos_SpecExponent, 1 ); + +#ifndef _X360 + if ( !g_pHardwareConfig->HasFastVertexTextures() ) +#endif + { + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_DYNAMIC_PIXEL_SHADER( eyes_ps20b ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( WRITE_DEPTH_TO_DESTALPHA, pShaderAPI->ShouldWriteDepthToDestAlpha() ); + SET_DYNAMIC_PIXEL_SHADER( eyes_ps20b ); + } + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( eyes_ps20 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + SET_DYNAMIC_PIXEL_SHADER( eyes_ps20 ); + } + } +#ifndef _X360 + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( eyes_ps30 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( WRITE_DEPTH_TO_DESTALPHA, pShaderAPI->ShouldWriteDepthToDestAlpha() ); + SET_DYNAMIC_PIXEL_SHADER( eyes_ps30 ); + } +#endif + + Assert( info.m_nIntro != -1 ); + if( params[info.m_nIntro]->GetIntValue() ) + { + float curTime = params[info.m_nWarpParam]->GetFloatValue(); + float timeVec[4] = { 0.0f, 0.0f, 0.0f, curTime }; + Assert( params[info.m_nEntityOrigin]->IsDefined() ); + params[info.m_nEntityOrigin]->GetVecValue( timeVec, 3 ); + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_6, timeVec, 1 ); + } + } + else +#endif + { + eyes_Dynamic_Index vshIndex; + vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + vshIndex.SetSKINNING( pShaderAPI->GetCurrentNumBones() > 0 ); + vshIndex.SetLIGHT_COMBO( pShaderAPI->GetCurrentLightCombo() ); + pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() ); + } + } + pShader->Draw(); +} + +static void DrawEyes_DX8_DX9_Internal( bool bDX9, CBaseVSShader *pShader, IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, + IShaderShadow* pShaderShadow, bool bHasFlashlight, Eyes_DX8_DX9_Vars_t &info, VertexCompressionType_t vertexCompression ) +{ + if( !bHasFlashlight ) + { + DrawUsingVertexShader( bDX9, pShader, params, pShaderAPI, pShaderShadow, info, vertexCompression ); + } + else + { + DrawFlashlight( bDX9, pShader, params, pShaderAPI, pShaderShadow, info, vertexCompression ); + } +} + +extern ConVar r_flashlight_version2; +void DrawEyes_DX8_DX9( bool bDX9, CBaseVSShader *pShader, IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, + IShaderShadow* pShaderShadow, Eyes_DX8_DX9_Vars_t &info, VertexCompressionType_t vertexCompression ) +{ + SHADOW_STATE + { + SET_FLAGS2( MATERIAL_VAR2_LIGHTING_VERTEX_LIT ); + } + bool bHasFlashlight = pShader->UsingFlashlight( params ); + if( bHasFlashlight && ( IsX360() || r_flashlight_version2.GetInt() ) ) + { + DrawEyes_DX8_DX9_Internal( bDX9, pShader, params, pShaderAPI, pShaderShadow, false, info, vertexCompression ); + if ( pShaderShadow ) + { + pShader->SetInitialShadowState( ); + } + } + DrawEyes_DX8_DX9_Internal( bDX9, pShader, params, pShaderAPI, pShaderShadow, bHasFlashlight, info, vertexCompression ); +} + + diff --git a/materialsystem/stdshaders/eyes_dx8_dx9_helper.h b/materialsystem/stdshaders/eyes_dx8_dx9_helper.h new file mode 100644 index 0000000..daf7c12 --- /dev/null +++ b/materialsystem/stdshaders/eyes_dx8_dx9_helper.h @@ -0,0 +1,54 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//============================================================================= + +#ifndef EYES_DX8_DX9_HELPER_H +#define EYES_DX8_DX9_HELPER_H +#ifdef _WIN32 +#pragma once +#endif + +#include + + +//----------------------------------------------------------------------------- +// Forward declarations +//----------------------------------------------------------------------------- +class CBaseVSShader; +class IMaterialVar; +class IShaderDynamicAPI; +class IShaderShadow; + + +//----------------------------------------------------------------------------- +// Init params/ init/ draw methods +//----------------------------------------------------------------------------- +struct Eyes_DX8_DX9_Vars_t +{ + Eyes_DX8_DX9_Vars_t() { memset( this, 0xFF, sizeof(Eyes_DX8_DX9_Vars_t) ); } + + int m_nBaseTexture; + int m_nFrame; + int m_nIris; + int m_nIrisFrame; + int m_nGlint; + int m_nEyeOrigin; + int m_nEyeUp; + int m_nIrisU; + int m_nIrisV; + int m_nGlintU; + int m_nGlintV; + int m_nDilation; + int m_nIntro; + int m_nEntityOrigin; + int m_nWarpParam; +}; + +void InitParamsEyes_DX8_DX9( CBaseVSShader *pShader, IMaterialVar** params, const char *pMaterialName, Eyes_DX8_DX9_Vars_t &info ); +void InitEyes_DX8_DX9( CBaseVSShader *pShader, IMaterialVar** params, Eyes_DX8_DX9_Vars_t &info ); +void DrawEyes_DX8_DX9( bool bDX9, CBaseVSShader *pShader, IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, + IShaderShadow* pShaderShadow, Eyes_DX8_DX9_Vars_t &info, VertexCompressionType_t vertexCompression ); + +#endif // EYES_DX8_DX9_HELPER_H diff --git a/materialsystem/stdshaders/eyes_dx9.cpp b/materialsystem/stdshaders/eyes_dx9.cpp new file mode 100644 index 0000000..b33ec80 --- /dev/null +++ b/materialsystem/stdshaders/eyes_dx9.cpp @@ -0,0 +1,84 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: eye renderer +// +// $Header: $ +// $NoKeywords: $ +//=============================================================================// + +#include "BaseVSShader.h" +#include "eyes_dx8_dx9_helper.h" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +DEFINE_FALLBACK_SHADER( eyes, Eyes_dx9 ) + +BEGIN_VS_SHADER( Eyes_dx9, "Help for Eyes" ) + + BEGIN_SHADER_PARAMS + SHADER_PARAM( IRIS, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "iris texture" ) + SHADER_PARAM( IRISFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "frame for the iris texture" ) + SHADER_PARAM( GLINT, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "glint texture" ) + SHADER_PARAM( EYEORIGIN, SHADER_PARAM_TYPE_VEC3, "[0 0 0]", "origin for the eyes" ) + SHADER_PARAM( EYEUP, SHADER_PARAM_TYPE_VEC3, "[0 0 1]", "up vector for the eyes" ) + SHADER_PARAM( IRISU, SHADER_PARAM_TYPE_VEC4, "[0 1 0 0 ]", "U projection vector for the iris" ) + SHADER_PARAM( IRISV, SHADER_PARAM_TYPE_VEC4, "[0 0 1 0]", "V projection vector for the iris" ) + SHADER_PARAM( GLINTU, SHADER_PARAM_TYPE_VEC4, "[0 1 0 0]", "U projection vector for the glint" ) + SHADER_PARAM( GLINTV, SHADER_PARAM_TYPE_VEC4, "[0 0 1 0]", "V projection vector for the glint" ) + SHADER_PARAM( DILATION, SHADER_PARAM_TYPE_FLOAT, "0", "Pupil dilation (0 is none, 1 is maximal)" ) + SHADER_PARAM( INTRO, SHADER_PARAM_TYPE_BOOL, "0", "is eyes in the ep1 intro" ) + SHADER_PARAM( ENTITYORIGIN, SHADER_PARAM_TYPE_VEC3,"0.0","center if the model in world space" ) + SHADER_PARAM( WARPPARAM, SHADER_PARAM_TYPE_FLOAT,"0.0","animation param between 0 and 1" ) + END_SHADER_PARAMS + + void SetupVars( Eyes_DX8_DX9_Vars_t &info ) + { + info.m_nBaseTexture = BASETEXTURE; + info.m_nFrame = FRAME; + info.m_nIris = IRIS; + info.m_nIrisFrame = IRISFRAME; + info.m_nGlint = GLINT; + info.m_nEyeOrigin = EYEORIGIN; + info.m_nEyeUp = EYEUP; + info.m_nIrisU = IRISU; + info.m_nIrisV = IRISV; + info.m_nGlintU = GLINTU; + info.m_nGlintV = GLINTV; + info.m_nDilation = DILATION; + info.m_nIntro = INTRO; + info.m_nEntityOrigin = ENTITYORIGIN; + info.m_nWarpParam = WARPPARAM; + } + + SHADER_INIT_PARAMS() + { + Eyes_DX8_DX9_Vars_t info; + SetupVars( info ); + InitParamsEyes_DX8_DX9( this, params, pMaterialName, info ); + } + + SHADER_FALLBACK + { + if ( g_pHardwareConfig->GetDXSupportLevel() < 90 ) + return "Eyes_dx8"; + + return 0; + } + + SHADER_INIT + { + Eyes_DX8_DX9_Vars_t info; + SetupVars( info ); + InitEyes_DX8_DX9( this, params, info ); + } + + + SHADER_DRAW + { + Eyes_DX8_DX9_Vars_t info; + SetupVars( info ); + DrawEyes_DX8_DX9( true, this, params, pShaderAPI, pShaderShadow, info, vertexCompression ); + } +END_SHADER + diff --git a/materialsystem/stdshaders/eyes_flashlight2_ps11.psh b/materialsystem/stdshaders/eyes_flashlight2_ps11.psh new file mode 100644 index 0000000..6cc5493 --- /dev/null +++ b/materialsystem/stdshaders/eyes_flashlight2_ps11.psh @@ -0,0 +1,17 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; Draw stuff +;------------------------------------------------------------------------------ + +tex t0 ; Contains spotlight +tex t1 ; Contains base texture +tex t2 ; Normalize world pos to light +tex t3 ; Sample iris + +dp3 r0, t2_bx2, v0_bx2 ; r0 = N dot L +lrp r1.rgb, t3.a, t3, t1 ; r1 = lerp( baseColor, irisSample.xyz, irisSample.a ) +mul r0.rgb, r0_sat, r1 ; Saturate ( N dot L )* lerp +mul r0.rgb, r0, v0.a ; *= attenuation +mul_x2 r0.rgb, r0, t0 + ; *= 2 * spotlight +mov r0.a, t1.a diff --git a/materialsystem/stdshaders/eyes_flashlight_inc.fxc b/materialsystem/stdshaders/eyes_flashlight_inc.fxc new file mode 100644 index 0000000..7629f72 --- /dev/null +++ b/materialsystem/stdshaders/eyes_flashlight_inc.fxc @@ -0,0 +1,92 @@ +//====== Copyright © 1996-2006, Valve Corporation, All rights reserved. ======= +// +// Purpose: +// +//============================================================================= + +#include "common_flashlight_fxc.h" +#include "shader_constant_register_map.h" + + +const float4 g_vShadowTweaks : register( PSREG_ENVMAP_TINT__SHADOW_TWEAKS ); + +sampler SpotSampler : register( s0 ); +sampler BaseTextureSampler : register( s1 ); +sampler IrisSampler : register( s3 ); + +#if FLASHLIGHTSHADOWS && (!SHADER_MODEL_PS_1_1) && (!SHADER_MODEL_PS_1_4) && (!SHADER_MODEL_PS_2_0) +sampler FlashlightDepthSampler : register( s4 ); +sampler RandomRotationSampler : register( s5 ); +#endif + +#if defined( SHADER_MODEL_PS_1_1 ) || defined ( SHADER_MODEL_PS_1_4 ) + +#else + const float4 g_FogParams : register( PSREG_FOG_PARAMS ); + const float4 g_EyePos_SpecExponent : register( PSREG_EYEPOS_SPEC_EXPONENT ); +#endif + +struct PS_INPUT +{ + float4 spotTexCoord : TEXCOORD0; + float2 baseTexCoord : TEXCOORD1; + float2 irisTexCoord : TEXCOORD3; +#if defined( SHADER_MODEL_PS_1_1 ) || defined ( SHADER_MODEL_PS_1_4 ) + float3 vertAtten : COLOR0; +#else + float3 vertAtten : TEXCOORD4; + float3 worldPos : TEXCOORD5; + float3 projPos : TEXCOORD7; +#endif +}; + +float4 main( PS_INPUT i ) : COLOR +{ +#if defined(SHADER_MODEL_PS_2_0) + float3 spotColor = tex2Dproj( SpotSampler, i.spotTexCoord.xyzw ) * cFlashlightColor; +#elif ( defined(SHADER_MODEL_PS_2_B) || defined(SHADER_MODEL_PS_3_0) ) + float3 vProjCoords = i.spotTexCoord.xyz / i.spotTexCoord.w; + float3 spotColor = tex2D( SpotSampler, vProjCoords ) * cFlashlightColor; +#else + float3 spotColor = tex2D( SpotSampler, i.spotTexCoord ); +#endif + + float4 baseSample = tex2D( BaseTextureSampler, i.baseTexCoord ); + float4 irisSample = tex2D( IrisSampler, i.irisTexCoord ); + + float3 outcolor = float3(1,1,1); + +#if !defined( SHADER_MODEL_PS_1_1 ) && !defined( SHADER_MODEL_PS_1_4 ) + if( i.spotTexCoord.w <= 0.0f ) + { + outcolor = float3(0,0,0); + } +#endif + + // Composite the iris and sclera together +#if defined( SHADER_MODEL_PS_1_1 ) || defined ( SHADER_MODEL_PS_1_4 ) + float3 albedo = lerp( baseSample.xyz, irisSample.xyz, irisSample.a ); +#else + float3 albedo = lerp( baseSample.xyz, irisSample.xyz * 0.5f, irisSample.a ); // dim down the iris in HDR +#endif + + // Do shadow depth mapping... +#if FLASHLIGHTSHADOWS && ( defined(SHADER_MODEL_PS_2_B) || defined(SHADER_MODEL_PS_3_0) ) + float flShadow = DoFlashlightShadow( FlashlightDepthSampler, RandomRotationSampler, vProjCoords, i.projPos.xy / i.projPos.z, FLASHLIGHTDEPTHFILTERMODE, g_vShadowTweaks, true ); + float flAttenuated = lerp( flShadow, 1.0f, g_vShadowTweaks.y ); // Blend between fully attenuated and not attenuated + flShadow = lerp( flAttenuated, flShadow, dot(i.vertAtten, float3(0.30f, 0.59f, 0.11f) ) ); // Blend between shadow and above, according to light attenuation + outcolor *= flShadow * spotColor * albedo; +#else + outcolor *= spotColor * albedo; +#endif + + // NOTE!! This has to be last to avoid loss of range. + outcolor *= i.vertAtten; +#if defined( SHADER_MODEL_PS_1_1 ) || defined ( SHADER_MODEL_PS_1_4 ) + return float4( outcolor, baseSample.a ); +#else + float fogFactor = CalcPixelFogFactor( PIXELFOGTYPE, g_FogParams, g_EyePos_SpecExponent.z, i.worldPos.z, i.projPos.z ); + return FinalOutput( float4( outcolor, 1.0f ), fogFactor, PIXELFOGTYPE, TONEMAP_SCALE_LINEAR ); +#endif + +} diff --git a/materialsystem/stdshaders/eyes_flashlight_ps11.fxc b/materialsystem/stdshaders/eyes_flashlight_ps11.fxc new file mode 100644 index 0000000..25e0702 --- /dev/null +++ b/materialsystem/stdshaders/eyes_flashlight_ps11.fxc @@ -0,0 +1,9 @@ +//====== Copyright © 1996-2004, Valve Corporation, All rights reserved. ======= +// +// Purpose: +// +//============================================================================= + +#define HDRTYPE HDR_TYPE_NONE + +#include "eyes_flashlight_inc.fxc" diff --git a/materialsystem/stdshaders/eyes_flashlight_ps2x.fxc b/materialsystem/stdshaders/eyes_flashlight_ps2x.fxc new file mode 100644 index 0000000..eb00fc0 --- /dev/null +++ b/materialsystem/stdshaders/eyes_flashlight_ps2x.fxc @@ -0,0 +1,15 @@ +//====== Copyright © 1996-2004, Valve Corporation, All rights reserved. ======= +// +// Purpose: +// +//============================================================================= + +// STATIC: "FLASHLIGHTDEPTHFILTERMODE" "0..2" [ps20b] [PC] +// STATIC: "FLASHLIGHTDEPTHFILTERMODE" "0..2" [ps30] [PC] +// STATIC: "FLASHLIGHTDEPTHFILTERMODE" "0..0" [ps20b] [XBOX] + +// DYNAMIC: "PIXELFOGTYPE" "0..1" +// DYNAMIC: "FLASHLIGHTSHADOWS" "0..1" [ps20b] +// DYNAMIC: "FLASHLIGHTSHADOWS" "0..1" [ps30] + +#include "eyes_flashlight_inc.fxc" diff --git a/materialsystem/stdshaders/eyes_flashlight_vs11.vsh b/materialsystem/stdshaders/eyes_flashlight_vs11.vsh new file mode 100644 index 0000000..48c4cd5 --- /dev/null +++ b/materialsystem/stdshaders/eyes_flashlight_vs11.vsh @@ -0,0 +1,115 @@ +vs.1.1 + +# DYNAMIC: "DOWATERFOG" "0..1" +# DYNAMIC: "SKINNING" "0..1" + +#include "macros.vsh" + +local( $worldPos, $worldNormal, $projPos ); + +alloc $worldPos +alloc $projPos + + +&SkinPosition( $worldPos ); + +;------------------------------------------------------------------------------ +; Transform the position from world to view space +;------------------------------------------------------------------------------ +dp4 $projPos.x, $worldPos, $cViewProj0 +dp4 $projPos.y, $worldPos, $cViewProj1 +dp4 $projPos.z, $worldPos, $cViewProj2 +dp4 $projPos.w, $worldPos, $cViewProj3 + +;------------------------------------------------------------------------------ +; Normal is based on vertex position +;------------------------------------------------------------------------------ +&AllocateRegister( \$worldNormal ); +&AllocateRegister( \$normalDotUp ); + +sub $worldNormal, $worldPos, $SHADER_SPECIFIC_CONST_6 ; Normal = (Pos - Eye origin) +dp3 $normalDotUp, $worldNormal, $SHADER_SPECIFIC_CONST_7 ; Normal -= 0.5f * (Normal dot Eye Up) * Eye Up +mul $normalDotUp, $normalDotUp, $cHalf +mad $worldNormal, -$normalDotUp, $SHADER_SPECIFIC_CONST_7, $worldNormal + +&FreeRegister( \$normalDotUp ); + +; normalize the normal +&Normalize( $worldNormal ); + +mov oPos, $projPos + +;------------------------------------------------------------------------------ +; Fog +;------------------------------------------------------------------------------ +&CalcFog( $worldPos, $projPos ); + +; base tex coords +mov oT1.xy, $vTexCoord0 + +; spotlight texcoords +dp4 oT0.x, $worldPos, $SHADER_SPECIFIC_CONST_1 +dp4 oT0.y, $worldPos, $SHADER_SPECIFIC_CONST_2 +dp4 oT0.z, $worldPos, $SHADER_SPECIFIC_CONST_3 +dp4 oT0.w, $worldPos, $SHADER_SPECIFIC_CONST_4 + +local( $worldPosToLightVector, $distFactors ); + +alloc $worldPosToLightVector + +sub $worldPosToLightVector, $SHADER_SPECIFIC_CONST_0.xyz, $worldPos + +local( $distatten ); +alloc $distatten +; $distatten = [ 1, 1/dist, 1/distsquared ] + +; dist squared +dp3 $distatten.z, $worldPosToLightVector, $worldPosToLightVector + +; oodist +rsq $distatten.y, $distatten.z + +mov $distatten.x, $cOne + +local( $dist ); +alloc $dist +mul $dist.x, $distatten.z, $distatten.y + +rcp $distatten.z, $distatten.z ; 1/distsquared + +local( $endFalloffFactor ); +alloc $endFalloffFactor + +; ( dist - farZ ) +sub $endFalloffFactor.x, $dist.x, $SHADER_SPECIFIC_CONST_5.w +; 1 / ( (0.6f * farZ) - farZ) +mul $endFalloffFactor, $endFalloffFactor.x, $SHADER_SPECIFIC_CONST_0.w +max $endFalloffFactor, $endFalloffFactor, $cZero +min $endFalloffFactor, $endFalloffFactor, $cOne + +local( $vertAtten ); +alloc $vertAtten +dp3 $vertAtten, $distatten, $SHADER_SPECIFIC_CONST_5 +mul $vertAtten, $vertAtten, $endFalloffFactor + +; Normalize L +&Normalize( $worldPosToLightVector ); + +; N.L +dp3 $worldNormal, $worldNormal, $worldPosToLightVector + +; Modulate distance attenuation with N.L +mul oD0, $vertAtten, $worldNormal + +; iris +dp4 oT3.x, $SHADER_SPECIFIC_CONST_8, $worldPos +dp4 oT3.y, $SHADER_SPECIFIC_CONST_9, $worldPos + +free $dist +free $endFalloffFactor +free $worldPos +free $worldNormal +free $projPos +free $worldPosToLightVector +free $distatten +free $vertAtten diff --git a/materialsystem/stdshaders/eyes_flashlight_vs20.fxc b/materialsystem/stdshaders/eyes_flashlight_vs20.fxc new file mode 100644 index 0000000..e2e37dc --- /dev/null +++ b/materialsystem/stdshaders/eyes_flashlight_vs20.fxc @@ -0,0 +1,145 @@ +// ------------------------------------------------------------------------------ +// $cLight0Pos = world space light position +// $SHADER_SPECIFIC_CONST_1 = spotlight projection +// $SHADER_SPECIFIC_CONST_2 = spotlight projection +// $SHADER_SPECIFIC_CONST_3 = spotlight projection +// $SHADER_SPECIFIC_CONST_4 = spotlight projection +// $SHADER_SPECIFIC_CONST_5 = far z +// $SHADER_SPECIFIC_CONST_6 = eyeball origin +// $SHADER_SPECIFIC_CONST_7 = eyeball up * 0.5 +// $SHADER_SPECIFIC_CONST_8 = iris projection U +// $SHADER_SPECIFIC_CONST_9 = iris projection V +// ------------------------------------------------------------------------------ + +// DYNAMIC: "COMPRESSED_VERTS" "0..1" +// DYNAMIC: "SKINNING" "0..1" +// DYNAMIC: "DOWATERFOG" "0..1" +// DYNAMIC: "MORPHING" "0..1" [vs30] + +#include "common_vs_fxc.h" + +static const bool g_bSkinning = SKINNING ? true : false; +static const int g_FogType = DOWATERFOG; + +const float4 cLightPosition : register( SHADER_SPECIFIC_CONST_0 ); +const float4 cSpotlightProj1 : register( SHADER_SPECIFIC_CONST_1 ); +const float4 cSpotlightProj2 : register( SHADER_SPECIFIC_CONST_2 ); +const float4 cSpotlightProj3 : register( SHADER_SPECIFIC_CONST_3 ); +const float4 cSpotlightProj4 : register( SHADER_SPECIFIC_CONST_4 ); +const float4 cFlashlighAtten : register( SHADER_SPECIFIC_CONST_5 ); // const, linear, quadratic & farZ +const float4 cIrisProjectionU : register( SHADER_SPECIFIC_CONST_8 ); +const float4 cIrisProjectionV : register( SHADER_SPECIFIC_CONST_9 ); + +#ifdef SHADER_MODEL_VS_3_0 +// NOTE: cMorphTargetTextureDim.xy = target dimensions, +// cMorphTargetTextureDim.z = 4tuples/morph +const float3 cMorphTargetTextureDim : register( SHADER_SPECIFIC_CONST_10 ); +const float4 cMorphSubrect : register( SHADER_SPECIFIC_CONST_11 ); + +sampler2D morphSampler : register( D3DVERTEXTEXTURESAMPLER0, s0 ); +#endif + +struct VS_INPUT +{ + float4 vPos : POSITION; // Position + float4 vBoneWeights : BLENDWEIGHT; // Skin weights + float4 vBoneIndices : BLENDINDICES; // Skin indices + float4 vNormal : NORMAL; + float4 vTexCoord0 : TEXCOORD0; // Base (sclera) texture coordinates + + // Position and normal/tangent deltas + float3 vPosFlex : POSITION1; + float3 vNormalFlex : NORMAL1; +#ifdef SHADER_MODEL_VS_3_0 + float vVertexID : POSITION2; +#endif +}; + +struct VS_OUTPUT +{ + float4 projPos : POSITION; // Projection-space position +#if !defined( _X360 ) + float fog : FOG; // Fixed-function fog factor +#endif + float4 spotTexCoord : TEXCOORD0; // Spotlight texture coordinates + float2 baseTexCoord : TEXCOORD1; // Base texture coordinates + float2 irisTexCoord : TEXCOORD3; // Iris texture coordinates + float3 vertAtten : TEXCOORD4; // vertex attenuation + float3 worldPos : TEXCOORD5; + float3 projPosXYZ : TEXCOORD7; +}; + + +float RemapValClamped_01( float val, float A, float B ) +{ + float cVal = (val - A) / (B - A); + cVal = saturate( cVal ); + return cVal; +} + +VS_OUTPUT main( const VS_INPUT v ) +{ + VS_OUTPUT o = ( VS_OUTPUT )0; + + float4 vPosition = v.vPos; + float3 vNormal; + DecompressVertex_Normal( v.vNormal, vNormal ); + +#if !defined( SHADER_MODEL_VS_3_0 ) || !MORPHING + ApplyMorph( v.vPosFlex, v.vNormalFlex, vPosition.xyz, vNormal ); +#else + ApplyMorph( morphSampler, cMorphTargetTextureDim, cMorphSubrect, v.vVertexID, float3( 0, 0, 0 ), vPosition.xyz, vNormal ); +#endif + + // Perform skinning + float3 worldNormal, worldPos; + SkinPositionAndNormal( + g_bSkinning, + vPosition, vNormal, + v.vBoneWeights, v.vBoneIndices, + worldPos, worldNormal ); + + worldNormal = normalize( worldNormal ); + + // Transform into projection space + float4 projPos = mul( float4( worldPos, 1 ), cViewProj ); + o.projPos = projPos; + o.projPosXYZ = projPos.xyz; + o.worldPos = worldPos.xyz; + +#if !defined( _X360 ) + // Set fixed-function fog factor + o.fog = CalcFog( worldPos, o.projPos, g_FogType ); +#endif + + // Base texture coordinates + o.baseTexCoord = v.vTexCoord0; + + // Spotlight texture coordinates + o.spotTexCoord.x = dot( cSpotlightProj1, float4(worldPos, 1) ); + o.spotTexCoord.y = dot( cSpotlightProj2, float4(worldPos, 1) ); + o.spotTexCoord.z = dot( cSpotlightProj3, float4(worldPos, 1) ); + o.spotTexCoord.w = dot( cSpotlightProj4, float4(worldPos, 1) ); + + // Compute vector to light + float3 vWorldPosToLightVector = cLightPosition.xyz - worldPos; + + float3 vDistAtten = float3(1, 1, 1); + vDistAtten.z = dot( vWorldPosToLightVector, vWorldPosToLightVector ); // distsquared + vDistAtten.y = rsqrt( vDistAtten.z ); // 1 / dist + + float flDist = vDistAtten.z * vDistAtten.y; // dist + vDistAtten.z = 1.0f / vDistAtten.z; // 1 / distsquared + + float fFarZ = cFlashlighAtten.w; + + float endFalloffFactor = RemapValClamped_01( flDist, fFarZ, 0.6 * fFarZ ); + o.vertAtten.xyz = endFalloffFactor * dot( vDistAtten, cFlashlighAtten.xyz ); + + o.vertAtten *= dot( normalize( vWorldPosToLightVector ), worldNormal ); + + o.irisTexCoord.x = dot( cIrisProjectionU, float4(worldPos, 1) ); + o.irisTexCoord.y = dot( cIrisProjectionV, float4(worldPos, 1) ); + + return o; +} \ No newline at end of file diff --git a/materialsystem/stdshaders/eyes_ps2x.fxc b/materialsystem/stdshaders/eyes_ps2x.fxc new file mode 100644 index 0000000..d71d813 --- /dev/null +++ b/materialsystem/stdshaders/eyes_ps2x.fxc @@ -0,0 +1,68 @@ +//====== Copyright © 1996-2006, Valve Corporation, All rights reserved. ======= +// +// Purpose: +// +//============================================================================= + +// DYNAMIC: "WRITE_DEPTH_TO_DESTALPHA" "0..1" [ps20b] [PC] +// DYNAMIC: "WRITE_DEPTH_TO_DESTALPHA" "0..0" [ps20b] [XBOX] +// DYNAMIC: "WRITE_DEPTH_TO_DESTALPHA" "0..1" [ps30] +// DYNAMIC: "PIXELFOGTYPE" "0..1" + +#include "common_ps_fxc.h" +#include "shader_constant_register_map.h" + +sampler BaseTextureSampler : register( s0 ); +sampler IrisSampler : register( s1 ); +sampler GlintSampler : register( s2 ); +const float4 cEyeScalars : register( c0 ); // { Dilation, ambient, x, x } + +const float4 g_FogParams : register( PSREG_FOG_PARAMS ); +const float4 g_EyePos_SpecExponent : register( PSREG_EYEPOS_SPEC_EXPONENT ); + +struct PS_INPUT +{ + float2 baseTexCoord : TEXCOORD0; + float2 irisTexCoord : TEXCOORD1; + float2 glintTexCoord : TEXCOORD2; + float3 vertAtten : TEXCOORD3; + + float4 worldPos_projPosZ : TEXCOORD7; // Necessary for pixel fog +}; + +#define fDilationFactor cEyeScalars.x +#define fGlintDamping cEyeScalars.y + +float4 main( PS_INPUT i ) : COLOR +{ + float4 baseSample = tex2D( BaseTextureSampler, i.baseTexCoord ); + float4 glintSample = tex2D( GlintSampler, i.glintTexCoord ); +/* + // Dilate the pupil/iris texture (1 is max dilation, 0 is none) + float2 biasedCoords = i.irisTexCoord * 2.0f - 1.0f; // -1 to +1 range + float fDilatability = saturate(0.8f - sqrt(dot(biasedCoords, biasedCoords) )); // 1 in the center, fading out to 0 at 0.8 from center, since irises are inset into maps + float2 scaledCoords = biasedCoords * (1 + fDilatability); // Maximal dilation + + // Blend undilated and maximally dilated based upon dilation factor + float2 dilatedCoords = lerp( scaledCoords, biasedCoords, 1.0f-saturate(cDilationFactor.x)); + dilatedCoords = dilatedCoords * 0.5f + 0.5f; // Back to 0..1 range +*/ + + float4 irisSample = tex2D( IrisSampler, i.irisTexCoord ); // Sample the iris map using dilated coordinates + + float4 result; + result.rgb = lerp( baseSample.rgb, irisSample.rgb, irisSample.a ); + result.rgb *= i.vertAtten; + result.rgb += glintSample.rgb * fGlintDamping; + result.a = baseSample.a; + + bool bWriteDepthToAlpha = false; + + // ps_2_b and beyond +#if !(defined(SHADER_MODEL_PS_1_1) || defined(SHADER_MODEL_PS_1_4) || defined(SHADER_MODEL_PS_2_0)) + bWriteDepthToAlpha = WRITE_DEPTH_TO_DESTALPHA != 0; +#endif + + float fogFactor = CalcPixelFogFactor( PIXELFOGTYPE, g_FogParams, g_EyePos_SpecExponent.z, i.worldPos_projPosZ.z, i.worldPos_projPosZ.w ); + return FinalOutput( result, fogFactor, PIXELFOGTYPE, TONEMAP_SCALE_LINEAR, bWriteDepthToAlpha, i.worldPos_projPosZ.w ); +} diff --git a/materialsystem/stdshaders/fillrate.cpp b/materialsystem/stdshaders/fillrate.cpp new file mode 100644 index 0000000..02ead06 --- /dev/null +++ b/materialsystem/stdshaders/fillrate.cpp @@ -0,0 +1,251 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $Header: $ +// $NoKeywords: $ +//=============================================================================// + +#include "BaseVSShader.h" + +#define USE_NEW_SHADER //Updating assembly shaders to fxc, this is for A/B testing. + +#ifdef USE_NEW_SHADER + +#include "fillrate_vs11.inc" +#include "fillrate_ps11.inc" +#include "fillrate_vs20.inc" +#include "fillrate_ps20.inc" +#include "fillrate_ps20b.inc" + +#else + +#include "fillrate.inc" + +#endif + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +BEGIN_VS_SHADER_FLAGS( Fillrate, "Help for Fillrate", SHADER_NOT_EDITABLE ) + BEGIN_SHADER_PARAMS + SHADER_PARAM( PASSCOUNT, SHADER_PARAM_TYPE_INTEGER, "1", "Number of passes for this material" ) + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + SET_FLAGS2( MATERIAL_VAR2_SUPPORTS_HW_SKINNING ); + } + + SHADER_INIT + { + } + + SHADER_FALLBACK + { + return 0; + } + + + SHADER_DRAW + { + SHADOW_STATE + { + pShaderShadow->EnableDepthTest( false ); + pShaderShadow->EnableDepthWrites( false ); + pShaderShadow->EnableBlending( true ); + pShaderShadow->BlendFunc( SHADER_BLEND_ONE, SHADER_BLEND_ONE ); + pShaderShadow->VertexShaderVertexFormat( VERTEX_POSITION, 1, 0, 0 ); + +#ifdef USE_NEW_SHADER + + if( g_pHardwareConfig->GetDXSupportLevel() >= 90 ) + { + DECLARE_STATIC_VERTEX_SHADER( fillrate_vs20 ); + SET_STATIC_VERTEX_SHADER( fillrate_vs20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_STATIC_PIXEL_SHADER( fillrate_ps20b ); + SET_STATIC_PIXEL_SHADER( fillrate_ps20b ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( fillrate_ps20 ); + SET_STATIC_PIXEL_SHADER( fillrate_ps20 ); + } + } + else + { + DECLARE_STATIC_VERTEX_SHADER( fillrate_vs11 ); + SET_STATIC_VERTEX_SHADER( fillrate_vs11 ); + + DECLARE_STATIC_PIXEL_SHADER( fillrate_ps11 ); + SET_STATIC_PIXEL_SHADER( fillrate_ps11 ); + } + +#else + + fillrate_Static_Index vshIndex; + pShaderShadow->SetVertexShader( "fillrate", vshIndex.GetIndex() ); + + pShaderShadow->SetPixelShader( "fillrate" ); + +#endif + } + DYNAMIC_STATE + { + int numPasses = params[PASSCOUNT]->GetIntValue(); + float color[4]; + if (g_pConfig->bMeasureFillRate) + { + // have to multiply by 2/255 since pixel shader constant are 1.7. + // Will divide the 2 out in the pixel shader. + color[0] = numPasses * ( 2.0f / 255.0f ); + } + else + { + color[0] = ( 16 * numPasses ) * ( 2.0f / 255.0f ); + } + color[1] = 0.0f; + color[2] = 0.0f; + color[3] = 0.0f; + pShaderAPI->SetPixelShaderConstant( 0, color, 1 ); + +#ifdef USE_NEW_SHADER + + if( g_pHardwareConfig->GetDXSupportLevel() >= 90 ) + { + DECLARE_DYNAMIC_VERTEX_SHADER( fillrate_vs20 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( DOWATERFOG, pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, pShaderAPI->GetCurrentNumBones() > 0 ); + SET_DYNAMIC_VERTEX_SHADER( fillrate_vs20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_DYNAMIC_PIXEL_SHADER( fillrate_ps20b ); + SET_DYNAMIC_PIXEL_SHADER( fillrate_ps20b ); + } + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( fillrate_ps20 ); + SET_DYNAMIC_PIXEL_SHADER( fillrate_ps20 ); + } + } + else + { + DECLARE_DYNAMIC_VERTEX_SHADER( fillrate_vs11 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( DOWATERFOG, pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, pShaderAPI->GetCurrentNumBones() > 0 ); + SET_DYNAMIC_VERTEX_SHADER( fillrate_vs11 ); + + DECLARE_DYNAMIC_PIXEL_SHADER( fillrate_ps11 ); + SET_DYNAMIC_PIXEL_SHADER( fillrate_ps11 ); + } + +#else + + fillrate_Dynamic_Index vshIndex; + vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + vshIndex.SetSKINNING( pShaderAPI->GetCurrentNumBones() > 0 ); + pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() ); + +#endif + } + Draw(); + + SHADOW_STATE + { + pShaderShadow->EnableDepthTest( false ); + pShaderShadow->EnableDepthWrites( false ); + pShaderShadow->EnableBlending( true ); + pShaderShadow->BlendFunc( SHADER_BLEND_ONE, SHADER_BLEND_ONE ); + pShaderShadow->VertexShaderVertexFormat( VERTEX_POSITION, 1, 0, 0 ); + pShaderShadow->PolyMode( SHADER_POLYMODEFACE_FRONT_AND_BACK, SHADER_POLYMODE_LINE ); + +#ifdef USE_NEW_SHADER + + if( g_pHardwareConfig->GetDXSupportLevel() >= 90 ) + { + DECLARE_STATIC_VERTEX_SHADER( fillrate_vs20 ); + SET_STATIC_VERTEX_SHADER( fillrate_vs20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_STATIC_PIXEL_SHADER( fillrate_ps20b ); + SET_STATIC_PIXEL_SHADER( fillrate_ps20b ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( fillrate_ps20 ); + SET_STATIC_PIXEL_SHADER( fillrate_ps20 ); + } + } + else + { + DECLARE_STATIC_VERTEX_SHADER( fillrate_vs11 ); + SET_STATIC_VERTEX_SHADER( fillrate_vs11 ); + + DECLARE_STATIC_PIXEL_SHADER( fillrate_ps11 ); + SET_STATIC_PIXEL_SHADER( fillrate_ps11 ); + } + +#else + + fillrate_Static_Index vshIndex; + pShaderShadow->SetVertexShader( "fillrate", vshIndex.GetIndex() ); + + pShaderShadow->SetPixelShader( "fillrate" ); + +#endif + } + DYNAMIC_STATE + { + float color[4] = { 0.0f, 0.05f, 0.05f, 0.0f }; + pShaderAPI->SetPixelShaderConstant( 0, color, 1 ); + +#ifdef USE_NEW_SHADER + + if( g_pHardwareConfig->GetDXSupportLevel() >= 90 ) + { + DECLARE_DYNAMIC_VERTEX_SHADER( fillrate_vs20 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( DOWATERFOG, pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, pShaderAPI->GetCurrentNumBones() > 0 ); + SET_DYNAMIC_VERTEX_SHADER( fillrate_vs20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_DYNAMIC_PIXEL_SHADER( fillrate_ps20b ); + SET_DYNAMIC_PIXEL_SHADER( fillrate_ps20b ); + } + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( fillrate_ps20 ); + SET_DYNAMIC_PIXEL_SHADER( fillrate_ps20 ); + } + } + else + { + DECLARE_DYNAMIC_VERTEX_SHADER( fillrate_vs11 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( DOWATERFOG, pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, pShaderAPI->GetCurrentNumBones() > 0 ); + SET_DYNAMIC_VERTEX_SHADER( fillrate_vs11 ); + + DECLARE_DYNAMIC_PIXEL_SHADER( fillrate_ps11 ); + SET_DYNAMIC_PIXEL_SHADER( fillrate_ps11 ); + } + +#else + + fillrate_Dynamic_Index vshIndex; + vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + vshIndex.SetSKINNING( pShaderAPI->GetCurrentNumBones() > 0 ); + pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() ); + +#endif + } + Draw(); + } +END_SHADER + + diff --git a/materialsystem/stdshaders/fillrate.psh b/materialsystem/stdshaders/fillrate.psh new file mode 100644 index 0000000..dea5a87 --- /dev/null +++ b/materialsystem/stdshaders/fillrate.psh @@ -0,0 +1,12 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; Draw a texture . . woo hoo! +; t0 - texture +; +; The texture coordinates need to be defined as follows: +; tc0 - texcoords +;------------------------------------------------------------------------------ + +mov_d2 r0, c0 + diff --git a/materialsystem/stdshaders/fillrate.vsh b/materialsystem/stdshaders/fillrate.vsh new file mode 100644 index 0000000..917e316 --- /dev/null +++ b/materialsystem/stdshaders/fillrate.vsh @@ -0,0 +1,35 @@ +vs.1.1 + +# DYNAMIC: "DOWATERFOG" "0..1" +# DYNAMIC: "SKINNING" "0..1" + +;------------------------------------------------------------------------------ +; Constants specified by the app +; c0 = (0, 1, 2, 0.5) +; c1 = (1/2.2, 3, 255, overbright factor) +; c2 = camera position *in world space* +; c4-c7 = modelViewProj matrix (transpose) +; c8-c11 = ViewProj matrix (transpose) +; c12-c15 = model->view matrix (transpose) +; c16 = [fogStart, fogEnd, fogRange, 1.0/fogRange] +; $SHADER_SPECIFIC_CONST_0-$SHADER_SPECIFIC_CONST_1 = Base texture transform +; $SHADER_SPECIFIC_CONST_2-$SHADER_SPECIFIC_CONST_3 = Mask texture transform +;------------------------------------------------------------------------------ + +#include "macros.vsh" + +;------------------------------------------------------------------------------ +; Vertex blending +;------------------------------------------------------------------------------ + +&AllocateRegister( \$worldPos ); +&SkinPosition( $worldPos ); + +; Transform the position from world to view space +dp4 oPos.x, $worldPos, $cViewProj0 +dp4 oPos.y, $worldPos, $cViewProj1 +dp4 oPos.z, $worldPos, $cViewProj2 +dp4 oPos.w, $worldPos, $cViewProj3 + + +&FreeRegister( \$worldPos ); diff --git a/materialsystem/stdshaders/fillrate_ps11.fxc b/materialsystem/stdshaders/fillrate_ps11.fxc new file mode 100644 index 0000000..dfb5a94 --- /dev/null +++ b/materialsystem/stdshaders/fillrate_ps11.fxc @@ -0,0 +1,6 @@ +const float4 g_ColorConstant : register( c0 ); + +float4 main( void ) : COLOR +{ + return (g_ColorConstant / 2.0); +} diff --git a/materialsystem/stdshaders/fillrate_ps2x.fxc b/materialsystem/stdshaders/fillrate_ps2x.fxc new file mode 100644 index 0000000..2caa82b --- /dev/null +++ b/materialsystem/stdshaders/fillrate_ps2x.fxc @@ -0,0 +1,13 @@ +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX] + +#include "common_ps_fxc.h" + +const float4 g_ColorConstant : register( c0 ); + +float4 main( void ) : COLOR +{ + float4 result = (g_ColorConstant * (1.0 / 2.0)); + + return FinalOutput( result, 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE ); +} diff --git a/materialsystem/stdshaders/fillrate_vs11.fxc b/materialsystem/stdshaders/fillrate_vs11.fxc new file mode 100644 index 0000000..73f5c68 --- /dev/null +++ b/materialsystem/stdshaders/fillrate_vs11.fxc @@ -0,0 +1,33 @@ +// DYNAMIC: "DOWATERFOG" "0..1" +// DYNAMIC: "SKINNING" "0..1" + +#include "common_vs_fxc.h" + +static const int g_FogType = DOWATERFOG; +static const bool g_bSkinning = SKINNING ? true : false; + + +struct VS_INPUT +{ + float4 vPos : POSITION; + float4 vBoneWeights : BLENDWEIGHT; + float4 vBoneIndices : BLENDINDICES; +}; + +struct VS_OUTPUT +{ + float4 vProjPos : POSITION; +}; + + +VS_OUTPUT main( const VS_INPUT v ) +{ + VS_OUTPUT o = ( VS_OUTPUT )0; + + float3 worldPos; + SkinPosition( g_bSkinning, v.vPos, v.vBoneWeights, v.vBoneIndices, worldPos ); + + o.vProjPos = mul( float4( worldPos, 1 ), cViewProj ); + + return o; +} \ No newline at end of file diff --git a/materialsystem/stdshaders/fillrate_vs20.fxc b/materialsystem/stdshaders/fillrate_vs20.fxc new file mode 100644 index 0000000..4d85163 --- /dev/null +++ b/materialsystem/stdshaders/fillrate_vs20.fxc @@ -0,0 +1,32 @@ +// DYNAMIC: "DOWATERFOG" "0..1" +// DYNAMIC: "SKINNING" "0..1" + +#include "common_vs_fxc.h" + +static const int g_FogType = DOWATERFOG; +static const bool g_bSkinning = SKINNING ? true : false; + +struct VS_INPUT +{ + float4 vPos : POSITION; + float4 vBoneWeights : BLENDWEIGHT; + float4 vBoneIndices : BLENDINDICES; +}; + +struct VS_OUTPUT +{ + float4 vProjPos : POSITION; +}; + + +VS_OUTPUT main( const VS_INPUT v ) +{ + VS_OUTPUT o = ( VS_OUTPUT )0; + + float3 worldPos; + SkinPosition( g_bSkinning, v.vPos, v.vBoneWeights, v.vBoneIndices, worldPos ); + + o.vProjPos = mul( float4( worldPos, 1 ), cViewProj ); + + return o; +} \ No newline at end of file diff --git a/materialsystem/stdshaders/filmdust_dx7.cpp b/materialsystem/stdshaders/filmdust_dx7.cpp new file mode 100644 index 0000000..875604b --- /dev/null +++ b/materialsystem/stdshaders/filmdust_dx7.cpp @@ -0,0 +1,67 @@ +//========= 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" + +DEFINE_FALLBACK_SHADER( FilmDust, FilmDust_DX7 ) + +BEGIN_SHADER( FilmDust_DX7, "Help for FilmDust_DX7" ) + + BEGIN_SHADER_PARAMS + SHADER_PARAM( DUST_TEXTURE, SHADER_PARAM_TYPE_TEXTURE, "0", "Film grain texture" ) + SHADER_PARAM( CHANNEL_SELECT, SHADER_PARAM_TYPE_VEC4, "", "Select which color channel to use" ) + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + } + + SHADER_FALLBACK + { + // Requires DX9 + above + if ( g_pHardwareConfig->GetDXSupportLevel() < 70 ) + { + Assert( 0 ); + return "Wireframe"; + } + return 0; + } + + SHADER_INIT + { + LoadTexture( DUST_TEXTURE ); + } + + SHADER_DRAW + { + SHADOW_STATE + { + pShaderShadow->EnableConstantColor( true ); + pShaderShadow->EnableBlending( true ); + pShaderShadow->BlendFunc( SHADER_BLEND_ZERO, SHADER_BLEND_ONE_MINUS_SRC_COLOR ); + + pShaderShadow->EnableCustomPixelPipe( true ); + pShaderShadow->CustomTextureStages( 1 ); + pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE0, SHADER_TEXCHANNEL_COLOR, SHADER_TEXOP_DOTPRODUCT3, SHADER_TEXARG_CONSTANTCOLOR, SHADER_TEXARG_TEXTURE ); + + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + } + DYNAMIC_STATE + { + float color[4]; + params[CHANNEL_SELECT]->GetVecValue( color, 4 ); + s_pShaderAPI->Color4fv( color ); + + BindTexture( SHADER_SAMPLER0, DUST_TEXTURE, -1 ); + } + Draw(); + } +END_SHADER diff --git a/materialsystem/stdshaders/filmdust_dx8_dx9.cpp b/materialsystem/stdshaders/filmdust_dx8_dx9.cpp new file mode 100644 index 0000000..d7f2b72 --- /dev/null +++ b/materialsystem/stdshaders/filmdust_dx8_dx9.cpp @@ -0,0 +1,111 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//============================================================================= + +#include "BaseVSShader.h" + +#ifdef STDSHADER_DX9_DLL_EXPORT +#include "screenspaceeffect_vs20.inc" +#include "filmdust_ps20.inc" +#else +#include "screenspaceeffect_vs11.inc" +#include "filmdust_ps11.inc" +#endif + +#include "../materialsystem_global.h" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +#ifdef STDSHADER_DX9_DLL_EXPORT +DEFINE_FALLBACK_SHADER( FilmDust, FilmDust_dx9 ) +BEGIN_VS_SHADER_FLAGS( FilmDust_dx9, "Help for FilmDust", SHADER_NOT_EDITABLE ) +#else +DEFINE_FALLBACK_SHADER( FilmDust, FilmDust_dx8 ) +BEGIN_VS_SHADER_FLAGS( FilmDust_dx8, "Help for FilmDust", SHADER_NOT_EDITABLE ) +#endif + + BEGIN_SHADER_PARAMS + SHADER_PARAM( DUST_TEXTURE, SHADER_PARAM_TYPE_TEXTURE, "0", "Film dust texture" ) + SHADER_PARAM( CHANNEL_SELECT, SHADER_PARAM_TYPE_VEC4, "", "Select which color channel to use" ) + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + SET_FLAGS2( MATERIAL_VAR2_NEEDS_FULL_FRAME_BUFFER_TEXTURE ); + } + + SHADER_FALLBACK + { +#ifdef STDSHADER_DX9_DLL_EXPORT + // Requires DX9 + above + if ( g_pHardwareConfig->GetDXSupportLevel() < 90) + { + return "FilmDust_DX8"; + } +#else // We're DX8 + // Requires DX8 + above + if ( g_pHardwareConfig->GetDXSupportLevel() < 80) + { + return "FilmDust_DX7"; + } +#endif + return 0; + } + + SHADER_INIT + { + LoadTexture( DUST_TEXTURE ); + } + + SHADER_DRAW + { + SHADOW_STATE + { + pShaderShadow->EnableCulling( false ); + pShaderShadow->EnableBlending( true ); + pShaderShadow->BlendFunc( SHADER_BLEND_ZERO, SHADER_BLEND_SRC_COLOR ); + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + + int fmt = VERTEX_POSITION; + pShaderShadow->VertexShaderVertexFormat( fmt, 1, 0, 0 ); + +#ifdef STDSHADER_DX9_DLL_EXPORT + DECLARE_STATIC_VERTEX_SHADER( screenspaceeffect_vs20 ); + SET_STATIC_VERTEX_SHADER( screenspaceeffect_vs20 ); + + DECLARE_STATIC_PIXEL_SHADER( filmdust_ps20 ); + SET_STATIC_PIXEL_SHADER( filmdust_ps20 ); +#else + DECLARE_STATIC_VERTEX_SHADER( screenspaceeffect_vs11 ); + SET_STATIC_VERTEX_SHADER( screenspaceeffect_vs11 ); + + DECLARE_STATIC_PIXEL_SHADER( filmdust_ps11 ); + SET_STATIC_PIXEL_SHADER( filmdust_ps11 ); +#endif + } + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER0, DUST_TEXTURE, -1 ); + + SetPixelShaderConstant( 0, CHANNEL_SELECT ); +#ifdef STDSHADER_DX9_DLL_EXPORT + DECLARE_DYNAMIC_VERTEX_SHADER( screenspaceeffect_vs20 ); + SET_DYNAMIC_VERTEX_SHADER( screenspaceeffect_vs20 ); + + DECLARE_DYNAMIC_PIXEL_SHADER( filmdust_ps20 ); + SET_DYNAMIC_PIXEL_SHADER( filmdust_ps20 ); +#else + DECLARE_DYNAMIC_VERTEX_SHADER( screenspaceeffect_vs11 ); + SET_DYNAMIC_VERTEX_SHADER( screenspaceeffect_vs11 ); + + DECLARE_DYNAMIC_PIXEL_SHADER( filmdust_ps11 ); + SET_DYNAMIC_PIXEL_SHADER( filmdust_ps11 ); +#endif + } + Draw(); + } +END_SHADER diff --git a/materialsystem/stdshaders/filmdust_ps11.fxc b/materialsystem/stdshaders/filmdust_ps11.fxc new file mode 100644 index 0000000..3dc8ae3 --- /dev/null +++ b/materialsystem/stdshaders/filmdust_ps11.fxc @@ -0,0 +1,18 @@ +#define HDRTYPE HDR_TYPE_NONE +#include "common_ps_fxc.h" + +sampler FilmDustSampler : register( s0 ); + +const float4 vChannelSelect : register( c0 ); + +struct PS_INPUT +{ + float2 grainTexCoord : TEXCOORD0; +}; + +HALF4 main( PS_INPUT i ) : COLOR +{ + HALF4 noise = dot( tex2D( FilmDustSampler, i.grainTexCoord ), vChannelSelect ); + + return HALF4( noise.x, noise.y, noise.z, 1.0 ); +} diff --git a/materialsystem/stdshaders/filmdust_ps20.fxc b/materialsystem/stdshaders/filmdust_ps20.fxc new file mode 100644 index 0000000..9939271 --- /dev/null +++ b/materialsystem/stdshaders/filmdust_ps20.fxc @@ -0,0 +1,18 @@ +#define HDRTYPE HDR_TYPE_NONE +#include "common_ps_fxc.h" + +sampler FilmDustSampler : register( s0 ); + +const float4 vChannelSelect : register( c0 ); + +struct PS_INPUT +{ + float2 grainTexCoord : TEXCOORD0; +}; + +float4 main( PS_INPUT i ) : COLOR +{ + float4 noise = dot( tex2D( FilmDustSampler, i.grainTexCoord ), vChannelSelect ); + + return float4( noise.x, noise.y, noise.z, 1.0 ); +} diff --git a/materialsystem/stdshaders/filmgrain_dx7.cpp b/materialsystem/stdshaders/filmgrain_dx7.cpp new file mode 100644 index 0000000..314ed68 --- /dev/null +++ b/materialsystem/stdshaders/filmgrain_dx7.cpp @@ -0,0 +1,62 @@ +//========= 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" + +DEFINE_FALLBACK_SHADER( FilmGrain, FilmGrain_DX7 ) + +BEGIN_SHADER( FilmGrain_DX7, "Help for FilmGrain_DX7" ) + + BEGIN_SHADER_PARAMS + SHADER_PARAM( GRAIN_TEXTURE, SHADER_PARAM_TYPE_TEXTURE, "0", "Film grain texture" ) + SHADER_PARAM( NOISESCALE, SHADER_PARAM_TYPE_VEC4, "", "Strength of film grain" ) + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + } + + SHADER_FALLBACK + { + // Requires DX9 + above + if ( g_pHardwareConfig->GetDXSupportLevel() < 70 ) + { + Assert( 0 ); + return "Wireframe"; + } + return 0; + } + + SHADER_INIT + { + LoadTexture( GRAIN_TEXTURE ); + } + + SHADER_DRAW + { + SHADOW_STATE + { + pShaderShadow->EnableConstantColor( true ); + pShaderShadow->EnableBlending( true ); + pShaderShadow->BlendFunc( SHADER_BLEND_ONE_MINUS_DST_COLOR, SHADER_BLEND_ONE_MINUS_SRC_COLOR ); + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->DrawFlags( SHADER_DRAW_POSITION | SHADER_DRAW_TEXCOORD0 ); + } + DYNAMIC_STATE + { + float color[4]; + params[NOISESCALE]->GetVecValue( color, 4 ); + s_pShaderAPI->Color4fv( color ); + BindTexture( SHADER_SAMPLER0, GRAIN_TEXTURE, -1 ); + } + Draw(); + } +END_SHADER diff --git a/materialsystem/stdshaders/filmgrain_dx8_dx9.cpp b/materialsystem/stdshaders/filmgrain_dx8_dx9.cpp new file mode 100644 index 0000000..5c99ed8 --- /dev/null +++ b/materialsystem/stdshaders/filmgrain_dx8_dx9.cpp @@ -0,0 +1,113 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//============================================================================= + +#include "BaseVSShader.h" + +#ifdef STDSHADER_DX9_DLL_EXPORT +#include "screenspaceeffect_vs20.inc" +#include "filmgrain_ps20.inc" +#else +#include "screenspaceeffect_vs11.inc" +#include "filmgrain_ps11.inc" +#endif + +#include "../materialsystem_global.h" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +#ifdef STDSHADER_DX9_DLL_EXPORT +DEFINE_FALLBACK_SHADER( FilmGrain, FilmGrain_dx9 ) +BEGIN_VS_SHADER_FLAGS( FilmGrain_dx9, "Help for FilmGrain", SHADER_NOT_EDITABLE ) +#else +DEFINE_FALLBACK_SHADER( FilmGrain, FilmGrain_dx8 ) +BEGIN_VS_SHADER_FLAGS( FilmGrain_dx8, "Help for FilmGrain", SHADER_NOT_EDITABLE ) +#endif + + BEGIN_SHADER_PARAMS + SHADER_PARAM( GRAIN_TEXTURE, SHADER_PARAM_TYPE_TEXTURE, "0", "Film grain texture" ) + SHADER_PARAM( NOISESCALE, SHADER_PARAM_TYPE_VEC4, "", "Strength of film grain" ) + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + SET_FLAGS2( MATERIAL_VAR2_NEEDS_FULL_FRAME_BUFFER_TEXTURE ); + } + + SHADER_FALLBACK + { +#ifdef STDSHADER_DX9_DLL_EXPORT + // Requires DX9 + above + if ( g_pHardwareConfig->GetDXSupportLevel() < 90) + { + return "FilmGrain_dx8"; + } +#else // We're DX8 + // Requires DX8 + above + if ( g_pHardwareConfig->GetDXSupportLevel() < 80) + { + return "FilmGrain_dx7"; + } +#endif + + return 0; + } + + SHADER_INIT + { + LoadTexture( GRAIN_TEXTURE ); + } + + SHADER_DRAW + { + SHADOW_STATE + { + pShaderShadow->EnableBlending( true ); + pShaderShadow->BlendFunc( SHADER_BLEND_ONE, SHADER_BLEND_SRC_ALPHA ); + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + + int fmt = VERTEX_POSITION; + pShaderShadow->VertexShaderVertexFormat( fmt, 1, 0, 0 ); + +#ifdef STDSHADER_DX9_DLL_EXPORT + DECLARE_STATIC_VERTEX_SHADER( screenspaceeffect_vs20 ); + SET_STATIC_VERTEX_SHADER( screenspaceeffect_vs20 ); + + DECLARE_STATIC_PIXEL_SHADER( filmgrain_ps20 ); + SET_STATIC_PIXEL_SHADER( filmgrain_ps20 ); +#else + DECLARE_STATIC_VERTEX_SHADER( screenspaceeffect_vs11 ); + SET_STATIC_VERTEX_SHADER( screenspaceeffect_vs11 ); + + DECLARE_STATIC_PIXEL_SHADER( filmgrain_ps11 ); + SET_STATIC_PIXEL_SHADER( filmgrain_ps11 ); +#endif + + } + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER0, GRAIN_TEXTURE, -1 ); + + SetPixelShaderConstant( 0, NOISESCALE ); + +#ifdef STDSHADER_DX9_DLL_EXPORT + DECLARE_DYNAMIC_VERTEX_SHADER( screenspaceeffect_vs20 ); + SET_DYNAMIC_VERTEX_SHADER( screenspaceeffect_vs20 ); + + DECLARE_DYNAMIC_PIXEL_SHADER( filmgrain_ps20 ); + SET_DYNAMIC_PIXEL_SHADER( filmgrain_ps20 ); +#else + DECLARE_DYNAMIC_VERTEX_SHADER( screenspaceeffect_vs11 ); + SET_DYNAMIC_VERTEX_SHADER( screenspaceeffect_vs11 ); + + DECLARE_DYNAMIC_PIXEL_SHADER( filmgrain_ps11 ); + SET_DYNAMIC_PIXEL_SHADER( filmgrain_ps11 ); +#endif + } + Draw(); + } +END_SHADER diff --git a/materialsystem/stdshaders/filmgrain_ps11.fxc b/materialsystem/stdshaders/filmgrain_ps11.fxc new file mode 100644 index 0000000..c36d7cc --- /dev/null +++ b/materialsystem/stdshaders/filmgrain_ps11.fxc @@ -0,0 +1,21 @@ +#define HDRTYPE HDR_TYPE_NONE +#include "common_ps_fxc.h" + +sampler FilmGrainSampler : register( s0 ); + +const float4 vNoiseScale : register( c0 ); + +struct PS_INPUT +{ + float2 grainTexCoord : TEXCOORD0; +}; + +HALF4 main( PS_INPUT i ) : COLOR +{ + HALF4 noise = tex2D( FilmGrainSampler, i.grainTexCoord ); + + noise.w = noise.x*(1.0-vNoiseScale.w) + vNoiseScale.w; + noise.xyz *= vNoiseScale.xyz; + + return HALF4( noise.x, noise.y, noise.z, noise.w ); +} diff --git a/materialsystem/stdshaders/filmgrain_ps20.fxc b/materialsystem/stdshaders/filmgrain_ps20.fxc new file mode 100644 index 0000000..9ad9a75 --- /dev/null +++ b/materialsystem/stdshaders/filmgrain_ps20.fxc @@ -0,0 +1,21 @@ +#define HDRTYPE HDR_TYPE_NONE +#include "common_ps_fxc.h" + +sampler FilmGrainSampler : register( s0 ); + +const float4 vNoiseScale : register( c0 ); + +struct PS_INPUT +{ + float2 grainTexCoord : TEXCOORD0; +}; + +float4 main( PS_INPUT i ) : COLOR +{ + float4 noise = tex2D( FilmGrainSampler, i.grainTexCoord ); + + noise.w = noise.x*(1.0-vNoiseScale.w) + vNoiseScale.w; + noise.xyz *= vNoiseScale.xyz; + + return float4( noise.x, noise.y, noise.z, noise.w ); +} diff --git a/materialsystem/stdshaders/filmgrain_vs20.fxc b/materialsystem/stdshaders/filmgrain_vs20.fxc new file mode 100644 index 0000000..5580015 --- /dev/null +++ b/materialsystem/stdshaders/filmgrain_vs20.fxc @@ -0,0 +1,32 @@ +#include "common_vs_fxc.h" + +struct VS_INPUT +{ + float3 vPos : POSITION; + float2 vInputImageCoord : TEXCOORD0; +}; + +struct VS_OUTPUT +{ + float4 projPos : POSITION; + float2 InputImageCoord : TEXCOORD0; + float2 FilmGrainCoord : TEXCOORD1; +}; + +// +const float4 cFilmGrainOffset : register( SHADER_SPECIFIC_CONST_0 ); // should be SHADER_SPECIFIC_CONST_0 + + +VS_OUTPUT main( const VS_INPUT v ) +{ + VS_OUTPUT o = ( VS_OUTPUT )0; + + // Just copy these through to the output... + o.projPos = float4( v.vPos, 1.0f ); + o.InputImageCoord = v.vInputImageCoord; + + // Scale and bias the input coordinates to get grain coordinates + o.FilmGrainCoord.xy = v.vInputImageCoord.xy * cFilmGrainOffset.xy + cFilmGrainOffset.zw; + + return o; +} diff --git a/materialsystem/stdshaders/flashlight_ps11.fxc b/materialsystem/stdshaders/flashlight_ps11.fxc new file mode 100644 index 0000000..f2416d1 --- /dev/null +++ b/materialsystem/stdshaders/flashlight_ps11.fxc @@ -0,0 +1,69 @@ +//====== Copyright © 1996-2004, Valve Corporation, All rights reserved. ======= +// +// Purpose: +// +//============================================================================= + +// STATIC: "NORMALMAP" "0..1" +// STATIC: "NOCULL" "0..1" + +#include "common_ps_fxc.h" + +sampler SpotSampler : register( s0 ); +sampler BaseTextureSampler : register( s1 ); +sampler NormalizingCubemapSampler : register( s2 ); +// use a normalizing cube map here if we aren't normal mapping +#if NORMALMAP +sampler NormalMapSampler : register( s3 ); +#else +sampler NormalizingCubemapSampler2 : register( s3 ); +#endif + +static const HALF g_OverbrightFactor = 2.0f; + +struct PS_INPUT +{ + float4 spotTexCoord : TEXCOORD0; + float2 baseTexCoord : TEXCOORD1; +#if NORMALMAP + float3 tangentPosToLightVector : TEXCOORD2; + float2 normalMapTexCoord : TEXCOORD3; +#else + float3 worldPosToLightVector : TEXCOORD2; + float3 normal : TEXCOORD3; +#endif + float4 vertAtten : COLOR0; +}; + +float4 main( PS_INPUT i ) : COLOR +{ +#if NORMALMAP + float3 normal = tex2D( NormalMapSampler, i.normalMapTexCoord ) * 2.0f - 1.0f; +#else + float3 normal = texCUBE( NormalizingCubemapSampler2, i.normal ) * 2.0f - 1.0f; +#endif + + float3 spotColor = tex2D( SpotSampler, i.spotTexCoord ); + float4 baseSample = tex2D( BaseTextureSampler, i.baseTexCoord ); + float3 baseColor = baseSample.xyz; +#if NORMALMAP + // wrap this! + float3 tangentPosToLightVector = texCUBE( NormalizingCubemapSampler, i.tangentPosToLightVector ) * 2.0f - 1.0f; + float nDotL = saturate( dot( tangentPosToLightVector, normal ) ); +#else + float3 worldPosToLightVector = texCUBE( NormalizingCubemapSampler, i.worldPosToLightVector ) * 2.0f - 1.0f; + float nDotL = saturate( dot( worldPosToLightVector, normal ) ); +#endif + float3 outcolor; + + outcolor = spotColor * baseColor * g_OverbrightFactor; + +#if !NOCULL + outcolor *= nDotL; +#endif + + // NOTE!! This has to be last to avoid loss of range. + outcolor *= i.vertAtten; + + return float4( outcolor.xyz, baseSample.a * i.vertAtten.a ); +} diff --git a/materialsystem/stdshaders/flashlight_ps2x.fxc b/materialsystem/stdshaders/flashlight_ps2x.fxc new file mode 100644 index 0000000..8ac860c --- /dev/null +++ b/materialsystem/stdshaders/flashlight_ps2x.fxc @@ -0,0 +1,235 @@ +//====== Copyright c 1996-2004, Valve Corporation, All rights reserved. ======= +// +// Purpose: +// +//============================================================================= + + + +// STATIC: "NORMALMAP" "0..2" +// STATIC: "NORMALMAP2" "0..1" +// STATIC: "WORLDVERTEXTRANSITION" "0..1" +// STATIC: "SEAMLESS" "0..1" +// STATIC: "DETAILTEXTURE" "0..1" +// STATIC: "DETAIL_BLEND_MODE" "0..1" +// STATIC: "FLASHLIGHTDEPTHFILTERMODE" "0..2" [ps20b] [PC] +// STATIC: "FLASHLIGHTDEPTHFILTERMODE" "0..0" [ps20b] [XBOX] + +// DYNAMIC: "PIXELFOGTYPE" "0..1" +// DYNAMIC: "FLASHLIGHTSHADOWS" "0..1" [ps20b] + +// SKIP: !$WORLDVERTEXTRANSITION && $NORMALMAP2 +// SKIP: !$NORMALMAP && $NORMALMAP2 +// SKIP: !$DETAILTEXTURE && ( $DETAIL_BLEND_MODE != 0 ) + +#include "shader_constant_register_map.h" +#include "common_flashlight_fxc.h" +#include "common_lightmappedgeneric_fxc.h" + +const float4 g_vShadowTweaks : register( PSREG_ENVMAP_TINT__SHADOW_TWEAKS ); +const float4 g_FogParams : register( PSREG_FOG_PARAMS ); +const float4 g_EyePos : register( PSREG_EYEPOS_SPEC_EXPONENT ); +const float4 g_FlashlightAttenuation : register( PSREG_FLASHLIGHT_ATTENUATION ); +const float4 g_DetailConstants : register( c0 ); + +sampler SpotSampler : register( s0 ); +sampler BaseTextureSampler : register( s1 ); +sampler NormalizingCubemapSampler : register( s2 ); + +// use a normalizing cube map here if we aren't normal mapping +sampler BumpMapSampler : register( s3 ); +sampler BaseTextureSampler2 : register( s4 ); + +#ifdef WORLDVERTEXTRANSITION +sampler NormalMap2Sampler : register( s6 ); +#endif + +#if DETAILTEXTURE +sampler DetailSampler : register( s8 ); +#endif + +#if FLASHLIGHTSHADOWS && ( defined( SHADER_MODEL_PS_2_B ) || defined( SHADER_MODEL_PS_3_0 ) ) +sampler RandomRotationSampler : register( s5 ); // Random rotation sampler +sampler FlashlightDepthSampler : register( s7 ); +#endif + +struct PS_INPUT +{ + float4 spotTexCoord : TEXCOORD0; +#if SEAMLESS + float3 SeamlessTexCoord : TEXCOORD1; +#else + float2 baseTexCoord : TEXCOORD1; +#endif +#if NORMALMAP + float3 tangentPosToLightVector : TEXCOORD2; + float2 normalMapTexCoord : TEXCOORD3; +#else + float3 worldPosToLightVector : TEXCOORD2; + float3 normal : TEXCOORD3; +#endif + + float2 detailCoords : TEXCOORD4; + float4 worldPos_worldTransition : TEXCOORD5; + float3 projPos : TEXCOORD6; + float4 fogFactorW : TEXCOORD7; +}; + + + +float4 SampleNormal( sampler s, PS_INPUT i ) +{ +#if SEAMLESS + float4 szy=tex2D( s, i.SeamlessTexCoord.zy ); + float4 sxz=tex2D( s, i.SeamlessTexCoord.xz ); + float4 syx=tex2D( s, i.SeamlessTexCoord.xy ); + return i.fogFactorW.r*szy + i.fogFactorW.g*sxz + i.fogFactorW.b*syx; +#else +#if NORMALMAP + return tex2D( s, i.normalMapTexCoord.xy); +#else + return float4(0,0,1,1); +#endif +#endif + +} + +float4 main( PS_INPUT i ) : COLOR +{ + bool bBase2 = WORLDVERTEXTRANSITION ? true : false; + bool bBump = (NORMALMAP != 0) ? true : false; + + // Do spot stuff early since we can bail out + float3 spotColor = float3(0,0,0); + float3 vProjCoords = i.spotTexCoord.xyz / i.spotTexCoord.w; + +#if ( defined( _X360 ) ) + + float3 ltz = vProjCoords.xyz < float3( 0.0f, 0.0f, 0.0f ); + float3 gto = vProjCoords.xyz > float3( 1.0f, 1.0f, 1.0f ); + + [branch] + if ( dot(ltz + gto, float3(1,1,1)) > 0 ) + { + clip (-1); + return float4(0,0,0,0); + } + else + { + spotColor = tex2D( SpotSampler, vProjCoords ); + + [branch] + if ( dot(spotColor.xyz, float3(1,1,1)) <= 0 ) + { + clip(-1); + return float4(0,0,0,0); + } + else + { +#else + spotColor = tex2D( SpotSampler, vProjCoords ); +#endif + + float4 baseColor = 0.0f; + float4 baseColor2 = 0.0f; + float4 vNormal = float4(0, 0, 1, 1); + float3 baseTexCoords = float3(0,0,0); + +#if SEAMLESS + baseTexCoords = i.SeamlessTexCoord.xyz; +#else + baseTexCoords.xy = i.baseTexCoord.xy; +#endif + + GetBaseTextureAndNormal( BaseTextureSampler, BaseTextureSampler2, BumpMapSampler, bBase2, bBump, baseTexCoords, i.fogFactorW.xyz, baseColor, baseColor2, vNormal ); + +#if WORLDVERTEXTRANSITION + float lerpAlpha = 1-i.worldPos_worldTransition.a; +#endif + +#if ( NORMALMAP == 0 ) + vNormal.xyz = normalize( i.normal.xyz ); +#endif + +#if ( NORMALMAP == 1 ) + vNormal.xyz = vNormal.xyz * 2.0f - 1.0f; // signed + +# if NORMALMAP2 + float3 normal2 = SampleNormal( NormalMap2Sampler, i ) * 2.0f - 1.0f; + vNormal.xyz = lerp( normal2, vNormal.xyz, lerpAlpha ); +# endif +#endif + +// ssbump +#if ( NORMALMAP == 2 ) + +# if NORMALMAP2 + float3 normal2 = SampleNormal( NormalMap2Sampler, i ); + vNormal.xyz = lerp( normal2, vNormal.xyz, lerpAlpha ); +# endif +#else + // Normalize normal after all of the lerps above (including the tri/bilinear texel fetches) + vNormal.xyz = normalize( vNormal.xyz ); +#endif + + spotColor.rgb *= cFlashlightColor.rgb; + + // Compute per-pixel distance attenuation + float3 delta = g_EyePos.xyz - i.worldPos_worldTransition.xyz; + float distSquared = dot( delta, delta ); + float dist = sqrt( distSquared ); + float farZ = g_FlashlightAttenuation.w; + float endFalloffFactor = RemapValClamped( dist, farZ, 0.6f * farZ, 0.0f, 1.0f ); + float flAtten = saturate(endFalloffFactor * dot( g_FlashlightAttenuation.xyz, float3( 1.0f, 1.0f/dist, 1.0f/distSquared ) ) ); + +#if FLASHLIGHTSHADOWS && ( defined( SHADER_MODEL_PS_2_B ) || defined( SHADER_MODEL_PS_3_0 ) ) + float flShadow = DoFlashlightShadow( FlashlightDepthSampler, RandomRotationSampler, vProjCoords, i.projPos.xy / i.projPos.z, FLASHLIGHTDEPTHFILTERMODE, g_vShadowTweaks, false ); + float flAttenuated = lerp( flShadow, 1.0f, g_vShadowTweaks.y ); // Blend between fully attenuated and not attenuated + flShadow = saturate(lerp( flAttenuated, flShadow, flAtten )); // Blend between shadow and above, according to light attenuation + spotColor *= flShadow; +#endif + +#if WORLDVERTEXTRANSITION + baseColor.xyz = lerp( baseColor2.xyz, baseColor.xyz, lerpAlpha ); +#endif + +#if DETAILTEXTURE + float4 detailColor = float4( g_DetailConstants.xyz, 1.0f ) * tex2D( DetailSampler, i.detailCoords ); + float4 vBase = TextureCombine( float4(baseColor.xyz, 1.0f), detailColor, DETAIL_BLEND_MODE, g_DetailConstants.w ); + baseColor.xyz = vBase.xyz; +#endif + +#if NORMALMAP == 0 + float3 worldPosToLightVector = texCUBE( NormalizingCubemapSampler, i.worldPosToLightVector ) * 2.0f - 1.0f; + float nDotL = dot( worldPosToLightVector, vNormal.xyz ); +#endif + +#if NORMALMAP == 1 + // flashlightfixme: wrap this! + float3 tangentPosToLightVector = texCUBE( NormalizingCubemapSampler, i.tangentPosToLightVector ) * 2.0f - 1.0f; + float nDotL = dot( tangentPosToLightVector, vNormal.xyz ); +#endif + +#if NORMALMAP == 2 + float3 tangentPosToLightVector = normalize( i.tangentPosToLightVector ); + + float nDotL = + vNormal.x*dot( tangentPosToLightVector, bumpBasis[0]) + + vNormal.y*dot( tangentPosToLightVector, bumpBasis[1]) + + vNormal.z*dot( tangentPosToLightVector, bumpBasis[2]); +#endif + + float3 outColor; + outColor = spotColor * baseColor.xyz * saturate( nDotL ); + outColor *= flAtten; + + float fogFactor = CalcPixelFogFactor( PIXELFOGTYPE, g_FogParams, g_EyePos.z, i.worldPos_worldTransition.z, i.projPos.z ); + return FinalOutput( float4(outColor, baseColor.a) , fogFactor, PIXELFOGTYPE, TONEMAP_SCALE_LINEAR ); + + // so we can jump over all of the above +#if ( defined( _X360 ) ) + } + } +#endif + +} diff --git a/materialsystem/stdshaders/flesh_interior_blended_pass_dx8_helper.cpp b/materialsystem/stdshaders/flesh_interior_blended_pass_dx8_helper.cpp new file mode 100644 index 0000000..9b02330 --- /dev/null +++ b/materialsystem/stdshaders/flesh_interior_blended_pass_dx8_helper.cpp @@ -0,0 +1,271 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// + +/* Example how to plug this into an existing shader: + + In the VMT: + // Flesh Interior Pass + "$FleshInteriorEnabled" "1" // Enables effect + "$FleshInteriorTexture" "models/Alyx/alyx_flesh_color" // Mask in alpha + "$FleshNormalTexture" "models/Alyx/alyx_flesh_normal" + "$FleshBorderTexture1D" "models/Alyx/alyx_flesh_border" + "$FleshInteriorNoiseTexture" "Engine/noise-blur-256x256" + "$FleshSubsurfaceTexture" "models/Alyx/alyx_flesh_subsurface" + "$FleshBorderNoiseScale" "1.5" // Flesh Noise UV scalar for border + "$FleshBorderWidth" "0.3" // Width of flesh border + "$FleshBorderSoftness" "0.42" // Border softness must be greater than 0.0 and up tp 0.5 + "$FleshBorderTint" "[1 1 1]" // Tint / brighten the border 1D texture + "$FleshGlossBrightness" "0.66" // Change the brightness of the glossy layer + "$FleshDebugForceFleshOn" "0" // DEBUG: This will force on full flesh for testing + "$FleshScrollSpeed" "1.0" + "Proxies" + { + "FleshInterior" + { + } + } + + #include "flesh_interior_blended_pass_helper.h" + + In BEGIN_SHADER_PARAMS: + // Flesh Interior Pass + SHADER_PARAM( FLESHINTERIORENABLED, SHADER_PARAM_TYPE_BOOL, "0", "Enable Flesh interior blend pass" ) + SHADER_PARAM( FLESHINTERIORTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "Flesh color texture" ) + SHADER_PARAM( FLESHINTERIORNOISETEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "Flesh noise texture" ) + SHADER_PARAM( FLESHBORDERTEXTURE1D, SHADER_PARAM_TYPE_TEXTURE, "", "Flesh border 1D texture" ) + SHADER_PARAM( FLESHNORMALTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "Flesh normal texture" ) + SHADER_PARAM( FLESHSUBSURFACETEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "Flesh subsurface texture" ) + SHADER_PARAM( FLESHCUBETEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "Flesh cubemap texture" ) + SHADER_PARAM( FLESHBORDERNOISESCALE, SHADER_PARAM_TYPE_FLOAT, "1.5", "Flesh Noise UV scalar for border" ) + SHADER_PARAM( FLESHDEBUGFORCEFLESHON, SHADER_PARAM_TYPE_BOOL, "0", "Flesh Debug full flesh" ) + SHADER_PARAM( FLESHEFFECTCENTERRADIUS1, SHADER_PARAM_TYPE_VEC4, "[0 0 0 0.001]", "Flesh effect center and radius" ) + SHADER_PARAM( FLESHEFFECTCENTERRADIUS2, SHADER_PARAM_TYPE_VEC4, "[0 0 0 0.001]", "Flesh effect center and radius" ) + SHADER_PARAM( FLESHEFFECTCENTERRADIUS3, SHADER_PARAM_TYPE_VEC4, "[0 0 0 0.001]", "Flesh effect center and radius" ) + SHADER_PARAM( FLESHEFFECTCENTERRADIUS4, SHADER_PARAM_TYPE_VEC4, "[0 0 0 0.001]", "Flesh effect center and radius" ) + SHADER_PARAM( FLESHSUBSURFACETINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "Subsurface Color" ) + SHADER_PARAM( FLESHBORDERWIDTH, SHADER_PARAM_TYPE_FLOAT, "0.3", "Flesh border" ) + SHADER_PARAM( FLESHBORDERSOFTNESS, SHADER_PARAM_TYPE_FLOAT, "0.42", "Flesh border softness (> 0.0 && <= 0.5)" ) + SHADER_PARAM( FLESHBORDERTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "Flesh border Color" ) + SHADER_PARAM( FLESHGLOBALOPACITY, SHADER_PARAM_TYPE_FLOAT, "1.0", "Flesh global opacity" ) + SHADER_PARAM( FLESHGLOSSBRIGHTNESS, SHADER_PARAM_TYPE_FLOAT, "0.66", "Flesh gloss brightness" ) + SHADER_PARAM( FLESHSCROLLSPEED, SHADER_PARAM_TYPE_FLOAT, "1.0", "Flesh scroll speed" ) + + Add this above SHADER_INIT_PARAMS() + // Flesh Interior Pass + void SetupVarsFleshInteriorBlendedPass( FleshInteriorBlendedPassVars_t &info ) + { + info.m_nFleshTexture = FLESHINTERIORTEXTURE; + info.m_nFleshNoiseTexture = FLESHINTERIORNOISETEXTURE; + info.m_nFleshBorderTexture1D = FLESHBORDERTEXTURE1D; + info.m_nFleshNormalTexture = FLESHNORMALTEXTURE; + info.m_nFleshSubsurfaceTexture = FLESHSUBSURFACETEXTURE; + info.m_nFleshCubeTexture = FLESHCUBETEXTURE; + + info.m_nflBorderNoiseScale = FLESHBORDERNOISESCALE; + info.m_nflDebugForceFleshOn = FLESHDEBUGFORCEFLESHON; + info.m_nvEffectCenterRadius1 = FLESHEFFECTCENTERRADIUS1; + info.m_nvEffectCenterRadius2 = FLESHEFFECTCENTERRADIUS2; + info.m_nvEffectCenterRadius3 = FLESHEFFECTCENTERRADIUS3; + info.m_nvEffectCenterRadius4 = FLESHEFFECTCENTERRADIUS4; + + info.m_ncSubsurfaceTint = FLESHSUBSURFACETINT; + info.m_nflBorderWidth = FLESHBORDERWIDTH; + info.m_nflBorderSoftness = FLESHBORDERSOFTNESS; + info.m_ncBorderTint = FLESHBORDERTINT; + info.m_nflGlobalOpacity = FLESHGLOBALOPACITY; + info.m_nflGlossBrightness = FLESHGLOSSBRIGHTNESS; + info.m_nflScrollSpeed = FLESHSCROLLSPEED; + } + + In SHADER_INIT_PARAMS() + // Flesh Interior Pass + if ( !params[FLESHINTERIORENABLED]->IsDefined() ) + { + params[FLESHINTERIORENABLED]->SetIntValue( 0 ); + } + else if ( params[FLESHINTERIORENABLED]->GetIntValue() ) + { + FleshInteriorBlendedPassVars_t info; + SetupVarsFleshInteriorBlendedPass( info ); + InitParamsFleshInteriorBlendedPass( this, params, pMaterialName, info ); + } + + In SHADER_INIT + // Flesh Interior Pass + if ( params[FLESHINTERIORENABLED]->GetIntValue() ) + { + FleshInteriorBlendedPassVars_t info; + SetupVarsFleshInteriorBlendedPass( info ); + InitFleshInteriorBlendedPass( this, params, info ); + } + + At the very end of SHADER_DRAW + // Flesh Interior Pass + if ( params[FLESHINTERIORENABLED]->GetIntValue() ) + { + // If ( snapshotting ) or ( we need to draw this frame ) + if ( ( pShaderShadow != NULL ) || ( true ) ) + { + FleshInteriorBlendedPassVars_t info; + SetupVarsFleshInteriorBlendedPass( info ); + DrawFleshInteriorBlendedPass( this, params, pShaderAPI, pShaderShadow, info ); + } + else // We're not snapshotting and we don't need to draw this frame + { + // Skip this pass! + Draw( false ); + } + } + +==================================================================================================== */ + +#include "BaseVSShader.h" +#include "mathlib/vmatrix.h" +#include "convar.h" +#include "flesh_interior_blended_pass_helper.h" + +// Auto generated inc files +#include "flesh_interior_blended_pass_dx8_vs11.inc" + +void InitParamsFleshInteriorBlendedPass( CBaseVSShader *pShader, IMaterialVar** params, const char *pMaterialName, FleshInteriorBlendedPassVars_t &info ) +{ + SET_FLAGS2( MATERIAL_VAR2_SUPPORTS_HW_SKINNING ); + + SET_PARAM_STRING_IF_NOT_DEFINED( info.m_nFleshCubeTexture, "env_cubemap" ); // Default to in-game env map + SET_PARAM_FLOAT_IF_NOT_DEFINED( info.m_nflBorderNoiseScale, kDefaultBorderNoiseScale ); + SET_PARAM_FLOAT_IF_NOT_DEFINED( info.m_nflDebugForceFleshOn, kDefaultDebugForceFleshOn ); + SET_PARAM_VEC_IF_NOT_DEFINED( info.m_nvEffectCenterRadius1, kDefaultEffectCenterRadius, 4 ); + SET_PARAM_VEC_IF_NOT_DEFINED( info.m_nvEffectCenterRadius2, kDefaultEffectCenterRadius, 4 ); + SET_PARAM_VEC_IF_NOT_DEFINED( info.m_nvEffectCenterRadius3, kDefaultEffectCenterRadius, 4 ); + SET_PARAM_VEC_IF_NOT_DEFINED( info.m_nvEffectCenterRadius4, kDefaultEffectCenterRadius, 4 ); + SET_PARAM_VEC_IF_NOT_DEFINED( info.m_ncSubsurfaceTint, kDefaultSubsurfaceTint, 4 ); + SET_PARAM_FLOAT_IF_NOT_DEFINED( info.m_nflBorderWidth, kDefaultBorderWidth ); + SET_PARAM_FLOAT_IF_NOT_DEFINED( info.m_nflBorderSoftness, kDefaultBorderSoftness ); + SET_PARAM_VEC_IF_NOT_DEFINED( info.m_ncBorderTint, kDefaultBorderTint, 4 ); + SET_PARAM_FLOAT_IF_NOT_DEFINED( info.m_nflGlobalOpacity, kDefaultGlobalOpacity ); + SET_PARAM_FLOAT_IF_NOT_DEFINED( info.m_nflGlossBrightness, kDefaultGlossBrightness ); + SET_PARAM_FLOAT_IF_NOT_DEFINED( info.m_nflScrollSpeed, kDefaultScrollSpeed ); + SET_PARAM_FLOAT_IF_NOT_DEFINED( info.m_nTime, 0.0f ); +} + +void InitFleshInteriorBlendedPass( CBaseVSShader *pShader, IMaterialVar** params, FleshInteriorBlendedPassVars_t &info ) +{ + // Load textures + pShader->LoadTexture( info.m_nFleshTexture ); + //pShader->LoadTexture( info.m_nFleshNoiseTexture ); + //pShader->LoadTexture( info.m_nFleshBorderTexture1D ); + //pShader->LoadTexture( info.m_nFleshNormalTexture ); + //pShader->LoadTexture( info.m_nFleshSubsurfaceTexture ); + //pShader->LoadCubeMap( info.m_nFleshCubeTexture ); +} + +void DrawFleshInteriorBlendedPass( CBaseVSShader *pShader, IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, + IShaderShadow* pShaderShadow, FleshInteriorBlendedPassVars_t &info, VertexCompressionType_t vertexCompression ) +{ + SHADOW_STATE + { + // Reset shadow state manually since we're drawing from two materials + pShader->SetInitialShadowState(); + + // Set stream format (note that this shader supports compression) + unsigned int flags = VERTEX_POSITION | VERTEX_NORMAL | VERTEX_FORMAT_COMPRESSED; + int nTexCoordCount = 1; + int userDataSize = 0; + pShaderShadow->VertexShaderVertexFormat( flags, nTexCoordCount, NULL, userDataSize ); + + // Vertex Shader + flesh_interior_blended_pass_dx8_vs11_Static_Index vshIndex; + pShaderShadow->SetVertexShader( "flesh_interior_blended_pass_dx8_vs11", vshIndex.GetIndex() ); + + // Pixel Shader + pShaderShadow->SetPixelShader( "flesh_interior_blended_pass_dx8_ps11", 0 ); + + // Textures + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + + // Blending + pShader->EnableAlphaBlending( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA ); + pShaderShadow->EnableAlphaTest( true ); + pShaderShadow->AlphaFunc( SHADER_ALPHAFUNC_GREATER, 0.0f ); + } + DYNAMIC_STATE + { + // Reset render state manually since we're drawing from two materials + pShaderAPI->SetDefaultState(); + + // Set Vertex Shader Combos + flesh_interior_blended_pass_dx8_vs11_Dynamic_Index vshIndex; + vshIndex.SetSKINNING( pShaderAPI->GetCurrentNumBones() > 0 ); + pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() ); + + // Set Vertex Shader Constants + + // Time % 1000 + float flCurrentTime = IS_PARAM_DEFINED( info.m_nTime ) && params[info.m_nTime]->GetFloatValue() > 0.0f ? params[info.m_nTime]->GetFloatValue() : pShaderAPI->CurrentTime(); + flCurrentTime *= IS_PARAM_DEFINED( info.m_nflScrollSpeed ) ? params[info.m_nflScrollSpeed]->GetFloatValue() : kDefaultScrollSpeed; // This is a dirty hack, but it works well enough + + float vVsConst0[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; + vVsConst0[0] = flCurrentTime; + vVsConst0[0] -= (float)( (int)( vVsConst0[0] / 1000.0f ) ) * 1000.0f; + + // Flesh effect centers and radii + float vVsConst1[4] = { kDefaultEffectCenterRadius[0], kDefaultEffectCenterRadius[1], kDefaultEffectCenterRadius[2], kDefaultEffectCenterRadius[3] }; + if ( IS_PARAM_DEFINED( info.m_nvEffectCenterRadius1 ) ) + { + params[info.m_nvEffectCenterRadius1]->GetVecValue( vVsConst1, 4 ); + if ( vVsConst1[3] < 0.001f ) + vVsConst1[3] = 0.001f; + vVsConst1[3] = 1.0f / vVsConst1[3]; // Pass 1.0/radius so we do a mul instead of a divide in the shader + } + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_1, vVsConst1, 1 ); + + float vVsConst2[4] = { kDefaultEffectCenterRadius[0], kDefaultEffectCenterRadius[1], kDefaultEffectCenterRadius[2], kDefaultEffectCenterRadius[3] }; + if ( IS_PARAM_DEFINED( info.m_nvEffectCenterRadius2 ) ) + { + params[info.m_nvEffectCenterRadius2]->GetVecValue( vVsConst2, 4 ); + if ( vVsConst2[3] < 0.001f ) + vVsConst2[3] = 0.001f; + vVsConst2[3] = 1.0f / vVsConst2[3]; // Pass 1.0/radius so we do a mul instead of a divide in the shader + } + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_2, vVsConst2, 2 ); + + float vVsConst3[4] = { kDefaultEffectCenterRadius[0], kDefaultEffectCenterRadius[1], kDefaultEffectCenterRadius[2], kDefaultEffectCenterRadius[3] }; + if ( IS_PARAM_DEFINED( info.m_nvEffectCenterRadius3 ) ) + { + params[info.m_nvEffectCenterRadius3]->GetVecValue( vVsConst3, 4 ); + if ( vVsConst3[3] < 0.001f ) + vVsConst3[3] = 0.001f; + vVsConst3[3] = 1.0f / vVsConst3[3]; // Pass 1.0/radius so we do a mul instead of a divide in the shader + } + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_3, vVsConst3, 3 ); + + float vVsConst4[4] = { kDefaultEffectCenterRadius[0], kDefaultEffectCenterRadius[1], kDefaultEffectCenterRadius[2], kDefaultEffectCenterRadius[3] }; + if ( IS_PARAM_DEFINED( info.m_nvEffectCenterRadius4 ) ) + { + params[info.m_nvEffectCenterRadius4]->GetVecValue( vVsConst4, 4 ); + if ( vVsConst4[3] < 0.001f ) + vVsConst4[3] = 0.001f; + vVsConst4[3] = 1.0f / vVsConst4[3]; // Pass 1.0/radius so we do a mul instead of a divide in the shader + } + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_4, vVsConst4, 4 ); + + // Set Pixel Shader Combos + /* None */ + + // Bind textures + pShader->BindTexture( SHADER_SAMPLER0, info.m_nFleshTexture ); + + // Set Pixel Shader Constants + + // Border color tint + pShaderAPI->SetPixelShaderConstant( 3, IS_PARAM_DEFINED( info.m_ncBorderTint ) ? params[info.m_ncBorderTint]->GetVecValue() : kDefaultBorderTint, 1 ); + + // Global opacity + float vPsConst4[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; + vPsConst4[0] = IS_PARAM_DEFINED( info.m_nflGlobalOpacity ) ? params[info.m_nflGlobalOpacity]->GetFloatValue() : kDefaultGlobalOpacity; + pShaderAPI->SetPixelShaderConstant( 4, vPsConst4, 1 ); + + float vPsConst5[4] = { 1.0f, 1.0f, 1.0f, 1.0f }; + pShaderAPI->SetPixelShaderConstant( 5, vPsConst5, 1 ); + } + pShader->Draw(); +} diff --git a/materialsystem/stdshaders/flesh_interior_blended_pass_dx8_ps11.psh b/materialsystem/stdshaders/flesh_interior_blended_pass_dx8_ps11.psh new file mode 100644 index 0000000..a9e675d --- /dev/null +++ b/materialsystem/stdshaders/flesh_interior_blended_pass_dx8_ps11.psh @@ -0,0 +1,15 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; c5 1, 1, 1, 1 +;------------------------------------------------------------------------------ + +tex t0 ; Base color + +mul r0, v0, v0 ; // Mask^2 +mul r0, r0, r0 ; // Mask^4 +sub r0, c5, r0 ; // 1.0 - Mask^4 + +mul r0.rgb, r0, t0 ; // * Flesh texture color +mul r0.a, r0.a, t0.a ; // * Flesh X-rated mask +mul r0.a, r0.a, v1.a ; // * Fresnel mask diff --git a/materialsystem/stdshaders/flesh_interior_blended_pass_dx8_vs11.vsh b/materialsystem/stdshaders/flesh_interior_blended_pass_dx8_vs11.vsh new file mode 100644 index 0000000..53b6d87 --- /dev/null +++ b/materialsystem/stdshaders/flesh_interior_blended_pass_dx8_vs11.vsh @@ -0,0 +1,114 @@ +# DYNAMIC: "SKINNING" "0..1" + +vs.1.1 +#include "macros.vsh" + +;------------------------------------------------------------------------------ +; Vertex blending +;------------------------------------------------------------------------------ +&AllocateRegister( \$worldPos ); +&AllocateRegister( \$worldNormal ); +&AllocateRegister( \$projPos ); + +&SkinPositionAndNormal( $worldPos, $worldNormal ); + +if( $SKINNING == 1 ) +{ + &Normalize( $worldNormal ); +} + +;------------------------------------------------------------------------------ +; Transform the position from world to view space +;------------------------------------------------------------------------------ +dp4 $projPos.x, $worldPos, $cViewProj0 +dp4 $projPos.y, $worldPos, $cViewProj1 +dp4 $projPos.z, $worldPos, $cViewProj2 +dp4 $projPos.w, $worldPos, $cViewProj3 + +mov oPos, $projPos + +;------------------------------------------------------------------------------ +; Fog - don't bother with water fog for intro effects +;------------------------------------------------------------------------------ +&DepthFog( $projPos, "oFog" ); +&FreeRegister( \$projPos ); + +;------------------------------------------------------------------------------ +; Flesh area +;------------------------------------------------------------------------------ +; // Store the closest effect intensity +; o.flDistanceToEffectCenter_flFresnelEffect.x = 9999.0f; // A very large distance +; o.flDistanceToEffectCenter_flFresnelEffect.x = min( o.flDistanceToEffectCenter_flFresnelEffect.x, length( vWorldPosition.xyz - g_vEffectCenterOoRadius1.xyz ) * g_vEffectCenterOoRadius1.w ); +; o.flDistanceToEffectCenter_flFresnelEffect.x = min( o.flDistanceToEffectCenter_flFresnelEffect.x, length( vWorldPosition.xyz - g_vEffectCenterOoRadius2.xyz ) * g_vEffectCenterOoRadius2.w ); +; o.flDistanceToEffectCenter_flFresnelEffect.x = min( o.flDistanceToEffectCenter_flFresnelEffect.x, length( vWorldPosition.xyz - g_vEffectCenterOoRadius3.xyz ) * g_vEffectCenterOoRadius3.w ); +; o.flDistanceToEffectCenter_flFresnelEffect.x = min( o.flDistanceToEffectCenter_flFresnelEffect.x, length( vWorldPosition.xyz - g_vEffectCenterOoRadius4.xyz ) * g_vEffectCenterOoRadius4.w ); + +alloc $tmp1 +alloc $flEffect + +mov $flEffect, $cTwo +mad $flEffect, $flEffect, $cTwo, $cTwo + +sub $tmp1.xyz, $worldPos, $SHADER_SPECIFIC_CONST_1 +dp3 $tmp1.w, $tmp1, $tmp1 +rsq $tmp1.w, $tmp1.w +rcp $tmp1.w, $tmp1.w +mul $tmp1.w, $tmp1.w, $SHADER_SPECIFIC_CONST_1.w +min $flEffect, $flEffect, $tmp1.w + +sub $tmp1.xyz, $worldPos, $SHADER_SPECIFIC_CONST_2 +dp3 $tmp1.w, $tmp1, $tmp1 +rsq $tmp1.w, $tmp1.w +rcp $tmp1.w, $tmp1.w +mul $tmp1.w, $tmp1.w, $SHADER_SPECIFIC_CONST_2.w +min $flEffect, $flEffect, $tmp1.w + +sub $tmp1.xyz, $worldPos, $SHADER_SPECIFIC_CONST_3 +dp3 $tmp1.w, $tmp1, $tmp1 +rsq $tmp1.w, $tmp1.w +rcp $tmp1.w, $tmp1.w +mul $tmp1.w, $tmp1.w, $SHADER_SPECIFIC_CONST_3.w +min $flEffect, $flEffect, $tmp1.w + +sub $tmp1.xyz, $worldPos, $SHADER_SPECIFIC_CONST_4 +dp3 $tmp1.w, $tmp1, $tmp1 +rsq $tmp1.w, $tmp1.w +rcp $tmp1.w, $tmp1.w +mul $tmp1.w, $tmp1.w, $SHADER_SPECIFIC_CONST_4.w +min $flEffect, $flEffect, $tmp1.w + +mov oD0, $flEffect + +; float3 vWorldViewVector = normalize( vWorldPosition.xyz - cEyePos.xyz ); +; o.flDistanceToEffectCenter_flFresnelEffect.y = pow( saturate( dot( -vWorldViewVector.xyz, vWorldNormal.xyz ) ), 1.5f ); + +sub $tmp1, $worldPos, $cEyePos +&Normalize( $tmp1 ); +dp3 $tmp1, -$tmp1, $worldNormal +max $tmp1, $tmp1, $cZero +mul $tmp1, $tmp1, $tmp1 +mov oD1, $tmp1 + +free $tmp1 +free $flEffect + +;------------------------------------------------------------------------------ +; Texture coordinates +;------------------------------------------------------------------------------ + +mov oT0.xy, $vTexCoord0 + +alloc $tmp2 + +dp4 $tmp2.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_0 +dp4 $tmp2.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_1 + +add oT1.xy, $tmp2, $SHADER_SPECIFIC_CONST_4 + +free $tmp2 + +; YUCK! This is to make texcoords continuous for mat_softwaretl +mov oT2, $cZero + +&FreeRegister( \$worldPos ); +&FreeRegister( \$worldNormal ); diff --git a/materialsystem/stdshaders/flesh_interior_blended_pass_helper.cpp b/materialsystem/stdshaders/flesh_interior_blended_pass_helper.cpp new file mode 100644 index 0000000..885a4cf --- /dev/null +++ b/materialsystem/stdshaders/flesh_interior_blended_pass_helper.cpp @@ -0,0 +1,355 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// + +/* Example how to plug this into an existing shader: + + In the VMT: + // Flesh Interior Pass + "$FleshInteriorEnabled" "1" // Enables effect + "$FleshInteriorTexture" "models/Alyx/alyx_flesh_color" // Mask in alpha + "$FleshNormalTexture" "models/Alyx/alyx_flesh_normal" + "$FleshBorderTexture1D" "models/Alyx/alyx_flesh_border" + "$FleshInteriorNoiseTexture" "Engine/noise-blur-256x256" + "$FleshSubsurfaceTexture" "models/Alyx/alyx_flesh_subsurface" + "$FleshBorderNoiseScale" "1.5" // Flesh Noise UV scalar for border + "$FleshBorderWidth" "0.3" // Width of flesh border + "$FleshBorderSoftness" "0.42" // Border softness must be greater than 0.0 and up tp 0.5 + "$FleshBorderTint" "[1 1 1]" // Tint / brighten the border 1D texture + "$FleshGlossBrightness" "0.66" // Change the brightness of the glossy layer + "$FleshDebugForceFleshOn" "0" // DEBUG: This will force on full flesh for testing + "$FleshScrollSpeed" "1.0" + "Proxies" + { + "FleshInterior" + { + } + } + + #include "flesh_interior_blended_pass_helper.h" + + In BEGIN_SHADER_PARAMS: + // Flesh Interior Pass + SHADER_PARAM( FLESHINTERIORENABLED, SHADER_PARAM_TYPE_BOOL, "0", "Enable Flesh interior blend pass" ) + SHADER_PARAM( FLESHINTERIORTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "Flesh color texture" ) + SHADER_PARAM( FLESHINTERIORNOISETEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "Flesh noise texture" ) + SHADER_PARAM( FLESHBORDERTEXTURE1D, SHADER_PARAM_TYPE_TEXTURE, "", "Flesh border 1D texture" ) + SHADER_PARAM( FLESHNORMALTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "Flesh normal texture" ) + SHADER_PARAM( FLESHSUBSURFACETEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "Flesh subsurface texture" ) + SHADER_PARAM( FLESHCUBETEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "Flesh cubemap texture" ) + SHADER_PARAM( FLESHBORDERNOISESCALE, SHADER_PARAM_TYPE_FLOAT, "1.5", "Flesh Noise UV scalar for border" ) + SHADER_PARAM( FLESHDEBUGFORCEFLESHON, SHADER_PARAM_TYPE_BOOL, "0", "Flesh Debug full flesh" ) + SHADER_PARAM( FLESHEFFECTCENTERRADIUS1, SHADER_PARAM_TYPE_VEC4, "[0 0 0 0.001]", "Flesh effect center and radius" ) + SHADER_PARAM( FLESHEFFECTCENTERRADIUS2, SHADER_PARAM_TYPE_VEC4, "[0 0 0 0.001]", "Flesh effect center and radius" ) + SHADER_PARAM( FLESHEFFECTCENTERRADIUS3, SHADER_PARAM_TYPE_VEC4, "[0 0 0 0.001]", "Flesh effect center and radius" ) + SHADER_PARAM( FLESHEFFECTCENTERRADIUS4, SHADER_PARAM_TYPE_VEC4, "[0 0 0 0.001]", "Flesh effect center and radius" ) + SHADER_PARAM( FLESHSUBSURFACETINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "Subsurface Color" ) + SHADER_PARAM( FLESHBORDERWIDTH, SHADER_PARAM_TYPE_FLOAT, "0.3", "Flesh border" ) + SHADER_PARAM( FLESHBORDERSOFTNESS, SHADER_PARAM_TYPE_FLOAT, "0.42", "Flesh border softness (> 0.0 && <= 0.5)" ) + SHADER_PARAM( FLESHBORDERTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "Flesh border Color" ) + SHADER_PARAM( FLESHGLOBALOPACITY, SHADER_PARAM_TYPE_FLOAT, "1.0", "Flesh global opacity" ) + SHADER_PARAM( FLESHGLOSSBRIGHTNESS, SHADER_PARAM_TYPE_FLOAT, "0.66", "Flesh gloss brightness" ) + SHADER_PARAM( FLESHSCROLLSPEED, SHADER_PARAM_TYPE_FLOAT, "1.0", "Flesh scroll speed" ) + + Add this above SHADER_INIT_PARAMS() + // Flesh Interior Pass + void SetupVarsFleshInteriorBlendedPass( FleshInteriorBlendedPassVars_t &info ) + { + info.m_nFleshTexture = FLESHINTERIORTEXTURE; + info.m_nFleshNoiseTexture = FLESHINTERIORNOISETEXTURE; + info.m_nFleshBorderTexture1D = FLESHBORDERTEXTURE1D; + info.m_nFleshNormalTexture = FLESHNORMALTEXTURE; + info.m_nFleshSubsurfaceTexture = FLESHSUBSURFACETEXTURE; + info.m_nFleshCubeTexture = FLESHCUBETEXTURE; + + info.m_nflBorderNoiseScale = FLESHBORDERNOISESCALE; + info.m_nflDebugForceFleshOn = FLESHDEBUGFORCEFLESHON; + info.m_nvEffectCenterRadius1 = FLESHEFFECTCENTERRADIUS1; + info.m_nvEffectCenterRadius2 = FLESHEFFECTCENTERRADIUS2; + info.m_nvEffectCenterRadius3 = FLESHEFFECTCENTERRADIUS3; + info.m_nvEffectCenterRadius4 = FLESHEFFECTCENTERRADIUS4; + + info.m_ncSubsurfaceTint = FLESHSUBSURFACETINT; + info.m_nflBorderWidth = FLESHBORDERWIDTH; + info.m_nflBorderSoftness = FLESHBORDERSOFTNESS; + info.m_ncBorderTint = FLESHBORDERTINT; + info.m_nflGlobalOpacity = FLESHGLOBALOPACITY; + info.m_nflGlossBrightness = FLESHGLOSSBRIGHTNESS; + info.m_nflScrollSpeed = FLESHSCROLLSPEED; + } + + In SHADER_INIT_PARAMS() + // Flesh Interior Pass + if ( !params[FLESHINTERIORENABLED]->IsDefined() ) + { + params[FLESHINTERIORENABLED]->SetIntValue( 0 ); + } + else if ( params[FLESHINTERIORENABLED]->GetIntValue() ) + { + FleshInteriorBlendedPassVars_t info; + SetupVarsFleshInteriorBlendedPass( info ); + InitParamsFleshInteriorBlendedPass( this, params, pMaterialName, info ); + } + + In SHADER_INIT + // Flesh Interior Pass + if ( params[FLESHINTERIORENABLED]->GetIntValue() ) + { + FleshInteriorBlendedPassVars_t info; + SetupVarsFleshInteriorBlendedPass( info ); + InitFleshInteriorBlendedPass( this, params, info ); + } + + At the very end of SHADER_DRAW + // Flesh Interior Pass + if ( params[FLESHINTERIORENABLED]->GetIntValue() ) + { + // If ( snapshotting ) or ( we need to draw this frame ) + if ( ( pShaderShadow != NULL ) || ( true ) ) + { + FleshInteriorBlendedPassVars_t info; + SetupVarsFleshInteriorBlendedPass( info ); + DrawFleshInteriorBlendedPass( this, params, pShaderAPI, pShaderShadow, info ); + } + else // We're not snapshotting and we don't need to draw this frame + { + // Skip this pass! + Draw( false ); + } + } + +==================================================================================================== */ + +#include "BaseVSShader.h" +#include "mathlib/vmatrix.h" +#include "convar.h" +#include "flesh_interior_blended_pass_helper.h" + +// Auto generated inc files +#include "flesh_interior_blended_pass_vs20.inc" +#include "flesh_interior_blended_pass_ps20.inc" +#include "flesh_interior_blended_pass_ps20b.inc" + +void InitParamsFleshInteriorBlendedPass( CBaseVSShader *pShader, IMaterialVar** params, const char *pMaterialName, FleshInteriorBlendedPassVars_t &info ) +{ + SET_FLAGS2( MATERIAL_VAR2_SUPPORTS_HW_SKINNING ); + + SET_PARAM_STRING_IF_NOT_DEFINED( info.m_nFleshCubeTexture, "env_cubemap" ); // Default to in-game env map + SET_PARAM_FLOAT_IF_NOT_DEFINED( info.m_nflBorderNoiseScale, kDefaultBorderNoiseScale ); + SET_PARAM_FLOAT_IF_NOT_DEFINED( info.m_nflDebugForceFleshOn, kDefaultDebugForceFleshOn ); + SET_PARAM_VEC_IF_NOT_DEFINED( info.m_nvEffectCenterRadius1, kDefaultEffectCenterRadius, 4 ); + SET_PARAM_VEC_IF_NOT_DEFINED( info.m_nvEffectCenterRadius2, kDefaultEffectCenterRadius, 4 ); + SET_PARAM_VEC_IF_NOT_DEFINED( info.m_nvEffectCenterRadius3, kDefaultEffectCenterRadius, 4 ); + SET_PARAM_VEC_IF_NOT_DEFINED( info.m_nvEffectCenterRadius4, kDefaultEffectCenterRadius, 4 ); + SET_PARAM_VEC_IF_NOT_DEFINED( info.m_ncSubsurfaceTint, kDefaultSubsurfaceTint, 4 ); + SET_PARAM_FLOAT_IF_NOT_DEFINED( info.m_nflBorderWidth, kDefaultBorderWidth ); + SET_PARAM_FLOAT_IF_NOT_DEFINED( info.m_nflBorderSoftness, kDefaultBorderSoftness ); + SET_PARAM_VEC_IF_NOT_DEFINED( info.m_ncBorderTint, kDefaultBorderTint, 4 ); + SET_PARAM_FLOAT_IF_NOT_DEFINED( info.m_nflGlobalOpacity, kDefaultGlobalOpacity ); + SET_PARAM_FLOAT_IF_NOT_DEFINED( info.m_nflGlossBrightness, kDefaultGlossBrightness ); + SET_PARAM_FLOAT_IF_NOT_DEFINED( info.m_nflScrollSpeed, kDefaultScrollSpeed ); + SET_PARAM_FLOAT_IF_NOT_DEFINED( info.m_nTime, 0.0f ); +} + +void InitFleshInteriorBlendedPass( CBaseVSShader *pShader, IMaterialVar** params, FleshInteriorBlendedPassVars_t &info ) +{ + // Load textures + pShader->LoadTexture( info.m_nFleshTexture, TEXTUREFLAGS_SRGB ); + pShader->LoadTexture( info.m_nFleshNoiseTexture ); + pShader->LoadTexture( info.m_nFleshBorderTexture1D, TEXTUREFLAGS_SRGB ); + pShader->LoadTexture( info.m_nFleshNormalTexture ); + pShader->LoadTexture( info.m_nFleshSubsurfaceTexture, TEXTUREFLAGS_SRGB ); + pShader->LoadCubeMap( info.m_nFleshCubeTexture, TEXTUREFLAGS_SRGB ); +} + +void DrawFleshInteriorBlendedPass( CBaseVSShader *pShader, IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, + IShaderShadow* pShaderShadow, FleshInteriorBlendedPassVars_t &info, VertexCompressionType_t vertexCompression ) +{ + SHADOW_STATE + { + // Reset shadow state manually since we're drawing from two materials + pShader->SetInitialShadowState(); + + // Set stream format (note that this shader supports compression) + unsigned int flags = VERTEX_POSITION | VERTEX_NORMAL | VERTEX_FORMAT_COMPRESSED; + int nTexCoordCount = 1; + int userDataSize = 0; + pShaderShadow->VertexShaderVertexFormat( flags, nTexCoordCount, NULL, userDataSize ); + + bool bUseStaticControlFlow = g_pHardwareConfig->SupportsStaticControlFlow(); + + // Vertex Shader + DECLARE_STATIC_VERTEX_SHADER( flesh_interior_blended_pass_vs20 ); + SET_STATIC_VERTEX_SHADER_COMBO( HALFLAMBERT, IS_FLAG_SET( MATERIAL_VAR_HALFLAMBERT ) ); + SET_STATIC_VERTEX_SHADER_COMBO( USE_STATIC_CONTROL_FLOW, bUseStaticControlFlow ); + SET_STATIC_VERTEX_SHADER( flesh_interior_blended_pass_vs20 ); + + // Pixel Shader + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_STATIC_PIXEL_SHADER( flesh_interior_blended_pass_ps20b ); + SET_STATIC_PIXEL_SHADER( flesh_interior_blended_pass_ps20b ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( flesh_interior_blended_pass_ps20 ); + SET_STATIC_PIXEL_SHADER( flesh_interior_blended_pass_ps20 ); + } + + // Textures + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER1, false ); // Noise texture not sRGB + pShaderShadow->EnableTexture( SHADER_SAMPLER2, true ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER2, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER3, true ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER3, false ); // Normal texture not sRGB + pShaderShadow->EnableTexture( SHADER_SAMPLER4, true ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER4, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER5, true ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER5, true ); + pShaderShadow->EnableSRGBWrite( true ); + + // Blending + pShader->EnableAlphaBlending( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA ); + pShaderShadow->EnableAlphaTest( true ); + pShaderShadow->AlphaFunc( SHADER_ALPHAFUNC_GREATER, 0.0f ); + } + DYNAMIC_STATE + { + // Reset render state manually since we're drawing from two materials + pShaderAPI->SetDefaultState(); + + bool bUseStaticControlFlow = g_pHardwareConfig->SupportsStaticControlFlow(); + + // Set Vertex Shader Combos + LightState_t lightState = { 0, false, false }; + pShaderAPI->GetDX9LightState( &lightState ); + DECLARE_DYNAMIC_VERTEX_SHADER( flesh_interior_blended_pass_vs20 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( DOWATERFOG, pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, pShaderAPI->GetCurrentNumBones() > 0 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( DYNAMIC_LIGHT, lightState.HasDynamicLight() ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( STATIC_LIGHT, lightState.m_bStaticLightVertex ? 1 : 0 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( NUM_LIGHTS, bUseStaticControlFlow ? 0 : lightState.m_nNumLights ); + SET_DYNAMIC_VERTEX_SHADER( flesh_interior_blended_pass_vs20 ); + + // Set Vertex Shader Constants + pShader->SetAmbientCubeDynamicStateVertexShader(); + + // Time % 1000 + float flCurrentTime = IS_PARAM_DEFINED( info.m_nTime ) && params[info.m_nTime]->GetFloatValue() > 0.0f ? params[info.m_nTime]->GetFloatValue() : pShaderAPI->CurrentTime(); + flCurrentTime *= IS_PARAM_DEFINED( info.m_nflScrollSpeed ) ? params[info.m_nflScrollSpeed]->GetFloatValue() : kDefaultScrollSpeed; // This is a dirty hack, but it works well enough + + float vVsConst0[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; + vVsConst0[0] = flCurrentTime; + vVsConst0[0] -= (float)( (int)( vVsConst0[0] / 1000.0f ) ) * 1000.0f; + + // Noise UV scroll + vVsConst0[1] = flCurrentTime / 100.0f; + vVsConst0[1] -= (float)( (int)( vVsConst0[1] ) ); + + // Border noise scale + vVsConst0[2] = IS_PARAM_DEFINED( info.m_nflBorderNoiseScale ) ? params[info.m_nflBorderNoiseScale]->GetFloatValue() : kDefaultBorderNoiseScale; + + // Debug force flesh on + vVsConst0[3] = IS_PARAM_DEFINED( info.m_nflDebugForceFleshOn ) ? params[info.m_nflDebugForceFleshOn]->GetFloatValue() : kDefaultDebugForceFleshOn; + + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, vVsConst0, 1 ); + + // Flesh effect centers and radii + float vVsConst1[4] = { kDefaultEffectCenterRadius[0], kDefaultEffectCenterRadius[1], kDefaultEffectCenterRadius[2], kDefaultEffectCenterRadius[3] }; + if ( IS_PARAM_DEFINED( info.m_nvEffectCenterRadius1 ) ) + { + params[info.m_nvEffectCenterRadius1]->GetVecValue( vVsConst1, 4 ); + if ( vVsConst1[3] < 0.001f ) + vVsConst1[3] = 0.001f; + vVsConst1[3] = 1.0f / vVsConst1[3]; // Pass 1.0/radius so we do a mul instead of a divide in the shader + } + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_1, vVsConst1, 1 ); + + float vVsConst2[4] = { kDefaultEffectCenterRadius[0], kDefaultEffectCenterRadius[1], kDefaultEffectCenterRadius[2], kDefaultEffectCenterRadius[3] }; + if ( IS_PARAM_DEFINED( info.m_nvEffectCenterRadius2 ) ) + { + params[info.m_nvEffectCenterRadius2]->GetVecValue( vVsConst2, 4 ); + if ( vVsConst2[3] < 0.001f ) + vVsConst2[3] = 0.001f; + vVsConst2[3] = 1.0f / vVsConst2[3]; // Pass 1.0/radius so we do a mul instead of a divide in the shader + } + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_2, vVsConst2, 2 ); + + float vVsConst3[4] = { kDefaultEffectCenterRadius[0], kDefaultEffectCenterRadius[1], kDefaultEffectCenterRadius[2], kDefaultEffectCenterRadius[3] }; + if ( IS_PARAM_DEFINED( info.m_nvEffectCenterRadius3 ) ) + { + params[info.m_nvEffectCenterRadius3]->GetVecValue( vVsConst3, 4 ); + if ( vVsConst3[3] < 0.001f ) + vVsConst3[3] = 0.001f; + vVsConst3[3] = 1.0f / vVsConst3[3]; // Pass 1.0/radius so we do a mul instead of a divide in the shader + } + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_3, vVsConst3, 3 ); + + float vVsConst4[4] = { kDefaultEffectCenterRadius[0], kDefaultEffectCenterRadius[1], kDefaultEffectCenterRadius[2], kDefaultEffectCenterRadius[3] }; + if ( IS_PARAM_DEFINED( info.m_nvEffectCenterRadius4 ) ) + { + params[info.m_nvEffectCenterRadius4]->GetVecValue( vVsConst4, 4 ); + if ( vVsConst4[3] < 0.001f ) + vVsConst4[3] = 0.001f; + vVsConst4[3] = 1.0f / vVsConst4[3]; // Pass 1.0/radius so we do a mul instead of a divide in the shader + } + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_4, vVsConst4, 4 ); + + // Set Pixel Shader Combos + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_DYNAMIC_PIXEL_SHADER( flesh_interior_blended_pass_ps20b ); + SET_DYNAMIC_PIXEL_SHADER( flesh_interior_blended_pass_ps20b ); + } + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( flesh_interior_blended_pass_ps20 ); + SET_DYNAMIC_PIXEL_SHADER( flesh_interior_blended_pass_ps20 ); + } + + // Bind textures + pShader->BindTexture( SHADER_SAMPLER0, info.m_nFleshTexture ); + pShader->BindTexture( SHADER_SAMPLER1, info.m_nFleshNoiseTexture ); + pShader->BindTexture( SHADER_SAMPLER2, info.m_nFleshBorderTexture1D ); + pShader->BindTexture( SHADER_SAMPLER3, info.m_nFleshNormalTexture ); + pShader->BindTexture( SHADER_SAMPLER4, info.m_nFleshSubsurfaceTexture ); + pShader->BindTexture( SHADER_SAMPLER5, info.m_nFleshCubeTexture ); + + // Set Pixel Shader Constants + + // Subsurface tint + pShaderAPI->SetPixelShaderConstant( 0, IS_PARAM_DEFINED( info.m_ncSubsurfaceTint ) ? params[info.m_ncSubsurfaceTint]->GetVecValue() : kDefaultSubsurfaceTint, 1 ); + + // Border width + float vPsConst1[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; + vPsConst1[0] = IS_PARAM_DEFINED( info.m_nflBorderWidth ) ? params[info.m_nflBorderWidth]->GetFloatValue() : kDefaultBorderWidth; + vPsConst1[0] = 1.0f / vPsConst1[0]; // ( 1.0f / g_flBorderWidthFromVmt ) + vPsConst1[1] = vPsConst1[0] - 1.0f; // ( 1.0f / g_flBorderWidthFromVmt ) - 1.0f + pShaderAPI->SetPixelShaderConstant( 1, vPsConst1, 1 ); + + // Border softness + float vPsConst2[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; + vPsConst2[0] = IS_PARAM_DEFINED( info.m_nflBorderSoftness ) ? params[info.m_nflBorderSoftness]->GetFloatValue() : kDefaultBorderSoftness; + if ( vPsConst2[0] < 0.01f ) + vPsConst2[0] = 0.01f; + else if ( vPsConst2[0] > 0.5f ) + vPsConst2[0] = 0.5f; + pShaderAPI->SetPixelShaderConstant( 2, vPsConst2, 1 ); + + // Border color tint + pShaderAPI->SetPixelShaderConstant( 3, IS_PARAM_DEFINED( info.m_ncBorderTint ) ? params[info.m_ncBorderTint]->GetVecValue() : kDefaultBorderTint, 1 ); + + // Global opacity + float vPsConst4[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; + vPsConst4[0] = IS_PARAM_DEFINED( info.m_nflGlobalOpacity ) ? params[info.m_nflGlobalOpacity]->GetFloatValue() : kDefaultGlobalOpacity; + pShaderAPI->SetPixelShaderConstant( 4, vPsConst4, 1 ); + + // Gloss brightness + float vPsConst5[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; + vPsConst5[0] = IS_PARAM_DEFINED( info.m_nflGlossBrightness ) ? params[info.m_nflGlossBrightness]->GetFloatValue() : kDefaultGlossBrightness; + pShaderAPI->SetPixelShaderConstant( 5, vPsConst5, 1 ); + } + pShader->Draw(); +} diff --git a/materialsystem/stdshaders/flesh_interior_blended_pass_helper.h b/materialsystem/stdshaders/flesh_interior_blended_pass_helper.h new file mode 100644 index 0000000..92b8d57 --- /dev/null +++ b/materialsystem/stdshaders/flesh_interior_blended_pass_helper.h @@ -0,0 +1,68 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// + +#ifndef FLESH_INTERIOR_BLENDED_PASS_HELPER_H +#define FLESH_INTERIOR_BLENDED_PASS_HELPER_H +#ifdef _WIN32 +#pragma once +#endif + +#include + +//----------------------------------------------------------------------------- +// Forward declarations +//----------------------------------------------------------------------------- +class CBaseVSShader; +class IMaterialVar; +class IShaderDynamicAPI; +class IShaderShadow; + +//----------------------------------------------------------------------------- +// Init params/ init/ draw methods +//----------------------------------------------------------------------------- +struct FleshInteriorBlendedPassVars_t +{ + FleshInteriorBlendedPassVars_t() { memset( this, 0xFF, sizeof(FleshInteriorBlendedPassVars_t) ); } + + int m_nFleshTexture; + int m_nFleshNoiseTexture; + int m_nFleshBorderTexture1D; + int m_nFleshNormalTexture; + int m_nFleshSubsurfaceTexture; + int m_nFleshCubeTexture; + + int m_nflBorderNoiseScale; + int m_nflDebugForceFleshOn; + int m_nvEffectCenterRadius1; + int m_nvEffectCenterRadius2; + int m_nvEffectCenterRadius3; + int m_nvEffectCenterRadius4; + + int m_ncSubsurfaceTint; + int m_nflBorderWidth; + int m_nflBorderSoftness; // > 0.0f && < 0.5f ! + int m_ncBorderTint; + int m_nflGlobalOpacity; + int m_nflGlossBrightness; + int m_nflScrollSpeed; + + int m_nTime; +}; + +// Default values (Arrays should only be vec[4]) +static const float kDefaultBorderNoiseScale = 1.5f; +static const float kDefaultDebugForceFleshOn = 0.0f; +static const float kDefaultEffectCenterRadius[4] = { 0.0f, 0.0f, 0.0f, 0.0001f }; // Disabled by default +static const float kDefaultSubsurfaceTint[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; // Disabled by default +static const float kDefaultBorderWidth = 0.3f; +static const float kDefaultBorderSoftness = 0.42f; // > 0.0f && < 0.5f ! +static const float kDefaultBorderTint[4] = { 1.0f, 1.0f, 1.0f, 0.0f }; +static const float kDefaultGlobalOpacity = 1.0f; +static const float kDefaultGlossBrightness = 0.66f; +static const float kDefaultScrollSpeed = 1.0f; + +void InitParamsFleshInteriorBlendedPass( CBaseVSShader *pShader, IMaterialVar** params, const char *pMaterialName, FleshInteriorBlendedPassVars_t &info ); +void InitFleshInteriorBlendedPass( CBaseVSShader *pShader, IMaterialVar** params, FleshInteriorBlendedPassVars_t &info ); +void DrawFleshInteriorBlendedPass( CBaseVSShader *pShader, IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, + IShaderShadow* pShaderShadow, FleshInteriorBlendedPassVars_t &info, VertexCompressionType_t vertexCompression ); + +#endif // FLESH_INTERIOR_BLENDED_PASS_HELPER_H diff --git a/materialsystem/stdshaders/flesh_interior_blended_pass_ps2x.fxc b/materialsystem/stdshaders/flesh_interior_blended_pass_ps2x.fxc new file mode 100644 index 0000000..3e288e5 --- /dev/null +++ b/materialsystem/stdshaders/flesh_interior_blended_pass_ps2x.fxc @@ -0,0 +1,127 @@ +//========= Copyright © 1996-2006, Valve Corporation, All rights reserved. ============// +// Includes ======================================================================================= +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX] +#include "common_vertexlitgeneric_dx9.h" + +// Texture Samplers =============================================================================== +sampler g_tBaseSampler : register( s0 ); +sampler g_tNoiseSampler : register( s1 ); +sampler g_tBorder1DSampler : register( s2 ); +sampler g_tNormalSampler : register( s3 ); +sampler g_tSubsurfaceSampler: register( s4 ); +sampler g_tCubeSampler : register( s5 ); + +// Shaders Constants and Globals ================================================================== +const float3 g_cSubsurfaceTint : register( c0 ); +const float2 g_flBorderWidth : register( c1 ); //{ 1.0f / g_flBorderWidthFromVmt, ( 1.0f / g_flBorderWidthFromVmt ) - 1.0f }; +const float g_flBorderSoftness : register( c2 ); +const float3 g_cBorderTint : register( c3 ); +const float g_flGlobalOpacity : register( c4 ); +const float g_flGlossBrightness : register( c5 ); + +// Interpolated values ============================================================================ +struct PS_INPUT +{ + float2 vTexCoord0 : TEXCOORD0; + float2 flDistanceToEffectCenter_flFresnelEffect : TEXCOORD1; + float4 vNoiseTexCoord : TEXCOORD2; + float3 vTangentViewVector : TEXCOORD3; + float3 cVertexLight : TEXCOORD4; + float3x3 mTangentSpaceTranspose : TEXCOORD5; + // second row : TEXCOORD6; + // third row : TEXCOORD7; +}; + +// Main =========================================================================================== +float4 main( PS_INPUT i ) : COLOR +{ + // Color texture + float4 cBaseColor = tex2D( g_tBaseSampler, i.vTexCoord0.xy ); + float flFleshMaskFromTexture = cBaseColor.a; + + // Subsurface colors + float4 cSubsurfaceColor = tex2D( g_tSubsurfaceSampler, i.vTexCoord0.xy ); + cBaseColor.rgb += cBaseColor.rgb * cSubsurfaceColor.rgb * g_cSubsurfaceTint.rgb; + + // Scroll noise textures to ripple border of opening + float flNoise0 = tex2D( g_tNoiseSampler, i.vNoiseTexCoord.xy ).g; // Use green so we can DXT1 if we want + float flNoise1 = tex2D( g_tNoiseSampler, i.vNoiseTexCoord.wz ).g; // Use green so we can DXT1 if we want + float flNoise = ( flNoise0 + flNoise1 ) * 0.5f; + + // Generate 0-1 mask from distance computed in the VS + float flClampedInputMask = 0.0f; + flClampedInputMask = 1.0f - saturate( i.flDistanceToEffectCenter_flFresnelEffect.x ); + flClampedInputMask *= i.flDistanceToEffectCenter_flFresnelEffect.y; + flClampedInputMask *= flFleshMaskFromTexture; + + // Noise mask - Only apply noise around border of sphere + float flBorderMask = saturate( ( 1.0f - flClampedInputMask ) * g_flBorderWidth.x - g_flBorderWidth.y ); + float flNoiseMask = 1.0f - abs( ( flBorderMask * 2.0f ) - 1.0f ); + + // This is used to lerp in the 1D border texture over the flesh color + float flBorderMaskWithNoise = ( 1.0f - smoothstep( flNoiseMask - g_flBorderSoftness, flNoiseMask + g_flBorderSoftness, flNoise.r ) ) * flNoiseMask; + + // Border color + float vBorderUv = ( sign( flBorderMask - 0.5 ) * (1.0f - pow( flBorderMaskWithNoise, 4.0f )) * 0.5f ) + 0.5f; + float4 cBorderColor = 2.0f * tex2D( g_tBorder1DSampler, vBorderUv ); + cBorderColor.rgb *= g_cBorderTint; + cBorderColor.rgb *= flNoise; + + // Normal map + float4 vNormalMapValue = tex2D( g_tNormalSampler, i.vTexCoord0.xy ); + float3 vTangentNormal = ( vNormalMapValue.xyz * 2.0f ) - 1.0f; + vTangentNormal.xy += ( flNoise * 1.5f ) - 0.75f; // NOTE: This will denormalize the normal. + //float3 vWorldNormal = mul( i.mTangentSpaceTranspose, vTangentNormal.xyz ); + + // Specular gloss layer + float3 vTangentReflectionVector = reflect( i.vTangentViewVector.xyz, vTangentNormal.xyz ); + //vTangentReflectionVector.xy += ( flNoise * 1.5f ) - 0.75f; + float3 vWorldReflectionVector = mul( i.mTangentSpaceTranspose, vTangentReflectionVector.xyz ); + float3 cGlossLayer = ENV_MAP_SCALE * texCUBE( g_tCubeSampler, vWorldReflectionVector.xyz ).rgb; + cGlossLayer.rgb *= g_flGlossBrightness; + + // Gloss mask is just hard-coded fresnel for now + float flGlossMask = pow( saturate( dot( vTangentNormal.xyz, -i.vTangentViewVector.xyz ) ), 8.0f ); + + // Opacity + float flOpacity = 1.0f; + flOpacity = max( flBorderMaskWithNoise, step( flBorderMask, 0.5f ) ); + + // Apply global opacity + flOpacity *= g_flGlobalOpacity; + + //===============// + // Combine terms // + //===============// + float4 result; + result.rgb = cBaseColor.rgb * i.cVertexLight.rgb; + result.rgb += cGlossLayer.rgb * flGlossMask; + result.rgb *= pow( 1.0f - flBorderMaskWithNoise, 2.0f ); // Darken near border + result.rgb = lerp( result.rgb, cBorderColor.rgb, saturate( vBorderUv * 2.0f ) ); // bring in transition 1D texture + + //result.rgb = flClampedInputMask; + //result.rgb = flBorderMask; + //result.rgb = saturate( flClampedInputMask * 2.0f ); + //result.rgb = i.flDistanceToEffectCenter_flFresnelEffect.x;// * i.flDistanceToEffectCenter_flFresnelEffect.y; + //result.rgb = i.flDistanceToEffectCenter_flFresnelEffect.y * g_flBorderWidth.x - g_flBorderWidth.y; + //result.rgb = flNoiseMask; + //result.rgb = flBorderMaskWithNoise; + //result.rgb = flOpacity; + //result.rgb = flBorderUv; + //result.rgb = cBorderColor; + //result.rgb = -i.vTangentViewVector.z; + //result.rgb = vNormalMapValue.xyz; + //result.rgb = vTangentNormal.xyz; + //result.rgb = flGlossLayer; + //result.rgb = i.cVertexLight.rgb; + //result.rgb = texCUBE( g_tCubeSampler, vTangentNormal.xyz ).rgb; + //result.rgb = i.vTangentViewVector.x; + //result.rgb = cGlossLayer.rgb; + + // Set alpha for blending + result.a = flOpacity; + //result.a = 1.0f; + + return FinalOutput( result, 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_LINEAR ); +} diff --git a/materialsystem/stdshaders/flesh_interior_blended_pass_vs20.fxc b/materialsystem/stdshaders/flesh_interior_blended_pass_vs20.fxc new file mode 100644 index 0000000..2a361b0 --- /dev/null +++ b/materialsystem/stdshaders/flesh_interior_blended_pass_vs20.fxc @@ -0,0 +1,155 @@ +//========= Copyright © 1996-2006, Valve Corporation, All rights reserved. ============// + +// STATIC: "HALFLAMBERT" "0..1" +// STATIC: "USE_STATIC_CONTROL_FLOW" "0..1" [vs20] + +// DYNAMIC: "COMPRESSED_VERTS" "0..1" +// DYNAMIC: "SKINNING" "0..1" +// DYNAMIC: "DOWATERFOG" "0..1" +// DYNAMIC: "DYNAMIC_LIGHT" "0..1" +// DYNAMIC: "STATIC_LIGHT" "0..1" +// DYNAMIC: "NUM_LIGHTS" "0..2" [vs20] + +// If using static control flow on Direct3D, we should use the NUM_LIGHTS=0 combo +// SKIP: $USE_STATIC_CONTROL_FLOW && ( $NUM_LIGHTS > 0 ) [vs20] + +// Includes +#include "common_vs_fxc.h" + +// Globals +static const int g_iFogType = DOWATERFOG; +static const bool g_bHalfLambert = HALFLAMBERT ? true : false; +static const bool g_bSkinning = SKINNING ? true : false; + +const float4 g_vConst0 : register( SHADER_SPECIFIC_CONST_0 ); +#define g_flTime g_vConst0.x +#define g_flNoiseUvScroll g_vConst0.y +#define g_flBorderNoiseScale g_vConst0.z +#define g_flDebugForceFleshOn g_vConst0.w + +const float4 g_vEffectCenterOoRadius1 : register( SHADER_SPECIFIC_CONST_1 ); //= { -295.0f, -5.0f, 40.0f, 1.0f/20.0f }; +const float4 g_vEffectCenterOoRadius2 : register( SHADER_SPECIFIC_CONST_2 ); //= { -295.0f, 15.0f, 40.0f, 1.0f/10.0f }; +const float4 g_vEffectCenterOoRadius3 : register( SHADER_SPECIFIC_CONST_3 ); //= { -295.0f, 35.0f, 40.0f, 1.0f/10.0f }; +const float4 g_vEffectCenterOoRadius4 : register( SHADER_SPECIFIC_CONST_4 ); //= { -295.0f, 55.0f, 40.0f, 1.0f/10.0f }; + +// Structs +struct VS_INPUT +{ + float4 vPos : POSITION; // Position + float4 vNormal : NORMAL; // Normal + float4 vBoneWeights : BLENDWEIGHT; // Skin weights + float4 vBoneIndices : BLENDINDICES; // Skin indices + float4 vTexCoord0 : TEXCOORD0; // Base texture coordinates + float3 vPosFlex : POSITION1; // Delta positions for flexing + float4 vTangent : TANGENT; +}; + +struct VS_OUTPUT +{ + float4 vProjPosition : POSITION; // Projection-space position + float2 vTexCoord0 : TEXCOORD0; + float2 flDistanceToEffectCenter_flFresnelEffect : TEXCOORD1; + float4 vNoiseTexCoord : TEXCOORD2; + float3 vTangentViewVector : TEXCOORD3; + float3 cVertexLight : TEXCOORD4; + float3x3 mTangentSpaceTranspose : TEXCOORD5; + // second row : TEXCOORD6; + // third row : TEXCOORD7; + +}; + +// Main +VS_OUTPUT main( const VS_INPUT i ) +{ + VS_OUTPUT o; + + // Flexes coming in from a separate stream (contribution masked by cFlexScale.x) + float4 vObjPosition = i.vPos; + vObjPosition.xyz += i.vPosFlex.xyz * cFlexScale.x; + + float3 vObjNormal; + float4 vObjTangent; + DecompressVertex_NormalTangent( i.vNormal, i.vTangent, vObjNormal, vObjTangent ); + + // Transform the position + float3 vWorldPosition = { 0.0f, 0.0f, 0.0f }; + float3 vWorldNormal = { 0.0f, 0.0f, 0.0f }; + float3 vWorldTangent = { 0.0f, 0.0f, 0.0f }; + float3 vWorldBinormal = { 0.0f, 0.0f, 0.0f }; + SkinPositionNormalAndTangentSpace( g_bSkinning, vObjPosition, vObjNormal, vObjTangent, i.vBoneWeights, i.vBoneIndices, vWorldPosition, vWorldNormal, vWorldTangent, vWorldBinormal ); + + // Transform into projection space + float4 vProjPosition = mul( float4( vWorldPosition, 1.0f ), cViewProj ); + o.vProjPosition = vProjPosition; + + // Pass through tex coords + o.vTexCoord0.xy = i.vTexCoord0.xy; + + // Store the closest effect intensity + o.flDistanceToEffectCenter_flFresnelEffect.x = 9999.0f; // A very large distance + o.flDistanceToEffectCenter_flFresnelEffect.x = min( o.flDistanceToEffectCenter_flFresnelEffect.x, length( vWorldPosition.xyz - g_vEffectCenterOoRadius1.xyz ) * g_vEffectCenterOoRadius1.w ); + o.flDistanceToEffectCenter_flFresnelEffect.x = min( o.flDistanceToEffectCenter_flFresnelEffect.x, length( vWorldPosition.xyz - g_vEffectCenterOoRadius2.xyz ) * g_vEffectCenterOoRadius2.w ); + o.flDistanceToEffectCenter_flFresnelEffect.x = min( o.flDistanceToEffectCenter_flFresnelEffect.x, length( vWorldPosition.xyz - g_vEffectCenterOoRadius3.xyz ) * g_vEffectCenterOoRadius3.w ); + o.flDistanceToEffectCenter_flFresnelEffect.x = min( o.flDistanceToEffectCenter_flFresnelEffect.x, length( vWorldPosition.xyz - g_vEffectCenterOoRadius4.xyz ) * g_vEffectCenterOoRadius4.w ); + + /* + // Test values for development in Alyx_interior map + o.flDistanceToEffectCenter_flFresnelEffect.x = 9999.0f; // A very large distance + float3 vTestPosition = { -295.0f, -5.0f, 40.0f }; + float flMinY = -5.0f; + float flMaxY = 66.0f; + vTestPosition.y = lerp( flMinY, flMaxY, ( abs( frac( g_flTime / 20.0f ) * 2.0 - 1.0 ) ) ); + //vTestPosition.y = lerp( flMinY, flMaxY, 0.65f ); + + //1.0f - saturate( i.flDistanceToEffectCenter_flFresnelEffect.x * 4.0f - 3.0f ) + + //o.flDistanceToEffectCenter_flFresnelEffect.x = 9999.0f; // A very large distance + + const float g_flInteriorRadius = 20.0f; + if ( g_flInteriorRadius ) + { + o.flDistanceToEffectCenter_flFresnelEffect.x = min( o.flDistanceToEffectCenter_flFresnelEffect.x, length( vWorldPosition.xyz - vTestPosition.xyz ) / g_flInteriorRadius ); + } + + const float g_flInteriorRadius2 = 14.0f; + if ( g_flInteriorRadius2 ) + { + vTestPosition.y = lerp( flMinY, flMaxY, 0.65f ); + //vTestPosition.z = lerp( 37, 45, ( abs( frac( g_flTime / 4.0f ) * 2.0 - 1.0 ) ) ); + o.flDistanceToEffectCenter_flFresnelEffect.x = min( o.flDistanceToEffectCenter_flFresnelEffect.x, length( vWorldPosition.xyz - vTestPosition.xyz ) / g_flInteriorRadius2 ); + } + //*/ + + if ( g_flDebugForceFleshOn ) + { + o.flDistanceToEffectCenter_flFresnelEffect.x = 0.0f; + } + + // Fresnel mask + float3 vWorldViewVector = normalize( vWorldPosition.xyz - cEyePos.xyz ); + o.flDistanceToEffectCenter_flFresnelEffect.y = pow( saturate( dot( -vWorldViewVector.xyz, vWorldNormal.xyz ) ), 1.5f ); + + // Noise UV + o.vNoiseTexCoord.xy = o.vTexCoord0.xy * g_flBorderNoiseScale + g_flNoiseUvScroll; + o.vNoiseTexCoord.zw = o.vTexCoord0.xy * g_flBorderNoiseScale - g_flNoiseUvScroll; // Will fetch as wz to avoid matching layers + + // Tangent view vector + o.vTangentViewVector.xyz = Vec3WorldToTangentNormalized( vWorldViewVector.xyz, vWorldNormal.xyz, vWorldTangent.xyz, vWorldBinormal.xyz ); + + // Compute vertex lighting + bool bDynamicLight = DYNAMIC_LIGHT ? true : false; + bool bStaticLight = STATIC_LIGHT ? true : false; + +#if ( USE_STATIC_CONTROL_FLOW ) || defined ( SHADER_MODEL_VS_3_0 ) + o.cVertexLight.rgb = DoLighting( vWorldPosition, vWorldNormal, float3(0.0f, 0.0f, 0.0f), bStaticLight, bDynamicLight, g_bHalfLambert ); +#else + o.cVertexLight.rgb = DoLightingUnrolled( vWorldPosition, vWorldNormal, float3(0.0f, 0.0f, 0.0f), bStaticLight, bDynamicLight, g_bHalfLambert, NUM_LIGHTS ); +#endif + + // Tangent space transform + o.mTangentSpaceTranspose[0] = float3( vWorldTangent.x, vWorldBinormal.x, vWorldNormal.x ); + o.mTangentSpaceTranspose[1] = float3( vWorldTangent.y, vWorldBinormal.y, vWorldNormal.y ); + o.mTangentSpaceTranspose[2] = float3( vWorldTangent.z, vWorldBinormal.z, vWorldNormal.z ); + + return o; +} diff --git a/materialsystem/stdshaders/floatcombine.cpp b/materialsystem/stdshaders/floatcombine.cpp new file mode 100644 index 0000000..18757b9 --- /dev/null +++ b/materialsystem/stdshaders/floatcombine.cpp @@ -0,0 +1,118 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//=============================================================================// + +#include "BaseVSShader.h" + +#include "screenspaceeffect_vs20.inc" +#include "floatcombine_ps20.inc" +#include "floatcombine_ps20b.inc" + +BEGIN_VS_SHADER_FLAGS( floatcombine, "Help for floatcombine", SHADER_NOT_EDITABLE ) + BEGIN_SHADER_PARAMS + SHADER_PARAM( BLOOMTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "" ) + SHADER_PARAM( SHARPNESS, SHADER_PARAM_TYPE_FLOAT, "1", "" ) + SHADER_PARAM( WOODCUT, SHADER_PARAM_TYPE_FLOAT, "0", "" ) + SHADER_PARAM( VIGNETTE_MIN_BRIGHT,SHADER_PARAM_TYPE_FLOAT,"1","") + SHADER_PARAM( VIGNETTE_POWER,SHADER_PARAM_TYPE_FLOAT,"4","") + SHADER_PARAM( EDGE_SOFTNESS,SHADER_PARAM_TYPE_FLOAT,"0","") + SHADER_PARAM( BLOOMAMOUNT, SHADER_PARAM_TYPE_FLOAT, "1.0", "" ) + SHADER_PARAM( BLOOMEXPONENT, SHADER_PARAM_TYPE_FLOAT, "2.0", "" ) + SHADER_PARAM( ALPHASHARPENFACTOR, SHADER_PARAM_TYPE_FLOAT, "0.0", "" ) + END_SHADER_PARAMS + + SHADER_INIT + { + if( params[BASETEXTURE]->IsDefined() ) + { + LoadTexture( BASETEXTURE ); + } + if( params[BLOOMTEXTURE]->IsDefined() ) + { + LoadTexture( BLOOMTEXTURE ); + } + } + + SHADER_FALLBACK + { + // Requires DX9 + above + if ( g_pHardwareConfig->GetDXSupportLevel() < 90 ) + { +// Assert( 0 ); + return "Wireframe"; + } + return 0; + } + + SHADER_DRAW + { + SHADOW_STATE + { + pShaderShadow->EnableDepthWrites( false ); + + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + int fmt = VERTEX_POSITION; + pShaderShadow->VertexShaderVertexFormat( fmt, 1, 0, 0 ); + + // convert from linear to gamma on write. + pShaderShadow->EnableSRGBWrite( true ); + + // Pre-cache shaders + DECLARE_STATIC_VERTEX_SHADER( screenspaceeffect_vs20 ); + SET_STATIC_VERTEX_SHADER( screenspaceeffect_vs20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_STATIC_PIXEL_SHADER( floatcombine_ps20b ); + SET_STATIC_PIXEL_SHADER( floatcombine_ps20b ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( floatcombine_ps20 ); + SET_STATIC_PIXEL_SHADER( floatcombine_ps20 ); + } + } + + DYNAMIC_STATE + { + float c0[4]={params[SHARPNESS]->GetFloatValue(), + params[WOODCUT]->GetFloatValue(), + params[BLOOMAMOUNT]->GetFloatValue(), + params[ALPHASHARPENFACTOR]->GetFloatValue()}; + float c1[4]={params[BLOOMEXPONENT]->GetFloatValue(), + params[VIGNETTE_MIN_BRIGHT]->GetFloatValue(), + params[VIGNETTE_POWER]->GetFloatValue(), + params[EDGE_SOFTNESS]->GetFloatValue()}; + pShaderAPI->SetPixelShaderConstant( 0, c0, 1 ); + pShaderAPI->SetPixelShaderConstant( 1, c1, 1 ); + BindTexture( SHADER_SAMPLER0, BASETEXTURE, -1 ); + BindTexture( SHADER_SAMPLER1, BLOOMTEXTURE, -1 ); + + ITexture *base_texture=params[BASETEXTURE]->GetTextureValue(); + ITexture *bloom_texture=params[BLOOMTEXTURE]->GetTextureValue(); + + float v0[4]={ (float)(1.0/base_texture->GetActualWidth()), (float)(1.0/base_texture->GetActualHeight()), + (float)(1.0/bloom_texture->GetActualWidth()), (float)(1.0/bloom_texture->GetActualHeight()) }; + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, v0, 1 ); + + DECLARE_DYNAMIC_VERTEX_SHADER( screenspaceeffect_vs20 ); + SET_DYNAMIC_VERTEX_SHADER( screenspaceeffect_vs20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_DYNAMIC_PIXEL_SHADER( floatcombine_ps20b ); + SET_DYNAMIC_PIXEL_SHADER( floatcombine_ps20b ); + } + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( floatcombine_ps20 ); + SET_DYNAMIC_PIXEL_SHADER( floatcombine_ps20 ); + } + } + Draw(); + } +END_SHADER diff --git a/materialsystem/stdshaders/floatcombine_autoexpose.cpp b/materialsystem/stdshaders/floatcombine_autoexpose.cpp new file mode 100644 index 0000000..c28425f --- /dev/null +++ b/materialsystem/stdshaders/floatcombine_autoexpose.cpp @@ -0,0 +1,123 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//=============================================================================// + +#include "BaseVSShader.h" + +#include "screenspaceeffect_vs20.inc" +#include "floatcombine_autoexpose_ps20.inc" +#include "floatcombine_autoexpose_ps20b.inc" + +BEGIN_VS_SHADER( floatcombine_autoexpose, "Help for floatcombine_autoexpose" ) + BEGIN_SHADER_PARAMS + SHADER_PARAM( BLOOMTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "" ) + SHADER_PARAM( SHARPNESS, SHADER_PARAM_TYPE_FLOAT, "1", "" ) + SHADER_PARAM( WOODCUT, SHADER_PARAM_TYPE_FLOAT, "0", "" ) + SHADER_PARAM( VIGNETTE_MIN_BRIGHT,SHADER_PARAM_TYPE_FLOAT,"1","") + SHADER_PARAM( VIGNETTE_POWER,SHADER_PARAM_TYPE_FLOAT,"4","") + SHADER_PARAM( EDGE_SOFTNESS,SHADER_PARAM_TYPE_FLOAT,"0","") + SHADER_PARAM( BLOOMAMOUNT, SHADER_PARAM_TYPE_FLOAT, "1.0", "" ) + SHADER_PARAM( BLOOMEXPONENT, SHADER_PARAM_TYPE_FLOAT, "2.0", "" ) + SHADER_PARAM( ALPHASHARPENFACTOR, SHADER_PARAM_TYPE_FLOAT, "0.0", "" ) + SHADER_PARAM( EXPOSURE_TEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "" ) + SHADER_PARAM( AUTOEXPOSE_MIN, SHADER_PARAM_TYPE_FLOAT, ".5", "" ) + SHADER_PARAM( AUTOEXPOSE_MAX, SHADER_PARAM_TYPE_FLOAT, "2", "" ) + END_SHADER_PARAMS + + SHADER_INIT + { + if( params[BASETEXTURE]->IsDefined() ) + { + LoadTexture( BASETEXTURE ); + } + if( params[BLOOMTEXTURE]->IsDefined() ) + { + LoadTexture( BLOOMTEXTURE ); + } + if( params[EXPOSURE_TEXTURE]->IsDefined() ) + { + LoadTexture( EXPOSURE_TEXTURE ); + } + } + + SHADER_FALLBACK + { + // Requires DX9 + above + if ( g_pHardwareConfig->GetDXSupportLevel() < 90 ) + { + Assert( 0 ); + return "Wireframe"; + } + return 0; + } + + SHADER_DRAW + { + SHADOW_STATE + { + pShaderShadow->EnableDepthWrites( false ); + + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER2, true ); + int fmt = VERTEX_POSITION; + pShaderShadow->VertexShaderVertexFormat( fmt, 1, 0, 0 ); + + // convert from linear to gamma on write. + pShaderShadow->EnableSRGBWrite( true ); + + // Pre-cache shaders + DECLARE_STATIC_VERTEX_SHADER( screenspaceeffect_vs20 ); + SET_STATIC_VERTEX_SHADER( screenspaceeffect_vs20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_STATIC_PIXEL_SHADER( floatcombine_autoexpose_ps20b ); + SET_STATIC_PIXEL_SHADER( floatcombine_autoexpose_ps20b ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( floatcombine_autoexpose_ps20 ); + SET_STATIC_PIXEL_SHADER( floatcombine_autoexpose_ps20 ); + } + } + + DYNAMIC_STATE + { + float c0[4]={params[SHARPNESS]->GetFloatValue(), + params[WOODCUT]->GetFloatValue(), + params[BLOOMAMOUNT]->GetFloatValue(), + params[ALPHASHARPENFACTOR]->GetFloatValue()}; + float c1[4]={params[BLOOMEXPONENT]->GetFloatValue(), + params[VIGNETTE_MIN_BRIGHT]->GetFloatValue(), + params[VIGNETTE_POWER]->GetFloatValue(), + params[EDGE_SOFTNESS]->GetFloatValue()}; + float c2[4]={params[AUTOEXPOSE_MIN]->GetFloatValue(), + params[AUTOEXPOSE_MAX]->GetFloatValue(), + 0,0}; + pShaderAPI->SetPixelShaderConstant( 0, c0, 1 ); + pShaderAPI->SetPixelShaderConstant( 1, c1, 1 ); + pShaderAPI->SetPixelShaderConstant( 2, c2, 1 ); + BindTexture( SHADER_SAMPLER0, BASETEXTURE, -1 ); + BindTexture( SHADER_SAMPLER1, BLOOMTEXTURE, -1 ); + BindTexture( SHADER_SAMPLER2, EXPOSURE_TEXTURE, -1 ); + DECLARE_DYNAMIC_VERTEX_SHADER( screenspaceeffect_vs20 ); + SET_DYNAMIC_VERTEX_SHADER( screenspaceeffect_vs20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_DYNAMIC_PIXEL_SHADER( floatcombine_autoexpose_ps20b ); + SET_DYNAMIC_PIXEL_SHADER( floatcombine_autoexpose_ps20b ); + } + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( floatcombine_autoexpose_ps20 ); + SET_DYNAMIC_PIXEL_SHADER( floatcombine_autoexpose_ps20 ); + } + } + Draw(); + } +END_SHADER diff --git a/materialsystem/stdshaders/floatcombine_autoexpose_ps2x.fxc b/materialsystem/stdshaders/floatcombine_autoexpose_ps2x.fxc new file mode 100644 index 0000000..21b485d --- /dev/null +++ b/materialsystem/stdshaders/floatcombine_autoexpose_ps2x.fxc @@ -0,0 +1,48 @@ +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX] + +#define HDRTYPE HDR_TYPE_FLOAT +#define HDRENABLED 1 +#include "common_ps_fxc.h" + +sampler FBSampler : register( s0 ); +sampler BloomSampler : register( s1 ); +sampler Exposure_Sampler : register( s2 ); + +const HALF4 settings : register( c0 ); + // x=sharpness,y=woodcut,z=bloom_amt,w=alpha sharpen factor +const HALF4 settings2 : register( c1 ); // x=bloom exp,y=vignette min scale z=vignette_power +const HALF4 settings3 : register( c2 ); // x=autoexpose min y=autoexpose_max + +struct PS_INPUT +{ + float2 texCoord : TEXCOORD0; + float2 ZeroTexCoord : TEXCOORD1; +}; + + +float4 main( PS_INPUT i ) : COLOR +{ + float4 fbSample = tex2D( FBSampler, i.texCoord ); + float4 bloom=tex2D(BloomSampler,i.texCoord); + float4 exposure_data=tex2D(Exposure_Sampler,i.ZeroTexCoord); + float avg_lum=exposure_data.r; + float tmscale=max(0.18/max(avg_lum,0.0001),settings3.x); + tmscale=min(tmscale,settings3.y); + + + float2 xofs=2*(i.texCoord-float2(0.5,0.5)); + float dist=(1.0/2.0)*(xofs.x*xofs.x+xofs.y*xofs.y); + float vig=pow(1-dist,settings2.z); + + fbSample=lerp(fbSample,bloom,(1-vig)*settings2.w); + fbSample=lerp(bloom,fbSample,settings.x+settings.w*fbSample.a*settings2.w); + + bloom.xyz=min(bloom.xyz,1.0); + float lum=.3*bloom.x+.59*bloom.y+.11*bloom.z; + lum=min(1.0,lum); + + float4 c_out=(fbSample)+settings.z*pow(lum,settings2.x)*bloom; + c_out.xyz*=tmscale; + return FinalOutput( c_out, 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE ); +} diff --git a/materialsystem/stdshaders/floatcombine_ps2x.fxc b/materialsystem/stdshaders/floatcombine_ps2x.fxc new file mode 100644 index 0000000..b2c0e46 --- /dev/null +++ b/materialsystem/stdshaders/floatcombine_ps2x.fxc @@ -0,0 +1,60 @@ +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX] + +#define HDRTYPE HDR_TYPE_FLOAT +#define HDRENABLED 1 +#include "common_ps_fxc.h" + +sampler FBSampler : register( s0 ); +sampler BloomSampler : register( s1 ); + +const HALF4 settings : register( c0 ); + // x=sharpness,y=woodcut,z=bloom_amt,w=alpha sharpen factor +const HALF4 settings2 : register( c1 ); // x=bloom exp,y=vignette min scale z=vignette_power + +struct PS_INPUT +{ + float2 texCoord : TEXCOORD0; + float2 ZeroTexCoord : TEXCOORD1; + float2 bloomTexCoord : TEXCOORD2; +}; + + +float4 main( PS_INPUT i ) : COLOR +{ + float4 fbSample = tex2D( FBSampler, i.texCoord ); + float4 bloom=tex2D(BloomSampler,i.bloomTexCoord); + + float2 xofs=2*(i.texCoord-float2(0.5,0.5)); + float dist=(1.0/2.0)*(xofs.x*xofs.x+xofs.y*xofs.y); + float vig=pow(1-dist,settings2.z); + + fbSample=lerp(fbSample,bloom,(1-vig)*settings2.w); + fbSample=lerp(bloom,fbSample,settings.x+settings.w*fbSample.a*settings2.w); + + float3 woodcut; + if (bloom.xIsDefined() ) + { + LoadTexture( FBTEXTURE ); + } + } + + SHADER_FALLBACK + { + // Requires DX9 + above + if ( g_pHardwareConfig->GetDXSupportLevel() < 90 ) + return "Wireframe"; + return 0; + } + + SHADER_DRAW + { + SHADOW_STATE + { + pShaderShadow->EnableDepthWrites( false ); + + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + int fmt = VERTEX_POSITION; + pShaderShadow->VertexShaderVertexFormat( fmt, 1, 0, 0 ); + + // convert from linear to gamma on write. + pShaderShadow->EnableSRGBWrite( true ); + + // Pre-cache shaders + DECLARE_STATIC_VERTEX_SHADER( screenspaceeffect_vs20 ); + SET_STATIC_VERTEX_SHADER( screenspaceeffect_vs20 ); + +// DECLARE_STATIC_PIXEL_SHADER( floattoscreen_ps20 ); +// SET_STATIC_PIXEL_SHADER( floattoscreen_ps20 ); + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + const char *szPixelShader = params[PIXSHADER]->GetStringValue(); + size_t iLength = Q_strlen( szPixelShader ); + + if( (iLength > 5) && (Q_stricmp( &szPixelShader[iLength - 5], "_ps20" ) == 0) ) //detect if it's trying to load a ps20 shader + { + //replace it with the ps20b shader + char *szNewName = (char *)stackalloc( sizeof( char ) * (iLength + 2) ); + memcpy( szNewName, szPixelShader, sizeof( char ) * iLength ); + szNewName[iLength] = 'b'; + szNewName[iLength + 1] = '\0'; + pShaderShadow->SetPixelShader( szNewName, 0 ); + } + else + { + pShaderShadow->SetPixelShader( params[PIXSHADER]->GetStringValue(), 0 ); + } + } + else + { + pShaderShadow->SetPixelShader( params[PIXSHADER]->GetStringValue(), 0 ); + } + } + + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER0, FBTEXTURE, -1 ); + DECLARE_DYNAMIC_VERTEX_SHADER( screenspaceeffect_vs20 ); + SET_DYNAMIC_VERTEX_SHADER( screenspaceeffect_vs20 ); + +// DECLARE_DYNAMIC_PIXEL_SHADER( floattoscreen_ps20 ); +// SET_DYNAMIC_PIXEL_SHADER( floattoscreen_ps20 ); + pShaderAPI->SetPixelShaderIndex( 0 ); + } + Draw(); + } +END_SHADER diff --git a/materialsystem/stdshaders/floattoscreen_notonemap_ps2x.fxc b/materialsystem/stdshaders/floattoscreen_notonemap_ps2x.fxc new file mode 100644 index 0000000..0542283 --- /dev/null +++ b/materialsystem/stdshaders/floattoscreen_notonemap_ps2x.fxc @@ -0,0 +1,38 @@ +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX] + +#define HDRTYPE HDR_TYPE_FLOAT +#define HDRENABLED 1 +#include "common_ps_fxc.h" + +sampler FBSampler : register( s0 ); + +struct PS_INPUT +{ + float2 texCoord : TEXCOORD0; +}; + +#define MAX_LUM 5 +#define MIN_LUM .1 + +float4 main( PS_INPUT i ) : COLOR +{ + float4 fbSample = tex2D( FBSampler, i.texCoord ); + + float lum=0.33*(fbSample.x+fbSample.y+fbSample.z); + // derive a luminance-based scale factor for tone mapping + float factor=1.0; + if (lumMAX_LUM) + { + } + + + // linear scale for tone mapping +// fbSample *= lum * LINEAR_LIGHT_SCALE; + + // assume that sRGB write is enabled. + return FinalOutput( fbSample, 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE ); +} diff --git a/materialsystem/stdshaders/floattoscreen_ps2x.fxc b/materialsystem/stdshaders/floattoscreen_ps2x.fxc new file mode 100644 index 0000000..0a42069 --- /dev/null +++ b/materialsystem/stdshaders/floattoscreen_ps2x.fxc @@ -0,0 +1,21 @@ +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX] + +#define HDRTYPE HDR_TYPE_FLOAT +#define HDRENABLED 1 +#include "common_ps_fxc.h" + +sampler FBSampler : register( s0 ); + +struct PS_INPUT +{ + float2 texCoord : TEXCOORD0; +}; + + +float4 main( PS_INPUT i ) : COLOR +{ + float4 fbSample = tex2D( FBSampler, i.texCoord ) * float4(cLightScale.xyz, 1); + + return FinalOutput( fbSample, 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE ); +} diff --git a/materialsystem/stdshaders/floattoscreen_vanilla.cpp b/materialsystem/stdshaders/floattoscreen_vanilla.cpp new file mode 100644 index 0000000..25f4d89 --- /dev/null +++ b/materialsystem/stdshaders/floattoscreen_vanilla.cpp @@ -0,0 +1,88 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//=============================================================================// + +#include "BaseVSShader.h" + +#include "screenspaceeffect_vs20.inc" +#include "floattoscreen_vanilla_ps20.inc" +#include "floattoscreen_vanilla_ps20b.inc" +#include "floattoscreen_ps20.inc" +#include "floattoscreen_ps20b.inc" + +BEGIN_VS_SHADER_FLAGS( floattoscreen_vanilla, "Help for floattoscreen_vanilla", SHADER_NOT_EDITABLE ) + BEGIN_SHADER_PARAMS + SHADER_PARAM( FBTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "" ) + END_SHADER_PARAMS + + SHADER_INIT + { + if( params[FBTEXTURE]->IsDefined() ) + { + LoadTexture( FBTEXTURE ); + } + } + + SHADER_FALLBACK + { + // Requires DX9 + above + if ( g_pHardwareConfig->GetDXSupportLevel() < 90 ) + { + Assert( 0 ); + return "Wireframe"; + } + return 0; + } + + SHADER_DRAW + { + SHADOW_STATE + { + pShaderShadow->EnableDepthWrites( false ); + + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + int fmt = VERTEX_POSITION; + pShaderShadow->VertexShaderVertexFormat( fmt, 1, 0, 0 ); + + // convert from linear to gamma on write. + pShaderShadow->EnableSRGBWrite( true ); + + // Pre-cache shaders + DECLARE_STATIC_VERTEX_SHADER( screenspaceeffect_vs20 ); + SET_STATIC_VERTEX_SHADER( screenspaceeffect_vs20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_STATIC_PIXEL_SHADER( floattoscreen_ps20b ); + SET_STATIC_PIXEL_SHADER( floattoscreen_ps20b ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( floattoscreen_ps20 ); + SET_STATIC_PIXEL_SHADER( floattoscreen_ps20 ); + } + } + + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER0, FBTEXTURE, -1 ); + DECLARE_DYNAMIC_VERTEX_SHADER( screenspaceeffect_vs20 ); + SET_DYNAMIC_VERTEX_SHADER( screenspaceeffect_vs20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_DYNAMIC_PIXEL_SHADER( floattoscreen_vanilla_ps20b ); + SET_DYNAMIC_PIXEL_SHADER( floattoscreen_vanilla_ps20b ); + } + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( floattoscreen_vanilla_ps20 ); + SET_DYNAMIC_PIXEL_SHADER( floattoscreen_vanilla_ps20 ); + } + } + Draw(); + } +END_SHADER diff --git a/materialsystem/stdshaders/floattoscreen_vanilla_ps2x.fxc b/materialsystem/stdshaders/floattoscreen_vanilla_ps2x.fxc new file mode 100644 index 0000000..9f90948 --- /dev/null +++ b/materialsystem/stdshaders/floattoscreen_vanilla_ps2x.fxc @@ -0,0 +1,19 @@ +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX] + +#define HDRTYPE HDR_TYPE_FLOAT +#define HDRENABLED 1 +#include "common_ps_fxc.h" + +sampler FBSampler : register( s0 ); + +struct PS_INPUT +{ + float2 texCoord : TEXCOORD0; +}; + +float4 main( PS_INPUT i ) : COLOR +{ + float4 fbSample = tex2D( FBSampler, i.texCoord ); + return fbSample; +} diff --git a/materialsystem/stdshaders/fxctmp9/Bloom_ps20.inc b/materialsystem/stdshaders/fxctmp9/Bloom_ps20.inc new file mode 100644 index 0000000..f695603 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/Bloom_ps20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class bloom_ps20_Static_Index +{ +public: + bloom_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_bloom_ps20 0 +class bloom_ps20_Dynamic_Index +{ +public: + bloom_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_bloom_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9/Bloom_ps20b.inc b/materialsystem/stdshaders/fxctmp9/Bloom_ps20b.inc new file mode 100644 index 0000000..093fe21 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/Bloom_ps20b.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class bloom_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + bloom_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_bloom_ps20b 0 +class bloom_ps20b_Dynamic_Index +{ +public: + bloom_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_bloom_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9/BlurFilter_ps20.inc b/materialsystem/stdshaders/fxctmp9/BlurFilter_ps20.inc new file mode 100644 index 0000000..287e046 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/BlurFilter_ps20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class blurfilter_ps20_Static_Index +{ +public: + blurfilter_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_blurfilter_ps20 0 +class blurfilter_ps20_Dynamic_Index +{ +public: + blurfilter_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_blurfilter_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9/BlurFilter_ps20b.inc b/materialsystem/stdshaders/fxctmp9/BlurFilter_ps20b.inc new file mode 100644 index 0000000..7ec87ea --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/BlurFilter_ps20b.inc @@ -0,0 +1,85 @@ +#include "shaderlib/cshader.h" +class blurfilter_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +private: + int m_nAPPROX_SRGB_ADAPTER; +#ifdef _DEBUG + bool m_bAPPROX_SRGB_ADAPTER; +#endif +public: + void SetAPPROX_SRGB_ADAPTER( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nAPPROX_SRGB_ADAPTER = i; +#ifdef _DEBUG + m_bAPPROX_SRGB_ADAPTER = true; +#endif + } + void SetAPPROX_SRGB_ADAPTER( bool i ) + { + m_nAPPROX_SRGB_ADAPTER = i ? 1 : 0; +#ifdef _DEBUG + m_bAPPROX_SRGB_ADAPTER = true; +#endif + } +public: + blurfilter_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); +#ifdef _DEBUG + m_bAPPROX_SRGB_ADAPTER = false; +#endif // _DEBUG + m_nAPPROX_SRGB_ADAPTER = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB && m_bAPPROX_SRGB_ADAPTER; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + ( 2 * m_nAPPROX_SRGB_ADAPTER ) + 0; + } +}; +#define shaderStaticTest_blurfilter_ps20b psh_forgot_to_set_static_APPROX_SRGB_ADAPTER + 0 +class blurfilter_ps20b_Dynamic_Index +{ +public: + blurfilter_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_blurfilter_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9/BlurFilter_vs11.inc b/materialsystem/stdshaders/fxctmp9/BlurFilter_vs11.inc new file mode 100644 index 0000000..6036961 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/BlurFilter_vs11.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class blurfilter_vs11_Static_Index +{ +public: + blurfilter_vs11_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_blurfilter_vs11 0 +class blurfilter_vs11_Dynamic_Index +{ +public: + blurfilter_vs11_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_blurfilter_vs11 0 diff --git a/materialsystem/stdshaders/fxctmp9/BlurFilter_vs20.inc b/materialsystem/stdshaders/fxctmp9/BlurFilter_vs20.inc new file mode 100644 index 0000000..933c5b7 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/BlurFilter_vs20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class blurfilter_vs20_Static_Index +{ +public: + blurfilter_vs20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_blurfilter_vs20 0 +class blurfilter_vs20_Dynamic_Index +{ +public: + blurfilter_vs20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_blurfilter_vs20 0 diff --git a/materialsystem/stdshaders/fxctmp9/Downsample_nohdr_ps20.inc b/materialsystem/stdshaders/fxctmp9/Downsample_nohdr_ps20.inc new file mode 100644 index 0000000..dffe22a --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/Downsample_nohdr_ps20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class downsample_nohdr_ps20_Static_Index +{ +private: + int m_nCSTRIKE; +#ifdef _DEBUG + bool m_bCSTRIKE; +#endif +public: + void SetCSTRIKE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCSTRIKE = i; +#ifdef _DEBUG + m_bCSTRIKE = true; +#endif + } + void SetCSTRIKE( bool i ) + { + m_nCSTRIKE = i ? 1 : 0; +#ifdef _DEBUG + m_bCSTRIKE = true; +#endif + } +public: + downsample_nohdr_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCSTRIKE = false; +#endif // _DEBUG + m_nCSTRIKE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCSTRIKE; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCSTRIKE ) + 0; + } +}; +#define shaderStaticTest_downsample_nohdr_ps20 psh_forgot_to_set_static_CSTRIKE + 0 +class downsample_nohdr_ps20_Dynamic_Index +{ +public: + downsample_nohdr_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_downsample_nohdr_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9/Downsample_nohdr_ps20b.inc b/materialsystem/stdshaders/fxctmp9/Downsample_nohdr_ps20b.inc new file mode 100644 index 0000000..0543038 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/Downsample_nohdr_ps20b.inc @@ -0,0 +1,110 @@ +#include "shaderlib/cshader.h" +class downsample_nohdr_ps20b_Static_Index +{ +private: + int m_nSRGB_ADAPTER; +#ifdef _DEBUG + bool m_bSRGB_ADAPTER; +#endif +public: + void SetSRGB_ADAPTER( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSRGB_ADAPTER = i; +#ifdef _DEBUG + m_bSRGB_ADAPTER = true; +#endif + } + void SetSRGB_ADAPTER( bool i ) + { + m_nSRGB_ADAPTER = i ? 1 : 0; +#ifdef _DEBUG + m_bSRGB_ADAPTER = true; +#endif + } +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +private: + int m_nCSTRIKE; +#ifdef _DEBUG + bool m_bCSTRIKE; +#endif +public: + void SetCSTRIKE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCSTRIKE = i; +#ifdef _DEBUG + m_bCSTRIKE = true; +#endif + } + void SetCSTRIKE( bool i ) + { + m_nCSTRIKE = i ? 1 : 0; +#ifdef _DEBUG + m_bCSTRIKE = true; +#endif + } +public: + downsample_nohdr_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bSRGB_ADAPTER = false; +#endif // _DEBUG + m_nSRGB_ADAPTER = 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); +#ifdef _DEBUG + m_bCSTRIKE = false; +#endif // _DEBUG + m_nCSTRIKE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bSRGB_ADAPTER && m_bCONVERT_TO_SRGB && m_bCSTRIKE; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nSRGB_ADAPTER ) + ( 2 * m_nCONVERT_TO_SRGB ) + ( 4 * m_nCSTRIKE ) + 0; + } +}; +#define shaderStaticTest_downsample_nohdr_ps20b psh_forgot_to_set_static_SRGB_ADAPTER + psh_forgot_to_set_static_CSTRIKE + 0 +class downsample_nohdr_ps20b_Dynamic_Index +{ +public: + downsample_nohdr_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_downsample_nohdr_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9/Downsample_ps20.inc b/materialsystem/stdshaders/fxctmp9/Downsample_ps20.inc new file mode 100644 index 0000000..1f2dd91 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/Downsample_ps20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class downsample_ps20_Static_Index +{ +public: + downsample_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_downsample_ps20 0 +class downsample_ps20_Dynamic_Index +{ +public: + downsample_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_downsample_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9/Downsample_ps20b.inc b/materialsystem/stdshaders/fxctmp9/Downsample_ps20b.inc new file mode 100644 index 0000000..95257f6 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/Downsample_ps20b.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class downsample_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + downsample_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_downsample_ps20b 0 +class downsample_ps20b_Dynamic_Index +{ +public: + downsample_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_downsample_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9/Downsample_vs11.inc b/materialsystem/stdshaders/fxctmp9/Downsample_vs11.inc new file mode 100644 index 0000000..7b7376c --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/Downsample_vs11.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class downsample_vs11_Static_Index +{ +public: + downsample_vs11_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_downsample_vs11 0 +class downsample_vs11_Dynamic_Index +{ +public: + downsample_vs11_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_downsample_vs11 0 diff --git a/materialsystem/stdshaders/fxctmp9/Downsample_vs20.inc b/materialsystem/stdshaders/fxctmp9/Downsample_vs20.inc new file mode 100644 index 0000000..e6b4b44 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/Downsample_vs20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class downsample_vs20_Static_Index +{ +public: + downsample_vs20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_downsample_vs20 0 +class downsample_vs20_Dynamic_Index +{ +public: + downsample_vs20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_downsample_vs20 0 diff --git a/materialsystem/stdshaders/fxctmp9/HDRCombineTo16Bit_ps20.inc b/materialsystem/stdshaders/fxctmp9/HDRCombineTo16Bit_ps20.inc new file mode 100644 index 0000000..48281e9 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/HDRCombineTo16Bit_ps20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class hdrcombineto16bit_ps20_Static_Index +{ +public: + hdrcombineto16bit_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_hdrcombineto16bit_ps20 0 +class hdrcombineto16bit_ps20_Dynamic_Index +{ +public: + hdrcombineto16bit_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_hdrcombineto16bit_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9/HDRCombineTo16Bit_ps20b.inc b/materialsystem/stdshaders/fxctmp9/HDRCombineTo16Bit_ps20b.inc new file mode 100644 index 0000000..4a93127 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/HDRCombineTo16Bit_ps20b.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class hdrcombineto16bit_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + hdrcombineto16bit_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_hdrcombineto16bit_ps20b 0 +class hdrcombineto16bit_ps20b_Dynamic_Index +{ +public: + hdrcombineto16bit_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_hdrcombineto16bit_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9/HDRCombineTo16Bit_vs20.inc b/materialsystem/stdshaders/fxctmp9/HDRCombineTo16Bit_vs20.inc new file mode 100644 index 0000000..ff22564 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/HDRCombineTo16Bit_vs20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class hdrcombineto16bit_vs20_Static_Index +{ +public: + hdrcombineto16bit_vs20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_hdrcombineto16bit_vs20 0 +class hdrcombineto16bit_vs20_Dynamic_Index +{ +public: + hdrcombineto16bit_vs20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_hdrcombineto16bit_vs20 0 diff --git a/materialsystem/stdshaders/fxctmp9/HDRSelectRange_ps20.inc b/materialsystem/stdshaders/fxctmp9/HDRSelectRange_ps20.inc new file mode 100644 index 0000000..a359417 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/HDRSelectRange_ps20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class hdrselectrange_ps20_Static_Index +{ +public: + hdrselectrange_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_hdrselectrange_ps20 0 +class hdrselectrange_ps20_Dynamic_Index +{ +public: + hdrselectrange_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_hdrselectrange_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9/HDRSelectRange_ps20b.inc b/materialsystem/stdshaders/fxctmp9/HDRSelectRange_ps20b.inc new file mode 100644 index 0000000..f096b97 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/HDRSelectRange_ps20b.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class hdrselectrange_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + hdrselectrange_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_hdrselectrange_ps20b 0 +class hdrselectrange_ps20b_Dynamic_Index +{ +public: + hdrselectrange_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_hdrselectrange_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9/HDRSelectRange_vs20.inc b/materialsystem/stdshaders/fxctmp9/HDRSelectRange_vs20.inc new file mode 100644 index 0000000..1e180e7 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/HDRSelectRange_vs20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class hdrselectrange_vs20_Static_Index +{ +public: + hdrselectrange_vs20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_hdrselectrange_vs20 0 +class hdrselectrange_vs20_Dynamic_Index +{ +public: + hdrselectrange_vs20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_hdrselectrange_vs20 0 diff --git a/materialsystem/stdshaders/fxctmp9/IntroScreenSpaceEffect_ps20.inc b/materialsystem/stdshaders/fxctmp9/IntroScreenSpaceEffect_ps20.inc new file mode 100644 index 0000000..2c95e0c --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/IntroScreenSpaceEffect_ps20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class introscreenspaceeffect_ps20_Static_Index +{ +public: + introscreenspaceeffect_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_introscreenspaceeffect_ps20 0 +class introscreenspaceeffect_ps20_Dynamic_Index +{ +private: + int m_nMODE; +#ifdef _DEBUG + bool m_bMODE; +#endif +public: + void SetMODE( int i ) + { + Assert( i >= 0 && i <= 9 ); + m_nMODE = i; +#ifdef _DEBUG + m_bMODE = true; +#endif + } + void SetMODE( bool i ) + { + m_nMODE = i ? 1 : 0; +#ifdef _DEBUG + m_bMODE = true; +#endif + } +public: + introscreenspaceeffect_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bMODE = false; +#endif // _DEBUG + m_nMODE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bMODE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nMODE ) + 0; + } +}; +#define shaderDynamicTest_introscreenspaceeffect_ps20 psh_forgot_to_set_dynamic_MODE + 0 diff --git a/materialsystem/stdshaders/fxctmp9/IntroScreenSpaceEffect_ps20b.inc b/materialsystem/stdshaders/fxctmp9/IntroScreenSpaceEffect_ps20b.inc new file mode 100644 index 0000000..6fafd18 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/IntroScreenSpaceEffect_ps20b.inc @@ -0,0 +1,112 @@ +#include "shaderlib/cshader.h" +class introscreenspaceeffect_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +private: + int m_nLINEAR_TO_SRGB; +#ifdef _DEBUG + bool m_bLINEAR_TO_SRGB; +#endif +public: + void SetLINEAR_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nLINEAR_TO_SRGB = i; +#ifdef _DEBUG + m_bLINEAR_TO_SRGB = true; +#endif + } + void SetLINEAR_TO_SRGB( bool i ) + { + m_nLINEAR_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bLINEAR_TO_SRGB = true; +#endif + } +public: + introscreenspaceeffect_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); +#ifdef _DEBUG + m_bLINEAR_TO_SRGB = false; +#endif // _DEBUG + m_nLINEAR_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB && m_bLINEAR_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 10 * m_nCONVERT_TO_SRGB ) + ( 20 * m_nLINEAR_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_introscreenspaceeffect_ps20b psh_forgot_to_set_static_LINEAR_TO_SRGB + 0 +class introscreenspaceeffect_ps20b_Dynamic_Index +{ +private: + int m_nMODE; +#ifdef _DEBUG + bool m_bMODE; +#endif +public: + void SetMODE( int i ) + { + Assert( i >= 0 && i <= 9 ); + m_nMODE = i; +#ifdef _DEBUG + m_bMODE = true; +#endif + } + void SetMODE( bool i ) + { + m_nMODE = i ? 1 : 0; +#ifdef _DEBUG + m_bMODE = true; +#endif + } +public: + introscreenspaceeffect_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bMODE = false; +#endif // _DEBUG + m_nMODE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bMODE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nMODE ) + 0; + } +}; +#define shaderDynamicTest_introscreenspaceeffect_ps20b psh_forgot_to_set_dynamic_MODE + 0 diff --git a/materialsystem/stdshaders/fxctmp9/ParticleSphere_ps11.inc b/materialsystem/stdshaders/fxctmp9/ParticleSphere_ps11.inc new file mode 100644 index 0000000..85a976b --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/ParticleSphere_ps11.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class particlesphere_ps11_Static_Index +{ +public: + particlesphere_ps11_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_particlesphere_ps11 0 +class particlesphere_ps11_Dynamic_Index +{ +public: + particlesphere_ps11_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_particlesphere_ps11 0 diff --git a/materialsystem/stdshaders/fxctmp9/ParticleSphere_vs11.inc b/materialsystem/stdshaders/fxctmp9/ParticleSphere_vs11.inc new file mode 100644 index 0000000..4dcaa64 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/ParticleSphere_vs11.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class particlesphere_vs11_Static_Index +{ +public: + particlesphere_vs11_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_particlesphere_vs11 0 +class particlesphere_vs11_Dynamic_Index +{ +private: + int m_nFOGTYPE; +#ifdef _DEBUG + bool m_bFOGTYPE; +#endif +public: + void SetFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFOGTYPE = i; +#ifdef _DEBUG + m_bFOGTYPE = true; +#endif + } + void SetFOGTYPE( bool i ) + { + m_nFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bFOGTYPE = true; +#endif + } +public: + particlesphere_vs11_Dynamic_Index() + { +#ifdef _DEBUG + m_bFOGTYPE = false; +#endif // _DEBUG + m_nFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_particlesphere_vs11 vsh_forgot_to_set_dynamic_FOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9/Refract_ps20.inc b/materialsystem/stdshaders/fxctmp9/Refract_ps20.inc new file mode 100644 index 0000000..2d503d0 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/Refract_ps20.inc @@ -0,0 +1,262 @@ +#include "shaderlib/cshader.h" +class refract_ps20_Static_Index +{ +private: + int m_nBLUR; +#ifdef _DEBUG + bool m_bBLUR; +#endif +public: + void SetBLUR( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBLUR = i; +#ifdef _DEBUG + m_bBLUR = true; +#endif + } + void SetBLUR( bool i ) + { + m_nBLUR = i ? 1 : 0; +#ifdef _DEBUG + m_bBLUR = true; +#endif + } +private: + int m_nFADEOUTONSILHOUETTE; +#ifdef _DEBUG + bool m_bFADEOUTONSILHOUETTE; +#endif +public: + void SetFADEOUTONSILHOUETTE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFADEOUTONSILHOUETTE = i; +#ifdef _DEBUG + m_bFADEOUTONSILHOUETTE = true; +#endif + } + void SetFADEOUTONSILHOUETTE( bool i ) + { + m_nFADEOUTONSILHOUETTE = i ? 1 : 0; +#ifdef _DEBUG + m_bFADEOUTONSILHOUETTE = true; +#endif + } +private: + int m_nCUBEMAP; +#ifdef _DEBUG + bool m_bCUBEMAP; +#endif +public: + void SetCUBEMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCUBEMAP = i; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } + void SetCUBEMAP( bool i ) + { + m_nCUBEMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } +private: + int m_nREFRACTTINTTEXTURE; +#ifdef _DEBUG + bool m_bREFRACTTINTTEXTURE; +#endif +public: + void SetREFRACTTINTTEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nREFRACTTINTTEXTURE = i; +#ifdef _DEBUG + m_bREFRACTTINTTEXTURE = true; +#endif + } + void SetREFRACTTINTTEXTURE( bool i ) + { + m_nREFRACTTINTTEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bREFRACTTINTTEXTURE = true; +#endif + } +private: + int m_nMASKED; +#ifdef _DEBUG + bool m_bMASKED; +#endif +public: + void SetMASKED( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nMASKED = i; +#ifdef _DEBUG + m_bMASKED = true; +#endif + } + void SetMASKED( bool i ) + { + m_nMASKED = i ? 1 : 0; +#ifdef _DEBUG + m_bMASKED = true; +#endif + } +private: + int m_nCOLORMODULATE; +#ifdef _DEBUG + bool m_bCOLORMODULATE; +#endif +public: + void SetCOLORMODULATE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOLORMODULATE = i; +#ifdef _DEBUG + m_bCOLORMODULATE = true; +#endif + } + void SetCOLORMODULATE( bool i ) + { + m_nCOLORMODULATE = i ? 1 : 0; +#ifdef _DEBUG + m_bCOLORMODULATE = true; +#endif + } +private: + int m_nSECONDARY_NORMAL; +#ifdef _DEBUG + bool m_bSECONDARY_NORMAL; +#endif +public: + void SetSECONDARY_NORMAL( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSECONDARY_NORMAL = i; +#ifdef _DEBUG + m_bSECONDARY_NORMAL = true; +#endif + } + void SetSECONDARY_NORMAL( bool i ) + { + m_nSECONDARY_NORMAL = i ? 1 : 0; +#ifdef _DEBUG + m_bSECONDARY_NORMAL = true; +#endif + } +private: + int m_nNORMAL_DECODE_MODE; +#ifdef _DEBUG + bool m_bNORMAL_DECODE_MODE; +#endif +public: + void SetNORMAL_DECODE_MODE( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nNORMAL_DECODE_MODE = i; +#ifdef _DEBUG + m_bNORMAL_DECODE_MODE = true; +#endif + } + void SetNORMAL_DECODE_MODE( bool i ) + { + m_nNORMAL_DECODE_MODE = i ? 1 : 0; +#ifdef _DEBUG + m_bNORMAL_DECODE_MODE = true; +#endif + } +public: + refract_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bBLUR = false; +#endif // _DEBUG + m_nBLUR = 0; +#ifdef _DEBUG + m_bFADEOUTONSILHOUETTE = false; +#endif // _DEBUG + m_nFADEOUTONSILHOUETTE = 0; +#ifdef _DEBUG + m_bCUBEMAP = false; +#endif // _DEBUG + m_nCUBEMAP = 0; +#ifdef _DEBUG + m_bREFRACTTINTTEXTURE = false; +#endif // _DEBUG + m_nREFRACTTINTTEXTURE = 0; +#ifdef _DEBUG + m_bMASKED = false; +#endif // _DEBUG + m_nMASKED = 0; +#ifdef _DEBUG + m_bCOLORMODULATE = false; +#endif // _DEBUG + m_nCOLORMODULATE = 0; +#ifdef _DEBUG + m_bSECONDARY_NORMAL = false; +#endif // _DEBUG + m_nSECONDARY_NORMAL = 0; +#ifdef _DEBUG + m_bNORMAL_DECODE_MODE = false; +#endif // _DEBUG + m_nNORMAL_DECODE_MODE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bBLUR && m_bFADEOUTONSILHOUETTE && m_bCUBEMAP && m_bREFRACTTINTTEXTURE && m_bMASKED && m_bCOLORMODULATE && m_bSECONDARY_NORMAL && m_bNORMAL_DECODE_MODE; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nBLUR ) + ( 4 * m_nFADEOUTONSILHOUETTE ) + ( 8 * m_nCUBEMAP ) + ( 16 * m_nREFRACTTINTTEXTURE ) + ( 32 * m_nMASKED ) + ( 64 * m_nCOLORMODULATE ) + ( 128 * m_nSECONDARY_NORMAL ) + ( 256 * m_nNORMAL_DECODE_MODE ) + 0; + } +}; +#define shaderStaticTest_refract_ps20 psh_forgot_to_set_static_BLUR + psh_forgot_to_set_static_FADEOUTONSILHOUETTE + psh_forgot_to_set_static_CUBEMAP + psh_forgot_to_set_static_REFRACTTINTTEXTURE + psh_forgot_to_set_static_MASKED + psh_forgot_to_set_static_COLORMODULATE + psh_forgot_to_set_static_SECONDARY_NORMAL + psh_forgot_to_set_static_NORMAL_DECODE_MODE + 0 +class refract_ps20_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + refract_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_refract_ps20 psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9/Refract_ps20b.inc b/materialsystem/stdshaders/fxctmp9/Refract_ps20b.inc new file mode 100644 index 0000000..5d56a94 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/Refract_ps20b.inc @@ -0,0 +1,337 @@ +#include "shaderlib/cshader.h" +class refract_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +private: + int m_nBLUR; +#ifdef _DEBUG + bool m_bBLUR; +#endif +public: + void SetBLUR( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBLUR = i; +#ifdef _DEBUG + m_bBLUR = true; +#endif + } + void SetBLUR( bool i ) + { + m_nBLUR = i ? 1 : 0; +#ifdef _DEBUG + m_bBLUR = true; +#endif + } +private: + int m_nFADEOUTONSILHOUETTE; +#ifdef _DEBUG + bool m_bFADEOUTONSILHOUETTE; +#endif +public: + void SetFADEOUTONSILHOUETTE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFADEOUTONSILHOUETTE = i; +#ifdef _DEBUG + m_bFADEOUTONSILHOUETTE = true; +#endif + } + void SetFADEOUTONSILHOUETTE( bool i ) + { + m_nFADEOUTONSILHOUETTE = i ? 1 : 0; +#ifdef _DEBUG + m_bFADEOUTONSILHOUETTE = true; +#endif + } +private: + int m_nCUBEMAP; +#ifdef _DEBUG + bool m_bCUBEMAP; +#endif +public: + void SetCUBEMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCUBEMAP = i; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } + void SetCUBEMAP( bool i ) + { + m_nCUBEMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } +private: + int m_nREFRACTTINTTEXTURE; +#ifdef _DEBUG + bool m_bREFRACTTINTTEXTURE; +#endif +public: + void SetREFRACTTINTTEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nREFRACTTINTTEXTURE = i; +#ifdef _DEBUG + m_bREFRACTTINTTEXTURE = true; +#endif + } + void SetREFRACTTINTTEXTURE( bool i ) + { + m_nREFRACTTINTTEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bREFRACTTINTTEXTURE = true; +#endif + } +private: + int m_nMASKED; +#ifdef _DEBUG + bool m_bMASKED; +#endif +public: + void SetMASKED( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nMASKED = i; +#ifdef _DEBUG + m_bMASKED = true; +#endif + } + void SetMASKED( bool i ) + { + m_nMASKED = i ? 1 : 0; +#ifdef _DEBUG + m_bMASKED = true; +#endif + } +private: + int m_nCOLORMODULATE; +#ifdef _DEBUG + bool m_bCOLORMODULATE; +#endif +public: + void SetCOLORMODULATE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOLORMODULATE = i; +#ifdef _DEBUG + m_bCOLORMODULATE = true; +#endif + } + void SetCOLORMODULATE( bool i ) + { + m_nCOLORMODULATE = i ? 1 : 0; +#ifdef _DEBUG + m_bCOLORMODULATE = true; +#endif + } +private: + int m_nSECONDARY_NORMAL; +#ifdef _DEBUG + bool m_bSECONDARY_NORMAL; +#endif +public: + void SetSECONDARY_NORMAL( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSECONDARY_NORMAL = i; +#ifdef _DEBUG + m_bSECONDARY_NORMAL = true; +#endif + } + void SetSECONDARY_NORMAL( bool i ) + { + m_nSECONDARY_NORMAL = i ? 1 : 0; +#ifdef _DEBUG + m_bSECONDARY_NORMAL = true; +#endif + } +private: + int m_nNORMAL_DECODE_MODE; +#ifdef _DEBUG + bool m_bNORMAL_DECODE_MODE; +#endif +public: + void SetNORMAL_DECODE_MODE( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nNORMAL_DECODE_MODE = i; +#ifdef _DEBUG + m_bNORMAL_DECODE_MODE = true; +#endif + } + void SetNORMAL_DECODE_MODE( bool i ) + { + m_nNORMAL_DECODE_MODE = i ? 1 : 0; +#ifdef _DEBUG + m_bNORMAL_DECODE_MODE = true; +#endif + } +private: + int m_nSHADER_SRGB_READ; +#ifdef _DEBUG + bool m_bSHADER_SRGB_READ; +#endif +public: + void SetSHADER_SRGB_READ( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSHADER_SRGB_READ = i; +#ifdef _DEBUG + m_bSHADER_SRGB_READ = true; +#endif + } + void SetSHADER_SRGB_READ( bool i ) + { + m_nSHADER_SRGB_READ = i ? 1 : 0; +#ifdef _DEBUG + m_bSHADER_SRGB_READ = true; +#endif + } +public: + refract_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); +#ifdef _DEBUG + m_bBLUR = false; +#endif // _DEBUG + m_nBLUR = 0; +#ifdef _DEBUG + m_bFADEOUTONSILHOUETTE = false; +#endif // _DEBUG + m_nFADEOUTONSILHOUETTE = 0; +#ifdef _DEBUG + m_bCUBEMAP = false; +#endif // _DEBUG + m_nCUBEMAP = 0; +#ifdef _DEBUG + m_bREFRACTTINTTEXTURE = false; +#endif // _DEBUG + m_nREFRACTTINTTEXTURE = 0; +#ifdef _DEBUG + m_bMASKED = false; +#endif // _DEBUG + m_nMASKED = 0; +#ifdef _DEBUG + m_bCOLORMODULATE = false; +#endif // _DEBUG + m_nCOLORMODULATE = 0; +#ifdef _DEBUG + m_bSECONDARY_NORMAL = false; +#endif // _DEBUG + m_nSECONDARY_NORMAL = 0; +#ifdef _DEBUG + m_bNORMAL_DECODE_MODE = false; +#endif // _DEBUG + m_nNORMAL_DECODE_MODE = 0; +#ifdef _DEBUG + m_bSHADER_SRGB_READ = false; +#endif // _DEBUG + m_nSHADER_SRGB_READ = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB && m_bBLUR && m_bFADEOUTONSILHOUETTE && m_bCUBEMAP && m_bREFRACTTINTTEXTURE && m_bMASKED && m_bCOLORMODULATE && m_bSECONDARY_NORMAL && m_bNORMAL_DECODE_MODE && m_bSHADER_SRGB_READ; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 4 * m_nCONVERT_TO_SRGB ) + ( 8 * m_nBLUR ) + ( 16 * m_nFADEOUTONSILHOUETTE ) + ( 32 * m_nCUBEMAP ) + ( 64 * m_nREFRACTTINTTEXTURE ) + ( 128 * m_nMASKED ) + ( 256 * m_nCOLORMODULATE ) + ( 512 * m_nSECONDARY_NORMAL ) + ( 1024 * m_nNORMAL_DECODE_MODE ) + ( 1024 * m_nSHADER_SRGB_READ ) + 0; + } +}; +#define shaderStaticTest_refract_ps20b psh_forgot_to_set_static_BLUR + psh_forgot_to_set_static_FADEOUTONSILHOUETTE + psh_forgot_to_set_static_CUBEMAP + psh_forgot_to_set_static_REFRACTTINTTEXTURE + psh_forgot_to_set_static_MASKED + psh_forgot_to_set_static_COLORMODULATE + psh_forgot_to_set_static_SECONDARY_NORMAL + psh_forgot_to_set_static_NORMAL_DECODE_MODE + psh_forgot_to_set_static_SHADER_SRGB_READ + 0 +class refract_ps20b_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +private: + int m_nWRITE_DEPTH_TO_DESTALPHA; +#ifdef _DEBUG + bool m_bWRITE_DEPTH_TO_DESTALPHA; +#endif +public: + void SetWRITE_DEPTH_TO_DESTALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nWRITE_DEPTH_TO_DESTALPHA = i; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = true; +#endif + } + void SetWRITE_DEPTH_TO_DESTALPHA( bool i ) + { + m_nWRITE_DEPTH_TO_DESTALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = true; +#endif + } +public: + refract_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = false; +#endif // _DEBUG + m_nWRITE_DEPTH_TO_DESTALPHA = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE && m_bWRITE_DEPTH_TO_DESTALPHA; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + ( 2 * m_nWRITE_DEPTH_TO_DESTALPHA ) + 0; + } +}; +#define shaderDynamicTest_refract_ps20b psh_forgot_to_set_dynamic_PIXELFOGTYPE + psh_forgot_to_set_dynamic_WRITE_DEPTH_TO_DESTALPHA + 0 diff --git a/materialsystem/stdshaders/fxctmp9/Refract_vs20.inc b/materialsystem/stdshaders/fxctmp9/Refract_vs20.inc new file mode 100644 index 0000000..ad4e856 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/Refract_vs20.inc @@ -0,0 +1,137 @@ +#include "shaderlib/cshader.h" +class refract_vs20_Static_Index +{ +private: + int m_nMODEL; +#ifdef _DEBUG + bool m_bMODEL; +#endif +public: + void SetMODEL( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nMODEL = i; +#ifdef _DEBUG + m_bMODEL = true; +#endif + } + void SetMODEL( bool i ) + { + m_nMODEL = i ? 1 : 0; +#ifdef _DEBUG + m_bMODEL = true; +#endif + } +private: + int m_nCOLORMODULATE; +#ifdef _DEBUG + bool m_bCOLORMODULATE; +#endif +public: + void SetCOLORMODULATE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOLORMODULATE = i; +#ifdef _DEBUG + m_bCOLORMODULATE = true; +#endif + } + void SetCOLORMODULATE( bool i ) + { + m_nCOLORMODULATE = i ? 1 : 0; +#ifdef _DEBUG + m_bCOLORMODULATE = true; +#endif + } +public: + refract_vs20_Static_Index( ) + { +#ifdef _DEBUG + m_bMODEL = false; +#endif // _DEBUG + m_nMODEL = 0; +#ifdef _DEBUG + m_bCOLORMODULATE = false; +#endif // _DEBUG + m_nCOLORMODULATE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bMODEL && m_bCOLORMODULATE; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 4 * m_nMODEL ) + ( 8 * m_nCOLORMODULATE ) + 0; + } +}; +#define shaderStaticTest_refract_vs20 vsh_forgot_to_set_static_MODEL + vsh_forgot_to_set_static_COLORMODULATE + 0 +class refract_vs20_Dynamic_Index +{ +private: + int m_nCOMPRESSED_VERTS; +#ifdef _DEBUG + bool m_bCOMPRESSED_VERTS; +#endif +public: + void SetCOMPRESSED_VERTS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOMPRESSED_VERTS = i; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } + void SetCOMPRESSED_VERTS( bool i ) + { + m_nCOMPRESSED_VERTS = i ? 1 : 0; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +public: + refract_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = false; +#endif // _DEBUG + m_nCOMPRESSED_VERTS = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bCOMPRESSED_VERTS && m_bSKINNING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCOMPRESSED_VERTS ) + ( 2 * m_nSKINNING ) + 0; + } +}; +#define shaderDynamicTest_refract_vs20 vsh_forgot_to_set_dynamic_COMPRESSED_VERTS + vsh_forgot_to_set_dynamic_SKINNING + 0 diff --git a/materialsystem/stdshaders/fxctmp9/ShatteredGlass_ps20.inc b/materialsystem/stdshaders/fxctmp9/ShatteredGlass_ps20.inc new file mode 100644 index 0000000..1d3e975 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/ShatteredGlass_ps20.inc @@ -0,0 +1,212 @@ +#include "shaderlib/cshader.h" +class shatteredglass_ps20_Static_Index +{ +private: + int m_nCUBEMAP; +#ifdef _DEBUG + bool m_bCUBEMAP; +#endif +public: + void SetCUBEMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCUBEMAP = i; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } + void SetCUBEMAP( bool i ) + { + m_nCUBEMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } +private: + int m_nVERTEXCOLOR; +#ifdef _DEBUG + bool m_bVERTEXCOLOR; +#endif +public: + void SetVERTEXCOLOR( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nVERTEXCOLOR = i; +#ifdef _DEBUG + m_bVERTEXCOLOR = true; +#endif + } + void SetVERTEXCOLOR( bool i ) + { + m_nVERTEXCOLOR = i ? 1 : 0; +#ifdef _DEBUG + m_bVERTEXCOLOR = true; +#endif + } +private: + int m_nENVMAPMASK; +#ifdef _DEBUG + bool m_bENVMAPMASK; +#endif +public: + void SetENVMAPMASK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nENVMAPMASK = i; +#ifdef _DEBUG + m_bENVMAPMASK = true; +#endif + } + void SetENVMAPMASK( bool i ) + { + m_nENVMAPMASK = i ? 1 : 0; +#ifdef _DEBUG + m_bENVMAPMASK = true; +#endif + } +private: + int m_nBASEALPHAENVMAPMASK; +#ifdef _DEBUG + bool m_bBASEALPHAENVMAPMASK; +#endif +public: + void SetBASEALPHAENVMAPMASK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBASEALPHAENVMAPMASK = i; +#ifdef _DEBUG + m_bBASEALPHAENVMAPMASK = true; +#endif + } + void SetBASEALPHAENVMAPMASK( bool i ) + { + m_nBASEALPHAENVMAPMASK = i ? 1 : 0; +#ifdef _DEBUG + m_bBASEALPHAENVMAPMASK = true; +#endif + } +private: + int m_nHDRTYPE; +#ifdef _DEBUG + bool m_bHDRTYPE; +#endif +public: + void SetHDRTYPE( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nHDRTYPE = i; +#ifdef _DEBUG + m_bHDRTYPE = true; +#endif + } + void SetHDRTYPE( bool i ) + { + m_nHDRTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bHDRTYPE = true; +#endif + } +public: + shatteredglass_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCUBEMAP = false; +#endif // _DEBUG + m_nCUBEMAP = 0; +#ifdef _DEBUG + m_bVERTEXCOLOR = false; +#endif // _DEBUG + m_nVERTEXCOLOR = 0; +#ifdef _DEBUG + m_bENVMAPMASK = false; +#endif // _DEBUG + m_nENVMAPMASK = 0; +#ifdef _DEBUG + m_bBASEALPHAENVMAPMASK = false; +#endif // _DEBUG + m_nBASEALPHAENVMAPMASK = 0; +#ifdef _DEBUG + m_bHDRTYPE = false; +#endif // _DEBUG + m_nHDRTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCUBEMAP && m_bVERTEXCOLOR && m_bENVMAPMASK && m_bBASEALPHAENVMAPMASK && m_bHDRTYPE; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 4 * m_nCUBEMAP ) + ( 8 * m_nVERTEXCOLOR ) + ( 16 * m_nENVMAPMASK ) + ( 32 * m_nBASEALPHAENVMAPMASK ) + ( 64 * m_nHDRTYPE ) + 0; + } +}; +#define shaderStaticTest_shatteredglass_ps20 psh_forgot_to_set_static_CUBEMAP + psh_forgot_to_set_static_VERTEXCOLOR + psh_forgot_to_set_static_ENVMAPMASK + psh_forgot_to_set_static_BASEALPHAENVMAPMASK + psh_forgot_to_set_static_HDRTYPE + 0 +class shatteredglass_ps20_Dynamic_Index +{ +private: + int m_nHDRENABLED; +#ifdef _DEBUG + bool m_bHDRENABLED; +#endif +public: + void SetHDRENABLED( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHDRENABLED = i; +#ifdef _DEBUG + m_bHDRENABLED = true; +#endif + } + void SetHDRENABLED( bool i ) + { + m_nHDRENABLED = i ? 1 : 0; +#ifdef _DEBUG + m_bHDRENABLED = true; +#endif + } +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + shatteredglass_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bHDRENABLED = false; +#endif // _DEBUG + m_nHDRENABLED = 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bHDRENABLED && m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nHDRENABLED ) + ( 2 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_shatteredglass_ps20 psh_forgot_to_set_dynamic_HDRENABLED + psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9/ShatteredGlass_ps20b.inc b/materialsystem/stdshaders/fxctmp9/ShatteredGlass_ps20b.inc new file mode 100644 index 0000000..7b2df39 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/ShatteredGlass_ps20b.inc @@ -0,0 +1,237 @@ +#include "shaderlib/cshader.h" +class shatteredglass_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +private: + int m_nCUBEMAP; +#ifdef _DEBUG + bool m_bCUBEMAP; +#endif +public: + void SetCUBEMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCUBEMAP = i; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } + void SetCUBEMAP( bool i ) + { + m_nCUBEMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } +private: + int m_nVERTEXCOLOR; +#ifdef _DEBUG + bool m_bVERTEXCOLOR; +#endif +public: + void SetVERTEXCOLOR( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nVERTEXCOLOR = i; +#ifdef _DEBUG + m_bVERTEXCOLOR = true; +#endif + } + void SetVERTEXCOLOR( bool i ) + { + m_nVERTEXCOLOR = i ? 1 : 0; +#ifdef _DEBUG + m_bVERTEXCOLOR = true; +#endif + } +private: + int m_nENVMAPMASK; +#ifdef _DEBUG + bool m_bENVMAPMASK; +#endif +public: + void SetENVMAPMASK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nENVMAPMASK = i; +#ifdef _DEBUG + m_bENVMAPMASK = true; +#endif + } + void SetENVMAPMASK( bool i ) + { + m_nENVMAPMASK = i ? 1 : 0; +#ifdef _DEBUG + m_bENVMAPMASK = true; +#endif + } +private: + int m_nBASEALPHAENVMAPMASK; +#ifdef _DEBUG + bool m_bBASEALPHAENVMAPMASK; +#endif +public: + void SetBASEALPHAENVMAPMASK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBASEALPHAENVMAPMASK = i; +#ifdef _DEBUG + m_bBASEALPHAENVMAPMASK = true; +#endif + } + void SetBASEALPHAENVMAPMASK( bool i ) + { + m_nBASEALPHAENVMAPMASK = i ? 1 : 0; +#ifdef _DEBUG + m_bBASEALPHAENVMAPMASK = true; +#endif + } +private: + int m_nHDRTYPE; +#ifdef _DEBUG + bool m_bHDRTYPE; +#endif +public: + void SetHDRTYPE( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nHDRTYPE = i; +#ifdef _DEBUG + m_bHDRTYPE = true; +#endif + } + void SetHDRTYPE( bool i ) + { + m_nHDRTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bHDRTYPE = true; +#endif + } +public: + shatteredglass_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); +#ifdef _DEBUG + m_bCUBEMAP = false; +#endif // _DEBUG + m_nCUBEMAP = 0; +#ifdef _DEBUG + m_bVERTEXCOLOR = false; +#endif // _DEBUG + m_nVERTEXCOLOR = 0; +#ifdef _DEBUG + m_bENVMAPMASK = false; +#endif // _DEBUG + m_nENVMAPMASK = 0; +#ifdef _DEBUG + m_bBASEALPHAENVMAPMASK = false; +#endif // _DEBUG + m_nBASEALPHAENVMAPMASK = 0; +#ifdef _DEBUG + m_bHDRTYPE = false; +#endif // _DEBUG + m_nHDRTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB && m_bCUBEMAP && m_bVERTEXCOLOR && m_bENVMAPMASK && m_bBASEALPHAENVMAPMASK && m_bHDRTYPE; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 4 * m_nCONVERT_TO_SRGB ) + ( 8 * m_nCUBEMAP ) + ( 16 * m_nVERTEXCOLOR ) + ( 32 * m_nENVMAPMASK ) + ( 64 * m_nBASEALPHAENVMAPMASK ) + ( 128 * m_nHDRTYPE ) + 0; + } +}; +#define shaderStaticTest_shatteredglass_ps20b psh_forgot_to_set_static_CUBEMAP + psh_forgot_to_set_static_VERTEXCOLOR + psh_forgot_to_set_static_ENVMAPMASK + psh_forgot_to_set_static_BASEALPHAENVMAPMASK + psh_forgot_to_set_static_HDRTYPE + 0 +class shatteredglass_ps20b_Dynamic_Index +{ +private: + int m_nHDRENABLED; +#ifdef _DEBUG + bool m_bHDRENABLED; +#endif +public: + void SetHDRENABLED( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHDRENABLED = i; +#ifdef _DEBUG + m_bHDRENABLED = true; +#endif + } + void SetHDRENABLED( bool i ) + { + m_nHDRENABLED = i ? 1 : 0; +#ifdef _DEBUG + m_bHDRENABLED = true; +#endif + } +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + shatteredglass_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bHDRENABLED = false; +#endif // _DEBUG + m_nHDRENABLED = 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bHDRENABLED && m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nHDRENABLED ) + ( 2 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_shatteredglass_ps20b psh_forgot_to_set_dynamic_HDRENABLED + psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9/ShatteredGlass_vs20.inc b/materialsystem/stdshaders/fxctmp9/ShatteredGlass_vs20.inc new file mode 100644 index 0000000..adc1b4b --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/ShatteredGlass_vs20.inc @@ -0,0 +1,87 @@ +#include "shaderlib/cshader.h" +class shatteredglass_vs20_Static_Index +{ +private: + int m_nENVMAP_MASK; +#ifdef _DEBUG + bool m_bENVMAP_MASK; +#endif +public: + void SetENVMAP_MASK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nENVMAP_MASK = i; +#ifdef _DEBUG + m_bENVMAP_MASK = true; +#endif + } + void SetENVMAP_MASK( bool i ) + { + m_nENVMAP_MASK = i ? 1 : 0; +#ifdef _DEBUG + m_bENVMAP_MASK = true; +#endif + } +public: + shatteredglass_vs20_Static_Index( ) + { +#ifdef _DEBUG + m_bENVMAP_MASK = false; +#endif // _DEBUG + m_nENVMAP_MASK = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bENVMAP_MASK; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nENVMAP_MASK ) + 0; + } +}; +#define shaderStaticTest_shatteredglass_vs20 vsh_forgot_to_set_static_ENVMAP_MASK + 0 +class shatteredglass_vs20_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + shatteredglass_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; +#define shaderDynamicTest_shatteredglass_vs20 vsh_forgot_to_set_dynamic_DOWATERFOG + 0 diff --git a/materialsystem/stdshaders/fxctmp9/VertexLit_and_unlit_Generic_bump_vs20.inc b/materialsystem/stdshaders/fxctmp9/VertexLit_and_unlit_Generic_bump_vs20.inc new file mode 100644 index 0000000..858b1ad --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/VertexLit_and_unlit_Generic_bump_vs20.inc @@ -0,0 +1,212 @@ +#include "shaderlib/cshader.h" +class vertexlit_and_unlit_generic_bump_vs20_Static_Index +{ +private: + int m_nHALFLAMBERT; +#ifdef _DEBUG + bool m_bHALFLAMBERT; +#endif +public: + void SetHALFLAMBERT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHALFLAMBERT = i; +#ifdef _DEBUG + m_bHALFLAMBERT = true; +#endif + } + void SetHALFLAMBERT( bool i ) + { + m_nHALFLAMBERT = i ? 1 : 0; +#ifdef _DEBUG + m_bHALFLAMBERT = true; +#endif + } +private: + int m_nUSE_WITH_2B; +#ifdef _DEBUG + bool m_bUSE_WITH_2B; +#endif +public: + void SetUSE_WITH_2B( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nUSE_WITH_2B = i; +#ifdef _DEBUG + m_bUSE_WITH_2B = true; +#endif + } + void SetUSE_WITH_2B( bool i ) + { + m_nUSE_WITH_2B = i ? 1 : 0; +#ifdef _DEBUG + m_bUSE_WITH_2B = true; +#endif + } +private: + int m_nUSE_STATIC_CONTROL_FLOW; +#ifdef _DEBUG + bool m_bUSE_STATIC_CONTROL_FLOW; +#endif +public: + void SetUSE_STATIC_CONTROL_FLOW( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nUSE_STATIC_CONTROL_FLOW = i; +#ifdef _DEBUG + m_bUSE_STATIC_CONTROL_FLOW = true; +#endif + } + void SetUSE_STATIC_CONTROL_FLOW( bool i ) + { + m_nUSE_STATIC_CONTROL_FLOW = i ? 1 : 0; +#ifdef _DEBUG + m_bUSE_STATIC_CONTROL_FLOW = true; +#endif + } +public: + vertexlit_and_unlit_generic_bump_vs20_Static_Index( ) + { +#ifdef _DEBUG + m_bHALFLAMBERT = false; +#endif // _DEBUG + m_nHALFLAMBERT = 0; +#ifdef _DEBUG + m_bUSE_WITH_2B = false; +#endif // _DEBUG + m_nUSE_WITH_2B = 0; +#ifdef _DEBUG + m_bUSE_STATIC_CONTROL_FLOW = false; +#endif // _DEBUG + m_nUSE_STATIC_CONTROL_FLOW = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bHALFLAMBERT && m_bUSE_WITH_2B && m_bUSE_STATIC_CONTROL_FLOW; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 24 * m_nHALFLAMBERT ) + ( 48 * m_nUSE_WITH_2B ) + ( 96 * m_nUSE_STATIC_CONTROL_FLOW ) + 0; + } +}; +#define shaderStaticTest_vertexlit_and_unlit_generic_bump_vs20 vsh_forgot_to_set_static_HALFLAMBERT + vsh_forgot_to_set_static_USE_WITH_2B + vsh_forgot_to_set_static_USE_STATIC_CONTROL_FLOW + 0 +class vertexlit_and_unlit_generic_bump_vs20_Dynamic_Index +{ +private: + int m_nCOMPRESSED_VERTS; +#ifdef _DEBUG + bool m_bCOMPRESSED_VERTS; +#endif +public: + void SetCOMPRESSED_VERTS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOMPRESSED_VERTS = i; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } + void SetCOMPRESSED_VERTS( bool i ) + { + m_nCOMPRESSED_VERTS = i ? 1 : 0; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +private: + int m_nNUM_LIGHTS; +#ifdef _DEBUG + bool m_bNUM_LIGHTS; +#endif +public: + void SetNUM_LIGHTS( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nNUM_LIGHTS = i; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } + void SetNUM_LIGHTS( bool i ) + { + m_nNUM_LIGHTS = i ? 1 : 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } +public: + vertexlit_and_unlit_generic_bump_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = false; +#endif // _DEBUG + m_nCOMPRESSED_VERTS = 0; +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = false; +#endif // _DEBUG + m_nNUM_LIGHTS = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bCOMPRESSED_VERTS && m_bDOWATERFOG && m_bSKINNING && m_bNUM_LIGHTS; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCOMPRESSED_VERTS ) + ( 2 * m_nDOWATERFOG ) + ( 4 * m_nSKINNING ) + ( 8 * m_nNUM_LIGHTS ) + 0; + } +}; +#define shaderDynamicTest_vertexlit_and_unlit_generic_bump_vs20 vsh_forgot_to_set_dynamic_COMPRESSED_VERTS + vsh_forgot_to_set_dynamic_DOWATERFOG + vsh_forgot_to_set_dynamic_SKINNING + vsh_forgot_to_set_dynamic_NUM_LIGHTS + 0 diff --git a/materialsystem/stdshaders/fxctmp9/VertexLit_and_unlit_Generic_vs20.inc b/materialsystem/stdshaders/fxctmp9/VertexLit_and_unlit_Generic_vs20.inc new file mode 100644 index 0000000..96bc192 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/VertexLit_and_unlit_Generic_vs20.inc @@ -0,0 +1,462 @@ +#include "shaderlib/cshader.h" +class vertexlit_and_unlit_generic_vs20_Static_Index +{ +private: + int m_nVERTEXCOLOR; +#ifdef _DEBUG + bool m_bVERTEXCOLOR; +#endif +public: + void SetVERTEXCOLOR( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nVERTEXCOLOR = i; +#ifdef _DEBUG + m_bVERTEXCOLOR = true; +#endif + } + void SetVERTEXCOLOR( bool i ) + { + m_nVERTEXCOLOR = i ? 1 : 0; +#ifdef _DEBUG + m_bVERTEXCOLOR = true; +#endif + } +private: + int m_nCUBEMAP; +#ifdef _DEBUG + bool m_bCUBEMAP; +#endif +public: + void SetCUBEMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCUBEMAP = i; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } + void SetCUBEMAP( bool i ) + { + m_nCUBEMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } +private: + int m_nHALFLAMBERT; +#ifdef _DEBUG + bool m_bHALFLAMBERT; +#endif +public: + void SetHALFLAMBERT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHALFLAMBERT = i; +#ifdef _DEBUG + m_bHALFLAMBERT = true; +#endif + } + void SetHALFLAMBERT( bool i ) + { + m_nHALFLAMBERT = i ? 1 : 0; +#ifdef _DEBUG + m_bHALFLAMBERT = true; +#endif + } +private: + int m_nFLASHLIGHT; +#ifdef _DEBUG + bool m_bFLASHLIGHT; +#endif +public: + void SetFLASHLIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFLASHLIGHT = i; +#ifdef _DEBUG + m_bFLASHLIGHT = true; +#endif + } + void SetFLASHLIGHT( bool i ) + { + m_nFLASHLIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bFLASHLIGHT = true; +#endif + } +private: + int m_nSEAMLESS_BASE; +#ifdef _DEBUG + bool m_bSEAMLESS_BASE; +#endif +public: + void SetSEAMLESS_BASE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSEAMLESS_BASE = i; +#ifdef _DEBUG + m_bSEAMLESS_BASE = true; +#endif + } + void SetSEAMLESS_BASE( bool i ) + { + m_nSEAMLESS_BASE = i ? 1 : 0; +#ifdef _DEBUG + m_bSEAMLESS_BASE = true; +#endif + } +private: + int m_nSEAMLESS_DETAIL; +#ifdef _DEBUG + bool m_bSEAMLESS_DETAIL; +#endif +public: + void SetSEAMLESS_DETAIL( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSEAMLESS_DETAIL = i; +#ifdef _DEBUG + m_bSEAMLESS_DETAIL = true; +#endif + } + void SetSEAMLESS_DETAIL( bool i ) + { + m_nSEAMLESS_DETAIL = i ? 1 : 0; +#ifdef _DEBUG + m_bSEAMLESS_DETAIL = true; +#endif + } +private: + int m_nSEPARATE_DETAIL_UVS; +#ifdef _DEBUG + bool m_bSEPARATE_DETAIL_UVS; +#endif +public: + void SetSEPARATE_DETAIL_UVS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSEPARATE_DETAIL_UVS = i; +#ifdef _DEBUG + m_bSEPARATE_DETAIL_UVS = true; +#endif + } + void SetSEPARATE_DETAIL_UVS( bool i ) + { + m_nSEPARATE_DETAIL_UVS = i ? 1 : 0; +#ifdef _DEBUG + m_bSEPARATE_DETAIL_UVS = true; +#endif + } +private: + int m_nUSE_STATIC_CONTROL_FLOW; +#ifdef _DEBUG + bool m_bUSE_STATIC_CONTROL_FLOW; +#endif +public: + void SetUSE_STATIC_CONTROL_FLOW( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nUSE_STATIC_CONTROL_FLOW = i; +#ifdef _DEBUG + m_bUSE_STATIC_CONTROL_FLOW = true; +#endif + } + void SetUSE_STATIC_CONTROL_FLOW( bool i ) + { + m_nUSE_STATIC_CONTROL_FLOW = i ? 1 : 0; +#ifdef _DEBUG + m_bUSE_STATIC_CONTROL_FLOW = true; +#endif + } +private: + int m_nDONT_GAMMA_CONVERT_VERTEX_COLOR; +#ifdef _DEBUG + bool m_bDONT_GAMMA_CONVERT_VERTEX_COLOR; +#endif +public: + void SetDONT_GAMMA_CONVERT_VERTEX_COLOR( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDONT_GAMMA_CONVERT_VERTEX_COLOR = i; +#ifdef _DEBUG + m_bDONT_GAMMA_CONVERT_VERTEX_COLOR = true; +#endif + } + void SetDONT_GAMMA_CONVERT_VERTEX_COLOR( bool i ) + { + m_nDONT_GAMMA_CONVERT_VERTEX_COLOR = i ? 1 : 0; +#ifdef _DEBUG + m_bDONT_GAMMA_CONVERT_VERTEX_COLOR = true; +#endif + } +public: + vertexlit_and_unlit_generic_vs20_Static_Index( ) + { +#ifdef _DEBUG + m_bVERTEXCOLOR = false; +#endif // _DEBUG + m_nVERTEXCOLOR = 0; +#ifdef _DEBUG + m_bCUBEMAP = false; +#endif // _DEBUG + m_nCUBEMAP = 0; +#ifdef _DEBUG + m_bHALFLAMBERT = false; +#endif // _DEBUG + m_nHALFLAMBERT = 0; +#ifdef _DEBUG + m_bFLASHLIGHT = false; +#endif // _DEBUG + m_nFLASHLIGHT = 0; +#ifdef _DEBUG + m_bSEAMLESS_BASE = false; +#endif // _DEBUG + m_nSEAMLESS_BASE = 0; +#ifdef _DEBUG + m_bSEAMLESS_DETAIL = false; +#endif // _DEBUG + m_nSEAMLESS_DETAIL = 0; +#ifdef _DEBUG + m_bSEPARATE_DETAIL_UVS = false; +#endif // _DEBUG + m_nSEPARATE_DETAIL_UVS = 0; +#ifdef _DEBUG + m_bUSE_STATIC_CONTROL_FLOW = false; +#endif // _DEBUG + m_nUSE_STATIC_CONTROL_FLOW = 0; +#ifdef _DEBUG + m_bDONT_GAMMA_CONVERT_VERTEX_COLOR = false; +#endif // _DEBUG + m_nDONT_GAMMA_CONVERT_VERTEX_COLOR = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bVERTEXCOLOR && m_bCUBEMAP && m_bHALFLAMBERT && m_bFLASHLIGHT && m_bSEAMLESS_BASE && m_bSEAMLESS_DETAIL && m_bSEPARATE_DETAIL_UVS && m_bUSE_STATIC_CONTROL_FLOW && m_bDONT_GAMMA_CONVERT_VERTEX_COLOR; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 384 * m_nVERTEXCOLOR ) + ( 768 * m_nCUBEMAP ) + ( 1536 * m_nHALFLAMBERT ) + ( 3072 * m_nFLASHLIGHT ) + ( 6144 * m_nSEAMLESS_BASE ) + ( 12288 * m_nSEAMLESS_DETAIL ) + ( 24576 * m_nSEPARATE_DETAIL_UVS ) + ( 49152 * m_nUSE_STATIC_CONTROL_FLOW ) + ( 98304 * m_nDONT_GAMMA_CONVERT_VERTEX_COLOR ) + 0; + } +}; +#define shaderStaticTest_vertexlit_and_unlit_generic_vs20 vsh_forgot_to_set_static_VERTEXCOLOR + vsh_forgot_to_set_static_CUBEMAP + vsh_forgot_to_set_static_HALFLAMBERT + vsh_forgot_to_set_static_FLASHLIGHT + vsh_forgot_to_set_static_SEAMLESS_BASE + vsh_forgot_to_set_static_SEAMLESS_DETAIL + vsh_forgot_to_set_static_SEPARATE_DETAIL_UVS + vsh_forgot_to_set_static_USE_STATIC_CONTROL_FLOW + vsh_forgot_to_set_static_DONT_GAMMA_CONVERT_VERTEX_COLOR + 0 +class vertexlit_and_unlit_generic_vs20_Dynamic_Index +{ +private: + int m_nCOMPRESSED_VERTS; +#ifdef _DEBUG + bool m_bCOMPRESSED_VERTS; +#endif +public: + void SetCOMPRESSED_VERTS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOMPRESSED_VERTS = i; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } + void SetCOMPRESSED_VERTS( bool i ) + { + m_nCOMPRESSED_VERTS = i ? 1 : 0; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } +private: + int m_nDYNAMIC_LIGHT; +#ifdef _DEBUG + bool m_bDYNAMIC_LIGHT; +#endif +public: + void SetDYNAMIC_LIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDYNAMIC_LIGHT = i; +#ifdef _DEBUG + m_bDYNAMIC_LIGHT = true; +#endif + } + void SetDYNAMIC_LIGHT( bool i ) + { + m_nDYNAMIC_LIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bDYNAMIC_LIGHT = true; +#endif + } +private: + int m_nSTATIC_LIGHT_VERTEX; +#ifdef _DEBUG + bool m_bSTATIC_LIGHT_VERTEX; +#endif +public: + void SetSTATIC_LIGHT_VERTEX( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSTATIC_LIGHT_VERTEX = i; +#ifdef _DEBUG + m_bSTATIC_LIGHT_VERTEX = true; +#endif + } + void SetSTATIC_LIGHT_VERTEX( bool i ) + { + m_nSTATIC_LIGHT_VERTEX = i ? 1 : 0; +#ifdef _DEBUG + m_bSTATIC_LIGHT_VERTEX = true; +#endif + } +private: + int m_nSTATIC_LIGHT_LIGHTMAP; +#ifdef _DEBUG + bool m_bSTATIC_LIGHT_LIGHTMAP; +#endif +public: + void SetSTATIC_LIGHT_LIGHTMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSTATIC_LIGHT_LIGHTMAP = i; +#ifdef _DEBUG + m_bSTATIC_LIGHT_LIGHTMAP = true; +#endif + } + void SetSTATIC_LIGHT_LIGHTMAP( bool i ) + { + m_nSTATIC_LIGHT_LIGHTMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bSTATIC_LIGHT_LIGHTMAP = true; +#endif + } +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +private: + int m_nLIGHTING_PREVIEW; +#ifdef _DEBUG + bool m_bLIGHTING_PREVIEW; +#endif +public: + void SetLIGHTING_PREVIEW( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nLIGHTING_PREVIEW = i; +#ifdef _DEBUG + m_bLIGHTING_PREVIEW = true; +#endif + } + void SetLIGHTING_PREVIEW( bool i ) + { + m_nLIGHTING_PREVIEW = i ? 1 : 0; +#ifdef _DEBUG + m_bLIGHTING_PREVIEW = true; +#endif + } +private: + int m_nNUM_LIGHTS; +#ifdef _DEBUG + bool m_bNUM_LIGHTS; +#endif +public: + void SetNUM_LIGHTS( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nNUM_LIGHTS = i; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } + void SetNUM_LIGHTS( bool i ) + { + m_nNUM_LIGHTS = i ? 1 : 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } +public: + vertexlit_and_unlit_generic_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = false; +#endif // _DEBUG + m_nCOMPRESSED_VERTS = 0; +#ifdef _DEBUG + m_bDYNAMIC_LIGHT = false; +#endif // _DEBUG + m_nDYNAMIC_LIGHT = 0; +#ifdef _DEBUG + m_bSTATIC_LIGHT_VERTEX = false; +#endif // _DEBUG + m_nSTATIC_LIGHT_VERTEX = 0; +#ifdef _DEBUG + m_bSTATIC_LIGHT_LIGHTMAP = false; +#endif // _DEBUG + m_nSTATIC_LIGHT_LIGHTMAP = 0; +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; +#ifdef _DEBUG + m_bLIGHTING_PREVIEW = false; +#endif // _DEBUG + m_nLIGHTING_PREVIEW = 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = false; +#endif // _DEBUG + m_nNUM_LIGHTS = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bCOMPRESSED_VERTS && m_bDYNAMIC_LIGHT && m_bSTATIC_LIGHT_VERTEX && m_bSTATIC_LIGHT_LIGHTMAP && m_bDOWATERFOG && m_bSKINNING && m_bLIGHTING_PREVIEW && m_bNUM_LIGHTS; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCOMPRESSED_VERTS ) + ( 2 * m_nDYNAMIC_LIGHT ) + ( 4 * m_nSTATIC_LIGHT_VERTEX ) + ( 8 * m_nSTATIC_LIGHT_LIGHTMAP ) + ( 16 * m_nDOWATERFOG ) + ( 32 * m_nSKINNING ) + ( 64 * m_nLIGHTING_PREVIEW ) + ( 128 * m_nNUM_LIGHTS ) + 0; + } +}; +#define shaderDynamicTest_vertexlit_and_unlit_generic_vs20 vsh_forgot_to_set_dynamic_COMPRESSED_VERTS + vsh_forgot_to_set_dynamic_DYNAMIC_LIGHT + vsh_forgot_to_set_dynamic_STATIC_LIGHT_VERTEX + vsh_forgot_to_set_dynamic_STATIC_LIGHT_LIGHTMAP + vsh_forgot_to_set_dynamic_DOWATERFOG + vsh_forgot_to_set_dynamic_SKINNING + vsh_forgot_to_set_dynamic_LIGHTING_PREVIEW + vsh_forgot_to_set_dynamic_NUM_LIGHTS + 0 diff --git a/materialsystem/stdshaders/fxctmp9/WaterCheap_ps20.inc b/materialsystem/stdshaders/fxctmp9/WaterCheap_ps20.inc new file mode 100644 index 0000000..5e6dd2b --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/WaterCheap_ps20.inc @@ -0,0 +1,237 @@ +#include "shaderlib/cshader.h" +class watercheap_ps20_Static_Index +{ +private: + int m_nMULTITEXTURE; +#ifdef _DEBUG + bool m_bMULTITEXTURE; +#endif +public: + void SetMULTITEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nMULTITEXTURE = i; +#ifdef _DEBUG + m_bMULTITEXTURE = true; +#endif + } + void SetMULTITEXTURE( bool i ) + { + m_nMULTITEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bMULTITEXTURE = true; +#endif + } +private: + int m_nFRESNEL; +#ifdef _DEBUG + bool m_bFRESNEL; +#endif +public: + void SetFRESNEL( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFRESNEL = i; +#ifdef _DEBUG + m_bFRESNEL = true; +#endif + } + void SetFRESNEL( bool i ) + { + m_nFRESNEL = i ? 1 : 0; +#ifdef _DEBUG + m_bFRESNEL = true; +#endif + } +private: + int m_nBLEND; +#ifdef _DEBUG + bool m_bBLEND; +#endif +public: + void SetBLEND( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBLEND = i; +#ifdef _DEBUG + m_bBLEND = true; +#endif + } + void SetBLEND( bool i ) + { + m_nBLEND = i ? 1 : 0; +#ifdef _DEBUG + m_bBLEND = true; +#endif + } +private: + int m_nREFRACTALPHA; +#ifdef _DEBUG + bool m_bREFRACTALPHA; +#endif +public: + void SetREFRACTALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nREFRACTALPHA = i; +#ifdef _DEBUG + m_bREFRACTALPHA = true; +#endif + } + void SetREFRACTALPHA( bool i ) + { + m_nREFRACTALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bREFRACTALPHA = true; +#endif + } +private: + int m_nHDRTYPE; +#ifdef _DEBUG + bool m_bHDRTYPE; +#endif +public: + void SetHDRTYPE( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nHDRTYPE = i; +#ifdef _DEBUG + m_bHDRTYPE = true; +#endif + } + void SetHDRTYPE( bool i ) + { + m_nHDRTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bHDRTYPE = true; +#endif + } +private: + int m_nNORMAL_DECODE_MODE; +#ifdef _DEBUG + bool m_bNORMAL_DECODE_MODE; +#endif +public: + void SetNORMAL_DECODE_MODE( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nNORMAL_DECODE_MODE = i; +#ifdef _DEBUG + m_bNORMAL_DECODE_MODE = true; +#endif + } + void SetNORMAL_DECODE_MODE( bool i ) + { + m_nNORMAL_DECODE_MODE = i ? 1 : 0; +#ifdef _DEBUG + m_bNORMAL_DECODE_MODE = true; +#endif + } +public: + watercheap_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bMULTITEXTURE = false; +#endif // _DEBUG + m_nMULTITEXTURE = 0; +#ifdef _DEBUG + m_bFRESNEL = false; +#endif // _DEBUG + m_nFRESNEL = 0; +#ifdef _DEBUG + m_bBLEND = false; +#endif // _DEBUG + m_nBLEND = 0; +#ifdef _DEBUG + m_bREFRACTALPHA = false; +#endif // _DEBUG + m_nREFRACTALPHA = 0; +#ifdef _DEBUG + m_bHDRTYPE = false; +#endif // _DEBUG + m_nHDRTYPE = 0; +#ifdef _DEBUG + m_bNORMAL_DECODE_MODE = false; +#endif // _DEBUG + m_nNORMAL_DECODE_MODE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bMULTITEXTURE && m_bFRESNEL && m_bBLEND && m_bREFRACTALPHA && m_bHDRTYPE && m_bNORMAL_DECODE_MODE; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 4 * m_nMULTITEXTURE ) + ( 8 * m_nFRESNEL ) + ( 16 * m_nBLEND ) + ( 32 * m_nREFRACTALPHA ) + ( 64 * m_nHDRTYPE ) + ( 192 * m_nNORMAL_DECODE_MODE ) + 0; + } +}; +#define shaderStaticTest_watercheap_ps20 psh_forgot_to_set_static_MULTITEXTURE + psh_forgot_to_set_static_FRESNEL + psh_forgot_to_set_static_BLEND + psh_forgot_to_set_static_REFRACTALPHA + psh_forgot_to_set_static_HDRTYPE + psh_forgot_to_set_static_NORMAL_DECODE_MODE + 0 +class watercheap_ps20_Dynamic_Index +{ +private: + int m_nHDRENABLED; +#ifdef _DEBUG + bool m_bHDRENABLED; +#endif +public: + void SetHDRENABLED( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHDRENABLED = i; +#ifdef _DEBUG + m_bHDRENABLED = true; +#endif + } + void SetHDRENABLED( bool i ) + { + m_nHDRENABLED = i ? 1 : 0; +#ifdef _DEBUG + m_bHDRENABLED = true; +#endif + } +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + watercheap_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bHDRENABLED = false; +#endif // _DEBUG + m_nHDRENABLED = 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bHDRENABLED && m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nHDRENABLED ) + ( 2 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_watercheap_ps20 psh_forgot_to_set_dynamic_HDRENABLED + psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9/WaterCheap_ps20b.inc b/materialsystem/stdshaders/fxctmp9/WaterCheap_ps20b.inc new file mode 100644 index 0000000..0b51581 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/WaterCheap_ps20b.inc @@ -0,0 +1,262 @@ +#include "shaderlib/cshader.h" +class watercheap_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +private: + int m_nMULTITEXTURE; +#ifdef _DEBUG + bool m_bMULTITEXTURE; +#endif +public: + void SetMULTITEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nMULTITEXTURE = i; +#ifdef _DEBUG + m_bMULTITEXTURE = true; +#endif + } + void SetMULTITEXTURE( bool i ) + { + m_nMULTITEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bMULTITEXTURE = true; +#endif + } +private: + int m_nFRESNEL; +#ifdef _DEBUG + bool m_bFRESNEL; +#endif +public: + void SetFRESNEL( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFRESNEL = i; +#ifdef _DEBUG + m_bFRESNEL = true; +#endif + } + void SetFRESNEL( bool i ) + { + m_nFRESNEL = i ? 1 : 0; +#ifdef _DEBUG + m_bFRESNEL = true; +#endif + } +private: + int m_nBLEND; +#ifdef _DEBUG + bool m_bBLEND; +#endif +public: + void SetBLEND( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBLEND = i; +#ifdef _DEBUG + m_bBLEND = true; +#endif + } + void SetBLEND( bool i ) + { + m_nBLEND = i ? 1 : 0; +#ifdef _DEBUG + m_bBLEND = true; +#endif + } +private: + int m_nREFRACTALPHA; +#ifdef _DEBUG + bool m_bREFRACTALPHA; +#endif +public: + void SetREFRACTALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nREFRACTALPHA = i; +#ifdef _DEBUG + m_bREFRACTALPHA = true; +#endif + } + void SetREFRACTALPHA( bool i ) + { + m_nREFRACTALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bREFRACTALPHA = true; +#endif + } +private: + int m_nHDRTYPE; +#ifdef _DEBUG + bool m_bHDRTYPE; +#endif +public: + void SetHDRTYPE( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nHDRTYPE = i; +#ifdef _DEBUG + m_bHDRTYPE = true; +#endif + } + void SetHDRTYPE( bool i ) + { + m_nHDRTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bHDRTYPE = true; +#endif + } +private: + int m_nNORMAL_DECODE_MODE; +#ifdef _DEBUG + bool m_bNORMAL_DECODE_MODE; +#endif +public: + void SetNORMAL_DECODE_MODE( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nNORMAL_DECODE_MODE = i; +#ifdef _DEBUG + m_bNORMAL_DECODE_MODE = true; +#endif + } + void SetNORMAL_DECODE_MODE( bool i ) + { + m_nNORMAL_DECODE_MODE = i ? 1 : 0; +#ifdef _DEBUG + m_bNORMAL_DECODE_MODE = true; +#endif + } +public: + watercheap_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); +#ifdef _DEBUG + m_bMULTITEXTURE = false; +#endif // _DEBUG + m_nMULTITEXTURE = 0; +#ifdef _DEBUG + m_bFRESNEL = false; +#endif // _DEBUG + m_nFRESNEL = 0; +#ifdef _DEBUG + m_bBLEND = false; +#endif // _DEBUG + m_nBLEND = 0; +#ifdef _DEBUG + m_bREFRACTALPHA = false; +#endif // _DEBUG + m_nREFRACTALPHA = 0; +#ifdef _DEBUG + m_bHDRTYPE = false; +#endif // _DEBUG + m_nHDRTYPE = 0; +#ifdef _DEBUG + m_bNORMAL_DECODE_MODE = false; +#endif // _DEBUG + m_nNORMAL_DECODE_MODE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB && m_bMULTITEXTURE && m_bFRESNEL && m_bBLEND && m_bREFRACTALPHA && m_bHDRTYPE && m_bNORMAL_DECODE_MODE; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 4 * m_nCONVERT_TO_SRGB ) + ( 8 * m_nMULTITEXTURE ) + ( 16 * m_nFRESNEL ) + ( 32 * m_nBLEND ) + ( 64 * m_nREFRACTALPHA ) + ( 128 * m_nHDRTYPE ) + ( 384 * m_nNORMAL_DECODE_MODE ) + 0; + } +}; +#define shaderStaticTest_watercheap_ps20b psh_forgot_to_set_static_MULTITEXTURE + psh_forgot_to_set_static_FRESNEL + psh_forgot_to_set_static_BLEND + psh_forgot_to_set_static_REFRACTALPHA + psh_forgot_to_set_static_HDRTYPE + psh_forgot_to_set_static_NORMAL_DECODE_MODE + 0 +class watercheap_ps20b_Dynamic_Index +{ +private: + int m_nHDRENABLED; +#ifdef _DEBUG + bool m_bHDRENABLED; +#endif +public: + void SetHDRENABLED( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHDRENABLED = i; +#ifdef _DEBUG + m_bHDRENABLED = true; +#endif + } + void SetHDRENABLED( bool i ) + { + m_nHDRENABLED = i ? 1 : 0; +#ifdef _DEBUG + m_bHDRENABLED = true; +#endif + } +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + watercheap_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bHDRENABLED = false; +#endif // _DEBUG + m_nHDRENABLED = 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bHDRENABLED && m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nHDRENABLED ) + ( 2 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_watercheap_ps20b psh_forgot_to_set_dynamic_HDRENABLED + psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9/WaterCheap_vs20.inc b/materialsystem/stdshaders/fxctmp9/WaterCheap_vs20.inc new file mode 100644 index 0000000..fec9108 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/WaterCheap_vs20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class watercheap_vs20_Static_Index +{ +private: + int m_nBLEND; +#ifdef _DEBUG + bool m_bBLEND; +#endif +public: + void SetBLEND( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBLEND = i; +#ifdef _DEBUG + m_bBLEND = true; +#endif + } + void SetBLEND( bool i ) + { + m_nBLEND = i ? 1 : 0; +#ifdef _DEBUG + m_bBLEND = true; +#endif + } +public: + watercheap_vs20_Static_Index( ) + { +#ifdef _DEBUG + m_bBLEND = false; +#endif // _DEBUG + m_nBLEND = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bBLEND; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nBLEND ) + 0; + } +}; +#define shaderStaticTest_watercheap_vs20 vsh_forgot_to_set_static_BLEND + 0 +class watercheap_vs20_Dynamic_Index +{ +public: + watercheap_vs20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_watercheap_vs20 0 diff --git a/materialsystem/stdshaders/fxctmp9/Water_ps20.inc b/materialsystem/stdshaders/fxctmp9/Water_ps20.inc new file mode 100644 index 0000000..e67bfdb --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/Water_ps20.inc @@ -0,0 +1,212 @@ +#include "shaderlib/cshader.h" +class water_ps20_Static_Index +{ +private: + int m_nBASETEXTURE; +#ifdef _DEBUG + bool m_bBASETEXTURE; +#endif +public: + void SetBASETEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBASETEXTURE = i; +#ifdef _DEBUG + m_bBASETEXTURE = true; +#endif + } + void SetBASETEXTURE( bool i ) + { + m_nBASETEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bBASETEXTURE = true; +#endif + } +private: + int m_nMULTITEXTURE; +#ifdef _DEBUG + bool m_bMULTITEXTURE; +#endif +public: + void SetMULTITEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nMULTITEXTURE = i; +#ifdef _DEBUG + m_bMULTITEXTURE = true; +#endif + } + void SetMULTITEXTURE( bool i ) + { + m_nMULTITEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bMULTITEXTURE = true; +#endif + } +private: + int m_nREFLECT; +#ifdef _DEBUG + bool m_bREFLECT; +#endif +public: + void SetREFLECT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nREFLECT = i; +#ifdef _DEBUG + m_bREFLECT = true; +#endif + } + void SetREFLECT( bool i ) + { + m_nREFLECT = i ? 1 : 0; +#ifdef _DEBUG + m_bREFLECT = true; +#endif + } +private: + int m_nREFRACT; +#ifdef _DEBUG + bool m_bREFRACT; +#endif +public: + void SetREFRACT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nREFRACT = i; +#ifdef _DEBUG + m_bREFRACT = true; +#endif + } + void SetREFRACT( bool i ) + { + m_nREFRACT = i ? 1 : 0; +#ifdef _DEBUG + m_bREFRACT = true; +#endif + } +private: + int m_nABOVEWATER; +#ifdef _DEBUG + bool m_bABOVEWATER; +#endif +public: + void SetABOVEWATER( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nABOVEWATER = i; +#ifdef _DEBUG + m_bABOVEWATER = true; +#endif + } + void SetABOVEWATER( bool i ) + { + m_nABOVEWATER = i ? 1 : 0; +#ifdef _DEBUG + m_bABOVEWATER = true; +#endif + } +private: + int m_nNORMAL_DECODE_MODE; +#ifdef _DEBUG + bool m_bNORMAL_DECODE_MODE; +#endif +public: + void SetNORMAL_DECODE_MODE( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nNORMAL_DECODE_MODE = i; +#ifdef _DEBUG + m_bNORMAL_DECODE_MODE = true; +#endif + } + void SetNORMAL_DECODE_MODE( bool i ) + { + m_nNORMAL_DECODE_MODE = i ? 1 : 0; +#ifdef _DEBUG + m_bNORMAL_DECODE_MODE = true; +#endif + } +public: + water_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bBASETEXTURE = false; +#endif // _DEBUG + m_nBASETEXTURE = 0; +#ifdef _DEBUG + m_bMULTITEXTURE = false; +#endif // _DEBUG + m_nMULTITEXTURE = 0; +#ifdef _DEBUG + m_bREFLECT = false; +#endif // _DEBUG + m_nREFLECT = 0; +#ifdef _DEBUG + m_bREFRACT = false; +#endif // _DEBUG + m_nREFRACT = 0; +#ifdef _DEBUG + m_bABOVEWATER = false; +#endif // _DEBUG + m_nABOVEWATER = 0; +#ifdef _DEBUG + m_bNORMAL_DECODE_MODE = false; +#endif // _DEBUG + m_nNORMAL_DECODE_MODE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bBASETEXTURE && m_bMULTITEXTURE && m_bREFLECT && m_bREFRACT && m_bABOVEWATER && m_bNORMAL_DECODE_MODE; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nBASETEXTURE ) + ( 4 * m_nMULTITEXTURE ) + ( 8 * m_nREFLECT ) + ( 16 * m_nREFRACT ) + ( 32 * m_nABOVEWATER ) + ( 64 * m_nNORMAL_DECODE_MODE ) + 0; + } +}; +#define shaderStaticTest_water_ps20 psh_forgot_to_set_static_BASETEXTURE + psh_forgot_to_set_static_MULTITEXTURE + psh_forgot_to_set_static_REFLECT + psh_forgot_to_set_static_REFRACT + psh_forgot_to_set_static_ABOVEWATER + psh_forgot_to_set_static_NORMAL_DECODE_MODE + 0 +class water_ps20_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + water_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_water_ps20 psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9/Water_vs20.inc b/materialsystem/stdshaders/fxctmp9/Water_vs20.inc new file mode 100644 index 0000000..4f31b04 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/Water_vs20.inc @@ -0,0 +1,85 @@ +#include "shaderlib/cshader.h" +class water_vs20_Static_Index +{ +private: + int m_nBASETEXTURE; +#ifdef _DEBUG + bool m_bBASETEXTURE; +#endif +public: + void SetBASETEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBASETEXTURE = i; +#ifdef _DEBUG + m_bBASETEXTURE = true; +#endif + } + void SetBASETEXTURE( bool i ) + { + m_nBASETEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bBASETEXTURE = true; +#endif + } +private: + int m_nMULTITEXTURE; +#ifdef _DEBUG + bool m_bMULTITEXTURE; +#endif +public: + void SetMULTITEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nMULTITEXTURE = i; +#ifdef _DEBUG + m_bMULTITEXTURE = true; +#endif + } + void SetMULTITEXTURE( bool i ) + { + m_nMULTITEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bMULTITEXTURE = true; +#endif + } +public: + water_vs20_Static_Index( ) + { +#ifdef _DEBUG + m_bBASETEXTURE = false; +#endif // _DEBUG + m_nBASETEXTURE = 0; +#ifdef _DEBUG + m_bMULTITEXTURE = false; +#endif // _DEBUG + m_nMULTITEXTURE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bBASETEXTURE && m_bMULTITEXTURE; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nBASETEXTURE ) + ( 2 * m_nMULTITEXTURE ) + 0; + } +}; +#define shaderStaticTest_water_vs20 vsh_forgot_to_set_static_BASETEXTURE + vsh_forgot_to_set_static_MULTITEXTURE + 0 +class water_vs20_Dynamic_Index +{ +public: + water_vs20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_water_vs20 0 diff --git a/materialsystem/stdshaders/fxctmp9/WorldTwoTextureBlend_ps20.inc b/materialsystem/stdshaders/fxctmp9/WorldTwoTextureBlend_ps20.inc new file mode 100644 index 0000000..5211faf --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/WorldTwoTextureBlend_ps20.inc @@ -0,0 +1,287 @@ +#include "shaderlib/cshader.h" +class worldtwotextureblend_ps20_Static_Index +{ +private: + int m_nDETAILTEXTURE; +#ifdef _DEBUG + bool m_bDETAILTEXTURE; +#endif +public: + void SetDETAILTEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDETAILTEXTURE = i; +#ifdef _DEBUG + m_bDETAILTEXTURE = true; +#endif + } + void SetDETAILTEXTURE( bool i ) + { + m_nDETAILTEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bDETAILTEXTURE = true; +#endif + } +private: + int m_nBUMPMAP; +#ifdef _DEBUG + bool m_bBUMPMAP; +#endif +public: + void SetBUMPMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBUMPMAP = i; +#ifdef _DEBUG + m_bBUMPMAP = true; +#endif + } + void SetBUMPMAP( bool i ) + { + m_nBUMPMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bBUMPMAP = true; +#endif + } +private: + int m_nVERTEXCOLOR; +#ifdef _DEBUG + bool m_bVERTEXCOLOR; +#endif +public: + void SetVERTEXCOLOR( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nVERTEXCOLOR = i; +#ifdef _DEBUG + m_bVERTEXCOLOR = true; +#endif + } + void SetVERTEXCOLOR( bool i ) + { + m_nVERTEXCOLOR = i ? 1 : 0; +#ifdef _DEBUG + m_bVERTEXCOLOR = true; +#endif + } +private: + int m_nSELFILLUM; +#ifdef _DEBUG + bool m_bSELFILLUM; +#endif +public: + void SetSELFILLUM( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSELFILLUM = i; +#ifdef _DEBUG + m_bSELFILLUM = true; +#endif + } + void SetSELFILLUM( bool i ) + { + m_nSELFILLUM = i ? 1 : 0; +#ifdef _DEBUG + m_bSELFILLUM = true; +#endif + } +private: + int m_nDIFFUSEBUMPMAP; +#ifdef _DEBUG + bool m_bDIFFUSEBUMPMAP; +#endif +public: + void SetDIFFUSEBUMPMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDIFFUSEBUMPMAP = i; +#ifdef _DEBUG + m_bDIFFUSEBUMPMAP = true; +#endif + } + void SetDIFFUSEBUMPMAP( bool i ) + { + m_nDIFFUSEBUMPMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bDIFFUSEBUMPMAP = true; +#endif + } +private: + int m_nDETAIL_ALPHA_MASK_BASE_TEXTURE; +#ifdef _DEBUG + bool m_bDETAIL_ALPHA_MASK_BASE_TEXTURE; +#endif +public: + void SetDETAIL_ALPHA_MASK_BASE_TEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDETAIL_ALPHA_MASK_BASE_TEXTURE = i; +#ifdef _DEBUG + m_bDETAIL_ALPHA_MASK_BASE_TEXTURE = true; +#endif + } + void SetDETAIL_ALPHA_MASK_BASE_TEXTURE( bool i ) + { + m_nDETAIL_ALPHA_MASK_BASE_TEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bDETAIL_ALPHA_MASK_BASE_TEXTURE = true; +#endif + } +private: + int m_nFLASHLIGHT; +#ifdef _DEBUG + bool m_bFLASHLIGHT; +#endif +public: + void SetFLASHLIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFLASHLIGHT = i; +#ifdef _DEBUG + m_bFLASHLIGHT = true; +#endif + } + void SetFLASHLIGHT( bool i ) + { + m_nFLASHLIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bFLASHLIGHT = true; +#endif + } +private: + int m_nSEAMLESS; +#ifdef _DEBUG + bool m_bSEAMLESS; +#endif +public: + void SetSEAMLESS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSEAMLESS = i; +#ifdef _DEBUG + m_bSEAMLESS = true; +#endif + } + void SetSEAMLESS( bool i ) + { + m_nSEAMLESS = i ? 1 : 0; +#ifdef _DEBUG + m_bSEAMLESS = true; +#endif + } +public: + worldtwotextureblend_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bDETAILTEXTURE = false; +#endif // _DEBUG + m_nDETAILTEXTURE = 0; +#ifdef _DEBUG + m_bBUMPMAP = false; +#endif // _DEBUG + m_nBUMPMAP = 0; +#ifdef _DEBUG + m_bVERTEXCOLOR = false; +#endif // _DEBUG + m_nVERTEXCOLOR = 0; +#ifdef _DEBUG + m_bSELFILLUM = false; +#endif // _DEBUG + m_nSELFILLUM = 0; +#ifdef _DEBUG + m_bDIFFUSEBUMPMAP = false; +#endif // _DEBUG + m_nDIFFUSEBUMPMAP = 0; +#ifdef _DEBUG + m_bDETAIL_ALPHA_MASK_BASE_TEXTURE = false; +#endif // _DEBUG + m_nDETAIL_ALPHA_MASK_BASE_TEXTURE = 0; +#ifdef _DEBUG + m_bFLASHLIGHT = false; +#endif // _DEBUG + m_nFLASHLIGHT = 0; +#ifdef _DEBUG + m_bSEAMLESS = false; +#endif // _DEBUG + m_nSEAMLESS = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bDETAILTEXTURE && m_bBUMPMAP && m_bVERTEXCOLOR && m_bSELFILLUM && m_bDIFFUSEBUMPMAP && m_bDETAIL_ALPHA_MASK_BASE_TEXTURE && m_bFLASHLIGHT && m_bSEAMLESS; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 4 * m_nDETAILTEXTURE ) + ( 8 * m_nBUMPMAP ) + ( 16 * m_nVERTEXCOLOR ) + ( 32 * m_nSELFILLUM ) + ( 64 * m_nDIFFUSEBUMPMAP ) + ( 128 * m_nDETAIL_ALPHA_MASK_BASE_TEXTURE ) + ( 256 * m_nFLASHLIGHT ) + ( 512 * m_nSEAMLESS ) + 0; + } +}; +#define shaderStaticTest_worldtwotextureblend_ps20 psh_forgot_to_set_static_DETAILTEXTURE + psh_forgot_to_set_static_BUMPMAP + psh_forgot_to_set_static_VERTEXCOLOR + psh_forgot_to_set_static_SELFILLUM + psh_forgot_to_set_static_DIFFUSEBUMPMAP + psh_forgot_to_set_static_DETAIL_ALPHA_MASK_BASE_TEXTURE + psh_forgot_to_set_static_FLASHLIGHT + psh_forgot_to_set_static_SEAMLESS + 0 +class worldtwotextureblend_ps20_Dynamic_Index +{ +private: + int m_nWRITEWATERFOGTODESTALPHA; +#ifdef _DEBUG + bool m_bWRITEWATERFOGTODESTALPHA; +#endif +public: + void SetWRITEWATERFOGTODESTALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nWRITEWATERFOGTODESTALPHA = i; +#ifdef _DEBUG + m_bWRITEWATERFOGTODESTALPHA = true; +#endif + } + void SetWRITEWATERFOGTODESTALPHA( bool i ) + { + m_nWRITEWATERFOGTODESTALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bWRITEWATERFOGTODESTALPHA = true; +#endif + } +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + worldtwotextureblend_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bWRITEWATERFOGTODESTALPHA = false; +#endif // _DEBUG + m_nWRITEWATERFOGTODESTALPHA = 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bWRITEWATERFOGTODESTALPHA && m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nWRITEWATERFOGTODESTALPHA ) + ( 2 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_worldtwotextureblend_ps20 psh_forgot_to_set_dynamic_WRITEWATERFOGTODESTALPHA + psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9/WorldTwoTextureBlend_ps20b.inc b/materialsystem/stdshaders/fxctmp9/WorldTwoTextureBlend_ps20b.inc new file mode 100644 index 0000000..b9d095e --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/WorldTwoTextureBlend_ps20b.inc @@ -0,0 +1,387 @@ +#include "shaderlib/cshader.h" +class worldtwotextureblend_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +private: + int m_nDETAILTEXTURE; +#ifdef _DEBUG + bool m_bDETAILTEXTURE; +#endif +public: + void SetDETAILTEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDETAILTEXTURE = i; +#ifdef _DEBUG + m_bDETAILTEXTURE = true; +#endif + } + void SetDETAILTEXTURE( bool i ) + { + m_nDETAILTEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bDETAILTEXTURE = true; +#endif + } +private: + int m_nBUMPMAP; +#ifdef _DEBUG + bool m_bBUMPMAP; +#endif +public: + void SetBUMPMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBUMPMAP = i; +#ifdef _DEBUG + m_bBUMPMAP = true; +#endif + } + void SetBUMPMAP( bool i ) + { + m_nBUMPMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bBUMPMAP = true; +#endif + } +private: + int m_nVERTEXCOLOR; +#ifdef _DEBUG + bool m_bVERTEXCOLOR; +#endif +public: + void SetVERTEXCOLOR( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nVERTEXCOLOR = i; +#ifdef _DEBUG + m_bVERTEXCOLOR = true; +#endif + } + void SetVERTEXCOLOR( bool i ) + { + m_nVERTEXCOLOR = i ? 1 : 0; +#ifdef _DEBUG + m_bVERTEXCOLOR = true; +#endif + } +private: + int m_nSELFILLUM; +#ifdef _DEBUG + bool m_bSELFILLUM; +#endif +public: + void SetSELFILLUM( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSELFILLUM = i; +#ifdef _DEBUG + m_bSELFILLUM = true; +#endif + } + void SetSELFILLUM( bool i ) + { + m_nSELFILLUM = i ? 1 : 0; +#ifdef _DEBUG + m_bSELFILLUM = true; +#endif + } +private: + int m_nDIFFUSEBUMPMAP; +#ifdef _DEBUG + bool m_bDIFFUSEBUMPMAP; +#endif +public: + void SetDIFFUSEBUMPMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDIFFUSEBUMPMAP = i; +#ifdef _DEBUG + m_bDIFFUSEBUMPMAP = true; +#endif + } + void SetDIFFUSEBUMPMAP( bool i ) + { + m_nDIFFUSEBUMPMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bDIFFUSEBUMPMAP = true; +#endif + } +private: + int m_nDETAIL_ALPHA_MASK_BASE_TEXTURE; +#ifdef _DEBUG + bool m_bDETAIL_ALPHA_MASK_BASE_TEXTURE; +#endif +public: + void SetDETAIL_ALPHA_MASK_BASE_TEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDETAIL_ALPHA_MASK_BASE_TEXTURE = i; +#ifdef _DEBUG + m_bDETAIL_ALPHA_MASK_BASE_TEXTURE = true; +#endif + } + void SetDETAIL_ALPHA_MASK_BASE_TEXTURE( bool i ) + { + m_nDETAIL_ALPHA_MASK_BASE_TEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bDETAIL_ALPHA_MASK_BASE_TEXTURE = true; +#endif + } +private: + int m_nFLASHLIGHT; +#ifdef _DEBUG + bool m_bFLASHLIGHT; +#endif +public: + void SetFLASHLIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFLASHLIGHT = i; +#ifdef _DEBUG + m_bFLASHLIGHT = true; +#endif + } + void SetFLASHLIGHT( bool i ) + { + m_nFLASHLIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bFLASHLIGHT = true; +#endif + } +private: + int m_nSEAMLESS; +#ifdef _DEBUG + bool m_bSEAMLESS; +#endif +public: + void SetSEAMLESS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSEAMLESS = i; +#ifdef _DEBUG + m_bSEAMLESS = true; +#endif + } + void SetSEAMLESS( bool i ) + { + m_nSEAMLESS = i ? 1 : 0; +#ifdef _DEBUG + m_bSEAMLESS = true; +#endif + } +private: + int m_nFLASHLIGHTDEPTHFILTERMODE; +#ifdef _DEBUG + bool m_bFLASHLIGHTDEPTHFILTERMODE; +#endif +public: + void SetFLASHLIGHTDEPTHFILTERMODE( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nFLASHLIGHTDEPTHFILTERMODE = i; +#ifdef _DEBUG + m_bFLASHLIGHTDEPTHFILTERMODE = true; +#endif + } + void SetFLASHLIGHTDEPTHFILTERMODE( bool i ) + { + m_nFLASHLIGHTDEPTHFILTERMODE = i ? 1 : 0; +#ifdef _DEBUG + m_bFLASHLIGHTDEPTHFILTERMODE = true; +#endif + } +public: + worldtwotextureblend_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); +#ifdef _DEBUG + m_bDETAILTEXTURE = false; +#endif // _DEBUG + m_nDETAILTEXTURE = 0; +#ifdef _DEBUG + m_bBUMPMAP = false; +#endif // _DEBUG + m_nBUMPMAP = 0; +#ifdef _DEBUG + m_bVERTEXCOLOR = false; +#endif // _DEBUG + m_nVERTEXCOLOR = 0; +#ifdef _DEBUG + m_bSELFILLUM = false; +#endif // _DEBUG + m_nSELFILLUM = 0; +#ifdef _DEBUG + m_bDIFFUSEBUMPMAP = false; +#endif // _DEBUG + m_nDIFFUSEBUMPMAP = 0; +#ifdef _DEBUG + m_bDETAIL_ALPHA_MASK_BASE_TEXTURE = false; +#endif // _DEBUG + m_nDETAIL_ALPHA_MASK_BASE_TEXTURE = 0; +#ifdef _DEBUG + m_bFLASHLIGHT = false; +#endif // _DEBUG + m_nFLASHLIGHT = 0; +#ifdef _DEBUG + m_bSEAMLESS = false; +#endif // _DEBUG + m_nSEAMLESS = 0; +#ifdef _DEBUG + m_bFLASHLIGHTDEPTHFILTERMODE = false; +#endif // _DEBUG + m_nFLASHLIGHTDEPTHFILTERMODE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB && m_bDETAILTEXTURE && m_bBUMPMAP && m_bVERTEXCOLOR && m_bSELFILLUM && m_bDIFFUSEBUMPMAP && m_bDETAIL_ALPHA_MASK_BASE_TEXTURE && m_bFLASHLIGHT && m_bSEAMLESS && m_bFLASHLIGHTDEPTHFILTERMODE; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 16 * m_nCONVERT_TO_SRGB ) + ( 32 * m_nDETAILTEXTURE ) + ( 64 * m_nBUMPMAP ) + ( 128 * m_nVERTEXCOLOR ) + ( 256 * m_nSELFILLUM ) + ( 512 * m_nDIFFUSEBUMPMAP ) + ( 1024 * m_nDETAIL_ALPHA_MASK_BASE_TEXTURE ) + ( 2048 * m_nFLASHLIGHT ) + ( 4096 * m_nSEAMLESS ) + ( 8192 * m_nFLASHLIGHTDEPTHFILTERMODE ) + 0; + } +}; +#define shaderStaticTest_worldtwotextureblend_ps20b psh_forgot_to_set_static_DETAILTEXTURE + psh_forgot_to_set_static_BUMPMAP + psh_forgot_to_set_static_VERTEXCOLOR + psh_forgot_to_set_static_SELFILLUM + psh_forgot_to_set_static_DIFFUSEBUMPMAP + psh_forgot_to_set_static_DETAIL_ALPHA_MASK_BASE_TEXTURE + psh_forgot_to_set_static_FLASHLIGHT + psh_forgot_to_set_static_SEAMLESS + psh_forgot_to_set_static_FLASHLIGHTDEPTHFILTERMODE + 0 +class worldtwotextureblend_ps20b_Dynamic_Index +{ +private: + int m_nWRITEWATERFOGTODESTALPHA; +#ifdef _DEBUG + bool m_bWRITEWATERFOGTODESTALPHA; +#endif +public: + void SetWRITEWATERFOGTODESTALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nWRITEWATERFOGTODESTALPHA = i; +#ifdef _DEBUG + m_bWRITEWATERFOGTODESTALPHA = true; +#endif + } + void SetWRITEWATERFOGTODESTALPHA( bool i ) + { + m_nWRITEWATERFOGTODESTALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bWRITEWATERFOGTODESTALPHA = true; +#endif + } +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +private: + int m_nWRITE_DEPTH_TO_DESTALPHA; +#ifdef _DEBUG + bool m_bWRITE_DEPTH_TO_DESTALPHA; +#endif +public: + void SetWRITE_DEPTH_TO_DESTALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nWRITE_DEPTH_TO_DESTALPHA = i; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = true; +#endif + } + void SetWRITE_DEPTH_TO_DESTALPHA( bool i ) + { + m_nWRITE_DEPTH_TO_DESTALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = true; +#endif + } +private: + int m_nFLASHLIGHTSHADOWS; +#ifdef _DEBUG + bool m_bFLASHLIGHTSHADOWS; +#endif +public: + void SetFLASHLIGHTSHADOWS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFLASHLIGHTSHADOWS = i; +#ifdef _DEBUG + m_bFLASHLIGHTSHADOWS = true; +#endif + } + void SetFLASHLIGHTSHADOWS( bool i ) + { + m_nFLASHLIGHTSHADOWS = i ? 1 : 0; +#ifdef _DEBUG + m_bFLASHLIGHTSHADOWS = true; +#endif + } +public: + worldtwotextureblend_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bWRITEWATERFOGTODESTALPHA = false; +#endif // _DEBUG + m_nWRITEWATERFOGTODESTALPHA = 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = false; +#endif // _DEBUG + m_nWRITE_DEPTH_TO_DESTALPHA = 0; +#ifdef _DEBUG + m_bFLASHLIGHTSHADOWS = false; +#endif // _DEBUG + m_nFLASHLIGHTSHADOWS = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bWRITEWATERFOGTODESTALPHA && m_bPIXELFOGTYPE && m_bWRITE_DEPTH_TO_DESTALPHA && m_bFLASHLIGHTSHADOWS; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nWRITEWATERFOGTODESTALPHA ) + ( 2 * m_nPIXELFOGTYPE ) + ( 4 * m_nWRITE_DEPTH_TO_DESTALPHA ) + ( 8 * m_nFLASHLIGHTSHADOWS ) + 0; + } +}; +#define shaderDynamicTest_worldtwotextureblend_ps20b psh_forgot_to_set_dynamic_WRITEWATERFOGTODESTALPHA + psh_forgot_to_set_dynamic_PIXELFOGTYPE + psh_forgot_to_set_dynamic_WRITE_DEPTH_TO_DESTALPHA + psh_forgot_to_set_dynamic_FLASHLIGHTSHADOWS + 0 diff --git a/materialsystem/stdshaders/fxctmp9/accumbuff4sample_ps20.inc b/materialsystem/stdshaders/fxctmp9/accumbuff4sample_ps20.inc new file mode 100644 index 0000000..cacf59b --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/accumbuff4sample_ps20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class accumbuff4sample_ps20_Static_Index +{ +public: + accumbuff4sample_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_accumbuff4sample_ps20 0 +class accumbuff4sample_ps20_Dynamic_Index +{ +public: + accumbuff4sample_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_accumbuff4sample_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9/accumbuff4sample_ps20b.inc b/materialsystem/stdshaders/fxctmp9/accumbuff4sample_ps20b.inc new file mode 100644 index 0000000..716ea9a --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/accumbuff4sample_ps20b.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class accumbuff4sample_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + accumbuff4sample_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_accumbuff4sample_ps20b 0 +class accumbuff4sample_ps20b_Dynamic_Index +{ +public: + accumbuff4sample_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_accumbuff4sample_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9/accumbuff5sample_ps20.inc b/materialsystem/stdshaders/fxctmp9/accumbuff5sample_ps20.inc new file mode 100644 index 0000000..9090398 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/accumbuff5sample_ps20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class accumbuff5sample_ps20_Static_Index +{ +public: + accumbuff5sample_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_accumbuff5sample_ps20 0 +class accumbuff5sample_ps20_Dynamic_Index +{ +public: + accumbuff5sample_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_accumbuff5sample_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9/accumbuff5sample_ps20b.inc b/materialsystem/stdshaders/fxctmp9/accumbuff5sample_ps20b.inc new file mode 100644 index 0000000..fd14c0a --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/accumbuff5sample_ps20b.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class accumbuff5sample_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + accumbuff5sample_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_accumbuff5sample_ps20b 0 +class accumbuff5sample_ps20b_Dynamic_Index +{ +public: + accumbuff5sample_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_accumbuff5sample_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9/aftershock_ps20.inc b/materialsystem/stdshaders/fxctmp9/aftershock_ps20.inc new file mode 100644 index 0000000..5e737ba --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/aftershock_ps20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class aftershock_ps20_Static_Index +{ +public: + aftershock_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_aftershock_ps20 0 +class aftershock_ps20_Dynamic_Index +{ +public: + aftershock_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_aftershock_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9/aftershock_ps20b.inc b/materialsystem/stdshaders/fxctmp9/aftershock_ps20b.inc new file mode 100644 index 0000000..8e3b442 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/aftershock_ps20b.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class aftershock_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + aftershock_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_aftershock_ps20b 0 +class aftershock_ps20b_Dynamic_Index +{ +public: + aftershock_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_aftershock_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9/aftershock_vs20.inc b/materialsystem/stdshaders/fxctmp9/aftershock_vs20.inc new file mode 100644 index 0000000..9461ece --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/aftershock_vs20.inc @@ -0,0 +1,85 @@ +#include "shaderlib/cshader.h" +class aftershock_vs20_Static_Index +{ +public: + aftershock_vs20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_aftershock_vs20 0 +class aftershock_vs20_Dynamic_Index +{ +private: + int m_nCOMPRESSED_VERTS; +#ifdef _DEBUG + bool m_bCOMPRESSED_VERTS; +#endif +public: + void SetCOMPRESSED_VERTS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOMPRESSED_VERTS = i; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } + void SetCOMPRESSED_VERTS( bool i ) + { + m_nCOMPRESSED_VERTS = i ? 1 : 0; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +public: + aftershock_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = false; +#endif // _DEBUG + m_nCOMPRESSED_VERTS = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bCOMPRESSED_VERTS && m_bSKINNING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCOMPRESSED_VERTS ) + ( 2 * m_nSKINNING ) + 0; + } +}; +#define shaderDynamicTest_aftershock_vs20 vsh_forgot_to_set_dynamic_COMPRESSED_VERTS + vsh_forgot_to_set_dynamic_SKINNING + 0 diff --git a/materialsystem/stdshaders/fxctmp9/alphadist_ps11.inc b/materialsystem/stdshaders/fxctmp9/alphadist_ps11.inc new file mode 100644 index 0000000..5ee1d3e --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/alphadist_ps11.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class alphadist_ps11_Static_Index +{ +public: + alphadist_ps11_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_alphadist_ps11 0 +class alphadist_ps11_Dynamic_Index +{ +public: + alphadist_ps11_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_alphadist_ps11 0 diff --git a/materialsystem/stdshaders/fxctmp9/appchooser360movie_ps20.inc b/materialsystem/stdshaders/fxctmp9/appchooser360movie_ps20.inc new file mode 100644 index 0000000..2f10670 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/appchooser360movie_ps20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class appchooser360movie_ps20_Static_Index +{ +public: + appchooser360movie_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_appchooser360movie_ps20 0 +class appchooser360movie_ps20_Dynamic_Index +{ +public: + appchooser360movie_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_appchooser360movie_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9/appchooser360movie_ps20b.inc b/materialsystem/stdshaders/fxctmp9/appchooser360movie_ps20b.inc new file mode 100644 index 0000000..41ab35e --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/appchooser360movie_ps20b.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class appchooser360movie_ps20b_Static_Index +{ +public: + appchooser360movie_ps20b_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_appchooser360movie_ps20b 0 +class appchooser360movie_ps20b_Dynamic_Index +{ +public: + appchooser360movie_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_appchooser360movie_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9/bik_ps20.inc b/materialsystem/stdshaders/fxctmp9/bik_ps20.inc new file mode 100644 index 0000000..278f10b --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/bik_ps20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class bik_ps20_Static_Index +{ +public: + bik_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_bik_ps20 0 +class bik_ps20_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + bik_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_bik_ps20 psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9/bik_ps20b.inc b/materialsystem/stdshaders/fxctmp9/bik_ps20b.inc new file mode 100644 index 0000000..e5359e3 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/bik_ps20b.inc @@ -0,0 +1,87 @@ +#include "shaderlib/cshader.h" +class bik_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + bik_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_bik_ps20b 0 +class bik_ps20b_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + bik_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_bik_ps20b psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9/bik_vs20.inc b/materialsystem/stdshaders/fxctmp9/bik_vs20.inc new file mode 100644 index 0000000..1c1673a --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/bik_vs20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class bik_vs20_Static_Index +{ +public: + bik_vs20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_bik_vs20 0 +class bik_vs20_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + bik_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; +#define shaderDynamicTest_bik_vs20 vsh_forgot_to_set_dynamic_DOWATERFOG + 0 diff --git a/materialsystem/stdshaders/fxctmp9/bloomadd_ps11.inc b/materialsystem/stdshaders/fxctmp9/bloomadd_ps11.inc new file mode 100644 index 0000000..5452dee --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/bloomadd_ps11.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class bloomadd_ps11_Static_Index +{ +public: + bloomadd_ps11_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_bloomadd_ps11 0 +class bloomadd_ps11_Dynamic_Index +{ +public: + bloomadd_ps11_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_bloomadd_ps11 0 diff --git a/materialsystem/stdshaders/fxctmp9/bloomadd_ps20.inc b/materialsystem/stdshaders/fxctmp9/bloomadd_ps20.inc new file mode 100644 index 0000000..031c6dd --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/bloomadd_ps20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class bloomadd_ps20_Static_Index +{ +public: + bloomadd_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_bloomadd_ps20 0 +class bloomadd_ps20_Dynamic_Index +{ +public: + bloomadd_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_bloomadd_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9/bloomadd_ps20b.inc b/materialsystem/stdshaders/fxctmp9/bloomadd_ps20b.inc new file mode 100644 index 0000000..686a62e --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/bloomadd_ps20b.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class bloomadd_ps20b_Static_Index +{ +public: + bloomadd_ps20b_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_bloomadd_ps20b 0 +class bloomadd_ps20b_Dynamic_Index +{ +public: + bloomadd_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_bloomadd_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9/bufferclearobeystencil_ps20.inc b/materialsystem/stdshaders/fxctmp9/bufferclearobeystencil_ps20.inc new file mode 100644 index 0000000..16b3f05 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/bufferclearobeystencil_ps20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class bufferclearobeystencil_ps20_Static_Index +{ +public: + bufferclearobeystencil_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_bufferclearobeystencil_ps20 0 +class bufferclearobeystencil_ps20_Dynamic_Index +{ +public: + bufferclearobeystencil_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_bufferclearobeystencil_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9/bufferclearobeystencil_ps20b.inc b/materialsystem/stdshaders/fxctmp9/bufferclearobeystencil_ps20b.inc new file mode 100644 index 0000000..09541a4 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/bufferclearobeystencil_ps20b.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class bufferclearobeystencil_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + bufferclearobeystencil_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_bufferclearobeystencil_ps20b 0 +class bufferclearobeystencil_ps20b_Dynamic_Index +{ +public: + bufferclearobeystencil_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_bufferclearobeystencil_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9/bufferclearobeystencil_vs20.inc b/materialsystem/stdshaders/fxctmp9/bufferclearobeystencil_vs20.inc new file mode 100644 index 0000000..ca2e245 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/bufferclearobeystencil_vs20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class bufferclearobeystencil_vs20_Static_Index +{ +private: + int m_nUSESCOLOR; +#ifdef _DEBUG + bool m_bUSESCOLOR; +#endif +public: + void SetUSESCOLOR( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nUSESCOLOR = i; +#ifdef _DEBUG + m_bUSESCOLOR = true; +#endif + } + void SetUSESCOLOR( bool i ) + { + m_nUSESCOLOR = i ? 1 : 0; +#ifdef _DEBUG + m_bUSESCOLOR = true; +#endif + } +public: + bufferclearobeystencil_vs20_Static_Index( ) + { +#ifdef _DEBUG + m_bUSESCOLOR = false; +#endif // _DEBUG + m_nUSESCOLOR = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bUSESCOLOR; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nUSESCOLOR ) + 0; + } +}; +#define shaderStaticTest_bufferclearobeystencil_vs20 vsh_forgot_to_set_static_USESCOLOR + 0 +class bufferclearobeystencil_vs20_Dynamic_Index +{ +public: + bufferclearobeystencil_vs20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_bufferclearobeystencil_vs20 0 diff --git a/materialsystem/stdshaders/fxctmp9/bumpmappedlightmap_vs11.inc b/materialsystem/stdshaders/fxctmp9/bumpmappedlightmap_vs11.inc new file mode 100644 index 0000000..0b7b8bb --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/bumpmappedlightmap_vs11.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class bumpmappedlightmap_vs11_Static_Index +{ +public: + bumpmappedlightmap_vs11_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_bumpmappedlightmap_vs11 0 +class bumpmappedlightmap_vs11_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + bumpmappedlightmap_vs11_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; +#define shaderDynamicTest_bumpmappedlightmap_vs11 vsh_forgot_to_set_dynamic_DOWATERFOG + 0 diff --git a/materialsystem/stdshaders/fxctmp9/cable_ps20.inc b/materialsystem/stdshaders/fxctmp9/cable_ps20.inc new file mode 100644 index 0000000..e52b5fc --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/cable_ps20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class cable_ps20_Static_Index +{ +public: + cable_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_cable_ps20 0 +class cable_ps20_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + cable_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_cable_ps20 psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9/cable_ps20b.inc b/materialsystem/stdshaders/fxctmp9/cable_ps20b.inc new file mode 100644 index 0000000..0f07ba7 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/cable_ps20b.inc @@ -0,0 +1,112 @@ +#include "shaderlib/cshader.h" +class cable_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + cable_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 4 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_cable_ps20b 0 +class cable_ps20b_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +private: + int m_nWRITE_DEPTH_TO_DESTALPHA; +#ifdef _DEBUG + bool m_bWRITE_DEPTH_TO_DESTALPHA; +#endif +public: + void SetWRITE_DEPTH_TO_DESTALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nWRITE_DEPTH_TO_DESTALPHA = i; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = true; +#endif + } + void SetWRITE_DEPTH_TO_DESTALPHA( bool i ) + { + m_nWRITE_DEPTH_TO_DESTALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = true; +#endif + } +public: + cable_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = false; +#endif // _DEBUG + m_nWRITE_DEPTH_TO_DESTALPHA = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE && m_bWRITE_DEPTH_TO_DESTALPHA; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + ( 2 * m_nWRITE_DEPTH_TO_DESTALPHA ) + 0; + } +}; +#define shaderDynamicTest_cable_ps20b psh_forgot_to_set_dynamic_PIXELFOGTYPE + psh_forgot_to_set_dynamic_WRITE_DEPTH_TO_DESTALPHA + 0 diff --git a/materialsystem/stdshaders/fxctmp9/cable_vs20.inc b/materialsystem/stdshaders/fxctmp9/cable_vs20.inc new file mode 100644 index 0000000..832a15e --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/cable_vs20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class cable_vs20_Static_Index +{ +public: + cable_vs20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_cable_vs20 0 +class cable_vs20_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + cable_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; +#define shaderDynamicTest_cable_vs20 vsh_forgot_to_set_dynamic_DOWATERFOG + 0 diff --git a/materialsystem/stdshaders/fxctmp9/cloak_blended_pass_ps20.inc b/materialsystem/stdshaders/fxctmp9/cloak_blended_pass_ps20.inc new file mode 100644 index 0000000..698b3f4 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/cloak_blended_pass_ps20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class cloak_blended_pass_ps20_Static_Index +{ +private: + int m_nBUMPMAP; +#ifdef _DEBUG + bool m_bBUMPMAP; +#endif +public: + void SetBUMPMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBUMPMAP = i; +#ifdef _DEBUG + m_bBUMPMAP = true; +#endif + } + void SetBUMPMAP( bool i ) + { + m_nBUMPMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bBUMPMAP = true; +#endif + } +public: + cloak_blended_pass_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bBUMPMAP = false; +#endif // _DEBUG + m_nBUMPMAP = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bBUMPMAP; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nBUMPMAP ) + 0; + } +}; +#define shaderStaticTest_cloak_blended_pass_ps20 psh_forgot_to_set_static_BUMPMAP + 0 +class cloak_blended_pass_ps20_Dynamic_Index +{ +public: + cloak_blended_pass_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_cloak_blended_pass_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9/cloak_blended_pass_ps20b.inc b/materialsystem/stdshaders/fxctmp9/cloak_blended_pass_ps20b.inc new file mode 100644 index 0000000..0508a0c --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/cloak_blended_pass_ps20b.inc @@ -0,0 +1,85 @@ +#include "shaderlib/cshader.h" +class cloak_blended_pass_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +private: + int m_nBUMPMAP; +#ifdef _DEBUG + bool m_bBUMPMAP; +#endif +public: + void SetBUMPMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBUMPMAP = i; +#ifdef _DEBUG + m_bBUMPMAP = true; +#endif + } + void SetBUMPMAP( bool i ) + { + m_nBUMPMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bBUMPMAP = true; +#endif + } +public: + cloak_blended_pass_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); +#ifdef _DEBUG + m_bBUMPMAP = false; +#endif // _DEBUG + m_nBUMPMAP = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB && m_bBUMPMAP; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + ( 2 * m_nBUMPMAP ) + 0; + } +}; +#define shaderStaticTest_cloak_blended_pass_ps20b psh_forgot_to_set_static_BUMPMAP + 0 +class cloak_blended_pass_ps20b_Dynamic_Index +{ +public: + cloak_blended_pass_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_cloak_blended_pass_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9/cloak_blended_pass_ps30.inc b/materialsystem/stdshaders/fxctmp9/cloak_blended_pass_ps30.inc new file mode 100644 index 0000000..acfd354 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/cloak_blended_pass_ps30.inc @@ -0,0 +1,85 @@ +#include "shaderlib/cshader.h" +class cloak_blended_pass_ps30_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +private: + int m_nBUMPMAP; +#ifdef _DEBUG + bool m_bBUMPMAP; +#endif +public: + void SetBUMPMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBUMPMAP = i; +#ifdef _DEBUG + m_bBUMPMAP = true; +#endif + } + void SetBUMPMAP( bool i ) + { + m_nBUMPMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bBUMPMAP = true; +#endif + } +public: + cloak_blended_pass_ps30_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); +#ifdef _DEBUG + m_bBUMPMAP = false; +#endif // _DEBUG + m_nBUMPMAP = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB && m_bBUMPMAP; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + ( 2 * m_nBUMPMAP ) + 0; + } +}; +#define shaderStaticTest_cloak_blended_pass_ps30 psh_forgot_to_set_static_BUMPMAP + 0 +class cloak_blended_pass_ps30_Dynamic_Index +{ +public: + cloak_blended_pass_ps30_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_cloak_blended_pass_ps30 0 diff --git a/materialsystem/stdshaders/fxctmp9/cloak_blended_pass_vs20.inc b/materialsystem/stdshaders/fxctmp9/cloak_blended_pass_vs20.inc new file mode 100644 index 0000000..6f6f504 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/cloak_blended_pass_vs20.inc @@ -0,0 +1,112 @@ +#include "shaderlib/cshader.h" +class cloak_blended_pass_vs20_Static_Index +{ +private: + int m_nBUMPMAP; +#ifdef _DEBUG + bool m_bBUMPMAP; +#endif +public: + void SetBUMPMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBUMPMAP = i; +#ifdef _DEBUG + m_bBUMPMAP = true; +#endif + } + void SetBUMPMAP( bool i ) + { + m_nBUMPMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bBUMPMAP = true; +#endif + } +public: + cloak_blended_pass_vs20_Static_Index( ) + { +#ifdef _DEBUG + m_bBUMPMAP = false; +#endif // _DEBUG + m_nBUMPMAP = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bBUMPMAP; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 4 * m_nBUMPMAP ) + 0; + } +}; +#define shaderStaticTest_cloak_blended_pass_vs20 vsh_forgot_to_set_static_BUMPMAP + 0 +class cloak_blended_pass_vs20_Dynamic_Index +{ +private: + int m_nCOMPRESSED_VERTS; +#ifdef _DEBUG + bool m_bCOMPRESSED_VERTS; +#endif +public: + void SetCOMPRESSED_VERTS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOMPRESSED_VERTS = i; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } + void SetCOMPRESSED_VERTS( bool i ) + { + m_nCOMPRESSED_VERTS = i ? 1 : 0; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +public: + cloak_blended_pass_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = false; +#endif // _DEBUG + m_nCOMPRESSED_VERTS = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bCOMPRESSED_VERTS && m_bSKINNING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCOMPRESSED_VERTS ) + ( 2 * m_nSKINNING ) + 0; + } +}; +#define shaderDynamicTest_cloak_blended_pass_vs20 vsh_forgot_to_set_dynamic_COMPRESSED_VERTS + vsh_forgot_to_set_dynamic_SKINNING + 0 diff --git a/materialsystem/stdshaders/fxctmp9/cloak_blended_pass_vs30.inc b/materialsystem/stdshaders/fxctmp9/cloak_blended_pass_vs30.inc new file mode 100644 index 0000000..bd94090 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/cloak_blended_pass_vs30.inc @@ -0,0 +1,137 @@ +#include "shaderlib/cshader.h" +class cloak_blended_pass_vs30_Static_Index +{ +private: + int m_nBUMPMAP; +#ifdef _DEBUG + bool m_bBUMPMAP; +#endif +public: + void SetBUMPMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBUMPMAP = i; +#ifdef _DEBUG + m_bBUMPMAP = true; +#endif + } + void SetBUMPMAP( bool i ) + { + m_nBUMPMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bBUMPMAP = true; +#endif + } +public: + cloak_blended_pass_vs30_Static_Index( ) + { +#ifdef _DEBUG + m_bBUMPMAP = false; +#endif // _DEBUG + m_nBUMPMAP = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bBUMPMAP; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 8 * m_nBUMPMAP ) + 0; + } +}; +#define shaderStaticTest_cloak_blended_pass_vs30 vsh_forgot_to_set_static_BUMPMAP + 0 +class cloak_blended_pass_vs30_Dynamic_Index +{ +private: + int m_nCOMPRESSED_VERTS; +#ifdef _DEBUG + bool m_bCOMPRESSED_VERTS; +#endif +public: + void SetCOMPRESSED_VERTS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOMPRESSED_VERTS = i; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } + void SetCOMPRESSED_VERTS( bool i ) + { + m_nCOMPRESSED_VERTS = i ? 1 : 0; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +private: + int m_nMORPHING; +#ifdef _DEBUG + bool m_bMORPHING; +#endif +public: + void SetMORPHING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nMORPHING = i; +#ifdef _DEBUG + m_bMORPHING = true; +#endif + } + void SetMORPHING( bool i ) + { + m_nMORPHING = i ? 1 : 0; +#ifdef _DEBUG + m_bMORPHING = true; +#endif + } +public: + cloak_blended_pass_vs30_Dynamic_Index() + { +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = false; +#endif // _DEBUG + m_nCOMPRESSED_VERTS = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; +#ifdef _DEBUG + m_bMORPHING = false; +#endif // _DEBUG + m_nMORPHING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bCOMPRESSED_VERTS && m_bSKINNING && m_bMORPHING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCOMPRESSED_VERTS ) + ( 2 * m_nSKINNING ) + ( 4 * m_nMORPHING ) + 0; + } +}; +#define shaderDynamicTest_cloak_blended_pass_vs30 vsh_forgot_to_set_dynamic_COMPRESSED_VERTS + vsh_forgot_to_set_dynamic_SKINNING + vsh_forgot_to_set_dynamic_MORPHING + 0 diff --git a/materialsystem/stdshaders/fxctmp9/cloak_ps20.inc b/materialsystem/stdshaders/fxctmp9/cloak_ps20.inc new file mode 100644 index 0000000..31d2b25 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/cloak_ps20.inc @@ -0,0 +1,137 @@ +#include "shaderlib/cshader.h" +class cloak_ps20_Static_Index +{ +private: + int m_nLIGHTWARPTEXTURE; +#ifdef _DEBUG + bool m_bLIGHTWARPTEXTURE; +#endif +public: + void SetLIGHTWARPTEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nLIGHTWARPTEXTURE = i; +#ifdef _DEBUG + m_bLIGHTWARPTEXTURE = true; +#endif + } + void SetLIGHTWARPTEXTURE( bool i ) + { + m_nLIGHTWARPTEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bLIGHTWARPTEXTURE = true; +#endif + } +public: + cloak_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bLIGHTWARPTEXTURE = false; +#endif // _DEBUG + m_nLIGHTWARPTEXTURE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bLIGHTWARPTEXTURE; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 12 * m_nLIGHTWARPTEXTURE ) + 0; + } +}; +#define shaderStaticTest_cloak_ps20 psh_forgot_to_set_static_LIGHTWARPTEXTURE + 0 +class cloak_ps20_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +private: + int m_nWRITEWATERFOGTODESTALPHA; +#ifdef _DEBUG + bool m_bWRITEWATERFOGTODESTALPHA; +#endif +public: + void SetWRITEWATERFOGTODESTALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nWRITEWATERFOGTODESTALPHA = i; +#ifdef _DEBUG + m_bWRITEWATERFOGTODESTALPHA = true; +#endif + } + void SetWRITEWATERFOGTODESTALPHA( bool i ) + { + m_nWRITEWATERFOGTODESTALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bWRITEWATERFOGTODESTALPHA = true; +#endif + } +private: + int m_nNUM_LIGHTS; +#ifdef _DEBUG + bool m_bNUM_LIGHTS; +#endif +public: + void SetNUM_LIGHTS( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nNUM_LIGHTS = i; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } + void SetNUM_LIGHTS( bool i ) + { + m_nNUM_LIGHTS = i ? 1 : 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } +public: + cloak_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; +#ifdef _DEBUG + m_bWRITEWATERFOGTODESTALPHA = false; +#endif // _DEBUG + m_nWRITEWATERFOGTODESTALPHA = 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = false; +#endif // _DEBUG + m_nNUM_LIGHTS = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE && m_bWRITEWATERFOGTODESTALPHA && m_bNUM_LIGHTS; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + ( 2 * m_nWRITEWATERFOGTODESTALPHA ) + ( 4 * m_nNUM_LIGHTS ) + 0; + } +}; +#define shaderDynamicTest_cloak_ps20 psh_forgot_to_set_dynamic_PIXELFOGTYPE + psh_forgot_to_set_dynamic_WRITEWATERFOGTODESTALPHA + psh_forgot_to_set_dynamic_NUM_LIGHTS + 0 diff --git a/materialsystem/stdshaders/fxctmp9/cloak_ps20b.inc b/materialsystem/stdshaders/fxctmp9/cloak_ps20b.inc new file mode 100644 index 0000000..847b3c7 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/cloak_ps20b.inc @@ -0,0 +1,162 @@ +#include "shaderlib/cshader.h" +class cloak_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +private: + int m_nLIGHTWARPTEXTURE; +#ifdef _DEBUG + bool m_bLIGHTWARPTEXTURE; +#endif +public: + void SetLIGHTWARPTEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nLIGHTWARPTEXTURE = i; +#ifdef _DEBUG + m_bLIGHTWARPTEXTURE = true; +#endif + } + void SetLIGHTWARPTEXTURE( bool i ) + { + m_nLIGHTWARPTEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bLIGHTWARPTEXTURE = true; +#endif + } +public: + cloak_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); +#ifdef _DEBUG + m_bLIGHTWARPTEXTURE = false; +#endif // _DEBUG + m_nLIGHTWARPTEXTURE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB && m_bLIGHTWARPTEXTURE; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 20 * m_nCONVERT_TO_SRGB ) + ( 40 * m_nLIGHTWARPTEXTURE ) + 0; + } +}; +#define shaderStaticTest_cloak_ps20b psh_forgot_to_set_static_LIGHTWARPTEXTURE + 0 +class cloak_ps20b_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +private: + int m_nWRITEWATERFOGTODESTALPHA; +#ifdef _DEBUG + bool m_bWRITEWATERFOGTODESTALPHA; +#endif +public: + void SetWRITEWATERFOGTODESTALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nWRITEWATERFOGTODESTALPHA = i; +#ifdef _DEBUG + m_bWRITEWATERFOGTODESTALPHA = true; +#endif + } + void SetWRITEWATERFOGTODESTALPHA( bool i ) + { + m_nWRITEWATERFOGTODESTALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bWRITEWATERFOGTODESTALPHA = true; +#endif + } +private: + int m_nNUM_LIGHTS; +#ifdef _DEBUG + bool m_bNUM_LIGHTS; +#endif +public: + void SetNUM_LIGHTS( int i ) + { + Assert( i >= 0 && i <= 4 ); + m_nNUM_LIGHTS = i; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } + void SetNUM_LIGHTS( bool i ) + { + m_nNUM_LIGHTS = i ? 1 : 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } +public: + cloak_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; +#ifdef _DEBUG + m_bWRITEWATERFOGTODESTALPHA = false; +#endif // _DEBUG + m_nWRITEWATERFOGTODESTALPHA = 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = false; +#endif // _DEBUG + m_nNUM_LIGHTS = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE && m_bWRITEWATERFOGTODESTALPHA && m_bNUM_LIGHTS; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + ( 2 * m_nWRITEWATERFOGTODESTALPHA ) + ( 4 * m_nNUM_LIGHTS ) + 0; + } +}; +#define shaderDynamicTest_cloak_ps20b psh_forgot_to_set_dynamic_PIXELFOGTYPE + psh_forgot_to_set_dynamic_WRITEWATERFOGTODESTALPHA + psh_forgot_to_set_dynamic_NUM_LIGHTS + 0 diff --git a/materialsystem/stdshaders/fxctmp9/cloak_ps30.inc b/materialsystem/stdshaders/fxctmp9/cloak_ps30.inc new file mode 100644 index 0000000..b94553b --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/cloak_ps30.inc @@ -0,0 +1,162 @@ +#include "shaderlib/cshader.h" +class cloak_ps30_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +private: + int m_nLIGHTWARPTEXTURE; +#ifdef _DEBUG + bool m_bLIGHTWARPTEXTURE; +#endif +public: + void SetLIGHTWARPTEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nLIGHTWARPTEXTURE = i; +#ifdef _DEBUG + m_bLIGHTWARPTEXTURE = true; +#endif + } + void SetLIGHTWARPTEXTURE( bool i ) + { + m_nLIGHTWARPTEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bLIGHTWARPTEXTURE = true; +#endif + } +public: + cloak_ps30_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); +#ifdef _DEBUG + m_bLIGHTWARPTEXTURE = false; +#endif // _DEBUG + m_nLIGHTWARPTEXTURE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB && m_bLIGHTWARPTEXTURE; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 20 * m_nCONVERT_TO_SRGB ) + ( 40 * m_nLIGHTWARPTEXTURE ) + 0; + } +}; +#define shaderStaticTest_cloak_ps30 psh_forgot_to_set_static_LIGHTWARPTEXTURE + 0 +class cloak_ps30_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +private: + int m_nWRITEWATERFOGTODESTALPHA; +#ifdef _DEBUG + bool m_bWRITEWATERFOGTODESTALPHA; +#endif +public: + void SetWRITEWATERFOGTODESTALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nWRITEWATERFOGTODESTALPHA = i; +#ifdef _DEBUG + m_bWRITEWATERFOGTODESTALPHA = true; +#endif + } + void SetWRITEWATERFOGTODESTALPHA( bool i ) + { + m_nWRITEWATERFOGTODESTALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bWRITEWATERFOGTODESTALPHA = true; +#endif + } +private: + int m_nNUM_LIGHTS; +#ifdef _DEBUG + bool m_bNUM_LIGHTS; +#endif +public: + void SetNUM_LIGHTS( int i ) + { + Assert( i >= 0 && i <= 4 ); + m_nNUM_LIGHTS = i; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } + void SetNUM_LIGHTS( bool i ) + { + m_nNUM_LIGHTS = i ? 1 : 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } +public: + cloak_ps30_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; +#ifdef _DEBUG + m_bWRITEWATERFOGTODESTALPHA = false; +#endif // _DEBUG + m_nWRITEWATERFOGTODESTALPHA = 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = false; +#endif // _DEBUG + m_nNUM_LIGHTS = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE && m_bWRITEWATERFOGTODESTALPHA && m_bNUM_LIGHTS; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + ( 2 * m_nWRITEWATERFOGTODESTALPHA ) + ( 4 * m_nNUM_LIGHTS ) + 0; + } +}; +#define shaderDynamicTest_cloak_ps30 psh_forgot_to_set_dynamic_PIXELFOGTYPE + psh_forgot_to_set_dynamic_WRITEWATERFOGTODESTALPHA + psh_forgot_to_set_dynamic_NUM_LIGHTS + 0 diff --git a/materialsystem/stdshaders/fxctmp9/cloak_vs20.inc b/materialsystem/stdshaders/fxctmp9/cloak_vs20.inc new file mode 100644 index 0000000..6693832 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/cloak_vs20.inc @@ -0,0 +1,187 @@ +#include "shaderlib/cshader.h" +class cloak_vs20_Static_Index +{ +private: + int m_nMODEL; +#ifdef _DEBUG + bool m_bMODEL; +#endif +public: + void SetMODEL( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nMODEL = i; +#ifdef _DEBUG + m_bMODEL = true; +#endif + } + void SetMODEL( bool i ) + { + m_nMODEL = i ? 1 : 0; +#ifdef _DEBUG + m_bMODEL = true; +#endif + } +private: + int m_nUSE_STATIC_CONTROL_FLOW; +#ifdef _DEBUG + bool m_bUSE_STATIC_CONTROL_FLOW; +#endif +public: + void SetUSE_STATIC_CONTROL_FLOW( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nUSE_STATIC_CONTROL_FLOW = i; +#ifdef _DEBUG + m_bUSE_STATIC_CONTROL_FLOW = true; +#endif + } + void SetUSE_STATIC_CONTROL_FLOW( bool i ) + { + m_nUSE_STATIC_CONTROL_FLOW = i ? 1 : 0; +#ifdef _DEBUG + m_bUSE_STATIC_CONTROL_FLOW = true; +#endif + } +public: + cloak_vs20_Static_Index( ) + { +#ifdef _DEBUG + m_bMODEL = false; +#endif // _DEBUG + m_nMODEL = 0; +#ifdef _DEBUG + m_bUSE_STATIC_CONTROL_FLOW = false; +#endif // _DEBUG + m_nUSE_STATIC_CONTROL_FLOW = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bMODEL && m_bUSE_STATIC_CONTROL_FLOW; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 24 * m_nMODEL ) + ( 48 * m_nUSE_STATIC_CONTROL_FLOW ) + 0; + } +}; +#define shaderStaticTest_cloak_vs20 vsh_forgot_to_set_static_MODEL + vsh_forgot_to_set_static_USE_STATIC_CONTROL_FLOW + 0 +class cloak_vs20_Dynamic_Index +{ +private: + int m_nCOMPRESSED_VERTS; +#ifdef _DEBUG + bool m_bCOMPRESSED_VERTS; +#endif +public: + void SetCOMPRESSED_VERTS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOMPRESSED_VERTS = i; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } + void SetCOMPRESSED_VERTS( bool i ) + { + m_nCOMPRESSED_VERTS = i ? 1 : 0; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +private: + int m_nNUM_LIGHTS; +#ifdef _DEBUG + bool m_bNUM_LIGHTS; +#endif +public: + void SetNUM_LIGHTS( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nNUM_LIGHTS = i; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } + void SetNUM_LIGHTS( bool i ) + { + m_nNUM_LIGHTS = i ? 1 : 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } +public: + cloak_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = false; +#endif // _DEBUG + m_nCOMPRESSED_VERTS = 0; +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = false; +#endif // _DEBUG + m_nNUM_LIGHTS = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bCOMPRESSED_VERTS && m_bDOWATERFOG && m_bSKINNING && m_bNUM_LIGHTS; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCOMPRESSED_VERTS ) + ( 2 * m_nDOWATERFOG ) + ( 4 * m_nSKINNING ) + ( 8 * m_nNUM_LIGHTS ) + 0; + } +}; +#define shaderDynamicTest_cloak_vs20 vsh_forgot_to_set_dynamic_COMPRESSED_VERTS + vsh_forgot_to_set_dynamic_DOWATERFOG + vsh_forgot_to_set_dynamic_SKINNING + vsh_forgot_to_set_dynamic_NUM_LIGHTS + 0 diff --git a/materialsystem/stdshaders/fxctmp9/cloak_vs30.inc b/materialsystem/stdshaders/fxctmp9/cloak_vs30.inc new file mode 100644 index 0000000..09cee16 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/cloak_vs30.inc @@ -0,0 +1,162 @@ +#include "shaderlib/cshader.h" +class cloak_vs30_Static_Index +{ +private: + int m_nMODEL; +#ifdef _DEBUG + bool m_bMODEL; +#endif +public: + void SetMODEL( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nMODEL = i; +#ifdef _DEBUG + m_bMODEL = true; +#endif + } + void SetMODEL( bool i ) + { + m_nMODEL = i ? 1 : 0; +#ifdef _DEBUG + m_bMODEL = true; +#endif + } +public: + cloak_vs30_Static_Index( ) + { +#ifdef _DEBUG + m_bMODEL = false; +#endif // _DEBUG + m_nMODEL = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bMODEL; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 16 * m_nMODEL ) + 0; + } +}; +#define shaderStaticTest_cloak_vs30 vsh_forgot_to_set_static_MODEL + 0 +class cloak_vs30_Dynamic_Index +{ +private: + int m_nCOMPRESSED_VERTS; +#ifdef _DEBUG + bool m_bCOMPRESSED_VERTS; +#endif +public: + void SetCOMPRESSED_VERTS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOMPRESSED_VERTS = i; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } + void SetCOMPRESSED_VERTS( bool i ) + { + m_nCOMPRESSED_VERTS = i ? 1 : 0; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +private: + int m_nMORPHING; +#ifdef _DEBUG + bool m_bMORPHING; +#endif +public: + void SetMORPHING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nMORPHING = i; +#ifdef _DEBUG + m_bMORPHING = true; +#endif + } + void SetMORPHING( bool i ) + { + m_nMORPHING = i ? 1 : 0; +#ifdef _DEBUG + m_bMORPHING = true; +#endif + } +public: + cloak_vs30_Dynamic_Index() + { +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = false; +#endif // _DEBUG + m_nCOMPRESSED_VERTS = 0; +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; +#ifdef _DEBUG + m_bMORPHING = false; +#endif // _DEBUG + m_nMORPHING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bCOMPRESSED_VERTS && m_bDOWATERFOG && m_bSKINNING && m_bMORPHING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCOMPRESSED_VERTS ) + ( 2 * m_nDOWATERFOG ) + ( 4 * m_nSKINNING ) + ( 8 * m_nMORPHING ) + 0; + } +}; +#define shaderDynamicTest_cloak_vs30 vsh_forgot_to_set_dynamic_COMPRESSED_VERTS + vsh_forgot_to_set_dynamic_DOWATERFOG + vsh_forgot_to_set_dynamic_SKINNING + vsh_forgot_to_set_dynamic_MORPHING + 0 diff --git a/materialsystem/stdshaders/fxctmp9/cloud_ps20.inc b/materialsystem/stdshaders/fxctmp9/cloud_ps20.inc new file mode 100644 index 0000000..494bf27 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/cloud_ps20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class cloud_ps20_Static_Index +{ +public: + cloud_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_cloud_ps20 0 +class cloud_ps20_Dynamic_Index +{ +public: + cloud_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_cloud_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9/cloud_vs20.inc b/materialsystem/stdshaders/fxctmp9/cloud_vs20.inc new file mode 100644 index 0000000..c285f87 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/cloud_vs20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class cloud_vs20_Static_Index +{ +public: + cloud_vs20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_cloud_vs20 0 +class cloud_vs20_Dynamic_Index +{ +public: + cloud_vs20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_cloud_vs20 0 diff --git a/materialsystem/stdshaders/fxctmp9/color_projection_ps20.inc b/materialsystem/stdshaders/fxctmp9/color_projection_ps20.inc new file mode 100644 index 0000000..be9ef5a --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/color_projection_ps20.inc @@ -0,0 +1,110 @@ +#include "shaderlib/cshader.h" +class color_projection_ps20_Static_Index +{ +public: + color_projection_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_color_projection_ps20 0 +class color_projection_ps20_Dynamic_Index +{ +private: + int m_nNEED_BLINDMK; +#ifdef _DEBUG + bool m_bNEED_BLINDMK; +#endif +public: + void SetNEED_BLINDMK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nNEED_BLINDMK = i; +#ifdef _DEBUG + m_bNEED_BLINDMK = true; +#endif + } + void SetNEED_BLINDMK( bool i ) + { + m_nNEED_BLINDMK = i ? 1 : 0; +#ifdef _DEBUG + m_bNEED_BLINDMK = true; +#endif + } +private: + int m_nNEED_ANOMYLIZE; +#ifdef _DEBUG + bool m_bNEED_ANOMYLIZE; +#endif +public: + void SetNEED_ANOMYLIZE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nNEED_ANOMYLIZE = i; +#ifdef _DEBUG + m_bNEED_ANOMYLIZE = true; +#endif + } + void SetNEED_ANOMYLIZE( bool i ) + { + m_nNEED_ANOMYLIZE = i ? 1 : 0; +#ifdef _DEBUG + m_bNEED_ANOMYLIZE = true; +#endif + } +private: + int m_nNEED_MONOCHROME; +#ifdef _DEBUG + bool m_bNEED_MONOCHROME; +#endif +public: + void SetNEED_MONOCHROME( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nNEED_MONOCHROME = i; +#ifdef _DEBUG + m_bNEED_MONOCHROME = true; +#endif + } + void SetNEED_MONOCHROME( bool i ) + { + m_nNEED_MONOCHROME = i ? 1 : 0; +#ifdef _DEBUG + m_bNEED_MONOCHROME = true; +#endif + } +public: + color_projection_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bNEED_BLINDMK = false; +#endif // _DEBUG + m_nNEED_BLINDMK = 0; +#ifdef _DEBUG + m_bNEED_ANOMYLIZE = false; +#endif // _DEBUG + m_nNEED_ANOMYLIZE = 0; +#ifdef _DEBUG + m_bNEED_MONOCHROME = false; +#endif // _DEBUG + m_nNEED_MONOCHROME = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bNEED_BLINDMK && m_bNEED_ANOMYLIZE && m_bNEED_MONOCHROME; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nNEED_BLINDMK ) + ( 2 * m_nNEED_ANOMYLIZE ) + ( 4 * m_nNEED_MONOCHROME ) + 0; + } +}; +#define shaderDynamicTest_color_projection_ps20 psh_forgot_to_set_dynamic_NEED_BLINDMK + psh_forgot_to_set_dynamic_NEED_ANOMYLIZE + psh_forgot_to_set_dynamic_NEED_MONOCHROME + 0 diff --git a/materialsystem/stdshaders/fxctmp9/color_projection_ps20b.inc b/materialsystem/stdshaders/fxctmp9/color_projection_ps20b.inc new file mode 100644 index 0000000..8aba230 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/color_projection_ps20b.inc @@ -0,0 +1,110 @@ +#include "shaderlib/cshader.h" +class color_projection_ps20b_Static_Index +{ +public: + color_projection_ps20b_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_color_projection_ps20b 0 +class color_projection_ps20b_Dynamic_Index +{ +private: + int m_nNEED_BLINDMK; +#ifdef _DEBUG + bool m_bNEED_BLINDMK; +#endif +public: + void SetNEED_BLINDMK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nNEED_BLINDMK = i; +#ifdef _DEBUG + m_bNEED_BLINDMK = true; +#endif + } + void SetNEED_BLINDMK( bool i ) + { + m_nNEED_BLINDMK = i ? 1 : 0; +#ifdef _DEBUG + m_bNEED_BLINDMK = true; +#endif + } +private: + int m_nNEED_ANOMYLIZE; +#ifdef _DEBUG + bool m_bNEED_ANOMYLIZE; +#endif +public: + void SetNEED_ANOMYLIZE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nNEED_ANOMYLIZE = i; +#ifdef _DEBUG + m_bNEED_ANOMYLIZE = true; +#endif + } + void SetNEED_ANOMYLIZE( bool i ) + { + m_nNEED_ANOMYLIZE = i ? 1 : 0; +#ifdef _DEBUG + m_bNEED_ANOMYLIZE = true; +#endif + } +private: + int m_nNEED_MONOCHROME; +#ifdef _DEBUG + bool m_bNEED_MONOCHROME; +#endif +public: + void SetNEED_MONOCHROME( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nNEED_MONOCHROME = i; +#ifdef _DEBUG + m_bNEED_MONOCHROME = true; +#endif + } + void SetNEED_MONOCHROME( bool i ) + { + m_nNEED_MONOCHROME = i ? 1 : 0; +#ifdef _DEBUG + m_bNEED_MONOCHROME = true; +#endif + } +public: + color_projection_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bNEED_BLINDMK = false; +#endif // _DEBUG + m_nNEED_BLINDMK = 0; +#ifdef _DEBUG + m_bNEED_ANOMYLIZE = false; +#endif // _DEBUG + m_nNEED_ANOMYLIZE = 0; +#ifdef _DEBUG + m_bNEED_MONOCHROME = false; +#endif // _DEBUG + m_nNEED_MONOCHROME = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bNEED_BLINDMK && m_bNEED_ANOMYLIZE && m_bNEED_MONOCHROME; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nNEED_BLINDMK ) + ( 2 * m_nNEED_ANOMYLIZE ) + ( 4 * m_nNEED_MONOCHROME ) + 0; + } +}; +#define shaderDynamicTest_color_projection_ps20b psh_forgot_to_set_dynamic_NEED_BLINDMK + psh_forgot_to_set_dynamic_NEED_ANOMYLIZE + psh_forgot_to_set_dynamic_NEED_MONOCHROME + 0 diff --git a/materialsystem/stdshaders/fxctmp9/color_projection_vs20.inc b/materialsystem/stdshaders/fxctmp9/color_projection_vs20.inc new file mode 100644 index 0000000..cb49b23 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/color_projection_vs20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class color_projection_vs20_Static_Index +{ +public: + color_projection_vs20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_color_projection_vs20 0 +class color_projection_vs20_Dynamic_Index +{ +public: + color_projection_vs20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_color_projection_vs20 0 diff --git a/materialsystem/stdshaders/fxctmp9/colorcorrection_ps20.inc b/materialsystem/stdshaders/fxctmp9/colorcorrection_ps20.inc new file mode 100644 index 0000000..53b9055 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/colorcorrection_ps20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class colorcorrection_ps20_Static_Index +{ +public: + colorcorrection_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_colorcorrection_ps20 0 +class colorcorrection_ps20_Dynamic_Index +{ +private: + int m_nNUM_LOOKUPS; +#ifdef _DEBUG + bool m_bNUM_LOOKUPS; +#endif +public: + void SetNUM_LOOKUPS( int i ) + { + Assert( i >= 0 && i <= 4 ); + m_nNUM_LOOKUPS = i; +#ifdef _DEBUG + m_bNUM_LOOKUPS = true; +#endif + } + void SetNUM_LOOKUPS( bool i ) + { + m_nNUM_LOOKUPS = i ? 1 : 0; +#ifdef _DEBUG + m_bNUM_LOOKUPS = true; +#endif + } +public: + colorcorrection_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bNUM_LOOKUPS = false; +#endif // _DEBUG + m_nNUM_LOOKUPS = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bNUM_LOOKUPS; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nNUM_LOOKUPS ) + 0; + } +}; +#define shaderDynamicTest_colorcorrection_ps20 psh_forgot_to_set_dynamic_NUM_LOOKUPS + 0 diff --git a/materialsystem/stdshaders/fxctmp9/colorcorrection_ps20b.inc b/materialsystem/stdshaders/fxctmp9/colorcorrection_ps20b.inc new file mode 100644 index 0000000..ad4a221 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/colorcorrection_ps20b.inc @@ -0,0 +1,87 @@ +#include "shaderlib/cshader.h" +class colorcorrection_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + colorcorrection_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 5 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_colorcorrection_ps20b 0 +class colorcorrection_ps20b_Dynamic_Index +{ +private: + int m_nNUM_LOOKUPS; +#ifdef _DEBUG + bool m_bNUM_LOOKUPS; +#endif +public: + void SetNUM_LOOKUPS( int i ) + { + Assert( i >= 0 && i <= 4 ); + m_nNUM_LOOKUPS = i; +#ifdef _DEBUG + m_bNUM_LOOKUPS = true; +#endif + } + void SetNUM_LOOKUPS( bool i ) + { + m_nNUM_LOOKUPS = i ? 1 : 0; +#ifdef _DEBUG + m_bNUM_LOOKUPS = true; +#endif + } +public: + colorcorrection_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bNUM_LOOKUPS = false; +#endif // _DEBUG + m_nNUM_LOOKUPS = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bNUM_LOOKUPS; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nNUM_LOOKUPS ) + 0; + } +}; +#define shaderDynamicTest_colorcorrection_ps20b psh_forgot_to_set_dynamic_NUM_LOOKUPS + 0 diff --git a/materialsystem/stdshaders/fxctmp9/compositor_ps20.inc b/materialsystem/stdshaders/fxctmp9/compositor_ps20.inc new file mode 100644 index 0000000..15125f2 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/compositor_ps20.inc @@ -0,0 +1,87 @@ +#include "shaderlib/cshader.h" +class compositor_ps20_Static_Index +{ +private: + int m_nCOMBINE_MODE; +#ifdef _DEBUG + bool m_bCOMBINE_MODE; +#endif +public: + void SetCOMBINE_MODE( int i ) + { + Assert( i >= 0 && i <= 6 ); + m_nCOMBINE_MODE = i; +#ifdef _DEBUG + m_bCOMBINE_MODE = true; +#endif + } + void SetCOMBINE_MODE( bool i ) + { + m_nCOMBINE_MODE = i ? 1 : 0; +#ifdef _DEBUG + m_bCOMBINE_MODE = true; +#endif + } +public: + compositor_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCOMBINE_MODE = false; +#endif // _DEBUG + m_nCOMBINE_MODE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCOMBINE_MODE; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCOMBINE_MODE ) + 0; + } +}; +#define shaderStaticTest_compositor_ps20 psh_forgot_to_set_static_COMBINE_MODE + 0 +class compositor_ps20_Dynamic_Index +{ +private: + int m_nDEBUG_MODE; +#ifdef _DEBUG + bool m_bDEBUG_MODE; +#endif +public: + void SetDEBUG_MODE( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nDEBUG_MODE = i; +#ifdef _DEBUG + m_bDEBUG_MODE = true; +#endif + } + void SetDEBUG_MODE( bool i ) + { + m_nDEBUG_MODE = i ? 1 : 0; +#ifdef _DEBUG + m_bDEBUG_MODE = true; +#endif + } +public: + compositor_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bDEBUG_MODE = false; +#endif // _DEBUG + m_nDEBUG_MODE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDEBUG_MODE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDEBUG_MODE ) + 0; + } +}; +#define shaderDynamicTest_compositor_ps20 psh_forgot_to_set_dynamic_DEBUG_MODE + 0 diff --git a/materialsystem/stdshaders/fxctmp9/compositor_ps20b.inc b/materialsystem/stdshaders/fxctmp9/compositor_ps20b.inc new file mode 100644 index 0000000..21e0291 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/compositor_ps20b.inc @@ -0,0 +1,87 @@ +#include "shaderlib/cshader.h" +class compositor_ps20b_Static_Index +{ +private: + int m_nCOMBINE_MODE; +#ifdef _DEBUG + bool m_bCOMBINE_MODE; +#endif +public: + void SetCOMBINE_MODE( int i ) + { + Assert( i >= 0 && i <= 6 ); + m_nCOMBINE_MODE = i; +#ifdef _DEBUG + m_bCOMBINE_MODE = true; +#endif + } + void SetCOMBINE_MODE( bool i ) + { + m_nCOMBINE_MODE = i ? 1 : 0; +#ifdef _DEBUG + m_bCOMBINE_MODE = true; +#endif + } +public: + compositor_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCOMBINE_MODE = false; +#endif // _DEBUG + m_nCOMBINE_MODE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCOMBINE_MODE; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nCOMBINE_MODE ) + 0; + } +}; +#define shaderStaticTest_compositor_ps20b psh_forgot_to_set_static_COMBINE_MODE + 0 +class compositor_ps20b_Dynamic_Index +{ +private: + int m_nDEBUG_MODE; +#ifdef _DEBUG + bool m_bDEBUG_MODE; +#endif +public: + void SetDEBUG_MODE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDEBUG_MODE = i; +#ifdef _DEBUG + m_bDEBUG_MODE = true; +#endif + } + void SetDEBUG_MODE( bool i ) + { + m_nDEBUG_MODE = i ? 1 : 0; +#ifdef _DEBUG + m_bDEBUG_MODE = true; +#endif + } +public: + compositor_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bDEBUG_MODE = false; +#endif // _DEBUG + m_nDEBUG_MODE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDEBUG_MODE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDEBUG_MODE ) + 0; + } +}; +#define shaderDynamicTest_compositor_ps20b psh_forgot_to_set_dynamic_DEBUG_MODE + 0 diff --git a/materialsystem/stdshaders/fxctmp9/compositor_vs20.inc b/materialsystem/stdshaders/fxctmp9/compositor_vs20.inc new file mode 100644 index 0000000..c4baac4 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/compositor_vs20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class compositor_vs20_Static_Index +{ +public: + compositor_vs20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_compositor_vs20 0 +class compositor_vs20_Dynamic_Index +{ +public: + compositor_vs20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_compositor_vs20 0 diff --git a/materialsystem/stdshaders/fxctmp9/constant_color_ps20.inc b/materialsystem/stdshaders/fxctmp9/constant_color_ps20.inc new file mode 100644 index 0000000..ea46c12 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/constant_color_ps20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class constant_color_ps20_Static_Index +{ +public: + constant_color_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_constant_color_ps20 0 +class constant_color_ps20_Dynamic_Index +{ +public: + constant_color_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_constant_color_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9/constant_color_ps20b.inc b/materialsystem/stdshaders/fxctmp9/constant_color_ps20b.inc new file mode 100644 index 0000000..c9f6c3c --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/constant_color_ps20b.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class constant_color_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + constant_color_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_constant_color_ps20b 0 +class constant_color_ps20b_Dynamic_Index +{ +public: + constant_color_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_constant_color_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9/copy_fp_rt_ps20.inc b/materialsystem/stdshaders/fxctmp9/copy_fp_rt_ps20.inc new file mode 100644 index 0000000..f15ba7a --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/copy_fp_rt_ps20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class copy_fp_rt_ps20_Static_Index +{ +public: + copy_fp_rt_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_copy_fp_rt_ps20 0 +class copy_fp_rt_ps20_Dynamic_Index +{ +public: + copy_fp_rt_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_copy_fp_rt_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9/copy_fp_rt_ps20b.inc b/materialsystem/stdshaders/fxctmp9/copy_fp_rt_ps20b.inc new file mode 100644 index 0000000..2873f93 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/copy_fp_rt_ps20b.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class copy_fp_rt_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + copy_fp_rt_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_copy_fp_rt_ps20b 0 +class copy_fp_rt_ps20b_Dynamic_Index +{ +public: + copy_fp_rt_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_copy_fp_rt_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9/core_ps20.inc b/materialsystem/stdshaders/fxctmp9/core_ps20.inc new file mode 100644 index 0000000..c52cc06 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/core_ps20.inc @@ -0,0 +1,162 @@ +#include "shaderlib/cshader.h" +class core_ps20_Static_Index +{ +private: + int m_nCUBEMAP; +#ifdef _DEBUG + bool m_bCUBEMAP; +#endif +public: + void SetCUBEMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCUBEMAP = i; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } + void SetCUBEMAP( bool i ) + { + m_nCUBEMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } +private: + int m_nFLOWMAP; +#ifdef _DEBUG + bool m_bFLOWMAP; +#endif +public: + void SetFLOWMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFLOWMAP = i; +#ifdef _DEBUG + m_bFLOWMAP = true; +#endif + } + void SetFLOWMAP( bool i ) + { + m_nFLOWMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bFLOWMAP = true; +#endif + } +private: + int m_nCORECOLORTEXTURE; +#ifdef _DEBUG + bool m_bCORECOLORTEXTURE; +#endif +public: + void SetCORECOLORTEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCORECOLORTEXTURE = i; +#ifdef _DEBUG + m_bCORECOLORTEXTURE = true; +#endif + } + void SetCORECOLORTEXTURE( bool i ) + { + m_nCORECOLORTEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bCORECOLORTEXTURE = true; +#endif + } +private: + int m_nREFRACT; +#ifdef _DEBUG + bool m_bREFRACT; +#endif +public: + void SetREFRACT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nREFRACT = i; +#ifdef _DEBUG + m_bREFRACT = true; +#endif + } + void SetREFRACT( bool i ) + { + m_nREFRACT = i ? 1 : 0; +#ifdef _DEBUG + m_bREFRACT = true; +#endif + } +public: + core_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCUBEMAP = false; +#endif // _DEBUG + m_nCUBEMAP = 0; +#ifdef _DEBUG + m_bFLOWMAP = false; +#endif // _DEBUG + m_nFLOWMAP = 0; +#ifdef _DEBUG + m_bCORECOLORTEXTURE = false; +#endif // _DEBUG + m_nCORECOLORTEXTURE = 0; +#ifdef _DEBUG + m_bREFRACT = false; +#endif // _DEBUG + m_nREFRACT = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCUBEMAP && m_bFLOWMAP && m_bCORECOLORTEXTURE && m_bREFRACT; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nCUBEMAP ) + ( 4 * m_nFLOWMAP ) + ( 8 * m_nCORECOLORTEXTURE ) + ( 16 * m_nREFRACT ) + 0; + } +}; +#define shaderStaticTest_core_ps20 psh_forgot_to_set_static_CUBEMAP + psh_forgot_to_set_static_FLOWMAP + psh_forgot_to_set_static_CORECOLORTEXTURE + psh_forgot_to_set_static_REFRACT + 0 +class core_ps20_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + core_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_core_ps20 psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9/core_ps20b.inc b/materialsystem/stdshaders/fxctmp9/core_ps20b.inc new file mode 100644 index 0000000..b90999f --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/core_ps20b.inc @@ -0,0 +1,187 @@ +#include "shaderlib/cshader.h" +class core_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +private: + int m_nCUBEMAP; +#ifdef _DEBUG + bool m_bCUBEMAP; +#endif +public: + void SetCUBEMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCUBEMAP = i; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } + void SetCUBEMAP( bool i ) + { + m_nCUBEMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } +private: + int m_nFLOWMAP; +#ifdef _DEBUG + bool m_bFLOWMAP; +#endif +public: + void SetFLOWMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFLOWMAP = i; +#ifdef _DEBUG + m_bFLOWMAP = true; +#endif + } + void SetFLOWMAP( bool i ) + { + m_nFLOWMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bFLOWMAP = true; +#endif + } +private: + int m_nCORECOLORTEXTURE; +#ifdef _DEBUG + bool m_bCORECOLORTEXTURE; +#endif +public: + void SetCORECOLORTEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCORECOLORTEXTURE = i; +#ifdef _DEBUG + m_bCORECOLORTEXTURE = true; +#endif + } + void SetCORECOLORTEXTURE( bool i ) + { + m_nCORECOLORTEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bCORECOLORTEXTURE = true; +#endif + } +private: + int m_nREFRACT; +#ifdef _DEBUG + bool m_bREFRACT; +#endif +public: + void SetREFRACT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nREFRACT = i; +#ifdef _DEBUG + m_bREFRACT = true; +#endif + } + void SetREFRACT( bool i ) + { + m_nREFRACT = i ? 1 : 0; +#ifdef _DEBUG + m_bREFRACT = true; +#endif + } +public: + core_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); +#ifdef _DEBUG + m_bCUBEMAP = false; +#endif // _DEBUG + m_nCUBEMAP = 0; +#ifdef _DEBUG + m_bFLOWMAP = false; +#endif // _DEBUG + m_nFLOWMAP = 0; +#ifdef _DEBUG + m_bCORECOLORTEXTURE = false; +#endif // _DEBUG + m_nCORECOLORTEXTURE = 0; +#ifdef _DEBUG + m_bREFRACT = false; +#endif // _DEBUG + m_nREFRACT = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB && m_bCUBEMAP && m_bFLOWMAP && m_bCORECOLORTEXTURE && m_bREFRACT; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nCONVERT_TO_SRGB ) + ( 4 * m_nCUBEMAP ) + ( 8 * m_nFLOWMAP ) + ( 16 * m_nCORECOLORTEXTURE ) + ( 32 * m_nREFRACT ) + 0; + } +}; +#define shaderStaticTest_core_ps20b psh_forgot_to_set_static_CUBEMAP + psh_forgot_to_set_static_FLOWMAP + psh_forgot_to_set_static_CORECOLORTEXTURE + psh_forgot_to_set_static_REFRACT + 0 +class core_ps20b_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + core_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_core_ps20b psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9/core_vs11.inc b/materialsystem/stdshaders/fxctmp9/core_vs11.inc new file mode 100644 index 0000000..3a535e7 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/core_vs11.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class core_vs11_Static_Index +{ +public: + core_vs11_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_core_vs11 0 +class core_vs11_Dynamic_Index +{ +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +public: + core_vs11_Dynamic_Index() + { +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bSKINNING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nSKINNING ) + 0; + } +}; +#define shaderDynamicTest_core_vs11 vsh_forgot_to_set_dynamic_SKINNING + 0 diff --git a/materialsystem/stdshaders/fxctmp9/core_vs20.inc b/materialsystem/stdshaders/fxctmp9/core_vs20.inc new file mode 100644 index 0000000..5cbf35f --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/core_vs20.inc @@ -0,0 +1,112 @@ +#include "shaderlib/cshader.h" +class core_vs20_Static_Index +{ +private: + int m_nMODEL; +#ifdef _DEBUG + bool m_bMODEL; +#endif +public: + void SetMODEL( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nMODEL = i; +#ifdef _DEBUG + m_bMODEL = true; +#endif + } + void SetMODEL( bool i ) + { + m_nMODEL = i ? 1 : 0; +#ifdef _DEBUG + m_bMODEL = true; +#endif + } +public: + core_vs20_Static_Index( ) + { +#ifdef _DEBUG + m_bMODEL = false; +#endif // _DEBUG + m_nMODEL = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bMODEL; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 4 * m_nMODEL ) + 0; + } +}; +#define shaderStaticTest_core_vs20 vsh_forgot_to_set_static_MODEL + 0 +class core_vs20_Dynamic_Index +{ +private: + int m_nCOMPRESSED_VERTS; +#ifdef _DEBUG + bool m_bCOMPRESSED_VERTS; +#endif +public: + void SetCOMPRESSED_VERTS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOMPRESSED_VERTS = i; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } + void SetCOMPRESSED_VERTS( bool i ) + { + m_nCOMPRESSED_VERTS = i ? 1 : 0; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +public: + core_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = false; +#endif // _DEBUG + m_nCOMPRESSED_VERTS = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bCOMPRESSED_VERTS && m_bSKINNING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCOMPRESSED_VERTS ) + ( 2 * m_nSKINNING ) + 0; + } +}; +#define shaderDynamicTest_core_vs20 vsh_forgot_to_set_dynamic_COMPRESSED_VERTS + vsh_forgot_to_set_dynamic_SKINNING + 0 diff --git a/materialsystem/stdshaders/fxctmp9/debugbumpmappedlightmap_ps11.inc b/materialsystem/stdshaders/fxctmp9/debugbumpmappedlightmap_ps11.inc new file mode 100644 index 0000000..5a09de6 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/debugbumpmappedlightmap_ps11.inc @@ -0,0 +1,59 @@ +class debugbumpmappedlightmap_ps11_Static_Index +{ +public: + debugbumpmappedlightmap_ps11_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_debugbumpmappedlightmap_ps11 0 +class debugbumpmappedlightmap_ps11_Dynamic_Index +{ +private: + int m_nMODE; +#ifdef _DEBUG + bool m_bMODE; +#endif +public: + void SetMODE( int i ) + { + Assert( i >= 0 && i <= 3 ); + m_nMODE = i; +#ifdef _DEBUG + m_bMODE = true; +#endif + } + void SetMODE( bool i ) + { + m_nMODE = i ? 1 : 0; +#ifdef _DEBUG + m_bMODE = true; +#endif + } +public: + debugbumpmappedlightmap_ps11_Dynamic_Index() + { +#ifdef _DEBUG + m_bMODE = false; +#endif // _DEBUG + m_nMODE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bMODE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nMODE ) + 0; + } +}; +#define shaderDynamicTest_debugbumpmappedlightmap_ps11 psh_forgot_to_set_dynamic_MODE + 0 diff --git a/materialsystem/stdshaders/fxctmp9/debugbumpmappedlightmap_ps20.inc b/materialsystem/stdshaders/fxctmp9/debugbumpmappedlightmap_ps20.inc new file mode 100644 index 0000000..f4de181 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/debugbumpmappedlightmap_ps20.inc @@ -0,0 +1,59 @@ +class debugbumpmappedlightmap_ps20_Static_Index +{ +public: + debugbumpmappedlightmap_ps20_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_debugbumpmappedlightmap_ps20 0 +class debugbumpmappedlightmap_ps20_Dynamic_Index +{ +private: + int m_nMODE; +#ifdef _DEBUG + bool m_bMODE; +#endif +public: + void SetMODE( int i ) + { + Assert( i >= 0 && i <= 3 ); + m_nMODE = i; +#ifdef _DEBUG + m_bMODE = true; +#endif + } + void SetMODE( bool i ) + { + m_nMODE = i ? 1 : 0; +#ifdef _DEBUG + m_bMODE = true; +#endif + } +public: + debugbumpmappedlightmap_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bMODE = false; +#endif // _DEBUG + m_nMODE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bMODE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nMODE ) + 0; + } +}; +#define shaderDynamicTest_debugbumpmappedlightmap_ps20 psh_forgot_to_set_dynamic_MODE + 0 diff --git a/materialsystem/stdshaders/fxctmp9/debugbumpmappedlightmap_ps20b.inc b/materialsystem/stdshaders/fxctmp9/debugbumpmappedlightmap_ps20b.inc new file mode 100644 index 0000000..a09e12a --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/debugbumpmappedlightmap_ps20b.inc @@ -0,0 +1,59 @@ +class debugbumpmappedlightmap_ps20b_Static_Index +{ +public: + debugbumpmappedlightmap_ps20b_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_debugbumpmappedlightmap_ps20b 0 +class debugbumpmappedlightmap_ps20b_Dynamic_Index +{ +private: + int m_nMODE; +#ifdef _DEBUG + bool m_bMODE; +#endif +public: + void SetMODE( int i ) + { + Assert( i >= 0 && i <= 3 ); + m_nMODE = i; +#ifdef _DEBUG + m_bMODE = true; +#endif + } + void SetMODE( bool i ) + { + m_nMODE = i ? 1 : 0; +#ifdef _DEBUG + m_bMODE = true; +#endif + } +public: + debugbumpmappedlightmap_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bMODE = false; +#endif // _DEBUG + m_nMODE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bMODE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nMODE ) + 0; + } +}; +#define shaderDynamicTest_debugbumpmappedlightmap_ps20b psh_forgot_to_set_dynamic_MODE + 0 diff --git a/materialsystem/stdshaders/fxctmp9/debugdrawdepth_ps20.inc b/materialsystem/stdshaders/fxctmp9/debugdrawdepth_ps20.inc new file mode 100644 index 0000000..4b455e4 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/debugdrawdepth_ps20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class debugdrawdepth_ps20_Static_Index +{ +public: + debugdrawdepth_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_debugdrawdepth_ps20 0 +class debugdrawdepth_ps20_Dynamic_Index +{ +public: + debugdrawdepth_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_debugdrawdepth_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9/debugdrawdepth_ps20b.inc b/materialsystem/stdshaders/fxctmp9/debugdrawdepth_ps20b.inc new file mode 100644 index 0000000..4d82bb9 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/debugdrawdepth_ps20b.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class debugdrawdepth_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + debugdrawdepth_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_debugdrawdepth_ps20b 0 +class debugdrawdepth_ps20b_Dynamic_Index +{ +public: + debugdrawdepth_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_debugdrawdepth_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9/debugdrawdepth_vs20.inc b/materialsystem/stdshaders/fxctmp9/debugdrawdepth_vs20.inc new file mode 100644 index 0000000..eea4b80 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/debugdrawdepth_vs20.inc @@ -0,0 +1,85 @@ +#include "shaderlib/cshader.h" +class debugdrawdepth_vs20_Static_Index +{ +public: + debugdrawdepth_vs20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_debugdrawdepth_vs20 0 +class debugdrawdepth_vs20_Dynamic_Index +{ +private: + int m_nCOMPRESSED_VERTS; +#ifdef _DEBUG + bool m_bCOMPRESSED_VERTS; +#endif +public: + void SetCOMPRESSED_VERTS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOMPRESSED_VERTS = i; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } + void SetCOMPRESSED_VERTS( bool i ) + { + m_nCOMPRESSED_VERTS = i ? 1 : 0; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +public: + debugdrawdepth_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = false; +#endif // _DEBUG + m_nCOMPRESSED_VERTS = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bCOMPRESSED_VERTS && m_bSKINNING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCOMPRESSED_VERTS ) + ( 2 * m_nSKINNING ) + 0; + } +}; +#define shaderDynamicTest_debugdrawdepth_vs20 vsh_forgot_to_set_dynamic_COMPRESSED_VERTS + vsh_forgot_to_set_dynamic_SKINNING + 0 diff --git a/materialsystem/stdshaders/fxctmp9/debugdrawenvmapmask_ps20.inc b/materialsystem/stdshaders/fxctmp9/debugdrawenvmapmask_ps20.inc new file mode 100644 index 0000000..e111960 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/debugdrawenvmapmask_ps20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class debugdrawenvmapmask_ps20_Static_Index +{ +public: + debugdrawenvmapmask_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_debugdrawenvmapmask_ps20 0 +class debugdrawenvmapmask_ps20_Dynamic_Index +{ +private: + int m_nSHOWALPHA; +#ifdef _DEBUG + bool m_bSHOWALPHA; +#endif +public: + void SetSHOWALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSHOWALPHA = i; +#ifdef _DEBUG + m_bSHOWALPHA = true; +#endif + } + void SetSHOWALPHA( bool i ) + { + m_nSHOWALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bSHOWALPHA = true; +#endif + } +public: + debugdrawenvmapmask_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bSHOWALPHA = false; +#endif // _DEBUG + m_nSHOWALPHA = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bSHOWALPHA; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nSHOWALPHA ) + 0; + } +}; +#define shaderDynamicTest_debugdrawenvmapmask_ps20 psh_forgot_to_set_dynamic_SHOWALPHA + 0 diff --git a/materialsystem/stdshaders/fxctmp9/debugdrawenvmapmask_ps20b.inc b/materialsystem/stdshaders/fxctmp9/debugdrawenvmapmask_ps20b.inc new file mode 100644 index 0000000..09e8a81 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/debugdrawenvmapmask_ps20b.inc @@ -0,0 +1,87 @@ +#include "shaderlib/cshader.h" +class debugdrawenvmapmask_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + debugdrawenvmapmask_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_debugdrawenvmapmask_ps20b 0 +class debugdrawenvmapmask_ps20b_Dynamic_Index +{ +private: + int m_nSHOWALPHA; +#ifdef _DEBUG + bool m_bSHOWALPHA; +#endif +public: + void SetSHOWALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSHOWALPHA = i; +#ifdef _DEBUG + m_bSHOWALPHA = true; +#endif + } + void SetSHOWALPHA( bool i ) + { + m_nSHOWALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bSHOWALPHA = true; +#endif + } +public: + debugdrawenvmapmask_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bSHOWALPHA = false; +#endif // _DEBUG + m_nSHOWALPHA = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bSHOWALPHA; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nSHOWALPHA ) + 0; + } +}; +#define shaderDynamicTest_debugdrawenvmapmask_ps20b psh_forgot_to_set_dynamic_SHOWALPHA + 0 diff --git a/materialsystem/stdshaders/fxctmp9/debugdrawenvmapmask_vs20.inc b/materialsystem/stdshaders/fxctmp9/debugdrawenvmapmask_vs20.inc new file mode 100644 index 0000000..96910cd --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/debugdrawenvmapmask_vs20.inc @@ -0,0 +1,85 @@ +#include "shaderlib/cshader.h" +class debugdrawenvmapmask_vs20_Static_Index +{ +public: + debugdrawenvmapmask_vs20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_debugdrawenvmapmask_vs20 0 +class debugdrawenvmapmask_vs20_Dynamic_Index +{ +private: + int m_nCOMPRESSED_VERTS; +#ifdef _DEBUG + bool m_bCOMPRESSED_VERTS; +#endif +public: + void SetCOMPRESSED_VERTS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOMPRESSED_VERTS = i; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } + void SetCOMPRESSED_VERTS( bool i ) + { + m_nCOMPRESSED_VERTS = i ? 1 : 0; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +public: + debugdrawenvmapmask_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = false; +#endif // _DEBUG + m_nCOMPRESSED_VERTS = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bCOMPRESSED_VERTS && m_bSKINNING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCOMPRESSED_VERTS ) + ( 2 * m_nSKINNING ) + 0; + } +}; +#define shaderDynamicTest_debugdrawenvmapmask_vs20 vsh_forgot_to_set_dynamic_COMPRESSED_VERTS + vsh_forgot_to_set_dynamic_SKINNING + 0 diff --git a/materialsystem/stdshaders/fxctmp9/debugluxel_ps20.inc b/materialsystem/stdshaders/fxctmp9/debugluxel_ps20.inc new file mode 100644 index 0000000..9faa69b --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/debugluxel_ps20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class debugluxel_ps20_Static_Index +{ +public: + debugluxel_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_debugluxel_ps20 0 +class debugluxel_ps20_Dynamic_Index +{ +public: + debugluxel_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_debugluxel_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9/debugluxel_ps20b.inc b/materialsystem/stdshaders/fxctmp9/debugluxel_ps20b.inc new file mode 100644 index 0000000..0675d21 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/debugluxel_ps20b.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class debugluxel_ps20b_Static_Index +{ +public: + debugluxel_ps20b_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_debugluxel_ps20b 0 +class debugluxel_ps20b_Dynamic_Index +{ +public: + debugluxel_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_debugluxel_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9/debugluxel_vs20.inc b/materialsystem/stdshaders/fxctmp9/debugluxel_vs20.inc new file mode 100644 index 0000000..5c1fb5a --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/debugluxel_vs20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class debugluxel_vs20_Static_Index +{ +public: + debugluxel_vs20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_debugluxel_vs20 0 +class debugluxel_vs20_Dynamic_Index +{ +public: + debugluxel_vs20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_debugluxel_vs20 0 diff --git a/materialsystem/stdshaders/fxctmp9/debugmorphaccumulator_ps30.inc b/materialsystem/stdshaders/fxctmp9/debugmorphaccumulator_ps30.inc new file mode 100644 index 0000000..9c5f179 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/debugmorphaccumulator_ps30.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class debugmorphaccumulator_ps30_Static_Index +{ +public: + debugmorphaccumulator_ps30_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_debugmorphaccumulator_ps30 0 +class debugmorphaccumulator_ps30_Dynamic_Index +{ +public: + debugmorphaccumulator_ps30_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_debugmorphaccumulator_ps30 0 diff --git a/materialsystem/stdshaders/fxctmp9/debugmorphaccumulator_vs30.inc b/materialsystem/stdshaders/fxctmp9/debugmorphaccumulator_vs30.inc new file mode 100644 index 0000000..4137dfd --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/debugmorphaccumulator_vs30.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class debugmorphaccumulator_vs30_Static_Index +{ +public: + debugmorphaccumulator_vs30_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_debugmorphaccumulator_vs30 0 +class debugmorphaccumulator_vs30_Dynamic_Index +{ +public: + debugmorphaccumulator_vs30_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_debugmorphaccumulator_vs30 0 diff --git a/materialsystem/stdshaders/fxctmp9/debugmrttexture_ps20.inc b/materialsystem/stdshaders/fxctmp9/debugmrttexture_ps20.inc new file mode 100644 index 0000000..90f5afd --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/debugmrttexture_ps20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class debugmrttexture_ps20_Static_Index +{ +private: + int m_nMRTINDEX; +#ifdef _DEBUG + bool m_bMRTINDEX; +#endif +public: + void SetMRTINDEX( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nMRTINDEX = i; +#ifdef _DEBUG + m_bMRTINDEX = true; +#endif + } + void SetMRTINDEX( bool i ) + { + m_nMRTINDEX = i ? 1 : 0; +#ifdef _DEBUG + m_bMRTINDEX = true; +#endif + } +public: + debugmrttexture_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bMRTINDEX = false; +#endif // _DEBUG + m_nMRTINDEX = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bMRTINDEX; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nMRTINDEX ) + 0; + } +}; +#define shaderStaticTest_debugmrttexture_ps20 psh_forgot_to_set_static_MRTINDEX + 0 +class debugmrttexture_ps20_Dynamic_Index +{ +public: + debugmrttexture_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_debugmrttexture_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9/debugmrttexture_ps20b.inc b/materialsystem/stdshaders/fxctmp9/debugmrttexture_ps20b.inc new file mode 100644 index 0000000..7cf15bc --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/debugmrttexture_ps20b.inc @@ -0,0 +1,85 @@ +#include "shaderlib/cshader.h" +class debugmrttexture_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +private: + int m_nMRTINDEX; +#ifdef _DEBUG + bool m_bMRTINDEX; +#endif +public: + void SetMRTINDEX( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nMRTINDEX = i; +#ifdef _DEBUG + m_bMRTINDEX = true; +#endif + } + void SetMRTINDEX( bool i ) + { + m_nMRTINDEX = i ? 1 : 0; +#ifdef _DEBUG + m_bMRTINDEX = true; +#endif + } +public: + debugmrttexture_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); +#ifdef _DEBUG + m_bMRTINDEX = false; +#endif // _DEBUG + m_nMRTINDEX = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB && m_bMRTINDEX; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + ( 2 * m_nMRTINDEX ) + 0; + } +}; +#define shaderStaticTest_debugmrttexture_ps20b psh_forgot_to_set_static_MRTINDEX + 0 +class debugmrttexture_ps20b_Dynamic_Index +{ +public: + debugmrttexture_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_debugmrttexture_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9/debugmrttexture_vs20.inc b/materialsystem/stdshaders/fxctmp9/debugmrttexture_vs20.inc new file mode 100644 index 0000000..35138b3 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/debugmrttexture_vs20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class debugmrttexture_vs20_Static_Index +{ +public: + debugmrttexture_vs20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_debugmrttexture_vs20 0 +class debugmrttexture_vs20_Dynamic_Index +{ +public: + debugmrttexture_vs20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_debugmrttexture_vs20 0 diff --git a/materialsystem/stdshaders/fxctmp9/debugtangentspace_vs11.inc b/materialsystem/stdshaders/fxctmp9/debugtangentspace_vs11.inc new file mode 100644 index 0000000..3b1e89c --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/debugtangentspace_vs11.inc @@ -0,0 +1,85 @@ +#include "shaderlib/cshader.h" +class debugtangentspace_vs11_Static_Index +{ +public: + debugtangentspace_vs11_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_debugtangentspace_vs11 0 +class debugtangentspace_vs11_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +public: + debugtangentspace_vs11_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG && m_bSKINNING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + ( 2 * m_nSKINNING ) + 0; + } +}; +#define shaderDynamicTest_debugtangentspace_vs11 vsh_forgot_to_set_dynamic_DOWATERFOG + vsh_forgot_to_set_dynamic_SKINNING + 0 diff --git a/materialsystem/stdshaders/fxctmp9/debugtangentspace_vs20.inc b/materialsystem/stdshaders/fxctmp9/debugtangentspace_vs20.inc new file mode 100644 index 0000000..f0e4f7c --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/debugtangentspace_vs20.inc @@ -0,0 +1,110 @@ +#include "shaderlib/cshader.h" +class debugtangentspace_vs20_Static_Index +{ +public: + debugtangentspace_vs20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_debugtangentspace_vs20 0 +class debugtangentspace_vs20_Dynamic_Index +{ +private: + int m_nCOMPRESSED_VERTS; +#ifdef _DEBUG + bool m_bCOMPRESSED_VERTS; +#endif +public: + void SetCOMPRESSED_VERTS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOMPRESSED_VERTS = i; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } + void SetCOMPRESSED_VERTS( bool i ) + { + m_nCOMPRESSED_VERTS = i ? 1 : 0; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +public: + debugtangentspace_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = false; +#endif // _DEBUG + m_nCOMPRESSED_VERTS = 0; +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bCOMPRESSED_VERTS && m_bDOWATERFOG && m_bSKINNING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCOMPRESSED_VERTS ) + ( 2 * m_nDOWATERFOG ) + ( 4 * m_nSKINNING ) + 0; + } +}; +#define shaderDynamicTest_debugtangentspace_vs20 vsh_forgot_to_set_dynamic_COMPRESSED_VERTS + vsh_forgot_to_set_dynamic_DOWATERFOG + vsh_forgot_to_set_dynamic_SKINNING + 0 diff --git a/materialsystem/stdshaders/fxctmp9/debugtextureview_ps20.inc b/materialsystem/stdshaders/fxctmp9/debugtextureview_ps20.inc new file mode 100644 index 0000000..a240ec7 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/debugtextureview_ps20.inc @@ -0,0 +1,87 @@ +#include "shaderlib/cshader.h" +class debugtextureview_ps20_Static_Index +{ +private: + int m_nSHOWALPHA; +#ifdef _DEBUG + bool m_bSHOWALPHA; +#endif +public: + void SetSHOWALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSHOWALPHA = i; +#ifdef _DEBUG + m_bSHOWALPHA = true; +#endif + } + void SetSHOWALPHA( bool i ) + { + m_nSHOWALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bSHOWALPHA = true; +#endif + } +public: + debugtextureview_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bSHOWALPHA = false; +#endif // _DEBUG + m_nSHOWALPHA = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bSHOWALPHA; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nSHOWALPHA ) + 0; + } +}; +#define shaderStaticTest_debugtextureview_ps20 psh_forgot_to_set_static_SHOWALPHA + 0 +class debugtextureview_ps20_Dynamic_Index +{ +private: + int m_nISCUBEMAP; +#ifdef _DEBUG + bool m_bISCUBEMAP; +#endif +public: + void SetISCUBEMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nISCUBEMAP = i; +#ifdef _DEBUG + m_bISCUBEMAP = true; +#endif + } + void SetISCUBEMAP( bool i ) + { + m_nISCUBEMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bISCUBEMAP = true; +#endif + } +public: + debugtextureview_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bISCUBEMAP = false; +#endif // _DEBUG + m_nISCUBEMAP = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bISCUBEMAP; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nISCUBEMAP ) + 0; + } +}; +#define shaderDynamicTest_debugtextureview_ps20 psh_forgot_to_set_dynamic_ISCUBEMAP + 0 diff --git a/materialsystem/stdshaders/fxctmp9/debugtextureview_ps20b.inc b/materialsystem/stdshaders/fxctmp9/debugtextureview_ps20b.inc new file mode 100644 index 0000000..3016544 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/debugtextureview_ps20b.inc @@ -0,0 +1,112 @@ +#include "shaderlib/cshader.h" +class debugtextureview_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +private: + int m_nSHOWALPHA; +#ifdef _DEBUG + bool m_bSHOWALPHA; +#endif +public: + void SetSHOWALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSHOWALPHA = i; +#ifdef _DEBUG + m_bSHOWALPHA = true; +#endif + } + void SetSHOWALPHA( bool i ) + { + m_nSHOWALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bSHOWALPHA = true; +#endif + } +public: + debugtextureview_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); +#ifdef _DEBUG + m_bSHOWALPHA = false; +#endif // _DEBUG + m_nSHOWALPHA = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB && m_bSHOWALPHA; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nCONVERT_TO_SRGB ) + ( 4 * m_nSHOWALPHA ) + 0; + } +}; +#define shaderStaticTest_debugtextureview_ps20b psh_forgot_to_set_static_SHOWALPHA + 0 +class debugtextureview_ps20b_Dynamic_Index +{ +private: + int m_nISCUBEMAP; +#ifdef _DEBUG + bool m_bISCUBEMAP; +#endif +public: + void SetISCUBEMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nISCUBEMAP = i; +#ifdef _DEBUG + m_bISCUBEMAP = true; +#endif + } + void SetISCUBEMAP( bool i ) + { + m_nISCUBEMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bISCUBEMAP = true; +#endif + } +public: + debugtextureview_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bISCUBEMAP = false; +#endif // _DEBUG + m_nISCUBEMAP = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bISCUBEMAP; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nISCUBEMAP ) + 0; + } +}; +#define shaderDynamicTest_debugtextureview_ps20b psh_forgot_to_set_dynamic_ISCUBEMAP + 0 diff --git a/materialsystem/stdshaders/fxctmp9/debugtextureview_vs20.inc b/materialsystem/stdshaders/fxctmp9/debugtextureview_vs20.inc new file mode 100644 index 0000000..bb43b05 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/debugtextureview_vs20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class debugtextureview_vs20_Static_Index +{ +public: + debugtextureview_vs20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_debugtextureview_vs20 0 +class debugtextureview_vs20_Dynamic_Index +{ +private: + int m_nCOMPRESSED_VERTS; +#ifdef _DEBUG + bool m_bCOMPRESSED_VERTS; +#endif +public: + void SetCOMPRESSED_VERTS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOMPRESSED_VERTS = i; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } + void SetCOMPRESSED_VERTS( bool i ) + { + m_nCOMPRESSED_VERTS = i ? 1 : 0; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } +public: + debugtextureview_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = false; +#endif // _DEBUG + m_nCOMPRESSED_VERTS = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bCOMPRESSED_VERTS; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCOMPRESSED_VERTS ) + 0; + } +}; +#define shaderDynamicTest_debugtextureview_vs20 vsh_forgot_to_set_dynamic_COMPRESSED_VERTS + 0 diff --git a/materialsystem/stdshaders/fxctmp9/decalbasetimeslightmapalphablendselfillum2_ps20.inc b/materialsystem/stdshaders/fxctmp9/decalbasetimeslightmapalphablendselfillum2_ps20.inc new file mode 100644 index 0000000..7fa4682 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/decalbasetimeslightmapalphablendselfillum2_ps20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class decalbasetimeslightmapalphablendselfillum2_ps20_Static_Index +{ +public: + decalbasetimeslightmapalphablendselfillum2_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_decalbasetimeslightmapalphablendselfillum2_ps20 0 +class decalbasetimeslightmapalphablendselfillum2_ps20_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + decalbasetimeslightmapalphablendselfillum2_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_decalbasetimeslightmapalphablendselfillum2_ps20 psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9/decalbasetimeslightmapalphablendselfillum2_ps20b.inc b/materialsystem/stdshaders/fxctmp9/decalbasetimeslightmapalphablendselfillum2_ps20b.inc new file mode 100644 index 0000000..5f58f38 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/decalbasetimeslightmapalphablendselfillum2_ps20b.inc @@ -0,0 +1,87 @@ +#include "shaderlib/cshader.h" +class decalbasetimeslightmapalphablendselfillum2_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + decalbasetimeslightmapalphablendselfillum2_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_decalbasetimeslightmapalphablendselfillum2_ps20b 0 +class decalbasetimeslightmapalphablendselfillum2_ps20b_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + decalbasetimeslightmapalphablendselfillum2_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_decalbasetimeslightmapalphablendselfillum2_ps20b psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9/decalmodulate_ps20.inc b/materialsystem/stdshaders/fxctmp9/decalmodulate_ps20.inc new file mode 100644 index 0000000..20976a8 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/decalmodulate_ps20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class decalmodulate_ps20_Static_Index +{ +public: + decalmodulate_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_decalmodulate_ps20 0 +class decalmodulate_ps20_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + decalmodulate_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_decalmodulate_ps20 psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9/decalmodulate_ps20b.inc b/materialsystem/stdshaders/fxctmp9/decalmodulate_ps20b.inc new file mode 100644 index 0000000..695e0e3 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/decalmodulate_ps20b.inc @@ -0,0 +1,87 @@ +#include "shaderlib/cshader.h" +class decalmodulate_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + decalmodulate_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_decalmodulate_ps20b 0 +class decalmodulate_ps20b_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + decalmodulate_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_decalmodulate_ps20b psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9/decalmodulate_ps30.inc b/materialsystem/stdshaders/fxctmp9/decalmodulate_ps30.inc new file mode 100644 index 0000000..4c6bb17 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/decalmodulate_ps30.inc @@ -0,0 +1,87 @@ +#include "shaderlib/cshader.h" +class decalmodulate_ps30_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + decalmodulate_ps30_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_decalmodulate_ps30 0 +class decalmodulate_ps30_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + decalmodulate_ps30_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_decalmodulate_ps30 psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9/depthtodestalpha_ps20b.inc b/materialsystem/stdshaders/fxctmp9/depthtodestalpha_ps20b.inc new file mode 100644 index 0000000..62375d8 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/depthtodestalpha_ps20b.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class depthtodestalpha_ps20b_Static_Index +{ +public: + depthtodestalpha_ps20b_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_depthtodestalpha_ps20b 0 +class depthtodestalpha_ps20b_Dynamic_Index +{ +public: + depthtodestalpha_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_depthtodestalpha_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9/depthtodestalpha_vs20.inc b/materialsystem/stdshaders/fxctmp9/depthtodestalpha_vs20.inc new file mode 100644 index 0000000..3e3744e --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/depthtodestalpha_vs20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class depthtodestalpha_vs20_Static_Index +{ +public: + depthtodestalpha_vs20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_depthtodestalpha_vs20 0 +class depthtodestalpha_vs20_Dynamic_Index +{ +public: + depthtodestalpha_vs20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_depthtodestalpha_vs20 0 diff --git a/materialsystem/stdshaders/fxctmp9/depthwrite_ps20.inc b/materialsystem/stdshaders/fxctmp9/depthwrite_ps20.inc new file mode 100644 index 0000000..d9be071 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/depthwrite_ps20.inc @@ -0,0 +1,87 @@ +#include "shaderlib/cshader.h" +class depthwrite_ps20_Static_Index +{ +private: + int m_nCOLOR_DEPTH; +#ifdef _DEBUG + bool m_bCOLOR_DEPTH; +#endif +public: + void SetCOLOR_DEPTH( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOLOR_DEPTH = i; +#ifdef _DEBUG + m_bCOLOR_DEPTH = true; +#endif + } + void SetCOLOR_DEPTH( bool i ) + { + m_nCOLOR_DEPTH = i ? 1 : 0; +#ifdef _DEBUG + m_bCOLOR_DEPTH = true; +#endif + } +public: + depthwrite_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCOLOR_DEPTH = false; +#endif // _DEBUG + m_nCOLOR_DEPTH = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCOLOR_DEPTH; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nCOLOR_DEPTH ) + 0; + } +}; +#define shaderStaticTest_depthwrite_ps20 psh_forgot_to_set_static_COLOR_DEPTH + 0 +class depthwrite_ps20_Dynamic_Index +{ +private: + int m_nALPHACLIP; +#ifdef _DEBUG + bool m_bALPHACLIP; +#endif +public: + void SetALPHACLIP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nALPHACLIP = i; +#ifdef _DEBUG + m_bALPHACLIP = true; +#endif + } + void SetALPHACLIP( bool i ) + { + m_nALPHACLIP = i ? 1 : 0; +#ifdef _DEBUG + m_bALPHACLIP = true; +#endif + } +public: + depthwrite_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bALPHACLIP = false; +#endif // _DEBUG + m_nALPHACLIP = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bALPHACLIP; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nALPHACLIP ) + 0; + } +}; +#define shaderDynamicTest_depthwrite_ps20 psh_forgot_to_set_dynamic_ALPHACLIP + 0 diff --git a/materialsystem/stdshaders/fxctmp9/depthwrite_ps20b.inc b/materialsystem/stdshaders/fxctmp9/depthwrite_ps20b.inc new file mode 100644 index 0000000..a3d0bf4 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/depthwrite_ps20b.inc @@ -0,0 +1,87 @@ +#include "shaderlib/cshader.h" +class depthwrite_ps20b_Static_Index +{ +private: + int m_nCOLOR_DEPTH; +#ifdef _DEBUG + bool m_bCOLOR_DEPTH; +#endif +public: + void SetCOLOR_DEPTH( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOLOR_DEPTH = i; +#ifdef _DEBUG + m_bCOLOR_DEPTH = true; +#endif + } + void SetCOLOR_DEPTH( bool i ) + { + m_nCOLOR_DEPTH = i ? 1 : 0; +#ifdef _DEBUG + m_bCOLOR_DEPTH = true; +#endif + } +public: + depthwrite_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCOLOR_DEPTH = false; +#endif // _DEBUG + m_nCOLOR_DEPTH = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCOLOR_DEPTH; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nCOLOR_DEPTH ) + 0; + } +}; +#define shaderStaticTest_depthwrite_ps20b psh_forgot_to_set_static_COLOR_DEPTH + 0 +class depthwrite_ps20b_Dynamic_Index +{ +private: + int m_nALPHACLIP; +#ifdef _DEBUG + bool m_bALPHACLIP; +#endif +public: + void SetALPHACLIP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nALPHACLIP = i; +#ifdef _DEBUG + m_bALPHACLIP = true; +#endif + } + void SetALPHACLIP( bool i ) + { + m_nALPHACLIP = i ? 1 : 0; +#ifdef _DEBUG + m_bALPHACLIP = true; +#endif + } +public: + depthwrite_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bALPHACLIP = false; +#endif // _DEBUG + m_nALPHACLIP = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bALPHACLIP; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nALPHACLIP ) + 0; + } +}; +#define shaderDynamicTest_depthwrite_ps20b psh_forgot_to_set_dynamic_ALPHACLIP + 0 diff --git a/materialsystem/stdshaders/fxctmp9/depthwrite_ps30.inc b/materialsystem/stdshaders/fxctmp9/depthwrite_ps30.inc new file mode 100644 index 0000000..af6d03c --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/depthwrite_ps30.inc @@ -0,0 +1,87 @@ +#include "shaderlib/cshader.h" +class depthwrite_ps30_Static_Index +{ +private: + int m_nCOLOR_DEPTH; +#ifdef _DEBUG + bool m_bCOLOR_DEPTH; +#endif +public: + void SetCOLOR_DEPTH( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOLOR_DEPTH = i; +#ifdef _DEBUG + m_bCOLOR_DEPTH = true; +#endif + } + void SetCOLOR_DEPTH( bool i ) + { + m_nCOLOR_DEPTH = i ? 1 : 0; +#ifdef _DEBUG + m_bCOLOR_DEPTH = true; +#endif + } +public: + depthwrite_ps30_Static_Index( ) + { +#ifdef _DEBUG + m_bCOLOR_DEPTH = false; +#endif // _DEBUG + m_nCOLOR_DEPTH = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCOLOR_DEPTH; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nCOLOR_DEPTH ) + 0; + } +}; +#define shaderStaticTest_depthwrite_ps30 psh_forgot_to_set_static_COLOR_DEPTH + 0 +class depthwrite_ps30_Dynamic_Index +{ +private: + int m_nALPHACLIP; +#ifdef _DEBUG + bool m_bALPHACLIP; +#endif +public: + void SetALPHACLIP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nALPHACLIP = i; +#ifdef _DEBUG + m_bALPHACLIP = true; +#endif + } + void SetALPHACLIP( bool i ) + { + m_nALPHACLIP = i ? 1 : 0; +#ifdef _DEBUG + m_bALPHACLIP = true; +#endif + } +public: + depthwrite_ps30_Dynamic_Index() + { +#ifdef _DEBUG + m_bALPHACLIP = false; +#endif // _DEBUG + m_nALPHACLIP = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bALPHACLIP; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nALPHACLIP ) + 0; + } +}; +#define shaderDynamicTest_depthwrite_ps30 psh_forgot_to_set_dynamic_ALPHACLIP + 0 diff --git a/materialsystem/stdshaders/fxctmp9/depthwrite_vs20.inc b/materialsystem/stdshaders/fxctmp9/depthwrite_vs20.inc new file mode 100644 index 0000000..7b94dc5 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/depthwrite_vs20.inc @@ -0,0 +1,137 @@ +#include "shaderlib/cshader.h" +class depthwrite_vs20_Static_Index +{ +private: + int m_nONLY_PROJECT_POSITION; +#ifdef _DEBUG + bool m_bONLY_PROJECT_POSITION; +#endif +public: + void SetONLY_PROJECT_POSITION( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nONLY_PROJECT_POSITION = i; +#ifdef _DEBUG + m_bONLY_PROJECT_POSITION = true; +#endif + } + void SetONLY_PROJECT_POSITION( bool i ) + { + m_nONLY_PROJECT_POSITION = i ? 1 : 0; +#ifdef _DEBUG + m_bONLY_PROJECT_POSITION = true; +#endif + } +private: + int m_nCOLOR_DEPTH; +#ifdef _DEBUG + bool m_bCOLOR_DEPTH; +#endif +public: + void SetCOLOR_DEPTH( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOLOR_DEPTH = i; +#ifdef _DEBUG + m_bCOLOR_DEPTH = true; +#endif + } + void SetCOLOR_DEPTH( bool i ) + { + m_nCOLOR_DEPTH = i ? 1 : 0; +#ifdef _DEBUG + m_bCOLOR_DEPTH = true; +#endif + } +public: + depthwrite_vs20_Static_Index( ) + { +#ifdef _DEBUG + m_bONLY_PROJECT_POSITION = false; +#endif // _DEBUG + m_nONLY_PROJECT_POSITION = 0; +#ifdef _DEBUG + m_bCOLOR_DEPTH = false; +#endif // _DEBUG + m_nCOLOR_DEPTH = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bONLY_PROJECT_POSITION && m_bCOLOR_DEPTH; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 4 * m_nONLY_PROJECT_POSITION ) + ( 4 * m_nCOLOR_DEPTH ) + 0; + } +}; +#define shaderStaticTest_depthwrite_vs20 vsh_forgot_to_set_static_ONLY_PROJECT_POSITION + vsh_forgot_to_set_static_COLOR_DEPTH + 0 +class depthwrite_vs20_Dynamic_Index +{ +private: + int m_nCOMPRESSED_VERTS; +#ifdef _DEBUG + bool m_bCOMPRESSED_VERTS; +#endif +public: + void SetCOMPRESSED_VERTS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOMPRESSED_VERTS = i; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } + void SetCOMPRESSED_VERTS( bool i ) + { + m_nCOMPRESSED_VERTS = i ? 1 : 0; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +public: + depthwrite_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = false; +#endif // _DEBUG + m_nCOMPRESSED_VERTS = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bCOMPRESSED_VERTS && m_bSKINNING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCOMPRESSED_VERTS ) + ( 2 * m_nSKINNING ) + 0; + } +}; +#define shaderDynamicTest_depthwrite_vs20 vsh_forgot_to_set_dynamic_COMPRESSED_VERTS + vsh_forgot_to_set_dynamic_SKINNING + 0 diff --git a/materialsystem/stdshaders/fxctmp9/depthwrite_vs30.inc b/materialsystem/stdshaders/fxctmp9/depthwrite_vs30.inc new file mode 100644 index 0000000..36d3c3f --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/depthwrite_vs30.inc @@ -0,0 +1,162 @@ +#include "shaderlib/cshader.h" +class depthwrite_vs30_Static_Index +{ +private: + int m_nONLY_PROJECT_POSITION; +#ifdef _DEBUG + bool m_bONLY_PROJECT_POSITION; +#endif +public: + void SetONLY_PROJECT_POSITION( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nONLY_PROJECT_POSITION = i; +#ifdef _DEBUG + m_bONLY_PROJECT_POSITION = true; +#endif + } + void SetONLY_PROJECT_POSITION( bool i ) + { + m_nONLY_PROJECT_POSITION = i ? 1 : 0; +#ifdef _DEBUG + m_bONLY_PROJECT_POSITION = true; +#endif + } +private: + int m_nCOLOR_DEPTH; +#ifdef _DEBUG + bool m_bCOLOR_DEPTH; +#endif +public: + void SetCOLOR_DEPTH( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOLOR_DEPTH = i; +#ifdef _DEBUG + m_bCOLOR_DEPTH = true; +#endif + } + void SetCOLOR_DEPTH( bool i ) + { + m_nCOLOR_DEPTH = i ? 1 : 0; +#ifdef _DEBUG + m_bCOLOR_DEPTH = true; +#endif + } +public: + depthwrite_vs30_Static_Index( ) + { +#ifdef _DEBUG + m_bONLY_PROJECT_POSITION = false; +#endif // _DEBUG + m_nONLY_PROJECT_POSITION = 0; +#ifdef _DEBUG + m_bCOLOR_DEPTH = false; +#endif // _DEBUG + m_nCOLOR_DEPTH = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bONLY_PROJECT_POSITION && m_bCOLOR_DEPTH; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 8 * m_nONLY_PROJECT_POSITION ) + ( 8 * m_nCOLOR_DEPTH ) + 0; + } +}; +#define shaderStaticTest_depthwrite_vs30 vsh_forgot_to_set_static_ONLY_PROJECT_POSITION + vsh_forgot_to_set_static_COLOR_DEPTH + 0 +class depthwrite_vs30_Dynamic_Index +{ +private: + int m_nCOMPRESSED_VERTS; +#ifdef _DEBUG + bool m_bCOMPRESSED_VERTS; +#endif +public: + void SetCOMPRESSED_VERTS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOMPRESSED_VERTS = i; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } + void SetCOMPRESSED_VERTS( bool i ) + { + m_nCOMPRESSED_VERTS = i ? 1 : 0; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +private: + int m_nMORPHING; +#ifdef _DEBUG + bool m_bMORPHING; +#endif +public: + void SetMORPHING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nMORPHING = i; +#ifdef _DEBUG + m_bMORPHING = true; +#endif + } + void SetMORPHING( bool i ) + { + m_nMORPHING = i ? 1 : 0; +#ifdef _DEBUG + m_bMORPHING = true; +#endif + } +public: + depthwrite_vs30_Dynamic_Index() + { +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = false; +#endif // _DEBUG + m_nCOMPRESSED_VERTS = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; +#ifdef _DEBUG + m_bMORPHING = false; +#endif // _DEBUG + m_nMORPHING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bCOMPRESSED_VERTS && m_bSKINNING && m_bMORPHING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCOMPRESSED_VERTS ) + ( 2 * m_nSKINNING ) + ( 4 * m_nMORPHING ) + 0; + } +}; +#define shaderDynamicTest_depthwrite_vs30 vsh_forgot_to_set_dynamic_COMPRESSED_VERTS + vsh_forgot_to_set_dynamic_SKINNING + vsh_forgot_to_set_dynamic_MORPHING + 0 diff --git a/materialsystem/stdshaders/fxctmp9/emissive_scroll_blended_pass_ps20.inc b/materialsystem/stdshaders/fxctmp9/emissive_scroll_blended_pass_ps20.inc new file mode 100644 index 0000000..e02f691 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/emissive_scroll_blended_pass_ps20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class emissive_scroll_blended_pass_ps20_Static_Index +{ +public: + emissive_scroll_blended_pass_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_emissive_scroll_blended_pass_ps20 0 +class emissive_scroll_blended_pass_ps20_Dynamic_Index +{ +public: + emissive_scroll_blended_pass_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_emissive_scroll_blended_pass_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9/emissive_scroll_blended_pass_ps20b.inc b/materialsystem/stdshaders/fxctmp9/emissive_scroll_blended_pass_ps20b.inc new file mode 100644 index 0000000..a2989a3 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/emissive_scroll_blended_pass_ps20b.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class emissive_scroll_blended_pass_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + emissive_scroll_blended_pass_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_emissive_scroll_blended_pass_ps20b 0 +class emissive_scroll_blended_pass_ps20b_Dynamic_Index +{ +public: + emissive_scroll_blended_pass_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_emissive_scroll_blended_pass_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9/emissive_scroll_blended_pass_ps30.inc b/materialsystem/stdshaders/fxctmp9/emissive_scroll_blended_pass_ps30.inc new file mode 100644 index 0000000..83384e4 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/emissive_scroll_blended_pass_ps30.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class emissive_scroll_blended_pass_ps30_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + emissive_scroll_blended_pass_ps30_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_emissive_scroll_blended_pass_ps30 0 +class emissive_scroll_blended_pass_ps30_Dynamic_Index +{ +public: + emissive_scroll_blended_pass_ps30_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_emissive_scroll_blended_pass_ps30 0 diff --git a/materialsystem/stdshaders/fxctmp9/emissive_scroll_blended_pass_vs20.inc b/materialsystem/stdshaders/fxctmp9/emissive_scroll_blended_pass_vs20.inc new file mode 100644 index 0000000..c29b0b1 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/emissive_scroll_blended_pass_vs20.inc @@ -0,0 +1,85 @@ +#include "shaderlib/cshader.h" +class emissive_scroll_blended_pass_vs20_Static_Index +{ +public: + emissive_scroll_blended_pass_vs20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_emissive_scroll_blended_pass_vs20 0 +class emissive_scroll_blended_pass_vs20_Dynamic_Index +{ +private: + int m_nCOMPRESSED_VERTS; +#ifdef _DEBUG + bool m_bCOMPRESSED_VERTS; +#endif +public: + void SetCOMPRESSED_VERTS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOMPRESSED_VERTS = i; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } + void SetCOMPRESSED_VERTS( bool i ) + { + m_nCOMPRESSED_VERTS = i ? 1 : 0; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +public: + emissive_scroll_blended_pass_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = false; +#endif // _DEBUG + m_nCOMPRESSED_VERTS = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bCOMPRESSED_VERTS && m_bSKINNING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCOMPRESSED_VERTS ) + ( 2 * m_nSKINNING ) + 0; + } +}; +#define shaderDynamicTest_emissive_scroll_blended_pass_vs20 vsh_forgot_to_set_dynamic_COMPRESSED_VERTS + vsh_forgot_to_set_dynamic_SKINNING + 0 diff --git a/materialsystem/stdshaders/fxctmp9/emissive_scroll_blended_pass_vs30.inc b/materialsystem/stdshaders/fxctmp9/emissive_scroll_blended_pass_vs30.inc new file mode 100644 index 0000000..464117d --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/emissive_scroll_blended_pass_vs30.inc @@ -0,0 +1,110 @@ +#include "shaderlib/cshader.h" +class emissive_scroll_blended_pass_vs30_Static_Index +{ +public: + emissive_scroll_blended_pass_vs30_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_emissive_scroll_blended_pass_vs30 0 +class emissive_scroll_blended_pass_vs30_Dynamic_Index +{ +private: + int m_nCOMPRESSED_VERTS; +#ifdef _DEBUG + bool m_bCOMPRESSED_VERTS; +#endif +public: + void SetCOMPRESSED_VERTS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOMPRESSED_VERTS = i; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } + void SetCOMPRESSED_VERTS( bool i ) + { + m_nCOMPRESSED_VERTS = i ? 1 : 0; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +private: + int m_nMORPHING; +#ifdef _DEBUG + bool m_bMORPHING; +#endif +public: + void SetMORPHING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nMORPHING = i; +#ifdef _DEBUG + m_bMORPHING = true; +#endif + } + void SetMORPHING( bool i ) + { + m_nMORPHING = i ? 1 : 0; +#ifdef _DEBUG + m_bMORPHING = true; +#endif + } +public: + emissive_scroll_blended_pass_vs30_Dynamic_Index() + { +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = false; +#endif // _DEBUG + m_nCOMPRESSED_VERTS = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; +#ifdef _DEBUG + m_bMORPHING = false; +#endif // _DEBUG + m_nMORPHING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bCOMPRESSED_VERTS && m_bSKINNING && m_bMORPHING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCOMPRESSED_VERTS ) + ( 2 * m_nSKINNING ) + ( 4 * m_nMORPHING ) + 0; + } +}; +#define shaderDynamicTest_emissive_scroll_blended_pass_vs30 vsh_forgot_to_set_dynamic_COMPRESSED_VERTS + vsh_forgot_to_set_dynamic_SKINNING + vsh_forgot_to_set_dynamic_MORPHING + 0 diff --git a/materialsystem/stdshaders/fxctmp9/engine_post_ps20.inc b/materialsystem/stdshaders/fxctmp9/engine_post_ps20.inc new file mode 100644 index 0000000..c6e922f --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/engine_post_ps20.inc @@ -0,0 +1,135 @@ +#include "shaderlib/cshader.h" +class engine_post_ps20_Static_Index +{ +public: + engine_post_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_engine_post_ps20 0 +class engine_post_ps20_Dynamic_Index +{ +private: + int m_nAA_ENABLE; +#ifdef _DEBUG + bool m_bAA_ENABLE; +#endif +public: + void SetAA_ENABLE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nAA_ENABLE = i; +#ifdef _DEBUG + m_bAA_ENABLE = true; +#endif + } + void SetAA_ENABLE( bool i ) + { + m_nAA_ENABLE = i ? 1 : 0; +#ifdef _DEBUG + m_bAA_ENABLE = true; +#endif + } +private: + int m_nAA_QUALITY_MODE; +#ifdef _DEBUG + bool m_bAA_QUALITY_MODE; +#endif +public: + void SetAA_QUALITY_MODE( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nAA_QUALITY_MODE = i; +#ifdef _DEBUG + m_bAA_QUALITY_MODE = true; +#endif + } + void SetAA_QUALITY_MODE( bool i ) + { + m_nAA_QUALITY_MODE = i ? 1 : 0; +#ifdef _DEBUG + m_bAA_QUALITY_MODE = true; +#endif + } +private: + int m_nAA_REDUCE_ONE_PIXEL_LINE_BLUR; +#ifdef _DEBUG + bool m_bAA_REDUCE_ONE_PIXEL_LINE_BLUR; +#endif +public: + void SetAA_REDUCE_ONE_PIXEL_LINE_BLUR( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nAA_REDUCE_ONE_PIXEL_LINE_BLUR = i; +#ifdef _DEBUG + m_bAA_REDUCE_ONE_PIXEL_LINE_BLUR = true; +#endif + } + void SetAA_REDUCE_ONE_PIXEL_LINE_BLUR( bool i ) + { + m_nAA_REDUCE_ONE_PIXEL_LINE_BLUR = i ? 1 : 0; +#ifdef _DEBUG + m_bAA_REDUCE_ONE_PIXEL_LINE_BLUR = true; +#endif + } +private: + int m_nCOL_CORRECT_NUM_LOOKUPS; +#ifdef _DEBUG + bool m_bCOL_CORRECT_NUM_LOOKUPS; +#endif +public: + void SetCOL_CORRECT_NUM_LOOKUPS( int i ) + { + Assert( i >= 0 && i <= 4 ); + m_nCOL_CORRECT_NUM_LOOKUPS = i; +#ifdef _DEBUG + m_bCOL_CORRECT_NUM_LOOKUPS = true; +#endif + } + void SetCOL_CORRECT_NUM_LOOKUPS( bool i ) + { + m_nCOL_CORRECT_NUM_LOOKUPS = i ? 1 : 0; +#ifdef _DEBUG + m_bCOL_CORRECT_NUM_LOOKUPS = true; +#endif + } +public: + engine_post_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bAA_ENABLE = false; +#endif // _DEBUG + m_nAA_ENABLE = 0; +#ifdef _DEBUG + m_bAA_QUALITY_MODE = false; +#endif // _DEBUG + m_nAA_QUALITY_MODE = 0; +#ifdef _DEBUG + m_bAA_REDUCE_ONE_PIXEL_LINE_BLUR = false; +#endif // _DEBUG + m_nAA_REDUCE_ONE_PIXEL_LINE_BLUR = 0; +#ifdef _DEBUG + m_bCOL_CORRECT_NUM_LOOKUPS = false; +#endif // _DEBUG + m_nCOL_CORRECT_NUM_LOOKUPS = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bAA_ENABLE && m_bAA_QUALITY_MODE && m_bAA_REDUCE_ONE_PIXEL_LINE_BLUR && m_bCOL_CORRECT_NUM_LOOKUPS; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nAA_ENABLE ) + ( 2 * m_nAA_QUALITY_MODE ) + ( 2 * m_nAA_REDUCE_ONE_PIXEL_LINE_BLUR ) + ( 2 * m_nCOL_CORRECT_NUM_LOOKUPS ) + 0; + } +}; +#define shaderDynamicTest_engine_post_ps20 psh_forgot_to_set_dynamic_AA_ENABLE + psh_forgot_to_set_dynamic_AA_QUALITY_MODE + psh_forgot_to_set_dynamic_AA_REDUCE_ONE_PIXEL_LINE_BLUR + psh_forgot_to_set_dynamic_COL_CORRECT_NUM_LOOKUPS + 0 diff --git a/materialsystem/stdshaders/fxctmp9/engine_post_ps20b.inc b/materialsystem/stdshaders/fxctmp9/engine_post_ps20b.inc new file mode 100644 index 0000000..47609c1 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/engine_post_ps20b.inc @@ -0,0 +1,212 @@ +#include "shaderlib/cshader.h" +class engine_post_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +private: + int m_nLINEAR_INPUT; +#ifdef _DEBUG + bool m_bLINEAR_INPUT; +#endif +public: + void SetLINEAR_INPUT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nLINEAR_INPUT = i; +#ifdef _DEBUG + m_bLINEAR_INPUT = true; +#endif + } + void SetLINEAR_INPUT( bool i ) + { + m_nLINEAR_INPUT = i ? 1 : 0; +#ifdef _DEBUG + m_bLINEAR_INPUT = true; +#endif + } +private: + int m_nLINEAR_OUTPUT; +#ifdef _DEBUG + bool m_bLINEAR_OUTPUT; +#endif +public: + void SetLINEAR_OUTPUT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nLINEAR_OUTPUT = i; +#ifdef _DEBUG + m_bLINEAR_OUTPUT = true; +#endif + } + void SetLINEAR_OUTPUT( bool i ) + { + m_nLINEAR_OUTPUT = i ? 1 : 0; +#ifdef _DEBUG + m_bLINEAR_OUTPUT = true; +#endif + } +public: + engine_post_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); +#ifdef _DEBUG + m_bLINEAR_INPUT = false; +#endif // _DEBUG + m_nLINEAR_INPUT = 0; +#ifdef _DEBUG + m_bLINEAR_OUTPUT = false; +#endif // _DEBUG + m_nLINEAR_OUTPUT = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB && m_bLINEAR_INPUT && m_bLINEAR_OUTPUT; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 40 * m_nCONVERT_TO_SRGB ) + ( 80 * m_nLINEAR_INPUT ) + ( 160 * m_nLINEAR_OUTPUT ) + 0; + } +}; +#define shaderStaticTest_engine_post_ps20b psh_forgot_to_set_static_LINEAR_INPUT + psh_forgot_to_set_static_LINEAR_OUTPUT + 0 +class engine_post_ps20b_Dynamic_Index +{ +private: + int m_nAA_ENABLE; +#ifdef _DEBUG + bool m_bAA_ENABLE; +#endif +public: + void SetAA_ENABLE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nAA_ENABLE = i; +#ifdef _DEBUG + m_bAA_ENABLE = true; +#endif + } + void SetAA_ENABLE( bool i ) + { + m_nAA_ENABLE = i ? 1 : 0; +#ifdef _DEBUG + m_bAA_ENABLE = true; +#endif + } +private: + int m_nAA_QUALITY_MODE; +#ifdef _DEBUG + bool m_bAA_QUALITY_MODE; +#endif +public: + void SetAA_QUALITY_MODE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nAA_QUALITY_MODE = i; +#ifdef _DEBUG + m_bAA_QUALITY_MODE = true; +#endif + } + void SetAA_QUALITY_MODE( bool i ) + { + m_nAA_QUALITY_MODE = i ? 1 : 0; +#ifdef _DEBUG + m_bAA_QUALITY_MODE = true; +#endif + } +private: + int m_nAA_REDUCE_ONE_PIXEL_LINE_BLUR; +#ifdef _DEBUG + bool m_bAA_REDUCE_ONE_PIXEL_LINE_BLUR; +#endif +public: + void SetAA_REDUCE_ONE_PIXEL_LINE_BLUR( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nAA_REDUCE_ONE_PIXEL_LINE_BLUR = i; +#ifdef _DEBUG + m_bAA_REDUCE_ONE_PIXEL_LINE_BLUR = true; +#endif + } + void SetAA_REDUCE_ONE_PIXEL_LINE_BLUR( bool i ) + { + m_nAA_REDUCE_ONE_PIXEL_LINE_BLUR = i ? 1 : 0; +#ifdef _DEBUG + m_bAA_REDUCE_ONE_PIXEL_LINE_BLUR = true; +#endif + } +private: + int m_nCOL_CORRECT_NUM_LOOKUPS; +#ifdef _DEBUG + bool m_bCOL_CORRECT_NUM_LOOKUPS; +#endif +public: + void SetCOL_CORRECT_NUM_LOOKUPS( int i ) + { + Assert( i >= 0 && i <= 4 ); + m_nCOL_CORRECT_NUM_LOOKUPS = i; +#ifdef _DEBUG + m_bCOL_CORRECT_NUM_LOOKUPS = true; +#endif + } + void SetCOL_CORRECT_NUM_LOOKUPS( bool i ) + { + m_nCOL_CORRECT_NUM_LOOKUPS = i ? 1 : 0; +#ifdef _DEBUG + m_bCOL_CORRECT_NUM_LOOKUPS = true; +#endif + } +public: + engine_post_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bAA_ENABLE = false; +#endif // _DEBUG + m_nAA_ENABLE = 0; +#ifdef _DEBUG + m_bAA_QUALITY_MODE = false; +#endif // _DEBUG + m_nAA_QUALITY_MODE = 0; +#ifdef _DEBUG + m_bAA_REDUCE_ONE_PIXEL_LINE_BLUR = false; +#endif // _DEBUG + m_nAA_REDUCE_ONE_PIXEL_LINE_BLUR = 0; +#ifdef _DEBUG + m_bCOL_CORRECT_NUM_LOOKUPS = false; +#endif // _DEBUG + m_nCOL_CORRECT_NUM_LOOKUPS = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bAA_ENABLE && m_bAA_QUALITY_MODE && m_bAA_REDUCE_ONE_PIXEL_LINE_BLUR && m_bCOL_CORRECT_NUM_LOOKUPS; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nAA_ENABLE ) + ( 2 * m_nAA_QUALITY_MODE ) + ( 4 * m_nAA_REDUCE_ONE_PIXEL_LINE_BLUR ) + ( 8 * m_nCOL_CORRECT_NUM_LOOKUPS ) + 0; + } +}; +#define shaderDynamicTest_engine_post_ps20b psh_forgot_to_set_dynamic_AA_ENABLE + psh_forgot_to_set_dynamic_AA_QUALITY_MODE + psh_forgot_to_set_dynamic_AA_REDUCE_ONE_PIXEL_LINE_BLUR + psh_forgot_to_set_dynamic_COL_CORRECT_NUM_LOOKUPS + 0 diff --git a/materialsystem/stdshaders/fxctmp9/example_model_ps20b.inc b/materialsystem/stdshaders/fxctmp9/example_model_ps20b.inc new file mode 100644 index 0000000..1d9a37a --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/example_model_ps20b.inc @@ -0,0 +1,237 @@ +#include "shaderlib/cshader.h" +class example_model_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +private: + int m_nFLASHLIGHT; +#ifdef _DEBUG + bool m_bFLASHLIGHT; +#endif +public: + void SetFLASHLIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFLASHLIGHT = i; +#ifdef _DEBUG + m_bFLASHLIGHT = true; +#endif + } + void SetFLASHLIGHT( bool i ) + { + m_nFLASHLIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bFLASHLIGHT = true; +#endif + } +private: + int m_nFLASHLIGHTDEPTHFILTERMODE; +#ifdef _DEBUG + bool m_bFLASHLIGHTDEPTHFILTERMODE; +#endif +public: + void SetFLASHLIGHTDEPTHFILTERMODE( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nFLASHLIGHTDEPTHFILTERMODE = i; +#ifdef _DEBUG + m_bFLASHLIGHTDEPTHFILTERMODE = true; +#endif + } + void SetFLASHLIGHTDEPTHFILTERMODE( bool i ) + { + m_nFLASHLIGHTDEPTHFILTERMODE = i ? 1 : 0; +#ifdef _DEBUG + m_bFLASHLIGHTDEPTHFILTERMODE = true; +#endif + } +public: + example_model_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = false; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; +#ifdef _DEBUG + m_bFLASHLIGHT = false; +#endif // _DEBUG + m_nFLASHLIGHT = 0; +#ifdef _DEBUG + m_bFLASHLIGHTDEPTHFILTERMODE = false; +#endif // _DEBUG + m_nFLASHLIGHTDEPTHFILTERMODE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB && m_bFLASHLIGHT && m_bFLASHLIGHTDEPTHFILTERMODE; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 80 * m_nCONVERT_TO_SRGB ) + ( 80 * m_nFLASHLIGHT ) + ( 160 * m_nFLASHLIGHTDEPTHFILTERMODE ) + 0; + } +}; +#define shaderStaticTest_example_model_ps20b psh_forgot_to_set_static_CONVERT_TO_SRGB + psh_forgot_to_set_static_FLASHLIGHT + psh_forgot_to_set_static_FLASHLIGHTDEPTHFILTERMODE + 0 +class example_model_ps20b_Dynamic_Index +{ +private: + int m_nWRITEWATERFOGTODESTALPHA; +#ifdef _DEBUG + bool m_bWRITEWATERFOGTODESTALPHA; +#endif +public: + void SetWRITEWATERFOGTODESTALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nWRITEWATERFOGTODESTALPHA = i; +#ifdef _DEBUG + m_bWRITEWATERFOGTODESTALPHA = true; +#endif + } + void SetWRITEWATERFOGTODESTALPHA( bool i ) + { + m_nWRITEWATERFOGTODESTALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bWRITEWATERFOGTODESTALPHA = true; +#endif + } +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +private: + int m_nNUM_LIGHTS; +#ifdef _DEBUG + bool m_bNUM_LIGHTS; +#endif +public: + void SetNUM_LIGHTS( int i ) + { + Assert( i >= 0 && i <= 4 ); + m_nNUM_LIGHTS = i; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } + void SetNUM_LIGHTS( bool i ) + { + m_nNUM_LIGHTS = i ? 1 : 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } +private: + int m_nWRITE_DEPTH_TO_DESTALPHA; +#ifdef _DEBUG + bool m_bWRITE_DEPTH_TO_DESTALPHA; +#endif +public: + void SetWRITE_DEPTH_TO_DESTALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nWRITE_DEPTH_TO_DESTALPHA = i; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = true; +#endif + } + void SetWRITE_DEPTH_TO_DESTALPHA( bool i ) + { + m_nWRITE_DEPTH_TO_DESTALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = true; +#endif + } +private: + int m_nFLASHLIGHTSHADOWS; +#ifdef _DEBUG + bool m_bFLASHLIGHTSHADOWS; +#endif +public: + void SetFLASHLIGHTSHADOWS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFLASHLIGHTSHADOWS = i; +#ifdef _DEBUG + m_bFLASHLIGHTSHADOWS = true; +#endif + } + void SetFLASHLIGHTSHADOWS( bool i ) + { + m_nFLASHLIGHTSHADOWS = i ? 1 : 0; +#ifdef _DEBUG + m_bFLASHLIGHTSHADOWS = true; +#endif + } +public: + example_model_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bWRITEWATERFOGTODESTALPHA = false; +#endif // _DEBUG + m_nWRITEWATERFOGTODESTALPHA = 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = false; +#endif // _DEBUG + m_nNUM_LIGHTS = 0; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = false; +#endif // _DEBUG + m_nWRITE_DEPTH_TO_DESTALPHA = 0; +#ifdef _DEBUG + m_bFLASHLIGHTSHADOWS = false; +#endif // _DEBUG + m_nFLASHLIGHTSHADOWS = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bWRITEWATERFOGTODESTALPHA && m_bPIXELFOGTYPE && m_bNUM_LIGHTS && m_bWRITE_DEPTH_TO_DESTALPHA && m_bFLASHLIGHTSHADOWS; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nWRITEWATERFOGTODESTALPHA ) + ( 2 * m_nPIXELFOGTYPE ) + ( 4 * m_nNUM_LIGHTS ) + ( 20 * m_nWRITE_DEPTH_TO_DESTALPHA ) + ( 40 * m_nFLASHLIGHTSHADOWS ) + 0; + } +}; +#define shaderDynamicTest_example_model_ps20b psh_forgot_to_set_dynamic_WRITEWATERFOGTODESTALPHA + psh_forgot_to_set_dynamic_PIXELFOGTYPE + psh_forgot_to_set_dynamic_NUM_LIGHTS + psh_forgot_to_set_dynamic_WRITE_DEPTH_TO_DESTALPHA + psh_forgot_to_set_dynamic_FLASHLIGHTSHADOWS + 0 diff --git a/materialsystem/stdshaders/fxctmp9/example_model_vs20.inc b/materialsystem/stdshaders/fxctmp9/example_model_vs20.inc new file mode 100644 index 0000000..fcd08eb --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/example_model_vs20.inc @@ -0,0 +1,160 @@ +#include "shaderlib/cshader.h" +class example_model_vs20_Static_Index +{ +public: + example_model_vs20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_example_model_vs20 0 +class example_model_vs20_Dynamic_Index +{ +private: + int m_nCOMPRESSED_VERTS; +#ifdef _DEBUG + bool m_bCOMPRESSED_VERTS; +#endif +public: + void SetCOMPRESSED_VERTS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOMPRESSED_VERTS = i; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } + void SetCOMPRESSED_VERTS( bool i ) + { + m_nCOMPRESSED_VERTS = i ? 1 : 0; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +private: + int m_nLIGHTING_PREVIEW; +#ifdef _DEBUG + bool m_bLIGHTING_PREVIEW; +#endif +public: + void SetLIGHTING_PREVIEW( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nLIGHTING_PREVIEW = i; +#ifdef _DEBUG + m_bLIGHTING_PREVIEW = true; +#endif + } + void SetLIGHTING_PREVIEW( bool i ) + { + m_nLIGHTING_PREVIEW = i ? 1 : 0; +#ifdef _DEBUG + m_bLIGHTING_PREVIEW = true; +#endif + } +private: + int m_nNUM_LIGHTS; +#ifdef _DEBUG + bool m_bNUM_LIGHTS; +#endif +public: + void SetNUM_LIGHTS( int i ) + { + Assert( i >= 0 && i <= 4 ); + m_nNUM_LIGHTS = i; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } + void SetNUM_LIGHTS( bool i ) + { + m_nNUM_LIGHTS = i ? 1 : 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } +public: + example_model_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = false; +#endif // _DEBUG + m_nCOMPRESSED_VERTS = 0; +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; +#ifdef _DEBUG + m_bLIGHTING_PREVIEW = false; +#endif // _DEBUG + m_nLIGHTING_PREVIEW = 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = false; +#endif // _DEBUG + m_nNUM_LIGHTS = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bCOMPRESSED_VERTS && m_bDOWATERFOG && m_bSKINNING && m_bLIGHTING_PREVIEW && m_bNUM_LIGHTS; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCOMPRESSED_VERTS ) + ( 2 * m_nDOWATERFOG ) + ( 4 * m_nSKINNING ) + ( 8 * m_nLIGHTING_PREVIEW ) + ( 16 * m_nNUM_LIGHTS ) + 0; + } +}; +#define shaderDynamicTest_example_model_vs20 vsh_forgot_to_set_dynamic_COMPRESSED_VERTS + vsh_forgot_to_set_dynamic_DOWATERFOG + vsh_forgot_to_set_dynamic_SKINNING + vsh_forgot_to_set_dynamic_LIGHTING_PREVIEW + vsh_forgot_to_set_dynamic_NUM_LIGHTS + 0 diff --git a/materialsystem/stdshaders/fxctmp9/eye_refract_ps20.inc b/materialsystem/stdshaders/fxctmp9/eye_refract_ps20.inc new file mode 100644 index 0000000..eb316dd --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/eye_refract_ps20.inc @@ -0,0 +1,112 @@ +#include "shaderlib/cshader.h" +class eye_refract_ps20_Static_Index +{ +private: + int m_nFLASHLIGHT; +#ifdef _DEBUG + bool m_bFLASHLIGHT; +#endif +public: + void SetFLASHLIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFLASHLIGHT = i; +#ifdef _DEBUG + m_bFLASHLIGHT = true; +#endif + } + void SetFLASHLIGHT( bool i ) + { + m_nFLASHLIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bFLASHLIGHT = true; +#endif + } +private: + int m_nLIGHTWARPTEXTURE; +#ifdef _DEBUG + bool m_bLIGHTWARPTEXTURE; +#endif +public: + void SetLIGHTWARPTEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nLIGHTWARPTEXTURE = i; +#ifdef _DEBUG + m_bLIGHTWARPTEXTURE = true; +#endif + } + void SetLIGHTWARPTEXTURE( bool i ) + { + m_nLIGHTWARPTEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bLIGHTWARPTEXTURE = true; +#endif + } +public: + eye_refract_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bFLASHLIGHT = false; +#endif // _DEBUG + m_nFLASHLIGHT = 0; +#ifdef _DEBUG + m_bLIGHTWARPTEXTURE = false; +#endif // _DEBUG + m_nLIGHTWARPTEXTURE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bFLASHLIGHT && m_bLIGHTWARPTEXTURE; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 3 * m_nFLASHLIGHT ) + ( 6 * m_nLIGHTWARPTEXTURE ) + 0; + } +}; +#define shaderStaticTest_eye_refract_ps20 psh_forgot_to_set_static_FLASHLIGHT + psh_forgot_to_set_static_LIGHTWARPTEXTURE + 0 +class eye_refract_ps20_Dynamic_Index +{ +private: + int m_nNUM_LIGHTS; +#ifdef _DEBUG + bool m_bNUM_LIGHTS; +#endif +public: + void SetNUM_LIGHTS( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nNUM_LIGHTS = i; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } + void SetNUM_LIGHTS( bool i ) + { + m_nNUM_LIGHTS = i ? 1 : 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } +public: + eye_refract_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bNUM_LIGHTS = false; +#endif // _DEBUG + m_nNUM_LIGHTS = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bNUM_LIGHTS; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nNUM_LIGHTS ) + 0; + } +}; +#define shaderDynamicTest_eye_refract_ps20 psh_forgot_to_set_dynamic_NUM_LIGHTS + 0 diff --git a/materialsystem/stdshaders/fxctmp9/eye_refract_ps20b.inc b/materialsystem/stdshaders/fxctmp9/eye_refract_ps20b.inc new file mode 100644 index 0000000..815c318 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/eye_refract_ps20b.inc @@ -0,0 +1,212 @@ +#include "shaderlib/cshader.h" +class eye_refract_ps20b_Static_Index +{ +private: + int m_nFLASHLIGHT; +#ifdef _DEBUG + bool m_bFLASHLIGHT; +#endif +public: + void SetFLASHLIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFLASHLIGHT = i; +#ifdef _DEBUG + m_bFLASHLIGHT = true; +#endif + } + void SetFLASHLIGHT( bool i ) + { + m_nFLASHLIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bFLASHLIGHT = true; +#endif + } +private: + int m_nLIGHTWARPTEXTURE; +#ifdef _DEBUG + bool m_bLIGHTWARPTEXTURE; +#endif +public: + void SetLIGHTWARPTEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nLIGHTWARPTEXTURE = i; +#ifdef _DEBUG + m_bLIGHTWARPTEXTURE = true; +#endif + } + void SetLIGHTWARPTEXTURE( bool i ) + { + m_nLIGHTWARPTEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bLIGHTWARPTEXTURE = true; +#endif + } +private: + int m_nSPHERETEXKILLCOMBO; +#ifdef _DEBUG + bool m_bSPHERETEXKILLCOMBO; +#endif +public: + void SetSPHERETEXKILLCOMBO( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSPHERETEXKILLCOMBO = i; +#ifdef _DEBUG + m_bSPHERETEXKILLCOMBO = true; +#endif + } + void SetSPHERETEXKILLCOMBO( bool i ) + { + m_nSPHERETEXKILLCOMBO = i ? 1 : 0; +#ifdef _DEBUG + m_bSPHERETEXKILLCOMBO = true; +#endif + } +private: + int m_nRAYTRACESPHERE; +#ifdef _DEBUG + bool m_bRAYTRACESPHERE; +#endif +public: + void SetRAYTRACESPHERE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nRAYTRACESPHERE = i; +#ifdef _DEBUG + m_bRAYTRACESPHERE = true; +#endif + } + void SetRAYTRACESPHERE( bool i ) + { + m_nRAYTRACESPHERE = i ? 1 : 0; +#ifdef _DEBUG + m_bRAYTRACESPHERE = true; +#endif + } +private: + int m_nFLASHLIGHTDEPTHFILTERMODE; +#ifdef _DEBUG + bool m_bFLASHLIGHTDEPTHFILTERMODE; +#endif +public: + void SetFLASHLIGHTDEPTHFILTERMODE( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nFLASHLIGHTDEPTHFILTERMODE = i; +#ifdef _DEBUG + m_bFLASHLIGHTDEPTHFILTERMODE = true; +#endif + } + void SetFLASHLIGHTDEPTHFILTERMODE( bool i ) + { + m_nFLASHLIGHTDEPTHFILTERMODE = i ? 1 : 0; +#ifdef _DEBUG + m_bFLASHLIGHTDEPTHFILTERMODE = true; +#endif + } +public: + eye_refract_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bFLASHLIGHT = false; +#endif // _DEBUG + m_nFLASHLIGHT = 0; +#ifdef _DEBUG + m_bLIGHTWARPTEXTURE = false; +#endif // _DEBUG + m_nLIGHTWARPTEXTURE = 0; +#ifdef _DEBUG + m_bSPHERETEXKILLCOMBO = false; +#endif // _DEBUG + m_nSPHERETEXKILLCOMBO = 0; +#ifdef _DEBUG + m_bRAYTRACESPHERE = false; +#endif // _DEBUG + m_nRAYTRACESPHERE = 0; +#ifdef _DEBUG + m_bFLASHLIGHTDEPTHFILTERMODE = false; +#endif // _DEBUG + m_nFLASHLIGHTDEPTHFILTERMODE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bFLASHLIGHT && m_bLIGHTWARPTEXTURE && m_bSPHERETEXKILLCOMBO && m_bRAYTRACESPHERE && m_bFLASHLIGHTDEPTHFILTERMODE; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 10 * m_nFLASHLIGHT ) + ( 20 * m_nLIGHTWARPTEXTURE ) + ( 40 * m_nSPHERETEXKILLCOMBO ) + ( 80 * m_nRAYTRACESPHERE ) + ( 160 * m_nFLASHLIGHTDEPTHFILTERMODE ) + 0; + } +}; +#define shaderStaticTest_eye_refract_ps20b psh_forgot_to_set_static_FLASHLIGHT + psh_forgot_to_set_static_LIGHTWARPTEXTURE + psh_forgot_to_set_static_SPHERETEXKILLCOMBO + psh_forgot_to_set_static_RAYTRACESPHERE + psh_forgot_to_set_static_FLASHLIGHTDEPTHFILTERMODE + 0 +class eye_refract_ps20b_Dynamic_Index +{ +private: + int m_nNUM_LIGHTS; +#ifdef _DEBUG + bool m_bNUM_LIGHTS; +#endif +public: + void SetNUM_LIGHTS( int i ) + { + Assert( i >= 0 && i <= 4 ); + m_nNUM_LIGHTS = i; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } + void SetNUM_LIGHTS( bool i ) + { + m_nNUM_LIGHTS = i ? 1 : 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } +private: + int m_nFLASHLIGHTSHADOWS; +#ifdef _DEBUG + bool m_bFLASHLIGHTSHADOWS; +#endif +public: + void SetFLASHLIGHTSHADOWS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFLASHLIGHTSHADOWS = i; +#ifdef _DEBUG + m_bFLASHLIGHTSHADOWS = true; +#endif + } + void SetFLASHLIGHTSHADOWS( bool i ) + { + m_nFLASHLIGHTSHADOWS = i ? 1 : 0; +#ifdef _DEBUG + m_bFLASHLIGHTSHADOWS = true; +#endif + } +public: + eye_refract_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bNUM_LIGHTS = false; +#endif // _DEBUG + m_nNUM_LIGHTS = 0; +#ifdef _DEBUG + m_bFLASHLIGHTSHADOWS = false; +#endif // _DEBUG + m_nFLASHLIGHTSHADOWS = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bNUM_LIGHTS && m_bFLASHLIGHTSHADOWS; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nNUM_LIGHTS ) + ( 5 * m_nFLASHLIGHTSHADOWS ) + 0; + } +}; +#define shaderDynamicTest_eye_refract_ps20b psh_forgot_to_set_dynamic_NUM_LIGHTS + psh_forgot_to_set_dynamic_FLASHLIGHTSHADOWS + 0 diff --git a/materialsystem/stdshaders/fxctmp9/eye_refract_ps30.inc b/materialsystem/stdshaders/fxctmp9/eye_refract_ps30.inc new file mode 100644 index 0000000..5f68b55 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/eye_refract_ps30.inc @@ -0,0 +1,212 @@ +#include "shaderlib/cshader.h" +class eye_refract_ps30_Static_Index +{ +private: + int m_nFLASHLIGHT; +#ifdef _DEBUG + bool m_bFLASHLIGHT; +#endif +public: + void SetFLASHLIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFLASHLIGHT = i; +#ifdef _DEBUG + m_bFLASHLIGHT = true; +#endif + } + void SetFLASHLIGHT( bool i ) + { + m_nFLASHLIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bFLASHLIGHT = true; +#endif + } +private: + int m_nLIGHTWARPTEXTURE; +#ifdef _DEBUG + bool m_bLIGHTWARPTEXTURE; +#endif +public: + void SetLIGHTWARPTEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nLIGHTWARPTEXTURE = i; +#ifdef _DEBUG + m_bLIGHTWARPTEXTURE = true; +#endif + } + void SetLIGHTWARPTEXTURE( bool i ) + { + m_nLIGHTWARPTEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bLIGHTWARPTEXTURE = true; +#endif + } +private: + int m_nSPHERETEXKILLCOMBO; +#ifdef _DEBUG + bool m_bSPHERETEXKILLCOMBO; +#endif +public: + void SetSPHERETEXKILLCOMBO( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSPHERETEXKILLCOMBO = i; +#ifdef _DEBUG + m_bSPHERETEXKILLCOMBO = true; +#endif + } + void SetSPHERETEXKILLCOMBO( bool i ) + { + m_nSPHERETEXKILLCOMBO = i ? 1 : 0; +#ifdef _DEBUG + m_bSPHERETEXKILLCOMBO = true; +#endif + } +private: + int m_nRAYTRACESPHERE; +#ifdef _DEBUG + bool m_bRAYTRACESPHERE; +#endif +public: + void SetRAYTRACESPHERE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nRAYTRACESPHERE = i; +#ifdef _DEBUG + m_bRAYTRACESPHERE = true; +#endif + } + void SetRAYTRACESPHERE( bool i ) + { + m_nRAYTRACESPHERE = i ? 1 : 0; +#ifdef _DEBUG + m_bRAYTRACESPHERE = true; +#endif + } +private: + int m_nFLASHLIGHTDEPTHFILTERMODE; +#ifdef _DEBUG + bool m_bFLASHLIGHTDEPTHFILTERMODE; +#endif +public: + void SetFLASHLIGHTDEPTHFILTERMODE( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nFLASHLIGHTDEPTHFILTERMODE = i; +#ifdef _DEBUG + m_bFLASHLIGHTDEPTHFILTERMODE = true; +#endif + } + void SetFLASHLIGHTDEPTHFILTERMODE( bool i ) + { + m_nFLASHLIGHTDEPTHFILTERMODE = i ? 1 : 0; +#ifdef _DEBUG + m_bFLASHLIGHTDEPTHFILTERMODE = true; +#endif + } +public: + eye_refract_ps30_Static_Index( ) + { +#ifdef _DEBUG + m_bFLASHLIGHT = false; +#endif // _DEBUG + m_nFLASHLIGHT = 0; +#ifdef _DEBUG + m_bLIGHTWARPTEXTURE = false; +#endif // _DEBUG + m_nLIGHTWARPTEXTURE = 0; +#ifdef _DEBUG + m_bSPHERETEXKILLCOMBO = false; +#endif // _DEBUG + m_nSPHERETEXKILLCOMBO = 0; +#ifdef _DEBUG + m_bRAYTRACESPHERE = false; +#endif // _DEBUG + m_nRAYTRACESPHERE = 0; +#ifdef _DEBUG + m_bFLASHLIGHTDEPTHFILTERMODE = false; +#endif // _DEBUG + m_nFLASHLIGHTDEPTHFILTERMODE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bFLASHLIGHT && m_bLIGHTWARPTEXTURE && m_bSPHERETEXKILLCOMBO && m_bRAYTRACESPHERE && m_bFLASHLIGHTDEPTHFILTERMODE; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 10 * m_nFLASHLIGHT ) + ( 20 * m_nLIGHTWARPTEXTURE ) + ( 40 * m_nSPHERETEXKILLCOMBO ) + ( 80 * m_nRAYTRACESPHERE ) + ( 160 * m_nFLASHLIGHTDEPTHFILTERMODE ) + 0; + } +}; +#define shaderStaticTest_eye_refract_ps30 psh_forgot_to_set_static_FLASHLIGHT + psh_forgot_to_set_static_LIGHTWARPTEXTURE + psh_forgot_to_set_static_SPHERETEXKILLCOMBO + psh_forgot_to_set_static_RAYTRACESPHERE + psh_forgot_to_set_static_FLASHLIGHTDEPTHFILTERMODE + 0 +class eye_refract_ps30_Dynamic_Index +{ +private: + int m_nNUM_LIGHTS; +#ifdef _DEBUG + bool m_bNUM_LIGHTS; +#endif +public: + void SetNUM_LIGHTS( int i ) + { + Assert( i >= 0 && i <= 4 ); + m_nNUM_LIGHTS = i; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } + void SetNUM_LIGHTS( bool i ) + { + m_nNUM_LIGHTS = i ? 1 : 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } +private: + int m_nFLASHLIGHTSHADOWS; +#ifdef _DEBUG + bool m_bFLASHLIGHTSHADOWS; +#endif +public: + void SetFLASHLIGHTSHADOWS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFLASHLIGHTSHADOWS = i; +#ifdef _DEBUG + m_bFLASHLIGHTSHADOWS = true; +#endif + } + void SetFLASHLIGHTSHADOWS( bool i ) + { + m_nFLASHLIGHTSHADOWS = i ? 1 : 0; +#ifdef _DEBUG + m_bFLASHLIGHTSHADOWS = true; +#endif + } +public: + eye_refract_ps30_Dynamic_Index() + { +#ifdef _DEBUG + m_bNUM_LIGHTS = false; +#endif // _DEBUG + m_nNUM_LIGHTS = 0; +#ifdef _DEBUG + m_bFLASHLIGHTSHADOWS = false; +#endif // _DEBUG + m_nFLASHLIGHTSHADOWS = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bNUM_LIGHTS && m_bFLASHLIGHTSHADOWS; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nNUM_LIGHTS ) + ( 5 * m_nFLASHLIGHTSHADOWS ) + 0; + } +}; +#define shaderDynamicTest_eye_refract_ps30 psh_forgot_to_set_dynamic_NUM_LIGHTS + psh_forgot_to_set_dynamic_FLASHLIGHTSHADOWS + 0 diff --git a/materialsystem/stdshaders/fxctmp9/eye_refract_vs20.inc b/materialsystem/stdshaders/fxctmp9/eye_refract_vs20.inc new file mode 100644 index 0000000..a91fa7b --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/eye_refract_vs20.inc @@ -0,0 +1,287 @@ +#include "shaderlib/cshader.h" +class eye_refract_vs20_Static_Index +{ +private: + int m_nINTRO; +#ifdef _DEBUG + bool m_bINTRO; +#endif +public: + void SetINTRO( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nINTRO = i; +#ifdef _DEBUG + m_bINTRO = true; +#endif + } + void SetINTRO( bool i ) + { + m_nINTRO = i ? 1 : 0; +#ifdef _DEBUG + m_bINTRO = true; +#endif + } +private: + int m_nHALFLAMBERT; +#ifdef _DEBUG + bool m_bHALFLAMBERT; +#endif +public: + void SetHALFLAMBERT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHALFLAMBERT = i; +#ifdef _DEBUG + m_bHALFLAMBERT = true; +#endif + } + void SetHALFLAMBERT( bool i ) + { + m_nHALFLAMBERT = i ? 1 : 0; +#ifdef _DEBUG + m_bHALFLAMBERT = true; +#endif + } +private: + int m_nFLASHLIGHT; +#ifdef _DEBUG + bool m_bFLASHLIGHT; +#endif +public: + void SetFLASHLIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFLASHLIGHT = i; +#ifdef _DEBUG + m_bFLASHLIGHT = true; +#endif + } + void SetFLASHLIGHT( bool i ) + { + m_nFLASHLIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bFLASHLIGHT = true; +#endif + } +private: + int m_nLIGHTWARPTEXTURE; +#ifdef _DEBUG + bool m_bLIGHTWARPTEXTURE; +#endif +public: + void SetLIGHTWARPTEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nLIGHTWARPTEXTURE = i; +#ifdef _DEBUG + m_bLIGHTWARPTEXTURE = true; +#endif + } + void SetLIGHTWARPTEXTURE( bool i ) + { + m_nLIGHTWARPTEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bLIGHTWARPTEXTURE = true; +#endif + } +public: + eye_refract_vs20_Static_Index( ) + { +#ifdef _DEBUG + m_bINTRO = false; +#endif // _DEBUG + m_nINTRO = 0; +#ifdef _DEBUG + m_bHALFLAMBERT = false; +#endif // _DEBUG + m_nHALFLAMBERT = 0; +#ifdef _DEBUG + m_bFLASHLIGHT = false; +#endif // _DEBUG + m_nFLASHLIGHT = 0; +#ifdef _DEBUG + m_bLIGHTWARPTEXTURE = false; +#endif // _DEBUG + m_nLIGHTWARPTEXTURE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bINTRO && m_bHALFLAMBERT && m_bFLASHLIGHT && m_bLIGHTWARPTEXTURE; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 160 * m_nINTRO ) + ( 320 * m_nHALFLAMBERT ) + ( 640 * m_nFLASHLIGHT ) + ( 1280 * m_nLIGHTWARPTEXTURE ) + 0; + } +}; +#define shaderStaticTest_eye_refract_vs20 vsh_forgot_to_set_static_INTRO + vsh_forgot_to_set_static_HALFLAMBERT + vsh_forgot_to_set_static_FLASHLIGHT + vsh_forgot_to_set_static_LIGHTWARPTEXTURE + 0 +class eye_refract_vs20_Dynamic_Index +{ +private: + int m_nCOMPRESSED_VERTS; +#ifdef _DEBUG + bool m_bCOMPRESSED_VERTS; +#endif +public: + void SetCOMPRESSED_VERTS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOMPRESSED_VERTS = i; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } + void SetCOMPRESSED_VERTS( bool i ) + { + m_nCOMPRESSED_VERTS = i ? 1 : 0; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nDYNAMIC_LIGHT; +#ifdef _DEBUG + bool m_bDYNAMIC_LIGHT; +#endif +public: + void SetDYNAMIC_LIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDYNAMIC_LIGHT = i; +#ifdef _DEBUG + m_bDYNAMIC_LIGHT = true; +#endif + } + void SetDYNAMIC_LIGHT( bool i ) + { + m_nDYNAMIC_LIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bDYNAMIC_LIGHT = true; +#endif + } +private: + int m_nSTATIC_LIGHT; +#ifdef _DEBUG + bool m_bSTATIC_LIGHT; +#endif +public: + void SetSTATIC_LIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSTATIC_LIGHT = i; +#ifdef _DEBUG + m_bSTATIC_LIGHT = true; +#endif + } + void SetSTATIC_LIGHT( bool i ) + { + m_nSTATIC_LIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bSTATIC_LIGHT = true; +#endif + } +private: + int m_nNUM_LIGHTS; +#ifdef _DEBUG + bool m_bNUM_LIGHTS; +#endif +public: + void SetNUM_LIGHTS( int i ) + { + Assert( i >= 0 && i <= 4 ); + m_nNUM_LIGHTS = i; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } + void SetNUM_LIGHTS( bool i ) + { + m_nNUM_LIGHTS = i ? 1 : 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } +public: + eye_refract_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = false; +#endif // _DEBUG + m_nCOMPRESSED_VERTS = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bDYNAMIC_LIGHT = false; +#endif // _DEBUG + m_nDYNAMIC_LIGHT = 0; +#ifdef _DEBUG + m_bSTATIC_LIGHT = false; +#endif // _DEBUG + m_nSTATIC_LIGHT = 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = false; +#endif // _DEBUG + m_nNUM_LIGHTS = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bCOMPRESSED_VERTS && m_bSKINNING && m_bDOWATERFOG && m_bDYNAMIC_LIGHT && m_bSTATIC_LIGHT && m_bNUM_LIGHTS; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCOMPRESSED_VERTS ) + ( 2 * m_nSKINNING ) + ( 4 * m_nDOWATERFOG ) + ( 8 * m_nDYNAMIC_LIGHT ) + ( 16 * m_nSTATIC_LIGHT ) + ( 32 * m_nNUM_LIGHTS ) + 0; + } +}; +#define shaderDynamicTest_eye_refract_vs20 vsh_forgot_to_set_dynamic_COMPRESSED_VERTS + vsh_forgot_to_set_dynamic_SKINNING + vsh_forgot_to_set_dynamic_DOWATERFOG + vsh_forgot_to_set_dynamic_DYNAMIC_LIGHT + vsh_forgot_to_set_dynamic_STATIC_LIGHT + vsh_forgot_to_set_dynamic_NUM_LIGHTS + 0 diff --git a/materialsystem/stdshaders/fxctmp9/eye_refract_vs30.inc b/materialsystem/stdshaders/fxctmp9/eye_refract_vs30.inc new file mode 100644 index 0000000..bfeef3b --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/eye_refract_vs30.inc @@ -0,0 +1,312 @@ +#include "shaderlib/cshader.h" +class eye_refract_vs30_Static_Index +{ +private: + int m_nINTRO; +#ifdef _DEBUG + bool m_bINTRO; +#endif +public: + void SetINTRO( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nINTRO = i; +#ifdef _DEBUG + m_bINTRO = true; +#endif + } + void SetINTRO( bool i ) + { + m_nINTRO = i ? 1 : 0; +#ifdef _DEBUG + m_bINTRO = true; +#endif + } +private: + int m_nHALFLAMBERT; +#ifdef _DEBUG + bool m_bHALFLAMBERT; +#endif +public: + void SetHALFLAMBERT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHALFLAMBERT = i; +#ifdef _DEBUG + m_bHALFLAMBERT = true; +#endif + } + void SetHALFLAMBERT( bool i ) + { + m_nHALFLAMBERT = i ? 1 : 0; +#ifdef _DEBUG + m_bHALFLAMBERT = true; +#endif + } +private: + int m_nFLASHLIGHT; +#ifdef _DEBUG + bool m_bFLASHLIGHT; +#endif +public: + void SetFLASHLIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFLASHLIGHT = i; +#ifdef _DEBUG + m_bFLASHLIGHT = true; +#endif + } + void SetFLASHLIGHT( bool i ) + { + m_nFLASHLIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bFLASHLIGHT = true; +#endif + } +private: + int m_nLIGHTWARPTEXTURE; +#ifdef _DEBUG + bool m_bLIGHTWARPTEXTURE; +#endif +public: + void SetLIGHTWARPTEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nLIGHTWARPTEXTURE = i; +#ifdef _DEBUG + m_bLIGHTWARPTEXTURE = true; +#endif + } + void SetLIGHTWARPTEXTURE( bool i ) + { + m_nLIGHTWARPTEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bLIGHTWARPTEXTURE = true; +#endif + } +public: + eye_refract_vs30_Static_Index( ) + { +#ifdef _DEBUG + m_bINTRO = false; +#endif // _DEBUG + m_nINTRO = 0; +#ifdef _DEBUG + m_bHALFLAMBERT = false; +#endif // _DEBUG + m_nHALFLAMBERT = 0; +#ifdef _DEBUG + m_bFLASHLIGHT = false; +#endif // _DEBUG + m_nFLASHLIGHT = 0; +#ifdef _DEBUG + m_bLIGHTWARPTEXTURE = false; +#endif // _DEBUG + m_nLIGHTWARPTEXTURE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bINTRO && m_bHALFLAMBERT && m_bFLASHLIGHT && m_bLIGHTWARPTEXTURE; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 320 * m_nINTRO ) + ( 640 * m_nHALFLAMBERT ) + ( 1280 * m_nFLASHLIGHT ) + ( 2560 * m_nLIGHTWARPTEXTURE ) + 0; + } +}; +#define shaderStaticTest_eye_refract_vs30 vsh_forgot_to_set_static_INTRO + vsh_forgot_to_set_static_HALFLAMBERT + vsh_forgot_to_set_static_FLASHLIGHT + vsh_forgot_to_set_static_LIGHTWARPTEXTURE + 0 +class eye_refract_vs30_Dynamic_Index +{ +private: + int m_nCOMPRESSED_VERTS; +#ifdef _DEBUG + bool m_bCOMPRESSED_VERTS; +#endif +public: + void SetCOMPRESSED_VERTS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOMPRESSED_VERTS = i; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } + void SetCOMPRESSED_VERTS( bool i ) + { + m_nCOMPRESSED_VERTS = i ? 1 : 0; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nDYNAMIC_LIGHT; +#ifdef _DEBUG + bool m_bDYNAMIC_LIGHT; +#endif +public: + void SetDYNAMIC_LIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDYNAMIC_LIGHT = i; +#ifdef _DEBUG + m_bDYNAMIC_LIGHT = true; +#endif + } + void SetDYNAMIC_LIGHT( bool i ) + { + m_nDYNAMIC_LIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bDYNAMIC_LIGHT = true; +#endif + } +private: + int m_nSTATIC_LIGHT; +#ifdef _DEBUG + bool m_bSTATIC_LIGHT; +#endif +public: + void SetSTATIC_LIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSTATIC_LIGHT = i; +#ifdef _DEBUG + m_bSTATIC_LIGHT = true; +#endif + } + void SetSTATIC_LIGHT( bool i ) + { + m_nSTATIC_LIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bSTATIC_LIGHT = true; +#endif + } +private: + int m_nNUM_LIGHTS; +#ifdef _DEBUG + bool m_bNUM_LIGHTS; +#endif +public: + void SetNUM_LIGHTS( int i ) + { + Assert( i >= 0 && i <= 4 ); + m_nNUM_LIGHTS = i; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } + void SetNUM_LIGHTS( bool i ) + { + m_nNUM_LIGHTS = i ? 1 : 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } +private: + int m_nMORPHING; +#ifdef _DEBUG + bool m_bMORPHING; +#endif +public: + void SetMORPHING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nMORPHING = i; +#ifdef _DEBUG + m_bMORPHING = true; +#endif + } + void SetMORPHING( bool i ) + { + m_nMORPHING = i ? 1 : 0; +#ifdef _DEBUG + m_bMORPHING = true; +#endif + } +public: + eye_refract_vs30_Dynamic_Index() + { +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = false; +#endif // _DEBUG + m_nCOMPRESSED_VERTS = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bDYNAMIC_LIGHT = false; +#endif // _DEBUG + m_nDYNAMIC_LIGHT = 0; +#ifdef _DEBUG + m_bSTATIC_LIGHT = false; +#endif // _DEBUG + m_nSTATIC_LIGHT = 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = false; +#endif // _DEBUG + m_nNUM_LIGHTS = 0; +#ifdef _DEBUG + m_bMORPHING = false; +#endif // _DEBUG + m_nMORPHING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bCOMPRESSED_VERTS && m_bSKINNING && m_bDOWATERFOG && m_bDYNAMIC_LIGHT && m_bSTATIC_LIGHT && m_bNUM_LIGHTS && m_bMORPHING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCOMPRESSED_VERTS ) + ( 2 * m_nSKINNING ) + ( 4 * m_nDOWATERFOG ) + ( 8 * m_nDYNAMIC_LIGHT ) + ( 16 * m_nSTATIC_LIGHT ) + ( 32 * m_nNUM_LIGHTS ) + ( 160 * m_nMORPHING ) + 0; + } +}; +#define shaderDynamicTest_eye_refract_vs30 vsh_forgot_to_set_dynamic_COMPRESSED_VERTS + vsh_forgot_to_set_dynamic_SKINNING + vsh_forgot_to_set_dynamic_DOWATERFOG + vsh_forgot_to_set_dynamic_DYNAMIC_LIGHT + vsh_forgot_to_set_dynamic_STATIC_LIGHT + vsh_forgot_to_set_dynamic_NUM_LIGHTS + vsh_forgot_to_set_dynamic_MORPHING + 0 diff --git a/materialsystem/stdshaders/fxctmp9/eyeglint_ps20.inc b/materialsystem/stdshaders/fxctmp9/eyeglint_ps20.inc new file mode 100644 index 0000000..6b01552 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/eyeglint_ps20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class eyeglint_ps20_Static_Index +{ +public: + eyeglint_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_eyeglint_ps20 0 +class eyeglint_ps20_Dynamic_Index +{ +public: + eyeglint_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_eyeglint_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9/eyeglint_ps20b.inc b/materialsystem/stdshaders/fxctmp9/eyeglint_ps20b.inc new file mode 100644 index 0000000..e58e118 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/eyeglint_ps20b.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class eyeglint_ps20b_Static_Index +{ +public: + eyeglint_ps20b_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_eyeglint_ps20b 0 +class eyeglint_ps20b_Dynamic_Index +{ +public: + eyeglint_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_eyeglint_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9/eyeglint_vs20.inc b/materialsystem/stdshaders/fxctmp9/eyeglint_vs20.inc new file mode 100644 index 0000000..675f39c --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/eyeglint_vs20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class eyeglint_vs20_Static_Index +{ +public: + eyeglint_vs20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_eyeglint_vs20 0 +class eyeglint_vs20_Dynamic_Index +{ +public: + eyeglint_vs20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_eyeglint_vs20 0 diff --git a/materialsystem/stdshaders/fxctmp9/eyes_cloak_ps20b.inc b/materialsystem/stdshaders/fxctmp9/eyes_cloak_ps20b.inc new file mode 100644 index 0000000..d435652 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/eyes_cloak_ps20b.inc @@ -0,0 +1,262 @@ +#include "shaderlib/cshader.h" +class eyes_cloak_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +private: + int m_nHDRTYPE; +#ifdef _DEBUG + bool m_bHDRTYPE; +#endif +public: + void SetHDRTYPE( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nHDRTYPE = i; +#ifdef _DEBUG + m_bHDRTYPE = true; +#endif + } + void SetHDRTYPE( bool i ) + { + m_nHDRTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bHDRTYPE = true; +#endif + } +private: + int m_nBLUR; +#ifdef _DEBUG + bool m_bBLUR; +#endif +public: + void SetBLUR( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBLUR = i; +#ifdef _DEBUG + m_bBLUR = true; +#endif + } + void SetBLUR( bool i ) + { + m_nBLUR = i ? 1 : 0; +#ifdef _DEBUG + m_bBLUR = true; +#endif + } +private: + int m_nFADEOUTONSILHOUETTE; +#ifdef _DEBUG + bool m_bFADEOUTONSILHOUETTE; +#endif +public: + void SetFADEOUTONSILHOUETTE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFADEOUTONSILHOUETTE = i; +#ifdef _DEBUG + m_bFADEOUTONSILHOUETTE = true; +#endif + } + void SetFADEOUTONSILHOUETTE( bool i ) + { + m_nFADEOUTONSILHOUETTE = i ? 1 : 0; +#ifdef _DEBUG + m_bFADEOUTONSILHOUETTE = true; +#endif + } +private: + int m_nCUBEMAP; +#ifdef _DEBUG + bool m_bCUBEMAP; +#endif +public: + void SetCUBEMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCUBEMAP = i; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } + void SetCUBEMAP( bool i ) + { + m_nCUBEMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } +private: + int m_nREFRACTTINTTEXTURE; +#ifdef _DEBUG + bool m_bREFRACTTINTTEXTURE; +#endif +public: + void SetREFRACTTINTTEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nREFRACTTINTTEXTURE = i; +#ifdef _DEBUG + m_bREFRACTTINTTEXTURE = true; +#endif + } + void SetREFRACTTINTTEXTURE( bool i ) + { + m_nREFRACTTINTTEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bREFRACTTINTTEXTURE = true; +#endif + } +private: + int m_nMASKED; +#ifdef _DEBUG + bool m_bMASKED; +#endif +public: + void SetMASKED( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nMASKED = i; +#ifdef _DEBUG + m_bMASKED = true; +#endif + } + void SetMASKED( bool i ) + { + m_nMASKED = i ? 1 : 0; +#ifdef _DEBUG + m_bMASKED = true; +#endif + } +public: + eyes_cloak_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); +#ifdef _DEBUG + m_bHDRTYPE = false; +#endif // _DEBUG + m_nHDRTYPE = 0; +#ifdef _DEBUG + m_bBLUR = false; +#endif // _DEBUG + m_nBLUR = 0; +#ifdef _DEBUG + m_bFADEOUTONSILHOUETTE = false; +#endif // _DEBUG + m_nFADEOUTONSILHOUETTE = 0; +#ifdef _DEBUG + m_bCUBEMAP = false; +#endif // _DEBUG + m_nCUBEMAP = 0; +#ifdef _DEBUG + m_bREFRACTTINTTEXTURE = false; +#endif // _DEBUG + m_nREFRACTTINTTEXTURE = 0; +#ifdef _DEBUG + m_bMASKED = false; +#endif // _DEBUG + m_nMASKED = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB && m_bHDRTYPE && m_bBLUR && m_bFADEOUTONSILHOUETTE && m_bCUBEMAP && m_bREFRACTTINTTEXTURE && m_bMASKED; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 4 * m_nCONVERT_TO_SRGB ) + ( 8 * m_nHDRTYPE ) + ( 24 * m_nBLUR ) + ( 48 * m_nFADEOUTONSILHOUETTE ) + ( 96 * m_nCUBEMAP ) + ( 192 * m_nREFRACTTINTTEXTURE ) + ( 384 * m_nMASKED ) + 0; + } +}; +#define shaderStaticTest_eyes_cloak_ps20b psh_forgot_to_set_static_HDRTYPE + psh_forgot_to_set_static_BLUR + psh_forgot_to_set_static_FADEOUTONSILHOUETTE + psh_forgot_to_set_static_CUBEMAP + psh_forgot_to_set_static_REFRACTTINTTEXTURE + psh_forgot_to_set_static_MASKED + 0 +class eyes_cloak_ps20b_Dynamic_Index +{ +private: + int m_nHDRENABLED; +#ifdef _DEBUG + bool m_bHDRENABLED; +#endif +public: + void SetHDRENABLED( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHDRENABLED = i; +#ifdef _DEBUG + m_bHDRENABLED = true; +#endif + } + void SetHDRENABLED( bool i ) + { + m_nHDRENABLED = i ? 1 : 0; +#ifdef _DEBUG + m_bHDRENABLED = true; +#endif + } +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + eyes_cloak_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bHDRENABLED = false; +#endif // _DEBUG + m_nHDRENABLED = 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bHDRENABLED && m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nHDRENABLED ) + ( 2 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_eyes_cloak_ps20b psh_forgot_to_set_dynamic_HDRENABLED + psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9/eyes_cloak_vs20b.inc b/materialsystem/stdshaders/fxctmp9/eyes_cloak_vs20b.inc new file mode 100644 index 0000000..f6b848e --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/eyes_cloak_vs20b.inc @@ -0,0 +1,187 @@ +#include "shaderlib/cshader.h" +class eyes_cloak_vs20b_Static_Index +{ +private: + int m_nINTRO; +#ifdef _DEBUG + bool m_bINTRO; +#endif +public: + void SetINTRO( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nINTRO = i; +#ifdef _DEBUG + m_bINTRO = true; +#endif + } + void SetINTRO( bool i ) + { + m_nINTRO = i ? 1 : 0; +#ifdef _DEBUG + m_bINTRO = true; +#endif + } +private: + int m_nHALFLAMBERT; +#ifdef _DEBUG + bool m_bHALFLAMBERT; +#endif +public: + void SetHALFLAMBERT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHALFLAMBERT = i; +#ifdef _DEBUG + m_bHALFLAMBERT = true; +#endif + } + void SetHALFLAMBERT( bool i ) + { + m_nHALFLAMBERT = i ? 1 : 0; +#ifdef _DEBUG + m_bHALFLAMBERT = true; +#endif + } +public: + eyes_cloak_vs20b_Static_Index( ) + { +#ifdef _DEBUG + m_bINTRO = false; +#endif // _DEBUG + m_nINTRO = 0; +#ifdef _DEBUG + m_bHALFLAMBERT = false; +#endif // _DEBUG + m_nHALFLAMBERT = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bINTRO && m_bHALFLAMBERT; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 32 * m_nINTRO ) + ( 64 * m_nHALFLAMBERT ) + 0; + } +}; +#define shaderStaticTest_eyes_cloak_vs20b vsh_forgot_to_set_static_INTRO + vsh_forgot_to_set_static_HALFLAMBERT + 0 +class eyes_cloak_vs20b_Dynamic_Index +{ +private: + int m_nNUM_BONES; +#ifdef _DEBUG + bool m_bNUM_BONES; +#endif +public: + void SetNUM_BONES( int i ) + { + Assert( i >= 0 && i <= 3 ); + m_nNUM_BONES = i; +#ifdef _DEBUG + m_bNUM_BONES = true; +#endif + } + void SetNUM_BONES( bool i ) + { + m_nNUM_BONES = i ? 1 : 0; +#ifdef _DEBUG + m_bNUM_BONES = true; +#endif + } +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nDYNAMIC_LIGHT; +#ifdef _DEBUG + bool m_bDYNAMIC_LIGHT; +#endif +public: + void SetDYNAMIC_LIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDYNAMIC_LIGHT = i; +#ifdef _DEBUG + m_bDYNAMIC_LIGHT = true; +#endif + } + void SetDYNAMIC_LIGHT( bool i ) + { + m_nDYNAMIC_LIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bDYNAMIC_LIGHT = true; +#endif + } +private: + int m_nSTATIC_LIGHT; +#ifdef _DEBUG + bool m_bSTATIC_LIGHT; +#endif +public: + void SetSTATIC_LIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSTATIC_LIGHT = i; +#ifdef _DEBUG + m_bSTATIC_LIGHT = true; +#endif + } + void SetSTATIC_LIGHT( bool i ) + { + m_nSTATIC_LIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bSTATIC_LIGHT = true; +#endif + } +public: + eyes_cloak_vs20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bNUM_BONES = false; +#endif // _DEBUG + m_nNUM_BONES = 0; +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bDYNAMIC_LIGHT = false; +#endif // _DEBUG + m_nDYNAMIC_LIGHT = 0; +#ifdef _DEBUG + m_bSTATIC_LIGHT = false; +#endif // _DEBUG + m_nSTATIC_LIGHT = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bNUM_BONES && m_bDOWATERFOG && m_bDYNAMIC_LIGHT && m_bSTATIC_LIGHT; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nNUM_BONES ) + ( 4 * m_nDOWATERFOG ) + ( 8 * m_nDYNAMIC_LIGHT ) + ( 16 * m_nSTATIC_LIGHT ) + 0; + } +}; +#define shaderDynamicTest_eyes_cloak_vs20b vsh_forgot_to_set_dynamic_NUM_BONES + vsh_forgot_to_set_dynamic_DOWATERFOG + vsh_forgot_to_set_dynamic_DYNAMIC_LIGHT + vsh_forgot_to_set_dynamic_STATIC_LIGHT + 0 diff --git a/materialsystem/stdshaders/fxctmp9/eyes_flashlight_ps11.inc b/materialsystem/stdshaders/fxctmp9/eyes_flashlight_ps11.inc new file mode 100644 index 0000000..6292dd5 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/eyes_flashlight_ps11.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class eyes_flashlight_ps11_Static_Index +{ +public: + eyes_flashlight_ps11_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_eyes_flashlight_ps11 0 +class eyes_flashlight_ps11_Dynamic_Index +{ +public: + eyes_flashlight_ps11_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_eyes_flashlight_ps11 0 diff --git a/materialsystem/stdshaders/fxctmp9/eyes_flashlight_ps20.inc b/materialsystem/stdshaders/fxctmp9/eyes_flashlight_ps20.inc new file mode 100644 index 0000000..c353111 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/eyes_flashlight_ps20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class eyes_flashlight_ps20_Static_Index +{ +public: + eyes_flashlight_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_eyes_flashlight_ps20 0 +class eyes_flashlight_ps20_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + eyes_flashlight_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_eyes_flashlight_ps20 psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9/eyes_flashlight_ps20b.inc b/materialsystem/stdshaders/fxctmp9/eyes_flashlight_ps20b.inc new file mode 100644 index 0000000..1f90b01 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/eyes_flashlight_ps20b.inc @@ -0,0 +1,112 @@ +#include "shaderlib/cshader.h" +class eyes_flashlight_ps20b_Static_Index +{ +private: + int m_nFLASHLIGHTDEPTHFILTERMODE; +#ifdef _DEBUG + bool m_bFLASHLIGHTDEPTHFILTERMODE; +#endif +public: + void SetFLASHLIGHTDEPTHFILTERMODE( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nFLASHLIGHTDEPTHFILTERMODE = i; +#ifdef _DEBUG + m_bFLASHLIGHTDEPTHFILTERMODE = true; +#endif + } + void SetFLASHLIGHTDEPTHFILTERMODE( bool i ) + { + m_nFLASHLIGHTDEPTHFILTERMODE = i ? 1 : 0; +#ifdef _DEBUG + m_bFLASHLIGHTDEPTHFILTERMODE = true; +#endif + } +public: + eyes_flashlight_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bFLASHLIGHTDEPTHFILTERMODE = false; +#endif // _DEBUG + m_nFLASHLIGHTDEPTHFILTERMODE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bFLASHLIGHTDEPTHFILTERMODE; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 4 * m_nFLASHLIGHTDEPTHFILTERMODE ) + 0; + } +}; +#define shaderStaticTest_eyes_flashlight_ps20b psh_forgot_to_set_static_FLASHLIGHTDEPTHFILTERMODE + 0 +class eyes_flashlight_ps20b_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +private: + int m_nFLASHLIGHTSHADOWS; +#ifdef _DEBUG + bool m_bFLASHLIGHTSHADOWS; +#endif +public: + void SetFLASHLIGHTSHADOWS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFLASHLIGHTSHADOWS = i; +#ifdef _DEBUG + m_bFLASHLIGHTSHADOWS = true; +#endif + } + void SetFLASHLIGHTSHADOWS( bool i ) + { + m_nFLASHLIGHTSHADOWS = i ? 1 : 0; +#ifdef _DEBUG + m_bFLASHLIGHTSHADOWS = true; +#endif + } +public: + eyes_flashlight_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; +#ifdef _DEBUG + m_bFLASHLIGHTSHADOWS = false; +#endif // _DEBUG + m_nFLASHLIGHTSHADOWS = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE && m_bFLASHLIGHTSHADOWS; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + ( 2 * m_nFLASHLIGHTSHADOWS ) + 0; + } +}; +#define shaderDynamicTest_eyes_flashlight_ps20b psh_forgot_to_set_dynamic_PIXELFOGTYPE + psh_forgot_to_set_dynamic_FLASHLIGHTSHADOWS + 0 diff --git a/materialsystem/stdshaders/fxctmp9/eyes_flashlight_ps30.inc b/materialsystem/stdshaders/fxctmp9/eyes_flashlight_ps30.inc new file mode 100644 index 0000000..1fc26be --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/eyes_flashlight_ps30.inc @@ -0,0 +1,112 @@ +#include "shaderlib/cshader.h" +class eyes_flashlight_ps30_Static_Index +{ +private: + int m_nFLASHLIGHTDEPTHFILTERMODE; +#ifdef _DEBUG + bool m_bFLASHLIGHTDEPTHFILTERMODE; +#endif +public: + void SetFLASHLIGHTDEPTHFILTERMODE( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nFLASHLIGHTDEPTHFILTERMODE = i; +#ifdef _DEBUG + m_bFLASHLIGHTDEPTHFILTERMODE = true; +#endif + } + void SetFLASHLIGHTDEPTHFILTERMODE( bool i ) + { + m_nFLASHLIGHTDEPTHFILTERMODE = i ? 1 : 0; +#ifdef _DEBUG + m_bFLASHLIGHTDEPTHFILTERMODE = true; +#endif + } +public: + eyes_flashlight_ps30_Static_Index( ) + { +#ifdef _DEBUG + m_bFLASHLIGHTDEPTHFILTERMODE = false; +#endif // _DEBUG + m_nFLASHLIGHTDEPTHFILTERMODE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bFLASHLIGHTDEPTHFILTERMODE; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 4 * m_nFLASHLIGHTDEPTHFILTERMODE ) + 0; + } +}; +#define shaderStaticTest_eyes_flashlight_ps30 psh_forgot_to_set_static_FLASHLIGHTDEPTHFILTERMODE + 0 +class eyes_flashlight_ps30_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +private: + int m_nFLASHLIGHTSHADOWS; +#ifdef _DEBUG + bool m_bFLASHLIGHTSHADOWS; +#endif +public: + void SetFLASHLIGHTSHADOWS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFLASHLIGHTSHADOWS = i; +#ifdef _DEBUG + m_bFLASHLIGHTSHADOWS = true; +#endif + } + void SetFLASHLIGHTSHADOWS( bool i ) + { + m_nFLASHLIGHTSHADOWS = i ? 1 : 0; +#ifdef _DEBUG + m_bFLASHLIGHTSHADOWS = true; +#endif + } +public: + eyes_flashlight_ps30_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; +#ifdef _DEBUG + m_bFLASHLIGHTSHADOWS = false; +#endif // _DEBUG + m_nFLASHLIGHTSHADOWS = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE && m_bFLASHLIGHTSHADOWS; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + ( 2 * m_nFLASHLIGHTSHADOWS ) + 0; + } +}; +#define shaderDynamicTest_eyes_flashlight_ps30 psh_forgot_to_set_dynamic_PIXELFOGTYPE + psh_forgot_to_set_dynamic_FLASHLIGHTSHADOWS + 0 diff --git a/materialsystem/stdshaders/fxctmp9/eyes_flashlight_vs20.inc b/materialsystem/stdshaders/fxctmp9/eyes_flashlight_vs20.inc new file mode 100644 index 0000000..5abcd81 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/eyes_flashlight_vs20.inc @@ -0,0 +1,110 @@ +#include "shaderlib/cshader.h" +class eyes_flashlight_vs20_Static_Index +{ +public: + eyes_flashlight_vs20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_eyes_flashlight_vs20 0 +class eyes_flashlight_vs20_Dynamic_Index +{ +private: + int m_nCOMPRESSED_VERTS; +#ifdef _DEBUG + bool m_bCOMPRESSED_VERTS; +#endif +public: + void SetCOMPRESSED_VERTS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOMPRESSED_VERTS = i; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } + void SetCOMPRESSED_VERTS( bool i ) + { + m_nCOMPRESSED_VERTS = i ? 1 : 0; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + eyes_flashlight_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = false; +#endif // _DEBUG + m_nCOMPRESSED_VERTS = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bCOMPRESSED_VERTS && m_bSKINNING && m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCOMPRESSED_VERTS ) + ( 2 * m_nSKINNING ) + ( 4 * m_nDOWATERFOG ) + 0; + } +}; +#define shaderDynamicTest_eyes_flashlight_vs20 vsh_forgot_to_set_dynamic_COMPRESSED_VERTS + vsh_forgot_to_set_dynamic_SKINNING + vsh_forgot_to_set_dynamic_DOWATERFOG + 0 diff --git a/materialsystem/stdshaders/fxctmp9/eyes_flashlight_vs30.inc b/materialsystem/stdshaders/fxctmp9/eyes_flashlight_vs30.inc new file mode 100644 index 0000000..6be384a --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/eyes_flashlight_vs30.inc @@ -0,0 +1,135 @@ +#include "shaderlib/cshader.h" +class eyes_flashlight_vs30_Static_Index +{ +public: + eyes_flashlight_vs30_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_eyes_flashlight_vs30 0 +class eyes_flashlight_vs30_Dynamic_Index +{ +private: + int m_nCOMPRESSED_VERTS; +#ifdef _DEBUG + bool m_bCOMPRESSED_VERTS; +#endif +public: + void SetCOMPRESSED_VERTS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOMPRESSED_VERTS = i; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } + void SetCOMPRESSED_VERTS( bool i ) + { + m_nCOMPRESSED_VERTS = i ? 1 : 0; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nMORPHING; +#ifdef _DEBUG + bool m_bMORPHING; +#endif +public: + void SetMORPHING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nMORPHING = i; +#ifdef _DEBUG + m_bMORPHING = true; +#endif + } + void SetMORPHING( bool i ) + { + m_nMORPHING = i ? 1 : 0; +#ifdef _DEBUG + m_bMORPHING = true; +#endif + } +public: + eyes_flashlight_vs30_Dynamic_Index() + { +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = false; +#endif // _DEBUG + m_nCOMPRESSED_VERTS = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bMORPHING = false; +#endif // _DEBUG + m_nMORPHING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bCOMPRESSED_VERTS && m_bSKINNING && m_bDOWATERFOG && m_bMORPHING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCOMPRESSED_VERTS ) + ( 2 * m_nSKINNING ) + ( 4 * m_nDOWATERFOG ) + ( 8 * m_nMORPHING ) + 0; + } +}; +#define shaderDynamicTest_eyes_flashlight_vs30 vsh_forgot_to_set_dynamic_COMPRESSED_VERTS + vsh_forgot_to_set_dynamic_SKINNING + vsh_forgot_to_set_dynamic_DOWATERFOG + vsh_forgot_to_set_dynamic_MORPHING + 0 diff --git a/materialsystem/stdshaders/fxctmp9/eyes_ps20.inc b/materialsystem/stdshaders/fxctmp9/eyes_ps20.inc new file mode 100644 index 0000000..e3a2b4c --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/eyes_ps20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class eyes_ps20_Static_Index +{ +public: + eyes_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_eyes_ps20 0 +class eyes_ps20_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + eyes_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_eyes_ps20 psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9/eyes_ps20b.inc b/materialsystem/stdshaders/fxctmp9/eyes_ps20b.inc new file mode 100644 index 0000000..cab7fcf --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/eyes_ps20b.inc @@ -0,0 +1,85 @@ +#include "shaderlib/cshader.h" +class eyes_ps20b_Static_Index +{ +public: + eyes_ps20b_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_eyes_ps20b 0 +class eyes_ps20b_Dynamic_Index +{ +private: + int m_nWRITE_DEPTH_TO_DESTALPHA; +#ifdef _DEBUG + bool m_bWRITE_DEPTH_TO_DESTALPHA; +#endif +public: + void SetWRITE_DEPTH_TO_DESTALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nWRITE_DEPTH_TO_DESTALPHA = i; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = true; +#endif + } + void SetWRITE_DEPTH_TO_DESTALPHA( bool i ) + { + m_nWRITE_DEPTH_TO_DESTALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = true; +#endif + } +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + eyes_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = false; +#endif // _DEBUG + m_nWRITE_DEPTH_TO_DESTALPHA = 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bWRITE_DEPTH_TO_DESTALPHA && m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nWRITE_DEPTH_TO_DESTALPHA ) + ( 2 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_eyes_ps20b psh_forgot_to_set_dynamic_WRITE_DEPTH_TO_DESTALPHA + psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9/eyes_ps30.inc b/materialsystem/stdshaders/fxctmp9/eyes_ps30.inc new file mode 100644 index 0000000..ebcb412 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/eyes_ps30.inc @@ -0,0 +1,85 @@ +#include "shaderlib/cshader.h" +class eyes_ps30_Static_Index +{ +public: + eyes_ps30_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_eyes_ps30 0 +class eyes_ps30_Dynamic_Index +{ +private: + int m_nWRITE_DEPTH_TO_DESTALPHA; +#ifdef _DEBUG + bool m_bWRITE_DEPTH_TO_DESTALPHA; +#endif +public: + void SetWRITE_DEPTH_TO_DESTALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nWRITE_DEPTH_TO_DESTALPHA = i; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = true; +#endif + } + void SetWRITE_DEPTH_TO_DESTALPHA( bool i ) + { + m_nWRITE_DEPTH_TO_DESTALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = true; +#endif + } +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + eyes_ps30_Dynamic_Index() + { +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = false; +#endif // _DEBUG + m_nWRITE_DEPTH_TO_DESTALPHA = 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bWRITE_DEPTH_TO_DESTALPHA && m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nWRITE_DEPTH_TO_DESTALPHA ) + ( 2 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_eyes_ps30 psh_forgot_to_set_dynamic_WRITE_DEPTH_TO_DESTALPHA + psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9/eyes_vs20.inc b/materialsystem/stdshaders/fxctmp9/eyes_vs20.inc new file mode 100644 index 0000000..adc6fff --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/eyes_vs20.inc @@ -0,0 +1,262 @@ +#include "shaderlib/cshader.h" +class eyes_vs20_Static_Index +{ +private: + int m_nINTRO; +#ifdef _DEBUG + bool m_bINTRO; +#endif +public: + void SetINTRO( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nINTRO = i; +#ifdef _DEBUG + m_bINTRO = true; +#endif + } + void SetINTRO( bool i ) + { + m_nINTRO = i ? 1 : 0; +#ifdef _DEBUG + m_bINTRO = true; +#endif + } +private: + int m_nHALFLAMBERT; +#ifdef _DEBUG + bool m_bHALFLAMBERT; +#endif +public: + void SetHALFLAMBERT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHALFLAMBERT = i; +#ifdef _DEBUG + m_bHALFLAMBERT = true; +#endif + } + void SetHALFLAMBERT( bool i ) + { + m_nHALFLAMBERT = i ? 1 : 0; +#ifdef _DEBUG + m_bHALFLAMBERT = true; +#endif + } +private: + int m_nUSE_STATIC_CONTROL_FLOW; +#ifdef _DEBUG + bool m_bUSE_STATIC_CONTROL_FLOW; +#endif +public: + void SetUSE_STATIC_CONTROL_FLOW( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nUSE_STATIC_CONTROL_FLOW = i; +#ifdef _DEBUG + m_bUSE_STATIC_CONTROL_FLOW = true; +#endif + } + void SetUSE_STATIC_CONTROL_FLOW( bool i ) + { + m_nUSE_STATIC_CONTROL_FLOW = i ? 1 : 0; +#ifdef _DEBUG + m_bUSE_STATIC_CONTROL_FLOW = true; +#endif + } +public: + eyes_vs20_Static_Index( ) + { +#ifdef _DEBUG + m_bINTRO = false; +#endif // _DEBUG + m_nINTRO = 0; +#ifdef _DEBUG + m_bHALFLAMBERT = false; +#endif // _DEBUG + m_nHALFLAMBERT = 0; +#ifdef _DEBUG + m_bUSE_STATIC_CONTROL_FLOW = false; +#endif // _DEBUG + m_nUSE_STATIC_CONTROL_FLOW = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bINTRO && m_bHALFLAMBERT && m_bUSE_STATIC_CONTROL_FLOW; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 96 * m_nINTRO ) + ( 192 * m_nHALFLAMBERT ) + ( 384 * m_nUSE_STATIC_CONTROL_FLOW ) + 0; + } +}; +#define shaderStaticTest_eyes_vs20 vsh_forgot_to_set_static_INTRO + vsh_forgot_to_set_static_HALFLAMBERT + vsh_forgot_to_set_static_USE_STATIC_CONTROL_FLOW + 0 +class eyes_vs20_Dynamic_Index +{ +private: + int m_nCOMPRESSED_VERTS; +#ifdef _DEBUG + bool m_bCOMPRESSED_VERTS; +#endif +public: + void SetCOMPRESSED_VERTS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOMPRESSED_VERTS = i; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } + void SetCOMPRESSED_VERTS( bool i ) + { + m_nCOMPRESSED_VERTS = i ? 1 : 0; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nDYNAMIC_LIGHT; +#ifdef _DEBUG + bool m_bDYNAMIC_LIGHT; +#endif +public: + void SetDYNAMIC_LIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDYNAMIC_LIGHT = i; +#ifdef _DEBUG + m_bDYNAMIC_LIGHT = true; +#endif + } + void SetDYNAMIC_LIGHT( bool i ) + { + m_nDYNAMIC_LIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bDYNAMIC_LIGHT = true; +#endif + } +private: + int m_nSTATIC_LIGHT; +#ifdef _DEBUG + bool m_bSTATIC_LIGHT; +#endif +public: + void SetSTATIC_LIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSTATIC_LIGHT = i; +#ifdef _DEBUG + m_bSTATIC_LIGHT = true; +#endif + } + void SetSTATIC_LIGHT( bool i ) + { + m_nSTATIC_LIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bSTATIC_LIGHT = true; +#endif + } +private: + int m_nNUM_LIGHTS; +#ifdef _DEBUG + bool m_bNUM_LIGHTS; +#endif +public: + void SetNUM_LIGHTS( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nNUM_LIGHTS = i; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } + void SetNUM_LIGHTS( bool i ) + { + m_nNUM_LIGHTS = i ? 1 : 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } +public: + eyes_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = false; +#endif // _DEBUG + m_nCOMPRESSED_VERTS = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bDYNAMIC_LIGHT = false; +#endif // _DEBUG + m_nDYNAMIC_LIGHT = 0; +#ifdef _DEBUG + m_bSTATIC_LIGHT = false; +#endif // _DEBUG + m_nSTATIC_LIGHT = 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = false; +#endif // _DEBUG + m_nNUM_LIGHTS = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bCOMPRESSED_VERTS && m_bSKINNING && m_bDOWATERFOG && m_bDYNAMIC_LIGHT && m_bSTATIC_LIGHT && m_bNUM_LIGHTS; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCOMPRESSED_VERTS ) + ( 2 * m_nSKINNING ) + ( 4 * m_nDOWATERFOG ) + ( 8 * m_nDYNAMIC_LIGHT ) + ( 16 * m_nSTATIC_LIGHT ) + ( 32 * m_nNUM_LIGHTS ) + 0; + } +}; +#define shaderDynamicTest_eyes_vs20 vsh_forgot_to_set_dynamic_COMPRESSED_VERTS + vsh_forgot_to_set_dynamic_SKINNING + vsh_forgot_to_set_dynamic_DOWATERFOG + vsh_forgot_to_set_dynamic_DYNAMIC_LIGHT + vsh_forgot_to_set_dynamic_STATIC_LIGHT + vsh_forgot_to_set_dynamic_NUM_LIGHTS + 0 diff --git a/materialsystem/stdshaders/fxctmp9/eyes_vs30.inc b/materialsystem/stdshaders/fxctmp9/eyes_vs30.inc new file mode 100644 index 0000000..dc7be6d --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/eyes_vs30.inc @@ -0,0 +1,237 @@ +#include "shaderlib/cshader.h" +class eyes_vs30_Static_Index +{ +private: + int m_nINTRO; +#ifdef _DEBUG + bool m_bINTRO; +#endif +public: + void SetINTRO( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nINTRO = i; +#ifdef _DEBUG + m_bINTRO = true; +#endif + } + void SetINTRO( bool i ) + { + m_nINTRO = i ? 1 : 0; +#ifdef _DEBUG + m_bINTRO = true; +#endif + } +private: + int m_nHALFLAMBERT; +#ifdef _DEBUG + bool m_bHALFLAMBERT; +#endif +public: + void SetHALFLAMBERT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHALFLAMBERT = i; +#ifdef _DEBUG + m_bHALFLAMBERT = true; +#endif + } + void SetHALFLAMBERT( bool i ) + { + m_nHALFLAMBERT = i ? 1 : 0; +#ifdef _DEBUG + m_bHALFLAMBERT = true; +#endif + } +public: + eyes_vs30_Static_Index( ) + { +#ifdef _DEBUG + m_bINTRO = false; +#endif // _DEBUG + m_nINTRO = 0; +#ifdef _DEBUG + m_bHALFLAMBERT = false; +#endif // _DEBUG + m_nHALFLAMBERT = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bINTRO && m_bHALFLAMBERT; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 64 * m_nINTRO ) + ( 128 * m_nHALFLAMBERT ) + 0; + } +}; +#define shaderStaticTest_eyes_vs30 vsh_forgot_to_set_static_INTRO + vsh_forgot_to_set_static_HALFLAMBERT + 0 +class eyes_vs30_Dynamic_Index +{ +private: + int m_nCOMPRESSED_VERTS; +#ifdef _DEBUG + bool m_bCOMPRESSED_VERTS; +#endif +public: + void SetCOMPRESSED_VERTS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOMPRESSED_VERTS = i; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } + void SetCOMPRESSED_VERTS( bool i ) + { + m_nCOMPRESSED_VERTS = i ? 1 : 0; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nDYNAMIC_LIGHT; +#ifdef _DEBUG + bool m_bDYNAMIC_LIGHT; +#endif +public: + void SetDYNAMIC_LIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDYNAMIC_LIGHT = i; +#ifdef _DEBUG + m_bDYNAMIC_LIGHT = true; +#endif + } + void SetDYNAMIC_LIGHT( bool i ) + { + m_nDYNAMIC_LIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bDYNAMIC_LIGHT = true; +#endif + } +private: + int m_nSTATIC_LIGHT; +#ifdef _DEBUG + bool m_bSTATIC_LIGHT; +#endif +public: + void SetSTATIC_LIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSTATIC_LIGHT = i; +#ifdef _DEBUG + m_bSTATIC_LIGHT = true; +#endif + } + void SetSTATIC_LIGHT( bool i ) + { + m_nSTATIC_LIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bSTATIC_LIGHT = true; +#endif + } +private: + int m_nMORPHING; +#ifdef _DEBUG + bool m_bMORPHING; +#endif +public: + void SetMORPHING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nMORPHING = i; +#ifdef _DEBUG + m_bMORPHING = true; +#endif + } + void SetMORPHING( bool i ) + { + m_nMORPHING = i ? 1 : 0; +#ifdef _DEBUG + m_bMORPHING = true; +#endif + } +public: + eyes_vs30_Dynamic_Index() + { +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = false; +#endif // _DEBUG + m_nCOMPRESSED_VERTS = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bDYNAMIC_LIGHT = false; +#endif // _DEBUG + m_nDYNAMIC_LIGHT = 0; +#ifdef _DEBUG + m_bSTATIC_LIGHT = false; +#endif // _DEBUG + m_nSTATIC_LIGHT = 0; +#ifdef _DEBUG + m_bMORPHING = false; +#endif // _DEBUG + m_nMORPHING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bCOMPRESSED_VERTS && m_bSKINNING && m_bDOWATERFOG && m_bDYNAMIC_LIGHT && m_bSTATIC_LIGHT && m_bMORPHING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCOMPRESSED_VERTS ) + ( 2 * m_nSKINNING ) + ( 4 * m_nDOWATERFOG ) + ( 8 * m_nDYNAMIC_LIGHT ) + ( 16 * m_nSTATIC_LIGHT ) + ( 32 * m_nMORPHING ) + 0; + } +}; +#define shaderDynamicTest_eyes_vs30 vsh_forgot_to_set_dynamic_COMPRESSED_VERTS + vsh_forgot_to_set_dynamic_SKINNING + vsh_forgot_to_set_dynamic_DOWATERFOG + vsh_forgot_to_set_dynamic_DYNAMIC_LIGHT + vsh_forgot_to_set_dynamic_STATIC_LIGHT + vsh_forgot_to_set_dynamic_MORPHING + 0 diff --git a/materialsystem/stdshaders/fxctmp9/fillrate_ps11.inc b/materialsystem/stdshaders/fxctmp9/fillrate_ps11.inc new file mode 100644 index 0000000..1bccfd0 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/fillrate_ps11.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class fillrate_ps11_Static_Index +{ +public: + fillrate_ps11_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_fillrate_ps11 0 +class fillrate_ps11_Dynamic_Index +{ +public: + fillrate_ps11_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_fillrate_ps11 0 diff --git a/materialsystem/stdshaders/fxctmp9/fillrate_ps20.inc b/materialsystem/stdshaders/fxctmp9/fillrate_ps20.inc new file mode 100644 index 0000000..f4f2dff --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/fillrate_ps20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class fillrate_ps20_Static_Index +{ +public: + fillrate_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_fillrate_ps20 0 +class fillrate_ps20_Dynamic_Index +{ +public: + fillrate_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_fillrate_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9/fillrate_ps20b.inc b/materialsystem/stdshaders/fxctmp9/fillrate_ps20b.inc new file mode 100644 index 0000000..a21374e --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/fillrate_ps20b.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class fillrate_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + fillrate_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_fillrate_ps20b 0 +class fillrate_ps20b_Dynamic_Index +{ +public: + fillrate_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_fillrate_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9/fillrate_vs11.inc b/materialsystem/stdshaders/fxctmp9/fillrate_vs11.inc new file mode 100644 index 0000000..93cae13 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/fillrate_vs11.inc @@ -0,0 +1,85 @@ +#include "shaderlib/cshader.h" +class fillrate_vs11_Static_Index +{ +public: + fillrate_vs11_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_fillrate_vs11 0 +class fillrate_vs11_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +public: + fillrate_vs11_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG && m_bSKINNING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + ( 2 * m_nSKINNING ) + 0; + } +}; +#define shaderDynamicTest_fillrate_vs11 vsh_forgot_to_set_dynamic_DOWATERFOG + vsh_forgot_to_set_dynamic_SKINNING + 0 diff --git a/materialsystem/stdshaders/fxctmp9/fillrate_vs20.inc b/materialsystem/stdshaders/fxctmp9/fillrate_vs20.inc new file mode 100644 index 0000000..6ef8914 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/fillrate_vs20.inc @@ -0,0 +1,85 @@ +#include "shaderlib/cshader.h" +class fillrate_vs20_Static_Index +{ +public: + fillrate_vs20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_fillrate_vs20 0 +class fillrate_vs20_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +public: + fillrate_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG && m_bSKINNING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + ( 2 * m_nSKINNING ) + 0; + } +}; +#define shaderDynamicTest_fillrate_vs20 vsh_forgot_to_set_dynamic_DOWATERFOG + vsh_forgot_to_set_dynamic_SKINNING + 0 diff --git a/materialsystem/stdshaders/fxctmp9/filmdust_ps11.inc b/materialsystem/stdshaders/fxctmp9/filmdust_ps11.inc new file mode 100644 index 0000000..8cee92b --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/filmdust_ps11.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class filmdust_ps11_Static_Index +{ +public: + filmdust_ps11_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_filmdust_ps11 0 +class filmdust_ps11_Dynamic_Index +{ +public: + filmdust_ps11_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_filmdust_ps11 0 diff --git a/materialsystem/stdshaders/fxctmp9/filmdust_ps20.inc b/materialsystem/stdshaders/fxctmp9/filmdust_ps20.inc new file mode 100644 index 0000000..0db6ecb --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/filmdust_ps20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class filmdust_ps20_Static_Index +{ +public: + filmdust_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_filmdust_ps20 0 +class filmdust_ps20_Dynamic_Index +{ +public: + filmdust_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_filmdust_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9/filmgrain_ps11.inc b/materialsystem/stdshaders/fxctmp9/filmgrain_ps11.inc new file mode 100644 index 0000000..2281d84 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/filmgrain_ps11.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class filmgrain_ps11_Static_Index +{ +public: + filmgrain_ps11_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_filmgrain_ps11 0 +class filmgrain_ps11_Dynamic_Index +{ +public: + filmgrain_ps11_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_filmgrain_ps11 0 diff --git a/materialsystem/stdshaders/fxctmp9/filmgrain_ps20.inc b/materialsystem/stdshaders/fxctmp9/filmgrain_ps20.inc new file mode 100644 index 0000000..ee09ea7 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/filmgrain_ps20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class filmgrain_ps20_Static_Index +{ +public: + filmgrain_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_filmgrain_ps20 0 +class filmgrain_ps20_Dynamic_Index +{ +public: + filmgrain_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_filmgrain_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9/filmgrain_vs20.inc b/materialsystem/stdshaders/fxctmp9/filmgrain_vs20.inc new file mode 100644 index 0000000..76f4842 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/filmgrain_vs20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class filmgrain_vs20_Static_Index +{ +public: + filmgrain_vs20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_filmgrain_vs20 0 +class filmgrain_vs20_Dynamic_Index +{ +public: + filmgrain_vs20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_filmgrain_vs20 0 diff --git a/materialsystem/stdshaders/fxctmp9/flashlight_ps11.inc b/materialsystem/stdshaders/fxctmp9/flashlight_ps11.inc new file mode 100644 index 0000000..64a4148 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/flashlight_ps11.inc @@ -0,0 +1,85 @@ +#include "shaderlib/cshader.h" +class flashlight_ps11_Static_Index +{ +private: + int m_nNORMALMAP; +#ifdef _DEBUG + bool m_bNORMALMAP; +#endif +public: + void SetNORMALMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nNORMALMAP = i; +#ifdef _DEBUG + m_bNORMALMAP = true; +#endif + } + void SetNORMALMAP( bool i ) + { + m_nNORMALMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bNORMALMAP = true; +#endif + } +private: + int m_nNOCULL; +#ifdef _DEBUG + bool m_bNOCULL; +#endif +public: + void SetNOCULL( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nNOCULL = i; +#ifdef _DEBUG + m_bNOCULL = true; +#endif + } + void SetNOCULL( bool i ) + { + m_nNOCULL = i ? 1 : 0; +#ifdef _DEBUG + m_bNOCULL = true; +#endif + } +public: + flashlight_ps11_Static_Index( ) + { +#ifdef _DEBUG + m_bNORMALMAP = false; +#endif // _DEBUG + m_nNORMALMAP = 0; +#ifdef _DEBUG + m_bNOCULL = false; +#endif // _DEBUG + m_nNOCULL = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bNORMALMAP && m_bNOCULL; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nNORMALMAP ) + ( 2 * m_nNOCULL ) + 0; + } +}; +#define shaderStaticTest_flashlight_ps11 psh_forgot_to_set_static_NORMALMAP + psh_forgot_to_set_static_NOCULL + 0 +class flashlight_ps11_Dynamic_Index +{ +public: + flashlight_ps11_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_flashlight_ps11 0 diff --git a/materialsystem/stdshaders/fxctmp9/flashlight_ps20.inc b/materialsystem/stdshaders/fxctmp9/flashlight_ps20.inc new file mode 100644 index 0000000..c98a45d --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/flashlight_ps20.inc @@ -0,0 +1,212 @@ +#include "shaderlib/cshader.h" +class flashlight_ps20_Static_Index +{ +private: + int m_nNORMALMAP; +#ifdef _DEBUG + bool m_bNORMALMAP; +#endif +public: + void SetNORMALMAP( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nNORMALMAP = i; +#ifdef _DEBUG + m_bNORMALMAP = true; +#endif + } + void SetNORMALMAP( bool i ) + { + m_nNORMALMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bNORMALMAP = true; +#endif + } +private: + int m_nNORMALMAP2; +#ifdef _DEBUG + bool m_bNORMALMAP2; +#endif +public: + void SetNORMALMAP2( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nNORMALMAP2 = i; +#ifdef _DEBUG + m_bNORMALMAP2 = true; +#endif + } + void SetNORMALMAP2( bool i ) + { + m_nNORMALMAP2 = i ? 1 : 0; +#ifdef _DEBUG + m_bNORMALMAP2 = true; +#endif + } +private: + int m_nWORLDVERTEXTRANSITION; +#ifdef _DEBUG + bool m_bWORLDVERTEXTRANSITION; +#endif +public: + void SetWORLDVERTEXTRANSITION( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nWORLDVERTEXTRANSITION = i; +#ifdef _DEBUG + m_bWORLDVERTEXTRANSITION = true; +#endif + } + void SetWORLDVERTEXTRANSITION( bool i ) + { + m_nWORLDVERTEXTRANSITION = i ? 1 : 0; +#ifdef _DEBUG + m_bWORLDVERTEXTRANSITION = true; +#endif + } +private: + int m_nSEAMLESS; +#ifdef _DEBUG + bool m_bSEAMLESS; +#endif +public: + void SetSEAMLESS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSEAMLESS = i; +#ifdef _DEBUG + m_bSEAMLESS = true; +#endif + } + void SetSEAMLESS( bool i ) + { + m_nSEAMLESS = i ? 1 : 0; +#ifdef _DEBUG + m_bSEAMLESS = true; +#endif + } +private: + int m_nDETAILTEXTURE; +#ifdef _DEBUG + bool m_bDETAILTEXTURE; +#endif +public: + void SetDETAILTEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDETAILTEXTURE = i; +#ifdef _DEBUG + m_bDETAILTEXTURE = true; +#endif + } + void SetDETAILTEXTURE( bool i ) + { + m_nDETAILTEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bDETAILTEXTURE = true; +#endif + } +private: + int m_nDETAIL_BLEND_MODE; +#ifdef _DEBUG + bool m_bDETAIL_BLEND_MODE; +#endif +public: + void SetDETAIL_BLEND_MODE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDETAIL_BLEND_MODE = i; +#ifdef _DEBUG + m_bDETAIL_BLEND_MODE = true; +#endif + } + void SetDETAIL_BLEND_MODE( bool i ) + { + m_nDETAIL_BLEND_MODE = i ? 1 : 0; +#ifdef _DEBUG + m_bDETAIL_BLEND_MODE = true; +#endif + } +public: + flashlight_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bNORMALMAP = false; +#endif // _DEBUG + m_nNORMALMAP = 0; +#ifdef _DEBUG + m_bNORMALMAP2 = false; +#endif // _DEBUG + m_nNORMALMAP2 = 0; +#ifdef _DEBUG + m_bWORLDVERTEXTRANSITION = false; +#endif // _DEBUG + m_nWORLDVERTEXTRANSITION = 0; +#ifdef _DEBUG + m_bSEAMLESS = false; +#endif // _DEBUG + m_nSEAMLESS = 0; +#ifdef _DEBUG + m_bDETAILTEXTURE = false; +#endif // _DEBUG + m_nDETAILTEXTURE = 0; +#ifdef _DEBUG + m_bDETAIL_BLEND_MODE = false; +#endif // _DEBUG + m_nDETAIL_BLEND_MODE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bNORMALMAP && m_bNORMALMAP2 && m_bWORLDVERTEXTRANSITION && m_bSEAMLESS && m_bDETAILTEXTURE && m_bDETAIL_BLEND_MODE; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nNORMALMAP ) + ( 6 * m_nNORMALMAP2 ) + ( 12 * m_nWORLDVERTEXTRANSITION ) + ( 24 * m_nSEAMLESS ) + ( 48 * m_nDETAILTEXTURE ) + ( 96 * m_nDETAIL_BLEND_MODE ) + 0; + } +}; +#define shaderStaticTest_flashlight_ps20 psh_forgot_to_set_static_NORMALMAP + psh_forgot_to_set_static_NORMALMAP2 + psh_forgot_to_set_static_WORLDVERTEXTRANSITION + psh_forgot_to_set_static_SEAMLESS + psh_forgot_to_set_static_DETAILTEXTURE + psh_forgot_to_set_static_DETAIL_BLEND_MODE + 0 +class flashlight_ps20_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + flashlight_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_flashlight_ps20 psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9/flashlight_ps20b.inc b/materialsystem/stdshaders/fxctmp9/flashlight_ps20b.inc new file mode 100644 index 0000000..36d7c00 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/flashlight_ps20b.inc @@ -0,0 +1,262 @@ +#include "shaderlib/cshader.h" +class flashlight_ps20b_Static_Index +{ +private: + int m_nNORMALMAP; +#ifdef _DEBUG + bool m_bNORMALMAP; +#endif +public: + void SetNORMALMAP( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nNORMALMAP = i; +#ifdef _DEBUG + m_bNORMALMAP = true; +#endif + } + void SetNORMALMAP( bool i ) + { + m_nNORMALMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bNORMALMAP = true; +#endif + } +private: + int m_nNORMALMAP2; +#ifdef _DEBUG + bool m_bNORMALMAP2; +#endif +public: + void SetNORMALMAP2( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nNORMALMAP2 = i; +#ifdef _DEBUG + m_bNORMALMAP2 = true; +#endif + } + void SetNORMALMAP2( bool i ) + { + m_nNORMALMAP2 = i ? 1 : 0; +#ifdef _DEBUG + m_bNORMALMAP2 = true; +#endif + } +private: + int m_nWORLDVERTEXTRANSITION; +#ifdef _DEBUG + bool m_bWORLDVERTEXTRANSITION; +#endif +public: + void SetWORLDVERTEXTRANSITION( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nWORLDVERTEXTRANSITION = i; +#ifdef _DEBUG + m_bWORLDVERTEXTRANSITION = true; +#endif + } + void SetWORLDVERTEXTRANSITION( bool i ) + { + m_nWORLDVERTEXTRANSITION = i ? 1 : 0; +#ifdef _DEBUG + m_bWORLDVERTEXTRANSITION = true; +#endif + } +private: + int m_nSEAMLESS; +#ifdef _DEBUG + bool m_bSEAMLESS; +#endif +public: + void SetSEAMLESS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSEAMLESS = i; +#ifdef _DEBUG + m_bSEAMLESS = true; +#endif + } + void SetSEAMLESS( bool i ) + { + m_nSEAMLESS = i ? 1 : 0; +#ifdef _DEBUG + m_bSEAMLESS = true; +#endif + } +private: + int m_nDETAILTEXTURE; +#ifdef _DEBUG + bool m_bDETAILTEXTURE; +#endif +public: + void SetDETAILTEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDETAILTEXTURE = i; +#ifdef _DEBUG + m_bDETAILTEXTURE = true; +#endif + } + void SetDETAILTEXTURE( bool i ) + { + m_nDETAILTEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bDETAILTEXTURE = true; +#endif + } +private: + int m_nDETAIL_BLEND_MODE; +#ifdef _DEBUG + bool m_bDETAIL_BLEND_MODE; +#endif +public: + void SetDETAIL_BLEND_MODE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDETAIL_BLEND_MODE = i; +#ifdef _DEBUG + m_bDETAIL_BLEND_MODE = true; +#endif + } + void SetDETAIL_BLEND_MODE( bool i ) + { + m_nDETAIL_BLEND_MODE = i ? 1 : 0; +#ifdef _DEBUG + m_bDETAIL_BLEND_MODE = true; +#endif + } +private: + int m_nFLASHLIGHTDEPTHFILTERMODE; +#ifdef _DEBUG + bool m_bFLASHLIGHTDEPTHFILTERMODE; +#endif +public: + void SetFLASHLIGHTDEPTHFILTERMODE( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nFLASHLIGHTDEPTHFILTERMODE = i; +#ifdef _DEBUG + m_bFLASHLIGHTDEPTHFILTERMODE = true; +#endif + } + void SetFLASHLIGHTDEPTHFILTERMODE( bool i ) + { + m_nFLASHLIGHTDEPTHFILTERMODE = i ? 1 : 0; +#ifdef _DEBUG + m_bFLASHLIGHTDEPTHFILTERMODE = true; +#endif + } +public: + flashlight_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bNORMALMAP = false; +#endif // _DEBUG + m_nNORMALMAP = 0; +#ifdef _DEBUG + m_bNORMALMAP2 = false; +#endif // _DEBUG + m_nNORMALMAP2 = 0; +#ifdef _DEBUG + m_bWORLDVERTEXTRANSITION = false; +#endif // _DEBUG + m_nWORLDVERTEXTRANSITION = 0; +#ifdef _DEBUG + m_bSEAMLESS = false; +#endif // _DEBUG + m_nSEAMLESS = 0; +#ifdef _DEBUG + m_bDETAILTEXTURE = false; +#endif // _DEBUG + m_nDETAILTEXTURE = 0; +#ifdef _DEBUG + m_bDETAIL_BLEND_MODE = false; +#endif // _DEBUG + m_nDETAIL_BLEND_MODE = 0; +#ifdef _DEBUG + m_bFLASHLIGHTDEPTHFILTERMODE = false; +#endif // _DEBUG + m_nFLASHLIGHTDEPTHFILTERMODE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bNORMALMAP && m_bNORMALMAP2 && m_bWORLDVERTEXTRANSITION && m_bSEAMLESS && m_bDETAILTEXTURE && m_bDETAIL_BLEND_MODE && m_bFLASHLIGHTDEPTHFILTERMODE; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 4 * m_nNORMALMAP ) + ( 12 * m_nNORMALMAP2 ) + ( 24 * m_nWORLDVERTEXTRANSITION ) + ( 48 * m_nSEAMLESS ) + ( 96 * m_nDETAILTEXTURE ) + ( 192 * m_nDETAIL_BLEND_MODE ) + ( 384 * m_nFLASHLIGHTDEPTHFILTERMODE ) + 0; + } +}; +#define shaderStaticTest_flashlight_ps20b psh_forgot_to_set_static_NORMALMAP + psh_forgot_to_set_static_NORMALMAP2 + psh_forgot_to_set_static_WORLDVERTEXTRANSITION + psh_forgot_to_set_static_SEAMLESS + psh_forgot_to_set_static_DETAILTEXTURE + psh_forgot_to_set_static_DETAIL_BLEND_MODE + psh_forgot_to_set_static_FLASHLIGHTDEPTHFILTERMODE + 0 +class flashlight_ps20b_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +private: + int m_nFLASHLIGHTSHADOWS; +#ifdef _DEBUG + bool m_bFLASHLIGHTSHADOWS; +#endif +public: + void SetFLASHLIGHTSHADOWS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFLASHLIGHTSHADOWS = i; +#ifdef _DEBUG + m_bFLASHLIGHTSHADOWS = true; +#endif + } + void SetFLASHLIGHTSHADOWS( bool i ) + { + m_nFLASHLIGHTSHADOWS = i ? 1 : 0; +#ifdef _DEBUG + m_bFLASHLIGHTSHADOWS = true; +#endif + } +public: + flashlight_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; +#ifdef _DEBUG + m_bFLASHLIGHTSHADOWS = false; +#endif // _DEBUG + m_nFLASHLIGHTSHADOWS = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE && m_bFLASHLIGHTSHADOWS; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + ( 2 * m_nFLASHLIGHTSHADOWS ) + 0; + } +}; +#define shaderDynamicTest_flashlight_ps20b psh_forgot_to_set_dynamic_PIXELFOGTYPE + psh_forgot_to_set_dynamic_FLASHLIGHTSHADOWS + 0 diff --git a/materialsystem/stdshaders/fxctmp9/flesh_interior_blended_pass_ps20.inc b/materialsystem/stdshaders/fxctmp9/flesh_interior_blended_pass_ps20.inc new file mode 100644 index 0000000..89ddb22 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/flesh_interior_blended_pass_ps20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class flesh_interior_blended_pass_ps20_Static_Index +{ +public: + flesh_interior_blended_pass_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_flesh_interior_blended_pass_ps20 0 +class flesh_interior_blended_pass_ps20_Dynamic_Index +{ +public: + flesh_interior_blended_pass_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_flesh_interior_blended_pass_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9/flesh_interior_blended_pass_ps20b.inc b/materialsystem/stdshaders/fxctmp9/flesh_interior_blended_pass_ps20b.inc new file mode 100644 index 0000000..ae707c0 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/flesh_interior_blended_pass_ps20b.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class flesh_interior_blended_pass_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + flesh_interior_blended_pass_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_flesh_interior_blended_pass_ps20b 0 +class flesh_interior_blended_pass_ps20b_Dynamic_Index +{ +public: + flesh_interior_blended_pass_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_flesh_interior_blended_pass_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9/flesh_interior_blended_pass_vs20.inc b/materialsystem/stdshaders/fxctmp9/flesh_interior_blended_pass_vs20.inc new file mode 100644 index 0000000..2b7143e --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/flesh_interior_blended_pass_vs20.inc @@ -0,0 +1,237 @@ +#include "shaderlib/cshader.h" +class flesh_interior_blended_pass_vs20_Static_Index +{ +private: + int m_nHALFLAMBERT; +#ifdef _DEBUG + bool m_bHALFLAMBERT; +#endif +public: + void SetHALFLAMBERT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHALFLAMBERT = i; +#ifdef _DEBUG + m_bHALFLAMBERT = true; +#endif + } + void SetHALFLAMBERT( bool i ) + { + m_nHALFLAMBERT = i ? 1 : 0; +#ifdef _DEBUG + m_bHALFLAMBERT = true; +#endif + } +private: + int m_nUSE_STATIC_CONTROL_FLOW; +#ifdef _DEBUG + bool m_bUSE_STATIC_CONTROL_FLOW; +#endif +public: + void SetUSE_STATIC_CONTROL_FLOW( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nUSE_STATIC_CONTROL_FLOW = i; +#ifdef _DEBUG + m_bUSE_STATIC_CONTROL_FLOW = true; +#endif + } + void SetUSE_STATIC_CONTROL_FLOW( bool i ) + { + m_nUSE_STATIC_CONTROL_FLOW = i ? 1 : 0; +#ifdef _DEBUG + m_bUSE_STATIC_CONTROL_FLOW = true; +#endif + } +public: + flesh_interior_blended_pass_vs20_Static_Index( ) + { +#ifdef _DEBUG + m_bHALFLAMBERT = false; +#endif // _DEBUG + m_nHALFLAMBERT = 0; +#ifdef _DEBUG + m_bUSE_STATIC_CONTROL_FLOW = false; +#endif // _DEBUG + m_nUSE_STATIC_CONTROL_FLOW = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bHALFLAMBERT && m_bUSE_STATIC_CONTROL_FLOW; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 96 * m_nHALFLAMBERT ) + ( 192 * m_nUSE_STATIC_CONTROL_FLOW ) + 0; + } +}; +#define shaderStaticTest_flesh_interior_blended_pass_vs20 vsh_forgot_to_set_static_HALFLAMBERT + vsh_forgot_to_set_static_USE_STATIC_CONTROL_FLOW + 0 +class flesh_interior_blended_pass_vs20_Dynamic_Index +{ +private: + int m_nCOMPRESSED_VERTS; +#ifdef _DEBUG + bool m_bCOMPRESSED_VERTS; +#endif +public: + void SetCOMPRESSED_VERTS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOMPRESSED_VERTS = i; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } + void SetCOMPRESSED_VERTS( bool i ) + { + m_nCOMPRESSED_VERTS = i ? 1 : 0; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nDYNAMIC_LIGHT; +#ifdef _DEBUG + bool m_bDYNAMIC_LIGHT; +#endif +public: + void SetDYNAMIC_LIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDYNAMIC_LIGHT = i; +#ifdef _DEBUG + m_bDYNAMIC_LIGHT = true; +#endif + } + void SetDYNAMIC_LIGHT( bool i ) + { + m_nDYNAMIC_LIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bDYNAMIC_LIGHT = true; +#endif + } +private: + int m_nSTATIC_LIGHT; +#ifdef _DEBUG + bool m_bSTATIC_LIGHT; +#endif +public: + void SetSTATIC_LIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSTATIC_LIGHT = i; +#ifdef _DEBUG + m_bSTATIC_LIGHT = true; +#endif + } + void SetSTATIC_LIGHT( bool i ) + { + m_nSTATIC_LIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bSTATIC_LIGHT = true; +#endif + } +private: + int m_nNUM_LIGHTS; +#ifdef _DEBUG + bool m_bNUM_LIGHTS; +#endif +public: + void SetNUM_LIGHTS( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nNUM_LIGHTS = i; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } + void SetNUM_LIGHTS( bool i ) + { + m_nNUM_LIGHTS = i ? 1 : 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } +public: + flesh_interior_blended_pass_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = false; +#endif // _DEBUG + m_nCOMPRESSED_VERTS = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bDYNAMIC_LIGHT = false; +#endif // _DEBUG + m_nDYNAMIC_LIGHT = 0; +#ifdef _DEBUG + m_bSTATIC_LIGHT = false; +#endif // _DEBUG + m_nSTATIC_LIGHT = 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = false; +#endif // _DEBUG + m_nNUM_LIGHTS = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bCOMPRESSED_VERTS && m_bSKINNING && m_bDOWATERFOG && m_bDYNAMIC_LIGHT && m_bSTATIC_LIGHT && m_bNUM_LIGHTS; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCOMPRESSED_VERTS ) + ( 2 * m_nSKINNING ) + ( 4 * m_nDOWATERFOG ) + ( 8 * m_nDYNAMIC_LIGHT ) + ( 16 * m_nSTATIC_LIGHT ) + ( 32 * m_nNUM_LIGHTS ) + 0; + } +}; +#define shaderDynamicTest_flesh_interior_blended_pass_vs20 vsh_forgot_to_set_dynamic_COMPRESSED_VERTS + vsh_forgot_to_set_dynamic_SKINNING + vsh_forgot_to_set_dynamic_DOWATERFOG + vsh_forgot_to_set_dynamic_DYNAMIC_LIGHT + vsh_forgot_to_set_dynamic_STATIC_LIGHT + vsh_forgot_to_set_dynamic_NUM_LIGHTS + 0 diff --git a/materialsystem/stdshaders/fxctmp9/floatcombine_autoexpose_ps20.inc b/materialsystem/stdshaders/fxctmp9/floatcombine_autoexpose_ps20.inc new file mode 100644 index 0000000..9fcb27d --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/floatcombine_autoexpose_ps20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class floatcombine_autoexpose_ps20_Static_Index +{ +public: + floatcombine_autoexpose_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_floatcombine_autoexpose_ps20 0 +class floatcombine_autoexpose_ps20_Dynamic_Index +{ +public: + floatcombine_autoexpose_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_floatcombine_autoexpose_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9/floatcombine_autoexpose_ps20b.inc b/materialsystem/stdshaders/fxctmp9/floatcombine_autoexpose_ps20b.inc new file mode 100644 index 0000000..724ad07 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/floatcombine_autoexpose_ps20b.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class floatcombine_autoexpose_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + floatcombine_autoexpose_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_floatcombine_autoexpose_ps20b 0 +class floatcombine_autoexpose_ps20b_Dynamic_Index +{ +public: + floatcombine_autoexpose_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_floatcombine_autoexpose_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9/floatcombine_ps20.inc b/materialsystem/stdshaders/fxctmp9/floatcombine_ps20.inc new file mode 100644 index 0000000..0562a0d --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/floatcombine_ps20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class floatcombine_ps20_Static_Index +{ +public: + floatcombine_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_floatcombine_ps20 0 +class floatcombine_ps20_Dynamic_Index +{ +public: + floatcombine_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_floatcombine_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9/floatcombine_ps20b.inc b/materialsystem/stdshaders/fxctmp9/floatcombine_ps20b.inc new file mode 100644 index 0000000..6ddb0cd --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/floatcombine_ps20b.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class floatcombine_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + floatcombine_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_floatcombine_ps20b 0 +class floatcombine_ps20b_Dynamic_Index +{ +public: + floatcombine_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_floatcombine_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9/floattoscreen_notonemap_ps20.inc b/materialsystem/stdshaders/fxctmp9/floattoscreen_notonemap_ps20.inc new file mode 100644 index 0000000..3308fb7 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/floattoscreen_notonemap_ps20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class floattoscreen_notonemap_ps20_Static_Index +{ +public: + floattoscreen_notonemap_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_floattoscreen_notonemap_ps20 0 +class floattoscreen_notonemap_ps20_Dynamic_Index +{ +public: + floattoscreen_notonemap_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_floattoscreen_notonemap_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9/floattoscreen_notonemap_ps20b.inc b/materialsystem/stdshaders/fxctmp9/floattoscreen_notonemap_ps20b.inc new file mode 100644 index 0000000..fc47529 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/floattoscreen_notonemap_ps20b.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class floattoscreen_notonemap_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + floattoscreen_notonemap_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_floattoscreen_notonemap_ps20b 0 +class floattoscreen_notonemap_ps20b_Dynamic_Index +{ +public: + floattoscreen_notonemap_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_floattoscreen_notonemap_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9/floattoscreen_ps20.inc b/materialsystem/stdshaders/fxctmp9/floattoscreen_ps20.inc new file mode 100644 index 0000000..8cd8b62 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/floattoscreen_ps20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class floattoscreen_ps20_Static_Index +{ +public: + floattoscreen_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_floattoscreen_ps20 0 +class floattoscreen_ps20_Dynamic_Index +{ +public: + floattoscreen_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_floattoscreen_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9/floattoscreen_ps20b.inc b/materialsystem/stdshaders/fxctmp9/floattoscreen_ps20b.inc new file mode 100644 index 0000000..0a02562 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/floattoscreen_ps20b.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class floattoscreen_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + floattoscreen_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_floattoscreen_ps20b 0 +class floattoscreen_ps20b_Dynamic_Index +{ +public: + floattoscreen_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_floattoscreen_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9/floattoscreen_vanilla_ps20.inc b/materialsystem/stdshaders/fxctmp9/floattoscreen_vanilla_ps20.inc new file mode 100644 index 0000000..21fd839 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/floattoscreen_vanilla_ps20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class floattoscreen_vanilla_ps20_Static_Index +{ +public: + floattoscreen_vanilla_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_floattoscreen_vanilla_ps20 0 +class floattoscreen_vanilla_ps20_Dynamic_Index +{ +public: + floattoscreen_vanilla_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_floattoscreen_vanilla_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9/floattoscreen_vanilla_ps20b.inc b/materialsystem/stdshaders/fxctmp9/floattoscreen_vanilla_ps20b.inc new file mode 100644 index 0000000..2bb7715 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/floattoscreen_vanilla_ps20b.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class floattoscreen_vanilla_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + floattoscreen_vanilla_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_floattoscreen_vanilla_ps20b 0 +class floattoscreen_vanilla_ps20b_Dynamic_Index +{ +public: + floattoscreen_vanilla_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_floattoscreen_vanilla_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9/haloadd1d_ps20.inc b/materialsystem/stdshaders/fxctmp9/haloadd1d_ps20.inc new file mode 100644 index 0000000..f861fad --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/haloadd1d_ps20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class haloadd1d_ps20_Static_Index +{ +public: + haloadd1d_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_haloadd1d_ps20 0 +class haloadd1d_ps20_Dynamic_Index +{ +public: + haloadd1d_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_haloadd1d_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9/haloadd1d_ps20b.inc b/materialsystem/stdshaders/fxctmp9/haloadd1d_ps20b.inc new file mode 100644 index 0000000..c2bf645 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/haloadd1d_ps20b.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class haloadd1d_ps20b_Static_Index +{ +public: + haloadd1d_ps20b_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_haloadd1d_ps20b 0 +class haloadd1d_ps20b_Dynamic_Index +{ +public: + haloadd1d_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_haloadd1d_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9/haloadd_ps20.inc b/materialsystem/stdshaders/fxctmp9/haloadd_ps20.inc new file mode 100644 index 0000000..fe692d6 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/haloadd_ps20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class haloadd_ps20_Static_Index +{ +public: + haloadd_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_haloadd_ps20 0 +class haloadd_ps20_Dynamic_Index +{ +public: + haloadd_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_haloadd_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9/haloadd_ps20b.inc b/materialsystem/stdshaders/fxctmp9/haloadd_ps20b.inc new file mode 100644 index 0000000..d9eb204 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/haloadd_ps20b.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class haloadd_ps20b_Static_Index +{ +public: + haloadd_ps20b_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_haloadd_ps20b 0 +class haloadd_ps20b_Dynamic_Index +{ +public: + haloadd_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_haloadd_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9/haloaddoutline_ps20.inc b/materialsystem/stdshaders/fxctmp9/haloaddoutline_ps20.inc new file mode 100644 index 0000000..a557ee1 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/haloaddoutline_ps20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class haloaddoutline_ps20_Static_Index +{ +public: + haloaddoutline_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_haloaddoutline_ps20 0 +class haloaddoutline_ps20_Dynamic_Index +{ +public: + haloaddoutline_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_haloaddoutline_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9/haloaddoutline_ps20b.inc b/materialsystem/stdshaders/fxctmp9/haloaddoutline_ps20b.inc new file mode 100644 index 0000000..0b26b29 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/haloaddoutline_ps20b.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class haloaddoutline_ps20b_Static_Index +{ +public: + haloaddoutline_ps20b_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_haloaddoutline_ps20b 0 +class haloaddoutline_ps20b_Dynamic_Index +{ +public: + haloaddoutline_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_haloaddoutline_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9/hsl_filmgrain_pass1_ps20.inc b/materialsystem/stdshaders/fxctmp9/hsl_filmgrain_pass1_ps20.inc new file mode 100644 index 0000000..ef1cdd4 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/hsl_filmgrain_pass1_ps20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class hsl_filmgrain_pass1_ps20_Static_Index +{ +public: + hsl_filmgrain_pass1_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_hsl_filmgrain_pass1_ps20 0 +class hsl_filmgrain_pass1_ps20_Dynamic_Index +{ +public: + hsl_filmgrain_pass1_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_hsl_filmgrain_pass1_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9/hsl_filmgrain_pass1_ps20b.inc b/materialsystem/stdshaders/fxctmp9/hsl_filmgrain_pass1_ps20b.inc new file mode 100644 index 0000000..e8560ec --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/hsl_filmgrain_pass1_ps20b.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class hsl_filmgrain_pass1_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + hsl_filmgrain_pass1_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_hsl_filmgrain_pass1_ps20b 0 +class hsl_filmgrain_pass1_ps20b_Dynamic_Index +{ +public: + hsl_filmgrain_pass1_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_hsl_filmgrain_pass1_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9/hsl_filmgrain_pass2_ps20.inc b/materialsystem/stdshaders/fxctmp9/hsl_filmgrain_pass2_ps20.inc new file mode 100644 index 0000000..81d3e18 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/hsl_filmgrain_pass2_ps20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class hsl_filmgrain_pass2_ps20_Static_Index +{ +public: + hsl_filmgrain_pass2_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_hsl_filmgrain_pass2_ps20 0 +class hsl_filmgrain_pass2_ps20_Dynamic_Index +{ +public: + hsl_filmgrain_pass2_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_hsl_filmgrain_pass2_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9/hsl_filmgrain_pass2_ps20b.inc b/materialsystem/stdshaders/fxctmp9/hsl_filmgrain_pass2_ps20b.inc new file mode 100644 index 0000000..e9a1b3f --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/hsl_filmgrain_pass2_ps20b.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class hsl_filmgrain_pass2_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + hsl_filmgrain_pass2_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_hsl_filmgrain_pass2_ps20b 0 +class hsl_filmgrain_pass2_ps20b_Dynamic_Index +{ +public: + hsl_filmgrain_pass2_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_hsl_filmgrain_pass2_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9/hsv_ps20.inc b/materialsystem/stdshaders/fxctmp9/hsv_ps20.inc new file mode 100644 index 0000000..3fc2973 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/hsv_ps20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class hsv_ps20_Static_Index +{ +public: + hsv_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_hsv_ps20 0 +class hsv_ps20_Dynamic_Index +{ +public: + hsv_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_hsv_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9/hsv_ps20b.inc b/materialsystem/stdshaders/fxctmp9/hsv_ps20b.inc new file mode 100644 index 0000000..5149c85 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/hsv_ps20b.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class hsv_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + hsv_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_hsv_ps20b 0 +class hsv_ps20b_Dynamic_Index +{ +public: + hsv_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_hsv_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9/introscreenspaceeffect_ps11.inc b/materialsystem/stdshaders/fxctmp9/introscreenspaceeffect_ps11.inc new file mode 100644 index 0000000..a7afc44 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/introscreenspaceeffect_ps11.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class introscreenspaceeffect_ps11_Static_Index +{ +public: + introscreenspaceeffect_ps11_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_introscreenspaceeffect_ps11 0 +class introscreenspaceeffect_ps11_Dynamic_Index +{ +private: + int m_nMODE; +#ifdef _DEBUG + bool m_bMODE; +#endif +public: + void SetMODE( int i ) + { + Assert( i >= 0 && i <= 9 ); + m_nMODE = i; +#ifdef _DEBUG + m_bMODE = true; +#endif + } + void SetMODE( bool i ) + { + m_nMODE = i ? 1 : 0; +#ifdef _DEBUG + m_bMODE = true; +#endif + } +public: + introscreenspaceeffect_ps11_Dynamic_Index() + { +#ifdef _DEBUG + m_bMODE = false; +#endif // _DEBUG + m_nMODE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bMODE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nMODE ) + 0; + } +}; +#define shaderDynamicTest_introscreenspaceeffect_ps11 psh_forgot_to_set_dynamic_MODE + 0 diff --git a/materialsystem/stdshaders/fxctmp9/lightingonly_vs20.inc b/materialsystem/stdshaders/fxctmp9/lightingonly_vs20.inc new file mode 100644 index 0000000..c351859 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/lightingonly_vs20.inc @@ -0,0 +1,161 @@ +class lightingonly_vs20_Static_Index +{ +private: + int m_nHALFLAMBERT; +#ifdef _DEBUG + bool m_bHALFLAMBERT; +#endif +public: + void SetHALFLAMBERT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHALFLAMBERT = i; +#ifdef _DEBUG + m_bHALFLAMBERT = true; +#endif + } + void SetHALFLAMBERT( bool i ) + { + m_nHALFLAMBERT = i ? 1 : 0; +#ifdef _DEBUG + m_bHALFLAMBERT = true; +#endif + } +public: + lightingonly_vs20_Static_Index() + { +#ifdef _DEBUG + m_bHALFLAMBERT = false; +#endif // _DEBUG + m_nHALFLAMBERT = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bHALFLAMBERT; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 32 * m_nHALFLAMBERT ) + 0; + } +}; +#define shaderStaticTest_lightingonly_vs20 vsh_forgot_to_set_static_HALFLAMBERT + 0 +class lightingonly_vs20_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nNUM_BONES; +#ifdef _DEBUG + bool m_bNUM_BONES; +#endif +public: + void SetNUM_BONES( int i ) + { + Assert( i >= 0 && i <= 3 ); + m_nNUM_BONES = i; +#ifdef _DEBUG + m_bNUM_BONES = true; +#endif + } + void SetNUM_BONES( bool i ) + { + m_nNUM_BONES = i ? 1 : 0; +#ifdef _DEBUG + m_bNUM_BONES = true; +#endif + } +private: + int m_nAMBIENT_LIGHT; +#ifdef _DEBUG + bool m_bAMBIENT_LIGHT; +#endif +public: + void SetAMBIENT_LIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nAMBIENT_LIGHT = i; +#ifdef _DEBUG + m_bAMBIENT_LIGHT = true; +#endif + } + void SetAMBIENT_LIGHT( bool i ) + { + m_nAMBIENT_LIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bAMBIENT_LIGHT = true; +#endif + } +private: + int m_nSTATIC_LIGHT; +#ifdef _DEBUG + bool m_bSTATIC_LIGHT; +#endif +public: + void SetSTATIC_LIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSTATIC_LIGHT = i; +#ifdef _DEBUG + m_bSTATIC_LIGHT = true; +#endif + } + void SetSTATIC_LIGHT( bool i ) + { + m_nSTATIC_LIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bSTATIC_LIGHT = true; +#endif + } +public: + lightingonly_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bNUM_BONES = false; +#endif // _DEBUG + m_nNUM_BONES = 0; +#ifdef _DEBUG + m_bAMBIENT_LIGHT = false; +#endif // _DEBUG + m_nAMBIENT_LIGHT = 0; +#ifdef _DEBUG + m_bSTATIC_LIGHT = false; +#endif // _DEBUG + m_nSTATIC_LIGHT = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG && m_bNUM_BONES && m_bAMBIENT_LIGHT && m_bSTATIC_LIGHT; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + ( 2 * m_nNUM_BONES ) + ( 8 * m_nAMBIENT_LIGHT ) + ( 16 * m_nSTATIC_LIGHT ) + 0; + } +}; +#define shaderDynamicTest_lightingonly_vs20 vsh_forgot_to_set_dynamic_DOWATERFOG + vsh_forgot_to_set_dynamic_NUM_BONES + vsh_forgot_to_set_dynamic_AMBIENT_LIGHT + vsh_forgot_to_set_dynamic_STATIC_LIGHT + 0 diff --git a/materialsystem/stdshaders/fxctmp9/lightmappedgeneric_decal_ps20.inc b/materialsystem/stdshaders/fxctmp9/lightmappedgeneric_decal_ps20.inc new file mode 100644 index 0000000..698b0a7 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/lightmappedgeneric_decal_ps20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class lightmappedgeneric_decal_ps20_Static_Index +{ +public: + lightmappedgeneric_decal_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_lightmappedgeneric_decal_ps20 0 +class lightmappedgeneric_decal_ps20_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + lightmappedgeneric_decal_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_lightmappedgeneric_decal_ps20 psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9/lightmappedgeneric_decal_ps20b.inc b/materialsystem/stdshaders/fxctmp9/lightmappedgeneric_decal_ps20b.inc new file mode 100644 index 0000000..cb2861d --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/lightmappedgeneric_decal_ps20b.inc @@ -0,0 +1,87 @@ +#include "shaderlib/cshader.h" +class lightmappedgeneric_decal_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + lightmappedgeneric_decal_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_lightmappedgeneric_decal_ps20b 0 +class lightmappedgeneric_decal_ps20b_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + lightmappedgeneric_decal_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_lightmappedgeneric_decal_ps20b psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9/lightmappedgeneric_decal_vs20.inc b/materialsystem/stdshaders/fxctmp9/lightmappedgeneric_decal_vs20.inc new file mode 100644 index 0000000..b8106ca --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/lightmappedgeneric_decal_vs20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class lightmappedgeneric_decal_vs20_Static_Index +{ +public: + lightmappedgeneric_decal_vs20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_lightmappedgeneric_decal_vs20 0 +class lightmappedgeneric_decal_vs20_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + lightmappedgeneric_decal_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; +#define shaderDynamicTest_lightmappedgeneric_decal_vs20 vsh_forgot_to_set_dynamic_DOWATERFOG + 0 diff --git a/materialsystem/stdshaders/fxctmp9/lightmappedgeneric_flashlight_vs11.inc b/materialsystem/stdshaders/fxctmp9/lightmappedgeneric_flashlight_vs11.inc new file mode 100644 index 0000000..fbf5256 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/lightmappedgeneric_flashlight_vs11.inc @@ -0,0 +1,137 @@ +#include "shaderlib/cshader.h" +class lightmappedgeneric_flashlight_vs11_Static_Index +{ +private: + int m_nNORMALMAP; +#ifdef _DEBUG + bool m_bNORMALMAP; +#endif +public: + void SetNORMALMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nNORMALMAP = i; +#ifdef _DEBUG + m_bNORMALMAP = true; +#endif + } + void SetNORMALMAP( bool i ) + { + m_nNORMALMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bNORMALMAP = true; +#endif + } +private: + int m_nWORLDVERTEXTRANSITION; +#ifdef _DEBUG + bool m_bWORLDVERTEXTRANSITION; +#endif +public: + void SetWORLDVERTEXTRANSITION( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nWORLDVERTEXTRANSITION = i; +#ifdef _DEBUG + m_bWORLDVERTEXTRANSITION = true; +#endif + } + void SetWORLDVERTEXTRANSITION( bool i ) + { + m_nWORLDVERTEXTRANSITION = i ? 1 : 0; +#ifdef _DEBUG + m_bWORLDVERTEXTRANSITION = true; +#endif + } +private: + int m_nVERTEXCOLOR; +#ifdef _DEBUG + bool m_bVERTEXCOLOR; +#endif +public: + void SetVERTEXCOLOR( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nVERTEXCOLOR = i; +#ifdef _DEBUG + m_bVERTEXCOLOR = true; +#endif + } + void SetVERTEXCOLOR( bool i ) + { + m_nVERTEXCOLOR = i ? 1 : 0; +#ifdef _DEBUG + m_bVERTEXCOLOR = true; +#endif + } +public: + lightmappedgeneric_flashlight_vs11_Static_Index( ) + { +#ifdef _DEBUG + m_bNORMALMAP = false; +#endif // _DEBUG + m_nNORMALMAP = 0; +#ifdef _DEBUG + m_bWORLDVERTEXTRANSITION = false; +#endif // _DEBUG + m_nWORLDVERTEXTRANSITION = 0; +#ifdef _DEBUG + m_bVERTEXCOLOR = false; +#endif // _DEBUG + m_nVERTEXCOLOR = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bNORMALMAP && m_bWORLDVERTEXTRANSITION && m_bVERTEXCOLOR; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nNORMALMAP ) + ( 4 * m_nWORLDVERTEXTRANSITION ) + ( 8 * m_nVERTEXCOLOR ) + 0; + } +}; +#define shaderStaticTest_lightmappedgeneric_flashlight_vs11 vsh_forgot_to_set_static_NORMALMAP + vsh_forgot_to_set_static_WORLDVERTEXTRANSITION + vsh_forgot_to_set_static_VERTEXCOLOR + 0 +class lightmappedgeneric_flashlight_vs11_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + lightmappedgeneric_flashlight_vs11_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; +#define shaderDynamicTest_lightmappedgeneric_flashlight_vs11 vsh_forgot_to_set_dynamic_DOWATERFOG + 0 diff --git a/materialsystem/stdshaders/fxctmp9/lightmappedgeneric_flashlight_vs20.inc b/materialsystem/stdshaders/fxctmp9/lightmappedgeneric_flashlight_vs20.inc new file mode 100644 index 0000000..f472301 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/lightmappedgeneric_flashlight_vs20.inc @@ -0,0 +1,162 @@ +#include "shaderlib/cshader.h" +class lightmappedgeneric_flashlight_vs20_Static_Index +{ +private: + int m_nNORMALMAP; +#ifdef _DEBUG + bool m_bNORMALMAP; +#endif +public: + void SetNORMALMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nNORMALMAP = i; +#ifdef _DEBUG + m_bNORMALMAP = true; +#endif + } + void SetNORMALMAP( bool i ) + { + m_nNORMALMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bNORMALMAP = true; +#endif + } +private: + int m_nWORLDVERTEXTRANSITION; +#ifdef _DEBUG + bool m_bWORLDVERTEXTRANSITION; +#endif +public: + void SetWORLDVERTEXTRANSITION( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nWORLDVERTEXTRANSITION = i; +#ifdef _DEBUG + m_bWORLDVERTEXTRANSITION = true; +#endif + } + void SetWORLDVERTEXTRANSITION( bool i ) + { + m_nWORLDVERTEXTRANSITION = i ? 1 : 0; +#ifdef _DEBUG + m_bWORLDVERTEXTRANSITION = true; +#endif + } +private: + int m_nSEAMLESS; +#ifdef _DEBUG + bool m_bSEAMLESS; +#endif +public: + void SetSEAMLESS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSEAMLESS = i; +#ifdef _DEBUG + m_bSEAMLESS = true; +#endif + } + void SetSEAMLESS( bool i ) + { + m_nSEAMLESS = i ? 1 : 0; +#ifdef _DEBUG + m_bSEAMLESS = true; +#endif + } +private: + int m_nDETAIL; +#ifdef _DEBUG + bool m_bDETAIL; +#endif +public: + void SetDETAIL( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDETAIL = i; +#ifdef _DEBUG + m_bDETAIL = true; +#endif + } + void SetDETAIL( bool i ) + { + m_nDETAIL = i ? 1 : 0; +#ifdef _DEBUG + m_bDETAIL = true; +#endif + } +public: + lightmappedgeneric_flashlight_vs20_Static_Index( ) + { +#ifdef _DEBUG + m_bNORMALMAP = false; +#endif // _DEBUG + m_nNORMALMAP = 0; +#ifdef _DEBUG + m_bWORLDVERTEXTRANSITION = false; +#endif // _DEBUG + m_nWORLDVERTEXTRANSITION = 0; +#ifdef _DEBUG + m_bSEAMLESS = false; +#endif // _DEBUG + m_nSEAMLESS = 0; +#ifdef _DEBUG + m_bDETAIL = false; +#endif // _DEBUG + m_nDETAIL = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bNORMALMAP && m_bWORLDVERTEXTRANSITION && m_bSEAMLESS && m_bDETAIL; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nNORMALMAP ) + ( 4 * m_nWORLDVERTEXTRANSITION ) + ( 8 * m_nSEAMLESS ) + ( 16 * m_nDETAIL ) + 0; + } +}; +#define shaderStaticTest_lightmappedgeneric_flashlight_vs20 vsh_forgot_to_set_static_NORMALMAP + vsh_forgot_to_set_static_WORLDVERTEXTRANSITION + vsh_forgot_to_set_static_SEAMLESS + vsh_forgot_to_set_static_DETAIL + 0 +class lightmappedgeneric_flashlight_vs20_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + lightmappedgeneric_flashlight_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; +#define shaderDynamicTest_lightmappedgeneric_flashlight_vs20 vsh_forgot_to_set_dynamic_DOWATERFOG + 0 diff --git a/materialsystem/stdshaders/fxctmp9/lightmappedgeneric_lightingonly_overbright2_ps11.inc b/materialsystem/stdshaders/fxctmp9/lightmappedgeneric_lightingonly_overbright2_ps11.inc new file mode 100644 index 0000000..c8b345b --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/lightmappedgeneric_lightingonly_overbright2_ps11.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class lightmappedgeneric_lightingonly_overbright2_ps11_Static_Index +{ +public: + lightmappedgeneric_lightingonly_overbright2_ps11_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_lightmappedgeneric_lightingonly_overbright2_ps11 0 +class lightmappedgeneric_lightingonly_overbright2_ps11_Dynamic_Index +{ +public: + lightmappedgeneric_lightingonly_overbright2_ps11_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_lightmappedgeneric_lightingonly_overbright2_ps11 0 diff --git a/materialsystem/stdshaders/fxctmp9/lightmappedgeneric_lightingonly_vs11.inc b/materialsystem/stdshaders/fxctmp9/lightmappedgeneric_lightingonly_vs11.inc new file mode 100644 index 0000000..c4b302f --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/lightmappedgeneric_lightingonly_vs11.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class lightmappedgeneric_lightingonly_vs11_Static_Index +{ +public: + lightmappedgeneric_lightingonly_vs11_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_lightmappedgeneric_lightingonly_vs11 0 +class lightmappedgeneric_lightingonly_vs11_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + lightmappedgeneric_lightingonly_vs11_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; +#define shaderDynamicTest_lightmappedgeneric_lightingonly_vs11 vsh_forgot_to_set_dynamic_DOWATERFOG + 0 diff --git a/materialsystem/stdshaders/fxctmp9/lightmappedgeneric_ps20.inc b/materialsystem/stdshaders/fxctmp9/lightmappedgeneric_ps20.inc new file mode 100644 index 0000000..d4f49c9 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/lightmappedgeneric_ps20.inc @@ -0,0 +1,712 @@ +#include "shaderlib/cshader.h" +class lightmappedgeneric_ps20_Static_Index +{ +private: + int m_nMASKEDBLENDING; +#ifdef _DEBUG + bool m_bMASKEDBLENDING; +#endif +public: + void SetMASKEDBLENDING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nMASKEDBLENDING = i; +#ifdef _DEBUG + m_bMASKEDBLENDING = true; +#endif + } + void SetMASKEDBLENDING( bool i ) + { + m_nMASKEDBLENDING = i ? 1 : 0; +#ifdef _DEBUG + m_bMASKEDBLENDING = true; +#endif + } +private: + int m_nBASETEXTURE2; +#ifdef _DEBUG + bool m_bBASETEXTURE2; +#endif +public: + void SetBASETEXTURE2( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBASETEXTURE2 = i; +#ifdef _DEBUG + m_bBASETEXTURE2 = true; +#endif + } + void SetBASETEXTURE2( bool i ) + { + m_nBASETEXTURE2 = i ? 1 : 0; +#ifdef _DEBUG + m_bBASETEXTURE2 = true; +#endif + } +private: + int m_nDETAILTEXTURE; +#ifdef _DEBUG + bool m_bDETAILTEXTURE; +#endif +public: + void SetDETAILTEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDETAILTEXTURE = i; +#ifdef _DEBUG + m_bDETAILTEXTURE = true; +#endif + } + void SetDETAILTEXTURE( bool i ) + { + m_nDETAILTEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bDETAILTEXTURE = true; +#endif + } +private: + int m_nBUMPMAP; +#ifdef _DEBUG + bool m_bBUMPMAP; +#endif +public: + void SetBUMPMAP( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nBUMPMAP = i; +#ifdef _DEBUG + m_bBUMPMAP = true; +#endif + } + void SetBUMPMAP( bool i ) + { + m_nBUMPMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bBUMPMAP = true; +#endif + } +private: + int m_nBUMPMAP2; +#ifdef _DEBUG + bool m_bBUMPMAP2; +#endif +public: + void SetBUMPMAP2( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBUMPMAP2 = i; +#ifdef _DEBUG + m_bBUMPMAP2 = true; +#endif + } + void SetBUMPMAP2( bool i ) + { + m_nBUMPMAP2 = i ? 1 : 0; +#ifdef _DEBUG + m_bBUMPMAP2 = true; +#endif + } +private: + int m_nCUBEMAP; +#ifdef _DEBUG + bool m_bCUBEMAP; +#endif +public: + void SetCUBEMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCUBEMAP = i; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } + void SetCUBEMAP( bool i ) + { + m_nCUBEMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } +private: + int m_nENVMAPMASK; +#ifdef _DEBUG + bool m_bENVMAPMASK; +#endif +public: + void SetENVMAPMASK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nENVMAPMASK = i; +#ifdef _DEBUG + m_bENVMAPMASK = true; +#endif + } + void SetENVMAPMASK( bool i ) + { + m_nENVMAPMASK = i ? 1 : 0; +#ifdef _DEBUG + m_bENVMAPMASK = true; +#endif + } +private: + int m_nBASEALPHAENVMAPMASK; +#ifdef _DEBUG + bool m_bBASEALPHAENVMAPMASK; +#endif +public: + void SetBASEALPHAENVMAPMASK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBASEALPHAENVMAPMASK = i; +#ifdef _DEBUG + m_bBASEALPHAENVMAPMASK = true; +#endif + } + void SetBASEALPHAENVMAPMASK( bool i ) + { + m_nBASEALPHAENVMAPMASK = i ? 1 : 0; +#ifdef _DEBUG + m_bBASEALPHAENVMAPMASK = true; +#endif + } +private: + int m_nSELFILLUM; +#ifdef _DEBUG + bool m_bSELFILLUM; +#endif +public: + void SetSELFILLUM( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSELFILLUM = i; +#ifdef _DEBUG + m_bSELFILLUM = true; +#endif + } + void SetSELFILLUM( bool i ) + { + m_nSELFILLUM = i ? 1 : 0; +#ifdef _DEBUG + m_bSELFILLUM = true; +#endif + } +private: + int m_nNORMALMAPALPHAENVMAPMASK; +#ifdef _DEBUG + bool m_bNORMALMAPALPHAENVMAPMASK; +#endif +public: + void SetNORMALMAPALPHAENVMAPMASK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nNORMALMAPALPHAENVMAPMASK = i; +#ifdef _DEBUG + m_bNORMALMAPALPHAENVMAPMASK = true; +#endif + } + void SetNORMALMAPALPHAENVMAPMASK( bool i ) + { + m_nNORMALMAPALPHAENVMAPMASK = i ? 1 : 0; +#ifdef _DEBUG + m_bNORMALMAPALPHAENVMAPMASK = true; +#endif + } +private: + int m_nDIFFUSEBUMPMAP; +#ifdef _DEBUG + bool m_bDIFFUSEBUMPMAP; +#endif +public: + void SetDIFFUSEBUMPMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDIFFUSEBUMPMAP = i; +#ifdef _DEBUG + m_bDIFFUSEBUMPMAP = true; +#endif + } + void SetDIFFUSEBUMPMAP( bool i ) + { + m_nDIFFUSEBUMPMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bDIFFUSEBUMPMAP = true; +#endif + } +private: + int m_nBASETEXTURENOENVMAP; +#ifdef _DEBUG + bool m_bBASETEXTURENOENVMAP; +#endif +public: + void SetBASETEXTURENOENVMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBASETEXTURENOENVMAP = i; +#ifdef _DEBUG + m_bBASETEXTURENOENVMAP = true; +#endif + } + void SetBASETEXTURENOENVMAP( bool i ) + { + m_nBASETEXTURENOENVMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bBASETEXTURENOENVMAP = true; +#endif + } +private: + int m_nBASETEXTURE2NOENVMAP; +#ifdef _DEBUG + bool m_bBASETEXTURE2NOENVMAP; +#endif +public: + void SetBASETEXTURE2NOENVMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBASETEXTURE2NOENVMAP = i; +#ifdef _DEBUG + m_bBASETEXTURE2NOENVMAP = true; +#endif + } + void SetBASETEXTURE2NOENVMAP( bool i ) + { + m_nBASETEXTURE2NOENVMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bBASETEXTURE2NOENVMAP = true; +#endif + } +private: + int m_nWARPLIGHTING; +#ifdef _DEBUG + bool m_bWARPLIGHTING; +#endif +public: + void SetWARPLIGHTING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nWARPLIGHTING = i; +#ifdef _DEBUG + m_bWARPLIGHTING = true; +#endif + } + void SetWARPLIGHTING( bool i ) + { + m_nWARPLIGHTING = i ? 1 : 0; +#ifdef _DEBUG + m_bWARPLIGHTING = true; +#endif + } +private: + int m_nFANCY_BLENDING; +#ifdef _DEBUG + bool m_bFANCY_BLENDING; +#endif +public: + void SetFANCY_BLENDING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFANCY_BLENDING = i; +#ifdef _DEBUG + m_bFANCY_BLENDING = true; +#endif + } + void SetFANCY_BLENDING( bool i ) + { + m_nFANCY_BLENDING = i ? 1 : 0; +#ifdef _DEBUG + m_bFANCY_BLENDING = true; +#endif + } +private: + int m_nSEAMLESS; +#ifdef _DEBUG + bool m_bSEAMLESS; +#endif +public: + void SetSEAMLESS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSEAMLESS = i; +#ifdef _DEBUG + m_bSEAMLESS = true; +#endif + } + void SetSEAMLESS( bool i ) + { + m_nSEAMLESS = i ? 1 : 0; +#ifdef _DEBUG + m_bSEAMLESS = true; +#endif + } +private: + int m_nOUTLINE; +#ifdef _DEBUG + bool m_bOUTLINE; +#endif +public: + void SetOUTLINE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nOUTLINE = i; +#ifdef _DEBUG + m_bOUTLINE = true; +#endif + } + void SetOUTLINE( bool i ) + { + m_nOUTLINE = i ? 1 : 0; +#ifdef _DEBUG + m_bOUTLINE = true; +#endif + } +private: + int m_nSOFTEDGES; +#ifdef _DEBUG + bool m_bSOFTEDGES; +#endif +public: + void SetSOFTEDGES( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSOFTEDGES = i; +#ifdef _DEBUG + m_bSOFTEDGES = true; +#endif + } + void SetSOFTEDGES( bool i ) + { + m_nSOFTEDGES = i ? 1 : 0; +#ifdef _DEBUG + m_bSOFTEDGES = true; +#endif + } +private: + int m_nBUMPMASK; +#ifdef _DEBUG + bool m_bBUMPMASK; +#endif +public: + void SetBUMPMASK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBUMPMASK = i; +#ifdef _DEBUG + m_bBUMPMASK = true; +#endif + } + void SetBUMPMASK( bool i ) + { + m_nBUMPMASK = i ? 1 : 0; +#ifdef _DEBUG + m_bBUMPMASK = true; +#endif + } +private: + int m_nNORMAL_DECODE_MODE; +#ifdef _DEBUG + bool m_bNORMAL_DECODE_MODE; +#endif +public: + void SetNORMAL_DECODE_MODE( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nNORMAL_DECODE_MODE = i; +#ifdef _DEBUG + m_bNORMAL_DECODE_MODE = true; +#endif + } + void SetNORMAL_DECODE_MODE( bool i ) + { + m_nNORMAL_DECODE_MODE = i ? 1 : 0; +#ifdef _DEBUG + m_bNORMAL_DECODE_MODE = true; +#endif + } +private: + int m_nNORMALMASK_DECODE_MODE; +#ifdef _DEBUG + bool m_bNORMALMASK_DECODE_MODE; +#endif +public: + void SetNORMALMASK_DECODE_MODE( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nNORMALMASK_DECODE_MODE = i; +#ifdef _DEBUG + m_bNORMALMASK_DECODE_MODE = true; +#endif + } + void SetNORMALMASK_DECODE_MODE( bool i ) + { + m_nNORMALMASK_DECODE_MODE = i ? 1 : 0; +#ifdef _DEBUG + m_bNORMALMASK_DECODE_MODE = true; +#endif + } +private: + int m_nDETAIL_BLEND_MODE; +#ifdef _DEBUG + bool m_bDETAIL_BLEND_MODE; +#endif +public: + void SetDETAIL_BLEND_MODE( int i ) + { + Assert( i >= 0 && i <= 11 ); + m_nDETAIL_BLEND_MODE = i; +#ifdef _DEBUG + m_bDETAIL_BLEND_MODE = true; +#endif + } + void SetDETAIL_BLEND_MODE( bool i ) + { + m_nDETAIL_BLEND_MODE = i ? 1 : 0; +#ifdef _DEBUG + m_bDETAIL_BLEND_MODE = true; +#endif + } +public: + lightmappedgeneric_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bMASKEDBLENDING = false; +#endif // _DEBUG + m_nMASKEDBLENDING = 0; +#ifdef _DEBUG + m_bBASETEXTURE2 = false; +#endif // _DEBUG + m_nBASETEXTURE2 = 0; +#ifdef _DEBUG + m_bDETAILTEXTURE = false; +#endif // _DEBUG + m_nDETAILTEXTURE = 0; +#ifdef _DEBUG + m_bBUMPMAP = false; +#endif // _DEBUG + m_nBUMPMAP = 0; +#ifdef _DEBUG + m_bBUMPMAP2 = false; +#endif // _DEBUG + m_nBUMPMAP2 = 0; +#ifdef _DEBUG + m_bCUBEMAP = false; +#endif // _DEBUG + m_nCUBEMAP = 0; +#ifdef _DEBUG + m_bENVMAPMASK = false; +#endif // _DEBUG + m_nENVMAPMASK = 0; +#ifdef _DEBUG + m_bBASEALPHAENVMAPMASK = false; +#endif // _DEBUG + m_nBASEALPHAENVMAPMASK = 0; +#ifdef _DEBUG + m_bSELFILLUM = false; +#endif // _DEBUG + m_nSELFILLUM = 0; +#ifdef _DEBUG + m_bNORMALMAPALPHAENVMAPMASK = false; +#endif // _DEBUG + m_nNORMALMAPALPHAENVMAPMASK = 0; +#ifdef _DEBUG + m_bDIFFUSEBUMPMAP = false; +#endif // _DEBUG + m_nDIFFUSEBUMPMAP = 0; +#ifdef _DEBUG + m_bBASETEXTURENOENVMAP = false; +#endif // _DEBUG + m_nBASETEXTURENOENVMAP = 0; +#ifdef _DEBUG + m_bBASETEXTURE2NOENVMAP = false; +#endif // _DEBUG + m_nBASETEXTURE2NOENVMAP = 0; +#ifdef _DEBUG + m_bWARPLIGHTING = false; +#endif // _DEBUG + m_nWARPLIGHTING = 0; +#ifdef _DEBUG + m_bFANCY_BLENDING = false; +#endif // _DEBUG + m_nFANCY_BLENDING = 0; +#ifdef _DEBUG + m_bSEAMLESS = false; +#endif // _DEBUG + m_nSEAMLESS = 0; +#ifdef _DEBUG + m_bOUTLINE = false; +#endif // _DEBUG + m_nOUTLINE = 0; +#ifdef _DEBUG + m_bSOFTEDGES = false; +#endif // _DEBUG + m_nSOFTEDGES = 0; +#ifdef _DEBUG + m_bBUMPMASK = false; +#endif // _DEBUG + m_nBUMPMASK = 0; +#ifdef _DEBUG + m_bNORMAL_DECODE_MODE = false; +#endif // _DEBUG + m_nNORMAL_DECODE_MODE = 0; +#ifdef _DEBUG + m_bNORMALMASK_DECODE_MODE = false; +#endif // _DEBUG + m_nNORMALMASK_DECODE_MODE = 0; +#ifdef _DEBUG + m_bDETAIL_BLEND_MODE = false; +#endif // _DEBUG + m_nDETAIL_BLEND_MODE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bMASKEDBLENDING && m_bBASETEXTURE2 && m_bDETAILTEXTURE && m_bBUMPMAP && m_bBUMPMAP2 && m_bCUBEMAP && m_bENVMAPMASK && m_bBASEALPHAENVMAPMASK && m_bSELFILLUM && m_bNORMALMAPALPHAENVMAPMASK && m_bDIFFUSEBUMPMAP && m_bBASETEXTURENOENVMAP && m_bBASETEXTURE2NOENVMAP && m_bWARPLIGHTING && m_bFANCY_BLENDING && m_bSEAMLESS && m_bOUTLINE && m_bSOFTEDGES && m_bBUMPMASK && m_bNORMAL_DECODE_MODE && m_bNORMALMASK_DECODE_MODE && m_bDETAIL_BLEND_MODE; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 48 * m_nMASKEDBLENDING ) + ( 96 * m_nBASETEXTURE2 ) + ( 192 * m_nDETAILTEXTURE ) + ( 384 * m_nBUMPMAP ) + ( 1152 * m_nBUMPMAP2 ) + ( 2304 * m_nCUBEMAP ) + ( 4608 * m_nENVMAPMASK ) + ( 9216 * m_nBASEALPHAENVMAPMASK ) + ( 18432 * m_nSELFILLUM ) + ( 36864 * m_nNORMALMAPALPHAENVMAPMASK ) + ( 73728 * m_nDIFFUSEBUMPMAP ) + ( 147456 * m_nBASETEXTURENOENVMAP ) + ( 294912 * m_nBASETEXTURE2NOENVMAP ) + ( 589824 * m_nWARPLIGHTING ) + ( 1179648 * m_nFANCY_BLENDING ) + ( 2359296 * m_nSEAMLESS ) + ( 4718592 * m_nOUTLINE ) + ( 9437184 * m_nSOFTEDGES ) + ( 18874368 * m_nBUMPMASK ) + ( 37748736 * m_nNORMAL_DECODE_MODE ) + ( 37748736 * m_nNORMALMASK_DECODE_MODE ) + ( 37748736 * m_nDETAIL_BLEND_MODE ) + 0; + } +}; +#define shaderStaticTest_lightmappedgeneric_ps20 psh_forgot_to_set_static_MASKEDBLENDING + psh_forgot_to_set_static_BASETEXTURE2 + psh_forgot_to_set_static_DETAILTEXTURE + psh_forgot_to_set_static_BUMPMAP + psh_forgot_to_set_static_BUMPMAP2 + psh_forgot_to_set_static_CUBEMAP + psh_forgot_to_set_static_ENVMAPMASK + psh_forgot_to_set_static_BASEALPHAENVMAPMASK + psh_forgot_to_set_static_SELFILLUM + psh_forgot_to_set_static_NORMALMAPALPHAENVMAPMASK + psh_forgot_to_set_static_DIFFUSEBUMPMAP + psh_forgot_to_set_static_BASETEXTURENOENVMAP + psh_forgot_to_set_static_BASETEXTURE2NOENVMAP + psh_forgot_to_set_static_WARPLIGHTING + psh_forgot_to_set_static_FANCY_BLENDING + psh_forgot_to_set_static_SEAMLESS + psh_forgot_to_set_static_OUTLINE + psh_forgot_to_set_static_SOFTEDGES + psh_forgot_to_set_static_BUMPMASK + psh_forgot_to_set_static_NORMAL_DECODE_MODE + psh_forgot_to_set_static_NORMALMASK_DECODE_MODE + psh_forgot_to_set_static_DETAIL_BLEND_MODE + 0 +class lightmappedgeneric_ps20_Dynamic_Index +{ +private: + int m_nFASTPATHENVMAPCONTRAST; +#ifdef _DEBUG + bool m_bFASTPATHENVMAPCONTRAST; +#endif +public: + void SetFASTPATHENVMAPCONTRAST( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFASTPATHENVMAPCONTRAST = i; +#ifdef _DEBUG + m_bFASTPATHENVMAPCONTRAST = true; +#endif + } + void SetFASTPATHENVMAPCONTRAST( bool i ) + { + m_nFASTPATHENVMAPCONTRAST = i ? 1 : 0; +#ifdef _DEBUG + m_bFASTPATHENVMAPCONTRAST = true; +#endif + } +private: + int m_nFASTPATH; +#ifdef _DEBUG + bool m_bFASTPATH; +#endif +public: + void SetFASTPATH( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFASTPATH = i; +#ifdef _DEBUG + m_bFASTPATH = true; +#endif + } + void SetFASTPATH( bool i ) + { + m_nFASTPATH = i ? 1 : 0; +#ifdef _DEBUG + m_bFASTPATH = true; +#endif + } +private: + int m_nWRITEWATERFOGTODESTALPHA; +#ifdef _DEBUG + bool m_bWRITEWATERFOGTODESTALPHA; +#endif +public: + void SetWRITEWATERFOGTODESTALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nWRITEWATERFOGTODESTALPHA = i; +#ifdef _DEBUG + m_bWRITEWATERFOGTODESTALPHA = true; +#endif + } + void SetWRITEWATERFOGTODESTALPHA( bool i ) + { + m_nWRITEWATERFOGTODESTALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bWRITEWATERFOGTODESTALPHA = true; +#endif + } +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +private: + int m_nLIGHTING_PREVIEW; +#ifdef _DEBUG + bool m_bLIGHTING_PREVIEW; +#endif +public: + void SetLIGHTING_PREVIEW( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nLIGHTING_PREVIEW = i; +#ifdef _DEBUG + m_bLIGHTING_PREVIEW = true; +#endif + } + void SetLIGHTING_PREVIEW( bool i ) + { + m_nLIGHTING_PREVIEW = i ? 1 : 0; +#ifdef _DEBUG + m_bLIGHTING_PREVIEW = true; +#endif + } +public: + lightmappedgeneric_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bFASTPATHENVMAPCONTRAST = false; +#endif // _DEBUG + m_nFASTPATHENVMAPCONTRAST = 0; +#ifdef _DEBUG + m_bFASTPATH = false; +#endif // _DEBUG + m_nFASTPATH = 0; +#ifdef _DEBUG + m_bWRITEWATERFOGTODESTALPHA = false; +#endif // _DEBUG + m_nWRITEWATERFOGTODESTALPHA = 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; +#ifdef _DEBUG + m_bLIGHTING_PREVIEW = false; +#endif // _DEBUG + m_nLIGHTING_PREVIEW = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bFASTPATHENVMAPCONTRAST && m_bFASTPATH && m_bWRITEWATERFOGTODESTALPHA && m_bPIXELFOGTYPE && m_bLIGHTING_PREVIEW; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nFASTPATHENVMAPCONTRAST ) + ( 2 * m_nFASTPATH ) + ( 4 * m_nWRITEWATERFOGTODESTALPHA ) + ( 8 * m_nPIXELFOGTYPE ) + ( 16 * m_nLIGHTING_PREVIEW ) + 0; + } +}; +#define shaderDynamicTest_lightmappedgeneric_ps20 psh_forgot_to_set_dynamic_FASTPATHENVMAPCONTRAST + psh_forgot_to_set_dynamic_FASTPATH + psh_forgot_to_set_dynamic_WRITEWATERFOGTODESTALPHA + psh_forgot_to_set_dynamic_PIXELFOGTYPE + psh_forgot_to_set_dynamic_LIGHTING_PREVIEW + 0 diff --git a/materialsystem/stdshaders/fxctmp9/lightmappedgeneric_ps20b.inc b/materialsystem/stdshaders/fxctmp9/lightmappedgeneric_ps20b.inc new file mode 100644 index 0000000..7ecfcbd --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/lightmappedgeneric_ps20b.inc @@ -0,0 +1,762 @@ +#include "shaderlib/cshader.h" +class lightmappedgeneric_ps20b_Static_Index +{ +private: + int m_nMASKEDBLENDING; +#ifdef _DEBUG + bool m_bMASKEDBLENDING; +#endif +public: + void SetMASKEDBLENDING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nMASKEDBLENDING = i; +#ifdef _DEBUG + m_bMASKEDBLENDING = true; +#endif + } + void SetMASKEDBLENDING( bool i ) + { + m_nMASKEDBLENDING = i ? 1 : 0; +#ifdef _DEBUG + m_bMASKEDBLENDING = true; +#endif + } +private: + int m_nBASETEXTURE2; +#ifdef _DEBUG + bool m_bBASETEXTURE2; +#endif +public: + void SetBASETEXTURE2( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBASETEXTURE2 = i; +#ifdef _DEBUG + m_bBASETEXTURE2 = true; +#endif + } + void SetBASETEXTURE2( bool i ) + { + m_nBASETEXTURE2 = i ? 1 : 0; +#ifdef _DEBUG + m_bBASETEXTURE2 = true; +#endif + } +private: + int m_nDETAILTEXTURE; +#ifdef _DEBUG + bool m_bDETAILTEXTURE; +#endif +public: + void SetDETAILTEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDETAILTEXTURE = i; +#ifdef _DEBUG + m_bDETAILTEXTURE = true; +#endif + } + void SetDETAILTEXTURE( bool i ) + { + m_nDETAILTEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bDETAILTEXTURE = true; +#endif + } +private: + int m_nBUMPMAP; +#ifdef _DEBUG + bool m_bBUMPMAP; +#endif +public: + void SetBUMPMAP( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nBUMPMAP = i; +#ifdef _DEBUG + m_bBUMPMAP = true; +#endif + } + void SetBUMPMAP( bool i ) + { + m_nBUMPMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bBUMPMAP = true; +#endif + } +private: + int m_nBUMPMAP2; +#ifdef _DEBUG + bool m_bBUMPMAP2; +#endif +public: + void SetBUMPMAP2( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBUMPMAP2 = i; +#ifdef _DEBUG + m_bBUMPMAP2 = true; +#endif + } + void SetBUMPMAP2( bool i ) + { + m_nBUMPMAP2 = i ? 1 : 0; +#ifdef _DEBUG + m_bBUMPMAP2 = true; +#endif + } +private: + int m_nCUBEMAP; +#ifdef _DEBUG + bool m_bCUBEMAP; +#endif +public: + void SetCUBEMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCUBEMAP = i; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } + void SetCUBEMAP( bool i ) + { + m_nCUBEMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } +private: + int m_nENVMAPMASK; +#ifdef _DEBUG + bool m_bENVMAPMASK; +#endif +public: + void SetENVMAPMASK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nENVMAPMASK = i; +#ifdef _DEBUG + m_bENVMAPMASK = true; +#endif + } + void SetENVMAPMASK( bool i ) + { + m_nENVMAPMASK = i ? 1 : 0; +#ifdef _DEBUG + m_bENVMAPMASK = true; +#endif + } +private: + int m_nBASEALPHAENVMAPMASK; +#ifdef _DEBUG + bool m_bBASEALPHAENVMAPMASK; +#endif +public: + void SetBASEALPHAENVMAPMASK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBASEALPHAENVMAPMASK = i; +#ifdef _DEBUG + m_bBASEALPHAENVMAPMASK = true; +#endif + } + void SetBASEALPHAENVMAPMASK( bool i ) + { + m_nBASEALPHAENVMAPMASK = i ? 1 : 0; +#ifdef _DEBUG + m_bBASEALPHAENVMAPMASK = true; +#endif + } +private: + int m_nSELFILLUM; +#ifdef _DEBUG + bool m_bSELFILLUM; +#endif +public: + void SetSELFILLUM( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSELFILLUM = i; +#ifdef _DEBUG + m_bSELFILLUM = true; +#endif + } + void SetSELFILLUM( bool i ) + { + m_nSELFILLUM = i ? 1 : 0; +#ifdef _DEBUG + m_bSELFILLUM = true; +#endif + } +private: + int m_nNORMALMAPALPHAENVMAPMASK; +#ifdef _DEBUG + bool m_bNORMALMAPALPHAENVMAPMASK; +#endif +public: + void SetNORMALMAPALPHAENVMAPMASK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nNORMALMAPALPHAENVMAPMASK = i; +#ifdef _DEBUG + m_bNORMALMAPALPHAENVMAPMASK = true; +#endif + } + void SetNORMALMAPALPHAENVMAPMASK( bool i ) + { + m_nNORMALMAPALPHAENVMAPMASK = i ? 1 : 0; +#ifdef _DEBUG + m_bNORMALMAPALPHAENVMAPMASK = true; +#endif + } +private: + int m_nDIFFUSEBUMPMAP; +#ifdef _DEBUG + bool m_bDIFFUSEBUMPMAP; +#endif +public: + void SetDIFFUSEBUMPMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDIFFUSEBUMPMAP = i; +#ifdef _DEBUG + m_bDIFFUSEBUMPMAP = true; +#endif + } + void SetDIFFUSEBUMPMAP( bool i ) + { + m_nDIFFUSEBUMPMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bDIFFUSEBUMPMAP = true; +#endif + } +private: + int m_nBASETEXTURENOENVMAP; +#ifdef _DEBUG + bool m_bBASETEXTURENOENVMAP; +#endif +public: + void SetBASETEXTURENOENVMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBASETEXTURENOENVMAP = i; +#ifdef _DEBUG + m_bBASETEXTURENOENVMAP = true; +#endif + } + void SetBASETEXTURENOENVMAP( bool i ) + { + m_nBASETEXTURENOENVMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bBASETEXTURENOENVMAP = true; +#endif + } +private: + int m_nBASETEXTURE2NOENVMAP; +#ifdef _DEBUG + bool m_bBASETEXTURE2NOENVMAP; +#endif +public: + void SetBASETEXTURE2NOENVMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBASETEXTURE2NOENVMAP = i; +#ifdef _DEBUG + m_bBASETEXTURE2NOENVMAP = true; +#endif + } + void SetBASETEXTURE2NOENVMAP( bool i ) + { + m_nBASETEXTURE2NOENVMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bBASETEXTURE2NOENVMAP = true; +#endif + } +private: + int m_nWARPLIGHTING; +#ifdef _DEBUG + bool m_bWARPLIGHTING; +#endif +public: + void SetWARPLIGHTING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nWARPLIGHTING = i; +#ifdef _DEBUG + m_bWARPLIGHTING = true; +#endif + } + void SetWARPLIGHTING( bool i ) + { + m_nWARPLIGHTING = i ? 1 : 0; +#ifdef _DEBUG + m_bWARPLIGHTING = true; +#endif + } +private: + int m_nFANCY_BLENDING; +#ifdef _DEBUG + bool m_bFANCY_BLENDING; +#endif +public: + void SetFANCY_BLENDING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFANCY_BLENDING = i; +#ifdef _DEBUG + m_bFANCY_BLENDING = true; +#endif + } + void SetFANCY_BLENDING( bool i ) + { + m_nFANCY_BLENDING = i ? 1 : 0; +#ifdef _DEBUG + m_bFANCY_BLENDING = true; +#endif + } +private: + int m_nRELIEF_MAPPING; +#ifdef _DEBUG + bool m_bRELIEF_MAPPING; +#endif +public: + void SetRELIEF_MAPPING( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nRELIEF_MAPPING = i; +#ifdef _DEBUG + m_bRELIEF_MAPPING = true; +#endif + } + void SetRELIEF_MAPPING( bool i ) + { + m_nRELIEF_MAPPING = i ? 1 : 0; +#ifdef _DEBUG + m_bRELIEF_MAPPING = true; +#endif + } +private: + int m_nSEAMLESS; +#ifdef _DEBUG + bool m_bSEAMLESS; +#endif +public: + void SetSEAMLESS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSEAMLESS = i; +#ifdef _DEBUG + m_bSEAMLESS = true; +#endif + } + void SetSEAMLESS( bool i ) + { + m_nSEAMLESS = i ? 1 : 0; +#ifdef _DEBUG + m_bSEAMLESS = true; +#endif + } +private: + int m_nOUTLINE; +#ifdef _DEBUG + bool m_bOUTLINE; +#endif +public: + void SetOUTLINE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nOUTLINE = i; +#ifdef _DEBUG + m_bOUTLINE = true; +#endif + } + void SetOUTLINE( bool i ) + { + m_nOUTLINE = i ? 1 : 0; +#ifdef _DEBUG + m_bOUTLINE = true; +#endif + } +private: + int m_nSOFTEDGES; +#ifdef _DEBUG + bool m_bSOFTEDGES; +#endif +public: + void SetSOFTEDGES( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSOFTEDGES = i; +#ifdef _DEBUG + m_bSOFTEDGES = true; +#endif + } + void SetSOFTEDGES( bool i ) + { + m_nSOFTEDGES = i ? 1 : 0; +#ifdef _DEBUG + m_bSOFTEDGES = true; +#endif + } +private: + int m_nBUMPMASK; +#ifdef _DEBUG + bool m_bBUMPMASK; +#endif +public: + void SetBUMPMASK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBUMPMASK = i; +#ifdef _DEBUG + m_bBUMPMASK = true; +#endif + } + void SetBUMPMASK( bool i ) + { + m_nBUMPMASK = i ? 1 : 0; +#ifdef _DEBUG + m_bBUMPMASK = true; +#endif + } +private: + int m_nNORMAL_DECODE_MODE; +#ifdef _DEBUG + bool m_bNORMAL_DECODE_MODE; +#endif +public: + void SetNORMAL_DECODE_MODE( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nNORMAL_DECODE_MODE = i; +#ifdef _DEBUG + m_bNORMAL_DECODE_MODE = true; +#endif + } + void SetNORMAL_DECODE_MODE( bool i ) + { + m_nNORMAL_DECODE_MODE = i ? 1 : 0; +#ifdef _DEBUG + m_bNORMAL_DECODE_MODE = true; +#endif + } +private: + int m_nNORMALMASK_DECODE_MODE; +#ifdef _DEBUG + bool m_bNORMALMASK_DECODE_MODE; +#endif +public: + void SetNORMALMASK_DECODE_MODE( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nNORMALMASK_DECODE_MODE = i; +#ifdef _DEBUG + m_bNORMALMASK_DECODE_MODE = true; +#endif + } + void SetNORMALMASK_DECODE_MODE( bool i ) + { + m_nNORMALMASK_DECODE_MODE = i ? 1 : 0; +#ifdef _DEBUG + m_bNORMALMASK_DECODE_MODE = true; +#endif + } +private: + int m_nDETAIL_BLEND_MODE; +#ifdef _DEBUG + bool m_bDETAIL_BLEND_MODE; +#endif +public: + void SetDETAIL_BLEND_MODE( int i ) + { + Assert( i >= 0 && i <= 11 ); + m_nDETAIL_BLEND_MODE = i; +#ifdef _DEBUG + m_bDETAIL_BLEND_MODE = true; +#endif + } + void SetDETAIL_BLEND_MODE( bool i ) + { + m_nDETAIL_BLEND_MODE = i ? 1 : 0; +#ifdef _DEBUG + m_bDETAIL_BLEND_MODE = true; +#endif + } +public: + lightmappedgeneric_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bMASKEDBLENDING = false; +#endif // _DEBUG + m_nMASKEDBLENDING = 0; +#ifdef _DEBUG + m_bBASETEXTURE2 = false; +#endif // _DEBUG + m_nBASETEXTURE2 = 0; +#ifdef _DEBUG + m_bDETAILTEXTURE = false; +#endif // _DEBUG + m_nDETAILTEXTURE = 0; +#ifdef _DEBUG + m_bBUMPMAP = false; +#endif // _DEBUG + m_nBUMPMAP = 0; +#ifdef _DEBUG + m_bBUMPMAP2 = false; +#endif // _DEBUG + m_nBUMPMAP2 = 0; +#ifdef _DEBUG + m_bCUBEMAP = false; +#endif // _DEBUG + m_nCUBEMAP = 0; +#ifdef _DEBUG + m_bENVMAPMASK = false; +#endif // _DEBUG + m_nENVMAPMASK = 0; +#ifdef _DEBUG + m_bBASEALPHAENVMAPMASK = false; +#endif // _DEBUG + m_nBASEALPHAENVMAPMASK = 0; +#ifdef _DEBUG + m_bSELFILLUM = false; +#endif // _DEBUG + m_nSELFILLUM = 0; +#ifdef _DEBUG + m_bNORMALMAPALPHAENVMAPMASK = false; +#endif // _DEBUG + m_nNORMALMAPALPHAENVMAPMASK = 0; +#ifdef _DEBUG + m_bDIFFUSEBUMPMAP = false; +#endif // _DEBUG + m_nDIFFUSEBUMPMAP = 0; +#ifdef _DEBUG + m_bBASETEXTURENOENVMAP = false; +#endif // _DEBUG + m_nBASETEXTURENOENVMAP = 0; +#ifdef _DEBUG + m_bBASETEXTURE2NOENVMAP = false; +#endif // _DEBUG + m_nBASETEXTURE2NOENVMAP = 0; +#ifdef _DEBUG + m_bWARPLIGHTING = false; +#endif // _DEBUG + m_nWARPLIGHTING = 0; +#ifdef _DEBUG + m_bFANCY_BLENDING = false; +#endif // _DEBUG + m_nFANCY_BLENDING = 0; +#ifdef _DEBUG + m_bRELIEF_MAPPING = false; +#endif // _DEBUG + m_nRELIEF_MAPPING = 0; +#ifdef _DEBUG + m_bSEAMLESS = false; +#endif // _DEBUG + m_nSEAMLESS = 0; +#ifdef _DEBUG + m_bOUTLINE = false; +#endif // _DEBUG + m_nOUTLINE = 0; +#ifdef _DEBUG + m_bSOFTEDGES = false; +#endif // _DEBUG + m_nSOFTEDGES = 0; +#ifdef _DEBUG + m_bBUMPMASK = false; +#endif // _DEBUG + m_nBUMPMASK = 0; +#ifdef _DEBUG + m_bNORMAL_DECODE_MODE = false; +#endif // _DEBUG + m_nNORMAL_DECODE_MODE = 0; +#ifdef _DEBUG + m_bNORMALMASK_DECODE_MODE = false; +#endif // _DEBUG + m_nNORMALMASK_DECODE_MODE = 0; +#ifdef _DEBUG + m_bDETAIL_BLEND_MODE = false; +#endif // _DEBUG + m_nDETAIL_BLEND_MODE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bMASKEDBLENDING && m_bBASETEXTURE2 && m_bDETAILTEXTURE && m_bBUMPMAP && m_bBUMPMAP2 && m_bCUBEMAP && m_bENVMAPMASK && m_bBASEALPHAENVMAPMASK && m_bSELFILLUM && m_bNORMALMAPALPHAENVMAPMASK && m_bDIFFUSEBUMPMAP && m_bBASETEXTURENOENVMAP && m_bBASETEXTURE2NOENVMAP && m_bWARPLIGHTING && m_bFANCY_BLENDING && m_bRELIEF_MAPPING && m_bSEAMLESS && m_bOUTLINE && m_bSOFTEDGES && m_bBUMPMASK && m_bNORMAL_DECODE_MODE && m_bNORMALMASK_DECODE_MODE && m_bDETAIL_BLEND_MODE; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 96 * m_nMASKEDBLENDING ) + ( 192 * m_nBASETEXTURE2 ) + ( 384 * m_nDETAILTEXTURE ) + ( 768 * m_nBUMPMAP ) + ( 2304 * m_nBUMPMAP2 ) + ( 4608 * m_nCUBEMAP ) + ( 9216 * m_nENVMAPMASK ) + ( 18432 * m_nBASEALPHAENVMAPMASK ) + ( 36864 * m_nSELFILLUM ) + ( 73728 * m_nNORMALMAPALPHAENVMAPMASK ) + ( 147456 * m_nDIFFUSEBUMPMAP ) + ( 294912 * m_nBASETEXTURENOENVMAP ) + ( 589824 * m_nBASETEXTURE2NOENVMAP ) + ( 1179648 * m_nWARPLIGHTING ) + ( 2359296 * m_nFANCY_BLENDING ) + ( 4718592 * m_nRELIEF_MAPPING ) + ( 4718592 * m_nSEAMLESS ) + ( 9437184 * m_nOUTLINE ) + ( 18874368 * m_nSOFTEDGES ) + ( 37748736 * m_nBUMPMASK ) + ( 75497472 * m_nNORMAL_DECODE_MODE ) + ( 75497472 * m_nNORMALMASK_DECODE_MODE ) + ( 75497472 * m_nDETAIL_BLEND_MODE ) + 0; + } +}; +#define shaderStaticTest_lightmappedgeneric_ps20b psh_forgot_to_set_static_MASKEDBLENDING + psh_forgot_to_set_static_BASETEXTURE2 + psh_forgot_to_set_static_DETAILTEXTURE + psh_forgot_to_set_static_BUMPMAP + psh_forgot_to_set_static_BUMPMAP2 + psh_forgot_to_set_static_CUBEMAP + psh_forgot_to_set_static_ENVMAPMASK + psh_forgot_to_set_static_BASEALPHAENVMAPMASK + psh_forgot_to_set_static_SELFILLUM + psh_forgot_to_set_static_NORMALMAPALPHAENVMAPMASK + psh_forgot_to_set_static_DIFFUSEBUMPMAP + psh_forgot_to_set_static_BASETEXTURENOENVMAP + psh_forgot_to_set_static_BASETEXTURE2NOENVMAP + psh_forgot_to_set_static_WARPLIGHTING + psh_forgot_to_set_static_FANCY_BLENDING + psh_forgot_to_set_static_RELIEF_MAPPING + psh_forgot_to_set_static_SEAMLESS + psh_forgot_to_set_static_OUTLINE + psh_forgot_to_set_static_SOFTEDGES + psh_forgot_to_set_static_BUMPMASK + psh_forgot_to_set_static_NORMAL_DECODE_MODE + psh_forgot_to_set_static_NORMALMASK_DECODE_MODE + psh_forgot_to_set_static_DETAIL_BLEND_MODE + 0 +class lightmappedgeneric_ps20b_Dynamic_Index +{ +private: + int m_nFASTPATHENVMAPCONTRAST; +#ifdef _DEBUG + bool m_bFASTPATHENVMAPCONTRAST; +#endif +public: + void SetFASTPATHENVMAPCONTRAST( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFASTPATHENVMAPCONTRAST = i; +#ifdef _DEBUG + m_bFASTPATHENVMAPCONTRAST = true; +#endif + } + void SetFASTPATHENVMAPCONTRAST( bool i ) + { + m_nFASTPATHENVMAPCONTRAST = i ? 1 : 0; +#ifdef _DEBUG + m_bFASTPATHENVMAPCONTRAST = true; +#endif + } +private: + int m_nFASTPATH; +#ifdef _DEBUG + bool m_bFASTPATH; +#endif +public: + void SetFASTPATH( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFASTPATH = i; +#ifdef _DEBUG + m_bFASTPATH = true; +#endif + } + void SetFASTPATH( bool i ) + { + m_nFASTPATH = i ? 1 : 0; +#ifdef _DEBUG + m_bFASTPATH = true; +#endif + } +private: + int m_nWRITEWATERFOGTODESTALPHA; +#ifdef _DEBUG + bool m_bWRITEWATERFOGTODESTALPHA; +#endif +public: + void SetWRITEWATERFOGTODESTALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nWRITEWATERFOGTODESTALPHA = i; +#ifdef _DEBUG + m_bWRITEWATERFOGTODESTALPHA = true; +#endif + } + void SetWRITEWATERFOGTODESTALPHA( bool i ) + { + m_nWRITEWATERFOGTODESTALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bWRITEWATERFOGTODESTALPHA = true; +#endif + } +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +private: + int m_nLIGHTING_PREVIEW; +#ifdef _DEBUG + bool m_bLIGHTING_PREVIEW; +#endif +public: + void SetLIGHTING_PREVIEW( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nLIGHTING_PREVIEW = i; +#ifdef _DEBUG + m_bLIGHTING_PREVIEW = true; +#endif + } + void SetLIGHTING_PREVIEW( bool i ) + { + m_nLIGHTING_PREVIEW = i ? 1 : 0; +#ifdef _DEBUG + m_bLIGHTING_PREVIEW = true; +#endif + } +private: + int m_nWRITE_DEPTH_TO_DESTALPHA; +#ifdef _DEBUG + bool m_bWRITE_DEPTH_TO_DESTALPHA; +#endif +public: + void SetWRITE_DEPTH_TO_DESTALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nWRITE_DEPTH_TO_DESTALPHA = i; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = true; +#endif + } + void SetWRITE_DEPTH_TO_DESTALPHA( bool i ) + { + m_nWRITE_DEPTH_TO_DESTALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = true; +#endif + } +public: + lightmappedgeneric_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bFASTPATHENVMAPCONTRAST = false; +#endif // _DEBUG + m_nFASTPATHENVMAPCONTRAST = 0; +#ifdef _DEBUG + m_bFASTPATH = false; +#endif // _DEBUG + m_nFASTPATH = 0; +#ifdef _DEBUG + m_bWRITEWATERFOGTODESTALPHA = false; +#endif // _DEBUG + m_nWRITEWATERFOGTODESTALPHA = 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; +#ifdef _DEBUG + m_bLIGHTING_PREVIEW = false; +#endif // _DEBUG + m_nLIGHTING_PREVIEW = 0; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = false; +#endif // _DEBUG + m_nWRITE_DEPTH_TO_DESTALPHA = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bFASTPATHENVMAPCONTRAST && m_bFASTPATH && m_bWRITEWATERFOGTODESTALPHA && m_bPIXELFOGTYPE && m_bLIGHTING_PREVIEW && m_bWRITE_DEPTH_TO_DESTALPHA; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nFASTPATHENVMAPCONTRAST ) + ( 2 * m_nFASTPATH ) + ( 4 * m_nWRITEWATERFOGTODESTALPHA ) + ( 8 * m_nPIXELFOGTYPE ) + ( 16 * m_nLIGHTING_PREVIEW ) + ( 48 * m_nWRITE_DEPTH_TO_DESTALPHA ) + 0; + } +}; +#define shaderDynamicTest_lightmappedgeneric_ps20b psh_forgot_to_set_dynamic_FASTPATHENVMAPCONTRAST + psh_forgot_to_set_dynamic_FASTPATH + psh_forgot_to_set_dynamic_WRITEWATERFOGTODESTALPHA + psh_forgot_to_set_dynamic_PIXELFOGTYPE + psh_forgot_to_set_dynamic_LIGHTING_PREVIEW + psh_forgot_to_set_dynamic_WRITE_DEPTH_TO_DESTALPHA + 0 diff --git a/materialsystem/stdshaders/fxctmp9/lightmappedgeneric_vs20.inc b/materialsystem/stdshaders/fxctmp9/lightmappedgeneric_vs20.inc new file mode 100644 index 0000000..0e118ca --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/lightmappedgeneric_vs20.inc @@ -0,0 +1,337 @@ +#include "shaderlib/cshader.h" +class lightmappedgeneric_vs20_Static_Index +{ +private: + int m_nENVMAP_MASK; +#ifdef _DEBUG + bool m_bENVMAP_MASK; +#endif +public: + void SetENVMAP_MASK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nENVMAP_MASK = i; +#ifdef _DEBUG + m_bENVMAP_MASK = true; +#endif + } + void SetENVMAP_MASK( bool i ) + { + m_nENVMAP_MASK = i ? 1 : 0; +#ifdef _DEBUG + m_bENVMAP_MASK = true; +#endif + } +private: + int m_nTANGENTSPACE; +#ifdef _DEBUG + bool m_bTANGENTSPACE; +#endif +public: + void SetTANGENTSPACE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nTANGENTSPACE = i; +#ifdef _DEBUG + m_bTANGENTSPACE = true; +#endif + } + void SetTANGENTSPACE( bool i ) + { + m_nTANGENTSPACE = i ? 1 : 0; +#ifdef _DEBUG + m_bTANGENTSPACE = true; +#endif + } +private: + int m_nBUMPMAP; +#ifdef _DEBUG + bool m_bBUMPMAP; +#endif +public: + void SetBUMPMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBUMPMAP = i; +#ifdef _DEBUG + m_bBUMPMAP = true; +#endif + } + void SetBUMPMAP( bool i ) + { + m_nBUMPMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bBUMPMAP = true; +#endif + } +private: + int m_nDIFFUSEBUMPMAP; +#ifdef _DEBUG + bool m_bDIFFUSEBUMPMAP; +#endif +public: + void SetDIFFUSEBUMPMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDIFFUSEBUMPMAP = i; +#ifdef _DEBUG + m_bDIFFUSEBUMPMAP = true; +#endif + } + void SetDIFFUSEBUMPMAP( bool i ) + { + m_nDIFFUSEBUMPMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bDIFFUSEBUMPMAP = true; +#endif + } +private: + int m_nVERTEXCOLOR; +#ifdef _DEBUG + bool m_bVERTEXCOLOR; +#endif +public: + void SetVERTEXCOLOR( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nVERTEXCOLOR = i; +#ifdef _DEBUG + m_bVERTEXCOLOR = true; +#endif + } + void SetVERTEXCOLOR( bool i ) + { + m_nVERTEXCOLOR = i ? 1 : 0; +#ifdef _DEBUG + m_bVERTEXCOLOR = true; +#endif + } +private: + int m_nVERTEXALPHATEXBLENDFACTOR; +#ifdef _DEBUG + bool m_bVERTEXALPHATEXBLENDFACTOR; +#endif +public: + void SetVERTEXALPHATEXBLENDFACTOR( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nVERTEXALPHATEXBLENDFACTOR = i; +#ifdef _DEBUG + m_bVERTEXALPHATEXBLENDFACTOR = true; +#endif + } + void SetVERTEXALPHATEXBLENDFACTOR( bool i ) + { + m_nVERTEXALPHATEXBLENDFACTOR = i ? 1 : 0; +#ifdef _DEBUG + m_bVERTEXALPHATEXBLENDFACTOR = true; +#endif + } +private: + int m_nRELIEF_MAPPING; +#ifdef _DEBUG + bool m_bRELIEF_MAPPING; +#endif +public: + void SetRELIEF_MAPPING( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nRELIEF_MAPPING = i; +#ifdef _DEBUG + m_bRELIEF_MAPPING = true; +#endif + } + void SetRELIEF_MAPPING( bool i ) + { + m_nRELIEF_MAPPING = i ? 1 : 0; +#ifdef _DEBUG + m_bRELIEF_MAPPING = true; +#endif + } +private: + int m_nSEAMLESS; +#ifdef _DEBUG + bool m_bSEAMLESS; +#endif +public: + void SetSEAMLESS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSEAMLESS = i; +#ifdef _DEBUG + m_bSEAMLESS = true; +#endif + } + void SetSEAMLESS( bool i ) + { + m_nSEAMLESS = i ? 1 : 0; +#ifdef _DEBUG + m_bSEAMLESS = true; +#endif + } +private: + int m_nBUMPMASK; +#ifdef _DEBUG + bool m_bBUMPMASK; +#endif +public: + void SetBUMPMASK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBUMPMASK = i; +#ifdef _DEBUG + m_bBUMPMASK = true; +#endif + } + void SetBUMPMASK( bool i ) + { + m_nBUMPMASK = i ? 1 : 0; +#ifdef _DEBUG + m_bBUMPMASK = true; +#endif + } +public: + lightmappedgeneric_vs20_Static_Index( ) + { +#ifdef _DEBUG + m_bENVMAP_MASK = false; +#endif // _DEBUG + m_nENVMAP_MASK = 0; +#ifdef _DEBUG + m_bTANGENTSPACE = false; +#endif // _DEBUG + m_nTANGENTSPACE = 0; +#ifdef _DEBUG + m_bBUMPMAP = false; +#endif // _DEBUG + m_nBUMPMAP = 0; +#ifdef _DEBUG + m_bDIFFUSEBUMPMAP = false; +#endif // _DEBUG + m_nDIFFUSEBUMPMAP = 0; +#ifdef _DEBUG + m_bVERTEXCOLOR = false; +#endif // _DEBUG + m_nVERTEXCOLOR = 0; +#ifdef _DEBUG + m_bVERTEXALPHATEXBLENDFACTOR = false; +#endif // _DEBUG + m_nVERTEXALPHATEXBLENDFACTOR = 0; +#ifdef _DEBUG + m_bRELIEF_MAPPING = false; +#endif // _DEBUG + m_nRELIEF_MAPPING = 0; +#ifdef _DEBUG + m_bSEAMLESS = false; +#endif // _DEBUG + m_nSEAMLESS = 0; +#ifdef _DEBUG + m_bBUMPMASK = false; +#endif // _DEBUG + m_nBUMPMASK = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bENVMAP_MASK && m_bTANGENTSPACE && m_bBUMPMAP && m_bDIFFUSEBUMPMAP && m_bVERTEXCOLOR && m_bVERTEXALPHATEXBLENDFACTOR && m_bRELIEF_MAPPING && m_bSEAMLESS && m_bBUMPMASK; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 8 * m_nENVMAP_MASK ) + ( 16 * m_nTANGENTSPACE ) + ( 32 * m_nBUMPMAP ) + ( 64 * m_nDIFFUSEBUMPMAP ) + ( 128 * m_nVERTEXCOLOR ) + ( 256 * m_nVERTEXALPHATEXBLENDFACTOR ) + ( 512 * m_nRELIEF_MAPPING ) + ( 512 * m_nSEAMLESS ) + ( 1024 * m_nBUMPMASK ) + 0; + } +}; +#define shaderStaticTest_lightmappedgeneric_vs20 vsh_forgot_to_set_static_ENVMAP_MASK + vsh_forgot_to_set_static_TANGENTSPACE + vsh_forgot_to_set_static_BUMPMAP + vsh_forgot_to_set_static_DIFFUSEBUMPMAP + vsh_forgot_to_set_static_VERTEXCOLOR + vsh_forgot_to_set_static_VERTEXALPHATEXBLENDFACTOR + vsh_forgot_to_set_static_RELIEF_MAPPING + vsh_forgot_to_set_static_SEAMLESS + vsh_forgot_to_set_static_BUMPMASK + 0 +class lightmappedgeneric_vs20_Dynamic_Index +{ +private: + int m_nFASTPATH; +#ifdef _DEBUG + bool m_bFASTPATH; +#endif +public: + void SetFASTPATH( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFASTPATH = i; +#ifdef _DEBUG + m_bFASTPATH = true; +#endif + } + void SetFASTPATH( bool i ) + { + m_nFASTPATH = i ? 1 : 0; +#ifdef _DEBUG + m_bFASTPATH = true; +#endif + } +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nLIGHTING_PREVIEW; +#ifdef _DEBUG + bool m_bLIGHTING_PREVIEW; +#endif +public: + void SetLIGHTING_PREVIEW( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nLIGHTING_PREVIEW = i; +#ifdef _DEBUG + m_bLIGHTING_PREVIEW = true; +#endif + } + void SetLIGHTING_PREVIEW( bool i ) + { + m_nLIGHTING_PREVIEW = i ? 1 : 0; +#ifdef _DEBUG + m_bLIGHTING_PREVIEW = true; +#endif + } +public: + lightmappedgeneric_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bFASTPATH = false; +#endif // _DEBUG + m_nFASTPATH = 0; +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bLIGHTING_PREVIEW = false; +#endif // _DEBUG + m_nLIGHTING_PREVIEW = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bFASTPATH && m_bDOWATERFOG && m_bLIGHTING_PREVIEW; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nFASTPATH ) + ( 2 * m_nDOWATERFOG ) + ( 4 * m_nLIGHTING_PREVIEW ) + 0; + } +}; +#define shaderDynamicTest_lightmappedgeneric_vs20 vsh_forgot_to_set_dynamic_FASTPATH + vsh_forgot_to_set_dynamic_DOWATERFOG + vsh_forgot_to_set_dynamic_LIGHTING_PREVIEW + 0 diff --git a/materialsystem/stdshaders/fxctmp9/lightmappedreflective_ps20.inc b/materialsystem/stdshaders/fxctmp9/lightmappedreflective_ps20.inc new file mode 100644 index 0000000..c912dd8 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/lightmappedreflective_ps20.inc @@ -0,0 +1,162 @@ +#include "shaderlib/cshader.h" +class lightmappedreflective_ps20_Static_Index +{ +private: + int m_nBASETEXTURE; +#ifdef _DEBUG + bool m_bBASETEXTURE; +#endif +public: + void SetBASETEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBASETEXTURE = i; +#ifdef _DEBUG + m_bBASETEXTURE = true; +#endif + } + void SetBASETEXTURE( bool i ) + { + m_nBASETEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bBASETEXTURE = true; +#endif + } +private: + int m_nREFLECT; +#ifdef _DEBUG + bool m_bREFLECT; +#endif +public: + void SetREFLECT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nREFLECT = i; +#ifdef _DEBUG + m_bREFLECT = true; +#endif + } + void SetREFLECT( bool i ) + { + m_nREFLECT = i ? 1 : 0; +#ifdef _DEBUG + m_bREFLECT = true; +#endif + } +private: + int m_nREFRACT; +#ifdef _DEBUG + bool m_bREFRACT; +#endif +public: + void SetREFRACT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nREFRACT = i; +#ifdef _DEBUG + m_bREFRACT = true; +#endif + } + void SetREFRACT( bool i ) + { + m_nREFRACT = i ? 1 : 0; +#ifdef _DEBUG + m_bREFRACT = true; +#endif + } +private: + int m_nENVMAPMASK; +#ifdef _DEBUG + bool m_bENVMAPMASK; +#endif +public: + void SetENVMAPMASK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nENVMAPMASK = i; +#ifdef _DEBUG + m_bENVMAPMASK = true; +#endif + } + void SetENVMAPMASK( bool i ) + { + m_nENVMAPMASK = i ? 1 : 0; +#ifdef _DEBUG + m_bENVMAPMASK = true; +#endif + } +public: + lightmappedreflective_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bBASETEXTURE = false; +#endif // _DEBUG + m_nBASETEXTURE = 0; +#ifdef _DEBUG + m_bREFLECT = false; +#endif // _DEBUG + m_nREFLECT = 0; +#ifdef _DEBUG + m_bREFRACT = false; +#endif // _DEBUG + m_nREFRACT = 0; +#ifdef _DEBUG + m_bENVMAPMASK = false; +#endif // _DEBUG + m_nENVMAPMASK = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bBASETEXTURE && m_bREFLECT && m_bREFRACT && m_bENVMAPMASK; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nBASETEXTURE ) + ( 4 * m_nREFLECT ) + ( 8 * m_nREFRACT ) + ( 16 * m_nENVMAPMASK ) + 0; + } +}; +#define shaderStaticTest_lightmappedreflective_ps20 psh_forgot_to_set_static_BASETEXTURE + psh_forgot_to_set_static_REFLECT + psh_forgot_to_set_static_REFRACT + psh_forgot_to_set_static_ENVMAPMASK + 0 +class lightmappedreflective_ps20_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + lightmappedreflective_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_lightmappedreflective_ps20 psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9/lightmappedreflective_ps20b.inc b/materialsystem/stdshaders/fxctmp9/lightmappedreflective_ps20b.inc new file mode 100644 index 0000000..defa755 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/lightmappedreflective_ps20b.inc @@ -0,0 +1,212 @@ +#include "shaderlib/cshader.h" +class lightmappedreflective_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +private: + int m_nBASETEXTURE; +#ifdef _DEBUG + bool m_bBASETEXTURE; +#endif +public: + void SetBASETEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBASETEXTURE = i; +#ifdef _DEBUG + m_bBASETEXTURE = true; +#endif + } + void SetBASETEXTURE( bool i ) + { + m_nBASETEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bBASETEXTURE = true; +#endif + } +private: + int m_nREFLECT; +#ifdef _DEBUG + bool m_bREFLECT; +#endif +public: + void SetREFLECT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nREFLECT = i; +#ifdef _DEBUG + m_bREFLECT = true; +#endif + } + void SetREFLECT( bool i ) + { + m_nREFLECT = i ? 1 : 0; +#ifdef _DEBUG + m_bREFLECT = true; +#endif + } +private: + int m_nREFRACT; +#ifdef _DEBUG + bool m_bREFRACT; +#endif +public: + void SetREFRACT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nREFRACT = i; +#ifdef _DEBUG + m_bREFRACT = true; +#endif + } + void SetREFRACT( bool i ) + { + m_nREFRACT = i ? 1 : 0; +#ifdef _DEBUG + m_bREFRACT = true; +#endif + } +private: + int m_nENVMAPMASK; +#ifdef _DEBUG + bool m_bENVMAPMASK; +#endif +public: + void SetENVMAPMASK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nENVMAPMASK = i; +#ifdef _DEBUG + m_bENVMAPMASK = true; +#endif + } + void SetENVMAPMASK( bool i ) + { + m_nENVMAPMASK = i ? 1 : 0; +#ifdef _DEBUG + m_bENVMAPMASK = true; +#endif + } +public: + lightmappedreflective_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); +#ifdef _DEBUG + m_bBASETEXTURE = false; +#endif // _DEBUG + m_nBASETEXTURE = 0; +#ifdef _DEBUG + m_bREFLECT = false; +#endif // _DEBUG + m_nREFLECT = 0; +#ifdef _DEBUG + m_bREFRACT = false; +#endif // _DEBUG + m_nREFRACT = 0; +#ifdef _DEBUG + m_bENVMAPMASK = false; +#endif // _DEBUG + m_nENVMAPMASK = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB && m_bBASETEXTURE && m_bREFLECT && m_bREFRACT && m_bENVMAPMASK; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 4 * m_nCONVERT_TO_SRGB ) + ( 8 * m_nBASETEXTURE ) + ( 16 * m_nREFLECT ) + ( 32 * m_nREFRACT ) + ( 64 * m_nENVMAPMASK ) + 0; + } +}; +#define shaderStaticTest_lightmappedreflective_ps20b psh_forgot_to_set_static_BASETEXTURE + psh_forgot_to_set_static_REFLECT + psh_forgot_to_set_static_REFRACT + psh_forgot_to_set_static_ENVMAPMASK + 0 +class lightmappedreflective_ps20b_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +private: + int m_nWRITE_DEPTH_TO_DESTALPHA; +#ifdef _DEBUG + bool m_bWRITE_DEPTH_TO_DESTALPHA; +#endif +public: + void SetWRITE_DEPTH_TO_DESTALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nWRITE_DEPTH_TO_DESTALPHA = i; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = true; +#endif + } + void SetWRITE_DEPTH_TO_DESTALPHA( bool i ) + { + m_nWRITE_DEPTH_TO_DESTALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = true; +#endif + } +public: + lightmappedreflective_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = false; +#endif // _DEBUG + m_nWRITE_DEPTH_TO_DESTALPHA = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE && m_bWRITE_DEPTH_TO_DESTALPHA; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + ( 2 * m_nWRITE_DEPTH_TO_DESTALPHA ) + 0; + } +}; +#define shaderDynamicTest_lightmappedreflective_ps20b psh_forgot_to_set_dynamic_PIXELFOGTYPE + psh_forgot_to_set_dynamic_WRITE_DEPTH_TO_DESTALPHA + 0 diff --git a/materialsystem/stdshaders/fxctmp9/lightmappedreflective_vs20.inc b/materialsystem/stdshaders/fxctmp9/lightmappedreflective_vs20.inc new file mode 100644 index 0000000..5e8df64 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/lightmappedreflective_vs20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class lightmappedreflective_vs20_Static_Index +{ +private: + int m_nBASETEXTURE; +#ifdef _DEBUG + bool m_bBASETEXTURE; +#endif +public: + void SetBASETEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBASETEXTURE = i; +#ifdef _DEBUG + m_bBASETEXTURE = true; +#endif + } + void SetBASETEXTURE( bool i ) + { + m_nBASETEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bBASETEXTURE = true; +#endif + } +public: + lightmappedreflective_vs20_Static_Index( ) + { +#ifdef _DEBUG + m_bBASETEXTURE = false; +#endif // _DEBUG + m_nBASETEXTURE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bBASETEXTURE; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nBASETEXTURE ) + 0; + } +}; +#define shaderStaticTest_lightmappedreflective_vs20 vsh_forgot_to_set_static_BASETEXTURE + 0 +class lightmappedreflective_vs20_Dynamic_Index +{ +public: + lightmappedreflective_vs20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_lightmappedreflective_vs20 0 diff --git a/materialsystem/stdshaders/fxctmp9/lpreview1_ps20.inc b/materialsystem/stdshaders/fxctmp9/lpreview1_ps20.inc new file mode 100644 index 0000000..622a136 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/lpreview1_ps20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class lpreview1_ps20_Static_Index +{ +public: + lpreview1_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_lpreview1_ps20 0 +class lpreview1_ps20_Dynamic_Index +{ +public: + lpreview1_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_lpreview1_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9/lpreview1_ps20b.inc b/materialsystem/stdshaders/fxctmp9/lpreview1_ps20b.inc new file mode 100644 index 0000000..2e25142 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/lpreview1_ps20b.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class lpreview1_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + lpreview1_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_lpreview1_ps20b 0 +class lpreview1_ps20b_Dynamic_Index +{ +public: + lpreview1_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_lpreview1_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9/lpreview_output_ps20.inc b/materialsystem/stdshaders/fxctmp9/lpreview_output_ps20.inc new file mode 100644 index 0000000..bc52e92 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/lpreview_output_ps20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class lpreview_output_ps20_Static_Index +{ +public: + lpreview_output_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_lpreview_output_ps20 0 +class lpreview_output_ps20_Dynamic_Index +{ +public: + lpreview_output_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_lpreview_output_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9/lpreview_output_ps20b.inc b/materialsystem/stdshaders/fxctmp9/lpreview_output_ps20b.inc new file mode 100644 index 0000000..3c9eb22 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/lpreview_output_ps20b.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class lpreview_output_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + lpreview_output_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_lpreview_output_ps20b 0 +class lpreview_output_ps20b_Dynamic_Index +{ +public: + lpreview_output_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_lpreview_output_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9/luminance_compare_ps20.inc b/materialsystem/stdshaders/fxctmp9/luminance_compare_ps20.inc new file mode 100644 index 0000000..a167d3c --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/luminance_compare_ps20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class luminance_compare_ps20_Static_Index +{ +public: + luminance_compare_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_luminance_compare_ps20 0 +class luminance_compare_ps20_Dynamic_Index +{ +public: + luminance_compare_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_luminance_compare_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9/luminance_compare_ps20b.inc b/materialsystem/stdshaders/fxctmp9/luminance_compare_ps20b.inc new file mode 100644 index 0000000..36a93f1 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/luminance_compare_ps20b.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class luminance_compare_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + luminance_compare_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_luminance_compare_ps20b 0 +class luminance_compare_ps20b_Dynamic_Index +{ +public: + luminance_compare_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_luminance_compare_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9/modulate_ps20.inc b/materialsystem/stdshaders/fxctmp9/modulate_ps20.inc new file mode 100644 index 0000000..e3fb969 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/modulate_ps20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class modulate_ps20_Static_Index +{ +public: + modulate_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_modulate_ps20 0 +class modulate_ps20_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + modulate_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_modulate_ps20 psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9/modulate_ps20b.inc b/materialsystem/stdshaders/fxctmp9/modulate_ps20b.inc new file mode 100644 index 0000000..f19fe76 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/modulate_ps20b.inc @@ -0,0 +1,112 @@ +#include "shaderlib/cshader.h" +class modulate_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + modulate_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 4 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_modulate_ps20b 0 +class modulate_ps20b_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +private: + int m_nWRITE_DEPTH_TO_DESTALPHA; +#ifdef _DEBUG + bool m_bWRITE_DEPTH_TO_DESTALPHA; +#endif +public: + void SetWRITE_DEPTH_TO_DESTALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nWRITE_DEPTH_TO_DESTALPHA = i; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = true; +#endif + } + void SetWRITE_DEPTH_TO_DESTALPHA( bool i ) + { + m_nWRITE_DEPTH_TO_DESTALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = true; +#endif + } +public: + modulate_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = false; +#endif // _DEBUG + m_nWRITE_DEPTH_TO_DESTALPHA = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE && m_bWRITE_DEPTH_TO_DESTALPHA; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + ( 2 * m_nWRITE_DEPTH_TO_DESTALPHA ) + 0; + } +}; +#define shaderDynamicTest_modulate_ps20b psh_forgot_to_set_dynamic_PIXELFOGTYPE + psh_forgot_to_set_dynamic_WRITE_DEPTH_TO_DESTALPHA + 0 diff --git a/materialsystem/stdshaders/fxctmp9/monitorscreen_ps20.inc b/materialsystem/stdshaders/fxctmp9/monitorscreen_ps20.inc new file mode 100644 index 0000000..d331310 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/monitorscreen_ps20.inc @@ -0,0 +1,87 @@ +#include "shaderlib/cshader.h" +class monitorscreen_ps20_Static_Index +{ +private: + int m_nTEXTURE2; +#ifdef _DEBUG + bool m_bTEXTURE2; +#endif +public: + void SetTEXTURE2( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nTEXTURE2 = i; +#ifdef _DEBUG + m_bTEXTURE2 = true; +#endif + } + void SetTEXTURE2( bool i ) + { + m_nTEXTURE2 = i ? 1 : 0; +#ifdef _DEBUG + m_bTEXTURE2 = true; +#endif + } +public: + monitorscreen_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bTEXTURE2 = false; +#endif // _DEBUG + m_nTEXTURE2 = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bTEXTURE2; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nTEXTURE2 ) + 0; + } +}; +#define shaderStaticTest_monitorscreen_ps20 psh_forgot_to_set_static_TEXTURE2 + 0 +class monitorscreen_ps20_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + monitorscreen_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_monitorscreen_ps20 psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9/monitorscreen_ps20b.inc b/materialsystem/stdshaders/fxctmp9/monitorscreen_ps20b.inc new file mode 100644 index 0000000..04e589f --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/monitorscreen_ps20b.inc @@ -0,0 +1,137 @@ +#include "shaderlib/cshader.h" +class monitorscreen_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +private: + int m_nTEXTURE2; +#ifdef _DEBUG + bool m_bTEXTURE2; +#endif +public: + void SetTEXTURE2( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nTEXTURE2 = i; +#ifdef _DEBUG + m_bTEXTURE2 = true; +#endif + } + void SetTEXTURE2( bool i ) + { + m_nTEXTURE2 = i ? 1 : 0; +#ifdef _DEBUG + m_bTEXTURE2 = true; +#endif + } +public: + monitorscreen_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); +#ifdef _DEBUG + m_bTEXTURE2 = false; +#endif // _DEBUG + m_nTEXTURE2 = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB && m_bTEXTURE2; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 4 * m_nCONVERT_TO_SRGB ) + ( 8 * m_nTEXTURE2 ) + 0; + } +}; +#define shaderStaticTest_monitorscreen_ps20b psh_forgot_to_set_static_TEXTURE2 + 0 +class monitorscreen_ps20b_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +private: + int m_nWRITE_DEPTH_TO_DESTALPHA; +#ifdef _DEBUG + bool m_bWRITE_DEPTH_TO_DESTALPHA; +#endif +public: + void SetWRITE_DEPTH_TO_DESTALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nWRITE_DEPTH_TO_DESTALPHA = i; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = true; +#endif + } + void SetWRITE_DEPTH_TO_DESTALPHA( bool i ) + { + m_nWRITE_DEPTH_TO_DESTALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = true; +#endif + } +public: + monitorscreen_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = false; +#endif // _DEBUG + m_nWRITE_DEPTH_TO_DESTALPHA = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE && m_bWRITE_DEPTH_TO_DESTALPHA; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + ( 2 * m_nWRITE_DEPTH_TO_DESTALPHA ) + 0; + } +}; +#define shaderDynamicTest_monitorscreen_ps20b psh_forgot_to_set_dynamic_PIXELFOGTYPE + psh_forgot_to_set_dynamic_WRITE_DEPTH_TO_DESTALPHA + 0 diff --git a/materialsystem/stdshaders/fxctmp9/morphaccumulate_ps30.inc b/materialsystem/stdshaders/fxctmp9/morphaccumulate_ps30.inc new file mode 100644 index 0000000..548e71c --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/morphaccumulate_ps30.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class morphaccumulate_ps30_Static_Index +{ +private: + int m_nCONSTANTBASEDMORPH; +#ifdef _DEBUG + bool m_bCONSTANTBASEDMORPH; +#endif +public: + void SetCONSTANTBASEDMORPH( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONSTANTBASEDMORPH = i; +#ifdef _DEBUG + m_bCONSTANTBASEDMORPH = true; +#endif + } + void SetCONSTANTBASEDMORPH( bool i ) + { + m_nCONSTANTBASEDMORPH = i ? 1 : 0; +#ifdef _DEBUG + m_bCONSTANTBASEDMORPH = true; +#endif + } +public: + morphaccumulate_ps30_Static_Index( ) + { +#ifdef _DEBUG + m_bCONSTANTBASEDMORPH = false; +#endif // _DEBUG + m_nCONSTANTBASEDMORPH = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONSTANTBASEDMORPH; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONSTANTBASEDMORPH ) + 0; + } +}; +#define shaderStaticTest_morphaccumulate_ps30 psh_forgot_to_set_static_CONSTANTBASEDMORPH + 0 +class morphaccumulate_ps30_Dynamic_Index +{ +public: + morphaccumulate_ps30_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_morphaccumulate_ps30 0 diff --git a/materialsystem/stdshaders/fxctmp9/morphaccumulate_vs30.inc b/materialsystem/stdshaders/fxctmp9/morphaccumulate_vs30.inc new file mode 100644 index 0000000..cf9c6aa --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/morphaccumulate_vs30.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class morphaccumulate_vs30_Static_Index +{ +private: + int m_nCONSTANTBASEDMORPH; +#ifdef _DEBUG + bool m_bCONSTANTBASEDMORPH; +#endif +public: + void SetCONSTANTBASEDMORPH( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONSTANTBASEDMORPH = i; +#ifdef _DEBUG + m_bCONSTANTBASEDMORPH = true; +#endif + } + void SetCONSTANTBASEDMORPH( bool i ) + { + m_nCONSTANTBASEDMORPH = i ? 1 : 0; +#ifdef _DEBUG + m_bCONSTANTBASEDMORPH = true; +#endif + } +public: + morphaccumulate_vs30_Static_Index( ) + { +#ifdef _DEBUG + m_bCONSTANTBASEDMORPH = false; +#endif // _DEBUG + m_nCONSTANTBASEDMORPH = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONSTANTBASEDMORPH; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONSTANTBASEDMORPH ) + 0; + } +}; +#define shaderStaticTest_morphaccumulate_vs30 vsh_forgot_to_set_static_CONSTANTBASEDMORPH + 0 +class morphaccumulate_vs30_Dynamic_Index +{ +public: + morphaccumulate_vs30_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_morphaccumulate_vs30 0 diff --git a/materialsystem/stdshaders/fxctmp9/morphweight_ps30.inc b/materialsystem/stdshaders/fxctmp9/morphweight_ps30.inc new file mode 100644 index 0000000..b780702 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/morphweight_ps30.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class morphweight_ps30_Static_Index +{ +public: + morphweight_ps30_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_morphweight_ps30 0 +class morphweight_ps30_Dynamic_Index +{ +public: + morphweight_ps30_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_morphweight_ps30 0 diff --git a/materialsystem/stdshaders/fxctmp9/morphweight_vs30.inc b/materialsystem/stdshaders/fxctmp9/morphweight_vs30.inc new file mode 100644 index 0000000..7874ec6 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/morphweight_vs30.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class morphweight_vs30_Static_Index +{ +public: + morphweight_vs30_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_morphweight_vs30 0 +class morphweight_vs30_Dynamic_Index +{ +public: + morphweight_vs30_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_morphweight_vs30 0 diff --git a/materialsystem/stdshaders/fxctmp9/motion_blur_ps20.inc b/materialsystem/stdshaders/fxctmp9/motion_blur_ps20.inc new file mode 100644 index 0000000..7543154 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/motion_blur_ps20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class motion_blur_ps20_Static_Index +{ +public: + motion_blur_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_motion_blur_ps20 0 +class motion_blur_ps20_Dynamic_Index +{ +private: + int m_nQUALITY; +#ifdef _DEBUG + bool m_bQUALITY; +#endif +public: + void SetQUALITY( int i ) + { + Assert( i >= 0 && i <= 3 ); + m_nQUALITY = i; +#ifdef _DEBUG + m_bQUALITY = true; +#endif + } + void SetQUALITY( bool i ) + { + m_nQUALITY = i ? 1 : 0; +#ifdef _DEBUG + m_bQUALITY = true; +#endif + } +public: + motion_blur_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bQUALITY = false; +#endif // _DEBUG + m_nQUALITY = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bQUALITY; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nQUALITY ) + 0; + } +}; +#define shaderDynamicTest_motion_blur_ps20 psh_forgot_to_set_dynamic_QUALITY + 0 diff --git a/materialsystem/stdshaders/fxctmp9/motion_blur_ps20b.inc b/materialsystem/stdshaders/fxctmp9/motion_blur_ps20b.inc new file mode 100644 index 0000000..34b5dd3 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/motion_blur_ps20b.inc @@ -0,0 +1,87 @@ +#include "shaderlib/cshader.h" +class motion_blur_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + motion_blur_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 4 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_motion_blur_ps20b 0 +class motion_blur_ps20b_Dynamic_Index +{ +private: + int m_nQUALITY; +#ifdef _DEBUG + bool m_bQUALITY; +#endif +public: + void SetQUALITY( int i ) + { + Assert( i >= 0 && i <= 3 ); + m_nQUALITY = i; +#ifdef _DEBUG + m_bQUALITY = true; +#endif + } + void SetQUALITY( bool i ) + { + m_nQUALITY = i ? 1 : 0; +#ifdef _DEBUG + m_bQUALITY = true; +#endif + } +public: + motion_blur_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bQUALITY = false; +#endif // _DEBUG + m_nQUALITY = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bQUALITY; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nQUALITY ) + 0; + } +}; +#define shaderDynamicTest_motion_blur_ps20b psh_forgot_to_set_dynamic_QUALITY + 0 diff --git a/materialsystem/stdshaders/fxctmp9/motion_blur_vs20.inc b/materialsystem/stdshaders/fxctmp9/motion_blur_vs20.inc new file mode 100644 index 0000000..ff9b0c7 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/motion_blur_vs20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class motion_blur_vs20_Static_Index +{ +public: + motion_blur_vs20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_motion_blur_vs20 0 +class motion_blur_vs20_Dynamic_Index +{ +public: + motion_blur_vs20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_motion_blur_vs20 0 diff --git a/materialsystem/stdshaders/fxctmp9/particlelit_generic_ps30.inc b/materialsystem/stdshaders/fxctmp9/particlelit_generic_ps30.inc new file mode 100644 index 0000000..090a751 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/particlelit_generic_ps30.inc @@ -0,0 +1,186 @@ +class particlelit_generic_ps30_Static_Index +{ +private: + int m_nHALFLAMBERT; +#ifdef _DEBUG + bool m_bHALFLAMBERT; +#endif +public: + void SetHALFLAMBERT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHALFLAMBERT = i; +#ifdef _DEBUG + m_bHALFLAMBERT = true; +#endif + } + void SetHALFLAMBERT( bool i ) + { + m_nHALFLAMBERT = i ? 1 : 0; +#ifdef _DEBUG + m_bHALFLAMBERT = true; +#endif + } +private: + int m_nHDRTYPE; +#ifdef _DEBUG + bool m_bHDRTYPE; +#endif +public: + void SetHDRTYPE( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nHDRTYPE = i; +#ifdef _DEBUG + m_bHDRTYPE = true; +#endif + } + void SetHDRTYPE( bool i ) + { + m_nHDRTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bHDRTYPE = true; +#endif + } +public: + particlelit_generic_ps30_Static_Index() + { +#ifdef _DEBUG + m_bHALFLAMBERT = false; +#endif // _DEBUG + m_nHALFLAMBERT = 0; +#ifdef _DEBUG + m_bHDRTYPE = false; +#endif // _DEBUG + m_nHDRTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bHALFLAMBERT && m_bHDRTYPE; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 264 * m_nHALFLAMBERT ) + ( 528 * m_nHDRTYPE ) + 0; + } +}; +#define shaderStaticTest_particlelit_generic_ps30 psh_forgot_to_set_static_HALFLAMBERT + psh_forgot_to_set_static_HDRTYPE + 0 +class particlelit_generic_ps30_Dynamic_Index +{ +private: + int m_nLIGHT_COMBO; +#ifdef _DEBUG + bool m_bLIGHT_COMBO; +#endif +public: + void SetLIGHT_COMBO( int i ) + { + Assert( i >= 0 && i <= 21 ); + m_nLIGHT_COMBO = i; +#ifdef _DEBUG + m_bLIGHT_COMBO = true; +#endif + } + void SetLIGHT_COMBO( bool i ) + { + m_nLIGHT_COMBO = i ? 1 : 0; +#ifdef _DEBUG + m_bLIGHT_COMBO = true; +#endif + } +private: + int m_nWRITEWATERFOGTODESTALPHA; +#ifdef _DEBUG + bool m_bWRITEWATERFOGTODESTALPHA; +#endif +public: + void SetWRITEWATERFOGTODESTALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nWRITEWATERFOGTODESTALPHA = i; +#ifdef _DEBUG + m_bWRITEWATERFOGTODESTALPHA = true; +#endif + } + void SetWRITEWATERFOGTODESTALPHA( bool i ) + { + m_nWRITEWATERFOGTODESTALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bWRITEWATERFOGTODESTALPHA = true; +#endif + } +private: + int m_nFOGTYPE; +#ifdef _DEBUG + bool m_bFOGTYPE; +#endif +public: + void SetFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nFOGTYPE = i; +#ifdef _DEBUG + m_bFOGTYPE = true; +#endif + } + void SetFOGTYPE( bool i ) + { + m_nFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bFOGTYPE = true; +#endif + } +private: + int m_nHDRENABLED; +#ifdef _DEBUG + bool m_bHDRENABLED; +#endif +public: + void SetHDRENABLED( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHDRENABLED = i; +#ifdef _DEBUG + m_bHDRENABLED = true; +#endif + } + void SetHDRENABLED( bool i ) + { + m_nHDRENABLED = i ? 1 : 0; +#ifdef _DEBUG + m_bHDRENABLED = true; +#endif + } +public: + particlelit_generic_ps30_Dynamic_Index() + { +#ifdef _DEBUG + m_bLIGHT_COMBO = false; +#endif // _DEBUG + m_nLIGHT_COMBO = 0; +#ifdef _DEBUG + m_bWRITEWATERFOGTODESTALPHA = false; +#endif // _DEBUG + m_nWRITEWATERFOGTODESTALPHA = 0; +#ifdef _DEBUG + m_bFOGTYPE = false; +#endif // _DEBUG + m_nFOGTYPE = 0; +#ifdef _DEBUG + m_bHDRENABLED = false; +#endif // _DEBUG + m_nHDRENABLED = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bLIGHT_COMBO && m_bWRITEWATERFOGTODESTALPHA && m_bFOGTYPE && m_bHDRENABLED; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nLIGHT_COMBO ) + ( 22 * m_nWRITEWATERFOGTODESTALPHA ) + ( 44 * m_nFOGTYPE ) + ( 132 * m_nHDRENABLED ) + 0; + } +}; +#define shaderDynamicTest_particlelit_generic_ps30 psh_forgot_to_set_dynamic_LIGHT_COMBO + psh_forgot_to_set_dynamic_WRITEWATERFOGTODESTALPHA + psh_forgot_to_set_dynamic_FOGTYPE + psh_forgot_to_set_dynamic_HDRENABLED + 0 diff --git a/materialsystem/stdshaders/fxctmp9/particlelit_generic_vs30.inc b/materialsystem/stdshaders/fxctmp9/particlelit_generic_vs30.inc new file mode 100644 index 0000000..7d0fd36 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/particlelit_generic_vs30.inc @@ -0,0 +1,59 @@ +class particlelit_generic_vs30_Static_Index +{ +private: + int m_nHALFLAMBERT; +#ifdef _DEBUG + bool m_bHALFLAMBERT; +#endif +public: + void SetHALFLAMBERT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHALFLAMBERT = i; +#ifdef _DEBUG + m_bHALFLAMBERT = true; +#endif + } + void SetHALFLAMBERT( bool i ) + { + m_nHALFLAMBERT = i ? 1 : 0; +#ifdef _DEBUG + m_bHALFLAMBERT = true; +#endif + } +public: + particlelit_generic_vs30_Static_Index() + { +#ifdef _DEBUG + m_bHALFLAMBERT = false; +#endif // _DEBUG + m_nHALFLAMBERT = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bHALFLAMBERT; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nHALFLAMBERT ) + 0; + } +}; +#define shaderStaticTest_particlelit_generic_vs30 vsh_forgot_to_set_static_HALFLAMBERT + 0 +class particlelit_generic_vs30_Dynamic_Index +{ +public: + particlelit_generic_vs30_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_particlelit_generic_vs30 0 diff --git a/materialsystem/stdshaders/fxctmp9/particlesphere_ps20.inc b/materialsystem/stdshaders/fxctmp9/particlesphere_ps20.inc new file mode 100644 index 0000000..ad1cac0 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/particlesphere_ps20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class particlesphere_ps20_Static_Index +{ +public: + particlesphere_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_particlesphere_ps20 0 +class particlesphere_ps20_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + particlesphere_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_particlesphere_ps20 psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9/particlesphere_ps20b.inc b/materialsystem/stdshaders/fxctmp9/particlesphere_ps20b.inc new file mode 100644 index 0000000..0dc4ce6 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/particlesphere_ps20b.inc @@ -0,0 +1,112 @@ +#include "shaderlib/cshader.h" +class particlesphere_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +private: + int m_nDEPTHBLEND; +#ifdef _DEBUG + bool m_bDEPTHBLEND; +#endif +public: + void SetDEPTHBLEND( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDEPTHBLEND = i; +#ifdef _DEBUG + m_bDEPTHBLEND = true; +#endif + } + void SetDEPTHBLEND( bool i ) + { + m_nDEPTHBLEND = i ? 1 : 0; +#ifdef _DEBUG + m_bDEPTHBLEND = true; +#endif + } +public: + particlesphere_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); +#ifdef _DEBUG + m_bDEPTHBLEND = false; +#endif // _DEBUG + m_nDEPTHBLEND = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB && m_bDEPTHBLEND; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nCONVERT_TO_SRGB ) + ( 4 * m_nDEPTHBLEND ) + 0; + } +}; +#define shaderStaticTest_particlesphere_ps20b psh_forgot_to_set_static_DEPTHBLEND + 0 +class particlesphere_ps20b_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + particlesphere_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_particlesphere_ps20b psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9/particlesphere_vs20.inc b/materialsystem/stdshaders/fxctmp9/particlesphere_vs20.inc new file mode 100644 index 0000000..6b7b273 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/particlesphere_vs20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class particlesphere_vs20_Static_Index +{ +public: + particlesphere_vs20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_particlesphere_vs20 0 +class particlesphere_vs20_Dynamic_Index +{ +private: + int m_nFOGTYPE; +#ifdef _DEBUG + bool m_bFOGTYPE; +#endif +public: + void SetFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFOGTYPE = i; +#ifdef _DEBUG + m_bFOGTYPE = true; +#endif + } + void SetFOGTYPE( bool i ) + { + m_nFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bFOGTYPE = true; +#endif + } +public: + particlesphere_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bFOGTYPE = false; +#endif // _DEBUG + m_nFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_particlesphere_vs20 vsh_forgot_to_set_dynamic_FOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9/portal_ps11.inc b/materialsystem/stdshaders/fxctmp9/portal_ps11.inc new file mode 100644 index 0000000..cee5360 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/portal_ps11.inc @@ -0,0 +1,162 @@ +#include "shaderlib/cshader.h" +class portal_ps11_Static_Index +{ +private: + int m_nMAXTEXTURESTAGES; +#ifdef _DEBUG + bool m_bMAXTEXTURESTAGES; +#endif +public: + void SetMAXTEXTURESTAGES( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nMAXTEXTURESTAGES = i; +#ifdef _DEBUG + m_bMAXTEXTURESTAGES = true; +#endif + } + void SetMAXTEXTURESTAGES( bool i ) + { + m_nMAXTEXTURESTAGES = i ? 1 : 0; +#ifdef _DEBUG + m_bMAXTEXTURESTAGES = true; +#endif + } +private: + int m_nHASALPHAMASK; +#ifdef _DEBUG + bool m_bHASALPHAMASK; +#endif +public: + void SetHASALPHAMASK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHASALPHAMASK = i; +#ifdef _DEBUG + m_bHASALPHAMASK = true; +#endif + } + void SetHASALPHAMASK( bool i ) + { + m_nHASALPHAMASK = i ? 1 : 0; +#ifdef _DEBUG + m_bHASALPHAMASK = true; +#endif + } +private: + int m_nHASSTATICTEXTURE; +#ifdef _DEBUG + bool m_bHASSTATICTEXTURE; +#endif +public: + void SetHASSTATICTEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHASSTATICTEXTURE = i; +#ifdef _DEBUG + m_bHASSTATICTEXTURE = true; +#endif + } + void SetHASSTATICTEXTURE( bool i ) + { + m_nHASSTATICTEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bHASSTATICTEXTURE = true; +#endif + } +public: + portal_ps11_Static_Index( ) + { +#ifdef _DEBUG + m_bMAXTEXTURESTAGES = false; +#endif // _DEBUG + m_nMAXTEXTURESTAGES = 0; +#ifdef _DEBUG + m_bHASALPHAMASK = false; +#endif // _DEBUG + m_nHASALPHAMASK = 0; +#ifdef _DEBUG + m_bHASSTATICTEXTURE = false; +#endif // _DEBUG + m_nHASSTATICTEXTURE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bMAXTEXTURESTAGES && m_bHASALPHAMASK && m_bHASSTATICTEXTURE; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 4 * m_nMAXTEXTURESTAGES ) + ( 12 * m_nHASALPHAMASK ) + ( 24 * m_nHASSTATICTEXTURE ) + 0; + } +}; +#define shaderStaticTest_portal_ps11 psh_forgot_to_set_static_MAXTEXTURESTAGES + psh_forgot_to_set_static_HASALPHAMASK + psh_forgot_to_set_static_HASSTATICTEXTURE + 0 +class portal_ps11_Dynamic_Index +{ +private: + int m_nADDSTATIC; +#ifdef _DEBUG + bool m_bADDSTATIC; +#endif +public: + void SetADDSTATIC( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nADDSTATIC = i; +#ifdef _DEBUG + m_bADDSTATIC = true; +#endif + } + void SetADDSTATIC( bool i ) + { + m_nADDSTATIC = i ? 1 : 0; +#ifdef _DEBUG + m_bADDSTATIC = true; +#endif + } +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + portal_ps11_Dynamic_Index() + { +#ifdef _DEBUG + m_bADDSTATIC = false; +#endif // _DEBUG + m_nADDSTATIC = 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bADDSTATIC && m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nADDSTATIC ) + ( 2 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_portal_ps11 psh_forgot_to_set_dynamic_ADDSTATIC + psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9/portal_ps20.inc b/materialsystem/stdshaders/fxctmp9/portal_ps20.inc new file mode 100644 index 0000000..eccfeac --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/portal_ps20.inc @@ -0,0 +1,162 @@ +#include "shaderlib/cshader.h" +class portal_ps20_Static_Index +{ +private: + int m_nHASALPHAMASK; +#ifdef _DEBUG + bool m_bHASALPHAMASK; +#endif +public: + void SetHASALPHAMASK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHASALPHAMASK = i; +#ifdef _DEBUG + m_bHASALPHAMASK = true; +#endif + } + void SetHASALPHAMASK( bool i ) + { + m_nHASALPHAMASK = i ? 1 : 0; +#ifdef _DEBUG + m_bHASALPHAMASK = true; +#endif + } +private: + int m_nHASSTATICTEXTURE; +#ifdef _DEBUG + bool m_bHASSTATICTEXTURE; +#endif +public: + void SetHASSTATICTEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHASSTATICTEXTURE = i; +#ifdef _DEBUG + m_bHASSTATICTEXTURE = true; +#endif + } + void SetHASSTATICTEXTURE( bool i ) + { + m_nHASSTATICTEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bHASSTATICTEXTURE = true; +#endif + } +public: + portal_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bHASALPHAMASK = false; +#endif // _DEBUG + m_nHASALPHAMASK = 0; +#ifdef _DEBUG + m_bHASSTATICTEXTURE = false; +#endif // _DEBUG + m_nHASSTATICTEXTURE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bHASALPHAMASK && m_bHASSTATICTEXTURE; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 8 * m_nHASALPHAMASK ) + ( 16 * m_nHASSTATICTEXTURE ) + 0; + } +}; +#define shaderStaticTest_portal_ps20 psh_forgot_to_set_static_HASALPHAMASK + psh_forgot_to_set_static_HASSTATICTEXTURE + 0 +class portal_ps20_Dynamic_Index +{ +private: + int m_nADDSTATIC; +#ifdef _DEBUG + bool m_bADDSTATIC; +#endif +public: + void SetADDSTATIC( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nADDSTATIC = i; +#ifdef _DEBUG + m_bADDSTATIC = true; +#endif + } + void SetADDSTATIC( bool i ) + { + m_nADDSTATIC = i ? 1 : 0; +#ifdef _DEBUG + m_bADDSTATIC = true; +#endif + } +private: + int m_nHDRENABLED; +#ifdef _DEBUG + bool m_bHDRENABLED; +#endif +public: + void SetHDRENABLED( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHDRENABLED = i; +#ifdef _DEBUG + m_bHDRENABLED = true; +#endif + } + void SetHDRENABLED( bool i ) + { + m_nHDRENABLED = i ? 1 : 0; +#ifdef _DEBUG + m_bHDRENABLED = true; +#endif + } +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + portal_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bADDSTATIC = false; +#endif // _DEBUG + m_nADDSTATIC = 0; +#ifdef _DEBUG + m_bHDRENABLED = false; +#endif // _DEBUG + m_nHDRENABLED = 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bADDSTATIC && m_bHDRENABLED && m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nADDSTATIC ) + ( 2 * m_nHDRENABLED ) + ( 4 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_portal_ps20 psh_forgot_to_set_dynamic_ADDSTATIC + psh_forgot_to_set_dynamic_HDRENABLED + psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9/portal_ps20b.inc b/materialsystem/stdshaders/fxctmp9/portal_ps20b.inc new file mode 100644 index 0000000..b4b4de7 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/portal_ps20b.inc @@ -0,0 +1,187 @@ +#include "shaderlib/cshader.h" +class portal_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +private: + int m_nHASALPHAMASK; +#ifdef _DEBUG + bool m_bHASALPHAMASK; +#endif +public: + void SetHASALPHAMASK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHASALPHAMASK = i; +#ifdef _DEBUG + m_bHASALPHAMASK = true; +#endif + } + void SetHASALPHAMASK( bool i ) + { + m_nHASALPHAMASK = i ? 1 : 0; +#ifdef _DEBUG + m_bHASALPHAMASK = true; +#endif + } +private: + int m_nHASSTATICTEXTURE; +#ifdef _DEBUG + bool m_bHASSTATICTEXTURE; +#endif +public: + void SetHASSTATICTEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHASSTATICTEXTURE = i; +#ifdef _DEBUG + m_bHASSTATICTEXTURE = true; +#endif + } + void SetHASSTATICTEXTURE( bool i ) + { + m_nHASSTATICTEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bHASSTATICTEXTURE = true; +#endif + } +public: + portal_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); +#ifdef _DEBUG + m_bHASALPHAMASK = false; +#endif // _DEBUG + m_nHASALPHAMASK = 0; +#ifdef _DEBUG + m_bHASSTATICTEXTURE = false; +#endif // _DEBUG + m_nHASSTATICTEXTURE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB && m_bHASALPHAMASK && m_bHASSTATICTEXTURE; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 8 * m_nCONVERT_TO_SRGB ) + ( 16 * m_nHASALPHAMASK ) + ( 32 * m_nHASSTATICTEXTURE ) + 0; + } +}; +#define shaderStaticTest_portal_ps20b psh_forgot_to_set_static_HASALPHAMASK + psh_forgot_to_set_static_HASSTATICTEXTURE + 0 +class portal_ps20b_Dynamic_Index +{ +private: + int m_nADDSTATIC; +#ifdef _DEBUG + bool m_bADDSTATIC; +#endif +public: + void SetADDSTATIC( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nADDSTATIC = i; +#ifdef _DEBUG + m_bADDSTATIC = true; +#endif + } + void SetADDSTATIC( bool i ) + { + m_nADDSTATIC = i ? 1 : 0; +#ifdef _DEBUG + m_bADDSTATIC = true; +#endif + } +private: + int m_nHDRENABLED; +#ifdef _DEBUG + bool m_bHDRENABLED; +#endif +public: + void SetHDRENABLED( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHDRENABLED = i; +#ifdef _DEBUG + m_bHDRENABLED = true; +#endif + } + void SetHDRENABLED( bool i ) + { + m_nHDRENABLED = i ? 1 : 0; +#ifdef _DEBUG + m_bHDRENABLED = true; +#endif + } +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + portal_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bADDSTATIC = false; +#endif // _DEBUG + m_nADDSTATIC = 0; +#ifdef _DEBUG + m_bHDRENABLED = false; +#endif // _DEBUG + m_nHDRENABLED = 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bADDSTATIC && m_bHDRENABLED && m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nADDSTATIC ) + ( 2 * m_nHDRENABLED ) + ( 4 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_portal_ps20b psh_forgot_to_set_dynamic_ADDSTATIC + psh_forgot_to_set_dynamic_HDRENABLED + psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9/portal_refract_ps11.inc b/materialsystem/stdshaders/fxctmp9/portal_refract_ps11.inc new file mode 100644 index 0000000..b07bc38 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/portal_refract_ps11.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class portal_refract_ps11_Static_Index +{ +private: + int m_nSTAGE; +#ifdef _DEBUG + bool m_bSTAGE; +#endif +public: + void SetSTAGE( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nSTAGE = i; +#ifdef _DEBUG + m_bSTAGE = true; +#endif + } + void SetSTAGE( bool i ) + { + m_nSTAGE = i ? 1 : 0; +#ifdef _DEBUG + m_bSTAGE = true; +#endif + } +public: + portal_refract_ps11_Static_Index( ) + { +#ifdef _DEBUG + m_bSTAGE = false; +#endif // _DEBUG + m_nSTAGE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bSTAGE; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nSTAGE ) + 0; + } +}; +#define shaderStaticTest_portal_refract_ps11 psh_forgot_to_set_static_STAGE + 0 +class portal_refract_ps11_Dynamic_Index +{ +public: + portal_refract_ps11_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_portal_refract_ps11 0 diff --git a/materialsystem/stdshaders/fxctmp9/portal_refract_ps20.inc b/materialsystem/stdshaders/fxctmp9/portal_refract_ps20.inc new file mode 100644 index 0000000..acfa35e --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/portal_refract_ps20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class portal_refract_ps20_Static_Index +{ +private: + int m_nSTAGE; +#ifdef _DEBUG + bool m_bSTAGE; +#endif +public: + void SetSTAGE( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nSTAGE = i; +#ifdef _DEBUG + m_bSTAGE = true; +#endif + } + void SetSTAGE( bool i ) + { + m_nSTAGE = i ? 1 : 0; +#ifdef _DEBUG + m_bSTAGE = true; +#endif + } +public: + portal_refract_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bSTAGE = false; +#endif // _DEBUG + m_nSTAGE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bSTAGE; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nSTAGE ) + 0; + } +}; +#define shaderStaticTest_portal_refract_ps20 psh_forgot_to_set_static_STAGE + 0 +class portal_refract_ps20_Dynamic_Index +{ +public: + portal_refract_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_portal_refract_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9/portal_refract_ps20b.inc b/materialsystem/stdshaders/fxctmp9/portal_refract_ps20b.inc new file mode 100644 index 0000000..b7ebbd7 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/portal_refract_ps20b.inc @@ -0,0 +1,137 @@ +#include "shaderlib/cshader.h" +class portal_refract_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +private: + int m_nSTAGE; +#ifdef _DEBUG + bool m_bSTAGE; +#endif +public: + void SetSTAGE( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nSTAGE = i; +#ifdef _DEBUG + m_bSTAGE = true; +#endif + } + void SetSTAGE( bool i ) + { + m_nSTAGE = i ? 1 : 0; +#ifdef _DEBUG + m_bSTAGE = true; +#endif + } +private: + int m_nSHADER_SRGB_READ; +#ifdef _DEBUG + bool m_bSHADER_SRGB_READ; +#endif +public: + void SetSHADER_SRGB_READ( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSHADER_SRGB_READ = i; +#ifdef _DEBUG + m_bSHADER_SRGB_READ = true; +#endif + } + void SetSHADER_SRGB_READ( bool i ) + { + m_nSHADER_SRGB_READ = i ? 1 : 0; +#ifdef _DEBUG + m_bSHADER_SRGB_READ = true; +#endif + } +public: + portal_refract_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); +#ifdef _DEBUG + m_bSTAGE = false; +#endif // _DEBUG + m_nSTAGE = 0; +#ifdef _DEBUG + m_bSHADER_SRGB_READ = false; +#endif // _DEBUG + m_nSHADER_SRGB_READ = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB && m_bSTAGE && m_bSHADER_SRGB_READ; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nCONVERT_TO_SRGB ) + ( 4 * m_nSTAGE ) + ( 12 * m_nSHADER_SRGB_READ ) + 0; + } +}; +#define shaderStaticTest_portal_refract_ps20b psh_forgot_to_set_static_STAGE + psh_forgot_to_set_static_SHADER_SRGB_READ + 0 +class portal_refract_ps20b_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + portal_refract_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_portal_refract_ps20b psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9/portal_refract_vs11.inc b/materialsystem/stdshaders/fxctmp9/portal_refract_vs11.inc new file mode 100644 index 0000000..534d6c9 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/portal_refract_vs11.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class portal_refract_vs11_Static_Index +{ +private: + int m_nSTAGE; +#ifdef _DEBUG + bool m_bSTAGE; +#endif +public: + void SetSTAGE( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nSTAGE = i; +#ifdef _DEBUG + m_bSTAGE = true; +#endif + } + void SetSTAGE( bool i ) + { + m_nSTAGE = i ? 1 : 0; +#ifdef _DEBUG + m_bSTAGE = true; +#endif + } +public: + portal_refract_vs11_Static_Index( ) + { +#ifdef _DEBUG + m_bSTAGE = false; +#endif // _DEBUG + m_nSTAGE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bSTAGE; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nSTAGE ) + 0; + } +}; +#define shaderStaticTest_portal_refract_vs11 vsh_forgot_to_set_static_STAGE + 0 +class portal_refract_vs11_Dynamic_Index +{ +public: + portal_refract_vs11_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_portal_refract_vs11 0 diff --git a/materialsystem/stdshaders/fxctmp9/portal_refract_vs20.inc b/materialsystem/stdshaders/fxctmp9/portal_refract_vs20.inc new file mode 100644 index 0000000..534ca44 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/portal_refract_vs20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class portal_refract_vs20_Static_Index +{ +private: + int m_nSTAGE; +#ifdef _DEBUG + bool m_bSTAGE; +#endif +public: + void SetSTAGE( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nSTAGE = i; +#ifdef _DEBUG + m_bSTAGE = true; +#endif + } + void SetSTAGE( bool i ) + { + m_nSTAGE = i ? 1 : 0; +#ifdef _DEBUG + m_bSTAGE = true; +#endif + } +public: + portal_refract_vs20_Static_Index( ) + { +#ifdef _DEBUG + m_bSTAGE = false; +#endif // _DEBUG + m_nSTAGE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bSTAGE; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nSTAGE ) + 0; + } +}; +#define shaderStaticTest_portal_refract_vs20 vsh_forgot_to_set_static_STAGE + 0 +class portal_refract_vs20_Dynamic_Index +{ +public: + portal_refract_vs20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_portal_refract_vs20 0 diff --git a/materialsystem/stdshaders/fxctmp9/portal_vs11.inc b/materialsystem/stdshaders/fxctmp9/portal_vs11.inc new file mode 100644 index 0000000..4c687db --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/portal_vs11.inc @@ -0,0 +1,187 @@ +#include "shaderlib/cshader.h" +class portal_vs11_Static_Index +{ +private: + int m_nMAXTEXTURESTAGES; +#ifdef _DEBUG + bool m_bMAXTEXTURESTAGES; +#endif +public: + void SetMAXTEXTURESTAGES( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nMAXTEXTURESTAGES = i; +#ifdef _DEBUG + m_bMAXTEXTURESTAGES = true; +#endif + } + void SetMAXTEXTURESTAGES( bool i ) + { + m_nMAXTEXTURESTAGES = i ? 1 : 0; +#ifdef _DEBUG + m_bMAXTEXTURESTAGES = true; +#endif + } +private: + int m_nHASALPHAMASK; +#ifdef _DEBUG + bool m_bHASALPHAMASK; +#endif +public: + void SetHASALPHAMASK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHASALPHAMASK = i; +#ifdef _DEBUG + m_bHASALPHAMASK = true; +#endif + } + void SetHASALPHAMASK( bool i ) + { + m_nHASALPHAMASK = i ? 1 : 0; +#ifdef _DEBUG + m_bHASALPHAMASK = true; +#endif + } +private: + int m_nHASSTATICTEXTURE; +#ifdef _DEBUG + bool m_bHASSTATICTEXTURE; +#endif +public: + void SetHASSTATICTEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHASSTATICTEXTURE = i; +#ifdef _DEBUG + m_bHASSTATICTEXTURE = true; +#endif + } + void SetHASSTATICTEXTURE( bool i ) + { + m_nHASSTATICTEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bHASSTATICTEXTURE = true; +#endif + } +private: + int m_nUSEALTERNATEVIEW; +#ifdef _DEBUG + bool m_bUSEALTERNATEVIEW; +#endif +public: + void SetUSEALTERNATEVIEW( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nUSEALTERNATEVIEW = i; +#ifdef _DEBUG + m_bUSEALTERNATEVIEW = true; +#endif + } + void SetUSEALTERNATEVIEW( bool i ) + { + m_nUSEALTERNATEVIEW = i ? 1 : 0; +#ifdef _DEBUG + m_bUSEALTERNATEVIEW = true; +#endif + } +public: + portal_vs11_Static_Index( ) + { +#ifdef _DEBUG + m_bMAXTEXTURESTAGES = false; +#endif // _DEBUG + m_nMAXTEXTURESTAGES = 0; +#ifdef _DEBUG + m_bHASALPHAMASK = false; +#endif // _DEBUG + m_nHASALPHAMASK = 0; +#ifdef _DEBUG + m_bHASSTATICTEXTURE = false; +#endif // _DEBUG + m_nHASSTATICTEXTURE = 0; +#ifdef _DEBUG + m_bUSEALTERNATEVIEW = false; +#endif // _DEBUG + m_nUSEALTERNATEVIEW = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bMAXTEXTURESTAGES && m_bHASALPHAMASK && m_bHASSTATICTEXTURE && m_bUSEALTERNATEVIEW; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 4 * m_nMAXTEXTURESTAGES ) + ( 12 * m_nHASALPHAMASK ) + ( 24 * m_nHASSTATICTEXTURE ) + ( 48 * m_nUSEALTERNATEVIEW ) + 0; + } +}; +#define shaderStaticTest_portal_vs11 vsh_forgot_to_set_static_MAXTEXTURESTAGES + vsh_forgot_to_set_static_HASALPHAMASK + vsh_forgot_to_set_static_HASSTATICTEXTURE + vsh_forgot_to_set_static_USEALTERNATEVIEW + 0 +class portal_vs11_Dynamic_Index +{ +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +private: + int m_nADDSTATIC; +#ifdef _DEBUG + bool m_bADDSTATIC; +#endif +public: + void SetADDSTATIC( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nADDSTATIC = i; +#ifdef _DEBUG + m_bADDSTATIC = true; +#endif + } + void SetADDSTATIC( bool i ) + { + m_nADDSTATIC = i ? 1 : 0; +#ifdef _DEBUG + m_bADDSTATIC = true; +#endif + } +public: + portal_vs11_Dynamic_Index() + { +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; +#ifdef _DEBUG + m_bADDSTATIC = false; +#endif // _DEBUG + m_nADDSTATIC = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bSKINNING && m_bADDSTATIC; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nSKINNING ) + ( 2 * m_nADDSTATIC ) + 0; + } +}; +#define shaderDynamicTest_portal_vs11 vsh_forgot_to_set_dynamic_SKINNING + vsh_forgot_to_set_dynamic_ADDSTATIC + 0 diff --git a/materialsystem/stdshaders/fxctmp9/portal_vs20.inc b/materialsystem/stdshaders/fxctmp9/portal_vs20.inc new file mode 100644 index 0000000..e0eb237 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/portal_vs20.inc @@ -0,0 +1,162 @@ +#include "shaderlib/cshader.h" +class portal_vs20_Static_Index +{ +private: + int m_nHASALPHAMASK; +#ifdef _DEBUG + bool m_bHASALPHAMASK; +#endif +public: + void SetHASALPHAMASK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHASALPHAMASK = i; +#ifdef _DEBUG + m_bHASALPHAMASK = true; +#endif + } + void SetHASALPHAMASK( bool i ) + { + m_nHASALPHAMASK = i ? 1 : 0; +#ifdef _DEBUG + m_bHASALPHAMASK = true; +#endif + } +private: + int m_nHASSTATICTEXTURE; +#ifdef _DEBUG + bool m_bHASSTATICTEXTURE; +#endif +public: + void SetHASSTATICTEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHASSTATICTEXTURE = i; +#ifdef _DEBUG + m_bHASSTATICTEXTURE = true; +#endif + } + void SetHASSTATICTEXTURE( bool i ) + { + m_nHASSTATICTEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bHASSTATICTEXTURE = true; +#endif + } +private: + int m_nUSEALTERNATEVIEW; +#ifdef _DEBUG + bool m_bUSEALTERNATEVIEW; +#endif +public: + void SetUSEALTERNATEVIEW( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nUSEALTERNATEVIEW = i; +#ifdef _DEBUG + m_bUSEALTERNATEVIEW = true; +#endif + } + void SetUSEALTERNATEVIEW( bool i ) + { + m_nUSEALTERNATEVIEW = i ? 1 : 0; +#ifdef _DEBUG + m_bUSEALTERNATEVIEW = true; +#endif + } +public: + portal_vs20_Static_Index( ) + { +#ifdef _DEBUG + m_bHASALPHAMASK = false; +#endif // _DEBUG + m_nHASALPHAMASK = 0; +#ifdef _DEBUG + m_bHASSTATICTEXTURE = false; +#endif // _DEBUG + m_nHASSTATICTEXTURE = 0; +#ifdef _DEBUG + m_bUSEALTERNATEVIEW = false; +#endif // _DEBUG + m_nUSEALTERNATEVIEW = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bHASALPHAMASK && m_bHASSTATICTEXTURE && m_bUSEALTERNATEVIEW; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 4 * m_nHASALPHAMASK ) + ( 8 * m_nHASSTATICTEXTURE ) + ( 16 * m_nUSEALTERNATEVIEW ) + 0; + } +}; +#define shaderStaticTest_portal_vs20 vsh_forgot_to_set_static_HASALPHAMASK + vsh_forgot_to_set_static_HASSTATICTEXTURE + vsh_forgot_to_set_static_USEALTERNATEVIEW + 0 +class portal_vs20_Dynamic_Index +{ +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +private: + int m_nADDSTATIC; +#ifdef _DEBUG + bool m_bADDSTATIC; +#endif +public: + void SetADDSTATIC( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nADDSTATIC = i; +#ifdef _DEBUG + m_bADDSTATIC = true; +#endif + } + void SetADDSTATIC( bool i ) + { + m_nADDSTATIC = i ? 1 : 0; +#ifdef _DEBUG + m_bADDSTATIC = true; +#endif + } +public: + portal_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; +#ifdef _DEBUG + m_bADDSTATIC = false; +#endif // _DEBUG + m_nADDSTATIC = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bSKINNING && m_bADDSTATIC; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nSKINNING ) + ( 2 * m_nADDSTATIC ) + 0; + } +}; +#define shaderDynamicTest_portal_vs20 vsh_forgot_to_set_dynamic_SKINNING + vsh_forgot_to_set_dynamic_ADDSTATIC + 0 diff --git a/materialsystem/stdshaders/fxctmp9/portalstaticoverlay_ps11.inc b/materialsystem/stdshaders/fxctmp9/portalstaticoverlay_ps11.inc new file mode 100644 index 0000000..7b7eb8f --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/portalstaticoverlay_ps11.inc @@ -0,0 +1,137 @@ +#include "shaderlib/cshader.h" +class portalstaticoverlay_ps11_Static_Index +{ +private: + int m_nHASALPHAMASK; +#ifdef _DEBUG + bool m_bHASALPHAMASK; +#endif +public: + void SetHASALPHAMASK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHASALPHAMASK = i; +#ifdef _DEBUG + m_bHASALPHAMASK = true; +#endif + } + void SetHASALPHAMASK( bool i ) + { + m_nHASALPHAMASK = i ? 1 : 0; +#ifdef _DEBUG + m_bHASALPHAMASK = true; +#endif + } +private: + int m_nHASSTATICTEXTURE; +#ifdef _DEBUG + bool m_bHASSTATICTEXTURE; +#endif +public: + void SetHASSTATICTEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHASSTATICTEXTURE = i; +#ifdef _DEBUG + m_bHASSTATICTEXTURE = true; +#endif + } + void SetHASSTATICTEXTURE( bool i ) + { + m_nHASSTATICTEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bHASSTATICTEXTURE = true; +#endif + } +public: + portalstaticoverlay_ps11_Static_Index( ) + { +#ifdef _DEBUG + m_bHASALPHAMASK = false; +#endif // _DEBUG + m_nHASALPHAMASK = 0; +#ifdef _DEBUG + m_bHASSTATICTEXTURE = false; +#endif // _DEBUG + m_nHASSTATICTEXTURE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bHASALPHAMASK && m_bHASSTATICTEXTURE; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 4 * m_nHASALPHAMASK ) + ( 8 * m_nHASSTATICTEXTURE ) + 0; + } +}; +#define shaderStaticTest_portalstaticoverlay_ps11 psh_forgot_to_set_static_HASALPHAMASK + psh_forgot_to_set_static_HASSTATICTEXTURE + 0 +class portalstaticoverlay_ps11_Dynamic_Index +{ +private: + int m_nHDRENABLED; +#ifdef _DEBUG + bool m_bHDRENABLED; +#endif +public: + void SetHDRENABLED( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHDRENABLED = i; +#ifdef _DEBUG + m_bHDRENABLED = true; +#endif + } + void SetHDRENABLED( bool i ) + { + m_nHDRENABLED = i ? 1 : 0; +#ifdef _DEBUG + m_bHDRENABLED = true; +#endif + } +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + portalstaticoverlay_ps11_Dynamic_Index() + { +#ifdef _DEBUG + m_bHDRENABLED = false; +#endif // _DEBUG + m_nHDRENABLED = 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bHDRENABLED && m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nHDRENABLED ) + ( 2 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_portalstaticoverlay_ps11 psh_forgot_to_set_dynamic_HDRENABLED + psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9/portalstaticoverlay_ps20.inc b/materialsystem/stdshaders/fxctmp9/portalstaticoverlay_ps20.inc new file mode 100644 index 0000000..f30314e --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/portalstaticoverlay_ps20.inc @@ -0,0 +1,137 @@ +#include "shaderlib/cshader.h" +class portalstaticoverlay_ps20_Static_Index +{ +private: + int m_nHASALPHAMASK; +#ifdef _DEBUG + bool m_bHASALPHAMASK; +#endif +public: + void SetHASALPHAMASK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHASALPHAMASK = i; +#ifdef _DEBUG + m_bHASALPHAMASK = true; +#endif + } + void SetHASALPHAMASK( bool i ) + { + m_nHASALPHAMASK = i ? 1 : 0; +#ifdef _DEBUG + m_bHASALPHAMASK = true; +#endif + } +private: + int m_nHASSTATICTEXTURE; +#ifdef _DEBUG + bool m_bHASSTATICTEXTURE; +#endif +public: + void SetHASSTATICTEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHASSTATICTEXTURE = i; +#ifdef _DEBUG + m_bHASSTATICTEXTURE = true; +#endif + } + void SetHASSTATICTEXTURE( bool i ) + { + m_nHASSTATICTEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bHASSTATICTEXTURE = true; +#endif + } +public: + portalstaticoverlay_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bHASALPHAMASK = false; +#endif // _DEBUG + m_nHASALPHAMASK = 0; +#ifdef _DEBUG + m_bHASSTATICTEXTURE = false; +#endif // _DEBUG + m_nHASSTATICTEXTURE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bHASALPHAMASK && m_bHASSTATICTEXTURE; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 4 * m_nHASALPHAMASK ) + ( 8 * m_nHASSTATICTEXTURE ) + 0; + } +}; +#define shaderStaticTest_portalstaticoverlay_ps20 psh_forgot_to_set_static_HASALPHAMASK + psh_forgot_to_set_static_HASSTATICTEXTURE + 0 +class portalstaticoverlay_ps20_Dynamic_Index +{ +private: + int m_nHDRENABLED; +#ifdef _DEBUG + bool m_bHDRENABLED; +#endif +public: + void SetHDRENABLED( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHDRENABLED = i; +#ifdef _DEBUG + m_bHDRENABLED = true; +#endif + } + void SetHDRENABLED( bool i ) + { + m_nHDRENABLED = i ? 1 : 0; +#ifdef _DEBUG + m_bHDRENABLED = true; +#endif + } +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + portalstaticoverlay_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bHDRENABLED = false; +#endif // _DEBUG + m_nHDRENABLED = 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bHDRENABLED && m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nHDRENABLED ) + ( 2 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_portalstaticoverlay_ps20 psh_forgot_to_set_dynamic_HDRENABLED + psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9/portalstaticoverlay_ps20b.inc b/materialsystem/stdshaders/fxctmp9/portalstaticoverlay_ps20b.inc new file mode 100644 index 0000000..8510f3d --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/portalstaticoverlay_ps20b.inc @@ -0,0 +1,162 @@ +#include "shaderlib/cshader.h" +class portalstaticoverlay_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +private: + int m_nHASALPHAMASK; +#ifdef _DEBUG + bool m_bHASALPHAMASK; +#endif +public: + void SetHASALPHAMASK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHASALPHAMASK = i; +#ifdef _DEBUG + m_bHASALPHAMASK = true; +#endif + } + void SetHASALPHAMASK( bool i ) + { + m_nHASALPHAMASK = i ? 1 : 0; +#ifdef _DEBUG + m_bHASALPHAMASK = true; +#endif + } +private: + int m_nHASSTATICTEXTURE; +#ifdef _DEBUG + bool m_bHASSTATICTEXTURE; +#endif +public: + void SetHASSTATICTEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHASSTATICTEXTURE = i; +#ifdef _DEBUG + m_bHASSTATICTEXTURE = true; +#endif + } + void SetHASSTATICTEXTURE( bool i ) + { + m_nHASSTATICTEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bHASSTATICTEXTURE = true; +#endif + } +public: + portalstaticoverlay_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); +#ifdef _DEBUG + m_bHASALPHAMASK = false; +#endif // _DEBUG + m_nHASALPHAMASK = 0; +#ifdef _DEBUG + m_bHASSTATICTEXTURE = false; +#endif // _DEBUG + m_nHASSTATICTEXTURE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB && m_bHASALPHAMASK && m_bHASSTATICTEXTURE; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 4 * m_nCONVERT_TO_SRGB ) + ( 8 * m_nHASALPHAMASK ) + ( 16 * m_nHASSTATICTEXTURE ) + 0; + } +}; +#define shaderStaticTest_portalstaticoverlay_ps20b psh_forgot_to_set_static_HASALPHAMASK + psh_forgot_to_set_static_HASSTATICTEXTURE + 0 +class portalstaticoverlay_ps20b_Dynamic_Index +{ +private: + int m_nHDRENABLED; +#ifdef _DEBUG + bool m_bHDRENABLED; +#endif +public: + void SetHDRENABLED( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHDRENABLED = i; +#ifdef _DEBUG + m_bHDRENABLED = true; +#endif + } + void SetHDRENABLED( bool i ) + { + m_nHDRENABLED = i ? 1 : 0; +#ifdef _DEBUG + m_bHDRENABLED = true; +#endif + } +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + portalstaticoverlay_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bHDRENABLED = false; +#endif // _DEBUG + m_nHDRENABLED = 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bHDRENABLED && m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nHDRENABLED ) + ( 2 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_portalstaticoverlay_ps20b psh_forgot_to_set_dynamic_HDRENABLED + psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9/portalstaticoverlay_vs11.inc b/materialsystem/stdshaders/fxctmp9/portalstaticoverlay_vs11.inc new file mode 100644 index 0000000..012727a --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/portalstaticoverlay_vs11.inc @@ -0,0 +1,87 @@ +#include "shaderlib/cshader.h" +class portalstaticoverlay_vs11_Static_Index +{ +private: + int m_nMODEL; +#ifdef _DEBUG + bool m_bMODEL; +#endif +public: + void SetMODEL( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nMODEL = i; +#ifdef _DEBUG + m_bMODEL = true; +#endif + } + void SetMODEL( bool i ) + { + m_nMODEL = i ? 1 : 0; +#ifdef _DEBUG + m_bMODEL = true; +#endif + } +public: + portalstaticoverlay_vs11_Static_Index( ) + { +#ifdef _DEBUG + m_bMODEL = false; +#endif // _DEBUG + m_nMODEL = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bMODEL; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nMODEL ) + 0; + } +}; +#define shaderStaticTest_portalstaticoverlay_vs11 vsh_forgot_to_set_static_MODEL + 0 +class portalstaticoverlay_vs11_Dynamic_Index +{ +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +public: + portalstaticoverlay_vs11_Dynamic_Index() + { +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bSKINNING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nSKINNING ) + 0; + } +}; +#define shaderDynamicTest_portalstaticoverlay_vs11 vsh_forgot_to_set_dynamic_SKINNING + 0 diff --git a/materialsystem/stdshaders/fxctmp9/portalstaticoverlay_vs20.inc b/materialsystem/stdshaders/fxctmp9/portalstaticoverlay_vs20.inc new file mode 100644 index 0000000..91beed5 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/portalstaticoverlay_vs20.inc @@ -0,0 +1,87 @@ +#include "shaderlib/cshader.h" +class portalstaticoverlay_vs20_Static_Index +{ +private: + int m_nMODEL; +#ifdef _DEBUG + bool m_bMODEL; +#endif +public: + void SetMODEL( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nMODEL = i; +#ifdef _DEBUG + m_bMODEL = true; +#endif + } + void SetMODEL( bool i ) + { + m_nMODEL = i ? 1 : 0; +#ifdef _DEBUG + m_bMODEL = true; +#endif + } +public: + portalstaticoverlay_vs20_Static_Index( ) + { +#ifdef _DEBUG + m_bMODEL = false; +#endif // _DEBUG + m_nMODEL = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bMODEL; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nMODEL ) + 0; + } +}; +#define shaderStaticTest_portalstaticoverlay_vs20 vsh_forgot_to_set_static_MODEL + 0 +class portalstaticoverlay_vs20_Dynamic_Index +{ +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +public: + portalstaticoverlay_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bSKINNING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nSKINNING ) + 0; + } +}; +#define shaderDynamicTest_portalstaticoverlay_vs20 vsh_forgot_to_set_dynamic_SKINNING + 0 diff --git a/materialsystem/stdshaders/fxctmp9/pyro_vision_ps20.inc b/materialsystem/stdshaders/fxctmp9/pyro_vision_ps20.inc new file mode 100644 index 0000000..155a83b --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/pyro_vision_ps20.inc @@ -0,0 +1,312 @@ +#include "shaderlib/cshader.h" +class pyro_vision_ps20_Static_Index +{ +private: + int m_nEFFECT; +#ifdef _DEBUG + bool m_bEFFECT; +#endif +public: + void SetEFFECT( int i ) + { + Assert( i >= 0 && i <= 3 ); + m_nEFFECT = i; +#ifdef _DEBUG + m_bEFFECT = true; +#endif + } + void SetEFFECT( bool i ) + { + m_nEFFECT = i ? 1 : 0; +#ifdef _DEBUG + m_bEFFECT = true; +#endif + } +private: + int m_nVERTEX_LIT; +#ifdef _DEBUG + bool m_bVERTEX_LIT; +#endif +public: + void SetVERTEX_LIT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nVERTEX_LIT = i; +#ifdef _DEBUG + m_bVERTEX_LIT = true; +#endif + } + void SetVERTEX_LIT( bool i ) + { + m_nVERTEX_LIT = i ? 1 : 0; +#ifdef _DEBUG + m_bVERTEX_LIT = true; +#endif + } +private: + int m_nBASETEXTURE2; +#ifdef _DEBUG + bool m_bBASETEXTURE2; +#endif +public: + void SetBASETEXTURE2( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBASETEXTURE2 = i; +#ifdef _DEBUG + m_bBASETEXTURE2 = true; +#endif + } + void SetBASETEXTURE2( bool i ) + { + m_nBASETEXTURE2 = i ? 1 : 0; +#ifdef _DEBUG + m_bBASETEXTURE2 = true; +#endif + } +private: + int m_nFANCY_BLENDING; +#ifdef _DEBUG + bool m_bFANCY_BLENDING; +#endif +public: + void SetFANCY_BLENDING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFANCY_BLENDING = i; +#ifdef _DEBUG + m_bFANCY_BLENDING = true; +#endif + } + void SetFANCY_BLENDING( bool i ) + { + m_nFANCY_BLENDING = i ? 1 : 0; +#ifdef _DEBUG + m_bFANCY_BLENDING = true; +#endif + } +private: + int m_nSELFILLUM; +#ifdef _DEBUG + bool m_bSELFILLUM; +#endif +public: + void SetSELFILLUM( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSELFILLUM = i; +#ifdef _DEBUG + m_bSELFILLUM = true; +#endif + } + void SetSELFILLUM( bool i ) + { + m_nSELFILLUM = i ? 1 : 0; +#ifdef _DEBUG + m_bSELFILLUM = true; +#endif + } +private: + int m_nCOLOR_BAR; +#ifdef _DEBUG + bool m_bCOLOR_BAR; +#endif +public: + void SetCOLOR_BAR( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOLOR_BAR = i; +#ifdef _DEBUG + m_bCOLOR_BAR = true; +#endif + } + void SetCOLOR_BAR( bool i ) + { + m_nCOLOR_BAR = i ? 1 : 0; +#ifdef _DEBUG + m_bCOLOR_BAR = true; +#endif + } +private: + int m_nSTRIPES; +#ifdef _DEBUG + bool m_bSTRIPES; +#endif +public: + void SetSTRIPES( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSTRIPES = i; +#ifdef _DEBUG + m_bSTRIPES = true; +#endif + } + void SetSTRIPES( bool i ) + { + m_nSTRIPES = i ? 1 : 0; +#ifdef _DEBUG + m_bSTRIPES = true; +#endif + } +private: + int m_nSTRIPES_USE_NORMAL2; +#ifdef _DEBUG + bool m_bSTRIPES_USE_NORMAL2; +#endif +public: + void SetSTRIPES_USE_NORMAL2( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSTRIPES_USE_NORMAL2 = i; +#ifdef _DEBUG + m_bSTRIPES_USE_NORMAL2 = true; +#endif + } + void SetSTRIPES_USE_NORMAL2( bool i ) + { + m_nSTRIPES_USE_NORMAL2 = i ? 1 : 0; +#ifdef _DEBUG + m_bSTRIPES_USE_NORMAL2 = true; +#endif + } +public: + pyro_vision_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bEFFECT = false; +#endif // _DEBUG + m_nEFFECT = 0; +#ifdef _DEBUG + m_bVERTEX_LIT = false; +#endif // _DEBUG + m_nVERTEX_LIT = 0; +#ifdef _DEBUG + m_bBASETEXTURE2 = false; +#endif // _DEBUG + m_nBASETEXTURE2 = 0; +#ifdef _DEBUG + m_bFANCY_BLENDING = false; +#endif // _DEBUG + m_nFANCY_BLENDING = 0; +#ifdef _DEBUG + m_bSELFILLUM = false; +#endif // _DEBUG + m_nSELFILLUM = 0; +#ifdef _DEBUG + m_bCOLOR_BAR = false; +#endif // _DEBUG + m_nCOLOR_BAR = 0; +#ifdef _DEBUG + m_bSTRIPES = false; +#endif // _DEBUG + m_nSTRIPES = 0; +#ifdef _DEBUG + m_bSTRIPES_USE_NORMAL2 = false; +#endif // _DEBUG + m_nSTRIPES_USE_NORMAL2 = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bEFFECT && m_bVERTEX_LIT && m_bBASETEXTURE2 && m_bFANCY_BLENDING && m_bSELFILLUM && m_bCOLOR_BAR && m_bSTRIPES && m_bSTRIPES_USE_NORMAL2; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 8 * m_nEFFECT ) + ( 32 * m_nVERTEX_LIT ) + ( 64 * m_nBASETEXTURE2 ) + ( 128 * m_nFANCY_BLENDING ) + ( 256 * m_nSELFILLUM ) + ( 512 * m_nCOLOR_BAR ) + ( 1024 * m_nSTRIPES ) + ( 2048 * m_nSTRIPES_USE_NORMAL2 ) + 0; + } +}; +#define shaderStaticTest_pyro_vision_ps20 psh_forgot_to_set_static_EFFECT + psh_forgot_to_set_static_VERTEX_LIT + psh_forgot_to_set_static_BASETEXTURE2 + psh_forgot_to_set_static_FANCY_BLENDING + psh_forgot_to_set_static_SELFILLUM + psh_forgot_to_set_static_COLOR_BAR + psh_forgot_to_set_static_STRIPES + psh_forgot_to_set_static_STRIPES_USE_NORMAL2 + 0 +class pyro_vision_ps20_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +private: + int m_nVISUALIZE_DOF; +#ifdef _DEBUG + bool m_bVISUALIZE_DOF; +#endif +public: + void SetVISUALIZE_DOF( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nVISUALIZE_DOF = i; +#ifdef _DEBUG + m_bVISUALIZE_DOF = true; +#endif + } + void SetVISUALIZE_DOF( bool i ) + { + m_nVISUALIZE_DOF = i ? 1 : 0; +#ifdef _DEBUG + m_bVISUALIZE_DOF = true; +#endif + } +private: + int m_nHEATHAZE; +#ifdef _DEBUG + bool m_bHEATHAZE; +#endif +public: + void SetHEATHAZE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHEATHAZE = i; +#ifdef _DEBUG + m_bHEATHAZE = true; +#endif + } + void SetHEATHAZE( bool i ) + { + m_nHEATHAZE = i ? 1 : 0; +#ifdef _DEBUG + m_bHEATHAZE = true; +#endif + } +public: + pyro_vision_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; +#ifdef _DEBUG + m_bVISUALIZE_DOF = false; +#endif // _DEBUG + m_nVISUALIZE_DOF = 0; +#ifdef _DEBUG + m_bHEATHAZE = false; +#endif // _DEBUG + m_nHEATHAZE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE && m_bVISUALIZE_DOF && m_bHEATHAZE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + ( 2 * m_nVISUALIZE_DOF ) + ( 4 * m_nHEATHAZE ) + 0; + } +}; +#define shaderDynamicTest_pyro_vision_ps20 psh_forgot_to_set_dynamic_PIXELFOGTYPE + psh_forgot_to_set_dynamic_VISUALIZE_DOF + psh_forgot_to_set_dynamic_HEATHAZE + 0 diff --git a/materialsystem/stdshaders/fxctmp9/pyro_vision_ps20b.inc b/materialsystem/stdshaders/fxctmp9/pyro_vision_ps20b.inc new file mode 100644 index 0000000..8a6a5d4 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/pyro_vision_ps20b.inc @@ -0,0 +1,312 @@ +#include "shaderlib/cshader.h" +class pyro_vision_ps20b_Static_Index +{ +private: + int m_nEFFECT; +#ifdef _DEBUG + bool m_bEFFECT; +#endif +public: + void SetEFFECT( int i ) + { + Assert( i >= 0 && i <= 3 ); + m_nEFFECT = i; +#ifdef _DEBUG + m_bEFFECT = true; +#endif + } + void SetEFFECT( bool i ) + { + m_nEFFECT = i ? 1 : 0; +#ifdef _DEBUG + m_bEFFECT = true; +#endif + } +private: + int m_nVERTEX_LIT; +#ifdef _DEBUG + bool m_bVERTEX_LIT; +#endif +public: + void SetVERTEX_LIT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nVERTEX_LIT = i; +#ifdef _DEBUG + m_bVERTEX_LIT = true; +#endif + } + void SetVERTEX_LIT( bool i ) + { + m_nVERTEX_LIT = i ? 1 : 0; +#ifdef _DEBUG + m_bVERTEX_LIT = true; +#endif + } +private: + int m_nBASETEXTURE2; +#ifdef _DEBUG + bool m_bBASETEXTURE2; +#endif +public: + void SetBASETEXTURE2( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBASETEXTURE2 = i; +#ifdef _DEBUG + m_bBASETEXTURE2 = true; +#endif + } + void SetBASETEXTURE2( bool i ) + { + m_nBASETEXTURE2 = i ? 1 : 0; +#ifdef _DEBUG + m_bBASETEXTURE2 = true; +#endif + } +private: + int m_nFANCY_BLENDING; +#ifdef _DEBUG + bool m_bFANCY_BLENDING; +#endif +public: + void SetFANCY_BLENDING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFANCY_BLENDING = i; +#ifdef _DEBUG + m_bFANCY_BLENDING = true; +#endif + } + void SetFANCY_BLENDING( bool i ) + { + m_nFANCY_BLENDING = i ? 1 : 0; +#ifdef _DEBUG + m_bFANCY_BLENDING = true; +#endif + } +private: + int m_nSELFILLUM; +#ifdef _DEBUG + bool m_bSELFILLUM; +#endif +public: + void SetSELFILLUM( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSELFILLUM = i; +#ifdef _DEBUG + m_bSELFILLUM = true; +#endif + } + void SetSELFILLUM( bool i ) + { + m_nSELFILLUM = i ? 1 : 0; +#ifdef _DEBUG + m_bSELFILLUM = true; +#endif + } +private: + int m_nCOLOR_BAR; +#ifdef _DEBUG + bool m_bCOLOR_BAR; +#endif +public: + void SetCOLOR_BAR( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOLOR_BAR = i; +#ifdef _DEBUG + m_bCOLOR_BAR = true; +#endif + } + void SetCOLOR_BAR( bool i ) + { + m_nCOLOR_BAR = i ? 1 : 0; +#ifdef _DEBUG + m_bCOLOR_BAR = true; +#endif + } +private: + int m_nSTRIPES; +#ifdef _DEBUG + bool m_bSTRIPES; +#endif +public: + void SetSTRIPES( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSTRIPES = i; +#ifdef _DEBUG + m_bSTRIPES = true; +#endif + } + void SetSTRIPES( bool i ) + { + m_nSTRIPES = i ? 1 : 0; +#ifdef _DEBUG + m_bSTRIPES = true; +#endif + } +private: + int m_nSTRIPES_USE_NORMAL2; +#ifdef _DEBUG + bool m_bSTRIPES_USE_NORMAL2; +#endif +public: + void SetSTRIPES_USE_NORMAL2( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSTRIPES_USE_NORMAL2 = i; +#ifdef _DEBUG + m_bSTRIPES_USE_NORMAL2 = true; +#endif + } + void SetSTRIPES_USE_NORMAL2( bool i ) + { + m_nSTRIPES_USE_NORMAL2 = i ? 1 : 0; +#ifdef _DEBUG + m_bSTRIPES_USE_NORMAL2 = true; +#endif + } +public: + pyro_vision_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bEFFECT = false; +#endif // _DEBUG + m_nEFFECT = 0; +#ifdef _DEBUG + m_bVERTEX_LIT = false; +#endif // _DEBUG + m_nVERTEX_LIT = 0; +#ifdef _DEBUG + m_bBASETEXTURE2 = false; +#endif // _DEBUG + m_nBASETEXTURE2 = 0; +#ifdef _DEBUG + m_bFANCY_BLENDING = false; +#endif // _DEBUG + m_nFANCY_BLENDING = 0; +#ifdef _DEBUG + m_bSELFILLUM = false; +#endif // _DEBUG + m_nSELFILLUM = 0; +#ifdef _DEBUG + m_bCOLOR_BAR = false; +#endif // _DEBUG + m_nCOLOR_BAR = 0; +#ifdef _DEBUG + m_bSTRIPES = false; +#endif // _DEBUG + m_nSTRIPES = 0; +#ifdef _DEBUG + m_bSTRIPES_USE_NORMAL2 = false; +#endif // _DEBUG + m_nSTRIPES_USE_NORMAL2 = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bEFFECT && m_bVERTEX_LIT && m_bBASETEXTURE2 && m_bFANCY_BLENDING && m_bSELFILLUM && m_bCOLOR_BAR && m_bSTRIPES && m_bSTRIPES_USE_NORMAL2; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 8 * m_nEFFECT ) + ( 32 * m_nVERTEX_LIT ) + ( 64 * m_nBASETEXTURE2 ) + ( 128 * m_nFANCY_BLENDING ) + ( 256 * m_nSELFILLUM ) + ( 512 * m_nCOLOR_BAR ) + ( 1024 * m_nSTRIPES ) + ( 2048 * m_nSTRIPES_USE_NORMAL2 ) + 0; + } +}; +#define shaderStaticTest_pyro_vision_ps20b psh_forgot_to_set_static_EFFECT + psh_forgot_to_set_static_VERTEX_LIT + psh_forgot_to_set_static_BASETEXTURE2 + psh_forgot_to_set_static_FANCY_BLENDING + psh_forgot_to_set_static_SELFILLUM + psh_forgot_to_set_static_COLOR_BAR + psh_forgot_to_set_static_STRIPES + psh_forgot_to_set_static_STRIPES_USE_NORMAL2 + 0 +class pyro_vision_ps20b_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +private: + int m_nVISUALIZE_DOF; +#ifdef _DEBUG + bool m_bVISUALIZE_DOF; +#endif +public: + void SetVISUALIZE_DOF( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nVISUALIZE_DOF = i; +#ifdef _DEBUG + m_bVISUALIZE_DOF = true; +#endif + } + void SetVISUALIZE_DOF( bool i ) + { + m_nVISUALIZE_DOF = i ? 1 : 0; +#ifdef _DEBUG + m_bVISUALIZE_DOF = true; +#endif + } +private: + int m_nHEATHAZE; +#ifdef _DEBUG + bool m_bHEATHAZE; +#endif +public: + void SetHEATHAZE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHEATHAZE = i; +#ifdef _DEBUG + m_bHEATHAZE = true; +#endif + } + void SetHEATHAZE( bool i ) + { + m_nHEATHAZE = i ? 1 : 0; +#ifdef _DEBUG + m_bHEATHAZE = true; +#endif + } +public: + pyro_vision_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; +#ifdef _DEBUG + m_bVISUALIZE_DOF = false; +#endif // _DEBUG + m_nVISUALIZE_DOF = 0; +#ifdef _DEBUG + m_bHEATHAZE = false; +#endif // _DEBUG + m_nHEATHAZE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE && m_bVISUALIZE_DOF && m_bHEATHAZE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + ( 2 * m_nVISUALIZE_DOF ) + ( 4 * m_nHEATHAZE ) + 0; + } +}; +#define shaderDynamicTest_pyro_vision_ps20b psh_forgot_to_set_dynamic_PIXELFOGTYPE + psh_forgot_to_set_dynamic_VISUALIZE_DOF + psh_forgot_to_set_dynamic_HEATHAZE + 0 diff --git a/materialsystem/stdshaders/fxctmp9/pyro_vision_ps30.inc b/materialsystem/stdshaders/fxctmp9/pyro_vision_ps30.inc new file mode 100644 index 0000000..842fa31 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/pyro_vision_ps30.inc @@ -0,0 +1,312 @@ +#include "shaderlib/cshader.h" +class pyro_vision_ps30_Static_Index +{ +private: + int m_nEFFECT; +#ifdef _DEBUG + bool m_bEFFECT; +#endif +public: + void SetEFFECT( int i ) + { + Assert( i >= 0 && i <= 3 ); + m_nEFFECT = i; +#ifdef _DEBUG + m_bEFFECT = true; +#endif + } + void SetEFFECT( bool i ) + { + m_nEFFECT = i ? 1 : 0; +#ifdef _DEBUG + m_bEFFECT = true; +#endif + } +private: + int m_nVERTEX_LIT; +#ifdef _DEBUG + bool m_bVERTEX_LIT; +#endif +public: + void SetVERTEX_LIT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nVERTEX_LIT = i; +#ifdef _DEBUG + m_bVERTEX_LIT = true; +#endif + } + void SetVERTEX_LIT( bool i ) + { + m_nVERTEX_LIT = i ? 1 : 0; +#ifdef _DEBUG + m_bVERTEX_LIT = true; +#endif + } +private: + int m_nBASETEXTURE2; +#ifdef _DEBUG + bool m_bBASETEXTURE2; +#endif +public: + void SetBASETEXTURE2( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBASETEXTURE2 = i; +#ifdef _DEBUG + m_bBASETEXTURE2 = true; +#endif + } + void SetBASETEXTURE2( bool i ) + { + m_nBASETEXTURE2 = i ? 1 : 0; +#ifdef _DEBUG + m_bBASETEXTURE2 = true; +#endif + } +private: + int m_nFANCY_BLENDING; +#ifdef _DEBUG + bool m_bFANCY_BLENDING; +#endif +public: + void SetFANCY_BLENDING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFANCY_BLENDING = i; +#ifdef _DEBUG + m_bFANCY_BLENDING = true; +#endif + } + void SetFANCY_BLENDING( bool i ) + { + m_nFANCY_BLENDING = i ? 1 : 0; +#ifdef _DEBUG + m_bFANCY_BLENDING = true; +#endif + } +private: + int m_nSELFILLUM; +#ifdef _DEBUG + bool m_bSELFILLUM; +#endif +public: + void SetSELFILLUM( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSELFILLUM = i; +#ifdef _DEBUG + m_bSELFILLUM = true; +#endif + } + void SetSELFILLUM( bool i ) + { + m_nSELFILLUM = i ? 1 : 0; +#ifdef _DEBUG + m_bSELFILLUM = true; +#endif + } +private: + int m_nCOLOR_BAR; +#ifdef _DEBUG + bool m_bCOLOR_BAR; +#endif +public: + void SetCOLOR_BAR( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOLOR_BAR = i; +#ifdef _DEBUG + m_bCOLOR_BAR = true; +#endif + } + void SetCOLOR_BAR( bool i ) + { + m_nCOLOR_BAR = i ? 1 : 0; +#ifdef _DEBUG + m_bCOLOR_BAR = true; +#endif + } +private: + int m_nSTRIPES; +#ifdef _DEBUG + bool m_bSTRIPES; +#endif +public: + void SetSTRIPES( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSTRIPES = i; +#ifdef _DEBUG + m_bSTRIPES = true; +#endif + } + void SetSTRIPES( bool i ) + { + m_nSTRIPES = i ? 1 : 0; +#ifdef _DEBUG + m_bSTRIPES = true; +#endif + } +private: + int m_nSTRIPES_USE_NORMAL2; +#ifdef _DEBUG + bool m_bSTRIPES_USE_NORMAL2; +#endif +public: + void SetSTRIPES_USE_NORMAL2( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSTRIPES_USE_NORMAL2 = i; +#ifdef _DEBUG + m_bSTRIPES_USE_NORMAL2 = true; +#endif + } + void SetSTRIPES_USE_NORMAL2( bool i ) + { + m_nSTRIPES_USE_NORMAL2 = i ? 1 : 0; +#ifdef _DEBUG + m_bSTRIPES_USE_NORMAL2 = true; +#endif + } +public: + pyro_vision_ps30_Static_Index( ) + { +#ifdef _DEBUG + m_bEFFECT = false; +#endif // _DEBUG + m_nEFFECT = 0; +#ifdef _DEBUG + m_bVERTEX_LIT = false; +#endif // _DEBUG + m_nVERTEX_LIT = 0; +#ifdef _DEBUG + m_bBASETEXTURE2 = false; +#endif // _DEBUG + m_nBASETEXTURE2 = 0; +#ifdef _DEBUG + m_bFANCY_BLENDING = false; +#endif // _DEBUG + m_nFANCY_BLENDING = 0; +#ifdef _DEBUG + m_bSELFILLUM = false; +#endif // _DEBUG + m_nSELFILLUM = 0; +#ifdef _DEBUG + m_bCOLOR_BAR = false; +#endif // _DEBUG + m_nCOLOR_BAR = 0; +#ifdef _DEBUG + m_bSTRIPES = false; +#endif // _DEBUG + m_nSTRIPES = 0; +#ifdef _DEBUG + m_bSTRIPES_USE_NORMAL2 = false; +#endif // _DEBUG + m_nSTRIPES_USE_NORMAL2 = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bEFFECT && m_bVERTEX_LIT && m_bBASETEXTURE2 && m_bFANCY_BLENDING && m_bSELFILLUM && m_bCOLOR_BAR && m_bSTRIPES && m_bSTRIPES_USE_NORMAL2; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 8 * m_nEFFECT ) + ( 32 * m_nVERTEX_LIT ) + ( 64 * m_nBASETEXTURE2 ) + ( 128 * m_nFANCY_BLENDING ) + ( 256 * m_nSELFILLUM ) + ( 512 * m_nCOLOR_BAR ) + ( 1024 * m_nSTRIPES ) + ( 2048 * m_nSTRIPES_USE_NORMAL2 ) + 0; + } +}; +#define shaderStaticTest_pyro_vision_ps30 psh_forgot_to_set_static_EFFECT + psh_forgot_to_set_static_VERTEX_LIT + psh_forgot_to_set_static_BASETEXTURE2 + psh_forgot_to_set_static_FANCY_BLENDING + psh_forgot_to_set_static_SELFILLUM + psh_forgot_to_set_static_COLOR_BAR + psh_forgot_to_set_static_STRIPES + psh_forgot_to_set_static_STRIPES_USE_NORMAL2 + 0 +class pyro_vision_ps30_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +private: + int m_nVISUALIZE_DOF; +#ifdef _DEBUG + bool m_bVISUALIZE_DOF; +#endif +public: + void SetVISUALIZE_DOF( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nVISUALIZE_DOF = i; +#ifdef _DEBUG + m_bVISUALIZE_DOF = true; +#endif + } + void SetVISUALIZE_DOF( bool i ) + { + m_nVISUALIZE_DOF = i ? 1 : 0; +#ifdef _DEBUG + m_bVISUALIZE_DOF = true; +#endif + } +private: + int m_nHEATHAZE; +#ifdef _DEBUG + bool m_bHEATHAZE; +#endif +public: + void SetHEATHAZE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHEATHAZE = i; +#ifdef _DEBUG + m_bHEATHAZE = true; +#endif + } + void SetHEATHAZE( bool i ) + { + m_nHEATHAZE = i ? 1 : 0; +#ifdef _DEBUG + m_bHEATHAZE = true; +#endif + } +public: + pyro_vision_ps30_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; +#ifdef _DEBUG + m_bVISUALIZE_DOF = false; +#endif // _DEBUG + m_nVISUALIZE_DOF = 0; +#ifdef _DEBUG + m_bHEATHAZE = false; +#endif // _DEBUG + m_nHEATHAZE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE && m_bVISUALIZE_DOF && m_bHEATHAZE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + ( 2 * m_nVISUALIZE_DOF ) + ( 4 * m_nHEATHAZE ) + 0; + } +}; +#define shaderDynamicTest_pyro_vision_ps30 psh_forgot_to_set_dynamic_PIXELFOGTYPE + psh_forgot_to_set_dynamic_VISUALIZE_DOF + psh_forgot_to_set_dynamic_HEATHAZE + 0 diff --git a/materialsystem/stdshaders/fxctmp9/pyro_vision_vs20.inc b/materialsystem/stdshaders/fxctmp9/pyro_vision_vs20.inc new file mode 100644 index 0000000..7be1c20 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/pyro_vision_vs20.inc @@ -0,0 +1,387 @@ +#include "shaderlib/cshader.h" +class pyro_vision_vs20_Static_Index +{ +private: + int m_nEFFECT; +#ifdef _DEBUG + bool m_bEFFECT; +#endif +public: + void SetEFFECT( int i ) + { + Assert( i >= 0 && i <= 3 ); + m_nEFFECT = i; +#ifdef _DEBUG + m_bEFFECT = true; +#endif + } + void SetEFFECT( bool i ) + { + m_nEFFECT = i ? 1 : 0; +#ifdef _DEBUG + m_bEFFECT = true; +#endif + } +private: + int m_nVERTEXCOLOR; +#ifdef _DEBUG + bool m_bVERTEXCOLOR; +#endif +public: + void SetVERTEXCOLOR( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nVERTEXCOLOR = i; +#ifdef _DEBUG + m_bVERTEXCOLOR = true; +#endif + } + void SetVERTEXCOLOR( bool i ) + { + m_nVERTEXCOLOR = i ? 1 : 0; +#ifdef _DEBUG + m_bVERTEXCOLOR = true; +#endif + } +private: + int m_nHALFLAMBERT; +#ifdef _DEBUG + bool m_bHALFLAMBERT; +#endif +public: + void SetHALFLAMBERT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHALFLAMBERT = i; +#ifdef _DEBUG + m_bHALFLAMBERT = true; +#endif + } + void SetHALFLAMBERT( bool i ) + { + m_nHALFLAMBERT = i ? 1 : 0; +#ifdef _DEBUG + m_bHALFLAMBERT = true; +#endif + } +private: + int m_nVERTEX_LIT; +#ifdef _DEBUG + bool m_bVERTEX_LIT; +#endif +public: + void SetVERTEX_LIT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nVERTEX_LIT = i; +#ifdef _DEBUG + m_bVERTEX_LIT = true; +#endif + } + void SetVERTEX_LIT( bool i ) + { + m_nVERTEX_LIT = i ? 1 : 0; +#ifdef _DEBUG + m_bVERTEX_LIT = true; +#endif + } +private: + int m_nFULLBRIGHT; +#ifdef _DEBUG + bool m_bFULLBRIGHT; +#endif +public: + void SetFULLBRIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFULLBRIGHT = i; +#ifdef _DEBUG + m_bFULLBRIGHT = true; +#endif + } + void SetFULLBRIGHT( bool i ) + { + m_nFULLBRIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bFULLBRIGHT = true; +#endif + } +private: + int m_nUSE_STATIC_CONTROL_FLOW; +#ifdef _DEBUG + bool m_bUSE_STATIC_CONTROL_FLOW; +#endif +public: + void SetUSE_STATIC_CONTROL_FLOW( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nUSE_STATIC_CONTROL_FLOW = i; +#ifdef _DEBUG + m_bUSE_STATIC_CONTROL_FLOW = true; +#endif + } + void SetUSE_STATIC_CONTROL_FLOW( bool i ) + { + m_nUSE_STATIC_CONTROL_FLOW = i ? 1 : 0; +#ifdef _DEBUG + m_bUSE_STATIC_CONTROL_FLOW = true; +#endif + } +private: + int m_nBASETEXTURE2; +#ifdef _DEBUG + bool m_bBASETEXTURE2; +#endif +public: + void SetBASETEXTURE2( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBASETEXTURE2 = i; +#ifdef _DEBUG + m_bBASETEXTURE2 = true; +#endif + } + void SetBASETEXTURE2( bool i ) + { + m_nBASETEXTURE2 = i ? 1 : 0; +#ifdef _DEBUG + m_bBASETEXTURE2 = true; +#endif + } +private: + int m_nSTRIPES; +#ifdef _DEBUG + bool m_bSTRIPES; +#endif +public: + void SetSTRIPES( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSTRIPES = i; +#ifdef _DEBUG + m_bSTRIPES = true; +#endif + } + void SetSTRIPES( bool i ) + { + m_nSTRIPES = i ? 1 : 0; +#ifdef _DEBUG + m_bSTRIPES = true; +#endif + } +private: + int m_nSTRIPES_USE_NORMAL2; +#ifdef _DEBUG + bool m_bSTRIPES_USE_NORMAL2; +#endif +public: + void SetSTRIPES_USE_NORMAL2( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSTRIPES_USE_NORMAL2 = i; +#ifdef _DEBUG + m_bSTRIPES_USE_NORMAL2 = true; +#endif + } + void SetSTRIPES_USE_NORMAL2( bool i ) + { + m_nSTRIPES_USE_NORMAL2 = i ? 1 : 0; +#ifdef _DEBUG + m_bSTRIPES_USE_NORMAL2 = true; +#endif + } +public: + pyro_vision_vs20_Static_Index( ) + { +#ifdef _DEBUG + m_bEFFECT = false; +#endif // _DEBUG + m_nEFFECT = 0; +#ifdef _DEBUG + m_bVERTEXCOLOR = false; +#endif // _DEBUG + m_nVERTEXCOLOR = 0; +#ifdef _DEBUG + m_bHALFLAMBERT = false; +#endif // _DEBUG + m_nHALFLAMBERT = 0; +#ifdef _DEBUG + m_bVERTEX_LIT = false; +#endif // _DEBUG + m_nVERTEX_LIT = 0; +#ifdef _DEBUG + m_bFULLBRIGHT = false; +#endif // _DEBUG + m_nFULLBRIGHT = 0; +#ifdef _DEBUG + m_bUSE_STATIC_CONTROL_FLOW = false; +#endif // _DEBUG + m_nUSE_STATIC_CONTROL_FLOW = 0; +#ifdef _DEBUG + m_bBASETEXTURE2 = false; +#endif // _DEBUG + m_nBASETEXTURE2 = 0; +#ifdef _DEBUG + m_bSTRIPES = false; +#endif // _DEBUG + m_nSTRIPES = 0; +#ifdef _DEBUG + m_bSTRIPES_USE_NORMAL2 = false; +#endif // _DEBUG + m_nSTRIPES_USE_NORMAL2 = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bEFFECT && m_bVERTEXCOLOR && m_bHALFLAMBERT && m_bVERTEX_LIT && m_bFULLBRIGHT && m_bUSE_STATIC_CONTROL_FLOW && m_bBASETEXTURE2 && m_bSTRIPES && m_bSTRIPES_USE_NORMAL2; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 48 * m_nEFFECT ) + ( 192 * m_nVERTEXCOLOR ) + ( 384 * m_nHALFLAMBERT ) + ( 768 * m_nVERTEX_LIT ) + ( 1536 * m_nFULLBRIGHT ) + ( 3072 * m_nUSE_STATIC_CONTROL_FLOW ) + ( 6144 * m_nBASETEXTURE2 ) + ( 12288 * m_nSTRIPES ) + ( 24576 * m_nSTRIPES_USE_NORMAL2 ) + 0; + } +}; +#define shaderStaticTest_pyro_vision_vs20 vsh_forgot_to_set_static_EFFECT + vsh_forgot_to_set_static_VERTEXCOLOR + vsh_forgot_to_set_static_HALFLAMBERT + vsh_forgot_to_set_static_VERTEX_LIT + vsh_forgot_to_set_static_FULLBRIGHT + vsh_forgot_to_set_static_USE_STATIC_CONTROL_FLOW + vsh_forgot_to_set_static_BASETEXTURE2 + vsh_forgot_to_set_static_STRIPES + vsh_forgot_to_set_static_STRIPES_USE_NORMAL2 + 0 +class pyro_vision_vs20_Dynamic_Index +{ +private: + int m_nCOMPRESSED_VERTS; +#ifdef _DEBUG + bool m_bCOMPRESSED_VERTS; +#endif +public: + void SetCOMPRESSED_VERTS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOMPRESSED_VERTS = i; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } + void SetCOMPRESSED_VERTS( bool i ) + { + m_nCOMPRESSED_VERTS = i ? 1 : 0; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +private: + int m_nDYNAMIC_LIGHT; +#ifdef _DEBUG + bool m_bDYNAMIC_LIGHT; +#endif +public: + void SetDYNAMIC_LIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDYNAMIC_LIGHT = i; +#ifdef _DEBUG + m_bDYNAMIC_LIGHT = true; +#endif + } + void SetDYNAMIC_LIGHT( bool i ) + { + m_nDYNAMIC_LIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bDYNAMIC_LIGHT = true; +#endif + } +private: + int m_nSTATIC_LIGHT; +#ifdef _DEBUG + bool m_bSTATIC_LIGHT; +#endif +public: + void SetSTATIC_LIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSTATIC_LIGHT = i; +#ifdef _DEBUG + m_bSTATIC_LIGHT = true; +#endif + } + void SetSTATIC_LIGHT( bool i ) + { + m_nSTATIC_LIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bSTATIC_LIGHT = true; +#endif + } +private: + int m_nNUM_LIGHTS; +#ifdef _DEBUG + bool m_bNUM_LIGHTS; +#endif +public: + void SetNUM_LIGHTS( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nNUM_LIGHTS = i; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } + void SetNUM_LIGHTS( bool i ) + { + m_nNUM_LIGHTS = i ? 1 : 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } +public: + pyro_vision_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = false; +#endif // _DEBUG + m_nCOMPRESSED_VERTS = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; +#ifdef _DEBUG + m_bDYNAMIC_LIGHT = false; +#endif // _DEBUG + m_nDYNAMIC_LIGHT = 0; +#ifdef _DEBUG + m_bSTATIC_LIGHT = false; +#endif // _DEBUG + m_nSTATIC_LIGHT = 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = false; +#endif // _DEBUG + m_nNUM_LIGHTS = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bCOMPRESSED_VERTS && m_bSKINNING && m_bDYNAMIC_LIGHT && m_bSTATIC_LIGHT && m_bNUM_LIGHTS; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCOMPRESSED_VERTS ) + ( 2 * m_nSKINNING ) + ( 4 * m_nDYNAMIC_LIGHT ) + ( 8 * m_nSTATIC_LIGHT ) + ( 16 * m_nNUM_LIGHTS ) + 0; + } +}; +#define shaderDynamicTest_pyro_vision_vs20 vsh_forgot_to_set_dynamic_COMPRESSED_VERTS + vsh_forgot_to_set_dynamic_SKINNING + vsh_forgot_to_set_dynamic_DYNAMIC_LIGHT + vsh_forgot_to_set_dynamic_STATIC_LIGHT + vsh_forgot_to_set_dynamic_NUM_LIGHTS + 0 diff --git a/materialsystem/stdshaders/fxctmp9/pyro_vision_vs30.inc b/materialsystem/stdshaders/fxctmp9/pyro_vision_vs30.inc new file mode 100644 index 0000000..f398ae2 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/pyro_vision_vs30.inc @@ -0,0 +1,337 @@ +#include "shaderlib/cshader.h" +class pyro_vision_vs30_Static_Index +{ +private: + int m_nEFFECT; +#ifdef _DEBUG + bool m_bEFFECT; +#endif +public: + void SetEFFECT( int i ) + { + Assert( i >= 0 && i <= 3 ); + m_nEFFECT = i; +#ifdef _DEBUG + m_bEFFECT = true; +#endif + } + void SetEFFECT( bool i ) + { + m_nEFFECT = i ? 1 : 0; +#ifdef _DEBUG + m_bEFFECT = true; +#endif + } +private: + int m_nVERTEXCOLOR; +#ifdef _DEBUG + bool m_bVERTEXCOLOR; +#endif +public: + void SetVERTEXCOLOR( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nVERTEXCOLOR = i; +#ifdef _DEBUG + m_bVERTEXCOLOR = true; +#endif + } + void SetVERTEXCOLOR( bool i ) + { + m_nVERTEXCOLOR = i ? 1 : 0; +#ifdef _DEBUG + m_bVERTEXCOLOR = true; +#endif + } +private: + int m_nHALFLAMBERT; +#ifdef _DEBUG + bool m_bHALFLAMBERT; +#endif +public: + void SetHALFLAMBERT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHALFLAMBERT = i; +#ifdef _DEBUG + m_bHALFLAMBERT = true; +#endif + } + void SetHALFLAMBERT( bool i ) + { + m_nHALFLAMBERT = i ? 1 : 0; +#ifdef _DEBUG + m_bHALFLAMBERT = true; +#endif + } +private: + int m_nVERTEX_LIT; +#ifdef _DEBUG + bool m_bVERTEX_LIT; +#endif +public: + void SetVERTEX_LIT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nVERTEX_LIT = i; +#ifdef _DEBUG + m_bVERTEX_LIT = true; +#endif + } + void SetVERTEX_LIT( bool i ) + { + m_nVERTEX_LIT = i ? 1 : 0; +#ifdef _DEBUG + m_bVERTEX_LIT = true; +#endif + } +private: + int m_nFULLBRIGHT; +#ifdef _DEBUG + bool m_bFULLBRIGHT; +#endif +public: + void SetFULLBRIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFULLBRIGHT = i; +#ifdef _DEBUG + m_bFULLBRIGHT = true; +#endif + } + void SetFULLBRIGHT( bool i ) + { + m_nFULLBRIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bFULLBRIGHT = true; +#endif + } +private: + int m_nBASETEXTURE2; +#ifdef _DEBUG + bool m_bBASETEXTURE2; +#endif +public: + void SetBASETEXTURE2( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBASETEXTURE2 = i; +#ifdef _DEBUG + m_bBASETEXTURE2 = true; +#endif + } + void SetBASETEXTURE2( bool i ) + { + m_nBASETEXTURE2 = i ? 1 : 0; +#ifdef _DEBUG + m_bBASETEXTURE2 = true; +#endif + } +private: + int m_nSTRIPES; +#ifdef _DEBUG + bool m_bSTRIPES; +#endif +public: + void SetSTRIPES( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSTRIPES = i; +#ifdef _DEBUG + m_bSTRIPES = true; +#endif + } + void SetSTRIPES( bool i ) + { + m_nSTRIPES = i ? 1 : 0; +#ifdef _DEBUG + m_bSTRIPES = true; +#endif + } +private: + int m_nSTRIPES_USE_NORMAL2; +#ifdef _DEBUG + bool m_bSTRIPES_USE_NORMAL2; +#endif +public: + void SetSTRIPES_USE_NORMAL2( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSTRIPES_USE_NORMAL2 = i; +#ifdef _DEBUG + m_bSTRIPES_USE_NORMAL2 = true; +#endif + } + void SetSTRIPES_USE_NORMAL2( bool i ) + { + m_nSTRIPES_USE_NORMAL2 = i ? 1 : 0; +#ifdef _DEBUG + m_bSTRIPES_USE_NORMAL2 = true; +#endif + } +public: + pyro_vision_vs30_Static_Index( ) + { +#ifdef _DEBUG + m_bEFFECT = false; +#endif // _DEBUG + m_nEFFECT = 0; +#ifdef _DEBUG + m_bVERTEXCOLOR = false; +#endif // _DEBUG + m_nVERTEXCOLOR = 0; +#ifdef _DEBUG + m_bHALFLAMBERT = false; +#endif // _DEBUG + m_nHALFLAMBERT = 0; +#ifdef _DEBUG + m_bVERTEX_LIT = false; +#endif // _DEBUG + m_nVERTEX_LIT = 0; +#ifdef _DEBUG + m_bFULLBRIGHT = false; +#endif // _DEBUG + m_nFULLBRIGHT = 0; +#ifdef _DEBUG + m_bBASETEXTURE2 = false; +#endif // _DEBUG + m_nBASETEXTURE2 = 0; +#ifdef _DEBUG + m_bSTRIPES = false; +#endif // _DEBUG + m_nSTRIPES = 0; +#ifdef _DEBUG + m_bSTRIPES_USE_NORMAL2 = false; +#endif // _DEBUG + m_nSTRIPES_USE_NORMAL2 = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bEFFECT && m_bVERTEXCOLOR && m_bHALFLAMBERT && m_bVERTEX_LIT && m_bFULLBRIGHT && m_bBASETEXTURE2 && m_bSTRIPES && m_bSTRIPES_USE_NORMAL2; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 16 * m_nEFFECT ) + ( 64 * m_nVERTEXCOLOR ) + ( 128 * m_nHALFLAMBERT ) + ( 256 * m_nVERTEX_LIT ) + ( 512 * m_nFULLBRIGHT ) + ( 1024 * m_nBASETEXTURE2 ) + ( 2048 * m_nSTRIPES ) + ( 4096 * m_nSTRIPES_USE_NORMAL2 ) + 0; + } +}; +#define shaderStaticTest_pyro_vision_vs30 vsh_forgot_to_set_static_EFFECT + vsh_forgot_to_set_static_VERTEXCOLOR + vsh_forgot_to_set_static_HALFLAMBERT + vsh_forgot_to_set_static_VERTEX_LIT + vsh_forgot_to_set_static_FULLBRIGHT + vsh_forgot_to_set_static_BASETEXTURE2 + vsh_forgot_to_set_static_STRIPES + vsh_forgot_to_set_static_STRIPES_USE_NORMAL2 + 0 +class pyro_vision_vs30_Dynamic_Index +{ +private: + int m_nCOMPRESSED_VERTS; +#ifdef _DEBUG + bool m_bCOMPRESSED_VERTS; +#endif +public: + void SetCOMPRESSED_VERTS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOMPRESSED_VERTS = i; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } + void SetCOMPRESSED_VERTS( bool i ) + { + m_nCOMPRESSED_VERTS = i ? 1 : 0; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +private: + int m_nDYNAMIC_LIGHT; +#ifdef _DEBUG + bool m_bDYNAMIC_LIGHT; +#endif +public: + void SetDYNAMIC_LIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDYNAMIC_LIGHT = i; +#ifdef _DEBUG + m_bDYNAMIC_LIGHT = true; +#endif + } + void SetDYNAMIC_LIGHT( bool i ) + { + m_nDYNAMIC_LIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bDYNAMIC_LIGHT = true; +#endif + } +private: + int m_nSTATIC_LIGHT; +#ifdef _DEBUG + bool m_bSTATIC_LIGHT; +#endif +public: + void SetSTATIC_LIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSTATIC_LIGHT = i; +#ifdef _DEBUG + m_bSTATIC_LIGHT = true; +#endif + } + void SetSTATIC_LIGHT( bool i ) + { + m_nSTATIC_LIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bSTATIC_LIGHT = true; +#endif + } +public: + pyro_vision_vs30_Dynamic_Index() + { +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = false; +#endif // _DEBUG + m_nCOMPRESSED_VERTS = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; +#ifdef _DEBUG + m_bDYNAMIC_LIGHT = false; +#endif // _DEBUG + m_nDYNAMIC_LIGHT = 0; +#ifdef _DEBUG + m_bSTATIC_LIGHT = false; +#endif // _DEBUG + m_nSTATIC_LIGHT = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bCOMPRESSED_VERTS && m_bSKINNING && m_bDYNAMIC_LIGHT && m_bSTATIC_LIGHT; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCOMPRESSED_VERTS ) + ( 2 * m_nSKINNING ) + ( 4 * m_nDYNAMIC_LIGHT ) + ( 8 * m_nSTATIC_LIGHT ) + 0; + } +}; +#define shaderDynamicTest_pyro_vision_vs30 vsh_forgot_to_set_dynamic_COMPRESSED_VERTS + vsh_forgot_to_set_dynamic_SKINNING + vsh_forgot_to_set_dynamic_DYNAMIC_LIGHT + vsh_forgot_to_set_dynamic_STATIC_LIGHT + 0 diff --git a/materialsystem/stdshaders/fxctmp9/rendertargetblit_ps20.inc b/materialsystem/stdshaders/fxctmp9/rendertargetblit_ps20.inc new file mode 100644 index 0000000..e2577eb --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/rendertargetblit_ps20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class rendertargetblit_ps20_Static_Index +{ +public: + rendertargetblit_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_rendertargetblit_ps20 0 +class rendertargetblit_ps20_Dynamic_Index +{ +public: + rendertargetblit_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_rendertargetblit_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9/rendertargetblit_ps20b.inc b/materialsystem/stdshaders/fxctmp9/rendertargetblit_ps20b.inc new file mode 100644 index 0000000..698b94f --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/rendertargetblit_ps20b.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class rendertargetblit_ps20b_Static_Index +{ +public: + rendertargetblit_ps20b_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_rendertargetblit_ps20b 0 +class rendertargetblit_ps20b_Dynamic_Index +{ +public: + rendertargetblit_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_rendertargetblit_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9/rendertargetblit_vs20.inc b/materialsystem/stdshaders/fxctmp9/rendertargetblit_vs20.inc new file mode 100644 index 0000000..7b69014 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/rendertargetblit_vs20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class rendertargetblit_vs20_Static_Index +{ +public: + rendertargetblit_vs20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_rendertargetblit_vs20 0 +class rendertargetblit_vs20_Dynamic_Index +{ +public: + rendertargetblit_vs20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_rendertargetblit_vs20 0 diff --git a/materialsystem/stdshaders/fxctmp9/sample4x4_blend_ps20.inc b/materialsystem/stdshaders/fxctmp9/sample4x4_blend_ps20.inc new file mode 100644 index 0000000..792c725 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/sample4x4_blend_ps20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class sample4x4_blend_ps20_Static_Index +{ +public: + sample4x4_blend_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_sample4x4_blend_ps20 0 +class sample4x4_blend_ps20_Dynamic_Index +{ +public: + sample4x4_blend_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_sample4x4_blend_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9/sample4x4_blend_ps20b.inc b/materialsystem/stdshaders/fxctmp9/sample4x4_blend_ps20b.inc new file mode 100644 index 0000000..fe94b5d --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/sample4x4_blend_ps20b.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class sample4x4_blend_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + sample4x4_blend_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_sample4x4_blend_ps20b 0 +class sample4x4_blend_ps20b_Dynamic_Index +{ +public: + sample4x4_blend_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_sample4x4_blend_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9/sample4x4_ps20.inc b/materialsystem/stdshaders/fxctmp9/sample4x4_ps20.inc new file mode 100644 index 0000000..4b44d7c --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/sample4x4_ps20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class sample4x4_ps20_Static_Index +{ +public: + sample4x4_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_sample4x4_ps20 0 +class sample4x4_ps20_Dynamic_Index +{ +public: + sample4x4_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_sample4x4_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9/sample4x4_ps20b.inc b/materialsystem/stdshaders/fxctmp9/sample4x4_ps20b.inc new file mode 100644 index 0000000..834101a --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/sample4x4_ps20b.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class sample4x4_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + sample4x4_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_sample4x4_ps20b 0 +class sample4x4_ps20b_Dynamic_Index +{ +public: + sample4x4_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_sample4x4_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9/sample4x4delog_ps20.inc b/materialsystem/stdshaders/fxctmp9/sample4x4delog_ps20.inc new file mode 100644 index 0000000..182dc96 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/sample4x4delog_ps20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class sample4x4delog_ps20_Static_Index +{ +public: + sample4x4delog_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_sample4x4delog_ps20 0 +class sample4x4delog_ps20_Dynamic_Index +{ +public: + sample4x4delog_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_sample4x4delog_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9/sample4x4delog_ps20b.inc b/materialsystem/stdshaders/fxctmp9/sample4x4delog_ps20b.inc new file mode 100644 index 0000000..c9c5cb7 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/sample4x4delog_ps20b.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class sample4x4delog_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + sample4x4delog_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_sample4x4delog_ps20b 0 +class sample4x4delog_ps20b_Dynamic_Index +{ +public: + sample4x4delog_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_sample4x4delog_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9/sample4x4log_ps20.inc b/materialsystem/stdshaders/fxctmp9/sample4x4log_ps20.inc new file mode 100644 index 0000000..31bfcca --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/sample4x4log_ps20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class sample4x4log_ps20_Static_Index +{ +public: + sample4x4log_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_sample4x4log_ps20 0 +class sample4x4log_ps20_Dynamic_Index +{ +public: + sample4x4log_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_sample4x4log_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9/sample4x4log_ps20b.inc b/materialsystem/stdshaders/fxctmp9/sample4x4log_ps20b.inc new file mode 100644 index 0000000..d2b173f --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/sample4x4log_ps20b.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class sample4x4log_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + sample4x4log_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_sample4x4log_ps20b 0 +class sample4x4log_ps20b_Dynamic_Index +{ +public: + sample4x4log_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_sample4x4log_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9/sample4x4maxmin_ps20.inc b/materialsystem/stdshaders/fxctmp9/sample4x4maxmin_ps20.inc new file mode 100644 index 0000000..d9e853d --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/sample4x4maxmin_ps20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class sample4x4maxmin_ps20_Static_Index +{ +public: + sample4x4maxmin_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_sample4x4maxmin_ps20 0 +class sample4x4maxmin_ps20_Dynamic_Index +{ +public: + sample4x4maxmin_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_sample4x4maxmin_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9/sample4x4maxmin_ps20b.inc b/materialsystem/stdshaders/fxctmp9/sample4x4maxmin_ps20b.inc new file mode 100644 index 0000000..65932fc --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/sample4x4maxmin_ps20b.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class sample4x4maxmin_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + sample4x4maxmin_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_sample4x4maxmin_ps20b 0 +class sample4x4maxmin_ps20b_Dynamic_Index +{ +public: + sample4x4maxmin_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_sample4x4maxmin_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9/screenspaceeffect_vs11.inc b/materialsystem/stdshaders/fxctmp9/screenspaceeffect_vs11.inc new file mode 100644 index 0000000..38093cc --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/screenspaceeffect_vs11.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class screenspaceeffect_vs11_Static_Index +{ +public: + screenspaceeffect_vs11_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_screenspaceeffect_vs11 0 +class screenspaceeffect_vs11_Dynamic_Index +{ +public: + screenspaceeffect_vs11_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_screenspaceeffect_vs11 0 diff --git a/materialsystem/stdshaders/fxctmp9/screenspaceeffect_vs20.inc b/materialsystem/stdshaders/fxctmp9/screenspaceeffect_vs20.inc new file mode 100644 index 0000000..3ed87f4 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/screenspaceeffect_vs20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class screenspaceeffect_vs20_Static_Index +{ +private: + int m_nX360APPCHOOSER; +#ifdef _DEBUG + bool m_bX360APPCHOOSER; +#endif +public: + void SetX360APPCHOOSER( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nX360APPCHOOSER = i; +#ifdef _DEBUG + m_bX360APPCHOOSER = true; +#endif + } + void SetX360APPCHOOSER( bool i ) + { + m_nX360APPCHOOSER = i ? 1 : 0; +#ifdef _DEBUG + m_bX360APPCHOOSER = true; +#endif + } +public: + screenspaceeffect_vs20_Static_Index( ) + { +#ifdef _DEBUG + m_bX360APPCHOOSER = true; +#endif // _DEBUG + m_nX360APPCHOOSER = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bX360APPCHOOSER; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nX360APPCHOOSER ) + 0; + } +}; +#define shaderStaticTest_screenspaceeffect_vs20 0 +class screenspaceeffect_vs20_Dynamic_Index +{ +public: + screenspaceeffect_vs20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_screenspaceeffect_vs20 0 diff --git a/materialsystem/stdshaders/fxctmp9/sfm_combine_vs20.inc b/materialsystem/stdshaders/fxctmp9/sfm_combine_vs20.inc new file mode 100644 index 0000000..f8d5f29 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/sfm_combine_vs20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class sfm_combine_vs20_Static_Index +{ +public: + sfm_combine_vs20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_sfm_combine_vs20 0 +class sfm_combine_vs20_Dynamic_Index +{ +public: + sfm_combine_vs20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_sfm_combine_vs20 0 diff --git a/materialsystem/stdshaders/fxctmp9/sfm_integercombine_ps20.inc b/materialsystem/stdshaders/fxctmp9/sfm_integercombine_ps20.inc new file mode 100644 index 0000000..3bccf86 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/sfm_integercombine_ps20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class sfm_integercombine_ps20_Static_Index +{ +public: + sfm_integercombine_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_sfm_integercombine_ps20 0 +class sfm_integercombine_ps20_Dynamic_Index +{ +public: + sfm_integercombine_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_sfm_integercombine_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9/sfm_integercombine_ps20b.inc b/materialsystem/stdshaders/fxctmp9/sfm_integercombine_ps20b.inc new file mode 100644 index 0000000..60f4c6b --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/sfm_integercombine_ps20b.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class sfm_integercombine_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + sfm_integercombine_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_sfm_integercombine_ps20b 0 +class sfm_integercombine_ps20b_Dynamic_Index +{ +public: + sfm_integercombine_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_sfm_integercombine_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9/shadow_ps20.inc b/materialsystem/stdshaders/fxctmp9/shadow_ps20.inc new file mode 100644 index 0000000..0f56f12 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/shadow_ps20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class shadow_ps20_Static_Index +{ +public: + shadow_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_shadow_ps20 0 +class shadow_ps20_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + shadow_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_shadow_ps20 psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9/shadow_ps20b.inc b/materialsystem/stdshaders/fxctmp9/shadow_ps20b.inc new file mode 100644 index 0000000..8948de6 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/shadow_ps20b.inc @@ -0,0 +1,87 @@ +#include "shaderlib/cshader.h" +class shadow_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + shadow_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_shadow_ps20b 0 +class shadow_ps20b_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + shadow_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_shadow_ps20b psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9/shadow_vs20.inc b/materialsystem/stdshaders/fxctmp9/shadow_vs20.inc new file mode 100644 index 0000000..4a96e17 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/shadow_vs20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class shadow_vs20_Static_Index +{ +public: + shadow_vs20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_shadow_vs20 0 +class shadow_vs20_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + shadow_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; +#define shaderDynamicTest_shadow_vs20 vsh_forgot_to_set_dynamic_DOWATERFOG + 0 diff --git a/materialsystem/stdshaders/fxctmp9/shadowbuildtexture_ps20.inc b/materialsystem/stdshaders/fxctmp9/shadowbuildtexture_ps20.inc new file mode 100644 index 0000000..9b63d4d --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/shadowbuildtexture_ps20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class shadowbuildtexture_ps20_Static_Index +{ +public: + shadowbuildtexture_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_shadowbuildtexture_ps20 0 +class shadowbuildtexture_ps20_Dynamic_Index +{ +public: + shadowbuildtexture_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_shadowbuildtexture_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9/shadowbuildtexture_ps20b.inc b/materialsystem/stdshaders/fxctmp9/shadowbuildtexture_ps20b.inc new file mode 100644 index 0000000..11a8608 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/shadowbuildtexture_ps20b.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class shadowbuildtexture_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + shadowbuildtexture_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_shadowbuildtexture_ps20b 0 +class shadowbuildtexture_ps20b_Dynamic_Index +{ +public: + shadowbuildtexture_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_shadowbuildtexture_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9/shadowmodel_ps20.inc b/materialsystem/stdshaders/fxctmp9/shadowmodel_ps20.inc new file mode 100644 index 0000000..6d4f8c8 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/shadowmodel_ps20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class shadowmodel_ps20_Static_Index +{ +public: + shadowmodel_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_shadowmodel_ps20 0 +class shadowmodel_ps20_Dynamic_Index +{ +public: + shadowmodel_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_shadowmodel_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9/shadowmodel_vs20.inc b/materialsystem/stdshaders/fxctmp9/shadowmodel_vs20.inc new file mode 100644 index 0000000..f5ec141 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/shadowmodel_vs20.inc @@ -0,0 +1,85 @@ +#include "shaderlib/cshader.h" +class shadowmodel_vs20_Static_Index +{ +public: + shadowmodel_vs20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_shadowmodel_vs20 0 +class shadowmodel_vs20_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +public: + shadowmodel_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG && m_bSKINNING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + ( 2 * m_nSKINNING ) + 0; + } +}; +#define shaderDynamicTest_shadowmodel_vs20 vsh_forgot_to_set_dynamic_DOWATERFOG + vsh_forgot_to_set_dynamic_SKINNING + 0 diff --git a/materialsystem/stdshaders/fxctmp9/showz_ps20.inc b/materialsystem/stdshaders/fxctmp9/showz_ps20.inc new file mode 100644 index 0000000..af02368 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/showz_ps20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class showz_ps20_Static_Index +{ +private: + int m_nDEPTH_IN_ALPHA; +#ifdef _DEBUG + bool m_bDEPTH_IN_ALPHA; +#endif +public: + void SetDEPTH_IN_ALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDEPTH_IN_ALPHA = i; +#ifdef _DEBUG + m_bDEPTH_IN_ALPHA = true; +#endif + } + void SetDEPTH_IN_ALPHA( bool i ) + { + m_nDEPTH_IN_ALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bDEPTH_IN_ALPHA = true; +#endif + } +public: + showz_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bDEPTH_IN_ALPHA = false; +#endif // _DEBUG + m_nDEPTH_IN_ALPHA = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bDEPTH_IN_ALPHA; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDEPTH_IN_ALPHA ) + 0; + } +}; +#define shaderStaticTest_showz_ps20 psh_forgot_to_set_static_DEPTH_IN_ALPHA + 0 +class showz_ps20_Dynamic_Index +{ +public: + showz_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_showz_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9/showz_ps20b.inc b/materialsystem/stdshaders/fxctmp9/showz_ps20b.inc new file mode 100644 index 0000000..0de3ce1 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/showz_ps20b.inc @@ -0,0 +1,85 @@ +#include "shaderlib/cshader.h" +class showz_ps20b_Static_Index +{ +private: + int m_nDEPTH_IN_ALPHA; +#ifdef _DEBUG + bool m_bDEPTH_IN_ALPHA; +#endif +public: + void SetDEPTH_IN_ALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDEPTH_IN_ALPHA = i; +#ifdef _DEBUG + m_bDEPTH_IN_ALPHA = true; +#endif + } + void SetDEPTH_IN_ALPHA( bool i ) + { + m_nDEPTH_IN_ALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bDEPTH_IN_ALPHA = true; +#endif + } +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + showz_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bDEPTH_IN_ALPHA = false; +#endif // _DEBUG + m_nDEPTH_IN_ALPHA = 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bDEPTH_IN_ALPHA && m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDEPTH_IN_ALPHA ) + ( 2 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_showz_ps20b psh_forgot_to_set_static_DEPTH_IN_ALPHA + 0 +class showz_ps20b_Dynamic_Index +{ +public: + showz_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_showz_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9/showz_vs20.inc b/materialsystem/stdshaders/fxctmp9/showz_vs20.inc new file mode 100644 index 0000000..344b432 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/showz_vs20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class showz_vs20_Static_Index +{ +public: + showz_vs20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_showz_vs20 0 +class showz_vs20_Dynamic_Index +{ +public: + showz_vs20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_showz_vs20 0 diff --git a/materialsystem/stdshaders/fxctmp9/skin_ps20.inc b/materialsystem/stdshaders/fxctmp9/skin_ps20.inc new file mode 100644 index 0000000..a43983d --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/skin_ps20.inc @@ -0,0 +1,261 @@ +class skin_ps20_Static_Index +{ +private: + int m_nBASETEXTURE; +#ifdef _DEBUG + bool m_bBASETEXTURE; +#endif +public: + void SetBASETEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBASETEXTURE = i; +#ifdef _DEBUG + m_bBASETEXTURE = true; +#endif + } + void SetBASETEXTURE( bool i ) + { + m_nBASETEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bBASETEXTURE = true; +#endif + } +private: + int m_nBUMPTEXTURE; +#ifdef _DEBUG + bool m_bBUMPTEXTURE; +#endif +public: + void SetBUMPTEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBUMPTEXTURE = i; +#ifdef _DEBUG + m_bBUMPTEXTURE = true; +#endif + } + void SetBUMPTEXTURE( bool i ) + { + m_nBUMPTEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bBUMPTEXTURE = true; +#endif + } +private: + int m_nDIFFUSELIGHTING; +#ifdef _DEBUG + bool m_bDIFFUSELIGHTING; +#endif +public: + void SetDIFFUSELIGHTING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDIFFUSELIGHTING = i; +#ifdef _DEBUG + m_bDIFFUSELIGHTING = true; +#endif + } + void SetDIFFUSELIGHTING( bool i ) + { + m_nDIFFUSELIGHTING = i ? 1 : 0; +#ifdef _DEBUG + m_bDIFFUSELIGHTING = true; +#endif + } +private: + int m_nSELFILLUM; +#ifdef _DEBUG + bool m_bSELFILLUM; +#endif +public: + void SetSELFILLUM( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSELFILLUM = i; +#ifdef _DEBUG + m_bSELFILLUM = true; +#endif + } + void SetSELFILLUM( bool i ) + { + m_nSELFILLUM = i ? 1 : 0; +#ifdef _DEBUG + m_bSELFILLUM = true; +#endif + } +private: + int m_nHALFLAMBERT; +#ifdef _DEBUG + bool m_bHALFLAMBERT; +#endif +public: + void SetHALFLAMBERT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHALFLAMBERT = i; +#ifdef _DEBUG + m_bHALFLAMBERT = true; +#endif + } + void SetHALFLAMBERT( bool i ) + { + m_nHALFLAMBERT = i ? 1 : 0; +#ifdef _DEBUG + m_bHALFLAMBERT = true; +#endif + } +private: + int m_nFLASHLIGHT; +#ifdef _DEBUG + bool m_bFLASHLIGHT; +#endif +public: + void SetFLASHLIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFLASHLIGHT = i; +#ifdef _DEBUG + m_bFLASHLIGHT = true; +#endif + } + void SetFLASHLIGHT( bool i ) + { + m_nFLASHLIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bFLASHLIGHT = true; +#endif + } +public: + skin_ps20_Static_Index() + { +#ifdef _DEBUG + m_bBASETEXTURE = false; +#endif // _DEBUG + m_nBASETEXTURE = 0; +#ifdef _DEBUG + m_bBUMPTEXTURE = false; +#endif // _DEBUG + m_nBUMPTEXTURE = 0; +#ifdef _DEBUG + m_bDIFFUSELIGHTING = false; +#endif // _DEBUG + m_nDIFFUSELIGHTING = 0; +#ifdef _DEBUG + m_bSELFILLUM = false; +#endif // _DEBUG + m_nSELFILLUM = 0; +#ifdef _DEBUG + m_bHALFLAMBERT = false; +#endif // _DEBUG + m_nHALFLAMBERT = 0; +#ifdef _DEBUG + m_bFLASHLIGHT = false; +#endif // _DEBUG + m_nFLASHLIGHT = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bBASETEXTURE && m_bBUMPTEXTURE && m_bDIFFUSELIGHTING && m_bSELFILLUM && m_bHALFLAMBERT && m_bFLASHLIGHT; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 132 * m_nBASETEXTURE ) + ( 264 * m_nBUMPTEXTURE ) + ( 528 * m_nDIFFUSELIGHTING ) + ( 1056 * m_nSELFILLUM ) + ( 2112 * m_nHALFLAMBERT ) + ( 4224 * m_nFLASHLIGHT ) + 0; + } +}; +#define shaderStaticTest_skin_ps20 psh_forgot_to_set_static_BASETEXTURE + psh_forgot_to_set_static_BUMPTEXTURE + psh_forgot_to_set_static_DIFFUSELIGHTING + psh_forgot_to_set_static_SELFILLUM + psh_forgot_to_set_static_HALFLAMBERT + psh_forgot_to_set_static_FLASHLIGHT + 0 +class skin_ps20_Dynamic_Index +{ +private: + int m_nLIGHT_COMBO; +#ifdef _DEBUG + bool m_bLIGHT_COMBO; +#endif +public: + void SetLIGHT_COMBO( int i ) + { + Assert( i >= 0 && i <= 21 ); + m_nLIGHT_COMBO = i; +#ifdef _DEBUG + m_bLIGHT_COMBO = true; +#endif + } + void SetLIGHT_COMBO( bool i ) + { + m_nLIGHT_COMBO = i ? 1 : 0; +#ifdef _DEBUG + m_bLIGHT_COMBO = true; +#endif + } +private: + int m_nWRITEWATERFOGTODESTALPHA; +#ifdef _DEBUG + bool m_bWRITEWATERFOGTODESTALPHA; +#endif +public: + void SetWRITEWATERFOGTODESTALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nWRITEWATERFOGTODESTALPHA = i; +#ifdef _DEBUG + m_bWRITEWATERFOGTODESTALPHA = true; +#endif + } + void SetWRITEWATERFOGTODESTALPHA( bool i ) + { + m_nWRITEWATERFOGTODESTALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bWRITEWATERFOGTODESTALPHA = true; +#endif + } +private: + int m_nFOGTYPE; +#ifdef _DEBUG + bool m_bFOGTYPE; +#endif +public: + void SetFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nFOGTYPE = i; +#ifdef _DEBUG + m_bFOGTYPE = true; +#endif + } + void SetFOGTYPE( bool i ) + { + m_nFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bFOGTYPE = true; +#endif + } +public: + skin_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bLIGHT_COMBO = false; +#endif // _DEBUG + m_nLIGHT_COMBO = 0; +#ifdef _DEBUG + m_bWRITEWATERFOGTODESTALPHA = false; +#endif // _DEBUG + m_nWRITEWATERFOGTODESTALPHA = 0; +#ifdef _DEBUG + m_bFOGTYPE = false; +#endif // _DEBUG + m_nFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bLIGHT_COMBO && m_bWRITEWATERFOGTODESTALPHA && m_bFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nLIGHT_COMBO ) + ( 22 * m_nWRITEWATERFOGTODESTALPHA ) + ( 44 * m_nFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_skin_ps20 psh_forgot_to_set_dynamic_LIGHT_COMBO + psh_forgot_to_set_dynamic_WRITEWATERFOGTODESTALPHA + psh_forgot_to_set_dynamic_FOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9/skin_ps20b.inc b/materialsystem/stdshaders/fxctmp9/skin_ps20b.inc new file mode 100644 index 0000000..6bd3c16 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/skin_ps20b.inc @@ -0,0 +1,537 @@ +#include "shaderlib/cshader.h" +class skin_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +private: + int m_nCUBEMAP; +#ifdef _DEBUG + bool m_bCUBEMAP; +#endif +public: + void SetCUBEMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCUBEMAP = i; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } + void SetCUBEMAP( bool i ) + { + m_nCUBEMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } +private: + int m_nSELFILLUM; +#ifdef _DEBUG + bool m_bSELFILLUM; +#endif +public: + void SetSELFILLUM( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSELFILLUM = i; +#ifdef _DEBUG + m_bSELFILLUM = true; +#endif + } + void SetSELFILLUM( bool i ) + { + m_nSELFILLUM = i ? 1 : 0; +#ifdef _DEBUG + m_bSELFILLUM = true; +#endif + } +private: + int m_nSELFILLUMFRESNEL; +#ifdef _DEBUG + bool m_bSELFILLUMFRESNEL; +#endif +public: + void SetSELFILLUMFRESNEL( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSELFILLUMFRESNEL = i; +#ifdef _DEBUG + m_bSELFILLUMFRESNEL = true; +#endif + } + void SetSELFILLUMFRESNEL( bool i ) + { + m_nSELFILLUMFRESNEL = i ? 1 : 0; +#ifdef _DEBUG + m_bSELFILLUMFRESNEL = true; +#endif + } +private: + int m_nFLASHLIGHT; +#ifdef _DEBUG + bool m_bFLASHLIGHT; +#endif +public: + void SetFLASHLIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFLASHLIGHT = i; +#ifdef _DEBUG + m_bFLASHLIGHT = true; +#endif + } + void SetFLASHLIGHT( bool i ) + { + m_nFLASHLIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bFLASHLIGHT = true; +#endif + } +private: + int m_nLIGHTWARPTEXTURE; +#ifdef _DEBUG + bool m_bLIGHTWARPTEXTURE; +#endif +public: + void SetLIGHTWARPTEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nLIGHTWARPTEXTURE = i; +#ifdef _DEBUG + m_bLIGHTWARPTEXTURE = true; +#endif + } + void SetLIGHTWARPTEXTURE( bool i ) + { + m_nLIGHTWARPTEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bLIGHTWARPTEXTURE = true; +#endif + } +private: + int m_nPHONGWARPTEXTURE; +#ifdef _DEBUG + bool m_bPHONGWARPTEXTURE; +#endif +public: + void SetPHONGWARPTEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPHONGWARPTEXTURE = i; +#ifdef _DEBUG + m_bPHONGWARPTEXTURE = true; +#endif + } + void SetPHONGWARPTEXTURE( bool i ) + { + m_nPHONGWARPTEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bPHONGWARPTEXTURE = true; +#endif + } +private: + int m_nWRINKLEMAP; +#ifdef _DEBUG + bool m_bWRINKLEMAP; +#endif +public: + void SetWRINKLEMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nWRINKLEMAP = i; +#ifdef _DEBUG + m_bWRINKLEMAP = true; +#endif + } + void SetWRINKLEMAP( bool i ) + { + m_nWRINKLEMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bWRINKLEMAP = true; +#endif + } +private: + int m_nDETAIL_BLEND_MODE; +#ifdef _DEBUG + bool m_bDETAIL_BLEND_MODE; +#endif +public: + void SetDETAIL_BLEND_MODE( int i ) + { + Assert( i >= 0 && i <= 6 ); + m_nDETAIL_BLEND_MODE = i; +#ifdef _DEBUG + m_bDETAIL_BLEND_MODE = true; +#endif + } + void SetDETAIL_BLEND_MODE( bool i ) + { + m_nDETAIL_BLEND_MODE = i ? 1 : 0; +#ifdef _DEBUG + m_bDETAIL_BLEND_MODE = true; +#endif + } +private: + int m_nDETAILTEXTURE; +#ifdef _DEBUG + bool m_bDETAILTEXTURE; +#endif +public: + void SetDETAILTEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDETAILTEXTURE = i; +#ifdef _DEBUG + m_bDETAILTEXTURE = true; +#endif + } + void SetDETAILTEXTURE( bool i ) + { + m_nDETAILTEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bDETAILTEXTURE = true; +#endif + } +private: + int m_nRIMLIGHT; +#ifdef _DEBUG + bool m_bRIMLIGHT; +#endif +public: + void SetRIMLIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nRIMLIGHT = i; +#ifdef _DEBUG + m_bRIMLIGHT = true; +#endif + } + void SetRIMLIGHT( bool i ) + { + m_nRIMLIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bRIMLIGHT = true; +#endif + } +private: + int m_nFLASHLIGHTDEPTHFILTERMODE; +#ifdef _DEBUG + bool m_bFLASHLIGHTDEPTHFILTERMODE; +#endif +public: + void SetFLASHLIGHTDEPTHFILTERMODE( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nFLASHLIGHTDEPTHFILTERMODE = i; +#ifdef _DEBUG + m_bFLASHLIGHTDEPTHFILTERMODE = true; +#endif + } + void SetFLASHLIGHTDEPTHFILTERMODE( bool i ) + { + m_nFLASHLIGHTDEPTHFILTERMODE = i ? 1 : 0; +#ifdef _DEBUG + m_bFLASHLIGHTDEPTHFILTERMODE = true; +#endif + } +private: + int m_nFASTPATH_NOBUMP; +#ifdef _DEBUG + bool m_bFASTPATH_NOBUMP; +#endif +public: + void SetFASTPATH_NOBUMP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFASTPATH_NOBUMP = i; +#ifdef _DEBUG + m_bFASTPATH_NOBUMP = true; +#endif + } + void SetFASTPATH_NOBUMP( bool i ) + { + m_nFASTPATH_NOBUMP = i ? 1 : 0; +#ifdef _DEBUG + m_bFASTPATH_NOBUMP = true; +#endif + } +private: + int m_nBLENDTINTBYBASEALPHA; +#ifdef _DEBUG + bool m_bBLENDTINTBYBASEALPHA; +#endif +public: + void SetBLENDTINTBYBASEALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBLENDTINTBYBASEALPHA = i; +#ifdef _DEBUG + m_bBLENDTINTBYBASEALPHA = true; +#endif + } + void SetBLENDTINTBYBASEALPHA( bool i ) + { + m_nBLENDTINTBYBASEALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bBLENDTINTBYBASEALPHA = true; +#endif + } +public: + skin_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = false; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; +#ifdef _DEBUG + m_bCUBEMAP = false; +#endif // _DEBUG + m_nCUBEMAP = 0; +#ifdef _DEBUG + m_bSELFILLUM = false; +#endif // _DEBUG + m_nSELFILLUM = 0; +#ifdef _DEBUG + m_bSELFILLUMFRESNEL = false; +#endif // _DEBUG + m_nSELFILLUMFRESNEL = 0; +#ifdef _DEBUG + m_bFLASHLIGHT = false; +#endif // _DEBUG + m_nFLASHLIGHT = 0; +#ifdef _DEBUG + m_bLIGHTWARPTEXTURE = false; +#endif // _DEBUG + m_nLIGHTWARPTEXTURE = 0; +#ifdef _DEBUG + m_bPHONGWARPTEXTURE = false; +#endif // _DEBUG + m_nPHONGWARPTEXTURE = 0; +#ifdef _DEBUG + m_bWRINKLEMAP = false; +#endif // _DEBUG + m_nWRINKLEMAP = 0; +#ifdef _DEBUG + m_bDETAIL_BLEND_MODE = false; +#endif // _DEBUG + m_nDETAIL_BLEND_MODE = 0; +#ifdef _DEBUG + m_bDETAILTEXTURE = false; +#endif // _DEBUG + m_nDETAILTEXTURE = 0; +#ifdef _DEBUG + m_bRIMLIGHT = false; +#endif // _DEBUG + m_nRIMLIGHT = 0; +#ifdef _DEBUG + m_bFLASHLIGHTDEPTHFILTERMODE = false; +#endif // _DEBUG + m_nFLASHLIGHTDEPTHFILTERMODE = 0; +#ifdef _DEBUG + m_bFASTPATH_NOBUMP = false; +#endif // _DEBUG + m_nFASTPATH_NOBUMP = 0; +#ifdef _DEBUG + m_bBLENDTINTBYBASEALPHA = false; +#endif // _DEBUG + m_nBLENDTINTBYBASEALPHA = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB && m_bCUBEMAP && m_bSELFILLUM && m_bSELFILLUMFRESNEL && m_bFLASHLIGHT && m_bLIGHTWARPTEXTURE && m_bPHONGWARPTEXTURE && m_bWRINKLEMAP && m_bDETAIL_BLEND_MODE && m_bDETAILTEXTURE && m_bRIMLIGHT && m_bFLASHLIGHTDEPTHFILTERMODE && m_bFASTPATH_NOBUMP && m_bBLENDTINTBYBASEALPHA; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 160 * m_nCONVERT_TO_SRGB ) + ( 160 * m_nCUBEMAP ) + ( 320 * m_nSELFILLUM ) + ( 640 * m_nSELFILLUMFRESNEL ) + ( 1280 * m_nFLASHLIGHT ) + ( 2560 * m_nLIGHTWARPTEXTURE ) + ( 5120 * m_nPHONGWARPTEXTURE ) + ( 10240 * m_nWRINKLEMAP ) + ( 20480 * m_nDETAIL_BLEND_MODE ) + ( 143360 * m_nDETAILTEXTURE ) + ( 286720 * m_nRIMLIGHT ) + ( 573440 * m_nFLASHLIGHTDEPTHFILTERMODE ) + ( 1720320 * m_nFASTPATH_NOBUMP ) + ( 3440640 * m_nBLENDTINTBYBASEALPHA ) + 0; + } +}; +#define shaderStaticTest_skin_ps20b psh_forgot_to_set_static_CONVERT_TO_SRGB + psh_forgot_to_set_static_CUBEMAP + psh_forgot_to_set_static_SELFILLUM + psh_forgot_to_set_static_SELFILLUMFRESNEL + psh_forgot_to_set_static_FLASHLIGHT + psh_forgot_to_set_static_LIGHTWARPTEXTURE + psh_forgot_to_set_static_PHONGWARPTEXTURE + psh_forgot_to_set_static_WRINKLEMAP + psh_forgot_to_set_static_DETAIL_BLEND_MODE + psh_forgot_to_set_static_DETAILTEXTURE + psh_forgot_to_set_static_RIMLIGHT + psh_forgot_to_set_static_FLASHLIGHTDEPTHFILTERMODE + psh_forgot_to_set_static_FASTPATH_NOBUMP + psh_forgot_to_set_static_BLENDTINTBYBASEALPHA + 0 +class skin_ps20b_Dynamic_Index +{ +private: + int m_nWRITEWATERFOGTODESTALPHA; +#ifdef _DEBUG + bool m_bWRITEWATERFOGTODESTALPHA; +#endif +public: + void SetWRITEWATERFOGTODESTALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nWRITEWATERFOGTODESTALPHA = i; +#ifdef _DEBUG + m_bWRITEWATERFOGTODESTALPHA = true; +#endif + } + void SetWRITEWATERFOGTODESTALPHA( bool i ) + { + m_nWRITEWATERFOGTODESTALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bWRITEWATERFOGTODESTALPHA = true; +#endif + } +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +private: + int m_nNUM_LIGHTS; +#ifdef _DEBUG + bool m_bNUM_LIGHTS; +#endif +public: + void SetNUM_LIGHTS( int i ) + { + Assert( i >= 0 && i <= 4 ); + m_nNUM_LIGHTS = i; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } + void SetNUM_LIGHTS( bool i ) + { + m_nNUM_LIGHTS = i ? 1 : 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } +private: + int m_nWRITE_DEPTH_TO_DESTALPHA; +#ifdef _DEBUG + bool m_bWRITE_DEPTH_TO_DESTALPHA; +#endif +public: + void SetWRITE_DEPTH_TO_DESTALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nWRITE_DEPTH_TO_DESTALPHA = i; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = true; +#endif + } + void SetWRITE_DEPTH_TO_DESTALPHA( bool i ) + { + m_nWRITE_DEPTH_TO_DESTALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = true; +#endif + } +private: + int m_nFLASHLIGHTSHADOWS; +#ifdef _DEBUG + bool m_bFLASHLIGHTSHADOWS; +#endif +public: + void SetFLASHLIGHTSHADOWS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFLASHLIGHTSHADOWS = i; +#ifdef _DEBUG + m_bFLASHLIGHTSHADOWS = true; +#endif + } + void SetFLASHLIGHTSHADOWS( bool i ) + { + m_nFLASHLIGHTSHADOWS = i ? 1 : 0; +#ifdef _DEBUG + m_bFLASHLIGHTSHADOWS = true; +#endif + } +private: + int m_nPHONG_USE_EXPONENT_FACTOR; +#ifdef _DEBUG + bool m_bPHONG_USE_EXPONENT_FACTOR; +#endif +public: + void SetPHONG_USE_EXPONENT_FACTOR( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPHONG_USE_EXPONENT_FACTOR = i; +#ifdef _DEBUG + m_bPHONG_USE_EXPONENT_FACTOR = true; +#endif + } + void SetPHONG_USE_EXPONENT_FACTOR( bool i ) + { + m_nPHONG_USE_EXPONENT_FACTOR = i ? 1 : 0; +#ifdef _DEBUG + m_bPHONG_USE_EXPONENT_FACTOR = true; +#endif + } +public: + skin_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bWRITEWATERFOGTODESTALPHA = false; +#endif // _DEBUG + m_nWRITEWATERFOGTODESTALPHA = 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = false; +#endif // _DEBUG + m_nNUM_LIGHTS = 0; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = false; +#endif // _DEBUG + m_nWRITE_DEPTH_TO_DESTALPHA = 0; +#ifdef _DEBUG + m_bFLASHLIGHTSHADOWS = false; +#endif // _DEBUG + m_nFLASHLIGHTSHADOWS = 0; +#ifdef _DEBUG + m_bPHONG_USE_EXPONENT_FACTOR = false; +#endif // _DEBUG + m_nPHONG_USE_EXPONENT_FACTOR = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bWRITEWATERFOGTODESTALPHA && m_bPIXELFOGTYPE && m_bNUM_LIGHTS && m_bWRITE_DEPTH_TO_DESTALPHA && m_bFLASHLIGHTSHADOWS && m_bPHONG_USE_EXPONENT_FACTOR; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nWRITEWATERFOGTODESTALPHA ) + ( 2 * m_nPIXELFOGTYPE ) + ( 4 * m_nNUM_LIGHTS ) + ( 20 * m_nWRITE_DEPTH_TO_DESTALPHA ) + ( 40 * m_nFLASHLIGHTSHADOWS ) + ( 80 * m_nPHONG_USE_EXPONENT_FACTOR ) + 0; + } +}; +#define shaderDynamicTest_skin_ps20b psh_forgot_to_set_dynamic_WRITEWATERFOGTODESTALPHA + psh_forgot_to_set_dynamic_PIXELFOGTYPE + psh_forgot_to_set_dynamic_NUM_LIGHTS + psh_forgot_to_set_dynamic_WRITE_DEPTH_TO_DESTALPHA + psh_forgot_to_set_dynamic_FLASHLIGHTSHADOWS + psh_forgot_to_set_dynamic_PHONG_USE_EXPONENT_FACTOR + 0 diff --git a/materialsystem/stdshaders/fxctmp9/skin_ps30.inc b/materialsystem/stdshaders/fxctmp9/skin_ps30.inc new file mode 100644 index 0000000..fc77ac6 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/skin_ps30.inc @@ -0,0 +1,537 @@ +#include "shaderlib/cshader.h" +class skin_ps30_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +private: + int m_nCUBEMAP; +#ifdef _DEBUG + bool m_bCUBEMAP; +#endif +public: + void SetCUBEMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCUBEMAP = i; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } + void SetCUBEMAP( bool i ) + { + m_nCUBEMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } +private: + int m_nSELFILLUM; +#ifdef _DEBUG + bool m_bSELFILLUM; +#endif +public: + void SetSELFILLUM( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSELFILLUM = i; +#ifdef _DEBUG + m_bSELFILLUM = true; +#endif + } + void SetSELFILLUM( bool i ) + { + m_nSELFILLUM = i ? 1 : 0; +#ifdef _DEBUG + m_bSELFILLUM = true; +#endif + } +private: + int m_nSELFILLUMFRESNEL; +#ifdef _DEBUG + bool m_bSELFILLUMFRESNEL; +#endif +public: + void SetSELFILLUMFRESNEL( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSELFILLUMFRESNEL = i; +#ifdef _DEBUG + m_bSELFILLUMFRESNEL = true; +#endif + } + void SetSELFILLUMFRESNEL( bool i ) + { + m_nSELFILLUMFRESNEL = i ? 1 : 0; +#ifdef _DEBUG + m_bSELFILLUMFRESNEL = true; +#endif + } +private: + int m_nFLASHLIGHT; +#ifdef _DEBUG + bool m_bFLASHLIGHT; +#endif +public: + void SetFLASHLIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFLASHLIGHT = i; +#ifdef _DEBUG + m_bFLASHLIGHT = true; +#endif + } + void SetFLASHLIGHT( bool i ) + { + m_nFLASHLIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bFLASHLIGHT = true; +#endif + } +private: + int m_nLIGHTWARPTEXTURE; +#ifdef _DEBUG + bool m_bLIGHTWARPTEXTURE; +#endif +public: + void SetLIGHTWARPTEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nLIGHTWARPTEXTURE = i; +#ifdef _DEBUG + m_bLIGHTWARPTEXTURE = true; +#endif + } + void SetLIGHTWARPTEXTURE( bool i ) + { + m_nLIGHTWARPTEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bLIGHTWARPTEXTURE = true; +#endif + } +private: + int m_nPHONGWARPTEXTURE; +#ifdef _DEBUG + bool m_bPHONGWARPTEXTURE; +#endif +public: + void SetPHONGWARPTEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPHONGWARPTEXTURE = i; +#ifdef _DEBUG + m_bPHONGWARPTEXTURE = true; +#endif + } + void SetPHONGWARPTEXTURE( bool i ) + { + m_nPHONGWARPTEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bPHONGWARPTEXTURE = true; +#endif + } +private: + int m_nWRINKLEMAP; +#ifdef _DEBUG + bool m_bWRINKLEMAP; +#endif +public: + void SetWRINKLEMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nWRINKLEMAP = i; +#ifdef _DEBUG + m_bWRINKLEMAP = true; +#endif + } + void SetWRINKLEMAP( bool i ) + { + m_nWRINKLEMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bWRINKLEMAP = true; +#endif + } +private: + int m_nDETAIL_BLEND_MODE; +#ifdef _DEBUG + bool m_bDETAIL_BLEND_MODE; +#endif +public: + void SetDETAIL_BLEND_MODE( int i ) + { + Assert( i >= 0 && i <= 6 ); + m_nDETAIL_BLEND_MODE = i; +#ifdef _DEBUG + m_bDETAIL_BLEND_MODE = true; +#endif + } + void SetDETAIL_BLEND_MODE( bool i ) + { + m_nDETAIL_BLEND_MODE = i ? 1 : 0; +#ifdef _DEBUG + m_bDETAIL_BLEND_MODE = true; +#endif + } +private: + int m_nDETAILTEXTURE; +#ifdef _DEBUG + bool m_bDETAILTEXTURE; +#endif +public: + void SetDETAILTEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDETAILTEXTURE = i; +#ifdef _DEBUG + m_bDETAILTEXTURE = true; +#endif + } + void SetDETAILTEXTURE( bool i ) + { + m_nDETAILTEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bDETAILTEXTURE = true; +#endif + } +private: + int m_nRIMLIGHT; +#ifdef _DEBUG + bool m_bRIMLIGHT; +#endif +public: + void SetRIMLIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nRIMLIGHT = i; +#ifdef _DEBUG + m_bRIMLIGHT = true; +#endif + } + void SetRIMLIGHT( bool i ) + { + m_nRIMLIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bRIMLIGHT = true; +#endif + } +private: + int m_nFLASHLIGHTDEPTHFILTERMODE; +#ifdef _DEBUG + bool m_bFLASHLIGHTDEPTHFILTERMODE; +#endif +public: + void SetFLASHLIGHTDEPTHFILTERMODE( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nFLASHLIGHTDEPTHFILTERMODE = i; +#ifdef _DEBUG + m_bFLASHLIGHTDEPTHFILTERMODE = true; +#endif + } + void SetFLASHLIGHTDEPTHFILTERMODE( bool i ) + { + m_nFLASHLIGHTDEPTHFILTERMODE = i ? 1 : 0; +#ifdef _DEBUG + m_bFLASHLIGHTDEPTHFILTERMODE = true; +#endif + } +private: + int m_nFASTPATH_NOBUMP; +#ifdef _DEBUG + bool m_bFASTPATH_NOBUMP; +#endif +public: + void SetFASTPATH_NOBUMP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFASTPATH_NOBUMP = i; +#ifdef _DEBUG + m_bFASTPATH_NOBUMP = true; +#endif + } + void SetFASTPATH_NOBUMP( bool i ) + { + m_nFASTPATH_NOBUMP = i ? 1 : 0; +#ifdef _DEBUG + m_bFASTPATH_NOBUMP = true; +#endif + } +private: + int m_nBLENDTINTBYBASEALPHA; +#ifdef _DEBUG + bool m_bBLENDTINTBYBASEALPHA; +#endif +public: + void SetBLENDTINTBYBASEALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBLENDTINTBYBASEALPHA = i; +#ifdef _DEBUG + m_bBLENDTINTBYBASEALPHA = true; +#endif + } + void SetBLENDTINTBYBASEALPHA( bool i ) + { + m_nBLENDTINTBYBASEALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bBLENDTINTBYBASEALPHA = true; +#endif + } +public: + skin_ps30_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = false; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; +#ifdef _DEBUG + m_bCUBEMAP = false; +#endif // _DEBUG + m_nCUBEMAP = 0; +#ifdef _DEBUG + m_bSELFILLUM = false; +#endif // _DEBUG + m_nSELFILLUM = 0; +#ifdef _DEBUG + m_bSELFILLUMFRESNEL = false; +#endif // _DEBUG + m_nSELFILLUMFRESNEL = 0; +#ifdef _DEBUG + m_bFLASHLIGHT = false; +#endif // _DEBUG + m_nFLASHLIGHT = 0; +#ifdef _DEBUG + m_bLIGHTWARPTEXTURE = false; +#endif // _DEBUG + m_nLIGHTWARPTEXTURE = 0; +#ifdef _DEBUG + m_bPHONGWARPTEXTURE = false; +#endif // _DEBUG + m_nPHONGWARPTEXTURE = 0; +#ifdef _DEBUG + m_bWRINKLEMAP = false; +#endif // _DEBUG + m_nWRINKLEMAP = 0; +#ifdef _DEBUG + m_bDETAIL_BLEND_MODE = false; +#endif // _DEBUG + m_nDETAIL_BLEND_MODE = 0; +#ifdef _DEBUG + m_bDETAILTEXTURE = false; +#endif // _DEBUG + m_nDETAILTEXTURE = 0; +#ifdef _DEBUG + m_bRIMLIGHT = false; +#endif // _DEBUG + m_nRIMLIGHT = 0; +#ifdef _DEBUG + m_bFLASHLIGHTDEPTHFILTERMODE = false; +#endif // _DEBUG + m_nFLASHLIGHTDEPTHFILTERMODE = 0; +#ifdef _DEBUG + m_bFASTPATH_NOBUMP = false; +#endif // _DEBUG + m_nFASTPATH_NOBUMP = 0; +#ifdef _DEBUG + m_bBLENDTINTBYBASEALPHA = false; +#endif // _DEBUG + m_nBLENDTINTBYBASEALPHA = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB && m_bCUBEMAP && m_bSELFILLUM && m_bSELFILLUMFRESNEL && m_bFLASHLIGHT && m_bLIGHTWARPTEXTURE && m_bPHONGWARPTEXTURE && m_bWRINKLEMAP && m_bDETAIL_BLEND_MODE && m_bDETAILTEXTURE && m_bRIMLIGHT && m_bFLASHLIGHTDEPTHFILTERMODE && m_bFASTPATH_NOBUMP && m_bBLENDTINTBYBASEALPHA; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 160 * m_nCONVERT_TO_SRGB ) + ( 160 * m_nCUBEMAP ) + ( 320 * m_nSELFILLUM ) + ( 640 * m_nSELFILLUMFRESNEL ) + ( 1280 * m_nFLASHLIGHT ) + ( 2560 * m_nLIGHTWARPTEXTURE ) + ( 5120 * m_nPHONGWARPTEXTURE ) + ( 10240 * m_nWRINKLEMAP ) + ( 20480 * m_nDETAIL_BLEND_MODE ) + ( 143360 * m_nDETAILTEXTURE ) + ( 286720 * m_nRIMLIGHT ) + ( 573440 * m_nFLASHLIGHTDEPTHFILTERMODE ) + ( 1720320 * m_nFASTPATH_NOBUMP ) + ( 3440640 * m_nBLENDTINTBYBASEALPHA ) + 0; + } +}; +#define shaderStaticTest_skin_ps30 psh_forgot_to_set_static_CONVERT_TO_SRGB + psh_forgot_to_set_static_CUBEMAP + psh_forgot_to_set_static_SELFILLUM + psh_forgot_to_set_static_SELFILLUMFRESNEL + psh_forgot_to_set_static_FLASHLIGHT + psh_forgot_to_set_static_LIGHTWARPTEXTURE + psh_forgot_to_set_static_PHONGWARPTEXTURE + psh_forgot_to_set_static_WRINKLEMAP + psh_forgot_to_set_static_DETAIL_BLEND_MODE + psh_forgot_to_set_static_DETAILTEXTURE + psh_forgot_to_set_static_RIMLIGHT + psh_forgot_to_set_static_FLASHLIGHTDEPTHFILTERMODE + psh_forgot_to_set_static_FASTPATH_NOBUMP + psh_forgot_to_set_static_BLENDTINTBYBASEALPHA + 0 +class skin_ps30_Dynamic_Index +{ +private: + int m_nWRITEWATERFOGTODESTALPHA; +#ifdef _DEBUG + bool m_bWRITEWATERFOGTODESTALPHA; +#endif +public: + void SetWRITEWATERFOGTODESTALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nWRITEWATERFOGTODESTALPHA = i; +#ifdef _DEBUG + m_bWRITEWATERFOGTODESTALPHA = true; +#endif + } + void SetWRITEWATERFOGTODESTALPHA( bool i ) + { + m_nWRITEWATERFOGTODESTALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bWRITEWATERFOGTODESTALPHA = true; +#endif + } +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +private: + int m_nNUM_LIGHTS; +#ifdef _DEBUG + bool m_bNUM_LIGHTS; +#endif +public: + void SetNUM_LIGHTS( int i ) + { + Assert( i >= 0 && i <= 4 ); + m_nNUM_LIGHTS = i; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } + void SetNUM_LIGHTS( bool i ) + { + m_nNUM_LIGHTS = i ? 1 : 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } +private: + int m_nWRITE_DEPTH_TO_DESTALPHA; +#ifdef _DEBUG + bool m_bWRITE_DEPTH_TO_DESTALPHA; +#endif +public: + void SetWRITE_DEPTH_TO_DESTALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nWRITE_DEPTH_TO_DESTALPHA = i; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = true; +#endif + } + void SetWRITE_DEPTH_TO_DESTALPHA( bool i ) + { + m_nWRITE_DEPTH_TO_DESTALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = true; +#endif + } +private: + int m_nFLASHLIGHTSHADOWS; +#ifdef _DEBUG + bool m_bFLASHLIGHTSHADOWS; +#endif +public: + void SetFLASHLIGHTSHADOWS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFLASHLIGHTSHADOWS = i; +#ifdef _DEBUG + m_bFLASHLIGHTSHADOWS = true; +#endif + } + void SetFLASHLIGHTSHADOWS( bool i ) + { + m_nFLASHLIGHTSHADOWS = i ? 1 : 0; +#ifdef _DEBUG + m_bFLASHLIGHTSHADOWS = true; +#endif + } +private: + int m_nPHONG_USE_EXPONENT_FACTOR; +#ifdef _DEBUG + bool m_bPHONG_USE_EXPONENT_FACTOR; +#endif +public: + void SetPHONG_USE_EXPONENT_FACTOR( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPHONG_USE_EXPONENT_FACTOR = i; +#ifdef _DEBUG + m_bPHONG_USE_EXPONENT_FACTOR = true; +#endif + } + void SetPHONG_USE_EXPONENT_FACTOR( bool i ) + { + m_nPHONG_USE_EXPONENT_FACTOR = i ? 1 : 0; +#ifdef _DEBUG + m_bPHONG_USE_EXPONENT_FACTOR = true; +#endif + } +public: + skin_ps30_Dynamic_Index() + { +#ifdef _DEBUG + m_bWRITEWATERFOGTODESTALPHA = false; +#endif // _DEBUG + m_nWRITEWATERFOGTODESTALPHA = 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = false; +#endif // _DEBUG + m_nNUM_LIGHTS = 0; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = false; +#endif // _DEBUG + m_nWRITE_DEPTH_TO_DESTALPHA = 0; +#ifdef _DEBUG + m_bFLASHLIGHTSHADOWS = false; +#endif // _DEBUG + m_nFLASHLIGHTSHADOWS = 0; +#ifdef _DEBUG + m_bPHONG_USE_EXPONENT_FACTOR = false; +#endif // _DEBUG + m_nPHONG_USE_EXPONENT_FACTOR = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bWRITEWATERFOGTODESTALPHA && m_bPIXELFOGTYPE && m_bNUM_LIGHTS && m_bWRITE_DEPTH_TO_DESTALPHA && m_bFLASHLIGHTSHADOWS && m_bPHONG_USE_EXPONENT_FACTOR; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nWRITEWATERFOGTODESTALPHA ) + ( 2 * m_nPIXELFOGTYPE ) + ( 4 * m_nNUM_LIGHTS ) + ( 20 * m_nWRITE_DEPTH_TO_DESTALPHA ) + ( 40 * m_nFLASHLIGHTSHADOWS ) + ( 80 * m_nPHONG_USE_EXPONENT_FACTOR ) + 0; + } +}; +#define shaderDynamicTest_skin_ps30 psh_forgot_to_set_dynamic_WRITEWATERFOGTODESTALPHA + psh_forgot_to_set_dynamic_PIXELFOGTYPE + psh_forgot_to_set_dynamic_NUM_LIGHTS + psh_forgot_to_set_dynamic_WRITE_DEPTH_TO_DESTALPHA + psh_forgot_to_set_dynamic_FLASHLIGHTSHADOWS + psh_forgot_to_set_dynamic_PHONG_USE_EXPONENT_FACTOR + 0 diff --git a/materialsystem/stdshaders/fxctmp9/skin_ps30b.inc b/materialsystem/stdshaders/fxctmp9/skin_ps30b.inc new file mode 100644 index 0000000..d94bb09 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/skin_ps30b.inc @@ -0,0 +1,387 @@ +#include "shaderlib/cshader.h" +class skin_ps30b_Static_Index +{ +private: + int m_nCUBEMAP; +#ifdef _DEBUG + bool m_bCUBEMAP; +#endif +public: + void SetCUBEMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCUBEMAP = i; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } + void SetCUBEMAP( bool i ) + { + m_nCUBEMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } +private: + int m_nSELFILLUM; +#ifdef _DEBUG + bool m_bSELFILLUM; +#endif +public: + void SetSELFILLUM( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSELFILLUM = i; +#ifdef _DEBUG + m_bSELFILLUM = true; +#endif + } + void SetSELFILLUM( bool i ) + { + m_nSELFILLUM = i ? 1 : 0; +#ifdef _DEBUG + m_bSELFILLUM = true; +#endif + } +private: + int m_nSELFILLUMFRESNEL; +#ifdef _DEBUG + bool m_bSELFILLUMFRESNEL; +#endif +public: + void SetSELFILLUMFRESNEL( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSELFILLUMFRESNEL = i; +#ifdef _DEBUG + m_bSELFILLUMFRESNEL = true; +#endif + } + void SetSELFILLUMFRESNEL( bool i ) + { + m_nSELFILLUMFRESNEL = i ? 1 : 0; +#ifdef _DEBUG + m_bSELFILLUMFRESNEL = true; +#endif + } +private: + int m_nFLASHLIGHT; +#ifdef _DEBUG + bool m_bFLASHLIGHT; +#endif +public: + void SetFLASHLIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFLASHLIGHT = i; +#ifdef _DEBUG + m_bFLASHLIGHT = true; +#endif + } + void SetFLASHLIGHT( bool i ) + { + m_nFLASHLIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bFLASHLIGHT = true; +#endif + } +private: + int m_nLIGHTWARPTEXTURE; +#ifdef _DEBUG + bool m_bLIGHTWARPTEXTURE; +#endif +public: + void SetLIGHTWARPTEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nLIGHTWARPTEXTURE = i; +#ifdef _DEBUG + m_bLIGHTWARPTEXTURE = true; +#endif + } + void SetLIGHTWARPTEXTURE( bool i ) + { + m_nLIGHTWARPTEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bLIGHTWARPTEXTURE = true; +#endif + } +private: + int m_nPHONGEXPONENTTEXTURE; +#ifdef _DEBUG + bool m_bPHONGEXPONENTTEXTURE; +#endif +public: + void SetPHONGEXPONENTTEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPHONGEXPONENTTEXTURE = i; +#ifdef _DEBUG + m_bPHONGEXPONENTTEXTURE = true; +#endif + } + void SetPHONGEXPONENTTEXTURE( bool i ) + { + m_nPHONGEXPONENTTEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bPHONGEXPONENTTEXTURE = true; +#endif + } +private: + int m_nPHONGWARPTEXTURE; +#ifdef _DEBUG + bool m_bPHONGWARPTEXTURE; +#endif +public: + void SetPHONGWARPTEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPHONGWARPTEXTURE = i; +#ifdef _DEBUG + m_bPHONGWARPTEXTURE = true; +#endif + } + void SetPHONGWARPTEXTURE( bool i ) + { + m_nPHONGWARPTEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bPHONGWARPTEXTURE = true; +#endif + } +private: + int m_nWRINKLEMAP; +#ifdef _DEBUG + bool m_bWRINKLEMAP; +#endif +public: + void SetWRINKLEMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nWRINKLEMAP = i; +#ifdef _DEBUG + m_bWRINKLEMAP = true; +#endif + } + void SetWRINKLEMAP( bool i ) + { + m_nWRINKLEMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bWRINKLEMAP = true; +#endif + } +private: + int m_nDETAIL_BLEND_MODE; +#ifdef _DEBUG + bool m_bDETAIL_BLEND_MODE; +#endif +public: + void SetDETAIL_BLEND_MODE( int i ) + { + Assert( i >= 0 && i <= 6 ); + m_nDETAIL_BLEND_MODE = i; +#ifdef _DEBUG + m_bDETAIL_BLEND_MODE = true; +#endif + } + void SetDETAIL_BLEND_MODE( bool i ) + { + m_nDETAIL_BLEND_MODE = i ? 1 : 0; +#ifdef _DEBUG + m_bDETAIL_BLEND_MODE = true; +#endif + } +private: + int m_nDETAILTEXTURE; +#ifdef _DEBUG + bool m_bDETAILTEXTURE; +#endif +public: + void SetDETAILTEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDETAILTEXTURE = i; +#ifdef _DEBUG + m_bDETAILTEXTURE = true; +#endif + } + void SetDETAILTEXTURE( bool i ) + { + m_nDETAILTEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bDETAILTEXTURE = true; +#endif + } +private: + int m_nRIMLIGHT; +#ifdef _DEBUG + bool m_bRIMLIGHT; +#endif +public: + void SetRIMLIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nRIMLIGHT = i; +#ifdef _DEBUG + m_bRIMLIGHT = true; +#endif + } + void SetRIMLIGHT( bool i ) + { + m_nRIMLIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bRIMLIGHT = true; +#endif + } +public: + skin_ps30b_Static_Index( ) + { +#ifdef _DEBUG + m_bCUBEMAP = false; +#endif // _DEBUG + m_nCUBEMAP = 0; +#ifdef _DEBUG + m_bSELFILLUM = false; +#endif // _DEBUG + m_nSELFILLUM = 0; +#ifdef _DEBUG + m_bSELFILLUMFRESNEL = false; +#endif // _DEBUG + m_nSELFILLUMFRESNEL = 0; +#ifdef _DEBUG + m_bFLASHLIGHT = false; +#endif // _DEBUG + m_nFLASHLIGHT = 0; +#ifdef _DEBUG + m_bLIGHTWARPTEXTURE = false; +#endif // _DEBUG + m_nLIGHTWARPTEXTURE = 0; +#ifdef _DEBUG + m_bPHONGEXPONENTTEXTURE = false; +#endif // _DEBUG + m_nPHONGEXPONENTTEXTURE = 0; +#ifdef _DEBUG + m_bPHONGWARPTEXTURE = false; +#endif // _DEBUG + m_nPHONGWARPTEXTURE = 0; +#ifdef _DEBUG + m_bWRINKLEMAP = false; +#endif // _DEBUG + m_nWRINKLEMAP = 0; +#ifdef _DEBUG + m_bDETAIL_BLEND_MODE = false; +#endif // _DEBUG + m_nDETAIL_BLEND_MODE = 0; +#ifdef _DEBUG + m_bDETAILTEXTURE = false; +#endif // _DEBUG + m_nDETAILTEXTURE = 0; +#ifdef _DEBUG + m_bRIMLIGHT = false; +#endif // _DEBUG + m_nRIMLIGHT = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCUBEMAP && m_bSELFILLUM && m_bSELFILLUMFRESNEL && m_bFLASHLIGHT && m_bLIGHTWARPTEXTURE && m_bPHONGEXPONENTTEXTURE && m_bPHONGWARPTEXTURE && m_bWRINKLEMAP && m_bDETAIL_BLEND_MODE && m_bDETAILTEXTURE && m_bRIMLIGHT; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 20 * m_nCUBEMAP ) + ( 40 * m_nSELFILLUM ) + ( 80 * m_nSELFILLUMFRESNEL ) + ( 160 * m_nFLASHLIGHT ) + ( 320 * m_nLIGHTWARPTEXTURE ) + ( 640 * m_nPHONGEXPONENTTEXTURE ) + ( 1280 * m_nPHONGWARPTEXTURE ) + ( 2560 * m_nWRINKLEMAP ) + ( 5120 * m_nDETAIL_BLEND_MODE ) + ( 35840 * m_nDETAILTEXTURE ) + ( 71680 * m_nRIMLIGHT ) + 0; + } +}; +#define shaderStaticTest_skin_ps30b psh_forgot_to_set_static_CUBEMAP + psh_forgot_to_set_static_SELFILLUM + psh_forgot_to_set_static_SELFILLUMFRESNEL + psh_forgot_to_set_static_FLASHLIGHT + psh_forgot_to_set_static_LIGHTWARPTEXTURE + psh_forgot_to_set_static_PHONGEXPONENTTEXTURE + psh_forgot_to_set_static_PHONGWARPTEXTURE + psh_forgot_to_set_static_WRINKLEMAP + psh_forgot_to_set_static_DETAIL_BLEND_MODE + psh_forgot_to_set_static_DETAILTEXTURE + psh_forgot_to_set_static_RIMLIGHT + 0 +class skin_ps30b_Dynamic_Index +{ +private: + int m_nWRITEWATERFOGTODESTALPHA; +#ifdef _DEBUG + bool m_bWRITEWATERFOGTODESTALPHA; +#endif +public: + void SetWRITEWATERFOGTODESTALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nWRITEWATERFOGTODESTALPHA = i; +#ifdef _DEBUG + m_bWRITEWATERFOGTODESTALPHA = true; +#endif + } + void SetWRITEWATERFOGTODESTALPHA( bool i ) + { + m_nWRITEWATERFOGTODESTALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bWRITEWATERFOGTODESTALPHA = true; +#endif + } +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +private: + int m_nNUM_LIGHTS; +#ifdef _DEBUG + bool m_bNUM_LIGHTS; +#endif +public: + void SetNUM_LIGHTS( int i ) + { + Assert( i >= 0 && i <= 4 ); + m_nNUM_LIGHTS = i; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } + void SetNUM_LIGHTS( bool i ) + { + m_nNUM_LIGHTS = i ? 1 : 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } +public: + skin_ps30b_Dynamic_Index() + { +#ifdef _DEBUG + m_bWRITEWATERFOGTODESTALPHA = false; +#endif // _DEBUG + m_nWRITEWATERFOGTODESTALPHA = 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = false; +#endif // _DEBUG + m_nNUM_LIGHTS = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bWRITEWATERFOGTODESTALPHA && m_bPIXELFOGTYPE && m_bNUM_LIGHTS; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nWRITEWATERFOGTODESTALPHA ) + ( 2 * m_nPIXELFOGTYPE ) + ( 4 * m_nNUM_LIGHTS ) + 0; + } +}; +#define shaderDynamicTest_skin_ps30b psh_forgot_to_set_dynamic_WRITEWATERFOGTODESTALPHA + psh_forgot_to_set_dynamic_PIXELFOGTYPE + psh_forgot_to_set_dynamic_NUM_LIGHTS + 0 diff --git a/materialsystem/stdshaders/fxctmp9/skin_vs20.inc b/materialsystem/stdshaders/fxctmp9/skin_vs20.inc new file mode 100644 index 0000000..5c8ee4d --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/skin_vs20.inc @@ -0,0 +1,187 @@ +#include "shaderlib/cshader.h" +class skin_vs20_Static_Index +{ +private: + int m_nUSE_STATIC_CONTROL_FLOW; +#ifdef _DEBUG + bool m_bUSE_STATIC_CONTROL_FLOW; +#endif +public: + void SetUSE_STATIC_CONTROL_FLOW( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nUSE_STATIC_CONTROL_FLOW = i; +#ifdef _DEBUG + m_bUSE_STATIC_CONTROL_FLOW = true; +#endif + } + void SetUSE_STATIC_CONTROL_FLOW( bool i ) + { + m_nUSE_STATIC_CONTROL_FLOW = i ? 1 : 0; +#ifdef _DEBUG + m_bUSE_STATIC_CONTROL_FLOW = true; +#endif + } +public: + skin_vs20_Static_Index( ) + { +#ifdef _DEBUG + m_bUSE_STATIC_CONTROL_FLOW = false; +#endif // _DEBUG + m_nUSE_STATIC_CONTROL_FLOW = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bUSE_STATIC_CONTROL_FLOW; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 48 * m_nUSE_STATIC_CONTROL_FLOW ) + 0; + } +}; +#define shaderStaticTest_skin_vs20 vsh_forgot_to_set_static_USE_STATIC_CONTROL_FLOW + 0 +class skin_vs20_Dynamic_Index +{ +private: + int m_nCOMPRESSED_VERTS; +#ifdef _DEBUG + bool m_bCOMPRESSED_VERTS; +#endif +public: + void SetCOMPRESSED_VERTS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOMPRESSED_VERTS = i; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } + void SetCOMPRESSED_VERTS( bool i ) + { + m_nCOMPRESSED_VERTS = i ? 1 : 0; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +private: + int m_nLIGHTING_PREVIEW; +#ifdef _DEBUG + bool m_bLIGHTING_PREVIEW; +#endif +public: + void SetLIGHTING_PREVIEW( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nLIGHTING_PREVIEW = i; +#ifdef _DEBUG + m_bLIGHTING_PREVIEW = true; +#endif + } + void SetLIGHTING_PREVIEW( bool i ) + { + m_nLIGHTING_PREVIEW = i ? 1 : 0; +#ifdef _DEBUG + m_bLIGHTING_PREVIEW = true; +#endif + } +private: + int m_nNUM_LIGHTS; +#ifdef _DEBUG + bool m_bNUM_LIGHTS; +#endif +public: + void SetNUM_LIGHTS( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nNUM_LIGHTS = i; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } + void SetNUM_LIGHTS( bool i ) + { + m_nNUM_LIGHTS = i ? 1 : 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } +public: + skin_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = false; +#endif // _DEBUG + m_nCOMPRESSED_VERTS = 0; +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; +#ifdef _DEBUG + m_bLIGHTING_PREVIEW = false; +#endif // _DEBUG + m_nLIGHTING_PREVIEW = 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = false; +#endif // _DEBUG + m_nNUM_LIGHTS = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bCOMPRESSED_VERTS && m_bDOWATERFOG && m_bSKINNING && m_bLIGHTING_PREVIEW && m_bNUM_LIGHTS; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCOMPRESSED_VERTS ) + ( 2 * m_nDOWATERFOG ) + ( 4 * m_nSKINNING ) + ( 8 * m_nLIGHTING_PREVIEW ) + ( 16 * m_nNUM_LIGHTS ) + 0; + } +}; +#define shaderDynamicTest_skin_vs20 vsh_forgot_to_set_dynamic_COMPRESSED_VERTS + vsh_forgot_to_set_dynamic_DOWATERFOG + vsh_forgot_to_set_dynamic_SKINNING + vsh_forgot_to_set_dynamic_LIGHTING_PREVIEW + vsh_forgot_to_set_dynamic_NUM_LIGHTS + 0 diff --git a/materialsystem/stdshaders/fxctmp9/skin_vs30.inc b/materialsystem/stdshaders/fxctmp9/skin_vs30.inc new file mode 100644 index 0000000..78ccdea --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/skin_vs30.inc @@ -0,0 +1,187 @@ +#include "shaderlib/cshader.h" +class skin_vs30_Static_Index +{ +private: + int m_nDECAL; +#ifdef _DEBUG + bool m_bDECAL; +#endif +public: + void SetDECAL( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDECAL = i; +#ifdef _DEBUG + m_bDECAL = true; +#endif + } + void SetDECAL( bool i ) + { + m_nDECAL = i ? 1 : 0; +#ifdef _DEBUG + m_bDECAL = true; +#endif + } +public: + skin_vs30_Static_Index( ) + { +#ifdef _DEBUG + m_bDECAL = false; +#endif // _DEBUG + m_nDECAL = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bDECAL; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 32 * m_nDECAL ) + 0; + } +}; +#define shaderStaticTest_skin_vs30 vsh_forgot_to_set_static_DECAL + 0 +class skin_vs30_Dynamic_Index +{ +private: + int m_nCOMPRESSED_VERTS; +#ifdef _DEBUG + bool m_bCOMPRESSED_VERTS; +#endif +public: + void SetCOMPRESSED_VERTS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOMPRESSED_VERTS = i; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } + void SetCOMPRESSED_VERTS( bool i ) + { + m_nCOMPRESSED_VERTS = i ? 1 : 0; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +private: + int m_nLIGHTING_PREVIEW; +#ifdef _DEBUG + bool m_bLIGHTING_PREVIEW; +#endif +public: + void SetLIGHTING_PREVIEW( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nLIGHTING_PREVIEW = i; +#ifdef _DEBUG + m_bLIGHTING_PREVIEW = true; +#endif + } + void SetLIGHTING_PREVIEW( bool i ) + { + m_nLIGHTING_PREVIEW = i ? 1 : 0; +#ifdef _DEBUG + m_bLIGHTING_PREVIEW = true; +#endif + } +private: + int m_nMORPHING; +#ifdef _DEBUG + bool m_bMORPHING; +#endif +public: + void SetMORPHING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nMORPHING = i; +#ifdef _DEBUG + m_bMORPHING = true; +#endif + } + void SetMORPHING( bool i ) + { + m_nMORPHING = i ? 1 : 0; +#ifdef _DEBUG + m_bMORPHING = true; +#endif + } +public: + skin_vs30_Dynamic_Index() + { +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = false; +#endif // _DEBUG + m_nCOMPRESSED_VERTS = 0; +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; +#ifdef _DEBUG + m_bLIGHTING_PREVIEW = false; +#endif // _DEBUG + m_nLIGHTING_PREVIEW = 0; +#ifdef _DEBUG + m_bMORPHING = false; +#endif // _DEBUG + m_nMORPHING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bCOMPRESSED_VERTS && m_bDOWATERFOG && m_bSKINNING && m_bLIGHTING_PREVIEW && m_bMORPHING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCOMPRESSED_VERTS ) + ( 2 * m_nDOWATERFOG ) + ( 4 * m_nSKINNING ) + ( 8 * m_nLIGHTING_PREVIEW ) + ( 16 * m_nMORPHING ) + 0; + } +}; +#define shaderDynamicTest_skin_vs30 vsh_forgot_to_set_dynamic_COMPRESSED_VERTS + vsh_forgot_to_set_dynamic_DOWATERFOG + vsh_forgot_to_set_dynamic_SKINNING + vsh_forgot_to_set_dynamic_LIGHTING_PREVIEW + vsh_forgot_to_set_dynamic_MORPHING + 0 diff --git a/materialsystem/stdshaders/fxctmp9/sky_hdr_compressed_ps20.inc b/materialsystem/stdshaders/fxctmp9/sky_hdr_compressed_ps20.inc new file mode 100644 index 0000000..d968c6c --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/sky_hdr_compressed_ps20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class sky_hdr_compressed_ps20_Static_Index +{ +public: + sky_hdr_compressed_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_sky_hdr_compressed_ps20 0 +class sky_hdr_compressed_ps20_Dynamic_Index +{ +public: + sky_hdr_compressed_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_sky_hdr_compressed_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9/sky_hdr_compressed_ps20b.inc b/materialsystem/stdshaders/fxctmp9/sky_hdr_compressed_ps20b.inc new file mode 100644 index 0000000..e3ec509 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/sky_hdr_compressed_ps20b.inc @@ -0,0 +1,87 @@ +#include "shaderlib/cshader.h" +class sky_hdr_compressed_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + sky_hdr_compressed_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_sky_hdr_compressed_ps20b 0 +class sky_hdr_compressed_ps20b_Dynamic_Index +{ +private: + int m_nWRITE_DEPTH_TO_DESTALPHA; +#ifdef _DEBUG + bool m_bWRITE_DEPTH_TO_DESTALPHA; +#endif +public: + void SetWRITE_DEPTH_TO_DESTALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nWRITE_DEPTH_TO_DESTALPHA = i; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = true; +#endif + } + void SetWRITE_DEPTH_TO_DESTALPHA( bool i ) + { + m_nWRITE_DEPTH_TO_DESTALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = true; +#endif + } +public: + sky_hdr_compressed_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = false; +#endif // _DEBUG + m_nWRITE_DEPTH_TO_DESTALPHA = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bWRITE_DEPTH_TO_DESTALPHA; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nWRITE_DEPTH_TO_DESTALPHA ) + 0; + } +}; +#define shaderDynamicTest_sky_hdr_compressed_ps20b psh_forgot_to_set_dynamic_WRITE_DEPTH_TO_DESTALPHA + 0 diff --git a/materialsystem/stdshaders/fxctmp9/sky_hdr_compressed_rgbs_ps20.inc b/materialsystem/stdshaders/fxctmp9/sky_hdr_compressed_rgbs_ps20.inc new file mode 100644 index 0000000..5b5777a --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/sky_hdr_compressed_rgbs_ps20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class sky_hdr_compressed_rgbs_ps20_Static_Index +{ +public: + sky_hdr_compressed_rgbs_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_sky_hdr_compressed_rgbs_ps20 0 +class sky_hdr_compressed_rgbs_ps20_Dynamic_Index +{ +public: + sky_hdr_compressed_rgbs_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_sky_hdr_compressed_rgbs_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9/sky_hdr_compressed_rgbs_ps20b.inc b/materialsystem/stdshaders/fxctmp9/sky_hdr_compressed_rgbs_ps20b.inc new file mode 100644 index 0000000..7c3240a --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/sky_hdr_compressed_rgbs_ps20b.inc @@ -0,0 +1,87 @@ +#include "shaderlib/cshader.h" +class sky_hdr_compressed_rgbs_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + sky_hdr_compressed_rgbs_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_sky_hdr_compressed_rgbs_ps20b 0 +class sky_hdr_compressed_rgbs_ps20b_Dynamic_Index +{ +private: + int m_nWRITE_DEPTH_TO_DESTALPHA; +#ifdef _DEBUG + bool m_bWRITE_DEPTH_TO_DESTALPHA; +#endif +public: + void SetWRITE_DEPTH_TO_DESTALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nWRITE_DEPTH_TO_DESTALPHA = i; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = true; +#endif + } + void SetWRITE_DEPTH_TO_DESTALPHA( bool i ) + { + m_nWRITE_DEPTH_TO_DESTALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = true; +#endif + } +public: + sky_hdr_compressed_rgbs_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = false; +#endif // _DEBUG + m_nWRITE_DEPTH_TO_DESTALPHA = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bWRITE_DEPTH_TO_DESTALPHA; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nWRITE_DEPTH_TO_DESTALPHA ) + 0; + } +}; +#define shaderDynamicTest_sky_hdr_compressed_rgbs_ps20b psh_forgot_to_set_dynamic_WRITE_DEPTH_TO_DESTALPHA + 0 diff --git a/materialsystem/stdshaders/fxctmp9/sky_ps20.inc b/materialsystem/stdshaders/fxctmp9/sky_ps20.inc new file mode 100644 index 0000000..ce7c66b --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/sky_ps20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class sky_ps20_Static_Index +{ +public: + sky_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_sky_ps20 0 +class sky_ps20_Dynamic_Index +{ +public: + sky_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_sky_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9/sky_ps20b.inc b/materialsystem/stdshaders/fxctmp9/sky_ps20b.inc new file mode 100644 index 0000000..63e4c1b --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/sky_ps20b.inc @@ -0,0 +1,87 @@ +#include "shaderlib/cshader.h" +class sky_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + sky_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_sky_ps20b 0 +class sky_ps20b_Dynamic_Index +{ +private: + int m_nWRITE_DEPTH_TO_DESTALPHA; +#ifdef _DEBUG + bool m_bWRITE_DEPTH_TO_DESTALPHA; +#endif +public: + void SetWRITE_DEPTH_TO_DESTALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nWRITE_DEPTH_TO_DESTALPHA = i; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = true; +#endif + } + void SetWRITE_DEPTH_TO_DESTALPHA( bool i ) + { + m_nWRITE_DEPTH_TO_DESTALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = true; +#endif + } +public: + sky_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = false; +#endif // _DEBUG + m_nWRITE_DEPTH_TO_DESTALPHA = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bWRITE_DEPTH_TO_DESTALPHA; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nWRITE_DEPTH_TO_DESTALPHA ) + 0; + } +}; +#define shaderDynamicTest_sky_ps20b psh_forgot_to_set_dynamic_WRITE_DEPTH_TO_DESTALPHA + 0 diff --git a/materialsystem/stdshaders/fxctmp9/sky_vs20.inc b/materialsystem/stdshaders/fxctmp9/sky_vs20.inc new file mode 100644 index 0000000..546b1d9 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/sky_vs20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class sky_vs20_Static_Index +{ +public: + sky_vs20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_sky_vs20 0 +class sky_vs20_Dynamic_Index +{ +public: + sky_vs20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_sky_vs20 0 diff --git a/materialsystem/stdshaders/fxctmp9/splinecard_vs11.inc b/materialsystem/stdshaders/fxctmp9/splinecard_vs11.inc new file mode 100644 index 0000000..aa16481 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/splinecard_vs11.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class splinecard_vs11_Static_Index +{ +public: + splinecard_vs11_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_splinecard_vs11 0 +class splinecard_vs11_Dynamic_Index +{ +public: + splinecard_vs11_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_splinecard_vs11 0 diff --git a/materialsystem/stdshaders/fxctmp9/splinecard_vs20.inc b/materialsystem/stdshaders/fxctmp9/splinecard_vs20.inc new file mode 100644 index 0000000..97c6b1e --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/splinecard_vs20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class splinecard_vs20_Static_Index +{ +public: + splinecard_vs20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_splinecard_vs20 0 +class splinecard_vs20_Dynamic_Index +{ +public: + splinecard_vs20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_splinecard_vs20 0 diff --git a/materialsystem/stdshaders/fxctmp9/sprite_ps20.inc b/materialsystem/stdshaders/fxctmp9/sprite_ps20.inc new file mode 100644 index 0000000..b047cb0 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/sprite_ps20.inc @@ -0,0 +1,187 @@ +#include "shaderlib/cshader.h" +class sprite_ps20_Static_Index +{ +private: + int m_nVERTEXCOLOR; +#ifdef _DEBUG + bool m_bVERTEXCOLOR; +#endif +public: + void SetVERTEXCOLOR( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nVERTEXCOLOR = i; +#ifdef _DEBUG + m_bVERTEXCOLOR = true; +#endif + } + void SetVERTEXCOLOR( bool i ) + { + m_nVERTEXCOLOR = i ? 1 : 0; +#ifdef _DEBUG + m_bVERTEXCOLOR = true; +#endif + } +private: + int m_nCONSTANTCOLOR; +#ifdef _DEBUG + bool m_bCONSTANTCOLOR; +#endif +public: + void SetCONSTANTCOLOR( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONSTANTCOLOR = i; +#ifdef _DEBUG + m_bCONSTANTCOLOR = true; +#endif + } + void SetCONSTANTCOLOR( bool i ) + { + m_nCONSTANTCOLOR = i ? 1 : 0; +#ifdef _DEBUG + m_bCONSTANTCOLOR = true; +#endif + } +private: + int m_nHDRTYPE; +#ifdef _DEBUG + bool m_bHDRTYPE; +#endif +public: + void SetHDRTYPE( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nHDRTYPE = i; +#ifdef _DEBUG + m_bHDRTYPE = true; +#endif + } + void SetHDRTYPE( bool i ) + { + m_nHDRTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bHDRTYPE = true; +#endif + } +private: + int m_nSRGB; +#ifdef _DEBUG + bool m_bSRGB; +#endif +public: + void SetSRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSRGB = i; +#ifdef _DEBUG + m_bSRGB = true; +#endif + } + void SetSRGB( bool i ) + { + m_nSRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bSRGB = true; +#endif + } +public: + sprite_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bVERTEXCOLOR = false; +#endif // _DEBUG + m_nVERTEXCOLOR = 0; +#ifdef _DEBUG + m_bCONSTANTCOLOR = false; +#endif // _DEBUG + m_nCONSTANTCOLOR = 0; +#ifdef _DEBUG + m_bHDRTYPE = false; +#endif // _DEBUG + m_nHDRTYPE = 0; +#ifdef _DEBUG + m_bSRGB = false; +#endif // _DEBUG + m_nSRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bVERTEXCOLOR && m_bCONSTANTCOLOR && m_bHDRTYPE && m_bSRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 4 * m_nVERTEXCOLOR ) + ( 8 * m_nCONSTANTCOLOR ) + ( 16 * m_nHDRTYPE ) + ( 48 * m_nSRGB ) + 0; + } +}; +#define shaderStaticTest_sprite_ps20 psh_forgot_to_set_static_VERTEXCOLOR + psh_forgot_to_set_static_CONSTANTCOLOR + psh_forgot_to_set_static_HDRTYPE + psh_forgot_to_set_static_SRGB + 0 +class sprite_ps20_Dynamic_Index +{ +private: + int m_nHDRENABLED; +#ifdef _DEBUG + bool m_bHDRENABLED; +#endif +public: + void SetHDRENABLED( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHDRENABLED = i; +#ifdef _DEBUG + m_bHDRENABLED = true; +#endif + } + void SetHDRENABLED( bool i ) + { + m_nHDRENABLED = i ? 1 : 0; +#ifdef _DEBUG + m_bHDRENABLED = true; +#endif + } +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + sprite_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bHDRENABLED = false; +#endif // _DEBUG + m_nHDRENABLED = 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bHDRENABLED && m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nHDRENABLED ) + ( 2 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_sprite_ps20 psh_forgot_to_set_dynamic_HDRENABLED + psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9/sprite_ps20b.inc b/materialsystem/stdshaders/fxctmp9/sprite_ps20b.inc new file mode 100644 index 0000000..a7f0126 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/sprite_ps20b.inc @@ -0,0 +1,237 @@ +#include "shaderlib/cshader.h" +class sprite_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +private: + int m_nVERTEXCOLOR; +#ifdef _DEBUG + bool m_bVERTEXCOLOR; +#endif +public: + void SetVERTEXCOLOR( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nVERTEXCOLOR = i; +#ifdef _DEBUG + m_bVERTEXCOLOR = true; +#endif + } + void SetVERTEXCOLOR( bool i ) + { + m_nVERTEXCOLOR = i ? 1 : 0; +#ifdef _DEBUG + m_bVERTEXCOLOR = true; +#endif + } +private: + int m_nCONSTANTCOLOR; +#ifdef _DEBUG + bool m_bCONSTANTCOLOR; +#endif +public: + void SetCONSTANTCOLOR( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONSTANTCOLOR = i; +#ifdef _DEBUG + m_bCONSTANTCOLOR = true; +#endif + } + void SetCONSTANTCOLOR( bool i ) + { + m_nCONSTANTCOLOR = i ? 1 : 0; +#ifdef _DEBUG + m_bCONSTANTCOLOR = true; +#endif + } +private: + int m_nHDRTYPE; +#ifdef _DEBUG + bool m_bHDRTYPE; +#endif +public: + void SetHDRTYPE( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nHDRTYPE = i; +#ifdef _DEBUG + m_bHDRTYPE = true; +#endif + } + void SetHDRTYPE( bool i ) + { + m_nHDRTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bHDRTYPE = true; +#endif + } +private: + int m_nSRGB; +#ifdef _DEBUG + bool m_bSRGB; +#endif +public: + void SetSRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSRGB = i; +#ifdef _DEBUG + m_bSRGB = true; +#endif + } + void SetSRGB( bool i ) + { + m_nSRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bSRGB = true; +#endif + } +private: + int m_nSRGB_OUTPUT_ADAPTER; +#ifdef _DEBUG + bool m_bSRGB_OUTPUT_ADAPTER; +#endif +public: + void SetSRGB_OUTPUT_ADAPTER( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSRGB_OUTPUT_ADAPTER = i; +#ifdef _DEBUG + m_bSRGB_OUTPUT_ADAPTER = true; +#endif + } + void SetSRGB_OUTPUT_ADAPTER( bool i ) + { + m_nSRGB_OUTPUT_ADAPTER = i ? 1 : 0; +#ifdef _DEBUG + m_bSRGB_OUTPUT_ADAPTER = true; +#endif + } +public: + sprite_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); +#ifdef _DEBUG + m_bVERTEXCOLOR = false; +#endif // _DEBUG + m_nVERTEXCOLOR = 0; +#ifdef _DEBUG + m_bCONSTANTCOLOR = false; +#endif // _DEBUG + m_nCONSTANTCOLOR = 0; +#ifdef _DEBUG + m_bHDRTYPE = false; +#endif // _DEBUG + m_nHDRTYPE = 0; +#ifdef _DEBUG + m_bSRGB = false; +#endif // _DEBUG + m_nSRGB = 0; +#ifdef _DEBUG + m_bSRGB_OUTPUT_ADAPTER = false; +#endif // _DEBUG + m_nSRGB_OUTPUT_ADAPTER = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB && m_bVERTEXCOLOR && m_bCONSTANTCOLOR && m_bHDRTYPE && m_bSRGB && m_bSRGB_OUTPUT_ADAPTER; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 4 * m_nCONVERT_TO_SRGB ) + ( 8 * m_nVERTEXCOLOR ) + ( 16 * m_nCONSTANTCOLOR ) + ( 32 * m_nHDRTYPE ) + ( 96 * m_nSRGB ) + ( 192 * m_nSRGB_OUTPUT_ADAPTER ) + 0; + } +}; +#define shaderStaticTest_sprite_ps20b psh_forgot_to_set_static_VERTEXCOLOR + psh_forgot_to_set_static_CONSTANTCOLOR + psh_forgot_to_set_static_HDRTYPE + psh_forgot_to_set_static_SRGB + psh_forgot_to_set_static_SRGB_OUTPUT_ADAPTER + 0 +class sprite_ps20b_Dynamic_Index +{ +private: + int m_nHDRENABLED; +#ifdef _DEBUG + bool m_bHDRENABLED; +#endif +public: + void SetHDRENABLED( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHDRENABLED = i; +#ifdef _DEBUG + m_bHDRENABLED = true; +#endif + } + void SetHDRENABLED( bool i ) + { + m_nHDRENABLED = i ? 1 : 0; +#ifdef _DEBUG + m_bHDRENABLED = true; +#endif + } +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + sprite_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bHDRENABLED = false; +#endif // _DEBUG + m_nHDRENABLED = 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bHDRENABLED && m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nHDRENABLED ) + ( 2 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_sprite_ps20b psh_forgot_to_set_dynamic_HDRENABLED + psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9/sprite_vs20.inc b/materialsystem/stdshaders/fxctmp9/sprite_vs20.inc new file mode 100644 index 0000000..5422743 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/sprite_vs20.inc @@ -0,0 +1,112 @@ +#include "shaderlib/cshader.h" +class sprite_vs20_Static_Index +{ +private: + int m_nVERTEXCOLOR; +#ifdef _DEBUG + bool m_bVERTEXCOLOR; +#endif +public: + void SetVERTEXCOLOR( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nVERTEXCOLOR = i; +#ifdef _DEBUG + m_bVERTEXCOLOR = true; +#endif + } + void SetVERTEXCOLOR( bool i ) + { + m_nVERTEXCOLOR = i ? 1 : 0; +#ifdef _DEBUG + m_bVERTEXCOLOR = true; +#endif + } +private: + int m_nSRGB; +#ifdef _DEBUG + bool m_bSRGB; +#endif +public: + void SetSRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSRGB = i; +#ifdef _DEBUG + m_bSRGB = true; +#endif + } + void SetSRGB( bool i ) + { + m_nSRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bSRGB = true; +#endif + } +public: + sprite_vs20_Static_Index( ) + { +#ifdef _DEBUG + m_bVERTEXCOLOR = false; +#endif // _DEBUG + m_nVERTEXCOLOR = 0; +#ifdef _DEBUG + m_bSRGB = false; +#endif // _DEBUG + m_nSRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bVERTEXCOLOR && m_bSRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nVERTEXCOLOR ) + ( 4 * m_nSRGB ) + 0; + } +}; +#define shaderStaticTest_sprite_vs20 vsh_forgot_to_set_static_VERTEXCOLOR + vsh_forgot_to_set_static_SRGB + 0 +class sprite_vs20_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + sprite_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; +#define shaderDynamicTest_sprite_vs20 vsh_forgot_to_set_dynamic_DOWATERFOG + 0 diff --git a/materialsystem/stdshaders/fxctmp9/spritecard_ps11.inc b/materialsystem/stdshaders/fxctmp9/spritecard_ps11.inc new file mode 100644 index 0000000..9978f06 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/spritecard_ps11.inc @@ -0,0 +1,110 @@ +#include "shaderlib/cshader.h" +class spritecard_ps11_Static_Index +{ +private: + int m_nADDBASETEXTURE2; +#ifdef _DEBUG + bool m_bADDBASETEXTURE2; +#endif +public: + void SetADDBASETEXTURE2( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nADDBASETEXTURE2 = i; +#ifdef _DEBUG + m_bADDBASETEXTURE2 = true; +#endif + } + void SetADDBASETEXTURE2( bool i ) + { + m_nADDBASETEXTURE2 = i ? 1 : 0; +#ifdef _DEBUG + m_bADDBASETEXTURE2 = true; +#endif + } +private: + int m_nADDSELF; +#ifdef _DEBUG + bool m_bADDSELF; +#endif +public: + void SetADDSELF( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nADDSELF = i; +#ifdef _DEBUG + m_bADDSELF = true; +#endif + } + void SetADDSELF( bool i ) + { + m_nADDSELF = i ? 1 : 0; +#ifdef _DEBUG + m_bADDSELF = true; +#endif + } +private: + int m_nUSEALPHAASRGB; +#ifdef _DEBUG + bool m_bUSEALPHAASRGB; +#endif +public: + void SetUSEALPHAASRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nUSEALPHAASRGB = i; +#ifdef _DEBUG + m_bUSEALPHAASRGB = true; +#endif + } + void SetUSEALPHAASRGB( bool i ) + { + m_nUSEALPHAASRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bUSEALPHAASRGB = true; +#endif + } +public: + spritecard_ps11_Static_Index( ) + { +#ifdef _DEBUG + m_bADDBASETEXTURE2 = false; +#endif // _DEBUG + m_nADDBASETEXTURE2 = 0; +#ifdef _DEBUG + m_bADDSELF = false; +#endif // _DEBUG + m_nADDSELF = 0; +#ifdef _DEBUG + m_bUSEALPHAASRGB = false; +#endif // _DEBUG + m_nUSEALPHAASRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bADDBASETEXTURE2 && m_bADDSELF && m_bUSEALPHAASRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nADDBASETEXTURE2 ) + ( 2 * m_nADDSELF ) + ( 4 * m_nUSEALPHAASRGB ) + 0; + } +}; +#define shaderStaticTest_spritecard_ps11 psh_forgot_to_set_static_ADDBASETEXTURE2 + psh_forgot_to_set_static_ADDSELF + psh_forgot_to_set_static_USEALPHAASRGB + 0 +class spritecard_ps11_Dynamic_Index +{ +public: + spritecard_ps11_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_spritecard_ps11 0 diff --git a/materialsystem/stdshaders/fxctmp9/spritecard_ps20.inc b/materialsystem/stdshaders/fxctmp9/spritecard_ps20.inc new file mode 100644 index 0000000..4185974 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/spritecard_ps20.inc @@ -0,0 +1,260 @@ +#include "shaderlib/cshader.h" +class spritecard_ps20_Static_Index +{ +private: + int m_nDUALSEQUENCE; +#ifdef _DEBUG + bool m_bDUALSEQUENCE; +#endif +public: + void SetDUALSEQUENCE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDUALSEQUENCE = i; +#ifdef _DEBUG + m_bDUALSEQUENCE = true; +#endif + } + void SetDUALSEQUENCE( bool i ) + { + m_nDUALSEQUENCE = i ? 1 : 0; +#ifdef _DEBUG + m_bDUALSEQUENCE = true; +#endif + } +private: + int m_nSEQUENCE_BLEND_MODE; +#ifdef _DEBUG + bool m_bSEQUENCE_BLEND_MODE; +#endif +public: + void SetSEQUENCE_BLEND_MODE( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nSEQUENCE_BLEND_MODE = i; +#ifdef _DEBUG + m_bSEQUENCE_BLEND_MODE = true; +#endif + } + void SetSEQUENCE_BLEND_MODE( bool i ) + { + m_nSEQUENCE_BLEND_MODE = i ? 1 : 0; +#ifdef _DEBUG + m_bSEQUENCE_BLEND_MODE = true; +#endif + } +private: + int m_nADDBASETEXTURE2; +#ifdef _DEBUG + bool m_bADDBASETEXTURE2; +#endif +public: + void SetADDBASETEXTURE2( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nADDBASETEXTURE2 = i; +#ifdef _DEBUG + m_bADDBASETEXTURE2 = true; +#endif + } + void SetADDBASETEXTURE2( bool i ) + { + m_nADDBASETEXTURE2 = i ? 1 : 0; +#ifdef _DEBUG + m_bADDBASETEXTURE2 = true; +#endif + } +private: + int m_nMAXLUMFRAMEBLEND1; +#ifdef _DEBUG + bool m_bMAXLUMFRAMEBLEND1; +#endif +public: + void SetMAXLUMFRAMEBLEND1( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nMAXLUMFRAMEBLEND1 = i; +#ifdef _DEBUG + m_bMAXLUMFRAMEBLEND1 = true; +#endif + } + void SetMAXLUMFRAMEBLEND1( bool i ) + { + m_nMAXLUMFRAMEBLEND1 = i ? 1 : 0; +#ifdef _DEBUG + m_bMAXLUMFRAMEBLEND1 = true; +#endif + } +private: + int m_nMAXLUMFRAMEBLEND2; +#ifdef _DEBUG + bool m_bMAXLUMFRAMEBLEND2; +#endif +public: + void SetMAXLUMFRAMEBLEND2( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nMAXLUMFRAMEBLEND2 = i; +#ifdef _DEBUG + m_bMAXLUMFRAMEBLEND2 = true; +#endif + } + void SetMAXLUMFRAMEBLEND2( bool i ) + { + m_nMAXLUMFRAMEBLEND2 = i ? 1 : 0; +#ifdef _DEBUG + m_bMAXLUMFRAMEBLEND2 = true; +#endif + } +private: + int m_nEXTRACTGREENALPHA; +#ifdef _DEBUG + bool m_bEXTRACTGREENALPHA; +#endif +public: + void SetEXTRACTGREENALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nEXTRACTGREENALPHA = i; +#ifdef _DEBUG + m_bEXTRACTGREENALPHA = true; +#endif + } + void SetEXTRACTGREENALPHA( bool i ) + { + m_nEXTRACTGREENALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bEXTRACTGREENALPHA = true; +#endif + } +private: + int m_nCOLORRAMP; +#ifdef _DEBUG + bool m_bCOLORRAMP; +#endif +public: + void SetCOLORRAMP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOLORRAMP = i; +#ifdef _DEBUG + m_bCOLORRAMP = true; +#endif + } + void SetCOLORRAMP( bool i ) + { + m_nCOLORRAMP = i ? 1 : 0; +#ifdef _DEBUG + m_bCOLORRAMP = true; +#endif + } +private: + int m_nANIMBLEND; +#ifdef _DEBUG + bool m_bANIMBLEND; +#endif +public: + void SetANIMBLEND( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nANIMBLEND = i; +#ifdef _DEBUG + m_bANIMBLEND = true; +#endif + } + void SetANIMBLEND( bool i ) + { + m_nANIMBLEND = i ? 1 : 0; +#ifdef _DEBUG + m_bANIMBLEND = true; +#endif + } +private: + int m_nADDSELF; +#ifdef _DEBUG + bool m_bADDSELF; +#endif +public: + void SetADDSELF( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nADDSELF = i; +#ifdef _DEBUG + m_bADDSELF = true; +#endif + } + void SetADDSELF( bool i ) + { + m_nADDSELF = i ? 1 : 0; +#ifdef _DEBUG + m_bADDSELF = true; +#endif + } +public: + spritecard_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bDUALSEQUENCE = false; +#endif // _DEBUG + m_nDUALSEQUENCE = 0; +#ifdef _DEBUG + m_bSEQUENCE_BLEND_MODE = false; +#endif // _DEBUG + m_nSEQUENCE_BLEND_MODE = 0; +#ifdef _DEBUG + m_bADDBASETEXTURE2 = false; +#endif // _DEBUG + m_nADDBASETEXTURE2 = 0; +#ifdef _DEBUG + m_bMAXLUMFRAMEBLEND1 = false; +#endif // _DEBUG + m_nMAXLUMFRAMEBLEND1 = 0; +#ifdef _DEBUG + m_bMAXLUMFRAMEBLEND2 = false; +#endif // _DEBUG + m_nMAXLUMFRAMEBLEND2 = 0; +#ifdef _DEBUG + m_bEXTRACTGREENALPHA = false; +#endif // _DEBUG + m_nEXTRACTGREENALPHA = 0; +#ifdef _DEBUG + m_bCOLORRAMP = false; +#endif // _DEBUG + m_nCOLORRAMP = 0; +#ifdef _DEBUG + m_bANIMBLEND = false; +#endif // _DEBUG + m_nANIMBLEND = 0; +#ifdef _DEBUG + m_bADDSELF = false; +#endif // _DEBUG + m_nADDSELF = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bDUALSEQUENCE && m_bSEQUENCE_BLEND_MODE && m_bADDBASETEXTURE2 && m_bMAXLUMFRAMEBLEND1 && m_bMAXLUMFRAMEBLEND2 && m_bEXTRACTGREENALPHA && m_bCOLORRAMP && m_bANIMBLEND && m_bADDSELF; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDUALSEQUENCE ) + ( 2 * m_nSEQUENCE_BLEND_MODE ) + ( 6 * m_nADDBASETEXTURE2 ) + ( 12 * m_nMAXLUMFRAMEBLEND1 ) + ( 24 * m_nMAXLUMFRAMEBLEND2 ) + ( 48 * m_nEXTRACTGREENALPHA ) + ( 96 * m_nCOLORRAMP ) + ( 192 * m_nANIMBLEND ) + ( 384 * m_nADDSELF ) + 0; + } +}; +#define shaderStaticTest_spritecard_ps20 psh_forgot_to_set_static_DUALSEQUENCE + psh_forgot_to_set_static_SEQUENCE_BLEND_MODE + psh_forgot_to_set_static_ADDBASETEXTURE2 + psh_forgot_to_set_static_MAXLUMFRAMEBLEND1 + psh_forgot_to_set_static_MAXLUMFRAMEBLEND2 + psh_forgot_to_set_static_EXTRACTGREENALPHA + psh_forgot_to_set_static_COLORRAMP + psh_forgot_to_set_static_ANIMBLEND + psh_forgot_to_set_static_ADDSELF + 0 +class spritecard_ps20_Dynamic_Index +{ +public: + spritecard_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_spritecard_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9/spritecard_ps20b.inc b/materialsystem/stdshaders/fxctmp9/spritecard_ps20b.inc new file mode 100644 index 0000000..6ab1460 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/spritecard_ps20b.inc @@ -0,0 +1,310 @@ +#include "shaderlib/cshader.h" +class spritecard_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +private: + int m_nDUALSEQUENCE; +#ifdef _DEBUG + bool m_bDUALSEQUENCE; +#endif +public: + void SetDUALSEQUENCE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDUALSEQUENCE = i; +#ifdef _DEBUG + m_bDUALSEQUENCE = true; +#endif + } + void SetDUALSEQUENCE( bool i ) + { + m_nDUALSEQUENCE = i ? 1 : 0; +#ifdef _DEBUG + m_bDUALSEQUENCE = true; +#endif + } +private: + int m_nSEQUENCE_BLEND_MODE; +#ifdef _DEBUG + bool m_bSEQUENCE_BLEND_MODE; +#endif +public: + void SetSEQUENCE_BLEND_MODE( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nSEQUENCE_BLEND_MODE = i; +#ifdef _DEBUG + m_bSEQUENCE_BLEND_MODE = true; +#endif + } + void SetSEQUENCE_BLEND_MODE( bool i ) + { + m_nSEQUENCE_BLEND_MODE = i ? 1 : 0; +#ifdef _DEBUG + m_bSEQUENCE_BLEND_MODE = true; +#endif + } +private: + int m_nADDBASETEXTURE2; +#ifdef _DEBUG + bool m_bADDBASETEXTURE2; +#endif +public: + void SetADDBASETEXTURE2( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nADDBASETEXTURE2 = i; +#ifdef _DEBUG + m_bADDBASETEXTURE2 = true; +#endif + } + void SetADDBASETEXTURE2( bool i ) + { + m_nADDBASETEXTURE2 = i ? 1 : 0; +#ifdef _DEBUG + m_bADDBASETEXTURE2 = true; +#endif + } +private: + int m_nMAXLUMFRAMEBLEND1; +#ifdef _DEBUG + bool m_bMAXLUMFRAMEBLEND1; +#endif +public: + void SetMAXLUMFRAMEBLEND1( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nMAXLUMFRAMEBLEND1 = i; +#ifdef _DEBUG + m_bMAXLUMFRAMEBLEND1 = true; +#endif + } + void SetMAXLUMFRAMEBLEND1( bool i ) + { + m_nMAXLUMFRAMEBLEND1 = i ? 1 : 0; +#ifdef _DEBUG + m_bMAXLUMFRAMEBLEND1 = true; +#endif + } +private: + int m_nMAXLUMFRAMEBLEND2; +#ifdef _DEBUG + bool m_bMAXLUMFRAMEBLEND2; +#endif +public: + void SetMAXLUMFRAMEBLEND2( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nMAXLUMFRAMEBLEND2 = i; +#ifdef _DEBUG + m_bMAXLUMFRAMEBLEND2 = true; +#endif + } + void SetMAXLUMFRAMEBLEND2( bool i ) + { + m_nMAXLUMFRAMEBLEND2 = i ? 1 : 0; +#ifdef _DEBUG + m_bMAXLUMFRAMEBLEND2 = true; +#endif + } +private: + int m_nEXTRACTGREENALPHA; +#ifdef _DEBUG + bool m_bEXTRACTGREENALPHA; +#endif +public: + void SetEXTRACTGREENALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nEXTRACTGREENALPHA = i; +#ifdef _DEBUG + m_bEXTRACTGREENALPHA = true; +#endif + } + void SetEXTRACTGREENALPHA( bool i ) + { + m_nEXTRACTGREENALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bEXTRACTGREENALPHA = true; +#endif + } +private: + int m_nCOLORRAMP; +#ifdef _DEBUG + bool m_bCOLORRAMP; +#endif +public: + void SetCOLORRAMP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOLORRAMP = i; +#ifdef _DEBUG + m_bCOLORRAMP = true; +#endif + } + void SetCOLORRAMP( bool i ) + { + m_nCOLORRAMP = i ? 1 : 0; +#ifdef _DEBUG + m_bCOLORRAMP = true; +#endif + } +private: + int m_nANIMBLEND; +#ifdef _DEBUG + bool m_bANIMBLEND; +#endif +public: + void SetANIMBLEND( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nANIMBLEND = i; +#ifdef _DEBUG + m_bANIMBLEND = true; +#endif + } + void SetANIMBLEND( bool i ) + { + m_nANIMBLEND = i ? 1 : 0; +#ifdef _DEBUG + m_bANIMBLEND = true; +#endif + } +private: + int m_nADDSELF; +#ifdef _DEBUG + bool m_bADDSELF; +#endif +public: + void SetADDSELF( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nADDSELF = i; +#ifdef _DEBUG + m_bADDSELF = true; +#endif + } + void SetADDSELF( bool i ) + { + m_nADDSELF = i ? 1 : 0; +#ifdef _DEBUG + m_bADDSELF = true; +#endif + } +private: + int m_nDEPTHBLEND; +#ifdef _DEBUG + bool m_bDEPTHBLEND; +#endif +public: + void SetDEPTHBLEND( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDEPTHBLEND = i; +#ifdef _DEBUG + m_bDEPTHBLEND = true; +#endif + } + void SetDEPTHBLEND( bool i ) + { + m_nDEPTHBLEND = i ? 1 : 0; +#ifdef _DEBUG + m_bDEPTHBLEND = true; +#endif + } +public: + spritecard_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); +#ifdef _DEBUG + m_bDUALSEQUENCE = false; +#endif // _DEBUG + m_nDUALSEQUENCE = 0; +#ifdef _DEBUG + m_bSEQUENCE_BLEND_MODE = false; +#endif // _DEBUG + m_nSEQUENCE_BLEND_MODE = 0; +#ifdef _DEBUG + m_bADDBASETEXTURE2 = false; +#endif // _DEBUG + m_nADDBASETEXTURE2 = 0; +#ifdef _DEBUG + m_bMAXLUMFRAMEBLEND1 = false; +#endif // _DEBUG + m_nMAXLUMFRAMEBLEND1 = 0; +#ifdef _DEBUG + m_bMAXLUMFRAMEBLEND2 = false; +#endif // _DEBUG + m_nMAXLUMFRAMEBLEND2 = 0; +#ifdef _DEBUG + m_bEXTRACTGREENALPHA = false; +#endif // _DEBUG + m_nEXTRACTGREENALPHA = 0; +#ifdef _DEBUG + m_bCOLORRAMP = false; +#endif // _DEBUG + m_nCOLORRAMP = 0; +#ifdef _DEBUG + m_bANIMBLEND = false; +#endif // _DEBUG + m_nANIMBLEND = 0; +#ifdef _DEBUG + m_bADDSELF = false; +#endif // _DEBUG + m_nADDSELF = 0; +#ifdef _DEBUG + m_bDEPTHBLEND = false; +#endif // _DEBUG + m_nDEPTHBLEND = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB && m_bDUALSEQUENCE && m_bSEQUENCE_BLEND_MODE && m_bADDBASETEXTURE2 && m_bMAXLUMFRAMEBLEND1 && m_bMAXLUMFRAMEBLEND2 && m_bEXTRACTGREENALPHA && m_bCOLORRAMP && m_bANIMBLEND && m_bADDSELF && m_bDEPTHBLEND; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + ( 2 * m_nDUALSEQUENCE ) + ( 4 * m_nSEQUENCE_BLEND_MODE ) + ( 12 * m_nADDBASETEXTURE2 ) + ( 24 * m_nMAXLUMFRAMEBLEND1 ) + ( 48 * m_nMAXLUMFRAMEBLEND2 ) + ( 96 * m_nEXTRACTGREENALPHA ) + ( 192 * m_nCOLORRAMP ) + ( 384 * m_nANIMBLEND ) + ( 768 * m_nADDSELF ) + ( 1536 * m_nDEPTHBLEND ) + 0; + } +}; +#define shaderStaticTest_spritecard_ps20b psh_forgot_to_set_static_DUALSEQUENCE + psh_forgot_to_set_static_SEQUENCE_BLEND_MODE + psh_forgot_to_set_static_ADDBASETEXTURE2 + psh_forgot_to_set_static_MAXLUMFRAMEBLEND1 + psh_forgot_to_set_static_MAXLUMFRAMEBLEND2 + psh_forgot_to_set_static_EXTRACTGREENALPHA + psh_forgot_to_set_static_COLORRAMP + psh_forgot_to_set_static_ANIMBLEND + psh_forgot_to_set_static_ADDSELF + psh_forgot_to_set_static_DEPTHBLEND + 0 +class spritecard_ps20b_Dynamic_Index +{ +public: + spritecard_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_spritecard_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9/spritecard_vs11.inc b/materialsystem/stdshaders/fxctmp9/spritecard_vs11.inc new file mode 100644 index 0000000..7b6a9ef --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/spritecard_vs11.inc @@ -0,0 +1,137 @@ +#include "shaderlib/cshader.h" +class spritecard_vs11_Static_Index +{ +private: + int m_nZOOM_ANIMATE_SEQ2; +#ifdef _DEBUG + bool m_bZOOM_ANIMATE_SEQ2; +#endif +public: + void SetZOOM_ANIMATE_SEQ2( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nZOOM_ANIMATE_SEQ2 = i; +#ifdef _DEBUG + m_bZOOM_ANIMATE_SEQ2 = true; +#endif + } + void SetZOOM_ANIMATE_SEQ2( bool i ) + { + m_nZOOM_ANIMATE_SEQ2 = i ? 1 : 0; +#ifdef _DEBUG + m_bZOOM_ANIMATE_SEQ2 = true; +#endif + } +private: + int m_nDUALSEQUENCE; +#ifdef _DEBUG + bool m_bDUALSEQUENCE; +#endif +public: + void SetDUALSEQUENCE( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nDUALSEQUENCE = i; +#ifdef _DEBUG + m_bDUALSEQUENCE = true; +#endif + } + void SetDUALSEQUENCE( bool i ) + { + m_nDUALSEQUENCE = i ? 1 : 0; +#ifdef _DEBUG + m_bDUALSEQUENCE = true; +#endif + } +private: + int m_nEXTRACTGREENALPHA; +#ifdef _DEBUG + bool m_bEXTRACTGREENALPHA; +#endif +public: + void SetEXTRACTGREENALPHA( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nEXTRACTGREENALPHA = i; +#ifdef _DEBUG + m_bEXTRACTGREENALPHA = true; +#endif + } + void SetEXTRACTGREENALPHA( bool i ) + { + m_nEXTRACTGREENALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bEXTRACTGREENALPHA = true; +#endif + } +public: + spritecard_vs11_Static_Index( ) + { +#ifdef _DEBUG + m_bZOOM_ANIMATE_SEQ2 = false; +#endif // _DEBUG + m_nZOOM_ANIMATE_SEQ2 = 0; +#ifdef _DEBUG + m_bDUALSEQUENCE = false; +#endif // _DEBUG + m_nDUALSEQUENCE = 0; +#ifdef _DEBUG + m_bEXTRACTGREENALPHA = false; +#endif // _DEBUG + m_nEXTRACTGREENALPHA = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bZOOM_ANIMATE_SEQ2 && m_bDUALSEQUENCE && m_bEXTRACTGREENALPHA; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 3 * m_nZOOM_ANIMATE_SEQ2 ) + ( 3 * m_nDUALSEQUENCE ) + ( 3 * m_nEXTRACTGREENALPHA ) + 0; + } +}; +#define shaderStaticTest_spritecard_vs11 vsh_forgot_to_set_static_ZOOM_ANIMATE_SEQ2 + vsh_forgot_to_set_static_DUALSEQUENCE + vsh_forgot_to_set_static_EXTRACTGREENALPHA + 0 +class spritecard_vs11_Dynamic_Index +{ +private: + int m_nORIENTATION; +#ifdef _DEBUG + bool m_bORIENTATION; +#endif +public: + void SetORIENTATION( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nORIENTATION = i; +#ifdef _DEBUG + m_bORIENTATION = true; +#endif + } + void SetORIENTATION( bool i ) + { + m_nORIENTATION = i ? 1 : 0; +#ifdef _DEBUG + m_bORIENTATION = true; +#endif + } +public: + spritecard_vs11_Dynamic_Index() + { +#ifdef _DEBUG + m_bORIENTATION = false; +#endif // _DEBUG + m_nORIENTATION = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bORIENTATION; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nORIENTATION ) + 0; + } +}; +#define shaderDynamicTest_spritecard_vs11 vsh_forgot_to_set_dynamic_ORIENTATION + 0 diff --git a/materialsystem/stdshaders/fxctmp9/spritecard_vs20.inc b/materialsystem/stdshaders/fxctmp9/spritecard_vs20.inc new file mode 100644 index 0000000..f573fb9 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/spritecard_vs20.inc @@ -0,0 +1,162 @@ +#include "shaderlib/cshader.h" +class spritecard_vs20_Static_Index +{ +private: + int m_nZOOM_ANIMATE_SEQ2; +#ifdef _DEBUG + bool m_bZOOM_ANIMATE_SEQ2; +#endif +public: + void SetZOOM_ANIMATE_SEQ2( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nZOOM_ANIMATE_SEQ2 = i; +#ifdef _DEBUG + m_bZOOM_ANIMATE_SEQ2 = true; +#endif + } + void SetZOOM_ANIMATE_SEQ2( bool i ) + { + m_nZOOM_ANIMATE_SEQ2 = i ? 1 : 0; +#ifdef _DEBUG + m_bZOOM_ANIMATE_SEQ2 = true; +#endif + } +private: + int m_nDUALSEQUENCE; +#ifdef _DEBUG + bool m_bDUALSEQUENCE; +#endif +public: + void SetDUALSEQUENCE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDUALSEQUENCE = i; +#ifdef _DEBUG + m_bDUALSEQUENCE = true; +#endif + } + void SetDUALSEQUENCE( bool i ) + { + m_nDUALSEQUENCE = i ? 1 : 0; +#ifdef _DEBUG + m_bDUALSEQUENCE = true; +#endif + } +private: + int m_nEXTRACTGREENALPHA; +#ifdef _DEBUG + bool m_bEXTRACTGREENALPHA; +#endif +public: + void SetEXTRACTGREENALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nEXTRACTGREENALPHA = i; +#ifdef _DEBUG + m_bEXTRACTGREENALPHA = true; +#endif + } + void SetEXTRACTGREENALPHA( bool i ) + { + m_nEXTRACTGREENALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bEXTRACTGREENALPHA = true; +#endif + } +private: + int m_nUSE_INSTANCING; +#ifdef _DEBUG + bool m_bUSE_INSTANCING; +#endif +public: + void SetUSE_INSTANCING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nUSE_INSTANCING = i; +#ifdef _DEBUG + m_bUSE_INSTANCING = true; +#endif + } + void SetUSE_INSTANCING( bool i ) + { + m_nUSE_INSTANCING = i ? 1 : 0; +#ifdef _DEBUG + m_bUSE_INSTANCING = true; +#endif + } +public: + spritecard_vs20_Static_Index( ) + { +#ifdef _DEBUG + m_bZOOM_ANIMATE_SEQ2 = false; +#endif // _DEBUG + m_nZOOM_ANIMATE_SEQ2 = 0; +#ifdef _DEBUG + m_bDUALSEQUENCE = false; +#endif // _DEBUG + m_nDUALSEQUENCE = 0; +#ifdef _DEBUG + m_bEXTRACTGREENALPHA = false; +#endif // _DEBUG + m_nEXTRACTGREENALPHA = 0; +#ifdef _DEBUG + m_bUSE_INSTANCING = false; +#endif // _DEBUG + m_nUSE_INSTANCING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bZOOM_ANIMATE_SEQ2 && m_bDUALSEQUENCE && m_bEXTRACTGREENALPHA && m_bUSE_INSTANCING; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 3 * m_nZOOM_ANIMATE_SEQ2 ) + ( 6 * m_nDUALSEQUENCE ) + ( 12 * m_nEXTRACTGREENALPHA ) + ( 24 * m_nUSE_INSTANCING ) + 0; + } +}; +#define shaderStaticTest_spritecard_vs20 vsh_forgot_to_set_static_ZOOM_ANIMATE_SEQ2 + vsh_forgot_to_set_static_DUALSEQUENCE + vsh_forgot_to_set_static_EXTRACTGREENALPHA + vsh_forgot_to_set_static_USE_INSTANCING + 0 +class spritecard_vs20_Dynamic_Index +{ +private: + int m_nORIENTATION; +#ifdef _DEBUG + bool m_bORIENTATION; +#endif +public: + void SetORIENTATION( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nORIENTATION = i; +#ifdef _DEBUG + m_bORIENTATION = true; +#endif + } + void SetORIENTATION( bool i ) + { + m_nORIENTATION = i ? 1 : 0; +#ifdef _DEBUG + m_bORIENTATION = true; +#endif + } +public: + spritecard_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bORIENTATION = false; +#endif // _DEBUG + m_nORIENTATION = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bORIENTATION; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nORIENTATION ) + 0; + } +}; +#define shaderDynamicTest_spritecard_vs20 vsh_forgot_to_set_dynamic_ORIENTATION + 0 diff --git a/materialsystem/stdshaders/fxctmp9/teeth_bump_ps20.inc b/materialsystem/stdshaders/fxctmp9/teeth_bump_ps20.inc new file mode 100644 index 0000000..6ae3f70 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/teeth_bump_ps20.inc @@ -0,0 +1,110 @@ +#include "shaderlib/cshader.h" +class teeth_bump_ps20_Static_Index +{ +public: + teeth_bump_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_teeth_bump_ps20 0 +class teeth_bump_ps20_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +private: + int m_nNUM_LIGHTS; +#ifdef _DEBUG + bool m_bNUM_LIGHTS; +#endif +public: + void SetNUM_LIGHTS( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nNUM_LIGHTS = i; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } + void SetNUM_LIGHTS( bool i ) + { + m_nNUM_LIGHTS = i ? 1 : 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } +private: + int m_nAMBIENT_LIGHT; +#ifdef _DEBUG + bool m_bAMBIENT_LIGHT; +#endif +public: + void SetAMBIENT_LIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nAMBIENT_LIGHT = i; +#ifdef _DEBUG + m_bAMBIENT_LIGHT = true; +#endif + } + void SetAMBIENT_LIGHT( bool i ) + { + m_nAMBIENT_LIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bAMBIENT_LIGHT = true; +#endif + } +public: + teeth_bump_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = false; +#endif // _DEBUG + m_nNUM_LIGHTS = 0; +#ifdef _DEBUG + m_bAMBIENT_LIGHT = false; +#endif // _DEBUG + m_nAMBIENT_LIGHT = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE && m_bNUM_LIGHTS && m_bAMBIENT_LIGHT; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + ( 2 * m_nNUM_LIGHTS ) + ( 6 * m_nAMBIENT_LIGHT ) + 0; + } +}; +#define shaderDynamicTest_teeth_bump_ps20 psh_forgot_to_set_dynamic_PIXELFOGTYPE + psh_forgot_to_set_dynamic_NUM_LIGHTS + psh_forgot_to_set_dynamic_AMBIENT_LIGHT + 0 diff --git a/materialsystem/stdshaders/fxctmp9/teeth_bump_ps20b.inc b/materialsystem/stdshaders/fxctmp9/teeth_bump_ps20b.inc new file mode 100644 index 0000000..428abd5 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/teeth_bump_ps20b.inc @@ -0,0 +1,162 @@ +#include "shaderlib/cshader.h" +class teeth_bump_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + teeth_bump_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 40 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_teeth_bump_ps20b 0 +class teeth_bump_ps20b_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +private: + int m_nNUM_LIGHTS; +#ifdef _DEBUG + bool m_bNUM_LIGHTS; +#endif +public: + void SetNUM_LIGHTS( int i ) + { + Assert( i >= 0 && i <= 4 ); + m_nNUM_LIGHTS = i; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } + void SetNUM_LIGHTS( bool i ) + { + m_nNUM_LIGHTS = i ? 1 : 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } +private: + int m_nAMBIENT_LIGHT; +#ifdef _DEBUG + bool m_bAMBIENT_LIGHT; +#endif +public: + void SetAMBIENT_LIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nAMBIENT_LIGHT = i; +#ifdef _DEBUG + m_bAMBIENT_LIGHT = true; +#endif + } + void SetAMBIENT_LIGHT( bool i ) + { + m_nAMBIENT_LIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bAMBIENT_LIGHT = true; +#endif + } +private: + int m_nWRITE_DEPTH_TO_DESTALPHA; +#ifdef _DEBUG + bool m_bWRITE_DEPTH_TO_DESTALPHA; +#endif +public: + void SetWRITE_DEPTH_TO_DESTALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nWRITE_DEPTH_TO_DESTALPHA = i; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = true; +#endif + } + void SetWRITE_DEPTH_TO_DESTALPHA( bool i ) + { + m_nWRITE_DEPTH_TO_DESTALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = true; +#endif + } +public: + teeth_bump_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = false; +#endif // _DEBUG + m_nNUM_LIGHTS = 0; +#ifdef _DEBUG + m_bAMBIENT_LIGHT = false; +#endif // _DEBUG + m_nAMBIENT_LIGHT = 0; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = false; +#endif // _DEBUG + m_nWRITE_DEPTH_TO_DESTALPHA = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE && m_bNUM_LIGHTS && m_bAMBIENT_LIGHT && m_bWRITE_DEPTH_TO_DESTALPHA; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + ( 2 * m_nNUM_LIGHTS ) + ( 10 * m_nAMBIENT_LIGHT ) + ( 20 * m_nWRITE_DEPTH_TO_DESTALPHA ) + 0; + } +}; +#define shaderDynamicTest_teeth_bump_ps20b psh_forgot_to_set_dynamic_PIXELFOGTYPE + psh_forgot_to_set_dynamic_NUM_LIGHTS + psh_forgot_to_set_dynamic_AMBIENT_LIGHT + psh_forgot_to_set_dynamic_WRITE_DEPTH_TO_DESTALPHA + 0 diff --git a/materialsystem/stdshaders/fxctmp9/teeth_bump_ps30.inc b/materialsystem/stdshaders/fxctmp9/teeth_bump_ps30.inc new file mode 100644 index 0000000..2de32ee --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/teeth_bump_ps30.inc @@ -0,0 +1,162 @@ +#include "shaderlib/cshader.h" +class teeth_bump_ps30_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + teeth_bump_ps30_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 40 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_teeth_bump_ps30 0 +class teeth_bump_ps30_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +private: + int m_nNUM_LIGHTS; +#ifdef _DEBUG + bool m_bNUM_LIGHTS; +#endif +public: + void SetNUM_LIGHTS( int i ) + { + Assert( i >= 0 && i <= 4 ); + m_nNUM_LIGHTS = i; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } + void SetNUM_LIGHTS( bool i ) + { + m_nNUM_LIGHTS = i ? 1 : 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } +private: + int m_nAMBIENT_LIGHT; +#ifdef _DEBUG + bool m_bAMBIENT_LIGHT; +#endif +public: + void SetAMBIENT_LIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nAMBIENT_LIGHT = i; +#ifdef _DEBUG + m_bAMBIENT_LIGHT = true; +#endif + } + void SetAMBIENT_LIGHT( bool i ) + { + m_nAMBIENT_LIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bAMBIENT_LIGHT = true; +#endif + } +private: + int m_nWRITE_DEPTH_TO_DESTALPHA; +#ifdef _DEBUG + bool m_bWRITE_DEPTH_TO_DESTALPHA; +#endif +public: + void SetWRITE_DEPTH_TO_DESTALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nWRITE_DEPTH_TO_DESTALPHA = i; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = true; +#endif + } + void SetWRITE_DEPTH_TO_DESTALPHA( bool i ) + { + m_nWRITE_DEPTH_TO_DESTALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = true; +#endif + } +public: + teeth_bump_ps30_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = false; +#endif // _DEBUG + m_nNUM_LIGHTS = 0; +#ifdef _DEBUG + m_bAMBIENT_LIGHT = false; +#endif // _DEBUG + m_nAMBIENT_LIGHT = 0; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = false; +#endif // _DEBUG + m_nWRITE_DEPTH_TO_DESTALPHA = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE && m_bNUM_LIGHTS && m_bAMBIENT_LIGHT && m_bWRITE_DEPTH_TO_DESTALPHA; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + ( 2 * m_nNUM_LIGHTS ) + ( 10 * m_nAMBIENT_LIGHT ) + ( 20 * m_nWRITE_DEPTH_TO_DESTALPHA ) + 0; + } +}; +#define shaderDynamicTest_teeth_bump_ps30 psh_forgot_to_set_dynamic_PIXELFOGTYPE + psh_forgot_to_set_dynamic_NUM_LIGHTS + psh_forgot_to_set_dynamic_AMBIENT_LIGHT + psh_forgot_to_set_dynamic_WRITE_DEPTH_TO_DESTALPHA + 0 diff --git a/materialsystem/stdshaders/fxctmp9/teeth_bump_vs20.inc b/materialsystem/stdshaders/fxctmp9/teeth_bump_vs20.inc new file mode 100644 index 0000000..1f02a02 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/teeth_bump_vs20.inc @@ -0,0 +1,212 @@ +#include "shaderlib/cshader.h" +class teeth_bump_vs20_Static_Index +{ +private: + int m_nINTRO; +#ifdef _DEBUG + bool m_bINTRO; +#endif +public: + void SetINTRO( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nINTRO = i; +#ifdef _DEBUG + m_bINTRO = true; +#endif + } + void SetINTRO( bool i ) + { + m_nINTRO = i ? 1 : 0; +#ifdef _DEBUG + m_bINTRO = true; +#endif + } +private: + int m_nUSE_STATIC_CONTROL_FLOW; +#ifdef _DEBUG + bool m_bUSE_STATIC_CONTROL_FLOW; +#endif +public: + void SetUSE_STATIC_CONTROL_FLOW( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nUSE_STATIC_CONTROL_FLOW = i; +#ifdef _DEBUG + m_bUSE_STATIC_CONTROL_FLOW = true; +#endif + } + void SetUSE_STATIC_CONTROL_FLOW( bool i ) + { + m_nUSE_STATIC_CONTROL_FLOW = i ? 1 : 0; +#ifdef _DEBUG + m_bUSE_STATIC_CONTROL_FLOW = true; +#endif + } +public: + teeth_bump_vs20_Static_Index( ) + { +#ifdef _DEBUG + m_bINTRO = false; +#endif // _DEBUG + m_nINTRO = 0; +#ifdef _DEBUG + m_bUSE_STATIC_CONTROL_FLOW = false; +#endif // _DEBUG + m_nUSE_STATIC_CONTROL_FLOW = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bINTRO && m_bUSE_STATIC_CONTROL_FLOW; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 48 * m_nINTRO ) + ( 96 * m_nUSE_STATIC_CONTROL_FLOW ) + 0; + } +}; +#define shaderStaticTest_teeth_bump_vs20 vsh_forgot_to_set_static_INTRO + vsh_forgot_to_set_static_USE_STATIC_CONTROL_FLOW + 0 +class teeth_bump_vs20_Dynamic_Index +{ +private: + int m_nCOMPRESSED_VERTS; +#ifdef _DEBUG + bool m_bCOMPRESSED_VERTS; +#endif +public: + void SetCOMPRESSED_VERTS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOMPRESSED_VERTS = i; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } + void SetCOMPRESSED_VERTS( bool i ) + { + m_nCOMPRESSED_VERTS = i ? 1 : 0; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +private: + int m_nSTATIC_LIGHT; +#ifdef _DEBUG + bool m_bSTATIC_LIGHT; +#endif +public: + void SetSTATIC_LIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSTATIC_LIGHT = i; +#ifdef _DEBUG + m_bSTATIC_LIGHT = true; +#endif + } + void SetSTATIC_LIGHT( bool i ) + { + m_nSTATIC_LIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bSTATIC_LIGHT = true; +#endif + } +private: + int m_nNUM_LIGHTS; +#ifdef _DEBUG + bool m_bNUM_LIGHTS; +#endif +public: + void SetNUM_LIGHTS( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nNUM_LIGHTS = i; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } + void SetNUM_LIGHTS( bool i ) + { + m_nNUM_LIGHTS = i ? 1 : 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } +public: + teeth_bump_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = false; +#endif // _DEBUG + m_nCOMPRESSED_VERTS = 0; +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; +#ifdef _DEBUG + m_bSTATIC_LIGHT = false; +#endif // _DEBUG + m_nSTATIC_LIGHT = 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = false; +#endif // _DEBUG + m_nNUM_LIGHTS = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bCOMPRESSED_VERTS && m_bDOWATERFOG && m_bSKINNING && m_bSTATIC_LIGHT && m_bNUM_LIGHTS; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCOMPRESSED_VERTS ) + ( 2 * m_nDOWATERFOG ) + ( 4 * m_nSKINNING ) + ( 8 * m_nSTATIC_LIGHT ) + ( 16 * m_nNUM_LIGHTS ) + 0; + } +}; +#define shaderDynamicTest_teeth_bump_vs20 vsh_forgot_to_set_dynamic_COMPRESSED_VERTS + vsh_forgot_to_set_dynamic_DOWATERFOG + vsh_forgot_to_set_dynamic_SKINNING + vsh_forgot_to_set_dynamic_STATIC_LIGHT + vsh_forgot_to_set_dynamic_NUM_LIGHTS + 0 diff --git a/materialsystem/stdshaders/fxctmp9/teeth_bump_vs30.inc b/materialsystem/stdshaders/fxctmp9/teeth_bump_vs30.inc new file mode 100644 index 0000000..cc1cf13 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/teeth_bump_vs30.inc @@ -0,0 +1,187 @@ +#include "shaderlib/cshader.h" +class teeth_bump_vs30_Static_Index +{ +private: + int m_nINTRO; +#ifdef _DEBUG + bool m_bINTRO; +#endif +public: + void SetINTRO( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nINTRO = i; +#ifdef _DEBUG + m_bINTRO = true; +#endif + } + void SetINTRO( bool i ) + { + m_nINTRO = i ? 1 : 0; +#ifdef _DEBUG + m_bINTRO = true; +#endif + } +public: + teeth_bump_vs30_Static_Index( ) + { +#ifdef _DEBUG + m_bINTRO = false; +#endif // _DEBUG + m_nINTRO = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bINTRO; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 32 * m_nINTRO ) + 0; + } +}; +#define shaderStaticTest_teeth_bump_vs30 vsh_forgot_to_set_static_INTRO + 0 +class teeth_bump_vs30_Dynamic_Index +{ +private: + int m_nCOMPRESSED_VERTS; +#ifdef _DEBUG + bool m_bCOMPRESSED_VERTS; +#endif +public: + void SetCOMPRESSED_VERTS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOMPRESSED_VERTS = i; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } + void SetCOMPRESSED_VERTS( bool i ) + { + m_nCOMPRESSED_VERTS = i ? 1 : 0; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +private: + int m_nSTATIC_LIGHT; +#ifdef _DEBUG + bool m_bSTATIC_LIGHT; +#endif +public: + void SetSTATIC_LIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSTATIC_LIGHT = i; +#ifdef _DEBUG + m_bSTATIC_LIGHT = true; +#endif + } + void SetSTATIC_LIGHT( bool i ) + { + m_nSTATIC_LIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bSTATIC_LIGHT = true; +#endif + } +private: + int m_nMORPHING; +#ifdef _DEBUG + bool m_bMORPHING; +#endif +public: + void SetMORPHING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nMORPHING = i; +#ifdef _DEBUG + m_bMORPHING = true; +#endif + } + void SetMORPHING( bool i ) + { + m_nMORPHING = i ? 1 : 0; +#ifdef _DEBUG + m_bMORPHING = true; +#endif + } +public: + teeth_bump_vs30_Dynamic_Index() + { +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = false; +#endif // _DEBUG + m_nCOMPRESSED_VERTS = 0; +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; +#ifdef _DEBUG + m_bSTATIC_LIGHT = false; +#endif // _DEBUG + m_nSTATIC_LIGHT = 0; +#ifdef _DEBUG + m_bMORPHING = false; +#endif // _DEBUG + m_nMORPHING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bCOMPRESSED_VERTS && m_bDOWATERFOG && m_bSKINNING && m_bSTATIC_LIGHT && m_bMORPHING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCOMPRESSED_VERTS ) + ( 2 * m_nDOWATERFOG ) + ( 4 * m_nSKINNING ) + ( 8 * m_nSTATIC_LIGHT ) + ( 16 * m_nMORPHING ) + 0; + } +}; +#define shaderDynamicTest_teeth_bump_vs30 vsh_forgot_to_set_dynamic_COMPRESSED_VERTS + vsh_forgot_to_set_dynamic_DOWATERFOG + vsh_forgot_to_set_dynamic_SKINNING + vsh_forgot_to_set_dynamic_STATIC_LIGHT + vsh_forgot_to_set_dynamic_MORPHING + 0 diff --git a/materialsystem/stdshaders/fxctmp9/teeth_flashlight_ps20.inc b/materialsystem/stdshaders/fxctmp9/teeth_flashlight_ps20.inc new file mode 100644 index 0000000..6a0eb3e --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/teeth_flashlight_ps20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class teeth_flashlight_ps20_Static_Index +{ +public: + teeth_flashlight_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_teeth_flashlight_ps20 0 +class teeth_flashlight_ps20_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + teeth_flashlight_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_teeth_flashlight_ps20 psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9/teeth_flashlight_ps20b.inc b/materialsystem/stdshaders/fxctmp9/teeth_flashlight_ps20b.inc new file mode 100644 index 0000000..cf4779a --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/teeth_flashlight_ps20b.inc @@ -0,0 +1,137 @@ +#include "shaderlib/cshader.h" +class teeth_flashlight_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +private: + int m_nFLASHLIGHTDEPTHFILTERMODE; +#ifdef _DEBUG + bool m_bFLASHLIGHTDEPTHFILTERMODE; +#endif +public: + void SetFLASHLIGHTDEPTHFILTERMODE( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nFLASHLIGHTDEPTHFILTERMODE = i; +#ifdef _DEBUG + m_bFLASHLIGHTDEPTHFILTERMODE = true; +#endif + } + void SetFLASHLIGHTDEPTHFILTERMODE( bool i ) + { + m_nFLASHLIGHTDEPTHFILTERMODE = i ? 1 : 0; +#ifdef _DEBUG + m_bFLASHLIGHTDEPTHFILTERMODE = true; +#endif + } +public: + teeth_flashlight_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); +#ifdef _DEBUG + m_bFLASHLIGHTDEPTHFILTERMODE = false; +#endif // _DEBUG + m_nFLASHLIGHTDEPTHFILTERMODE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB && m_bFLASHLIGHTDEPTHFILTERMODE; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 4 * m_nCONVERT_TO_SRGB ) + ( 8 * m_nFLASHLIGHTDEPTHFILTERMODE ) + 0; + } +}; +#define shaderStaticTest_teeth_flashlight_ps20b psh_forgot_to_set_static_FLASHLIGHTDEPTHFILTERMODE + 0 +class teeth_flashlight_ps20b_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +private: + int m_nFLASHLIGHTSHADOWS; +#ifdef _DEBUG + bool m_bFLASHLIGHTSHADOWS; +#endif +public: + void SetFLASHLIGHTSHADOWS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFLASHLIGHTSHADOWS = i; +#ifdef _DEBUG + m_bFLASHLIGHTSHADOWS = true; +#endif + } + void SetFLASHLIGHTSHADOWS( bool i ) + { + m_nFLASHLIGHTSHADOWS = i ? 1 : 0; +#ifdef _DEBUG + m_bFLASHLIGHTSHADOWS = true; +#endif + } +public: + teeth_flashlight_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; +#ifdef _DEBUG + m_bFLASHLIGHTSHADOWS = false; +#endif // _DEBUG + m_nFLASHLIGHTSHADOWS = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE && m_bFLASHLIGHTSHADOWS; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + ( 2 * m_nFLASHLIGHTSHADOWS ) + 0; + } +}; +#define shaderDynamicTest_teeth_flashlight_ps20b psh_forgot_to_set_dynamic_PIXELFOGTYPE + psh_forgot_to_set_dynamic_FLASHLIGHTSHADOWS + 0 diff --git a/materialsystem/stdshaders/fxctmp9/teeth_flashlight_ps30.inc b/materialsystem/stdshaders/fxctmp9/teeth_flashlight_ps30.inc new file mode 100644 index 0000000..554b624 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/teeth_flashlight_ps30.inc @@ -0,0 +1,137 @@ +#include "shaderlib/cshader.h" +class teeth_flashlight_ps30_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +private: + int m_nFLASHLIGHTDEPTHFILTERMODE; +#ifdef _DEBUG + bool m_bFLASHLIGHTDEPTHFILTERMODE; +#endif +public: + void SetFLASHLIGHTDEPTHFILTERMODE( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nFLASHLIGHTDEPTHFILTERMODE = i; +#ifdef _DEBUG + m_bFLASHLIGHTDEPTHFILTERMODE = true; +#endif + } + void SetFLASHLIGHTDEPTHFILTERMODE( bool i ) + { + m_nFLASHLIGHTDEPTHFILTERMODE = i ? 1 : 0; +#ifdef _DEBUG + m_bFLASHLIGHTDEPTHFILTERMODE = true; +#endif + } +public: + teeth_flashlight_ps30_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); +#ifdef _DEBUG + m_bFLASHLIGHTDEPTHFILTERMODE = false; +#endif // _DEBUG + m_nFLASHLIGHTDEPTHFILTERMODE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB && m_bFLASHLIGHTDEPTHFILTERMODE; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 4 * m_nCONVERT_TO_SRGB ) + ( 8 * m_nFLASHLIGHTDEPTHFILTERMODE ) + 0; + } +}; +#define shaderStaticTest_teeth_flashlight_ps30 psh_forgot_to_set_static_FLASHLIGHTDEPTHFILTERMODE + 0 +class teeth_flashlight_ps30_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +private: + int m_nFLASHLIGHTSHADOWS; +#ifdef _DEBUG + bool m_bFLASHLIGHTSHADOWS; +#endif +public: + void SetFLASHLIGHTSHADOWS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFLASHLIGHTSHADOWS = i; +#ifdef _DEBUG + m_bFLASHLIGHTSHADOWS = true; +#endif + } + void SetFLASHLIGHTSHADOWS( bool i ) + { + m_nFLASHLIGHTSHADOWS = i ? 1 : 0; +#ifdef _DEBUG + m_bFLASHLIGHTSHADOWS = true; +#endif + } +public: + teeth_flashlight_ps30_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; +#ifdef _DEBUG + m_bFLASHLIGHTSHADOWS = false; +#endif // _DEBUG + m_nFLASHLIGHTSHADOWS = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE && m_bFLASHLIGHTSHADOWS; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + ( 2 * m_nFLASHLIGHTSHADOWS ) + 0; + } +}; +#define shaderDynamicTest_teeth_flashlight_ps30 psh_forgot_to_set_dynamic_PIXELFOGTYPE + psh_forgot_to_set_dynamic_FLASHLIGHTSHADOWS + 0 diff --git a/materialsystem/stdshaders/fxctmp9/teeth_flashlight_vs20.inc b/materialsystem/stdshaders/fxctmp9/teeth_flashlight_vs20.inc new file mode 100644 index 0000000..438bdab --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/teeth_flashlight_vs20.inc @@ -0,0 +1,137 @@ +#include "shaderlib/cshader.h" +class teeth_flashlight_vs20_Static_Index +{ +private: + int m_nINTRO; +#ifdef _DEBUG + bool m_bINTRO; +#endif +public: + void SetINTRO( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nINTRO = i; +#ifdef _DEBUG + m_bINTRO = true; +#endif + } + void SetINTRO( bool i ) + { + m_nINTRO = i ? 1 : 0; +#ifdef _DEBUG + m_bINTRO = true; +#endif + } +public: + teeth_flashlight_vs20_Static_Index( ) + { +#ifdef _DEBUG + m_bINTRO = false; +#endif // _DEBUG + m_nINTRO = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bINTRO; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 8 * m_nINTRO ) + 0; + } +}; +#define shaderStaticTest_teeth_flashlight_vs20 vsh_forgot_to_set_static_INTRO + 0 +class teeth_flashlight_vs20_Dynamic_Index +{ +private: + int m_nCOMPRESSED_VERTS; +#ifdef _DEBUG + bool m_bCOMPRESSED_VERTS; +#endif +public: + void SetCOMPRESSED_VERTS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOMPRESSED_VERTS = i; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } + void SetCOMPRESSED_VERTS( bool i ) + { + m_nCOMPRESSED_VERTS = i ? 1 : 0; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +public: + teeth_flashlight_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = false; +#endif // _DEBUG + m_nCOMPRESSED_VERTS = 0; +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bCOMPRESSED_VERTS && m_bDOWATERFOG && m_bSKINNING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCOMPRESSED_VERTS ) + ( 2 * m_nDOWATERFOG ) + ( 4 * m_nSKINNING ) + 0; + } +}; +#define shaderDynamicTest_teeth_flashlight_vs20 vsh_forgot_to_set_dynamic_COMPRESSED_VERTS + vsh_forgot_to_set_dynamic_DOWATERFOG + vsh_forgot_to_set_dynamic_SKINNING + 0 diff --git a/materialsystem/stdshaders/fxctmp9/teeth_flashlight_vs30.inc b/materialsystem/stdshaders/fxctmp9/teeth_flashlight_vs30.inc new file mode 100644 index 0000000..f31e877 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/teeth_flashlight_vs30.inc @@ -0,0 +1,162 @@ +#include "shaderlib/cshader.h" +class teeth_flashlight_vs30_Static_Index +{ +private: + int m_nINTRO; +#ifdef _DEBUG + bool m_bINTRO; +#endif +public: + void SetINTRO( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nINTRO = i; +#ifdef _DEBUG + m_bINTRO = true; +#endif + } + void SetINTRO( bool i ) + { + m_nINTRO = i ? 1 : 0; +#ifdef _DEBUG + m_bINTRO = true; +#endif + } +public: + teeth_flashlight_vs30_Static_Index( ) + { +#ifdef _DEBUG + m_bINTRO = false; +#endif // _DEBUG + m_nINTRO = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bINTRO; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 16 * m_nINTRO ) + 0; + } +}; +#define shaderStaticTest_teeth_flashlight_vs30 vsh_forgot_to_set_static_INTRO + 0 +class teeth_flashlight_vs30_Dynamic_Index +{ +private: + int m_nCOMPRESSED_VERTS; +#ifdef _DEBUG + bool m_bCOMPRESSED_VERTS; +#endif +public: + void SetCOMPRESSED_VERTS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOMPRESSED_VERTS = i; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } + void SetCOMPRESSED_VERTS( bool i ) + { + m_nCOMPRESSED_VERTS = i ? 1 : 0; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +private: + int m_nMORPHING; +#ifdef _DEBUG + bool m_bMORPHING; +#endif +public: + void SetMORPHING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nMORPHING = i; +#ifdef _DEBUG + m_bMORPHING = true; +#endif + } + void SetMORPHING( bool i ) + { + m_nMORPHING = i ? 1 : 0; +#ifdef _DEBUG + m_bMORPHING = true; +#endif + } +public: + teeth_flashlight_vs30_Dynamic_Index() + { +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = false; +#endif // _DEBUG + m_nCOMPRESSED_VERTS = 0; +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; +#ifdef _DEBUG + m_bMORPHING = false; +#endif // _DEBUG + m_nMORPHING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bCOMPRESSED_VERTS && m_bDOWATERFOG && m_bSKINNING && m_bMORPHING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCOMPRESSED_VERTS ) + ( 2 * m_nDOWATERFOG ) + ( 4 * m_nSKINNING ) + ( 8 * m_nMORPHING ) + 0; + } +}; +#define shaderDynamicTest_teeth_flashlight_vs30 vsh_forgot_to_set_dynamic_COMPRESSED_VERTS + vsh_forgot_to_set_dynamic_DOWATERFOG + vsh_forgot_to_set_dynamic_SKINNING + vsh_forgot_to_set_dynamic_MORPHING + 0 diff --git a/materialsystem/stdshaders/fxctmp9/teeth_ps20.inc b/materialsystem/stdshaders/fxctmp9/teeth_ps20.inc new file mode 100644 index 0000000..92dc85c --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/teeth_ps20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class teeth_ps20_Static_Index +{ +public: + teeth_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_teeth_ps20 0 +class teeth_ps20_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + teeth_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_teeth_ps20 psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9/teeth_ps20b.inc b/materialsystem/stdshaders/fxctmp9/teeth_ps20b.inc new file mode 100644 index 0000000..3678080 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/teeth_ps20b.inc @@ -0,0 +1,112 @@ +#include "shaderlib/cshader.h" +class teeth_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + teeth_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 4 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_teeth_ps20b 0 +class teeth_ps20b_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +private: + int m_nWRITE_DEPTH_TO_DESTALPHA; +#ifdef _DEBUG + bool m_bWRITE_DEPTH_TO_DESTALPHA; +#endif +public: + void SetWRITE_DEPTH_TO_DESTALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nWRITE_DEPTH_TO_DESTALPHA = i; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = true; +#endif + } + void SetWRITE_DEPTH_TO_DESTALPHA( bool i ) + { + m_nWRITE_DEPTH_TO_DESTALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = true; +#endif + } +public: + teeth_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = false; +#endif // _DEBUG + m_nWRITE_DEPTH_TO_DESTALPHA = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE && m_bWRITE_DEPTH_TO_DESTALPHA; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + ( 2 * m_nWRITE_DEPTH_TO_DESTALPHA ) + 0; + } +}; +#define shaderDynamicTest_teeth_ps20b psh_forgot_to_set_dynamic_PIXELFOGTYPE + psh_forgot_to_set_dynamic_WRITE_DEPTH_TO_DESTALPHA + 0 diff --git a/materialsystem/stdshaders/fxctmp9/teeth_ps30.inc b/materialsystem/stdshaders/fxctmp9/teeth_ps30.inc new file mode 100644 index 0000000..58cdd07 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/teeth_ps30.inc @@ -0,0 +1,112 @@ +#include "shaderlib/cshader.h" +class teeth_ps30_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + teeth_ps30_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 4 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_teeth_ps30 0 +class teeth_ps30_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +private: + int m_nWRITE_DEPTH_TO_DESTALPHA; +#ifdef _DEBUG + bool m_bWRITE_DEPTH_TO_DESTALPHA; +#endif +public: + void SetWRITE_DEPTH_TO_DESTALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nWRITE_DEPTH_TO_DESTALPHA = i; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = true; +#endif + } + void SetWRITE_DEPTH_TO_DESTALPHA( bool i ) + { + m_nWRITE_DEPTH_TO_DESTALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = true; +#endif + } +public: + teeth_ps30_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = false; +#endif // _DEBUG + m_nWRITE_DEPTH_TO_DESTALPHA = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE && m_bWRITE_DEPTH_TO_DESTALPHA; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + ( 2 * m_nWRITE_DEPTH_TO_DESTALPHA ) + 0; + } +}; +#define shaderDynamicTest_teeth_ps30 psh_forgot_to_set_dynamic_PIXELFOGTYPE + psh_forgot_to_set_dynamic_WRITE_DEPTH_TO_DESTALPHA + 0 diff --git a/materialsystem/stdshaders/fxctmp9/teeth_vs20.inc b/materialsystem/stdshaders/fxctmp9/teeth_vs20.inc new file mode 100644 index 0000000..5103e17 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/teeth_vs20.inc @@ -0,0 +1,237 @@ +#include "shaderlib/cshader.h" +class teeth_vs20_Static_Index +{ +private: + int m_nINTRO; +#ifdef _DEBUG + bool m_bINTRO; +#endif +public: + void SetINTRO( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nINTRO = i; +#ifdef _DEBUG + m_bINTRO = true; +#endif + } + void SetINTRO( bool i ) + { + m_nINTRO = i ? 1 : 0; +#ifdef _DEBUG + m_bINTRO = true; +#endif + } +private: + int m_nUSE_STATIC_CONTROL_FLOW; +#ifdef _DEBUG + bool m_bUSE_STATIC_CONTROL_FLOW; +#endif +public: + void SetUSE_STATIC_CONTROL_FLOW( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nUSE_STATIC_CONTROL_FLOW = i; +#ifdef _DEBUG + m_bUSE_STATIC_CONTROL_FLOW = true; +#endif + } + void SetUSE_STATIC_CONTROL_FLOW( bool i ) + { + m_nUSE_STATIC_CONTROL_FLOW = i ? 1 : 0; +#ifdef _DEBUG + m_bUSE_STATIC_CONTROL_FLOW = true; +#endif + } +public: + teeth_vs20_Static_Index( ) + { +#ifdef _DEBUG + m_bINTRO = false; +#endif // _DEBUG + m_nINTRO = 0; +#ifdef _DEBUG + m_bUSE_STATIC_CONTROL_FLOW = false; +#endif // _DEBUG + m_nUSE_STATIC_CONTROL_FLOW = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bINTRO && m_bUSE_STATIC_CONTROL_FLOW; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 96 * m_nINTRO ) + ( 192 * m_nUSE_STATIC_CONTROL_FLOW ) + 0; + } +}; +#define shaderStaticTest_teeth_vs20 vsh_forgot_to_set_static_INTRO + vsh_forgot_to_set_static_USE_STATIC_CONTROL_FLOW + 0 +class teeth_vs20_Dynamic_Index +{ +private: + int m_nCOMPRESSED_VERTS; +#ifdef _DEBUG + bool m_bCOMPRESSED_VERTS; +#endif +public: + void SetCOMPRESSED_VERTS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOMPRESSED_VERTS = i; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } + void SetCOMPRESSED_VERTS( bool i ) + { + m_nCOMPRESSED_VERTS = i ? 1 : 0; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +private: + int m_nDYNAMIC_LIGHT; +#ifdef _DEBUG + bool m_bDYNAMIC_LIGHT; +#endif +public: + void SetDYNAMIC_LIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDYNAMIC_LIGHT = i; +#ifdef _DEBUG + m_bDYNAMIC_LIGHT = true; +#endif + } + void SetDYNAMIC_LIGHT( bool i ) + { + m_nDYNAMIC_LIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bDYNAMIC_LIGHT = true; +#endif + } +private: + int m_nSTATIC_LIGHT; +#ifdef _DEBUG + bool m_bSTATIC_LIGHT; +#endif +public: + void SetSTATIC_LIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSTATIC_LIGHT = i; +#ifdef _DEBUG + m_bSTATIC_LIGHT = true; +#endif + } + void SetSTATIC_LIGHT( bool i ) + { + m_nSTATIC_LIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bSTATIC_LIGHT = true; +#endif + } +private: + int m_nNUM_LIGHTS; +#ifdef _DEBUG + bool m_bNUM_LIGHTS; +#endif +public: + void SetNUM_LIGHTS( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nNUM_LIGHTS = i; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } + void SetNUM_LIGHTS( bool i ) + { + m_nNUM_LIGHTS = i ? 1 : 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } +public: + teeth_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = false; +#endif // _DEBUG + m_nCOMPRESSED_VERTS = 0; +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; +#ifdef _DEBUG + m_bDYNAMIC_LIGHT = false; +#endif // _DEBUG + m_nDYNAMIC_LIGHT = 0; +#ifdef _DEBUG + m_bSTATIC_LIGHT = false; +#endif // _DEBUG + m_nSTATIC_LIGHT = 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = false; +#endif // _DEBUG + m_nNUM_LIGHTS = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bCOMPRESSED_VERTS && m_bDOWATERFOG && m_bSKINNING && m_bDYNAMIC_LIGHT && m_bSTATIC_LIGHT && m_bNUM_LIGHTS; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCOMPRESSED_VERTS ) + ( 2 * m_nDOWATERFOG ) + ( 4 * m_nSKINNING ) + ( 8 * m_nDYNAMIC_LIGHT ) + ( 16 * m_nSTATIC_LIGHT ) + ( 32 * m_nNUM_LIGHTS ) + 0; + } +}; +#define shaderDynamicTest_teeth_vs20 vsh_forgot_to_set_dynamic_COMPRESSED_VERTS + vsh_forgot_to_set_dynamic_DOWATERFOG + vsh_forgot_to_set_dynamic_SKINNING + vsh_forgot_to_set_dynamic_DYNAMIC_LIGHT + vsh_forgot_to_set_dynamic_STATIC_LIGHT + vsh_forgot_to_set_dynamic_NUM_LIGHTS + 0 diff --git a/materialsystem/stdshaders/fxctmp9/teeth_vs30.inc b/materialsystem/stdshaders/fxctmp9/teeth_vs30.inc new file mode 100644 index 0000000..4e07e03 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/teeth_vs30.inc @@ -0,0 +1,212 @@ +#include "shaderlib/cshader.h" +class teeth_vs30_Static_Index +{ +private: + int m_nINTRO; +#ifdef _DEBUG + bool m_bINTRO; +#endif +public: + void SetINTRO( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nINTRO = i; +#ifdef _DEBUG + m_bINTRO = true; +#endif + } + void SetINTRO( bool i ) + { + m_nINTRO = i ? 1 : 0; +#ifdef _DEBUG + m_bINTRO = true; +#endif + } +public: + teeth_vs30_Static_Index( ) + { +#ifdef _DEBUG + m_bINTRO = false; +#endif // _DEBUG + m_nINTRO = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bINTRO; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 64 * m_nINTRO ) + 0; + } +}; +#define shaderStaticTest_teeth_vs30 vsh_forgot_to_set_static_INTRO + 0 +class teeth_vs30_Dynamic_Index +{ +private: + int m_nCOMPRESSED_VERTS; +#ifdef _DEBUG + bool m_bCOMPRESSED_VERTS; +#endif +public: + void SetCOMPRESSED_VERTS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOMPRESSED_VERTS = i; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } + void SetCOMPRESSED_VERTS( bool i ) + { + m_nCOMPRESSED_VERTS = i ? 1 : 0; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +private: + int m_nDYNAMIC_LIGHT; +#ifdef _DEBUG + bool m_bDYNAMIC_LIGHT; +#endif +public: + void SetDYNAMIC_LIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDYNAMIC_LIGHT = i; +#ifdef _DEBUG + m_bDYNAMIC_LIGHT = true; +#endif + } + void SetDYNAMIC_LIGHT( bool i ) + { + m_nDYNAMIC_LIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bDYNAMIC_LIGHT = true; +#endif + } +private: + int m_nSTATIC_LIGHT; +#ifdef _DEBUG + bool m_bSTATIC_LIGHT; +#endif +public: + void SetSTATIC_LIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSTATIC_LIGHT = i; +#ifdef _DEBUG + m_bSTATIC_LIGHT = true; +#endif + } + void SetSTATIC_LIGHT( bool i ) + { + m_nSTATIC_LIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bSTATIC_LIGHT = true; +#endif + } +private: + int m_nMORPHING; +#ifdef _DEBUG + bool m_bMORPHING; +#endif +public: + void SetMORPHING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nMORPHING = i; +#ifdef _DEBUG + m_bMORPHING = true; +#endif + } + void SetMORPHING( bool i ) + { + m_nMORPHING = i ? 1 : 0; +#ifdef _DEBUG + m_bMORPHING = true; +#endif + } +public: + teeth_vs30_Dynamic_Index() + { +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = false; +#endif // _DEBUG + m_nCOMPRESSED_VERTS = 0; +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; +#ifdef _DEBUG + m_bDYNAMIC_LIGHT = false; +#endif // _DEBUG + m_nDYNAMIC_LIGHT = 0; +#ifdef _DEBUG + m_bSTATIC_LIGHT = false; +#endif // _DEBUG + m_nSTATIC_LIGHT = 0; +#ifdef _DEBUG + m_bMORPHING = false; +#endif // _DEBUG + m_nMORPHING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bCOMPRESSED_VERTS && m_bDOWATERFOG && m_bSKINNING && m_bDYNAMIC_LIGHT && m_bSTATIC_LIGHT && m_bMORPHING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCOMPRESSED_VERTS ) + ( 2 * m_nDOWATERFOG ) + ( 4 * m_nSKINNING ) + ( 8 * m_nDYNAMIC_LIGHT ) + ( 16 * m_nSTATIC_LIGHT ) + ( 32 * m_nMORPHING ) + 0; + } +}; +#define shaderDynamicTest_teeth_vs30 vsh_forgot_to_set_dynamic_COMPRESSED_VERTS + vsh_forgot_to_set_dynamic_DOWATERFOG + vsh_forgot_to_set_dynamic_SKINNING + vsh_forgot_to_set_dynamic_DYNAMIC_LIGHT + vsh_forgot_to_set_dynamic_STATIC_LIGHT + vsh_forgot_to_set_dynamic_MORPHING + 0 diff --git a/materialsystem/stdshaders/fxctmp9/treeleaf_ps20.inc b/materialsystem/stdshaders/fxctmp9/treeleaf_ps20.inc new file mode 100644 index 0000000..c851ff5 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/treeleaf_ps20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class treeleaf_ps20_Static_Index +{ +public: + treeleaf_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_treeleaf_ps20 0 +class treeleaf_ps20_Dynamic_Index +{ +public: + treeleaf_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_treeleaf_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9/treeleaf_ps20b.inc b/materialsystem/stdshaders/fxctmp9/treeleaf_ps20b.inc new file mode 100644 index 0000000..dadb99d --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/treeleaf_ps20b.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class treeleaf_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + treeleaf_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_treeleaf_ps20b 0 +class treeleaf_ps20b_Dynamic_Index +{ +public: + treeleaf_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_treeleaf_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9/treeleaf_vs20.inc b/materialsystem/stdshaders/fxctmp9/treeleaf_vs20.inc new file mode 100644 index 0000000..fdd9e28 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/treeleaf_vs20.inc @@ -0,0 +1,162 @@ +#include "shaderlib/cshader.h" +class treeleaf_vs20_Static_Index +{ +private: + int m_nHALFLAMBERT; +#ifdef _DEBUG + bool m_bHALFLAMBERT; +#endif +public: + void SetHALFLAMBERT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHALFLAMBERT = i; +#ifdef _DEBUG + m_bHALFLAMBERT = true; +#endif + } + void SetHALFLAMBERT( bool i ) + { + m_nHALFLAMBERT = i ? 1 : 0; +#ifdef _DEBUG + m_bHALFLAMBERT = true; +#endif + } +private: + int m_nUSE_STATIC_CONTROL_FLOW; +#ifdef _DEBUG + bool m_bUSE_STATIC_CONTROL_FLOW; +#endif +public: + void SetUSE_STATIC_CONTROL_FLOW( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nUSE_STATIC_CONTROL_FLOW = i; +#ifdef _DEBUG + m_bUSE_STATIC_CONTROL_FLOW = true; +#endif + } + void SetUSE_STATIC_CONTROL_FLOW( bool i ) + { + m_nUSE_STATIC_CONTROL_FLOW = i ? 1 : 0; +#ifdef _DEBUG + m_bUSE_STATIC_CONTROL_FLOW = true; +#endif + } +public: + treeleaf_vs20_Static_Index( ) + { +#ifdef _DEBUG + m_bHALFLAMBERT = false; +#endif // _DEBUG + m_nHALFLAMBERT = 0; +#ifdef _DEBUG + m_bUSE_STATIC_CONTROL_FLOW = false; +#endif // _DEBUG + m_nUSE_STATIC_CONTROL_FLOW = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bHALFLAMBERT && m_bUSE_STATIC_CONTROL_FLOW; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 12 * m_nHALFLAMBERT ) + ( 24 * m_nUSE_STATIC_CONTROL_FLOW ) + 0; + } +}; +#define shaderStaticTest_treeleaf_vs20 vsh_forgot_to_set_static_HALFLAMBERT + vsh_forgot_to_set_static_USE_STATIC_CONTROL_FLOW + 0 +class treeleaf_vs20_Dynamic_Index +{ +private: + int m_nDYNAMIC_LIGHT; +#ifdef _DEBUG + bool m_bDYNAMIC_LIGHT; +#endif +public: + void SetDYNAMIC_LIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDYNAMIC_LIGHT = i; +#ifdef _DEBUG + m_bDYNAMIC_LIGHT = true; +#endif + } + void SetDYNAMIC_LIGHT( bool i ) + { + m_nDYNAMIC_LIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bDYNAMIC_LIGHT = true; +#endif + } +private: + int m_nSTATIC_LIGHT; +#ifdef _DEBUG + bool m_bSTATIC_LIGHT; +#endif +public: + void SetSTATIC_LIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSTATIC_LIGHT = i; +#ifdef _DEBUG + m_bSTATIC_LIGHT = true; +#endif + } + void SetSTATIC_LIGHT( bool i ) + { + m_nSTATIC_LIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bSTATIC_LIGHT = true; +#endif + } +private: + int m_nNUM_LIGHTS; +#ifdef _DEBUG + bool m_bNUM_LIGHTS; +#endif +public: + void SetNUM_LIGHTS( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nNUM_LIGHTS = i; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } + void SetNUM_LIGHTS( bool i ) + { + m_nNUM_LIGHTS = i ? 1 : 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } +public: + treeleaf_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bDYNAMIC_LIGHT = false; +#endif // _DEBUG + m_nDYNAMIC_LIGHT = 0; +#ifdef _DEBUG + m_bSTATIC_LIGHT = false; +#endif // _DEBUG + m_nSTATIC_LIGHT = 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = false; +#endif // _DEBUG + m_nNUM_LIGHTS = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDYNAMIC_LIGHT && m_bSTATIC_LIGHT && m_bNUM_LIGHTS; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDYNAMIC_LIGHT ) + ( 2 * m_nSTATIC_LIGHT ) + ( 4 * m_nNUM_LIGHTS ) + 0; + } +}; +#define shaderDynamicTest_treeleaf_vs20 vsh_forgot_to_set_dynamic_DYNAMIC_LIGHT + vsh_forgot_to_set_dynamic_STATIC_LIGHT + vsh_forgot_to_set_dynamic_NUM_LIGHTS + 0 diff --git a/materialsystem/stdshaders/fxctmp9/unlitgeneric_lightingonly_vs11.inc b/materialsystem/stdshaders/fxctmp9/unlitgeneric_lightingonly_vs11.inc new file mode 100644 index 0000000..5f6ea9a --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/unlitgeneric_lightingonly_vs11.inc @@ -0,0 +1,84 @@ +class unlitgeneric_lightingonly_vs11_Static_Index +{ +public: + unlitgeneric_lightingonly_vs11_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_unlitgeneric_lightingonly_vs11 0 +class unlitgeneric_lightingonly_vs11_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nNUM_BONES; +#ifdef _DEBUG + bool m_bNUM_BONES; +#endif +public: + void SetNUM_BONES( int i ) + { + Assert( i >= 0 && i <= 3 ); + m_nNUM_BONES = i; +#ifdef _DEBUG + m_bNUM_BONES = true; +#endif + } + void SetNUM_BONES( bool i ) + { + m_nNUM_BONES = i ? 1 : 0; +#ifdef _DEBUG + m_bNUM_BONES = true; +#endif + } +public: + unlitgeneric_lightingonly_vs11_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bNUM_BONES = false; +#endif // _DEBUG + m_nNUM_BONES = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG && m_bNUM_BONES; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + ( 2 * m_nNUM_BONES ) + 0; + } +}; +#define shaderDynamicTest_unlitgeneric_lightingonly_vs11 vsh_forgot_to_set_dynamic_DOWATERFOG + vsh_forgot_to_set_dynamic_NUM_BONES + 0 diff --git a/materialsystem/stdshaders/fxctmp9/unlitgeneric_maskbasebydetailalpha_ps11.inc b/materialsystem/stdshaders/fxctmp9/unlitgeneric_maskbasebydetailalpha_ps11.inc new file mode 100644 index 0000000..8b4279e --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/unlitgeneric_maskbasebydetailalpha_ps11.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class unlitgeneric_maskbasebydetailalpha_ps11_Static_Index +{ +public: + unlitgeneric_maskbasebydetailalpha_ps11_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_unlitgeneric_maskbasebydetailalpha_ps11 0 +class unlitgeneric_maskbasebydetailalpha_ps11_Dynamic_Index +{ +public: + unlitgeneric_maskbasebydetailalpha_ps11_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_unlitgeneric_maskbasebydetailalpha_ps11 0 diff --git a/materialsystem/stdshaders/fxctmp9/unlitgeneric_notexture_ps11.inc b/materialsystem/stdshaders/fxctmp9/unlitgeneric_notexture_ps11.inc new file mode 100644 index 0000000..5a684db --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/unlitgeneric_notexture_ps11.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class unlitgeneric_notexture_ps11_Static_Index +{ +public: + unlitgeneric_notexture_ps11_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_unlitgeneric_notexture_ps11 0 +class unlitgeneric_notexture_ps11_Dynamic_Index +{ +public: + unlitgeneric_notexture_ps11_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_unlitgeneric_notexture_ps11 0 diff --git a/materialsystem/stdshaders/fxctmp9/unlitgeneric_notexture_ps20.inc b/materialsystem/stdshaders/fxctmp9/unlitgeneric_notexture_ps20.inc new file mode 100644 index 0000000..545fe54 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/unlitgeneric_notexture_ps20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class unlitgeneric_notexture_ps20_Static_Index +{ +public: + unlitgeneric_notexture_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_unlitgeneric_notexture_ps20 0 +class unlitgeneric_notexture_ps20_Dynamic_Index +{ +public: + unlitgeneric_notexture_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_unlitgeneric_notexture_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9/unlitgeneric_notexture_ps20b.inc b/materialsystem/stdshaders/fxctmp9/unlitgeneric_notexture_ps20b.inc new file mode 100644 index 0000000..bc3534d --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/unlitgeneric_notexture_ps20b.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class unlitgeneric_notexture_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + unlitgeneric_notexture_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_unlitgeneric_notexture_ps20b 0 +class unlitgeneric_notexture_ps20b_Dynamic_Index +{ +public: + unlitgeneric_notexture_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_unlitgeneric_notexture_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9/unlitgeneric_ps11.inc b/materialsystem/stdshaders/fxctmp9/unlitgeneric_ps11.inc new file mode 100644 index 0000000..cbce8db --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/unlitgeneric_ps11.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class unlitgeneric_ps11_Static_Index +{ +public: + unlitgeneric_ps11_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_unlitgeneric_ps11 0 +class unlitgeneric_ps11_Dynamic_Index +{ +public: + unlitgeneric_ps11_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_unlitgeneric_ps11 0 diff --git a/materialsystem/stdshaders/fxctmp9/unlitgeneric_ps20.inc b/materialsystem/stdshaders/fxctmp9/unlitgeneric_ps20.inc new file mode 100644 index 0000000..6a257cc --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/unlitgeneric_ps20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class unlitgeneric_ps20_Static_Index +{ +public: + unlitgeneric_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_unlitgeneric_ps20 0 +class unlitgeneric_ps20_Dynamic_Index +{ +public: + unlitgeneric_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_unlitgeneric_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9/unlitgeneric_ps20b.inc b/materialsystem/stdshaders/fxctmp9/unlitgeneric_ps20b.inc new file mode 100644 index 0000000..06d56ee --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/unlitgeneric_ps20b.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class unlitgeneric_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + unlitgeneric_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_unlitgeneric_ps20b 0 +class unlitgeneric_ps20b_Dynamic_Index +{ +public: + unlitgeneric_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_unlitgeneric_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9/unlitgeneric_vs20.inc b/materialsystem/stdshaders/fxctmp9/unlitgeneric_vs20.inc new file mode 100644 index 0000000..9111529 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/unlitgeneric_vs20.inc @@ -0,0 +1,137 @@ +#include "shaderlib/cshader.h" +class unlitgeneric_vs20_Static_Index +{ +private: + int m_nVERTEXCOLOR; +#ifdef _DEBUG + bool m_bVERTEXCOLOR; +#endif +public: + void SetVERTEXCOLOR( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nVERTEXCOLOR = i; +#ifdef _DEBUG + m_bVERTEXCOLOR = true; +#endif + } + void SetVERTEXCOLOR( bool i ) + { + m_nVERTEXCOLOR = i ? 1 : 0; +#ifdef _DEBUG + m_bVERTEXCOLOR = true; +#endif + } +public: + unlitgeneric_vs20_Static_Index( ) + { +#ifdef _DEBUG + m_bVERTEXCOLOR = false; +#endif // _DEBUG + m_nVERTEXCOLOR = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bVERTEXCOLOR; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 8 * m_nVERTEXCOLOR ) + 0; + } +}; +#define shaderStaticTest_unlitgeneric_vs20 vsh_forgot_to_set_static_VERTEXCOLOR + 0 +class unlitgeneric_vs20_Dynamic_Index +{ +private: + int m_nCOMPRESSED_VERTS; +#ifdef _DEBUG + bool m_bCOMPRESSED_VERTS; +#endif +public: + void SetCOMPRESSED_VERTS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOMPRESSED_VERTS = i; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } + void SetCOMPRESSED_VERTS( bool i ) + { + m_nCOMPRESSED_VERTS = i ? 1 : 0; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +public: + unlitgeneric_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = false; +#endif // _DEBUG + m_nCOMPRESSED_VERTS = 0; +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bCOMPRESSED_VERTS && m_bDOWATERFOG && m_bSKINNING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCOMPRESSED_VERTS ) + ( 2 * m_nDOWATERFOG ) + ( 4 * m_nSKINNING ) + 0; + } +}; +#define shaderDynamicTest_unlitgeneric_vs20 vsh_forgot_to_set_dynamic_COMPRESSED_VERTS + vsh_forgot_to_set_dynamic_DOWATERFOG + vsh_forgot_to_set_dynamic_SKINNING + 0 diff --git a/materialsystem/stdshaders/fxctmp9/unlittwotexture_ps20.inc b/materialsystem/stdshaders/fxctmp9/unlittwotexture_ps20.inc new file mode 100644 index 0000000..175c3b3 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/unlittwotexture_ps20.inc @@ -0,0 +1,85 @@ +#include "shaderlib/cshader.h" +class unlittwotexture_ps20_Static_Index +{ +public: + unlittwotexture_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_unlittwotexture_ps20 0 +class unlittwotexture_ps20_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +private: + int m_nLIGHTING_PREVIEW; +#ifdef _DEBUG + bool m_bLIGHTING_PREVIEW; +#endif +public: + void SetLIGHTING_PREVIEW( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nLIGHTING_PREVIEW = i; +#ifdef _DEBUG + m_bLIGHTING_PREVIEW = true; +#endif + } + void SetLIGHTING_PREVIEW( bool i ) + { + m_nLIGHTING_PREVIEW = i ? 1 : 0; +#ifdef _DEBUG + m_bLIGHTING_PREVIEW = true; +#endif + } +public: + unlittwotexture_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; +#ifdef _DEBUG + m_bLIGHTING_PREVIEW = false; +#endif // _DEBUG + m_nLIGHTING_PREVIEW = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE && m_bLIGHTING_PREVIEW; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + ( 2 * m_nLIGHTING_PREVIEW ) + 0; + } +}; +#define shaderDynamicTest_unlittwotexture_ps20 psh_forgot_to_set_dynamic_PIXELFOGTYPE + psh_forgot_to_set_dynamic_LIGHTING_PREVIEW + 0 diff --git a/materialsystem/stdshaders/fxctmp9/unlittwotexture_ps20b.inc b/materialsystem/stdshaders/fxctmp9/unlittwotexture_ps20b.inc new file mode 100644 index 0000000..4e40dcc --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/unlittwotexture_ps20b.inc @@ -0,0 +1,137 @@ +#include "shaderlib/cshader.h" +class unlittwotexture_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + unlittwotexture_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 12 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_unlittwotexture_ps20b 0 +class unlittwotexture_ps20b_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +private: + int m_nLIGHTING_PREVIEW; +#ifdef _DEBUG + bool m_bLIGHTING_PREVIEW; +#endif +public: + void SetLIGHTING_PREVIEW( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nLIGHTING_PREVIEW = i; +#ifdef _DEBUG + m_bLIGHTING_PREVIEW = true; +#endif + } + void SetLIGHTING_PREVIEW( bool i ) + { + m_nLIGHTING_PREVIEW = i ? 1 : 0; +#ifdef _DEBUG + m_bLIGHTING_PREVIEW = true; +#endif + } +private: + int m_nWRITE_DEPTH_TO_DESTALPHA; +#ifdef _DEBUG + bool m_bWRITE_DEPTH_TO_DESTALPHA; +#endif +public: + void SetWRITE_DEPTH_TO_DESTALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nWRITE_DEPTH_TO_DESTALPHA = i; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = true; +#endif + } + void SetWRITE_DEPTH_TO_DESTALPHA( bool i ) + { + m_nWRITE_DEPTH_TO_DESTALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = true; +#endif + } +public: + unlittwotexture_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; +#ifdef _DEBUG + m_bLIGHTING_PREVIEW = false; +#endif // _DEBUG + m_nLIGHTING_PREVIEW = 0; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = false; +#endif // _DEBUG + m_nWRITE_DEPTH_TO_DESTALPHA = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE && m_bLIGHTING_PREVIEW && m_bWRITE_DEPTH_TO_DESTALPHA; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + ( 2 * m_nLIGHTING_PREVIEW ) + ( 6 * m_nWRITE_DEPTH_TO_DESTALPHA ) + 0; + } +}; +#define shaderDynamicTest_unlittwotexture_ps20b psh_forgot_to_set_dynamic_PIXELFOGTYPE + psh_forgot_to_set_dynamic_LIGHTING_PREVIEW + psh_forgot_to_set_dynamic_WRITE_DEPTH_TO_DESTALPHA + 0 diff --git a/materialsystem/stdshaders/fxctmp9/unlittwotexture_vs20.inc b/materialsystem/stdshaders/fxctmp9/unlittwotexture_vs20.inc new file mode 100644 index 0000000..a0da040 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/unlittwotexture_vs20.inc @@ -0,0 +1,110 @@ +#include "shaderlib/cshader.h" +class unlittwotexture_vs20_Static_Index +{ +public: + unlittwotexture_vs20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_unlittwotexture_vs20 0 +class unlittwotexture_vs20_Dynamic_Index +{ +private: + int m_nCOMPRESSED_VERTS; +#ifdef _DEBUG + bool m_bCOMPRESSED_VERTS; +#endif +public: + void SetCOMPRESSED_VERTS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOMPRESSED_VERTS = i; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } + void SetCOMPRESSED_VERTS( bool i ) + { + m_nCOMPRESSED_VERTS = i ? 1 : 0; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +public: + unlittwotexture_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = false; +#endif // _DEBUG + m_nCOMPRESSED_VERTS = 0; +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bCOMPRESSED_VERTS && m_bDOWATERFOG && m_bSKINNING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCOMPRESSED_VERTS ) + ( 2 * m_nDOWATERFOG ) + ( 4 * m_nSKINNING ) + 0; + } +}; +#define shaderDynamicTest_unlittwotexture_vs20 vsh_forgot_to_set_dynamic_COMPRESSED_VERTS + vsh_forgot_to_set_dynamic_DOWATERFOG + vsh_forgot_to_set_dynamic_SKINNING + 0 diff --git a/materialsystem/stdshaders/fxctmp9/vertexlit_and_unlit_generic_bump_ps20.inc b/materialsystem/stdshaders/fxctmp9/vertexlit_and_unlit_generic_bump_ps20.inc new file mode 100644 index 0000000..6d18282 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/vertexlit_and_unlit_generic_bump_ps20.inc @@ -0,0 +1,412 @@ +#include "shaderlib/cshader.h" +class vertexlit_and_unlit_generic_bump_ps20_Static_Index +{ +private: + int m_nCUBEMAP; +#ifdef _DEBUG + bool m_bCUBEMAP; +#endif +public: + void SetCUBEMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCUBEMAP = i; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } + void SetCUBEMAP( bool i ) + { + m_nCUBEMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } +private: + int m_nDIFFUSELIGHTING; +#ifdef _DEBUG + bool m_bDIFFUSELIGHTING; +#endif +public: + void SetDIFFUSELIGHTING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDIFFUSELIGHTING = i; +#ifdef _DEBUG + m_bDIFFUSELIGHTING = true; +#endif + } + void SetDIFFUSELIGHTING( bool i ) + { + m_nDIFFUSELIGHTING = i ? 1 : 0; +#ifdef _DEBUG + m_bDIFFUSELIGHTING = true; +#endif + } +private: + int m_nLIGHTWARPTEXTURE; +#ifdef _DEBUG + bool m_bLIGHTWARPTEXTURE; +#endif +public: + void SetLIGHTWARPTEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nLIGHTWARPTEXTURE = i; +#ifdef _DEBUG + m_bLIGHTWARPTEXTURE = true; +#endif + } + void SetLIGHTWARPTEXTURE( bool i ) + { + m_nLIGHTWARPTEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bLIGHTWARPTEXTURE = true; +#endif + } +private: + int m_nSELFILLUM; +#ifdef _DEBUG + bool m_bSELFILLUM; +#endif +public: + void SetSELFILLUM( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSELFILLUM = i; +#ifdef _DEBUG + m_bSELFILLUM = true; +#endif + } + void SetSELFILLUM( bool i ) + { + m_nSELFILLUM = i ? 1 : 0; +#ifdef _DEBUG + m_bSELFILLUM = true; +#endif + } +private: + int m_nSELFILLUMFRESNEL; +#ifdef _DEBUG + bool m_bSELFILLUMFRESNEL; +#endif +public: + void SetSELFILLUMFRESNEL( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSELFILLUMFRESNEL = i; +#ifdef _DEBUG + m_bSELFILLUMFRESNEL = true; +#endif + } + void SetSELFILLUMFRESNEL( bool i ) + { + m_nSELFILLUMFRESNEL = i ? 1 : 0; +#ifdef _DEBUG + m_bSELFILLUMFRESNEL = true; +#endif + } +private: + int m_nNORMALMAPALPHAENVMAPMASK; +#ifdef _DEBUG + bool m_bNORMALMAPALPHAENVMAPMASK; +#endif +public: + void SetNORMALMAPALPHAENVMAPMASK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nNORMALMAPALPHAENVMAPMASK = i; +#ifdef _DEBUG + m_bNORMALMAPALPHAENVMAPMASK = true; +#endif + } + void SetNORMALMAPALPHAENVMAPMASK( bool i ) + { + m_nNORMALMAPALPHAENVMAPMASK = i ? 1 : 0; +#ifdef _DEBUG + m_bNORMALMAPALPHAENVMAPMASK = true; +#endif + } +private: + int m_nHALFLAMBERT; +#ifdef _DEBUG + bool m_bHALFLAMBERT; +#endif +public: + void SetHALFLAMBERT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHALFLAMBERT = i; +#ifdef _DEBUG + m_bHALFLAMBERT = true; +#endif + } + void SetHALFLAMBERT( bool i ) + { + m_nHALFLAMBERT = i ? 1 : 0; +#ifdef _DEBUG + m_bHALFLAMBERT = true; +#endif + } +private: + int m_nFLASHLIGHT; +#ifdef _DEBUG + bool m_bFLASHLIGHT; +#endif +public: + void SetFLASHLIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFLASHLIGHT = i; +#ifdef _DEBUG + m_bFLASHLIGHT = true; +#endif + } + void SetFLASHLIGHT( bool i ) + { + m_nFLASHLIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bFLASHLIGHT = true; +#endif + } +private: + int m_nDETAILTEXTURE; +#ifdef _DEBUG + bool m_bDETAILTEXTURE; +#endif +public: + void SetDETAILTEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDETAILTEXTURE = i; +#ifdef _DEBUG + m_bDETAILTEXTURE = true; +#endif + } + void SetDETAILTEXTURE( bool i ) + { + m_nDETAILTEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bDETAILTEXTURE = true; +#endif + } +private: + int m_nDETAIL_BLEND_MODE; +#ifdef _DEBUG + bool m_bDETAIL_BLEND_MODE; +#endif +public: + void SetDETAIL_BLEND_MODE( int i ) + { + Assert( i >= 0 && i <= 6 ); + m_nDETAIL_BLEND_MODE = i; +#ifdef _DEBUG + m_bDETAIL_BLEND_MODE = true; +#endif + } + void SetDETAIL_BLEND_MODE( bool i ) + { + m_nDETAIL_BLEND_MODE = i ? 1 : 0; +#ifdef _DEBUG + m_bDETAIL_BLEND_MODE = true; +#endif + } +private: + int m_nBLENDTINTBYBASEALPHA; +#ifdef _DEBUG + bool m_bBLENDTINTBYBASEALPHA; +#endif +public: + void SetBLENDTINTBYBASEALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBLENDTINTBYBASEALPHA = i; +#ifdef _DEBUG + m_bBLENDTINTBYBASEALPHA = true; +#endif + } + void SetBLENDTINTBYBASEALPHA( bool i ) + { + m_nBLENDTINTBYBASEALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bBLENDTINTBYBASEALPHA = true; +#endif + } +public: + vertexlit_and_unlit_generic_bump_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCUBEMAP = false; +#endif // _DEBUG + m_nCUBEMAP = 0; +#ifdef _DEBUG + m_bDIFFUSELIGHTING = false; +#endif // _DEBUG + m_nDIFFUSELIGHTING = 0; +#ifdef _DEBUG + m_bLIGHTWARPTEXTURE = false; +#endif // _DEBUG + m_nLIGHTWARPTEXTURE = 0; +#ifdef _DEBUG + m_bSELFILLUM = false; +#endif // _DEBUG + m_nSELFILLUM = 0; +#ifdef _DEBUG + m_bSELFILLUMFRESNEL = false; +#endif // _DEBUG + m_nSELFILLUMFRESNEL = 0; +#ifdef _DEBUG + m_bNORMALMAPALPHAENVMAPMASK = false; +#endif // _DEBUG + m_nNORMALMAPALPHAENVMAPMASK = 0; +#ifdef _DEBUG + m_bHALFLAMBERT = false; +#endif // _DEBUG + m_nHALFLAMBERT = 0; +#ifdef _DEBUG + m_bFLASHLIGHT = false; +#endif // _DEBUG + m_nFLASHLIGHT = 0; +#ifdef _DEBUG + m_bDETAILTEXTURE = false; +#endif // _DEBUG + m_nDETAILTEXTURE = 0; +#ifdef _DEBUG + m_bDETAIL_BLEND_MODE = false; +#endif // _DEBUG + m_nDETAIL_BLEND_MODE = 0; +#ifdef _DEBUG + m_bBLENDTINTBYBASEALPHA = false; +#endif // _DEBUG + m_nBLENDTINTBYBASEALPHA = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCUBEMAP && m_bDIFFUSELIGHTING && m_bLIGHTWARPTEXTURE && m_bSELFILLUM && m_bSELFILLUMFRESNEL && m_bNORMALMAPALPHAENVMAPMASK && m_bHALFLAMBERT && m_bFLASHLIGHT && m_bDETAILTEXTURE && m_bDETAIL_BLEND_MODE && m_bBLENDTINTBYBASEALPHA; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 24 * m_nCUBEMAP ) + ( 48 * m_nDIFFUSELIGHTING ) + ( 96 * m_nLIGHTWARPTEXTURE ) + ( 192 * m_nSELFILLUM ) + ( 384 * m_nSELFILLUMFRESNEL ) + ( 768 * m_nNORMALMAPALPHAENVMAPMASK ) + ( 1536 * m_nHALFLAMBERT ) + ( 3072 * m_nFLASHLIGHT ) + ( 6144 * m_nDETAILTEXTURE ) + ( 12288 * m_nDETAIL_BLEND_MODE ) + ( 86016 * m_nBLENDTINTBYBASEALPHA ) + 0; + } +}; +#define shaderStaticTest_vertexlit_and_unlit_generic_bump_ps20 psh_forgot_to_set_static_CUBEMAP + psh_forgot_to_set_static_DIFFUSELIGHTING + psh_forgot_to_set_static_LIGHTWARPTEXTURE + psh_forgot_to_set_static_SELFILLUM + psh_forgot_to_set_static_SELFILLUMFRESNEL + psh_forgot_to_set_static_NORMALMAPALPHAENVMAPMASK + psh_forgot_to_set_static_HALFLAMBERT + psh_forgot_to_set_static_FLASHLIGHT + psh_forgot_to_set_static_DETAILTEXTURE + psh_forgot_to_set_static_DETAIL_BLEND_MODE + psh_forgot_to_set_static_BLENDTINTBYBASEALPHA + 0 +class vertexlit_and_unlit_generic_bump_ps20_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +private: + int m_nWRITEWATERFOGTODESTALPHA; +#ifdef _DEBUG + bool m_bWRITEWATERFOGTODESTALPHA; +#endif +public: + void SetWRITEWATERFOGTODESTALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nWRITEWATERFOGTODESTALPHA = i; +#ifdef _DEBUG + m_bWRITEWATERFOGTODESTALPHA = true; +#endif + } + void SetWRITEWATERFOGTODESTALPHA( bool i ) + { + m_nWRITEWATERFOGTODESTALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bWRITEWATERFOGTODESTALPHA = true; +#endif + } +private: + int m_nNUM_LIGHTS; +#ifdef _DEBUG + bool m_bNUM_LIGHTS; +#endif +public: + void SetNUM_LIGHTS( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nNUM_LIGHTS = i; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } + void SetNUM_LIGHTS( bool i ) + { + m_nNUM_LIGHTS = i ? 1 : 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } +private: + int m_nAMBIENT_LIGHT; +#ifdef _DEBUG + bool m_bAMBIENT_LIGHT; +#endif +public: + void SetAMBIENT_LIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nAMBIENT_LIGHT = i; +#ifdef _DEBUG + m_bAMBIENT_LIGHT = true; +#endif + } + void SetAMBIENT_LIGHT( bool i ) + { + m_nAMBIENT_LIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bAMBIENT_LIGHT = true; +#endif + } +public: + vertexlit_and_unlit_generic_bump_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; +#ifdef _DEBUG + m_bWRITEWATERFOGTODESTALPHA = false; +#endif // _DEBUG + m_nWRITEWATERFOGTODESTALPHA = 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = false; +#endif // _DEBUG + m_nNUM_LIGHTS = 0; +#ifdef _DEBUG + m_bAMBIENT_LIGHT = false; +#endif // _DEBUG + m_nAMBIENT_LIGHT = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE && m_bWRITEWATERFOGTODESTALPHA && m_bNUM_LIGHTS && m_bAMBIENT_LIGHT; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + ( 2 * m_nWRITEWATERFOGTODESTALPHA ) + ( 4 * m_nNUM_LIGHTS ) + ( 12 * m_nAMBIENT_LIGHT ) + 0; + } +}; +#define shaderDynamicTest_vertexlit_and_unlit_generic_bump_ps20 psh_forgot_to_set_dynamic_PIXELFOGTYPE + psh_forgot_to_set_dynamic_WRITEWATERFOGTODESTALPHA + psh_forgot_to_set_dynamic_NUM_LIGHTS + psh_forgot_to_set_dynamic_AMBIENT_LIGHT + 0 diff --git a/materialsystem/stdshaders/fxctmp9/vertexlit_and_unlit_generic_bump_ps20b.inc b/materialsystem/stdshaders/fxctmp9/vertexlit_and_unlit_generic_bump_ps20b.inc new file mode 100644 index 0000000..c73bd9d --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/vertexlit_and_unlit_generic_bump_ps20b.inc @@ -0,0 +1,412 @@ +#include "shaderlib/cshader.h" +class vertexlit_and_unlit_generic_bump_ps20b_Static_Index +{ +private: + int m_nCUBEMAP; +#ifdef _DEBUG + bool m_bCUBEMAP; +#endif +public: + void SetCUBEMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCUBEMAP = i; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } + void SetCUBEMAP( bool i ) + { + m_nCUBEMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } +private: + int m_nDIFFUSELIGHTING; +#ifdef _DEBUG + bool m_bDIFFUSELIGHTING; +#endif +public: + void SetDIFFUSELIGHTING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDIFFUSELIGHTING = i; +#ifdef _DEBUG + m_bDIFFUSELIGHTING = true; +#endif + } + void SetDIFFUSELIGHTING( bool i ) + { + m_nDIFFUSELIGHTING = i ? 1 : 0; +#ifdef _DEBUG + m_bDIFFUSELIGHTING = true; +#endif + } +private: + int m_nLIGHTWARPTEXTURE; +#ifdef _DEBUG + bool m_bLIGHTWARPTEXTURE; +#endif +public: + void SetLIGHTWARPTEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nLIGHTWARPTEXTURE = i; +#ifdef _DEBUG + m_bLIGHTWARPTEXTURE = true; +#endif + } + void SetLIGHTWARPTEXTURE( bool i ) + { + m_nLIGHTWARPTEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bLIGHTWARPTEXTURE = true; +#endif + } +private: + int m_nSELFILLUM; +#ifdef _DEBUG + bool m_bSELFILLUM; +#endif +public: + void SetSELFILLUM( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSELFILLUM = i; +#ifdef _DEBUG + m_bSELFILLUM = true; +#endif + } + void SetSELFILLUM( bool i ) + { + m_nSELFILLUM = i ? 1 : 0; +#ifdef _DEBUG + m_bSELFILLUM = true; +#endif + } +private: + int m_nSELFILLUMFRESNEL; +#ifdef _DEBUG + bool m_bSELFILLUMFRESNEL; +#endif +public: + void SetSELFILLUMFRESNEL( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSELFILLUMFRESNEL = i; +#ifdef _DEBUG + m_bSELFILLUMFRESNEL = true; +#endif + } + void SetSELFILLUMFRESNEL( bool i ) + { + m_nSELFILLUMFRESNEL = i ? 1 : 0; +#ifdef _DEBUG + m_bSELFILLUMFRESNEL = true; +#endif + } +private: + int m_nNORMALMAPALPHAENVMAPMASK; +#ifdef _DEBUG + bool m_bNORMALMAPALPHAENVMAPMASK; +#endif +public: + void SetNORMALMAPALPHAENVMAPMASK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nNORMALMAPALPHAENVMAPMASK = i; +#ifdef _DEBUG + m_bNORMALMAPALPHAENVMAPMASK = true; +#endif + } + void SetNORMALMAPALPHAENVMAPMASK( bool i ) + { + m_nNORMALMAPALPHAENVMAPMASK = i ? 1 : 0; +#ifdef _DEBUG + m_bNORMALMAPALPHAENVMAPMASK = true; +#endif + } +private: + int m_nHALFLAMBERT; +#ifdef _DEBUG + bool m_bHALFLAMBERT; +#endif +public: + void SetHALFLAMBERT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHALFLAMBERT = i; +#ifdef _DEBUG + m_bHALFLAMBERT = true; +#endif + } + void SetHALFLAMBERT( bool i ) + { + m_nHALFLAMBERT = i ? 1 : 0; +#ifdef _DEBUG + m_bHALFLAMBERT = true; +#endif + } +private: + int m_nFLASHLIGHT; +#ifdef _DEBUG + bool m_bFLASHLIGHT; +#endif +public: + void SetFLASHLIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFLASHLIGHT = i; +#ifdef _DEBUG + m_bFLASHLIGHT = true; +#endif + } + void SetFLASHLIGHT( bool i ) + { + m_nFLASHLIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bFLASHLIGHT = true; +#endif + } +private: + int m_nDETAILTEXTURE; +#ifdef _DEBUG + bool m_bDETAILTEXTURE; +#endif +public: + void SetDETAILTEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDETAILTEXTURE = i; +#ifdef _DEBUG + m_bDETAILTEXTURE = true; +#endif + } + void SetDETAILTEXTURE( bool i ) + { + m_nDETAILTEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bDETAILTEXTURE = true; +#endif + } +private: + int m_nDETAIL_BLEND_MODE; +#ifdef _DEBUG + bool m_bDETAIL_BLEND_MODE; +#endif +public: + void SetDETAIL_BLEND_MODE( int i ) + { + Assert( i >= 0 && i <= 6 ); + m_nDETAIL_BLEND_MODE = i; +#ifdef _DEBUG + m_bDETAIL_BLEND_MODE = true; +#endif + } + void SetDETAIL_BLEND_MODE( bool i ) + { + m_nDETAIL_BLEND_MODE = i ? 1 : 0; +#ifdef _DEBUG + m_bDETAIL_BLEND_MODE = true; +#endif + } +private: + int m_nFLASHLIGHTDEPTHFILTERMODE; +#ifdef _DEBUG + bool m_bFLASHLIGHTDEPTHFILTERMODE; +#endif +public: + void SetFLASHLIGHTDEPTHFILTERMODE( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nFLASHLIGHTDEPTHFILTERMODE = i; +#ifdef _DEBUG + m_bFLASHLIGHTDEPTHFILTERMODE = true; +#endif + } + void SetFLASHLIGHTDEPTHFILTERMODE( bool i ) + { + m_nFLASHLIGHTDEPTHFILTERMODE = i ? 1 : 0; +#ifdef _DEBUG + m_bFLASHLIGHTDEPTHFILTERMODE = true; +#endif + } +private: + int m_nBLENDTINTBYBASEALPHA; +#ifdef _DEBUG + bool m_bBLENDTINTBYBASEALPHA; +#endif +public: + void SetBLENDTINTBYBASEALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBLENDTINTBYBASEALPHA = i; +#ifdef _DEBUG + m_bBLENDTINTBYBASEALPHA = true; +#endif + } + void SetBLENDTINTBYBASEALPHA( bool i ) + { + m_nBLENDTINTBYBASEALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bBLENDTINTBYBASEALPHA = true; +#endif + } +public: + vertexlit_and_unlit_generic_bump_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCUBEMAP = false; +#endif // _DEBUG + m_nCUBEMAP = 0; +#ifdef _DEBUG + m_bDIFFUSELIGHTING = false; +#endif // _DEBUG + m_nDIFFUSELIGHTING = 0; +#ifdef _DEBUG + m_bLIGHTWARPTEXTURE = false; +#endif // _DEBUG + m_nLIGHTWARPTEXTURE = 0; +#ifdef _DEBUG + m_bSELFILLUM = false; +#endif // _DEBUG + m_nSELFILLUM = 0; +#ifdef _DEBUG + m_bSELFILLUMFRESNEL = false; +#endif // _DEBUG + m_nSELFILLUMFRESNEL = 0; +#ifdef _DEBUG + m_bNORMALMAPALPHAENVMAPMASK = false; +#endif // _DEBUG + m_nNORMALMAPALPHAENVMAPMASK = 0; +#ifdef _DEBUG + m_bHALFLAMBERT = false; +#endif // _DEBUG + m_nHALFLAMBERT = 0; +#ifdef _DEBUG + m_bFLASHLIGHT = false; +#endif // _DEBUG + m_nFLASHLIGHT = 0; +#ifdef _DEBUG + m_bDETAILTEXTURE = false; +#endif // _DEBUG + m_nDETAILTEXTURE = 0; +#ifdef _DEBUG + m_bDETAIL_BLEND_MODE = false; +#endif // _DEBUG + m_nDETAIL_BLEND_MODE = 0; +#ifdef _DEBUG + m_bFLASHLIGHTDEPTHFILTERMODE = false; +#endif // _DEBUG + m_nFLASHLIGHTDEPTHFILTERMODE = 0; +#ifdef _DEBUG + m_bBLENDTINTBYBASEALPHA = false; +#endif // _DEBUG + m_nBLENDTINTBYBASEALPHA = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCUBEMAP && m_bDIFFUSELIGHTING && m_bLIGHTWARPTEXTURE && m_bSELFILLUM && m_bSELFILLUMFRESNEL && m_bNORMALMAPALPHAENVMAPMASK && m_bHALFLAMBERT && m_bFLASHLIGHT && m_bDETAILTEXTURE && m_bDETAIL_BLEND_MODE && m_bFLASHLIGHTDEPTHFILTERMODE && m_bBLENDTINTBYBASEALPHA; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 20 * m_nCUBEMAP ) + ( 40 * m_nDIFFUSELIGHTING ) + ( 80 * m_nLIGHTWARPTEXTURE ) + ( 160 * m_nSELFILLUM ) + ( 320 * m_nSELFILLUMFRESNEL ) + ( 640 * m_nNORMALMAPALPHAENVMAPMASK ) + ( 1280 * m_nHALFLAMBERT ) + ( 2560 * m_nFLASHLIGHT ) + ( 5120 * m_nDETAILTEXTURE ) + ( 10240 * m_nDETAIL_BLEND_MODE ) + ( 71680 * m_nFLASHLIGHTDEPTHFILTERMODE ) + ( 215040 * m_nBLENDTINTBYBASEALPHA ) + 0; + } +}; +#define shaderStaticTest_vertexlit_and_unlit_generic_bump_ps20b psh_forgot_to_set_static_CUBEMAP + psh_forgot_to_set_static_DIFFUSELIGHTING + psh_forgot_to_set_static_LIGHTWARPTEXTURE + psh_forgot_to_set_static_SELFILLUM + psh_forgot_to_set_static_SELFILLUMFRESNEL + psh_forgot_to_set_static_NORMALMAPALPHAENVMAPMASK + psh_forgot_to_set_static_HALFLAMBERT + psh_forgot_to_set_static_FLASHLIGHT + psh_forgot_to_set_static_DETAILTEXTURE + psh_forgot_to_set_static_DETAIL_BLEND_MODE + psh_forgot_to_set_static_FLASHLIGHTDEPTHFILTERMODE + psh_forgot_to_set_static_BLENDTINTBYBASEALPHA + 0 +class vertexlit_and_unlit_generic_bump_ps20b_Dynamic_Index +{ +private: + int m_nNUM_LIGHTS; +#ifdef _DEBUG + bool m_bNUM_LIGHTS; +#endif +public: + void SetNUM_LIGHTS( int i ) + { + Assert( i >= 0 && i <= 4 ); + m_nNUM_LIGHTS = i; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } + void SetNUM_LIGHTS( bool i ) + { + m_nNUM_LIGHTS = i ? 1 : 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } +private: + int m_nAMBIENT_LIGHT; +#ifdef _DEBUG + bool m_bAMBIENT_LIGHT; +#endif +public: + void SetAMBIENT_LIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nAMBIENT_LIGHT = i; +#ifdef _DEBUG + m_bAMBIENT_LIGHT = true; +#endif + } + void SetAMBIENT_LIGHT( bool i ) + { + m_nAMBIENT_LIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bAMBIENT_LIGHT = true; +#endif + } +private: + int m_nFLASHLIGHTSHADOWS; +#ifdef _DEBUG + bool m_bFLASHLIGHTSHADOWS; +#endif +public: + void SetFLASHLIGHTSHADOWS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFLASHLIGHTSHADOWS = i; +#ifdef _DEBUG + m_bFLASHLIGHTSHADOWS = true; +#endif + } + void SetFLASHLIGHTSHADOWS( bool i ) + { + m_nFLASHLIGHTSHADOWS = i ? 1 : 0; +#ifdef _DEBUG + m_bFLASHLIGHTSHADOWS = true; +#endif + } +public: + vertexlit_and_unlit_generic_bump_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bNUM_LIGHTS = false; +#endif // _DEBUG + m_nNUM_LIGHTS = 0; +#ifdef _DEBUG + m_bAMBIENT_LIGHT = false; +#endif // _DEBUG + m_nAMBIENT_LIGHT = 0; +#ifdef _DEBUG + m_bFLASHLIGHTSHADOWS = false; +#endif // _DEBUG + m_nFLASHLIGHTSHADOWS = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bNUM_LIGHTS && m_bAMBIENT_LIGHT && m_bFLASHLIGHTSHADOWS; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nNUM_LIGHTS ) + ( 5 * m_nAMBIENT_LIGHT ) + ( 10 * m_nFLASHLIGHTSHADOWS ) + 0; + } +}; +#define shaderDynamicTest_vertexlit_and_unlit_generic_bump_ps20b psh_forgot_to_set_dynamic_NUM_LIGHTS + psh_forgot_to_set_dynamic_AMBIENT_LIGHT + psh_forgot_to_set_dynamic_FLASHLIGHTSHADOWS + 0 diff --git a/materialsystem/stdshaders/fxctmp9/vertexlit_and_unlit_generic_bump_ps30.inc b/materialsystem/stdshaders/fxctmp9/vertexlit_and_unlit_generic_bump_ps30.inc new file mode 100644 index 0000000..47ee38e --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/vertexlit_and_unlit_generic_bump_ps30.inc @@ -0,0 +1,412 @@ +#include "shaderlib/cshader.h" +class vertexlit_and_unlit_generic_bump_ps30_Static_Index +{ +private: + int m_nCUBEMAP; +#ifdef _DEBUG + bool m_bCUBEMAP; +#endif +public: + void SetCUBEMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCUBEMAP = i; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } + void SetCUBEMAP( bool i ) + { + m_nCUBEMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } +private: + int m_nDIFFUSELIGHTING; +#ifdef _DEBUG + bool m_bDIFFUSELIGHTING; +#endif +public: + void SetDIFFUSELIGHTING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDIFFUSELIGHTING = i; +#ifdef _DEBUG + m_bDIFFUSELIGHTING = true; +#endif + } + void SetDIFFUSELIGHTING( bool i ) + { + m_nDIFFUSELIGHTING = i ? 1 : 0; +#ifdef _DEBUG + m_bDIFFUSELIGHTING = true; +#endif + } +private: + int m_nLIGHTWARPTEXTURE; +#ifdef _DEBUG + bool m_bLIGHTWARPTEXTURE; +#endif +public: + void SetLIGHTWARPTEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nLIGHTWARPTEXTURE = i; +#ifdef _DEBUG + m_bLIGHTWARPTEXTURE = true; +#endif + } + void SetLIGHTWARPTEXTURE( bool i ) + { + m_nLIGHTWARPTEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bLIGHTWARPTEXTURE = true; +#endif + } +private: + int m_nSELFILLUM; +#ifdef _DEBUG + bool m_bSELFILLUM; +#endif +public: + void SetSELFILLUM( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSELFILLUM = i; +#ifdef _DEBUG + m_bSELFILLUM = true; +#endif + } + void SetSELFILLUM( bool i ) + { + m_nSELFILLUM = i ? 1 : 0; +#ifdef _DEBUG + m_bSELFILLUM = true; +#endif + } +private: + int m_nSELFILLUMFRESNEL; +#ifdef _DEBUG + bool m_bSELFILLUMFRESNEL; +#endif +public: + void SetSELFILLUMFRESNEL( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSELFILLUMFRESNEL = i; +#ifdef _DEBUG + m_bSELFILLUMFRESNEL = true; +#endif + } + void SetSELFILLUMFRESNEL( bool i ) + { + m_nSELFILLUMFRESNEL = i ? 1 : 0; +#ifdef _DEBUG + m_bSELFILLUMFRESNEL = true; +#endif + } +private: + int m_nNORMALMAPALPHAENVMAPMASK; +#ifdef _DEBUG + bool m_bNORMALMAPALPHAENVMAPMASK; +#endif +public: + void SetNORMALMAPALPHAENVMAPMASK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nNORMALMAPALPHAENVMAPMASK = i; +#ifdef _DEBUG + m_bNORMALMAPALPHAENVMAPMASK = true; +#endif + } + void SetNORMALMAPALPHAENVMAPMASK( bool i ) + { + m_nNORMALMAPALPHAENVMAPMASK = i ? 1 : 0; +#ifdef _DEBUG + m_bNORMALMAPALPHAENVMAPMASK = true; +#endif + } +private: + int m_nHALFLAMBERT; +#ifdef _DEBUG + bool m_bHALFLAMBERT; +#endif +public: + void SetHALFLAMBERT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHALFLAMBERT = i; +#ifdef _DEBUG + m_bHALFLAMBERT = true; +#endif + } + void SetHALFLAMBERT( bool i ) + { + m_nHALFLAMBERT = i ? 1 : 0; +#ifdef _DEBUG + m_bHALFLAMBERT = true; +#endif + } +private: + int m_nFLASHLIGHT; +#ifdef _DEBUG + bool m_bFLASHLIGHT; +#endif +public: + void SetFLASHLIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFLASHLIGHT = i; +#ifdef _DEBUG + m_bFLASHLIGHT = true; +#endif + } + void SetFLASHLIGHT( bool i ) + { + m_nFLASHLIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bFLASHLIGHT = true; +#endif + } +private: + int m_nDETAILTEXTURE; +#ifdef _DEBUG + bool m_bDETAILTEXTURE; +#endif +public: + void SetDETAILTEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDETAILTEXTURE = i; +#ifdef _DEBUG + m_bDETAILTEXTURE = true; +#endif + } + void SetDETAILTEXTURE( bool i ) + { + m_nDETAILTEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bDETAILTEXTURE = true; +#endif + } +private: + int m_nDETAIL_BLEND_MODE; +#ifdef _DEBUG + bool m_bDETAIL_BLEND_MODE; +#endif +public: + void SetDETAIL_BLEND_MODE( int i ) + { + Assert( i >= 0 && i <= 6 ); + m_nDETAIL_BLEND_MODE = i; +#ifdef _DEBUG + m_bDETAIL_BLEND_MODE = true; +#endif + } + void SetDETAIL_BLEND_MODE( bool i ) + { + m_nDETAIL_BLEND_MODE = i ? 1 : 0; +#ifdef _DEBUG + m_bDETAIL_BLEND_MODE = true; +#endif + } +private: + int m_nFLASHLIGHTDEPTHFILTERMODE; +#ifdef _DEBUG + bool m_bFLASHLIGHTDEPTHFILTERMODE; +#endif +public: + void SetFLASHLIGHTDEPTHFILTERMODE( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nFLASHLIGHTDEPTHFILTERMODE = i; +#ifdef _DEBUG + m_bFLASHLIGHTDEPTHFILTERMODE = true; +#endif + } + void SetFLASHLIGHTDEPTHFILTERMODE( bool i ) + { + m_nFLASHLIGHTDEPTHFILTERMODE = i ? 1 : 0; +#ifdef _DEBUG + m_bFLASHLIGHTDEPTHFILTERMODE = true; +#endif + } +private: + int m_nBLENDTINTBYBASEALPHA; +#ifdef _DEBUG + bool m_bBLENDTINTBYBASEALPHA; +#endif +public: + void SetBLENDTINTBYBASEALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBLENDTINTBYBASEALPHA = i; +#ifdef _DEBUG + m_bBLENDTINTBYBASEALPHA = true; +#endif + } + void SetBLENDTINTBYBASEALPHA( bool i ) + { + m_nBLENDTINTBYBASEALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bBLENDTINTBYBASEALPHA = true; +#endif + } +public: + vertexlit_and_unlit_generic_bump_ps30_Static_Index( ) + { +#ifdef _DEBUG + m_bCUBEMAP = false; +#endif // _DEBUG + m_nCUBEMAP = 0; +#ifdef _DEBUG + m_bDIFFUSELIGHTING = false; +#endif // _DEBUG + m_nDIFFUSELIGHTING = 0; +#ifdef _DEBUG + m_bLIGHTWARPTEXTURE = false; +#endif // _DEBUG + m_nLIGHTWARPTEXTURE = 0; +#ifdef _DEBUG + m_bSELFILLUM = false; +#endif // _DEBUG + m_nSELFILLUM = 0; +#ifdef _DEBUG + m_bSELFILLUMFRESNEL = false; +#endif // _DEBUG + m_nSELFILLUMFRESNEL = 0; +#ifdef _DEBUG + m_bNORMALMAPALPHAENVMAPMASK = false; +#endif // _DEBUG + m_nNORMALMAPALPHAENVMAPMASK = 0; +#ifdef _DEBUG + m_bHALFLAMBERT = false; +#endif // _DEBUG + m_nHALFLAMBERT = 0; +#ifdef _DEBUG + m_bFLASHLIGHT = false; +#endif // _DEBUG + m_nFLASHLIGHT = 0; +#ifdef _DEBUG + m_bDETAILTEXTURE = false; +#endif // _DEBUG + m_nDETAILTEXTURE = 0; +#ifdef _DEBUG + m_bDETAIL_BLEND_MODE = false; +#endif // _DEBUG + m_nDETAIL_BLEND_MODE = 0; +#ifdef _DEBUG + m_bFLASHLIGHTDEPTHFILTERMODE = false; +#endif // _DEBUG + m_nFLASHLIGHTDEPTHFILTERMODE = 0; +#ifdef _DEBUG + m_bBLENDTINTBYBASEALPHA = false; +#endif // _DEBUG + m_nBLENDTINTBYBASEALPHA = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCUBEMAP && m_bDIFFUSELIGHTING && m_bLIGHTWARPTEXTURE && m_bSELFILLUM && m_bSELFILLUMFRESNEL && m_bNORMALMAPALPHAENVMAPMASK && m_bHALFLAMBERT && m_bFLASHLIGHT && m_bDETAILTEXTURE && m_bDETAIL_BLEND_MODE && m_bFLASHLIGHTDEPTHFILTERMODE && m_bBLENDTINTBYBASEALPHA; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 20 * m_nCUBEMAP ) + ( 40 * m_nDIFFUSELIGHTING ) + ( 80 * m_nLIGHTWARPTEXTURE ) + ( 160 * m_nSELFILLUM ) + ( 320 * m_nSELFILLUMFRESNEL ) + ( 640 * m_nNORMALMAPALPHAENVMAPMASK ) + ( 1280 * m_nHALFLAMBERT ) + ( 2560 * m_nFLASHLIGHT ) + ( 5120 * m_nDETAILTEXTURE ) + ( 10240 * m_nDETAIL_BLEND_MODE ) + ( 71680 * m_nFLASHLIGHTDEPTHFILTERMODE ) + ( 215040 * m_nBLENDTINTBYBASEALPHA ) + 0; + } +}; +#define shaderStaticTest_vertexlit_and_unlit_generic_bump_ps30 psh_forgot_to_set_static_CUBEMAP + psh_forgot_to_set_static_DIFFUSELIGHTING + psh_forgot_to_set_static_LIGHTWARPTEXTURE + psh_forgot_to_set_static_SELFILLUM + psh_forgot_to_set_static_SELFILLUMFRESNEL + psh_forgot_to_set_static_NORMALMAPALPHAENVMAPMASK + psh_forgot_to_set_static_HALFLAMBERT + psh_forgot_to_set_static_FLASHLIGHT + psh_forgot_to_set_static_DETAILTEXTURE + psh_forgot_to_set_static_DETAIL_BLEND_MODE + psh_forgot_to_set_static_FLASHLIGHTDEPTHFILTERMODE + psh_forgot_to_set_static_BLENDTINTBYBASEALPHA + 0 +class vertexlit_and_unlit_generic_bump_ps30_Dynamic_Index +{ +private: + int m_nNUM_LIGHTS; +#ifdef _DEBUG + bool m_bNUM_LIGHTS; +#endif +public: + void SetNUM_LIGHTS( int i ) + { + Assert( i >= 0 && i <= 4 ); + m_nNUM_LIGHTS = i; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } + void SetNUM_LIGHTS( bool i ) + { + m_nNUM_LIGHTS = i ? 1 : 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } +private: + int m_nAMBIENT_LIGHT; +#ifdef _DEBUG + bool m_bAMBIENT_LIGHT; +#endif +public: + void SetAMBIENT_LIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nAMBIENT_LIGHT = i; +#ifdef _DEBUG + m_bAMBIENT_LIGHT = true; +#endif + } + void SetAMBIENT_LIGHT( bool i ) + { + m_nAMBIENT_LIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bAMBIENT_LIGHT = true; +#endif + } +private: + int m_nFLASHLIGHTSHADOWS; +#ifdef _DEBUG + bool m_bFLASHLIGHTSHADOWS; +#endif +public: + void SetFLASHLIGHTSHADOWS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFLASHLIGHTSHADOWS = i; +#ifdef _DEBUG + m_bFLASHLIGHTSHADOWS = true; +#endif + } + void SetFLASHLIGHTSHADOWS( bool i ) + { + m_nFLASHLIGHTSHADOWS = i ? 1 : 0; +#ifdef _DEBUG + m_bFLASHLIGHTSHADOWS = true; +#endif + } +public: + vertexlit_and_unlit_generic_bump_ps30_Dynamic_Index() + { +#ifdef _DEBUG + m_bNUM_LIGHTS = false; +#endif // _DEBUG + m_nNUM_LIGHTS = 0; +#ifdef _DEBUG + m_bAMBIENT_LIGHT = false; +#endif // _DEBUG + m_nAMBIENT_LIGHT = 0; +#ifdef _DEBUG + m_bFLASHLIGHTSHADOWS = false; +#endif // _DEBUG + m_nFLASHLIGHTSHADOWS = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bNUM_LIGHTS && m_bAMBIENT_LIGHT && m_bFLASHLIGHTSHADOWS; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nNUM_LIGHTS ) + ( 5 * m_nAMBIENT_LIGHT ) + ( 10 * m_nFLASHLIGHTSHADOWS ) + 0; + } +}; +#define shaderDynamicTest_vertexlit_and_unlit_generic_bump_ps30 psh_forgot_to_set_dynamic_NUM_LIGHTS + psh_forgot_to_set_dynamic_AMBIENT_LIGHT + psh_forgot_to_set_dynamic_FLASHLIGHTSHADOWS + 0 diff --git a/materialsystem/stdshaders/fxctmp9/vertexlit_and_unlit_generic_bump_vs30.inc b/materialsystem/stdshaders/fxctmp9/vertexlit_and_unlit_generic_bump_vs30.inc new file mode 100644 index 0000000..b4231fc --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/vertexlit_and_unlit_generic_bump_vs30.inc @@ -0,0 +1,212 @@ +#include "shaderlib/cshader.h" +class vertexlit_and_unlit_generic_bump_vs30_Static_Index +{ +private: + int m_nHALFLAMBERT; +#ifdef _DEBUG + bool m_bHALFLAMBERT; +#endif +public: + void SetHALFLAMBERT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHALFLAMBERT = i; +#ifdef _DEBUG + m_bHALFLAMBERT = true; +#endif + } + void SetHALFLAMBERT( bool i ) + { + m_nHALFLAMBERT = i ? 1 : 0; +#ifdef _DEBUG + m_bHALFLAMBERT = true; +#endif + } +private: + int m_nUSE_WITH_2B; +#ifdef _DEBUG + bool m_bUSE_WITH_2B; +#endif +public: + void SetUSE_WITH_2B( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nUSE_WITH_2B = i; +#ifdef _DEBUG + m_bUSE_WITH_2B = true; +#endif + } + void SetUSE_WITH_2B( bool i ) + { + m_nUSE_WITH_2B = i ? 1 : 0; +#ifdef _DEBUG + m_bUSE_WITH_2B = true; +#endif + } +private: + int m_nDECAL; +#ifdef _DEBUG + bool m_bDECAL; +#endif +public: + void SetDECAL( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDECAL = i; +#ifdef _DEBUG + m_bDECAL = true; +#endif + } + void SetDECAL( bool i ) + { + m_nDECAL = i ? 1 : 0; +#ifdef _DEBUG + m_bDECAL = true; +#endif + } +public: + vertexlit_and_unlit_generic_bump_vs30_Static_Index( ) + { +#ifdef _DEBUG + m_bHALFLAMBERT = false; +#endif // _DEBUG + m_nHALFLAMBERT = 0; +#ifdef _DEBUG + m_bUSE_WITH_2B = false; +#endif // _DEBUG + m_nUSE_WITH_2B = 0; +#ifdef _DEBUG + m_bDECAL = false; +#endif // _DEBUG + m_nDECAL = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bHALFLAMBERT && m_bUSE_WITH_2B && m_bDECAL; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 16 * m_nHALFLAMBERT ) + ( 32 * m_nUSE_WITH_2B ) + ( 64 * m_nDECAL ) + 0; + } +}; +#define shaderStaticTest_vertexlit_and_unlit_generic_bump_vs30 vsh_forgot_to_set_static_HALFLAMBERT + vsh_forgot_to_set_static_USE_WITH_2B + vsh_forgot_to_set_static_DECAL + 0 +class vertexlit_and_unlit_generic_bump_vs30_Dynamic_Index +{ +private: + int m_nCOMPRESSED_VERTS; +#ifdef _DEBUG + bool m_bCOMPRESSED_VERTS; +#endif +public: + void SetCOMPRESSED_VERTS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOMPRESSED_VERTS = i; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } + void SetCOMPRESSED_VERTS( bool i ) + { + m_nCOMPRESSED_VERTS = i ? 1 : 0; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +private: + int m_nMORPHING; +#ifdef _DEBUG + bool m_bMORPHING; +#endif +public: + void SetMORPHING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nMORPHING = i; +#ifdef _DEBUG + m_bMORPHING = true; +#endif + } + void SetMORPHING( bool i ) + { + m_nMORPHING = i ? 1 : 0; +#ifdef _DEBUG + m_bMORPHING = true; +#endif + } +public: + vertexlit_and_unlit_generic_bump_vs30_Dynamic_Index() + { +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = false; +#endif // _DEBUG + m_nCOMPRESSED_VERTS = 0; +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; +#ifdef _DEBUG + m_bMORPHING = false; +#endif // _DEBUG + m_nMORPHING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bCOMPRESSED_VERTS && m_bDOWATERFOG && m_bSKINNING && m_bMORPHING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCOMPRESSED_VERTS ) + ( 2 * m_nDOWATERFOG ) + ( 4 * m_nSKINNING ) + ( 8 * m_nMORPHING ) + 0; + } +}; +#define shaderDynamicTest_vertexlit_and_unlit_generic_bump_vs30 vsh_forgot_to_set_dynamic_COMPRESSED_VERTS + vsh_forgot_to_set_dynamic_DOWATERFOG + vsh_forgot_to_set_dynamic_SKINNING + vsh_forgot_to_set_dynamic_MORPHING + 0 diff --git a/materialsystem/stdshaders/fxctmp9/vertexlit_and_unlit_generic_ps20.inc b/materialsystem/stdshaders/fxctmp9/vertexlit_and_unlit_generic_ps20.inc new file mode 100644 index 0000000..cc3b8ba --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/vertexlit_and_unlit_generic_ps20.inc @@ -0,0 +1,587 @@ +#include "shaderlib/cshader.h" +class vertexlit_and_unlit_generic_ps20_Static_Index +{ +private: + int m_nDETAILTEXTURE; +#ifdef _DEBUG + bool m_bDETAILTEXTURE; +#endif +public: + void SetDETAILTEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDETAILTEXTURE = i; +#ifdef _DEBUG + m_bDETAILTEXTURE = true; +#endif + } + void SetDETAILTEXTURE( bool i ) + { + m_nDETAILTEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bDETAILTEXTURE = true; +#endif + } +private: + int m_nCUBEMAP; +#ifdef _DEBUG + bool m_bCUBEMAP; +#endif +public: + void SetCUBEMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCUBEMAP = i; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } + void SetCUBEMAP( bool i ) + { + m_nCUBEMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } +private: + int m_nDIFFUSELIGHTING; +#ifdef _DEBUG + bool m_bDIFFUSELIGHTING; +#endif +public: + void SetDIFFUSELIGHTING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDIFFUSELIGHTING = i; +#ifdef _DEBUG + m_bDIFFUSELIGHTING = true; +#endif + } + void SetDIFFUSELIGHTING( bool i ) + { + m_nDIFFUSELIGHTING = i ? 1 : 0; +#ifdef _DEBUG + m_bDIFFUSELIGHTING = true; +#endif + } +private: + int m_nENVMAPMASK; +#ifdef _DEBUG + bool m_bENVMAPMASK; +#endif +public: + void SetENVMAPMASK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nENVMAPMASK = i; +#ifdef _DEBUG + m_bENVMAPMASK = true; +#endif + } + void SetENVMAPMASK( bool i ) + { + m_nENVMAPMASK = i ? 1 : 0; +#ifdef _DEBUG + m_bENVMAPMASK = true; +#endif + } +private: + int m_nBASEALPHAENVMAPMASK; +#ifdef _DEBUG + bool m_bBASEALPHAENVMAPMASK; +#endif +public: + void SetBASEALPHAENVMAPMASK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBASEALPHAENVMAPMASK = i; +#ifdef _DEBUG + m_bBASEALPHAENVMAPMASK = true; +#endif + } + void SetBASEALPHAENVMAPMASK( bool i ) + { + m_nBASEALPHAENVMAPMASK = i ? 1 : 0; +#ifdef _DEBUG + m_bBASEALPHAENVMAPMASK = true; +#endif + } +private: + int m_nSELFILLUM; +#ifdef _DEBUG + bool m_bSELFILLUM; +#endif +public: + void SetSELFILLUM( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSELFILLUM = i; +#ifdef _DEBUG + m_bSELFILLUM = true; +#endif + } + void SetSELFILLUM( bool i ) + { + m_nSELFILLUM = i ? 1 : 0; +#ifdef _DEBUG + m_bSELFILLUM = true; +#endif + } +private: + int m_nVERTEXCOLOR; +#ifdef _DEBUG + bool m_bVERTEXCOLOR; +#endif +public: + void SetVERTEXCOLOR( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nVERTEXCOLOR = i; +#ifdef _DEBUG + m_bVERTEXCOLOR = true; +#endif + } + void SetVERTEXCOLOR( bool i ) + { + m_nVERTEXCOLOR = i ? 1 : 0; +#ifdef _DEBUG + m_bVERTEXCOLOR = true; +#endif + } +private: + int m_nFLASHLIGHT; +#ifdef _DEBUG + bool m_bFLASHLIGHT; +#endif +public: + void SetFLASHLIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFLASHLIGHT = i; +#ifdef _DEBUG + m_bFLASHLIGHT = true; +#endif + } + void SetFLASHLIGHT( bool i ) + { + m_nFLASHLIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bFLASHLIGHT = true; +#endif + } +private: + int m_nSELFILLUM_ENVMAPMASK_ALPHA; +#ifdef _DEBUG + bool m_bSELFILLUM_ENVMAPMASK_ALPHA; +#endif +public: + void SetSELFILLUM_ENVMAPMASK_ALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSELFILLUM_ENVMAPMASK_ALPHA = i; +#ifdef _DEBUG + m_bSELFILLUM_ENVMAPMASK_ALPHA = true; +#endif + } + void SetSELFILLUM_ENVMAPMASK_ALPHA( bool i ) + { + m_nSELFILLUM_ENVMAPMASK_ALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bSELFILLUM_ENVMAPMASK_ALPHA = true; +#endif + } +private: + int m_nDETAIL_BLEND_MODE; +#ifdef _DEBUG + bool m_bDETAIL_BLEND_MODE; +#endif +public: + void SetDETAIL_BLEND_MODE( int i ) + { + Assert( i >= 0 && i <= 9 ); + m_nDETAIL_BLEND_MODE = i; +#ifdef _DEBUG + m_bDETAIL_BLEND_MODE = true; +#endif + } + void SetDETAIL_BLEND_MODE( bool i ) + { + m_nDETAIL_BLEND_MODE = i ? 1 : 0; +#ifdef _DEBUG + m_bDETAIL_BLEND_MODE = true; +#endif + } +private: + int m_nSEAMLESS_BASE; +#ifdef _DEBUG + bool m_bSEAMLESS_BASE; +#endif +public: + void SetSEAMLESS_BASE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSEAMLESS_BASE = i; +#ifdef _DEBUG + m_bSEAMLESS_BASE = true; +#endif + } + void SetSEAMLESS_BASE( bool i ) + { + m_nSEAMLESS_BASE = i ? 1 : 0; +#ifdef _DEBUG + m_bSEAMLESS_BASE = true; +#endif + } +private: + int m_nSEAMLESS_DETAIL; +#ifdef _DEBUG + bool m_bSEAMLESS_DETAIL; +#endif +public: + void SetSEAMLESS_DETAIL( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSEAMLESS_DETAIL = i; +#ifdef _DEBUG + m_bSEAMLESS_DETAIL = true; +#endif + } + void SetSEAMLESS_DETAIL( bool i ) + { + m_nSEAMLESS_DETAIL = i ? 1 : 0; +#ifdef _DEBUG + m_bSEAMLESS_DETAIL = true; +#endif + } +private: + int m_nDISTANCEALPHA; +#ifdef _DEBUG + bool m_bDISTANCEALPHA; +#endif +public: + void SetDISTANCEALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDISTANCEALPHA = i; +#ifdef _DEBUG + m_bDISTANCEALPHA = true; +#endif + } + void SetDISTANCEALPHA( bool i ) + { + m_nDISTANCEALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bDISTANCEALPHA = true; +#endif + } +private: + int m_nDISTANCEALPHAFROMDETAIL; +#ifdef _DEBUG + bool m_bDISTANCEALPHAFROMDETAIL; +#endif +public: + void SetDISTANCEALPHAFROMDETAIL( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDISTANCEALPHAFROMDETAIL = i; +#ifdef _DEBUG + m_bDISTANCEALPHAFROMDETAIL = true; +#endif + } + void SetDISTANCEALPHAFROMDETAIL( bool i ) + { + m_nDISTANCEALPHAFROMDETAIL = i ? 1 : 0; +#ifdef _DEBUG + m_bDISTANCEALPHAFROMDETAIL = true; +#endif + } +private: + int m_nSOFT_MASK; +#ifdef _DEBUG + bool m_bSOFT_MASK; +#endif +public: + void SetSOFT_MASK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSOFT_MASK = i; +#ifdef _DEBUG + m_bSOFT_MASK = true; +#endif + } + void SetSOFT_MASK( bool i ) + { + m_nSOFT_MASK = i ? 1 : 0; +#ifdef _DEBUG + m_bSOFT_MASK = true; +#endif + } +private: + int m_nOUTLINE; +#ifdef _DEBUG + bool m_bOUTLINE; +#endif +public: + void SetOUTLINE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nOUTLINE = i; +#ifdef _DEBUG + m_bOUTLINE = true; +#endif + } + void SetOUTLINE( bool i ) + { + m_nOUTLINE = i ? 1 : 0; +#ifdef _DEBUG + m_bOUTLINE = true; +#endif + } +private: + int m_nOUTER_GLOW; +#ifdef _DEBUG + bool m_bOUTER_GLOW; +#endif +public: + void SetOUTER_GLOW( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nOUTER_GLOW = i; +#ifdef _DEBUG + m_bOUTER_GLOW = true; +#endif + } + void SetOUTER_GLOW( bool i ) + { + m_nOUTER_GLOW = i ? 1 : 0; +#ifdef _DEBUG + m_bOUTER_GLOW = true; +#endif + } +private: + int m_nBLENDTINTBYBASEALPHA; +#ifdef _DEBUG + bool m_bBLENDTINTBYBASEALPHA; +#endif +public: + void SetBLENDTINTBYBASEALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBLENDTINTBYBASEALPHA = i; +#ifdef _DEBUG + m_bBLENDTINTBYBASEALPHA = true; +#endif + } + void SetBLENDTINTBYBASEALPHA( bool i ) + { + m_nBLENDTINTBYBASEALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bBLENDTINTBYBASEALPHA = true; +#endif + } +private: + int m_nCUBEMAP_SPHERE_LEGACY; +#ifdef _DEBUG + bool m_bCUBEMAP_SPHERE_LEGACY; +#endif +public: + void SetCUBEMAP_SPHERE_LEGACY( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCUBEMAP_SPHERE_LEGACY = i; +#ifdef _DEBUG + m_bCUBEMAP_SPHERE_LEGACY = true; +#endif + } + void SetCUBEMAP_SPHERE_LEGACY( bool i ) + { + m_nCUBEMAP_SPHERE_LEGACY = i ? 1 : 0; +#ifdef _DEBUG + m_bCUBEMAP_SPHERE_LEGACY = true; +#endif + } +public: + vertexlit_and_unlit_generic_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bDETAILTEXTURE = false; +#endif // _DEBUG + m_nDETAILTEXTURE = 0; +#ifdef _DEBUG + m_bCUBEMAP = false; +#endif // _DEBUG + m_nCUBEMAP = 0; +#ifdef _DEBUG + m_bDIFFUSELIGHTING = false; +#endif // _DEBUG + m_nDIFFUSELIGHTING = 0; +#ifdef _DEBUG + m_bENVMAPMASK = false; +#endif // _DEBUG + m_nENVMAPMASK = 0; +#ifdef _DEBUG + m_bBASEALPHAENVMAPMASK = false; +#endif // _DEBUG + m_nBASEALPHAENVMAPMASK = 0; +#ifdef _DEBUG + m_bSELFILLUM = false; +#endif // _DEBUG + m_nSELFILLUM = 0; +#ifdef _DEBUG + m_bVERTEXCOLOR = false; +#endif // _DEBUG + m_nVERTEXCOLOR = 0; +#ifdef _DEBUG + m_bFLASHLIGHT = false; +#endif // _DEBUG + m_nFLASHLIGHT = 0; +#ifdef _DEBUG + m_bSELFILLUM_ENVMAPMASK_ALPHA = false; +#endif // _DEBUG + m_nSELFILLUM_ENVMAPMASK_ALPHA = 0; +#ifdef _DEBUG + m_bDETAIL_BLEND_MODE = false; +#endif // _DEBUG + m_nDETAIL_BLEND_MODE = 0; +#ifdef _DEBUG + m_bSEAMLESS_BASE = false; +#endif // _DEBUG + m_nSEAMLESS_BASE = 0; +#ifdef _DEBUG + m_bSEAMLESS_DETAIL = false; +#endif // _DEBUG + m_nSEAMLESS_DETAIL = 0; +#ifdef _DEBUG + m_bDISTANCEALPHA = false; +#endif // _DEBUG + m_nDISTANCEALPHA = 0; +#ifdef _DEBUG + m_bDISTANCEALPHAFROMDETAIL = false; +#endif // _DEBUG + m_nDISTANCEALPHAFROMDETAIL = 0; +#ifdef _DEBUG + m_bSOFT_MASK = false; +#endif // _DEBUG + m_nSOFT_MASK = 0; +#ifdef _DEBUG + m_bOUTLINE = false; +#endif // _DEBUG + m_nOUTLINE = 0; +#ifdef _DEBUG + m_bOUTER_GLOW = false; +#endif // _DEBUG + m_nOUTER_GLOW = 0; +#ifdef _DEBUG + m_bBLENDTINTBYBASEALPHA = false; +#endif // _DEBUG + m_nBLENDTINTBYBASEALPHA = 0; +#ifdef _DEBUG + m_bCUBEMAP_SPHERE_LEGACY = false; +#endif // _DEBUG + m_nCUBEMAP_SPHERE_LEGACY = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bDETAILTEXTURE && m_bCUBEMAP && m_bDIFFUSELIGHTING && m_bENVMAPMASK && m_bBASEALPHAENVMAPMASK && m_bSELFILLUM && m_bVERTEXCOLOR && m_bFLASHLIGHT && m_bSELFILLUM_ENVMAPMASK_ALPHA && m_bDETAIL_BLEND_MODE && m_bSEAMLESS_BASE && m_bSEAMLESS_DETAIL && m_bDISTANCEALPHA && m_bDISTANCEALPHAFROMDETAIL && m_bSOFT_MASK && m_bOUTLINE && m_bOUTER_GLOW && m_bBLENDTINTBYBASEALPHA && m_bCUBEMAP_SPHERE_LEGACY; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 6 * m_nDETAILTEXTURE ) + ( 12 * m_nCUBEMAP ) + ( 24 * m_nDIFFUSELIGHTING ) + ( 48 * m_nENVMAPMASK ) + ( 96 * m_nBASEALPHAENVMAPMASK ) + ( 192 * m_nSELFILLUM ) + ( 384 * m_nVERTEXCOLOR ) + ( 768 * m_nFLASHLIGHT ) + ( 1536 * m_nSELFILLUM_ENVMAPMASK_ALPHA ) + ( 3072 * m_nDETAIL_BLEND_MODE ) + ( 30720 * m_nSEAMLESS_BASE ) + ( 61440 * m_nSEAMLESS_DETAIL ) + ( 122880 * m_nDISTANCEALPHA ) + ( 245760 * m_nDISTANCEALPHAFROMDETAIL ) + ( 491520 * m_nSOFT_MASK ) + ( 983040 * m_nOUTLINE ) + ( 1966080 * m_nOUTER_GLOW ) + ( 3932160 * m_nBLENDTINTBYBASEALPHA ) + ( 7864320 * m_nCUBEMAP_SPHERE_LEGACY ) + 0; + } +}; +#define shaderStaticTest_vertexlit_and_unlit_generic_ps20 psh_forgot_to_set_static_DETAILTEXTURE + psh_forgot_to_set_static_CUBEMAP + psh_forgot_to_set_static_DIFFUSELIGHTING + psh_forgot_to_set_static_ENVMAPMASK + psh_forgot_to_set_static_BASEALPHAENVMAPMASK + psh_forgot_to_set_static_SELFILLUM + psh_forgot_to_set_static_VERTEXCOLOR + psh_forgot_to_set_static_FLASHLIGHT + psh_forgot_to_set_static_SELFILLUM_ENVMAPMASK_ALPHA + psh_forgot_to_set_static_DETAIL_BLEND_MODE + psh_forgot_to_set_static_SEAMLESS_BASE + psh_forgot_to_set_static_SEAMLESS_DETAIL + psh_forgot_to_set_static_DISTANCEALPHA + psh_forgot_to_set_static_DISTANCEALPHAFROMDETAIL + psh_forgot_to_set_static_SOFT_MASK + psh_forgot_to_set_static_OUTLINE + psh_forgot_to_set_static_OUTER_GLOW + psh_forgot_to_set_static_BLENDTINTBYBASEALPHA + psh_forgot_to_set_static_CUBEMAP_SPHERE_LEGACY + 0 +class vertexlit_and_unlit_generic_ps20_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +private: + int m_nLIGHTING_PREVIEW; +#ifdef _DEBUG + bool m_bLIGHTING_PREVIEW; +#endif +public: + void SetLIGHTING_PREVIEW( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nLIGHTING_PREVIEW = i; +#ifdef _DEBUG + m_bLIGHTING_PREVIEW = true; +#endif + } + void SetLIGHTING_PREVIEW( bool i ) + { + m_nLIGHTING_PREVIEW = i ? 1 : 0; +#ifdef _DEBUG + m_bLIGHTING_PREVIEW = true; +#endif + } +private: + int m_nSTATIC_LIGHT_LIGHTMAP; +#ifdef _DEBUG + bool m_bSTATIC_LIGHT_LIGHTMAP; +#endif +public: + void SetSTATIC_LIGHT_LIGHTMAP( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nSTATIC_LIGHT_LIGHTMAP = i; +#ifdef _DEBUG + m_bSTATIC_LIGHT_LIGHTMAP = true; +#endif + } + void SetSTATIC_LIGHT_LIGHTMAP( bool i ) + { + m_nSTATIC_LIGHT_LIGHTMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bSTATIC_LIGHT_LIGHTMAP = true; +#endif + } +public: + vertexlit_and_unlit_generic_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; +#ifdef _DEBUG + m_bLIGHTING_PREVIEW = false; +#endif // _DEBUG + m_nLIGHTING_PREVIEW = 0; +#ifdef _DEBUG + m_bSTATIC_LIGHT_LIGHTMAP = false; +#endif // _DEBUG + m_nSTATIC_LIGHT_LIGHTMAP = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE && m_bLIGHTING_PREVIEW && m_bSTATIC_LIGHT_LIGHTMAP; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + ( 2 * m_nLIGHTING_PREVIEW ) + ( 6 * m_nSTATIC_LIGHT_LIGHTMAP ) + 0; + } +}; +#define shaderDynamicTest_vertexlit_and_unlit_generic_ps20 psh_forgot_to_set_dynamic_PIXELFOGTYPE + psh_forgot_to_set_dynamic_LIGHTING_PREVIEW + psh_forgot_to_set_dynamic_STATIC_LIGHT_LIGHTMAP + 0 diff --git a/materialsystem/stdshaders/fxctmp9/vertexlit_and_unlit_generic_ps20b.inc b/materialsystem/stdshaders/fxctmp9/vertexlit_and_unlit_generic_ps20b.inc new file mode 100644 index 0000000..ee4f714 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/vertexlit_and_unlit_generic_ps20b.inc @@ -0,0 +1,687 @@ +#include "shaderlib/cshader.h" +class vertexlit_and_unlit_generic_ps20b_Static_Index +{ +private: + int m_nDETAILTEXTURE; +#ifdef _DEBUG + bool m_bDETAILTEXTURE; +#endif +public: + void SetDETAILTEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDETAILTEXTURE = i; +#ifdef _DEBUG + m_bDETAILTEXTURE = true; +#endif + } + void SetDETAILTEXTURE( bool i ) + { + m_nDETAILTEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bDETAILTEXTURE = true; +#endif + } +private: + int m_nCUBEMAP; +#ifdef _DEBUG + bool m_bCUBEMAP; +#endif +public: + void SetCUBEMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCUBEMAP = i; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } + void SetCUBEMAP( bool i ) + { + m_nCUBEMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } +private: + int m_nDIFFUSELIGHTING; +#ifdef _DEBUG + bool m_bDIFFUSELIGHTING; +#endif +public: + void SetDIFFUSELIGHTING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDIFFUSELIGHTING = i; +#ifdef _DEBUG + m_bDIFFUSELIGHTING = true; +#endif + } + void SetDIFFUSELIGHTING( bool i ) + { + m_nDIFFUSELIGHTING = i ? 1 : 0; +#ifdef _DEBUG + m_bDIFFUSELIGHTING = true; +#endif + } +private: + int m_nENVMAPMASK; +#ifdef _DEBUG + bool m_bENVMAPMASK; +#endif +public: + void SetENVMAPMASK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nENVMAPMASK = i; +#ifdef _DEBUG + m_bENVMAPMASK = true; +#endif + } + void SetENVMAPMASK( bool i ) + { + m_nENVMAPMASK = i ? 1 : 0; +#ifdef _DEBUG + m_bENVMAPMASK = true; +#endif + } +private: + int m_nBASEALPHAENVMAPMASK; +#ifdef _DEBUG + bool m_bBASEALPHAENVMAPMASK; +#endif +public: + void SetBASEALPHAENVMAPMASK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBASEALPHAENVMAPMASK = i; +#ifdef _DEBUG + m_bBASEALPHAENVMAPMASK = true; +#endif + } + void SetBASEALPHAENVMAPMASK( bool i ) + { + m_nBASEALPHAENVMAPMASK = i ? 1 : 0; +#ifdef _DEBUG + m_bBASEALPHAENVMAPMASK = true; +#endif + } +private: + int m_nSELFILLUM; +#ifdef _DEBUG + bool m_bSELFILLUM; +#endif +public: + void SetSELFILLUM( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSELFILLUM = i; +#ifdef _DEBUG + m_bSELFILLUM = true; +#endif + } + void SetSELFILLUM( bool i ) + { + m_nSELFILLUM = i ? 1 : 0; +#ifdef _DEBUG + m_bSELFILLUM = true; +#endif + } +private: + int m_nVERTEXCOLOR; +#ifdef _DEBUG + bool m_bVERTEXCOLOR; +#endif +public: + void SetVERTEXCOLOR( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nVERTEXCOLOR = i; +#ifdef _DEBUG + m_bVERTEXCOLOR = true; +#endif + } + void SetVERTEXCOLOR( bool i ) + { + m_nVERTEXCOLOR = i ? 1 : 0; +#ifdef _DEBUG + m_bVERTEXCOLOR = true; +#endif + } +private: + int m_nFLASHLIGHT; +#ifdef _DEBUG + bool m_bFLASHLIGHT; +#endif +public: + void SetFLASHLIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFLASHLIGHT = i; +#ifdef _DEBUG + m_bFLASHLIGHT = true; +#endif + } + void SetFLASHLIGHT( bool i ) + { + m_nFLASHLIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bFLASHLIGHT = true; +#endif + } +private: + int m_nSELFILLUM_ENVMAPMASK_ALPHA; +#ifdef _DEBUG + bool m_bSELFILLUM_ENVMAPMASK_ALPHA; +#endif +public: + void SetSELFILLUM_ENVMAPMASK_ALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSELFILLUM_ENVMAPMASK_ALPHA = i; +#ifdef _DEBUG + m_bSELFILLUM_ENVMAPMASK_ALPHA = true; +#endif + } + void SetSELFILLUM_ENVMAPMASK_ALPHA( bool i ) + { + m_nSELFILLUM_ENVMAPMASK_ALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bSELFILLUM_ENVMAPMASK_ALPHA = true; +#endif + } +private: + int m_nDETAIL_BLEND_MODE; +#ifdef _DEBUG + bool m_bDETAIL_BLEND_MODE; +#endif +public: + void SetDETAIL_BLEND_MODE( int i ) + { + Assert( i >= 0 && i <= 9 ); + m_nDETAIL_BLEND_MODE = i; +#ifdef _DEBUG + m_bDETAIL_BLEND_MODE = true; +#endif + } + void SetDETAIL_BLEND_MODE( bool i ) + { + m_nDETAIL_BLEND_MODE = i ? 1 : 0; +#ifdef _DEBUG + m_bDETAIL_BLEND_MODE = true; +#endif + } +private: + int m_nSEAMLESS_BASE; +#ifdef _DEBUG + bool m_bSEAMLESS_BASE; +#endif +public: + void SetSEAMLESS_BASE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSEAMLESS_BASE = i; +#ifdef _DEBUG + m_bSEAMLESS_BASE = true; +#endif + } + void SetSEAMLESS_BASE( bool i ) + { + m_nSEAMLESS_BASE = i ? 1 : 0; +#ifdef _DEBUG + m_bSEAMLESS_BASE = true; +#endif + } +private: + int m_nSEAMLESS_DETAIL; +#ifdef _DEBUG + bool m_bSEAMLESS_DETAIL; +#endif +public: + void SetSEAMLESS_DETAIL( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSEAMLESS_DETAIL = i; +#ifdef _DEBUG + m_bSEAMLESS_DETAIL = true; +#endif + } + void SetSEAMLESS_DETAIL( bool i ) + { + m_nSEAMLESS_DETAIL = i ? 1 : 0; +#ifdef _DEBUG + m_bSEAMLESS_DETAIL = true; +#endif + } +private: + int m_nDISTANCEALPHA; +#ifdef _DEBUG + bool m_bDISTANCEALPHA; +#endif +public: + void SetDISTANCEALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDISTANCEALPHA = i; +#ifdef _DEBUG + m_bDISTANCEALPHA = true; +#endif + } + void SetDISTANCEALPHA( bool i ) + { + m_nDISTANCEALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bDISTANCEALPHA = true; +#endif + } +private: + int m_nDISTANCEALPHAFROMDETAIL; +#ifdef _DEBUG + bool m_bDISTANCEALPHAFROMDETAIL; +#endif +public: + void SetDISTANCEALPHAFROMDETAIL( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDISTANCEALPHAFROMDETAIL = i; +#ifdef _DEBUG + m_bDISTANCEALPHAFROMDETAIL = true; +#endif + } + void SetDISTANCEALPHAFROMDETAIL( bool i ) + { + m_nDISTANCEALPHAFROMDETAIL = i ? 1 : 0; +#ifdef _DEBUG + m_bDISTANCEALPHAFROMDETAIL = true; +#endif + } +private: + int m_nSOFT_MASK; +#ifdef _DEBUG + bool m_bSOFT_MASK; +#endif +public: + void SetSOFT_MASK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSOFT_MASK = i; +#ifdef _DEBUG + m_bSOFT_MASK = true; +#endif + } + void SetSOFT_MASK( bool i ) + { + m_nSOFT_MASK = i ? 1 : 0; +#ifdef _DEBUG + m_bSOFT_MASK = true; +#endif + } +private: + int m_nOUTLINE; +#ifdef _DEBUG + bool m_bOUTLINE; +#endif +public: + void SetOUTLINE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nOUTLINE = i; +#ifdef _DEBUG + m_bOUTLINE = true; +#endif + } + void SetOUTLINE( bool i ) + { + m_nOUTLINE = i ? 1 : 0; +#ifdef _DEBUG + m_bOUTLINE = true; +#endif + } +private: + int m_nOUTER_GLOW; +#ifdef _DEBUG + bool m_bOUTER_GLOW; +#endif +public: + void SetOUTER_GLOW( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nOUTER_GLOW = i; +#ifdef _DEBUG + m_bOUTER_GLOW = true; +#endif + } + void SetOUTER_GLOW( bool i ) + { + m_nOUTER_GLOW = i ? 1 : 0; +#ifdef _DEBUG + m_bOUTER_GLOW = true; +#endif + } +private: + int m_nFLASHLIGHTDEPTHFILTERMODE; +#ifdef _DEBUG + bool m_bFLASHLIGHTDEPTHFILTERMODE; +#endif +public: + void SetFLASHLIGHTDEPTHFILTERMODE( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nFLASHLIGHTDEPTHFILTERMODE = i; +#ifdef _DEBUG + m_bFLASHLIGHTDEPTHFILTERMODE = true; +#endif + } + void SetFLASHLIGHTDEPTHFILTERMODE( bool i ) + { + m_nFLASHLIGHTDEPTHFILTERMODE = i ? 1 : 0; +#ifdef _DEBUG + m_bFLASHLIGHTDEPTHFILTERMODE = true; +#endif + } +private: + int m_nDEPTHBLEND; +#ifdef _DEBUG + bool m_bDEPTHBLEND; +#endif +public: + void SetDEPTHBLEND( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDEPTHBLEND = i; +#ifdef _DEBUG + m_bDEPTHBLEND = true; +#endif + } + void SetDEPTHBLEND( bool i ) + { + m_nDEPTHBLEND = i ? 1 : 0; +#ifdef _DEBUG + m_bDEPTHBLEND = true; +#endif + } +private: + int m_nBLENDTINTBYBASEALPHA; +#ifdef _DEBUG + bool m_bBLENDTINTBYBASEALPHA; +#endif +public: + void SetBLENDTINTBYBASEALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBLENDTINTBYBASEALPHA = i; +#ifdef _DEBUG + m_bBLENDTINTBYBASEALPHA = true; +#endif + } + void SetBLENDTINTBYBASEALPHA( bool i ) + { + m_nBLENDTINTBYBASEALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bBLENDTINTBYBASEALPHA = true; +#endif + } +private: + int m_nSRGB_INPUT_ADAPTER; +#ifdef _DEBUG + bool m_bSRGB_INPUT_ADAPTER; +#endif +public: + void SetSRGB_INPUT_ADAPTER( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSRGB_INPUT_ADAPTER = i; +#ifdef _DEBUG + m_bSRGB_INPUT_ADAPTER = true; +#endif + } + void SetSRGB_INPUT_ADAPTER( bool i ) + { + m_nSRGB_INPUT_ADAPTER = i ? 1 : 0; +#ifdef _DEBUG + m_bSRGB_INPUT_ADAPTER = true; +#endif + } +private: + int m_nCUBEMAP_SPHERE_LEGACY; +#ifdef _DEBUG + bool m_bCUBEMAP_SPHERE_LEGACY; +#endif +public: + void SetCUBEMAP_SPHERE_LEGACY( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCUBEMAP_SPHERE_LEGACY = i; +#ifdef _DEBUG + m_bCUBEMAP_SPHERE_LEGACY = true; +#endif + } + void SetCUBEMAP_SPHERE_LEGACY( bool i ) + { + m_nCUBEMAP_SPHERE_LEGACY = i ? 1 : 0; +#ifdef _DEBUG + m_bCUBEMAP_SPHERE_LEGACY = true; +#endif + } +public: + vertexlit_and_unlit_generic_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bDETAILTEXTURE = false; +#endif // _DEBUG + m_nDETAILTEXTURE = 0; +#ifdef _DEBUG + m_bCUBEMAP = false; +#endif // _DEBUG + m_nCUBEMAP = 0; +#ifdef _DEBUG + m_bDIFFUSELIGHTING = false; +#endif // _DEBUG + m_nDIFFUSELIGHTING = 0; +#ifdef _DEBUG + m_bENVMAPMASK = false; +#endif // _DEBUG + m_nENVMAPMASK = 0; +#ifdef _DEBUG + m_bBASEALPHAENVMAPMASK = false; +#endif // _DEBUG + m_nBASEALPHAENVMAPMASK = 0; +#ifdef _DEBUG + m_bSELFILLUM = false; +#endif // _DEBUG + m_nSELFILLUM = 0; +#ifdef _DEBUG + m_bVERTEXCOLOR = false; +#endif // _DEBUG + m_nVERTEXCOLOR = 0; +#ifdef _DEBUG + m_bFLASHLIGHT = false; +#endif // _DEBUG + m_nFLASHLIGHT = 0; +#ifdef _DEBUG + m_bSELFILLUM_ENVMAPMASK_ALPHA = false; +#endif // _DEBUG + m_nSELFILLUM_ENVMAPMASK_ALPHA = 0; +#ifdef _DEBUG + m_bDETAIL_BLEND_MODE = false; +#endif // _DEBUG + m_nDETAIL_BLEND_MODE = 0; +#ifdef _DEBUG + m_bSEAMLESS_BASE = false; +#endif // _DEBUG + m_nSEAMLESS_BASE = 0; +#ifdef _DEBUG + m_bSEAMLESS_DETAIL = false; +#endif // _DEBUG + m_nSEAMLESS_DETAIL = 0; +#ifdef _DEBUG + m_bDISTANCEALPHA = false; +#endif // _DEBUG + m_nDISTANCEALPHA = 0; +#ifdef _DEBUG + m_bDISTANCEALPHAFROMDETAIL = false; +#endif // _DEBUG + m_nDISTANCEALPHAFROMDETAIL = 0; +#ifdef _DEBUG + m_bSOFT_MASK = false; +#endif // _DEBUG + m_nSOFT_MASK = 0; +#ifdef _DEBUG + m_bOUTLINE = false; +#endif // _DEBUG + m_nOUTLINE = 0; +#ifdef _DEBUG + m_bOUTER_GLOW = false; +#endif // _DEBUG + m_nOUTER_GLOW = 0; +#ifdef _DEBUG + m_bFLASHLIGHTDEPTHFILTERMODE = false; +#endif // _DEBUG + m_nFLASHLIGHTDEPTHFILTERMODE = 0; +#ifdef _DEBUG + m_bDEPTHBLEND = false; +#endif // _DEBUG + m_nDEPTHBLEND = 0; +#ifdef _DEBUG + m_bBLENDTINTBYBASEALPHA = false; +#endif // _DEBUG + m_nBLENDTINTBYBASEALPHA = 0; +#ifdef _DEBUG + m_bSRGB_INPUT_ADAPTER = false; +#endif // _DEBUG + m_nSRGB_INPUT_ADAPTER = 0; +#ifdef _DEBUG + m_bCUBEMAP_SPHERE_LEGACY = false; +#endif // _DEBUG + m_nCUBEMAP_SPHERE_LEGACY = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bDETAILTEXTURE && m_bCUBEMAP && m_bDIFFUSELIGHTING && m_bENVMAPMASK && m_bBASEALPHAENVMAPMASK && m_bSELFILLUM && m_bVERTEXCOLOR && m_bFLASHLIGHT && m_bSELFILLUM_ENVMAPMASK_ALPHA && m_bDETAIL_BLEND_MODE && m_bSEAMLESS_BASE && m_bSEAMLESS_DETAIL && m_bDISTANCEALPHA && m_bDISTANCEALPHAFROMDETAIL && m_bSOFT_MASK && m_bOUTLINE && m_bOUTER_GLOW && m_bFLASHLIGHTDEPTHFILTERMODE && m_bDEPTHBLEND && m_bBLENDTINTBYBASEALPHA && m_bSRGB_INPUT_ADAPTER && m_bCUBEMAP_SPHERE_LEGACY; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 24 * m_nDETAILTEXTURE ) + ( 48 * m_nCUBEMAP ) + ( 96 * m_nDIFFUSELIGHTING ) + ( 192 * m_nENVMAPMASK ) + ( 384 * m_nBASEALPHAENVMAPMASK ) + ( 768 * m_nSELFILLUM ) + ( 1536 * m_nVERTEXCOLOR ) + ( 3072 * m_nFLASHLIGHT ) + ( 6144 * m_nSELFILLUM_ENVMAPMASK_ALPHA ) + ( 12288 * m_nDETAIL_BLEND_MODE ) + ( 122880 * m_nSEAMLESS_BASE ) + ( 245760 * m_nSEAMLESS_DETAIL ) + ( 491520 * m_nDISTANCEALPHA ) + ( 983040 * m_nDISTANCEALPHAFROMDETAIL ) + ( 1966080 * m_nSOFT_MASK ) + ( 3932160 * m_nOUTLINE ) + ( 7864320 * m_nOUTER_GLOW ) + ( 15728640 * m_nFLASHLIGHTDEPTHFILTERMODE ) + ( 47185920 * m_nDEPTHBLEND ) + ( 94371840 * m_nBLENDTINTBYBASEALPHA ) + ( 188743680 * m_nSRGB_INPUT_ADAPTER ) + ( 377487360 * m_nCUBEMAP_SPHERE_LEGACY ) + 0; + } +}; +#define shaderStaticTest_vertexlit_and_unlit_generic_ps20b psh_forgot_to_set_static_DETAILTEXTURE + psh_forgot_to_set_static_CUBEMAP + psh_forgot_to_set_static_DIFFUSELIGHTING + psh_forgot_to_set_static_ENVMAPMASK + psh_forgot_to_set_static_BASEALPHAENVMAPMASK + psh_forgot_to_set_static_SELFILLUM + psh_forgot_to_set_static_VERTEXCOLOR + psh_forgot_to_set_static_FLASHLIGHT + psh_forgot_to_set_static_SELFILLUM_ENVMAPMASK_ALPHA + psh_forgot_to_set_static_DETAIL_BLEND_MODE + psh_forgot_to_set_static_SEAMLESS_BASE + psh_forgot_to_set_static_SEAMLESS_DETAIL + psh_forgot_to_set_static_DISTANCEALPHA + psh_forgot_to_set_static_DISTANCEALPHAFROMDETAIL + psh_forgot_to_set_static_SOFT_MASK + psh_forgot_to_set_static_OUTLINE + psh_forgot_to_set_static_OUTER_GLOW + psh_forgot_to_set_static_FLASHLIGHTDEPTHFILTERMODE + psh_forgot_to_set_static_DEPTHBLEND + psh_forgot_to_set_static_BLENDTINTBYBASEALPHA + psh_forgot_to_set_static_SRGB_INPUT_ADAPTER + psh_forgot_to_set_static_CUBEMAP_SPHERE_LEGACY + 0 +class vertexlit_and_unlit_generic_ps20b_Dynamic_Index +{ +private: + int m_nLIGHTING_PREVIEW; +#ifdef _DEBUG + bool m_bLIGHTING_PREVIEW; +#endif +public: + void SetLIGHTING_PREVIEW( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nLIGHTING_PREVIEW = i; +#ifdef _DEBUG + m_bLIGHTING_PREVIEW = true; +#endif + } + void SetLIGHTING_PREVIEW( bool i ) + { + m_nLIGHTING_PREVIEW = i ? 1 : 0; +#ifdef _DEBUG + m_bLIGHTING_PREVIEW = true; +#endif + } +private: + int m_nFLASHLIGHTSHADOWS; +#ifdef _DEBUG + bool m_bFLASHLIGHTSHADOWS; +#endif +public: + void SetFLASHLIGHTSHADOWS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFLASHLIGHTSHADOWS = i; +#ifdef _DEBUG + m_bFLASHLIGHTSHADOWS = true; +#endif + } + void SetFLASHLIGHTSHADOWS( bool i ) + { + m_nFLASHLIGHTSHADOWS = i ? 1 : 0; +#ifdef _DEBUG + m_bFLASHLIGHTSHADOWS = true; +#endif + } +private: + int m_nSTATIC_LIGHT_LIGHTMAP; +#ifdef _DEBUG + bool m_bSTATIC_LIGHT_LIGHTMAP; +#endif +public: + void SetSTATIC_LIGHT_LIGHTMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSTATIC_LIGHT_LIGHTMAP = i; +#ifdef _DEBUG + m_bSTATIC_LIGHT_LIGHTMAP = true; +#endif + } + void SetSTATIC_LIGHT_LIGHTMAP( bool i ) + { + m_nSTATIC_LIGHT_LIGHTMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bSTATIC_LIGHT_LIGHTMAP = true; +#endif + } +private: + int m_nDEBUG_LUXELS; +#ifdef _DEBUG + bool m_bDEBUG_LUXELS; +#endif +public: + void SetDEBUG_LUXELS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDEBUG_LUXELS = i; +#ifdef _DEBUG + m_bDEBUG_LUXELS = true; +#endif + } + void SetDEBUG_LUXELS( bool i ) + { + m_nDEBUG_LUXELS = i ? 1 : 0; +#ifdef _DEBUG + m_bDEBUG_LUXELS = true; +#endif + } +public: + vertexlit_and_unlit_generic_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bLIGHTING_PREVIEW = false; +#endif // _DEBUG + m_nLIGHTING_PREVIEW = 0; +#ifdef _DEBUG + m_bFLASHLIGHTSHADOWS = false; +#endif // _DEBUG + m_nFLASHLIGHTSHADOWS = 0; +#ifdef _DEBUG + m_bSTATIC_LIGHT_LIGHTMAP = false; +#endif // _DEBUG + m_nSTATIC_LIGHT_LIGHTMAP = 0; +#ifdef _DEBUG + m_bDEBUG_LUXELS = false; +#endif // _DEBUG + m_nDEBUG_LUXELS = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bLIGHTING_PREVIEW && m_bFLASHLIGHTSHADOWS && m_bSTATIC_LIGHT_LIGHTMAP && m_bDEBUG_LUXELS; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nLIGHTING_PREVIEW ) + ( 3 * m_nFLASHLIGHTSHADOWS ) + ( 6 * m_nSTATIC_LIGHT_LIGHTMAP ) + ( 12 * m_nDEBUG_LUXELS ) + 0; + } +}; +#define shaderDynamicTest_vertexlit_and_unlit_generic_ps20b psh_forgot_to_set_dynamic_LIGHTING_PREVIEW + psh_forgot_to_set_dynamic_FLASHLIGHTSHADOWS + psh_forgot_to_set_dynamic_STATIC_LIGHT_LIGHTMAP + psh_forgot_to_set_dynamic_DEBUG_LUXELS + 0 diff --git a/materialsystem/stdshaders/fxctmp9/vertexlit_and_unlit_generic_ps30.inc b/materialsystem/stdshaders/fxctmp9/vertexlit_and_unlit_generic_ps30.inc new file mode 100644 index 0000000..ce1c6f9 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/vertexlit_and_unlit_generic_ps30.inc @@ -0,0 +1,662 @@ +#include "shaderlib/cshader.h" +class vertexlit_and_unlit_generic_ps30_Static_Index +{ +private: + int m_nDETAILTEXTURE; +#ifdef _DEBUG + bool m_bDETAILTEXTURE; +#endif +public: + void SetDETAILTEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDETAILTEXTURE = i; +#ifdef _DEBUG + m_bDETAILTEXTURE = true; +#endif + } + void SetDETAILTEXTURE( bool i ) + { + m_nDETAILTEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bDETAILTEXTURE = true; +#endif + } +private: + int m_nCUBEMAP; +#ifdef _DEBUG + bool m_bCUBEMAP; +#endif +public: + void SetCUBEMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCUBEMAP = i; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } + void SetCUBEMAP( bool i ) + { + m_nCUBEMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } +private: + int m_nDIFFUSELIGHTING; +#ifdef _DEBUG + bool m_bDIFFUSELIGHTING; +#endif +public: + void SetDIFFUSELIGHTING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDIFFUSELIGHTING = i; +#ifdef _DEBUG + m_bDIFFUSELIGHTING = true; +#endif + } + void SetDIFFUSELIGHTING( bool i ) + { + m_nDIFFUSELIGHTING = i ? 1 : 0; +#ifdef _DEBUG + m_bDIFFUSELIGHTING = true; +#endif + } +private: + int m_nENVMAPMASK; +#ifdef _DEBUG + bool m_bENVMAPMASK; +#endif +public: + void SetENVMAPMASK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nENVMAPMASK = i; +#ifdef _DEBUG + m_bENVMAPMASK = true; +#endif + } + void SetENVMAPMASK( bool i ) + { + m_nENVMAPMASK = i ? 1 : 0; +#ifdef _DEBUG + m_bENVMAPMASK = true; +#endif + } +private: + int m_nBASEALPHAENVMAPMASK; +#ifdef _DEBUG + bool m_bBASEALPHAENVMAPMASK; +#endif +public: + void SetBASEALPHAENVMAPMASK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBASEALPHAENVMAPMASK = i; +#ifdef _DEBUG + m_bBASEALPHAENVMAPMASK = true; +#endif + } + void SetBASEALPHAENVMAPMASK( bool i ) + { + m_nBASEALPHAENVMAPMASK = i ? 1 : 0; +#ifdef _DEBUG + m_bBASEALPHAENVMAPMASK = true; +#endif + } +private: + int m_nSELFILLUM; +#ifdef _DEBUG + bool m_bSELFILLUM; +#endif +public: + void SetSELFILLUM( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSELFILLUM = i; +#ifdef _DEBUG + m_bSELFILLUM = true; +#endif + } + void SetSELFILLUM( bool i ) + { + m_nSELFILLUM = i ? 1 : 0; +#ifdef _DEBUG + m_bSELFILLUM = true; +#endif + } +private: + int m_nVERTEXCOLOR; +#ifdef _DEBUG + bool m_bVERTEXCOLOR; +#endif +public: + void SetVERTEXCOLOR( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nVERTEXCOLOR = i; +#ifdef _DEBUG + m_bVERTEXCOLOR = true; +#endif + } + void SetVERTEXCOLOR( bool i ) + { + m_nVERTEXCOLOR = i ? 1 : 0; +#ifdef _DEBUG + m_bVERTEXCOLOR = true; +#endif + } +private: + int m_nFLASHLIGHT; +#ifdef _DEBUG + bool m_bFLASHLIGHT; +#endif +public: + void SetFLASHLIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFLASHLIGHT = i; +#ifdef _DEBUG + m_bFLASHLIGHT = true; +#endif + } + void SetFLASHLIGHT( bool i ) + { + m_nFLASHLIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bFLASHLIGHT = true; +#endif + } +private: + int m_nSELFILLUM_ENVMAPMASK_ALPHA; +#ifdef _DEBUG + bool m_bSELFILLUM_ENVMAPMASK_ALPHA; +#endif +public: + void SetSELFILLUM_ENVMAPMASK_ALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSELFILLUM_ENVMAPMASK_ALPHA = i; +#ifdef _DEBUG + m_bSELFILLUM_ENVMAPMASK_ALPHA = true; +#endif + } + void SetSELFILLUM_ENVMAPMASK_ALPHA( bool i ) + { + m_nSELFILLUM_ENVMAPMASK_ALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bSELFILLUM_ENVMAPMASK_ALPHA = true; +#endif + } +private: + int m_nDETAIL_BLEND_MODE; +#ifdef _DEBUG + bool m_bDETAIL_BLEND_MODE; +#endif +public: + void SetDETAIL_BLEND_MODE( int i ) + { + Assert( i >= 0 && i <= 9 ); + m_nDETAIL_BLEND_MODE = i; +#ifdef _DEBUG + m_bDETAIL_BLEND_MODE = true; +#endif + } + void SetDETAIL_BLEND_MODE( bool i ) + { + m_nDETAIL_BLEND_MODE = i ? 1 : 0; +#ifdef _DEBUG + m_bDETAIL_BLEND_MODE = true; +#endif + } +private: + int m_nSEAMLESS_BASE; +#ifdef _DEBUG + bool m_bSEAMLESS_BASE; +#endif +public: + void SetSEAMLESS_BASE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSEAMLESS_BASE = i; +#ifdef _DEBUG + m_bSEAMLESS_BASE = true; +#endif + } + void SetSEAMLESS_BASE( bool i ) + { + m_nSEAMLESS_BASE = i ? 1 : 0; +#ifdef _DEBUG + m_bSEAMLESS_BASE = true; +#endif + } +private: + int m_nSEAMLESS_DETAIL; +#ifdef _DEBUG + bool m_bSEAMLESS_DETAIL; +#endif +public: + void SetSEAMLESS_DETAIL( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSEAMLESS_DETAIL = i; +#ifdef _DEBUG + m_bSEAMLESS_DETAIL = true; +#endif + } + void SetSEAMLESS_DETAIL( bool i ) + { + m_nSEAMLESS_DETAIL = i ? 1 : 0; +#ifdef _DEBUG + m_bSEAMLESS_DETAIL = true; +#endif + } +private: + int m_nDISTANCEALPHA; +#ifdef _DEBUG + bool m_bDISTANCEALPHA; +#endif +public: + void SetDISTANCEALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDISTANCEALPHA = i; +#ifdef _DEBUG + m_bDISTANCEALPHA = true; +#endif + } + void SetDISTANCEALPHA( bool i ) + { + m_nDISTANCEALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bDISTANCEALPHA = true; +#endif + } +private: + int m_nDISTANCEALPHAFROMDETAIL; +#ifdef _DEBUG + bool m_bDISTANCEALPHAFROMDETAIL; +#endif +public: + void SetDISTANCEALPHAFROMDETAIL( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDISTANCEALPHAFROMDETAIL = i; +#ifdef _DEBUG + m_bDISTANCEALPHAFROMDETAIL = true; +#endif + } + void SetDISTANCEALPHAFROMDETAIL( bool i ) + { + m_nDISTANCEALPHAFROMDETAIL = i ? 1 : 0; +#ifdef _DEBUG + m_bDISTANCEALPHAFROMDETAIL = true; +#endif + } +private: + int m_nSOFT_MASK; +#ifdef _DEBUG + bool m_bSOFT_MASK; +#endif +public: + void SetSOFT_MASK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSOFT_MASK = i; +#ifdef _DEBUG + m_bSOFT_MASK = true; +#endif + } + void SetSOFT_MASK( bool i ) + { + m_nSOFT_MASK = i ? 1 : 0; +#ifdef _DEBUG + m_bSOFT_MASK = true; +#endif + } +private: + int m_nOUTLINE; +#ifdef _DEBUG + bool m_bOUTLINE; +#endif +public: + void SetOUTLINE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nOUTLINE = i; +#ifdef _DEBUG + m_bOUTLINE = true; +#endif + } + void SetOUTLINE( bool i ) + { + m_nOUTLINE = i ? 1 : 0; +#ifdef _DEBUG + m_bOUTLINE = true; +#endif + } +private: + int m_nOUTER_GLOW; +#ifdef _DEBUG + bool m_bOUTER_GLOW; +#endif +public: + void SetOUTER_GLOW( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nOUTER_GLOW = i; +#ifdef _DEBUG + m_bOUTER_GLOW = true; +#endif + } + void SetOUTER_GLOW( bool i ) + { + m_nOUTER_GLOW = i ? 1 : 0; +#ifdef _DEBUG + m_bOUTER_GLOW = true; +#endif + } +private: + int m_nFLASHLIGHTDEPTHFILTERMODE; +#ifdef _DEBUG + bool m_bFLASHLIGHTDEPTHFILTERMODE; +#endif +public: + void SetFLASHLIGHTDEPTHFILTERMODE( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nFLASHLIGHTDEPTHFILTERMODE = i; +#ifdef _DEBUG + m_bFLASHLIGHTDEPTHFILTERMODE = true; +#endif + } + void SetFLASHLIGHTDEPTHFILTERMODE( bool i ) + { + m_nFLASHLIGHTDEPTHFILTERMODE = i ? 1 : 0; +#ifdef _DEBUG + m_bFLASHLIGHTDEPTHFILTERMODE = true; +#endif + } +private: + int m_nDEPTHBLEND; +#ifdef _DEBUG + bool m_bDEPTHBLEND; +#endif +public: + void SetDEPTHBLEND( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDEPTHBLEND = i; +#ifdef _DEBUG + m_bDEPTHBLEND = true; +#endif + } + void SetDEPTHBLEND( bool i ) + { + m_nDEPTHBLEND = i ? 1 : 0; +#ifdef _DEBUG + m_bDEPTHBLEND = true; +#endif + } +private: + int m_nBLENDTINTBYBASEALPHA; +#ifdef _DEBUG + bool m_bBLENDTINTBYBASEALPHA; +#endif +public: + void SetBLENDTINTBYBASEALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBLENDTINTBYBASEALPHA = i; +#ifdef _DEBUG + m_bBLENDTINTBYBASEALPHA = true; +#endif + } + void SetBLENDTINTBYBASEALPHA( bool i ) + { + m_nBLENDTINTBYBASEALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bBLENDTINTBYBASEALPHA = true; +#endif + } +private: + int m_nCUBEMAP_SPHERE_LEGACY; +#ifdef _DEBUG + bool m_bCUBEMAP_SPHERE_LEGACY; +#endif +public: + void SetCUBEMAP_SPHERE_LEGACY( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCUBEMAP_SPHERE_LEGACY = i; +#ifdef _DEBUG + m_bCUBEMAP_SPHERE_LEGACY = true; +#endif + } + void SetCUBEMAP_SPHERE_LEGACY( bool i ) + { + m_nCUBEMAP_SPHERE_LEGACY = i ? 1 : 0; +#ifdef _DEBUG + m_bCUBEMAP_SPHERE_LEGACY = true; +#endif + } +public: + vertexlit_and_unlit_generic_ps30_Static_Index( ) + { +#ifdef _DEBUG + m_bDETAILTEXTURE = false; +#endif // _DEBUG + m_nDETAILTEXTURE = 0; +#ifdef _DEBUG + m_bCUBEMAP = false; +#endif // _DEBUG + m_nCUBEMAP = 0; +#ifdef _DEBUG + m_bDIFFUSELIGHTING = false; +#endif // _DEBUG + m_nDIFFUSELIGHTING = 0; +#ifdef _DEBUG + m_bENVMAPMASK = false; +#endif // _DEBUG + m_nENVMAPMASK = 0; +#ifdef _DEBUG + m_bBASEALPHAENVMAPMASK = false; +#endif // _DEBUG + m_nBASEALPHAENVMAPMASK = 0; +#ifdef _DEBUG + m_bSELFILLUM = false; +#endif // _DEBUG + m_nSELFILLUM = 0; +#ifdef _DEBUG + m_bVERTEXCOLOR = false; +#endif // _DEBUG + m_nVERTEXCOLOR = 0; +#ifdef _DEBUG + m_bFLASHLIGHT = false; +#endif // _DEBUG + m_nFLASHLIGHT = 0; +#ifdef _DEBUG + m_bSELFILLUM_ENVMAPMASK_ALPHA = false; +#endif // _DEBUG + m_nSELFILLUM_ENVMAPMASK_ALPHA = 0; +#ifdef _DEBUG + m_bDETAIL_BLEND_MODE = false; +#endif // _DEBUG + m_nDETAIL_BLEND_MODE = 0; +#ifdef _DEBUG + m_bSEAMLESS_BASE = false; +#endif // _DEBUG + m_nSEAMLESS_BASE = 0; +#ifdef _DEBUG + m_bSEAMLESS_DETAIL = false; +#endif // _DEBUG + m_nSEAMLESS_DETAIL = 0; +#ifdef _DEBUG + m_bDISTANCEALPHA = false; +#endif // _DEBUG + m_nDISTANCEALPHA = 0; +#ifdef _DEBUG + m_bDISTANCEALPHAFROMDETAIL = false; +#endif // _DEBUG + m_nDISTANCEALPHAFROMDETAIL = 0; +#ifdef _DEBUG + m_bSOFT_MASK = false; +#endif // _DEBUG + m_nSOFT_MASK = 0; +#ifdef _DEBUG + m_bOUTLINE = false; +#endif // _DEBUG + m_nOUTLINE = 0; +#ifdef _DEBUG + m_bOUTER_GLOW = false; +#endif // _DEBUG + m_nOUTER_GLOW = 0; +#ifdef _DEBUG + m_bFLASHLIGHTDEPTHFILTERMODE = false; +#endif // _DEBUG + m_nFLASHLIGHTDEPTHFILTERMODE = 0; +#ifdef _DEBUG + m_bDEPTHBLEND = false; +#endif // _DEBUG + m_nDEPTHBLEND = 0; +#ifdef _DEBUG + m_bBLENDTINTBYBASEALPHA = false; +#endif // _DEBUG + m_nBLENDTINTBYBASEALPHA = 0; +#ifdef _DEBUG + m_bCUBEMAP_SPHERE_LEGACY = false; +#endif // _DEBUG + m_nCUBEMAP_SPHERE_LEGACY = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bDETAILTEXTURE && m_bCUBEMAP && m_bDIFFUSELIGHTING && m_bENVMAPMASK && m_bBASEALPHAENVMAPMASK && m_bSELFILLUM && m_bVERTEXCOLOR && m_bFLASHLIGHT && m_bSELFILLUM_ENVMAPMASK_ALPHA && m_bDETAIL_BLEND_MODE && m_bSEAMLESS_BASE && m_bSEAMLESS_DETAIL && m_bDISTANCEALPHA && m_bDISTANCEALPHAFROMDETAIL && m_bSOFT_MASK && m_bOUTLINE && m_bOUTER_GLOW && m_bFLASHLIGHTDEPTHFILTERMODE && m_bDEPTHBLEND && m_bBLENDTINTBYBASEALPHA && m_bCUBEMAP_SPHERE_LEGACY; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 24 * m_nDETAILTEXTURE ) + ( 48 * m_nCUBEMAP ) + ( 96 * m_nDIFFUSELIGHTING ) + ( 192 * m_nENVMAPMASK ) + ( 384 * m_nBASEALPHAENVMAPMASK ) + ( 768 * m_nSELFILLUM ) + ( 1536 * m_nVERTEXCOLOR ) + ( 3072 * m_nFLASHLIGHT ) + ( 6144 * m_nSELFILLUM_ENVMAPMASK_ALPHA ) + ( 12288 * m_nDETAIL_BLEND_MODE ) + ( 122880 * m_nSEAMLESS_BASE ) + ( 245760 * m_nSEAMLESS_DETAIL ) + ( 491520 * m_nDISTANCEALPHA ) + ( 983040 * m_nDISTANCEALPHAFROMDETAIL ) + ( 1966080 * m_nSOFT_MASK ) + ( 3932160 * m_nOUTLINE ) + ( 7864320 * m_nOUTER_GLOW ) + ( 15728640 * m_nFLASHLIGHTDEPTHFILTERMODE ) + ( 47185920 * m_nDEPTHBLEND ) + ( 94371840 * m_nBLENDTINTBYBASEALPHA ) + ( 188743680 * m_nCUBEMAP_SPHERE_LEGACY ) + 0; + } +}; +#define shaderStaticTest_vertexlit_and_unlit_generic_ps30 psh_forgot_to_set_static_DETAILTEXTURE + psh_forgot_to_set_static_CUBEMAP + psh_forgot_to_set_static_DIFFUSELIGHTING + psh_forgot_to_set_static_ENVMAPMASK + psh_forgot_to_set_static_BASEALPHAENVMAPMASK + psh_forgot_to_set_static_SELFILLUM + psh_forgot_to_set_static_VERTEXCOLOR + psh_forgot_to_set_static_FLASHLIGHT + psh_forgot_to_set_static_SELFILLUM_ENVMAPMASK_ALPHA + psh_forgot_to_set_static_DETAIL_BLEND_MODE + psh_forgot_to_set_static_SEAMLESS_BASE + psh_forgot_to_set_static_SEAMLESS_DETAIL + psh_forgot_to_set_static_DISTANCEALPHA + psh_forgot_to_set_static_DISTANCEALPHAFROMDETAIL + psh_forgot_to_set_static_SOFT_MASK + psh_forgot_to_set_static_OUTLINE + psh_forgot_to_set_static_OUTER_GLOW + psh_forgot_to_set_static_FLASHLIGHTDEPTHFILTERMODE + psh_forgot_to_set_static_DEPTHBLEND + psh_forgot_to_set_static_BLENDTINTBYBASEALPHA + psh_forgot_to_set_static_CUBEMAP_SPHERE_LEGACY + 0 +class vertexlit_and_unlit_generic_ps30_Dynamic_Index +{ +private: + int m_nLIGHTING_PREVIEW; +#ifdef _DEBUG + bool m_bLIGHTING_PREVIEW; +#endif +public: + void SetLIGHTING_PREVIEW( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nLIGHTING_PREVIEW = i; +#ifdef _DEBUG + m_bLIGHTING_PREVIEW = true; +#endif + } + void SetLIGHTING_PREVIEW( bool i ) + { + m_nLIGHTING_PREVIEW = i ? 1 : 0; +#ifdef _DEBUG + m_bLIGHTING_PREVIEW = true; +#endif + } +private: + int m_nFLASHLIGHTSHADOWS; +#ifdef _DEBUG + bool m_bFLASHLIGHTSHADOWS; +#endif +public: + void SetFLASHLIGHTSHADOWS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFLASHLIGHTSHADOWS = i; +#ifdef _DEBUG + m_bFLASHLIGHTSHADOWS = true; +#endif + } + void SetFLASHLIGHTSHADOWS( bool i ) + { + m_nFLASHLIGHTSHADOWS = i ? 1 : 0; +#ifdef _DEBUG + m_bFLASHLIGHTSHADOWS = true; +#endif + } +private: + int m_nSTATIC_LIGHT_LIGHTMAP; +#ifdef _DEBUG + bool m_bSTATIC_LIGHT_LIGHTMAP; +#endif +public: + void SetSTATIC_LIGHT_LIGHTMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSTATIC_LIGHT_LIGHTMAP = i; +#ifdef _DEBUG + m_bSTATIC_LIGHT_LIGHTMAP = true; +#endif + } + void SetSTATIC_LIGHT_LIGHTMAP( bool i ) + { + m_nSTATIC_LIGHT_LIGHTMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bSTATIC_LIGHT_LIGHTMAP = true; +#endif + } +private: + int m_nDEBUG_LUXELS; +#ifdef _DEBUG + bool m_bDEBUG_LUXELS; +#endif +public: + void SetDEBUG_LUXELS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDEBUG_LUXELS = i; +#ifdef _DEBUG + m_bDEBUG_LUXELS = true; +#endif + } + void SetDEBUG_LUXELS( bool i ) + { + m_nDEBUG_LUXELS = i ? 1 : 0; +#ifdef _DEBUG + m_bDEBUG_LUXELS = true; +#endif + } +public: + vertexlit_and_unlit_generic_ps30_Dynamic_Index() + { +#ifdef _DEBUG + m_bLIGHTING_PREVIEW = false; +#endif // _DEBUG + m_nLIGHTING_PREVIEW = 0; +#ifdef _DEBUG + m_bFLASHLIGHTSHADOWS = false; +#endif // _DEBUG + m_nFLASHLIGHTSHADOWS = 0; +#ifdef _DEBUG + m_bSTATIC_LIGHT_LIGHTMAP = false; +#endif // _DEBUG + m_nSTATIC_LIGHT_LIGHTMAP = 0; +#ifdef _DEBUG + m_bDEBUG_LUXELS = false; +#endif // _DEBUG + m_nDEBUG_LUXELS = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bLIGHTING_PREVIEW && m_bFLASHLIGHTSHADOWS && m_bSTATIC_LIGHT_LIGHTMAP && m_bDEBUG_LUXELS; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nLIGHTING_PREVIEW ) + ( 3 * m_nFLASHLIGHTSHADOWS ) + ( 6 * m_nSTATIC_LIGHT_LIGHTMAP ) + ( 12 * m_nDEBUG_LUXELS ) + 0; + } +}; +#define shaderDynamicTest_vertexlit_and_unlit_generic_ps30 psh_forgot_to_set_dynamic_LIGHTING_PREVIEW + psh_forgot_to_set_dynamic_FLASHLIGHTSHADOWS + psh_forgot_to_set_dynamic_STATIC_LIGHT_LIGHTMAP + psh_forgot_to_set_dynamic_DEBUG_LUXELS + 0 diff --git a/materialsystem/stdshaders/fxctmp9/vertexlit_and_unlit_generic_vs30.inc b/materialsystem/stdshaders/fxctmp9/vertexlit_and_unlit_generic_vs30.inc new file mode 100644 index 0000000..7473d29 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/vertexlit_and_unlit_generic_vs30.inc @@ -0,0 +1,462 @@ +#include "shaderlib/cshader.h" +class vertexlit_and_unlit_generic_vs30_Static_Index +{ +private: + int m_nVERTEXCOLOR; +#ifdef _DEBUG + bool m_bVERTEXCOLOR; +#endif +public: + void SetVERTEXCOLOR( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nVERTEXCOLOR = i; +#ifdef _DEBUG + m_bVERTEXCOLOR = true; +#endif + } + void SetVERTEXCOLOR( bool i ) + { + m_nVERTEXCOLOR = i ? 1 : 0; +#ifdef _DEBUG + m_bVERTEXCOLOR = true; +#endif + } +private: + int m_nCUBEMAP; +#ifdef _DEBUG + bool m_bCUBEMAP; +#endif +public: + void SetCUBEMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCUBEMAP = i; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } + void SetCUBEMAP( bool i ) + { + m_nCUBEMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } +private: + int m_nHALFLAMBERT; +#ifdef _DEBUG + bool m_bHALFLAMBERT; +#endif +public: + void SetHALFLAMBERT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHALFLAMBERT = i; +#ifdef _DEBUG + m_bHALFLAMBERT = true; +#endif + } + void SetHALFLAMBERT( bool i ) + { + m_nHALFLAMBERT = i ? 1 : 0; +#ifdef _DEBUG + m_bHALFLAMBERT = true; +#endif + } +private: + int m_nFLASHLIGHT; +#ifdef _DEBUG + bool m_bFLASHLIGHT; +#endif +public: + void SetFLASHLIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFLASHLIGHT = i; +#ifdef _DEBUG + m_bFLASHLIGHT = true; +#endif + } + void SetFLASHLIGHT( bool i ) + { + m_nFLASHLIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bFLASHLIGHT = true; +#endif + } +private: + int m_nSEAMLESS_BASE; +#ifdef _DEBUG + bool m_bSEAMLESS_BASE; +#endif +public: + void SetSEAMLESS_BASE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSEAMLESS_BASE = i; +#ifdef _DEBUG + m_bSEAMLESS_BASE = true; +#endif + } + void SetSEAMLESS_BASE( bool i ) + { + m_nSEAMLESS_BASE = i ? 1 : 0; +#ifdef _DEBUG + m_bSEAMLESS_BASE = true; +#endif + } +private: + int m_nSEAMLESS_DETAIL; +#ifdef _DEBUG + bool m_bSEAMLESS_DETAIL; +#endif +public: + void SetSEAMLESS_DETAIL( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSEAMLESS_DETAIL = i; +#ifdef _DEBUG + m_bSEAMLESS_DETAIL = true; +#endif + } + void SetSEAMLESS_DETAIL( bool i ) + { + m_nSEAMLESS_DETAIL = i ? 1 : 0; +#ifdef _DEBUG + m_bSEAMLESS_DETAIL = true; +#endif + } +private: + int m_nSEPARATE_DETAIL_UVS; +#ifdef _DEBUG + bool m_bSEPARATE_DETAIL_UVS; +#endif +public: + void SetSEPARATE_DETAIL_UVS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSEPARATE_DETAIL_UVS = i; +#ifdef _DEBUG + m_bSEPARATE_DETAIL_UVS = true; +#endif + } + void SetSEPARATE_DETAIL_UVS( bool i ) + { + m_nSEPARATE_DETAIL_UVS = i ? 1 : 0; +#ifdef _DEBUG + m_bSEPARATE_DETAIL_UVS = true; +#endif + } +private: + int m_nDECAL; +#ifdef _DEBUG + bool m_bDECAL; +#endif +public: + void SetDECAL( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDECAL = i; +#ifdef _DEBUG + m_bDECAL = true; +#endif + } + void SetDECAL( bool i ) + { + m_nDECAL = i ? 1 : 0; +#ifdef _DEBUG + m_bDECAL = true; +#endif + } +private: + int m_nDONT_GAMMA_CONVERT_VERTEX_COLOR; +#ifdef _DEBUG + bool m_bDONT_GAMMA_CONVERT_VERTEX_COLOR; +#endif +public: + void SetDONT_GAMMA_CONVERT_VERTEX_COLOR( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDONT_GAMMA_CONVERT_VERTEX_COLOR = i; +#ifdef _DEBUG + m_bDONT_GAMMA_CONVERT_VERTEX_COLOR = true; +#endif + } + void SetDONT_GAMMA_CONVERT_VERTEX_COLOR( bool i ) + { + m_nDONT_GAMMA_CONVERT_VERTEX_COLOR = i ? 1 : 0; +#ifdef _DEBUG + m_bDONT_GAMMA_CONVERT_VERTEX_COLOR = true; +#endif + } +public: + vertexlit_and_unlit_generic_vs30_Static_Index( ) + { +#ifdef _DEBUG + m_bVERTEXCOLOR = false; +#endif // _DEBUG + m_nVERTEXCOLOR = 0; +#ifdef _DEBUG + m_bCUBEMAP = false; +#endif // _DEBUG + m_nCUBEMAP = 0; +#ifdef _DEBUG + m_bHALFLAMBERT = false; +#endif // _DEBUG + m_nHALFLAMBERT = 0; +#ifdef _DEBUG + m_bFLASHLIGHT = false; +#endif // _DEBUG + m_nFLASHLIGHT = 0; +#ifdef _DEBUG + m_bSEAMLESS_BASE = false; +#endif // _DEBUG + m_nSEAMLESS_BASE = 0; +#ifdef _DEBUG + m_bSEAMLESS_DETAIL = false; +#endif // _DEBUG + m_nSEAMLESS_DETAIL = 0; +#ifdef _DEBUG + m_bSEPARATE_DETAIL_UVS = false; +#endif // _DEBUG + m_nSEPARATE_DETAIL_UVS = 0; +#ifdef _DEBUG + m_bDECAL = false; +#endif // _DEBUG + m_nDECAL = 0; +#ifdef _DEBUG + m_bDONT_GAMMA_CONVERT_VERTEX_COLOR = false; +#endif // _DEBUG + m_nDONT_GAMMA_CONVERT_VERTEX_COLOR = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bVERTEXCOLOR && m_bCUBEMAP && m_bHALFLAMBERT && m_bFLASHLIGHT && m_bSEAMLESS_BASE && m_bSEAMLESS_DETAIL && m_bSEPARATE_DETAIL_UVS && m_bDECAL && m_bDONT_GAMMA_CONVERT_VERTEX_COLOR; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 256 * m_nVERTEXCOLOR ) + ( 512 * m_nCUBEMAP ) + ( 1024 * m_nHALFLAMBERT ) + ( 2048 * m_nFLASHLIGHT ) + ( 4096 * m_nSEAMLESS_BASE ) + ( 8192 * m_nSEAMLESS_DETAIL ) + ( 16384 * m_nSEPARATE_DETAIL_UVS ) + ( 32768 * m_nDECAL ) + ( 65536 * m_nDONT_GAMMA_CONVERT_VERTEX_COLOR ) + 0; + } +}; +#define shaderStaticTest_vertexlit_and_unlit_generic_vs30 vsh_forgot_to_set_static_VERTEXCOLOR + vsh_forgot_to_set_static_CUBEMAP + vsh_forgot_to_set_static_HALFLAMBERT + vsh_forgot_to_set_static_FLASHLIGHT + vsh_forgot_to_set_static_SEAMLESS_BASE + vsh_forgot_to_set_static_SEAMLESS_DETAIL + vsh_forgot_to_set_static_SEPARATE_DETAIL_UVS + vsh_forgot_to_set_static_DECAL + vsh_forgot_to_set_static_DONT_GAMMA_CONVERT_VERTEX_COLOR + 0 +class vertexlit_and_unlit_generic_vs30_Dynamic_Index +{ +private: + int m_nCOMPRESSED_VERTS; +#ifdef _DEBUG + bool m_bCOMPRESSED_VERTS; +#endif +public: + void SetCOMPRESSED_VERTS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOMPRESSED_VERTS = i; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } + void SetCOMPRESSED_VERTS( bool i ) + { + m_nCOMPRESSED_VERTS = i ? 1 : 0; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } +private: + int m_nDYNAMIC_LIGHT; +#ifdef _DEBUG + bool m_bDYNAMIC_LIGHT; +#endif +public: + void SetDYNAMIC_LIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDYNAMIC_LIGHT = i; +#ifdef _DEBUG + m_bDYNAMIC_LIGHT = true; +#endif + } + void SetDYNAMIC_LIGHT( bool i ) + { + m_nDYNAMIC_LIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bDYNAMIC_LIGHT = true; +#endif + } +private: + int m_nSTATIC_LIGHT_VERTEX; +#ifdef _DEBUG + bool m_bSTATIC_LIGHT_VERTEX; +#endif +public: + void SetSTATIC_LIGHT_VERTEX( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSTATIC_LIGHT_VERTEX = i; +#ifdef _DEBUG + m_bSTATIC_LIGHT_VERTEX = true; +#endif + } + void SetSTATIC_LIGHT_VERTEX( bool i ) + { + m_nSTATIC_LIGHT_VERTEX = i ? 1 : 0; +#ifdef _DEBUG + m_bSTATIC_LIGHT_VERTEX = true; +#endif + } +private: + int m_nSTATIC_LIGHT_LIGHTMAP; +#ifdef _DEBUG + bool m_bSTATIC_LIGHT_LIGHTMAP; +#endif +public: + void SetSTATIC_LIGHT_LIGHTMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSTATIC_LIGHT_LIGHTMAP = i; +#ifdef _DEBUG + m_bSTATIC_LIGHT_LIGHTMAP = true; +#endif + } + void SetSTATIC_LIGHT_LIGHTMAP( bool i ) + { + m_nSTATIC_LIGHT_LIGHTMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bSTATIC_LIGHT_LIGHTMAP = true; +#endif + } +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +private: + int m_nLIGHTING_PREVIEW; +#ifdef _DEBUG + bool m_bLIGHTING_PREVIEW; +#endif +public: + void SetLIGHTING_PREVIEW( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nLIGHTING_PREVIEW = i; +#ifdef _DEBUG + m_bLIGHTING_PREVIEW = true; +#endif + } + void SetLIGHTING_PREVIEW( bool i ) + { + m_nLIGHTING_PREVIEW = i ? 1 : 0; +#ifdef _DEBUG + m_bLIGHTING_PREVIEW = true; +#endif + } +private: + int m_nMORPHING; +#ifdef _DEBUG + bool m_bMORPHING; +#endif +public: + void SetMORPHING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nMORPHING = i; +#ifdef _DEBUG + m_bMORPHING = true; +#endif + } + void SetMORPHING( bool i ) + { + m_nMORPHING = i ? 1 : 0; +#ifdef _DEBUG + m_bMORPHING = true; +#endif + } +public: + vertexlit_and_unlit_generic_vs30_Dynamic_Index() + { +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = false; +#endif // _DEBUG + m_nCOMPRESSED_VERTS = 0; +#ifdef _DEBUG + m_bDYNAMIC_LIGHT = false; +#endif // _DEBUG + m_nDYNAMIC_LIGHT = 0; +#ifdef _DEBUG + m_bSTATIC_LIGHT_VERTEX = false; +#endif // _DEBUG + m_nSTATIC_LIGHT_VERTEX = 0; +#ifdef _DEBUG + m_bSTATIC_LIGHT_LIGHTMAP = false; +#endif // _DEBUG + m_nSTATIC_LIGHT_LIGHTMAP = 0; +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; +#ifdef _DEBUG + m_bLIGHTING_PREVIEW = false; +#endif // _DEBUG + m_nLIGHTING_PREVIEW = 0; +#ifdef _DEBUG + m_bMORPHING = false; +#endif // _DEBUG + m_nMORPHING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bCOMPRESSED_VERTS && m_bDYNAMIC_LIGHT && m_bSTATIC_LIGHT_VERTEX && m_bSTATIC_LIGHT_LIGHTMAP && m_bDOWATERFOG && m_bSKINNING && m_bLIGHTING_PREVIEW && m_bMORPHING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCOMPRESSED_VERTS ) + ( 2 * m_nDYNAMIC_LIGHT ) + ( 4 * m_nSTATIC_LIGHT_VERTEX ) + ( 8 * m_nSTATIC_LIGHT_LIGHTMAP ) + ( 16 * m_nDOWATERFOG ) + ( 32 * m_nSKINNING ) + ( 64 * m_nLIGHTING_PREVIEW ) + ( 128 * m_nMORPHING ) + 0; + } +}; +#define shaderDynamicTest_vertexlit_and_unlit_generic_vs30 vsh_forgot_to_set_dynamic_COMPRESSED_VERTS + vsh_forgot_to_set_dynamic_DYNAMIC_LIGHT + vsh_forgot_to_set_dynamic_STATIC_LIGHT_VERTEX + vsh_forgot_to_set_dynamic_STATIC_LIGHT_LIGHTMAP + vsh_forgot_to_set_dynamic_DOWATERFOG + vsh_forgot_to_set_dynamic_SKINNING + vsh_forgot_to_set_dynamic_LIGHTING_PREVIEW + vsh_forgot_to_set_dynamic_MORPHING + 0 diff --git a/materialsystem/stdshaders/fxctmp9/vertexlit_lighting_only_ps20.inc b/materialsystem/stdshaders/fxctmp9/vertexlit_lighting_only_ps20.inc new file mode 100644 index 0000000..7634f65 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/vertexlit_lighting_only_ps20.inc @@ -0,0 +1,137 @@ +#include "shaderlib/cshader.h" +class vertexlit_lighting_only_ps20_Static_Index +{ +private: + int m_nDIFFUSELIGHTING; +#ifdef _DEBUG + bool m_bDIFFUSELIGHTING; +#endif +public: + void SetDIFFUSELIGHTING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDIFFUSELIGHTING = i; +#ifdef _DEBUG + m_bDIFFUSELIGHTING = true; +#endif + } + void SetDIFFUSELIGHTING( bool i ) + { + m_nDIFFUSELIGHTING = i ? 1 : 0; +#ifdef _DEBUG + m_bDIFFUSELIGHTING = true; +#endif + } +private: + int m_nHALFLAMBERT; +#ifdef _DEBUG + bool m_bHALFLAMBERT; +#endif +public: + void SetHALFLAMBERT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHALFLAMBERT = i; +#ifdef _DEBUG + m_bHALFLAMBERT = true; +#endif + } + void SetHALFLAMBERT( bool i ) + { + m_nHALFLAMBERT = i ? 1 : 0; +#ifdef _DEBUG + m_bHALFLAMBERT = true; +#endif + } +public: + vertexlit_lighting_only_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bDIFFUSELIGHTING = false; +#endif // _DEBUG + m_nDIFFUSELIGHTING = 0; +#ifdef _DEBUG + m_bHALFLAMBERT = false; +#endif // _DEBUG + m_nHALFLAMBERT = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bDIFFUSELIGHTING && m_bHALFLAMBERT; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 6 * m_nDIFFUSELIGHTING ) + ( 12 * m_nHALFLAMBERT ) + 0; + } +}; +#define shaderStaticTest_vertexlit_lighting_only_ps20 psh_forgot_to_set_static_DIFFUSELIGHTING + psh_forgot_to_set_static_HALFLAMBERT + 0 +class vertexlit_lighting_only_ps20_Dynamic_Index +{ +private: + int m_nAMBIENT_LIGHT; +#ifdef _DEBUG + bool m_bAMBIENT_LIGHT; +#endif +public: + void SetAMBIENT_LIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nAMBIENT_LIGHT = i; +#ifdef _DEBUG + m_bAMBIENT_LIGHT = true; +#endif + } + void SetAMBIENT_LIGHT( bool i ) + { + m_nAMBIENT_LIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bAMBIENT_LIGHT = true; +#endif + } +private: + int m_nNUM_LIGHTS; +#ifdef _DEBUG + bool m_bNUM_LIGHTS; +#endif +public: + void SetNUM_LIGHTS( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nNUM_LIGHTS = i; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } + void SetNUM_LIGHTS( bool i ) + { + m_nNUM_LIGHTS = i ? 1 : 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } +public: + vertexlit_lighting_only_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bAMBIENT_LIGHT = false; +#endif // _DEBUG + m_nAMBIENT_LIGHT = 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = false; +#endif // _DEBUG + m_nNUM_LIGHTS = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bAMBIENT_LIGHT && m_bNUM_LIGHTS; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nAMBIENT_LIGHT ) + ( 2 * m_nNUM_LIGHTS ) + 0; + } +}; +#define shaderDynamicTest_vertexlit_lighting_only_ps20 psh_forgot_to_set_dynamic_AMBIENT_LIGHT + psh_forgot_to_set_dynamic_NUM_LIGHTS + 0 diff --git a/materialsystem/stdshaders/fxctmp9/vertexlit_lighting_only_ps20b.inc b/materialsystem/stdshaders/fxctmp9/vertexlit_lighting_only_ps20b.inc new file mode 100644 index 0000000..cc1bfb3 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/vertexlit_lighting_only_ps20b.inc @@ -0,0 +1,162 @@ +#include "shaderlib/cshader.h" +class vertexlit_lighting_only_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +private: + int m_nDIFFUSELIGHTING; +#ifdef _DEBUG + bool m_bDIFFUSELIGHTING; +#endif +public: + void SetDIFFUSELIGHTING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDIFFUSELIGHTING = i; +#ifdef _DEBUG + m_bDIFFUSELIGHTING = true; +#endif + } + void SetDIFFUSELIGHTING( bool i ) + { + m_nDIFFUSELIGHTING = i ? 1 : 0; +#ifdef _DEBUG + m_bDIFFUSELIGHTING = true; +#endif + } +private: + int m_nHALFLAMBERT; +#ifdef _DEBUG + bool m_bHALFLAMBERT; +#endif +public: + void SetHALFLAMBERT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHALFLAMBERT = i; +#ifdef _DEBUG + m_bHALFLAMBERT = true; +#endif + } + void SetHALFLAMBERT( bool i ) + { + m_nHALFLAMBERT = i ? 1 : 0; +#ifdef _DEBUG + m_bHALFLAMBERT = true; +#endif + } +public: + vertexlit_lighting_only_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); +#ifdef _DEBUG + m_bDIFFUSELIGHTING = false; +#endif // _DEBUG + m_nDIFFUSELIGHTING = 0; +#ifdef _DEBUG + m_bHALFLAMBERT = false; +#endif // _DEBUG + m_nHALFLAMBERT = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB && m_bDIFFUSELIGHTING && m_bHALFLAMBERT; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 10 * m_nCONVERT_TO_SRGB ) + ( 20 * m_nDIFFUSELIGHTING ) + ( 40 * m_nHALFLAMBERT ) + 0; + } +}; +#define shaderStaticTest_vertexlit_lighting_only_ps20b psh_forgot_to_set_static_DIFFUSELIGHTING + psh_forgot_to_set_static_HALFLAMBERT + 0 +class vertexlit_lighting_only_ps20b_Dynamic_Index +{ +private: + int m_nAMBIENT_LIGHT; +#ifdef _DEBUG + bool m_bAMBIENT_LIGHT; +#endif +public: + void SetAMBIENT_LIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nAMBIENT_LIGHT = i; +#ifdef _DEBUG + m_bAMBIENT_LIGHT = true; +#endif + } + void SetAMBIENT_LIGHT( bool i ) + { + m_nAMBIENT_LIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bAMBIENT_LIGHT = true; +#endif + } +private: + int m_nNUM_LIGHTS; +#ifdef _DEBUG + bool m_bNUM_LIGHTS; +#endif +public: + void SetNUM_LIGHTS( int i ) + { + Assert( i >= 0 && i <= 4 ); + m_nNUM_LIGHTS = i; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } + void SetNUM_LIGHTS( bool i ) + { + m_nNUM_LIGHTS = i ? 1 : 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } +public: + vertexlit_lighting_only_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bAMBIENT_LIGHT = false; +#endif // _DEBUG + m_nAMBIENT_LIGHT = 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = false; +#endif // _DEBUG + m_nNUM_LIGHTS = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bAMBIENT_LIGHT && m_bNUM_LIGHTS; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nAMBIENT_LIGHT ) + ( 2 * m_nNUM_LIGHTS ) + 0; + } +}; +#define shaderDynamicTest_vertexlit_lighting_only_ps20b psh_forgot_to_set_dynamic_AMBIENT_LIGHT + psh_forgot_to_set_dynamic_NUM_LIGHTS + 0 diff --git a/materialsystem/stdshaders/fxctmp9/vertexlitgeneric_lightingonly_overbright2_ps11.inc b/materialsystem/stdshaders/fxctmp9/vertexlitgeneric_lightingonly_overbright2_ps11.inc new file mode 100644 index 0000000..7fc097a --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/vertexlitgeneric_lightingonly_overbright2_ps11.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class vertexlitgeneric_lightingonly_overbright2_ps11_Static_Index +{ +public: + vertexlitgeneric_lightingonly_overbright2_ps11_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_vertexlitgeneric_lightingonly_overbright2_ps11 0 +class vertexlitgeneric_lightingonly_overbright2_ps11_Dynamic_Index +{ +public: + vertexlitgeneric_lightingonly_overbright2_ps11_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_vertexlitgeneric_lightingonly_overbright2_ps11 0 diff --git a/materialsystem/stdshaders/fxctmp9/volume_clouds_ps20.inc b/materialsystem/stdshaders/fxctmp9/volume_clouds_ps20.inc new file mode 100644 index 0000000..4a79d14 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/volume_clouds_ps20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class volume_clouds_ps20_Static_Index +{ +public: + volume_clouds_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_volume_clouds_ps20 0 +class volume_clouds_ps20_Dynamic_Index +{ +public: + volume_clouds_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_volume_clouds_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9/volume_clouds_ps20b.inc b/materialsystem/stdshaders/fxctmp9/volume_clouds_ps20b.inc new file mode 100644 index 0000000..6e4458a --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/volume_clouds_ps20b.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class volume_clouds_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + volume_clouds_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_volume_clouds_ps20b 0 +class volume_clouds_ps20b_Dynamic_Index +{ +public: + volume_clouds_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_volume_clouds_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9/volume_clouds_vs20.inc b/materialsystem/stdshaders/fxctmp9/volume_clouds_vs20.inc new file mode 100644 index 0000000..d858334 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/volume_clouds_vs20.inc @@ -0,0 +1,85 @@ +#include "shaderlib/cshader.h" +class volume_clouds_vs20_Static_Index +{ +public: + volume_clouds_vs20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_volume_clouds_vs20 0 +class volume_clouds_vs20_Dynamic_Index +{ +private: + int m_nCOMPRESSED_VERTS; +#ifdef _DEBUG + bool m_bCOMPRESSED_VERTS; +#endif +public: + void SetCOMPRESSED_VERTS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOMPRESSED_VERTS = i; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } + void SetCOMPRESSED_VERTS( bool i ) + { + m_nCOMPRESSED_VERTS = i ? 1 : 0; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +public: + volume_clouds_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = false; +#endif // _DEBUG + m_nCOMPRESSED_VERTS = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bCOMPRESSED_VERTS && m_bSKINNING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCOMPRESSED_VERTS ) + ( 2 * m_nSKINNING ) + 0; + } +}; +#define shaderDynamicTest_volume_clouds_vs20 vsh_forgot_to_set_dynamic_COMPRESSED_VERTS + vsh_forgot_to_set_dynamic_SKINNING + 0 diff --git a/materialsystem/stdshaders/fxctmp9/vortwarp_ps20.inc b/materialsystem/stdshaders/fxctmp9/vortwarp_ps20.inc new file mode 100644 index 0000000..e10c6d7 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/vortwarp_ps20.inc @@ -0,0 +1,337 @@ +#include "shaderlib/cshader.h" +class vortwarp_ps20_Static_Index +{ +private: + int m_nBASETEXTURE; +#ifdef _DEBUG + bool m_bBASETEXTURE; +#endif +public: + void SetBASETEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBASETEXTURE = i; +#ifdef _DEBUG + m_bBASETEXTURE = true; +#endif + } + void SetBASETEXTURE( bool i ) + { + m_nBASETEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bBASETEXTURE = true; +#endif + } +private: + int m_nCUBEMAP; +#ifdef _DEBUG + bool m_bCUBEMAP; +#endif +public: + void SetCUBEMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCUBEMAP = i; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } + void SetCUBEMAP( bool i ) + { + m_nCUBEMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } +private: + int m_nDIFFUSELIGHTING; +#ifdef _DEBUG + bool m_bDIFFUSELIGHTING; +#endif +public: + void SetDIFFUSELIGHTING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDIFFUSELIGHTING = i; +#ifdef _DEBUG + m_bDIFFUSELIGHTING = true; +#endif + } + void SetDIFFUSELIGHTING( bool i ) + { + m_nDIFFUSELIGHTING = i ? 1 : 0; +#ifdef _DEBUG + m_bDIFFUSELIGHTING = true; +#endif + } +private: + int m_nNORMALMAPALPHAENVMAPMASK; +#ifdef _DEBUG + bool m_bNORMALMAPALPHAENVMAPMASK; +#endif +public: + void SetNORMALMAPALPHAENVMAPMASK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nNORMALMAPALPHAENVMAPMASK = i; +#ifdef _DEBUG + m_bNORMALMAPALPHAENVMAPMASK = true; +#endif + } + void SetNORMALMAPALPHAENVMAPMASK( bool i ) + { + m_nNORMALMAPALPHAENVMAPMASK = i ? 1 : 0; +#ifdef _DEBUG + m_bNORMALMAPALPHAENVMAPMASK = true; +#endif + } +private: + int m_nHALFLAMBERT; +#ifdef _DEBUG + bool m_bHALFLAMBERT; +#endif +public: + void SetHALFLAMBERT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHALFLAMBERT = i; +#ifdef _DEBUG + m_bHALFLAMBERT = true; +#endif + } + void SetHALFLAMBERT( bool i ) + { + m_nHALFLAMBERT = i ? 1 : 0; +#ifdef _DEBUG + m_bHALFLAMBERT = true; +#endif + } +private: + int m_nFLASHLIGHT; +#ifdef _DEBUG + bool m_bFLASHLIGHT; +#endif +public: + void SetFLASHLIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFLASHLIGHT = i; +#ifdef _DEBUG + m_bFLASHLIGHT = true; +#endif + } + void SetFLASHLIGHT( bool i ) + { + m_nFLASHLIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bFLASHLIGHT = true; +#endif + } +private: + int m_nTRANSLUCENT; +#ifdef _DEBUG + bool m_bTRANSLUCENT; +#endif +public: + void SetTRANSLUCENT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nTRANSLUCENT = i; +#ifdef _DEBUG + m_bTRANSLUCENT = true; +#endif + } + void SetTRANSLUCENT( bool i ) + { + m_nTRANSLUCENT = i ? 1 : 0; +#ifdef _DEBUG + m_bTRANSLUCENT = true; +#endif + } +public: + vortwarp_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bBASETEXTURE = false; +#endif // _DEBUG + m_nBASETEXTURE = 0; +#ifdef _DEBUG + m_bCUBEMAP = false; +#endif // _DEBUG + m_nCUBEMAP = 0; +#ifdef _DEBUG + m_bDIFFUSELIGHTING = false; +#endif // _DEBUG + m_nDIFFUSELIGHTING = 0; +#ifdef _DEBUG + m_bNORMALMAPALPHAENVMAPMASK = false; +#endif // _DEBUG + m_nNORMALMAPALPHAENVMAPMASK = 0; +#ifdef _DEBUG + m_bHALFLAMBERT = false; +#endif // _DEBUG + m_nHALFLAMBERT = 0; +#ifdef _DEBUG + m_bFLASHLIGHT = false; +#endif // _DEBUG + m_nFLASHLIGHT = 0; +#ifdef _DEBUG + m_bTRANSLUCENT = false; +#endif // _DEBUG + m_nTRANSLUCENT = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bBASETEXTURE && m_bCUBEMAP && m_bDIFFUSELIGHTING && m_bNORMALMAPALPHAENVMAPMASK && m_bHALFLAMBERT && m_bFLASHLIGHT && m_bTRANSLUCENT; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 48 * m_nBASETEXTURE ) + ( 96 * m_nCUBEMAP ) + ( 192 * m_nDIFFUSELIGHTING ) + ( 384 * m_nNORMALMAPALPHAENVMAPMASK ) + ( 768 * m_nHALFLAMBERT ) + ( 1536 * m_nFLASHLIGHT ) + ( 3072 * m_nTRANSLUCENT ) + 0; + } +}; +#define shaderStaticTest_vortwarp_ps20 psh_forgot_to_set_static_BASETEXTURE + psh_forgot_to_set_static_CUBEMAP + psh_forgot_to_set_static_DIFFUSELIGHTING + psh_forgot_to_set_static_NORMALMAPALPHAENVMAPMASK + psh_forgot_to_set_static_HALFLAMBERT + psh_forgot_to_set_static_FLASHLIGHT + psh_forgot_to_set_static_TRANSLUCENT + 0 +class vortwarp_ps20_Dynamic_Index +{ +private: + int m_nWRITEWATERFOGTODESTALPHA; +#ifdef _DEBUG + bool m_bWRITEWATERFOGTODESTALPHA; +#endif +public: + void SetWRITEWATERFOGTODESTALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nWRITEWATERFOGTODESTALPHA = i; +#ifdef _DEBUG + m_bWRITEWATERFOGTODESTALPHA = true; +#endif + } + void SetWRITEWATERFOGTODESTALPHA( bool i ) + { + m_nWRITEWATERFOGTODESTALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bWRITEWATERFOGTODESTALPHA = true; +#endif + } +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +private: + int m_nWARPINGIN; +#ifdef _DEBUG + bool m_bWARPINGIN; +#endif +public: + void SetWARPINGIN( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nWARPINGIN = i; +#ifdef _DEBUG + m_bWARPINGIN = true; +#endif + } + void SetWARPINGIN( bool i ) + { + m_nWARPINGIN = i ? 1 : 0; +#ifdef _DEBUG + m_bWARPINGIN = true; +#endif + } +private: + int m_nAMBIENT_LIGHT; +#ifdef _DEBUG + bool m_bAMBIENT_LIGHT; +#endif +public: + void SetAMBIENT_LIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nAMBIENT_LIGHT = i; +#ifdef _DEBUG + m_bAMBIENT_LIGHT = true; +#endif + } + void SetAMBIENT_LIGHT( bool i ) + { + m_nAMBIENT_LIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bAMBIENT_LIGHT = true; +#endif + } +private: + int m_nNUM_LIGHTS; +#ifdef _DEBUG + bool m_bNUM_LIGHTS; +#endif +public: + void SetNUM_LIGHTS( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nNUM_LIGHTS = i; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } + void SetNUM_LIGHTS( bool i ) + { + m_nNUM_LIGHTS = i ? 1 : 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } +public: + vortwarp_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bWRITEWATERFOGTODESTALPHA = false; +#endif // _DEBUG + m_nWRITEWATERFOGTODESTALPHA = 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; +#ifdef _DEBUG + m_bWARPINGIN = false; +#endif // _DEBUG + m_nWARPINGIN = 0; +#ifdef _DEBUG + m_bAMBIENT_LIGHT = false; +#endif // _DEBUG + m_nAMBIENT_LIGHT = 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = false; +#endif // _DEBUG + m_nNUM_LIGHTS = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bWRITEWATERFOGTODESTALPHA && m_bPIXELFOGTYPE && m_bWARPINGIN && m_bAMBIENT_LIGHT && m_bNUM_LIGHTS; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nWRITEWATERFOGTODESTALPHA ) + ( 2 * m_nPIXELFOGTYPE ) + ( 4 * m_nWARPINGIN ) + ( 8 * m_nAMBIENT_LIGHT ) + ( 16 * m_nNUM_LIGHTS ) + 0; + } +}; +#define shaderDynamicTest_vortwarp_ps20 psh_forgot_to_set_dynamic_WRITEWATERFOGTODESTALPHA + psh_forgot_to_set_dynamic_PIXELFOGTYPE + psh_forgot_to_set_dynamic_WARPINGIN + psh_forgot_to_set_dynamic_AMBIENT_LIGHT + psh_forgot_to_set_dynamic_NUM_LIGHTS + 0 diff --git a/materialsystem/stdshaders/fxctmp9/vortwarp_ps20b.inc b/materialsystem/stdshaders/fxctmp9/vortwarp_ps20b.inc new file mode 100644 index 0000000..1e79f66 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/vortwarp_ps20b.inc @@ -0,0 +1,362 @@ +#include "shaderlib/cshader.h" +class vortwarp_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +private: + int m_nBASETEXTURE; +#ifdef _DEBUG + bool m_bBASETEXTURE; +#endif +public: + void SetBASETEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBASETEXTURE = i; +#ifdef _DEBUG + m_bBASETEXTURE = true; +#endif + } + void SetBASETEXTURE( bool i ) + { + m_nBASETEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bBASETEXTURE = true; +#endif + } +private: + int m_nCUBEMAP; +#ifdef _DEBUG + bool m_bCUBEMAP; +#endif +public: + void SetCUBEMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCUBEMAP = i; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } + void SetCUBEMAP( bool i ) + { + m_nCUBEMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } +private: + int m_nDIFFUSELIGHTING; +#ifdef _DEBUG + bool m_bDIFFUSELIGHTING; +#endif +public: + void SetDIFFUSELIGHTING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDIFFUSELIGHTING = i; +#ifdef _DEBUG + m_bDIFFUSELIGHTING = true; +#endif + } + void SetDIFFUSELIGHTING( bool i ) + { + m_nDIFFUSELIGHTING = i ? 1 : 0; +#ifdef _DEBUG + m_bDIFFUSELIGHTING = true; +#endif + } +private: + int m_nNORMALMAPALPHAENVMAPMASK; +#ifdef _DEBUG + bool m_bNORMALMAPALPHAENVMAPMASK; +#endif +public: + void SetNORMALMAPALPHAENVMAPMASK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nNORMALMAPALPHAENVMAPMASK = i; +#ifdef _DEBUG + m_bNORMALMAPALPHAENVMAPMASK = true; +#endif + } + void SetNORMALMAPALPHAENVMAPMASK( bool i ) + { + m_nNORMALMAPALPHAENVMAPMASK = i ? 1 : 0; +#ifdef _DEBUG + m_bNORMALMAPALPHAENVMAPMASK = true; +#endif + } +private: + int m_nHALFLAMBERT; +#ifdef _DEBUG + bool m_bHALFLAMBERT; +#endif +public: + void SetHALFLAMBERT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHALFLAMBERT = i; +#ifdef _DEBUG + m_bHALFLAMBERT = true; +#endif + } + void SetHALFLAMBERT( bool i ) + { + m_nHALFLAMBERT = i ? 1 : 0; +#ifdef _DEBUG + m_bHALFLAMBERT = true; +#endif + } +private: + int m_nFLASHLIGHT; +#ifdef _DEBUG + bool m_bFLASHLIGHT; +#endif +public: + void SetFLASHLIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFLASHLIGHT = i; +#ifdef _DEBUG + m_bFLASHLIGHT = true; +#endif + } + void SetFLASHLIGHT( bool i ) + { + m_nFLASHLIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bFLASHLIGHT = true; +#endif + } +private: + int m_nTRANSLUCENT; +#ifdef _DEBUG + bool m_bTRANSLUCENT; +#endif +public: + void SetTRANSLUCENT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nTRANSLUCENT = i; +#ifdef _DEBUG + m_bTRANSLUCENT = true; +#endif + } + void SetTRANSLUCENT( bool i ) + { + m_nTRANSLUCENT = i ? 1 : 0; +#ifdef _DEBUG + m_bTRANSLUCENT = true; +#endif + } +public: + vortwarp_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); +#ifdef _DEBUG + m_bBASETEXTURE = false; +#endif // _DEBUG + m_nBASETEXTURE = 0; +#ifdef _DEBUG + m_bCUBEMAP = false; +#endif // _DEBUG + m_nCUBEMAP = 0; +#ifdef _DEBUG + m_bDIFFUSELIGHTING = false; +#endif // _DEBUG + m_nDIFFUSELIGHTING = 0; +#ifdef _DEBUG + m_bNORMALMAPALPHAENVMAPMASK = false; +#endif // _DEBUG + m_nNORMALMAPALPHAENVMAPMASK = 0; +#ifdef _DEBUG + m_bHALFLAMBERT = false; +#endif // _DEBUG + m_nHALFLAMBERT = 0; +#ifdef _DEBUG + m_bFLASHLIGHT = false; +#endif // _DEBUG + m_nFLASHLIGHT = 0; +#ifdef _DEBUG + m_bTRANSLUCENT = false; +#endif // _DEBUG + m_nTRANSLUCENT = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB && m_bBASETEXTURE && m_bCUBEMAP && m_bDIFFUSELIGHTING && m_bNORMALMAPALPHAENVMAPMASK && m_bHALFLAMBERT && m_bFLASHLIGHT && m_bTRANSLUCENT; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 80 * m_nCONVERT_TO_SRGB ) + ( 160 * m_nBASETEXTURE ) + ( 320 * m_nCUBEMAP ) + ( 640 * m_nDIFFUSELIGHTING ) + ( 1280 * m_nNORMALMAPALPHAENVMAPMASK ) + ( 2560 * m_nHALFLAMBERT ) + ( 5120 * m_nFLASHLIGHT ) + ( 10240 * m_nTRANSLUCENT ) + 0; + } +}; +#define shaderStaticTest_vortwarp_ps20b psh_forgot_to_set_static_BASETEXTURE + psh_forgot_to_set_static_CUBEMAP + psh_forgot_to_set_static_DIFFUSELIGHTING + psh_forgot_to_set_static_NORMALMAPALPHAENVMAPMASK + psh_forgot_to_set_static_HALFLAMBERT + psh_forgot_to_set_static_FLASHLIGHT + psh_forgot_to_set_static_TRANSLUCENT + 0 +class vortwarp_ps20b_Dynamic_Index +{ +private: + int m_nWRITEWATERFOGTODESTALPHA; +#ifdef _DEBUG + bool m_bWRITEWATERFOGTODESTALPHA; +#endif +public: + void SetWRITEWATERFOGTODESTALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nWRITEWATERFOGTODESTALPHA = i; +#ifdef _DEBUG + m_bWRITEWATERFOGTODESTALPHA = true; +#endif + } + void SetWRITEWATERFOGTODESTALPHA( bool i ) + { + m_nWRITEWATERFOGTODESTALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bWRITEWATERFOGTODESTALPHA = true; +#endif + } +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +private: + int m_nWARPINGIN; +#ifdef _DEBUG + bool m_bWARPINGIN; +#endif +public: + void SetWARPINGIN( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nWARPINGIN = i; +#ifdef _DEBUG + m_bWARPINGIN = true; +#endif + } + void SetWARPINGIN( bool i ) + { + m_nWARPINGIN = i ? 1 : 0; +#ifdef _DEBUG + m_bWARPINGIN = true; +#endif + } +private: + int m_nAMBIENT_LIGHT; +#ifdef _DEBUG + bool m_bAMBIENT_LIGHT; +#endif +public: + void SetAMBIENT_LIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nAMBIENT_LIGHT = i; +#ifdef _DEBUG + m_bAMBIENT_LIGHT = true; +#endif + } + void SetAMBIENT_LIGHT( bool i ) + { + m_nAMBIENT_LIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bAMBIENT_LIGHT = true; +#endif + } +private: + int m_nNUM_LIGHTS; +#ifdef _DEBUG + bool m_bNUM_LIGHTS; +#endif +public: + void SetNUM_LIGHTS( int i ) + { + Assert( i >= 0 && i <= 4 ); + m_nNUM_LIGHTS = i; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } + void SetNUM_LIGHTS( bool i ) + { + m_nNUM_LIGHTS = i ? 1 : 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } +public: + vortwarp_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bWRITEWATERFOGTODESTALPHA = false; +#endif // _DEBUG + m_nWRITEWATERFOGTODESTALPHA = 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; +#ifdef _DEBUG + m_bWARPINGIN = false; +#endif // _DEBUG + m_nWARPINGIN = 0; +#ifdef _DEBUG + m_bAMBIENT_LIGHT = false; +#endif // _DEBUG + m_nAMBIENT_LIGHT = 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = false; +#endif // _DEBUG + m_nNUM_LIGHTS = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bWRITEWATERFOGTODESTALPHA && m_bPIXELFOGTYPE && m_bWARPINGIN && m_bAMBIENT_LIGHT && m_bNUM_LIGHTS; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nWRITEWATERFOGTODESTALPHA ) + ( 2 * m_nPIXELFOGTYPE ) + ( 4 * m_nWARPINGIN ) + ( 8 * m_nAMBIENT_LIGHT ) + ( 16 * m_nNUM_LIGHTS ) + 0; + } +}; +#define shaderDynamicTest_vortwarp_ps20b psh_forgot_to_set_dynamic_WRITEWATERFOGTODESTALPHA + psh_forgot_to_set_dynamic_PIXELFOGTYPE + psh_forgot_to_set_dynamic_WARPINGIN + psh_forgot_to_set_dynamic_AMBIENT_LIGHT + psh_forgot_to_set_dynamic_NUM_LIGHTS + 0 diff --git a/materialsystem/stdshaders/fxctmp9/vortwarp_ps30.inc b/materialsystem/stdshaders/fxctmp9/vortwarp_ps30.inc new file mode 100644 index 0000000..df00fc6 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/vortwarp_ps30.inc @@ -0,0 +1,362 @@ +#include "shaderlib/cshader.h" +class vortwarp_ps30_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +private: + int m_nBASETEXTURE; +#ifdef _DEBUG + bool m_bBASETEXTURE; +#endif +public: + void SetBASETEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBASETEXTURE = i; +#ifdef _DEBUG + m_bBASETEXTURE = true; +#endif + } + void SetBASETEXTURE( bool i ) + { + m_nBASETEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bBASETEXTURE = true; +#endif + } +private: + int m_nCUBEMAP; +#ifdef _DEBUG + bool m_bCUBEMAP; +#endif +public: + void SetCUBEMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCUBEMAP = i; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } + void SetCUBEMAP( bool i ) + { + m_nCUBEMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } +private: + int m_nDIFFUSELIGHTING; +#ifdef _DEBUG + bool m_bDIFFUSELIGHTING; +#endif +public: + void SetDIFFUSELIGHTING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDIFFUSELIGHTING = i; +#ifdef _DEBUG + m_bDIFFUSELIGHTING = true; +#endif + } + void SetDIFFUSELIGHTING( bool i ) + { + m_nDIFFUSELIGHTING = i ? 1 : 0; +#ifdef _DEBUG + m_bDIFFUSELIGHTING = true; +#endif + } +private: + int m_nNORMALMAPALPHAENVMAPMASK; +#ifdef _DEBUG + bool m_bNORMALMAPALPHAENVMAPMASK; +#endif +public: + void SetNORMALMAPALPHAENVMAPMASK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nNORMALMAPALPHAENVMAPMASK = i; +#ifdef _DEBUG + m_bNORMALMAPALPHAENVMAPMASK = true; +#endif + } + void SetNORMALMAPALPHAENVMAPMASK( bool i ) + { + m_nNORMALMAPALPHAENVMAPMASK = i ? 1 : 0; +#ifdef _DEBUG + m_bNORMALMAPALPHAENVMAPMASK = true; +#endif + } +private: + int m_nHALFLAMBERT; +#ifdef _DEBUG + bool m_bHALFLAMBERT; +#endif +public: + void SetHALFLAMBERT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHALFLAMBERT = i; +#ifdef _DEBUG + m_bHALFLAMBERT = true; +#endif + } + void SetHALFLAMBERT( bool i ) + { + m_nHALFLAMBERT = i ? 1 : 0; +#ifdef _DEBUG + m_bHALFLAMBERT = true; +#endif + } +private: + int m_nFLASHLIGHT; +#ifdef _DEBUG + bool m_bFLASHLIGHT; +#endif +public: + void SetFLASHLIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFLASHLIGHT = i; +#ifdef _DEBUG + m_bFLASHLIGHT = true; +#endif + } + void SetFLASHLIGHT( bool i ) + { + m_nFLASHLIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bFLASHLIGHT = true; +#endif + } +private: + int m_nTRANSLUCENT; +#ifdef _DEBUG + bool m_bTRANSLUCENT; +#endif +public: + void SetTRANSLUCENT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nTRANSLUCENT = i; +#ifdef _DEBUG + m_bTRANSLUCENT = true; +#endif + } + void SetTRANSLUCENT( bool i ) + { + m_nTRANSLUCENT = i ? 1 : 0; +#ifdef _DEBUG + m_bTRANSLUCENT = true; +#endif + } +public: + vortwarp_ps30_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); +#ifdef _DEBUG + m_bBASETEXTURE = false; +#endif // _DEBUG + m_nBASETEXTURE = 0; +#ifdef _DEBUG + m_bCUBEMAP = false; +#endif // _DEBUG + m_nCUBEMAP = 0; +#ifdef _DEBUG + m_bDIFFUSELIGHTING = false; +#endif // _DEBUG + m_nDIFFUSELIGHTING = 0; +#ifdef _DEBUG + m_bNORMALMAPALPHAENVMAPMASK = false; +#endif // _DEBUG + m_nNORMALMAPALPHAENVMAPMASK = 0; +#ifdef _DEBUG + m_bHALFLAMBERT = false; +#endif // _DEBUG + m_nHALFLAMBERT = 0; +#ifdef _DEBUG + m_bFLASHLIGHT = false; +#endif // _DEBUG + m_nFLASHLIGHT = 0; +#ifdef _DEBUG + m_bTRANSLUCENT = false; +#endif // _DEBUG + m_nTRANSLUCENT = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB && m_bBASETEXTURE && m_bCUBEMAP && m_bDIFFUSELIGHTING && m_bNORMALMAPALPHAENVMAPMASK && m_bHALFLAMBERT && m_bFLASHLIGHT && m_bTRANSLUCENT; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 80 * m_nCONVERT_TO_SRGB ) + ( 160 * m_nBASETEXTURE ) + ( 320 * m_nCUBEMAP ) + ( 640 * m_nDIFFUSELIGHTING ) + ( 1280 * m_nNORMALMAPALPHAENVMAPMASK ) + ( 2560 * m_nHALFLAMBERT ) + ( 5120 * m_nFLASHLIGHT ) + ( 10240 * m_nTRANSLUCENT ) + 0; + } +}; +#define shaderStaticTest_vortwarp_ps30 psh_forgot_to_set_static_BASETEXTURE + psh_forgot_to_set_static_CUBEMAP + psh_forgot_to_set_static_DIFFUSELIGHTING + psh_forgot_to_set_static_NORMALMAPALPHAENVMAPMASK + psh_forgot_to_set_static_HALFLAMBERT + psh_forgot_to_set_static_FLASHLIGHT + psh_forgot_to_set_static_TRANSLUCENT + 0 +class vortwarp_ps30_Dynamic_Index +{ +private: + int m_nWRITEWATERFOGTODESTALPHA; +#ifdef _DEBUG + bool m_bWRITEWATERFOGTODESTALPHA; +#endif +public: + void SetWRITEWATERFOGTODESTALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nWRITEWATERFOGTODESTALPHA = i; +#ifdef _DEBUG + m_bWRITEWATERFOGTODESTALPHA = true; +#endif + } + void SetWRITEWATERFOGTODESTALPHA( bool i ) + { + m_nWRITEWATERFOGTODESTALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bWRITEWATERFOGTODESTALPHA = true; +#endif + } +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +private: + int m_nWARPINGIN; +#ifdef _DEBUG + bool m_bWARPINGIN; +#endif +public: + void SetWARPINGIN( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nWARPINGIN = i; +#ifdef _DEBUG + m_bWARPINGIN = true; +#endif + } + void SetWARPINGIN( bool i ) + { + m_nWARPINGIN = i ? 1 : 0; +#ifdef _DEBUG + m_bWARPINGIN = true; +#endif + } +private: + int m_nAMBIENT_LIGHT; +#ifdef _DEBUG + bool m_bAMBIENT_LIGHT; +#endif +public: + void SetAMBIENT_LIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nAMBIENT_LIGHT = i; +#ifdef _DEBUG + m_bAMBIENT_LIGHT = true; +#endif + } + void SetAMBIENT_LIGHT( bool i ) + { + m_nAMBIENT_LIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bAMBIENT_LIGHT = true; +#endif + } +private: + int m_nNUM_LIGHTS; +#ifdef _DEBUG + bool m_bNUM_LIGHTS; +#endif +public: + void SetNUM_LIGHTS( int i ) + { + Assert( i >= 0 && i <= 4 ); + m_nNUM_LIGHTS = i; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } + void SetNUM_LIGHTS( bool i ) + { + m_nNUM_LIGHTS = i ? 1 : 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } +public: + vortwarp_ps30_Dynamic_Index() + { +#ifdef _DEBUG + m_bWRITEWATERFOGTODESTALPHA = false; +#endif // _DEBUG + m_nWRITEWATERFOGTODESTALPHA = 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; +#ifdef _DEBUG + m_bWARPINGIN = false; +#endif // _DEBUG + m_nWARPINGIN = 0; +#ifdef _DEBUG + m_bAMBIENT_LIGHT = false; +#endif // _DEBUG + m_nAMBIENT_LIGHT = 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = false; +#endif // _DEBUG + m_nNUM_LIGHTS = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bWRITEWATERFOGTODESTALPHA && m_bPIXELFOGTYPE && m_bWARPINGIN && m_bAMBIENT_LIGHT && m_bNUM_LIGHTS; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nWRITEWATERFOGTODESTALPHA ) + ( 2 * m_nPIXELFOGTYPE ) + ( 4 * m_nWARPINGIN ) + ( 8 * m_nAMBIENT_LIGHT ) + ( 16 * m_nNUM_LIGHTS ) + 0; + } +}; +#define shaderDynamicTest_vortwarp_ps30 psh_forgot_to_set_dynamic_WRITEWATERFOGTODESTALPHA + psh_forgot_to_set_dynamic_PIXELFOGTYPE + psh_forgot_to_set_dynamic_WARPINGIN + psh_forgot_to_set_dynamic_AMBIENT_LIGHT + psh_forgot_to_set_dynamic_NUM_LIGHTS + 0 diff --git a/materialsystem/stdshaders/fxctmp9/vortwarp_vs20.inc b/materialsystem/stdshaders/fxctmp9/vortwarp_vs20.inc new file mode 100644 index 0000000..1c45cab --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/vortwarp_vs20.inc @@ -0,0 +1,187 @@ +#include "shaderlib/cshader.h" +class vortwarp_vs20_Static_Index +{ +private: + int m_nHALFLAMBERT; +#ifdef _DEBUG + bool m_bHALFLAMBERT; +#endif +public: + void SetHALFLAMBERT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHALFLAMBERT = i; +#ifdef _DEBUG + m_bHALFLAMBERT = true; +#endif + } + void SetHALFLAMBERT( bool i ) + { + m_nHALFLAMBERT = i ? 1 : 0; +#ifdef _DEBUG + m_bHALFLAMBERT = true; +#endif + } +private: + int m_nUSE_STATIC_CONTROL_FLOW; +#ifdef _DEBUG + bool m_bUSE_STATIC_CONTROL_FLOW; +#endif +public: + void SetUSE_STATIC_CONTROL_FLOW( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nUSE_STATIC_CONTROL_FLOW = i; +#ifdef _DEBUG + m_bUSE_STATIC_CONTROL_FLOW = true; +#endif + } + void SetUSE_STATIC_CONTROL_FLOW( bool i ) + { + m_nUSE_STATIC_CONTROL_FLOW = i ? 1 : 0; +#ifdef _DEBUG + m_bUSE_STATIC_CONTROL_FLOW = true; +#endif + } +public: + vortwarp_vs20_Static_Index( ) + { +#ifdef _DEBUG + m_bHALFLAMBERT = false; +#endif // _DEBUG + m_nHALFLAMBERT = 0; +#ifdef _DEBUG + m_bUSE_STATIC_CONTROL_FLOW = false; +#endif // _DEBUG + m_nUSE_STATIC_CONTROL_FLOW = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bHALFLAMBERT && m_bUSE_STATIC_CONTROL_FLOW; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 24 * m_nHALFLAMBERT ) + ( 48 * m_nUSE_STATIC_CONTROL_FLOW ) + 0; + } +}; +#define shaderStaticTest_vortwarp_vs20 vsh_forgot_to_set_static_HALFLAMBERT + vsh_forgot_to_set_static_USE_STATIC_CONTROL_FLOW + 0 +class vortwarp_vs20_Dynamic_Index +{ +private: + int m_nCOMPRESSED_VERTS; +#ifdef _DEBUG + bool m_bCOMPRESSED_VERTS; +#endif +public: + void SetCOMPRESSED_VERTS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOMPRESSED_VERTS = i; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } + void SetCOMPRESSED_VERTS( bool i ) + { + m_nCOMPRESSED_VERTS = i ? 1 : 0; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +private: + int m_nNUM_LIGHTS; +#ifdef _DEBUG + bool m_bNUM_LIGHTS; +#endif +public: + void SetNUM_LIGHTS( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nNUM_LIGHTS = i; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } + void SetNUM_LIGHTS( bool i ) + { + m_nNUM_LIGHTS = i ? 1 : 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } +public: + vortwarp_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = false; +#endif // _DEBUG + m_nCOMPRESSED_VERTS = 0; +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = false; +#endif // _DEBUG + m_nNUM_LIGHTS = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bCOMPRESSED_VERTS && m_bDOWATERFOG && m_bSKINNING && m_bNUM_LIGHTS; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCOMPRESSED_VERTS ) + ( 2 * m_nDOWATERFOG ) + ( 4 * m_nSKINNING ) + ( 8 * m_nNUM_LIGHTS ) + 0; + } +}; +#define shaderDynamicTest_vortwarp_vs20 vsh_forgot_to_set_dynamic_COMPRESSED_VERTS + vsh_forgot_to_set_dynamic_DOWATERFOG + vsh_forgot_to_set_dynamic_SKINNING + vsh_forgot_to_set_dynamic_NUM_LIGHTS + 0 diff --git a/materialsystem/stdshaders/fxctmp9/vortwarp_vs30.inc b/materialsystem/stdshaders/fxctmp9/vortwarp_vs30.inc new file mode 100644 index 0000000..c92406a --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/vortwarp_vs30.inc @@ -0,0 +1,162 @@ +#include "shaderlib/cshader.h" +class vortwarp_vs30_Static_Index +{ +private: + int m_nHALFLAMBERT; +#ifdef _DEBUG + bool m_bHALFLAMBERT; +#endif +public: + void SetHALFLAMBERT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHALFLAMBERT = i; +#ifdef _DEBUG + m_bHALFLAMBERT = true; +#endif + } + void SetHALFLAMBERT( bool i ) + { + m_nHALFLAMBERT = i ? 1 : 0; +#ifdef _DEBUG + m_bHALFLAMBERT = true; +#endif + } +public: + vortwarp_vs30_Static_Index( ) + { +#ifdef _DEBUG + m_bHALFLAMBERT = false; +#endif // _DEBUG + m_nHALFLAMBERT = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bHALFLAMBERT; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 16 * m_nHALFLAMBERT ) + 0; + } +}; +#define shaderStaticTest_vortwarp_vs30 vsh_forgot_to_set_static_HALFLAMBERT + 0 +class vortwarp_vs30_Dynamic_Index +{ +private: + int m_nCOMPRESSED_VERTS; +#ifdef _DEBUG + bool m_bCOMPRESSED_VERTS; +#endif +public: + void SetCOMPRESSED_VERTS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOMPRESSED_VERTS = i; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } + void SetCOMPRESSED_VERTS( bool i ) + { + m_nCOMPRESSED_VERTS = i ? 1 : 0; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +private: + int m_nMORPHING; +#ifdef _DEBUG + bool m_bMORPHING; +#endif +public: + void SetMORPHING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nMORPHING = i; +#ifdef _DEBUG + m_bMORPHING = true; +#endif + } + void SetMORPHING( bool i ) + { + m_nMORPHING = i ? 1 : 0; +#ifdef _DEBUG + m_bMORPHING = true; +#endif + } +public: + vortwarp_vs30_Dynamic_Index() + { +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = false; +#endif // _DEBUG + m_nCOMPRESSED_VERTS = 0; +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; +#ifdef _DEBUG + m_bMORPHING = false; +#endif // _DEBUG + m_nMORPHING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bCOMPRESSED_VERTS && m_bDOWATERFOG && m_bSKINNING && m_bMORPHING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCOMPRESSED_VERTS ) + ( 2 * m_nDOWATERFOG ) + ( 4 * m_nSKINNING ) + ( 8 * m_nMORPHING ) + 0; + } +}; +#define shaderDynamicTest_vortwarp_vs30 vsh_forgot_to_set_dynamic_COMPRESSED_VERTS + vsh_forgot_to_set_dynamic_DOWATERFOG + vsh_forgot_to_set_dynamic_SKINNING + vsh_forgot_to_set_dynamic_MORPHING + 0 diff --git a/materialsystem/stdshaders/fxctmp9/vr_distort_hud_ps20.inc b/materialsystem/stdshaders/fxctmp9/vr_distort_hud_ps20.inc new file mode 100644 index 0000000..5447055 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/vr_distort_hud_ps20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class vr_distort_hud_ps20_Static_Index +{ +public: + vr_distort_hud_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_vr_distort_hud_ps20 0 +class vr_distort_hud_ps20_Dynamic_Index +{ +private: + int m_nCMBO_HUDUNDISTORT; +#ifdef _DEBUG + bool m_bCMBO_HUDUNDISTORT; +#endif +public: + void SetCMBO_HUDUNDISTORT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCMBO_HUDUNDISTORT = i; +#ifdef _DEBUG + m_bCMBO_HUDUNDISTORT = true; +#endif + } + void SetCMBO_HUDUNDISTORT( bool i ) + { + m_nCMBO_HUDUNDISTORT = i ? 1 : 0; +#ifdef _DEBUG + m_bCMBO_HUDUNDISTORT = true; +#endif + } +public: + vr_distort_hud_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bCMBO_HUDUNDISTORT = false; +#endif // _DEBUG + m_nCMBO_HUDUNDISTORT = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bCMBO_HUDUNDISTORT; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCMBO_HUDUNDISTORT ) + 0; + } +}; +#define shaderDynamicTest_vr_distort_hud_ps20 psh_forgot_to_set_dynamic_CMBO_HUDUNDISTORT + 0 diff --git a/materialsystem/stdshaders/fxctmp9/vr_distort_hud_ps20b.inc b/materialsystem/stdshaders/fxctmp9/vr_distort_hud_ps20b.inc new file mode 100644 index 0000000..639a8c0 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/vr_distort_hud_ps20b.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class vr_distort_hud_ps20b_Static_Index +{ +public: + vr_distort_hud_ps20b_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_vr_distort_hud_ps20b 0 +class vr_distort_hud_ps20b_Dynamic_Index +{ +private: + int m_nCMBO_HUDUNDISTORT; +#ifdef _DEBUG + bool m_bCMBO_HUDUNDISTORT; +#endif +public: + void SetCMBO_HUDUNDISTORT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCMBO_HUDUNDISTORT = i; +#ifdef _DEBUG + m_bCMBO_HUDUNDISTORT = true; +#endif + } + void SetCMBO_HUDUNDISTORT( bool i ) + { + m_nCMBO_HUDUNDISTORT = i ? 1 : 0; +#ifdef _DEBUG + m_bCMBO_HUDUNDISTORT = true; +#endif + } +public: + vr_distort_hud_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bCMBO_HUDUNDISTORT = false; +#endif // _DEBUG + m_nCMBO_HUDUNDISTORT = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bCMBO_HUDUNDISTORT; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCMBO_HUDUNDISTORT ) + 0; + } +}; +#define shaderDynamicTest_vr_distort_hud_ps20b psh_forgot_to_set_dynamic_CMBO_HUDUNDISTORT + 0 diff --git a/materialsystem/stdshaders/fxctmp9/vr_distort_hud_ps30.inc b/materialsystem/stdshaders/fxctmp9/vr_distort_hud_ps30.inc new file mode 100644 index 0000000..6e20058 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/vr_distort_hud_ps30.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class vr_distort_hud_ps30_Static_Index +{ +public: + vr_distort_hud_ps30_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_vr_distort_hud_ps30 0 +class vr_distort_hud_ps30_Dynamic_Index +{ +private: + int m_nCMBO_HUDUNDISTORT; +#ifdef _DEBUG + bool m_bCMBO_HUDUNDISTORT; +#endif +public: + void SetCMBO_HUDUNDISTORT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCMBO_HUDUNDISTORT = i; +#ifdef _DEBUG + m_bCMBO_HUDUNDISTORT = true; +#endif + } + void SetCMBO_HUDUNDISTORT( bool i ) + { + m_nCMBO_HUDUNDISTORT = i ? 1 : 0; +#ifdef _DEBUG + m_bCMBO_HUDUNDISTORT = true; +#endif + } +public: + vr_distort_hud_ps30_Dynamic_Index() + { +#ifdef _DEBUG + m_bCMBO_HUDUNDISTORT = false; +#endif // _DEBUG + m_nCMBO_HUDUNDISTORT = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bCMBO_HUDUNDISTORT; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCMBO_HUDUNDISTORT ) + 0; + } +}; +#define shaderDynamicTest_vr_distort_hud_ps30 psh_forgot_to_set_dynamic_CMBO_HUDUNDISTORT + 0 diff --git a/materialsystem/stdshaders/fxctmp9/vr_distort_hud_vs20.inc b/materialsystem/stdshaders/fxctmp9/vr_distort_hud_vs20.inc new file mode 100644 index 0000000..d448ab0 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/vr_distort_hud_vs20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class vr_distort_hud_vs20_Static_Index +{ +public: + vr_distort_hud_vs20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_vr_distort_hud_vs20 0 +class vr_distort_hud_vs20_Dynamic_Index +{ +public: + vr_distort_hud_vs20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_vr_distort_hud_vs20 0 diff --git a/materialsystem/stdshaders/fxctmp9/vr_distort_hud_vs30.inc b/materialsystem/stdshaders/fxctmp9/vr_distort_hud_vs30.inc new file mode 100644 index 0000000..b2e5944 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/vr_distort_hud_vs30.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class vr_distort_hud_vs30_Static_Index +{ +public: + vr_distort_hud_vs30_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_vr_distort_hud_vs30 0 +class vr_distort_hud_vs30_Dynamic_Index +{ +public: + vr_distort_hud_vs30_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_vr_distort_hud_vs30 0 diff --git a/materialsystem/stdshaders/fxctmp9/vr_distort_texture_ps20.inc b/materialsystem/stdshaders/fxctmp9/vr_distort_texture_ps20.inc new file mode 100644 index 0000000..4cf0dee --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/vr_distort_texture_ps20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class vr_distort_texture_ps20_Static_Index +{ +public: + vr_distort_texture_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_vr_distort_texture_ps20 0 +class vr_distort_texture_ps20_Dynamic_Index +{ +private: + int m_nCMBO_USERENDERTARGET; +#ifdef _DEBUG + bool m_bCMBO_USERENDERTARGET; +#endif +public: + void SetCMBO_USERENDERTARGET( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCMBO_USERENDERTARGET = i; +#ifdef _DEBUG + m_bCMBO_USERENDERTARGET = true; +#endif + } + void SetCMBO_USERENDERTARGET( bool i ) + { + m_nCMBO_USERENDERTARGET = i ? 1 : 0; +#ifdef _DEBUG + m_bCMBO_USERENDERTARGET = true; +#endif + } +public: + vr_distort_texture_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bCMBO_USERENDERTARGET = false; +#endif // _DEBUG + m_nCMBO_USERENDERTARGET = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bCMBO_USERENDERTARGET; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCMBO_USERENDERTARGET ) + 0; + } +}; +#define shaderDynamicTest_vr_distort_texture_ps20 psh_forgot_to_set_dynamic_CMBO_USERENDERTARGET + 0 diff --git a/materialsystem/stdshaders/fxctmp9/vr_distort_texture_ps20b.inc b/materialsystem/stdshaders/fxctmp9/vr_distort_texture_ps20b.inc new file mode 100644 index 0000000..fb658aa --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/vr_distort_texture_ps20b.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class vr_distort_texture_ps20b_Static_Index +{ +public: + vr_distort_texture_ps20b_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_vr_distort_texture_ps20b 0 +class vr_distort_texture_ps20b_Dynamic_Index +{ +private: + int m_nCMBO_USERENDERTARGET; +#ifdef _DEBUG + bool m_bCMBO_USERENDERTARGET; +#endif +public: + void SetCMBO_USERENDERTARGET( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCMBO_USERENDERTARGET = i; +#ifdef _DEBUG + m_bCMBO_USERENDERTARGET = true; +#endif + } + void SetCMBO_USERENDERTARGET( bool i ) + { + m_nCMBO_USERENDERTARGET = i ? 1 : 0; +#ifdef _DEBUG + m_bCMBO_USERENDERTARGET = true; +#endif + } +public: + vr_distort_texture_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bCMBO_USERENDERTARGET = false; +#endif // _DEBUG + m_nCMBO_USERENDERTARGET = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bCMBO_USERENDERTARGET; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCMBO_USERENDERTARGET ) + 0; + } +}; +#define shaderDynamicTest_vr_distort_texture_ps20b psh_forgot_to_set_dynamic_CMBO_USERENDERTARGET + 0 diff --git a/materialsystem/stdshaders/fxctmp9/vr_distort_texture_ps30.inc b/materialsystem/stdshaders/fxctmp9/vr_distort_texture_ps30.inc new file mode 100644 index 0000000..587b51c --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/vr_distort_texture_ps30.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class vr_distort_texture_ps30_Static_Index +{ +public: + vr_distort_texture_ps30_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_vr_distort_texture_ps30 0 +class vr_distort_texture_ps30_Dynamic_Index +{ +private: + int m_nCMBO_USERENDERTARGET; +#ifdef _DEBUG + bool m_bCMBO_USERENDERTARGET; +#endif +public: + void SetCMBO_USERENDERTARGET( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCMBO_USERENDERTARGET = i; +#ifdef _DEBUG + m_bCMBO_USERENDERTARGET = true; +#endif + } + void SetCMBO_USERENDERTARGET( bool i ) + { + m_nCMBO_USERENDERTARGET = i ? 1 : 0; +#ifdef _DEBUG + m_bCMBO_USERENDERTARGET = true; +#endif + } +public: + vr_distort_texture_ps30_Dynamic_Index() + { +#ifdef _DEBUG + m_bCMBO_USERENDERTARGET = false; +#endif // _DEBUG + m_nCMBO_USERENDERTARGET = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bCMBO_USERENDERTARGET; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCMBO_USERENDERTARGET ) + 0; + } +}; +#define shaderDynamicTest_vr_distort_texture_ps30 psh_forgot_to_set_dynamic_CMBO_USERENDERTARGET + 0 diff --git a/materialsystem/stdshaders/fxctmp9/vr_distort_texture_vs20.inc b/materialsystem/stdshaders/fxctmp9/vr_distort_texture_vs20.inc new file mode 100644 index 0000000..270150a --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/vr_distort_texture_vs20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class vr_distort_texture_vs20_Static_Index +{ +public: + vr_distort_texture_vs20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_vr_distort_texture_vs20 0 +class vr_distort_texture_vs20_Dynamic_Index +{ +public: + vr_distort_texture_vs20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_vr_distort_texture_vs20 0 diff --git a/materialsystem/stdshaders/fxctmp9/vr_distort_texture_vs30.inc b/materialsystem/stdshaders/fxctmp9/vr_distort_texture_vs30.inc new file mode 100644 index 0000000..442f87a --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/vr_distort_texture_vs30.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class vr_distort_texture_vs30_Static_Index +{ +public: + vr_distort_texture_vs30_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_vr_distort_texture_vs30 0 +class vr_distort_texture_vs30_Dynamic_Index +{ +public: + vr_distort_texture_vs30_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_vr_distort_texture_vs30 0 diff --git a/materialsystem/stdshaders/fxctmp9/warp_ps20.inc b/materialsystem/stdshaders/fxctmp9/warp_ps20.inc new file mode 100644 index 0000000..b6dbc9c --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/warp_ps20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class warp_ps20_Static_Index +{ +public: + warp_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_warp_ps20 0 +class warp_ps20_Dynamic_Index +{ +private: + int m_nDISTORT_TYPE; +#ifdef _DEBUG + bool m_bDISTORT_TYPE; +#endif +public: + void SetDISTORT_TYPE( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nDISTORT_TYPE = i; +#ifdef _DEBUG + m_bDISTORT_TYPE = true; +#endif + } + void SetDISTORT_TYPE( bool i ) + { + m_nDISTORT_TYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bDISTORT_TYPE = true; +#endif + } +public: + warp_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bDISTORT_TYPE = false; +#endif // _DEBUG + m_nDISTORT_TYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDISTORT_TYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDISTORT_TYPE ) + 0; + } +}; +#define shaderDynamicTest_warp_ps20 psh_forgot_to_set_dynamic_DISTORT_TYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9/warp_ps20b.inc b/materialsystem/stdshaders/fxctmp9/warp_ps20b.inc new file mode 100644 index 0000000..d699f96 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/warp_ps20b.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class warp_ps20b_Static_Index +{ +public: + warp_ps20b_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_warp_ps20b 0 +class warp_ps20b_Dynamic_Index +{ +private: + int m_nDISTORT_TYPE; +#ifdef _DEBUG + bool m_bDISTORT_TYPE; +#endif +public: + void SetDISTORT_TYPE( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nDISTORT_TYPE = i; +#ifdef _DEBUG + m_bDISTORT_TYPE = true; +#endif + } + void SetDISTORT_TYPE( bool i ) + { + m_nDISTORT_TYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bDISTORT_TYPE = true; +#endif + } +public: + warp_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bDISTORT_TYPE = false; +#endif // _DEBUG + m_nDISTORT_TYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDISTORT_TYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDISTORT_TYPE ) + 0; + } +}; +#define shaderDynamicTest_warp_ps20b psh_forgot_to_set_dynamic_DISTORT_TYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9/warp_ps30.inc b/materialsystem/stdshaders/fxctmp9/warp_ps30.inc new file mode 100644 index 0000000..6c18adb --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/warp_ps30.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class warp_ps30_Static_Index +{ +public: + warp_ps30_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_warp_ps30 0 +class warp_ps30_Dynamic_Index +{ +private: + int m_nDISTORT_TYPE; +#ifdef _DEBUG + bool m_bDISTORT_TYPE; +#endif +public: + void SetDISTORT_TYPE( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nDISTORT_TYPE = i; +#ifdef _DEBUG + m_bDISTORT_TYPE = true; +#endif + } + void SetDISTORT_TYPE( bool i ) + { + m_nDISTORT_TYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bDISTORT_TYPE = true; +#endif + } +public: + warp_ps30_Dynamic_Index() + { +#ifdef _DEBUG + m_bDISTORT_TYPE = false; +#endif // _DEBUG + m_nDISTORT_TYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDISTORT_TYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDISTORT_TYPE ) + 0; + } +}; +#define shaderDynamicTest_warp_ps30 psh_forgot_to_set_dynamic_DISTORT_TYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9/warp_vs20.inc b/materialsystem/stdshaders/fxctmp9/warp_vs20.inc new file mode 100644 index 0000000..6caee99 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/warp_vs20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class warp_vs20_Static_Index +{ +public: + warp_vs20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_warp_vs20 0 +class warp_vs20_Dynamic_Index +{ +public: + warp_vs20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_warp_vs20 0 diff --git a/materialsystem/stdshaders/fxctmp9/warp_vs30.inc b/materialsystem/stdshaders/fxctmp9/warp_vs30.inc new file mode 100644 index 0000000..3a4aeda --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/warp_vs30.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class warp_vs30_Static_Index +{ +public: + warp_vs30_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_warp_vs30 0 +class warp_vs30_Dynamic_Index +{ +public: + warp_vs30_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_warp_vs30 0 diff --git a/materialsystem/stdshaders/fxctmp9/water_ps20b.inc b/materialsystem/stdshaders/fxctmp9/water_ps20b.inc new file mode 100644 index 0000000..c7f0fad --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/water_ps20b.inc @@ -0,0 +1,287 @@ +#include "shaderlib/cshader.h" +class water_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +private: + int m_nBASETEXTURE; +#ifdef _DEBUG + bool m_bBASETEXTURE; +#endif +public: + void SetBASETEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBASETEXTURE = i; +#ifdef _DEBUG + m_bBASETEXTURE = true; +#endif + } + void SetBASETEXTURE( bool i ) + { + m_nBASETEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bBASETEXTURE = true; +#endif + } +private: + int m_nMULTITEXTURE; +#ifdef _DEBUG + bool m_bMULTITEXTURE; +#endif +public: + void SetMULTITEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nMULTITEXTURE = i; +#ifdef _DEBUG + m_bMULTITEXTURE = true; +#endif + } + void SetMULTITEXTURE( bool i ) + { + m_nMULTITEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bMULTITEXTURE = true; +#endif + } +private: + int m_nREFLECT; +#ifdef _DEBUG + bool m_bREFLECT; +#endif +public: + void SetREFLECT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nREFLECT = i; +#ifdef _DEBUG + m_bREFLECT = true; +#endif + } + void SetREFLECT( bool i ) + { + m_nREFLECT = i ? 1 : 0; +#ifdef _DEBUG + m_bREFLECT = true; +#endif + } +private: + int m_nREFRACT; +#ifdef _DEBUG + bool m_bREFRACT; +#endif +public: + void SetREFRACT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nREFRACT = i; +#ifdef _DEBUG + m_bREFRACT = true; +#endif + } + void SetREFRACT( bool i ) + { + m_nREFRACT = i ? 1 : 0; +#ifdef _DEBUG + m_bREFRACT = true; +#endif + } +private: + int m_nABOVEWATER; +#ifdef _DEBUG + bool m_bABOVEWATER; +#endif +public: + void SetABOVEWATER( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nABOVEWATER = i; +#ifdef _DEBUG + m_bABOVEWATER = true; +#endif + } + void SetABOVEWATER( bool i ) + { + m_nABOVEWATER = i ? 1 : 0; +#ifdef _DEBUG + m_bABOVEWATER = true; +#endif + } +private: + int m_nBLURRY_REFRACT; +#ifdef _DEBUG + bool m_bBLURRY_REFRACT; +#endif +public: + void SetBLURRY_REFRACT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBLURRY_REFRACT = i; +#ifdef _DEBUG + m_bBLURRY_REFRACT = true; +#endif + } + void SetBLURRY_REFRACT( bool i ) + { + m_nBLURRY_REFRACT = i ? 1 : 0; +#ifdef _DEBUG + m_bBLURRY_REFRACT = true; +#endif + } +private: + int m_nNORMAL_DECODE_MODE; +#ifdef _DEBUG + bool m_bNORMAL_DECODE_MODE; +#endif +public: + void SetNORMAL_DECODE_MODE( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nNORMAL_DECODE_MODE = i; +#ifdef _DEBUG + m_bNORMAL_DECODE_MODE = true; +#endif + } + void SetNORMAL_DECODE_MODE( bool i ) + { + m_nNORMAL_DECODE_MODE = i ? 1 : 0; +#ifdef _DEBUG + m_bNORMAL_DECODE_MODE = true; +#endif + } +public: + water_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); +#ifdef _DEBUG + m_bBASETEXTURE = false; +#endif // _DEBUG + m_nBASETEXTURE = 0; +#ifdef _DEBUG + m_bMULTITEXTURE = false; +#endif // _DEBUG + m_nMULTITEXTURE = 0; +#ifdef _DEBUG + m_bREFLECT = false; +#endif // _DEBUG + m_nREFLECT = 0; +#ifdef _DEBUG + m_bREFRACT = false; +#endif // _DEBUG + m_nREFRACT = 0; +#ifdef _DEBUG + m_bABOVEWATER = false; +#endif // _DEBUG + m_nABOVEWATER = 0; +#ifdef _DEBUG + m_bBLURRY_REFRACT = false; +#endif // _DEBUG + m_nBLURRY_REFRACT = 0; +#ifdef _DEBUG + m_bNORMAL_DECODE_MODE = false; +#endif // _DEBUG + m_nNORMAL_DECODE_MODE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB && m_bBASETEXTURE && m_bMULTITEXTURE && m_bREFLECT && m_bREFRACT && m_bABOVEWATER && m_bBLURRY_REFRACT && m_bNORMAL_DECODE_MODE; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 4 * m_nCONVERT_TO_SRGB ) + ( 8 * m_nBASETEXTURE ) + ( 16 * m_nMULTITEXTURE ) + ( 32 * m_nREFLECT ) + ( 64 * m_nREFRACT ) + ( 128 * m_nABOVEWATER ) + ( 256 * m_nBLURRY_REFRACT ) + ( 512 * m_nNORMAL_DECODE_MODE ) + 0; + } +}; +#define shaderStaticTest_water_ps20b psh_forgot_to_set_static_BASETEXTURE + psh_forgot_to_set_static_MULTITEXTURE + psh_forgot_to_set_static_REFLECT + psh_forgot_to_set_static_REFRACT + psh_forgot_to_set_static_ABOVEWATER + psh_forgot_to_set_static_BLURRY_REFRACT + psh_forgot_to_set_static_NORMAL_DECODE_MODE + 0 +class water_ps20b_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +private: + int m_nWRITE_DEPTH_TO_DESTALPHA; +#ifdef _DEBUG + bool m_bWRITE_DEPTH_TO_DESTALPHA; +#endif +public: + void SetWRITE_DEPTH_TO_DESTALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nWRITE_DEPTH_TO_DESTALPHA = i; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = true; +#endif + } + void SetWRITE_DEPTH_TO_DESTALPHA( bool i ) + { + m_nWRITE_DEPTH_TO_DESTALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = true; +#endif + } +public: + water_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = false; +#endif // _DEBUG + m_nWRITE_DEPTH_TO_DESTALPHA = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE && m_bWRITE_DEPTH_TO_DESTALPHA; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + ( 2 * m_nWRITE_DEPTH_TO_DESTALPHA ) + 0; + } +}; +#define shaderDynamicTest_water_ps20b psh_forgot_to_set_dynamic_PIXELFOGTYPE + psh_forgot_to_set_dynamic_WRITE_DEPTH_TO_DESTALPHA + 0 diff --git a/materialsystem/stdshaders/fxctmp9/weapon_sheen_pass_ps20.inc b/materialsystem/stdshaders/fxctmp9/weapon_sheen_pass_ps20.inc new file mode 100644 index 0000000..cb90bc6 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/weapon_sheen_pass_ps20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class weapon_sheen_pass_ps20_Static_Index +{ +private: + int m_nBUMPMAP; +#ifdef _DEBUG + bool m_bBUMPMAP; +#endif +public: + void SetBUMPMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBUMPMAP = i; +#ifdef _DEBUG + m_bBUMPMAP = true; +#endif + } + void SetBUMPMAP( bool i ) + { + m_nBUMPMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bBUMPMAP = true; +#endif + } +public: + weapon_sheen_pass_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bBUMPMAP = false; +#endif // _DEBUG + m_nBUMPMAP = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bBUMPMAP; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nBUMPMAP ) + 0; + } +}; +#define shaderStaticTest_weapon_sheen_pass_ps20 psh_forgot_to_set_static_BUMPMAP + 0 +class weapon_sheen_pass_ps20_Dynamic_Index +{ +public: + weapon_sheen_pass_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_weapon_sheen_pass_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9/weapon_sheen_pass_ps20b.inc b/materialsystem/stdshaders/fxctmp9/weapon_sheen_pass_ps20b.inc new file mode 100644 index 0000000..9351118 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/weapon_sheen_pass_ps20b.inc @@ -0,0 +1,85 @@ +#include "shaderlib/cshader.h" +class weapon_sheen_pass_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +private: + int m_nBUMPMAP; +#ifdef _DEBUG + bool m_bBUMPMAP; +#endif +public: + void SetBUMPMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBUMPMAP = i; +#ifdef _DEBUG + m_bBUMPMAP = true; +#endif + } + void SetBUMPMAP( bool i ) + { + m_nBUMPMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bBUMPMAP = true; +#endif + } +public: + weapon_sheen_pass_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); +#ifdef _DEBUG + m_bBUMPMAP = false; +#endif // _DEBUG + m_nBUMPMAP = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB && m_bBUMPMAP; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + ( 2 * m_nBUMPMAP ) + 0; + } +}; +#define shaderStaticTest_weapon_sheen_pass_ps20b psh_forgot_to_set_static_BUMPMAP + 0 +class weapon_sheen_pass_ps20b_Dynamic_Index +{ +public: + weapon_sheen_pass_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_weapon_sheen_pass_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9/weapon_sheen_pass_ps30.inc b/materialsystem/stdshaders/fxctmp9/weapon_sheen_pass_ps30.inc new file mode 100644 index 0000000..884c90c --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/weapon_sheen_pass_ps30.inc @@ -0,0 +1,85 @@ +#include "shaderlib/cshader.h" +class weapon_sheen_pass_ps30_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +private: + int m_nBUMPMAP; +#ifdef _DEBUG + bool m_bBUMPMAP; +#endif +public: + void SetBUMPMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBUMPMAP = i; +#ifdef _DEBUG + m_bBUMPMAP = true; +#endif + } + void SetBUMPMAP( bool i ) + { + m_nBUMPMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bBUMPMAP = true; +#endif + } +public: + weapon_sheen_pass_ps30_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); +#ifdef _DEBUG + m_bBUMPMAP = false; +#endif // _DEBUG + m_nBUMPMAP = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB && m_bBUMPMAP; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + ( 2 * m_nBUMPMAP ) + 0; + } +}; +#define shaderStaticTest_weapon_sheen_pass_ps30 psh_forgot_to_set_static_BUMPMAP + 0 +class weapon_sheen_pass_ps30_Dynamic_Index +{ +public: + weapon_sheen_pass_ps30_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_weapon_sheen_pass_ps30 0 diff --git a/materialsystem/stdshaders/fxctmp9/weapon_sheen_pass_vs20.inc b/materialsystem/stdshaders/fxctmp9/weapon_sheen_pass_vs20.inc new file mode 100644 index 0000000..76106b8 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/weapon_sheen_pass_vs20.inc @@ -0,0 +1,112 @@ +#include "shaderlib/cshader.h" +class weapon_sheen_pass_vs20_Static_Index +{ +private: + int m_nBUMPMAP; +#ifdef _DEBUG + bool m_bBUMPMAP; +#endif +public: + void SetBUMPMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBUMPMAP = i; +#ifdef _DEBUG + m_bBUMPMAP = true; +#endif + } + void SetBUMPMAP( bool i ) + { + m_nBUMPMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bBUMPMAP = true; +#endif + } +public: + weapon_sheen_pass_vs20_Static_Index( ) + { +#ifdef _DEBUG + m_bBUMPMAP = false; +#endif // _DEBUG + m_nBUMPMAP = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bBUMPMAP; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 4 * m_nBUMPMAP ) + 0; + } +}; +#define shaderStaticTest_weapon_sheen_pass_vs20 vsh_forgot_to_set_static_BUMPMAP + 0 +class weapon_sheen_pass_vs20_Dynamic_Index +{ +private: + int m_nCOMPRESSED_VERTS; +#ifdef _DEBUG + bool m_bCOMPRESSED_VERTS; +#endif +public: + void SetCOMPRESSED_VERTS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOMPRESSED_VERTS = i; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } + void SetCOMPRESSED_VERTS( bool i ) + { + m_nCOMPRESSED_VERTS = i ? 1 : 0; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +public: + weapon_sheen_pass_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = false; +#endif // _DEBUG + m_nCOMPRESSED_VERTS = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bCOMPRESSED_VERTS && m_bSKINNING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCOMPRESSED_VERTS ) + ( 2 * m_nSKINNING ) + 0; + } +}; +#define shaderDynamicTest_weapon_sheen_pass_vs20 vsh_forgot_to_set_dynamic_COMPRESSED_VERTS + vsh_forgot_to_set_dynamic_SKINNING + 0 diff --git a/materialsystem/stdshaders/fxctmp9/weapon_sheen_pass_vs30.inc b/materialsystem/stdshaders/fxctmp9/weapon_sheen_pass_vs30.inc new file mode 100644 index 0000000..3620db5 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/weapon_sheen_pass_vs30.inc @@ -0,0 +1,137 @@ +#include "shaderlib/cshader.h" +class weapon_sheen_pass_vs30_Static_Index +{ +private: + int m_nBUMPMAP; +#ifdef _DEBUG + bool m_bBUMPMAP; +#endif +public: + void SetBUMPMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBUMPMAP = i; +#ifdef _DEBUG + m_bBUMPMAP = true; +#endif + } + void SetBUMPMAP( bool i ) + { + m_nBUMPMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bBUMPMAP = true; +#endif + } +public: + weapon_sheen_pass_vs30_Static_Index( ) + { +#ifdef _DEBUG + m_bBUMPMAP = false; +#endif // _DEBUG + m_nBUMPMAP = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bBUMPMAP; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 8 * m_nBUMPMAP ) + 0; + } +}; +#define shaderStaticTest_weapon_sheen_pass_vs30 vsh_forgot_to_set_static_BUMPMAP + 0 +class weapon_sheen_pass_vs30_Dynamic_Index +{ +private: + int m_nCOMPRESSED_VERTS; +#ifdef _DEBUG + bool m_bCOMPRESSED_VERTS; +#endif +public: + void SetCOMPRESSED_VERTS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOMPRESSED_VERTS = i; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } + void SetCOMPRESSED_VERTS( bool i ) + { + m_nCOMPRESSED_VERTS = i ? 1 : 0; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +private: + int m_nMORPHING; +#ifdef _DEBUG + bool m_bMORPHING; +#endif +public: + void SetMORPHING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nMORPHING = i; +#ifdef _DEBUG + m_bMORPHING = true; +#endif + } + void SetMORPHING( bool i ) + { + m_nMORPHING = i ? 1 : 0; +#ifdef _DEBUG + m_bMORPHING = true; +#endif + } +public: + weapon_sheen_pass_vs30_Dynamic_Index() + { +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = false; +#endif // _DEBUG + m_nCOMPRESSED_VERTS = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; +#ifdef _DEBUG + m_bMORPHING = false; +#endif // _DEBUG + m_nMORPHING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bCOMPRESSED_VERTS && m_bSKINNING && m_bMORPHING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCOMPRESSED_VERTS ) + ( 2 * m_nSKINNING ) + ( 4 * m_nMORPHING ) + 0; + } +}; +#define shaderDynamicTest_weapon_sheen_pass_vs30 vsh_forgot_to_set_dynamic_COMPRESSED_VERTS + vsh_forgot_to_set_dynamic_SKINNING + vsh_forgot_to_set_dynamic_MORPHING + 0 diff --git a/materialsystem/stdshaders/fxctmp9/white_ps20.inc b/materialsystem/stdshaders/fxctmp9/white_ps20.inc new file mode 100644 index 0000000..01a5578 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/white_ps20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class white_ps20_Static_Index +{ +public: + white_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_white_ps20 0 +class white_ps20_Dynamic_Index +{ +public: + white_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_white_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9/white_ps20b.inc b/materialsystem/stdshaders/fxctmp9/white_ps20b.inc new file mode 100644 index 0000000..277a68c --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/white_ps20b.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class white_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + white_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_white_ps20b 0 +class white_ps20b_Dynamic_Index +{ +public: + white_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_white_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9/windowimposter_ps11.inc b/materialsystem/stdshaders/fxctmp9/windowimposter_ps11.inc new file mode 100644 index 0000000..1e46457 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/windowimposter_ps11.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class windowimposter_ps11_Static_Index +{ +public: + windowimposter_ps11_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_windowimposter_ps11 0 +class windowimposter_ps11_Dynamic_Index +{ +public: + windowimposter_ps11_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_windowimposter_ps11 0 diff --git a/materialsystem/stdshaders/fxctmp9/windowimposter_ps20.inc b/materialsystem/stdshaders/fxctmp9/windowimposter_ps20.inc new file mode 100644 index 0000000..babed49 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/windowimposter_ps20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class windowimposter_ps20_Static_Index +{ +public: + windowimposter_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_windowimposter_ps20 0 +class windowimposter_ps20_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + windowimposter_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_windowimposter_ps20 psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9/windowimposter_ps20b.inc b/materialsystem/stdshaders/fxctmp9/windowimposter_ps20b.inc new file mode 100644 index 0000000..e8a1b46 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/windowimposter_ps20b.inc @@ -0,0 +1,87 @@ +#include "shaderlib/cshader.h" +class windowimposter_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + windowimposter_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_windowimposter_ps20b 0 +class windowimposter_ps20b_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + windowimposter_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_windowimposter_ps20b psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9/windowimposter_vs11.inc b/materialsystem/stdshaders/fxctmp9/windowimposter_vs11.inc new file mode 100644 index 0000000..0f8fe63 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/windowimposter_vs11.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class windowimposter_vs11_Static_Index +{ +public: + windowimposter_vs11_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_windowimposter_vs11 0 +class windowimposter_vs11_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + windowimposter_vs11_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; +#define shaderDynamicTest_windowimposter_vs11 vsh_forgot_to_set_dynamic_DOWATERFOG + 0 diff --git a/materialsystem/stdshaders/fxctmp9/windowimposter_vs20.inc b/materialsystem/stdshaders/fxctmp9/windowimposter_vs20.inc new file mode 100644 index 0000000..b99a21a --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/windowimposter_vs20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class windowimposter_vs20_Static_Index +{ +public: + windowimposter_vs20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_windowimposter_vs20 0 +class windowimposter_vs20_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + windowimposter_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; +#define shaderDynamicTest_windowimposter_vs20 vsh_forgot_to_set_dynamic_DOWATERFOG + 0 diff --git a/materialsystem/stdshaders/fxctmp9/worldvertexalpha_ps20.inc b/materialsystem/stdshaders/fxctmp9/worldvertexalpha_ps20.inc new file mode 100644 index 0000000..97b21d3 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/worldvertexalpha_ps20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class worldvertexalpha_ps20_Static_Index +{ +private: + int m_nPASS; +#ifdef _DEBUG + bool m_bPASS; +#endif +public: + void SetPASS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPASS = i; +#ifdef _DEBUG + m_bPASS = true; +#endif + } + void SetPASS( bool i ) + { + m_nPASS = i ? 1 : 0; +#ifdef _DEBUG + m_bPASS = true; +#endif + } +public: + worldvertexalpha_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bPASS = false; +#endif // _DEBUG + m_nPASS = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bPASS; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPASS ) + 0; + } +}; +#define shaderStaticTest_worldvertexalpha_ps20 psh_forgot_to_set_static_PASS + 0 +class worldvertexalpha_ps20_Dynamic_Index +{ +public: + worldvertexalpha_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_worldvertexalpha_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9/worldvertexalpha_ps20b.inc b/materialsystem/stdshaders/fxctmp9/worldvertexalpha_ps20b.inc new file mode 100644 index 0000000..ff9f797 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/worldvertexalpha_ps20b.inc @@ -0,0 +1,85 @@ +#include "shaderlib/cshader.h" +class worldvertexalpha_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +private: + int m_nPASS; +#ifdef _DEBUG + bool m_bPASS; +#endif +public: + void SetPASS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPASS = i; +#ifdef _DEBUG + m_bPASS = true; +#endif + } + void SetPASS( bool i ) + { + m_nPASS = i ? 1 : 0; +#ifdef _DEBUG + m_bPASS = true; +#endif + } +public: + worldvertexalpha_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = g_pHardwareConfig->NeedsShaderSRGBConversion(); +#ifdef _DEBUG + m_bPASS = false; +#endif // _DEBUG + m_nPASS = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB && m_bPASS; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + ( 2 * m_nPASS ) + 0; + } +}; +#define shaderStaticTest_worldvertexalpha_ps20b psh_forgot_to_set_static_PASS + 0 +class worldvertexalpha_ps20b_Dynamic_Index +{ +public: + worldvertexalpha_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_worldvertexalpha_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9/writevertexalphatodestalpha_ps11.inc b/materialsystem/stdshaders/fxctmp9/writevertexalphatodestalpha_ps11.inc new file mode 100644 index 0000000..8185a31 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/writevertexalphatodestalpha_ps11.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class writevertexalphatodestalpha_ps11_Static_Index +{ +public: + writevertexalphatodestalpha_ps11_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_writevertexalphatodestalpha_ps11 0 +class writevertexalphatodestalpha_ps11_Dynamic_Index +{ +public: + writevertexalphatodestalpha_ps11_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_writevertexalphatodestalpha_ps11 0 diff --git a/materialsystem/stdshaders/fxctmp9/writevertexalphatodestalpha_vs11.inc b/materialsystem/stdshaders/fxctmp9/writevertexalphatodestalpha_vs11.inc new file mode 100644 index 0000000..07f29e0 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/writevertexalphatodestalpha_vs11.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class writevertexalphatodestalpha_vs11_Static_Index +{ +public: + writevertexalphatodestalpha_vs11_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_writevertexalphatodestalpha_vs11 0 +class writevertexalphatodestalpha_vs11_Dynamic_Index +{ +public: + writevertexalphatodestalpha_vs11_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_writevertexalphatodestalpha_vs11 0 diff --git a/materialsystem/stdshaders/fxctmp9/writez_vs20.inc b/materialsystem/stdshaders/fxctmp9/writez_vs20.inc new file mode 100644 index 0000000..fd2ced2 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9/writez_vs20.inc @@ -0,0 +1,85 @@ +#include "shaderlib/cshader.h" +class writez_vs20_Static_Index +{ +public: + writez_vs20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_writez_vs20 0 +class writez_vs20_Dynamic_Index +{ +private: + int m_nCOMPRESSED_VERTS; +#ifdef _DEBUG + bool m_bCOMPRESSED_VERTS; +#endif +public: + void SetCOMPRESSED_VERTS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOMPRESSED_VERTS = i; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } + void SetCOMPRESSED_VERTS( bool i ) + { + m_nCOMPRESSED_VERTS = i ? 1 : 0; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + writez_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = false; +#endif // _DEBUG + m_nCOMPRESSED_VERTS = 0; +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bCOMPRESSED_VERTS && m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCOMPRESSED_VERTS ) + ( 2 * m_nDOWATERFOG ) + 0; + } +}; +#define shaderDynamicTest_writez_vs20 vsh_forgot_to_set_dynamic_COMPRESSED_VERTS + vsh_forgot_to_set_dynamic_DOWATERFOG + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/Bloom_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/Bloom_ps20.inc new file mode 100644 index 0000000..8952817 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/Bloom_ps20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class bloom_ps20_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + bloom_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_bloom_ps20 0 +class bloom_ps20_Dynamic_Index +{ +public: + bloom_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_bloom_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/Bloom_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/Bloom_ps20b.inc new file mode 100644 index 0000000..9207e0e --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/Bloom_ps20b.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class bloom_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + bloom_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_bloom_ps20b 0 +class bloom_ps20b_Dynamic_Index +{ +public: + bloom_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_bloom_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/BlurFilter_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/BlurFilter_ps20.inc new file mode 100644 index 0000000..455e2a8 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/BlurFilter_ps20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class blurfilter_ps20_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + blurfilter_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_blurfilter_ps20 0 +class blurfilter_ps20_Dynamic_Index +{ +public: + blurfilter_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_blurfilter_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/BlurFilter_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/BlurFilter_ps20b.inc new file mode 100644 index 0000000..79a170f --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/BlurFilter_ps20b.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class blurfilter_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + blurfilter_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_blurfilter_ps20b 0 +class blurfilter_ps20b_Dynamic_Index +{ +public: + blurfilter_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_blurfilter_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/BlurFilter_vs11.inc b/materialsystem/stdshaders/fxctmp9_360/BlurFilter_vs11.inc new file mode 100644 index 0000000..6036961 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/BlurFilter_vs11.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class blurfilter_vs11_Static_Index +{ +public: + blurfilter_vs11_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_blurfilter_vs11 0 +class blurfilter_vs11_Dynamic_Index +{ +public: + blurfilter_vs11_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_blurfilter_vs11 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/BlurFilter_vs20.inc b/materialsystem/stdshaders/fxctmp9_360/BlurFilter_vs20.inc new file mode 100644 index 0000000..933c5b7 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/BlurFilter_vs20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class blurfilter_vs20_Static_Index +{ +public: + blurfilter_vs20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_blurfilter_vs20 0 +class blurfilter_vs20_Dynamic_Index +{ +public: + blurfilter_vs20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_blurfilter_vs20 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/Downsample_nohdr_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/Downsample_nohdr_ps20.inc new file mode 100644 index 0000000..c94c738 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/Downsample_nohdr_ps20.inc @@ -0,0 +1,85 @@ +#include "shaderlib/cshader.h" +class downsample_nohdr_ps20_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +private: + int m_nCSTRIKE; +#ifdef _DEBUG + bool m_bCSTRIKE; +#endif +public: + void SetCSTRIKE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCSTRIKE = i; +#ifdef _DEBUG + m_bCSTRIKE = true; +#endif + } + void SetCSTRIKE( bool i ) + { + m_nCSTRIKE = i ? 1 : 0; +#ifdef _DEBUG + m_bCSTRIKE = true; +#endif + } +public: + downsample_nohdr_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; +#ifdef _DEBUG + m_bCSTRIKE = false; +#endif // _DEBUG + m_nCSTRIKE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB && m_bCSTRIKE; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + ( 1 * m_nCSTRIKE ) + 0; + } +}; +#define shaderStaticTest_downsample_nohdr_ps20 psh_forgot_to_set_static_CSTRIKE + 0 +class downsample_nohdr_ps20_Dynamic_Index +{ +public: + downsample_nohdr_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_downsample_nohdr_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/Downsample_nohdr_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/Downsample_nohdr_ps20b.inc new file mode 100644 index 0000000..5652158 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/Downsample_nohdr_ps20b.inc @@ -0,0 +1,85 @@ +#include "shaderlib/cshader.h" +class downsample_nohdr_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +private: + int m_nCSTRIKE; +#ifdef _DEBUG + bool m_bCSTRIKE; +#endif +public: + void SetCSTRIKE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCSTRIKE = i; +#ifdef _DEBUG + m_bCSTRIKE = true; +#endif + } + void SetCSTRIKE( bool i ) + { + m_nCSTRIKE = i ? 1 : 0; +#ifdef _DEBUG + m_bCSTRIKE = true; +#endif + } +public: + downsample_nohdr_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; +#ifdef _DEBUG + m_bCSTRIKE = false; +#endif // _DEBUG + m_nCSTRIKE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB && m_bCSTRIKE; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + ( 1 * m_nCSTRIKE ) + 0; + } +}; +#define shaderStaticTest_downsample_nohdr_ps20b psh_forgot_to_set_static_CSTRIKE + 0 +class downsample_nohdr_ps20b_Dynamic_Index +{ +public: + downsample_nohdr_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_downsample_nohdr_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/Downsample_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/Downsample_ps20.inc new file mode 100644 index 0000000..29af50a --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/Downsample_ps20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class downsample_ps20_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + downsample_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_downsample_ps20 0 +class downsample_ps20_Dynamic_Index +{ +public: + downsample_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_downsample_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/Downsample_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/Downsample_ps20b.inc new file mode 100644 index 0000000..acf71ee --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/Downsample_ps20b.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class downsample_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + downsample_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_downsample_ps20b 0 +class downsample_ps20b_Dynamic_Index +{ +public: + downsample_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_downsample_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/Downsample_vs11.inc b/materialsystem/stdshaders/fxctmp9_360/Downsample_vs11.inc new file mode 100644 index 0000000..7b7376c --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/Downsample_vs11.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class downsample_vs11_Static_Index +{ +public: + downsample_vs11_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_downsample_vs11 0 +class downsample_vs11_Dynamic_Index +{ +public: + downsample_vs11_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_downsample_vs11 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/Downsample_vs20.inc b/materialsystem/stdshaders/fxctmp9_360/Downsample_vs20.inc new file mode 100644 index 0000000..e6b4b44 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/Downsample_vs20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class downsample_vs20_Static_Index +{ +public: + downsample_vs20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_downsample_vs20 0 +class downsample_vs20_Dynamic_Index +{ +public: + downsample_vs20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_downsample_vs20 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/HDRCombineTo16Bit_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/HDRCombineTo16Bit_ps20.inc new file mode 100644 index 0000000..6fc5b38 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/HDRCombineTo16Bit_ps20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class hdrcombineto16bit_ps20_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + hdrcombineto16bit_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_hdrcombineto16bit_ps20 0 +class hdrcombineto16bit_ps20_Dynamic_Index +{ +public: + hdrcombineto16bit_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_hdrcombineto16bit_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/HDRCombineTo16Bit_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/HDRCombineTo16Bit_ps20b.inc new file mode 100644 index 0000000..bbbb8a9 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/HDRCombineTo16Bit_ps20b.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class hdrcombineto16bit_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + hdrcombineto16bit_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_hdrcombineto16bit_ps20b 0 +class hdrcombineto16bit_ps20b_Dynamic_Index +{ +public: + hdrcombineto16bit_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_hdrcombineto16bit_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/HDRCombineTo16Bit_vs20.inc b/materialsystem/stdshaders/fxctmp9_360/HDRCombineTo16Bit_vs20.inc new file mode 100644 index 0000000..ff22564 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/HDRCombineTo16Bit_vs20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class hdrcombineto16bit_vs20_Static_Index +{ +public: + hdrcombineto16bit_vs20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_hdrcombineto16bit_vs20 0 +class hdrcombineto16bit_vs20_Dynamic_Index +{ +public: + hdrcombineto16bit_vs20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_hdrcombineto16bit_vs20 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/HDRSelectRange_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/HDRSelectRange_ps20.inc new file mode 100644 index 0000000..4561783 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/HDRSelectRange_ps20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class hdrselectrange_ps20_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + hdrselectrange_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_hdrselectrange_ps20 0 +class hdrselectrange_ps20_Dynamic_Index +{ +public: + hdrselectrange_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_hdrselectrange_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/HDRSelectRange_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/HDRSelectRange_ps20b.inc new file mode 100644 index 0000000..d447a24 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/HDRSelectRange_ps20b.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class hdrselectrange_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + hdrselectrange_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_hdrselectrange_ps20b 0 +class hdrselectrange_ps20b_Dynamic_Index +{ +public: + hdrselectrange_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_hdrselectrange_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/HDRSelectRange_vs20.inc b/materialsystem/stdshaders/fxctmp9_360/HDRSelectRange_vs20.inc new file mode 100644 index 0000000..1e180e7 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/HDRSelectRange_vs20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class hdrselectrange_vs20_Static_Index +{ +public: + hdrselectrange_vs20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_hdrselectrange_vs20 0 +class hdrselectrange_vs20_Dynamic_Index +{ +public: + hdrselectrange_vs20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_hdrselectrange_vs20 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/IntroScreenSpaceEffect_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/IntroScreenSpaceEffect_ps20.inc new file mode 100644 index 0000000..9b8b506 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/IntroScreenSpaceEffect_ps20.inc @@ -0,0 +1,87 @@ +#include "shaderlib/cshader.h" +class introscreenspaceeffect_ps20_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + introscreenspaceeffect_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 10 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_introscreenspaceeffect_ps20 0 +class introscreenspaceeffect_ps20_Dynamic_Index +{ +private: + int m_nMODE; +#ifdef _DEBUG + bool m_bMODE; +#endif +public: + void SetMODE( int i ) + { + Assert( i >= 0 && i <= 9 ); + m_nMODE = i; +#ifdef _DEBUG + m_bMODE = true; +#endif + } + void SetMODE( bool i ) + { + m_nMODE = i ? 1 : 0; +#ifdef _DEBUG + m_bMODE = true; +#endif + } +public: + introscreenspaceeffect_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bMODE = false; +#endif // _DEBUG + m_nMODE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bMODE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nMODE ) + 0; + } +}; +#define shaderDynamicTest_introscreenspaceeffect_ps20 psh_forgot_to_set_dynamic_MODE + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/IntroScreenSpaceEffect_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/IntroScreenSpaceEffect_ps20b.inc new file mode 100644 index 0000000..29fa55d --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/IntroScreenSpaceEffect_ps20b.inc @@ -0,0 +1,112 @@ +#include "shaderlib/cshader.h" +class introscreenspaceeffect_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +private: + int m_nLINEAR_TO_SRGB; +#ifdef _DEBUG + bool m_bLINEAR_TO_SRGB; +#endif +public: + void SetLINEAR_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nLINEAR_TO_SRGB = i; +#ifdef _DEBUG + m_bLINEAR_TO_SRGB = true; +#endif + } + void SetLINEAR_TO_SRGB( bool i ) + { + m_nLINEAR_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bLINEAR_TO_SRGB = true; +#endif + } +public: + introscreenspaceeffect_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; +#ifdef _DEBUG + m_bLINEAR_TO_SRGB = false; +#endif // _DEBUG + m_nLINEAR_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB && m_bLINEAR_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 10 * m_nCONVERT_TO_SRGB ) + ( 10 * m_nLINEAR_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_introscreenspaceeffect_ps20b psh_forgot_to_set_static_LINEAR_TO_SRGB + 0 +class introscreenspaceeffect_ps20b_Dynamic_Index +{ +private: + int m_nMODE; +#ifdef _DEBUG + bool m_bMODE; +#endif +public: + void SetMODE( int i ) + { + Assert( i >= 0 && i <= 9 ); + m_nMODE = i; +#ifdef _DEBUG + m_bMODE = true; +#endif + } + void SetMODE( bool i ) + { + m_nMODE = i ? 1 : 0; +#ifdef _DEBUG + m_bMODE = true; +#endif + } +public: + introscreenspaceeffect_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bMODE = false; +#endif // _DEBUG + m_nMODE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bMODE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nMODE ) + 0; + } +}; +#define shaderDynamicTest_introscreenspaceeffect_ps20b psh_forgot_to_set_dynamic_MODE + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/ParticleSphere_ps11.inc b/materialsystem/stdshaders/fxctmp9_360/ParticleSphere_ps11.inc new file mode 100644 index 0000000..85a976b --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/ParticleSphere_ps11.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class particlesphere_ps11_Static_Index +{ +public: + particlesphere_ps11_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_particlesphere_ps11 0 +class particlesphere_ps11_Dynamic_Index +{ +public: + particlesphere_ps11_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_particlesphere_ps11 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/ParticleSphere_vs11.inc b/materialsystem/stdshaders/fxctmp9_360/ParticleSphere_vs11.inc new file mode 100644 index 0000000..4dcaa64 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/ParticleSphere_vs11.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class particlesphere_vs11_Static_Index +{ +public: + particlesphere_vs11_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_particlesphere_vs11 0 +class particlesphere_vs11_Dynamic_Index +{ +private: + int m_nFOGTYPE; +#ifdef _DEBUG + bool m_bFOGTYPE; +#endif +public: + void SetFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFOGTYPE = i; +#ifdef _DEBUG + m_bFOGTYPE = true; +#endif + } + void SetFOGTYPE( bool i ) + { + m_nFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bFOGTYPE = true; +#endif + } +public: + particlesphere_vs11_Dynamic_Index() + { +#ifdef _DEBUG + m_bFOGTYPE = false; +#endif // _DEBUG + m_nFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_particlesphere_vs11 vsh_forgot_to_set_dynamic_FOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/Refract_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/Refract_ps20.inc new file mode 100644 index 0000000..0fa04d9 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/Refract_ps20.inc @@ -0,0 +1,287 @@ +#include "shaderlib/cshader.h" +class refract_ps20_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +private: + int m_nBLUR; +#ifdef _DEBUG + bool m_bBLUR; +#endif +public: + void SetBLUR( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBLUR = i; +#ifdef _DEBUG + m_bBLUR = true; +#endif + } + void SetBLUR( bool i ) + { + m_nBLUR = i ? 1 : 0; +#ifdef _DEBUG + m_bBLUR = true; +#endif + } +private: + int m_nFADEOUTONSILHOUETTE; +#ifdef _DEBUG + bool m_bFADEOUTONSILHOUETTE; +#endif +public: + void SetFADEOUTONSILHOUETTE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFADEOUTONSILHOUETTE = i; +#ifdef _DEBUG + m_bFADEOUTONSILHOUETTE = true; +#endif + } + void SetFADEOUTONSILHOUETTE( bool i ) + { + m_nFADEOUTONSILHOUETTE = i ? 1 : 0; +#ifdef _DEBUG + m_bFADEOUTONSILHOUETTE = true; +#endif + } +private: + int m_nCUBEMAP; +#ifdef _DEBUG + bool m_bCUBEMAP; +#endif +public: + void SetCUBEMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCUBEMAP = i; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } + void SetCUBEMAP( bool i ) + { + m_nCUBEMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } +private: + int m_nREFRACTTINTTEXTURE; +#ifdef _DEBUG + bool m_bREFRACTTINTTEXTURE; +#endif +public: + void SetREFRACTTINTTEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nREFRACTTINTTEXTURE = i; +#ifdef _DEBUG + m_bREFRACTTINTTEXTURE = true; +#endif + } + void SetREFRACTTINTTEXTURE( bool i ) + { + m_nREFRACTTINTTEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bREFRACTTINTTEXTURE = true; +#endif + } +private: + int m_nMASKED; +#ifdef _DEBUG + bool m_bMASKED; +#endif +public: + void SetMASKED( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nMASKED = i; +#ifdef _DEBUG + m_bMASKED = true; +#endif + } + void SetMASKED( bool i ) + { + m_nMASKED = i ? 1 : 0; +#ifdef _DEBUG + m_bMASKED = true; +#endif + } +private: + int m_nCOLORMODULATE; +#ifdef _DEBUG + bool m_bCOLORMODULATE; +#endif +public: + void SetCOLORMODULATE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOLORMODULATE = i; +#ifdef _DEBUG + m_bCOLORMODULATE = true; +#endif + } + void SetCOLORMODULATE( bool i ) + { + m_nCOLORMODULATE = i ? 1 : 0; +#ifdef _DEBUG + m_bCOLORMODULATE = true; +#endif + } +private: + int m_nSECONDARY_NORMAL; +#ifdef _DEBUG + bool m_bSECONDARY_NORMAL; +#endif +public: + void SetSECONDARY_NORMAL( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSECONDARY_NORMAL = i; +#ifdef _DEBUG + m_bSECONDARY_NORMAL = true; +#endif + } + void SetSECONDARY_NORMAL( bool i ) + { + m_nSECONDARY_NORMAL = i ? 1 : 0; +#ifdef _DEBUG + m_bSECONDARY_NORMAL = true; +#endif + } +private: + int m_nNORMAL_DECODE_MODE; +#ifdef _DEBUG + bool m_bNORMAL_DECODE_MODE; +#endif +public: + void SetNORMAL_DECODE_MODE( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nNORMAL_DECODE_MODE = i; +#ifdef _DEBUG + m_bNORMAL_DECODE_MODE = true; +#endif + } + void SetNORMAL_DECODE_MODE( bool i ) + { + m_nNORMAL_DECODE_MODE = i ? 1 : 0; +#ifdef _DEBUG + m_bNORMAL_DECODE_MODE = true; +#endif + } +public: + refract_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; +#ifdef _DEBUG + m_bBLUR = false; +#endif // _DEBUG + m_nBLUR = 0; +#ifdef _DEBUG + m_bFADEOUTONSILHOUETTE = false; +#endif // _DEBUG + m_nFADEOUTONSILHOUETTE = 0; +#ifdef _DEBUG + m_bCUBEMAP = false; +#endif // _DEBUG + m_nCUBEMAP = 0; +#ifdef _DEBUG + m_bREFRACTTINTTEXTURE = false; +#endif // _DEBUG + m_nREFRACTTINTTEXTURE = 0; +#ifdef _DEBUG + m_bMASKED = false; +#endif // _DEBUG + m_nMASKED = 0; +#ifdef _DEBUG + m_bCOLORMODULATE = false; +#endif // _DEBUG + m_nCOLORMODULATE = 0; +#ifdef _DEBUG + m_bSECONDARY_NORMAL = false; +#endif // _DEBUG + m_nSECONDARY_NORMAL = 0; +#ifdef _DEBUG + m_bNORMAL_DECODE_MODE = false; +#endif // _DEBUG + m_nNORMAL_DECODE_MODE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB && m_bBLUR && m_bFADEOUTONSILHOUETTE && m_bCUBEMAP && m_bREFRACTTINTTEXTURE && m_bMASKED && m_bCOLORMODULATE && m_bSECONDARY_NORMAL && m_bNORMAL_DECODE_MODE; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nCONVERT_TO_SRGB ) + ( 2 * m_nBLUR ) + ( 4 * m_nFADEOUTONSILHOUETTE ) + ( 8 * m_nCUBEMAP ) + ( 16 * m_nREFRACTTINTTEXTURE ) + ( 32 * m_nMASKED ) + ( 64 * m_nCOLORMODULATE ) + ( 128 * m_nSECONDARY_NORMAL ) + ( 256 * m_nNORMAL_DECODE_MODE ) + 0; + } +}; +#define shaderStaticTest_refract_ps20 psh_forgot_to_set_static_BLUR + psh_forgot_to_set_static_FADEOUTONSILHOUETTE + psh_forgot_to_set_static_CUBEMAP + psh_forgot_to_set_static_REFRACTTINTTEXTURE + psh_forgot_to_set_static_MASKED + psh_forgot_to_set_static_COLORMODULATE + psh_forgot_to_set_static_SECONDARY_NORMAL + psh_forgot_to_set_static_NORMAL_DECODE_MODE + 0 +class refract_ps20_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + refract_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_refract_ps20 psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/Refract_vs20.inc b/materialsystem/stdshaders/fxctmp9_360/Refract_vs20.inc new file mode 100644 index 0000000..ad4e856 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/Refract_vs20.inc @@ -0,0 +1,137 @@ +#include "shaderlib/cshader.h" +class refract_vs20_Static_Index +{ +private: + int m_nMODEL; +#ifdef _DEBUG + bool m_bMODEL; +#endif +public: + void SetMODEL( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nMODEL = i; +#ifdef _DEBUG + m_bMODEL = true; +#endif + } + void SetMODEL( bool i ) + { + m_nMODEL = i ? 1 : 0; +#ifdef _DEBUG + m_bMODEL = true; +#endif + } +private: + int m_nCOLORMODULATE; +#ifdef _DEBUG + bool m_bCOLORMODULATE; +#endif +public: + void SetCOLORMODULATE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOLORMODULATE = i; +#ifdef _DEBUG + m_bCOLORMODULATE = true; +#endif + } + void SetCOLORMODULATE( bool i ) + { + m_nCOLORMODULATE = i ? 1 : 0; +#ifdef _DEBUG + m_bCOLORMODULATE = true; +#endif + } +public: + refract_vs20_Static_Index( ) + { +#ifdef _DEBUG + m_bMODEL = false; +#endif // _DEBUG + m_nMODEL = 0; +#ifdef _DEBUG + m_bCOLORMODULATE = false; +#endif // _DEBUG + m_nCOLORMODULATE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bMODEL && m_bCOLORMODULATE; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 4 * m_nMODEL ) + ( 8 * m_nCOLORMODULATE ) + 0; + } +}; +#define shaderStaticTest_refract_vs20 vsh_forgot_to_set_static_MODEL + vsh_forgot_to_set_static_COLORMODULATE + 0 +class refract_vs20_Dynamic_Index +{ +private: + int m_nCOMPRESSED_VERTS; +#ifdef _DEBUG + bool m_bCOMPRESSED_VERTS; +#endif +public: + void SetCOMPRESSED_VERTS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOMPRESSED_VERTS = i; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } + void SetCOMPRESSED_VERTS( bool i ) + { + m_nCOMPRESSED_VERTS = i ? 1 : 0; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +public: + refract_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = false; +#endif // _DEBUG + m_nCOMPRESSED_VERTS = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bCOMPRESSED_VERTS && m_bSKINNING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCOMPRESSED_VERTS ) + ( 2 * m_nSKINNING ) + 0; + } +}; +#define shaderDynamicTest_refract_vs20 vsh_forgot_to_set_dynamic_COMPRESSED_VERTS + vsh_forgot_to_set_dynamic_SKINNING + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/ShatteredGlass_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/ShatteredGlass_ps20.inc new file mode 100644 index 0000000..52d3718 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/ShatteredGlass_ps20.inc @@ -0,0 +1,237 @@ +#include "shaderlib/cshader.h" +class shatteredglass_ps20_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +private: + int m_nCUBEMAP; +#ifdef _DEBUG + bool m_bCUBEMAP; +#endif +public: + void SetCUBEMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCUBEMAP = i; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } + void SetCUBEMAP( bool i ) + { + m_nCUBEMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } +private: + int m_nVERTEXCOLOR; +#ifdef _DEBUG + bool m_bVERTEXCOLOR; +#endif +public: + void SetVERTEXCOLOR( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nVERTEXCOLOR = i; +#ifdef _DEBUG + m_bVERTEXCOLOR = true; +#endif + } + void SetVERTEXCOLOR( bool i ) + { + m_nVERTEXCOLOR = i ? 1 : 0; +#ifdef _DEBUG + m_bVERTEXCOLOR = true; +#endif + } +private: + int m_nENVMAPMASK; +#ifdef _DEBUG + bool m_bENVMAPMASK; +#endif +public: + void SetENVMAPMASK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nENVMAPMASK = i; +#ifdef _DEBUG + m_bENVMAPMASK = true; +#endif + } + void SetENVMAPMASK( bool i ) + { + m_nENVMAPMASK = i ? 1 : 0; +#ifdef _DEBUG + m_bENVMAPMASK = true; +#endif + } +private: + int m_nBASEALPHAENVMAPMASK; +#ifdef _DEBUG + bool m_bBASEALPHAENVMAPMASK; +#endif +public: + void SetBASEALPHAENVMAPMASK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBASEALPHAENVMAPMASK = i; +#ifdef _DEBUG + m_bBASEALPHAENVMAPMASK = true; +#endif + } + void SetBASEALPHAENVMAPMASK( bool i ) + { + m_nBASEALPHAENVMAPMASK = i ? 1 : 0; +#ifdef _DEBUG + m_bBASEALPHAENVMAPMASK = true; +#endif + } +private: + int m_nHDRTYPE; +#ifdef _DEBUG + bool m_bHDRTYPE; +#endif +public: + void SetHDRTYPE( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nHDRTYPE = i; +#ifdef _DEBUG + m_bHDRTYPE = true; +#endif + } + void SetHDRTYPE( bool i ) + { + m_nHDRTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bHDRTYPE = true; +#endif + } +public: + shatteredglass_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; +#ifdef _DEBUG + m_bCUBEMAP = false; +#endif // _DEBUG + m_nCUBEMAP = 0; +#ifdef _DEBUG + m_bVERTEXCOLOR = false; +#endif // _DEBUG + m_nVERTEXCOLOR = 0; +#ifdef _DEBUG + m_bENVMAPMASK = false; +#endif // _DEBUG + m_nENVMAPMASK = 0; +#ifdef _DEBUG + m_bBASEALPHAENVMAPMASK = false; +#endif // _DEBUG + m_nBASEALPHAENVMAPMASK = 0; +#ifdef _DEBUG + m_bHDRTYPE = false; +#endif // _DEBUG + m_nHDRTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB && m_bCUBEMAP && m_bVERTEXCOLOR && m_bENVMAPMASK && m_bBASEALPHAENVMAPMASK && m_bHDRTYPE; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 4 * m_nCONVERT_TO_SRGB ) + ( 4 * m_nCUBEMAP ) + ( 8 * m_nVERTEXCOLOR ) + ( 16 * m_nENVMAPMASK ) + ( 32 * m_nBASEALPHAENVMAPMASK ) + ( 64 * m_nHDRTYPE ) + 0; + } +}; +#define shaderStaticTest_shatteredglass_ps20 psh_forgot_to_set_static_CUBEMAP + psh_forgot_to_set_static_VERTEXCOLOR + psh_forgot_to_set_static_ENVMAPMASK + psh_forgot_to_set_static_BASEALPHAENVMAPMASK + psh_forgot_to_set_static_HDRTYPE + 0 +class shatteredglass_ps20_Dynamic_Index +{ +private: + int m_nHDRENABLED; +#ifdef _DEBUG + bool m_bHDRENABLED; +#endif +public: + void SetHDRENABLED( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHDRENABLED = i; +#ifdef _DEBUG + m_bHDRENABLED = true; +#endif + } + void SetHDRENABLED( bool i ) + { + m_nHDRENABLED = i ? 1 : 0; +#ifdef _DEBUG + m_bHDRENABLED = true; +#endif + } +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + shatteredglass_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bHDRENABLED = false; +#endif // _DEBUG + m_nHDRENABLED = 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bHDRENABLED && m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nHDRENABLED ) + ( 2 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_shatteredglass_ps20 psh_forgot_to_set_dynamic_HDRENABLED + psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/ShatteredGlass_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/ShatteredGlass_ps20b.inc new file mode 100644 index 0000000..e070009 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/ShatteredGlass_ps20b.inc @@ -0,0 +1,237 @@ +#include "shaderlib/cshader.h" +class shatteredglass_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +private: + int m_nCUBEMAP; +#ifdef _DEBUG + bool m_bCUBEMAP; +#endif +public: + void SetCUBEMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCUBEMAP = i; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } + void SetCUBEMAP( bool i ) + { + m_nCUBEMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } +private: + int m_nVERTEXCOLOR; +#ifdef _DEBUG + bool m_bVERTEXCOLOR; +#endif +public: + void SetVERTEXCOLOR( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nVERTEXCOLOR = i; +#ifdef _DEBUG + m_bVERTEXCOLOR = true; +#endif + } + void SetVERTEXCOLOR( bool i ) + { + m_nVERTEXCOLOR = i ? 1 : 0; +#ifdef _DEBUG + m_bVERTEXCOLOR = true; +#endif + } +private: + int m_nENVMAPMASK; +#ifdef _DEBUG + bool m_bENVMAPMASK; +#endif +public: + void SetENVMAPMASK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nENVMAPMASK = i; +#ifdef _DEBUG + m_bENVMAPMASK = true; +#endif + } + void SetENVMAPMASK( bool i ) + { + m_nENVMAPMASK = i ? 1 : 0; +#ifdef _DEBUG + m_bENVMAPMASK = true; +#endif + } +private: + int m_nBASEALPHAENVMAPMASK; +#ifdef _DEBUG + bool m_bBASEALPHAENVMAPMASK; +#endif +public: + void SetBASEALPHAENVMAPMASK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBASEALPHAENVMAPMASK = i; +#ifdef _DEBUG + m_bBASEALPHAENVMAPMASK = true; +#endif + } + void SetBASEALPHAENVMAPMASK( bool i ) + { + m_nBASEALPHAENVMAPMASK = i ? 1 : 0; +#ifdef _DEBUG + m_bBASEALPHAENVMAPMASK = true; +#endif + } +private: + int m_nHDRTYPE; +#ifdef _DEBUG + bool m_bHDRTYPE; +#endif +public: + void SetHDRTYPE( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nHDRTYPE = i; +#ifdef _DEBUG + m_bHDRTYPE = true; +#endif + } + void SetHDRTYPE( bool i ) + { + m_nHDRTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bHDRTYPE = true; +#endif + } +public: + shatteredglass_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; +#ifdef _DEBUG + m_bCUBEMAP = false; +#endif // _DEBUG + m_nCUBEMAP = 0; +#ifdef _DEBUG + m_bVERTEXCOLOR = false; +#endif // _DEBUG + m_nVERTEXCOLOR = 0; +#ifdef _DEBUG + m_bENVMAPMASK = false; +#endif // _DEBUG + m_nENVMAPMASK = 0; +#ifdef _DEBUG + m_bBASEALPHAENVMAPMASK = false; +#endif // _DEBUG + m_nBASEALPHAENVMAPMASK = 0; +#ifdef _DEBUG + m_bHDRTYPE = false; +#endif // _DEBUG + m_nHDRTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB && m_bCUBEMAP && m_bVERTEXCOLOR && m_bENVMAPMASK && m_bBASEALPHAENVMAPMASK && m_bHDRTYPE; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 4 * m_nCONVERT_TO_SRGB ) + ( 4 * m_nCUBEMAP ) + ( 8 * m_nVERTEXCOLOR ) + ( 16 * m_nENVMAPMASK ) + ( 32 * m_nBASEALPHAENVMAPMASK ) + ( 64 * m_nHDRTYPE ) + 0; + } +}; +#define shaderStaticTest_shatteredglass_ps20b psh_forgot_to_set_static_CUBEMAP + psh_forgot_to_set_static_VERTEXCOLOR + psh_forgot_to_set_static_ENVMAPMASK + psh_forgot_to_set_static_BASEALPHAENVMAPMASK + psh_forgot_to_set_static_HDRTYPE + 0 +class shatteredglass_ps20b_Dynamic_Index +{ +private: + int m_nHDRENABLED; +#ifdef _DEBUG + bool m_bHDRENABLED; +#endif +public: + void SetHDRENABLED( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHDRENABLED = i; +#ifdef _DEBUG + m_bHDRENABLED = true; +#endif + } + void SetHDRENABLED( bool i ) + { + m_nHDRENABLED = i ? 1 : 0; +#ifdef _DEBUG + m_bHDRENABLED = true; +#endif + } +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + shatteredglass_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bHDRENABLED = false; +#endif // _DEBUG + m_nHDRENABLED = 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bHDRENABLED && m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nHDRENABLED ) + ( 2 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_shatteredglass_ps20b psh_forgot_to_set_dynamic_HDRENABLED + psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/ShatteredGlass_vs20.inc b/materialsystem/stdshaders/fxctmp9_360/ShatteredGlass_vs20.inc new file mode 100644 index 0000000..adc1b4b --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/ShatteredGlass_vs20.inc @@ -0,0 +1,87 @@ +#include "shaderlib/cshader.h" +class shatteredglass_vs20_Static_Index +{ +private: + int m_nENVMAP_MASK; +#ifdef _DEBUG + bool m_bENVMAP_MASK; +#endif +public: + void SetENVMAP_MASK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nENVMAP_MASK = i; +#ifdef _DEBUG + m_bENVMAP_MASK = true; +#endif + } + void SetENVMAP_MASK( bool i ) + { + m_nENVMAP_MASK = i ? 1 : 0; +#ifdef _DEBUG + m_bENVMAP_MASK = true; +#endif + } +public: + shatteredglass_vs20_Static_Index( ) + { +#ifdef _DEBUG + m_bENVMAP_MASK = false; +#endif // _DEBUG + m_nENVMAP_MASK = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bENVMAP_MASK; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nENVMAP_MASK ) + 0; + } +}; +#define shaderStaticTest_shatteredglass_vs20 vsh_forgot_to_set_static_ENVMAP_MASK + 0 +class shatteredglass_vs20_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + shatteredglass_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; +#define shaderDynamicTest_shatteredglass_vs20 vsh_forgot_to_set_dynamic_DOWATERFOG + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/VertexLit_and_unlit_Generic_bump_vs20.inc b/materialsystem/stdshaders/fxctmp9_360/VertexLit_and_unlit_Generic_bump_vs20.inc new file mode 100644 index 0000000..d950b06 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/VertexLit_and_unlit_Generic_bump_vs20.inc @@ -0,0 +1,237 @@ +#include "shaderlib/cshader.h" +class vertexlit_and_unlit_generic_bump_vs20_Static_Index +{ +private: + int m_nHALFLAMBERT; +#ifdef _DEBUG + bool m_bHALFLAMBERT; +#endif +public: + void SetHALFLAMBERT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHALFLAMBERT = i; +#ifdef _DEBUG + m_bHALFLAMBERT = true; +#endif + } + void SetHALFLAMBERT( bool i ) + { + m_nHALFLAMBERT = i ? 1 : 0; +#ifdef _DEBUG + m_bHALFLAMBERT = true; +#endif + } +private: + int m_nUSE_WITH_2B; +#ifdef _DEBUG + bool m_bUSE_WITH_2B; +#endif +public: + void SetUSE_WITH_2B( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nUSE_WITH_2B = i; +#ifdef _DEBUG + m_bUSE_WITH_2B = true; +#endif + } + void SetUSE_WITH_2B( bool i ) + { + m_nUSE_WITH_2B = i ? 1 : 0; +#ifdef _DEBUG + m_bUSE_WITH_2B = true; +#endif + } +private: + int m_nFLASHLIGHT; +#ifdef _DEBUG + bool m_bFLASHLIGHT; +#endif +public: + void SetFLASHLIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFLASHLIGHT = i; +#ifdef _DEBUG + m_bFLASHLIGHT = true; +#endif + } + void SetFLASHLIGHT( bool i ) + { + m_nFLASHLIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bFLASHLIGHT = true; +#endif + } +private: + int m_nUSE_STATIC_CONTROL_FLOW; +#ifdef _DEBUG + bool m_bUSE_STATIC_CONTROL_FLOW; +#endif +public: + void SetUSE_STATIC_CONTROL_FLOW( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nUSE_STATIC_CONTROL_FLOW = i; +#ifdef _DEBUG + m_bUSE_STATIC_CONTROL_FLOW = true; +#endif + } + void SetUSE_STATIC_CONTROL_FLOW( bool i ) + { + m_nUSE_STATIC_CONTROL_FLOW = i ? 1 : 0; +#ifdef _DEBUG + m_bUSE_STATIC_CONTROL_FLOW = true; +#endif + } +public: + vertexlit_and_unlit_generic_bump_vs20_Static_Index( ) + { +#ifdef _DEBUG + m_bHALFLAMBERT = false; +#endif // _DEBUG + m_nHALFLAMBERT = 0; +#ifdef _DEBUG + m_bUSE_WITH_2B = false; +#endif // _DEBUG + m_nUSE_WITH_2B = 0; +#ifdef _DEBUG + m_bFLASHLIGHT = false; +#endif // _DEBUG + m_nFLASHLIGHT = 0; +#ifdef _DEBUG + m_bUSE_STATIC_CONTROL_FLOW = false; +#endif // _DEBUG + m_nUSE_STATIC_CONTROL_FLOW = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bHALFLAMBERT && m_bUSE_WITH_2B && m_bFLASHLIGHT && m_bUSE_STATIC_CONTROL_FLOW; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 24 * m_nHALFLAMBERT ) + ( 48 * m_nUSE_WITH_2B ) + ( 96 * m_nFLASHLIGHT ) + ( 192 * m_nUSE_STATIC_CONTROL_FLOW ) + 0; + } +}; +#define shaderStaticTest_vertexlit_and_unlit_generic_bump_vs20 vsh_forgot_to_set_static_HALFLAMBERT + vsh_forgot_to_set_static_USE_WITH_2B + vsh_forgot_to_set_static_FLASHLIGHT + vsh_forgot_to_set_static_USE_STATIC_CONTROL_FLOW + 0 +class vertexlit_and_unlit_generic_bump_vs20_Dynamic_Index +{ +private: + int m_nCOMPRESSED_VERTS; +#ifdef _DEBUG + bool m_bCOMPRESSED_VERTS; +#endif +public: + void SetCOMPRESSED_VERTS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOMPRESSED_VERTS = i; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } + void SetCOMPRESSED_VERTS( bool i ) + { + m_nCOMPRESSED_VERTS = i ? 1 : 0; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +private: + int m_nNUM_LIGHTS; +#ifdef _DEBUG + bool m_bNUM_LIGHTS; +#endif +public: + void SetNUM_LIGHTS( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nNUM_LIGHTS = i; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } + void SetNUM_LIGHTS( bool i ) + { + m_nNUM_LIGHTS = i ? 1 : 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } +public: + vertexlit_and_unlit_generic_bump_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = false; +#endif // _DEBUG + m_nCOMPRESSED_VERTS = 0; +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = false; +#endif // _DEBUG + m_nNUM_LIGHTS = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bCOMPRESSED_VERTS && m_bDOWATERFOG && m_bSKINNING && m_bNUM_LIGHTS; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCOMPRESSED_VERTS ) + ( 2 * m_nDOWATERFOG ) + ( 4 * m_nSKINNING ) + ( 8 * m_nNUM_LIGHTS ) + 0; + } +}; +#define shaderDynamicTest_vertexlit_and_unlit_generic_bump_vs20 vsh_forgot_to_set_dynamic_COMPRESSED_VERTS + vsh_forgot_to_set_dynamic_DOWATERFOG + vsh_forgot_to_set_dynamic_SKINNING + vsh_forgot_to_set_dynamic_NUM_LIGHTS + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/VertexLit_and_unlit_Generic_vs20.inc b/materialsystem/stdshaders/fxctmp9_360/VertexLit_and_unlit_Generic_vs20.inc new file mode 100644 index 0000000..432e508 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/VertexLit_and_unlit_Generic_vs20.inc @@ -0,0 +1,437 @@ +#include "shaderlib/cshader.h" +class vertexlit_and_unlit_generic_vs20_Static_Index +{ +private: + int m_nVERTEXCOLOR; +#ifdef _DEBUG + bool m_bVERTEXCOLOR; +#endif +public: + void SetVERTEXCOLOR( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nVERTEXCOLOR = i; +#ifdef _DEBUG + m_bVERTEXCOLOR = true; +#endif + } + void SetVERTEXCOLOR( bool i ) + { + m_nVERTEXCOLOR = i ? 1 : 0; +#ifdef _DEBUG + m_bVERTEXCOLOR = true; +#endif + } +private: + int m_nCUBEMAP; +#ifdef _DEBUG + bool m_bCUBEMAP; +#endif +public: + void SetCUBEMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCUBEMAP = i; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } + void SetCUBEMAP( bool i ) + { + m_nCUBEMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } +private: + int m_nHALFLAMBERT; +#ifdef _DEBUG + bool m_bHALFLAMBERT; +#endif +public: + void SetHALFLAMBERT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHALFLAMBERT = i; +#ifdef _DEBUG + m_bHALFLAMBERT = true; +#endif + } + void SetHALFLAMBERT( bool i ) + { + m_nHALFLAMBERT = i ? 1 : 0; +#ifdef _DEBUG + m_bHALFLAMBERT = true; +#endif + } +private: + int m_nFLASHLIGHT; +#ifdef _DEBUG + bool m_bFLASHLIGHT; +#endif +public: + void SetFLASHLIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFLASHLIGHT = i; +#ifdef _DEBUG + m_bFLASHLIGHT = true; +#endif + } + void SetFLASHLIGHT( bool i ) + { + m_nFLASHLIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bFLASHLIGHT = true; +#endif + } +private: + int m_nSEAMLESS_BASE; +#ifdef _DEBUG + bool m_bSEAMLESS_BASE; +#endif +public: + void SetSEAMLESS_BASE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSEAMLESS_BASE = i; +#ifdef _DEBUG + m_bSEAMLESS_BASE = true; +#endif + } + void SetSEAMLESS_BASE( bool i ) + { + m_nSEAMLESS_BASE = i ? 1 : 0; +#ifdef _DEBUG + m_bSEAMLESS_BASE = true; +#endif + } +private: + int m_nSEAMLESS_DETAIL; +#ifdef _DEBUG + bool m_bSEAMLESS_DETAIL; +#endif +public: + void SetSEAMLESS_DETAIL( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSEAMLESS_DETAIL = i; +#ifdef _DEBUG + m_bSEAMLESS_DETAIL = true; +#endif + } + void SetSEAMLESS_DETAIL( bool i ) + { + m_nSEAMLESS_DETAIL = i ? 1 : 0; +#ifdef _DEBUG + m_bSEAMLESS_DETAIL = true; +#endif + } +private: + int m_nSEPARATE_DETAIL_UVS; +#ifdef _DEBUG + bool m_bSEPARATE_DETAIL_UVS; +#endif +public: + void SetSEPARATE_DETAIL_UVS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSEPARATE_DETAIL_UVS = i; +#ifdef _DEBUG + m_bSEPARATE_DETAIL_UVS = true; +#endif + } + void SetSEPARATE_DETAIL_UVS( bool i ) + { + m_nSEPARATE_DETAIL_UVS = i ? 1 : 0; +#ifdef _DEBUG + m_bSEPARATE_DETAIL_UVS = true; +#endif + } +private: + int m_nUSE_STATIC_CONTROL_FLOW; +#ifdef _DEBUG + bool m_bUSE_STATIC_CONTROL_FLOW; +#endif +public: + void SetUSE_STATIC_CONTROL_FLOW( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nUSE_STATIC_CONTROL_FLOW = i; +#ifdef _DEBUG + m_bUSE_STATIC_CONTROL_FLOW = true; +#endif + } + void SetUSE_STATIC_CONTROL_FLOW( bool i ) + { + m_nUSE_STATIC_CONTROL_FLOW = i ? 1 : 0; +#ifdef _DEBUG + m_bUSE_STATIC_CONTROL_FLOW = true; +#endif + } +private: + int m_nDONT_GAMMA_CONVERT_VERTEX_COLOR; +#ifdef _DEBUG + bool m_bDONT_GAMMA_CONVERT_VERTEX_COLOR; +#endif +public: + void SetDONT_GAMMA_CONVERT_VERTEX_COLOR( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDONT_GAMMA_CONVERT_VERTEX_COLOR = i; +#ifdef _DEBUG + m_bDONT_GAMMA_CONVERT_VERTEX_COLOR = true; +#endif + } + void SetDONT_GAMMA_CONVERT_VERTEX_COLOR( bool i ) + { + m_nDONT_GAMMA_CONVERT_VERTEX_COLOR = i ? 1 : 0; +#ifdef _DEBUG + m_bDONT_GAMMA_CONVERT_VERTEX_COLOR = true; +#endif + } +public: + vertexlit_and_unlit_generic_vs20_Static_Index( ) + { +#ifdef _DEBUG + m_bVERTEXCOLOR = false; +#endif // _DEBUG + m_nVERTEXCOLOR = 0; +#ifdef _DEBUG + m_bCUBEMAP = false; +#endif // _DEBUG + m_nCUBEMAP = 0; +#ifdef _DEBUG + m_bHALFLAMBERT = false; +#endif // _DEBUG + m_nHALFLAMBERT = 0; +#ifdef _DEBUG + m_bFLASHLIGHT = false; +#endif // _DEBUG + m_nFLASHLIGHT = 0; +#ifdef _DEBUG + m_bSEAMLESS_BASE = false; +#endif // _DEBUG + m_nSEAMLESS_BASE = 0; +#ifdef _DEBUG + m_bSEAMLESS_DETAIL = false; +#endif // _DEBUG + m_nSEAMLESS_DETAIL = 0; +#ifdef _DEBUG + m_bSEPARATE_DETAIL_UVS = false; +#endif // _DEBUG + m_nSEPARATE_DETAIL_UVS = 0; +#ifdef _DEBUG + m_bUSE_STATIC_CONTROL_FLOW = false; +#endif // _DEBUG + m_nUSE_STATIC_CONTROL_FLOW = 0; +#ifdef _DEBUG + m_bDONT_GAMMA_CONVERT_VERTEX_COLOR = false; +#endif // _DEBUG + m_nDONT_GAMMA_CONVERT_VERTEX_COLOR = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bVERTEXCOLOR && m_bCUBEMAP && m_bHALFLAMBERT && m_bFLASHLIGHT && m_bSEAMLESS_BASE && m_bSEAMLESS_DETAIL && m_bSEPARATE_DETAIL_UVS && m_bUSE_STATIC_CONTROL_FLOW && m_bDONT_GAMMA_CONVERT_VERTEX_COLOR; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 96 * m_nVERTEXCOLOR ) + ( 192 * m_nCUBEMAP ) + ( 384 * m_nHALFLAMBERT ) + ( 768 * m_nFLASHLIGHT ) + ( 1536 * m_nSEAMLESS_BASE ) + ( 3072 * m_nSEAMLESS_DETAIL ) + ( 6144 * m_nSEPARATE_DETAIL_UVS ) + ( 12288 * m_nUSE_STATIC_CONTROL_FLOW ) + ( 24576 * m_nDONT_GAMMA_CONVERT_VERTEX_COLOR ) + 0; + } +}; +#define shaderStaticTest_vertexlit_and_unlit_generic_vs20 vsh_forgot_to_set_static_VERTEXCOLOR + vsh_forgot_to_set_static_CUBEMAP + vsh_forgot_to_set_static_HALFLAMBERT + vsh_forgot_to_set_static_FLASHLIGHT + vsh_forgot_to_set_static_SEAMLESS_BASE + vsh_forgot_to_set_static_SEAMLESS_DETAIL + vsh_forgot_to_set_static_SEPARATE_DETAIL_UVS + vsh_forgot_to_set_static_USE_STATIC_CONTROL_FLOW + vsh_forgot_to_set_static_DONT_GAMMA_CONVERT_VERTEX_COLOR + 0 +class vertexlit_and_unlit_generic_vs20_Dynamic_Index +{ +private: + int m_nCOMPRESSED_VERTS; +#ifdef _DEBUG + bool m_bCOMPRESSED_VERTS; +#endif +public: + void SetCOMPRESSED_VERTS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOMPRESSED_VERTS = i; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } + void SetCOMPRESSED_VERTS( bool i ) + { + m_nCOMPRESSED_VERTS = i ? 1 : 0; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } +private: + int m_nDYNAMIC_LIGHT; +#ifdef _DEBUG + bool m_bDYNAMIC_LIGHT; +#endif +public: + void SetDYNAMIC_LIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDYNAMIC_LIGHT = i; +#ifdef _DEBUG + m_bDYNAMIC_LIGHT = true; +#endif + } + void SetDYNAMIC_LIGHT( bool i ) + { + m_nDYNAMIC_LIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bDYNAMIC_LIGHT = true; +#endif + } +private: + int m_nSTATIC_LIGHT; +#ifdef _DEBUG + bool m_bSTATIC_LIGHT; +#endif +public: + void SetSTATIC_LIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSTATIC_LIGHT = i; +#ifdef _DEBUG + m_bSTATIC_LIGHT = true; +#endif + } + void SetSTATIC_LIGHT( bool i ) + { + m_nSTATIC_LIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bSTATIC_LIGHT = true; +#endif + } +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +private: + int m_nLIGHTING_PREVIEW; +#ifdef _DEBUG + bool m_bLIGHTING_PREVIEW; +#endif +public: + void SetLIGHTING_PREVIEW( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nLIGHTING_PREVIEW = i; +#ifdef _DEBUG + m_bLIGHTING_PREVIEW = true; +#endif + } + void SetLIGHTING_PREVIEW( bool i ) + { + m_nLIGHTING_PREVIEW = i ? 1 : 0; +#ifdef _DEBUG + m_bLIGHTING_PREVIEW = true; +#endif + } +private: + int m_nNUM_LIGHTS; +#ifdef _DEBUG + bool m_bNUM_LIGHTS; +#endif +public: + void SetNUM_LIGHTS( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nNUM_LIGHTS = i; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } + void SetNUM_LIGHTS( bool i ) + { + m_nNUM_LIGHTS = i ? 1 : 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } +public: + vertexlit_and_unlit_generic_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = false; +#endif // _DEBUG + m_nCOMPRESSED_VERTS = 0; +#ifdef _DEBUG + m_bDYNAMIC_LIGHT = false; +#endif // _DEBUG + m_nDYNAMIC_LIGHT = 0; +#ifdef _DEBUG + m_bSTATIC_LIGHT = false; +#endif // _DEBUG + m_nSTATIC_LIGHT = 0; +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; +#ifdef _DEBUG + m_bLIGHTING_PREVIEW = false; +#endif // _DEBUG + m_nLIGHTING_PREVIEW = 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = false; +#endif // _DEBUG + m_nNUM_LIGHTS = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bCOMPRESSED_VERTS && m_bDYNAMIC_LIGHT && m_bSTATIC_LIGHT && m_bDOWATERFOG && m_bSKINNING && m_bLIGHTING_PREVIEW && m_bNUM_LIGHTS; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCOMPRESSED_VERTS ) + ( 2 * m_nDYNAMIC_LIGHT ) + ( 4 * m_nSTATIC_LIGHT ) + ( 8 * m_nDOWATERFOG ) + ( 16 * m_nSKINNING ) + ( 32 * m_nLIGHTING_PREVIEW ) + ( 32 * m_nNUM_LIGHTS ) + 0; + } +}; +#define shaderDynamicTest_vertexlit_and_unlit_generic_vs20 vsh_forgot_to_set_dynamic_COMPRESSED_VERTS + vsh_forgot_to_set_dynamic_DYNAMIC_LIGHT + vsh_forgot_to_set_dynamic_STATIC_LIGHT + vsh_forgot_to_set_dynamic_DOWATERFOG + vsh_forgot_to_set_dynamic_SKINNING + vsh_forgot_to_set_dynamic_LIGHTING_PREVIEW + vsh_forgot_to_set_dynamic_NUM_LIGHTS + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/WaterCheap_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/WaterCheap_ps20.inc new file mode 100644 index 0000000..b450ea8 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/WaterCheap_ps20.inc @@ -0,0 +1,262 @@ +#include "shaderlib/cshader.h" +class watercheap_ps20_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +private: + int m_nMULTITEXTURE; +#ifdef _DEBUG + bool m_bMULTITEXTURE; +#endif +public: + void SetMULTITEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nMULTITEXTURE = i; +#ifdef _DEBUG + m_bMULTITEXTURE = true; +#endif + } + void SetMULTITEXTURE( bool i ) + { + m_nMULTITEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bMULTITEXTURE = true; +#endif + } +private: + int m_nFRESNEL; +#ifdef _DEBUG + bool m_bFRESNEL; +#endif +public: + void SetFRESNEL( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFRESNEL = i; +#ifdef _DEBUG + m_bFRESNEL = true; +#endif + } + void SetFRESNEL( bool i ) + { + m_nFRESNEL = i ? 1 : 0; +#ifdef _DEBUG + m_bFRESNEL = true; +#endif + } +private: + int m_nBLEND; +#ifdef _DEBUG + bool m_bBLEND; +#endif +public: + void SetBLEND( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBLEND = i; +#ifdef _DEBUG + m_bBLEND = true; +#endif + } + void SetBLEND( bool i ) + { + m_nBLEND = i ? 1 : 0; +#ifdef _DEBUG + m_bBLEND = true; +#endif + } +private: + int m_nREFRACTALPHA; +#ifdef _DEBUG + bool m_bREFRACTALPHA; +#endif +public: + void SetREFRACTALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nREFRACTALPHA = i; +#ifdef _DEBUG + m_bREFRACTALPHA = true; +#endif + } + void SetREFRACTALPHA( bool i ) + { + m_nREFRACTALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bREFRACTALPHA = true; +#endif + } +private: + int m_nHDRTYPE; +#ifdef _DEBUG + bool m_bHDRTYPE; +#endif +public: + void SetHDRTYPE( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nHDRTYPE = i; +#ifdef _DEBUG + m_bHDRTYPE = true; +#endif + } + void SetHDRTYPE( bool i ) + { + m_nHDRTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bHDRTYPE = true; +#endif + } +private: + int m_nNORMAL_DECODE_MODE; +#ifdef _DEBUG + bool m_bNORMAL_DECODE_MODE; +#endif +public: + void SetNORMAL_DECODE_MODE( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nNORMAL_DECODE_MODE = i; +#ifdef _DEBUG + m_bNORMAL_DECODE_MODE = true; +#endif + } + void SetNORMAL_DECODE_MODE( bool i ) + { + m_nNORMAL_DECODE_MODE = i ? 1 : 0; +#ifdef _DEBUG + m_bNORMAL_DECODE_MODE = true; +#endif + } +public: + watercheap_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; +#ifdef _DEBUG + m_bMULTITEXTURE = false; +#endif // _DEBUG + m_nMULTITEXTURE = 0; +#ifdef _DEBUG + m_bFRESNEL = false; +#endif // _DEBUG + m_nFRESNEL = 0; +#ifdef _DEBUG + m_bBLEND = false; +#endif // _DEBUG + m_nBLEND = 0; +#ifdef _DEBUG + m_bREFRACTALPHA = false; +#endif // _DEBUG + m_nREFRACTALPHA = 0; +#ifdef _DEBUG + m_bHDRTYPE = false; +#endif // _DEBUG + m_nHDRTYPE = 0; +#ifdef _DEBUG + m_bNORMAL_DECODE_MODE = false; +#endif // _DEBUG + m_nNORMAL_DECODE_MODE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB && m_bMULTITEXTURE && m_bFRESNEL && m_bBLEND && m_bREFRACTALPHA && m_bHDRTYPE && m_bNORMAL_DECODE_MODE; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 4 * m_nCONVERT_TO_SRGB ) + ( 4 * m_nMULTITEXTURE ) + ( 8 * m_nFRESNEL ) + ( 16 * m_nBLEND ) + ( 32 * m_nREFRACTALPHA ) + ( 64 * m_nHDRTYPE ) + ( 192 * m_nNORMAL_DECODE_MODE ) + 0; + } +}; +#define shaderStaticTest_watercheap_ps20 psh_forgot_to_set_static_MULTITEXTURE + psh_forgot_to_set_static_FRESNEL + psh_forgot_to_set_static_BLEND + psh_forgot_to_set_static_REFRACTALPHA + psh_forgot_to_set_static_HDRTYPE + psh_forgot_to_set_static_NORMAL_DECODE_MODE + 0 +class watercheap_ps20_Dynamic_Index +{ +private: + int m_nHDRENABLED; +#ifdef _DEBUG + bool m_bHDRENABLED; +#endif +public: + void SetHDRENABLED( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHDRENABLED = i; +#ifdef _DEBUG + m_bHDRENABLED = true; +#endif + } + void SetHDRENABLED( bool i ) + { + m_nHDRENABLED = i ? 1 : 0; +#ifdef _DEBUG + m_bHDRENABLED = true; +#endif + } +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + watercheap_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bHDRENABLED = false; +#endif // _DEBUG + m_nHDRENABLED = 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bHDRENABLED && m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nHDRENABLED ) + ( 2 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_watercheap_ps20 psh_forgot_to_set_dynamic_HDRENABLED + psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/WaterCheap_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/WaterCheap_ps20b.inc new file mode 100644 index 0000000..601062e --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/WaterCheap_ps20b.inc @@ -0,0 +1,262 @@ +#include "shaderlib/cshader.h" +class watercheap_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +private: + int m_nMULTITEXTURE; +#ifdef _DEBUG + bool m_bMULTITEXTURE; +#endif +public: + void SetMULTITEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nMULTITEXTURE = i; +#ifdef _DEBUG + m_bMULTITEXTURE = true; +#endif + } + void SetMULTITEXTURE( bool i ) + { + m_nMULTITEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bMULTITEXTURE = true; +#endif + } +private: + int m_nFRESNEL; +#ifdef _DEBUG + bool m_bFRESNEL; +#endif +public: + void SetFRESNEL( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFRESNEL = i; +#ifdef _DEBUG + m_bFRESNEL = true; +#endif + } + void SetFRESNEL( bool i ) + { + m_nFRESNEL = i ? 1 : 0; +#ifdef _DEBUG + m_bFRESNEL = true; +#endif + } +private: + int m_nBLEND; +#ifdef _DEBUG + bool m_bBLEND; +#endif +public: + void SetBLEND( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBLEND = i; +#ifdef _DEBUG + m_bBLEND = true; +#endif + } + void SetBLEND( bool i ) + { + m_nBLEND = i ? 1 : 0; +#ifdef _DEBUG + m_bBLEND = true; +#endif + } +private: + int m_nREFRACTALPHA; +#ifdef _DEBUG + bool m_bREFRACTALPHA; +#endif +public: + void SetREFRACTALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nREFRACTALPHA = i; +#ifdef _DEBUG + m_bREFRACTALPHA = true; +#endif + } + void SetREFRACTALPHA( bool i ) + { + m_nREFRACTALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bREFRACTALPHA = true; +#endif + } +private: + int m_nHDRTYPE; +#ifdef _DEBUG + bool m_bHDRTYPE; +#endif +public: + void SetHDRTYPE( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nHDRTYPE = i; +#ifdef _DEBUG + m_bHDRTYPE = true; +#endif + } + void SetHDRTYPE( bool i ) + { + m_nHDRTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bHDRTYPE = true; +#endif + } +private: + int m_nNORMAL_DECODE_MODE; +#ifdef _DEBUG + bool m_bNORMAL_DECODE_MODE; +#endif +public: + void SetNORMAL_DECODE_MODE( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nNORMAL_DECODE_MODE = i; +#ifdef _DEBUG + m_bNORMAL_DECODE_MODE = true; +#endif + } + void SetNORMAL_DECODE_MODE( bool i ) + { + m_nNORMAL_DECODE_MODE = i ? 1 : 0; +#ifdef _DEBUG + m_bNORMAL_DECODE_MODE = true; +#endif + } +public: + watercheap_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; +#ifdef _DEBUG + m_bMULTITEXTURE = false; +#endif // _DEBUG + m_nMULTITEXTURE = 0; +#ifdef _DEBUG + m_bFRESNEL = false; +#endif // _DEBUG + m_nFRESNEL = 0; +#ifdef _DEBUG + m_bBLEND = false; +#endif // _DEBUG + m_nBLEND = 0; +#ifdef _DEBUG + m_bREFRACTALPHA = false; +#endif // _DEBUG + m_nREFRACTALPHA = 0; +#ifdef _DEBUG + m_bHDRTYPE = false; +#endif // _DEBUG + m_nHDRTYPE = 0; +#ifdef _DEBUG + m_bNORMAL_DECODE_MODE = false; +#endif // _DEBUG + m_nNORMAL_DECODE_MODE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB && m_bMULTITEXTURE && m_bFRESNEL && m_bBLEND && m_bREFRACTALPHA && m_bHDRTYPE && m_bNORMAL_DECODE_MODE; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 4 * m_nCONVERT_TO_SRGB ) + ( 4 * m_nMULTITEXTURE ) + ( 8 * m_nFRESNEL ) + ( 16 * m_nBLEND ) + ( 32 * m_nREFRACTALPHA ) + ( 64 * m_nHDRTYPE ) + ( 192 * m_nNORMAL_DECODE_MODE ) + 0; + } +}; +#define shaderStaticTest_watercheap_ps20b psh_forgot_to_set_static_MULTITEXTURE + psh_forgot_to_set_static_FRESNEL + psh_forgot_to_set_static_BLEND + psh_forgot_to_set_static_REFRACTALPHA + psh_forgot_to_set_static_HDRTYPE + psh_forgot_to_set_static_NORMAL_DECODE_MODE + 0 +class watercheap_ps20b_Dynamic_Index +{ +private: + int m_nHDRENABLED; +#ifdef _DEBUG + bool m_bHDRENABLED; +#endif +public: + void SetHDRENABLED( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHDRENABLED = i; +#ifdef _DEBUG + m_bHDRENABLED = true; +#endif + } + void SetHDRENABLED( bool i ) + { + m_nHDRENABLED = i ? 1 : 0; +#ifdef _DEBUG + m_bHDRENABLED = true; +#endif + } +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + watercheap_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bHDRENABLED = false; +#endif // _DEBUG + m_nHDRENABLED = 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bHDRENABLED && m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nHDRENABLED ) + ( 2 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_watercheap_ps20b psh_forgot_to_set_dynamic_HDRENABLED + psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/WaterCheap_vs20.inc b/materialsystem/stdshaders/fxctmp9_360/WaterCheap_vs20.inc new file mode 100644 index 0000000..fec9108 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/WaterCheap_vs20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class watercheap_vs20_Static_Index +{ +private: + int m_nBLEND; +#ifdef _DEBUG + bool m_bBLEND; +#endif +public: + void SetBLEND( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBLEND = i; +#ifdef _DEBUG + m_bBLEND = true; +#endif + } + void SetBLEND( bool i ) + { + m_nBLEND = i ? 1 : 0; +#ifdef _DEBUG + m_bBLEND = true; +#endif + } +public: + watercheap_vs20_Static_Index( ) + { +#ifdef _DEBUG + m_bBLEND = false; +#endif // _DEBUG + m_nBLEND = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bBLEND; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nBLEND ) + 0; + } +}; +#define shaderStaticTest_watercheap_vs20 vsh_forgot_to_set_static_BLEND + 0 +class watercheap_vs20_Dynamic_Index +{ +public: + watercheap_vs20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_watercheap_vs20 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/Water_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/Water_ps20.inc new file mode 100644 index 0000000..8df24cd --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/Water_ps20.inc @@ -0,0 +1,237 @@ +#include "shaderlib/cshader.h" +class water_ps20_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +private: + int m_nBASETEXTURE; +#ifdef _DEBUG + bool m_bBASETEXTURE; +#endif +public: + void SetBASETEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBASETEXTURE = i; +#ifdef _DEBUG + m_bBASETEXTURE = true; +#endif + } + void SetBASETEXTURE( bool i ) + { + m_nBASETEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bBASETEXTURE = true; +#endif + } +private: + int m_nMULTITEXTURE; +#ifdef _DEBUG + bool m_bMULTITEXTURE; +#endif +public: + void SetMULTITEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nMULTITEXTURE = i; +#ifdef _DEBUG + m_bMULTITEXTURE = true; +#endif + } + void SetMULTITEXTURE( bool i ) + { + m_nMULTITEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bMULTITEXTURE = true; +#endif + } +private: + int m_nREFLECT; +#ifdef _DEBUG + bool m_bREFLECT; +#endif +public: + void SetREFLECT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nREFLECT = i; +#ifdef _DEBUG + m_bREFLECT = true; +#endif + } + void SetREFLECT( bool i ) + { + m_nREFLECT = i ? 1 : 0; +#ifdef _DEBUG + m_bREFLECT = true; +#endif + } +private: + int m_nREFRACT; +#ifdef _DEBUG + bool m_bREFRACT; +#endif +public: + void SetREFRACT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nREFRACT = i; +#ifdef _DEBUG + m_bREFRACT = true; +#endif + } + void SetREFRACT( bool i ) + { + m_nREFRACT = i ? 1 : 0; +#ifdef _DEBUG + m_bREFRACT = true; +#endif + } +private: + int m_nABOVEWATER; +#ifdef _DEBUG + bool m_bABOVEWATER; +#endif +public: + void SetABOVEWATER( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nABOVEWATER = i; +#ifdef _DEBUG + m_bABOVEWATER = true; +#endif + } + void SetABOVEWATER( bool i ) + { + m_nABOVEWATER = i ? 1 : 0; +#ifdef _DEBUG + m_bABOVEWATER = true; +#endif + } +private: + int m_nNORMAL_DECODE_MODE; +#ifdef _DEBUG + bool m_bNORMAL_DECODE_MODE; +#endif +public: + void SetNORMAL_DECODE_MODE( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nNORMAL_DECODE_MODE = i; +#ifdef _DEBUG + m_bNORMAL_DECODE_MODE = true; +#endif + } + void SetNORMAL_DECODE_MODE( bool i ) + { + m_nNORMAL_DECODE_MODE = i ? 1 : 0; +#ifdef _DEBUG + m_bNORMAL_DECODE_MODE = true; +#endif + } +public: + water_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; +#ifdef _DEBUG + m_bBASETEXTURE = false; +#endif // _DEBUG + m_nBASETEXTURE = 0; +#ifdef _DEBUG + m_bMULTITEXTURE = false; +#endif // _DEBUG + m_nMULTITEXTURE = 0; +#ifdef _DEBUG + m_bREFLECT = false; +#endif // _DEBUG + m_nREFLECT = 0; +#ifdef _DEBUG + m_bREFRACT = false; +#endif // _DEBUG + m_nREFRACT = 0; +#ifdef _DEBUG + m_bABOVEWATER = false; +#endif // _DEBUG + m_nABOVEWATER = 0; +#ifdef _DEBUG + m_bNORMAL_DECODE_MODE = false; +#endif // _DEBUG + m_nNORMAL_DECODE_MODE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB && m_bBASETEXTURE && m_bMULTITEXTURE && m_bREFLECT && m_bREFRACT && m_bABOVEWATER && m_bNORMAL_DECODE_MODE; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nCONVERT_TO_SRGB ) + ( 2 * m_nBASETEXTURE ) + ( 4 * m_nMULTITEXTURE ) + ( 8 * m_nREFLECT ) + ( 16 * m_nREFRACT ) + ( 32 * m_nABOVEWATER ) + ( 64 * m_nNORMAL_DECODE_MODE ) + 0; + } +}; +#define shaderStaticTest_water_ps20 psh_forgot_to_set_static_BASETEXTURE + psh_forgot_to_set_static_MULTITEXTURE + psh_forgot_to_set_static_REFLECT + psh_forgot_to_set_static_REFRACT + psh_forgot_to_set_static_ABOVEWATER + psh_forgot_to_set_static_NORMAL_DECODE_MODE + 0 +class water_ps20_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + water_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_water_ps20 psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/Water_vs20.inc b/materialsystem/stdshaders/fxctmp9_360/Water_vs20.inc new file mode 100644 index 0000000..4f31b04 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/Water_vs20.inc @@ -0,0 +1,85 @@ +#include "shaderlib/cshader.h" +class water_vs20_Static_Index +{ +private: + int m_nBASETEXTURE; +#ifdef _DEBUG + bool m_bBASETEXTURE; +#endif +public: + void SetBASETEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBASETEXTURE = i; +#ifdef _DEBUG + m_bBASETEXTURE = true; +#endif + } + void SetBASETEXTURE( bool i ) + { + m_nBASETEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bBASETEXTURE = true; +#endif + } +private: + int m_nMULTITEXTURE; +#ifdef _DEBUG + bool m_bMULTITEXTURE; +#endif +public: + void SetMULTITEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nMULTITEXTURE = i; +#ifdef _DEBUG + m_bMULTITEXTURE = true; +#endif + } + void SetMULTITEXTURE( bool i ) + { + m_nMULTITEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bMULTITEXTURE = true; +#endif + } +public: + water_vs20_Static_Index( ) + { +#ifdef _DEBUG + m_bBASETEXTURE = false; +#endif // _DEBUG + m_nBASETEXTURE = 0; +#ifdef _DEBUG + m_bMULTITEXTURE = false; +#endif // _DEBUG + m_nMULTITEXTURE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bBASETEXTURE && m_bMULTITEXTURE; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nBASETEXTURE ) + ( 2 * m_nMULTITEXTURE ) + 0; + } +}; +#define shaderStaticTest_water_vs20 vsh_forgot_to_set_static_BASETEXTURE + vsh_forgot_to_set_static_MULTITEXTURE + 0 +class water_vs20_Dynamic_Index +{ +public: + water_vs20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_water_vs20 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/WorldTwoTextureBlend_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/WorldTwoTextureBlend_ps20.inc new file mode 100644 index 0000000..20ed614 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/WorldTwoTextureBlend_ps20.inc @@ -0,0 +1,312 @@ +#include "shaderlib/cshader.h" +class worldtwotextureblend_ps20_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +private: + int m_nDETAILTEXTURE; +#ifdef _DEBUG + bool m_bDETAILTEXTURE; +#endif +public: + void SetDETAILTEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDETAILTEXTURE = i; +#ifdef _DEBUG + m_bDETAILTEXTURE = true; +#endif + } + void SetDETAILTEXTURE( bool i ) + { + m_nDETAILTEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bDETAILTEXTURE = true; +#endif + } +private: + int m_nBUMPMAP; +#ifdef _DEBUG + bool m_bBUMPMAP; +#endif +public: + void SetBUMPMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBUMPMAP = i; +#ifdef _DEBUG + m_bBUMPMAP = true; +#endif + } + void SetBUMPMAP( bool i ) + { + m_nBUMPMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bBUMPMAP = true; +#endif + } +private: + int m_nVERTEXCOLOR; +#ifdef _DEBUG + bool m_bVERTEXCOLOR; +#endif +public: + void SetVERTEXCOLOR( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nVERTEXCOLOR = i; +#ifdef _DEBUG + m_bVERTEXCOLOR = true; +#endif + } + void SetVERTEXCOLOR( bool i ) + { + m_nVERTEXCOLOR = i ? 1 : 0; +#ifdef _DEBUG + m_bVERTEXCOLOR = true; +#endif + } +private: + int m_nSELFILLUM; +#ifdef _DEBUG + bool m_bSELFILLUM; +#endif +public: + void SetSELFILLUM( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSELFILLUM = i; +#ifdef _DEBUG + m_bSELFILLUM = true; +#endif + } + void SetSELFILLUM( bool i ) + { + m_nSELFILLUM = i ? 1 : 0; +#ifdef _DEBUG + m_bSELFILLUM = true; +#endif + } +private: + int m_nDIFFUSEBUMPMAP; +#ifdef _DEBUG + bool m_bDIFFUSEBUMPMAP; +#endif +public: + void SetDIFFUSEBUMPMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDIFFUSEBUMPMAP = i; +#ifdef _DEBUG + m_bDIFFUSEBUMPMAP = true; +#endif + } + void SetDIFFUSEBUMPMAP( bool i ) + { + m_nDIFFUSEBUMPMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bDIFFUSEBUMPMAP = true; +#endif + } +private: + int m_nDETAIL_ALPHA_MASK_BASE_TEXTURE; +#ifdef _DEBUG + bool m_bDETAIL_ALPHA_MASK_BASE_TEXTURE; +#endif +public: + void SetDETAIL_ALPHA_MASK_BASE_TEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDETAIL_ALPHA_MASK_BASE_TEXTURE = i; +#ifdef _DEBUG + m_bDETAIL_ALPHA_MASK_BASE_TEXTURE = true; +#endif + } + void SetDETAIL_ALPHA_MASK_BASE_TEXTURE( bool i ) + { + m_nDETAIL_ALPHA_MASK_BASE_TEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bDETAIL_ALPHA_MASK_BASE_TEXTURE = true; +#endif + } +private: + int m_nFLASHLIGHT; +#ifdef _DEBUG + bool m_bFLASHLIGHT; +#endif +public: + void SetFLASHLIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFLASHLIGHT = i; +#ifdef _DEBUG + m_bFLASHLIGHT = true; +#endif + } + void SetFLASHLIGHT( bool i ) + { + m_nFLASHLIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bFLASHLIGHT = true; +#endif + } +private: + int m_nSEAMLESS; +#ifdef _DEBUG + bool m_bSEAMLESS; +#endif +public: + void SetSEAMLESS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSEAMLESS = i; +#ifdef _DEBUG + m_bSEAMLESS = true; +#endif + } + void SetSEAMLESS( bool i ) + { + m_nSEAMLESS = i ? 1 : 0; +#ifdef _DEBUG + m_bSEAMLESS = true; +#endif + } +public: + worldtwotextureblend_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; +#ifdef _DEBUG + m_bDETAILTEXTURE = false; +#endif // _DEBUG + m_nDETAILTEXTURE = 0; +#ifdef _DEBUG + m_bBUMPMAP = false; +#endif // _DEBUG + m_nBUMPMAP = 0; +#ifdef _DEBUG + m_bVERTEXCOLOR = false; +#endif // _DEBUG + m_nVERTEXCOLOR = 0; +#ifdef _DEBUG + m_bSELFILLUM = false; +#endif // _DEBUG + m_nSELFILLUM = 0; +#ifdef _DEBUG + m_bDIFFUSEBUMPMAP = false; +#endif // _DEBUG + m_nDIFFUSEBUMPMAP = 0; +#ifdef _DEBUG + m_bDETAIL_ALPHA_MASK_BASE_TEXTURE = false; +#endif // _DEBUG + m_nDETAIL_ALPHA_MASK_BASE_TEXTURE = 0; +#ifdef _DEBUG + m_bFLASHLIGHT = false; +#endif // _DEBUG + m_nFLASHLIGHT = 0; +#ifdef _DEBUG + m_bSEAMLESS = false; +#endif // _DEBUG + m_nSEAMLESS = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB && m_bDETAILTEXTURE && m_bBUMPMAP && m_bVERTEXCOLOR && m_bSELFILLUM && m_bDIFFUSEBUMPMAP && m_bDETAIL_ALPHA_MASK_BASE_TEXTURE && m_bFLASHLIGHT && m_bSEAMLESS; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 4 * m_nCONVERT_TO_SRGB ) + ( 4 * m_nDETAILTEXTURE ) + ( 8 * m_nBUMPMAP ) + ( 16 * m_nVERTEXCOLOR ) + ( 32 * m_nSELFILLUM ) + ( 64 * m_nDIFFUSEBUMPMAP ) + ( 128 * m_nDETAIL_ALPHA_MASK_BASE_TEXTURE ) + ( 256 * m_nFLASHLIGHT ) + ( 512 * m_nSEAMLESS ) + 0; + } +}; +#define shaderStaticTest_worldtwotextureblend_ps20 psh_forgot_to_set_static_DETAILTEXTURE + psh_forgot_to_set_static_BUMPMAP + psh_forgot_to_set_static_VERTEXCOLOR + psh_forgot_to_set_static_SELFILLUM + psh_forgot_to_set_static_DIFFUSEBUMPMAP + psh_forgot_to_set_static_DETAIL_ALPHA_MASK_BASE_TEXTURE + psh_forgot_to_set_static_FLASHLIGHT + psh_forgot_to_set_static_SEAMLESS + 0 +class worldtwotextureblend_ps20_Dynamic_Index +{ +private: + int m_nWRITEWATERFOGTODESTALPHA; +#ifdef _DEBUG + bool m_bWRITEWATERFOGTODESTALPHA; +#endif +public: + void SetWRITEWATERFOGTODESTALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nWRITEWATERFOGTODESTALPHA = i; +#ifdef _DEBUG + m_bWRITEWATERFOGTODESTALPHA = true; +#endif + } + void SetWRITEWATERFOGTODESTALPHA( bool i ) + { + m_nWRITEWATERFOGTODESTALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bWRITEWATERFOGTODESTALPHA = true; +#endif + } +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + worldtwotextureblend_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bWRITEWATERFOGTODESTALPHA = false; +#endif // _DEBUG + m_nWRITEWATERFOGTODESTALPHA = 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bWRITEWATERFOGTODESTALPHA && m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nWRITEWATERFOGTODESTALPHA ) + ( 2 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_worldtwotextureblend_ps20 psh_forgot_to_set_dynamic_WRITEWATERFOGTODESTALPHA + psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/WorldTwoTextureBlend_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/WorldTwoTextureBlend_ps20b.inc new file mode 100644 index 0000000..ef54bed --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/WorldTwoTextureBlend_ps20b.inc @@ -0,0 +1,387 @@ +#include "shaderlib/cshader.h" +class worldtwotextureblend_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +private: + int m_nDETAILTEXTURE; +#ifdef _DEBUG + bool m_bDETAILTEXTURE; +#endif +public: + void SetDETAILTEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDETAILTEXTURE = i; +#ifdef _DEBUG + m_bDETAILTEXTURE = true; +#endif + } + void SetDETAILTEXTURE( bool i ) + { + m_nDETAILTEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bDETAILTEXTURE = true; +#endif + } +private: + int m_nBUMPMAP; +#ifdef _DEBUG + bool m_bBUMPMAP; +#endif +public: + void SetBUMPMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBUMPMAP = i; +#ifdef _DEBUG + m_bBUMPMAP = true; +#endif + } + void SetBUMPMAP( bool i ) + { + m_nBUMPMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bBUMPMAP = true; +#endif + } +private: + int m_nVERTEXCOLOR; +#ifdef _DEBUG + bool m_bVERTEXCOLOR; +#endif +public: + void SetVERTEXCOLOR( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nVERTEXCOLOR = i; +#ifdef _DEBUG + m_bVERTEXCOLOR = true; +#endif + } + void SetVERTEXCOLOR( bool i ) + { + m_nVERTEXCOLOR = i ? 1 : 0; +#ifdef _DEBUG + m_bVERTEXCOLOR = true; +#endif + } +private: + int m_nSELFILLUM; +#ifdef _DEBUG + bool m_bSELFILLUM; +#endif +public: + void SetSELFILLUM( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSELFILLUM = i; +#ifdef _DEBUG + m_bSELFILLUM = true; +#endif + } + void SetSELFILLUM( bool i ) + { + m_nSELFILLUM = i ? 1 : 0; +#ifdef _DEBUG + m_bSELFILLUM = true; +#endif + } +private: + int m_nDIFFUSEBUMPMAP; +#ifdef _DEBUG + bool m_bDIFFUSEBUMPMAP; +#endif +public: + void SetDIFFUSEBUMPMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDIFFUSEBUMPMAP = i; +#ifdef _DEBUG + m_bDIFFUSEBUMPMAP = true; +#endif + } + void SetDIFFUSEBUMPMAP( bool i ) + { + m_nDIFFUSEBUMPMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bDIFFUSEBUMPMAP = true; +#endif + } +private: + int m_nDETAIL_ALPHA_MASK_BASE_TEXTURE; +#ifdef _DEBUG + bool m_bDETAIL_ALPHA_MASK_BASE_TEXTURE; +#endif +public: + void SetDETAIL_ALPHA_MASK_BASE_TEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDETAIL_ALPHA_MASK_BASE_TEXTURE = i; +#ifdef _DEBUG + m_bDETAIL_ALPHA_MASK_BASE_TEXTURE = true; +#endif + } + void SetDETAIL_ALPHA_MASK_BASE_TEXTURE( bool i ) + { + m_nDETAIL_ALPHA_MASK_BASE_TEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bDETAIL_ALPHA_MASK_BASE_TEXTURE = true; +#endif + } +private: + int m_nFLASHLIGHT; +#ifdef _DEBUG + bool m_bFLASHLIGHT; +#endif +public: + void SetFLASHLIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFLASHLIGHT = i; +#ifdef _DEBUG + m_bFLASHLIGHT = true; +#endif + } + void SetFLASHLIGHT( bool i ) + { + m_nFLASHLIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bFLASHLIGHT = true; +#endif + } +private: + int m_nSEAMLESS; +#ifdef _DEBUG + bool m_bSEAMLESS; +#endif +public: + void SetSEAMLESS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSEAMLESS = i; +#ifdef _DEBUG + m_bSEAMLESS = true; +#endif + } + void SetSEAMLESS( bool i ) + { + m_nSEAMLESS = i ? 1 : 0; +#ifdef _DEBUG + m_bSEAMLESS = true; +#endif + } +private: + int m_nFLASHLIGHTDEPTHFILTERMODE; +#ifdef _DEBUG + bool m_bFLASHLIGHTDEPTHFILTERMODE; +#endif +public: + void SetFLASHLIGHTDEPTHFILTERMODE( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nFLASHLIGHTDEPTHFILTERMODE = i; +#ifdef _DEBUG + m_bFLASHLIGHTDEPTHFILTERMODE = true; +#endif + } + void SetFLASHLIGHTDEPTHFILTERMODE( bool i ) + { + m_nFLASHLIGHTDEPTHFILTERMODE = i ? 1 : 0; +#ifdef _DEBUG + m_bFLASHLIGHTDEPTHFILTERMODE = true; +#endif + } +public: + worldtwotextureblend_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; +#ifdef _DEBUG + m_bDETAILTEXTURE = false; +#endif // _DEBUG + m_nDETAILTEXTURE = 0; +#ifdef _DEBUG + m_bBUMPMAP = false; +#endif // _DEBUG + m_nBUMPMAP = 0; +#ifdef _DEBUG + m_bVERTEXCOLOR = false; +#endif // _DEBUG + m_nVERTEXCOLOR = 0; +#ifdef _DEBUG + m_bSELFILLUM = false; +#endif // _DEBUG + m_nSELFILLUM = 0; +#ifdef _DEBUG + m_bDIFFUSEBUMPMAP = false; +#endif // _DEBUG + m_nDIFFUSEBUMPMAP = 0; +#ifdef _DEBUG + m_bDETAIL_ALPHA_MASK_BASE_TEXTURE = false; +#endif // _DEBUG + m_nDETAIL_ALPHA_MASK_BASE_TEXTURE = 0; +#ifdef _DEBUG + m_bFLASHLIGHT = false; +#endif // _DEBUG + m_nFLASHLIGHT = 0; +#ifdef _DEBUG + m_bSEAMLESS = false; +#endif // _DEBUG + m_nSEAMLESS = 0; +#ifdef _DEBUG + m_bFLASHLIGHTDEPTHFILTERMODE = false; +#endif // _DEBUG + m_nFLASHLIGHTDEPTHFILTERMODE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB && m_bDETAILTEXTURE && m_bBUMPMAP && m_bVERTEXCOLOR && m_bSELFILLUM && m_bDIFFUSEBUMPMAP && m_bDETAIL_ALPHA_MASK_BASE_TEXTURE && m_bFLASHLIGHT && m_bSEAMLESS && m_bFLASHLIGHTDEPTHFILTERMODE; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 8 * m_nCONVERT_TO_SRGB ) + ( 8 * m_nDETAILTEXTURE ) + ( 16 * m_nBUMPMAP ) + ( 32 * m_nVERTEXCOLOR ) + ( 64 * m_nSELFILLUM ) + ( 128 * m_nDIFFUSEBUMPMAP ) + ( 256 * m_nDETAIL_ALPHA_MASK_BASE_TEXTURE ) + ( 512 * m_nFLASHLIGHT ) + ( 1024 * m_nSEAMLESS ) + ( 2048 * m_nFLASHLIGHTDEPTHFILTERMODE ) + 0; + } +}; +#define shaderStaticTest_worldtwotextureblend_ps20b psh_forgot_to_set_static_DETAILTEXTURE + psh_forgot_to_set_static_BUMPMAP + psh_forgot_to_set_static_VERTEXCOLOR + psh_forgot_to_set_static_SELFILLUM + psh_forgot_to_set_static_DIFFUSEBUMPMAP + psh_forgot_to_set_static_DETAIL_ALPHA_MASK_BASE_TEXTURE + psh_forgot_to_set_static_FLASHLIGHT + psh_forgot_to_set_static_SEAMLESS + psh_forgot_to_set_static_FLASHLIGHTDEPTHFILTERMODE + 0 +class worldtwotextureblend_ps20b_Dynamic_Index +{ +private: + int m_nWRITEWATERFOGTODESTALPHA; +#ifdef _DEBUG + bool m_bWRITEWATERFOGTODESTALPHA; +#endif +public: + void SetWRITEWATERFOGTODESTALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nWRITEWATERFOGTODESTALPHA = i; +#ifdef _DEBUG + m_bWRITEWATERFOGTODESTALPHA = true; +#endif + } + void SetWRITEWATERFOGTODESTALPHA( bool i ) + { + m_nWRITEWATERFOGTODESTALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bWRITEWATERFOGTODESTALPHA = true; +#endif + } +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +private: + int m_nWRITE_DEPTH_TO_DESTALPHA; +#ifdef _DEBUG + bool m_bWRITE_DEPTH_TO_DESTALPHA; +#endif +public: + void SetWRITE_DEPTH_TO_DESTALPHA( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nWRITE_DEPTH_TO_DESTALPHA = i; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = true; +#endif + } + void SetWRITE_DEPTH_TO_DESTALPHA( bool i ) + { + m_nWRITE_DEPTH_TO_DESTALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = true; +#endif + } +private: + int m_nFLASHLIGHTSHADOWS; +#ifdef _DEBUG + bool m_bFLASHLIGHTSHADOWS; +#endif +public: + void SetFLASHLIGHTSHADOWS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFLASHLIGHTSHADOWS = i; +#ifdef _DEBUG + m_bFLASHLIGHTSHADOWS = true; +#endif + } + void SetFLASHLIGHTSHADOWS( bool i ) + { + m_nFLASHLIGHTSHADOWS = i ? 1 : 0; +#ifdef _DEBUG + m_bFLASHLIGHTSHADOWS = true; +#endif + } +public: + worldtwotextureblend_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bWRITEWATERFOGTODESTALPHA = false; +#endif // _DEBUG + m_nWRITEWATERFOGTODESTALPHA = 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = false; +#endif // _DEBUG + m_nWRITE_DEPTH_TO_DESTALPHA = 0; +#ifdef _DEBUG + m_bFLASHLIGHTSHADOWS = false; +#endif // _DEBUG + m_nFLASHLIGHTSHADOWS = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bWRITEWATERFOGTODESTALPHA && m_bPIXELFOGTYPE && m_bWRITE_DEPTH_TO_DESTALPHA && m_bFLASHLIGHTSHADOWS; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nWRITEWATERFOGTODESTALPHA ) + ( 2 * m_nPIXELFOGTYPE ) + ( 4 * m_nWRITE_DEPTH_TO_DESTALPHA ) + ( 4 * m_nFLASHLIGHTSHADOWS ) + 0; + } +}; +#define shaderDynamicTest_worldtwotextureblend_ps20b psh_forgot_to_set_dynamic_WRITEWATERFOGTODESTALPHA + psh_forgot_to_set_dynamic_PIXELFOGTYPE + psh_forgot_to_set_dynamic_WRITE_DEPTH_TO_DESTALPHA + psh_forgot_to_set_dynamic_FLASHLIGHTSHADOWS + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/accumbuff4sample_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/accumbuff4sample_ps20.inc new file mode 100644 index 0000000..df7a007 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/accumbuff4sample_ps20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class accumbuff4sample_ps20_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + accumbuff4sample_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_accumbuff4sample_ps20 0 +class accumbuff4sample_ps20_Dynamic_Index +{ +public: + accumbuff4sample_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_accumbuff4sample_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/accumbuff4sample_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/accumbuff4sample_ps20b.inc new file mode 100644 index 0000000..1326aad --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/accumbuff4sample_ps20b.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class accumbuff4sample_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + accumbuff4sample_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_accumbuff4sample_ps20b 0 +class accumbuff4sample_ps20b_Dynamic_Index +{ +public: + accumbuff4sample_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_accumbuff4sample_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/accumbuff5sample_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/accumbuff5sample_ps20.inc new file mode 100644 index 0000000..f82f243 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/accumbuff5sample_ps20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class accumbuff5sample_ps20_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + accumbuff5sample_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_accumbuff5sample_ps20 0 +class accumbuff5sample_ps20_Dynamic_Index +{ +public: + accumbuff5sample_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_accumbuff5sample_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/accumbuff5sample_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/accumbuff5sample_ps20b.inc new file mode 100644 index 0000000..7095544 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/accumbuff5sample_ps20b.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class accumbuff5sample_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + accumbuff5sample_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_accumbuff5sample_ps20b 0 +class accumbuff5sample_ps20b_Dynamic_Index +{ +public: + accumbuff5sample_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_accumbuff5sample_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/aftershock_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/aftershock_ps20.inc new file mode 100644 index 0000000..36ef2e7 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/aftershock_ps20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class aftershock_ps20_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + aftershock_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_aftershock_ps20 0 +class aftershock_ps20_Dynamic_Index +{ +public: + aftershock_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_aftershock_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/aftershock_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/aftershock_ps20b.inc new file mode 100644 index 0000000..135b914 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/aftershock_ps20b.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class aftershock_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + aftershock_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_aftershock_ps20b 0 +class aftershock_ps20b_Dynamic_Index +{ +public: + aftershock_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_aftershock_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/aftershock_vs20.inc b/materialsystem/stdshaders/fxctmp9_360/aftershock_vs20.inc new file mode 100644 index 0000000..9461ece --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/aftershock_vs20.inc @@ -0,0 +1,85 @@ +#include "shaderlib/cshader.h" +class aftershock_vs20_Static_Index +{ +public: + aftershock_vs20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_aftershock_vs20 0 +class aftershock_vs20_Dynamic_Index +{ +private: + int m_nCOMPRESSED_VERTS; +#ifdef _DEBUG + bool m_bCOMPRESSED_VERTS; +#endif +public: + void SetCOMPRESSED_VERTS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOMPRESSED_VERTS = i; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } + void SetCOMPRESSED_VERTS( bool i ) + { + m_nCOMPRESSED_VERTS = i ? 1 : 0; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +public: + aftershock_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = false; +#endif // _DEBUG + m_nCOMPRESSED_VERTS = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bCOMPRESSED_VERTS && m_bSKINNING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCOMPRESSED_VERTS ) + ( 2 * m_nSKINNING ) + 0; + } +}; +#define shaderDynamicTest_aftershock_vs20 vsh_forgot_to_set_dynamic_COMPRESSED_VERTS + vsh_forgot_to_set_dynamic_SKINNING + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/alphadist_ps11.inc b/materialsystem/stdshaders/fxctmp9_360/alphadist_ps11.inc new file mode 100644 index 0000000..5ee1d3e --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/alphadist_ps11.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class alphadist_ps11_Static_Index +{ +public: + alphadist_ps11_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_alphadist_ps11 0 +class alphadist_ps11_Dynamic_Index +{ +public: + alphadist_ps11_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_alphadist_ps11 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/appchooser360movie_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/appchooser360movie_ps20.inc new file mode 100644 index 0000000..2f10670 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/appchooser360movie_ps20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class appchooser360movie_ps20_Static_Index +{ +public: + appchooser360movie_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_appchooser360movie_ps20 0 +class appchooser360movie_ps20_Dynamic_Index +{ +public: + appchooser360movie_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_appchooser360movie_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/appchooser360movie_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/appchooser360movie_ps20b.inc new file mode 100644 index 0000000..41ab35e --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/appchooser360movie_ps20b.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class appchooser360movie_ps20b_Static_Index +{ +public: + appchooser360movie_ps20b_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_appchooser360movie_ps20b 0 +class appchooser360movie_ps20b_Dynamic_Index +{ +public: + appchooser360movie_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_appchooser360movie_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/bik_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/bik_ps20.inc new file mode 100644 index 0000000..ec8dc4d --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/bik_ps20.inc @@ -0,0 +1,87 @@ +#include "shaderlib/cshader.h" +class bik_ps20_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + bik_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_bik_ps20 0 +class bik_ps20_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + bik_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_bik_ps20 psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/bik_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/bik_ps20b.inc new file mode 100644 index 0000000..083032f --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/bik_ps20b.inc @@ -0,0 +1,87 @@ +#include "shaderlib/cshader.h" +class bik_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + bik_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_bik_ps20b 0 +class bik_ps20b_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + bik_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_bik_ps20b psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/bik_vs20.inc b/materialsystem/stdshaders/fxctmp9_360/bik_vs20.inc new file mode 100644 index 0000000..1c1673a --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/bik_vs20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class bik_vs20_Static_Index +{ +public: + bik_vs20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_bik_vs20 0 +class bik_vs20_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + bik_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; +#define shaderDynamicTest_bik_vs20 vsh_forgot_to_set_dynamic_DOWATERFOG + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/bloomadd_ps11.inc b/materialsystem/stdshaders/fxctmp9_360/bloomadd_ps11.inc new file mode 100644 index 0000000..5452dee --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/bloomadd_ps11.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class bloomadd_ps11_Static_Index +{ +public: + bloomadd_ps11_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_bloomadd_ps11 0 +class bloomadd_ps11_Dynamic_Index +{ +public: + bloomadd_ps11_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_bloomadd_ps11 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/bloomadd_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/bloomadd_ps20.inc new file mode 100644 index 0000000..031c6dd --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/bloomadd_ps20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class bloomadd_ps20_Static_Index +{ +public: + bloomadd_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_bloomadd_ps20 0 +class bloomadd_ps20_Dynamic_Index +{ +public: + bloomadd_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_bloomadd_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/bloomadd_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/bloomadd_ps20b.inc new file mode 100644 index 0000000..686a62e --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/bloomadd_ps20b.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class bloomadd_ps20b_Static_Index +{ +public: + bloomadd_ps20b_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_bloomadd_ps20b 0 +class bloomadd_ps20b_Dynamic_Index +{ +public: + bloomadd_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_bloomadd_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/bufferclearobeystencil_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/bufferclearobeystencil_ps20.inc new file mode 100644 index 0000000..3e5a32f --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/bufferclearobeystencil_ps20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class bufferclearobeystencil_ps20_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + bufferclearobeystencil_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_bufferclearobeystencil_ps20 0 +class bufferclearobeystencil_ps20_Dynamic_Index +{ +public: + bufferclearobeystencil_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_bufferclearobeystencil_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/bufferclearobeystencil_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/bufferclearobeystencil_ps20b.inc new file mode 100644 index 0000000..6f3cfd2 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/bufferclearobeystencil_ps20b.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class bufferclearobeystencil_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + bufferclearobeystencil_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_bufferclearobeystencil_ps20b 0 +class bufferclearobeystencil_ps20b_Dynamic_Index +{ +public: + bufferclearobeystencil_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_bufferclearobeystencil_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/bufferclearobeystencil_vs20.inc b/materialsystem/stdshaders/fxctmp9_360/bufferclearobeystencil_vs20.inc new file mode 100644 index 0000000..ca2e245 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/bufferclearobeystencil_vs20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class bufferclearobeystencil_vs20_Static_Index +{ +private: + int m_nUSESCOLOR; +#ifdef _DEBUG + bool m_bUSESCOLOR; +#endif +public: + void SetUSESCOLOR( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nUSESCOLOR = i; +#ifdef _DEBUG + m_bUSESCOLOR = true; +#endif + } + void SetUSESCOLOR( bool i ) + { + m_nUSESCOLOR = i ? 1 : 0; +#ifdef _DEBUG + m_bUSESCOLOR = true; +#endif + } +public: + bufferclearobeystencil_vs20_Static_Index( ) + { +#ifdef _DEBUG + m_bUSESCOLOR = false; +#endif // _DEBUG + m_nUSESCOLOR = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bUSESCOLOR; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nUSESCOLOR ) + 0; + } +}; +#define shaderStaticTest_bufferclearobeystencil_vs20 vsh_forgot_to_set_static_USESCOLOR + 0 +class bufferclearobeystencil_vs20_Dynamic_Index +{ +public: + bufferclearobeystencil_vs20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_bufferclearobeystencil_vs20 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/bumpmappedlightmap_vs11.inc b/materialsystem/stdshaders/fxctmp9_360/bumpmappedlightmap_vs11.inc new file mode 100644 index 0000000..0b7b8bb --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/bumpmappedlightmap_vs11.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class bumpmappedlightmap_vs11_Static_Index +{ +public: + bumpmappedlightmap_vs11_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_bumpmappedlightmap_vs11 0 +class bumpmappedlightmap_vs11_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + bumpmappedlightmap_vs11_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; +#define shaderDynamicTest_bumpmappedlightmap_vs11 vsh_forgot_to_set_dynamic_DOWATERFOG + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/cable_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/cable_ps20.inc new file mode 100644 index 0000000..35c7e4f --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/cable_ps20.inc @@ -0,0 +1,87 @@ +#include "shaderlib/cshader.h" +class cable_ps20_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + cable_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_cable_ps20 0 +class cable_ps20_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + cable_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_cable_ps20 psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/cable_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/cable_ps20b.inc new file mode 100644 index 0000000..704b799 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/cable_ps20b.inc @@ -0,0 +1,112 @@ +#include "shaderlib/cshader.h" +class cable_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + cable_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_cable_ps20b 0 +class cable_ps20b_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +private: + int m_nWRITE_DEPTH_TO_DESTALPHA; +#ifdef _DEBUG + bool m_bWRITE_DEPTH_TO_DESTALPHA; +#endif +public: + void SetWRITE_DEPTH_TO_DESTALPHA( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nWRITE_DEPTH_TO_DESTALPHA = i; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = true; +#endif + } + void SetWRITE_DEPTH_TO_DESTALPHA( bool i ) + { + m_nWRITE_DEPTH_TO_DESTALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = true; +#endif + } +public: + cable_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = false; +#endif // _DEBUG + m_nWRITE_DEPTH_TO_DESTALPHA = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE && m_bWRITE_DEPTH_TO_DESTALPHA; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + ( 2 * m_nWRITE_DEPTH_TO_DESTALPHA ) + 0; + } +}; +#define shaderDynamicTest_cable_ps20b psh_forgot_to_set_dynamic_PIXELFOGTYPE + psh_forgot_to_set_dynamic_WRITE_DEPTH_TO_DESTALPHA + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/cable_vs20.inc b/materialsystem/stdshaders/fxctmp9_360/cable_vs20.inc new file mode 100644 index 0000000..832a15e --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/cable_vs20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class cable_vs20_Static_Index +{ +public: + cable_vs20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_cable_vs20 0 +class cable_vs20_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + cable_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; +#define shaderDynamicTest_cable_vs20 vsh_forgot_to_set_dynamic_DOWATERFOG + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/cloak_blended_pass_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/cloak_blended_pass_ps20.inc new file mode 100644 index 0000000..279b574 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/cloak_blended_pass_ps20.inc @@ -0,0 +1,85 @@ +#include "shaderlib/cshader.h" +class cloak_blended_pass_ps20_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +private: + int m_nBUMPMAP; +#ifdef _DEBUG + bool m_bBUMPMAP; +#endif +public: + void SetBUMPMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBUMPMAP = i; +#ifdef _DEBUG + m_bBUMPMAP = true; +#endif + } + void SetBUMPMAP( bool i ) + { + m_nBUMPMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bBUMPMAP = true; +#endif + } +public: + cloak_blended_pass_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; +#ifdef _DEBUG + m_bBUMPMAP = false; +#endif // _DEBUG + m_nBUMPMAP = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB && m_bBUMPMAP; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + ( 1 * m_nBUMPMAP ) + 0; + } +}; +#define shaderStaticTest_cloak_blended_pass_ps20 psh_forgot_to_set_static_BUMPMAP + 0 +class cloak_blended_pass_ps20_Dynamic_Index +{ +public: + cloak_blended_pass_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_cloak_blended_pass_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/cloak_blended_pass_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/cloak_blended_pass_ps20b.inc new file mode 100644 index 0000000..d295c98 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/cloak_blended_pass_ps20b.inc @@ -0,0 +1,85 @@ +#include "shaderlib/cshader.h" +class cloak_blended_pass_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +private: + int m_nBUMPMAP; +#ifdef _DEBUG + bool m_bBUMPMAP; +#endif +public: + void SetBUMPMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBUMPMAP = i; +#ifdef _DEBUG + m_bBUMPMAP = true; +#endif + } + void SetBUMPMAP( bool i ) + { + m_nBUMPMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bBUMPMAP = true; +#endif + } +public: + cloak_blended_pass_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; +#ifdef _DEBUG + m_bBUMPMAP = false; +#endif // _DEBUG + m_nBUMPMAP = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB && m_bBUMPMAP; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + ( 1 * m_nBUMPMAP ) + 0; + } +}; +#define shaderStaticTest_cloak_blended_pass_ps20b psh_forgot_to_set_static_BUMPMAP + 0 +class cloak_blended_pass_ps20b_Dynamic_Index +{ +public: + cloak_blended_pass_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_cloak_blended_pass_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/cloak_blended_pass_vs20.inc b/materialsystem/stdshaders/fxctmp9_360/cloak_blended_pass_vs20.inc new file mode 100644 index 0000000..6f6f504 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/cloak_blended_pass_vs20.inc @@ -0,0 +1,112 @@ +#include "shaderlib/cshader.h" +class cloak_blended_pass_vs20_Static_Index +{ +private: + int m_nBUMPMAP; +#ifdef _DEBUG + bool m_bBUMPMAP; +#endif +public: + void SetBUMPMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBUMPMAP = i; +#ifdef _DEBUG + m_bBUMPMAP = true; +#endif + } + void SetBUMPMAP( bool i ) + { + m_nBUMPMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bBUMPMAP = true; +#endif + } +public: + cloak_blended_pass_vs20_Static_Index( ) + { +#ifdef _DEBUG + m_bBUMPMAP = false; +#endif // _DEBUG + m_nBUMPMAP = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bBUMPMAP; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 4 * m_nBUMPMAP ) + 0; + } +}; +#define shaderStaticTest_cloak_blended_pass_vs20 vsh_forgot_to_set_static_BUMPMAP + 0 +class cloak_blended_pass_vs20_Dynamic_Index +{ +private: + int m_nCOMPRESSED_VERTS; +#ifdef _DEBUG + bool m_bCOMPRESSED_VERTS; +#endif +public: + void SetCOMPRESSED_VERTS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOMPRESSED_VERTS = i; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } + void SetCOMPRESSED_VERTS( bool i ) + { + m_nCOMPRESSED_VERTS = i ? 1 : 0; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +public: + cloak_blended_pass_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = false; +#endif // _DEBUG + m_nCOMPRESSED_VERTS = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bCOMPRESSED_VERTS && m_bSKINNING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCOMPRESSED_VERTS ) + ( 2 * m_nSKINNING ) + 0; + } +}; +#define shaderDynamicTest_cloak_blended_pass_vs20 vsh_forgot_to_set_dynamic_COMPRESSED_VERTS + vsh_forgot_to_set_dynamic_SKINNING + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/cloak_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/cloak_ps20.inc new file mode 100644 index 0000000..38a4ae9 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/cloak_ps20.inc @@ -0,0 +1,162 @@ +#include "shaderlib/cshader.h" +class cloak_ps20_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +private: + int m_nLIGHTWARPTEXTURE; +#ifdef _DEBUG + bool m_bLIGHTWARPTEXTURE; +#endif +public: + void SetLIGHTWARPTEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nLIGHTWARPTEXTURE = i; +#ifdef _DEBUG + m_bLIGHTWARPTEXTURE = true; +#endif + } + void SetLIGHTWARPTEXTURE( bool i ) + { + m_nLIGHTWARPTEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bLIGHTWARPTEXTURE = true; +#endif + } +public: + cloak_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; +#ifdef _DEBUG + m_bLIGHTWARPTEXTURE = false; +#endif // _DEBUG + m_nLIGHTWARPTEXTURE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB && m_bLIGHTWARPTEXTURE; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 12 * m_nCONVERT_TO_SRGB ) + ( 12 * m_nLIGHTWARPTEXTURE ) + 0; + } +}; +#define shaderStaticTest_cloak_ps20 psh_forgot_to_set_static_LIGHTWARPTEXTURE + 0 +class cloak_ps20_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +private: + int m_nWRITEWATERFOGTODESTALPHA; +#ifdef _DEBUG + bool m_bWRITEWATERFOGTODESTALPHA; +#endif +public: + void SetWRITEWATERFOGTODESTALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nWRITEWATERFOGTODESTALPHA = i; +#ifdef _DEBUG + m_bWRITEWATERFOGTODESTALPHA = true; +#endif + } + void SetWRITEWATERFOGTODESTALPHA( bool i ) + { + m_nWRITEWATERFOGTODESTALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bWRITEWATERFOGTODESTALPHA = true; +#endif + } +private: + int m_nNUM_LIGHTS; +#ifdef _DEBUG + bool m_bNUM_LIGHTS; +#endif +public: + void SetNUM_LIGHTS( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nNUM_LIGHTS = i; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } + void SetNUM_LIGHTS( bool i ) + { + m_nNUM_LIGHTS = i ? 1 : 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } +public: + cloak_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; +#ifdef _DEBUG + m_bWRITEWATERFOGTODESTALPHA = false; +#endif // _DEBUG + m_nWRITEWATERFOGTODESTALPHA = 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = false; +#endif // _DEBUG + m_nNUM_LIGHTS = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE && m_bWRITEWATERFOGTODESTALPHA && m_bNUM_LIGHTS; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + ( 2 * m_nWRITEWATERFOGTODESTALPHA ) + ( 4 * m_nNUM_LIGHTS ) + 0; + } +}; +#define shaderDynamicTest_cloak_ps20 psh_forgot_to_set_dynamic_PIXELFOGTYPE + psh_forgot_to_set_dynamic_WRITEWATERFOGTODESTALPHA + psh_forgot_to_set_dynamic_NUM_LIGHTS + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/cloak_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/cloak_ps20b.inc new file mode 100644 index 0000000..175c0a0 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/cloak_ps20b.inc @@ -0,0 +1,162 @@ +#include "shaderlib/cshader.h" +class cloak_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +private: + int m_nLIGHTWARPTEXTURE; +#ifdef _DEBUG + bool m_bLIGHTWARPTEXTURE; +#endif +public: + void SetLIGHTWARPTEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nLIGHTWARPTEXTURE = i; +#ifdef _DEBUG + m_bLIGHTWARPTEXTURE = true; +#endif + } + void SetLIGHTWARPTEXTURE( bool i ) + { + m_nLIGHTWARPTEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bLIGHTWARPTEXTURE = true; +#endif + } +public: + cloak_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; +#ifdef _DEBUG + m_bLIGHTWARPTEXTURE = false; +#endif // _DEBUG + m_nLIGHTWARPTEXTURE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB && m_bLIGHTWARPTEXTURE; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 20 * m_nCONVERT_TO_SRGB ) + ( 20 * m_nLIGHTWARPTEXTURE ) + 0; + } +}; +#define shaderStaticTest_cloak_ps20b psh_forgot_to_set_static_LIGHTWARPTEXTURE + 0 +class cloak_ps20b_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +private: + int m_nWRITEWATERFOGTODESTALPHA; +#ifdef _DEBUG + bool m_bWRITEWATERFOGTODESTALPHA; +#endif +public: + void SetWRITEWATERFOGTODESTALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nWRITEWATERFOGTODESTALPHA = i; +#ifdef _DEBUG + m_bWRITEWATERFOGTODESTALPHA = true; +#endif + } + void SetWRITEWATERFOGTODESTALPHA( bool i ) + { + m_nWRITEWATERFOGTODESTALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bWRITEWATERFOGTODESTALPHA = true; +#endif + } +private: + int m_nNUM_LIGHTS; +#ifdef _DEBUG + bool m_bNUM_LIGHTS; +#endif +public: + void SetNUM_LIGHTS( int i ) + { + Assert( i >= 0 && i <= 4 ); + m_nNUM_LIGHTS = i; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } + void SetNUM_LIGHTS( bool i ) + { + m_nNUM_LIGHTS = i ? 1 : 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } +public: + cloak_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; +#ifdef _DEBUG + m_bWRITEWATERFOGTODESTALPHA = false; +#endif // _DEBUG + m_nWRITEWATERFOGTODESTALPHA = 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = false; +#endif // _DEBUG + m_nNUM_LIGHTS = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE && m_bWRITEWATERFOGTODESTALPHA && m_bNUM_LIGHTS; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + ( 2 * m_nWRITEWATERFOGTODESTALPHA ) + ( 4 * m_nNUM_LIGHTS ) + 0; + } +}; +#define shaderDynamicTest_cloak_ps20b psh_forgot_to_set_dynamic_PIXELFOGTYPE + psh_forgot_to_set_dynamic_WRITEWATERFOGTODESTALPHA + psh_forgot_to_set_dynamic_NUM_LIGHTS + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/cloak_vs20.inc b/materialsystem/stdshaders/fxctmp9_360/cloak_vs20.inc new file mode 100644 index 0000000..6693832 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/cloak_vs20.inc @@ -0,0 +1,187 @@ +#include "shaderlib/cshader.h" +class cloak_vs20_Static_Index +{ +private: + int m_nMODEL; +#ifdef _DEBUG + bool m_bMODEL; +#endif +public: + void SetMODEL( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nMODEL = i; +#ifdef _DEBUG + m_bMODEL = true; +#endif + } + void SetMODEL( bool i ) + { + m_nMODEL = i ? 1 : 0; +#ifdef _DEBUG + m_bMODEL = true; +#endif + } +private: + int m_nUSE_STATIC_CONTROL_FLOW; +#ifdef _DEBUG + bool m_bUSE_STATIC_CONTROL_FLOW; +#endif +public: + void SetUSE_STATIC_CONTROL_FLOW( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nUSE_STATIC_CONTROL_FLOW = i; +#ifdef _DEBUG + m_bUSE_STATIC_CONTROL_FLOW = true; +#endif + } + void SetUSE_STATIC_CONTROL_FLOW( bool i ) + { + m_nUSE_STATIC_CONTROL_FLOW = i ? 1 : 0; +#ifdef _DEBUG + m_bUSE_STATIC_CONTROL_FLOW = true; +#endif + } +public: + cloak_vs20_Static_Index( ) + { +#ifdef _DEBUG + m_bMODEL = false; +#endif // _DEBUG + m_nMODEL = 0; +#ifdef _DEBUG + m_bUSE_STATIC_CONTROL_FLOW = false; +#endif // _DEBUG + m_nUSE_STATIC_CONTROL_FLOW = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bMODEL && m_bUSE_STATIC_CONTROL_FLOW; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 24 * m_nMODEL ) + ( 48 * m_nUSE_STATIC_CONTROL_FLOW ) + 0; + } +}; +#define shaderStaticTest_cloak_vs20 vsh_forgot_to_set_static_MODEL + vsh_forgot_to_set_static_USE_STATIC_CONTROL_FLOW + 0 +class cloak_vs20_Dynamic_Index +{ +private: + int m_nCOMPRESSED_VERTS; +#ifdef _DEBUG + bool m_bCOMPRESSED_VERTS; +#endif +public: + void SetCOMPRESSED_VERTS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOMPRESSED_VERTS = i; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } + void SetCOMPRESSED_VERTS( bool i ) + { + m_nCOMPRESSED_VERTS = i ? 1 : 0; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +private: + int m_nNUM_LIGHTS; +#ifdef _DEBUG + bool m_bNUM_LIGHTS; +#endif +public: + void SetNUM_LIGHTS( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nNUM_LIGHTS = i; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } + void SetNUM_LIGHTS( bool i ) + { + m_nNUM_LIGHTS = i ? 1 : 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } +public: + cloak_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = false; +#endif // _DEBUG + m_nCOMPRESSED_VERTS = 0; +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = false; +#endif // _DEBUG + m_nNUM_LIGHTS = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bCOMPRESSED_VERTS && m_bDOWATERFOG && m_bSKINNING && m_bNUM_LIGHTS; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCOMPRESSED_VERTS ) + ( 2 * m_nDOWATERFOG ) + ( 4 * m_nSKINNING ) + ( 8 * m_nNUM_LIGHTS ) + 0; + } +}; +#define shaderDynamicTest_cloak_vs20 vsh_forgot_to_set_dynamic_COMPRESSED_VERTS + vsh_forgot_to_set_dynamic_DOWATERFOG + vsh_forgot_to_set_dynamic_SKINNING + vsh_forgot_to_set_dynamic_NUM_LIGHTS + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/cloud_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/cloud_ps20.inc new file mode 100644 index 0000000..494bf27 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/cloud_ps20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class cloud_ps20_Static_Index +{ +public: + cloud_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_cloud_ps20 0 +class cloud_ps20_Dynamic_Index +{ +public: + cloud_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_cloud_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/cloud_vs20.inc b/materialsystem/stdshaders/fxctmp9_360/cloud_vs20.inc new file mode 100644 index 0000000..c285f87 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/cloud_vs20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class cloud_vs20_Static_Index +{ +public: + cloud_vs20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_cloud_vs20 0 +class cloud_vs20_Dynamic_Index +{ +public: + cloud_vs20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_cloud_vs20 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/color_projection_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/color_projection_ps20.inc new file mode 100644 index 0000000..be9ef5a --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/color_projection_ps20.inc @@ -0,0 +1,110 @@ +#include "shaderlib/cshader.h" +class color_projection_ps20_Static_Index +{ +public: + color_projection_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_color_projection_ps20 0 +class color_projection_ps20_Dynamic_Index +{ +private: + int m_nNEED_BLINDMK; +#ifdef _DEBUG + bool m_bNEED_BLINDMK; +#endif +public: + void SetNEED_BLINDMK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nNEED_BLINDMK = i; +#ifdef _DEBUG + m_bNEED_BLINDMK = true; +#endif + } + void SetNEED_BLINDMK( bool i ) + { + m_nNEED_BLINDMK = i ? 1 : 0; +#ifdef _DEBUG + m_bNEED_BLINDMK = true; +#endif + } +private: + int m_nNEED_ANOMYLIZE; +#ifdef _DEBUG + bool m_bNEED_ANOMYLIZE; +#endif +public: + void SetNEED_ANOMYLIZE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nNEED_ANOMYLIZE = i; +#ifdef _DEBUG + m_bNEED_ANOMYLIZE = true; +#endif + } + void SetNEED_ANOMYLIZE( bool i ) + { + m_nNEED_ANOMYLIZE = i ? 1 : 0; +#ifdef _DEBUG + m_bNEED_ANOMYLIZE = true; +#endif + } +private: + int m_nNEED_MONOCHROME; +#ifdef _DEBUG + bool m_bNEED_MONOCHROME; +#endif +public: + void SetNEED_MONOCHROME( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nNEED_MONOCHROME = i; +#ifdef _DEBUG + m_bNEED_MONOCHROME = true; +#endif + } + void SetNEED_MONOCHROME( bool i ) + { + m_nNEED_MONOCHROME = i ? 1 : 0; +#ifdef _DEBUG + m_bNEED_MONOCHROME = true; +#endif + } +public: + color_projection_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bNEED_BLINDMK = false; +#endif // _DEBUG + m_nNEED_BLINDMK = 0; +#ifdef _DEBUG + m_bNEED_ANOMYLIZE = false; +#endif // _DEBUG + m_nNEED_ANOMYLIZE = 0; +#ifdef _DEBUG + m_bNEED_MONOCHROME = false; +#endif // _DEBUG + m_nNEED_MONOCHROME = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bNEED_BLINDMK && m_bNEED_ANOMYLIZE && m_bNEED_MONOCHROME; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nNEED_BLINDMK ) + ( 2 * m_nNEED_ANOMYLIZE ) + ( 4 * m_nNEED_MONOCHROME ) + 0; + } +}; +#define shaderDynamicTest_color_projection_ps20 psh_forgot_to_set_dynamic_NEED_BLINDMK + psh_forgot_to_set_dynamic_NEED_ANOMYLIZE + psh_forgot_to_set_dynamic_NEED_MONOCHROME + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/color_projection_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/color_projection_ps20b.inc new file mode 100644 index 0000000..8aba230 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/color_projection_ps20b.inc @@ -0,0 +1,110 @@ +#include "shaderlib/cshader.h" +class color_projection_ps20b_Static_Index +{ +public: + color_projection_ps20b_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_color_projection_ps20b 0 +class color_projection_ps20b_Dynamic_Index +{ +private: + int m_nNEED_BLINDMK; +#ifdef _DEBUG + bool m_bNEED_BLINDMK; +#endif +public: + void SetNEED_BLINDMK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nNEED_BLINDMK = i; +#ifdef _DEBUG + m_bNEED_BLINDMK = true; +#endif + } + void SetNEED_BLINDMK( bool i ) + { + m_nNEED_BLINDMK = i ? 1 : 0; +#ifdef _DEBUG + m_bNEED_BLINDMK = true; +#endif + } +private: + int m_nNEED_ANOMYLIZE; +#ifdef _DEBUG + bool m_bNEED_ANOMYLIZE; +#endif +public: + void SetNEED_ANOMYLIZE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nNEED_ANOMYLIZE = i; +#ifdef _DEBUG + m_bNEED_ANOMYLIZE = true; +#endif + } + void SetNEED_ANOMYLIZE( bool i ) + { + m_nNEED_ANOMYLIZE = i ? 1 : 0; +#ifdef _DEBUG + m_bNEED_ANOMYLIZE = true; +#endif + } +private: + int m_nNEED_MONOCHROME; +#ifdef _DEBUG + bool m_bNEED_MONOCHROME; +#endif +public: + void SetNEED_MONOCHROME( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nNEED_MONOCHROME = i; +#ifdef _DEBUG + m_bNEED_MONOCHROME = true; +#endif + } + void SetNEED_MONOCHROME( bool i ) + { + m_nNEED_MONOCHROME = i ? 1 : 0; +#ifdef _DEBUG + m_bNEED_MONOCHROME = true; +#endif + } +public: + color_projection_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bNEED_BLINDMK = false; +#endif // _DEBUG + m_nNEED_BLINDMK = 0; +#ifdef _DEBUG + m_bNEED_ANOMYLIZE = false; +#endif // _DEBUG + m_nNEED_ANOMYLIZE = 0; +#ifdef _DEBUG + m_bNEED_MONOCHROME = false; +#endif // _DEBUG + m_nNEED_MONOCHROME = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bNEED_BLINDMK && m_bNEED_ANOMYLIZE && m_bNEED_MONOCHROME; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nNEED_BLINDMK ) + ( 2 * m_nNEED_ANOMYLIZE ) + ( 4 * m_nNEED_MONOCHROME ) + 0; + } +}; +#define shaderDynamicTest_color_projection_ps20b psh_forgot_to_set_dynamic_NEED_BLINDMK + psh_forgot_to_set_dynamic_NEED_ANOMYLIZE + psh_forgot_to_set_dynamic_NEED_MONOCHROME + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/color_projection_vs20.inc b/materialsystem/stdshaders/fxctmp9_360/color_projection_vs20.inc new file mode 100644 index 0000000..cb49b23 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/color_projection_vs20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class color_projection_vs20_Static_Index +{ +public: + color_projection_vs20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_color_projection_vs20 0 +class color_projection_vs20_Dynamic_Index +{ +public: + color_projection_vs20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_color_projection_vs20 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/colorcorrection_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/colorcorrection_ps20.inc new file mode 100644 index 0000000..820009f --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/colorcorrection_ps20.inc @@ -0,0 +1,87 @@ +#include "shaderlib/cshader.h" +class colorcorrection_ps20_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + colorcorrection_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 5 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_colorcorrection_ps20 0 +class colorcorrection_ps20_Dynamic_Index +{ +private: + int m_nNUM_LOOKUPS; +#ifdef _DEBUG + bool m_bNUM_LOOKUPS; +#endif +public: + void SetNUM_LOOKUPS( int i ) + { + Assert( i >= 0 && i <= 4 ); + m_nNUM_LOOKUPS = i; +#ifdef _DEBUG + m_bNUM_LOOKUPS = true; +#endif + } + void SetNUM_LOOKUPS( bool i ) + { + m_nNUM_LOOKUPS = i ? 1 : 0; +#ifdef _DEBUG + m_bNUM_LOOKUPS = true; +#endif + } +public: + colorcorrection_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bNUM_LOOKUPS = false; +#endif // _DEBUG + m_nNUM_LOOKUPS = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bNUM_LOOKUPS; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nNUM_LOOKUPS ) + 0; + } +}; +#define shaderDynamicTest_colorcorrection_ps20 psh_forgot_to_set_dynamic_NUM_LOOKUPS + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/colorcorrection_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/colorcorrection_ps20b.inc new file mode 100644 index 0000000..a46b056 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/colorcorrection_ps20b.inc @@ -0,0 +1,87 @@ +#include "shaderlib/cshader.h" +class colorcorrection_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + colorcorrection_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 5 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_colorcorrection_ps20b 0 +class colorcorrection_ps20b_Dynamic_Index +{ +private: + int m_nNUM_LOOKUPS; +#ifdef _DEBUG + bool m_bNUM_LOOKUPS; +#endif +public: + void SetNUM_LOOKUPS( int i ) + { + Assert( i >= 0 && i <= 4 ); + m_nNUM_LOOKUPS = i; +#ifdef _DEBUG + m_bNUM_LOOKUPS = true; +#endif + } + void SetNUM_LOOKUPS( bool i ) + { + m_nNUM_LOOKUPS = i ? 1 : 0; +#ifdef _DEBUG + m_bNUM_LOOKUPS = true; +#endif + } +public: + colorcorrection_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bNUM_LOOKUPS = false; +#endif // _DEBUG + m_nNUM_LOOKUPS = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bNUM_LOOKUPS; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nNUM_LOOKUPS ) + 0; + } +}; +#define shaderDynamicTest_colorcorrection_ps20b psh_forgot_to_set_dynamic_NUM_LOOKUPS + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/constant_color_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/constant_color_ps20.inc new file mode 100644 index 0000000..70abdd0 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/constant_color_ps20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class constant_color_ps20_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + constant_color_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_constant_color_ps20 0 +class constant_color_ps20_Dynamic_Index +{ +public: + constant_color_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_constant_color_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/constant_color_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/constant_color_ps20b.inc new file mode 100644 index 0000000..447c239 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/constant_color_ps20b.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class constant_color_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + constant_color_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_constant_color_ps20b 0 +class constant_color_ps20b_Dynamic_Index +{ +public: + constant_color_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_constant_color_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/copy_fp_rt_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/copy_fp_rt_ps20.inc new file mode 100644 index 0000000..10000a8 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/copy_fp_rt_ps20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class copy_fp_rt_ps20_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + copy_fp_rt_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_copy_fp_rt_ps20 0 +class copy_fp_rt_ps20_Dynamic_Index +{ +public: + copy_fp_rt_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_copy_fp_rt_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/copy_fp_rt_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/copy_fp_rt_ps20b.inc new file mode 100644 index 0000000..fe6aaf4 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/copy_fp_rt_ps20b.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class copy_fp_rt_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + copy_fp_rt_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_copy_fp_rt_ps20b 0 +class copy_fp_rt_ps20b_Dynamic_Index +{ +public: + copy_fp_rt_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_copy_fp_rt_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/core_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/core_ps20.inc new file mode 100644 index 0000000..61f3a84 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/core_ps20.inc @@ -0,0 +1,187 @@ +#include "shaderlib/cshader.h" +class core_ps20_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +private: + int m_nCUBEMAP; +#ifdef _DEBUG + bool m_bCUBEMAP; +#endif +public: + void SetCUBEMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCUBEMAP = i; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } + void SetCUBEMAP( bool i ) + { + m_nCUBEMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } +private: + int m_nFLOWMAP; +#ifdef _DEBUG + bool m_bFLOWMAP; +#endif +public: + void SetFLOWMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFLOWMAP = i; +#ifdef _DEBUG + m_bFLOWMAP = true; +#endif + } + void SetFLOWMAP( bool i ) + { + m_nFLOWMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bFLOWMAP = true; +#endif + } +private: + int m_nCORECOLORTEXTURE; +#ifdef _DEBUG + bool m_bCORECOLORTEXTURE; +#endif +public: + void SetCORECOLORTEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCORECOLORTEXTURE = i; +#ifdef _DEBUG + m_bCORECOLORTEXTURE = true; +#endif + } + void SetCORECOLORTEXTURE( bool i ) + { + m_nCORECOLORTEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bCORECOLORTEXTURE = true; +#endif + } +private: + int m_nREFRACT; +#ifdef _DEBUG + bool m_bREFRACT; +#endif +public: + void SetREFRACT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nREFRACT = i; +#ifdef _DEBUG + m_bREFRACT = true; +#endif + } + void SetREFRACT( bool i ) + { + m_nREFRACT = i ? 1 : 0; +#ifdef _DEBUG + m_bREFRACT = true; +#endif + } +public: + core_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; +#ifdef _DEBUG + m_bCUBEMAP = false; +#endif // _DEBUG + m_nCUBEMAP = 0; +#ifdef _DEBUG + m_bFLOWMAP = false; +#endif // _DEBUG + m_nFLOWMAP = 0; +#ifdef _DEBUG + m_bCORECOLORTEXTURE = false; +#endif // _DEBUG + m_nCORECOLORTEXTURE = 0; +#ifdef _DEBUG + m_bREFRACT = false; +#endif // _DEBUG + m_nREFRACT = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB && m_bCUBEMAP && m_bFLOWMAP && m_bCORECOLORTEXTURE && m_bREFRACT; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nCONVERT_TO_SRGB ) + ( 2 * m_nCUBEMAP ) + ( 4 * m_nFLOWMAP ) + ( 8 * m_nCORECOLORTEXTURE ) + ( 16 * m_nREFRACT ) + 0; + } +}; +#define shaderStaticTest_core_ps20 psh_forgot_to_set_static_CUBEMAP + psh_forgot_to_set_static_FLOWMAP + psh_forgot_to_set_static_CORECOLORTEXTURE + psh_forgot_to_set_static_REFRACT + 0 +class core_ps20_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + core_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_core_ps20 psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/core_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/core_ps20b.inc new file mode 100644 index 0000000..ac3eaac --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/core_ps20b.inc @@ -0,0 +1,187 @@ +#include "shaderlib/cshader.h" +class core_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +private: + int m_nCUBEMAP; +#ifdef _DEBUG + bool m_bCUBEMAP; +#endif +public: + void SetCUBEMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCUBEMAP = i; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } + void SetCUBEMAP( bool i ) + { + m_nCUBEMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } +private: + int m_nFLOWMAP; +#ifdef _DEBUG + bool m_bFLOWMAP; +#endif +public: + void SetFLOWMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFLOWMAP = i; +#ifdef _DEBUG + m_bFLOWMAP = true; +#endif + } + void SetFLOWMAP( bool i ) + { + m_nFLOWMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bFLOWMAP = true; +#endif + } +private: + int m_nCORECOLORTEXTURE; +#ifdef _DEBUG + bool m_bCORECOLORTEXTURE; +#endif +public: + void SetCORECOLORTEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCORECOLORTEXTURE = i; +#ifdef _DEBUG + m_bCORECOLORTEXTURE = true; +#endif + } + void SetCORECOLORTEXTURE( bool i ) + { + m_nCORECOLORTEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bCORECOLORTEXTURE = true; +#endif + } +private: + int m_nREFRACT; +#ifdef _DEBUG + bool m_bREFRACT; +#endif +public: + void SetREFRACT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nREFRACT = i; +#ifdef _DEBUG + m_bREFRACT = true; +#endif + } + void SetREFRACT( bool i ) + { + m_nREFRACT = i ? 1 : 0; +#ifdef _DEBUG + m_bREFRACT = true; +#endif + } +public: + core_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; +#ifdef _DEBUG + m_bCUBEMAP = false; +#endif // _DEBUG + m_nCUBEMAP = 0; +#ifdef _DEBUG + m_bFLOWMAP = false; +#endif // _DEBUG + m_nFLOWMAP = 0; +#ifdef _DEBUG + m_bCORECOLORTEXTURE = false; +#endif // _DEBUG + m_nCORECOLORTEXTURE = 0; +#ifdef _DEBUG + m_bREFRACT = false; +#endif // _DEBUG + m_nREFRACT = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB && m_bCUBEMAP && m_bFLOWMAP && m_bCORECOLORTEXTURE && m_bREFRACT; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nCONVERT_TO_SRGB ) + ( 2 * m_nCUBEMAP ) + ( 4 * m_nFLOWMAP ) + ( 8 * m_nCORECOLORTEXTURE ) + ( 16 * m_nREFRACT ) + 0; + } +}; +#define shaderStaticTest_core_ps20b psh_forgot_to_set_static_CUBEMAP + psh_forgot_to_set_static_FLOWMAP + psh_forgot_to_set_static_CORECOLORTEXTURE + psh_forgot_to_set_static_REFRACT + 0 +class core_ps20b_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + core_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_core_ps20b psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/core_vs11.inc b/materialsystem/stdshaders/fxctmp9_360/core_vs11.inc new file mode 100644 index 0000000..3a535e7 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/core_vs11.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class core_vs11_Static_Index +{ +public: + core_vs11_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_core_vs11 0 +class core_vs11_Dynamic_Index +{ +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +public: + core_vs11_Dynamic_Index() + { +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bSKINNING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nSKINNING ) + 0; + } +}; +#define shaderDynamicTest_core_vs11 vsh_forgot_to_set_dynamic_SKINNING + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/core_vs20.inc b/materialsystem/stdshaders/fxctmp9_360/core_vs20.inc new file mode 100644 index 0000000..5cbf35f --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/core_vs20.inc @@ -0,0 +1,112 @@ +#include "shaderlib/cshader.h" +class core_vs20_Static_Index +{ +private: + int m_nMODEL; +#ifdef _DEBUG + bool m_bMODEL; +#endif +public: + void SetMODEL( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nMODEL = i; +#ifdef _DEBUG + m_bMODEL = true; +#endif + } + void SetMODEL( bool i ) + { + m_nMODEL = i ? 1 : 0; +#ifdef _DEBUG + m_bMODEL = true; +#endif + } +public: + core_vs20_Static_Index( ) + { +#ifdef _DEBUG + m_bMODEL = false; +#endif // _DEBUG + m_nMODEL = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bMODEL; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 4 * m_nMODEL ) + 0; + } +}; +#define shaderStaticTest_core_vs20 vsh_forgot_to_set_static_MODEL + 0 +class core_vs20_Dynamic_Index +{ +private: + int m_nCOMPRESSED_VERTS; +#ifdef _DEBUG + bool m_bCOMPRESSED_VERTS; +#endif +public: + void SetCOMPRESSED_VERTS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOMPRESSED_VERTS = i; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } + void SetCOMPRESSED_VERTS( bool i ) + { + m_nCOMPRESSED_VERTS = i ? 1 : 0; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +public: + core_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = false; +#endif // _DEBUG + m_nCOMPRESSED_VERTS = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bCOMPRESSED_VERTS && m_bSKINNING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCOMPRESSED_VERTS ) + ( 2 * m_nSKINNING ) + 0; + } +}; +#define shaderDynamicTest_core_vs20 vsh_forgot_to_set_dynamic_COMPRESSED_VERTS + vsh_forgot_to_set_dynamic_SKINNING + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/debugdrawdepth_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/debugdrawdepth_ps20.inc new file mode 100644 index 0000000..18bd82b --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/debugdrawdepth_ps20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class debugdrawdepth_ps20_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + debugdrawdepth_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_debugdrawdepth_ps20 0 +class debugdrawdepth_ps20_Dynamic_Index +{ +public: + debugdrawdepth_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_debugdrawdepth_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/debugdrawdepth_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/debugdrawdepth_ps20b.inc new file mode 100644 index 0000000..6363121 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/debugdrawdepth_ps20b.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class debugdrawdepth_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + debugdrawdepth_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_debugdrawdepth_ps20b 0 +class debugdrawdepth_ps20b_Dynamic_Index +{ +public: + debugdrawdepth_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_debugdrawdepth_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/debugdrawdepth_vs20.inc b/materialsystem/stdshaders/fxctmp9_360/debugdrawdepth_vs20.inc new file mode 100644 index 0000000..eea4b80 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/debugdrawdepth_vs20.inc @@ -0,0 +1,85 @@ +#include "shaderlib/cshader.h" +class debugdrawdepth_vs20_Static_Index +{ +public: + debugdrawdepth_vs20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_debugdrawdepth_vs20 0 +class debugdrawdepth_vs20_Dynamic_Index +{ +private: + int m_nCOMPRESSED_VERTS; +#ifdef _DEBUG + bool m_bCOMPRESSED_VERTS; +#endif +public: + void SetCOMPRESSED_VERTS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOMPRESSED_VERTS = i; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } + void SetCOMPRESSED_VERTS( bool i ) + { + m_nCOMPRESSED_VERTS = i ? 1 : 0; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +public: + debugdrawdepth_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = false; +#endif // _DEBUG + m_nCOMPRESSED_VERTS = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bCOMPRESSED_VERTS && m_bSKINNING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCOMPRESSED_VERTS ) + ( 2 * m_nSKINNING ) + 0; + } +}; +#define shaderDynamicTest_debugdrawdepth_vs20 vsh_forgot_to_set_dynamic_COMPRESSED_VERTS + vsh_forgot_to_set_dynamic_SKINNING + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/debugdrawenvmapmask_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/debugdrawenvmapmask_ps20.inc new file mode 100644 index 0000000..66c9a5e --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/debugdrawenvmapmask_ps20.inc @@ -0,0 +1,87 @@ +#include "shaderlib/cshader.h" +class debugdrawenvmapmask_ps20_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + debugdrawenvmapmask_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_debugdrawenvmapmask_ps20 0 +class debugdrawenvmapmask_ps20_Dynamic_Index +{ +private: + int m_nSHOWALPHA; +#ifdef _DEBUG + bool m_bSHOWALPHA; +#endif +public: + void SetSHOWALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSHOWALPHA = i; +#ifdef _DEBUG + m_bSHOWALPHA = true; +#endif + } + void SetSHOWALPHA( bool i ) + { + m_nSHOWALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bSHOWALPHA = true; +#endif + } +public: + debugdrawenvmapmask_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bSHOWALPHA = false; +#endif // _DEBUG + m_nSHOWALPHA = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bSHOWALPHA; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nSHOWALPHA ) + 0; + } +}; +#define shaderDynamicTest_debugdrawenvmapmask_ps20 psh_forgot_to_set_dynamic_SHOWALPHA + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/debugdrawenvmapmask_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/debugdrawenvmapmask_ps20b.inc new file mode 100644 index 0000000..05eaf05 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/debugdrawenvmapmask_ps20b.inc @@ -0,0 +1,87 @@ +#include "shaderlib/cshader.h" +class debugdrawenvmapmask_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + debugdrawenvmapmask_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_debugdrawenvmapmask_ps20b 0 +class debugdrawenvmapmask_ps20b_Dynamic_Index +{ +private: + int m_nSHOWALPHA; +#ifdef _DEBUG + bool m_bSHOWALPHA; +#endif +public: + void SetSHOWALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSHOWALPHA = i; +#ifdef _DEBUG + m_bSHOWALPHA = true; +#endif + } + void SetSHOWALPHA( bool i ) + { + m_nSHOWALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bSHOWALPHA = true; +#endif + } +public: + debugdrawenvmapmask_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bSHOWALPHA = false; +#endif // _DEBUG + m_nSHOWALPHA = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bSHOWALPHA; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nSHOWALPHA ) + 0; + } +}; +#define shaderDynamicTest_debugdrawenvmapmask_ps20b psh_forgot_to_set_dynamic_SHOWALPHA + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/debugdrawenvmapmask_vs20.inc b/materialsystem/stdshaders/fxctmp9_360/debugdrawenvmapmask_vs20.inc new file mode 100644 index 0000000..96910cd --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/debugdrawenvmapmask_vs20.inc @@ -0,0 +1,85 @@ +#include "shaderlib/cshader.h" +class debugdrawenvmapmask_vs20_Static_Index +{ +public: + debugdrawenvmapmask_vs20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_debugdrawenvmapmask_vs20 0 +class debugdrawenvmapmask_vs20_Dynamic_Index +{ +private: + int m_nCOMPRESSED_VERTS; +#ifdef _DEBUG + bool m_bCOMPRESSED_VERTS; +#endif +public: + void SetCOMPRESSED_VERTS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOMPRESSED_VERTS = i; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } + void SetCOMPRESSED_VERTS( bool i ) + { + m_nCOMPRESSED_VERTS = i ? 1 : 0; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +public: + debugdrawenvmapmask_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = false; +#endif // _DEBUG + m_nCOMPRESSED_VERTS = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bCOMPRESSED_VERTS && m_bSKINNING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCOMPRESSED_VERTS ) + ( 2 * m_nSKINNING ) + 0; + } +}; +#define shaderDynamicTest_debugdrawenvmapmask_vs20 vsh_forgot_to_set_dynamic_COMPRESSED_VERTS + vsh_forgot_to_set_dynamic_SKINNING + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/debugmrttexture_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/debugmrttexture_ps20.inc new file mode 100644 index 0000000..c4c188c --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/debugmrttexture_ps20.inc @@ -0,0 +1,85 @@ +#include "shaderlib/cshader.h" +class debugmrttexture_ps20_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +private: + int m_nMRTINDEX; +#ifdef _DEBUG + bool m_bMRTINDEX; +#endif +public: + void SetMRTINDEX( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nMRTINDEX = i; +#ifdef _DEBUG + m_bMRTINDEX = true; +#endif + } + void SetMRTINDEX( bool i ) + { + m_nMRTINDEX = i ? 1 : 0; +#ifdef _DEBUG + m_bMRTINDEX = true; +#endif + } +public: + debugmrttexture_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; +#ifdef _DEBUG + m_bMRTINDEX = false; +#endif // _DEBUG + m_nMRTINDEX = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB && m_bMRTINDEX; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + ( 1 * m_nMRTINDEX ) + 0; + } +}; +#define shaderStaticTest_debugmrttexture_ps20 psh_forgot_to_set_static_MRTINDEX + 0 +class debugmrttexture_ps20_Dynamic_Index +{ +public: + debugmrttexture_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_debugmrttexture_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/debugmrttexture_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/debugmrttexture_ps20b.inc new file mode 100644 index 0000000..13add2a --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/debugmrttexture_ps20b.inc @@ -0,0 +1,85 @@ +#include "shaderlib/cshader.h" +class debugmrttexture_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +private: + int m_nMRTINDEX; +#ifdef _DEBUG + bool m_bMRTINDEX; +#endif +public: + void SetMRTINDEX( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nMRTINDEX = i; +#ifdef _DEBUG + m_bMRTINDEX = true; +#endif + } + void SetMRTINDEX( bool i ) + { + m_nMRTINDEX = i ? 1 : 0; +#ifdef _DEBUG + m_bMRTINDEX = true; +#endif + } +public: + debugmrttexture_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; +#ifdef _DEBUG + m_bMRTINDEX = false; +#endif // _DEBUG + m_nMRTINDEX = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB && m_bMRTINDEX; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + ( 1 * m_nMRTINDEX ) + 0; + } +}; +#define shaderStaticTest_debugmrttexture_ps20b psh_forgot_to_set_static_MRTINDEX + 0 +class debugmrttexture_ps20b_Dynamic_Index +{ +public: + debugmrttexture_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_debugmrttexture_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/debugmrttexture_vs20.inc b/materialsystem/stdshaders/fxctmp9_360/debugmrttexture_vs20.inc new file mode 100644 index 0000000..35138b3 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/debugmrttexture_vs20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class debugmrttexture_vs20_Static_Index +{ +public: + debugmrttexture_vs20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_debugmrttexture_vs20 0 +class debugmrttexture_vs20_Dynamic_Index +{ +public: + debugmrttexture_vs20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_debugmrttexture_vs20 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/debugtangentspace_vs11.inc b/materialsystem/stdshaders/fxctmp9_360/debugtangentspace_vs11.inc new file mode 100644 index 0000000..3b1e89c --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/debugtangentspace_vs11.inc @@ -0,0 +1,85 @@ +#include "shaderlib/cshader.h" +class debugtangentspace_vs11_Static_Index +{ +public: + debugtangentspace_vs11_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_debugtangentspace_vs11 0 +class debugtangentspace_vs11_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +public: + debugtangentspace_vs11_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG && m_bSKINNING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + ( 2 * m_nSKINNING ) + 0; + } +}; +#define shaderDynamicTest_debugtangentspace_vs11 vsh_forgot_to_set_dynamic_DOWATERFOG + vsh_forgot_to_set_dynamic_SKINNING + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/debugtangentspace_vs20.inc b/materialsystem/stdshaders/fxctmp9_360/debugtangentspace_vs20.inc new file mode 100644 index 0000000..f0e4f7c --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/debugtangentspace_vs20.inc @@ -0,0 +1,110 @@ +#include "shaderlib/cshader.h" +class debugtangentspace_vs20_Static_Index +{ +public: + debugtangentspace_vs20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_debugtangentspace_vs20 0 +class debugtangentspace_vs20_Dynamic_Index +{ +private: + int m_nCOMPRESSED_VERTS; +#ifdef _DEBUG + bool m_bCOMPRESSED_VERTS; +#endif +public: + void SetCOMPRESSED_VERTS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOMPRESSED_VERTS = i; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } + void SetCOMPRESSED_VERTS( bool i ) + { + m_nCOMPRESSED_VERTS = i ? 1 : 0; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +public: + debugtangentspace_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = false; +#endif // _DEBUG + m_nCOMPRESSED_VERTS = 0; +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bCOMPRESSED_VERTS && m_bDOWATERFOG && m_bSKINNING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCOMPRESSED_VERTS ) + ( 2 * m_nDOWATERFOG ) + ( 4 * m_nSKINNING ) + 0; + } +}; +#define shaderDynamicTest_debugtangentspace_vs20 vsh_forgot_to_set_dynamic_COMPRESSED_VERTS + vsh_forgot_to_set_dynamic_DOWATERFOG + vsh_forgot_to_set_dynamic_SKINNING + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/debugtextureview_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/debugtextureview_ps20.inc new file mode 100644 index 0000000..0fd6798 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/debugtextureview_ps20.inc @@ -0,0 +1,112 @@ +#include "shaderlib/cshader.h" +class debugtextureview_ps20_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +private: + int m_nSHOWALPHA; +#ifdef _DEBUG + bool m_bSHOWALPHA; +#endif +public: + void SetSHOWALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSHOWALPHA = i; +#ifdef _DEBUG + m_bSHOWALPHA = true; +#endif + } + void SetSHOWALPHA( bool i ) + { + m_nSHOWALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bSHOWALPHA = true; +#endif + } +public: + debugtextureview_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; +#ifdef _DEBUG + m_bSHOWALPHA = false; +#endif // _DEBUG + m_nSHOWALPHA = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB && m_bSHOWALPHA; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nCONVERT_TO_SRGB ) + ( 2 * m_nSHOWALPHA ) + 0; + } +}; +#define shaderStaticTest_debugtextureview_ps20 psh_forgot_to_set_static_SHOWALPHA + 0 +class debugtextureview_ps20_Dynamic_Index +{ +private: + int m_nISCUBEMAP; +#ifdef _DEBUG + bool m_bISCUBEMAP; +#endif +public: + void SetISCUBEMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nISCUBEMAP = i; +#ifdef _DEBUG + m_bISCUBEMAP = true; +#endif + } + void SetISCUBEMAP( bool i ) + { + m_nISCUBEMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bISCUBEMAP = true; +#endif + } +public: + debugtextureview_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bISCUBEMAP = false; +#endif // _DEBUG + m_nISCUBEMAP = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bISCUBEMAP; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nISCUBEMAP ) + 0; + } +}; +#define shaderDynamicTest_debugtextureview_ps20 psh_forgot_to_set_dynamic_ISCUBEMAP + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/debugtextureview_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/debugtextureview_ps20b.inc new file mode 100644 index 0000000..4ec46cf --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/debugtextureview_ps20b.inc @@ -0,0 +1,112 @@ +#include "shaderlib/cshader.h" +class debugtextureview_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +private: + int m_nSHOWALPHA; +#ifdef _DEBUG + bool m_bSHOWALPHA; +#endif +public: + void SetSHOWALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSHOWALPHA = i; +#ifdef _DEBUG + m_bSHOWALPHA = true; +#endif + } + void SetSHOWALPHA( bool i ) + { + m_nSHOWALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bSHOWALPHA = true; +#endif + } +public: + debugtextureview_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; +#ifdef _DEBUG + m_bSHOWALPHA = false; +#endif // _DEBUG + m_nSHOWALPHA = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB && m_bSHOWALPHA; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nCONVERT_TO_SRGB ) + ( 2 * m_nSHOWALPHA ) + 0; + } +}; +#define shaderStaticTest_debugtextureview_ps20b psh_forgot_to_set_static_SHOWALPHA + 0 +class debugtextureview_ps20b_Dynamic_Index +{ +private: + int m_nISCUBEMAP; +#ifdef _DEBUG + bool m_bISCUBEMAP; +#endif +public: + void SetISCUBEMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nISCUBEMAP = i; +#ifdef _DEBUG + m_bISCUBEMAP = true; +#endif + } + void SetISCUBEMAP( bool i ) + { + m_nISCUBEMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bISCUBEMAP = true; +#endif + } +public: + debugtextureview_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bISCUBEMAP = false; +#endif // _DEBUG + m_nISCUBEMAP = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bISCUBEMAP; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nISCUBEMAP ) + 0; + } +}; +#define shaderDynamicTest_debugtextureview_ps20b psh_forgot_to_set_dynamic_ISCUBEMAP + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/debugtextureview_vs20.inc b/materialsystem/stdshaders/fxctmp9_360/debugtextureview_vs20.inc new file mode 100644 index 0000000..bb43b05 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/debugtextureview_vs20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class debugtextureview_vs20_Static_Index +{ +public: + debugtextureview_vs20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_debugtextureview_vs20 0 +class debugtextureview_vs20_Dynamic_Index +{ +private: + int m_nCOMPRESSED_VERTS; +#ifdef _DEBUG + bool m_bCOMPRESSED_VERTS; +#endif +public: + void SetCOMPRESSED_VERTS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOMPRESSED_VERTS = i; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } + void SetCOMPRESSED_VERTS( bool i ) + { + m_nCOMPRESSED_VERTS = i ? 1 : 0; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } +public: + debugtextureview_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = false; +#endif // _DEBUG + m_nCOMPRESSED_VERTS = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bCOMPRESSED_VERTS; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCOMPRESSED_VERTS ) + 0; + } +}; +#define shaderDynamicTest_debugtextureview_vs20 vsh_forgot_to_set_dynamic_COMPRESSED_VERTS + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/decalbasetimeslightmapalphablendselfillum2_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/decalbasetimeslightmapalphablendselfillum2_ps20.inc new file mode 100644 index 0000000..320678f --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/decalbasetimeslightmapalphablendselfillum2_ps20.inc @@ -0,0 +1,87 @@ +#include "shaderlib/cshader.h" +class decalbasetimeslightmapalphablendselfillum2_ps20_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + decalbasetimeslightmapalphablendselfillum2_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_decalbasetimeslightmapalphablendselfillum2_ps20 0 +class decalbasetimeslightmapalphablendselfillum2_ps20_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + decalbasetimeslightmapalphablendselfillum2_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_decalbasetimeslightmapalphablendselfillum2_ps20 psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/decalbasetimeslightmapalphablendselfillum2_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/decalbasetimeslightmapalphablendselfillum2_ps20b.inc new file mode 100644 index 0000000..c7dd414 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/decalbasetimeslightmapalphablendselfillum2_ps20b.inc @@ -0,0 +1,87 @@ +#include "shaderlib/cshader.h" +class decalbasetimeslightmapalphablendselfillum2_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + decalbasetimeslightmapalphablendselfillum2_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_decalbasetimeslightmapalphablendselfillum2_ps20b 0 +class decalbasetimeslightmapalphablendselfillum2_ps20b_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + decalbasetimeslightmapalphablendselfillum2_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_decalbasetimeslightmapalphablendselfillum2_ps20b psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/decalmodulate_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/decalmodulate_ps20.inc new file mode 100644 index 0000000..1412571 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/decalmodulate_ps20.inc @@ -0,0 +1,87 @@ +#include "shaderlib/cshader.h" +class decalmodulate_ps20_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + decalmodulate_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_decalmodulate_ps20 0 +class decalmodulate_ps20_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + decalmodulate_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_decalmodulate_ps20 psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/decalmodulate_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/decalmodulate_ps20b.inc new file mode 100644 index 0000000..3bfa493 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/decalmodulate_ps20b.inc @@ -0,0 +1,87 @@ +#include "shaderlib/cshader.h" +class decalmodulate_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + decalmodulate_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_decalmodulate_ps20b 0 +class decalmodulate_ps20b_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + decalmodulate_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_decalmodulate_ps20b psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/depthtodestalpha_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/depthtodestalpha_ps20b.inc new file mode 100644 index 0000000..62375d8 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/depthtodestalpha_ps20b.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class depthtodestalpha_ps20b_Static_Index +{ +public: + depthtodestalpha_ps20b_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_depthtodestalpha_ps20b 0 +class depthtodestalpha_ps20b_Dynamic_Index +{ +public: + depthtodestalpha_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_depthtodestalpha_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/depthtodestalpha_vs20.inc b/materialsystem/stdshaders/fxctmp9_360/depthtodestalpha_vs20.inc new file mode 100644 index 0000000..3e3744e --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/depthtodestalpha_vs20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class depthtodestalpha_vs20_Static_Index +{ +public: + depthtodestalpha_vs20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_depthtodestalpha_vs20 0 +class depthtodestalpha_vs20_Dynamic_Index +{ +public: + depthtodestalpha_vs20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_depthtodestalpha_vs20 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/depthwrite_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/depthwrite_ps20.inc new file mode 100644 index 0000000..39826e6 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/depthwrite_ps20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class depthwrite_ps20_Static_Index +{ +public: + depthwrite_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_depthwrite_ps20 0 +class depthwrite_ps20_Dynamic_Index +{ +private: + int m_nALPHACLIP; +#ifdef _DEBUG + bool m_bALPHACLIP; +#endif +public: + void SetALPHACLIP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nALPHACLIP = i; +#ifdef _DEBUG + m_bALPHACLIP = true; +#endif + } + void SetALPHACLIP( bool i ) + { + m_nALPHACLIP = i ? 1 : 0; +#ifdef _DEBUG + m_bALPHACLIP = true; +#endif + } +public: + depthwrite_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bALPHACLIP = false; +#endif // _DEBUG + m_nALPHACLIP = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bALPHACLIP; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nALPHACLIP ) + 0; + } +}; +#define shaderDynamicTest_depthwrite_ps20 psh_forgot_to_set_dynamic_ALPHACLIP + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/depthwrite_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/depthwrite_ps20b.inc new file mode 100644 index 0000000..dbb93d5 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/depthwrite_ps20b.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class depthwrite_ps20b_Static_Index +{ +public: + depthwrite_ps20b_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_depthwrite_ps20b 0 +class depthwrite_ps20b_Dynamic_Index +{ +private: + int m_nALPHACLIP; +#ifdef _DEBUG + bool m_bALPHACLIP; +#endif +public: + void SetALPHACLIP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nALPHACLIP = i; +#ifdef _DEBUG + m_bALPHACLIP = true; +#endif + } + void SetALPHACLIP( bool i ) + { + m_nALPHACLIP = i ? 1 : 0; +#ifdef _DEBUG + m_bALPHACLIP = true; +#endif + } +public: + depthwrite_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bALPHACLIP = false; +#endif // _DEBUG + m_nALPHACLIP = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bALPHACLIP; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nALPHACLIP ) + 0; + } +}; +#define shaderDynamicTest_depthwrite_ps20b psh_forgot_to_set_dynamic_ALPHACLIP + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/depthwrite_vs20.inc b/materialsystem/stdshaders/fxctmp9_360/depthwrite_vs20.inc new file mode 100644 index 0000000..00f2aa5 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/depthwrite_vs20.inc @@ -0,0 +1,112 @@ +#include "shaderlib/cshader.h" +class depthwrite_vs20_Static_Index +{ +private: + int m_nONLY_PROJECT_POSITION; +#ifdef _DEBUG + bool m_bONLY_PROJECT_POSITION; +#endif +public: + void SetONLY_PROJECT_POSITION( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nONLY_PROJECT_POSITION = i; +#ifdef _DEBUG + m_bONLY_PROJECT_POSITION = true; +#endif + } + void SetONLY_PROJECT_POSITION( bool i ) + { + m_nONLY_PROJECT_POSITION = i ? 1 : 0; +#ifdef _DEBUG + m_bONLY_PROJECT_POSITION = true; +#endif + } +public: + depthwrite_vs20_Static_Index( ) + { +#ifdef _DEBUG + m_bONLY_PROJECT_POSITION = false; +#endif // _DEBUG + m_nONLY_PROJECT_POSITION = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bONLY_PROJECT_POSITION; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 4 * m_nONLY_PROJECT_POSITION ) + 0; + } +}; +#define shaderStaticTest_depthwrite_vs20 vsh_forgot_to_set_static_ONLY_PROJECT_POSITION + 0 +class depthwrite_vs20_Dynamic_Index +{ +private: + int m_nCOMPRESSED_VERTS; +#ifdef _DEBUG + bool m_bCOMPRESSED_VERTS; +#endif +public: + void SetCOMPRESSED_VERTS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOMPRESSED_VERTS = i; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } + void SetCOMPRESSED_VERTS( bool i ) + { + m_nCOMPRESSED_VERTS = i ? 1 : 0; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +public: + depthwrite_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = false; +#endif // _DEBUG + m_nCOMPRESSED_VERTS = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bCOMPRESSED_VERTS && m_bSKINNING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCOMPRESSED_VERTS ) + ( 2 * m_nSKINNING ) + 0; + } +}; +#define shaderDynamicTest_depthwrite_vs20 vsh_forgot_to_set_dynamic_COMPRESSED_VERTS + vsh_forgot_to_set_dynamic_SKINNING + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/emissive_scroll_blended_pass_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/emissive_scroll_blended_pass_ps20.inc new file mode 100644 index 0000000..4d9d596 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/emissive_scroll_blended_pass_ps20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class emissive_scroll_blended_pass_ps20_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + emissive_scroll_blended_pass_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_emissive_scroll_blended_pass_ps20 0 +class emissive_scroll_blended_pass_ps20_Dynamic_Index +{ +public: + emissive_scroll_blended_pass_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_emissive_scroll_blended_pass_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/emissive_scroll_blended_pass_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/emissive_scroll_blended_pass_ps20b.inc new file mode 100644 index 0000000..8cca0e4 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/emissive_scroll_blended_pass_ps20b.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class emissive_scroll_blended_pass_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + emissive_scroll_blended_pass_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_emissive_scroll_blended_pass_ps20b 0 +class emissive_scroll_blended_pass_ps20b_Dynamic_Index +{ +public: + emissive_scroll_blended_pass_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_emissive_scroll_blended_pass_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/emissive_scroll_blended_pass_vs20.inc b/materialsystem/stdshaders/fxctmp9_360/emissive_scroll_blended_pass_vs20.inc new file mode 100644 index 0000000..c29b0b1 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/emissive_scroll_blended_pass_vs20.inc @@ -0,0 +1,85 @@ +#include "shaderlib/cshader.h" +class emissive_scroll_blended_pass_vs20_Static_Index +{ +public: + emissive_scroll_blended_pass_vs20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_emissive_scroll_blended_pass_vs20 0 +class emissive_scroll_blended_pass_vs20_Dynamic_Index +{ +private: + int m_nCOMPRESSED_VERTS; +#ifdef _DEBUG + bool m_bCOMPRESSED_VERTS; +#endif +public: + void SetCOMPRESSED_VERTS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOMPRESSED_VERTS = i; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } + void SetCOMPRESSED_VERTS( bool i ) + { + m_nCOMPRESSED_VERTS = i ? 1 : 0; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +public: + emissive_scroll_blended_pass_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = false; +#endif // _DEBUG + m_nCOMPRESSED_VERTS = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bCOMPRESSED_VERTS && m_bSKINNING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCOMPRESSED_VERTS ) + ( 2 * m_nSKINNING ) + 0; + } +}; +#define shaderDynamicTest_emissive_scroll_blended_pass_vs20 vsh_forgot_to_set_dynamic_COMPRESSED_VERTS + vsh_forgot_to_set_dynamic_SKINNING + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/engine_post_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/engine_post_ps20.inc new file mode 100644 index 0000000..7c1b587 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/engine_post_ps20.inc @@ -0,0 +1,162 @@ +#include "shaderlib/cshader.h" +class engine_post_ps20_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + engine_post_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 10 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_engine_post_ps20 0 +class engine_post_ps20_Dynamic_Index +{ +private: + int m_nAA_ENABLE; +#ifdef _DEBUG + bool m_bAA_ENABLE; +#endif +public: + void SetAA_ENABLE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nAA_ENABLE = i; +#ifdef _DEBUG + m_bAA_ENABLE = true; +#endif + } + void SetAA_ENABLE( bool i ) + { + m_nAA_ENABLE = i ? 1 : 0; +#ifdef _DEBUG + m_bAA_ENABLE = true; +#endif + } +private: + int m_nAA_QUALITY_MODE; +#ifdef _DEBUG + bool m_bAA_QUALITY_MODE; +#endif +public: + void SetAA_QUALITY_MODE( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nAA_QUALITY_MODE = i; +#ifdef _DEBUG + m_bAA_QUALITY_MODE = true; +#endif + } + void SetAA_QUALITY_MODE( bool i ) + { + m_nAA_QUALITY_MODE = i ? 1 : 0; +#ifdef _DEBUG + m_bAA_QUALITY_MODE = true; +#endif + } +private: + int m_nAA_REDUCE_ONE_PIXEL_LINE_BLUR; +#ifdef _DEBUG + bool m_bAA_REDUCE_ONE_PIXEL_LINE_BLUR; +#endif +public: + void SetAA_REDUCE_ONE_PIXEL_LINE_BLUR( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nAA_REDUCE_ONE_PIXEL_LINE_BLUR = i; +#ifdef _DEBUG + m_bAA_REDUCE_ONE_PIXEL_LINE_BLUR = true; +#endif + } + void SetAA_REDUCE_ONE_PIXEL_LINE_BLUR( bool i ) + { + m_nAA_REDUCE_ONE_PIXEL_LINE_BLUR = i ? 1 : 0; +#ifdef _DEBUG + m_bAA_REDUCE_ONE_PIXEL_LINE_BLUR = true; +#endif + } +private: + int m_nCOL_CORRECT_NUM_LOOKUPS; +#ifdef _DEBUG + bool m_bCOL_CORRECT_NUM_LOOKUPS; +#endif +public: + void SetCOL_CORRECT_NUM_LOOKUPS( int i ) + { + Assert( i >= 0 && i <= 4 ); + m_nCOL_CORRECT_NUM_LOOKUPS = i; +#ifdef _DEBUG + m_bCOL_CORRECT_NUM_LOOKUPS = true; +#endif + } + void SetCOL_CORRECT_NUM_LOOKUPS( bool i ) + { + m_nCOL_CORRECT_NUM_LOOKUPS = i ? 1 : 0; +#ifdef _DEBUG + m_bCOL_CORRECT_NUM_LOOKUPS = true; +#endif + } +public: + engine_post_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bAA_ENABLE = false; +#endif // _DEBUG + m_nAA_ENABLE = 0; +#ifdef _DEBUG + m_bAA_QUALITY_MODE = false; +#endif // _DEBUG + m_nAA_QUALITY_MODE = 0; +#ifdef _DEBUG + m_bAA_REDUCE_ONE_PIXEL_LINE_BLUR = false; +#endif // _DEBUG + m_nAA_REDUCE_ONE_PIXEL_LINE_BLUR = 0; +#ifdef _DEBUG + m_bCOL_CORRECT_NUM_LOOKUPS = false; +#endif // _DEBUG + m_nCOL_CORRECT_NUM_LOOKUPS = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bAA_ENABLE && m_bAA_QUALITY_MODE && m_bAA_REDUCE_ONE_PIXEL_LINE_BLUR && m_bCOL_CORRECT_NUM_LOOKUPS; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nAA_ENABLE ) + ( 2 * m_nAA_QUALITY_MODE ) + ( 2 * m_nAA_REDUCE_ONE_PIXEL_LINE_BLUR ) + ( 2 * m_nCOL_CORRECT_NUM_LOOKUPS ) + 0; + } +}; +#define shaderDynamicTest_engine_post_ps20 psh_forgot_to_set_dynamic_AA_ENABLE + psh_forgot_to_set_dynamic_AA_QUALITY_MODE + psh_forgot_to_set_dynamic_AA_REDUCE_ONE_PIXEL_LINE_BLUR + psh_forgot_to_set_dynamic_COL_CORRECT_NUM_LOOKUPS + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/engine_post_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/engine_post_ps20b.inc new file mode 100644 index 0000000..01f0723 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/engine_post_ps20b.inc @@ -0,0 +1,212 @@ +#include "shaderlib/cshader.h" +class engine_post_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +private: + int m_nLINEAR_INPUT; +#ifdef _DEBUG + bool m_bLINEAR_INPUT; +#endif +public: + void SetLINEAR_INPUT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nLINEAR_INPUT = i; +#ifdef _DEBUG + m_bLINEAR_INPUT = true; +#endif + } + void SetLINEAR_INPUT( bool i ) + { + m_nLINEAR_INPUT = i ? 1 : 0; +#ifdef _DEBUG + m_bLINEAR_INPUT = true; +#endif + } +private: + int m_nLINEAR_OUTPUT; +#ifdef _DEBUG + bool m_bLINEAR_OUTPUT; +#endif +public: + void SetLINEAR_OUTPUT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nLINEAR_OUTPUT = i; +#ifdef _DEBUG + m_bLINEAR_OUTPUT = true; +#endif + } + void SetLINEAR_OUTPUT( bool i ) + { + m_nLINEAR_OUTPUT = i ? 1 : 0; +#ifdef _DEBUG + m_bLINEAR_OUTPUT = true; +#endif + } +public: + engine_post_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; +#ifdef _DEBUG + m_bLINEAR_INPUT = false; +#endif // _DEBUG + m_nLINEAR_INPUT = 0; +#ifdef _DEBUG + m_bLINEAR_OUTPUT = false; +#endif // _DEBUG + m_nLINEAR_OUTPUT = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB && m_bLINEAR_INPUT && m_bLINEAR_OUTPUT; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 40 * m_nCONVERT_TO_SRGB ) + ( 40 * m_nLINEAR_INPUT ) + ( 80 * m_nLINEAR_OUTPUT ) + 0; + } +}; +#define shaderStaticTest_engine_post_ps20b psh_forgot_to_set_static_LINEAR_INPUT + psh_forgot_to_set_static_LINEAR_OUTPUT + 0 +class engine_post_ps20b_Dynamic_Index +{ +private: + int m_nAA_ENABLE; +#ifdef _DEBUG + bool m_bAA_ENABLE; +#endif +public: + void SetAA_ENABLE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nAA_ENABLE = i; +#ifdef _DEBUG + m_bAA_ENABLE = true; +#endif + } + void SetAA_ENABLE( bool i ) + { + m_nAA_ENABLE = i ? 1 : 0; +#ifdef _DEBUG + m_bAA_ENABLE = true; +#endif + } +private: + int m_nAA_QUALITY_MODE; +#ifdef _DEBUG + bool m_bAA_QUALITY_MODE; +#endif +public: + void SetAA_QUALITY_MODE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nAA_QUALITY_MODE = i; +#ifdef _DEBUG + m_bAA_QUALITY_MODE = true; +#endif + } + void SetAA_QUALITY_MODE( bool i ) + { + m_nAA_QUALITY_MODE = i ? 1 : 0; +#ifdef _DEBUG + m_bAA_QUALITY_MODE = true; +#endif + } +private: + int m_nAA_REDUCE_ONE_PIXEL_LINE_BLUR; +#ifdef _DEBUG + bool m_bAA_REDUCE_ONE_PIXEL_LINE_BLUR; +#endif +public: + void SetAA_REDUCE_ONE_PIXEL_LINE_BLUR( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nAA_REDUCE_ONE_PIXEL_LINE_BLUR = i; +#ifdef _DEBUG + m_bAA_REDUCE_ONE_PIXEL_LINE_BLUR = true; +#endif + } + void SetAA_REDUCE_ONE_PIXEL_LINE_BLUR( bool i ) + { + m_nAA_REDUCE_ONE_PIXEL_LINE_BLUR = i ? 1 : 0; +#ifdef _DEBUG + m_bAA_REDUCE_ONE_PIXEL_LINE_BLUR = true; +#endif + } +private: + int m_nCOL_CORRECT_NUM_LOOKUPS; +#ifdef _DEBUG + bool m_bCOL_CORRECT_NUM_LOOKUPS; +#endif +public: + void SetCOL_CORRECT_NUM_LOOKUPS( int i ) + { + Assert( i >= 0 && i <= 4 ); + m_nCOL_CORRECT_NUM_LOOKUPS = i; +#ifdef _DEBUG + m_bCOL_CORRECT_NUM_LOOKUPS = true; +#endif + } + void SetCOL_CORRECT_NUM_LOOKUPS( bool i ) + { + m_nCOL_CORRECT_NUM_LOOKUPS = i ? 1 : 0; +#ifdef _DEBUG + m_bCOL_CORRECT_NUM_LOOKUPS = true; +#endif + } +public: + engine_post_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bAA_ENABLE = false; +#endif // _DEBUG + m_nAA_ENABLE = 0; +#ifdef _DEBUG + m_bAA_QUALITY_MODE = false; +#endif // _DEBUG + m_nAA_QUALITY_MODE = 0; +#ifdef _DEBUG + m_bAA_REDUCE_ONE_PIXEL_LINE_BLUR = false; +#endif // _DEBUG + m_nAA_REDUCE_ONE_PIXEL_LINE_BLUR = 0; +#ifdef _DEBUG + m_bCOL_CORRECT_NUM_LOOKUPS = false; +#endif // _DEBUG + m_nCOL_CORRECT_NUM_LOOKUPS = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bAA_ENABLE && m_bAA_QUALITY_MODE && m_bAA_REDUCE_ONE_PIXEL_LINE_BLUR && m_bCOL_CORRECT_NUM_LOOKUPS; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nAA_ENABLE ) + ( 2 * m_nAA_QUALITY_MODE ) + ( 4 * m_nAA_REDUCE_ONE_PIXEL_LINE_BLUR ) + ( 8 * m_nCOL_CORRECT_NUM_LOOKUPS ) + 0; + } +}; +#define shaderDynamicTest_engine_post_ps20b psh_forgot_to_set_dynamic_AA_ENABLE + psh_forgot_to_set_dynamic_AA_QUALITY_MODE + psh_forgot_to_set_dynamic_AA_REDUCE_ONE_PIXEL_LINE_BLUR + psh_forgot_to_set_dynamic_COL_CORRECT_NUM_LOOKUPS + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/eye_refract_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/eye_refract_ps20.inc new file mode 100644 index 0000000..eb316dd --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/eye_refract_ps20.inc @@ -0,0 +1,112 @@ +#include "shaderlib/cshader.h" +class eye_refract_ps20_Static_Index +{ +private: + int m_nFLASHLIGHT; +#ifdef _DEBUG + bool m_bFLASHLIGHT; +#endif +public: + void SetFLASHLIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFLASHLIGHT = i; +#ifdef _DEBUG + m_bFLASHLIGHT = true; +#endif + } + void SetFLASHLIGHT( bool i ) + { + m_nFLASHLIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bFLASHLIGHT = true; +#endif + } +private: + int m_nLIGHTWARPTEXTURE; +#ifdef _DEBUG + bool m_bLIGHTWARPTEXTURE; +#endif +public: + void SetLIGHTWARPTEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nLIGHTWARPTEXTURE = i; +#ifdef _DEBUG + m_bLIGHTWARPTEXTURE = true; +#endif + } + void SetLIGHTWARPTEXTURE( bool i ) + { + m_nLIGHTWARPTEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bLIGHTWARPTEXTURE = true; +#endif + } +public: + eye_refract_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bFLASHLIGHT = false; +#endif // _DEBUG + m_nFLASHLIGHT = 0; +#ifdef _DEBUG + m_bLIGHTWARPTEXTURE = false; +#endif // _DEBUG + m_nLIGHTWARPTEXTURE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bFLASHLIGHT && m_bLIGHTWARPTEXTURE; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 3 * m_nFLASHLIGHT ) + ( 6 * m_nLIGHTWARPTEXTURE ) + 0; + } +}; +#define shaderStaticTest_eye_refract_ps20 psh_forgot_to_set_static_FLASHLIGHT + psh_forgot_to_set_static_LIGHTWARPTEXTURE + 0 +class eye_refract_ps20_Dynamic_Index +{ +private: + int m_nNUM_LIGHTS; +#ifdef _DEBUG + bool m_bNUM_LIGHTS; +#endif +public: + void SetNUM_LIGHTS( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nNUM_LIGHTS = i; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } + void SetNUM_LIGHTS( bool i ) + { + m_nNUM_LIGHTS = i ? 1 : 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } +public: + eye_refract_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bNUM_LIGHTS = false; +#endif // _DEBUG + m_nNUM_LIGHTS = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bNUM_LIGHTS; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nNUM_LIGHTS ) + 0; + } +}; +#define shaderDynamicTest_eye_refract_ps20 psh_forgot_to_set_dynamic_NUM_LIGHTS + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/eye_refract_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/eye_refract_ps20b.inc new file mode 100644 index 0000000..d79853f --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/eye_refract_ps20b.inc @@ -0,0 +1,212 @@ +#include "shaderlib/cshader.h" +class eye_refract_ps20b_Static_Index +{ +private: + int m_nFLASHLIGHT; +#ifdef _DEBUG + bool m_bFLASHLIGHT; +#endif +public: + void SetFLASHLIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFLASHLIGHT = i; +#ifdef _DEBUG + m_bFLASHLIGHT = true; +#endif + } + void SetFLASHLIGHT( bool i ) + { + m_nFLASHLIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bFLASHLIGHT = true; +#endif + } +private: + int m_nLIGHTWARPTEXTURE; +#ifdef _DEBUG + bool m_bLIGHTWARPTEXTURE; +#endif +public: + void SetLIGHTWARPTEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nLIGHTWARPTEXTURE = i; +#ifdef _DEBUG + m_bLIGHTWARPTEXTURE = true; +#endif + } + void SetLIGHTWARPTEXTURE( bool i ) + { + m_nLIGHTWARPTEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bLIGHTWARPTEXTURE = true; +#endif + } +private: + int m_nSPHERETEXKILLCOMBO; +#ifdef _DEBUG + bool m_bSPHERETEXKILLCOMBO; +#endif +public: + void SetSPHERETEXKILLCOMBO( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSPHERETEXKILLCOMBO = i; +#ifdef _DEBUG + m_bSPHERETEXKILLCOMBO = true; +#endif + } + void SetSPHERETEXKILLCOMBO( bool i ) + { + m_nSPHERETEXKILLCOMBO = i ? 1 : 0; +#ifdef _DEBUG + m_bSPHERETEXKILLCOMBO = true; +#endif + } +private: + int m_nRAYTRACESPHERE; +#ifdef _DEBUG + bool m_bRAYTRACESPHERE; +#endif +public: + void SetRAYTRACESPHERE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nRAYTRACESPHERE = i; +#ifdef _DEBUG + m_bRAYTRACESPHERE = true; +#endif + } + void SetRAYTRACESPHERE( bool i ) + { + m_nRAYTRACESPHERE = i ? 1 : 0; +#ifdef _DEBUG + m_bRAYTRACESPHERE = true; +#endif + } +private: + int m_nFLASHLIGHTDEPTHFILTERMODE; +#ifdef _DEBUG + bool m_bFLASHLIGHTDEPTHFILTERMODE; +#endif +public: + void SetFLASHLIGHTDEPTHFILTERMODE( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nFLASHLIGHTDEPTHFILTERMODE = i; +#ifdef _DEBUG + m_bFLASHLIGHTDEPTHFILTERMODE = true; +#endif + } + void SetFLASHLIGHTDEPTHFILTERMODE( bool i ) + { + m_nFLASHLIGHTDEPTHFILTERMODE = i ? 1 : 0; +#ifdef _DEBUG + m_bFLASHLIGHTDEPTHFILTERMODE = true; +#endif + } +public: + eye_refract_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bFLASHLIGHT = false; +#endif // _DEBUG + m_nFLASHLIGHT = 0; +#ifdef _DEBUG + m_bLIGHTWARPTEXTURE = false; +#endif // _DEBUG + m_nLIGHTWARPTEXTURE = 0; +#ifdef _DEBUG + m_bSPHERETEXKILLCOMBO = false; +#endif // _DEBUG + m_nSPHERETEXKILLCOMBO = 0; +#ifdef _DEBUG + m_bRAYTRACESPHERE = false; +#endif // _DEBUG + m_nRAYTRACESPHERE = 0; +#ifdef _DEBUG + m_bFLASHLIGHTDEPTHFILTERMODE = false; +#endif // _DEBUG + m_nFLASHLIGHTDEPTHFILTERMODE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bFLASHLIGHT && m_bLIGHTWARPTEXTURE && m_bSPHERETEXKILLCOMBO && m_bRAYTRACESPHERE && m_bFLASHLIGHTDEPTHFILTERMODE; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 10 * m_nFLASHLIGHT ) + ( 20 * m_nLIGHTWARPTEXTURE ) + ( 40 * m_nSPHERETEXKILLCOMBO ) + ( 80 * m_nRAYTRACESPHERE ) + ( 160 * m_nFLASHLIGHTDEPTHFILTERMODE ) + 0; + } +}; +#define shaderStaticTest_eye_refract_ps20b psh_forgot_to_set_static_FLASHLIGHT + psh_forgot_to_set_static_LIGHTWARPTEXTURE + psh_forgot_to_set_static_SPHERETEXKILLCOMBO + psh_forgot_to_set_static_RAYTRACESPHERE + psh_forgot_to_set_static_FLASHLIGHTDEPTHFILTERMODE + 0 +class eye_refract_ps20b_Dynamic_Index +{ +private: + int m_nNUM_LIGHTS; +#ifdef _DEBUG + bool m_bNUM_LIGHTS; +#endif +public: + void SetNUM_LIGHTS( int i ) + { + Assert( i >= 0 && i <= 4 ); + m_nNUM_LIGHTS = i; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } + void SetNUM_LIGHTS( bool i ) + { + m_nNUM_LIGHTS = i ? 1 : 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } +private: + int m_nFLASHLIGHTSHADOWS; +#ifdef _DEBUG + bool m_bFLASHLIGHTSHADOWS; +#endif +public: + void SetFLASHLIGHTSHADOWS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFLASHLIGHTSHADOWS = i; +#ifdef _DEBUG + m_bFLASHLIGHTSHADOWS = true; +#endif + } + void SetFLASHLIGHTSHADOWS( bool i ) + { + m_nFLASHLIGHTSHADOWS = i ? 1 : 0; +#ifdef _DEBUG + m_bFLASHLIGHTSHADOWS = true; +#endif + } +public: + eye_refract_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bNUM_LIGHTS = false; +#endif // _DEBUG + m_nNUM_LIGHTS = 0; +#ifdef _DEBUG + m_bFLASHLIGHTSHADOWS = false; +#endif // _DEBUG + m_nFLASHLIGHTSHADOWS = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bNUM_LIGHTS && m_bFLASHLIGHTSHADOWS; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nNUM_LIGHTS ) + ( 5 * m_nFLASHLIGHTSHADOWS ) + 0; + } +}; +#define shaderDynamicTest_eye_refract_ps20b psh_forgot_to_set_dynamic_NUM_LIGHTS + psh_forgot_to_set_dynamic_FLASHLIGHTSHADOWS + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/eye_refract_vs20.inc b/materialsystem/stdshaders/fxctmp9_360/eye_refract_vs20.inc new file mode 100644 index 0000000..a91fa7b --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/eye_refract_vs20.inc @@ -0,0 +1,287 @@ +#include "shaderlib/cshader.h" +class eye_refract_vs20_Static_Index +{ +private: + int m_nINTRO; +#ifdef _DEBUG + bool m_bINTRO; +#endif +public: + void SetINTRO( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nINTRO = i; +#ifdef _DEBUG + m_bINTRO = true; +#endif + } + void SetINTRO( bool i ) + { + m_nINTRO = i ? 1 : 0; +#ifdef _DEBUG + m_bINTRO = true; +#endif + } +private: + int m_nHALFLAMBERT; +#ifdef _DEBUG + bool m_bHALFLAMBERT; +#endif +public: + void SetHALFLAMBERT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHALFLAMBERT = i; +#ifdef _DEBUG + m_bHALFLAMBERT = true; +#endif + } + void SetHALFLAMBERT( bool i ) + { + m_nHALFLAMBERT = i ? 1 : 0; +#ifdef _DEBUG + m_bHALFLAMBERT = true; +#endif + } +private: + int m_nFLASHLIGHT; +#ifdef _DEBUG + bool m_bFLASHLIGHT; +#endif +public: + void SetFLASHLIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFLASHLIGHT = i; +#ifdef _DEBUG + m_bFLASHLIGHT = true; +#endif + } + void SetFLASHLIGHT( bool i ) + { + m_nFLASHLIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bFLASHLIGHT = true; +#endif + } +private: + int m_nLIGHTWARPTEXTURE; +#ifdef _DEBUG + bool m_bLIGHTWARPTEXTURE; +#endif +public: + void SetLIGHTWARPTEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nLIGHTWARPTEXTURE = i; +#ifdef _DEBUG + m_bLIGHTWARPTEXTURE = true; +#endif + } + void SetLIGHTWARPTEXTURE( bool i ) + { + m_nLIGHTWARPTEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bLIGHTWARPTEXTURE = true; +#endif + } +public: + eye_refract_vs20_Static_Index( ) + { +#ifdef _DEBUG + m_bINTRO = false; +#endif // _DEBUG + m_nINTRO = 0; +#ifdef _DEBUG + m_bHALFLAMBERT = false; +#endif // _DEBUG + m_nHALFLAMBERT = 0; +#ifdef _DEBUG + m_bFLASHLIGHT = false; +#endif // _DEBUG + m_nFLASHLIGHT = 0; +#ifdef _DEBUG + m_bLIGHTWARPTEXTURE = false; +#endif // _DEBUG + m_nLIGHTWARPTEXTURE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bINTRO && m_bHALFLAMBERT && m_bFLASHLIGHT && m_bLIGHTWARPTEXTURE; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 160 * m_nINTRO ) + ( 320 * m_nHALFLAMBERT ) + ( 640 * m_nFLASHLIGHT ) + ( 1280 * m_nLIGHTWARPTEXTURE ) + 0; + } +}; +#define shaderStaticTest_eye_refract_vs20 vsh_forgot_to_set_static_INTRO + vsh_forgot_to_set_static_HALFLAMBERT + vsh_forgot_to_set_static_FLASHLIGHT + vsh_forgot_to_set_static_LIGHTWARPTEXTURE + 0 +class eye_refract_vs20_Dynamic_Index +{ +private: + int m_nCOMPRESSED_VERTS; +#ifdef _DEBUG + bool m_bCOMPRESSED_VERTS; +#endif +public: + void SetCOMPRESSED_VERTS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOMPRESSED_VERTS = i; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } + void SetCOMPRESSED_VERTS( bool i ) + { + m_nCOMPRESSED_VERTS = i ? 1 : 0; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nDYNAMIC_LIGHT; +#ifdef _DEBUG + bool m_bDYNAMIC_LIGHT; +#endif +public: + void SetDYNAMIC_LIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDYNAMIC_LIGHT = i; +#ifdef _DEBUG + m_bDYNAMIC_LIGHT = true; +#endif + } + void SetDYNAMIC_LIGHT( bool i ) + { + m_nDYNAMIC_LIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bDYNAMIC_LIGHT = true; +#endif + } +private: + int m_nSTATIC_LIGHT; +#ifdef _DEBUG + bool m_bSTATIC_LIGHT; +#endif +public: + void SetSTATIC_LIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSTATIC_LIGHT = i; +#ifdef _DEBUG + m_bSTATIC_LIGHT = true; +#endif + } + void SetSTATIC_LIGHT( bool i ) + { + m_nSTATIC_LIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bSTATIC_LIGHT = true; +#endif + } +private: + int m_nNUM_LIGHTS; +#ifdef _DEBUG + bool m_bNUM_LIGHTS; +#endif +public: + void SetNUM_LIGHTS( int i ) + { + Assert( i >= 0 && i <= 4 ); + m_nNUM_LIGHTS = i; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } + void SetNUM_LIGHTS( bool i ) + { + m_nNUM_LIGHTS = i ? 1 : 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } +public: + eye_refract_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = false; +#endif // _DEBUG + m_nCOMPRESSED_VERTS = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bDYNAMIC_LIGHT = false; +#endif // _DEBUG + m_nDYNAMIC_LIGHT = 0; +#ifdef _DEBUG + m_bSTATIC_LIGHT = false; +#endif // _DEBUG + m_nSTATIC_LIGHT = 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = false; +#endif // _DEBUG + m_nNUM_LIGHTS = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bCOMPRESSED_VERTS && m_bSKINNING && m_bDOWATERFOG && m_bDYNAMIC_LIGHT && m_bSTATIC_LIGHT && m_bNUM_LIGHTS; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCOMPRESSED_VERTS ) + ( 2 * m_nSKINNING ) + ( 4 * m_nDOWATERFOG ) + ( 8 * m_nDYNAMIC_LIGHT ) + ( 16 * m_nSTATIC_LIGHT ) + ( 32 * m_nNUM_LIGHTS ) + 0; + } +}; +#define shaderDynamicTest_eye_refract_vs20 vsh_forgot_to_set_dynamic_COMPRESSED_VERTS + vsh_forgot_to_set_dynamic_SKINNING + vsh_forgot_to_set_dynamic_DOWATERFOG + vsh_forgot_to_set_dynamic_DYNAMIC_LIGHT + vsh_forgot_to_set_dynamic_STATIC_LIGHT + vsh_forgot_to_set_dynamic_NUM_LIGHTS + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/eyeglint_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/eyeglint_ps20.inc new file mode 100644 index 0000000..6b01552 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/eyeglint_ps20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class eyeglint_ps20_Static_Index +{ +public: + eyeglint_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_eyeglint_ps20 0 +class eyeglint_ps20_Dynamic_Index +{ +public: + eyeglint_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_eyeglint_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/eyeglint_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/eyeglint_ps20b.inc new file mode 100644 index 0000000..e58e118 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/eyeglint_ps20b.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class eyeglint_ps20b_Static_Index +{ +public: + eyeglint_ps20b_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_eyeglint_ps20b 0 +class eyeglint_ps20b_Dynamic_Index +{ +public: + eyeglint_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_eyeglint_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/eyeglint_vs20.inc b/materialsystem/stdshaders/fxctmp9_360/eyeglint_vs20.inc new file mode 100644 index 0000000..675f39c --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/eyeglint_vs20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class eyeglint_vs20_Static_Index +{ +public: + eyeglint_vs20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_eyeglint_vs20 0 +class eyeglint_vs20_Dynamic_Index +{ +public: + eyeglint_vs20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_eyeglint_vs20 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/eyes_flashlight_ps11.inc b/materialsystem/stdshaders/fxctmp9_360/eyes_flashlight_ps11.inc new file mode 100644 index 0000000..6292dd5 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/eyes_flashlight_ps11.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class eyes_flashlight_ps11_Static_Index +{ +public: + eyes_flashlight_ps11_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_eyes_flashlight_ps11 0 +class eyes_flashlight_ps11_Dynamic_Index +{ +public: + eyes_flashlight_ps11_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_eyes_flashlight_ps11 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/eyes_flashlight_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/eyes_flashlight_ps20.inc new file mode 100644 index 0000000..c353111 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/eyes_flashlight_ps20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class eyes_flashlight_ps20_Static_Index +{ +public: + eyes_flashlight_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_eyes_flashlight_ps20 0 +class eyes_flashlight_ps20_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + eyes_flashlight_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_eyes_flashlight_ps20 psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/eyes_flashlight_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/eyes_flashlight_ps20b.inc new file mode 100644 index 0000000..eba0593 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/eyes_flashlight_ps20b.inc @@ -0,0 +1,112 @@ +#include "shaderlib/cshader.h" +class eyes_flashlight_ps20b_Static_Index +{ +private: + int m_nFLASHLIGHTDEPTHFILTERMODE; +#ifdef _DEBUG + bool m_bFLASHLIGHTDEPTHFILTERMODE; +#endif +public: + void SetFLASHLIGHTDEPTHFILTERMODE( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nFLASHLIGHTDEPTHFILTERMODE = i; +#ifdef _DEBUG + m_bFLASHLIGHTDEPTHFILTERMODE = true; +#endif + } + void SetFLASHLIGHTDEPTHFILTERMODE( bool i ) + { + m_nFLASHLIGHTDEPTHFILTERMODE = i ? 1 : 0; +#ifdef _DEBUG + m_bFLASHLIGHTDEPTHFILTERMODE = true; +#endif + } +public: + eyes_flashlight_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bFLASHLIGHTDEPTHFILTERMODE = false; +#endif // _DEBUG + m_nFLASHLIGHTDEPTHFILTERMODE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bFLASHLIGHTDEPTHFILTERMODE; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 4 * m_nFLASHLIGHTDEPTHFILTERMODE ) + 0; + } +}; +#define shaderStaticTest_eyes_flashlight_ps20b psh_forgot_to_set_static_FLASHLIGHTDEPTHFILTERMODE + 0 +class eyes_flashlight_ps20b_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +private: + int m_nFLASHLIGHTSHADOWS; +#ifdef _DEBUG + bool m_bFLASHLIGHTSHADOWS; +#endif +public: + void SetFLASHLIGHTSHADOWS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFLASHLIGHTSHADOWS = i; +#ifdef _DEBUG + m_bFLASHLIGHTSHADOWS = true; +#endif + } + void SetFLASHLIGHTSHADOWS( bool i ) + { + m_nFLASHLIGHTSHADOWS = i ? 1 : 0; +#ifdef _DEBUG + m_bFLASHLIGHTSHADOWS = true; +#endif + } +public: + eyes_flashlight_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; +#ifdef _DEBUG + m_bFLASHLIGHTSHADOWS = false; +#endif // _DEBUG + m_nFLASHLIGHTSHADOWS = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE && m_bFLASHLIGHTSHADOWS; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + ( 2 * m_nFLASHLIGHTSHADOWS ) + 0; + } +}; +#define shaderDynamicTest_eyes_flashlight_ps20b psh_forgot_to_set_dynamic_PIXELFOGTYPE + psh_forgot_to_set_dynamic_FLASHLIGHTSHADOWS + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/eyes_flashlight_vs20.inc b/materialsystem/stdshaders/fxctmp9_360/eyes_flashlight_vs20.inc new file mode 100644 index 0000000..5abcd81 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/eyes_flashlight_vs20.inc @@ -0,0 +1,110 @@ +#include "shaderlib/cshader.h" +class eyes_flashlight_vs20_Static_Index +{ +public: + eyes_flashlight_vs20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_eyes_flashlight_vs20 0 +class eyes_flashlight_vs20_Dynamic_Index +{ +private: + int m_nCOMPRESSED_VERTS; +#ifdef _DEBUG + bool m_bCOMPRESSED_VERTS; +#endif +public: + void SetCOMPRESSED_VERTS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOMPRESSED_VERTS = i; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } + void SetCOMPRESSED_VERTS( bool i ) + { + m_nCOMPRESSED_VERTS = i ? 1 : 0; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + eyes_flashlight_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = false; +#endif // _DEBUG + m_nCOMPRESSED_VERTS = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bCOMPRESSED_VERTS && m_bSKINNING && m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCOMPRESSED_VERTS ) + ( 2 * m_nSKINNING ) + ( 4 * m_nDOWATERFOG ) + 0; + } +}; +#define shaderDynamicTest_eyes_flashlight_vs20 vsh_forgot_to_set_dynamic_COMPRESSED_VERTS + vsh_forgot_to_set_dynamic_SKINNING + vsh_forgot_to_set_dynamic_DOWATERFOG + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/eyes_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/eyes_ps20.inc new file mode 100644 index 0000000..e3a2b4c --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/eyes_ps20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class eyes_ps20_Static_Index +{ +public: + eyes_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_eyes_ps20 0 +class eyes_ps20_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + eyes_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_eyes_ps20 psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/eyes_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/eyes_ps20b.inc new file mode 100644 index 0000000..c179026 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/eyes_ps20b.inc @@ -0,0 +1,85 @@ +#include "shaderlib/cshader.h" +class eyes_ps20b_Static_Index +{ +public: + eyes_ps20b_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_eyes_ps20b 0 +class eyes_ps20b_Dynamic_Index +{ +private: + int m_nWRITE_DEPTH_TO_DESTALPHA; +#ifdef _DEBUG + bool m_bWRITE_DEPTH_TO_DESTALPHA; +#endif +public: + void SetWRITE_DEPTH_TO_DESTALPHA( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nWRITE_DEPTH_TO_DESTALPHA = i; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = true; +#endif + } + void SetWRITE_DEPTH_TO_DESTALPHA( bool i ) + { + m_nWRITE_DEPTH_TO_DESTALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = true; +#endif + } +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + eyes_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = false; +#endif // _DEBUG + m_nWRITE_DEPTH_TO_DESTALPHA = 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bWRITE_DEPTH_TO_DESTALPHA && m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nWRITE_DEPTH_TO_DESTALPHA ) + ( 1 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_eyes_ps20b psh_forgot_to_set_dynamic_WRITE_DEPTH_TO_DESTALPHA + psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/eyes_vs20.inc b/materialsystem/stdshaders/fxctmp9_360/eyes_vs20.inc new file mode 100644 index 0000000..adc6fff --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/eyes_vs20.inc @@ -0,0 +1,262 @@ +#include "shaderlib/cshader.h" +class eyes_vs20_Static_Index +{ +private: + int m_nINTRO; +#ifdef _DEBUG + bool m_bINTRO; +#endif +public: + void SetINTRO( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nINTRO = i; +#ifdef _DEBUG + m_bINTRO = true; +#endif + } + void SetINTRO( bool i ) + { + m_nINTRO = i ? 1 : 0; +#ifdef _DEBUG + m_bINTRO = true; +#endif + } +private: + int m_nHALFLAMBERT; +#ifdef _DEBUG + bool m_bHALFLAMBERT; +#endif +public: + void SetHALFLAMBERT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHALFLAMBERT = i; +#ifdef _DEBUG + m_bHALFLAMBERT = true; +#endif + } + void SetHALFLAMBERT( bool i ) + { + m_nHALFLAMBERT = i ? 1 : 0; +#ifdef _DEBUG + m_bHALFLAMBERT = true; +#endif + } +private: + int m_nUSE_STATIC_CONTROL_FLOW; +#ifdef _DEBUG + bool m_bUSE_STATIC_CONTROL_FLOW; +#endif +public: + void SetUSE_STATIC_CONTROL_FLOW( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nUSE_STATIC_CONTROL_FLOW = i; +#ifdef _DEBUG + m_bUSE_STATIC_CONTROL_FLOW = true; +#endif + } + void SetUSE_STATIC_CONTROL_FLOW( bool i ) + { + m_nUSE_STATIC_CONTROL_FLOW = i ? 1 : 0; +#ifdef _DEBUG + m_bUSE_STATIC_CONTROL_FLOW = true; +#endif + } +public: + eyes_vs20_Static_Index( ) + { +#ifdef _DEBUG + m_bINTRO = false; +#endif // _DEBUG + m_nINTRO = 0; +#ifdef _DEBUG + m_bHALFLAMBERT = false; +#endif // _DEBUG + m_nHALFLAMBERT = 0; +#ifdef _DEBUG + m_bUSE_STATIC_CONTROL_FLOW = false; +#endif // _DEBUG + m_nUSE_STATIC_CONTROL_FLOW = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bINTRO && m_bHALFLAMBERT && m_bUSE_STATIC_CONTROL_FLOW; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 96 * m_nINTRO ) + ( 192 * m_nHALFLAMBERT ) + ( 384 * m_nUSE_STATIC_CONTROL_FLOW ) + 0; + } +}; +#define shaderStaticTest_eyes_vs20 vsh_forgot_to_set_static_INTRO + vsh_forgot_to_set_static_HALFLAMBERT + vsh_forgot_to_set_static_USE_STATIC_CONTROL_FLOW + 0 +class eyes_vs20_Dynamic_Index +{ +private: + int m_nCOMPRESSED_VERTS; +#ifdef _DEBUG + bool m_bCOMPRESSED_VERTS; +#endif +public: + void SetCOMPRESSED_VERTS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOMPRESSED_VERTS = i; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } + void SetCOMPRESSED_VERTS( bool i ) + { + m_nCOMPRESSED_VERTS = i ? 1 : 0; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nDYNAMIC_LIGHT; +#ifdef _DEBUG + bool m_bDYNAMIC_LIGHT; +#endif +public: + void SetDYNAMIC_LIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDYNAMIC_LIGHT = i; +#ifdef _DEBUG + m_bDYNAMIC_LIGHT = true; +#endif + } + void SetDYNAMIC_LIGHT( bool i ) + { + m_nDYNAMIC_LIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bDYNAMIC_LIGHT = true; +#endif + } +private: + int m_nSTATIC_LIGHT; +#ifdef _DEBUG + bool m_bSTATIC_LIGHT; +#endif +public: + void SetSTATIC_LIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSTATIC_LIGHT = i; +#ifdef _DEBUG + m_bSTATIC_LIGHT = true; +#endif + } + void SetSTATIC_LIGHT( bool i ) + { + m_nSTATIC_LIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bSTATIC_LIGHT = true; +#endif + } +private: + int m_nNUM_LIGHTS; +#ifdef _DEBUG + bool m_bNUM_LIGHTS; +#endif +public: + void SetNUM_LIGHTS( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nNUM_LIGHTS = i; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } + void SetNUM_LIGHTS( bool i ) + { + m_nNUM_LIGHTS = i ? 1 : 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } +public: + eyes_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = false; +#endif // _DEBUG + m_nCOMPRESSED_VERTS = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bDYNAMIC_LIGHT = false; +#endif // _DEBUG + m_nDYNAMIC_LIGHT = 0; +#ifdef _DEBUG + m_bSTATIC_LIGHT = false; +#endif // _DEBUG + m_nSTATIC_LIGHT = 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = false; +#endif // _DEBUG + m_nNUM_LIGHTS = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bCOMPRESSED_VERTS && m_bSKINNING && m_bDOWATERFOG && m_bDYNAMIC_LIGHT && m_bSTATIC_LIGHT && m_bNUM_LIGHTS; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCOMPRESSED_VERTS ) + ( 2 * m_nSKINNING ) + ( 4 * m_nDOWATERFOG ) + ( 8 * m_nDYNAMIC_LIGHT ) + ( 16 * m_nSTATIC_LIGHT ) + ( 32 * m_nNUM_LIGHTS ) + 0; + } +}; +#define shaderDynamicTest_eyes_vs20 vsh_forgot_to_set_dynamic_COMPRESSED_VERTS + vsh_forgot_to_set_dynamic_SKINNING + vsh_forgot_to_set_dynamic_DOWATERFOG + vsh_forgot_to_set_dynamic_DYNAMIC_LIGHT + vsh_forgot_to_set_dynamic_STATIC_LIGHT + vsh_forgot_to_set_dynamic_NUM_LIGHTS + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/fillrate_ps11.inc b/materialsystem/stdshaders/fxctmp9_360/fillrate_ps11.inc new file mode 100644 index 0000000..1bccfd0 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/fillrate_ps11.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class fillrate_ps11_Static_Index +{ +public: + fillrate_ps11_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_fillrate_ps11 0 +class fillrate_ps11_Dynamic_Index +{ +public: + fillrate_ps11_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_fillrate_ps11 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/fillrate_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/fillrate_ps20.inc new file mode 100644 index 0000000..b2f8554 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/fillrate_ps20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class fillrate_ps20_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + fillrate_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_fillrate_ps20 0 +class fillrate_ps20_Dynamic_Index +{ +public: + fillrate_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_fillrate_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/fillrate_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/fillrate_ps20b.inc new file mode 100644 index 0000000..34b6c78 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/fillrate_ps20b.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class fillrate_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + fillrate_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_fillrate_ps20b 0 +class fillrate_ps20b_Dynamic_Index +{ +public: + fillrate_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_fillrate_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/fillrate_vs11.inc b/materialsystem/stdshaders/fxctmp9_360/fillrate_vs11.inc new file mode 100644 index 0000000..93cae13 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/fillrate_vs11.inc @@ -0,0 +1,85 @@ +#include "shaderlib/cshader.h" +class fillrate_vs11_Static_Index +{ +public: + fillrate_vs11_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_fillrate_vs11 0 +class fillrate_vs11_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +public: + fillrate_vs11_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG && m_bSKINNING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + ( 2 * m_nSKINNING ) + 0; + } +}; +#define shaderDynamicTest_fillrate_vs11 vsh_forgot_to_set_dynamic_DOWATERFOG + vsh_forgot_to_set_dynamic_SKINNING + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/fillrate_vs20.inc b/materialsystem/stdshaders/fxctmp9_360/fillrate_vs20.inc new file mode 100644 index 0000000..6ef8914 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/fillrate_vs20.inc @@ -0,0 +1,85 @@ +#include "shaderlib/cshader.h" +class fillrate_vs20_Static_Index +{ +public: + fillrate_vs20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_fillrate_vs20 0 +class fillrate_vs20_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +public: + fillrate_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG && m_bSKINNING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + ( 2 * m_nSKINNING ) + 0; + } +}; +#define shaderDynamicTest_fillrate_vs20 vsh_forgot_to_set_dynamic_DOWATERFOG + vsh_forgot_to_set_dynamic_SKINNING + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/filmdust_ps11.inc b/materialsystem/stdshaders/fxctmp9_360/filmdust_ps11.inc new file mode 100644 index 0000000..8cee92b --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/filmdust_ps11.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class filmdust_ps11_Static_Index +{ +public: + filmdust_ps11_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_filmdust_ps11 0 +class filmdust_ps11_Dynamic_Index +{ +public: + filmdust_ps11_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_filmdust_ps11 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/filmdust_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/filmdust_ps20.inc new file mode 100644 index 0000000..0db6ecb --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/filmdust_ps20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class filmdust_ps20_Static_Index +{ +public: + filmdust_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_filmdust_ps20 0 +class filmdust_ps20_Dynamic_Index +{ +public: + filmdust_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_filmdust_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/filmgrain_ps11.inc b/materialsystem/stdshaders/fxctmp9_360/filmgrain_ps11.inc new file mode 100644 index 0000000..2281d84 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/filmgrain_ps11.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class filmgrain_ps11_Static_Index +{ +public: + filmgrain_ps11_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_filmgrain_ps11 0 +class filmgrain_ps11_Dynamic_Index +{ +public: + filmgrain_ps11_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_filmgrain_ps11 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/filmgrain_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/filmgrain_ps20.inc new file mode 100644 index 0000000..ee09ea7 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/filmgrain_ps20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class filmgrain_ps20_Static_Index +{ +public: + filmgrain_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_filmgrain_ps20 0 +class filmgrain_ps20_Dynamic_Index +{ +public: + filmgrain_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_filmgrain_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/filmgrain_vs20.inc b/materialsystem/stdshaders/fxctmp9_360/filmgrain_vs20.inc new file mode 100644 index 0000000..76f4842 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/filmgrain_vs20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class filmgrain_vs20_Static_Index +{ +public: + filmgrain_vs20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_filmgrain_vs20 0 +class filmgrain_vs20_Dynamic_Index +{ +public: + filmgrain_vs20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_filmgrain_vs20 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/flashlight_ps11.inc b/materialsystem/stdshaders/fxctmp9_360/flashlight_ps11.inc new file mode 100644 index 0000000..64a4148 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/flashlight_ps11.inc @@ -0,0 +1,85 @@ +#include "shaderlib/cshader.h" +class flashlight_ps11_Static_Index +{ +private: + int m_nNORMALMAP; +#ifdef _DEBUG + bool m_bNORMALMAP; +#endif +public: + void SetNORMALMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nNORMALMAP = i; +#ifdef _DEBUG + m_bNORMALMAP = true; +#endif + } + void SetNORMALMAP( bool i ) + { + m_nNORMALMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bNORMALMAP = true; +#endif + } +private: + int m_nNOCULL; +#ifdef _DEBUG + bool m_bNOCULL; +#endif +public: + void SetNOCULL( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nNOCULL = i; +#ifdef _DEBUG + m_bNOCULL = true; +#endif + } + void SetNOCULL( bool i ) + { + m_nNOCULL = i ? 1 : 0; +#ifdef _DEBUG + m_bNOCULL = true; +#endif + } +public: + flashlight_ps11_Static_Index( ) + { +#ifdef _DEBUG + m_bNORMALMAP = false; +#endif // _DEBUG + m_nNORMALMAP = 0; +#ifdef _DEBUG + m_bNOCULL = false; +#endif // _DEBUG + m_nNOCULL = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bNORMALMAP && m_bNOCULL; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nNORMALMAP ) + ( 2 * m_nNOCULL ) + 0; + } +}; +#define shaderStaticTest_flashlight_ps11 psh_forgot_to_set_static_NORMALMAP + psh_forgot_to_set_static_NOCULL + 0 +class flashlight_ps11_Dynamic_Index +{ +public: + flashlight_ps11_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_flashlight_ps11 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/flashlight_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/flashlight_ps20.inc new file mode 100644 index 0000000..c98a45d --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/flashlight_ps20.inc @@ -0,0 +1,212 @@ +#include "shaderlib/cshader.h" +class flashlight_ps20_Static_Index +{ +private: + int m_nNORMALMAP; +#ifdef _DEBUG + bool m_bNORMALMAP; +#endif +public: + void SetNORMALMAP( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nNORMALMAP = i; +#ifdef _DEBUG + m_bNORMALMAP = true; +#endif + } + void SetNORMALMAP( bool i ) + { + m_nNORMALMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bNORMALMAP = true; +#endif + } +private: + int m_nNORMALMAP2; +#ifdef _DEBUG + bool m_bNORMALMAP2; +#endif +public: + void SetNORMALMAP2( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nNORMALMAP2 = i; +#ifdef _DEBUG + m_bNORMALMAP2 = true; +#endif + } + void SetNORMALMAP2( bool i ) + { + m_nNORMALMAP2 = i ? 1 : 0; +#ifdef _DEBUG + m_bNORMALMAP2 = true; +#endif + } +private: + int m_nWORLDVERTEXTRANSITION; +#ifdef _DEBUG + bool m_bWORLDVERTEXTRANSITION; +#endif +public: + void SetWORLDVERTEXTRANSITION( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nWORLDVERTEXTRANSITION = i; +#ifdef _DEBUG + m_bWORLDVERTEXTRANSITION = true; +#endif + } + void SetWORLDVERTEXTRANSITION( bool i ) + { + m_nWORLDVERTEXTRANSITION = i ? 1 : 0; +#ifdef _DEBUG + m_bWORLDVERTEXTRANSITION = true; +#endif + } +private: + int m_nSEAMLESS; +#ifdef _DEBUG + bool m_bSEAMLESS; +#endif +public: + void SetSEAMLESS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSEAMLESS = i; +#ifdef _DEBUG + m_bSEAMLESS = true; +#endif + } + void SetSEAMLESS( bool i ) + { + m_nSEAMLESS = i ? 1 : 0; +#ifdef _DEBUG + m_bSEAMLESS = true; +#endif + } +private: + int m_nDETAILTEXTURE; +#ifdef _DEBUG + bool m_bDETAILTEXTURE; +#endif +public: + void SetDETAILTEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDETAILTEXTURE = i; +#ifdef _DEBUG + m_bDETAILTEXTURE = true; +#endif + } + void SetDETAILTEXTURE( bool i ) + { + m_nDETAILTEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bDETAILTEXTURE = true; +#endif + } +private: + int m_nDETAIL_BLEND_MODE; +#ifdef _DEBUG + bool m_bDETAIL_BLEND_MODE; +#endif +public: + void SetDETAIL_BLEND_MODE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDETAIL_BLEND_MODE = i; +#ifdef _DEBUG + m_bDETAIL_BLEND_MODE = true; +#endif + } + void SetDETAIL_BLEND_MODE( bool i ) + { + m_nDETAIL_BLEND_MODE = i ? 1 : 0; +#ifdef _DEBUG + m_bDETAIL_BLEND_MODE = true; +#endif + } +public: + flashlight_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bNORMALMAP = false; +#endif // _DEBUG + m_nNORMALMAP = 0; +#ifdef _DEBUG + m_bNORMALMAP2 = false; +#endif // _DEBUG + m_nNORMALMAP2 = 0; +#ifdef _DEBUG + m_bWORLDVERTEXTRANSITION = false; +#endif // _DEBUG + m_nWORLDVERTEXTRANSITION = 0; +#ifdef _DEBUG + m_bSEAMLESS = false; +#endif // _DEBUG + m_nSEAMLESS = 0; +#ifdef _DEBUG + m_bDETAILTEXTURE = false; +#endif // _DEBUG + m_nDETAILTEXTURE = 0; +#ifdef _DEBUG + m_bDETAIL_BLEND_MODE = false; +#endif // _DEBUG + m_nDETAIL_BLEND_MODE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bNORMALMAP && m_bNORMALMAP2 && m_bWORLDVERTEXTRANSITION && m_bSEAMLESS && m_bDETAILTEXTURE && m_bDETAIL_BLEND_MODE; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nNORMALMAP ) + ( 6 * m_nNORMALMAP2 ) + ( 12 * m_nWORLDVERTEXTRANSITION ) + ( 24 * m_nSEAMLESS ) + ( 48 * m_nDETAILTEXTURE ) + ( 96 * m_nDETAIL_BLEND_MODE ) + 0; + } +}; +#define shaderStaticTest_flashlight_ps20 psh_forgot_to_set_static_NORMALMAP + psh_forgot_to_set_static_NORMALMAP2 + psh_forgot_to_set_static_WORLDVERTEXTRANSITION + psh_forgot_to_set_static_SEAMLESS + psh_forgot_to_set_static_DETAILTEXTURE + psh_forgot_to_set_static_DETAIL_BLEND_MODE + 0 +class flashlight_ps20_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + flashlight_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_flashlight_ps20 psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/flashlight_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/flashlight_ps20b.inc new file mode 100644 index 0000000..2478fcd --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/flashlight_ps20b.inc @@ -0,0 +1,262 @@ +#include "shaderlib/cshader.h" +class flashlight_ps20b_Static_Index +{ +private: + int m_nNORMALMAP; +#ifdef _DEBUG + bool m_bNORMALMAP; +#endif +public: + void SetNORMALMAP( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nNORMALMAP = i; +#ifdef _DEBUG + m_bNORMALMAP = true; +#endif + } + void SetNORMALMAP( bool i ) + { + m_nNORMALMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bNORMALMAP = true; +#endif + } +private: + int m_nNORMALMAP2; +#ifdef _DEBUG + bool m_bNORMALMAP2; +#endif +public: + void SetNORMALMAP2( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nNORMALMAP2 = i; +#ifdef _DEBUG + m_bNORMALMAP2 = true; +#endif + } + void SetNORMALMAP2( bool i ) + { + m_nNORMALMAP2 = i ? 1 : 0; +#ifdef _DEBUG + m_bNORMALMAP2 = true; +#endif + } +private: + int m_nWORLDVERTEXTRANSITION; +#ifdef _DEBUG + bool m_bWORLDVERTEXTRANSITION; +#endif +public: + void SetWORLDVERTEXTRANSITION( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nWORLDVERTEXTRANSITION = i; +#ifdef _DEBUG + m_bWORLDVERTEXTRANSITION = true; +#endif + } + void SetWORLDVERTEXTRANSITION( bool i ) + { + m_nWORLDVERTEXTRANSITION = i ? 1 : 0; +#ifdef _DEBUG + m_bWORLDVERTEXTRANSITION = true; +#endif + } +private: + int m_nSEAMLESS; +#ifdef _DEBUG + bool m_bSEAMLESS; +#endif +public: + void SetSEAMLESS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSEAMLESS = i; +#ifdef _DEBUG + m_bSEAMLESS = true; +#endif + } + void SetSEAMLESS( bool i ) + { + m_nSEAMLESS = i ? 1 : 0; +#ifdef _DEBUG + m_bSEAMLESS = true; +#endif + } +private: + int m_nDETAILTEXTURE; +#ifdef _DEBUG + bool m_bDETAILTEXTURE; +#endif +public: + void SetDETAILTEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDETAILTEXTURE = i; +#ifdef _DEBUG + m_bDETAILTEXTURE = true; +#endif + } + void SetDETAILTEXTURE( bool i ) + { + m_nDETAILTEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bDETAILTEXTURE = true; +#endif + } +private: + int m_nDETAIL_BLEND_MODE; +#ifdef _DEBUG + bool m_bDETAIL_BLEND_MODE; +#endif +public: + void SetDETAIL_BLEND_MODE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDETAIL_BLEND_MODE = i; +#ifdef _DEBUG + m_bDETAIL_BLEND_MODE = true; +#endif + } + void SetDETAIL_BLEND_MODE( bool i ) + { + m_nDETAIL_BLEND_MODE = i ? 1 : 0; +#ifdef _DEBUG + m_bDETAIL_BLEND_MODE = true; +#endif + } +private: + int m_nFLASHLIGHTDEPTHFILTERMODE; +#ifdef _DEBUG + bool m_bFLASHLIGHTDEPTHFILTERMODE; +#endif +public: + void SetFLASHLIGHTDEPTHFILTERMODE( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nFLASHLIGHTDEPTHFILTERMODE = i; +#ifdef _DEBUG + m_bFLASHLIGHTDEPTHFILTERMODE = true; +#endif + } + void SetFLASHLIGHTDEPTHFILTERMODE( bool i ) + { + m_nFLASHLIGHTDEPTHFILTERMODE = i ? 1 : 0; +#ifdef _DEBUG + m_bFLASHLIGHTDEPTHFILTERMODE = true; +#endif + } +public: + flashlight_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bNORMALMAP = false; +#endif // _DEBUG + m_nNORMALMAP = 0; +#ifdef _DEBUG + m_bNORMALMAP2 = false; +#endif // _DEBUG + m_nNORMALMAP2 = 0; +#ifdef _DEBUG + m_bWORLDVERTEXTRANSITION = false; +#endif // _DEBUG + m_nWORLDVERTEXTRANSITION = 0; +#ifdef _DEBUG + m_bSEAMLESS = false; +#endif // _DEBUG + m_nSEAMLESS = 0; +#ifdef _DEBUG + m_bDETAILTEXTURE = false; +#endif // _DEBUG + m_nDETAILTEXTURE = 0; +#ifdef _DEBUG + m_bDETAIL_BLEND_MODE = false; +#endif // _DEBUG + m_nDETAIL_BLEND_MODE = 0; +#ifdef _DEBUG + m_bFLASHLIGHTDEPTHFILTERMODE = false; +#endif // _DEBUG + m_nFLASHLIGHTDEPTHFILTERMODE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bNORMALMAP && m_bNORMALMAP2 && m_bWORLDVERTEXTRANSITION && m_bSEAMLESS && m_bDETAILTEXTURE && m_bDETAIL_BLEND_MODE && m_bFLASHLIGHTDEPTHFILTERMODE; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 4 * m_nNORMALMAP ) + ( 12 * m_nNORMALMAP2 ) + ( 24 * m_nWORLDVERTEXTRANSITION ) + ( 48 * m_nSEAMLESS ) + ( 96 * m_nDETAILTEXTURE ) + ( 192 * m_nDETAIL_BLEND_MODE ) + ( 384 * m_nFLASHLIGHTDEPTHFILTERMODE ) + 0; + } +}; +#define shaderStaticTest_flashlight_ps20b psh_forgot_to_set_static_NORMALMAP + psh_forgot_to_set_static_NORMALMAP2 + psh_forgot_to_set_static_WORLDVERTEXTRANSITION + psh_forgot_to_set_static_SEAMLESS + psh_forgot_to_set_static_DETAILTEXTURE + psh_forgot_to_set_static_DETAIL_BLEND_MODE + psh_forgot_to_set_static_FLASHLIGHTDEPTHFILTERMODE + 0 +class flashlight_ps20b_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +private: + int m_nFLASHLIGHTSHADOWS; +#ifdef _DEBUG + bool m_bFLASHLIGHTSHADOWS; +#endif +public: + void SetFLASHLIGHTSHADOWS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFLASHLIGHTSHADOWS = i; +#ifdef _DEBUG + m_bFLASHLIGHTSHADOWS = true; +#endif + } + void SetFLASHLIGHTSHADOWS( bool i ) + { + m_nFLASHLIGHTSHADOWS = i ? 1 : 0; +#ifdef _DEBUG + m_bFLASHLIGHTSHADOWS = true; +#endif + } +public: + flashlight_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; +#ifdef _DEBUG + m_bFLASHLIGHTSHADOWS = false; +#endif // _DEBUG + m_nFLASHLIGHTSHADOWS = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE && m_bFLASHLIGHTSHADOWS; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + ( 2 * m_nFLASHLIGHTSHADOWS ) + 0; + } +}; +#define shaderDynamicTest_flashlight_ps20b psh_forgot_to_set_dynamic_PIXELFOGTYPE + psh_forgot_to_set_dynamic_FLASHLIGHTSHADOWS + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/flesh_interior_blended_pass_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/flesh_interior_blended_pass_ps20.inc new file mode 100644 index 0000000..ce52a0d --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/flesh_interior_blended_pass_ps20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class flesh_interior_blended_pass_ps20_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + flesh_interior_blended_pass_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_flesh_interior_blended_pass_ps20 0 +class flesh_interior_blended_pass_ps20_Dynamic_Index +{ +public: + flesh_interior_blended_pass_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_flesh_interior_blended_pass_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/flesh_interior_blended_pass_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/flesh_interior_blended_pass_ps20b.inc new file mode 100644 index 0000000..6c90282 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/flesh_interior_blended_pass_ps20b.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class flesh_interior_blended_pass_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + flesh_interior_blended_pass_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_flesh_interior_blended_pass_ps20b 0 +class flesh_interior_blended_pass_ps20b_Dynamic_Index +{ +public: + flesh_interior_blended_pass_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_flesh_interior_blended_pass_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/flesh_interior_blended_pass_vs20.inc b/materialsystem/stdshaders/fxctmp9_360/flesh_interior_blended_pass_vs20.inc new file mode 100644 index 0000000..2b7143e --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/flesh_interior_blended_pass_vs20.inc @@ -0,0 +1,237 @@ +#include "shaderlib/cshader.h" +class flesh_interior_blended_pass_vs20_Static_Index +{ +private: + int m_nHALFLAMBERT; +#ifdef _DEBUG + bool m_bHALFLAMBERT; +#endif +public: + void SetHALFLAMBERT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHALFLAMBERT = i; +#ifdef _DEBUG + m_bHALFLAMBERT = true; +#endif + } + void SetHALFLAMBERT( bool i ) + { + m_nHALFLAMBERT = i ? 1 : 0; +#ifdef _DEBUG + m_bHALFLAMBERT = true; +#endif + } +private: + int m_nUSE_STATIC_CONTROL_FLOW; +#ifdef _DEBUG + bool m_bUSE_STATIC_CONTROL_FLOW; +#endif +public: + void SetUSE_STATIC_CONTROL_FLOW( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nUSE_STATIC_CONTROL_FLOW = i; +#ifdef _DEBUG + m_bUSE_STATIC_CONTROL_FLOW = true; +#endif + } + void SetUSE_STATIC_CONTROL_FLOW( bool i ) + { + m_nUSE_STATIC_CONTROL_FLOW = i ? 1 : 0; +#ifdef _DEBUG + m_bUSE_STATIC_CONTROL_FLOW = true; +#endif + } +public: + flesh_interior_blended_pass_vs20_Static_Index( ) + { +#ifdef _DEBUG + m_bHALFLAMBERT = false; +#endif // _DEBUG + m_nHALFLAMBERT = 0; +#ifdef _DEBUG + m_bUSE_STATIC_CONTROL_FLOW = false; +#endif // _DEBUG + m_nUSE_STATIC_CONTROL_FLOW = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bHALFLAMBERT && m_bUSE_STATIC_CONTROL_FLOW; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 96 * m_nHALFLAMBERT ) + ( 192 * m_nUSE_STATIC_CONTROL_FLOW ) + 0; + } +}; +#define shaderStaticTest_flesh_interior_blended_pass_vs20 vsh_forgot_to_set_static_HALFLAMBERT + vsh_forgot_to_set_static_USE_STATIC_CONTROL_FLOW + 0 +class flesh_interior_blended_pass_vs20_Dynamic_Index +{ +private: + int m_nCOMPRESSED_VERTS; +#ifdef _DEBUG + bool m_bCOMPRESSED_VERTS; +#endif +public: + void SetCOMPRESSED_VERTS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOMPRESSED_VERTS = i; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } + void SetCOMPRESSED_VERTS( bool i ) + { + m_nCOMPRESSED_VERTS = i ? 1 : 0; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nDYNAMIC_LIGHT; +#ifdef _DEBUG + bool m_bDYNAMIC_LIGHT; +#endif +public: + void SetDYNAMIC_LIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDYNAMIC_LIGHT = i; +#ifdef _DEBUG + m_bDYNAMIC_LIGHT = true; +#endif + } + void SetDYNAMIC_LIGHT( bool i ) + { + m_nDYNAMIC_LIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bDYNAMIC_LIGHT = true; +#endif + } +private: + int m_nSTATIC_LIGHT; +#ifdef _DEBUG + bool m_bSTATIC_LIGHT; +#endif +public: + void SetSTATIC_LIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSTATIC_LIGHT = i; +#ifdef _DEBUG + m_bSTATIC_LIGHT = true; +#endif + } + void SetSTATIC_LIGHT( bool i ) + { + m_nSTATIC_LIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bSTATIC_LIGHT = true; +#endif + } +private: + int m_nNUM_LIGHTS; +#ifdef _DEBUG + bool m_bNUM_LIGHTS; +#endif +public: + void SetNUM_LIGHTS( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nNUM_LIGHTS = i; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } + void SetNUM_LIGHTS( bool i ) + { + m_nNUM_LIGHTS = i ? 1 : 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } +public: + flesh_interior_blended_pass_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = false; +#endif // _DEBUG + m_nCOMPRESSED_VERTS = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bDYNAMIC_LIGHT = false; +#endif // _DEBUG + m_nDYNAMIC_LIGHT = 0; +#ifdef _DEBUG + m_bSTATIC_LIGHT = false; +#endif // _DEBUG + m_nSTATIC_LIGHT = 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = false; +#endif // _DEBUG + m_nNUM_LIGHTS = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bCOMPRESSED_VERTS && m_bSKINNING && m_bDOWATERFOG && m_bDYNAMIC_LIGHT && m_bSTATIC_LIGHT && m_bNUM_LIGHTS; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCOMPRESSED_VERTS ) + ( 2 * m_nSKINNING ) + ( 4 * m_nDOWATERFOG ) + ( 8 * m_nDYNAMIC_LIGHT ) + ( 16 * m_nSTATIC_LIGHT ) + ( 32 * m_nNUM_LIGHTS ) + 0; + } +}; +#define shaderDynamicTest_flesh_interior_blended_pass_vs20 vsh_forgot_to_set_dynamic_COMPRESSED_VERTS + vsh_forgot_to_set_dynamic_SKINNING + vsh_forgot_to_set_dynamic_DOWATERFOG + vsh_forgot_to_set_dynamic_DYNAMIC_LIGHT + vsh_forgot_to_set_dynamic_STATIC_LIGHT + vsh_forgot_to_set_dynamic_NUM_LIGHTS + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/floatcombine_autoexpose_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/floatcombine_autoexpose_ps20.inc new file mode 100644 index 0000000..b43ae15 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/floatcombine_autoexpose_ps20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class floatcombine_autoexpose_ps20_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + floatcombine_autoexpose_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_floatcombine_autoexpose_ps20 0 +class floatcombine_autoexpose_ps20_Dynamic_Index +{ +public: + floatcombine_autoexpose_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_floatcombine_autoexpose_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/floatcombine_autoexpose_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/floatcombine_autoexpose_ps20b.inc new file mode 100644 index 0000000..d684063 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/floatcombine_autoexpose_ps20b.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class floatcombine_autoexpose_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + floatcombine_autoexpose_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_floatcombine_autoexpose_ps20b 0 +class floatcombine_autoexpose_ps20b_Dynamic_Index +{ +public: + floatcombine_autoexpose_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_floatcombine_autoexpose_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/floatcombine_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/floatcombine_ps20.inc new file mode 100644 index 0000000..0671a17 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/floatcombine_ps20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class floatcombine_ps20_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + floatcombine_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_floatcombine_ps20 0 +class floatcombine_ps20_Dynamic_Index +{ +public: + floatcombine_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_floatcombine_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/floatcombine_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/floatcombine_ps20b.inc new file mode 100644 index 0000000..de6fe38 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/floatcombine_ps20b.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class floatcombine_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + floatcombine_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_floatcombine_ps20b 0 +class floatcombine_ps20b_Dynamic_Index +{ +public: + floatcombine_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_floatcombine_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/floattoscreen_notonemap_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/floattoscreen_notonemap_ps20.inc new file mode 100644 index 0000000..cebbab6 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/floattoscreen_notonemap_ps20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class floattoscreen_notonemap_ps20_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + floattoscreen_notonemap_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_floattoscreen_notonemap_ps20 0 +class floattoscreen_notonemap_ps20_Dynamic_Index +{ +public: + floattoscreen_notonemap_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_floattoscreen_notonemap_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/floattoscreen_notonemap_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/floattoscreen_notonemap_ps20b.inc new file mode 100644 index 0000000..412015e --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/floattoscreen_notonemap_ps20b.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class floattoscreen_notonemap_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + floattoscreen_notonemap_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_floattoscreen_notonemap_ps20b 0 +class floattoscreen_notonemap_ps20b_Dynamic_Index +{ +public: + floattoscreen_notonemap_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_floattoscreen_notonemap_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/floattoscreen_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/floattoscreen_ps20.inc new file mode 100644 index 0000000..8c02542 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/floattoscreen_ps20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class floattoscreen_ps20_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + floattoscreen_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_floattoscreen_ps20 0 +class floattoscreen_ps20_Dynamic_Index +{ +public: + floattoscreen_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_floattoscreen_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/floattoscreen_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/floattoscreen_ps20b.inc new file mode 100644 index 0000000..e1a7025 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/floattoscreen_ps20b.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class floattoscreen_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + floattoscreen_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_floattoscreen_ps20b 0 +class floattoscreen_ps20b_Dynamic_Index +{ +public: + floattoscreen_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_floattoscreen_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/floattoscreen_vanilla_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/floattoscreen_vanilla_ps20.inc new file mode 100644 index 0000000..2cc61e1 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/floattoscreen_vanilla_ps20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class floattoscreen_vanilla_ps20_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + floattoscreen_vanilla_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_floattoscreen_vanilla_ps20 0 +class floattoscreen_vanilla_ps20_Dynamic_Index +{ +public: + floattoscreen_vanilla_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_floattoscreen_vanilla_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/floattoscreen_vanilla_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/floattoscreen_vanilla_ps20b.inc new file mode 100644 index 0000000..645d719 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/floattoscreen_vanilla_ps20b.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class floattoscreen_vanilla_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + floattoscreen_vanilla_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_floattoscreen_vanilla_ps20b 0 +class floattoscreen_vanilla_ps20b_Dynamic_Index +{ +public: + floattoscreen_vanilla_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_floattoscreen_vanilla_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/haloadd1d_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/haloadd1d_ps20.inc new file mode 100644 index 0000000..f861fad --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/haloadd1d_ps20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class haloadd1d_ps20_Static_Index +{ +public: + haloadd1d_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_haloadd1d_ps20 0 +class haloadd1d_ps20_Dynamic_Index +{ +public: + haloadd1d_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_haloadd1d_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/haloadd1d_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/haloadd1d_ps20b.inc new file mode 100644 index 0000000..c2bf645 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/haloadd1d_ps20b.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class haloadd1d_ps20b_Static_Index +{ +public: + haloadd1d_ps20b_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_haloadd1d_ps20b 0 +class haloadd1d_ps20b_Dynamic_Index +{ +public: + haloadd1d_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_haloadd1d_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/haloadd_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/haloadd_ps20.inc new file mode 100644 index 0000000..fe692d6 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/haloadd_ps20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class haloadd_ps20_Static_Index +{ +public: + haloadd_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_haloadd_ps20 0 +class haloadd_ps20_Dynamic_Index +{ +public: + haloadd_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_haloadd_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/haloadd_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/haloadd_ps20b.inc new file mode 100644 index 0000000..d9eb204 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/haloadd_ps20b.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class haloadd_ps20b_Static_Index +{ +public: + haloadd_ps20b_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_haloadd_ps20b 0 +class haloadd_ps20b_Dynamic_Index +{ +public: + haloadd_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_haloadd_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/haloaddoutline_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/haloaddoutline_ps20.inc new file mode 100644 index 0000000..a557ee1 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/haloaddoutline_ps20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class haloaddoutline_ps20_Static_Index +{ +public: + haloaddoutline_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_haloaddoutline_ps20 0 +class haloaddoutline_ps20_Dynamic_Index +{ +public: + haloaddoutline_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_haloaddoutline_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/haloaddoutline_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/haloaddoutline_ps20b.inc new file mode 100644 index 0000000..0b26b29 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/haloaddoutline_ps20b.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class haloaddoutline_ps20b_Static_Index +{ +public: + haloaddoutline_ps20b_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_haloaddoutline_ps20b 0 +class haloaddoutline_ps20b_Dynamic_Index +{ +public: + haloaddoutline_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_haloaddoutline_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/hsl_filmgrain_pass1_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/hsl_filmgrain_pass1_ps20.inc new file mode 100644 index 0000000..5da489e --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/hsl_filmgrain_pass1_ps20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class hsl_filmgrain_pass1_ps20_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + hsl_filmgrain_pass1_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_hsl_filmgrain_pass1_ps20 0 +class hsl_filmgrain_pass1_ps20_Dynamic_Index +{ +public: + hsl_filmgrain_pass1_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_hsl_filmgrain_pass1_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/hsl_filmgrain_pass1_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/hsl_filmgrain_pass1_ps20b.inc new file mode 100644 index 0000000..a9a5fcf --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/hsl_filmgrain_pass1_ps20b.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class hsl_filmgrain_pass1_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + hsl_filmgrain_pass1_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_hsl_filmgrain_pass1_ps20b 0 +class hsl_filmgrain_pass1_ps20b_Dynamic_Index +{ +public: + hsl_filmgrain_pass1_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_hsl_filmgrain_pass1_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/hsl_filmgrain_pass2_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/hsl_filmgrain_pass2_ps20.inc new file mode 100644 index 0000000..8bc97fa --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/hsl_filmgrain_pass2_ps20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class hsl_filmgrain_pass2_ps20_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + hsl_filmgrain_pass2_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_hsl_filmgrain_pass2_ps20 0 +class hsl_filmgrain_pass2_ps20_Dynamic_Index +{ +public: + hsl_filmgrain_pass2_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_hsl_filmgrain_pass2_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/hsl_filmgrain_pass2_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/hsl_filmgrain_pass2_ps20b.inc new file mode 100644 index 0000000..82b75e4 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/hsl_filmgrain_pass2_ps20b.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class hsl_filmgrain_pass2_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + hsl_filmgrain_pass2_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_hsl_filmgrain_pass2_ps20b 0 +class hsl_filmgrain_pass2_ps20b_Dynamic_Index +{ +public: + hsl_filmgrain_pass2_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_hsl_filmgrain_pass2_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/hsv_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/hsv_ps20.inc new file mode 100644 index 0000000..0b58f66 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/hsv_ps20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class hsv_ps20_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + hsv_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_hsv_ps20 0 +class hsv_ps20_Dynamic_Index +{ +public: + hsv_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_hsv_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/hsv_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/hsv_ps20b.inc new file mode 100644 index 0000000..e9302a0 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/hsv_ps20b.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class hsv_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + hsv_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_hsv_ps20b 0 +class hsv_ps20b_Dynamic_Index +{ +public: + hsv_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_hsv_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/introscreenspaceeffect_ps11.inc b/materialsystem/stdshaders/fxctmp9_360/introscreenspaceeffect_ps11.inc new file mode 100644 index 0000000..a7afc44 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/introscreenspaceeffect_ps11.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class introscreenspaceeffect_ps11_Static_Index +{ +public: + introscreenspaceeffect_ps11_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_introscreenspaceeffect_ps11 0 +class introscreenspaceeffect_ps11_Dynamic_Index +{ +private: + int m_nMODE; +#ifdef _DEBUG + bool m_bMODE; +#endif +public: + void SetMODE( int i ) + { + Assert( i >= 0 && i <= 9 ); + m_nMODE = i; +#ifdef _DEBUG + m_bMODE = true; +#endif + } + void SetMODE( bool i ) + { + m_nMODE = i ? 1 : 0; +#ifdef _DEBUG + m_bMODE = true; +#endif + } +public: + introscreenspaceeffect_ps11_Dynamic_Index() + { +#ifdef _DEBUG + m_bMODE = false; +#endif // _DEBUG + m_nMODE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bMODE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nMODE ) + 0; + } +}; +#define shaderDynamicTest_introscreenspaceeffect_ps11 psh_forgot_to_set_dynamic_MODE + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/lightmappedgeneric_decal_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/lightmappedgeneric_decal_ps20.inc new file mode 100644 index 0000000..a5347f6 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/lightmappedgeneric_decal_ps20.inc @@ -0,0 +1,87 @@ +#include "shaderlib/cshader.h" +class lightmappedgeneric_decal_ps20_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + lightmappedgeneric_decal_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_lightmappedgeneric_decal_ps20 0 +class lightmappedgeneric_decal_ps20_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + lightmappedgeneric_decal_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_lightmappedgeneric_decal_ps20 psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/lightmappedgeneric_decal_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/lightmappedgeneric_decal_ps20b.inc new file mode 100644 index 0000000..bb9da90 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/lightmappedgeneric_decal_ps20b.inc @@ -0,0 +1,87 @@ +#include "shaderlib/cshader.h" +class lightmappedgeneric_decal_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + lightmappedgeneric_decal_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_lightmappedgeneric_decal_ps20b 0 +class lightmappedgeneric_decal_ps20b_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + lightmappedgeneric_decal_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_lightmappedgeneric_decal_ps20b psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/lightmappedgeneric_decal_vs20.inc b/materialsystem/stdshaders/fxctmp9_360/lightmappedgeneric_decal_vs20.inc new file mode 100644 index 0000000..b8106ca --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/lightmappedgeneric_decal_vs20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class lightmappedgeneric_decal_vs20_Static_Index +{ +public: + lightmappedgeneric_decal_vs20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_lightmappedgeneric_decal_vs20 0 +class lightmappedgeneric_decal_vs20_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + lightmappedgeneric_decal_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; +#define shaderDynamicTest_lightmappedgeneric_decal_vs20 vsh_forgot_to_set_dynamic_DOWATERFOG + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/lightmappedgeneric_flashlight_vs11.inc b/materialsystem/stdshaders/fxctmp9_360/lightmappedgeneric_flashlight_vs11.inc new file mode 100644 index 0000000..fbf5256 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/lightmappedgeneric_flashlight_vs11.inc @@ -0,0 +1,137 @@ +#include "shaderlib/cshader.h" +class lightmappedgeneric_flashlight_vs11_Static_Index +{ +private: + int m_nNORMALMAP; +#ifdef _DEBUG + bool m_bNORMALMAP; +#endif +public: + void SetNORMALMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nNORMALMAP = i; +#ifdef _DEBUG + m_bNORMALMAP = true; +#endif + } + void SetNORMALMAP( bool i ) + { + m_nNORMALMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bNORMALMAP = true; +#endif + } +private: + int m_nWORLDVERTEXTRANSITION; +#ifdef _DEBUG + bool m_bWORLDVERTEXTRANSITION; +#endif +public: + void SetWORLDVERTEXTRANSITION( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nWORLDVERTEXTRANSITION = i; +#ifdef _DEBUG + m_bWORLDVERTEXTRANSITION = true; +#endif + } + void SetWORLDVERTEXTRANSITION( bool i ) + { + m_nWORLDVERTEXTRANSITION = i ? 1 : 0; +#ifdef _DEBUG + m_bWORLDVERTEXTRANSITION = true; +#endif + } +private: + int m_nVERTEXCOLOR; +#ifdef _DEBUG + bool m_bVERTEXCOLOR; +#endif +public: + void SetVERTEXCOLOR( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nVERTEXCOLOR = i; +#ifdef _DEBUG + m_bVERTEXCOLOR = true; +#endif + } + void SetVERTEXCOLOR( bool i ) + { + m_nVERTEXCOLOR = i ? 1 : 0; +#ifdef _DEBUG + m_bVERTEXCOLOR = true; +#endif + } +public: + lightmappedgeneric_flashlight_vs11_Static_Index( ) + { +#ifdef _DEBUG + m_bNORMALMAP = false; +#endif // _DEBUG + m_nNORMALMAP = 0; +#ifdef _DEBUG + m_bWORLDVERTEXTRANSITION = false; +#endif // _DEBUG + m_nWORLDVERTEXTRANSITION = 0; +#ifdef _DEBUG + m_bVERTEXCOLOR = false; +#endif // _DEBUG + m_nVERTEXCOLOR = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bNORMALMAP && m_bWORLDVERTEXTRANSITION && m_bVERTEXCOLOR; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nNORMALMAP ) + ( 4 * m_nWORLDVERTEXTRANSITION ) + ( 8 * m_nVERTEXCOLOR ) + 0; + } +}; +#define shaderStaticTest_lightmappedgeneric_flashlight_vs11 vsh_forgot_to_set_static_NORMALMAP + vsh_forgot_to_set_static_WORLDVERTEXTRANSITION + vsh_forgot_to_set_static_VERTEXCOLOR + 0 +class lightmappedgeneric_flashlight_vs11_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + lightmappedgeneric_flashlight_vs11_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; +#define shaderDynamicTest_lightmappedgeneric_flashlight_vs11 vsh_forgot_to_set_dynamic_DOWATERFOG + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/lightmappedgeneric_flashlight_vs20.inc b/materialsystem/stdshaders/fxctmp9_360/lightmappedgeneric_flashlight_vs20.inc new file mode 100644 index 0000000..f472301 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/lightmappedgeneric_flashlight_vs20.inc @@ -0,0 +1,162 @@ +#include "shaderlib/cshader.h" +class lightmappedgeneric_flashlight_vs20_Static_Index +{ +private: + int m_nNORMALMAP; +#ifdef _DEBUG + bool m_bNORMALMAP; +#endif +public: + void SetNORMALMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nNORMALMAP = i; +#ifdef _DEBUG + m_bNORMALMAP = true; +#endif + } + void SetNORMALMAP( bool i ) + { + m_nNORMALMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bNORMALMAP = true; +#endif + } +private: + int m_nWORLDVERTEXTRANSITION; +#ifdef _DEBUG + bool m_bWORLDVERTEXTRANSITION; +#endif +public: + void SetWORLDVERTEXTRANSITION( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nWORLDVERTEXTRANSITION = i; +#ifdef _DEBUG + m_bWORLDVERTEXTRANSITION = true; +#endif + } + void SetWORLDVERTEXTRANSITION( bool i ) + { + m_nWORLDVERTEXTRANSITION = i ? 1 : 0; +#ifdef _DEBUG + m_bWORLDVERTEXTRANSITION = true; +#endif + } +private: + int m_nSEAMLESS; +#ifdef _DEBUG + bool m_bSEAMLESS; +#endif +public: + void SetSEAMLESS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSEAMLESS = i; +#ifdef _DEBUG + m_bSEAMLESS = true; +#endif + } + void SetSEAMLESS( bool i ) + { + m_nSEAMLESS = i ? 1 : 0; +#ifdef _DEBUG + m_bSEAMLESS = true; +#endif + } +private: + int m_nDETAIL; +#ifdef _DEBUG + bool m_bDETAIL; +#endif +public: + void SetDETAIL( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDETAIL = i; +#ifdef _DEBUG + m_bDETAIL = true; +#endif + } + void SetDETAIL( bool i ) + { + m_nDETAIL = i ? 1 : 0; +#ifdef _DEBUG + m_bDETAIL = true; +#endif + } +public: + lightmappedgeneric_flashlight_vs20_Static_Index( ) + { +#ifdef _DEBUG + m_bNORMALMAP = false; +#endif // _DEBUG + m_nNORMALMAP = 0; +#ifdef _DEBUG + m_bWORLDVERTEXTRANSITION = false; +#endif // _DEBUG + m_nWORLDVERTEXTRANSITION = 0; +#ifdef _DEBUG + m_bSEAMLESS = false; +#endif // _DEBUG + m_nSEAMLESS = 0; +#ifdef _DEBUG + m_bDETAIL = false; +#endif // _DEBUG + m_nDETAIL = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bNORMALMAP && m_bWORLDVERTEXTRANSITION && m_bSEAMLESS && m_bDETAIL; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nNORMALMAP ) + ( 4 * m_nWORLDVERTEXTRANSITION ) + ( 8 * m_nSEAMLESS ) + ( 16 * m_nDETAIL ) + 0; + } +}; +#define shaderStaticTest_lightmappedgeneric_flashlight_vs20 vsh_forgot_to_set_static_NORMALMAP + vsh_forgot_to_set_static_WORLDVERTEXTRANSITION + vsh_forgot_to_set_static_SEAMLESS + vsh_forgot_to_set_static_DETAIL + 0 +class lightmappedgeneric_flashlight_vs20_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + lightmappedgeneric_flashlight_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; +#define shaderDynamicTest_lightmappedgeneric_flashlight_vs20 vsh_forgot_to_set_dynamic_DOWATERFOG + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/lightmappedgeneric_lightingonly_overbright2_ps11.inc b/materialsystem/stdshaders/fxctmp9_360/lightmappedgeneric_lightingonly_overbright2_ps11.inc new file mode 100644 index 0000000..c8b345b --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/lightmappedgeneric_lightingonly_overbright2_ps11.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class lightmappedgeneric_lightingonly_overbright2_ps11_Static_Index +{ +public: + lightmappedgeneric_lightingonly_overbright2_ps11_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_lightmappedgeneric_lightingonly_overbright2_ps11 0 +class lightmappedgeneric_lightingonly_overbright2_ps11_Dynamic_Index +{ +public: + lightmappedgeneric_lightingonly_overbright2_ps11_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_lightmappedgeneric_lightingonly_overbright2_ps11 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/lightmappedgeneric_lightingonly_vs11.inc b/materialsystem/stdshaders/fxctmp9_360/lightmappedgeneric_lightingonly_vs11.inc new file mode 100644 index 0000000..c4b302f --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/lightmappedgeneric_lightingonly_vs11.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class lightmappedgeneric_lightingonly_vs11_Static_Index +{ +public: + lightmappedgeneric_lightingonly_vs11_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_lightmappedgeneric_lightingonly_vs11 0 +class lightmappedgeneric_lightingonly_vs11_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + lightmappedgeneric_lightingonly_vs11_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; +#define shaderDynamicTest_lightmappedgeneric_lightingonly_vs11 vsh_forgot_to_set_dynamic_DOWATERFOG + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/lightmappedgeneric_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/lightmappedgeneric_ps20.inc new file mode 100644 index 0000000..d2427db --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/lightmappedgeneric_ps20.inc @@ -0,0 +1,712 @@ +#include "shaderlib/cshader.h" +class lightmappedgeneric_ps20_Static_Index +{ +private: + int m_nMASKEDBLENDING; +#ifdef _DEBUG + bool m_bMASKEDBLENDING; +#endif +public: + void SetMASKEDBLENDING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nMASKEDBLENDING = i; +#ifdef _DEBUG + m_bMASKEDBLENDING = true; +#endif + } + void SetMASKEDBLENDING( bool i ) + { + m_nMASKEDBLENDING = i ? 1 : 0; +#ifdef _DEBUG + m_bMASKEDBLENDING = true; +#endif + } +private: + int m_nBASETEXTURE2; +#ifdef _DEBUG + bool m_bBASETEXTURE2; +#endif +public: + void SetBASETEXTURE2( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBASETEXTURE2 = i; +#ifdef _DEBUG + m_bBASETEXTURE2 = true; +#endif + } + void SetBASETEXTURE2( bool i ) + { + m_nBASETEXTURE2 = i ? 1 : 0; +#ifdef _DEBUG + m_bBASETEXTURE2 = true; +#endif + } +private: + int m_nDETAILTEXTURE; +#ifdef _DEBUG + bool m_bDETAILTEXTURE; +#endif +public: + void SetDETAILTEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDETAILTEXTURE = i; +#ifdef _DEBUG + m_bDETAILTEXTURE = true; +#endif + } + void SetDETAILTEXTURE( bool i ) + { + m_nDETAILTEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bDETAILTEXTURE = true; +#endif + } +private: + int m_nBUMPMAP; +#ifdef _DEBUG + bool m_bBUMPMAP; +#endif +public: + void SetBUMPMAP( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nBUMPMAP = i; +#ifdef _DEBUG + m_bBUMPMAP = true; +#endif + } + void SetBUMPMAP( bool i ) + { + m_nBUMPMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bBUMPMAP = true; +#endif + } +private: + int m_nBUMPMAP2; +#ifdef _DEBUG + bool m_bBUMPMAP2; +#endif +public: + void SetBUMPMAP2( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBUMPMAP2 = i; +#ifdef _DEBUG + m_bBUMPMAP2 = true; +#endif + } + void SetBUMPMAP2( bool i ) + { + m_nBUMPMAP2 = i ? 1 : 0; +#ifdef _DEBUG + m_bBUMPMAP2 = true; +#endif + } +private: + int m_nCUBEMAP; +#ifdef _DEBUG + bool m_bCUBEMAP; +#endif +public: + void SetCUBEMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCUBEMAP = i; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } + void SetCUBEMAP( bool i ) + { + m_nCUBEMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } +private: + int m_nENVMAPMASK; +#ifdef _DEBUG + bool m_bENVMAPMASK; +#endif +public: + void SetENVMAPMASK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nENVMAPMASK = i; +#ifdef _DEBUG + m_bENVMAPMASK = true; +#endif + } + void SetENVMAPMASK( bool i ) + { + m_nENVMAPMASK = i ? 1 : 0; +#ifdef _DEBUG + m_bENVMAPMASK = true; +#endif + } +private: + int m_nBASEALPHAENVMAPMASK; +#ifdef _DEBUG + bool m_bBASEALPHAENVMAPMASK; +#endif +public: + void SetBASEALPHAENVMAPMASK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBASEALPHAENVMAPMASK = i; +#ifdef _DEBUG + m_bBASEALPHAENVMAPMASK = true; +#endif + } + void SetBASEALPHAENVMAPMASK( bool i ) + { + m_nBASEALPHAENVMAPMASK = i ? 1 : 0; +#ifdef _DEBUG + m_bBASEALPHAENVMAPMASK = true; +#endif + } +private: + int m_nSELFILLUM; +#ifdef _DEBUG + bool m_bSELFILLUM; +#endif +public: + void SetSELFILLUM( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSELFILLUM = i; +#ifdef _DEBUG + m_bSELFILLUM = true; +#endif + } + void SetSELFILLUM( bool i ) + { + m_nSELFILLUM = i ? 1 : 0; +#ifdef _DEBUG + m_bSELFILLUM = true; +#endif + } +private: + int m_nNORMALMAPALPHAENVMAPMASK; +#ifdef _DEBUG + bool m_bNORMALMAPALPHAENVMAPMASK; +#endif +public: + void SetNORMALMAPALPHAENVMAPMASK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nNORMALMAPALPHAENVMAPMASK = i; +#ifdef _DEBUG + m_bNORMALMAPALPHAENVMAPMASK = true; +#endif + } + void SetNORMALMAPALPHAENVMAPMASK( bool i ) + { + m_nNORMALMAPALPHAENVMAPMASK = i ? 1 : 0; +#ifdef _DEBUG + m_bNORMALMAPALPHAENVMAPMASK = true; +#endif + } +private: + int m_nDIFFUSEBUMPMAP; +#ifdef _DEBUG + bool m_bDIFFUSEBUMPMAP; +#endif +public: + void SetDIFFUSEBUMPMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDIFFUSEBUMPMAP = i; +#ifdef _DEBUG + m_bDIFFUSEBUMPMAP = true; +#endif + } + void SetDIFFUSEBUMPMAP( bool i ) + { + m_nDIFFUSEBUMPMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bDIFFUSEBUMPMAP = true; +#endif + } +private: + int m_nBASETEXTURENOENVMAP; +#ifdef _DEBUG + bool m_bBASETEXTURENOENVMAP; +#endif +public: + void SetBASETEXTURENOENVMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBASETEXTURENOENVMAP = i; +#ifdef _DEBUG + m_bBASETEXTURENOENVMAP = true; +#endif + } + void SetBASETEXTURENOENVMAP( bool i ) + { + m_nBASETEXTURENOENVMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bBASETEXTURENOENVMAP = true; +#endif + } +private: + int m_nBASETEXTURE2NOENVMAP; +#ifdef _DEBUG + bool m_bBASETEXTURE2NOENVMAP; +#endif +public: + void SetBASETEXTURE2NOENVMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBASETEXTURE2NOENVMAP = i; +#ifdef _DEBUG + m_bBASETEXTURE2NOENVMAP = true; +#endif + } + void SetBASETEXTURE2NOENVMAP( bool i ) + { + m_nBASETEXTURE2NOENVMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bBASETEXTURE2NOENVMAP = true; +#endif + } +private: + int m_nWARPLIGHTING; +#ifdef _DEBUG + bool m_bWARPLIGHTING; +#endif +public: + void SetWARPLIGHTING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nWARPLIGHTING = i; +#ifdef _DEBUG + m_bWARPLIGHTING = true; +#endif + } + void SetWARPLIGHTING( bool i ) + { + m_nWARPLIGHTING = i ? 1 : 0; +#ifdef _DEBUG + m_bWARPLIGHTING = true; +#endif + } +private: + int m_nFANCY_BLENDING; +#ifdef _DEBUG + bool m_bFANCY_BLENDING; +#endif +public: + void SetFANCY_BLENDING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFANCY_BLENDING = i; +#ifdef _DEBUG + m_bFANCY_BLENDING = true; +#endif + } + void SetFANCY_BLENDING( bool i ) + { + m_nFANCY_BLENDING = i ? 1 : 0; +#ifdef _DEBUG + m_bFANCY_BLENDING = true; +#endif + } +private: + int m_nSEAMLESS; +#ifdef _DEBUG + bool m_bSEAMLESS; +#endif +public: + void SetSEAMLESS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSEAMLESS = i; +#ifdef _DEBUG + m_bSEAMLESS = true; +#endif + } + void SetSEAMLESS( bool i ) + { + m_nSEAMLESS = i ? 1 : 0; +#ifdef _DEBUG + m_bSEAMLESS = true; +#endif + } +private: + int m_nOUTLINE; +#ifdef _DEBUG + bool m_bOUTLINE; +#endif +public: + void SetOUTLINE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nOUTLINE = i; +#ifdef _DEBUG + m_bOUTLINE = true; +#endif + } + void SetOUTLINE( bool i ) + { + m_nOUTLINE = i ? 1 : 0; +#ifdef _DEBUG + m_bOUTLINE = true; +#endif + } +private: + int m_nSOFTEDGES; +#ifdef _DEBUG + bool m_bSOFTEDGES; +#endif +public: + void SetSOFTEDGES( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSOFTEDGES = i; +#ifdef _DEBUG + m_bSOFTEDGES = true; +#endif + } + void SetSOFTEDGES( bool i ) + { + m_nSOFTEDGES = i ? 1 : 0; +#ifdef _DEBUG + m_bSOFTEDGES = true; +#endif + } +private: + int m_nBUMPMASK; +#ifdef _DEBUG + bool m_bBUMPMASK; +#endif +public: + void SetBUMPMASK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBUMPMASK = i; +#ifdef _DEBUG + m_bBUMPMASK = true; +#endif + } + void SetBUMPMASK( bool i ) + { + m_nBUMPMASK = i ? 1 : 0; +#ifdef _DEBUG + m_bBUMPMASK = true; +#endif + } +private: + int m_nNORMAL_DECODE_MODE; +#ifdef _DEBUG + bool m_bNORMAL_DECODE_MODE; +#endif +public: + void SetNORMAL_DECODE_MODE( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nNORMAL_DECODE_MODE = i; +#ifdef _DEBUG + m_bNORMAL_DECODE_MODE = true; +#endif + } + void SetNORMAL_DECODE_MODE( bool i ) + { + m_nNORMAL_DECODE_MODE = i ? 1 : 0; +#ifdef _DEBUG + m_bNORMAL_DECODE_MODE = true; +#endif + } +private: + int m_nNORMALMASK_DECODE_MODE; +#ifdef _DEBUG + bool m_bNORMALMASK_DECODE_MODE; +#endif +public: + void SetNORMALMASK_DECODE_MODE( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nNORMALMASK_DECODE_MODE = i; +#ifdef _DEBUG + m_bNORMALMASK_DECODE_MODE = true; +#endif + } + void SetNORMALMASK_DECODE_MODE( bool i ) + { + m_nNORMALMASK_DECODE_MODE = i ? 1 : 0; +#ifdef _DEBUG + m_bNORMALMASK_DECODE_MODE = true; +#endif + } +private: + int m_nDETAIL_BLEND_MODE; +#ifdef _DEBUG + bool m_bDETAIL_BLEND_MODE; +#endif +public: + void SetDETAIL_BLEND_MODE( int i ) + { + Assert( i >= 0 && i <= 11 ); + m_nDETAIL_BLEND_MODE = i; +#ifdef _DEBUG + m_bDETAIL_BLEND_MODE = true; +#endif + } + void SetDETAIL_BLEND_MODE( bool i ) + { + m_nDETAIL_BLEND_MODE = i ? 1 : 0; +#ifdef _DEBUG + m_bDETAIL_BLEND_MODE = true; +#endif + } +public: + lightmappedgeneric_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bMASKEDBLENDING = false; +#endif // _DEBUG + m_nMASKEDBLENDING = 0; +#ifdef _DEBUG + m_bBASETEXTURE2 = false; +#endif // _DEBUG + m_nBASETEXTURE2 = 0; +#ifdef _DEBUG + m_bDETAILTEXTURE = false; +#endif // _DEBUG + m_nDETAILTEXTURE = 0; +#ifdef _DEBUG + m_bBUMPMAP = false; +#endif // _DEBUG + m_nBUMPMAP = 0; +#ifdef _DEBUG + m_bBUMPMAP2 = false; +#endif // _DEBUG + m_nBUMPMAP2 = 0; +#ifdef _DEBUG + m_bCUBEMAP = false; +#endif // _DEBUG + m_nCUBEMAP = 0; +#ifdef _DEBUG + m_bENVMAPMASK = false; +#endif // _DEBUG + m_nENVMAPMASK = 0; +#ifdef _DEBUG + m_bBASEALPHAENVMAPMASK = false; +#endif // _DEBUG + m_nBASEALPHAENVMAPMASK = 0; +#ifdef _DEBUG + m_bSELFILLUM = false; +#endif // _DEBUG + m_nSELFILLUM = 0; +#ifdef _DEBUG + m_bNORMALMAPALPHAENVMAPMASK = false; +#endif // _DEBUG + m_nNORMALMAPALPHAENVMAPMASK = 0; +#ifdef _DEBUG + m_bDIFFUSEBUMPMAP = false; +#endif // _DEBUG + m_nDIFFUSEBUMPMAP = 0; +#ifdef _DEBUG + m_bBASETEXTURENOENVMAP = false; +#endif // _DEBUG + m_nBASETEXTURENOENVMAP = 0; +#ifdef _DEBUG + m_bBASETEXTURE2NOENVMAP = false; +#endif // _DEBUG + m_nBASETEXTURE2NOENVMAP = 0; +#ifdef _DEBUG + m_bWARPLIGHTING = false; +#endif // _DEBUG + m_nWARPLIGHTING = 0; +#ifdef _DEBUG + m_bFANCY_BLENDING = false; +#endif // _DEBUG + m_nFANCY_BLENDING = 0; +#ifdef _DEBUG + m_bSEAMLESS = false; +#endif // _DEBUG + m_nSEAMLESS = 0; +#ifdef _DEBUG + m_bOUTLINE = false; +#endif // _DEBUG + m_nOUTLINE = 0; +#ifdef _DEBUG + m_bSOFTEDGES = false; +#endif // _DEBUG + m_nSOFTEDGES = 0; +#ifdef _DEBUG + m_bBUMPMASK = false; +#endif // _DEBUG + m_nBUMPMASK = 0; +#ifdef _DEBUG + m_bNORMAL_DECODE_MODE = false; +#endif // _DEBUG + m_nNORMAL_DECODE_MODE = 0; +#ifdef _DEBUG + m_bNORMALMASK_DECODE_MODE = false; +#endif // _DEBUG + m_nNORMALMASK_DECODE_MODE = 0; +#ifdef _DEBUG + m_bDETAIL_BLEND_MODE = false; +#endif // _DEBUG + m_nDETAIL_BLEND_MODE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bMASKEDBLENDING && m_bBASETEXTURE2 && m_bDETAILTEXTURE && m_bBUMPMAP && m_bBUMPMAP2 && m_bCUBEMAP && m_bENVMAPMASK && m_bBASEALPHAENVMAPMASK && m_bSELFILLUM && m_bNORMALMAPALPHAENVMAPMASK && m_bDIFFUSEBUMPMAP && m_bBASETEXTURENOENVMAP && m_bBASETEXTURE2NOENVMAP && m_bWARPLIGHTING && m_bFANCY_BLENDING && m_bSEAMLESS && m_bOUTLINE && m_bSOFTEDGES && m_bBUMPMASK && m_bNORMAL_DECODE_MODE && m_bNORMALMASK_DECODE_MODE && m_bDETAIL_BLEND_MODE; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 16 * m_nMASKEDBLENDING ) + ( 32 * m_nBASETEXTURE2 ) + ( 64 * m_nDETAILTEXTURE ) + ( 128 * m_nBUMPMAP ) + ( 384 * m_nBUMPMAP2 ) + ( 768 * m_nCUBEMAP ) + ( 1536 * m_nENVMAPMASK ) + ( 3072 * m_nBASEALPHAENVMAPMASK ) + ( 6144 * m_nSELFILLUM ) + ( 12288 * m_nNORMALMAPALPHAENVMAPMASK ) + ( 24576 * m_nDIFFUSEBUMPMAP ) + ( 49152 * m_nBASETEXTURENOENVMAP ) + ( 98304 * m_nBASETEXTURE2NOENVMAP ) + ( 196608 * m_nWARPLIGHTING ) + ( 393216 * m_nFANCY_BLENDING ) + ( 786432 * m_nSEAMLESS ) + ( 1572864 * m_nOUTLINE ) + ( 3145728 * m_nSOFTEDGES ) + ( 6291456 * m_nBUMPMASK ) + ( 12582912 * m_nNORMAL_DECODE_MODE ) + ( 12582912 * m_nNORMALMASK_DECODE_MODE ) + ( 12582912 * m_nDETAIL_BLEND_MODE ) + 0; + } +}; +#define shaderStaticTest_lightmappedgeneric_ps20 psh_forgot_to_set_static_MASKEDBLENDING + psh_forgot_to_set_static_BASETEXTURE2 + psh_forgot_to_set_static_DETAILTEXTURE + psh_forgot_to_set_static_BUMPMAP + psh_forgot_to_set_static_BUMPMAP2 + psh_forgot_to_set_static_CUBEMAP + psh_forgot_to_set_static_ENVMAPMASK + psh_forgot_to_set_static_BASEALPHAENVMAPMASK + psh_forgot_to_set_static_SELFILLUM + psh_forgot_to_set_static_NORMALMAPALPHAENVMAPMASK + psh_forgot_to_set_static_DIFFUSEBUMPMAP + psh_forgot_to_set_static_BASETEXTURENOENVMAP + psh_forgot_to_set_static_BASETEXTURE2NOENVMAP + psh_forgot_to_set_static_WARPLIGHTING + psh_forgot_to_set_static_FANCY_BLENDING + psh_forgot_to_set_static_SEAMLESS + psh_forgot_to_set_static_OUTLINE + psh_forgot_to_set_static_SOFTEDGES + psh_forgot_to_set_static_BUMPMASK + psh_forgot_to_set_static_NORMAL_DECODE_MODE + psh_forgot_to_set_static_NORMALMASK_DECODE_MODE + psh_forgot_to_set_static_DETAIL_BLEND_MODE + 0 +class lightmappedgeneric_ps20_Dynamic_Index +{ +private: + int m_nFASTPATHENVMAPCONTRAST; +#ifdef _DEBUG + bool m_bFASTPATHENVMAPCONTRAST; +#endif +public: + void SetFASTPATHENVMAPCONTRAST( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFASTPATHENVMAPCONTRAST = i; +#ifdef _DEBUG + m_bFASTPATHENVMAPCONTRAST = true; +#endif + } + void SetFASTPATHENVMAPCONTRAST( bool i ) + { + m_nFASTPATHENVMAPCONTRAST = i ? 1 : 0; +#ifdef _DEBUG + m_bFASTPATHENVMAPCONTRAST = true; +#endif + } +private: + int m_nFASTPATH; +#ifdef _DEBUG + bool m_bFASTPATH; +#endif +public: + void SetFASTPATH( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFASTPATH = i; +#ifdef _DEBUG + m_bFASTPATH = true; +#endif + } + void SetFASTPATH( bool i ) + { + m_nFASTPATH = i ? 1 : 0; +#ifdef _DEBUG + m_bFASTPATH = true; +#endif + } +private: + int m_nWRITEWATERFOGTODESTALPHA; +#ifdef _DEBUG + bool m_bWRITEWATERFOGTODESTALPHA; +#endif +public: + void SetWRITEWATERFOGTODESTALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nWRITEWATERFOGTODESTALPHA = i; +#ifdef _DEBUG + m_bWRITEWATERFOGTODESTALPHA = true; +#endif + } + void SetWRITEWATERFOGTODESTALPHA( bool i ) + { + m_nWRITEWATERFOGTODESTALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bWRITEWATERFOGTODESTALPHA = true; +#endif + } +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +private: + int m_nLIGHTING_PREVIEW; +#ifdef _DEBUG + bool m_bLIGHTING_PREVIEW; +#endif +public: + void SetLIGHTING_PREVIEW( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nLIGHTING_PREVIEW = i; +#ifdef _DEBUG + m_bLIGHTING_PREVIEW = true; +#endif + } + void SetLIGHTING_PREVIEW( bool i ) + { + m_nLIGHTING_PREVIEW = i ? 1 : 0; +#ifdef _DEBUG + m_bLIGHTING_PREVIEW = true; +#endif + } +public: + lightmappedgeneric_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bFASTPATHENVMAPCONTRAST = false; +#endif // _DEBUG + m_nFASTPATHENVMAPCONTRAST = 0; +#ifdef _DEBUG + m_bFASTPATH = false; +#endif // _DEBUG + m_nFASTPATH = 0; +#ifdef _DEBUG + m_bWRITEWATERFOGTODESTALPHA = false; +#endif // _DEBUG + m_nWRITEWATERFOGTODESTALPHA = 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; +#ifdef _DEBUG + m_bLIGHTING_PREVIEW = false; +#endif // _DEBUG + m_nLIGHTING_PREVIEW = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bFASTPATHENVMAPCONTRAST && m_bFASTPATH && m_bWRITEWATERFOGTODESTALPHA && m_bPIXELFOGTYPE && m_bLIGHTING_PREVIEW; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nFASTPATHENVMAPCONTRAST ) + ( 2 * m_nFASTPATH ) + ( 4 * m_nWRITEWATERFOGTODESTALPHA ) + ( 8 * m_nPIXELFOGTYPE ) + ( 16 * m_nLIGHTING_PREVIEW ) + 0; + } +}; +#define shaderDynamicTest_lightmappedgeneric_ps20 psh_forgot_to_set_dynamic_FASTPATHENVMAPCONTRAST + psh_forgot_to_set_dynamic_FASTPATH + psh_forgot_to_set_dynamic_WRITEWATERFOGTODESTALPHA + psh_forgot_to_set_dynamic_PIXELFOGTYPE + psh_forgot_to_set_dynamic_LIGHTING_PREVIEW + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/lightmappedgeneric_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/lightmappedgeneric_ps20b.inc new file mode 100644 index 0000000..3603f36 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/lightmappedgeneric_ps20b.inc @@ -0,0 +1,787 @@ +#include "shaderlib/cshader.h" +class lightmappedgeneric_ps20b_Static_Index +{ +private: + int m_nMASKEDBLENDING; +#ifdef _DEBUG + bool m_bMASKEDBLENDING; +#endif +public: + void SetMASKEDBLENDING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nMASKEDBLENDING = i; +#ifdef _DEBUG + m_bMASKEDBLENDING = true; +#endif + } + void SetMASKEDBLENDING( bool i ) + { + m_nMASKEDBLENDING = i ? 1 : 0; +#ifdef _DEBUG + m_bMASKEDBLENDING = true; +#endif + } +private: + int m_nBASETEXTURE2; +#ifdef _DEBUG + bool m_bBASETEXTURE2; +#endif +public: + void SetBASETEXTURE2( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBASETEXTURE2 = i; +#ifdef _DEBUG + m_bBASETEXTURE2 = true; +#endif + } + void SetBASETEXTURE2( bool i ) + { + m_nBASETEXTURE2 = i ? 1 : 0; +#ifdef _DEBUG + m_bBASETEXTURE2 = true; +#endif + } +private: + int m_nDETAILTEXTURE; +#ifdef _DEBUG + bool m_bDETAILTEXTURE; +#endif +public: + void SetDETAILTEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDETAILTEXTURE = i; +#ifdef _DEBUG + m_bDETAILTEXTURE = true; +#endif + } + void SetDETAILTEXTURE( bool i ) + { + m_nDETAILTEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bDETAILTEXTURE = true; +#endif + } +private: + int m_nBUMPMAP; +#ifdef _DEBUG + bool m_bBUMPMAP; +#endif +public: + void SetBUMPMAP( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nBUMPMAP = i; +#ifdef _DEBUG + m_bBUMPMAP = true; +#endif + } + void SetBUMPMAP( bool i ) + { + m_nBUMPMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bBUMPMAP = true; +#endif + } +private: + int m_nBUMPMAP2; +#ifdef _DEBUG + bool m_bBUMPMAP2; +#endif +public: + void SetBUMPMAP2( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBUMPMAP2 = i; +#ifdef _DEBUG + m_bBUMPMAP2 = true; +#endif + } + void SetBUMPMAP2( bool i ) + { + m_nBUMPMAP2 = i ? 1 : 0; +#ifdef _DEBUG + m_bBUMPMAP2 = true; +#endif + } +private: + int m_nCUBEMAP; +#ifdef _DEBUG + bool m_bCUBEMAP; +#endif +public: + void SetCUBEMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCUBEMAP = i; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } + void SetCUBEMAP( bool i ) + { + m_nCUBEMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } +private: + int m_nENVMAPMASK; +#ifdef _DEBUG + bool m_bENVMAPMASK; +#endif +public: + void SetENVMAPMASK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nENVMAPMASK = i; +#ifdef _DEBUG + m_bENVMAPMASK = true; +#endif + } + void SetENVMAPMASK( bool i ) + { + m_nENVMAPMASK = i ? 1 : 0; +#ifdef _DEBUG + m_bENVMAPMASK = true; +#endif + } +private: + int m_nBASEALPHAENVMAPMASK; +#ifdef _DEBUG + bool m_bBASEALPHAENVMAPMASK; +#endif +public: + void SetBASEALPHAENVMAPMASK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBASEALPHAENVMAPMASK = i; +#ifdef _DEBUG + m_bBASEALPHAENVMAPMASK = true; +#endif + } + void SetBASEALPHAENVMAPMASK( bool i ) + { + m_nBASEALPHAENVMAPMASK = i ? 1 : 0; +#ifdef _DEBUG + m_bBASEALPHAENVMAPMASK = true; +#endif + } +private: + int m_nSELFILLUM; +#ifdef _DEBUG + bool m_bSELFILLUM; +#endif +public: + void SetSELFILLUM( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSELFILLUM = i; +#ifdef _DEBUG + m_bSELFILLUM = true; +#endif + } + void SetSELFILLUM( bool i ) + { + m_nSELFILLUM = i ? 1 : 0; +#ifdef _DEBUG + m_bSELFILLUM = true; +#endif + } +private: + int m_nNORMALMAPALPHAENVMAPMASK; +#ifdef _DEBUG + bool m_bNORMALMAPALPHAENVMAPMASK; +#endif +public: + void SetNORMALMAPALPHAENVMAPMASK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nNORMALMAPALPHAENVMAPMASK = i; +#ifdef _DEBUG + m_bNORMALMAPALPHAENVMAPMASK = true; +#endif + } + void SetNORMALMAPALPHAENVMAPMASK( bool i ) + { + m_nNORMALMAPALPHAENVMAPMASK = i ? 1 : 0; +#ifdef _DEBUG + m_bNORMALMAPALPHAENVMAPMASK = true; +#endif + } +private: + int m_nDIFFUSEBUMPMAP; +#ifdef _DEBUG + bool m_bDIFFUSEBUMPMAP; +#endif +public: + void SetDIFFUSEBUMPMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDIFFUSEBUMPMAP = i; +#ifdef _DEBUG + m_bDIFFUSEBUMPMAP = true; +#endif + } + void SetDIFFUSEBUMPMAP( bool i ) + { + m_nDIFFUSEBUMPMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bDIFFUSEBUMPMAP = true; +#endif + } +private: + int m_nBASETEXTURENOENVMAP; +#ifdef _DEBUG + bool m_bBASETEXTURENOENVMAP; +#endif +public: + void SetBASETEXTURENOENVMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBASETEXTURENOENVMAP = i; +#ifdef _DEBUG + m_bBASETEXTURENOENVMAP = true; +#endif + } + void SetBASETEXTURENOENVMAP( bool i ) + { + m_nBASETEXTURENOENVMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bBASETEXTURENOENVMAP = true; +#endif + } +private: + int m_nBASETEXTURE2NOENVMAP; +#ifdef _DEBUG + bool m_bBASETEXTURE2NOENVMAP; +#endif +public: + void SetBASETEXTURE2NOENVMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBASETEXTURE2NOENVMAP = i; +#ifdef _DEBUG + m_bBASETEXTURE2NOENVMAP = true; +#endif + } + void SetBASETEXTURE2NOENVMAP( bool i ) + { + m_nBASETEXTURE2NOENVMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bBASETEXTURE2NOENVMAP = true; +#endif + } +private: + int m_nWARPLIGHTING; +#ifdef _DEBUG + bool m_bWARPLIGHTING; +#endif +public: + void SetWARPLIGHTING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nWARPLIGHTING = i; +#ifdef _DEBUG + m_bWARPLIGHTING = true; +#endif + } + void SetWARPLIGHTING( bool i ) + { + m_nWARPLIGHTING = i ? 1 : 0; +#ifdef _DEBUG + m_bWARPLIGHTING = true; +#endif + } +private: + int m_nFANCY_BLENDING; +#ifdef _DEBUG + bool m_bFANCY_BLENDING; +#endif +public: + void SetFANCY_BLENDING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFANCY_BLENDING = i; +#ifdef _DEBUG + m_bFANCY_BLENDING = true; +#endif + } + void SetFANCY_BLENDING( bool i ) + { + m_nFANCY_BLENDING = i ? 1 : 0; +#ifdef _DEBUG + m_bFANCY_BLENDING = true; +#endif + } +private: + int m_nRELIEF_MAPPING; +#ifdef _DEBUG + bool m_bRELIEF_MAPPING; +#endif +public: + void SetRELIEF_MAPPING( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nRELIEF_MAPPING = i; +#ifdef _DEBUG + m_bRELIEF_MAPPING = true; +#endif + } + void SetRELIEF_MAPPING( bool i ) + { + m_nRELIEF_MAPPING = i ? 1 : 0; +#ifdef _DEBUG + m_bRELIEF_MAPPING = true; +#endif + } +private: + int m_nSEAMLESS; +#ifdef _DEBUG + bool m_bSEAMLESS; +#endif +public: + void SetSEAMLESS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSEAMLESS = i; +#ifdef _DEBUG + m_bSEAMLESS = true; +#endif + } + void SetSEAMLESS( bool i ) + { + m_nSEAMLESS = i ? 1 : 0; +#ifdef _DEBUG + m_bSEAMLESS = true; +#endif + } +private: + int m_nOUTLINE; +#ifdef _DEBUG + bool m_bOUTLINE; +#endif +public: + void SetOUTLINE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nOUTLINE = i; +#ifdef _DEBUG + m_bOUTLINE = true; +#endif + } + void SetOUTLINE( bool i ) + { + m_nOUTLINE = i ? 1 : 0; +#ifdef _DEBUG + m_bOUTLINE = true; +#endif + } +private: + int m_nSOFTEDGES; +#ifdef _DEBUG + bool m_bSOFTEDGES; +#endif +public: + void SetSOFTEDGES( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSOFTEDGES = i; +#ifdef _DEBUG + m_bSOFTEDGES = true; +#endif + } + void SetSOFTEDGES( bool i ) + { + m_nSOFTEDGES = i ? 1 : 0; +#ifdef _DEBUG + m_bSOFTEDGES = true; +#endif + } +private: + int m_nBUMPMASK; +#ifdef _DEBUG + bool m_bBUMPMASK; +#endif +public: + void SetBUMPMASK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBUMPMASK = i; +#ifdef _DEBUG + m_bBUMPMASK = true; +#endif + } + void SetBUMPMASK( bool i ) + { + m_nBUMPMASK = i ? 1 : 0; +#ifdef _DEBUG + m_bBUMPMASK = true; +#endif + } +private: + int m_nNORMAL_DECODE_MODE; +#ifdef _DEBUG + bool m_bNORMAL_DECODE_MODE; +#endif +public: + void SetNORMAL_DECODE_MODE( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nNORMAL_DECODE_MODE = i; +#ifdef _DEBUG + m_bNORMAL_DECODE_MODE = true; +#endif + } + void SetNORMAL_DECODE_MODE( bool i ) + { + m_nNORMAL_DECODE_MODE = i ? 1 : 0; +#ifdef _DEBUG + m_bNORMAL_DECODE_MODE = true; +#endif + } +private: + int m_nNORMALMASK_DECODE_MODE; +#ifdef _DEBUG + bool m_bNORMALMASK_DECODE_MODE; +#endif +public: + void SetNORMALMASK_DECODE_MODE( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nNORMALMASK_DECODE_MODE = i; +#ifdef _DEBUG + m_bNORMALMASK_DECODE_MODE = true; +#endif + } + void SetNORMALMASK_DECODE_MODE( bool i ) + { + m_nNORMALMASK_DECODE_MODE = i ? 1 : 0; +#ifdef _DEBUG + m_bNORMALMASK_DECODE_MODE = true; +#endif + } +private: + int m_nDETAIL_BLEND_MODE; +#ifdef _DEBUG + bool m_bDETAIL_BLEND_MODE; +#endif +public: + void SetDETAIL_BLEND_MODE( int i ) + { + Assert( i >= 0 && i <= 11 ); + m_nDETAIL_BLEND_MODE = i; +#ifdef _DEBUG + m_bDETAIL_BLEND_MODE = true; +#endif + } + void SetDETAIL_BLEND_MODE( bool i ) + { + m_nDETAIL_BLEND_MODE = i ? 1 : 0; +#ifdef _DEBUG + m_bDETAIL_BLEND_MODE = true; +#endif + } +private: + int m_nFLASHLIGHT; +#ifdef _DEBUG + bool m_bFLASHLIGHT; +#endif +public: + void SetFLASHLIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFLASHLIGHT = i; +#ifdef _DEBUG + m_bFLASHLIGHT = true; +#endif + } + void SetFLASHLIGHT( bool i ) + { + m_nFLASHLIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bFLASHLIGHT = true; +#endif + } +public: + lightmappedgeneric_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bMASKEDBLENDING = false; +#endif // _DEBUG + m_nMASKEDBLENDING = 0; +#ifdef _DEBUG + m_bBASETEXTURE2 = false; +#endif // _DEBUG + m_nBASETEXTURE2 = 0; +#ifdef _DEBUG + m_bDETAILTEXTURE = false; +#endif // _DEBUG + m_nDETAILTEXTURE = 0; +#ifdef _DEBUG + m_bBUMPMAP = false; +#endif // _DEBUG + m_nBUMPMAP = 0; +#ifdef _DEBUG + m_bBUMPMAP2 = false; +#endif // _DEBUG + m_nBUMPMAP2 = 0; +#ifdef _DEBUG + m_bCUBEMAP = false; +#endif // _DEBUG + m_nCUBEMAP = 0; +#ifdef _DEBUG + m_bENVMAPMASK = false; +#endif // _DEBUG + m_nENVMAPMASK = 0; +#ifdef _DEBUG + m_bBASEALPHAENVMAPMASK = false; +#endif // _DEBUG + m_nBASEALPHAENVMAPMASK = 0; +#ifdef _DEBUG + m_bSELFILLUM = false; +#endif // _DEBUG + m_nSELFILLUM = 0; +#ifdef _DEBUG + m_bNORMALMAPALPHAENVMAPMASK = false; +#endif // _DEBUG + m_nNORMALMAPALPHAENVMAPMASK = 0; +#ifdef _DEBUG + m_bDIFFUSEBUMPMAP = false; +#endif // _DEBUG + m_nDIFFUSEBUMPMAP = 0; +#ifdef _DEBUG + m_bBASETEXTURENOENVMAP = false; +#endif // _DEBUG + m_nBASETEXTURENOENVMAP = 0; +#ifdef _DEBUG + m_bBASETEXTURE2NOENVMAP = false; +#endif // _DEBUG + m_nBASETEXTURE2NOENVMAP = 0; +#ifdef _DEBUG + m_bWARPLIGHTING = false; +#endif // _DEBUG + m_nWARPLIGHTING = 0; +#ifdef _DEBUG + m_bFANCY_BLENDING = false; +#endif // _DEBUG + m_nFANCY_BLENDING = 0; +#ifdef _DEBUG + m_bRELIEF_MAPPING = false; +#endif // _DEBUG + m_nRELIEF_MAPPING = 0; +#ifdef _DEBUG + m_bSEAMLESS = false; +#endif // _DEBUG + m_nSEAMLESS = 0; +#ifdef _DEBUG + m_bOUTLINE = false; +#endif // _DEBUG + m_nOUTLINE = 0; +#ifdef _DEBUG + m_bSOFTEDGES = false; +#endif // _DEBUG + m_nSOFTEDGES = 0; +#ifdef _DEBUG + m_bBUMPMASK = false; +#endif // _DEBUG + m_nBUMPMASK = 0; +#ifdef _DEBUG + m_bNORMAL_DECODE_MODE = false; +#endif // _DEBUG + m_nNORMAL_DECODE_MODE = 0; +#ifdef _DEBUG + m_bNORMALMASK_DECODE_MODE = false; +#endif // _DEBUG + m_nNORMALMASK_DECODE_MODE = 0; +#ifdef _DEBUG + m_bDETAIL_BLEND_MODE = false; +#endif // _DEBUG + m_nDETAIL_BLEND_MODE = 0; +#ifdef _DEBUG + m_bFLASHLIGHT = false; +#endif // _DEBUG + m_nFLASHLIGHT = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bMASKEDBLENDING && m_bBASETEXTURE2 && m_bDETAILTEXTURE && m_bBUMPMAP && m_bBUMPMAP2 && m_bCUBEMAP && m_bENVMAPMASK && m_bBASEALPHAENVMAPMASK && m_bSELFILLUM && m_bNORMALMAPALPHAENVMAPMASK && m_bDIFFUSEBUMPMAP && m_bBASETEXTURENOENVMAP && m_bBASETEXTURE2NOENVMAP && m_bWARPLIGHTING && m_bFANCY_BLENDING && m_bRELIEF_MAPPING && m_bSEAMLESS && m_bOUTLINE && m_bSOFTEDGES && m_bBUMPMASK && m_bNORMAL_DECODE_MODE && m_bNORMALMASK_DECODE_MODE && m_bDETAIL_BLEND_MODE && m_bFLASHLIGHT; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 16 * m_nMASKEDBLENDING ) + ( 32 * m_nBASETEXTURE2 ) + ( 64 * m_nDETAILTEXTURE ) + ( 128 * m_nBUMPMAP ) + ( 384 * m_nBUMPMAP2 ) + ( 768 * m_nCUBEMAP ) + ( 1536 * m_nENVMAPMASK ) + ( 3072 * m_nBASEALPHAENVMAPMASK ) + ( 6144 * m_nSELFILLUM ) + ( 12288 * m_nNORMALMAPALPHAENVMAPMASK ) + ( 24576 * m_nDIFFUSEBUMPMAP ) + ( 49152 * m_nBASETEXTURENOENVMAP ) + ( 98304 * m_nBASETEXTURE2NOENVMAP ) + ( 196608 * m_nWARPLIGHTING ) + ( 393216 * m_nFANCY_BLENDING ) + ( 786432 * m_nRELIEF_MAPPING ) + ( 786432 * m_nSEAMLESS ) + ( 1572864 * m_nOUTLINE ) + ( 3145728 * m_nSOFTEDGES ) + ( 6291456 * m_nBUMPMASK ) + ( 12582912 * m_nNORMAL_DECODE_MODE ) + ( 12582912 * m_nNORMALMASK_DECODE_MODE ) + ( 12582912 * m_nDETAIL_BLEND_MODE ) + ( 150994944 * m_nFLASHLIGHT ) + 0; + } +}; +#define shaderStaticTest_lightmappedgeneric_ps20b psh_forgot_to_set_static_MASKEDBLENDING + psh_forgot_to_set_static_BASETEXTURE2 + psh_forgot_to_set_static_DETAILTEXTURE + psh_forgot_to_set_static_BUMPMAP + psh_forgot_to_set_static_BUMPMAP2 + psh_forgot_to_set_static_CUBEMAP + psh_forgot_to_set_static_ENVMAPMASK + psh_forgot_to_set_static_BASEALPHAENVMAPMASK + psh_forgot_to_set_static_SELFILLUM + psh_forgot_to_set_static_NORMALMAPALPHAENVMAPMASK + psh_forgot_to_set_static_DIFFUSEBUMPMAP + psh_forgot_to_set_static_BASETEXTURENOENVMAP + psh_forgot_to_set_static_BASETEXTURE2NOENVMAP + psh_forgot_to_set_static_WARPLIGHTING + psh_forgot_to_set_static_FANCY_BLENDING + psh_forgot_to_set_static_RELIEF_MAPPING + psh_forgot_to_set_static_SEAMLESS + psh_forgot_to_set_static_OUTLINE + psh_forgot_to_set_static_SOFTEDGES + psh_forgot_to_set_static_BUMPMASK + psh_forgot_to_set_static_NORMAL_DECODE_MODE + psh_forgot_to_set_static_NORMALMASK_DECODE_MODE + psh_forgot_to_set_static_DETAIL_BLEND_MODE + psh_forgot_to_set_static_FLASHLIGHT + 0 +class lightmappedgeneric_ps20b_Dynamic_Index +{ +private: + int m_nFASTPATHENVMAPCONTRAST; +#ifdef _DEBUG + bool m_bFASTPATHENVMAPCONTRAST; +#endif +public: + void SetFASTPATHENVMAPCONTRAST( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFASTPATHENVMAPCONTRAST = i; +#ifdef _DEBUG + m_bFASTPATHENVMAPCONTRAST = true; +#endif + } + void SetFASTPATHENVMAPCONTRAST( bool i ) + { + m_nFASTPATHENVMAPCONTRAST = i ? 1 : 0; +#ifdef _DEBUG + m_bFASTPATHENVMAPCONTRAST = true; +#endif + } +private: + int m_nFASTPATH; +#ifdef _DEBUG + bool m_bFASTPATH; +#endif +public: + void SetFASTPATH( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFASTPATH = i; +#ifdef _DEBUG + m_bFASTPATH = true; +#endif + } + void SetFASTPATH( bool i ) + { + m_nFASTPATH = i ? 1 : 0; +#ifdef _DEBUG + m_bFASTPATH = true; +#endif + } +private: + int m_nWRITEWATERFOGTODESTALPHA; +#ifdef _DEBUG + bool m_bWRITEWATERFOGTODESTALPHA; +#endif +public: + void SetWRITEWATERFOGTODESTALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nWRITEWATERFOGTODESTALPHA = i; +#ifdef _DEBUG + m_bWRITEWATERFOGTODESTALPHA = true; +#endif + } + void SetWRITEWATERFOGTODESTALPHA( bool i ) + { + m_nWRITEWATERFOGTODESTALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bWRITEWATERFOGTODESTALPHA = true; +#endif + } +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +private: + int m_nLIGHTING_PREVIEW; +#ifdef _DEBUG + bool m_bLIGHTING_PREVIEW; +#endif +public: + void SetLIGHTING_PREVIEW( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nLIGHTING_PREVIEW = i; +#ifdef _DEBUG + m_bLIGHTING_PREVIEW = true; +#endif + } + void SetLIGHTING_PREVIEW( bool i ) + { + m_nLIGHTING_PREVIEW = i ? 1 : 0; +#ifdef _DEBUG + m_bLIGHTING_PREVIEW = true; +#endif + } +private: + int m_nWRITE_DEPTH_TO_DESTALPHA; +#ifdef _DEBUG + bool m_bWRITE_DEPTH_TO_DESTALPHA; +#endif +public: + void SetWRITE_DEPTH_TO_DESTALPHA( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nWRITE_DEPTH_TO_DESTALPHA = i; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = true; +#endif + } + void SetWRITE_DEPTH_TO_DESTALPHA( bool i ) + { + m_nWRITE_DEPTH_TO_DESTALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = true; +#endif + } +public: + lightmappedgeneric_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bFASTPATHENVMAPCONTRAST = false; +#endif // _DEBUG + m_nFASTPATHENVMAPCONTRAST = 0; +#ifdef _DEBUG + m_bFASTPATH = false; +#endif // _DEBUG + m_nFASTPATH = 0; +#ifdef _DEBUG + m_bWRITEWATERFOGTODESTALPHA = false; +#endif // _DEBUG + m_nWRITEWATERFOGTODESTALPHA = 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; +#ifdef _DEBUG + m_bLIGHTING_PREVIEW = false; +#endif // _DEBUG + m_nLIGHTING_PREVIEW = 0; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = false; +#endif // _DEBUG + m_nWRITE_DEPTH_TO_DESTALPHA = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bFASTPATHENVMAPCONTRAST && m_bFASTPATH && m_bWRITEWATERFOGTODESTALPHA && m_bPIXELFOGTYPE && m_bLIGHTING_PREVIEW && m_bWRITE_DEPTH_TO_DESTALPHA; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nFASTPATHENVMAPCONTRAST ) + ( 2 * m_nFASTPATH ) + ( 4 * m_nWRITEWATERFOGTODESTALPHA ) + ( 8 * m_nPIXELFOGTYPE ) + ( 16 * m_nLIGHTING_PREVIEW ) + ( 16 * m_nWRITE_DEPTH_TO_DESTALPHA ) + 0; + } +}; +#define shaderDynamicTest_lightmappedgeneric_ps20b psh_forgot_to_set_dynamic_FASTPATHENVMAPCONTRAST + psh_forgot_to_set_dynamic_FASTPATH + psh_forgot_to_set_dynamic_WRITEWATERFOGTODESTALPHA + psh_forgot_to_set_dynamic_PIXELFOGTYPE + psh_forgot_to_set_dynamic_LIGHTING_PREVIEW + psh_forgot_to_set_dynamic_WRITE_DEPTH_TO_DESTALPHA + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/lightmappedgeneric_vs20.inc b/materialsystem/stdshaders/fxctmp9_360/lightmappedgeneric_vs20.inc new file mode 100644 index 0000000..52900f8 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/lightmappedgeneric_vs20.inc @@ -0,0 +1,362 @@ +#include "shaderlib/cshader.h" +class lightmappedgeneric_vs20_Static_Index +{ +private: + int m_nENVMAP_MASK; +#ifdef _DEBUG + bool m_bENVMAP_MASK; +#endif +public: + void SetENVMAP_MASK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nENVMAP_MASK = i; +#ifdef _DEBUG + m_bENVMAP_MASK = true; +#endif + } + void SetENVMAP_MASK( bool i ) + { + m_nENVMAP_MASK = i ? 1 : 0; +#ifdef _DEBUG + m_bENVMAP_MASK = true; +#endif + } +private: + int m_nTANGENTSPACE; +#ifdef _DEBUG + bool m_bTANGENTSPACE; +#endif +public: + void SetTANGENTSPACE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nTANGENTSPACE = i; +#ifdef _DEBUG + m_bTANGENTSPACE = true; +#endif + } + void SetTANGENTSPACE( bool i ) + { + m_nTANGENTSPACE = i ? 1 : 0; +#ifdef _DEBUG + m_bTANGENTSPACE = true; +#endif + } +private: + int m_nBUMPMAP; +#ifdef _DEBUG + bool m_bBUMPMAP; +#endif +public: + void SetBUMPMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBUMPMAP = i; +#ifdef _DEBUG + m_bBUMPMAP = true; +#endif + } + void SetBUMPMAP( bool i ) + { + m_nBUMPMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bBUMPMAP = true; +#endif + } +private: + int m_nDIFFUSEBUMPMAP; +#ifdef _DEBUG + bool m_bDIFFUSEBUMPMAP; +#endif +public: + void SetDIFFUSEBUMPMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDIFFUSEBUMPMAP = i; +#ifdef _DEBUG + m_bDIFFUSEBUMPMAP = true; +#endif + } + void SetDIFFUSEBUMPMAP( bool i ) + { + m_nDIFFUSEBUMPMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bDIFFUSEBUMPMAP = true; +#endif + } +private: + int m_nVERTEXCOLOR; +#ifdef _DEBUG + bool m_bVERTEXCOLOR; +#endif +public: + void SetVERTEXCOLOR( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nVERTEXCOLOR = i; +#ifdef _DEBUG + m_bVERTEXCOLOR = true; +#endif + } + void SetVERTEXCOLOR( bool i ) + { + m_nVERTEXCOLOR = i ? 1 : 0; +#ifdef _DEBUG + m_bVERTEXCOLOR = true; +#endif + } +private: + int m_nVERTEXALPHATEXBLENDFACTOR; +#ifdef _DEBUG + bool m_bVERTEXALPHATEXBLENDFACTOR; +#endif +public: + void SetVERTEXALPHATEXBLENDFACTOR( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nVERTEXALPHATEXBLENDFACTOR = i; +#ifdef _DEBUG + m_bVERTEXALPHATEXBLENDFACTOR = true; +#endif + } + void SetVERTEXALPHATEXBLENDFACTOR( bool i ) + { + m_nVERTEXALPHATEXBLENDFACTOR = i ? 1 : 0; +#ifdef _DEBUG + m_bVERTEXALPHATEXBLENDFACTOR = true; +#endif + } +private: + int m_nRELIEF_MAPPING; +#ifdef _DEBUG + bool m_bRELIEF_MAPPING; +#endif +public: + void SetRELIEF_MAPPING( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nRELIEF_MAPPING = i; +#ifdef _DEBUG + m_bRELIEF_MAPPING = true; +#endif + } + void SetRELIEF_MAPPING( bool i ) + { + m_nRELIEF_MAPPING = i ? 1 : 0; +#ifdef _DEBUG + m_bRELIEF_MAPPING = true; +#endif + } +private: + int m_nSEAMLESS; +#ifdef _DEBUG + bool m_bSEAMLESS; +#endif +public: + void SetSEAMLESS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSEAMLESS = i; +#ifdef _DEBUG + m_bSEAMLESS = true; +#endif + } + void SetSEAMLESS( bool i ) + { + m_nSEAMLESS = i ? 1 : 0; +#ifdef _DEBUG + m_bSEAMLESS = true; +#endif + } +private: + int m_nBUMPMASK; +#ifdef _DEBUG + bool m_bBUMPMASK; +#endif +public: + void SetBUMPMASK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBUMPMASK = i; +#ifdef _DEBUG + m_bBUMPMASK = true; +#endif + } + void SetBUMPMASK( bool i ) + { + m_nBUMPMASK = i ? 1 : 0; +#ifdef _DEBUG + m_bBUMPMASK = true; +#endif + } +private: + int m_nFLASHLIGHT; +#ifdef _DEBUG + bool m_bFLASHLIGHT; +#endif +public: + void SetFLASHLIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFLASHLIGHT = i; +#ifdef _DEBUG + m_bFLASHLIGHT = true; +#endif + } + void SetFLASHLIGHT( bool i ) + { + m_nFLASHLIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bFLASHLIGHT = true; +#endif + } +public: + lightmappedgeneric_vs20_Static_Index( ) + { +#ifdef _DEBUG + m_bENVMAP_MASK = false; +#endif // _DEBUG + m_nENVMAP_MASK = 0; +#ifdef _DEBUG + m_bTANGENTSPACE = false; +#endif // _DEBUG + m_nTANGENTSPACE = 0; +#ifdef _DEBUG + m_bBUMPMAP = false; +#endif // _DEBUG + m_nBUMPMAP = 0; +#ifdef _DEBUG + m_bDIFFUSEBUMPMAP = false; +#endif // _DEBUG + m_nDIFFUSEBUMPMAP = 0; +#ifdef _DEBUG + m_bVERTEXCOLOR = false; +#endif // _DEBUG + m_nVERTEXCOLOR = 0; +#ifdef _DEBUG + m_bVERTEXALPHATEXBLENDFACTOR = false; +#endif // _DEBUG + m_nVERTEXALPHATEXBLENDFACTOR = 0; +#ifdef _DEBUG + m_bRELIEF_MAPPING = false; +#endif // _DEBUG + m_nRELIEF_MAPPING = 0; +#ifdef _DEBUG + m_bSEAMLESS = false; +#endif // _DEBUG + m_nSEAMLESS = 0; +#ifdef _DEBUG + m_bBUMPMASK = false; +#endif // _DEBUG + m_nBUMPMASK = 0; +#ifdef _DEBUG + m_bFLASHLIGHT = false; +#endif // _DEBUG + m_nFLASHLIGHT = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bENVMAP_MASK && m_bTANGENTSPACE && m_bBUMPMAP && m_bDIFFUSEBUMPMAP && m_bVERTEXCOLOR && m_bVERTEXALPHATEXBLENDFACTOR && m_bRELIEF_MAPPING && m_bSEAMLESS && m_bBUMPMASK && m_bFLASHLIGHT; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 4 * m_nENVMAP_MASK ) + ( 8 * m_nTANGENTSPACE ) + ( 16 * m_nBUMPMAP ) + ( 32 * m_nDIFFUSEBUMPMAP ) + ( 64 * m_nVERTEXCOLOR ) + ( 128 * m_nVERTEXALPHATEXBLENDFACTOR ) + ( 256 * m_nRELIEF_MAPPING ) + ( 256 * m_nSEAMLESS ) + ( 512 * m_nBUMPMASK ) + ( 1024 * m_nFLASHLIGHT ) + 0; + } +}; +#define shaderStaticTest_lightmappedgeneric_vs20 vsh_forgot_to_set_static_ENVMAP_MASK + vsh_forgot_to_set_static_TANGENTSPACE + vsh_forgot_to_set_static_BUMPMAP + vsh_forgot_to_set_static_DIFFUSEBUMPMAP + vsh_forgot_to_set_static_VERTEXCOLOR + vsh_forgot_to_set_static_VERTEXALPHATEXBLENDFACTOR + vsh_forgot_to_set_static_RELIEF_MAPPING + vsh_forgot_to_set_static_SEAMLESS + vsh_forgot_to_set_static_BUMPMASK + vsh_forgot_to_set_static_FLASHLIGHT + 0 +class lightmappedgeneric_vs20_Dynamic_Index +{ +private: + int m_nFASTPATH; +#ifdef _DEBUG + bool m_bFASTPATH; +#endif +public: + void SetFASTPATH( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFASTPATH = i; +#ifdef _DEBUG + m_bFASTPATH = true; +#endif + } + void SetFASTPATH( bool i ) + { + m_nFASTPATH = i ? 1 : 0; +#ifdef _DEBUG + m_bFASTPATH = true; +#endif + } +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nLIGHTING_PREVIEW; +#ifdef _DEBUG + bool m_bLIGHTING_PREVIEW; +#endif +public: + void SetLIGHTING_PREVIEW( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nLIGHTING_PREVIEW = i; +#ifdef _DEBUG + m_bLIGHTING_PREVIEW = true; +#endif + } + void SetLIGHTING_PREVIEW( bool i ) + { + m_nLIGHTING_PREVIEW = i ? 1 : 0; +#ifdef _DEBUG + m_bLIGHTING_PREVIEW = true; +#endif + } +public: + lightmappedgeneric_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bFASTPATH = false; +#endif // _DEBUG + m_nFASTPATH = 0; +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bLIGHTING_PREVIEW = false; +#endif // _DEBUG + m_nLIGHTING_PREVIEW = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bFASTPATH && m_bDOWATERFOG && m_bLIGHTING_PREVIEW; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nFASTPATH ) + ( 2 * m_nDOWATERFOG ) + ( 4 * m_nLIGHTING_PREVIEW ) + 0; + } +}; +#define shaderDynamicTest_lightmappedgeneric_vs20 vsh_forgot_to_set_dynamic_FASTPATH + vsh_forgot_to_set_dynamic_DOWATERFOG + vsh_forgot_to_set_dynamic_LIGHTING_PREVIEW + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/lightmappedreflective_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/lightmappedreflective_ps20.inc new file mode 100644 index 0000000..c1a6c2d --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/lightmappedreflective_ps20.inc @@ -0,0 +1,187 @@ +#include "shaderlib/cshader.h" +class lightmappedreflective_ps20_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +private: + int m_nBASETEXTURE; +#ifdef _DEBUG + bool m_bBASETEXTURE; +#endif +public: + void SetBASETEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBASETEXTURE = i; +#ifdef _DEBUG + m_bBASETEXTURE = true; +#endif + } + void SetBASETEXTURE( bool i ) + { + m_nBASETEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bBASETEXTURE = true; +#endif + } +private: + int m_nREFLECT; +#ifdef _DEBUG + bool m_bREFLECT; +#endif +public: + void SetREFLECT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nREFLECT = i; +#ifdef _DEBUG + m_bREFLECT = true; +#endif + } + void SetREFLECT( bool i ) + { + m_nREFLECT = i ? 1 : 0; +#ifdef _DEBUG + m_bREFLECT = true; +#endif + } +private: + int m_nREFRACT; +#ifdef _DEBUG + bool m_bREFRACT; +#endif +public: + void SetREFRACT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nREFRACT = i; +#ifdef _DEBUG + m_bREFRACT = true; +#endif + } + void SetREFRACT( bool i ) + { + m_nREFRACT = i ? 1 : 0; +#ifdef _DEBUG + m_bREFRACT = true; +#endif + } +private: + int m_nENVMAPMASK; +#ifdef _DEBUG + bool m_bENVMAPMASK; +#endif +public: + void SetENVMAPMASK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nENVMAPMASK = i; +#ifdef _DEBUG + m_bENVMAPMASK = true; +#endif + } + void SetENVMAPMASK( bool i ) + { + m_nENVMAPMASK = i ? 1 : 0; +#ifdef _DEBUG + m_bENVMAPMASK = true; +#endif + } +public: + lightmappedreflective_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; +#ifdef _DEBUG + m_bBASETEXTURE = false; +#endif // _DEBUG + m_nBASETEXTURE = 0; +#ifdef _DEBUG + m_bREFLECT = false; +#endif // _DEBUG + m_nREFLECT = 0; +#ifdef _DEBUG + m_bREFRACT = false; +#endif // _DEBUG + m_nREFRACT = 0; +#ifdef _DEBUG + m_bENVMAPMASK = false; +#endif // _DEBUG + m_nENVMAPMASK = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB && m_bBASETEXTURE && m_bREFLECT && m_bREFRACT && m_bENVMAPMASK; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nCONVERT_TO_SRGB ) + ( 2 * m_nBASETEXTURE ) + ( 4 * m_nREFLECT ) + ( 8 * m_nREFRACT ) + ( 16 * m_nENVMAPMASK ) + 0; + } +}; +#define shaderStaticTest_lightmappedreflective_ps20 psh_forgot_to_set_static_BASETEXTURE + psh_forgot_to_set_static_REFLECT + psh_forgot_to_set_static_REFRACT + psh_forgot_to_set_static_ENVMAPMASK + 0 +class lightmappedreflective_ps20_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + lightmappedreflective_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_lightmappedreflective_ps20 psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/lightmappedreflective_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/lightmappedreflective_ps20b.inc new file mode 100644 index 0000000..33cba0d --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/lightmappedreflective_ps20b.inc @@ -0,0 +1,212 @@ +#include "shaderlib/cshader.h" +class lightmappedreflective_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +private: + int m_nBASETEXTURE; +#ifdef _DEBUG + bool m_bBASETEXTURE; +#endif +public: + void SetBASETEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBASETEXTURE = i; +#ifdef _DEBUG + m_bBASETEXTURE = true; +#endif + } + void SetBASETEXTURE( bool i ) + { + m_nBASETEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bBASETEXTURE = true; +#endif + } +private: + int m_nREFLECT; +#ifdef _DEBUG + bool m_bREFLECT; +#endif +public: + void SetREFLECT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nREFLECT = i; +#ifdef _DEBUG + m_bREFLECT = true; +#endif + } + void SetREFLECT( bool i ) + { + m_nREFLECT = i ? 1 : 0; +#ifdef _DEBUG + m_bREFLECT = true; +#endif + } +private: + int m_nREFRACT; +#ifdef _DEBUG + bool m_bREFRACT; +#endif +public: + void SetREFRACT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nREFRACT = i; +#ifdef _DEBUG + m_bREFRACT = true; +#endif + } + void SetREFRACT( bool i ) + { + m_nREFRACT = i ? 1 : 0; +#ifdef _DEBUG + m_bREFRACT = true; +#endif + } +private: + int m_nENVMAPMASK; +#ifdef _DEBUG + bool m_bENVMAPMASK; +#endif +public: + void SetENVMAPMASK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nENVMAPMASK = i; +#ifdef _DEBUG + m_bENVMAPMASK = true; +#endif + } + void SetENVMAPMASK( bool i ) + { + m_nENVMAPMASK = i ? 1 : 0; +#ifdef _DEBUG + m_bENVMAPMASK = true; +#endif + } +public: + lightmappedreflective_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; +#ifdef _DEBUG + m_bBASETEXTURE = false; +#endif // _DEBUG + m_nBASETEXTURE = 0; +#ifdef _DEBUG + m_bREFLECT = false; +#endif // _DEBUG + m_nREFLECT = 0; +#ifdef _DEBUG + m_bREFRACT = false; +#endif // _DEBUG + m_nREFRACT = 0; +#ifdef _DEBUG + m_bENVMAPMASK = false; +#endif // _DEBUG + m_nENVMAPMASK = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB && m_bBASETEXTURE && m_bREFLECT && m_bREFRACT && m_bENVMAPMASK; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nCONVERT_TO_SRGB ) + ( 2 * m_nBASETEXTURE ) + ( 4 * m_nREFLECT ) + ( 8 * m_nREFRACT ) + ( 16 * m_nENVMAPMASK ) + 0; + } +}; +#define shaderStaticTest_lightmappedreflective_ps20b psh_forgot_to_set_static_BASETEXTURE + psh_forgot_to_set_static_REFLECT + psh_forgot_to_set_static_REFRACT + psh_forgot_to_set_static_ENVMAPMASK + 0 +class lightmappedreflective_ps20b_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +private: + int m_nWRITE_DEPTH_TO_DESTALPHA; +#ifdef _DEBUG + bool m_bWRITE_DEPTH_TO_DESTALPHA; +#endif +public: + void SetWRITE_DEPTH_TO_DESTALPHA( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nWRITE_DEPTH_TO_DESTALPHA = i; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = true; +#endif + } + void SetWRITE_DEPTH_TO_DESTALPHA( bool i ) + { + m_nWRITE_DEPTH_TO_DESTALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = true; +#endif + } +public: + lightmappedreflective_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = false; +#endif // _DEBUG + m_nWRITE_DEPTH_TO_DESTALPHA = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE && m_bWRITE_DEPTH_TO_DESTALPHA; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + ( 2 * m_nWRITE_DEPTH_TO_DESTALPHA ) + 0; + } +}; +#define shaderDynamicTest_lightmappedreflective_ps20b psh_forgot_to_set_dynamic_PIXELFOGTYPE + psh_forgot_to_set_dynamic_WRITE_DEPTH_TO_DESTALPHA + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/lightmappedreflective_vs20.inc b/materialsystem/stdshaders/fxctmp9_360/lightmappedreflective_vs20.inc new file mode 100644 index 0000000..5e8df64 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/lightmappedreflective_vs20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class lightmappedreflective_vs20_Static_Index +{ +private: + int m_nBASETEXTURE; +#ifdef _DEBUG + bool m_bBASETEXTURE; +#endif +public: + void SetBASETEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBASETEXTURE = i; +#ifdef _DEBUG + m_bBASETEXTURE = true; +#endif + } + void SetBASETEXTURE( bool i ) + { + m_nBASETEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bBASETEXTURE = true; +#endif + } +public: + lightmappedreflective_vs20_Static_Index( ) + { +#ifdef _DEBUG + m_bBASETEXTURE = false; +#endif // _DEBUG + m_nBASETEXTURE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bBASETEXTURE; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nBASETEXTURE ) + 0; + } +}; +#define shaderStaticTest_lightmappedreflective_vs20 vsh_forgot_to_set_static_BASETEXTURE + 0 +class lightmappedreflective_vs20_Dynamic_Index +{ +public: + lightmappedreflective_vs20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_lightmappedreflective_vs20 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/lpreview1_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/lpreview1_ps20.inc new file mode 100644 index 0000000..9edf87b --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/lpreview1_ps20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class lpreview1_ps20_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + lpreview1_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_lpreview1_ps20 0 +class lpreview1_ps20_Dynamic_Index +{ +public: + lpreview1_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_lpreview1_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/lpreview1_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/lpreview1_ps20b.inc new file mode 100644 index 0000000..8865514 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/lpreview1_ps20b.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class lpreview1_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + lpreview1_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_lpreview1_ps20b 0 +class lpreview1_ps20b_Dynamic_Index +{ +public: + lpreview1_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_lpreview1_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/lpreview_output_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/lpreview_output_ps20.inc new file mode 100644 index 0000000..af99861 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/lpreview_output_ps20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class lpreview_output_ps20_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + lpreview_output_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_lpreview_output_ps20 0 +class lpreview_output_ps20_Dynamic_Index +{ +public: + lpreview_output_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_lpreview_output_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/lpreview_output_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/lpreview_output_ps20b.inc new file mode 100644 index 0000000..48b8f43 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/lpreview_output_ps20b.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class lpreview_output_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + lpreview_output_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_lpreview_output_ps20b 0 +class lpreview_output_ps20b_Dynamic_Index +{ +public: + lpreview_output_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_lpreview_output_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/luminance_compare_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/luminance_compare_ps20.inc new file mode 100644 index 0000000..f2c85fb --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/luminance_compare_ps20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class luminance_compare_ps20_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + luminance_compare_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_luminance_compare_ps20 0 +class luminance_compare_ps20_Dynamic_Index +{ +public: + luminance_compare_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_luminance_compare_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/luminance_compare_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/luminance_compare_ps20b.inc new file mode 100644 index 0000000..a9b8942 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/luminance_compare_ps20b.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class luminance_compare_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + luminance_compare_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_luminance_compare_ps20b 0 +class luminance_compare_ps20b_Dynamic_Index +{ +public: + luminance_compare_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_luminance_compare_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/modulate_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/modulate_ps20.inc new file mode 100644 index 0000000..5e14cbd --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/modulate_ps20.inc @@ -0,0 +1,87 @@ +#include "shaderlib/cshader.h" +class modulate_ps20_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + modulate_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_modulate_ps20 0 +class modulate_ps20_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + modulate_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_modulate_ps20 psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/modulate_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/modulate_ps20b.inc new file mode 100644 index 0000000..4a13bf2 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/modulate_ps20b.inc @@ -0,0 +1,112 @@ +#include "shaderlib/cshader.h" +class modulate_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + modulate_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_modulate_ps20b 0 +class modulate_ps20b_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +private: + int m_nWRITE_DEPTH_TO_DESTALPHA; +#ifdef _DEBUG + bool m_bWRITE_DEPTH_TO_DESTALPHA; +#endif +public: + void SetWRITE_DEPTH_TO_DESTALPHA( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nWRITE_DEPTH_TO_DESTALPHA = i; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = true; +#endif + } + void SetWRITE_DEPTH_TO_DESTALPHA( bool i ) + { + m_nWRITE_DEPTH_TO_DESTALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = true; +#endif + } +public: + modulate_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = false; +#endif // _DEBUG + m_nWRITE_DEPTH_TO_DESTALPHA = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE && m_bWRITE_DEPTH_TO_DESTALPHA; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + ( 2 * m_nWRITE_DEPTH_TO_DESTALPHA ) + 0; + } +}; +#define shaderDynamicTest_modulate_ps20b psh_forgot_to_set_dynamic_PIXELFOGTYPE + psh_forgot_to_set_dynamic_WRITE_DEPTH_TO_DESTALPHA + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/monitorscreen_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/monitorscreen_ps20.inc new file mode 100644 index 0000000..949e289 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/monitorscreen_ps20.inc @@ -0,0 +1,112 @@ +#include "shaderlib/cshader.h" +class monitorscreen_ps20_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +private: + int m_nTEXTURE2; +#ifdef _DEBUG + bool m_bTEXTURE2; +#endif +public: + void SetTEXTURE2( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nTEXTURE2 = i; +#ifdef _DEBUG + m_bTEXTURE2 = true; +#endif + } + void SetTEXTURE2( bool i ) + { + m_nTEXTURE2 = i ? 1 : 0; +#ifdef _DEBUG + m_bTEXTURE2 = true; +#endif + } +public: + monitorscreen_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; +#ifdef _DEBUG + m_bTEXTURE2 = false; +#endif // _DEBUG + m_nTEXTURE2 = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB && m_bTEXTURE2; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nCONVERT_TO_SRGB ) + ( 2 * m_nTEXTURE2 ) + 0; + } +}; +#define shaderStaticTest_monitorscreen_ps20 psh_forgot_to_set_static_TEXTURE2 + 0 +class monitorscreen_ps20_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + monitorscreen_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_monitorscreen_ps20 psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/monitorscreen_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/monitorscreen_ps20b.inc new file mode 100644 index 0000000..e3e9073 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/monitorscreen_ps20b.inc @@ -0,0 +1,137 @@ +#include "shaderlib/cshader.h" +class monitorscreen_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +private: + int m_nTEXTURE2; +#ifdef _DEBUG + bool m_bTEXTURE2; +#endif +public: + void SetTEXTURE2( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nTEXTURE2 = i; +#ifdef _DEBUG + m_bTEXTURE2 = true; +#endif + } + void SetTEXTURE2( bool i ) + { + m_nTEXTURE2 = i ? 1 : 0; +#ifdef _DEBUG + m_bTEXTURE2 = true; +#endif + } +public: + monitorscreen_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; +#ifdef _DEBUG + m_bTEXTURE2 = false; +#endif // _DEBUG + m_nTEXTURE2 = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB && m_bTEXTURE2; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nCONVERT_TO_SRGB ) + ( 2 * m_nTEXTURE2 ) + 0; + } +}; +#define shaderStaticTest_monitorscreen_ps20b psh_forgot_to_set_static_TEXTURE2 + 0 +class monitorscreen_ps20b_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +private: + int m_nWRITE_DEPTH_TO_DESTALPHA; +#ifdef _DEBUG + bool m_bWRITE_DEPTH_TO_DESTALPHA; +#endif +public: + void SetWRITE_DEPTH_TO_DESTALPHA( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nWRITE_DEPTH_TO_DESTALPHA = i; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = true; +#endif + } + void SetWRITE_DEPTH_TO_DESTALPHA( bool i ) + { + m_nWRITE_DEPTH_TO_DESTALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = true; +#endif + } +public: + monitorscreen_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = false; +#endif // _DEBUG + m_nWRITE_DEPTH_TO_DESTALPHA = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE && m_bWRITE_DEPTH_TO_DESTALPHA; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + ( 2 * m_nWRITE_DEPTH_TO_DESTALPHA ) + 0; + } +}; +#define shaderDynamicTest_monitorscreen_ps20b psh_forgot_to_set_dynamic_PIXELFOGTYPE + psh_forgot_to_set_dynamic_WRITE_DEPTH_TO_DESTALPHA + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/motion_blur_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/motion_blur_ps20.inc new file mode 100644 index 0000000..10ff009 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/motion_blur_ps20.inc @@ -0,0 +1,87 @@ +#include "shaderlib/cshader.h" +class motion_blur_ps20_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + motion_blur_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 4 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_motion_blur_ps20 0 +class motion_blur_ps20_Dynamic_Index +{ +private: + int m_nQUALITY; +#ifdef _DEBUG + bool m_bQUALITY; +#endif +public: + void SetQUALITY( int i ) + { + Assert( i >= 0 && i <= 3 ); + m_nQUALITY = i; +#ifdef _DEBUG + m_bQUALITY = true; +#endif + } + void SetQUALITY( bool i ) + { + m_nQUALITY = i ? 1 : 0; +#ifdef _DEBUG + m_bQUALITY = true; +#endif + } +public: + motion_blur_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bQUALITY = false; +#endif // _DEBUG + m_nQUALITY = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bQUALITY; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nQUALITY ) + 0; + } +}; +#define shaderDynamicTest_motion_blur_ps20 psh_forgot_to_set_dynamic_QUALITY + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/motion_blur_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/motion_blur_ps20b.inc new file mode 100644 index 0000000..f79b4bb --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/motion_blur_ps20b.inc @@ -0,0 +1,87 @@ +#include "shaderlib/cshader.h" +class motion_blur_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + motion_blur_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 4 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_motion_blur_ps20b 0 +class motion_blur_ps20b_Dynamic_Index +{ +private: + int m_nQUALITY; +#ifdef _DEBUG + bool m_bQUALITY; +#endif +public: + void SetQUALITY( int i ) + { + Assert( i >= 0 && i <= 3 ); + m_nQUALITY = i; +#ifdef _DEBUG + m_bQUALITY = true; +#endif + } + void SetQUALITY( bool i ) + { + m_nQUALITY = i ? 1 : 0; +#ifdef _DEBUG + m_bQUALITY = true; +#endif + } +public: + motion_blur_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bQUALITY = false; +#endif // _DEBUG + m_nQUALITY = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bQUALITY; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nQUALITY ) + 0; + } +}; +#define shaderDynamicTest_motion_blur_ps20b psh_forgot_to_set_dynamic_QUALITY + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/motion_blur_vs20.inc b/materialsystem/stdshaders/fxctmp9_360/motion_blur_vs20.inc new file mode 100644 index 0000000..ff9b0c7 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/motion_blur_vs20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class motion_blur_vs20_Static_Index +{ +public: + motion_blur_vs20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_motion_blur_vs20 0 +class motion_blur_vs20_Dynamic_Index +{ +public: + motion_blur_vs20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_motion_blur_vs20 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/particlesphere_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/particlesphere_ps20.inc new file mode 100644 index 0000000..afa2f90 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/particlesphere_ps20.inc @@ -0,0 +1,87 @@ +#include "shaderlib/cshader.h" +class particlesphere_ps20_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + particlesphere_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_particlesphere_ps20 0 +class particlesphere_ps20_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + particlesphere_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_particlesphere_ps20 psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/particlesphere_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/particlesphere_ps20b.inc new file mode 100644 index 0000000..ce9ec24 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/particlesphere_ps20b.inc @@ -0,0 +1,112 @@ +#include "shaderlib/cshader.h" +class particlesphere_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +private: + int m_nDEPTHBLEND; +#ifdef _DEBUG + bool m_bDEPTHBLEND; +#endif +public: + void SetDEPTHBLEND( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDEPTHBLEND = i; +#ifdef _DEBUG + m_bDEPTHBLEND = true; +#endif + } + void SetDEPTHBLEND( bool i ) + { + m_nDEPTHBLEND = i ? 1 : 0; +#ifdef _DEBUG + m_bDEPTHBLEND = true; +#endif + } +public: + particlesphere_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; +#ifdef _DEBUG + m_bDEPTHBLEND = false; +#endif // _DEBUG + m_nDEPTHBLEND = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB && m_bDEPTHBLEND; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nCONVERT_TO_SRGB ) + ( 2 * m_nDEPTHBLEND ) + 0; + } +}; +#define shaderStaticTest_particlesphere_ps20b psh_forgot_to_set_static_DEPTHBLEND + 0 +class particlesphere_ps20b_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + particlesphere_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_particlesphere_ps20b psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/particlesphere_vs20.inc b/materialsystem/stdshaders/fxctmp9_360/particlesphere_vs20.inc new file mode 100644 index 0000000..6b7b273 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/particlesphere_vs20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class particlesphere_vs20_Static_Index +{ +public: + particlesphere_vs20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_particlesphere_vs20 0 +class particlesphere_vs20_Dynamic_Index +{ +private: + int m_nFOGTYPE; +#ifdef _DEBUG + bool m_bFOGTYPE; +#endif +public: + void SetFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFOGTYPE = i; +#ifdef _DEBUG + m_bFOGTYPE = true; +#endif + } + void SetFOGTYPE( bool i ) + { + m_nFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bFOGTYPE = true; +#endif + } +public: + particlesphere_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bFOGTYPE = false; +#endif // _DEBUG + m_nFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_particlesphere_vs20 vsh_forgot_to_set_dynamic_FOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/portal_ps11.inc b/materialsystem/stdshaders/fxctmp9_360/portal_ps11.inc new file mode 100644 index 0000000..cee5360 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/portal_ps11.inc @@ -0,0 +1,162 @@ +#include "shaderlib/cshader.h" +class portal_ps11_Static_Index +{ +private: + int m_nMAXTEXTURESTAGES; +#ifdef _DEBUG + bool m_bMAXTEXTURESTAGES; +#endif +public: + void SetMAXTEXTURESTAGES( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nMAXTEXTURESTAGES = i; +#ifdef _DEBUG + m_bMAXTEXTURESTAGES = true; +#endif + } + void SetMAXTEXTURESTAGES( bool i ) + { + m_nMAXTEXTURESTAGES = i ? 1 : 0; +#ifdef _DEBUG + m_bMAXTEXTURESTAGES = true; +#endif + } +private: + int m_nHASALPHAMASK; +#ifdef _DEBUG + bool m_bHASALPHAMASK; +#endif +public: + void SetHASALPHAMASK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHASALPHAMASK = i; +#ifdef _DEBUG + m_bHASALPHAMASK = true; +#endif + } + void SetHASALPHAMASK( bool i ) + { + m_nHASALPHAMASK = i ? 1 : 0; +#ifdef _DEBUG + m_bHASALPHAMASK = true; +#endif + } +private: + int m_nHASSTATICTEXTURE; +#ifdef _DEBUG + bool m_bHASSTATICTEXTURE; +#endif +public: + void SetHASSTATICTEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHASSTATICTEXTURE = i; +#ifdef _DEBUG + m_bHASSTATICTEXTURE = true; +#endif + } + void SetHASSTATICTEXTURE( bool i ) + { + m_nHASSTATICTEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bHASSTATICTEXTURE = true; +#endif + } +public: + portal_ps11_Static_Index( ) + { +#ifdef _DEBUG + m_bMAXTEXTURESTAGES = false; +#endif // _DEBUG + m_nMAXTEXTURESTAGES = 0; +#ifdef _DEBUG + m_bHASALPHAMASK = false; +#endif // _DEBUG + m_nHASALPHAMASK = 0; +#ifdef _DEBUG + m_bHASSTATICTEXTURE = false; +#endif // _DEBUG + m_nHASSTATICTEXTURE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bMAXTEXTURESTAGES && m_bHASALPHAMASK && m_bHASSTATICTEXTURE; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 4 * m_nMAXTEXTURESTAGES ) + ( 12 * m_nHASALPHAMASK ) + ( 24 * m_nHASSTATICTEXTURE ) + 0; + } +}; +#define shaderStaticTest_portal_ps11 psh_forgot_to_set_static_MAXTEXTURESTAGES + psh_forgot_to_set_static_HASALPHAMASK + psh_forgot_to_set_static_HASSTATICTEXTURE + 0 +class portal_ps11_Dynamic_Index +{ +private: + int m_nADDSTATIC; +#ifdef _DEBUG + bool m_bADDSTATIC; +#endif +public: + void SetADDSTATIC( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nADDSTATIC = i; +#ifdef _DEBUG + m_bADDSTATIC = true; +#endif + } + void SetADDSTATIC( bool i ) + { + m_nADDSTATIC = i ? 1 : 0; +#ifdef _DEBUG + m_bADDSTATIC = true; +#endif + } +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + portal_ps11_Dynamic_Index() + { +#ifdef _DEBUG + m_bADDSTATIC = false; +#endif // _DEBUG + m_nADDSTATIC = 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bADDSTATIC && m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nADDSTATIC ) + ( 2 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_portal_ps11 psh_forgot_to_set_dynamic_ADDSTATIC + psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/portal_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/portal_ps20.inc new file mode 100644 index 0000000..f0a5cfb --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/portal_ps20.inc @@ -0,0 +1,187 @@ +#include "shaderlib/cshader.h" +class portal_ps20_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +private: + int m_nHASALPHAMASK; +#ifdef _DEBUG + bool m_bHASALPHAMASK; +#endif +public: + void SetHASALPHAMASK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHASALPHAMASK = i; +#ifdef _DEBUG + m_bHASALPHAMASK = true; +#endif + } + void SetHASALPHAMASK( bool i ) + { + m_nHASALPHAMASK = i ? 1 : 0; +#ifdef _DEBUG + m_bHASALPHAMASK = true; +#endif + } +private: + int m_nHASSTATICTEXTURE; +#ifdef _DEBUG + bool m_bHASSTATICTEXTURE; +#endif +public: + void SetHASSTATICTEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHASSTATICTEXTURE = i; +#ifdef _DEBUG + m_bHASSTATICTEXTURE = true; +#endif + } + void SetHASSTATICTEXTURE( bool i ) + { + m_nHASSTATICTEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bHASSTATICTEXTURE = true; +#endif + } +public: + portal_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; +#ifdef _DEBUG + m_bHASALPHAMASK = false; +#endif // _DEBUG + m_nHASALPHAMASK = 0; +#ifdef _DEBUG + m_bHASSTATICTEXTURE = false; +#endif // _DEBUG + m_nHASSTATICTEXTURE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB && m_bHASALPHAMASK && m_bHASSTATICTEXTURE; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 8 * m_nCONVERT_TO_SRGB ) + ( 8 * m_nHASALPHAMASK ) + ( 16 * m_nHASSTATICTEXTURE ) + 0; + } +}; +#define shaderStaticTest_portal_ps20 psh_forgot_to_set_static_HASALPHAMASK + psh_forgot_to_set_static_HASSTATICTEXTURE + 0 +class portal_ps20_Dynamic_Index +{ +private: + int m_nADDSTATIC; +#ifdef _DEBUG + bool m_bADDSTATIC; +#endif +public: + void SetADDSTATIC( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nADDSTATIC = i; +#ifdef _DEBUG + m_bADDSTATIC = true; +#endif + } + void SetADDSTATIC( bool i ) + { + m_nADDSTATIC = i ? 1 : 0; +#ifdef _DEBUG + m_bADDSTATIC = true; +#endif + } +private: + int m_nHDRENABLED; +#ifdef _DEBUG + bool m_bHDRENABLED; +#endif +public: + void SetHDRENABLED( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHDRENABLED = i; +#ifdef _DEBUG + m_bHDRENABLED = true; +#endif + } + void SetHDRENABLED( bool i ) + { + m_nHDRENABLED = i ? 1 : 0; +#ifdef _DEBUG + m_bHDRENABLED = true; +#endif + } +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + portal_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bADDSTATIC = false; +#endif // _DEBUG + m_nADDSTATIC = 0; +#ifdef _DEBUG + m_bHDRENABLED = false; +#endif // _DEBUG + m_nHDRENABLED = 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bADDSTATIC && m_bHDRENABLED && m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nADDSTATIC ) + ( 2 * m_nHDRENABLED ) + ( 4 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_portal_ps20 psh_forgot_to_set_dynamic_ADDSTATIC + psh_forgot_to_set_dynamic_HDRENABLED + psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/portal_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/portal_ps20b.inc new file mode 100644 index 0000000..fb97732 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/portal_ps20b.inc @@ -0,0 +1,187 @@ +#include "shaderlib/cshader.h" +class portal_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +private: + int m_nHASALPHAMASK; +#ifdef _DEBUG + bool m_bHASALPHAMASK; +#endif +public: + void SetHASALPHAMASK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHASALPHAMASK = i; +#ifdef _DEBUG + m_bHASALPHAMASK = true; +#endif + } + void SetHASALPHAMASK( bool i ) + { + m_nHASALPHAMASK = i ? 1 : 0; +#ifdef _DEBUG + m_bHASALPHAMASK = true; +#endif + } +private: + int m_nHASSTATICTEXTURE; +#ifdef _DEBUG + bool m_bHASSTATICTEXTURE; +#endif +public: + void SetHASSTATICTEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHASSTATICTEXTURE = i; +#ifdef _DEBUG + m_bHASSTATICTEXTURE = true; +#endif + } + void SetHASSTATICTEXTURE( bool i ) + { + m_nHASSTATICTEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bHASSTATICTEXTURE = true; +#endif + } +public: + portal_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; +#ifdef _DEBUG + m_bHASALPHAMASK = false; +#endif // _DEBUG + m_nHASALPHAMASK = 0; +#ifdef _DEBUG + m_bHASSTATICTEXTURE = false; +#endif // _DEBUG + m_nHASSTATICTEXTURE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB && m_bHASALPHAMASK && m_bHASSTATICTEXTURE; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 8 * m_nCONVERT_TO_SRGB ) + ( 8 * m_nHASALPHAMASK ) + ( 16 * m_nHASSTATICTEXTURE ) + 0; + } +}; +#define shaderStaticTest_portal_ps20b psh_forgot_to_set_static_HASALPHAMASK + psh_forgot_to_set_static_HASSTATICTEXTURE + 0 +class portal_ps20b_Dynamic_Index +{ +private: + int m_nADDSTATIC; +#ifdef _DEBUG + bool m_bADDSTATIC; +#endif +public: + void SetADDSTATIC( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nADDSTATIC = i; +#ifdef _DEBUG + m_bADDSTATIC = true; +#endif + } + void SetADDSTATIC( bool i ) + { + m_nADDSTATIC = i ? 1 : 0; +#ifdef _DEBUG + m_bADDSTATIC = true; +#endif + } +private: + int m_nHDRENABLED; +#ifdef _DEBUG + bool m_bHDRENABLED; +#endif +public: + void SetHDRENABLED( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHDRENABLED = i; +#ifdef _DEBUG + m_bHDRENABLED = true; +#endif + } + void SetHDRENABLED( bool i ) + { + m_nHDRENABLED = i ? 1 : 0; +#ifdef _DEBUG + m_bHDRENABLED = true; +#endif + } +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + portal_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bADDSTATIC = false; +#endif // _DEBUG + m_nADDSTATIC = 0; +#ifdef _DEBUG + m_bHDRENABLED = false; +#endif // _DEBUG + m_nHDRENABLED = 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bADDSTATIC && m_bHDRENABLED && m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nADDSTATIC ) + ( 2 * m_nHDRENABLED ) + ( 4 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_portal_ps20b psh_forgot_to_set_dynamic_ADDSTATIC + psh_forgot_to_set_dynamic_HDRENABLED + psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/portal_refract_ps11.inc b/materialsystem/stdshaders/fxctmp9_360/portal_refract_ps11.inc new file mode 100644 index 0000000..b07bc38 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/portal_refract_ps11.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class portal_refract_ps11_Static_Index +{ +private: + int m_nSTAGE; +#ifdef _DEBUG + bool m_bSTAGE; +#endif +public: + void SetSTAGE( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nSTAGE = i; +#ifdef _DEBUG + m_bSTAGE = true; +#endif + } + void SetSTAGE( bool i ) + { + m_nSTAGE = i ? 1 : 0; +#ifdef _DEBUG + m_bSTAGE = true; +#endif + } +public: + portal_refract_ps11_Static_Index( ) + { +#ifdef _DEBUG + m_bSTAGE = false; +#endif // _DEBUG + m_nSTAGE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bSTAGE; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nSTAGE ) + 0; + } +}; +#define shaderStaticTest_portal_refract_ps11 psh_forgot_to_set_static_STAGE + 0 +class portal_refract_ps11_Dynamic_Index +{ +public: + portal_refract_ps11_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_portal_refract_ps11 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/portal_refract_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/portal_refract_ps20.inc new file mode 100644 index 0000000..b686c0e --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/portal_refract_ps20.inc @@ -0,0 +1,85 @@ +#include "shaderlib/cshader.h" +class portal_refract_ps20_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +private: + int m_nSTAGE; +#ifdef _DEBUG + bool m_bSTAGE; +#endif +public: + void SetSTAGE( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nSTAGE = i; +#ifdef _DEBUG + m_bSTAGE = true; +#endif + } + void SetSTAGE( bool i ) + { + m_nSTAGE = i ? 1 : 0; +#ifdef _DEBUG + m_bSTAGE = true; +#endif + } +public: + portal_refract_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; +#ifdef _DEBUG + m_bSTAGE = false; +#endif // _DEBUG + m_nSTAGE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB && m_bSTAGE; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + ( 1 * m_nSTAGE ) + 0; + } +}; +#define shaderStaticTest_portal_refract_ps20 psh_forgot_to_set_static_STAGE + 0 +class portal_refract_ps20_Dynamic_Index +{ +public: + portal_refract_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_portal_refract_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/portal_refract_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/portal_refract_ps20b.inc new file mode 100644 index 0000000..75efe8a --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/portal_refract_ps20b.inc @@ -0,0 +1,137 @@ +#include "shaderlib/cshader.h" +class portal_refract_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +private: + int m_nSTAGE; +#ifdef _DEBUG + bool m_bSTAGE; +#endif +public: + void SetSTAGE( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nSTAGE = i; +#ifdef _DEBUG + m_bSTAGE = true; +#endif + } + void SetSTAGE( bool i ) + { + m_nSTAGE = i ? 1 : 0; +#ifdef _DEBUG + m_bSTAGE = true; +#endif + } +private: + int m_nSHADER_SRGB_READ; +#ifdef _DEBUG + bool m_bSHADER_SRGB_READ; +#endif +public: + void SetSHADER_SRGB_READ( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSHADER_SRGB_READ = i; +#ifdef _DEBUG + m_bSHADER_SRGB_READ = true; +#endif + } + void SetSHADER_SRGB_READ( bool i ) + { + m_nSHADER_SRGB_READ = i ? 1 : 0; +#ifdef _DEBUG + m_bSHADER_SRGB_READ = true; +#endif + } +public: + portal_refract_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; +#ifdef _DEBUG + m_bSTAGE = false; +#endif // _DEBUG + m_nSTAGE = 0; +#ifdef _DEBUG + m_bSHADER_SRGB_READ = false; +#endif // _DEBUG + m_nSHADER_SRGB_READ = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB && m_bSTAGE && m_bSHADER_SRGB_READ; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nCONVERT_TO_SRGB ) + ( 2 * m_nSTAGE ) + ( 6 * m_nSHADER_SRGB_READ ) + 0; + } +}; +#define shaderStaticTest_portal_refract_ps20b psh_forgot_to_set_static_STAGE + psh_forgot_to_set_static_SHADER_SRGB_READ + 0 +class portal_refract_ps20b_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + portal_refract_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_portal_refract_ps20b psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/portal_refract_vs11.inc b/materialsystem/stdshaders/fxctmp9_360/portal_refract_vs11.inc new file mode 100644 index 0000000..534d6c9 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/portal_refract_vs11.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class portal_refract_vs11_Static_Index +{ +private: + int m_nSTAGE; +#ifdef _DEBUG + bool m_bSTAGE; +#endif +public: + void SetSTAGE( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nSTAGE = i; +#ifdef _DEBUG + m_bSTAGE = true; +#endif + } + void SetSTAGE( bool i ) + { + m_nSTAGE = i ? 1 : 0; +#ifdef _DEBUG + m_bSTAGE = true; +#endif + } +public: + portal_refract_vs11_Static_Index( ) + { +#ifdef _DEBUG + m_bSTAGE = false; +#endif // _DEBUG + m_nSTAGE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bSTAGE; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nSTAGE ) + 0; + } +}; +#define shaderStaticTest_portal_refract_vs11 vsh_forgot_to_set_static_STAGE + 0 +class portal_refract_vs11_Dynamic_Index +{ +public: + portal_refract_vs11_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_portal_refract_vs11 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/portal_refract_vs20.inc b/materialsystem/stdshaders/fxctmp9_360/portal_refract_vs20.inc new file mode 100644 index 0000000..534ca44 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/portal_refract_vs20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class portal_refract_vs20_Static_Index +{ +private: + int m_nSTAGE; +#ifdef _DEBUG + bool m_bSTAGE; +#endif +public: + void SetSTAGE( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nSTAGE = i; +#ifdef _DEBUG + m_bSTAGE = true; +#endif + } + void SetSTAGE( bool i ) + { + m_nSTAGE = i ? 1 : 0; +#ifdef _DEBUG + m_bSTAGE = true; +#endif + } +public: + portal_refract_vs20_Static_Index( ) + { +#ifdef _DEBUG + m_bSTAGE = false; +#endif // _DEBUG + m_nSTAGE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bSTAGE; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nSTAGE ) + 0; + } +}; +#define shaderStaticTest_portal_refract_vs20 vsh_forgot_to_set_static_STAGE + 0 +class portal_refract_vs20_Dynamic_Index +{ +public: + portal_refract_vs20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_portal_refract_vs20 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/portal_vs11.inc b/materialsystem/stdshaders/fxctmp9_360/portal_vs11.inc new file mode 100644 index 0000000..4c687db --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/portal_vs11.inc @@ -0,0 +1,187 @@ +#include "shaderlib/cshader.h" +class portal_vs11_Static_Index +{ +private: + int m_nMAXTEXTURESTAGES; +#ifdef _DEBUG + bool m_bMAXTEXTURESTAGES; +#endif +public: + void SetMAXTEXTURESTAGES( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nMAXTEXTURESTAGES = i; +#ifdef _DEBUG + m_bMAXTEXTURESTAGES = true; +#endif + } + void SetMAXTEXTURESTAGES( bool i ) + { + m_nMAXTEXTURESTAGES = i ? 1 : 0; +#ifdef _DEBUG + m_bMAXTEXTURESTAGES = true; +#endif + } +private: + int m_nHASALPHAMASK; +#ifdef _DEBUG + bool m_bHASALPHAMASK; +#endif +public: + void SetHASALPHAMASK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHASALPHAMASK = i; +#ifdef _DEBUG + m_bHASALPHAMASK = true; +#endif + } + void SetHASALPHAMASK( bool i ) + { + m_nHASALPHAMASK = i ? 1 : 0; +#ifdef _DEBUG + m_bHASALPHAMASK = true; +#endif + } +private: + int m_nHASSTATICTEXTURE; +#ifdef _DEBUG + bool m_bHASSTATICTEXTURE; +#endif +public: + void SetHASSTATICTEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHASSTATICTEXTURE = i; +#ifdef _DEBUG + m_bHASSTATICTEXTURE = true; +#endif + } + void SetHASSTATICTEXTURE( bool i ) + { + m_nHASSTATICTEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bHASSTATICTEXTURE = true; +#endif + } +private: + int m_nUSEALTERNATEVIEW; +#ifdef _DEBUG + bool m_bUSEALTERNATEVIEW; +#endif +public: + void SetUSEALTERNATEVIEW( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nUSEALTERNATEVIEW = i; +#ifdef _DEBUG + m_bUSEALTERNATEVIEW = true; +#endif + } + void SetUSEALTERNATEVIEW( bool i ) + { + m_nUSEALTERNATEVIEW = i ? 1 : 0; +#ifdef _DEBUG + m_bUSEALTERNATEVIEW = true; +#endif + } +public: + portal_vs11_Static_Index( ) + { +#ifdef _DEBUG + m_bMAXTEXTURESTAGES = false; +#endif // _DEBUG + m_nMAXTEXTURESTAGES = 0; +#ifdef _DEBUG + m_bHASALPHAMASK = false; +#endif // _DEBUG + m_nHASALPHAMASK = 0; +#ifdef _DEBUG + m_bHASSTATICTEXTURE = false; +#endif // _DEBUG + m_nHASSTATICTEXTURE = 0; +#ifdef _DEBUG + m_bUSEALTERNATEVIEW = false; +#endif // _DEBUG + m_nUSEALTERNATEVIEW = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bMAXTEXTURESTAGES && m_bHASALPHAMASK && m_bHASSTATICTEXTURE && m_bUSEALTERNATEVIEW; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 4 * m_nMAXTEXTURESTAGES ) + ( 12 * m_nHASALPHAMASK ) + ( 24 * m_nHASSTATICTEXTURE ) + ( 48 * m_nUSEALTERNATEVIEW ) + 0; + } +}; +#define shaderStaticTest_portal_vs11 vsh_forgot_to_set_static_MAXTEXTURESTAGES + vsh_forgot_to_set_static_HASALPHAMASK + vsh_forgot_to_set_static_HASSTATICTEXTURE + vsh_forgot_to_set_static_USEALTERNATEVIEW + 0 +class portal_vs11_Dynamic_Index +{ +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +private: + int m_nADDSTATIC; +#ifdef _DEBUG + bool m_bADDSTATIC; +#endif +public: + void SetADDSTATIC( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nADDSTATIC = i; +#ifdef _DEBUG + m_bADDSTATIC = true; +#endif + } + void SetADDSTATIC( bool i ) + { + m_nADDSTATIC = i ? 1 : 0; +#ifdef _DEBUG + m_bADDSTATIC = true; +#endif + } +public: + portal_vs11_Dynamic_Index() + { +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; +#ifdef _DEBUG + m_bADDSTATIC = false; +#endif // _DEBUG + m_nADDSTATIC = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bSKINNING && m_bADDSTATIC; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nSKINNING ) + ( 2 * m_nADDSTATIC ) + 0; + } +}; +#define shaderDynamicTest_portal_vs11 vsh_forgot_to_set_dynamic_SKINNING + vsh_forgot_to_set_dynamic_ADDSTATIC + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/portal_vs20.inc b/materialsystem/stdshaders/fxctmp9_360/portal_vs20.inc new file mode 100644 index 0000000..e0eb237 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/portal_vs20.inc @@ -0,0 +1,162 @@ +#include "shaderlib/cshader.h" +class portal_vs20_Static_Index +{ +private: + int m_nHASALPHAMASK; +#ifdef _DEBUG + bool m_bHASALPHAMASK; +#endif +public: + void SetHASALPHAMASK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHASALPHAMASK = i; +#ifdef _DEBUG + m_bHASALPHAMASK = true; +#endif + } + void SetHASALPHAMASK( bool i ) + { + m_nHASALPHAMASK = i ? 1 : 0; +#ifdef _DEBUG + m_bHASALPHAMASK = true; +#endif + } +private: + int m_nHASSTATICTEXTURE; +#ifdef _DEBUG + bool m_bHASSTATICTEXTURE; +#endif +public: + void SetHASSTATICTEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHASSTATICTEXTURE = i; +#ifdef _DEBUG + m_bHASSTATICTEXTURE = true; +#endif + } + void SetHASSTATICTEXTURE( bool i ) + { + m_nHASSTATICTEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bHASSTATICTEXTURE = true; +#endif + } +private: + int m_nUSEALTERNATEVIEW; +#ifdef _DEBUG + bool m_bUSEALTERNATEVIEW; +#endif +public: + void SetUSEALTERNATEVIEW( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nUSEALTERNATEVIEW = i; +#ifdef _DEBUG + m_bUSEALTERNATEVIEW = true; +#endif + } + void SetUSEALTERNATEVIEW( bool i ) + { + m_nUSEALTERNATEVIEW = i ? 1 : 0; +#ifdef _DEBUG + m_bUSEALTERNATEVIEW = true; +#endif + } +public: + portal_vs20_Static_Index( ) + { +#ifdef _DEBUG + m_bHASALPHAMASK = false; +#endif // _DEBUG + m_nHASALPHAMASK = 0; +#ifdef _DEBUG + m_bHASSTATICTEXTURE = false; +#endif // _DEBUG + m_nHASSTATICTEXTURE = 0; +#ifdef _DEBUG + m_bUSEALTERNATEVIEW = false; +#endif // _DEBUG + m_nUSEALTERNATEVIEW = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bHASALPHAMASK && m_bHASSTATICTEXTURE && m_bUSEALTERNATEVIEW; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 4 * m_nHASALPHAMASK ) + ( 8 * m_nHASSTATICTEXTURE ) + ( 16 * m_nUSEALTERNATEVIEW ) + 0; + } +}; +#define shaderStaticTest_portal_vs20 vsh_forgot_to_set_static_HASALPHAMASK + vsh_forgot_to_set_static_HASSTATICTEXTURE + vsh_forgot_to_set_static_USEALTERNATEVIEW + 0 +class portal_vs20_Dynamic_Index +{ +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +private: + int m_nADDSTATIC; +#ifdef _DEBUG + bool m_bADDSTATIC; +#endif +public: + void SetADDSTATIC( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nADDSTATIC = i; +#ifdef _DEBUG + m_bADDSTATIC = true; +#endif + } + void SetADDSTATIC( bool i ) + { + m_nADDSTATIC = i ? 1 : 0; +#ifdef _DEBUG + m_bADDSTATIC = true; +#endif + } +public: + portal_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; +#ifdef _DEBUG + m_bADDSTATIC = false; +#endif // _DEBUG + m_nADDSTATIC = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bSKINNING && m_bADDSTATIC; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nSKINNING ) + ( 2 * m_nADDSTATIC ) + 0; + } +}; +#define shaderDynamicTest_portal_vs20 vsh_forgot_to_set_dynamic_SKINNING + vsh_forgot_to_set_dynamic_ADDSTATIC + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/portalstaticoverlay_ps11.inc b/materialsystem/stdshaders/fxctmp9_360/portalstaticoverlay_ps11.inc new file mode 100644 index 0000000..7b7eb8f --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/portalstaticoverlay_ps11.inc @@ -0,0 +1,137 @@ +#include "shaderlib/cshader.h" +class portalstaticoverlay_ps11_Static_Index +{ +private: + int m_nHASALPHAMASK; +#ifdef _DEBUG + bool m_bHASALPHAMASK; +#endif +public: + void SetHASALPHAMASK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHASALPHAMASK = i; +#ifdef _DEBUG + m_bHASALPHAMASK = true; +#endif + } + void SetHASALPHAMASK( bool i ) + { + m_nHASALPHAMASK = i ? 1 : 0; +#ifdef _DEBUG + m_bHASALPHAMASK = true; +#endif + } +private: + int m_nHASSTATICTEXTURE; +#ifdef _DEBUG + bool m_bHASSTATICTEXTURE; +#endif +public: + void SetHASSTATICTEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHASSTATICTEXTURE = i; +#ifdef _DEBUG + m_bHASSTATICTEXTURE = true; +#endif + } + void SetHASSTATICTEXTURE( bool i ) + { + m_nHASSTATICTEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bHASSTATICTEXTURE = true; +#endif + } +public: + portalstaticoverlay_ps11_Static_Index( ) + { +#ifdef _DEBUG + m_bHASALPHAMASK = false; +#endif // _DEBUG + m_nHASALPHAMASK = 0; +#ifdef _DEBUG + m_bHASSTATICTEXTURE = false; +#endif // _DEBUG + m_nHASSTATICTEXTURE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bHASALPHAMASK && m_bHASSTATICTEXTURE; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 4 * m_nHASALPHAMASK ) + ( 8 * m_nHASSTATICTEXTURE ) + 0; + } +}; +#define shaderStaticTest_portalstaticoverlay_ps11 psh_forgot_to_set_static_HASALPHAMASK + psh_forgot_to_set_static_HASSTATICTEXTURE + 0 +class portalstaticoverlay_ps11_Dynamic_Index +{ +private: + int m_nHDRENABLED; +#ifdef _DEBUG + bool m_bHDRENABLED; +#endif +public: + void SetHDRENABLED( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHDRENABLED = i; +#ifdef _DEBUG + m_bHDRENABLED = true; +#endif + } + void SetHDRENABLED( bool i ) + { + m_nHDRENABLED = i ? 1 : 0; +#ifdef _DEBUG + m_bHDRENABLED = true; +#endif + } +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + portalstaticoverlay_ps11_Dynamic_Index() + { +#ifdef _DEBUG + m_bHDRENABLED = false; +#endif // _DEBUG + m_nHDRENABLED = 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bHDRENABLED && m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nHDRENABLED ) + ( 2 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_portalstaticoverlay_ps11 psh_forgot_to_set_dynamic_HDRENABLED + psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/portalstaticoverlay_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/portalstaticoverlay_ps20.inc new file mode 100644 index 0000000..3d08fd0 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/portalstaticoverlay_ps20.inc @@ -0,0 +1,162 @@ +#include "shaderlib/cshader.h" +class portalstaticoverlay_ps20_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +private: + int m_nHASALPHAMASK; +#ifdef _DEBUG + bool m_bHASALPHAMASK; +#endif +public: + void SetHASALPHAMASK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHASALPHAMASK = i; +#ifdef _DEBUG + m_bHASALPHAMASK = true; +#endif + } + void SetHASALPHAMASK( bool i ) + { + m_nHASALPHAMASK = i ? 1 : 0; +#ifdef _DEBUG + m_bHASALPHAMASK = true; +#endif + } +private: + int m_nHASSTATICTEXTURE; +#ifdef _DEBUG + bool m_bHASSTATICTEXTURE; +#endif +public: + void SetHASSTATICTEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHASSTATICTEXTURE = i; +#ifdef _DEBUG + m_bHASSTATICTEXTURE = true; +#endif + } + void SetHASSTATICTEXTURE( bool i ) + { + m_nHASSTATICTEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bHASSTATICTEXTURE = true; +#endif + } +public: + portalstaticoverlay_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; +#ifdef _DEBUG + m_bHASALPHAMASK = false; +#endif // _DEBUG + m_nHASALPHAMASK = 0; +#ifdef _DEBUG + m_bHASSTATICTEXTURE = false; +#endif // _DEBUG + m_nHASSTATICTEXTURE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB && m_bHASALPHAMASK && m_bHASSTATICTEXTURE; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 4 * m_nCONVERT_TO_SRGB ) + ( 4 * m_nHASALPHAMASK ) + ( 8 * m_nHASSTATICTEXTURE ) + 0; + } +}; +#define shaderStaticTest_portalstaticoverlay_ps20 psh_forgot_to_set_static_HASALPHAMASK + psh_forgot_to_set_static_HASSTATICTEXTURE + 0 +class portalstaticoverlay_ps20_Dynamic_Index +{ +private: + int m_nHDRENABLED; +#ifdef _DEBUG + bool m_bHDRENABLED; +#endif +public: + void SetHDRENABLED( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHDRENABLED = i; +#ifdef _DEBUG + m_bHDRENABLED = true; +#endif + } + void SetHDRENABLED( bool i ) + { + m_nHDRENABLED = i ? 1 : 0; +#ifdef _DEBUG + m_bHDRENABLED = true; +#endif + } +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + portalstaticoverlay_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bHDRENABLED = false; +#endif // _DEBUG + m_nHDRENABLED = 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bHDRENABLED && m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nHDRENABLED ) + ( 2 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_portalstaticoverlay_ps20 psh_forgot_to_set_dynamic_HDRENABLED + psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/portalstaticoverlay_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/portalstaticoverlay_ps20b.inc new file mode 100644 index 0000000..c45e7b3 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/portalstaticoverlay_ps20b.inc @@ -0,0 +1,162 @@ +#include "shaderlib/cshader.h" +class portalstaticoverlay_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +private: + int m_nHASALPHAMASK; +#ifdef _DEBUG + bool m_bHASALPHAMASK; +#endif +public: + void SetHASALPHAMASK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHASALPHAMASK = i; +#ifdef _DEBUG + m_bHASALPHAMASK = true; +#endif + } + void SetHASALPHAMASK( bool i ) + { + m_nHASALPHAMASK = i ? 1 : 0; +#ifdef _DEBUG + m_bHASALPHAMASK = true; +#endif + } +private: + int m_nHASSTATICTEXTURE; +#ifdef _DEBUG + bool m_bHASSTATICTEXTURE; +#endif +public: + void SetHASSTATICTEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHASSTATICTEXTURE = i; +#ifdef _DEBUG + m_bHASSTATICTEXTURE = true; +#endif + } + void SetHASSTATICTEXTURE( bool i ) + { + m_nHASSTATICTEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bHASSTATICTEXTURE = true; +#endif + } +public: + portalstaticoverlay_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; +#ifdef _DEBUG + m_bHASALPHAMASK = false; +#endif // _DEBUG + m_nHASALPHAMASK = 0; +#ifdef _DEBUG + m_bHASSTATICTEXTURE = false; +#endif // _DEBUG + m_nHASSTATICTEXTURE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB && m_bHASALPHAMASK && m_bHASSTATICTEXTURE; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 4 * m_nCONVERT_TO_SRGB ) + ( 4 * m_nHASALPHAMASK ) + ( 8 * m_nHASSTATICTEXTURE ) + 0; + } +}; +#define shaderStaticTest_portalstaticoverlay_ps20b psh_forgot_to_set_static_HASALPHAMASK + psh_forgot_to_set_static_HASSTATICTEXTURE + 0 +class portalstaticoverlay_ps20b_Dynamic_Index +{ +private: + int m_nHDRENABLED; +#ifdef _DEBUG + bool m_bHDRENABLED; +#endif +public: + void SetHDRENABLED( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHDRENABLED = i; +#ifdef _DEBUG + m_bHDRENABLED = true; +#endif + } + void SetHDRENABLED( bool i ) + { + m_nHDRENABLED = i ? 1 : 0; +#ifdef _DEBUG + m_bHDRENABLED = true; +#endif + } +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + portalstaticoverlay_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bHDRENABLED = false; +#endif // _DEBUG + m_nHDRENABLED = 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bHDRENABLED && m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nHDRENABLED ) + ( 2 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_portalstaticoverlay_ps20b psh_forgot_to_set_dynamic_HDRENABLED + psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/portalstaticoverlay_vs11.inc b/materialsystem/stdshaders/fxctmp9_360/portalstaticoverlay_vs11.inc new file mode 100644 index 0000000..012727a --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/portalstaticoverlay_vs11.inc @@ -0,0 +1,87 @@ +#include "shaderlib/cshader.h" +class portalstaticoverlay_vs11_Static_Index +{ +private: + int m_nMODEL; +#ifdef _DEBUG + bool m_bMODEL; +#endif +public: + void SetMODEL( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nMODEL = i; +#ifdef _DEBUG + m_bMODEL = true; +#endif + } + void SetMODEL( bool i ) + { + m_nMODEL = i ? 1 : 0; +#ifdef _DEBUG + m_bMODEL = true; +#endif + } +public: + portalstaticoverlay_vs11_Static_Index( ) + { +#ifdef _DEBUG + m_bMODEL = false; +#endif // _DEBUG + m_nMODEL = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bMODEL; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nMODEL ) + 0; + } +}; +#define shaderStaticTest_portalstaticoverlay_vs11 vsh_forgot_to_set_static_MODEL + 0 +class portalstaticoverlay_vs11_Dynamic_Index +{ +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +public: + portalstaticoverlay_vs11_Dynamic_Index() + { +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bSKINNING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nSKINNING ) + 0; + } +}; +#define shaderDynamicTest_portalstaticoverlay_vs11 vsh_forgot_to_set_dynamic_SKINNING + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/portalstaticoverlay_vs20.inc b/materialsystem/stdshaders/fxctmp9_360/portalstaticoverlay_vs20.inc new file mode 100644 index 0000000..91beed5 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/portalstaticoverlay_vs20.inc @@ -0,0 +1,87 @@ +#include "shaderlib/cshader.h" +class portalstaticoverlay_vs20_Static_Index +{ +private: + int m_nMODEL; +#ifdef _DEBUG + bool m_bMODEL; +#endif +public: + void SetMODEL( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nMODEL = i; +#ifdef _DEBUG + m_bMODEL = true; +#endif + } + void SetMODEL( bool i ) + { + m_nMODEL = i ? 1 : 0; +#ifdef _DEBUG + m_bMODEL = true; +#endif + } +public: + portalstaticoverlay_vs20_Static_Index( ) + { +#ifdef _DEBUG + m_bMODEL = false; +#endif // _DEBUG + m_nMODEL = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bMODEL; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nMODEL ) + 0; + } +}; +#define shaderStaticTest_portalstaticoverlay_vs20 vsh_forgot_to_set_static_MODEL + 0 +class portalstaticoverlay_vs20_Dynamic_Index +{ +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +public: + portalstaticoverlay_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bSKINNING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nSKINNING ) + 0; + } +}; +#define shaderDynamicTest_portalstaticoverlay_vs20 vsh_forgot_to_set_dynamic_SKINNING + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/refract_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/refract_ps20b.inc new file mode 100644 index 0000000..9542a0a --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/refract_ps20b.inc @@ -0,0 +1,337 @@ +#include "shaderlib/cshader.h" +class refract_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +private: + int m_nBLUR; +#ifdef _DEBUG + bool m_bBLUR; +#endif +public: + void SetBLUR( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBLUR = i; +#ifdef _DEBUG + m_bBLUR = true; +#endif + } + void SetBLUR( bool i ) + { + m_nBLUR = i ? 1 : 0; +#ifdef _DEBUG + m_bBLUR = true; +#endif + } +private: + int m_nFADEOUTONSILHOUETTE; +#ifdef _DEBUG + bool m_bFADEOUTONSILHOUETTE; +#endif +public: + void SetFADEOUTONSILHOUETTE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFADEOUTONSILHOUETTE = i; +#ifdef _DEBUG + m_bFADEOUTONSILHOUETTE = true; +#endif + } + void SetFADEOUTONSILHOUETTE( bool i ) + { + m_nFADEOUTONSILHOUETTE = i ? 1 : 0; +#ifdef _DEBUG + m_bFADEOUTONSILHOUETTE = true; +#endif + } +private: + int m_nCUBEMAP; +#ifdef _DEBUG + bool m_bCUBEMAP; +#endif +public: + void SetCUBEMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCUBEMAP = i; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } + void SetCUBEMAP( bool i ) + { + m_nCUBEMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } +private: + int m_nREFRACTTINTTEXTURE; +#ifdef _DEBUG + bool m_bREFRACTTINTTEXTURE; +#endif +public: + void SetREFRACTTINTTEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nREFRACTTINTTEXTURE = i; +#ifdef _DEBUG + m_bREFRACTTINTTEXTURE = true; +#endif + } + void SetREFRACTTINTTEXTURE( bool i ) + { + m_nREFRACTTINTTEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bREFRACTTINTTEXTURE = true; +#endif + } +private: + int m_nMASKED; +#ifdef _DEBUG + bool m_bMASKED; +#endif +public: + void SetMASKED( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nMASKED = i; +#ifdef _DEBUG + m_bMASKED = true; +#endif + } + void SetMASKED( bool i ) + { + m_nMASKED = i ? 1 : 0; +#ifdef _DEBUG + m_bMASKED = true; +#endif + } +private: + int m_nCOLORMODULATE; +#ifdef _DEBUG + bool m_bCOLORMODULATE; +#endif +public: + void SetCOLORMODULATE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOLORMODULATE = i; +#ifdef _DEBUG + m_bCOLORMODULATE = true; +#endif + } + void SetCOLORMODULATE( bool i ) + { + m_nCOLORMODULATE = i ? 1 : 0; +#ifdef _DEBUG + m_bCOLORMODULATE = true; +#endif + } +private: + int m_nSECONDARY_NORMAL; +#ifdef _DEBUG + bool m_bSECONDARY_NORMAL; +#endif +public: + void SetSECONDARY_NORMAL( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSECONDARY_NORMAL = i; +#ifdef _DEBUG + m_bSECONDARY_NORMAL = true; +#endif + } + void SetSECONDARY_NORMAL( bool i ) + { + m_nSECONDARY_NORMAL = i ? 1 : 0; +#ifdef _DEBUG + m_bSECONDARY_NORMAL = true; +#endif + } +private: + int m_nNORMAL_DECODE_MODE; +#ifdef _DEBUG + bool m_bNORMAL_DECODE_MODE; +#endif +public: + void SetNORMAL_DECODE_MODE( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nNORMAL_DECODE_MODE = i; +#ifdef _DEBUG + m_bNORMAL_DECODE_MODE = true; +#endif + } + void SetNORMAL_DECODE_MODE( bool i ) + { + m_nNORMAL_DECODE_MODE = i ? 1 : 0; +#ifdef _DEBUG + m_bNORMAL_DECODE_MODE = true; +#endif + } +private: + int m_nSHADER_SRGB_READ; +#ifdef _DEBUG + bool m_bSHADER_SRGB_READ; +#endif +public: + void SetSHADER_SRGB_READ( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSHADER_SRGB_READ = i; +#ifdef _DEBUG + m_bSHADER_SRGB_READ = true; +#endif + } + void SetSHADER_SRGB_READ( bool i ) + { + m_nSHADER_SRGB_READ = i ? 1 : 0; +#ifdef _DEBUG + m_bSHADER_SRGB_READ = true; +#endif + } +public: + refract_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; +#ifdef _DEBUG + m_bBLUR = false; +#endif // _DEBUG + m_nBLUR = 0; +#ifdef _DEBUG + m_bFADEOUTONSILHOUETTE = false; +#endif // _DEBUG + m_nFADEOUTONSILHOUETTE = 0; +#ifdef _DEBUG + m_bCUBEMAP = false; +#endif // _DEBUG + m_nCUBEMAP = 0; +#ifdef _DEBUG + m_bREFRACTTINTTEXTURE = false; +#endif // _DEBUG + m_nREFRACTTINTTEXTURE = 0; +#ifdef _DEBUG + m_bMASKED = false; +#endif // _DEBUG + m_nMASKED = 0; +#ifdef _DEBUG + m_bCOLORMODULATE = false; +#endif // _DEBUG + m_nCOLORMODULATE = 0; +#ifdef _DEBUG + m_bSECONDARY_NORMAL = false; +#endif // _DEBUG + m_nSECONDARY_NORMAL = 0; +#ifdef _DEBUG + m_bNORMAL_DECODE_MODE = false; +#endif // _DEBUG + m_nNORMAL_DECODE_MODE = 0; +#ifdef _DEBUG + m_bSHADER_SRGB_READ = false; +#endif // _DEBUG + m_nSHADER_SRGB_READ = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB && m_bBLUR && m_bFADEOUTONSILHOUETTE && m_bCUBEMAP && m_bREFRACTTINTTEXTURE && m_bMASKED && m_bCOLORMODULATE && m_bSECONDARY_NORMAL && m_bNORMAL_DECODE_MODE && m_bSHADER_SRGB_READ; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nCONVERT_TO_SRGB ) + ( 2 * m_nBLUR ) + ( 4 * m_nFADEOUTONSILHOUETTE ) + ( 8 * m_nCUBEMAP ) + ( 16 * m_nREFRACTTINTTEXTURE ) + ( 32 * m_nMASKED ) + ( 64 * m_nCOLORMODULATE ) + ( 128 * m_nSECONDARY_NORMAL ) + ( 256 * m_nNORMAL_DECODE_MODE ) + ( 256 * m_nSHADER_SRGB_READ ) + 0; + } +}; +#define shaderStaticTest_refract_ps20b psh_forgot_to_set_static_BLUR + psh_forgot_to_set_static_FADEOUTONSILHOUETTE + psh_forgot_to_set_static_CUBEMAP + psh_forgot_to_set_static_REFRACTTINTTEXTURE + psh_forgot_to_set_static_MASKED + psh_forgot_to_set_static_COLORMODULATE + psh_forgot_to_set_static_SECONDARY_NORMAL + psh_forgot_to_set_static_NORMAL_DECODE_MODE + psh_forgot_to_set_static_SHADER_SRGB_READ + 0 +class refract_ps20b_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +private: + int m_nWRITE_DEPTH_TO_DESTALPHA; +#ifdef _DEBUG + bool m_bWRITE_DEPTH_TO_DESTALPHA; +#endif +public: + void SetWRITE_DEPTH_TO_DESTALPHA( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nWRITE_DEPTH_TO_DESTALPHA = i; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = true; +#endif + } + void SetWRITE_DEPTH_TO_DESTALPHA( bool i ) + { + m_nWRITE_DEPTH_TO_DESTALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = true; +#endif + } +public: + refract_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = false; +#endif // _DEBUG + m_nWRITE_DEPTH_TO_DESTALPHA = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE && m_bWRITE_DEPTH_TO_DESTALPHA; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + ( 2 * m_nWRITE_DEPTH_TO_DESTALPHA ) + 0; + } +}; +#define shaderDynamicTest_refract_ps20b psh_forgot_to_set_dynamic_PIXELFOGTYPE + psh_forgot_to_set_dynamic_WRITE_DEPTH_TO_DESTALPHA + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/rendertargetblit_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/rendertargetblit_ps20.inc new file mode 100644 index 0000000..e2577eb --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/rendertargetblit_ps20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class rendertargetblit_ps20_Static_Index +{ +public: + rendertargetblit_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_rendertargetblit_ps20 0 +class rendertargetblit_ps20_Dynamic_Index +{ +public: + rendertargetblit_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_rendertargetblit_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/rendertargetblit_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/rendertargetblit_ps20b.inc new file mode 100644 index 0000000..698b94f --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/rendertargetblit_ps20b.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class rendertargetblit_ps20b_Static_Index +{ +public: + rendertargetblit_ps20b_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_rendertargetblit_ps20b 0 +class rendertargetblit_ps20b_Dynamic_Index +{ +public: + rendertargetblit_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_rendertargetblit_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/rendertargetblit_vs20.inc b/materialsystem/stdshaders/fxctmp9_360/rendertargetblit_vs20.inc new file mode 100644 index 0000000..7b69014 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/rendertargetblit_vs20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class rendertargetblit_vs20_Static_Index +{ +public: + rendertargetblit_vs20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_rendertargetblit_vs20 0 +class rendertargetblit_vs20_Dynamic_Index +{ +public: + rendertargetblit_vs20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_rendertargetblit_vs20 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/sample4x4_blend_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/sample4x4_blend_ps20.inc new file mode 100644 index 0000000..2dc45b6 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/sample4x4_blend_ps20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class sample4x4_blend_ps20_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + sample4x4_blend_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_sample4x4_blend_ps20 0 +class sample4x4_blend_ps20_Dynamic_Index +{ +public: + sample4x4_blend_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_sample4x4_blend_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/sample4x4_blend_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/sample4x4_blend_ps20b.inc new file mode 100644 index 0000000..393fc0c --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/sample4x4_blend_ps20b.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class sample4x4_blend_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + sample4x4_blend_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_sample4x4_blend_ps20b 0 +class sample4x4_blend_ps20b_Dynamic_Index +{ +public: + sample4x4_blend_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_sample4x4_blend_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/sample4x4_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/sample4x4_ps20.inc new file mode 100644 index 0000000..e91fed0 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/sample4x4_ps20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class sample4x4_ps20_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + sample4x4_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_sample4x4_ps20 0 +class sample4x4_ps20_Dynamic_Index +{ +public: + sample4x4_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_sample4x4_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/sample4x4_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/sample4x4_ps20b.inc new file mode 100644 index 0000000..69df521 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/sample4x4_ps20b.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class sample4x4_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + sample4x4_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_sample4x4_ps20b 0 +class sample4x4_ps20b_Dynamic_Index +{ +public: + sample4x4_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_sample4x4_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/sample4x4delog_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/sample4x4delog_ps20.inc new file mode 100644 index 0000000..e78db8a --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/sample4x4delog_ps20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class sample4x4delog_ps20_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + sample4x4delog_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_sample4x4delog_ps20 0 +class sample4x4delog_ps20_Dynamic_Index +{ +public: + sample4x4delog_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_sample4x4delog_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/sample4x4delog_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/sample4x4delog_ps20b.inc new file mode 100644 index 0000000..7e580ba --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/sample4x4delog_ps20b.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class sample4x4delog_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + sample4x4delog_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_sample4x4delog_ps20b 0 +class sample4x4delog_ps20b_Dynamic_Index +{ +public: + sample4x4delog_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_sample4x4delog_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/sample4x4log_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/sample4x4log_ps20.inc new file mode 100644 index 0000000..4361fa3 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/sample4x4log_ps20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class sample4x4log_ps20_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + sample4x4log_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_sample4x4log_ps20 0 +class sample4x4log_ps20_Dynamic_Index +{ +public: + sample4x4log_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_sample4x4log_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/sample4x4log_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/sample4x4log_ps20b.inc new file mode 100644 index 0000000..f157410 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/sample4x4log_ps20b.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class sample4x4log_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + sample4x4log_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_sample4x4log_ps20b 0 +class sample4x4log_ps20b_Dynamic_Index +{ +public: + sample4x4log_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_sample4x4log_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/sample4x4maxmin_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/sample4x4maxmin_ps20.inc new file mode 100644 index 0000000..1b0c1f3 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/sample4x4maxmin_ps20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class sample4x4maxmin_ps20_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + sample4x4maxmin_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_sample4x4maxmin_ps20 0 +class sample4x4maxmin_ps20_Dynamic_Index +{ +public: + sample4x4maxmin_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_sample4x4maxmin_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/sample4x4maxmin_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/sample4x4maxmin_ps20b.inc new file mode 100644 index 0000000..89f1f1e --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/sample4x4maxmin_ps20b.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class sample4x4maxmin_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + sample4x4maxmin_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_sample4x4maxmin_ps20b 0 +class sample4x4maxmin_ps20b_Dynamic_Index +{ +public: + sample4x4maxmin_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_sample4x4maxmin_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/screenspaceeffect_vs11.inc b/materialsystem/stdshaders/fxctmp9_360/screenspaceeffect_vs11.inc new file mode 100644 index 0000000..38093cc --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/screenspaceeffect_vs11.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class screenspaceeffect_vs11_Static_Index +{ +public: + screenspaceeffect_vs11_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_screenspaceeffect_vs11 0 +class screenspaceeffect_vs11_Dynamic_Index +{ +public: + screenspaceeffect_vs11_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_screenspaceeffect_vs11 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/screenspaceeffect_vs20.inc b/materialsystem/stdshaders/fxctmp9_360/screenspaceeffect_vs20.inc new file mode 100644 index 0000000..3ed87f4 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/screenspaceeffect_vs20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class screenspaceeffect_vs20_Static_Index +{ +private: + int m_nX360APPCHOOSER; +#ifdef _DEBUG + bool m_bX360APPCHOOSER; +#endif +public: + void SetX360APPCHOOSER( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nX360APPCHOOSER = i; +#ifdef _DEBUG + m_bX360APPCHOOSER = true; +#endif + } + void SetX360APPCHOOSER( bool i ) + { + m_nX360APPCHOOSER = i ? 1 : 0; +#ifdef _DEBUG + m_bX360APPCHOOSER = true; +#endif + } +public: + screenspaceeffect_vs20_Static_Index( ) + { +#ifdef _DEBUG + m_bX360APPCHOOSER = true; +#endif // _DEBUG + m_nX360APPCHOOSER = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bX360APPCHOOSER; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nX360APPCHOOSER ) + 0; + } +}; +#define shaderStaticTest_screenspaceeffect_vs20 0 +class screenspaceeffect_vs20_Dynamic_Index +{ +public: + screenspaceeffect_vs20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_screenspaceeffect_vs20 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/sfm_combine_vs20.inc b/materialsystem/stdshaders/fxctmp9_360/sfm_combine_vs20.inc new file mode 100644 index 0000000..f8d5f29 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/sfm_combine_vs20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class sfm_combine_vs20_Static_Index +{ +public: + sfm_combine_vs20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_sfm_combine_vs20 0 +class sfm_combine_vs20_Dynamic_Index +{ +public: + sfm_combine_vs20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_sfm_combine_vs20 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/sfm_integercombine_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/sfm_integercombine_ps20.inc new file mode 100644 index 0000000..c10d85a --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/sfm_integercombine_ps20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class sfm_integercombine_ps20_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + sfm_integercombine_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_sfm_integercombine_ps20 0 +class sfm_integercombine_ps20_Dynamic_Index +{ +public: + sfm_integercombine_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_sfm_integercombine_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/sfm_integercombine_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/sfm_integercombine_ps20b.inc new file mode 100644 index 0000000..7669ffc --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/sfm_integercombine_ps20b.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class sfm_integercombine_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + sfm_integercombine_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_sfm_integercombine_ps20b 0 +class sfm_integercombine_ps20b_Dynamic_Index +{ +public: + sfm_integercombine_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_sfm_integercombine_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/shadow_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/shadow_ps20.inc new file mode 100644 index 0000000..7bd6ea9 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/shadow_ps20.inc @@ -0,0 +1,87 @@ +#include "shaderlib/cshader.h" +class shadow_ps20_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + shadow_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_shadow_ps20 0 +class shadow_ps20_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + shadow_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_shadow_ps20 psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/shadow_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/shadow_ps20b.inc new file mode 100644 index 0000000..6bed304 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/shadow_ps20b.inc @@ -0,0 +1,87 @@ +#include "shaderlib/cshader.h" +class shadow_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + shadow_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_shadow_ps20b 0 +class shadow_ps20b_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + shadow_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_shadow_ps20b psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/shadow_vs20.inc b/materialsystem/stdshaders/fxctmp9_360/shadow_vs20.inc new file mode 100644 index 0000000..4a96e17 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/shadow_vs20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class shadow_vs20_Static_Index +{ +public: + shadow_vs20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_shadow_vs20 0 +class shadow_vs20_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + shadow_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; +#define shaderDynamicTest_shadow_vs20 vsh_forgot_to_set_dynamic_DOWATERFOG + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/shadowbuildtexture_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/shadowbuildtexture_ps20.inc new file mode 100644 index 0000000..cbf9462 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/shadowbuildtexture_ps20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class shadowbuildtexture_ps20_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + shadowbuildtexture_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_shadowbuildtexture_ps20 0 +class shadowbuildtexture_ps20_Dynamic_Index +{ +public: + shadowbuildtexture_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_shadowbuildtexture_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/shadowbuildtexture_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/shadowbuildtexture_ps20b.inc new file mode 100644 index 0000000..bf5b665 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/shadowbuildtexture_ps20b.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class shadowbuildtexture_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + shadowbuildtexture_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_shadowbuildtexture_ps20b 0 +class shadowbuildtexture_ps20b_Dynamic_Index +{ +public: + shadowbuildtexture_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_shadowbuildtexture_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/shadowmodel_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/shadowmodel_ps20.inc new file mode 100644 index 0000000..6d4f8c8 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/shadowmodel_ps20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class shadowmodel_ps20_Static_Index +{ +public: + shadowmodel_ps20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_shadowmodel_ps20 0 +class shadowmodel_ps20_Dynamic_Index +{ +public: + shadowmodel_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_shadowmodel_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/shadowmodel_vs20.inc b/materialsystem/stdshaders/fxctmp9_360/shadowmodel_vs20.inc new file mode 100644 index 0000000..f5ec141 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/shadowmodel_vs20.inc @@ -0,0 +1,85 @@ +#include "shaderlib/cshader.h" +class shadowmodel_vs20_Static_Index +{ +public: + shadowmodel_vs20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_shadowmodel_vs20 0 +class shadowmodel_vs20_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +public: + shadowmodel_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG && m_bSKINNING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + ( 2 * m_nSKINNING ) + 0; + } +}; +#define shaderDynamicTest_shadowmodel_vs20 vsh_forgot_to_set_dynamic_DOWATERFOG + vsh_forgot_to_set_dynamic_SKINNING + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/showz_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/showz_ps20.inc new file mode 100644 index 0000000..a13230c --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/showz_ps20.inc @@ -0,0 +1,85 @@ +#include "shaderlib/cshader.h" +class showz_ps20_Static_Index +{ +private: + int m_nDEPTH_IN_ALPHA; +#ifdef _DEBUG + bool m_bDEPTH_IN_ALPHA; +#endif +public: + void SetDEPTH_IN_ALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDEPTH_IN_ALPHA = i; +#ifdef _DEBUG + m_bDEPTH_IN_ALPHA = true; +#endif + } + void SetDEPTH_IN_ALPHA( bool i ) + { + m_nDEPTH_IN_ALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bDEPTH_IN_ALPHA = true; +#endif + } +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + showz_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bDEPTH_IN_ALPHA = false; +#endif // _DEBUG + m_nDEPTH_IN_ALPHA = 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bDEPTH_IN_ALPHA && m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDEPTH_IN_ALPHA ) + ( 2 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_showz_ps20 psh_forgot_to_set_static_DEPTH_IN_ALPHA + 0 +class showz_ps20_Dynamic_Index +{ +public: + showz_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_showz_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/showz_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/showz_ps20b.inc new file mode 100644 index 0000000..1779ff9 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/showz_ps20b.inc @@ -0,0 +1,85 @@ +#include "shaderlib/cshader.h" +class showz_ps20b_Static_Index +{ +private: + int m_nDEPTH_IN_ALPHA; +#ifdef _DEBUG + bool m_bDEPTH_IN_ALPHA; +#endif +public: + void SetDEPTH_IN_ALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDEPTH_IN_ALPHA = i; +#ifdef _DEBUG + m_bDEPTH_IN_ALPHA = true; +#endif + } + void SetDEPTH_IN_ALPHA( bool i ) + { + m_nDEPTH_IN_ALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bDEPTH_IN_ALPHA = true; +#endif + } +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + showz_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bDEPTH_IN_ALPHA = false; +#endif // _DEBUG + m_nDEPTH_IN_ALPHA = 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bDEPTH_IN_ALPHA && m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDEPTH_IN_ALPHA ) + ( 2 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_showz_ps20b psh_forgot_to_set_static_DEPTH_IN_ALPHA + 0 +class showz_ps20b_Dynamic_Index +{ +public: + showz_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_showz_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/showz_vs11.inc b/materialsystem/stdshaders/fxctmp9_360/showz_vs11.inc new file mode 100644 index 0000000..61bae60 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/showz_vs11.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class showz_vs11_Static_Index +{ +public: + showz_vs11_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_showz_vs11 0 +class showz_vs11_Dynamic_Index +{ +public: + showz_vs11_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_showz_vs11 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/showz_vs20.inc b/materialsystem/stdshaders/fxctmp9_360/showz_vs20.inc new file mode 100644 index 0000000..344b432 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/showz_vs20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class showz_vs20_Static_Index +{ +public: + showz_vs20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_showz_vs20 0 +class showz_vs20_Dynamic_Index +{ +public: + showz_vs20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_showz_vs20 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/skin_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/skin_ps20b.inc new file mode 100644 index 0000000..f7ef204 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/skin_ps20b.inc @@ -0,0 +1,512 @@ +#include "shaderlib/cshader.h" +class skin_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +private: + int m_nCUBEMAP; +#ifdef _DEBUG + bool m_bCUBEMAP; +#endif +public: + void SetCUBEMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCUBEMAP = i; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } + void SetCUBEMAP( bool i ) + { + m_nCUBEMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } +private: + int m_nSELFILLUM; +#ifdef _DEBUG + bool m_bSELFILLUM; +#endif +public: + void SetSELFILLUM( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSELFILLUM = i; +#ifdef _DEBUG + m_bSELFILLUM = true; +#endif + } + void SetSELFILLUM( bool i ) + { + m_nSELFILLUM = i ? 1 : 0; +#ifdef _DEBUG + m_bSELFILLUM = true; +#endif + } +private: + int m_nSELFILLUMFRESNEL; +#ifdef _DEBUG + bool m_bSELFILLUMFRESNEL; +#endif +public: + void SetSELFILLUMFRESNEL( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSELFILLUMFRESNEL = i; +#ifdef _DEBUG + m_bSELFILLUMFRESNEL = true; +#endif + } + void SetSELFILLUMFRESNEL( bool i ) + { + m_nSELFILLUMFRESNEL = i ? 1 : 0; +#ifdef _DEBUG + m_bSELFILLUMFRESNEL = true; +#endif + } +private: + int m_nFLASHLIGHT; +#ifdef _DEBUG + bool m_bFLASHLIGHT; +#endif +public: + void SetFLASHLIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFLASHLIGHT = i; +#ifdef _DEBUG + m_bFLASHLIGHT = true; +#endif + } + void SetFLASHLIGHT( bool i ) + { + m_nFLASHLIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bFLASHLIGHT = true; +#endif + } +private: + int m_nLIGHTWARPTEXTURE; +#ifdef _DEBUG + bool m_bLIGHTWARPTEXTURE; +#endif +public: + void SetLIGHTWARPTEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nLIGHTWARPTEXTURE = i; +#ifdef _DEBUG + m_bLIGHTWARPTEXTURE = true; +#endif + } + void SetLIGHTWARPTEXTURE( bool i ) + { + m_nLIGHTWARPTEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bLIGHTWARPTEXTURE = true; +#endif + } +private: + int m_nPHONGWARPTEXTURE; +#ifdef _DEBUG + bool m_bPHONGWARPTEXTURE; +#endif +public: + void SetPHONGWARPTEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPHONGWARPTEXTURE = i; +#ifdef _DEBUG + m_bPHONGWARPTEXTURE = true; +#endif + } + void SetPHONGWARPTEXTURE( bool i ) + { + m_nPHONGWARPTEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bPHONGWARPTEXTURE = true; +#endif + } +private: + int m_nWRINKLEMAP; +#ifdef _DEBUG + bool m_bWRINKLEMAP; +#endif +public: + void SetWRINKLEMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nWRINKLEMAP = i; +#ifdef _DEBUG + m_bWRINKLEMAP = true; +#endif + } + void SetWRINKLEMAP( bool i ) + { + m_nWRINKLEMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bWRINKLEMAP = true; +#endif + } +private: + int m_nDETAIL_BLEND_MODE; +#ifdef _DEBUG + bool m_bDETAIL_BLEND_MODE; +#endif +public: + void SetDETAIL_BLEND_MODE( int i ) + { + Assert( i >= 0 && i <= 6 ); + m_nDETAIL_BLEND_MODE = i; +#ifdef _DEBUG + m_bDETAIL_BLEND_MODE = true; +#endif + } + void SetDETAIL_BLEND_MODE( bool i ) + { + m_nDETAIL_BLEND_MODE = i ? 1 : 0; +#ifdef _DEBUG + m_bDETAIL_BLEND_MODE = true; +#endif + } +private: + int m_nDETAILTEXTURE; +#ifdef _DEBUG + bool m_bDETAILTEXTURE; +#endif +public: + void SetDETAILTEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDETAILTEXTURE = i; +#ifdef _DEBUG + m_bDETAILTEXTURE = true; +#endif + } + void SetDETAILTEXTURE( bool i ) + { + m_nDETAILTEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bDETAILTEXTURE = true; +#endif + } +private: + int m_nRIMLIGHT; +#ifdef _DEBUG + bool m_bRIMLIGHT; +#endif +public: + void SetRIMLIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nRIMLIGHT = i; +#ifdef _DEBUG + m_bRIMLIGHT = true; +#endif + } + void SetRIMLIGHT( bool i ) + { + m_nRIMLIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bRIMLIGHT = true; +#endif + } +private: + int m_nFLASHLIGHTDEPTHFILTERMODE; +#ifdef _DEBUG + bool m_bFLASHLIGHTDEPTHFILTERMODE; +#endif +public: + void SetFLASHLIGHTDEPTHFILTERMODE( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nFLASHLIGHTDEPTHFILTERMODE = i; +#ifdef _DEBUG + m_bFLASHLIGHTDEPTHFILTERMODE = true; +#endif + } + void SetFLASHLIGHTDEPTHFILTERMODE( bool i ) + { + m_nFLASHLIGHTDEPTHFILTERMODE = i ? 1 : 0; +#ifdef _DEBUG + m_bFLASHLIGHTDEPTHFILTERMODE = true; +#endif + } +private: + int m_nFASTPATH_NOBUMP; +#ifdef _DEBUG + bool m_bFASTPATH_NOBUMP; +#endif +public: + void SetFASTPATH_NOBUMP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFASTPATH_NOBUMP = i; +#ifdef _DEBUG + m_bFASTPATH_NOBUMP = true; +#endif + } + void SetFASTPATH_NOBUMP( bool i ) + { + m_nFASTPATH_NOBUMP = i ? 1 : 0; +#ifdef _DEBUG + m_bFASTPATH_NOBUMP = true; +#endif + } +private: + int m_nBLENDTINTBYBASEALPHA; +#ifdef _DEBUG + bool m_bBLENDTINTBYBASEALPHA; +#endif +public: + void SetBLENDTINTBYBASEALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBLENDTINTBYBASEALPHA = i; +#ifdef _DEBUG + m_bBLENDTINTBYBASEALPHA = true; +#endif + } + void SetBLENDTINTBYBASEALPHA( bool i ) + { + m_nBLENDTINTBYBASEALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bBLENDTINTBYBASEALPHA = true; +#endif + } +public: + skin_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = false; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; +#ifdef _DEBUG + m_bCUBEMAP = false; +#endif // _DEBUG + m_nCUBEMAP = 0; +#ifdef _DEBUG + m_bSELFILLUM = false; +#endif // _DEBUG + m_nSELFILLUM = 0; +#ifdef _DEBUG + m_bSELFILLUMFRESNEL = false; +#endif // _DEBUG + m_nSELFILLUMFRESNEL = 0; +#ifdef _DEBUG + m_bFLASHLIGHT = false; +#endif // _DEBUG + m_nFLASHLIGHT = 0; +#ifdef _DEBUG + m_bLIGHTWARPTEXTURE = false; +#endif // _DEBUG + m_nLIGHTWARPTEXTURE = 0; +#ifdef _DEBUG + m_bPHONGWARPTEXTURE = false; +#endif // _DEBUG + m_nPHONGWARPTEXTURE = 0; +#ifdef _DEBUG + m_bWRINKLEMAP = false; +#endif // _DEBUG + m_nWRINKLEMAP = 0; +#ifdef _DEBUG + m_bDETAIL_BLEND_MODE = false; +#endif // _DEBUG + m_nDETAIL_BLEND_MODE = 0; +#ifdef _DEBUG + m_bDETAILTEXTURE = false; +#endif // _DEBUG + m_nDETAILTEXTURE = 0; +#ifdef _DEBUG + m_bRIMLIGHT = false; +#endif // _DEBUG + m_nRIMLIGHT = 0; +#ifdef _DEBUG + m_bFLASHLIGHTDEPTHFILTERMODE = false; +#endif // _DEBUG + m_nFLASHLIGHTDEPTHFILTERMODE = 0; +#ifdef _DEBUG + m_bFASTPATH_NOBUMP = false; +#endif // _DEBUG + m_nFASTPATH_NOBUMP = 0; +#ifdef _DEBUG + m_bBLENDTINTBYBASEALPHA = false; +#endif // _DEBUG + m_nBLENDTINTBYBASEALPHA = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB && m_bCUBEMAP && m_bSELFILLUM && m_bSELFILLUMFRESNEL && m_bFLASHLIGHT && m_bLIGHTWARPTEXTURE && m_bPHONGWARPTEXTURE && m_bWRINKLEMAP && m_bDETAIL_BLEND_MODE && m_bDETAILTEXTURE && m_bRIMLIGHT && m_bFLASHLIGHTDEPTHFILTERMODE && m_bFASTPATH_NOBUMP && m_bBLENDTINTBYBASEALPHA; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 40 * m_nCONVERT_TO_SRGB ) + ( 40 * m_nCUBEMAP ) + ( 80 * m_nSELFILLUM ) + ( 160 * m_nSELFILLUMFRESNEL ) + ( 320 * m_nFLASHLIGHT ) + ( 640 * m_nLIGHTWARPTEXTURE ) + ( 1280 * m_nPHONGWARPTEXTURE ) + ( 2560 * m_nWRINKLEMAP ) + ( 5120 * m_nDETAIL_BLEND_MODE ) + ( 35840 * m_nDETAILTEXTURE ) + ( 71680 * m_nRIMLIGHT ) + ( 143360 * m_nFLASHLIGHTDEPTHFILTERMODE ) + ( 143360 * m_nFASTPATH_NOBUMP ) + ( 286720 * m_nBLENDTINTBYBASEALPHA ) + 0; + } +}; +#define shaderStaticTest_skin_ps20b psh_forgot_to_set_static_CONVERT_TO_SRGB + psh_forgot_to_set_static_CUBEMAP + psh_forgot_to_set_static_SELFILLUM + psh_forgot_to_set_static_SELFILLUMFRESNEL + psh_forgot_to_set_static_FLASHLIGHT + psh_forgot_to_set_static_LIGHTWARPTEXTURE + psh_forgot_to_set_static_PHONGWARPTEXTURE + psh_forgot_to_set_static_WRINKLEMAP + psh_forgot_to_set_static_DETAIL_BLEND_MODE + psh_forgot_to_set_static_DETAILTEXTURE + psh_forgot_to_set_static_RIMLIGHT + psh_forgot_to_set_static_FLASHLIGHTDEPTHFILTERMODE + psh_forgot_to_set_static_FASTPATH_NOBUMP + psh_forgot_to_set_static_BLENDTINTBYBASEALPHA + 0 +class skin_ps20b_Dynamic_Index +{ +private: + int m_nWRITEWATERFOGTODESTALPHA; +#ifdef _DEBUG + bool m_bWRITEWATERFOGTODESTALPHA; +#endif +public: + void SetWRITEWATERFOGTODESTALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nWRITEWATERFOGTODESTALPHA = i; +#ifdef _DEBUG + m_bWRITEWATERFOGTODESTALPHA = true; +#endif + } + void SetWRITEWATERFOGTODESTALPHA( bool i ) + { + m_nWRITEWATERFOGTODESTALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bWRITEWATERFOGTODESTALPHA = true; +#endif + } +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +private: + int m_nNUM_LIGHTS; +#ifdef _DEBUG + bool m_bNUM_LIGHTS; +#endif +public: + void SetNUM_LIGHTS( int i ) + { + Assert( i >= 0 && i <= 4 ); + m_nNUM_LIGHTS = i; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } + void SetNUM_LIGHTS( bool i ) + { + m_nNUM_LIGHTS = i ? 1 : 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } +private: + int m_nWRITE_DEPTH_TO_DESTALPHA; +#ifdef _DEBUG + bool m_bWRITE_DEPTH_TO_DESTALPHA; +#endif +public: + void SetWRITE_DEPTH_TO_DESTALPHA( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nWRITE_DEPTH_TO_DESTALPHA = i; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = true; +#endif + } + void SetWRITE_DEPTH_TO_DESTALPHA( bool i ) + { + m_nWRITE_DEPTH_TO_DESTALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = true; +#endif + } +private: + int m_nFLASHLIGHTSHADOWS; +#ifdef _DEBUG + bool m_bFLASHLIGHTSHADOWS; +#endif +public: + void SetFLASHLIGHTSHADOWS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFLASHLIGHTSHADOWS = i; +#ifdef _DEBUG + m_bFLASHLIGHTSHADOWS = true; +#endif + } + void SetFLASHLIGHTSHADOWS( bool i ) + { + m_nFLASHLIGHTSHADOWS = i ? 1 : 0; +#ifdef _DEBUG + m_bFLASHLIGHTSHADOWS = true; +#endif + } +public: + skin_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bWRITEWATERFOGTODESTALPHA = false; +#endif // _DEBUG + m_nWRITEWATERFOGTODESTALPHA = 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = false; +#endif // _DEBUG + m_nNUM_LIGHTS = 0; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = false; +#endif // _DEBUG + m_nWRITE_DEPTH_TO_DESTALPHA = 0; +#ifdef _DEBUG + m_bFLASHLIGHTSHADOWS = false; +#endif // _DEBUG + m_nFLASHLIGHTSHADOWS = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bWRITEWATERFOGTODESTALPHA && m_bPIXELFOGTYPE && m_bNUM_LIGHTS && m_bWRITE_DEPTH_TO_DESTALPHA && m_bFLASHLIGHTSHADOWS; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nWRITEWATERFOGTODESTALPHA ) + ( 2 * m_nPIXELFOGTYPE ) + ( 4 * m_nNUM_LIGHTS ) + ( 20 * m_nWRITE_DEPTH_TO_DESTALPHA ) + ( 20 * m_nFLASHLIGHTSHADOWS ) + 0; + } +}; +#define shaderDynamicTest_skin_ps20b psh_forgot_to_set_dynamic_WRITEWATERFOGTODESTALPHA + psh_forgot_to_set_dynamic_PIXELFOGTYPE + psh_forgot_to_set_dynamic_NUM_LIGHTS + psh_forgot_to_set_dynamic_WRITE_DEPTH_TO_DESTALPHA + psh_forgot_to_set_dynamic_FLASHLIGHTSHADOWS + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/skin_vs20.inc b/materialsystem/stdshaders/fxctmp9_360/skin_vs20.inc new file mode 100644 index 0000000..4c821b8 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/skin_vs20.inc @@ -0,0 +1,187 @@ +#include "shaderlib/cshader.h" +class skin_vs20_Static_Index +{ +private: + int m_nUSE_STATIC_CONTROL_FLOW; +#ifdef _DEBUG + bool m_bUSE_STATIC_CONTROL_FLOW; +#endif +public: + void SetUSE_STATIC_CONTROL_FLOW( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nUSE_STATIC_CONTROL_FLOW = i; +#ifdef _DEBUG + m_bUSE_STATIC_CONTROL_FLOW = true; +#endif + } + void SetUSE_STATIC_CONTROL_FLOW( bool i ) + { + m_nUSE_STATIC_CONTROL_FLOW = i ? 1 : 0; +#ifdef _DEBUG + m_bUSE_STATIC_CONTROL_FLOW = true; +#endif + } +public: + skin_vs20_Static_Index( ) + { +#ifdef _DEBUG + m_bUSE_STATIC_CONTROL_FLOW = false; +#endif // _DEBUG + m_nUSE_STATIC_CONTROL_FLOW = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bUSE_STATIC_CONTROL_FLOW; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 24 * m_nUSE_STATIC_CONTROL_FLOW ) + 0; + } +}; +#define shaderStaticTest_skin_vs20 vsh_forgot_to_set_static_USE_STATIC_CONTROL_FLOW + 0 +class skin_vs20_Dynamic_Index +{ +private: + int m_nCOMPRESSED_VERTS; +#ifdef _DEBUG + bool m_bCOMPRESSED_VERTS; +#endif +public: + void SetCOMPRESSED_VERTS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOMPRESSED_VERTS = i; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } + void SetCOMPRESSED_VERTS( bool i ) + { + m_nCOMPRESSED_VERTS = i ? 1 : 0; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +private: + int m_nLIGHTING_PREVIEW; +#ifdef _DEBUG + bool m_bLIGHTING_PREVIEW; +#endif +public: + void SetLIGHTING_PREVIEW( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nLIGHTING_PREVIEW = i; +#ifdef _DEBUG + m_bLIGHTING_PREVIEW = true; +#endif + } + void SetLIGHTING_PREVIEW( bool i ) + { + m_nLIGHTING_PREVIEW = i ? 1 : 0; +#ifdef _DEBUG + m_bLIGHTING_PREVIEW = true; +#endif + } +private: + int m_nNUM_LIGHTS; +#ifdef _DEBUG + bool m_bNUM_LIGHTS; +#endif +public: + void SetNUM_LIGHTS( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nNUM_LIGHTS = i; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } + void SetNUM_LIGHTS( bool i ) + { + m_nNUM_LIGHTS = i ? 1 : 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } +public: + skin_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = false; +#endif // _DEBUG + m_nCOMPRESSED_VERTS = 0; +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; +#ifdef _DEBUG + m_bLIGHTING_PREVIEW = false; +#endif // _DEBUG + m_nLIGHTING_PREVIEW = 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = false; +#endif // _DEBUG + m_nNUM_LIGHTS = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bCOMPRESSED_VERTS && m_bDOWATERFOG && m_bSKINNING && m_bLIGHTING_PREVIEW && m_bNUM_LIGHTS; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCOMPRESSED_VERTS ) + ( 2 * m_nDOWATERFOG ) + ( 4 * m_nSKINNING ) + ( 8 * m_nLIGHTING_PREVIEW ) + ( 8 * m_nNUM_LIGHTS ) + 0; + } +}; +#define shaderDynamicTest_skin_vs20 vsh_forgot_to_set_dynamic_COMPRESSED_VERTS + vsh_forgot_to_set_dynamic_DOWATERFOG + vsh_forgot_to_set_dynamic_SKINNING + vsh_forgot_to_set_dynamic_LIGHTING_PREVIEW + vsh_forgot_to_set_dynamic_NUM_LIGHTS + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/sky_hdr_compressed_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/sky_hdr_compressed_ps20.inc new file mode 100644 index 0000000..c9251d0 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/sky_hdr_compressed_ps20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class sky_hdr_compressed_ps20_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + sky_hdr_compressed_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_sky_hdr_compressed_ps20 0 +class sky_hdr_compressed_ps20_Dynamic_Index +{ +public: + sky_hdr_compressed_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_sky_hdr_compressed_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/sky_hdr_compressed_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/sky_hdr_compressed_ps20b.inc new file mode 100644 index 0000000..fdca141 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/sky_hdr_compressed_ps20b.inc @@ -0,0 +1,87 @@ +#include "shaderlib/cshader.h" +class sky_hdr_compressed_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + sky_hdr_compressed_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_sky_hdr_compressed_ps20b 0 +class sky_hdr_compressed_ps20b_Dynamic_Index +{ +private: + int m_nWRITE_DEPTH_TO_DESTALPHA; +#ifdef _DEBUG + bool m_bWRITE_DEPTH_TO_DESTALPHA; +#endif +public: + void SetWRITE_DEPTH_TO_DESTALPHA( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nWRITE_DEPTH_TO_DESTALPHA = i; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = true; +#endif + } + void SetWRITE_DEPTH_TO_DESTALPHA( bool i ) + { + m_nWRITE_DEPTH_TO_DESTALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = true; +#endif + } +public: + sky_hdr_compressed_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = false; +#endif // _DEBUG + m_nWRITE_DEPTH_TO_DESTALPHA = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bWRITE_DEPTH_TO_DESTALPHA; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nWRITE_DEPTH_TO_DESTALPHA ) + 0; + } +}; +#define shaderDynamicTest_sky_hdr_compressed_ps20b psh_forgot_to_set_dynamic_WRITE_DEPTH_TO_DESTALPHA + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/sky_hdr_compressed_rgbs_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/sky_hdr_compressed_rgbs_ps20.inc new file mode 100644 index 0000000..08636b2 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/sky_hdr_compressed_rgbs_ps20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class sky_hdr_compressed_rgbs_ps20_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + sky_hdr_compressed_rgbs_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_sky_hdr_compressed_rgbs_ps20 0 +class sky_hdr_compressed_rgbs_ps20_Dynamic_Index +{ +public: + sky_hdr_compressed_rgbs_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_sky_hdr_compressed_rgbs_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/sky_hdr_compressed_rgbs_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/sky_hdr_compressed_rgbs_ps20b.inc new file mode 100644 index 0000000..ba05d60 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/sky_hdr_compressed_rgbs_ps20b.inc @@ -0,0 +1,87 @@ +#include "shaderlib/cshader.h" +class sky_hdr_compressed_rgbs_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + sky_hdr_compressed_rgbs_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_sky_hdr_compressed_rgbs_ps20b 0 +class sky_hdr_compressed_rgbs_ps20b_Dynamic_Index +{ +private: + int m_nWRITE_DEPTH_TO_DESTALPHA; +#ifdef _DEBUG + bool m_bWRITE_DEPTH_TO_DESTALPHA; +#endif +public: + void SetWRITE_DEPTH_TO_DESTALPHA( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nWRITE_DEPTH_TO_DESTALPHA = i; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = true; +#endif + } + void SetWRITE_DEPTH_TO_DESTALPHA( bool i ) + { + m_nWRITE_DEPTH_TO_DESTALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = true; +#endif + } +public: + sky_hdr_compressed_rgbs_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = false; +#endif // _DEBUG + m_nWRITE_DEPTH_TO_DESTALPHA = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bWRITE_DEPTH_TO_DESTALPHA; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nWRITE_DEPTH_TO_DESTALPHA ) + 0; + } +}; +#define shaderDynamicTest_sky_hdr_compressed_rgbs_ps20b psh_forgot_to_set_dynamic_WRITE_DEPTH_TO_DESTALPHA + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/sky_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/sky_ps20.inc new file mode 100644 index 0000000..a1f913c --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/sky_ps20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class sky_ps20_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + sky_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_sky_ps20 0 +class sky_ps20_Dynamic_Index +{ +public: + sky_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_sky_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/sky_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/sky_ps20b.inc new file mode 100644 index 0000000..e6b7d00 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/sky_ps20b.inc @@ -0,0 +1,87 @@ +#include "shaderlib/cshader.h" +class sky_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + sky_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_sky_ps20b 0 +class sky_ps20b_Dynamic_Index +{ +private: + int m_nWRITE_DEPTH_TO_DESTALPHA; +#ifdef _DEBUG + bool m_bWRITE_DEPTH_TO_DESTALPHA; +#endif +public: + void SetWRITE_DEPTH_TO_DESTALPHA( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nWRITE_DEPTH_TO_DESTALPHA = i; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = true; +#endif + } + void SetWRITE_DEPTH_TO_DESTALPHA( bool i ) + { + m_nWRITE_DEPTH_TO_DESTALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = true; +#endif + } +public: + sky_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = false; +#endif // _DEBUG + m_nWRITE_DEPTH_TO_DESTALPHA = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bWRITE_DEPTH_TO_DESTALPHA; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nWRITE_DEPTH_TO_DESTALPHA ) + 0; + } +}; +#define shaderDynamicTest_sky_ps20b psh_forgot_to_set_dynamic_WRITE_DEPTH_TO_DESTALPHA + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/sky_vs20.inc b/materialsystem/stdshaders/fxctmp9_360/sky_vs20.inc new file mode 100644 index 0000000..546b1d9 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/sky_vs20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class sky_vs20_Static_Index +{ +public: + sky_vs20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_sky_vs20 0 +class sky_vs20_Dynamic_Index +{ +public: + sky_vs20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_sky_vs20 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/splinecard_vs11.inc b/materialsystem/stdshaders/fxctmp9_360/splinecard_vs11.inc new file mode 100644 index 0000000..aa16481 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/splinecard_vs11.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class splinecard_vs11_Static_Index +{ +public: + splinecard_vs11_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_splinecard_vs11 0 +class splinecard_vs11_Dynamic_Index +{ +public: + splinecard_vs11_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_splinecard_vs11 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/splinecard_vs20.inc b/materialsystem/stdshaders/fxctmp9_360/splinecard_vs20.inc new file mode 100644 index 0000000..97c6b1e --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/splinecard_vs20.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class splinecard_vs20_Static_Index +{ +public: + splinecard_vs20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_splinecard_vs20 0 +class splinecard_vs20_Dynamic_Index +{ +public: + splinecard_vs20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_splinecard_vs20 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/sprite_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/sprite_ps20.inc new file mode 100644 index 0000000..9070e6d --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/sprite_ps20.inc @@ -0,0 +1,212 @@ +#include "shaderlib/cshader.h" +class sprite_ps20_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +private: + int m_nVERTEXCOLOR; +#ifdef _DEBUG + bool m_bVERTEXCOLOR; +#endif +public: + void SetVERTEXCOLOR( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nVERTEXCOLOR = i; +#ifdef _DEBUG + m_bVERTEXCOLOR = true; +#endif + } + void SetVERTEXCOLOR( bool i ) + { + m_nVERTEXCOLOR = i ? 1 : 0; +#ifdef _DEBUG + m_bVERTEXCOLOR = true; +#endif + } +private: + int m_nCONSTANTCOLOR; +#ifdef _DEBUG + bool m_bCONSTANTCOLOR; +#endif +public: + void SetCONSTANTCOLOR( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONSTANTCOLOR = i; +#ifdef _DEBUG + m_bCONSTANTCOLOR = true; +#endif + } + void SetCONSTANTCOLOR( bool i ) + { + m_nCONSTANTCOLOR = i ? 1 : 0; +#ifdef _DEBUG + m_bCONSTANTCOLOR = true; +#endif + } +private: + int m_nHDRTYPE; +#ifdef _DEBUG + bool m_bHDRTYPE; +#endif +public: + void SetHDRTYPE( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nHDRTYPE = i; +#ifdef _DEBUG + m_bHDRTYPE = true; +#endif + } + void SetHDRTYPE( bool i ) + { + m_nHDRTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bHDRTYPE = true; +#endif + } +private: + int m_nSRGB; +#ifdef _DEBUG + bool m_bSRGB; +#endif +public: + void SetSRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSRGB = i; +#ifdef _DEBUG + m_bSRGB = true; +#endif + } + void SetSRGB( bool i ) + { + m_nSRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bSRGB = true; +#endif + } +public: + sprite_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; +#ifdef _DEBUG + m_bVERTEXCOLOR = false; +#endif // _DEBUG + m_nVERTEXCOLOR = 0; +#ifdef _DEBUG + m_bCONSTANTCOLOR = false; +#endif // _DEBUG + m_nCONSTANTCOLOR = 0; +#ifdef _DEBUG + m_bHDRTYPE = false; +#endif // _DEBUG + m_nHDRTYPE = 0; +#ifdef _DEBUG + m_bSRGB = false; +#endif // _DEBUG + m_nSRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB && m_bVERTEXCOLOR && m_bCONSTANTCOLOR && m_bHDRTYPE && m_bSRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 4 * m_nCONVERT_TO_SRGB ) + ( 4 * m_nVERTEXCOLOR ) + ( 8 * m_nCONSTANTCOLOR ) + ( 16 * m_nHDRTYPE ) + ( 48 * m_nSRGB ) + 0; + } +}; +#define shaderStaticTest_sprite_ps20 psh_forgot_to_set_static_VERTEXCOLOR + psh_forgot_to_set_static_CONSTANTCOLOR + psh_forgot_to_set_static_HDRTYPE + psh_forgot_to_set_static_SRGB + 0 +class sprite_ps20_Dynamic_Index +{ +private: + int m_nHDRENABLED; +#ifdef _DEBUG + bool m_bHDRENABLED; +#endif +public: + void SetHDRENABLED( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHDRENABLED = i; +#ifdef _DEBUG + m_bHDRENABLED = true; +#endif + } + void SetHDRENABLED( bool i ) + { + m_nHDRENABLED = i ? 1 : 0; +#ifdef _DEBUG + m_bHDRENABLED = true; +#endif + } +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + sprite_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bHDRENABLED = false; +#endif // _DEBUG + m_nHDRENABLED = 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bHDRENABLED && m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nHDRENABLED ) + ( 2 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_sprite_ps20 psh_forgot_to_set_dynamic_HDRENABLED + psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/sprite_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/sprite_ps20b.inc new file mode 100644 index 0000000..13ee22f --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/sprite_ps20b.inc @@ -0,0 +1,237 @@ +#include "shaderlib/cshader.h" +class sprite_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +private: + int m_nVERTEXCOLOR; +#ifdef _DEBUG + bool m_bVERTEXCOLOR; +#endif +public: + void SetVERTEXCOLOR( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nVERTEXCOLOR = i; +#ifdef _DEBUG + m_bVERTEXCOLOR = true; +#endif + } + void SetVERTEXCOLOR( bool i ) + { + m_nVERTEXCOLOR = i ? 1 : 0; +#ifdef _DEBUG + m_bVERTEXCOLOR = true; +#endif + } +private: + int m_nCONSTANTCOLOR; +#ifdef _DEBUG + bool m_bCONSTANTCOLOR; +#endif +public: + void SetCONSTANTCOLOR( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCONSTANTCOLOR = i; +#ifdef _DEBUG + m_bCONSTANTCOLOR = true; +#endif + } + void SetCONSTANTCOLOR( bool i ) + { + m_nCONSTANTCOLOR = i ? 1 : 0; +#ifdef _DEBUG + m_bCONSTANTCOLOR = true; +#endif + } +private: + int m_nHDRTYPE; +#ifdef _DEBUG + bool m_bHDRTYPE; +#endif +public: + void SetHDRTYPE( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nHDRTYPE = i; +#ifdef _DEBUG + m_bHDRTYPE = true; +#endif + } + void SetHDRTYPE( bool i ) + { + m_nHDRTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bHDRTYPE = true; +#endif + } +private: + int m_nSRGB; +#ifdef _DEBUG + bool m_bSRGB; +#endif +public: + void SetSRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSRGB = i; +#ifdef _DEBUG + m_bSRGB = true; +#endif + } + void SetSRGB( bool i ) + { + m_nSRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bSRGB = true; +#endif + } +private: + int m_nSRGB_OUTPUT_ADAPTER; +#ifdef _DEBUG + bool m_bSRGB_OUTPUT_ADAPTER; +#endif +public: + void SetSRGB_OUTPUT_ADAPTER( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSRGB_OUTPUT_ADAPTER = i; +#ifdef _DEBUG + m_bSRGB_OUTPUT_ADAPTER = true; +#endif + } + void SetSRGB_OUTPUT_ADAPTER( bool i ) + { + m_nSRGB_OUTPUT_ADAPTER = i ? 1 : 0; +#ifdef _DEBUG + m_bSRGB_OUTPUT_ADAPTER = true; +#endif + } +public: + sprite_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; +#ifdef _DEBUG + m_bVERTEXCOLOR = false; +#endif // _DEBUG + m_nVERTEXCOLOR = 0; +#ifdef _DEBUG + m_bCONSTANTCOLOR = false; +#endif // _DEBUG + m_nCONSTANTCOLOR = 0; +#ifdef _DEBUG + m_bHDRTYPE = false; +#endif // _DEBUG + m_nHDRTYPE = 0; +#ifdef _DEBUG + m_bSRGB = false; +#endif // _DEBUG + m_nSRGB = 0; +#ifdef _DEBUG + m_bSRGB_OUTPUT_ADAPTER = false; +#endif // _DEBUG + m_nSRGB_OUTPUT_ADAPTER = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB && m_bVERTEXCOLOR && m_bCONSTANTCOLOR && m_bHDRTYPE && m_bSRGB && m_bSRGB_OUTPUT_ADAPTER; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 4 * m_nCONVERT_TO_SRGB ) + ( 4 * m_nVERTEXCOLOR ) + ( 8 * m_nCONSTANTCOLOR ) + ( 16 * m_nHDRTYPE ) + ( 48 * m_nSRGB ) + ( 96 * m_nSRGB_OUTPUT_ADAPTER ) + 0; + } +}; +#define shaderStaticTest_sprite_ps20b psh_forgot_to_set_static_VERTEXCOLOR + psh_forgot_to_set_static_CONSTANTCOLOR + psh_forgot_to_set_static_HDRTYPE + psh_forgot_to_set_static_SRGB + psh_forgot_to_set_static_SRGB_OUTPUT_ADAPTER + 0 +class sprite_ps20b_Dynamic_Index +{ +private: + int m_nHDRENABLED; +#ifdef _DEBUG + bool m_bHDRENABLED; +#endif +public: + void SetHDRENABLED( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHDRENABLED = i; +#ifdef _DEBUG + m_bHDRENABLED = true; +#endif + } + void SetHDRENABLED( bool i ) + { + m_nHDRENABLED = i ? 1 : 0; +#ifdef _DEBUG + m_bHDRENABLED = true; +#endif + } +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + sprite_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bHDRENABLED = false; +#endif // _DEBUG + m_nHDRENABLED = 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bHDRENABLED && m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nHDRENABLED ) + ( 2 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_sprite_ps20b psh_forgot_to_set_dynamic_HDRENABLED + psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/sprite_vs20.inc b/materialsystem/stdshaders/fxctmp9_360/sprite_vs20.inc new file mode 100644 index 0000000..5422743 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/sprite_vs20.inc @@ -0,0 +1,112 @@ +#include "shaderlib/cshader.h" +class sprite_vs20_Static_Index +{ +private: + int m_nVERTEXCOLOR; +#ifdef _DEBUG + bool m_bVERTEXCOLOR; +#endif +public: + void SetVERTEXCOLOR( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nVERTEXCOLOR = i; +#ifdef _DEBUG + m_bVERTEXCOLOR = true; +#endif + } + void SetVERTEXCOLOR( bool i ) + { + m_nVERTEXCOLOR = i ? 1 : 0; +#ifdef _DEBUG + m_bVERTEXCOLOR = true; +#endif + } +private: + int m_nSRGB; +#ifdef _DEBUG + bool m_bSRGB; +#endif +public: + void SetSRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSRGB = i; +#ifdef _DEBUG + m_bSRGB = true; +#endif + } + void SetSRGB( bool i ) + { + m_nSRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bSRGB = true; +#endif + } +public: + sprite_vs20_Static_Index( ) + { +#ifdef _DEBUG + m_bVERTEXCOLOR = false; +#endif // _DEBUG + m_nVERTEXCOLOR = 0; +#ifdef _DEBUG + m_bSRGB = false; +#endif // _DEBUG + m_nSRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bVERTEXCOLOR && m_bSRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nVERTEXCOLOR ) + ( 4 * m_nSRGB ) + 0; + } +}; +#define shaderStaticTest_sprite_vs20 vsh_forgot_to_set_static_VERTEXCOLOR + vsh_forgot_to_set_static_SRGB + 0 +class sprite_vs20_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + sprite_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; +#define shaderDynamicTest_sprite_vs20 vsh_forgot_to_set_dynamic_DOWATERFOG + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/spritecard_ps11.inc b/materialsystem/stdshaders/fxctmp9_360/spritecard_ps11.inc new file mode 100644 index 0000000..9978f06 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/spritecard_ps11.inc @@ -0,0 +1,110 @@ +#include "shaderlib/cshader.h" +class spritecard_ps11_Static_Index +{ +private: + int m_nADDBASETEXTURE2; +#ifdef _DEBUG + bool m_bADDBASETEXTURE2; +#endif +public: + void SetADDBASETEXTURE2( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nADDBASETEXTURE2 = i; +#ifdef _DEBUG + m_bADDBASETEXTURE2 = true; +#endif + } + void SetADDBASETEXTURE2( bool i ) + { + m_nADDBASETEXTURE2 = i ? 1 : 0; +#ifdef _DEBUG + m_bADDBASETEXTURE2 = true; +#endif + } +private: + int m_nADDSELF; +#ifdef _DEBUG + bool m_bADDSELF; +#endif +public: + void SetADDSELF( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nADDSELF = i; +#ifdef _DEBUG + m_bADDSELF = true; +#endif + } + void SetADDSELF( bool i ) + { + m_nADDSELF = i ? 1 : 0; +#ifdef _DEBUG + m_bADDSELF = true; +#endif + } +private: + int m_nUSEALPHAASRGB; +#ifdef _DEBUG + bool m_bUSEALPHAASRGB; +#endif +public: + void SetUSEALPHAASRGB( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nUSEALPHAASRGB = i; +#ifdef _DEBUG + m_bUSEALPHAASRGB = true; +#endif + } + void SetUSEALPHAASRGB( bool i ) + { + m_nUSEALPHAASRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bUSEALPHAASRGB = true; +#endif + } +public: + spritecard_ps11_Static_Index( ) + { +#ifdef _DEBUG + m_bADDBASETEXTURE2 = false; +#endif // _DEBUG + m_nADDBASETEXTURE2 = 0; +#ifdef _DEBUG + m_bADDSELF = false; +#endif // _DEBUG + m_nADDSELF = 0; +#ifdef _DEBUG + m_bUSEALPHAASRGB = false; +#endif // _DEBUG + m_nUSEALPHAASRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bADDBASETEXTURE2 && m_bADDSELF && m_bUSEALPHAASRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nADDBASETEXTURE2 ) + ( 2 * m_nADDSELF ) + ( 4 * m_nUSEALPHAASRGB ) + 0; + } +}; +#define shaderStaticTest_spritecard_ps11 psh_forgot_to_set_static_ADDBASETEXTURE2 + psh_forgot_to_set_static_ADDSELF + psh_forgot_to_set_static_USEALPHAASRGB + 0 +class spritecard_ps11_Dynamic_Index +{ +public: + spritecard_ps11_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_spritecard_ps11 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/spritecard_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/spritecard_ps20.inc new file mode 100644 index 0000000..2d1492b --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/spritecard_ps20.inc @@ -0,0 +1,285 @@ +#include "shaderlib/cshader.h" +class spritecard_ps20_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +private: + int m_nDUALSEQUENCE; +#ifdef _DEBUG + bool m_bDUALSEQUENCE; +#endif +public: + void SetDUALSEQUENCE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDUALSEQUENCE = i; +#ifdef _DEBUG + m_bDUALSEQUENCE = true; +#endif + } + void SetDUALSEQUENCE( bool i ) + { + m_nDUALSEQUENCE = i ? 1 : 0; +#ifdef _DEBUG + m_bDUALSEQUENCE = true; +#endif + } +private: + int m_nSEQUENCE_BLEND_MODE; +#ifdef _DEBUG + bool m_bSEQUENCE_BLEND_MODE; +#endif +public: + void SetSEQUENCE_BLEND_MODE( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nSEQUENCE_BLEND_MODE = i; +#ifdef _DEBUG + m_bSEQUENCE_BLEND_MODE = true; +#endif + } + void SetSEQUENCE_BLEND_MODE( bool i ) + { + m_nSEQUENCE_BLEND_MODE = i ? 1 : 0; +#ifdef _DEBUG + m_bSEQUENCE_BLEND_MODE = true; +#endif + } +private: + int m_nADDBASETEXTURE2; +#ifdef _DEBUG + bool m_bADDBASETEXTURE2; +#endif +public: + void SetADDBASETEXTURE2( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nADDBASETEXTURE2 = i; +#ifdef _DEBUG + m_bADDBASETEXTURE2 = true; +#endif + } + void SetADDBASETEXTURE2( bool i ) + { + m_nADDBASETEXTURE2 = i ? 1 : 0; +#ifdef _DEBUG + m_bADDBASETEXTURE2 = true; +#endif + } +private: + int m_nMAXLUMFRAMEBLEND1; +#ifdef _DEBUG + bool m_bMAXLUMFRAMEBLEND1; +#endif +public: + void SetMAXLUMFRAMEBLEND1( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nMAXLUMFRAMEBLEND1 = i; +#ifdef _DEBUG + m_bMAXLUMFRAMEBLEND1 = true; +#endif + } + void SetMAXLUMFRAMEBLEND1( bool i ) + { + m_nMAXLUMFRAMEBLEND1 = i ? 1 : 0; +#ifdef _DEBUG + m_bMAXLUMFRAMEBLEND1 = true; +#endif + } +private: + int m_nMAXLUMFRAMEBLEND2; +#ifdef _DEBUG + bool m_bMAXLUMFRAMEBLEND2; +#endif +public: + void SetMAXLUMFRAMEBLEND2( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nMAXLUMFRAMEBLEND2 = i; +#ifdef _DEBUG + m_bMAXLUMFRAMEBLEND2 = true; +#endif + } + void SetMAXLUMFRAMEBLEND2( bool i ) + { + m_nMAXLUMFRAMEBLEND2 = i ? 1 : 0; +#ifdef _DEBUG + m_bMAXLUMFRAMEBLEND2 = true; +#endif + } +private: + int m_nEXTRACTGREENALPHA; +#ifdef _DEBUG + bool m_bEXTRACTGREENALPHA; +#endif +public: + void SetEXTRACTGREENALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nEXTRACTGREENALPHA = i; +#ifdef _DEBUG + m_bEXTRACTGREENALPHA = true; +#endif + } + void SetEXTRACTGREENALPHA( bool i ) + { + m_nEXTRACTGREENALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bEXTRACTGREENALPHA = true; +#endif + } +private: + int m_nCOLORRAMP; +#ifdef _DEBUG + bool m_bCOLORRAMP; +#endif +public: + void SetCOLORRAMP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOLORRAMP = i; +#ifdef _DEBUG + m_bCOLORRAMP = true; +#endif + } + void SetCOLORRAMP( bool i ) + { + m_nCOLORRAMP = i ? 1 : 0; +#ifdef _DEBUG + m_bCOLORRAMP = true; +#endif + } +private: + int m_nANIMBLEND; +#ifdef _DEBUG + bool m_bANIMBLEND; +#endif +public: + void SetANIMBLEND( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nANIMBLEND = i; +#ifdef _DEBUG + m_bANIMBLEND = true; +#endif + } + void SetANIMBLEND( bool i ) + { + m_nANIMBLEND = i ? 1 : 0; +#ifdef _DEBUG + m_bANIMBLEND = true; +#endif + } +private: + int m_nADDSELF; +#ifdef _DEBUG + bool m_bADDSELF; +#endif +public: + void SetADDSELF( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nADDSELF = i; +#ifdef _DEBUG + m_bADDSELF = true; +#endif + } + void SetADDSELF( bool i ) + { + m_nADDSELF = i ? 1 : 0; +#ifdef _DEBUG + m_bADDSELF = true; +#endif + } +public: + spritecard_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; +#ifdef _DEBUG + m_bDUALSEQUENCE = false; +#endif // _DEBUG + m_nDUALSEQUENCE = 0; +#ifdef _DEBUG + m_bSEQUENCE_BLEND_MODE = false; +#endif // _DEBUG + m_nSEQUENCE_BLEND_MODE = 0; +#ifdef _DEBUG + m_bADDBASETEXTURE2 = false; +#endif // _DEBUG + m_nADDBASETEXTURE2 = 0; +#ifdef _DEBUG + m_bMAXLUMFRAMEBLEND1 = false; +#endif // _DEBUG + m_nMAXLUMFRAMEBLEND1 = 0; +#ifdef _DEBUG + m_bMAXLUMFRAMEBLEND2 = false; +#endif // _DEBUG + m_nMAXLUMFRAMEBLEND2 = 0; +#ifdef _DEBUG + m_bEXTRACTGREENALPHA = false; +#endif // _DEBUG + m_nEXTRACTGREENALPHA = 0; +#ifdef _DEBUG + m_bCOLORRAMP = false; +#endif // _DEBUG + m_nCOLORRAMP = 0; +#ifdef _DEBUG + m_bANIMBLEND = false; +#endif // _DEBUG + m_nANIMBLEND = 0; +#ifdef _DEBUG + m_bADDSELF = false; +#endif // _DEBUG + m_nADDSELF = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB && m_bDUALSEQUENCE && m_bSEQUENCE_BLEND_MODE && m_bADDBASETEXTURE2 && m_bMAXLUMFRAMEBLEND1 && m_bMAXLUMFRAMEBLEND2 && m_bEXTRACTGREENALPHA && m_bCOLORRAMP && m_bANIMBLEND && m_bADDSELF; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + ( 1 * m_nDUALSEQUENCE ) + ( 2 * m_nSEQUENCE_BLEND_MODE ) + ( 6 * m_nADDBASETEXTURE2 ) + ( 12 * m_nMAXLUMFRAMEBLEND1 ) + ( 24 * m_nMAXLUMFRAMEBLEND2 ) + ( 48 * m_nEXTRACTGREENALPHA ) + ( 96 * m_nCOLORRAMP ) + ( 192 * m_nANIMBLEND ) + ( 384 * m_nADDSELF ) + 0; + } +}; +#define shaderStaticTest_spritecard_ps20 psh_forgot_to_set_static_DUALSEQUENCE + psh_forgot_to_set_static_SEQUENCE_BLEND_MODE + psh_forgot_to_set_static_ADDBASETEXTURE2 + psh_forgot_to_set_static_MAXLUMFRAMEBLEND1 + psh_forgot_to_set_static_MAXLUMFRAMEBLEND2 + psh_forgot_to_set_static_EXTRACTGREENALPHA + psh_forgot_to_set_static_COLORRAMP + psh_forgot_to_set_static_ANIMBLEND + psh_forgot_to_set_static_ADDSELF + 0 +class spritecard_ps20_Dynamic_Index +{ +public: + spritecard_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_spritecard_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/spritecard_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/spritecard_ps20b.inc new file mode 100644 index 0000000..262cab1 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/spritecard_ps20b.inc @@ -0,0 +1,310 @@ +#include "shaderlib/cshader.h" +class spritecard_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +private: + int m_nDUALSEQUENCE; +#ifdef _DEBUG + bool m_bDUALSEQUENCE; +#endif +public: + void SetDUALSEQUENCE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDUALSEQUENCE = i; +#ifdef _DEBUG + m_bDUALSEQUENCE = true; +#endif + } + void SetDUALSEQUENCE( bool i ) + { + m_nDUALSEQUENCE = i ? 1 : 0; +#ifdef _DEBUG + m_bDUALSEQUENCE = true; +#endif + } +private: + int m_nSEQUENCE_BLEND_MODE; +#ifdef _DEBUG + bool m_bSEQUENCE_BLEND_MODE; +#endif +public: + void SetSEQUENCE_BLEND_MODE( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nSEQUENCE_BLEND_MODE = i; +#ifdef _DEBUG + m_bSEQUENCE_BLEND_MODE = true; +#endif + } + void SetSEQUENCE_BLEND_MODE( bool i ) + { + m_nSEQUENCE_BLEND_MODE = i ? 1 : 0; +#ifdef _DEBUG + m_bSEQUENCE_BLEND_MODE = true; +#endif + } +private: + int m_nADDBASETEXTURE2; +#ifdef _DEBUG + bool m_bADDBASETEXTURE2; +#endif +public: + void SetADDBASETEXTURE2( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nADDBASETEXTURE2 = i; +#ifdef _DEBUG + m_bADDBASETEXTURE2 = true; +#endif + } + void SetADDBASETEXTURE2( bool i ) + { + m_nADDBASETEXTURE2 = i ? 1 : 0; +#ifdef _DEBUG + m_bADDBASETEXTURE2 = true; +#endif + } +private: + int m_nMAXLUMFRAMEBLEND1; +#ifdef _DEBUG + bool m_bMAXLUMFRAMEBLEND1; +#endif +public: + void SetMAXLUMFRAMEBLEND1( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nMAXLUMFRAMEBLEND1 = i; +#ifdef _DEBUG + m_bMAXLUMFRAMEBLEND1 = true; +#endif + } + void SetMAXLUMFRAMEBLEND1( bool i ) + { + m_nMAXLUMFRAMEBLEND1 = i ? 1 : 0; +#ifdef _DEBUG + m_bMAXLUMFRAMEBLEND1 = true; +#endif + } +private: + int m_nMAXLUMFRAMEBLEND2; +#ifdef _DEBUG + bool m_bMAXLUMFRAMEBLEND2; +#endif +public: + void SetMAXLUMFRAMEBLEND2( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nMAXLUMFRAMEBLEND2 = i; +#ifdef _DEBUG + m_bMAXLUMFRAMEBLEND2 = true; +#endif + } + void SetMAXLUMFRAMEBLEND2( bool i ) + { + m_nMAXLUMFRAMEBLEND2 = i ? 1 : 0; +#ifdef _DEBUG + m_bMAXLUMFRAMEBLEND2 = true; +#endif + } +private: + int m_nEXTRACTGREENALPHA; +#ifdef _DEBUG + bool m_bEXTRACTGREENALPHA; +#endif +public: + void SetEXTRACTGREENALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nEXTRACTGREENALPHA = i; +#ifdef _DEBUG + m_bEXTRACTGREENALPHA = true; +#endif + } + void SetEXTRACTGREENALPHA( bool i ) + { + m_nEXTRACTGREENALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bEXTRACTGREENALPHA = true; +#endif + } +private: + int m_nCOLORRAMP; +#ifdef _DEBUG + bool m_bCOLORRAMP; +#endif +public: + void SetCOLORRAMP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOLORRAMP = i; +#ifdef _DEBUG + m_bCOLORRAMP = true; +#endif + } + void SetCOLORRAMP( bool i ) + { + m_nCOLORRAMP = i ? 1 : 0; +#ifdef _DEBUG + m_bCOLORRAMP = true; +#endif + } +private: + int m_nANIMBLEND; +#ifdef _DEBUG + bool m_bANIMBLEND; +#endif +public: + void SetANIMBLEND( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nANIMBLEND = i; +#ifdef _DEBUG + m_bANIMBLEND = true; +#endif + } + void SetANIMBLEND( bool i ) + { + m_nANIMBLEND = i ? 1 : 0; +#ifdef _DEBUG + m_bANIMBLEND = true; +#endif + } +private: + int m_nADDSELF; +#ifdef _DEBUG + bool m_bADDSELF; +#endif +public: + void SetADDSELF( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nADDSELF = i; +#ifdef _DEBUG + m_bADDSELF = true; +#endif + } + void SetADDSELF( bool i ) + { + m_nADDSELF = i ? 1 : 0; +#ifdef _DEBUG + m_bADDSELF = true; +#endif + } +private: + int m_nDEPTHBLEND; +#ifdef _DEBUG + bool m_bDEPTHBLEND; +#endif +public: + void SetDEPTHBLEND( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDEPTHBLEND = i; +#ifdef _DEBUG + m_bDEPTHBLEND = true; +#endif + } + void SetDEPTHBLEND( bool i ) + { + m_nDEPTHBLEND = i ? 1 : 0; +#ifdef _DEBUG + m_bDEPTHBLEND = true; +#endif + } +public: + spritecard_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; +#ifdef _DEBUG + m_bDUALSEQUENCE = false; +#endif // _DEBUG + m_nDUALSEQUENCE = 0; +#ifdef _DEBUG + m_bSEQUENCE_BLEND_MODE = false; +#endif // _DEBUG + m_nSEQUENCE_BLEND_MODE = 0; +#ifdef _DEBUG + m_bADDBASETEXTURE2 = false; +#endif // _DEBUG + m_nADDBASETEXTURE2 = 0; +#ifdef _DEBUG + m_bMAXLUMFRAMEBLEND1 = false; +#endif // _DEBUG + m_nMAXLUMFRAMEBLEND1 = 0; +#ifdef _DEBUG + m_bMAXLUMFRAMEBLEND2 = false; +#endif // _DEBUG + m_nMAXLUMFRAMEBLEND2 = 0; +#ifdef _DEBUG + m_bEXTRACTGREENALPHA = false; +#endif // _DEBUG + m_nEXTRACTGREENALPHA = 0; +#ifdef _DEBUG + m_bCOLORRAMP = false; +#endif // _DEBUG + m_nCOLORRAMP = 0; +#ifdef _DEBUG + m_bANIMBLEND = false; +#endif // _DEBUG + m_nANIMBLEND = 0; +#ifdef _DEBUG + m_bADDSELF = false; +#endif // _DEBUG + m_nADDSELF = 0; +#ifdef _DEBUG + m_bDEPTHBLEND = false; +#endif // _DEBUG + m_nDEPTHBLEND = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB && m_bDUALSEQUENCE && m_bSEQUENCE_BLEND_MODE && m_bADDBASETEXTURE2 && m_bMAXLUMFRAMEBLEND1 && m_bMAXLUMFRAMEBLEND2 && m_bEXTRACTGREENALPHA && m_bCOLORRAMP && m_bANIMBLEND && m_bADDSELF && m_bDEPTHBLEND; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + ( 1 * m_nDUALSEQUENCE ) + ( 2 * m_nSEQUENCE_BLEND_MODE ) + ( 6 * m_nADDBASETEXTURE2 ) + ( 12 * m_nMAXLUMFRAMEBLEND1 ) + ( 24 * m_nMAXLUMFRAMEBLEND2 ) + ( 48 * m_nEXTRACTGREENALPHA ) + ( 96 * m_nCOLORRAMP ) + ( 192 * m_nANIMBLEND ) + ( 384 * m_nADDSELF ) + ( 768 * m_nDEPTHBLEND ) + 0; + } +}; +#define shaderStaticTest_spritecard_ps20b psh_forgot_to_set_static_DUALSEQUENCE + psh_forgot_to_set_static_SEQUENCE_BLEND_MODE + psh_forgot_to_set_static_ADDBASETEXTURE2 + psh_forgot_to_set_static_MAXLUMFRAMEBLEND1 + psh_forgot_to_set_static_MAXLUMFRAMEBLEND2 + psh_forgot_to_set_static_EXTRACTGREENALPHA + psh_forgot_to_set_static_COLORRAMP + psh_forgot_to_set_static_ANIMBLEND + psh_forgot_to_set_static_ADDSELF + psh_forgot_to_set_static_DEPTHBLEND + 0 +class spritecard_ps20b_Dynamic_Index +{ +public: + spritecard_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_spritecard_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/spritecard_vs11.inc b/materialsystem/stdshaders/fxctmp9_360/spritecard_vs11.inc new file mode 100644 index 0000000..7b6a9ef --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/spritecard_vs11.inc @@ -0,0 +1,137 @@ +#include "shaderlib/cshader.h" +class spritecard_vs11_Static_Index +{ +private: + int m_nZOOM_ANIMATE_SEQ2; +#ifdef _DEBUG + bool m_bZOOM_ANIMATE_SEQ2; +#endif +public: + void SetZOOM_ANIMATE_SEQ2( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nZOOM_ANIMATE_SEQ2 = i; +#ifdef _DEBUG + m_bZOOM_ANIMATE_SEQ2 = true; +#endif + } + void SetZOOM_ANIMATE_SEQ2( bool i ) + { + m_nZOOM_ANIMATE_SEQ2 = i ? 1 : 0; +#ifdef _DEBUG + m_bZOOM_ANIMATE_SEQ2 = true; +#endif + } +private: + int m_nDUALSEQUENCE; +#ifdef _DEBUG + bool m_bDUALSEQUENCE; +#endif +public: + void SetDUALSEQUENCE( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nDUALSEQUENCE = i; +#ifdef _DEBUG + m_bDUALSEQUENCE = true; +#endif + } + void SetDUALSEQUENCE( bool i ) + { + m_nDUALSEQUENCE = i ? 1 : 0; +#ifdef _DEBUG + m_bDUALSEQUENCE = true; +#endif + } +private: + int m_nEXTRACTGREENALPHA; +#ifdef _DEBUG + bool m_bEXTRACTGREENALPHA; +#endif +public: + void SetEXTRACTGREENALPHA( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nEXTRACTGREENALPHA = i; +#ifdef _DEBUG + m_bEXTRACTGREENALPHA = true; +#endif + } + void SetEXTRACTGREENALPHA( bool i ) + { + m_nEXTRACTGREENALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bEXTRACTGREENALPHA = true; +#endif + } +public: + spritecard_vs11_Static_Index( ) + { +#ifdef _DEBUG + m_bZOOM_ANIMATE_SEQ2 = false; +#endif // _DEBUG + m_nZOOM_ANIMATE_SEQ2 = 0; +#ifdef _DEBUG + m_bDUALSEQUENCE = false; +#endif // _DEBUG + m_nDUALSEQUENCE = 0; +#ifdef _DEBUG + m_bEXTRACTGREENALPHA = false; +#endif // _DEBUG + m_nEXTRACTGREENALPHA = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bZOOM_ANIMATE_SEQ2 && m_bDUALSEQUENCE && m_bEXTRACTGREENALPHA; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 3 * m_nZOOM_ANIMATE_SEQ2 ) + ( 3 * m_nDUALSEQUENCE ) + ( 3 * m_nEXTRACTGREENALPHA ) + 0; + } +}; +#define shaderStaticTest_spritecard_vs11 vsh_forgot_to_set_static_ZOOM_ANIMATE_SEQ2 + vsh_forgot_to_set_static_DUALSEQUENCE + vsh_forgot_to_set_static_EXTRACTGREENALPHA + 0 +class spritecard_vs11_Dynamic_Index +{ +private: + int m_nORIENTATION; +#ifdef _DEBUG + bool m_bORIENTATION; +#endif +public: + void SetORIENTATION( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nORIENTATION = i; +#ifdef _DEBUG + m_bORIENTATION = true; +#endif + } + void SetORIENTATION( bool i ) + { + m_nORIENTATION = i ? 1 : 0; +#ifdef _DEBUG + m_bORIENTATION = true; +#endif + } +public: + spritecard_vs11_Dynamic_Index() + { +#ifdef _DEBUG + m_bORIENTATION = false; +#endif // _DEBUG + m_nORIENTATION = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bORIENTATION; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nORIENTATION ) + 0; + } +}; +#define shaderDynamicTest_spritecard_vs11 vsh_forgot_to_set_dynamic_ORIENTATION + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/spritecard_vs20.inc b/materialsystem/stdshaders/fxctmp9_360/spritecard_vs20.inc new file mode 100644 index 0000000..f573fb9 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/spritecard_vs20.inc @@ -0,0 +1,162 @@ +#include "shaderlib/cshader.h" +class spritecard_vs20_Static_Index +{ +private: + int m_nZOOM_ANIMATE_SEQ2; +#ifdef _DEBUG + bool m_bZOOM_ANIMATE_SEQ2; +#endif +public: + void SetZOOM_ANIMATE_SEQ2( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nZOOM_ANIMATE_SEQ2 = i; +#ifdef _DEBUG + m_bZOOM_ANIMATE_SEQ2 = true; +#endif + } + void SetZOOM_ANIMATE_SEQ2( bool i ) + { + m_nZOOM_ANIMATE_SEQ2 = i ? 1 : 0; +#ifdef _DEBUG + m_bZOOM_ANIMATE_SEQ2 = true; +#endif + } +private: + int m_nDUALSEQUENCE; +#ifdef _DEBUG + bool m_bDUALSEQUENCE; +#endif +public: + void SetDUALSEQUENCE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDUALSEQUENCE = i; +#ifdef _DEBUG + m_bDUALSEQUENCE = true; +#endif + } + void SetDUALSEQUENCE( bool i ) + { + m_nDUALSEQUENCE = i ? 1 : 0; +#ifdef _DEBUG + m_bDUALSEQUENCE = true; +#endif + } +private: + int m_nEXTRACTGREENALPHA; +#ifdef _DEBUG + bool m_bEXTRACTGREENALPHA; +#endif +public: + void SetEXTRACTGREENALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nEXTRACTGREENALPHA = i; +#ifdef _DEBUG + m_bEXTRACTGREENALPHA = true; +#endif + } + void SetEXTRACTGREENALPHA( bool i ) + { + m_nEXTRACTGREENALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bEXTRACTGREENALPHA = true; +#endif + } +private: + int m_nUSE_INSTANCING; +#ifdef _DEBUG + bool m_bUSE_INSTANCING; +#endif +public: + void SetUSE_INSTANCING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nUSE_INSTANCING = i; +#ifdef _DEBUG + m_bUSE_INSTANCING = true; +#endif + } + void SetUSE_INSTANCING( bool i ) + { + m_nUSE_INSTANCING = i ? 1 : 0; +#ifdef _DEBUG + m_bUSE_INSTANCING = true; +#endif + } +public: + spritecard_vs20_Static_Index( ) + { +#ifdef _DEBUG + m_bZOOM_ANIMATE_SEQ2 = false; +#endif // _DEBUG + m_nZOOM_ANIMATE_SEQ2 = 0; +#ifdef _DEBUG + m_bDUALSEQUENCE = false; +#endif // _DEBUG + m_nDUALSEQUENCE = 0; +#ifdef _DEBUG + m_bEXTRACTGREENALPHA = false; +#endif // _DEBUG + m_nEXTRACTGREENALPHA = 0; +#ifdef _DEBUG + m_bUSE_INSTANCING = false; +#endif // _DEBUG + m_nUSE_INSTANCING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bZOOM_ANIMATE_SEQ2 && m_bDUALSEQUENCE && m_bEXTRACTGREENALPHA && m_bUSE_INSTANCING; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 3 * m_nZOOM_ANIMATE_SEQ2 ) + ( 6 * m_nDUALSEQUENCE ) + ( 12 * m_nEXTRACTGREENALPHA ) + ( 24 * m_nUSE_INSTANCING ) + 0; + } +}; +#define shaderStaticTest_spritecard_vs20 vsh_forgot_to_set_static_ZOOM_ANIMATE_SEQ2 + vsh_forgot_to_set_static_DUALSEQUENCE + vsh_forgot_to_set_static_EXTRACTGREENALPHA + vsh_forgot_to_set_static_USE_INSTANCING + 0 +class spritecard_vs20_Dynamic_Index +{ +private: + int m_nORIENTATION; +#ifdef _DEBUG + bool m_bORIENTATION; +#endif +public: + void SetORIENTATION( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nORIENTATION = i; +#ifdef _DEBUG + m_bORIENTATION = true; +#endif + } + void SetORIENTATION( bool i ) + { + m_nORIENTATION = i ? 1 : 0; +#ifdef _DEBUG + m_bORIENTATION = true; +#endif + } +public: + spritecard_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bORIENTATION = false; +#endif // _DEBUG + m_nORIENTATION = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bORIENTATION; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nORIENTATION ) + 0; + } +}; +#define shaderDynamicTest_spritecard_vs20 vsh_forgot_to_set_dynamic_ORIENTATION + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/teeth_bump_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/teeth_bump_ps20.inc new file mode 100644 index 0000000..0348e4f --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/teeth_bump_ps20.inc @@ -0,0 +1,137 @@ +#include "shaderlib/cshader.h" +class teeth_bump_ps20_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + teeth_bump_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 12 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_teeth_bump_ps20 0 +class teeth_bump_ps20_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +private: + int m_nNUM_LIGHTS; +#ifdef _DEBUG + bool m_bNUM_LIGHTS; +#endif +public: + void SetNUM_LIGHTS( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nNUM_LIGHTS = i; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } + void SetNUM_LIGHTS( bool i ) + { + m_nNUM_LIGHTS = i ? 1 : 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } +private: + int m_nAMBIENT_LIGHT; +#ifdef _DEBUG + bool m_bAMBIENT_LIGHT; +#endif +public: + void SetAMBIENT_LIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nAMBIENT_LIGHT = i; +#ifdef _DEBUG + m_bAMBIENT_LIGHT = true; +#endif + } + void SetAMBIENT_LIGHT( bool i ) + { + m_nAMBIENT_LIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bAMBIENT_LIGHT = true; +#endif + } +public: + teeth_bump_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = false; +#endif // _DEBUG + m_nNUM_LIGHTS = 0; +#ifdef _DEBUG + m_bAMBIENT_LIGHT = false; +#endif // _DEBUG + m_nAMBIENT_LIGHT = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE && m_bNUM_LIGHTS && m_bAMBIENT_LIGHT; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + ( 2 * m_nNUM_LIGHTS ) + ( 6 * m_nAMBIENT_LIGHT ) + 0; + } +}; +#define shaderDynamicTest_teeth_bump_ps20 psh_forgot_to_set_dynamic_PIXELFOGTYPE + psh_forgot_to_set_dynamic_NUM_LIGHTS + psh_forgot_to_set_dynamic_AMBIENT_LIGHT + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/teeth_bump_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/teeth_bump_ps20b.inc new file mode 100644 index 0000000..117d6f4 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/teeth_bump_ps20b.inc @@ -0,0 +1,162 @@ +#include "shaderlib/cshader.h" +class teeth_bump_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + teeth_bump_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 20 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_teeth_bump_ps20b 0 +class teeth_bump_ps20b_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +private: + int m_nNUM_LIGHTS; +#ifdef _DEBUG + bool m_bNUM_LIGHTS; +#endif +public: + void SetNUM_LIGHTS( int i ) + { + Assert( i >= 0 && i <= 4 ); + m_nNUM_LIGHTS = i; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } + void SetNUM_LIGHTS( bool i ) + { + m_nNUM_LIGHTS = i ? 1 : 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } +private: + int m_nAMBIENT_LIGHT; +#ifdef _DEBUG + bool m_bAMBIENT_LIGHT; +#endif +public: + void SetAMBIENT_LIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nAMBIENT_LIGHT = i; +#ifdef _DEBUG + m_bAMBIENT_LIGHT = true; +#endif + } + void SetAMBIENT_LIGHT( bool i ) + { + m_nAMBIENT_LIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bAMBIENT_LIGHT = true; +#endif + } +private: + int m_nWRITE_DEPTH_TO_DESTALPHA; +#ifdef _DEBUG + bool m_bWRITE_DEPTH_TO_DESTALPHA; +#endif +public: + void SetWRITE_DEPTH_TO_DESTALPHA( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nWRITE_DEPTH_TO_DESTALPHA = i; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = true; +#endif + } + void SetWRITE_DEPTH_TO_DESTALPHA( bool i ) + { + m_nWRITE_DEPTH_TO_DESTALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = true; +#endif + } +public: + teeth_bump_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = false; +#endif // _DEBUG + m_nNUM_LIGHTS = 0; +#ifdef _DEBUG + m_bAMBIENT_LIGHT = false; +#endif // _DEBUG + m_nAMBIENT_LIGHT = 0; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = false; +#endif // _DEBUG + m_nWRITE_DEPTH_TO_DESTALPHA = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE && m_bNUM_LIGHTS && m_bAMBIENT_LIGHT && m_bWRITE_DEPTH_TO_DESTALPHA; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + ( 2 * m_nNUM_LIGHTS ) + ( 10 * m_nAMBIENT_LIGHT ) + ( 20 * m_nWRITE_DEPTH_TO_DESTALPHA ) + 0; + } +}; +#define shaderDynamicTest_teeth_bump_ps20b psh_forgot_to_set_dynamic_PIXELFOGTYPE + psh_forgot_to_set_dynamic_NUM_LIGHTS + psh_forgot_to_set_dynamic_AMBIENT_LIGHT + psh_forgot_to_set_dynamic_WRITE_DEPTH_TO_DESTALPHA + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/teeth_bump_vs20.inc b/materialsystem/stdshaders/fxctmp9_360/teeth_bump_vs20.inc new file mode 100644 index 0000000..1f02a02 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/teeth_bump_vs20.inc @@ -0,0 +1,212 @@ +#include "shaderlib/cshader.h" +class teeth_bump_vs20_Static_Index +{ +private: + int m_nINTRO; +#ifdef _DEBUG + bool m_bINTRO; +#endif +public: + void SetINTRO( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nINTRO = i; +#ifdef _DEBUG + m_bINTRO = true; +#endif + } + void SetINTRO( bool i ) + { + m_nINTRO = i ? 1 : 0; +#ifdef _DEBUG + m_bINTRO = true; +#endif + } +private: + int m_nUSE_STATIC_CONTROL_FLOW; +#ifdef _DEBUG + bool m_bUSE_STATIC_CONTROL_FLOW; +#endif +public: + void SetUSE_STATIC_CONTROL_FLOW( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nUSE_STATIC_CONTROL_FLOW = i; +#ifdef _DEBUG + m_bUSE_STATIC_CONTROL_FLOW = true; +#endif + } + void SetUSE_STATIC_CONTROL_FLOW( bool i ) + { + m_nUSE_STATIC_CONTROL_FLOW = i ? 1 : 0; +#ifdef _DEBUG + m_bUSE_STATIC_CONTROL_FLOW = true; +#endif + } +public: + teeth_bump_vs20_Static_Index( ) + { +#ifdef _DEBUG + m_bINTRO = false; +#endif // _DEBUG + m_nINTRO = 0; +#ifdef _DEBUG + m_bUSE_STATIC_CONTROL_FLOW = false; +#endif // _DEBUG + m_nUSE_STATIC_CONTROL_FLOW = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bINTRO && m_bUSE_STATIC_CONTROL_FLOW; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 48 * m_nINTRO ) + ( 96 * m_nUSE_STATIC_CONTROL_FLOW ) + 0; + } +}; +#define shaderStaticTest_teeth_bump_vs20 vsh_forgot_to_set_static_INTRO + vsh_forgot_to_set_static_USE_STATIC_CONTROL_FLOW + 0 +class teeth_bump_vs20_Dynamic_Index +{ +private: + int m_nCOMPRESSED_VERTS; +#ifdef _DEBUG + bool m_bCOMPRESSED_VERTS; +#endif +public: + void SetCOMPRESSED_VERTS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOMPRESSED_VERTS = i; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } + void SetCOMPRESSED_VERTS( bool i ) + { + m_nCOMPRESSED_VERTS = i ? 1 : 0; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +private: + int m_nSTATIC_LIGHT; +#ifdef _DEBUG + bool m_bSTATIC_LIGHT; +#endif +public: + void SetSTATIC_LIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSTATIC_LIGHT = i; +#ifdef _DEBUG + m_bSTATIC_LIGHT = true; +#endif + } + void SetSTATIC_LIGHT( bool i ) + { + m_nSTATIC_LIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bSTATIC_LIGHT = true; +#endif + } +private: + int m_nNUM_LIGHTS; +#ifdef _DEBUG + bool m_bNUM_LIGHTS; +#endif +public: + void SetNUM_LIGHTS( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nNUM_LIGHTS = i; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } + void SetNUM_LIGHTS( bool i ) + { + m_nNUM_LIGHTS = i ? 1 : 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } +public: + teeth_bump_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = false; +#endif // _DEBUG + m_nCOMPRESSED_VERTS = 0; +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; +#ifdef _DEBUG + m_bSTATIC_LIGHT = false; +#endif // _DEBUG + m_nSTATIC_LIGHT = 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = false; +#endif // _DEBUG + m_nNUM_LIGHTS = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bCOMPRESSED_VERTS && m_bDOWATERFOG && m_bSKINNING && m_bSTATIC_LIGHT && m_bNUM_LIGHTS; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCOMPRESSED_VERTS ) + ( 2 * m_nDOWATERFOG ) + ( 4 * m_nSKINNING ) + ( 8 * m_nSTATIC_LIGHT ) + ( 16 * m_nNUM_LIGHTS ) + 0; + } +}; +#define shaderDynamicTest_teeth_bump_vs20 vsh_forgot_to_set_dynamic_COMPRESSED_VERTS + vsh_forgot_to_set_dynamic_DOWATERFOG + vsh_forgot_to_set_dynamic_SKINNING + vsh_forgot_to_set_dynamic_STATIC_LIGHT + vsh_forgot_to_set_dynamic_NUM_LIGHTS + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/teeth_flashlight_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/teeth_flashlight_ps20.inc new file mode 100644 index 0000000..d8fc719 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/teeth_flashlight_ps20.inc @@ -0,0 +1,87 @@ +#include "shaderlib/cshader.h" +class teeth_flashlight_ps20_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + teeth_flashlight_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_teeth_flashlight_ps20 0 +class teeth_flashlight_ps20_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + teeth_flashlight_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_teeth_flashlight_ps20 psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/teeth_flashlight_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/teeth_flashlight_ps20b.inc new file mode 100644 index 0000000..2771376 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/teeth_flashlight_ps20b.inc @@ -0,0 +1,137 @@ +#include "shaderlib/cshader.h" +class teeth_flashlight_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +private: + int m_nFLASHLIGHTDEPTHFILTERMODE; +#ifdef _DEBUG + bool m_bFLASHLIGHTDEPTHFILTERMODE; +#endif +public: + void SetFLASHLIGHTDEPTHFILTERMODE( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nFLASHLIGHTDEPTHFILTERMODE = i; +#ifdef _DEBUG + m_bFLASHLIGHTDEPTHFILTERMODE = true; +#endif + } + void SetFLASHLIGHTDEPTHFILTERMODE( bool i ) + { + m_nFLASHLIGHTDEPTHFILTERMODE = i ? 1 : 0; +#ifdef _DEBUG + m_bFLASHLIGHTDEPTHFILTERMODE = true; +#endif + } +public: + teeth_flashlight_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; +#ifdef _DEBUG + m_bFLASHLIGHTDEPTHFILTERMODE = false; +#endif // _DEBUG + m_nFLASHLIGHTDEPTHFILTERMODE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB && m_bFLASHLIGHTDEPTHFILTERMODE; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 4 * m_nCONVERT_TO_SRGB ) + ( 4 * m_nFLASHLIGHTDEPTHFILTERMODE ) + 0; + } +}; +#define shaderStaticTest_teeth_flashlight_ps20b psh_forgot_to_set_static_FLASHLIGHTDEPTHFILTERMODE + 0 +class teeth_flashlight_ps20b_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +private: + int m_nFLASHLIGHTSHADOWS; +#ifdef _DEBUG + bool m_bFLASHLIGHTSHADOWS; +#endif +public: + void SetFLASHLIGHTSHADOWS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFLASHLIGHTSHADOWS = i; +#ifdef _DEBUG + m_bFLASHLIGHTSHADOWS = true; +#endif + } + void SetFLASHLIGHTSHADOWS( bool i ) + { + m_nFLASHLIGHTSHADOWS = i ? 1 : 0; +#ifdef _DEBUG + m_bFLASHLIGHTSHADOWS = true; +#endif + } +public: + teeth_flashlight_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; +#ifdef _DEBUG + m_bFLASHLIGHTSHADOWS = false; +#endif // _DEBUG + m_nFLASHLIGHTSHADOWS = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE && m_bFLASHLIGHTSHADOWS; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + ( 2 * m_nFLASHLIGHTSHADOWS ) + 0; + } +}; +#define shaderDynamicTest_teeth_flashlight_ps20b psh_forgot_to_set_dynamic_PIXELFOGTYPE + psh_forgot_to_set_dynamic_FLASHLIGHTSHADOWS + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/teeth_flashlight_vs20.inc b/materialsystem/stdshaders/fxctmp9_360/teeth_flashlight_vs20.inc new file mode 100644 index 0000000..438bdab --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/teeth_flashlight_vs20.inc @@ -0,0 +1,137 @@ +#include "shaderlib/cshader.h" +class teeth_flashlight_vs20_Static_Index +{ +private: + int m_nINTRO; +#ifdef _DEBUG + bool m_bINTRO; +#endif +public: + void SetINTRO( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nINTRO = i; +#ifdef _DEBUG + m_bINTRO = true; +#endif + } + void SetINTRO( bool i ) + { + m_nINTRO = i ? 1 : 0; +#ifdef _DEBUG + m_bINTRO = true; +#endif + } +public: + teeth_flashlight_vs20_Static_Index( ) + { +#ifdef _DEBUG + m_bINTRO = false; +#endif // _DEBUG + m_nINTRO = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bINTRO; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 8 * m_nINTRO ) + 0; + } +}; +#define shaderStaticTest_teeth_flashlight_vs20 vsh_forgot_to_set_static_INTRO + 0 +class teeth_flashlight_vs20_Dynamic_Index +{ +private: + int m_nCOMPRESSED_VERTS; +#ifdef _DEBUG + bool m_bCOMPRESSED_VERTS; +#endif +public: + void SetCOMPRESSED_VERTS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOMPRESSED_VERTS = i; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } + void SetCOMPRESSED_VERTS( bool i ) + { + m_nCOMPRESSED_VERTS = i ? 1 : 0; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +public: + teeth_flashlight_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = false; +#endif // _DEBUG + m_nCOMPRESSED_VERTS = 0; +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bCOMPRESSED_VERTS && m_bDOWATERFOG && m_bSKINNING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCOMPRESSED_VERTS ) + ( 2 * m_nDOWATERFOG ) + ( 4 * m_nSKINNING ) + 0; + } +}; +#define shaderDynamicTest_teeth_flashlight_vs20 vsh_forgot_to_set_dynamic_COMPRESSED_VERTS + vsh_forgot_to_set_dynamic_DOWATERFOG + vsh_forgot_to_set_dynamic_SKINNING + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/teeth_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/teeth_ps20.inc new file mode 100644 index 0000000..7a18171 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/teeth_ps20.inc @@ -0,0 +1,87 @@ +#include "shaderlib/cshader.h" +class teeth_ps20_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + teeth_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_teeth_ps20 0 +class teeth_ps20_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + teeth_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_teeth_ps20 psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/teeth_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/teeth_ps20b.inc new file mode 100644 index 0000000..8caa34c --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/teeth_ps20b.inc @@ -0,0 +1,112 @@ +#include "shaderlib/cshader.h" +class teeth_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + teeth_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_teeth_ps20b 0 +class teeth_ps20b_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +private: + int m_nWRITE_DEPTH_TO_DESTALPHA; +#ifdef _DEBUG + bool m_bWRITE_DEPTH_TO_DESTALPHA; +#endif +public: + void SetWRITE_DEPTH_TO_DESTALPHA( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nWRITE_DEPTH_TO_DESTALPHA = i; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = true; +#endif + } + void SetWRITE_DEPTH_TO_DESTALPHA( bool i ) + { + m_nWRITE_DEPTH_TO_DESTALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = true; +#endif + } +public: + teeth_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = false; +#endif // _DEBUG + m_nWRITE_DEPTH_TO_DESTALPHA = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE && m_bWRITE_DEPTH_TO_DESTALPHA; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + ( 2 * m_nWRITE_DEPTH_TO_DESTALPHA ) + 0; + } +}; +#define shaderDynamicTest_teeth_ps20b psh_forgot_to_set_dynamic_PIXELFOGTYPE + psh_forgot_to_set_dynamic_WRITE_DEPTH_TO_DESTALPHA + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/teeth_vs20.inc b/materialsystem/stdshaders/fxctmp9_360/teeth_vs20.inc new file mode 100644 index 0000000..5103e17 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/teeth_vs20.inc @@ -0,0 +1,237 @@ +#include "shaderlib/cshader.h" +class teeth_vs20_Static_Index +{ +private: + int m_nINTRO; +#ifdef _DEBUG + bool m_bINTRO; +#endif +public: + void SetINTRO( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nINTRO = i; +#ifdef _DEBUG + m_bINTRO = true; +#endif + } + void SetINTRO( bool i ) + { + m_nINTRO = i ? 1 : 0; +#ifdef _DEBUG + m_bINTRO = true; +#endif + } +private: + int m_nUSE_STATIC_CONTROL_FLOW; +#ifdef _DEBUG + bool m_bUSE_STATIC_CONTROL_FLOW; +#endif +public: + void SetUSE_STATIC_CONTROL_FLOW( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nUSE_STATIC_CONTROL_FLOW = i; +#ifdef _DEBUG + m_bUSE_STATIC_CONTROL_FLOW = true; +#endif + } + void SetUSE_STATIC_CONTROL_FLOW( bool i ) + { + m_nUSE_STATIC_CONTROL_FLOW = i ? 1 : 0; +#ifdef _DEBUG + m_bUSE_STATIC_CONTROL_FLOW = true; +#endif + } +public: + teeth_vs20_Static_Index( ) + { +#ifdef _DEBUG + m_bINTRO = false; +#endif // _DEBUG + m_nINTRO = 0; +#ifdef _DEBUG + m_bUSE_STATIC_CONTROL_FLOW = false; +#endif // _DEBUG + m_nUSE_STATIC_CONTROL_FLOW = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bINTRO && m_bUSE_STATIC_CONTROL_FLOW; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 96 * m_nINTRO ) + ( 192 * m_nUSE_STATIC_CONTROL_FLOW ) + 0; + } +}; +#define shaderStaticTest_teeth_vs20 vsh_forgot_to_set_static_INTRO + vsh_forgot_to_set_static_USE_STATIC_CONTROL_FLOW + 0 +class teeth_vs20_Dynamic_Index +{ +private: + int m_nCOMPRESSED_VERTS; +#ifdef _DEBUG + bool m_bCOMPRESSED_VERTS; +#endif +public: + void SetCOMPRESSED_VERTS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOMPRESSED_VERTS = i; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } + void SetCOMPRESSED_VERTS( bool i ) + { + m_nCOMPRESSED_VERTS = i ? 1 : 0; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +private: + int m_nDYNAMIC_LIGHT; +#ifdef _DEBUG + bool m_bDYNAMIC_LIGHT; +#endif +public: + void SetDYNAMIC_LIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDYNAMIC_LIGHT = i; +#ifdef _DEBUG + m_bDYNAMIC_LIGHT = true; +#endif + } + void SetDYNAMIC_LIGHT( bool i ) + { + m_nDYNAMIC_LIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bDYNAMIC_LIGHT = true; +#endif + } +private: + int m_nSTATIC_LIGHT; +#ifdef _DEBUG + bool m_bSTATIC_LIGHT; +#endif +public: + void SetSTATIC_LIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSTATIC_LIGHT = i; +#ifdef _DEBUG + m_bSTATIC_LIGHT = true; +#endif + } + void SetSTATIC_LIGHT( bool i ) + { + m_nSTATIC_LIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bSTATIC_LIGHT = true; +#endif + } +private: + int m_nNUM_LIGHTS; +#ifdef _DEBUG + bool m_bNUM_LIGHTS; +#endif +public: + void SetNUM_LIGHTS( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nNUM_LIGHTS = i; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } + void SetNUM_LIGHTS( bool i ) + { + m_nNUM_LIGHTS = i ? 1 : 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } +public: + teeth_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = false; +#endif // _DEBUG + m_nCOMPRESSED_VERTS = 0; +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; +#ifdef _DEBUG + m_bDYNAMIC_LIGHT = false; +#endif // _DEBUG + m_nDYNAMIC_LIGHT = 0; +#ifdef _DEBUG + m_bSTATIC_LIGHT = false; +#endif // _DEBUG + m_nSTATIC_LIGHT = 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = false; +#endif // _DEBUG + m_nNUM_LIGHTS = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bCOMPRESSED_VERTS && m_bDOWATERFOG && m_bSKINNING && m_bDYNAMIC_LIGHT && m_bSTATIC_LIGHT && m_bNUM_LIGHTS; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCOMPRESSED_VERTS ) + ( 2 * m_nDOWATERFOG ) + ( 4 * m_nSKINNING ) + ( 8 * m_nDYNAMIC_LIGHT ) + ( 16 * m_nSTATIC_LIGHT ) + ( 32 * m_nNUM_LIGHTS ) + 0; + } +}; +#define shaderDynamicTest_teeth_vs20 vsh_forgot_to_set_dynamic_COMPRESSED_VERTS + vsh_forgot_to_set_dynamic_DOWATERFOG + vsh_forgot_to_set_dynamic_SKINNING + vsh_forgot_to_set_dynamic_DYNAMIC_LIGHT + vsh_forgot_to_set_dynamic_STATIC_LIGHT + vsh_forgot_to_set_dynamic_NUM_LIGHTS + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/treeleaf_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/treeleaf_ps20.inc new file mode 100644 index 0000000..56663bc --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/treeleaf_ps20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class treeleaf_ps20_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + treeleaf_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_treeleaf_ps20 0 +class treeleaf_ps20_Dynamic_Index +{ +public: + treeleaf_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_treeleaf_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/treeleaf_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/treeleaf_ps20b.inc new file mode 100644 index 0000000..23367c2 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/treeleaf_ps20b.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class treeleaf_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + treeleaf_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_treeleaf_ps20b 0 +class treeleaf_ps20b_Dynamic_Index +{ +public: + treeleaf_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_treeleaf_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/treeleaf_vs20.inc b/materialsystem/stdshaders/fxctmp9_360/treeleaf_vs20.inc new file mode 100644 index 0000000..fdd9e28 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/treeleaf_vs20.inc @@ -0,0 +1,162 @@ +#include "shaderlib/cshader.h" +class treeleaf_vs20_Static_Index +{ +private: + int m_nHALFLAMBERT; +#ifdef _DEBUG + bool m_bHALFLAMBERT; +#endif +public: + void SetHALFLAMBERT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHALFLAMBERT = i; +#ifdef _DEBUG + m_bHALFLAMBERT = true; +#endif + } + void SetHALFLAMBERT( bool i ) + { + m_nHALFLAMBERT = i ? 1 : 0; +#ifdef _DEBUG + m_bHALFLAMBERT = true; +#endif + } +private: + int m_nUSE_STATIC_CONTROL_FLOW; +#ifdef _DEBUG + bool m_bUSE_STATIC_CONTROL_FLOW; +#endif +public: + void SetUSE_STATIC_CONTROL_FLOW( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nUSE_STATIC_CONTROL_FLOW = i; +#ifdef _DEBUG + m_bUSE_STATIC_CONTROL_FLOW = true; +#endif + } + void SetUSE_STATIC_CONTROL_FLOW( bool i ) + { + m_nUSE_STATIC_CONTROL_FLOW = i ? 1 : 0; +#ifdef _DEBUG + m_bUSE_STATIC_CONTROL_FLOW = true; +#endif + } +public: + treeleaf_vs20_Static_Index( ) + { +#ifdef _DEBUG + m_bHALFLAMBERT = false; +#endif // _DEBUG + m_nHALFLAMBERT = 0; +#ifdef _DEBUG + m_bUSE_STATIC_CONTROL_FLOW = false; +#endif // _DEBUG + m_nUSE_STATIC_CONTROL_FLOW = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bHALFLAMBERT && m_bUSE_STATIC_CONTROL_FLOW; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 12 * m_nHALFLAMBERT ) + ( 24 * m_nUSE_STATIC_CONTROL_FLOW ) + 0; + } +}; +#define shaderStaticTest_treeleaf_vs20 vsh_forgot_to_set_static_HALFLAMBERT + vsh_forgot_to_set_static_USE_STATIC_CONTROL_FLOW + 0 +class treeleaf_vs20_Dynamic_Index +{ +private: + int m_nDYNAMIC_LIGHT; +#ifdef _DEBUG + bool m_bDYNAMIC_LIGHT; +#endif +public: + void SetDYNAMIC_LIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDYNAMIC_LIGHT = i; +#ifdef _DEBUG + m_bDYNAMIC_LIGHT = true; +#endif + } + void SetDYNAMIC_LIGHT( bool i ) + { + m_nDYNAMIC_LIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bDYNAMIC_LIGHT = true; +#endif + } +private: + int m_nSTATIC_LIGHT; +#ifdef _DEBUG + bool m_bSTATIC_LIGHT; +#endif +public: + void SetSTATIC_LIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSTATIC_LIGHT = i; +#ifdef _DEBUG + m_bSTATIC_LIGHT = true; +#endif + } + void SetSTATIC_LIGHT( bool i ) + { + m_nSTATIC_LIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bSTATIC_LIGHT = true; +#endif + } +private: + int m_nNUM_LIGHTS; +#ifdef _DEBUG + bool m_bNUM_LIGHTS; +#endif +public: + void SetNUM_LIGHTS( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nNUM_LIGHTS = i; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } + void SetNUM_LIGHTS( bool i ) + { + m_nNUM_LIGHTS = i ? 1 : 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } +public: + treeleaf_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bDYNAMIC_LIGHT = false; +#endif // _DEBUG + m_nDYNAMIC_LIGHT = 0; +#ifdef _DEBUG + m_bSTATIC_LIGHT = false; +#endif // _DEBUG + m_nSTATIC_LIGHT = 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = false; +#endif // _DEBUG + m_nNUM_LIGHTS = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDYNAMIC_LIGHT && m_bSTATIC_LIGHT && m_bNUM_LIGHTS; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDYNAMIC_LIGHT ) + ( 2 * m_nSTATIC_LIGHT ) + ( 4 * m_nNUM_LIGHTS ) + 0; + } +}; +#define shaderDynamicTest_treeleaf_vs20 vsh_forgot_to_set_dynamic_DYNAMIC_LIGHT + vsh_forgot_to_set_dynamic_STATIC_LIGHT + vsh_forgot_to_set_dynamic_NUM_LIGHTS + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/unlitgeneric_maskbasebydetailalpha_ps11.inc b/materialsystem/stdshaders/fxctmp9_360/unlitgeneric_maskbasebydetailalpha_ps11.inc new file mode 100644 index 0000000..8b4279e --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/unlitgeneric_maskbasebydetailalpha_ps11.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class unlitgeneric_maskbasebydetailalpha_ps11_Static_Index +{ +public: + unlitgeneric_maskbasebydetailalpha_ps11_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_unlitgeneric_maskbasebydetailalpha_ps11 0 +class unlitgeneric_maskbasebydetailalpha_ps11_Dynamic_Index +{ +public: + unlitgeneric_maskbasebydetailalpha_ps11_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_unlitgeneric_maskbasebydetailalpha_ps11 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/unlitgeneric_notexture_ps11.inc b/materialsystem/stdshaders/fxctmp9_360/unlitgeneric_notexture_ps11.inc new file mode 100644 index 0000000..5a684db --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/unlitgeneric_notexture_ps11.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class unlitgeneric_notexture_ps11_Static_Index +{ +public: + unlitgeneric_notexture_ps11_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_unlitgeneric_notexture_ps11 0 +class unlitgeneric_notexture_ps11_Dynamic_Index +{ +public: + unlitgeneric_notexture_ps11_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_unlitgeneric_notexture_ps11 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/unlitgeneric_notexture_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/unlitgeneric_notexture_ps20.inc new file mode 100644 index 0000000..e489f34 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/unlitgeneric_notexture_ps20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class unlitgeneric_notexture_ps20_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + unlitgeneric_notexture_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_unlitgeneric_notexture_ps20 0 +class unlitgeneric_notexture_ps20_Dynamic_Index +{ +public: + unlitgeneric_notexture_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_unlitgeneric_notexture_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/unlitgeneric_notexture_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/unlitgeneric_notexture_ps20b.inc new file mode 100644 index 0000000..fe44f5b --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/unlitgeneric_notexture_ps20b.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class unlitgeneric_notexture_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + unlitgeneric_notexture_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_unlitgeneric_notexture_ps20b 0 +class unlitgeneric_notexture_ps20b_Dynamic_Index +{ +public: + unlitgeneric_notexture_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_unlitgeneric_notexture_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/unlitgeneric_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/unlitgeneric_ps20.inc new file mode 100644 index 0000000..5187a58 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/unlitgeneric_ps20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class unlitgeneric_ps20_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + unlitgeneric_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_unlitgeneric_ps20 0 +class unlitgeneric_ps20_Dynamic_Index +{ +public: + unlitgeneric_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_unlitgeneric_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/unlitgeneric_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/unlitgeneric_ps20b.inc new file mode 100644 index 0000000..abdfe9f --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/unlitgeneric_ps20b.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class unlitgeneric_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + unlitgeneric_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_unlitgeneric_ps20b 0 +class unlitgeneric_ps20b_Dynamic_Index +{ +public: + unlitgeneric_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_unlitgeneric_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/unlitgeneric_vs20.inc b/materialsystem/stdshaders/fxctmp9_360/unlitgeneric_vs20.inc new file mode 100644 index 0000000..3a47bc7 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/unlitgeneric_vs20.inc @@ -0,0 +1,110 @@ +#include "shaderlib/cshader.h" +class unlitgeneric_vs20_Static_Index +{ +public: + unlitgeneric_vs20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_unlitgeneric_vs20 0 +class unlitgeneric_vs20_Dynamic_Index +{ +private: + int m_nCOMPRESSED_VERTS; +#ifdef _DEBUG + bool m_bCOMPRESSED_VERTS; +#endif +public: + void SetCOMPRESSED_VERTS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOMPRESSED_VERTS = i; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } + void SetCOMPRESSED_VERTS( bool i ) + { + m_nCOMPRESSED_VERTS = i ? 1 : 0; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +public: + unlitgeneric_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = false; +#endif // _DEBUG + m_nCOMPRESSED_VERTS = 0; +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bCOMPRESSED_VERTS && m_bDOWATERFOG && m_bSKINNING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCOMPRESSED_VERTS ) + ( 2 * m_nDOWATERFOG ) + ( 4 * m_nSKINNING ) + 0; + } +}; +#define shaderDynamicTest_unlitgeneric_vs20 vsh_forgot_to_set_dynamic_COMPRESSED_VERTS + vsh_forgot_to_set_dynamic_DOWATERFOG + vsh_forgot_to_set_dynamic_SKINNING + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/unlittwotexture_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/unlittwotexture_ps20.inc new file mode 100644 index 0000000..6517157 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/unlittwotexture_ps20.inc @@ -0,0 +1,112 @@ +#include "shaderlib/cshader.h" +class unlittwotexture_ps20_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + unlittwotexture_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_unlittwotexture_ps20 0 +class unlittwotexture_ps20_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +private: + int m_nLIGHTING_PREVIEW; +#ifdef _DEBUG + bool m_bLIGHTING_PREVIEW; +#endif +public: + void SetLIGHTING_PREVIEW( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nLIGHTING_PREVIEW = i; +#ifdef _DEBUG + m_bLIGHTING_PREVIEW = true; +#endif + } + void SetLIGHTING_PREVIEW( bool i ) + { + m_nLIGHTING_PREVIEW = i ? 1 : 0; +#ifdef _DEBUG + m_bLIGHTING_PREVIEW = true; +#endif + } +public: + unlittwotexture_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; +#ifdef _DEBUG + m_bLIGHTING_PREVIEW = false; +#endif // _DEBUG + m_nLIGHTING_PREVIEW = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE && m_bLIGHTING_PREVIEW; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + ( 2 * m_nLIGHTING_PREVIEW ) + 0; + } +}; +#define shaderDynamicTest_unlittwotexture_ps20 psh_forgot_to_set_dynamic_PIXELFOGTYPE + psh_forgot_to_set_dynamic_LIGHTING_PREVIEW + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/unlittwotexture_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/unlittwotexture_ps20b.inc new file mode 100644 index 0000000..ea1c8f6 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/unlittwotexture_ps20b.inc @@ -0,0 +1,137 @@ +#include "shaderlib/cshader.h" +class unlittwotexture_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + unlittwotexture_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_unlittwotexture_ps20b 0 +class unlittwotexture_ps20b_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +private: + int m_nLIGHTING_PREVIEW; +#ifdef _DEBUG + bool m_bLIGHTING_PREVIEW; +#endif +public: + void SetLIGHTING_PREVIEW( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nLIGHTING_PREVIEW = i; +#ifdef _DEBUG + m_bLIGHTING_PREVIEW = true; +#endif + } + void SetLIGHTING_PREVIEW( bool i ) + { + m_nLIGHTING_PREVIEW = i ? 1 : 0; +#ifdef _DEBUG + m_bLIGHTING_PREVIEW = true; +#endif + } +private: + int m_nWRITE_DEPTH_TO_DESTALPHA; +#ifdef _DEBUG + bool m_bWRITE_DEPTH_TO_DESTALPHA; +#endif +public: + void SetWRITE_DEPTH_TO_DESTALPHA( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nWRITE_DEPTH_TO_DESTALPHA = i; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = true; +#endif + } + void SetWRITE_DEPTH_TO_DESTALPHA( bool i ) + { + m_nWRITE_DEPTH_TO_DESTALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = true; +#endif + } +public: + unlittwotexture_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; +#ifdef _DEBUG + m_bLIGHTING_PREVIEW = false; +#endif // _DEBUG + m_nLIGHTING_PREVIEW = 0; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = false; +#endif // _DEBUG + m_nWRITE_DEPTH_TO_DESTALPHA = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE && m_bLIGHTING_PREVIEW && m_bWRITE_DEPTH_TO_DESTALPHA; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + ( 2 * m_nLIGHTING_PREVIEW ) + ( 2 * m_nWRITE_DEPTH_TO_DESTALPHA ) + 0; + } +}; +#define shaderDynamicTest_unlittwotexture_ps20b psh_forgot_to_set_dynamic_PIXELFOGTYPE + psh_forgot_to_set_dynamic_LIGHTING_PREVIEW + psh_forgot_to_set_dynamic_WRITE_DEPTH_TO_DESTALPHA + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/unlittwotexture_vs20.inc b/materialsystem/stdshaders/fxctmp9_360/unlittwotexture_vs20.inc new file mode 100644 index 0000000..a0da040 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/unlittwotexture_vs20.inc @@ -0,0 +1,110 @@ +#include "shaderlib/cshader.h" +class unlittwotexture_vs20_Static_Index +{ +public: + unlittwotexture_vs20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_unlittwotexture_vs20 0 +class unlittwotexture_vs20_Dynamic_Index +{ +private: + int m_nCOMPRESSED_VERTS; +#ifdef _DEBUG + bool m_bCOMPRESSED_VERTS; +#endif +public: + void SetCOMPRESSED_VERTS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOMPRESSED_VERTS = i; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } + void SetCOMPRESSED_VERTS( bool i ) + { + m_nCOMPRESSED_VERTS = i ? 1 : 0; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +public: + unlittwotexture_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = false; +#endif // _DEBUG + m_nCOMPRESSED_VERTS = 0; +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bCOMPRESSED_VERTS && m_bDOWATERFOG && m_bSKINNING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCOMPRESSED_VERTS ) + ( 2 * m_nDOWATERFOG ) + ( 4 * m_nSKINNING ) + 0; + } +}; +#define shaderDynamicTest_unlittwotexture_vs20 vsh_forgot_to_set_dynamic_COMPRESSED_VERTS + vsh_forgot_to_set_dynamic_DOWATERFOG + vsh_forgot_to_set_dynamic_SKINNING + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/vertexlit_and_unlit_generic_bump_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/vertexlit_and_unlit_generic_bump_ps20.inc new file mode 100644 index 0000000..6d18282 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/vertexlit_and_unlit_generic_bump_ps20.inc @@ -0,0 +1,412 @@ +#include "shaderlib/cshader.h" +class vertexlit_and_unlit_generic_bump_ps20_Static_Index +{ +private: + int m_nCUBEMAP; +#ifdef _DEBUG + bool m_bCUBEMAP; +#endif +public: + void SetCUBEMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCUBEMAP = i; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } + void SetCUBEMAP( bool i ) + { + m_nCUBEMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } +private: + int m_nDIFFUSELIGHTING; +#ifdef _DEBUG + bool m_bDIFFUSELIGHTING; +#endif +public: + void SetDIFFUSELIGHTING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDIFFUSELIGHTING = i; +#ifdef _DEBUG + m_bDIFFUSELIGHTING = true; +#endif + } + void SetDIFFUSELIGHTING( bool i ) + { + m_nDIFFUSELIGHTING = i ? 1 : 0; +#ifdef _DEBUG + m_bDIFFUSELIGHTING = true; +#endif + } +private: + int m_nLIGHTWARPTEXTURE; +#ifdef _DEBUG + bool m_bLIGHTWARPTEXTURE; +#endif +public: + void SetLIGHTWARPTEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nLIGHTWARPTEXTURE = i; +#ifdef _DEBUG + m_bLIGHTWARPTEXTURE = true; +#endif + } + void SetLIGHTWARPTEXTURE( bool i ) + { + m_nLIGHTWARPTEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bLIGHTWARPTEXTURE = true; +#endif + } +private: + int m_nSELFILLUM; +#ifdef _DEBUG + bool m_bSELFILLUM; +#endif +public: + void SetSELFILLUM( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSELFILLUM = i; +#ifdef _DEBUG + m_bSELFILLUM = true; +#endif + } + void SetSELFILLUM( bool i ) + { + m_nSELFILLUM = i ? 1 : 0; +#ifdef _DEBUG + m_bSELFILLUM = true; +#endif + } +private: + int m_nSELFILLUMFRESNEL; +#ifdef _DEBUG + bool m_bSELFILLUMFRESNEL; +#endif +public: + void SetSELFILLUMFRESNEL( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSELFILLUMFRESNEL = i; +#ifdef _DEBUG + m_bSELFILLUMFRESNEL = true; +#endif + } + void SetSELFILLUMFRESNEL( bool i ) + { + m_nSELFILLUMFRESNEL = i ? 1 : 0; +#ifdef _DEBUG + m_bSELFILLUMFRESNEL = true; +#endif + } +private: + int m_nNORMALMAPALPHAENVMAPMASK; +#ifdef _DEBUG + bool m_bNORMALMAPALPHAENVMAPMASK; +#endif +public: + void SetNORMALMAPALPHAENVMAPMASK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nNORMALMAPALPHAENVMAPMASK = i; +#ifdef _DEBUG + m_bNORMALMAPALPHAENVMAPMASK = true; +#endif + } + void SetNORMALMAPALPHAENVMAPMASK( bool i ) + { + m_nNORMALMAPALPHAENVMAPMASK = i ? 1 : 0; +#ifdef _DEBUG + m_bNORMALMAPALPHAENVMAPMASK = true; +#endif + } +private: + int m_nHALFLAMBERT; +#ifdef _DEBUG + bool m_bHALFLAMBERT; +#endif +public: + void SetHALFLAMBERT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHALFLAMBERT = i; +#ifdef _DEBUG + m_bHALFLAMBERT = true; +#endif + } + void SetHALFLAMBERT( bool i ) + { + m_nHALFLAMBERT = i ? 1 : 0; +#ifdef _DEBUG + m_bHALFLAMBERT = true; +#endif + } +private: + int m_nFLASHLIGHT; +#ifdef _DEBUG + bool m_bFLASHLIGHT; +#endif +public: + void SetFLASHLIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFLASHLIGHT = i; +#ifdef _DEBUG + m_bFLASHLIGHT = true; +#endif + } + void SetFLASHLIGHT( bool i ) + { + m_nFLASHLIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bFLASHLIGHT = true; +#endif + } +private: + int m_nDETAILTEXTURE; +#ifdef _DEBUG + bool m_bDETAILTEXTURE; +#endif +public: + void SetDETAILTEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDETAILTEXTURE = i; +#ifdef _DEBUG + m_bDETAILTEXTURE = true; +#endif + } + void SetDETAILTEXTURE( bool i ) + { + m_nDETAILTEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bDETAILTEXTURE = true; +#endif + } +private: + int m_nDETAIL_BLEND_MODE; +#ifdef _DEBUG + bool m_bDETAIL_BLEND_MODE; +#endif +public: + void SetDETAIL_BLEND_MODE( int i ) + { + Assert( i >= 0 && i <= 6 ); + m_nDETAIL_BLEND_MODE = i; +#ifdef _DEBUG + m_bDETAIL_BLEND_MODE = true; +#endif + } + void SetDETAIL_BLEND_MODE( bool i ) + { + m_nDETAIL_BLEND_MODE = i ? 1 : 0; +#ifdef _DEBUG + m_bDETAIL_BLEND_MODE = true; +#endif + } +private: + int m_nBLENDTINTBYBASEALPHA; +#ifdef _DEBUG + bool m_bBLENDTINTBYBASEALPHA; +#endif +public: + void SetBLENDTINTBYBASEALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBLENDTINTBYBASEALPHA = i; +#ifdef _DEBUG + m_bBLENDTINTBYBASEALPHA = true; +#endif + } + void SetBLENDTINTBYBASEALPHA( bool i ) + { + m_nBLENDTINTBYBASEALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bBLENDTINTBYBASEALPHA = true; +#endif + } +public: + vertexlit_and_unlit_generic_bump_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCUBEMAP = false; +#endif // _DEBUG + m_nCUBEMAP = 0; +#ifdef _DEBUG + m_bDIFFUSELIGHTING = false; +#endif // _DEBUG + m_nDIFFUSELIGHTING = 0; +#ifdef _DEBUG + m_bLIGHTWARPTEXTURE = false; +#endif // _DEBUG + m_nLIGHTWARPTEXTURE = 0; +#ifdef _DEBUG + m_bSELFILLUM = false; +#endif // _DEBUG + m_nSELFILLUM = 0; +#ifdef _DEBUG + m_bSELFILLUMFRESNEL = false; +#endif // _DEBUG + m_nSELFILLUMFRESNEL = 0; +#ifdef _DEBUG + m_bNORMALMAPALPHAENVMAPMASK = false; +#endif // _DEBUG + m_nNORMALMAPALPHAENVMAPMASK = 0; +#ifdef _DEBUG + m_bHALFLAMBERT = false; +#endif // _DEBUG + m_nHALFLAMBERT = 0; +#ifdef _DEBUG + m_bFLASHLIGHT = false; +#endif // _DEBUG + m_nFLASHLIGHT = 0; +#ifdef _DEBUG + m_bDETAILTEXTURE = false; +#endif // _DEBUG + m_nDETAILTEXTURE = 0; +#ifdef _DEBUG + m_bDETAIL_BLEND_MODE = false; +#endif // _DEBUG + m_nDETAIL_BLEND_MODE = 0; +#ifdef _DEBUG + m_bBLENDTINTBYBASEALPHA = false; +#endif // _DEBUG + m_nBLENDTINTBYBASEALPHA = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCUBEMAP && m_bDIFFUSELIGHTING && m_bLIGHTWARPTEXTURE && m_bSELFILLUM && m_bSELFILLUMFRESNEL && m_bNORMALMAPALPHAENVMAPMASK && m_bHALFLAMBERT && m_bFLASHLIGHT && m_bDETAILTEXTURE && m_bDETAIL_BLEND_MODE && m_bBLENDTINTBYBASEALPHA; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 24 * m_nCUBEMAP ) + ( 48 * m_nDIFFUSELIGHTING ) + ( 96 * m_nLIGHTWARPTEXTURE ) + ( 192 * m_nSELFILLUM ) + ( 384 * m_nSELFILLUMFRESNEL ) + ( 768 * m_nNORMALMAPALPHAENVMAPMASK ) + ( 1536 * m_nHALFLAMBERT ) + ( 3072 * m_nFLASHLIGHT ) + ( 6144 * m_nDETAILTEXTURE ) + ( 12288 * m_nDETAIL_BLEND_MODE ) + ( 86016 * m_nBLENDTINTBYBASEALPHA ) + 0; + } +}; +#define shaderStaticTest_vertexlit_and_unlit_generic_bump_ps20 psh_forgot_to_set_static_CUBEMAP + psh_forgot_to_set_static_DIFFUSELIGHTING + psh_forgot_to_set_static_LIGHTWARPTEXTURE + psh_forgot_to_set_static_SELFILLUM + psh_forgot_to_set_static_SELFILLUMFRESNEL + psh_forgot_to_set_static_NORMALMAPALPHAENVMAPMASK + psh_forgot_to_set_static_HALFLAMBERT + psh_forgot_to_set_static_FLASHLIGHT + psh_forgot_to_set_static_DETAILTEXTURE + psh_forgot_to_set_static_DETAIL_BLEND_MODE + psh_forgot_to_set_static_BLENDTINTBYBASEALPHA + 0 +class vertexlit_and_unlit_generic_bump_ps20_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +private: + int m_nWRITEWATERFOGTODESTALPHA; +#ifdef _DEBUG + bool m_bWRITEWATERFOGTODESTALPHA; +#endif +public: + void SetWRITEWATERFOGTODESTALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nWRITEWATERFOGTODESTALPHA = i; +#ifdef _DEBUG + m_bWRITEWATERFOGTODESTALPHA = true; +#endif + } + void SetWRITEWATERFOGTODESTALPHA( bool i ) + { + m_nWRITEWATERFOGTODESTALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bWRITEWATERFOGTODESTALPHA = true; +#endif + } +private: + int m_nNUM_LIGHTS; +#ifdef _DEBUG + bool m_bNUM_LIGHTS; +#endif +public: + void SetNUM_LIGHTS( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nNUM_LIGHTS = i; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } + void SetNUM_LIGHTS( bool i ) + { + m_nNUM_LIGHTS = i ? 1 : 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } +private: + int m_nAMBIENT_LIGHT; +#ifdef _DEBUG + bool m_bAMBIENT_LIGHT; +#endif +public: + void SetAMBIENT_LIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nAMBIENT_LIGHT = i; +#ifdef _DEBUG + m_bAMBIENT_LIGHT = true; +#endif + } + void SetAMBIENT_LIGHT( bool i ) + { + m_nAMBIENT_LIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bAMBIENT_LIGHT = true; +#endif + } +public: + vertexlit_and_unlit_generic_bump_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; +#ifdef _DEBUG + m_bWRITEWATERFOGTODESTALPHA = false; +#endif // _DEBUG + m_nWRITEWATERFOGTODESTALPHA = 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = false; +#endif // _DEBUG + m_nNUM_LIGHTS = 0; +#ifdef _DEBUG + m_bAMBIENT_LIGHT = false; +#endif // _DEBUG + m_nAMBIENT_LIGHT = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE && m_bWRITEWATERFOGTODESTALPHA && m_bNUM_LIGHTS && m_bAMBIENT_LIGHT; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + ( 2 * m_nWRITEWATERFOGTODESTALPHA ) + ( 4 * m_nNUM_LIGHTS ) + ( 12 * m_nAMBIENT_LIGHT ) + 0; + } +}; +#define shaderDynamicTest_vertexlit_and_unlit_generic_bump_ps20 psh_forgot_to_set_dynamic_PIXELFOGTYPE + psh_forgot_to_set_dynamic_WRITEWATERFOGTODESTALPHA + psh_forgot_to_set_dynamic_NUM_LIGHTS + psh_forgot_to_set_dynamic_AMBIENT_LIGHT + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/vertexlit_and_unlit_generic_bump_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/vertexlit_and_unlit_generic_bump_ps20b.inc new file mode 100644 index 0000000..230354d --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/vertexlit_and_unlit_generic_bump_ps20b.inc @@ -0,0 +1,412 @@ +#include "shaderlib/cshader.h" +class vertexlit_and_unlit_generic_bump_ps20b_Static_Index +{ +private: + int m_nCUBEMAP; +#ifdef _DEBUG + bool m_bCUBEMAP; +#endif +public: + void SetCUBEMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCUBEMAP = i; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } + void SetCUBEMAP( bool i ) + { + m_nCUBEMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } +private: + int m_nDIFFUSELIGHTING; +#ifdef _DEBUG + bool m_bDIFFUSELIGHTING; +#endif +public: + void SetDIFFUSELIGHTING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDIFFUSELIGHTING = i; +#ifdef _DEBUG + m_bDIFFUSELIGHTING = true; +#endif + } + void SetDIFFUSELIGHTING( bool i ) + { + m_nDIFFUSELIGHTING = i ? 1 : 0; +#ifdef _DEBUG + m_bDIFFUSELIGHTING = true; +#endif + } +private: + int m_nLIGHTWARPTEXTURE; +#ifdef _DEBUG + bool m_bLIGHTWARPTEXTURE; +#endif +public: + void SetLIGHTWARPTEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nLIGHTWARPTEXTURE = i; +#ifdef _DEBUG + m_bLIGHTWARPTEXTURE = true; +#endif + } + void SetLIGHTWARPTEXTURE( bool i ) + { + m_nLIGHTWARPTEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bLIGHTWARPTEXTURE = true; +#endif + } +private: + int m_nSELFILLUM; +#ifdef _DEBUG + bool m_bSELFILLUM; +#endif +public: + void SetSELFILLUM( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSELFILLUM = i; +#ifdef _DEBUG + m_bSELFILLUM = true; +#endif + } + void SetSELFILLUM( bool i ) + { + m_nSELFILLUM = i ? 1 : 0; +#ifdef _DEBUG + m_bSELFILLUM = true; +#endif + } +private: + int m_nSELFILLUMFRESNEL; +#ifdef _DEBUG + bool m_bSELFILLUMFRESNEL; +#endif +public: + void SetSELFILLUMFRESNEL( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSELFILLUMFRESNEL = i; +#ifdef _DEBUG + m_bSELFILLUMFRESNEL = true; +#endif + } + void SetSELFILLUMFRESNEL( bool i ) + { + m_nSELFILLUMFRESNEL = i ? 1 : 0; +#ifdef _DEBUG + m_bSELFILLUMFRESNEL = true; +#endif + } +private: + int m_nNORMALMAPALPHAENVMAPMASK; +#ifdef _DEBUG + bool m_bNORMALMAPALPHAENVMAPMASK; +#endif +public: + void SetNORMALMAPALPHAENVMAPMASK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nNORMALMAPALPHAENVMAPMASK = i; +#ifdef _DEBUG + m_bNORMALMAPALPHAENVMAPMASK = true; +#endif + } + void SetNORMALMAPALPHAENVMAPMASK( bool i ) + { + m_nNORMALMAPALPHAENVMAPMASK = i ? 1 : 0; +#ifdef _DEBUG + m_bNORMALMAPALPHAENVMAPMASK = true; +#endif + } +private: + int m_nHALFLAMBERT; +#ifdef _DEBUG + bool m_bHALFLAMBERT; +#endif +public: + void SetHALFLAMBERT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHALFLAMBERT = i; +#ifdef _DEBUG + m_bHALFLAMBERT = true; +#endif + } + void SetHALFLAMBERT( bool i ) + { + m_nHALFLAMBERT = i ? 1 : 0; +#ifdef _DEBUG + m_bHALFLAMBERT = true; +#endif + } +private: + int m_nFLASHLIGHT; +#ifdef _DEBUG + bool m_bFLASHLIGHT; +#endif +public: + void SetFLASHLIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFLASHLIGHT = i; +#ifdef _DEBUG + m_bFLASHLIGHT = true; +#endif + } + void SetFLASHLIGHT( bool i ) + { + m_nFLASHLIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bFLASHLIGHT = true; +#endif + } +private: + int m_nDETAILTEXTURE; +#ifdef _DEBUG + bool m_bDETAILTEXTURE; +#endif +public: + void SetDETAILTEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDETAILTEXTURE = i; +#ifdef _DEBUG + m_bDETAILTEXTURE = true; +#endif + } + void SetDETAILTEXTURE( bool i ) + { + m_nDETAILTEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bDETAILTEXTURE = true; +#endif + } +private: + int m_nDETAIL_BLEND_MODE; +#ifdef _DEBUG + bool m_bDETAIL_BLEND_MODE; +#endif +public: + void SetDETAIL_BLEND_MODE( int i ) + { + Assert( i >= 0 && i <= 6 ); + m_nDETAIL_BLEND_MODE = i; +#ifdef _DEBUG + m_bDETAIL_BLEND_MODE = true; +#endif + } + void SetDETAIL_BLEND_MODE( bool i ) + { + m_nDETAIL_BLEND_MODE = i ? 1 : 0; +#ifdef _DEBUG + m_bDETAIL_BLEND_MODE = true; +#endif + } +private: + int m_nFLASHLIGHTDEPTHFILTERMODE; +#ifdef _DEBUG + bool m_bFLASHLIGHTDEPTHFILTERMODE; +#endif +public: + void SetFLASHLIGHTDEPTHFILTERMODE( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nFLASHLIGHTDEPTHFILTERMODE = i; +#ifdef _DEBUG + m_bFLASHLIGHTDEPTHFILTERMODE = true; +#endif + } + void SetFLASHLIGHTDEPTHFILTERMODE( bool i ) + { + m_nFLASHLIGHTDEPTHFILTERMODE = i ? 1 : 0; +#ifdef _DEBUG + m_bFLASHLIGHTDEPTHFILTERMODE = true; +#endif + } +private: + int m_nBLENDTINTBYBASEALPHA; +#ifdef _DEBUG + bool m_bBLENDTINTBYBASEALPHA; +#endif +public: + void SetBLENDTINTBYBASEALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBLENDTINTBYBASEALPHA = i; +#ifdef _DEBUG + m_bBLENDTINTBYBASEALPHA = true; +#endif + } + void SetBLENDTINTBYBASEALPHA( bool i ) + { + m_nBLENDTINTBYBASEALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bBLENDTINTBYBASEALPHA = true; +#endif + } +public: + vertexlit_and_unlit_generic_bump_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCUBEMAP = false; +#endif // _DEBUG + m_nCUBEMAP = 0; +#ifdef _DEBUG + m_bDIFFUSELIGHTING = false; +#endif // _DEBUG + m_nDIFFUSELIGHTING = 0; +#ifdef _DEBUG + m_bLIGHTWARPTEXTURE = false; +#endif // _DEBUG + m_nLIGHTWARPTEXTURE = 0; +#ifdef _DEBUG + m_bSELFILLUM = false; +#endif // _DEBUG + m_nSELFILLUM = 0; +#ifdef _DEBUG + m_bSELFILLUMFRESNEL = false; +#endif // _DEBUG + m_nSELFILLUMFRESNEL = 0; +#ifdef _DEBUG + m_bNORMALMAPALPHAENVMAPMASK = false; +#endif // _DEBUG + m_nNORMALMAPALPHAENVMAPMASK = 0; +#ifdef _DEBUG + m_bHALFLAMBERT = false; +#endif // _DEBUG + m_nHALFLAMBERT = 0; +#ifdef _DEBUG + m_bFLASHLIGHT = false; +#endif // _DEBUG + m_nFLASHLIGHT = 0; +#ifdef _DEBUG + m_bDETAILTEXTURE = false; +#endif // _DEBUG + m_nDETAILTEXTURE = 0; +#ifdef _DEBUG + m_bDETAIL_BLEND_MODE = false; +#endif // _DEBUG + m_nDETAIL_BLEND_MODE = 0; +#ifdef _DEBUG + m_bFLASHLIGHTDEPTHFILTERMODE = false; +#endif // _DEBUG + m_nFLASHLIGHTDEPTHFILTERMODE = 0; +#ifdef _DEBUG + m_bBLENDTINTBYBASEALPHA = false; +#endif // _DEBUG + m_nBLENDTINTBYBASEALPHA = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCUBEMAP && m_bDIFFUSELIGHTING && m_bLIGHTWARPTEXTURE && m_bSELFILLUM && m_bSELFILLUMFRESNEL && m_bNORMALMAPALPHAENVMAPMASK && m_bHALFLAMBERT && m_bFLASHLIGHT && m_bDETAILTEXTURE && m_bDETAIL_BLEND_MODE && m_bFLASHLIGHTDEPTHFILTERMODE && m_bBLENDTINTBYBASEALPHA; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 20 * m_nCUBEMAP ) + ( 40 * m_nDIFFUSELIGHTING ) + ( 80 * m_nLIGHTWARPTEXTURE ) + ( 160 * m_nSELFILLUM ) + ( 320 * m_nSELFILLUMFRESNEL ) + ( 640 * m_nNORMALMAPALPHAENVMAPMASK ) + ( 1280 * m_nHALFLAMBERT ) + ( 2560 * m_nFLASHLIGHT ) + ( 5120 * m_nDETAILTEXTURE ) + ( 10240 * m_nDETAIL_BLEND_MODE ) + ( 71680 * m_nFLASHLIGHTDEPTHFILTERMODE ) + ( 71680 * m_nBLENDTINTBYBASEALPHA ) + 0; + } +}; +#define shaderStaticTest_vertexlit_and_unlit_generic_bump_ps20b psh_forgot_to_set_static_CUBEMAP + psh_forgot_to_set_static_DIFFUSELIGHTING + psh_forgot_to_set_static_LIGHTWARPTEXTURE + psh_forgot_to_set_static_SELFILLUM + psh_forgot_to_set_static_SELFILLUMFRESNEL + psh_forgot_to_set_static_NORMALMAPALPHAENVMAPMASK + psh_forgot_to_set_static_HALFLAMBERT + psh_forgot_to_set_static_FLASHLIGHT + psh_forgot_to_set_static_DETAILTEXTURE + psh_forgot_to_set_static_DETAIL_BLEND_MODE + psh_forgot_to_set_static_FLASHLIGHTDEPTHFILTERMODE + psh_forgot_to_set_static_BLENDTINTBYBASEALPHA + 0 +class vertexlit_and_unlit_generic_bump_ps20b_Dynamic_Index +{ +private: + int m_nNUM_LIGHTS; +#ifdef _DEBUG + bool m_bNUM_LIGHTS; +#endif +public: + void SetNUM_LIGHTS( int i ) + { + Assert( i >= 0 && i <= 4 ); + m_nNUM_LIGHTS = i; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } + void SetNUM_LIGHTS( bool i ) + { + m_nNUM_LIGHTS = i ? 1 : 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } +private: + int m_nAMBIENT_LIGHT; +#ifdef _DEBUG + bool m_bAMBIENT_LIGHT; +#endif +public: + void SetAMBIENT_LIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nAMBIENT_LIGHT = i; +#ifdef _DEBUG + m_bAMBIENT_LIGHT = true; +#endif + } + void SetAMBIENT_LIGHT( bool i ) + { + m_nAMBIENT_LIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bAMBIENT_LIGHT = true; +#endif + } +private: + int m_nFLASHLIGHTSHADOWS; +#ifdef _DEBUG + bool m_bFLASHLIGHTSHADOWS; +#endif +public: + void SetFLASHLIGHTSHADOWS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFLASHLIGHTSHADOWS = i; +#ifdef _DEBUG + m_bFLASHLIGHTSHADOWS = true; +#endif + } + void SetFLASHLIGHTSHADOWS( bool i ) + { + m_nFLASHLIGHTSHADOWS = i ? 1 : 0; +#ifdef _DEBUG + m_bFLASHLIGHTSHADOWS = true; +#endif + } +public: + vertexlit_and_unlit_generic_bump_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bNUM_LIGHTS = false; +#endif // _DEBUG + m_nNUM_LIGHTS = 0; +#ifdef _DEBUG + m_bAMBIENT_LIGHT = false; +#endif // _DEBUG + m_nAMBIENT_LIGHT = 0; +#ifdef _DEBUG + m_bFLASHLIGHTSHADOWS = false; +#endif // _DEBUG + m_nFLASHLIGHTSHADOWS = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bNUM_LIGHTS && m_bAMBIENT_LIGHT && m_bFLASHLIGHTSHADOWS; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nNUM_LIGHTS ) + ( 5 * m_nAMBIENT_LIGHT ) + ( 10 * m_nFLASHLIGHTSHADOWS ) + 0; + } +}; +#define shaderDynamicTest_vertexlit_and_unlit_generic_bump_ps20b psh_forgot_to_set_dynamic_NUM_LIGHTS + psh_forgot_to_set_dynamic_AMBIENT_LIGHT + psh_forgot_to_set_dynamic_FLASHLIGHTSHADOWS + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/vertexlit_and_unlit_generic_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/vertexlit_and_unlit_generic_ps20.inc new file mode 100644 index 0000000..137ea60 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/vertexlit_and_unlit_generic_ps20.inc @@ -0,0 +1,537 @@ +#include "shaderlib/cshader.h" +class vertexlit_and_unlit_generic_ps20_Static_Index +{ +private: + int m_nDETAILTEXTURE; +#ifdef _DEBUG + bool m_bDETAILTEXTURE; +#endif +public: + void SetDETAILTEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDETAILTEXTURE = i; +#ifdef _DEBUG + m_bDETAILTEXTURE = true; +#endif + } + void SetDETAILTEXTURE( bool i ) + { + m_nDETAILTEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bDETAILTEXTURE = true; +#endif + } +private: + int m_nCUBEMAP; +#ifdef _DEBUG + bool m_bCUBEMAP; +#endif +public: + void SetCUBEMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCUBEMAP = i; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } + void SetCUBEMAP( bool i ) + { + m_nCUBEMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } +private: + int m_nDIFFUSELIGHTING; +#ifdef _DEBUG + bool m_bDIFFUSELIGHTING; +#endif +public: + void SetDIFFUSELIGHTING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDIFFUSELIGHTING = i; +#ifdef _DEBUG + m_bDIFFUSELIGHTING = true; +#endif + } + void SetDIFFUSELIGHTING( bool i ) + { + m_nDIFFUSELIGHTING = i ? 1 : 0; +#ifdef _DEBUG + m_bDIFFUSELIGHTING = true; +#endif + } +private: + int m_nENVMAPMASK; +#ifdef _DEBUG + bool m_bENVMAPMASK; +#endif +public: + void SetENVMAPMASK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nENVMAPMASK = i; +#ifdef _DEBUG + m_bENVMAPMASK = true; +#endif + } + void SetENVMAPMASK( bool i ) + { + m_nENVMAPMASK = i ? 1 : 0; +#ifdef _DEBUG + m_bENVMAPMASK = true; +#endif + } +private: + int m_nBASEALPHAENVMAPMASK; +#ifdef _DEBUG + bool m_bBASEALPHAENVMAPMASK; +#endif +public: + void SetBASEALPHAENVMAPMASK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBASEALPHAENVMAPMASK = i; +#ifdef _DEBUG + m_bBASEALPHAENVMAPMASK = true; +#endif + } + void SetBASEALPHAENVMAPMASK( bool i ) + { + m_nBASEALPHAENVMAPMASK = i ? 1 : 0; +#ifdef _DEBUG + m_bBASEALPHAENVMAPMASK = true; +#endif + } +private: + int m_nSELFILLUM; +#ifdef _DEBUG + bool m_bSELFILLUM; +#endif +public: + void SetSELFILLUM( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSELFILLUM = i; +#ifdef _DEBUG + m_bSELFILLUM = true; +#endif + } + void SetSELFILLUM( bool i ) + { + m_nSELFILLUM = i ? 1 : 0; +#ifdef _DEBUG + m_bSELFILLUM = true; +#endif + } +private: + int m_nVERTEXCOLOR; +#ifdef _DEBUG + bool m_bVERTEXCOLOR; +#endif +public: + void SetVERTEXCOLOR( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nVERTEXCOLOR = i; +#ifdef _DEBUG + m_bVERTEXCOLOR = true; +#endif + } + void SetVERTEXCOLOR( bool i ) + { + m_nVERTEXCOLOR = i ? 1 : 0; +#ifdef _DEBUG + m_bVERTEXCOLOR = true; +#endif + } +private: + int m_nFLASHLIGHT; +#ifdef _DEBUG + bool m_bFLASHLIGHT; +#endif +public: + void SetFLASHLIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFLASHLIGHT = i; +#ifdef _DEBUG + m_bFLASHLIGHT = true; +#endif + } + void SetFLASHLIGHT( bool i ) + { + m_nFLASHLIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bFLASHLIGHT = true; +#endif + } +private: + int m_nSELFILLUM_ENVMAPMASK_ALPHA; +#ifdef _DEBUG + bool m_bSELFILLUM_ENVMAPMASK_ALPHA; +#endif +public: + void SetSELFILLUM_ENVMAPMASK_ALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSELFILLUM_ENVMAPMASK_ALPHA = i; +#ifdef _DEBUG + m_bSELFILLUM_ENVMAPMASK_ALPHA = true; +#endif + } + void SetSELFILLUM_ENVMAPMASK_ALPHA( bool i ) + { + m_nSELFILLUM_ENVMAPMASK_ALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bSELFILLUM_ENVMAPMASK_ALPHA = true; +#endif + } +private: + int m_nDETAIL_BLEND_MODE; +#ifdef _DEBUG + bool m_bDETAIL_BLEND_MODE; +#endif +public: + void SetDETAIL_BLEND_MODE( int i ) + { + Assert( i >= 0 && i <= 9 ); + m_nDETAIL_BLEND_MODE = i; +#ifdef _DEBUG + m_bDETAIL_BLEND_MODE = true; +#endif + } + void SetDETAIL_BLEND_MODE( bool i ) + { + m_nDETAIL_BLEND_MODE = i ? 1 : 0; +#ifdef _DEBUG + m_bDETAIL_BLEND_MODE = true; +#endif + } +private: + int m_nSEAMLESS_BASE; +#ifdef _DEBUG + bool m_bSEAMLESS_BASE; +#endif +public: + void SetSEAMLESS_BASE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSEAMLESS_BASE = i; +#ifdef _DEBUG + m_bSEAMLESS_BASE = true; +#endif + } + void SetSEAMLESS_BASE( bool i ) + { + m_nSEAMLESS_BASE = i ? 1 : 0; +#ifdef _DEBUG + m_bSEAMLESS_BASE = true; +#endif + } +private: + int m_nSEAMLESS_DETAIL; +#ifdef _DEBUG + bool m_bSEAMLESS_DETAIL; +#endif +public: + void SetSEAMLESS_DETAIL( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSEAMLESS_DETAIL = i; +#ifdef _DEBUG + m_bSEAMLESS_DETAIL = true; +#endif + } + void SetSEAMLESS_DETAIL( bool i ) + { + m_nSEAMLESS_DETAIL = i ? 1 : 0; +#ifdef _DEBUG + m_bSEAMLESS_DETAIL = true; +#endif + } +private: + int m_nDISTANCEALPHA; +#ifdef _DEBUG + bool m_bDISTANCEALPHA; +#endif +public: + void SetDISTANCEALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDISTANCEALPHA = i; +#ifdef _DEBUG + m_bDISTANCEALPHA = true; +#endif + } + void SetDISTANCEALPHA( bool i ) + { + m_nDISTANCEALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bDISTANCEALPHA = true; +#endif + } +private: + int m_nDISTANCEALPHAFROMDETAIL; +#ifdef _DEBUG + bool m_bDISTANCEALPHAFROMDETAIL; +#endif +public: + void SetDISTANCEALPHAFROMDETAIL( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDISTANCEALPHAFROMDETAIL = i; +#ifdef _DEBUG + m_bDISTANCEALPHAFROMDETAIL = true; +#endif + } + void SetDISTANCEALPHAFROMDETAIL( bool i ) + { + m_nDISTANCEALPHAFROMDETAIL = i ? 1 : 0; +#ifdef _DEBUG + m_bDISTANCEALPHAFROMDETAIL = true; +#endif + } +private: + int m_nSOFT_MASK; +#ifdef _DEBUG + bool m_bSOFT_MASK; +#endif +public: + void SetSOFT_MASK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSOFT_MASK = i; +#ifdef _DEBUG + m_bSOFT_MASK = true; +#endif + } + void SetSOFT_MASK( bool i ) + { + m_nSOFT_MASK = i ? 1 : 0; +#ifdef _DEBUG + m_bSOFT_MASK = true; +#endif + } +private: + int m_nOUTLINE; +#ifdef _DEBUG + bool m_bOUTLINE; +#endif +public: + void SetOUTLINE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nOUTLINE = i; +#ifdef _DEBUG + m_bOUTLINE = true; +#endif + } + void SetOUTLINE( bool i ) + { + m_nOUTLINE = i ? 1 : 0; +#ifdef _DEBUG + m_bOUTLINE = true; +#endif + } +private: + int m_nOUTER_GLOW; +#ifdef _DEBUG + bool m_bOUTER_GLOW; +#endif +public: + void SetOUTER_GLOW( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nOUTER_GLOW = i; +#ifdef _DEBUG + m_bOUTER_GLOW = true; +#endif + } + void SetOUTER_GLOW( bool i ) + { + m_nOUTER_GLOW = i ? 1 : 0; +#ifdef _DEBUG + m_bOUTER_GLOW = true; +#endif + } +private: + int m_nBLENDTINTBYBASEALPHA; +#ifdef _DEBUG + bool m_bBLENDTINTBYBASEALPHA; +#endif +public: + void SetBLENDTINTBYBASEALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBLENDTINTBYBASEALPHA = i; +#ifdef _DEBUG + m_bBLENDTINTBYBASEALPHA = true; +#endif + } + void SetBLENDTINTBYBASEALPHA( bool i ) + { + m_nBLENDTINTBYBASEALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bBLENDTINTBYBASEALPHA = true; +#endif + } +public: + vertexlit_and_unlit_generic_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bDETAILTEXTURE = false; +#endif // _DEBUG + m_nDETAILTEXTURE = 0; +#ifdef _DEBUG + m_bCUBEMAP = false; +#endif // _DEBUG + m_nCUBEMAP = 0; +#ifdef _DEBUG + m_bDIFFUSELIGHTING = false; +#endif // _DEBUG + m_nDIFFUSELIGHTING = 0; +#ifdef _DEBUG + m_bENVMAPMASK = false; +#endif // _DEBUG + m_nENVMAPMASK = 0; +#ifdef _DEBUG + m_bBASEALPHAENVMAPMASK = false; +#endif // _DEBUG + m_nBASEALPHAENVMAPMASK = 0; +#ifdef _DEBUG + m_bSELFILLUM = false; +#endif // _DEBUG + m_nSELFILLUM = 0; +#ifdef _DEBUG + m_bVERTEXCOLOR = false; +#endif // _DEBUG + m_nVERTEXCOLOR = 0; +#ifdef _DEBUG + m_bFLASHLIGHT = false; +#endif // _DEBUG + m_nFLASHLIGHT = 0; +#ifdef _DEBUG + m_bSELFILLUM_ENVMAPMASK_ALPHA = false; +#endif // _DEBUG + m_nSELFILLUM_ENVMAPMASK_ALPHA = 0; +#ifdef _DEBUG + m_bDETAIL_BLEND_MODE = false; +#endif // _DEBUG + m_nDETAIL_BLEND_MODE = 0; +#ifdef _DEBUG + m_bSEAMLESS_BASE = false; +#endif // _DEBUG + m_nSEAMLESS_BASE = 0; +#ifdef _DEBUG + m_bSEAMLESS_DETAIL = false; +#endif // _DEBUG + m_nSEAMLESS_DETAIL = 0; +#ifdef _DEBUG + m_bDISTANCEALPHA = false; +#endif // _DEBUG + m_nDISTANCEALPHA = 0; +#ifdef _DEBUG + m_bDISTANCEALPHAFROMDETAIL = false; +#endif // _DEBUG + m_nDISTANCEALPHAFROMDETAIL = 0; +#ifdef _DEBUG + m_bSOFT_MASK = false; +#endif // _DEBUG + m_nSOFT_MASK = 0; +#ifdef _DEBUG + m_bOUTLINE = false; +#endif // _DEBUG + m_nOUTLINE = 0; +#ifdef _DEBUG + m_bOUTER_GLOW = false; +#endif // _DEBUG + m_nOUTER_GLOW = 0; +#ifdef _DEBUG + m_bBLENDTINTBYBASEALPHA = false; +#endif // _DEBUG + m_nBLENDTINTBYBASEALPHA = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bDETAILTEXTURE && m_bCUBEMAP && m_bDIFFUSELIGHTING && m_bENVMAPMASK && m_bBASEALPHAENVMAPMASK && m_bSELFILLUM && m_bVERTEXCOLOR && m_bFLASHLIGHT && m_bSELFILLUM_ENVMAPMASK_ALPHA && m_bDETAIL_BLEND_MODE && m_bSEAMLESS_BASE && m_bSEAMLESS_DETAIL && m_bDISTANCEALPHA && m_bDISTANCEALPHAFROMDETAIL && m_bSOFT_MASK && m_bOUTLINE && m_bOUTER_GLOW && m_bBLENDTINTBYBASEALPHA; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nDETAILTEXTURE ) + ( 4 * m_nCUBEMAP ) + ( 8 * m_nDIFFUSELIGHTING ) + ( 16 * m_nENVMAPMASK ) + ( 32 * m_nBASEALPHAENVMAPMASK ) + ( 64 * m_nSELFILLUM ) + ( 128 * m_nVERTEXCOLOR ) + ( 256 * m_nFLASHLIGHT ) + ( 512 * m_nSELFILLUM_ENVMAPMASK_ALPHA ) + ( 1024 * m_nDETAIL_BLEND_MODE ) + ( 10240 * m_nSEAMLESS_BASE ) + ( 20480 * m_nSEAMLESS_DETAIL ) + ( 40960 * m_nDISTANCEALPHA ) + ( 81920 * m_nDISTANCEALPHAFROMDETAIL ) + ( 163840 * m_nSOFT_MASK ) + ( 327680 * m_nOUTLINE ) + ( 655360 * m_nOUTER_GLOW ) + ( 1310720 * m_nBLENDTINTBYBASEALPHA ) + 0; + } +}; +#define shaderStaticTest_vertexlit_and_unlit_generic_ps20 psh_forgot_to_set_static_DETAILTEXTURE + psh_forgot_to_set_static_CUBEMAP + psh_forgot_to_set_static_DIFFUSELIGHTING + psh_forgot_to_set_static_ENVMAPMASK + psh_forgot_to_set_static_BASEALPHAENVMAPMASK + psh_forgot_to_set_static_SELFILLUM + psh_forgot_to_set_static_VERTEXCOLOR + psh_forgot_to_set_static_FLASHLIGHT + psh_forgot_to_set_static_SELFILLUM_ENVMAPMASK_ALPHA + psh_forgot_to_set_static_DETAIL_BLEND_MODE + psh_forgot_to_set_static_SEAMLESS_BASE + psh_forgot_to_set_static_SEAMLESS_DETAIL + psh_forgot_to_set_static_DISTANCEALPHA + psh_forgot_to_set_static_DISTANCEALPHAFROMDETAIL + psh_forgot_to_set_static_SOFT_MASK + psh_forgot_to_set_static_OUTLINE + psh_forgot_to_set_static_OUTER_GLOW + psh_forgot_to_set_static_BLENDTINTBYBASEALPHA + 0 +class vertexlit_and_unlit_generic_ps20_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +private: + int m_nLIGHTING_PREVIEW; +#ifdef _DEBUG + bool m_bLIGHTING_PREVIEW; +#endif +public: + void SetLIGHTING_PREVIEW( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nLIGHTING_PREVIEW = i; +#ifdef _DEBUG + m_bLIGHTING_PREVIEW = true; +#endif + } + void SetLIGHTING_PREVIEW( bool i ) + { + m_nLIGHTING_PREVIEW = i ? 1 : 0; +#ifdef _DEBUG + m_bLIGHTING_PREVIEW = true; +#endif + } +public: + vertexlit_and_unlit_generic_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; +#ifdef _DEBUG + m_bLIGHTING_PREVIEW = false; +#endif // _DEBUG + m_nLIGHTING_PREVIEW = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE && m_bLIGHTING_PREVIEW; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + ( 2 * m_nLIGHTING_PREVIEW ) + 0; + } +}; +#define shaderDynamicTest_vertexlit_and_unlit_generic_ps20 psh_forgot_to_set_dynamic_PIXELFOGTYPE + psh_forgot_to_set_dynamic_LIGHTING_PREVIEW + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/vertexlit_and_unlit_generic_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/vertexlit_and_unlit_generic_ps20b.inc new file mode 100644 index 0000000..c6ecf3a --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/vertexlit_and_unlit_generic_ps20b.inc @@ -0,0 +1,612 @@ +#include "shaderlib/cshader.h" +class vertexlit_and_unlit_generic_ps20b_Static_Index +{ +private: + int m_nDETAILTEXTURE; +#ifdef _DEBUG + bool m_bDETAILTEXTURE; +#endif +public: + void SetDETAILTEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDETAILTEXTURE = i; +#ifdef _DEBUG + m_bDETAILTEXTURE = true; +#endif + } + void SetDETAILTEXTURE( bool i ) + { + m_nDETAILTEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bDETAILTEXTURE = true; +#endif + } +private: + int m_nCUBEMAP; +#ifdef _DEBUG + bool m_bCUBEMAP; +#endif +public: + void SetCUBEMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCUBEMAP = i; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } + void SetCUBEMAP( bool i ) + { + m_nCUBEMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } +private: + int m_nDIFFUSELIGHTING; +#ifdef _DEBUG + bool m_bDIFFUSELIGHTING; +#endif +public: + void SetDIFFUSELIGHTING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDIFFUSELIGHTING = i; +#ifdef _DEBUG + m_bDIFFUSELIGHTING = true; +#endif + } + void SetDIFFUSELIGHTING( bool i ) + { + m_nDIFFUSELIGHTING = i ? 1 : 0; +#ifdef _DEBUG + m_bDIFFUSELIGHTING = true; +#endif + } +private: + int m_nENVMAPMASK; +#ifdef _DEBUG + bool m_bENVMAPMASK; +#endif +public: + void SetENVMAPMASK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nENVMAPMASK = i; +#ifdef _DEBUG + m_bENVMAPMASK = true; +#endif + } + void SetENVMAPMASK( bool i ) + { + m_nENVMAPMASK = i ? 1 : 0; +#ifdef _DEBUG + m_bENVMAPMASK = true; +#endif + } +private: + int m_nBASEALPHAENVMAPMASK; +#ifdef _DEBUG + bool m_bBASEALPHAENVMAPMASK; +#endif +public: + void SetBASEALPHAENVMAPMASK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBASEALPHAENVMAPMASK = i; +#ifdef _DEBUG + m_bBASEALPHAENVMAPMASK = true; +#endif + } + void SetBASEALPHAENVMAPMASK( bool i ) + { + m_nBASEALPHAENVMAPMASK = i ? 1 : 0; +#ifdef _DEBUG + m_bBASEALPHAENVMAPMASK = true; +#endif + } +private: + int m_nSELFILLUM; +#ifdef _DEBUG + bool m_bSELFILLUM; +#endif +public: + void SetSELFILLUM( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSELFILLUM = i; +#ifdef _DEBUG + m_bSELFILLUM = true; +#endif + } + void SetSELFILLUM( bool i ) + { + m_nSELFILLUM = i ? 1 : 0; +#ifdef _DEBUG + m_bSELFILLUM = true; +#endif + } +private: + int m_nVERTEXCOLOR; +#ifdef _DEBUG + bool m_bVERTEXCOLOR; +#endif +public: + void SetVERTEXCOLOR( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nVERTEXCOLOR = i; +#ifdef _DEBUG + m_bVERTEXCOLOR = true; +#endif + } + void SetVERTEXCOLOR( bool i ) + { + m_nVERTEXCOLOR = i ? 1 : 0; +#ifdef _DEBUG + m_bVERTEXCOLOR = true; +#endif + } +private: + int m_nFLASHLIGHT; +#ifdef _DEBUG + bool m_bFLASHLIGHT; +#endif +public: + void SetFLASHLIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFLASHLIGHT = i; +#ifdef _DEBUG + m_bFLASHLIGHT = true; +#endif + } + void SetFLASHLIGHT( bool i ) + { + m_nFLASHLIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bFLASHLIGHT = true; +#endif + } +private: + int m_nSELFILLUM_ENVMAPMASK_ALPHA; +#ifdef _DEBUG + bool m_bSELFILLUM_ENVMAPMASK_ALPHA; +#endif +public: + void SetSELFILLUM_ENVMAPMASK_ALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSELFILLUM_ENVMAPMASK_ALPHA = i; +#ifdef _DEBUG + m_bSELFILLUM_ENVMAPMASK_ALPHA = true; +#endif + } + void SetSELFILLUM_ENVMAPMASK_ALPHA( bool i ) + { + m_nSELFILLUM_ENVMAPMASK_ALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bSELFILLUM_ENVMAPMASK_ALPHA = true; +#endif + } +private: + int m_nDETAIL_BLEND_MODE; +#ifdef _DEBUG + bool m_bDETAIL_BLEND_MODE; +#endif +public: + void SetDETAIL_BLEND_MODE( int i ) + { + Assert( i >= 0 && i <= 9 ); + m_nDETAIL_BLEND_MODE = i; +#ifdef _DEBUG + m_bDETAIL_BLEND_MODE = true; +#endif + } + void SetDETAIL_BLEND_MODE( bool i ) + { + m_nDETAIL_BLEND_MODE = i ? 1 : 0; +#ifdef _DEBUG + m_bDETAIL_BLEND_MODE = true; +#endif + } +private: + int m_nSEAMLESS_BASE; +#ifdef _DEBUG + bool m_bSEAMLESS_BASE; +#endif +public: + void SetSEAMLESS_BASE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSEAMLESS_BASE = i; +#ifdef _DEBUG + m_bSEAMLESS_BASE = true; +#endif + } + void SetSEAMLESS_BASE( bool i ) + { + m_nSEAMLESS_BASE = i ? 1 : 0; +#ifdef _DEBUG + m_bSEAMLESS_BASE = true; +#endif + } +private: + int m_nSEAMLESS_DETAIL; +#ifdef _DEBUG + bool m_bSEAMLESS_DETAIL; +#endif +public: + void SetSEAMLESS_DETAIL( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSEAMLESS_DETAIL = i; +#ifdef _DEBUG + m_bSEAMLESS_DETAIL = true; +#endif + } + void SetSEAMLESS_DETAIL( bool i ) + { + m_nSEAMLESS_DETAIL = i ? 1 : 0; +#ifdef _DEBUG + m_bSEAMLESS_DETAIL = true; +#endif + } +private: + int m_nDISTANCEALPHA; +#ifdef _DEBUG + bool m_bDISTANCEALPHA; +#endif +public: + void SetDISTANCEALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDISTANCEALPHA = i; +#ifdef _DEBUG + m_bDISTANCEALPHA = true; +#endif + } + void SetDISTANCEALPHA( bool i ) + { + m_nDISTANCEALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bDISTANCEALPHA = true; +#endif + } +private: + int m_nDISTANCEALPHAFROMDETAIL; +#ifdef _DEBUG + bool m_bDISTANCEALPHAFROMDETAIL; +#endif +public: + void SetDISTANCEALPHAFROMDETAIL( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDISTANCEALPHAFROMDETAIL = i; +#ifdef _DEBUG + m_bDISTANCEALPHAFROMDETAIL = true; +#endif + } + void SetDISTANCEALPHAFROMDETAIL( bool i ) + { + m_nDISTANCEALPHAFROMDETAIL = i ? 1 : 0; +#ifdef _DEBUG + m_bDISTANCEALPHAFROMDETAIL = true; +#endif + } +private: + int m_nSOFT_MASK; +#ifdef _DEBUG + bool m_bSOFT_MASK; +#endif +public: + void SetSOFT_MASK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSOFT_MASK = i; +#ifdef _DEBUG + m_bSOFT_MASK = true; +#endif + } + void SetSOFT_MASK( bool i ) + { + m_nSOFT_MASK = i ? 1 : 0; +#ifdef _DEBUG + m_bSOFT_MASK = true; +#endif + } +private: + int m_nOUTLINE; +#ifdef _DEBUG + bool m_bOUTLINE; +#endif +public: + void SetOUTLINE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nOUTLINE = i; +#ifdef _DEBUG + m_bOUTLINE = true; +#endif + } + void SetOUTLINE( bool i ) + { + m_nOUTLINE = i ? 1 : 0; +#ifdef _DEBUG + m_bOUTLINE = true; +#endif + } +private: + int m_nOUTER_GLOW; +#ifdef _DEBUG + bool m_bOUTER_GLOW; +#endif +public: + void SetOUTER_GLOW( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nOUTER_GLOW = i; +#ifdef _DEBUG + m_bOUTER_GLOW = true; +#endif + } + void SetOUTER_GLOW( bool i ) + { + m_nOUTER_GLOW = i ? 1 : 0; +#ifdef _DEBUG + m_bOUTER_GLOW = true; +#endif + } +private: + int m_nFLASHLIGHTDEPTHFILTERMODE; +#ifdef _DEBUG + bool m_bFLASHLIGHTDEPTHFILTERMODE; +#endif +public: + void SetFLASHLIGHTDEPTHFILTERMODE( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nFLASHLIGHTDEPTHFILTERMODE = i; +#ifdef _DEBUG + m_bFLASHLIGHTDEPTHFILTERMODE = true; +#endif + } + void SetFLASHLIGHTDEPTHFILTERMODE( bool i ) + { + m_nFLASHLIGHTDEPTHFILTERMODE = i ? 1 : 0; +#ifdef _DEBUG + m_bFLASHLIGHTDEPTHFILTERMODE = true; +#endif + } +private: + int m_nDEPTHBLEND; +#ifdef _DEBUG + bool m_bDEPTHBLEND; +#endif +public: + void SetDEPTHBLEND( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDEPTHBLEND = i; +#ifdef _DEBUG + m_bDEPTHBLEND = true; +#endif + } + void SetDEPTHBLEND( bool i ) + { + m_nDEPTHBLEND = i ? 1 : 0; +#ifdef _DEBUG + m_bDEPTHBLEND = true; +#endif + } +private: + int m_nBLENDTINTBYBASEALPHA; +#ifdef _DEBUG + bool m_bBLENDTINTBYBASEALPHA; +#endif +public: + void SetBLENDTINTBYBASEALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBLENDTINTBYBASEALPHA = i; +#ifdef _DEBUG + m_bBLENDTINTBYBASEALPHA = true; +#endif + } + void SetBLENDTINTBYBASEALPHA( bool i ) + { + m_nBLENDTINTBYBASEALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bBLENDTINTBYBASEALPHA = true; +#endif + } +private: + int m_nSRGB_INPUT_ADAPTER; +#ifdef _DEBUG + bool m_bSRGB_INPUT_ADAPTER; +#endif +public: + void SetSRGB_INPUT_ADAPTER( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSRGB_INPUT_ADAPTER = i; +#ifdef _DEBUG + m_bSRGB_INPUT_ADAPTER = true; +#endif + } + void SetSRGB_INPUT_ADAPTER( bool i ) + { + m_nSRGB_INPUT_ADAPTER = i ? 1 : 0; +#ifdef _DEBUG + m_bSRGB_INPUT_ADAPTER = true; +#endif + } +public: + vertexlit_and_unlit_generic_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bDETAILTEXTURE = false; +#endif // _DEBUG + m_nDETAILTEXTURE = 0; +#ifdef _DEBUG + m_bCUBEMAP = false; +#endif // _DEBUG + m_nCUBEMAP = 0; +#ifdef _DEBUG + m_bDIFFUSELIGHTING = false; +#endif // _DEBUG + m_nDIFFUSELIGHTING = 0; +#ifdef _DEBUG + m_bENVMAPMASK = false; +#endif // _DEBUG + m_nENVMAPMASK = 0; +#ifdef _DEBUG + m_bBASEALPHAENVMAPMASK = false; +#endif // _DEBUG + m_nBASEALPHAENVMAPMASK = 0; +#ifdef _DEBUG + m_bSELFILLUM = false; +#endif // _DEBUG + m_nSELFILLUM = 0; +#ifdef _DEBUG + m_bVERTEXCOLOR = false; +#endif // _DEBUG + m_nVERTEXCOLOR = 0; +#ifdef _DEBUG + m_bFLASHLIGHT = false; +#endif // _DEBUG + m_nFLASHLIGHT = 0; +#ifdef _DEBUG + m_bSELFILLUM_ENVMAPMASK_ALPHA = false; +#endif // _DEBUG + m_nSELFILLUM_ENVMAPMASK_ALPHA = 0; +#ifdef _DEBUG + m_bDETAIL_BLEND_MODE = false; +#endif // _DEBUG + m_nDETAIL_BLEND_MODE = 0; +#ifdef _DEBUG + m_bSEAMLESS_BASE = false; +#endif // _DEBUG + m_nSEAMLESS_BASE = 0; +#ifdef _DEBUG + m_bSEAMLESS_DETAIL = false; +#endif // _DEBUG + m_nSEAMLESS_DETAIL = 0; +#ifdef _DEBUG + m_bDISTANCEALPHA = false; +#endif // _DEBUG + m_nDISTANCEALPHA = 0; +#ifdef _DEBUG + m_bDISTANCEALPHAFROMDETAIL = false; +#endif // _DEBUG + m_nDISTANCEALPHAFROMDETAIL = 0; +#ifdef _DEBUG + m_bSOFT_MASK = false; +#endif // _DEBUG + m_nSOFT_MASK = 0; +#ifdef _DEBUG + m_bOUTLINE = false; +#endif // _DEBUG + m_nOUTLINE = 0; +#ifdef _DEBUG + m_bOUTER_GLOW = false; +#endif // _DEBUG + m_nOUTER_GLOW = 0; +#ifdef _DEBUG + m_bFLASHLIGHTDEPTHFILTERMODE = false; +#endif // _DEBUG + m_nFLASHLIGHTDEPTHFILTERMODE = 0; +#ifdef _DEBUG + m_bDEPTHBLEND = false; +#endif // _DEBUG + m_nDEPTHBLEND = 0; +#ifdef _DEBUG + m_bBLENDTINTBYBASEALPHA = false; +#endif // _DEBUG + m_nBLENDTINTBYBASEALPHA = 0; +#ifdef _DEBUG + m_bSRGB_INPUT_ADAPTER = false; +#endif // _DEBUG + m_nSRGB_INPUT_ADAPTER = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bDETAILTEXTURE && m_bCUBEMAP && m_bDIFFUSELIGHTING && m_bENVMAPMASK && m_bBASEALPHAENVMAPMASK && m_bSELFILLUM && m_bVERTEXCOLOR && m_bFLASHLIGHT && m_bSELFILLUM_ENVMAPMASK_ALPHA && m_bDETAIL_BLEND_MODE && m_bSEAMLESS_BASE && m_bSEAMLESS_DETAIL && m_bDISTANCEALPHA && m_bDISTANCEALPHAFROMDETAIL && m_bSOFT_MASK && m_bOUTLINE && m_bOUTER_GLOW && m_bFLASHLIGHTDEPTHFILTERMODE && m_bDEPTHBLEND && m_bBLENDTINTBYBASEALPHA && m_bSRGB_INPUT_ADAPTER; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nDETAILTEXTURE ) + ( 4 * m_nCUBEMAP ) + ( 8 * m_nDIFFUSELIGHTING ) + ( 16 * m_nENVMAPMASK ) + ( 32 * m_nBASEALPHAENVMAPMASK ) + ( 64 * m_nSELFILLUM ) + ( 128 * m_nVERTEXCOLOR ) + ( 256 * m_nFLASHLIGHT ) + ( 512 * m_nSELFILLUM_ENVMAPMASK_ALPHA ) + ( 1024 * m_nDETAIL_BLEND_MODE ) + ( 10240 * m_nSEAMLESS_BASE ) + ( 20480 * m_nSEAMLESS_DETAIL ) + ( 40960 * m_nDISTANCEALPHA ) + ( 81920 * m_nDISTANCEALPHAFROMDETAIL ) + ( 163840 * m_nSOFT_MASK ) + ( 327680 * m_nOUTLINE ) + ( 655360 * m_nOUTER_GLOW ) + ( 1310720 * m_nFLASHLIGHTDEPTHFILTERMODE ) + ( 1310720 * m_nDEPTHBLEND ) + ( 2621440 * m_nBLENDTINTBYBASEALPHA ) + ( 5242880 * m_nSRGB_INPUT_ADAPTER ) + 0; + } +}; +#define shaderStaticTest_vertexlit_and_unlit_generic_ps20b psh_forgot_to_set_static_DETAILTEXTURE + psh_forgot_to_set_static_CUBEMAP + psh_forgot_to_set_static_DIFFUSELIGHTING + psh_forgot_to_set_static_ENVMAPMASK + psh_forgot_to_set_static_BASEALPHAENVMAPMASK + psh_forgot_to_set_static_SELFILLUM + psh_forgot_to_set_static_VERTEXCOLOR + psh_forgot_to_set_static_FLASHLIGHT + psh_forgot_to_set_static_SELFILLUM_ENVMAPMASK_ALPHA + psh_forgot_to_set_static_DETAIL_BLEND_MODE + psh_forgot_to_set_static_SEAMLESS_BASE + psh_forgot_to_set_static_SEAMLESS_DETAIL + psh_forgot_to_set_static_DISTANCEALPHA + psh_forgot_to_set_static_DISTANCEALPHAFROMDETAIL + psh_forgot_to_set_static_SOFT_MASK + psh_forgot_to_set_static_OUTLINE + psh_forgot_to_set_static_OUTER_GLOW + psh_forgot_to_set_static_FLASHLIGHTDEPTHFILTERMODE + psh_forgot_to_set_static_DEPTHBLEND + psh_forgot_to_set_static_BLENDTINTBYBASEALPHA + psh_forgot_to_set_static_SRGB_INPUT_ADAPTER + 0 +class vertexlit_and_unlit_generic_ps20b_Dynamic_Index +{ +private: + int m_nLIGHTING_PREVIEW; +#ifdef _DEBUG + bool m_bLIGHTING_PREVIEW; +#endif +public: + void SetLIGHTING_PREVIEW( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nLIGHTING_PREVIEW = i; +#ifdef _DEBUG + m_bLIGHTING_PREVIEW = true; +#endif + } + void SetLIGHTING_PREVIEW( bool i ) + { + m_nLIGHTING_PREVIEW = i ? 1 : 0; +#ifdef _DEBUG + m_bLIGHTING_PREVIEW = true; +#endif + } +private: + int m_nFLASHLIGHTSHADOWS; +#ifdef _DEBUG + bool m_bFLASHLIGHTSHADOWS; +#endif +public: + void SetFLASHLIGHTSHADOWS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFLASHLIGHTSHADOWS = i; +#ifdef _DEBUG + m_bFLASHLIGHTSHADOWS = true; +#endif + } + void SetFLASHLIGHTSHADOWS( bool i ) + { + m_nFLASHLIGHTSHADOWS = i ? 1 : 0; +#ifdef _DEBUG + m_bFLASHLIGHTSHADOWS = true; +#endif + } +public: + vertexlit_and_unlit_generic_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bLIGHTING_PREVIEW = false; +#endif // _DEBUG + m_nLIGHTING_PREVIEW = 0; +#ifdef _DEBUG + m_bFLASHLIGHTSHADOWS = false; +#endif // _DEBUG + m_nFLASHLIGHTSHADOWS = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bLIGHTING_PREVIEW && m_bFLASHLIGHTSHADOWS; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nLIGHTING_PREVIEW ) + ( 1 * m_nFLASHLIGHTSHADOWS ) + 0; + } +}; +#define shaderDynamicTest_vertexlit_and_unlit_generic_ps20b psh_forgot_to_set_dynamic_LIGHTING_PREVIEW + psh_forgot_to_set_dynamic_FLASHLIGHTSHADOWS + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/vertexlitgeneric_lightingonly_overbright2_ps11.inc b/materialsystem/stdshaders/fxctmp9_360/vertexlitgeneric_lightingonly_overbright2_ps11.inc new file mode 100644 index 0000000..7fc097a --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/vertexlitgeneric_lightingonly_overbright2_ps11.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class vertexlitgeneric_lightingonly_overbright2_ps11_Static_Index +{ +public: + vertexlitgeneric_lightingonly_overbright2_ps11_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_vertexlitgeneric_lightingonly_overbright2_ps11 0 +class vertexlitgeneric_lightingonly_overbright2_ps11_Dynamic_Index +{ +public: + vertexlitgeneric_lightingonly_overbright2_ps11_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_vertexlitgeneric_lightingonly_overbright2_ps11 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/volume_clouds_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/volume_clouds_ps20.inc new file mode 100644 index 0000000..70e421a --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/volume_clouds_ps20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class volume_clouds_ps20_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + volume_clouds_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_volume_clouds_ps20 0 +class volume_clouds_ps20_Dynamic_Index +{ +public: + volume_clouds_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_volume_clouds_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/volume_clouds_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/volume_clouds_ps20b.inc new file mode 100644 index 0000000..d9829a1 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/volume_clouds_ps20b.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class volume_clouds_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + volume_clouds_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_volume_clouds_ps20b 0 +class volume_clouds_ps20b_Dynamic_Index +{ +public: + volume_clouds_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_volume_clouds_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/volume_clouds_vs20.inc b/materialsystem/stdshaders/fxctmp9_360/volume_clouds_vs20.inc new file mode 100644 index 0000000..d858334 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/volume_clouds_vs20.inc @@ -0,0 +1,85 @@ +#include "shaderlib/cshader.h" +class volume_clouds_vs20_Static_Index +{ +public: + volume_clouds_vs20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_volume_clouds_vs20 0 +class volume_clouds_vs20_Dynamic_Index +{ +private: + int m_nCOMPRESSED_VERTS; +#ifdef _DEBUG + bool m_bCOMPRESSED_VERTS; +#endif +public: + void SetCOMPRESSED_VERTS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOMPRESSED_VERTS = i; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } + void SetCOMPRESSED_VERTS( bool i ) + { + m_nCOMPRESSED_VERTS = i ? 1 : 0; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +public: + volume_clouds_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = false; +#endif // _DEBUG + m_nCOMPRESSED_VERTS = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bCOMPRESSED_VERTS && m_bSKINNING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCOMPRESSED_VERTS ) + ( 2 * m_nSKINNING ) + 0; + } +}; +#define shaderDynamicTest_volume_clouds_vs20 vsh_forgot_to_set_dynamic_COMPRESSED_VERTS + vsh_forgot_to_set_dynamic_SKINNING + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/vortwarp_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/vortwarp_ps20.inc new file mode 100644 index 0000000..920ad9b --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/vortwarp_ps20.inc @@ -0,0 +1,362 @@ +#include "shaderlib/cshader.h" +class vortwarp_ps20_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +private: + int m_nBASETEXTURE; +#ifdef _DEBUG + bool m_bBASETEXTURE; +#endif +public: + void SetBASETEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBASETEXTURE = i; +#ifdef _DEBUG + m_bBASETEXTURE = true; +#endif + } + void SetBASETEXTURE( bool i ) + { + m_nBASETEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bBASETEXTURE = true; +#endif + } +private: + int m_nCUBEMAP; +#ifdef _DEBUG + bool m_bCUBEMAP; +#endif +public: + void SetCUBEMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCUBEMAP = i; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } + void SetCUBEMAP( bool i ) + { + m_nCUBEMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } +private: + int m_nDIFFUSELIGHTING; +#ifdef _DEBUG + bool m_bDIFFUSELIGHTING; +#endif +public: + void SetDIFFUSELIGHTING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDIFFUSELIGHTING = i; +#ifdef _DEBUG + m_bDIFFUSELIGHTING = true; +#endif + } + void SetDIFFUSELIGHTING( bool i ) + { + m_nDIFFUSELIGHTING = i ? 1 : 0; +#ifdef _DEBUG + m_bDIFFUSELIGHTING = true; +#endif + } +private: + int m_nNORMALMAPALPHAENVMAPMASK; +#ifdef _DEBUG + bool m_bNORMALMAPALPHAENVMAPMASK; +#endif +public: + void SetNORMALMAPALPHAENVMAPMASK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nNORMALMAPALPHAENVMAPMASK = i; +#ifdef _DEBUG + m_bNORMALMAPALPHAENVMAPMASK = true; +#endif + } + void SetNORMALMAPALPHAENVMAPMASK( bool i ) + { + m_nNORMALMAPALPHAENVMAPMASK = i ? 1 : 0; +#ifdef _DEBUG + m_bNORMALMAPALPHAENVMAPMASK = true; +#endif + } +private: + int m_nHALFLAMBERT; +#ifdef _DEBUG + bool m_bHALFLAMBERT; +#endif +public: + void SetHALFLAMBERT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHALFLAMBERT = i; +#ifdef _DEBUG + m_bHALFLAMBERT = true; +#endif + } + void SetHALFLAMBERT( bool i ) + { + m_nHALFLAMBERT = i ? 1 : 0; +#ifdef _DEBUG + m_bHALFLAMBERT = true; +#endif + } +private: + int m_nFLASHLIGHT; +#ifdef _DEBUG + bool m_bFLASHLIGHT; +#endif +public: + void SetFLASHLIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFLASHLIGHT = i; +#ifdef _DEBUG + m_bFLASHLIGHT = true; +#endif + } + void SetFLASHLIGHT( bool i ) + { + m_nFLASHLIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bFLASHLIGHT = true; +#endif + } +private: + int m_nTRANSLUCENT; +#ifdef _DEBUG + bool m_bTRANSLUCENT; +#endif +public: + void SetTRANSLUCENT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nTRANSLUCENT = i; +#ifdef _DEBUG + m_bTRANSLUCENT = true; +#endif + } + void SetTRANSLUCENT( bool i ) + { + m_nTRANSLUCENT = i ? 1 : 0; +#ifdef _DEBUG + m_bTRANSLUCENT = true; +#endif + } +public: + vortwarp_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; +#ifdef _DEBUG + m_bBASETEXTURE = false; +#endif // _DEBUG + m_nBASETEXTURE = 0; +#ifdef _DEBUG + m_bCUBEMAP = false; +#endif // _DEBUG + m_nCUBEMAP = 0; +#ifdef _DEBUG + m_bDIFFUSELIGHTING = false; +#endif // _DEBUG + m_nDIFFUSELIGHTING = 0; +#ifdef _DEBUG + m_bNORMALMAPALPHAENVMAPMASK = false; +#endif // _DEBUG + m_nNORMALMAPALPHAENVMAPMASK = 0; +#ifdef _DEBUG + m_bHALFLAMBERT = false; +#endif // _DEBUG + m_nHALFLAMBERT = 0; +#ifdef _DEBUG + m_bFLASHLIGHT = false; +#endif // _DEBUG + m_nFLASHLIGHT = 0; +#ifdef _DEBUG + m_bTRANSLUCENT = false; +#endif // _DEBUG + m_nTRANSLUCENT = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB && m_bBASETEXTURE && m_bCUBEMAP && m_bDIFFUSELIGHTING && m_bNORMALMAPALPHAENVMAPMASK && m_bHALFLAMBERT && m_bFLASHLIGHT && m_bTRANSLUCENT; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 48 * m_nCONVERT_TO_SRGB ) + ( 48 * m_nBASETEXTURE ) + ( 96 * m_nCUBEMAP ) + ( 192 * m_nDIFFUSELIGHTING ) + ( 384 * m_nNORMALMAPALPHAENVMAPMASK ) + ( 768 * m_nHALFLAMBERT ) + ( 1536 * m_nFLASHLIGHT ) + ( 3072 * m_nTRANSLUCENT ) + 0; + } +}; +#define shaderStaticTest_vortwarp_ps20 psh_forgot_to_set_static_BASETEXTURE + psh_forgot_to_set_static_CUBEMAP + psh_forgot_to_set_static_DIFFUSELIGHTING + psh_forgot_to_set_static_NORMALMAPALPHAENVMAPMASK + psh_forgot_to_set_static_HALFLAMBERT + psh_forgot_to_set_static_FLASHLIGHT + psh_forgot_to_set_static_TRANSLUCENT + 0 +class vortwarp_ps20_Dynamic_Index +{ +private: + int m_nWRITEWATERFOGTODESTALPHA; +#ifdef _DEBUG + bool m_bWRITEWATERFOGTODESTALPHA; +#endif +public: + void SetWRITEWATERFOGTODESTALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nWRITEWATERFOGTODESTALPHA = i; +#ifdef _DEBUG + m_bWRITEWATERFOGTODESTALPHA = true; +#endif + } + void SetWRITEWATERFOGTODESTALPHA( bool i ) + { + m_nWRITEWATERFOGTODESTALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bWRITEWATERFOGTODESTALPHA = true; +#endif + } +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +private: + int m_nWARPINGIN; +#ifdef _DEBUG + bool m_bWARPINGIN; +#endif +public: + void SetWARPINGIN( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nWARPINGIN = i; +#ifdef _DEBUG + m_bWARPINGIN = true; +#endif + } + void SetWARPINGIN( bool i ) + { + m_nWARPINGIN = i ? 1 : 0; +#ifdef _DEBUG + m_bWARPINGIN = true; +#endif + } +private: + int m_nAMBIENT_LIGHT; +#ifdef _DEBUG + bool m_bAMBIENT_LIGHT; +#endif +public: + void SetAMBIENT_LIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nAMBIENT_LIGHT = i; +#ifdef _DEBUG + m_bAMBIENT_LIGHT = true; +#endif + } + void SetAMBIENT_LIGHT( bool i ) + { + m_nAMBIENT_LIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bAMBIENT_LIGHT = true; +#endif + } +private: + int m_nNUM_LIGHTS; +#ifdef _DEBUG + bool m_bNUM_LIGHTS; +#endif +public: + void SetNUM_LIGHTS( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nNUM_LIGHTS = i; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } + void SetNUM_LIGHTS( bool i ) + { + m_nNUM_LIGHTS = i ? 1 : 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } +public: + vortwarp_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bWRITEWATERFOGTODESTALPHA = false; +#endif // _DEBUG + m_nWRITEWATERFOGTODESTALPHA = 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; +#ifdef _DEBUG + m_bWARPINGIN = false; +#endif // _DEBUG + m_nWARPINGIN = 0; +#ifdef _DEBUG + m_bAMBIENT_LIGHT = false; +#endif // _DEBUG + m_nAMBIENT_LIGHT = 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = false; +#endif // _DEBUG + m_nNUM_LIGHTS = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bWRITEWATERFOGTODESTALPHA && m_bPIXELFOGTYPE && m_bWARPINGIN && m_bAMBIENT_LIGHT && m_bNUM_LIGHTS; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nWRITEWATERFOGTODESTALPHA ) + ( 2 * m_nPIXELFOGTYPE ) + ( 4 * m_nWARPINGIN ) + ( 8 * m_nAMBIENT_LIGHT ) + ( 16 * m_nNUM_LIGHTS ) + 0; + } +}; +#define shaderDynamicTest_vortwarp_ps20 psh_forgot_to_set_dynamic_WRITEWATERFOGTODESTALPHA + psh_forgot_to_set_dynamic_PIXELFOGTYPE + psh_forgot_to_set_dynamic_WARPINGIN + psh_forgot_to_set_dynamic_AMBIENT_LIGHT + psh_forgot_to_set_dynamic_NUM_LIGHTS + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/vortwarp_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/vortwarp_ps20b.inc new file mode 100644 index 0000000..8bd32ae --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/vortwarp_ps20b.inc @@ -0,0 +1,362 @@ +#include "shaderlib/cshader.h" +class vortwarp_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +private: + int m_nBASETEXTURE; +#ifdef _DEBUG + bool m_bBASETEXTURE; +#endif +public: + void SetBASETEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBASETEXTURE = i; +#ifdef _DEBUG + m_bBASETEXTURE = true; +#endif + } + void SetBASETEXTURE( bool i ) + { + m_nBASETEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bBASETEXTURE = true; +#endif + } +private: + int m_nCUBEMAP; +#ifdef _DEBUG + bool m_bCUBEMAP; +#endif +public: + void SetCUBEMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCUBEMAP = i; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } + void SetCUBEMAP( bool i ) + { + m_nCUBEMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bCUBEMAP = true; +#endif + } +private: + int m_nDIFFUSELIGHTING; +#ifdef _DEBUG + bool m_bDIFFUSELIGHTING; +#endif +public: + void SetDIFFUSELIGHTING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDIFFUSELIGHTING = i; +#ifdef _DEBUG + m_bDIFFUSELIGHTING = true; +#endif + } + void SetDIFFUSELIGHTING( bool i ) + { + m_nDIFFUSELIGHTING = i ? 1 : 0; +#ifdef _DEBUG + m_bDIFFUSELIGHTING = true; +#endif + } +private: + int m_nNORMALMAPALPHAENVMAPMASK; +#ifdef _DEBUG + bool m_bNORMALMAPALPHAENVMAPMASK; +#endif +public: + void SetNORMALMAPALPHAENVMAPMASK( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nNORMALMAPALPHAENVMAPMASK = i; +#ifdef _DEBUG + m_bNORMALMAPALPHAENVMAPMASK = true; +#endif + } + void SetNORMALMAPALPHAENVMAPMASK( bool i ) + { + m_nNORMALMAPALPHAENVMAPMASK = i ? 1 : 0; +#ifdef _DEBUG + m_bNORMALMAPALPHAENVMAPMASK = true; +#endif + } +private: + int m_nHALFLAMBERT; +#ifdef _DEBUG + bool m_bHALFLAMBERT; +#endif +public: + void SetHALFLAMBERT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHALFLAMBERT = i; +#ifdef _DEBUG + m_bHALFLAMBERT = true; +#endif + } + void SetHALFLAMBERT( bool i ) + { + m_nHALFLAMBERT = i ? 1 : 0; +#ifdef _DEBUG + m_bHALFLAMBERT = true; +#endif + } +private: + int m_nFLASHLIGHT; +#ifdef _DEBUG + bool m_bFLASHLIGHT; +#endif +public: + void SetFLASHLIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nFLASHLIGHT = i; +#ifdef _DEBUG + m_bFLASHLIGHT = true; +#endif + } + void SetFLASHLIGHT( bool i ) + { + m_nFLASHLIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bFLASHLIGHT = true; +#endif + } +private: + int m_nTRANSLUCENT; +#ifdef _DEBUG + bool m_bTRANSLUCENT; +#endif +public: + void SetTRANSLUCENT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nTRANSLUCENT = i; +#ifdef _DEBUG + m_bTRANSLUCENT = true; +#endif + } + void SetTRANSLUCENT( bool i ) + { + m_nTRANSLUCENT = i ? 1 : 0; +#ifdef _DEBUG + m_bTRANSLUCENT = true; +#endif + } +public: + vortwarp_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; +#ifdef _DEBUG + m_bBASETEXTURE = false; +#endif // _DEBUG + m_nBASETEXTURE = 0; +#ifdef _DEBUG + m_bCUBEMAP = false; +#endif // _DEBUG + m_nCUBEMAP = 0; +#ifdef _DEBUG + m_bDIFFUSELIGHTING = false; +#endif // _DEBUG + m_nDIFFUSELIGHTING = 0; +#ifdef _DEBUG + m_bNORMALMAPALPHAENVMAPMASK = false; +#endif // _DEBUG + m_nNORMALMAPALPHAENVMAPMASK = 0; +#ifdef _DEBUG + m_bHALFLAMBERT = false; +#endif // _DEBUG + m_nHALFLAMBERT = 0; +#ifdef _DEBUG + m_bFLASHLIGHT = false; +#endif // _DEBUG + m_nFLASHLIGHT = 0; +#ifdef _DEBUG + m_bTRANSLUCENT = false; +#endif // _DEBUG + m_nTRANSLUCENT = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB && m_bBASETEXTURE && m_bCUBEMAP && m_bDIFFUSELIGHTING && m_bNORMALMAPALPHAENVMAPMASK && m_bHALFLAMBERT && m_bFLASHLIGHT && m_bTRANSLUCENT; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 80 * m_nCONVERT_TO_SRGB ) + ( 80 * m_nBASETEXTURE ) + ( 160 * m_nCUBEMAP ) + ( 320 * m_nDIFFUSELIGHTING ) + ( 640 * m_nNORMALMAPALPHAENVMAPMASK ) + ( 1280 * m_nHALFLAMBERT ) + ( 2560 * m_nFLASHLIGHT ) + ( 5120 * m_nTRANSLUCENT ) + 0; + } +}; +#define shaderStaticTest_vortwarp_ps20b psh_forgot_to_set_static_BASETEXTURE + psh_forgot_to_set_static_CUBEMAP + psh_forgot_to_set_static_DIFFUSELIGHTING + psh_forgot_to_set_static_NORMALMAPALPHAENVMAPMASK + psh_forgot_to_set_static_HALFLAMBERT + psh_forgot_to_set_static_FLASHLIGHT + psh_forgot_to_set_static_TRANSLUCENT + 0 +class vortwarp_ps20b_Dynamic_Index +{ +private: + int m_nWRITEWATERFOGTODESTALPHA; +#ifdef _DEBUG + bool m_bWRITEWATERFOGTODESTALPHA; +#endif +public: + void SetWRITEWATERFOGTODESTALPHA( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nWRITEWATERFOGTODESTALPHA = i; +#ifdef _DEBUG + m_bWRITEWATERFOGTODESTALPHA = true; +#endif + } + void SetWRITEWATERFOGTODESTALPHA( bool i ) + { + m_nWRITEWATERFOGTODESTALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bWRITEWATERFOGTODESTALPHA = true; +#endif + } +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +private: + int m_nWARPINGIN; +#ifdef _DEBUG + bool m_bWARPINGIN; +#endif +public: + void SetWARPINGIN( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nWARPINGIN = i; +#ifdef _DEBUG + m_bWARPINGIN = true; +#endif + } + void SetWARPINGIN( bool i ) + { + m_nWARPINGIN = i ? 1 : 0; +#ifdef _DEBUG + m_bWARPINGIN = true; +#endif + } +private: + int m_nAMBIENT_LIGHT; +#ifdef _DEBUG + bool m_bAMBIENT_LIGHT; +#endif +public: + void SetAMBIENT_LIGHT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nAMBIENT_LIGHT = i; +#ifdef _DEBUG + m_bAMBIENT_LIGHT = true; +#endif + } + void SetAMBIENT_LIGHT( bool i ) + { + m_nAMBIENT_LIGHT = i ? 1 : 0; +#ifdef _DEBUG + m_bAMBIENT_LIGHT = true; +#endif + } +private: + int m_nNUM_LIGHTS; +#ifdef _DEBUG + bool m_bNUM_LIGHTS; +#endif +public: + void SetNUM_LIGHTS( int i ) + { + Assert( i >= 0 && i <= 4 ); + m_nNUM_LIGHTS = i; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } + void SetNUM_LIGHTS( bool i ) + { + m_nNUM_LIGHTS = i ? 1 : 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } +public: + vortwarp_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bWRITEWATERFOGTODESTALPHA = false; +#endif // _DEBUG + m_nWRITEWATERFOGTODESTALPHA = 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; +#ifdef _DEBUG + m_bWARPINGIN = false; +#endif // _DEBUG + m_nWARPINGIN = 0; +#ifdef _DEBUG + m_bAMBIENT_LIGHT = false; +#endif // _DEBUG + m_nAMBIENT_LIGHT = 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = false; +#endif // _DEBUG + m_nNUM_LIGHTS = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bWRITEWATERFOGTODESTALPHA && m_bPIXELFOGTYPE && m_bWARPINGIN && m_bAMBIENT_LIGHT && m_bNUM_LIGHTS; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nWRITEWATERFOGTODESTALPHA ) + ( 2 * m_nPIXELFOGTYPE ) + ( 4 * m_nWARPINGIN ) + ( 8 * m_nAMBIENT_LIGHT ) + ( 16 * m_nNUM_LIGHTS ) + 0; + } +}; +#define shaderDynamicTest_vortwarp_ps20b psh_forgot_to_set_dynamic_WRITEWATERFOGTODESTALPHA + psh_forgot_to_set_dynamic_PIXELFOGTYPE + psh_forgot_to_set_dynamic_WARPINGIN + psh_forgot_to_set_dynamic_AMBIENT_LIGHT + psh_forgot_to_set_dynamic_NUM_LIGHTS + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/vortwarp_vs20.inc b/materialsystem/stdshaders/fxctmp9_360/vortwarp_vs20.inc new file mode 100644 index 0000000..1c45cab --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/vortwarp_vs20.inc @@ -0,0 +1,187 @@ +#include "shaderlib/cshader.h" +class vortwarp_vs20_Static_Index +{ +private: + int m_nHALFLAMBERT; +#ifdef _DEBUG + bool m_bHALFLAMBERT; +#endif +public: + void SetHALFLAMBERT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHALFLAMBERT = i; +#ifdef _DEBUG + m_bHALFLAMBERT = true; +#endif + } + void SetHALFLAMBERT( bool i ) + { + m_nHALFLAMBERT = i ? 1 : 0; +#ifdef _DEBUG + m_bHALFLAMBERT = true; +#endif + } +private: + int m_nUSE_STATIC_CONTROL_FLOW; +#ifdef _DEBUG + bool m_bUSE_STATIC_CONTROL_FLOW; +#endif +public: + void SetUSE_STATIC_CONTROL_FLOW( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nUSE_STATIC_CONTROL_FLOW = i; +#ifdef _DEBUG + m_bUSE_STATIC_CONTROL_FLOW = true; +#endif + } + void SetUSE_STATIC_CONTROL_FLOW( bool i ) + { + m_nUSE_STATIC_CONTROL_FLOW = i ? 1 : 0; +#ifdef _DEBUG + m_bUSE_STATIC_CONTROL_FLOW = true; +#endif + } +public: + vortwarp_vs20_Static_Index( ) + { +#ifdef _DEBUG + m_bHALFLAMBERT = false; +#endif // _DEBUG + m_nHALFLAMBERT = 0; +#ifdef _DEBUG + m_bUSE_STATIC_CONTROL_FLOW = false; +#endif // _DEBUG + m_nUSE_STATIC_CONTROL_FLOW = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bHALFLAMBERT && m_bUSE_STATIC_CONTROL_FLOW; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 24 * m_nHALFLAMBERT ) + ( 48 * m_nUSE_STATIC_CONTROL_FLOW ) + 0; + } +}; +#define shaderStaticTest_vortwarp_vs20 vsh_forgot_to_set_static_HALFLAMBERT + vsh_forgot_to_set_static_USE_STATIC_CONTROL_FLOW + 0 +class vortwarp_vs20_Dynamic_Index +{ +private: + int m_nCOMPRESSED_VERTS; +#ifdef _DEBUG + bool m_bCOMPRESSED_VERTS; +#endif +public: + void SetCOMPRESSED_VERTS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOMPRESSED_VERTS = i; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } + void SetCOMPRESSED_VERTS( bool i ) + { + m_nCOMPRESSED_VERTS = i ? 1 : 0; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +private: + int m_nNUM_LIGHTS; +#ifdef _DEBUG + bool m_bNUM_LIGHTS; +#endif +public: + void SetNUM_LIGHTS( int i ) + { + Assert( i >= 0 && i <= 2 ); + m_nNUM_LIGHTS = i; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } + void SetNUM_LIGHTS( bool i ) + { + m_nNUM_LIGHTS = i ? 1 : 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = true; +#endif + } +public: + vortwarp_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = false; +#endif // _DEBUG + m_nCOMPRESSED_VERTS = 0; +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; +#ifdef _DEBUG + m_bNUM_LIGHTS = false; +#endif // _DEBUG + m_nNUM_LIGHTS = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bCOMPRESSED_VERTS && m_bDOWATERFOG && m_bSKINNING && m_bNUM_LIGHTS; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCOMPRESSED_VERTS ) + ( 2 * m_nDOWATERFOG ) + ( 4 * m_nSKINNING ) + ( 8 * m_nNUM_LIGHTS ) + 0; + } +}; +#define shaderDynamicTest_vortwarp_vs20 vsh_forgot_to_set_dynamic_COMPRESSED_VERTS + vsh_forgot_to_set_dynamic_DOWATERFOG + vsh_forgot_to_set_dynamic_SKINNING + vsh_forgot_to_set_dynamic_NUM_LIGHTS + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/water_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/water_ps20b.inc new file mode 100644 index 0000000..1d38be4 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/water_ps20b.inc @@ -0,0 +1,287 @@ +#include "shaderlib/cshader.h" +class water_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +private: + int m_nBASETEXTURE; +#ifdef _DEBUG + bool m_bBASETEXTURE; +#endif +public: + void SetBASETEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBASETEXTURE = i; +#ifdef _DEBUG + m_bBASETEXTURE = true; +#endif + } + void SetBASETEXTURE( bool i ) + { + m_nBASETEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bBASETEXTURE = true; +#endif + } +private: + int m_nMULTITEXTURE; +#ifdef _DEBUG + bool m_bMULTITEXTURE; +#endif +public: + void SetMULTITEXTURE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nMULTITEXTURE = i; +#ifdef _DEBUG + m_bMULTITEXTURE = true; +#endif + } + void SetMULTITEXTURE( bool i ) + { + m_nMULTITEXTURE = i ? 1 : 0; +#ifdef _DEBUG + m_bMULTITEXTURE = true; +#endif + } +private: + int m_nREFLECT; +#ifdef _DEBUG + bool m_bREFLECT; +#endif +public: + void SetREFLECT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nREFLECT = i; +#ifdef _DEBUG + m_bREFLECT = true; +#endif + } + void SetREFLECT( bool i ) + { + m_nREFLECT = i ? 1 : 0; +#ifdef _DEBUG + m_bREFLECT = true; +#endif + } +private: + int m_nREFRACT; +#ifdef _DEBUG + bool m_bREFRACT; +#endif +public: + void SetREFRACT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nREFRACT = i; +#ifdef _DEBUG + m_bREFRACT = true; +#endif + } + void SetREFRACT( bool i ) + { + m_nREFRACT = i ? 1 : 0; +#ifdef _DEBUG + m_bREFRACT = true; +#endif + } +private: + int m_nABOVEWATER; +#ifdef _DEBUG + bool m_bABOVEWATER; +#endif +public: + void SetABOVEWATER( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nABOVEWATER = i; +#ifdef _DEBUG + m_bABOVEWATER = true; +#endif + } + void SetABOVEWATER( bool i ) + { + m_nABOVEWATER = i ? 1 : 0; +#ifdef _DEBUG + m_bABOVEWATER = true; +#endif + } +private: + int m_nBLURRY_REFRACT; +#ifdef _DEBUG + bool m_bBLURRY_REFRACT; +#endif +public: + void SetBLURRY_REFRACT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nBLURRY_REFRACT = i; +#ifdef _DEBUG + m_bBLURRY_REFRACT = true; +#endif + } + void SetBLURRY_REFRACT( bool i ) + { + m_nBLURRY_REFRACT = i ? 1 : 0; +#ifdef _DEBUG + m_bBLURRY_REFRACT = true; +#endif + } +private: + int m_nNORMAL_DECODE_MODE; +#ifdef _DEBUG + bool m_bNORMAL_DECODE_MODE; +#endif +public: + void SetNORMAL_DECODE_MODE( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nNORMAL_DECODE_MODE = i; +#ifdef _DEBUG + m_bNORMAL_DECODE_MODE = true; +#endif + } + void SetNORMAL_DECODE_MODE( bool i ) + { + m_nNORMAL_DECODE_MODE = i ? 1 : 0; +#ifdef _DEBUG + m_bNORMAL_DECODE_MODE = true; +#endif + } +public: + water_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; +#ifdef _DEBUG + m_bBASETEXTURE = false; +#endif // _DEBUG + m_nBASETEXTURE = 0; +#ifdef _DEBUG + m_bMULTITEXTURE = false; +#endif // _DEBUG + m_nMULTITEXTURE = 0; +#ifdef _DEBUG + m_bREFLECT = false; +#endif // _DEBUG + m_nREFLECT = 0; +#ifdef _DEBUG + m_bREFRACT = false; +#endif // _DEBUG + m_nREFRACT = 0; +#ifdef _DEBUG + m_bABOVEWATER = false; +#endif // _DEBUG + m_nABOVEWATER = 0; +#ifdef _DEBUG + m_bBLURRY_REFRACT = false; +#endif // _DEBUG + m_nBLURRY_REFRACT = 0; +#ifdef _DEBUG + m_bNORMAL_DECODE_MODE = false; +#endif // _DEBUG + m_nNORMAL_DECODE_MODE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB && m_bBASETEXTURE && m_bMULTITEXTURE && m_bREFLECT && m_bREFRACT && m_bABOVEWATER && m_bBLURRY_REFRACT && m_bNORMAL_DECODE_MODE; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nCONVERT_TO_SRGB ) + ( 2 * m_nBASETEXTURE ) + ( 4 * m_nMULTITEXTURE ) + ( 8 * m_nREFLECT ) + ( 16 * m_nREFRACT ) + ( 32 * m_nABOVEWATER ) + ( 64 * m_nBLURRY_REFRACT ) + ( 128 * m_nNORMAL_DECODE_MODE ) + 0; + } +}; +#define shaderStaticTest_water_ps20b psh_forgot_to_set_static_BASETEXTURE + psh_forgot_to_set_static_MULTITEXTURE + psh_forgot_to_set_static_REFLECT + psh_forgot_to_set_static_REFRACT + psh_forgot_to_set_static_ABOVEWATER + psh_forgot_to_set_static_BLURRY_REFRACT + psh_forgot_to_set_static_NORMAL_DECODE_MODE + 0 +class water_ps20b_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +private: + int m_nWRITE_DEPTH_TO_DESTALPHA; +#ifdef _DEBUG + bool m_bWRITE_DEPTH_TO_DESTALPHA; +#endif +public: + void SetWRITE_DEPTH_TO_DESTALPHA( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nWRITE_DEPTH_TO_DESTALPHA = i; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = true; +#endif + } + void SetWRITE_DEPTH_TO_DESTALPHA( bool i ) + { + m_nWRITE_DEPTH_TO_DESTALPHA = i ? 1 : 0; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = true; +#endif + } +public: + water_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; +#ifdef _DEBUG + m_bWRITE_DEPTH_TO_DESTALPHA = false; +#endif // _DEBUG + m_nWRITE_DEPTH_TO_DESTALPHA = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE && m_bWRITE_DEPTH_TO_DESTALPHA; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + ( 2 * m_nWRITE_DEPTH_TO_DESTALPHA ) + 0; + } +}; +#define shaderDynamicTest_water_ps20b psh_forgot_to_set_dynamic_PIXELFOGTYPE + psh_forgot_to_set_dynamic_WRITE_DEPTH_TO_DESTALPHA + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/white_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/white_ps20.inc new file mode 100644 index 0000000..ccf4539 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/white_ps20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class white_ps20_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + white_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_white_ps20 0 +class white_ps20_Dynamic_Index +{ +public: + white_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_white_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/white_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/white_ps20b.inc new file mode 100644 index 0000000..e66ac83 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/white_ps20b.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class white_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + white_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_white_ps20b 0 +class white_ps20b_Dynamic_Index +{ +public: + white_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_white_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/windowimposter_ps11.inc b/materialsystem/stdshaders/fxctmp9_360/windowimposter_ps11.inc new file mode 100644 index 0000000..1e46457 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/windowimposter_ps11.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class windowimposter_ps11_Static_Index +{ +public: + windowimposter_ps11_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_windowimposter_ps11 0 +class windowimposter_ps11_Dynamic_Index +{ +public: + windowimposter_ps11_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_windowimposter_ps11 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/windowimposter_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/windowimposter_ps20.inc new file mode 100644 index 0000000..c37e6de --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/windowimposter_ps20.inc @@ -0,0 +1,87 @@ +#include "shaderlib/cshader.h" +class windowimposter_ps20_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + windowimposter_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_windowimposter_ps20 0 +class windowimposter_ps20_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + windowimposter_ps20_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_windowimposter_ps20 psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/windowimposter_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/windowimposter_ps20b.inc new file mode 100644 index 0000000..b620aac --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/windowimposter_ps20b.inc @@ -0,0 +1,87 @@ +#include "shaderlib/cshader.h" +class windowimposter_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +public: + windowimposter_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nCONVERT_TO_SRGB ) + 0; + } +}; +#define shaderStaticTest_windowimposter_ps20b 0 +class windowimposter_ps20b_Dynamic_Index +{ +private: + int m_nPIXELFOGTYPE; +#ifdef _DEBUG + bool m_bPIXELFOGTYPE; +#endif +public: + void SetPIXELFOGTYPE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPIXELFOGTYPE = i; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } + void SetPIXELFOGTYPE( bool i ) + { + m_nPIXELFOGTYPE = i ? 1 : 0; +#ifdef _DEBUG + m_bPIXELFOGTYPE = true; +#endif + } +public: + windowimposter_ps20b_Dynamic_Index() + { +#ifdef _DEBUG + m_bPIXELFOGTYPE = false; +#endif // _DEBUG + m_nPIXELFOGTYPE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bPIXELFOGTYPE; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nPIXELFOGTYPE ) + 0; + } +}; +#define shaderDynamicTest_windowimposter_ps20b psh_forgot_to_set_dynamic_PIXELFOGTYPE + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/windowimposter_vs11.inc b/materialsystem/stdshaders/fxctmp9_360/windowimposter_vs11.inc new file mode 100644 index 0000000..0f8fe63 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/windowimposter_vs11.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class windowimposter_vs11_Static_Index +{ +public: + windowimposter_vs11_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_windowimposter_vs11 0 +class windowimposter_vs11_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + windowimposter_vs11_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; +#define shaderDynamicTest_windowimposter_vs11 vsh_forgot_to_set_dynamic_DOWATERFOG + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/windowimposter_vs20.inc b/materialsystem/stdshaders/fxctmp9_360/windowimposter_vs20.inc new file mode 100644 index 0000000..b99a21a --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/windowimposter_vs20.inc @@ -0,0 +1,60 @@ +#include "shaderlib/cshader.h" +class windowimposter_vs20_Static_Index +{ +public: + windowimposter_vs20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_windowimposter_vs20 0 +class windowimposter_vs20_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + windowimposter_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; +#define shaderDynamicTest_windowimposter_vs20 vsh_forgot_to_set_dynamic_DOWATERFOG + 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/worldvertexalpha_ps20.inc b/materialsystem/stdshaders/fxctmp9_360/worldvertexalpha_ps20.inc new file mode 100644 index 0000000..16093d2 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/worldvertexalpha_ps20.inc @@ -0,0 +1,85 @@ +#include "shaderlib/cshader.h" +class worldvertexalpha_ps20_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +private: + int m_nPASS; +#ifdef _DEBUG + bool m_bPASS; +#endif +public: + void SetPASS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPASS = i; +#ifdef _DEBUG + m_bPASS = true; +#endif + } + void SetPASS( bool i ) + { + m_nPASS = i ? 1 : 0; +#ifdef _DEBUG + m_bPASS = true; +#endif + } +public: + worldvertexalpha_ps20_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; +#ifdef _DEBUG + m_bPASS = false; +#endif // _DEBUG + m_nPASS = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB && m_bPASS; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + ( 1 * m_nPASS ) + 0; + } +}; +#define shaderStaticTest_worldvertexalpha_ps20 psh_forgot_to_set_static_PASS + 0 +class worldvertexalpha_ps20_Dynamic_Index +{ +public: + worldvertexalpha_ps20_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_worldvertexalpha_ps20 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/worldvertexalpha_ps20b.inc b/materialsystem/stdshaders/fxctmp9_360/worldvertexalpha_ps20b.inc new file mode 100644 index 0000000..a09c3c4 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/worldvertexalpha_ps20b.inc @@ -0,0 +1,85 @@ +#include "shaderlib/cshader.h" +class worldvertexalpha_ps20b_Static_Index +{ +private: + int m_nCONVERT_TO_SRGB; +#ifdef _DEBUG + bool m_bCONVERT_TO_SRGB; +#endif +public: + void SetCONVERT_TO_SRGB( int i ) + { + Assert( i >= 0 && i <= 0 ); + m_nCONVERT_TO_SRGB = i; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } + void SetCONVERT_TO_SRGB( bool i ) + { + m_nCONVERT_TO_SRGB = i ? 1 : 0; +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif + } +private: + int m_nPASS; +#ifdef _DEBUG + bool m_bPASS; +#endif +public: + void SetPASS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nPASS = i; +#ifdef _DEBUG + m_bPASS = true; +#endif + } + void SetPASS( bool i ) + { + m_nPASS = i ? 1 : 0; +#ifdef _DEBUG + m_bPASS = true; +#endif + } +public: + worldvertexalpha_ps20b_Static_Index( ) + { +#ifdef _DEBUG + m_bCONVERT_TO_SRGB = true; +#endif // _DEBUG + m_nCONVERT_TO_SRGB = 0; +#ifdef _DEBUG + m_bPASS = false; +#endif // _DEBUG + m_nPASS = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bCONVERT_TO_SRGB && m_bPASS; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCONVERT_TO_SRGB ) + ( 1 * m_nPASS ) + 0; + } +}; +#define shaderStaticTest_worldvertexalpha_ps20b psh_forgot_to_set_static_PASS + 0 +class worldvertexalpha_ps20b_Dynamic_Index +{ +public: + worldvertexalpha_ps20b_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_worldvertexalpha_ps20b 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/writevertexalphatodestalpha_ps11.inc b/materialsystem/stdshaders/fxctmp9_360/writevertexalphatodestalpha_ps11.inc new file mode 100644 index 0000000..8185a31 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/writevertexalphatodestalpha_ps11.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class writevertexalphatodestalpha_ps11_Static_Index +{ +public: + writevertexalphatodestalpha_ps11_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_writevertexalphatodestalpha_ps11 0 +class writevertexalphatodestalpha_ps11_Dynamic_Index +{ +public: + writevertexalphatodestalpha_ps11_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_writevertexalphatodestalpha_ps11 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/writevertexalphatodestalpha_vs11.inc b/materialsystem/stdshaders/fxctmp9_360/writevertexalphatodestalpha_vs11.inc new file mode 100644 index 0000000..07f29e0 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/writevertexalphatodestalpha_vs11.inc @@ -0,0 +1,33 @@ +#include "shaderlib/cshader.h" +class writevertexalphatodestalpha_vs11_Static_Index +{ +public: + writevertexalphatodestalpha_vs11_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_writevertexalphatodestalpha_vs11 0 +class writevertexalphatodestalpha_vs11_Dynamic_Index +{ +public: + writevertexalphatodestalpha_vs11_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderDynamicTest_writevertexalphatodestalpha_vs11 0 diff --git a/materialsystem/stdshaders/fxctmp9_360/writez_vs20.inc b/materialsystem/stdshaders/fxctmp9_360/writez_vs20.inc new file mode 100644 index 0000000..fd2ced2 --- /dev/null +++ b/materialsystem/stdshaders/fxctmp9_360/writez_vs20.inc @@ -0,0 +1,85 @@ +#include "shaderlib/cshader.h" +class writez_vs20_Static_Index +{ +public: + writez_vs20_Static_Index( ) + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +#define shaderStaticTest_writez_vs20 0 +class writez_vs20_Dynamic_Index +{ +private: + int m_nCOMPRESSED_VERTS; +#ifdef _DEBUG + bool m_bCOMPRESSED_VERTS; +#endif +public: + void SetCOMPRESSED_VERTS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nCOMPRESSED_VERTS = i; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } + void SetCOMPRESSED_VERTS( bool i ) + { + m_nCOMPRESSED_VERTS = i ? 1 : 0; +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = true; +#endif + } +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + writez_vs20_Dynamic_Index() + { +#ifdef _DEBUG + m_bCOMPRESSED_VERTS = false; +#endif // _DEBUG + m_nCOMPRESSED_VERTS = 0; +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bCOMPRESSED_VERTS && m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nCOMPRESSED_VERTS ) + ( 2 * m_nDOWATERFOG ) + 0; + } +}; +#define shaderDynamicTest_writez_vs20 vsh_forgot_to_set_dynamic_COMPRESSED_VERTS + vsh_forgot_to_set_dynamic_DOWATERFOG + 0 diff --git a/materialsystem/stdshaders/genwaterloop.pl b/materialsystem/stdshaders/genwaterloop.pl new file mode 100644 index 0000000..64ad065 --- /dev/null +++ b/materialsystem/stdshaders/genwaterloop.pl @@ -0,0 +1,9 @@ +for($ix=-2;$ix<=2;$ix++) +{ + for($iy=-2;$iy<=2;$iy++) + { + print "vRefractColor += tex2D( RefractSampler, vRefractTexCoord + $ix * ddx1 + $iy * ddy1 );\n"; + $sumweights+=1; + } +} +print "float sumweights = $sumweights;\n"; diff --git a/materialsystem/stdshaders/glowwarp.psh b/materialsystem/stdshaders/glowwarp.psh new file mode 100644 index 0000000..aa72c1a --- /dev/null +++ b/materialsystem/stdshaders/glowwarp.psh @@ -0,0 +1,20 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; Draw a texture . . woo hoo! +; t0 - texture +; +; The texture coordinates need to be defined as follows: +; tc0 - texcoords +;------------------------------------------------------------------------------ + +; Get the color from the texture +tex t0 + +mul r0, t0, v0 +;mul_x2 r0, t0, v0 +;mov r0, v0 +;mul r0, t0, c0 + + + diff --git a/materialsystem/stdshaders/gooinglass.cpp b/materialsystem/stdshaders/gooinglass.cpp new file mode 100644 index 0000000..4b04621 --- /dev/null +++ b/materialsystem/stdshaders/gooinglass.cpp @@ -0,0 +1,169 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//=============================================================================// + +#include "BaseVSShader.h" + +#include "bumpmappedenvmap.inc" + +#include "lightmappedgeneric_vs11.inc" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +// FIXME: Need to make a dx9 version so that "CENTROID" works. + +BEGIN_VS_SHADER( GooInGlass, + "Help for GooInGlass" ) + + BEGIN_SHADER_PARAMS + SHADER_PARAM_OVERRIDE( BASETEXTURE, SHADER_PARAM_TYPE_TEXTURE, "shadertest/GooInGlass", "Base texture", 0 ) + SHADER_PARAM_OVERRIDE( COLOR, SHADER_PARAM_TYPE_COLOR, "{255 255 255}", "unused", SHADER_PARAM_NOT_EDITABLE ) + SHADER_PARAM_OVERRIDE( ALPHA, SHADER_PARAM_TYPE_FLOAT, "1.0", "unused", SHADER_PARAM_NOT_EDITABLE ) + SHADER_PARAM( BUMPMAP, SHADER_PARAM_TYPE_TEXTURE, "shadertest/GooInGlass_normal", "bump map" ) + SHADER_PARAM( BUMPTRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$bump texcoord transform" ) + SHADER_PARAM( ENVMAP, SHADER_PARAM_TYPE_TEXTURE, "shadertest/GooInGlass_env", "envmap" ) + SHADER_PARAM( GLASSENVMAP, SHADER_PARAM_TYPE_TEXTURE, "shadertest/GooInGlass_envglass", "Glass Envmap" ) + SHADER_PARAM( ENVMAPTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "envmap tint" ) + SHADER_PARAM( GLASSENVMAPTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "envmap tint" ) + SHADER_PARAM( TRANSLUCENTGOO, SHADER_PARAM_TYPE_BOOL, "0", "whether or not goo is translucent" ) + END_SHADER_PARAMS + + SHADER_INIT + { + LoadBumpMap( BUMPMAP ); + LoadTexture( BASETEXTURE ); + LoadCubeMap( ENVMAP ); + LoadCubeMap( GLASSENVMAP ); + if( !params[ENVMAPTINT]->IsDefined() ) + { + params[ENVMAPTINT]->SetVecValue( 1.0f, 1.0f, 1.0f ); + } + if( !params[GLASSENVMAPTINT]->IsDefined() ) + { + params[GLASSENVMAPTINT]->SetVecValue( 1.0f, 1.0f, 1.0f ); + } + if( !params[TRANSLUCENTGOO]->IsDefined() ) + { + params[TRANSLUCENTGOO]->SetIntValue( 0 ); + } + } + + SHADER_DRAW + { + // + MASKED BUMPED CUBEMAP * ENVMAPTINT + SHADOW_STATE + { + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER3, true ); + if( params[TRANSLUCENTGOO]->GetIntValue() ) + { + pShaderShadow->EnableBlending( true ); + pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE ); + } + // FIXME: Remove the normal (needed for tangent space gen) + pShaderShadow->VertexShaderVertexFormat( + VERTEX_POSITION | VERTEX_NORMAL | VERTEX_TANGENT_S | + VERTEX_TANGENT_T, 1, 0, 0 ); + + bumpmappedenvmap_Static_Index vshIndex; + pShaderShadow->SetVertexShader( "BumpmappedEnvmap", vshIndex.GetIndex() ); + + pShaderShadow->SetPixelShader( "BumpmappedEnvmap" ); + FogToBlack(); + } + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER0, BUMPMAP ); + BindTexture( SHADER_SAMPLER3, ENVMAP ); + + float constantColor[4]; + params[ENVMAPTINT]->GetVecValue( constantColor, 3 ); + constantColor[3] = 0.0f; + pShaderAPI->SetPixelShaderConstant( 0, constantColor, 1 ); + + // handle scrolling of bump texture + SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_4, BUMPTRANSFORM ); + + bumpmappedenvmap_Dynamic_Index vshIndex; + vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() ); + } + Draw(); + // glass envmap + SHADOW_STATE + { + SetInitialShadowState( ); + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER3, true ); + pShaderShadow->EnableBlending( true ); + pShaderShadow->BlendFunc( SHADER_BLEND_ONE, SHADER_BLEND_ONE ); + + // FIXME: Remove the normal (needed for tangent space gen) + pShaderShadow->VertexShaderVertexFormat( + VERTEX_POSITION | VERTEX_NORMAL | VERTEX_TANGENT_S | + VERTEX_TANGENT_T, 1, 0, 0 ); + + bumpmappedenvmap_Static_Index vshIndex; + pShaderShadow->SetVertexShader( "BumpmappedEnvmap", vshIndex.GetIndex() ); + + pShaderShadow->SetPixelShader( "BumpmappedEnvMap" ); + FogToBlack(); + } + DYNAMIC_STATE + { + // fixme: doesn't support camera space envmapping!!!!!! + pShaderAPI->BindStandardTexture( SHADER_SAMPLER0, TEXTURE_NORMALMAP_FLAT ); + BindTexture( SHADER_SAMPLER3, GLASSENVMAP ); + + float constantColor[4]; + params[GLASSENVMAPTINT]->GetVecValue( constantColor, 3 ); + constantColor[3] = 0.0f; + pShaderAPI->SetPixelShaderConstant( 0, constantColor, 1 ); + SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_4, BUMPTRANSFORM ); + bumpmappedenvmap_Dynamic_Index vshIndex; + vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + + pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() ); + } + Draw(); + + // BASE TEXTURE * LIGHTMAP + SHADOW_STATE + { + SET_FLAGS2( MATERIAL_VAR2_LIGHTING_LIGHTMAP ); + SetInitialShadowState( ); + pShaderShadow->EnableBlending( true ); + pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA ); + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + pShaderShadow->VertexShaderVertexFormat( VERTEX_POSITION, 2, 0, 0 ); + + lightmappedgeneric_vs11_Static_Index vshIndex; + vshIndex.SetDETAIL( false ); + vshIndex.SetENVMAP( false ); + vshIndex.SetENVMAPCAMERASPACE( false ); + vshIndex.SetENVMAPSPHERE( false ); + vshIndex.SetVERTEXCOLOR( false ); + pShaderShadow->SetVertexShader( "LightmappedGeneric_vs11", vshIndex.GetIndex() ); + + pShaderShadow->SetPixelShader( "LightmappedGeneric" ); + FogToFogColor(); + } + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME ); + pShaderAPI->BindStandardTexture( SHADER_SAMPLER1, TEXTURE_LIGHTMAP ); + SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, BASETEXTURETRANSFORM ); + EnablePixelShaderOverbright( true, 0, true ); + + lightmappedgeneric_vs11_Dynamic_Index vshIndex; + vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() ); + } + Draw(); + } +END_SHADER diff --git a/materialsystem/stdshaders/haloadd1d_ps2x.fxc b/materialsystem/stdshaders/haloadd1d_ps2x.fxc new file mode 100644 index 0000000..a392de2 --- /dev/null +++ b/materialsystem/stdshaders/haloadd1d_ps2x.fxc @@ -0,0 +1,35 @@ +//======= Copyright © 1996-2006, Valve Corporation, All rights reserved. ====== + +#include "common_ps_fxc.h" + +sampler TexSampler : register( s0 ); +sampler TexRed : register( s1 ); +sampler TexGreen : register( s2 ); +sampler TexBlue : register( s3 ); + +float g_flDimValue : register( c0 ); + +struct PS_INPUT +{ + HALF2 baseTexCoord : TEXCOORD0; // Base texture coordinate +}; + +float4 main( PS_INPUT i ) : COLOR +{ + float4 result = tex2D( TexSampler, i.baseTexCoord ); + + // Scale by dim value before computing luminance below + result.rgb *= saturate( g_flDimValue ); + + // Fetch into 1D textures based on the intensity of each color channel and sum + float4 vRed = tex2D( TexRed, pow( result.r, 0.45 ) ); + float4 vGreen = tex2D( TexGreen, pow( result.g, 0.45 ) ); + float4 vBlue = tex2D( TexBlue, pow( result.b, 0.45 ) ); + result.rgb = vRed.rgb + vGreen.rgb + vBlue.rgb; + + // Store max color component in alpha for alpha blend of one/invSrcAlpha + float flLuminance = max( result.r, max( result.g, result.b ) ); + result.a = flLuminance; + + return result.rgba; +} diff --git a/materialsystem/stdshaders/haloadd_ps2x.fxc b/materialsystem/stdshaders/haloadd_ps2x.fxc new file mode 100644 index 0000000..9496f59 --- /dev/null +++ b/materialsystem/stdshaders/haloadd_ps2x.fxc @@ -0,0 +1,26 @@ +//======= Copyright © 1996-2006, Valve Corporation, All rights reserved. ====== + +#include "common_ps_fxc.h" + +sampler TexSampler : register( s0 ); + +float g_flDimValue : register( c0 ); + +struct PS_INPUT +{ + HALF2 baseTexCoord : TEXCOORD0; // Base texture coordinate +}; + +float4 main( PS_INPUT i ) : COLOR +{ + float4 result = tex2D( TexSampler, i.baseTexCoord ); + + // Scale by dim value before computing luminance below + result.rgb *= saturate( g_flDimValue ); + + // Store max color component in alpha for alpha blend of one/invSrcAlpha + float flLuminance = max( result.r, max( result.g, result.b ) ); + result.a = pow( flLuminance, 0.8f ); + + return result.rgba; +} diff --git a/materialsystem/stdshaders/haloaddoutline_ps2x.fxc b/materialsystem/stdshaders/haloaddoutline_ps2x.fxc new file mode 100644 index 0000000..8e3127c --- /dev/null +++ b/materialsystem/stdshaders/haloaddoutline_ps2x.fxc @@ -0,0 +1,34 @@ +//======= Copyright © 1996-2006, Valve Corporation, All rights reserved. ====== + +#include "common_ps_fxc.h" + +sampler TexSampler : register( s0 ); +sampler TexRed : register( s1 ); +sampler TexGreen : register( s2 ); +sampler TexBlue : register( s3 ); + +float2 g_vPixelSize : register( c4 ); + +struct PS_INPUT +{ + float2 baseTexCoord : TEXCOORD0; // Base texture coordinate +}; + +float4 main( PS_INPUT i ) : COLOR +{ + // Make outline 2 pixels wide $C0_X in a vmt doesn't seem to work in staging so I can't parameterize this right now + float2 vOffset = 2.0f * g_vPixelSize.xy; + + // Take the max of 4 offset texture samples + float4 result; + result.rgba = tex2D( TexSampler, i.baseTexCoord.xy + float2( vOffset.x, vOffset.y ) ); + result.rgba = max( result.rgba, tex2D( TexSampler, i.baseTexCoord.xy + float2( vOffset.x, -vOffset.y ) ) ); + result.rgba = max( result.rgba, tex2D( TexSampler, i.baseTexCoord.xy + float2( -vOffset.x, vOffset.y ) ) ); + result.rgba = max( result.rgba, tex2D( TexSampler, i.baseTexCoord.xy + float2( -vOffset.x, -vOffset.y ) ) ); + + // Store max color component in alpha for alpha blend of one/invSrcAlpha + float flLuminance = max( result.r, max( result.g, result.b ) ); + result.a = flLuminance; + + return result.rgba; +} diff --git a/materialsystem/stdshaders/hsl_filmgrain_pass1.cpp b/materialsystem/stdshaders/hsl_filmgrain_pass1.cpp new file mode 100644 index 0000000..e2a3527 --- /dev/null +++ b/materialsystem/stdshaders/hsl_filmgrain_pass1.cpp @@ -0,0 +1,103 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//============================================================================= + +#include "BaseVSShader.h" +#include "convar.h" +#include "filmgrain_vs20.inc" +#include "hsl_filmgrain_pass1_ps20.inc" +#include "hsl_filmgrain_pass1_ps20b.inc" + +// +// First pass converts from RGB to HSL and tweaks with noise similar to After Effects +// + +BEGIN_VS_SHADER( hsl_filmgrain_pass1, "Help for Film Grain" ) + BEGIN_SHADER_PARAMS + // Input textures + SHADER_PARAM( INPUT, SHADER_PARAM_TYPE_TEXTURE, "", "" ) + SHADER_PARAM( GRAIN, SHADER_PARAM_TYPE_TEXTURE, "", "" ) + + // Grain parameters to control positioning and noise params + SHADER_PARAM( SCALEBIAS, SHADER_PARAM_TYPE_VEC4, "", "Scale and bias for grain placement" ) + SHADER_PARAM( HSLNOISESCALE, SHADER_PARAM_TYPE_VEC4, "", "Strength of film grain" ) + + END_SHADER_PARAMS + + SHADER_INIT + { + LoadTexture( INPUT ); + LoadTexture( GRAIN ); + } + + SHADER_FALLBACK + { + // Requires DX9 + above + if (!g_pHardwareConfig->SupportsVertexAndPixelShaders()) + { + Assert( 0 ); + return "Wireframe"; + } + return 0; + } + + SHADER_DRAW + { + SHADOW_STATE + { + pShaderShadow->EnableDepthWrites( false ); + pShaderShadow->EnableDepthTest( false ); + pShaderShadow->EnableAlphaWrites( false ); + pShaderShadow->EnableBlending( false ); + pShaderShadow->EnableCulling( false ); +// pShaderShadow->PolyMode( SHADER_POLYMODEFACE_FRONT_AND_BACK, SHADER_POLYMODE_LINE ); + + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + int fmt = VERTEX_POSITION; + pShaderShadow->VertexShaderVertexFormat( fmt, 1, 0, 0 ); + + DECLARE_STATIC_VERTEX_SHADER( filmgrain_vs20 ); + SET_STATIC_VERTEX_SHADER( filmgrain_vs20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_STATIC_PIXEL_SHADER( hsl_filmgrain_pass1_ps20b ); + SET_STATIC_PIXEL_SHADER( hsl_filmgrain_pass1_ps20b ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( hsl_filmgrain_pass1_ps20 ); + SET_STATIC_PIXEL_SHADER( hsl_filmgrain_pass1_ps20 ); + } + } + + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER0, INPUT, -1 ); + BindTexture( SHADER_SAMPLER1, GRAIN, -1 ); + + SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, SCALEBIAS ); + + SetPixelShaderConstant( 0, HSLNOISESCALE ); + + DECLARE_DYNAMIC_VERTEX_SHADER( filmgrain_vs20 ); + SET_DYNAMIC_VERTEX_SHADER( filmgrain_vs20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_DYNAMIC_PIXEL_SHADER( hsl_filmgrain_pass1_ps20b ); + SET_DYNAMIC_PIXEL_SHADER( hsl_filmgrain_pass1_ps20b ); + } + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( hsl_filmgrain_pass1_ps20 ); + SET_DYNAMIC_PIXEL_SHADER( hsl_filmgrain_pass1_ps20 ); + } + } + Draw(); + } +END_SHADER diff --git a/materialsystem/stdshaders/hsl_filmgrain_pass1_ps2x.fxc b/materialsystem/stdshaders/hsl_filmgrain_pass1_ps2x.fxc new file mode 100644 index 0000000..5a98300 --- /dev/null +++ b/materialsystem/stdshaders/hsl_filmgrain_pass1_ps2x.fxc @@ -0,0 +1,26 @@ +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX] + +#define HDRTYPE HDR_TYPE_NONE +#include "common_ps_fxc.h" + +sampler InputSampler : register( s0 ); +sampler FilmGrain : register( s1 ); + +const float4 vNoiseScale : register( c0 ); + +struct PS_INPUT +{ + float2 inputImageCoords : TEXCOORD0; // Input image having grain added + float2 filmGrainCoords : TEXCOORD1; // Tiling film grain texture +}; + +float4 main( PS_INPUT i ) : COLOR +{ + float3 hsl = RGBtoHSL( tex2D( InputSampler, i.inputImageCoords ) ); + float3 hslNoise = tex2D( FilmGrain, i.filmGrainCoords ) * 2.0f - 1.0f; + + hsl += hslNoise * vNoiseScale * float3( 0.5f, 1.0f, 1.0f ); + + return FinalOutput( float4 ( hsl, 1.0f ), 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE ); +} diff --git a/materialsystem/stdshaders/hsl_filmgrain_pass2.cpp b/materialsystem/stdshaders/hsl_filmgrain_pass2.cpp new file mode 100644 index 0000000..1229c13 --- /dev/null +++ b/materialsystem/stdshaders/hsl_filmgrain_pass2.cpp @@ -0,0 +1,93 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//============================================================================= + +#include "BaseVSShader.h" +#include "convar.h" +#include "filmgrain_vs20.inc" +#include "hsl_filmgrain_pass2_ps20.inc" +#include "hsl_filmgrain_pass2_ps20b.inc" + + +// +// Second pass merely converts from HSL back to RGB space, noise was already applied in first pass +// + +BEGIN_VS_SHADER( hsl_filmgrain_pass2, "Help for Film Grain" ) + BEGIN_SHADER_PARAMS + SHADER_PARAM( INPUT, SHADER_PARAM_TYPE_TEXTURE, "", "" ) + + END_SHADER_PARAMS + + SHADER_INIT + { + LoadTexture( INPUT ); + } + + SHADER_FALLBACK + { + // Requires DX9 + above + if (!g_pHardwareConfig->SupportsVertexAndPixelShaders()) + { + Assert( 0 ); + return "Wireframe"; + } + return 0; + } + + SHADER_DRAW + { + SHADOW_STATE + { + pShaderShadow->EnableDepthWrites( false ); + pShaderShadow->EnableDepthTest( false ); + pShaderShadow->EnableAlphaWrites( false ); + pShaderShadow->EnableBlending( false ); + pShaderShadow->EnableCulling( false ); +// pShaderShadow->PolyMode( SHADER_POLYMODEFACE_FRONT_AND_BACK, SHADER_POLYMODE_LINE ); + + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + int fmt = VERTEX_POSITION; + pShaderShadow->VertexShaderVertexFormat( fmt, 1, 0, 0 ); + + DECLARE_STATIC_VERTEX_SHADER( filmgrain_vs20 ); + SET_STATIC_VERTEX_SHADER( filmgrain_vs20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_STATIC_PIXEL_SHADER( hsl_filmgrain_pass2_ps20b ); + SET_STATIC_PIXEL_SHADER( hsl_filmgrain_pass2_ps20b ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( hsl_filmgrain_pass2_ps20 ); + SET_STATIC_PIXEL_SHADER( hsl_filmgrain_pass2_ps20 ); + } + } + + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER0, INPUT, -1 ); + + DECLARE_DYNAMIC_VERTEX_SHADER( filmgrain_vs20 ); + SET_DYNAMIC_VERTEX_SHADER( filmgrain_vs20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_DYNAMIC_PIXEL_SHADER( hsl_filmgrain_pass2_ps20b ); + SET_DYNAMIC_PIXEL_SHADER( hsl_filmgrain_pass2_ps20b ); + } + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( hsl_filmgrain_pass2_ps20 ); + SET_DYNAMIC_PIXEL_SHADER( hsl_filmgrain_pass2_ps20 ); + } + } + Draw(); + } +END_SHADER + + diff --git a/materialsystem/stdshaders/hsl_filmgrain_pass2_ps2x.fxc b/materialsystem/stdshaders/hsl_filmgrain_pass2_ps2x.fxc new file mode 100644 index 0000000..1203a00 --- /dev/null +++ b/materialsystem/stdshaders/hsl_filmgrain_pass2_ps2x.fxc @@ -0,0 +1,19 @@ +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX] + +#define HDRTYPE HDR_TYPE_NONE +#include "common_ps_fxc.h" + +sampler InputSampler : register( s0 ); + +struct PS_INPUT +{ + float2 inputImageCoords : TEXCOORD0; // Input image + float2 filmGrainCoords : TEXCOORD1; // Tiling film grain texture +}; + +float4 main( PS_INPUT i ) : COLOR +{ + return FinalOutput( HSLtoRGB( tex2D( InputSampler, i.inputImageCoords ) ), 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE ); +} + diff --git a/materialsystem/stdshaders/hsv.cpp b/materialsystem/stdshaders/hsv.cpp new file mode 100644 index 0000000..a5e3d4a --- /dev/null +++ b/materialsystem/stdshaders/hsv.cpp @@ -0,0 +1,67 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//=============================================================================// + +#include "BaseVSShader.h" +#include "screenspaceeffect_vs20.inc" +#include "hsv_ps20.inc" +#include "hsv_ps20b.inc" + +BEGIN_VS_SHADER_FLAGS( HSV, "Help for HSV", SHADER_NOT_EDITABLE ) + BEGIN_SHADER_PARAMS + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + SET_FLAGS2( MATERIAL_VAR2_NEEDS_FULL_FRAME_BUFFER_TEXTURE ); + } + + SHADER_INIT + { + } + + SHADER_FALLBACK + { + // Requires DX9 + above + if (g_pHardwareConfig->GetDXSupportLevel() < 90) + { + Assert( 0 ); + return "Wireframe"; + } + return 0; + } + + SHADER_DRAW + { + SHADOW_STATE + { + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + int fmt = VERTEX_POSITION; + pShaderShadow->VertexShaderVertexFormat( fmt, 1, 0, 0 ); + + DECLARE_STATIC_VERTEX_SHADER( screenspaceeffect_vs20 ); + SET_STATIC_VERTEX_SHADER( screenspaceeffect_vs20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_STATIC_PIXEL_SHADER( hsv_ps20b ); + SET_STATIC_PIXEL_SHADER( hsv_ps20b ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( hsv_ps20 ); + SET_STATIC_PIXEL_SHADER( hsv_ps20 ); + } + } + DYNAMIC_STATE + { + pShaderAPI->BindStandardTexture( SHADER_SAMPLER0, TEXTURE_FRAME_BUFFER_FULL_TEXTURE_0 ); + DECLARE_DYNAMIC_VERTEX_SHADER( screenspaceeffect_vs20 ); + SET_DYNAMIC_VERTEX_SHADER( screenspaceeffect_vs20 ); + } + Draw(); + } +END_SHADER diff --git a/materialsystem/stdshaders/hsv_ps2x.fxc b/materialsystem/stdshaders/hsv_ps2x.fxc new file mode 100644 index 0000000..617b90d --- /dev/null +++ b/materialsystem/stdshaders/hsv_ps2x.fxc @@ -0,0 +1,27 @@ +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX] + +#define HDRTYPE HDR_TYPE_NONE +#include "common_ps_fxc.h" + +sampler BaseTextureSampler : register( s0 ); + +struct PS_INPUT +{ + float2 baseTexCoord : TEXCOORD0; +}; + +HALF4 main( PS_INPUT i ) : COLOR +{ + HALF4 result; + HALF4 baseColor; + HALF maxValue; + + baseColor = tex2D( BaseTextureSampler, i.baseTexCoord ); + maxValue = max( baseColor.r, baseColor.g ); + maxValue = max( baseColor.b, maxValue ); + result = maxValue; + result.a = 1.0f; + return FinalOutput( result, 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE ); +} + diff --git a/materialsystem/stdshaders/introscreenspaceeffect.cpp b/materialsystem/stdshaders/introscreenspaceeffect.cpp new file mode 100644 index 0000000..d233b51 --- /dev/null +++ b/materialsystem/stdshaders/introscreenspaceeffect.cpp @@ -0,0 +1,104 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//=============================================================================// + +#include "BaseVSShader.h" + +#include "screenspaceeffect_vs20.inc" +#include "IntroScreenSpaceEffect_ps20.inc" +#include "IntroScreenSpaceEffect_ps20b.inc" + +BEGIN_VS_SHADER_FLAGS( IntroScreenSpaceEffect, "Help for IntroScreenSpaceEffect", SHADER_NOT_EDITABLE ) + BEGIN_SHADER_PARAMS + SHADER_PARAM( MODE, SHADER_PARAM_TYPE_INTEGER, "0", "" ) + SHADER_PARAM( ENABLESRGB, SHADER_PARAM_TYPE_BOOL, "0", "" ) + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + SET_FLAGS2( MATERIAL_VAR2_NEEDS_FULL_FRAME_BUFFER_TEXTURE ); + + if ( !params[ENABLESRGB]->IsDefined() ) + { + params[ENABLESRGB]->SetIntValue( 0 ); + } + } + + SHADER_INIT + { + } + + SHADER_FALLBACK + { + // Requires DX9 + above + if ( IsWindows() && ( g_pHardwareConfig->GetDXSupportLevel() < 90 || g_pHardwareConfig->PreferReducedFillrate() ) ) + return "IntroScreenSpaceEffect_dx80"; + return 0; + } + + SHADER_DRAW + { + SHADOW_STATE + { + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + + // On OpenGL OSX, we MUST do sRGB reads from the bloom and full framebuffer textures AND sRGB writes on the way out to the framebuffer. + if ( params[ENABLESRGB]->GetIntValue() || IsOSX() ) + { + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, true ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER1, true ); + pShaderShadow->EnableSRGBWrite( true ); + } + + // Only need the adapter if the shader expects sRGB values and we're forced to do an sRGB read by the API/Hardware + bool bNeedsSRGBAdapter = ( params[ENABLESRGB]->GetIntValue() == 0 ) && IsOSX() && !g_pHardwareConfig->FakeSRGBWrite() && g_pHardwareConfig->CanDoSRGBReadFromRTs(); + + pShaderShadow->VertexShaderVertexFormat( VERTEX_POSITION, 1, 0, 0 ); + + DECLARE_STATIC_VERTEX_SHADER( screenspaceeffect_vs20 ); + SET_STATIC_VERTEX_SHADER( screenspaceeffect_vs20 ); + + if ( g_pHardwareConfig->SupportsPixelShaders_2_b() || g_pHardwareConfig->ShouldAlwaysUseShaderModel2bShaders() ) // GL always goes the ps2b way for this shader, even on "ps20" parts + { + DECLARE_STATIC_PIXEL_SHADER( introscreenspaceeffect_ps20b ); + SET_STATIC_PIXEL_SHADER_COMBO( LINEAR_TO_SRGB, bNeedsSRGBAdapter ); + SET_STATIC_PIXEL_SHADER( introscreenspaceeffect_ps20b ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( introscreenspaceeffect_ps20 ); + SET_STATIC_PIXEL_SHADER( introscreenspaceeffect_ps20 ); + } + + pShaderShadow->EnableBlending( true ); + pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE ); + } + DYNAMIC_STATE + { + pShaderAPI->BindStandardTexture( SHADER_SAMPLER0, TEXTURE_FRAME_BUFFER_FULL_TEXTURE_0 ); + pShaderAPI->BindStandardTexture( SHADER_SAMPLER1, TEXTURE_FRAME_BUFFER_FULL_TEXTURE_1 ); + DECLARE_DYNAMIC_VERTEX_SHADER( screenspaceeffect_vs20 ); + SET_DYNAMIC_VERTEX_SHADER( screenspaceeffect_vs20 ); + + if ( g_pHardwareConfig->SupportsPixelShaders_2_b() || g_pHardwareConfig->ShouldAlwaysUseShaderModel2bShaders() ) // Posix always goes the ps2b way for this shader, even on "ps20" parts + { + DECLARE_DYNAMIC_PIXEL_SHADER( introscreenspaceeffect_ps20b ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( MODE, params[MODE]->GetIntValue() ); + SET_DYNAMIC_PIXEL_SHADER( introscreenspaceeffect_ps20b ); + } + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( introscreenspaceeffect_ps20 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( MODE, params[MODE]->GetIntValue() ); + SET_DYNAMIC_PIXEL_SHADER( introscreenspaceeffect_ps20 ); + } + + SetPixelShaderConstant( 0, ALPHA ); + } + Draw(); + } +END_SHADER diff --git a/materialsystem/stdshaders/introscreenspaceeffect_dx60.cpp b/materialsystem/stdshaders/introscreenspaceeffect_dx60.cpp new file mode 100644 index 0000000..a52fcfe --- /dev/null +++ b/materialsystem/stdshaders/introscreenspaceeffect_dx60.cpp @@ -0,0 +1,79 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//=============================================================================// + +#include "BaseVSShader.h" + +DEFINE_FALLBACK_SHADER( IntroScreenSpaceEffect, IntroScreenSpaceEffect_dx60 ) + +BEGIN_SHADER_FLAGS( IntroScreenSpaceEffect_dx60, "Help for IntroScreenSpaceEffect_dx60", SHADER_NOT_EDITABLE ) + BEGIN_SHADER_PARAMS + SHADER_PARAM( MODE, SHADER_PARAM_TYPE_INTEGER, "0", "" ) + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + SET_FLAGS2( MATERIAL_VAR2_NEEDS_FULL_FRAME_BUFFER_TEXTURE ); + } + + SHADER_INIT + { + } + + SHADER_DRAW + { + SHADOW_STATE + { + pShaderShadow->EnableCulling( false ); + pShaderShadow->EnableDepthWrites( false ); + pShaderShadow->EnableDepthTest( false ); + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + pShaderShadow->DrawFlags( SHADER_DRAW_POSITION | SHADER_DRAW_TEXCOORD0 | SHADER_DRAW_TEXCOORD1 ); + DisableFog(); + + pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE ); + pShaderShadow->EnableCustomPixelPipe( true ); + pShaderShadow->CustomTextureStages( 2 ); + pShaderShadow->EnableConstantAlpha( true ); + pShaderShadow->EnableBlending( true ); + + pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE0, + SHADER_TEXCHANNEL_COLOR, SHADER_TEXOP_SELECTARG1, + SHADER_TEXARG_TEXTURE, SHADER_TEXARG_NONE ); + + pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE1, + SHADER_TEXCHANNEL_COLOR, SHADER_TEXOP_ADD, + SHADER_TEXARG_TEXTURE, SHADER_TEXARG_PREVIOUSSTAGE ); + + pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE1, + SHADER_TEXCHANNEL_ALPHA, SHADER_TEXOP_SELECTARG1, + SHADER_TEXARG_CONSTANTCOLOR, SHADER_TEXARG_NONE ); + } + DYNAMIC_STATE + { + switch( params[MODE]->GetIntValue() ) + { + case 7: + pShaderAPI->BindStandardTexture( SHADER_SAMPLER0, TEXTURE_FRAME_BUFFER_FULL_TEXTURE_0 ); + pShaderAPI->BindStandardTexture( SHADER_SAMPLER1, TEXTURE_BLACK ); + break; + case 8: + pShaderAPI->BindStandardTexture( SHADER_SAMPLER0, TEXTURE_FRAME_BUFFER_FULL_TEXTURE_1 ); + pShaderAPI->BindStandardTexture( SHADER_SAMPLER1, TEXTURE_BLACK ); + break; + default: + pShaderAPI->BindStandardTexture( SHADER_SAMPLER0, TEXTURE_FRAME_BUFFER_FULL_TEXTURE_0 ); + pShaderAPI->BindStandardTexture( SHADER_SAMPLER1, TEXTURE_FRAME_BUFFER_FULL_TEXTURE_1 ); + break; + } + float color[4] = { 1.0, 1.0, 1.0, 1.0 }; + color[3] = params[ALPHA]->GetFloatValue(); + s_pShaderAPI->Color4fv( color ); + } + Draw(); + } +END_SHADER diff --git a/materialsystem/stdshaders/introscreenspaceeffect_dx80.cpp b/materialsystem/stdshaders/introscreenspaceeffect_dx80.cpp new file mode 100644 index 0000000..3769da3 --- /dev/null +++ b/materialsystem/stdshaders/introscreenspaceeffect_dx80.cpp @@ -0,0 +1,69 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//=============================================================================// + +#include "BaseVSShader.h" + +#include "ScreenSpaceEffect_vs11.inc" +#include "IntroScreenSpaceEffect_ps11.inc" + +DEFINE_FALLBACK_SHADER( IntroScreenSpaceEffect, IntroScreenSpaceEffect_dx80 ) + +BEGIN_VS_SHADER_FLAGS( IntroScreenSpaceEffect_dx80, "Help for IntroScreenSpaceEffect_dx80", SHADER_NOT_EDITABLE ) + BEGIN_SHADER_PARAMS + SHADER_PARAM( MODE, SHADER_PARAM_TYPE_INTEGER, "0", "" ) + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + SET_FLAGS2( MATERIAL_VAR2_NEEDS_FULL_FRAME_BUFFER_TEXTURE ); + } + + SHADER_INIT + { + } + + SHADER_FALLBACK + { + // Requires DX9 + above + if ( IsPC() && g_pHardwareConfig->GetDXSupportLevel() < 80 ) + return "introscreenspaceeffect_dx60"; + return 0; + } + + SHADER_DRAW + { + SHADOW_STATE + { + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + int fmt = VERTEX_POSITION; + pShaderShadow->VertexShaderVertexFormat( fmt, 1, 0, 0 ); + DECLARE_STATIC_VERTEX_SHADER( screenspaceeffect_vs11 ); + SET_STATIC_VERTEX_SHADER( screenspaceeffect_vs11 ); + + DECLARE_STATIC_PIXEL_SHADER( introscreenspaceeffect_ps11 ); + SET_STATIC_PIXEL_SHADER( introscreenspaceeffect_ps11 ); + + pShaderShadow->EnableBlending( true ); + pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE ); + } + DYNAMIC_STATE + { + pShaderAPI->BindStandardTexture( SHADER_SAMPLER0, TEXTURE_FRAME_BUFFER_FULL_TEXTURE_0 ); + pShaderAPI->BindStandardTexture( SHADER_SAMPLER1, TEXTURE_FRAME_BUFFER_FULL_TEXTURE_1 ); + DECLARE_DYNAMIC_VERTEX_SHADER( screenspaceeffect_vs11 ); + SET_DYNAMIC_VERTEX_SHADER( screenspaceeffect_vs11 ); + + DECLARE_DYNAMIC_PIXEL_SHADER( introscreenspaceeffect_ps11 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( MODE, params[MODE]->GetIntValue() ); + SET_DYNAMIC_PIXEL_SHADER( introscreenspaceeffect_ps11 ); + + SetPixelShaderConstant( 0, ALPHA ); + } + Draw(); + } +END_SHADER diff --git a/materialsystem/stdshaders/jellyfish.cpp b/materialsystem/stdshaders/jellyfish.cpp new file mode 100644 index 0000000..9d0e984 --- /dev/null +++ b/materialsystem/stdshaders/jellyfish.cpp @@ -0,0 +1,111 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $Header: $ +// $NoKeywords: $ +//=============================================================================// + +#include "BaseVSShader.h" + +#include "jellyfish.inc" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +BEGIN_VS_SHADER( JellyFish, + "Help for JellyFish" ) + + BEGIN_SHADER_PARAMS + SHADER_PARAM( GRADIENTTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "1D texture for silhouette glowy bits" ) + SHADER_PARAM( ENVMAP, SHADER_PARAM_TYPE_TEXTURE, "shadertest/cubemap", "envmap" ) + SHADER_PARAM( ENVMAPTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "envmaptint" ) + SHADER_PARAM( PULSERATE, SHADER_PARAM_TYPE_FLOAT, "1", "blah" ) + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + SET_FLAGS2( MATERIAL_VAR2_SUPPORTS_HW_SKINNING ); + } + + SHADER_INIT + { + LoadTexture( GRADIENTTEXTURE ); + LoadTexture( BASETEXTURE ); + if( params[ENVMAP]->IsDefined() ) + { + LoadCubeMap( ENVMAP ); + } + if( !params[ENVMAPTINT]->IsDefined() ) + { + params[ENVMAPTINT]->SetVecValue( 1.0f, 1.0f, 1.0f ); + } + if( !params[PULSERATE]->IsDefined() ) + { + params[PULSERATE]->SetFloatValue( 0.0f ); + } + } + + SHADER_DRAW + { + // fixme + if( !g_pHardwareConfig->SupportsVertexAndPixelShaders() ) + { + return; + } + + SHADOW_STATE + { + pShaderShadow->EnableDepthWrites( false ); + pShaderShadow->EnableBlending( true ); + pShaderShadow->BlendFunc( SHADER_BLEND_ONE, SHADER_BLEND_ONE ); + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + pShaderShadow->VertexShaderVertexFormat( + VERTEX_POSITION | VERTEX_NORMAL, 1, 0, 0 ); + jellyfish_Static_Index vshIndex; + pShaderShadow->SetVertexShader( "JellyFish", vshIndex.GetIndex() ); + pShaderShadow->SetPixelShader( "JellyFish" ); + FogToBlack(); + } + DYNAMIC_STATE + { + float time[4]; + time[0] = pShaderAPI->CurrentTime() * params[PULSERATE]->GetFloatValue(); + BindTexture( SHADER_SAMPLER0, GRADIENTTEXTURE ); + BindTexture( SHADER_SAMPLER1, BASETEXTURE ); + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_5, time, 1 ); + LoadViewMatrixIntoVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0 ); + + jellyfish_Dynamic_Index vshIndex; + vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + vshIndex.SetSKINNING( pShaderAPI->GetCurrentNumBones() > 0 ); + pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() ); + } + Draw(); + + if( params[ENVMAP]->IsTexture() ) + { + SHADOW_STATE + { + SetInitialShadowState( ); + pShaderShadow->EnableDepthWrites( false ); + pShaderShadow->EnableBlending( true ); + pShaderShadow->BlendFunc( SHADER_BLEND_ONE, SHADER_BLEND_ONE ); + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->TexGen( SHADER_TEXTURE_STAGE0, SHADER_TEXGENPARAM_CAMERASPACEREFLECTIONVECTOR ); + pShaderShadow->EnableTexGen( SHADER_TEXTURE_STAGE0, true ); + pShaderShadow->DrawFlags( SHADER_DRAW_POSITION | SHADER_DRAW_NORMAL ); + pShaderShadow->EnableConstantColor( true ); + FogToFogColor(); + } + DYNAMIC_STATE + { + SetColorState( ENVMAPTINT ); + LoadCameraToWorldTransform( MATERIAL_TEXTURE0 ); + BindTexture( SHADER_SAMPLER0, ENVMAP ); + } + Draw(); + } + } +END_SHADER diff --git a/materialsystem/stdshaders/lightingonly_vs20.fxc b/materialsystem/stdshaders/lightingonly_vs20.fxc new file mode 100644 index 0000000..0c0cb3b --- /dev/null +++ b/materialsystem/stdshaders/lightingonly_vs20.fxc @@ -0,0 +1,74 @@ +// STATIC: "HALFLAMBERT" "0..1" +// STATIC: "USE_STATIC_CONTROL_FLOW" "0..1" [vs20] + +// DYNAMIC: "DOWATERFOG" "0..1" +// DYNAMIC: "SKINNING" "0..1" +// DYNAMIC: "DYNAMIC_LIGHT" "0..1" +// DYNAMIC: "STATIC_LIGHT" "0..1" +// DYNAMIC: "NUM_LIGHTS" "0..2" [vs20] + +// If using static control flow on Direct3D, we should use the NUM_LIGHTS=0 combo +// SKIP: $USE_STATIC_CONTROL_FLOW && ( $NUM_LIGHTS > 0 ) [vs20] + +#include "common_vs_fxc.h" + +static const int g_FogType = DOWATERFOG; +static const bool g_bHalfLambert = HALFLAMBERT ? true : false; +static const int g_nSkinning = SKINNING; +static const bool g_bDynamicLight = DYNAMIC_LIGHT ? true : false; +static const bool g_bStaticLight = STATIC_LIGHT ? true : false; + +struct VS_INPUT +{ + float4 vPos : POSITION; + float4 vBoneWeights : BLENDWEIGHT; + float4 vBoneIndices : BLENDINDICES; + float4 vNormal : NORMAL; + + float3 vSpecular : COLOR1; + + float2 vTexCoord0 : TEXCOORD0; + float2 vTexCoord1 : TEXCOORD1; + float2 vTexCoord2 : TEXCOORD2; + +}; + +struct VS_OUTPUT +{ + float4 vProjPos : POSITION; + float3 vColor0 : COLOR0; + + float4 fogFactorW : COLOR1; + +#if !defined( _X360 ) + float fog : FOG; +#endif +}; + + +VS_OUTPUT main( const VS_INPUT v ) +{ + VS_OUTPUT o = ( VS_OUTPUT )0; + + float3 vObjNormal; + DecompressVertex_Normal( v.vNormal, vObjNormal ); + + float3 worldPos, worldNormal; + SkinPositionAndNormal( g_bSkinning, v.vPos, vObjNormal, v.vBoneWeights, v.vBoneIndices, worldPos, worldNormal ); + + o.vProjPos = mul( float4( worldPos, 1 ), cViewProj ); + + o.fogFactorW = CalcFog( worldPos, o.vProjPos, g_FogType ); +#if !defined( _X360 ) + o.fog = o.fogFactorW; +#endif + + // Compute vertex lighting +#if ( USE_STATIC_CONTROL_FLOW ) || defined ( SHADER_MODEL_VS_3_0 ) + o.vColor0 = DoLighting( worldPos, worldNormal, float3(0.0f, 0.0f, 0.0f), g_bStaticLight, g_bDynamicLight, g_bHalfLambert ); +#else + o.vColor0 = DoLightingUnrolled( worldPos, worldNormal, float3(0.0f, 0.0f, 0.0f), g_bStaticLight, g_bDynamicLight, g_bHalfLambert, NUM_LIGHTS ); +#endif + + return o; +} \ No newline at end of file diff --git a/materialsystem/stdshaders/lightmappedenvmappedbumpmappedtexture.psh b/materialsystem/stdshaders/lightmappedenvmappedbumpmappedtexture.psh new file mode 100644 index 0000000..cab8d7d --- /dev/null +++ b/materialsystem/stdshaders/lightmappedenvmappedbumpmappedtexture.psh @@ -0,0 +1,33 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; Environment mapping on a bumped surface +; t0 - Normalmap +; t3 - Cube environment map (*must* be a cube map!) +; +; c0 - color to multiply the results by +; Input texture coords required here are a little wonky. +; tc0.uv <- U,V into the normal map +; tc1.uvw, tc2.uvw, tc3.uvw <- 3x3 matrix transform +; from tangent space->env map space +; tc1.q, tc2.q, tc3.q <- eye vector in env map space +;------------------------------------------------------------------------------ + +; Get the 3-vector from the normal map +tex t0 + +; Perform matrix multiply to get a local normal bump. Then +; reflect the eye vector through the normal and sample from +; a cubic environment map. +texm3x3pad t1, t0_bx2 +texm3x3pad t2, t0_bx2 +texm3x3vspec t3, t0_bx2 + +; result goes in output color (multiply by constant color c0) +mul r0, t3, c0 + +; The output alpha comes from the normal map. +mov r0.w, t0.a + + + diff --git a/materialsystem/stdshaders/lightmappedgeneric_basealphamaskedenvmap.psh b/materialsystem/stdshaders/lightmappedgeneric_basealphamaskedenvmap.psh new file mode 100644 index 0000000..80e6db4 --- /dev/null +++ b/materialsystem/stdshaders/lightmappedgeneric_basealphamaskedenvmap.psh @@ -0,0 +1,22 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; Draw a texture . . woo hoo! +; t0 - texture +; +; The texture coordinates need to be defined as follows: +; tc0 - texcoords +; c1 - self-illum tint +; c2 - envmap tint +;------------------------------------------------------------------------------ + +tex t0 +tex t1 +tex t2 +tex t3 + +mul r0, t0, v0 ; base times vertex color (with alpha) +mul r1, t2, 1-t3.a ; envmap * envmapmask alpha +mad r0.rgb, r1, c2, r0 ; + envmap * envmapmask * envmaptint (color only) +mul r0.rgb, t1, r0 ; fold in lighting (color only) +mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2) diff --git a/materialsystem/stdshaders/lightmappedgeneric_basetextureblend.psh b/materialsystem/stdshaders/lightmappedgeneric_basetextureblend.psh new file mode 100644 index 0000000..9ca0eeb --- /dev/null +++ b/materialsystem/stdshaders/lightmappedgeneric_basetextureblend.psh @@ -0,0 +1,9 @@ +ps.1.1 + +tex t0 ; base 1 +tex t1 ; base 2 + +mov r1, t1 +lrp r0, 1-v0.a, t0, r1 +mul r0, r0, c0 + diff --git a/materialsystem/stdshaders/lightmappedgeneric_decal.cpp b/materialsystem/stdshaders/lightmappedgeneric_decal.cpp new file mode 100644 index 0000000..9e74b5c --- /dev/null +++ b/materialsystem/stdshaders/lightmappedgeneric_decal.cpp @@ -0,0 +1,135 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: Lightmap only shader +// +// $Header: $ +// $NoKeywords: $ +//=============================================================================// + +#include "BaseVSShader.h" + +#include "lightmappedgeneric_decal.inc" +#include "mathlib/bumpvects.h" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + + +BEGIN_VS_SHADER( LightmappedGeneric_Decal, + "Help for LightmappedGeneric_Decal" ) + + BEGIN_SHADER_PARAMS + END_SHADER_PARAMS + + // Set up anything that is necessary to make decisions in SHADER_FALLBACK. + SHADER_INIT_PARAMS() + { + if ( g_pHardwareConfig->SupportsBorderColor() ) + { + params[FLASHLIGHTTEXTURE]->SetStringValue( "effects/flashlight_border" ); + } + else + { + params[FLASHLIGHTTEXTURE]->SetStringValue( "effects/flashlight001" ); + } + + // No texture means no self-illum or env mask in base alpha + if ( !params[BASETEXTURE]->IsDefined() ) + { + CLEAR_FLAGS( MATERIAL_VAR_SELFILLUM ); + CLEAR_FLAGS( MATERIAL_VAR_BASEALPHAENVMAPMASK ); + } + + SET_FLAGS( MATERIAL_VAR_DECAL ); + SET_FLAGS( MATERIAL_VAR_NO_DEBUG_OVERRIDE ); + SET_FLAGS2( MATERIAL_VAR2_LIGHTING_LIGHTMAP ); + } + + SHADER_FALLBACK + { + return 0; + } + + SHADER_INIT + { + LoadTexture( FLASHLIGHTTEXTURE, TEXTUREFLAGS_SRGB ); + + if (params[BASETEXTURE]->IsDefined()) + { + LoadTexture( BASETEXTURE ); + + if ( !params[BASETEXTURE]->GetTextureValue()->IsTranslucent() ) + { + CLEAR_FLAGS( MATERIAL_VAR_SELFILLUM ); + CLEAR_FLAGS( MATERIAL_VAR_BASEALPHAENVMAPMASK ); + } + } + + // Don't alpha test if the alpha channel is used for other purposes + if (IS_FLAG_SET(MATERIAL_VAR_SELFILLUM) || IS_FLAG_SET(MATERIAL_VAR_BASEALPHAENVMAPMASK) ) + { + CLEAR_FLAGS( MATERIAL_VAR_ALPHATEST ); + } + } + + void DrawDecal( IMaterialVar **params, IShaderDynamicAPI *pShaderAPI, IShaderShadow *pShaderShadow ) + { + if( IsSnapshotting() ) + { + // Be sure not to write to dest alpha + pShaderShadow->EnableAlphaWrites( false ); + + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER2, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER3, true ); + + SetNormalBlendingShadowState( BASETEXTURE, true ); + + int pTexCoords[3] = { 2, 2, 1 }; + pShaderShadow->VertexShaderVertexFormat( VERTEX_POSITION | VERTEX_COLOR, 3, pTexCoords, 0 ); + + lightmappedgeneric_decal_Static_Index vshIndex; + pShaderShadow->SetVertexShader( "LightmappedGeneric_Decal", vshIndex.GetIndex() ); + pShaderShadow->SetPixelShader( "LightmappedGeneric_Decal" ); + FogToFogColor(); + } + else + { + BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME ); + + // Load the z^2 components of the lightmap coordinate axes only + // This is (N dot basis)^2 + Vector vecZValues( g_localBumpBasis[0].z, g_localBumpBasis[1].z, g_localBumpBasis[2].z ); + vecZValues *= vecZValues; + + Vector4D basis[3]; + basis[0].Init( vecZValues.x, vecZValues.x, vecZValues.x, 0.0f ); + basis[1].Init( vecZValues.y, vecZValues.y, vecZValues.y, 0.0f ); + basis[2].Init( vecZValues.z, vecZValues.z, vecZValues.z, 0.0f ); + pShaderAPI->SetPixelShaderConstant( 0, (float*)basis, 3 ); + + pShaderAPI->BindStandardTexture( SHADER_SAMPLER1, TEXTURE_LIGHTMAP_BUMPED ); + SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, BASETEXTURETRANSFORM ); + SetModulationPixelShaderDynamicState( 3 ); + + lightmappedgeneric_decal_Dynamic_Index vshIndex; + vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() ); + } + Draw(); + } + + SHADER_DRAW + { + if( UsingFlashlight( params ) ) + { + DrawFlashlight_dx80( params, pShaderAPI, pShaderShadow, false, -1, -1, -1, + FLASHLIGHTTEXTURE, FLASHLIGHTTEXTUREFRAME, true, false, 0, -1, -1 ); + } + else + { + DrawDecal( params, pShaderAPI, pShaderShadow ); + } + } +END_SHADER diff --git a/materialsystem/stdshaders/lightmappedgeneric_decal_ps2x.fxc b/materialsystem/stdshaders/lightmappedgeneric_decal_ps2x.fxc new file mode 100644 index 0000000..fd457be --- /dev/null +++ b/materialsystem/stdshaders/lightmappedgeneric_decal_ps2x.fxc @@ -0,0 +1,59 @@ +// DYNAMIC: "PIXELFOGTYPE" "0..1" + +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX] + +#include "common_ps_fxc.h" +#include "shader_constant_register_map.h" + +sampler BaseTextureSampler : register( s0 ); +sampler LightMap0Sampler : register( s1 ); +sampler LightMap1Sampler : register( s2 ); +sampler LightMap2Sampler : register( s3 ); + +const float4 g_LightMap0Color : register( c0 ); +const float4 g_LightMap1Color : register( c1 ); +const float4 g_LightMap2Color : register( c2 ); +const float4 g_ModulationColor : register( c3 ); + +const float4 g_FogParams : register( PSREG_FOG_PARAMS ); +const float4 g_EyePos_SpecExponent : register( PSREG_EYEPOS_SPEC_EXPONENT ); + + +struct PS_INPUT +{ + float4 vProjPos : POSITION; + float2 vTexCoord0 : TEXCOORD0; + float2 vTexCoord1 : TEXCOORD1; + float2 vTexCoord2 : TEXCOORD2; + float2 vTexCoord3 : TEXCOORD3; + float4 worldPos_projPosZ : TEXCOORD4; // Necessary for pixel fog + + float4 vColor : COLOR0; +}; + +float4 main( PS_INPUT i ) : COLOR +{ + float4 resultColor; + + // output = lightmapColor[0] * ( ( N dot basis[0] )^2 ) + + // lightmapColor[1] * ( ( N dot basis[1] )^2 ) + + // lightmapColor[2] * ( ( N dot basis[2] )^2 ) + + resultColor = tex2D( LightMap0Sampler, i.vTexCoord1 ) * g_LightMap0Color; + resultColor = (tex2D( LightMap1Sampler, i.vTexCoord2 ) * g_LightMap1Color) + resultColor; + resultColor = (tex2D( LightMap2Sampler, i.vTexCoord3 ) * g_LightMap2Color) + resultColor; + + // Modulate by decal texture + float4 decalColor = tex2D( BaseTextureSampler, i.vTexCoord0 ); + resultColor.rgb = resultColor * decalColor; + resultColor.a = decalColor.a; + + // Modulate by constant color + resultColor = resultColor * g_ModulationColor; + + // Modulate by per-vertex factor + resultColor = resultColor * i.vColor; + + float fogFactor = CalcPixelFogFactor( PIXELFOGTYPE, g_FogParams, g_EyePos_SpecExponent.z, i.worldPos_projPosZ.z, i.worldPos_projPosZ.w ); + return FinalOutput( resultColor, fogFactor, PIXELFOGTYPE, TONEMAP_SCALE_LINEAR ); +} diff --git a/materialsystem/stdshaders/lightmappedgeneric_decal_vs20.fxc b/materialsystem/stdshaders/lightmappedgeneric_decal_vs20.fxc new file mode 100644 index 0000000..0b7db28 --- /dev/null +++ b/materialsystem/stdshaders/lightmappedgeneric_decal_vs20.fxc @@ -0,0 +1,74 @@ +// DYNAMIC: "DOWATERFOG" "0..1" + +#include "common_vs_fxc.h" + +static const int g_FogType = DOWATERFOG; + +const float4 cShaderConst0 : register( SHADER_SPECIFIC_CONST_0 ); +const float4 cShaderConst1 : register( SHADER_SPECIFIC_CONST_1 ); + +struct VS_INPUT +{ + float4 vPos : POSITION; + float4 vTexCoord0 : TEXCOORD0; + float4 vTexCoord1 : TEXCOORD1; + float2 vTexCoord2 : TEXCOORD2; + + float4 vColor : COLOR0; +}; + +struct VS_OUTPUT +{ + float4 vProjPos : POSITION; + float2 vTexCoord0 : TEXCOORD0; + float2 vTexCoord1 : TEXCOORD1; + float2 vTexCoord2 : TEXCOORD2; + float2 vTexCoord3 : TEXCOORD3; + + float4 worldPos_projPosZ : TEXCOORD4; // Necessary for pixel fog + + float4 vColor : COLOR0; + + float4 fogFactorW : COLOR1; + +#if !defined( _X360 ) + float fog : FOG; +#endif +}; + + +VS_OUTPUT main( const VS_INPUT v ) +{ + VS_OUTPUT o = ( VS_OUTPUT )0; + + float3 worldPos; + worldPos = mul( v.vPos, cModel[0] ); + float4 vProjPos = mul( float4( worldPos, 1 ), cViewProj ); + o.vProjPos = vProjPos; + vProjPos.z = dot( float4( worldPos, 1 ), cViewProjZ ); + + o.worldPos_projPosZ = float4( worldPos.xyz, vProjPos.z ); + + o.fogFactorW = CalcFog( worldPos, vProjPos, g_FogType ); +#if !defined( _X360 ) + o.fog = o.fogFactorW; +#endif + + + // Compute the texture coordinates given the offset between + // each bumped lightmap + float2 offset; + offset.x = v.vTexCoord2.x; + offset.y = 0.0f; + + o.vTexCoord0.x = dot( v.vTexCoord0, cShaderConst0 ); + o.vTexCoord0.y = dot( v.vTexCoord0, cShaderConst1 ); + + o.vTexCoord1 = offset + v.vTexCoord1.xy; + o.vTexCoord2 = (offset * 2.0) + v.vTexCoord1.xy; + o.vTexCoord3 = (offset * 3.0) + v.vTexCoord1.xy; + + o.vColor = v.vColor; + + return o; +} \ No newline at end of file diff --git a/materialsystem/stdshaders/lightmappedgeneric_dx6.cpp b/materialsystem/stdshaders/lightmappedgeneric_dx6.cpp new file mode 100644 index 0000000..f55f888 --- /dev/null +++ b/materialsystem/stdshaders/lightmappedgeneric_dx6.cpp @@ -0,0 +1,288 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: Lightmap only shader +// +// $Header: $ +// $NoKeywords: $ +//=============================================================================// + +#include "shaderlib/cshader.h" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +DEFINE_FALLBACK_SHADER( LightmappedGeneric, LightmappedGeneric_DX6 ) + +BEGIN_SHADER( LightmappedGeneric_DX6, + "Help for LightmappedGeneric_DX6" ) + + BEGIN_SHADER_PARAMS + SHADER_PARAM( SELFILLUMTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "Self-illumination tint" ) + SHADER_PARAM( DETAIL, SHADER_PARAM_TYPE_TEXTURE, "shadertest/detail", "detail texture" ) + SHADER_PARAM( DETAILSCALE, SHADER_PARAM_TYPE_FLOAT, "4", "scale of the detail texture" ) + SHADER_PARAM( ENVMAP, SHADER_PARAM_TYPE_TEXTURE, "shadertest/shadertest_env", "envmap" ) + SHADER_PARAM( ENVMAPFRAME, SHADER_PARAM_TYPE_INTEGER, "", "" ) + SHADER_PARAM( ENVMAPMASK, SHADER_PARAM_TYPE_TEXTURE, "shadertest/shadertest_envmask", "envmap mask" ) + SHADER_PARAM( ENVMAPMASKFRAME, SHADER_PARAM_TYPE_INTEGER, "", "" ) + SHADER_PARAM( ENVMAPMASKSCALE, SHADER_PARAM_TYPE_FLOAT, "1", "envmap mask scale" ) + SHADER_PARAM( ENVMAPTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "envmap tint" ) + SHADER_PARAM( ENVMAPOPTIONAL, SHADER_PARAM_TYPE_BOOL, "90", "Do specular pass only on dxlevel or higher (ie.80, 81, 90)" ) + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + // FLASHLIGHTFIXME + params[FLASHLIGHTTEXTURE]->SetStringValue( "effects/flashlight001" ); + + if( params[BASETEXTURE]->IsDefined() ) + { + if( !IS_FLAG_SET(MATERIAL_VAR_MULTIPASS) ) + { + params[ENVMAP]->SetUndefined(); + params[ENVMAPMASK]->SetUndefined(); + } + } + + if( !params[ENVMAPMASKSCALE]->IsDefined() ) + params[ENVMAPMASKSCALE]->SetFloatValue( 1.0f ); + + if( !params[ENVMAPTINT]->IsDefined() ) + params[ENVMAPTINT]->SetVecValue( 1.0f, 1.0f, 1.0f ); + + if( !params[SELFILLUMTINT]->IsDefined() ) + params[SELFILLUMTINT]->SetVecValue( 1.0f, 1.0f, 1.0f ); + + if( !params[DETAILSCALE]->IsDefined() ) + params[DETAILSCALE]->SetFloatValue( 4.0f ); + + // No texture means no self-illum or env mask in base alpha + if ( !params[BASETEXTURE]->IsDefined() ) + { + CLEAR_FLAGS( MATERIAL_VAR_SELFILLUM ); + CLEAR_FLAGS( MATERIAL_VAR_BASEALPHAENVMAPMASK ); + } + + // If in decal mode, no debug override... + if (IS_FLAG_SET(MATERIAL_VAR_DECAL)) + { + SET_FLAGS( MATERIAL_VAR_NO_DEBUG_OVERRIDE ); + } + + SET_FLAGS2( MATERIAL_VAR2_LIGHTING_LIGHTMAP ); + + // Get rid of the envmap if it's optional for this dx level. + if( params[ENVMAPOPTIONAL]->IsDefined() && params[ENVMAPOPTIONAL]->GetIntValue() ) + { + params[ENVMAP]->SetUndefined(); + } + + // If mat_specular 0, then get rid of envmap + if( !g_pConfig->UseSpecular() && params[ENVMAP]->IsDefined() && params[BASETEXTURE]->IsDefined() ) + { + params[ENVMAP]->SetUndefined(); + } + + SET_FLAGS2( MATERIAL_VAR2_NEEDS_FIXED_FUNCTION_FLASHLIGHT ); + } + + SHADER_INIT + { + LoadTexture( FLASHLIGHTTEXTURE ); + if (params[BASETEXTURE]->IsDefined()) + { + LoadTexture( BASETEXTURE ); + + if (!params[BASETEXTURE]->GetTextureValue()->IsTranslucent()) + { + if (IS_FLAG_SET(MATERIAL_VAR_SELFILLUM)) + CLEAR_FLAGS( MATERIAL_VAR_SELFILLUM ); + if (IS_FLAG_SET(MATERIAL_VAR_BASEALPHAENVMAPMASK)) + CLEAR_FLAGS( MATERIAL_VAR_BASEALPHAENVMAPMASK ); + } + } + + if (params[DETAIL]->IsDefined()) + { + LoadTexture( DETAIL ); + } + + // Don't alpha test if the alpha channel is used for other purposes + if (IS_FLAG_SET(MATERIAL_VAR_SELFILLUM) || IS_FLAG_SET(MATERIAL_VAR_BASEALPHAENVMAPMASK) ) + CLEAR_FLAGS( MATERIAL_VAR_ALPHATEST ); + + if (params[ENVMAP]->IsDefined()) + { + if( !IS_FLAG_SET(MATERIAL_VAR_ENVMAPSPHERE) ) + { + LoadCubeMap( ENVMAP ); + } + else + { + LoadTexture( ENVMAP ); + } + + if( !g_pHardwareConfig->SupportsCubeMaps() ) + { + SET_FLAGS( MATERIAL_VAR_ENVMAPSPHERE ); + } + + if (params[ENVMAPMASK]->IsDefined()) + { + LoadTexture( ENVMAPMASK ); + } + } + } + + SHADER_FALLBACK + { + return 0; + } + + int GetDrawFlagsPass1(IMaterialVar** params) + { + int flags = SHADER_DRAW_POSITION | SHADER_DRAW_LIGHTMAP_TEXCOORD0; + if (IS_FLAG_SET(MATERIAL_VAR_VERTEXCOLOR)) + flags |= SHADER_DRAW_COLOR; + if (params[BASETEXTURE]->IsTexture()) + flags |= SHADER_DRAW_TEXCOORD1; + return flags; + } + + void DrawLightmapOnly( IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow ) + { + SHADOW_STATE + { + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->OverbrightValue( SHADER_TEXTURE_STAGE0, OVERBRIGHT ); + + SetModulationShadowState(); + SetDefaultBlendingShadowState( ); + pShaderShadow->DrawFlags( GetDrawFlagsPass1( params ) ); + DefaultFog(); + } + DYNAMIC_STATE + { + pShaderAPI->BindStandardTexture( SHADER_SAMPLER0, TEXTURE_LIGHTMAP ); + SetModulationDynamicState(); + } + Draw(); + } + + void DrawBaseTimesLightmap( IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow ) + { + // Base times lightmap + SHADOW_STATE + { + // alpha test + pShaderShadow->EnableAlphaTest( IS_FLAG_SET(MATERIAL_VAR_ALPHATEST) ); + + // Alpha blending + SetDefaultBlendingShadowState( BASETEXTURE, true ); + + // Independenly configure alpha and color + pShaderShadow->EnableAlphaPipe( true ); + + // color channel + + // base + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + + // lightmap + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + pShaderShadow->OverbrightValue( SHADER_TEXTURE_STAGE1, OVERBRIGHT ); + + pShaderShadow->EnableConstantColor( IsColorModulating() ); + + // alpha channel + pShaderShadow->EnableConstantAlpha( IsAlphaModulating() ); + if ((! IsColorModulating()) && ( ! IsAlphaModulating())) + pShaderShadow->EnableVertexAlpha( IS_FLAG_SET(MATERIAL_VAR_VERTEXALPHA) ); + pShaderShadow->EnableTextureAlpha( SHADER_TEXTURE_STAGE0, TextureIsTranslucent(BASETEXTURE, true) ); + pShaderShadow->EnableTextureAlpha( SHADER_TEXTURE_STAGE1, false ); + + int flags = SHADER_DRAW_POSITION | SHADER_DRAW_LIGHTMAP_TEXCOORD1; + if (IS_FLAG_SET(MATERIAL_VAR_VERTEXCOLOR)) + { + if ( (! IsColorModulating()) && ( ! IsAlphaModulating())) + flags |= SHADER_DRAW_COLOR; + + } + if (params[BASETEXTURE]->IsTexture()) + { + flags |= SHADER_DRAW_TEXCOORD0; + } + + pShaderShadow->DrawFlags( flags ); + DefaultFog(); + } + DYNAMIC_STATE + { + pShaderAPI->BindStandardTexture( SHADER_SAMPLER1, TEXTURE_LIGHTMAP ); + BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME ); + SetFixedFunctionTextureTransform( MATERIAL_TEXTURE0, BASETEXTURETRANSFORM ); + SetModulationDynamicState(); + } + Draw(); + + SHADOW_STATE + { + pShaderShadow->EnableAlphaPipe( false ); + } + } + + void DrawMode1( IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow ) + { + // Pass 1 : Base * lightmap or just lightmap + if ( params[BASETEXTURE]->IsTexture() ) + { + DrawBaseTimesLightmap( params, pShaderAPI, pShaderShadow ); + FixedFunctionMultiplyByDetailPass( + BASETEXTURE, FRAME, BASETEXTURETRANSFORM, DETAIL, DETAILSCALE ); + + // Draw the selfillum pass + if ( IS_FLAG_SET(MATERIAL_VAR_SELFILLUM) ) + { + FixedFunctionSelfIlluminationPass( + SHADER_SAMPLER0, BASETEXTURE, FRAME, BASETEXTURETRANSFORM, SELFILLUMTINT ); + } + } + else + { + DrawLightmapOnly( params, pShaderAPI, pShaderShadow ); + FixedFunctionMultiplyByDetailPass( + BASETEXTURE, FRAME, BASETEXTURETRANSFORM, DETAIL, DETAILSCALE ); + } + + // Pass 2 : Masked environment map + if (params[ENVMAP]->IsTexture()) + { + FixedFunctionAdditiveMaskedEnvmapPass( + ENVMAP, ENVMAPMASK, BASETEXTURE, + ENVMAPFRAME, ENVMAPMASKFRAME, FRAME, + BASETEXTURETRANSFORM, ENVMAPMASKSCALE, ENVMAPTINT ); + } + } + + SHADER_DRAW + { + bool hasFlashlight = UsingFlashlight( params ); + + if( hasFlashlight ) + { + DrawFlashlight_dx70( params, pShaderAPI, pShaderShadow, FLASHLIGHTTEXTURE, FLASHLIGHTTEXTUREFRAME ); + } + else + { + // Base * Lightmap + env + DrawMode1( params, pShaderAPI, pShaderShadow ); + } + } +END_SHADER + + +//----------------------------------------------------------------------------- +// This allows us to use a block labelled 'Water_DX60' in the water materials +//----------------------------------------------------------------------------- +BEGIN_INHERITED_SHADER( Water_DX60, LightmappedGeneric_DX6, "Help for Water_DX60" ) +END_INHERITED_SHADER + diff --git a/materialsystem/stdshaders/lightmappedgeneric_dx8.cpp b/materialsystem/stdshaders/lightmappedgeneric_dx8.cpp new file mode 100644 index 0000000..8464f94 --- /dev/null +++ b/materialsystem/stdshaders/lightmappedgeneric_dx8.cpp @@ -0,0 +1,802 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: Lightmap only shader +// +// $Header: $ +// $NoKeywords: $ +//=============================================================================// + +#include "BaseVSShader.h" + + +#include "lightmappedgeneric_vs11.inc" +#include "unlitgeneric_vs11.inc" +#include "worldvertextransition_seamless.inc" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +static ConVar mat_fullbright( "mat_fullbright","0", FCVAR_CHEAT ); + +DEFINE_FALLBACK_SHADER( LightmappedGeneric, LightmappedGeneric_DX8 ) + +BEGIN_VS_SHADER( LightmappedGeneric_DX8, + "Help for LightmappedGeneric_DX8" ) + + BEGIN_SHADER_PARAMS + SHADER_PARAM( ALBEDO, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "albedo (Base texture with no baked lighting)" ) + SHADER_PARAM( SELFILLUMTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "Self-illumination tint" ) + SHADER_PARAM( DETAIL, SHADER_PARAM_TYPE_TEXTURE, "shadertest/detail", "detail texture" ) + SHADER_PARAM( DETAILSCALE, SHADER_PARAM_TYPE_FLOAT, "4", "scale of the detail texture" ) + SHADER_PARAM( DETAILBLENDFACTOR, SHADER_PARAM_TYPE_FLOAT, "1", "amount of detail texture to apply" ) + SHADER_PARAM( ENVMAP, SHADER_PARAM_TYPE_TEXTURE, "shadertest/shadertest_env", "envmap" ) + SHADER_PARAM( ENVMAPFRAME, SHADER_PARAM_TYPE_INTEGER, "", "" ) + SHADER_PARAM( ENVMAPMASK, SHADER_PARAM_TYPE_TEXTURE, "shadertest/shadertest_envmask", "envmap mask" ) + SHADER_PARAM( ENVMAPMASKFRAME, SHADER_PARAM_TYPE_INTEGER, "", "" ) + SHADER_PARAM( ENVMAPMASKSCALE, SHADER_PARAM_TYPE_FLOAT, "1", "envmap mask scale" ) + SHADER_PARAM( ENVMAPTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "envmap tint" ) + SHADER_PARAM( BUMPMAP, SHADER_PARAM_TYPE_TEXTURE, "models/shadertest/shader1_normal", "bump map" ) + SHADER_PARAM( BUMPFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $bumpmap" ) + SHADER_PARAM( BUMPTRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$bumpmap texcoord transform" ) + SHADER_PARAM( ENVMAPCONTRAST, SHADER_PARAM_TYPE_FLOAT, "0.0", "contrast 0 == normal 1 == color*color" ) + SHADER_PARAM( ENVMAPSATURATION, SHADER_PARAM_TYPE_FLOAT, "1.0", "saturation 0 == greyscale 1 == normal" ) + SHADER_PARAM( FRESNELREFLECTION, SHADER_PARAM_TYPE_FLOAT, "1.0", "1.0 == mirror, 0.0 == water" ) + SHADER_PARAM( ENVMAPOPTIONAL, SHADER_PARAM_TYPE_INTEGER, "90", "Do specular pass only on dxlevel or higher (ie.80, 81, 90)" ) + SHADER_PARAM( NODIFFUSEBUMPLIGHTING, SHADER_PARAM_TYPE_BOOL, "0", "0 == Use diffuse bump lighting, 1 = No diffuse bump lighting" ) + SHADER_PARAM( FORCEBUMP, SHADER_PARAM_TYPE_BOOL, "0", "0 == Do bumpmapping if the card says it can handle it. 1 == Always do bumpmapping." ) + SHADER_PARAM( ALPHATESTREFERENCE, SHADER_PARAM_TYPE_FLOAT, "0.0", "" ) + SHADER_PARAM( SSBUMP, SHADER_PARAM_TYPE_INTEGER, "0", "whether or not to use alternate bumpmap format with height" ) + SHADER_PARAM( SEAMLESS_SCALE, SHADER_PARAM_TYPE_FLOAT, "0", "Scale factor for 'seamless' texture mapping. 0 means to use ordinary mapping" ) + END_SHADER_PARAMS + + virtual bool ShouldUseBumpmapping( IMaterialVar **params ) + { + return g_pConfig->UseBumpmapping() && params[BUMPMAP]->IsDefined(); + } + + // Set up anything that is necessary to make decisions in SHADER_FALLBACK. + SHADER_INIT_PARAMS() + { + // FLASHLIGHTFIXME + params[FLASHLIGHTTEXTURE]->SetStringValue( "effects/flashlight001" ); + + // Write over $basetexture with $albedo if we are going to be using diffuse normal mapping. + if( ShouldUseBumpmapping( params ) && params[ALBEDO]->IsDefined() && + params[BASETEXTURE]->IsDefined() && + !( params[NODIFFUSEBUMPLIGHTING]->IsDefined() && params[NODIFFUSEBUMPLIGHTING]->GetIntValue() ) ) + { + params[BASETEXTURE]->SetStringValue( params[ALBEDO]->GetStringValue() ); + } + + if( IsUsingGraphics() && params[ENVMAP]->IsDefined() && !CanUseEditorMaterials() ) + { + if( stricmp( params[ENVMAP]->GetStringValue(), "env_cubemap" ) == 0 ) + { + Warning( "env_cubemap used on world geometry without rebuilding map. . ignoring: %s\n", pMaterialName ); + params[ENVMAP]->SetUndefined(); + } + } + + if( !params[ENVMAPMASKSCALE]->IsDefined() ) + { + params[ENVMAPMASKSCALE]->SetFloatValue( 1.0f ); + } + + if( !params[ENVMAPTINT]->IsDefined() ) + { + params[ENVMAPTINT]->SetVecValue( 1.0f, 1.0f, 1.0f ); + } + + if( !params[SELFILLUMTINT]->IsDefined() ) + { + params[SELFILLUMTINT]->SetVecValue( 1.0f, 1.0f, 1.0f ); + } + + if( !params[DETAILSCALE]->IsDefined() ) + { + params[DETAILSCALE]->SetFloatValue( 4.0f ); + } + + if( !params[DETAILBLENDFACTOR]->IsDefined() ) + { + params[DETAILBLENDFACTOR]->SetFloatValue( 1.0f ); + } + + if( !params[FRESNELREFLECTION]->IsDefined() ) + { + params[FRESNELREFLECTION]->SetFloatValue( 1.0f ); + } + + if( !params[ENVMAPMASKFRAME]->IsDefined() ) + { + params[ENVMAPMASKFRAME]->SetIntValue( 0 ); + } + + if( !params[ENVMAPFRAME]->IsDefined() ) + { + params[ENVMAPFRAME]->SetIntValue( 0 ); + } + + if( !params[BUMPFRAME]->IsDefined() ) + { + params[BUMPFRAME]->SetIntValue( 0 ); + } + + if( !params[ENVMAPCONTRAST]->IsDefined() ) + { + params[ENVMAPCONTRAST]->SetFloatValue( 0.0f ); + } + + if( !params[ENVMAPSATURATION]->IsDefined() ) + { + params[ENVMAPSATURATION]->SetFloatValue( 1.0f ); + } + + if( !params[ALPHATESTREFERENCE]->IsDefined() ) + { + params[ALPHATESTREFERENCE]->SetFloatValue( 0.0f ); + } + + // No texture means no self-illum or env mask in base alpha + if ( !params[BASETEXTURE]->IsDefined() ) + { + CLEAR_FLAGS( MATERIAL_VAR_SELFILLUM ); + CLEAR_FLAGS( MATERIAL_VAR_BASEALPHAENVMAPMASK ); + } + + // If in decal mode, no debug override... + if (IS_FLAG_SET(MATERIAL_VAR_DECAL)) + { + SET_FLAGS( MATERIAL_VAR_NO_DEBUG_OVERRIDE ); + } + + SET_FLAGS2( MATERIAL_VAR2_LIGHTING_LIGHTMAP ); + if( ShouldUseBumpmapping( params ) && (params[NODIFFUSEBUMPLIGHTING]->GetIntValue() == 0) ) + { + SET_FLAGS2( MATERIAL_VAR2_LIGHTING_BUMPED_LIGHTMAP ); + } + + // Get rid of the envmap if it's optional for this dx level. + if( params[ENVMAPOPTIONAL]->IsDefined() && (params[ENVMAPOPTIONAL]->GetIntValue() > g_pHardwareConfig->GetDXSupportLevel()) ) + { + params[ENVMAP]->SetUndefined(); + } + + // If mat_specular 0, then get rid of envmap + if( !g_pConfig->UseSpecular() && params[ENVMAP]->IsDefined() && params[BASETEXTURE]->IsDefined() ) + { + params[ENVMAP]->SetUndefined(); + } + + if( params[SEAMLESS_SCALE]->IsDefined() && params[SEAMLESS_SCALE]->GetFloatValue() != 0.0f ) + { + if( params[BUMPMAP]->IsDefined() ) + { + Warning( "Can't use $bumpmap with $seamless_scale for lightmappedgeneric_dx8. Implicitly disabling $bumpmap: %s\n", pMaterialName ); + params[BUMPMAP]->SetUndefined(); + } + if( params[ENVMAP]->IsDefined() ) + { + Warning( "Can't use $envmap with $seamless_scale for lightmappedgeneric_dx8. Implicitly disabling $envmap: %s\n", pMaterialName ); + params[ENVMAP]->SetUndefined(); + } + } + + if ( !params[SEAMLESS_SCALE]->IsDefined() ) + { + // zero means don't do seamless mapping. + params[SEAMLESS_SCALE]->SetFloatValue( 0.0f ); + } + + // Get rid of envmap if we aren't using bumpmapping + // *and* we have normalmapalphaenvmapmask *and* we don't have envmapmask elsewhere + if ( params[ENVMAP]->IsDefined() && params[BUMPMAP]->IsDefined() && IS_FLAG_SET( MATERIAL_VAR_NORMALMAPALPHAENVMAPMASK ) && !ShouldUseBumpmapping( params ) ) + { + if ( !IS_FLAG_SET(MATERIAL_VAR_BASEALPHAENVMAPMASK) && !params[ENVMAPMASK]->IsDefined() ) + { + params[ENVMAP]->SetUndefined(); + } + } + } + + SHADER_FALLBACK + { + if ( IsPC() && g_pHardwareConfig->GetDXSupportLevel() < 80) + return "LightmappedGeneric_DX6"; + + if ( IsPC() && g_pHardwareConfig->PreferReducedFillrate() ) + return "LightmappedGeneric_NoBump_DX8"; + + return 0; + } + + SHADER_INIT + { + LoadTexture( FLASHLIGHTTEXTURE ); + + if( ShouldUseBumpmapping( params ) ) + { + LoadBumpMap( BUMPMAP ); + } + + if (params[BASETEXTURE]->IsDefined()) + { + LoadTexture( BASETEXTURE ); + + if (!params[BASETEXTURE]->GetTextureValue()->IsTranslucent()) + { + CLEAR_FLAGS( MATERIAL_VAR_SELFILLUM ); + CLEAR_FLAGS( MATERIAL_VAR_BASEALPHAENVMAPMASK ); + } + } + + if (params[DETAIL]->IsDefined()) + { + LoadTexture( DETAIL ); + } + + // Don't alpha test if the alpha channel is used for other purposes + if (IS_FLAG_SET(MATERIAL_VAR_SELFILLUM) || IS_FLAG_SET(MATERIAL_VAR_BASEALPHAENVMAPMASK) ) + CLEAR_FLAGS( MATERIAL_VAR_ALPHATEST ); + + if (params[ENVMAP]->IsDefined()) + { + if( !IS_FLAG_SET(MATERIAL_VAR_ENVMAPSPHERE) ) + LoadCubeMap( ENVMAP ); + else + LoadTexture( ENVMAP ); + + if( !g_pHardwareConfig->SupportsCubeMaps() ) + { + SET_FLAGS( MATERIAL_VAR_ENVMAPSPHERE ); + } + + if (params[ENVMAPMASK]->IsDefined()) + LoadTexture( ENVMAPMASK ); + } + + if( ShouldUseBumpmapping( params ) ) + { + SET_FLAGS2( MATERIAL_VAR2_NEEDS_TANGENT_SPACES ); + } + } + +#ifndef USE_HLSL_PIXEL_SHADERS + inline const char *GetPixelShaderName( IMaterialVar** params, bool bBumpedEnvMap ) + { + static char const* s_pPixelShaders[] = + { + // Unmasked + "LightmappedGeneric_EnvMapV2", + "LightmappedGeneric_SelfIlluminatedEnvMapV2", + + "LightmappedGeneric_BaseAlphaMaskedEnvMapV2", + "LightmappedGeneric_SelfIlluminatedEnvMapV2", + + // Env map mask + "LightmappedGeneric_MaskedEnvMapV2", + "LightmappedGeneric_SelfIlluminatedMaskedEnvMapV2", + + "LightmappedGeneric_MaskedEnvMapV2", + "LightmappedGeneric_SelfIlluminatedMaskedEnvMapV2", + }; + + if (!params[BASETEXTURE]->IsTexture()) + { + if (params[ENVMAP]->IsTexture() && !bBumpedEnvMap ) + { + if (!params[ENVMAPMASK]->IsDefined() ) + { + return "LightmappedGeneric_EnvmapNoTexture"; + } + else + { + return "LightmappedGeneric_MaskedEnvmapNoTexture"; + } + } + else + { + return "LightmappedGeneric_NoTexture"; + } + } + else + { + if (params[ENVMAP]->IsTexture() && !bBumpedEnvMap ) + { + int pshIndex = 0; + if (IS_FLAG_SET(MATERIAL_VAR_SELFILLUM)) + pshIndex |= 0x1; + if (IS_FLAG_SET(MATERIAL_VAR_BASEALPHAENVMAPMASK)) + pshIndex |= 0x2; + if (params[ENVMAPMASK]->IsTexture()) + pshIndex |= 0x4; + return s_pPixelShaders[pshIndex]; + } + else + { + if (IS_FLAG_SET(MATERIAL_VAR_SELFILLUM)) + return "LightmappedGeneric_SelfIlluminated"; + else + return "LightmappedGeneric"; + } + } + } +#endif + + void DrawUnbumpedUsingVertexShader( IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow, bool bBumpedEnvMap ) + { + bool hasEnvmap = params[ENVMAP]->IsTexture() && !bBumpedEnvMap; + bool hasBaseTexture = params[BASETEXTURE]->IsTexture(); + bool hasVertexColor = IS_FLAG_SET( MATERIAL_VAR_VERTEXCOLOR ); + bool hasEnvmapCameraSpace = IS_FLAG_SET( MATERIAL_VAR_ENVMAPCAMERASPACE ); + bool hasEnvmapSphere = IS_FLAG_SET( MATERIAL_VAR_ENVMAPSPHERE ); + + if ( hasEnvmap || hasBaseTexture || hasVertexColor || !bBumpedEnvMap ) + { + SHADOW_STATE + { + // Alpha test + pShaderShadow->EnableAlphaTest( IS_FLAG_SET(MATERIAL_VAR_ALPHATEST) ); + if ( params[ALPHATESTREFERENCE]->GetFloatValue() > 0.0f ) + { + pShaderShadow->AlphaFunc( SHADER_ALPHAFUNC_GEQUAL, params[ALPHATESTREFERENCE]->GetFloatValue() ); + } + + // Base texture on stage 0 + if (params[BASETEXTURE]->IsTexture()) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + } + + // Lightmap on stage 1 + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + + int fmt = VERTEX_POSITION; + + if ( hasEnvmap ) + { + fmt |= VERTEX_NORMAL; + + // envmap on stage 2 + pShaderShadow->EnableTexture( SHADER_SAMPLER2, true ); + + // envmapmask on stage 3 + if (params[ENVMAPMASK]->IsTexture() || IS_FLAG_SET(MATERIAL_VAR_BASEALPHAENVMAPMASK ) ) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER3, true ); + } + } + + if (params[BASETEXTURE]->IsTexture() || bBumpedEnvMap) + { + SetDefaultBlendingShadowState( BASETEXTURE, true ); + } + else + { + SetDefaultBlendingShadowState( ENVMAPMASK, false ); + } + + if (IS_FLAG_SET(MATERIAL_VAR_VERTEXCOLOR)) + { + fmt |= VERTEX_COLOR; + } + + pShaderShadow->VertexShaderVertexFormat( fmt, 2, 0, 0 ); + lightmappedgeneric_vs11_Static_Index vshIndex; + vshIndex.SetDETAIL( false ); + vshIndex.SetENVMAP( hasEnvmap ); + vshIndex.SetENVMAPCAMERASPACE( hasEnvmap && hasEnvmapCameraSpace ); + vshIndex.SetENVMAPSPHERE( hasEnvmap && hasEnvmapSphere ); + vshIndex.SetVERTEXCOLOR( hasVertexColor ); + pShaderShadow->SetVertexShader( "LightmappedGeneric_vs11", vshIndex.GetIndex() ); + + const char *pshName = GetPixelShaderName( params, bBumpedEnvMap ); + pShaderShadow->SetPixelShader( pshName ); + DefaultFog(); + } + DYNAMIC_STATE + { + if (hasBaseTexture) + { + BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME ); + SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, BASETEXTURETRANSFORM ); + } + + pShaderAPI->BindStandardTexture( SHADER_SAMPLER1, TEXTURE_LIGHTMAP ); + + if ( hasEnvmap ) + { + BindTexture( SHADER_SAMPLER2, ENVMAP, ENVMAPFRAME ); + + if (params[ENVMAPMASK]->IsTexture() || IS_FLAG_SET(MATERIAL_VAR_BASEALPHAENVMAPMASK) ) + { + if (params[ENVMAPMASK]->IsTexture() ) + BindTexture( SHADER_SAMPLER3, ENVMAPMASK, ENVMAPMASKFRAME ); + else + BindTexture( SHADER_SAMPLER3, BASETEXTURE, FRAME ); + + SetVertexShaderTextureScaledTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_2, BASETEXTURETRANSFORM, ENVMAPMASKSCALE ); + } + + if (IS_FLAG_SET(MATERIAL_VAR_ENVMAPSPHERE) || + IS_FLAG_SET(MATERIAL_VAR_ENVMAPCAMERASPACE)) + { + LoadViewMatrixIntoVertexShaderConstant( VERTEX_SHADER_VIEWMODEL ); + } + SetEnvMapTintPixelShaderDynamicState( 2, ENVMAPTINT, -1 ); + } + + if ( !hasEnvmap || hasBaseTexture || hasVertexColor ) + { + SetModulationVertexShaderDynamicState(); + } + EnablePixelShaderOverbright( 0, true, true ); + SetPixelShaderConstant( 1, SELFILLUMTINT ); + + lightmappedgeneric_vs11_Dynamic_Index vshIndex; + vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() ); + } + Draw(); + } + + if ( bBumpedEnvMap ) + { + DrawWorldBumpedSpecularLighting( + BUMPMAP, ENVMAP, BUMPFRAME, ENVMAPFRAME, + ENVMAPTINT, ALPHA, ENVMAPCONTRAST, ENVMAPSATURATION, + BUMPTRANSFORM, FRESNELREFLECTION, + hasEnvmap || hasBaseTexture || hasVertexColor ); + } + } + + void DrawDetailNoEnvmap( IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow, bool doSelfIllum ) + { + SHADOW_STATE + { + // Alpha test + pShaderShadow->EnableAlphaTest( IS_FLAG_SET(MATERIAL_VAR_ALPHATEST) ); + + // Base texture on stage 0 + if (params[BASETEXTURE]->IsTexture()) + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + + // Lightmap on stage 1 + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + + // Detail on stage 2 + pShaderShadow->EnableTexture( SHADER_SAMPLER2, true ); + + int fmt = VERTEX_POSITION; + + SetDefaultBlendingShadowState( BASETEXTURE, true ); + + if (IS_FLAG_SET(MATERIAL_VAR_VERTEXCOLOR)) + fmt |= VERTEX_COLOR; + + pShaderShadow->VertexShaderVertexFormat( fmt, 2, 0, 0 ); + + lightmappedgeneric_vs11_Static_Index vshIndex; + vshIndex.SetDETAIL( true ); + vshIndex.SetENVMAP( false ); + vshIndex.SetENVMAPCAMERASPACE( false ); + vshIndex.SetENVMAPSPHERE( false ); + vshIndex.SetVERTEXCOLOR( IS_FLAG_SET( MATERIAL_VAR_VERTEXCOLOR ) ); + pShaderShadow->SetVertexShader( "LightmappedGeneric_vs11", vshIndex.GetIndex() ); + + if (!params[BASETEXTURE]->IsTexture()) + { + pShaderShadow->SetPixelShader("LightmappedGeneric_DetailNoTexture"); + } + else + { + if (!IS_FLAG_SET(MATERIAL_VAR_SELFILLUM) || (!doSelfIllum)) + { + pShaderShadow->SetPixelShader("LightmappedGeneric_Detail"); + } + else + { + pShaderShadow->SetPixelShader("LightmappedGeneric_DetailSelfIlluminated"); + } + } + DefaultFog(); + } + DYNAMIC_STATE + { + if (params[BASETEXTURE]->IsTexture()) + { + BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME ); + SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, BASETEXTURETRANSFORM ); + } + + pShaderAPI->BindStandardTexture( SHADER_SAMPLER1, TEXTURE_LIGHTMAP ); + + BindTexture( SHADER_SAMPLER2, DETAIL, FRAME ); + SetVertexShaderTextureScaledTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_4, BASETEXTURETRANSFORM, DETAILSCALE ); + + SetModulationVertexShaderDynamicState(); + EnablePixelShaderOverbright( 0, true, true ); + + if (doSelfIllum) + { + SetPixelShaderConstant( 1, SELFILLUMTINT ); + } + float c2[4] = { 1.0f, 1.0f, 1.0f, 1.0f }; + c2[0] = c2[1] = c2[2] = c2[3] = params[DETAILBLENDFACTOR]->GetFloatValue(); + pShaderAPI->SetPixelShaderConstant( 2, c2, 1 ); + + lightmappedgeneric_vs11_Dynamic_Index vshIndex; + vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() ); + } + Draw(); + } + + inline const char *GetAdditiveEnvmapPixelShaderName( bool usingMask, + bool usingBaseTexture, bool usingBaseAlphaEnvmapMask ) + { + static char const* s_pPixelShaders[] = + { + "LightmappedGeneric_AddEnvmapNoTexture", + "LightmappedGeneric_AddEnvmapMaskNoTexture", + }; + + if ( !usingMask && usingBaseTexture && usingBaseAlphaEnvmapMask ) + return "LightmappedGeneric_AddBaseAlphaMaskedEnvMap"; + + int pshIndex = 0; + if (usingMask) + pshIndex |= 0x1; + return s_pPixelShaders[pshIndex]; + } + + void DrawAdditiveEnvmap( IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow ) + { + bool usingBaseTexture = params[BASETEXTURE]->IsTexture(); + bool usingMask = params[ENVMAPMASK]->IsTexture(); + bool usingBaseAlphaEnvmapMask = IS_FLAG_SET(MATERIAL_VAR_BASEALPHAENVMAPMASK); + SHADOW_STATE + { + // Alpha test + pShaderShadow->EnableAlphaTest( false ); + + pShaderShadow->EnableTexture( SHADER_SAMPLER0, false ); + pShaderShadow->EnableTexture( SHADER_SAMPLER1, false ); + + // envmap on stage 2 + pShaderShadow->EnableTexture( SHADER_SAMPLER2, true ); + + // envmapmask on stage 3 + if (params[ENVMAPMASK]->IsTexture() || IS_FLAG_SET(MATERIAL_VAR_BASEALPHAENVMAPMASK ) ) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER3, true ); + } + + if (params[BASETEXTURE]->IsTexture()) + { + SetAdditiveBlendingShadowState( BASETEXTURE, true ); + } + else + { + SetAdditiveBlendingShadowState( ENVMAPMASK, false ); + } + + int fmt = VERTEX_POSITION | VERTEX_NORMAL; + + pShaderShadow->VertexShaderVertexFormat( fmt, 1, 0, 0 ); + + // Compute the vertex shader index. + lightmappedgeneric_vs11_Static_Index vshIndex; + vshIndex.SetDETAIL( false ); + vshIndex.SetENVMAP( true ); + vshIndex.SetENVMAPCAMERASPACE( IS_FLAG_SET(MATERIAL_VAR_ENVMAPCAMERASPACE) ); + vshIndex.SetENVMAPSPHERE( IS_FLAG_SET(MATERIAL_VAR_ENVMAPSPHERE) ); + vshIndex.SetVERTEXCOLOR( false ); + s_pShaderShadow->SetVertexShader( "LightmappedGeneric_vs11", vshIndex.GetIndex() ); + + const char *pshName = GetAdditiveEnvmapPixelShaderName( usingMask, + usingBaseTexture, usingBaseAlphaEnvmapMask ); + pShaderShadow->SetPixelShader( pshName ); + FogToBlack(); + } + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER2, ENVMAP, ENVMAPFRAME ); + + if (usingMask || IS_FLAG_SET(MATERIAL_VAR_BASEALPHAENVMAPMASK)) + { + if (usingMask) + BindTexture( SHADER_SAMPLER3, ENVMAPMASK, ENVMAPMASKFRAME ); + else + BindTexture( SHADER_SAMPLER3, BASETEXTURE, FRAME ); + + SetVertexShaderTextureScaledTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_2, BASETEXTURETRANSFORM, ENVMAPMASKSCALE ); + } + + SetPixelShaderConstant( 2, ENVMAPTINT ); + + if (IS_FLAG_SET(MATERIAL_VAR_ENVMAPSPHERE) || IS_FLAG_SET(MATERIAL_VAR_ENVMAPCAMERASPACE)) + { + LoadViewMatrixIntoVertexShaderConstant( VERTEX_SHADER_VIEWMODEL ); + } + + SetModulationVertexShaderDynamicState(); + + // Compute the vertex shader index. + lightmappedgeneric_vs11_Dynamic_Index vshIndex; + vshIndex.SetDOWATERFOG( s_pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + s_pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() ); + } + Draw(); + } + + void DrawDetailMode1( IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow, bool bBumpedEnvMap ) + { + // Mode 1 : + // Pass 1 : B * L * D + Self Illum + // Pass 2 : Add E * M + + // Draw the detail w/ no envmap + DrawDetailNoEnvmap( params, pShaderAPI, pShaderShadow, true ); + + if ( !bBumpedEnvMap ) + { + DrawAdditiveEnvmap( params, pShaderAPI, pShaderShadow ); + } + else + { + DrawWorldBumpedSpecularLighting( + BUMPMAP, ENVMAP, BUMPFRAME, ENVMAPFRAME, + ENVMAPTINT, ALPHA, ENVMAPCONTRAST, ENVMAPSATURATION, + BUMPTRANSFORM, FRESNELREFLECTION, + true ); + } + } + + void DrawDetailUsingVertexShader( IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow, bool bBumpedEnvMap ) + { + // We don't have enough textures; gotta do this in two passes if there's envmapping + if (!params[ENVMAP]->IsTexture()) + { + DrawDetailNoEnvmap( params, pShaderAPI, pShaderShadow, IS_FLAG_SET( MATERIAL_VAR_SELFILLUM ) ); + } + else + { + if (!params[BASETEXTURE]->IsTexture()) + { + // If there's an envmap but no base texture, ignore detail + DrawUnbumpedUsingVertexShader( params, pShaderAPI, pShaderShadow, bBumpedEnvMap ); + } + else + { + DrawDetailMode1( params, pShaderAPI, pShaderShadow, bBumpedEnvMap ); + } + } + } + + void DrawUnbumpedSeamlessUsingVertexShader( IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow ) + { + // This is the seamless_scale version, which doesn't use $detail or $bumpmap + SHADOW_STATE + { + // three copies of the base texture for seamless blending + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER2, true ); + + // lightmap + pShaderShadow->EnableTexture( SHADER_SAMPLER3, true ); + + int fmt = VERTEX_POSITION; + pShaderShadow->VertexShaderVertexFormat( fmt, 2, 0, 0 ); + + worldvertextransition_seamless_Static_Index vshIndex; + pShaderShadow->SetVertexShader( "WorldVertexTransition_Seamless", vshIndex.GetIndex() ); + + int pshIndex = 0; + pShaderShadow->SetPixelShader( "WorldVertexTransition_Seamless", pshIndex ); + + FogToFogColor(); + } + DYNAMIC_STATE + { + bool bLightingOnly = mat_fullbright.GetInt() == 2 && !IS_FLAG_SET( MATERIAL_VAR_NO_DEBUG_OVERRIDE ); + // Texture 0..2 + if( bLightingOnly ) + { + pShaderAPI->BindStandardTexture( SHADER_SAMPLER0, TEXTURE_GREY ); + pShaderAPI->BindStandardTexture( SHADER_SAMPLER1, TEXTURE_GREY ); + pShaderAPI->BindStandardTexture( SHADER_SAMPLER2, TEXTURE_GREY ); + } + else + { + BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME ); + BindTexture( SHADER_SAMPLER1, BASETEXTURE, FRAME ); + BindTexture( SHADER_SAMPLER2, BASETEXTURE, FRAME ); + } + + // Texture 3 = lightmap + pShaderAPI->BindStandardTexture( SHADER_SAMPLER3, TEXTURE_LIGHTMAP ); + + EnablePixelShaderOverbright( 0, true, true ); + + float fSeamlessScale = params[SEAMLESS_SCALE]->GetFloatValue(); + float map_scale[4]= { fSeamlessScale, fSeamlessScale, fSeamlessScale, fSeamlessScale }; + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, map_scale ); + + worldvertextransition_seamless_Dynamic_Index vshIndex; + vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() ); + } + Draw(); + } + + SHADER_DRAW + { + bool hasFlashlight = UsingFlashlight( params ); + bool bBump = ShouldUseBumpmapping( params ) && params[BUMPMAP]->IsTexture() && + (params[NODIFFUSEBUMPLIGHTING]->GetIntValue() == 0); + bool bSSBump = bBump && ( params[SSBUMP]->GetIntValue() != 0 ); + + if( hasFlashlight ) + { + DrawFlashlight_dx80( params, pShaderAPI, pShaderShadow, bBump, BUMPMAP, BUMPFRAME, BUMPTRANSFORM, + FLASHLIGHTTEXTURE, FLASHLIGHTTEXTUREFRAME, true, false, 0, -1, -1 ); + } + else if( bBump ) + { + DrawWorldBumpedUsingVertexShader( + BASETEXTURE, BASETEXTURETRANSFORM, + BUMPMAP, BUMPFRAME, BUMPTRANSFORM, ENVMAPMASK, ENVMAPMASKFRAME, ENVMAP, + ENVMAPFRAME, ENVMAPTINT, COLOR, ALPHA, ENVMAPCONTRAST, ENVMAPSATURATION, FRAME, FRESNELREFLECTION, + false, -1, -1, -1, bSSBump ); + } + else + { + bool bBumpedEnvMap = ShouldUseBumpmapping( params ) && params[BUMPMAP]->IsTexture() && params[ENVMAP]->IsTexture(); + if (!params[DETAIL]->IsTexture()) + { + if( params[SEAMLESS_SCALE]->GetFloatValue() != 0.0f ) + { + DrawUnbumpedSeamlessUsingVertexShader( params, pShaderAPI, pShaderShadow ); + } + else + { + DrawUnbumpedUsingVertexShader( params, pShaderAPI, pShaderShadow, bBumpedEnvMap ); + } + } + else + { + DrawDetailUsingVertexShader( params, pShaderAPI, pShaderShadow, bBumpedEnvMap ); + } + } + } +END_SHADER + + +//----------------------------------------------------------------------------- +// Version that doesn't do bumpmapping +//----------------------------------------------------------------------------- +BEGIN_INHERITED_SHADER( LightmappedGeneric_NoBump_DX8, LightmappedGeneric_DX8, + "Help for LightmappedGeneric_NoBump_DX8" ) + + SHADER_FALLBACK + { + if (g_pHardwareConfig->GetDXSupportLevel() < 80) + return "LightmappedGeneric_DX6"; + + return 0; + } + + virtual bool ShouldUseBumpmapping( IMaterialVar **params ) + { + if ( !g_pConfig->UseBumpmapping() ) + return false; + + if ( !params[BUMPMAP]->IsDefined() ) + return false; + + return ( params[FORCEBUMP]->GetIntValue() != 0 ); + } + +END_INHERITED_SHADER diff --git a/materialsystem/stdshaders/lightmappedgeneric_dx9.cpp b/materialsystem/stdshaders/lightmappedgeneric_dx9.cpp new file mode 100644 index 0000000..bac124a --- /dev/null +++ b/materialsystem/stdshaders/lightmappedgeneric_dx9.cpp @@ -0,0 +1,164 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: Lightmap only shader +// +// $Header: $ +// $NoKeywords: $ +//=============================================================================// + +#include "BaseVSShader.h" +#include "convar.h" +#include "lightmappedgeneric_dx9_helper.h" + +static LightmappedGeneric_DX9_Vars_t s_info; + + +BEGIN_VS_SHADER( LightmappedGeneric, + "Help for LightmappedGeneric" ) + + BEGIN_SHADER_PARAMS + SHADER_PARAM( ALBEDO, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "albedo (Base texture with no baked lighting)" ) + SHADER_PARAM( SELFILLUMTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "Self-illumination tint" ) + SHADER_PARAM( DETAIL, SHADER_PARAM_TYPE_TEXTURE, "shadertest/detail", "detail texture" ) + SHADER_PARAM( DETAILFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $detail" ) + SHADER_PARAM( DETAILSCALE, SHADER_PARAM_TYPE_FLOAT, "4", "scale of the detail texture" ) + + SHADER_PARAM( ALPHA2, SHADER_PARAM_TYPE_FLOAT, "1", "" ) + + // detail (multi-) texturing + SHADER_PARAM( DETAILBLENDMODE, SHADER_PARAM_TYPE_INTEGER, "0", "mode for combining detail texture with base. 0=normal, 1= additive, 2=alpha blend detail over base, 3=crossfade" ) + SHADER_PARAM( DETAILBLENDFACTOR, SHADER_PARAM_TYPE_FLOAT, "1", "blend amount for detail texture." ) + SHADER_PARAM( DETAILTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "detail texture tint" ) + + SHADER_PARAM( ENVMAP, SHADER_PARAM_TYPE_TEXTURE, "shadertest/shadertest_env", "envmap" ) + SHADER_PARAM( ENVMAPFRAME, SHADER_PARAM_TYPE_INTEGER, "", "" ) + SHADER_PARAM( ENVMAPMASK, SHADER_PARAM_TYPE_TEXTURE, "shadertest/shadertest_envmask", "envmap mask" ) + SHADER_PARAM( ENVMAPMASKFRAME, SHADER_PARAM_TYPE_INTEGER, "", "" ) + SHADER_PARAM( ENVMAPMASKTRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$envmapmask texcoord transform" ) + SHADER_PARAM( ENVMAPTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "envmap tint" ) + SHADER_PARAM( BUMPMAP, SHADER_PARAM_TYPE_TEXTURE, "models/shadertest/shader1_normal", "bump map" ) + SHADER_PARAM( BUMPFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $bumpmap" ) + SHADER_PARAM( BUMPTRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$bumpmap texcoord transform" ) + SHADER_PARAM( ENVMAPCONTRAST, SHADER_PARAM_TYPE_FLOAT, "0.0", "contrast 0 == normal 1 == color*color" ) + SHADER_PARAM( ENVMAPSATURATION, SHADER_PARAM_TYPE_FLOAT, "1.0", "saturation 0 == greyscale 1 == normal" ) + SHADER_PARAM( FRESNELREFLECTION, SHADER_PARAM_TYPE_FLOAT, "1.0", "1.0 == mirror, 0.0 == water" ) + SHADER_PARAM( NODIFFUSEBUMPLIGHTING, SHADER_PARAM_TYPE_INTEGER, "0", "0 == Use diffuse bump lighting, 1 = No diffuse bump lighting" ) + SHADER_PARAM( BUMPMAP2, SHADER_PARAM_TYPE_TEXTURE, "models/shadertest/shader3_normal", "bump map" ) + SHADER_PARAM( BUMPFRAME2, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $bumpmap" ) + SHADER_PARAM( BUMPTRANSFORM2, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$bumpmap texcoord transform" ) + SHADER_PARAM( BUMPMASK, SHADER_PARAM_TYPE_TEXTURE, "models/shadertest/shader3_normal", "bump map" ) + SHADER_PARAM( BASETEXTURE2, SHADER_PARAM_TYPE_TEXTURE, "shadertest/lightmappedtexture", "Blended texture" ) + SHADER_PARAM( FRAME2, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $basetexture2" ) + SHADER_PARAM( BASETEXTURENOENVMAP, SHADER_PARAM_TYPE_BOOL, "0", "" ) + SHADER_PARAM( BASETEXTURE2NOENVMAP, SHADER_PARAM_TYPE_BOOL, "0", "" ) + SHADER_PARAM( DETAIL_ALPHA_MASK_BASE_TEXTURE, SHADER_PARAM_TYPE_BOOL, "0", + "If this is 1, then when detail alpha=0, no base texture is blended and when " + "detail alpha=1, you get detail*base*lightmap" ) + SHADER_PARAM( LIGHTWARPTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "light munging lookup texture" ) + SHADER_PARAM( BLENDMODULATETEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "texture to use r/g channels for blend range for" ) + SHADER_PARAM( MASKEDBLENDING, SHADER_PARAM_TYPE_INTEGER, "0", "blend using texture with no vertex alpha. For using texture blending on non-displacements" ) + SHADER_PARAM( BLENDMASKTRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$blendmodulatetexture texcoord transform" ) + SHADER_PARAM( SSBUMP, SHADER_PARAM_TYPE_INTEGER, "0", "whether or not to use alternate bumpmap format with height" ) + SHADER_PARAM( SEAMLESS_SCALE, SHADER_PARAM_TYPE_FLOAT, "0", "Scale factor for 'seamless' texture mapping. 0 means to use ordinary mapping" ) + SHADER_PARAM( ALPHATESTREFERENCE, SHADER_PARAM_TYPE_FLOAT, "0.0", "" ) + + SHADER_PARAM( SOFTEDGES, SHADER_PARAM_TYPE_BOOL, "0", "Enable soft edges to distance coded textures.") + SHADER_PARAM( EDGESOFTNESSSTART, SHADER_PARAM_TYPE_FLOAT, "0.6", "Start value for soft edges for distancealpha."); + SHADER_PARAM( EDGESOFTNESSEND, SHADER_PARAM_TYPE_FLOAT, "0.5", "End value for soft edges for distancealpha."); + + SHADER_PARAM( OUTLINE, SHADER_PARAM_TYPE_BOOL, "0", "Enable outline for distance coded textures.") + SHADER_PARAM( OUTLINECOLOR, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "color of outline for distance coded images." ) + SHADER_PARAM( OUTLINEALPHA, SHADER_PARAM_TYPE_FLOAT, "0.0", "alpha value for outline") + SHADER_PARAM( OUTLINESTART0, SHADER_PARAM_TYPE_FLOAT, "0.0", "outer start value for outline") + SHADER_PARAM( OUTLINESTART1, SHADER_PARAM_TYPE_FLOAT, "0.0", "inner start value for outline") + SHADER_PARAM( OUTLINEEND0, SHADER_PARAM_TYPE_FLOAT, "0.0", "inner end value for outline") + SHADER_PARAM( OUTLINEEND1, SHADER_PARAM_TYPE_FLOAT, "0.0", "outer end value for outline") +END_SHADER_PARAMS + + void SetupVars( LightmappedGeneric_DX9_Vars_t& info ) + { + info.m_nBaseTexture = BASETEXTURE; + info.m_nBaseTextureFrame = FRAME; + info.m_nBaseTextureTransform = BASETEXTURETRANSFORM; + info.m_nAlbedo = ALBEDO; + info.m_nSelfIllumTint = SELFILLUMTINT; + + info.m_nAlpha2 = ALPHA2; + + info.m_nDetail = DETAIL; + info.m_nDetailFrame = DETAILFRAME; + info.m_nDetailScale = DETAILSCALE; + info.m_nDetailTextureCombineMode = DETAILBLENDMODE; + info.m_nDetailTextureBlendFactor = DETAILBLENDFACTOR; + info.m_nDetailTint = DETAILTINT; + + info.m_nEnvmap = ENVMAP; + info.m_nEnvmapFrame = ENVMAPFRAME; + info.m_nEnvmapMask = ENVMAPMASK; + info.m_nEnvmapMaskFrame = ENVMAPMASKFRAME; + info.m_nEnvmapMaskTransform = ENVMAPMASKTRANSFORM; + info.m_nEnvmapTint = ENVMAPTINT; + info.m_nBumpmap = BUMPMAP; + info.m_nBumpFrame = BUMPFRAME; + info.m_nBumpTransform = BUMPTRANSFORM; + info.m_nEnvmapContrast = ENVMAPCONTRAST; + info.m_nEnvmapSaturation = ENVMAPSATURATION; + info.m_nFresnelReflection = FRESNELREFLECTION; + info.m_nNoDiffuseBumpLighting = NODIFFUSEBUMPLIGHTING; + info.m_nBumpmap2 = BUMPMAP2; + info.m_nBumpFrame2 = BUMPFRAME2; + info.m_nBumpTransform2 = BUMPTRANSFORM2; + info.m_nBumpMask = BUMPMASK; + info.m_nBaseTexture2 = BASETEXTURE2; + info.m_nBaseTexture2Frame = FRAME2; + info.m_nBaseTextureNoEnvmap = BASETEXTURENOENVMAP; + info.m_nBaseTexture2NoEnvmap = BASETEXTURE2NOENVMAP; + info.m_nDetailAlphaMaskBaseTexture = DETAIL_ALPHA_MASK_BASE_TEXTURE; + info.m_nFlashlightTexture = FLASHLIGHTTEXTURE; + info.m_nFlashlightTextureFrame = FLASHLIGHTTEXTUREFRAME; + info.m_nLightWarpTexture = LIGHTWARPTEXTURE; + info.m_nBlendModulateTexture = BLENDMODULATETEXTURE; + info.m_nMaskedBlending = MASKEDBLENDING; + info.m_nBlendMaskTransform = BLENDMASKTRANSFORM; + info.m_nSelfShadowedBumpFlag = SSBUMP; + info.m_nSeamlessMappingScale = SEAMLESS_SCALE; + info.m_nAlphaTestReference = ALPHATESTREFERENCE; + + info.m_nSoftEdges = SOFTEDGES; + info.m_nEdgeSoftnessStart = EDGESOFTNESSSTART; + info.m_nEdgeSoftnessEnd = EDGESOFTNESSEND; + info.m_nOutline = OUTLINE; + info.m_nOutlineColor = OUTLINECOLOR; + info.m_nOutlineAlpha = OUTLINEALPHA; + info.m_nOutlineStart0 = OUTLINESTART0; + info.m_nOutlineStart1 = OUTLINESTART1; + info.m_nOutlineEnd0 = OUTLINEEND0; + info.m_nOutlineEnd1 = OUTLINEEND1; + } + + SHADER_FALLBACK + { + if( g_pHardwareConfig->GetDXSupportLevel() < 90 ) + return "LightmappedGeneric_DX8"; + + return 0; + } + + // Set up anything that is necessary to make decisions in SHADER_FALLBACK. + SHADER_INIT_PARAMS() + { + SetupVars( s_info ); + InitParamsLightmappedGeneric_DX9( this, params, pMaterialName, s_info ); + } + + SHADER_INIT + { + SetupVars( s_info ); + InitLightmappedGeneric_DX9( this, params, s_info ); + } + + SHADER_DRAW + { + DrawLightmappedGeneric_DX9( this, params, pShaderAPI, pShaderShadow, s_info, pContextDataPtr ); + } +END_SHADER diff --git a/materialsystem/stdshaders/lightmappedgeneric_dx9_helper.cpp b/materialsystem/stdshaders/lightmappedgeneric_dx9_helper.cpp new file mode 100644 index 0000000..6f9c95a --- /dev/null +++ b/materialsystem/stdshaders/lightmappedgeneric_dx9_helper.cpp @@ -0,0 +1,1021 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: Lightmap only shader +// +// $Header: $ +// $NoKeywords: $ +//============================================================================= + +#include "lightmappedgeneric_dx9_helper.h" +#include "BaseVSShader.h" +#include "commandbuilder.h" +#include "convar.h" +#include "lightmappedgeneric_ps20.inc" +#include "lightmappedgeneric_vs20.inc" +#include "lightmappedgeneric_ps20b.inc" + +#include "tier0/memdbgon.h" + +ConVar mat_disable_lightwarp( "mat_disable_lightwarp", "0" ); +ConVar mat_disable_fancy_blending( "mat_disable_fancy_blending", "0" ); +ConVar mat_fullbright( "mat_fullbright","0", FCVAR_CHEAT ); +ConVar my_mat_fullbright( "mat_fullbright","0", FCVAR_CHEAT ); +extern ConVar r_flashlight_version2; + +class CLightmappedGeneric_DX9_Context : public CBasePerMaterialContextData +{ +public: + uint8 *m_pStaticCmds; + CCommandBufferBuilder< CFixedCommandStorageBuffer< 1000 > > m_SemiStaticCmdsOut; + + bool m_bVertexShaderFastPath; + bool m_bPixelShaderFastPath; + bool m_bPixelShaderForceFastPathBecauseOutline; + bool m_bFullyOpaque; + bool m_bFullyOpaqueWithoutAlphaTest; + + void ResetStaticCmds( void ) + { + if ( m_pStaticCmds ) + { + delete[] m_pStaticCmds; + m_pStaticCmds = NULL; + } + } + + CLightmappedGeneric_DX9_Context( void ) + { + m_pStaticCmds = NULL; + } + + ~CLightmappedGeneric_DX9_Context( void ) + { + ResetStaticCmds(); + } + +}; + + +void InitParamsLightmappedGeneric_DX9( CBaseVSShader *pShader, IMaterialVar** params, const char *pMaterialName, LightmappedGeneric_DX9_Vars_t &info ) +{ + if ( g_pHardwareConfig->SupportsBorderColor() ) + { + params[FLASHLIGHTTEXTURE]->SetStringValue( "effects/flashlight_border" ); + } + else + { + params[FLASHLIGHTTEXTURE]->SetStringValue( "effects/flashlight001" ); + } + + // Write over $basetexture with $albedo if we are going to be using diffuse normal mapping. + if( g_pConfig->UseBumpmapping() && params[info.m_nBumpmap]->IsDefined() && params[info.m_nAlbedo]->IsDefined() && + params[info.m_nBaseTexture]->IsDefined() && + !( params[info.m_nNoDiffuseBumpLighting]->IsDefined() && params[info.m_nNoDiffuseBumpLighting]->GetIntValue() ) ) + { + params[info.m_nBaseTexture]->SetStringValue( params[info.m_nAlbedo]->GetStringValue() ); + } + + if( pShader->IsUsingGraphics() && params[info.m_nEnvmap]->IsDefined() && !pShader->CanUseEditorMaterials() ) + { + if( stricmp( params[info.m_nEnvmap]->GetStringValue(), "env_cubemap" ) == 0 ) + { + Warning( "env_cubemap used on world geometry without rebuilding map. . ignoring: %s\n", pMaterialName ); + params[info.m_nEnvmap]->SetUndefined(); + } + } + + if ( (mat_disable_lightwarp.GetBool() ) && + (info.m_nLightWarpTexture != -1) ) + { + params[info.m_nLightWarpTexture]->SetUndefined(); + } + if ( (mat_disable_fancy_blending.GetBool() ) && + (info.m_nBlendModulateTexture != -1) ) + { + params[info.m_nBlendModulateTexture]->SetUndefined(); + } + + if( !params[info.m_nEnvmapTint]->IsDefined() ) + params[info.m_nEnvmapTint]->SetVecValue( 1.0f, 1.0f, 1.0f ); + + if( !params[info.m_nNoDiffuseBumpLighting]->IsDefined() ) + params[info.m_nNoDiffuseBumpLighting]->SetIntValue( 0 ); + + if( !params[info.m_nSelfIllumTint]->IsDefined() ) + params[info.m_nSelfIllumTint]->SetVecValue( 1.0f, 1.0f, 1.0f ); + + if( !params[info.m_nDetailScale]->IsDefined() ) + params[info.m_nDetailScale]->SetFloatValue( 4.0f ); + + if ( !params[info.m_nDetailTint]->IsDefined() ) + params[info.m_nDetailTint]->SetVecValue( 1.0f, 1.0f, 1.0f, 1.0f ); + + InitFloatParam( info.m_nDetailTextureBlendFactor, params, 1.0 ); + InitIntParam( info.m_nDetailTextureCombineMode, params, 0 ); + + if( !params[info.m_nFresnelReflection]->IsDefined() ) + params[info.m_nFresnelReflection]->SetFloatValue( 1.0f ); + + if( !params[info.m_nEnvmapMaskFrame]->IsDefined() ) + params[info.m_nEnvmapMaskFrame]->SetIntValue( 0 ); + + if( !params[info.m_nEnvmapFrame]->IsDefined() ) + params[info.m_nEnvmapFrame]->SetIntValue( 0 ); + + if( !params[info.m_nBumpFrame]->IsDefined() ) + params[info.m_nBumpFrame]->SetIntValue( 0 ); + + if( !params[info.m_nDetailFrame]->IsDefined() ) + params[info.m_nDetailFrame]->SetIntValue( 0 ); + + if( !params[info.m_nEnvmapContrast]->IsDefined() ) + params[info.m_nEnvmapContrast]->SetFloatValue( 0.0f ); + + if( !params[info.m_nEnvmapSaturation]->IsDefined() ) + params[info.m_nEnvmapSaturation]->SetFloatValue( 1.0f ); + + InitFloatParam( info.m_nAlphaTestReference, params, 0.0f ); + + // No texture means no self-illum or env mask in base alpha + if ( !params[info.m_nBaseTexture]->IsDefined() ) + { + CLEAR_FLAGS( MATERIAL_VAR_SELFILLUM ); + CLEAR_FLAGS( MATERIAL_VAR_BASEALPHAENVMAPMASK ); + } + + if( params[info.m_nBumpmap]->IsDefined() ) + { + params[info.m_nEnvmapMask]->SetUndefined(); + } + + // If in decal mode, no debug override... + if (IS_FLAG_SET(MATERIAL_VAR_DECAL)) + { + SET_FLAGS( MATERIAL_VAR_NO_DEBUG_OVERRIDE ); + } + + SET_FLAGS2( MATERIAL_VAR2_LIGHTING_LIGHTMAP ); + if( g_pConfig->UseBumpmapping() && params[info.m_nBumpmap]->IsDefined() && (params[info.m_nNoDiffuseBumpLighting]->GetIntValue() == 0) ) + { + SET_FLAGS2( MATERIAL_VAR2_LIGHTING_BUMPED_LIGHTMAP ); + } + + // If mat_specular 0, then get rid of envmap + if( !g_pConfig->UseSpecular() && params[info.m_nEnvmap]->IsDefined() && params[info.m_nBaseTexture]->IsDefined() ) + { + params[info.m_nEnvmap]->SetUndefined(); + } + + if( !params[info.m_nBaseTextureNoEnvmap]->IsDefined() ) + { + params[info.m_nBaseTextureNoEnvmap]->SetIntValue( 0 ); + } + if( !params[info.m_nBaseTexture2NoEnvmap]->IsDefined() ) + { + params[info.m_nBaseTexture2NoEnvmap]->SetIntValue( 0 ); + } + + if( ( info.m_nSelfShadowedBumpFlag != -1 ) && + ( !params[info.m_nSelfShadowedBumpFlag]->IsDefined() ) + ) + { + params[info.m_nSelfShadowedBumpFlag]->SetIntValue( 0 ); + } + // handle line art parms + InitFloatParam( info.m_nEdgeSoftnessStart, params, 0.5 ); + InitFloatParam( info.m_nEdgeSoftnessEnd, params, 0.5 ); + InitFloatParam( info.m_nOutlineAlpha, params, 1.0 ); +} + +void InitLightmappedGeneric_DX9( CBaseVSShader *pShader, IMaterialVar** params, LightmappedGeneric_DX9_Vars_t &info ) +{ + if ( g_pConfig->UseBumpmapping() && params[info.m_nBumpmap]->IsDefined() ) + { + pShader->LoadBumpMap( info.m_nBumpmap ); + } + + if ( g_pConfig->UseBumpmapping() && params[info.m_nBumpmap2]->IsDefined() ) + { + pShader->LoadBumpMap( info.m_nBumpmap2 ); + } + + if ( g_pConfig->UseBumpmapping() && params[info.m_nBumpMask]->IsDefined() ) + { + pShader->LoadBumpMap( info.m_nBumpMask ); + } + + if (params[info.m_nBaseTexture]->IsDefined()) + { + pShader->LoadTexture( info.m_nBaseTexture, TEXTUREFLAGS_SRGB ); + + if (!params[info.m_nBaseTexture]->GetTextureValue()->IsTranslucent()) + { + CLEAR_FLAGS( MATERIAL_VAR_SELFILLUM ); + CLEAR_FLAGS( MATERIAL_VAR_BASEALPHAENVMAPMASK ); + } + } + + if (params[info.m_nBaseTexture2]->IsDefined() ) + { + pShader->LoadTexture( info.m_nBaseTexture2, TEXTUREFLAGS_SRGB ); + } + + if (params[info.m_nLightWarpTexture]->IsDefined() ) + { + pShader->LoadTexture( info.m_nLightWarpTexture ); + } + + if ((info.m_nBlendModulateTexture != -1) && + (params[info.m_nBlendModulateTexture]->IsDefined()) ) + { + pShader->LoadTexture( info.m_nBlendModulateTexture ); + } + + if (params[info.m_nDetail]->IsDefined()) + { + int nDetailBlendMode = ( info.m_nDetailTextureCombineMode == -1 ) ? 0 : params[info.m_nDetailTextureCombineMode]->GetIntValue(); + nDetailBlendMode = nDetailBlendMode > 1 ? 1 : nDetailBlendMode; + + pShader->LoadTexture( info.m_nDetail, nDetailBlendMode != 0 ? TEXTUREFLAGS_SRGB : 0 ); + } + + pShader->LoadTexture( info.m_nFlashlightTexture, TEXTUREFLAGS_SRGB ); + + // Don't alpha test if the alpha channel is used for other purposes + if (IS_FLAG_SET(MATERIAL_VAR_SELFILLUM) || IS_FLAG_SET(MATERIAL_VAR_BASEALPHAENVMAPMASK) ) + { + CLEAR_FLAGS( MATERIAL_VAR_ALPHATEST ); + } + + if (params[info.m_nEnvmap]->IsDefined()) + { + if ( !IS_FLAG_SET(MATERIAL_VAR_ENVMAPSPHERE) ) + { + pShader->LoadCubeMap( info.m_nEnvmap, g_pHardwareConfig->GetHDRType() == HDR_TYPE_NONE ? TEXTUREFLAGS_SRGB : 0 ); + } + else + { + pShader->LoadTexture( info.m_nEnvmap ); + } + + if ( !g_pHardwareConfig->SupportsCubeMaps() ) + { + SET_FLAGS( MATERIAL_VAR_ENVMAPSPHERE ); + } + + if ( params[info.m_nEnvmapMask]->IsDefined() ) + { + pShader->LoadTexture( info.m_nEnvmapMask ); + } + } + else + { + params[info.m_nEnvmapMask]->SetUndefined(); + } + + // We always need this because of the flashlight. + SET_FLAGS2( MATERIAL_VAR2_NEEDS_TANGENT_SPACES ); +} + +void DrawLightmappedGeneric_DX9_Internal(CBaseVSShader *pShader, IMaterialVar** params, bool hasFlashlight, + IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow, + LightmappedGeneric_DX9_Vars_t &info, + CBasePerMaterialContextData **pContextDataPtr + ) +{ + CLightmappedGeneric_DX9_Context *pContextData = reinterpret_cast< CLightmappedGeneric_DX9_Context *> ( *pContextDataPtr ); + if ( pShaderShadow || ( ! pContextData ) || pContextData->m_bMaterialVarsChanged || hasFlashlight ) + { + bool hasBaseTexture = params[info.m_nBaseTexture]->IsTexture(); + int nAlphaChannelTextureVar = hasBaseTexture ? (int)info.m_nBaseTexture : (int)info.m_nEnvmapMask; + BlendType_t nBlendType = pShader->EvaluateBlendRequirements( nAlphaChannelTextureVar, hasBaseTexture ); + bool bIsAlphaTested = IS_FLAG_SET( MATERIAL_VAR_ALPHATEST ) != 0; + bool bFullyOpaqueWithoutAlphaTest = (nBlendType != BT_BLENDADD) && (nBlendType != BT_BLEND) && (!hasFlashlight || IsX360()); //dest alpha is free for special use + bool bFullyOpaque = bFullyOpaqueWithoutAlphaTest && !bIsAlphaTested; + bool bNeedRegenStaticCmds = (! pContextData ) || pShaderShadow; + + if ( ! pContextData ) // make sure allocated + { + pContextData = new CLightmappedGeneric_DX9_Context; + *pContextDataPtr = pContextData; + } + + bool hasBump = ( params[info.m_nBumpmap]->IsTexture() ) && ( !g_pHardwareConfig->PreferReducedFillrate() ); + bool hasSSBump = hasBump && (info.m_nSelfShadowedBumpFlag != -1) && ( params[info.m_nSelfShadowedBumpFlag]->GetIntValue() ); + bool hasBaseTexture2 = hasBaseTexture && params[info.m_nBaseTexture2]->IsTexture(); + bool hasLightWarpTexture = params[info.m_nLightWarpTexture]->IsTexture(); + bool hasBump2 = hasBump && params[info.m_nBumpmap2]->IsTexture(); + bool hasDetailTexture = params[info.m_nDetail]->IsTexture(); + bool hasSelfIllum = IS_FLAG_SET( MATERIAL_VAR_SELFILLUM ); + bool hasBumpMask = hasBump && hasBump2 && params[info.m_nBumpMask]->IsTexture() && !hasSelfIllum && + !hasDetailTexture && !hasBaseTexture2 && (params[info.m_nBaseTextureNoEnvmap]->GetIntValue() == 0); + bool bHasBlendModulateTexture = + (info.m_nBlendModulateTexture != -1) && + (params[info.m_nBlendModulateTexture]->IsTexture() ); + bool hasNormalMapAlphaEnvmapMask = IS_FLAG_SET( MATERIAL_VAR_NORMALMAPALPHAENVMAPMASK ); + + if ( hasFlashlight && !IsX360() ) + { + // !!speed!! do this in the caller so we don't build struct every time + CBaseVSShader::DrawFlashlight_dx90_Vars_t vars; + vars.m_bBump = hasBump; + vars.m_nBumpmapVar = info.m_nBumpmap; + vars.m_nBumpmapFrame = info.m_nBumpFrame; + vars.m_nBumpTransform = info.m_nBumpTransform; + vars.m_nFlashlightTextureVar = info.m_nFlashlightTexture; + vars.m_nFlashlightTextureFrameVar = info.m_nFlashlightTextureFrame; + vars.m_bLightmappedGeneric = true; + vars.m_bWorldVertexTransition = hasBaseTexture2; + vars.m_nBaseTexture2Var = info.m_nBaseTexture2; + vars.m_nBaseTexture2FrameVar = info.m_nBaseTexture2Frame; + vars.m_nBumpmap2Var = info.m_nBumpmap2; + vars.m_nBumpmap2Frame = info.m_nBumpFrame2; + vars.m_nBump2Transform = info.m_nBumpTransform2; + vars.m_nAlphaTestReference = info.m_nAlphaTestReference; + vars.m_bSSBump = hasSSBump; + vars.m_nDetailVar = info.m_nDetail; + vars.m_nDetailScale = info.m_nDetailScale; + vars.m_nDetailTextureCombineMode = info.m_nDetailTextureCombineMode; + vars.m_nDetailTextureBlendFactor = info.m_nDetailTextureBlendFactor; + vars.m_nDetailTint = info.m_nDetailTint; + + if ( ( info.m_nSeamlessMappingScale != -1 ) ) + vars.m_fSeamlessScale = params[info.m_nSeamlessMappingScale]->GetFloatValue(); + else + vars.m_fSeamlessScale = 0.0; + pShader->DrawFlashlight_dx90( params, pShaderAPI, pShaderShadow, vars ); + return; + } + + pContextData->m_bFullyOpaque = bFullyOpaque; + pContextData->m_bFullyOpaqueWithoutAlphaTest = bFullyOpaqueWithoutAlphaTest; + + bool bHasOutline = IsBoolSet( info.m_nOutline, params ); + pContextData->m_bPixelShaderForceFastPathBecauseOutline = bHasOutline; + bool bHasSoftEdges = IsBoolSet( info.m_nSoftEdges, params ); + bool hasEnvmapMask = params[info.m_nEnvmapMask]->IsTexture(); + + + float fDetailBlendFactor = GetFloatParam( info.m_nDetailTextureBlendFactor, params, 1.0 ); + + if ( pShaderShadow || bNeedRegenStaticCmds ) + { + bool hasVertexColor = IS_FLAG_SET( MATERIAL_VAR_VERTEXCOLOR ); + bool hasDiffuseBumpmap = hasBump && (params[info.m_nNoDiffuseBumpLighting]->GetIntValue() == 0); + + bool hasEnvmap = params[info.m_nEnvmap]->IsTexture(); + + bool bSeamlessMapping = ( ( info.m_nSeamlessMappingScale != -1 ) && + ( params[info.m_nSeamlessMappingScale]->GetFloatValue() != 0.0 ) ); + + if ( bNeedRegenStaticCmds ) + { + pContextData->ResetStaticCmds(); + CCommandBufferBuilder< CFixedCommandStorageBuffer< 5000 > > staticCmdsBuf; + + + if( !hasBaseTexture ) + { + if( hasEnvmap ) + { + // if we only have an envmap (no basetexture), then we want the albedo to be black. + staticCmdsBuf.BindStandardTexture( SHADER_SAMPLER0, TEXTURE_BLACK ); + } + else + { + staticCmdsBuf.BindStandardTexture( SHADER_SAMPLER0, TEXTURE_WHITE ); + } + } + staticCmdsBuf.BindStandardTexture( SHADER_SAMPLER1, TEXTURE_LIGHTMAP ); + + if ( bSeamlessMapping ) + { + staticCmdsBuf.SetVertexShaderConstant4( + VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, + params[info.m_nSeamlessMappingScale]->GetFloatValue(),0,0,0 ); + } + staticCmdsBuf.StoreEyePosInPixelShaderConstant( 10 ); + staticCmdsBuf.SetPixelShaderFogParams( 11 ); + staticCmdsBuf.End(); + // now, copy buf + pContextData->m_pStaticCmds = new uint8[staticCmdsBuf.Size()]; + memcpy( pContextData->m_pStaticCmds, staticCmdsBuf.Base(), staticCmdsBuf.Size() ); + } + if ( pShaderShadow ) + { + + // Alpha test: FIXME: shouldn't this be handled in Shader_t::SetInitialShadowState + pShaderShadow->EnableAlphaTest( bIsAlphaTested ); + if ( info.m_nAlphaTestReference != -1 && params[info.m_nAlphaTestReference]->GetFloatValue() > 0.0f ) + { + pShaderShadow->AlphaFunc( SHADER_ALPHAFUNC_GEQUAL, params[info.m_nAlphaTestReference]->GetFloatValue() ); + } + + pShader->SetDefaultBlendingShadowState( nAlphaChannelTextureVar, hasBaseTexture ); + + unsigned int flags = VERTEX_POSITION; + + // base texture + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, true ); + + if ( hasLightWarpTexture ) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER6, true ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER6, false ); + } + if ( bHasBlendModulateTexture ) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER3, true ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER3, false ); + } + + if ( hasBaseTexture2 ) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER7, true ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER7, true ); + } +// if( hasLightmap ) + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + if( g_pHardwareConfig->GetHDRType() == HDR_TYPE_NONE ) + { + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER1, true ); + } + else + { + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER1, false ); + } + + if( hasEnvmap || ( IsX360() && hasFlashlight ) ) + { + if( hasEnvmap ) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER2, true ); + if( g_pHardwareConfig->GetHDRType() == HDR_TYPE_NONE ) + { + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER2, true ); + } + } + flags |= VERTEX_TANGENT_S | VERTEX_TANGENT_T | VERTEX_NORMAL; + } + + int nDetailBlendMode = 0; + if ( hasDetailTexture ) + { + nDetailBlendMode = GetIntParam( info.m_nDetailTextureCombineMode, params ); + ITexture *pDetailTexture = params[info.m_nDetail]->GetTextureValue(); + if ( pDetailTexture->GetFlags() & TEXTUREFLAGS_SSBUMP ) + { + if ( hasBump ) + nDetailBlendMode = 10; // ssbump + else + nDetailBlendMode = 11; // ssbump_nobump + } + } + + if( hasDetailTexture ) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER12, true ); + bool bSRGBState = ( nDetailBlendMode == 1 ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER12, bSRGBState ); + } + + if( hasBump || hasNormalMapAlphaEnvmapMask ) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER4, true ); + } + if( hasBump2 ) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER5, true ); + } + if( hasBumpMask ) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER8, true ); + } + if( hasEnvmapMask ) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER5, true ); + } + + if( hasFlashlight && IsX360() ) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER13, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER14, true ); + pShaderShadow->SetShadowDepthFiltering( SHADER_SAMPLER14 ); + pShaderShadow->EnableTexture( SHADER_SAMPLER15, true ); + } + + if( hasVertexColor || hasBaseTexture2 || hasBump2 ) + { + flags |= VERTEX_COLOR; + } + + // texcoord0 : base texcoord + // texcoord1 : lightmap texcoord + // texcoord2 : lightmap texcoord offset + int numTexCoords = 2; + if( hasBump ) + { + numTexCoords = 3; + } + + pShaderShadow->VertexShaderVertexFormat( flags, numTexCoords, 0, 0 ); + + // Pre-cache pixel shaders + bool hasBaseAlphaEnvmapMask = IS_FLAG_SET( MATERIAL_VAR_BASEALPHAENVMAPMASK ); + + int bumpmap_variant=(hasSSBump) ? 2 : hasBump; + bool bMaskedBlending=( (info.m_nMaskedBlending != -1) && + (params[info.m_nMaskedBlending]->GetIntValue() != 0) ); + + DECLARE_STATIC_VERTEX_SHADER( lightmappedgeneric_vs20 ); + SET_STATIC_VERTEX_SHADER_COMBO( ENVMAP_MASK, hasEnvmapMask ); + SET_STATIC_VERTEX_SHADER_COMBO( TANGENTSPACE, params[info.m_nEnvmap]->IsTexture() ); + SET_STATIC_VERTEX_SHADER_COMBO( BUMPMAP, hasBump ); + SET_STATIC_VERTEX_SHADER_COMBO( DIFFUSEBUMPMAP, hasDiffuseBumpmap ); + SET_STATIC_VERTEX_SHADER_COMBO( VERTEXCOLOR, IS_FLAG_SET( MATERIAL_VAR_VERTEXCOLOR ) ); + SET_STATIC_VERTEX_SHADER_COMBO( VERTEXALPHATEXBLENDFACTOR, hasBaseTexture2 || hasBump2 ); + SET_STATIC_VERTEX_SHADER_COMBO( BUMPMASK, hasBumpMask ); + + bool bReliefMapping = false; //( bumpmap_variant == 2 ) && ( ! bSeamlessMapping ); + SET_STATIC_VERTEX_SHADER_COMBO( RELIEF_MAPPING, false );//bReliefMapping ); + SET_STATIC_VERTEX_SHADER_COMBO( SEAMLESS, bSeamlessMapping ); +#ifdef _X360 + SET_STATIC_VERTEX_SHADER_COMBO( FLASHLIGHT, hasFlashlight); +#endif + SET_STATIC_VERTEX_SHADER( lightmappedgeneric_vs20 ); + + if ( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_STATIC_PIXEL_SHADER( lightmappedgeneric_ps20b ); + SET_STATIC_PIXEL_SHADER_COMBO( BASETEXTURE2, hasBaseTexture2 ); + SET_STATIC_PIXEL_SHADER_COMBO( DETAILTEXTURE, hasDetailTexture ); + SET_STATIC_PIXEL_SHADER_COMBO( BUMPMAP, bumpmap_variant ); + SET_STATIC_PIXEL_SHADER_COMBO( BUMPMAP2, hasBump2 ); + SET_STATIC_PIXEL_SHADER_COMBO( BUMPMASK, hasBumpMask ); + SET_STATIC_PIXEL_SHADER_COMBO( DIFFUSEBUMPMAP, hasDiffuseBumpmap ); + SET_STATIC_PIXEL_SHADER_COMBO( CUBEMAP, hasEnvmap ); + SET_STATIC_PIXEL_SHADER_COMBO( ENVMAPMASK, hasEnvmapMask ); + SET_STATIC_PIXEL_SHADER_COMBO( BASEALPHAENVMAPMASK, hasBaseAlphaEnvmapMask ); + SET_STATIC_PIXEL_SHADER_COMBO( SELFILLUM, hasSelfIllum ); + SET_STATIC_PIXEL_SHADER_COMBO( NORMALMAPALPHAENVMAPMASK, hasNormalMapAlphaEnvmapMask ); + SET_STATIC_PIXEL_SHADER_COMBO( BASETEXTURENOENVMAP, params[info.m_nBaseTextureNoEnvmap]->GetIntValue() ); + SET_STATIC_PIXEL_SHADER_COMBO( BASETEXTURE2NOENVMAP, params[info.m_nBaseTexture2NoEnvmap]->GetIntValue() ); + SET_STATIC_PIXEL_SHADER_COMBO( WARPLIGHTING, hasLightWarpTexture ); + SET_STATIC_PIXEL_SHADER_COMBO( FANCY_BLENDING, bHasBlendModulateTexture ); + SET_STATIC_PIXEL_SHADER_COMBO( MASKEDBLENDING, bMaskedBlending); + SET_STATIC_PIXEL_SHADER_COMBO( RELIEF_MAPPING, bReliefMapping ); + SET_STATIC_PIXEL_SHADER_COMBO( SEAMLESS, bSeamlessMapping ); + SET_STATIC_PIXEL_SHADER_COMBO( OUTLINE, bHasOutline ); + SET_STATIC_PIXEL_SHADER_COMBO( SOFTEDGES, bHasSoftEdges ); + SET_STATIC_PIXEL_SHADER_COMBO( DETAIL_BLEND_MODE, nDetailBlendMode ); + SET_STATIC_PIXEL_SHADER_COMBO( NORMAL_DECODE_MODE, (int) NORMAL_DECODE_NONE ); + SET_STATIC_PIXEL_SHADER_COMBO( NORMALMASK_DECODE_MODE, (int) NORMAL_DECODE_NONE ); +#ifdef _X360 + SET_STATIC_PIXEL_SHADER_COMBO( FLASHLIGHT, hasFlashlight); +#endif + SET_STATIC_PIXEL_SHADER( lightmappedgeneric_ps20b ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( lightmappedgeneric_ps20 ); + SET_STATIC_PIXEL_SHADER_COMBO( BASETEXTURE2, hasBaseTexture2 ); + SET_STATIC_PIXEL_SHADER_COMBO( DETAILTEXTURE, hasDetailTexture ); + SET_STATIC_PIXEL_SHADER_COMBO( BUMPMAP, bumpmap_variant ); + SET_STATIC_PIXEL_SHADER_COMBO( BUMPMAP2, hasBump2 ); + SET_STATIC_PIXEL_SHADER_COMBO( BUMPMASK, hasBumpMask ); + SET_STATIC_PIXEL_SHADER_COMBO( DIFFUSEBUMPMAP, hasDiffuseBumpmap ); + SET_STATIC_PIXEL_SHADER_COMBO( CUBEMAP, hasEnvmap ); + SET_STATIC_PIXEL_SHADER_COMBO( ENVMAPMASK, hasEnvmapMask ); + SET_STATIC_PIXEL_SHADER_COMBO( BASEALPHAENVMAPMASK, hasBaseAlphaEnvmapMask ); + SET_STATIC_PIXEL_SHADER_COMBO( SELFILLUM, hasSelfIllum ); + SET_STATIC_PIXEL_SHADER_COMBO( NORMALMAPALPHAENVMAPMASK, hasNormalMapAlphaEnvmapMask ); + SET_STATIC_PIXEL_SHADER_COMBO( BASETEXTURENOENVMAP, params[info.m_nBaseTextureNoEnvmap]->GetIntValue() ); + SET_STATIC_PIXEL_SHADER_COMBO( BASETEXTURE2NOENVMAP, params[info.m_nBaseTexture2NoEnvmap]->GetIntValue() ); + SET_STATIC_PIXEL_SHADER_COMBO( WARPLIGHTING, hasLightWarpTexture ); + SET_STATIC_PIXEL_SHADER_COMBO( FANCY_BLENDING, bHasBlendModulateTexture ); + SET_STATIC_PIXEL_SHADER_COMBO( MASKEDBLENDING, bMaskedBlending); + SET_STATIC_PIXEL_SHADER_COMBO( SEAMLESS, bSeamlessMapping ); + SET_STATIC_PIXEL_SHADER_COMBO( OUTLINE, bHasOutline ); + SET_STATIC_PIXEL_SHADER_COMBO( SOFTEDGES, bHasSoftEdges ); + SET_STATIC_PIXEL_SHADER_COMBO( DETAIL_BLEND_MODE, nDetailBlendMode ); + SET_STATIC_PIXEL_SHADER_COMBO( NORMAL_DECODE_MODE, 0 ); // No normal compression with ps_2_0 (yikes!) + SET_STATIC_PIXEL_SHADER_COMBO( NORMALMASK_DECODE_MODE, 0 ); // No normal compression with ps_2_0 + SET_STATIC_PIXEL_SHADER( lightmappedgeneric_ps20 ); + } + // HACK HACK HACK - enable alpha writes all the time so that we have them for + // underwater stuff and writing depth to dest alpha + // But only do it if we're not using the alpha already for translucency + pShaderShadow->EnableAlphaWrites( bFullyOpaque ); + + pShaderShadow->EnableSRGBWrite( true ); + + pShader->DefaultFog(); + + + } // end shadow state + } // end shadow || regen display list + if ( pShaderAPI && pContextData->m_bMaterialVarsChanged ) + { + // need to regenerate the semistatic cmds + pContextData->m_SemiStaticCmdsOut.Reset(); + pContextData->m_bMaterialVarsChanged = false; + + bool bHasBlendMaskTransform= ( + (info.m_nBlendMaskTransform != -1) && + (info.m_nMaskedBlending != -1) && + (params[info.m_nMaskedBlending]->GetIntValue() ) && + ( ! (params[info.m_nBumpTransform]->MatrixIsIdentity() ) ) ); + + // If we don't have a texture transform, we don't have + // to set vertex shader constants or run vertex shader instructions + // for the texture transform. + bool bHasTextureTransform = + !( params[info.m_nBaseTextureTransform]->MatrixIsIdentity() && + params[info.m_nBumpTransform]->MatrixIsIdentity() && + params[info.m_nBumpTransform2]->MatrixIsIdentity() && + params[info.m_nEnvmapMaskTransform]->MatrixIsIdentity() ); + + bHasTextureTransform |= bHasBlendMaskTransform; + + pContextData->m_bVertexShaderFastPath = !bHasTextureTransform; + + if( params[info.m_nDetail]->IsTexture() ) + { + pContextData->m_bVertexShaderFastPath = false; + } + if (bHasBlendMaskTransform) + { + pContextData->m_SemiStaticCmdsOut.SetVertexShaderTextureTransform( + VERTEX_SHADER_SHADER_SPECIFIC_CONST_10, info.m_nBlendMaskTransform ); + } + + if ( ! pContextData->m_bVertexShaderFastPath ) + { + bool bSeamlessMapping = ( ( info.m_nSeamlessMappingScale != -1 ) && + ( params[info.m_nSeamlessMappingScale]->GetFloatValue() != 0.0 ) ); + bool hasEnvmapMask = params[info.m_nEnvmapMask]->IsTexture(); + if (!bSeamlessMapping ) + pContextData->m_SemiStaticCmdsOut.SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, info.m_nBaseTextureTransform ); + // If we have a detail texture, then the bump texcoords are the same as the base texcoords. + if( hasBump && !hasDetailTexture ) + { + pContextData->m_SemiStaticCmdsOut.SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_2, info.m_nBumpTransform ); + } + if( hasEnvmapMask ) + { + pContextData->m_SemiStaticCmdsOut.SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_4, info.m_nEnvmapMaskTransform ); + } + else if ( hasBump2 ) + { + pContextData->m_SemiStaticCmdsOut.SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_4, info.m_nBumpTransform2 ); + } + } + pContextData->m_SemiStaticCmdsOut.SetEnvMapTintPixelShaderDynamicState( 0, info.m_nEnvmapTint ); + // set up shader modulation color + float color[4] = { 1.0, 1.0, 1.0, 1.0 }; + pShader->ComputeModulationColor( color ); + float flLScale = pShaderAPI->GetLightMapScaleFactor(); + color[0] *= flLScale; + color[1] *= flLScale; + color[2] *= flLScale; + + pContextData->m_SemiStaticCmdsOut.SetVertexShaderConstant( VERTEX_SHADER_MODULATION_COLOR, color ); + + color[3] *= ( IS_PARAM_DEFINED( info.m_nAlpha2 ) && params[ info.m_nAlpha2 ]->GetFloatValue() > 0.0f ) ? params[ info.m_nAlpha2 ]->GetFloatValue() : 1.0f; + pContextData->m_SemiStaticCmdsOut.SetPixelShaderConstant( 12, color ); + + if ( hasDetailTexture ) + { + float detailTintAndBlend[4] = {1, 1, 1, 1}; + + if ( info.m_nDetailTint != -1 ) + { + params[info.m_nDetailTint]->GetVecValue( detailTintAndBlend, 3 ); + } + + detailTintAndBlend[3] = fDetailBlendFactor; + pContextData->m_SemiStaticCmdsOut.SetPixelShaderConstant( 8, detailTintAndBlend ); + } + + float envmapTintVal[4]; + float selfIllumTintVal[4]; + params[info.m_nEnvmapTint]->GetVecValue( envmapTintVal, 3 ); + params[info.m_nSelfIllumTint]->GetVecValue( selfIllumTintVal, 3 ); + float envmapContrast = params[info.m_nEnvmapContrast]->GetFloatValue(); + float envmapSaturation = params[info.m_nEnvmapSaturation]->GetFloatValue(); + float fresnelReflection = params[info.m_nFresnelReflection]->GetFloatValue(); + bool hasEnvmap = params[info.m_nEnvmap]->IsTexture(); + + pContextData->m_bPixelShaderFastPath = true; + bool bUsingContrast = hasEnvmap && ( (envmapContrast != 0.0f) && (envmapContrast != 1.0f) ) && (envmapSaturation != 1.0f); + bool bUsingFresnel = hasEnvmap && (fresnelReflection != 1.0f); + bool bUsingSelfIllumTint = IS_FLAG_SET(MATERIAL_VAR_SELFILLUM) && (selfIllumTintVal[0] != 1.0f || selfIllumTintVal[1] != 1.0f || selfIllumTintVal[2] != 1.0f); + if ( bUsingContrast || bUsingFresnel || bUsingSelfIllumTint || !g_pConfig->bShowSpecular ) + { + pContextData->m_bPixelShaderFastPath = false; + } + if( !pContextData->m_bPixelShaderFastPath ) + { + pContextData->m_SemiStaticCmdsOut.SetPixelShaderConstants( 2, 3 ); + pContextData->m_SemiStaticCmdsOut.OutputConstantData( params[info.m_nEnvmapContrast]->GetVecValue() ); + pContextData->m_SemiStaticCmdsOut.OutputConstantData( params[info.m_nEnvmapSaturation]->GetVecValue() ); + float flFresnel = params[info.m_nFresnelReflection]->GetFloatValue(); + // [ 0, 0, 1-R(0), R(0) ] + pContextData->m_SemiStaticCmdsOut.OutputConstantData4( 0., 0., 1.0 - flFresnel, flFresnel ); + + pContextData->m_SemiStaticCmdsOut.SetPixelShaderConstant( 7, params[info.m_nSelfIllumTint]->GetVecValue() ); + } + else + { + if ( bHasOutline ) + { + float flOutlineParms[8] = { GetFloatParam( info.m_nOutlineStart0, params ), + GetFloatParam( info.m_nOutlineStart1, params ), + GetFloatParam( info.m_nOutlineEnd0, params ), + GetFloatParam( info.m_nOutlineEnd1, params ), + 0,0,0, + GetFloatParam( info.m_nOutlineAlpha, params ) }; + if ( info.m_nOutlineColor != -1 ) + { + params[info.m_nOutlineColor]->GetVecValue( flOutlineParms + 4, 3 ); + } + pContextData->m_SemiStaticCmdsOut.SetPixelShaderConstant( 2, flOutlineParms, 2 ); + } + + if ( bHasSoftEdges ) + { + pContextData->m_SemiStaticCmdsOut.SetPixelShaderConstant4( + 4, GetFloatParam( info.m_nEdgeSoftnessStart, params ), + GetFloatParam( info.m_nEdgeSoftnessEnd, params ), + 0,0 ); + } + } + // texture binds + if( hasBaseTexture ) + { + pContextData->m_SemiStaticCmdsOut.BindTexture( pShader, SHADER_SAMPLER0, info.m_nBaseTexture, info.m_nBaseTextureFrame ); + } + // handle mat_fullbright 2 + bool bLightingOnly = mat_fullbright.GetInt() == 2 && !IS_FLAG_SET( MATERIAL_VAR_NO_DEBUG_OVERRIDE ); + if( bLightingOnly ) + { + // BASE TEXTURE + if( hasSelfIllum ) + { + pContextData->m_SemiStaticCmdsOut.BindStandardTexture( SHADER_SAMPLER0, TEXTURE_GREY_ALPHA_ZERO ); + } + else + { + pContextData->m_SemiStaticCmdsOut.BindStandardTexture( SHADER_SAMPLER0, TEXTURE_GREY ); + } + + // BASE TEXTURE 2 + if( hasBaseTexture2 ) + { + pContextData->m_SemiStaticCmdsOut.BindStandardTexture( SHADER_SAMPLER7, TEXTURE_GREY ); + } + + // DETAIL TEXTURE + if( hasDetailTexture ) + { + pContextData->m_SemiStaticCmdsOut.BindStandardTexture( SHADER_SAMPLER12, TEXTURE_GREY ); + } + + // disable color modulation + float color[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; + pContextData->m_SemiStaticCmdsOut.SetVertexShaderConstant( VERTEX_SHADER_MODULATION_COLOR, color ); + + // turn off environment mapping + envmapTintVal[0] = 0.0f; + envmapTintVal[1] = 0.0f; + envmapTintVal[2] = 0.0f; + } + + // always set the transform for detail textures since I'm assuming that you'll + // always have a detailscale. + if( hasDetailTexture ) + { + pContextData->m_SemiStaticCmdsOut.SetVertexShaderTextureScaledTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_2, info.m_nBaseTextureTransform, info.m_nDetailScale ); + } + + if( hasBaseTexture2 ) + { + pContextData->m_SemiStaticCmdsOut.BindTexture( pShader, SHADER_SAMPLER7, info.m_nBaseTexture2, info.m_nBaseTexture2Frame ); + } + if( hasDetailTexture ) + { + pContextData->m_SemiStaticCmdsOut.BindTexture( pShader, SHADER_SAMPLER12, info.m_nDetail, info.m_nDetailFrame ); + } + + if( hasBump || hasNormalMapAlphaEnvmapMask ) + { + if( !g_pConfig->m_bFastNoBump ) + { + pContextData->m_SemiStaticCmdsOut.BindTexture( pShader, SHADER_SAMPLER4, info.m_nBumpmap, info.m_nBumpFrame ); + } + else + { + pContextData->m_SemiStaticCmdsOut.BindStandardTexture( SHADER_SAMPLER4, TEXTURE_NORMALMAP_FLAT ); + } + } + if( hasBump2 ) + { + if( !g_pConfig->m_bFastNoBump ) + { + pContextData->m_SemiStaticCmdsOut.BindTexture( pShader, SHADER_SAMPLER5, info.m_nBumpmap2, info.m_nBumpFrame2 ); + } + else + { + pContextData->m_SemiStaticCmdsOut.BindStandardTexture( SHADER_SAMPLER5, TEXTURE_NORMALMAP_FLAT ); + } + } + if( hasBumpMask ) + { + if( !g_pConfig->m_bFastNoBump ) + { + pContextData->m_SemiStaticCmdsOut.BindTexture( pShader, SHADER_SAMPLER8, info.m_nBumpMask, -1 ); + } + else + { + pContextData->m_SemiStaticCmdsOut.BindStandardTexture( SHADER_SAMPLER8, TEXTURE_NORMALMAP_FLAT ); + } + } + + if( hasEnvmapMask ) + { + pContextData->m_SemiStaticCmdsOut.BindTexture( pShader, SHADER_SAMPLER5, info.m_nEnvmapMask, info.m_nEnvmapMaskFrame ); + } + + if ( hasLightWarpTexture ) + { + pContextData->m_SemiStaticCmdsOut.BindTexture( pShader, SHADER_SAMPLER6, info.m_nLightWarpTexture, -1 ); + } + + if ( bHasBlendModulateTexture ) + { + pContextData->m_SemiStaticCmdsOut.BindTexture( pShader, SHADER_SAMPLER3, info.m_nBlendModulateTexture, -1 ); + } + + pContextData->m_SemiStaticCmdsOut.End(); + } + } + DYNAMIC_STATE + { + CCommandBufferBuilder< CFixedCommandStorageBuffer< 1000 > > DynamicCmdsOut; + DynamicCmdsOut.Call( pContextData->m_pStaticCmds ); + DynamicCmdsOut.Call( pContextData->m_SemiStaticCmdsOut.Base() ); + + bool hasEnvmap = params[info.m_nEnvmap]->IsTexture(); + + if( hasEnvmap ) + { + DynamicCmdsOut.BindTexture( pShader, SHADER_SAMPLER2, info.m_nEnvmap, info.m_nEnvmapFrame ); + } + int nFixedLightingMode = pShaderAPI->GetIntRenderingParameter( INT_RENDERPARM_ENABLE_FIXED_LIGHTING ); + + bool bVertexShaderFastPath = pContextData->m_bVertexShaderFastPath; + + if( nFixedLightingMode != 0 ) + { + if ( pContextData->m_bPixelShaderForceFastPathBecauseOutline ) + nFixedLightingMode = 0; + else + bVertexShaderFastPath = false; + } + + MaterialFogMode_t fogType = pShaderAPI->GetSceneFogMode(); + DECLARE_DYNAMIC_VERTEX_SHADER( lightmappedgeneric_vs20 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( DOWATERFOG, fogType == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( FASTPATH, bVertexShaderFastPath ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( + LIGHTING_PREVIEW, + (nFixedLightingMode)?1:0 + ); + SET_DYNAMIC_VERTEX_SHADER_CMD( DynamicCmdsOut, lightmappedgeneric_vs20 ); + + bool bPixelShaderFastPath = pContextData->m_bPixelShaderFastPath; + if( nFixedLightingMode !=0 ) + { + bPixelShaderFastPath = false; + } + bool bWriteDepthToAlpha; + bool bWriteWaterFogToAlpha; + if( pContextData->m_bFullyOpaque ) + { + bWriteDepthToAlpha = pShaderAPI->ShouldWriteDepthToDestAlpha(); + bWriteWaterFogToAlpha = (fogType == MATERIAL_FOG_LINEAR_BELOW_FOG_Z); + AssertMsg( !(bWriteDepthToAlpha && bWriteWaterFogToAlpha), "Can't write two values to alpha at the same time." ); + } + else + { + //can't write a special value to dest alpha if we're actually using as-intended alpha + bWriteDepthToAlpha = false; + bWriteWaterFogToAlpha = false; + } + + float envmapContrast = params[info.m_nEnvmapContrast]->GetFloatValue(); + if ( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_DYNAMIC_PIXEL_SHADER( lightmappedgeneric_ps20b ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( FASTPATH, bPixelShaderFastPath || pContextData->m_bPixelShaderForceFastPathBecauseOutline ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( FASTPATHENVMAPCONTRAST, bPixelShaderFastPath && envmapContrast == 1.0f ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + + // Don't write fog to alpha if we're using translucency + SET_DYNAMIC_PIXEL_SHADER_COMBO( WRITE_DEPTH_TO_DESTALPHA, bWriteDepthToAlpha ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( WRITEWATERFOGTODESTALPHA, bWriteWaterFogToAlpha ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( LIGHTING_PREVIEW, nFixedLightingMode ); + + SET_DYNAMIC_PIXEL_SHADER_CMD( DynamicCmdsOut, lightmappedgeneric_ps20b ); + } + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( lightmappedgeneric_ps20 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( FASTPATH, bPixelShaderFastPath ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( FASTPATHENVMAPCONTRAST, bPixelShaderFastPath && envmapContrast == 1.0f ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + + // Don't write fog to alpha if we're using translucency + SET_DYNAMIC_PIXEL_SHADER_COMBO( WRITEWATERFOGTODESTALPHA, bWriteWaterFogToAlpha ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( LIGHTING_PREVIEW, nFixedLightingMode ); + + SET_DYNAMIC_PIXEL_SHADER_CMD( DynamicCmdsOut, lightmappedgeneric_ps20 ); + } + + if( hasFlashlight && IsX360() ) + { + VMatrix worldToTexture; + ITexture *pFlashlightDepthTexture; + FlashlightState_t flashlightState = pShaderAPI->GetFlashlightStateEx( worldToTexture, &pFlashlightDepthTexture ); + + DynamicCmdsOut.SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_6, worldToTexture.Base(), 4 ); + + SetFlashLightColorFromState( flashlightState, pShaderAPI ); + + float atten[4], pos[4]; + atten[0] = flashlightState.m_fConstantAtten; // Set the flashlight attenuation factors + atten[1] = flashlightState.m_fLinearAtten; + atten[2] = flashlightState.m_fQuadraticAtten; + atten[3] = flashlightState.m_FarZ; + DynamicCmdsOut.SetPixelShaderConstant( 13, atten, 1 ); + + pos[0] = flashlightState.m_vecLightOrigin[0]; // Set the flashlight origin + pos[1] = flashlightState.m_vecLightOrigin[1]; + pos[2] = flashlightState.m_vecLightOrigin[2]; + DynamicCmdsOut.SetPixelShaderConstant( 14, pos, 1 ); + + pShader->BindTexture( SHADER_SAMPLER13, flashlightState.m_pSpotlightTexture, flashlightState.m_nSpotlightTextureFrame ); + + if( pFlashlightDepthTexture && g_pConfig->ShadowDepthTexture() && flashlightState.m_bEnableShadows ) + { + pShader->BindTexture( SHADER_SAMPLER14, pFlashlightDepthTexture, 0 ); + DynamicCmdsOut.BindStandardTexture( SHADER_SAMPLER15, TEXTURE_SHADOW_NOISE_2D ); + + // Tweaks associated with a given flashlight + float tweaks[4]; + tweaks[0] = ShadowFilterFromState( flashlightState ); + tweaks[1] = ShadowAttenFromState( flashlightState ); + pShader->HashShadow2DJitter( flashlightState.m_flShadowJitterSeed, &tweaks[2], &tweaks[3] ); + DynamicCmdsOut.SetPixelShaderConstant( 19, tweaks, 1 ); + + // Dimensions of screen, used for screen-space noise map sampling + float vScreenScale[4] = {1280.0f / 32.0f, 720.0f / 32.0f, 0, 0}; + int nWidth, nHeight; + pShaderAPI->GetBackBufferDimensions( nWidth, nHeight ); + vScreenScale[0] = (float) nWidth / 32.0f; + vScreenScale[1] = (float) nHeight / 32.0f; + DynamicCmdsOut.SetPixelShaderConstant( 31, vScreenScale, 1 ); + } + } + + DynamicCmdsOut.End(); + pShaderAPI->ExecuteCommandBuffer( DynamicCmdsOut.Base() ); + } + pShader->Draw(); + + if( IsPC() && (IS_FLAG_SET( MATERIAL_VAR_ALPHATEST ) != 0) && pContextData->m_bFullyOpaqueWithoutAlphaTest ) + { + //Alpha testing makes it so we can't write to dest alpha + //Writing to depth makes it so later polygons can't write to dest alpha either + //This leads to situations with garbage in dest alpha. + + //Fix it now by converting depth to dest alpha for any pixels that just wrote. + pShader->DrawEqualDepthToDestAlpha(); + } +} + +void DrawLightmappedGeneric_DX9(CBaseVSShader *pShader, IMaterialVar** params, + IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow, + LightmappedGeneric_DX9_Vars_t &info, + CBasePerMaterialContextData **pContextDataPtr ) +{ + bool hasFlashlight = pShader->UsingFlashlight( params ); + if ( !IsX360() && !r_flashlight_version2.GetInt() ) + { + DrawLightmappedGeneric_DX9_Internal( pShader, params, hasFlashlight, pShaderAPI, pShaderShadow, info, pContextDataPtr ); + return; + } + + DrawLightmappedGeneric_DX9_Internal( pShader, params, hasFlashlight, pShaderAPI, pShaderShadow, info, pContextDataPtr ); +} diff --git a/materialsystem/stdshaders/lightmappedgeneric_dx9_helper.h b/materialsystem/stdshaders/lightmappedgeneric_dx9_helper.h new file mode 100644 index 0000000..00375b9 --- /dev/null +++ b/materialsystem/stdshaders/lightmappedgeneric_dx9_helper.h @@ -0,0 +1,99 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//============================================================================= + +#ifndef LIGHTMAPPEDGENERIC_DX9_HELPER_H +#define LIGHTMAPPEDGENERIC_DX9_HELPER_H + +#include +#include "BaseVSShader.h" + + +//----------------------------------------------------------------------------- +// Forward declarations +//----------------------------------------------------------------------------- +class CBaseVSShader; +class IMaterialVar; +class IShaderDynamicAPI; +class IShaderShadow; + + +//----------------------------------------------------------------------------- +// Init params/ init/ draw methods +//----------------------------------------------------------------------------- +struct LightmappedGeneric_DX9_Vars_t +{ + LightmappedGeneric_DX9_Vars_t() { memset( this, 0xFF, sizeof(LightmappedGeneric_DX9_Vars_t) ); } + + int m_nBaseTexture; + int m_nBaseTextureFrame; + int m_nBaseTextureTransform; + int m_nAlbedo; + int m_nSelfIllumTint; + + int m_nAlpha2; // Hack for DoD srgb blend issues on overlays + + int m_nDetail; + int m_nDetailFrame; + int m_nDetailScale; + int m_nDetailTextureCombineMode; + int m_nDetailTextureBlendFactor; + int m_nDetailTint; + + int m_nEnvmap; + int m_nEnvmapFrame; + int m_nEnvmapMask; + int m_nEnvmapMaskFrame; + int m_nEnvmapMaskTransform; + int m_nEnvmapTint; + int m_nBumpmap; + int m_nBumpFrame; + int m_nBumpTransform; + int m_nEnvmapContrast; + int m_nEnvmapSaturation; + int m_nFresnelReflection; + int m_nNoDiffuseBumpLighting; + int m_nBumpmap2; + int m_nBumpFrame2; + int m_nBumpTransform2; + int m_nBumpMask; + int m_nBaseTexture2; + int m_nBaseTexture2Frame; + int m_nBaseTextureNoEnvmap; + int m_nBaseTexture2NoEnvmap; + int m_nDetailAlphaMaskBaseTexture; + int m_nFlashlightTexture; + int m_nFlashlightTextureFrame; + int m_nLightWarpTexture; + int m_nBlendModulateTexture; + int m_nMaskedBlending; + int m_nBlendMaskTransform; + int m_nSelfShadowedBumpFlag; + int m_nSeamlessMappingScale; + int m_nAlphaTestReference; + + int m_nSoftEdges; + int m_nEdgeSoftnessStart; + int m_nEdgeSoftnessEnd; + + int m_nOutline; + int m_nOutlineColor; + int m_nOutlineAlpha; + int m_nOutlineStart0; + int m_nOutlineStart1; + int m_nOutlineEnd0; + int m_nOutlineEnd1; + +}; + +void InitParamsLightmappedGeneric_DX9( CBaseVSShader *pShader, IMaterialVar** params, const char *pMaterialName, LightmappedGeneric_DX9_Vars_t &info ); +void InitLightmappedGeneric_DX9( CBaseVSShader *pShader, IMaterialVar** params, LightmappedGeneric_DX9_Vars_t &info ); +void DrawLightmappedGeneric_DX9( CBaseVSShader *pShader, IMaterialVar** params, + IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow, + LightmappedGeneric_DX9_Vars_t &info, CBasePerMaterialContextData **pContextDataPtr ); + + +#endif // LIGHTMAPPEDGENERIC_DX9_HELPER_H diff --git a/materialsystem/stdshaders/lightmappedgeneric_envmap.psh b/materialsystem/stdshaders/lightmappedgeneric_envmap.psh new file mode 100644 index 0000000..49217fe --- /dev/null +++ b/materialsystem/stdshaders/lightmappedgeneric_envmap.psh @@ -0,0 +1,20 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; Draw a texture . . woo hoo! +; t0 - texture +; +; The texture coordinates need to be defined as follows: +; tc0 - texcoords +; c1 - self-illum tint +; c2 - envmap tint +;------------------------------------------------------------------------------ + +tex t0 +tex t1 +tex t2 + +mul r0, t0, v0 ; base times vertex color (with alpha) +mad r0.rgb, t2, c2, r0 ; + envmap * envmaptint (color only) +mul r0.rgb, t1, r0 ; fold in lightmap (color only) +mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2) diff --git a/materialsystem/stdshaders/lightmappedgeneric_flashlight_vs11.fxc b/materialsystem/stdshaders/lightmappedgeneric_flashlight_vs11.fxc new file mode 100644 index 0000000..3a0d059 --- /dev/null +++ b/materialsystem/stdshaders/lightmappedgeneric_flashlight_vs11.fxc @@ -0,0 +1,122 @@ +//====== Copyright © 1996-2007, Valve Corporation, All rights reserved. ======= +// +// Purpose: +// +//============================================================================= + +// STATIC: "NORMALMAP" "0..1" +// STATIC: "WORLDVERTEXTRANSITION" "0..1" +// STATIC: "VERTEXCOLOR" "0..1" +// DYNAMIC: "DOWATERFOG" "0..1" + +#include "common_vs_fxc.h" + +const float3 g_FlashlightPos : register( SHADER_SPECIFIC_CONST_0 ); +const float4x4 g_FlashlightWorldToTexture : register( SHADER_SPECIFIC_CONST_1 ); +const float4 g_FlashlightAttenuationFactors : register( SHADER_SPECIFIC_CONST_5 ); + +const float4 cBaseTexCoordTransform[2] : register( SHADER_SPECIFIC_CONST_6 ); +const float4 cNormalMapTexCoordTransform[2] : register( SHADER_SPECIFIC_CONST_8 ); + +static const int g_FogType = DOWATERFOG; + +struct VS_INPUT +{ + // If this is float4, and the input is float3, the w component default to one. + float4 vPos : POSITION; + float3 vNormal : NORMAL; + float2 vBaseTexCoord : TEXCOORD0; +#if NORMALMAP + float3 vTangentS : TANGENT; + float3 vTangentT : BINORMAL; +#endif + float4 vColor : COLOR0; +}; + +struct VS_OUTPUT +{ + float4 projPos : POSITION; +#if !defined( _X360 ) + float fog : FOG; +#endif + float4 spotTexCoord : TEXCOORD0; + float2 baseTexCoord : TEXCOORD1; +#if NORMALMAP + float3 tangentPosToLightVector : TEXCOORD2; + float2 normalMapTexCoord : TEXCOORD3; +#else + float3 worldPosToLightVector : TEXCOORD2; + float3 normal : TEXCOORD3; +#endif + float4 vertAtten : COLOR0; +}; + +float RemapValClamped( float val, float A, float B ) +{ + float cVal = (val - A) / (B - A); + cVal = saturate( cVal ); + return cVal; +} + +VS_OUTPUT main( const VS_INPUT v ) +{ + VS_OUTPUT o; + + float4 projPos; + float3 worldPos; + float3 worldNormal; + float3 eyeVector; + + projPos = mul( v.vPos, cModelViewProj ); + o.projPos = projPos; + + worldPos = mul( v.vPos, cModel[0] ); + worldNormal = mul( v.vNormal, ( float3x3 )cModel[0] ); + +#if NORMALMAP + float3 worldTangentS = mul( v.vTangentS, cModel[0] ); + float3 worldTangentT = mul( v.vTangentT, cModel[0] ); +#endif + +#if !defined( _X360 ) + o.fog = CalcFog( worldPos, projPos, g_FogType ); +#endif + + o.baseTexCoord.x = dot( v.vBaseTexCoord, cBaseTexCoordTransform[0] ) + cBaseTexCoordTransform[0].w; + o.baseTexCoord.y = dot( v.vBaseTexCoord, cBaseTexCoordTransform[1] ) + cBaseTexCoordTransform[1].w; + + float4 spotTexCoord = mul( float4( worldPos, 1.0f ), g_FlashlightWorldToTexture ); + o.spotTexCoord = spotTexCoord.xyzw; + + float3 worldPosToLightVector = g_FlashlightPos - worldPos; +#if NORMALMAP + o.normalMapTexCoord.x = dot( v.vBaseTexCoord, cNormalMapTexCoordTransform[0] ) + cNormalMapTexCoordTransform[0].w; + o.normalMapTexCoord.y = dot( v.vBaseTexCoord, cNormalMapTexCoordTransform[1] ) + cNormalMapTexCoordTransform[1].w; + + o.tangentPosToLightVector.x = dot( worldPosToLightVector, worldTangentS ); + o.tangentPosToLightVector.y = dot( worldPosToLightVector, worldTangentT ); + o.tangentPosToLightVector.z = dot( worldPosToLightVector, worldNormal ); +#else + o.worldPosToLightVector = worldPosToLightVector; + o.normal = worldNormal; +#endif + + float3 delta = worldPosToLightVector; + float distSquared = dot( delta, delta ); + float dist = sqrt( distSquared ); + float farZ = g_FlashlightAttenuationFactors.w; + float endFalloffFactor = RemapValClamped( dist, farZ, 0.6 * farZ ); + o.vertAtten.xyz = saturate( endFalloffFactor * dot( g_FlashlightAttenuationFactors, float3( 1.0f, 1.0f/dist, 1.0f/distSquared ) ) ); + +#if WORLDVERTEXTRANSITION + o.vertAtten.w = 1 - v.vColor.w; +#else +#if VERTEXCOLOR + o.vertAtten.w = v.vColor.w; +#else + o.vertAtten.w = 1.0f; +#endif +#endif + + return o; +} diff --git a/materialsystem/stdshaders/lightmappedgeneric_flashlight_vs20.fxc b/materialsystem/stdshaders/lightmappedgeneric_flashlight_vs20.fxc new file mode 100644 index 0000000..7d23bb9 --- /dev/null +++ b/materialsystem/stdshaders/lightmappedgeneric_flashlight_vs20.fxc @@ -0,0 +1,184 @@ +//====== Copyright © 1996-2004, Valve Corporation, All rights reserved. ======= +// +// Purpose: +// +//============================================================================= + +// STATIC: "NORMALMAP" "0..1" +// STATIC: "WORLDVERTEXTRANSITION" "0..1" +// STATIC: "SEAMLESS" "0..1" +// STATIC: "DETAIL" "0..1" +// DYNAMIC: "DOWATERFOG" "0..1" + +#include "common_vs_fxc.h" + +const float3 g_FlashlightPos : register( SHADER_SPECIFIC_CONST_0 ); +const float4x4 g_FlashlightWorldToTexture : register( SHADER_SPECIFIC_CONST_1 ); +const float4 g_FlashlightAttenuationFactors : register( SHADER_SPECIFIC_CONST_5 ); + +#if SEAMLESS +const float4 SeamlessScale : register( SHADER_SPECIFIC_CONST_6 ); +#define SEAMLESS_SCALE (SeamlessScale.x) +#endif +const float4 cBaseTexCoordTransform[2] : register( SHADER_SPECIFIC_CONST_6 ); +const float4 cNormalMapOrDetailTexCoordTransform[2] : register( SHADER_SPECIFIC_CONST_8 ); + +static const int g_FogType = DOWATERFOG; + +struct VS_INPUT +{ + float3 vPos : POSITION; //This HAS to match lightmappedgeneric_vs20.fxc's position input. Otherwise depth fighting errors occur on the 360 + float4 vNormal : NORMAL; + float2 vBaseTexCoord : TEXCOORD0; +#if WORLDVERTEXTRANSITION + float2 vLightmapTexCoord : TEXCOORD1; + float4 vColor : COLOR0; +#endif +#if NORMALMAP + float3 vTangentS : TANGENT; + float3 vTangentT : BINORMAL; +#endif +}; + +struct VS_OUTPUT +{ + float4 projPos : POSITION; +#if !defined( _X360 ) + float fog : FOG; +#endif + + float4 spotTexCoord : TEXCOORD0; + +#if SEAMLESS + float3 SeamlessTexCoord : TEXCOORD1; +#else + float2 baseTexCoord : TEXCOORD1; +#endif + +#if NORMALMAP + float3 tangentPosToLightVector : TEXCOORD2; + float2 normalMapTexCoord : TEXCOORD3; +#else + float3 worldPosToLightVector : TEXCOORD2; + float3 normal : TEXCOORD3; +#endif + + float2 detailCoords : TEXCOORD4; + float4 worldPos_worldTransition : TEXCOORD5; + float3 vProjPos : TEXCOORD6; + float4 fogFactorW : TEXCOORD7; +}; + +float RemapValClamped( float val, float A, float B, float C, float D) +{ + float cVal = (val - A) / (B - A); + cVal = saturate( cVal ); + + return C + (D - C) * cVal; +} + + +VS_OUTPUT main( const VS_INPUT v ) +{ + VS_OUTPUT o; + + float3 vObjNormal; + DecompressVertex_Normal( v.vNormal, vObjNormal ); + + float4 projPos; + float3 worldPos; + float3 worldNormal; + float3 eyeVector; + + //Projection math HAS to match lightmappedgeneric_vs20.fxc's math exactly. Otherwise depth fighting errors occur on the 360 + projPos = mul( float4( v.vPos, 1 ), cModelViewProj ); + o.projPos = projPos; + o.vProjPos.xyz = projPos.xyw; + + worldPos = mul( float4( v.vPos, 1 ), cModel[0] ); + worldNormal = mul( vObjNormal, ( float3x3 )cModel[0] ); + + o.worldPos_worldTransition = float4( worldPos.xyz, 1.0f ); + + o.fogFactorW = CalcFog( worldPos, projPos, g_FogType ); +#if !defined( _X360 ) + o.fog = o.fogFactorW.w; +#endif + +#if NORMALMAP + float3 worldTangentS = mul( v.vTangentS, cModel[0] ); + float3 worldTangentT = mul( v.vTangentT, cModel[0] ); +#endif +#if SEAMLESS + float3 vNormal=normalize( worldNormal ); + o.fogFactorW.xyz = vNormal * vNormal; // sums to 1. + o.SeamlessTexCoord = SEAMLESS_SCALE*worldPos; + + // Generate new tangent and binormal with seamless projection + #if NORMALMAP + // Brute-force for prototype - This must match the projection in the pixel shader! + //float3 vVecX = { 1.0f, 0.0f, 0.0f }; + //float3 vVecY = { 0.0f, 1.0f, 0.0f }; + //float3 vVecZ = { 0.0f, 0.0f, 1.0f }; + //worldTangentS.xyz = normalize( ( o.fogFactorW.x * vVecZ.xyz ) + ( o.fogFactorW.y * vVecX.xyz ) + ( o.fogFactorW.z * vVecX.xyz ) ); + //worldTangentT.xyz = normalize( ( o.fogFactorW.x * vVecY.xyz ) + ( o.fogFactorW.y * vVecZ.xyz ) + ( o.fogFactorW.z * vVecY.xyz ) ); + + // Optimized version - This must match the projection in the pixel shader! + worldTangentS.xyz = normalize( float3( o.fogFactorW.y + o.fogFactorW.z, 0.0f, o.fogFactorW.x ) ); + worldTangentT.xyz = normalize( float3( 0.0f, o.fogFactorW.x + o.fogFactorW.z, o.fogFactorW.y ) ); + #endif +#else +#if (SEAMLESS == 0 ) + o.baseTexCoord.x = dot( v.vBaseTexCoord, cBaseTexCoordTransform[0] ) + cBaseTexCoordTransform[0].w; + o.baseTexCoord.y = dot( v.vBaseTexCoord, cBaseTexCoordTransform[1] ) + cBaseTexCoordTransform[1].w; +#endif +#endif + + float4 spotTexCoord = mul( float4( worldPos, 1.0f ), g_FlashlightWorldToTexture ); + o.spotTexCoord = spotTexCoord.xyzw; + + float3 worldPosToLightVector = g_FlashlightPos - worldPos; +#if NORMALMAP + +#if (DETAIL == 0) + o.normalMapTexCoord.x = dot( v.vBaseTexCoord, cNormalMapOrDetailTexCoordTransform[0] ) + cNormalMapOrDetailTexCoordTransform[0].w; + o.normalMapTexCoord.y = dot( v.vBaseTexCoord, cNormalMapOrDetailTexCoordTransform[1] ) + cNormalMapOrDetailTexCoordTransform[1].w; +#else + +#if SEAMLESS + o.normalMapTexCoord = v.vBaseTexCoord; +#else + o.normalMapTexCoord = o.baseTexCoord; +#endif + +#endif + + o.tangentPosToLightVector.x = dot( worldPosToLightVector, worldTangentS ); + o.tangentPosToLightVector.y = dot( worldPosToLightVector, worldTangentT ); + o.tangentPosToLightVector.z = dot( worldPosToLightVector, worldNormal ); +#else + o.worldPosToLightVector = worldPosToLightVector; + o.normal = worldNormal; +#endif + +#if DETAIL + o.detailCoords.x = dot( v.vBaseTexCoord, cNormalMapOrDetailTexCoordTransform[0] ) + cNormalMapOrDetailTexCoordTransform[0].w; + o.detailCoords.y = dot( v.vBaseTexCoord, cNormalMapOrDetailTexCoordTransform[1] ) + cNormalMapOrDetailTexCoordTransform[1].w; +#else + o.detailCoords = float2(0,0); +#endif + + //float3 delta = worldPosToLightVector; + //float distSquared = dot( delta, delta ); + //float dist = sqrt( distSquared ); + //float farZ = g_FlashlightAttenuationFactors.w; + //float endFalloffFactor = RemapValClamped( dist, farZ, 0.6f * farZ, 0.0f, 1.0f ); + //o.projPos_atten.w = endFalloffFactor * dot( g_FlashlightAttenuationFactors, float3( 1.0f, 1.0f/dist, 1.0f/distSquared ) ); + //o.projPos_atten.w = saturate( o.projPos_atten.w ); + +#if WORLDVERTEXTRANSITION + o.worldPos_worldTransition.w = v.vColor.w; +#endif + + return o; +} diff --git a/materialsystem/stdshaders/lightmappedgeneric_inc.vsh b/materialsystem/stdshaders/lightmappedgeneric_inc.vsh new file mode 100644 index 0000000..a5d12a8 --- /dev/null +++ b/materialsystem/stdshaders/lightmappedgeneric_inc.vsh @@ -0,0 +1,110 @@ +#include "macros.vsh" + +;------------------------------------------------------------------------------ +; $SHADER_SPECIFIC_CONST_0-$SHADER_SPECIFIC_CONST_1 = Base texture transform +; $SHADER_SPECIFIC_CONST_2-$SHADER_SPECIFIC_CONST_3 = Mask texture transform +; $SHADER_SPECIFIC_CONST_4 = Modulation color +;------------------------------------------------------------------------------ + +sub LightmappedGeneric +{ + local( $detail ) = shift; + local( $envmap ) = shift; + local( $envmapcameraspace ) = shift; + local( $envmapsphere ) = shift; + local( $vertexcolor ) = shift; + + local( $worldPos, $worldNormal, $projPos, $reflectionVector ); + + &AllocateRegister( \$projPos ); + + dp4 $projPos.x, $vPos, $cModelViewProj0 + dp4 $projPos.y, $vPos, $cModelViewProj1 + dp4 $projPos.z, $vPos, $cModelViewProj2 + dp4 $projPos.w, $vPos, $cModelViewProj3 + mov oPos, $projPos + + &AllocateRegister( \$worldPos ); + + if( $DOWATERFOG == 1 ) + { + ; Get the worldpos z component only since that's all we need for height fog + dp4 $worldPos.z, $vPos, $cModel2 + } + &CalcFog( $worldPos, $projPos ); + &FreeRegister( \$projPos ); + + ;------------------------------------------------------------------------------ + ; Texture coordinates + ;------------------------------------------------------------------------------ + ; base texcoords + dp4 oT0.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_0 + dp4 oT0.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_1 + + ; lightmap texcoords + mov oT1, $vTexCoord1 + + if( $envmap ) + { + &AllocateRegister( \$worldNormal ); + + ; Transform the position + normal to world space + dp4 $worldPos.x, $vPos, $cModel0 + dp4 $worldPos.y, $vPos, $cModel1 + if( $DOWATERFOG ne 1 ) + { + dp4 $worldPos.z, $vPos, $cModel2 + } + + dp3 $worldNormal.x, $vNormal, $cModel0 + dp3 $worldNormal.y, $vNormal, $cModel1 + dp3 $worldNormal.z, $vNormal, $cModel2 + + if( $envmapcameraspace ) + { + &AllocateRegister( \$reflectionVector ); + &ComputeReflectionVector( $worldPos, $worldNormal, $reflectionVector ); + ; transform reflection vector into view space + dp3 oT2.x, $reflectionVector, $cViewModel0 + dp3 oT2.y, $reflectionVector, $cViewModel1 + dp3 oT2.z, $reflectionVector, $cViewModel2 + &FreeRegister( \$reflectionVector ); + } + elsif( $envmapsphere ) + { + &AllocateRegister( \$reflectionVector ); + &ComputeReflectionVector( $worldPos, $worldNormal, $reflectionVector ); + &ComputeSphereMapTexCoords( $reflectionVector, "oT2" ); + &FreeRegister( \$reflectionVector ); + } + else + { + &ComputeReflectionVector( $worldPos, $worldNormal, "oT2" ); + } + ; envmap mask + dp4 oT3.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_2 ; FIXME + dp4 oT3.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_3 ; FIXME + +# &FreeRegister( \$worldPos ); + &FreeRegister( \$worldNormal ); + } + + &FreeRegister( \$worldPos ); # garymcthack + + if( $detail ) + { + dp4 oT2.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_4 ; FIXME + dp4 oT2.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_5 ; FIXME + } + + if( $vertexcolor ) + { + ; Modulation color + mul oD0, $vColor, $cModulationColor + } + else + { + ; Modulation color + mov oD0, $cModulationColor + } +} diff --git a/materialsystem/stdshaders/lightmappedgeneric_lightingonly_overbright2_ps11.fxc b/materialsystem/stdshaders/lightmappedgeneric_lightingonly_overbright2_ps11.fxc new file mode 100644 index 0000000..1dbb8b2 --- /dev/null +++ b/materialsystem/stdshaders/lightmappedgeneric_lightingonly_overbright2_ps11.fxc @@ -0,0 +1,12 @@ +sampler TextureSampler : register( s1 ); + +struct PS_INPUT +{ + float4 vColor0 : COLOR0; + float2 vTexCoord1 : TEXCOORD1; +}; + +float4 main( PS_INPUT i ) : COLOR +{ + return tex2D( TextureSampler, i.vTexCoord1 ); +} \ No newline at end of file diff --git a/materialsystem/stdshaders/lightmappedgeneric_lightingonly_vs11.fxc b/materialsystem/stdshaders/lightmappedgeneric_lightingonly_vs11.fxc new file mode 100644 index 0000000..afee6c9 --- /dev/null +++ b/materialsystem/stdshaders/lightmappedgeneric_lightingonly_vs11.fxc @@ -0,0 +1,51 @@ +// DYNAMIC: "DOWATERFOG" "0..1" + +#include "common_vs_fxc.h" + +static const int g_FogType = DOWATERFOG; + +struct VS_INPUT +{ + float4 vPos : POSITION; + float2 vTexCoord1 : TEXCOORD1; +}; + +struct VS_OUTPUT +{ + float4 vProjPos : POSITION; + + float2 vTexCoord0 : TEXCOORD0; + float2 vTexCoord1 : TEXCOORD1; + + float4 vDiffuse : COLOR0; + + float4 fogFactorW : COLOR1; + +#if !defined( _X360 ) + float fog : FOG; +#endif +}; + + +VS_OUTPUT main( const VS_INPUT v ) +{ + VS_OUTPUT o = ( VS_OUTPUT )0; + + float3 worldPos; + worldPos = mul4x3( v.vPos, cModel[0] ); + + o.vProjPos = mul( float4( worldPos, 1 ), cViewProj ); + + o.fogFactorW = CalcFog( worldPos, o.vProjPos, g_FogType ); +#if !defined( _X360 ) + o.fog = o.fogFactorW; +#endif + + // YUCK! This is to make texcoords continuous for mat_softwaretl + o.vTexCoord0 = 0.0f; + o.vTexCoord1 = v.vTexCoord1; + + o.vDiffuse = 1.0f; + + return o; +} \ No newline at end of file diff --git a/materialsystem/stdshaders/lightmappedgeneric_maskedenvmap.psh b/materialsystem/stdshaders/lightmappedgeneric_maskedenvmap.psh new file mode 100644 index 0000000..980269a --- /dev/null +++ b/materialsystem/stdshaders/lightmappedgeneric_maskedenvmap.psh @@ -0,0 +1,22 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; Draw a texture . . woo hoo! +; t0 - texture +; +; The texture coordinates need to be defined as follows: +; tc0 - texcoords +; c1 - self-illum tint +; c2 - envmap tint +;------------------------------------------------------------------------------ + +tex t0 +tex t1 +tex t2 +tex t3 + +mul r0, t0, v0 ; base times vertex color (with alpha) +mul r1, t2, t3 ; envmap * envmapmask +mad r0.rgb, r1, c2, r0 ; + envmap * envmapmask * envmaptint (color only) +mul r0.rgb, t1, r0 ; fold in lighting (color only) +mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2) diff --git a/materialsystem/stdshaders/lightmappedgeneric_multiplybylightingbasealphamaskedselfillum.psh b/materialsystem/stdshaders/lightmappedgeneric_multiplybylightingbasealphamaskedselfillum.psh new file mode 100644 index 0000000..4790239 --- /dev/null +++ b/materialsystem/stdshaders/lightmappedgeneric_multiplybylightingbasealphamaskedselfillum.psh @@ -0,0 +1,24 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; Draw a texture . . woo hoo! +; t0 - texture +; +; The texture coordinates need to be defined as follows: +; tc0 - texcoords +;------------------------------------------------------------------------------ + +tex t0 +tex t1 + +; Blend between grey and lightmap color based on total alpha + +def c0 0.5f 0.5f 0.5f 1.0f + +mul_x2 r1.rgb, c0, t1 ; Apply overbright to lightmap ++ mul r1.a, t0, v0 ; base times vertex alpha +; GR - workaround for const/lerp issues +mul r0.rgb, c1, t0 ; Self illum * tint ++mul_sat r0.a, c1, t0 +lrp r1.rgb, t0.a, r1, r0 ; Blend between self-illum + lightmap +lrp r0, r1.a, r1, c0 ; interpolate between grey + color diff --git a/materialsystem/stdshaders/lightmappedgeneric_multiplybylightingbasenotexture.psh b/materialsystem/stdshaders/lightmappedgeneric_multiplybylightingbasenotexture.psh new file mode 100644 index 0000000..8cc6b4c --- /dev/null +++ b/materialsystem/stdshaders/lightmappedgeneric_multiplybylightingbasenotexture.psh @@ -0,0 +1,20 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; Draw a texture . . woo hoo! +; t0 - texture +; +; The texture coordinates need to be defined as follows: +; tc0 - texcoords +;------------------------------------------------------------------------------ + +tex t0 +tex t1 + +; Blend between grey and lightmap color based on total alpha + +def c2, 0.5f, 0.5f, 0.5f, 1.0f + +mul_x2 r1.rgb, c0, t1 ; Apply overbright to lightmap ++ mov r1.a, v0 ; vertex alpha +lrp r0, r1.a, r1, c2 ; interpolate between grey + color diff --git a/materialsystem/stdshaders/lightmappedgeneric_ps11.fxc b/materialsystem/stdshaders/lightmappedgeneric_ps11.fxc new file mode 100644 index 0000000..d5be9e5 --- /dev/null +++ b/materialsystem/stdshaders/lightmappedgeneric_ps11.fxc @@ -0,0 +1,122 @@ +// STATIC: "BASETEXTURE" "0..1" +// STATIC: "ENVMAP" "0..1" +// STATIC: "ENVMAPMASK" "0..1" +// STATIC: "SELFILLUM" "0..1" +// STATIC: "BASEALPHAENVMAPMASK" "0..1" + +// SKIP: !$ENVMAP && ( $BASEALPHAENVMAPMASK || $ENVMAPMASK ) +// SKIP: !$BASETEXTURE && $BASEALPHAENVMAPMASK +// SKIP: $BASEALPHAENVMAPMASK && $ENVMAPMASK +// SKIP: !$BASETEXTURE && $BASEALPHAENVMAPMASK +// SKIP: $SELFILLUM && $BASEALPHAENVMAPMASK +// SKIP: !$BASETEXTURE && $SELFILLUM + +const float3 g_OverbrightFactor : register( c0 ); +const float3 g_SelfIllumTint : register( c1 ); +const float3 g_EnvmapTint : register( c2 ); + +sampler BaseTextureSampler : register( s0 ); +sampler LightmapSampler : register( s1 ); +sampler EnvmapSampler : register( s2 ); +sampler EnvmapMaskSampler : register( s3 ); + +//sampler DetailSampler : register( s3 ); + +struct PS_INPUT +{ + float2 baseTexCoord : TEXCOORD0; + float2 lightmapTexCoord : TEXCOORD1; + float3 envmapTexCoord : TEXCOORD2; + float2 envmapMaskTexCoord : TEXCOORD3; + float4 vertexColor : COLOR0; +}; + +float4 main( PS_INPUT i ) : COLOR +{ + bool bBaseTexture = BASETEXTURE ? true : false; + bool bEnvmap = ENVMAP ? true : false; + bool bEnvmapMask = ENVMAPMASK ? true : false; + bool bSelfIllum = SELFILLUM ? true : false; + bool bBaseAlphaEnvmapMask = BASEALPHAENVMAPMASK ? true : false; + +#if 1 + float4 baseColor = float4( 1.0f, 1.0f, 1.0f, 1.0f ); + if( bBaseTexture ) + { + baseColor = tex2D( BaseTextureSampler, i.baseTexCoord ); + } + + float3 specularFactor = 1.0f; + + if( bEnvmapMask ) + { + specularFactor *= tex2D( EnvmapMaskSampler, i.envmapMaskTexCoord ).xyz; + } + if( bBaseAlphaEnvmapMask ) + { + specularFactor *= 1.0 - baseColor.a; // this blows! + } + + float3 diffuseLighting = tex2D( LightmapSampler, i.lightmapTexCoord ); + + float3 albedo = float3( 1.0f, 1.0f, 1.0f ); + float alpha = 1.0f; + if( bBaseTexture ) + { + albedo *= baseColor; + if( !bBaseAlphaEnvmapMask && !bSelfIllum ) + { + alpha *= baseColor.a; + } + } + + // The vertex color contains the modulation color + vertex color combined + albedo *= i.vertexColor; + alpha *= i.vertexColor.a; // not sure about this one + + float3 diffuseComponent = ( albedo * diffuseLighting * 2.0f ) * g_OverbrightFactor; + + if( bSelfIllum ) + { + float3 selfIllumComponent = g_SelfIllumTint * albedo; + diffuseComponent = lerp( diffuseComponent, selfIllumComponent, baseColor.a ); + } + + float3 specularLighting = float3( 0.0f, 0.0f, 0.0f ); + + if( bEnvmap ) + { + specularLighting = tex2D( EnvmapSampler, i.envmapTexCoord ); + specularLighting *= specularFactor; + specularLighting *= g_EnvmapTint; + } + + float3 result = diffuseComponent + specularLighting; + return float4( result, alpha ); +#endif + +#if 0 + float4 baseColor = float4( 1.0f, 1.0f, 1.0f, 1.0f ); + float3 diffuseLighting = tex2D( LightmapSampler, i.lightmapTexCoord ); + + float3 albedo = float3( 1.0f, 1.0f, 1.0f ); + float alpha = 1.0f; + albedo *= i.vertexColor; + alpha *= i.vertexColor.a; // not sure about this one + + float3 diffuseComponent = ( albedo * diffuseLighting * 2.0f ) * g_OverbrightFactor; + float3 result = diffuseComponent; + return float4( result, alpha ); +#endif + +#if 0 + float4 result; + + result.rgb = tex2D( LightmapSampler, i.lightmapTexCoord ).rgb * i.vertexColor.rgb; + result.a = i.vertexColor.a; + result.rgb = ( result.rgb * g_OverbrightFactor ) * 2.0f; + return result; +#endif +} + + diff --git a/materialsystem/stdshaders/lightmappedgeneric_ps2_3_x.h b/materialsystem/stdshaders/lightmappedgeneric_ps2_3_x.h new file mode 100644 index 0000000..585ea1f --- /dev/null +++ b/materialsystem/stdshaders/lightmappedgeneric_ps2_3_x.h @@ -0,0 +1,583 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// SKIP: $BUMPMAP2 && $WARPLIGHTING +// SKIP: $WARPLIGHTING && $DETAILTEXTURE +// SKIP: $ENVMAPMASK && $BUMPMAP +// SKIP: $NORMALMAPALPHAENVMAPMASK && $BASEALPHAENVMAPMASK +// SKIP: $NORMALMAPALPHAENVMAPMASK && $ENVMAPMASK +// SKIP: $BASEALPHAENVMAPMASK && $ENVMAPMASK +// SKIP: $BASEALPHAENVMAPMASK && $SELFILLUM +// SKIP: !$FASTPATH && $FASTPATHENVMAPCONTRAST +// SKIP: !$FASTPATH && $FASTPATHENVMAPTINT +// SKIP: !$BUMPMAP && $DIFFUSEBUMPMAP +// SKIP: !$BUMPMAP && $BUMPMAP2 +// SKIP: $ENVMAPMASK && $BUMPMAP2 +// SKIP: $BASETEXTURENOENVMAP && ( !$BASETEXTURE2 || !$CUBEMAP ) +// SKIP: $BASETEXTURE2NOENVMAP && ( !$BASETEXTURE2 || !$CUBEMAP ) +// SKIP: $BASEALPHAENVMAPMASK && $BUMPMAP +// SKIP: $PARALLAXMAP && $DETAILTEXTURE +// SKIP: $SEAMLESS && $RELIEF_MAPPING +// SKIP: $SEAMLESS && $DETAILTEXTURE +// SKIP: $SEAMLESS && $MASKEDBLENDING +// SKIP: $BUMPMASK && ( $SEAMLESS || $DETAILTEXTURE || $SELFILLUM || $BASETEXTURENOENVMAP || $BASETEXTURE2 ) +// SKIP: !$BUMPMAP && ($NORMAL_DECODE_MODE == 1) +// SKIP: !$BUMPMAP && ($NORMAL_DECODE_MODE == 2) +// SKIP: !$BUMPMAP && ($NORMALMASK_DECODE_MODE == 1) +// SKIP: !$BUMPMAP && ($NORMALMASK_DECODE_MODE == 2) +// NOSKIP: $FANCY_BLENDING && (!$FASTPATH) + +// 360 compiler craps out on some combo in this family. Content doesn't use blendmode 10 anyway +// SKIP: $FASTPATH && $PIXELFOGTYPE && $BASETEXTURE2 && $DETAILTEXTURE && $CUBEMAP && ($DETAIL_BLEND_MODE == 10 ) [XBOX] + +// debug crap: +// NOSKIP: $DETAILTEXTURE +// NOSKIP: $CUBEMAP +// NOSKIP: $ENVMAPMASK +// NOSKIP: $BASEALPHAENVMAPMASK +// NOSKIP: $SELFILLUM + +#define USE_32BIT_LIGHTMAPS_ON_360 //uncomment to use 32bit lightmaps, be sure to keep this in sync with the same #define in materialsystem/cmatlightmaps.cpp + +#include "common_ps_fxc.h" +#include "common_flashlight_fxc.h" +#include "common_lightmappedgeneric_fxc.h" + +#if SEAMLESS +#define USE_FAST_PATH 1 +#else +#define USE_FAST_PATH FASTPATH +#endif + +const HALF4 g_EnvmapTint : register( c0 ); + +#if USE_FAST_PATH == 1 + +# if FASTPATHENVMAPCONTRAST == 0 +static const HALF3 g_EnvmapContrast = { 0.0f, 0.0f, 0.0f }; +# else +static const HALF3 g_EnvmapContrast = { 1.0f, 1.0f, 1.0f }; +# endif +static const HALF3 g_EnvmapSaturation = { 1.0f, 1.0f, 1.0f }; +static const HALF g_FresnelReflection = 1.0f; +static const HALF g_OneMinusFresnelReflection = 0.0f; +static const HALF4 g_SelfIllumTint = { 1.0f, 1.0f, 1.0f, 1.0f }; +# if OUTLINE +const float4 g_OutlineParams : register( c2 ); +#define OUTLINE_MIN_VALUE0 g_OutlineParams.x +#define OUTLINE_MIN_VALUE1 g_OutlineParams.y +#define OUTLINE_MAX_VALUE0 g_OutlineParams.z +#define OUTLINE_MAX_VALUE1 g_OutlineParams.w + +const float4 g_OutlineColor : register( c3 ); +#define OUTLINE_COLOR g_OutlineColor + +# endif +# if SOFTEDGES +const float4 g_EdgeSoftnessParms : register( c4 ); +#define SOFT_MASK_MIN g_EdgeSoftnessParms.x +#define SOFT_MASK_MAX g_EdgeSoftnessParms.y +# endif +#else + +const HALF3 g_EnvmapContrast : register( c2 ); +const HALF3 g_EnvmapSaturation : register( c3 ); +const HALF4 g_FresnelReflectionReg : register( c4 ); +#define g_FresnelReflection g_FresnelReflectionReg.a +#define g_OneMinusFresnelReflection g_FresnelReflectionReg.b +const HALF4 g_SelfIllumTint : register( c7 ); +#endif + +const float4 g_DetailTint_and_BlendFactor : register( c8 ); +#define g_DetailTint (g_DetailTint_and_BlendFactor.rgb) +#define g_DetailBlendFactor (g_DetailTint_and_BlendFactor.w) + +const HALF3 g_EyePos : register( c10 ); +const HALF4 g_FogParams : register( c11 ); +const float4 g_TintValuesAndLightmapScale : register( c12 ); + +#define g_flAlpha2 g_TintValuesAndLightmapScale.w + +const float4 g_FlashlightAttenuationFactors : register( c13 ); +const float3 g_FlashlightPos : register( c14 ); +const float4x4 g_FlashlightWorldToTexture : register( c15 ); // through c18 +const float4 g_ShadowTweaks : register( c19 ); + + +sampler BaseTextureSampler : register( s0 ); +sampler LightmapSampler : register( s1 ); +sampler EnvmapSampler : register( s2 ); +#if FANCY_BLENDING +sampler BlendModulationSampler : register( s3 ); +#endif + +#if DETAILTEXTURE +sampler DetailSampler : register( s12 ); +#endif + +sampler BumpmapSampler : register( s4 ); +#if NORMAL_DECODE_MODE == NORM_DECODE_ATI2N_ALPHA +sampler AlphaMapSampler : register( s9 ); // alpha +#else +#define AlphaMapSampler BumpmapSampler +#endif + +#if BUMPMAP2 == 1 +sampler BumpmapSampler2 : register( s5 ); +#if NORMAL_DECODE_MODE == NORM_DECODE_ATI2N_ALPHA +sampler AlphaMapSampler2 : register( s10 ); // alpha +#else +#define AlphaMapSampler2 BumpmapSampler2 +#endif +#else +sampler EnvmapMaskSampler : register( s5 ); +#endif + + +#if WARPLIGHTING +sampler WarpLightingSampler : register( s6 ); +#endif +sampler BaseTextureSampler2 : register( s7 ); + +#if BUMPMASK == 1 +sampler BumpMaskSampler : register( s8 ); +#if NORMALMASK_DECODE_MODE == NORM_DECODE_ATI2N_ALPHA +sampler AlphaMaskSampler : register( s11 ); // alpha +#else +#define AlphaMaskSampler BumpMaskSampler +#endif +#endif + +#if defined( _X360 ) && FLASHLIGHT +sampler FlashlightSampler : register( s13 ); +sampler ShadowDepthSampler : register( s14 ); +sampler RandRotSampler : register( s15 ); +#endif + +struct PS_INPUT +{ +#if SEAMLESS + float3 SeamlessTexCoord : TEXCOORD0; // zy xz + float4 detailOrBumpAndEnvmapMaskTexCoord : TEXCOORD1; // envmap mask +#else + HALF2 baseTexCoord : TEXCOORD0; + // detail textures and bumpmaps are mutually exclusive so that we have enough texcoords. +#if ( RELIEF_MAPPING == 0 ) + HALF4 detailOrBumpAndEnvmapMaskTexCoord : TEXCOORD1; +#endif +#endif +// CENTROID: TEXCOORD2 + HALF4 lightmapTexCoord1And2 : TEXCOORD2; +// CENTROID: TEXCOORD3 + HALF4 lightmapTexCoord3 : TEXCOORD3; + HALF4 worldPos_projPosZ : TEXCOORD4; + HALF3x3 tangentSpaceTranspose : TEXCOORD5; + // tangentSpaceTranspose : TEXCOORD6 + // tangentSpaceTranspose : TEXCOORD7 + HALF4 vertexColor : COLOR; + float4 vertexBlendX_fogFactorW : COLOR1; + + // Extra iterators on 360, used in flashlight combo +#if defined( _X360 ) && FLASHLIGHT + float4 flashlightSpacePos : TEXCOORD8; + float4 vProjPos : TEXCOORD9; +#endif +}; + +#if LIGHTING_PREVIEW == 2 +LPREVIEW_PS_OUT main( PS_INPUT i ) : COLOR +#else +HALF4 main( PS_INPUT i ) : COLOR +#endif +{ + bool bBaseTexture2 = BASETEXTURE2 ? true : false; + bool bDetailTexture = DETAILTEXTURE ? true : false; + bool bBumpmap = BUMPMAP ? true : false; + bool bDiffuseBumpmap = DIFFUSEBUMPMAP ? true : false; + bool bCubemap = CUBEMAP ? true : false; + bool bEnvmapMask = ENVMAPMASK ? true : false; + bool bBaseAlphaEnvmapMask = BASEALPHAENVMAPMASK ? true : false; + bool bSelfIllum = SELFILLUM ? true : false; + bool bNormalMapAlphaEnvmapMask = NORMALMAPALPHAENVMAPMASK ? true : false; + bool bBaseTextureNoEnvmap = BASETEXTURENOENVMAP ? true : false; + bool bBaseTexture2NoEnvmap = BASETEXTURE2NOENVMAP ? true : false; + + float4 baseColor = 0.0f; + float4 baseColor2 = 0.0f; + float4 vNormal = float4(0, 0, 1, 1); + float3 baseTexCoords = float3(0,0,0); + +#if SEAMLESS + baseTexCoords = i.SeamlessTexCoord.xyz; +#else + baseTexCoords.xy = i.baseTexCoord.xy; +#endif + + GetBaseTextureAndNormal( BaseTextureSampler, BaseTextureSampler2, BumpmapSampler, bBaseTexture2, bBumpmap || bNormalMapAlphaEnvmapMask, + baseTexCoords, i.vertexColor.rgb, baseColor, baseColor2, vNormal ); + +#if BUMPMAP == 1 // not ssbump + vNormal.xyz = vNormal.xyz * 2.0f - 1.0f; // make signed if we're not ssbump +#endif + + HALF3 lightmapColor1 = HALF3( 1.0f, 1.0f, 1.0f ); + HALF3 lightmapColor2 = HALF3( 1.0f, 1.0f, 1.0f ); + HALF3 lightmapColor3 = HALF3( 1.0f, 1.0f, 1.0f ); +#if LIGHTING_PREVIEW == 0 + if( bBumpmap && bDiffuseBumpmap ) + { + HALF2 bumpCoord1; + HALF2 bumpCoord2; + HALF2 bumpCoord3; + ComputeBumpedLightmapCoordinates( i.lightmapTexCoord1And2, i.lightmapTexCoord3.xy, + bumpCoord1, bumpCoord2, bumpCoord3 ); + + lightmapColor1 = LightMapSample( LightmapSampler, bumpCoord1 ); + lightmapColor2 = LightMapSample( LightmapSampler, bumpCoord2 ); + lightmapColor3 = LightMapSample( LightmapSampler, bumpCoord3 ); + } + else + { + HALF2 bumpCoord1 = ComputeLightmapCoordinates( i.lightmapTexCoord1And2, i.lightmapTexCoord3.xy ); + lightmapColor1 = LightMapSample( LightmapSampler, bumpCoord1 ); + } +#endif + +#if RELIEF_MAPPING + // in the parallax case, all texcoords must be the same in order to free + // up an iterator for the tangent space view vector + HALF2 detailTexCoord = i.baseTexCoord.xy; + HALF2 bumpmapTexCoord = i.baseTexCoord.xy; + HALF2 envmapMaskTexCoord = i.baseTexCoord.xy; +#else + + #if ( DETAILTEXTURE == 1 ) + HALF2 detailTexCoord = i.detailOrBumpAndEnvmapMaskTexCoord.xy; + HALF2 bumpmapTexCoord = i.baseTexCoord.xy; + #elif ( BUMPMASK == 1 ) + HALF2 detailTexCoord = 0.0f; + HALF2 bumpmapTexCoord = i.detailOrBumpAndEnvmapMaskTexCoord.xy; + HALF2 bumpmap2TexCoord = i.detailOrBumpAndEnvmapMaskTexCoord.wz; + #else + HALF2 detailTexCoord = 0.0f; + HALF2 bumpmapTexCoord = i.detailOrBumpAndEnvmapMaskTexCoord.xy; + #endif + + HALF2 envmapMaskTexCoord = i.detailOrBumpAndEnvmapMaskTexCoord.wz; +#endif // !RELIEF_MAPPING + + HALF4 detailColor = HALF4( 1.0f, 1.0f, 1.0f, 1.0f ); +#if DETAILTEXTURE + +#if SHADER_MODEL_PS_2_0 + detailColor = tex2D( DetailSampler, detailTexCoord ); +#else + detailColor = float4( g_DetailTint, 1.0f ) * tex2D( DetailSampler, detailTexCoord ); +#endif + +#endif + +#if ( OUTLINE || SOFTEDGES ) + float distAlphaMask = baseColor.a; + +# if OUTLINE + if ( ( distAlphaMask >= OUTLINE_MIN_VALUE0 ) && + ( distAlphaMask <= OUTLINE_MAX_VALUE1 ) ) + { + float oFactor=1.0; + if ( distAlphaMask <= OUTLINE_MIN_VALUE1 ) + { + oFactor=smoothstep( OUTLINE_MIN_VALUE0, OUTLINE_MIN_VALUE1, distAlphaMask ); + } + else + { + oFactor=smoothstep( OUTLINE_MAX_VALUE1, OUTLINE_MAX_VALUE0, distAlphaMask ); + } + baseColor = lerp( baseColor, OUTLINE_COLOR, oFactor ); + } +# endif +# if SOFTEDGES + baseColor.a *= smoothstep( SOFT_MASK_MAX, SOFT_MASK_MIN, distAlphaMask ); +# else + baseColor.a *= distAlphaMask >= 0.5; +# endif +#endif + + +#if LIGHTING_PREVIEW == 2 + baseColor.xyz=GammaToLinear(baseColor.xyz); +#endif + + float blendedAlpha = baseColor.a; + +#if MASKEDBLENDING + float blendfactor=0.5; +#else + float blendfactor=i.vertexBlendX_fogFactorW.r; +#endif + + if( bBaseTexture2 ) + { +#if (SELFILLUM == 0) && (PIXELFOGTYPE != PIXEL_FOG_TYPE_HEIGHT) && (FANCY_BLENDING) + float4 modt=tex2D(BlendModulationSampler,i.lightmapTexCoord3.zw); +#if MASKEDBLENDING + // FXC is unable to optimize this, despite blendfactor=0.5 above + //float minb=modt.g-modt.r; + //float maxb=modt.g+modt.r; + //blendfactor=smoothstep(minb,maxb,blendfactor); + blendfactor=modt.g; +#else + float minb=saturate(modt.g-modt.r); + float maxb=saturate(modt.g+modt.r); + blendfactor=smoothstep(minb,maxb,blendfactor); +#endif +#endif + baseColor.rgb = lerp( baseColor, baseColor2.rgb, blendfactor ); + blendedAlpha = lerp( baseColor.a, baseColor2.a, blendfactor ); + } + + HALF3 specularFactor = 1.0f; + float4 vNormalMask = float4(0, 0, 1, 1); + if( bBumpmap ) + { + if( bBaseTextureNoEnvmap ) + { + vNormal.a = 0.0f; + } + +#if ( BUMPMAP2 == 1 ) + { + #if ( BUMPMASK == 1 ) + HALF2 b2TexCoord = bumpmap2TexCoord; + #else + HALF2 b2TexCoord = bumpmapTexCoord; + #endif + + HALF4 vNormal2; + if ( BUMPMAP == 2 ) + vNormal2 = tex2D( BumpmapSampler2, b2TexCoord ); + else + vNormal2 = DecompressNormal( BumpmapSampler2, b2TexCoord, NORMAL_DECODE_MODE, AlphaMapSampler2 ); // Bump 2 coords + + if( bBaseTexture2NoEnvmap ) + { + vNormal2.a = 0.0f; + } + + #if ( BUMPMASK == 1 ) + float3 vNormal1 = DecompressNormal( BumpmapSampler, i.detailOrBumpAndEnvmapMaskTexCoord.xy, NORMALMASK_DECODE_MODE, AlphaMapSampler ); + + vNormal.xyz = normalize( vNormal1.xyz + vNormal2.xyz ); + + // Third normal map...same coords as base + vNormalMask = DecompressNormal( BumpMaskSampler, i.baseTexCoord.xy, NORMALMASK_DECODE_MODE, AlphaMaskSampler ); + + vNormal.xyz = lerp( vNormalMask.xyz, vNormal.xyz, vNormalMask.a ); // Mask out normals from vNormal + specularFactor = vNormalMask.a; + #else // BUMPMASK == 0 + if ( FANCY_BLENDING && bNormalMapAlphaEnvmapMask ) + { + vNormal = lerp( vNormal, vNormal2, blendfactor); + } + else + { + vNormal.xyz = lerp( vNormal.xyz, vNormal2.xyz, blendfactor); + } + + #endif + + } + +#endif // BUMPMAP2 == 1 + + if( bNormalMapAlphaEnvmapMask ) + { + specularFactor *= vNormal.a; + } + } + else if ( bNormalMapAlphaEnvmapMask ) + { + specularFactor *= vNormal.a; + } + +#if ( BUMPMAP2 == 0 ) + if( bEnvmapMask ) + { + specularFactor *= tex2D( EnvmapMaskSampler, envmapMaskTexCoord ).xyz; + } +#endif + + if( bBaseAlphaEnvmapMask ) + { + specularFactor *= 1.0 - blendedAlpha; // Reversing alpha blows! + } + float4 albedo = float4( 1.0f, 1.0f, 1.0f, 1.0f ); + float alpha = 1.0f; + albedo *= baseColor; + if( !bBaseAlphaEnvmapMask && !bSelfIllum ) + { + alpha *= baseColor.a; + } + + if( bDetailTexture ) + { + albedo = TextureCombine( albedo, detailColor, DETAIL_BLEND_MODE, g_DetailBlendFactor ); + } + + // The vertex color contains the modulation color + vertex color combined +#if ( SEAMLESS == 0 ) + albedo.xyz *= i.vertexColor; +#endif + alpha *= i.vertexColor.a * g_flAlpha2; // not sure about this one + + // Save this off for single-pass flashlight, since we'll still need the SSBump vector, not a real normal + float3 vSSBumpVector = vNormal.xyz; + + HALF3 diffuseLighting; + if( bBumpmap && bDiffuseBumpmap ) + { + +// ssbump +#if ( BUMPMAP == 2 ) + diffuseLighting = vNormal.x * lightmapColor1 + + vNormal.y * lightmapColor2 + + vNormal.z * lightmapColor3; + diffuseLighting *= g_TintValuesAndLightmapScale.rgb; + + // now, calculate vNormal for reflection purposes. if vNormal isn't needed, hopefully + // the compiler will eliminate these calculations + vNormal.xyz = normalize( bumpBasis[0]*vNormal.x + bumpBasis[1]*vNormal.y + bumpBasis[2]*vNormal.z); +#else + float3 dp; + dp.x = saturate( dot( vNormal, bumpBasis[0] ) ); + dp.y = saturate( dot( vNormal, bumpBasis[1] ) ); + dp.z = saturate( dot( vNormal, bumpBasis[2] ) ); + dp *= dp; + +#if ( DETAIL_BLEND_MODE == TCOMBINE_SSBUMP_BUMP ) + dp *= 2*detailColor; +#endif + diffuseLighting = dp.x * lightmapColor1 + + dp.y * lightmapColor2 + + dp.z * lightmapColor3; + float sum = dot( dp, float3( 1.0f, 1.0f, 1.0f ) ); + diffuseLighting *= g_TintValuesAndLightmapScale.rgb / sum; +#endif + } + else + { + diffuseLighting = lightmapColor1 * g_TintValuesAndLightmapScale.rgb; + } + +#if WARPLIGHTING && ( SEAMLESS == 0 ) + float len=0.5*length(diffuseLighting); + // FIXME: 8-bit lookup textures like this need a "nice filtering" VTF option, which converts + // them to 16-bit on load or does filtering in the shader (since most hardware - 360 + // included - interpolates 8-bit textures at 8-bit precision, which causes banding) + diffuseLighting *= 2.0*tex2D(WarpLightingSampler,float2(len,0)); +#endif + +#if CUBEMAP || LIGHTING_PREVIEW || ( defined( _X360 ) && FLASHLIGHT ) + float3 worldSpaceNormal = mul( vNormal, i.tangentSpaceTranspose ); +#endif + + float3 diffuseComponent = albedo.xyz * diffuseLighting; + +#if defined( _X360 ) && FLASHLIGHT + + // ssbump doesn't pass a normal to the flashlight...it computes shadowing a different way +#if ( BUMPMAP == 2 ) + bool bHasNormal = false; + + float3 worldPosToLightVector = g_FlashlightPos - i.worldPos_projPosZ.xyz; + + float3 tangentPosToLightVector; + tangentPosToLightVector.x = dot( worldPosToLightVector, i.tangentSpaceTranspose[0] ); + tangentPosToLightVector.y = dot( worldPosToLightVector, i.tangentSpaceTranspose[1] ); + tangentPosToLightVector.z = dot( worldPosToLightVector, i.tangentSpaceTranspose[2] ); + + tangentPosToLightVector = normalize( tangentPosToLightVector ); + + float nDotL = saturate( vSSBumpVector.x*dot( tangentPosToLightVector, bumpBasis[0]) + + vSSBumpVector.y*dot( tangentPosToLightVector, bumpBasis[1]) + + vSSBumpVector.z*dot( tangentPosToLightVector, bumpBasis[2]) ); +#else + bool bHasNormal = true; + float nDotL = 1.0f; +#endif + + float fFlashlight = DoFlashlight( g_FlashlightPos, i.worldPos_projPosZ.xyz, i.flashlightSpacePos, + worldSpaceNormal, g_FlashlightAttenuationFactors.xyz, + g_FlashlightAttenuationFactors.w, FlashlightSampler, ShadowDepthSampler, + RandRotSampler, 0, true, false, i.vProjPos.xy / i.vProjPos.w, false, g_ShadowTweaks, bHasNormal ); + + diffuseComponent = albedo.xyz * ( diffuseLighting + ( fFlashlight * nDotL ) ); +#endif + + if( bSelfIllum ) + { + float3 selfIllumComponent = g_SelfIllumTint * albedo.xyz; + diffuseComponent = lerp( diffuseComponent, selfIllumComponent, baseColor.a ); + } + + HALF3 specularLighting = HALF3( 0.0f, 0.0f, 0.0f ); +#if CUBEMAP + if( bCubemap ) + { + float3 worldVertToEyeVector = g_EyePos - i.worldPos_projPosZ.xyz; + float3 reflectVect = CalcReflectionVectorUnnormalized( worldSpaceNormal, worldVertToEyeVector ); + + // Calc Fresnel factor + half3 eyeVect = normalize(worldVertToEyeVector); + HALF fresnel = 1.0 - dot( worldSpaceNormal, eyeVect ); + fresnel = pow( fresnel, 5.0 ); + fresnel = fresnel * g_OneMinusFresnelReflection + g_FresnelReflection; + + specularLighting = ENV_MAP_SCALE * texCUBE( EnvmapSampler, reflectVect ); + specularLighting *= specularFactor; + + specularLighting *= g_EnvmapTint; +#if FANCY_BLENDING == 0 + HALF3 specularLightingSquared = specularLighting * specularLighting; + specularLighting = lerp( specularLighting, specularLightingSquared, g_EnvmapContrast ); + HALF3 greyScale = dot( specularLighting, HALF3( 0.299f, 0.587f, 0.114f ) ); + specularLighting = lerp( greyScale, specularLighting, g_EnvmapSaturation ); +#endif + specularLighting *= fresnel; + } +#endif + + HALF3 result = diffuseComponent + specularLighting; + +#if LIGHTING_PREVIEW + worldSpaceNormal = mul( vNormal, i.tangentSpaceTranspose ); +# if LIGHTING_PREVIEW == 1 + float dotprod = 0.7+0.25 * dot( worldSpaceNormal, normalize( float3( 1, 2, -.5 ) ) ); + return FinalOutput( HALF4( dotprod*albedo.xyz, alpha ), 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE ); +# else + LPREVIEW_PS_OUT ret; + ret.color = float4( albedo.xyz,alpha ); + ret.normal = float4( worldSpaceNormal,alpha ); + ret.position = float4( i.worldPos_projPosZ.xyz, alpha ); + ret.flags = float4( 1, 1, 1, alpha ); + + return FinalOutput( ret, 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE ); +# endif +#else // == end LIGHTING_PREVIEW == + + bool bWriteDepthToAlpha = false; + + // ps_2_b and beyond +#if !(defined(SHADER_MODEL_PS_1_1) || defined(SHADER_MODEL_PS_1_4) || defined(SHADER_MODEL_PS_2_0)) + bWriteDepthToAlpha = ( WRITE_DEPTH_TO_DESTALPHA != 0 ) && ( WRITEWATERFOGTODESTALPHA == 0 ); +#endif + + float fogFactor = CalcPixelFogFactor( PIXELFOGTYPE, g_FogParams, g_EyePos.z, i.worldPos_projPosZ.z, i.worldPos_projPosZ.w ); + +#if WRITEWATERFOGTODESTALPHA && (PIXELFOGTYPE == PIXEL_FOG_TYPE_HEIGHT) + alpha = fogFactor; +#endif + + return FinalOutput( float4( result.rgb, alpha ), fogFactor, PIXELFOGTYPE, TONEMAP_SCALE_LINEAR, bWriteDepthToAlpha, i.worldPos_projPosZ.w ); + +#endif +} + diff --git a/materialsystem/stdshaders/lightmappedgeneric_ps2x.fxc b/materialsystem/stdshaders/lightmappedgeneric_ps2x.fxc new file mode 100644 index 0000000..599d16a --- /dev/null +++ b/materialsystem/stdshaders/lightmappedgeneric_ps2x.fxc @@ -0,0 +1,59 @@ +// STATIC: "MASKEDBLENDING" "0..1" +// STATIC: "BASETEXTURE2" "0..1" +// STATIC: "DETAILTEXTURE" "0..1" +// STATIC: "BUMPMAP" "0..2" +// STATIC: "BUMPMAP2" "0..1" +// STATIC: "CUBEMAP" "0..1" +// STATIC: "ENVMAPMASK" "0..1" +// STATIC: "BASEALPHAENVMAPMASK" "0..1" +// STATIC: "SELFILLUM" "0..1" +// STATIC: "NORMALMAPALPHAENVMAPMASK" "0..1" +// STATIC: "DIFFUSEBUMPMAP" "0..1" +// STATIC: "BASETEXTURENOENVMAP" "0..1" +// STATIC: "BASETEXTURE2NOENVMAP" "0..1" +// STATIC: "WARPLIGHTING" "0..1" +// STATIC: "FANCY_BLENDING" "0..1" +// STATIC: "RELIEF_MAPPING" "0..0" [ps20b] +// STATIC: "SEAMLESS" "0..1" +// STATIC: "OUTLINE" "0..1" +// STATIC: "SOFTEDGES" "0..1" +// STATIC: "BUMPMASK" "0..1" +// STATIC: "NORMAL_DECODE_MODE" "0..0" [XBOX] +// STATIC: "NORMAL_DECODE_MODE" "0..0" [PC] +// STATIC: "NORMALMASK_DECODE_MODE" "0..0" [XBOX] +// STATIC: "NORMALMASK_DECODE_MODE" "0..0" [PC] +// STATIC: "DETAIL_BLEND_MODE" "0..11" +// STATIC: "FLASHLIGHT" "0..1" [ps20b] [XBOX] + +// DYNAMIC: "FASTPATHENVMAPCONTRAST" "0..1" +// DYNAMIC: "FASTPATH" "0..1" +// DYNAMIC: "WRITEWATERFOGTODESTALPHA" "0..1" +// DYNAMIC: "PIXELFOGTYPE" "0..1" +// DYNAMIC: "LIGHTING_PREVIEW" "0..2" [PC] +// DYNAMIC: "LIGHTING_PREVIEW" "0..0" [XBOX] +// DYNAMIC: "WRITE_DEPTH_TO_DESTALPHA" "0..1" [ps20b] [PC] +// DYNAMIC: "WRITE_DEPTH_TO_DESTALPHA" "0..0" [ps20b] [XBOX] + +// SKIP: $SEAMLESS && $RELIEF_MAPPING [ps20b] + +// SKIP: (! $DETAILTEXTURE) && ( $DETAIL_BLEND_MODE != 0 ) + +// SKIP: $SEAMLESS && ( $OUTLINE || $SOFTEDGES) +// SKIP: $BASETEXTURE2 && ( $OUTLINE || $SOFTEDGES) +// SKIP: $BUMPMAP2 && ( $OUTLINE || $SOFTEDGES) +// SKIP: $SELFILLUM && ( $OUTLINE || $SOFTEDGES) +// SKIP: $MASKEDBLENDING && ( $OUTLINE || $SOFTEDGES) +// SKIP: $FANCY_BLENDING && ( $OUTLINE || $SOFTEDGES) +// SKIP: $LIGHTING_PREVIEW && ( $OUTLINE || $SOFTEDGES) +// SKIP: ($FASTPATH == 0) && ( $OUTLINE || $SOFTEDGES) +// SKIP: ($DETAILTEXTURE && $BUMPMAP) && ( $OUTLINE || $SOFTEDGES) +// SKIP: ($WARPLIGHTING) && ( $OUTLINE || $SOFTEDGES) +// SKIP: ($BUMPMAP) && ( $OUTLINE || $SOFTEDGES) +// SKIP: ($DETAIL_BLEND_MODE == 2 ) || ($DETAIL_BLEND_MODE == 3 ) || ($DETAIL_BLEND_MODE == 4 ) +// SKIP: ($DETAIL_BLEND_MODE == 5 ) || ($DETAIL_BLEND_MODE == 6 ) || ($DETAIL_BLEND_MODE == 7 ) +// SKIP: ($DETAIL_BLEND_MODE == 8 ) || ($DETAIL_BLEND_MODE == 9 ) +// SKIP ($DETAIL_BLEND_MODE == 10 ) && ($BUMPMAP == 0 ) +// SKIP ($DETAIL_BLEND_MODE == 11 ) && ($BUMPMAP != 0 ) + +#include "lightmappedgeneric_ps2_3_x.h" + diff --git a/materialsystem/stdshaders/lightmappedgeneric_selfilluminatedenvmap.psh b/materialsystem/stdshaders/lightmappedgeneric_selfilluminatedenvmap.psh new file mode 100644 index 0000000..4c80db2 --- /dev/null +++ b/materialsystem/stdshaders/lightmappedgeneric_selfilluminatedenvmap.psh @@ -0,0 +1,27 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; Draw a texture . . woo hoo! +; t0 - texture +; +; The texture coordinates need to be defined as follows: +; tc0 - texcoords +; c1 - self-illum tint +; c2 - envmap tint +;------------------------------------------------------------------------------ + +tex t0 +tex t1 +tex t2 + +mul r0.rgb, t0, v0 + ; base times vertex color (no alpha) +mov r0.a, v0.a ; Grab alpha from vertex color + +mad r0.rgb, t2, c2, r0 ; + envmap * envmaptint (color only) + +mul r0.rgb, t1, r0 ; fold in lighting (color only) +mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2) + +mul r1, t0, c1 ; Self illum * tint +lrp r0.rgb, t0.a, r1, r0 ; Blend between self-illum + base * lighting + diff --git a/materialsystem/stdshaders/lightmappedgeneric_selfilluminatedmaskedenvmap.psh b/materialsystem/stdshaders/lightmappedgeneric_selfilluminatedmaskedenvmap.psh new file mode 100644 index 0000000..7807212 --- /dev/null +++ b/materialsystem/stdshaders/lightmappedgeneric_selfilluminatedmaskedenvmap.psh @@ -0,0 +1,27 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; Draw a texture . . woo hoo! +; t0 - texture +; +; The texture coordinates need to be defined as follows: +; tc0 - texcoords +; c1 - self-illum tint +; c2 - envmap tint +;------------------------------------------------------------------------------ + +tex t0 +tex t1 +tex t2 +tex t3 + +mul r0.rgb, t0, v0 + ; base times vertex color (with alpha) +mov r0.a, v0.a ; Grab alpha from vertex color + +mul r1, t2, t3 ; envmap * envmapmask +mad r0.rgb, r1, c2, r0 ; + envmap * envmapmask * envmaptint (color only) + +mul r1, c1, t0.a ; Self illum alpha * tint +mad r1, t0, r1, t1 ; Self illum * tint + lightmap +mul r0.rgb, r1, r0 ; fold in lighting (color only) +mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2) diff --git a/materialsystem/stdshaders/lightmappedgeneric_vs11.vsh b/materialsystem/stdshaders/lightmappedgeneric_vs11.vsh new file mode 100644 index 0000000..cc1dd1f --- /dev/null +++ b/materialsystem/stdshaders/lightmappedgeneric_vs11.vsh @@ -0,0 +1,20 @@ +vs.1.1 + +# DYNAMIC: "DOWATERFOG" "0..1" +# STATIC: "DETAIL" "0..1" +# STATIC: "ENVMAP" "0..1" +# STATIC: "ENVMAPCAMERASPACE" "0..0" +# STATIC: "ENVMAPSPHERE" "0..1" +# STATIC: "VERTEXCOLOR" "0..1" + +# can't have envmapshere or envmapcameraspace without envmap +# SKIP: !$ENVMAP && ( $ENVMAPSPHERE || $ENVMAPCAMERASPACE ) + +# can't have both envmapsphere and envmapcameraspace +# SKIP: $ENVMAPSPHERE && $ENVMAPCAMERASPACE + +#include "LightmappedGeneric_inc.vsh" + +&LightmappedGeneric( $DETAIL, $ENVMAP, $ENVMAPCAMERASPACE, $ENVMAPSPHERE, + $VERTEXCOLOR ); + diff --git a/materialsystem/stdshaders/lightmappedgeneric_vs20.fxc b/materialsystem/stdshaders/lightmappedgeneric_vs20.fxc new file mode 100644 index 0000000..362eb66 --- /dev/null +++ b/materialsystem/stdshaders/lightmappedgeneric_vs20.fxc @@ -0,0 +1,254 @@ +// STATIC: "ENVMAP_MASK" "0..1" +// STATIC: "TANGENTSPACE" "0..1" +// STATIC: "BUMPMAP" "0..1" +// STATIC: "DIFFUSEBUMPMAP" "0..1" +// STATIC: "VERTEXCOLOR" "0..1" +// STATIC: "VERTEXALPHATEXBLENDFACTOR" "0..1" +// STATIC: "RELIEF_MAPPING" "0..0" +// STATIC: "SEAMLESS" "0..1" +// STATIC: "BUMPMASK" "0..1" +// STATIC: "FLASHLIGHT" "0..1" [XBOX] + +// DYNAMIC: "FASTPATH" "0..1" +// DYNAMIC: "DOWATERFOG" "0..1" +// DYNAMIC: "LIGHTING_PREVIEW" "0..1" [PC] +// DYNAMIC: "LIGHTING_PREVIEW" "0..0" [XBOX] + +// This should not be a combo since I'm a moron with the tangent space and the flashlight. +// SKIP: !$BUMPMAP && $DIFFUSEBUMPMAP +// SKIP: $SEAMLESS && $RELIEF_MAPPING +// SKIP: $BUMPMASK && $RELIEF_MAPPING +// SKIP: $BUMPMASK && $SEAMLESS + +#include "common_vs_fxc.h" + +static const int g_FogType = DOWATERFOG; +static const bool g_UseSeparateEnvmapMask = ENVMAP_MASK; +static const bool g_bTangentSpace = TANGENTSPACE; +static const bool g_bBumpmap = BUMPMAP; +static const bool g_bBumpmapDiffuseLighting = DIFFUSEBUMPMAP; +static const bool g_bVertexColor = VERTEXCOLOR; +static const bool g_bVertexAlphaTexBlendFactor = VERTEXALPHATEXBLENDFACTOR; +static const bool g_BumpMask = BUMPMASK; + +#if SEAMLESS +const float4 SeamlessScale : register( SHADER_SPECIFIC_CONST_0 ); +#define SEAMLESS_SCALE (SeamlessScale.x) +#else +const float4 cBaseTexCoordTransform[2] : register( SHADER_SPECIFIC_CONST_0 ); +const float4 cDetailOrBumpTexCoordTransform[2] : register( SHADER_SPECIFIC_CONST_2 ); +#endif +// This should be identity if we are bump mapping, otherwise we'll screw up the lightmapTexCoordOffset. +const float4 cEnvmapMaskTexCoordTransform[2] : register( SHADER_SPECIFIC_CONST_4 ); +const float4x4 g_FlashlightWorldToTexture : register( SHADER_SPECIFIC_CONST_6 ); +const float4 cBlendMaskTexCoordTransform[2] : register( SHADER_SPECIFIC_CONST_10 ); // not contiguous with the rest! + +struct VS_INPUT +{ + float3 vPos : POSITION; + float4 vNormal : NORMAL; + float2 vBaseTexCoord : TEXCOORD0; + float2 vLightmapTexCoord : TEXCOORD1; + float2 vLightmapTexCoordOffset : TEXCOORD2; + float3 vTangentS : TANGENT; + float3 vTangentT : BINORMAL; + float4 vColor : COLOR0; +}; + +struct VS_OUTPUT +{ + float4 projPos : POSITION; +#if !defined( _X360 ) + float fog : FOG; +#endif + +#if SEAMLESS + float3 SeamlessTexCoord : TEXCOORD0; // x y z + float4 detailOrBumpAndEnvmapMaskTexCoord : TEXCOORD1; // envmap mask +#else + float2 baseTexCoord : TEXCOORD0; + // detail textures and bumpmaps are mutually exclusive so that we have enough texcoords. +#if RELIEF_MAPPING + float3 TangentSpaceViewRay : TEXCOORD1; +#else + float4 detailOrBumpAndEnvmapMaskTexCoord : TEXCOORD1; +#endif +#endif + float4 lightmapTexCoord1And2 : TEXCOORD2; + float4 lightmapTexCoord3 : TEXCOORD3; // and basetexcoord*mask_scale + float4 worldPos_projPosZ : TEXCOORD4; + +#if TANGENTSPACE || (LIGHTING_PREVIEW) || defined( _X360 ) + float3x3 tangentSpaceTranspose : TEXCOORD5; // and 6 and 7 +#endif + + float4 vertexColor : COLOR; // in seamless, r g b = blend weights + float4 vertexBlendX_fogFactorW : COLOR1; + + // Extra iterators on 360, used in flashlight combo +#if defined( _X360 ) +#if FLASHLIGHT + float4 flashlightSpacePos : TEXCOORD8; + float4 vProjPos : TEXCOORD9; +#endif +#endif + +}; + +VS_OUTPUT main( const VS_INPUT v ) +{ + VS_OUTPUT o = ( VS_OUTPUT )0; + + float3 vObjNormal; + DecompressVertex_Normal( v.vNormal, vObjNormal ); + + float3 worldPos = mul( float4( v.vPos, 1 ), cModel[0] ); + + float4 vProjPos = mul( float4( v.vPos, 1 ), cModelViewProj ); + o.projPos = vProjPos; + vProjPos.z = dot( float4( v.vPos, 1 ), cModelViewProjZ ); + + o.worldPos_projPosZ = float4( worldPos, vProjPos.z ); + + float3 worldNormal = mul( vObjNormal, ( float3x3 )cModel[0] ); + +#if TANGENTSPACE || (LIGHTING_PREVIEW) || defined( _X360 ) + float3 worldTangentS = mul( v.vTangentS, ( const float3x3 )cModel[0] ); + float3 worldTangentT = mul( v.vTangentT, ( const float3x3 )cModel[0] ); + + #if SEAMLESS && BUMPMAP && defined( _X360 ) + float3 n = normalize( worldNormal ); + float3 n2 = n * n; // sums to 1. + + o.tangentSpaceTranspose[0] = normalize( float3( n2.y + n2.z, 0.0f, n2.x ) ); + o.tangentSpaceTranspose[1] = normalize( float3( 0.0f, n2.x + n2.z, n2.y ) ); + o.tangentSpaceTranspose[2] = worldNormal; + #else + o.tangentSpaceTranspose[0] = worldTangentS; + o.tangentSpaceTranspose[1] = worldTangentT; + o.tangentSpaceTranspose[2] = worldNormal; + #endif + +#endif + + float3 worldVertToEyeVector = VSHADER_VECT_SCALE * (cEyePos - worldPos); + +#if SEAMLESS + { + // we need to fill in the texture coordinate projections + o.SeamlessTexCoord = SEAMLESS_SCALE*worldPos; + } +#else + { + if (FASTPATH) + { + o.baseTexCoord.xy = v.vBaseTexCoord; + } + else + { + o.baseTexCoord.x = dot( v.vBaseTexCoord, cBaseTexCoordTransform[0] ) + cBaseTexCoordTransform[0].w; + o.baseTexCoord.y = dot( v.vBaseTexCoord, cBaseTexCoordTransform[1] ) + cBaseTexCoordTransform[1].w; + } +#if ( RELIEF_MAPPING == 0 ) + { + // calculate detailorbumptexcoord + if ( FASTPATH ) + o.detailOrBumpAndEnvmapMaskTexCoord.xy = v.vBaseTexCoord.xy; + else + { + o.detailOrBumpAndEnvmapMaskTexCoord.x = dot( v.vBaseTexCoord, cDetailOrBumpTexCoordTransform[0] ) + cDetailOrBumpTexCoordTransform[0].w; + o.detailOrBumpAndEnvmapMaskTexCoord.y = dot( v.vBaseTexCoord, cDetailOrBumpTexCoordTransform[1] ) + cDetailOrBumpTexCoordTransform[1].w; + } + } +#endif + } +#endif + if ( FASTPATH ) + { + o.lightmapTexCoord3.zw = v.vBaseTexCoord; + } + else + { + o.lightmapTexCoord3.z = dot( v.vBaseTexCoord, cBlendMaskTexCoordTransform[0] ) + cBlendMaskTexCoordTransform[0].w; + o.lightmapTexCoord3.w = dot( v.vBaseTexCoord, cBlendMaskTexCoordTransform[1] ) + cBlendMaskTexCoordTransform[1].w; + } + + // compute lightmap coordinates + if( g_bBumpmap && g_bBumpmapDiffuseLighting ) + { + o.lightmapTexCoord1And2.xy = v.vLightmapTexCoord + v.vLightmapTexCoordOffset; + + float2 lightmapTexCoord2 = o.lightmapTexCoord1And2.xy + v.vLightmapTexCoordOffset; + float2 lightmapTexCoord3 = lightmapTexCoord2 + v.vLightmapTexCoordOffset; + + // reversed component order + o.lightmapTexCoord1And2.w = lightmapTexCoord2.x; + o.lightmapTexCoord1And2.z = lightmapTexCoord2.y; + + o.lightmapTexCoord3.xy = lightmapTexCoord3; + } + else + { + o.lightmapTexCoord1And2.xy = v.vLightmapTexCoord; + } + +#if ( RELIEF_MAPPING == 0) + if( g_UseSeparateEnvmapMask || g_BumpMask ) + { + // reversed component order +# if FASTPATH + o.detailOrBumpAndEnvmapMaskTexCoord.wz = v.vBaseTexCoord.xy; +# else + o.detailOrBumpAndEnvmapMaskTexCoord.w = dot( v.vBaseTexCoord, cEnvmapMaskTexCoordTransform[0] ) + cEnvmapMaskTexCoordTransform[0].w; + o.detailOrBumpAndEnvmapMaskTexCoord.z = dot( v.vBaseTexCoord, cEnvmapMaskTexCoordTransform[1] ) + cEnvmapMaskTexCoordTransform[1].w; +# endif + } +#endif + + o.vertexBlendX_fogFactorW = CalcFog( worldPos, vProjPos, g_FogType ); +#if !defined( _X360 ) + o.fog = o.vertexBlendX_fogFactorW; +#endif + + if (!g_bVertexColor) + { + o.vertexColor = float4( 1.0f, 1.0f, 1.0f, cModulationColor.a ); + } + else + { +#if FASTPATH + o.vertexColor = v.vColor; +#else + if ( g_bVertexAlphaTexBlendFactor ) + { + o.vertexColor.rgb = v.vColor.rgb; + o.vertexColor.a = cModulationColor.a; + } + else + { + o.vertexColor = v.vColor; + o.vertexColor.a *= cModulationColor.a; + } +#endif + } +#if SEAMLESS + // compute belnd weights in rgb + float3 vNormal=normalize( worldNormal ); + o.vertexColor.xyz = vNormal * vNormal; // sums to 1. +#endif + +// On 360, we have extra iterators and can fold the flashlight into this shader +#if defined( _X360 ) + #if FLASHLIGHT + o.flashlightSpacePos = mul( float4( worldPos, 1.0f ), g_FlashlightWorldToTexture ); + o.vProjPos = vProjPos; + #endif +#endif + + if ( g_bVertexAlphaTexBlendFactor ) + { + o.vertexBlendX_fogFactorW.r = v.vColor.a; + } + + return o; +} diff --git a/materialsystem/stdshaders/lightmappedreflective.cpp b/materialsystem/stdshaders/lightmappedreflective.cpp new file mode 100644 index 0000000..719bdaf --- /dev/null +++ b/materialsystem/stdshaders/lightmappedreflective.cpp @@ -0,0 +1,287 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//===========================================================================// + +#include "BaseVSShader.h" +#include "mathlib/vmatrix.h" +#include "common_hlsl_cpp_consts.h" // hack hack hack! + +#include "lightmappedreflective_vs20.inc" +#include "lightmappedreflective_ps20.inc" +#include "lightmappedreflective_ps20b.inc" + + +DEFINE_FALLBACK_SHADER( LightmappedReflective, LightmappedReflective_DX90 ) + +BEGIN_VS_SHADER( LightmappedReflective_DX90, "Help for Lightmapped Reflective" ) + + BEGIN_SHADER_PARAMS + SHADER_PARAM( REFRACTTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "_rt_WaterRefraction", "" ) + SHADER_PARAM( REFLECTTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "_rt_WaterReflection", "" ) + SHADER_PARAM( REFRACTAMOUNT, SHADER_PARAM_TYPE_FLOAT, "0", "" ) + SHADER_PARAM( REFRACTTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "refraction tint" ) + SHADER_PARAM( REFLECTAMOUNT, SHADER_PARAM_TYPE_FLOAT, "0.8", "" ) + SHADER_PARAM( REFLECTTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "reflection tint" ) + SHADER_PARAM( NORMALMAP, SHADER_PARAM_TYPE_TEXTURE, "dev/water_normal", "normal map" ) + SHADER_PARAM( BUMPFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $bumpmap" ) + SHADER_PARAM( BUMPTRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$bumpmap texcoord transform" ) + SHADER_PARAM( ENVMAPMASK, SHADER_PARAM_TYPE_TEXTURE, "shadertest/shadertest_envmask", "envmap mask" ) + SHADER_PARAM( ENVMAPMASKFRAME, SHADER_PARAM_TYPE_INTEGER, "", "" ) + SHADER_PARAM( FRESNELPOWER, SHADER_PARAM_TYPE_FLOAT, "5", "" ) + SHADER_PARAM( MAXREFLECTIVITY, SHADER_PARAM_TYPE_FLOAT, "1", "" ) + SHADER_PARAM( MINREFLECTIVITY, SHADER_PARAM_TYPE_FLOAT, "0", "" ) + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + if ( !params[FRESNELPOWER]->IsDefined() ) + { + params[FRESNELPOWER]->SetFloatValue( 5.0f ); + } + if ( !params[MAXREFLECTIVITY]->IsDefined() ) + { + params[MAXREFLECTIVITY]->SetFloatValue( 1.0f ); + } + + SET_FLAGS2( MATERIAL_VAR2_NEEDS_TANGENT_SPACES ); + if ( params[BASETEXTURE]->IsDefined() ) + { + SET_FLAGS2( MATERIAL_VAR2_LIGHTING_LIGHTMAP ); + if( g_pConfig->UseBumpmapping() && params[NORMALMAP]->IsDefined() ) + { + SET_FLAGS2( MATERIAL_VAR2_LIGHTING_BUMPED_LIGHTMAP ); + } + } + } + + SHADER_FALLBACK + { + // FIXME: Create dx8 level fallback if we use this feature out of the SFM + return 0; + } + + SHADER_INIT + { + if( params[REFRACTTEXTURE]->IsDefined() ) + { + LoadTexture( REFRACTTEXTURE, g_pHardwareConfig->GetHDRType() == HDR_TYPE_INTEGER || IsOSX() ? TEXTUREFLAGS_SRGB : 0 ); + } + if( params[REFLECTTEXTURE]->IsDefined() ) + { + LoadTexture( REFLECTTEXTURE, g_pHardwareConfig->GetHDRType() == HDR_TYPE_INTEGER || IsOSX() ? TEXTUREFLAGS_SRGB : 0 ); + } + if ( params[NORMALMAP]->IsDefined() ) + { + LoadBumpMap( NORMALMAP ); + } + if( params[BASETEXTURE]->IsDefined() ) + { + LoadTexture( BASETEXTURE, TEXTUREFLAGS_SRGB ); + + if( params[ENVMAPMASK]->IsDefined() ) + { + LoadTexture( ENVMAPMASK ); + } + } + else + { + params[ENVMAPMASK]->SetUndefined(); + } + } + + inline void DrawReflectionRefraction( IMaterialVar **params, IShaderShadow* pShaderShadow, + IShaderDynamicAPI* pShaderAPI, bool bReflection, bool bRefraction ) + { + BlendType_t nBlendType = EvaluateBlendRequirements( BASETEXTURE, true ); + bool bFullyOpaque = (nBlendType != BT_BLENDADD) && (nBlendType != BT_BLEND) && !IS_FLAG_SET(MATERIAL_VAR_ALPHATEST); //dest alpha is free for special use + + SHADOW_STATE + { + SetInitialShadowState( ); + if( bRefraction ) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); // Refract + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, g_pHardwareConfig->GetHDRType() == HDR_TYPE_INTEGER || IsOSX() ); + + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); // Base + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER1, true ); + } + + if( bReflection ) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER2, true ); // Reflect + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER2, g_pHardwareConfig->GetHDRType() == HDR_TYPE_INTEGER || IsOSX() ); + + pShaderShadow->EnableTexture( SHADER_SAMPLER3, true ); // Lightmap + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER3, g_pHardwareConfig->GetHDRType() == HDR_TYPE_NONE ); + } + + if( params[BASETEXTURE]->IsTexture() ) + { + // BASETEXTURE + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER1, true ); + + // LIGHTMAP + pShaderShadow->EnableTexture( SHADER_SAMPLER3, true ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER3, g_pHardwareConfig->GetHDRType() == HDR_TYPE_NONE ); + + if ( params[ENVMAPMASK]->IsTexture() ) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER6, true ); + } + } + + // normal map + pShaderShadow->EnableTexture( SHADER_SAMPLER4, true ); + + int fmt = VERTEX_POSITION | VERTEX_NORMAL | VERTEX_TANGENT_S | VERTEX_TANGENT_T; + + // texcoord0 : base texcoord + // texcoord1 : lightmap texcoord + // texcoord2 : lightmap texcoord offset + int numTexCoords = 1; + if( params[BASETEXTURE]->IsTexture() ) + { + numTexCoords = 3; + } + pShaderShadow->VertexShaderVertexFormat( fmt, numTexCoords, 0, 0 ); + + if ( IS_FLAG_SET(MATERIAL_VAR_TRANSLUCENT ) ) + { + EnableAlphaBlending( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA ); + } + + DECLARE_STATIC_VERTEX_SHADER( lightmappedreflective_vs20 ); + SET_STATIC_VERTEX_SHADER_COMBO( BASETEXTURE, params[BASETEXTURE]->IsTexture() ); + SET_STATIC_VERTEX_SHADER( lightmappedreflective_vs20 ); + + // "REFLECT" "0..1" + // "REFRACT" "0..1" + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_STATIC_PIXEL_SHADER( lightmappedreflective_ps20b ); + SET_STATIC_PIXEL_SHADER_COMBO( REFLECT, bReflection ); + SET_STATIC_PIXEL_SHADER_COMBO( REFRACT, bRefraction ); + SET_STATIC_PIXEL_SHADER_COMBO( BASETEXTURE, params[BASETEXTURE]->IsTexture() ); + SET_STATIC_PIXEL_SHADER_COMBO( ENVMAPMASK, params[ENVMAPMASK]->IsTexture() && params[BASETEXTURE]->IsTexture() ); + SET_STATIC_PIXEL_SHADER( lightmappedreflective_ps20b ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( lightmappedreflective_ps20 ); + SET_STATIC_PIXEL_SHADER_COMBO( REFLECT, bReflection ); + SET_STATIC_PIXEL_SHADER_COMBO( REFRACT, bRefraction ); + SET_STATIC_PIXEL_SHADER_COMBO( BASETEXTURE, params[BASETEXTURE]->IsTexture() ); + SET_STATIC_PIXEL_SHADER_COMBO( ENVMAPMASK, params[ENVMAPMASK]->IsTexture() && params[BASETEXTURE]->IsTexture() ); + SET_STATIC_PIXEL_SHADER( lightmappedreflective_ps20 ); + } + + FogToFogColor(); + + if( g_pHardwareConfig->GetHDRType() != HDR_TYPE_NONE ) + { + // we are writing linear values from this shader. + pShaderShadow->EnableSRGBWrite( true ); + } + + pShaderShadow->EnableAlphaWrites( bFullyOpaque ); + } + DYNAMIC_STATE + { + if( bRefraction ) + { + // HDRFIXME: add comment about binding.. Specify the number of MRTs in the enable + BindTexture( SHADER_SAMPLER0, REFRACTTEXTURE, -1 ); + } + if( bReflection ) + { + BindTexture( SHADER_SAMPLER2, REFLECTTEXTURE, -1 ); + } + BindTexture( SHADER_SAMPLER4, NORMALMAP, BUMPFRAME ); + if( params[BASETEXTURE]->IsTexture() ) + { + BindTexture( SHADER_SAMPLER1, BASETEXTURE, FRAME ); + pShaderAPI->BindStandardTexture( SHADER_SAMPLER3, TEXTURE_LIGHTMAP ); + SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_3, BASETEXTURETRANSFORM ); + + if ( params[ENVMAPMASK]->IsTexture() ) + { + BindTexture( SHADER_SAMPLER6, ENVMAPMASK, ENVMAPMASKFRAME ); + } + } + + // Refraction tint + if( bRefraction ) + { + SetPixelShaderConstantGammaToLinear( 1, REFRACTTINT ); + } + // Reflection tint + if( bReflection ) + { + SetPixelShaderConstantGammaToLinear( 4, REFLECTTINT ); + } + + SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_1, BUMPTRANSFORM ); + + float c0[4] = { 1.0f / 3.0f, 1.0f / 3.0f, 1.0f / 3.0f, 0.0f }; + pShaderAPI->SetPixelShaderConstant( 0, c0, 1 ); + + float c2[4] = { 0.5f, 0.5f, 0.5f, 0.5f }; + pShaderAPI->SetPixelShaderConstant( 2, c2, 1 ); + + // fresnel constants + float flFresnelFactor = params[MAXREFLECTIVITY]->GetFloatValue() - params[MINREFLECTIVITY]->GetFloatValue(); + float c3[4] = { flFresnelFactor, params[FRESNELPOWER]->GetFloatValue(), params[MINREFLECTIVITY]->GetFloatValue(), 0.0f }; + pShaderAPI->SetPixelShaderConstant( 3, c3, 1 ); + + float c5[4] = { params[REFLECTAMOUNT]->GetFloatValue(), params[REFLECTAMOUNT]->GetFloatValue(), + params[REFRACTAMOUNT]->GetFloatValue(), params[REFRACTAMOUNT]->GetFloatValue() }; + pShaderAPI->SetPixelShaderConstant( 5, c5, 1 ); + + pShaderAPI->SetPixelShaderFogParams( 8 ); + + DECLARE_DYNAMIC_VERTEX_SHADER( lightmappedreflective_vs20 ); + SET_DYNAMIC_VERTEX_SHADER( lightmappedreflective_vs20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_DYNAMIC_PIXEL_SHADER( lightmappedreflective_ps20b ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( WRITE_DEPTH_TO_DESTALPHA, bFullyOpaque && pShaderAPI->ShouldWriteDepthToDestAlpha() ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + SET_DYNAMIC_PIXEL_SHADER( lightmappedreflective_ps20b ); + } + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( lightmappedreflective_ps20 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + SET_DYNAMIC_PIXEL_SHADER( lightmappedreflective_ps20 ); + } + } + Draw(); + } + + SHADER_DRAW + { + bool bRefraction = params[REFRACTTEXTURE]->IsTexture(); + bool bReflection = params[REFLECTTEXTURE]->IsTexture(); + bool bDrewSomething = false; + if ( bReflection || bRefraction ) + { + bDrewSomething = true; + DrawReflectionRefraction( params, pShaderShadow, pShaderAPI, bReflection, bRefraction ); + } + + if( !bDrewSomething ) + { + // We are likely here because of the tools. . . draw something so that + // we won't go into wireframe-land. + Draw(); + } + } +END_SHADER + diff --git a/materialsystem/stdshaders/lightmappedreflective_ps2x.fxc b/materialsystem/stdshaders/lightmappedreflective_ps2x.fxc new file mode 100644 index 0000000..b323ae7 --- /dev/null +++ b/materialsystem/stdshaders/lightmappedreflective_ps2x.fxc @@ -0,0 +1,190 @@ +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX] +// STATIC: "BASETEXTURE" "0..1" +// STATIC: "REFLECT" "0..1" +// STATIC: "REFRACT" "0..1" +// STATIC: "ENVMAPMASK" "0..1" + +// DYNAMIC: "PIXELFOGTYPE" "0..1" +// DYNAMIC: "WRITE_DEPTH_TO_DESTALPHA" "0..1" [ps20b] [PC] +// DYNAMIC: "WRITE_DEPTH_TO_DESTALPHA" "0..0" [ps20b] [XBOX] + +#if defined( SHADER_MODEL_PS_2_0 ) +# define WRITE_DEPTH_TO_DESTALPHA 0 +#endif + +#include "common_ps_fxc.h" + +sampler RefractSampler : register( s0 ); +sampler BaseTextureSampler : register( s1 ); +sampler ReflectSampler : register( s2 ); +#if BASETEXTURE +sampler LightmapSampler : register( s3 ); +#endif +#if ENVMAPMASK +sampler EnvMapMaskSampler : register( s6 ); +#endif +sampler NormalSampler : register( s4 ); + +const HALF4 vRefractTint : register( c1 ); +const float4 g_FresnelConstants : register( c3 ); +const HALF4 vReflectTint : register( c4 ); +const float4 g_ReflectRefractScale : register( c5 ); // xy - reflect scale, zw - refract scale + +const float4 g_PixelFogParams : register( c8 ); + + +static const bool g_bReflect = REFLECT ? true : false; +static const bool g_bRefract = REFRACT ? true : false; + +struct PS_INPUT +{ + float4 vBumpTexCoordXY_vTexCoordXY : TEXCOORD0; + half3 vTangentEyeVect : TEXCOORD1; + float4 vReflectXY_vRefractYX : TEXCOORD2; + float W : TEXCOORD3; + float4 vProjPos : TEXCOORD4; + float screenCoord : TEXCOORD5; +#if BASETEXTURE +// CENTROID: TEXCOORD6 + HALF4 lightmapTexCoord1And2 : TEXCOORD6; +// CENTROID: TEXCOORD7 + HALF4 lightmapTexCoord3 : TEXCOORD7; +#endif + + float4 fogFactorW : COLOR1; +}; + +float4 main( PS_INPUT i ) : COLOR +{ + // Load normal and expand range + HALF4 vNormalSample = tex2D( NormalSampler, i.vBumpTexCoordXY_vTexCoordXY.xy ); + HALF3 vNormal = normalize( vNormalSample * 2.0 - 1.0 ); + + // Perform division by W only once + float ooW = 1.0f / i.W; + + float2 unwarpedRefractTexCoord = i.vReflectXY_vRefractYX.wz * ooW; + + float4 reflectRefractScale = g_ReflectRefractScale; + + // Compute coordinates for sampling Reflection + float2 vReflectTexCoord; + float2 vRefractTexCoord; + + // vectorize the dependent UV calculations (reflect = .xy, refract = .wz) +#ifdef NV3X + float4 vDependentTexCoords = vNormal.xyxy * vNormalSample.a * reflectRefractScale; +#else + float4 vN; + vN.xy = vNormal.xy; + vN.w = vNormal.x; + vN.z = vNormal.y; + float4 vDependentTexCoords = vN * vNormalSample.a * reflectRefractScale; +#endif + + vDependentTexCoords += ( i.vReflectXY_vRefractYX * ooW ); + vReflectTexCoord = vDependentTexCoords.xy; + vRefractTexCoord = vDependentTexCoords.wz; + + // Sample reflection and refraction + HALF4 vReflectColor = tex2D( ReflectSampler, vReflectTexCoord ); + HALF4 vRefractColor = tex2D( RefractSampler, vRefractTexCoord ); + vReflectColor *= vReflectTint; + vRefractColor *= vRefractTint; + + half3 vEyeVect; + vEyeVect = normalize( i.vTangentEyeVect ); + + // Fresnel term + HALF fNdotV = saturate( dot( vEyeVect, vNormal ) ); + HALF fFresnelScalar = g_FresnelConstants.x * pow( 1.0 - fNdotV, g_FresnelConstants.y ) + g_FresnelConstants.z; + HALF4 fFresnel = HALF4( fFresnelScalar, fFresnelScalar, fFresnelScalar, fFresnelScalar ); + +#if BASETEXTURE + float4 baseSample = tex2D( BaseTextureSampler, i.vBumpTexCoordXY_vTexCoordXY.zw ); + HALF2 bumpCoord1; + HALF2 bumpCoord2; + HALF2 bumpCoord3; + ComputeBumpedLightmapCoordinates( i.lightmapTexCoord1And2, i.lightmapTexCoord3.xy, + bumpCoord1, bumpCoord2, bumpCoord3 ); + + HALF4 lightmapSample1 = tex2D( LightmapSampler, bumpCoord1 ); + HALF3 lightmapColor1 = lightmapSample1.rgb; + HALF3 lightmapColor2 = tex2D( LightmapSampler, bumpCoord2 ); + HALF3 lightmapColor3 = tex2D( LightmapSampler, bumpCoord3 ); + + float3 dp; + dp.x = saturate( dot( vNormal, bumpBasis[0] ) ); + dp.y = saturate( dot( vNormal, bumpBasis[1] ) ); + dp.z = saturate( dot( vNormal, bumpBasis[2] ) ); + dp *= dp; + + float3 diffuseLighting = dp.x * lightmapColor1 + + dp.y * lightmapColor2 + + dp.z * lightmapColor3; + float sum = dot( dp, float3( 1.0f, 1.0f, 1.0f ) ); + diffuseLighting *= LIGHT_MAP_SCALE / sum; + HALF3 diffuseComponent = baseSample.rgb * diffuseLighting; +#endif + + float4 flMask; +#if ENVMAPMASK + flMask = tex2D( EnvMapMaskSampler, i.vBumpTexCoordXY_vTexCoordXY.zw ); +#else + flMask = float4( 1.0f, 1.0f, 1.0f, 1.0f ); +#endif + + // NOTE: the BASETEXTURE path hasn't been tested (or really written for that matter, just copied from water) + // What I think should happen is that the alpha of base texture should be its 'translucency' + // which should indicate how much refraction to use. + // We should add an envmapmask to deal with how much reflection to use + // along with all the focus, etc. features + float4 result; + float flAlpha = 1.0f; + if( g_bReflect && g_bRefract ) + { + result = lerp( vRefractColor, vReflectColor, fFresnel ) * flMask; +#if BASETEXTURE + result += float4( diffuseComponent, 1.0f ); + flAlpha = baseSample.a; +#endif + } + else if( g_bReflect ) + { +#if BASETEXTURE + result = float4( diffuseComponent, 1.0f ) + vReflectColor * flMask; + flAlpha = baseSample.a; +#else + result = vReflectColor; +#endif + } + else if( g_bRefract ) + { +#if BASETEXTURE + result = float4( diffuseComponent, 1.0f ) + vRefractColor * flMask; + flAlpha = baseSample.a; +#else + result = vRefractColor; +#endif + } + else + { +#if BASETEXTURE + result = float4( diffuseComponent, 1.0f ); + flAlpha = baseSample.a; +#else + result = float4( 0.0f, 0.0f, 0.0f, 0.0f ); +#endif + } + + +#if ( PIXELFOGTYPE == PIXEL_FOG_TYPE_RANGE ) + float fogFactor = CalcRangeFog( i.vProjPos.z, g_PixelFogParams.x, g_PixelFogParams.z, g_PixelFogParams.w ); +#else + float fogFactor = 0; +#endif + + return FinalOutput( float4( result.rgb, flAlpha ), fogFactor, PIXELFOGTYPE, TONEMAP_SCALE_NONE, (WRITE_DEPTH_TO_DESTALPHA != 0), i.vProjPos.z ); +} + diff --git a/materialsystem/stdshaders/lightmappedreflective_vs20.fxc b/materialsystem/stdshaders/lightmappedreflective_vs20.fxc new file mode 100644 index 0000000..b5a37b1 --- /dev/null +++ b/materialsystem/stdshaders/lightmappedreflective_vs20.fxc @@ -0,0 +1,106 @@ +// STATIC: "BASETEXTURE" "0..1" + +#include "common_vs_fxc.h" + +const float4 cBumpTexCoordTransform[2] : register( SHADER_SPECIFIC_CONST_1 ); +const float4 cBaseTextureTransform[2] : register( SHADER_SPECIFIC_CONST_3 ); + +struct VS_INPUT +{ + float4 vPos : POSITION; + float4 vNormal : NORMAL; + float4 vBaseTexCoord : TEXCOORD0; + float2 vLightmapTexCoord : TEXCOORD1; + float2 vLightmapTexCoordOffset : TEXCOORD2; + float3 vTangentS : TANGENT; + float3 vTangentT : BINORMAL0; +}; + +struct VS_OUTPUT +{ + float4 vProjPos_POSITION : POSITION; + float vFog : FOG; + float4 vBumpTexCoordXY_vTexCoordXY : TEXCOORD0; + float3 vTangentEyeVect : TEXCOORD1; + float4 vReflectXY_vRefractYX : TEXCOORD2; + float W : TEXCOORD3; + float4 vProjPos : TEXCOORD4; + float screenCoord : TEXCOORD5; +#if BASETEXTURE + HALF4 lightmapTexCoord1And2 : TEXCOORD6; + HALF4 lightmapTexCoord3 : TEXCOORD7; +#endif + float4 fogFactorW : COLOR1; +}; + +VS_OUTPUT main( const VS_INPUT v ) +{ + VS_OUTPUT o = ( VS_OUTPUT )0; + + float3 vObjNormal; + DecompressVertex_Normal( v.vNormal, vObjNormal ); + + // Projected position + float4 vProjPos = mul( v.vPos, cModelViewProj ); + o.vProjPos = o.vProjPos_POSITION = vProjPos; + + // Project tangent basis + float2 vProjTangentS = mul( v.vTangentS, cViewProj ); + float2 vProjTangentT = mul( v.vTangentT, cViewProj ); + + // Map projected position to the reflection texture + float2 vReflectPos; + vReflectPos.x = -vProjPos.x; + vReflectPos.y = -vProjPos.y; // invert Y + vReflectPos = (vReflectPos + vProjPos.w) * 0.5f; + + // Map projected position to the refraction texture + float2 vRefractPos; + vRefractPos.x = vProjPos.x; + vRefractPos.y = -vProjPos.y; // invert Y + vRefractPos = (vRefractPos + vProjPos.w) * 0.5f; + + // Reflection transform + o.vReflectXY_vRefractYX = float4( vReflectPos.x, vReflectPos.y, vRefractPos.y, vRefractPos.x ); + o.W = vProjPos.w; + + o.screenCoord = vProjPos.x; + + // Compute fog based on the position + float3 vWorldPos = mul( v.vPos, cModel[0] ); + o.fogFactorW = o.vFog = CalcFog( vWorldPos, vProjPos, FOGTYPE_RANGE ); + + // Eye vector + float3 vWorldEyeVect = cEyePos - vWorldPos; + // Transform to the tangent space + o.vTangentEyeVect.x = dot( vWorldEyeVect, v.vTangentS ); + o.vTangentEyeVect.y = dot( vWorldEyeVect, v.vTangentT ); + o.vTangentEyeVect.z = dot( vWorldEyeVect, vObjNormal ); + + // Tranform bump coordinates + o.vBumpTexCoordXY_vTexCoordXY.x = dot( v.vBaseTexCoord, cBumpTexCoordTransform[0] ); + o.vBumpTexCoordXY_vTexCoordXY.y = dot( v.vBaseTexCoord, cBumpTexCoordTransform[1] ); + +#if BASETEXTURE + o.vBumpTexCoordXY_vTexCoordXY.z = dot( v.vBaseTexCoord, cBaseTextureTransform[0] ); + o.vBumpTexCoordXY_vTexCoordXY.w = dot( v.vBaseTexCoord, cBaseTextureTransform[1] ); + + o.lightmapTexCoord1And2.xy = v.vLightmapTexCoord + v.vLightmapTexCoordOffset; + + float2 lightmapTexCoord2 = o.lightmapTexCoord1And2.xy + v.vLightmapTexCoordOffset; + float2 lightmapTexCoord3 = lightmapTexCoord2 + v.vLightmapTexCoordOffset; + + // reversed component order + o.lightmapTexCoord1And2.w = lightmapTexCoord2.x; + o.lightmapTexCoord1And2.z = lightmapTexCoord2.y; + + o.lightmapTexCoord3.xy = lightmapTexCoord3; +#else + o.vBumpTexCoordXY_vTexCoordXY.z = 0.0f; + o.vBumpTexCoordXY_vTexCoordXY.w = 0.0f; +#endif + + return o; +} + + diff --git a/materialsystem/stdshaders/lightmappedtexture.psh b/materialsystem/stdshaders/lightmappedtexture.psh new file mode 100644 index 0000000..b9d585f --- /dev/null +++ b/materialsystem/stdshaders/lightmappedtexture.psh @@ -0,0 +1,17 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; Draw a alpha blended, translucent (alpha in texture) texture. +; t0 - texture +; +; c0 - overbright value +; +; The texture coordinates need to be defined as follows: +; tc0 - texcoords +;------------------------------------------------------------------------------ + +; Get the color from the texture +tex t0 +tex t1 +mul r0.rgb, t0, t1 ; base * lightmap +mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2) diff --git a/materialsystem/stdshaders/lightmappedtwotexture.cpp b/materialsystem/stdshaders/lightmappedtwotexture.cpp new file mode 100644 index 0000000..dbafede --- /dev/null +++ b/materialsystem/stdshaders/lightmappedtwotexture.cpp @@ -0,0 +1,186 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: Lightmap only shader +// +// $Header: $ +// $NoKeywords: $ +//=============================================================================// + +#include "shaderlib/cshader.h" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +// FIXME!! Need to make dx9 version so that "CENTROID" flags can be added! +BEGIN_SHADER( LightmappedTwoTexture, + "Help for LightmappedTwoTexture" ) + + BEGIN_SHADER_PARAMS + SHADER_PARAM( DETAIL, SHADER_PARAM_TYPE_TEXTURE, "shadertest/Detail", "detail" ) + SHADER_PARAM( DETAILSCALE, SHADER_PARAM_TYPE_FLOAT, "1", "detail scale" ) + SHADER_PARAM( ENVMAP, SHADER_PARAM_TYPE_TEXTURE, "shadertest/shadertest_env", "envmap" ) + SHADER_PARAM( ENVMAPFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "Frame for animated envmap" ) + SHADER_PARAM( ENVMAPMASK, SHADER_PARAM_TYPE_TEXTURE, "shadertest/shadertest_envmask", "envmap mask" ) + SHADER_PARAM( ENVMAPMASKFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "" ) + SHADER_PARAM( ENVMAPMASKSCALE, SHADER_PARAM_TYPE_FLOAT, "1", "envmap mask scale" ) + SHADER_PARAM( ENVMAPTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "envmap tint" ) + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + SET_FLAGS2( MATERIAL_VAR2_LIGHTING_LIGHTMAP ); + if( !params[ENVMAPMASKSCALE]->IsDefined() ) + params[ENVMAPMASKSCALE]->SetFloatValue( 1.0f ); + + if( !params[DETAILSCALE]->IsDefined() ) + params[DETAILSCALE]->SetFloatValue( 1.0f ); + + if( !params[ENVMAPTINT]->IsDefined() ) + params[ENVMAPTINT]->SetVecValue( 1.0f, 1.0f, 1.0f ); + + // No texture means no self-illum or env mask in base alpha + if ( !params[BASETEXTURE]->IsDefined() ) + { + CLEAR_FLAGS( MATERIAL_VAR_BASEALPHAENVMAPMASK ); + } + + // If in decal mode, no debug override... + if (IS_FLAG_SET(MATERIAL_VAR_DECAL)) + { + SET_FLAGS( MATERIAL_VAR_NO_DEBUG_OVERRIDE ); + } + } + + SHADER_INIT + { + if (params[BASETEXTURE]->IsDefined()) + { + LoadTexture( BASETEXTURE ); + + if (!params[BASETEXTURE]->GetTextureValue()->IsTranslucent()) + { + if (IS_FLAG_SET(MATERIAL_VAR_BASEALPHAENVMAPMASK)) + CLEAR_FLAGS( MATERIAL_VAR_BASEALPHAENVMAPMASK ); + } + } + + if (params[DETAIL]->IsDefined()) + { + LoadTexture( DETAIL ); + } + + // Don't alpha test if the alpha channel is used for other purposes + if (IS_FLAG_SET(MATERIAL_VAR_BASEALPHAENVMAPMASK) ) + CLEAR_FLAGS( MATERIAL_VAR_ALPHATEST ); + + if (params[ENVMAP]->IsDefined()) + { + if( !IS_FLAG_SET(MATERIAL_VAR_ENVMAPSPHERE) ) + LoadCubeMap( ENVMAP ); + else + LoadTexture( ENVMAP ); + + if( !g_pHardwareConfig->SupportsCubeMaps() ) + { + SET_FLAGS( MATERIAL_VAR_ENVMAPSPHERE ); + } + + if (params[ENVMAPMASK]->IsDefined()) + LoadTexture( ENVMAPMASK ); + } + } + + SHADER_FALLBACK + { + // The only thing we can't do here is masked env-mapped + if (g_pHardwareConfig->GetSamplerCount() < 2) + { + return "LightmappedTwoTexture_DX5"; + } + return 0; + } + + /* + // FIXME: I didn't remove this because it's modulating against the detail alpha! + // This seems very strange and isn't what FixedFunctionBaseTimesDetailPass does. + // Should it!?!? If so, I want to move this to the FixedFunctionBaseTimesDetailPass. + + void DrawBaseTimesDetail( IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow ) + { + // Base + SHADOW_STATE + { + // alpha test + pShaderShadow->EnableAlphaTest( IS_FLAG_SET(MATERIAL_VAR_ALPHATEST) ); + + // Alpha blending, enable alpha blending if the detail texture is translucent + bool detailIsTranslucent = TextureIsTranslucent( DETAIL, false ); + if ( detailIsTranslucent ) + { + 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 + { + SetDefaultBlendingShadowState( BASETEXTURE, true ); + } + + // independently configure alpha and color + pShaderShadow->EnableAlphaPipe( true ); + + // Here's the color states (NOTE: SHADER_DRAW_COLOR == use Vertex Color) + pShaderShadow->EnableConstantColor( IsColorModulating() ); + pShaderShadow->EnableTexture( SHADER_TEXTURE_STAGE0, true ); + pShaderShadow->EnableTexture( SHADER_TEXTURE_STAGE1, true ); + + // Here's the alpha states + pShaderShadow->EnableConstantAlpha( IsAlphaModulating() ); + pShaderShadow->EnableVertexAlpha( IS_FLAG_SET(MATERIAL_VAR_VERTEXALPHA) ); + pShaderShadow->EnableTextureAlpha( SHADER_TEXTURE_STAGE0, TextureIsTranslucent(BASETEXTURE, true) ); + pShaderShadow->EnableTextureAlpha( SHADER_TEXTURE_STAGE1, detailIsTranslucent ); + + int flags = SHADER_DRAW_POSITION | SHADER_DRAW_TEXCOORD0 | SHADER_DRAW_SECONDARY_TEXCOORD1; + if (IS_FLAG_SET(MATERIAL_VAR_VERTEXCOLOR)) + flags |= SHADER_DRAW_COLOR; + pShaderShadow->DrawFlags( flags ); + DefaultFog(); + } + DYNAMIC_STATE + { + SetFixedFunctionTextureTransform( MATERIAL_TEXTURE0, BASETEXTURETRANSFORM ); + SetFixedFunctionTextureScale( MATERIAL_TEXTURE1, DETAILSCALE ); + BindTexture( SHADER_TEXTURE_STAGE0, BASETEXTURE, FRAME ); + BindTexture( SHADER_TEXTURE_STAGE1, DETAIL ); + SetModulationDynamicState(); + } + Draw(); + + SHADOW_STATE + { + pShaderShadow->EnableAlphaPipe( false ); + } + } + */ + + SHADER_DRAW + { + // Pass 1 : Base + detail + FixedFunctionBaseTimesDetailPass( + BASETEXTURE, FRAME, BASETEXTURETRANSFORM, DETAIL, DETAILSCALE ); + + // Pass 2 : * lightmap + FixedFunctionMultiplyByLightmapPass( BASETEXTURE, FRAME, BASETEXTURETRANSFORM ); + + // Pass 3 : + env + bool envDefined = params[ENVMAP]->IsTexture(); + if (envDefined) + { + FixedFunctionAdditiveMaskedEnvmapPass( + ENVMAP, ENVMAPMASK, BASETEXTURE, + ENVMAPFRAME, ENVMAPMASKFRAME, FRAME, + BASETEXTURETRANSFORM, ENVMAPMASKSCALE, ENVMAPTINT ); + } + } +END_SHADER diff --git a/materialsystem/stdshaders/lpreview1_ps2x.fxc b/materialsystem/stdshaders/lpreview1_ps2x.fxc new file mode 100644 index 0000000..e7a1009 --- /dev/null +++ b/materialsystem/stdshaders/lpreview1_ps2x.fxc @@ -0,0 +1,69 @@ +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX] + +#define HDRTYPE HDR_TYPE_NONE +#define HDRENABLED 0 +#include "common_ps_fxc.h" + +sampler AlbedoSampler : register( s0 ); +sampler NormalSampler : register( s1 ); +sampler PositionSampler : register( s2 ); +sampler AccBuf_In : register( s3 ); + +float4 EyePosition : register (c10); + +float4 Light_origin : register( c0 ); +#define INNER_COS (Light_origin.w) +#define OUTER_COS (Light_dir.w) + +float4 Light_dir : register( c1 ); + +float4 Light_attn : register (c2); +#define QUADRATIC_ATTN (Light_attn.x) +#define LINEAR_ATTN (Light_attn.y) +#define CONSTANT_ATTN (Light_attn.z) +#define SCALE_FACTOR (Light_attn.w) + +float3 Light_color: register(c3); + +struct PS_INPUT +{ + float2 texCoord : TEXCOORD0; +}; + + +float Lerp5(float f1, float f2, float i1, float i2, float x) +{ + return f1+(f2-f1)*(x-i1)/(i2-i1); +} + +float4 main( PS_INPUT i ) : COLOR +{ + float4 normal=tex2D( NormalSampler, i.texCoord ); + float4 albedo=tex2D( AlbedoSampler, i.texCoord ); + float4 pos=tex2D( PositionSampler, i.texCoord ); + float3 old_acc=tex2D( AccBuf_In, i.texCoord ); +// pos.xyz+=EyePosition.xyz; + + float3 ldir=Light_origin.xyz-pos.xyz; + float dist=sqrt(dot(ldir,ldir)); + ldir=normalize(ldir); + float spot_dot=dot(ldir,-Light_dir); + float3 ret=Light_color*0.09*albedo.xyz; // ambient + float dist_falloff=(SCALE_FACTOR/(QUADRATIC_ATTN*dist*dist+LINEAR_ATTN*dist+CONSTANT_ATTN)); + if (spot_dot>OUTER_COS) + { + float falloff=1; + if (spot_dotNeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX] + +#define HDRTYPE HDR_TYPE_NONE +#define HDRENABLED 0 +#include "common_ps_fxc.h" + +sampler InputTexture : register( s0 ); +sampler Albedo : register( s1 ); +sampler Flags : register( s2 ); + +struct PS_INPUT +{ + float2 texCoord : TEXCOORD0; +}; + + +float4 main( PS_INPUT i ) : COLOR +{ + float3 flags_check=tex2D( Flags, i.texCoord ); + float3 input=tex2D( InputTexture, i.texCoord ); + float3 albedo=tex2D( Albedo, i.texCoord ); + input=lerp(albedo,input,flags_check.r); + return FinalOutput( float4(input.xyz,1), 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE ); +} diff --git a/materialsystem/stdshaders/luminance_compare_ps2x.fxc b/materialsystem/stdshaders/luminance_compare_ps2x.fxc new file mode 100644 index 0000000..20b3bc6 --- /dev/null +++ b/materialsystem/stdshaders/luminance_compare_ps2x.fxc @@ -0,0 +1,51 @@ +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX] + +#define HDRTYPE HDR_TYPE_NONE +#include "common_ps_fxc.h" + +// This pixel shader compares the luminance against a constant value and retruns all 1's when greater + +sampler TexSampler : register( s0 ); + +struct PS_INPUT +{ + float2 uv0 : TEXCOORD0; + +#if defined( _X360 ) //matching pixel shader inputs to vertex shader outputs to avoid shader patches + float2 ZeroTexCoord : TEXCOORD1; + float2 bloomTexCoord : TEXCOORD2; +#endif +}; + +float3 g_vComparisonMinMaxScale : register( c0 ); +#define g_flComparisonMin g_vComparisonMinMaxScale.x +#define g_flComparisonMax g_vComparisonMinMaxScale.y +#define g_flComparisonScale g_vComparisonMinMaxScale.z + +struct PS_OUTPUT +{ + float4 color : COLOR0; + float depth : DEPTH; +}; + +PS_OUTPUT main( PS_INPUT i ) +{ + float3 color = tex2D( TexSampler, i.uv0 ) * g_flComparisonScale; + + // Formula for calculating luminance based on NTSC standard + float3 tmpv = { 0.2125f, 0.7154f, 0.0721f }; + float flLuminance = dot( color.rgb, tmpv.rgb ); + + // Alternate formula for calculating luminance for linear RGB space (Widely used in color hue and saturation computations) + //float3 tmpv = { 0.3086f, 0.6094f, 0.0820f }; + //float flLuminance = dot( color.rgb, tmpv.rgb ); + + // Simple average + //float flLuminance = ( color.r + color.g + color.b ) * 0.33333f; + + PS_OUTPUT o; + o.color.rgba = step( g_flComparisonMin, flLuminance ) * step( flLuminance, g_flComparisonMax ); + o.depth = 0.0f; + return o; +} diff --git a/materialsystem/stdshaders/macros.vsh b/materialsystem/stdshaders/macros.vsh new file mode 100644 index 0000000..d1116e5 --- /dev/null +++ b/materialsystem/stdshaders/macros.vsh @@ -0,0 +1,1393 @@ +;------------------------------------ +; RULES FOR AUTHORING VERTEX SHADERS: +;------------------------------------ +; - never use "def" . . .set constants in code instead. . our constant shadowing will break otherwise. +; (same goes for pixel shaders) +; - use cN notation instead of c[N] notation. .makes grepping for registers easier. +; The only exception is c[a0.x+blah] where you have no choice. +$g_NumRegisters = 12; + +; NOTE: These must match the same values in vsh_prep.pl! +$vPos = "v0"; +$vBoneWeights = "v1"; +$vBoneIndices = "v2"; +$vNormal = "v3"; +$vColor = "v5"; +$vSpecular = "v6"; +$vTexCoord0 = "v7"; +$vTexCoord1 = "v8"; +$vTexCoord2 = "v9"; +$vTexCoord3 = "v10"; +$vTangentS = "v11"; +$vTangentT = "v12"; +$vUserData = "v14"; + +if( $g_dx9 ) +{ + if( $g_usesPos ) + { + dcl_position $vPos; + } + + if( $g_usesBoneWeights ) + { + dcl_blendweight $vBoneWeights; + } + if( $g_usesBoneIndices ) + { + dcl_blendindices $vBoneIndices; + } + if( $g_usesNormal ) + { + dcl_normal $vNormal; + } + if( $g_usesColor ) + { + dcl_color0 $vColor; + } + if( $g_usesSpecular ) + { + dcl_color1 $vSpecular; + } + if( $g_usesTexCoord0 ) + { + dcl_texcoord0 $vTexCoord0; + } + if( $g_usesTexCoord1 ) + { + dcl_texcoord1 $vTexCoord1; + } + if( $g_usesTexCoord2 ) + { + dcl_texcoord2 $vTexCoord2; + } + if( $g_usesTexCoord3 ) + { + dcl_texcoord3 $vTexCoord3; + } + if( $g_usesTangentS ) + { + dcl_tangent $vTangentS; + } + if( $g_usesTangentT ) + { + dcl_binormal0 $vTangentT; + } + if( $g_usesUserData ) + { + dcl_tangent $vUserData; + } +} + +# NOTE: These should match g_LightCombinations in vertexshaderdx8.cpp! +# NOTE: Leave this on single lines or shit might blow up. +@g_staticLightTypeArray = ( "none", "static", "none", "none", "none", "none", "none", "none", "none", "none", "none", "none", "static", "static", "static", "static", "static", "static", "static", "static", "static", "static" ); +@g_ambientLightTypeArray = ( "none", "none", "ambient", "ambient", "ambient", "ambient", "ambient", "ambient", "ambient", "ambient", "ambient", "ambient", "ambient", "ambient", "ambient", "ambient", "ambient", "ambient", "ambient", "ambient", "ambient", "ambient" ); +@g_localLightType1Array = ( "none", "none", "none", "spot", "point", "directional", "spot", "spot", "spot", "point", "point", "directional", "none", "spot", "point", "directional", "spot", "spot", "spot", "point", "point", "directional" ); +@g_localLightType2Array = ( "none", "none", "none", "none", "none", "none", "spot", "point", "directional", "point", "directional", "directional", "none", "none", "none", "none", "spot", "point", "directional", "point", "directional", "directional" ); + +$cConstants0 = "c0"; +$cZero = "c0.x"; +$cOne = "c0.y"; +$cTwo = "c0.z"; +$cHalf = "c0.w"; + +$cConstants1 = "c1"; +$cOOGamma = "c1.x"; # 1/2.2 +$cOtherOverbrightFactor = "c1.y"; # overbright +$cOneThird = "c1.z"; # 1/3 +$cOverbrightFactor = "c1.w"; # 1/overbright + +$cEyePos = "c2"; +$cWaterZ = "c2.w"; +$cEyePosWaterZ = "c2"; + +$cLightIndex = "c3"; +$cLight0Offset = "c3.x"; # 27 +$cLight1Offset = "c3.y"; # 32 +$cColorToIntScale = "c3.z"; # matrix array offset = 3.0f * 255.0f + 0.01 (epsilon ensures floor yields desired result) +$cModel0Index = "c3.w"; # base for start of skinning matrices + +; NOTE: These must match the same values in vsh_prep.pl! +$cModelViewProj0 = "c4"; +$cModelViewProj1 = "c5"; +$cModelViewProj2 = "c6"; +$cModelViewProj3 = "c7"; + +$cViewProj0 = "c8"; +$cViewProj1 = "c9"; +$cViewProj2 = "c10"; +$cViewProj3 = "c11"; + +; currently unused +; c12, c13 + +$SHADER_SPECIFIC_CONST_10 = "c14"; +$SHADER_SPECIFIC_CONST_11 = "c15"; + +$cFogParams = "c16"; +$cFogEndOverFogRange = "c16.x"; +$cFogOne = "c16.y"; +$cFogMaxDensity = "c16.z"; +$cOOFogRange = "c16.w"; # (1/(fogEnd-fogStart)) + +$cViewModel0 = "c17"; +$cViewModel1 = "c18"; +$cViewModel2 = "c19"; +$cViewModel3 = "c20"; + +$cAmbientColorPosX = "c21"; +$cAmbientColorNegX = "c22"; +$cAmbientColorPosY = "c23"; +$cAmbientColorNegY = "c24"; +$cAmbientColorPosZ = "c25"; +$cAmbientColorNegZ = "c26"; + +$cAmbientColorPosXOffset = "21"; +$cAmbientColorPosYOffset = "23"; +$cAmbientColorPosZOffset = "25"; + +$cLight0DiffColor = "c27"; +$cLight0Dir = "c28"; +$cLight0Pos = "c29"; +$cLight0SpotParams = "c30"; # [ exponent, stopdot, stopdot2, 1 / (stopdot - stopdot2) +$cLight0Atten = "c31"; # [ constant, linear, quadratic, 0.0f ] + +$cLight1DiffColor = "c32"; +$cLight1Dir = "c33"; +$cLight1Pos = "c34"; +$cLight1SpotParams = "c35"; # [ exponent, stopdot, stopdot2, 1 / (stopdot - stopdot2) +$cLight1Atten = "c36"; # [ constant, linear, quadratic, 0.0f ] + +$cModulationColor = "c37"; + +$SHADER_SPECIFIC_CONST_0 = "c38"; +$SHADER_SPECIFIC_CONST_1 = "c39"; +$SHADER_SPECIFIC_CONST_2 = "c40"; +$SHADER_SPECIFIC_CONST_3 = "c41"; +$SHADER_SPECIFIC_CONST_4 = "c42"; +$SHADER_SPECIFIC_CONST_5 = "c43"; +$SHADER_SPECIFIC_CONST_6 = "c44"; +$SHADER_SPECIFIC_CONST_7 = "c45"; +$SHADER_SPECIFIC_CONST_8 = "c46"; +$SHADER_SPECIFIC_CONST_9 = "c47"; +; $SHADER_SPECIFIC_CONST_10 is c14 +; $SHADER_SPECIFIC_CONST_11 is c15 + +; There are 16 model matrices for skinning +; NOTE: These must match the same values in vsh_prep.pl! +$cModel0 = "c48"; +$cModel1 = "c49"; +$cModel2 = "c50"; + +sub OutputUsedRegisters +{ + local( $i ); + ; USED REGISTERS + for( $i = 0; $i < $g_NumRegisters; $i++ ) + { + if( $g_allocated[$i] ) + { + ; $g_allocatedname[$i] = r$i + } + } + ; +} + +sub AllocateRegister +{ + local( *reg ) = shift; + local( $regname ) = shift; + local( $i ); + for( $i = 0; $i < $g_NumRegisters; $i++ ) + { + if( !$g_allocated[$i] ) + { + $g_allocated[$i] = 1; + $g_allocatedname[$i] = $regname; + ; AllocateRegister $regname = r$i + $reg = "r$i"; + &OutputUsedRegisters(); + return; + } + } + ; Out of registers allocating $regname! + $reg = "rERROR_OUT_OF_REGISTERS"; + &OutputUsedRegisters(); +} + +; pass in a reference to a var that contains a register. . ie \$var where var will constain "r1", etc +sub FreeRegister +{ + local( *reg ) = shift; + local( $regname ) = shift; + ; FreeRegister $regname = $reg + if( $reg =~ m/rERROR_DEALLOCATED/ ) + { + ; $regname already deallocated + ; $reg = "rALREADY_DEALLOCATED"; + &OutputUsedRegisters(); + return; + } +; if( $regname ne g_allocatedname[$reg] ) +; { +; ; Error freeing $reg +; mov compileerror, freed unallocated register $regname +; } + + if( ( $reg =~ m/r(.*)/ ) ) + { + $g_allocated[$1] = 0; + } + $reg = "rERROR_DEALLOCATED"; + &OutputUsedRegisters(); +} + +sub CheckUnfreedRegisters() +{ + local( $i ); + for( $i = 0; $i < $g_NumRegisters; $i++ ) + { + if( $g_allocated[$i] ) + { + print "ERROR: r$i allocated to $g_allocatedname[$i] at end of program\n"; + $g_allocated[$i] = 0; + } + } +} + +sub Normalize +{ + local( $r ) = shift; + dp3 $r.w, $r, $r + rsq $r.w, $r.w + mul $r, $r, $r.w +} + +sub Cross +{ + local( $result ) = shift; + local( $a ) = shift; + local( $b ) = shift; + + mul $result.xyz, $a.yzx, $b.zxy + mad $result.xyz, -$b.yzx, $a.zxy, $result +} + +sub RangeFog +{ + local( $projPos ) = shift; + + ;------------------------------ + ; Regular range fog + ;------------------------------ + + ; oFog.x = 1.0f = no fog + ; oFog.x = 0.0f = full fog + ; compute fog factor f = (fog_end - dist)*(1/(fog_end-fog_start)) + ; this is == to: (fog_end/(fog_end-fog_start) - dist/(fog_end-fog_start) + ; which can be expressed with a single mad instruction! + + ; Compute |projPos| + local( $tmp ); + &AllocateRegister( \$tmp ); + dp3 $tmp.x, $projPos.xyw, $projPos.xyw + rsq $tmp.x, $tmp.x + rcp $tmp.x, $tmp.x + + if( $g_dx9 ) + { + mad $tmp, -$tmp.x, $cOOFogRange, $cFogEndOverFogRange + min $tmp, $tmp, $cOne + max oFog, $tmp.x, $cFogMaxDensity + } + else + { + mad $tmp, -$tmp.x, $cOOFogRange, $cFogEndOverFogRange + min $tmp, $tmp, $cOne + max oFog.x, $tmp.x, $cFogMaxDensity + } + &FreeRegister( \$tmp ); +} + +sub DepthFog +{ + local( $projPos ) = shift; + local( $dest ) = shift; + + if ( $dest eq "" ) + { + $dest = "oFog"; + } + + ;------------------------------ + ; Regular range fog + ;------------------------------ + + ; oFog.x = 1.0f = no fog + ; oFog.x = 0.0f = full fog + ; compute fog factor f = (fog_end - dist)*(1/(fog_end-fog_start)) + ; this is == to: (fog_end/(fog_end-fog_start) - dist/(fog_end-fog_start) + ; which can be expressed with a single mad instruction! + + ; Compute |projPos| + local( $tmp ); + &AllocateRegister( \$tmp ); + + if( $g_dx9 ) + { + mad $tmp, -$projPos.w, $cOOFogRange, $cFogEndOverFogRange + min $tmp, $tmp, $cOne + max $dest, $tmp.x, $cFogMaxDensity + } + else + { + mad $tmp, -$projPos.w, $cOOFogRange, $cFogEndOverFogRange + min $tmp, $tmp, $cOne + max $dest.x, $tmp.x, $cFogMaxDensity + } + + &FreeRegister( \$tmp ); +} + +sub WaterRangeFog +{ + ; oFog.x = 1.0f = no fog + ; oFog.x = 0.0f = full fog + + ; only $worldPos.z is used out of worldPos + local( $worldPos ) = shift; + local( $projPos ) = shift; + + local( $tmp ); + &AllocateRegister( \$tmp ); + + ; This is simple similar triangles. Imagine a line passing from the point directly vertically + ; and another line passing from the point to the eye position. + ; Let d = total distance from point to the eye + ; Let h = vertical distance from the point to the eye + ; Let hw = vertical distance from the point to the water surface + ; Let dw = distance from the point to a point on the water surface that lies along the ray from point to eye + ; Therefore d/h = dw/hw by similar triangles, or dw = d * hw / h. + ; d = |projPos|, h = eyepos.z - worldPos.z, hw = waterheight.z - worldPos.z, dw = what we solve for + + ; Now, tmp.x = hw, and tmp.y = h + add $tmp.xy, $cEyePosWaterZ.wz, -$worldPos.z + + ; if $tmp.x < 0, then set it to 0 + ; This is the equivalent of moving the vert to the water surface if it's above the water surface + max $tmp.x, $tmp.x, $cZero + + ; Compute 1 / |projPos| = 1/d + dp3 $tmp.z, $projPos.xyw, $projPos.xyw + rsq $tmp.z, $tmp.z + + ; Now we have h/d + mul $tmp.z, $tmp.z, $tmp.y + + ; Now we have d/h + rcp $tmp.w, $tmp.z + + ; We finally have d * hw / h + ; $tmp.w is now the distance that we see through water. + mul $tmp.w, $tmp.x, $tmp.w + + if( $g_dx9 ) + { + mad $tmp, -$tmp.w, $cOOFogRange, $cFogOne + min $tmp, $tmp, $cOne + max oFog, $tmp.x, $cFogMaxDensity + } + else + { + mad $tmp, -$tmp.w, $cOOFogRange, $cFogOne + min $tmp, $tmp, $cOne + max oFog.x, $tmp.x, $cFogMaxDensity + } + + &FreeRegister( \$tmp ); +} + +sub WaterDepthFog +{ + ; oFog.x = 1.0f = no fog + ; oFog.x = 0.0f = full fog + + ; only $worldPos.z is used out of worldPos + local( $worldPos ) = shift; + local( $projPos ) = shift; + local( $dest ) = shift; + + if ( $dest eq "" ) + { + $dest = "oFog"; + } + + local( $tmp ); + &AllocateRegister( \$tmp ); + + ; This is simple similar triangles. Imagine a line passing from the point directly vertically + ; and another line passing from the point to the eye position. + ; Let d = total distance from point to the eye + ; Let h = vertical distance from the point to the eye + ; Let hw = vertical distance from the point to the water surface + ; Let dw = distance from the point to a point on the water surface that lies along the ray from point to eye + ; Therefore d/h = dw/hw by similar triangles, or dw = d * hw / h. + ; d = projPos.w, h = eyepos.z - worldPos.z, hw = waterheight.z - worldPos.z, dw = what we solve for + + ; Now, tmp.x = hw, and tmp.y = h + add $tmp.xy, $cEyePosWaterZ.wz, -$worldPos.z + + ; if $tmp.x < 0, then set it to 0 + ; This is the equivalent of moving the vert to the water surface if it's above the water surface + max $tmp.x, $tmp.x, $cZero + + ; Now we have 1/h + rcp $tmp.z, $tmp.y + + ; Now we have d/h + mul $tmp.w, $projPos.w, $tmp.z + + ; We finally have d * hw / h + ; $tmp.w is now the distance that we see through water. + mul $tmp.w, $tmp.x, $tmp.w + + if( $g_dx9 ) + { + mad $tmp, -$tmp.w, $cOOFogRange, $cFogOne + min $tmp, $tmp, $cOne + max $dest, $tmp.x, $cZero + } + else + { + mad $tmp, -$tmp.w, $cOOFogRange, $cFogOne + min $tmp, $tmp, $cOne + max $dest.x, $tmp.x, $cZero + } + + &FreeRegister( \$tmp ); +} + + +;------------------------------------------------------------------------------ +; Main fogging routine +;------------------------------------------------------------------------------ +sub CalcFog +{ + if( !defined $DOWATERFOG ) + { + die "CalcFog called without using \$DOWATERFOG\n"; + } + my $fogType; + if( $DOWATERFOG == 0 ) + { + $fogType = "rangefog"; + } + else + { + $fogType = "heightfog"; + } + +# print "\$fogType = $fogType\n"; + + ; CalcFog + local( $worldPos ) = shift; + local( $projPos ) = shift; + local( $dest ) = shift; + + if ( $dest eq "" ) + { + $dest = "oFog"; + } + + if( $fogType eq "rangefog" ) + { + &DepthFog( $projPos, $dest ); + } + elsif( $fogType eq "heightfog" ) + { + &WaterDepthFog( $worldPos, $projPos, $dest ); + } + else + { + die; + } +} + +sub CalcRangeFog +{ + ; CalcFog + local( $worldPos ) = shift; + local( $projPos ) = shift; + + if( $DOWATERFOG == 0 ) + { + &RangeFog( $projPos ); + } + elsif( $DOWATERFOG == 1 ) + { + &WaterRangeFog( $worldPos, $projPos ); + } + else + { + die; + } +} + +sub GammaToLinear +{ + local( $gamma ) = shift; + local( $linear ) = shift; + + local( $tmp ); + &AllocateRegister( \$tmp ); + + ; Is rcp more expensive than just storing 2.2 somewhere and doing a mov? + rcp $gamma.w, $cOOGamma ; $gamma.w = 2.2 + lit $linear.z, $gamma.zzzw ; r0.z = linear blue + lit $tmp.z, $gamma.yyyw ; r2.z = linear green + mov $linear.y, $tmp.z ; r0.y = linear green + lit $tmp.z, $gamma.xxxw ; r2.z = linear red + mov $linear.x, $tmp.z ; r0.x = linear red + + &FreeRegister( \$tmp ); +} + +sub LinearToGamma +{ + local( $linear ) = shift; + local( $gamma ) = shift; + + local( $tmp ); + &AllocateRegister( \$tmp ); + + mov $linear.w, $cOOGamma ; $linear.w = 1.0/2.2 + lit $gamma.z, $linear.zzzw ; r0.z = gamma blue + lit $tmp.z, $linear.yyyw ; r2.z = gamma green + mov $gamma.y, $tmp.z ; r0.y = gamma green + lit $tmp.z, $linear.xxxw ; r2.z = gamma red + mov $gamma.x, $tmp.z ; r0.x = gamma red + + &FreeRegister( \$tmp ); +} + +sub ComputeReflectionVector +{ + local( $worldPos ) = shift; + local( $worldNormal ) = shift; + local( $reflectionVector ) = shift; + + local( $vertToEye ); &AllocateRegister( \$vertToEye ); + local( $tmp ); &AllocateRegister( \$tmp ); + + ; compute reflection vector r = 2 * (n dot v) n - v + sub $vertToEye.xyz, $cEyePos.xyz, $worldPos ; $tmp1 = v = c - p + dp3 $tmp, $worldNormal, $vertToEye ; $tmp = n dot v + mul $tmp.xyz, $tmp.xyz, $worldNormal ; $tmp = (n dot v ) n + mad $reflectionVector.xyz, $tmp, $cTwo, -$vertToEye + + &FreeRegister( \$vertToEye ); + &FreeRegister( \$tmp ); +} + +sub ComputeSphereMapTexCoords +{ + local( $reflectionVector ) = shift; + local( $sphereMapTexCoords ) = shift; + + local( $tmp ); &AllocateRegister( \$tmp ); + + ; transform reflection vector into view space + dp3 $tmp.x, $reflectionVector, $cViewModel0 + dp3 $tmp.y, $reflectionVector, $cViewModel1 + dp3 $tmp.z, $reflectionVector, $cViewModel2 + + ; generate + add $tmp.z, $tmp.z, $cOne + + ; find 1 / the length of r2 + dp3 $tmp.w, $tmp, $tmp + rsq $tmp.w, $tmp.w + + ; r1 = r2/|r2| + 1 + mad $tmp.xy, $tmp.w, $tmp, $cOne + mul $sphereMapTexCoords.xy, $tmp.xy, $cHalf + + &FreeRegister( \$tmp ); +} + +sub SkinPosition +{ +# print "\$SKINNING = $SKINNING\n"; + local( $worldPos ) = shift; + + if( !defined $SKINNING ) + { + die "using \$SKINNING without defining.\n"; + } + + if( $SKINNING == 0 ) + { + ; + ; 0 bone skinning (4 instructions) + ; + ; Transform position into world space + ; position + dp4 $worldPos.x, $vPos, $cModel0 + dp4 $worldPos.y, $vPos, $cModel1 + dp4 $worldPos.z, $vPos, $cModel2 + mov $worldPos.w, $cOne + } + else + { + ; + ; 3 bone skinning (19 instructions) + ; + local( $boneIndices ); + local( $blendedMatrix0 ); + local( $blendedMatrix1 ); + local( $blendedMatrix2 ); + local( $localPos ); + &AllocateRegister( \$boneIndices ); + &AllocateRegister( \$blendedMatrix0 ); + &AllocateRegister( \$blendedMatrix1 ); + &AllocateRegister( \$blendedMatrix2 ); + + ; Transform position into world space using all bones + ; denormalize d3dcolor to matrix index + mad $boneIndices, $vBoneIndices, $cColorToIntScale, $cModel0Index + if ( $g_x360 ) + { + mov $boneIndices, $boneIndices.zyxw + } + + ; r11 = boneindices at this point + ; first matrix + mov a0.x, $boneIndices.z + mul $blendedMatrix0, $vBoneWeights.x, c[a0.x] + mul $blendedMatrix1, $vBoneWeights.x, c[a0.x+1] + mul $blendedMatrix2, $vBoneWeights.x, c[a0.x+2] + ; second matrix + mov a0.x, $boneIndices.y + mad $blendedMatrix0, $vBoneWeights.y, c[a0.x], $blendedMatrix0 + mad $blendedMatrix1, $vBoneWeights.y, c[a0.x+1], $blendedMatrix1 + mad $blendedMatrix2, $vBoneWeights.y, c[a0.x+2], $blendedMatrix2 + + ; Calculate third weight + ; compute 1-(weight1+weight2) to calculate weight2 + ; Use $boneIndices.w as a temp since we aren't using it for anything. + add $boneIndices.w, $vBoneWeights.x, $vBoneWeights.y + sub $boneIndices.w, $cOne, $boneIndices.w + + ; third matrix + mov a0.x, $boneIndices.x + mad $blendedMatrix0, $boneIndices.w, c[a0.x], $blendedMatrix0 + mad $blendedMatrix1, $boneIndices.w, c[a0.x+1], $blendedMatrix1 + mad $blendedMatrix2, $boneIndices.w, c[a0.x+2], $blendedMatrix2 + + dp4 $worldPos.x, $vPos, $blendedMatrix0 + dp4 $worldPos.y, $vPos, $blendedMatrix1 + dp4 $worldPos.z, $vPos, $blendedMatrix2 + mov $worldPos.w, $cOne + + &FreeRegister( \$boneIndices ); + &FreeRegister( \$blendedMatrix0 ); + &FreeRegister( \$blendedMatrix1 ); + &FreeRegister( \$blendedMatrix2 ); + } +} + + +sub SkinPositionAndNormal +{ +# print "\$SKINNING = $SKINNING\n"; + local( $worldPos ) = shift; + local( $worldNormal ) = shift; + + if( !defined $SKINNING ) + { + die "using \$SKINNING without defining.\n"; + } + + if( $SKINNING == 0 ) + { + ; + ; 0 bone skinning (13 instructions) + ; + ; Transform position + normal + tangentS + tangentT into world space + ; position + dp4 $worldPos.x, $vPos, $cModel0 + dp4 $worldPos.y, $vPos, $cModel1 + dp4 $worldPos.z, $vPos, $cModel2 + mov $worldPos.w, $cOne + ; normal + dp3 $worldNormal.x, $vNormal, $cModel0 + dp3 $worldNormal.y, $vNormal, $cModel1 + dp3 $worldNormal.z, $vNormal, $cModel2 + } + else + { + local( $boneIndices ); + local( $blendedMatrix0 ); + local( $blendedMatrix1 ); + local( $blendedMatrix2 ); + local( $localPos ); + local( $localNormal ); + local( $normalLength ); + local( $ooNormalLength ); + &AllocateRegister( \$boneIndices ); + &AllocateRegister( \$blendedMatrix0 ); + &AllocateRegister( \$blendedMatrix1 ); + &AllocateRegister( \$blendedMatrix2 ); + + ; Transform position into world space using all bones + ; denormalize d3dcolor to matrix index + mad $boneIndices, $vBoneIndices, $cColorToIntScale, $cModel0Index + if ( $g_x360 ) + { + mov $boneIndices, $boneIndices.zyxw + } + + ; r11 = boneindices at this point + ; first matrix + mov a0.x, $boneIndices.z + mul $blendedMatrix0, $vBoneWeights.x, c[a0.x] + mul $blendedMatrix1, $vBoneWeights.x, c[a0.x+1] + mul $blendedMatrix2, $vBoneWeights.x, c[a0.x+2] + ; second matrix + mov a0.x, $boneIndices.y + mad $blendedMatrix0, $vBoneWeights.y, c[a0.x], $blendedMatrix0 + mad $blendedMatrix1, $vBoneWeights.y, c[a0.x+1], $blendedMatrix1 + mad $blendedMatrix2, $vBoneWeights.y, c[a0.x+2], $blendedMatrix2 + + ; Calculate third weight + ; compute 1-(weight1+weight2) to calculate weight2 + ; Use $boneIndices.w as a temp since we aren't using it for anything. + add $boneIndices.w, $vBoneWeights.x, $vBoneWeights.y + sub $boneIndices.w, $cOne, $boneIndices.w + + ; third matrix + mov a0.x, $boneIndices.x + mad $blendedMatrix0, $boneIndices.w, c[a0.x], $blendedMatrix0 + mad $blendedMatrix1, $boneIndices.w, c[a0.x+1], $blendedMatrix1 + mad $blendedMatrix2, $boneIndices.w, c[a0.x+2], $blendedMatrix2 + + dp4 $worldPos.x, $vPos, $blendedMatrix0 + dp4 $worldPos.y, $vPos, $blendedMatrix1 + dp4 $worldPos.z, $vPos, $blendedMatrix2 + mov $worldPos.w, $cOne + + ; normal + dp3 $worldNormal.x, $vNormal, $blendedMatrix0 + dp3 $worldNormal.y, $vNormal, $blendedMatrix1 + dp3 $worldNormal.z, $vNormal, $blendedMatrix2 + + &FreeRegister( \$boneIndices ); + &FreeRegister( \$blendedMatrix0 ); + &FreeRegister( \$blendedMatrix1 ); + &FreeRegister( \$blendedMatrix2 ); + } +} + +sub SkinPositionNormalAndTangentSpace +{ +# print "\$SKINNING = $SKINNING\n"; + local( $worldPos ) = shift; + local( $worldNormal ) = shift; + local( $worldTangentS ) = shift; + local( $worldTangentT ) = shift; + local( $userData ); + local( $localPos ); + local( $localNormal ); + local( $normalLength ); + local( $ooNormalLength ); + + if( !defined $SKINNING ) + { + die "using \$SKINNING without defining.\n"; + } + +# X360TBD: needed for compressed vertex format +# if ( $g_x360 ) +# { +# &AllocateRegister( \$userData ); +# ; remap compressed range [0..1] to [-1..1] +# mad $userData, $vUserData, $cTwo, -$cOne +# } + + if( $SKINNING == 0 ) + { + ; + ; 0 bone skinning (13 instructions) + ; + ; Transform position + normal + tangentS + tangentT into world space + dp4 $worldPos.x, $vPos, $cModel0 + dp4 $worldPos.y, $vPos, $cModel1 + dp4 $worldPos.z, $vPos, $cModel2 + mov $worldPos.w, $cOne + + ; normal + dp3 $worldNormal.x, $vNormal, $cModel0 + dp3 $worldNormal.y, $vNormal, $cModel1 + dp3 $worldNormal.z, $vNormal, $cModel2 + +# X360TBD: needed for compressed vertex format +# if ( $g_x360 ) +# { +# ; tangents +# dp3 $worldTangentS.x, $userData, $cModel0 +# dp3 $worldTangentS.y, $userData, $cModel1 +# dp3 $worldTangentS.z, $userData, $cModel2 +# +# ; calculate tangent t via cross( N, S ) * S[3] +# &Cross( $worldTangentT, $worldNormal, $worldTangentS ); +# mul $worldTangentT.xyz, $userData.w, $worldTangentT.xyz +# } +# else + { + ; tangents + dp3 $worldTangentS.x, $vUserData, $cModel0 + dp3 $worldTangentS.y, $vUserData, $cModel1 + dp3 $worldTangentS.z, $vUserData, $cModel2 + + ; calculate tangent t via cross( N, S ) * S[3] + &Cross( $worldTangentT, $worldNormal, $worldTangentS ); + mul $worldTangentT.xyz, $vUserData.w, $worldTangentT.xyz + } + } + else + { + local( $boneIndices ); + local( $blendedMatrix0 ); + local( $blendedMatrix1 ); + local( $blendedMatrix2 ); + &AllocateRegister( \$boneIndices ); + &AllocateRegister( \$blendedMatrix0 ); + &AllocateRegister( \$blendedMatrix1 ); + &AllocateRegister( \$blendedMatrix2 ); + + ; Transform position into world space using all bones + ; denormalize d3dcolor to matrix index + mad $boneIndices, $vBoneIndices, $cColorToIntScale, $cModel0Index + if ( $g_x360 ) + { + mov $boneIndices, $boneIndices.zyxw + } + + ; r11 = boneindices at this point + ; first matrix + mov a0.x, $boneIndices.z + mul $blendedMatrix0, $vBoneWeights.x, c[a0.x] + mul $blendedMatrix1, $vBoneWeights.x, c[a0.x+1] + mul $blendedMatrix2, $vBoneWeights.x, c[a0.x+2] + ; second matrix + mov a0.x, $boneIndices.y + mad $blendedMatrix0, $vBoneWeights.y, c[a0.x], $blendedMatrix0 + mad $blendedMatrix1, $vBoneWeights.y, c[a0.x+1], $blendedMatrix1 + mad $blendedMatrix2, $vBoneWeights.y, c[a0.x+2], $blendedMatrix2 + + ; Calculate third weight + ; compute 1-(weight1+weight2) to calculate weight2 + ; Use $boneIndices.w as a temp since we aren't using it for anything. + add $boneIndices.w, $vBoneWeights.x, $vBoneWeights.y + sub $boneIndices.w, $cOne, $boneIndices.w + + ; third matrix + mov a0.x, $boneIndices.x + mad $blendedMatrix0, $boneIndices.w, c[a0.x], $blendedMatrix0 + mad $blendedMatrix1, $boneIndices.w, c[a0.x+1], $blendedMatrix1 + mad $blendedMatrix2, $boneIndices.w, c[a0.x+2], $blendedMatrix2 + + ; position + dp4 $worldPos.x, $vPos, $blendedMatrix0 + dp4 $worldPos.y, $vPos, $blendedMatrix1 + dp4 $worldPos.z, $vPos, $blendedMatrix2 + mov $worldPos.w, $cOne + + ; normal + dp3 $worldNormal.x, $vNormal, $blendedMatrix0 + dp3 $worldNormal.y, $vNormal, $blendedMatrix1 + dp3 $worldNormal.z, $vNormal, $blendedMatrix2 + +# X360TBD: needed for compressed vertex format +# if ( $g_x360 ) +# { +# ; tangents +# dp3 $worldTangentS.x, $userData, $blendedMatrix0 +# dp3 $worldTangentS.y, $userData, $blendedMatrix1 +# dp3 $worldTangentS.z, $userData, $blendedMatrix2 +# +# ; calculate tangent t via cross( N, S ) * S[3] +# &Cross( $worldTangentT, $worldNormal, $worldTangentS ); +# mul $worldTangentT.xyz, $userData.w, $worldTangentT.xyz +# } +# else + { + ; tangents + dp3 $worldTangentS.x, $vUserData, $blendedMatrix0 + dp3 $worldTangentS.y, $vUserData, $blendedMatrix1 + dp3 $worldTangentS.z, $vUserData, $blendedMatrix2 + + ; calculate tangent t via cross( N, S ) * S[3] + &Cross( $worldTangentT, $worldNormal, $worldTangentS ); + mul $worldTangentT.xyz, $vUserData.w, $worldTangentT.xyz + } + + &FreeRegister( \$boneIndices ); + &FreeRegister( \$blendedMatrix0 ); + &FreeRegister( \$blendedMatrix1 ); + &FreeRegister( \$blendedMatrix2 ); + } + +# X360TBD: needed for compressed vertex format +# if ( $g_x360 ) +# { +# &FreeRegister( \$userData ); +# } +} + +sub ColorClamp +{ + ; ColorClamp; stomps $color.w + local( $color ) = shift; + local( $dst ) = shift; + + ; Get the max of RGB and stick it in W + max $color.w, $color.x, $color.y + max $color.w, $color.w, $color.z + + ; get the greater of one and the max color. + max $color.w, $color.w, $cOne + + rcp $color.w, $color.w + mul $dst.xyz, $color.w, $color.xyz +} + +sub AmbientLight +{ + local( $worldNormal ) = shift; + local( $linearColor ) = shift; + local( $add ) = shift; + + ; Ambient lighting + &AllocateRegister( \$nSquared ); + &AllocateRegister( \$isNegative ); + + mul $nSquared.xyz, $worldNormal.xyz, $worldNormal.xyz ; compute n times n + slt $isNegative.xyz, $worldNormal.xyz, $cZero ; Figure out whether each component is >0 + mov a0.x, $isNegative.x + if( $add ) + { + mad $linearColor.xyz, $nSquared.x, c[a0.x + $cAmbientColorPosXOffset], $linearColor ; $linearColor = normal[0]*normal[0] * box color of appropriate x side + } + else + { + mul $linearColor.xyz, $nSquared.x, c[a0.x + $cAmbientColorPosXOffset] ; $linearColor = normal[0]*normal[0] * box color of appropriate x side + } + mov a0.x, $isNegative.y + mad $linearColor.xyz, $nSquared.y, c[a0.x + $cAmbientColorPosYOffset], $linearColor + mov a0.x, $isNegative.z + mad $linearColor.xyz, $nSquared.z, c[a0.x + $cAmbientColorPosZOffset], $linearColor + + &FreeRegister( \$isNegative ); + &FreeRegister( \$nSquared ); +} + +sub DirectionalLight +{ + local( $worldNormal ) = shift; + local( $linearColor ) = shift; + local( $add ) = shift; + + &AllocateRegister( \$nDotL ); # FIXME: This only needs to be a scalar + + ; NOTE: Gotta use -l here, since light direction = -l + ; DIRECTIONAL LIGHT + ; compute n dot l + dp3 $nDotL.x, -c[a0.x + 1], $worldNormal + + if ( $HALF_LAMBERT == 0 ) + { + ; lambert + max $nDotL.x, $nDotL.x, c0.x ; Clamp to zero + } + elsif ( $HALF_LAMBERT == 1 ) + { + ; half-lambert + mad $nDotL.x, $nDotL.x, $cHalf, $cHalf ; dot = (dot * 0.5 + 0.5)^2 + mul $nDotL.x, $nDotL.x, $nDotL.x + } + else + { + die "\$HALF_LAMBERT is hosed\n"; + } + + if( $add ) + { + mad $linearColor.xyz, c[a0.x], $nDotL.x, $linearColor + } + else + { + mul $linearColor.xyz, c[a0.x], $nDotL.x + } + + &FreeRegister( \$nDotL ); +} + +sub PointLight +{ + local( $worldPos ) = shift; + local( $worldNormal ) = shift; + local( $linearColor ) = shift; + local( $add ) = shift; + + local( $lightDir ); + &AllocateRegister( \$lightDir ); + + ; POINT LIGHT + ; compute light direction + sub $lightDir, c[a0.x+2], $worldPos + + local( $lightDistSquared ); + local( $ooLightDist ); + &AllocateRegister( \$lightDistSquared ); + &AllocateRegister( \$ooLightDist ); + + ; normalize light direction, maintain temporaries for attenuation + dp3 $lightDistSquared, $lightDir, $lightDir + rsq $ooLightDist, $lightDistSquared.x + mul $lightDir, $lightDir, $ooLightDist.x + + local( $attenuationFactors ); + &AllocateRegister( \$attenuationFactors ); + + ; compute attenuation amount (r2 = 'd*d d*d d*d d*d', r3 = '1/d 1/d 1/d 1/d') + dst $attenuationFactors, $lightDistSquared, $ooLightDist ; r4 = ( 1, d, d*d, 1/d ) + &FreeRegister( \$lightDistSquared ); + &FreeRegister( \$ooLightDist ); + local( $attenuation ); + &AllocateRegister( \$attenuation ); + dp3 $attenuation, $attenuationFactors, c[a0.x+4] ; r3 = atten0 + d * atten1 + d*d * atten2 + + rcp $lightDir.w, $attenuation ; $lightDir.w = 1 / (atten0 + d * atten1 + d*d * atten2) + + &FreeRegister( \$attenuationFactors ); + &FreeRegister( \$attenuation ); + + local( $tmp ); + &AllocateRegister( \$tmp ); # FIXME : really only needs to be a scalar + + ; compute n dot l, fold in distance attenutation + dp3 $tmp.x, $lightDir, $worldNormal + + if ( $HALF_LAMBERT == 0 ) + { + ; lambert + max $tmp.x, $tmp.x, c0.x ; Clamp to zero + } + elsif ( $HALF_LAMBERT == 1 ) + { + ; half-lambert + mad $tmp.x, $tmp.x, $cHalf, $cHalf ; dot = (dot * 0.5 + 0.5)^2 + mul $tmp.x, $tmp.x, $tmp.x + } + else + { + die "\$HALF_LAMBERT is hosed\n"; + } + + mul $tmp.x, $tmp.x, $lightDir.w + if( $add ) + { + mad $linearColor.xyz, c[a0.x], $tmp.x, $linearColor + } + else + { + mul $linearColor.xyz, c[a0.x], $tmp.x + } + + &FreeRegister( \$lightDir ); + &FreeRegister( \$tmp ); # FIXME : really only needs to be a scalar +} + +sub SpotLight +{ + local( $worldPos ) = shift; + local( $worldNormal ) = shift; + local( $linearColor ) = shift; + local( $add ) = shift; + + local( $lightDir ); + &AllocateRegister( \$lightDir ); + + ; SPOTLIGHT + ; compute light direction + sub $lightDir, c[a0.x+2], $worldPos + + local( $lightDistSquared ); + local( $ooLightDist ); + &AllocateRegister( \$lightDistSquared ); + &AllocateRegister( \$ooLightDist ); + + ; normalize light direction, maintain temporaries for attenuation + dp3 $lightDistSquared, $lightDir, $lightDir + rsq $ooLightDist, $lightDistSquared.x + mul $lightDir, $lightDir, $ooLightDist.x + + local( $attenuationFactors ); + &AllocateRegister( \$attenuationFactors ); + + ; compute attenuation amount (r2 = 'd*d d*d d*d d*d', r3 = '1/d 1/d 1/d 1/d') + dst $attenuationFactors, $lightDistSquared, $ooLightDist ; r4 = ( 1, d, d*d, 1/d ) + + &FreeRegister( \$lightDistSquared ); + &FreeRegister( \$ooLightDist ); + local( $attenuation ); &AllocateRegister( \$attenuation ); + + dp3 $attenuation, $attenuationFactors, c[a0.x+4] ; r3 = atten0 + d * atten1 + d*d * atten2 + rcp $lightDir.w, $attenuation ; r1.w = 1 / (atten0 + d * atten1 + d*d * atten2) + + &FreeRegister( \$attenuationFactors ); + &FreeRegister( \$attenuation ); + + local( $litSrc ); &AllocateRegister( \$litSrc ); + local( $tmp ); &AllocateRegister( \$tmp ); # FIXME - only needs to be scalar + + ; compute n dot l + dp3 $litSrc.x, $worldNormal, $lightDir + + if ( $HALF_LAMBERT == 0 ) + { + ; lambert + max $litSrc.x, $litSrc.x, c0.x ; Clamp to zero + } + elsif ( $HALF_LAMBERT == 1 ) + { + ; half-lambert + mad $litSrc.x, $litSrc.x, $cHalf, $cHalf ; dot = (dot * 0.5 + 0.5) ^ 2 + mul $litSrc.x, $litSrc.x, $litSrc.x + } + else + { + die "\$HALF_LAMBERT is hosed\n"; + } + + ; compute angular attenuation + dp3 $tmp.x, c[a0.x+1], -$lightDir ; dot = -delta * spot direction + sub $litSrc.y, $tmp.x, c[a0.x+3].z ; r2.y = dot - stopdot2 + &FreeRegister( \$tmp ); + mul $litSrc.y, $litSrc.y, c[a0.x+3].w ; r2.y = (dot - stopdot2) / (stopdot - stopdot2) + mov $litSrc.w, c[a0.x+3].x ; r2.w = exponent + local( $litDst ); &AllocateRegister( \$litDst ); + lit $litDst, $litSrc ; r3.y = N dot L or 0, whichever is bigger + &FreeRegister( \$litSrc ); + ; r3.z = pow((dot - stopdot2) / (stopdot - stopdot2), exponent) + min $litDst.z, $litDst.z, $cOne ; clamp pow() to 1 + + local( $tmp1 ); &AllocateRegister( \$tmp1 ); + local( $tmp2 ); &AllocateRegister( \$tmp2 ); # FIXME - could be scalar + + ; fold in distance attenutation with other factors + mul $tmp1, c[a0.x], $lightDir.w + mul $tmp2.x, $litDst.y, $litDst.z + if( $add ) + { + mad $linearColor.xyz, $tmp1, $tmp2.x, $linearColor + } + else + { + mul $linearColor.xyz, $tmp1, $tmp2.x + } + + &FreeRegister( \$lightDir ); + &FreeRegister( \$litDst ); + &FreeRegister( \$tmp1 ); + &FreeRegister( \$tmp2 ); +} + +sub DoLight +{ + local( $lightType ) = shift; + local( $worldPos ) = shift; + local( $worldNormal ) = shift; + local( $linearColor ) = shift; + local( $add ) = shift; + + if( $lightType eq "spot" ) + { + &SpotLight( $worldPos, $worldNormal, $linearColor, $add ); + } + elsif( $lightType eq "point" ) + { + &PointLight( $worldPos, $worldNormal, $linearColor, $add ); + } + elsif( $lightType eq "directional" ) + { + &DirectionalLight( $worldNormal, $linearColor, $add ); + } + else + { + die "don't know about light type \"$lightType\"\n"; + } +} + +sub DoLighting +{ + if( !defined $LIGHT_COMBO ) + { + die "DoLighting called without using \$LIGHT_COMBO\n"; + } + if ( !defined $HALF_LAMBERT ) + { + die "DoLighting called without using \$HALF_LAMBERT\n"; + } + + my $staticLightType = $g_staticLightTypeArray[$LIGHT_COMBO]; + my $ambientLightType = $g_ambientLightTypeArray[$LIGHT_COMBO]; + my $localLightType1 = $g_localLightType1Array[$LIGHT_COMBO]; + my $localLightType2 = $g_localLightType2Array[$LIGHT_COMBO]; + +# print "\$staticLightType = $staticLightType\n"; +# print "\$ambientLightType = $ambientLightType\n"; +# print "\$localLightType1 = $localLightType1\n"; +# print "\$localLightType2 = $localLightType2\n"; + + local( $worldPos ) = shift; + local( $worldNormal ) = shift; + + ; special case for no lighting + if( $staticLightType eq "none" && $ambientLightType eq "none" && + $localLightType1 eq "none" && $localLightType2 eq "none" ) + { + ; Have to write something here since debug d3d runtime will barf otherwise. + mov oD0, $cOne + return; + } + + ; special case for static lighting only + ; Don't need to bother converting to linear space in this case. + if( $staticLightType eq "static" && $ambientLightType eq "none" && + $localLightType1 eq "none" && $localLightType2 eq "none" ) + { + mov oD0, $vSpecular + return; + } + + alloc $linearColor + alloc $gammaColor + + local( $add ) = 0; + if( $staticLightType eq "static" ) + { + ; The static lighting comes in in gamma space and has also been premultiplied by $cOverbrightFactor + ; need to get it into + ; linear space so that we can do adds. + rcp $gammaColor.w, $cOverbrightFactor + mul $gammaColor.xyz, $vSpecular, $gammaColor.w + &GammaToLinear( $gammaColor, $linearColor ); + $add = 1; + } + + if( $ambientLightType eq "ambient" ) + { + &AmbientLight( $worldNormal, $linearColor, $add ); + $add = 1; + } + + if( $localLightType1 ne "none" ) + { + mov a0.x, $cLight0Offset + &DoLight( $localLightType1, $worldPos, $worldNormal, $linearColor, $add ); + $add = 1; + } + + if( $localLightType2 ne "none" ) + { + mov a0.x, $cLight1Offset + &DoLight( $localLightType2, $worldPos, $worldNormal, $linearColor, $add ); + $add = 1; + } + + ;------------------------------------------------------------------------------ + ; Output color (gamma correction) + ;------------------------------------------------------------------------------ + + &LinearToGamma( $linearColor, $gammaColor ); + if( 0 ) + { + mul oD0.xyz, $gammaColor.xyz, $cOverbrightFactor + } + else + { + mul $gammaColor.xyz, $gammaColor.xyz, $cOverbrightFactor + &ColorClamp( $gammaColor, "oD0" ); + } + +; mov oD0.xyz, $linearColor + mov oD0.w, $cOne ; make sure all components are defined + + free $linearColor + free $gammaColor +} + +sub DoDynamicLightingToLinear +{ + local( $worldPos ) = shift; + local( $worldNormal ) = shift; + local( $linearColor ) = shift; + + if( !defined $LIGHT_COMBO ) + { + die "DoLighting called without using \$LIGHT_COMBO\n"; + } + if ( !defined $HALF_LAMBERT ) + { + die "DoLighting called without using \$HALF_LAMBERT\n"; + } + + my $staticLightType = $g_staticLightTypeArray[$LIGHT_COMBO]; + my $ambientLightType = $g_ambientLightTypeArray[$LIGHT_COMBO]; + my $localLightType1 = $g_localLightType1Array[$LIGHT_COMBO]; + my $localLightType2 = $g_localLightType2Array[$LIGHT_COMBO]; + + # No lights at all. . note that we don't even consider static lighting here. + if( $ambientLightType eq "none" && + $localLightType1 eq "none" && $localLightType2 eq "none" ) + { + mov $linearColor, $cZero + return; + } + + local( $add ) = 0; + if( $ambientLightType eq "ambient" ) + { + &AmbientLight( $worldNormal, $linearColor, $add ); + $add = 1; + } + + if( $localLightType1 ne "none" ) + { + mov a0.x, $cLight0Offset + &DoLight( $localLightType1, $worldPos, $worldNormal, $linearColor, $add ); + $add = 1; + } + + if( $localLightType2 ne "none" ) + { + mov a0.x, $cLight1Offset + &DoLight( $localLightType2, $worldPos, $worldNormal, $linearColor, $add ); + $add = 1; + } +} + +sub NotImplementedYet +{ + &AllocateRegister( \$projPos ); + dp4 $projPos.x, $worldPos, $cViewProj0 + dp4 $projPos.y, $worldPos, $cViewProj1 + dp4 $projPos.z, $worldPos, $cViewProj2 + dp4 $projPos.w, $worldPos, $cViewProj3 + mov oPos, $projPos + &FreeRegister( \$projPos ); + exit; +} diff --git a/materialsystem/stdshaders/modeldiffusebump.psh b/materialsystem/stdshaders/modeldiffusebump.psh new file mode 100644 index 0000000..68f1850 --- /dev/null +++ b/materialsystem/stdshaders/modeldiffusebump.psh @@ -0,0 +1,39 @@ +ps.1.1 + +; base texture +tex t0 + +; normalmap +tex t1 + +; rgb - tangent space light direction for first light +texcoord t2 + +; rgb - tangent space light direction for second light +texcoord t3 + +; v0.rgb : ambient color +; c5 : light 1 color +; c6 : light 2 color + +; first local light +dp3_sat r0.rgb, t1_bx2, t2_bx2 ; n dot l ++mov r0.a, t0.a ; Get the output color alpha from the base texture +mad r0.rgb, c5, r0, v0 ; mult by light color add add ambient color + +; second local light +dp3_sat r1, t1_bx2, t3_bx2 ; n dot l +mad r0.rgb, c6, r1, r0 ; mult by light color and add first local light + +; c1 = A +; c2 = B +; c3 = C +; D = 0 +;mad_x2 r1.rgb, c1, r0, c2 +;mad_x2 r1.rgb, r1, r0, c3 +;mul_x4 r0.rgb, r1, r0 + +;mul_x2 r0.rgb, r0, t0 ; mult by texture and overbright + + +mov_x2 r0.rgb, r0 diff --git a/materialsystem/stdshaders/modeldiffusebump2.psh b/materialsystem/stdshaders/modeldiffusebump2.psh new file mode 100644 index 0000000..2419627 --- /dev/null +++ b/materialsystem/stdshaders/modeldiffusebump2.psh @@ -0,0 +1,33 @@ +ps.1.1 + +; base texture +tex t0 + +; normalmap +tex t1 + +; rgb - color for first axis - gamma converted to 2.2 in the vertex shader +texcoord t2 + +; rgb - color for second axis - gamma converted to 2.2 in the vertex shader +texcoord t3 + +; v0.rgb : color for third axis - gamma converted to 2.2 in the vertex shader + +; c0, c1, c2 - Axes of the lightmap coordinate system in tangent space + +dp3_sat r1.rgb, t1_bx2, c0 ++mov r0.a, t0 +mul r0.rgb, r1, t2 + +dp3_sat r1.rgb, t1_bx2, c1 +mad r0.rgb, r1, t3, r0 + +dp3_sat r1.rgb, t1_bx2, c2 +mad r0.rgb, r1, v0, r0 + +;mov_x2 r0.rgb, r0 +mul_x2 r0.rgb, r0, t0 + + + diff --git a/materialsystem/stdshaders/modelenvmappedbumpmapv2.psh b/materialsystem/stdshaders/modelenvmappedbumpmapv2.psh new file mode 100644 index 0000000..003b818 --- /dev/null +++ b/materialsystem/stdshaders/modelenvmappedbumpmapv2.psh @@ -0,0 +1,30 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; Environment mapping on a bumped surface +; t0 - Normalmap +; t3 - Cube environment map (*must* be a cube map!) +; +; c0 - color to multiply the results by +; Input texture coords required here are a little wonky. +; tc0.uv <- U,V into the normal map +; tc1.uvw, tc2.uvw, tc3.uvw <- 3x3 matrix transform +; from tangent space->env map space +; tc1.q, tc2.q, tc3.q <- eye vector in env map space +;------------------------------------------------------------------------------ +; This version doesn't multiply by lighting. + +; Get the 3-vector from the normal map +tex t0 + +; Perform matrix multiply to get a local normal bump. Then +; reflect the eye vector through the normal and sample from +; a cubic environment map. +texm3x3pad t1, t0_bx2 +texm3x3pad t2, t0_bx2 +texm3x3vspec t3, t0_bx2 + +; result goes in output color (multiply by constant color c0) +mul r0.rgb, t3, c0 +mov r0.a, c0.a + diff --git a/materialsystem/stdshaders/modelenvmappedbumpmapv2_multbyalpha.psh b/materialsystem/stdshaders/modelenvmappedbumpmapv2_multbyalpha.psh new file mode 100644 index 0000000..032a2b0 --- /dev/null +++ b/materialsystem/stdshaders/modelenvmappedbumpmapv2_multbyalpha.psh @@ -0,0 +1,35 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; Environment mapping on a bumped surface +; t0 - Normalmap +; t3 - Cube environment map (*must* be a cube map!) +; +; c0 - color to multiply the results by +; Input texture coords required here are a little wonky. +; tc0.uv <- U,V into the normal map +; tc1.uvw, tc2.uvw, tc3.uvw <- 3x3 matrix transform +; from tangent space->env map space +; tc1.q, tc2.q, tc3.q <- eye vector in env map space +;------------------------------------------------------------------------------ +; This version doesn't multiply by lighting. + +; Get the 3-vector from the normal map +tex t0 + +; Perform matrix multiply to get a local normal bump. Then +; reflect the eye vector through the normal and sample from +; a cubic environment map. +texm3x3pad t1, t0_bx2 +texm3x3pad t2, t0_bx2 +texm3x3vspec t3, t0_bx2 + +; result goes in output color (multiply by constant color c0) +mul r0, t3, c0 + +; Multiply the output color by the alpha channel of the normal map. +mul r0.rgb, t0.a, r0 + + + + diff --git a/materialsystem/stdshaders/modulate_dx6.cpp b/materialsystem/stdshaders/modulate_dx6.cpp new file mode 100644 index 0000000..7c9820e --- /dev/null +++ b/materialsystem/stdshaders/modulate_dx6.cpp @@ -0,0 +1,96 @@ +//========= 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" + +// FIXME!! This version doesn't support vertexalpha to make it blend to white!!! +DEFINE_FALLBACK_SHADER( Modulate, Modulate_DX6 ) + +BEGIN_SHADER( Modulate_DX6, + "Help for Modulate_DX6" ) + + BEGIN_SHADER_PARAMS + SHADER_PARAM( WRITEZ, SHADER_PARAM_TYPE_BOOL, "0", "Forces z to be written if set" ) + SHADER_PARAM( MOD2X, SHADER_PARAM_TYPE_BOOL, "0", "forces a 2x modulate so that you can brighten and darken things" ) + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + } + + SHADER_INIT + { + if (params[BASETEXTURE]->IsDefined()) + LoadTexture( BASETEXTURE ); + } + + SHADER_DRAW + { + bool bMod2X = params[MOD2X]->IsDefined() && params[MOD2X]->GetIntValue(); + SHADOW_STATE + { + if( bMod2X ) + { + EnableAlphaBlending( SHADER_BLEND_DST_COLOR, SHADER_BLEND_SRC_COLOR ); + } + else + { + EnableAlphaBlending( SHADER_BLEND_DST_COLOR, SHADER_BLEND_ZERO ); + } + + if (params[WRITEZ]->GetIntValue() != 0) + { + // This overrides the disabling of depth writes performed in + // EnableAlphaBlending + pShaderShadow->EnableDepthWrites(true); + } + + pShaderShadow->EnableConstantColor( true ); + + int drawFlags = SHADER_DRAW_POSITION; + + if (params[BASETEXTURE]->IsTexture()) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + drawFlags |= SHADER_DRAW_TEXCOORD0; + } + + if (IS_FLAG_SET(MATERIAL_VAR_VERTEXCOLOR)) + { + drawFlags |= SHADER_DRAW_COLOR; + } + + pShaderShadow->DrawFlags( drawFlags ); + // We need to fog to *white* regardless of overbrighting... + if( bMod2X ) + { + FogToGrey(); + } + else + { + FogToOOOverbright(); + } + } + DYNAMIC_STATE + { + if (params[BASETEXTURE]->IsTexture()) + { + BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME ); + SetFixedFunctionTextureTransform( MATERIAL_TEXTURE0, BASETEXTURETRANSFORM ); + } + + // The constant color is the modulation color... + SetColorState( COLOR ); + + } + Draw( ); + } +END_SHADER diff --git a/materialsystem/stdshaders/modulate_dx8.cpp b/materialsystem/stdshaders/modulate_dx8.cpp new file mode 100644 index 0000000..7a3b2d8 --- /dev/null +++ b/materialsystem/stdshaders/modulate_dx8.cpp @@ -0,0 +1,231 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//=====================================================================================// + +#include "BaseVSShader.h" +#include "unlitgeneric_vs11.inc" +#include "cloak_blended_pass_helper.h" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +DEFINE_FALLBACK_SHADER( Modulate, Modulate_DX8 ) + +BEGIN_VS_SHADER( Modulate_DX8, + "Help for Modulate" ) + + BEGIN_SHADER_PARAMS + SHADER_PARAM( WRITEZ, SHADER_PARAM_TYPE_BOOL, "0", "Forces z to be written if set" ) + SHADER_PARAM( MOD2X, SHADER_PARAM_TYPE_BOOL, "0", "forces a 2x modulate so that you can brighten and darken things" ) + + // Cloak Pass + SHADER_PARAM( CLOAKPASSENABLED, SHADER_PARAM_TYPE_BOOL, "0", "Enables cloak render in a second pass" ) + SHADER_PARAM( CLOAKFACTOR, SHADER_PARAM_TYPE_FLOAT, "0.0", "" ) + SHADER_PARAM( CLOAKCOLORTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "Cloak color tint" ) + SHADER_PARAM( REFRACTAMOUNT, SHADER_PARAM_TYPE_FLOAT, "2", "" ) + END_SHADER_PARAMS + + SHADER_FALLBACK + { + if ( IsPC() && !g_pHardwareConfig->SupportsVertexAndPixelShaders() ) + return "Modulate_DX6"; + return 0; + } + + // Cloak Pass + void SetupVarsCloakBlendedPass( CloakBlendedPassVars_t &info ) + { + info.m_nCloakFactor = CLOAKFACTOR; + info.m_nCloakColorTint = CLOAKCOLORTINT; + info.m_nRefractAmount = REFRACTAMOUNT; + } + + bool NeedsPowerOfTwoFrameBufferTexture( IMaterialVar **params, bool bCheckSpecificToThisFrame ) const + { + if ( params[CLOAKPASSENABLED]->GetIntValue() ) // If material supports cloaking + { + if ( bCheckSpecificToThisFrame == false ) // For setting model flag at load time + return true; + else if ( ( params[CLOAKFACTOR]->GetFloatValue() > 0.0f ) && ( params[CLOAKFACTOR]->GetFloatValue() < 1.0f ) ) // Per-frame check + return true; + // else, not cloaking this frame, so check flag2 in case the base material still needs it + } + + // Check flag2 if not drawing cloak pass + return IS_FLAG2_SET( MATERIAL_VAR2_NEEDS_POWER_OF_TWO_FRAME_BUFFER_TEXTURE ); + } + + bool IsTranslucent( IMaterialVar **params ) const + { + if ( params[CLOAKPASSENABLED]->GetIntValue() ) // If material supports cloaking + { + if ( ( params[CLOAKFACTOR]->GetFloatValue() > 0.0f ) && ( params[CLOAKFACTOR]->GetFloatValue() < 1.0f ) ) // Per-frame check + return true; + // else, not cloaking this frame, so check flag in case the base material still needs it + } + + // Check flag if not drawing cloak pass + return IS_FLAG_SET( MATERIAL_VAR_TRANSLUCENT ); + } + + SHADER_INIT_PARAMS() + { + SET_FLAGS2( MATERIAL_VAR2_SUPPORTS_HW_SKINNING ); + + // Cloak Pass + if ( !params[CLOAKPASSENABLED]->IsDefined() ) + { + params[CLOAKPASSENABLED]->SetIntValue( 0 ); + } + else if ( params[CLOAKPASSENABLED]->GetIntValue() ) + { + CloakBlendedPassVars_t info; + SetupVarsCloakBlendedPass( info ); + InitParamsCloakBlendedPass( this, params, pMaterialName, info ); + } + } + + SHADER_INIT + { + if (params[BASETEXTURE]->IsDefined()) + LoadTexture( BASETEXTURE ); + + // Cloak Pass + if ( params[CLOAKPASSENABLED]->GetIntValue() ) + { + CloakBlendedPassVars_t info; + SetupVarsCloakBlendedPass( info ); + InitCloakBlendedPass( this, params, info ); + } + } + + SHADER_DRAW + { + // Skip the standard rendering if cloak pass is fully opaque + bool bDrawStandardPass = true; + if ( params[CLOAKPASSENABLED]->GetIntValue() && ( pShaderShadow == NULL ) ) // && not snapshotting + { + CloakBlendedPassVars_t info; + SetupVarsCloakBlendedPass( info ); + if ( CloakBlendedPassIsFullyOpaque( params, info ) ) + { + // There is some strangeness in DX8 when trying to skip the main pass, so leave this alone for now + //bDrawStandardPass = false; + } + } + + // Standard rendering pass + if ( bDrawStandardPass ) + { + bool bMod2X = params[MOD2X]->IsDefined() && params[MOD2X]->GetIntValue(); + bool bVertexColorOrAlpha = IS_FLAG_SET( MATERIAL_VAR_VERTEXCOLOR ) || IS_FLAG_SET( MATERIAL_VAR_VERTEXALPHA ); + + SHADOW_STATE + { + if( bMod2X ) + { + EnableAlphaBlending( SHADER_BLEND_DST_COLOR, SHADER_BLEND_SRC_COLOR ); + } + else + { + EnableAlphaBlending( SHADER_BLEND_DST_COLOR, SHADER_BLEND_ZERO ); + } + + if (params[WRITEZ]->GetIntValue() != 0) + { + // This overrides the disabling of depth writes performed in + // EnableAlphaBlending + pShaderShadow->EnableDepthWrites( true ); + } + + unsigned int flags = VERTEX_POSITION; + int numTexCoords = 1; + + if( params[BASETEXTURE]->IsTexture() ) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + } + + if( bVertexColorOrAlpha ) + { + flags |= VERTEX_COLOR; + } + + pShaderShadow->VertexShaderVertexFormat( flags, numTexCoords, NULL, 0 ); + + unlitgeneric_vs11_Static_Index vshIndex; + vshIndex.SetDETAIL( false ); + vshIndex.SetENVMAP( false ); + vshIndex.SetENVMAPCAMERASPACE( false ); + vshIndex.SetENVMAPSPHERE( false ); + vshIndex.SetSEPARATEDETAILUVS( false ); + vshIndex.SetVERTEXCOLOR( bVertexColorOrAlpha ); + + pShaderShadow->SetVertexShader( "unlitgeneric_vs11", vshIndex.GetIndex() ); + pShaderShadow->SetPixelShader( "Modulate_ps11" ); + + // We need to fog to *white* regardless of overbrighting... + if( bMod2X ) + { + FogToGrey(); + } + else + { + FogToOOOverbright(); + } + } + DYNAMIC_STATE + { + if( params[BASETEXTURE]->IsTexture() ) + { + BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME ); + SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, BASETEXTURETRANSFORM ); + } + + // set constant color for modulation + SetModulationVertexShaderDynamicState(); + + // We need to fog to *white* regardless of overbrighting... + if( bMod2X ) + { + float grey[4] = { 0.5f, 0.5f, 0.5f, 1.0f }; + pShaderAPI->SetPixelShaderConstant( 0, grey ); + } + else + { + float white[4] = { 0.5f, 0.5f, 0.5f, 1.0f }; + pShaderAPI->SetPixelShaderConstant( 0, white ); + } + unlitgeneric_vs11_Dynamic_Index vshIndex; + vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + vshIndex.SetSKINNING( pShaderAPI->GetCurrentNumBones() > 0 ); + pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() ); + } + Draw( ); + } + else + { + // Skip this pass! + Draw( false ); + } + + // Cloak Pass + if ( params[CLOAKPASSENABLED]->GetIntValue() ) + { + // If ( snapshotting ) or ( we need to draw this frame ) + if ( ( pShaderShadow != NULL ) || ( ( params[CLOAKFACTOR]->GetFloatValue() > 0.0f ) && ( params[CLOAKFACTOR]->GetFloatValue() < 1.0f ) ) ) + { + CloakBlendedPassVars_t info; + SetupVarsCloakBlendedPass( info ); + DrawCloakBlendedPass( this, params, pShaderAPI, pShaderShadow, info, vertexCompression ); + } + else // We're not snapshotting and we don't need to draw this frame + { + // Skip this pass! + Draw( false ); + } + } + } +END_SHADER diff --git a/materialsystem/stdshaders/modulate_dx9.cpp b/materialsystem/stdshaders/modulate_dx9.cpp new file mode 100644 index 0000000..54a4475 --- /dev/null +++ b/materialsystem/stdshaders/modulate_dx9.cpp @@ -0,0 +1,291 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//=====================================================================================// + +#include "BaseVSShader.h" + +#include "unlitgeneric_vs20.inc" +#include "modulate_ps20.inc" +#include "modulate_ps20b.inc" + +#include "cpp_shader_constant_register_map.h" + + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" +#include "cloak_blended_pass_helper.h" + +DEFINE_FALLBACK_SHADER( Modulate, Modulate_DX9 ) + +BEGIN_VS_SHADER( Modulate_DX9, + "Help for Modulate" ) + + BEGIN_SHADER_PARAMS + SHADER_PARAM( WRITEZ, SHADER_PARAM_TYPE_BOOL, "0", "Forces z to be written if set" ) + SHADER_PARAM( MOD2X, SHADER_PARAM_TYPE_BOOL, "0", "forces a 2x modulate so that you can brighten and darken things" ) + + // Cloak Pass + SHADER_PARAM( CLOAKPASSENABLED, SHADER_PARAM_TYPE_BOOL, "0", "Enables cloak render in a second pass" ) + SHADER_PARAM( CLOAKFACTOR, SHADER_PARAM_TYPE_FLOAT, "0.0", "" ) + SHADER_PARAM( CLOAKCOLORTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "Cloak color tint" ) + SHADER_PARAM( REFRACTAMOUNT, SHADER_PARAM_TYPE_FLOAT, "2", "" ) + END_SHADER_PARAMS + + SHADER_FALLBACK + { + if ( !(g_pHardwareConfig->SupportsPixelShaders_2_0() && g_pHardwareConfig->SupportsVertexShaders_2_0()) || + (g_pHardwareConfig->GetDXSupportLevel() < 90) ) + { + return "Modulate_DX8"; + } + + return 0; + } + + // Cloak Pass + void SetupVarsCloakBlendedPass( CloakBlendedPassVars_t &info ) + { + info.m_nCloakFactor = CLOAKFACTOR; + info.m_nCloakColorTint = CLOAKCOLORTINT; + info.m_nRefractAmount = REFRACTAMOUNT; + } + + bool NeedsPowerOfTwoFrameBufferTexture( IMaterialVar **params, bool bCheckSpecificToThisFrame ) const + { + if ( params[CLOAKPASSENABLED]->GetIntValue() ) // If material supports cloaking + { + if ( bCheckSpecificToThisFrame == false ) // For setting model flag at load time + return true; + else if ( ( params[CLOAKFACTOR]->GetFloatValue() > 0.0f ) && ( params[CLOAKFACTOR]->GetFloatValue() < 1.0f ) ) // Per-frame check + return true; + // else, not cloaking this frame, so check flag2 in case the base material still needs it + } + + // Check flag2 if not drawing cloak pass + return IS_FLAG2_SET( MATERIAL_VAR2_NEEDS_POWER_OF_TWO_FRAME_BUFFER_TEXTURE ); + } + + bool IsTranslucent( IMaterialVar **params ) const + { + if ( params[CLOAKPASSENABLED]->GetIntValue() ) // If material supports cloaking + { + if ( ( params[CLOAKFACTOR]->GetFloatValue() > 0.0f ) && ( params[CLOAKFACTOR]->GetFloatValue() < 1.0f ) ) // Per-frame check + return true; + // else, not cloaking this frame, so check flag in case the base material still needs it + } + + // Check flag if not drawing cloak pass + return IS_FLAG_SET( MATERIAL_VAR_TRANSLUCENT ); + } + + SHADER_INIT_PARAMS() + { + SET_FLAGS2( MATERIAL_VAR2_SUPPORTS_HW_SKINNING ); + + // Cloak Pass + if ( !params[CLOAKPASSENABLED]->IsDefined() ) + { + params[CLOAKPASSENABLED]->SetIntValue( 0 ); + } + else if ( params[CLOAKPASSENABLED]->GetIntValue() ) + { + CloakBlendedPassVars_t info; + SetupVarsCloakBlendedPass( info ); + InitParamsCloakBlendedPass( this, params, pMaterialName, info ); + } + } + + SHADER_INIT + { + if (params[BASETEXTURE]->IsDefined()) + { + LoadTexture( BASETEXTURE ); + } + + // Cloak Pass + if ( params[CLOAKPASSENABLED]->GetIntValue() ) + { + CloakBlendedPassVars_t info; + SetupVarsCloakBlendedPass( info ); + InitCloakBlendedPass( this, params, info ); + } + } + + SHADER_DRAW + { + // Skip the standard rendering if cloak pass is fully opaque + bool bDrawStandardPass = true; + if ( params[CLOAKPASSENABLED]->GetIntValue() && ( pShaderShadow == NULL ) ) // && not snapshotting + { + CloakBlendedPassVars_t info; + SetupVarsCloakBlendedPass( info ); + if ( CloakBlendedPassIsFullyOpaque( params, info ) ) + { + bDrawStandardPass = false; + } + } + + // Standard rendering pass + if ( bDrawStandardPass ) + { + bool bMod2X = params[MOD2X]->IsDefined() && params[MOD2X]->GetIntValue(); + bool bVertexColorOrAlpha = IS_FLAG_SET( MATERIAL_VAR_VERTEXCOLOR ) || IS_FLAG_SET( MATERIAL_VAR_VERTEXALPHA ); + bool bWriteZ = params[WRITEZ]->GetIntValue() != 0; + BlendType_t nBlendType = EvaluateBlendRequirements( BASETEXTURE, true ); + bool bFullyOpaque = (nBlendType != BT_BLENDADD) && (nBlendType != BT_BLEND) && !IS_FLAG_SET(MATERIAL_VAR_ALPHATEST); //dest alpha is free for special use + + SHADOW_STATE + { + if( bMod2X ) + { + EnableAlphaBlending( SHADER_BLEND_DST_COLOR, SHADER_BLEND_SRC_COLOR ); + } + else + { + EnableAlphaBlending( SHADER_BLEND_DST_COLOR, SHADER_BLEND_ZERO ); + } + + if ( bWriteZ ) + { + // This overrides the disabling of depth writes performed in + // EnableAlphaBlending + pShaderShadow->EnableDepthWrites( true ); + } + + unsigned int flags = VERTEX_POSITION; + int numTexCoords = 0; + int userDataSize = 0; + + if( params[BASETEXTURE]->IsTexture() ) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + + numTexCoords = 1; + } + + if( bVertexColorOrAlpha ) + { + flags |= VERTEX_COLOR; + } + + // HACK: add 1 texcoord if these verts are too thin (to do with how we + // bind stream 2 - see CShaderShadowDX8::VertexShaderVertexFormat) + // FIXME: instead of this, don't add stream 2 elements to all vertex decls! + if ( !( flags & VERTEX_COLOR ) && ( numTexCoords == 0 ) ) + { + numTexCoords = 1; + } + + // This shader supports compressed vertices, so OR in that flag: + flags |= VERTEX_FORMAT_COMPRESSED; + + pShaderShadow->VertexShaderVertexFormat( flags, numTexCoords, NULL, userDataSize ); + + DECLARE_STATIC_VERTEX_SHADER( unlitgeneric_vs20 ); + SET_STATIC_VERTEX_SHADER_COMBO( VERTEXCOLOR, bVertexColorOrAlpha ? 1 : 0 ); + SET_STATIC_VERTEX_SHADER( unlitgeneric_vs20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_STATIC_PIXEL_SHADER( modulate_ps20b ); + SET_STATIC_PIXEL_SHADER( modulate_ps20b ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( modulate_ps20 ); + SET_STATIC_PIXEL_SHADER( modulate_ps20 ); + } + + // We need to fog to *white* regardless of overbrighting... + if( bMod2X ) + { + FogToGrey(); + } + else + { + FogToOOOverbright(); + } + + pShaderShadow->EnableAlphaWrites( bWriteZ && bFullyOpaque ); + } + DYNAMIC_STATE + { + if( params[BASETEXTURE]->IsTexture() ) + { + BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME ); + SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, BASETEXTURETRANSFORM ); + } + + // set constant color for modulation + SetModulationVertexShaderDynamicState(); + + // We need to fog to *white* regardless of overbrighting... + if( bMod2X ) + { + float grey[4] = { 0.5f, 0.5f, 0.5f, 1.0f }; + pShaderAPI->SetPixelShaderConstant( 0, grey ); + } + else + { + float white[4] = { 0.5f, 0.5f, 0.5f, 1.0f }; + pShaderAPI->SetPixelShaderConstant( 0, white ); + } + + pShaderAPI->SetPixelShaderFogParams( PSREG_FOG_PARAMS ); + + float vEyePos_SpecExponent[4]; + pShaderAPI->GetWorldSpaceCameraPosition( vEyePos_SpecExponent ); + vEyePos_SpecExponent[3] = 0.0f; + pShaderAPI->SetPixelShaderConstant( PSREG_EYEPOS_SPEC_EXPONENT, vEyePos_SpecExponent, 1 ); + + float vVertexColor[4] = { bVertexColorOrAlpha ? 1.0f : 0.0f, 0.0f, 0.0f, 0.0f }; + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_6, vVertexColor, 1 ); + + DECLARE_DYNAMIC_VERTEX_SHADER( unlitgeneric_vs20 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( DOWATERFOG, pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, pShaderAPI->GetCurrentNumBones() > 0 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression ); + SET_DYNAMIC_VERTEX_SHADER( unlitgeneric_vs20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_DYNAMIC_PIXEL_SHADER( modulate_ps20b ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( WRITE_DEPTH_TO_DESTALPHA, bWriteZ && bFullyOpaque && pShaderAPI->ShouldWriteDepthToDestAlpha() ); + SET_DYNAMIC_PIXEL_SHADER( modulate_ps20b ); + } + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( modulate_ps20 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + SET_DYNAMIC_PIXEL_SHADER( modulate_ps20 ); + } + } + Draw(); + } + else + { + // Skip this pass! + Draw( false ); + } + + // Cloak Pass + if ( params[CLOAKPASSENABLED]->GetIntValue() ) + { + // If ( snapshotting ) or ( we need to draw this frame ) + if ( ( pShaderShadow != NULL ) || ( ( params[CLOAKFACTOR]->GetFloatValue() > 0.0f ) && ( params[CLOAKFACTOR]->GetFloatValue() < 1.0f ) ) ) + { + CloakBlendedPassVars_t info; + SetupVarsCloakBlendedPass( info ); + DrawCloakBlendedPass( this, params, pShaderAPI, pShaderShadow, info, vertexCompression ); + } + else // We're not snapshotting and we don't need to draw this frame + { + // Skip this pass! + Draw( false ); + } + } + } +END_SHADER diff --git a/materialsystem/stdshaders/modulate_ps2x.fxc b/materialsystem/stdshaders/modulate_ps2x.fxc new file mode 100644 index 0000000..7eee5bd --- /dev/null +++ b/materialsystem/stdshaders/modulate_ps2x.fxc @@ -0,0 +1,38 @@ +// DYNAMIC: "PIXELFOGTYPE" "0..1" +// DYNAMIC: "WRITE_DEPTH_TO_DESTALPHA" "0..1" [ps20b] [PC] +// DYNAMIC: "WRITE_DEPTH_TO_DESTALPHA" "0..0" [ps20b] [XBOX] + +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX] + +#if defined( SHADER_MODEL_PS_2_0 ) +# define WRITE_DEPTH_TO_DESTALPHA 0 +#endif + +#include "common_ps_fxc.h" +#include "shader_constant_register_map.h" + +sampler BaseTextureSampler : register( s0 ); + +const float4 g_WhiteGrayMix : register( c0 ); +const float4 g_FogParams : register( PSREG_FOG_PARAMS ); +const float4 g_EyePos_SpecExponent : register( PSREG_EYEPOS_SPEC_EXPONENT ); + +struct PS_INPUT +{ + float2 vTexCoord0 : TEXCOORD0; + float4 vColor : COLOR0; + + float4 worldPos_projPosZ : TEXCOORD7; // Necessary for pixel fog +}; + +float4 main( PS_INPUT i ) : COLOR +{ + float4 textureColor = tex2D( BaseTextureSampler, i.vTexCoord0 ); + + float4 resultColor = saturate( textureColor * i.vColor ); + resultColor.rgb = lerp( g_WhiteGrayMix.rgb, resultColor.rgb, resultColor.a ); + + float fogFactor = CalcPixelFogFactor( PIXELFOGTYPE, g_FogParams, g_EyePos_SpecExponent.z, i.worldPos_projPosZ.z, i.worldPos_projPosZ.w ); + return FinalOutput( resultColor, fogFactor, PIXELFOGTYPE, TONEMAP_SCALE_NONE, (WRITE_DEPTH_TO_DESTALPHA != 0), i.worldPos_projPosZ.w ); +} diff --git a/materialsystem/stdshaders/modulate_vs11.vsh b/materialsystem/stdshaders/modulate_vs11.vsh new file mode 100644 index 0000000..e69de29 diff --git a/materialsystem/stdshaders/monitorscreen_ps2x.fxc b/materialsystem/stdshaders/monitorscreen_ps2x.fxc new file mode 100644 index 0000000..2387e75 --- /dev/null +++ b/materialsystem/stdshaders/monitorscreen_ps2x.fxc @@ -0,0 +1,53 @@ +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX] +// STATIC: "TEXTURE2" "0..1" +// DYNAMIC: "PIXELFOGTYPE" "0..1" +// DYNAMIC: "WRITE_DEPTH_TO_DESTALPHA" "0..1" [ps20b] [PC] +// DYNAMIC: "WRITE_DEPTH_TO_DESTALPHA" "0..0" [ps20b] [XBOX] + +#if defined( SHADER_MODEL_PS_2_0 ) +# define WRITE_DEPTH_TO_DESTALPHA 0 +#endif + +#include "shader_constant_register_map.h" +#include "common_ps_fxc.h" + +sampler BaseTextureSampler : register( s0 ); +sampler SecondaryTextureSampler : register( s1 ); + + +const float4 g_Contrast : register( c1 ); +const float4 g_Saturation : register( c2 ); +const float4 g_Tint : register( c3 ); +const float4 g_FogParams : register( PSREG_FOG_PARAMS ); +const float4 g_EyePos_SpecExponent : register( PSREG_EYEPOS_SPEC_EXPONENT ); + +#define g_Grey float4( 0.33333f, 0.33333f, 0.33333f, 0.33333f ) + +struct PS_INPUT +{ + float2 vTexCoord0 : TEXCOORD0; + float2 vTexCoord1 : TEXCOORD1; + + float4 vColor : COLOR0; + + float4 worldPos_projPosZ : TEXCOORD7; +}; + +float4 main( PS_INPUT i ) : COLOR +{ + float4 resultColor = tex2D( BaseTextureSampler, i.vTexCoord0 ) * i.vColor; // base texture modulated with vertex color + +#if (TEXTURE2 == 1) + resultColor = tex2D( SecondaryTextureSampler, i.vTexCoord1 ) * resultColor; // modulate base color by another texture +#endif + + float3 tempColor = resultColor.rgb * resultColor.rgb; //base * base + resultColor.rgb = lerp( resultColor.rgb, tempColor.rgb, g_Contrast.rgb ); // blend between color and color * color + tempColor = dot( resultColor.rgb, g_Grey ); // color greyscaled + resultColor.rgb = lerp( tempColor.rgb, resultColor.rgb, g_Saturation.rgb ); // blend between color and greyscale + resultColor.rgb = resultColor.rgb * g_Tint.rgb; // tint + + float fogFactor = CalcPixelFogFactor( PIXELFOGTYPE, g_FogParams, g_EyePos_SpecExponent.z, i.worldPos_projPosZ.z, i.worldPos_projPosZ.w ); + return FinalOutput( resultColor, fogFactor, PIXELFOGTYPE, TONEMAP_SCALE_NONE, (WRITE_DEPTH_TO_DESTALPHA != 0), i.worldPos_projPosZ.w ); +} diff --git a/materialsystem/stdshaders/morphaccumulate_dx9.cpp b/materialsystem/stdshaders/morphaccumulate_dx9.cpp new file mode 100644 index 0000000..925f71e --- /dev/null +++ b/materialsystem/stdshaders/morphaccumulate_dx9.cpp @@ -0,0 +1,108 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//===========================================================================// + +#include "BaseVSShader.h" + + +#include "morphaccumulate_vs30.inc" +#include "morphaccumulate_ps30.inc" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +DEFINE_FALLBACK_SHADER( MorphAccumulate, MorphAccumulate_DX9 ) + +BEGIN_VS_SHADER_FLAGS( MorphAccumulate_DX9, "Help for MorphAccumulate", SHADER_NOT_EDITABLE ) + + BEGIN_SHADER_PARAMS + SHADER_PARAM( DELTA, SHADER_PARAM_TYPE_TEXTURE, "", "position/normal deltas" ) + SHADER_PARAM( SIDESPEED, SHADER_PARAM_TYPE_TEXTURE, "", "side/speed map" ) + SHADER_PARAM( DIMENSIONS, SHADER_PARAM_TYPE_VEC3, "", "delta dimensions" ) + SHADER_PARAM( DELTASCALE, SHADER_PARAM_TYPE_FLOAT, "", "delta scale" ) + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + } + + SHADER_FALLBACK + { + return 0; + } + + SHADER_INIT + { + LoadTexture( DELTA ); + LoadTexture( SIDESPEED ); + } + + SHADER_DRAW + { + bool bUseConstantBasedAccum = ( g_pHardwareConfig->NumVertexShaderConstants() >= VERTEX_SHADER_FLEX_WEIGHTS + VERTEX_SHADER_MAX_FLEX_WEIGHT_COUNT ); + + SHADOW_STATE + { + EnableAlphaBlending( SHADER_BLEND_ONE, SHADER_BLEND_ONE ); + pShaderShadow->EnableBlendingSeparateAlpha( true ); + pShaderShadow->BlendFuncSeparateAlpha( SHADER_BLEND_ONE, SHADER_BLEND_ONE ); + pShaderShadow->EnableDepthTest( false ); + pShaderShadow->EnableDepthWrites( false ); + pShaderShadow->EnableAlphaWrites( true ); + pShaderShadow->EnableCulling( false ); + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER2, true ); + pShaderShadow->FogMode( SHADER_FOGMODE_DISABLED ); + + DECLARE_STATIC_VERTEX_SHADER( morphaccumulate_vs30 ); + SET_STATIC_VERTEX_SHADER_COMBO( CONSTANTBASEDMORPH, bUseConstantBasedAccum ); + SET_STATIC_VERTEX_SHADER( morphaccumulate_vs30 ); + + DECLARE_STATIC_PIXEL_SHADER( morphaccumulate_ps30 ); + SET_STATIC_PIXEL_SHADER_COMBO( CONSTANTBASEDMORPH, bUseConstantBasedAccum ); + SET_STATIC_PIXEL_SHADER( morphaccumulate_ps30 ); + + // NOTE: Color indicates where in the morph accumulator to render into + // Texcoord0 is the texcoord to read from in the source morph texture + // Texcoord1 indicates the strength of the morph target + int pTexCoord[2] = { 4, 1 }; + pShaderShadow->VertexShaderVertexFormat( VERTEX_FORMAT_USE_EXACT_FORMAT, 2, pTexCoord, 0 ); + } + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER0, DELTA ); + BindTexture( SHADER_SAMPLER1, SIDESPEED ); + + if ( !bUseConstantBasedAccum ) + { + pShaderAPI->BindStandardTexture( SHADER_SAMPLER2, TEXTURE_MORPH_WEIGHTS ); + + int nXOffset = pShaderAPI->GetIntRenderingParameter( INT_RENDERPARM_MORPH_WEIGHT_X_OFFSET ); + int nYOffset = pShaderAPI->GetIntRenderingParameter( INT_RENDERPARM_MORPH_WEIGHT_Y_OFFSET ); + int nSubrectWidth = pShaderAPI->GetIntRenderingParameter( INT_RENDERPARM_MORPH_WEIGHT_SUBRECT_WIDTH ); + int nSubrectHeight = pShaderAPI->GetIntRenderingParameter( INT_RENDERPARM_MORPH_WEIGHT_SUBRECT_HEIGHT ); + float pMorphWeightSubrect[4] = { nXOffset, nYOffset, nSubrectWidth, nSubrectHeight }; + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, pMorphWeightSubrect ); + + int nWidth, nHeight; + pShaderAPI->GetStandardTextureDimensions( &nWidth, &nHeight, TEXTURE_MORPH_WEIGHTS ); + float pMorphWeightDim[4] = { nWidth, nHeight, 0, 0 }; + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_1, pMorphWeightDim ); + } + + SetPixelShaderConstant( 0, DELTASCALE ); + + DECLARE_DYNAMIC_VERTEX_SHADER( morphaccumulate_vs30 ); + SET_DYNAMIC_VERTEX_SHADER( morphaccumulate_vs30 ); + + DECLARE_DYNAMIC_PIXEL_SHADER( morphaccumulate_ps30 ); + SET_DYNAMIC_PIXEL_SHADER( morphaccumulate_ps30 ); + } + Draw(); + } +END_SHADER + diff --git a/materialsystem/stdshaders/morphaccumulate_ps30.fxc b/materialsystem/stdshaders/morphaccumulate_ps30.fxc new file mode 100644 index 0000000..77630af --- /dev/null +++ b/materialsystem/stdshaders/morphaccumulate_ps30.fxc @@ -0,0 +1,59 @@ +//======= Copyright © 1996-2006, Valve Corporation, All rights reserved. ====== + +// STATIC: "CONSTANTBASEDMORPH" "0..1" + +#define HDRTYPE HDR_TYPE_NONE +#include "common_ps_fxc.h" + +struct PS_INPUT +{ + float2 vSrcCoord : TEXCOORD0; + float2 vSideSpeedCoord : TEXCOORD1; +#if CONSTANTBASEDMORPH + float4 vMorphWeights : TEXCOORD2; +#else + float2 vMorphWeightCoord : TEXCOORD2; +#endif +}; + +sampler MorphTarget : register( s0 ); +sampler SideSpeedMap : register( s1 ); +#if !CONSTANTBASEDMORPH +sampler MorphWeights : register( s2 ); +#endif + +const float4 vMorphScale : register( c0 ); + +HALF4 main( PS_INPUT i ) : COLOR +{ +#if CONSTANTBASEDMORPH + float4 vMorphWeights = i.vMorphWeights; +#else + float4 vMorphWeights = tex2D( MorphWeights, i.vMorphWeightCoord ); +#endif + + float4 delta = tex2D( MorphTarget, i.vSrcCoord ); + float4 sideSpeed = tex2D( SideSpeedMap, i.vSideSpeedCoord ); + + // NOTE: This is necessary to fixup slight errors in the delta. + // On the cpu, only the range 0-65534 is used so we can encode -1, 0, and 1 exactly. + delta *= 65535.0f / 65534.0f; + + // Compute total weight, taking into account side + speed + float flWeight = lerp( vMorphWeights.y, vMorphWeights.x, sideSpeed.y ); + float flStereoWeight = lerp( vMorphWeights.w, vMorphWeights.z, sideSpeed.y ); + float w = lerp( flWeight, flStereoWeight, sideSpeed.x ); + + // Convert 0-1 -> -1 to 1 + delta *= 2.0f; + delta -= float4( 1.0f, 1.0f, 1.0f, 1.0f ); + + // Apply the morph scale + delta *= vMorphScale; + + // Apply weight + delta *= w; + + return delta; +} + diff --git a/materialsystem/stdshaders/morphaccumulate_vs30.fxc b/materialsystem/stdshaders/morphaccumulate_vs30.fxc new file mode 100644 index 0000000..9fdac4b --- /dev/null +++ b/materialsystem/stdshaders/morphaccumulate_vs30.fxc @@ -0,0 +1,54 @@ +//======= Copyright © 1996-2006, Valve Corporation, All rights reserved. ====== + +// STATIC: "CONSTANTBASEDMORPH" "0..1" + +#include "common_vs_fxc.h" + +struct VS_INPUT +{ + float4 vSrcCoord : TEXCOORD0; + float vMorphWeightId : TEXCOORD1; +}; + +struct VS_OUTPUT +{ + float4 vDestCoord : POSITION; + float2 vSrcCoord : TEXCOORD0; + float2 vSideSpeedCoord : TEXCOORD1; + +#if CONSTANTBASEDMORPH + float4 vMorphWeights : TEXCOORD2; +#else + float2 vMorphWeightCoord : TEXCOORD2; +#endif +}; + +#if !CONSTANTBASEDMORPH +const float4 vMorphWeightSubrect : register( SHADER_SPECIFIC_CONST_0 ); +const float4 vMorphWeightDimensions : register( SHADER_SPECIFIC_CONST_1 ); +#endif + +VS_OUTPUT main( const VS_INPUT v ) +{ + VS_OUTPUT o = ( VS_OUTPUT )0; + + // FIXME: Want these to be in pixel centers! + float2 projSpace = v.vSrcCoord.zw; + projSpace *= 2.0f; + projSpace -= 1.0f; + projSpace.y *= -1.0f; + + o.vDestCoord = float4( projSpace.x, projSpace.y, 0.0f, 1.0f ); + o.vSrcCoord = v.vSrcCoord.xy; + o.vSideSpeedCoord = v.vSrcCoord.xy; + +#if CONSTANTBASEDMORPH + o.vMorphWeights = cFlexWeights[ v.vMorphWeightId ]; +#else + float flColumn = floor( v.vMorphWeightId / vMorphWeightSubrect.w ); + o.vMorphWeightCoord.x = vMorphWeightSubrect.x + flColumn + 0.5f; + o.vMorphWeightCoord.y = vMorphWeightSubrect.y + v.vMorphWeightId - flColumn * vMorphWeightSubrect.w + 0.5f; + o.vMorphWeightCoord.xy /= vMorphWeightDimensions.xy; +#endif + return o; +} \ No newline at end of file diff --git a/materialsystem/stdshaders/morphweight_dx9.cpp b/materialsystem/stdshaders/morphweight_dx9.cpp new file mode 100644 index 0000000..d15bdb2 --- /dev/null +++ b/materialsystem/stdshaders/morphweight_dx9.cpp @@ -0,0 +1,72 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//===========================================================================// + +#include "BaseVSShader.h" + + +#include "morphweight_vs30.inc" +#include "morphweight_ps30.inc" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +//#define V1 1 + +DEFINE_FALLBACK_SHADER( MorphWeight, MorphWeight_DX9 ) + +BEGIN_VS_SHADER_FLAGS( MorphWeight_DX9, "Help for morphweight", SHADER_NOT_EDITABLE ) + + BEGIN_SHADER_PARAMS + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + } + + SHADER_FALLBACK + { + return 0; + } + + SHADER_INIT + { + } + + SHADER_DRAW + { + SHADOW_STATE + { + pShaderShadow->EnableDepthTest( false ); + pShaderShadow->EnableDepthWrites( false ); + pShaderShadow->EnableAlphaWrites( true ); + pShaderShadow->EnableCulling( false ); + pShaderShadow->FogMode( SHADER_FOGMODE_DISABLED ); + + DECLARE_STATIC_VERTEX_SHADER( morphweight_vs30 ); + SET_STATIC_VERTEX_SHADER( morphweight_vs30 ); + + DECLARE_STATIC_PIXEL_SHADER( morphweight_ps30 ); + SET_STATIC_PIXEL_SHADER( morphweight_ps30 ); + + // Texcoord0 is the texcoord to write the weights into + // Texcoord1 contains the morph weights + int pTexCoord[2] = { 2, 4 }; + + pShaderShadow->VertexShaderVertexFormat( VERTEX_FORMAT_USE_EXACT_FORMAT, 2, pTexCoord, 0 ); + } + DYNAMIC_STATE + { + DECLARE_DYNAMIC_VERTEX_SHADER( morphweight_vs30 ); + SET_DYNAMIC_VERTEX_SHADER( morphweight_vs30 ); + + DECLARE_DYNAMIC_PIXEL_SHADER( morphweight_ps30 ); + SET_DYNAMIC_PIXEL_SHADER( morphweight_ps30 ); + } + Draw(); + } +END_SHADER + diff --git a/materialsystem/stdshaders/morphweight_ps30.fxc b/materialsystem/stdshaders/morphweight_ps30.fxc new file mode 100644 index 0000000..1f873eb --- /dev/null +++ b/materialsystem/stdshaders/morphweight_ps30.fxc @@ -0,0 +1,13 @@ +#define HDRTYPE HDR_TYPE_NONE +#include "common_ps_fxc.h" + +struct PS_INPUT +{ + float4 vMorphWeights : TEXCOORD0; +}; + +HALF4 main( PS_INPUT i ) : COLOR +{ + return i.vMorphWeights; +} + diff --git a/materialsystem/stdshaders/morphweight_vs30.fxc b/materialsystem/stdshaders/morphweight_vs30.fxc new file mode 100644 index 0000000..0de2c56 --- /dev/null +++ b/materialsystem/stdshaders/morphweight_vs30.fxc @@ -0,0 +1,29 @@ +#include "common_vs_fxc.h" + +struct VS_INPUT +{ + float2 vSrcCoord : TEXCOORD0; + float4 vMorphWeights : TEXCOORD1; +}; + +struct VS_OUTPUT +{ + float4 vDestCoord : POSITION; + float4 vMorphWeights : TEXCOORD0; +}; + +VS_OUTPUT main( const VS_INPUT v ) +{ + VS_OUTPUT o = ( VS_OUTPUT )0; + + // FIXME: Want these to be in pixel centers! + float2 projSpace = v.vSrcCoord.xy; + projSpace *= 2.0f; + projSpace -= 1.0f; + projSpace.y *= -1.0f; + + o.vDestCoord = float4( projSpace.x, projSpace.y, 0.0f, 1.0f ); + o.vMorphWeights = v.vMorphWeights; + + return o; +} \ No newline at end of file diff --git a/materialsystem/stdshaders/motion_blur_dx9.cpp b/materialsystem/stdshaders/motion_blur_dx9.cpp new file mode 100644 index 0000000..6af6ae9 --- /dev/null +++ b/materialsystem/stdshaders/motion_blur_dx9.cpp @@ -0,0 +1,132 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//===========================================================================// + +#include "BaseVSShader.h" +#include "motion_blur_vs20.inc" +#include "motion_blur_ps20.inc" +#include "motion_blur_ps20b.inc" +#include "convar.h" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +ConVar mat_motion_blur_percent_of_screen_max( "mat_motion_blur_percent_of_screen_max", "4.0" ); + +DEFINE_FALLBACK_SHADER( MotionBlur, MotionBlur_dx9 ) +BEGIN_VS_SHADER_FLAGS( MotionBlur_dx9, "Motion Blur", SHADER_NOT_EDITABLE ) + BEGIN_SHADER_PARAMS + SHADER_PARAM( MOTIONBLURINTERNAL, SHADER_PARAM_TYPE_VEC4, "[0 0 0 0]", "Internal motion blur value set by proxy" ) + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + } + + SHADER_FALLBACK + { + if ( g_pHardwareConfig->GetDXSupportLevel() < 90 ) + { + return "Wireframe"; + } + + return 0; + } + + SHADER_INIT + { + if ( params[BASETEXTURE]->IsDefined() ) + { + LoadTexture( BASETEXTURE, IsOSX() && g_pHardwareConfig->CanDoSRGBReadFromRTs() ? TEXTUREFLAGS_SRGB : 0 ); + } + } + + SHADER_DRAW + { + SHADOW_STATE + { + pShaderShadow->VertexShaderVertexFormat( VERTEX_POSITION, 1, 0, 0 ); + + // On OpenGL OSX, we must do sRGB reads and writes since these render targets are tagged as such + bool bForceSRGBReadsAndWrites = IsOSX() && g_pHardwareConfig->CanDoSRGBReadFromRTs(); + + // NOTE: sRGB is disabled because of the NV8800 brokenness + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, bForceSRGBReadsAndWrites ); + pShaderShadow->EnableSRGBWrite( bForceSRGBReadsAndWrites ); + + DECLARE_STATIC_VERTEX_SHADER( motion_blur_vs20 ); + SET_STATIC_VERTEX_SHADER( motion_blur_vs20 ); + + if ( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_STATIC_PIXEL_SHADER( motion_blur_ps20b ); + SET_STATIC_PIXEL_SHADER( motion_blur_ps20b ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( motion_blur_ps20 ); + SET_STATIC_PIXEL_SHADER( motion_blur_ps20 ); + } + + pShaderShadow->EnableDepthWrites( false ); + pShaderShadow->EnableAlphaWrites( false ); + } + + DYNAMIC_STATE + { + DECLARE_DYNAMIC_VERTEX_SHADER( motion_blur_vs20 ); + SET_DYNAMIC_VERTEX_SHADER( motion_blur_vs20 ); + + // Bind textures + BindTexture( SHADER_SAMPLER0, BASETEXTURE ); + + // Get texture dimensions + ITexture *src_texture = params[BASETEXTURE]->GetTextureValue(); + //int flTextureWidth = src_texture->GetActualWidth(); + int flTextureHeight = src_texture->GetActualHeight(); + + // Percent of screen clamp + float vConst[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; + vConst[0] = mat_motion_blur_percent_of_screen_max.GetFloat() / 100.0f; + pShaderAPI->SetPixelShaderConstant( 0, vConst, 1 ); + + // Set values from material proxy + pShaderAPI->SetPixelShaderConstant( 1, params[MOTIONBLURINTERNAL]->GetVecValue(), 1 ); + + // Quality based on screen resolution height + int nQuality = 1; + if ( flTextureHeight >= 1080 ) // 1080p and higher + nQuality = 3; + else if ( flTextureHeight >= 720 ) // 720p to 1080p + nQuality = 2; + else // Lower resolution than 720p + nQuality = 1; + + if ( fabs( params[MOTIONBLURINTERNAL]->GetVecValue()[0] ) + fabs( params[MOTIONBLURINTERNAL]->GetVecValue()[1] ) + + fabs( params[MOTIONBLURINTERNAL]->GetVecValue()[2] ) + fabs( params[MOTIONBLURINTERNAL]->GetVecValue()[3] ) == 0.0f ) + { + // No motion blur this frame, so force quality to 0 + nQuality = 0; + } + + if ( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_DYNAMIC_PIXEL_SHADER( motion_blur_ps20b ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( QUALITY, nQuality ); + SET_DYNAMIC_PIXEL_SHADER( motion_blur_ps20b ); + } + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( motion_blur_ps20 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( QUALITY, nQuality ); + SET_DYNAMIC_PIXEL_SHADER( motion_blur_ps20 ); + } + } + + Draw(); + } +END_SHADER diff --git a/materialsystem/stdshaders/motion_blur_ps2x.fxc b/materialsystem/stdshaders/motion_blur_ps2x.fxc new file mode 100644 index 0000000..e842e81 --- /dev/null +++ b/materialsystem/stdshaders/motion_blur_ps2x.fxc @@ -0,0 +1,189 @@ +//====== Copyright © 1996-2007, Valve Corporation, All rights reserved. =========================== + +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX] + +// DYNAMIC: "QUALITY" "0..3" + +#ifdef HDRTYPE + #undef HDRTYPE +#endif +#define HDRTYPE HDR_TYPE_NONE + +// Includes ======================================================================================= +#include "common_ps_fxc.h" + +// Texture Samplers =============================================================================== +sampler g_tTexSampler : register( s0 ); + +// Shaders Constants and Globals ================================================================== +float g_flMaxMotionBlur : register( c0 ); +float4 g_vConst5 : register( c1 ); +#define g_vGlobalBlurVector g_vConst5.xy +#define g_flFallingMotionIntensity g_vConst5.z +#define g_flRollBlurIntensity g_vConst5.w + +// Interpolated values ============================================================================ +struct PS_INPUT +{ + float2 vUv0 : TEXCOORD0; +}; + +// Main =========================================================================================== +float4 main( PS_INPUT i ) : COLOR +{ + // Calculate blur vector + float2 vFallingMotionBlurVector = ( ( i.vUv0.xy * 2.0f ) - 1.0f ); + float2 vRollBlurVector = cross( float3( vFallingMotionBlurVector.xy, 0.0f ), float3( 0.0f, 0.0f, 1.0f ) ).xy; + float2 vGlobalBlurVector = g_vGlobalBlurVector; + vGlobalBlurVector.y = -vGlobalBlurVector.y; + //vGlobalBlurVector.xy = float2( 1.0f, 0.0f ); // For debugging + + float flFallingMotionBlurIntensity = -abs( g_flFallingMotionIntensity ); // Keep samples on screen by keeping vector pointing in + //flFallingMotionBlurIntensity = step( 10, abs(g_flFallingMotionIntensity) ); // For finding the sweet spot in debug mode + vFallingMotionBlurVector.xy *= dot( vFallingMotionBlurVector.xy, vFallingMotionBlurVector.xy ); // Dampen the effect in the middle of the screen + vFallingMotionBlurVector.xy *= flFallingMotionBlurIntensity; + + float flRollBlurIntensity = g_flRollBlurIntensity; + vRollBlurVector.xy *= flRollBlurIntensity; + + float2 vFinalBlurVector = vGlobalBlurVector.xy + vFallingMotionBlurVector.xy + vRollBlurVector.xy; + + // Clamp length of blur vector to unit length + //vFinalBlurVector.xy = max( -1.0f, min( 1.0f, vFinalBlurVector.xy ) ); + if ( length( vFinalBlurVector.xy ) > g_flMaxMotionBlur ) + { + vFinalBlurVector.xy = normalize( vFinalBlurVector.xy ) * g_flMaxMotionBlur; + } + + // Set number of samples + #if QUALITY == 0 + const int kNumSamples = 1; + #endif + #if QUALITY == 1 + const int kNumSamples = 7; + #endif + #if QUALITY == 2 + const int kNumSamples = 11; + #endif + #if QUALITY == 3 + const int kNumSamples = 15; + #endif + + float4 cColor = { 0.0f, 0.0f, 0.0f, 0.0f }; + float2 vUvOffset = vFinalBlurVector.xy / ( kNumSamples - 1 ); + for ( int x=0; x 1.0f ) || ( uv.y < 0.0f ) || ( uv.y > 1.0f ) ) + { + cColor.rgb = float3( 1.0f, 0.0f, 0.0f ) * ( 1 - abs( uv.x ) ); + } + else + { + cColor.rgb = uv.x; + //cColor = tex2D( g_tTexSampler, uv.xy ); + + // Simulate 360 sRGB read + //float3 v360Linear = { X360GammaToLinear( cColor.r ), X360GammaToLinear( cColor.g ), X360GammaToLinear( cColor.b ) }; + //cColor.rgb = v360Linear.rgb; + + // On the PC, simulate the remapping for the 360 + + + } + + // Blue ruler + if ( ( uv.y <= 1.0f ) && ( uv.x >= 0.0f ) && ( uv.x <= 1.0f ) ) + { + if ( uv.y > 0.9f ) + { + if ( frac( uv.x * 10.0f ) < 0.01f ) + { + cColor.rgb = float3( 0.0f, 0.0f, 1.0f ); + } + } + + if ( uv.y > 0.925f ) + { + if ( frac( uv.x * 20.0f ) < 0.02f ) + { + cColor.rgb = float3( 0.0f, 0.0f, 1.0f ); + } + } + + if ( uv.y > 0.95f ) + { + if ( frac( uv.x * 100.0f ) < 0.1f ) + { + cColor.rgb = float3( 0.0f, 0.0f, 1.0f ); + } + } + } + + //if ( ( uv.x >= 0.0f ) && ( uv.x <= 1.0f ) && ( uv.y >= 0.0f ) && ( uv.y <= 1.0f ) ) + //{ + // cColor = tex2D( g_tTexSampler, uv.xy ); + //} + + float3 vShaderColor = cColor.rgb; + float3 v360Linear = { SrgbGammaToLinear( vShaderColor.r ), SrgbGammaToLinear( vShaderColor.g ), SrgbGammaToLinear( vShaderColor.b ) }; + cColor.rgb = v360Linear.rgb; + //float3 v360Gamma = { X360LinearToGamma( v360Linear.r ), X360LinearToGamma( v360Linear.g ), X360LinearToGamma( v360Linear.b ) }; + //cColor.rgb = v360Gamma.rgb; + + + //float3 vGamma = { SrgbLinearToGamma( vShaderColor.r ), SrgbLinearToGamma( vShaderColor.g ), SrgbLinearToGamma( vShaderColor.b ) }; + //float3 v360Linear = { X360GammaToLinear( vShaderColor.r ), X360GammaToLinear( vShaderColor.g ), X360GammaToLinear( vShaderColor.b ) }; + //cColor.rgb = v360Linear.rgb; + + + // Simulate 360 sRGB write + //float3 v360Gamma = { X360LinearToGamma( vShaderColor.r ), X360LinearToGamma( vShaderColor.g ), X360LinearToGamma( vShaderColor.b ) }; + //cColor.rgb = v360Gamma.rgb; + + return cColor; + } + //*/ +} diff --git a/materialsystem/stdshaders/motion_blur_vs20.fxc b/materialsystem/stdshaders/motion_blur_vs20.fxc new file mode 100644 index 0000000..7136af5 --- /dev/null +++ b/materialsystem/stdshaders/motion_blur_vs20.fxc @@ -0,0 +1,29 @@ +//====== Copyright © 1996-2007, Valve Corporation, All rights reserved. =========================== + +// Includes ======================================================================================= +#include "common_vs_fxc.h" + +// Input values =================================================================================== +struct VS_INPUT +{ + float3 vPos : POSITION; + float2 vBaseTexCoord : TEXCOORD0; +}; + +// Interpolated values ============================================================================ +struct VS_OUTPUT +{ + float4 projPos : POSITION; + float2 vUv0 : TEXCOORD0; +}; + +// Main =========================================================================================== +VS_OUTPUT main( const VS_INPUT i ) +{ + VS_OUTPUT o; + + o.projPos.xyzw = float4( i.vPos.xyz, 1.0f ); + o.vUv0.xy = i.vBaseTexCoord.xy; + + return o; +} diff --git a/materialsystem/stdshaders/occlusion_dx8.cpp b/materialsystem/stdshaders/occlusion_dx8.cpp new file mode 100644 index 0000000..a863d58 --- /dev/null +++ b/materialsystem/stdshaders/occlusion_dx8.cpp @@ -0,0 +1,62 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//=============================================================================// + +#include "BaseVSShader.h" +#include "writez.inc" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +DEFINE_FALLBACK_SHADER( Occlusion, Occlusion_DX8 ) + +BEGIN_VS_SHADER_FLAGS( Occlusion_DX8, "Help for Occlusion", SHADER_NOT_EDITABLE ) + + BEGIN_SHADER_PARAMS + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + } + + SHADER_FALLBACK + { + if ( IsPC() && g_pHardwareConfig->GetDXSupportLevel() < 80 ) + { + return "Wireframe"; + } + return 0; + } + + SHADER_INIT + { + } + + SHADER_DRAW + { + SHADOW_STATE + { + pShaderShadow->EnableColorWrites( false ); + pShaderShadow->EnableAlphaWrites( false ); + pShaderShadow->EnableDepthWrites( false ); + + pShaderShadow->VertexShaderVertexFormat( VERTEX_POSITION, 1, 0, 0 ); + + writez_Static_Index vshIndex; + pShaderShadow->SetVertexShader( "writez", vshIndex.GetIndex() ); + pShaderShadow->SetPixelShader( "white" ); + } + DYNAMIC_STATE + { + writez_Dynamic_Index vshIndex; + vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() ); + pShaderAPI->SetPixelShaderIndex( 0 ); + } + Draw(); + } +END_SHADER + diff --git a/materialsystem/stdshaders/occlusion_dx9.cpp b/materialsystem/stdshaders/occlusion_dx9.cpp new file mode 100644 index 0000000..62e7e9d --- /dev/null +++ b/materialsystem/stdshaders/occlusion_dx9.cpp @@ -0,0 +1,91 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//=============================================================================// + +#include "BaseVSShader.h" + +#include "writez_vs20.inc" +#include "white_ps20.inc" +#include "white_ps20b.inc" + + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +ConVar gl_amd_occlusion_workaround( "gl_amd_occlusion_workaround", "1" ); + +DEFINE_FALLBACK_SHADER( Occlusion, Occlusion_DX9 ) + +BEGIN_VS_SHADER_FLAGS( Occlusion_DX9, "Help for Occlusion", SHADER_NOT_EDITABLE ) + + BEGIN_SHADER_PARAMS + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + } + + SHADER_FALLBACK + { + if ( g_pHardwareConfig->GetDXSupportLevel() < 90 ) + { + return "Occlusion_DX8"; + } + return 0; + } + + SHADER_INIT + { + } + + SHADER_DRAW + { + SHADOW_STATE + { + pShaderShadow->EnableColorWrites( false ); + pShaderShadow->EnableAlphaWrites( false ); + pShaderShadow->EnableDepthWrites( false ); + + DECLARE_STATIC_VERTEX_SHADER( writez_vs20 ); + SET_STATIC_VERTEX_SHADER( writez_vs20 ); + + // No pixel shader on Direct3D, doubles fill rate + if ( g_pHardwareConfig->PlatformRequiresNonNullPixelShaders() ) + { + DECLARE_STATIC_PIXEL_SHADER( white_ps20 ); + SET_STATIC_PIXEL_SHADER( white_ps20 ); + + // Workaround for weird AMD bug - if sRGB write isn't enabled here then sRGB write enable in subsequent world rendering passes will randomly not take effect (even though we're enabling it) in the driver. + if ( ( IsLinux() || IsWindows() ) && gl_amd_occlusion_workaround.GetBool() ) + { + pShaderShadow->EnableSRGBWrite( true ); + } + } + + // Set stream format (note that this shader supports compression) + unsigned int flags = VERTEX_POSITION | VERTEX_FORMAT_COMPRESSED; + int nTexCoordCount = 1; + int userDataSize = 0; + pShaderShadow->VertexShaderVertexFormat( flags, nTexCoordCount, NULL, userDataSize ); + } + DYNAMIC_STATE + { + DECLARE_DYNAMIC_VERTEX_SHADER( writez_vs20 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( DOWATERFOG, pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression ); + SET_DYNAMIC_VERTEX_SHADER( writez_vs20 ); + + // No pixel shader on Direct3D, doubles fill rate + if ( g_pHardwareConfig->PlatformRequiresNonNullPixelShaders() ) + { + DECLARE_DYNAMIC_PIXEL_SHADER( white_ps20 ); + SET_DYNAMIC_PIXEL_SHADER( white_ps20 ); + } + } + Draw(); + } +END_SHADER + diff --git a/materialsystem/stdshaders/overlay_fit.cpp b/materialsystem/stdshaders/overlay_fit.cpp new file mode 100644 index 0000000..489409c --- /dev/null +++ b/materialsystem/stdshaders/overlay_fit.cpp @@ -0,0 +1,90 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//=============================================================================// + +#include "BaseVSShader.h" +#include "convar.h" + +#include "overlay_fit_vs11.inc" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +// FIXME: Need to make a dx9 version so that "CENTROID" works. + +BEGIN_VS_SHADER_FLAGS( Overlay_Fit, "Help for TerrainTest2", SHADER_NOT_EDITABLE ) + + BEGIN_SHADER_PARAMS + END_SHADER_PARAMS + + // Set up anything that is necessary to make decisions in SHADER_FALLBACK. + SHADER_INIT_PARAMS() + { + // No texture means no self-illum or env mask in base alpha + CLEAR_FLAGS( MATERIAL_VAR_BASEALPHAENVMAPMASK ); + + // If in decal mode, no debug override... + if (IS_FLAG_SET(MATERIAL_VAR_DECAL)) + { + SET_FLAGS( MATERIAL_VAR_NO_DEBUG_OVERRIDE ); + } + + SET_FLAGS2( MATERIAL_VAR2_LIGHTING_LIGHTMAP ); + } + + SHADER_FALLBACK + { + if ( IsPC() && !g_pHardwareConfig->SupportsVertexAndPixelShaders() ) + return "WorldTwoTextureBlend"; + + return 0; + } + + SHADER_INIT + { + CLEAR_FLAGS( MATERIAL_VAR_BASEALPHAENVMAPMASK ); + LoadTexture( BASETEXTURE ); + } + + SHADER_DRAW + { + SHADOW_STATE + { + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); // BASETEXTURE + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); // LIGHTMAP + pShaderShadow->EnableTexture( SHADER_SAMPLER2, true ); // BASETEXTURE + + // texcoord0 : base texcoord + // texcoord1 : alpha texcoord (mapped to fill the overlay) + unsigned int flags = VERTEX_POSITION | VERTEX_COLOR; + int numTexCoords = 3; + pShaderShadow->VertexShaderVertexFormat( flags, numTexCoords, 0, 0 ); + + pShaderShadow->EnableBlending( true ); + pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA ); + + pShaderShadow->EnablePolyOffset( SHADER_POLYOFFSET_DECAL ); + + overlay_fit_vs11_Static_Index vshIndex; + pShaderShadow->SetVertexShader( "Overlay_Fit_vs11", vshIndex.GetIndex() ); + + pShaderShadow->SetPixelShader ( "Overlay_Fit_ps11", 0 ); + + FogToFogColor(); + } + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME ); + pShaderAPI->BindStandardTexture( SHADER_SAMPLER1, TEXTURE_LIGHTMAP ); + BindTexture( SHADER_SAMPLER2, BASETEXTURE, FRAME ); + + overlay_fit_vs11_Dynamic_Index vshIndex; + vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() ); + } + Draw(); + } +END_SHADER + diff --git a/materialsystem/stdshaders/overlay_fit_ps11.psh b/materialsystem/stdshaders/overlay_fit_ps11.psh new file mode 100644 index 0000000..3f1496b --- /dev/null +++ b/materialsystem/stdshaders/overlay_fit_ps11.psh @@ -0,0 +1,11 @@ +ps.1.1 + +tex t0 ; base +tex t1 ; lightmap +tex t2 ; base (with tcoords for alpha) + + +mov r0.rgb, t0 ; base times vertex color (with alpha) +mul r0.rgb, t1, r0 ; fold in lightmap (color only) +mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2) +mov r0.a, t2.a diff --git a/materialsystem/stdshaders/overlay_fit_vs11.vsh b/materialsystem/stdshaders/overlay_fit_vs11.vsh new file mode 100644 index 0000000..eb51f55 --- /dev/null +++ b/materialsystem/stdshaders/overlay_fit_vs11.vsh @@ -0,0 +1,55 @@ +vs.1.1 + +# DYNAMIC: "DOWATERFOG" "0..1" + +;------------------------------------------------------------------------------ +; Constants specified by the app +; c0 = (0, 1, 2, 0.5) +; c1 = (1/2.2, 0, 0, 0) +; c2 = camera position *in world space* +; c4-c7 = modelViewProj matrix (transpose) +; c8-c11 = ViewProj matrix (transpose) +; c12-c15 = model->view matrix (transpose) +; c16 = [fogStart, fogEnd, fogRange, undefined] +; +; Vertex components (as specified in the vertex DECL) +; $vPos = Position +; $vTexCoord0.xy = TexCoord0 +;------------------------------------------------------------------------------ + +#include "macros.vsh" + +; Vertex components +; $vPos = Position +; $vNormal = normal +; $vTexCoord0.xy = TexCoord0 +; $vTangentS = S axis of Texture space +; $vTangentT = T axis of Texture space + +;------------------------------------------------------------------------------ +; Transform the position from world to view space +;------------------------------------------------------------------------------ + +alloc $worldPos +alloc $projPos + + +; Transform position from world to projection space +dp4 $projPos.x, $vPos, $cViewProj0 +dp4 $projPos.y, $vPos, $cViewProj1 +dp4 $projPos.z, $vPos, $cViewProj2 +dp4 $projPos.w, $vPos, $cViewProj3 +mov oPos, $projPos + +dp4 $worldPos.z, $vPos, $cModel2 +&CalcFog( $worldPos, $projPos ); + +free $projPos +free $worldPos + + +mov oD0, $vColor + +mov oT0, $vTexCoord0 +mov oT1, $vTexCoord1 +mov oT2, $vTexCoord2 diff --git a/materialsystem/stdshaders/particlelitgeneric_dx9.cpp b/materialsystem/stdshaders/particlelitgeneric_dx9.cpp new file mode 100644 index 0000000..b402422 --- /dev/null +++ b/materialsystem/stdshaders/particlelitgeneric_dx9.cpp @@ -0,0 +1,66 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $Header: $ +// $NoKeywords: $ +//===========================================================================// + +#include "BaseVSShader.h" +#include "particlelitgeneric_dx9_helper.h" + +BEGIN_VS_SHADER( ParticleLitGeneric_DX9, + "Help for ParticleLitGeneric_DX9" ) + BEGIN_SHADER_PARAMS + SHADER_PARAM( BUMPMAP, SHADER_PARAM_TYPE_TEXTURE, "models/shadertest/shader1_normal", "bump map" ) + SHADER_PARAM( BUMPFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $bumpmap" ) + SHADER_PARAM( BUMPTRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$bumpmap texcoord transform" ) + END_SHADER_PARAMS + + void SetupVars( ParticleLitGeneric_DX9_Vars_t& info ) + { + info.m_nBaseTexture = BASETEXTURE; + info.m_nBaseTextureFrame = FRAME; + info.m_nBaseTextureTransform = BASETEXTURETRANSFORM; + info.m_nBumpmap = BUMPMAP; + info.m_nBumpFrame = BUMPFRAME; + info.m_nBumpTransform = BUMPTRANSFORM; + info.m_nAlphaTestReference = -1; + info.m_nFlashlightTexture = FLASHLIGHTTEXTURE; + info.m_nFlashlightTextureFrame = FLASHLIGHTTEXTUREFRAME; + } + + SHADER_INIT_PARAMS() + { + ParticleLitGeneric_DX9_Vars_t vars; + SetupVars( vars ); +// InitParamsParticleLitGeneric_DX9( this, params, pMaterialName, vars ); + } + + SHADER_FALLBACK + { + if (g_pHardwareConfig->GetDXSupportLevel() < 70) + return "ParticleLitGeneric_DX6"; + + if (g_pHardwareConfig->GetDXSupportLevel() < 80) + return "ParticleLitGeneric_DX7"; + + return "ParticleLitGeneric_DX8"; + + return 0; + } + + SHADER_INIT + { + ParticleLitGeneric_DX9_Vars_t vars; + SetupVars( vars ); +// InitParticleLitGeneric_DX9( this, params, vars ); + } + + SHADER_DRAW + { + ParticleLitGeneric_DX9_Vars_t vars; + SetupVars( vars ); +// DrawParticleLitGeneric_DX9( this, params, pShaderAPI, pShaderShadow, vars ); + } +END_SHADER diff --git a/materialsystem/stdshaders/particlelitgeneric_dx9_helper.cpp b/materialsystem/stdshaders/particlelitgeneric_dx9_helper.cpp new file mode 100644 index 0000000..7ec4ce3 --- /dev/null +++ b/materialsystem/stdshaders/particlelitgeneric_dx9_helper.cpp @@ -0,0 +1,303 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +// +//===========================================================================// + +#if 0 + +#include "particlelitgeneric_dx9_helper.h" +#include "BaseVSShader.h" +#include "particlelit_generic_vs30.inc" +#include "particlelit_generic_ps30.inc" +#include "convar.h" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + + +//----------------------------------------------------------------------------- +// Initialize shader parameters +//----------------------------------------------------------------------------- +void InitParamsParticleLitGeneric_DX9( CBaseVSShader *pShader, IMaterialVar** params, const char *pMaterialName, ParticleLitGeneric_DX9_Vars_t &info ) +{ + // FLASHLIGHTFIXME: Do ShaderAPI::BindFlashlightTexture + Assert( info.m_nFlashlightTexture >= 0 ); + + if ( g_pHardwareConfig->SupportsBorderColor() ) + { + params[FLASHLIGHTTEXTURE]->SetStringValue( "effects/flashlight_border" ); + } + else + { + params[FLASHLIGHTTEXTURE]->SetStringValue( "effects/flashlight001" ); + } + + + SET_FLAGS2( MATERIAL_VAR2_LIGHTING_VERTEX_LIT ); + CLEAR_FLAGS( MATERIAL_VAR_SELFILLUM ); + CLEAR_FLAGS( MATERIAL_VAR_BASEALPHAENVMAPMASK ); + + if( (info.m_nBumpFrame != -1) && !params[info.m_nBumpFrame]->IsDefined() ) + { + params[info.m_nBumpFrame]->SetIntValue( 0 ); + } + + if( (info.m_nBumpmap != -1) && g_pConfig->UseBumpmapping() && params[info.m_nBumpmap]->IsDefined() ) + { + SET_FLAGS2( MATERIAL_VAR2_NEEDS_TANGENT_SPACES ); + } + else + { + CLEAR_FLAGS( MATERIAL_VAR_NORMALMAPALPHAENVMAPMASK ); + } +} + + +//----------------------------------------------------------------------------- +// Initialize shader +//----------------------------------------------------------------------------- +void InitParticleLitGeneric_DX9( CBaseVSShader *pShader, IMaterialVar** params, ParticleLitGeneric_DX9_Vars_t &info ) +{ + Assert( info.m_nFlashlightTexture >= 0 ); + pShader->LoadTexture( info.m_nFlashlightTexture, TEXTUREFLAGS_SRGB ); + + bool bIsBaseTextureTranslucent = false; + if ( params[info.m_nBaseTexture]->IsDefined() ) + { + pShader->LoadTexture( info.m_nBaseTexture, TEXTUREFLAGS_SRGB ); + + if ( params[info.m_nBaseTexture]->GetTextureValue()->IsTranslucent() ) + { + bIsBaseTextureTranslucent = true; + } + } + // No alpha channel in any of the textures? No self illum or envmapmask + if ( !bIsBaseTextureTranslucent ) + { + CLEAR_FLAGS( MATERIAL_VAR_SELFILLUM ); + CLEAR_FLAGS( MATERIAL_VAR_BASEALPHAENVMAPMASK ); + } + + if ( g_pConfig->UseBumpmapping() ) + { + if ( (info.m_nBumpmap != -1) && params[info.m_nBumpmap]->IsDefined() ) + { + pShader->LoadBumpMap( info.m_nBumpmap ); + SET_FLAGS2( MATERIAL_VAR2_DIFFUSE_BUMPMAPPED_MODEL ); + } + } + + // Don't alpha test if the alpha channel is used for other purposes + if ( IS_FLAG_SET(MATERIAL_VAR_SELFILLUM) || IS_FLAG_SET(MATERIAL_VAR_BASEALPHAENVMAPMASK) ) + { + CLEAR_FLAGS( MATERIAL_VAR_ALPHATEST ); + } +} + + +//----------------------------------------------------------------------------- +// Draws the shader +//----------------------------------------------------------------------------- +void DrawParticleLitGeneric_DX9( CBaseVSShader *pShader, IMaterialVar** params, + IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow, ParticleLitGeneric_DX9_Vars_t &info ) +{ + bool hasBaseTexture = params[info.m_nBaseTexture]->IsTexture(); + bool hasBump = (info.m_nBumpmap != -1) && params[info.m_nBumpmap]->IsTexture(); + bool hasVertexColor = IS_FLAG_SET( MATERIAL_VAR_VERTEXCOLOR ); + bool hasVertexAlpha = IS_FLAG_SET( MATERIAL_VAR_VERTEXALPHA ); + bool bIsAlphaTested = IS_FLAG_SET( MATERIAL_VAR_ALPHATEST ) != 0; + bool bNoFog = IS_FLAG_SET( MATERIAL_VAR_NOFOG ); + + HDRType_t hdrType = g_pHardwareConfig->GetHDRType(); + + BlendType_t blendType = pShader->EvaluateBlendRequirements( info.m_nBaseTexture, true ); + if( pShader->IsSnapshotting() ) + { + // look at color and alphamod stuff. + // Unlit generic never uses the flashlight + bool hasFlashlight = CShader_IsFlag2Set( params, MATERIAL_VAR2_USE_FLASHLIGHT ); + bool bHalfLambert = IS_FLAG_SET( MATERIAL_VAR_HALFLAMBERT ); + + // Alpha test: FIXME: shouldn't this be handled in CBaseVSShader::SetInitialShadowState + pShaderShadow->EnableAlphaTest( bIsAlphaTested ); + + if( info.m_nAlphaTestReference != -1 && params[info.m_nAlphaTestReference]->GetFloatValue() > 0.0f ) + { + pShaderShadow->AlphaFunc( SHADER_ALPHAFUNC_GEQUAL, params[info.m_nAlphaTestReference]->GetFloatValue() ); + } + + if( hasFlashlight ) + { + pShader->SetAdditiveBlendingShadowState( info.m_nBaseTexture, true ); + if( bIsAlphaTested ) + { + // disable alpha test and use the zfunc zequals since alpha isn't guaranteed to + // be the same on both the regular pass and the flashlight pass. + pShaderShadow->EnableAlphaTest( false ); + pShaderShadow->DepthFunc( SHADER_DEPTHFUNC_EQUAL ); + } + pShaderShadow->EnableBlending( true ); + pShaderShadow->EnableDepthWrites( false ); + } + else + { + pShader->SetDefaultBlendingShadowState( info.m_nBaseTexture, true ); + } + + unsigned int flags = VERTEX_POSITION; + + int userDataSize = 0; + if( hasBaseTexture ) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, true ); + } + if( hasFlashlight ) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER7, true ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER7, true ); + userDataSize = 4; // tangent S + } + if( hasBump ) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER3, true ); + userDataSize = 4; // tangent S + // Normalizing cube map + pShaderShadow->EnableTexture( SHADER_SAMPLER5, true ); + } + if( hasVertexColor || hasVertexAlpha ) + { + flags |= VERTEX_COLOR; + } + + pShaderShadow->EnableSRGBWrite( true ); + + // texcoord0 : base texcoord + int pTexCoordCount[2] = { 2, 3 }; + pShaderShadow->VertexShaderVertexFormat( + flags, 2, pTexCoordCount, 0, userDataSize ); + + DECLARE_STATIC_VERTEX_SHADER( particlelit_generic_vs30 ); + SET_STATIC_VERTEX_SHADER_COMBO( HALFLAMBERT, bHalfLambert); + SET_STATIC_VERTEX_SHADER( particlelit_generic_vs30 ); + + DECLARE_STATIC_PIXEL_SHADER( particlelit_generic_ps30 ); + SET_STATIC_PIXEL_SHADER_COMBO( HALFLAMBERT, bHalfLambert); +// SET_STATIC_PIXEL_SHADER_COMBO( FLASHLIGHT, hasFlashlight ); + SET_STATIC_PIXEL_SHADER_COMBO( HDRTYPE, hdrType ); + SET_STATIC_PIXEL_SHADER( particlelit_generic_ps30 ); + + if( hasFlashlight ) + { + pShader->FogToBlack(); + } + else + { + pShader->DefaultFog(); + } + + // HACK HACK HACK - enable alpha writes all the time so that we have them for + // underwater stuff + if( blendType != BT_BLENDADD && blendType != BT_BLEND && !bIsAlphaTested ) + { + pShaderShadow->EnableAlphaWrites( true ); + } + } + else + { + bool hasFlashlight = pShaderAPI->InFlashlightMode(); + + if( hasBaseTexture ) + { + pShader->BindTexture( SHADER_SAMPLER0, info.m_nBaseTexture, info.m_nBaseTextureFrame ); + } + if( !g_pConfig->m_bFastNoBump ) + { + if( hasBump ) + { + pShader->BindTexture( SHADER_SAMPLER3, info.m_nBumpmap, info.m_nBumpFrame ); + } + } + else + { + if( hasBump ) + { + pShaderAPI->BindStandardTexture( SHADER_SAMPLER3, TEXTURE_NORMALMAP_FLAT ); + } + } + if( hasFlashlight ) + { + Assert( info.m_nFlashlightTexture >= 0 && info.m_nFlashlightTextureFrame >= 0 ); + pShader->BindTexture( SHADER_SAMPLER7, info.m_nFlashlightTexture, info.m_nFlashlightTextureFrame ); + } + + LightState_t lightState = { 0, false, false }; + if( !hasFlashlight ) + pShaderAPI->GetDX9LightState( &lightState ); + + MaterialFogMode_t fogType = pShaderAPI->GetSceneFogMode(); +// int fogIndex = ( fogType == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ) ? 1 : 0; + + DECLARE_DYNAMIC_VERTEX_SHADER( particlelit_generic_vs30 ); + SET_DYNAMIC_VERTEX_SHADER( particlelit_generic_vs30 ); + + DECLARE_DYNAMIC_PIXEL_SHADER( particlelit_generic_ps30 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( NUM_LIGHTS, lightState.m_nNumLights ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( AMBIENT_LIGHT, lightState.m_bAmbientLight ? 1 : 0 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( STATIC_LIGHT, lightState.m_bStaticLight ? 1 : 0 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( WRITEWATERFOGTODESTALPHA, fogType == MATERIAL_FOG_LINEAR_BELOW_FOG_Z && + blendType != BT_BLENDADD && blendType != BT_BLEND && !bIsAlphaTested ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( HDRENABLED, pShader->IsHDREnabled() ); + SET_DYNAMIC_PIXEL_SHADER( particlelit_generic_ps30 ); + + pShader->SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, info.m_nBaseTextureTransform ); + if( hasBump ) + { + pShader->SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_2, info.m_nBumpTransform ); + } + if( hasBump ) + { + pShaderAPI->BindStandardTexture( SHADER_SAMPLER5, TEXTURE_NORMALIZATION_CUBEMAP_SIGNED ); + pShaderAPI->SetPixelShaderStateAmbientLightCube( 5 ); + pShaderAPI->CommitPixelShaderLighting( 13 ); + } + + float eyePos[4]; + pShaderAPI->GetWorldSpaceCameraPosition( eyePos ); + pShaderAPI->SetPixelShaderConstant( 20, eyePos, 1 ); + pShaderAPI->SetPixelShaderFogParams( 21 ); + + // flashlightfixme: put this in common code. + if( hasFlashlight ) + { + VMatrix worldToTexture; + const FlashlightState_t &flashlightState = pShaderAPI->GetFlashlightState( worldToTexture ); + + // Set the flashlight attenuation factors + float atten[4]; + atten[0] = flashlightState.m_fConstantAtten; + atten[1] = flashlightState.m_fLinearAtten; + atten[2] = flashlightState.m_fQuadraticAtten; + atten[3] = flashlightState.m_FarZ; + pShaderAPI->SetPixelShaderConstant( 22, atten, 1 ); + + // Set the flashlight origin + float pos[4]; + pos[0] = flashlightState.m_vecLightOrigin[0]; + pos[1] = flashlightState.m_vecLightOrigin[1]; + pos[2] = flashlightState.m_vecLightOrigin[2]; + pos[3] = 1.0f; + pShaderAPI->SetPixelShaderConstant( 23, pos, 1 ); + + pShaderAPI->SetPixelShaderConstant( 24, worldToTexture.Base(), 4 ); + } + } + pShader->Draw(); +} + +// Commenting out this entire file +#endif diff --git a/materialsystem/stdshaders/particlelitgeneric_dx9_helper.h b/materialsystem/stdshaders/particlelitgeneric_dx9_helper.h new file mode 100644 index 0000000..89316d5 --- /dev/null +++ b/materialsystem/stdshaders/particlelitgeneric_dx9_helper.h @@ -0,0 +1,47 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//============================================================================= + +#ifndef PARTICLELITGENERIC_DX9_HELPER_H +#define PARTICLELITGENERIC_DX9_HELPER_H + +#include + + +//----------------------------------------------------------------------------- +// Forward declarations +//----------------------------------------------------------------------------- +class CBaseVSShader; +class IMaterialVar; +class IShaderDynamicAPI; +class IShaderShadow; + + +//----------------------------------------------------------------------------- +// Init params/ init/ draw methods +//----------------------------------------------------------------------------- +struct ParticleLitGeneric_DX9_Vars_t +{ + ParticleLitGeneric_DX9_Vars_t() { memset( this, 0xFF, sizeof(ParticleLitGeneric_DX9_Vars_t) ); } + + int m_nBaseTexture; + int m_nBaseTextureFrame; + int m_nBaseTextureTransform; + int m_nBumpmap; + int m_nBumpFrame; + int m_nBumpTransform; + int m_nAlphaTestReference; + int m_nFlashlightTexture; + int m_nFlashlightTextureFrame; +}; + +void InitParamsParticleLitGeneric_DX9( CBaseVSShader *pShader, IMaterialVar** params, const char *pMaterialName, ParticleLitGeneric_DX9_Vars_t &info ); +void InitParticleLitGeneric_DX9( CBaseVSShader *pShader, IMaterialVar** params, ParticleLitGeneric_DX9_Vars_t &info ); +void DrawParticleLitGeneric_DX9( CBaseVSShader *pShader, IMaterialVar** params, + IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow, ParticleLitGeneric_DX9_Vars_t &info ); + + +#endif // PARTICLELITGENERIC_DX9_HELPER_H \ No newline at end of file diff --git a/materialsystem/stdshaders/particlesphere.psh b/materialsystem/stdshaders/particlesphere.psh new file mode 100644 index 0000000..aecbeca --- /dev/null +++ b/materialsystem/stdshaders/particlesphere.psh @@ -0,0 +1,39 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; Sphere-lit particle pixel shader. +; +; The ParticleSphere lighting equation is: +; A + [[N dot |L - P|] * 0.5 + 0.5] * C * r / ||L - P|| +; +; where: +; A = ambient light color +; N = particle normal (stored in the texture) +; L = light position +; P = point on surface +; C = directional light color +; r = directional light intensity +; +; This shader takes as input: +; t0 = Normal map texture coordinates (N) +; t1 = Light vector Normalize(L - P) * 0.5 in range [0,1] +; v0 = Directional color (C * r / ||L - P||^2) * 0.5 +; t2 = Ambient light color (A) +; c0 = 0.5 +; +; and outputs [v1 + (sample(t0) dot t1) * 0.5f + 0.5f] +;------------------------------------------------------------------------------ + +tex t0 ; Get the 3-vector from the normal map +texcoord t1 ; Interpret tcoord t1 as color data. +texcoord t2 ; Ambient light color + +dp3 r1, t0_bx2, t1_bx2 ; r0 = sample(t0) dot t1 +add r0, r1, c0 ; + 0.5 + +mul r1, v0, r0 ; scale the dot product by the dirlight's actual color +add r0.rgb, r1, t2 ; add the ambient color in v1 + +mul r0.a, t0, v0 ; Alpha = normal map alpha * vertex alpha + + diff --git a/materialsystem/stdshaders/particlesphere_dx8.cpp b/materialsystem/stdshaders/particlesphere_dx8.cpp new file mode 100644 index 0000000..422c7c3 --- /dev/null +++ b/materialsystem/stdshaders/particlesphere_dx8.cpp @@ -0,0 +1,101 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: A wet version of base * lightmap +// +// $Header: $ +// $NoKeywords: $ +//=============================================================================// + +#include "BaseVSShader.h" + +#include "particlesphere_vs11.inc" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +DEFINE_FALLBACK_SHADER( ParticleSphere, ParticleSphere_DX8 ) + +BEGIN_VS_SHADER_FLAGS( ParticleSphere_DX8, "Help for BumpmappedEnvMap", SHADER_NOT_EDITABLE ) + + BEGIN_SHADER_PARAMS + SHADER_PARAM( USINGPIXELSHADER, SHADER_PARAM_TYPE_BOOL, "0", "Tells to client code whether the shader is using DX8 vertex/pixel shaders or not" ) + SHADER_PARAM( BUMPMAP, SHADER_PARAM_TYPE_TEXTURE, "models/shadertest/shader1_normal", "bumpmap" ) + SHADER_PARAM( LIGHTS, SHADER_PARAM_TYPE_FOURCC, "", "array of lights" ) + SHADER_PARAM( LIGHT_POSITION, SHADER_PARAM_TYPE_VEC3, "0 0 0", "This is the directional light position." ) + SHADER_PARAM( LIGHT_COLOR, SHADER_PARAM_TYPE_VEC3, "1 1 1", "This is the directional light color." ) + END_SHADER_PARAMS + + bool UsePixelShaders( IMaterialVar **params ) const + { + return (!params || params[BUMPMAP]->IsDefined()) && g_pHardwareConfig->SupportsVertexAndPixelShaders(); + } + + SHADER_INIT + { + // If this would return false, then we should have fallen back to the DX6 one. + Assert( UsePixelShaders( params ) ); + + params[USINGPIXELSHADER]->SetIntValue( true ); + LoadBumpMap( BUMPMAP ); + } + + SHADER_FALLBACK + { + if ( IsPC() && !UsePixelShaders(params) ) + { + return "UnlitGeneric_DX6"; + } + return 0; + } + + SHADER_DRAW + { + SHADOW_STATE + { + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + + int tCoordDimensions[] = {2}; + pShaderShadow->VertexShaderVertexFormat( + VERTEX_POSITION | VERTEX_COLOR, 1, tCoordDimensions, 0 ); + + pShaderShadow->EnableBlending( true ); + pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA ); + pShaderShadow->EnableDepthWrites( false ); + + particlesphere_vs11_Static_Index vshIndex; + pShaderShadow->SetVertexShader( "ParticleSphere_vs11", vshIndex.GetIndex() ); + + pShaderShadow->SetPixelShader( "ParticleSphere_ps11" ); + FogToFogColor(); + } + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER0, BUMPMAP ); + + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, params[LIGHT_POSITION]->GetVecValue() ); + + // Separate the light color into something that has a max value of 1 and a scale + // so the vertex shader can determine if it's going to overflow the color and scale back + // if it needs to. + // + // (It does this by seeing if the intensity*1/distSqr is > 1. If so, then it scales it so + // it is equal to 1). + const float *f = params[LIGHT_COLOR]->GetVecValue(); + Vector vLightColor( f[0], f[1], f[2] ); + float flScale = max( vLightColor.x, max( vLightColor.y, vLightColor.z ) ); + if ( flScale < 0.01f ) + flScale = 0.01f; + float vScaleVec[3] = { flScale, flScale, flScale }; + vLightColor /= flScale; + + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_1, vLightColor.Base() ); + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_2, vScaleVec ); + + // Compute the vertex shader index. + particlesphere_vs11_Dynamic_Index vshIndex; + vshIndex.SetFOGTYPE( s_pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + s_pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() ); + } + Draw(); + } +END_SHADER diff --git a/materialsystem/stdshaders/particlesphere_dx9.cpp b/materialsystem/stdshaders/particlesphere_dx9.cpp new file mode 100644 index 0000000..07b28eb --- /dev/null +++ b/materialsystem/stdshaders/particlesphere_dx9.cpp @@ -0,0 +1,175 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: A wet version of base * lightmap +// +// $Header: $ +// $NoKeywords: $ +//=============================================================================// + +#include "BaseVSShader.h" + +#include "particlesphere_vs20.inc" +#include "particlesphere_ps20.inc" +#include "particlesphere_ps20b.inc" + +#include "cpp_shader_constant_register_map.h" + +int GetDefaultDepthFeatheringValue( void ); //defined in spritecard.cpp + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +DEFINE_FALLBACK_SHADER( ParticleSphere, ParticleSphere_DX9 ) + +BEGIN_VS_SHADER_FLAGS( ParticleSphere_DX9, "Help for BumpmappedEnvMap", SHADER_NOT_EDITABLE ) + + BEGIN_SHADER_PARAMS + SHADER_PARAM( DEPTHBLEND, SHADER_PARAM_TYPE_INTEGER, "0", "fade at intersection boundaries" ) + SHADER_PARAM( DEPTHBLENDSCALE, SHADER_PARAM_TYPE_FLOAT, "50.0", "Amplify or reduce DEPTHBLEND fading. Lower values make harder edges." ) + SHADER_PARAM( USINGPIXELSHADER, SHADER_PARAM_TYPE_BOOL, "0", "Tells to client code whether the shader is using DX8 vertex/pixel shaders or not" ) + SHADER_PARAM( BUMPMAP, SHADER_PARAM_TYPE_TEXTURE, "models/shadertest/shader1_normal", "bumpmap" ) + SHADER_PARAM( LIGHTS, SHADER_PARAM_TYPE_FOURCC, "", "array of lights" ) + SHADER_PARAM( LIGHT_POSITION, SHADER_PARAM_TYPE_VEC3, "0 0 0", "This is the directional light position." ) + SHADER_PARAM( LIGHT_COLOR, SHADER_PARAM_TYPE_VEC3, "1 1 1", "This is the directional light color." ) + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + if ( !params[DEPTHBLEND]->IsDefined() ) + { + params[ DEPTHBLEND ]->SetIntValue( GetDefaultDepthFeatheringValue() ); + } + if ( !g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + params[ DEPTHBLEND ]->SetIntValue( 0 ); + } + if ( !params[DEPTHBLENDSCALE]->IsDefined() ) + { + params[ DEPTHBLENDSCALE ]->SetFloatValue( 50.0f ); + } + } + + bool UsePixelShaders( IMaterialVar **params ) const + { + return (!params || params[BUMPMAP]->IsDefined()) && g_pHardwareConfig->SupportsVertexAndPixelShaders(); + } + + SHADER_INIT + { + // If this would return false, then we should have fallen back to the DX6 one. + Assert( UsePixelShaders( params ) ); + + params[USINGPIXELSHADER]->SetIntValue( true ); + LoadBumpMap( BUMPMAP ); + } + + SHADER_FALLBACK + { + if ( !UsePixelShaders(params) ) + { + return "UnlitGeneric_DX6"; + } + + if ( g_pHardwareConfig->GetDXSupportLevel() < 90 ) + { + return "ParticleSphere_DX8"; + } + + return 0; + } + + SHADER_DRAW + { + SHADOW_STATE + { + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + + if ( params[DEPTHBLEND]->GetIntValue() ) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + } + + int tCoordDimensions[] = {2}; + pShaderShadow->VertexShaderVertexFormat( + VERTEX_POSITION | VERTEX_COLOR, 1, tCoordDimensions, 0 ); + + pShaderShadow->EnableBlending( true ); + pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA ); + pShaderShadow->EnableDepthWrites( false ); + + DECLARE_STATIC_VERTEX_SHADER( particlesphere_vs20 ); + SET_STATIC_VERTEX_SHADER( particlesphere_vs20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_STATIC_PIXEL_SHADER( particlesphere_ps20b ); + SET_STATIC_PIXEL_SHADER_COMBO( DEPTHBLEND, params[DEPTHBLEND]->GetIntValue() ); + SET_STATIC_PIXEL_SHADER( particlesphere_ps20b ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( particlesphere_ps20 ); + SET_STATIC_PIXEL_SHADER( particlesphere_ps20 ); + } + + FogToFogColor(); + } + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER0, BUMPMAP ); + + if ( params[DEPTHBLEND]->GetIntValue() ) + { + pShaderAPI->BindStandardTexture( SHADER_SAMPLER1, TEXTURE_FRAME_BUFFER_FULL_DEPTH ); + } + + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, params[LIGHT_POSITION]->GetVecValue() ); + + // Separate the light color into something that has a max value of 1 and a scale + // so the vertex shader can determine if it's going to overflow the color and scale back + // if it needs to. + // + // (It does this by seeing if the intensity*1/distSqr is > 1. If so, then it scales it so + // it is equal to 1). + const float *f = params[LIGHT_COLOR]->GetVecValue(); + Vector vLightColor( f[0], f[1], f[2] ); + float flScale = max( vLightColor.x, max( vLightColor.y, vLightColor.z ) ); + if ( flScale < 0.01f ) + flScale = 0.01f; + float vScaleVec[3] = { flScale, flScale, flScale }; + vLightColor /= flScale; + + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_1, vLightColor.Base() ); + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_2, vScaleVec ); + + pShaderAPI->SetPixelShaderFogParams( PSREG_FOG_PARAMS ); + + float vEyePos_SpecExponent[4]; + pShaderAPI->GetWorldSpaceCameraPosition( vEyePos_SpecExponent ); + vEyePos_SpecExponent[3] = 0.0f; + pShaderAPI->SetPixelShaderConstant( PSREG_EYEPOS_SPEC_EXPONENT, vEyePos_SpecExponent, 1 ); + + pShaderAPI->SetDepthFeatheringPixelShaderConstant( 0, params[DEPTHBLENDSCALE]->GetFloatValue() ); + + + // Compute the vertex shader index. + DECLARE_DYNAMIC_VERTEX_SHADER( particlesphere_vs20 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( FOGTYPE, s_pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + SET_DYNAMIC_VERTEX_SHADER( particlesphere_vs20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_DYNAMIC_PIXEL_SHADER( particlesphere_ps20b ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + SET_DYNAMIC_PIXEL_SHADER( particlesphere_ps20b ); + } + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( particlesphere_ps20 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + SET_DYNAMIC_PIXEL_SHADER( particlesphere_ps20 ); + } + } + Draw(); + } +END_SHADER diff --git a/materialsystem/stdshaders/particlesphere_ps11.fxc b/materialsystem/stdshaders/particlesphere_ps11.fxc new file mode 100644 index 0000000..49397b7 --- /dev/null +++ b/materialsystem/stdshaders/particlesphere_ps11.fxc @@ -0,0 +1,40 @@ + +const float3 g_OverbrightFactor : register( c0 ); +const float3 g_SelfIllumTint : register( c1 ); +const float3 g_EnvmapTint : register( c2 ); + +sampler BumpmapSampler : register( s0 ); + +struct PS_INPUT +{ + float2 vBumpTexCoord : TEXCOORD0; + float3 vTangentSpaceLightDir : TEXCOORD1; + float3 vAmbientColor : TEXCOORD2; + + float4 vDirLightScale : COLOR0; +}; + +float4 main( PS_INPUT i ) : COLOR +{ + float4 baseColor = tex2D( BumpmapSampler, i.vBumpTexCoord ); + + // Dot the bump normal and the light vector. + float4 vBumpMapNormal = (baseColor - 0.5); // The format of the sphere map is 0 to 1, + // so this is now -0.5 to 0.5. + + float3 vTangentSpaceLightDir = (i.vTangentSpaceLightDir - 0.5) * 2; // This is -1 to 1 + float4 vOutput = dot( vBumpMapNormal, vTangentSpaceLightDir ) + 0.5; + + // Scale by the light color outputted by the vertex shader (ie: based on distance). + vOutput *= i.vDirLightScale; + + // Add ambient. + vOutput += float4( i.vAmbientColor.x, i.vAmbientColor.y, i.vAmbientColor.z, 0 ); + + // Alpha = normal map alpha * vertex alpha + vOutput.a = baseColor.a * i.vDirLightScale.a; + + return vOutput; +} + + diff --git a/materialsystem/stdshaders/particlesphere_ps2x.fxc b/materialsystem/stdshaders/particlesphere_ps2x.fxc new file mode 100644 index 0000000..9871023 --- /dev/null +++ b/materialsystem/stdshaders/particlesphere_ps2x.fxc @@ -0,0 +1,67 @@ +// DYNAMIC: "PIXELFOGTYPE" "0..1" + +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX] +// STATIC: "DEPTHBLEND" "0..1" [ps20b] + +#include "shader_constant_register_map.h" + +const float4 g_FogParams : register( PSREG_FOG_PARAMS ); +const float4 g_EyePos_SpecExponent : register( PSREG_EYEPOS_SPEC_EXPONENT ); + + +const float4 g_DepthFeatheringConstants : register( c0 ); + +sampler BumpmapSampler : register( s0 ); +sampler DepthSampler : register( s1 ); + +struct PS_INPUT +{ + float2 vBumpTexCoord : TEXCOORD0; + float3 vTangentSpaceLightDir : TEXCOORD1; + float3 vAmbientColor : TEXCOORD2; +#if defined( _X360 ) + float4 vScreenPos_ReverseZ : TEXCOORD3; +#else + float4 vScreenPos : TEXCOORD3; +#endif + + float4 vDirLightScale : COLOR0; + + float4 worldPos_projPosZ : TEXCOORD7; // Necessary for pixel fog +}; + +float4 main( PS_INPUT i ) : COLOR +{ + float4 baseColor = tex2D( BumpmapSampler, i.vBumpTexCoord ); + + // Dot the bump normal and the light vector. + float4 vBumpMapNormal = (baseColor - 0.5); // The format of the sphere map is 0 to 1, + // so this is now -0.5 to 0.5. + + float3 vTangentSpaceLightDir = (i.vTangentSpaceLightDir - 0.5) * 2; // This is -1 to 1 + float4 vOutput = dot( vBumpMapNormal, vTangentSpaceLightDir ) + 0.5; + + // Scale by the light color outputted by the vertex shader (ie: based on distance). + vOutput *= i.vDirLightScale; + + // Add ambient. + vOutput += float4( i.vAmbientColor.x, i.vAmbientColor.y, i.vAmbientColor.z, 0 ); + + // Alpha = normal map alpha * vertex alpha + vOutput.a = baseColor.a * i.vDirLightScale.a; + + //Soft Particles FTW +# if (DEPTHBLEND == 1) +# if defined( _X360 ) + vOutput.a *= DepthFeathering( DepthSampler, i.vScreenPos_ReverseZ.xy / i.vScreenPos_ReverseZ.w, i.vScreenPos_ReverseZ.z, i.vScreenPos_ReverseZ.w, g_DepthFeatheringConstants ); +# else + vOutput.a *= DepthFeathering( DepthSampler, i.vScreenPos.xy / i.vScreenPos.w, i.vScreenPos.z, i.vScreenPos.w, g_DepthFeatheringConstants ); +# endif +# endif + + float fogFactor = CalcPixelFogFactor( PIXELFOGTYPE, g_FogParams, g_EyePos_SpecExponent.z, i.worldPos_projPosZ.z, i.worldPos_projPosZ.w ); + return FinalOutput( vOutput, fogFactor, PIXELFOGTYPE, TONEMAP_SCALE_LINEAR ); +} + + diff --git a/materialsystem/stdshaders/particlesphere_vs11.fxc b/materialsystem/stdshaders/particlesphere_vs11.fxc new file mode 100644 index 0000000..3a4abfa --- /dev/null +++ b/materialsystem/stdshaders/particlesphere_vs11.fxc @@ -0,0 +1,103 @@ +// DYNAMIC: "FOGTYPE" "0..1" + +#include "common_vs_fxc.h" + +static const int g_FogType = FOGTYPE; +const float4 cCustomConstants[6] : register( SHADER_SPECIFIC_CONST_0 ); + + +const float4 g_vLightPosition : register( SHADER_SPECIFIC_CONST_0 ); +const float4 g_vLightColor : register( SHADER_SPECIFIC_CONST_1 ); // range 0-1 +const float g_flLightIntensity : register( SHADER_SPECIFIC_CONST_2 ); // scales g_vLightColor + + +struct VS_INPUT +{ + // If this is float4, and the input is float3, the w component default to one. + float4 vPos : POSITION; + float2 vBumpTexCoord : TEXCOORD0; + float4 vAmbientColor : COLOR0; +}; + +struct VS_OUTPUT +{ + float4 projPos : POSITION; +#if !defined( _X360 ) + float fog : FOG; +#endif + float2 vBumpTexCoord : TEXCOORD0; + float3 vTangentSpaceLightDir : TEXCOORD1; + float3 vAmbientColor : TEXCOORD2; + float4 vDirLightScale : COLOR0; +}; + +VS_OUTPUT main( const VS_INPUT v ) +{ + VS_OUTPUT o; + + // Transform the input position. + float4 projPos = mul( v.vPos, cModelViewProj ); + o.projPos = projPos; + +#if !defined( _X360 ) + // Setup fog. + o.fog = CalcFog( mul( v.vPos, cModel[0] ), projPos, g_FogType ); +#endif + + // Copy texcoords over. + o.vBumpTexCoord = v.vBumpTexCoord; + + // Copy the vertex color over. + o.vAmbientColor = v.vAmbientColor; + + // ------------------------------------------------------------------------------ + // Generate a tangent space and rotate L. + // This can be thought of as rotating the normal map to face the viewer. + // + // This is useful when a particle is way off to the side of the screen. + // You should be looking at the half-sphere with a normal pointing from the + // particle to the viewer. Instead, you're looking at the half-sphere with + // a normal along Z. This tangent space builder code fixes the problem. + // + // Note that since the model and view matrices are identity, the coordinate + // system has X=right, Y=up, and Z=behind you (negative Z goes into the screen). + // ------------------------------------------------------------------------------ + + // This basis wants Z positive going into the screen so flip it here. + float4 vForward = normalize( float4( v.vPos.x, v.vPos.y, -v.vPos.z, 1 ) ); + + // This is the same as CrossProduct( vForward, Vector( 1, 0, 0 ) ) + float4 vUp = normalize( float4( 0, vForward.z, -vForward.y, vForward.w ) ); + + // vRight = CrossProduct( vUp, vForward ) + float4 vRight = vUp.yzxw * vForward.zxyw; + vRight += -vUp.zxyw * vForward.yzxw; + + + // Put the light in tangent space. + float4 vToLight = g_vLightPosition - v.vPos; + float4 vTangentSpaceLight = vRight*vToLight.x + vUp*vToLight.y + vForward*vToLight.z; + + // Output texcoord 1 holds the normalized transformed light direction. + o.vTangentSpaceLightDir = normalize( vTangentSpaceLight ) * 0.5 + 0.5; // make it 0-1 for the pixel shader + + + // Handle oversaturation here. The shader code already scaled the light color so its max value is 1, + // so if our intensity/distance scale is > 1, then all we need to do is use the light color. + float flTransposedLenSqr = dot( vTangentSpaceLight, vTangentSpaceLight ); + float flScaledIntensity = g_flLightIntensity / flTransposedLenSqr; + if ( flScaledIntensity > 1 ) + { + o.vDirLightScale.xyz = g_vLightColor; + } + else + { + o.vDirLightScale.xyz = g_vLightColor * flScaledIntensity; + } + + // Alpha comes right from the vertex color. + o.vDirLightScale.a = v.vAmbientColor.a; + return o; +} + + diff --git a/materialsystem/stdshaders/particlesphere_vs20.fxc b/materialsystem/stdshaders/particlesphere_vs20.fxc new file mode 100644 index 0000000..3d0a72f --- /dev/null +++ b/materialsystem/stdshaders/particlesphere_vs20.fxc @@ -0,0 +1,130 @@ +// DYNAMIC: "FOGTYPE" "0..1" + +#include "common_vs_fxc.h" + +static const int g_FogType = FOGTYPE; +const float4 cCustomConstants[6] : register( SHADER_SPECIFIC_CONST_0 ); + + +const float4 g_vLightPosition : register( SHADER_SPECIFIC_CONST_0 ); +const float4 g_vLightColor : register( SHADER_SPECIFIC_CONST_1 ); // range 0-1 +const float g_flLightIntensity : register( SHADER_SPECIFIC_CONST_2 ); // scales g_vLightColor + + +struct VS_INPUT +{ + // If this is float4, and the input is float3, the w component default to one. + float4 vPos : POSITION; + float2 vBumpTexCoord : TEXCOORD0; + float4 vAmbientColor : COLOR0; +}; + +struct VS_OUTPUT +{ + float4 projPos : POSITION; +#if !defined( _X360 ) + float fog : FOG; +#endif + float2 vBumpTexCoord : TEXCOORD0; + float3 vTangentSpaceLightDir : TEXCOORD1; + float3 vAmbientColor : TEXCOORD2; + +#if defined( _X360 ) + float4 vScreenPos_ReverseZ : TEXCOORD3; +#else + float4 vScreenPos : TEXCOORD3; +#endif + + + float4 vDirLightScale : COLOR0; + + float4 worldPos_projPosZ : TEXCOORD7; // Necessary for pixel fog +}; + +VS_OUTPUT main( const VS_INPUT v ) +{ + VS_OUTPUT o; + + // Transform the input position. + float4 projPos = mul( v.vPos, cModelViewProj ); + o.projPos = projPos; + projPos.z = dot( v.vPos, cModelViewProjZ ); + +#if defined( _X360 ) + o.vScreenPos_ReverseZ.x = projPos.x; + o.vScreenPos_ReverseZ.y = -projPos.y; // invert Y + o.vScreenPos_ReverseZ.xy = (o.vScreenPos_ReverseZ.xy + projPos.w) * 0.5f; + o.vScreenPos_ReverseZ.z = projPos.w - projPos.z; + o.vScreenPos_ReverseZ.w = projPos.w; +#else + o.vScreenPos.x = projPos.x; + o.vScreenPos.y = -projPos.y; // invert Y + o.vScreenPos.xy = (o.vScreenPos.xy + projPos.w) * 0.5f; + o.vScreenPos.z = projPos.z; + o.vScreenPos.w = projPos.w; +#endif + + o.worldPos_projPosZ = float4( v.vPos.xyz, projPos.z ); + +#if !defined( _X360 ) + // Setup fog. + o.fog = CalcFog( mul( v.vPos, cModel[0] ), projPos, g_FogType ); +#endif + + // Copy texcoords over. + o.vBumpTexCoord = v.vBumpTexCoord; + + // Copy the vertex color over. + o.vAmbientColor = v.vAmbientColor; + + // ------------------------------------------------------------------------------ + // Generate a tangent space and rotate L. + // This can be thought of as rotating the normal map to face the viewer. + // + // This is useful when a particle is way off to the side of the screen. + // You should be looking at the half-sphere with a normal pointing from the + // particle to the viewer. Instead, you're looking at the half-sphere with + // a normal along Z. This tangent space builder code fixes the problem. + // + // Note that since the model and view matrices are identity, the coordinate + // system has X=right, Y=up, and Z=behind you (negative Z goes into the screen). + // ------------------------------------------------------------------------------ + + // This basis wants Z positive going into the screen so flip it here. + float4 vForward = normalize( float4( v.vPos.x, v.vPos.y, -v.vPos.z, 1 ) ); + + // This is the same as CrossProduct( vForward, Vector( 1, 0, 0 ) ) + float4 vUp = normalize( float4( 0, vForward.z, -vForward.y, vForward.w ) ); + + // vRight = CrossProduct( vUp, vForward ) + float4 vRight = vUp.yzxw * vForward.zxyw; + vRight += -vUp.zxyw * vForward.yzxw; + + + // Put the light in tangent space. + float4 vToLight = g_vLightPosition - v.vPos; + float4 vTangentSpaceLight = vRight*vToLight.x + vUp*vToLight.y + vForward*vToLight.z; + + // Output texcoord 1 holds the normalized transformed light direction. + o.vTangentSpaceLightDir = normalize( vTangentSpaceLight ) * 0.5 + 0.5; // make it 0-1 for the pixel shader + + + // Handle oversaturation here. The shader code already scaled the light color so its max value is 1, + // so if our intensity/distance scale is > 1, then all we need to do is use the light color. + float flTransposedLenSqr = dot( vTangentSpaceLight, vTangentSpaceLight ); + float flScaledIntensity = g_flLightIntensity / flTransposedLenSqr; + if ( flScaledIntensity > 1 ) + { + o.vDirLightScale.xyz = g_vLightColor; + } + else + { + o.vDirLightScale.xyz = g_vLightColor * flScaledIntensity; + } + + // Alpha comes right from the vertex color. + o.vDirLightScale.a = v.vAmbientColor.a; + return o; +} + + diff --git a/materialsystem/stdshaders/portal.cpp b/materialsystem/stdshaders/portal.cpp new file mode 100644 index 0000000..e929f13 --- /dev/null +++ b/materialsystem/stdshaders/portal.cpp @@ -0,0 +1,262 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//=============================================================================// + +#include "BaseVSShader.h" +#include "portal_vs20.inc" +#include "portal_ps20.inc" +#include "portal_ps20b.inc" +#include "convar.h" +#include "cpp_shader_constant_register_map.h" + + +DEFINE_FALLBACK_SHADER( Portal, Portal_DX90 ) + +BEGIN_VS_SHADER( Portal_DX90, + "Help for Portal shader" ) + + BEGIN_SHADER_PARAMS + SHADER_PARAM_OVERRIDE( COLOR, SHADER_PARAM_TYPE_COLOR, "{255 255 255}", "unused", SHADER_PARAM_NOT_EDITABLE ) + SHADER_PARAM_OVERRIDE( ALPHA, SHADER_PARAM_TYPE_FLOAT, "1.0", "unused", SHADER_PARAM_NOT_EDITABLE ) + SHADER_PARAM( STATICAMOUNT, SHADER_PARAM_TYPE_FLOAT, "0.0", "Amount of the static blend texture to blend into the base texture" ) + SHADER_PARAM( STATICBLENDTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "When adding static, this is the texture that gets blended in" ) + SHADER_PARAM( STATICBLENDTEXTUREFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "" ) + SHADER_PARAM( ALPHAMASKTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "An alpha mask for odd shaped portals" ) + SHADER_PARAM( ALPHAMASKTEXTUREFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "" ) + SHADER_PARAM( RENDERFIXZ, SHADER_PARAM_TYPE_INTEGER, "0", "Special depth handling, intended for rendering bug workarounds for extremely close polygons" ) + SHADER_PARAM( USEALTERNATEVIEWMATRIX, SHADER_PARAM_TYPE_INTEGER, "1", "Use the alternate view matrix instead of the current view matrix" ) + SHADER_PARAM( ALTERNATEVIEWMATRIX, SHADER_PARAM_TYPE_MATRIX, "0", "The alternate view matrix to use when $usealternateviewmatrix is enabled" ) + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + SET_FLAGS( MATERIAL_VAR_TRANSLUCENT ); + if( !params[BASETEXTURE]->IsDefined() ) + { + SET_FLAGS2( MATERIAL_VAR2_NEEDS_POWER_OF_TWO_FRAME_BUFFER_TEXTURE ); + } + } + + SHADER_FALLBACK + { + if ( g_pHardwareConfig->GetDXSupportLevel() < 90 ) + return "Portal_DX80"; + + return 0; + } + + SHADER_INIT + { + if ( params[BASETEXTURE]->IsDefined() ) + { + if ( IsX360() ) + { + // prevent unused rt access + IMaterialVar* pNameVar = params[BASETEXTURE]; + const char *pStringValue = pNameVar->GetStringValue(); + if ( !V_stricmp( pStringValue, "_rt_portal1" ) || !V_stricmp( pStringValue, "_rt_portal2" ) ) + { + pNameVar->SetStringValue( "white" ); + } + } + LoadTexture( BASETEXTURE, TEXTUREFLAGS_SRGB ); + } + + if ( params[STATICBLENDTEXTURE]->IsDefined() ) + LoadTexture( STATICBLENDTEXTURE ); + if ( params[ALPHAMASKTEXTURE]->IsDefined() ) + LoadTexture( ALPHAMASKTEXTURE ); + + if ( !params[STATICAMOUNT]->IsDefined() ) + params[STATICAMOUNT]->SetFloatValue( 0.0f ); + + if ( !params[STATICAMOUNT]->IsDefined() ) + params[STATICAMOUNT]->SetFloatValue( 0.0f ); + + if ( !params[STATICBLENDTEXTURE]->IsDefined() ) + params[STATICBLENDTEXTURE]->SetIntValue( 0 ); + if ( !params[STATICBLENDTEXTUREFRAME]->IsDefined() ) + params[STATICBLENDTEXTUREFRAME]->SetIntValue( 0 ); + + if ( !params[ALPHAMASKTEXTURE]->IsDefined() ) + params[ALPHAMASKTEXTURE]->SetIntValue( 0 ); + if ( !params[ALPHAMASKTEXTUREFRAME]->IsDefined() ) + params[ALPHAMASKTEXTUREFRAME]->SetIntValue( 0 ); + + if ( !params[RENDERFIXZ]->IsDefined() ) + params[RENDERFIXZ]->SetIntValue( 0 ); + + if ( !params[USEALTERNATEVIEWMATRIX]->IsDefined() ) + params[USEALTERNATEVIEWMATRIX]->SetIntValue( 0 ); + + if ( !params[ALTERNATEVIEWMATRIX]->IsDefined() ) + { + VMatrix matIdentity; + matIdentity.Identity(); + params[ALTERNATEVIEWMATRIX]->SetMatrixValue( matIdentity ); + } + } + + SHADER_DRAW + { + bool bStaticBlendTexture = params[STATICBLENDTEXTURE]->IsTexture(); + bool bAlphaMaskTexture = ( params[ALPHAMASKTEXTURE]->IsTexture()? 1 : 0 ); + + float fStaticAmount = params[STATICAMOUNT]->GetFloatValue(); + + SHADOW_STATE + { + SetInitialShadowState(); + FogToFogColor(); + + if( params[RENDERFIXZ]->GetIntValue() == 0 ) + { + //pShaderShadow->EnablePolyOffset( SHADER_POLYOFFSET_DECAL ); //a portal is effectively a decal on top of a wall + pShaderShadow->DepthFunc( SHADER_DEPTHFUNC_NEAREROREQUAL ); + } + else + { + pShaderShadow->EnablePolyOffset( SHADER_POLYOFFSET_DISABLE ); + pShaderShadow->DepthFunc( SHADER_DEPTHFUNC_ALWAYS ); + pShaderShadow->EnableDepthTest( false ); + pShaderShadow->EnableDepthWrites( false ); + } + + pShaderShadow->EnableAlphaTest( true ); + + if( bAlphaMaskTexture ) + { + pShaderShadow->EnableBlending( true ); + pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA ); + } + else + { + pShaderShadow->EnableBlending( false ); + } + + pShaderShadow->EnableSRGBWrite( true ); + + int fmt = VERTEX_POSITION | VERTEX_NORMAL; + int userDataSize = 0; + int iTexCoords = 1; + if( IS_FLAG_SET( MATERIAL_VAR_MODEL ) ) + { + userDataSize = 4; + } + else + { + fmt |= VERTEX_TANGENT_S | VERTEX_TANGENT_T; + } + pShaderShadow->VertexShaderVertexFormat( fmt, iTexCoords, NULL, userDataSize ); + + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, true ); + + if( bStaticBlendTexture || bAlphaMaskTexture ) + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + + if( bStaticBlendTexture && bAlphaMaskTexture ) + pShaderShadow->EnableTexture( SHADER_SAMPLER2, true ); + + DECLARE_STATIC_VERTEX_SHADER( portal_vs20 ); + SET_STATIC_VERTEX_SHADER_COMBO( HASALPHAMASK, bAlphaMaskTexture ); + SET_STATIC_VERTEX_SHADER_COMBO( HASSTATICTEXTURE, bStaticBlendTexture ); + SET_STATIC_VERTEX_SHADER_COMBO( USEALTERNATEVIEW, (params[USEALTERNATEVIEWMATRIX]->GetIntValue() != 0) ); + SET_STATIC_VERTEX_SHADER( portal_vs20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_STATIC_PIXEL_SHADER( portal_ps20b ); + SET_STATIC_PIXEL_SHADER_COMBO( HASALPHAMASK, bAlphaMaskTexture ); + SET_STATIC_PIXEL_SHADER_COMBO( HASSTATICTEXTURE, bStaticBlendTexture ); + SET_STATIC_PIXEL_SHADER( portal_ps20b ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( portal_ps20 ); + SET_STATIC_PIXEL_SHADER_COMBO( HASALPHAMASK, bAlphaMaskTexture ); + SET_STATIC_PIXEL_SHADER_COMBO( HASSTATICTEXTURE, bStaticBlendTexture ); + SET_STATIC_PIXEL_SHADER( portal_ps20 ); + } + + } + DYNAMIC_STATE + { + pShaderAPI->SetDefaultState(); + + //x is static, y is inverse static + float pc0[4] = { fStaticAmount, 1.0f - fStaticAmount, 0.0f, 0.0f }; + pShaderAPI->SetPixelShaderConstant( 0, pc0 ); + + pShaderAPI->SetPixelShaderFogParams( PSREG_FOG_PARAMS ); + + float vEyePos_SpecExponent[4]; + pShaderAPI->GetWorldSpaceCameraPosition( vEyePos_SpecExponent ); + vEyePos_SpecExponent[3] = 0.0f; + pShaderAPI->SetPixelShaderConstant( PSREG_EYEPOS_SPEC_EXPONENT, vEyePos_SpecExponent, 1 ); + + if ( params[BASETEXTURE]->IsTexture() ) + BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME ); + else + pShaderAPI->BindStandardTexture( SHADER_SAMPLER0, TEXTURE_FRAME_BUFFER_FULL_TEXTURE_0 ); + + bool bHasStatic = (fStaticAmount > 0.0f); + bool bUsingStaticTexture = (bStaticBlendTexture && bHasStatic); + + if ( bAlphaMaskTexture ) + { + BindTexture( SHADER_SAMPLER1, ALPHAMASKTEXTURE, ALPHAMASKTEXTUREFRAME ); + if ( bUsingStaticTexture ) + BindTexture( SHADER_SAMPLER2, STATICBLENDTEXTURE, STATICBLENDTEXTUREFRAME ); + } + else + { + if ( bUsingStaticTexture ) + BindTexture( SHADER_SAMPLER1, STATICBLENDTEXTURE, STATICBLENDTEXTUREFRAME ); + } + + if ( params[USEALTERNATEVIEWMATRIX]->GetIntValue() != 0 ) + { + const VMatrix &matCustomView = params[ALTERNATEVIEWMATRIX]->GetMatrixValue(); + + VMatrix matProj; + pShaderAPI->GetMatrix( MATERIAL_PROJECTION, matProj.Base() ); + MatrixTranspose( matProj, matProj ); + + VMatrix matFinal; + MatrixMultiply( matProj, matCustomView, matFinal ); + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, matFinal.Base(), 4 ); + } + + DECLARE_DYNAMIC_VERTEX_SHADER( portal_vs20 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, pShaderAPI->GetCurrentNumBones() > 0 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( ADDSTATIC, bHasStatic ); + SET_DYNAMIC_VERTEX_SHADER( portal_vs20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_DYNAMIC_PIXEL_SHADER( portal_ps20b ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( ADDSTATIC, bHasStatic ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( HDRENABLED, IsHDREnabled() ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + SET_DYNAMIC_PIXEL_SHADER( portal_ps20b ); + } + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( portal_ps20 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( ADDSTATIC, bHasStatic ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( HDRENABLED, IsHDREnabled() ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + SET_DYNAMIC_PIXEL_SHADER( portal_ps20 ); + } + } + + Draw(); + } + +END_SHADER + + diff --git a/materialsystem/stdshaders/portal_dx60.cpp b/materialsystem/stdshaders/portal_dx60.cpp new file mode 100644 index 0000000..489db66 --- /dev/null +++ b/materialsystem/stdshaders/portal_dx60.cpp @@ -0,0 +1,205 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//=============================================================================// + +#include "BaseVSShader.h" +#include "convar.h" +#include "d3dx.h" + +DEFINE_FALLBACK_SHADER( Portal, Portal_DX60 ) + +BEGIN_VS_SHADER( Portal_DX60, + "Help for Portal_DX60 shader" ) + + BEGIN_SHADER_PARAMS + SHADER_PARAM_OVERRIDE( COLOR, SHADER_PARAM_TYPE_COLOR, "{255 255 255}", "unused", SHADER_PARAM_NOT_EDITABLE ) + SHADER_PARAM_OVERRIDE( ALPHA, SHADER_PARAM_TYPE_FLOAT, "1.0", "unused", SHADER_PARAM_NOT_EDITABLE ) + SHADER_PARAM( STATICAMOUNT, SHADER_PARAM_TYPE_FLOAT, "0.0", "Amount of the static blend texture to blend into the base texture" ) + SHADER_PARAM( STATICBLENDTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "When adding static, this is the texture that gets blended in" ) + SHADER_PARAM( STATICBLENDTEXTUREFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "" ) + SHADER_PARAM( ALPHAMASKTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "An alpha mask for odd shaped portals" ) + SHADER_PARAM( ALPHAMASKTEXTUREFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "" ) + SHADER_PARAM( RENDERFIXZ, SHADER_PARAM_TYPE_INTEGER, "0", "Special depth handling, intended for rendering bug workarounds for extremely close polygons" ) + END_SHADER_PARAMS + +SHADER_INIT_PARAMS() +{ + SET_FLAGS( MATERIAL_VAR_TRANSLUCENT ); +} + +SHADER_FALLBACK +{ + return 0; //it doesn't get any simpler than this +} + +SHADER_INIT +{ + if( params[STATICBLENDTEXTURE]->IsDefined() ) + LoadTexture( STATICBLENDTEXTURE ); + if( params[ALPHAMASKTEXTURE]->IsDefined() ) + LoadTexture( ALPHAMASKTEXTURE ); + + if( !params[STATICAMOUNT]->IsDefined() ) + params[STATICAMOUNT]->SetFloatValue( 0.0f ); + + if( !params[STATICAMOUNT]->IsDefined() ) + params[STATICAMOUNT]->SetFloatValue( 0.0f ); + + if( !params[STATICBLENDTEXTURE]->IsDefined() ) + params[STATICBLENDTEXTURE]->SetIntValue( 0 ); + if( !params[STATICBLENDTEXTUREFRAME]->IsDefined() ) + params[STATICBLENDTEXTUREFRAME]->SetIntValue( 0 ); + + if( !params[ALPHAMASKTEXTURE]->IsDefined() ) + params[ALPHAMASKTEXTURE]->SetIntValue( 0 ); + if( !params[ALPHAMASKTEXTUREFRAME]->IsDefined() ) + params[ALPHAMASKTEXTUREFRAME]->SetIntValue( 0 ); + + if( !params[RENDERFIXZ]->IsDefined() ) + params[RENDERFIXZ]->SetIntValue( 0 ); +} + +SHADER_DRAW +{ + bool bAlphaMaskTexture = params[ALPHAMASKTEXTURE]->IsTexture(); + + SHADOW_STATE + { + SetInitialShadowState(); + + bool bIsModel = IS_FLAG_SET( MATERIAL_VAR_MODEL ); + + FogToFogColor(); + + if( params[RENDERFIXZ]->GetIntValue() == 0 ) + { + //pShaderShadow->EnablePolyOffset( SHADER_POLYOFFSET_DECAL ); //a portal is effectively a decal on top of a wall + pShaderShadow->DepthFunc( SHADER_DEPTHFUNC_NEAREROREQUAL ); + } + else + { + pShaderShadow->EnablePolyOffset( SHADER_POLYOFFSET_DISABLE ); + pShaderShadow->DepthFunc( SHADER_DEPTHFUNC_ALWAYS ); + pShaderShadow->EnableDepthTest( false ); + pShaderShadow->EnableDepthWrites( false ); + } + + pShaderShadow->EnableDepthWrites( true ); + + if( bAlphaMaskTexture ) + { + pShaderShadow->EnableAlphaTest( true ); + if( bIsModel ) + pShaderShadow->DrawFlags( SHADER_DRAW_POSITION | SHADER_DRAW_TEXCOORD0 | SHADER_DRAW_TEXCOORD1 ); + else + pShaderShadow->DrawFlags( SHADER_DRAW_POSITION | SHADER_DRAW_LIGHTMAP_TEXCOORD0 | SHADER_DRAW_LIGHTMAP_TEXCOORD1 ); + } + else + { + if( bIsModel ) + pShaderShadow->DrawFlags( SHADER_DRAW_POSITION | SHADER_DRAW_TEXCOORD0 ); + else + pShaderShadow->DrawFlags( SHADER_DRAW_POSITION | SHADER_DRAW_LIGHTMAP_TEXCOORD0 ); + } + } + DYNAMIC_STATE + { + pShaderAPI->SetDefaultState(); + } + + if( bAlphaMaskTexture ) + StaticPass_WithAlphaMask( pShaderShadow, pShaderAPI, params ); //portal static texture blending + else + StaticPass_NoAlphaMask( pShaderShadow, pShaderAPI, params ); //portal static texture blending +} + + +void StaticPass_NoAlphaMask( IShaderShadow *pShaderShadow, IShaderDynamicAPI *pShaderAPI, IMaterialVar **params ) +{ + bool bStaticBlendTexture = params[STATICBLENDTEXTURE]->IsTexture(); + + SHADOW_STATE + { + if( bStaticBlendTexture ) + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + } + DYNAMIC_STATE + { + if( bStaticBlendTexture ) + BindTexture( SHADER_SAMPLER0, STATICBLENDTEXTURE, STATICBLENDTEXTUREFRAME ); + else + pShaderAPI->Color4f( 0.5f, 0.5f, 0.5f, 0.0f ); + } + Draw(); +} + + +void StaticPass_WithAlphaMask( IShaderShadow *pShaderShadow, IShaderDynamicAPI *pShaderAPI, IMaterialVar **params ) +{ + bool bStaticBlendTexture = params[STATICBLENDTEXTURE]->IsTexture(); + + SHADOW_STATE + { + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + pShaderShadow->EnableBlending( true ); + pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA ); + + pShaderShadow->EnableCustomPixelPipe( true ); + pShaderShadow->CustomTextureStages( 2 ); + + //portal static + if( bStaticBlendTexture ) + { + pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE0, + SHADER_TEXCHANNEL_COLOR, + SHADER_TEXOP_SELECTARG1, + SHADER_TEXARG_TEXTURE, SHADER_TEXARG_TEXTURE ); + } + else + { + pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE0, + SHADER_TEXCHANNEL_COLOR, + SHADER_TEXOP_SELECTARG1, + SHADER_TEXARG_CONSTANTCOLOR, SHADER_TEXARG_CONSTANTCOLOR ); + } + + pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE0, + SHADER_TEXCHANNEL_ALPHA, + SHADER_TEXOP_SELECTARG1, + SHADER_TEXARG_ZERO, SHADER_TEXARG_ZERO ); + + + //alpha mask + pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE1, + SHADER_TEXCHANNEL_COLOR, + SHADER_TEXOP_SELECTARG1, + SHADER_TEXARG_PREVIOUSSTAGE, SHADER_TEXARG_PREVIOUSSTAGE ); + + pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE1, + SHADER_TEXCHANNEL_ALPHA, + SHADER_TEXOP_SELECTARG1, + SHADER_TEXARG_TEXTUREALPHA, SHADER_TEXARG_TEXTUREALPHA ); + } + DYNAMIC_STATE + { + if( bStaticBlendTexture ) + BindTexture( SHADER_SAMPLER0, STATICBLENDTEXTURE, STATICBLENDTEXTUREFRAME ); + else + pShaderAPI->Color4f( 0.5f, 0.5f, 0.5f, 0.0f ); + + BindTexture( SHADER_SAMPLER1, ALPHAMASKTEXTURE, ALPHAMASKTEXTUREFRAME ); + } + Draw(); + SHADOW_STATE + { + pShaderShadow->EnableCustomPixelPipe( false ); + } +} + +END_SHADER + + diff --git a/materialsystem/stdshaders/portal_dx80.cpp b/materialsystem/stdshaders/portal_dx80.cpp new file mode 100644 index 0000000..079b653 --- /dev/null +++ b/materialsystem/stdshaders/portal_dx80.cpp @@ -0,0 +1,307 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//=============================================================================// + +#include "BaseVSShader.h" +#include "portal_vs11.inc" +#include "portal_ps11.inc" +#include "convar.h" + + +DEFINE_FALLBACK_SHADER( Portal, Portal_DX80 ) + +BEGIN_VS_SHADER( Portal_DX80, + "Help for Portal shader" ) + + BEGIN_SHADER_PARAMS + SHADER_PARAM_OVERRIDE( COLOR, SHADER_PARAM_TYPE_COLOR, "{255 255 255}", "unused", SHADER_PARAM_NOT_EDITABLE ) + SHADER_PARAM_OVERRIDE( ALPHA, SHADER_PARAM_TYPE_FLOAT, "1.0", "unused", SHADER_PARAM_NOT_EDITABLE ) + SHADER_PARAM( STATICAMOUNT, SHADER_PARAM_TYPE_FLOAT, "0.0", "Amount of the static blend texture to blend into the base texture" ) + SHADER_PARAM( STATICBLENDTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "When adding static, this is the texture that gets blended in" ) + SHADER_PARAM( STATICBLENDTEXTUREFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "" ) + SHADER_PARAM( ALPHAMASKTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "An alpha mask for odd shaped portals" ) + SHADER_PARAM( ALPHAMASKTEXTUREFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "" ) + SHADER_PARAM( RENDERFIXZ, SHADER_PARAM_TYPE_INTEGER, "0", "Special depth handling, intended for rendering bug workarounds for extremely close polygons" ) + SHADER_PARAM( USEALTERNATEVIEWMATRIX, SHADER_PARAM_TYPE_INTEGER, "1", "Use the alternate view matrix instead of the current view matrix" ) + SHADER_PARAM( ALTERNATEVIEWMATRIX, SHADER_PARAM_TYPE_MATRIX, "0", "The alternate view matrix to use when $usealternateviewmatrix is enabled" ) + END_SHADER_PARAMS + +SHADER_INIT_PARAMS() +{ + SET_FLAGS( MATERIAL_VAR_TRANSLUCENT ); + if( !params[BASETEXTURE]->IsDefined() ) + { + SET_FLAGS2( MATERIAL_VAR2_NEEDS_POWER_OF_TWO_FRAME_BUFFER_TEXTURE ); + } +} + +SHADER_FALLBACK +{ + if( !g_pHardwareConfig->SupportsVertexAndPixelShaders() ) + return "Portal_DX60"; + + return 0; +} + +int iMaxTextureStages; + +SHADER_INIT +{ + iMaxTextureStages = min( 3, g_pHardwareConfig->GetSamplerCount() ); + + if (params[BASETEXTURE]->IsDefined() ) + LoadTexture( BASETEXTURE ); + if( params[STATICBLENDTEXTURE]->IsDefined() ) + LoadTexture( STATICBLENDTEXTURE ); + if( (iMaxTextureStages > 1) && params[ALPHAMASKTEXTURE]->IsDefined() ) + LoadTexture( ALPHAMASKTEXTURE ); + + if( !params[STATICAMOUNT]->IsDefined() ) + params[STATICAMOUNT]->SetFloatValue( 0.0f ); + + if( !params[STATICAMOUNT]->IsDefined() ) + params[STATICAMOUNT]->SetFloatValue( 0.0f ); + + if( !params[STATICBLENDTEXTURE]->IsDefined() ) + params[STATICBLENDTEXTURE]->SetIntValue( 0 ); + if( !params[STATICBLENDTEXTUREFRAME]->IsDefined() ) + params[STATICBLENDTEXTUREFRAME]->SetIntValue( 0 ); + + if( !params[ALPHAMASKTEXTURE]->IsDefined() ) + params[ALPHAMASKTEXTURE]->SetIntValue( 0 ); + if( !params[ALPHAMASKTEXTUREFRAME]->IsDefined() ) + params[ALPHAMASKTEXTUREFRAME]->SetIntValue( 0 ); + + if( !params[RENDERFIXZ]->IsDefined() ) + params[RENDERFIXZ]->SetIntValue( 0 ); + + if ( !params[USEALTERNATEVIEWMATRIX]->IsDefined() ) + params[USEALTERNATEVIEWMATRIX]->SetIntValue( 0 ); + + if ( !params[ALTERNATEVIEWMATRIX]->IsDefined() ) + { + VMatrix matIdentity; + matIdentity.Identity(); + params[ALTERNATEVIEWMATRIX]->SetMatrixValue( matIdentity ); + } +} + +SHADER_DRAW +{ + bool bStaticBlendTexture = params[STATICBLENDTEXTURE]->IsTexture(); + bool bAlphaMaskTexture = ((iMaxTextureStages > 1) && (params[ALPHAMASKTEXTURE]->IsTexture()))?(1):(0); //must support at least 2 texture stages to use any kind of mask + + float fStaticAmount = params[STATICAMOUNT]->GetFloatValue(); + + SHADOW_STATE + { + SetInitialShadowState(); + FogToFogColor(); + + if( params[RENDERFIXZ]->GetIntValue() == 0 ) + { + //pShaderShadow->EnablePolyOffset( SHADER_POLYOFFSET_DECAL ); //a portal is effectively a decal on top of a wall + pShaderShadow->DepthFunc( SHADER_DEPTHFUNC_NEAREROREQUAL ); + } + else + { + pShaderShadow->EnablePolyOffset( SHADER_POLYOFFSET_DISABLE ); + pShaderShadow->DepthFunc( SHADER_DEPTHFUNC_ALWAYS ); + pShaderShadow->EnableDepthTest( false ); + pShaderShadow->EnableDepthWrites( false ); + } + + pShaderShadow->EnableAlphaTest( true ); + + if( ((iMaxTextureStages < 3) && bStaticBlendTexture) || bAlphaMaskTexture ) //in multipass modes, we need alpha to mix portal static, other + { + pShaderShadow->EnableBlending( true ); + pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA ); + } + else + { + pShaderShadow->EnableBlending( false ); + } + + int fmt = VERTEX_POSITION | VERTEX_NORMAL; + int userDataSize = 0; + int iTexCoords = 1; + if( IS_FLAG_SET( MATERIAL_VAR_MODEL ) ) + { + userDataSize = 4; + } + else + { + fmt |= VERTEX_TANGENT_S | VERTEX_TANGENT_T; + } + pShaderShadow->VertexShaderVertexFormat( fmt, iTexCoords, NULL, userDataSize ); + + DECLARE_STATIC_VERTEX_SHADER( portal_vs11 ); + SET_STATIC_VERTEX_SHADER_COMBO( MAXTEXTURESTAGES, (iMaxTextureStages - 1) ); + SET_STATIC_VERTEX_SHADER_COMBO( HASALPHAMASK, bAlphaMaskTexture ); + SET_STATIC_VERTEX_SHADER_COMBO( HASSTATICTEXTURE, bStaticBlendTexture ); + SET_STATIC_VERTEX_SHADER_COMBO( USEALTERNATEVIEW, (params[USEALTERNATEVIEWMATRIX]->GetIntValue() != 0) ); + SET_STATIC_VERTEX_SHADER( portal_vs11 ); + + DECLARE_STATIC_PIXEL_SHADER( portal_ps11 ); + SET_STATIC_PIXEL_SHADER_COMBO( MAXTEXTURESTAGES, (iMaxTextureStages - 1) ); + SET_STATIC_PIXEL_SHADER_COMBO( HASALPHAMASK, bAlphaMaskTexture ); + SET_STATIC_PIXEL_SHADER_COMBO( HASSTATICTEXTURE, bStaticBlendTexture ); + SET_STATIC_PIXEL_SHADER( portal_ps11 ); + + } + DYNAMIC_STATE + { + pShaderAPI->SetDefaultState(); + + //x is static, y is inverse static + float pc0[4] = { fStaticAmount, 1.0f - fStaticAmount, 0.0f, 0.0f }; + pShaderAPI->SetPixelShaderConstant( 0, pc0 ); + + if ( params[USEALTERNATEVIEWMATRIX]->GetIntValue() != 0 ) + { + const VMatrix &matCustomView = params[ALTERNATEVIEWMATRIX]->GetMatrixValue(); + + VMatrix matProj; + pShaderAPI->GetMatrix( MATERIAL_PROJECTION, matProj.Base() ); + MatrixTranspose( matProj, matProj ); + + VMatrix matFinal; + MatrixMultiply( matProj, matCustomView, matFinal ); + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, matFinal.Base(), 4 ); + } + } + + + if( iMaxTextureStages == 3 ) + { + SinglePass( pShaderShadow, pShaderAPI, params, fStaticAmount, bStaticBlendTexture, bAlphaMaskTexture ); + } + else + { + MultiPass_CutoutPass( pShaderShadow, pShaderAPI, params, bAlphaMaskTexture ); + if( bStaticBlendTexture ) //if we don't have a static texture, the cutout pass will mix in gray for any static amount + MultiPass_StaticPass( pShaderShadow, pShaderAPI, params, bAlphaMaskTexture ); + } +} + +void SinglePass( IShaderShadow *pShaderShadow, IShaderDynamicAPI *pShaderAPI, IMaterialVar **params, float fStaticAmount, bool bStaticBlendTexture, bool bAlphaMaskTexture ) +{ + SHADOW_STATE + { + // source render target that contains the image that we are warping. + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + + if( bStaticBlendTexture || bAlphaMaskTexture ) + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + + if( bStaticBlendTexture && bAlphaMaskTexture ) + pShaderShadow->EnableTexture( SHADER_SAMPLER2, true ); + + } + DYNAMIC_STATE + { + if ( params[BASETEXTURE]->IsTexture() ) + BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME ); + else + pShaderAPI->BindStandardTexture( SHADER_SAMPLER0, TEXTURE_FRAME_BUFFER_FULL_TEXTURE_0 ); + + bool bHasStatic = (fStaticAmount > 0.0f); + bool bUsingStaticTexture = (bStaticBlendTexture && bHasStatic); + + if ( bAlphaMaskTexture ) + { + BindTexture( SHADER_SAMPLER1, ALPHAMASKTEXTURE, ALPHAMASKTEXTUREFRAME ); + if ( bUsingStaticTexture ) + BindTexture( SHADER_SAMPLER2, STATICBLENDTEXTURE, STATICBLENDTEXTUREFRAME ); + } + else + { + if ( bUsingStaticTexture ) + BindTexture( SHADER_SAMPLER1, STATICBLENDTEXTURE, STATICBLENDTEXTUREFRAME ); + } + + int iHasStatic = bHasStatic?1:0; + + DECLARE_DYNAMIC_VERTEX_SHADER( portal_vs11 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, pShaderAPI->GetCurrentNumBones() > 0 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( ADDSTATIC, iHasStatic ); + SET_DYNAMIC_VERTEX_SHADER( portal_vs11 ); + + DECLARE_DYNAMIC_PIXEL_SHADER( portal_ps11 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( ADDSTATIC, iHasStatic ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + SET_DYNAMIC_PIXEL_SHADER( portal_ps11 ); + } + Draw(); +} + + +void MultiPass_CutoutPass( IShaderShadow *pShaderShadow, IShaderDynamicAPI *pShaderAPI, IMaterialVar **params, bool bAlphaMaskTexture ) +{ + //the basic portal effect + SHADOW_STATE + { + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + + if( bAlphaMaskTexture ) + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + } + DYNAMIC_STATE + { + if ( params[BASETEXTURE]->IsTexture() ) + BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME ); + else + pShaderAPI->BindStandardTexture( SHADER_SAMPLER0, TEXTURE_FRAME_BUFFER_FULL_TEXTURE_0 ); + + if( bAlphaMaskTexture ) + BindTexture( SHADER_SAMPLER1, ALPHAMASKTEXTURE, ALPHAMASKTEXTUREFRAME ); + + DECLARE_DYNAMIC_VERTEX_SHADER( portal_vs11 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, pShaderAPI->GetCurrentNumBones() > 0 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( ADDSTATIC, 0 ); + SET_DYNAMIC_VERTEX_SHADER( portal_vs11 ); + + DECLARE_DYNAMIC_PIXEL_SHADER( portal_ps11 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( ADDSTATIC, 0 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + SET_DYNAMIC_PIXEL_SHADER( portal_ps11 ); + } + Draw(); +} + + +void MultiPass_StaticPass( IShaderShadow *pShaderShadow, IShaderDynamicAPI *pShaderAPI, IMaterialVar **params, bool bAlphaMaskTexture ) +{ + SHADOW_STATE + { + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + if( bAlphaMaskTexture ) + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + + } + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER0, STATICBLENDTEXTURE, STATICBLENDTEXTUREFRAME ); + if( bAlphaMaskTexture ) + BindTexture( SHADER_SAMPLER1, ALPHAMASKTEXTURE, ALPHAMASKTEXTUREFRAME ); + + DECLARE_DYNAMIC_VERTEX_SHADER( portal_vs11 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, pShaderAPI->GetCurrentNumBones() > 0 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( ADDSTATIC, 1 ); + SET_DYNAMIC_VERTEX_SHADER( portal_vs11 ); + + DECLARE_DYNAMIC_PIXEL_SHADER( portal_ps11 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( ADDSTATIC, 1 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + SET_DYNAMIC_PIXEL_SHADER( portal_ps11 ); + } + Draw(); +} + +END_SHADER + + diff --git a/materialsystem/stdshaders/portal_ps11.fxc b/materialsystem/stdshaders/portal_ps11.fxc new file mode 100644 index 0000000..137ff87 --- /dev/null +++ b/materialsystem/stdshaders/portal_ps11.fxc @@ -0,0 +1,122 @@ +// STATIC: "MAXTEXTURESTAGES" "0..2" +// STATIC: "HASALPHAMASK" "0..1" +// STATIC: "HASSTATICTEXTURE" "0..1" + +// DYNAMIC: "ADDSTATIC" "0..1" +// DYNAMIC: "PIXELFOGTYPE" "0..1" + +// When max texture stages is less than 2, we go into multipass mode, but without a static texture, we consolidate back to a single pass by using gray as static +// SKIP: ($MAXTEXTURESTAGES < 2) && ($HASSTATICTEXTURE == 0) && ($ADDSTATIC == 1) + +#define TEXTURESTAGES (MAXTEXTURESTAGES + 1) +#define USESTATICTEXTURE (((ADDSTATIC == 1) && (HASSTATICTEXTURE == 1))?(1):(0)) + +#include "common_ps_fxc.h" + + + +const HALF3 g_StaticAmount : register( c0 ); //x is static, y is 1.0 - static + +sampler PrimarySampler : register( s0 ); +#if( TEXTURESTAGES == 3 ) +# if( (HASALPHAMASK == 1) || (USESTATICTEXTURE == 1) ) + sampler SecondarySampler : register( s1 ); +# if( (HASALPHAMASK == 1) && (USESTATICTEXTURE == 1) ) + sampler TertiarySampler : register( s2 ); +# endif +# endif +#elif( (TEXTURESTAGES > 1) && (HASALPHAMASK == 1) ) + sampler SecondarySampler : register( s1 ); +#endif + +struct PS_INPUT +{ + float3 vPrimaryTexCoord : TEXCOORD0; + +# if( TEXTURESTAGES == 3 ) +# if( (HASALPHAMASK == 1) || (USESTATICTEXTURE == 1) ) + float2 vSecondaryTexCoord : TEXCOORD1; +# if( (HASALPHAMASK == 1) && (USESTATICTEXTURE == 1) ) + float2 vTertiaryTexCoord : TEXCOORD2; +# endif +# endif +# elif( TEXTURESTAGES > 1 && HASALPHAMASK == 1 ) + float2 vSecondaryTexCoord : TEXCOORD1; +# endif +}; + + + + +HALF4 main( PS_INPUT i ) : COLOR +{ + HALF4 result; + +# if( TEXTURESTAGES == 3 ) //we can do everything in one pass + { + result.rgb = tex2D(PrimarySampler, i.vPrimaryTexCoord.xy ).rgb; + + //mix in static +# if( ADDSTATIC == 1 ) + { + result.rgb *= g_StaticAmount.y; //inverse static on original colors + +# if( HASSTATICTEXTURE == 1 ) + { +# if( HASALPHAMASK == 1 ) + result.rgb += tex2D(TertiarySampler, i.vTertiaryTexCoord ).rgb * g_StaticAmount.x; //static +# else + result.rgb += tex2D(SecondarySampler, i.vSecondaryTexCoord ).rgb * g_StaticAmount.x; //static +# endif + } +# else + { + result.rgb += g_StaticAmount.x * 0.25; //mix in gray + } +# endif + } +# endif + +# if( HASALPHAMASK == 1 ) + { + //alpha mask + result.a = tex2D(SecondarySampler, i.vSecondaryTexCoord ).a; + } +# else + { + result.a = 1; + } +# endif + } +# else //multiple pass configuration + { +# if( ADDSTATIC == 1 ) //in multipass configuration and adding static + { +# if( HASSTATICTEXTURE == 1 ) + result.rgb = tex2D(PrimarySampler, i.vPrimaryTexCoord.xy ).rgb; +# endif + result.a = g_StaticAmount.x; //in multipass, static is achieved by alpha blending the static onto an existing cutout pixel in the destination pixel + } +# else //in multipass config on the cutout pass + { + result.rgb = tex2D(PrimarySampler, i.vPrimaryTexCoord.xy ).rgb; + +# if( HASSTATICTEXTURE == 0 ) //there's no need to do another pass if there's no other texture to mix with, just mix in gray + { + result.rgb *= g_StaticAmount.y; + result.rgb += g_StaticAmount.x * 0.25; //mix in gray + } +# endif + + result.a = 1; + } +# endif + +# if( (TEXTURESTAGES > 1) && (HASALPHAMASK == 1) ) + result.a *= tex2D(SecondarySampler, i.vSecondaryTexCoord ).a; //modulate in the alpha instead of setting it so we get blend as well as mask +# endif + } +# endif + + return result; +} \ No newline at end of file diff --git a/materialsystem/stdshaders/portal_ps2x.fxc b/materialsystem/stdshaders/portal_ps2x.fxc new file mode 100644 index 0000000..9c899fd --- /dev/null +++ b/materialsystem/stdshaders/portal_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: "HASALPHAMASK" "0..1" +// STATIC: "HASSTATICTEXTURE" "0..1" + +// DYNAMIC: "ADDSTATIC" "0..1" +// DYNAMIC: "HDRENABLED" "0..1" +// DYNAMIC: "PIXELFOGTYPE" "0..1" + +#define USESTATICTEXTURE (((ADDSTATIC == 1) && (HASSTATICTEXTURE == 1))?(1):(0)) + +#include "common_ps_fxc.h" +#include "shader_constant_register_map.h" + + + +const float4 g_StaticAmount : register( c0 ); //x is static, y is 1.0 - static +const float4 g_FogParams : register( PSREG_FOG_PARAMS ); +const float4 g_EyePos_SpecExponent : register( PSREG_EYEPOS_SPEC_EXPONENT ); + +sampler PortalSampler : register( s0 ); + +#if( (HASALPHAMASK == 1) || (USESTATICTEXTURE == 1) ) + sampler SecondarySampler : register( s1 ); +# if( (HASALPHAMASK == 1) && (USESTATICTEXTURE == 1) ) + sampler TertiarySampler : register( s2 ); +# endif +#endif + + +struct PS_INPUT +{ + float3 vPortalTexCoord : TEXCOORD0; + +# if( (HASALPHAMASK == 1) || (USESTATICTEXTURE == 1) ) + float2 vSecondaryTexCoord : TEXCOORD1; +# if( (HASALPHAMASK == 1) && (USESTATICTEXTURE == 1) ) + float2 vTertiaryTexCoord : TEXCOORD2; +# endif +# endif + + float4 worldPos_projPosZ : TEXCOORD7; // Necessary for pixel fog +}; + + + + +float4 main( PS_INPUT i ) : COLOR +{ + HALF4 result; + result.rgb = tex2D(PortalSampler, i.vPortalTexCoord.xy / i.vPortalTexCoord.z ).rgb; + + //mix in static +# if( ADDSTATIC == 1 ) + { + result.rgb *= g_StaticAmount.y; //inverse static on original colors + +# if( HASSTATICTEXTURE == 1 ) + { +# if( HASALPHAMASK == 1 ) + result.rgb += tex2D(TertiarySampler, i.vTertiaryTexCoord ).rgb * g_StaticAmount.x; //static +# else + result.rgb += tex2D(SecondarySampler, i.vSecondaryTexCoord ).rgb * g_StaticAmount.x; //static +# endif + } +# else + { + result.rgb += g_StaticAmount.x * 0.25; //mix in gray + } +# endif + } +# endif + +# if( HASALPHAMASK == 1 ) + { + //alpha mask + result.a = tex2D(SecondarySampler, i.vSecondaryTexCoord ).a; + } +# else + { + result.a = 1; + } +# endif + + + float fogFactor = CalcPixelFogFactor( PIXELFOGTYPE, g_FogParams, g_EyePos_SpecExponent.z, i.worldPos_projPosZ.z, i.worldPos_projPosZ.w ); + return FinalOutput( result, fogFactor, PIXELFOGTYPE, TONEMAP_SCALE_LINEAR ); +} \ No newline at end of file diff --git a/materialsystem/stdshaders/portal_refract.cpp b/materialsystem/stdshaders/portal_refract.cpp new file mode 100644 index 0000000..2a2a221 --- /dev/null +++ b/materialsystem/stdshaders/portal_refract.cpp @@ -0,0 +1,98 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// + +#include "BaseVSShader.h" +#include "portal_refract_helper.h" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +DEFINE_FALLBACK_SHADER( PortalRefract, PortalRefract_dx9 ) +BEGIN_VS_SHADER( PortalRefract_dx9, "PortalRefract" ) + BEGIN_SHADER_PARAMS + SHADER_PARAM( STAGE, SHADER_PARAM_TYPE_INTEGER, "0", "Stage of portal rendering (0, 1, 2)" ) + SHADER_PARAM( PORTALOPENAMOUNT, SHADER_PARAM_TYPE_FLOAT, "0.0", "Portal open amount 0.0-1.0" ) + SHADER_PARAM( PORTALSTATIC, SHADER_PARAM_TYPE_FLOAT, "0.0", "Portal static amount 0.0-1.0" ) + SHADER_PARAM( PORTALMASKTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "Mask texture" ) + SHADER_PARAM( TEXTURETRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "Texcoord transform" ) + SHADER_PARAM( PORTALCOLORTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "Color texture" ) + SHADER_PARAM( PORTALCOLORSCALE, SHADER_PARAM_TYPE_FLOAT, "0.0", "Portal color scale" ) + SHADER_PARAM( TIME, SHADER_PARAM_TYPE_FLOAT, "0.0", "Needs CurrentTime Proxy" ) + END_SHADER_PARAMS + + void SetupVarsPortalRefract( PortalRefractVars_t &info ) + { + info.m_nStage = STAGE; + info.m_nPortalOpenAmount = PORTALOPENAMOUNT; + info.m_nPortalStatic = PORTALSTATIC; + info.m_nPortalMaskTexture = PORTALMASKTEXTURE; + info.m_nTextureTransform = TEXTURETRANSFORM; + info.m_nPortalColorTexture = PORTALCOLORTEXTURE; + info.m_nPortalColorScale = PORTALCOLORSCALE; + info.m_nTime = TIME; + } + + bool NeedsPowerOfTwoFrameBufferTexture( IMaterialVar **params, bool bCheckSpecificToThisFrame ) const + { + // For setting model flag at load time + if ( bCheckSpecificToThisFrame == false ) + return true; + + // We only need the texture for stage 0 + if ( params[STAGE]->GetIntValue() == 0 ) + { + //Msg( "Portal Refract @ %f time\n", params[TIME]->GetFloatValue() ); + return true; + } + else + { + return false; + } + } + + SHADER_INIT_PARAMS() + { + PortalRefractVars_t info; + SetupVarsPortalRefract( info ); + InitParamsPortalRefract( this, params, pMaterialName, info ); + } + + SHADER_FALLBACK + { + if ( g_pHardwareConfig->GetDXSupportLevel() < 90 ) + { + return "PortalRefract_dx8"; + } + + return 0; + } + + SHADER_INIT + { + PortalRefractVars_t info; + SetupVarsPortalRefract( info ); + InitPortalRefract( this, params, info ); + } + + SHADER_DRAW + { + // Skip drawing if in stage 0 and the portal isn't partially opened + bool bDraw = true; + if ( ( params[STAGE]->GetIntValue() == 0 ) && ( ( params[PORTALOPENAMOUNT]->GetFloatValue() <= 0.0f ) || ( params[PORTALOPENAMOUNT]->GetFloatValue() >= 1.0f ) ) ) // If in stage 0 and not partially opened + { + bDraw = false; + } + + // If ( snapshotting ) or ( we need to draw this frame ) + if ( ( pShaderShadow != NULL ) || ( bDraw == true ) ) + { + PortalRefractVars_t info; + SetupVarsPortalRefract( info ); + DrawPortalRefract( this, params, pShaderAPI, pShaderShadow, info ); + } + else // We're not snapshotting and we don't need to draw this frame + { + // Skip this pass! + Draw( false ); + } + } +END_SHADER diff --git a/materialsystem/stdshaders/portal_refract_dx8.cpp b/materialsystem/stdshaders/portal_refract_dx8.cpp new file mode 100644 index 0000000..261aebb --- /dev/null +++ b/materialsystem/stdshaders/portal_refract_dx8.cpp @@ -0,0 +1,83 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// + +#include "BaseVSShader.h" +#include "portal_refract_dx8_helper.h" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +DEFINE_FALLBACK_SHADER( PortalRefract, PortalRefract_dx8 ) +BEGIN_VS_SHADER( PortalRefract_dx8, "PortalRefract_dx8" ) + BEGIN_SHADER_PARAMS + SHADER_PARAM( STAGE, SHADER_PARAM_TYPE_INTEGER, "0", "Stage of portal rendering (0, 1, 2)" ) + SHADER_PARAM( PORTALOPENAMOUNT, SHADER_PARAM_TYPE_FLOAT, "0.0", "Portal open amount 0.0-1.0" ) + SHADER_PARAM( PORTALSTATIC, SHADER_PARAM_TYPE_FLOAT, "0.0", "Portal static amount 0.0-1.0" ) + SHADER_PARAM( PORTALMASKTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "Mask texture" ) + SHADER_PARAM( TEXTURETRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "Texcoord transform" ) + SHADER_PARAM( PORTALCOLORTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "Color texture" ) + SHADER_PARAM( PORTALCOLORSCALE, SHADER_PARAM_TYPE_FLOAT, "0.0", "Portal color scale" ) + END_SHADER_PARAMS + + void SetupVarsPortalRefract_DX8( PortalRefractVarsDX8_t &info ) + { + info.m_nStage = STAGE; + info.m_nPortalOpenAmount = PORTALOPENAMOUNT; + info.m_nPortalStatic = PORTALSTATIC; + info.m_nPortalMaskTexture = PORTALMASKTEXTURE; + info.m_nTextureTransform = TEXTURETRANSFORM; + info.m_nPortalColorTexture = PORTALCOLORTEXTURE; + info.m_nPortalColorScale = PORTALCOLORSCALE; + } + + bool NeedsPowerOfTwoFrameBufferTexture( IMaterialVar **params, bool bCheckSpecificToThisFrame ) const + { + return false; + } + + SHADER_INIT_PARAMS() + { + PortalRefractVarsDX8_t info; + SetupVarsPortalRefract_DX8( info ); + InitParamsPortalRefract_DX8( this, params, pMaterialName, info ); + } + + SHADER_FALLBACK + { + if ( g_pHardwareConfig->GetDXSupportLevel() < 80 ) + { + return "Wireframe"; + } + + return 0; + } + + SHADER_INIT + { + PortalRefractVarsDX8_t info; + SetupVarsPortalRefract_DX8( info ); + InitPortalRefract_DX8( this, params, info ); + } + + SHADER_DRAW + { + // Skip drawing stage 0 in DX8 + bool bDraw = true; + if ( params[STAGE]->GetIntValue() == 0 ) + { + bDraw = false; + } + + // If ( snapshotting ) or ( we need to draw this frame ) + if ( ( pShaderShadow != NULL ) || ( bDraw == true ) ) + { + PortalRefractVarsDX8_t info; + SetupVarsPortalRefract_DX8( info ); + DrawPortalRefract_DX8( this, params, pShaderAPI, pShaderShadow, info ); + } + else // We're not snapshotting and we don't need to draw this frame + { + // Skip this pass! + Draw( false ); + } + } +END_SHADER diff --git a/materialsystem/stdshaders/portal_refract_dx8_helper.cpp b/materialsystem/stdshaders/portal_refract_dx8_helper.cpp new file mode 100644 index 0000000..930ea1f --- /dev/null +++ b/materialsystem/stdshaders/portal_refract_dx8_helper.cpp @@ -0,0 +1,145 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +#include "BaseVSShader.h" +#include "mathlib/vmatrix.h" +#include "portal_refract_dx8_helper.h" +#include "convar.h" + +// Auto generated inc files +#include "portal_refract_vs11.inc" +#include "portal_refract_ps11.inc" + +void InitParamsPortalRefract_DX8( CBaseVSShader *pShader, IMaterialVar** params, const char *pMaterialName, PortalRefractVarsDX8_t &info ) +{ + // Set material flags + SET_FLAGS( MATERIAL_VAR_MODEL ); + SET_FLAGS( MATERIAL_VAR_TRANSLUCENT ); + + // Set material parameter default values + if ( ( info.m_nStage != -1 ) && ( !params[info.m_nStage]->IsDefined() ) ) + { + params[info.m_nStage]->SetIntValue( 0 ); + } + + if ( ( info.m_nPortalOpenAmount != -1 ) && ( !params[info.m_nPortalOpenAmount]->IsDefined() ) ) + { + params[info.m_nPortalOpenAmount]->SetFloatValue( kDefaultPortalOpenAmount ); + } + + if ( ( info.m_nPortalStatic != -1 ) && ( !params[info.m_nPortalStatic]->IsDefined() ) ) + { + params[info.m_nPortalStatic]->SetFloatValue( kDefaultPortalStatic ); + } +} + +void InitPortalRefract_DX8( CBaseVSShader *pShader, IMaterialVar** params, PortalRefractVarsDX8_t &info ) +{ + if ( (info.m_nPortalMaskTexture != -1) && params[info.m_nPortalMaskTexture]->IsDefined() ) + { + pShader->LoadTexture( info.m_nPortalMaskTexture ); + } + + if ( (info.m_nPortalColorTexture != -1) && params[info.m_nPortalColorTexture]->IsDefined() ) + { + pShader->LoadTexture( info.m_nPortalColorTexture ); + } +} + +void DrawPortalRefract_DX8( CBaseVSShader *pShader, IMaterialVar** params, + IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow, PortalRefractVarsDX8_t &info ) +{ + int nStage = IS_PARAM_DEFINED( info.m_nStage ) ? params[info.m_nStage]->GetIntValue() : 0; + + SHADOW_STATE + { + // Set stream format + pShaderShadow->VertexShaderVertexFormat( VERTEX_POSITION | VERTEX_NORMAL, 1, NULL, 4 ); + + // Vertex Shader + DECLARE_STATIC_VERTEX_SHADER( portal_refract_vs11 ); + SET_STATIC_VERTEX_SHADER_COMBO( STAGE, nStage ); + SET_STATIC_VERTEX_SHADER( portal_refract_vs11 ); + + // Pixel Shader + DECLARE_STATIC_PIXEL_SHADER( portal_refract_ps11 ); + SET_STATIC_PIXEL_SHADER_COMBO( STAGE, nStage ); + SET_STATIC_PIXEL_SHADER( portal_refract_ps11 ); + + // Textures + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + + // Enable alpha testing for all stages + pShaderShadow->EnableAlphaTest( true ); + pShaderShadow->AlphaFunc( SHADER_ALPHAFUNC_GREATER, 0.5f ); + + // Enable alpha blending for stage 2 + if ( nStage == 2 ) + { + pShader->EnableAlphaBlending( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA ); + pShaderShadow->AlphaFunc( SHADER_ALPHAFUNC_GREATER, 1.0f/255.0f ); + } + + // Disable z-writes for all passes + pShaderShadow->EnableDepthWrites( false ); + + // Disable alpha-writes for all passes + pShaderShadow->EnableAlphaWrites( false ); + + pShader->DefaultFog(); + } + DYNAMIC_STATE + { + // Set Vertex Shader Combos + DECLARE_DYNAMIC_VERTEX_SHADER( portal_refract_vs11 ); + SET_DYNAMIC_VERTEX_SHADER( portal_refract_vs11 ); + + // Set Vertex Shader Constants + if ( IS_PARAM_DEFINED( info.m_nTextureTransform ) ) + { + pShader->SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_1, info.m_nTextureTransform ); + } + + // Time % 1000 + float vPackedVsConst1[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; + vPackedVsConst1[0] = pShaderAPI->CurrentTime(); + vPackedVsConst1[0] -= (float)( floor( vPackedVsConst1[0] / 1000.0f ) ) * 1000.0f; + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, vPackedVsConst1, 1 ); + + // Set Pixel Shader Combos + DECLARE_DYNAMIC_PIXEL_SHADER( portal_refract_ps11 ); + SET_DYNAMIC_PIXEL_SHADER( portal_refract_ps11 ); + + // Bind textures + pShader->BindTexture( SHADER_SAMPLER0, info.m_nPortalColorTexture ); + pShader->BindTexture( SHADER_SAMPLER1, info.m_nPortalMaskTexture ); + + // Set Pixel Shader Constants + pShaderAPI->SetPixelShaderFogParams( 6 ); + + // Set c0-c3 to contain four rows of ViewProj matrix + VMatrix mView, mProj; + pShaderAPI->GetMatrix( MATERIAL_VIEW, mView.m[0] ); + pShaderAPI->GetMatrix( MATERIAL_PROJECTION, mProj.m[0] ); + VMatrix mViewProj = mView * mProj; + mViewProj = mViewProj.Transpose(); + pShaderAPI->SetPixelShaderConstant( 0, mViewProj.m[0], 4 ); + + // Portal open amount + float vPackedConst1[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; + vPackedConst1[0] = ( IS_PARAM_DEFINED( info.m_nPortalOpenAmount ) ? params[info.m_nPortalOpenAmount]->GetFloatValue() : kDefaultPortalOpenAmount ); + vPackedConst1[1] = 1.0f - ( IS_PARAM_DEFINED( info.m_nPortalStatic ) ? params[info.m_nPortalStatic]->GetFloatValue() : kDefaultPortalStatic ); + vPackedConst1[2] = ( IS_PARAM_DEFINED( info.m_nPortalColorScale ) ? params[info.m_nPortalColorScale]->GetFloatValue() : kDefaultPortalColorScale ) / 4.0f; // Will scale by 4 in ps + + //vPackedConst4[0] = 0.6f; + //DevMsg( "Refract Time: %f\n", vPackedConst4[0] ); + + pShaderAPI->SetPixelShaderConstant( 1, vPackedConst1, 1 ); + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_3, vPackedConst1, 1 ); + + // Camera position + float vEyePos[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; + pShaderAPI->GetWorldSpaceCameraPosition( vEyePos ); + pShaderAPI->SetPixelShaderConstant( 5, vEyePos, 1 ); + } + pShader->Draw(); +} diff --git a/materialsystem/stdshaders/portal_refract_dx8_helper.h b/materialsystem/stdshaders/portal_refract_dx8_helper.h new file mode 100644 index 0000000..c0ac084 --- /dev/null +++ b/materialsystem/stdshaders/portal_refract_dx8_helper.h @@ -0,0 +1,45 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// + +#ifndef PORTALREFRACT_DX8_HELPER_H +#define PORTALREFRACT_DX8_HELPER_H +#ifdef _WIN32 +#pragma once +#endif + +#include + +//----------------------------------------------------------------------------- +// Forward declarations +//----------------------------------------------------------------------------- +class CBaseVSShader; +class IMaterialVar; +class IShaderDynamicAPI; +class IShaderShadow; + +//----------------------------------------------------------------------------- +// Init params/ init/ draw methods +//----------------------------------------------------------------------------- +struct PortalRefractVarsDX8_t +{ + PortalRefractVarsDX8_t() { memset( this, 0xFF, sizeof(PortalRefractVarsDX8_t) ); } + + int m_nStage; + int m_nPortalOpenAmount; + int m_nPortalStatic; + int m_nPortalMaskTexture; + int m_nTextureTransform; + int m_nPortalColorTexture; + int m_nPortalColorScale; +}; + +// Default values (Arrays should only be vec[4]) +static const float kDefaultPortalStatic = 0.0f; +static const float kDefaultPortalOpenAmount = 0.0f; +static const float kDefaultPortalColorScale = 1.0f; + +void InitParamsPortalRefract_DX8( CBaseVSShader *pShader, IMaterialVar** params, const char *pMaterialName, PortalRefractVarsDX8_t &info ); +void InitPortalRefract_DX8( CBaseVSShader *pShader, IMaterialVar** params, PortalRefractVarsDX8_t &info ); +void DrawPortalRefract_DX8( CBaseVSShader *pShader, IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, + IShaderShadow* pShaderShadow, PortalRefractVarsDX8_t &info ); + +#endif // PortalRefract_DX8_HELPER_H diff --git a/materialsystem/stdshaders/portal_refract_helper.cpp b/materialsystem/stdshaders/portal_refract_helper.cpp new file mode 100644 index 0000000..6380215 --- /dev/null +++ b/materialsystem/stdshaders/portal_refract_helper.cpp @@ -0,0 +1,190 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +#include "BaseVSShader.h" +#include "mathlib/vmatrix.h" +#include "portal_refract_helper.h" +#include "convar.h" + +// Auto generated inc files +#include "portal_refract_vs20.inc" +#include "portal_refract_ps20.inc" +#include "portal_refract_ps20b.inc" + +void InitParamsPortalRefract( CBaseVSShader *pShader, IMaterialVar** params, const char *pMaterialName, PortalRefractVars_t &info ) +{ + // Set material flags + SET_FLAGS( MATERIAL_VAR_MODEL ); + SET_FLAGS2( MATERIAL_VAR2_NEEDS_TANGENT_SPACES ); + + SET_FLAGS( MATERIAL_VAR_TRANSLUCENT ); + SET_FLAGS2( MATERIAL_VAR2_NEEDS_POWER_OF_TWO_FRAME_BUFFER_TEXTURE ); + + // Set material parameter default values + if ( ( info.m_nStage != -1 ) && ( !params[info.m_nStage]->IsDefined() ) ) + { + params[info.m_nStage]->SetIntValue( 0 ); + } + + if ( ( info.m_nPortalOpenAmount != -1 ) && ( !params[info.m_nPortalOpenAmount]->IsDefined() ) ) + { + params[info.m_nPortalOpenAmount]->SetFloatValue( kDefaultPortalOpenAmount ); + } + + if ( ( info.m_nPortalStatic != -1 ) && ( !params[info.m_nPortalStatic]->IsDefined() ) ) + { + params[info.m_nPortalStatic]->SetFloatValue( kDefaultPortalStatic ); + } + + SET_PARAM_FLOAT_IF_NOT_DEFINED( info.m_nTime, 0.0f ); +} + +void InitPortalRefract( CBaseVSShader *pShader, IMaterialVar** params, PortalRefractVars_t &info ) +{ + int nStage = IS_PARAM_DEFINED( info.m_nStage ) ? params[info.m_nStage]->GetIntValue() : 0; + + // Load textures + if ( nStage == 2 ) // Only load textures for third stage + { + if ( (info.m_nPortalMaskTexture != -1) && params[info.m_nPortalMaskTexture]->IsDefined() ) + { + pShader->LoadTexture( info.m_nPortalMaskTexture ); + } + + if ( (info.m_nPortalColorTexture != -1) && params[info.m_nPortalColorTexture]->IsDefined() ) + { + pShader->LoadTexture( info.m_nPortalColorTexture, TEXTUREFLAGS_SRGB ); + } + } +} + +void DrawPortalRefract( CBaseVSShader *pShader, IMaterialVar** params, + IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow, PortalRefractVars_t &info ) +{ + int nStage = IS_PARAM_DEFINED( info.m_nStage ) ? params[info.m_nStage]->GetIntValue() : 0; + + SHADOW_STATE + { + // Set stream format + pShaderShadow->VertexShaderVertexFormat( VERTEX_POSITION | VERTEX_NORMAL, 1, NULL, 4 ); + + // Vertex Shader + DECLARE_STATIC_VERTEX_SHADER( portal_refract_vs20 ); + SET_STATIC_VERTEX_SHADER_COMBO( STAGE, nStage ); + SET_STATIC_VERTEX_SHADER( portal_refract_vs20 ); + + // On Leopard / 10.5.8, we can't do an sRGB read from a render target, so we must fake it in shader code + bool bShaderSRGBRead = IsOSX() && !g_pHardwareConfig->CanDoSRGBReadFromRTs(); + + // Pixel Shader + if( g_pHardwareConfig->SupportsPixelShaders_2_b() || g_pHardwareConfig->ShouldAlwaysUseShaderModel2bShaders() ) // Always send OpenGL / Posix down this path + { + DECLARE_STATIC_PIXEL_SHADER( portal_refract_ps20b ); + SET_STATIC_PIXEL_SHADER_COMBO( STAGE, nStage ); + SET_STATIC_PIXEL_SHADER_COMBO( SHADER_SRGB_READ, bShaderSRGBRead ? 1 : 0 ); + SET_STATIC_PIXEL_SHADER( portal_refract_ps20b ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( portal_refract_ps20 ); + SET_STATIC_PIXEL_SHADER_COMBO( STAGE, nStage ); + SET_STATIC_PIXEL_SHADER( portal_refract_ps20 ); + } + + // Textures + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); // Refraction texture + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); // Noise + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER1, false ); // Not sRGB + pShaderShadow->EnableTexture( SHADER_SAMPLER2, true ); // Color + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER2, true ); // sRGB + pShaderShadow->EnableSRGBWrite( true ); //Stage 1 doesn't actually need srgb conversion, but it skips the software srgb solution anyway. + + // Enable alpha testing for all stages + pShaderShadow->EnableAlphaTest( true ); + pShaderShadow->AlphaFunc( SHADER_ALPHAFUNC_GREATER, 0.5f ); + + // Enable alpha blending for stage 2 + if ( nStage == 2 ) + { + pShader->EnableAlphaBlending( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA ); + pShaderShadow->AlphaFunc( SHADER_ALPHAFUNC_GREATER, 1.0f/255.0f ); + } + + // Disable z-writes for all passes + pShaderShadow->EnableDepthWrites( false ); + + // Disable alpha-writes for all passes + pShaderShadow->EnableAlphaWrites( false ); + } + DYNAMIC_STATE + { + // Set Vertex Shader Combos + DECLARE_DYNAMIC_VERTEX_SHADER( portal_refract_vs20 ); + SET_DYNAMIC_VERTEX_SHADER( portal_refract_vs20 ); + + // Set Vertex Shader Constants + if ( IS_PARAM_DEFINED( info.m_nTextureTransform ) ) + { + pShader->SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_1, info.m_nTextureTransform ); + } + + // Time % 1000 + float vPackedVsConst1[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; + float flTime = IS_PARAM_DEFINED( info.m_nTime ) && params[info.m_nTime]->GetFloatValue() > 0.0f ? params[info.m_nTime]->GetFloatValue() : pShaderAPI->CurrentTime(); + vPackedVsConst1[0] = flTime; + vPackedVsConst1[0] -= (float)( floor( vPackedVsConst1[0] / 1000.0f ) ) * 1000.0f; + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, vPackedVsConst1, 1 ); + + // Set Pixel Shader Combos + if( g_pHardwareConfig->SupportsPixelShaders_2_b() || g_pHardwareConfig->ShouldAlwaysUseShaderModel2bShaders() ) // Always send OpenGL / Posix down this path + { + DECLARE_DYNAMIC_PIXEL_SHADER( portal_refract_ps20b ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + SET_DYNAMIC_PIXEL_SHADER( portal_refract_ps20b ); + } + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( portal_refract_ps20 ); + SET_DYNAMIC_PIXEL_SHADER( portal_refract_ps20 ); + } + + // Bind textures + if ( nStage == 0 ) // Only bind frame buffer texture for first stage + { + pShaderAPI->BindStandardTexture( SHADER_SAMPLER0, TEXTURE_FRAME_BUFFER_FULL_TEXTURE_0 ); // Refraction Map + } + if ( nStage == 2 ) // Only load textures for third stage + { + pShader->BindTexture( SHADER_SAMPLER1, info.m_nPortalMaskTexture ); + pShader->BindTexture( SHADER_SAMPLER2, info.m_nPortalColorTexture ); + } + + // Set Pixel Shader Constants + pShaderAPI->SetPixelShaderFogParams( 6 ); + + // Set c0-c3 to contain four rows of ViewProj matrix + VMatrix mView, mProj; + pShaderAPI->GetMatrix( MATERIAL_VIEW, mView.m[0] ); + pShaderAPI->GetMatrix( MATERIAL_PROJECTION, mProj.m[0] ); + VMatrix mViewProj = mView * mProj; + mViewProj = mViewProj.Transpose(); + pShaderAPI->SetPixelShaderConstant( 0, mViewProj.m[0], 4 ); + + // Portal open amount + float vPackedConst4[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; + vPackedConst4[0] = ( IS_PARAM_DEFINED( info.m_nPortalOpenAmount ) ? params[info.m_nPortalOpenAmount]->GetFloatValue() : kDefaultPortalOpenAmount ); + vPackedConst4[1] = 1.0f - ( IS_PARAM_DEFINED( info.m_nPortalStatic ) ? params[info.m_nPortalStatic]->GetFloatValue() : kDefaultPortalStatic ); + vPackedConst4[2] = ( IS_PARAM_DEFINED( info.m_nPortalColorScale ) ? params[info.m_nPortalColorScale]->GetFloatValue() : kDefaultPortalColorScale ); + + //vPackedConst4[0] = 0.6f; + //DevMsg( "Refract Time: %f\n", vPackedConst4[0] ); + + pShaderAPI->SetPixelShaderConstant( 4, vPackedConst4, 1 ); + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_3, vPackedConst4, 1 ); + + // Camera position + float vEyePos[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; + pShaderAPI->GetWorldSpaceCameraPosition( vEyePos ); + pShaderAPI->SetPixelShaderConstant( 5, vEyePos, 1 ); + } + pShader->Draw(); +} diff --git a/materialsystem/stdshaders/portal_refract_helper.h b/materialsystem/stdshaders/portal_refract_helper.h new file mode 100644 index 0000000..3c54858 --- /dev/null +++ b/materialsystem/stdshaders/portal_refract_helper.h @@ -0,0 +1,46 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// + +#ifndef PORTALREFRACT_HELPER_H +#define PORTALREFRACT_HELPER_H +#ifdef _WIN32 +#pragma once +#endif + +#include + +//----------------------------------------------------------------------------- +// Forward declarations +//----------------------------------------------------------------------------- +class CBaseVSShader; +class IMaterialVar; +class IShaderDynamicAPI; +class IShaderShadow; + +//----------------------------------------------------------------------------- +// Init params/ init/ draw methods +//----------------------------------------------------------------------------- +struct PortalRefractVars_t +{ + PortalRefractVars_t() { memset( this, 0xFF, sizeof(PortalRefractVars_t) ); } + + int m_nStage; + int m_nPortalOpenAmount; + int m_nPortalStatic; + int m_nPortalMaskTexture; + int m_nTextureTransform; + int m_nPortalColorTexture; + int m_nPortalColorScale; + int m_nTime; +}; + +// Default values (Arrays should only be vec[4]) +static const float kDefaultPortalStatic = 0.0f; +static const float kDefaultPortalOpenAmount = 0.0f; +static const float kDefaultPortalColorScale = 1.0f; + +void InitParamsPortalRefract( CBaseVSShader *pShader, IMaterialVar** params, const char *pMaterialName, PortalRefractVars_t &info ); +void InitPortalRefract( CBaseVSShader *pShader, IMaterialVar** params, PortalRefractVars_t &info ); +void DrawPortalRefract( CBaseVSShader *pShader, IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, + IShaderShadow* pShaderShadow, PortalRefractVars_t &info ); + +#endif // PortalRefract_HELPER_H diff --git a/materialsystem/stdshaders/portal_refract_ps11.fxc b/materialsystem/stdshaders/portal_refract_ps11.fxc new file mode 100644 index 0000000..61f16a2 --- /dev/null +++ b/materialsystem/stdshaders/portal_refract_ps11.fxc @@ -0,0 +1,33 @@ +//========= Copyright © 1996-2007, Valve Corporation, All rights reserved. ============// + +// STATIC: "STAGE" "0..2" + +#include "common_ps_fxc.h" + +sampler g_tPortalColorSampler : register( s0 ); +sampler g_tPortalMaskSampler : register( s1 ); + +const float3 g_vConst1 : register( c1 ); +#define g_flPortalOpenAmount g_vConst1.x +#define g_flPortalActive g_vConst1.y +#define g_flPortalColorScale g_vConst1.z + +struct PS_INPUT +{ + float2 vUv0 : TEXCOORD0; + float2 vUv1 : TEXCOORD1; +}; + +float4 main( PS_INPUT i ) : COLOR +{ + float4 result; + + result.rgba = tex2D( g_tPortalColorSampler, i.vUv0.xy ); + result.rgb *= g_flPortalColorScale + g_flPortalColorScale + g_flPortalColorScale + g_flPortalColorScale; // This is divided by 4 in C code + + #if ( STAGE == 2 ) // Color layer + result.a += tex2D( g_tPortalMaskSampler, i.vUv1.xy ).a * ( 1.0f - g_flPortalActive ); + #endif + + return result; +} diff --git a/materialsystem/stdshaders/portal_refract_ps2x.fxc b/materialsystem/stdshaders/portal_refract_ps2x.fxc new file mode 100644 index 0000000..29f2c93 --- /dev/null +++ b/materialsystem/stdshaders/portal_refract_ps2x.fxc @@ -0,0 +1,224 @@ +//========= Copyright © 1996-2007, Valve Corporation, All rights reserved. ============// + +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX] +// STATIC: "STAGE" "0..2" +// STATIC: "SHADER_SRGB_READ" "0..1" [ps20b] + +// DYNAMIC: "PIXELFOGTYPE" "0..1" [ps20b] + +#if defined(SHADER_MODEL_PS_2_0) + #define PIXELFOGTYPE PIXEL_FOG_TYPE_NONE +#endif + +// Includes ======================================================================================= +#include "common_vertexlitgeneric_dx9.h" + +// Texture Samplers =============================================================================== +sampler g_tRefractionSampler : register( s0 ); +sampler g_tPortalNoiseSampler : register( s1 ); +sampler g_tPortalColorSampler : register( s2 ); + +// Shaders Constants and Globals ================================================================== +const float4 g_mViewProj0 : register( c0 ); // 1st row of matrix +const float4 g_mViewProj1 : register( c1 ); // 2nd row of matrix +const float4 g_mViewProj2 : register( c2 ); // 3rd row of matrix +const float4 g_mViewProj3 : register( c3 ); // 4th row of matrix +const float3 g_vConst4 : register( c4 ); +#define g_flPortalOpenAmount g_vConst4.x +#define g_flPortalActive g_vConst4.y +#define g_flPortalColorScale g_vConst4.z +const float4 g_vCameraPosition : register( c5 ); +const float4 g_vFogParams : register( c6 ); + +// Interpolated values ============================================================================ +struct PS_INPUT +{ + float2 vUv0 : TEXCOORD0; + float3 vWorldTangent : TEXCOORD1; + float3 vWorldBinormal : TEXCOORD2; + float4 vWorldPosition : TEXCOORD3; // Proj pos z in w + float3 vProjPosForRefract : TEXCOORD4; + float4 vNoiseTexCoord : TEXCOORD5; +}; + +// This is the equilavent of smoothstep built into HLSL but linear +float linearstep( float iMin, float iMax, float iValue ) +{ + return saturate( ( iValue - iMin ) / ( iMax - iMin ) ); +} + +// Main =========================================================================================== +float4 main( PS_INPUT i ) : COLOR +{ + float kFlPortalOuterBorder = 0.075f; // Must match VS! + float kFlPortalInnerBorder = kFlPortalOuterBorder * 4.0f; + + // Add a slight border around the portal opening (Do this in the VS?) + //i.vUv0.xy = i.vUv0.xy * ( 1.0f + kFlPortalOuterBorder ) - ( kFlPortalOuterBorder * 0.5f ); + + // Portal open time + float flPortalOpenAmount = smoothstep( 0.0f, 1.0f, saturate( g_flPortalOpenAmount ) ); + //float flPortalOpenAmount = saturate( g_flPortalOpenAmount ); + float flPortalOpenAmountSquared = flPortalOpenAmount * flPortalOpenAmount; + + // Stretch values + float2 vStretchVector = ( i.vUv0.xy * 2.0f ) - 1.0f; + float flDistFromCenter = length( vStretchVector ); + float2 vStretchVectorNormalized = normalize( vStretchVector ); + + // Stencil cutout (1.0 in hole) + float flStencilCutout = step( flDistFromCenter, flPortalOpenAmountSquared ); + + //==================================// + // Stage 0: Warp pixels around hole // + //==================================// + #if ( STAGE == 0 ) + { + // Unrefracted tex coords + float2 vRefractTexCoordNoWarp = i.vProjPosForRefract.xy / i.vProjPosForRefract.z; + + // Projected screen-space tangent + float3 vProjTangent; + vProjTangent.x = dot( float4( i.vWorldTangent.xyz, 1.0f ), g_mViewProj0.xyzw ); // 1st row + vProjTangent.y = -dot( float4( i.vWorldTangent.xyz, 1.0f ), g_mViewProj1.xyzw ); // 2nd row + vProjTangent.z = dot( float4( i.vWorldTangent.xyz, 1.0f ), g_mViewProj3.xyzw ); // 4th row + vProjTangent.xy += vProjTangent.z; + vProjTangent.xy *= 0.5f; + vProjTangent.xy /= vProjTangent.z; + vProjTangent.xy -= vRefractTexCoordNoWarp.xy; + + // Projected screen-space binormal + float3 vProjBinormal; + vProjBinormal.x = dot( float4( i.vWorldBinormal.xyz, 1.0f ), g_mViewProj0.xyzw ); // 1st row + vProjBinormal.y = -dot( float4( i.vWorldBinormal.xyz, 1.0f ), g_mViewProj1.xyzw ); // 2nd row + vProjBinormal.z = dot( float4( i.vWorldBinormal.xyz, 1.0f ), g_mViewProj3.xyzw ); // 4th row + vProjBinormal.xy += vProjBinormal.z; + vProjBinormal.xy *= 0.5f; + vProjBinormal.xy /= vProjBinormal.z; + vProjBinormal.xy -= vRefractTexCoordNoWarp.xy; + + // Tangent-space uv offset + float2 vTangentRefract = -vStretchVectorNormalized * flPortalOpenAmountSquared * ( 1.0f - pow( saturate( flDistFromCenter ), 64.0f ) ); + vTangentRefract.xy *= smoothstep( ( flPortalOpenAmount * 1.5f ), flPortalOpenAmount, flDistFromCenter ); + + // Note: This works well perpendicular to the surface, but because the projection is non-linear, it's refracty very edge on + float2 kPortalRadius = { 32.0f, 32.0f }; // Should be 32, 54 but this reduces the artifacts from the comment above + vTangentRefract.xy *= kPortalRadius.xy; + + // Generate refracteds screen-space uv + float2 vRefractTexCoord = vRefractTexCoordNoWarp.xy; + vRefractTexCoord.xy += vTangentRefract.x * vProjTangent.xy; + vRefractTexCoord.xy -= vTangentRefract.y * vProjBinormal.xy; + + // Fetch color from texture + float3 cRefract = tex2D( g_tRefractionSampler, vRefractTexCoord.xy ); + + // In some cases, we have to convert this render target from sRGB to Linear ourselves here + #if ( SHADER_SRGB_READ == 1 ) + { + cRefract = GammaToLinear( cRefract ); + } + #endif + + // Darken the ring around the portal as it's opening to help it stand out on plain walls + float flHoleEdge = flPortalOpenAmountSquared; + float flDimEdge = saturate( flPortalOpenAmount * 2.0f ); + float flDarkeningRing = linearstep( flHoleEdge - 0.01f, flDimEdge, flDistFromCenter ); + flDarkeningRing = ( abs( flDarkeningRing * 2.0f - 1.0f ) * 0.15f ) + 0.85f; + + //===============// + // Combine terms // + //===============// + float4 result; + result.rgb = cRefract.rgb; + result.rgb *= flDarkeningRing; + + // Alpha test away outside the portal oval + result.a = step( flDistFromCenter, 1.0f ); + + return FinalOutput( result, 0.0f, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE ); + } + #endif + + //============================================================================// + // Stage 1: Cut a hole in the stencil buffer (only render pixels in the hole) // + //============================================================================// + #if ( STAGE == 1 ) + { + float4 result; + result.rgb = 0.0f; + result.a = flStencilCutout; + //result = 0.0f; // Disable the hole for debugging + return result; + } + #endif + + //============================================// + // Stage 2: Fire effect around rim of opening // + //============================================// + #if ( STAGE == 2 ) + { + // Outer effect mask + float flOuterEffectMask = ( 1.0f - linearstep( flPortalOpenAmountSquared, flPortalOpenAmountSquared + kFlPortalOuterBorder, flDistFromCenter ) ) * ( 1.0f - flStencilCutout ); + + // Inner effect mask + float flInnerEffectMask = ( linearstep( flPortalOpenAmountSquared - kFlPortalInnerBorder, flPortalOpenAmountSquared, flDistFromCenter ) ) * ( flStencilCutout ); + + // Fade it in as the portal is opening + //float flPortalActive = smoothstep( 0.0f, 1.0f, saturate( g_flPortalActive ) ); + float flPortalActive = saturate( g_flPortalActive ); // This is good enough...smoothstep above is not necessary + //flPortalActive = linearstep( 0.0f, saturate( flDistFromCenter ), saturate( flPortalActive ) ); // Experiment to fade from center out + float flEffectFadeIn = max( saturate( flPortalOpenAmount * 2.5f ), ( 1.0f - flPortalActive ) ); + + // Combine mask terms + float flEffectMask = ( flInnerEffectMask + flOuterEffectMask ) * flEffectFadeIn; + //flEffectMask = pow( flEffectMask, 0.75f ); // This will thicken the border but also darken the alpha blend in ugly ways. Leaving this here for experiments later. + + float4 cNoiseTexel1 = tex2D( g_tPortalNoiseSampler, i.vNoiseTexCoord.xy ); + float4 cNoiseTexel2 = tex2D( g_tPortalNoiseSampler, i.vNoiseTexCoord.wz - cNoiseTexel1.rg*0.02 ); + cNoiseTexel1.rgba = tex2D( g_tPortalNoiseSampler, i.vNoiseTexCoord.xy - cNoiseTexel2.rg*0.02 ); + + //float flNoise = ( ( cNoiseTexel1.g * cNoiseTexel2.g ) * 2.0f ); // More broken up flames and crazier + float flNoise = ( ( cNoiseTexel1.g + cNoiseTexel2.g ) * 0.5f ); // More solid flames and calmer + float flPortalActiveWithNoise = smoothstep( 0.0f, flNoise, flPortalActive ); + + float kFlBorderSoftness = 0.875f; // Larger numbers give more color in the middle when portal is inactive + float flBorderMaskWithNoise = ( 1.0f - smoothstep( flEffectMask - kFlBorderSoftness, flEffectMask + kFlBorderSoftness, flNoise ) ); + flNoise = flBorderMaskWithNoise; + flEffectMask *= flBorderMaskWithNoise; + + // This will get stuffed in alpha + float flTransparancy = saturate( flEffectMask + ( flStencilCutout * ( 1.0f - flPortalActiveWithNoise ) ) ) * 1.5f; // Magic number at the end will make the flames thicker with larger numbers + + // This will make the portals shift in color from bottom to top (Set to 1.0f to disable) + //float flBottomToTopBrightnessShift = ( pow( abs(i.vUv0.y), 1.5f ) * 0.9f ) + 0.1f; // More extreme + //float flBottomToTopBrightnessShift = ( pow( abs(i.vUv0.y), 1.5f ) * 0.85f ) + 0.15f; + float flBottomToTopBrightnessShift = ( pow( abs(i.vUv0.y), 1.5f ) * 0.8f ) + 0.2f; + //float flBottomToTopBrightnessShift = ( pow( abs(i.vUv0.y), 1.5f ) * 0.75f ) + 0.25f; // More subtle (needs higher color scale below) + //float flBottomToTopBrightnessShift = 1.0f; // Disabled + + // Fetch color from 1D texture + float4 cFlameColor = tex1D( g_tPortalColorSampler, pow( flNoise, 0.5f ) * flBottomToTopBrightnessShift * flTransparancy ); + cFlameColor.rgb *= g_flPortalColorScale; // Brighten colors to make it look more emissive + + // Generate final color result + float4 result; + result.rgb = cFlameColor.rgb; + result.a = flTransparancy; + //result.rgb *= result.a; // This will give better definition to the flames but also darkens the outer rim + //result.rgb = pow( result.rgb, 1.5f ); + //result.rgb *= result.rgb; // Make it look hotter + + // Debugging + //result.rgba = flBorderMaskWithNoise; + //result.rgba = flEffectMask; + //result.rgba = flTransparancy; + //result.rgba = flPortalActive * flStencilCutout; + + // Apply fog and deal with HDR + float fogFactor = CalcPixelFogFactor( PIXELFOGTYPE, g_vFogParams, g_vCameraPosition.z, i.vWorldPosition.z, i.vWorldPosition.w ); + return FinalOutput( result, fogFactor, PIXELFOGTYPE, TONEMAP_SCALE_LINEAR ); + } + #endif +} diff --git a/materialsystem/stdshaders/portal_refract_vs11.fxc b/materialsystem/stdshaders/portal_refract_vs11.fxc new file mode 100644 index 0000000..4f8425d --- /dev/null +++ b/materialsystem/stdshaders/portal_refract_vs11.fxc @@ -0,0 +1,63 @@ +//========= Copyright © 1996-2006, Valve Corporation, All rights reserved. ============// + +// STATIC: "STAGE" "0..2" + +// Includes +#include "common_vs_fxc.h" + +// Globals +//const float g_flTime : register( SHADER_SPECIFIC_CONST_0 ); +const float4 cBaseTexCoordTransform[2] : register( SHADER_SPECIFIC_CONST_1 ); + +const float2 g_vConst3 : register( SHADER_SPECIFIC_CONST_3 ); +#define g_flPortalOpenAmount g_vConst3.x +#define g_flPortalStaticAmount g_vConst3.y + +// Structs +struct VS_INPUT +{ + float4 vPos : POSITION; // Position + float4 vTexCoord0 : TEXCOORD0; // Base texture coordinates +}; + +struct VS_OUTPUT +{ + float4 vProjPosition : POSITION; // Projection-space position + float2 vUv0 : TEXCOORD0; + float2 vUv1 : TEXCOORD1; + + #ifndef _X360 + float fog : FOG; + #endif +}; + +// Main +VS_OUTPUT main( const VS_INPUT i ) +{ + float kFlPortalOuterBorder = 0.075f; // Must match PS! + + VS_OUTPUT o; + + // Transform the position + o.vProjPosition.xyzw = mul( i.vPos, cModelViewProj ); + + // Portal open time + float flPortalOpenAmount = saturate( g_flPortalOpenAmount + 0.001f ); // 0.001f to avoid divide by zero + + // Texture coordinates + float2 vBaseUv; + vBaseUv.x = dot( i.vTexCoord0.xy, cBaseTexCoordTransform[0] ); + vBaseUv.y = dot( i.vTexCoord0.xy, cBaseTexCoordTransform[1] ); + o.vUv0.xy = ( ( vBaseUv.xy - 0.5f ) / ( flPortalOpenAmount * flPortalOpenAmount ) ) + 0.5f; + o.vUv1.xy = o.vUv0.xy; + + // Fog + #ifndef _X360 + { + float3 vWorldPos = mul( i.vPos, cModel[0] ); + o.fog = CalcFog( vWorldPos.xyz, o.vProjPosition, FOGTYPE_RANGE ); + } + #endif + + return o; +} diff --git a/materialsystem/stdshaders/portal_refract_vs20.fxc b/materialsystem/stdshaders/portal_refract_vs20.fxc new file mode 100644 index 0000000..86c04ba --- /dev/null +++ b/materialsystem/stdshaders/portal_refract_vs20.fxc @@ -0,0 +1,90 @@ +//========= Copyright © 1996-2006, Valve Corporation, All rights reserved. ============// + +// STATIC: "STAGE" "0..2" + +// Includes +#include "common_vs_fxc.h" + +// Globals +const float g_flTime : register( SHADER_SPECIFIC_CONST_0 ); +const float4 cBaseTexCoordTransform[2] : register( SHADER_SPECIFIC_CONST_1 ); + +const float2 g_vConst3 : register( SHADER_SPECIFIC_CONST_3 ); +#define g_flPortalOpenAmount g_vConst3.x +#define g_flPortalStaticAmount g_vConst3.y + +// Structs +struct VS_INPUT +{ + float4 vPos : POSITION; // Position + float4 vNormal : NORMAL; // Normal + float4 vTexCoord0 : TEXCOORD0; // Base texture coordinates + float4 vTangent : TANGENT; // Flip in w +}; + +struct VS_OUTPUT +{ + float4 vProjPosition : POSITION; // Projection-space position + float2 vUv0 : TEXCOORD0; + float3 vWorldTangent : TEXCOORD1; + float3 vWorldBinormal : TEXCOORD2; + float4 vWorldPosition : TEXCOORD3; // Proj pos z in w + float3 vProjPosForRefract : TEXCOORD4; + float4 vNoiseTexCoord : TEXCOORD5; +}; + +// Main +VS_OUTPUT main( const VS_INPUT i ) +{ + float kFlPortalOuterBorder = 0.075f; // Must match PS! + + VS_OUTPUT o; + + float3 vObjNormal; + DecompressVertex_Normal( i.vNormal, vObjNormal ); + + // Transform the position + float3 vWorldPosition = mul( i.vPos, cModel[0] ); + float3 vWorldNormal = normalize( mul( vObjNormal, ( float3x3 )cModel[0] ) ); + float3 vWorldTangent = normalize( mul( i.vTangent, ( float3x3 )cModel[0] ) ); + float3 vWorldBinormal = normalize( cross( vWorldNormal, vWorldTangent ) * i.vTangent.w ); + + o.vWorldPosition.xyz = vWorldPosition.xyz; + //o.vWorldNormal.xyz = vWorldNormal.xyz; + o.vWorldTangent.xyz = vWorldTangent.xyz + vWorldPosition.xyz; + o.vWorldBinormal.xyz = vWorldBinormal.xyz + vWorldPosition.xyz; + + // Transform into projection space + float4 vProjPosition = mul( float4( vWorldPosition, 1.0f ), cViewProj ); + o.vProjPosition.xyzw = vProjPosition.xyzw; + o.vWorldPosition.w = vProjPosition.z; + + // Map projected position to the refraction texture + float2 vRefractPos; + vRefractPos.x = vProjPosition.x; + vRefractPos.y = -vProjPosition.y; // Invert Y + vRefractPos = ( vRefractPos + vProjPosition.w ) * 0.5f; + o.vProjPosForRefract.xyz = float3(vRefractPos.x, vRefractPos.y, vProjPosition.w); + + // View vector + float3 vWorldViewVector = normalize (vWorldPosition.xyz - cEyePos.xyz); + + // Texture coordinates + float2 vBaseUv; + vBaseUv.x = dot( i.vTexCoord0.xy, cBaseTexCoordTransform[0] ); + vBaseUv.y = dot( i.vTexCoord0.xy, cBaseTexCoordTransform[1] ); + //o.vUv0.xy = vBaseUv.xy; + o.vUv0.xy = vBaseUv.xy * ( 1.0f + kFlPortalOuterBorder ) - ( kFlPortalOuterBorder * 0.5f ); // Adjust uv's for shrunken portal + + // Portal open time + float flPortalOpenAmount = saturate( g_flPortalOpenAmount + 0.001f ); // 0.001f to avoid divide by zero + + // Noise UV + float kFlBorderNoiseScale = 0.3f; + float kFlNoiseUvScroll = g_flTime * 0.0275f; + float2 vNoiseUv = ( ( vBaseUv.xy - 0.5f ) / flPortalOpenAmount ) + 0.5f; + o.vNoiseTexCoord.xy = ( vNoiseUv.xy * kFlBorderNoiseScale ) + float2( kFlNoiseUvScroll, 0 ); + o.vNoiseTexCoord.zw = ( vNoiseUv.xy * kFlBorderNoiseScale ) - float2( kFlNoiseUvScroll, 0 ); // Will fetch as wz to avoid matching layers + + return o; +} diff --git a/materialsystem/stdshaders/portal_vs11.fxc b/materialsystem/stdshaders/portal_vs11.fxc new file mode 100644 index 0000000..1f30750 --- /dev/null +++ b/materialsystem/stdshaders/portal_vs11.fxc @@ -0,0 +1,142 @@ +// STATIC: "MAXTEXTURESTAGES" "0..2" +// STATIC: "HASALPHAMASK" "0..1" +// STATIC: "HASSTATICTEXTURE" "0..1" +// STATIC: "USEALTERNATEVIEW" "0..1" + +// DYNAMIC: "SKINNING" "0..1" +// DYNAMIC: "ADDSTATIC" "0..1" +//in multipass configurations, this specifies whether we're adding static on this pass + +#define TEXTURESTAGES (MAXTEXTURESTAGES + 1) +#define USESTATICTEXTURE (((ADDSTATIC == 1) && (HASSTATICTEXTURE == 1))?(1):(0)) + +#include "common_vs_fxc.h" + +static const int g_bSkinning = SKINNING ? true : false; + +#if ( USEALTERNATEVIEW == 1 ) +const float4x4 g_CustomViewProj : register( SHADER_SPECIFIC_CONST_0 ); +#endif + +struct VS_INPUT +{ + float4 vPos : POSITION; + + float4 vBoneWeights : BLENDWEIGHT; + float4 vBoneIndices : BLENDINDICES; + float2 vMappingTexCoord : TEXCOORD0; +}; + + +struct VS_OUTPUT +{ + float4 vProjPos : POSITION; + float2 vPrimaryTexCoord : TEXCOORD0; //either the portal cutout, or static + +# if( TEXTURESTAGES == 3 ) +# if( (HASALPHAMASK == 1) || (USESTATICTEXTURE == 1) ) + float2 vSecondaryTexCoord : TEXCOORD1; +# if( (HASALPHAMASK == 1) && (USESTATICTEXTURE == 1) ) + float2 vTertiaryTexCoord : TEXCOORD2; +# endif +# endif +# elif( TEXTURESTAGES > 1 && HASALPHAMASK == 1 ) + float2 vSecondaryTexCoord : TEXCOORD1; +# endif + +# if( !defined( _X360 ) ) + float vFog : FOG; +# endif +}; + +float2 GetPortalTextureCoordinate( float3 worldPos, float4 projPos ) +{ + float2 result; + + float4 vTextureProjectedPos; +#if ( USEALTERNATEVIEW == 1 ) + vTextureProjectedPos = mul( float4( worldPos, 1 ), g_CustomViewProj ); +#else + vTextureProjectedPos = projPos; +#endif + + //Screen coordinates mapped back to texture coordinates for the portal texture + result.x = vTextureProjectedPos.x; + result.y = -vTextureProjectedPos.y; // invert Y + result.xy = (result.xy + vTextureProjectedPos.w) * 0.5f; + result.xy = result.xy / vTextureProjectedPos.w; + +#if ( USEALTERNATEVIEW == 1 ) + result.xy = saturate( result.xy ); //stretch instead of clipping. +#endif + + return result; +} + +VS_OUTPUT main( const VS_INPUT v ) +{ + VS_OUTPUT o = ( VS_OUTPUT )0; + + float3 worldPos; + SkinPosition( + g_bSkinning, + v.vPos, + v.vBoneWeights, v.vBoneIndices, + worldPos ); + + o.vProjPos = mul( float4( worldPos, 1 ), cViewProj ); + + //Because we're pairing this with ps11, we can't divide the portal cutout texture coordinates in the pixel shader by w + //So, we had to divide it by w here in the vertex shader. Unfortunately that causes some interpolation inconsistencies + //between the position and the texture coordinate. So we also divide the position by w here. Causing the exact same projection + //errors for both position and texture coordinate, thereby eliminating the difference between the two that cause the "warping" look. + o.vProjPos.xyz = o.vProjPos.xyz * (1.0f / o.vProjPos.w); + o.vProjPos.w = 1.0f; + +#if !defined( _X360 ) + o.vFog = CalcFog( worldPos, o.vProjPos.xyz, FOGTYPE_RANGE ); +#endif + +# if( TEXTURESTAGES == 3 )//single pass configuration + { + o.vPrimaryTexCoord = GetPortalTextureCoordinate( worldPos, o.vProjPos ); + +# if( HASALPHAMASK == 1 ) + { + o.vSecondaryTexCoord = v.vMappingTexCoord.xy; +# if( USESTATICTEXTURE == 1 ) + o.vTertiaryTexCoord = v.vMappingTexCoord.xy; +# endif + } +# else + { +# if( USESTATICTEXTURE == 1 ) + o.vSecondaryTexCoord = v.vMappingTexCoord.xy; +# endif + } +# endif + } +# else //multipass configuration + { +# if( ADDSTATIC == 0 ) //if addstatic is 0, we're rendering the cutout on this pass, if it's 1, we're rendering static on this pass + { + o.vPrimaryTexCoord = GetPortalTextureCoordinate( worldPos, o.vProjPos ); + } +# else + { + o.vPrimaryTexCoord = v.vMappingTexCoord.xy; + } +# endif + + +# if( (TEXTURESTAGES > 1) && (HASALPHAMASK == 1) ) //supports alpha mask as well + o.vSecondaryTexCoord = v.vMappingTexCoord.xy; +# endif + } +# endif + + + return o; +} + + \ No newline at end of file diff --git a/materialsystem/stdshaders/portal_vs20.fxc b/materialsystem/stdshaders/portal_vs20.fxc new file mode 100644 index 0000000..dd3f7e5 --- /dev/null +++ b/materialsystem/stdshaders/portal_vs20.fxc @@ -0,0 +1,97 @@ +// STATIC: "HASALPHAMASK" "0..1" +// STATIC: "HASSTATICTEXTURE" "0..1" +// STATIC: "USEALTERNATEVIEW" "0..1" + +// DYNAMIC: "SKINNING" "0..1" +// DYNAMIC: "ADDSTATIC" "0..1" + +#define USESTATICTEXTURE (((ADDSTATIC == 1) && (HASSTATICTEXTURE == 1))?(1):(0)) + +#include "common_vs_fxc.h" + +static const bool g_bSkinning = SKINNING ? true : false; + +#if ( USEALTERNATEVIEW == 1 ) +const float4x4 g_CustomViewProj : register( SHADER_SPECIFIC_CONST_0 ); +#endif + +struct VS_INPUT +{ + float4 vPos : POSITION; + + float4 vBoneWeights : BLENDWEIGHT; + float4 vBoneIndices : BLENDINDICES; + float2 vMappingTexCoord : TEXCOORD0; +}; + + +struct VS_OUTPUT +{ + float4 vProjPos : POSITION; + float3 vPortalTexCoord : TEXCOORD0; + +# if( (HASALPHAMASK == 1) || (USESTATICTEXTURE == 1) ) + float2 vSecondaryTexCoord : TEXCOORD1; +# if( (HASALPHAMASK == 1) && (USESTATICTEXTURE == 1) ) + float2 vTertiaryTexCoord : TEXCOORD2; +# endif +# endif + +# if !defined( _X360 ) + float vFog : FOG; +# endif + + float4 worldPos_projPosZ : TEXCOORD7; // Necessary for pixel fog +}; + + +VS_OUTPUT main( const VS_INPUT v ) +{ + VS_OUTPUT o = ( VS_OUTPUT )0; + + float3 worldPos; + + SkinPosition( + g_bSkinning, + v.vPos, + v.vBoneWeights, v.vBoneIndices, + worldPos ); + + float4 vTextureProjectedPos; + + o.vProjPos = mul( float4( worldPos, 1 ), cViewProj ); + +#if ( USEALTERNATEVIEW == 1 ) + vTextureProjectedPos = mul( float4( worldPos, 1 ), g_CustomViewProj ); +#else + vTextureProjectedPos = o.vProjPos; +#endif + +#if !defined( _X360 ) + o.vFog = CalcFog( worldPos, o.vProjPos.xyz, FOGTYPE_RANGE ); +#endif + o.worldPos_projPosZ = float4( worldPos.xyz, o.vProjPos.z ); + + //Screen coordinates mapped back to texture coordinates for the portal texture + o.vPortalTexCoord.x = vTextureProjectedPos.x; + o.vPortalTexCoord.y = -vTextureProjectedPos.y; // invert Y + o.vPortalTexCoord.xy = (o.vPortalTexCoord.xy + vTextureProjectedPos.w) * 0.5f; + o.vPortalTexCoord.z = vTextureProjectedPos.w; + +#if ( USEALTERNATEVIEW == 1 ) + o.vPortalTexCoord.xy = saturate( o.vPortalTexCoord.xy / vTextureProjectedPos.w ) * vTextureProjectedPos.w; //stretch instead of clipping. +#endif + +# if( (HASALPHAMASK == 1) || (USESTATICTEXTURE == 1) ) + { + o.vSecondaryTexCoord = v.vMappingTexCoord.xy; +# if( (HASALPHAMASK == 1) && (USESTATICTEXTURE == 1) ) + o.vTertiaryTexCoord = v.vMappingTexCoord.xy; +# endif + } +# endif + + return o; +} + + \ No newline at end of file diff --git a/materialsystem/stdshaders/portalstaticoverlay.cpp b/materialsystem/stdshaders/portalstaticoverlay.cpp new file mode 100644 index 0000000..5ee3ea6 --- /dev/null +++ b/materialsystem/stdshaders/portalstaticoverlay.cpp @@ -0,0 +1,198 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//=============================================================================// + +#include "BaseVSShader.h" +#include "convar.h" +#include "portalstaticoverlay_vs20.inc" +#include "portalstaticoverlay_ps20.inc" +#include "portalstaticoverlay_ps20b.inc" +#include "cpp_shader_constant_register_map.h" + +BEGIN_VS_SHADER( PortalStaticOverlay, + "Help for PortalStaticOverlay shader" ) + + BEGIN_SHADER_PARAMS + SHADER_PARAM_OVERRIDE( COLOR, SHADER_PARAM_TYPE_COLOR, "{255 255 255}", "unused", SHADER_PARAM_NOT_EDITABLE ) + SHADER_PARAM_OVERRIDE( ALPHA, SHADER_PARAM_TYPE_FLOAT, "1.0", "unused", SHADER_PARAM_NOT_EDITABLE ) + SHADER_PARAM( STATICAMOUNT, SHADER_PARAM_TYPE_FLOAT, "0.0", "Amount of the static blend texture to blend into the base texture" ) + SHADER_PARAM( STATICBLENDTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "When adding static, this is the texture that gets blended in" ) + SHADER_PARAM( STATICBLENDTEXTUREFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "" ) + SHADER_PARAM( ALPHAMASKTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "An alpha mask for odd shaped portals" ) + SHADER_PARAM( ALPHAMASKTEXTUREFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "" ) + SHADER_PARAM( NOCOLORWRITE, SHADER_PARAM_TYPE_INTEGER, "0", "" ) + END_SHADER_PARAMS + + +SHADER_INIT_PARAMS() +{ + SET_FLAGS( MATERIAL_VAR_TRANSLUCENT ); +} + +SHADER_FALLBACK +{ + if( !g_pHardwareConfig->SupportsVertexAndPixelShaders() ) + return "PortalStaticOverlay_DX60"; + + return 0; +} + +SHADER_INIT +{ + if( params[STATICBLENDTEXTURE]->IsDefined() ) + LoadTexture( STATICBLENDTEXTURE ); + if( params[ALPHAMASKTEXTURE]->IsDefined() ) + LoadTexture( ALPHAMASKTEXTURE ); + + if( !params[STATICAMOUNT]->IsDefined() ) + params[STATICAMOUNT]->SetFloatValue( 0.0f ); + + if( !params[STATICBLENDTEXTURE]->IsDefined() ) + params[STATICBLENDTEXTURE]->SetIntValue( 0 ); + if( !params[STATICBLENDTEXTUREFRAME]->IsDefined() ) + params[STATICBLENDTEXTUREFRAME]->SetIntValue( 0 ); + + if( !params[ALPHAMASKTEXTURE]->IsDefined() ) + params[ALPHAMASKTEXTURE]->SetIntValue( 0 ); + if( !params[ALPHAMASKTEXTUREFRAME]->IsDefined() ) + params[ALPHAMASKTEXTUREFRAME]->SetIntValue( 0 ); + + if( !params[NOCOLORWRITE]->IsDefined() ) + params[NOCOLORWRITE]->SetIntValue( 0 ); +} + +SHADER_DRAW +{ + bool bStaticBlendTexture = params[STATICBLENDTEXTURE]->IsTexture(); + bool bAlphaMaskTexture = params[ALPHAMASKTEXTURE]->IsTexture(); //must support 2 texture stages to use a mask + + bool bIsModel = IS_FLAG_SET( MATERIAL_VAR_MODEL ); + bool bColorWrites = params[NOCOLORWRITE]->GetIntValue() == 0; + + SHADOW_STATE + { + SetInitialShadowState(); + FogToFogColor(); + + //pShaderShadow->EnablePolyOffset( SHADER_POLYOFFSET_DECAL ); //a portal is effectively a decal on top of a wall + pShaderShadow->DepthFunc( SHADER_DEPTHFUNC_NEAREROREQUAL ); + + pShaderShadow->EnableDepthWrites( true ); + + if( g_pHardwareConfig->GetHDRType() != HDR_TYPE_NONE ) + { + pShaderShadow->EnableSRGBWrite( true ); + } + + pShaderShadow->EnableBlending( true ); + pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA ); + + pShaderShadow->EnableAlphaTest( true ); + pShaderShadow->AlphaFunc( SHADER_ALPHAFUNC_GREATER, 0.0f ); + + pShaderShadow->EnableColorWrites( bColorWrites ); + + if( g_pHardwareConfig->GetHDRType() != HDR_TYPE_NONE ) + pShaderShadow->EnableSRGBWrite( true ); + + if( bStaticBlendTexture || bAlphaMaskTexture ) + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + if( bStaticBlendTexture && bAlphaMaskTexture ) + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + + int fmt = VERTEX_POSITION | VERTEX_NORMAL; + int userDataSize = 0; + if( bIsModel ) + { + userDataSize = 4; + } + else + { + fmt |= VERTEX_TANGENT_S | VERTEX_TANGENT_T; + } + pShaderShadow->VertexShaderVertexFormat( fmt, 1, 0, userDataSize ); + + DECLARE_STATIC_VERTEX_SHADER( portalstaticoverlay_vs20 ); + SET_STATIC_VERTEX_SHADER_COMBO( MODEL, bIsModel ); + SET_STATIC_VERTEX_SHADER( portalstaticoverlay_vs20 ); + + // Avoid setting a pixel shader when only doing depth/stencil operations, as recommended by PIX + if( bColorWrites || bAlphaMaskTexture || g_pHardwareConfig->PlatformRequiresNonNullPixelShaders() ) + { + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_STATIC_PIXEL_SHADER( portalstaticoverlay_ps20b ); + SET_STATIC_PIXEL_SHADER_COMBO( HASALPHAMASK, bAlphaMaskTexture ); + SET_STATIC_PIXEL_SHADER_COMBO( HASSTATICTEXTURE, bStaticBlendTexture ); + SET_STATIC_PIXEL_SHADER( portalstaticoverlay_ps20b ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( portalstaticoverlay_ps20 ); + SET_STATIC_PIXEL_SHADER_COMBO( HASALPHAMASK, bAlphaMaskTexture ); + SET_STATIC_PIXEL_SHADER_COMBO( HASSTATICTEXTURE, bStaticBlendTexture ); + SET_STATIC_PIXEL_SHADER( portalstaticoverlay_ps20 ); + } + } + } + DYNAMIC_STATE + { + pShaderAPI->SetDefaultState(); + + float fStaticAmount = params[STATICAMOUNT]->GetFloatValue(); + + //x is static, y is inverse static + float pc0[4] = { fStaticAmount, 1.0f - fStaticAmount, 0.0f, 0.0f }; + pShaderAPI->SetPixelShaderConstant( 0, pc0 ); + + if ( bStaticBlendTexture ) + { + BindTexture( SHADER_SAMPLER0, STATICBLENDTEXTURE, STATICBLENDTEXTUREFRAME ); + if( bAlphaMaskTexture ) + BindTexture( SHADER_SAMPLER1, ALPHAMASKTEXTURE, ALPHAMASKTEXTUREFRAME ); + } + else if( bAlphaMaskTexture ) + { + BindTexture( SHADER_SAMPLER0, ALPHAMASKTEXTURE, ALPHAMASKTEXTUREFRAME ); + } + + pShaderAPI->SetPixelShaderFogParams( PSREG_FOG_PARAMS ); + + float vEyePos_SpecExponent[4]; + pShaderAPI->GetWorldSpaceCameraPosition( vEyePos_SpecExponent ); + vEyePos_SpecExponent[3] = 0.0f; + pShaderAPI->SetPixelShaderConstant( PSREG_EYEPOS_SPEC_EXPONENT, vEyePos_SpecExponent, 1 ); + + DECLARE_DYNAMIC_VERTEX_SHADER( portalstaticoverlay_vs20 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, pShaderAPI->GetCurrentNumBones() > 0 ); + SET_DYNAMIC_VERTEX_SHADER( portalstaticoverlay_vs20 ); + + // Avoid setting a pixel shader when only doing depth/stencil operations, as recommended by PIX + if( bColorWrites || bAlphaMaskTexture || g_pHardwareConfig->PlatformRequiresNonNullPixelShaders() ) + { + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_DYNAMIC_PIXEL_SHADER( portalstaticoverlay_ps20b ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( HDRENABLED, IsHDREnabled() ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + SET_DYNAMIC_PIXEL_SHADER( portalstaticoverlay_ps20b ); + } + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( portalstaticoverlay_ps20 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( HDRENABLED, IsHDREnabled() ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + SET_DYNAMIC_PIXEL_SHADER( portalstaticoverlay_ps20 ); + } + } + } + + Draw(); +} + +END_SHADER + + diff --git a/materialsystem/stdshaders/portalstaticoverlay_dx60.cpp b/materialsystem/stdshaders/portalstaticoverlay_dx60.cpp new file mode 100644 index 0000000..709a6bf --- /dev/null +++ b/materialsystem/stdshaders/portalstaticoverlay_dx60.cpp @@ -0,0 +1,181 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//=============================================================================// + +#include "BaseVSShader.h" +#include "convar.h" +#include "d3dx.h" + +DEFINE_FALLBACK_SHADER( PortalStaticOverlay, PortalStaticOverlay_DX60 ); + +BEGIN_VS_SHADER( PortalStaticOverlay_DX60, + "Help for PortalStaticOverlay_DX60 shader" ) + + BEGIN_SHADER_PARAMS + SHADER_PARAM_OVERRIDE( COLOR, SHADER_PARAM_TYPE_COLOR, "{255 255 255}", "unused", SHADER_PARAM_NOT_EDITABLE ) + SHADER_PARAM_OVERRIDE( ALPHA, SHADER_PARAM_TYPE_FLOAT, "1.0", "unused", SHADER_PARAM_NOT_EDITABLE ) + SHADER_PARAM( STATICAMOUNT, SHADER_PARAM_TYPE_FLOAT, "0.0", "Amount of the static blend texture to blend into the base texture" ) + SHADER_PARAM( STATICBLENDTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "When adding static, this is the texture that gets blended in" ) + SHADER_PARAM( STATICBLENDTEXTUREFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "" ) + SHADER_PARAM( ALPHAMASKTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "An alpha mask for odd shaped portals" ) + SHADER_PARAM( ALPHAMASKTEXTUREFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "" ) + SHADER_PARAM( NOCOLORWRITE, SHADER_PARAM_TYPE_INTEGER, "0", "" ) + END_SHADER_PARAMS + + +SHADER_INIT_PARAMS() +{ + SET_FLAGS( MATERIAL_VAR_TRANSLUCENT ); +} + +SHADER_FALLBACK +{ + return 0; +} + + +SHADER_INIT +{ + if( params[STATICBLENDTEXTURE]->IsDefined() ) + LoadTexture( STATICBLENDTEXTURE ); + if( params[ALPHAMASKTEXTURE]->IsDefined() ) + LoadTexture( ALPHAMASKTEXTURE ); + + if( !params[STATICAMOUNT]->IsDefined() ) + params[STATICAMOUNT]->SetFloatValue( 0.0f ); + + if( !params[STATICBLENDTEXTURE]->IsDefined() ) + params[STATICBLENDTEXTURE]->SetIntValue( 0 ); + if( !params[STATICBLENDTEXTUREFRAME]->IsDefined() ) + params[STATICBLENDTEXTUREFRAME]->SetIntValue( 0 ); + + if( !params[ALPHAMASKTEXTURE]->IsDefined() ) + params[ALPHAMASKTEXTURE]->SetIntValue( 0 ); + if( !params[ALPHAMASKTEXTUREFRAME]->IsDefined() ) + params[ALPHAMASKTEXTUREFRAME]->SetIntValue( 0 ); + + if( !params[NOCOLORWRITE]->IsDefined() ) + params[NOCOLORWRITE]->SetIntValue( 0 ); +} + +SHADER_DRAW +{ + SHADOW_STATE + { + SetInitialShadowState(); + FogToFogColor(); + + //pShaderShadow->EnablePolyOffset( SHADER_POLYOFFSET_DECAL ); //a portal is effectively a decal on top of a wall + pShaderShadow->DepthFunc( SHADER_DEPTHFUNC_NEAREROREQUAL ); + + pShaderShadow->EnableDepthWrites( true ); + + pShaderShadow->EnableAlphaTest( true ); + pShaderShadow->EnableColorWrites( params[NOCOLORWRITE]->GetIntValue() == 0 ); + } + DYNAMIC_STATE + { + pShaderAPI->SetDefaultState(); + } + + if( params[ALPHAMASKTEXTURE]->IsTexture() ) + StaticPass_WithAlphaMask( pShaderShadow, pShaderAPI, params ); //portal static texture blending, with an alpha mask + else + StaticPass_NoAlphaMask( pShaderShadow, pShaderAPI, params ); //portal static texture blending +} + +void StaticPass_NoAlphaMask( IShaderShadow *pShaderShadow, IShaderDynamicAPI *pShaderAPI, IMaterialVar **params ) +{ + SHADOW_STATE + { + pShaderShadow->DrawFlags( SHADER_DRAW_POSITION | SHADER_DRAW_TEXCOORD0 ); + + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + + pShaderShadow->EnableBlending( true ); + pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA ); + + pShaderShadow->EnableCustomPixelPipe( true ); + pShaderShadow->CustomTextureStages( 1 ); + + pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE0, + SHADER_TEXCHANNEL_COLOR, + SHADER_TEXOP_SELECTARG1, + SHADER_TEXARG_TEXTURE, SHADER_TEXARG_TEXTURE ); + + pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE0, + SHADER_TEXCHANNEL_ALPHA, + SHADER_TEXOP_BLEND_CONSTANTALPHA, + SHADER_TEXARG_ZERO, SHADER_TEXARG_ONE ); + } + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER0, STATICBLENDTEXTURE, STATICBLENDTEXTUREFRAME ); + pShaderAPI->Color4f( 0.0f, 0.0f, 0.0f, params[STATICAMOUNT]->GetFloatValue() ); + } + Draw(); + SHADOW_STATE + { + pShaderShadow->EnableCustomPixelPipe( false ); + } +} + + +void StaticPass_WithAlphaMask( IShaderShadow *pShaderShadow, IShaderDynamicAPI *pShaderAPI, IMaterialVar **params ) +{ + SHADOW_STATE + { + pShaderShadow->DrawFlags( SHADER_DRAW_POSITION | SHADER_DRAW_TEXCOORD0 | SHADER_DRAW_TEXCOORD1 ); + + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + + pShaderShadow->EnableBlending( true ); + pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA ); + + pShaderShadow->EnableCustomPixelPipe( true ); + pShaderShadow->CustomTextureStages( 2 ); + + //portal static + pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE0, + SHADER_TEXCHANNEL_COLOR, + SHADER_TEXOP_SELECTARG1, + SHADER_TEXARG_TEXTURE, SHADER_TEXARG_TEXTURE ); + + pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE0, + SHADER_TEXCHANNEL_ALPHA, + SHADER_TEXOP_BLEND_CONSTANTALPHA, + SHADER_TEXARG_ZERO, SHADER_TEXARG_ONE ); + + + //alpha mask + pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE1, + SHADER_TEXCHANNEL_COLOR, + SHADER_TEXOP_SELECTARG1, + SHADER_TEXARG_PREVIOUSSTAGE, SHADER_TEXARG_PREVIOUSSTAGE ); + + pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE1, + SHADER_TEXCHANNEL_ALPHA, + SHADER_TEXOP_MODULATE, + SHADER_TEXARG_TEXTUREALPHA, SHADER_TEXARG_PREVIOUSSTAGE ); + } + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER0, STATICBLENDTEXTURE, STATICBLENDTEXTUREFRAME ); + BindTexture( SHADER_SAMPLER1, ALPHAMASKTEXTURE, ALPHAMASKTEXTUREFRAME ); + + pShaderAPI->Color4f( 0.0f, 0.0f, 0.0f, params[STATICAMOUNT]->GetFloatValue() ); + } + Draw(); + SHADOW_STATE + { + pShaderShadow->EnableCustomPixelPipe( false ); + } +} + +END_SHADER + + diff --git a/materialsystem/stdshaders/portalstaticoverlay_dx80.cpp b/materialsystem/stdshaders/portalstaticoverlay_dx80.cpp new file mode 100644 index 0000000..60d1e32 --- /dev/null +++ b/materialsystem/stdshaders/portalstaticoverlay_dx80.cpp @@ -0,0 +1,152 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//=============================================================================// + +#include "BaseVSShader.h" +#include "convar.h" +#include "portalstaticoverlay_vs11.inc" +#include "portalstaticoverlay_ps11.inc" + +BEGIN_VS_SHADER( PortalStaticOverlay, + "Help for PortalStaticOverlay shader" ) + + BEGIN_SHADER_PARAMS + SHADER_PARAM_OVERRIDE( COLOR, SHADER_PARAM_TYPE_COLOR, "{255 255 255}", "unused", SHADER_PARAM_NOT_EDITABLE ) + SHADER_PARAM_OVERRIDE( ALPHA, SHADER_PARAM_TYPE_FLOAT, "1.0", "unused", SHADER_PARAM_NOT_EDITABLE ) + SHADER_PARAM( STATICAMOUNT, SHADER_PARAM_TYPE_FLOAT, "0.0", "Amount of the static blend texture to blend into the base texture" ) + SHADER_PARAM( STATICBLENDTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "When adding static, this is the texture that gets blended in" ) + SHADER_PARAM( STATICBLENDTEXTUREFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "" ) + SHADER_PARAM( ALPHAMASKTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "An alpha mask for odd shaped portals" ) + SHADER_PARAM( ALPHAMASKTEXTUREFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "" ) + SHADER_PARAM( NOCOLORWRITE, SHADER_PARAM_TYPE_INTEGER, "0", "" ) + END_SHADER_PARAMS + + +SHADER_INIT_PARAMS() +{ + SET_FLAGS( MATERIAL_VAR_TRANSLUCENT ); +} + +SHADER_FALLBACK +{ + if( !g_pHardwareConfig->SupportsVertexAndPixelShaders() ) + return "PortalStaticOverlay_DX60"; + + return 0; +} + +SHADER_INIT +{ + if( params[STATICBLENDTEXTURE]->IsDefined() ) + LoadTexture( STATICBLENDTEXTURE ); + if( params[ALPHAMASKTEXTURE]->IsDefined() ) + LoadTexture( ALPHAMASKTEXTURE ); + + if( !params[STATICAMOUNT]->IsDefined() ) + params[STATICAMOUNT]->SetFloatValue( 0.0f ); + + if( !params[STATICBLENDTEXTURE]->IsDefined() ) + params[STATICBLENDTEXTURE]->SetIntValue( 0 ); + if( !params[STATICBLENDTEXTUREFRAME]->IsDefined() ) + params[STATICBLENDTEXTUREFRAME]->SetIntValue( 0 ); + + if( !params[ALPHAMASKTEXTURE]->IsDefined() ) + params[ALPHAMASKTEXTURE]->SetIntValue( 0 ); + if( !params[ALPHAMASKTEXTUREFRAME]->IsDefined() ) + params[ALPHAMASKTEXTUREFRAME]->SetIntValue( 0 ); + + if( !params[NOCOLORWRITE]->IsDefined() ) + params[NOCOLORWRITE]->SetIntValue( 0 ); +} + +SHADER_DRAW +{ + bool bStaticBlendTexture = params[STATICBLENDTEXTURE]->IsTexture(); + bool bAlphaMaskTexture = params[ALPHAMASKTEXTURE]->IsTexture(); + + bool bIsModel = IS_FLAG_SET( MATERIAL_VAR_MODEL ); + + SHADOW_STATE + { + SetInitialShadowState(); + FogToFogColor(); + + //pShaderShadow->EnablePolyOffset( SHADER_POLYOFFSET_DECAL ); //a portal is effectively a decal on top of a wall + pShaderShadow->DepthFunc( SHADER_DEPTHFUNC_NEAREROREQUAL ); + + pShaderShadow->EnableDepthWrites( true ); + + pShaderShadow->EnableBlending( true ); + pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA ); + + pShaderShadow->EnableAlphaTest( true ); + pShaderShadow->AlphaFunc( SHADER_ALPHAFUNC_GREATER, 0.0f ); + + pShaderShadow->EnableColorWrites( params[NOCOLORWRITE]->GetIntValue() == 0 ); + + if( bStaticBlendTexture || bAlphaMaskTexture ) + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + if( bStaticBlendTexture && bAlphaMaskTexture ) + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + + int fmt = VERTEX_POSITION | VERTEX_NORMAL; + int userDataSize = 0; + if( bIsModel ) + { + userDataSize = 4; + } + else + { + fmt |= VERTEX_TANGENT_S | VERTEX_TANGENT_T; + } + pShaderShadow->VertexShaderVertexFormat( fmt, 1, 0, userDataSize ); + + DECLARE_STATIC_VERTEX_SHADER( portalstaticoverlay_vs11 ); + SET_STATIC_VERTEX_SHADER_COMBO( MODEL, bIsModel ); + SET_STATIC_VERTEX_SHADER( portalstaticoverlay_vs11 ); + + DECLARE_STATIC_PIXEL_SHADER( portalstaticoverlay_ps11 ); + SET_STATIC_PIXEL_SHADER_COMBO( HASALPHAMASK, bAlphaMaskTexture ); + SET_STATIC_PIXEL_SHADER_COMBO( HASSTATICTEXTURE, bStaticBlendTexture ); + SET_STATIC_PIXEL_SHADER( portalstaticoverlay_ps11 ); + } + DYNAMIC_STATE + { + pShaderAPI->SetDefaultState(); + + float fStaticAmount = params[STATICAMOUNT]->GetFloatValue(); + + //x is static, y is inverse static + float pc0[4] = { fStaticAmount, 1.0f - fStaticAmount, 0.0f, 0.0f }; + pShaderAPI->SetPixelShaderConstant( 0, pc0 ); + + if( bStaticBlendTexture ) + { + BindTexture( SHADER_SAMPLER0, STATICBLENDTEXTURE, STATICBLENDTEXTUREFRAME ); + if( bAlphaMaskTexture ) + BindTexture( SHADER_SAMPLER1, ALPHAMASKTEXTURE, ALPHAMASKTEXTUREFRAME ); + } + else if( bAlphaMaskTexture ) + { + BindTexture( SHADER_SAMPLER0, ALPHAMASKTEXTURE, ALPHAMASKTEXTUREFRAME ); + } + + DECLARE_DYNAMIC_VERTEX_SHADER( portalstaticoverlay_vs11 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, pShaderAPI->GetCurrentNumBones() > 0 ); + SET_DYNAMIC_VERTEX_SHADER( portalstaticoverlay_vs11 ); + + DECLARE_DYNAMIC_PIXEL_SHADER( portalstaticoverlay_ps11 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( HDRENABLED, IsHDREnabled() ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + SET_DYNAMIC_PIXEL_SHADER( portalstaticoverlay_ps11 ); + } + + Draw(); +} + +END_SHADER + + diff --git a/materialsystem/stdshaders/portalstaticoverlay_ps11.fxc b/materialsystem/stdshaders/portalstaticoverlay_ps11.fxc new file mode 100644 index 0000000..d049970 --- /dev/null +++ b/materialsystem/stdshaders/portalstaticoverlay_ps11.fxc @@ -0,0 +1,68 @@ +// STATIC: "HASALPHAMASK" "0..1" +// STATIC: "HASSTATICTEXTURE" "0..1" + +// DYNAMIC: "HDRENABLED" "0..1" +// DYNAMIC: "PIXELFOGTYPE" "0..1" + +#include "common_ps_fxc.h" + +const HALF3 g_StaticAmount : register( c0 ); //x is static, y is 1.0 - static + +#if( HASSTATICTEXTURE ) + sampler StaticTextureSampler : register( s0 ); +# if( HASALPHAMASK ) + sampler AlphaMaskSampler : register( s1 ); +# endif +#else +# if( HASALPHAMASK ) + sampler AlphaMaskSampler : register( s0 ); +# endif +#endif + +struct PS_INPUT +{ + float4 vProjPos : POSITION; + + //vStaticTexCoord and vAlphaMaskTexCoord are the same numbers, but we need to map TEXCOORD0 to sampler 0, and TEXCOORD1 to sampler1. ps11 compatibility issue +#if( HASSTATICTEXTURE ) + float2 vStaticTexCoord : TEXCOORD0; +# if( HASALPHAMASK ) + float2 vAlphaMaskTexCoord : TEXCOORD1; +# endif +#else +# if( HASALPHAMASK ) + float2 vAlphaMaskTexCoord : TEXCOORD0; +# else + float2 vUnusedTexCoord1 : TEXCOORD0; +# endif + float2 vUnusedTexCoord2 : TEXCOORD1; +#endif +}; + + + + +HALF4 main( PS_INPUT i ) : COLOR +{ + HALF4 result; + +# if( HASSTATICTEXTURE ) + result.rgb = tex2D( StaticTextureSampler, i.vStaticTexCoord ).rgb; +# else + result.rgb = 0.25; //without a static texture, just be gray +# endif + + + +# if( HASALPHAMASK ) + result.a = min( g_StaticAmount.x, tex2D( AlphaMaskSampler, i.vAlphaMaskTexCoord ).a ); //when static reaches 0, fades away completely, also never exceeds the mask's alpha +# else + result.a = g_StaticAmount.x; //when static reaches 0, fades away completely +# endif + + //result.r = 1.0; + //result.gb = 0.0; + //result.a = 0.5; + + return result; +} \ No newline at end of file diff --git a/materialsystem/stdshaders/portalstaticoverlay_ps2x.fxc b/materialsystem/stdshaders/portalstaticoverlay_ps2x.fxc new file mode 100644 index 0000000..a37f40e --- /dev/null +++ b/materialsystem/stdshaders/portalstaticoverlay_ps2x.fxc @@ -0,0 +1,74 @@ +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX] +// STATIC: "HASALPHAMASK" "0..1" +// STATIC: "HASSTATICTEXTURE" "0..1" + +// DYNAMIC: "HDRENABLED" "0..1" +// DYNAMIC: "PIXELFOGTYPE" "0..1" + +#include "common_ps_fxc.h" +#include "shader_constant_register_map.h" + +const HALF3 g_StaticAmount : register( c0 ); //x is static, y is 1.0 - static + +const float4 g_FogParams : register( PSREG_FOG_PARAMS ); +const float4 g_EyePos_SpecExponent : register( PSREG_EYEPOS_SPEC_EXPONENT ); + +#if( HASSTATICTEXTURE ) + sampler StaticTextureSampler : register( s0 ); +# if( HASALPHAMASK ) + sampler AlphaMaskSampler : register( s1 ); +# endif +#else +# if( HASALPHAMASK ) + sampler AlphaMaskSampler : register( s0 ); +# endif +#endif + +struct PS_INPUT +{ + float4 vProjPos : POSITION; + + //vStaticTexCoord and vAlphaMaskTexCoord are the same numbers, but we need to map TEXCOORD0 to sampler 0, and TEXCOORD1 to sampler1. ps11 compatibility issue +#if( HASSTATICTEXTURE ) + float2 vStaticTexCoord : TEXCOORD0; +# if( HASALPHAMASK ) + float2 vAlphaMaskTexCoord : TEXCOORD1; +# endif +#else +# if( HASALPHAMASK ) + float2 vAlphaMaskTexCoord : TEXCOORD0; +# else + float2 vUnusedTexCoord1 : TEXCOORD0; +# endif + float2 vUnusedTexCoord2 : TEXCOORD1; +#endif + + float4 worldPos_projPosZ : TEXCOORD7; // Necessary for pixel fog +}; + + + + +float4 main( PS_INPUT i ) : COLOR +{ + HALF4 result; + +# if( HASSTATICTEXTURE ) + result.rgb = tex2D( StaticTextureSampler, i.vStaticTexCoord ).rgb; +# else + result.rgb = 0.25; //without a static texture, just be gray +# endif + + + +# if( HASALPHAMASK ) + result.a = min( g_StaticAmount.x, tex2D( AlphaMaskSampler, i.vAlphaMaskTexCoord ).a ); //when static reaches 0, fades away completely, also never exceeds the mask's alpha +# else + result.a = g_StaticAmount.x; //when static reaches 0, fades away completely +# endif + + + float fogFactor = CalcPixelFogFactor( PIXELFOGTYPE, g_FogParams, g_EyePos_SpecExponent.z, i.worldPos_projPosZ.z, i.worldPos_projPosZ.w ); + return FinalOutput( result, fogFactor, PIXELFOGTYPE, TONEMAP_SCALE_LINEAR ); +} \ No newline at end of file diff --git a/materialsystem/stdshaders/portalstaticoverlay_vs11.fxc b/materialsystem/stdshaders/portalstaticoverlay_vs11.fxc new file mode 100644 index 0000000..6938427 --- /dev/null +++ b/materialsystem/stdshaders/portalstaticoverlay_vs11.fxc @@ -0,0 +1,55 @@ +// STATIC: "MODEL" "0..1" + +// DYNAMIC: "SKINNING" "0..1" + +#include "common_vs_fxc.h" + +static const bool g_bSkinning = SKINNING ? true : false; +static const bool g_bModel = MODEL ? true : false; + +struct VS_INPUT +{ + float4 vPos : POSITION; + + float4 vBoneWeights : BLENDWEIGHT; + float4 vBoneIndices : BLENDINDICES; + float4 vTexCoord : TEXCOORD0; +}; + + +struct VS_OUTPUT +{ + float4 vProjPos : POSITION; + float2 vTexCoord1 : TEXCOORD0; + float2 vTexCoord2 : TEXCOORD1; //just a copy of vTexCoord1, ps11 compatibility issue + float vFog : FOG; +}; + + +VS_OUTPUT main( const VS_INPUT v ) +{ + VS_OUTPUT o = ( VS_OUTPUT )0; + + float3 worldPos; + if( MODEL == 1 ) + { + SkinPosition( + g_bSkinning, + v.vPos, + v.vBoneWeights, v.vBoneIndices, + worldPos ); + } + else + { + worldPos = mul( v.vPos.xyz, cModel[0] ); + } + + o.vProjPos = mul( float4( worldPos, 1 ), cViewProj ); + o.vTexCoord1 = v.vTexCoord.xy; + o.vTexCoord2 = v.vTexCoord.xy; + o.vFog = CalcFog( worldPos, o.vProjPos.xyz, FOGTYPE_RANGE ); + + return o; +} + + \ No newline at end of file diff --git a/materialsystem/stdshaders/portalstaticoverlay_vs20.fxc b/materialsystem/stdshaders/portalstaticoverlay_vs20.fxc new file mode 100644 index 0000000..b4e4f36 --- /dev/null +++ b/materialsystem/stdshaders/portalstaticoverlay_vs20.fxc @@ -0,0 +1,58 @@ +// STATIC: "MODEL" "0..1" + +// DYNAMIC: "SKINNING" "0..1" + +#include "common_vs_fxc.h" + +static const bool g_bSkinning = SKINNING ? true : false; +static const bool g_bModel = MODEL ? true : false; + +struct VS_INPUT +{ + float4 vPos : POSITION; + + float4 vBoneWeights : BLENDWEIGHT; + float4 vBoneIndices : BLENDINDICES; + float4 vTexCoord : TEXCOORD0; +}; + + +struct VS_OUTPUT +{ + float4 vProjPos : POSITION; + float2 vTexCoord1 : TEXCOORD0; + float2 vTexCoord2 : TEXCOORD1; //just a copy of vTexCoord1, ps11 compatibility issue + float vFog : FOG; + + float4 worldPos_projPosZ : TEXCOORD7; // Necessary for pixel fog +}; + + +VS_OUTPUT main( const VS_INPUT v ) +{ + VS_OUTPUT o = ( VS_OUTPUT )0; + + float3 worldPos; + if( MODEL == 1 ) + { + SkinPosition( + g_bSkinning, + v.vPos, + v.vBoneWeights, v.vBoneIndices, + worldPos ); + } + else + { + worldPos = mul( v.vPos.xyz, cModel[0] ); + } + + o.vProjPos = mul( float4( worldPos, 1 ), cViewProj ); + o.worldPos_projPosZ = float4( worldPos.xyz, o.vProjPos.z ); + o.vTexCoord1 = v.vTexCoord.xy; + o.vTexCoord2 = v.vTexCoord.xy; + o.vFog = CalcFog( worldPos, o.vProjPos.xyz, FOGTYPE_RANGE ); + + return o; +} + + \ No newline at end of file diff --git a/materialsystem/stdshaders/predator.cpp b/materialsystem/stdshaders/predator.cpp new file mode 100644 index 0000000..4a49d14 --- /dev/null +++ b/materialsystem/stdshaders/predator.cpp @@ -0,0 +1,99 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//=============================================================================// + +#include "BaseVSShader.h" + +#include "predator.inc" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +DEFINE_FALLBACK_SHADER( Predator, Predator_DX80 ) + +BEGIN_VS_SHADER( Predator_DX80, + "Help for Predator" ) + + BEGIN_SHADER_PARAMS + SHADER_PARAM( REFRACTIONAMOUNT, SHADER_PARAM_TYPE_VEC2, "[0.2 0.2]", "refaction amount" ) + SHADER_PARAM( ENVMAP, SHADER_PARAM_TYPE_TEXTURE, "shadertest/shadertest_env", "envmap" ) + SHADER_PARAM( ENVMAPFRAME, SHADER_PARAM_TYPE_INTEGER, "", "envmap frame number" ) + SHADER_PARAM( ENVMAPMASK, SHADER_PARAM_TYPE_TEXTURE, "shadertest/shadertest_envmask", "envmap mask" ) + SHADER_PARAM( ENVMAPMASKFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "" ) + SHADER_PARAM( ENVMAPMASKSCALE, SHADER_PARAM_TYPE_FLOAT, "1", "envmap mask scale" ) + SHADER_PARAM( ENVMAPTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "envmap tint" ) + SHADER_PARAM( REFRACTTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "refraction tint" ) + SHADER_PARAM( BUMPMAP, SHADER_PARAM_TYPE_TEXTURE, "models/shadertes/shader1_normal", "bump map" ) + SHADER_PARAM( BUMPFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $bumpmap" ) + SHADER_PARAM( BUMPOFFSET, SHADER_PARAM_TYPE_VEC2, "[0 0]", "2D bump offset for texture scrolling" ) + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + SET_FLAGS2( MATERIAL_VAR2_NEEDS_TANGENT_SPACES ); + SET_FLAGS2( MATERIAL_VAR2_SUPPORTS_HW_SKINNING ); + SET_FLAGS( MATERIAL_VAR_TRANSLUCENT ); + SET_FLAGS2( MATERIAL_VAR2_NEEDS_POWER_OF_TWO_FRAME_BUFFER_TEXTURE ); + } + + SHADER_FALLBACK + { + if (!g_pHardwareConfig->SupportsVertexAndPixelShaders()) + return "Predator_DX60"; + return 0; + } + + SHADER_INIT + { + if( params[ENVMAP]->IsDefined() ) + { + LoadCubeMap( ENVMAP ); + } + if( params[ENVMAPMASK]->IsDefined() ) + { + LoadTexture( ENVMAPMASK ); + } + if( !params[ENVMAPTINT]->IsDefined() ) + { + params[ENVMAPTINT]->SetVecValue( 1.0f, 1.0f, 1.0f ); + } + if( !params[REFRACTTINT]->IsDefined() ) + { + params[REFRACTTINT]->SetVecValue( 1.0f, 1.0f, 1.0f ); + } + } + + SHADER_DRAW + { + // Refractive pass + SHADOW_STATE + { + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + int fmt = VERTEX_POSITION | VERTEX_NORMAL; + pShaderShadow->VertexShaderVertexFormat( fmt, 1, 0, 0 ); + + predator_Static_Index vshIndex; + pShaderShadow->SetVertexShader( "predator", vshIndex.GetIndex() ); + + pShaderShadow->SetPixelShader( "predator" ); + } + DYNAMIC_STATE + { + pShaderAPI->SetDefaultState(); + pShaderAPI->BindStandardTexture( SHADER_SAMPLER0, TEXTURE_FRAME_BUFFER_FULL_TEXTURE_0 ); + SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_4, REFRACTIONAMOUNT ); + float c95[4] = { 1.0f, 1.0f, 0.0f, 0.0f }; + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_5, c95, 1 ); + SetPixelShaderConstant( 2, REFRACTTINT ); + + predator_Dynamic_Index vshIndex; + vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + vshIndex.SetSKINNING( pShaderAPI->GetCurrentNumBones() > 0 ); + pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() ); + } + Draw(); + } +END_SHADER diff --git a/materialsystem/stdshaders/predator.psh b/materialsystem/stdshaders/predator.psh new file mode 100644 index 0000000..0494627 --- /dev/null +++ b/materialsystem/stdshaders/predator.psh @@ -0,0 +1,11 @@ +ps.1.1 + +; c2 - tint +tex t0 ; refraction + + +mul r0, t0, c2 + + + + diff --git a/materialsystem/stdshaders/predator.vsh b/materialsystem/stdshaders/predator.vsh new file mode 100644 index 0000000..3f71fd3 --- /dev/null +++ b/materialsystem/stdshaders/predator.vsh @@ -0,0 +1,86 @@ +vs.1.1 + +# DYNAMIC: "DOWATERFOG" "0..1" +# DYNAMIC: "SKINNING" "0..1" + +;------------------------------------------------------------------------------ +; Constants specified by the app +; c0 = (0, 1, 2, 0.5) +; c1 = (1/2.2, 0, 0, 0) +; c2 = camera position *in world space* +; c4-c7 = modelViewProj matrix (transpose) +; c8-c11 = ViewProj matrix (transpose) +; c12-c15 = model->view matrix (transpose) +; c16 = [fogStart, fogEnd, fogRange, undefined] +; +; Vertex components (as specified in the vertex DECL) +; $vPos = Position +; $vTexCoord0.xy = TexCoord0 +;------------------------------------------------------------------------------ + +#include "macros.vsh" + +;------------------------------------------------------------------------------ +; Vertex blending +;------------------------------------------------------------------------------ +&AllocateRegister( \$worldPos ); +&AllocateRegister( \$worldNormal ); +&SkinPositionAndNormal( $worldPos, $worldNormal ); + +;------------------------------------------------------------------------------ +; Transform the position from world to proj space +;------------------------------------------------------------------------------ + +&AllocateRegister( \$projPos ); + +dp4 $projPos.x, $worldPos, $cViewProj0 +dp4 $projPos.y, $worldPos, $cViewProj1 +dp4 $projPos.z, $worldPos, $cViewProj2 +dp4 $projPos.w, $worldPos, $cViewProj3 +mov oPos, $projPos + + +;------------------------------------------------------------------------------ +; Fog +;------------------------------------------------------------------------------ + +&CalcFog( $worldPos, $projPos ); + +&FreeRegister( \$worldPos ); + +;------------------------------------------------------------------------------ +; Transform the normal from world to proj space +;------------------------------------------------------------------------------ + +&AllocateRegister( \$projNormal ); + +; only do X and Y since that's all we care about +dp3 $projNormal.x, $worldNormal, $cViewProj0 +dp3 $projNormal.y, $worldNormal, $cViewProj1 + +&FreeRegister( \$worldNormal ); + +;------------------------------------------------------------------------------ +; Texture coordinates +;------------------------------------------------------------------------------ + +; NOTE: projPos isn't projPos after this point. :) + +; divide by z +rcp $projPos.w, $projPos.w +mul $projPos.xy, $projPos.w, $projPos.xy + +; map from -1..1 to 0..1 +mad $projPos.xy, $projPos.xy, $cHalf, $cHalf + +; tweak with the texcoords based on the normal and $refractionamount +mad $projPos.xy, $projNormal.xy, -$SHADER_SPECIFIC_CONST_4.xy, $projPos.xy ; FIXME + +; invert y +add $projPos.y, $cOne, -$projPos.y + +; hack scale for nvidia (Power of two texcoords are screwed.) +mul oT0.xy, $projPos.xy, $SHADER_SPECIFIC_CONST_5.xy + +&FreeRegister( \$projPos ); +&FreeRegister( \$projNormal ); diff --git a/materialsystem/stdshaders/predator_envmap.psh b/materialsystem/stdshaders/predator_envmap.psh new file mode 100644 index 0000000..f856821 --- /dev/null +++ b/materialsystem/stdshaders/predator_envmap.psh @@ -0,0 +1,7 @@ +ps.1.1 + +; c2 - envmaptint +tex t0 ; cube map + +mul r0.rgb, t0, c2 +mov r0.a, c0 diff --git a/materialsystem/stdshaders/pyro_vision.cpp b/materialsystem/stdshaders/pyro_vision.cpp new file mode 100644 index 0000000..9c861c7 --- /dev/null +++ b/materialsystem/stdshaders/pyro_vision.cpp @@ -0,0 +1,696 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//============================================================================= + +#include "BaseVSShader.h" +#include "commandbuilder.h" + +#include "pyro_vision_ps20.inc" +#include "pyro_vision_ps20b.inc" +#include "pyro_vision_vs20.inc" +#include "pyro_vision_ps30.inc" +#include "pyro_vision_vs30.inc" + +#include "../materialsystem_global.h" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + + +static ConVar mat_visualize_dof( "mat_visualize_dof", "0", FCVAR_CHEAT ); + + +class CPyroVision_DX9_Context : public CBasePerMaterialContextData +{ +public: + uint8 *m_pStaticCmds; + CCommandBufferBuilder< CFixedCommandStorageBuffer< 1000 > > m_SemiStaticCmdsOut; + + void ResetStaticCmds( void ) + { + if ( m_pStaticCmds ) + { + delete[] m_pStaticCmds; + m_pStaticCmds = NULL; + } + } + + CPyroVision_DX9_Context( void ) + { + m_pStaticCmds = NULL; + } + + ~CPyroVision_DX9_Context( void ) + { + ResetStaticCmds(); + } + +}; + + +static const float kDefaultStripeScale[ 3 ] = { 0.002f, 0.002f, 0.2f }; +static const float kDefaultStripeFadeNormal1[ 3 ] = { 0.0f, 0.0f, 1.0f }; +static const float kDefaultStripeFadeNormal2[ 3 ] = { 0.0f, 0.0f, 0.0f }; +static const float kDefaultStripeColor[ 3 ] = { 0.0f, 1.0f, 1.0f }; +static const float kDefaultSelfIllumTint[ 3 ] = { 1.0f, 1.0f, 1.0f }; +static const float kDefaultGrayStep[ 2 ] = { 0.0f, 1.0f }; + + +BEGIN_VS_SHADER( pyro_vision, "Help for pyro vision" ) + BEGIN_SHADER_PARAMS + + SHADER_PARAM( EFFECT, SHADER_PARAM_TYPE_INTEGER, "0.0", "" ) + + SHADER_PARAM( VERTEX_LIT, SHADER_PARAM_TYPE_INTEGER, "0.0", "" ) + SHADER_PARAM( FULLBRIGHT, SHADER_PARAM_TYPE_INTEGER, "0.0", "" ) + SHADER_PARAM( ALPHATESTREFERENCE, SHADER_PARAM_TYPE_FLOAT, "0.0", "" ) + + SHADER_PARAM( BASETEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "" ) + SHADER_PARAM( BASETEXTURE2, SHADER_PARAM_TYPE_TEXTURE, "shadertest/detail", "detail texture" ) + SHADER_PARAM( BLENDMODULATETEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "texture to use r/g channels for blend range for" ) + SHADER_PARAM( BLENDMASKTRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$blendmodulatetexture texcoord transform" ) + + SHADER_PARAM( STRIPETEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "" ) + SHADER_PARAM( STRIPE_SCALE, SHADER_PARAM_TYPE_VEC3, "[ 0.002 0.002 0.2 ]", "" ) + SHADER_PARAM( STRIPE_FADE_NORMAL1, SHADER_PARAM_TYPE_VEC3, "[ 0.0 0.0 1.0 ]", "" ) + SHADER_PARAM( STRIPE_FADE_NORMAL2, SHADER_PARAM_TYPE_VEC3, "[ 0.0 0.0 0.0 ]", "" ) + SHADER_PARAM( STRIPE_COLOR, SHADER_PARAM_TYPE_VEC3, "[ 0.0 0.0 0.0 ]", "" ) + SHADER_PARAM( STRIPE_LM_SCALE, SHADER_PARAM_TYPE_FLOAT, "0.0", "" ) + + // EFFECT 0 + SHADER_PARAM( BASE_STEP_RANGE, SHADER_PARAM_TYPE_VEC2, "[ 0.0 1.0 ]", "" ) + SHADER_PARAM( LIGHTMAP_STEP_RANGE, SHADER_PARAM_TYPE_VEC2, "[ 0.0 1.0 ]", "" ) + SHADER_PARAM( CANVAS, SHADER_PARAM_TYPE_TEXTURE, "", "" ) + SHADER_PARAM( CANVAS_SCALE, SHADER_PARAM_TYPE_VEC3, "[ 0.002 0.002 0.2 ]", "" ) + SHADER_PARAM( CANVAS_STEP_RANGE, SHADER_PARAM_TYPE_VEC2, "[ 0.0 1.0 ]", "" ) + SHADER_PARAM( CANVAS_COLOR_START, SHADER_PARAM_TYPE_VEC3, "[ 0.0 0.0 0.0 ]", "" ) + SHADER_PARAM( CANVAS_COLOR_END, SHADER_PARAM_TYPE_VEC3, "[ 0.0 0.0 0.0 ]", "" ) + + // EFFECT 1 + SHADER_PARAM( DIFFUSE_BASE, SHADER_PARAM_TYPE_FLOAT, "0.0", "" ) + SHADER_PARAM( DIFFUSE_WHITE, SHADER_PARAM_TYPE_FLOAT, "0.0", "" ) + SHADER_PARAM( GRAY_POWER, SHADER_PARAM_TYPE_FLOAT, "0.0", "" ) + SHADER_PARAM( GRAY_STEP, SHADER_PARAM_TYPE_VEC2, "[ 0.0 1.0 ]", "" ) + SHADER_PARAM( LIGHTMAP_GRADIENTS, SHADER_PARAM_TYPE_FLOAT, "0.0", "" ) + SHADER_PARAM( COLORBAR, SHADER_PARAM_TYPE_TEXTURE, "", "" ) + SHADER_PARAM( SELFILLUMTINT, SHADER_PARAM_TYPE_COLOR, "[ 1.0 1.0 1.0 ]", "Self-illumination tint" ) + + // EFFECT 2 Depth of Field + SHADER_PARAM( DOF_START_DISTANCE, SHADER_PARAM_TYPE_FLOAT, "0.0", "" ) + SHADER_PARAM( DOF_POWER, SHADER_PARAM_TYPE_FLOAT, "0.0", "" ) + SHADER_PARAM( DOF_MAX, SHADER_PARAM_TYPE_FLOAT, "0.0", "" ) + + // EFFECT 3 Pyro Post + SHADER_PARAM( WARPTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "" ) + SHADER_PARAM( NOISETEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "" ) + SHADER_PARAM( VIGNETTE_TEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "" ) + SHADER_PARAM( VIGNETTE_TILE, SHADER_PARAM_TYPE_TEXTURE, "", "" ) + SHADER_PARAM( NOISE_SCALE, SHADER_PARAM_TYPE_FLOAT, "0.0", "" ) + SHADER_PARAM( TIME_SCALE, SHADER_PARAM_TYPE_FLOAT, "0.0", "" ) + SHADER_PARAM( HEAT_HAZE_SCALE, SHADER_PARAM_TYPE_FLOAT, "0.0", "" ) + + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + SET_PARAM_INT_IF_NOT_DEFINED( EFFECT, 0 ); + SET_PARAM_INT_IF_NOT_DEFINED( VERTEX_LIT, 0 ); + SET_PARAM_INT_IF_NOT_DEFINED( FULLBRIGHT, 0 ); + SET_PARAM_FLOAT_IF_NOT_DEFINED( ALPHATESTREFERENCE, 0.0f ); + + SET_PARAM_STRING_IF_NOT_DEFINED( BLENDMASKTRANSFORM, "center .5 .5 scale 1 1 rotate 0 translate 0 0" ); + + SET_PARAM_VEC_IF_NOT_DEFINED( STRIPE_SCALE, kDefaultStripeScale, 3 ); + SET_PARAM_VEC_IF_NOT_DEFINED( STRIPE_FADE_NORMAL1, kDefaultStripeFadeNormal1, 3 ); + SET_PARAM_VEC_IF_NOT_DEFINED( STRIPE_FADE_NORMAL2, kDefaultStripeFadeNormal2, 3 ); + SET_PARAM_VEC_IF_NOT_DEFINED( STRIPE_COLOR, kDefaultStripeColor, 3 ); + SET_PARAM_FLOAT_IF_NOT_DEFINED( STRIPE_LM_SCALE, 0.0f ); + + SET_PARAM_FLOAT_IF_NOT_DEFINED( DIFFUSE_BASE, 0.0f ); + SET_PARAM_FLOAT_IF_NOT_DEFINED( DIFFUSE_WHITE, 0.0f ); + SET_PARAM_FLOAT_IF_NOT_DEFINED( GRAY_POWER, 1.0f ); + SET_PARAM_VEC_IF_NOT_DEFINED( GRAY_STEP, kDefaultGrayStep, 2 ); + SET_PARAM_FLOAT_IF_NOT_DEFINED( LIGHTMAP_GRADIENTS, 255.0f ); + + + SET_PARAM_VEC_IF_NOT_DEFINED( SELFILLUMTINT, kDefaultSelfIllumTint, 3 ); + + SET_PARAM_FLOAT_IF_NOT_DEFINED( DOF_START_DISTANCE, 0.1f ); + SET_PARAM_FLOAT_IF_NOT_DEFINED( DOF_POWER, 0.4f ); + SET_PARAM_FLOAT_IF_NOT_DEFINED( DOF_MAX, 0.7f ); + + SET_PARAM_FLOAT_IF_NOT_DEFINED( NOISE_SCALE, 0.2f ); + SET_PARAM_FLOAT_IF_NOT_DEFINED( TIME_SCALE, 0.02f ); + SET_PARAM_FLOAT_IF_NOT_DEFINED( HEAT_HAZE_SCALE, 0.2f ); + + bool bVertexLit = params[ VERTEX_LIT ]->GetIntValue() != 0; + + if ( bVertexLit ) + { + SET_FLAGS2( MATERIAL_VAR2_LIGHTING_VERTEX_LIT ); + } + SET_FLAGS2( MATERIAL_VAR2_SUPPORTS_HW_SKINNING ); + } + + SHADER_FALLBACK + { + return 0; + } + + SHADER_INIT + { + LoadTexture( BASETEXTURE, TEXTUREFLAGS_SRGB ); + + if ( params[ CANVAS ]->IsDefined() ) + { + LoadTexture( CANVAS, TEXTUREFLAGS_SRGB ); + } + + if ( params[ COLORBAR ]->IsDefined() ) + { + LoadTexture( COLORBAR, TEXTUREFLAGS_SRGB ); + } + + if ( params[ BASETEXTURE2 ]->IsDefined() ) + { + LoadTexture( BASETEXTURE2, TEXTUREFLAGS_SRGB ); + } + + if ( params[ BLENDMODULATETEXTURE ]->IsDefined() ) + { + LoadTexture( BLENDMODULATETEXTURE ); + } + + if ( params[ STRIPETEXTURE ]->IsDefined() ) + { + LoadTexture( STRIPETEXTURE, TEXTUREFLAGS_SRGB ); + } + + if ( params[ WARPTEXTURE ]->IsDefined() ) + { + LoadTexture( WARPTEXTURE ); + } + + if ( params[ NOISETEXTURE ]->IsDefined() ) + { + LoadTexture( NOISETEXTURE ); + } + + if ( params[ VIGNETTE_TEXTURE ]->IsDefined() ) + { + LoadTexture( VIGNETTE_TEXTURE ); + } + + if ( params[ VIGNETTE_TILE ]->IsDefined() ) + { + LoadTexture( VIGNETTE_TILE, TEXTUREFLAGS_SRGB ); + } + } + + SHADER_DRAW + { + CPyroVision_DX9_Context *pContextData = reinterpret_cast< CPyroVision_DX9_Context *> ( *pContextDataPtr ); + bool bNeedRegenStaticCmds = ( !pContextData ) || pShaderShadow; + bool bVertexLit = params[ VERTEX_LIT ]->GetIntValue() != 0; + bool bFullBright = params[ FULLBRIGHT ]->GetIntValue() != 0; + bool bUseStaticControlFlow = g_pHardwareConfig->SupportsStaticControlFlow(); + bool bHasVertexColor = IS_FLAG_SET( MATERIAL_VAR_VERTEXCOLOR ); + bool bHasBaseTexture2 = ( params[ BASETEXTURE2 ]->IsDefined() ) && ( params[ BASETEXTURE2 ]->IsTexture() ); + bool bHasBlendModulateTexture = bHasBaseTexture2 && ( params[ BLENDMODULATETEXTURE ]->IsDefined() ) && ( params[ BLENDMODULATETEXTURE ]->IsTexture() ); + bool bHasHeatHaze = ( params[ WARPTEXTURE ]->IsDefined() ) && ( params[ WARPTEXTURE ]->IsTexture() ); + int nEffect = params[ EFFECT ]->GetIntValue(); + bool bSelfIllum = IS_FLAG_SET( MATERIAL_VAR_SELFILLUM ); + bool bVisualizeDoF = mat_visualize_dof.GetBool(); + bool bIsAlphaTested = IS_FLAG_SET( MATERIAL_VAR_ALPHATEST ) != 0; + bool bFullyOpaque = !bIsAlphaTested; + bool bHasColorbar = ( params[ COLORBAR ]->IsDefined() ) && ( params[ COLORBAR ]->IsTexture() ); + bool bHasStripes = ( params[ STRIPETEXTURE ]->IsDefined() ) && ( params[ STRIPETEXTURE ]->IsTexture() ); + bool bHasStripesNormal2 = false; + if ( bHasStripes ) + { + Vector vNormal2; + + params[ STRIPE_FADE_NORMAL2 ]->GetVecValue( vNormal2.Base(), 3 ); + + if ( vNormal2.LengthSqr() > 0.5f ) + { + bHasStripesNormal2 = true; + } + } + + if ( !pContextData ) // make sure allocated + { + pContextData = new CPyroVision_DX9_Context; + *pContextDataPtr = pContextData; + } + + if ( nEffect == 3 ) + { + static ConVarRef pyro_vignette_distortion( "pyro_vignette_distortion" ); + + bHasHeatHaze &= pyro_vignette_distortion.GetBool(); + } + + + if ( pShaderShadow || bNeedRegenStaticCmds ) + { + pContextData->ResetStaticCmds(); + CCommandBufferBuilder< CFixedCommandStorageBuffer< 5000 > > staticCmdsBuf; + + Vector4D vParms(0, 0, 0, 0); + + params[ STRIPE_SCALE ]->GetVecValue( &vParms.x, 3 ); + staticCmdsBuf.SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, vParms.Base() ); + + staticCmdsBuf.BindTexture( this, SHADER_SAMPLER0, BASETEXTURE, -1 ); + staticCmdsBuf.BindStandardTexture( SHADER_SAMPLER1, TEXTURE_LIGHTMAP ); + if ( bHasBlendModulateTexture ) + { + staticCmdsBuf.BindTexture( this, SHADER_SAMPLER3, BLENDMODULATETEXTURE, -1 ); + staticCmdsBuf.BindTexture( this, SHADER_SAMPLER4, BASETEXTURE2, -1 ); + } + + if ( bHasStripes ) + { + staticCmdsBuf.BindTexture( this, SHADER_SAMPLER5, STRIPETEXTURE, -1 ); + + params[ STRIPE_COLOR ]->GetVecValue( &vParms.x, 3 ); + vParms.w = params[ STRIPE_LM_SCALE ]->GetFloatValue(); + staticCmdsBuf.SetPixelShaderConstant( 5, vParms.Base() ); + + params[ STRIPE_FADE_NORMAL1 ]->GetVecValue( &vParms.x, 3 ); + staticCmdsBuf.SetPixelShaderConstant( 6, vParms.Base() ); + + if ( bHasStripesNormal2 ) + { + params[ STRIPE_FADE_NORMAL2 ]->GetVecValue( &vParms.x, 3 ); + staticCmdsBuf.SetPixelShaderConstant( 7, vParms.Base() ); + } + } + + switch( nEffect ) + { + case 0: + { + params[ CANVAS_SCALE ]->GetVecValue( &vParms.x, 3 ); + staticCmdsBuf.SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_1, vParms.Base() ); + + staticCmdsBuf.BindTexture( this, SHADER_SAMPLER2, CANVAS, -1 ); + + params[ BASE_STEP_RANGE ]->GetVecValue( &vParms.x, 2 ); + params[ LIGHTMAP_STEP_RANGE ]->GetVecValue( &vParms.z, 2 ); + staticCmdsBuf.SetPixelShaderConstant( 0, vParms.Base() ); + + params[ CANVAS_STEP_RANGE ]->GetVecValue( &vParms.x, 2 ); + staticCmdsBuf.SetPixelShaderConstant( 2, vParms.Base() ); + + params[ CANVAS_COLOR_START ]->GetVecValue( &vParms.x, 3 ); + staticCmdsBuf.SetPixelShaderConstant( 3, vParms.Base() ); + + params[ CANVAS_COLOR_END ]->GetVecValue( &vParms.x, 3 ); + staticCmdsBuf.SetPixelShaderConstant( 4, vParms.Base() ); + } + break; + + case 1: + { + if ( bHasColorbar ) + { + staticCmdsBuf.BindTexture( this, SHADER_SAMPLER2, COLORBAR, -1 ); + } + + vParms.x = params[ GRAY_POWER ]->GetFloatValue(); + params[ GRAY_STEP ]->GetVecValue( &vParms.y, 2 ); + vParms.w = params[ LIGHTMAP_GRADIENTS ]->GetFloatValue(); + staticCmdsBuf.SetPixelShaderConstant( 0, vParms.Base() ); + + vParms[ 0 ] = params[ DIFFUSE_BASE ]->GetFloatValue(); + params[ SELFILLUMTINT ]->GetVecValue( &vParms[ 1 ], 3 ); + staticCmdsBuf.SetPixelShaderConstant( 2, vParms.Base() ); + } + break; + + case 2: + { + staticCmdsBuf.BindTexture( this, SHADER_SAMPLER4, BASETEXTURE2, -1 ); + + vParms.x = params[ DOF_START_DISTANCE ]->GetFloatValue(); + vParms.y = params[ DOF_POWER ]->GetFloatValue(); + vParms.z = params[ DOF_MAX ]->GetFloatValue(); + vParms.w = 0.0f; + staticCmdsBuf.SetPixelShaderConstant( 0, vParms.Base() ); + } + break; + + case 3: + { + staticCmdsBuf.BindTexture( this, SHADER_SAMPLER3, NOISETEXTURE, -1 ); + staticCmdsBuf.BindTexture( this, SHADER_SAMPLER4, WARPTEXTURE, -1 ); + staticCmdsBuf.BindTexture( this, SHADER_SAMPLER5, VIGNETTE_TEXTURE, -1 ); + staticCmdsBuf.BindTexture( this, SHADER_SAMPLER6, VIGNETTE_TILE, -1 ); + + vParms.x = params[ NOISE_SCALE ]->GetFloatValue(); + vParms.y = params[ TIME_SCALE ]->GetFloatValue(); + vParms.z = params[ HEAT_HAZE_SCALE ]->GetFloatValue(); + vParms.w = 0.0f; + staticCmdsBuf.SetPixelShaderConstant( 0, vParms.Base() ); + } + break; + } + + staticCmdsBuf.StoreEyePosInPixelShaderConstant( 10 ); + staticCmdsBuf.SetPixelShaderFogParams( 11 ); + staticCmdsBuf.End(); + + // now, copy buf + pContextData->m_pStaticCmds = new uint8[ staticCmdsBuf.Size() ]; + memcpy( pContextData->m_pStaticCmds, staticCmdsBuf.Base(), staticCmdsBuf.Size() ); + } + + if ( pShaderAPI && pContextData->m_bMaterialVarsChanged ) + { + // need to regenerate the semistatic cmds + pContextData->m_SemiStaticCmdsOut.Reset(); + pContextData->m_bMaterialVarsChanged = false; + + if ( bHasBlendModulateTexture ) + { + pContextData->m_SemiStaticCmdsOut.SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_10, BLENDMASKTRANSFORM ); + } + + Vector4D vParms; + +// vParms.x = pShaderAPI->LinearToGamma_HardwareSpecific( 1.0f ); + + switch( nEffect ) + { + case 0: + { + // set up shader modulation color + vParms[ 0 ] = vParms[ 1 ] = vParms[ 2] = vParms[ 3 ] = 1.0f; + ComputeModulationColor( vParms.Base() ); + float flLScale = pShaderAPI->GetLightMapScaleFactor(); + vParms[ 0 ] *= flLScale; + vParms[ 1 ] *= flLScale; + vParms[ 2 ] *= flLScale; + pContextData->m_SemiStaticCmdsOut.SetPixelShaderConstant( 1, vParms.Base() ); + } + break; + + case 1: + { + // set up shader modulation color + vParms[ 0 ] = vParms[ 1 ] = vParms[ 2] = vParms[ 3 ] = 1.0f; + ComputeModulationColor( vParms.Base() ); + float flLScale = pShaderAPI->GetLightMapScaleFactor(); + vParms[ 0 ] *= flLScale; + vParms[ 1 ] *= flLScale; + vParms[ 2 ] *= flLScale; + vParms[ 3 ] = params[ DIFFUSE_WHITE ]->GetFloatValue(); + pContextData->m_SemiStaticCmdsOut.SetPixelShaderConstant( 1, vParms.Base() ); + } + break; + } + + pContextData->m_SemiStaticCmdsOut.SetAmbientCubeDynamicStateVertexShader(); + pContextData->m_SemiStaticCmdsOut.End(); + } + + SHADOW_STATE + { + SetInitialShadowState( ); + + switch( nEffect ) + { + case 0: + case 1: + { + pShaderShadow->EnableDepthWrites( true ); + pShaderShadow->EnableDepthTest( true ); + + SetDefaultBlendingShadowState( BASETEXTURE ); + } + break; + + case 2: + { + pShaderShadow->EnableDepthWrites( false ); + pShaderShadow->EnableDepthTest( false ); + + pShaderShadow->EnableBlending( true ); + pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA ); + } + break; + + case 3: + { + pShaderShadow->EnableDepthWrites( false ); + pShaderShadow->EnableDepthTest( false ); + + pShaderShadow->EnableBlending( false ); + } + break; + } +// pShaderShadow->BlendOp( SHADER_BLEND_OP_REVSUBTRACT ); +// EnableAlphaBlending( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE ); + + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, true ); + + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + if( g_pHardwareConfig->GetHDRType() == HDR_TYPE_NONE ) + { + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER1, true ); + } + else + { + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER1, false ); + } + + pShaderShadow->EnableTexture( SHADER_SAMPLER2, true ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER2, true ); + + if ( nEffect == 0 || nEffect == 1 ) + { + if ( bHasBlendModulateTexture ) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER3, true ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER3, false ); + + pShaderShadow->EnableTexture( SHADER_SAMPLER4, true ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER4, true ); + } + + if ( bHasStripes ) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER5, true ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER5, true ); + } + } + + if ( nEffect == 2 ) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER4, true ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER4, true ); + } + + if ( nEffect == 3 ) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER3, true ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER3, true ); + + pShaderShadow->EnableTexture( SHADER_SAMPLER4, true ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER4, true ); + + pShaderShadow->EnableTexture( SHADER_SAMPLER5, true ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER5, false ); + + pShaderShadow->EnableTexture( SHADER_SAMPLER6, true ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER6, true ); + } + + pShaderShadow->EnableSRGBWrite( true ); + pShaderShadow->EnableAlphaWrites( true ); + pShaderShadow->EnableAlphaTest( bIsAlphaTested ); + + if ( params[ ALPHATESTREFERENCE ]->GetFloatValue() > 0.0f ) + { + pShaderShadow->AlphaFunc( SHADER_ALPHAFUNC_GEQUAL, params[ ALPHATESTREFERENCE ]->GetFloatValue() ); + } + + DefaultFog(); + + int nFormat = 0; + if ( bHasVertexColor ) + { + nFormat |= VERTEX_COLOR; + } + + if ( bVertexLit ) + { + nFormat |= VERTEX_POSITION | VERTEX_NORMAL | VERTEX_FORMAT_COMPRESSED; + pShaderShadow->VertexShaderVertexFormat( nFormat, 1, 0, 0 ); + } + else + { + nFormat |= VERTEX_POSITION; + pShaderShadow->VertexShaderVertexFormat( nFormat, 2, 0, 0 ); + } + + bool bHalfLambert = IS_FLAG_SET( MATERIAL_VAR_HALFLAMBERT ); + + if ( !g_pHardwareConfig->HasFastVertexTextures() ) + { + DECLARE_STATIC_VERTEX_SHADER( pyro_vision_vs20 ); + SET_STATIC_VERTEX_SHADER_COMBO( EFFECT, params[ EFFECT ]->GetIntValue() ); + SET_STATIC_VERTEX_SHADER_COMBO( VERTEXCOLOR, IS_FLAG_SET( MATERIAL_VAR_VERTEXCOLOR ) ); + SET_STATIC_VERTEX_SHADER_COMBO( VERTEX_LIT, bVertexLit ); + SET_STATIC_VERTEX_SHADER_COMBO( FULLBRIGHT, bFullBright ); + SET_STATIC_VERTEX_SHADER_COMBO( HALFLAMBERT, bHalfLambert ); + SET_STATIC_VERTEX_SHADER_COMBO( BASETEXTURE2, bHasBaseTexture2 ); + SET_STATIC_VERTEX_SHADER_COMBO( STRIPES, bHasStripes ); + SET_STATIC_VERTEX_SHADER_COMBO( STRIPES_USE_NORMAL2, bHasStripesNormal2 ); + SET_STATIC_VERTEX_SHADER_COMBO( USE_STATIC_CONTROL_FLOW, bUseStaticControlFlow ); + SET_STATIC_VERTEX_SHADER( pyro_vision_vs20 ); + + if ( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_STATIC_PIXEL_SHADER( pyro_vision_ps20b ); + SET_STATIC_PIXEL_SHADER_COMBO( EFFECT, params[ EFFECT ]->GetIntValue() ); + SET_STATIC_PIXEL_SHADER_COMBO( VERTEX_LIT, bVertexLit ); + SET_STATIC_PIXEL_SHADER_COMBO( BASETEXTURE2, bHasBaseTexture2 ); + SET_STATIC_PIXEL_SHADER_COMBO( FANCY_BLENDING, bHasBlendModulateTexture ); + SET_STATIC_PIXEL_SHADER_COMBO( SELFILLUM, bSelfIllum ); + SET_STATIC_PIXEL_SHADER_COMBO( COLOR_BAR, bHasColorbar ); + SET_STATIC_PIXEL_SHADER_COMBO( STRIPES, bHasStripes ); + SET_STATIC_PIXEL_SHADER_COMBO( STRIPES_USE_NORMAL2, bHasStripesNormal2 ); + SET_STATIC_PIXEL_SHADER( pyro_vision_ps20b ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( pyro_vision_ps20 ); + SET_STATIC_PIXEL_SHADER_COMBO( EFFECT, params[ EFFECT ]->GetIntValue() ); + SET_STATIC_PIXEL_SHADER_COMBO( VERTEX_LIT, bVertexLit ); + SET_STATIC_PIXEL_SHADER_COMBO( BASETEXTURE2, bHasBaseTexture2 ); + SET_STATIC_PIXEL_SHADER_COMBO( FANCY_BLENDING, bHasBlendModulateTexture ); + SET_STATIC_PIXEL_SHADER_COMBO( SELFILLUM, bSelfIllum ); + SET_STATIC_PIXEL_SHADER_COMBO( COLOR_BAR, bHasColorbar ); + SET_STATIC_PIXEL_SHADER_COMBO( STRIPES, bHasStripes ); + SET_STATIC_PIXEL_SHADER_COMBO( STRIPES_USE_NORMAL2, bHasStripesNormal2 ); + SET_STATIC_PIXEL_SHADER( pyro_vision_ps20 ); + } + } + else + { + DECLARE_STATIC_VERTEX_SHADER( pyro_vision_vs30 ); + SET_STATIC_VERTEX_SHADER_COMBO( EFFECT, params[ EFFECT ]->GetIntValue() ); + SET_STATIC_VERTEX_SHADER_COMBO( VERTEXCOLOR, IS_FLAG_SET( MATERIAL_VAR_VERTEXCOLOR ) ); + SET_STATIC_VERTEX_SHADER_COMBO( VERTEX_LIT, bVertexLit ); + SET_STATIC_VERTEX_SHADER_COMBO( FULLBRIGHT, bFullBright ); + SET_STATIC_VERTEX_SHADER_COMBO( HALFLAMBERT, bHalfLambert ); + SET_STATIC_VERTEX_SHADER_COMBO( BASETEXTURE2, bHasBaseTexture2 ); + SET_STATIC_VERTEX_SHADER_COMBO( STRIPES, bHasStripes ); + SET_STATIC_VERTEX_SHADER_COMBO( STRIPES_USE_NORMAL2, bHasStripesNormal2 ); + SET_STATIC_VERTEX_SHADER( pyro_vision_vs30 ); + + DECLARE_STATIC_PIXEL_SHADER( pyro_vision_ps30 ); + SET_STATIC_PIXEL_SHADER_COMBO( EFFECT, params[ EFFECT ]->GetIntValue() ); + SET_STATIC_PIXEL_SHADER_COMBO( VERTEX_LIT, bVertexLit ); + SET_STATIC_PIXEL_SHADER_COMBO( BASETEXTURE2, bHasBaseTexture2 ); + SET_STATIC_PIXEL_SHADER_COMBO( FANCY_BLENDING, bHasBlendModulateTexture ); + SET_STATIC_PIXEL_SHADER_COMBO( SELFILLUM, bSelfIllum ); + SET_STATIC_PIXEL_SHADER_COMBO( COLOR_BAR, bHasColorbar ); + SET_STATIC_PIXEL_SHADER_COMBO( STRIPES, bHasStripes ); + SET_STATIC_PIXEL_SHADER_COMBO( STRIPES_USE_NORMAL2, bHasStripesNormal2 ); + SET_STATIC_PIXEL_SHADER( pyro_vision_ps30 ); + } + } + + DYNAMIC_STATE + { + CCommandBufferBuilder< CFixedCommandStorageBuffer< 1000 > > DynamicCmdsOut; + DynamicCmdsOut.Call( pContextData->m_pStaticCmds ); + DynamicCmdsOut.Call( pContextData->m_SemiStaticCmdsOut.Base() ); + + pShaderAPI->SetDefaultState(); + + bool bWriteDepthToAlpha; + if( bFullyOpaque ) + { + bWriteDepthToAlpha = pShaderAPI->ShouldWriteDepthToDestAlpha(); + } + else + { + //can't write a special value to dest alpha if we're actually using as-intended alpha + bWriteDepthToAlpha = false; + } + + Vector4D vParms; + + vParms.x = bWriteDepthToAlpha ? 1.0f : 0.0f; + vParms.y = pShaderAPI->CurrentTime(); + vParms.z = 0.0f; + vParms.w = 0.0f; + + DynamicCmdsOut.SetPixelShaderConstant( 12, vParms.Base() ); + + int numBones = pShaderAPI->GetCurrentNumBones(); + LightState_t lightState = { 0, false, false }; + if ( bVertexLit && !bFullBright ) + { + pShaderAPI->GetDX9LightState( &lightState ); + } + + if ( !g_pHardwareConfig->HasFastVertexTextures() ) + { + DECLARE_DYNAMIC_VERTEX_SHADER( pyro_vision_vs20 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, numBones > 0 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( DYNAMIC_LIGHT, lightState.HasDynamicLight() ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( STATIC_LIGHT, lightState.m_bStaticLightVertex ? 1 : 0 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( NUM_LIGHTS, bUseStaticControlFlow ? 0 : lightState.m_nNumLights ); + SET_DYNAMIC_VERTEX_SHADER( pyro_vision_vs20 ); + + if ( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_DYNAMIC_PIXEL_SHADER( pyro_vision_ps20b ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( VISUALIZE_DOF, bVisualizeDoF ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( HEATHAZE, bHasHeatHaze ); + SET_DYNAMIC_PIXEL_SHADER( pyro_vision_ps20b ); + } + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( pyro_vision_ps20 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( VISUALIZE_DOF, bVisualizeDoF ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( HEATHAZE, bHasHeatHaze ); + SET_DYNAMIC_PIXEL_SHADER( pyro_vision_ps20 ); + } + } + else + { + DECLARE_DYNAMIC_VERTEX_SHADER( pyro_vision_vs30 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, numBones > 0 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( DYNAMIC_LIGHT, lightState.HasDynamicLight() ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( STATIC_LIGHT, lightState.m_bStaticLightVertex ? 1 : 0 ); + SET_DYNAMIC_VERTEX_SHADER( pyro_vision_vs30 ); + + DECLARE_DYNAMIC_PIXEL_SHADER( pyro_vision_ps30 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( VISUALIZE_DOF, bVisualizeDoF ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( HEATHAZE, bHasHeatHaze ); + SET_DYNAMIC_PIXEL_SHADER( pyro_vision_ps30 ); + } + + + DynamicCmdsOut.End(); + pShaderAPI->ExecuteCommandBuffer( DynamicCmdsOut.Base() ); + } + Draw(); + } +END_SHADER diff --git a/materialsystem/stdshaders/pyro_vision_ps2x.fxc b/materialsystem/stdshaders/pyro_vision_ps2x.fxc new file mode 100644 index 0000000..ba1718c --- /dev/null +++ b/materialsystem/stdshaders/pyro_vision_ps2x.fxc @@ -0,0 +1,460 @@ +// STATIC: "EFFECT" "0..3" +// STATIC: "VERTEX_LIT" "0..1" +// STATIC: "BASETEXTURE2" "0..1" +// STATIC: "FANCY_BLENDING" "0..1" +// STATIC: "SELFILLUM" "0..1" +// STATIC: "COLOR_BAR" "0..1" +// STATIC: "STRIPES" "0..1" +// STATIC: "STRIPES_USE_NORMAL2" "0..1" + +// DYNAMIC: "PIXELFOGTYPE" "0..1" +// DYNAMIC: "VISUALIZE_DOF" "0..1" +// DYNAMIC: "HEATHAZE" "0..1" + +// SKIP: ( STRIPES == 0 ) && ( STRIPES_USE_NORMAL2 == 1 ) +// SKIP: ( EFFECT != 1 ) && ( COLOR_BAR == 1 ) +// SKIP: ( EFFECT != 2 ) && ( VISUALIZE_DOF == 1 ) +// SKIP: ( EFFECT == 2 || EFFECT == 3 ) && ( STRIPES == 1 || STRIPES_USE_NORMAL2 == 1 || COLOR_BAR == 1 || BASETEXTURE2 == 1 || FANCY_BLENDING == 1 || VERTEX_LIT == 1 || PIXELFOGTYPE == 1 || SELFILLUM == 1 ) +// SKIP: ( EFFECT != 3 ) && ( HEATHAZE == 1 ) + +#include "shader_constant_register_map.h" +#include "common_ps_fxc.h" + +sampler BaseTextureSampler : register( s0 ); + +#if BASETEXTURE2 == 1 + +sampler BaseTexture2Sampler : register( s4 ); + +#if FANCY_BLENDING == 1 + +sampler BlendModulationSampler : register( s3 ); + +#endif + +#endif + +#if STRIPES + +sampler StripeSampler : register( s5 ); + +const float4 g_vPyroParms6 : register( c5 ); + #define g_vStripeColor g_vPyroParms6.rgb + #define g_flStripeLMScale g_vPyroParms6.a + +const float4 g_vPyroParms7 : register( c6 ); + #define g_vStripeNormal1 g_vPyroParms6.xyz + #define g_flUnused6 g_vPyroParms6.w + +#if ( STRIPES_USE_NORMAL2 == 1 ) + +const float4 g_vPyroParms8 : register( c7 ); + #define g_vStripeNormal2 g_vPyroParms7.xyz + #define g_flUnused7 g_vPyroParms7.w + +#endif + +#endif + + + +#if EFFECT == 0 + +sampler LightmapSampler : register( s1 ); +sampler CanvasSampler : register( s2 ); + +const float4 g_vPyroParms1 : register( c0 ); + #define g_vBaseStepRange g_vPyroParms1.xy + #define g_vLightmapStepRange g_vPyroParms1.zw + +const float4 g_vPyroParms2 : register( c1 ); + #define g_vColorModulation g_vPyroParms2.rgb + #define g_flUnused1 g_vPyroParms2.w + +const float4 g_vPyroParms3 : register( c2 ); + #define g_vCanvasStepRange g_vPyroParms3.xy + #define g_vUnused2 g_vPyroParms3.zw + +const float4 g_vPyroParms4 : register( c3 ); + #define g_vCanvasColorStart g_vPyroParms4.rgb + #define g_flUnused3 g_vPyroParms4.w + +const float4 g_vPyroParms5 : register( c4 ); + #define g_vCanvasColorEnd g_vPyroParms5.rgb + #define g_flUnused4 g_vPyroParms5.w + +#elif EFFECT == 1 + +sampler LightmapSampler : register( s1 ); +sampler ColorBarSampler : register( s2 ); + +const float4 g_vPyroParms1 : register( c0 ); + #define g_flGrayPower g_vPyroParms1.x + #define g_flGrayStep g_vPyroParms1.yz + #define g_flLightMapGradients g_vPyroParms1.w + +const float4 g_vPyroParms2 : register( c1 ); + #define g_vColorModulation g_vPyroParms2.rgb + #define g_flDiffuseLighting g_vPyroParms2.w + +const float4 g_vPyroParms3 : register( c2 ); + #define g_flDiffuseBase g_vPyroParms3.x + #define g_vSelfIllumTint g_vPyroParms3.yzw + +#elif EFFECT == 2 + +sampler BlurredFrameSampler : register( s4 ); + +const float4 g_vPyroParms1 : register( c0 ); + #define g_flDoFStartDistance g_vPyroParms1.x + #define g_flDoFPower g_vPyroParms1.y + #define g_flDoFMax g_vPyroParms1.z + #define g_flUnused1 g_vPyroParms1.w + +#elif EFFECT == 3 + +sampler NoiseSampler : register( s3 ); +sampler WarpFrameSampler : register( s4 ); +sampler VignetteSampler : register( s5 ); +sampler VignetteTileSampler : register( s6 ); + +const float4 g_vPyroParms1 : register( c0 ); + #define g_flNoiseScale g_vPyroParms1.x // 0.2 + #define g_flTimeScale g_vPyroParms1.y // 0.020 + #define g_flHeatHazeScale g_vPyroParms1.z // 0.2 + #define g_flUnused1 g_vPyroParms1.w + +#endif + +const HALF3 g_EyePos : register( c10 ); +const HALF4 g_FogParams : register( c11 ); +const float4 g_vGeneralPyroParms1 : register( c12 ); + #define g_fWriteDepthToAlpha g_vGeneralPyroParms1.x + #define g_flTime g_vGeneralPyroParms1.y + #define g_flGeneralUnused2 g_vGeneralPyroParms1.z + #define g_flGeneralUnused3 g_vGeneralPyroParms1.w + + + +struct PS_INPUT +{ +#if EFFECT == 0 || EFFECT == 1 + + float4 vBaseAndSeamlessTexCoord : TEXCOORD0; +#if ( STRIPES == 1 ) + float2 vStripeSeamlessTexCoord : TEXCOORD1; +#endif +#if ( VERTEX_LIT == 0 ) + float2 vLightmapBlendTexCoord : TEXCOORD2; +#endif +#if BASETEXTURE2 == 1 + float3 vBlendFactor : TEXCOORD3; +#endif + float4 worldPos_projPosZ : TEXCOORD4; + float3 vWorldNormal : TEXCOORD5; + float4 vVertexColor : COLOR; + +#else + + float2 vBaseTexCoord : TEXCOORD0; + +#endif + +}; + + +float ToGray( const float3 vColor ) +{ + return dot( vColor, float3( 0.30f, 0.59f, 0.11f ) ); +} + + +void HandleBlending( const float2 vBaseTextureCoord, const float3 vBlendFactor, inout float4 vBaseColor ) +{ +#if BASETEXTURE2 == 1 + + float4 vBaseColor2 = tex2D( BaseTexture2Sampler, vBaseTextureCoord ); + float flBlendFactor = vBlendFactor.z; + +#if FANCY_BLENDING == 1 + + float4 modt = tex2D( BlendModulationSampler, vBlendFactor.xy ); + float minb = saturate( modt.g - modt.r ); + float maxb = saturate( modt.g + modt.r ); + flBlendFactor = smoothstep( minb, maxb, flBlendFactor ); + +#endif + + vBaseColor = lerp( vBaseColor, vBaseColor2, flBlendFactor ); + +#endif +} + + +#if STRIPES + +void CalculateStripe( const float2 vStripeSeamlessTexCoord, const float3 vWorldNormal, const float flLMScale, inout float3 vResult ) +{ + float4 vStripeColor = tex2D( StripeSampler, vStripeSeamlessTexCoord ); + + vStripeColor.rgb *= g_vStripeColor; + vStripeColor.rgb *= lerp( float3( 1.0, 1.0, 1.0 ), flLMScale, g_flStripeLMScale ); + +#if VERTEX_LIT == 1 && 0 + + float flAngle = saturate( dot( vWorldNormal, g_vStripeNormal1 ) ); + vResult.rgb = ( vWorldNormal * 0.5 ) + 0.5; + return; + + flAngle = 1 - flAngle; + vStripeColor.a *= flAngle; + +#endif + + vResult = lerp( vResult, vStripeColor.rgb, vStripeColor.a ); +} + +#endif + + +#if EFFECT == -1 + +float4 main( PS_INPUT i ) : COLOR +{ + float4 vBaseColor = tex2D( BaseTextureSampler, i.vBaseAndSeamlessTexCoord.xy ); + +#if BASETEXTURE2 == 1 + HandleBlending( i.vBaseAndSeamlessTexCoord.xy, i.vBlendFactor, vBaseColor ); +#endif + +// return vBaseColor; + + vBaseColor *= i.vVertexColor; + +#if VERTEX_LIT == 0 + float4 vLightmapSample = tex2D( LightmapSampler, i.vLightmapBlendTexCoord.xy ) * float4( g_vColorModulation, 1.0 ); +#endif + float4 vCanvas = tex2D( CanvasSampler, i.vBaseAndSeamlessTexCoord.zw ); + + float flFogFactor = CalcPixelFogFactor( 0, g_FogParams, g_EyePos.z, i.worldPos_projPosZ.z, i.worldPos_projPosZ.w ); + +// return saturate( min( g_FogParams.z, (i.worldPos_projPosZ.w * g_FogParams.w) - g_FogParams.x ) ); + +// return float4( g_FogParams.x, g_FogParams.z, g_FogParams.w, 1 ); + +// return g_LinearFogColor; +// flFogFactor = 1; + + float4 vResult; + +#if 0 + vResult = vBaseColor * vLightmapSample; +#else + float flBaseGray = dot( vBaseColor.rgb, float3( 0.30f, 0.59f, 0.11f ) ); +#if VERTEX_LIT == 0 + float flLightmapGray = dot( vLightmapSample.rgb, float3( 0.30f, 0.59f, 0.11f ) ); +#endif + + flBaseGray = smoothstep( g_vBaseStepRange.x, g_vBaseStepRange.y, flBaseGray ); + vResult = float4( flBaseGray.rrr, vBaseColor.a ); + +#if VERTEX_LIT == 0 +// flLightmapGray = pow( flLightmapGray, 0.01 ); + flLightmapGray = smoothstep( g_vLightmapStepRange.x, g_vLightmapStepRange.y, flLightmapGray ); + vResult *= flLightmapGray; +#endif + + float flCanvasGray = dot( vCanvas.rgb, float3( 0.30f, 0.59f, 0.11f ) ); + flCanvasGray = smoothstep( g_vCanvasStepRange.x, g_vCanvasStepRange.y, flCanvasGray ); + + vCanvas.rgb = lerp( g_vCanvasColorStart, g_vCanvasColorEnd, flCanvasGray ); + + vResult *= vCanvas; + +#endif + + return FinalOutput( vResult, flFogFactor, 0, TONEMAP_SCALE_LINEAR, true, i.worldPos_projPosZ.w ); +} + +#elif EFFECT == 0 + +float4 main( PS_INPUT i ) : COLOR +{ + float4 vBaseColor = tex2D( BaseTextureSampler, i.vBaseAndSeamlessTexCoord.xy ); + +#if BASETEXTURE2 == 1 + HandleBlending( i.vBaseAndSeamlessTexCoord.xy, i.vBlendFactor, vBaseColor ); +#endif + + vBaseColor.rgb *= i.vVertexColor.rgb; + vBaseColor.rgb = ceil( vBaseColor.rgb * 16.0 ) / 16.0; + +#if VERTEX_LIT == 0 + float4 vLightmapSample = tex2D( LightmapSampler, i.vLightmapBlendTexCoord.xy ) * float4( g_vColorModulation, 1.0 ); +#endif + float4 vCanvas = tex2D( CanvasSampler, i.vBaseAndSeamlessTexCoord.zw ); + + float flFogFactor = CalcPixelFogFactor( 0, g_FogParams, g_EyePos.z, i.worldPos_projPosZ.z, i.worldPos_projPosZ.w ); + + float4 vResult; + + float flBaseGray = dot( vBaseColor.rgb, float3( 0.30f, 0.59f, 0.11f ) ); +#if VERTEX_LIT == 0 + float flLightmapGray = dot( vLightmapSample.rgb, float3( 0.30f, 0.59f, 0.11f ) ); +#endif + +#ifdef GRAY_DIFFUSE + flBaseGray = smoothstep( g_vBaseStepRange.x, g_vBaseStepRange.y, flBaseGray ); + vResult = float4( flBaseGray.rrr, vBaseColor.a ); +#else + vResult.rgb = smoothstep( g_vBaseStepRange.xxx, g_vBaseStepRange.yyy, vBaseColor.rgb ); + vResult.a = vBaseColor.a; +#endif + + +#if VERTEX_LIT == 0 + +#ifdef GRAY_LM + + flLightmapGray = pow( flLightmapGray, 0.01 ); + flLightmapGray = smoothstep( g_vLightmapStepRange.x, g_vLightmapStepRange.y, flLightmapGray ); + vResult.rgb *= flLightmapGray; + +#else + + vLightmapSample.rgb = smoothstep( g_vLightmapStepRange.xxx, g_vLightmapStepRange.yyy, vLightmapSample.rgb ); +// vLightmapSample.rgb = lerp( float3( 0.0, 0.0, 0.0 ), float3( 3.1, 1.1, 5.1 ), vLightmapSample.rgb ); + vResult.rgb *= vLightmapSample.rgb; + +#endif + +#endif + + float flCanvasGray = dot( vCanvas.rgb, float3( 0.30f, 0.59f, 0.11f ) ); + flCanvasGray = smoothstep( g_vCanvasStepRange.x, g_vCanvasStepRange.y, flCanvasGray ); + + vCanvas.rgb = lerp( g_vCanvasColorStart, g_vCanvasColorEnd, flCanvasGray ); +// vCanvas.rgb = pow( vCanvas.rgb, 0.6 ); + + vResult *= vCanvas; + + return FinalOutput( vResult, flFogFactor, 0, TONEMAP_SCALE_LINEAR, true, i.worldPos_projPosZ.w ); +} + +#elif EFFECT == 1 + +#define GRAY_DIFFUSE 1 +#define GRAY_LM 1 + + +float4 main( PS_INPUT i ) : COLOR +{ + float4 vResult; + + float4 vBaseColor = tex2D( BaseTextureSampler, i.vBaseAndSeamlessTexCoord.xy ); + +#if BASETEXTURE2 == 1 + HandleBlending( i.vBaseAndSeamlessTexCoord.xy, i.vBlendFactor, vBaseColor ); +#endif + + float flFogFactor = CalcPixelFogFactor( 0, g_FogParams, g_EyePos.z, i.worldPos_projPosZ.z, i.worldPos_projPosZ.w ); + + vBaseColor.rgb = lerp( vBaseColor.rgb, 1.0, g_flDiffuseBase ); + vResult = vBaseColor * i.vVertexColor; + +#if VERTEX_LIT == 0 + float4 vLightmapSample = tex2D( LightmapSampler, i.vLightmapBlendTexCoord.xy ) * float4( g_vColorModulation, 1.0 ); + vResult.rgb = lerp( vResult.rgb, 0.5, g_flDiffuseLighting ); + vResult.rgb *= vLightmapSample.rgb; +#endif + +#if SELFILLUM + + float3 vSelfIllumComponent = g_vSelfIllumTint * vBaseColor.rgb; + vResult.rgb = lerp( vResult.rgb, vSelfIllumComponent, vBaseColor.a ); + +#endif + + float flGray = dot( vResult.rgb, float3( 0.30f, 0.59f, 0.11f ) ); + + flGray = pow( flGray, g_flGrayPower ); + flGray = smoothstep( g_flGrayStep.x, g_flGrayStep.y, flGray ); + + flGray = ceil( flGray * g_flLightMapGradients ) / g_flLightMapGradients; + +#if COLOR_BAR == 1 + + float4 vCanvas = tex1D( ColorBarSampler, flGray ); + vResult.rgb = vCanvas.rgb * flGray; + +#endif + +#if STRIPES + + CalculateStripe( i.vStripeSeamlessTexCoord, i.vWorldNormal, flGray, vResult.rgb ); + +#endif + + return FinalOutput( vResult, flFogFactor, 0, TONEMAP_SCALE_LINEAR, false, i.worldPos_projPosZ.w ); +} + +#elif EFFECT == 2 + +float4 main( PS_INPUT i ) : COLOR +{ + float flDepth = tex2D( BaseTextureSampler, i.vBaseTexCoord.xy ).r; + float4 vBaseColor = tex2D( BlurredFrameSampler, i.vBaseTexCoord.xy ); + + + float flAmount; + flAmount = flDepth; + + flAmount = saturate( flDepth - g_flDoFStartDistance ); + flAmount = pow( flAmount, g_flDoFPower ); + flAmount *= g_flDoFMax; + +#if VISUALIZE_DOF == 1 + + return float4( flAmount.rrr, 1 ); + +#else + + return float4( vBaseColor.rgb, flAmount ); + +#endif +} + +#elif EFFECT == 3 + +float4 main( PS_INPUT i ) : COLOR +{ + float flVignetteAmount = tex2D( VignetteSampler, i.vBaseTexCoord.xy ); + float4 vVignetteTile = tex2D( VignetteTileSampler, i.vBaseTexCoord.xy * 50.0f ); + +#if HEATHAZE == 1 + float2 vOffset = tex2D( WarpFrameSampler, i.vBaseTexCoord.xy ).aa; + float flDynamicOffset = tex2D( NoiseSampler, float2( i.vBaseTexCoord.x, ( i.vBaseTexCoord.y * g_flNoiseScale ) + ( g_flTime * g_flTimeScale ) ) ).r; + +// return float4( vOffset.yyy, 1 ); +// return float4( flDynamicOffset.xxx, 1.0 ); + +// vOffset = ( vOffset - 0.5 ); + vOffset = smoothstep( 0.1, 1.0, vOffset ); + vOffset *= flDynamicOffset * g_flHeatHazeScale; + float4 vOriginal = tex2D( BaseTextureSampler, i.vBaseTexCoord.xy + float2( 0, vOffset.y ) ); + +#else + + float4 vOriginal = tex2D( BaseTextureSampler, i.vBaseTexCoord.xy ); + +#endif + + float flDelta = flVignetteAmount.x - vVignetteTile.a; + + float flFinal = flDelta <= 0.0f ? 0.0f : lerp( flVignetteAmount.x, 1.0, flDelta / flVignetteAmount.x ); + vOriginal.rgb = lerp( vOriginal.rgb, vVignetteTile.rgb, flFinal * flVignetteAmount.x ); + + return float4( vOriginal ); +} + +#endif diff --git a/materialsystem/stdshaders/pyro_vision_vs20.fxc b/materialsystem/stdshaders/pyro_vision_vs20.fxc new file mode 100644 index 0000000..bcd2f84 --- /dev/null +++ b/materialsystem/stdshaders/pyro_vision_vs20.fxc @@ -0,0 +1,185 @@ +// STATIC: "EFFECT" "0..3" +// STATIC: "VERTEXCOLOR" "0..1" +// STATIC: "HALFLAMBERT" "0..1" +// STATIC: "VERTEX_LIT" "0..1" +// STATIC: "FULLBRIGHT" "0..1" +// STATIC: "USE_STATIC_CONTROL_FLOW" "0..1" [vs20] +// STATIC: "BASETEXTURE2" "0..1" +// STATIC: "STRIPES" "0..1" +// STATIC: "STRIPES_USE_NORMAL2" "0..1" + +// DYNAMIC: "COMPRESSED_VERTS" "0..1" +// DYNAMIC: "SKINNING" "0..1" +// DYNAMIC: "DYNAMIC_LIGHT" "0..1" +// DYNAMIC: "STATIC_LIGHT" "0..1" +// DYNAMIC: "NUM_LIGHTS" "0..2" [vs20] + +// SKIP: ( STRIPES == 0 ) && ( STRIPES_USE_NORMAL2 == 1 ) +// SKIP: ( EFFECT == 2 || EFFECT == 3 ) && ( VERTEXCOLOR == 1 || HALFLAMBERT == 1 || VERTEX_LIT == 1 || FULLBRIGHT == 1 || USE_STATIC_CONTROL_FLOW == 1 || BASETEXTURE2 == 1 || STRIPES == 1 || STRIPES_USE_NORMAL2 == 1 ) +// SKIP: ( EFFECT == 2 || EFFECT == 3 ) && ( SKINNING == 1 || DYNAMIC_LIGHT == 1 || STATIC_LIGHT == 1 || NUM_LIGHTS != 0 ) +// SKIP: ( FULLBRIGHT == 1 ) && ( VERTEX_LIT == 0 || DYNAMIC_LIGHT == 1 || STATIC_LIGHT == 1 || NUM_LIGHTS != 0 ) + + +#include "common_vs_fxc.h" + + +static const bool g_bSkinning = SKINNING ? true : false; +static const bool g_bHalfLambert = HALFLAMBERT ? true : false; + + +const float4 g_vPyroParms1 : register( SHADER_SPECIFIC_CONST_0 ); + #define g_vStripeScale g_vPyroParms1.xyz + #define g_flUnused1 g_vPyroParms1.w + +#if EFFECT == 0 || EFFECT == 1 + +const float4 g_vPyroParms2 : register( SHADER_SPECIFIC_CONST_1 ); + #define g_vCanvasScale g_vPyroParms2.xyz + #define g_flUnused2 g_vPyroParms2.w + +#endif + +const float4 cBlendMaskTexCoordTransform[ 2 ] : register( SHADER_SPECIFIC_CONST_10 ); // not contiguous with the rest! + +struct VS_INPUT +{ + float4 vPos : POSITION; + float4 vBoneWeights : BLENDWEIGHT; + float4 vBoneIndices : BLENDINDICES; +#if ( VERTEX_LIT == 1 ) + float4 vNormal : NORMAL; +#endif + float2 vBaseTexCoord : TEXCOORD0; + float2 vLightmapTexCoord : TEXCOORD1; + float2 vLightmapTexCoordOffset : TEXCOORD2; + float3 vTangentS : TANGENT; + float3 vTangentT : BINORMAL; + float4 vColor : COLOR0; + float3 vSpecular : COLOR1; +}; + + +struct VS_OUTPUT +{ + float4 vProjPos : POSITION; + +#if EFFECT == 0 || EFFECT == 1 + + float4 vBaseAndSeamlessTexCoord : TEXCOORD0; +#if ( STRIPES == 1 ) + float2 vStripeSeamlessTexCoord : TEXCOORD1; +#endif +#if ( VERTEX_LIT == 0 ) + float2 vLightmapBlendTexCoord : TEXCOORD2; +#endif +#if BASETEXTURE2 == 1 + float3 vBlendFactor : TEXCOORD3; +#endif + float4 worldPos_projPosZ : TEXCOORD4; + float3 vWorldNormal : TEXCOORD5; + float4 vVertexColor : COLOR; + +#else + + float2 vBaseTexCoord : TEXCOORD0; + +#endif + +}; + + +VS_OUTPUT main( const VS_INPUT v ) +{ + VS_OUTPUT o; + +#if EFFECT == 0 || EFFECT == 1 + + float4 vObjPosition = v.vPos; + +#if ( VERTEX_LIT == 1 ) + float3 vObjNormal; + DecompressVertex_Normal( v.vNormal, vObjNormal ); +#else + float3 vObjNormal = float3( 0.0, 0.0, 1.0 ); +#endif + + float3 vWorldNormal, vWorldPos; + SkinPositionAndNormal( g_bSkinning, vObjPosition, vObjNormal, v.vBoneWeights, v.vBoneIndices, vWorldPos, vWorldNormal ); + + float4 vProjPos = mul( float4( vWorldPos, 1 ), cViewProj ); + o.vProjPos = vProjPos; + vProjPos.z = dot( float4( vWorldPos, 1 ), cViewProjZ ); + + o.worldPos_projPosZ = float4( vWorldPos, vProjPos.z ); + +#if 0 + if ( !g_bSkinning ) + { + vWorldNormal = vObjNormal; + } +#endif + vWorldNormal = normalize( vWorldNormal ); + o.vWorldNormal = vWorldNormal; + + o.vBaseAndSeamlessTexCoord.xy = v.vBaseTexCoord; + float flZFactor = vWorldPos.z * g_vCanvasScale.z; + o.vBaseAndSeamlessTexCoord.zw = float2( vWorldPos.x + flZFactor, vWorldPos.y - flZFactor ) * g_vCanvasScale.xy; + +#if ( STRIPES == 1 ) + + float3 vWorldStripeCoord = vWorldPos * g_vStripeScale; + o.vStripeSeamlessTexCoord.xy = vWorldStripeCoord.yz + vWorldStripeCoord.xz + vWorldStripeCoord.xy; + +#endif + + +#if VERTEX_LIT == 0 + + o.vLightmapBlendTexCoord.xy = v.vLightmapTexCoord; + +#endif + +#if BASETEXTURE2 == 1 + + o.vBlendFactor.x = dot( v.vBaseTexCoord, cBlendMaskTexCoordTransform[ 0 ] ) + cBlendMaskTexCoordTransform[ 0 ].w; + o.vBlendFactor.y = dot( v.vBaseTexCoord, cBlendMaskTexCoordTransform[ 1 ] ) + cBlendMaskTexCoordTransform[ 1 ].w; + o.vBlendFactor.z = v.vColor.a; + +#endif + +#if VERTEXCOLOR == 1 + + o.vVertexColor = v.vColor; + +#elif VERTEX_LIT == 1 && FULLBRIGHT == 0 + + bool bDynamicLight = DYNAMIC_LIGHT ? true : false; + bool bStaticLight = STATIC_LIGHT ? true : false; + + #if ( ( USE_STATIC_CONTROL_FLOW ) || defined ( SHADER_MODEL_VS_3_0 ) ) + { + o.vVertexColor.xyz = DoLighting( vWorldPos, vWorldNormal, v.vSpecular, bStaticLight, bDynamicLight, g_bHalfLambert ); + } + #else + { + o.vVertexColor.xyz = DoLightingUnrolled( vWorldPos, vWorldNormal, v.vSpecular, bStaticLight, bDynamicLight, g_bHalfLambert, NUM_LIGHTS ); + } + #endif + + o.vVertexColor.a = 1.0f; + +#else + + o.vVertexColor = 1.0f; + +#endif + +#else + + o.vProjPos = v.vPos; + o.vBaseTexCoord = v.vBaseTexCoord; + +#endif + + return o; +} diff --git a/materialsystem/stdshaders/refract.cpp b/materialsystem/stdshaders/refract.cpp new file mode 100644 index 0000000..852e93a --- /dev/null +++ b/materialsystem/stdshaders/refract.cpp @@ -0,0 +1,111 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//=============================================================================// + +#include "BaseVSShader.h" +#include "convar.h" +#include "refract_dx9_helper.h" + +DEFINE_FALLBACK_SHADER( Refract, Refract_DX90 ) + +BEGIN_VS_SHADER( Refract_DX90, "Help for Refract" ) + + BEGIN_SHADER_PARAMS + SHADER_PARAM_OVERRIDE( COLOR, SHADER_PARAM_TYPE_COLOR, "{255 255 255}", "unused", SHADER_PARAM_NOT_EDITABLE ) + SHADER_PARAM_OVERRIDE( ALPHA, SHADER_PARAM_TYPE_FLOAT, "1.0", "unused", SHADER_PARAM_NOT_EDITABLE ) + SHADER_PARAM( REFRACTAMOUNT, SHADER_PARAM_TYPE_FLOAT, "2", "" ) + SHADER_PARAM( REFRACTTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "refraction tint" ) + SHADER_PARAM( NORMALMAP, SHADER_PARAM_TYPE_TEXTURE, "models/shadertest/shader1_normal", "normal map" ) + SHADER_PARAM( NORMALMAP2, SHADER_PARAM_TYPE_TEXTURE, "models/shadertest/shader1_normal", "normal map" ) + SHADER_PARAM( BUMPFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $normalmap" ) + SHADER_PARAM( BUMPFRAME2, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $normalmap" ) + SHADER_PARAM( BUMPTRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$normalmap texcoord transform" ) + SHADER_PARAM( BUMPTRANSFORM2, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$normalmap texcoord transform" ) + SHADER_PARAM( TIME, SHADER_PARAM_TYPE_FLOAT, "0.0f", "" ) + SHADER_PARAM( BLURAMOUNT, SHADER_PARAM_TYPE_INTEGER, "1", "0, 1, or 2 for how much blur you want" ) + SHADER_PARAM( FADEOUTONSILHOUETTE, SHADER_PARAM_TYPE_BOOL, "1", "0 for no fade out on silhouette, 1 for fade out on sillhouette" ) + SHADER_PARAM( ENVMAP, SHADER_PARAM_TYPE_TEXTURE, "shadertest/shadertest_env", "envmap" ) + SHADER_PARAM( ENVMAPFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "envmap frame number" ) + SHADER_PARAM( ENVMAPTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "envmap tint" ) + SHADER_PARAM( ENVMAPCONTRAST, SHADER_PARAM_TYPE_FLOAT, "0.0", "contrast 0 == normal 1 == color*color" ) + SHADER_PARAM( ENVMAPSATURATION, SHADER_PARAM_TYPE_FLOAT, "1.0", "saturation 0 == greyscale 1 == normal" ) + SHADER_PARAM( REFRACTTINTTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "models/shadertest/shield", "" ) + SHADER_PARAM( REFRACTTINTTEXTUREFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "" ) + SHADER_PARAM( FRESNELREFLECTION, SHADER_PARAM_TYPE_FLOAT, "1.0", "1.0 == mirror, 0.0 == water" ) + SHADER_PARAM( NOWRITEZ, SHADER_PARAM_TYPE_INTEGER, "0", "0 == write z, 1 = no write z" ) + SHADER_PARAM( MASKED, SHADER_PARAM_TYPE_BOOL, "0", "mask using dest alpha" ) + SHADER_PARAM( VERTEXCOLORMODULATE, SHADER_PARAM_TYPE_BOOL, "0","Use the vertex color to effect refract color. alpha will adjust refract amount" ) + SHADER_PARAM( FORCEALPHAWRITE, SHADER_PARAM_TYPE_BOOL, "0","Force the material to write alpha to the dest buffer" ) + END_SHADER_PARAMS +// FIXME: doesn't support Fresnel! + + void SetupVars( Refract_DX9_Vars_t& info ) + { + info.m_nBaseTexture = BASETEXTURE; + info.m_nFrame = FRAME; + info.m_nRefractAmount = REFRACTAMOUNT; + info.m_nRefractTint = REFRACTTINT; + info.m_nNormalMap = NORMALMAP; + info.m_nNormalMap2 = NORMALMAP2; + info.m_nBumpFrame = BUMPFRAME; + info.m_nBumpFrame2 = BUMPFRAME2; + info.m_nBumpTransform = BUMPTRANSFORM; + info.m_nBumpTransform2 = BUMPTRANSFORM2; + info.m_nBlurAmount = BLURAMOUNT; + info.m_nFadeOutOnSilhouette = FADEOUTONSILHOUETTE; + info.m_nEnvmap = ENVMAP; + info.m_nEnvmapFrame = ENVMAPFRAME; + info.m_nEnvmapTint = ENVMAPTINT; + info.m_nEnvmapContrast = ENVMAPCONTRAST; + info.m_nEnvmapSaturation = ENVMAPSATURATION; + info.m_nRefractTintTexture = REFRACTTINTTEXTURE; + info.m_nRefractTintTextureFrame = REFRACTTINTTEXTUREFRAME; + info.m_nFresnelReflection = FRESNELREFLECTION; + info.m_nNoWriteZ = NOWRITEZ; + info.m_nMasked = MASKED; + info.m_nVertexColorModulate = VERTEXCOLORMODULATE; + info.m_nForceAlphaWrite = FORCEALPHAWRITE; + } + + SHADER_INIT_PARAMS() + { + Refract_DX9_Vars_t info; + SetupVars( info ); + InitParamsRefract_DX9( this, params, pMaterialName, info ); + } + + SHADER_FALLBACK + { + if( g_pHardwareConfig->GetDXSupportLevel() < 82 ) + return "Refract_DX80"; + + return 0; + } + + SHADER_INIT + { + Refract_DX9_Vars_t info; + SetupVars( info ); + InitRefract_DX9( this, params, info ); + } + + SHADER_DRAW + { + Refract_DX9_Vars_t info; + SetupVars( info ); + + // If ( snapshotting ) or ( we need to draw this frame ) + bool bHasFlashlight = this->UsingFlashlight( params ); + if ( ( pShaderShadow != NULL ) || ( bHasFlashlight == false ) ) + { + DrawRefract_DX9( this, params, pShaderAPI, pShaderShadow, info, vertexCompression ); + } + else + { + Draw( false ); + } + } +END_SHADER diff --git a/materialsystem/stdshaders/refract_dx60.cpp b/materialsystem/stdshaders/refract_dx60.cpp new file mode 100644 index 0000000..2ca7a83 --- /dev/null +++ b/materialsystem/stdshaders/refract_dx60.cpp @@ -0,0 +1,16 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//=============================================================================// + +#include "shaderlib/cshader.h" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +// FIXME: This is a placeholder. . need to do something for real here. +DEFINE_FALLBACK_SHADER( Refract, Refract_DX60 ) +DEFINE_FALLBACK_SHADER( Refract_DX60, UnlitGeneric ) + + diff --git a/materialsystem/stdshaders/refract_dx80.cpp b/materialsystem/stdshaders/refract_dx80.cpp new file mode 100644 index 0000000..b6e6e5a --- /dev/null +++ b/materialsystem/stdshaders/refract_dx80.cpp @@ -0,0 +1,317 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//=============================================================================// + + +#include "BaseVSShader.h" + +#include "refract_model_vs11.inc" +#include "refract_world_vs11.inc" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +#define MAXBLUR 1 + +DEFINE_FALLBACK_SHADER( Refract, Refract_DX80 ) + +BEGIN_VS_SHADER( Refract_DX80, + "Help for Refract_DX80" ) + + BEGIN_SHADER_PARAMS + SHADER_PARAM_OVERRIDE( COLOR, SHADER_PARAM_TYPE_COLOR, "{255 255 255}", "unused", SHADER_PARAM_NOT_EDITABLE ) + SHADER_PARAM_OVERRIDE( ALPHA, SHADER_PARAM_TYPE_FLOAT, "1.0", "unused", SHADER_PARAM_NOT_EDITABLE ) + SHADER_PARAM( REFRACTAMOUNT, SHADER_PARAM_TYPE_FLOAT, "2", "" ) + SHADER_PARAM( REFRACTTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "refraction tint" ) + SHADER_PARAM( DUDVMAP, SHADER_PARAM_TYPE_TEXTURE, "models/shadertest/shader1_dudv", "dudv bump map" ) + SHADER_PARAM( NORMALMAP, SHADER_PARAM_TYPE_TEXTURE, "models/shadertest/shader1_normal", "normal map" ) + SHADER_PARAM( BUMPFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $bumpmap" ) + SHADER_PARAM( DUDVFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $dudvmap" ) + SHADER_PARAM( BUMPTRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$bumpmap texcoord transform" ) + SHADER_PARAM( TIME, SHADER_PARAM_TYPE_FLOAT, "0.0f", "" ) + SHADER_PARAM( BLURAMOUNT, SHADER_PARAM_TYPE_INTEGER, "1", "0, 1, or 2 for how much blur you want" ) + SHADER_PARAM( FADEOUTONSILHOUETTE, SHADER_PARAM_TYPE_BOOL, "1", "0 for no fade out on silhouette, 1 for fade out on sillhouette" ) + SHADER_PARAM( ENVMAP, SHADER_PARAM_TYPE_TEXTURE, "shadertest/shadertest_env", "envmap" ) + SHADER_PARAM( ENVMAPFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "envmap frame number" ) + SHADER_PARAM( ENVMAPTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "envmap tint" ) + SHADER_PARAM( ENVMAPCONTRAST, SHADER_PARAM_TYPE_FLOAT, "0.0", "contrast 0 == normal 1 == color*color" ) + SHADER_PARAM( ENVMAPSATURATION, SHADER_PARAM_TYPE_FLOAT, "1.0", "saturation 0 == greyscale 1 == normal" ) + SHADER_PARAM( REFRACTTINTTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "models/shadertest/shield", "" ) + SHADER_PARAM( REFRACTTINTTEXTUREFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "" ) + SHADER_PARAM( FRESNELREFLECTION, SHADER_PARAM_TYPE_FLOAT, "1.0", "1.0 == mirror, 0.0 == water" ) + SHADER_PARAM( FALLBACK, SHADER_PARAM_TYPE_STRING, "", "Name of the fallback shader" ) + SHADER_PARAM( FORCEREFRACT, SHADER_PARAM_TYPE_BOOL, "0", "Forces refraction on boards that have poor performance" ) + SHADER_PARAM( NOWRITEZ, SHADER_PARAM_TYPE_INTEGER, "0", "0 == write z, 1 = no write z" ) + SHADER_PARAM( MASKED, SHADER_PARAM_TYPE_BOOL, "0", "mask using dest alpha" ) + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + SET_FLAGS2( MATERIAL_VAR2_SUPPORTS_HW_SKINNING ); + SET_FLAGS2( MATERIAL_VAR2_NEEDS_TANGENT_SPACES ); + SET_FLAGS( MATERIAL_VAR_TRANSLUCENT ); + if( !params[ENVMAPTINT]->IsDefined() ) + { + params[ENVMAPTINT]->SetVecValue( 1.0f, 1.0f, 1.0f ); + } + if( !params[ENVMAPCONTRAST]->IsDefined() ) + { + params[ENVMAPCONTRAST]->SetFloatValue( 0.0f ); + } + if( !params[ENVMAPSATURATION]->IsDefined() ) + { + params[ENVMAPSATURATION]->SetFloatValue( 1.0f ); + } + if( !params[ENVMAPFRAME]->IsDefined() ) + { + params[ENVMAPFRAME]->SetIntValue( 0 ); + } + if( !params[FRESNELREFLECTION]->IsDefined() ) + { + params[FRESNELREFLECTION]->SetFloatValue( 1.0f ); + } + if( !params[MASKED]->IsDefined() ) + { + params[MASKED]->SetIntValue( 0 ); + } + if( !params[BLURAMOUNT]->IsDefined() ) + { + params[BLURAMOUNT]->SetIntValue( 0 ); + } + if( !params[FADEOUTONSILHOUETTE]->IsDefined() ) + { + params[FADEOUTONSILHOUETTE]->SetIntValue( 0 ); + } + SET_FLAGS2( MATERIAL_VAR2_NEEDS_POWER_OF_TWO_FRAME_BUFFER_TEXTURE ); + } + + SHADER_FALLBACK + { + if ( IsPC() ) + { + const char *pFallback = (params && params[FALLBACK]->IsDefined()) ? params[FALLBACK]->GetStringValue() : ""; + if (!pFallback[0]) + { + pFallback = "Refract_DX60"; + } + + if( g_pHardwareConfig->GetDXSupportLevel() < 80 || !g_pHardwareConfig->HasProjectedBumpEnv() ) + return pFallback; + + if ( g_pHardwareConfig->PreferReducedFillrate() && (params && (params[FORCEREFRACT]->GetIntValue() == 0)) ) + return pFallback; + } + + return 0; + } + + SHADER_INIT + { + if (params[BASETEXTURE]->IsDefined() ) + { + LoadTexture( BASETEXTURE ); + } + if (params[DUDVMAP]->IsDefined() ) + { + LoadTexture( DUDVMAP ); + } + if (params[NORMALMAP]->IsDefined() ) + { + LoadBumpMap( NORMALMAP ); + } + if( params[ENVMAP]->IsDefined() ) + { + LoadCubeMap( ENVMAP ); + } + if( params[REFRACTTINTTEXTURE]->IsDefined() ) + { + LoadTexture( REFRACTTINTTEXTURE ); + } + } + + inline int ComputePixelShaderIndex( bool bRefractTintTexture, bool bNormalMapAlpha ) + { + // "REFRACTTINTTEXTURE" "0..1" + // "NORMALMAPALPHA" "0..1" + int pshIndex = 0; + if( bRefractTintTexture ) pshIndex |= 0x1; + if( bNormalMapAlpha ) pshIndex |= 0x2; + return pshIndex; + } + + SHADER_DRAW + { + bool bIsModel = IS_FLAG_SET( MATERIAL_VAR_MODEL ); + bool bHasEnvmap = params[ENVMAP]->IsTexture(); + int blurAmount = params[BLURAMOUNT]->GetIntValue(); + bool bRefractTintTexture = params[REFRACTTINTTEXTURE]->IsTexture(); + if( blurAmount < 0 ) + { + blurAmount = 0; + } + else if( blurAmount > MAXBLUR ) + { + blurAmount = MAXBLUR; + } + bool bMasked = (params[MASKED]->GetIntValue() != 0); + + SHADOW_STATE + { + if ( params[NOWRITEZ]->GetIntValue() != 0 ) + { + pShaderShadow->EnableDepthWrites( false ); + } + + // Alpha test: FIXME: shouldn't this be handled in Shader_t::SetInitialShadowState + pShaderShadow->EnableAlphaTest( IS_FLAG_SET(MATERIAL_VAR_ALPHATEST) ); + + // If envmap is not specified, the alpha channel is the translucency + // (If envmap *is* specified, alpha channel is the reflection amount) + bool bNormalMapAlpha = false; + if ( params[NORMALMAP]->IsTexture() && !bHasEnvmap ) + { + SetDefaultBlendingShadowState( NORMALMAP, false ); + if ( !bMasked && TextureIsTranslucent( NORMALMAP, false ) ) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER3, true ); + bNormalMapAlpha = true; + } + } + + // dudv map + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + + // renderable texture for refraction + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + + if( bRefractTintTexture ) + { + // refract tint texture + pShaderShadow->EnableTexture( SHADER_SAMPLER2, true ); + } + + int fmt = VERTEX_POSITION | VERTEX_NORMAL; + int userDataSize = 0; + if( bIsModel ) + { + userDataSize = 4; + } + else + { + fmt |= VERTEX_TANGENT_S | VERTEX_TANGENT_T; + } + pShaderShadow->VertexShaderVertexFormat( fmt, 1, 0, userDataSize ); + + if( bIsModel ) + { + refract_model_vs11_Static_Index vshIndex; + pShaderShadow->SetVertexShader( "Refract_model_vs11", vshIndex.GetIndex() ); + } + else + { + refract_world_vs11_Static_Index vshIndex; + pShaderShadow->SetVertexShader( "Refract_world_vs11", vshIndex.GetIndex() ); + } + + int pshIndex; + pshIndex = ComputePixelShaderIndex( bRefractTintTexture, bNormalMapAlpha ); + pShaderShadow->SetPixelShader( "Refract_ps11", pshIndex ); + + if( bMasked ) + { + EnableAlphaBlending( SHADER_BLEND_ONE_MINUS_SRC_ALPHA, SHADER_BLEND_SRC_ALPHA ); + } + DefaultFog(); + } + DYNAMIC_STATE + { + pShaderAPI->SetDefaultState(); + + // The dx9.0c runtime says that we shouldn't have a non-zero dimension when using vertex and pixel shaders. + pShaderAPI->SetTextureTransformDimension( SHADER_TEXTURE_STAGE1, 0, true ); + + if ( params[DUDVFRAME]->GetIntValue() == 0 ) + { + BindTexture( SHADER_SAMPLER0, DUDVMAP, BUMPFRAME ); + } + else + { + BindTexture( SHADER_SAMPLER0, DUDVMAP, DUDVFRAME ); + } + + if ( params[BASETEXTURE]->IsTexture() ) + { + BindTexture( SHADER_SAMPLER1, BASETEXTURE, FRAME ); + } + else + { + pShaderAPI->BindStandardTexture( SHADER_SAMPLER1, TEXTURE_FRAME_BUFFER_FULL_TEXTURE_0 ); + } + + if( bRefractTintTexture ) + { + BindTexture( SHADER_SAMPLER2, REFRACTTINTTEXTURE, REFRACTTINTTEXTUREFRAME ); + } + + if ( params[NORMALMAP]->IsTexture() ) + { + BindTexture( SHADER_SAMPLER3, NORMALMAP, BUMPFRAME ); + } + + float fRefractionAmount = params[REFRACTAMOUNT]->GetFloatValue(); + pShaderAPI->SetBumpEnvMatrix( SHADER_TEXTURE_STAGE1, fRefractionAmount, 0.0f, 0.0f, fRefractionAmount ); + + SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_1, BUMPTRANSFORM ); + + // used to invert y + // xboxfixme - move this into defined constants + float c[4] = { 0.0f, 0.0f, 0.0f, -1.0f }; + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_4, c, 1 ); + + SetPixelShaderConstant( 0, REFRACTTINT ); + if( bIsModel ) + { + refract_model_vs11_Dynamic_Index vshIndex; + vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + vshIndex.SetSKINNING( pShaderAPI->GetCurrentNumBones() > 0 ); + pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() ); + } + else + { + refract_world_vs11_Dynamic_Index vshIndex; + vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() ); + } + } + + Draw(); + + if( bHasEnvmap ) + { + bool bNoWriteZ = (params[NOWRITEZ]->GetIntValue() != 0); + const bool bBlendSpecular = true; + if( bIsModel ) + { + DrawModelBumpedSpecularLighting( NORMALMAP, BUMPFRAME, + ENVMAP, ENVMAPFRAME, + ENVMAPTINT, ALPHA, + ENVMAPCONTRAST, ENVMAPSATURATION, + BUMPTRANSFORM, + bBlendSpecular, bNoWriteZ ); + } + else + { + DrawWorldBumpedSpecularLighting( NORMALMAP, ENVMAP, + BUMPFRAME, ENVMAPFRAME, + ENVMAPTINT, ALPHA, + ENVMAPCONTRAST, ENVMAPSATURATION, + BUMPTRANSFORM, FRESNELREFLECTION, + bBlendSpecular, bNoWriteZ ); + } + } + } +END_SHADER + diff --git a/materialsystem/stdshaders/refract_dx9_helper.cpp b/materialsystem/stdshaders/refract_dx9_helper.cpp new file mode 100644 index 0000000..e027b67 --- /dev/null +++ b/materialsystem/stdshaders/refract_dx9_helper.cpp @@ -0,0 +1,298 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//=============================================================================// + +#include "BaseVSShader.h" +#include "refract_dx9_helper.h" +#include "convar.h" +#include "Refract_vs20.inc" +#include "Refract_ps20.inc" +#include "Refract_ps20b.inc" +#include "cpp_shader_constant_register_map.h" + +#define MAXBLUR 1 + +// FIXME: doesn't support fresnel! +void InitParamsRefract_DX9( CBaseVSShader *pShader, IMaterialVar** params, const char *pMaterialName, Refract_DX9_Vars_t &info ) +{ + SET_FLAGS2( MATERIAL_VAR2_NEEDS_TANGENT_SPACES ); + SET_FLAGS( MATERIAL_VAR_TRANSLUCENT ); + if( !params[info.m_nEnvmapTint]->IsDefined() ) + { + params[info.m_nEnvmapTint]->SetVecValue( 1.0f, 1.0f, 1.0f ); + } + if( !params[info.m_nEnvmapContrast]->IsDefined() ) + { + params[info.m_nEnvmapContrast]->SetFloatValue( 0.0f ); + } + if( !params[info.m_nEnvmapSaturation]->IsDefined() ) + { + params[info.m_nEnvmapSaturation]->SetFloatValue( 1.0f ); + } + if( !params[info.m_nEnvmapFrame]->IsDefined() ) + { + params[info.m_nEnvmapFrame]->SetIntValue( 0 ); + } + if( !params[info.m_nFresnelReflection]->IsDefined() ) + { + params[info.m_nFresnelReflection]->SetFloatValue( 1.0f ); + } + if( !params[info.m_nMasked]->IsDefined() ) + { + params[info.m_nMasked]->SetIntValue( 0 ); + } + if( !params[info.m_nBlurAmount]->IsDefined() ) + { + params[info.m_nBlurAmount]->SetIntValue( 0 ); + } + if( !params[info.m_nFadeOutOnSilhouette]->IsDefined() ) + { + params[info.m_nFadeOutOnSilhouette]->SetIntValue( 0 ); + } + if( !params[info.m_nForceAlphaWrite]->IsDefined() ) + { + params[info.m_nForceAlphaWrite]->SetIntValue( 0 ); + } + SET_FLAGS2( MATERIAL_VAR2_NEEDS_POWER_OF_TWO_FRAME_BUFFER_TEXTURE ); +} + +void InitRefract_DX9( CBaseVSShader *pShader, IMaterialVar** params, Refract_DX9_Vars_t &info ) +{ + if (params[info.m_nBaseTexture]->IsDefined() ) + { + pShader->LoadTexture( info.m_nBaseTexture, TEXTUREFLAGS_SRGB ); + } + if (params[info.m_nNormalMap]->IsDefined() ) + { + pShader->LoadBumpMap( info.m_nNormalMap ); + } + if (params[info.m_nNormalMap2]->IsDefined() ) + { + pShader->LoadBumpMap( info.m_nNormalMap2 ); + } + if( params[info.m_nEnvmap]->IsDefined() ) + { + pShader->LoadCubeMap( info.m_nEnvmap, TEXTUREFLAGS_SRGB ); + } + if( params[info.m_nRefractTintTexture]->IsDefined() ) + { + pShader->LoadTexture( info.m_nRefractTintTexture, TEXTUREFLAGS_SRGB ); + } +} + +void DrawRefract_DX9( CBaseVSShader *pShader, IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, + IShaderShadow* pShaderShadow, Refract_DX9_Vars_t &info, VertexCompressionType_t vertexCompression ) +{ + bool bIsModel = IS_FLAG_SET( MATERIAL_VAR_MODEL ); + bool bHasEnvmap = params[info.m_nEnvmap]->IsTexture(); + bool bRefractTintTexture = params[info.m_nRefractTintTexture]->IsTexture(); + bool bFadeOutOnSilhouette = params[info.m_nFadeOutOnSilhouette]->GetIntValue() != 0; + int blurAmount = params[info.m_nBlurAmount]->GetIntValue(); + bool bMasked = (params[info.m_nMasked]->GetIntValue() != 0); + bool bSecondaryNormal = ( ( info.m_nNormalMap2 != -1 ) && ( params[info.m_nNormalMap2]->IsTexture() ) ); + bool bColorModulate = ( ( info.m_nVertexColorModulate != -1 ) && ( params[info.m_nVertexColorModulate]->GetIntValue() ) ); + bool bWriteZ = params[info.m_nNoWriteZ]->GetIntValue() == 0; + + if( blurAmount < 0 ) + { + blurAmount = 0; + } + else if( blurAmount > MAXBLUR ) + { + blurAmount = MAXBLUR; + } + + BlendType_t nBlendType = pShader->EvaluateBlendRequirements( BASETEXTURE, true ); + bool bFullyOpaque = (nBlendType != BT_BLENDADD) && (nBlendType != BT_BLEND) && !IS_FLAG_SET(MATERIAL_VAR_ALPHATEST); //dest alpha is free for special use + bFullyOpaque &= !bMasked; + + bool bTranslucentNormal = pShader->TextureIsTranslucent( info.m_nNormalMap, false ); + bFullyOpaque &= (! bTranslucentNormal ); + + SHADOW_STATE + { + pShader->SetInitialShadowState( ); + + pShaderShadow->EnableDepthWrites( bWriteZ ); + + // Alpha test: FIXME: shouldn't this be handled in Shader_t::SetInitialShadowState + pShaderShadow->EnableAlphaTest( IS_FLAG_SET(MATERIAL_VAR_ALPHATEST) ); + + // If envmap is not specified, the alpha channel is the translucency + // (If envmap *is* specified, alpha channel is the reflection amount) + if ( params[info.m_nNormalMap]->IsTexture() && !bHasEnvmap ) + { + pShader->SetDefaultBlendingShadowState( info.m_nNormalMap, false ); + } + + // source render target that contains the image that we are warping. + pShaderShadow->EnableTexture( SHADER_SAMPLER2, true ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER2, true ); + + // normal map + pShaderShadow->EnableTexture( SHADER_SAMPLER3, true ); + if ( bSecondaryNormal ) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + } + + if( bHasEnvmap ) + { + // envmap + pShaderShadow->EnableTexture( SHADER_SAMPLER4, true ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER4, true ); + } + if( bRefractTintTexture ) + { + // refract tint texture + pShaderShadow->EnableTexture( SHADER_SAMPLER5, true ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER5, true ); + } + + pShaderShadow->EnableSRGBWrite( true ); + + unsigned int flags = VERTEX_POSITION | VERTEX_NORMAL; + int userDataSize = 0; + int nTexCoordCount = 1; + if( bIsModel ) + { + userDataSize = 4; + } + else + { + flags |= VERTEX_TANGENT_S | VERTEX_TANGENT_T; + } + + if ( bColorModulate ) + { + flags |= VERTEX_COLOR; + } + + // This shader supports compressed vertices, so OR in that flag: + flags |= VERTEX_FORMAT_COMPRESSED; + + pShaderShadow->VertexShaderVertexFormat( flags, nTexCoordCount, NULL, userDataSize ); + + DECLARE_STATIC_VERTEX_SHADER( refract_vs20 ); + SET_STATIC_VERTEX_SHADER_COMBO( MODEL, bIsModel ); + SET_STATIC_VERTEX_SHADER_COMBO( COLORMODULATE, bColorModulate ); + SET_STATIC_VERTEX_SHADER( refract_vs20 ); + + // We have to do this in the shader on R500 or Leopard + bool bShaderSRGBConvert = IsOSX() && ( g_pHardwareConfig->FakeSRGBWrite() || !g_pHardwareConfig->CanDoSRGBReadFromRTs() ); + if ( g_pHardwareConfig->SupportsPixelShaders_2_b() || g_pHardwareConfig->ShouldAlwaysUseShaderModel2bShaders() ) // always send OpenGL down the ps2b path + { + DECLARE_STATIC_PIXEL_SHADER( refract_ps20b ); + SET_STATIC_PIXEL_SHADER_COMBO( BLUR, blurAmount ); + SET_STATIC_PIXEL_SHADER_COMBO( FADEOUTONSILHOUETTE, bFadeOutOnSilhouette ); + SET_STATIC_PIXEL_SHADER_COMBO( CUBEMAP, bHasEnvmap ); + SET_STATIC_PIXEL_SHADER_COMBO( REFRACTTINTTEXTURE, bRefractTintTexture ); + SET_STATIC_PIXEL_SHADER_COMBO( MASKED, bMasked ); + SET_STATIC_PIXEL_SHADER_COMBO( COLORMODULATE, bColorModulate ); + SET_STATIC_PIXEL_SHADER_COMBO( SECONDARY_NORMAL, bSecondaryNormal ); + SET_STATIC_PIXEL_SHADER_COMBO( NORMAL_DECODE_MODE, (int) NORMAL_DECODE_NONE ); + SET_STATIC_PIXEL_SHADER_COMBO( SHADER_SRGB_READ, bShaderSRGBConvert ); + SET_STATIC_PIXEL_SHADER( refract_ps20b ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( refract_ps20 ); + SET_STATIC_PIXEL_SHADER_COMBO( BLUR, blurAmount ); + SET_STATIC_PIXEL_SHADER_COMBO( FADEOUTONSILHOUETTE, bFadeOutOnSilhouette ); + SET_STATIC_PIXEL_SHADER_COMBO( CUBEMAP, bHasEnvmap ); + SET_STATIC_PIXEL_SHADER_COMBO( REFRACTTINTTEXTURE, bRefractTintTexture ); + SET_STATIC_PIXEL_SHADER_COMBO( MASKED, bMasked ); + SET_STATIC_PIXEL_SHADER_COMBO( COLORMODULATE, bColorModulate ); + SET_STATIC_PIXEL_SHADER_COMBO( SECONDARY_NORMAL, bSecondaryNormal ); + SET_STATIC_PIXEL_SHADER_COMBO( NORMAL_DECODE_MODE, (int) NORMAL_DECODE_NONE ); + SET_STATIC_PIXEL_SHADER( refract_ps20 ); + } + pShader->DefaultFog(); + if( bMasked ) + { + pShader->EnableAlphaBlending( SHADER_BLEND_ONE_MINUS_SRC_ALPHA, SHADER_BLEND_SRC_ALPHA ); + } + + bool bAlphaWrites = bFullyOpaque || ( params[ info.m_nForceAlphaWrite ]->GetIntValue() != 0 ); + pShaderShadow->EnableAlphaWrites( bAlphaWrites ); + } + DYNAMIC_STATE + { + pShaderAPI->SetDefaultState(); + + if ( params[info.m_nBaseTexture]->IsTexture() ) + { + pShader->BindTexture( SHADER_SAMPLER2, info.m_nBaseTexture, info.m_nFrame ); + } + else + { + pShaderAPI->BindStandardTexture( SHADER_SAMPLER2, TEXTURE_FRAME_BUFFER_FULL_TEXTURE_0 ); + } + + pShader->BindTexture( SHADER_SAMPLER3, info.m_nNormalMap, info.m_nBumpFrame ); + + if ( bSecondaryNormal ) + { + pShader->BindTexture( SHADER_SAMPLER1, info.m_nNormalMap2, info.m_nBumpFrame2 ); + } + + if( bHasEnvmap ) + { + pShader->BindTexture( SHADER_SAMPLER4, info.m_nEnvmap, info.m_nEnvmapFrame ); + } + + if( bRefractTintTexture ) + { + pShader->BindTexture( SHADER_SAMPLER5, info.m_nRefractTintTexture, info.m_nRefractTintTextureFrame ); + } + + DECLARE_DYNAMIC_VERTEX_SHADER( refract_vs20 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, pShaderAPI->GetCurrentNumBones() > 0 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression ); + SET_DYNAMIC_VERTEX_SHADER( refract_vs20 ); + + if ( g_pHardwareConfig->SupportsPixelShaders_2_b() || g_pHardwareConfig->ShouldAlwaysUseShaderModel2bShaders() ) // always send Posix down the ps2b path + { + DECLARE_DYNAMIC_PIXEL_SHADER( refract_ps20b ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( WRITE_DEPTH_TO_DESTALPHA, bWriteZ && bFullyOpaque && pShaderAPI->ShouldWriteDepthToDestAlpha() ); + SET_DYNAMIC_PIXEL_SHADER( refract_ps20b ); + } + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( refract_ps20 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + SET_DYNAMIC_PIXEL_SHADER( refract_ps20 ); + } + + pShader->SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_1, info.m_nBumpTransform ); // 1 & 2 + pShader->SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_3, info.m_nBumpTransform2 ); // 3 & 4 + + pShaderAPI->SetPixelShaderFogParams( PSREG_FOG_PARAMS ); + + float vEyePos_SpecExponent[4]; + pShaderAPI->GetWorldSpaceCameraPosition( vEyePos_SpecExponent ); + vEyePos_SpecExponent[3] = 0.0f; + pShaderAPI->SetPixelShaderConstant( PSREG_EYEPOS_SPEC_EXPONENT, vEyePos_SpecExponent, 1 ); + + pShader->SetPixelShaderConstantGammaToLinear( 0, info.m_nEnvmapTint ); + pShader->SetPixelShaderConstantGammaToLinear( 1, info.m_nRefractTint ); + pShader->SetPixelShaderConstant( 2, info.m_nEnvmapContrast ); + pShader->SetPixelShaderConstant( 3, info.m_nEnvmapSaturation ); + float c5[4] = { params[info.m_nRefractAmount]->GetFloatValue(), + params[info.m_nRefractAmount]->GetFloatValue(), 0.0f, 0.0f }; + + // Time % 1000 + c5[3] = pShaderAPI->CurrentTime(); + c5[3] -= (float)( (int)( c5[3] / 1000.0f ) ) * 1000.0f; + pShaderAPI->SetPixelShaderConstant( 5, c5, 1 ); + + float cVs3[4] = { c5[3], 0.0f, 0.0f, 0.0f }; + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_5, cVs3, 1 ); + } + pShader->Draw(); +} + diff --git a/materialsystem/stdshaders/refract_dx9_helper.h b/materialsystem/stdshaders/refract_dx9_helper.h new file mode 100644 index 0000000..69d6116 --- /dev/null +++ b/materialsystem/stdshaders/refract_dx9_helper.h @@ -0,0 +1,62 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//============================================================================= + +#ifndef REFRACT_DX9_HELPER_H +#define REFRACT_DX9_HELPER_H +#ifdef _WIN32 +#pragma once +#endif + +#include + +//----------------------------------------------------------------------------- +// Forward declarations +//----------------------------------------------------------------------------- +class CBaseVSShader; +class IMaterialVar; +class IShaderDynamicAPI; +class IShaderShadow; + +//----------------------------------------------------------------------------- +// Init params/ init/ draw methods +//----------------------------------------------------------------------------- +struct Refract_DX9_Vars_t +{ + Refract_DX9_Vars_t() { memset( this, 0xFF, sizeof( *this ) ); } + + int m_nBaseTexture; + int m_nFrame; + int m_nRefractAmount; + int m_nRefractTint; + int m_nNormalMap; + int m_nNormalMap2; + int m_nBumpFrame; + int m_nBumpFrame2; + int m_nBumpTransform; + int m_nBumpTransform2; + int m_nBlurAmount; + int m_nFadeOutOnSilhouette; + int m_nEnvmap; + int m_nEnvmapFrame; + int m_nEnvmapTint; + int m_nEnvmapContrast; + int m_nEnvmapSaturation; + int m_nRefractTintTexture; + int m_nRefractTintTextureFrame; + int m_nFresnelReflection; + int m_nNoWriteZ; + int m_nMasked; + int m_nVertexColorModulate; + int m_nForceAlphaWrite; +}; + +void InitParamsRefract_DX9( CBaseVSShader *pShader, IMaterialVar** params, const char *pMaterialName, + Refract_DX9_Vars_t &info ); +void InitRefract_DX9( CBaseVSShader *pShader, IMaterialVar** params, Refract_DX9_Vars_t &info ); +void DrawRefract_DX9( CBaseVSShader *pShader, IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, + IShaderShadow* pShaderShadow, Refract_DX9_Vars_t &info, VertexCompressionType_t vertexCompression ); + +#endif // REFRACT_DX9_HELPER_H diff --git a/materialsystem/stdshaders/refract_ps2x.fxc b/materialsystem/stdshaders/refract_ps2x.fxc new file mode 100644 index 0000000..2f97423 --- /dev/null +++ b/materialsystem/stdshaders/refract_ps2x.fxc @@ -0,0 +1,250 @@ +//====== Copyright © 1996-2007, Valve Corporation, All rights reserved. ======= +// +//============================================================================= + +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX] +// STATIC: "BLUR" "0..1" +// STATIC: "FADEOUTONSILHOUETTE" "0..1" +// STATIC: "CUBEMAP" "0..1" +// STATIC: "REFRACTTINTTEXTURE" "0..1" +// STATIC: "MASKED" "0..1" +// STATIC: "COLORMODULATE" "0..1" +// STATIC: "SECONDARY_NORMAL" "0..1" +// STATIC: "NORMAL_DECODE_MODE" "0..0" [XBOX] +// STATIC: "NORMAL_DECODE_MODE" "0..0" [PC] +// STATIC: "SHADER_SRGB_READ" "0..1" [ps20b] + +// DYNAMIC: "PIXELFOGTYPE" "0..1" +// DYNAMIC: "WRITE_DEPTH_TO_DESTALPHA" "0..1" [ps20b] [PC] +// DYNAMIC: "WRITE_DEPTH_TO_DESTALPHA" "0..0" [ps20b] [XBOX] + +// SKIP: $MASKED && $BLUR + +#if defined( SHADER_MODEL_PS_2_0 ) +# define WRITE_DEPTH_TO_DESTALPHA 0 +#endif + +#include "common_ps_fxc.h" +#include "shader_constant_register_map.h" + +sampler NormalSampler2 : register( s1 ); +sampler RefractSampler : register( s2 ); +sampler NormalSampler : register( s3 ); +#if CUBEMAP +sampler EnvmapSampler : register( s4 ); +#endif +#if REFRACTTINTTEXTURE +sampler RefractTintSampler : register( s5 ); +#endif + +#if NORMAL_DECODE_MODE == NORM_DECODE_ATI2N_ALPHA +sampler AlphaMapSampler : register( s6 ); // alpha +sampler AlphaMapSampler2 : register( s7 ); +#else +#define AlphaMapSampler2 NormalSampler +#define AlphaMapSampler NormalSampler2 +#endif + +const float3 g_EnvmapTint : register( c0 ); +const float3 g_RefractTint : register( c1 ); +const float3 g_EnvmapContrast : register( c2 ); +const float3 g_EnvmapSaturation : register( c3 ); +const float4 g_c5 : register( c5 ); +#define g_RefractScale g_c5.x +#define g_flTime g_c5.w + +const float4 g_FogParams : register( PSREG_FOG_PARAMS ); +const float4 g_EyePos_SpecExponent : register( PSREG_EYEPOS_SPEC_EXPONENT ); + +static const int g_BlurCount = BLUR; +static const float g_BlurFraction = 1.0f / 512.0f; +static const float g_HalfBlurFraction = 0.5 * g_BlurFraction; +static const float4 g_BlurFractionVec = float4( g_BlurFraction, g_HalfBlurFraction, + -g_BlurFraction,-g_HalfBlurFraction ); + +struct PS_INPUT +{ + float4 vBumpTexCoord : TEXCOORD0; // NormalMap1 in xy, NormalMap2 in wz + float3 vTangentVertToEyeVector : TEXCOORD1; + float3 vWorldNormal : TEXCOORD2; + float3 vWorldTangent : TEXCOORD3; + float3 vWorldBinormal : TEXCOORD4; + float3 vRefractXYW : TEXCOORD5; + float3 vWorldViewVector : TEXCOORD6; +#if COLORMODULATE + float4 ColorModulate : COLOR0; +#endif + + float4 worldPos_projPosZ : TEXCOORD7; // Necessary for pixel fog + float4 fogFactorW : COLOR1; +}; + +float4 main( PS_INPUT i ) : COLOR +{ + float3 result; + + float pixelFogFactor = CalcPixelFogFactor( PIXELFOGTYPE, g_FogParams, g_EyePos_SpecExponent.z, i.worldPos_projPosZ.z, i.worldPos_projPosZ.w ); + +#if FADEOUTONSILHOUETTE + //float blend = -i.projNormal.z; + float blend = saturate( dot( -i.vWorldViewVector.xyz, i.vWorldNormal.xyz ) ); + blend = blend * blend * blend; +#else + float blend = 1.0f; +#endif + + // Decompress normal + float4 vNormal = DecompressNormal( NormalSampler, i.vBumpTexCoord.xy, NORMAL_DECODE_MODE, AlphaMapSampler ); + +#if SECONDARY_NORMAL + float3 vNormal2 = DecompressNormal( NormalSampler2, i.vBumpTexCoord.wz, NORMAL_DECODE_MODE, AlphaMapSampler2 ); + vNormal.xyz = normalize( vNormal.xyz + vNormal2.xyz ); +#endif + +#if REFRACTTINTTEXTURE + float3 refractTintColor = 2.0 * g_RefractTint * tex2D( RefractTintSampler, i.vBumpTexCoord.xy ); +#else + float3 refractTintColor = g_RefractTint; +#endif + +#if COLORMODULATE + refractTintColor *= i.ColorModulate.rgb; +#endif + + // Perform division by W only once + float ooW = 1.0f / i.vRefractXYW.z; + + // Compute coordinates for sampling refraction + float2 vRefractTexCoordNoWarp = i.vRefractXYW.xy * ooW; + float2 vRefractTexCoord = vNormal.xy; + float scale = vNormal.a * g_RefractScale; +#if COLORMODULATE + scale *= i.ColorModulate.a; +#endif + vRefractTexCoord *= scale; + vRefractTexCoord += vRefractTexCoordNoWarp; + +#if (BLUR==1) // use polyphase magic to convert 9 lookups into 4 + + // basic principle behind this transformation: + // [ A B C ] + // [ D E F ] + // [ G H I ] + // use bilinear filtering hardware to weight upper 2x2 samples evenly (0.25* [A + B + D + E]). + // scale the upper 2x2 by 4/9 (total area of kernel occupied) + // use bilinear filtering hardware to weight right 1x2 samples evenly (0.5*[C + F]) + // scale right 1x2 by 2/9 + // use bilinear filtering hardware to weight lower 2x1 samples evenly (0.5*[G + H]) + // scale bottom 2x1 by 2/9 + // fetch last sample (I) and scale by 1/9. + + float2 upper_2x2_loc = vRefractTexCoord.xy - float2(g_HalfBlurFraction, g_HalfBlurFraction); + float2 right_1x2_loc = vRefractTexCoord.xy + float2(g_BlurFraction, -g_HalfBlurFraction); + float2 lower_2x1_loc = vRefractTexCoord.xy + float2(-g_HalfBlurFraction, g_BlurFraction); + float2 singleton_loc = vRefractTexCoord.xy + float2(g_BlurFraction, g_BlurFraction); + result = tex2D(RefractSampler, upper_2x2_loc) * 0.4444444; + result += tex2D(RefractSampler, right_1x2_loc) * 0.2222222; + result += tex2D(RefractSampler, lower_2x1_loc) * 0.2222222; + result += tex2D(RefractSampler, singleton_loc) * 0.1111111; + + #if ( SHADER_SRGB_READ == 1 ) + { + // Just do this once rather than after every blur step, which is wrong, but much more efficient + result = GammaToLinear( result ); + } + #endif + + float3 unblurredColor = tex2D(RefractSampler, vRefractTexCoordNoWarp.xy); + #if ( SHADER_SRGB_READ == 1 ) + { + unblurredColor = GammaToLinear( unblurredColor ); + } + #endif + + result = lerp(unblurredColor, result * refractTintColor, blend); + +#elif (BLUR>0) // iteratively step through render target + int x, y; + + result = float3( 0.0f, 0.0f, 0.0f ); + for( x = -g_BlurCount; x <= g_BlurCount; x++ ) + { + for( y = -g_BlurCount; y <= g_BlurCount; y++ ) + { + result += tex2D( RefractSampler, vRefractTexCoord.xy + float2( g_BlurFraction * x, g_BlurFraction * y ) ); + } + } + + int width = g_BlurCount * 2 + 1; + result *= 1.0f / ( width * width ); + + #if ( SHADER_SRGB_READ == 1 ) + { + // Just do this once rather than after every blur step, which is wrong, but much more efficient + result = GammaToLinear( result ); + } + #endif + + // result is the blurred one now. . .now lerp. + float3 unblurredColor = tex2D( RefractSampler, vRefractTexCoordNoWarp.xy ); + #if ( SHADER_SRGB_READ == 1 ) + { + unblurredColor = GammaToLinear( unblurredColor ); + } + #endif + + result = lerp( unblurredColor, result * refractTintColor, blend ); +#else +# if MASKED + float4 fMaskedResult = tex2D( RefractSampler, vRefractTexCoord.xy ); + #if ( SHADER_SRGB_READ == 1 ) + { + fMaskedResult = GammaToLinear( fMaskedResult ); + } + #endif + + return FinalOutput( fMaskedResult, pixelFogFactor, PIXELFOGTYPE, TONEMAP_SCALE_NONE ); +# else + float3 colorWarp = tex2D( RefractSampler, vRefractTexCoord.xy ); + #if ( SHADER_SRGB_READ == 1 ) + { + colorWarp = GammaToLinear( colorWarp ); + } + #endif + float3 colorNoWarp = tex2D( RefractSampler, vRefractTexCoordNoWarp.xy ); + #if ( SHADER_SRGB_READ == 1 ) + { + colorNoWarp = GammaToLinear( colorNoWarp ); + } + #endif + + colorWarp *= refractTintColor; + result = lerp( colorNoWarp, colorWarp, blend ); +# endif +#endif + +#if CUBEMAP + float specularFactor = vNormal.a; + + float3 worldSpaceNormal = Vec3TangentToWorld( vNormal.xyz, i.vWorldNormal, i.vWorldTangent, i.vWorldBinormal ); + + float3 reflectVect = CalcReflectionVectorUnnormalized( worldSpaceNormal, i.vTangentVertToEyeVector ); + float3 specularLighting = texCUBE( EnvmapSampler, reflectVect ); + specularLighting *= specularFactor; + specularLighting *= g_EnvmapTint; + float3 specularLightingSquared = specularLighting * specularLighting; + specularLighting = lerp( specularLighting, specularLightingSquared, g_EnvmapContrast ); + float3 greyScale = dot( specularLighting, float3( 0.299f, 0.587f, 0.114f ) ); + specularLighting = lerp( greyScale, specularLighting, g_EnvmapSaturation ); + result += specularLighting; +#endif + +#if COLORMODULATE + float resultAlpha = i.ColorModulate.a * vNormal.a; +#else + float resultAlpha = vNormal.a; +#endif + + return FinalOutput( float4( result, resultAlpha ), pixelFogFactor, PIXELFOGTYPE, TONEMAP_SCALE_NONE, (WRITE_DEPTH_TO_DESTALPHA != 0), i.worldPos_projPosZ.w ); +} diff --git a/materialsystem/stdshaders/rendertargetblit_ps2x.fxc b/materialsystem/stdshaders/rendertargetblit_ps2x.fxc new file mode 100644 index 0000000..8bfa700 --- /dev/null +++ b/materialsystem/stdshaders/rendertargetblit_ps2x.fxc @@ -0,0 +1,20 @@ +//======= Copyright © 1996-2006, Valve Corporation, All rights reserved. ====== + +#define CONVERT_TO_SRGB 0 + +#include "common_ps_fxc.h" + +sampler TexSampler : register( s0 ); + +struct PS_INPUT +{ + HALF2 baseTexCoord : TEXCOORD0; // Base texture coordinate +}; + +float4 main( PS_INPUT i ) : COLOR +{ + float4 result = tex2D( TexSampler, i.baseTexCoord ); + + return FinalOutput( result, 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE ); +} + diff --git a/materialsystem/stdshaders/rendertargetblit_vs20.fxc b/materialsystem/stdshaders/rendertargetblit_vs20.fxc new file mode 100644 index 0000000..c6bc84b --- /dev/null +++ b/materialsystem/stdshaders/rendertargetblit_vs20.fxc @@ -0,0 +1,24 @@ +#include "common_vs_fxc.h" + +struct VS_INPUT +{ + float3 vPos : POSITION; + float2 vBaseTexCoord : TEXCOORD0; +}; + +struct VS_OUTPUT +{ + float4 projPos : POSITION; + float2 baseTexCoord : TEXCOORD0; +}; + +VS_OUTPUT main( const VS_INPUT v ) +{ + VS_OUTPUT o = ( VS_OUTPUT )0; + + o.projPos = float4( v.vPos, 1.0f ); + o.baseTexCoord = v.vBaseTexCoord; + return o; +} + + diff --git a/materialsystem/stdshaders/rendertargetblit_x360.cpp b/materialsystem/stdshaders/rendertargetblit_x360.cpp new file mode 100644 index 0000000..e6a6bd0 --- /dev/null +++ b/materialsystem/stdshaders/rendertargetblit_x360.cpp @@ -0,0 +1,83 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: Replaces 360 missing StretchRect() functionality. +// +//============================================================================= + +#include "BaseVSShader.h" +#include "rendertargetblit_vs20.inc" +#include "rendertargetblit_ps20.inc" +#include "rendertargetblit_ps20b.inc" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +BEGIN_VS_SHADER_FLAGS( RenderTargetBlit_X360, "", SHADER_NOT_EDITABLE ) + + BEGIN_SHADER_PARAMS + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + if ( !params[BASETEXTURE]->IsDefined() ) + { + params[BASETEXTURE]->SetStringValue( "_rt_FullFrameFB" ); + } + } + + SHADER_INIT + { + LoadTexture( BASETEXTURE ); + } + + SHADER_DRAW + { + SHADOW_STATE + { + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, false ); + pShaderShadow->EnableSRGBWrite( false ); + + pShaderShadow->EnableDepthWrites( false ); + pShaderShadow->DepthFunc( SHADER_DEPTHFUNC_ALWAYS ); + pShaderShadow->EnableCulling( false ); + + pShaderShadow->VertexShaderVertexFormat( VERTEX_POSITION, 1, 0, 0 ); + + DECLARE_STATIC_VERTEX_SHADER( rendertargetblit_vs20 ); + SET_STATIC_VERTEX_SHADER( rendertargetblit_vs20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_STATIC_PIXEL_SHADER( rendertargetblit_ps20b ); + SET_STATIC_PIXEL_SHADER( rendertargetblit_ps20b ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( rendertargetblit_ps20 ); + SET_STATIC_PIXEL_SHADER( rendertargetblit_ps20 ); + } + } + + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME ); + + DECLARE_DYNAMIC_VERTEX_SHADER( rendertargetblit_vs20 ); + SET_DYNAMIC_VERTEX_SHADER( rendertargetblit_vs20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_DYNAMIC_PIXEL_SHADER( rendertargetblit_ps20b ); + SET_DYNAMIC_PIXEL_SHADER( rendertargetblit_ps20b ); + } + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( rendertargetblit_ps20 ); + SET_DYNAMIC_PIXEL_SHADER( rendertargetblit_ps20 ); + } + } + + Draw(); + } +END_SHADER 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 diff --git a/materialsystem/stdshaders/rift_dx8.cpp b/materialsystem/stdshaders/rift_dx8.cpp new file mode 100644 index 0000000..cb60c15 --- /dev/null +++ b/materialsystem/stdshaders/rift_dx8.cpp @@ -0,0 +1,102 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $Header: $ +// $NoKeywords: $ +//===========================================================================// + +#include "BaseVSShader.h" +#include "rift_vs11.inc" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +BEGIN_VS_SHADER( Rift_DX8, + "Help for Rift_DX8" ) + + 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_PARAMS() + { + SET_FLAGS2( MATERIAL_VAR2_SUPPORTS_HW_SKINNING ); + } + + SHADER_INIT + { + if (params[BASETEXTURE]->IsDefined()) + { + LoadTexture( BASETEXTURE ); + } + if (params[TEXTURE2]->IsDefined()) + { + LoadTexture( TEXTURE2 ); + } + } + + SHADER_DRAW + { + SHADOW_STATE + { + pShaderShadow->EnableTexture( SHADER_TEXTURE_STAGE0, true ); + pShaderShadow->EnableTexture( SHADER_TEXTURE_STAGE1, true ); + + // 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 ); + } + } + + int fmt = VERTEX_POSITION; + pShaderShadow->VertexShaderVertexFormat( fmt, 1, 0, 0 ); + pShaderShadow->SetVertexShader( "rift_vs11", 0 ); + pShaderShadow->SetPixelShader( "rift_ps11", 0 ); + + DefaultFog(); + } + DYNAMIC_STATE + { + BindTexture( SHADER_TEXTURE_STAGE0, BASETEXTURE, FRAME ); + pShaderAPI->SetTextureTransformDimension( 0, 3, true ); + + BindTexture( SHADER_TEXTURE_STAGE1, TEXTURE2, FRAME2 ); + SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_1, TEXTURE2TRANSFORM ); + + // used to invert y + float c[4] = { 0.0f, 0.0f, 0.0f, -1.0f }; + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_4, c, 1 ); + + SetModulationPixelShaderDynamicState( 0 ); + + rift_vs11_Dynamic_Index vshIndex; + vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + vshIndex.SetSKINNING( pShaderAPI->GetCurrentNumBones() > 0 ); + pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() ); + } + Draw(); + } +END_SHADER diff --git a/materialsystem/stdshaders/rift_ps11.psh b/materialsystem/stdshaders/rift_ps11.psh new file mode 100644 index 0000000..8b1912d --- /dev/null +++ b/materialsystem/stdshaders/rift_ps11.psh @@ -0,0 +1,16 @@ +ps.1.1 + +; t0: +; texture: dudv map +; texcoords: dudvmap texcoords +; t1: +; texture: refraction render target +; texcoords: + +tex t0 ; refraction +tex t1 ; sample alpha channel + +mul r0.rgb, t1, t0 + +mov r0.a, t1.a + +mul r0, r0, c0 diff --git a/materialsystem/stdshaders/rift_vs11.vsh b/materialsystem/stdshaders/rift_vs11.vsh new file mode 100644 index 0000000..aa4b31c --- /dev/null +++ b/materialsystem/stdshaders/rift_vs11.vsh @@ -0,0 +1,70 @@ +vs.1.1 + +# DYNAMIC: "DOWATERFOG" "0..1" +# DYNAMIC: "SKINNING" "0..1" + +;------------------------------------------------------------------------------ +; Constants specified by the app +; c0 = (0, 1, 2, 0.5) +; c1 = (1/2.2, 0, 0, 0) +; c2 = camera position *in world space* +; c4-c7 = modelViewProj matrix (transpose) +; c8-c11 = ViewProj matrix (transpose) +; c12-c15 = model->view matrix (transpose) +; c16 = [fogStart, fogEnd, fogRange, undefined] +; +; Vertex components (as specified in the vertex DECL) +; $vPos = Position +; $vTexCoord0.xy = TexCoord0 +;------------------------------------------------------------------------------ + +#include "macros.vsh" + +; Vertex components +; $vPos = Position +; $vNormal = normal +; $vTexCoord0.xy = TexCoord0 +; $vTangentS = S axis of Texture space +; $vTangentT = T axis of Texture space + +;------------------------------------------------------------------------------ +; Transform the position from world to view space +;------------------------------------------------------------------------------ + +; Transform position from object to world space +alloc $worldPos +&SkinPosition( $worldPos ); + +; Project to view space +alloc $projPos +dp4 $projPos.x, $worldPos, $cViewProj0 +dp4 $projPos.y, $worldPos, $cViewProj1 +dp4 $projPos.z, $worldPos, $cViewProj2 +dp4 $projPos.w, $worldPos, $cViewProj3 +mov oPos, $projPos + +&CalcFog( $worldPos, $projPos ); + +alloc $newProjPos + +mov oPos, $projPos + +; special case perspective correct texture projection so that the texture fits exactly on the screen +mul $projPos.y, $projPos.y, $SHADER_SPECIFIC_CONST_4.w +add $projPos.xy, $projPos.xy, $projPos.w +mul $projPos.xy, $projPos.xy, $cHalf + +mov oT0.xy, $projPos.xy +mov oT0.z, $cZero +mov oT0.w, $projPos.w + +free $projPos +free $worldPos +free $newProjPos + +; alpha map +alloc $bumpTexCoord +dp4 $bumpTexCoord.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_1 +dp4 $bumpTexCoord.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_2 +mov oT1.xy, $bumpTexCoord +free $bumpTexCoord diff --git a/materialsystem/stdshaders/sample4x4.cpp b/materialsystem/stdshaders/sample4x4.cpp new file mode 100644 index 0000000..1c994bc --- /dev/null +++ b/materialsystem/stdshaders/sample4x4.cpp @@ -0,0 +1,121 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//=============================================================================// + +#include "BaseVSShader.h" +#include "common_hlsl_cpp_consts.h" + + +BEGIN_VS_SHADER_FLAGS( Sample4x4, "Help for Sample4x4", SHADER_NOT_EDITABLE ) + BEGIN_SHADER_PARAMS + SHADER_PARAM( BASETEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "" ) + SHADER_PARAM( PIXSHADER, SHADER_PARAM_TYPE_STRING, "sample4x4_ps20", "Name of the pixel shader to use" ) + END_SHADER_PARAMS + + SHADER_INIT + { + LoadTexture( BASETEXTURE ); + } + + SHADER_FALLBACK + { + // Requires DX9 + above + if (!g_pHardwareConfig->SupportsVertexAndPixelShaders()) + { + Assert( 0 ); + return "Wireframe"; + } + return 0; + } + + SHADER_DRAW + { + SHADOW_STATE + { + pShaderShadow->EnableDepthWrites( false ); + pShaderShadow->EnableAlphaWrites( true ); + + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + int fmt = VERTEX_POSITION; + pShaderShadow->VertexShaderVertexFormat( fmt, 1, 0, 0 ); + + pShaderShadow->SetVertexShader( "Downsample_vs20", 0 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + const char *szPixelShader = params[PIXSHADER]->GetStringValue(); + size_t iLength = Q_strlen( szPixelShader ); + + if( (iLength > 5) && (Q_stricmp( &szPixelShader[iLength - 5], "_ps20" ) == 0) ) //detect if it's trying to load a ps20 shader + { + //replace it with the ps20b shader + char *szNewName = (char *)stackalloc( sizeof( char ) * (iLength + 2) ); + memcpy( szNewName, szPixelShader, sizeof( char ) * iLength ); + szNewName[iLength] = 'b'; + szNewName[iLength + 1] = '\0'; + pShaderShadow->SetPixelShader( szNewName, 0 ); + } + else + { + pShaderShadow->SetPixelShader( params[PIXSHADER]->GetStringValue(), 0 ); + } + } + else + { + pShaderShadow->SetPixelShader( params[PIXSHADER]->GetStringValue(), 0 ); + } + +// if ( IsAlphaModulating() ) +// { +// pShaderShadow->EnableBlending( true ); +// pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, +// SHADER_BLEND_ONE_MINUS_SRC_ALPHA ); +// } +// else +// { +// pShaderShadow->EnableBlending( true ); +// pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, +// SHADER_BLEND_ONE_MINUS_SRC_ALPHA ); +// // pShaderShadow->EnableBlending( false ); +// } + } + + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER0, BASETEXTURE, -1 ); + ITexture *src_texture=params[BASETEXTURE]->GetTextureValue(); + + int width=src_texture->GetActualWidth(); + int height=src_texture->GetActualHeight(); + + float v[4]; + float dX = 1.0f / width; + float dY = 1.0f / height; + + v[0] = -dX; + v[1] = -dY; + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, v, 1 ); + v[0] = -dX; + v[1] = dY; + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_1, v, 1 ); + v[0] = dX; + v[1] = -dY; + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_2, v, 1 ); + v[0] = dX; + v[1] = dY; + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_3, v, 1 ); + + pShaderAPI->SetVertexShaderIndex( 0 ); + pShaderAPI->SetPixelShaderIndex( 0 ); + + // store the ALPHA material var into c0 + v[0] = ALPHA; + pShaderAPI->SetPixelShaderConstant( 0, v, 1 ); + + } + Draw(); + } +END_SHADER diff --git a/materialsystem/stdshaders/sample4x4_blend.cpp b/materialsystem/stdshaders/sample4x4_blend.cpp new file mode 100644 index 0000000..4bdc8b1 --- /dev/null +++ b/materialsystem/stdshaders/sample4x4_blend.cpp @@ -0,0 +1,111 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//=============================================================================// + +#include "BaseVSShader.h" +#include "common_hlsl_cpp_consts.h" + + +BEGIN_VS_SHADER( Sample4x4_Blend, "Help for Sample4x4_Blend" ) + BEGIN_SHADER_PARAMS + SHADER_PARAM( BASETEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "" ) + SHADER_PARAM( PIXSHADER, SHADER_PARAM_TYPE_STRING, "sample4x4_ps20", "Name of the pixel shader to use" ) + END_SHADER_PARAMS + + SHADER_INIT + { + LoadTexture( BASETEXTURE ); + } + + SHADER_FALLBACK + { + // Requires DX9 + above + if (!g_pHardwareConfig->SupportsVertexAndPixelShaders()) + { + Assert( 0 ); + return "Wireframe"; + } + return 0; + } + + SHADER_DRAW + { + SHADOW_STATE + { + pShaderShadow->EnableDepthWrites( false ); + pShaderShadow->EnableAlphaWrites( true ); + + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + int fmt = VERTEX_POSITION; + pShaderShadow->VertexShaderVertexFormat( fmt, 1, 0, 0 ); + + pShaderShadow->SetVertexShader( "Downsample_vs20", 0 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + const char *szPixelShader = params[PIXSHADER]->GetStringValue(); + size_t iLength = Q_strlen( szPixelShader ); + + if( (iLength > 5) && (Q_stricmp( &szPixelShader[iLength - 5], "_ps20" ) == 0) ) //detect if it's trying to load a ps20 shader + { + //replace it with the ps20b shader + char *szNewName = (char *)stackalloc( sizeof( char ) * (iLength + 2) ); + memcpy( szNewName, szPixelShader, sizeof( char ) * iLength ); + szNewName[iLength] = 'b'; + szNewName[iLength + 1] = '\0'; + pShaderShadow->SetPixelShader( szNewName, 0 ); + } + else + { + pShaderShadow->SetPixelShader( params[PIXSHADER]->GetStringValue(), 0 ); + } + } + else + { + pShaderShadow->SetPixelShader( params[PIXSHADER]->GetStringValue(), 0 ); + } + + pShaderShadow->EnableBlending( true ); + pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, + SHADER_BLEND_ONE_MINUS_SRC_ALPHA ); + } + + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER0, BASETEXTURE, -1 ); + ITexture *src_texture=params[BASETEXTURE]->GetTextureValue(); + + int width=src_texture->GetActualWidth(); + int height=src_texture->GetActualHeight(); + + float v[4]; + float dX = 1.0f / width; + float dY = 1.0f / height; + + v[0] = -dX; + v[1] = -dY; + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, v, 1 ); + v[0] = -dX; + v[1] = dY; + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_1, v, 1 ); + v[0] = dX; + v[1] = -dY; + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_2, v, 1 ); + v[0] = dX; + v[1] = dY; + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_3, v, 1 ); + + pShaderAPI->SetVertexShaderIndex( 0 ); + pShaderAPI->SetPixelShaderIndex( 0 ); + + // store the ALPHA material var into c0 + v[0] = ALPHA; + pShaderAPI->SetPixelShaderConstant( 0, v, 1 ); + + } + Draw(); + } +END_SHADER diff --git a/materialsystem/stdshaders/sample4x4_blend_ps2x.fxc b/materialsystem/stdshaders/sample4x4_blend_ps2x.fxc new file mode 100644 index 0000000..7ec0f2c --- /dev/null +++ b/materialsystem/stdshaders/sample4x4_blend_ps2x.fxc @@ -0,0 +1,30 @@ +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX] + +#define HDRTYPE HDR_TYPE_NONE +#include "common_ps_fxc.h" + + +sampler TexSampler : register( s0 ); + +struct PS_INPUT +{ + float2 coordTap0 : TEXCOORD0; + float2 coordTap1 : TEXCOORD1; + float2 coordTap2 : TEXCOORD2; + float2 coordTap3 : TEXCOORD3; +}; + +float4 main( PS_INPUT i ) : COLOR +{ + float3 s0, s1, s2, s3; + + // Sample 4 taps. We use the trick of sampling four taps with bilinear in order + // to average 16 texels. + s0 = tex2D( TexSampler, i.coordTap0); + s1 = tex2D( TexSampler, i.coordTap1); + s2 = tex2D( TexSampler, i.coordTap2); + s3 = tex2D( TexSampler, i.coordTap3); + return FinalOutput( float4(exp(0.25*(s0+s1+s2+s3)),0.01), 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE ); +} + diff --git a/materialsystem/stdshaders/sample4x4_ps2x.fxc b/materialsystem/stdshaders/sample4x4_ps2x.fxc new file mode 100644 index 0000000..648bb11 --- /dev/null +++ b/materialsystem/stdshaders/sample4x4_ps2x.fxc @@ -0,0 +1,32 @@ +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX] + +#define HDRTYPE HDR_TYPE_NONE +#include "common_ps_fxc.h" + + +sampler TexSampler : register( s0 ); + +struct PS_INPUT +{ + float2 coordTap0 : TEXCOORD0; + float2 coordTap1 : TEXCOORD1; + float2 coordTap2 : TEXCOORD2; + float2 coordTap3 : TEXCOORD3; +}; + +float AlphaConst : register( c0 ); + +float4 main( PS_INPUT i ) : COLOR +{ + float3 s0, s1, s2, s3; + + // Sample 4 taps. We use the trick of sampling four taps with bilinear in order + // to average 16 texels. + s0 = tex2D( TexSampler, i.coordTap0); + s1 = tex2D( TexSampler, i.coordTap1); + s2 = tex2D( TexSampler, i.coordTap2); + s3 = tex2D( TexSampler, i.coordTap3); + return FinalOutput( float4(0.25*(s0+s1+s2+s3),1), 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE ); +} + diff --git a/materialsystem/stdshaders/sample4x4delog_ps2x.fxc b/materialsystem/stdshaders/sample4x4delog_ps2x.fxc new file mode 100644 index 0000000..9f3fb61 --- /dev/null +++ b/materialsystem/stdshaders/sample4x4delog_ps2x.fxc @@ -0,0 +1,35 @@ +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX] + +#define HDRTYPE HDR_TYPE_NONE +#include "common_ps_fxc.h" + + +sampler TexSampler : register( s0 ); + +struct PS_INPUT +{ + float2 coordTap0 : TEXCOORD0; + float2 coordTap1 : TEXCOORD1; + float2 coordTap2 : TEXCOORD2; + float2 coordTap3 : TEXCOORD3; +}; + +float AlphaConst : register( c0 ); + +float4 main( PS_INPUT i ) : COLOR +{ + float3 s0, s1, s2, s3; + + // Sample 4 taps. We use the trick of sampling four taps with bilinear in order + // to average 16 texels. + s0 = tex2D( TexSampler, i.coordTap0); + s1 = tex2D( TexSampler, i.coordTap1); + s2 = tex2D( TexSampler, i.coordTap2); + s3 = tex2D( TexSampler, i.coordTap3); + float avglum=0.25*(s0.x+s1.x+s2.x+s3.x); + float elum=exp(avglum); + + return FinalOutput( float4(elum,elum,elum,1), 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE ); +} + diff --git a/materialsystem/stdshaders/sample4x4log_ps2x.fxc b/materialsystem/stdshaders/sample4x4log_ps2x.fxc new file mode 100644 index 0000000..801e0f6 --- /dev/null +++ b/materialsystem/stdshaders/sample4x4log_ps2x.fxc @@ -0,0 +1,51 @@ +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX] + +#define HDRTYPE HDR_TYPE_NONE +#include "common_ps_fxc.h" + + +sampler TexSampler : register( s0 ); + +struct PS_INPUT +{ + float2 coordTap0 : TEXCOORD0; + float2 coordTap1 : TEXCOORD1; + float2 coordTap2 : TEXCOORD2; + float2 coordTap3 : TEXCOORD3; +}; + +float AlphaConst : register( c0 ); + +#define LOG_EPSILON 0.000001 + +float luminance(float3 color) : FLOAT +{ + return 0.2125*color.x+0.7154*color.y+0.0721*color.z; +} + +float logluminance(float3 color) : FLOAT +{ + return log(0.2125*color.x+0.7154*color.y+0.0721*color.z+LOG_EPSILON); +} + +float4 main( PS_INPUT i ) : COLOR +{ + float3 s0, s1, s2, s3; + + // Sample 4 taps. We use the trick of sampling four taps with bilinear in order + // to average 16 texels. + s0 = tex2D( TexSampler, i.coordTap0); + s1 = tex2D( TexSampler, i.coordTap1); + s2 = tex2D( TexSampler, i.coordTap2); + s3 = tex2D( TexSampler, i.coordTap3); + float maxlum=max(max(luminance(s0),luminance(s1)),max(luminance(s2),luminance(s3))); + float loglum0=logluminance(s0); + float loglum1=logluminance(s1); + float loglum2=logluminance(s2); + float loglum3=logluminance(s3); + +// return float4(0.25*(loglum0+loglum1+loglum2+loglum3),maxlum,0,1); + return FinalOutput( float4(0.25*(loglum0+loglum1+loglum2+loglum3),0,.5,AlphaConst), 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE ); +} + diff --git a/materialsystem/stdshaders/sample4x4maxmin_ps2x.fxc b/materialsystem/stdshaders/sample4x4maxmin_ps2x.fxc new file mode 100644 index 0000000..5ac3cb8 --- /dev/null +++ b/materialsystem/stdshaders/sample4x4maxmin_ps2x.fxc @@ -0,0 +1,32 @@ +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX] + +#define HDRTYPE HDR_TYPE_NONE +#include "common_ps_Fxc.h" + + +sampler TexSampler : register( s0 ); + +struct PS_INPUT +{ + float2 coordTap0 : TEXCOORD0; + float2 coordTap1 : TEXCOORD1; + float2 coordTap2 : TEXCOORD2; + float2 coordTap3 : TEXCOORD3; +}; + +float PixelScale : register( c0 ); + +float4 main( PS_INPUT i ) : COLOR +{ + float3 s0, s1, s2, s3; + + // Sample 4 taps. We use the trick of sampling four taps with bilinear in order + // to average 16 texels. + s0 = tex2D( TexSampler, i.coordTap0); + s1 = tex2D( TexSampler, i.coordTap1); + s2 = tex2D( TexSampler, i.coordTap2); + s3 = tex2D( TexSampler, i.coordTap3); + return FinalOutput( float4(0.25*(s0.xyz+s1.xyz+s2.xyz+s3.xzy),1), 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE ); +} + diff --git a/materialsystem/stdshaders/screenspace_general.cpp b/materialsystem/stdshaders/screenspace_general.cpp new file mode 100644 index 0000000..ece1b9d --- /dev/null +++ b/materialsystem/stdshaders/screenspace_general.cpp @@ -0,0 +1,313 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//=============================================================================// + +#include "BaseVSShader.h" + +#include "screenspaceeffect_vs20.inc" + +DEFINE_FALLBACK_SHADER( screenspace_general, screenspace_general_dx9 ) +BEGIN_VS_SHADER_FLAGS( screenspace_general_dx9, "Help for screenspace_general", SHADER_NOT_EDITABLE ) + BEGIN_SHADER_PARAMS + SHADER_PARAM( C0_X,SHADER_PARAM_TYPE_FLOAT,"0","") + SHADER_PARAM( C0_Y,SHADER_PARAM_TYPE_FLOAT,"0","") + SHADER_PARAM( C0_Z,SHADER_PARAM_TYPE_FLOAT,"0","") + SHADER_PARAM( C0_W,SHADER_PARAM_TYPE_FLOAT,"0","") + SHADER_PARAM( C1_X,SHADER_PARAM_TYPE_FLOAT,"0","") + SHADER_PARAM( C1_Y,SHADER_PARAM_TYPE_FLOAT,"0","") + SHADER_PARAM( C1_Z,SHADER_PARAM_TYPE_FLOAT,"0","") + SHADER_PARAM( C1_W,SHADER_PARAM_TYPE_FLOAT,"0","") + SHADER_PARAM( C2_X,SHADER_PARAM_TYPE_FLOAT,"0","") + SHADER_PARAM( C2_Y,SHADER_PARAM_TYPE_FLOAT,"0","") + SHADER_PARAM( C2_Z,SHADER_PARAM_TYPE_FLOAT,"0","") + SHADER_PARAM( C2_W,SHADER_PARAM_TYPE_FLOAT,"0","") + SHADER_PARAM( C3_X,SHADER_PARAM_TYPE_FLOAT,"0","") + SHADER_PARAM( C3_Y,SHADER_PARAM_TYPE_FLOAT,"0","") + SHADER_PARAM( C3_Z,SHADER_PARAM_TYPE_FLOAT,"0","") + SHADER_PARAM( C3_W,SHADER_PARAM_TYPE_FLOAT,"0","") + SHADER_PARAM( PIXSHADER, SHADER_PARAM_TYPE_STRING, "", "Name of the pixel shader to use" ) + SHADER_PARAM( DISABLE_COLOR_WRITES,SHADER_PARAM_TYPE_INTEGER,"0","") + SHADER_PARAM( ALPHATESTED,SHADER_PARAM_TYPE_FLOAT,"0","") + SHADER_PARAM( ALPHA_BLEND_COLOR_OVERLAY, SHADER_PARAM_TYPE_INTEGER, "0", "") + SHADER_PARAM( ALPHA_BLEND, SHADER_PARAM_TYPE_INTEGER, "0", "") + SHADER_PARAM( TEXTURE1, SHADER_PARAM_TYPE_TEXTURE, "", "" ) + SHADER_PARAM( TEXTURE2, SHADER_PARAM_TYPE_TEXTURE, "", "" ) + SHADER_PARAM( TEXTURE3, SHADER_PARAM_TYPE_TEXTURE, "", "" ) + SHADER_PARAM( LINEARREAD_BASETEXTURE, SHADER_PARAM_TYPE_INTEGER, "0", "" ) + SHADER_PARAM( LINEARREAD_TEXTURE1, SHADER_PARAM_TYPE_INTEGER, "0", "" ) + SHADER_PARAM( LINEARREAD_TEXTURE2, SHADER_PARAM_TYPE_INTEGER, "0", "" ) + SHADER_PARAM( LINEARREAD_TEXTURE3, SHADER_PARAM_TYPE_INTEGER, "0", "" ) + SHADER_PARAM( LINEARWRITE,SHADER_PARAM_TYPE_INTEGER,"0","") + SHADER_PARAM( X360APPCHOOSER, SHADER_PARAM_TYPE_INTEGER, "0", "Needed for movies in 360 launcher" ) + SHADER_PARAM( COPYALPHA, SHADER_PARAM_TYPE_INTEGER, "0", "") + END_SHADER_PARAMS + + SHADER_INIT + { + if ( params[BASETEXTURE]->IsDefined() ) + { +#ifdef POSIX + ImageFormat fmt = params[BASETEXTURE]->GetTextureValue()->GetImageFormat(); + bool bSRGB; + if ( ( fmt == IMAGE_FORMAT_RGBA16161616F ) || ( fmt == IMAGE_FORMAT_RGBA16161616 ) ) + bSRGB = false; + else + bSRGB = !params[LINEARREAD_BASETEXTURE]->IsDefined() || !params[LINEARREAD_BASETEXTURE]->GetIntValue(); + LoadTexture( BASETEXTURE, bSRGB ? TEXTUREFLAGS_SRGB : 0 ); +#else + LoadTexture( BASETEXTURE ); +#endif // POSIX + } + if ( params[TEXTURE1]->IsDefined() ) + { +#ifdef POSIX + ImageFormat fmt = params[TEXTURE1]->GetTextureValue()->GetImageFormat(); + bool bSRGB; + if ( ( fmt == IMAGE_FORMAT_RGBA16161616F ) || ( fmt == IMAGE_FORMAT_RGBA16161616 ) ) + bSRGB = false; + else + bSRGB = !params[LINEARREAD_TEXTURE1]->IsDefined() || !params[LINEARREAD_TEXTURE1]->GetIntValue(); + LoadTexture( TEXTURE1, bSRGB ? TEXTUREFLAGS_SRGB : 0 ); +#else + LoadTexture( TEXTURE1 ); +#endif // POSIX + } + if ( params[TEXTURE2]->IsDefined() ) + { +#ifdef POSIX + ImageFormat fmt = params[TEXTURE2]->GetTextureValue()->GetImageFormat(); + bool bSRGB; + if ( ( fmt == IMAGE_FORMAT_RGBA16161616F ) || ( fmt == IMAGE_FORMAT_RGBA16161616 ) ) + bSRGB = false; + else + bSRGB = !params[LINEARREAD_TEXTURE2]->IsDefined() || !params[LINEARREAD_TEXTURE2]->GetIntValue(); + LoadTexture( TEXTURE2, bSRGB ? TEXTUREFLAGS_SRGB : 0 ); +#else + LoadTexture( TEXTURE2 ); +#endif // POSIX + } + if ( params[TEXTURE3]->IsDefined() ) + { +#ifdef POSIX + ImageFormat fmt = params[TEXTURE3]->GetTextureValue()->GetImageFormat(); + bool bSRGB; + if ( ( fmt == IMAGE_FORMAT_RGBA16161616F ) || ( fmt == IMAGE_FORMAT_RGBA16161616 ) ) + bSRGB = false; + else + bSRGB = !params[LINEARREAD_TEXTURE3]->IsDefined() || !params[LINEARREAD_TEXTURE3]->GetIntValue(); + LoadTexture( TEXTURE3, bSRGB ? TEXTUREFLAGS_SRGB : 0 ); +#else + LoadTexture( TEXTURE3 ); +#endif // POSIX + } + } + + SHADER_FALLBACK + { + if ( g_pHardwareConfig->GetDXSupportLevel() < 90 ) + { + return "screenspace_general_dx8"; + } + + return 0; + } + + SHADER_DRAW + { + SHADOW_STATE + { + pShaderShadow->EnableDepthWrites( false ); + + if (params[BASETEXTURE]->IsDefined()) + { + 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, !params[LINEARREAD_BASETEXTURE]->IsDefined() || !params[LINEARREAD_BASETEXTURE]->GetIntValue() ); + } + if (params[TEXTURE1]->IsDefined()) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + ITexture *txtr=params[TEXTURE1]->GetTextureValue(); + ImageFormat fmt=txtr->GetImageFormat(); + if ((fmt==IMAGE_FORMAT_RGBA16161616F) || (fmt==IMAGE_FORMAT_RGBA16161616)) + pShaderShadow->EnableSRGBRead(SHADER_SAMPLER1,false); + else + pShaderShadow->EnableSRGBRead(SHADER_SAMPLER1, !params[LINEARREAD_TEXTURE1]->IsDefined() || !params[LINEARREAD_TEXTURE1]->GetIntValue() ); + } + if (params[TEXTURE2]->IsDefined()) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER2, true ); + ITexture *txtr=params[TEXTURE2]->GetTextureValue(); + ImageFormat fmt=txtr->GetImageFormat(); + if ((fmt==IMAGE_FORMAT_RGBA16161616F) || (fmt==IMAGE_FORMAT_RGBA16161616)) + pShaderShadow->EnableSRGBRead(SHADER_SAMPLER2,false); + else + pShaderShadow->EnableSRGBRead(SHADER_SAMPLER2, !params[LINEARREAD_TEXTURE2]->IsDefined() || !params[LINEARREAD_TEXTURE2]->GetIntValue() ); + } + if (params[TEXTURE3]->IsDefined()) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER3, true ); + ITexture *txtr=params[TEXTURE3]->GetTextureValue(); + ImageFormat fmt=txtr->GetImageFormat(); + if ((fmt==IMAGE_FORMAT_RGBA16161616F) || (fmt==IMAGE_FORMAT_RGBA16161616)) + pShaderShadow->EnableSRGBRead(SHADER_SAMPLER3,false); + else + pShaderShadow->EnableSRGBRead(SHADER_SAMPLER3, !params[LINEARREAD_TEXTURE3]->IsDefined() || !params[LINEARREAD_TEXTURE3]->GetIntValue() ); + } + int fmt = VERTEX_POSITION; + + if ( IS_PARAM_DEFINED( X360APPCHOOSER ) && ( params[X360APPCHOOSER]->GetIntValue() ) ) + { + fmt |= VERTEX_COLOR; + EnableAlphaBlending( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA ); + } + pShaderShadow->VertexShaderVertexFormat( fmt, 1, 0, 0 ); + + // maybe convert from linear to gamma on write. + bool srgb_write=true; + if (params[LINEARWRITE]->GetFloatValue()) + srgb_write=false; + pShaderShadow->EnableSRGBWrite( srgb_write ); + + // Pre-cache shaders + DECLARE_STATIC_VERTEX_SHADER( screenspaceeffect_vs20 ); + SET_STATIC_VERTEX_SHADER_COMBO( X360APPCHOOSER, IS_PARAM_DEFINED( X360APPCHOOSER ) ? params[X360APPCHOOSER]->GetIntValue() : 0 ); + vsh_forgot_to_set_static_X360APPCHOOSER = 0; // This is a dirty workaround to the shortcut [= 0] in the fxc + SET_STATIC_VERTEX_SHADER( screenspaceeffect_vs20 ); + + if (params[DISABLE_COLOR_WRITES]->GetIntValue()) + { + pShaderShadow->EnableColorWrites(false); + } +// if (params[ALPHATESTED]->GetFloatValue()) + { + pShaderShadow->EnableAlphaTest(true); + pShaderShadow->AlphaFunc(SHADER_ALPHAFUNC_GREATER,0.0); + } + if ( IS_FLAG_SET(MATERIAL_VAR_ADDITIVE) ) + { + EnableAlphaBlending( SHADER_BLEND_ONE, SHADER_BLEND_ONE ); + } + if ( params[ ALPHA_BLEND_COLOR_OVERLAY ]->GetIntValue() ) + { + // Used for adding L4D-style halos + EnableAlphaBlending( SHADER_BLEND_ONE, SHADER_BLEND_ONE_MINUS_SRC_ALPHA ); + } + if ( params[ ALPHA_BLEND ]->GetIntValue() ) + { + // Used for adding L4D-style halos + EnableAlphaBlending( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA ); + } + + if( params[ COPYALPHA ]->GetIntValue() ) + { + pShaderShadow->EnableBlending( false ); + pShaderShadow->AlphaFunc( SHADER_ALPHAFUNC_ALWAYS, 0.0f ); + } + + if ( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + const char *szPixelShader = params[PIXSHADER]->GetStringValue(); + size_t iLength = Q_strlen( szPixelShader ); + + if( (iLength > 5) && (Q_stricmp( &szPixelShader[iLength - 5], "_ps20" ) == 0) ) //detect if it's trying to load a ps20 shader + { + //replace it with the ps20b shader + char *szNewName = (char *)stackalloc( sizeof( char ) * (iLength + 2) ); + memcpy( szNewName, szPixelShader, sizeof( char ) * iLength ); + szNewName[iLength] = 'b'; + szNewName[iLength + 1] = '\0'; + pShaderShadow->SetPixelShader( szNewName, 0 ); + } + else + { + pShaderShadow->SetPixelShader( params[PIXSHADER]->GetStringValue(), 0 ); + } + } + else + { + pShaderShadow->SetPixelShader( params[PIXSHADER]->GetStringValue(), 0 ); + } + } + + DYNAMIC_STATE + { + // Using c4-c7 to store the pixel sizes of each texture + if (params[BASETEXTURE]->IsDefined()) + { + BindTexture( SHADER_SAMPLER0, BASETEXTURE, -1 ); + + ITexture *pTarget = params[ BASETEXTURE ]->GetTextureValue(); + float vPixelSize[4] = { 1.0f / pTarget->GetActualWidth(), 1.0f / pTarget->GetActualHeight(), 0.0f, 0.0f }; + pShaderAPI->SetPixelShaderConstant( 4, vPixelSize, 1 ); + } + + if (params[TEXTURE1]->IsDefined()) + { + BindTexture( SHADER_SAMPLER1, TEXTURE1, -1 ); + + ITexture *pTarget = params[ TEXTURE1 ]->GetTextureValue(); + float vPixelSize[4] = { 1.0f / pTarget->GetActualWidth(), 1.0f / pTarget->GetActualHeight(), 0.0f, 0.0f }; + pShaderAPI->SetPixelShaderConstant( 5, vPixelSize, 1 ); + } + + if (params[TEXTURE2]->IsDefined()) + { + BindTexture( SHADER_SAMPLER2, TEXTURE2, -1 ); + + ITexture *pTarget = params[ TEXTURE2 ]->GetTextureValue(); + float vPixelSize[4] = { 1.0f / pTarget->GetActualWidth(), 1.0f / pTarget->GetActualHeight(), 0.0f, 0.0f }; + pShaderAPI->SetPixelShaderConstant( 6, vPixelSize, 1 ); + } + + if (params[TEXTURE3]->IsDefined()) + { + BindTexture( SHADER_SAMPLER3, TEXTURE3, -1 ); + + ITexture *pTarget = params[ TEXTURE3 ]->GetTextureValue(); + float vPixelSize[4] = { 1.0f / pTarget->GetActualWidth(), 1.0f / pTarget->GetActualHeight(), 0.0f, 0.0f }; + pShaderAPI->SetPixelShaderConstant( 7, vPixelSize, 1 ); + } + + float c0[] = { + params[C0_X]->GetFloatValue(), + params[C0_Y]->GetFloatValue(), + params[C0_Z]->GetFloatValue(), + params[C0_W]->GetFloatValue(), + params[C1_X]->GetFloatValue(), + params[C1_Y]->GetFloatValue(), + params[C1_Z]->GetFloatValue(), + params[C1_W]->GetFloatValue(), + params[C2_X]->GetFloatValue(), + params[C2_Y]->GetFloatValue(), + params[C2_Z]->GetFloatValue(), + params[C2_W]->GetFloatValue(), + params[C3_X]->GetFloatValue(), + params[C3_Y]->GetFloatValue(), + params[C3_Z]->GetFloatValue(), + params[C3_W]->GetFloatValue() + }; + + // c0-c3 + pShaderAPI->SetPixelShaderConstant( 0, c0, ARRAYSIZE(c0)/4 ); + + float eyePos[4]; + pShaderAPI->GetWorldSpaceCameraPosition( eyePos ); + pShaderAPI->SetPixelShaderConstant( 10, eyePos, 1 ); + + pShaderAPI->SetVertexShaderIndex( 0 ); + pShaderAPI->SetPixelShaderIndex( 0 ); + + DECLARE_DYNAMIC_VERTEX_SHADER( screenspaceeffect_vs20 ); + SET_DYNAMIC_VERTEX_SHADER( screenspaceeffect_vs20 ); + } + Draw(); + } +END_SHADER diff --git a/materialsystem/stdshaders/screenspace_general_dx8.cpp b/materialsystem/stdshaders/screenspace_general_dx8.cpp new file mode 100644 index 0000000..f83cea6 --- /dev/null +++ b/materialsystem/stdshaders/screenspace_general_dx8.cpp @@ -0,0 +1,196 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//=============================================================================// + +#include "BaseVSShader.h" + +#include "screenspaceeffect_vs11.inc" + +DEFINE_FALLBACK_SHADER( screenspace_general, screenspace_general_dx8 ) +BEGIN_VS_SHADER_FLAGS( screenspace_general_dx8, "Help for screenspace_general", SHADER_NOT_EDITABLE ) + BEGIN_SHADER_PARAMS + SHADER_PARAM( C0_X,SHADER_PARAM_TYPE_FLOAT,"0","") + SHADER_PARAM( C0_Y,SHADER_PARAM_TYPE_FLOAT,"0","") + SHADER_PARAM( C0_Z,SHADER_PARAM_TYPE_FLOAT,"0","") + SHADER_PARAM( C0_W,SHADER_PARAM_TYPE_FLOAT,"0","") + SHADER_PARAM( C1_X,SHADER_PARAM_TYPE_FLOAT,"0","") + SHADER_PARAM( C1_Y,SHADER_PARAM_TYPE_FLOAT,"0","") + SHADER_PARAM( C1_Z,SHADER_PARAM_TYPE_FLOAT,"0","") + SHADER_PARAM( C1_W,SHADER_PARAM_TYPE_FLOAT,"0","") + SHADER_PARAM( C2_X,SHADER_PARAM_TYPE_FLOAT,"0","") + SHADER_PARAM( C2_Y,SHADER_PARAM_TYPE_FLOAT,"0","") + SHADER_PARAM( C2_Z,SHADER_PARAM_TYPE_FLOAT,"0","") + SHADER_PARAM( C2_W,SHADER_PARAM_TYPE_FLOAT,"0","") + SHADER_PARAM( C3_X,SHADER_PARAM_TYPE_FLOAT,"0","") + SHADER_PARAM( C3_Y,SHADER_PARAM_TYPE_FLOAT,"0","") + SHADER_PARAM( C3_Z,SHADER_PARAM_TYPE_FLOAT,"0","") + SHADER_PARAM( C3_W,SHADER_PARAM_TYPE_FLOAT,"0","") + SHADER_PARAM( PIXSHADER, SHADER_PARAM_TYPE_STRING, "", "Name of the pixel shader to use" ) + SHADER_PARAM( DISABLE_COLOR_WRITES,SHADER_PARAM_TYPE_INTEGER,"0","") + SHADER_PARAM( ALPHATESTED,SHADER_PARAM_TYPE_FLOAT,"0","") + SHADER_PARAM( TEXTURE1, SHADER_PARAM_TYPE_TEXTURE, "", "" ) + SHADER_PARAM( TEXTURE2, SHADER_PARAM_TYPE_TEXTURE, "", "" ) + SHADER_PARAM( TEXTURE3, SHADER_PARAM_TYPE_TEXTURE, "", "" ) + SHADER_PARAM( LINEARREAD_BASETEXTURE, SHADER_PARAM_TYPE_INTEGER, "0", "" ) + SHADER_PARAM( LINEARREAD_TEXTURE1, SHADER_PARAM_TYPE_INTEGER, "0", "" ) + SHADER_PARAM( LINEARREAD_TEXTURE2, SHADER_PARAM_TYPE_INTEGER, "0", "" ) + SHADER_PARAM( LINEARREAD_TEXTURE3, SHADER_PARAM_TYPE_INTEGER, "0", "" ) + SHADER_PARAM( LINEARWRITE,SHADER_PARAM_TYPE_INTEGER,"0","") + END_SHADER_PARAMS + + SHADER_INIT + { + if ( params[BASETEXTURE]->IsDefined() ) + { + LoadTexture( BASETEXTURE ); + } + if ( params[TEXTURE1]->IsDefined() ) + { + LoadTexture( TEXTURE1 ); + } + if ( params[TEXTURE2]->IsDefined() ) + { + LoadTexture( TEXTURE2 ); + } + if ( params[TEXTURE3]->IsDefined() ) + { + LoadTexture( TEXTURE3 ); + } + } + + SHADER_FALLBACK + { + if ( g_pHardwareConfig->GetDXSupportLevel() < 80 ) + { + return "Wireframe"; + } + + return 0; + } + + SHADER_DRAW + { + SHADOW_STATE + { + pShaderShadow->EnableDepthWrites( false ); + + if (params[BASETEXTURE]->IsDefined()) + { + 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, !params[LINEARREAD_BASETEXTURE]->IsDefined() || !params[LINEARREAD_BASETEXTURE]->GetIntValue() ); + } + if (params[TEXTURE1]->IsDefined()) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + ITexture *txtr=params[TEXTURE1]->GetTextureValue(); + ImageFormat fmt=txtr->GetImageFormat(); + if ((fmt==IMAGE_FORMAT_RGBA16161616F) || (fmt==IMAGE_FORMAT_RGBA16161616)) + pShaderShadow->EnableSRGBRead(SHADER_SAMPLER1,false); + else + pShaderShadow->EnableSRGBRead(SHADER_SAMPLER1, !params[LINEARREAD_TEXTURE1]->IsDefined() || !params[LINEARREAD_TEXTURE1]->GetIntValue() ); + } + if (params[TEXTURE2]->IsDefined()) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER2, true ); + ITexture *txtr=params[TEXTURE2]->GetTextureValue(); + ImageFormat fmt=txtr->GetImageFormat(); + if ((fmt==IMAGE_FORMAT_RGBA16161616F) || (fmt==IMAGE_FORMAT_RGBA16161616)) + pShaderShadow->EnableSRGBRead(SHADER_SAMPLER2,false); + else + pShaderShadow->EnableSRGBRead(SHADER_SAMPLER2, !params[LINEARREAD_TEXTURE2]->IsDefined() || !params[LINEARREAD_TEXTURE2]->GetIntValue() ); + } + if (params[TEXTURE3]->IsDefined()) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER3, true ); + ITexture *txtr=params[TEXTURE3]->GetTextureValue(); + ImageFormat fmt=txtr->GetImageFormat(); + if ((fmt==IMAGE_FORMAT_RGBA16161616F) || (fmt==IMAGE_FORMAT_RGBA16161616)) + pShaderShadow->EnableSRGBRead(SHADER_SAMPLER3,false); + else + pShaderShadow->EnableSRGBRead(SHADER_SAMPLER3, !params[LINEARREAD_TEXTURE3]->IsDefined() || !params[LINEARREAD_TEXTURE3]->GetIntValue() ); + } + int fmt = VERTEX_POSITION; + pShaderShadow->VertexShaderVertexFormat( fmt, 1, 0, 0 ); + + // maybe convert from linear to gamma on write. + bool srgb_write=true; + if (params[LINEARWRITE]->GetFloatValue()) + srgb_write=false; + pShaderShadow->EnableSRGBWrite( srgb_write ); + + // Pre-cache shaders + DECLARE_STATIC_VERTEX_SHADER( screenspaceeffect_vs11 ); + SET_STATIC_VERTEX_SHADER( screenspaceeffect_vs11 ); + + if (params[DISABLE_COLOR_WRITES]->GetIntValue()) + { + pShaderShadow->EnableColorWrites(false); + } +// if (params[ALPHATESTED]->GetFloatValue()) + { + pShaderShadow->EnableAlphaTest(true); + pShaderShadow->AlphaFunc(SHADER_ALPHAFUNC_GREATER,0.0); + } + if ( IS_FLAG_SET(MATERIAL_VAR_ADDITIVE) ) + { + EnableAlphaBlending( SHADER_BLEND_ONE, SHADER_BLEND_ONE ); + } + + pShaderShadow->SetPixelShader( params[PIXSHADER]->GetStringValue(), 0 ); + } + + DYNAMIC_STATE + { + if (params[BASETEXTURE]->IsDefined()) + { + BindTexture( SHADER_SAMPLER0, BASETEXTURE, -1 ); + } + if (params[TEXTURE1]->IsDefined()) + { + BindTexture( SHADER_SAMPLER1, TEXTURE1, -1 ); + } + if (params[TEXTURE2]->IsDefined()) + { + BindTexture( SHADER_SAMPLER2, TEXTURE2, -1 ); + } + if (params[TEXTURE3]->IsDefined()) + { + BindTexture( SHADER_SAMPLER3, TEXTURE3, -1 ); + } + float c0[]={ + params[C0_X]->GetFloatValue(), + params[C0_Y]->GetFloatValue(), + params[C0_Z]->GetFloatValue(), + params[C0_W]->GetFloatValue(), + params[C1_X]->GetFloatValue(), + params[C1_Y]->GetFloatValue(), + params[C1_Z]->GetFloatValue(), + params[C1_W]->GetFloatValue(), + params[C2_X]->GetFloatValue(), + params[C2_Y]->GetFloatValue(), + params[C2_Z]->GetFloatValue(), + params[C2_W]->GetFloatValue(), + params[C3_X]->GetFloatValue(), + params[C3_Y]->GetFloatValue(), + params[C3_Z]->GetFloatValue(), + params[C3_W]->GetFloatValue() + }; + + pShaderAPI->SetPixelShaderConstant( 0, c0, ARRAYSIZE(c0)/4 ); + pShaderAPI->SetVertexShaderIndex( 0 ); + pShaderAPI->SetPixelShaderIndex( 0 ); + + DECLARE_DYNAMIC_VERTEX_SHADER( screenspaceeffect_vs11 ); + SET_DYNAMIC_VERTEX_SHADER( screenspaceeffect_vs11 ); + } + Draw(); + } +END_SHADER diff --git a/materialsystem/stdshaders/screenspaceeffect_vs11.fxc b/materialsystem/stdshaders/screenspaceeffect_vs11.fxc new file mode 100644 index 0000000..bc52878 --- /dev/null +++ b/materialsystem/stdshaders/screenspaceeffect_vs11.fxc @@ -0,0 +1,26 @@ +#include "common_vs_fxc.h" + +struct VS_INPUT +{ + float3 vPos : POSITION; + float2 vBaseTexCoord : TEXCOORD0; +}; + +struct VS_OUTPUT +{ + float4 projPos : POSITION; + float2 baseTexCoord : TEXCOORD0; + float2 baseTexCoord2 : TEXCOORD1; +}; + +VS_OUTPUT main( const VS_INPUT v ) +{ + VS_OUTPUT o = ( VS_OUTPUT )0; + + o.projPos = float4( v.vPos, 1.0f ); + o.baseTexCoord = v.vBaseTexCoord; + o.baseTexCoord2 = v.vBaseTexCoord; + return o; +} + + diff --git a/materialsystem/stdshaders/screenspaceeffect_vs20.fxc b/materialsystem/stdshaders/screenspaceeffect_vs20.fxc new file mode 100644 index 0000000..96cb899 --- /dev/null +++ b/materialsystem/stdshaders/screenspaceeffect_vs20.fxc @@ -0,0 +1,47 @@ +//========= Copyright © 1996-2006, Valve Corporation, All rights reserved. ============// + +// STATIC: "X360APPCHOOSER" "0..1" [= 0] + +#include "common_vs_fxc.h" + +struct VS_INPUT +{ + float3 vPos : POSITION; + float2 vBaseTexCoord : TEXCOORD0; + + #if X360APPCHOOSER + float4 vColor : COLOR0; + #endif +}; + +struct VS_OUTPUT +{ + float4 projPos : POSITION; + float2 baseTexCoord : TEXCOORD0; + float2 ZeroTexCoord : TEXCOORD1; + float2 bloomTexCoord : TEXCOORD2; + + #if X360APPCHOOSER + float4 vColor : TEXCOORD3; + #endif +}; + +float4 Texel_Sizes : register (SHADER_SPECIFIC_CONST_0); + +VS_OUTPUT main( const VS_INPUT v ) +{ + VS_OUTPUT o = ( VS_OUTPUT )0; + + o.projPos = float4( v.vPos, 1.0f ); + o.baseTexCoord = v.vBaseTexCoord; + o.ZeroTexCoord=float2(0,0); + o.bloomTexCoord.x=v.vBaseTexCoord.x+Texel_Sizes.z; + o.bloomTexCoord.y=v.vBaseTexCoord.y+Texel_Sizes.w; + + #if X360APPCHOOSER + o.vColor.rgba = v.vColor.rgba; + o.projPos.xyzw = mul( float4( v.vPos.xyz, 1.0f ), cModelViewProj ); + #endif + + return o; +} diff --git a/materialsystem/stdshaders/sfm_blurfilterx.cpp b/materialsystem/stdshaders/sfm_blurfilterx.cpp new file mode 100644 index 0000000..4e54691 --- /dev/null +++ b/materialsystem/stdshaders/sfm_blurfilterx.cpp @@ -0,0 +1,121 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//===========================================================================// + +#include "BaseVSShader.h" +#include "BlurFilter_vs20.inc" +#include "BlurFilter_ps20.inc" +#include "BlurFilter_ps20b.inc" + +BEGIN_VS_SHADER_FLAGS( sfm_blurfilterx_shader, "Help for BlurFilterX", SHADER_NOT_EDITABLE ) + BEGIN_SHADER_PARAMS + END_SHADER_PARAMS + + SHADER_INIT + { + if( params[BASETEXTURE]->IsDefined() ) + { + LoadTexture( BASETEXTURE ); + } + } + + SHADER_FALLBACK + { + // Requires DX9 + above + if ( g_pHardwareConfig->GetDXSupportLevel() < 90 ) + { + Assert( 0 ); + return "Wireframe"; + } + return 0; + } + + SHADER_DRAW + { + SHADOW_STATE + { + pShaderShadow->EnableDepthWrites( false ); + pShaderShadow->EnableAlphaWrites( true ); + + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + int fmt = VERTEX_POSITION; + pShaderShadow->VertexShaderVertexFormat( fmt, 1, 0, 0 ); + + // Pre-cache shaders + blurfilter_vs20_Static_Index vshIndex; + pShaderShadow->SetVertexShader( "BlurFilter_vs20", vshIndex.GetIndex() ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_STATIC_PIXEL_SHADER( blurfilter_ps20b ); +#ifndef _X360 + SET_STATIC_PIXEL_SHADER_COMBO( APPROX_SRGB_ADAPTER, 0 ); +#endif + SET_STATIC_PIXEL_SHADER( blurfilter_ps20b ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( blurfilter_ps20 ); + SET_STATIC_PIXEL_SHADER( blurfilter_ps20 ); + } + + + if ( IS_FLAG_SET( MATERIAL_VAR_ADDITIVE ) ) + EnableAlphaBlending( SHADER_BLEND_ONE, SHADER_BLEND_ONE ); + } + + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER0, BASETEXTURE, -1 ); + + ITexture *src_texture=params[BASETEXTURE]->GetTextureValue(); + int width = src_texture->GetActualWidth(); + + float v[4]; + + // The temp buffer is 1/4 back buffer size + float dX = 1.0f / width; + + // Tap offsets + v[0] = 1.3366f * dX; + v[1] = 0.0f; + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, v, 1 ); + v[0] = 3.4295f * dX; + v[1] = 0.0f; + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_1, v, 1 ); + v[0] = 5.4264f * dX; + v[1] = 0.0f; + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_2, v, 1 ); + + v[0] = 7.4359f * dX; + v[1] = 0.0f; + pShaderAPI->SetPixelShaderConstant( 0, v, 1 ); + v[0] = 9.4436f * dX; + v[1] = 0.0f; + pShaderAPI->SetPixelShaderConstant( 1, v, 1 ); + v[0] = 11.4401f * dX; + v[1] = 0.0f; + pShaderAPI->SetPixelShaderConstant( 2, v, 1 ); + + v[0] = v[1] = v[2] = v [3]=1.0; + pShaderAPI->SetPixelShaderConstant( 3, v, 1 ); + + pShaderAPI->SetVertexShaderIndex( 0 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_DYNAMIC_PIXEL_SHADER( blurfilter_ps20b ); + SET_DYNAMIC_PIXEL_SHADER( blurfilter_ps20b ); + } + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( blurfilter_ps20 ); + SET_DYNAMIC_PIXEL_SHADER( blurfilter_ps20 ); + } + } + Draw(); + } +END_SHADER diff --git a/materialsystem/stdshaders/sfm_blurfiltery.cpp b/materialsystem/stdshaders/sfm_blurfiltery.cpp new file mode 100644 index 0000000..1a7f7e7 --- /dev/null +++ b/materialsystem/stdshaders/sfm_blurfiltery.cpp @@ -0,0 +1,123 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//===========================================================================// + +#include "BaseVSShader.h" +#include "BlurFilter_vs20.inc" +#include "BlurFilter_ps20.inc" +#include "BlurFilter_ps20b.inc" + + +BEGIN_VS_SHADER_FLAGS( sfm_blurfiltery_shader, "Help for BlurFilterY", SHADER_NOT_EDITABLE ) + BEGIN_SHADER_PARAMS + END_SHADER_PARAMS + + SHADER_INIT + { + if( params[BASETEXTURE]->IsDefined() ) + { + LoadTexture( BASETEXTURE ); + } + } + + SHADER_FALLBACK + { + // Requires DX9 + above + if ( g_pHardwareConfig->GetDXSupportLevel() < 90 ) + { + Assert( 0 ); + return "Wireframe"; + } + return 0; + } + + SHADER_DRAW + { + SHADOW_STATE + { + pShaderShadow->EnableDepthWrites( false ); + pShaderShadow->EnableAlphaWrites( true ); + + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + int fmt = VERTEX_POSITION; + pShaderShadow->VertexShaderVertexFormat( fmt, 1, 0, 0 ); + + // Pre-cache shaders + blurfilter_vs20_Static_Index vshIndex; + pShaderShadow->SetVertexShader( "BlurFilter_vs20", vshIndex.GetIndex() ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_STATIC_PIXEL_SHADER( blurfilter_ps20b ); +#ifndef _X360 + SET_STATIC_PIXEL_SHADER_COMBO( APPROX_SRGB_ADAPTER, 0 ); +#endif + SET_STATIC_PIXEL_SHADER( blurfilter_ps20b ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( blurfilter_ps20 ); + SET_STATIC_PIXEL_SHADER( blurfilter_ps20 ); + } + + if ( IS_FLAG_SET( MATERIAL_VAR_ADDITIVE ) ) + EnableAlphaBlending( SHADER_BLEND_ONE, SHADER_BLEND_ONE ); + } + + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER0, BASETEXTURE, -1 ); + + ITexture *src_texture=params[BASETEXTURE]->GetTextureValue(); + int height = src_texture->GetActualHeight(); + + float v[4]; + + // The temp buffer is 1/4 back buffer size + float dY = 1.0f / height; + + // Tap offsets + v[0] = 0.0f; + v[1] = 1.3366f * dY; + v[2] = 0; + v[3] = 0; + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, v, 1 ); + v[0] = 0.0f; + v[1] = 3.4295f * dY; + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_1, v, 1 ); + v[0] = 0.0f; + v[1] = 5.4264f * dY; + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_2, v, 1 ); + + v[0] = 0.0f; + v[1] = 7.4359f * dY; + pShaderAPI->SetPixelShaderConstant( 0, v, 1 ); + v[0] = 0.0f; + v[1] = 9.4436f * dY; + pShaderAPI->SetPixelShaderConstant( 1, v, 1 ); + v[0] = 0.0f; + v[1] = 11.4401f * dY; + pShaderAPI->SetPixelShaderConstant( 2, v, 1 ); + + v[0] = v[1] = v[2] = v [3]=1.0; + pShaderAPI->SetPixelShaderConstant( 3, v, 1 ); + + pShaderAPI->SetVertexShaderIndex( 0 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_DYNAMIC_PIXEL_SHADER( blurfilter_ps20b ); + SET_DYNAMIC_PIXEL_SHADER( blurfilter_ps20b ); + } + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( blurfilter_ps20 ); + SET_DYNAMIC_PIXEL_SHADER( blurfilter_ps20 ); + } + } + Draw(); + } +END_SHADER diff --git a/materialsystem/stdshaders/sfm_combine_vs20.fxc b/materialsystem/stdshaders/sfm_combine_vs20.fxc new file mode 100644 index 0000000..0ada148 --- /dev/null +++ b/materialsystem/stdshaders/sfm_combine_vs20.fxc @@ -0,0 +1,25 @@ +#include "common_vs_fxc.h" + +struct VS_INPUT +{ + float3 vPos : POSITION; + float2 vBaseTexCoord : TEXCOORD0; + float2 vBloomTexCoord : TEXCOORD1; +}; + +struct VS_OUTPUT +{ + float4 projPos : POSITION; + float2 baseTexCoord : TEXCOORD0; + float2 bloomTexCoord : TEXCOORD1; +}; + +VS_OUTPUT main( const VS_INPUT v ) +{ + VS_OUTPUT o = ( VS_OUTPUT )0; + + o.projPos = float4( v.vPos, 1.0f ); // Just pass these iterators through... + o.baseTexCoord = v.vBaseTexCoord; + o.bloomTexCoord = v.vBloomTexCoord; + return o; +} diff --git a/materialsystem/stdshaders/sfm_downsample.cpp b/materialsystem/stdshaders/sfm_downsample.cpp new file mode 100644 index 0000000..0e672d8 --- /dev/null +++ b/materialsystem/stdshaders/sfm_downsample.cpp @@ -0,0 +1,103 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//===========================================================================// + +#include "BaseVSShader.h" +#include "common_hlsl_cpp_consts.h" + +#include "Downsample_ps20.inc" +#include "Downsample_ps20b.inc" + +BEGIN_VS_SHADER_FLAGS( sfm_downsample_shader, "Help for Downsample", SHADER_NOT_EDITABLE ) + BEGIN_SHADER_PARAMS + END_SHADER_PARAMS + + SHADER_INIT + { + LoadTexture( BASETEXTURE ); + } + + SHADER_FALLBACK + { + // Requires DX9 + above + if (!g_pHardwareConfig->SupportsVertexAndPixelShaders()) + { + Assert( 0 ); + return "Wireframe"; + } + return 0; + } + + SHADER_DRAW + { + SHADOW_STATE + { + pShaderShadow->EnableDepthWrites( false ); + pShaderShadow->EnableAlphaWrites( true ); + + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + int fmt = VERTEX_POSITION; + pShaderShadow->VertexShaderVertexFormat( fmt, 1, 0, 0 ); + + pShaderShadow->SetVertexShader( "downsample_vs20", 0 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_STATIC_PIXEL_SHADER( downsample_ps20b ); + SET_STATIC_PIXEL_SHADER( downsample_ps20b ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( downsample_ps20 ); + SET_STATIC_PIXEL_SHADER( downsample_ps20 ); + } + } + + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER0, BASETEXTURE, -1 ); + + ITexture *src_texture=params[BASETEXTURE]->GetTextureValue(); + int width = src_texture->GetActualWidth(); + int height = src_texture->GetActualHeight(); + + float v[4]; + float dX = 1.0f / width; + float dY = 1.0f / height; + + v[0] = -dX; + v[1] = -dY; + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, v, 1 ); + v[0] = -dX; + v[1] = dY; + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_1, v, 1 ); + v[0] = dX; + v[1] = -dY; + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_2, v, 1 ); + v[0] = dX; + v[1] = dY; + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_3, v, 1 ); + + // Setup luminance threshold (all values are scaled down by max luminance) +// v[0] = 1.0f / MAX_HDR_OVERBRIGHT; + v[0] = 0.0f; + pShaderAPI->SetPixelShaderConstant( 0, v, 1 ); + + pShaderAPI->SetVertexShaderIndex( 0 ); + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_DYNAMIC_PIXEL_SHADER( downsample_ps20b ); + SET_DYNAMIC_PIXEL_SHADER( downsample_ps20b ); + } + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( downsample_ps20 ); + SET_DYNAMIC_PIXEL_SHADER( downsample_ps20 ); + } + } + Draw(); + } +END_SHADER diff --git a/materialsystem/stdshaders/sfm_integercombine.cpp b/materialsystem/stdshaders/sfm_integercombine.cpp new file mode 100644 index 0000000..1f330bb --- /dev/null +++ b/materialsystem/stdshaders/sfm_integercombine.cpp @@ -0,0 +1,97 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//===========================================================================// + +#include "BaseVSShader.h" +#include "sfm_combine_vs20.inc" +#include "sfm_integercombine_ps20.inc" +#include "sfm_integercombine_ps20b.inc" + +BEGIN_VS_SHADER_FLAGS( sfm_integercombine_shader, "Help for SFM integer HDR combine pass", SHADER_NOT_EDITABLE ) + BEGIN_SHADER_PARAMS + // Original full resolution texture + SHADER_PARAM( ORIGINALTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "" ) + + // Blurred quarter-resolution texture + SHADER_PARAM( BLURREDTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "" ) + + // How much bloom gets added in + SHADER_PARAM( BLOOMAMOUNT, SHADER_PARAM_TYPE_VEC4, "", "" ) + + END_SHADER_PARAMS + + SHADER_INIT + { + LoadTexture( ORIGINALTEXTURE ); + LoadTexture( BLURREDTEXTURE ); + } + + SHADER_FALLBACK + { + // Requires DX9 + above + if ( g_pHardwareConfig->GetDXSupportLevel() < 90 ) + { + Assert( 0 ); + return "Wireframe"; + } + return 0; + } + + SHADER_DRAW + { + SHADOW_STATE + { + pShaderShadow->EnableDepthWrites( false ); + pShaderShadow->EnableDepthTest( false ); + pShaderShadow->EnableAlphaWrites( false ); + pShaderShadow->EnableBlending( false ); + pShaderShadow->EnableCulling( false ); + + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + + int fmt = VERTEX_POSITION; + pShaderShadow->VertexShaderVertexFormat( fmt, 2, 0, 0 ); // Two texture coordinates (first for high res, second for low res) + + DECLARE_STATIC_VERTEX_SHADER( sfm_combine_vs20 ); + SET_STATIC_VERTEX_SHADER( sfm_combine_vs20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_STATIC_PIXEL_SHADER( sfm_integercombine_ps20b ); + SET_STATIC_PIXEL_SHADER( sfm_integercombine_ps20b ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( sfm_integercombine_ps20 ); + SET_STATIC_PIXEL_SHADER( sfm_integercombine_ps20 ); + } + } + + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER0, ORIGINALTEXTURE, -1 ); + BindTexture( SHADER_SAMPLER1, BLURREDTEXTURE, -1 ); + + SetPixelShaderConstant( 0, BLOOMAMOUNT ); + + DECLARE_DYNAMIC_VERTEX_SHADER( sfm_combine_vs20 ); + SET_DYNAMIC_VERTEX_SHADER( sfm_combine_vs20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_DYNAMIC_PIXEL_SHADER( sfm_integercombine_ps20b ); + SET_DYNAMIC_PIXEL_SHADER( sfm_integercombine_ps20b ); + } + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( sfm_integercombine_ps20 ); + SET_DYNAMIC_PIXEL_SHADER( sfm_integercombine_ps20 ); + } + } + Draw(); + } +END_SHADER diff --git a/materialsystem/stdshaders/sfm_integercombine_ps2x.fxc b/materialsystem/stdshaders/sfm_integercombine_ps2x.fxc new file mode 100644 index 0000000..54d0584 --- /dev/null +++ b/materialsystem/stdshaders/sfm_integercombine_ps2x.fxc @@ -0,0 +1,27 @@ +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX] + +#define HDRTYPE HDR_TYPE_NONE +#include "common_ps_fxc.h" + +sampler TexSampler0 : register( s0 ); +sampler TexSampler1 : register( s1 ); + +struct PS_INPUT +{ + float2 tc0 : TEXCOORD0; + float2 tc1 : TEXCOORD1; +}; + +const float4 bloomamount : register( c0 ); + +float4 main( PS_INPUT i ) : COLOR +{ + // Just sample the input textures + float4 c0 = tex2D( TexSampler0, i.tc0 ); + float4 c1 = tex2D( TexSampler1, i.tc1 ); + + // Add in bloom and return + return FinalOutput( c0 + bloomamount.xxxx * c1, 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE ); +} + diff --git a/materialsystem/stdshaders/shader_constant_register_map.h b/materialsystem/stdshaders/shader_constant_register_map.h new file mode 100644 index 0000000..ef1d9df --- /dev/null +++ b/materialsystem/stdshaders/shader_constant_register_map.h @@ -0,0 +1,81 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: Provide convenient mapping for shader constants +// +// $NoKeywords: $ +//============================================================================= + +#ifndef C_CODE_HACK +#include "common_vertexlitgeneric_dx9.h" +#endif + +#define PSREG_SELFILLUMTINT PSREG_CONSTANT_00 +#define PSREG_DIFFUSE_MODULATION PSREG_CONSTANT_01 +#define PSREG_ENVMAP_TINT__SHADOW_TWEAKS PSREG_CONSTANT_02 +#define PSREG_SELFILLUM_SCALE_BIAS_EXP PSREG_CONSTANT_03 +#define PSREG_AMBIENT_CUBE PSREG_CONSTANT_04 +// PSREG_AMBIENT_CUBE PSREG_CONSTANT_05 +// PSREG_AMBIENT_CUBE PSREG_CONSTANT_06 +// PSREG_AMBIENT_CUBE PSREG_CONSTANT_07 +// PSREG_AMBIENT_CUBE PSREG_CONSTANT_08 +// PSREG_AMBIENT_CUBE PSREG_CONSTANT_09 +#define PSREG_ENVMAP_FRESNEL__SELFILLUMMASK PSREG_CONSTANT_10 +#define PSREG_EYEPOS_SPEC_EXPONENT PSREG_CONSTANT_11 +#define PSREG_FOG_PARAMS PSREG_CONSTANT_12 +#define PSREG_FLASHLIGHT_ATTENUATION PSREG_CONSTANT_13 +#define PSREG_FLASHLIGHT_POSITION_RIM_BOOST PSREG_CONSTANT_14 +#define PSREG_FLASHLIGHT_TO_WORLD_TEXTURE PSREG_CONSTANT_15 +// PSREG_FLASHLIGHT_TO_WORLD_TEXTURE PSREG_CONSTANT_16 +// PSREG_FLASHLIGHT_TO_WORLD_TEXTURE PSREG_CONSTANT_17 +// PSREG_FLASHLIGHT_TO_WORLD_TEXTURE PSREG_CONSTANT_18 +#define PSREG_FRESNEL_SPEC_PARAMS PSREG_CONSTANT_19 +#define PSREG_LIGHT_INFO_ARRAY PSREG_CONSTANT_20 +// PSREG_LIGHT_INFO_ARRAY PSREG_CONSTANT_21 +// PSREG_LIGHT_INFO_ARRAY PSREG_CONSTANT_22 +// PSREG_LIGHT_INFO_ARRAY PSREG_CONSTANT_23 +// PSREG_LIGHT_INFO_ARRAY PSREG_CONSTANT_24 +// PSREG_LIGHT_INFO_ARRAY PSREG_CONSTANT_25 +#define PSREG_SPEC_RIM_PARAMS PSREG_CONSTANT_26 +// #define **free** PSREG_CONSTANT_27 //actually using this often blows constant limits, since literals have to get stuffed somewhere... +#define PSREG_FLASHLIGHT_COLOR PSREG_CONSTANT_28 +#define PSREG_LINEAR_FOG_COLOR PSREG_CONSTANT_29 +#define PSREG_LIGHT_SCALE PSREG_CONSTANT_30 +#define PSREG_FLASHLIGHT_SCREEN_SCALE PSREG_CONSTANT_31 +// --- End of ps_2_0 and ps_2_b constants --- + + +#ifndef C_CODE_HACK +//for fxc code, map the constants to register names. +#define PSREG_CONSTANT_00 c0 +#define PSREG_CONSTANT_01 c1 +#define PSREG_CONSTANT_02 c2 +#define PSREG_CONSTANT_03 c3 +#define PSREG_CONSTANT_04 c4 +#define PSREG_CONSTANT_05 c5 +#define PSREG_CONSTANT_06 c6 +#define PSREG_CONSTANT_07 c7 +#define PSREG_CONSTANT_08 c8 +#define PSREG_CONSTANT_09 c9 +#define PSREG_CONSTANT_10 c10 +#define PSREG_CONSTANT_11 c11 +#define PSREG_CONSTANT_12 c12 +#define PSREG_CONSTANT_13 c13 +#define PSREG_CONSTANT_14 c14 +#define PSREG_CONSTANT_15 c15 +#define PSREG_CONSTANT_16 c16 +#define PSREG_CONSTANT_17 c17 +#define PSREG_CONSTANT_18 c18 +#define PSREG_CONSTANT_19 c19 +#define PSREG_CONSTANT_20 c20 +#define PSREG_CONSTANT_21 c21 +#define PSREG_CONSTANT_22 c22 +#define PSREG_CONSTANT_23 c23 +#define PSREG_CONSTANT_24 c24 +#define PSREG_CONSTANT_25 c25 +#define PSREG_CONSTANT_26 c26 +#define PSREG_CONSTANT_27 c27 +#define PSREG_CONSTANT_28 c28 +#define PSREG_CONSTANT_29 c29 +#define PSREG_CONSTANT_30 c30 +#define PSREG_CONSTANT_31 c31 +#endif diff --git a/materialsystem/stdshaders/shadow.cpp b/materialsystem/stdshaders/shadow.cpp new file mode 100644 index 0000000..17318a3 --- /dev/null +++ b/materialsystem/stdshaders/shadow.cpp @@ -0,0 +1,138 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $Header: $ +// $NoKeywords: $ +//=============================================================================// + +#include "BaseVSShader.h" + +#include "shadow_ps20.inc" +#include "shadow_ps20b.inc" +#include "shadow_vs20.inc" + +BEGIN_VS_SHADER_FLAGS( Shadow, "Help for Shadow", SHADER_NOT_EDITABLE ) + + BEGIN_SHADER_PARAMS + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + /* + The alpha blending state either must be: + + Src Color * Dst Color + Dst Color * 0 + (src color = C*A + 1-A) + + or + + // Can't be this, doesn't work with fog + Src Color * Dst Color + Dst Color * (1-Src Alpha) + (src color = C * A, Src Alpha = A) + */ + } + + SHADER_FALLBACK + { + if ( g_pHardwareConfig->GetDXSupportLevel() < 90 ) + { + return "Shadow_DX8"; + } + return 0; + } + + SHADER_INIT + { + LoadTexture( BASETEXTURE, TEXTUREFLAGS_SRGB ); + } + + SHADER_DRAW + { + SHADOW_STATE + { + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, true ); + + + // NOTE: This is deliberately this way round (instead of "DST_COLOR, ZERO"), + // since these two permutations produce *different* values on 360!! + // This was causing undue darkening of the framebuffer by these + // shadows, which was highly noticeable in very dark areas: + EnableAlphaBlending( SHADER_BLEND_ZERO, SHADER_BLEND_SRC_COLOR ); + + + unsigned int flags = VERTEX_POSITION | VERTEX_COLOR; + int numTexCoords = 1; + pShaderShadow->VertexShaderVertexFormat( flags, numTexCoords, 0, 0 ); + + DECLARE_STATIC_VERTEX_SHADER( shadow_vs20 ); + SET_STATIC_VERTEX_SHADER( shadow_vs20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_STATIC_PIXEL_SHADER( shadow_ps20b ); + SET_STATIC_PIXEL_SHADER( shadow_ps20b ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( shadow_ps20 ); + SET_STATIC_PIXEL_SHADER( shadow_ps20 ); + } + + pShaderShadow->EnableSRGBWrite( true ); + + // We need to fog to *white* regardless of overbrighting... + FogToWhite(); + } + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME ); + + SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, BASETEXTURETRANSFORM ); + SetPixelShaderConstantGammaToLinear( 1, COLOR ); + + // Get texture dimensions... + int nWidth = 16; + int nHeight = 16; + ITexture *pTexture = params[BASETEXTURE]->GetTextureValue(); + if (pTexture) + { + nWidth = pTexture->GetActualWidth(); + nHeight = pTexture->GetActualHeight(); + } + + Vector4D vecJitter( 1.0 / nWidth, 1.0 / nHeight, 0.0, 0.0 ); + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_2, vecJitter.Base() ); + + vecJitter.y *= -1.0f; + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_3, vecJitter.Base() ); + + MaterialFogMode_t fogType = pShaderAPI->GetSceneFogMode(); + int fogIndex = ( fogType == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ) ? 1 : 0; + + DECLARE_DYNAMIC_VERTEX_SHADER( shadow_vs20 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( DOWATERFOG, fogIndex ); + SET_DYNAMIC_VERTEX_SHADER( shadow_vs20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_DYNAMIC_PIXEL_SHADER( shadow_ps20b ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + SET_DYNAMIC_PIXEL_SHADER( shadow_ps20b ); + } + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( shadow_ps20 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + SET_DYNAMIC_PIXEL_SHADER( shadow_ps20 ); + } + + float eyePos[4]; + pShaderAPI->GetWorldSpaceCameraPosition( eyePos ); + pShaderAPI->SetPixelShaderConstant( 2, eyePos, 1 ); + pShaderAPI->SetPixelShaderFogParams( 3 ); + } + Draw( ); + } +END_SHADER diff --git a/materialsystem/stdshaders/shadow_dx6.cpp b/materialsystem/stdshaders/shadow_dx6.cpp new file mode 100644 index 0000000..a867ef9 --- /dev/null +++ b/materialsystem/stdshaders/shadow_dx6.cpp @@ -0,0 +1,90 @@ +//========= 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" + +DEFINE_FALLBACK_SHADER( Shadow, Shadow_DX6 ) + +BEGIN_SHADER_FLAGS( Shadow_DX6, "Help for Shadow_DX6", SHADER_NOT_EDITABLE ) + + BEGIN_SHADER_PARAMS + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + // FIXME: Need fallback for dx5, don't fade out shadows, just pop them out + + /* + The alpha blending state either must be: + + Src Color * Dst Color + Dst Color * 0 + (src color = C*A + 1-A) + +or + + // Can't be this, doesn't work with fog + Src Color * Dst Color + Dst Color * (1-Src Alpha) + (src color = C * A, Src Alpha = A) + + */ + } + + SHADER_INIT + { + if (params[BASETEXTURE]->IsDefined()) + LoadTexture( BASETEXTURE ); + } + + SHADER_DRAW + { + SHADOW_STATE + { + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + + // To accomplish shadow fading, subtract vertex alpha from texture alpha + // color channel isn't used... + pShaderShadow->EnableCustomPixelPipe( true ); + pShaderShadow->CustomTextureStages( 2 ); + pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE0, + SHADER_TEXCHANNEL_COLOR, SHADER_TEXOP_SELECTARG1, + SHADER_TEXARG_TEXTURE, SHADER_TEXARG_VERTEXCOLOR ); + pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE0, + SHADER_TEXCHANNEL_ALPHA, SHADER_TEXOP_SUBTRACT, + SHADER_TEXARG_TEXTURE, SHADER_TEXARG_VERTEXCOLOR ); + + // Blend between white and the vertex color... + pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE1, + SHADER_TEXCHANNEL_COLOR, SHADER_TEXOP_BLEND_PREVIOUSSTAGEALPHA, + SHADER_TEXARG_CONSTANTCOLOR, SHADER_TEXARG_TEXTURE ); + pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE1, + SHADER_TEXCHANNEL_ALPHA, SHADER_TEXOP_SELECTARG1, + SHADER_TEXARG_PREVIOUSSTAGE, SHADER_TEXARG_VERTEXCOLOR ); + + EnableAlphaBlending( SHADER_BLEND_DST_COLOR, SHADER_BLEND_ZERO ); + pShaderShadow->DrawFlags( SHADER_DRAW_POSITION | SHADER_DRAW_COLOR | + SHADER_DRAW_TEXCOORD0 | SHADER_DRAW_TEXCOORD1 ); + // We need to fog to *white* regardless of overbrighting... + FogToWhite(); + } + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME ); + BindTexture( SHADER_SAMPLER1, BASETEXTURE, FRAME ); + SetFixedFunctionTextureTransform( MATERIAL_TEXTURE0, BASETEXTURETRANSFORM ); + SetFixedFunctionTextureTransform( MATERIAL_TEXTURE1, BASETEXTURETRANSFORM ); + + // The constant color is the shadow color... + SetColorState( COLOR ); + } + Draw( ); + } +END_SHADER diff --git a/materialsystem/stdshaders/shadow_dx8.cpp b/materialsystem/stdshaders/shadow_dx8.cpp new file mode 100644 index 0000000..1dc9374 --- /dev/null +++ b/materialsystem/stdshaders/shadow_dx8.cpp @@ -0,0 +1,135 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $Header: $ +// $NoKeywords: $ +//=============================================================================// + + +#include "BaseVSShader.h" + +#include "shadow_vs14.inc" +#include "unlitgeneric_vs11.inc" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +DEFINE_FALLBACK_SHADER( Shadow, Shadow_DX8 ) + +BEGIN_VS_SHADER_FLAGS( Shadow_DX8, "Help for Shadow_DX8", SHADER_NOT_EDITABLE ) + + BEGIN_SHADER_PARAMS + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + // FIXME: Need fallback for dx5, don't fade out shadows, just pop them out + /* + The alpha blending state either must be: + Src Color * Dst Color + Dst Color * 0 + (src color = C*A + 1-A) + + or + + // Can't be this, doesn't work with fog + Src Color * Dst Color + Dst Color * (1-Src Alpha) + (src color = C * A, Src Alpha = A) + */ + } + + SHADER_FALLBACK + { + if ( IsPC() && g_pHardwareConfig->GetDXSupportLevel() < 80 ) + { + return "Shadow_DX6"; + } + return 0; + } + + SHADER_INIT + { + LoadTexture( BASETEXTURE ); + } + + SHADER_DRAW + { + SHADOW_STATE + { + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + if ( g_pHardwareConfig->SupportsPixelShaders_1_4() ) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER2, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER3, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER4, true ); + } + + EnableAlphaBlending( SHADER_BLEND_DST_COLOR, SHADER_BLEND_ZERO ); + unsigned int flags = VERTEX_POSITION | VERTEX_COLOR; + int numTexCoords = 1; + pShaderShadow->VertexShaderVertexFormat( flags, numTexCoords, 0, 0 ); + if( g_pHardwareConfig->GetDXSupportLevel() >= 81 ) + { + shadow_vs14_Static_Index vshIndex; + pShaderShadow->SetVertexShader( "Shadow_vs14", vshIndex.GetIndex() ); + pShaderShadow->SetPixelShader( "Shadow_ps14" ); + } + else + { + unlitgeneric_vs11_Static_Index vshIndex; + vshIndex.SetDETAIL( false ); + vshIndex.SetENVMAP( false ); + vshIndex.SetENVMAPCAMERASPACE( false ); + vshIndex.SetENVMAPSPHERE( false ); + vshIndex.SetVERTEXCOLOR( true ); + vshIndex.SetSEPARATEDETAILUVS( false ); + pShaderShadow->SetVertexShader( "UnlitGeneric_vs11", vshIndex.GetIndex() ); + pShaderShadow->SetPixelShader( "Shadow" ); + } + // We need to fog to *white* regardless of overbrighting... + FogToWhite(); + } + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME ); + + SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, BASETEXTURETRANSFORM ); + SetPixelShaderConstant( 1, COLOR ); + if ( g_pHardwareConfig->GetDXSupportLevel() >= 81 ) + { + BindTexture( SHADER_SAMPLER1, BASETEXTURE, FRAME ); + BindTexture( SHADER_SAMPLER2, BASETEXTURE, FRAME ); + BindTexture( SHADER_SAMPLER3, BASETEXTURE, FRAME ); + BindTexture( SHADER_SAMPLER4, BASETEXTURE, FRAME ); + + // Get texture dimensions... + int nWidth = 16; + int nHeight = 16; + ITexture *pTexture = params[BASETEXTURE]->GetTextureValue(); + if (pTexture) + { + nWidth = pTexture->GetActualWidth(); + nHeight = pTexture->GetActualHeight(); + } + Vector4D vecJitter( 1.0 / nWidth, 1.0 / nHeight, 0.0, 0.0 ); + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_2, vecJitter.Base() ); + + vecJitter.y *= -1.0f; + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_3, vecJitter.Base() ); + + shadow_vs14_Dynamic_Index vshIndex; + vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() ); + } + else + { + unlitgeneric_vs11_Dynamic_Index vshIndex; + vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + vshIndex.SetSKINNING( pShaderAPI->GetCurrentNumBones() > 0 ); + pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() ); + } + } + Draw( ); + } +END_SHADER diff --git a/materialsystem/stdshaders/shadow_ps14.psh b/materialsystem/stdshaders/shadow_ps14.psh new file mode 100644 index 0000000..a71df83 --- /dev/null +++ b/materialsystem/stdshaders/shadow_ps14.psh @@ -0,0 +1,28 @@ +ps.1.4 + +def c0, 1.0f, 1.0f, 1.0f, 1.0f +def c2, 0.2f, 0.2f, 0.2f, 0.2f + +texld r0, t0 +texld r1, t1 +texld r2, t2 +texld r3, t3 +texld r4, t4 + +// The mul has to happen here first because we overflow otherwise +mul r0.r, r0.a, c2.a +mad r0.r, r1.a, c2.a, r0.r +mad r0.r, r2.a, c2.a, r0.r +mad r0.r, r3.a, c2.a, r0.r +mad r0.r, r4.a, c2.a, r0.r + +; To accomplish shadow fading, subtract vertex alpha from texture alpha +; color channel isn't used... +sub_sat r0.a, r0.r, v0.a + +; Blend between white and the constant color... +lrp r0.rgba, 1-r0.a, c0, c1 + + + + diff --git a/materialsystem/stdshaders/shadow_ps2x.fxc b/materialsystem/stdshaders/shadow_ps2x.fxc new file mode 100644 index 0000000..9b1bfa3 --- /dev/null +++ b/materialsystem/stdshaders/shadow_ps2x.fxc @@ -0,0 +1,63 @@ +// DYNAMIC: "PIXELFOGTYPE" "0..1" + +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX] + +#define HDRTYPE HDR_TYPE_NONE +#include "common_ps_fxc.h" + +const HALF4 g_ShadowColor : register( c1 ); +const HALF3 g_EyePos : register( c2 ); +const HALF4 g_FogParams : register( c3 ); + +sampler ShadowSampler : register( s0 ); + +// CENTROID: TEXCOORD0 +// CENTROID: TEXCOORD1 +// CENTROID: TEXCOORD2 +// CENTROID: TEXCOORD3 +// CENTROID: TEXCOORD4 +struct PS_INPUT +{ + float2 texCoord0 : TEXCOORD0; + float2 texCoord1 : TEXCOORD1; + float2 texCoord2 : TEXCOORD2; + float2 texCoord3 : TEXCOORD3; + float2 texCoord4 : TEXCOORD4; + HALF4 worldPos_projPosZ : TEXCOORD5; + HALF4 shadowColor : COLOR0; + HALF4 fogFactorW : COLOR1; +}; + +float4 main( PS_INPUT i ) : COLOR +{ + HALF4 samples[5]; + samples[0] = tex2D( ShadowSampler, i.texCoord0 ); + samples[1] = tex2D( ShadowSampler, i.texCoord1 ); + samples[2] = tex2D( ShadowSampler, i.texCoord2 ); + samples[3] = tex2D( ShadowSampler, i.texCoord3 ); + samples[4] = tex2D( ShadowSampler, i.texCoord4 ); + + // Interpolate between a bunch of jittered shadow samples. + HALF shadowCoverage = (samples[0].a + samples[1].a + samples[2].a + samples[3].a + samples[4].a) * 0.2; + + // To accomplish shadow fading, subtract vertex alpha from texture alpha + shadowCoverage = saturate( shadowCoverage - i.shadowColor.a ); + + // Blend between white and the constant color... + // return lerp( 1.0-shadowCoverage, 1.0, g_ShadowColor ); + + // this is equivalent, and saves an instruction + HALF4 result = shadowCoverage*g_ShadowColor - shadowCoverage; + result = 1.0 + result; + + float alpha = 1.0f; + + float fogFactor = CalcPixelFogFactor( PIXELFOGTYPE, g_FogParams, g_EyePos.z, i.worldPos_projPosZ.z, i.worldPos_projPosZ.w ); + + // Apply fog here to compensate for our srcColor*dstColor alpha blend into already fogged pixels + result.rgb = 1.0f - ( ( 1.0f - result.rgb ) * pow( ( 1.0f - fogFactor ), 4.0f ) ); + + // Call FinalOutput without fog! + return FinalOutput( float4( result.rgb, alpha ), fogFactor, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE ); +} diff --git a/materialsystem/stdshaders/shadow_vs14.vsh b/materialsystem/stdshaders/shadow_vs14.vsh new file mode 100644 index 0000000..21dd91e --- /dev/null +++ b/materialsystem/stdshaders/shadow_vs14.vsh @@ -0,0 +1,43 @@ +vs.1.1 + +# DYNAMIC: "DOWATERFOG" "0..1" + +#include "macros.vsh" + +&AllocateRegister( \$projPos ); + +dp4 $projPos.x, $vPos, $cViewProj0 +dp4 $projPos.y, $vPos, $cViewProj1 +dp4 $projPos.z, $vPos, $cViewProj2 +dp4 $projPos.w, $vPos, $cViewProj3 +mov oPos, $projPos + +;------------------------------------------------------------------------------ +; Fog +;------------------------------------------------------------------------------ +alloc $worldPos +if( $DOWATERFOG == 1 ) +{ + ; Get the worldpos z component only since that's all we need for height fog + dp4 $worldPos.z, $vPos, $cModel2 +} +&CalcFog( $worldPos, $projPos ); +free $worldPos + +&FreeRegister( \$projPos ); + +; Shadow color +mov oD0, $vColor + +;------------------------------------------------------------------------------ +; Texture coordinates +;------------------------------------------------------------------------------ +dp4 r0.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_0 +dp4 r0.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_1 + +; Jittered versions +mov oT0, r0 +add oT1, r0, $SHADER_SPECIFIC_CONST_2 +sub oT2, r0, $SHADER_SPECIFIC_CONST_2 +add oT3, r0, $SHADER_SPECIFIC_CONST_3 +sub oT4, r0, $SHADER_SPECIFIC_CONST_3 \ No newline at end of file diff --git a/materialsystem/stdshaders/shadow_vs20.fxc b/materialsystem/stdshaders/shadow_vs20.fxc new file mode 100644 index 0000000..66db17d --- /dev/null +++ b/materialsystem/stdshaders/shadow_vs20.fxc @@ -0,0 +1,66 @@ +// DYNAMIC: "DOWATERFOG" "0..1" + +#include "common_vs_fxc.h" + +static const int g_FogType = DOWATERFOG; + +const float4 cBaseTexCoordTransform[2] : register( SHADER_SPECIFIC_CONST_0 ); +const float4 cTextureJitter[2] : register( SHADER_SPECIFIC_CONST_2 ); + +struct VS_INPUT +{ + // This is all of the stuff that we ever use. + float4 vPos : POSITION; + float4 vColor : COLOR0; + float4 vTexCoord0 : TEXCOORD0; +}; + +struct VS_OUTPUT +{ + float4 projPos : POSITION; +#if !defined( _X360 ) + float fog : FOG; +#endif + float2 texCoord0 : TEXCOORD0; + float2 texCoord1 : TEXCOORD1; + float2 texCoord2 : TEXCOORD2; + float2 texCoord3 : TEXCOORD3; + float2 texCoord4 : TEXCOORD4; + HALF4 worldPos_projPosZ : TEXCOORD5; + float4 shadowColor : COLOR0; + float4 fogFactorW : COLOR1; +}; + +VS_OUTPUT main( const VS_INPUT v ) +{ + VS_OUTPUT o = ( VS_OUTPUT )0; + + float3 worldNormal, worldPos; + float2 texCoord; + worldPos = mul( v.vPos, cModel[0] ); + float4 projPos = mul( float4( worldPos, 1 ), cViewProj ); + o.projPos = projPos; + projPos.z = dot( float4( worldPos, 1 ), cViewProjZ ); + + // NOTE: CalcFog returns 1 for non-water fog, so it's ok to use fog + // It returns the real fog for range fog, since we do vertex fog + o.fogFactorW = CalcFog( worldPos, projPos, g_FogType ); +#if !defined( _X360 ) + o.fog = o.fogFactorW; +#endif + o.shadowColor = v.vColor; + o.worldPos_projPosZ = float4( worldPos, projPos.z ); + + texCoord.x = dot( v.vTexCoord0, cBaseTexCoordTransform[0] ); + texCoord.y = dot( v.vTexCoord0, cBaseTexCoordTransform[1] ); + + o.texCoord0.xy = texCoord; + o.texCoord1.xy = texCoord + cTextureJitter[0]; + o.texCoord2.xy = texCoord - cTextureJitter[0]; + o.texCoord3.xy = texCoord + cTextureJitter[1]; + o.texCoord4.xy = texCoord - cTextureJitter[1]; + + return o; +} + + diff --git a/materialsystem/stdshaders/shadowbuild_dx6.cpp b/materialsystem/stdshaders/shadowbuild_dx6.cpp new file mode 100644 index 0000000..35326f1 --- /dev/null +++ b/materialsystem/stdshaders/shadowbuild_dx6.cpp @@ -0,0 +1,45 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: A shader that builds the shadow using render-to-texture +// +// $Header: $ +// $NoKeywords: $ +//=============================================================================// + +#include "shaderlib/cshader.h" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +DEFINE_FALLBACK_SHADER( ShadowBuild, ShadowBuild_DX6 ) + +BEGIN_SHADER_FLAGS( ShadowBuild_DX6, "Help for ShadowBuild", SHADER_NOT_EDITABLE ) + BEGIN_SHADER_PARAMS + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + } + + SHADER_INIT + { + } + + SHADER_DRAW + { + SHADOW_STATE + { + pShaderShadow->EnableAlphaWrites( true ); + pShaderShadow->EnableConstantColor( true ); + pShaderShadow->EnableConstantAlpha( true ); + pShaderShadow->EnableDepthWrites( false ); + pShaderShadow->EnableDepthTest( false ); + pShaderShadow->DrawFlags( SHADER_DRAW_POSITION ); + FogToGrey(); + } + DYNAMIC_STATE + { + } + Draw( ); + } +END_SHADER diff --git a/materialsystem/stdshaders/shadowbuild_dx8.cpp b/materialsystem/stdshaders/shadowbuild_dx8.cpp new file mode 100644 index 0000000..2316fb5 --- /dev/null +++ b/materialsystem/stdshaders/shadowbuild_dx8.cpp @@ -0,0 +1,118 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: A shader that builds the shadow using render-to-texture +// +// $Header: $ +// $NoKeywords: $ +//=============================================================================// + +#include "BaseVSShader.h" +#include "mathlib/vmatrix.h" +#include "unlitgeneric_vs11.inc" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +DEFINE_FALLBACK_SHADER( ShadowBuild, ShadowBuild_DX8 ) + +BEGIN_VS_SHADER_FLAGS( ShadowBuild_DX8, "Help for ShadowBuild", SHADER_NOT_EDITABLE ) + + BEGIN_SHADER_PARAMS + SHADER_PARAM( TRANSLUCENT_MATERIAL, SHADER_PARAM_TYPE_MATERIAL, "", "Points to a material to grab translucency from" ) + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + SET_FLAGS2( MATERIAL_VAR2_SUPPORTS_HW_SKINNING ); + SET_FLAGS( MATERIAL_VAR_NO_DEBUG_OVERRIDE ); + } + + SHADER_FALLBACK + { + if ( !g_pHardwareConfig->SupportsVertexAndPixelShaders() ) + return "ShadowBuild_DX6"; + return 0; + } + + SHADER_INIT + { + if (params[BASETEXTURE]->IsDefined()) + { + LoadTexture(BASETEXTURE); + } + } + + SHADER_DRAW + { + SHADOW_STATE + { + // Add the alphas into the frame buffer + EnableAlphaBlending( SHADER_BLEND_ONE, SHADER_BLEND_ONE ); + + // base texture. We just use this for alpha, but enable SRGB read to make everything consistent. + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, true ); + + pShaderShadow->EnableSRGBWrite( true ); + + pShaderShadow->EnableAlphaWrites( true ); + pShaderShadow->EnableDepthWrites( false ); + pShaderShadow->DepthFunc( SHADER_DEPTHFUNC_ALWAYS ); + pShaderShadow->VertexShaderVertexFormat( VERTEX_POSITION, 1, 0, 0 ); + + unlitgeneric_vs11_Static_Index vshIndex; + vshIndex.SetDETAIL( false ); + vshIndex.SetENVMAP( false ); + vshIndex.SetENVMAPCAMERASPACE( false ); + vshIndex.SetENVMAPSPHERE( false ); + vshIndex.SetVERTEXCOLOR( false ); + vshIndex.SetSEPARATEDETAILUVS( false ); + pShaderShadow->SetVertexShader( "UnlitGeneric_vs11", vshIndex.GetIndex() ); + + pShaderShadow->SetPixelShader( "ShadowBuildTexture" ); + } + DYNAMIC_STATE + { + SetModulationVertexShaderDynamicState(); + + // Snack important parameters from the original material + // FIXME: What about alpha modulation? Need a solution for that + ITexture *pTexture = NULL; + IMaterialVar **ppTranslucentParams = NULL; + if (params[TRANSLUCENT_MATERIAL]->IsDefined()) + { + IMaterial *pMaterial = params[TRANSLUCENT_MATERIAL]->GetMaterialValue(); + if (pMaterial) + { + ppTranslucentParams = pMaterial->GetShaderParams(); + if ( ppTranslucentParams[BASETEXTURE]->IsTexture() ) + { + pTexture = ppTranslucentParams[BASETEXTURE]->GetTextureValue(); + } + } + } + + if (pTexture) + { + BindTexture( SHADER_SAMPLER0, pTexture, ppTranslucentParams[FRAME]->GetIntValue() ); + + Vector4D transformation[2]; + const VMatrix &mat = ppTranslucentParams[BASETEXTURETRANSFORM]->GetMatrixValue(); + transformation[0].Init( mat[0][0], mat[0][1], mat[0][2], mat[0][3] ); + transformation[1].Init( mat[1][0], mat[1][1], mat[1][2], mat[1][3] ); + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, transformation[0].Base(), 2 ); + } + else + { + pShaderAPI->BindStandardTexture( SHADER_SAMPLER0, TEXTURE_LIGHTMAP_FULLBRIGHT ); + } + + // Compute the vertex shader index. + unlitgeneric_vs11_Dynamic_Index vshIndex; + vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + vshIndex.SetSKINNING( pShaderAPI->GetCurrentNumBones() > 0 ); + pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() ); + } + Draw( ); + } +END_SHADER diff --git a/materialsystem/stdshaders/shadowbuild_dx9.cpp b/materialsystem/stdshaders/shadowbuild_dx9.cpp new file mode 100644 index 0000000..57dbd8a --- /dev/null +++ b/materialsystem/stdshaders/shadowbuild_dx9.cpp @@ -0,0 +1,149 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: A shader that builds the shadow using render-to-texture +// +// $Header: $ +// $NoKeywords: $ +//=============================================================================// + +#include "BaseVSShader.h" +#include "mathlib/vmatrix.h" + +#include "unlitgeneric_vs20.inc" +#include "shadowbuildtexture_ps20.inc" +#include "shadowbuildtexture_ps20b.inc" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +DEFINE_FALLBACK_SHADER( ShadowBuild, ShadowBuild_DX9 ) + +BEGIN_VS_SHADER_FLAGS( ShadowBuild_DX9, "Help for ShadowBuild", SHADER_NOT_EDITABLE ) + + BEGIN_SHADER_PARAMS + SHADER_PARAM( TRANSLUCENT_MATERIAL, SHADER_PARAM_TYPE_MATERIAL, "", "Points to a material to grab translucency from" ) + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + SET_FLAGS2( MATERIAL_VAR2_SUPPORTS_HW_SKINNING ); + SET_FLAGS( MATERIAL_VAR_NO_DEBUG_OVERRIDE ); + } + + SHADER_FALLBACK + { + if ( !g_pHardwareConfig->SupportsVertexAndPixelShaders() ) + return "ShadowBuild_DX6"; + + if ( g_pHardwareConfig->GetDXSupportLevel() < 90 ) + return "ShadowBuild_DX8"; + + return 0; + } + + SHADER_INIT + { + if ( params[BASETEXTURE]->IsDefined() ) + { + LoadTexture( BASETEXTURE, TEXTUREFLAGS_SRGB ); + } + } + + SHADER_DRAW + { + SHADOW_STATE + { + // Add the alphas into the frame buffer + EnableAlphaBlending( SHADER_BLEND_ONE, SHADER_BLEND_ONE ); + + // base texture. We just use this for alpha, but enable SRGB read to make everything consistent. + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, true ); + + pShaderShadow->EnableSRGBWrite( true ); + + pShaderShadow->EnableAlphaWrites( true ); + pShaderShadow->EnableDepthWrites( false ); + pShaderShadow->DepthFunc( SHADER_DEPTHFUNC_ALWAYS ); + + // Specify vertex format (note that this shader supports compression) + unsigned int flags = VERTEX_POSITION | VERTEX_FORMAT_COMPRESSED; + unsigned int nTexCoordCount = 1; + unsigned int userDataSize = 0; + pShaderShadow->VertexShaderVertexFormat( flags, nTexCoordCount, NULL, userDataSize ); + + DECLARE_STATIC_VERTEX_SHADER( unlitgeneric_vs20 ); + SET_STATIC_VERTEX_SHADER_COMBO( VERTEXCOLOR, 0 ); + SET_STATIC_VERTEX_SHADER( unlitgeneric_vs20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_STATIC_PIXEL_SHADER( shadowbuildtexture_ps20b ); + SET_STATIC_PIXEL_SHADER( shadowbuildtexture_ps20b ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( shadowbuildtexture_ps20 ); + SET_STATIC_PIXEL_SHADER( shadowbuildtexture_ps20 ); + } + } + DYNAMIC_STATE + { + SetModulationVertexShaderDynamicState(); + + // Snack important parameters from the original material + // FIXME: What about alpha modulation? Need a solution for that + ITexture *pTexture = NULL; + IMaterialVar **ppTranslucentParams = NULL; + if (params[TRANSLUCENT_MATERIAL]->IsDefined()) + { + IMaterial *pMaterial = params[TRANSLUCENT_MATERIAL]->GetMaterialValue(); + if (pMaterial) + { + ppTranslucentParams = pMaterial->GetShaderParams(); + if ( ppTranslucentParams[BASETEXTURE]->IsTexture() ) + { + pTexture = ppTranslucentParams[BASETEXTURE]->GetTextureValue(); + } + } + } + + if (pTexture) + { + BindTexture( SHADER_SAMPLER0, pTexture, ppTranslucentParams[FRAME]->GetIntValue() ); + + Vector4D transformation[2]; + const VMatrix &mat = ppTranslucentParams[BASETEXTURETRANSFORM]->GetMatrixValue(); + transformation[0].Init( mat[0][0], mat[0][1], mat[0][2], mat[0][3] ); + transformation[1].Init( mat[1][0], mat[1][1], mat[1][2], mat[1][3] ); + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, transformation[0].Base(), 2 ); + } + else + { + pShaderAPI->BindStandardTexture( SHADER_SAMPLER0, TEXTURE_LIGHTMAP_FULLBRIGHT ); + } + + float vVertexColor[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_6, vVertexColor, 1 ); + + // Compute the vertex shader index. + DECLARE_DYNAMIC_VERTEX_SHADER( unlitgeneric_vs20 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( DOWATERFOG, pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, pShaderAPI->GetCurrentNumBones() > 0 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression ); + SET_DYNAMIC_VERTEX_SHADER( unlitgeneric_vs20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_DYNAMIC_PIXEL_SHADER( shadowbuildtexture_ps20b ); + SET_DYNAMIC_PIXEL_SHADER( shadowbuildtexture_ps20b ); + } + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( shadowbuildtexture_ps20 ); + SET_DYNAMIC_PIXEL_SHADER( shadowbuildtexture_ps20 ); + } + } + Draw( ); + } +END_SHADER diff --git a/materialsystem/stdshaders/shadowbuildtexture_ps2x.fxc b/materialsystem/stdshaders/shadowbuildtexture_ps2x.fxc new file mode 100644 index 0000000..e3a2d1c --- /dev/null +++ b/materialsystem/stdshaders/shadowbuildtexture_ps2x.fxc @@ -0,0 +1,28 @@ +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX] + +#include "common_ps_fxc.h" + +sampler BaseTextureSampler : register( s0 ); + +struct PS_INPUT +{ + float2 vTexCoord0 : TEXCOORD0; + float4 vColor : COLOR0; + +#if defined( _X360 ) //matching pixel shader inputs to vertex shader outputs to avoid shader patches + float2 vTexCoord1 : TEXCOORD1; + float2 vTexCoord2 : TEXCOORD2; + float2 vTexCoord3 : TEXCOORD3; + float4 fogFactorW : COLOR1; + float4 worldPos_projPosZ : TEXCOORD7; // Necessary for pixel fog +#endif +}; + +HALF4 main( PS_INPUT i ) : COLOR +{ + //relevant data is in the alpha channel, modulate vertex alpha by texture alpha + float returnAlpha = tex2D( BaseTextureSampler, i.vTexCoord0 ).a * i.vColor.a; + + return FinalOutput( float4( 1.0f, 1.0f, 1.0f, returnAlpha ), 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE ); +} diff --git a/materialsystem/stdshaders/shadowmodel_dx8.cpp b/materialsystem/stdshaders/shadowmodel_dx8.cpp new file mode 100644 index 0000000..e7d7228 --- /dev/null +++ b/materialsystem/stdshaders/shadowmodel_dx8.cpp @@ -0,0 +1,97 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $Header: $ +// $NoKeywords: $ +//=============================================================================// + +#include "BaseVSShader.h" + +#include "shadowmodel.inc" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +DEFINE_FALLBACK_SHADER( ShadowModel, ShadowModel_DX8 ) + +BEGIN_VS_SHADER_FLAGS( ShadowModel_DX8, "Help for ShadowModel", SHADER_NOT_EDITABLE ) + + BEGIN_SHADER_PARAMS + SHADER_PARAM( BASETEXTUREOFFSET, SHADER_PARAM_TYPE_VEC2, "[0 0]", "$baseTexture texcoord offset" ) + SHADER_PARAM( BASETEXTURESCALE, SHADER_PARAM_TYPE_VEC2, "[1 1]", "$baseTexture texcoord scale" ) + SHADER_PARAM( FALLOFFOFFSET, SHADER_PARAM_TYPE_FLOAT, "0", "Distance at which shadow starts to fade" ) + SHADER_PARAM( FALLOFFDISTANCE, SHADER_PARAM_TYPE_FLOAT, "100", "Max shadow distance" ) + SHADER_PARAM( FALLOFFAMOUNT, SHADER_PARAM_TYPE_FLOAT, "0.9", "Amount to brighten the shadow at max dist" ) + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + SET_FLAGS2( MATERIAL_VAR2_SUPPORTS_HW_SKINNING ); + if (!params[BASETEXTURESCALE]->IsDefined()) + { + Vector2D scale(1, 1); + params[BASETEXTURESCALE]->SetVecValue( scale.Base(), 2 ); + } + + if (!params[FALLOFFDISTANCE]->IsDefined()) + params[FALLOFFDISTANCE]->SetFloatValue( 100.0f ); + + if (!params[FALLOFFAMOUNT]->IsDefined()) + params[FALLOFFAMOUNT]->SetFloatValue( 0.9f ); + } + + SHADER_INIT + { + if (params[BASETEXTURE]->IsDefined()) + LoadTexture( BASETEXTURE ); + } + + SHADER_DRAW + { + SHADOW_STATE + { + // Base texture on stage 0 + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + + // Multiplicative blending state... + EnableAlphaBlending( SHADER_BLEND_DST_COLOR, SHADER_BLEND_ZERO ); + + int fmt = VERTEX_POSITION | VERTEX_NORMAL; + pShaderShadow->VertexShaderVertexFormat( fmt, 1, 0, 0 ); + + shadowmodel_Static_Index vshIndex; + pShaderShadow->SetVertexShader( "ShadowModel", vshIndex.GetIndex() ); + + pShaderShadow->SetPixelShader( "ShadowModel" ); + + // We need to fog to *white* regardless of overbrighting... + FogToWhite(); + } + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME ); + SetVertexShaderMatrix3x4( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, BASETEXTURETRANSFORM ); + + SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_3, BASETEXTUREOFFSET ); + SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_4, BASETEXTURESCALE ); + + Vector4D shadow; + shadow[0] = params[FALLOFFOFFSET]->GetFloatValue(); + shadow[1] = params[FALLOFFDISTANCE]->GetFloatValue() + shadow[0]; + if (shadow[1] != 0.0f) + shadow[1] = 1.0f / shadow[1]; + shadow[2] = params[FALLOFFAMOUNT]->GetFloatValue(); + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_5, shadow.Base(), 1 ); + + // The constant color is the shadow color... + SetModulationVertexShaderDynamicState(); + + shadowmodel_Dynamic_Index vshIndex; + vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + vshIndex.SetSKINNING( pShaderAPI->GetCurrentNumBones() > 0 ); + pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() ); + } + Draw( ); + } +END_SHADER diff --git a/materialsystem/stdshaders/shadowmodel_dx9.cpp b/materialsystem/stdshaders/shadowmodel_dx9.cpp new file mode 100644 index 0000000..0198e86 --- /dev/null +++ b/materialsystem/stdshaders/shadowmodel_dx9.cpp @@ -0,0 +1,154 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $Header: $ +// $NoKeywords: $ +//=============================================================================// + +//Note: Not upgraded to vs/ps 2.0 fxc's because this shader is unused and there are no test cases to verify against. +#include "BaseVSShader.h" + +#if !defined( _X360 ) +#include "shadowmodel_ps20.inc" +#include "shadowmodel_vs20.inc" +#endif + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +DEFINE_FALLBACK_SHADER( ShadowModel, ShadowModel_DX9 ) + + +#if !defined( _X360 ) //not used for anything at time of 360 ship, and we want to avoid storing/loading assembly shaders + +//PC version +BEGIN_VS_SHADER_FLAGS( ShadowModel_DX9, "Help for ShadowModel", SHADER_NOT_EDITABLE ) + +BEGIN_SHADER_PARAMS +SHADER_PARAM( BASETEXTUREOFFSET, SHADER_PARAM_TYPE_VEC2, "[0 0]", "$baseTexture texcoord offset" ) +SHADER_PARAM( BASETEXTURESCALE, SHADER_PARAM_TYPE_VEC2, "[1 1]", "$baseTexture texcoord scale" ) +SHADER_PARAM( FALLOFFOFFSET, SHADER_PARAM_TYPE_FLOAT, "0", "Distance at which shadow starts to fade" ) +SHADER_PARAM( FALLOFFDISTANCE, SHADER_PARAM_TYPE_FLOAT, "100", "Max shadow distance" ) +SHADER_PARAM( FALLOFFAMOUNT, SHADER_PARAM_TYPE_FLOAT, "0.9", "Amount to brighten the shadow at max dist" ) +END_SHADER_PARAMS + +SHADER_INIT_PARAMS() +{ + if (!params[BASETEXTURESCALE]->IsDefined()) + { + Vector2D scale(1, 1); + params[BASETEXTURESCALE]->SetVecValue( scale.Base(), 2 ); + } + + if (!params[FALLOFFDISTANCE]->IsDefined()) + params[FALLOFFDISTANCE]->SetFloatValue( 100.0f ); + + if (!params[FALLOFFAMOUNT]->IsDefined()) + params[FALLOFFAMOUNT]->SetFloatValue( 0.9f ); +} + +SHADER_FALLBACK +{ + if ( g_pHardwareConfig->GetDXSupportLevel() < 90 ) + return "ShadowModel_DX8"; + + return 0; +} + +SHADER_INIT +{ + if (params[BASETEXTURE]->IsDefined()) + { + LoadTexture( BASETEXTURE ); + } +} + +SHADER_DRAW +{ + SHADOW_STATE + { + // Base texture on stage 0 + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + + // Multiplicative blending state... + EnableAlphaBlending( SHADER_BLEND_DST_COLOR, SHADER_BLEND_ZERO ); + + int fmt = VERTEX_POSITION | VERTEX_NORMAL; + pShaderShadow->VertexShaderVertexFormat( fmt, 1, 0, 0 ); + + DECLARE_STATIC_VERTEX_SHADER( shadowmodel_vs20 ); + SET_STATIC_VERTEX_SHADER( shadowmodel_vs20 ); + + DECLARE_STATIC_PIXEL_SHADER( shadowmodel_ps20 ); + SET_STATIC_PIXEL_SHADER( shadowmodel_ps20 ); + + // We need to fog to *white* regardless of overbrighting... + FogToWhite(); + } + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME ); + SetVertexShaderMatrix3x4( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, BASETEXTURETRANSFORM ); + + SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_3, BASETEXTUREOFFSET ); + SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_4, BASETEXTURESCALE ); + + Vector4D shadow; + shadow[0] = params[FALLOFFOFFSET]->GetFloatValue(); + shadow[1] = params[FALLOFFDISTANCE]->GetFloatValue() + shadow[0]; + if (shadow[1] != 0.0f) + shadow[1] = 1.0f / shadow[1]; + shadow[2] = params[FALLOFFAMOUNT]->GetFloatValue(); + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_5, shadow.Base(), 1 ); + + // The constant color is the shadow color... + SetModulationVertexShaderDynamicState(); + + DECLARE_DYNAMIC_VERTEX_SHADER( shadowmodel_vs20 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( DOWATERFOG, pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, pShaderAPI->GetCurrentNumBones() > 0 ); + SET_DYNAMIC_VERTEX_SHADER( shadowmodel_vs20 ); + + DECLARE_DYNAMIC_PIXEL_SHADER( shadowmodel_ps20 ); + SET_DYNAMIC_PIXEL_SHADER( shadowmodel_ps20 ); + } + Draw( ); +} +END_SHADER + + +#else + +//360 version + +BEGIN_VS_SHADER_FLAGS( ShadowModel_DX9, "Help for ShadowModel", SHADER_NOT_EDITABLE ) + +BEGIN_SHADER_PARAMS +SHADER_PARAM( BASETEXTUREOFFSET, SHADER_PARAM_TYPE_VEC2, "[0 0]", "$baseTexture texcoord offset" ) +SHADER_PARAM( BASETEXTURESCALE, SHADER_PARAM_TYPE_VEC2, "[1 1]", "$baseTexture texcoord scale" ) +SHADER_PARAM( FALLOFFOFFSET, SHADER_PARAM_TYPE_FLOAT, "0", "Distance at which shadow starts to fade" ) +SHADER_PARAM( FALLOFFDISTANCE, SHADER_PARAM_TYPE_FLOAT, "100", "Max shadow distance" ) +SHADER_PARAM( FALLOFFAMOUNT, SHADER_PARAM_TYPE_FLOAT, "0.9", "Amount to brighten the shadow at max dist" ) +END_SHADER_PARAMS + +SHADER_INIT_PARAMS() +{ +} + +SHADER_FALLBACK +{ + return 0; +} + +SHADER_INIT +{ +} + +SHADER_DRAW +{ + Draw( false ); +} +END_SHADER + +#endif \ No newline at end of file diff --git a/materialsystem/stdshaders/shadowmodel_ps20.fxc b/materialsystem/stdshaders/shadowmodel_ps20.fxc new file mode 100644 index 0000000..d0aedda --- /dev/null +++ b/materialsystem/stdshaders/shadowmodel_ps20.fxc @@ -0,0 +1,20 @@ + +struct PS_INPUT +{ + float4 T0 : TEXCOORD0; + float3 T1 : TEXCOORD1; + float3 T2 : TEXCOORD2; + float T3 : TEXCOORD3; + float3 vColor : COLOR0; +}; + +float4 main( PS_INPUT i ) : COLOR +{ + // Kill pixel against various fields computed in vertex shader + clip ( i.T1 ); + clip ( i.T2 ); + clip ( i.T3 ); // Backface cull + + // i.T0.a is uninitialized by the vs, but this is how the original asm shader was written???? + return float4( lerp( float3(1,1,1), i.vColor.xyz, i.T0.a ), 1 ); +} \ No newline at end of file diff --git a/materialsystem/stdshaders/shadowmodel_vs20.fxc b/materialsystem/stdshaders/shadowmodel_vs20.fxc new file mode 100644 index 0000000..9d1ff02 --- /dev/null +++ b/materialsystem/stdshaders/shadowmodel_vs20.fxc @@ -0,0 +1,81 @@ +// DYNAMIC: "DOWATERFOG" "0..1" +// DYNAMIC: "SKINNING" "0..1" + +#include "common_vs_fxc.h" + +static const bool g_bSkinning = SKINNING ? true : false; +static const int g_FogType = DOWATERFOG; + +const float4 cShadowTextureMatrix[3] : register( SHADER_SPECIFIC_CONST_0 ); +const float4 cTexOrigin : register( SHADER_SPECIFIC_CONST_3 ); +const float4 cTexScale : register( SHADER_SPECIFIC_CONST_4 ); + +// { Shadow falloff offset, 1/Shadow distance, Shadow scale, 0 } +const float3 cShadowConstants : register( SHADER_SPECIFIC_CONST_5 ); +#define flShadowFalloffOffset cShadowConstants.x +#define flOneOverShadowDist cShadowConstants.y +#define flShadowScale cShadowConstants.z + + +struct VS_INPUT +{ + float4 vPos : POSITION; + float3 vNormal : NORMAL; + float4 vBoneWeights : BLENDWEIGHT; + float4 vBoneIndices : BLENDINDICES; +}; + +struct VS_OUTPUT +{ + float4 projPos : POSITION; // Projection-space position + float3 T0 : TEXCOORD0; // PS wants this to be 4D but VS doesn't? (see original asm sources) + float3 T1 : TEXCOORD1; + float3 T2 : TEXCOORD2; + float T3 : TEXCOORD3; + float4 vColor : COLOR0; + float fog : FOG; +}; + +VS_OUTPUT main( const VS_INPUT v ) +{ + VS_OUTPUT o; + + // Perform skinning + float3 worldNormal, worldPos; + SkinPositionAndNormal( g_bSkinning, v.vPos, v.vNormal, v.vBoneWeights, v.vBoneIndices, worldPos, worldNormal ); + + // Transform into projection space + o.projPos = mul( float4( worldPos, 1 ), cViewProj ); + + // Compute fog + o.fog = CalcFog( worldPos, o.projPos, g_FogType ); + + // Transform position into texture space (from 0 to 1) + float3 vTexturePos; + vTexturePos.x = dot( worldPos.xyz, cShadowTextureMatrix[0].xyz ); + vTexturePos.y = dot( worldPos.xyz, cShadowTextureMatrix[1].xyz ); + vTexturePos.z = dot( worldPos.xyz, cShadowTextureMatrix[2].xyz ); + + // Figure out the shadow fade amount + float flShadowFade = ( vTexturePos.z - flShadowFalloffOffset ) * flOneOverShadowDist; + + // Offset it into the texture + o.T0 = vTexturePos * cTexScale + cTexOrigin; + + // We're doing clipping by using texkill + o.T1.xyz = vTexturePos.xyz; // Also clips when shadow z < 0 ! + o.T2.xyz = float3( 1.0f, 1.0f, 1.0f ) - vTexturePos.xyz; + o.T2.z = 1.0f - flShadowFade; // Clips when shadow z > shadow distance + + // We're doing backface culling by using texkill also (wow yucky) + // -------------------------------------------------------------- + // Transform z component of normal in texture space + // If it's negative, then don't draw the pixel + o.T3 = dot( worldNormal, -cShadowTextureMatrix[2] ); + + // Shadow color, falloff + o.vColor.xyz = cModulationColor.xyz; + o.vColor.w = flShadowFade * flShadowScale; + + return o; +} diff --git a/materialsystem/stdshaders/shatteredglass.cpp b/materialsystem/stdshaders/shatteredglass.cpp new file mode 100644 index 0000000..88fee04 --- /dev/null +++ b/materialsystem/stdshaders/shatteredglass.cpp @@ -0,0 +1,297 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: Lightmap only shader +// +// $Header: $ +// $NoKeywords: $ +//=============================================================================// + +#include "BaseVSShader.h" + +#include "ShatteredGlass_ps20.inc" +#include "ShatteredGlass_ps20b.inc" +#include "ShatteredGlass_vs20.inc" + +BEGIN_VS_SHADER( ShatteredGlass, + "Help for ShatteredGlass" ) + + BEGIN_SHADER_PARAMS + SHADER_PARAM_OVERRIDE( BASETEXTURE, SHADER_PARAM_TYPE_TEXTURE, "Glass/glasswindowbreak070b", "unused", SHADER_PARAM_NOT_EDITABLE ) + SHADER_PARAM( DETAIL, SHADER_PARAM_TYPE_TEXTURE, "Glass/glasswindowbreak070b", "detail" ) + SHADER_PARAM( DETAILSCALE, SHADER_PARAM_TYPE_FLOAT, "1.0", "detail scale" ) + SHADER_PARAM( ENVMAP, SHADER_PARAM_TYPE_TEXTURE, "shadertest/shadertest_env", "envmap" ) + SHADER_PARAM( ENVMAPFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "" ) + SHADER_PARAM( ENVMAPMASK, SHADER_PARAM_TYPE_TEXTURE, "glass/glasswindowbreak070b_mask", "envmap mask" ) + SHADER_PARAM( ENVMAPMASKFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "" ) + SHADER_PARAM( ENVMAPMASKTRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$envmapmask texcoord transform" ) + SHADER_PARAM( ENVMAPTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "envmap tint" ) + SHADER_PARAM( ENVMAPCONTRAST, SHADER_PARAM_TYPE_FLOAT, "0.0", "contrast 0 == normal 1 == color*color" ) + SHADER_PARAM( ENVMAPSATURATION, SHADER_PARAM_TYPE_FLOAT, "1.0", "saturation 0 == greyscale 1 == normal" ) + SHADER_PARAM( FRESNELREFLECTION, SHADER_PARAM_TYPE_FLOAT, "1.0", "1.0 == mirror, 0.0 == water" ) + SHADER_PARAM( UNLITFACTOR, SHADER_PARAM_TYPE_FLOAT, "0.7", "0.0 == multiply by lightmap, 1.0 == multiply by 1" ) + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + if( !params[DETAILSCALE]->IsDefined() ) + params[DETAILSCALE]->SetFloatValue( 1.0f ); + + if( !params[ENVMAPTINT]->IsDefined() ) + params[ENVMAPTINT]->SetVecValue( 1.0f, 1.0f, 1.0f ); + + if( !params[ENVMAPCONTRAST]->IsDefined() ) + params[ENVMAPCONTRAST]->SetFloatValue( 0.0f ); + + if( !params[ENVMAPSATURATION]->IsDefined() ) + params[ENVMAPSATURATION]->SetFloatValue( 1.0f ); + + if( !params[UNLITFACTOR]->IsDefined() ) + params[UNLITFACTOR]->SetFloatValue( 0.3f ); + + if( !params[FRESNELREFLECTION]->IsDefined() ) + params[FRESNELREFLECTION]->SetFloatValue( 1.0f ); + + if( !params[ENVMAPMASKFRAME]->IsDefined() ) + params[ENVMAPMASKFRAME]->SetIntValue( 0 ); + + if( !params[ENVMAPFRAME]->IsDefined() ) + params[ENVMAPFRAME]->SetIntValue( 0 ); + + // No texture means no self-illum or env mask in base alpha + if ( !params[BASETEXTURE]->IsDefined() ) + { + CLEAR_FLAGS( MATERIAL_VAR_BASEALPHAENVMAPMASK ); + } + + // If in decal mode, no debug override... + if (IS_FLAG_SET(MATERIAL_VAR_DECAL)) + { + SET_FLAGS( MATERIAL_VAR_NO_DEBUG_OVERRIDE ); + } + } + + SHADER_FALLBACK + { + // MMW Shattered Glass runs as a DX9 effect for 8.2 hardware + bool isDX9 = (g_pHardwareConfig->GetDXSupportLevel() >= 82); + if( !isDX9 ) + { + return "ShatteredGlass_DX8"; + } + return 0; + } + + SHADER_INIT + { + if (params[BASETEXTURE]->IsDefined()) + { + LoadTexture( BASETEXTURE, TEXTUREFLAGS_SRGB ); + + if ( !params[BASETEXTURE]->GetTextureValue()->IsTranslucent() ) + { + if ( IS_FLAG_SET( MATERIAL_VAR_BASEALPHAENVMAPMASK ) ) + CLEAR_FLAGS( MATERIAL_VAR_BASEALPHAENVMAPMASK ); + } + } + + if ( params[DETAIL]->IsDefined() ) + { + LoadTexture( DETAIL, TEXTUREFLAGS_SRGB ); + } + + // Don't alpha test if the alpha channel is used for other purposes + if ( IS_FLAG_SET(MATERIAL_VAR_BASEALPHAENVMAPMASK) ) + CLEAR_FLAGS( MATERIAL_VAR_ALPHATEST ); + + if (params[ENVMAP]->IsDefined()) + { + LoadCubeMap( ENVMAP ); + if ( params[ENVMAPMASK]->IsDefined() ) + { + LoadTexture( ENVMAPMASK, g_pHardwareConfig->GetHDRType() == HDR_TYPE_NONE ? TEXTUREFLAGS_SRGB : 0 ); + } + } + } + + SHADER_DRAW + { + bool bHasEnvmapMask = false; + bool bHasEnvmap = false; + if ( params[ENVMAP]->IsTexture() ) + { + bHasEnvmap = true; + if ( params[ENVMAPMASK]->IsTexture() ) + { + bHasEnvmapMask = true; + } + } + bool bHasVertexColor = IS_FLAG_SET(MATERIAL_VAR_VERTEXCOLOR); + bool bHasBaseAlphaEnvmapMask = IS_FLAG_SET(MATERIAL_VAR_BASEALPHAENVMAPMASK); + + // Base + SHADOW_STATE + { + // alpha test + pShaderShadow->EnableAlphaTest( IS_FLAG_SET(MATERIAL_VAR_ALPHATEST) ); + + // Alpha blending, enable alpha blending if the detail texture is translucent + bool detailIsTranslucent = TextureIsTranslucent( DETAIL, false ); + if ( detailIsTranslucent ) + { + 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 + { + SetDefaultBlendingShadowState( BASETEXTURE, true ); + } + + pShaderShadow->EnableSRGBWrite( true ); + + // Base texture + unsigned int flags = VERTEX_POSITION; + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, true ); + + // Lightmap + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + if( g_pHardwareConfig->GetHDRType() == HDR_TYPE_NONE ) + { + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER1, true ); + } + else + { + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER1, false ); + } + + // Detail texture + pShaderShadow->EnableTexture( SHADER_SAMPLER3, true ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER3, true ); + + // Envmap + if ( bHasEnvmap ) + { + flags |= VERTEX_NORMAL; + pShaderShadow->EnableTexture( SHADER_SAMPLER2, true ); + if( g_pHardwareConfig->GetHDRType() == HDR_TYPE_NONE ) + { + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER2, true ); + } + + if( bHasEnvmapMask ) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER5, true ); + } + } + + // Normalizing cube map + pShaderShadow->EnableTexture( SHADER_SAMPLER6, true ); + + if ( bHasVertexColor ) + { + flags |= VERTEX_COLOR; + } + + pShaderShadow->VertexShaderVertexFormat( flags, 3, 0, 0 ); + + DECLARE_STATIC_VERTEX_SHADER( shatteredglass_vs20 ); + SET_STATIC_VERTEX_SHADER_COMBO( ENVMAP_MASK, bHasEnvmapMask ); + SET_STATIC_VERTEX_SHADER( shatteredglass_vs20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_STATIC_PIXEL_SHADER( shatteredglass_ps20b ); + SET_STATIC_PIXEL_SHADER_COMBO( CUBEMAP, bHasEnvmap ); + SET_STATIC_PIXEL_SHADER_COMBO( VERTEXCOLOR, bHasVertexColor ); + SET_STATIC_PIXEL_SHADER_COMBO( ENVMAPMASK, bHasEnvmapMask ); + SET_STATIC_PIXEL_SHADER_COMBO( BASEALPHAENVMAPMASK, bHasBaseAlphaEnvmapMask ); + SET_STATIC_PIXEL_SHADER_COMBO( HDRTYPE, g_pHardwareConfig->GetHDRType() ); + SET_STATIC_PIXEL_SHADER( shatteredglass_ps20b ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( shatteredglass_ps20 ); + SET_STATIC_PIXEL_SHADER_COMBO( CUBEMAP, bHasEnvmap ); + SET_STATIC_PIXEL_SHADER_COMBO( VERTEXCOLOR, bHasVertexColor ); + SET_STATIC_PIXEL_SHADER_COMBO( ENVMAPMASK, bHasEnvmapMask ); + SET_STATIC_PIXEL_SHADER_COMBO( BASEALPHAENVMAPMASK, bHasBaseAlphaEnvmapMask ); + SET_STATIC_PIXEL_SHADER_COMBO( HDRTYPE, g_pHardwareConfig->GetHDRType() ); + SET_STATIC_PIXEL_SHADER( shatteredglass_ps20 ); + } + + DefaultFog(); + } + DYNAMIC_STATE + { + SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, BASETEXTURETRANSFORM ); + SetVertexShaderTextureScale( VERTEX_SHADER_SHADER_SPECIFIC_CONST_2, DETAILSCALE ); + + BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME ); + pShaderAPI->BindStandardTexture( SHADER_SAMPLER1, TEXTURE_LIGHTMAP ); + BindTexture( SHADER_SAMPLER3, DETAIL ); + + if( bHasEnvmap ) + { + BindTexture( SHADER_SAMPLER2, ENVMAP, ENVMAPFRAME ); + if( bHasEnvmapMask ) + { + BindTexture( SHADER_SAMPLER5, ENVMAPMASK, ENVMAPMASKFRAME ); + } + } + + pShaderAPI->BindStandardTexture( SHADER_SAMPLER6, TEXTURE_NORMALIZATION_CUBEMAP_SIGNED ); + + /* + "DOWATERFOG" "0..1" + "ENVMAP_MASK" "0..1" + */ + MaterialFogMode_t fogType = pShaderAPI->GetSceneFogMode(); + int fogIndex = ( fogType == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ) ? 1 : 0; + + DECLARE_DYNAMIC_VERTEX_SHADER( shatteredglass_vs20 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( DOWATERFOG, fogIndex ); + SET_DYNAMIC_VERTEX_SHADER( shatteredglass_vs20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_DYNAMIC_PIXEL_SHADER( shatteredglass_ps20b ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( HDRENABLED, IsHDREnabled() ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + SET_DYNAMIC_PIXEL_SHADER( shatteredglass_ps20b ); + } + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( shatteredglass_ps20 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( HDRENABLED, IsHDREnabled() ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + SET_DYNAMIC_PIXEL_SHADER( shatteredglass_ps20 ); + } + + SetEnvMapTintPixelShaderDynamicState( 0, ENVMAPTINT, -1 ); + SetModulationPixelShaderDynamicState( 1 ); + SetPixelShaderConstant( 2, ENVMAPCONTRAST ); + SetPixelShaderConstant( 3, ENVMAPSATURATION ); + + // [ 0, 0 ,0, R(0) ] + float fresnel[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; + fresnel[3] = params[FRESNELREFLECTION]->GetFloatValue(); + fresnel[0] = fresnel[1] = fresnel[2] = 1.0f - fresnel[3]; + pShaderAPI->SetPixelShaderConstant( 4, fresnel ); + + float eyePos[4]; + pShaderAPI->GetWorldSpaceCameraPosition( eyePos ); + pShaderAPI->SetPixelShaderConstant( 5, eyePos, 1 ); + + pShaderAPI->SetPixelShaderFogParams( 12 ); + + float overbright[4]; + overbright[0] = OVERBRIGHT; + overbright[1] = params[UNLITFACTOR]->GetFloatValue(); + overbright[2] = overbright[3] = 1.0f - params[UNLITFACTOR]->GetFloatValue(); + pShaderAPI->SetPixelShaderConstant( 6, overbright ); + } + Draw(); + } +END_SHADER diff --git a/materialsystem/stdshaders/shatteredglass_dx7.cpp b/materialsystem/stdshaders/shatteredglass_dx7.cpp new file mode 100644 index 0000000..5199ccd --- /dev/null +++ b/materialsystem/stdshaders/shatteredglass_dx7.cpp @@ -0,0 +1,194 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: Lightmap only shader +// +// $Header: $ +// $NoKeywords: $ +//=============================================================================// + +#include "shaderlib/cshader.h" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +DEFINE_FALLBACK_SHADER( ShatteredGlass, ShatteredGlass_DX7 ) + +BEGIN_SHADER( ShatteredGlass_DX7, + "Help for ShatteredGlass_DX7" ) + + BEGIN_SHADER_PARAMS + SHADER_PARAM( DETAIL, SHADER_PARAM_TYPE_TEXTURE, "shadertest/Detail", "detail" ) + SHADER_PARAM( DETAILSCALE, SHADER_PARAM_TYPE_FLOAT, "1", "detail scale" ) + SHADER_PARAM( ENVMAP, SHADER_PARAM_TYPE_TEXTURE, "shadertest/shadertest_env", "envmap" ) + SHADER_PARAM( ENVMAPFRAME, SHADER_PARAM_TYPE_INTEGER, "", "" ) + SHADER_PARAM( ENVMAPTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "envmap tint" ) + SHADER_PARAM( ENVMAPMASKSCALE, SHADER_PARAM_TYPE_FLOAT, "1", "envmap mask scale" ) + SHADER_PARAM( LIGHTMAPTINT, SHADER_PARAM_TYPE_FLOAT, "1.0", "lightmap tint" ) + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + if( !params[ENVMAPMASKSCALE]->IsDefined() ) + { + params[ENVMAPMASKSCALE]->SetFloatValue( 1.0f ); + } + + if( !params[DETAILSCALE]->IsDefined() ) + { + params[DETAILSCALE]->SetFloatValue( 1.0f ); + } + + if( !params[LIGHTMAPTINT]->IsDefined() ) + { + params[LIGHTMAPTINT]->SetFloatValue( 1.0f ); + } + + if( !params[ENVMAPTINT]->IsDefined() ) + { + params[ENVMAPTINT]->SetVecValue( 1.0f, 1.0f, 1.0f ); + } + + // No texture means no self-illum or env mask in base alpha + if ( !params[BASETEXTURE]->IsDefined() ) + { + CLEAR_FLAGS( MATERIAL_VAR_BASEALPHAENVMAPMASK ); + } + + // If in decal mode, no debug override... + if (IS_FLAG_SET(MATERIAL_VAR_DECAL)) + { + SET_FLAGS( MATERIAL_VAR_NO_DEBUG_OVERRIDE ); + } + } + + SHADER_INIT + { + if (params[BASETEXTURE]->IsDefined()) + { + LoadTexture( BASETEXTURE ); + + if (!params[BASETEXTURE]->GetTextureValue()->IsTranslucent()) + { + if (IS_FLAG_SET(MATERIAL_VAR_BASEALPHAENVMAPMASK)) + CLEAR_FLAGS( MATERIAL_VAR_BASEALPHAENVMAPMASK ); + } + } + + if (params[DETAIL]->IsDefined()) + { + LoadTexture( DETAIL ); + } + + // Don't alpha test if the alpha channel is used for other purposes + if (IS_FLAG_SET(MATERIAL_VAR_BASEALPHAENVMAPMASK) ) + CLEAR_FLAGS( MATERIAL_VAR_ALPHATEST ); + + if (params[ENVMAP]->IsDefined()) + { + if( !IS_FLAG_SET(MATERIAL_VAR_ENVMAPSPHERE) ) + LoadCubeMap( ENVMAP ); + else + LoadTexture( ENVMAP ); + + if( !g_pHardwareConfig->SupportsCubeMaps() ) + { + SET_FLAGS( MATERIAL_VAR_ENVMAPSPHERE ); + } + } + } + + SHADER_FALLBACK + { + // The only thing we can't do here is masked env-mapped + if (g_pHardwareConfig->GetSamplerCount() < 2) + { + return "LightmappedTwoTexture_DX5"; + } + return 0; + } + + + // Can't use the normal detail pass since we're modulating by the detail texture + // and because we're using the secondary texture coordinate + void DrawBaseTimesDetail( IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow ) + { + // Base + SHADOW_STATE + { + // alpha test + pShaderShadow->EnableAlphaTest( IS_FLAG_SET(MATERIAL_VAR_ALPHATEST) ); + + // Alpha blending, enable alpha blending if the detail texture is translucent + bool detailIsTranslucent = TextureIsTranslucent( DETAIL, false ); + if ( detailIsTranslucent ) + { + 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 + { + SetDefaultBlendingShadowState( BASETEXTURE, true ); + } + + // independently configure alpha and color + pShaderShadow->EnableAlphaPipe( true ); + + // Here's the color states (NOTE: SHADER_DRAW_COLOR == use Vertex Color) + pShaderShadow->EnableConstantColor( IsColorModulating() ); + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + + // Here's the alpha states + pShaderShadow->EnableConstantAlpha( IsAlphaModulating() ); + pShaderShadow->EnableVertexAlpha( IS_FLAG_SET(MATERIAL_VAR_VERTEXALPHA) ); + pShaderShadow->EnableTextureAlpha( SHADER_TEXTURE_STAGE0, TextureIsTranslucent(BASETEXTURE, true) ); + pShaderShadow->EnableTextureAlpha( SHADER_TEXTURE_STAGE1, detailIsTranslucent ); + + int flags = SHADER_DRAW_POSITION | SHADER_DRAW_TEXCOORD0 | SHADER_DRAW_SECONDARY_TEXCOORD1; + if (IS_FLAG_SET(MATERIAL_VAR_VERTEXCOLOR)) + flags |= SHADER_DRAW_COLOR; + pShaderShadow->DrawFlags( flags ); + DefaultFog(); + } + DYNAMIC_STATE + { + SetFixedFunctionTextureTransform( MATERIAL_TEXTURE0, BASETEXTURETRANSFORM ); + SetFixedFunctionTextureScale( MATERIAL_TEXTURE1, DETAILSCALE ); + BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME ); + BindTexture( SHADER_SAMPLER1, DETAIL ); + SetModulationDynamicState(); + } + Draw(); + + SHADOW_STATE + { + pShaderShadow->EnableAlphaPipe( false ); + } + } + + + SHADER_DRAW + { + // Pass 1 : Base + env + DrawBaseTimesDetail( params, pShaderAPI, pShaderShadow ); + + // Pass 2 : * lightmap + FixedFunctionMultiplyByLightmapPass( BASETEXTURE, FRAME, BASETEXTURETRANSFORM, params[LIGHTMAPTINT]->GetFloatValue() ); + + // Pass 3 : + env + bool envDefined = params[ENVMAP]->IsTexture(); + if (envDefined) + { + FixedFunctionAdditiveMaskedEnvmapPass( + ENVMAP, BASETEXTURE, BASETEXTURE, + ENVMAPFRAME, FRAME, FRAME, + BASETEXTURETRANSFORM, ENVMAPMASKSCALE, ENVMAPTINT ); + } + } +END_SHADER diff --git a/materialsystem/stdshaders/shatteredglass_dx8.cpp b/materialsystem/stdshaders/shatteredglass_dx8.cpp new file mode 100644 index 0000000..e62a05e --- /dev/null +++ b/materialsystem/stdshaders/shatteredglass_dx8.cpp @@ -0,0 +1,211 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: Lightmap only shader +// +// $Header: $ +// $NoKeywords: $ +//=============================================================================// + + +#include "BaseVSShader.h" +#include "shatteredglass.inc" +#include "shatteredglass_envmap.inc" +#include "shatteredglass_envmapsphere.inc" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +BEGIN_VS_SHADER( ShatteredGlass_DX8, + "Help for ShatteredGlass_DX8" ) + + BEGIN_SHADER_PARAMS + SHADER_PARAM( DETAIL, SHADER_PARAM_TYPE_TEXTURE, "shadertest/Detail", "detail" ) + SHADER_PARAM( DETAILTRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "detail scale" ) + SHADER_PARAM( ENVMAP, SHADER_PARAM_TYPE_TEXTURE, "shadertest/shadertest_env", "envmap" ) + SHADER_PARAM( ENVMAPFRAME, SHADER_PARAM_TYPE_INTEGER, "", "" ) + SHADER_PARAM( ENVMAPTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "envmap tint" ) + SHADER_PARAM( UNLITFACTOR, SHADER_PARAM_TYPE_FLOAT, "0.7", "0.0 == multiply by lightmap, 1.0 == multiply by 1" ) + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + if( !params[ENVMAPTINT]->IsDefined() ) + { + params[ENVMAPTINT]->SetVecValue( 1.0f, 1.0f, 1.0f ); + } + + if( !params[UNLITFACTOR]->IsDefined() ) + { + params[UNLITFACTOR]->SetFloatValue( 0.3f ); + } + + // No texture means no self-illum or env mask in base alpha + if ( !params[BASETEXTURE]->IsDefined() ) + { + CLEAR_FLAGS( MATERIAL_VAR_BASEALPHAENVMAPMASK ); + } + + // If in decal mode, no debug override... + if (IS_FLAG_SET(MATERIAL_VAR_DECAL)) + { + SET_FLAGS( MATERIAL_VAR_NO_DEBUG_OVERRIDE ); + } + } + + SHADER_FALLBACK + { + if ( IsPC() && g_pHardwareConfig->GetDXSupportLevel() < 80 ) + { + return "ShatteredGlass_DX7"; + } + return 0; + } + + SHADER_INIT + { + if ( params[BASETEXTURE]->IsDefined() ) + { + LoadTexture( BASETEXTURE ); + + if ( !params[BASETEXTURE]->GetTextureValue()->IsTranslucent() ) + { + if ( IS_FLAG_SET( MATERIAL_VAR_BASEALPHAENVMAPMASK ) ) + { + CLEAR_FLAGS( MATERIAL_VAR_BASEALPHAENVMAPMASK ); + } + } + } + + if ( params[DETAIL]->IsDefined() ) + { + LoadTexture( DETAIL ); + } + + if ( params[ENVMAP]->IsDefined()) + { + LoadCubeMap( ENVMAP ); + } + } + + SHADER_DRAW + { + bool bHasEnvmap = params[ENVMAP]->IsTexture(); + bool bHasVertexColor = IS_FLAG_SET(MATERIAL_VAR_VERTEXCOLOR); + + // Base + SHADOW_STATE + { + // alpha test + pShaderShadow->EnableAlphaTest( IS_FLAG_SET(MATERIAL_VAR_ALPHATEST) ); + + // Alpha blending, enable alpha blending if the detail texture is translucent + bool detailIsTranslucent = TextureIsTranslucent( DETAIL, false ); + if ( detailIsTranslucent ) + { + 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 + { + SetDefaultBlendingShadowState( BASETEXTURE, true ); + } + + // Base texture and envmapmask + unsigned int flags = VERTEX_POSITION; + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + + // Lightmap + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + + // Detail texture + pShaderShadow->EnableTexture( SHADER_SAMPLER3, true ); + + // Envmap + if ( bHasEnvmap ) + { + flags |= VERTEX_NORMAL; + pShaderShadow->EnableTexture( SHADER_SAMPLER2, true ); + } + + if ( bHasVertexColor ) + { + flags |= VERTEX_COLOR; + } + + pShaderShadow->VertexShaderVertexFormat( flags, 3, 0, 0 ); + + Assert( !bHasVertexColor ); + if ( !bHasEnvmap ) + { + shatteredglass_Static_Index vshIndex; + pShaderShadow->SetVertexShader( "shatteredglass", vshIndex.GetIndex() ); + + pShaderShadow->SetPixelShader( "shatteredglass" ); + } + else + { + if ( !IS_FLAG_SET(MATERIAL_VAR_ENVMAPSPHERE) ) + { + shatteredglass_envmap_Static_Index vshIndex; + pShaderShadow->SetVertexShader( "shatteredglass_envmap", vshIndex.GetIndex() ); + } + else + { + shatteredglass_envmapsphere_Static_Index vshIndex; + pShaderShadow->SetVertexShader( "shatteredglass_envmapsphere", vshIndex.GetIndex() ); + } + pShaderShadow->SetPixelShader( "shatteredglass_envmap" ); + } + DefaultFog(); + } + DYNAMIC_STATE + { + SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, BASETEXTURETRANSFORM ); + SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_2, DETAILTRANSFORM ); + + BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME ); + pShaderAPI->BindStandardTexture( SHADER_SAMPLER1, TEXTURE_LIGHTMAP ); + BindTexture( SHADER_SAMPLER3, DETAIL ); + + if( !bHasEnvmap ) + { + shatteredglass_Dynamic_Index vshIndex; + vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() ); + } + else + { + BindTexture( SHADER_SAMPLER2, ENVMAP, ENVMAPFRAME ); + if ( !IS_FLAG_SET(MATERIAL_VAR_ENVMAPSPHERE) ) + { + shatteredglass_envmap_Dynamic_Index vshIndex; + vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() ); + } + else + { + shatteredglass_envmapsphere_Dynamic_Index vshIndex; + vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() ); + } + } + + if (IS_FLAG_SET(MATERIAL_VAR_ENVMAPSPHERE) || IS_FLAG_SET(MATERIAL_VAR_ENVMAPCAMERASPACE)) + { + LoadViewMatrixIntoVertexShaderConstant( VERTEX_SHADER_VIEWMODEL ); + } + + SetModulationVertexShaderDynamicState(); + EnablePixelShaderOverbright( 0, true, true ); + SetPixelShaderConstant( 2, ENVMAPTINT ); + + // Blend between lightmap + unlit based on the unlit factor to make it look better + float flUnlitFactor[4]; + flUnlitFactor[0] = flUnlitFactor[1] = flUnlitFactor[2] = flUnlitFactor[3] = params[UNLITFACTOR]->GetFloatValue(); + pShaderAPI->SetPixelShaderConstant( 3, flUnlitFactor, 1 ); + } + Draw(); + } +END_SHADER diff --git a/materialsystem/stdshaders/showz.cpp b/materialsystem/stdshaders/showz.cpp new file mode 100644 index 0000000..3c3cb57 --- /dev/null +++ b/materialsystem/stdshaders/showz.cpp @@ -0,0 +1,98 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: Visualize shadow z buffers. Designed to be used when drawing a screen-aligned +// quad with a floating-point z-buffer so that the large z-range is divided down +// into visual range of grayscale colors. +// +// $NoKeywords: $ +//=============================================================================// + +#include "convar.h" +#include "BaseVSShader.h" + +#include "showz_vs20.inc" +#include "showz_ps20.inc" +#include "showz_ps20b.inc" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +static ConVar r_showz_power( "r_showz_power", "1.0f", FCVAR_CHEAT ); + +BEGIN_VS_SHADER_FLAGS( showz, "Help for ShowZ", SHADER_NOT_EDITABLE ) + BEGIN_SHADER_PARAMS + SHADER_PARAM( ALPHADEPTH, SHADER_PARAM_TYPE_INTEGER, "0", "Depth is stored in alpha channel" ) + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + if ( !params[ALPHADEPTH]->IsDefined() ) + { + params[ALPHADEPTH]->SetIntValue( 0 ); + } + } + + SHADER_FALLBACK + { +// if ( g_pHardwareConfig->GetDXSupportLevel() < 90 ) +// return "Wireframe"; + return 0; + } + + SHADER_INIT + { + } + + SHADER_DRAW + { + SHADOW_STATE + { + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + + DECLARE_STATIC_VERTEX_SHADER( showz_vs20 ); + SET_STATIC_VERTEX_SHADER( showz_vs20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_STATIC_PIXEL_SHADER( showz_ps20b ); + SET_STATIC_PIXEL_SHADER_COMBO( DEPTH_IN_ALPHA, params[ALPHADEPTH]->GetIntValue() ); + SET_STATIC_PIXEL_SHADER( showz_ps20b ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( showz_ps20 ); + SET_STATIC_PIXEL_SHADER_COMBO( DEPTH_IN_ALPHA, params[ALPHADEPTH]->GetIntValue() ); + SET_STATIC_PIXEL_SHADER( showz_ps20 ); + } + + pShaderShadow->VertexShaderVertexFormat( VERTEX_POSITION, 1, 0, 0 ); + + pShaderShadow->EnableSRGBWrite( true ); // The back buffer is sRGB, we should always set this true! + } + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME ); // Bind shadow depth map + + DECLARE_DYNAMIC_VERTEX_SHADER( showz_vs20 ); + SET_DYNAMIC_VERTEX_SHADER( showz_vs20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_DYNAMIC_PIXEL_SHADER( showz_ps20b ); + SET_DYNAMIC_PIXEL_SHADER( showz_ps20b ); + } + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( showz_ps20 ); + SET_DYNAMIC_PIXEL_SHADER( showz_ps20 ); + } + + Vector4D C0; + C0.x = r_showz_power.GetFloat(); + + pShaderAPI->SetPixelShaderConstant( 0, C0.Base(), 1 ); + } + Draw(); + } +END_SHADER + diff --git a/materialsystem/stdshaders/showz_ps2x.fxc b/materialsystem/stdshaders/showz_ps2x.fxc new file mode 100644 index 0000000..bc45e1d --- /dev/null +++ b/materialsystem/stdshaders/showz_ps2x.fxc @@ -0,0 +1,34 @@ +// STATIC: "DEPTH_IN_ALPHA" "0..1" +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX] + +#include "common_ps_fxc.h" + +const float4 g_Parameters : register( c0 ); + +sampler DepthTextureSampler : register( s0 ); // Scalar shadow depth map + +float4 main( float2 baseTexCoord : TEXCOORD0 ) : COLOR +{ + float fDepth = 0; + +# if (DEPTH_IN_ALPHA == 1) + { + fDepth = tex2D( DepthTextureSampler, baseTexCoord ).a; + + } +# else + { +# if !(defined(SHADER_MODEL_PS_1_1) || defined(SHADER_MODEL_PS_1_4) || defined(SHADER_MODEL_PS_2_0)) //Minimum requirement of ps2b + { + fDepth = tex2D( DepthTextureSampler, baseTexCoord ).r; + } +# endif + } +# endif + + fDepth = pow( fDepth, g_Parameters.x ); + + return FinalOutput( float4( fDepth, fDepth, fDepth, 1.0f ), 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE ); +} + diff --git a/materialsystem/stdshaders/showz_vs20.fxc b/materialsystem/stdshaders/showz_vs20.fxc new file mode 100644 index 0000000..2bcb66d --- /dev/null +++ b/materialsystem/stdshaders/showz_vs20.fxc @@ -0,0 +1,33 @@ +//====== Copyright © 1996-2004, Valve Corporation, All rights reserved. ======= +// +// Purpose: +// +//============================================================================= + +#include "common_vs_fxc.h" + +struct VS_INPUT +{ + // If this is float4, and the input is float3, the w component defaults to one. + float4 vPos : POSITION; + float2 vBaseTexCoords : TEXCOORD0; +}; + +struct VS_OUTPUT +{ + float4 projPos : POSITION; + float2 vBaseTexCoords : TEXCOORD0; +}; + +VS_OUTPUT main( const VS_INPUT v ) +{ + VS_OUTPUT o; + + float4 projPos; + + projPos = mul( v.vPos, cModelViewProj ); + o.projPos = projPos; + + o.vBaseTexCoords = v.vBaseTexCoords; + return o; +} diff --git a/materialsystem/stdshaders/skin_dx9_helper.cpp b/materialsystem/stdshaders/skin_dx9_helper.cpp new file mode 100644 index 0000000..cc99978 --- /dev/null +++ b/materialsystem/stdshaders/skin_dx9_helper.cpp @@ -0,0 +1,990 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +// +//===========================================================================// +#include "BaseVSShader.h" +#include "skin_dx9_helper.h" +#include "convar.h" +#include "cpp_shader_constant_register_map.h" +#include "skin_vs20.inc" +#include "skin_ps20b.inc" +#include "commandbuilder.h" + +#ifndef _X360 +#include "skin_vs30.inc" +#include "skin_ps30.inc" +#endif + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +static ConVar mat_fullbright( "mat_fullbright", "0", FCVAR_CHEAT ); +static ConVar r_lightwarpidentity( "r_lightwarpidentity", "0", FCVAR_CHEAT ); +static ConVar r_rimlight( "r_rimlight", "1", FCVAR_NONE ); + +// Textures may be bound to the following samplers: +// SHADER_SAMPLER0 Base (Albedo) / Gloss in alpha +// SHADER_SAMPLER1 Specular warp (including iridescence) +// SHADER_SAMPLER2 Diffuse Lighting warp texture +// SHADER_SAMPLER3 Normal Map +// SHADER_SAMPLER4 Flashlight Shadow Depth Map +// SHADER_SAMPLER5 Normalization cube map +// SHADER_SAMPLER6 Flashlight Cookie +// SHADER_SAMPLER7 Specular exponent +// SHADER_SAMPLER8 Cubic environment map +// SHADER_SAMPLER9 Compressed wrinklemap +// SHADER_SAMPLER10 Stretched wrinklemap +// SHADER_SAMPLER11 Compressed wrinkle normal map +// SHADER_SAMPLER12 Stretched wrinkle normal map +// SHADER_SAMPLER13 Detail texture + + +//----------------------------------------------------------------------------- +// Initialize shader parameters +//----------------------------------------------------------------------------- +void InitParamsSkin_DX9( CBaseVSShader *pShader, IMaterialVar** params, const char *pMaterialName, VertexLitGeneric_DX9_Vars_t &info ) +{ + // FLASHLIGHTFIXME: Do ShaderAPI::BindFlashlightTexture + Assert( info.m_nFlashlightTexture >= 0 ); + + if ( g_pHardwareConfig->SupportsBorderColor() ) + { + params[FLASHLIGHTTEXTURE]->SetStringValue( "effects/flashlight_border" ); + } + else + { + params[FLASHLIGHTTEXTURE]->SetStringValue( "effects/flashlight001" ); + } + + // Write over $basetexture with $info.m_nBumpmap if we are going to be using diffuse normal mapping. + if( info.m_nAlbedo != -1 && g_pConfig->UseBumpmapping() && info.m_nBumpmap != -1 && params[info.m_nBumpmap]->IsDefined() && params[info.m_nAlbedo]->IsDefined() && + params[info.m_nBaseTexture]->IsDefined() ) + { + params[info.m_nBaseTexture]->SetStringValue( params[info.m_nAlbedo]->GetStringValue() ); + } + + // This shader can be used with hw skinning + SET_FLAGS2( MATERIAL_VAR2_SUPPORTS_HW_SKINNING ); + SET_FLAGS2( MATERIAL_VAR2_LIGHTING_VERTEX_LIT ); + + // No texture means no env mask in base alpha + if ( !params[info.m_nBaseTexture]->IsDefined() ) + { + CLEAR_FLAGS( MATERIAL_VAR_BASEALPHAENVMAPMASK ); + } + + // If in decal mode, no debug override... + if (IS_FLAG_SET(MATERIAL_VAR_DECAL)) + { + SET_FLAGS( MATERIAL_VAR_NO_DEBUG_OVERRIDE ); + } + + // Lots of reasons to want tangent space, since we bind a flat normal map in many cases where we don't have a bump map + bool bBump = (info.m_nBumpmap != -1) && g_pConfig->UseBumpmapping() && params[info.m_nBumpmap]->IsDefined(); + bool bEnvMap = (info.m_nEnvmap != -1) && params[info.m_nEnvmap]->IsDefined(); + bool bDiffuseWarp = (info.m_nDiffuseWarpTexture != -1) && params[info.m_nDiffuseWarpTexture]->IsDefined(); + bool bPhong = (info.m_nPhong != -1) && params[info.m_nPhong]->IsDefined(); + if( bBump || bEnvMap || bDiffuseWarp || bPhong ) + { + SET_FLAGS2( MATERIAL_VAR2_NEEDS_TANGENT_SPACES ); + } + else + { + CLEAR_FLAGS( MATERIAL_VAR_NORMALMAPALPHAENVMAPMASK ); + } + + if ( ( info.m_nSelfIllumFresnel != -1 ) && ( !params[info.m_nSelfIllumFresnel]->IsDefined() ) ) + { + params[info.m_nSelfIllumFresnel]->SetIntValue( 0 ); + } + + if ( ( info.m_nSelfIllumFresnelMinMaxExp != -1 ) && ( !params[info.m_nSelfIllumFresnelMinMaxExp]->IsDefined() ) ) + { + params[info.m_nSelfIllumFresnelMinMaxExp]->SetVecValue( 0.0f, 1.0f, 1.0f ); + } + + if ( ( info.m_nBaseMapAlphaPhongMask != -1 ) && ( !params[info.m_nBaseMapAlphaPhongMask]->IsDefined() ) ) + { + params[info.m_nBaseMapAlphaPhongMask]->SetIntValue( 0 ); + } + + if ( ( info.m_nEnvmapFresnel != -1 ) && ( !params[info.m_nEnvmapFresnel]->IsDefined() ) ) + { + params[info.m_nEnvmapFresnel]->SetFloatValue( 0 ); + } +} + +//----------------------------------------------------------------------------- +// Initialize shader +//----------------------------------------------------------------------------- +void InitSkin_DX9( CBaseVSShader *pShader, IMaterialVar** params, VertexLitGeneric_DX9_Vars_t &info ) +{ + Assert( info.m_nFlashlightTexture >= 0 ); + pShader->LoadTexture( info.m_nFlashlightTexture, TEXTUREFLAGS_SRGB ); + + bool bIsBaseTextureTranslucent = false; + if ( params[info.m_nBaseTexture]->IsDefined() ) + { + pShader->LoadTexture( info.m_nBaseTexture, TEXTUREFLAGS_SRGB ); + + if ( params[info.m_nBaseTexture]->GetTextureValue()->IsTranslucent() ) + { + bIsBaseTextureTranslucent = true; + } + + if ( ( info.m_nWrinkle != -1 ) && ( info.m_nStretch != -1 ) && + params[info.m_nWrinkle]->IsDefined() && params[info.m_nStretch]->IsDefined() ) + { + pShader->LoadTexture( info.m_nWrinkle, TEXTUREFLAGS_SRGB ); + pShader->LoadTexture( info.m_nStretch, TEXTUREFLAGS_SRGB ); + } + } + + bool bHasSelfIllumMask = IS_FLAG_SET( MATERIAL_VAR_SELFILLUM ) && (info.m_nSelfIllumMask != -1) && params[info.m_nSelfIllumMask]->IsDefined(); + + // No alpha channel in any of the textures? No self illum or envmapmask + if ( !bIsBaseTextureTranslucent ) + { + bool bHasSelfIllumFresnel = IS_FLAG_SET( MATERIAL_VAR_SELFILLUM ) && ( info.m_nSelfIllumFresnel != -1 ) && ( params[info.m_nSelfIllumFresnel]->GetIntValue() != 0 ); + + // Can still be self illum with no base alpha if using one of these alternate modes + if ( !bHasSelfIllumFresnel && !bHasSelfIllumMask ) + { + CLEAR_FLAGS( MATERIAL_VAR_SELFILLUM ); + } + + CLEAR_FLAGS( MATERIAL_VAR_BASEALPHAENVMAPMASK ); + } + + if ( (info.m_nPhongExponentTexture != -1) && params[info.m_nPhongExponentTexture]->IsDefined() && + (info.m_nPhong != -1) && params[info.m_nPhong]->IsDefined() ) + { + pShader->LoadTexture( info.m_nPhongExponentTexture ); + } + + if ( (info.m_nDiffuseWarpTexture != -1) && params[info.m_nDiffuseWarpTexture]->IsDefined() && + (info.m_nPhong != -1) && params[info.m_nPhong]->IsDefined() ) + { + pShader->LoadTexture( info.m_nDiffuseWarpTexture ); + } + + if ( (info.m_nPhongWarpTexture != -1) && params[info.m_nPhongWarpTexture]->IsDefined() && + (info.m_nPhong != -1) && params[info.m_nPhong]->IsDefined() ) + { + pShader->LoadTexture( info.m_nPhongWarpTexture ); + } + + if ( info.m_nDetail != -1 && params[info.m_nDetail]->IsDefined() ) + { + int nDetailBlendMode = ( info.m_nDetailTextureCombineMode == -1 ) ? 0 : params[info.m_nDetailTextureCombineMode]->GetIntValue(); + if ( nDetailBlendMode == 0 ) // Mod2X + pShader->LoadTexture( info.m_nDetail ); + else + pShader->LoadTexture( info.m_nDetail, TEXTUREFLAGS_SRGB ); + } + + if ( g_pConfig->UseBumpmapping() ) + { + if ( (info.m_nBumpmap != -1) && params[info.m_nBumpmap]->IsDefined() ) + { + pShader->LoadBumpMap( info.m_nBumpmap ); + SET_FLAGS2( MATERIAL_VAR2_DIFFUSE_BUMPMAPPED_MODEL ); + + if ( ( info.m_nNormalWrinkle != -1 ) && ( info.m_nNormalStretch != -1 ) && + params[info.m_nNormalWrinkle]->IsDefined() && params[info.m_nNormalStretch]->IsDefined() ) + { + pShader->LoadTexture( info.m_nNormalWrinkle ); + pShader->LoadTexture( info.m_nNormalStretch ); + } + } + } + + if ( params[info.m_nEnvmap]->IsDefined() ) + { + pShader->LoadCubeMap( info.m_nEnvmap, g_pHardwareConfig->GetHDRType() == HDR_TYPE_NONE ? TEXTUREFLAGS_SRGB : 0 ); + } + + if ( bHasSelfIllumMask ) + { + pShader->LoadTexture( info.m_nSelfIllumMask ); + } +} + +class CSkin_DX9_Context : public CBasePerMaterialContextData +{ +public: + CCommandBufferBuilder< CFixedCommandStorageBuffer< 800 > > m_SemiStaticCmdsOut; + bool m_bFastPath; + +}; + +//----------------------------------------------------------------------------- +// Draws the shader +//----------------------------------------------------------------------------- +void DrawSkin_DX9_Internal( CBaseVSShader *pShader, IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow, + bool bHasFlashlight, VertexLitGeneric_DX9_Vars_t &info, VertexCompressionType_t vertexCompression, + CBasePerMaterialContextData **pContextDataPtr ) +{ + bool bHasBaseTexture = (info.m_nBaseTexture != -1) && params[info.m_nBaseTexture]->IsTexture(); + bool bHasBump = (info.m_nBumpmap != -1) && params[info.m_nBumpmap]->IsTexture(); + + bool bHasBaseTextureWrinkle = bHasBaseTexture && + (info.m_nWrinkle != -1) && params[info.m_nWrinkle]->IsTexture() && + (info.m_nStretch != -1) && params[info.m_nStretch]->IsTexture(); + + bool bHasBumpWrinkle = bHasBump && + (info.m_nNormalWrinkle != -1) && params[info.m_nNormalWrinkle]->IsTexture() && + (info.m_nNormalStretch != -1) && params[info.m_nNormalStretch]->IsTexture(); + + bool bHasVertexColor = IS_FLAG_SET( MATERIAL_VAR_VERTEXCOLOR ); + bool bHasVertexAlpha = IS_FLAG_SET( MATERIAL_VAR_VERTEXALPHA ); + bool bIsAlphaTested = IS_FLAG_SET( MATERIAL_VAR_ALPHATEST ) != 0; + bool bHasSelfIllum = IS_FLAG_SET( MATERIAL_VAR_SELFILLUM ) != 0; + bool bHasSelfIllumFresnel = ( bHasSelfIllum ) && ( info.m_nSelfIllumFresnel != -1 ) && ( params[info.m_nSelfIllumFresnel]->GetIntValue() != 0 ); + bool bHasSelfIllumMask = ( bHasSelfIllum ) && (info.m_nSelfIllumMask != -1) && params[info.m_nSelfIllumMask]->IsTexture(); + + // Tie these to specular + bool bHasPhong = (info.m_nPhong != -1) && ( params[info.m_nPhong]->GetIntValue() != 0 ); + bool bHasSpecularExponentTexture = (info.m_nPhongExponentTexture != -1) && params[info.m_nPhongExponentTexture]->IsTexture(); + bool bHasPhongTintMap = bHasSpecularExponentTexture && (info.m_nPhongAlbedoTint != -1) && ( params[info.m_nPhongAlbedoTint]->GetIntValue() != 0 ); + bool bHasDiffuseWarp = (info.m_nDiffuseWarpTexture != -1) && params[info.m_nDiffuseWarpTexture]->IsTexture(); + bool bHasPhongWarp = (info.m_nPhongWarpTexture != -1) && params[info.m_nPhongWarpTexture]->IsTexture(); + bool bHasNormalMapAlphaEnvmapMask = IS_FLAG_SET( MATERIAL_VAR_NORMALMAPALPHAENVMAPMASK ); + +#if !defined( _X360 ) + bool bIsDecal = IS_FLAG_SET( MATERIAL_VAR_DECAL ); +#endif + + // Rimlight must be set to non-zero to trigger rim light combo (also requires Phong) + bool bHasRimLight = r_rimlight.GetBool() && bHasPhong && (info.m_nRimLight != -1) && ( params[info.m_nRimLight]->GetIntValue() != 0 ); + bool bHasRimMaskMap = bHasSpecularExponentTexture && bHasRimLight && (info.m_nRimMask != -1) && ( params[info.m_nRimMask]->GetIntValue() != 0 ); + + float fBlendFactor=( info.m_nDetailTextureBlendFactor == -1 )? 1 : params[info.m_nDetailTextureBlendFactor]->GetFloatValue(); + bool hasDetailTexture = ( info.m_nDetail != -1 ) && params[info.m_nDetail]->IsTexture(); + int nDetailBlendMode = ( hasDetailTexture && info.m_nDetailTextureCombineMode != -1 ) ? params[info.m_nDetailTextureCombineMode]->GetIntValue() : 0; + + bool bBlendTintByBaseAlpha = IsBoolSet( info.m_nBlendTintByBaseAlpha, params ) && !bHasSelfIllum; // Pixel shader can't do both BLENDTINTBYBASEALPHA and SELFILLUM, so let selfillum win + + float flTintReplacementAmount = GetFloatParam( info.m_nTintReplacesBaseColor, params ); + + float flPhongExponentFactor = ( info.m_nPhongExponentFactor != -1 ) ? GetFloatParam( info.m_nPhongExponentFactor, params ) : 0.0f; + const bool bHasPhongExponentFactor = flPhongExponentFactor != 0.0f; + + BlendType_t nBlendType= pShader->EvaluateBlendRequirements( bBlendTintByBaseAlpha ? -1 : info.m_nBaseTexture, true ); + + bool bFullyOpaque = (nBlendType != BT_BLENDADD) && (nBlendType != BT_BLEND) && !bIsAlphaTested && !bHasFlashlight; //dest alpha is free for special use + + CSkin_DX9_Context *pContextData = reinterpret_cast< CSkin_DX9_Context *> ( *pContextDataPtr ); + if ( ! pContextData ) + { + pContextData = new CSkin_DX9_Context; + *pContextDataPtr = pContextData; + } + + if( pShader->IsSnapshotting() ) + { + // look at color and alphamod stuff. + // Unlit generic never uses the flashlight + bool bHasEnvmap = !bHasFlashlight && params[info.m_nEnvmap]->IsTexture(); + bool bHasNormal = params[info.m_nBumpmap]->IsTexture(); + bool bCanUseBaseAlphaPhongMaskFastPath = (info.m_nBaseMapAlphaPhongMask != -1) && ( params[info.m_nBaseMapAlphaPhongMask]->GetIntValue() != 0 ); + + if ( ! ( params[info.m_nBaseTexture]->GetTextureValue()->IsTranslucent() ) ) + bCanUseBaseAlphaPhongMaskFastPath = true; + + pContextData->m_bFastPath = + (! bHasBump ) && + (! bHasSpecularExponentTexture ) && + (! bHasPhongTintMap ) && + (! bHasPhongWarp ) && + (! bHasRimLight ) && + (! hasDetailTexture ) && + bCanUseBaseAlphaPhongMaskFastPath && + (! bHasSelfIllum ) && + (! bBlendTintByBaseAlpha ); + + // Alpha test: FIXME: shouldn't this be handled in CBaseVSShader::SetInitialShadowState + pShaderShadow->EnableAlphaTest( bIsAlphaTested ); + + if( info.m_nAlphaTestReference != -1 && params[info.m_nAlphaTestReference]->GetFloatValue() > 0.0f ) + { + pShaderShadow->AlphaFunc( SHADER_ALPHAFUNC_GEQUAL, params[info.m_nAlphaTestReference]->GetFloatValue() ); + } + + int nShadowFilterMode = 0; + if( bHasFlashlight ) + { + if (params[info.m_nBaseTexture]->IsTexture()) + { + pShader->SetAdditiveBlendingShadowState( info.m_nBaseTexture, true ); + } + + if( bIsAlphaTested ) + { + // disable alpha test and use the zfunc zequals since alpha isn't guaranteed to + // be the same on both the regular pass and the flashlight pass. + pShaderShadow->EnableAlphaTest( false ); + pShaderShadow->DepthFunc( SHADER_DEPTHFUNC_EQUAL ); + } + pShaderShadow->EnableBlending( true ); + pShaderShadow->EnableDepthWrites( false ); + + // Be sure not to write to dest alpha + pShaderShadow->EnableAlphaWrites( false ); + + nShadowFilterMode = g_pHardwareConfig->GetShadowFilterMode(); // Based upon vendor and device dependent formats + } + else // not flashlight pass + { + if (params[info.m_nBaseTexture]->IsTexture()) + { + pShader->SetDefaultBlendingShadowState( info.m_nBaseTexture, true ); + } + + if ( bHasEnvmap ) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER8, true ); // Cubic environment map + if( g_pHardwareConfig->GetHDRType() == HDR_TYPE_NONE ) + { + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER8, true ); + } + } + } + + unsigned int flags = VERTEX_POSITION; + if( bHasNormal ) + { + flags |= VERTEX_NORMAL; + } + + int userDataSize = 0; + + // Always enable...will bind white if nothing specified... + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); // Base (albedo) map + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, true ); + + if ( bHasBaseTextureWrinkle || bHasBumpWrinkle ) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER9, true ); // Base (albedo) compression map + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER9, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER10, true ); // Base (albedo) expansion map + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER10, true ); + } + + if( bHasDiffuseWarp ) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER2, true ); // Diffuse warp texture + } + + if( bHasPhongWarp ) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); // Specular warp texture + } + + // Specular exponent map or dummy + pShaderShadow->EnableTexture( SHADER_SAMPLER7, true ); // Specular exponent map + + if( bHasFlashlight ) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER4, true ); // Shadow depth map + pShaderShadow->SetShadowDepthFiltering( SHADER_SAMPLER4 ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER4, false ); + pShaderShadow->EnableTexture( SHADER_SAMPLER5, true ); // Noise map + pShaderShadow->EnableTexture( SHADER_SAMPLER6, true ); // Flashlight cookie + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER6, true ); + userDataSize = 4; // tangent S + } + + // Always enable, since flat normal will be bound + pShaderShadow->EnableTexture( SHADER_SAMPLER3, true ); // Normal map + userDataSize = 4; // tangent S + pShaderShadow->EnableTexture( SHADER_SAMPLER5, true ); // Normalizing cube map + + if ( bHasBaseTextureWrinkle || bHasBumpWrinkle ) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER11, true ); // Normal compression map + pShaderShadow->EnableTexture( SHADER_SAMPLER12, true ); // Normal expansion map + } + + if ( hasDetailTexture ) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER13, true ); + if ( nDetailBlendMode != 0 ) //Not Mod2X + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER13, true ); + } + + if ( bHasSelfIllum ) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER14, true ); + } + + if( bHasVertexColor || bHasVertexAlpha ) + { + flags |= VERTEX_COLOR; + } + + pShaderShadow->EnableSRGBWrite( true ); + + // texcoord0 : base texcoord, texcoord2 : decal hw morph delta + int pTexCoordDim[3] = { 2, 0, 3 }; + int nTexCoordCount = 1; + +#ifndef _X360 + // Special morphed decal information + if ( bIsDecal && g_pHardwareConfig->HasFastVertexTextures() ) + { + nTexCoordCount = 3; + } +#endif + + // This shader supports compressed vertices, so OR in that flag: + flags |= VERTEX_FORMAT_COMPRESSED; + + pShaderShadow->VertexShaderVertexFormat( flags, nTexCoordCount, pTexCoordDim, userDataSize ); + + +#ifndef _X360 + if ( !g_pHardwareConfig->HasFastVertexTextures() ) +#endif + { + bool bUseStaticControlFlow = g_pHardwareConfig->SupportsStaticControlFlow(); + + DECLARE_STATIC_VERTEX_SHADER( skin_vs20 ); + SET_STATIC_VERTEX_SHADER_COMBO( USE_STATIC_CONTROL_FLOW, bUseStaticControlFlow ); + SET_STATIC_VERTEX_SHADER( skin_vs20 ); + + // Assume we're only going to get in here if we support 2b + DECLARE_STATIC_PIXEL_SHADER( skin_ps20b ); + SET_STATIC_PIXEL_SHADER_COMBO( FLASHLIGHT, bHasFlashlight ); + SET_STATIC_PIXEL_SHADER_COMBO( SELFILLUM, bHasSelfIllum && !bHasFlashlight ); + SET_STATIC_PIXEL_SHADER_COMBO( SELFILLUMFRESNEL, bHasSelfIllumFresnel && !bHasFlashlight ); + SET_STATIC_PIXEL_SHADER_COMBO( LIGHTWARPTEXTURE, bHasDiffuseWarp && bHasPhong ); + SET_STATIC_PIXEL_SHADER_COMBO( PHONGWARPTEXTURE, bHasPhongWarp && bHasPhong ); + SET_STATIC_PIXEL_SHADER_COMBO( WRINKLEMAP, bHasBaseTextureWrinkle || bHasBumpWrinkle ); + SET_STATIC_PIXEL_SHADER_COMBO( DETAILTEXTURE, hasDetailTexture ); + SET_STATIC_PIXEL_SHADER_COMBO( DETAIL_BLEND_MODE, nDetailBlendMode ); + SET_STATIC_PIXEL_SHADER_COMBO( RIMLIGHT, bHasRimLight ); + SET_STATIC_PIXEL_SHADER_COMBO( CUBEMAP, bHasEnvmap ); + SET_STATIC_PIXEL_SHADER_COMBO( FLASHLIGHTDEPTHFILTERMODE, nShadowFilterMode ); + SET_STATIC_PIXEL_SHADER_COMBO( CONVERT_TO_SRGB, 0 ); + SET_STATIC_PIXEL_SHADER_COMBO( FASTPATH_NOBUMP, pContextData->m_bFastPath ); + SET_STATIC_PIXEL_SHADER_COMBO( BLENDTINTBYBASEALPHA, bBlendTintByBaseAlpha ); + SET_STATIC_PIXEL_SHADER( skin_ps20b ); + } +#ifndef _X360 + else + { + // The vertex shader uses the vertex id stream + SET_FLAGS2( MATERIAL_VAR2_USES_VERTEXID ); + + DECLARE_STATIC_VERTEX_SHADER( skin_vs30 ); + SET_STATIC_VERTEX_SHADER_COMBO( DECAL, bIsDecal ); + SET_STATIC_VERTEX_SHADER( skin_vs30 ); + + DECLARE_STATIC_PIXEL_SHADER( skin_ps30 ); + SET_STATIC_PIXEL_SHADER_COMBO( FLASHLIGHT, bHasFlashlight ); + SET_STATIC_PIXEL_SHADER_COMBO( SELFILLUM, bHasSelfIllum && !bHasFlashlight ); + SET_STATIC_PIXEL_SHADER_COMBO( SELFILLUMFRESNEL, bHasSelfIllumFresnel && !bHasFlashlight ); + SET_STATIC_PIXEL_SHADER_COMBO( LIGHTWARPTEXTURE, bHasDiffuseWarp && bHasPhong ); + SET_STATIC_PIXEL_SHADER_COMBO( PHONGWARPTEXTURE, bHasPhongWarp && bHasPhong ); + SET_STATIC_PIXEL_SHADER_COMBO( WRINKLEMAP, bHasBaseTextureWrinkle || bHasBumpWrinkle ); + SET_STATIC_PIXEL_SHADER_COMBO( DETAILTEXTURE, hasDetailTexture ); + SET_STATIC_PIXEL_SHADER_COMBO( DETAIL_BLEND_MODE, nDetailBlendMode ); + SET_STATIC_PIXEL_SHADER_COMBO( RIMLIGHT, bHasRimLight ); + SET_STATIC_PIXEL_SHADER_COMBO( CUBEMAP, bHasEnvmap ); + SET_STATIC_PIXEL_SHADER_COMBO( FLASHLIGHTDEPTHFILTERMODE, nShadowFilterMode ); + SET_STATIC_PIXEL_SHADER_COMBO( CONVERT_TO_SRGB, 0 ); + SET_STATIC_PIXEL_SHADER_COMBO( FASTPATH_NOBUMP, pContextData->m_bFastPath ); + SET_STATIC_PIXEL_SHADER_COMBO( BLENDTINTBYBASEALPHA, bBlendTintByBaseAlpha ); + SET_STATIC_PIXEL_SHADER( skin_ps30 ); + } +#endif + + if( bHasFlashlight ) + { + pShader->FogToBlack(); + } + else + { + pShader->DefaultFog(); + } + + // HACK HACK HACK - enable alpha writes all the time so that we have them for underwater stuff + pShaderShadow->EnableAlphaWrites( bFullyOpaque ); + } + else // not snapshotting -- begin dynamic state + { + bool bLightingOnly = mat_fullbright.GetInt() == 2 && !IS_FLAG_SET( MATERIAL_VAR_NO_DEBUG_OVERRIDE ); + bool bHasEnvmap = !bHasFlashlight && params[info.m_nEnvmap]->IsTexture(); + + if( bHasBaseTexture ) + { + pShader->BindTexture( SHADER_SAMPLER0, info.m_nBaseTexture, info.m_nBaseTextureFrame ); + } + else + { + pShaderAPI->BindStandardTexture( SHADER_SAMPLER0, TEXTURE_WHITE ); + } + + if ( bHasBaseTextureWrinkle ) + { + pShader->BindTexture( SHADER_SAMPLER9, info.m_nWrinkle, info.m_nBaseTextureFrame ); + pShader->BindTexture( SHADER_SAMPLER10, info.m_nStretch, info.m_nBaseTextureFrame ); + } + else if ( bHasBumpWrinkle ) + { + pShader->BindTexture( SHADER_SAMPLER9, info.m_nBaseTexture, info.m_nBaseTextureFrame ); + pShader->BindTexture( SHADER_SAMPLER10, info.m_nBaseTexture, info.m_nBaseTextureFrame ); + } + + if( bHasDiffuseWarp && bHasPhong ) + { + if ( r_lightwarpidentity.GetBool() ) + { + pShaderAPI->BindStandardTexture( SHADER_SAMPLER2, TEXTURE_IDENTITY_LIGHTWARP ); + } + else + { + pShader->BindTexture( SHADER_SAMPLER2, info.m_nDiffuseWarpTexture ); + } + } + + if( bHasPhongWarp ) + { + pShader->BindTexture( SHADER_SAMPLER1, info.m_nPhongWarpTexture ); + } + + if( bHasSpecularExponentTexture && bHasPhong ) + { + pShader->BindTexture( SHADER_SAMPLER7, info.m_nPhongExponentTexture ); + } + else + { + pShaderAPI->BindStandardTexture( SHADER_SAMPLER7, TEXTURE_WHITE ); + } + + if( !g_pConfig->m_bFastNoBump ) + { + if( bHasBump ) + pShader->BindTexture( SHADER_SAMPLER3, info.m_nBumpmap, info.m_nBumpFrame ); + else + pShaderAPI->BindStandardTexture( SHADER_SAMPLER3, TEXTURE_NORMALMAP_FLAT ); + + if ( bHasBumpWrinkle ) + { + pShader->BindTexture( SHADER_SAMPLER11, info.m_nNormalWrinkle, info.m_nBumpFrame ); + pShader->BindTexture( SHADER_SAMPLER12, info.m_nNormalStretch, info.m_nBumpFrame ); + } + else if ( bHasBaseTextureWrinkle ) + { + pShader->BindTexture( SHADER_SAMPLER11, info.m_nBumpmap, info.m_nBumpFrame ); + pShader->BindTexture( SHADER_SAMPLER12, info.m_nBumpmap, info.m_nBumpFrame ); + } + } + else + { + if( bHasBump ) + { + pShaderAPI->BindStandardTexture( SHADER_SAMPLER3, TEXTURE_NORMALMAP_FLAT ); + } + if ( bHasBaseTextureWrinkle || bHasBumpWrinkle ) + { + pShaderAPI->BindStandardTexture( SHADER_SAMPLER11, TEXTURE_NORMALMAP_FLAT ); + pShaderAPI->BindStandardTexture( SHADER_SAMPLER12, TEXTURE_NORMALMAP_FLAT ); + } + } + + if ( hasDetailTexture ) + { + pShader->BindTexture( SHADER_SAMPLER13, info.m_nDetail, info.m_nDetailFrame ); + } + + if ( bHasSelfIllum ) + { + if ( bHasSelfIllumMask ) // Separate texture for self illum? + { + pShader->BindTexture( SHADER_SAMPLER14, info.m_nSelfIllumMask ); // Bind it + } + else // else + { + pShaderAPI->BindStandardTexture( SHADER_SAMPLER14, TEXTURE_BLACK ); // Bind dummy + } + } + + LightState_t lightState = { 0, false, false }; + bool bFlashlightShadows = false; + if( bHasFlashlight ) + { + Assert( info.m_nFlashlightTexture >= 0 && info.m_nFlashlightTextureFrame >= 0 ); + pShader->BindTexture( SHADER_SAMPLER6, info.m_nFlashlightTexture, info.m_nFlashlightTextureFrame ); + VMatrix worldToTexture; + ITexture *pFlashlightDepthTexture; + FlashlightState_t state = pShaderAPI->GetFlashlightStateEx( worldToTexture, &pFlashlightDepthTexture ); + bFlashlightShadows = state.m_bEnableShadows && ( pFlashlightDepthTexture != NULL ); + + SetFlashLightColorFromState( state, pShaderAPI, PSREG_FLASHLIGHT_COLOR ); + + if( pFlashlightDepthTexture && g_pConfig->ShadowDepthTexture() && state.m_bEnableShadows ) + { + pShader->BindTexture( SHADER_SAMPLER4, pFlashlightDepthTexture, 0 ); + pShaderAPI->BindStandardTexture( SHADER_SAMPLER5, TEXTURE_SHADOW_NOISE_2D ); + } + } + else // no flashlight + { + if ( bHasEnvmap ) + { + pShader->BindTexture( SHADER_SAMPLER8, info.m_nEnvmap, info.m_nEnvmapFrame ); + } + + pShaderAPI->GetDX9LightState( &lightState ); + } + + MaterialFogMode_t fogType = pShaderAPI->GetSceneFogMode(); + int fogIndex = ( fogType == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ) ? 1 : 0; + int numBones = pShaderAPI->GetCurrentNumBones(); + + // don't have an easy way to get this through to GLM, so just print it old school + //printf("\n-D- DrawSkin_DX9_Internal numBones is %d", numBones ); + + bool bWriteDepthToAlpha = false; + bool bWriteWaterFogToAlpha = false; + if( bFullyOpaque ) + { + bWriteDepthToAlpha = pShaderAPI->ShouldWriteDepthToDestAlpha(); + bWriteWaterFogToAlpha = (fogType == MATERIAL_FOG_LINEAR_BELOW_FOG_Z); + AssertMsg( !(bWriteDepthToAlpha && bWriteWaterFogToAlpha), "Can't write two values to alpha at the same time." ); + } + +#ifndef _X360 + if ( !g_pHardwareConfig->HasFastVertexTextures() ) +#endif + { + bool bUseStaticControlFlow = g_pHardwareConfig->SupportsStaticControlFlow(); + + DECLARE_DYNAMIC_VERTEX_SHADER( skin_vs20 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( DOWATERFOG, fogIndex ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, numBones > 0 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( LIGHTING_PREVIEW, pShaderAPI->GetIntRenderingParameter(INT_RENDERPARM_ENABLE_FIXED_LIGHTING)!=0); + SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( NUM_LIGHTS, bUseStaticControlFlow ? 0 : lightState.m_nNumLights ); + SET_DYNAMIC_VERTEX_SHADER( skin_vs20 ); + + DECLARE_DYNAMIC_PIXEL_SHADER( skin_ps20b ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( NUM_LIGHTS, lightState.m_nNumLights ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( WRITEWATERFOGTODESTALPHA, bWriteWaterFogToAlpha ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( WRITE_DEPTH_TO_DESTALPHA, bWriteDepthToAlpha ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( FLASHLIGHTSHADOWS, bFlashlightShadows ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PHONG_USE_EXPONENT_FACTOR, bHasPhongExponentFactor ); + SET_DYNAMIC_PIXEL_SHADER( skin_ps20b ); + } +#ifndef _X360 + else + { + pShader->SetHWMorphVertexShaderState( VERTEX_SHADER_SHADER_SPECIFIC_CONST_6, VERTEX_SHADER_SHADER_SPECIFIC_CONST_7, SHADER_VERTEXTEXTURE_SAMPLER0 ); + + DECLARE_DYNAMIC_VERTEX_SHADER( skin_vs30 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( DOWATERFOG, fogIndex ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, numBones > 0 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( LIGHTING_PREVIEW, pShaderAPI->GetIntRenderingParameter(INT_RENDERPARM_ENABLE_FIXED_LIGHTING)!=0); + SET_DYNAMIC_VERTEX_SHADER_COMBO( MORPHING, pShaderAPI->IsHWMorphingEnabled() ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression ); + SET_DYNAMIC_VERTEX_SHADER( skin_vs30 ); + + DECLARE_DYNAMIC_PIXEL_SHADER( skin_ps30 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( NUM_LIGHTS, lightState.m_nNumLights ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( WRITEWATERFOGTODESTALPHA, bWriteWaterFogToAlpha ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( WRITE_DEPTH_TO_DESTALPHA, bWriteDepthToAlpha ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( FLASHLIGHTSHADOWS, bFlashlightShadows ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PHONG_USE_EXPONENT_FACTOR, bHasPhongExponentFactor ); + SET_DYNAMIC_PIXEL_SHADER( skin_ps30 ); + + bool bUnusedTexCoords[3] = { false, false, !pShaderAPI->IsHWMorphingEnabled() || !bIsDecal }; + pShaderAPI->MarkUnusedVertexFields( 0, 3, bUnusedTexCoords ); + } +#endif + + pShader->SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, info.m_nBaseTextureTransform ); + + if( bHasBump ) + { + pShader->SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_2, info.m_nBumpTransform ); + } + + if ( hasDetailTexture ) + { + if ( IS_PARAM_DEFINED( info.m_nDetailTextureTransform ) ) + pShader->SetVertexShaderTextureScaledTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_4, + info.m_nDetailTextureTransform, + info.m_nDetailScale ); + else + pShader->SetVertexShaderTextureScaledTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_4, + info.m_nBaseTextureTransform, + info.m_nDetailScale ); + } + + pShader->SetModulationPixelShaderDynamicState_LinearColorSpace( 1 ); + pShader->SetPixelShaderConstant_W( PSREG_SELFILLUMTINT, info.m_nSelfIllumTint, fBlendFactor ); + bool bInvertPhongMask = ( info.m_nInvertPhongMask != -1 ) && ( params[info.m_nInvertPhongMask]->GetIntValue() != 0 ); + float fInvertPhongMask = bInvertPhongMask ? 1 : 0; + + bool bHasBaseAlphaPhongMask = (info.m_nBaseMapAlphaPhongMask != -1) && ( params[info.m_nBaseMapAlphaPhongMask]->GetIntValue() != 0 ); + float fHasBaseAlphaPhongMask = bHasBaseAlphaPhongMask ? 1 : 0; + // Controls for lerp-style paths through shader code + float vShaderControls[4] = { fHasBaseAlphaPhongMask, 0.0f/*unused*/, flTintReplacementAmount, fInvertPhongMask }; + pShaderAPI->SetPixelShaderConstant( PSREG_CONSTANT_27, vShaderControls, 1 ); + + if ( hasDetailTexture ) + { +#if 0 // needs constant change + if ( info.m_nDetailTint != -1 ) + pShader->SetPixelShaderConstantGammaToLinear( 10, info.m_nDetailTint ); + else + { + float boring_tint[4]={1,1,1,1}; + pShaderAPI->SetPixelShaderConstant( 10, boring_tint, 1 ); + } +#endif + } + + if ( bHasSelfIllumFresnel && !bHasFlashlight ) + { + float vConstScaleBiasExp[4] = { 1.0f, 0.0f, 1.0f, 0.0f }; + float flMin = IS_PARAM_DEFINED( info.m_nSelfIllumFresnelMinMaxExp ) ? params[info.m_nSelfIllumFresnelMinMaxExp]->GetVecValue()[0] : 0.0f; + float flMax = IS_PARAM_DEFINED( info.m_nSelfIllumFresnelMinMaxExp ) ? params[info.m_nSelfIllumFresnelMinMaxExp]->GetVecValue()[1] : 1.0f; + float flExp = IS_PARAM_DEFINED( info.m_nSelfIllumFresnelMinMaxExp ) ? params[info.m_nSelfIllumFresnelMinMaxExp]->GetVecValue()[2] : 1.0f; + + vConstScaleBiasExp[1] = ( flMax != 0.0f ) ? ( flMin / flMax ) : 0.0f; // Bias + vConstScaleBiasExp[0] = 1.0f - vConstScaleBiasExp[1]; // Scale + vConstScaleBiasExp[2] = flExp; // Exp + vConstScaleBiasExp[3] = flMax; // Brightness + + pShaderAPI->SetPixelShaderConstant( PSREG_SELFILLUM_SCALE_BIAS_EXP, vConstScaleBiasExp, 1 ); + } + + pShader->SetAmbientCubeDynamicStateVertexShader(); + + if( !bHasFlashlight ) + { + pShaderAPI->BindStandardTexture( SHADER_SAMPLER5, TEXTURE_NORMALIZATION_CUBEMAP_SIGNED ); + + // Setting .x to 1 means to apply Fresnel to env map. Setting w to 1 means use separate selfillummask + float vEnvMapFresnel_SelfIllumMask[4] = {0.0f, 0.0f, 0.0f, 0.0f}; + vEnvMapFresnel_SelfIllumMask[3] = bHasSelfIllumMask ? 1.0f : 0.0f; + + if( bHasEnvmap ) + { + float vEnvMapTint_MaskControl[4] = {1.0f, 1.0f, 1.0f, 0.0f}; + + // If we have a tint, grab it + if ( (info.m_nEnvmapTint != -1) && params[info.m_nEnvmapTint]->IsDefined() ) + params[info.m_nEnvmapTint]->GetVecValue(vEnvMapTint_MaskControl, 3); + + // Set control for source of env map mask (normal alpha or base alpha) + vEnvMapTint_MaskControl[3] = bHasNormalMapAlphaEnvmapMask ? 1.0f : 0.0f; + + if ( (info.m_nEnvmapFresnel != -1) && params[info.m_nEnvmapFresnel]->IsDefined() ) + vEnvMapFresnel_SelfIllumMask[0] = params[info.m_nEnvmapFresnel]->GetFloatValue(); + + // Handle mat_fullbright 2 (diffuse lighting only with 50% gamma space basetexture) + if( bLightingOnly ) + { + vEnvMapTint_MaskControl[0] = vEnvMapTint_MaskControl[1] = vEnvMapTint_MaskControl[2] = 0.0f; + } + + pShaderAPI->SetPixelShaderConstant( PSREG_ENVMAP_TINT__SHADOW_TWEAKS, vEnvMapTint_MaskControl, 1 ); + } + + pShaderAPI->SetPixelShaderConstant( PSREG_ENVMAP_FRESNEL__SELFILLUMMASK, vEnvMapFresnel_SelfIllumMask, 1 ); + } + + pShaderAPI->SetPixelShaderStateAmbientLightCube( PSREG_AMBIENT_CUBE, !lightState.m_bAmbientLight ); // Force to black if not bAmbientLight + pShaderAPI->CommitPixelShaderLighting( PSREG_LIGHT_INFO_ARRAY ); + + // Pack Phong exponent in with the eye position + float vEyePos_SpecExponent[4], vFresnelRanges_SpecBoost[4] = {1, 0.5, 1, 1}, vRimBoost[4] = {1, 1, 1, 1}; + float vSpecularTint[4] = {1, 1, 1, 4}; + pShaderAPI->GetWorldSpaceCameraPosition( vEyePos_SpecExponent ); + + // If we have a phong exponent factor, then use that as a multiplier against the texture. + if ( bHasPhongExponentFactor ) + { + vEyePos_SpecExponent[3] = flPhongExponentFactor; + } + else + { + // Use the alpha channel of the normal map for the exponent by default + vEyePos_SpecExponent[3] = -1.f; + if ( (info.m_nPhongExponent != -1) && params[info.m_nPhongExponent]->IsDefined() ) + { + float fValue = params[info.m_nPhongExponent]->GetFloatValue(); + if ( fValue > 0.f ) + { + // Nonzero value in material overrides map channel + vEyePos_SpecExponent[3] = fValue; + } + } + } + + // Get the tint parameter + if ( (info.m_nPhongTint != -1) && params[info.m_nPhongTint]->IsDefined() ) + { + params[info.m_nPhongTint]->GetVecValue(vSpecularTint, 3); + } + + // Get the rim light power (goes in w of Phong tint) + if ( bHasRimLight && (info.m_nRimLightPower != -1) && params[info.m_nRimLightPower]->IsDefined() ) + { + vSpecularTint[3] = params[info.m_nRimLightPower]->GetFloatValue(); + vSpecularTint[3] = max(vSpecularTint[3], 1.0f); // Make sure this is at least 1 + } + + // Get the rim boost (goes in w of flashlight position) + if ( bHasRimLight && (info.m_nRimLightBoost != -1) && params[info.m_nRimLightBoost]->IsDefined() ) + { + vRimBoost[3] = params[info.m_nRimLightBoost]->GetFloatValue(); + } + + if ( !bHasFlashlight ) + { + float vRimMaskControl[4] = {0, 0, 0, 0}; // Only x is relevant in shader code + vRimMaskControl[0] = bHasRimMaskMap ? params[info.m_nRimMask]->GetFloatValue() : 0.0f; + + // Rim mask...if this is true, use alpha channel of spec exponent texture to mask the rim term + pShaderAPI->SetPixelShaderConstant( PSREG_FLASHLIGHT_ATTENUATION, vRimMaskControl, 1 ); + } + + // If it's all zeros, there was no constant tint in the vmt + if ( (vSpecularTint[0] == 0.0f) && (vSpecularTint[1] == 0.0f) && (vSpecularTint[2] == 0.0f) ) + { + if ( bHasPhongTintMap ) // If we have a map to use, tell the shader + { + vSpecularTint[0] = -1; + } + else // Otherwise, just tint with white + { + vSpecularTint[0] = 1.0f; + vSpecularTint[1] = 1.0f; + vSpecularTint[2] = 1.0f; + } + } + + // handle mat_fullbright 2 (diffuse lighting only) + if( bLightingOnly ) + { + // BASETEXTURE + if( bHasSelfIllum && !bHasFlashlight ) + { + pShaderAPI->BindStandardTexture( SHADER_SAMPLER0, TEXTURE_GREY_ALPHA_ZERO ); + } + else + { + pShaderAPI->BindStandardTexture( SHADER_SAMPLER0, TEXTURE_GREY ); + } + + // DETAILTEXTURE + if ( hasDetailTexture ) + { + pShaderAPI->BindStandardTexture( SHADER_SAMPLER13, TEXTURE_GREY ); + } + + // turn off specularity + vSpecularTint[0] = vSpecularTint[1] = vSpecularTint[2] = 0.0f; + } + + if ( (info.m_nPhongFresnelRanges != -1) && params[info.m_nPhongFresnelRanges]->IsDefined() ) + { + params[info.m_nPhongFresnelRanges]->GetVecValue( vFresnelRanges_SpecBoost, 3 ); // Grab optional Fresnel range parameters + // Change fresnel range encoding from (min, mid, max) to ((mid-min)*2, mid, (max-mid)*2) + vFresnelRanges_SpecBoost[0] = (vFresnelRanges_SpecBoost[1] - vFresnelRanges_SpecBoost[0]) * 2; + vFresnelRanges_SpecBoost[2] = (vFresnelRanges_SpecBoost[2] - vFresnelRanges_SpecBoost[1]) * 2; + } + + if ( (info.m_nPhongBoost != -1 ) && params[info.m_nPhongBoost]->IsDefined()) // Grab optional Phong boost param + vFresnelRanges_SpecBoost[3] = params[info.m_nPhongBoost]->GetFloatValue(); + else + vFresnelRanges_SpecBoost[3] = 1.0f; + + pShaderAPI->SetPixelShaderConstant( PSREG_EYEPOS_SPEC_EXPONENT, vEyePos_SpecExponent, 1 ); + pShaderAPI->SetPixelShaderConstant( PSREG_FRESNEL_SPEC_PARAMS, vFresnelRanges_SpecBoost, 1 ); + + pShaderAPI->SetPixelShaderConstant( PSREG_FLASHLIGHT_POSITION_RIM_BOOST, vRimBoost, 1 ); // Rim boost in w on non-flashlight pass + + pShaderAPI->SetPixelShaderConstant( PSREG_SPEC_RIM_PARAMS, vSpecularTint, 1 ); + pShaderAPI->SetPixelShaderFogParams( PSREG_FOG_PARAMS ); + + // flashlightfixme: put this in common code. + if( bHasFlashlight ) + { + VMatrix worldToTexture; + float atten[4], pos[4], tweaks[4]; + + const FlashlightState_t &flashlightState = pShaderAPI->GetFlashlightState( worldToTexture ); + SetFlashLightColorFromState( flashlightState, pShaderAPI, PSREG_FLASHLIGHT_COLOR ); + + pShader->BindTexture( SHADER_SAMPLER6, flashlightState.m_pSpotlightTexture, flashlightState.m_nSpotlightTextureFrame ); + + atten[0] = flashlightState.m_fConstantAtten; // Set the flashlight attenuation factors + atten[1] = flashlightState.m_fLinearAtten; + atten[2] = flashlightState.m_fQuadraticAtten; + atten[3] = flashlightState.m_FarZ; + pShaderAPI->SetPixelShaderConstant( PSREG_FLASHLIGHT_ATTENUATION, atten, 1 ); + + pos[0] = flashlightState.m_vecLightOrigin[0]; // Set the flashlight origin + pos[1] = flashlightState.m_vecLightOrigin[1]; + pos[2] = flashlightState.m_vecLightOrigin[2]; + pShaderAPI->SetPixelShaderConstant( PSREG_FLASHLIGHT_POSITION_RIM_BOOST, pos, 1 ); // steps on rim boost + + pShaderAPI->SetPixelShaderConstant( PSREG_FLASHLIGHT_TO_WORLD_TEXTURE, worldToTexture.Base(), 4 ); + + // Tweaks associated with a given flashlight + tweaks[0] = ShadowFilterFromState( flashlightState ); + tweaks[1] = ShadowAttenFromState( flashlightState ); + pShader->HashShadow2DJitter( flashlightState.m_flShadowJitterSeed, &tweaks[2], &tweaks[3] ); + pShaderAPI->SetPixelShaderConstant( PSREG_ENVMAP_TINT__SHADOW_TWEAKS, tweaks, 1 ); + + // Dimensions of screen, used for screen-space noise map sampling + float vScreenScale[4] = {1280.0f / 32.0f, 720.0f / 32.0f, 0, 0}; + int nWidth, nHeight; + pShaderAPI->GetBackBufferDimensions( nWidth, nHeight ); + vScreenScale[0] = (float) nWidth / 32.0f; + vScreenScale[1] = (float) nHeight / 32.0f; + pShaderAPI->SetPixelShaderConstant( PSREG_FLASHLIGHT_SCREEN_SCALE, vScreenScale, 1 ); + + if ( IsX360() ) + { + pShaderAPI->SetBooleanPixelShaderConstant( 0, &flashlightState.m_nShadowQuality, 1 ); + } + } + } + pShader->Draw(); +} + + +//----------------------------------------------------------------------------- +// Draws the shader +//----------------------------------------------------------------------------- +extern ConVar r_flashlight_version2; +void DrawSkin_DX9( CBaseVSShader *pShader, IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow, + VertexLitGeneric_DX9_Vars_t &info, VertexCompressionType_t vertexCompression, + CBasePerMaterialContextData **pContextDataPtr ) + +{ + bool bHasFlashlight = pShader->UsingFlashlight( params ); + if ( bHasFlashlight && ( IsX360() || r_flashlight_version2.GetInt() ) ) + { + DrawSkin_DX9_Internal( pShader, params, pShaderAPI, + pShaderShadow, false, info, vertexCompression, pContextDataPtr++ ); + if ( pShaderShadow ) + { + pShader->SetInitialShadowState( ); + } + } + DrawSkin_DX9_Internal( pShader, params, pShaderAPI, + pShaderShadow, bHasFlashlight, info, vertexCompression, pContextDataPtr ); +} diff --git a/materialsystem/stdshaders/skin_dx9_helper.h b/materialsystem/stdshaders/skin_dx9_helper.h new file mode 100644 index 0000000..414e8dd --- /dev/null +++ b/materialsystem/stdshaders/skin_dx9_helper.h @@ -0,0 +1,35 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//============================================================================= + +#ifndef SKIN_DX9_HELPER_H +#define SKIN_DX9_HELPER_H + +#include + +#include "vertexlitgeneric_dx9_helper.h" + +//----------------------------------------------------------------------------- +// Forward declarations +//----------------------------------------------------------------------------- +class CBaseVSShader; +class IMaterialVar; +class IShaderDynamicAPI; +class IShaderShadow; + +void InitParamsSkin_DX9( CBaseVSShader *pShader, IMaterialVar** params, + const char *pMaterialName, VertexLitGeneric_DX9_Vars_t &info ); +void InitSkin_DX9( CBaseVSShader *pShader, IMaterialVar** params, + VertexLitGeneric_DX9_Vars_t &info ); + +void DrawSkin_DX9( CBaseVSShader *pShader, IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, + IShaderShadow* pShaderShadow, + VertexLitGeneric_DX9_Vars_t &info, VertexCompressionType_t vertexCompression, + CBasePerMaterialContextData **pContextDataPtr ); + + + +#endif // SKIN_DX9_HELPER_H diff --git a/materialsystem/stdshaders/skin_ps20b.fxc b/materialsystem/stdshaders/skin_ps20b.fxc new file mode 100644 index 0000000..8d2e320 --- /dev/null +++ b/materialsystem/stdshaders/skin_ps20b.fxc @@ -0,0 +1,381 @@ +//======= Copyright © 1996-2007, Valve Corporation, All rights reserved. ====== +// STATIC: "CONVERT_TO_SRGB" "0..0" +// STATIC: "CUBEMAP" "0..1" +// STATIC: "SELFILLUM" "0..1" +// STATIC: "SELFILLUMFRESNEL" "0..1" +// STATIC: "FLASHLIGHT" "0..1" +// STATIC: "LIGHTWARPTEXTURE" "0..1" +// STATIC: "PHONGWARPTEXTURE" "0..1" +// STATIC: "WRINKLEMAP" "0..1" +// STATIC: "DETAIL_BLEND_MODE" "0..6" +// STATIC: "DETAILTEXTURE" "0..1" +// STATIC: "RIMLIGHT" "0..1" +// STATIC: "FLASHLIGHTDEPTHFILTERMODE" "0..2" [ps20b] [PC] +// STATIC: "FLASHLIGHTDEPTHFILTERMODE" "0..2" [ps30] [PC] +// STATIC: "FLASHLIGHTDEPTHFILTERMODE" "0..0" [ps20b] [XBOX] +// STATIC: "FASTPATH_NOBUMP" "0..1" +// STATIC: "BLENDTINTBYBASEALPHA" "0..1" + +// DYNAMIC: "WRITEWATERFOGTODESTALPHA" "0..1" +// DYNAMIC: "PIXELFOGTYPE" "0..1" +// DYNAMIC: "NUM_LIGHTS" "0..4" +// DYNAMIC: "WRITE_DEPTH_TO_DESTALPHA" "0..1" [ps20b] [PC] +// DYNAMIC: "WRITE_DEPTH_TO_DESTALPHA" "0..0" [ps20b] [XBOX] +// DYNAMIC: "WRITE_DEPTH_TO_DESTALPHA" "0..1" [ps30] +// DYNAMIC: "FLASHLIGHTSHADOWS" "0..1" [ps20b] +// DYNAMIC: "FLASHLIGHTSHADOWS" "0..1" [ps30] +// DYNAMIC: "PHONG_USE_EXPONENT_FACTOR" "0..0" [ps20] +// DYNAMIC: "PHONG_USE_EXPONENT_FACTOR" "0..1" [ps20b] [ps30] [PC] + + +// SKIP: ($PIXELFOGTYPE == 0) && ($WRITEWATERFOGTODESTALPHA != 0) + +// blend mode doesn't matter if we only have one texture +// SKIP: (! $DETAILTEXTURE) && ( $DETAIL_BLEND_MODE != 0 ) + +// We don't care about flashlight depth unless the flashlight is on +// SKIP: ( $FLASHLIGHT == 0 ) && ( $FLASHLIGHTSHADOWS == 1 ) + +// Flashlight shadow filter mode is irrelevant if there is no flashlight +// SKIP: ( $FLASHLIGHT == 0 ) && ( $FLASHLIGHTDEPTHFILTERMODE != 0 ) [ps20b] +// SKIP: ( $FLASHLIGHT == 0 ) && ( $FLASHLIGHTDEPTHFILTERMODE != 0 ) [ps30] + +// Only need self illum fresnel when self illum enabled +// SKIP: ( $SELFILLUM == 0 ) && ( $SELFILLUMFRESNEL == 1 ) +// SKIP: ( $FLASHLIGHT == 1 ) && ( $SELFILLUMFRESNEL == 1 ) +// SKIP: ( $FLASHLIGHT == 1 ) && ( $SELFILLUM == 1 ) + +// BlendTintByBaseAlpha and self illum and are opposing meanings for alpha channel +// SKIP: ( $BLENDTINTBYBASEALPHA ) && ( $SELFILLUM ) + +// fastpath means: +// no bumpmap +// basealphaenvmapmask (not inverted) +// no spec expmap +// no spectint +// no specwarp +// no rimlight +// no selfillum +// no detail +// no BlendTintByBaseAlpha + +// SKIP: $FASTPATH_NOBUMP && ( $RIMLIGHT || $DETAILTEXTURE || $PHONGWARPTEXTURE || $SELFILLUM || $BLENDTINTBYBASEALPHA ) + + + +#include "common_flashlight_fxc.h" +#include "shader_constant_register_map.h" + +const float4 g_SelfIllumTint_and_DetailBlendFactor : register( PSREG_SELFILLUMTINT ); +#if ( SELFILLUMFRESNEL == 1 ) +const float4 g_SelfIllumScaleBiasExpBrightness : register( PSREG_SELFILLUM_SCALE_BIAS_EXP ); +#endif +const float4 g_DiffuseModulation : register( PSREG_DIFFUSE_MODULATION ); +const float4 g_EnvmapTint_ShadowTweaks : register( PSREG_ENVMAP_TINT__SHADOW_TWEAKS ); // w controls spec mask +const float3 cAmbientCube[6] : register( PSREG_AMBIENT_CUBE ); +const float4 g_EnvMapFresnel : register( PSREG_ENVMAP_FRESNEL__SELFILLUMMASK ); // x is envmap fresnel ... w is selfillummask control +const float4 g_EyePos_SpecExponent : register( PSREG_EYEPOS_SPEC_EXPONENT ); +const float4 g_FogParams : register( PSREG_FOG_PARAMS ); +const float4 g_FlashlightAttenuationFactors_RimMask : register( PSREG_FLASHLIGHT_ATTENUATION ); // On non-flashlight pass, x has rim mask control +const float4 g_FlashlightPos_RimBoost : register( PSREG_FLASHLIGHT_POSITION_RIM_BOOST ); +#if FLASHLIGHT + const float4x4 g_FlashlightWorldToTexture : register( PSREG_FLASHLIGHT_TO_WORLD_TEXTURE ); +#endif +const float4 g_FresnelSpecParams : register( PSREG_FRESNEL_SPEC_PARAMS ); // xyz are fresnel, w is specular boost +const float4 g_SpecularRimParams : register( PSREG_SPEC_RIM_PARAMS ); // xyz are specular tint color, w is rim power +PixelShaderLightInfo cLightInfo[3] : register( PSREG_LIGHT_INFO_ARRAY ); // 2 registers each - 6 registers total (4th light spread across w's) + +// TODO: give this a better name. For now, I don't want to touch shader_constant_register_map.h since I don't want to trigger a recompile of everything... +const float4 g_ShaderControls : register( PSREG_CONSTANT_27 ); // x is basemap alpgha phong mask, y is 1 - blendtintbybasealpha, z is tint overlay amount, w controls "INVERTPHONGMASK" +#define g_FlashlightPos g_FlashlightPos_RimBoost.xyz +#define g_fRimBoost g_FlashlightPos_RimBoost.w +#define g_FresnelRanges g_FresnelSpecParams.xyz +#define g_SpecularBoost g_FresnelSpecParams.w +#define g_SpecularTint g_SpecularRimParams.xyz +#define g_RimExponent g_SpecularRimParams.w +#define g_FlashlightAttenuationFactors g_FlashlightAttenuationFactors_RimMask +#define g_RimMaskControl g_FlashlightAttenuationFactors_RimMask.x +#define g_SelfIllumMaskControl g_EnvMapFresnel.w +#define g_fBaseMapAlphaPhongMask g_ShaderControls.x +#define g_fTintReplacementControl g_ShaderControls.z +#define g_fInvertPhongMask g_ShaderControls.w + + +sampler BaseTextureSampler : register( s0 ); // Base map, selfillum in alpha +sampler SpecularWarpSampler : register( s1 ); // Specular warp sampler (for iridescence etc) +sampler DiffuseWarpSampler : register( s2 ); // Lighting warp sampler (1D texture for diffuse lighting modification) +sampler NormalMapSampler : register( s3 ); // Normal map, specular mask in alpha +sampler ShadowDepthSampler : register( s4 ); // Flashlight shadow depth map sampler +sampler NormalizeRandRotSampler : register( s5 ); // Normalization / RandomRotation samplers +sampler FlashlightSampler : register( s6 ); // Flashlight cookie +sampler SpecExponentSampler : register( s7 ); // Specular exponent map +sampler EnvmapSampler : register( s8 ); // Cubic environment map + +#if WRINKLEMAP +sampler WrinkleSampler : register( s9 ); // Compression base +sampler StretchSampler : register( s10 ); // Expansion base +sampler NormalWrinkleSampler : register( s11 ); // Compression base +sampler NormalStretchSampler : register( s12 ); // Expansion base +#endif + +#if DETAILTEXTURE +sampler DetailSampler : register( s13 ); // detail texture +#endif + +sampler SelfIllumMaskSampler : register( s14 ); // selfillummask + +struct PS_INPUT +{ + float4 baseTexCoordDetailTexCoord : TEXCOORD0; // xy=base zw=detail + float3 lightAtten : TEXCOORD1; // Scalar light attenuation factors for FOUR lights + float3 worldVertToEyeVectorXYZ_tangentSpaceVertToEyeVectorZ : TEXCOORD2; + float3x3 tangentSpaceTranspose : TEXCOORD3; + // second row : TEXCOORD4; + // third row : TEXCOORD5; + float4 worldPos_atten3 : TEXCOORD6; + float4 projPos_fWrinkleWeight : TEXCOORD7; +}; + + + +float4 main( PS_INPUT i ) : COLOR +{ + bool bWrinkleMap = WRINKLEMAP ? true : false; + bool bDoDiffuseWarp = LIGHTWARPTEXTURE ? true : false; + bool bDoSpecularWarp = PHONGWARPTEXTURE ? true : false; + bool bDoAmbientOcclusion = false; + bool bFlashlight = (FLASHLIGHT!=0) ? true : false; + bool bSelfIllum = SELFILLUM ? true : false; + bool bDoRimLighting = RIMLIGHT ? true : false; + bool bCubemap = CUBEMAP ? true : false; + bool bBlendTintByBaseAlpha = BLENDTINTBYBASEALPHA ? true : false; + int nNumLights = NUM_LIGHTS; + + // Unpacking for convenience + float fWrinkleWeight = i.projPos_fWrinkleWeight.w; + float3 vProjPos = i.projPos_fWrinkleWeight.xyz; + float3 vWorldPos = i.worldPos_atten3.xyz; + float atten3 = i.worldPos_atten3.w; + + float4 vLightAtten = float4( i.lightAtten, atten3 ); + +#if WRINKLEMAP + float flWrinkleAmount = saturate( -fWrinkleWeight ); // One of these two is zero + float flStretchAmount = saturate( fWrinkleWeight ); // while the other is in the 0..1 range + + float flTextureAmount = 1.0f - flWrinkleAmount - flStretchAmount; // These should sum to one +#endif + + float4 baseColor = tex2D( BaseTextureSampler, i.baseTexCoordDetailTexCoord.xy ); +#if WRINKLEMAP + float4 wrinkleColor = tex2D( WrinkleSampler, i.baseTexCoordDetailTexCoord.xy ); + float4 stretchColor = tex2D( StretchSampler, i.baseTexCoordDetailTexCoord.xy ); + + // Apply wrinkle blend to only RGB. Alpha comes from the base texture + baseColor.rgb = flTextureAmount * baseColor + flWrinkleAmount * wrinkleColor + flStretchAmount * stretchColor; +#endif + +#if DETAILTEXTURE + float4 detailColor = tex2D( DetailSampler, i.baseTexCoordDetailTexCoord.zw ); + baseColor = TextureCombine( baseColor, detailColor, DETAIL_BLEND_MODE, g_SelfIllumTint_and_DetailBlendFactor.w ); +#endif + + float fogFactor = CalcPixelFogFactor( PIXELFOGTYPE, g_FogParams, g_EyePos_SpecExponent.z, vWorldPos.z, vProjPos.z ); + + float3 vEyeDir = normalize(i.worldVertToEyeVectorXYZ_tangentSpaceVertToEyeVectorZ.xyz); + float3 vRimAmbientCubeColor = PixelShaderAmbientLight(vEyeDir, cAmbientCube); + + float3 worldSpaceNormal, tangentSpaceNormal; + float fSpecMask = 1.0f; + float4 normalTexel = tex2D( NormalMapSampler, i.baseTexCoordDetailTexCoord.xy ); + +#if WRINKLEMAP + float4 wrinkleNormal = tex2D( NormalWrinkleSampler, i.baseTexCoordDetailTexCoord.xy ); + float4 stretchNormal = tex2D( NormalStretchSampler, i.baseTexCoordDetailTexCoord.xy ); + normalTexel = flTextureAmount * normalTexel + flWrinkleAmount * wrinkleNormal + flStretchAmount * stretchNormal; +#endif + +#if (FASTPATH_NOBUMP == 0 ) + tangentSpaceNormal = lerp( 2.0f * normalTexel.xyz - 1.0f, float3(0, 0, 1), g_fBaseMapAlphaPhongMask ); + fSpecMask = lerp( normalTexel.a, baseColor.a, g_fBaseMapAlphaPhongMask ); +#else + tangentSpaceNormal = float3(0, 0, 1); + fSpecMask = baseColor.a; +#endif + + // We need a normal if we're doing any lighting + worldSpaceNormal = normalize( mul( i.tangentSpaceTranspose, tangentSpaceNormal ) ); + + float fFresnelRanges = Fresnel( worldSpaceNormal, vEyeDir, g_FresnelRanges ); + float fRimFresnel = Fresnel4( worldSpaceNormal, vEyeDir ); + + // Break down reflect so that we can share dot(worldSpaceNormal,vEyeDir) with fresnel terms + float3 vReflect = 2 * worldSpaceNormal * dot(worldSpaceNormal, vEyeDir) - vEyeDir; + + float3 diffuseLighting = float3( 1.0f, 1.0f, 1.0f ); + float3 envMapColor = float3( 0.0f, 0.0f, 0.0f ); + if( !bFlashlight ) + { + // Summation of diffuse illumination from all local lights + diffuseLighting = PixelShaderDoLighting( vWorldPos, worldSpaceNormal, + float3( 0.0f, 0.0f, 0.0f ), false, true, vLightAtten, + cAmbientCube, NormalizeRandRotSampler, nNumLights, cLightInfo, true, + + // These parameters aren't passed by generic shaders: + false, 1.0f, + bDoDiffuseWarp, DiffuseWarpSampler ); + + if( bCubemap ) + { + // Mask is either normal map alpha or base map alpha +#if ( SELFILLUMFRESNEL == 1 ) // This is to match the 2.0 version of vertexlitgeneric + float fEnvMapMask = lerp( baseColor.a, g_fInvertPhongMask, g_EnvmapTint_ShadowTweaks.w ); +#else + float fEnvMapMask = lerp( baseColor.a, fSpecMask, g_EnvmapTint_ShadowTweaks.w ); +#endif + + envMapColor = (ENV_MAP_SCALE * + lerp(1, fFresnelRanges, g_EnvMapFresnel.x) * + lerp(fEnvMapMask, 1-fEnvMapMask, g_fInvertPhongMask)) * + texCUBE( EnvmapSampler, vReflect ) * + g_EnvmapTint_ShadowTweaks.xyz; + } + } + + float3 specularLighting = float3( 0.0f, 0.0f, 0.0f ); + float3 rimLighting = float3( 0.0f, 0.0f, 0.0f ); + + float3 vSpecularTint = 1; + float fRimMask = 0; + float fSpecExp = 1; + +#if ( FASTPATH_NOBUMP == 0 ) + float4 vSpecExpMap = tex2D( SpecExponentSampler, i.baseTexCoordDetailTexCoord.xy ); + + if ( !bFlashlight ) + { + fRimMask = lerp( 1.0f, vSpecExpMap.a, g_RimMaskControl ); // Select rim mask + } + + // If the exponent passed in as a constant is zero, use the value from the map as the exponent +#if defined( _X360 ) + [flatten] +#endif + +#if ( PHONG_USE_EXPONENT_FACTOR ) + fSpecExp = ( 1.0f + g_EyePos_SpecExponent.w * vSpecExpMap.r ); +#else + fSpecExp = (g_EyePos_SpecExponent.w >= 0.0) ? g_EyePos_SpecExponent.w : (1.0f + 149.0f * vSpecExpMap.r); +#endif + + // If constant tint is negative, tint with albedo, based upon scalar tint map +#if defined( _X360 ) + [flatten] +#endif + vSpecularTint = lerp( float3(1.0f, 1.0f, 1.0f), baseColor.rgb, vSpecExpMap.g ); + vSpecularTint = (g_SpecularTint.r >= 0.0) ? g_SpecularTint.rgb : vSpecularTint; + +#else + fSpecExp = max(g_EyePos_SpecExponent.w, 0); +#endif + + float3 albedo = baseColor.rgb; + + if ( !bFlashlight ) + { + // Summation of specular from all local lights besides the flashlight + PixelShaderDoSpecularLighting( vWorldPos, worldSpaceNormal, + fSpecExp, vEyeDir, vLightAtten, + nNumLights, cLightInfo, false, 1.0f, bDoSpecularWarp, + SpecularWarpSampler, fFresnelRanges, bDoRimLighting, g_RimExponent, + + // Outputs + specularLighting, rimLighting ); + } + else + { + #if FLASHLIGHT + float4 flashlightSpacePosition = mul( float4( vWorldPos, 1.0f ), g_FlashlightWorldToTexture ); + + DoSpecularFlashlight( g_FlashlightPos, vWorldPos, flashlightSpacePosition, worldSpaceNormal, + g_FlashlightAttenuationFactors.xyz, g_FlashlightAttenuationFactors.w, + FlashlightSampler, ShadowDepthSampler, NormalizeRandRotSampler, FLASHLIGHTDEPTHFILTERMODE, FLASHLIGHTSHADOWS, true, vProjPos.xy / vProjPos.z, + fSpecExp, vEyeDir, bDoSpecularWarp, SpecularWarpSampler, fFresnelRanges, g_EnvmapTint_ShadowTweaks, + + // These two values are output + diffuseLighting, specularLighting ); + #endif + } + + // If we didn't already apply Fresnel to specular warp, modulate the specular + if ( !bDoSpecularWarp ) + fSpecMask *= fFresnelRanges; + + // Modulate with spec mask, boost and tint + specularLighting *= fSpecMask * g_SpecularBoost; + + if (bBlendTintByBaseAlpha) + { + float3 tintedColor = albedo * g_DiffuseModulation.rgb; + tintedColor = lerp(tintedColor, g_DiffuseModulation.rgb, g_fTintReplacementControl); + albedo = lerp(albedo, tintedColor, baseColor.a); + } + else + { + albedo = albedo * g_DiffuseModulation.rgb; + } + + + float3 diffuseComponent = albedo * diffuseLighting; + if ( bSelfIllum && !bFlashlight ) + { +#if ( SELFILLUMFRESNEL == 1 ) // To free up the constant register...see top of file + // This will apply a Fresnel term based on the vertex normal (not the per-pixel normal!) to help fake and internal glow look + float3 vVertexNormal = normalize( float3( i.tangentSpaceTranspose[0].z, i.tangentSpaceTranspose[1].z, i.tangentSpaceTranspose[2].z ) ); + float flSelfIllumFresnel = ( pow( saturate( dot( vVertexNormal.xyz, vEyeDir.xyz ) ), g_SelfIllumScaleBiasExpBrightness.z ) * g_SelfIllumScaleBiasExpBrightness.x ) + g_SelfIllumScaleBiasExpBrightness.y; + diffuseComponent = lerp( diffuseComponent, g_SelfIllumTint_and_DetailBlendFactor.rgb * albedo * g_SelfIllumScaleBiasExpBrightness.w, baseColor.a * saturate( flSelfIllumFresnel ) ); +#else + float3 vSelfIllumMask = tex2D( SelfIllumMaskSampler, i.baseTexCoordDetailTexCoord.xy ); + vSelfIllumMask = lerp( baseColor.aaa, vSelfIllumMask, g_SelfIllumMaskControl ); + diffuseComponent = lerp( diffuseComponent, g_SelfIllumTint_and_DetailBlendFactor.rgb * albedo, vSelfIllumMask ); +#endif + + diffuseComponent = max( 0.0f, diffuseComponent ); + } + +#if DETAILTEXTURE + diffuseComponent = TextureCombinePostLighting( diffuseComponent, detailColor, + DETAIL_BLEND_MODE, g_SelfIllumTint_and_DetailBlendFactor.w ); +#endif + + if ( bDoRimLighting && !bFlashlight ) + { + float fRimMultiply = fRimMask * fRimFresnel; // both unit range: [0, 1] + + // Add in rim light modulated with tint, mask and traditional Fresnel (not using Fresnel ranges) + rimLighting *= fRimMultiply; + + // Fold rim lighting into specular term by using the max so that we don't really add light twice... + specularLighting = max( specularLighting, rimLighting ); + + // Add in view-ray lookup from ambient cube + specularLighting += (vRimAmbientCubeColor * g_fRimBoost) * saturate(fRimMultiply * worldSpaceNormal.z); + } + + float3 result = specularLighting*vSpecularTint + envMapColor + diffuseComponent; + +#if WRITEWATERFOGTODESTALPHA && ( PIXELFOGTYPE == PIXEL_FOG_TYPE_HEIGHT ) + float alpha = fogFactor; +#else + float alpha = g_DiffuseModulation.a; + if ( !bSelfIllum && !bBlendTintByBaseAlpha ) + { + alpha = lerp( baseColor.a * alpha, alpha, g_fBaseMapAlphaPhongMask ); + } +#endif + + bool bWriteDepthToAlpha = ( WRITE_DEPTH_TO_DESTALPHA != 0 ) && ( WRITEWATERFOGTODESTALPHA == 0 ); + + //FIXME: need to take dowaterfog into consideration + return FinalOutput( float4( result, alpha ), fogFactor, PIXELFOGTYPE, TONEMAP_SCALE_LINEAR, bWriteDepthToAlpha, vProjPos.z ); +} diff --git a/materialsystem/stdshaders/skin_vs20.fxc b/materialsystem/stdshaders/skin_vs20.fxc new file mode 100644 index 0000000..9b04b7a --- /dev/null +++ b/materialsystem/stdshaders/skin_vs20.fxc @@ -0,0 +1,173 @@ +//======= Copyright (c) 1996-2007, Valve Corporation, All rights reserved. ====== + +// STATIC: "DECAL" "0..1" [vs30] +// STATIC: "USE_STATIC_CONTROL_FLOW" "0..1" [vs20] + +// DYNAMIC: "COMPRESSED_VERTS" "0..1" +// DYNAMIC: "DOWATERFOG" "0..1" +// DYNAMIC: "SKINNING" "0..1" +// DYNAMIC: "LIGHTING_PREVIEW" "0..1" [PC] +// DYNAMIC: "LIGHTING_PREVIEW" "0..0" [XBOX] +// DYNAMIC: "MORPHING" "0..1" [vs30] +// DYNAMIC: "NUM_LIGHTS" "0..2" [vs20] + +// If using static control flow on Direct3D, we should use the NUM_LIGHTS=0 combo +// SKIP: $USE_STATIC_CONTROL_FLOW && ( $NUM_LIGHTS > 0 ) [vs20] + +#include "common_vs_fxc.h" + +static const bool g_bSkinning = SKINNING ? true : false; +static const int g_FogType = DOWATERFOG; + +const float4 cBaseTexCoordTransform[2] : register( SHADER_SPECIFIC_CONST_0 ); +const float4 cDetailTexCoordTransform[2] : register( SHADER_SPECIFIC_CONST_4 ); + +#ifdef SHADER_MODEL_VS_3_0 +// NOTE: cMorphTargetTextureDim.xy = target dimensions, +// cMorphTargetTextureDim.z = 4tuples/morph +const float3 cMorphTargetTextureDim : register( SHADER_SPECIFIC_CONST_6 ); +const float4 cMorphSubrect : register( SHADER_SPECIFIC_CONST_7 ); + +sampler2D morphSampler : register( D3DVERTEXTEXTURESAMPLER0, s0 ); +#endif + + +//----------------------------------------------------------------------------- +// Input vertex format +//----------------------------------------------------------------------------- +struct VS_INPUT +{ + // This is all of the stuff that we ever use. + float4 vPos : POSITION; + float4 vBoneWeights : BLENDWEIGHT; + float4 vBoneIndices : BLENDINDICES; + float4 vNormal : NORMAL; + float4 vColor : COLOR0; + float3 vSpecular : COLOR1; + // make these float2's and stick the [n n 0 1] in the dot math. + float4 vTexCoord0 : TEXCOORD0; + float4 vTexCoord1 : TEXCOORD1; + float4 vTexCoord2 : TEXCOORD2; + float4 vTexCoord3 : TEXCOORD3; + float3 vTangentS : TANGENT; + float3 vTangentT : BINORMAL; + float4 vUserData : TANGENT; + + // Position and normal/tangent deltas + float4 vPosFlex : POSITION1; + float4 vNormalFlex : NORMAL1; + +#ifdef SHADER_MODEL_VS_3_0 + float vVertexID : POSITION2; +#endif +}; + +struct VS_OUTPUT +{ + // Stuff that isn't seen by the pixel shader + float4 projPos : POSITION; +#if !defined( _X360 ) + float fog : FOG; +#endif + // Stuff that is seen by the pixel shader + float4 baseTexCoord : TEXCOORD0; // includes detail tex coord + float3 lightAtten : TEXCOORD1; + float3 worldVertToEyeVector : TEXCOORD2; + float3x3 tangentSpaceTranspose : TEXCOORD3; + // second row : TEXCOORD4; + // third row : TEXCOORD5; + float4 worldPos_atten3 : TEXCOORD6; + float4 projPos_fWrinkleWeight : TEXCOORD7; +}; + +//----------------------------------------------------------------------------- +// Main shader entry point +//----------------------------------------------------------------------------- +VS_OUTPUT main( const VS_INPUT v ) +{ + VS_OUTPUT o = ( VS_OUTPUT )0; + + float4 vPosition = v.vPos; + float3 vNormal; + float4 vTangent; + DecompressVertex_NormalTangent( v.vNormal, v.vUserData, vNormal, vTangent ); + +#if !defined( SHADER_MODEL_VS_3_0 ) || !MORPHING + ApplyMorph( v.vPosFlex, v.vNormalFlex, + vPosition.xyz, vNormal, vTangent.xyz, o.projPos_fWrinkleWeight.w ); +#else + ApplyMorph( morphSampler, cMorphTargetTextureDim, cMorphSubrect, v.vVertexID, v.vTexCoord2, + vPosition.xyz, vNormal, vTangent.xyz, o.projPos_fWrinkleWeight.w ); +#endif + + // Perform skinning + float3 worldNormal, worldPos, worldTangentS, worldTangentT; + SkinPositionNormalAndTangentSpace( g_bSkinning, vPosition, vNormal, vTangent, + v.vBoneWeights, v.vBoneIndices, worldPos, + worldNormal, worldTangentS, worldTangentT ); + + // Always normalize since flex path is controlled by runtime + // constant not a shader combo and will always generate the normalization + worldNormal = normalize( worldNormal ); + worldTangentS = normalize( worldTangentS ); + worldTangentT = normalize( worldTangentT ); + +#if defined( SHADER_MODEL_VS_3_0 ) && MORPHING && DECAL + // Avoid z precision errors + worldPos += worldNormal * 0.05f * v.vTexCoord2.z; +#endif + + // Transform into projection space + float4 vProjPos = mul( float4( worldPos, 1 ), cViewProj ); + o.projPos = vProjPos; + vProjPos.z = dot( float4( worldPos, 1 ), cViewProjZ ); + + o.projPos_fWrinkleWeight.xyz = vProjPos.xyz; + +#if !defined( _X360 ) + o.fog = CalcFog( worldPos, vProjPos.xyz, g_FogType ); +#endif + // Needed for water fog alpha and diffuse lighting + // FIXME: we shouldn't have to compute this all the time. + o.worldPos_atten3.xyz = worldPos; + + // Needed for specular + o.worldVertToEyeVector = VSHADER_VECT_SCALE * (cEyePos - worldPos); + + // Compute bumped lighting + // FIXME: We shouldn't have to compute this for unlit materials +#if defined ( SHADER_MODEL_VS_2_0 ) && ( !USE_STATIC_CONTROL_FLOW ) + o.lightAtten.xyz = float3(0,0,0); + o.worldPos_atten3.w = 0.0f; + #if ( NUM_LIGHTS > 0 ) + o.lightAtten.x = GetVertexAttenForLight( worldPos, 0, false ); + #endif + #if ( NUM_LIGHTS > 1 ) + o.lightAtten.y = GetVertexAttenForLight( worldPos, 1, false ); + #endif + #if ( NUM_LIGHTS > 2 ) + o.lightAtten.z = GetVertexAttenForLight( worldPos, 2, false ); + #endif + #if ( NUM_LIGHTS > 3 ) + o.worldPos_atten3.w = GetVertexAttenForLight( worldPos, 3, false ); + #endif +#else + o.lightAtten.x = GetVertexAttenForLight( worldPos, 0, true ); + o.lightAtten.y = GetVertexAttenForLight( worldPos, 1, true ); + o.lightAtten.z = GetVertexAttenForLight( worldPos, 2, true ); + o.worldPos_atten3.w = GetVertexAttenForLight( worldPos, 3, true ); +#endif + + // Base texture coordinate transform + o.baseTexCoord.x = dot( v.vTexCoord0, cBaseTexCoordTransform[0] ); + o.baseTexCoord.y = dot( v.vTexCoord0, cBaseTexCoordTransform[1] ); + o.baseTexCoord.z = dot( v.vTexCoord0, cDetailTexCoordTransform[0] ); + o.baseTexCoord.w = dot( v.vTexCoord0, cDetailTexCoordTransform[1] ); + + // Tangent space transform + o.tangentSpaceTranspose[0] = float3( worldTangentS.x, worldTangentT.x, worldNormal.x ); + o.tangentSpaceTranspose[1] = float3( worldTangentS.y, worldTangentT.y, worldNormal.y ); + o.tangentSpaceTranspose[2] = float3( worldTangentS.z, worldTangentT.z, worldNormal.z ); + + return o; +} diff --git a/materialsystem/stdshaders/sky_dx6.cpp b/materialsystem/stdshaders/sky_dx6.cpp new file mode 100644 index 0000000..15bdc55 --- /dev/null +++ b/materialsystem/stdshaders/sky_dx6.cpp @@ -0,0 +1,15 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: Teeth renderer +// +// $Header: $ +// $NoKeywords: $ +//=============================================================================// +#include "shaderlib/cshader.h" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +DEFINE_FALLBACK_SHADER( Sky, UnlitGeneric ) +DEFINE_FALLBACK_SHADER( Sky_dx6, UnlitGeneric ) + diff --git a/materialsystem/stdshaders/sky_dx9.cpp b/materialsystem/stdshaders/sky_dx9.cpp new file mode 100644 index 0000000..93eb611 --- /dev/null +++ b/materialsystem/stdshaders/sky_dx9.cpp @@ -0,0 +1,126 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $Header: $ +// $NoKeywords: $ +//=============================================================================// +#include "BaseVSShader.h" +#include "sky_vs20.inc" +#include "sky_ps20.inc" +#include "sky_ps20b.inc" + +#include "convar.h" + +BEGIN_VS_SHADER( Sky_DX9, "Help for 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 ) + END_SHADER_PARAMS + + SHADER_FALLBACK + { + if( g_pHardwareConfig->GetDXSupportLevel() < 90 ) + { + return "sky_dx6"; + } + return 0; + } + + SHADER_INIT_PARAMS() + { + SET_FLAGS( MATERIAL_VAR_NOFOG ); + SET_FLAGS( MATERIAL_VAR_IGNOREZ ); + } + SHADER_INIT + { + if (params[BASETEXTURE]->IsDefined()) + { + ImageFormat fmt = params[BASETEXTURE]->GetTextureValue()->GetImageFormat(); + LoadTexture( BASETEXTURE, (fmt==IMAGE_FORMAT_RGBA16161616F) || (fmt==IMAGE_FORMAT_RGBA16161616) ? 0 : TEXTUREFLAGS_SRGB ); + } + } + SHADER_DRAW + { + SHADOW_STATE + { + SetInitialShadowState(); + +// 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); + + pShaderShadow->VertexShaderVertexFormat( VERTEX_POSITION, 1, NULL, 0 ); + + DECLARE_STATIC_VERTEX_SHADER( sky_vs20 ); + SET_STATIC_VERTEX_SHADER( sky_vs20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_STATIC_PIXEL_SHADER( sky_ps20b ); + SET_STATIC_PIXEL_SHADER( sky_ps20b ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( sky_ps20 ); + SET_STATIC_PIXEL_SHADER( sky_ps20 ); + } + // we are writing linear values from this shader. + pShaderShadow->EnableSRGBWrite( true ); + + pShaderShadow->EnableAlphaWrites( true ); + } + + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME ); + float c1[4]={0,0,0,0}; + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, c1); + + float c0[4]={1,1,1,1}; + if (params[COLOR]->IsDefined()) + { + 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)) + ) + { + 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 ); + + // Texture coord transform + SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_1, BASETEXTURETRANSFORM ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_DYNAMIC_PIXEL_SHADER( sky_ps20b ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( WRITE_DEPTH_TO_DESTALPHA, pShaderAPI->ShouldWriteDepthToDestAlpha() ); + SET_DYNAMIC_PIXEL_SHADER( sky_ps20b ); + } + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( sky_ps20 ); + SET_DYNAMIC_PIXEL_SHADER( sky_ps20 ); + } + } + Draw( ); + } + +END_SHADER + diff --git a/materialsystem/stdshaders/sky_hdr_compressed_ps2x.fxc b/materialsystem/stdshaders/sky_hdr_compressed_ps2x.fxc new file mode 100644 index 0000000..8e54d21 --- /dev/null +++ b/materialsystem/stdshaders/sky_hdr_compressed_ps2x.fxc @@ -0,0 +1,29 @@ +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX] +// DYNAMIC: "WRITE_DEPTH_TO_DESTALPHA" "0..1" [ps20b] [PC] +// DYNAMIC: "WRITE_DEPTH_TO_DESTALPHA" "0..0" [ps20b] [XBOX] +#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 ); + +struct PS_INPUT +{ + float2 baseTexCoord : TEXCOORD0; +}; + +float4 main( PS_INPUT i ) : COLOR +{ + HALF3 color0 = 0.25*tex2D( ExposureTextureSampler0, i.baseTexCoord ); + HALF3 color1 = 2.0*tex2D( ExposureTextureSampler1, i.baseTexCoord ); + HALF3 color2 = 16.0*tex2D( ExposureTextureSampler2, i.baseTexCoord ); + + // 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/materialsystem/stdshaders/sky_hdr_compressed_rgbs_ps2x.fxc b/materialsystem/stdshaders/sky_hdr_compressed_rgbs_ps2x.fxc new file mode 100644 index 0000000..4871da5 --- /dev/null +++ b/materialsystem/stdshaders/sky_hdr_compressed_rgbs_ps2x.fxc @@ -0,0 +1,81 @@ +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX] +// DYNAMIC: "WRITE_DEPTH_TO_DESTALPHA" "0..1" [ps20b] [PC] +// DYNAMIC: "WRITE_DEPTH_TO_DESTALPHA" "0..0" [ps20b] [XBOX] +#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 ); + +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 + float4 s00 = tex2D(RGBSTextureSampler, i.baseTexCoord00); + float4 s10 = tex2D(RGBSTextureSampler, i.baseTexCoord10); + float4 s01 = tex2D(RGBSTextureSampler, i.baseTexCoord01); + float4 s11 = tex2D(RGBSTextureSampler, i.baseTexCoord11); + + 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/materialsystem/stdshaders/sky_hdr_dx9.cpp b/materialsystem/stdshaders/sky_hdr_dx9.cpp new file mode 100644 index 0000000..008f37e --- /dev/null +++ b/materialsystem/stdshaders/sky_hdr_dx9.cpp @@ -0,0 +1,297 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $Header: $ +// $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 "convar.h" + +static ConVar mat_use_compressed_hdr_textures( "mat_use_compressed_hdr_textures", "1" ); + +DEFINE_FALLBACK_SHADER( Sky, Sky_HDR_DX9 ) + +BEGIN_VS_SHADER( 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" ) + SHADER_PARAM( HDRCOMPRESSEDTEXTURE0, SHADER_PARAM_TYPE_TEXTURE, "", "compressed base texture0 for hdr compression method B" ) + 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 ) + END_SHADER_PARAMS + + SHADER_FALLBACK + { + if( g_pHardwareConfig->GetDXSupportLevel() < 90 || g_pHardwareConfig->GetHDRType() == HDR_TYPE_NONE ) + { + return "Sky_DX9"; + } + return 0; + } + + SHADER_INIT_PARAMS() + { + SET_FLAGS( MATERIAL_VAR_NOFOG ); + SET_FLAGS( MATERIAL_VAR_IGNOREZ ); + } + SHADER_INIT + { + // First figure out if sampler zero wants to be sRGB + int nSamplerZeroFlags = 0; + if ( (params[HDRCOMPRESSEDTEXTURE]->IsDefined()) && mat_use_compressed_hdr_textures.GetBool() ) + { + nSamplerZeroFlags = 0; + } + else + { + if (params[HDRCOMPRESSEDTEXTURE0]->IsDefined()) + { + nSamplerZeroFlags = 0; + } + else + { + nSamplerZeroFlags = TEXTUREFLAGS_SRGB; + + if ( params[HDRBASETEXTURE]->IsDefined() && params[HDRBASETEXTURE]->IsTexture() ) + { + ITexture *txtr=params[HDRBASETEXTURE]->GetTextureValue(); + ImageFormat fmt=txtr->GetImageFormat(); + if ( ( fmt == IMAGE_FORMAT_RGBA16161616F ) || ( fmt == IMAGE_FORMAT_RGBA16161616 ) ) + { + nSamplerZeroFlags = 0; + } + } + } + } + + // Next, figure out which texture will be on sampler zero + int nSampler0 = HDRCOMPRESSEDTEXTURE; + if ( params[HDRCOMPRESSEDTEXTURE]->IsDefined() && mat_use_compressed_hdr_textures.GetBool() ) + { + nSampler0 = HDRCOMPRESSEDTEXTURE; + } + else + { + if ( params[HDRCOMPRESSEDTEXTURE0]->IsDefined() ) + { + nSampler0 = HDRCOMPRESSEDTEXTURE0; + } + else + { + nSampler0 = HDRBASETEXTURE; + } + } + + // 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() ) ) + { + LoadTexture( HDRCOMPRESSEDTEXTURE, HDRCOMPRESSEDTEXTURE == nSampler0 ? nSamplerZeroFlags : 0 ); + } + else + { + if (params[HDRCOMPRESSEDTEXTURE0]->IsDefined()) + { + LoadTexture( HDRCOMPRESSEDTEXTURE0, HDRCOMPRESSEDTEXTURE0 == nSampler0 ? nSamplerZeroFlags : 0 ); + if ( params[HDRCOMPRESSEDTEXTURE1]->IsDefined() ) + { + LoadTexture( HDRCOMPRESSEDTEXTURE1, HDRCOMPRESSEDTEXTURE1 == nSampler0 ? nSamplerZeroFlags : 0 ); + } + if ( params[HDRCOMPRESSEDTEXTURE2]->IsDefined()) + { + LoadTexture( HDRCOMPRESSEDTEXTURE2, HDRCOMPRESSEDTEXTURE2 == nSampler0 ? nSamplerZeroFlags : 0 ); + } + } + else + { + if ( params[HDRBASETEXTURE]->IsDefined() ) + { + LoadTexture( HDRBASETEXTURE, HDRBASETEXTURE == nSampler0 ? nSamplerZeroFlags : 0 ); + } + } + } + } + + SHADER_DRAW + { + SHADOW_STATE + { + SetInitialShadowState(); + +// pShaderShadow->EnableAlphaWrites( true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->VertexShaderVertexFormat( VERTEX_POSITION, 1, NULL, 0 ); + + DECLARE_STATIC_VERTEX_SHADER( sky_vs20 ); + SET_STATIC_VERTEX_SHADER( sky_vs20 ); + + if ( (params[HDRCOMPRESSEDTEXTURE]->IsDefined()) && + mat_use_compressed_hdr_textures.GetBool() ) + { + 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 ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( sky_hdr_compressed_rgbs_ps20 ); + SET_STATIC_PIXEL_SHADER( sky_hdr_compressed_rgbs_ps20 ); + } + } + else + { + if (params[HDRCOMPRESSEDTEXTURE0]->IsDefined()) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER2, true ); + + pShaderShadow->EnableSRGBRead(SHADER_SAMPLER0,false); + pShaderShadow->EnableSRGBRead(SHADER_SAMPLER1,false); + pShaderShadow->EnableSRGBRead(SHADER_SAMPLER2,false); + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_STATIC_PIXEL_SHADER( sky_hdr_compressed_ps20b ); + SET_STATIC_PIXEL_SHADER( sky_hdr_compressed_ps20b ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( sky_hdr_compressed_ps20 ); + SET_STATIC_PIXEL_SHADER( 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() ) + { + DECLARE_STATIC_PIXEL_SHADER( sky_ps20b ); + SET_STATIC_PIXEL_SHADER( sky_ps20b ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( sky_ps20 ); + SET_STATIC_PIXEL_SHADER( sky_ps20 ); + } + } + } + // we are writing linear values from this shader. + pShaderShadow->EnableSRGBWrite( true ); + + pShaderShadow->EnableAlphaWrites( true ); + } + + DYNAMIC_STATE + { + DECLARE_DYNAMIC_VERTEX_SHADER( sky_vs20 ); + SET_DYNAMIC_VERTEX_SHADER( sky_vs20 ); + + // Texture coord transform + SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_1, BASETEXTURETRANSFORM ); + + float c0[4]={1,1,1,1}; + if (params[COLOR]->IsDefined()) + { + memcpy(c0,params[COLOR]->GetVecValue(),3*sizeof(float)); + } + if ( + params[HDRCOMPRESSEDTEXTURE]->IsDefined() && + mat_use_compressed_hdr_textures.GetBool() + ) + { + // set up data needs for pixel shader interpolation + ITexture *txtr=params[HDRCOMPRESSEDTEXTURE]->GetTextureValue(); + float w=txtr->GetActualWidth(); + float h=txtr->GetActualHeight(); + float FUDGE=0.01/max(w,h); // per ATI + float c1[4]={(float)(0.5/w-FUDGE), (float)(0.5/h-FUDGE), w, h }; + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, c1); + + 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 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( WRITE_DEPTH_TO_DESTALPHA, pShaderAPI->ShouldWriteDepthToDestAlpha() ); + SET_DYNAMIC_PIXEL_SHADER( sky_hdr_compressed_rgbs_ps20b ); + } + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( sky_hdr_compressed_rgbs_ps20 ); + SET_DYNAMIC_PIXEL_SHADER( sky_hdr_compressed_rgbs_ps20 ); + } + } + else + { + float c1[4]={0,0,0,0}; + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, c1); + + if (params[HDRCOMPRESSEDTEXTURE0]->IsDefined() ) + { + BindTexture( SHADER_SAMPLER0, HDRCOMPRESSEDTEXTURE0, FRAME ); + BindTexture( SHADER_SAMPLER1, HDRCOMPRESSEDTEXTURE1, FRAME ); + BindTexture( SHADER_SAMPLER2, HDRCOMPRESSEDTEXTURE2, FRAME ); + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_DYNAMIC_PIXEL_SHADER( sky_hdr_compressed_ps20b ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( WRITE_DEPTH_TO_DESTALPHA, pShaderAPI->ShouldWriteDepthToDestAlpha() ); + SET_DYNAMIC_PIXEL_SHADER( sky_hdr_compressed_ps20b ); + } + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( sky_hdr_compressed_ps20 ); + SET_DYNAMIC_PIXEL_SHADER( 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)) + ) + { + c0[0]*=16.0; + c0[1]*=16.0; + c0[2]*=16.0; + } + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_DYNAMIC_PIXEL_SHADER( sky_ps20b ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( WRITE_DEPTH_TO_DESTALPHA, pShaderAPI->ShouldWriteDepthToDestAlpha() ); + SET_DYNAMIC_PIXEL_SHADER( sky_ps20b ); + } + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( sky_ps20 ); + SET_DYNAMIC_PIXEL_SHADER( sky_ps20 ); + } + } + } + pShaderAPI->SetPixelShaderConstant( 0, c0, 1 ); + } + Draw( ); + } +END_SHADER diff --git a/materialsystem/stdshaders/sky_ps2x.fxc b/materialsystem/stdshaders/sky_ps2x.fxc new file mode 100644 index 0000000..563fddb --- /dev/null +++ b/materialsystem/stdshaders/sky_ps2x.fxc @@ -0,0 +1,27 @@ +// 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] +// DYNAMIC: "WRITE_DEPTH_TO_DESTALPHA" "0..1" [ps20b] [PC] +// DYNAMIC: "WRITE_DEPTH_TO_DESTALPHA" "0..0" [ps20b] [XBOX] +#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 ); + +struct PS_INPUT +{ + float2 baseTexCoord : TEXCOORD0; +}; + +float4 main( PS_INPUT i ) : COLOR +{ + HALF4 color = tex2D( BaseTextureSampler, i.baseTexCoord.xy ); + 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/materialsystem/stdshaders/sky_vs20.fxc b/materialsystem/stdshaders/sky_vs20.fxc new file mode 100644 index 0000000..1bc2a3e --- /dev/null +++ b/materialsystem/stdshaders/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/materialsystem/stdshaders/splinecard_vsxx.fxc b/materialsystem/stdshaders/splinecard_vsxx.fxc new file mode 100644 index 0000000..35a3c23 --- /dev/null +++ b/materialsystem/stdshaders/splinecard_vsxx.fxc @@ -0,0 +1,65 @@ +#include "common_vs_fxc.h" + + +const float4x3 cModelView : register(SHADER_SPECIFIC_CONST_0); +const float4x4 cProj : register(SHADER_SPECIFIC_CONST_3); + +// derivative of catmull rom spline courtesy of calc +float4 DCatmullRomSpline ( float4 a, float4 b, float4 c, float4 d, float t ) +{ + return 0.5 *( c - a + t * ( 2 * a - 5 * b + 4 * c - d + t * (3 * b - a - 3 * c + d ) ) + + t * ( 2 * a - 5 * b + 4 * c - d + 2 * ( t * ( 3 * b - a - 3 * c + d ) ) ) ); +} + +float3 DCatmullRomSpline3 ( float3 a, float3 b, float3 c, float3 d, float t ) +{ + return 0.5 *( c - a + t * ( 2 * a - 5 * b + 4 * c - d + t * (3 * b - a - 3 * c + d ) ) + + t * ( 2 * a - 5 * b + 4 * c - d + 2 * ( t * ( 3 * b - a - 3 * c + d ) ) ) ); +} + + +float4 CatmullRomSpline( float4 a, float4 b, float4 c, float4 d, float t ) +{ + return b + 0.5 * t * ( c - a + t * ( 2 * a - 5 * b + 4 * c - d + t * ( -a + 3 * b -3 * c + d ) ) ); +} + +struct VS_INPUT +{ + // This is all of the stuff that we ever use. + float4 vTint : COLOR; + float4 vParms : POSITION; // T V side_id + float4 vSplinePt0 : TEXCOORD0; // x y z rad + float4 vSplinePt1 : TEXCOORD1; // x y z rad + float4 vSplinePt2 : TEXCOORD2; // x y z rad + float4 vSplinePt3 : TEXCOORD3; // x y z rad +}; + +struct VS_OUTPUT +{ + float4 projPos : POSITION; + + float2 texCoord0 : TEXCOORD0; + float2 texCoord1 : TEXCOORD1; + float4 argbcolor : COLOR; + float4 blendfactor0 : TEXCOORD2; + float4 vScreenPos : TEXCOORD7; +}; + +VS_OUTPUT main( const VS_INPUT v ) +{ + VS_OUTPUT o; + + float4 posrad = + CatmullRomSpline( v.vSplinePt0, v.vSplinePt1, v.vSplinePt2, v.vSplinePt3, v.vParms.x ); + float3 v2p = ( posrad.xyz - cEyePos ); + float3 tangent=DCatmullRomSpline3( v.vSplinePt0, v.vSplinePt1, v.vSplinePt2, v.vSplinePt3, v.vParms.x ); + float3 ofs = normalize( cross(v2p, normalize( tangent) ) ); + posrad.xyz += ofs * ( posrad.w * ( v.vParms.z - .5 ) ); + o.projPos = mul( float4(posrad.xyz, 1.0f), cViewProj ); + o.texCoord0 = o.texCoord1 = float2( (1-v.vParms.z), v.vParms.y); + o.argbcolor = v.vTint; + o.blendfactor0 = float4(0,0,0,0); + o.vScreenPos = float4(0,0,0,0); + return o; + +} diff --git a/materialsystem/stdshaders/sprite.cpp b/materialsystem/stdshaders/sprite.cpp new file mode 100644 index 0000000..77934f5 --- /dev/null +++ b/materialsystem/stdshaders/sprite.cpp @@ -0,0 +1,379 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +// +// Implementation of the sprite shader +//=============================================================================// + +#include "BaseVSShader.h" +#include +#include "const.h" +#include "sprite_vs11.inc" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +// WARNING! Change these in engine/SpriteGn.h if you change them here! +#define SPR_VP_PARALLEL_UPRIGHT 0 +#define SPR_FACING_UPRIGHT 1 +#define SPR_VP_PARALLEL 2 +#define SPR_ORIENTED 3 +#define SPR_VP_PARALLEL_ORIENTED 4 + + +DEFINE_FALLBACK_SHADER( Sprite, Sprite_DX8 ) + +BEGIN_VS_SHADER( Sprite_DX8, + "Help for Sprite_DX8" ) + + BEGIN_SHADER_PARAMS + SHADER_PARAM( SPRITEORIGIN, SHADER_PARAM_TYPE_VEC3, "[0 0 0]", "sprite origin" ) + SHADER_PARAM( SPRITEORIENTATION, SHADER_PARAM_TYPE_INTEGER, "0", "sprite orientation" ) + SHADER_PARAM( SPRITERENDERMODE, SHADER_PARAM_TYPE_INTEGER, "0", "sprite rendermode" ) + SHADER_PARAM( IGNOREVERTEXCOLORS, SHADER_PARAM_TYPE_BOOL, "1", "ignore vertex colors" ) + END_SHADER_PARAMS + + SHADER_FALLBACK + { + if ( IsPC() && g_pHardwareConfig->GetDXSupportLevel() < 80 ) + return "Sprite_DX6"; + return 0; + } + + SHADER_INIT_PARAMS() + { + // FIXME: This can share code with sprite.cpp + // FIXME: Not sure if this is the best solution, but it's a very] + // easy one. When graphics aren't enabled, we oftentimes need to get + // at the parameters of a shader. Therefore, we must set the default + // values in a separate phase from when we load resources. + + if (!params[ALPHA]->IsDefined()) + params[ ALPHA ]->SetFloatValue( 1.0f ); + + SET_FLAGS( MATERIAL_VAR_NO_DEBUG_OVERRIDE ); + SET_FLAGS( MATERIAL_VAR_VERTEXCOLOR ); + SET_FLAGS( MATERIAL_VAR_VERTEXALPHA ); + + // translate from a string orientation to an enumeration + if (params[SPRITEORIENTATION]->IsDefined()) + { + const char *orientationString = params[SPRITEORIENTATION]->GetStringValue(); + if( stricmp( orientationString, "parallel_upright" ) == 0 ) + { + params[SPRITEORIENTATION]->SetIntValue( SPR_VP_PARALLEL_UPRIGHT ); + } + else if( stricmp( orientationString, "facing_upright" ) == 0 ) + { + params[SPRITEORIENTATION]->SetIntValue( SPR_FACING_UPRIGHT ); + } + else if( stricmp( orientationString, "vp_parallel" ) == 0 ) + { + params[SPRITEORIENTATION]->SetIntValue( SPR_VP_PARALLEL ); + } + else if( stricmp( orientationString, "oriented" ) == 0 ) + { + params[SPRITEORIENTATION]->SetIntValue( SPR_ORIENTED ); + } + else if( stricmp( orientationString, "vp_parallel_oriented" ) == 0 ) + { + params[SPRITEORIENTATION]->SetIntValue( SPR_VP_PARALLEL_ORIENTED ); + } + else + { + Warning( "error with $spriteOrientation\n" ); + params[SPRITEORIENTATION]->SetIntValue( SPR_VP_PARALLEL_UPRIGHT ); + } + } + else + { + // default case + params[SPRITEORIENTATION]->SetIntValue( SPR_VP_PARALLEL_UPRIGHT ); + } + } + + SHADER_INIT + { + LoadTexture( BASETEXTURE ); + } + +#define SHADER_USE_VERTEX_COLOR 1 +#define SHADER_USE_CONSTANT_COLOR 2 + + void SetSpriteCommonShadowState( unsigned int shaderFlags ) + { + s_pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + + unsigned int flags = VERTEX_POSITION; + if( shaderFlags & SHADER_USE_VERTEX_COLOR ) + { + flags |= VERTEX_COLOR; + } + s_pShaderShadow->VertexShaderVertexFormat( flags, 1, 0, 0 ); + + sprite_vs11_Static_Index vshIndex; + bool vertexColor = ( shaderFlags & SHADER_USE_VERTEX_COLOR ) ? true : false; + vshIndex.SetVERTEXCOLOR( vertexColor ); + s_pShaderShadow->SetVertexShader( "sprite_vs11", vshIndex.GetIndex() ); + + // "VERTEXCOLOR" "0..1" + // "CONSTANTCOLOR" "0..1" + int pshIndex = 0; + if ( shaderFlags & SHADER_USE_VERTEX_COLOR ) pshIndex |= 0x1; + if ( shaderFlags & SHADER_USE_CONSTANT_COLOR ) pshIndex |= 0x2; + s_pShaderShadow->SetPixelShader( "sprite_ps11", pshIndex ); + } + + void SetSpriteCommonDynamicState( unsigned int shaderFlags ) + { + BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME ); + + MaterialFogMode_t fogType = s_pShaderAPI->GetSceneFogMode(); + int fogIndex = ( fogType == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ) ? 1 : 0; + sprite_vs11_Dynamic_Index vshIndex; + vshIndex.SetSKINNING( 0 ); + vshIndex.SetDOWATERFOG( fogIndex ); + s_pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() ); + + s_pShaderAPI->SetPixelShaderIndex( 0 ); + if ( shaderFlags & SHADER_USE_CONSTANT_COLOR ) + { + SetPixelShaderConstant( 0, COLOR, ALPHA ); + } + + float color[4] = { 1.0, 1.0, 1.0, 1.0 }; + s_pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_MODULATION_COLOR, color ); + + // identity base texture transorm + float ident[2][4] = { + { 1.0f, 0.0f, 0.0f, 0.0f }, + { 0.0f, 1.0f, 0.0f, 0.0f } + }; + s_pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, &ident[0][0], 2 ); + } + + SHADER_DRAW + { + SHADOW_STATE + { + pShaderShadow->EnableCulling( false ); + } + + switch( params[SPRITERENDERMODE]->GetIntValue() ) + { + case kRenderNormal: + SHADOW_STATE + { + FogToFogColor(); + SetSpriteCommonShadowState( 0 ); + } + DYNAMIC_STATE + { + SetSpriteCommonDynamicState( 0 ); + } + Draw(); + break; + case kRenderTransColor: + case kRenderTransTexture: + SHADOW_STATE + { + pShaderShadow->EnableDepthWrites( false ); + pShaderShadow->EnableBlending( true ); + pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA ); + FogToFogColor(); + + SetSpriteCommonShadowState( SHADER_USE_VERTEX_COLOR ); + } + DYNAMIC_STATE + { + SetSpriteCommonDynamicState( SHADER_USE_VERTEX_COLOR ); + } + Draw(); + break; + case kRenderGlow: + case kRenderWorldGlow: + SHADOW_STATE + { + pShaderShadow->EnableDepthWrites( false ); + pShaderShadow->DepthFunc( SHADER_DEPTHFUNC_ALWAYS ); + pShaderShadow->EnableBlending( true ); + pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE ); + FogToBlack(); + + SetSpriteCommonShadowState( SHADER_USE_VERTEX_COLOR ); + } + DYNAMIC_STATE + { + SetSpriteCommonDynamicState( SHADER_USE_VERTEX_COLOR ); + } + Draw(); + break; + case kRenderTransAlpha: + // untested cut and past from kRenderTransAlphaAdd . . same as first pass of that. + SHADOW_STATE + { + pShaderShadow->EnableDepthWrites( false ); + pShaderShadow->EnableBlending( true ); + pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA ); + FogToFogColor(); + + SetSpriteCommonShadowState( SHADER_USE_VERTEX_COLOR ); + } + DYNAMIC_STATE + { + SetSpriteCommonDynamicState( SHADER_USE_VERTEX_COLOR ); + } + Draw(); + break; + case kRenderTransAlphaAdd: + SHADOW_STATE + { + pShaderShadow->EnableDepthWrites( false ); + pShaderShadow->EnableBlending( true ); + pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA ); + FogToFogColor(); + + SetSpriteCommonShadowState( SHADER_USE_VERTEX_COLOR ); + } + DYNAMIC_STATE + { + SetSpriteCommonDynamicState( SHADER_USE_VERTEX_COLOR ); + } + Draw(); + + SHADOW_STATE + { + SetInitialShadowState(); + pShaderShadow->EnableDepthWrites( false ); + pShaderShadow->EnableBlending( true ); + pShaderShadow->BlendFunc( SHADER_BLEND_ONE_MINUS_SRC_ALPHA, SHADER_BLEND_ONE ); + FogToBlack(); + + SetSpriteCommonShadowState( SHADER_USE_VERTEX_COLOR ); + } + DYNAMIC_STATE + { + SetSpriteCommonDynamicState( SHADER_USE_VERTEX_COLOR ); + } + Draw(); + break; + + case kRenderTransAdd: + { + unsigned int flags = SHADER_USE_CONSTANT_COLOR; + if( !params[ IGNOREVERTEXCOLORS ]->GetIntValue() ) + { + flags |= SHADER_USE_VERTEX_COLOR; + } + SHADOW_STATE + { + pShaderShadow->EnableDepthWrites( false ); + pShaderShadow->EnableBlending( true ); + pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE ); + FogToBlack(); + + SetSpriteCommonShadowState( flags ); + } + DYNAMIC_STATE + { + SetSpriteCommonDynamicState( flags ); + } + } + Draw(); + break; + case kRenderTransAddFrameBlend: + { + float flFrame = params[FRAME]->GetFloatValue(); + float flFade = params[ALPHA]->GetFloatValue(); + unsigned int flags = SHADER_USE_CONSTANT_COLOR; + if( !params[ IGNOREVERTEXCOLORS ]->GetIntValue() ) + { + flags |= SHADER_USE_VERTEX_COLOR; + } + SHADOW_STATE + { + pShaderShadow->EnableDepthWrites( false ); + pShaderShadow->EnableBlending( true ); + pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE ); + FogToBlack(); + + SetSpriteCommonShadowState( flags ); + } + DYNAMIC_STATE + { + float frameBlendAlpha = 1.0f - ( flFrame - ( int )flFrame ); + ITexture *pTexture = params[BASETEXTURE]->GetTextureValue(); + BindTexture( SHADER_SAMPLER0, pTexture, ( int )flFrame ); + + MaterialFogMode_t fogType = s_pShaderAPI->GetSceneFogMode(); + int fogIndex = ( fogType == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ) ? 1 : 0; + sprite_vs11_Dynamic_Index vshIndex; + vshIndex.SetSKINNING( 0 ); + vshIndex.SetDOWATERFOG( fogIndex ); + s_pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() ); + + float color[4] = { 1.0, 1.0, 1.0, 1.0 }; + s_pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_MODULATION_COLOR, color ); + + s_pShaderAPI->SetPixelShaderIndex( 0 ); + + color[0] = color[1] = color[2] = flFade * frameBlendAlpha; + color[3] = 1.0f; + s_pShaderAPI->SetPixelShaderConstant( 0, color ); + + + // identity base texture transorm + float ident[2][4] = { + { 1.0f, 0.0f, 0.0f, 0.0f }, + { 0.0f, 1.0f, 0.0f, 0.0f } + }; + s_pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, &ident[0][0], 2 ); + } + Draw(); + SHADOW_STATE + { + FogToBlack(); + + SetSpriteCommonShadowState( flags ); + } + DYNAMIC_STATE + { + float frameBlendAlpha = ( flFrame - ( int )flFrame ); + ITexture *pTexture = params[BASETEXTURE]->GetTextureValue(); + int numAnimationFrames = pTexture->GetNumAnimationFrames(); + BindTexture( SHADER_SAMPLER0, pTexture, ( ( int )flFrame + 1 ) % numAnimationFrames ); + + MaterialFogMode_t fogType = s_pShaderAPI->GetSceneFogMode(); + int fogIndex = ( fogType == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ) ? 1 : 0; + sprite_vs11_Dynamic_Index vshIndex; + vshIndex.SetSKINNING( 0 ); + vshIndex.SetDOWATERFOG( fogIndex ); + s_pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() ); + + float color[4] = { 1.0, 1.0, 1.0, 1.0 }; + s_pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_MODULATION_COLOR, color ); + + s_pShaderAPI->SetPixelShaderIndex( 0 ); + + color[0] = color[1] = color[2] = flFade * frameBlendAlpha; + color[3] = 1.0f; + s_pShaderAPI->SetPixelShaderConstant( 0, color ); + + // identity base texture transorm + float ident[2][4] = { + { 1.0f, 0.0f, 0.0f, 0.0f }, + { 0.0f, 1.0f, 0.0f, 0.0f } + }; + s_pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, &ident[0][0], 2 ); + } + Draw(); + } + break; + default: + ShaderWarning( "shader Sprite: Unknown sprite render mode\n" ); + break; + } + } +END_SHADER diff --git a/materialsystem/stdshaders/sprite_dx6.cpp b/materialsystem/stdshaders/sprite_dx6.cpp new file mode 100644 index 0000000..15ba22a --- /dev/null +++ b/materialsystem/stdshaders/sprite_dx6.cpp @@ -0,0 +1,289 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +// +// Implementation of the sprite shader +//=============================================================================// + +#include "shaderlib/cshader.h" +#include +#include "const.h" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +// WARNING! Change these in engine/SpriteGn.h if you change them here! +#define SPR_VP_PARALLEL_UPRIGHT 0 +#define SPR_FACING_UPRIGHT 1 +#define SPR_VP_PARALLEL 2 +#define SPR_ORIENTED 3 +#define SPR_VP_PARALLEL_ORIENTED 4 + + +DEFINE_FALLBACK_SHADER( Sprite, Sprite_DX6 ) + +BEGIN_SHADER( Sprite_DX6, + "Help for Sprite_DX6" ) + + BEGIN_SHADER_PARAMS + SHADER_PARAM( SPRITEORIGIN, SHADER_PARAM_TYPE_VEC3, "[0 0 0]", "sprite origin" ) + SHADER_PARAM( SPRITEORIENTATION, SHADER_PARAM_TYPE_INTEGER, "0", "sprite orientation" ) + SHADER_PARAM( SPRITERENDERMODE, SHADER_PARAM_TYPE_INTEGER, "0", "sprite rendermode" ) + SHADER_PARAM( IGNOREVERTEXCOLORS, SHADER_PARAM_TYPE_BOOL, "1", "ignore vertex colors" ) + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + // FIXME: This can share code with sprite.cpp + // FIXME: Not sure if this is the best solution, but it's a very] + // easy one. When graphics aren't enabled, we oftentimes need to get + // at the parameters of a shader. Therefore, we must set the default + // values in a separate phase from when we load resources. + + if (!params[ALPHA]->IsDefined()) + params[ ALPHA ]->SetFloatValue( 1.0f ); + + SET_FLAGS( MATERIAL_VAR_NO_DEBUG_OVERRIDE ); + SET_FLAGS( MATERIAL_VAR_VERTEXCOLOR ); + SET_FLAGS( MATERIAL_VAR_VERTEXALPHA ); + + // translate from a string orientation to an enumeration + if (params[SPRITEORIENTATION]->IsDefined()) + { + const char *orientationString = params[SPRITEORIENTATION]->GetStringValue(); + if( stricmp( orientationString, "parallel_upright" ) == 0 ) + { + params[SPRITEORIENTATION]->SetIntValue( SPR_VP_PARALLEL_UPRIGHT ); + } + else if( stricmp( orientationString, "facing_upright" ) == 0 ) + { + params[SPRITEORIENTATION]->SetIntValue( SPR_FACING_UPRIGHT ); + } + else if( stricmp( orientationString, "vp_parallel" ) == 0 ) + { + params[SPRITEORIENTATION]->SetIntValue( SPR_VP_PARALLEL ); + } + else if( stricmp( orientationString, "oriented" ) == 0 ) + { + params[SPRITEORIENTATION]->SetIntValue( SPR_ORIENTED ); + } + else if( stricmp( orientationString, "vp_parallel_oriented" ) == 0 ) + { + params[SPRITEORIENTATION]->SetIntValue( SPR_VP_PARALLEL_ORIENTED ); + } + else + { + Warning( "error with $spriteOrientation\n" ); + params[SPRITEORIENTATION]->SetIntValue( SPR_VP_PARALLEL_UPRIGHT ); + } + } + else + { + // default case + params[SPRITEORIENTATION]->SetIntValue( SPR_VP_PARALLEL_UPRIGHT ); + } + } + + SHADER_INIT + { + LoadTexture( BASETEXTURE ); + } + + SHADER_DRAW + { + SHADOW_STATE + { + pShaderShadow->EnableCulling( false ); + } + + switch( params[SPRITERENDERMODE]->GetIntValue() ) + { + case kRenderNormal: + SHADOW_STATE + { + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->DrawFlags( SHADER_DRAW_POSITION | SHADER_DRAW_TEXCOORD0 ); + FogToFogColor(); + } + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME ); + } + Draw(); + break; + case kRenderTransColor: + SHADOW_STATE + { + pShaderShadow->EnableDepthWrites( false ); + pShaderShadow->EnableBlending( true ); + pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA ); + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->DrawFlags( SHADER_DRAW_POSITION | SHADER_DRAW_TEXCOORD0 | SHADER_DRAW_COLOR ); + FogToFogColor(); + } + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME ); + } + Draw(); + break; + case kRenderTransTexture: + SHADOW_STATE + { + pShaderShadow->EnableDepthWrites( false ); + pShaderShadow->EnableBlending( true ); + pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA ); + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->DrawFlags( SHADER_DRAW_POSITION | SHADER_DRAW_TEXCOORD0 | SHADER_DRAW_COLOR ); + FogToFogColor(); + } + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME ); + } + Draw(); + break; + case kRenderGlow: + case kRenderWorldGlow: + SHADOW_STATE + { + pShaderShadow->EnableDepthWrites( false ); + pShaderShadow->EnableDepthTest( false ); + pShaderShadow->EnableBlending( true ); + pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE ); + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->DrawFlags( SHADER_DRAW_POSITION | SHADER_DRAW_TEXCOORD0 | SHADER_DRAW_COLOR ); + FogToBlack(); + } + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME ); + } + Draw(); + break; + case kRenderTransAlpha: + SHADOW_STATE + { + pShaderShadow->EnableDepthWrites( false ); + pShaderShadow->EnableBlending( true ); + pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA ); + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->DrawFlags( SHADER_DRAW_POSITION | SHADER_DRAW_TEXCOORD0 | SHADER_DRAW_COLOR ); + FogToFogColor(); + } + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME ); + } + Draw(); + break; + case kRenderTransAlphaAdd: + SHADOW_STATE + { + pShaderShadow->EnableDepthWrites( false ); + pShaderShadow->EnableBlending( true ); + pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA ); + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->DrawFlags( SHADER_DRAW_POSITION | SHADER_DRAW_TEXCOORD0 | SHADER_DRAW_COLOR ); + FogToFogColor(); + } + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME ); + } + Draw(); + + SHADOW_STATE + { + pShaderShadow->EnableDepthWrites( false ); + pShaderShadow->EnableBlending( true ); + pShaderShadow->BlendFunc( SHADER_BLEND_ONE_MINUS_SRC_ALPHA, SHADER_BLEND_ONE ); + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->DrawFlags( SHADER_DRAW_POSITION | SHADER_DRAW_TEXCOORD0 | SHADER_DRAW_COLOR ); + FogToBlack(); + } + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME ); + } + Draw(); + break; + + case kRenderTransAdd: + SHADOW_STATE + { + if( params[ IGNOREVERTEXCOLORS ]->GetIntValue() ) + { + pShaderShadow->DrawFlags( SHADER_DRAW_POSITION | SHADER_DRAW_TEXCOORD0 ); + } + else + { + pShaderShadow->DrawFlags( SHADER_DRAW_POSITION | SHADER_DRAW_TEXCOORD0 | SHADER_DRAW_COLOR ); + } + pShaderShadow->EnableConstantColor( true ); + pShaderShadow->EnableDepthWrites( false ); + pShaderShadow->EnableBlending( true ); + pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE ); + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + FogToBlack(); + } + DYNAMIC_STATE + { + SetColorState( COLOR, ALPHA ); + BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME ); + } + Draw(); + break; + case kRenderTransAddFrameBlend: + { + float flFrame = params[FRAME]->GetFloatValue(); + float flFade = params[ALPHA]->GetFloatValue(); + SHADOW_STATE + { + if( params[ IGNOREVERTEXCOLORS ]->GetIntValue() ) + { + pShaderShadow->DrawFlags( SHADER_DRAW_POSITION | SHADER_DRAW_TEXCOORD0 ); + } + else + { + pShaderShadow->DrawFlags( SHADER_DRAW_POSITION | SHADER_DRAW_TEXCOORD0 | SHADER_DRAW_COLOR ); + } + pShaderShadow->EnableConstantColor( true ); + pShaderShadow->EnableDepthWrites( false ); + pShaderShadow->EnableBlending( true ); + pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE ); + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + FogToBlack(); + } + DYNAMIC_STATE + { + float frameBlendAlpha = 1.0f - ( flFrame - ( int )flFrame ); + pShaderAPI->Color3f( flFade * frameBlendAlpha, flFade * frameBlendAlpha, flFade * frameBlendAlpha ); + ITexture *pTexture = params[BASETEXTURE]->GetTextureValue(); + BindTexture( SHADER_SAMPLER0, pTexture, ( int )flFrame ); + } + Draw(); + SHADOW_STATE + { + FogToBlack(); + } + DYNAMIC_STATE + { + float frameBlendAlpha = ( flFrame - ( int )flFrame ); + pShaderAPI->Color3f( flFade * frameBlendAlpha, flFade * frameBlendAlpha, flFade * frameBlendAlpha ); + ITexture *pTexture = params[BASETEXTURE]->GetTextureValue(); + int numAnimationFrames = pTexture->GetNumAnimationFrames(); + BindTexture( SHADER_SAMPLER0, pTexture, ( ( int )flFrame + 1 ) % numAnimationFrames ); + } + Draw(); + } + + break; + default: + ShaderWarning( "shader Sprite: Unknown sprite render mode\n" ); + break; + } + } +END_SHADER diff --git a/materialsystem/stdshaders/sprite_dx9.cpp b/materialsystem/stdshaders/sprite_dx9.cpp new file mode 100644 index 0000000..0a0bb9f --- /dev/null +++ b/materialsystem/stdshaders/sprite_dx9.cpp @@ -0,0 +1,490 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +// +//=============================================================================// + +#include "BaseVSShader.h" +#include +#include "const.h" + +#include "cpp_shader_constant_register_map.h" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +#include "sprite_vs20.inc" +#include "sprite_ps20.inc" +#include "sprite_ps20b.inc" + +// WARNING! Change these in engine/SpriteGn.h if you change them here! +#define SPR_VP_PARALLEL_UPRIGHT 0 +#define SPR_FACING_UPRIGHT 1 +#define SPR_VP_PARALLEL 2 +#define SPR_ORIENTED 3 +#define SPR_VP_PARALLEL_ORIENTED 4 + + +DEFINE_FALLBACK_SHADER( Sprite, Sprite_DX9 ) + +BEGIN_VS_SHADER( Sprite_DX9, + "Help for Sprite_DX9" ) + + BEGIN_SHADER_PARAMS + SHADER_PARAM( SPRITEORIGIN, SHADER_PARAM_TYPE_VEC3, "[0 0 0]", "sprite origin" ) + SHADER_PARAM( SPRITEORIENTATION, SHADER_PARAM_TYPE_INTEGER, "0", "sprite orientation" ) + SHADER_PARAM( SPRITERENDERMODE, SHADER_PARAM_TYPE_INTEGER, "0", "sprite rendermode" ) + SHADER_PARAM( IGNOREVERTEXCOLORS, SHADER_PARAM_TYPE_BOOL, "1", "ignore vertex colors" ) + SHADER_PARAM( NOSRGB, SHADER_PARAM_TYPE_BOOL, "0", "do not operate in srgb space" ) + SHADER_PARAM( HDRCOLORSCALE, SHADER_PARAM_TYPE_FLOAT, "1.0", "hdr color scale" ) + END_SHADER_PARAMS + + SHADER_FALLBACK + { + if (g_pHardwareConfig->GetDXSupportLevel() < 90) + return "Sprite_DX8"; + return 0; + } + SHADER_INIT_PARAMS() + { + // FIXME: This can share code with sprite.cpp + if (!params[ALPHA]->IsDefined()) + { + params[ALPHA]->SetFloatValue( 1.0f ); + } + + if (!params[HDRCOLORSCALE]->IsDefined()) + { + params[HDRCOLORSCALE]->SetFloatValue( 1.0f ); + } + + if ( !params[NOSRGB]->IsDefined() ) + { + // Disable sRGB reads and writes by default + params[NOSRGB]->SetIntValue( 1 ); + } + + SET_FLAGS( MATERIAL_VAR_NO_DEBUG_OVERRIDE ); + SET_FLAGS( MATERIAL_VAR_VERTEXCOLOR ); + SET_FLAGS( MATERIAL_VAR_VERTEXALPHA ); + + // translate from a string orientation to an enumeration + if (params[SPRITEORIENTATION]->IsDefined()) + { + const char *orientationString = params[SPRITEORIENTATION]->GetStringValue(); + if( stricmp( orientationString, "parallel_upright" ) == 0 ) + { + params[SPRITEORIENTATION]->SetIntValue( SPR_VP_PARALLEL_UPRIGHT ); + } + else if( stricmp( orientationString, "facing_upright" ) == 0 ) + { + params[SPRITEORIENTATION]->SetIntValue( SPR_FACING_UPRIGHT ); + } + else if( stricmp( orientationString, "vp_parallel" ) == 0 ) + { + params[SPRITEORIENTATION]->SetIntValue( SPR_VP_PARALLEL ); + } + else if( stricmp( orientationString, "oriented" ) == 0 ) + { + params[SPRITEORIENTATION]->SetIntValue( SPR_ORIENTED ); + } + else if( stricmp( orientationString, "vp_parallel_oriented" ) == 0 ) + { + params[SPRITEORIENTATION]->SetIntValue( SPR_VP_PARALLEL_ORIENTED ); + } + else + { + Warning( "error with $spriteOrientation\n" ); + params[SPRITEORIENTATION]->SetIntValue( SPR_VP_PARALLEL_UPRIGHT ); + } + } + else + { + // default case + params[SPRITEORIENTATION]->SetIntValue( SPR_VP_PARALLEL_UPRIGHT ); + } + } + + SHADER_INIT + { + bool bSRGB = s_ppParams[NOSRGB]->GetIntValue() == 0; + LoadTexture( BASETEXTURE, bSRGB ? TEXTUREFLAGS_SRGB : 0 ); + } + +#define SHADER_USE_VERTEX_COLOR 1 +#define SHADER_USE_CONSTANT_COLOR 2 + + void SetSpriteCommonShadowState( unsigned int shaderFlags ) + { + IShaderShadow *pShaderShadow = s_pShaderShadow; + s_pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + bool bSRGB = s_ppParams[NOSRGB]->GetIntValue() == 0; + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, bSRGB ); + + // Only enabling this on OSX() - it causes GL mode's light glow sprites to be much darker vs. D3D9 under Linux/Win GL. + bool bSRGBOutputAdapter = ( IsOSX() && !g_pHardwareConfig->FakeSRGBWrite() ) && !bSRGB; + + unsigned int flags = VERTEX_POSITION; + if( shaderFlags & SHADER_USE_VERTEX_COLOR ) + { + flags |= VERTEX_COLOR; + } + int numTexCoords = 1; + s_pShaderShadow->VertexShaderVertexFormat( flags, numTexCoords, 0, 0 ); + + DECLARE_STATIC_VERTEX_SHADER( sprite_vs20 ); + SET_STATIC_VERTEX_SHADER_COMBO( VERTEXCOLOR, ( shaderFlags & SHADER_USE_VERTEX_COLOR ) ? true : false ); + SET_STATIC_VERTEX_SHADER_COMBO( SRGB, bSRGB ); + SET_STATIC_VERTEX_SHADER( sprite_vs20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() || g_pHardwareConfig->ShouldAlwaysUseShaderModel2bShaders() ) // Always send GL down this path + { + DECLARE_STATIC_PIXEL_SHADER( sprite_ps20b ); + SET_STATIC_PIXEL_SHADER_COMBO( VERTEXCOLOR, ( shaderFlags & SHADER_USE_VERTEX_COLOR ) ? true : false ); + SET_STATIC_PIXEL_SHADER_COMBO( CONSTANTCOLOR, ( shaderFlags & SHADER_USE_CONSTANT_COLOR ) ? true : false ); + SET_STATIC_PIXEL_SHADER_COMBO( HDRTYPE, g_pHardwareConfig->GetHDRType() ); + SET_STATIC_PIXEL_SHADER_COMBO( SRGB, bSRGB ); + SET_STATIC_PIXEL_SHADER_COMBO( SRGB_OUTPUT_ADAPTER, bSRGBOutputAdapter ); + SET_STATIC_PIXEL_SHADER( sprite_ps20b ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( sprite_ps20 ); + SET_STATIC_PIXEL_SHADER_COMBO( VERTEXCOLOR, ( shaderFlags & SHADER_USE_VERTEX_COLOR ) ? true : false ); + SET_STATIC_PIXEL_SHADER_COMBO( CONSTANTCOLOR, ( shaderFlags & SHADER_USE_CONSTANT_COLOR ) ? true : false ); + SET_STATIC_PIXEL_SHADER_COMBO( HDRTYPE, g_pHardwareConfig->GetHDRType() ); + SET_STATIC_PIXEL_SHADER_COMBO( SRGB, bSRGB ); + SET_STATIC_PIXEL_SHADER( sprite_ps20 ); + } + + // OSX always has to sRGB write (don't do this on Linux/Win GL - it causes glow sprites to be way too dark) + s_pShaderShadow->EnableSRGBWrite( bSRGB || ( IsOSX() && !g_pHardwareConfig->FakeSRGBWrite() ) ); + } + + void SetSpriteCommonDynamicState( unsigned int shaderFlags ) + { + IShaderDynamicAPI *pShaderAPI = s_pShaderAPI; + bool bSRGB = s_ppParams[NOSRGB]->GetIntValue() == 0; + + BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME ); + + MaterialFogMode_t fogType = s_pShaderAPI->GetSceneFogMode(); + int fogIndex = ( fogType == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ) ? 1 : 0; + DECLARE_DYNAMIC_VERTEX_SHADER( sprite_vs20 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( DOWATERFOG, fogIndex ); + SET_DYNAMIC_VERTEX_SHADER( sprite_vs20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() || g_pHardwareConfig->ShouldAlwaysUseShaderModel2bShaders() ) // Always send GL down this path + { + DECLARE_DYNAMIC_PIXEL_SHADER( sprite_ps20b ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( HDRENABLED, IsHDREnabled() ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + SET_DYNAMIC_PIXEL_SHADER( sprite_ps20b ); + } + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( sprite_ps20 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( HDRENABLED, IsHDREnabled() ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + SET_DYNAMIC_PIXEL_SHADER( sprite_ps20 ); + } + + pShaderAPI->SetPixelShaderFogParams( PSREG_FOG_PARAMS ); + + float vEyePos_SpecExponent[4]; + pShaderAPI->GetWorldSpaceCameraPosition( vEyePos_SpecExponent ); + vEyePos_SpecExponent[3] = 0.0f; + pShaderAPI->SetPixelShaderConstant( PSREG_EYEPOS_SPEC_EXPONENT, vEyePos_SpecExponent, 1 ); + + if( shaderFlags & SHADER_USE_CONSTANT_COLOR ) + { + if ( bSRGB ) + SetPixelShaderConstantGammaToLinear( 0, COLOR, ALPHA ); + else + SetPixelShaderConstant( 0, COLOR, ALPHA ); + } + + if( IsHDREnabled() ) + { + if ( bSRGB ) + SetPixelShaderConstantGammaToLinear( 1, HDRCOLORSCALE ); + else + SetPixelShaderConstant( 1, HDRCOLORSCALE ); + } + } + + SHADER_DRAW + { + bool bSRGB = params[NOSRGB]->GetIntValue() == 0; + + SHADOW_STATE + { + pShaderShadow->EnableCulling( false ); + } + + switch( params[SPRITERENDERMODE]->GetIntValue() ) + { + case kRenderNormal: + SHADOW_STATE + { + FogToFogColor(); + + SetSpriteCommonShadowState( 0 ); + } + DYNAMIC_STATE + { + SetSpriteCommonDynamicState( 0 ); + } + Draw(); + break; + case kRenderTransColor: + case kRenderTransTexture: + SHADOW_STATE + { + pShaderShadow->EnableDepthWrites( false ); + pShaderShadow->EnableBlending( true ); + pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA ); + + FogToFogColor(); + + SetSpriteCommonShadowState( SHADER_USE_VERTEX_COLOR ); + } + DYNAMIC_STATE + { + SetSpriteCommonDynamicState( SHADER_USE_VERTEX_COLOR ); + } + Draw(); + break; + case kRenderGlow: + case kRenderWorldGlow: + SHADOW_STATE + { + pShaderShadow->EnableDepthWrites( false ); + pShaderShadow->EnableDepthTest( false ); + pShaderShadow->EnableBlending( true ); + pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE ); + + FogToBlack(); + + SetSpriteCommonShadowState( SHADER_USE_VERTEX_COLOR ); + } + DYNAMIC_STATE + { + SetSpriteCommonDynamicState( SHADER_USE_VERTEX_COLOR ); + } + Draw(); + break; + case kRenderTransAlpha: + // untested cut and past from kRenderTransAlphaAdd . . same as first pass of that. + SHADOW_STATE + { + pShaderShadow->EnableDepthWrites( false ); + pShaderShadow->EnableBlending( true ); + pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA ); + + FogToFogColor(); + + SetSpriteCommonShadowState( SHADER_USE_VERTEX_COLOR ); + } + DYNAMIC_STATE + { + SetSpriteCommonDynamicState( SHADER_USE_VERTEX_COLOR ); + } + Draw(); + break; + case kRenderTransAlphaAdd: + SHADOW_STATE + { + pShaderShadow->EnableDepthWrites( false ); + pShaderShadow->EnableBlending( true ); + pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA ); + + FogToFogColor(); + + SetSpriteCommonShadowState( SHADER_USE_VERTEX_COLOR ); + } + DYNAMIC_STATE + { + SetSpriteCommonDynamicState( SHADER_USE_VERTEX_COLOR ); + } + Draw(); + + SHADOW_STATE + { + SetInitialShadowState(); + pShaderShadow->EnableDepthWrites( false ); + pShaderShadow->EnableBlending( true ); + pShaderShadow->BlendFunc( SHADER_BLEND_ONE_MINUS_SRC_ALPHA, SHADER_BLEND_ONE ); + + FogToBlack(); + + SetSpriteCommonShadowState( SHADER_USE_VERTEX_COLOR ); + } + DYNAMIC_STATE + { + SetSpriteCommonDynamicState( SHADER_USE_VERTEX_COLOR ); + } + Draw(); + break; + + case kRenderTransAdd: + { + unsigned int flags = SHADER_USE_CONSTANT_COLOR; + if( !params[ IGNOREVERTEXCOLORS ]->GetIntValue() ) + { + flags |= SHADER_USE_VERTEX_COLOR; + } + SHADOW_STATE + { + pShaderShadow->EnableDepthWrites( false ); + pShaderShadow->EnableBlending( true ); + pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE ); + + FogToBlack(); + + SetSpriteCommonShadowState( flags ); + } + DYNAMIC_STATE + { + SetSpriteCommonDynamicState( flags ); + } + } + Draw(); + break; + case kRenderTransAddFrameBlend: + { + float flFrame = params[FRAME]->GetFloatValue(); + float flFade = params[ALPHA]->GetFloatValue(); + unsigned int flags = SHADER_USE_CONSTANT_COLOR; + if( !params[ IGNOREVERTEXCOLORS ]->GetIntValue() ) + { + flags |= SHADER_USE_VERTEX_COLOR; + } + SHADOW_STATE + { + pShaderShadow->EnableDepthWrites( false ); + pShaderShadow->EnableBlending( true ); + pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE ); + + FogToBlack(); + + SetSpriteCommonShadowState( flags ); + } + DYNAMIC_STATE + { + float frameBlendAlpha = 1.0f - ( flFrame - ( int )flFrame ); + ITexture *pTexture = params[BASETEXTURE]->GetTextureValue(); + BindTexture( SHADER_SAMPLER0, pTexture, ( int )flFrame ); + + MaterialFogMode_t fogType = s_pShaderAPI->GetSceneFogMode(); + int fogIndex = ( fogType == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ) ? 1 : 0; + DECLARE_DYNAMIC_VERTEX_SHADER( sprite_vs20 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( DOWATERFOG, fogIndex ); + SET_DYNAMIC_VERTEX_SHADER( sprite_vs20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() || g_pHardwareConfig->ShouldAlwaysUseShaderModel2bShaders() ) // Always send GL down this path + { + DECLARE_DYNAMIC_PIXEL_SHADER( sprite_ps20b ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( HDRENABLED, IsHDREnabled() ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + SET_DYNAMIC_PIXEL_SHADER( sprite_ps20b ); + } + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( sprite_ps20 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( HDRENABLED, IsHDREnabled() ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + SET_DYNAMIC_PIXEL_SHADER( sprite_ps20 ); + } + + pShaderAPI->SetPixelShaderFogParams( PSREG_FOG_PARAMS ); + + float vEyePos_SpecExponent[4]; + pShaderAPI->GetWorldSpaceCameraPosition( vEyePos_SpecExponent ); + vEyePos_SpecExponent[3] = 0.0f; + pShaderAPI->SetPixelShaderConstant( PSREG_EYEPOS_SPEC_EXPONENT, vEyePos_SpecExponent, 1 ); + + float color[4]; + if ( bSRGB ) + color[0] = color[1] = color[2] = GammaToLinear( flFade * frameBlendAlpha ); + else + color[0] = color[1] = color[2] = flFade * frameBlendAlpha; + color[3] = 1.0f; + s_pShaderAPI->SetPixelShaderConstant( 0, color ); + if( IsHDREnabled() ) + { + if ( bSRGB ) + SetPixelShaderConstantGammaToLinear( 1, HDRCOLORSCALE ); + else + SetPixelShaderConstant( 1, HDRCOLORSCALE ); + } + } + Draw(); + SHADOW_STATE + { + FogToBlack(); + + SetSpriteCommonShadowState( flags ); + } + DYNAMIC_STATE + { + float frameBlendAlpha = ( flFrame - ( int )flFrame ); + ITexture *pTexture = params[BASETEXTURE]->GetTextureValue(); + int numAnimationFrames = pTexture->GetNumAnimationFrames(); + BindTexture( SHADER_SAMPLER0, pTexture, ( ( int )flFrame + 1 ) % numAnimationFrames ); + + MaterialFogMode_t fogType = s_pShaderAPI->GetSceneFogMode(); + int fogIndex = ( fogType == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ) ? 1 : 0; + DECLARE_DYNAMIC_VERTEX_SHADER( sprite_vs20 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( DOWATERFOG, fogIndex ); + SET_DYNAMIC_VERTEX_SHADER( sprite_vs20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() || g_pHardwareConfig->ShouldAlwaysUseShaderModel2bShaders() ) // Always send GL down this path + { + DECLARE_DYNAMIC_PIXEL_SHADER( sprite_ps20b ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( HDRENABLED, IsHDREnabled() ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + SET_DYNAMIC_PIXEL_SHADER( sprite_ps20b ); + } + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( sprite_ps20 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( HDRENABLED, IsHDREnabled() ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + SET_DYNAMIC_PIXEL_SHADER( sprite_ps20 ); + } + + pShaderAPI->SetPixelShaderFogParams( PSREG_FOG_PARAMS ); + + float vEyePos_SpecExponent[4]; + pShaderAPI->GetWorldSpaceCameraPosition( vEyePos_SpecExponent ); + vEyePos_SpecExponent[3] = 0.0f; + pShaderAPI->SetPixelShaderConstant( PSREG_EYEPOS_SPEC_EXPONENT, vEyePos_SpecExponent, 1 ); + + float color[4]; + if ( bSRGB ) + color[0] = color[1] = color[2] = GammaToLinear( flFade * frameBlendAlpha ); + else + color[0] = color[1] = color[2] = flFade * frameBlendAlpha; + color[3] = 1.0f; + s_pShaderAPI->SetPixelShaderConstant( 0, color ); + if( IsHDREnabled() ) + { + if ( bSRGB ) + SetPixelShaderConstantGammaToLinear( 1, HDRCOLORSCALE ); + else + SetPixelShaderConstant( 1, HDRCOLORSCALE ); + } + } + Draw(); + } + + break; + default: + ShaderWarning( "shader Sprite: Unknown sprite render mode\n" ); + break; + } + } +END_SHADER diff --git a/materialsystem/stdshaders/sprite_ps11.psh b/materialsystem/stdshaders/sprite_ps11.psh new file mode 100644 index 0000000..021246d --- /dev/null +++ b/materialsystem/stdshaders/sprite_ps11.psh @@ -0,0 +1,15 @@ +; STATIC: "VERTEXCOLOR" "0..1" +; STATIC: "CONSTANTCOLOR" "0..1" + +ps.1.1 + +tex t0 +mov r0, t0 + +#if VERTEXCOLOR +mul r0, r0, v0 +#endif + +#if CONSTANTCOLOR +mul r0, r0, c0 +#endif \ No newline at end of file diff --git a/materialsystem/stdshaders/sprite_ps2x.fxc b/materialsystem/stdshaders/sprite_ps2x.fxc new file mode 100644 index 0000000..83a7ab0 --- /dev/null +++ b/materialsystem/stdshaders/sprite_ps2x.fxc @@ -0,0 +1,61 @@ +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX] +// STATIC: "VERTEXCOLOR" "0..1" +// STATIC: "CONSTANTCOLOR" "0..1" +// STATIC: "HDRTYPE" "0..2" +// STATIC: "SRGB" "0..1" +// STATIC: "SRGB_OUTPUT_ADAPTER" "0..1" [ps20b] + +// DYNAMIC: "HDRENABLED" "0..1" +// DYNAMIC: "PIXELFOGTYPE" "0..1" + +#include "common_ps_fxc.h" +#include "shader_constant_register_map.h" + +const HALF4 g_Color : register( c0 ); +const float g_HDRColorScale : register( c1 ); + +const float4 g_FogParams : register( PSREG_FOG_PARAMS ); +const float4 g_EyePos_SpecExponent : register( PSREG_EYEPOS_SPEC_EXPONENT ); + +sampler TexSampler : register( s0 ); + +struct PS_INPUT +{ + HALF2 baseTexCoord : TEXCOORD0; // Base texture coordinate + float4 color : TEXCOORD2; // Vertex color (from lighting or unlit) + + float4 worldPos_projPosZ : TEXCOORD7; // Necessary for pixel fog +}; + +float4 main( PS_INPUT i ) : COLOR +{ + float4 result, sample = tex2D( TexSampler, i.baseTexCoord ); + +#if VERTEXCOLOR + sample *= i.color; +#endif + +#if CONSTANTCOLOR + sample *= g_Color; +#endif + +#if HDRTYPE && HDRENABLED + sample.xyz *= g_HDRColorScale; +#endif + + float fogFactor = CalcPixelFogFactor( PIXELFOGTYPE, g_FogParams, g_EyePos_SpecExponent.z, i.worldPos_projPosZ.z, i.worldPos_projPosZ.w ); +#if SRGB + result = FinalOutput( sample, fogFactor, PIXELFOGTYPE, TONEMAP_SCALE_LINEAR ); +#else + result = FinalOutput( sample, fogFactor, PIXELFOGTYPE, TONEMAP_SCALE_GAMMA ); +#endif + + // On Posix, we're being forced through a linear-to-gamma curve but don't want it, so we do the opposite here first +#if SRGB_OUTPUT_ADAPTER + result = GammaToLinear( result ); +#endif + + return result; +} + diff --git a/materialsystem/stdshaders/sprite_vs11.vsh b/materialsystem/stdshaders/sprite_vs11.vsh new file mode 100644 index 0000000..5ffa45f --- /dev/null +++ b/materialsystem/stdshaders/sprite_vs11.vsh @@ -0,0 +1,9 @@ +vs.1.1 + +# STATIC: "VERTEXCOLOR" "0..1" +# DYNAMIC: "SKINNING" "0..0" +# DYNAMIC: "DOWATERFOG" "0..1" + +#include "UnlitGeneric_inc.vsh" + +&UnlitGeneric( 0, 0, 0, 0, $VERTEXCOLOR ); diff --git a/materialsystem/stdshaders/sprite_vs20.fxc b/materialsystem/stdshaders/sprite_vs20.fxc new file mode 100644 index 0000000..5e427c1 --- /dev/null +++ b/materialsystem/stdshaders/sprite_vs20.fxc @@ -0,0 +1,65 @@ +// STATIC: "VERTEXCOLOR" "0..1" +// STATIC: "SRGB" "0..1" +// DYNAMIC: "DOWATERFOG" "0..1" + +#include "common_vs_fxc.h" + +static const int g_FogType = DOWATERFOG; +static const bool g_bVertexColor = VERTEXCOLOR ? true : false; + +struct VS_INPUT +{ + // This is all of the stuff that we ever use. + float4 vPos : POSITION; + float4 vColor : COLOR0; + // make these float2's and stick the [n n 0 1] in the dot math. + float4 vTexCoord0 : TEXCOORD0; +}; + +struct VS_OUTPUT +{ + float4 projPos : POSITION; // Projection-space position +#if !defined( _X360 ) + float fog : FOG; +#endif + HALF2 baseTexCoord : TEXCOORD0; // Base texture coordinate + float4 color : TEXCOORD2; // Vertex color (from lighting or unlit) + + float4 worldPos_projPosZ : TEXCOORD7; // Necessary for pixel fog +}; + + +VS_OUTPUT main( const VS_INPUT v ) +{ + VS_OUTPUT o = ( VS_OUTPUT )0; + + float3 worldPos; + worldPos = mul4x3( v.vPos, cModel[0] ); + + // Transform into projection space + float4 projPos = mul( float4( worldPos, 1 ), cViewProj ); + o.projPos = projPos; + projPos.z = dot( float4( worldPos, 1 ), cViewProjZ ); + + o.worldPos_projPosZ = float4( worldPos.xyz, projPos.z ); + +#if !defined( _X360 ) + o.fog = CalcFog( worldPos, projPos, g_FogType ); +#endif + if ( g_bVertexColor ) + { + // Assume that this is unlitgeneric if you are using vertex color. +#if SRGB + o.color.rgba = GammaToLinear( v.vColor.rgba ); +#else + o.color.rgba = v.vColor.rgba; +#endif + } + + // Base texture coordinates + o.baseTexCoord.xy = v.vTexCoord0.xy; + + return o; +} + + diff --git a/materialsystem/stdshaders/spritecard.cpp b/materialsystem/stdshaders/spritecard.cpp new file mode 100644 index 0000000..19cbe69 --- /dev/null +++ b/materialsystem/stdshaders/spritecard.cpp @@ -0,0 +1,484 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: shader for drawing sprites as cards, with animation frame lerping +// +// $Header: $ +// $NoKeywords: $ +//===========================================================================// + +#include "BaseVSShader.h" +#include "convar.h" + +// STDSHADER_DX9_DLL_EXPORT +#include "spritecard_ps20.inc" +#include "spritecard_ps20b.inc" +#include "spritecard_vs20.inc" +#include "splinecard_vs20.inc" + +#if SUPPORT_DX8 +// STDSHADER_DX8_DLL_EXPORT +#include "spritecard_vs11.inc" +#include "spritecard_ps11.inc" +#include "splinecard_vs11.inc" +#endif + +#include "tier0/icommandline.h" //command line + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +#define DEFAULT_PARTICLE_FEATHERING_ENABLED 1 + +#ifdef STDSHADER_DX8_DLL_EXPORT +DEFINE_FALLBACK_SHADER( Spritecard, Spritecard_DX8 ) +#endif + +int GetDefaultDepthFeatheringValue( void ) //Allow the command-line to go against the default soft-particle value +{ + static int iRetVal = -1; + + if( iRetVal == -1 ) + { +# if( DEFAULT_PARTICLE_FEATHERING_ENABLED == 1 ) + { + if( CommandLine()->CheckParm( "-softparticlesdefaultoff" ) ) + iRetVal = 0; + else + iRetVal = 1; + } +# else + { + if( CommandLine()->CheckParm( "-softparticlesdefaulton" ) ) + iRetVal = 1; + else + iRetVal = 0; + } +# endif + } + + // On low end parts on the Mac, we reduce particles and shut off depth blending here + static ConVarRef mat_reduceparticles( "mat_reduceparticles" ); + if ( mat_reduceparticles.GetBool() ) + { + iRetVal = 0; + } + + return iRetVal; +} + + +#ifdef STDSHADER_DX9_DLL_EXPORT +BEGIN_VS_SHADER_FLAGS( Spritecard, "Help for Spritecard", SHADER_NOT_EDITABLE ) +#else +BEGIN_VS_SHADER_FLAGS( Spritecard_DX8, "Help for Spritecard_DX8", SHADER_NOT_EDITABLE ) +#endif + +BEGIN_SHADER_PARAMS +SHADER_PARAM( DEPTHBLEND, SHADER_PARAM_TYPE_INTEGER, "0", "fade at intersection boundaries" ) +SHADER_PARAM( DEPTHBLENDSCALE, SHADER_PARAM_TYPE_FLOAT, "50.0", "Amplify or reduce DEPTHBLEND fading. Lower values make harder edges." ) +SHADER_PARAM( ORIENTATION, SHADER_PARAM_TYPE_INTEGER, "0", "0 = always face camera, 1 = rotate around z, 2= parallel to ground" ) +SHADER_PARAM( ADDBASETEXTURE2, SHADER_PARAM_TYPE_FLOAT, "0.0", "amount to blend second texture into frame by" ) +SHADER_PARAM( OVERBRIGHTFACTOR, SHADER_PARAM_TYPE_FLOAT, "1.0", "overbright factor for texture. For HDR effects.") +SHADER_PARAM( DUALSEQUENCE, SHADER_PARAM_TYPE_INTEGER, "0", "blend two separate animated sequences.") +SHADER_PARAM( SEQUENCE_BLEND_MODE, SHADER_PARAM_TYPE_INTEGER, "0", "defines the blend mode between the images un dual sequence particles. 0 = avg, 1=alpha from first, rgb from 2nd, 2= first over second" ) +SHADER_PARAM( MAXLUMFRAMEBLEND1, SHADER_PARAM_TYPE_INTEGER, "0", "instead of blending between animation frames for the first sequence, select pixels based upon max luminance" ) +SHADER_PARAM( MAXLUMFRAMEBLEND2, SHADER_PARAM_TYPE_INTEGER, "0", "instead of blending between animation frames for the 2nd sequence, select pixels based upon max luminance" ) +SHADER_PARAM( RAMPTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "if specified, then the red value of the image is used to index this ramp to produce the output color" ) +SHADER_PARAM( ZOOMANIMATESEQ2, SHADER_PARAM_TYPE_FLOAT, "1.0", "amount to gradually zoom between frames on the second sequence. 2.0 will double the size of a frame over its lifetime.") +SHADER_PARAM( EXTRACTGREENALPHA, SHADER_PARAM_TYPE_INTEGER, "0", "grayscale data sitting in green/alpha channels") +SHADER_PARAM( ADDOVERBLEND, SHADER_PARAM_TYPE_INTEGER, "0", "use ONE:INVSRCALPHA blending") +SHADER_PARAM( ADDSELF, SHADER_PARAM_TYPE_FLOAT, "0.0", "amount of base texture to additively blend in" ) +SHADER_PARAM( BLENDFRAMES, SHADER_PARAM_TYPE_BOOL, "1", "whether or not to smoothly blend between animated frames" ) +SHADER_PARAM( MINSIZE, SHADER_PARAM_TYPE_FLOAT, "0.0", "minimum screen fractional size of particle") +SHADER_PARAM( STARTFADESIZE, SHADER_PARAM_TYPE_FLOAT, "10.0", "screen fractional size to start fading particle out") +SHADER_PARAM( ENDFADESIZE, SHADER_PARAM_TYPE_FLOAT, "20.0", "screen fractional size to finish fading particle out") +SHADER_PARAM( MAXSIZE, SHADER_PARAM_TYPE_FLOAT, "20.0", "maximum screen fractional size of particle") +SHADER_PARAM( USEINSTANCING, SHADER_PARAM_TYPE_BOOL, "1", "whether to use GPU vertex instancing (submit 1 vert per particle quad)") +SHADER_PARAM( SPLINETYPE, SHADER_PARAM_TYPE_INTEGER, "0", "spline type 0 = none, 1=ctamull rom") +SHADER_PARAM( MAXDISTANCE, SHADER_PARAM_TYPE_FLOAT, "100000.0", "maximum distance to draw particles at") +SHADER_PARAM( FARFADEINTERVAL, SHADER_PARAM_TYPE_FLOAT, "400.0", "interval over which to fade out far away particles") +END_SHADER_PARAMS + +SHADER_INIT_PARAMS() +{ + INIT_FLOAT_PARM( MAXDISTANCE, 100000.0); + INIT_FLOAT_PARM( FARFADEINTERVAL, 400.0); + INIT_FLOAT_PARM( MAXSIZE, 20.0 ); + INIT_FLOAT_PARM( ENDFADESIZE, 20.0 ); + INIT_FLOAT_PARM( STARTFADESIZE, 10.0 ); + INIT_FLOAT_PARM( DEPTHBLENDSCALE, 50.0 ); + INIT_FLOAT_PARM( OVERBRIGHTFACTOR, 1.0 ); + INIT_FLOAT_PARM( ADDBASETEXTURE2, 0.0 ); + INIT_FLOAT_PARM( ADDSELF, 0.0 ); + INIT_FLOAT_PARM( ZOOMANIMATESEQ2, 0.0 ); + + if ( !params[DEPTHBLEND]->IsDefined() ) + { + params[ DEPTHBLEND ]->SetIntValue( GetDefaultDepthFeatheringValue() ); + } + if ( !g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + params[ DEPTHBLEND ]->SetIntValue( 0 ); + } + if ( !params[DUALSEQUENCE]->IsDefined() ) + { + params[DUALSEQUENCE]->SetIntValue( 0 ); + } + if ( !params[MAXLUMFRAMEBLEND1]->IsDefined() ) + { + params[MAXLUMFRAMEBLEND1]->SetIntValue( 0 ); + } + if ( !params[MAXLUMFRAMEBLEND2]->IsDefined() ) + { + params[MAXLUMFRAMEBLEND2]->SetIntValue( 0 ); + } + if ( !params[EXTRACTGREENALPHA]->IsDefined() ) + { + params[EXTRACTGREENALPHA]->SetIntValue( 0 ); + } + if ( !params[ADDOVERBLEND]->IsDefined() ) + { + params[ADDOVERBLEND]->SetIntValue( 0 ); + } + if ( !params[BLENDFRAMES]->IsDefined() ) + { + params[ BLENDFRAMES ]->SetIntValue( 1 ); + } + if ( !params[USEINSTANCING]->IsDefined() ) + { + params[ USEINSTANCING ]->SetIntValue( IsX360() ? 1 : 0 ); + } + SET_FLAGS2( MATERIAL_VAR2_IS_SPRITECARD ); +} + +SHADER_FALLBACK +{ +#ifdef STDSHADER_DX9_DLL_EXPORT + if ( g_pHardwareConfig->GetDXSupportLevel() < 90 ) + return "SpriteCard_DX8"; +#endif +#ifdef STDSHADER_DX8_DLL_EXPORT + // STDSHADER_DX8_DLL_EXPORT + if ( g_pHardwareConfig->GetDXSupportLevel() < 80 ) + return "Wireframe"; +#endif + return 0; +} + +SHADER_INIT +{ +#ifdef STDSHADER_DX9_DLL_EXPORT + const bool bDX8 = false; +#endif +#ifdef STDSHADER_DX8_DLL_EXPORT + const bool bDX8 = true; +#endif + + SET_FLAGS2( MATERIAL_VAR2_LIGHTING_VERTEX_LIT ); + + if ( params[BASETEXTURE]->IsDefined() ) + { + bool bExtractGreenAlpha = false; + if ( params[EXTRACTGREENALPHA]->IsDefined() ) + { + bExtractGreenAlpha = params[EXTRACTGREENALPHA]->GetIntValue() != 0; + } + + LoadTexture( BASETEXTURE, !bExtractGreenAlpha && !bDX8 ? TEXTUREFLAGS_SRGB : 0 ); + } + if ( params[RAMPTEXTURE]->IsDefined() ) + { + LoadTexture( RAMPTEXTURE, TEXTUREFLAGS_SRGB ); + } +} + +SHADER_DRAW +{ +#ifdef STDSHADER_DX9_DLL_EXPORT + const bool bDX8 = false; +#endif +#ifdef STDSHADER_DX8_DLL_EXPORT + const bool bDX8 = true; +#endif + bool bUseRampTexture = (! bDX8 ) && ( params[RAMPTEXTURE]->IsDefined() ); + bool bZoomSeq2 = (! bDX8 ) && ( ( params[ZOOMANIMATESEQ2]->GetFloatValue()) > 1.0 ); + bool bDepthBlend = (! bDX8 ) && ( params[DEPTHBLEND]->GetIntValue() != 0 ); + bool bAdditive2ndTexture = params[ADDBASETEXTURE2]->GetFloatValue() != 0.0; + int nSplineType = params[SPLINETYPE]->GetIntValue(); + + SHADOW_STATE + { + bool bSecondSequence = params[DUALSEQUENCE]->GetIntValue() != 0; + bool bAddOverBlend = params[ADDOVERBLEND]->GetIntValue() != 0; + bool bExtractGreenAlpha = (! bDX8 ) && ( params[EXTRACTGREENALPHA]->GetIntValue() != 0 ); + bool bBlendFrames = (! bDX8 ) && ( params[BLENDFRAMES]->GetIntValue() != 0 ); + if ( nSplineType ) + { + bBlendFrames = false; + } + bool bAddSelf = params[ADDSELF]->GetFloatValue() != 0.0; + bool bUseInstancing = IsX360() ? ( params[ USEINSTANCING ]->GetIntValue() != 0 ) : false; + if ( nSplineType ) + bUseInstancing = false; + + // draw back-facing because of yaw spin + pShaderShadow->EnableCulling( false ); + + // Be sure not to write to dest alpha + pShaderShadow->EnableAlphaWrites( false ); + + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + if ( bDX8 ) + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + + if ( bAdditive2ndTexture && bDX8 ) + pShaderShadow->EnableTexture( SHADER_SAMPLER3, true ); + + if ( bUseRampTexture ) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER1, true ); + } + + if ( bDepthBlend ) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER2, true ); + } + + if ( bAdditive2ndTexture || bAddSelf ) + pShaderShadow->EnableAlphaTest( false ); + else + pShaderShadow->EnableAlphaTest( true ); + + pShaderShadow->AlphaFunc( SHADER_ALPHAFUNC_GREATER, 0.01f ); + + if ( bAdditive2ndTexture || bAddOverBlend || bAddSelf ) + { + EnableAlphaBlending( SHADER_BLEND_ONE, SHADER_BLEND_ONE_MINUS_SRC_ALPHA ); + } + else + { + 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 ); + } + } + + unsigned int flags = VERTEX_POSITION | VERTEX_COLOR; + static int s_TexCoordSize[8]={4, // 0 = sheet bounding uvs, frame0 + 4, // 1 = sheet bounding uvs, frame 1 + 4, // 2 = frame blend, rot, radius, ??? + 2, // 3 = corner identifier ( 0/0,1/0,1/1, 1/0 ) + 4, // 4 = texture 2 bounding uvs + 4, // 5 = second sequence bounding uvs, frame0 + 4, // 6 = second sequence bounding uvs, frame1 + 4, // 7 = second sequence frame blend, ?,?,? + }; + static int s_TexCoordSizeSpline[]={4, // 0 = sheet bounding uvs, frame0 + 4, // 1 = sheet bounding uvs, frame 1 + 4, // 2 = frame blend, rot, radius, ??? + 4, // 3 = corner identifier ( 0/0,1/0,1/1, 1/0 ) + 4, // 4 = texture 2 bounding uvs + 4, // 5 = second sequence bounding uvs, frame0 + 4, // 6 = second sequence bounding uvs, frame1 + 4, // 7 = second sequence frame blend, ?,?,? + }; + + int numTexCoords = 4; + if ( true /* bAdditive2ndTexture */ ) // there is no branch for 2nd texture in the VS! -henryg + { + numTexCoords = 5; + } + if ( bSecondSequence ) + { + // the whole shebang - 2 sequences, with a possible multi-image sequence first + numTexCoords = 8; + } + pShaderShadow->VertexShaderVertexFormat( flags, + numTexCoords, + nSplineType? s_TexCoordSizeSpline : s_TexCoordSize, 0 ); + + if ( bDX8 ) + { +#if SUPPORT_DX8 + if ( nSplineType ) + { + DECLARE_STATIC_VERTEX_SHADER( splinecard_vs11 ); + SET_STATIC_VERTEX_SHADER( splinecard_vs11 ); + } + else + { + DECLARE_STATIC_VERTEX_SHADER( spritecard_vs11 ); + if ( bSecondSequence ) + bAdditive2ndTexture = false; + SET_STATIC_VERTEX_SHADER_COMBO( DUALSEQUENCE, false ); + SET_STATIC_VERTEX_SHADER_COMBO( ZOOM_ANIMATE_SEQ2, false ); + SET_STATIC_VERTEX_SHADER_COMBO( EXTRACTGREENALPHA, bExtractGreenAlpha ); + SET_STATIC_VERTEX_SHADER( spritecard_vs11 ); + } + + DECLARE_STATIC_PIXEL_SHADER( spritecard_ps11 ); + SET_STATIC_PIXEL_SHADER_COMBO( ADDBASETEXTURE2, bAdditive2ndTexture ); + SET_STATIC_PIXEL_SHADER_COMBO( ADDSELF, bAddSelf ); + SET_STATIC_PIXEL_SHADER_COMBO( USEALPHAASRGB, bSecondSequence ); + SET_STATIC_PIXEL_SHADER( spritecard_ps11 ); +#endif + } + else + { + if ( nSplineType ) + { + DECLARE_STATIC_VERTEX_SHADER( splinecard_vs20 ); + SET_STATIC_VERTEX_SHADER( splinecard_vs20 ); + } + else + { + DECLARE_STATIC_VERTEX_SHADER( spritecard_vs20 ); + SET_STATIC_VERTEX_SHADER_COMBO( DUALSEQUENCE, bSecondSequence ); + SET_STATIC_VERTEX_SHADER_COMBO( ZOOM_ANIMATE_SEQ2, bZoomSeq2 ); + SET_STATIC_VERTEX_SHADER_COMBO( EXTRACTGREENALPHA, bExtractGreenAlpha ); + SET_STATIC_VERTEX_SHADER_COMBO( USE_INSTANCING, bUseInstancing ); + SET_STATIC_VERTEX_SHADER( spritecard_vs20 ); + } + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_STATIC_PIXEL_SHADER( spritecard_ps20b ); + SET_STATIC_PIXEL_SHADER_COMBO( ADDBASETEXTURE2, bAdditive2ndTexture ); + SET_STATIC_PIXEL_SHADER_COMBO( ADDSELF, bAddSelf ); + SET_STATIC_PIXEL_SHADER_COMBO( ANIMBLEND, bBlendFrames ); + SET_STATIC_PIXEL_SHADER_COMBO( DUALSEQUENCE, bSecondSequence ); + SET_STATIC_PIXEL_SHADER_COMBO( SEQUENCE_BLEND_MODE, bSecondSequence ? params[SEQUENCE_BLEND_MODE]->GetIntValue() : 0 ); + SET_STATIC_PIXEL_SHADER_COMBO( MAXLUMFRAMEBLEND1, params[MAXLUMFRAMEBLEND1]->GetIntValue() ); + SET_STATIC_PIXEL_SHADER_COMBO( MAXLUMFRAMEBLEND2, bSecondSequence? params[MAXLUMFRAMEBLEND1]->GetIntValue() : 0 ); + SET_STATIC_PIXEL_SHADER_COMBO( COLORRAMP, bUseRampTexture ); + SET_STATIC_PIXEL_SHADER_COMBO( EXTRACTGREENALPHA, bExtractGreenAlpha ); + SET_STATIC_PIXEL_SHADER_COMBO( DEPTHBLEND, bDepthBlend ); + SET_STATIC_PIXEL_SHADER( spritecard_ps20b ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( spritecard_ps20 ); + SET_STATIC_PIXEL_SHADER_COMBO( ADDBASETEXTURE2, bAdditive2ndTexture ); + SET_STATIC_PIXEL_SHADER_COMBO( DUALSEQUENCE, bSecondSequence ); + SET_STATIC_PIXEL_SHADER_COMBO( ADDSELF, bAddSelf ); + SET_STATIC_PIXEL_SHADER_COMBO( ANIMBLEND, bBlendFrames ); + SET_STATIC_PIXEL_SHADER_COMBO( SEQUENCE_BLEND_MODE, bSecondSequence ? params[SEQUENCE_BLEND_MODE]->GetIntValue() : 0 ); + SET_STATIC_PIXEL_SHADER_COMBO( MAXLUMFRAMEBLEND1, params[MAXLUMFRAMEBLEND1]->GetIntValue() ); + SET_STATIC_PIXEL_SHADER_COMBO( MAXLUMFRAMEBLEND2, bSecondSequence? params[MAXLUMFRAMEBLEND1]->GetIntValue() : 0 ); + SET_STATIC_PIXEL_SHADER_COMBO( COLORRAMP, bUseRampTexture ); + SET_STATIC_PIXEL_SHADER_COMBO( EXTRACTGREENALPHA, bExtractGreenAlpha ); + SET_STATIC_PIXEL_SHADER( spritecard_ps20 ); + } + + if ( !bDX8 ) + pShaderShadow->EnableSRGBWrite( true ); + + if( !bExtractGreenAlpha && !bDX8 ) + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, true ); + } + } + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME ); + + if ( bDX8 ) // bind on 2nd sampelr so we can lerp + BindTexture( SHADER_SAMPLER1, BASETEXTURE, FRAME ); + + if ( bDX8 && bAdditive2ndTexture ) + BindTexture( SHADER_SAMPLER3, BASETEXTURE, FRAME ); + + if ( bUseRampTexture && ( !bDX8 ) ) + { + BindTexture( SHADER_SAMPLER1, RAMPTEXTURE, FRAME ); + } + + if ( bDepthBlend ) + { + pShaderAPI->BindStandardTexture( SHADER_SAMPLER2, TEXTURE_FRAME_BUFFER_FULL_DEPTH ); + } + + LoadViewportTransformScaledIntoVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_10 ); + + int nOrientation = params[ORIENTATION]->GetIntValue(); + nOrientation = clamp( nOrientation, 0, 2 ); + + // We need these only when screen-orienting + if ( nOrientation == 0 ) + { + LoadModelViewMatrixIntoVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0 ); + LoadProjectionMatrixIntoVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_3 ); + } + + if ( bZoomSeq2 ) + { + float flZScale=1.0/(params[ZOOMANIMATESEQ2]->GetFloatValue()); + float C0[4]={ (float)(0.5*(1.0+flZScale)), flZScale, 0, 0 }; + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_7, C0, + ARRAYSIZE(C0)/4 ); + } + + // set fade constants in vsconsts 8 and 9 + float flMaxDistance = params[MAXDISTANCE]->GetFloatValue(); + float flStartFade = max( 1.f, flMaxDistance - params[FARFADEINTERVAL]->GetFloatValue() ); + + float VC0[8]={ params[MINSIZE]->GetFloatValue(), params[MAXSIZE]->GetFloatValue(), + params[STARTFADESIZE]->GetFloatValue(), params[ENDFADESIZE]->GetFloatValue(), + flStartFade, (float)(1.0/(flMaxDistance-flStartFade)), + 0,0 }; + + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_8, VC0, ARRAYSIZE(VC0)/4 ); + + pShaderAPI->SetDepthFeatheringPixelShaderConstant( 2, params[DEPTHBLENDSCALE]->GetFloatValue() ); + + float C0[4]={ params[ADDBASETEXTURE2]->GetFloatValue(), + params[OVERBRIGHTFACTOR]->GetFloatValue(), + params[ADDSELF]->GetFloatValue(), + 0.0f }; + + if ( bDX8 && ( !bAdditive2ndTexture ) ) // deal with 0..1 limit for pix shader constants + { + C0[2] *= 0.25; + C0[1] *= 0.25; + } + + pShaderAPI->SetPixelShaderConstant( 0, C0, ARRAYSIZE(C0)/4 ); + + if ( g_pHardwareConfig->GetDXSupportLevel() < 90 ) + { +#if SUPPORT_DX8 + if ( nSplineType ) + { + DECLARE_DYNAMIC_VERTEX_SHADER( splinecard_vs11 ); + SET_DYNAMIC_VERTEX_SHADER( splinecard_vs11 ); + } + else + { + DECLARE_DYNAMIC_VERTEX_SHADER( spritecard_vs11 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( ORIENTATION, nOrientation ); + SET_DYNAMIC_VERTEX_SHADER( spritecard_vs11 ); + } +#endif + } + else + { + if ( nSplineType ) + { + DECLARE_DYNAMIC_VERTEX_SHADER( splinecard_vs20 ); + SET_DYNAMIC_VERTEX_SHADER( splinecard_vs20 ); + } + else + { + DECLARE_DYNAMIC_VERTEX_SHADER( spritecard_vs20 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( ORIENTATION, nOrientation ); + SET_DYNAMIC_VERTEX_SHADER( spritecard_vs20 ); + } + } + } + Draw( ); +} +END_SHADER diff --git a/materialsystem/stdshaders/spritecard_ps11.fxc b/materialsystem/stdshaders/spritecard_ps11.fxc new file mode 100644 index 0000000..624362c --- /dev/null +++ b/materialsystem/stdshaders/spritecard_ps11.fxc @@ -0,0 +1,72 @@ +// STATIC: "ADDBASETEXTURE2" "0..1" +// STATIC: "ADDSELF" "0..1" +// STATIC: "USEALPHAASRGB" "0..1" +// SKIP: $USEALPHAASRGB && $ADDSELF +// SKIP: $USEALPHAASRGB && $ADDBASETEXTURE2 + +#define HDRTYPE HDR_TYPE_NONE +#include "common_ps_fxc.h" + +struct PS_INPUT +{ + float2 texCoord0 : TEXCOORD0; + float2 texCoord1 : TEXCOORD1; + float4 argbcolor : COLOR; + float4 blendfactor0 : TEXCOORD2; +#if ADDBASETEXTURE2 + float2 texCoord2 : TEXCOORD3; +#endif + float4 vScreenPos : TEXCOORD7; +}; + +sampler BaseTextureSampler : register( s0 ); + +#if ADDBASETEXTURE2 +sampler BaseTextureSampler2 : register( s3 ); +#endif + +sampler BaseTextureSampler1 : register( s1 ); +const float4 g_Parameters : register( c0 ); +const float4 g_ColorPowers : register( c1 ); + +#define fAdditiveBlendWeight g_Parameters.x +#define fOverbrightFactor g_Parameters.y +#define fAdditiveSelfBlendWeight g_Parameters.z +#define fSoftParticleBlendScale g_Parameters.w + +#pragma warning( disable : 4707 4704 ) +float4 main( PS_INPUT i ) : COLOR +{ + // Sample frames from texture 0 +#if ( ! ADDSELF ) && ( ! ADDBASETEXTURE2 ) + float4 baseTex0 = tex2D( BaseTextureSampler, i.texCoord0 ); + float4 baseTex1 = tex2D( BaseTextureSampler1, i.texCoord1 ); + float4 blended_rgb = lerp( baseTex0, baseTex1, i.blendfactor0.x ); +#else + float4 blended_rgb = tex2D( BaseTextureSampler, i.texCoord0 ); +#endif +#if USEALPHAASRGB + blended_rgb.rgb = blended_rgb.a; +#endif + +#if ADDBASETEXTURE2 + blended_rgb.a *= i.argbcolor.a; + + // In this case, we don't really want to pre-multiply by alpha + float4 color2 = tex2D( BaseTextureSampler2, i.texCoord2 ); + blended_rgb.rgb *= blended_rgb.a; + blended_rgb.rgb += fOverbrightFactor * fAdditiveBlendWeight * i.argbcolor.a * color2; + blended_rgb.rgb *= 2 * i.argbcolor.rgb; +#else +#if ADDSELF + blended_rgb.a *= i.argbcolor.a; + blended_rgb.rgb *= blended_rgb.a; + blended_rgb.rgb += fOverbrightFactor * 8 * fAdditiveSelfBlendWeight * blended_rgb; + blended_rgb.rgb *= 2 * i.argbcolor.rgb; +#else + blended_rgb *= i.argbcolor; +#endif +#endif + return blended_rgb; +} + diff --git a/materialsystem/stdshaders/spritecard_ps2x.fxc b/materialsystem/stdshaders/spritecard_ps2x.fxc new file mode 100644 index 0000000..1281d33 --- /dev/null +++ b/materialsystem/stdshaders/spritecard_ps2x.fxc @@ -0,0 +1,194 @@ +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX] +// STATIC: "DUALSEQUENCE" "0..1" +// STATIC: "SEQUENCE_BLEND_MODE" "0..2" +// STATIC: "ADDBASETEXTURE2" "0..1" +// STATIC: "MAXLUMFRAMEBLEND1" "0..1" +// STATIC: "MAXLUMFRAMEBLEND2" "0..1" +// STATIC: "EXTRACTGREENALPHA" "0..1" +// STATIC: "COLORRAMP" "0..1" +// STATIC: "ANIMBLEND" "0..1" +// STATIC: "ADDSELF" "0..1" +// STATIC: "DEPTHBLEND" "0..1" [ps20b] + +#define COMBINE_MODE_AVERAGE 0 +#define COMBINE_MODE_USE_FIRST_AS_ALPHA_MASK_ON_SECOND 1 +#define COMBINE_MODE_USE_FIRST_OVER_SECOND 2 + +#define HDRTYPE HDR_TYPE_NONE +#include "common_ps_fxc.h" + +const float4 g_Parameters : register( c0 ); +const float4 g_DepthFeatheringConstants : register( c2 ); + +#define fAdditiveBlendWeight g_Parameters.x +#define fOverbrightFactor g_Parameters.y +#define fAdditiveSelfBlendWeight g_Parameters.z + +struct PS_INPUT +{ + float2 texCoord0 : TEXCOORD0; + float2 texCoord1 : TEXCOORD1; + float4 argbcolor : COLOR; + float4 blendfactor0 : TEXCOORD2; +#if ADDBASETEXTURE2 + float2 texCoord2 : TEXCOORD3; +#endif +#if EXTRACTGREENALPHA + float4 blendfactor1 : TEXCOORD4; +#endif + +#if DUALSEQUENCE + float2 vSeq2TexCoord0 : TEXCOORD5; + float2 vSeq2TexCoord1 : TEXCOORD6; +#endif + +#if defined( REVERSE_DEPTH_ON_X360 ) + float4 vScreenPos_ReverseZ : TEXCOORD7; +#else + float4 vScreenPos : TEXCOORD7; +#endif +}; + +sampler BaseTextureSampler : register( s0 ); +sampler ColorRampSampler : register( s1 ); +sampler DepthSampler : register( s2 ); + +float4 main( PS_INPUT i ) : COLOR +{ + bool bMaxLumFrameBlend1 = MAXLUMFRAMEBLEND1 ? true : false; + bool bMaxLumFrameBlend2 = MAXLUMFRAMEBLEND2 ? true : false; + bool bExtractGreenAlpha = EXTRACTGREENALPHA ? true : false; + bool bAddBaseTexture2 = ADDBASETEXTURE2 ? true : false; + bool bDualSequence = DUALSEQUENCE ? true : false; + bool bColorRamp = COLORRAMP ? true : false; +#ifdef DEPTHBLEND + bool bDepthBlend = DEPTHBLEND ? true : false; +#endif + int nSequenceBlendMode = SEQUENCE_BLEND_MODE; + + // Sample frames from texture 0 + float4 baseTex0 = tex2D( BaseTextureSampler, i.texCoord0 ); + + float4 baseTex1 = tex2D( BaseTextureSampler, i.texCoord1 ); + + // Blend by default (may override with bMaxLumFrameBlend1 or bExtractGreenAlpha) +#if ANIMBLEND + float4 blended_rgb = lerp( baseTex0, baseTex1, i.blendfactor0.x ); +#else + float4 blended_rgb = baseTex0; +#endif + + if ( bMaxLumFrameBlend1 ) + { + // Blend between animation frames based upon max luminance + float lum0 = dot( float3(.3, .59, .11), baseTex0.rgb * (1-i.blendfactor0.x)); + float lum1 = dot( float3(.3, .59, .11), baseTex1.rgb * i.blendfactor0.x); + + if ( lum0 > lum1 ) + blended_rgb = baseTex0; + else + blended_rgb = baseTex1; + } + else if( bExtractGreenAlpha ) + { +#if EXTRACTGREENALPHA + // Weight Green/Alphas from the two frames for a scalar result + blended_rgb = dot( baseTex0, i.blendfactor0 ) + dot( baseTex1, i.blendfactor1 ); +#endif + } + +#if DUALSEQUENCE + if ( bDualSequence ) + { + baseTex0 = tex2D( BaseTextureSampler, i.vSeq2TexCoord0 ); + baseTex1 = tex2D( BaseTextureSampler, i.vSeq2TexCoord1 ); + + // Blend by default (may override with bMaxLumFrameBlend2) + float4 rgb2 = lerp( baseTex0, baseTex1, i.blendfactor0.z ); + + if ( bMaxLumFrameBlend2 ) + { + // blend between animation frames based upon max luminance + float tlum0 = dot( float3(.3, .59, .11), baseTex0.rgb * (1-i.blendfactor0.x)); + float tlum1 = dot( float3(.3, .59, .11), baseTex1.rgb * i.blendfactor0.x); + + if ( tlum0 > tlum1 ) + rgb2 = baseTex0; + else + rgb2 = baseTex1; + } + + if ( nSequenceBlendMode == COMBINE_MODE_AVERAGE ) + { + blended_rgb = 0.5 * ( blended_rgb + rgb2 ); + } + else if ( nSequenceBlendMode == COMBINE_MODE_USE_FIRST_AS_ALPHA_MASK_ON_SECOND ) + { + blended_rgb.rgb = rgb2.rgb; + } + else if ( nSequenceBlendMode == COMBINE_MODE_USE_FIRST_OVER_SECOND ) + { + blended_rgb.rgb = lerp( blended_rgb.rgb, rgb2.rgb, rgb2.a ); + } + } // bDualSequence +#endif + + // Optional color ramp + if ( bColorRamp ) + { + blended_rgb.rgb = tex2D( ColorRampSampler, float2( blended_rgb.r, blended_rgb.g ) ); + } + + // Overbright + blended_rgb.rgb *= fOverbrightFactor; + + //Soft Particles FTW +# if (DEPTHBLEND == 1) +# if defined( _X360 ) + float fDepthBlend = DepthFeathering( DepthSampler, i.vScreenPos_ReverseZ.xy / i.vScreenPos_ReverseZ.w, i.vScreenPos_ReverseZ.z, i.vScreenPos_ReverseZ.w, g_DepthFeatheringConstants ); +# else + float fDepthBlend = DepthFeathering( DepthSampler, i.vScreenPos.xy / i.vScreenPos.w, i.vScreenPos.z, i.vScreenPos.w, g_DepthFeatheringConstants ); +# endif + i.argbcolor.a *= fDepthBlend; +# endif + + // Premultiply the alpha for a ONE:INVALPHA blend +#if ADDBASETEXTURE2 + if ( bAddBaseTexture2 ) + { + blended_rgb.a *= i.argbcolor.a; + + // In this case, we don't really want to pre-multiply by alpha + if ( !bColorRamp ) + { + blended_rgb.rgb *= blended_rgb.a; + } + + if ( bExtractGreenAlpha ) + { + blended_rgb.rgb += fAdditiveBlendWeight * i.argbcolor.a * blended_rgb.rgb; + } + else + { + blended_rgb.rgb += fOverbrightFactor * fAdditiveBlendWeight * i.argbcolor.a * tex2D( BaseTextureSampler, i.texCoord2 ); + } + + blended_rgb.rgb *= i.argbcolor.rgb; + } + else +#endif + { +#if ADDSELF + blended_rgb.a *= i.argbcolor.a; + blended_rgb.rgb *= blended_rgb.a; + blended_rgb.rgb += fOverbrightFactor * fAdditiveSelfBlendWeight * i.argbcolor.a * blended_rgb; + blended_rgb.rgb *= i.argbcolor.rgb; +#else + blended_rgb *= i.argbcolor; +#endif + } + + return FinalOutput( blended_rgb, 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_LINEAR ); +} + diff --git a/materialsystem/stdshaders/spritecard_vsxx.fxc b/materialsystem/stdshaders/spritecard_vsxx.fxc new file mode 100644 index 0000000..6f67010 --- /dev/null +++ b/materialsystem/stdshaders/spritecard_vsxx.fxc @@ -0,0 +1,347 @@ +// STATIC: "ZOOM_ANIMATE_SEQ2" "0..1" [vs20] +// STATIC: "DUALSEQUENCE" "0..1" [vs20] +// STATIC: "EXTRACTGREENALPHA" "0..1" [vs20] + +// STATIC: "ZOOM_ANIMATE_SEQ2" "0..0" [vs11] +// STATIC: "DUALSEQUENCE" "0..0" [vs11] +// STATIC: "EXTRACTGREENALPHA" "0..0" [vs11] + +// STATIC: "USE_INSTANCING" "0..1" [vs20] +// DYNAMIC: "ORIENTATION" "0..2" + + +#include "common_vs_fxc.h" + +const float4x3 cModelView : register(SHADER_SPECIFIC_CONST_0); +const float4x4 cProj : register(SHADER_SPECIFIC_CONST_3); + +#if ZOOM_ANIMATE_SEQ2 +const float4 ScaleParms : register(SHADER_SPECIFIC_CONST_7); +#define OLDFRM_SCALE_START (ScaleParms.x) +#define OLDFRM_SCALE_END (ScaleParms.y) +#endif + +const float4 SizeParms : register(SHADER_SPECIFIC_CONST_8); +const float4 SizeParms2 : register(SHADER_SPECIFIC_CONST_9); +const float4 ViewportTransformScaled : register(SHADER_SPECIFIC_CONST_10); + +#define MINIMUM_SIZE_FACTOR (SizeParms.x) +#define MAXIMUM_SIZE_FACTOR (SizeParms.y) + +#define START_FADE_SIZE_FACTOR (SizeParms.z) +#define END_FADE_SIZE_FACTOR (SizeParms.w) + +// alpha fade w/ distance +#define START_FAR_FADE ( SizeParms2.x ) +#define FAR_FADE_FACTOR ( SizeParms2.y ) // alpha = 1-min(1,max(0, (dist-start_fade)*factor)) + +// Define stuff for instancing on 360 +#if ( defined( _X360 ) && defined( SHADER_MODEL_VS_2_0 ) ) +#define CONST_PC +#define VERTEX_INDEX_PARAM_360 ,int Index:INDEX +#define DO_INSTANCING 1 +#else +#define CONST_PC const +#define VERTEX_INDEX_PARAM_360 +#endif + + +struct VS_INPUT +{ + // This is all of the stuff that we ever use. + float4 vTint : COLOR; + float4 vPos : POSITION; + float4 vTexCoord0 : TEXCOORD0; + float4 vTexCoord1 : TEXCOORD1; + float4 vParms : TEXCOORD2; // frame blend, rot, radius, yaw + // FIXME: remove this vertex element for (USE_INSTANCING == 1), need to shuffle the following elements down + float2 vCornerID : TEXCOORD3; // 0,0 1,0 1,1 0,1 + float4 vTexCoord2 : TEXCOORD4; +#if DUALSEQUENCE + float4 vSeq2TexCoord0 : TEXCOORD5; + float4 vSeq2TexCoord1 : TEXCOORD6; + float4 vParms1 : TEXCOORD7; // second frame blend, ?,?,? +#endif +}; + +struct VS_OUTPUT +{ + float4 projPos : POSITION; + + float2 texCoord0 : TEXCOORD0; + float2 texCoord1 : TEXCOORD1; + float4 argbcolor : COLOR; + float4 blendfactor0 : TEXCOORD2; + float2 texCoord2 : TEXCOORD3; +#if !defined( SHADER_MODEL_VS_1_1 ) + float4 blendfactor1 : TEXCOORD4; // for extracting green/alpha +#endif +#if DUALSEQUENCE + float2 vSeq2TexCoord0 : TEXCOORD5; + float2 vSeq2TexCoord1 : TEXCOORD6; +#endif + +#if defined( _X360 ) + float4 vScreenPos_ReverseZ : TEXCOORD7; +#else + float4 vScreenPos : TEXCOORD7; +#endif +}; + +#define BLENDFACTOR v.vParms.x +#define ROTATION v.vParms.y +#define RADIUS v.vParms.z +#define YAW (v.vParms.w) + +#if ( ZOOM_ANIMATE_SEQ2 ) +float getlerpscaled( float l_in, float s0, float s1, float ts ) +{ + l_in = 2.0*(l_in-.5); + l_in *= lerp(s0,s1,ts); + return 0.5+0.5*l_in; +} + +float getlerpscale_for_old_frame( float l_in, float ts ) +{ + return getlerpscaled( l_in, OLDFRM_SCALE_START, OLDFRM_SCALE_END, ts); +} + +float getlerpscale_for_new_frame( float l_in, float ts ) +{ + return getlerpscaled( l_in, 1.0, OLDFRM_SCALE_START, ts ); +} +#endif // ZOOM_ANIMATE_SEQ2 + +#ifdef DO_INSTANCING +void InstancedVertexRead( inout VS_INPUT v, int index ) +{ + // Duplicate each VB vertex 4 times (and generate vCornerID - the only thing that varies per-corner) + float4 vTint; + float4 vPos; + float4 vTexCoord0; + float4 vTexCoord1; + float4 vParms; + float4 vTexCoord2; + float4 vSeq_TexCoord0; // NOTE: April XDK compiler barfs on var names which have a number in the middle! (i.e. vSeq2TexCoord0) + float4 vSeq_TexCoord1; + float4 vParms1; + + int spriteIndex = index / 4; + int cornerIndex = index - 4*spriteIndex; + asm + { + vfetch vTint, spriteIndex, color0; + vfetch vPos, spriteIndex, position0; + vfetch vTexCoord0, spriteIndex, texcoord0; + vfetch vTexCoord1, spriteIndex, texcoord1; + vfetch vParms, spriteIndex, texcoord2; + vfetch vTexCoord2, spriteIndex, texcoord4; +#if DUALSEQUENCE + vfetch vSeq_TexCoord0, spriteIndex, texcoord5; + vfetch vSeq_TexCoord1, spriteIndex, texcoord6; + vfetch vParms1, spriteIndex, texcoord7; +#endif + }; + + v.vTint = vTint; + v.vPos = vPos; + v.vTexCoord0 = vTexCoord0; + v.vTexCoord1 = vTexCoord1; + v.vParms = vParms; + v.vTexCoord2 = vTexCoord2; +#if DUALSEQUENCE + v.vSeq2TexCoord0 = vSeq_TexCoord0; + v.vSeq2TexCoord1 = vSeq_TexCoord1; + v.vParms1 = vParms1; +#endif + + // Compute vCornerID - order is: (0,0) (1,0) (1,1) (0,1) + // float2 IDs[4] = { {0,0}, {1,0}, {1,1}, {0,1} }; + // v.vCornerID.xy = IDs[ cornerIndex ]; + // This compiles to 2 ops on 360 (MADDs with abs/sat register read/write modifiers): + v.vCornerID.xy = float2( 1.5f, 0.0f ) + cornerIndex*float2( -1.0f, 1.0f ); + v.vCornerID.xy = saturate( float2(1.5f, -3.0f) + float2( -1.0f, 2.0f )*abs( v.vCornerID.xy ) ); +} +#endif + +VS_OUTPUT main( CONST_PC VS_INPUT v + VERTEX_INDEX_PARAM_360 ) +{ + VS_OUTPUT o; + +#ifdef DO_INSTANCING + if ( USE_INSTANCING ) + { + InstancedVertexRead( v, Index ); + } +#endif + +#if SHADER_MODEL_VS_1_1 + float4 tint = v.vTint; +#else + float4 tint = GammaToLinear( v.vTint ); +#endif + + float2 sc_yaw; + sincos( YAW, sc_yaw.y, sc_yaw.x ); + + float2 sc; + sincos( ROTATION, sc.y, sc.x ); + + float2 ix=2*v.vCornerID.xy-1; + float x1=dot(ix,sc); + float y1=sc.x*ix.y-sc.y*ix.x; + + float4 projPos; + float3 worldPos; + worldPos = mul4x3( v.vPos, cModel[0] ); + + float rad = RADIUS; + float3 v2p = ( worldPos - cEyePos ); + float l = length(v2p); + rad=max(rad, MINIMUM_SIZE_FACTOR * l); + // now, perform fade out +#ifndef SHADER_MODEL_VS_1_1 + if ( rad > START_FADE_SIZE_FACTOR * l ) + { + if ( rad > END_FADE_SIZE_FACTOR *l ) + { + tint = 0; + rad = 0; // cull so we emit 0-sized sprite + } + else + { + tint *= 1-(rad-START_FADE_SIZE_FACTOR*l)/(END_FADE_SIZE_FACTOR*l-START_FADE_SIZE_FACTOR*l); + } + } +#endif + + +#ifndef SHADER_MODEL_VS_1_1 + // perform far fade + float tscale = 1-min(1, max(0, (l-START_FAR_FADE)*FAR_FADE_FACTOR) ); + tint *= tscale; + + if ( tscale <= 0) + rad = 0; // cull so we emit 0-sized sprite +#endif + + rad=min(rad, MAXIMUM_SIZE_FACTOR * l); + +#if ORIENTATION == 0 + // Screen-aligned case + float3 viewPos; + viewPos = mul4x3( v.vPos, cModelView ); + + float3 disp=float3( -x1,y1,0); + float tmpx=disp.x*sc_yaw.x+disp.z*sc_yaw.y; + disp.z = disp.z*sc_yaw.x-disp.x*sc_yaw.y; + disp.x=tmpx; + + viewPos.xyz += disp * rad; + + projPos = mul( float4(viewPos, 1.0f), cProj ); +#endif + +#if ORIENTATION == 1 + // Z-aligned case + if (l > rad/2) + { + float3 up = float3(0,0,1); + float3 right = normalize(cross(up, v2p)); + float tmpx=right.x*sc_yaw.x+right.y*sc_yaw.y; + right.y = right.y*sc_yaw.x-right.x*sc_yaw.y; + right.x=tmpx; + + worldPos += (x1*rad)*right; + worldPos.z += (y1*rad)*up.z; + +#ifndef SHADER_MODEL_VS_1_1 + if (l < rad*2 ) + { + tint *= smoothstep(rad/2,rad,l); + } +#endif + + } + projPos = mul( float4(worldPos, 1.0f), cViewProj ); +#endif + +#if ORIENTATION == 2 + // aligned with z plane case - easy + float3 wpos=v.vPos+RADIUS*float3( y1,x1,0); + projPos = mul( float4(wpos, 1.0f), cModelViewProj ); +#endif + + o.blendfactor0 = float4( v.vParms.x, 0, 0, 0 ); + o.projPos = projPos; + o.texCoord0.x = lerp( v.vTexCoord0.z, v.vTexCoord0.x, v.vCornerID.x ); + o.texCoord0.y = lerp( v.vTexCoord0.w, v.vTexCoord0.y, v.vCornerID.y ); + o.texCoord1.x = lerp( v.vTexCoord1.z, v.vTexCoord1.x, v.vCornerID.x ); + o.texCoord1.y = lerp( v.vTexCoord1.w, v.vTexCoord1.y, v.vCornerID.y ); + o.texCoord2.x = lerp( v.vTexCoord2.z, v.vTexCoord2.x, v.vCornerID.x ); + o.texCoord2.y = lerp( v.vTexCoord2.w, v.vTexCoord2.y, v.vCornerID.y ); + +#if ( DUALSEQUENCE ) + float2 lerpold = v.vCornerID.xy; + float2 lerpnew = v.vCornerID.xy; + +#if ( ZOOM_ANIMATE_SEQ2 ) + lerpold.x = getlerpscale_for_old_frame( v.vCornerID.x, v.vParms1.x ); + lerpold.y = getlerpscale_for_old_frame( v.vCornerID.y, v.vParms1.x ); + lerpnew.x = getlerpscale_for_new_frame( v.vCornerID.x, v.vParms1.x ); + lerpnew.y = getlerpscale_for_new_frame( v.vCornerID.y, v.vParms1.x ); +#endif + + o.vSeq2TexCoord0.xy = lerp( v.vSeq2TexCoord0.zw, v.vSeq2TexCoord0.xy, lerpold.xy ); + o.vSeq2TexCoord1.xy = lerp( v.vSeq2TexCoord1.zw, v.vSeq2TexCoord1.xy, lerpnew.xy ); + + o.blendfactor0.z = v.vParms1.x; +#endif + + +#if !defined( SHADER_MODEL_VS_1_1 ) + + o.blendfactor1 = float4( 0.0f, 0.0f, 0.0f, 0.0f ); + +#if ( EXTRACTGREENALPHA ) + // Input range Output range + if ( v.vParms.x < 0.25f ) // 0.0 .. 0.25 + { + o.blendfactor0.a = v.vParms.x * 2 + 0.5f; // 0.5 .. 1.0 + o.blendfactor0.g = 1 - o.blendfactor0.a; // 0.5 .. 0.0 + } + else if ( v.vParms.x < 0.75f ) // 0.25 .. 0.75 + { + o.blendfactor1.g = v.vParms.x * 2 - 0.5f; // 0.0 .. 1.0 + o.blendfactor0.a = 1 - o.blendfactor1.g; // 1.0 .. 0.0 + } + else // 0.75 .. 1.0 + { + o.blendfactor1.a = v.vParms.x * 2 - 1.5f; // 0.0 .. 0.5 + o.blendfactor1.g = 1 - o.blendfactor1.a; // 1.0 .. 0.5 + } +#endif + +#endif + + // Map projected position to the refraction texture + float2 vScreenPos; + vScreenPos.x = projPos.x; + vScreenPos.y = -projPos.y; // invert Y + vScreenPos = (vScreenPos + projPos.w) * 0.5f; + + // Need to also account for the viewport transform, which matters when rendering with mat_viewportscale != 1.0 + vScreenPos = (vScreenPos * ViewportTransformScaled.xy) + (projPos.w * ViewportTransformScaled.zw); + +#if defined( _X360 ) + o.vScreenPos_ReverseZ = float4(vScreenPos.x, vScreenPos.y, projPos.w - projPos.z, projPos.w ); +#else + o.vScreenPos = float4(vScreenPos.x, vScreenPos.y, projPos.z, projPos.w ); +#endif + + o.argbcolor = tint; + return o; +} + + diff --git a/materialsystem/stdshaders/stdshader_dbg.vpc b/materialsystem/stdshaders/stdshader_dbg.vpc new file mode 100644 index 0000000..d07acfd --- /dev/null +++ b/materialsystem/stdshaders/stdshader_dbg.vpc @@ -0,0 +1,102 @@ +//----------------------------------------------------------------------------- +// STDSHADER_DBG.VPC +// +// Project Script +//----------------------------------------------------------------------------- + +$macro SRCDIR "..\.." +$Macro OUTBINDIR "$SRCDIR\..\game\bin" + +// shader_dll_verify.cpp defines a function called _ftol3. This means that we can't +// link with the bug-fixed ftol3.obj. It also means we can't convert float-to-unsigned. +$Macro DISABLE_FTOL3_OVERRIDE "1" + +$include "$SRCDIR\vpc_scripts\source_dll_base.vpc" + +$Configuration "Debug" +{ + $General + { + $OutputDirectory "Debug_dbg" [$WINDOWS] + $IntermediateDirectory "Debug_dbg" [$WINDOWS] + + $OutputDirectory "Debug_dbg_360" [$X360] + $IntermediateDirectory "Debug_dbg_360" [$X360] + } +} + +$Configuration "Release" +{ + $General + { + $OutputDirectory "Release_dbg" [$WINDOWS] + $IntermediateDirectory "Release_dbg" [$WINDOWS] + + $OutputDirectory "Release_dbg_360" [$X360] + $IntermediateDirectory "Release_dbg_360" [$X360] + } +} + +// Common Configuration +$Configuration +{ + $Compiler + { + $AdditionalIncludeDirectories "$BASE;fxctmp9;vshtmp9;..\..\dx9sdk\include" [$WIN32] + $AdditionalIncludeDirectories "$BASE;fxctmp9_360;vshtmp9_360" [$X360] + $PreprocessorDefinitions "$BASE;STDSHADER_DBG_DLL_EXPORT;FAST_MATERIALVAR_ACCESS" + } + + $Linker + { + $AdditionalDependencies "$BASE version.lib winmm.lib" [$WIN32] + $ModuleDefinitionFile "xbox\xbox_dbg.def" [$X360] + } +} + +$Project "stdshader_dbg" +{ + $Folder "Source Files" + { + $File "BaseVSShader.cpp" + $File "debugdepth.cpp" + $File "DebugDrawEnvmapMask.cpp" + $File "debugluxel.cpp" + $File "debugnormalmap.cpp" + $File "debugtangentspace.cpp" + $File "fillrate.cpp" + + $Folder "Remove me when VAC2 is out" [$WIN32] + { + $File "..\shader_dll_verify.cpp" + $File "..\shader_dll_verify.h" + } + } + + $Folder "Xbox" [$X360] + { + -$File "xbox\xbox.def" + $File "xbox\xbox_dbg.def" + } + + $Folder "Header Files" + { + $File "BaseVSShader.h" + } + + $Folder "Link Libraries" + { + $File "$SRCDIR\dx9sdk\lib\d3dx9.lib" [$WIN32] + $Lib mathlib + $Lib shaderlib + } + + $File "$SRCDIR\devtools\bin\vsh_prep.pl" + $File "$SRCDIR\devtools\bin\psh_prep.pl" + $File "$SRCDIR\devtools\bin\fxc_prep.pl" + $File "$SRCDIR\devtools\bin\updateshaders.pl" + + $Shaders "stdshader_dx9_20b.txt" + $Shaders "stdshader_dx9_30.txt" + //$Shaders "stdshader_dx10.txt" +} diff --git a/materialsystem/stdshaders/stdshader_dx10.txt b/materialsystem/stdshaders/stdshader_dx10.txt new file mode 100644 index 0000000..b64a2ec --- /dev/null +++ b/materialsystem/stdshaders/stdshader_dx10.txt @@ -0,0 +1 @@ +// vs 4.0 ps 4.0 shaders collection diff --git a/materialsystem/stdshaders/stdshader_dx6.vpc b/materialsystem/stdshaders/stdshader_dx6.vpc new file mode 100644 index 0000000..0740e07 --- /dev/null +++ b/materialsystem/stdshaders/stdshader_dx6.vpc @@ -0,0 +1,105 @@ +//----------------------------------------------------------------------------- +// STDSHADER_DX6.VPC +// +// Project Script +//----------------------------------------------------------------------------- + +$Macro SRCDIR "..\.." +$Macro OUTBINDIR "$SRCDIR\..\game\bin" + +// shader_dll_verify.cpp defines a function called _ftol3. This means that we can't +// link with the bug-fixed ftol3.obj. It also means we can't convert float-to-unsigned. +$Macro DISABLE_FTOL3_OVERRIDE "1" + +$Include "$SRCDIR\vpc_scripts\source_dll_base.vpc" + +$Configuration "Debug" +{ + $General + { + $OutputDirectory "Debug_dx6" + $IntermediateDirectory "Debug_dx6" + } +} + +$Configuration "Release" +{ + $General + { + $OutputDirectory "Release_dx6" + $IntermediateDirectory "Release_dx6" + } +} + +// Common Configuration +$Configuration +{ + $Compiler + { + $PreprocessorDefinitions "$BASE;STDSHADER_DX6_DLL_EXPORT;FAST_MATERIALVAR_ACCESS" + $AdditionalIncludeDirectories "$BASE;..\..\dx9sdk\include" + } + + $Linker + { + $AdditionalDependencies "$BASE odbc32.lib odbccp32.lib" + } +} + +$Project "Stdshader_dx6" +{ + $Folder "Source Files" + { + $File "BufferClearObeyStencil_dx6.cpp" + $File "cable_dx6.cpp" + $File "cloud.cpp" + $File "decal.cpp" + $File "DecalBaseTimesLightmapAlphaBlendSelfIllum_dx6.cpp" + $File "decalmodulate.cpp" + $File "eyeball.cpp" + $File "eyes_dx6.cpp" + $File "introscreenspaceeffect_dx60.cpp" + $File "lightmappedgeneric_dx6.cpp" + $File "lightmappedtwotexture.cpp" + $File "modulate_dx6.cpp" + $File "portal_dx60.cpp" + $File "portalstaticoverlay_dx60.cpp" + $File "refract_dx60.cpp" + $File "rift_dx6.cpp" + $File "SetZ.cpp" + $File "shadow_dx6.cpp" + $File "shadowbuild_dx6.cpp" + $File "sky_dx6.cpp" + $File "sprite_dx6.cpp" + $File "teeth_dx6.cpp" + $File "unlitgeneric_dx6.cpp" + $File "unlittwotexture_dx6.cpp" + $File "vertexlitgeneric_dx6.cpp" + $File "viewalpha.cpp" + $File "volumetricfog.cpp" + $File "water_dx60.cpp" + $File "worldtwotextureblend_dx6.cpp" + $File "worldvertextransition_dx6.cpp" + $File "worldvertextransition_dx6_helper.cpp" + $File "writez_dx6.cpp" + + $Folder "remove me when VAC2 is out" + { + $File "$SRCDIR\tier1\checksum_crc.cpp" + $File "$SRCDIR\tier1\checksum_md5.cpp" + $File "..\shader_dll_verify.cpp" + $File "..\shader_dll_verify.h" + } + } + + $Folder "Header Files" + { + $File "worldvertextransition_dx6_helper.h" + } + + $Folder "Link Libraries" + { + $Lib mathlib + $Lib shaderlib + } +} diff --git a/materialsystem/stdshaders/stdshader_dx7.vpc b/materialsystem/stdshaders/stdshader_dx7.vpc new file mode 100644 index 0000000..30bb028 --- /dev/null +++ b/materialsystem/stdshaders/stdshader_dx7.vpc @@ -0,0 +1,74 @@ +//----------------------------------------------------------------------------- +// STDSHADER_DX7.VPC +// +// Project Script +//----------------------------------------------------------------------------- + +$Macro SRCDIR "..\.." +$Macro OUTBINDIR "$SRCDIR\..\game\bin" + +// shader_dll_verify.cpp defines a function called _ftol3. This means that we can't +// link with the bug-fixed ftol3.obj. It also means we can't convert float-to-unsigned. +$Macro DISABLE_FTOL3_OVERRIDE "1" + +$Include "$SRCDIR\vpc_scripts\source_dll_base.vpc" + +$Configuration "Debug" +{ + $General + { + $OutputDirectory "Debug_dx7" + $IntermediateDirectory "Debug_dx7" + } +} + +$Configuration "Release" +{ + $General + { + $OutputDirectory "Release_dx7" + $IntermediateDirectory "Release_dx7" + } +} + +// Common Configuration +$Configuration +{ + $Compiler + { + $PreprocessorDefinitions "$BASE;STDSHADER_DX7_DLL_EXPORT;FAST_MATERIALVAR_ACCESS" + $AdditionalIncludeDirectories "$BASE;..\..\dx9sdk\include" + } + + $Linker + { + $AdditionalDependencies "$BASE odbc32.lib odbccp32.lib" + } +} + +$Project "Stdshader_dx7" +{ + $Folder "Source Files" + { + $File "core_dx7.cpp" + $File "filmdust_dx7.cpp" + $File "filmgrain_dx7.cpp" + $File "shatteredglass_dx7.cpp" + $File "vertexlitgeneric_dx7.cpp" + $File "vortwarp_dx7.cpp" + + $Folder "remove me when VAC2 is out" + { + $File "$SRCDIR\tier1\checksum_crc.cpp" + $File "$SRCDIR\tier1\checksum_md5.cpp" + $File "..\shader_dll_verify.cpp" + $File "..\shader_dll_verify.h" + } + } + + $Folder "Link Libraries" + { + $Lib mathlib + $Lib shaderlib + } +} diff --git a/materialsystem/stdshaders/stdshader_dx8.vpc b/materialsystem/stdshaders/stdshader_dx8.vpc new file mode 100644 index 0000000..2eabff7 --- /dev/null +++ b/materialsystem/stdshaders/stdshader_dx8.vpc @@ -0,0 +1,141 @@ +//----------------------------------------------------------------------------- +// STDSHADER_DX8.VPC +// +// Project Script +//----------------------------------------------------------------------------- + +$Macro SRCDIR "..\.." +$Macro OUTBINDIR "$SRCDIR\..\game\bin" + +// shader_dll_verify.cpp defines a function called _ftol3. This means that we can't +// link with the bug-fixed ftol3.obj. It also means we can't convert float-to-unsigned. +$Macro DISABLE_FTOL3_OVERRIDE "1" + +$Include "$SRCDIR\vpc_scripts\source_dll_base.vpc" + +$Configuration "Debug" +{ + $General + { + $OutputDirectory "Debug_dx8" + $IntermediateDirectory "Debug_dx8" + } +} + +$Configuration "Release" +{ + $General + { + $OutputDirectory "Release_dx8" + $IntermediateDirectory "Release_dx8" + } +} + +// Common Configuration +$Configuration +{ + $Compiler + { + $AdditionalIncludeDirectories "$BASE;fxctmp9;vshtmp9;..\..\dx9sdk\include" + $PreprocessorDefinitions "$BASE;STDSHADER_DX8_DLL_EXPORT;FAST_MATERIALVAR_ACCESS" + } + + $Linker + { + $AdditionalDependencies "$BASE version.lib winmm.lib" + } +} + + +$Project "stdshader_dx8" +{ + $Folder "Source Files" + { + $File "BaseVSShader.cpp" + $File "BlurFilterX_dx80.cpp" + $File "Bik_dx80.cpp" + $File "Bik_dx81.cpp" + $File "BlurFilterY_dx80.cpp" + $File "BufferClearObeyStencil_dx8.cpp" + $File "cable_dx8.cpp" + $File "cloak_blended_pass_dx8_helper.cpp" + $File "cloud_dx8.cpp" + $File "core_dx8.cpp" + $File "DecalBaseTimesLightmapAlphaBlendSelfIllum_dx8.cpp" + $File "detail.cpp" + $File "downsample_nohdr_dx80.cpp" + $File "dx8fallbacks.cpp" + $File "eyes.cpp" + $File "emissive_scroll_blended_pass_dx8_helper.cpp" + $File "flesh_interior_blended_pass_dx8_helper.cpp" + $File "eyes_dx8_dx9_helper.cpp" + $File "filmdust_dx8_dx9.cpp" + $File "filmgrain_dx8_dx9.cpp" + $File "gooinglass.cpp" + $File "introscreenspaceeffect_dx80.cpp" + $File "lightmappedgeneric_decal.cpp" + $File "lightmappedgeneric_dx8.cpp" + $File "modulate_dx8.cpp" + $File "MonitorScreen_dx8.cpp" + $File "occlusion_dx8.cpp" + $File "overlay_fit.cpp" + $File "particlesphere_dx8.cpp" + $File "portal_dx80.cpp" + $File "portal_refract_dx8.cpp" + $File "portal_refract_dx8_helper.cpp" + $File "portalstaticoverlay_dx80.cpp" + $File "predator.cpp" + $File "refract_dx80.cpp" + $File "screenspace_general_dx8.cpp" + $File "shadow_dx8.cpp" + $File "shadowbuild_dx8.cpp" + $File "shadowmodel_dx8.cpp" + $File "shatteredglass_dx8.cpp" + $File "sprite.cpp" + $File "spritecard.cpp" + $File "teeth_dx8.cpp" + $File "unlitgeneric_dx8.cpp" + $File "unlittwotexture_dx8.cpp" + $File "vertexlitgeneric_dx8.cpp" + $File "vortwarp_dx8.cpp" + $File "water_dx80.cpp" + $File "water_dx81.cpp" + $File "windowimposter_dx80.cpp" + $File "wireframe_dx8.cpp" + $File "worldtwotextureblend_dx8.cpp" + $File "worldvertexalpha_dx8.cpp" + $File "WorldVertexTransition_dx8.cpp" + $File "worldvertextransition_dx8_helper.cpp" + $File "writez_dx8.cpp" + $File "writestencil_dx8.cpp" + $File "yuv.cpp" + + $Folder "Remove me when VAC2 is out" + { + $File "..\shader_dll_verify.cpp" + $File "..\shader_dll_verify.h" + } + } + + $Folder "Header Files" + { + $File "eyes_dx8_dx9_helper.h" + $File "worldvertextransition_dx8_helper.h" + $File "BaseVSShader.h" + } + + $Folder "Link Libraries" + { + $File "$SRCDIR\dx9sdk\lib\d3dx9.lib" + $Lib mathlib + $Lib shaderlib + } + + $File "$SRCDIR\devtools\bin\fxc_prep.pl" + $File "$SRCDIR\devtools\bin\vsh_prep.pl" + $File "$SRCDIR\devtools\bin\psh_prep.pl" + + $Shaders "stdshader_dx9_20b.txt" + $Shaders "stdshader_dx9_30.txt" + //$Shaders "stdshader_dx10.txt" +} diff --git a/materialsystem/stdshaders/stdshader_dx9.vpc b/materialsystem/stdshaders/stdshader_dx9.vpc new file mode 100644 index 0000000..46428bd --- /dev/null +++ b/materialsystem/stdshaders/stdshader_dx9.vpc @@ -0,0 +1,247 @@ +//----------------------------------------------------------------------------- +// STDSHADER_DX9.VPC +// +// Project Script +//----------------------------------------------------------------------------- + +$Macro SRCDIR "..\.." +$Macro OUTBINDIR "$SRCDIR\..\game\bin" + +// shader_dll_verify.cpp defines a function called _ftol3. This means that we can't +// link with the bug-fixed ftol3.obj. It also means we can't convert float-to-unsigned. +$Macro DISABLE_FTOL3_OVERRIDE "1" + +$Include "$SRCDIR\vpc_scripts\source_dll_base.vpc" + +$Configuration "Debug" +{ + $General + { + $OutputDirectory "Debug_dx9" [$WINDOWS] + $IntermediateDirectory "Debug_dx9" [$WINDOWS] + + $OutputDirectory "Debug_dx9_360" [$X360] + $IntermediateDirectory "Debug_dx9_360" [$X360] + } +} + +$Configuration "Release" +{ + $General + { + $OutputDirectory "Release_dx9" [$WINDOWS] + $IntermediateDirectory "Release_dx9" [$WINDOWS] + + $OutputDirectory "Release_dx9_360" [$X360] + $IntermediateDirectory "Release_dx9_360" [$X360] + } +} + +// Common Configuration +$Configuration +{ + $Compiler + { + $AdditionalIncludeDirectories "$BASE;fxctmp9;vshtmp9;" [$WIN32||$POSIX] + $AdditionalIncludeDirectories "$BASE;..\..\dx9sdk\include" [$WIN32] + $AdditionalIncludeDirectories "$BASE;fxctmp9_360;vshtmp9_360" [$X360] + $PreprocessorDefinitions "$BASE;STDSHADER_DX9_DLL_EXPORT;FAST_MATERIALVAR_ACCESS" + $PreprocessorDefinitions "$BASE;USE_ACTUAL_DX" [($WIN32||$X360) && !$GL] + } + + $Linker + { + $AdditionalDependencies "$BASE version.lib winmm.lib" [$WIN32] + $ModuleDefinitionFile "xbox\xbox_dx9.def" [$X360] + $SystemLibraries "iconv" [$OSXALL] + } +} + +$Project "stdshader_dx9" +{ + $Folder "Source Files" + { + $File "aftershock.cpp" + $File "aftershock_helper.cpp" + $File "AccumBuff4Sample.cpp" + $File "accumbuff5sample.cpp" + $File "BaseVSShader.cpp" + $File "bik_dx90.cpp" + $File "Bloom.cpp" + $File "BlurFilterX.cpp" + $File "BlurFilterY.cpp" + $File "BufferClearObeyStencil_dx9.cpp" + $File "cable_dx9.cpp" + $File "cloak.cpp" + $File "cloak_blended_pass_helper.cpp" + $File "cloak_dx9_helper.cpp" + $File "cloud_dx9.cpp" + $File "colorcorrection.cpp" + $File "compositor.cpp" + $File "core_dx9.cpp" + $File "color_projection.cpp" + $File "debugmrttexture.cpp" + $File "debugmorphaccumulator_dx9.cpp" [$WIN32] + $File "DebugTextureView.cpp" + $File "DecalBaseTimesLightmapAlphaBlendSelfIllum_dx9.cpp" + $File "DecalModulate_dx9.cpp" + $File "depthwrite.cpp" + $File "Downsample.cpp" + $File "downsample_nohdr.cpp" + $File "Engine_Post_dx9.cpp" + $File "emissive_scroll_blended_pass_helper.cpp" + $File "eye_refract.cpp" + $File "eye_refract_helper.cpp" + $File "eyes_dx8_dx9_helper.cpp" + $File "eyes_dx9.cpp" + $File "eyeglint_dx9.cpp" + $File "filmdust_dx8_dx9.cpp" + $File "filmgrain_dx8_dx9.cpp" + $File "flesh_interior_blended_pass_helper.cpp" + $File "floatcombine.cpp" + $File "floatcombine_autoexpose.cpp" + $File "floattoscreen.cpp" + $File "floattoscreen_vanilla.cpp" + $File "HDRCombineTo16Bit.cpp" + $File "HDRSelectRange.cpp" + $File "hsl_filmgrain_pass1.cpp" + $File "hsl_filmgrain_pass2.cpp" + $File "hsv.cpp" + $File "introscreenspaceeffect.cpp" + $File "lightmappedgeneric_dx9.cpp" + $File "lightmappedgeneric_dx9_helper.cpp" + $File "lightmappedreflective.cpp" + $File "modulate_dx9.cpp" + $File "MonitorScreen_dx9.cpp" + $File "morphaccumulate_dx9.cpp" [$WIN32] + $File "morphweight_dx9.cpp" [$WIN32] + $File "motion_blur_dx9.cpp" + $File "occlusion_dx9.cpp" + $File "particlelitgeneric_dx9.cpp" + $File "particlelitgeneric_dx9_helper.cpp" + $File "particlesphere_dx9.cpp" + $File "portal.cpp" + $File "portalstaticoverlay.cpp" + $File "portal_refract.cpp" + $File "portal_refract_helper.cpp" + $File "pyro_vision.cpp" + $File "refract.cpp" + $File "refract_dx9_helper.cpp" + $File "rendertargetblit_x360.cpp" [$X360] + $File "sample4x4.cpp" + $File "sample4x4_blend.cpp" + $File "screenspace_general.cpp" + $File "sfm_blurfilterx.cpp" + $File "sfm_blurfiltery.cpp" + $File "sfm_downsample.cpp" + $File "sfm_integercombine.cpp" + $File "shadow.cpp" + $File "shadowbuild_dx9.cpp" + $File "shadowmodel_dx9.cpp" + $File "shatteredglass.cpp" + $File "showz.cpp" + $File "skin_dx9_helper.cpp" + $File "sky_dx9.cpp" + $File "sky_hdr_dx9.cpp" + $File "sprite_dx9.cpp" + $File "spritecard.cpp" + $File "teeth.cpp" + $File "TreeLeaf.cpp" + $File "unlitgeneric_dx9.cpp" + $File "unlittwotexture_dx9.cpp" + $File "vertexlitgeneric_dx9.cpp" + $File "vertexlitgeneric_dx9_helper.cpp" + $File "volume_clouds.cpp" + $File "volume_clouds_helper.cpp" + $File "vortwarp_dx9.cpp" + $File "vr_distort_hud.cpp" + $File "vr_distort_texture.cpp" + $File "warp.cpp" + $File "water.cpp" + $File "weapon_sheen_pass_helper.cpp" + $File "windowimposter_dx90.cpp" + $File "wireframe_dx9.cpp" + $File "worldtwotextureblend.cpp" + $File "worldvertexalpha.cpp" + $File "worldvertextransition.cpp" + $File "worldvertextransition_dx8_helper.cpp" + $File "writez_dx9.cpp" + $File "writestencil_dx9.cpp" + + $Folder "Remove me when VAC2 is out" [$WIN32] + { + $File "$SRCDIR\tier1\checksum_crc.cpp" + $File "$SRCDIR\tier1\checksum_md5.cpp" + $File "..\shader_dll_verify.cpp" + $File "..\shader_dll_verify.h" + } + + // 360 collapes stdshader_dbg.dll into stdshader_dx9.dll + $Folder "stdshader_dbg Files" [$X360] + { + $File "debugdepth.cpp" + $File "DebugDrawEnvmapMask.cpp" + $File "debugluxel.cpp" + $File "debugnormalmap.cpp" + $File "debugtangentspace.cpp" + $File "fillrate.cpp" + + // dead shader, but hl2 models have it + $File "eyeball.cpp" + } + } + + $Folder "Xbox" [$X360] + { + -$File "xbox\xbox.def" + $File "xbox\xbox_dx9.def" + } + + $Folder "Header Files" + { + $File "BaseVSShader.h" + $File "cloak_dx9_helper.h" + $File "common_fxc.h" + $File "common_hlsl_cpp_consts.h" + $File "common_ps_fxc.h" + $File "common_vertexlitgeneric_dx9.h" + $File "common_vs_fxc.h" + $File "lightmappedgeneric_dx9_helper.h" + $File "lightmappedgeneric_ps2_3_x.h" + $File "refract_dx9_helper.h" + $File "shader_constant_register_map.h" + $File "skin_dx9_helper.h" + $File "particlelitgeneric_dx9_helper.h" + $File "vertexlitgeneric_dx95_helper.h" + $File "vortwarp_vs20_helper.h" + $File "worldvertextransition_dx8_helper.h" + $File "water_ps2x_helper.h" + } + + $Folder "Link Libraries" [$WIN32] + { + $File "$SRCDIR\dx9sdk\lib\d3dx9.lib" + } + + $Folder "Link Libraries" + { + $Lib mathlib + $Lib shaderlib + } + + $File "$SRCDIR\devtools\bin\vsh_prep.pl" + $File "$SRCDIR\devtools\bin\psh_prep.pl" + $File "$SRCDIR\devtools\bin\fxc_prep.pl" + $File "$SRCDIR\devtools\bin\updateshaders.pl" + $File "$SRCDIR\devtools\bin\copyshaders.pl" + $File "$SRCDIR\devtools\bin\p4autocheckout.pl" + $File "$SRCDIR\devtools\bin\p4revertshadertargets.pl" + $File "$SRCDIR\devtools\bin\valve_perl_helpers.pl" + $File "$SRCDIR\devtools\bin\checkshaderchecksums.pl" + $File "buildallshaders.bat" + $File "buildshaders.bat" + + $Shaders "stdshader_dx9_20b.txt" + $Shaders "stdshader_dx9_30.txt" + //$Shaders "stdshader_dx10.txt" +} diff --git a/materialsystem/stdshaders/stdshader_dx9_20b.txt b/materialsystem/stdshaders/stdshader_dx9_20b.txt new file mode 100644 index 0000000..647a393 --- /dev/null +++ b/materialsystem/stdshaders/stdshader_dx9_20b.txt @@ -0,0 +1,529 @@ +// +// Standard shaders collection +// +// These shaders are compiled as the following shader models: +// _ps11.vcs +// _ps14.vcs +// _ps20.vcs +// _ps20b.vcs +// _vs11.vcs +// _vs20.vcs +// +// These shaders use the old DirectX compiler. +// + +AccumBuff4Sample_ps2x.fxc +accumbuff5sample_ps2x.fxc + +aftershock_ps2x.fxc +aftershock_vs20.fxc + +appchooser360movie_ps2x.fxc + +bik_ps11.psh +bik_ps14.psh +bik_ps2x.fxc +bik_vs11.vsh +bik_vs20.fxc + +Bloom_ps2x.fxc + +bloomadd_ps11.fxc +bloomadd_ps2x.fxc + +BlurFilter_ps11.psh +BlurFilter_ps2x.fxc +BlurFilter_vs11.fxc +BlurFilter_vs20.fxc + +BufferClearObeyStencil_ps11.psh +bufferclearobeystencil_ps2x.fxc +BufferClearObeyStencil_vs11.vsh +bufferclearobeystencil_vs20.fxc + +BumpmappedEnvmap.psh +BumpmappedEnvmap.vsh + +BumpmappedLightmap.vsh +BumpmappedLightmap_OverBright2.psh +bumpmappedlightmap_vs11.fxc + +Cable.psh +Cable.vsh +cable_ps2x.fxc +cable_vs20.fxc + +cloak_blended_pass_ps2x.fxc +cloak_blended_pass_vs20.fxc +cloak_blended_pass_dx8_ps11.psh +cloak_blended_pass_dx8_vs11.vsh + +cloak_ps2x.fxc +cloak_vs20.fxc + +cloud_ps11.psh +cloud_vs11.vsh +cloud_ps20.fxc +cloud_vs20.fxc + +colorcorrection_ps2x.fxc + +compositor_ps2x.fxc +compositor_vs20.fxc + +constant_color_ps2x.fxc + +copy_fp_rt_ps2x.fxc + +color_projection_ps2x.fxc +color_projection_vs20.fxc + +core_ps11.psh +core_ps2x.fxc +core_vs11.fxc +core_vs20.fxc + +DebugDrawDepth_ps2x.fxc +DebugDrawDepth_vs20.fxc + +DebugDrawEnvmapMask_ps2x.fxc +DebugDrawEnvmapMask_vs20.fxc + +debugluxel_ps2x.fxc +debugluxel_vs20.fxc + +debugmrttexture_ps2x.fxc +debugmrttexture_vs20.fxc + +debugtangentspace.vsh +debugtangentspace_vs11.fxc +debugtangentspace_vs20.fxc + +DecalBaseTimesLightmapAlphaBlendSelfIllum1_ps11.psh +DecalBaseTimesLightmapAlphaBlendSelfIllum2_ps11.psh +decalbasetimeslightmapalphablendselfillum2_ps2x.fxc + +decalmodulate_ps2x.fxc + +depthwrite_ps2x.fxc +depthwrite_vs20.fxc + +depthtodestalpha_vs20.fxc +depthtodestalpha_ps20b.fxc + +Downsample_nohdr_ps11.psh +Downsample_nohdr_ps2x.fxc +Downsample_ps2x.fxc +Downsample_vs11.fxc +Downsample_vs20.fxc + +emissive_scroll_blended_pass_dx8_ps11.psh +emissive_scroll_blended_pass_dx8_vs11.vsh +emissive_scroll_blended_pass_ps2x.fxc +emissive_scroll_blended_pass_vs20.fxc + +Engine_Post_ps2x.fxc + +example_model_ps20b.fxc +example_model_vs20.fxc + +eye_refract_ps2x.fxc +eye_refract_vs20.fxc + +Eyes.psh +eyes.vsh +eyes_ps2x.fxc +Eyes_vs20.fxc + +eyes_flashlight_ps11.fxc +eyes_flashlight_vs11.vsh +eyes_flashlight_ps2x.fxc +eyes_flashlight_vs20.fxc + +eyeglint_vs20.fxc +eyeglint_ps2x.fxc + +Eyes_Overbright2.psh + +fillrate.psh +fillrate.vsh +fillrate_ps11.fxc +fillrate_vs11.fxc +fillrate_ps2x.fxc +fillrate_vs20.fxc + +filmdust_ps11.fxc +filmdust_ps20.fxc + +filmgrain_ps11.fxc +filmgrain_ps20.fxc +filmgrain_vs20.fxc + +flashlight_ps11.fxc +flashlight_ps2x.fxc + +flesh_interior_blended_pass_dx8_ps11.psh +flesh_interior_blended_pass_dx8_vs11.vsh +flesh_interior_blended_pass_ps2x.fxc +flesh_interior_blended_pass_vs20.fxc + +floatcombine_autoexpose_ps2x.fxc +floatcombine_ps2x.fxc + +floattoscreen_notonemap_ps2x.fxc +floattoscreen_ps2x.fxc +floattoscreen_vanilla_ps2x.fxc + +haloadd_ps2x.fxc +haloadd1d_ps2x.fxc +haloaddoutline_ps2x.fxc + +HDRCombineTo16Bit_ps2x.fxc +HDRCombineTo16Bit_vs20.fxc + +HDRSelectRange_ps2x.fxc +HDRSelectRange_vs20.fxc + +hsl_filmgrain_pass1_ps2x.fxc +hsl_filmgrain_pass2_ps2x.fxc + +hsv_ps2x.fxc + +IntroScreenSpaceEffect_ps11.fxc +IntroScreenSpaceEffect_ps2x.fxc + +JellyFish.psh +JellyFish.vsh + +LightingOnly.vsh + +LightmappedGeneric.psh +LightmappedGeneric_AddBaseAlphaMaskedEnvMap.psh +LightmappedGeneric_AddEnvMapMaskNoTexture.psh +LightmappedGeneric_AddEnvMapNoTexture.psh +LightmappedGeneric_BaseAlphaMaskedEnvMapV2.psh +LightmappedGeneric_BaseTexture.psh +LightmappedGeneric_BaseTexture.vsh +lightmappedgeneric_basetextureblend.psh +LightmappedGeneric_BaseTextureBlend.vsh +LightmappedGeneric_BumpmappedEnvmap.psh +LightmappedGeneric_BumpmappedEnvmap.vsh +LightmappedGeneric_BumpmappedEnvmap_ps14.psh +LightmappedGeneric_BumpmappedEnvmap_ps14.vsh +LightmappedGeneric_BumpmappedLightmap.psh +LightmappedGeneric_SSBumpmappedLightmap.psh +LightmappedGeneric_BumpmappedLightmap.vsh +LightmappedGeneric_BumpmappedLightmap_base_ps14.psh +LightmappedGeneric_BumpmappedLightmap_base_ps14.vsh +LightmappedGeneric_BumpmappedLightmap_blend_ps14.psh +LightmappedGeneric_BumpmappedLightmap_blend_ps14.vsh +LightmappedGeneric_Decal.psh +LightmappedGeneric_Decal.vsh +lightmappedgeneric_decal_ps2x.fxc +lightmappedgeneric_decal_vs20.fxc +LightmappedGeneric_Detail.psh +LightmappedGeneric_DetailNoTexture.psh +LightmappedGeneric_DetailSelfIlluminated.psh +LightmappedGeneric_EnvMapNoTexture.psh +LightmappedGeneric_EnvMapV2.psh +lightmappedgeneric_flashlight_vs11.fxc +lightmappedgeneric_flashlight_vs20.fxc +LightmappedGeneric_LightingOnly.vsh +LightmappedGeneric_LightingOnly_Overbright2.psh +lightmappedgeneric_lightingonly_overbright2_ps11.fxc +lightmappedgeneric_lightingonly_vs11.fxc +LightmappedGeneric_MaskedEnvMapNoTexture.psh +LightmappedGeneric_MaskedEnvMapV2.psh +LightmappedGeneric_MultiplyByLighting.psh +LightmappedGeneric_MultiplyByLightingNoTexture.psh +LightmappedGeneric_MultiplyByLightingSelfIllum.psh +LightmappedGeneric_NoTexture.psh +lightmappedgeneric_ps2x.fxc +LightmappedGeneric_SelfIlluminated.psh +LightmappedGeneric_SelfIlluminatedEnvMapV2.psh +LightmappedGeneric_SelfIlluminatedMaskedEnvMapV2.psh +lightmappedgeneric_vs11.vsh +lightmappedgeneric_vs20.fxc + +lightmappedreflective_ps2x.fxc +lightmappedreflective_vs20.fxc + +LightmappedTranslucentTexture.psh + +lpreview_output_ps2x.fxc +lpreview1_ps2x.fxc + +luminance_compare_ps2x.fxc + +Modulate_ps11.psh +modulate_ps2x.fxc + +MonitorScreen.psh +monitorscreen_ps2x.fxc + +motion_blur_vs20.fxc +motion_blur_ps2x.fxc + +overlay_fit_ps11.psh +overlay_fit_vs11.vsh + +particlesphere_ps11.fxc +particlesphere_vs11.fxc +particlesphere_ps2x.fxc +particlesphere_vs20.fxc + +portal_ps11.fxc +portal_vs11.fxc +portal_ps2x.fxc +portal_vs20.fxc + +portalstaticoverlay_ps11.fxc +portalstaticoverlay_vs11.fxc +portalstaticoverlay_ps2x.fxc +portalstaticoverlay_vs20.fxc + +portal_refract_vs11.fxc +portal_refract_ps11.fxc +portal_refract_vs20.fxc +portal_refract_ps2x.fxc + +predator.psh +predator.vsh + +pyro_vision_ps2x.fxc +pyro_vision_vs20.fxc + +Refract_model_vs11.vsh +Refract_ps11.psh +refract_ps2x.fxc +Refract_vs20.fxc +Refract_world_vs11.vsh + +rendertargetblit_ps2x.fxc +rendertargetblit_vs20.fxc + +sample4x4_blend_ps2x.fxc +sample4x4_ps2x.fxc +sample4x4delog_ps2x.fxc +sample4x4log_ps2x.fxc +sample4x4maxmin_ps2x.fxc + +ScreenSpaceEffect.vsh +screenspaceeffect_vs11.fxc +screenspaceeffect_vs20.fxc + +sfm_combine_vs20.fxc +sfm_integercombine_ps2x.fxc + +Shadow.psh +shadow_ps14.psh +shadow_vs14.vsh +shadow_ps2x.fxc +shadow_vs20.fxc + +ShadowBuildTexture.psh +shadowbuildtexture_ps2x.fxc + +ShadowModel.psh +ShadowModel.vsh + +shadowmodel_ps20.fxc +shadowmodel_vs20.fxc + +ShatteredGlass.psh +ShatteredGlass.vsh +ShatteredGlass_EnvMap.psh +ShatteredGlass_EnvMap.vsh +ShatteredGlass_EnvMapSphere.vsh +ShatteredGlass_ps2x.fxc +ShatteredGlass_vs20.fxc + +DebugTextureView_vs20.fxc +DebugTextureView_ps2x.fxc + +showz_ps2x.fxc +showz_vs20.fxc + +skin_ps20b.fxc +skin_vs20.fxc + +sky_ps2x.fxc +sky_vs20.fxc +sky_hdr_compressed_ps2x.fxc +sky_hdr_compressed_rgbs_ps2x.fxc + +splinecard_vsxx.fxc + +sprite_ps11.psh +sprite_vs11.vsh +sprite_ps2x.fxc +sprite_vs20.fxc +spritecard_ps2x.fxc +spritecard_vsxx.fxc +spritecard_ps11.fxc +SpriteRenderNormal.psh +SpriteRenderTransAdd.psh +SpriteRenderTransColor.psh + +Teeth.vsh +teeth_ps2x.fxc +teeth_vs20.fxc +teeth_bump_ps2x.fxc +teeth_bump_vs20.fxc +teeth_flashlight_ps2x.fxc +teeth_flashlight_vs20.fxc + +TreeLeaf_ps2x.fxc +TreeLeaf_vs20.fxc + +UnlitGeneric.psh +unlitgeneric_basetimesdetail.psh +UnlitGeneric_BaseAlphaMaskedEnvMap.psh +UnlitGeneric_Detail.psh +UnlitGeneric_DetailBaseAlphaMaskedEnvMap.psh +UnlitGeneric_DetailEnvMap.psh +UnlitGeneric_DetailEnvMapMask.psh +UnlitGeneric_DetailEnvMapMaskNoTexture.psh +UnlitGeneric_DetailEnvMapNoTexture.psh +UnlitGeneric_DetailNoTexture.psh +UnlitGeneric_EnvMap.psh +UnlitGeneric_EnvMapMask.psh +UnlitGeneric_EnvMapMaskNoTexture.psh +UnlitGeneric_EnvMapNoTexture.psh +UnlitGeneric_LightingOnly.vsh +UnlitGeneric_NoTexture.psh +unlitgeneric_notexture_ps11.fxc +unlitgeneric_notexture_ps2x.fxc +unlitgeneric_ps2x.fxc +alphadist_ps11.fxc +UnlitGeneric_MaskBaseByDetailAlpha_ps11.fxc +unlitgeneric_vs11.vsh +unlitgeneric_vs20.fxc + +UnlitTwoTexture.vsh +UnlitTwoTexture.psh +unlittwotexture_ps2x.fxc +unlittwotexture_vs20.fxc + +vertexlit_and_unlit_generic_bump_ps2x.fxc +vertexlit_and_unlit_generic_bump_vs20.fxc + +vertexlit_and_unlit_generic_ps2x.fxc +vertexlit_and_unlit_generic_vs20.fxc + +VertexLitGeneric.psh +VertexLitGeneric_BaseAlphaMaskedEnvMapV2.psh +VertexLitGeneric_BlendTint.psh +VertexLitGeneric_Detail.psh +VertexLitGeneric_Detail_LerpBase.psh +VertexLitGeneric_Detail_additive.psh +VertexLitGeneric_Detail_additive_selfillum.psh +VertexLitGeneric_DetailBaseAlphaMaskedEnvMapV2.psh +VertexLitGeneric_DetailEnvMapV2.psh +VertexLitGeneric_DetailMaskedEnvMapV2.psh +VertexLitGeneric_DetailNoTexture.psh +VertexLitGeneric_DetailSelfIlluminated.psh +VertexLitGeneric_DetailSelfIlluminatedEnvMapV2.psh +VertexLitGeneric_DetailSelfIlluminatedMaskedEnvMapV2.psh +VertexLitGeneric_EnvMapNoTexture.psh +VertexLitGeneric_EnvmappedBumpmap_NoLighting.vsh +VertexLitGeneric_EnvmappedBumpmap_NoLighting_ps14.vsh +VertexLitGeneric_EnvmappedBumpmapV2.psh +VertexLitGeneric_EnvmappedBumpmapV2_MultByAlpha.psh +VertexLitGeneric_EnvmappedBumpmapV2_MultByAlpha_ps14.psh +VertexLitGeneric_EnvmappedBumpmapV2_ps14.psh +VertexLitGeneric_EnvMapV2.psh +vertexlitgeneric_flashlight_vs11.vsh +vertexlitgeneric_lightingonly_overbright2.psh +vertexlitgeneric_lightingonly_overbright2_ps11.fxc +VertexLitGeneric_MaskedEnvMapNoTexture.psh +VertexLitGeneric_MaskedEnvMapV2.psh +VertexLitGeneric_NoTexture.psh +VertexLitGeneric_SelfIlluminated.psh +VertexLitGeneric_SelfIlluminatedEnvMapV2.psh +VertexLitGeneric_SelfIlluminatedMaskedEnvMapV2.psh +VertexLitGeneric_SelfIllumOnly.vsh +vertexlitgeneric_vs11.vsh + +VertexLitTexture.psh +VertexLitTexture_Overbright2.psh + +volume_clouds_vs20.fxc +volume_clouds_ps2x.fxc + +vortwarp_ps11.psh +vortwarp_ps2x.fxc +vortwarp_vs11.vsh +vortwarp_vs20.fxc + +vr_distort_hud_ps2x.fxc +vr_distort_hud_vs20.fxc + +vr_distort_texture_ps2x.fxc +vr_distort_texture_vs20.fxc + +warp_ps2x.fxc +warp_vs20.fxc + +Water_vs11.vsh +Water_ps14.psh +Water_ps14.vsh +water_ps2x.fxc +Water_vs20.fxc + +WaterCheap_ps11.psh +WaterCheap_vs11.vsh +WaterCheap_ps14.psh +WaterCheap_vs14.vsh +WaterCheap_ps2x.fxc +WaterCheap_vs20.fxc +WaterCheapFresnel_ps14.psh +WaterCheapFresnelOpaque_ps14.psh +WaterCheapNoFresnel_ps11.psh +WaterCheapNoFresnelOpaque_ps11.psh +WaterCheapOpaque_ps11.psh +WaterCheapOpaque_ps14.psh +WaterCheapPerVertexFresnel_vs11.vsh + +WaterReflect_ps11.psh +WaterRefract_ps11.psh +WaterRefractFresnel_ps11.psh + +weapon_sheen_pass_ps2x.fxc +weapon_sheen_pass_vs20.fxc + +white.psh +white_ps2x.fxc + +windowimposter_ps11.fxc +windowimposter_vs11.fxc +windowimposter_ps2x.fxc +windowimposter_vs20.fxc + +WorldTexture.psh + +WorldTwoTextureBlend.psh +WorldTwoTextureBlend_DetailAlpha.psh +worldtwotextureblend_ps2x.fxc +WorldTwoTextureBlend_SelfIlluminated.psh + +WorldVertexAlpha.psh +WorldVertexAlpha.vsh +WorldVertexAlpha_ps2x.fxc + +WorldVertexTransition.psh +WorldVertexTransition.vsh +WorldVertexTransition_ps14.psh +WorldVertexTransition_vs14.vsh +WorldVertexTransition_Seamless.psh +WorldVertexTransition_Seamless.vsh +WorldVertexTransition_BlendBase2.psh +WorldVertexTransition_Editor.psh + +writevertexalphatodestalpha_ps11.fxc +writevertexalphatodestalpha_vs11.fxc + +writez.vsh +writez_vs20.fxc + +yuv.psh diff --git a/materialsystem/stdshaders/stdshader_dx9_20b_new.txt b/materialsystem/stdshaders/stdshader_dx9_20b_new.txt new file mode 100644 index 0000000..5ff72ca --- /dev/null +++ b/materialsystem/stdshaders/stdshader_dx9_20b_new.txt @@ -0,0 +1,11 @@ +// +// New shaders collection +// +// These shaders are compiled as shader model 2.0/2.0b +// using the new compiler. +// _ps20.vcs +// _ps20b.vcs +// _vs20.vcs +// + + diff --git a/materialsystem/stdshaders/stdshader_dx9_30.txt b/materialsystem/stdshaders/stdshader_dx9_30.txt new file mode 100644 index 0000000..b23b9fc --- /dev/null +++ b/materialsystem/stdshaders/stdshader_dx9_30.txt @@ -0,0 +1,54 @@ +// +// vs 3.0 ps 3.0 shaders collection +// +// These shaders are forced to compile as shader model 3.0 +// using the new compiler. +// _ps30.vcs +// _vs30.vcs +// + +cloak_vs20.fxc +cloak_ps2x.fxc +cloak_blended_pass_vs20.fxc +cloak_blended_pass_ps2x.fxc +debugmorphaccumulator_vs30.fxc +debugmorphaccumulator_ps30.fxc +decalmodulate_ps2x.fxc +emissive_scroll_blended_pass_vs20.fxc +emissive_scroll_blended_pass_ps2x.fxc +eye_refract_vs20.fxc +eye_refract_ps2x.fxc +Eyes_vs20.fxc +eyes_ps2x.fxc +eyes_flashlight_vs20.fxc +eyes_flashlight_ps2x.fxc +morphaccumulate_vs30.fxc +morphaccumulate_ps30.fxc +morphweight_vs30.fxc +morphweight_ps30.fxc +pyro_vision_ps2x.fxc +pyro_vision_vs20.fxc +skin_vs20.fxc +skin_ps20b.fxc +teeth_vs20.fxc +teeth_ps2x.fxc +teeth_bump_vs20.fxc +teeth_bump_ps2x.fxc +teeth_flashlight_vs20.fxc +teeth_flashlight_ps2x.fxc +vertexlit_and_unlit_generic_vs20.fxc +vertexlit_and_unlit_generic_ps2x.fxc +vertexlit_and_unlit_generic_bump_vs20.fxc +vertexlit_and_unlit_generic_bump_ps2x.fxc +vortwarp_vs20.fxc +vortwarp_ps2x.fxc +vr_distort_hud_ps2x.fxc +vr_distort_hud_vs20.fxc +vr_distort_texture_ps2x.fxc +vr_distort_texture_vs20.fxc +warp_ps2x.fxc +warp_vs20.fxc +weapon_sheen_pass_vs20.fxc +weapon_sheen_pass_ps2x.fxc +depthwrite_ps2x.fxc +depthwrite_vs20.fxc \ No newline at end of file diff --git a/materialsystem/stdshaders/teeth.cpp b/materialsystem/stdshaders/teeth.cpp new file mode 100644 index 0000000..b3dc9ff --- /dev/null +++ b/materialsystem/stdshaders/teeth.cpp @@ -0,0 +1,578 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//=============================================================================// + +#include "BaseVSShader.h" +#include "cpp_shader_constant_register_map.h" + +#include "teeth_vs20.inc" +#include "teeth_flashlight_vs20.inc" +#include "teeth_bump_vs20.inc" +#include "teeth_ps20.inc" +#include "teeth_ps20b.inc" +#include "teeth_flashlight_ps20.inc" +#include "teeth_flashlight_ps20b.inc" +#include "teeth_bump_ps20.inc" +#include "teeth_bump_ps20b.inc" + +#ifndef _X360 +#include "teeth_vs30.inc" +#include "teeth_ps30.inc" +#include "teeth_bump_vs30.inc" +#include "teeth_bump_ps30.inc" +#include "teeth_flashlight_vs30.inc" +#include "teeth_flashlight_ps30.inc" +#endif + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +DEFINE_FALLBACK_SHADER( Teeth, Teeth_DX9 ) + +extern ConVar r_flashlight_version2; +BEGIN_VS_SHADER( Teeth_DX9, "Help for Teeth_DX9" ) + + BEGIN_SHADER_PARAMS + SHADER_PARAM( ILLUMFACTOR, SHADER_PARAM_TYPE_FLOAT, "1", "Amount to darken or brighten the teeth" ) + SHADER_PARAM( FORWARD, SHADER_PARAM_TYPE_VEC3, "[1 0 0]", "Forward direction vector for teeth lighting" ) + SHADER_PARAM( BUMPMAP, SHADER_PARAM_TYPE_TEXTURE, "models/shadertest/shader1_normal", "bump map" ) + SHADER_PARAM( PHONGEXPONENT, SHADER_PARAM_TYPE_FLOAT, "100", "phong exponent" ) + SHADER_PARAM( INTRO, SHADER_PARAM_TYPE_BOOL, "0", "is teeth in the ep1 intro" ) + SHADER_PARAM( ENTITYORIGIN, SHADER_PARAM_TYPE_VEC3,"0.0","center if the model in world space" ) + SHADER_PARAM( WARPPARAM, SHADER_PARAM_TYPE_FLOAT,"0.0","animation param between 0 and 1" ) + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + if ( g_pHardwareConfig->SupportsBorderColor() ) + { + params[FLASHLIGHTTEXTURE]->SetStringValue( "effects/flashlight_border" ); + } + else + { + params[FLASHLIGHTTEXTURE]->SetStringValue( "effects/flashlight001" ); + } + + SET_FLAGS2( MATERIAL_VAR2_SUPPORTS_HW_SKINNING ); + + if( !params[INTRO]->IsDefined() ) + { + params[INTRO]->SetIntValue( 0 ); + } + } + + SHADER_FALLBACK + { + if( g_pHardwareConfig->GetDXSupportLevel() < 90 || g_pConfig->bSoftwareLighting ) + { + return "Teeth_dx8"; + } + return 0; + } + + SHADER_INIT + { + LoadTexture( FLASHLIGHTTEXTURE, TEXTUREFLAGS_SRGB ); + LoadTexture( BASETEXTURE, TEXTUREFLAGS_SRGB ); + + if( params[BUMPMAP]->IsDefined() ) + { + LoadTexture( BUMPMAP ); + } + } + + void DrawUsingVertexShader( IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow, VertexCompressionType_t vertexCompression ) + { + bool hasBump = params[BUMPMAP]->IsTexture(); + + BlendType_t nBlendType = EvaluateBlendRequirements( BASETEXTURE, true ); + bool bFullyOpaque = (nBlendType != BT_BLENDADD) && (nBlendType != BT_BLEND) && !IS_FLAG_SET(MATERIAL_VAR_ALPHATEST); //dest alpha is free for special use + + SHADOW_STATE + { + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); // Base map + + int flags = VERTEX_POSITION | VERTEX_NORMAL; + int nTexCoordCount = 1; + int userDataSize = 0; + + if ( hasBump ) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); // Bump map + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER1, false ); + pShaderShadow->EnableTexture( SHADER_SAMPLER2, true ); // Normalization sampler for per-pixel lighting + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER2, false ); + userDataSize = 4; // tangent S + } + + // This shader supports compressed vertices, so OR in that flag: + flags |= VERTEX_FORMAT_COMPRESSED; + pShaderShadow->VertexShaderVertexFormat( flags, nTexCoordCount, NULL, userDataSize ); + + if ( hasBump ) + { +#ifndef _X360 + if ( !g_pHardwareConfig->HasFastVertexTextures() ) +#endif + { + bool bUseStaticControlFlow = g_pHardwareConfig->SupportsStaticControlFlow(); + + DECLARE_STATIC_VERTEX_SHADER( teeth_bump_vs20 ); + SET_STATIC_VERTEX_SHADER_COMBO( INTRO, params[INTRO]->GetIntValue() ? 1 : 0 ); + SET_STATIC_VERTEX_SHADER_COMBO( USE_STATIC_CONTROL_FLOW, bUseStaticControlFlow ); + SET_STATIC_VERTEX_SHADER( teeth_bump_vs20 ); + + // ps_2_b version which does phong + if ( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_STATIC_PIXEL_SHADER( teeth_bump_ps20b ); + SET_STATIC_PIXEL_SHADER( teeth_bump_ps20b ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( teeth_bump_ps20 ); + SET_STATIC_PIXEL_SHADER( teeth_bump_ps20 ); + } + } +#ifndef _X360 + else + { + // The vertex shader uses the vertex id stream + SET_FLAGS2( MATERIAL_VAR2_USES_VERTEXID ); + + DECLARE_STATIC_VERTEX_SHADER( teeth_bump_vs30 ); + SET_STATIC_VERTEX_SHADER_COMBO( INTRO, params[INTRO]->GetIntValue() ? 1 : 0 ); + SET_STATIC_VERTEX_SHADER( teeth_bump_vs30 ); + + DECLARE_STATIC_PIXEL_SHADER( teeth_bump_ps30 ); + SET_STATIC_PIXEL_SHADER( teeth_bump_ps30 ); + } +#endif + } + else + { +#ifndef _X360 + if ( !g_pHardwareConfig->HasFastVertexTextures() ) +#endif + { + bool bUseStaticControlFlow = g_pHardwareConfig->SupportsStaticControlFlow(); + + DECLARE_STATIC_VERTEX_SHADER( teeth_vs20 ); + SET_STATIC_VERTEX_SHADER_COMBO( INTRO, params[INTRO]->GetIntValue() ? 1 : 0 ); + SET_STATIC_VERTEX_SHADER_COMBO( USE_STATIC_CONTROL_FLOW, bUseStaticControlFlow ); + SET_STATIC_VERTEX_SHADER( teeth_vs20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_STATIC_PIXEL_SHADER( teeth_ps20b ); + SET_STATIC_PIXEL_SHADER( teeth_ps20b ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( teeth_ps20 ); + SET_STATIC_PIXEL_SHADER( teeth_ps20 ); + } + } +#ifndef _X360 + else + { + // The vertex shader uses the vertex id stream + SET_FLAGS2( MATERIAL_VAR2_USES_VERTEXID ); + + DECLARE_STATIC_VERTEX_SHADER( teeth_vs30 ); + SET_STATIC_VERTEX_SHADER_COMBO( INTRO, params[INTRO]->GetIntValue() ? 1 : 0 ); + SET_STATIC_VERTEX_SHADER( teeth_vs30 ); + + DECLARE_STATIC_PIXEL_SHADER( teeth_ps30 ); + SET_STATIC_PIXEL_SHADER( teeth_ps30 ); + } +#endif + } + + // On DX9, do sRGB + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, true ); + pShaderShadow->EnableSRGBWrite( true ); + + FogToFogColor(); + + pShaderShadow->EnableAlphaWrites( bFullyOpaque ); + } + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME ); + if ( hasBump ) + { + BindTexture( SHADER_SAMPLER1, BUMPMAP ); + } + pShaderAPI->BindStandardTexture( SHADER_SAMPLER2, TEXTURE_NORMALIZATION_CUBEMAP_SIGNED ); + pShaderAPI->SetPixelShaderStateAmbientLightCube( PSREG_AMBIENT_CUBE ); + pShaderAPI->CommitPixelShaderLighting( PSREG_LIGHT_INFO_ARRAY ); + + Vector4D lighting; + params[FORWARD]->GetVecValue( lighting.Base(), 3 ); + lighting[3] = params[ILLUMFACTOR]->GetFloatValue(); + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, lighting.Base() ); + + LightState_t lightState; + pShaderAPI->GetDX9LightState( &lightState ); + + pShaderAPI->SetPixelShaderFogParams( PSREG_FOG_PARAMS ); + + float vEyePos_SpecExponent[4]; + pShaderAPI->GetWorldSpaceCameraPosition( vEyePos_SpecExponent ); + vEyePos_SpecExponent[3] = 0.0f; + pShaderAPI->SetPixelShaderConstant( PSREG_EYEPOS_SPEC_EXPONENT, vEyePos_SpecExponent, 1 ); + + if ( hasBump ) + { +#ifndef _X360 + if ( !g_pHardwareConfig->HasFastVertexTextures() ) +#endif + { + bool bUseStaticControlFlow = g_pHardwareConfig->SupportsStaticControlFlow(); + + DECLARE_DYNAMIC_VERTEX_SHADER( teeth_bump_vs20 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( DOWATERFOG, pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, pShaderAPI->GetCurrentNumBones() > 0 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( STATIC_LIGHT, lightState.m_bStaticLightVertex ? 1 : 0 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( NUM_LIGHTS, bUseStaticControlFlow ? 0 : lightState.m_nNumLights ); + SET_DYNAMIC_VERTEX_SHADER( teeth_bump_vs20 ); + + // ps_2_b version which does Phong + if ( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + Vector4D vSpecExponent; + vSpecExponent[3] = params[PHONGEXPONENT]->GetFloatValue(); + + pShaderAPI->SetPixelShaderConstant( PSREG_EYEPOS_SPEC_EXPONENT, vSpecExponent.Base(), 1 ); + + DECLARE_DYNAMIC_PIXEL_SHADER( teeth_bump_ps20b ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( NUM_LIGHTS, lightState.m_nNumLights ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( AMBIENT_LIGHT, lightState.m_bAmbientLight ? 1 : 0 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( WRITE_DEPTH_TO_DESTALPHA, bFullyOpaque && pShaderAPI->ShouldWriteDepthToDestAlpha() ); + SET_DYNAMIC_PIXEL_SHADER( teeth_bump_ps20b ); + } + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( teeth_bump_ps20 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( NUM_LIGHTS, lightState.m_nNumLights ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( AMBIENT_LIGHT, lightState.m_bAmbientLight ? 1 : 0 ); + SET_DYNAMIC_PIXEL_SHADER( teeth_bump_ps20 ); + } + } +#ifndef _X360 + else + { + SetHWMorphVertexShaderState( VERTEX_SHADER_SHADER_SPECIFIC_CONST_6, VERTEX_SHADER_SHADER_SPECIFIC_CONST_7, SHADER_VERTEXTEXTURE_SAMPLER0 ); + + DECLARE_DYNAMIC_VERTEX_SHADER( teeth_bump_vs30 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( DOWATERFOG, pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, pShaderAPI->GetCurrentNumBones() > 0 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( STATIC_LIGHT, lightState.m_bStaticLightVertex ? 1 : 0 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( MORPHING, pShaderAPI->IsHWMorphingEnabled() ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression ); + SET_DYNAMIC_VERTEX_SHADER( teeth_bump_vs30 ); + + Vector4D vSpecExponent; + vSpecExponent[3] = params[PHONGEXPONENT]->GetFloatValue(); + pShaderAPI->SetPixelShaderConstant( PSREG_EYEPOS_SPEC_EXPONENT, vSpecExponent.Base(), 1 ); + + DECLARE_DYNAMIC_PIXEL_SHADER( teeth_bump_ps30 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( NUM_LIGHTS, lightState.m_nNumLights ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( AMBIENT_LIGHT, lightState.m_bAmbientLight ? 1 : 0 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( WRITE_DEPTH_TO_DESTALPHA, bFullyOpaque && pShaderAPI->ShouldWriteDepthToDestAlpha() ); + SET_DYNAMIC_PIXEL_SHADER( teeth_bump_ps30 ); + } +#endif + } + else + { + // For non-bumped case, ambient cube is computed in the vertex shader + SetAmbientCubeDynamicStateVertexShader(); + +#ifndef _X360 + if ( !g_pHardwareConfig->HasFastVertexTextures() ) +#endif + { + bool bUseStaticControlFlow = g_pHardwareConfig->SupportsStaticControlFlow(); + + DECLARE_DYNAMIC_VERTEX_SHADER( teeth_vs20 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( DOWATERFOG, pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, pShaderAPI->GetCurrentNumBones() > 0 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( DYNAMIC_LIGHT, lightState.HasDynamicLight() ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( STATIC_LIGHT, lightState.m_bStaticLightVertex ? 1 : 0 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( NUM_LIGHTS, bUseStaticControlFlow ? 0 : lightState.m_nNumLights ); + SET_DYNAMIC_VERTEX_SHADER( teeth_vs20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_DYNAMIC_PIXEL_SHADER( teeth_ps20b ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( WRITE_DEPTH_TO_DESTALPHA, bFullyOpaque && pShaderAPI->ShouldWriteDepthToDestAlpha() ); + SET_DYNAMIC_PIXEL_SHADER( teeth_ps20b ); + } + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( teeth_ps20 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + SET_DYNAMIC_PIXEL_SHADER( teeth_ps20 ); + } + } +#ifndef _X360 + else + { + SetHWMorphVertexShaderState( VERTEX_SHADER_SHADER_SPECIFIC_CONST_6, VERTEX_SHADER_SHADER_SPECIFIC_CONST_7, SHADER_VERTEXTEXTURE_SAMPLER0 ); + + DECLARE_DYNAMIC_VERTEX_SHADER( teeth_vs30 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( DOWATERFOG, pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, pShaderAPI->GetCurrentNumBones() > 0 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( DYNAMIC_LIGHT, lightState.HasDynamicLight() ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( STATIC_LIGHT, lightState.m_bStaticLightVertex ? 1 : 0 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( MORPHING, pShaderAPI->IsHWMorphingEnabled() ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression ); + SET_DYNAMIC_VERTEX_SHADER( teeth_vs30 ); + + DECLARE_DYNAMIC_PIXEL_SHADER( teeth_ps30 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( WRITE_DEPTH_TO_DESTALPHA, bFullyOpaque && pShaderAPI->ShouldWriteDepthToDestAlpha() ); + SET_DYNAMIC_PIXEL_SHADER( teeth_ps30 ); + } +#endif + } + + if( params[INTRO]->GetIntValue() ) + { + float curTime = params[WARPPARAM]->GetFloatValue(); + float timeVec[4] = { 0.0f, 0.0f, 0.0f, curTime }; + Assert( params[ENTITYORIGIN]->IsDefined() ); + params[ENTITYORIGIN]->GetVecValue( timeVec, 3 ); + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_1, timeVec, 1 ); + } + } + Draw(); + } + + void DrawFlashlight( IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow, VertexCompressionType_t vertexCompression ) + { + SHADOW_STATE + { + // Be sure not to write to dest alpha + pShaderShadow->EnableAlphaWrites( false ); + + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); // Base map + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); // Flashlight spot + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER1, true ); + + // Additive blend the teeth, lit by the flashlight + s_pShaderShadow->EnableAlphaTest( false ); + s_pShaderShadow->BlendFunc( SHADER_BLEND_ONE, SHADER_BLEND_ONE ); + s_pShaderShadow->EnableBlending( true ); + + // Set stream format (note that this shader supports compression) + int flags = VERTEX_POSITION | VERTEX_NORMAL | VERTEX_FORMAT_COMPRESSED; + int nTexCoordCount = 1; + int userDataSize = 0; + pShaderShadow->VertexShaderVertexFormat( flags, nTexCoordCount, NULL, userDataSize ); + + int nShadowFilterMode = 0; + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER2, true ); // shadow depth map + pShaderShadow->SetShadowDepthFiltering( SHADER_SAMPLER2 ); + pShaderShadow->EnableTexture( SHADER_SAMPLER3, true ); // shadow noise + + nShadowFilterMode = g_pHardwareConfig->GetShadowFilterMode(); // Based upon vendor and device dependent formats + } + +#ifndef _X360 + if ( !g_pHardwareConfig->HasFastVertexTextures() ) +#endif + { + DECLARE_STATIC_VERTEX_SHADER( teeth_flashlight_vs20 ); + SET_STATIC_VERTEX_SHADER_COMBO( INTRO, params[INTRO]->GetIntValue() ? 1 : 0 ); + SET_STATIC_VERTEX_SHADER( teeth_flashlight_vs20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_STATIC_PIXEL_SHADER( teeth_flashlight_ps20b ); + SET_STATIC_PIXEL_SHADER_COMBO( FLASHLIGHTDEPTHFILTERMODE, nShadowFilterMode ); + SET_STATIC_PIXEL_SHADER( teeth_flashlight_ps20b ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( teeth_flashlight_ps20 ); + SET_STATIC_PIXEL_SHADER( teeth_flashlight_ps20 ); + } + } +#ifndef _X360 + else + { + // The vertex shader uses the vertex id stream + SET_FLAGS2( MATERIAL_VAR2_USES_VERTEXID ); + + DECLARE_STATIC_VERTEX_SHADER( teeth_flashlight_vs30 ); + SET_STATIC_VERTEX_SHADER_COMBO( INTRO, params[INTRO]->GetIntValue() ? 1 : 0 ); + SET_STATIC_VERTEX_SHADER( teeth_flashlight_vs30 ); + + DECLARE_STATIC_PIXEL_SHADER( teeth_flashlight_ps30 ); + SET_STATIC_PIXEL_SHADER_COMBO( FLASHLIGHTDEPTHFILTERMODE, nShadowFilterMode ); + SET_STATIC_PIXEL_SHADER( teeth_flashlight_ps30 ); + } +#endif + // On DX9, do sRGB + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, true ); + pShaderShadow->EnableSRGBWrite( true ); + + FogToFogColor(); + } + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME ); + + // State for spotlight projection, attenuation etc + SetFlashlightVertexShaderConstants( false, -1, false, -1, true ); + + VMatrix worldToTexture; + ITexture *pFlashlightDepthTexture; + FlashlightState_t state = pShaderAPI->GetFlashlightStateEx( worldToTexture, &pFlashlightDepthTexture ); + SetFlashLightColorFromState( state, pShaderAPI, PSREG_FLASHLIGHT_COLOR ); + + bool bFlashlightShadows = g_pHardwareConfig->SupportsPixelShaders_2_b() ? state.m_bEnableShadows && ( pFlashlightDepthTexture != NULL ) : false; + if( pFlashlightDepthTexture && g_pConfig->ShadowDepthTexture() && state.m_bEnableShadows ) + { + BindTexture( SHADER_SAMPLER2, pFlashlightDepthTexture, 0 ); + pShaderAPI->BindStandardTexture( SHADER_SAMPLER3, TEXTURE_SHADOW_NOISE_2D ); + } + + Vector4D lighting; + params[FORWARD]->GetVecValue( lighting.Base(), 3 ); + lighting[3] = params[ILLUMFACTOR]->GetFloatValue(); + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_8, lighting.Base() ); + + float atten[4], pos[4], tweaks[4]; + + const FlashlightState_t &flashlightState = pShaderAPI->GetFlashlightState( worldToTexture ); + SetFlashLightColorFromState( flashlightState, pShaderAPI, PSREG_FLASHLIGHT_COLOR ); + + BindTexture( SHADER_SAMPLER1, flashlightState.m_pSpotlightTexture, flashlightState.m_nSpotlightTextureFrame ); + + atten[0] = flashlightState.m_fConstantAtten; // Set the flashlight attenuation factors + atten[1] = flashlightState.m_fLinearAtten; + atten[2] = flashlightState.m_fQuadraticAtten; + atten[3] = flashlightState.m_FarZ; + pShaderAPI->SetPixelShaderConstant( PSREG_FLASHLIGHT_ATTENUATION, atten, 1 ); + + pos[0] = flashlightState.m_vecLightOrigin[0]; // Set the flashlight origin + pos[1] = flashlightState.m_vecLightOrigin[1]; + pos[2] = flashlightState.m_vecLightOrigin[2]; + pShaderAPI->SetPixelShaderConstant( PSREG_FLASHLIGHT_POSITION_RIM_BOOST, pos, 1 ); // steps on rim boost + + pShaderAPI->SetPixelShaderConstant( PSREG_FLASHLIGHT_TO_WORLD_TEXTURE, worldToTexture.Base(), 4 ); + + // Tweaks associated with a given flashlight + tweaks[0] = ShadowFilterFromState( flashlightState ); + tweaks[1] = ShadowAttenFromState( flashlightState ); + HashShadow2DJitter( flashlightState.m_flShadowJitterSeed, &tweaks[2], &tweaks[3] ); + pShaderAPI->SetPixelShaderConstant( PSREG_ENVMAP_TINT__SHADOW_TWEAKS, tweaks, 1 ); + + // Dimensions of screen, used for screen-space noise map sampling + float vScreenScale[4] = {1280.0f / 32.0f, 720.0f / 32.0f, 0, 0}; + int nWidth, nHeight; + pShaderAPI->GetBackBufferDimensions( nWidth, nHeight ); + vScreenScale[0] = (float) nWidth / 32.0f; + vScreenScale[1] = (float) nHeight / 32.0f; + pShaderAPI->SetPixelShaderConstant( PSREG_FLASHLIGHT_SCREEN_SCALE, vScreenScale, 1 ); + + float vFlashlightPos[4]; + pShaderAPI->GetWorldSpaceCameraPosition( vFlashlightPos ); + pShaderAPI->SetPixelShaderConstant( PSREG_FLASHLIGHT_POSITION_RIM_BOOST, vFlashlightPos, 1 ); + + if ( IsX360() ) + { + pShaderAPI->SetBooleanPixelShaderConstant( 0, &flashlightState.m_nShadowQuality, 1 ); + } + +#ifndef _X360 + if ( !g_pHardwareConfig->HasFastVertexTextures() ) +#endif + { + DECLARE_DYNAMIC_VERTEX_SHADER( teeth_flashlight_vs20 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( DOWATERFOG, pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, pShaderAPI->GetCurrentNumBones() > 0 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression ); + SET_DYNAMIC_VERTEX_SHADER( teeth_flashlight_vs20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_DYNAMIC_PIXEL_SHADER( teeth_flashlight_ps20b ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( FLASHLIGHTSHADOWS, bFlashlightShadows ); + SET_DYNAMIC_PIXEL_SHADER( teeth_flashlight_ps20b ); + } + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( teeth_flashlight_ps20 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + SET_DYNAMIC_PIXEL_SHADER( teeth_flashlight_ps20 ); + } + } +#ifndef _X360 + else + { + SetHWMorphVertexShaderState( VERTEX_SHADER_SHADER_SPECIFIC_CONST_6, VERTEX_SHADER_SHADER_SPECIFIC_CONST_7, SHADER_VERTEXTEXTURE_SAMPLER0 ); + + DECLARE_DYNAMIC_VERTEX_SHADER( teeth_flashlight_vs30 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( DOWATERFOG, pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, pShaderAPI->GetCurrentNumBones() > 0 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( MORPHING, pShaderAPI->IsHWMorphingEnabled() ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression ); + SET_DYNAMIC_VERTEX_SHADER( teeth_flashlight_vs30 ); + + DECLARE_DYNAMIC_PIXEL_SHADER( teeth_flashlight_ps30 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( FLASHLIGHTSHADOWS, bFlashlightShadows ); + SET_DYNAMIC_PIXEL_SHADER( teeth_flashlight_ps30 ); + } +#endif + + if( params[INTRO]->GetIntValue() ) + { + float curTime = params[WARPPARAM]->GetFloatValue(); + float timeVec[4] = { 0.0f, 0.0f, 0.0f, curTime }; + Assert( params[ENTITYORIGIN]->IsDefined() ); + params[ENTITYORIGIN]->GetVecValue( timeVec, 3 ); + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_9, timeVec, 1 ); + } + } + Draw(); + } + + SHADER_DRAW + { + SHADOW_STATE + { + SET_FLAGS2( MATERIAL_VAR2_LIGHTING_VERTEX_LIT ); + } + bool hasFlashlight = UsingFlashlight( params ); + if ( !hasFlashlight || ( IsX360() || r_flashlight_version2.GetInt() ) ) + { + DrawUsingVertexShader( params, pShaderAPI, pShaderShadow, vertexCompression ); + SHADOW_STATE + { + SetInitialShadowState(); + } + } + if( hasFlashlight ) + { + DrawFlashlight( params, pShaderAPI, pShaderShadow, vertexCompression ); + } + } +END_SHADER diff --git a/materialsystem/stdshaders/teeth_bump_ps2x.fxc b/materialsystem/stdshaders/teeth_bump_ps2x.fxc new file mode 100644 index 0000000..72e43a1 --- /dev/null +++ b/materialsystem/stdshaders/teeth_bump_ps2x.fxc @@ -0,0 +1,101 @@ +//====== Copyright © 1996-2006, Valve Corporation, All rights reserved. ======= + +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps30][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX] + +// DYNAMIC: "PIXELFOGTYPE" "0..1" +// DYNAMIC: "NUM_LIGHTS" "0..2" [ps20] +// DYNAMIC: "NUM_LIGHTS" "0..4" [ps20b] +// DYNAMIC: "NUM_LIGHTS" "0..4" [ps30] +// DYNAMIC: "AMBIENT_LIGHT" "0..1" +// DYNAMIC: "WRITE_DEPTH_TO_DESTALPHA" "0..1" [ps20b] [PC] +// DYNAMIC: "WRITE_DEPTH_TO_DESTALPHA" "0..0" [ps20b] [XBOX] +// DYNAMIC: "WRITE_DEPTH_TO_DESTALPHA" "0..1" [ps30] + +#if defined( SHADER_MODEL_PS_2_0 ) +# define WRITE_DEPTH_TO_DESTALPHA 0 +#endif + +#include "shader_constant_register_map.h" + +const float3 cAmbientCube[6] : register( PSREG_AMBIENT_CUBE ); +const float4 g_FogParams : register( PSREG_FOG_PARAMS ); +const float4 g_EyePos_SpecExponent : register( PSREG_EYEPOS_SPEC_EXPONENT ); +PixelShaderLightInfo cLightInfo[3] : register( PSREG_LIGHT_INFO_ARRAY ); // 2 registers each - 6 registers total + +sampler BaseTextureSampler : register( s0 ); +sampler BumpTextureSampler : register( s1 ); +sampler NormalizeSampler : register( s2 ); + +struct PS_INPUT +{ + float2 baseTexCoord : TEXCOORD0; + float4 worldVertToEyeVector_Darkening : TEXCOORD1; + float3x3 tangentSpaceTranspose : TEXCOORD2; + // second row : TEXCOORD3; + // third row : TEXCOORD4; + float4 worldPos_projPosZ : TEXCOORD5; + float2 lightAtten01 : TEXCOORD6; + float2 lightAtten23 : TEXCOORD7; +}; + + + +#if ((defined(SHADER_MODEL_PS_2_B) || defined(SHADER_MODEL_PS_3_0))) + +#define worldVertToEyeVector i.worldVertToEyeVector_Darkening.xyz +#define fDarkening i.worldVertToEyeVector_Darkening.w + +#endif + + + +float4 main( PS_INPUT i ) : COLOR +{ + bool bAmbientLight = AMBIENT_LIGHT ? true : false; + int nNumLights = NUM_LIGHTS; + + float4 vLightAtten = float4( i.lightAtten01, i.lightAtten23 ); + float4 baseSample = tex2D( BaseTextureSampler, i.baseTexCoord ); + + float3 worldSpaceNormal, tangentSpaceNormal = float3(0, 0, 1); + float fSpecExp = g_EyePos_SpecExponent.w; + + float4 normalTexel = tex2D( BumpTextureSampler, i.baseTexCoord ); + tangentSpaceNormal = 2.0f * normalTexel.xyz - 1.0f; + worldSpaceNormal = normalize( mul( i.tangentSpaceTranspose, tangentSpaceNormal ) ); + + // If the exponent passed in as a constant is zero, use the value from the map as the exponent + if ( fSpecExp == 0 ) + fSpecExp = 1.0f * ( 1.0f - normalTexel.w ) + 150.0f * normalTexel.w; + + // Summation of diffuse illumination from all local lights + float3 diffuseLighting = PixelShaderDoLighting( i.worldPos_projPosZ.xyz, worldSpaceNormal, + float3( 0.0f, 0.0f, 0.0f ), false, + bAmbientLight, vLightAtten, + cAmbientCube, NormalizeSampler, nNumLights, cLightInfo, true, + false, 0, false, NormalizeSampler ); + +#if ((defined(SHADER_MODEL_PS_2_B) || defined(SHADER_MODEL_PS_3_0))) + + float3 vDummy, specularLighting; + + // Summation of specular from all local lights + PixelShaderDoSpecularLighting( i.worldPos_projPosZ.xyz, worldSpaceNormal, fSpecExp, normalize(worldVertToEyeVector), + vLightAtten, nNumLights, cLightInfo, + false, 1.0f, false, NormalizeSampler, 1.0f, false, 1.0f, + + // Outputs + specularLighting, vDummy ); + + // Specular plus diffuse, all darkened as a function of mouth openness + float3 result = (specularLighting * baseSample.a + baseSample.rgb * diffuseLighting) * fDarkening; + +#else + float3 result = baseSample.rgb * diffuseLighting * i.worldVertToEyeVector_Darkening.w; +#endif + + float fogFactor = CalcPixelFogFactor( PIXELFOGTYPE, g_FogParams, g_EyePos_SpecExponent.z, i.worldPos_projPosZ.z, i.worldPos_projPosZ.w ); + return FinalOutput( float4(result, 1.0f), fogFactor, PIXELFOGTYPE, TONEMAP_SCALE_LINEAR, (WRITE_DEPTH_TO_DESTALPHA != 0), i.worldPos_projPosZ.w ); +} diff --git a/materialsystem/stdshaders/teeth_bump_vs20.fxc b/materialsystem/stdshaders/teeth_bump_vs20.fxc new file mode 100644 index 0000000..1dd834b --- /dev/null +++ b/materialsystem/stdshaders/teeth_bump_vs20.fxc @@ -0,0 +1,152 @@ +//======= Copyright © 1996-2006, Valve Corporation, All rights reserved. ====== + +// STATIC: "INTRO" "0..1" +// STATIC: "USE_STATIC_CONTROL_FLOW" "0..1" [vs20] + +// DYNAMIC: "COMPRESSED_VERTS" "0..1" +// DYNAMIC: "DOWATERFOG" "0..1" +// DYNAMIC: "SKINNING" "0..1" +// DYNAMIC: "STATIC_LIGHT" "0..1" +// DYNAMIC: "MORPHING" "0..1" [vs30] +// DYNAMIC: "NUM_LIGHTS" "0..2" [vs20] + +// If using static control flow on Direct3D, we should use the NUM_LIGHTS=0 combo +// SKIP: $USE_STATIC_CONTROL_FLOW && ( $NUM_LIGHTS > 0 ) [vs20] + +#include "vortwarp_vs20_helper.h" + +static const int g_FogType = DOWATERFOG; +static const bool g_bSkinning = SKINNING ? true : false; + +const float4 cTeethLighting : register( SHADER_SPECIFIC_CONST_0 ); +#if INTRO +const float4 const4 : register( SHADER_SPECIFIC_CONST_1 ); +#define g_Time const4.w +#define modelOrigin const4.xyz +#endif + +#ifdef SHADER_MODEL_VS_3_0 +// NOTE: cMorphTargetTextureDim.xy = target dimensions, +// cMorphTargetTextureDim.z = 4tuples/morph +const float3 cMorphTargetTextureDim : register( SHADER_SPECIFIC_CONST_6 ); +const float4 cMorphSubrect : register( SHADER_SPECIFIC_CONST_7 ); + +sampler2D morphSampler : register( D3DVERTEXTEXTURESAMPLER0, s0 ); +#endif + +struct VS_INPUT +{ + // This is all of the stuff that we ever use. + float4 vPos : POSITION; + float4 vBoneWeights : BLENDWEIGHT; + float4 vBoneIndices : BLENDINDICES; + float4 vNormal : NORMAL; + float2 vTexCoord0 : TEXCOORD0; + float4 vUserData : TANGENT; // Sign for cross product in w + + // Position and normal/tangent deltas + float3 vPosFlex : POSITION1; + float3 vNormalFlex : NORMAL1; +#ifdef SHADER_MODEL_VS_3_0 + float vVertexID : POSITION2; +#endif +}; + +struct VS_OUTPUT +{ + float4 projPos : POSITION; +#if !defined( _X360 ) + float fog : FOG; +#endif + float2 baseTexCoord : TEXCOORD0; + float4 worldVertToEyeVector_Darkening : TEXCOORD1; + float3x3 tangentSpaceTranspose : TEXCOORD2; + // second row : TEXCOORD3; + // third row : TEXCOORD4; + float4 worldPos_projPosZ : TEXCOORD5; + float2 lightAtten01 : TEXCOORD6; + float2 lightAtten23 : TEXCOORD7; +}; + +VS_OUTPUT main( const VS_INPUT v ) +{ + VS_OUTPUT o = ( VS_OUTPUT )0; + + float4 vPosition = v.vPos; + float3 vNormal; + float4 vTangent; + DecompressVertex_NormalTangent( v.vNormal, v.vUserData, vNormal, vTangent ); + +#if !defined( SHADER_MODEL_VS_3_0 ) || !MORPHING + ApplyMorph( v.vPosFlex, v.vNormalFlex, vPosition.xyz, vNormal, vTangent.xyz ); +#else + ApplyMorph( morphSampler, cMorphTargetTextureDim, cMorphSubrect, v.vVertexID, float3( 0, 0, 0 ), + vPosition.xyz, vNormal, vTangent.xyz ); +#endif + + // Perform skinning + float3 worldNormal, worldPos, worldTangentS, worldTangentT; + SkinPositionNormalAndTangentSpace( g_bSkinning, vPosition, vNormal, vTangent, + v.vBoneWeights, v.vBoneIndices, worldPos, + worldNormal, worldTangentS, worldTangentT ); + +#if INTRO + WorldSpaceVertexProcess( g_Time, modelOrigin, worldPos, worldNormal, worldTangentS, worldTangentT ); +#endif + + // Always normalize since flex path is controlled by runtime + // constant not a shader combo and will always generate the normalization + worldNormal = normalize( worldNormal ); + worldTangentS = normalize( worldTangentS ); + worldTangentT = normalize( worldTangentT ); + + // Transform into projection space + float4 vProjPos = mul( float4( worldPos, 1 ), cViewProj ); + o.projPos = vProjPos; + vProjPos.z = dot( float4( worldPos, 1 ), cViewProjZ ); + + o.worldPos_projPosZ = float4( worldPos, vProjPos.z ); +#if !defined( _X360 ) + // Set fixed-function fog factor + o.fog = CalcFog( worldPos, vProjPos, g_FogType ); +#endif + // Needed for specular + o.worldVertToEyeVector_Darkening.xyz = cEyePos - worldPos; + + // Special darkening of lights for mouth open/close + o.worldVertToEyeVector_Darkening.w = cTeethLighting.w * saturate( dot( worldNormal, cTeethLighting.xyz ) );; + + // Scalar light attenuation (mouth darkening applied in pixel shader) +#if defined( SHADER_MODEL_VS_2_0 ) && ( !USE_STATIC_CONTROL_FLOW ) + o.lightAtten01.xy = float2(0,0); + o.lightAtten23.xy = float2(0,0); + #if ( NUM_LIGHTS > 0 ) + o.lightAtten01.x = GetVertexAttenForLight( worldPos, 0, false ); + #endif + #if ( NUM_LIGHTS > 1 ) + o.lightAtten01.y = GetVertexAttenForLight( worldPos, 1, false ); + #endif + #if ( NUM_LIGHTS > 2 ) + o.lightAtten23.x = GetVertexAttenForLight( worldPos, 2, false ); + #endif + #if ( NUM_LIGHTS > 3 ) + o.lightAtten23.y = GetVertexAttenForLight( worldPos, 3, false ); + #endif +#else + o.lightAtten01.x = GetVertexAttenForLight( worldPos, 0, true ); + o.lightAtten01.y = GetVertexAttenForLight( worldPos, 1, true ); + o.lightAtten23.x = GetVertexAttenForLight( worldPos, 2, true ); + o.lightAtten23.y = GetVertexAttenForLight( worldPos, 3, true ); +#endif + + o.baseTexCoord = v.vTexCoord0; + + // Tangent space transform + o.tangentSpaceTranspose[0] = float3( worldTangentS.x, worldTangentT.x, worldNormal.x ); + o.tangentSpaceTranspose[1] = float3( worldTangentS.y, worldTangentT.y, worldNormal.y ); + o.tangentSpaceTranspose[2] = float3( worldTangentS.z, worldTangentT.z, worldNormal.z ); + + return o; +} + + diff --git a/materialsystem/stdshaders/teeth_dx6.cpp b/materialsystem/stdshaders/teeth_dx6.cpp new file mode 100644 index 0000000..8c097f6 --- /dev/null +++ b/materialsystem/stdshaders/teeth_dx6.cpp @@ -0,0 +1,69 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//=============================================================================// + +#include "BaseVSShader.h" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +DEFINE_FALLBACK_SHADER( Teeth, Teeth_DX6 ) + +BEGIN_VS_SHADER( Teeth_DX6, + "Help for Teeth_DX6" ) + + BEGIN_SHADER_PARAMS + SHADER_PARAM( ILLUMFACTOR, SHADER_PARAM_TYPE_FLOAT, "1", "Amount to darken or brighten the teeth" ) + SHADER_PARAM( FORWARD, SHADER_PARAM_TYPE_VEC3, "[1 0 0]", "Forward direction vector for teeth lighting" ) + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + // FLASHLIGHTFIXME + params[FLASHLIGHTTEXTURE]->SetStringValue( "effects/flashlight001" ); + + SET_FLAGS2( MATERIAL_VAR2_SUPPORTS_HW_SKINNING ); + } + + SHADER_INIT + { + LoadTexture( FLASHLIGHTTEXTURE ); + LoadTexture( BASETEXTURE ); + } + + void DrawUsingSoftwareLighting( IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow ) + { + SHADOW_STATE + { + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->OverbrightValue( SHADER_TEXTURE_STAGE0, OVERBRIGHT ); + pShaderShadow->DrawFlags( SHADER_DRAW_POSITION | SHADER_DRAW_COLOR | SHADER_DRAW_TEXCOORD0 ); + FogToFogColor(); + } + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME ); + } + Draw(); + } + + SHADER_DRAW + { + SHADOW_STATE + { + SET_FLAGS2( MATERIAL_VAR2_LIGHTING_VERTEX_LIT ); + } + bool hasFlashlight = UsingFlashlight( params ); + + if( hasFlashlight ) + { + DrawFlashlight_dx70( params, pShaderAPI, pShaderShadow, FLASHLIGHTTEXTURE, FLASHLIGHTTEXTUREFRAME ); + } + else + { + DrawUsingSoftwareLighting( params, pShaderAPI, pShaderShadow ); + } + } +END_SHADER diff --git a/materialsystem/stdshaders/teeth_dx8.cpp b/materialsystem/stdshaders/teeth_dx8.cpp new file mode 100644 index 0000000..d91626d --- /dev/null +++ b/materialsystem/stdshaders/teeth_dx8.cpp @@ -0,0 +1,116 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//=============================================================================// + +#include "BaseVSShader.h" + +#include "teeth.inc" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +DEFINE_FALLBACK_SHADER( Teeth, Teeth_DX8 ) + +BEGIN_VS_SHADER( Teeth_DX8, "Help for Teeth_DX8" ) + + BEGIN_SHADER_PARAMS + SHADER_PARAM( ILLUMFACTOR, SHADER_PARAM_TYPE_FLOAT, "1", "Amount to darken or brighten the teeth" ) + SHADER_PARAM( FORWARD, SHADER_PARAM_TYPE_VEC3, "[1 0 0]", "Forward direction vector for teeth lighting" ) + SHADER_PARAM( INTRO, SHADER_PARAM_TYPE_BOOL, "0", "is teeth in the ep1 intro" ) + SHADER_PARAM( ENTITYORIGIN, SHADER_PARAM_TYPE_VEC3,"0.0","center if the model in world space" ) + SHADER_PARAM( WARPPARAM, SHADER_PARAM_TYPE_FLOAT,"0.0","animation param between 0 and 1" ) + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + // FLASHLIGHTFIXME + params[FLASHLIGHTTEXTURE]->SetStringValue( "effects/flashlight001" ); + + SET_FLAGS2( MATERIAL_VAR2_SUPPORTS_HW_SKINNING ); + + if( !params[INTRO]->IsDefined() ) + { + params[INTRO]->SetIntValue( 0 ); + } + } + + SHADER_FALLBACK + { + if ( IsPC() && ( g_pHardwareConfig->GetDXSupportLevel() < 80 || g_pConfig->bSoftwareLighting ) ) + { + return "Teeth_dx6"; + } + return 0; + } + + SHADER_INIT + { + LoadTexture( FLASHLIGHTTEXTURE ); + LoadTexture( BASETEXTURE ); + } + + void DrawUsingVertexShader( IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow ) + { + SHADOW_STATE + { + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->VertexShaderVertexFormat( + VERTEX_POSITION | VERTEX_NORMAL, 1, 0, 0 ); + teeth_Static_Index vshIndex; + vshIndex.SetHALF_LAMBERT( IS_FLAG_SET( MATERIAL_VAR_HALFLAMBERT ) ); + vshIndex.SetINTRO( params[INTRO]->GetIntValue() != 0 ); + pShaderShadow->SetVertexShader( "Teeth", vshIndex.GetIndex() ); + pShaderShadow->SetPixelShader( "VertexLitTexture_Overbright2" ); + + FogToFogColor(); + } + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME ); + SetAmbientCubeDynamicStateVertexShader(); + + Vector4D lighting; + params[FORWARD]->GetVecValue( lighting.Base(), 3 ); + lighting[3] = params[ILLUMFACTOR]->GetFloatValue(); + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, lighting.Base() ); + + teeth_Dynamic_Index vshIndex; + vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + vshIndex.SetSKINNING( pShaderAPI->GetCurrentNumBones() > 0 ); + vshIndex.SetLIGHT_COMBO( pShaderAPI->GetCurrentLightCombo() ); + pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() ); + + if( params[INTRO]->GetIntValue() ) + { + float curTime = params[WARPPARAM]->GetFloatValue(); + float timeVec[4] = { 0.0f, 0.0f, 0.0f, curTime }; + Assert( params[ENTITYORIGIN]->IsDefined() ); + params[ENTITYORIGIN]->GetVecValue( timeVec, 3 ); + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_1, timeVec, 1 ); + } + } + Draw(); + } + + SHADER_DRAW + { + SHADOW_STATE + { + SET_FLAGS2( MATERIAL_VAR2_LIGHTING_VERTEX_LIT ); + } + bool hasFlashlight = UsingFlashlight( params ); + if( hasFlashlight ) + { + DrawFlashlight_dx80( params, pShaderAPI, pShaderShadow, false, -1, -1, -1, + FLASHLIGHTTEXTURE, FLASHLIGHTTEXTUREFRAME, false, false, 0, -1, -1, + // Optional parameters, specific to teeth: + true, FORWARD, ILLUMFACTOR ); + } + else + { + DrawUsingVertexShader( params, pShaderAPI, pShaderShadow ); + } + } +END_SHADER diff --git a/materialsystem/stdshaders/teeth_flashlight_ps2x.fxc b/materialsystem/stdshaders/teeth_flashlight_ps2x.fxc new file mode 100644 index 0000000..7ef6187 --- /dev/null +++ b/materialsystem/stdshaders/teeth_flashlight_ps2x.fxc @@ -0,0 +1,66 @@ +//====== Copyright © 1996-2004, Valve Corporation, All rights reserved. ======= +// +// Purpose: +// +//============================================================================= + +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps30][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX] +// STATIC: "FLASHLIGHTDEPTHFILTERMODE" "0..2" [ps20b] [PC] +// STATIC: "FLASHLIGHTDEPTHFILTERMODE" "0..2" [ps30] [PC] +// STATIC: "FLASHLIGHTDEPTHFILTERMODE" "0..0" [ps20b] [XBOX] + +// DYNAMIC: "PIXELFOGTYPE" "0..1" +// DYNAMIC: "FLASHLIGHTSHADOWS" "0..1" [ps20b] +// DYNAMIC: "FLASHLIGHTSHADOWS" "0..1" [ps30] + +#include "common_flashlight_fxc.h" +#include "shader_constant_register_map.h" + +sampler BaseTextureSampler : register( s0 ); +sampler SpotSampler : register( s1 ); +sampler FlashlightDepthSampler : register( s2 ); +sampler RandomRotationSampler : register( s3 ); + +const float4 g_FogParams : register( PSREG_FOG_PARAMS ); +const float3 g_EyePos : register( PSREG_EYEPOS_SPEC_EXPONENT ); +const float3 g_FlashlightPos : register( PSREG_FLASHLIGHT_POSITION_RIM_BOOST ); +const float4 g_FlashlightAtten : register( PSREG_FLASHLIGHT_ATTENUATION ); +const float4x4 g_FlashlightWorldToTexture : register( PSREG_FLASHLIGHT_TO_WORLD_TEXTURE ); +const float4 g_ShadowTweaks : register( PSREG_ENVMAP_TINT__SHADOW_TWEAKS ); + +struct PS_INPUT +{ + float2 baseTexCoord : TEXCOORD0; // Base texture coordinates + float4 spotTexCoord : TEXCOORD1; // Spotlight texture coordinates + float3 vertAtten : TEXCOORD2; // Distance/spot attenuation + float4 projPos : TEXCOORD3; // Projective space position + float3 worldPos : TEXCOORD4; // Necessary for pixel fog +}; + +float4 main( PS_INPUT i ) : COLOR +{ +#if defined( SHADER_MODEL_PS_2_0 ) + float3 result = tex2Dproj( SpotSampler, i.spotTexCoord.xyzw ); +#else + float3 vProjCoords = i.spotTexCoord.xyz / i.spotTexCoord.w; + float3 result = tex2D( SpotSampler, vProjCoords ); +#endif + + result *= cFlashlightColor.rgb; + +#if FLASHLIGHTSHADOWS && ( defined( SHADER_MODEL_PS_2_B ) || defined( SHADER_MODEL_PS_3_0 ) ) + result *= DoFlashlightShadow( FlashlightDepthSampler, RandomRotationSampler, vProjCoords, i.projPos.xy / i.projPos.z, FLASHLIGHTDEPTHFILTERMODE, g_ShadowTweaks, true ); +#endif + result *= 0.35f; // Without this, unshadowed teeth always seem to glow + + result *= i.vertAtten; // Distance atten, NdotL and forward vector + + float4 baseSample = tex2D( BaseTextureSampler, i.baseTexCoord ); + result *= baseSample.rgb; // Multiply by base map and diffuse + + float fogFactor = CalcPixelFogFactor( PIXELFOGTYPE, g_FogParams, g_EyePos.z, i.worldPos.z, i.projPos.z ); + return FinalOutput( float4( result, baseSample.a ), fogFactor, PIXELFOGTYPE, TONEMAP_SCALE_LINEAR ); +} + diff --git a/materialsystem/stdshaders/teeth_flashlight_vs20.fxc b/materialsystem/stdshaders/teeth_flashlight_vs20.fxc new file mode 100644 index 0000000..8c5ce4c --- /dev/null +++ b/materialsystem/stdshaders/teeth_flashlight_vs20.fxc @@ -0,0 +1,149 @@ +//======= Copyright © 1996-2007, Valve Corporation, All rights reserved. ====== + +// STATIC: "INTRO" "0..1" + +// DYNAMIC: "COMPRESSED_VERTS" "0..1" +// DYNAMIC: "DOWATERFOG" "0..1" +// DYNAMIC: "SKINNING" "0..1" +// DYNAMIC: "MORPHING" "0..1" [vs30] + +#include "vortwarp_vs20_helper.h" + +static const int g_FogType = DOWATERFOG; +static const bool g_bSkinning = SKINNING ? true : false; + +const float4 cFlashlightPosition : register( SHADER_SPECIFIC_CONST_0 ); +const float4 cSpotlightProj1 : register( SHADER_SPECIFIC_CONST_1 ); +const float4 cSpotlightProj2 : register( SHADER_SPECIFIC_CONST_2 ); +const float4 cSpotlightProj3 : register( SHADER_SPECIFIC_CONST_3 ); +const float4 cSpotlightProj4 : register( SHADER_SPECIFIC_CONST_4 ); +const float4 cFlashlighAtten : register( SHADER_SPECIFIC_CONST_5 ); // const, linear, quadratic & farZ + +const float4 cTeethLighting : register( SHADER_SPECIFIC_CONST_8 ); +#if INTRO +const float4 const4 : register( SHADER_SPECIFIC_CONST_9 ); +#define g_Time const4.w +#define modelOrigin const4.xyz +#endif + +#ifdef SHADER_MODEL_VS_3_0 +// NOTE: cMorphTargetTextureDim.xy = target dimensions, +// cMorphTargetTextureDim.z = 4tuples/morph +const float3 cMorphTargetTextureDim : register( SHADER_SPECIFIC_CONST_6 ); +const float4 cMorphSubrect : register( SHADER_SPECIFIC_CONST_7 ); + +sampler2D morphSampler : register( D3DVERTEXTEXTURESAMPLER0, s0 ); +#endif + + +struct VS_INPUT +{ + // This is all of the stuff that we ever use. + float4 vPos : POSITION; + float4 vBoneWeights : BLENDWEIGHT; + float4 vBoneIndices : BLENDINDICES; + float4 vNormal : NORMAL; + float2 vTexCoord0 : TEXCOORD0; + + // Position and normal/tangent deltas + float3 vPosFlex : POSITION1; + float3 vNormalFlex : NORMAL1; +#ifdef SHADER_MODEL_VS_3_0 + float vVertexID : POSITION2; +#endif +}; + +struct VS_OUTPUT +{ + float4 projPos : POSITION; +#if !defined( _X360 ) + float fog : FOG; +#endif + float2 baseTexCoord : TEXCOORD0; // Base texture coordinates + float4 spotTexCoord : TEXCOORD1; // Spotlight texture coordinates + float3 vertAtten : TEXCOORD2; // Distance/spot attenuation + float4 vProjPos : TEXCOORD3; // Projective space position + float3 worldPos : TEXCOORD4; // Necessary for pixel fog +}; + + +float RemapValClamped_01( float val, float A, float B ) +{ + float cVal = (val - A) / (B - A); + cVal = saturate( cVal ); + return cVal; +} + +VS_OUTPUT main( const VS_INPUT v ) +{ + VS_OUTPUT o = ( VS_OUTPUT )0; + + float4 vPosition = v.vPos; + float3 vNormal; + DecompressVertex_Normal( v.vNormal, vNormal ); + +#if !defined( SHADER_MODEL_VS_3_0 ) || !MORPHING + ApplyMorph( v.vPosFlex, v.vNormalFlex, vPosition.xyz, vNormal ); +#else + ApplyMorph( morphSampler, cMorphTargetTextureDim, cMorphSubrect, v.vVertexID, float3( 0, 0, 0 ), vPosition.xyz, vNormal ); +#endif + + // Normalize the flexed normal + vNormal.xyz = normalize( vNormal.xyz ); + + // Transform the position + float3 worldPos, worldNormal; + SkinPositionAndNormal( g_bSkinning, vPosition, vNormal, v.vBoneWeights, v.vBoneIndices, worldPos, worldNormal ); + +#if INTRO + float3 dummy = float3( 0.0f, 0.0f, 0.0f ); + WorldSpaceVertexProcess( g_Time, modelOrigin, worldPos, worldNormal, dummy, dummy ); +#endif + + // Transform into projection space + o.projPos = mul( float4( worldPos, 1 ), cViewProj ); + o.worldPos = worldPos.xyz; + o.vProjPos = o.projPos; +#if !defined( _X360 ) + // Set fixed-function fog factor + o.fog = CalcFog( worldPos, o.projPos, g_FogType ); +#endif + // Spotlight texture coordinates + o.spotTexCoord.x = dot( cSpotlightProj1, float4(worldPos, 1) ); + o.spotTexCoord.y = dot( cSpotlightProj2, float4(worldPos, 1) ); + o.spotTexCoord.z = dot( cSpotlightProj3, float4(worldPos, 1) ); + o.spotTexCoord.w = dot( cSpotlightProj4, float4(worldPos, 1) ); + + // Compute vector to light + float3 vWorldPosToLightVector = cFlashlightPosition.xyz - worldPos; + + float3 vDistAtten = float3(1, 1, 1); + vDistAtten.z = dot( vWorldPosToLightVector, vWorldPosToLightVector ); + vDistAtten.y = rsqrt( vDistAtten.z ); + + float flDist = vDistAtten.z * vDistAtten.y; // Distance to light + vDistAtten.z = 1.0f / vDistAtten.z; // 1 / distsquared + + float fFarZ = cFlashlighAtten.w; + + float NdotL = saturate( dot( worldNormal, normalize( vWorldPosToLightVector ) ) ); + + float endFalloffFactor = RemapValClamped_01( flDist, fFarZ, 0.6 * fFarZ ); + o.vertAtten.xyz = endFalloffFactor * dot( vDistAtten, cFlashlighAtten.xyz ); + + // Final attenuation from flashlight only... + float linearAtten = NdotL * dot( vDistAtten, cFlashlighAtten.xyz ) * endFalloffFactor; + + // Forward vector + float3 vForward = cTeethLighting.xyz; + float fIllumFactor = cTeethLighting.w; + + // Modulate flashlight by mouth darkening + o.vertAtten = linearAtten * fIllumFactor * saturate( dot( worldNormal, vForward ) ); + + o.baseTexCoord = v.vTexCoord0; + + return o; +} + + diff --git a/materialsystem/stdshaders/teeth_ps2x.fxc b/materialsystem/stdshaders/teeth_ps2x.fxc new file mode 100644 index 0000000..4893f9a --- /dev/null +++ b/materialsystem/stdshaders/teeth_ps2x.fxc @@ -0,0 +1,48 @@ +//====== Copyright © 1996-2004, Valve Corporation, All rights reserved. ======= +// +// Purpose: +// +//============================================================================= + +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps30][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX] + +// DYNAMIC: "PIXELFOGTYPE" "0..1" +// DYNAMIC: "WRITE_DEPTH_TO_DESTALPHA" "0..1" [ps20b] [PC] +// DYNAMIC: "WRITE_DEPTH_TO_DESTALPHA" "0..0" [ps20b] [XBOX] +// DYNAMIC: "WRITE_DEPTH_TO_DESTALPHA" "0..1" [ps30] + + +#if defined( SHADER_MODEL_PS_2_0 ) +# define WRITE_DEPTH_TO_DESTALPHA 0 +#endif + +#include "common_ps_fxc.h" +#include "shader_constant_register_map.h" + +sampler BaseTextureSampler : register( s0 ); + +const float4 g_FogParams : register( PSREG_FOG_PARAMS ); +const float4 g_EyePos_SpecExponent : register( PSREG_EYEPOS_SPEC_EXPONENT ); + +struct PS_INPUT +{ + float2 baseTexCoord : TEXCOORD0; + float3 vertAtten : TEXCOORD1; + + float4 worldPos_projPosZ : TEXCOORD7; // Necessary for pixel fog +}; + +float4 main( PS_INPUT i ) : COLOR +{ + float4 baseSample = tex2D( BaseTextureSampler, i.baseTexCoord ); + + float4 result; + result.xyz = baseSample.xyz * i.vertAtten; + result.a = baseSample.a; + + + float fogFactor = CalcPixelFogFactor( PIXELFOGTYPE, g_FogParams, g_EyePos_SpecExponent.z, i.worldPos_projPosZ.z, i.worldPos_projPosZ.w ); + return FinalOutput( result, fogFactor, PIXELFOGTYPE, TONEMAP_SCALE_LINEAR, (WRITE_DEPTH_TO_DESTALPHA != 0), i.worldPos_projPosZ.w ); +} diff --git a/materialsystem/stdshaders/teeth_vs20.fxc b/materialsystem/stdshaders/teeth_vs20.fxc new file mode 100644 index 0000000..9a9ab04 --- /dev/null +++ b/materialsystem/stdshaders/teeth_vs20.fxc @@ -0,0 +1,127 @@ +//======= Copyright © 1996-2006, Valve Corporation, All rights reserved. ====== + +// STATIC: "INTRO" "0..1" +// STATIC: "USE_STATIC_CONTROL_FLOW" "0..1" [vs20] + +// DYNAMIC: "COMPRESSED_VERTS" "0..1" +// DYNAMIC: "DOWATERFOG" "0..1" +// DYNAMIC: "SKINNING" "0..1" +// DYNAMIC: "DYNAMIC_LIGHT" "0..1" +// DYNAMIC: "STATIC_LIGHT" "0..1" +// DYNAMIC: "MORPHING" "0..1" [vs30] +// DYNAMIC: "NUM_LIGHTS" "0..2" [vs20] + +// If using static control flow on Direct3D, we should use the NUM_LIGHTS=0 combo +// SKIP: $USE_STATIC_CONTROL_FLOW && ( $NUM_LIGHTS > 0 ) [vs20] + +#include "vortwarp_vs20_helper.h" + +static const int g_FogType = DOWATERFOG; +static const bool g_bSkinning = SKINNING ? true : false; + +const float4 cTeethLighting : register( SHADER_SPECIFIC_CONST_0 ); +#if INTRO +const float4 const4 : register( SHADER_SPECIFIC_CONST_1 ); +#define g_Time const4.w +#define modelOrigin const4.xyz +#endif + +#ifdef SHADER_MODEL_VS_3_0 +// NOTE: cMorphTargetTextureDim.xy = target dimensions, +// cMorphTargetTextureDim.z = 4tuples/morph +const float3 cMorphTargetTextureDim : register( SHADER_SPECIFIC_CONST_6 ); +const float4 cMorphSubrect : register( SHADER_SPECIFIC_CONST_7 ); + +sampler2D morphSampler : register( D3DVERTEXTEXTURESAMPLER0, s0 ); +#endif + +struct VS_INPUT +{ + // This is all of the stuff that we ever use. + float4 vPos : POSITION; + float4 vBoneWeights : BLENDWEIGHT; + float4 vBoneIndices : BLENDINDICES; + float4 vNormal : NORMAL; + float2 vTexCoord0 : TEXCOORD0; + + // Position and normal/tangent deltas + float3 vPosFlex : POSITION1; + float3 vNormalFlex : NORMAL1; +#ifdef SHADER_MODEL_VS_3_0 + float vVertexID : POSITION2; +#endif +}; + +struct VS_OUTPUT +{ + float4 projPos : POSITION; +#if !defined( _X360 ) + float fog : FOG; +#endif + float2 baseTexCoord : TEXCOORD0; + float3 vertAtten : TEXCOORD1; + + float4 worldPos_projPosZ : TEXCOORD7; // Necessary for pixel fog +}; + +VS_OUTPUT main( const VS_INPUT v ) +{ + VS_OUTPUT o = ( VS_OUTPUT )0; + + bool bDynamicLight = DYNAMIC_LIGHT ? true : false; + bool bStaticLight = STATIC_LIGHT ? true : false; + + float4 vPosition = v.vPos; + float3 vNormal; + DecompressVertex_Normal( v.vNormal, vNormal ); + +#if !defined( SHADER_MODEL_VS_3_0 ) || !MORPHING + ApplyMorph( v.vPosFlex, v.vNormalFlex, vPosition.xyz, vNormal ); +#else + ApplyMorph( morphSampler, cMorphTargetTextureDim, cMorphSubrect, v.vVertexID, float3( 0, 0, 0 ), vPosition.xyz, vNormal ); +#endif + + // Normalize the flexed normal + vNormal.xyz = normalize( vNormal.xyz ); + + // Transform the position + float3 worldPos, worldNormal; + SkinPositionAndNormal( g_bSkinning, vPosition, vNormal, v.vBoneWeights, v.vBoneIndices, worldPos, worldNormal ); + +#if INTRO + float3 dummy = float3( 0.0f, 0.0f, 0.0f ); + WorldSpaceVertexProcess( g_Time, modelOrigin, worldPos, worldNormal, dummy, dummy ); +#endif + + // Transform into projection space + float4 vProjPos = mul( float4( worldPos, 1 ), cViewProj ); + o.projPos = vProjPos; + vProjPos.z = dot( float4( worldPos, 1 ), cViewProjZ ); + + o.worldPos_projPosZ = float4( worldPos.xyz, vProjPos.z ); +#if !defined( _X360 ) + // Set fixed-function fog factor + o.fog = CalcFog( worldPos, vProjPos, g_FogType ); +#endif + + // Compute lighting +#if ( USE_STATIC_CONTROL_FLOW ) || defined ( SHADER_MODEL_VS_3_0 ) + float3 linearColor = DoLighting( worldPos, worldNormal, float3(0.0f, 0.0f, 0.0f), bStaticLight, bDynamicLight, false ); +#else + float3 linearColor = DoLightingUnrolled( worldPos, worldNormal, float3(0.0f, 0.0f, 0.0f), bStaticLight, bDynamicLight, false, NUM_LIGHTS ); +#endif + + // Forward vector + float3 vForward = cTeethLighting.xyz; + float fIllumFactor = cTeethLighting.w; + + // Darken by forward dot normal and illumination factor + linearColor *= fIllumFactor * saturate( dot( worldNormal, vForward ) ); + + o.vertAtten = linearColor; + o.baseTexCoord = v.vTexCoord0; + + return o; +} + + diff --git a/materialsystem/stdshaders/unlitgeneric_basetimesdetail.psh b/materialsystem/stdshaders/unlitgeneric_basetimesdetail.psh new file mode 100644 index 0000000..563845d --- /dev/null +++ b/materialsystem/stdshaders/unlitgeneric_basetimesdetail.psh @@ -0,0 +1,24 @@ +ps.1.1 +def c0,0,0,0,.1 +def c1,0,0,0,.1 +;------------------------------------------------------------------------------ +; Draw a texture . . woo hoo! +; t0 - texture +; +; The texture coordinates need to be defined as follows: +; tc0 - texcoords +; tc3 - detail texcoords +; +; c3 = outline color +;------------------------------------------------------------------------------ + +tex t0 ; base color +tex t3 ; detail mask + +mul r1,t0,t3 ; multiply + +mov r0.rgb, c3 ; color = outline color +;add r0.a, r1.a, c0.a +;cnd r0.rgb, r0.a, r0, r1 ; if ( alpha+c0 > 0.5 ) color = outline, else color = base +sub r0.a, r1.a, c1.a +cnd r0.rgb, r0.a, r1, r0 ; if ( alpha -c1 > 0.5) color=base diff --git a/materialsystem/stdshaders/unlitgeneric_dx6.cpp b/materialsystem/stdshaders/unlitgeneric_dx6.cpp new file mode 100644 index 0000000..fc8bdf4 --- /dev/null +++ b/materialsystem/stdshaders/unlitgeneric_dx6.cpp @@ -0,0 +1,310 @@ +//========= 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" + +DEFINE_FALLBACK_SHADER( UnlitGeneric, UnlitGeneric_DX6 ) +DEFINE_FALLBACK_SHADER( MonitorScreen, UnlitGeneric_DX6 ) +DEFINE_FALLBACK_SHADER( ParticleSphere, UnlitGeneric_DX6 ) +DEFINE_FALLBACK_SHADER( Predator, Predator_DX60 ) +DEFINE_FALLBACK_SHADER( Predator_DX60, UnlitGeneric_DX6 ) +DEFINE_FALLBACK_SHADER( WindowImposter, WindowImposter_DX60 ) +DEFINE_FALLBACK_SHADER( WindowImposter_DX60, UnlitGeneric_DX6 ) + +BEGIN_SHADER( UnlitGeneric_DX6, + "Help for UnlitGeneric_DX6" ) + + BEGIN_SHADER_PARAMS + SHADER_PARAM( DETAIL, SHADER_PARAM_TYPE_TEXTURE, "shadertest/detail", "detail texture" ) + SHADER_PARAM( DETAILSCALE, SHADER_PARAM_TYPE_FLOAT, "4", "scale of the detail texture" ) + SHADER_PARAM( ENVMAP, SHADER_PARAM_TYPE_TEXTURE, "shadertest/shadertest_env", "envmap" ) + SHADER_PARAM( ENVMAPFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "" ) + SHADER_PARAM( ENVMAPMASK, SHADER_PARAM_TYPE_TEXTURE, "shadertest/shadertest_envmask", "envmap mask" ) + SHADER_PARAM( ENVMAPMASKFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "" ) + SHADER_PARAM( ENVMAPMASKSCALE, SHADER_PARAM_TYPE_FLOAT, "1", "envmap mask scale" ) + SHADER_PARAM( ENVMAPTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "envmap tint" ) + SHADER_PARAM( ENVMAPOPTIONAL, SHADER_PARAM_TYPE_BOOL, "0", "Make the envmap only apply to dx9 and higher hardware" ) + SHADER_PARAM( ALPHATESTREFERENCE, SHADER_PARAM_TYPE_FLOAT, "0.7", "" ) + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + if( !params[ENVMAPTINT]->IsDefined() ) + params[ENVMAPTINT]->SetVecValue( 1.0f, 1.0f, 1.0f ); + if( !params[ENVMAPMASKSCALE]->IsDefined() ) + params[ENVMAPMASKSCALE]->SetFloatValue( 1.0f ); + if( !params[DETAILSCALE]->IsDefined() ) + params[DETAILSCALE]->SetFloatValue( 4.0f ); + + // No texture means no env mask in base alpha + if ( !params[BASETEXTURE]->IsDefined() ) + { + CLEAR_FLAGS( MATERIAL_VAR_BASEALPHAENVMAPMASK ); + } + + // If in decal mode, no debug override... + if (IS_FLAG_SET(MATERIAL_VAR_DECAL)) + { + SET_FLAGS( MATERIAL_VAR_NO_DEBUG_OVERRIDE ); + } + + // Get rid of the envmap if it's optional for this dx level. + if( params[ENVMAPOPTIONAL]->IsDefined() && params[ENVMAPOPTIONAL]->GetIntValue() ) + { + params[ENVMAP]->SetUndefined(); + } + + // If mat_specular 0, then get rid of envmap + if( !g_pConfig->UseSpecular() && params[ENVMAP]->IsDefined() && params[BASETEXTURE]->IsDefined() ) + { + params[ENVMAP]->SetUndefined(); + } + } + + SHADER_INIT + { + if (params[BASETEXTURE]->IsDefined()) + { + LoadTexture( BASETEXTURE ); + + if (!params[BASETEXTURE]->GetTextureValue()->IsTranslucent()) + { + if (IS_FLAG_SET(MATERIAL_VAR_BASEALPHAENVMAPMASK)) + CLEAR_FLAGS( MATERIAL_VAR_BASEALPHAENVMAPMASK ); + } + } + + // the second texture (if there is one) + if (params[DETAIL]->IsDefined()) + { + LoadTexture( DETAIL ); + } + + // Don't alpha test if the alpha channel is used for other purposes + if (IS_FLAG_SET(MATERIAL_VAR_SELFILLUM) || IS_FLAG_SET(MATERIAL_VAR_BASEALPHAENVMAPMASK) ) + CLEAR_FLAGS( MATERIAL_VAR_ALPHATEST ); + + if (params[ENVMAP]->IsDefined()) + { + if( !IS_FLAG_SET(MATERIAL_VAR_ENVMAPSPHERE) ) + LoadCubeMap( ENVMAP ); + else + LoadTexture( ENVMAP ); + + if( !g_pHardwareConfig->SupportsCubeMaps() ) + SET_FLAGS(MATERIAL_VAR_ENVMAPSPHERE); + + if (params[ENVMAPMASK]->IsDefined()) + { + LoadTexture( ENVMAPMASK ); + } + } + } + + int GetDrawFlagsPass1(IMaterialVar** params, bool doDetail) + { + int flags = SHADER_DRAW_POSITION; + if (IS_FLAG_SET(MATERIAL_VAR_VERTEXCOLOR)) + flags |= SHADER_DRAW_COLOR; + if (params[BASETEXTURE]->IsTexture()) + flags |= SHADER_DRAW_TEXCOORD0; + if (doDetail) + flags |= SHADER_DRAW_TEXCOORD1; + return flags; + } + + void SetDetailShadowState(IShaderShadow* pShaderShadow) + { + // Specifically choose overbright2, will cause mod2x here + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + pShaderShadow->OverbrightValue( SHADER_TEXTURE_STAGE1, 2.0f ); + } + + void SetDetailDymamicState(IShaderShadow* pShaderShadow) + { + BindTexture( SHADER_SAMPLER1, DETAIL, FRAME ); + SetFixedFunctionTextureScaledTransform( MATERIAL_TEXTURE1, BASETEXTURETRANSFORM, DETAILSCALE ); + } + + void DrawAdditiveNonTextured( IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow, bool doDetail ) + { + SHADOW_STATE + { + SetModulationShadowState(); + SetAdditiveBlendingShadowState( ); + if (doDetail) + SetDetailShadowState(pShaderShadow); + pShaderShadow->DrawFlags( GetDrawFlagsPass1(params, doDetail) ); + FogToBlack(); + } + DYNAMIC_STATE + { + SetModulationDynamicState(); + if (doDetail) + SetDetailDymamicState(pShaderShadow); + } + Draw( ); + } + + void DrawAdditiveTextured( IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow, bool doDetail ) + { + SHADOW_STATE + { + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + SetModulationShadowState(); + SetAdditiveBlendingShadowState( BASETEXTURE, true ); + if (doDetail) + SetDetailShadowState(pShaderShadow); + pShaderShadow->DrawFlags( GetDrawFlagsPass1(params, doDetail) ); + FogToBlack(); + } + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME ); + SetFixedFunctionTextureTransform( MATERIAL_TEXTURE0, BASETEXTURETRANSFORM ); + if (doDetail) + SetDetailDymamicState(pShaderShadow); + SetModulationDynamicState(); + } + Draw( ); + } + + void DrawNonTextured( IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow, bool doDetail ) + { + SHADOW_STATE + { + SetModulationShadowState(); + SetNormalBlendingShadowState( ); + if (doDetail) + SetDetailShadowState(pShaderShadow); + pShaderShadow->DrawFlags( GetDrawFlagsPass1(params, doDetail) ); + FogToFogColor(); + } + DYNAMIC_STATE + { + SetModulationDynamicState(); + if (doDetail) + SetDetailDymamicState(pShaderShadow); + } + Draw( ); + } + + void DrawTextured( IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow, bool doDetail ) + { + SHADOW_STATE + { + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + SetModulationShadowState(); + SetNormalBlendingShadowState( BASETEXTURE, true ); + if (doDetail) + SetDetailShadowState(pShaderShadow); + pShaderShadow->DrawFlags( GetDrawFlagsPass1(params, doDetail) ); + FogToFogColor(); + } + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME ); + SetFixedFunctionTextureTransform( MATERIAL_TEXTURE0, BASETEXTURETRANSFORM ); + if (doDetail) + SetDetailDymamicState(pShaderShadow); + SetModulationDynamicState(); + } + Draw( ); + } + + SHADER_DRAW + { + bool isTextureDefined = params[BASETEXTURE]->IsTexture(); + bool hasVertexColor = IS_FLAG_SET(MATERIAL_VAR_VERTEXCOLOR); + bool doFirstPass = isTextureDefined || hasVertexColor || (!params[ENVMAP]->IsTexture()); + + if (doFirstPass) + { + SHADOW_STATE + { + pShaderShadow->EnableAlphaTest( IS_FLAG_SET(MATERIAL_VAR_ALPHATEST) ); + if( params[ALPHATESTREFERENCE]->IsDefined() && params[ALPHATESTREFERENCE]->GetFloatValue() > 0.0f ) + { + pShaderShadow->AlphaFunc( SHADER_ALPHAFUNC_GEQUAL, params[ALPHATESTREFERENCE]->GetFloatValue() ); + } + } + + if (IS_FLAG_SET(MATERIAL_VAR_ADDITIVE)) + { + if (!isTextureDefined) + { + bool hasDetailTexture = params[DETAIL]->IsTexture(); + DrawAdditiveNonTextured( params, pShaderAPI, pShaderShadow, hasDetailTexture ); + } + else + { + // We can't do detail in a single pass if we're also + // colormodulating and have vertex color + bool hasDetailTexture = params[DETAIL]->IsTexture(); + bool isModulating = IsColorModulating() || IsAlphaModulating(); + bool onePassDetail = hasDetailTexture && (!hasVertexColor || !isModulating); + DrawAdditiveTextured( params, pShaderAPI, pShaderShadow, onePassDetail ); + if (hasDetailTexture && !onePassDetail) + { + FixedFunctionMultiplyByDetailPass( + BASETEXTURE, FRAME, BASETEXTURETRANSFORM, DETAIL, DETAILSCALE ); + } + } + } + else + { + if (!isTextureDefined) + { + bool hasDetailTexture = params[DETAIL]->IsTexture(); + DrawNonTextured( params, pShaderAPI, pShaderShadow, hasDetailTexture ); + } + else + { + // We can't do detail in a single pass if we're also + // colormodulating and have vertex color + bool hasDetailTexture = params[DETAIL]->IsTexture(); + bool isModulating = IsColorModulating() || IsAlphaModulating(); + bool onePassDetail = hasDetailTexture && (!hasVertexColor || !isModulating); + DrawTextured( params, pShaderAPI, pShaderShadow, onePassDetail ); + if (hasDetailTexture && !onePassDetail) + { + FixedFunctionMultiplyByDetailPass( + BASETEXTURE, FRAME, BASETEXTURETRANSFORM, DETAIL, DETAILSCALE ); + } + } + } + } + + SHADOW_STATE + { + // Disable mod2x used by detail + pShaderShadow->OverbrightValue( SHADER_TEXTURE_STAGE1, 1.0f ); + } + + // Second pass... + if (params[ENVMAP]->IsTexture() && + (!doFirstPass || IS_FLAG_SET(MATERIAL_VAR_MULTIPASS)) ) + { + if (doFirstPass || IS_FLAG_SET(MATERIAL_VAR_ADDITIVE)) + { + FixedFunctionAdditiveMaskedEnvmapPass( ENVMAP, ENVMAPMASK, BASETEXTURE, + ENVMAPFRAME, ENVMAPMASKFRAME, FRAME, + BASETEXTURETRANSFORM, ENVMAPMASKSCALE, ENVMAPTINT ); + } + else + { + FixedFunctionMaskedEnvmapPass( ENVMAP, ENVMAPMASK, BASETEXTURE, + ENVMAPFRAME, ENVMAPMASKFRAME, FRAME, + BASETEXTURETRANSFORM, ENVMAPMASKSCALE, ENVMAPTINT ); + } + } + } +END_SHADER diff --git a/materialsystem/stdshaders/unlitgeneric_dx8.cpp b/materialsystem/stdshaders/unlitgeneric_dx8.cpp new file mode 100644 index 0000000..19d0e16 --- /dev/null +++ b/materialsystem/stdshaders/unlitgeneric_dx8.cpp @@ -0,0 +1,72 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $Header: $ +// $NoKeywords: $ +//=============================================================================// + +#include "BaseVSShader.h" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +DEFINE_FALLBACK_SHADER( UnlitGeneric, UnlitGeneric_DX8 ) + +BEGIN_VS_SHADER( UnlitGeneric_DX8, + "Help for UnlitGeneric_DX8" ) + + BEGIN_SHADER_PARAMS + SHADER_PARAM( DETAIL, SHADER_PARAM_TYPE_TEXTURE, "shadertest/detail", "detail texture" ) + SHADER_PARAM( DETAILSCALE, SHADER_PARAM_TYPE_FLOAT, "4", "scale of the detail texture" ) + SHADER_PARAM( ENVMAP, SHADER_PARAM_TYPE_TEXTURE, "shadertest/shadertest_env", "envmap" ) + SHADER_PARAM( ENVMAPFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "" ) + SHADER_PARAM( ENVMAPMASK, SHADER_PARAM_TYPE_TEXTURE, "shadertest/shadertest_envmask", "envmap mask" ) + SHADER_PARAM( ENVMAPMASKFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "" ) + SHADER_PARAM( ENVMAPMASKSCALE, SHADER_PARAM_TYPE_FLOAT, "1", "envmap mask scale" ) + SHADER_PARAM( ENVMAPTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "envmap tint" ) + SHADER_PARAM( ENVMAPOPTIONAL, SHADER_PARAM_TYPE_BOOL, "0", "Make the envmap only apply to dx9 and higher hardware" ) + SHADER_PARAM( DETAILBLENDMODE, SHADER_PARAM_TYPE_INTEGER, "0", "mode for combining detail texture with base. 0=normal, 1= additive, 2=alpha blend detail over base, 3=crossfade" ) + SHADER_PARAM( ALPHATESTREFERENCE, SHADER_PARAM_TYPE_FLOAT, "0.7", "" ) + SHADER_PARAM( OUTLINE, SHADER_PARAM_TYPE_BOOL, "0", "Enable outline for distance coded textures.") + SHADER_PARAM( OUTLINECOLOR, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "color of outline for distance coded images." ) + SHADER_PARAM( OUTLINESTART0, SHADER_PARAM_TYPE_FLOAT, "0.0", "outer start value for outline") + SHADER_PARAM( OUTLINESTART1, SHADER_PARAM_TYPE_FLOAT, "0.0", "inner start value for outline") + SHADER_PARAM( OUTLINEEND0, SHADER_PARAM_TYPE_FLOAT, "0.0", "inner end value for outline") + SHADER_PARAM( OUTLINEEND1, SHADER_PARAM_TYPE_FLOAT, "0.0", "outer end value for outline") + SHADER_PARAM( SEPARATEDETAILUVS, SHADER_PARAM_TYPE_INTEGER, "0", "" ) + END_SHADER_PARAMS + + SHADER_FALLBACK + { + if ( IsPC() && !g_pHardwareConfig->SupportsVertexAndPixelShaders()) + { + return "UnlitGeneric_DX6"; + } + return 0; + } + + SHADER_INIT_PARAMS() + { + InitParamsUnlitGeneric_DX8( + BASETEXTURE, DETAILSCALE, ENVMAPOPTIONAL, + ENVMAP, ENVMAPTINT, ENVMAPMASKSCALE, + DETAILBLENDMODE ); + } + + SHADER_INIT + { + InitUnlitGeneric_DX8( BASETEXTURE, DETAIL, ENVMAP, ENVMAPMASK ); + } + + SHADER_DRAW + { + VertexShaderUnlitGenericPass( + BASETEXTURE, FRAME, BASETEXTURETRANSFORM, + DETAIL, DETAILSCALE, true, ENVMAP, ENVMAPFRAME, ENVMAPMASK, + ENVMAPMASKFRAME, ENVMAPMASKSCALE, ENVMAPTINT, ALPHATESTREFERENCE, + DETAILBLENDMODE, + OUTLINE, OUTLINECOLOR, OUTLINESTART0, OUTLINEEND1, SEPARATEDETAILUVS ); + } +END_SHADER + diff --git a/materialsystem/stdshaders/unlitgeneric_dx9.cpp b/materialsystem/stdshaders/unlitgeneric_dx9.cpp new file mode 100644 index 0000000..b57474a --- /dev/null +++ b/materialsystem/stdshaders/unlitgeneric_dx9.cpp @@ -0,0 +1,200 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $Header: $ +// $NoKeywords: $ +//===========================================================================// + +#include "BaseVSShader.h" +#include "vertexlitgeneric_dx9_helper.h" + +extern ConVar r_flashlight_version2; + +BEGIN_VS_SHADER( UnlitGeneric, "Help for UnlitGeneric" ) + + BEGIN_SHADER_PARAMS + SHADER_PARAM( ALBEDO, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "albedo (Base texture with no baked lighting)" ) + SHADER_PARAM( DETAIL, SHADER_PARAM_TYPE_TEXTURE, "shadertest/detail", "detail texture" ) + SHADER_PARAM( DETAILFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $detail" ) + SHADER_PARAM( DETAILSCALE, SHADER_PARAM_TYPE_FLOAT, "4", "scale of the detail texture" ) + SHADER_PARAM( ENVMAP, SHADER_PARAM_TYPE_TEXTURE, "shadertest/shadertest_env", "envmap" ) + SHADER_PARAM( ENVMAPFRAME, SHADER_PARAM_TYPE_INTEGER, "", "envmap frame number" ) + SHADER_PARAM( ENVMAPMASK, SHADER_PARAM_TYPE_TEXTURE, "shadertest/shadertest_envmask", "envmap mask" ) + SHADER_PARAM( ENVMAPMASKFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "" ) + SHADER_PARAM( ENVMAPMASKTRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$envmapmask texcoord transform" ) + SHADER_PARAM( ENVMAPTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "envmap tint" ) + SHADER_PARAM( ENVMAPCONTRAST, SHADER_PARAM_TYPE_FLOAT, "0.0", "contrast 0 == normal 1 == color*color" ) + SHADER_PARAM( ENVMAPSATURATION, SHADER_PARAM_TYPE_FLOAT, "1.0", "saturation 0 == greyscale 1 == normal" ) + SHADER_PARAM( ALPHATESTREFERENCE, SHADER_PARAM_TYPE_FLOAT, "0.7", "" ) + SHADER_PARAM( VERTEXALPHATEST, SHADER_PARAM_TYPE_INTEGER, "0", "" ) + SHADER_PARAM( HDRCOLORSCALE, SHADER_PARAM_TYPE_FLOAT, "1.0", "hdr color scale" ) + SHADER_PARAM( PHONGEXPONENT, SHADER_PARAM_TYPE_FLOAT, "5.0", "Phong exponent for local specular lights" ) + SHADER_PARAM( PHONGTINT, SHADER_PARAM_TYPE_VEC3, "5.0", "Phong tint for local specular lights" ) + SHADER_PARAM( PHONGALBEDOTINT, SHADER_PARAM_TYPE_BOOL, "1.0", "Apply tint by albedo (controlled by spec exponent texture" ) + SHADER_PARAM( LIGHTWARPTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "1D ramp texture for tinting scalar diffuse term" ) + SHADER_PARAM( PHONGWARPTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "2D map for warping specular" ) + SHADER_PARAM( PHONGFRESNELRANGES, SHADER_PARAM_TYPE_VEC3, "[0 0.5 1]", "Parameters for remapping fresnel output" ) + SHADER_PARAM( PHONGBOOST, SHADER_PARAM_TYPE_FLOAT, "1.0", "Phong overbrightening factor (specular mask channel should be authored to account for this)" ) + SHADER_PARAM( PHONGEXPONENTTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "Phong Exponent map" ) + SHADER_PARAM( PHONG, SHADER_PARAM_TYPE_BOOL, "0", "enables phong lighting" ) + SHADER_PARAM( DETAILBLENDMODE, SHADER_PARAM_TYPE_INTEGER, "0", "mode for combining detail texture with base. 0=normal, 1= additive, 2=alpha blend detail over base, 3=crossfade" ) + SHADER_PARAM( DETAILBLENDFACTOR, SHADER_PARAM_TYPE_FLOAT, "1", "blend amount for detail texture." ) + SHADER_PARAM( DETAILTEXTURETRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$detail texcoord transform" ) + + SHADER_PARAM( SELFILLUMMASK, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "If we bind a texture here, it overrides base alpha (if any) for self illum" ) + + SHADER_PARAM( DISTANCEALPHA, SHADER_PARAM_TYPE_BOOL, "0", "Use distance-coded alpha generated from hi-res texture by vtex.") + SHADER_PARAM( DISTANCEALPHAFROMDETAIL, SHADER_PARAM_TYPE_BOOL, "0", "Take the distance-coded alpha mask from the detail texture.") + + SHADER_PARAM( SOFTEDGES, SHADER_PARAM_TYPE_BOOL, "0", "Enable soft edges to distance coded textures.") + SHADER_PARAM( SCALEEDGESOFTNESSBASEDONSCREENRES, SHADER_PARAM_TYPE_BOOL, "0", "Scale the size of the soft edges based upon resolution. 1024x768 = nominal.") + SHADER_PARAM( EDGESOFTNESSSTART, SHADER_PARAM_TYPE_FLOAT, "0.6", "Start value for soft edges for distancealpha."); + SHADER_PARAM( EDGESOFTNESSEND, SHADER_PARAM_TYPE_FLOAT, "0.5", "End value for soft edges for distancealpha."); + + SHADER_PARAM( GLOW, SHADER_PARAM_TYPE_BOOL, "0", "Enable glow/shadow for distance coded textures.") + SHADER_PARAM( GLOWCOLOR, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "color of outter glow for distance coded line art." ) + SHADER_PARAM( GLOWALPHA, SHADER_PARAM_TYPE_FLOAT, "1", "Base glow alpha amount for glows/shadows with distance alpha." ) + SHADER_PARAM( GLOWSTART, SHADER_PARAM_TYPE_FLOAT, "0.7", "start value for glow/shadow") + SHADER_PARAM( GLOWEND, SHADER_PARAM_TYPE_FLOAT, "0.5", "end value for glow/shadow") + SHADER_PARAM( GLOWX, SHADER_PARAM_TYPE_FLOAT, "0", "texture offset x for glow mask.") + SHADER_PARAM( GLOWY, SHADER_PARAM_TYPE_FLOAT, "0", "texture offset y for glow mask.") + + SHADER_PARAM( OUTLINE, SHADER_PARAM_TYPE_BOOL, "0", "Enable outline for distance coded textures.") + SHADER_PARAM( OUTLINECOLOR, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "color of outline for distance coded images." ) + SHADER_PARAM( OUTLINEALPHA, SHADER_PARAM_TYPE_FLOAT, "0.0", "alpha value for outline") + SHADER_PARAM( OUTLINESTART0, SHADER_PARAM_TYPE_FLOAT, "0.0", "outer start value for outline") + SHADER_PARAM( OUTLINESTART1, SHADER_PARAM_TYPE_FLOAT, "0.0", "inner start value for outline") + SHADER_PARAM( OUTLINEEND0, SHADER_PARAM_TYPE_FLOAT, "0.0", "inner end value for outline") + SHADER_PARAM( OUTLINEEND1, SHADER_PARAM_TYPE_FLOAT, "0.0", "outer end value for outline") + SHADER_PARAM( SCALEOUTLINESOFTNESSBASEDONSCREENRES, SHADER_PARAM_TYPE_BOOL, "0", "Scale the size of the soft part of the outline based upon resolution. 1024x768 = nominal.") + + SHADER_PARAM( SEPARATEDETAILUVS, SHADER_PARAM_TYPE_BOOL, "0", "Use texcoord1 for detail texture" ) + + SHADER_PARAM( GAMMACOLORREAD, SHADER_PARAM_TYPE_INTEGER, "0", "Disables SRGB conversion of color texture read." ) + SHADER_PARAM( LINEARWRITE, SHADER_PARAM_TYPE_INTEGER, "0", "Disables SRGB conversion of shader results." ) + + SHADER_PARAM( DEPTHBLEND, SHADER_PARAM_TYPE_INTEGER, "0", "fade at intersection boundaries" ) + SHADER_PARAM( DEPTHBLENDSCALE, SHADER_PARAM_TYPE_FLOAT, "50.0", "Amplify or reduce DEPTHBLEND fading. Lower values make harder edges." ) + SHADER_PARAM( RECEIVEFLASHLIGHT, SHADER_PARAM_TYPE_INTEGER, "0", "Forces this material to receive flashlights." ) + + END_SHADER_PARAMS + + void SetupVars( VertexLitGeneric_DX9_Vars_t& info ) + { + info.m_nBaseTexture = BASETEXTURE; + info.m_nBaseTextureFrame = FRAME; + info.m_nBaseTextureTransform = BASETEXTURETRANSFORM; + info.m_nAlbedo = ALBEDO; + info.m_nSelfIllumTint = -1; + info.m_nDetail = DETAIL; + info.m_nDetailFrame = DETAILFRAME; + info.m_nDetailScale = DETAILSCALE; + info.m_nDetailTextureCombineMode = DETAILBLENDMODE; + info.m_nDetailTextureBlendFactor = DETAILBLENDFACTOR; + info.m_nDetailTextureTransform = DETAILTEXTURETRANSFORM; + + info.m_nEnvmap = ENVMAP; + info.m_nEnvmapFrame = ENVMAPFRAME; + info.m_nEnvmapMask = ENVMAPMASK; + info.m_nEnvmapMaskFrame = ENVMAPMASKFRAME; + info.m_nEnvmapMaskTransform = ENVMAPMASKTRANSFORM; + info.m_nEnvmapTint = ENVMAPTINT; + info.m_nBumpmap = -1; + info.m_nBumpFrame = -1; + info.m_nBumpTransform = -1; + info.m_nEnvmapContrast = ENVMAPCONTRAST; + info.m_nEnvmapSaturation = ENVMAPSATURATION; + info.m_nAlphaTestReference = ALPHATESTREFERENCE; + info.m_nVertexAlphaTest = VERTEXALPHATEST; + info.m_nFlashlightTexture = FLASHLIGHTTEXTURE; + info.m_nFlashlightTextureFrame = FLASHLIGHTTEXTUREFRAME; + info.m_nHDRColorScale = HDRCOLORSCALE; + info.m_nPhongExponent = -1; + info.m_nPhongExponentTexture = -1; + info.m_nDiffuseWarpTexture = -1; + info.m_nPhongWarpTexture = -1; + info.m_nPhongBoost = -1; + info.m_nPhongFresnelRanges = -1; + info.m_nPhong = -1; + info.m_nPhongTint = -1; + info.m_nPhongAlbedoTint = -1; + info.m_nSelfIllumEnvMapMask_Alpha = -1; + info.m_nAmbientOnly = -1; + info.m_nBaseMapAlphaPhongMask = -1; + info.m_nEnvmapFresnel = -1; + info.m_nSelfIllumMask = -1; + + info.m_nDistanceAlpha = DISTANCEALPHA; + info.m_nDistanceAlphaFromDetail = DISTANCEALPHAFROMDETAIL; + info.m_nSoftEdges = SOFTEDGES; + info.m_nEdgeSoftnessStart = EDGESOFTNESSSTART; + info.m_nEdgeSoftnessEnd = EDGESOFTNESSEND; + info.m_nScaleEdgeSoftnessBasedOnScreenRes = SCALEEDGESOFTNESSBASEDONSCREENRES; + + info.m_nGlow = GLOW; + info.m_nGlowColor = GLOWCOLOR; + info.m_nGlowAlpha = GLOWALPHA; + info.m_nGlowStart = GLOWSTART; + info.m_nGlowEnd = GLOWEND; + info.m_nGlowX = GLOWX; + info.m_nGlowY = GLOWY; + + info.m_nOutline = OUTLINE; + info.m_nOutlineColor = OUTLINECOLOR; + info.m_nOutlineAlpha = OUTLINEALPHA; + info.m_nOutlineStart0 = OUTLINESTART0; + info.m_nOutlineStart1 = OUTLINESTART1; + info.m_nOutlineEnd0 = OUTLINEEND0; + info.m_nOutlineEnd1 = OUTLINEEND1; + info.m_nScaleOutlineSoftnessBasedOnScreenRes = SCALEOUTLINESOFTNESSBASEDONSCREENRES; + + info.m_nSeparateDetailUVs = SEPARATEDETAILUVS; + + info.m_nLinearWrite = LINEARWRITE; + info.m_nGammaColorRead = GAMMACOLORREAD; + + info.m_nDepthBlend = DEPTHBLEND; + info.m_nDepthBlendScale = DEPTHBLENDSCALE; + info.m_nReceiveFlashlight = RECEIVEFLASHLIGHT; + } + + SHADER_INIT_PARAMS() + { + VertexLitGeneric_DX9_Vars_t vars; + SetupVars( vars ); + InitParamsVertexLitGeneric_DX9( this, params, pMaterialName, false, vars ); + } + + SHADER_FALLBACK + { + if( g_pHardwareConfig->GetDXSupportLevel() < 90 ) + { + return "UnlitGeneric_DX8"; + } + return 0; + } + + SHADER_INIT + { + VertexLitGeneric_DX9_Vars_t vars; + SetupVars( vars ); + InitVertexLitGeneric_DX9( this, params, false, vars ); + } + + SHADER_DRAW + { + VertexLitGeneric_DX9_Vars_t vars; + SetupVars( vars ); + + bool bNewFlashlightPath = IsX360() || ( r_flashlight_version2.GetInt() != 0 ); + if ( ( pShaderShadow == NULL ) && ( pShaderAPI != NULL ) && !bNewFlashlightPath && pShaderAPI->InFlashlightMode() ) // Not snapshotting && flashlight pass + { + Draw( false ); + } + else + { + DrawVertexLitGeneric_DX9( this, params, pShaderAPI, pShaderShadow, false, vars, vertexCompression, pContextDataPtr ); + } + } +END_SHADER diff --git a/materialsystem/stdshaders/unlitgeneric_inc.vsh b/materialsystem/stdshaders/unlitgeneric_inc.vsh new file mode 100644 index 0000000..ac2abb7 --- /dev/null +++ b/materialsystem/stdshaders/unlitgeneric_inc.vsh @@ -0,0 +1,142 @@ +#include "macros.vsh" + +;------------------------------------------------------------------------------ +; $SHADER_SPECIFIC_CONST_0-$SHADER_SPECIFIC_CONST_1 = Base texture transform +; $SHADER_SPECIFIC_CONST_2-$SHADER_SPECIFIC_CONST_3 = Mask texture transform +; $SHADER_SPECIFIC_CONST_4-$SHADER_SPECIFIC_CONST_5 = Detail texture transform +;------------------------------------------------------------------------------ + +sub UnlitGeneric +{ + local( $detail ) = shift; + local( $envmap ) = shift; + local( $envmapcameraspace ) = shift; + local( $envmapsphere ) = shift; + local( $vertexcolor ) = shift; + local( $separatedetailuvs ) = shift; + + local( $worldPos, $worldNormal, $projPos, $reflectionVector ); + + ;------------------------------------------------------------------------------ + ; Vertex blending + ;------------------------------------------------------------------------------ + &AllocateRegister( \$worldPos ); + if( $envmap ) + { + &AllocateRegister( \$worldNormal ); + &SkinPositionAndNormal( $worldPos, $worldNormal ); + } + else + { + &SkinPosition( $worldPos ); + } + + ;------------------------------------------------------------------------------ + ; Transform the position from world to proj space + ;------------------------------------------------------------------------------ + + &AllocateRegister( \$projPos ); + + dp4 $projPos.x, $worldPos, $cViewProj0 + dp4 $projPos.y, $worldPos, $cViewProj1 + dp4 $projPos.z, $worldPos, $cViewProj2 + dp4 $projPos.w, $worldPos, $cViewProj3 + mov oPos, $projPos + + ;------------------------------------------------------------------------------ + ; Fog + ;------------------------------------------------------------------------------ + &CalcFog( $worldPos, $projPos ); + &FreeRegister( \$projPos ); + + if( !$envmap ) + { + &FreeRegister( \$worldPos ); + } + + ;------------------------------------------------------------------------------ + ; Texture coordinates (use world-space normal for envmap, tex transform for mask) + ;------------------------------------------------------------------------------ + dp4 oT0.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_0 + dp4 oT0.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_1 + if ( $g_x360 ) + { + ; must write xyzw to match read in pixelshader + mov oT0.zw, $cZero + } + + if( $envmap ) + { + if( $envmapcameraspace ) + { + &AllocateRegister( \$reflectionVector ); + &ComputeReflectionVector( $worldPos, $worldNormal, $reflectionVector ); + + ; transform reflection vector into view space + dp3 oT1.x, $reflectionVector, $cViewModel0 + dp3 oT1.y, $reflectionVector, $cViewModel1 + dp3 oT1.z, $reflectionVector, $cViewModel2 + if ( $g_x360 ) + { + ; must write xyzw to match read in pixelshader + mov oT1.w, $cZero + } + + &FreeRegister( \$reflectionVector ); + } + elsif( $envmapsphere ) + { + &AllocateRegister( \$reflectionVector ); + &ComputeReflectionVector( $worldPos, $worldNormal, $reflectionVector ); + &ComputeSphereMapTexCoords( $reflectionVector, "oT1" ); + + &FreeRegister( \$reflectionVector ); + } + else + { + &ComputeReflectionVector( $worldPos, $worldNormal, "oT1" ); + } + + ; envmap mask + dp4 oT2.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_2 + dp4 oT2.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_3 + if ( $g_x360 ) + { + ; must write xyzw to match read in pixelshader + mov oT2.zw, $cZero + } + + &FreeRegister( \$worldPos ); + &FreeRegister( \$worldNormal ); + } + + if( $detail ) + { + if ( $separatedetailuvs ) + { + mov oT3, $vTexCoord1 + } + else + { + dp4 oT3.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_4 + dp4 oT3.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_5 + } + + if ( $g_x360 ) + { + ; must write xyzw to match read in pixelshader + mov oT3.zw, $cZero + } + } + + if( $vertexcolor ) + { + ; Modulation color + mul oD0, $vColor, $cModulationColor + } + else + { + ; Modulation color + mov oD0, $cModulationColor + } +} diff --git a/materialsystem/stdshaders/unlitgeneric_lightingonly_vs11.fxc b/materialsystem/stdshaders/unlitgeneric_lightingonly_vs11.fxc new file mode 100644 index 0000000..dcbd43a --- /dev/null +++ b/materialsystem/stdshaders/unlitgeneric_lightingonly_vs11.fxc @@ -0,0 +1,47 @@ +// DYNAMIC: "DOWATERFOG" "0..1" +// DYNAMIC: "SKINNING" "0..1" + +#include "common_vs_fxc.h" + +static const int g_FogType = DOWATERFOG; +static const bool g_bSkinning = SKINNING ? true : false; + +struct VS_INPUT +{ + float4 vPos : POSITION; + float4 vBoneWeights : BLENDWEIGHT; + float4 vBoneIndices : BLENDINDICES; +}; + +struct VS_OUTPUT +{ + float4 vProjPos : POSITION; + + float4 vDiffuse : COLOR0; + + float4 fogFactorW : COLOR1; + +#if !defined( _X360 ) + float fog : FOG; +#endif +}; + + +VS_OUTPUT main( const VS_INPUT v ) +{ + VS_OUTPUT o = ( VS_OUTPUT )0; + + float3 worldPos; + SkinPosition( g_bSkinning, v.vPos, v.vBoneWeights, v.vBoneIndices, worldPos ); + + o.vProjPos = mul( float4( worldPos, 1 ), cViewProj ); + + o.fogFactorW = CalcFog( worldPos, o.vProjPos, g_FogType ); +#if !defined( _X360 ) + o.fog = o.fogFactorW; +#endif + + o.vDiffuse = 1.0f; + + return o; +} \ No newline at end of file diff --git a/materialsystem/stdshaders/unlitgeneric_notexture_ps11.fxc b/materialsystem/stdshaders/unlitgeneric_notexture_ps11.fxc new file mode 100644 index 0000000..e3970e8 --- /dev/null +++ b/materialsystem/stdshaders/unlitgeneric_notexture_ps11.fxc @@ -0,0 +1,9 @@ +struct PS_INPUT +{ + float4 vColor0 : COLOR0; +}; + +float4 main( PS_INPUT i ) : COLOR +{ + return i.vColor0; +} \ No newline at end of file diff --git a/materialsystem/stdshaders/unlitgeneric_notexture_ps2x.fxc b/materialsystem/stdshaders/unlitgeneric_notexture_ps2x.fxc new file mode 100644 index 0000000..e4fffb8 --- /dev/null +++ b/materialsystem/stdshaders/unlitgeneric_notexture_ps2x.fxc @@ -0,0 +1,14 @@ +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX] + +#include "common_ps_fxc.h" + +struct PS_INPUT +{ + float4 vColor0 : COLOR0; +}; + +float4 main( PS_INPUT i ) : COLOR +{ + return FinalOutput( i.vColor0, 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE ); +} \ No newline at end of file diff --git a/materialsystem/stdshaders/unlitgeneric_ps11.fxc b/materialsystem/stdshaders/unlitgeneric_ps11.fxc new file mode 100644 index 0000000..071d666 --- /dev/null +++ b/materialsystem/stdshaders/unlitgeneric_ps11.fxc @@ -0,0 +1,12 @@ +sampler TextureSampler : register( s0 ); + +struct PS_INPUT +{ + float4 vColor0 : COLOR0; + float2 vTexCoord0 : TEXCOORD0; +}; + +float4 main( PS_INPUT i ) : COLOR +{ + return i.vColor0 * tex2D( TextureSampler, i.vTexCoord0 ); +} \ No newline at end of file diff --git a/materialsystem/stdshaders/unlitgeneric_ps2x.fxc b/materialsystem/stdshaders/unlitgeneric_ps2x.fxc new file mode 100644 index 0000000..1620638 --- /dev/null +++ b/materialsystem/stdshaders/unlitgeneric_ps2x.fxc @@ -0,0 +1,19 @@ +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX] + +#include "common_ps_fxc.h" + +sampler TextureSampler : register( s0 ); + +struct PS_INPUT +{ + float4 vColor0 : COLOR0; + float2 vTexCoord0 : TEXCOORD0; +}; + +float4 main( PS_INPUT i ) : COLOR +{ + float4 result = i.vColor0 * tex2D( TextureSampler, i.vTexCoord0 ); + + return FinalOutput( result, 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE ); +} \ No newline at end of file diff --git a/materialsystem/stdshaders/unlitgeneric_vs11.vsh b/materialsystem/stdshaders/unlitgeneric_vs11.vsh new file mode 100644 index 0000000..b165fa7 --- /dev/null +++ b/materialsystem/stdshaders/unlitgeneric_vs11.vsh @@ -0,0 +1,23 @@ +vs.1.1 + +# STATIC: "DETAIL" "0..1" +# STATIC: "ENVMAP" "0..1" +# STATIC: "ENVMAPCAMERASPACE" "0..0" +# STATIC: "ENVMAPSPHERE" "0..1" +# STATIC: "VERTEXCOLOR" "0..1" +# STATIC: "SEPARATEDETAILUVS" "0..1" +# DYNAMIC: "DOWATERFOG" "0..1" +# DYNAMIC: "SKINNING" "0..1" + +# can't have envmapshere or envmapcameraspace without envmap +# SKIP: !$ENVMAP && ( $ENVMAPSPHERE || $ENVMAPCAMERASPACE ) + +# can't have both envmapsphere and envmapcameraspace +# SKIP: $ENVMAPSPHERE && $ENVMAPCAMERASPACE + +# SKIP: !$DETAIL && $SEPARATEDETAILUVS + + +#include "UnlitGeneric_inc.vsh" + +&UnlitGeneric( $DETAIL, $ENVMAP, $ENVMAPCAMERASPACE, $ENVMAPSPHERE, $VERTEXCOLOR, $SEPARATEDETAILUVS ); diff --git a/materialsystem/stdshaders/unlitgeneric_vs20.fxc b/materialsystem/stdshaders/unlitgeneric_vs20.fxc new file mode 100644 index 0000000..3724930 --- /dev/null +++ b/materialsystem/stdshaders/unlitgeneric_vs20.fxc @@ -0,0 +1,91 @@ +// STATIC: "VERTEXCOLOR" "0..1" +// DYNAMIC: "COMPRESSED_VERTS" "0..1" +// DYNAMIC: "DOWATERFOG" "0..1" +// DYNAMIC: "SKINNING" "0..1" + +#include "common_vs_fxc.h" + +static const int g_FogType = DOWATERFOG; +static const bool g_bSkinning = SKINNING ? true : false; + +const float4 cBaseTextureTransform[2] : register( SHADER_SPECIFIC_CONST_0 ); +const float4 cMaskTextureTransform[2] : register( SHADER_SPECIFIC_CONST_2 ); +const float4 cDetailTextureTransform[2] : register( SHADER_SPECIFIC_CONST_4 ); +const float4 g_vVertexColor : register( SHADER_SPECIFIC_CONST_6 ); + +struct VS_INPUT +{ + float4 vPos : POSITION; + float4 vBoneWeights : BLENDWEIGHT; + float4 vBoneIndices : BLENDINDICES; + float4 vNormal : NORMAL; + +#if VERTEXCOLOR + float4 vColor : COLOR0; +#endif + + float4 vTexCoord0 : TEXCOORD0; +}; + +struct VS_OUTPUT +{ + float4 vProjPos : POSITION; + float2 vTexCoord0 : TEXCOORD0; + float2 vTexCoord1 : TEXCOORD1; + float2 vTexCoord2 : TEXCOORD2; + float2 vTexCoord3 : TEXCOORD3; + + float4 vColor : COLOR0; + float4 fogFactorW : COLOR1; + +#if !defined( _X360 ) + float fog : FOG; +#endif + + float4 worldPos_projPosZ : TEXCOORD7; // Necessary for pixel fog +}; + + +VS_OUTPUT main( const VS_INPUT v ) +{ + VS_OUTPUT o = ( VS_OUTPUT )0; + + float3 worldPos; + float3 worldNormal; + + //------------------------------------------------------------------------------ + // Vertex blending + //------------------------------------------------------------------------------ + SkinPosition( g_bSkinning, v.vPos, v.vBoneWeights, v.vBoneIndices, worldPos ); + + float4 vProjPos = mul( float4( worldPos, 1 ), cViewProj ); + o.vProjPos = vProjPos; + vProjPos = dot( float4( worldPos, 1 ), cViewProjZ ); + o.worldPos_projPosZ = float4( worldPos.xyz, vProjPos.z ); + + //------------------------------------------------------------------------------ + // Fog + //------------------------------------------------------------------------------ + o.fogFactorW = CalcFog( worldPos, vProjPos, g_FogType ); +#if !defined( _X360 ) + o.fog = o.fogFactorW; +#endif + + //------------------------------------------------------------------------------ + // Texture coord transforms + //------------------------------------------------------------------------------ + o.vTexCoord0 = mul( v.vTexCoord0, (float2x4)cBaseTextureTransform ); + o.vTexCoord3 = mul( v.vTexCoord0, (float2x4)cDetailTextureTransform ); + + o.vColor = cModulationColor; + +#if VERTEXCOLOR + // 0 or 1 for g_vVertexColor.x, eliminating a bool + o.vColor = lerp( o.vColor, o.vColor * v.vColor, g_vVertexColor.x ); +#endif + + return o; +} + + + diff --git a/materialsystem/stdshaders/unlittwotexture_dx6.cpp b/materialsystem/stdshaders/unlittwotexture_dx6.cpp new file mode 100644 index 0000000..f7158e4 --- /dev/null +++ b/materialsystem/stdshaders/unlittwotexture_dx6.cpp @@ -0,0 +1,85 @@ +//========= 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" + +DEFINE_FALLBACK_SHADER( UnlitTwoTexture, UnlitTwoTexture_DX6 ) + +BEGIN_SHADER( UnlitTwoTexture_DX6, + "Help for UnlitTwoTexture_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 ); + } + else + { + DisableAlphaBlending( ); + } + } + + pShaderShadow->DrawFlags( SHADER_DRAW_POSITION | SHADER_DRAW_TEXCOORD0 | + SHADER_DRAW_TEXCOORD1 ); + DefaultFog(); + } + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME ); + SetFixedFunctionTextureTransform( MATERIAL_TEXTURE0, BASETEXTURETRANSFORM ); + BindTexture( SHADER_SAMPLER1, TEXTURE2, FRAME2 ); + SetFixedFunctionTextureTransform( MATERIAL_TEXTURE1, TEXTURE2TRANSFORM ); + SetModulationDynamicState(); + } + Draw(); + } +END_SHADER diff --git a/materialsystem/stdshaders/unlittwotexture_dx8.cpp b/materialsystem/stdshaders/unlittwotexture_dx8.cpp new file mode 100644 index 0000000..b44afa6 --- /dev/null +++ b/materialsystem/stdshaders/unlittwotexture_dx8.cpp @@ -0,0 +1,222 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $Header: $ +// $NoKeywords: $ +//=============================================================================// + +#include "BaseVSShader.h" + +#include "unlittwotexture.inc" +#include "cloak_blended_pass_helper.h" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +DEFINE_FALLBACK_SHADER( UnlitTwoTexture, UnlitTwoTexture_DX8 ) + +BEGIN_VS_SHADER( UnlitTwoTexture_DX8, "Help for UnlitTwoTexture" ) + + 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" ) + + // Cloak Pass + SHADER_PARAM( CLOAKPASSENABLED, SHADER_PARAM_TYPE_BOOL, "0", "Enables cloak render in a second pass" ) + SHADER_PARAM( CLOAKFACTOR, SHADER_PARAM_TYPE_FLOAT, "0.0", "" ) + SHADER_PARAM( CLOAKCOLORTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "Cloak color tint" ) + SHADER_PARAM( REFRACTAMOUNT, SHADER_PARAM_TYPE_FLOAT, "2", "" ) + END_SHADER_PARAMS + + SHADER_FALLBACK + { + if ( !g_pHardwareConfig->SupportsVertexAndPixelShaders()) + { + return "UnlitTwoTexture_DX6"; + } + return 0; + } + + // Cloak Pass + void SetupVarsCloakBlendedPass( CloakBlendedPassVars_t &info ) + { + info.m_nCloakFactor = CLOAKFACTOR; + info.m_nCloakColorTint = CLOAKCOLORTINT; + info.m_nRefractAmount = REFRACTAMOUNT; + } + + bool NeedsPowerOfTwoFrameBufferTexture( IMaterialVar **params, bool bCheckSpecificToThisFrame ) const + { + if ( params[CLOAKPASSENABLED]->GetIntValue() ) // If material supports cloaking + { + if ( bCheckSpecificToThisFrame == false ) // For setting model flag at load time + return true; + else if ( ( params[CLOAKFACTOR]->GetFloatValue() > 0.0f ) && ( params[CLOAKFACTOR]->GetFloatValue() < 1.0f ) ) // Per-frame check + return true; + // else, not cloaking this frame, so check flag2 in case the base material still needs it + } + + // Check flag2 if not drawing cloak pass + return IS_FLAG2_SET( MATERIAL_VAR2_NEEDS_POWER_OF_TWO_FRAME_BUFFER_TEXTURE ); + } + + bool IsTranslucent( IMaterialVar **params ) const + { + if ( params[CLOAKPASSENABLED]->GetIntValue() ) // If material supports cloaking + { + if ( ( params[CLOAKFACTOR]->GetFloatValue() > 0.0f ) && ( params[CLOAKFACTOR]->GetFloatValue() < 1.0f ) ) // Per-frame check + return true; + // else, not cloaking this frame, so check flag in case the base material still needs it + } + + // Check flag if not drawing cloak pass + return IS_FLAG_SET( MATERIAL_VAR_TRANSLUCENT ); + } + + SHADER_INIT_PARAMS() + { + SET_FLAGS2( MATERIAL_VAR2_SUPPORTS_HW_SKINNING ); + + // Cloak Pass + if ( !params[CLOAKPASSENABLED]->IsDefined() ) + { + params[CLOAKPASSENABLED]->SetIntValue( 0 ); + } + else if ( params[CLOAKPASSENABLED]->GetIntValue() ) + { + CloakBlendedPassVars_t info; + SetupVarsCloakBlendedPass( info ); + InitParamsCloakBlendedPass( this, params, pMaterialName, info ); + } + } + + SHADER_INIT + { + if (params[BASETEXTURE]->IsDefined()) + LoadTexture( BASETEXTURE ); + if (params[TEXTURE2]->IsDefined()) + LoadTexture( TEXTURE2 ); + + // Cloak Pass + if ( params[CLOAKPASSENABLED]->GetIntValue() ) + { + CloakBlendedPassVars_t info; + SetupVarsCloakBlendedPass( info ); + InitCloakBlendedPass( this, params, info ); + } + } + + SHADER_DRAW + { + // Skip the standard rendering if cloak pass is fully opaque + bool bDrawStandardPass = true; + if ( params[CLOAKPASSENABLED]->GetIntValue() && ( pShaderShadow == NULL ) ) // && not snapshotting + { + CloakBlendedPassVars_t info; + SetupVarsCloakBlendedPass( info ); + if ( CloakBlendedPassIsFullyOpaque( params, info ) ) + { + // There is some strangeness in DX8 when trying to skip the main pass, so leave this alone for now + //bDrawStandardPass = false; + } + } + + // Standard rendering pass + if ( bDrawStandardPass ) + { + SHADOW_STATE + { + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + + // 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 ); + } + else + { + DisableAlphaBlending( ); + } + } + + int fmt = VERTEX_POSITION | VERTEX_NORMAL; + if (IS_FLAG_SET( MATERIAL_VAR_VERTEXCOLOR )) + { + fmt |= VERTEX_COLOR; + } + + pShaderShadow->VertexShaderVertexFormat( fmt, 1, 0, 0 ); + + unlittwotexture_Static_Index vshIndex; + pShaderShadow->SetVertexShader( "UnlitTwoTexture", vshIndex.GetIndex() ); + + pShaderShadow->SetPixelShader( "UnlitTwoTexture" ); + DefaultFog(); + } + DYNAMIC_STATE + { + if ( pShaderAPI->InFlashlightMode() ) // Not snapshotting && flashlight pass + { + Draw( false ); + return; + } + + BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME ); + BindTexture( SHADER_SAMPLER1, TEXTURE2, FRAME2 ); + SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, BASETEXTURETRANSFORM ); + SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_2, TEXTURE2TRANSFORM ); + SetModulationVertexShaderDynamicState(); + + unlittwotexture_Dynamic_Index vshIndex; + vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + vshIndex.SetSKINNING( pShaderAPI->GetCurrentNumBones() > 0 ); + pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() ); + } + Draw(); + } + else + { + // Skip this pass! + Draw( false ); + } + + // Cloak Pass + if ( params[CLOAKPASSENABLED]->GetIntValue() ) + { + // If ( snapshotting ) or ( we need to draw this frame ) + if ( ( pShaderShadow != NULL ) || ( ( params[CLOAKFACTOR]->GetFloatValue() > 0.0f ) && ( params[CLOAKFACTOR]->GetFloatValue() < 1.0f ) ) ) + { + CloakBlendedPassVars_t info; + SetupVarsCloakBlendedPass( info ); + DrawCloakBlendedPass( this, params, pShaderAPI, pShaderShadow, info, vertexCompression ); + } + else // We're not snapshotting and we don't need to draw this frame + { + // Skip this pass! + Draw( false ); + } + } + } +END_SHADER diff --git a/materialsystem/stdshaders/unlittwotexture_dx9.cpp b/materialsystem/stdshaders/unlittwotexture_dx9.cpp new file mode 100644 index 0000000..a966a8b --- /dev/null +++ b/materialsystem/stdshaders/unlittwotexture_dx9.cpp @@ -0,0 +1,280 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $Header: $ +// $NoKeywords: $ +//===========================================================================// + +#include "BaseVSShader.h" +#include "cloak_blended_pass_helper.h" +#include "cpp_shader_constant_register_map.h" + +#include "unlittwotexture_vs20.inc" +#include "unlittwotexture_ps20.inc" +#include "unlittwotexture_ps20b.inc" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +DEFINE_FALLBACK_SHADER( UnlitTwoTexture, UnlitTwoTexture_DX9 ) + +extern ConVar r_flashlight_version2; + +BEGIN_VS_SHADER( UnlitTwoTexture_DX9, "Help for UnlitTwoTexture_DX9" ) + + 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" ) + + // Cloak Pass + SHADER_PARAM( CLOAKPASSENABLED, SHADER_PARAM_TYPE_BOOL, "0", "Enables cloak render in a second pass" ) + SHADER_PARAM( CLOAKFACTOR, SHADER_PARAM_TYPE_FLOAT, "0.0", "" ) + SHADER_PARAM( CLOAKCOLORTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "Cloak color tint" ) + SHADER_PARAM( REFRACTAMOUNT, SHADER_PARAM_TYPE_FLOAT, "2", "" ) + END_SHADER_PARAMS + + SHADER_FALLBACK + { + if ( g_pHardwareConfig->GetDXSupportLevel() < 90) + { + return "UnlitTwoTexture_DX8"; + } + return 0; + } + + // Cloak Pass + void SetupVarsCloakBlendedPass( CloakBlendedPassVars_t &info ) + { + info.m_nCloakFactor = CLOAKFACTOR; + info.m_nCloakColorTint = CLOAKCOLORTINT; + info.m_nRefractAmount = REFRACTAMOUNT; + } + + bool NeedsPowerOfTwoFrameBufferTexture( IMaterialVar **params, bool bCheckSpecificToThisFrame ) const + { + if ( params[CLOAKPASSENABLED]->GetIntValue() ) // If material supports cloaking + { + if ( bCheckSpecificToThisFrame == false ) // For setting model flag at load time + return true; + else if ( ( params[CLOAKFACTOR]->GetFloatValue() > 0.0f ) && ( params[CLOAKFACTOR]->GetFloatValue() < 1.0f ) ) // Per-frame check + return true; + // else, not cloaking this frame, so check flag2 in case the base material still needs it + } + + // Check flag2 if not drawing cloak pass + return IS_FLAG2_SET( MATERIAL_VAR2_NEEDS_POWER_OF_TWO_FRAME_BUFFER_TEXTURE ); + } + + bool IsTranslucent( IMaterialVar **params ) const + { + if ( params[CLOAKPASSENABLED]->GetIntValue() ) // If material supports cloaking + { + if ( ( params[CLOAKFACTOR]->GetFloatValue() > 0.0f ) && ( params[CLOAKFACTOR]->GetFloatValue() < 1.0f ) ) // Per-frame check + return true; + // else, not cloaking this frame, so check flag in case the base material still needs it + } + + // Check flag if not drawing cloak pass + return IS_FLAG_SET( MATERIAL_VAR_TRANSLUCENT ); + } + + SHADER_INIT_PARAMS() + { + SET_FLAGS2( MATERIAL_VAR2_SUPPORTS_HW_SKINNING ); + + // Cloak Pass + if ( !params[CLOAKPASSENABLED]->IsDefined() ) + { + params[CLOAKPASSENABLED]->SetIntValue( 0 ); + } + else if ( params[CLOAKPASSENABLED]->GetIntValue() ) + { + CloakBlendedPassVars_t info; + SetupVarsCloakBlendedPass( info ); + InitParamsCloakBlendedPass( this, params, pMaterialName, info ); + } + } + + SHADER_INIT + { + if (params[BASETEXTURE]->IsDefined()) + LoadTexture( BASETEXTURE, TEXTUREFLAGS_SRGB ); + if (params[TEXTURE2]->IsDefined()) + LoadTexture( TEXTURE2, TEXTUREFLAGS_SRGB ); + + // Cloak Pass + if ( params[CLOAKPASSENABLED]->GetIntValue() ) + { + CloakBlendedPassVars_t info; + SetupVarsCloakBlendedPass( info ); + InitCloakBlendedPass( this, params, info ); + } + } + + SHADER_DRAW + { + // Skip the standard rendering if cloak pass is fully opaque + bool bDrawStandardPass = true; + if ( params[CLOAKPASSENABLED]->GetIntValue() && ( pShaderShadow == NULL ) ) // && not snapshotting + { + CloakBlendedPassVars_t info; + SetupVarsCloakBlendedPass( info ); + if ( CloakBlendedPassIsFullyOpaque( params, info ) ) + { + bDrawStandardPass = false; + } + } + + // Skip flashlight pass for unlit stuff + bool bNewFlashlightPath = IsX360() || ( r_flashlight_version2.GetInt() != 0 ); + if ( bDrawStandardPass && ( pShaderShadow == NULL ) && ( pShaderAPI != NULL ) && + !bNewFlashlightPath && ( pShaderAPI->InFlashlightMode() ) ) // not snapshotting && flashlight pass) + { + bDrawStandardPass = false; + } + + // Standard rendering pass + if ( bDrawStandardPass ) + { + BlendType_t nBlendType = EvaluateBlendRequirements( BASETEXTURE, true ); + bool bFullyOpaque = (nBlendType != BT_BLENDADD) && (nBlendType != BT_BLEND) && !IS_FLAG_SET(MATERIAL_VAR_ALPHATEST); //dest alpha is free for special use + + SHADOW_STATE + { + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, true ); + + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER1, true ); + + s_pShaderShadow->EnableSRGBWrite( true ); + + // 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 ); + } + else + { + DisableAlphaBlending( ); + } + } + + // Set stream format (note that this shader supports compression) + unsigned int flags = VERTEX_POSITION | VERTEX_NORMAL | VERTEX_FORMAT_COMPRESSED; + int nTexCoordCount = 1; + int userDataSize = 0; + if (IS_FLAG_SET( MATERIAL_VAR_VERTEXCOLOR )) + { + flags |= VERTEX_COLOR; + } + pShaderShadow->VertexShaderVertexFormat( flags, nTexCoordCount, NULL, userDataSize ); + + DECLARE_STATIC_VERTEX_SHADER( unlittwotexture_vs20 ); + SET_STATIC_VERTEX_SHADER( unlittwotexture_vs20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_STATIC_PIXEL_SHADER( unlittwotexture_ps20b ); + SET_STATIC_PIXEL_SHADER( unlittwotexture_ps20b ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( unlittwotexture_ps20 ); + SET_STATIC_PIXEL_SHADER( unlittwotexture_ps20 ); + } + + DefaultFog(); + + pShaderShadow->EnableAlphaWrites( bFullyOpaque ); + } + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME ); + BindTexture( SHADER_SAMPLER1, TEXTURE2, FRAME2 ); + SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, BASETEXTURETRANSFORM ); + SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_2, TEXTURE2TRANSFORM ); + SetModulationPixelShaderDynamicState_LinearColorSpace( 1 ); + + pShaderAPI->SetPixelShaderFogParams( PSREG_FOG_PARAMS ); + + float vEyePos_SpecExponent[4]; + pShaderAPI->GetWorldSpaceCameraPosition( vEyePos_SpecExponent ); + vEyePos_SpecExponent[3] = 0.0f; + pShaderAPI->SetPixelShaderConstant( PSREG_EYEPOS_SPEC_EXPONENT, vEyePos_SpecExponent, 1 ); + + MaterialFogMode_t fogType = pShaderAPI->GetSceneFogMode(); + int fogIndex = ( fogType == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ) ? 1 : 0; + int numBones = pShaderAPI->GetCurrentNumBones(); + + DECLARE_DYNAMIC_VERTEX_SHADER( unlittwotexture_vs20 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, numBones > 0 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( DOWATERFOG, fogIndex ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression ); + SET_DYNAMIC_VERTEX_SHADER( unlittwotexture_vs20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_DYNAMIC_PIXEL_SHADER( unlittwotexture_ps20b ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( WRITE_DEPTH_TO_DESTALPHA, bFullyOpaque && pShaderAPI->ShouldWriteDepthToDestAlpha() ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( LIGHTING_PREVIEW, + pShaderAPI->GetIntRenderingParameter(INT_RENDERPARM_ENABLE_FIXED_LIGHTING) ); + SET_DYNAMIC_PIXEL_SHADER( unlittwotexture_ps20b ); + } + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( unlittwotexture_ps20 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( LIGHTING_PREVIEW, + pShaderAPI->GetIntRenderingParameter(INT_RENDERPARM_ENABLE_FIXED_LIGHTING) ); + SET_DYNAMIC_PIXEL_SHADER( unlittwotexture_ps20 ); + } + } + Draw(); + } + else + { + // Skip this pass! + Draw( false ); + } + + // Cloak Pass + if ( params[CLOAKPASSENABLED]->GetIntValue() ) + { + // If ( snapshotting ) or ( we need to draw this frame ) + if ( ( pShaderShadow != NULL ) || ( ( params[CLOAKFACTOR]->GetFloatValue() > 0.0f ) && ( params[CLOAKFACTOR]->GetFloatValue() < 1.0f ) ) ) + { + CloakBlendedPassVars_t info; + SetupVarsCloakBlendedPass( info ); + DrawCloakBlendedPass( this, params, pShaderAPI, pShaderShadow, info, vertexCompression ); + } + else // We're not snapshotting and we don't need to draw this frame + { + // Skip this pass! + Draw( false ); + } + } + } +END_SHADER diff --git a/materialsystem/stdshaders/unlittwotexture_inc.vsh b/materialsystem/stdshaders/unlittwotexture_inc.vsh new file mode 100644 index 0000000..5575db2 --- /dev/null +++ b/materialsystem/stdshaders/unlittwotexture_inc.vsh @@ -0,0 +1,64 @@ + +#include "macros.vsh" + +sub UnlitTwoTexture +{ + local( $vertexcolor ) = shift; + + local( $worldPos, $projPos ); + + ;------------------------------------------------------------------------------ + ; Vertex blending + ;------------------------------------------------------------------------------ + &AllocateRegister( \$worldPos ); + &SkinPosition( $worldPos ); + + ;------------------------------------------------------------------------------ + ; Transform the position from world to proj space + ;------------------------------------------------------------------------------ + + &AllocateRegister( \$projPos ); + dp4 $projPos.x, $worldPos, $cViewProj0 + dp4 $projPos.y, $worldPos, $cViewProj1 + dp4 $projPos.z, $worldPos, $cViewProj2 + dp4 $projPos.w, $worldPos, $cViewProj3 + mov oPos, $projPos + + ;------------------------------------------------------------------------------ + ; Fog + ;------------------------------------------------------------------------------ + &CalcFog( $worldPos, $projPos ); + &FreeRegister( \$projPos ); + &FreeRegister( \$worldPos ); + + ;------------------------------------------------------------------------------ + ; Texture coordinates (use world-space normal for envmap, tex transform for mask) + ;------------------------------------------------------------------------------ + + dp4 oT0.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_0 + dp4 oT0.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_1 + if ( $g_x360 ) + { + ; must write xyzw to match read in pixelshader + mov oT0.zw, $cZero + } + + dp4 oT1.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_2 + dp4 oT1.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_3 + if ( $g_x360 ) + { + ; must write xyzw to match read in pixelshader + mov oT1.zw, $cZero + } + + if( $vertexcolor ) + { + ; Modulation color + mul oD0, $vColor, $cModulationColor + } + else + { + ; Modulation color + mov oD0, $cModulationColor + } +} \ No newline at end of file diff --git a/materialsystem/stdshaders/unlittwotexture_ps2x.fxc b/materialsystem/stdshaders/unlittwotexture_ps2x.fxc new file mode 100644 index 0000000..365bd25 --- /dev/null +++ b/materialsystem/stdshaders/unlittwotexture_ps2x.fxc @@ -0,0 +1,76 @@ +// DYNAMIC: "PIXELFOGTYPE" "0..1" +// DYNAMIC: "LIGHTING_PREVIEW" "0..2" [PC] +// DYNAMIC: "LIGHTING_PREVIEW" "0..0" [XBOX] +// DYNAMIC: "WRITE_DEPTH_TO_DESTALPHA" "0..1" [ps20b] [PC] +// DYNAMIC: "WRITE_DEPTH_TO_DESTALPHA" "0..0" [ps20b] [XBOX] + +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX] + +#if defined( SHADER_MODEL_PS_2_0 ) +# define WRITE_DEPTH_TO_DESTALPHA 0 +#endif + +#include "common_ps_fxc.h" +#include "shader_constant_register_map.h" + +const HALF4 g_DiffuseModulation : register( c1 ); +#if !FLASHLIGHT + // we don't use these with HDR. + const HALF3 g_EnvmapContrast : register( c2 ); + const HALF3 g_EnvmapSaturation : register( c3 ); +#endif + +const float4 g_FogParams : register( PSREG_FOG_PARAMS ); +const float4 g_EyePos_SpecExponent : register( PSREG_EYEPOS_SPEC_EXPONENT ); + +const float4 g_FlashlightAttenuationFactors : register( c22 ); +const HALF3 g_FlashlightPos : register( c23 ); +const float4x4 g_FlashlightWorldToTexture : register( c24 ); // through c27 + +sampler BaseTextureSampler : register( s0 ); +sampler BaseTextureSampler2 : register( s1 ); + +struct PS_INPUT +{ + float4 projPos : POSITION; // Projection-space position + HALF2 baseTexCoord : TEXCOORD0; // Base texture coordinate + HALF2 baseTexCoord2 : TEXCOORD1; // Base texture coordinate + float4 worldPos_projPosZ : TEXCOORD7; // Necessary for water fog dest alpha + float4 fogFactorW : COLOR1; + +#if defined( _X360 ) //matching pixel shader inputs to vertex shader outputs to avoid shader patches + float4 vColor : COLOR0; +#endif +}; + +#if LIGHTING_PREVIEW == 2 +LPREVIEW_PS_OUT main( PS_INPUT i ) : COLOR +#else +float4 main( PS_INPUT i ) : COLOR +#endif +{ + +#if LIGHTING_PREVIEW +# if LIGHTING_PREVIEW == 1 + return FinalOutput( float4( 0.0f, 0.0f, 0.0f, 1.0f ), 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_LINEAR ); +# else + LPREVIEW_PS_OUT ret; + float alpha = 1.0f; + ret.flags=float4(1,1,1,1); + ret.color=float4( 0.0f, 0.0f, 0.0f, alpha ); + ret.normal=float4( 0.0f, 0.0f, 1.0f, 1.0f ); + ret.position=float4( i.worldPos_projPosZ.xyz, alpha ); + return FinalOutput( ret, 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE ); +# endif +#else + HALF4 baseColor = tex2D( BaseTextureSampler, i.baseTexCoord.xy ); + HALF4 baseColor2 = tex2D( BaseTextureSampler2, i.baseTexCoord2.xy ); + HALF4 result = baseColor * baseColor2 * g_DiffuseModulation; + float alpha = 1.0f; + + float fogFactor = CalcPixelFogFactor( PIXELFOGTYPE, g_FogParams, g_EyePos_SpecExponent.z, i.worldPos_projPosZ.z, i.worldPos_projPosZ.w ); + return FinalOutput( float4( result.rgb, alpha ), fogFactor, PIXELFOGTYPE, TONEMAP_SCALE_LINEAR, (WRITE_DEPTH_TO_DESTALPHA != 0), i.worldPos_projPosZ.w ); +#endif +} + diff --git a/materialsystem/stdshaders/unlittwotexture_vs20.fxc b/materialsystem/stdshaders/unlittwotexture_vs20.fxc new file mode 100644 index 0000000..ea1f940 --- /dev/null +++ b/materialsystem/stdshaders/unlittwotexture_vs20.fxc @@ -0,0 +1,73 @@ +// DYNAMIC: "COMPRESSED_VERTS" "0..1" +// DYNAMIC: "DOWATERFOG" "0..1" +// DYNAMIC: "SKINNING" "0..1" + +#include "common_vs_fxc.h" + +static const bool g_bSkinning = SKINNING ? true : false; +static const int g_FogType = DOWATERFOG; + +const float4 cBaseTexCoordTransform[2] : register( SHADER_SPECIFIC_CONST_0 ); +const float4 cBaseTexCoordTransform2[2] : register( SHADER_SPECIFIC_CONST_2 ); + +struct VS_INPUT +{ + float4 vPos : POSITION; + float4 vBoneWeights : BLENDWEIGHT; + float4 vBoneIndices : BLENDINDICES; + // make these float2's and stick the [n n 0 1] in the dot math. + float4 vTexCoord0 : TEXCOORD0; +}; + +struct VS_OUTPUT +{ + float4 projPos : POSITION; // Projection-space position +#if !defined( _X360 ) + float fog : FOG; +#endif + HALF2 baseTexCoord : TEXCOORD0; // Base texture coordinate + HALF2 baseTexCoord2 : TEXCOORD1; // Base texture coordinate + float4 worldPos_projPosZ : TEXCOORD7; // Necessary for water fog dest alpha + + float4 vColor : COLOR0; + float4 fogFactorW : COLOR1; +}; + +VS_OUTPUT main( const VS_INPUT v ) +{ + VS_OUTPUT o = ( VS_OUTPUT )0; + + float4 vPosition = v.vPos; + + // Perform skinning + float3 worldNormal, worldPos; + SkinPosition( + g_bSkinning, + vPosition, + v.vBoneWeights, v.vBoneIndices, + worldPos ); + + // Transform into projection space + float4 vProjPos = mul( float4( worldPos, 1 ), cViewProj ); + o.projPos = vProjPos; + vProjPos.z = dot( float4( worldPos, 1 ), cViewProjZ ); + o.fogFactorW.w = CalcFog( worldPos, vProjPos, g_FogType ); +#if !defined( _X360 ) + o.fog = o.fogFactorW.w; +#endif + // Needed for water fog alpha; + // FIXME: we shouldn't have to compute this all thie time. + o.worldPos_projPosZ = float4( worldPos.xyz, vProjPos.z ); + + // Base texture coordinates + o.baseTexCoord.x = dot( v.vTexCoord0, cBaseTexCoordTransform[0] ); + o.baseTexCoord.y = dot( v.vTexCoord0, cBaseTexCoordTransform[1] ); + + // Base texture coordinates + o.baseTexCoord2.x = dot( v.vTexCoord0, cBaseTexCoordTransform2[0] ); + o.baseTexCoord2.y = dot( v.vTexCoord0, cBaseTexCoordTransform2[1] ); + + o.vColor = cModulationColor; + + return o; +} diff --git a/materialsystem/stdshaders/vertexlit_and_unlit_generic_bump_ps2x.fxc b/materialsystem/stdshaders/vertexlit_and_unlit_generic_bump_ps2x.fxc new file mode 100644 index 0000000..7768f47 --- /dev/null +++ b/materialsystem/stdshaders/vertexlit_and_unlit_generic_bump_ps2x.fxc @@ -0,0 +1,350 @@ +//======= Copyright © 1996-2008, Valve Corporation, All rights reserved. ====== + +// STATIC: "CUBEMAP" "0..1" +// STATIC: "DIFFUSELIGHTING" "0..1" +// STATIC: "LIGHTWARPTEXTURE" "0..1" +// STATIC: "SELFILLUM" "0..1" +// STATIC: "SELFILLUMFRESNEL" "0..1" +// STATIC: "NORMALMAPALPHAENVMAPMASK" "0..1" +// STATIC: "HALFLAMBERT" "0..1" +// STATIC: "FLASHLIGHT" "0..1" +// STATIC: "DETAILTEXTURE" "0..1" +// STATIC: "DETAIL_BLEND_MODE" "0..6" +// STATIC: "FLASHLIGHTDEPTHFILTERMODE" "0..2" [ps20b] [PC] +// STATIC: "FLASHLIGHTDEPTHFILTERMODE" "0..2" [ps30] [PC] +// STATIC: "FLASHLIGHTDEPTHFILTERMODE" "0..0" [ps20b] [XBOX] +// STATIC: "BLENDTINTBYBASEALPHA" "0..1" + +// DYNAMIC: "PIXELFOGTYPE" "0..1" [ps20] +// DYNAMIC: "WRITEWATERFOGTODESTALPHA" "0..1" [ps20] +// DYNAMIC: "NUM_LIGHTS" "0..2" [ps20] +// DYNAMIC: "NUM_LIGHTS" "0..4" [ps20b] +// DYNAMIC: "NUM_LIGHTS" "0..4" [ps30] +// DYNAMIC: "AMBIENT_LIGHT" "0..1" +// DYNAMIC: "FLASHLIGHTSHADOWS" "0..1" [ps20b] +// DYNAMIC: "FLASHLIGHTSHADOWS" "0..1" [ps30] [PC] + +// We don't use light combos when doing the flashlight +// SKIP: ( $FLASHLIGHT != 0 ) && ( $NUM_LIGHTS > 0 ) [PC] + +// We don't care about flashlight depth unless the flashlight is on +// SKIP: ( $FLASHLIGHT == 0 ) && ( $FLASHLIGHTSHADOWS == 1 ) [ps20b] +// SKIP: ( $FLASHLIGHT == 0 ) && ( $FLASHLIGHTSHADOWS == 1 ) [ps30] + +// Flashlight shadow filter mode is irrelevant if there is no flashlight +// SKIP: ( $FLASHLIGHT == 0 ) && ( $FLASHLIGHTDEPTHFILTERMODE != 0 ) [ps20b] +// SKIP: ( $FLASHLIGHT == 0 ) && ( $FLASHLIGHTDEPTHFILTERMODE != 0 ) [ps30] + +// SKIP: (! $DETAILTEXTURE) && ( $DETAIL_BLEND_MODE != 0 ) + +// Don't do diffuse warp on flashlight +// SKIP: ( $FLASHLIGHT == 1 ) && ( $LIGHTWARPTEXTURE == 1 ) [PC] + +// Only warp diffuse if we have it at all +// SKIP: ( $DIFFUSELIGHTING == 0 ) && ( $LIGHTWARPTEXTURE == 1 ) + +// Skip this since it blows ps20 instruction limits +// SKIP: ( $SELFILLUMFRESNEL == 1 ) && ( $LIGHTWARPTEXTURE == 1 ) + +// Only need self illum fresnel when self illum enabled +// SKIP: ( $SELFILLUM == 0 ) && ( $SELFILLUMFRESNEL == 1 ) +// SKIP: ( $FLASHLIGHT == 1 ) && ( $SELFILLUMFRESNEL == 1 ) [PC] +// SKIP: ( $FLASHLIGHT == 1 ) && ( $SELFILLUM == 1 ) [PC] +// SKIP: ( $SELFILLUMFRESNEL == 1 ) && ( $DETAILTEXTURE == 1 ) +// SKIP: ( $SELFILLUMFRESNEL == 1 ) && ( $NORMALMAPALPHAENVMAPMASK == 1 ) + +// BlendTintByBaseAlpha is incompatible with other interpretations of alpha +// SKIP: ($BLENDTINTBYBASEALPHA) && ($SELFILLUM) + +// Only _XBOX allows flashlight and cubemap in the current implementation +// SKIP: $FLASHLIGHT && $CUBEMAP [PC] + +// Meaningless combinations +// SKIP: $NORMALMAPALPHAENVMAPMASK && !$CUBEMAP + +#include "common_flashlight_fxc.h" +#include "common_vertexlitgeneric_dx9.h" + +const float4 g_EnvmapTint_TintReplaceFactor : register( c0 ); +const float4 g_DiffuseModulation : register( c1 ); +const float4 g_EnvmapContrast_ShadowTweaks : register( c2 ); +const float3 g_EnvmapSaturation : register( c3 ); +const float4 g_SelfIllumTint_and_BlendFactor : register( c4 ); +#define g_SelfIllumTint ( g_SelfIllumTint_and_BlendFactor.rgb) +#define g_DetailBlendFactor (g_SelfIllumTint_and_BlendFactor.w) + +const float3 cAmbientCube[6] : register( c5 ); + +// 11, 12 not used? +#if ( SELFILLUMFRESNEL == 1 ) + const float4 g_SelfIllumScaleBiasExpBrightness : register( c11 ); +#endif + +const float4 g_ShaderControls : register( c12 ); +#define g_fPixelFogType g_ShaderControls.x +#define g_fWriteDepthToAlpha g_ShaderControls.y +#define g_fWriteWaterFogToDestAlpha g_ShaderControls.z + + +// 2 registers each - 6 registers total +PixelShaderLightInfo cLightInfo[3] : register( c13 ); // through c18 + +const float3 g_EyePos : register( c20 ); +const float4 g_FogParams : register( c21 ); + +const float4 g_FlashlightAttenuationFactors : register( c22 ); +const float3 g_FlashlightPos : register( c23 ); +const float4x4 g_FlashlightWorldToTexture : register( c24 ); // through c27 + +sampler BaseTextureSampler : register( s0 ); +sampler EnvmapSampler : register( s1 ); +sampler DetailSampler : register( s2 ); +sampler BumpmapSampler : register( s3 ); +sampler EnvmapMaskSampler : register( s4 ); +sampler NormalizeSampler : register( s5 ); +sampler RandRotSampler : register( s6 ); // RandomRotation sampler +sampler FlashlightSampler : register( s7 ); +sampler ShadowDepthSampler : register( s8 ); // Flashlight shadow depth map sampler +sampler DiffuseWarpSampler : register( s9 ); // Lighting warp sampler (1D texture for diffuse lighting modification) + +struct PS_INPUT +{ + float4 baseTexCoord2_tangentSpaceVertToEyeVectorXY : TEXCOORD0; + float3 lightAtten : TEXCOORD1; + float4 worldVertToEyeVectorXYZ_tangentSpaceVertToEyeVectorZ : TEXCOORD2; + float3 vWorldNormal : TEXCOORD3; // World-space normal + float4 vWorldTangent : TEXCOORD4; +#if ((defined(SHADER_MODEL_PS_2_B) || defined(SHADER_MODEL_PS_3_0))) + float4 vProjPos : TEXCOORD5; +#else + float3 vWorldBinormal : TEXCOORD5; +#endif + float4 worldPos_projPosZ : TEXCOORD6; + float3 detailTexCoord_atten3 : TEXCOORD7; + float4 fogFactorW : COLOR1; + +#if defined( _X360 ) +#if FLASHLIGHT + float4 flashlightSpacePos : TEXCOORD8; +#endif +#endif +}; + +// Calculate both types of Fog and lerp to get result +float CalcPixelFogFactorConst( float fPixelFogType, const float4 fogParams, const float flEyePosZ, const float flWorldPosZ, const float flProjPosZ ) +{ + float fRangeFog = CalcRangeFog( flProjPosZ, fogParams.x, fogParams.z, fogParams.w ); + float fHeightFog = CalcWaterFogAlpha( fogParams.y, flEyePosZ, flWorldPosZ, flProjPosZ, fogParams.w ); + return lerp( fRangeFog, fHeightFog, fPixelFogType ); +} + +// Blend both types of Fog and lerp to get result +float3 BlendPixelFogConst( const float3 vShaderColor, float pixelFogFactor, const float3 vFogColor, float fPixelFogType ) +{ + pixelFogFactor = saturate( pixelFogFactor ); + float3 fRangeResult = lerp( vShaderColor.rgb, vFogColor.rgb, pixelFogFactor * pixelFogFactor ); //squaring the factor will get the middle range mixing closer to hardware fog + float3 fHeightResult = lerp( vShaderColor.rgb, vFogColor.rgb, saturate( pixelFogFactor ) ); + return lerp( fRangeResult, fHeightResult, fPixelFogType ); +} + +float4 FinalOutputConst( const float4 vShaderColor, float pixelFogFactor, float fPixelFogType, const int iTONEMAP_SCALE_TYPE, float fWriteDepthToDestAlpha, const float flProjZ ) +{ + float4 result = vShaderColor; + if( iTONEMAP_SCALE_TYPE == TONEMAP_SCALE_LINEAR ) + { + result.rgb *= LINEAR_LIGHT_SCALE; + } + else if( iTONEMAP_SCALE_TYPE == TONEMAP_SCALE_GAMMA ) + { + result.rgb *= GAMMA_LIGHT_SCALE; + } + + result.a = lerp( result.a, DepthToDestAlpha( flProjZ ), fWriteDepthToDestAlpha ); + + result.rgb = BlendPixelFogConst( result.rgb, pixelFogFactor, g_LinearFogColor.rgb, fPixelFogType ); + result.rgb = SRGBOutput( result.rgb ); //SRGB in pixel shader conversion + + return result; +} + +float4 main( PS_INPUT i ) : COLOR +{ + bool bCubemap = CUBEMAP ? true : false; + bool bDiffuseLighting = DIFFUSELIGHTING ? true : false; + bool bDoDiffuseWarp = LIGHTWARPTEXTURE ? true : false; + bool bSelfIllum = SELFILLUM ? true : false; + bool bSelfIllumFresnel = SELFILLUMFRESNEL ? true : false; + bool bNormalMapAlphaEnvmapMask = NORMALMAPALPHAENVMAPMASK ? true : false; + bool bHalfLambert = HALFLAMBERT ? true : false; + bool bFlashlight = (FLASHLIGHT!=0) ? true : false; + bool bAmbientLight = AMBIENT_LIGHT ? true : false; + bool bDetailTexture = DETAILTEXTURE ? true : false; + bool bBlendTintByBaseAlpha = BLENDTINTBYBASEALPHA ? true : false; + int nNumLights = NUM_LIGHTS; + +#if ((defined(SHADER_MODEL_PS_2_B) || defined(SHADER_MODEL_PS_3_0))) + float3 vWorldBinormal = cross( i.vWorldNormal.xyz, i.vWorldTangent.xyz ) * i.vWorldTangent.w; +#else + float3 vWorldBinormal = i.vWorldBinormal; +#endif + + // Unpack four light attenuations + float4 vLightAtten = float4( i.lightAtten, i.detailTexCoord_atten3.z ); + + float4 baseColor = float4( 1.0f, 1.0f, 1.0f, 1.0f ); + baseColor = tex2D( BaseTextureSampler, i.baseTexCoord2_tangentSpaceVertToEyeVectorXY.xy ); + +#if DETAILTEXTURE + float4 detailColor = tex2D( DetailSampler, i.detailTexCoord_atten3.xy ); + baseColor = TextureCombine( baseColor, detailColor, DETAIL_BLEND_MODE, g_DetailBlendFactor ); +#endif + + float specularFactor = 1.0f; + float4 normalTexel = tex2D( BumpmapSampler, i.baseTexCoord2_tangentSpaceVertToEyeVectorXY.xy ); + float3 tangentSpaceNormal = normalTexel * 2.0f - 1.0f; + + if ( bNormalMapAlphaEnvmapMask ) + specularFactor = normalTexel.a; + + float3 diffuseLighting = float3( 1.0f, 1.0f, 1.0f ); + + float3 worldSpaceNormal = float3( 0.0f, 0.0f, 1.0f ); + if ( bDiffuseLighting || bFlashlight || bCubemap || bSelfIllumFresnel ) + { + worldSpaceNormal = Vec3TangentToWorld( tangentSpaceNormal, i.vWorldNormal, i.vWorldTangent, vWorldBinormal ); +#if ( defined(SHADER_MODEL_PS_2_B) || defined(SHADER_MODEL_PS_3_0) ) + worldSpaceNormal = normalize( worldSpaceNormal ); +#else + worldSpaceNormal = NormalizeWithCubemap( NormalizeSampler, worldSpaceNormal ); +#endif + } + + if ( bDiffuseLighting ) + { + diffuseLighting = PixelShaderDoLighting( i.worldPos_projPosZ.xyz, worldSpaceNormal, + float3( 0.0f, 0.0f, 0.0f ), false, bAmbientLight, vLightAtten, + cAmbientCube, NormalizeSampler, nNumLights, cLightInfo, bHalfLambert, + false, 1.0f, bDoDiffuseWarp, DiffuseWarpSampler ); + } + + float3 albedo = baseColor; + if (bBlendTintByBaseAlpha) + { + float3 tintedColor = albedo * g_DiffuseModulation.rgb; + tintedColor = lerp(tintedColor, g_DiffuseModulation.rgb, g_EnvmapTint_TintReplaceFactor.w); + albedo = lerp(albedo, tintedColor, baseColor.a); + } + else + { + albedo = albedo * g_DiffuseModulation.rgb; + } + + float alpha = g_DiffuseModulation.a; + if ( !bSelfIllum && !bBlendTintByBaseAlpha ) + { + alpha *= baseColor.a; + } + + +#if FLASHLIGHT + if( bFlashlight ) + { + int nShadowSampleLevel = 0; + bool bDoShadows = false; + float2 vProjPos = float2(0, 0); +// On ps_2_b, we can do shadow mapping +#if ( FLASHLIGHTSHADOWS && (defined(SHADER_MODEL_PS_2_B) || defined(SHADER_MODEL_PS_3_0) ) ) + nShadowSampleLevel = FLASHLIGHTDEPTHFILTERMODE; + bDoShadows = FLASHLIGHTSHADOWS; + vProjPos = i.vProjPos.xy / i.vProjPos.w; // Screen-space position for shadow map noise +#endif + +#if defined ( _X360 ) + float4 flashlightSpacePosition = i.flashlightSpacePos; +#else + float4 flashlightSpacePosition = mul( float4( i.worldPos_projPosZ.xyz, 1.0f ), g_FlashlightWorldToTexture ); +#endif + + float3 flashlightColor = DoFlashlight( g_FlashlightPos, i.worldPos_projPosZ.xyz, flashlightSpacePosition, + worldSpaceNormal, g_FlashlightAttenuationFactors.xyz, + g_FlashlightAttenuationFactors.w, FlashlightSampler, ShadowDepthSampler, + RandRotSampler, nShadowSampleLevel, bDoShadows, false, vProjPos, false, g_EnvmapContrast_ShadowTweaks ); + +#if defined ( _X360 ) + diffuseLighting += flashlightColor; +#else + diffuseLighting = flashlightColor; +#endif + + } +#endif + + + float3 diffuseComponent = albedo * diffuseLighting; + + +#if !FLASHLIGHT || defined ( _X360 ) + if ( bSelfIllum ) + { + #if ( SELFILLUMFRESNEL == 1 ) // To free up the constant register...see top of file + // This will apply a fresnel term based on the vertex normal (not the per-pixel normal!) to help fake and internal glow look + #if ((defined(SHADER_MODEL_PS_2_B) || defined(SHADER_MODEL_PS_3_0))) + float3 vVertexNormal = normalize( i.vWorldNormal.xyz ); + float flSelfIllumFresnel = ( pow( saturate( dot( vVertexNormal.xyz, normalize( i.worldVertToEyeVectorXYZ_tangentSpaceVertToEyeVectorZ.xyz ) ) ), g_SelfIllumScaleBiasExpBrightness.z ) * g_SelfIllumScaleBiasExpBrightness.x ) + g_SelfIllumScaleBiasExpBrightness.y; + + float3 selfIllumComponent = g_SelfIllumTint * albedo * g_SelfIllumScaleBiasExpBrightness.w; + diffuseComponent = lerp( diffuseComponent, selfIllumComponent, baseColor.a * saturate( flSelfIllumFresnel ) ); + #else + float3 vVertexNormal = i.vWorldNormal.xyz; + float flSelfIllumFresnel = ( pow( saturate( dot( vVertexNormal.xyz, ( i.worldVertToEyeVectorXYZ_tangentSpaceVertToEyeVectorZ.xyz ) ) ), g_SelfIllumScaleBiasExpBrightness.z ) * g_SelfIllumScaleBiasExpBrightness.x ) + g_SelfIllumScaleBiasExpBrightness.y; + + float3 selfIllumComponent = g_SelfIllumTint * albedo * g_SelfIllumScaleBiasExpBrightness.w; + diffuseComponent = lerp( diffuseComponent, selfIllumComponent, baseColor.a * saturate( flSelfIllumFresnel ) ); + #endif + #else + float3 selfIllumComponent = g_SelfIllumTint * albedo; + diffuseComponent = lerp( diffuseComponent, selfIllumComponent, baseColor.a ); + #endif + } +#endif + + float3 specularLighting = float3( 0.0f, 0.0f, 0.0f ); +#if !FLASHLIGHT || defined ( _X360 ) + if( bCubemap ) + { + float3 reflectVect = CalcReflectionVectorUnnormalized( worldSpaceNormal, i.worldVertToEyeVectorXYZ_tangentSpaceVertToEyeVectorZ.xyz ); + + specularLighting = ENV_MAP_SCALE * texCUBE( EnvmapSampler, reflectVect ); + specularLighting *= specularFactor; + specularLighting *= g_EnvmapTint_TintReplaceFactor.rgb; + float3 specularLightingSquared = specularLighting * specularLighting; + specularLighting = lerp( specularLighting, specularLightingSquared, g_EnvmapContrast_ShadowTweaks ); + float3 greyScale = dot( specularLighting, float3( 0.299f, 0.587f, 0.114f ) ); + specularLighting = lerp( greyScale, specularLighting, g_EnvmapSaturation ); + } +#endif + + float3 result = diffuseComponent + specularLighting; + +#if defined(SHADER_MODEL_PS_2_0) + float fogFactor = CalcPixelFogFactor( PIXELFOGTYPE, g_FogParams, g_EyePos.z, i.worldPos_projPosZ.z, i.worldPos_projPosZ.w ); +#else + float fogFactor = CalcPixelFogFactorConst( g_fPixelFogType, g_FogParams, g_EyePos.z, i.worldPos_projPosZ.z, i.worldPos_projPosZ.w ); +#endif + +#if defined( SHADER_MODEL_PS_2_0 ) + #if WRITEWATERFOGTODESTALPHA && (PIXELFOGTYPE == PIXEL_FOG_TYPE_HEIGHT) + alpha = fogFactor; + #endif +#else // 2b or higher + alpha = lerp( alpha, fogFactor, g_fPixelFogType * g_fWriteWaterFogToDestAlpha ); // Use the fog factor if it's height fog +#endif + +#if defined( SHADER_MODEL_PS_2_0 ) + return FinalOutput( float4( result.rgb, alpha ), fogFactor, PIXELFOGTYPE, TONEMAP_SCALE_LINEAR, false, i.worldPos_projPosZ.w ); +#else + return FinalOutputConst( float4( result.rgb, alpha ), fogFactor, g_fPixelFogType, TONEMAP_SCALE_LINEAR, g_fWriteDepthToAlpha, i.worldPos_projPosZ.w ); +#endif + +} + diff --git a/materialsystem/stdshaders/vertexlit_and_unlit_generic_bump_vs20.fxc b/materialsystem/stdshaders/vertexlit_and_unlit_generic_bump_vs20.fxc new file mode 100644 index 0000000..06afd95 --- /dev/null +++ b/materialsystem/stdshaders/vertexlit_and_unlit_generic_bump_vs20.fxc @@ -0,0 +1,198 @@ +//======= Copyright (c) 1996-2009, Valve Corporation, All rights reserved. ====== +// STATIC: "HALFLAMBERT" "0..1" +// STATIC: "USE_WITH_2B" "0..1" +// STATIC: "DECAL" "0..1" [vs30] +// STATIC: "FLASHLIGHT" "0..1" [XBOX] +// STATIC: "USE_STATIC_CONTROL_FLOW" "0..1" [vs20] + +// DYNAMIC: "COMPRESSED_VERTS" "0..1" +// DYNAMIC: "DOWATERFOG" "0..1" +// DYNAMIC: "SKINNING" "0..1" +// DYNAMIC: "MORPHING" "0..1" [vs30] +// DYNAMIC: "NUM_LIGHTS" "0..2" [vs20] + +// If using static control flow on Direct3D, we should use the NUM_LIGHTS=0 combo +// SKIP: $USE_STATIC_CONTROL_FLOW && ( $NUM_LIGHTS > 0 ) [vs20] + +#include "common_vs_fxc.h" + +static const bool g_bSkinning = SKINNING ? true : false; +static const int g_FogType = DOWATERFOG; + +const float4 cBaseTexCoordTransform[2] : register( SHADER_SPECIFIC_CONST_0 ); // 0 & 1 +const float4 cDetailTexCoordTransform[2] : register( SHADER_SPECIFIC_CONST_4 ); // 4 & 5 +const float4x4 g_FlashlightWorldToTexture : register( SHADER_SPECIFIC_CONST_6 ); // 6, 7, 8, 9 + +#ifdef SHADER_MODEL_VS_3_0 +// NOTE: cMorphTargetTextureDim.xy = target dimensions, +// cMorphTargetTextureDim.z = 4tuples/morph +const float3 cMorphTargetTextureDim : register( SHADER_SPECIFIC_CONST_10 ); +const float4 cMorphSubrect : register( SHADER_SPECIFIC_CONST_11 ); + +sampler2D morphSampler : register( D3DVERTEXTEXTURESAMPLER0, s0 ); +#endif + + +//----------------------------------------------------------------------------- +// Input vertex format +//----------------------------------------------------------------------------- +struct VS_INPUT +{ + // This is all of the stuff that we ever use. + float4 vPos : POSITION; + float4 vBoneWeights : BLENDWEIGHT; + float4 vBoneIndices : BLENDINDICES; + float4 vNormal : NORMAL; + float4 vColor : COLOR0; + float3 vSpecular : COLOR1; + // make these float2's and stick the [n n 0 1] in the dot math. + float4 vTexCoord0 : TEXCOORD0; + float4 vTexCoord1 : TEXCOORD1; + float4 vTexCoord2 : TEXCOORD2; + float4 vTexCoord3 : TEXCOORD3; + float3 vTangentS : TANGENT; + float3 vTangentT : BINORMAL; + float4 vUserData : TANGENT; + + // Position and normal/tangent deltas + float3 vPosFlex : POSITION1; + float3 vNormalFlex : NORMAL1; +#ifdef SHADER_MODEL_VS_3_0 + float vVertexID : POSITION2; +#endif +}; + + +//----------------------------------------------------------------------------- +// Output vertex format +//----------------------------------------------------------------------------- +struct VS_OUTPUT +{ + // Stuff that isn't seen by the pixel shader + float4 projPos : POSITION; +#if !defined( _X360 ) + float fog : FOG; +#endif + // Stuff that is seen by the pixel shader + + float4 baseTexCoord2_tangentSpaceVertToEyeVectorXY : TEXCOORD0; + float3 lightAtten : TEXCOORD1; + float4 worldVertToEyeVectorXYZ_tangentSpaceVertToEyeVectorZ : TEXCOORD2; + float3 vWorldNormal : TEXCOORD3; // World-space normal + float4 vWorldTangent : TEXCOORD4; +#if USE_WITH_2B + float4 vProjPos : TEXCOORD5; +#else + float3 vWorldBinormal : TEXCOORD5; +#endif + float4 worldPos_projPosZ : TEXCOORD6; + float3 detailTexCoord_atten3 : TEXCOORD7; + float4 fogFactorW : COLOR1; + +#if defined( _X360 ) && FLASHLIGHT + float4 flashlightSpacePos : TEXCOORD8; +#endif +}; + + +//----------------------------------------------------------------------------- +// Main shader entry point +//----------------------------------------------------------------------------- +VS_OUTPUT main( const VS_INPUT v ) +{ + VS_OUTPUT o = ( VS_OUTPUT )0; + + float4 vPosition = v.vPos; + float3 vNormal; + float4 vTangent; + DecompressVertex_NormalTangent( v.vNormal, v.vUserData, vNormal, vTangent ); + +#if !defined( SHADER_MODEL_VS_3_0 ) || !MORPHING + ApplyMorph( v.vPosFlex, v.vNormalFlex, vPosition.xyz, vNormal, vTangent.xyz ); +#else + ApplyMorph( morphSampler, cMorphTargetTextureDim, cMorphSubrect, + v.vVertexID, v.vTexCoord2, vPosition.xyz, vNormal, vTangent.xyz ); +#endif + + // Perform skinning + float3 worldNormal, worldPos, worldTangentS, worldTangentT; + SkinPositionNormalAndTangentSpace( g_bSkinning, vPosition, vNormal, vTangent, + v.vBoneWeights, v.vBoneIndices, worldPos, + worldNormal, worldTangentS, worldTangentT ); + + // Always normalize since flex path is controlled by runtime + // constant not a shader combo and will always generate the normalization + worldNormal = normalize( worldNormal ); + worldTangentS = normalize( worldTangentS ); + worldTangentT = normalize( worldTangentT ); + +#if defined( SHADER_MODEL_VS_3_0 ) && MORPHING && DECAL + // Avoid z precision errors + worldPos += worldNormal * 0.05f * v.vTexCoord2.z; +#endif + + o.vWorldNormal.xyz = worldNormal.xyz; + o.vWorldTangent = float4( worldTangentS.xyz, vTangent.w ); // Propagate binormal sign in world tangent.w + + // Transform into projection space + float4 vProjPos = mul( float4( worldPos, 1 ), cViewProj ); + o.projPos = vProjPos; + vProjPos.z = dot( float4( worldPos, 1 ), cViewProjZ ); + +#if USE_WITH_2B + o.vProjPos = vProjPos; +#else + o.vWorldBinormal.xyz = worldTangentT.xyz; +#endif + + o.fogFactorW = CalcFog( worldPos, vProjPos, g_FogType ); +#if !defined( _X360 ) + o.fog = o.fogFactorW; +#endif + + // Needed for water fog alpha and diffuse lighting + // FIXME: we shouldn't have to compute this all the time. + o.worldPos_projPosZ = float4( worldPos, vProjPos.z ); + + // Needed for cubemapping + parallax mapping + // FIXME: We shouldn't have to compute this all the time. + //o.worldVertToEyeVectorXYZ_tangentSpaceVertToEyeVectorZ.xyz = VSHADER_VECT_SCALE * (cEyePos - worldPos); + o.worldVertToEyeVectorXYZ_tangentSpaceVertToEyeVectorZ.xyz = normalize( cEyePos.xyz - worldPos.xyz ); + +#if defined( SHADER_MODEL_VS_2_0 ) && ( !USE_STATIC_CONTROL_FLOW ) + o.lightAtten.xyz = float3(0,0,0); + o.detailTexCoord_atten3.z = 0.0f; + #if ( NUM_LIGHTS > 0 ) + o.lightAtten.x = GetVertexAttenForLight( worldPos, 0, false ); + #endif + #if ( NUM_LIGHTS > 1 ) + o.lightAtten.y = GetVertexAttenForLight( worldPos, 1, false ); + #endif + #if ( NUM_LIGHTS > 2 ) + o.lightAtten.z = GetVertexAttenForLight( worldPos, 2, false ); + #endif + #if ( NUM_LIGHTS > 3 ) + o.detailTexCoord_atten3.z = GetVertexAttenForLight( worldPos, 3, false ); + #endif +#else + // Scalar light attenuation + o.lightAtten.x = GetVertexAttenForLight( worldPos, 0, true ); + o.lightAtten.y = GetVertexAttenForLight( worldPos, 1, true ); + o.lightAtten.z = GetVertexAttenForLight( worldPos, 2, true ); + o.detailTexCoord_atten3.z = GetVertexAttenForLight( worldPos, 3, true ); +#endif + + // Base texture coordinate transform + o.baseTexCoord2_tangentSpaceVertToEyeVectorXY.x = dot( v.vTexCoord0, cBaseTexCoordTransform[0] ); + o.baseTexCoord2_tangentSpaceVertToEyeVectorXY.y = dot( v.vTexCoord0, cBaseTexCoordTransform[1] ); + + // Detail texture coordinate transform + o.detailTexCoord_atten3.x = dot( v.vTexCoord0, cDetailTexCoordTransform[0] ); + o.detailTexCoord_atten3.y = dot( v.vTexCoord0, cDetailTexCoordTransform[1] ); + +#if defined( _X360 ) && FLASHLIGHT + o.flashlightSpacePos = mul( float4( worldPos, 1.0f ), g_FlashlightWorldToTexture ); +#endif + + return o; +} diff --git a/materialsystem/stdshaders/vertexlit_and_unlit_generic_ps2x.fxc b/materialsystem/stdshaders/vertexlit_and_unlit_generic_ps2x.fxc new file mode 100644 index 0000000..eb3cbfa --- /dev/null +++ b/materialsystem/stdshaders/vertexlit_and_unlit_generic_ps2x.fxc @@ -0,0 +1,507 @@ +//====== Copyright © 1996-2007, Valve Corporation, All rights reserved. =======// +// +//=============================================================================// +// STATIC: "DETAILTEXTURE" "0..1" +// STATIC: "CUBEMAP" "0..1" +// STATIC: "DIFFUSELIGHTING" "0..1" +// STATIC: "ENVMAPMASK" "0..1" +// STATIC: "BASEALPHAENVMAPMASK" "0..1" +// STATIC: "SELFILLUM" "0..1" +// STATIC: "VERTEXCOLOR" "0..1" +// STATIC: "FLASHLIGHT" "0..1" +// STATIC: "SELFILLUM_ENVMAPMASK_ALPHA" "0..1" +// STATIC: "DETAIL_BLEND_MODE" "0..9" +// STATIC: "SEAMLESS_BASE" "0..1" +// STATIC: "SEAMLESS_DETAIL" "0..1" +// STATIC: "DISTANCEALPHA" "0..1" +// STATIC: "DISTANCEALPHAFROMDETAIL" "0..1" +// STATIC: "SOFT_MASK" "0..1" +// STATIC: "OUTLINE" "0..1" +// STATIC: "OUTER_GLOW" "0..1" +// STATIC: "FLASHLIGHTDEPTHFILTERMODE" "0..2" [ps20b] [PC] +// STATIC: "FLASHLIGHTDEPTHFILTERMODE" "0..2" [ps30] [PC] +// STATIC: "FLASHLIGHTDEPTHFILTERMODE" "0..0" [ps20b] [XBOX] +// STATIC: "DEPTHBLEND" "0..1" [ps20b] [ps30] +// STATIC: "BLENDTINTBYBASEALPHA" "0..1" +// STATIC: "SRGB_INPUT_ADAPTER" "0..1" [ps20b] +// STATIC: "CUBEMAP_SPHERE_LEGACY" "0..1" + +// DYNAMIC: "PIXELFOGTYPE" "0..1" [ps20] +// DYNAMIC: "LIGHTING_PREVIEW" "0..2" [PC] +// DYNAMIC: "LIGHTING_PREVIEW" "0..0" [XBOX] +// DYNAMIC: "FLASHLIGHTSHADOWS" "0..1" [ps20b] +// DYNAMIC: "FLASHLIGHTSHADOWS" "0..1" [ps30] +// DYNAMIC: "STATIC_LIGHT_LIGHTMAP" "0..1" [ps20b] [ps30] +// DYNAMIC: "STATIC_LIGHT_LIGHTMAP" "0..0" [ps20] +// DYNAMIC: "DEBUG_LUXELS" "0..1" [ps20b] [ps30] + +// detail blend mode 6 = ps20b only +// SKIP: $DETAIL_BLEND_MODE == 6 [ps20] + +// SKIP: ($DETAILTEXTURE == 0 ) && ( $DETAIL_BLEND_MODE != 0 ) +// SKIP: ($DETAILTEXTURE == 0 ) && ( $SEAMLESS_DETAIL ) +// SKIP: ($ENVMAPMASK || $SELFILLUM_ENVMAPMASK_ALPHA) && ($SEAMLESS_BASE || $SEAMLESS_DETAIL) +// SKIP: $BASEALPHAENVMAPMASK && $ENVMAPMASK +// SKIP: $BASEALPHAENVMAPMASK && $SELFILLUM +// SKIP: $SELFILLUM && $SELFILLUM_ENVMAPMASK_ALPHA +// SKIP: $SELFILLUM_ENVMAPMASK_ALPHA && (! $ENVMAPMASK) +// SKIP: $ENVMAPMASK && ($FLASHLIGHT || $FLASHLIGHTSHADOWS) [PC] +// SKIP: $BASEALPHAENVMAPMASK && ($SEAMLESS_BASE || $SEAMLESS_DETAIL) +// SKIP: ($DISTANCEALPHA == 0) && ($DISTANCEALPHAFROMDETAIL || $SOFT_MASK || $OUTLINE || $OUTER_GLOW) +// SKIP: ($DETAILTEXTURE == 0) && ($DISTANCEALPHAFROMDETAIL) + +// We don't care about flashlight depth unless the flashlight is on +// SKIP: ( $FLASHLIGHT == 0 ) && ( $FLASHLIGHTSHADOWS == 1 ) [ps20b] +// SKIP: ( $FLASHLIGHT == 0 ) && ( $FLASHLIGHTSHADOWS == 1 ) [ps30] + +// Flashlight shadow filter mode is irrelevant if there is no flashlight +// SKIP: ( $FLASHLIGHT == 0 ) && ( $FLASHLIGHTDEPTHFILTERMODE != 0 ) [ps20b] +// SKIP: ( $FLASHLIGHT == 0 ) && ( $FLASHLIGHTDEPTHFILTERMODE != 0 ) [ps30] + +// DISTANCEALPHA-related skips +// SKIP: ($DISTANCEALPHA) && ($ENVMAPMASK || $BASEALPHAENVMAPMASK || $SELFILLUM || $SELFILLUM_ENVMAPMASK_ALPHA ) +// SKIP: ($DISTANCEALPHA) && ($SEAMLESS_BASE || $SEAMLESS_DETAIL || $CUBEMAP || $LIGHTING_PREVIEW ) +// SKIP: ($DISTANCEALPHA) && ($WRITEWATERFOGTODESTALPHA || $PIXELFOGTYPE || $FLASHLIGHT || $FLASHLIGHTSHADOWS || $SRGB_INPUT_ADAPTER ) + +// SKIP: $SEAMLESS_BASE && $SRGB_INPUT_ADAPTER +// SKIP: $SEAMLESS_BASE && ($BLENDTINTBYBASEALPHA ) + +// BlendTintByBaseAlpha is incompatible with other interpretations of alpha +// SKIP: ($BLENDTINTBYBASEALPHA) && ($SELFILLUM || (($DISTANCEALPHA) && ($DISTANCEALPHAFROMDETAIL == 0)) || $BASEALPHAENVMAPMASK) + +// Only _XBOX allows flashlight and cubemap in the current implementation +// SKIP: $FLASHLIGHT && $CUBEMAP [PC] + +// SKIP: $CUBEMAP_SPHERE_LEGACY && ($CUBEMAP == 0) + +// Debugging luxels only makes sense if we have lightmaps on this geometry. +// SKIP: ($STATIC_LIGHT_LIGHTMAP == 0) && ($DEBUG_LUXELS == 1) + +#include "common_flashlight_fxc.h" +#include "common_vertexlitgeneric_dx9.h" + +const float4 g_EnvmapTint_TintReplaceFactor : register( c0 ); +const float4 g_DiffuseModulation : register( c1 ); +const float4 g_EnvmapContrast_ShadowTweaks : register( c2 ); +const float4 g_EnvmapSaturation_SelfIllumMask : register( c3 ); +const float4 g_SelfIllumTint_and_BlendFactor : register( c4 ); + +const float4 g_ShaderControls : register( c12 ); +const float4 g_DepthFeatheringConstants : register( c13 ); + +const float4 g_EyePos : register( c20 ); +const float4 g_FogParams : register( c21 ); + +#define g_SelfIllumTint g_SelfIllumTint_and_BlendFactor.xyz +#define g_DetailBlendFactor g_SelfIllumTint_and_BlendFactor.w +#define g_EnvmapSaturation g_EnvmapSaturation_SelfIllumMask.xyz +#define g_SelfIllumMaskControl g_EnvmapSaturation_SelfIllumMask.w + +const float4 g_FlashlightAttenuationFactors : register( c22 ); +const HALF3 g_FlashlightPos : register( c23 ); +const float4x4 g_FlashlightWorldToTexture : register( c24 ); // through c27 + + +sampler BaseTextureSampler : register( s0 ); +sampler EnvmapSampler : register( s1 ); +sampler DetailSampler : register( s2 ); +sampler EnvmapMaskSampler : register( s4 ); +sampler RandRotSampler : register( s6 ); // RandomRotation sampler +sampler FlashlightSampler : register( s7 ); +sampler ShadowDepthSampler : register( s8 ); // Flashlight shadow depth map sampler +sampler DepthSampler : register( s10 ); //depth buffer sampler for depth blending +sampler SelfIllumMaskSampler : register( s11 ); // selfillummask +sampler LightMapSampler : register( s12 ); + +struct PS_INPUT +{ +#if SEAMLESS_BASE + HALF3 baseTexCoord : TEXCOORD0; // Base texture coordinate +#else + HALF2 baseTexCoord : TEXCOORD0; // Base texture coordinate +#endif +#if SEAMLESS_DETAIL + HALF3 detailTexCoord : TEXCOORD1; // Seamless texture coordinate +#else + HALF2 detailTexCoord : TEXCOORD1; // Detail texture coordinate +#endif + float4 color : TEXCOORD2; // Vertex color (from lighting or unlit) + float3 worldVertToEyeVector : TEXCOORD3; // Necessary for reflection + float3 worldSpaceNormal : TEXCOORD4; // Necessary for cubemaps and flashlight + +#if defined ( _X360 ) +#if FLASHLIGHT + float4 flashlightSpacePos : TEXCOORD5; +#endif +#endif + + float4 projPos : TEXCOORD6; + float4 worldPos_projPosZ : TEXCOORD7; + float4 fogFactorW : COLOR1; +#if SEAMLESS_BASE || SEAMLESS_DETAIL + float3 SeamlessWeights : COLOR0; // x y z projection weights +#endif +}; + +const float4 g_GlowParameters : register( c5 ); +const float4 g_GlowColor : register( c6 ); +#define GLOW_UV_OFFSET g_GlowParameters.xy +#define OUTER_GLOW_MIN_DVALUE g_GlowParameters.z +#define OUTER_GLOW_MAX_DVALUE g_GlowParameters.w +#define OUTER_GLOW_COLOR g_GlowColor + +#define g_fPixelFogType g_ShaderControls.x +#define g_fWriteDepthToAlpha g_ShaderControls.y +#define g_fWriteWaterFogToDestAlpha g_ShaderControls.z +#define g_fVertexAlpha g_ShaderControls.w + + +const float4 g_DistanceAlphaParams : register( c7 ); +#define SOFT_MASK_MAX g_DistanceAlphaParams.x +#define SOFT_MASK_MIN g_DistanceAlphaParams.y + +const float4 g_OutlineColor : register( c8 ); +#define OUTLINE_COLOR g_OutlineColor + +const float4 g_OutlineParams : register( c9 ); +// these are ordered this way for optimal ps20 swizzling +#define OUTLINE_MIN_VALUE0 g_OutlineParams.x +#define OUTLINE_MAX_VALUE1 g_OutlineParams.y +#define OUTLINE_MAX_VALUE0 g_OutlineParams.z +#define OUTLINE_MIN_VALUE1 g_OutlineParams.w + +#if DETAILTEXTURE +const float3 g_DetailTint : register( c10 ); +#endif + +#if DEBUG_LUXELS +const float4 g_LuxelScale : register( c11 ); +#endif + + +// Calculate unified fog +float CalcPixelFogFactorConst( float fPixelFogType, const float4 fogParams, const float flEyePosZ, const float flWorldPosZ, const float flProjPosZ ) +{ + float flDepthBelowWater = fPixelFogType*fogParams.y - flWorldPosZ; // above water = negative, below water = positive + float flDepthBelowEye = fPixelFogType*flEyePosZ - flWorldPosZ; // above eye = negative, below eye = positive + // if fPixelFogType == 0, then flDepthBelowWater == flDepthBelowEye and frac will be 1 + float frac = (flDepthBelowEye == 0) ? 1 : saturate(flDepthBelowWater/flDepthBelowEye); + return saturate( min(fogParams.z, flProjPosZ * fogParams.w * frac - fogParams.x) ); +} + +// Blend both types of Fog and lerp to get result +float3 BlendPixelFogConst( const float3 vShaderColor, float pixelFogFactor, const float3 vFogColor, float fPixelFogType ) +{ + //float3 fRangeResult = lerp( vShaderColor.rgb, vFogColor.rgb, pixelFogFactor * pixelFogFactor ); //squaring the factor will get the middle range mixing closer to hardware fog + //float3 fHeightResult = lerp( vShaderColor.rgb, vFogColor.rgb, saturate( pixelFogFactor ) ); + //return lerp( fRangeResult, fHeightResult, fPixelFogType ); + pixelFogFactor = lerp( pixelFogFactor*pixelFogFactor, pixelFogFactor, fPixelFogType ); + return lerp( vShaderColor.rgb, vFogColor.rgb, pixelFogFactor ); +} + + +float4 FinalOutputConst( const float4 vShaderColor, float pixelFogFactor, float fPixelFogType, const int iTONEMAP_SCALE_TYPE, float fWriteDepthToDestAlpha, const float flProjZ ) +{ + float4 result = vShaderColor; + if( iTONEMAP_SCALE_TYPE == TONEMAP_SCALE_LINEAR ) + { + result.rgb *= LINEAR_LIGHT_SCALE; + } + else if( iTONEMAP_SCALE_TYPE == TONEMAP_SCALE_GAMMA ) + { + result.rgb *= GAMMA_LIGHT_SCALE; + } + + result.a = lerp( result.a, DepthToDestAlpha( flProjZ ), fWriteDepthToDestAlpha ); + + result.rgb = BlendPixelFogConst( result.rgb, pixelFogFactor, g_LinearFogColor.rgb, fPixelFogType ); + result.rgb = SRGBOutput( result.rgb ); //SRGB in pixel shader conversion + + return result; +} + + +#if LIGHTING_PREVIEW == 2 +LPREVIEW_PS_OUT main( PS_INPUT i ) : COLOR +#else +float4 main( PS_INPUT i ) : COLOR +#endif +{ + bool bDetailTexture = DETAILTEXTURE ? true : false; + bool bCubemap = CUBEMAP ? true : false; + bool bDiffuseLighting = DIFFUSELIGHTING ? true : false; + bool bHasNormal = bCubemap || bDiffuseLighting; + bool bEnvmapMask = ENVMAPMASK ? true : false; + bool bBaseAlphaEnvmapMask = BASEALPHAENVMAPMASK ? true : false; + bool bSelfIllum = SELFILLUM ? true : false; + bool bVertexColor = VERTEXCOLOR ? true : false; + bool bFlashlight = FLASHLIGHT ? true : false; + bool bBlendTintByBaseAlpha = BLENDTINTBYBASEALPHA ? true : false; + + HALF4 baseColor = HALF4( 1.0f, 1.0f, 1.0f, 1.0f ); +#if SEAMLESS_BASE + baseColor = + i.SeamlessWeights.x * tex2D( BaseTextureSampler, i.baseTexCoord.yz )+ + i.SeamlessWeights.y * tex2D( BaseTextureSampler, i.baseTexCoord.zx )+ + i.SeamlessWeights.z * tex2D( BaseTextureSampler, i.baseTexCoord.xy ); +#else + baseColor = tex2D( BaseTextureSampler, i.baseTexCoord.xy ); + +#if SRGB_INPUT_ADAPTER + baseColor.rgb = GammaToLinear( baseColor.rgb ); +#endif + +#endif // !SEAMLESS_BASE + + +#if DISTANCEALPHA && (DISTANCEALPHAFROMDETAIL == 0) + float distAlphaMask = baseColor.a; +#endif + + +#if DETAILTEXTURE +#if SEAMLESS_DETAIL + float4 detailColor = + i.SeamlessWeights.x * tex2D( DetailSampler, i.detailTexCoord.yz )+ + i.SeamlessWeights.y * tex2D( DetailSampler, i.detailTexCoord.zx )+ + i.SeamlessWeights.z * tex2D( DetailSampler, i.detailTexCoord.xy ); +#else + float4 detailColor = tex2D( DetailSampler, i.detailTexCoord.xy ); +#endif + detailColor.rgb *= g_DetailTint; + +#if DISTANCEALPHA && (DISTANCEALPHAFROMDETAIL == 1) + float distAlphaMask = detailColor.a; + detailColor.a = 1.0; // make tcombine treat as 1.0 +#endif + baseColor = + TextureCombine( baseColor, detailColor, DETAIL_BLEND_MODE, g_DetailBlendFactor ); +#endif + +#if DISTANCEALPHA + // now, do all distance alpha effects + //if ( OUTLINE && ( distAlphaMask >= OUTLINE_MIN_VALUE0 ) && ( distAlphaMask <= OUTLINE_MAX_VALUE1 ) ) + //{ + // float oFactor=1.0; + // if ( distAlphaMask <= OUTLINE_MIN_VALUE1 ) + // { + // oFactor=smoothstep( OUTLINE_MIN_VALUE0, OUTLINE_MIN_VALUE1, distAlphaMask ); + // } + // else + // { + // oFactor=smoothstep( OUTLINE_MAX_VALUE1, OUTLINE_MAX_VALUE0, distAlphaMask ); + // } + // baseColor = lerp( baseColor, OUTLINE_COLOR, oFactor ); + //} + if ( OUTLINE ) + { + float4 oFactors = smoothstep(g_OutlineParams.xyzw, g_OutlineParams.wzyx, distAlphaMask ); + baseColor = lerp( baseColor, g_OutlineColor, oFactors.x * oFactors.y ); + } + + float mskUsed; + if ( SOFT_MASK ) + { + mskUsed = smoothstep( SOFT_MASK_MIN, SOFT_MASK_MAX, distAlphaMask ); + baseColor.a *= mskUsed; + } + else + { + mskUsed = distAlphaMask >= 0.5; + if (DETAILTEXTURE ) + baseColor.a *= mskUsed; + else + baseColor.a = mskUsed; + } + + + if ( OUTER_GLOW ) + { +#if DISTANCEALPHAFROMDETAIL + float4 glowTexel = tex2D( DetailSampler, i.detailTexCoord.xy+GLOW_UV_OFFSET ); +#else + float4 glowTexel = tex2D( BaseTextureSampler, i.baseTexCoord.xy+GLOW_UV_OFFSET ); +#endif + float4 glowc = OUTER_GLOW_COLOR*smoothstep( OUTER_GLOW_MIN_DVALUE, OUTER_GLOW_MAX_DVALUE, glowTexel.a ); + baseColor = lerp( glowc, baseColor, mskUsed ); + } + +#endif // DISTANCEALPHA + + float3 specularFactor = 1.0f; + float4 envmapMaskTexel; + if( bEnvmapMask ) + { + envmapMaskTexel = tex2D( EnvmapMaskSampler, i.baseTexCoord.xy ); + specularFactor *= envmapMaskTexel.xyz; + } + + if( bBaseAlphaEnvmapMask ) + { + specularFactor *= 1.0 - baseColor.a; // this blows! + } + + float3 diffuseLighting = float3( 1.0f, 1.0f, 1.0f ); + if( bDiffuseLighting || bVertexColor ) + { + diffuseLighting = i.color.rgb; + } + +#if STATIC_LIGHT_LIGHTMAP + // This matches the behavior of vertex lighting, which multiplies by cOverbright (which is not accessible here) + // And converts from Gamma space to Linear space before being used. + float2 lightmapTexCoords = i.baseTexCoord.xy; + #if DEBUG_LUXELS + lightmapTexCoords.xy *= g_LuxelScale.xy; + #endif + float3 f3LightmapColor = GammaToLinear( 2.0f * tex2D( LightMapSampler, lightmapTexCoords ).rgb ); + diffuseLighting = f3LightmapColor; +#endif + + float3 albedo = baseColor; + + if (bBlendTintByBaseAlpha) + { + float3 tintedColor = albedo * g_DiffuseModulation.rgb; + tintedColor = lerp(tintedColor, g_DiffuseModulation.rgb, g_EnvmapTint_TintReplaceFactor.w); + albedo = lerp(albedo, tintedColor, baseColor.a); + } + else + { + albedo = albedo * g_DiffuseModulation.rgb; + } + + float alpha = g_DiffuseModulation.a; + if ( !bBaseAlphaEnvmapMask && !bSelfIllum && !bBlendTintByBaseAlpha ) + { + alpha *= baseColor.a; + } + + + if( bFlashlight ) + { + int nShadowSampleLevel = 0; + bool bDoShadows = false; +// On ps_2_b, we can do shadow mapping +#if ( FLASHLIGHTSHADOWS && (defined(SHADER_MODEL_PS_2_B) || defined(SHADER_MODEL_PS_3_0) ) ) + nShadowSampleLevel = FLASHLIGHTDEPTHFILTERMODE; + bDoShadows = true; +#endif + +#if defined ( _X360 ) + float4 flashlightSpacePosition = i.flashlightSpacePos; +#else + float4 flashlightSpacePosition = mul( float4( i.worldPos_projPosZ.xyz, 1.0f ), g_FlashlightWorldToTexture ); +#endif + + // We want the N.L to happen on the flashlight pass, but can't afford it on ps20 + bool bUseWorldNormal = true; +#if ( defined( SHADER_MODEL_PS_2_0 ) && ( DETAILTEXTURE ) ) + bUseWorldNormal = false; +#endif + float3 flashlightColor = DoFlashlight( g_FlashlightPos, i.worldPos_projPosZ.xyz, flashlightSpacePosition, + i.worldSpaceNormal, g_FlashlightAttenuationFactors.xyz, + g_FlashlightAttenuationFactors.w, FlashlightSampler, ShadowDepthSampler, + RandRotSampler, nShadowSampleLevel, bDoShadows, false, i.projPos.xy / i.projPos.w, false, g_EnvmapContrast_ShadowTweaks, bUseWorldNormal ); + +#if defined ( _X360 ) + diffuseLighting += flashlightColor; +#else + diffuseLighting = flashlightColor; +#endif + } + + if( bVertexColor && bDiffuseLighting ) + { + albedo *= i.color.rgb; + } + + alpha = lerp( alpha, alpha * i.color.a, g_fVertexAlpha ); + + float3 diffuseComponent = albedo * diffuseLighting; + +#if DETAILTEXTURE + diffuseComponent = + TextureCombinePostLighting( diffuseComponent, detailColor, DETAIL_BLEND_MODE, g_DetailBlendFactor ); +#endif + + HALF3 specularLighting = HALF3( 0.0f, 0.0f, 0.0f ); + +#if !FLASHLIGHT || defined ( _X360 ) + #if SELFILLUM_ENVMAPMASK_ALPHA + // range of alpha: + // 0 - 0.125 = lerp(diffuse,selfillum,alpha*8) + // 0.125-1.0 = selfillum*(1+alpha-0.125)*8 (over bright glows) + HALF3 selfIllumComponent = g_SelfIllumTint * albedo; + half Adj_Alpha=8*envmapMaskTexel.a; + diffuseComponent=( max( 0, 1-Adj_Alpha ) * diffuseComponent) + Adj_Alpha * selfIllumComponent; + #else + if ( bSelfIllum ) + { + float3 vSelfIllumMask = tex2D( SelfIllumMaskSampler, i.baseTexCoord.xy ); + vSelfIllumMask = lerp( baseColor.aaa, vSelfIllumMask, g_SelfIllumMaskControl ); + diffuseComponent = lerp( diffuseComponent, g_SelfIllumTint * albedo, vSelfIllumMask ); + } + #endif + + if( bCubemap ) + { +#if CUBEMAP_SPHERE_LEGACY + HALF3 reflectVect = normalize(CalcReflectionVectorUnnormalized( i.worldSpaceNormal, i.worldVertToEyeVector.xyz )); + + specularLighting = 0.5 * tex2D( EnvmapSampler, float2(reflectVect.x, reflectVect.y) ) * g_DiffuseModulation.rgb * diffuseLighting; +#else + HALF3 reflectVect = CalcReflectionVectorUnnormalized( i.worldSpaceNormal, i.worldVertToEyeVector.xyz ); + + specularLighting = ENV_MAP_SCALE * texCUBE( EnvmapSampler, reflectVect ); + specularLighting *= specularFactor; + specularLighting *= g_EnvmapTint_TintReplaceFactor.rgb; + HALF3 specularLightingSquared = specularLighting * specularLighting; + specularLighting = lerp( specularLighting, specularLightingSquared, g_EnvmapContrast_ShadowTweaks ); + HALF3 greyScale = dot( specularLighting, HALF3( 0.299f, 0.587f, 0.114f ) ); + specularLighting = lerp( greyScale, specularLighting, g_EnvmapSaturation ); +#endif + } +#endif + + HALF3 result = diffuseComponent + specularLighting; + +#if LIGHTING_PREVIEW +# if LIGHTING_PREVIEW == 1 + float dotprod=0.7+0.25*dot(i.worldSpaceNormal,normalize(float3(1,2,-.5))); + return FinalOutput( float4( dotprod*albedo.xyz, alpha ), 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_LINEAR ); +# else + LPREVIEW_PS_OUT ret; + ret.flags=float4(1,1,1,1); + ret.color=float4( albedo.xyz, alpha ); + ret.normal=float4(i.worldSpaceNormal,alpha); + ret.position=float4(i.worldPos_projPosZ.xyz, alpha); + return FinalOutput( ret, 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE ); +# endif +#else + +# if (DEPTHBLEND == 1) + { + float2 vScreenPos; + vScreenPos.x = i.projPos.x; + vScreenPos.y = -i.projPos.y; + vScreenPos = (vScreenPos + i.projPos.w) * 0.5f; + alpha *= DepthFeathering( DepthSampler, vScreenPos / i.projPos.w, i.projPos.w - i.projPos.z, i.projPos.w, g_DepthFeatheringConstants ); + } +# endif + +#if defined( SHADER_MODEL_PS_2_0 ) + float fogFactor = CalcPixelFogFactor( PIXELFOGTYPE, g_FogParams, g_EyePos.z, i.worldPos_projPosZ.z, i.projPos.z ); + #if (PIXELFOGTYPE == PIXEL_FOG_TYPE_HEIGHT) + alpha = lerp( alpha, fogFactor, g_fWriteWaterFogToDestAlpha ); + #endif + return FinalOutput( float4( result.rgb, alpha ), fogFactor, PIXELFOGTYPE, TONEMAP_SCALE_LINEAR, false, i.projPos.z ); +#else // 2b or higher + float fogFactor = CalcPixelFogFactorConst( g_fPixelFogType, g_FogParams, g_EyePos.z, i.worldPos_projPosZ.z, i.projPos.z ); + alpha = lerp( alpha, fogFactor, g_fWriteWaterFogToDestAlpha ); // Use the fog factor if it's height fog + return FinalOutputConst( float4( result.rgb, alpha ), fogFactor, g_fPixelFogType, TONEMAP_SCALE_LINEAR, g_fWriteDepthToAlpha, i.projPos.z ); +#endif + +#endif +} + diff --git a/materialsystem/stdshaders/vertexlit_and_unlit_generic_vs20.fxc b/materialsystem/stdshaders/vertexlit_and_unlit_generic_vs20.fxc new file mode 100644 index 0000000..43dae3a --- /dev/null +++ b/materialsystem/stdshaders/vertexlit_and_unlit_generic_vs20.fxc @@ -0,0 +1,250 @@ +//======= Copyright © 1996-2007, Valve Corporation, All rights reserved. ====== + +// STATIC: "VERTEXCOLOR" "0..1" +// STATIC: "CUBEMAP" "0..1" +// STATIC: "HALFLAMBERT" "0..1" +// STATIC: "FLASHLIGHT" "0..1" +// STATIC: "SEAMLESS_BASE" "0..1" +// STATIC: "SEAMLESS_DETAIL" "0..1" +// STATIC: "SEPARATE_DETAIL_UVS" "0..1" +// STATIC: "DECAL" "0..1" [vs30] +// STATIC: "USE_STATIC_CONTROL_FLOW" "0..1" [vs20] +// STATIC: "DONT_GAMMA_CONVERT_VERTEX_COLOR" "0..1" +// DYNAMIC: "COMPRESSED_VERTS" "0..1" +// DYNAMIC: "DYNAMIC_LIGHT" "0..1" +// DYNAMIC: "STATIC_LIGHT_VERTEX" "0..1" +// DYNAMIC: "STATIC_LIGHT_LIGHTMAP" "0..1" +// DYNAMIC: "DOWATERFOG" "0..1" +// DYNAMIC: "SKINNING" "0..1" +// DYNAMIC: "LIGHTING_PREVIEW" "0..1" [PC] +// DYNAMIC: "LIGHTING_PREVIEW" "0..0" [XBOX] +// DYNAMIC: "MORPHING" "0..1" [vs30] +// DYNAMIC: "NUM_LIGHTS" "0..2" [vs20] + +// If using static control flow on Direct3D, we should use the NUM_LIGHTS=0 combo +// SKIP: $USE_STATIC_CONTROL_FLOW && ( $NUM_LIGHTS > 0 ) [vs20] +// SKIP: ($SEPARATE_DETAIL_UVS) && ($SEAMLESS_DETAIL) +// SKIP: ($DONT_GAMMA_CONVERT_VERTEX_COLOR && ( ! $VERTEXCOLOR ) ) +#include "common_vs_fxc.h" + +static const bool g_bSkinning = SKINNING ? true : false; +static const int g_FogType = DOWATERFOG; +static const bool g_bVertexColor = VERTEXCOLOR ? true : false; +static const bool g_bCubemap = CUBEMAP ? true : false; +static const bool g_bFlashlight = FLASHLIGHT ? true : false; +static const bool g_bHalfLambert = HALFLAMBERT ? true : false; +#if (defined( SHADER_MODEL_VS_3_0 ) && MORPHING && DECAL) +static const bool g_bDecalOffset = true; +#else +static const bool g_bDecalOffset = false; +#endif + +const float4 cBaseTexCoordTransform[2] : register( SHADER_SPECIFIC_CONST_0 ); +#if SEAMLESS_DETAIL || SEAMLESS_BASE +const float cSeamlessScale : register( SHADER_SPECIFIC_CONST_2); +#define SEAMLESS_SCALE cSeamlessScale.x +#endif + +const float4 cDetailTexCoordTransform[2] : register( SHADER_SPECIFIC_CONST_4 ); + +#if defined ( _X360 ) +const float4x4 g_FlashlightWorldToTexture : register( SHADER_SPECIFIC_CONST_6 ); // 6, 7, 8, 9 +#endif + +#ifdef SHADER_MODEL_VS_3_0 +// NOTE: cMorphTargetTextureDim.xy = target dimensions, +// cMorphTargetTextureDim.z = 4tuples/morph +const float3 cMorphTargetTextureDim : register( SHADER_SPECIFIC_CONST_10 ); +const float4 cMorphSubrect : register( SHADER_SPECIFIC_CONST_11 ); +sampler2D morphSampler : register( D3DVERTEXTEXTURESAMPLER0, s0 ); +#endif + +struct VS_INPUT +{ + // This is all of the stuff that we ever use. + float4 vPos : POSITION; + float4 vBoneWeights : BLENDWEIGHT; + float4 vBoneIndices : BLENDINDICES; + float4 vNormal : NORMAL; + float4 vColor : COLOR0; + float3 vSpecular : COLOR1; + // make these float2's and stick the [n n 0 1] in the dot math. + float4 vTexCoord0 : TEXCOORD0; + float4 vTexCoord1 : TEXCOORD1; + float4 vTexCoord2 : TEXCOORD2; + float4 vTexCoord3 : TEXCOORD3; + + // Position and normal/tangent deltas + float3 vPosFlex : POSITION1; + float3 vNormalFlex : NORMAL1; +#ifdef SHADER_MODEL_VS_3_0 + float vVertexID : POSITION2; +#endif +}; + + +struct VS_OUTPUT +{ + float4 projPos : POSITION; // Projection-space position +#if !defined( _X360 ) + float fog : FOG; +#endif + +#if SEAMLESS_BASE + HALF3 SeamlessTexCoord : TEXCOORD0; // Base texture x/y/z (indexed by swizzle) +#else + HALF2 baseTexCoord : TEXCOORD0; // Base texture coordinate +#endif +#if SEAMLESS_DETAIL + HALF3 SeamlessDetailTexCoord : TEXCOORD1; // Detail texture coordinate +#else + HALF2 detailTexCoord : TEXCOORD1; // Detail texture coordinate +#endif + float4 color : TEXCOORD2; // Vertex color (from lighting or unlit) + +#if CUBEMAP || _X360 + float3 worldVertToEyeVector : TEXCOORD3; // Necessary for cubemaps +#endif + + float3 worldSpaceNormal : TEXCOORD4; // Necessary for cubemaps and flashlight + +#if defined ( _X360 ) && FLASHLIGHT + float4 flashlightSpacePos : TEXCOORD5; +#endif + + float4 vProjPos : TEXCOORD6; + float4 worldPos_ProjPosZ : TEXCOORD7; + float4 fogFactorW : COLOR1; +#if SEAMLESS_DETAIL || SEAMLESS_BASE + float3 SeamlessWeights : COLOR0; // x y z projection weights +#endif + +}; + +VS_OUTPUT main( const VS_INPUT v ) +{ + VS_OUTPUT o = ( VS_OUTPUT )0; + + bool bDynamicLight = DYNAMIC_LIGHT ? true : false; + bool bStaticLight = STATIC_LIGHT_VERTEX ? true : false; + bool bDoLighting = !g_bVertexColor && (bDynamicLight || bStaticLight); + + float4 vPosition = v.vPos; + float3 vNormal = 0; + if ( bDoLighting || FLASHLIGHT || SEAMLESS_BASE || SEAMLESS_DETAIL || LIGHTING_PREVIEW || g_bDecalOffset || CUBEMAP ) + { + // The vertex only contains valid normals if they are actually needed (fetching them when absent makes D3D complain) + DecompressVertex_Normal( v.vNormal, vNormal ); + } + +#if SEAMLESS_BASE || SEAMLESS_DETAIL + // compute blend weights in rgb + float3 NNormal=normalize( vNormal ); + o.SeamlessWeights.xyz = NNormal * NNormal; // sums to 1. +#endif + +#if !defined( SHADER_MODEL_VS_3_0 ) || !MORPHING + ApplyMorph( v.vPosFlex, v.vNormalFlex, vPosition.xyz, vNormal ); +#else + ApplyMorph( morphSampler, cMorphTargetTextureDim, cMorphSubrect, + v.vVertexID, v.vTexCoord2, vPosition.xyz, vNormal ); +#endif + + // Perform skinning + float3 worldNormal, worldPos; + SkinPositionAndNormal( + g_bSkinning, + vPosition, vNormal, + v.vBoneWeights, v.vBoneIndices, + worldPos, worldNormal ); + + if ( !g_bVertexColor ) + { + worldNormal = normalize( worldNormal ); + } + +#if defined( SHADER_MODEL_VS_3_0 ) && MORPHING && DECAL + // Avoid z precision errors + worldPos += worldNormal * 0.05f * v.vTexCoord2.z; +#endif + + o.worldSpaceNormal = worldNormal; + + // Transform into projection space + float4 vProjPos = mul( float4( worldPos, 1 ), cViewProj ); + o.projPos = vProjPos; + vProjPos.z = dot( float4( worldPos, 1 ), cViewProjZ ); + + o.vProjPos = vProjPos; + o.fogFactorW.w = CalcFog( worldPos, vProjPos, g_FogType ); +#if !defined( _X360 ) + o.fog = o.fogFactorW.w; +#endif + o.worldPos_ProjPosZ.xyz = worldPos.xyz; + o.worldPos_ProjPosZ.w = vProjPos.z; + + // Needed for cubemaps +#if CUBEMAP + o.worldVertToEyeVector.xyz = VSHADER_VECT_SCALE * (cEyePos - worldPos); +#endif + +#if !defined (_X360) && FLASHLIGHT + o.color = float4( 0.0f, 0.0f, 0.0f, 0.0f ); +#else + if ( g_bVertexColor ) + { + // Assume that this is unlitgeneric if you are using vertex color. + o.color.rgb = ( DONT_GAMMA_CONVERT_VERTEX_COLOR ) ? v.vColor.rgb : GammaToLinear( v.vColor.rgb ); + o.color.a = v.vColor.a; + } + else + { + #if ( ( USE_STATIC_CONTROL_FLOW ) || defined ( SHADER_MODEL_VS_3_0 ) ) + { + o.color.xyz = DoLighting( worldPos, worldNormal, v.vSpecular, bStaticLight, bDynamicLight, g_bHalfLambert ); + } + #else + { + o.color.xyz = DoLightingUnrolled( worldPos, worldNormal, v.vSpecular, bStaticLight, bDynamicLight, g_bHalfLambert, NUM_LIGHTS ); + } + #endif + } +#endif + + +#if SEAMLESS_BASE + o.SeamlessTexCoord.xyz = SEAMLESS_SCALE * v.vPos.xyz; +#else + // Base texture coordinates + o.baseTexCoord.x = dot( v.vTexCoord0, cBaseTexCoordTransform[0] ); + o.baseTexCoord.y = dot( v.vTexCoord0, cBaseTexCoordTransform[1] ); +#endif + +#if SEAMLESS_DETAIL + // FIXME: detail texcoord as a 2d xform doesn't make much sense here, so I just do enough so + // that scale works. More smartness could allow 3d xform. + o.SeamlessDetailTexCoord.xyz = (SEAMLESS_SCALE*cDetailTexCoordTransform[0].x) * v.vPos.xyz; +#else + // Detail texture coordinates + // FIXME: This shouldn't have to be computed all the time. + o.detailTexCoord.x = dot( v.vTexCoord0, cDetailTexCoordTransform[0] ); + o.detailTexCoord.y = dot( v.vTexCoord0, cDetailTexCoordTransform[1] ); +#endif + +#if SEPARATE_DETAIL_UVS + o.detailTexCoord.xy = v.vTexCoord1.xy; +#endif + +#if LIGHTING_PREVIEW + float dot=0.5+0.5*worldNormal*float3(0.7071,0.7071,0); + o.color.xyz=float3(dot,dot,dot); +#endif + +#if defined ( _X360 ) && FLASHLIGHT + o.flashlightSpacePos = mul( float4( worldPos, 1.0f ), g_FlashlightWorldToTexture ); +#endif + + return o; +} + + diff --git a/materialsystem/stdshaders/vertexlit_lighting_only_ps2x.fxc b/materialsystem/stdshaders/vertexlit_lighting_only_ps2x.fxc new file mode 100644 index 0000000..5281263 --- /dev/null +++ b/materialsystem/stdshaders/vertexlit_lighting_only_ps2x.fxc @@ -0,0 +1,68 @@ +//======= Copyright © 1996-2006, Valve Corporation, All rights reserved. ====== + +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX] +// STATIC: "DIFFUSELIGHTING" "0..1" +// STATIC: "HALFLAMBERT" "0..1" + +// DYNAMIC: "AMBIENT_LIGHT" "0..1" +// DYNAMIC: "NUM_LIGHTS" "0..2" [ps20] +// DYNAMIC: "NUM_LIGHTS" "0..4" [ps20b] + +#define HDRTYPE HDR_TYPE_NONE +#include "common_vertexlitgeneric_dx9.h" + +const float4 g_OverbrightFactor : register( c4 ); +const float3 cAmbientCube[6] : register( c6 ); + +PixelShaderLightInfo cLightInfo[3] : register(c13); + +sampler BumpmapSampler : register( s0 ); +sampler NormalizeSampler : register( s1 ); + +struct PS_INPUT +{ + float2 baseTexCoord : TEXCOORD0; + // detail textures and bumpmaps are mutually exclusive so that we have enough texcoords. + float2 detailOrBumpTexCoord : TEXCOORD1; + // bump mapping and a separate envmap mask texture are mutually exclusive. + float2 envmapMaskTexCoord : TEXCOORD2; + float3 worldVertToEyeVector : TEXCOORD3; + float3x3 tangentSpaceTranspose : TEXCOORD4; + float4 worldPos_projPosZ : TEXCOORD5; + float2 lightAtten01 : TEXCOORD6; + float2 lightAtten23 : TEXCOORD7; +}; + +float4 main( PS_INPUT i ) : COLOR +{ + bool bDiffuseLighting = DIFFUSELIGHTING ? true : false; + bool bHalfLambert = HALFLAMBERT ? true : false; + bool bAmbientLight = AMBIENT_LIGHT ? true : false; + int nNumLights = NUM_LIGHTS; + + float4 vLightAtten = float4( i.lightAtten01, i.lightAtten23 ); + + float3 tangentSpaceNormal = float3( 0.0f, 0.0f, 1.0f ); + float4 normalTexel = 1.0f; + float4 baseColor = float4( 1.0f, 1.0f, 1.0f, 1.0f ); + + normalTexel = tex2D( BumpmapSampler, i.detailOrBumpTexCoord ); + tangentSpaceNormal = 2.0f * normalTexel - 1.0f; + + float3 diffuseLighting = float3( 1.0f, 1.0f, 1.0f ); + if( bDiffuseLighting ) + { + float3 worldSpaceNormal = mul( i.tangentSpaceTranspose, tangentSpaceNormal ); + float3 staticLightingColor = float3( 0.0f, 0.0f, 0.0f ); + diffuseLighting = PixelShaderDoLighting( i.worldPos_projPosZ.xyz, worldSpaceNormal, + float3( 0.0f, 0.0f, 0.0f ), false, bAmbientLight, + vLightAtten, cAmbientCube, NormalizeSampler, nNumLights, cLightInfo, bHalfLambert, + false, 0, false, NormalizeSampler ); + // multiply by .5 since we want a 50% (in gamma space) reflective surface) + diffuseLighting *= pow( 0.5f, 2.2f ); + } + + return FinalOutput( float4( diffuseLighting, 1.0f ), 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE ); +} + diff --git a/materialsystem/stdshaders/vertexlit_notexture.psh b/materialsystem/stdshaders/vertexlit_notexture.psh new file mode 100644 index 0000000..5241abd --- /dev/null +++ b/materialsystem/stdshaders/vertexlit_notexture.psh @@ -0,0 +1,13 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; Draw a texture . . woo hoo! +; t0 - texture +; +; The texture coordinates need to be defined as follows: +; tc0 - texcoords +;------------------------------------------------------------------------------ + +mov r0, v0 +mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2) + diff --git a/materialsystem/stdshaders/vertexlitgeneric_basealphamaskedenvmap.psh b/materialsystem/stdshaders/vertexlitgeneric_basealphamaskedenvmap.psh new file mode 100644 index 0000000..db80aef --- /dev/null +++ b/materialsystem/stdshaders/vertexlitgeneric_basealphamaskedenvmap.psh @@ -0,0 +1,19 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; Draw a texture . . woo hoo! +; t0 - texture +; +; The texture coordinates need to be defined as follows: +; tc0 - texcoords +;------------------------------------------------------------------------------ + +tex t0 ; base color +tex t1 ; cube map +tex t2 ; envmap mask (in alpha channel) + +mul r0, t0, c3 ; base times modulation +mul r1, t1, 1-t2.a ; Envmap * mask (in alpha channel) +mad r0.rgb, r1, c2, r0 ; Base * mod + envmap * mask * tint +mul r0.rgb, v0, r0 ; apply vertex lighting +mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2) diff --git a/materialsystem/stdshaders/vertexlitgeneric_detailbasealphamaskedenvmap.psh b/materialsystem/stdshaders/vertexlitgeneric_detailbasealphamaskedenvmap.psh new file mode 100644 index 0000000..82989f4 --- /dev/null +++ b/materialsystem/stdshaders/vertexlitgeneric_detailbasealphamaskedenvmap.psh @@ -0,0 +1,21 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; Draw a texture . . woo hoo! +; t0 - texture +; +; The texture coordinates need to be defined as follows: +; tc0 - texcoords +;------------------------------------------------------------------------------ + +tex t0 ; base color +tex t1 ; cube map +tex t2 ; envmap mask (in alpha channel) +tex t3 ; detail texture + +mul r0, t0, c3 ; base times modulation +mul_x2 r0.rgb, r0, t3 ; detail texture +mul r1, t1, 1-t2.a ; Envmap * mask (in alpha channel) +mad r0.rgb, r1, c2, r0 ; Base * mod + envmap * mask * tint +mul r0.rgb, v0, r0 ; apply vertex lighting +mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2) diff --git a/materialsystem/stdshaders/vertexlitgeneric_detailenvmap.psh b/materialsystem/stdshaders/vertexlitgeneric_detailenvmap.psh new file mode 100644 index 0000000..e95d932 --- /dev/null +++ b/materialsystem/stdshaders/vertexlitgeneric_detailenvmap.psh @@ -0,0 +1,19 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; Draw a texture . . woo hoo! +; t0 - texture +; +; The texture coordinates need to be defined as follows: +; tc0 - texcoords +;------------------------------------------------------------------------------ + +tex t0 ; base color +tex t1 ; cube map +tex t3 ; detail texture + +mul r0, t0, c3 ; base times modulation +mul_x2 r0.rgb, r0, t3 ; detail texture +mad r0.rgb, t1, c2, r0 ; + envmap * envmaptint (color only) +mul r0.rgb, v0, r0 ; apply vertex lighting +mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2) diff --git a/materialsystem/stdshaders/vertexlitgeneric_detailmaskedenvmap.psh b/materialsystem/stdshaders/vertexlitgeneric_detailmaskedenvmap.psh new file mode 100644 index 0000000..ace4a68 --- /dev/null +++ b/materialsystem/stdshaders/vertexlitgeneric_detailmaskedenvmap.psh @@ -0,0 +1,21 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; Draw a texture . . woo hoo! +; t0 - texture +; +; The texture coordinates need to be defined as follows: +; tc0 - texcoords +;------------------------------------------------------------------------------ + +tex t0 ; base color +tex t1 ; cube map +tex t2 ; envmap mask +tex t3 ; detail texture + +mul r0, t0, c3 ; Base times modulation +mul_x2 r0.rgb, r0, t3 ; detail texture +mul r1, t1, t2 ; Envmap * mask +mad r0.rgb, r1, c2, r0 ; Base * mod + envmap * mask * tint +mul r0.rgb, v0, r0 ; apply vertex lighting +mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2) diff --git a/materialsystem/stdshaders/vertexlitgeneric_detailselfilluminatedenvmap.psh b/materialsystem/stdshaders/vertexlitgeneric_detailselfilluminatedenvmap.psh new file mode 100644 index 0000000..9cc7177 --- /dev/null +++ b/materialsystem/stdshaders/vertexlitgeneric_detailselfilluminatedenvmap.psh @@ -0,0 +1,28 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; Draw a texture . . woo hoo! +; t0 - texture +; +; The texture coordinates need to be defined as follows: +; tc0 - texcoords +;------------------------------------------------------------------------------ + +; Get the color from the texture +tex t0 +tex t1 +tex t3 + +mul r0.rgb, t0, c3 + ; base times modulation +mov r0.a, c3.a ; use modulation alpha (don't use texture alpha) + +mul_x2 r0.rgb, r0, t3 ; detail texture + +mad r0.rgb, t1, c2, r0 ; + envmap * envmaptint (color only) + +mul r0.rgb, v0, r0 ; Apply lighting +mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2) + +mul r1, t0, c1 ; Self illum * tint +lrp r0.rgb, t0.a, r1, r0 ; Blend between self-illum + base * lighting + diff --git a/materialsystem/stdshaders/vertexlitgeneric_detailselfilluminatedmaskedenvmap.psh b/materialsystem/stdshaders/vertexlitgeneric_detailselfilluminatedmaskedenvmap.psh new file mode 100644 index 0000000..24396a0 --- /dev/null +++ b/materialsystem/stdshaders/vertexlitgeneric_detailselfilluminatedmaskedenvmap.psh @@ -0,0 +1,29 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; Draw a texture . . woo hoo! +; t0 - texture +; +; The texture coordinates need to be defined as follows: +; tc0 - texcoords +;------------------------------------------------------------------------------ + +; Get the color from the texture +tex t0 ; base +tex t1 ; env map +tex t2 ; mask +tex t3 ; Detail + +mul r0.rgb, t0, c3 + ; base times modulation +mul r0.a, c3.a, t2.a ; alpha = mod alpha * mask alpha + +mul_x2 r0.rgb, r0, t3 ; detail texture + +mul r1, t2, t1 ; envmapmask * envmap +mad r0.rgb, r1, c2, r0 ; + envmapmask * envmap * envmaptint (color only) + +mul r0.rgb, v0, r0 ; Apply lighting +mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2) + +mul r1, t0, c1 ; Self illum * tint +lrp r0.rgb, t0.a, r1, r0 ; Blend between self-illum + base * lighting diff --git a/materialsystem/stdshaders/vertexlitgeneric_dx6.cpp b/materialsystem/stdshaders/vertexlitgeneric_dx6.cpp new file mode 100644 index 0000000..8ecd111 --- /dev/null +++ b/materialsystem/stdshaders/vertexlitgeneric_dx6.cpp @@ -0,0 +1,421 @@ +//========= 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" + +DEFINE_FALLBACK_SHADER( VertexLitGeneric, VertexLitGeneric_DX6 ) + +BEGIN_SHADER( VertexLitGeneric_DX6, + "Help for VertexLitGeneric_DX6" ) + + BEGIN_SHADER_PARAMS + SHADER_PARAM( DETAIL, SHADER_PARAM_TYPE_TEXTURE, "shadertest/detail", "detail texture" ) + SHADER_PARAM( DETAILSCALE, SHADER_PARAM_TYPE_FLOAT, "4", "scale of the detail texture" ) + SHADER_PARAM( SELFILLUMTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "Self-illumination tint" ) + SHADER_PARAM( ENVMAP, SHADER_PARAM_TYPE_TEXTURE, "shadertest/shadertest_env", "envmap" ) + SHADER_PARAM( ENVMAPFRAME, SHADER_PARAM_TYPE_INTEGER, "", "" ) + SHADER_PARAM( ENVMAPMASK, SHADER_PARAM_TYPE_TEXTURE, "shadertest/shadertest_envmask", "envmap mask" ) + SHADER_PARAM( ENVMAPMASKFRAME, SHADER_PARAM_TYPE_INTEGER, "", "" ) + SHADER_PARAM( ENVMAPMASKSCALE, SHADER_PARAM_TYPE_FLOAT, "1", "envmap mask scale" ) + SHADER_PARAM( ENVMAPTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "envmap tint" ) + SHADER_PARAM( ENVMAPOPTIONAL, SHADER_PARAM_TYPE_BOOL, "0", "Make the envmap only apply to dx9 and higher hardware" ) + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + SET_FLAGS2( MATERIAL_VAR2_SUPPORTS_HW_SKINNING ); + + if( !params[ENVMAPMASKSCALE]->IsDefined() ) + params[ENVMAPMASKSCALE]->SetFloatValue( 1.0f ); + + if( !params[ENVMAPTINT]->IsDefined() ) + params[ENVMAPTINT]->SetVecValue( 1.0f, 1.0f, 1.0f ); + + if( !params[SELFILLUMTINT]->IsDefined() ) + params[SELFILLUMTINT]->SetVecValue( 1.0f, 1.0f, 1.0f ); + + if( !params[DETAILSCALE]->IsDefined() ) + params[DETAILSCALE]->SetFloatValue( 4.0f ); + + // No envmap uses mode 0, it's one less pass + // Also, if multipass = 0, then go to mode 0 also + if ( ( !params[ENVMAP]->IsDefined() ) || + ( !IS_FLAG_SET(MATERIAL_VAR_MULTIPASS) ) ) + { + CLEAR_FLAGS( MATERIAL_VAR_ENVMAPMODE ); + } + + // Vertex color requires mode 1 + if ( IS_FLAG_SET(MATERIAL_VAR_VERTEXCOLOR) ) + { + SET_FLAGS( MATERIAL_VAR_ENVMAPMODE ); + } + + // No texture means no self-illum or env mask in base alpha + if ( !params[BASETEXTURE]->IsDefined() ) + { + CLEAR_FLAGS( MATERIAL_VAR_SELFILLUM ); + CLEAR_FLAGS( MATERIAL_VAR_BASEALPHAENVMAPMASK ); + } + + // If in decal mode, no debug override... + if ( IS_FLAG_SET(MATERIAL_VAR_DECAL) ) + { + SET_FLAGS( MATERIAL_VAR_NO_DEBUG_OVERRIDE ); + } + + SET_FLAGS2( MATERIAL_VAR2_LIGHTING_VERTEX_LIT ); + SET_FLAGS2( MATERIAL_VAR2_NEEDS_SOFTWARE_LIGHTING ); + + // Get rid of the envmap if it's optional for this dx level. + if( params[ENVMAPOPTIONAL]->IsDefined() && params[ENVMAPOPTIONAL]->GetIntValue() ) + { + params[ENVMAP]->SetUndefined(); + } + + // If mat_specular 0, then get rid of envmap + if( !g_pConfig->UseSpecular() && params[ENVMAP]->IsDefined() && params[BASETEXTURE]->IsDefined() ) + { + params[ENVMAP]->SetUndefined(); + } + } + + SHADER_FALLBACK + { + return 0; + } + + SHADER_INIT + { + if (params[BASETEXTURE]->IsDefined()) + { + LoadTexture( BASETEXTURE ); + + if (!params[BASETEXTURE]->GetTextureValue()->IsTranslucent()) + { + CLEAR_FLAGS( MATERIAL_VAR_SELFILLUM ); + CLEAR_FLAGS( MATERIAL_VAR_BASEALPHAENVMAPMASK ); + } + } + + if (params[DETAIL]->IsDefined()) + { + LoadTexture( DETAIL ); + } + + // Don't alpha test if the alpha channel is used for other purposes + if (IS_FLAG_SET(MATERIAL_VAR_SELFILLUM) || IS_FLAG_SET(MATERIAL_VAR_BASEALPHAENVMAPMASK) ) + CLEAR_FLAGS( MATERIAL_VAR_ALPHATEST ); + + if (params[ENVMAP]->IsDefined()) + { + if( !IS_FLAG_SET(MATERIAL_VAR_ENVMAPSPHERE) ) + LoadCubeMap( ENVMAP ); + else + LoadTexture( ENVMAP ); + + if( !g_pHardwareConfig->SupportsCubeMaps() ) + { + SET_FLAGS( MATERIAL_VAR_ENVMAPSPHERE ); + } + + if (params[ENVMAPMASK]->IsDefined()) + LoadTexture( ENVMAPMASK ); + } + } + + int GetDrawFlagsPass1(IMaterialVar** params) + { + int flags = SHADER_DRAW_POSITION | SHADER_DRAW_COLOR; + if (params[BASETEXTURE]->IsTexture()) + flags |= SHADER_DRAW_TEXCOORD0; + return flags; + } + + void DrawVertexLightingOnly( IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow ) + { + SHADOW_STATE + { + pShaderShadow->EnableTexture( SHADER_SAMPLER0, false ); + + SetModulationShadowState(); + SetDefaultBlendingShadowState( ); + pShaderShadow->DrawFlags( GetDrawFlagsPass1( params ) ); + DefaultFog(); + } + DYNAMIC_STATE + { + SetModulationDynamicState(); + } + Draw(); + } + + void MultiplyByVertexLighting( IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow ) + { + SHADOW_STATE + { + // FIXME: How to deal with texture alpha?? + + pShaderShadow->EnableTexGen( SHADER_TEXTURE_STAGE0, false ); + pShaderShadow->EnableTexGen( SHADER_TEXTURE_STAGE1, false ); + pShaderShadow->EnableTexture( SHADER_SAMPLER0, false ); + pShaderShadow->EnableTexture( SHADER_SAMPLER1, false ); + + // NOTE: We're not doing lightmapping here, but we want to use the + // same blend mode as we used for lightmapping + pShaderShadow->EnableBlending( true ); + SingleTextureLightmapBlendMode(); + + pShaderShadow->EnableCustomPixelPipe( true ); + pShaderShadow->CustomTextureStages( 1 ); + + // This here will perform color = vertex light * (cc alpha) + 1 * (1 - cc alpha) + pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE0, + SHADER_TEXCHANNEL_COLOR, SHADER_TEXOP_BLEND_CONSTANTALPHA, + SHADER_TEXARG_VERTEXCOLOR, SHADER_TEXARG_CONSTANTCOLOR ); + + // Alpha isn't used, it doesn't matter what we set it to. + pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE0, + SHADER_TEXCHANNEL_ALPHA, SHADER_TEXOP_SELECTARG1, + SHADER_TEXARG_NONE, SHADER_TEXARG_NONE ); + + pShaderShadow->DrawFlags( SHADER_DRAW_POSITION | SHADER_DRAW_COLOR ); + FogToOOOverbright(); + } + DYNAMIC_STATE + { + // Put the alpha in the color channel to modulate the color down.... + float alpha = GetAlpha(); + pShaderAPI->Color4f( OO_OVERBRIGHT, OO_OVERBRIGHT, OO_OVERBRIGHT, alpha ); + } + Draw(); + + SHADOW_STATE + { + pShaderShadow->EnableCustomPixelPipe( false ); + } + } + + + //----------------------------------------------------------------------------- + // Used by mode 1 + //----------------------------------------------------------------------------- + + void DrawBaseTimesVertexLighting( IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow ) + { + // Base times vertex lighting, no vertex color + SHADOW_STATE + { + // alpha test + pShaderShadow->EnableAlphaTest( IS_FLAG_SET(MATERIAL_VAR_ALPHATEST) ); + + // base + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->OverbrightValue( SHADER_TEXTURE_STAGE0, OVERBRIGHT ); + + // Independenly configure alpha and color + + // Color = Color mod * Vertex Light * Tex (x2) + // Alpha = Constant Alpha * Tex Alpha (no tex alpha if self illum == 1) + // Can't have color modulation here + pShaderShadow->EnableConstantColor( IsColorModulating() ); + + // Independenly configure alpha and color + pShaderShadow->EnableAlphaPipe( true ); + pShaderShadow->EnableConstantAlpha( IsAlphaModulating() ); + pShaderShadow->EnableVertexAlpha( IS_FLAG_SET(MATERIAL_VAR_VERTEXALPHA) ); + + if (!IS_FLAG_SET(MATERIAL_VAR_SELFILLUM) && !IS_FLAG_SET(MATERIAL_VAR_BASEALPHAENVMAPMASK)) + pShaderShadow->EnableTextureAlpha( SHADER_TEXTURE_STAGE0, true ); + + SetDefaultBlendingShadowState( BASETEXTURE, true ); + pShaderShadow->DrawFlags( GetDrawFlagsPass1( params ) ); + DefaultFog(); + } + DYNAMIC_STATE + { + SetFixedFunctionTextureTransform( MATERIAL_TEXTURE0, BASETEXTURETRANSFORM ); + BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME ); + SetModulationDynamicState(); + } + Draw(); + + SHADOW_STATE + { + pShaderShadow->EnableAlphaPipe( false ); + } + } + + //----------------------------------------------------------------------------- + // Envmap times vertex lighting, no vertex color + //----------------------------------------------------------------------------- + + void DrawEnvmapTimesVertexLighting( IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow ) + { + SHADOW_STATE + { + int materialVarFlags = params[FLAGS]->GetIntValue(); + + // alpha test + pShaderShadow->EnableAlphaTest( false ); + + int flags = SetShadowEnvMappingState( ENVMAPMASK ) | SHADER_DRAW_COLOR; + bool hasEnvMapMask = params[ENVMAPMASK]->IsTexture(); + + pShaderShadow->OverbrightValue( hasEnvMapMask ? + SHADER_TEXTURE_STAGE1 : SHADER_TEXTURE_STAGE0, OVERBRIGHT ); + + // Independenly configure alpha and color + + // Color = Env map * Vertex Light * Envmapmask (x2) + // Alpha = Constant Alpha * Vertex light alpha * Env Map mask Alpha + pShaderShadow->EnableConstantColor( IsColorModulating() ); + + pShaderShadow->EnableAlphaPipe( true ); + pShaderShadow->EnableConstantAlpha( IsAlphaModulating() ); + pShaderShadow->EnableVertexAlpha( (materialVarFlags & MATERIAL_VAR_VERTEXALPHA) != 0 ); + if (hasEnvMapMask) + pShaderShadow->EnableTextureAlpha( SHADER_TEXTURE_STAGE1, true ); + + SetDefaultBlendingShadowState( BASETEXTURE, true ); + + pShaderShadow->DrawFlags( flags ); + DefaultFog(); + } + DYNAMIC_STATE + { + SetDynamicEnvMappingState( ENVMAP, ENVMAPMASK, BASETEXTURE, + ENVMAPFRAME, ENVMAPMASKFRAME, FRAME, + BASETEXTURETRANSFORM, ENVMAPMASKSCALE ); + } + Draw(); + + SHADOW_STATE + { + pShaderShadow->EnableCustomPixelPipe( false ); + pShaderShadow->EnableAlphaPipe( false ); + } + } + + void DrawMode1( IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow ) + { + bool texDefined = params[BASETEXTURE]->IsTexture(); + bool envDefined = params[ENVMAP]->IsTexture(); +// bool maskDefined = params[ENVMAPMASK]->IsTexture(); + + // Pass 1 : Base + env + + // FIXME: Could make it 1 pass for base + env, if it wasn't + // for the envmap tint. So this is 3 passes for now.... + + // If it's base + mask * env, gotta do that in 2 passes + // Gotta do funky stuff to fade out self-illuminated stuff + bool hasEnvMapTint = !IsWhite(ENVMAPTINT); + + // Special case, can do in one pass + if (!hasEnvMapTint && !texDefined && !IS_FLAG_SET(MATERIAL_VAR_VERTEXCOLOR) && + !IsColorModulating() ) + { + DrawEnvmapTimesVertexLighting( params, pShaderAPI, pShaderShadow ); + return; + } + + if (texDefined) + { + FixedFunctionBaseTimesDetailPass( + BASETEXTURE, FRAME, BASETEXTURETRANSFORM, DETAIL, DETAILSCALE ); + } + else + { + FixedFunctionMaskedEnvmapPass( + ENVMAP, ENVMAPMASK, BASETEXTURE, + ENVMAPFRAME, ENVMAPMASKFRAME, FRAME, + BASETEXTURETRANSFORM, ENVMAPMASKSCALE, ENVMAPTINT ); + } + + // We can get here if multipass isn't set if we specify a vertex color + if ( IS_FLAG_SET(MATERIAL_VAR_MULTIPASS) ) + { + if ( texDefined && envDefined ) + { + FixedFunctionAdditiveMaskedEnvmapPass( + ENVMAP, ENVMAPMASK, BASETEXTURE, + ENVMAPFRAME, ENVMAPMASKFRAME, FRAME, + BASETEXTURETRANSFORM, ENVMAPMASKSCALE, ENVMAPTINT ); + } + } + + // Pass 2 : * vertex lighting + MultiplyByVertexLighting( params, pShaderAPI, pShaderShadow ); + + // FIXME: We could add it to the lightmap + // Draw the selfillum pass (blows away envmap at self-illum points) + if ( IS_FLAG_SET(MATERIAL_VAR_SELFILLUM) ) + { + FixedFunctionSelfIlluminationPass( + SHADER_SAMPLER0, BASETEXTURE, FRAME, BASETEXTURETRANSFORM, SELFILLUMTINT ); + } + } + + void DrawMode0( IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow ) + { + // Pass 1 : Base * lightmap or just lightmap + if ( params[BASETEXTURE]->IsTexture() ) + { + DrawBaseTimesVertexLighting( params, pShaderAPI, pShaderShadow ); + + // Detail map + FixedFunctionMultiplyByDetailPass( + BASETEXTURE, FRAME, BASETEXTURETRANSFORM, DETAIL, DETAILSCALE ); + + // Draw the selfillum pass + if ( IS_FLAG_SET(MATERIAL_VAR_SELFILLUM) ) + { + FixedFunctionSelfIlluminationPass( + SHADER_SAMPLER0, BASETEXTURE, FRAME, BASETEXTURETRANSFORM, SELFILLUMTINT ); + } + } + else + { + DrawVertexLightingOnly( params, pShaderAPI, pShaderShadow ); + + // Detail map + FixedFunctionMultiplyByDetailPass( + BASETEXTURE, FRAME, BASETEXTURETRANSFORM, DETAIL, DETAILSCALE ); + } + + // Pass 2 : Masked environment map + if ( params[ENVMAP]->IsTexture() && + (IS_FLAG_SET(MATERIAL_VAR_MULTIPASS)) ) + { + FixedFunctionAdditiveMaskedEnvmapPass( + ENVMAP, ENVMAPMASK, BASETEXTURE, + ENVMAPFRAME, ENVMAPMASKFRAME, FRAME, + BASETEXTURETRANSFORM, ENVMAPMASKSCALE, ENVMAPTINT ); + } + } + + SHADER_DRAW + { + bool useMode1 = IS_FLAG_SET(MATERIAL_VAR_ENVMAPMODE); + if (!useMode1) + { + // Base * Vertex Lighting + env + DrawMode0( params, pShaderAPI, pShaderShadow ); + } + else + { + // ( Base + env ) * Vertex Lighting + DrawMode1( params, pShaderAPI, pShaderShadow ); + } + } +END_SHADER + diff --git a/materialsystem/stdshaders/vertexlitgeneric_dx7.cpp b/materialsystem/stdshaders/vertexlitgeneric_dx7.cpp new file mode 100644 index 0000000..7a114a5 --- /dev/null +++ b/materialsystem/stdshaders/vertexlitgeneric_dx7.cpp @@ -0,0 +1,413 @@ +//========= 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" + +DEFINE_FALLBACK_SHADER( VertexLitGeneric, VertexLitGeneric_DX7 ) +DEFINE_FALLBACK_SHADER( Skin_DX9, VertexLitGeneric_DX7 ) + +BEGIN_SHADER( VertexLitGeneric_DX7, + "Help for VertexLitGeneric_DX7" ) + + BEGIN_SHADER_PARAMS + SHADER_PARAM( DETAIL, SHADER_PARAM_TYPE_TEXTURE, "shadertest/detail", "detail texture" ) + SHADER_PARAM( DETAILSCALE, SHADER_PARAM_TYPE_FLOAT, "4", "scale of the detail texture" ) + SHADER_PARAM( SELFILLUMTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "Self-illumination tint" ) + SHADER_PARAM( ENVMAP, SHADER_PARAM_TYPE_TEXTURE, "shadertest/shadertest_env", "envmap" ) + SHADER_PARAM( ENVMAPFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "" ) + SHADER_PARAM( ENVMAPMASK, SHADER_PARAM_TYPE_TEXTURE, "shadertest/shadertest_envmask", "envmap mask" ) + SHADER_PARAM( ENVMAPMASKFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "" ) + SHADER_PARAM( ENVMAPMASKSCALE, SHADER_PARAM_TYPE_FLOAT, "1", "envmap mask scale" ) + SHADER_PARAM( ENVMAPTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "envmap tint" ) + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + // FLASHLIGHTFIXME + params[FLASHLIGHTTEXTURE]->SetStringValue( "effects/flashlight001" ); + + SET_FLAGS2( MATERIAL_VAR2_SUPPORTS_HW_SKINNING ); + + if( !params[ENVMAPMASKSCALE]->IsDefined() ) + params[ENVMAPMASKSCALE]->SetFloatValue( 1.0f ); + + if( !params[ENVMAPTINT]->IsDefined() ) + params[ENVMAPTINT]->SetVecValue( 1.0f, 1.0f, 1.0f ); + + if( !params[SELFILLUMTINT]->IsDefined() ) + params[SELFILLUMTINT]->SetVecValue( 1.0f, 1.0f, 1.0f ); + + if( !params[DETAILSCALE]->IsDefined() ) + params[DETAILSCALE]->SetFloatValue( 4.0f ); + + // No texture means no self-illum or env mask in base alpha + if ( !params[BASETEXTURE]->IsDefined() ) + { + CLEAR_FLAGS( MATERIAL_VAR_SELFILLUM ); + CLEAR_FLAGS( MATERIAL_VAR_BASEALPHAENVMAPMASK ); + } + + // If in decal mode, no debug override... + if (IS_FLAG_SET(MATERIAL_VAR_DECAL)) + { + SET_FLAGS( MATERIAL_VAR_NO_DEBUG_OVERRIDE ); + } + + SET_FLAGS2( MATERIAL_VAR2_LIGHTING_VERTEX_LIT ); + SET_FLAGS2( MATERIAL_VAR2_NEEDS_BAKED_LIGHTING_SNAPSHOTS ); + + // If mat_specular 0, then get rid of envmap + if( !g_pConfig->UseSpecular() && params[ENVMAP]->IsDefined() && params[BASETEXTURE]->IsDefined() ) + { + params[ENVMAP]->SetUndefined(); + } + } + + SHADER_FALLBACK + { + if (g_pHardwareConfig->GetDXSupportLevel() < 70) + return "VertexLitGeneric_DX6"; + + return 0; + } + + SHADER_INIT + { + LoadTexture( FLASHLIGHTTEXTURE ); + if (params[BASETEXTURE]->IsDefined()) + { + LoadTexture( BASETEXTURE ); + + if (!params[BASETEXTURE]->GetTextureValue()->IsTranslucent()) + { + CLEAR_FLAGS( MATERIAL_VAR_SELFILLUM ); + CLEAR_FLAGS( MATERIAL_VAR_BASEALPHAENVMAPMASK ); + } + } + + if (params[DETAIL]->IsDefined()) + { + LoadTexture( DETAIL ); + } + + // Don't alpha test if the alpha channel is used for other purposes + if (IS_FLAG_SET(MATERIAL_VAR_SELFILLUM) || IS_FLAG_SET(MATERIAL_VAR_BASEALPHAENVMAPMASK) ) + CLEAR_FLAGS( MATERIAL_VAR_ALPHATEST ); + + if (params[ENVMAP]->IsDefined()) + { + if( !IS_FLAG_SET(MATERIAL_VAR_ENVMAPSPHERE) ) + LoadCubeMap( ENVMAP ); + else + LoadTexture( ENVMAP ); + + if( !g_pHardwareConfig->SupportsCubeMaps() ) + { + SET_FLAGS( MATERIAL_VAR_ENVMAPSPHERE ); + } + + if (params[ENVMAPMASK]->IsDefined()) + LoadTexture( ENVMAPMASK ); + } + } + + void DrawBaseTimesVertexColor( IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow ) + { + SHADOW_STATE + { + // alpha test + pShaderShadow->EnableAlphaTest( IS_FLAG_SET(MATERIAL_VAR_ALPHATEST) ); + + pShaderShadow->EnableCustomPixelPipe( true ); + + pShaderShadow->CustomTextureStages( 1 ); + + pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE0, + SHADER_TEXCHANNEL_COLOR, SHADER_TEXOP_MODULATE2X, + SHADER_TEXARG_TEXTURE, SHADER_TEXARG_VERTEXCOLOR ); + + // Get alpha from the texture so that alpha blend and alpha test work properly. + bool bTextureIsTranslucent = TextureIsTranslucent( BASETEXTURE, true ); + if ( bTextureIsTranslucent ) + { + pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE0, + SHADER_TEXCHANNEL_ALPHA, SHADER_TEXOP_SELECTARG1, + SHADER_TEXARG_TEXTURE, SHADER_TEXARG_NONE ); + } + else + { + if ( IsAlphaModulating() ) + { + pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE0, + SHADER_TEXCHANNEL_ALPHA, SHADER_TEXOP_SELECTARG1, + SHADER_TEXARG_CONSTANTCOLOR, SHADER_TEXARG_NONE ); + } + else + { + pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE0, + SHADER_TEXCHANNEL_ALPHA, SHADER_TEXOP_SELECTARG1, + SHADER_TEXARG_ONE, SHADER_TEXARG_NONE ); + } + } + + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + int flags = SHADER_DRAW_POSITION | SHADER_DRAW_NORMAL | SHADER_DRAW_TEXCOORD0; + pShaderShadow->DrawFlags( flags ); + DefaultFog(); + + if ( IsAlphaModulating() || IsColorModulating() ) + { + pShaderShadow->CustomTextureStages( 2 ); + + if ( IsColorModulating() ) + { + pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE1, + SHADER_TEXCHANNEL_COLOR, SHADER_TEXOP_MODULATE, + SHADER_TEXARG_PREVIOUSSTAGE, SHADER_TEXARG_CONSTANTCOLOR ); + } + else + { + pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE1, + SHADER_TEXCHANNEL_COLOR, SHADER_TEXOP_SELECTARG1, + SHADER_TEXARG_PREVIOUSSTAGE, SHADER_TEXARG_NONE ); + } + + // Get alpha from the texture so that alpha blend and alpha test work properly. + if ( IsAlphaModulating() && bTextureIsTranslucent ) + { + pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE1, + SHADER_TEXCHANNEL_ALPHA, SHADER_TEXOP_MODULATE, + SHADER_TEXARG_PREVIOUSSTAGE, SHADER_TEXARG_CONSTANTCOLOR ); + } + else + { + pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE1, + SHADER_TEXCHANNEL_ALPHA, SHADER_TEXOP_SELECTARG1, + SHADER_TEXARG_PREVIOUSSTAGE, SHADER_TEXARG_NONE ); + } + } + + SetDefaultBlendingShadowState( BASETEXTURE, true ); + } + DYNAMIC_STATE + { + SetFixedFunctionTextureTransform( MATERIAL_TEXTURE0, BASETEXTURETRANSFORM ); + BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME ); + SetModulationDynamicState(); + } + Draw(); + } + + void DrawVertexColorNoBase( IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow ) + { + SHADOW_STATE + { + pShaderShadow->EnableCustomPixelPipe( true ); + + pShaderShadow->CustomTextureStages( 1 ); + + pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE0, + SHADER_TEXCHANNEL_COLOR, SHADER_TEXOP_MODULATE2X, + SHADER_TEXARG_ONE, SHADER_TEXARG_VERTEXCOLOR ); + + int flags = SHADER_DRAW_POSITION; + pShaderShadow->DrawFlags( flags ); + DefaultFog(); + } + DYNAMIC_STATE + { +// SetModulationDynamicState(); + } + Draw(); + } + + void DrawBaseTimesBakedVertexLighting( IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow ) + { + SHADOW_STATE + { + // alpha test + pShaderShadow->EnableAlphaTest( IS_FLAG_SET( MATERIAL_VAR_ALPHATEST ) ); + + // base + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + int flags = SHADER_DRAW_POSITION; + if (params[BASETEXTURE]->IsTexture()) + { + flags |= SHADER_DRAW_TEXCOORD1; + } + pShaderShadow->DrawFlags( flags ); + DefaultFog(); + + pShaderShadow->EnableCustomPixelPipe( true ); + pShaderShadow->CustomTextureStages( 1 ); + + pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE0, + SHADER_TEXCHANNEL_COLOR, + SHADER_TEXOP_MODULATE2X, + SHADER_TEXARG_SPECULARCOLOR, SHADER_TEXARG_TEXTURE ); + + // Get alpha from the texture so that alpha blend and alpha test work properly. + bool bTextureIsTranslucent = TextureIsTranslucent( BASETEXTURE, true ); + if ( bTextureIsTranslucent ) + { + pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE0, + SHADER_TEXCHANNEL_ALPHA, SHADER_TEXOP_SELECTARG1, + SHADER_TEXARG_TEXTURE, SHADER_TEXARG_NONE ); + } + else + { + if ( IsAlphaModulating() ) + { + pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE0, + SHADER_TEXCHANNEL_ALPHA, SHADER_TEXOP_SELECTARG1, + SHADER_TEXARG_CONSTANTCOLOR, SHADER_TEXARG_NONE ); + } + else + { + pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE0, + SHADER_TEXCHANNEL_ALPHA, SHADER_TEXOP_SELECTARG1, + SHADER_TEXARG_ONE, SHADER_TEXARG_NONE ); + } + } + + if ( IsAlphaModulating() || IsColorModulating() ) + { + pShaderShadow->CustomTextureStages( 2 ); + + if ( IsColorModulating()) + { + pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE1, + SHADER_TEXCHANNEL_COLOR, SHADER_TEXOP_MODULATE, + SHADER_TEXARG_PREVIOUSSTAGE, SHADER_TEXARG_CONSTANTCOLOR ); + } + else + { + pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE1, + SHADER_TEXCHANNEL_COLOR, SHADER_TEXOP_SELECTARG1, + SHADER_TEXARG_PREVIOUSSTAGE, SHADER_TEXARG_NONE ); + } + + // Get alpha from the texture so that alpha blend and alpha test work properly. + if ( IsAlphaModulating() && bTextureIsTranslucent ) + { + pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE1, + SHADER_TEXCHANNEL_ALPHA, SHADER_TEXOP_MODULATE, + SHADER_TEXARG_PREVIOUSSTAGE, SHADER_TEXARG_CONSTANTCOLOR ); + } + else + { + pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE1, + SHADER_TEXCHANNEL_ALPHA, SHADER_TEXOP_SELECTARG1, + SHADER_TEXARG_PREVIOUSSTAGE, SHADER_TEXARG_NONE ); + } + } + + SetDefaultBlendingShadowState( BASETEXTURE, true ); + } + DYNAMIC_STATE + { + SetFixedFunctionTextureTransform( MATERIAL_TEXTURE1, BASETEXTURETRANSFORM ); + BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME ); + SetModulationDynamicState(); + } + Draw(); + } + + void DrawBakedVertexLightingNoBase( IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow ) + { + SHADOW_STATE + { + int flags = SHADER_DRAW_POSITION; + pShaderShadow->DrawFlags( flags ); + DefaultFog(); + + pShaderShadow->EnableCustomPixelPipe( true ); + pShaderShadow->CustomTextureStages( 1 ); + + pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE0, + SHADER_TEXCHANNEL_COLOR, + SHADER_TEXOP_MODULATE2X, + SHADER_TEXARG_SPECULARCOLOR, SHADER_TEXARG_NONE ); + + // Alpha isn't used, it doesn't matter what we set it to. + pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE0, + SHADER_TEXCHANNEL_ALPHA, SHADER_TEXOP_SELECTARG1, + SHADER_TEXARG_NONE, SHADER_TEXARG_NONE ); + } + DYNAMIC_STATE + { + } + Draw(); + } + + SHADER_DRAW + { + bool bBakedLighting = IS_FLAG2_SET( MATERIAL_VAR2_USE_FIXED_FUNCTION_BAKED_LIGHTING ); + bool hasFlashlight = UsingFlashlight( params ); + + if( hasFlashlight ) + { + DrawFlashlight_dx70( params, pShaderAPI, pShaderShadow, FLASHLIGHTTEXTURE, FLASHLIGHTTEXTUREFRAME ); + return; + } + // Pass 1 : Base * lightmap or just lightmap + if ( params[BASETEXTURE]->IsTexture() ) + { + // Draw base times lighting. + // Lighting is either sent down per vertex from the app, or it's in the second + // stream as color values. + if( bBakedLighting ) + { + DrawBaseTimesBakedVertexLighting( params, pShaderAPI, pShaderShadow ); + } + else + { + DrawBaseTimesVertexColor( params, pShaderAPI, pShaderShadow ); + } + + // Detail map + FixedFunctionMultiplyByDetailPass( + BASETEXTURE, FRAME, BASETEXTURETRANSFORM, DETAIL, DETAILSCALE ); + + // Draw the selfillum pass + if ( IS_FLAG_SET(MATERIAL_VAR_SELFILLUM) ) + { + FixedFunctionSelfIlluminationPass( + SHADER_SAMPLER0, BASETEXTURE, FRAME, BASETEXTURETRANSFORM, SELFILLUMTINT ); + } + } + else + { + if( bBakedLighting ) + { + DrawBakedVertexLightingNoBase( params, pShaderAPI, pShaderShadow ); + } + else + { + DrawVertexColorNoBase( params, pShaderAPI, pShaderShadow ); + } + + FixedFunctionMultiplyByDetailPass( + BASETEXTURE, FRAME, BASETEXTURETRANSFORM, DETAIL, DETAILSCALE ); + } + + + // Pass 2 : Masked environment map + if ( params[ENVMAP]->IsTexture() && (IS_FLAG_SET(MATERIAL_VAR_MULTIPASS)) ) + { + FixedFunctionAdditiveMaskedEnvmapPass( + ENVMAP, ENVMAPMASK, BASETEXTURE, + ENVMAPFRAME, ENVMAPMASKFRAME, FRAME, + BASETEXTURETRANSFORM, ENVMAPMASKSCALE, ENVMAPTINT ); + } + + } +END_SHADER diff --git a/materialsystem/stdshaders/vertexlitgeneric_dx8.cpp b/materialsystem/stdshaders/vertexlitgeneric_dx8.cpp new file mode 100644 index 0000000..31addf4 --- /dev/null +++ b/materialsystem/stdshaders/vertexlitgeneric_dx8.cpp @@ -0,0 +1,807 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $Header: $ +// $NoKeywords: $ +//=============================================================================// + +#include "BaseVSShader.h" + +#include "vertexlitgeneric_vs11.inc" +#include "vertexlitgeneric_selfillumonly.inc" +#include "emissive_scroll_blended_pass_helper.h" +#include "flesh_interior_blended_pass_helper.h" +#include "cloak_blended_pass_helper.h" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +DEFINE_FALLBACK_SHADER( VertexLitGeneric, VertexLitGeneric_DX8 ) +DEFINE_FALLBACK_SHADER( Skin_DX9, VertexLitGeneric_DX8 ) + +BEGIN_VS_SHADER( VertexLitGeneric_DX8, + "Help for VertexLitGeneric" ) + BEGIN_SHADER_PARAMS + SHADER_PARAM( SELFILLUMTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "Self-illumination tint" ) + SHADER_PARAM( DETAIL, SHADER_PARAM_TYPE_TEXTURE, "shadertest/detail", "detail texture" ) + SHADER_PARAM( DETAILSCALE, SHADER_PARAM_TYPE_FLOAT, "4", "scale of the detail texture" ) + SHADER_PARAM( DETAILFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $detail" ) + SHADER_PARAM( ENVMAP, SHADER_PARAM_TYPE_TEXTURE, "shadertest/shadertest_env", "envmap" ) + SHADER_PARAM( ENVMAPFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "envmap frame number" ) + SHADER_PARAM( ENVMAPMASK, SHADER_PARAM_TYPE_TEXTURE, "shadertest/shadertest_envmask", "envmap mask" ) + SHADER_PARAM( ENVMAPMASKFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "" ) + SHADER_PARAM( ENVMAPMASKSCALE, SHADER_PARAM_TYPE_FLOAT, "1", "envmap mask scale" ) + SHADER_PARAM( ENVMAPTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "envmap tint" ) + SHADER_PARAM( BUMPMAP, SHADER_PARAM_TYPE_TEXTURE, "models/shadertest/shader1_normal", "bump map" ) + SHADER_PARAM( BUMPFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $bumpmap" ) + SHADER_PARAM( BUMPTRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$bumpmap texcoord transform" ) + SHADER_PARAM( ENVMAPCONTRAST, SHADER_PARAM_TYPE_FLOAT, "0.0", "contrast 0 == normal 1 == color*color" ) + SHADER_PARAM( ENVMAPSATURATION, SHADER_PARAM_TYPE_FLOAT, "1.0", "saturation 0 == greyscale 1 == normal" ) + SHADER_PARAM( ENVMAPOPTIONAL, SHADER_PARAM_TYPE_BOOL, "0", "Make the envmap only apply to dx9 and higher hardware" ) + SHADER_PARAM( FORCEBUMP, SHADER_PARAM_TYPE_BOOL, "0", "0 == Do bumpmapping if the card says it can handle it. 1 == Always do bumpmapping." ) + SHADER_PARAM( ALPHATESTREFERENCE, SHADER_PARAM_TYPE_FLOAT, "0.0", "" ) + + SHADER_PARAM( DETAILBLENDMODE, SHADER_PARAM_TYPE_INTEGER, "0", "mode for combining detail texture with base. 0=normal, 1= additive, 2=alpha blend detail over base, 3=crossfade" ) + SHADER_PARAM( DETAILBLENDFACTOR, SHADER_PARAM_TYPE_FLOAT, "1", "blend amount for detail texture." ) + + // Emissive Scroll Pass + SHADER_PARAM( EMISSIVEBLENDENABLED, SHADER_PARAM_TYPE_BOOL, "0", "Enable emissive blend pass" ) + SHADER_PARAM( EMISSIVEBLENDBASETEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "self-illumination map" ) + SHADER_PARAM( EMISSIVEBLENDSCROLLVECTOR, SHADER_PARAM_TYPE_VEC2, "[0.11 0.124]", "Emissive scroll vec" ) + SHADER_PARAM( EMISSIVEBLENDSTRENGTH, SHADER_PARAM_TYPE_FLOAT, "1.0", "Emissive blend strength" ) + SHADER_PARAM( EMISSIVEBLENDTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "self-illumination map" ) + SHADER_PARAM( EMISSIVEBLENDTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "Self-illumination tint" ) + SHADER_PARAM( TIME, SHADER_PARAM_TYPE_FLOAT, "0.0", "Needs CurrentTime Proxy" ) + + // Cloak Pass + SHADER_PARAM( CLOAKPASSENABLED, SHADER_PARAM_TYPE_BOOL, "0", "Enables cloak render in a second pass" ) + SHADER_PARAM( CLOAKFACTOR, SHADER_PARAM_TYPE_FLOAT, "0.0", "" ) + SHADER_PARAM( CLOAKCOLORTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "Cloak color tint" ) + SHADER_PARAM( REFRACTAMOUNT, SHADER_PARAM_TYPE_FLOAT, "2", "" ) + + // Flesh Interior Pass + SHADER_PARAM( FLESHINTERIORENABLED, SHADER_PARAM_TYPE_BOOL, "0", "Enable Flesh interior blend pass" ) + SHADER_PARAM( FLESHINTERIORTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "Flesh color texture" ) + SHADER_PARAM( FLESHINTERIORNOISETEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "Flesh noise texture" ) + SHADER_PARAM( FLESHBORDERTEXTURE1D, SHADER_PARAM_TYPE_TEXTURE, "", "Flesh border 1D texture" ) + SHADER_PARAM( FLESHNORMALTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "Flesh normal texture" ) + SHADER_PARAM( FLESHSUBSURFACETEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "Flesh subsurface texture" ) + SHADER_PARAM( FLESHCUBETEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "Flesh cubemap texture" ) + SHADER_PARAM( FLESHBORDERNOISESCALE, SHADER_PARAM_TYPE_FLOAT, "1.5", "Flesh Noise UV scalar for border" ) + SHADER_PARAM( FLESHDEBUGFORCEFLESHON, SHADER_PARAM_TYPE_BOOL, "0", "Flesh Debug full flesh" ) + SHADER_PARAM( FLESHEFFECTCENTERRADIUS1, SHADER_PARAM_TYPE_VEC4, "[0 0 0 0.001]", "Flesh effect center and radius" ) + SHADER_PARAM( FLESHEFFECTCENTERRADIUS2, SHADER_PARAM_TYPE_VEC4, "[0 0 0 0.001]", "Flesh effect center and radius" ) + SHADER_PARAM( FLESHEFFECTCENTERRADIUS3, SHADER_PARAM_TYPE_VEC4, "[0 0 0 0.001]", "Flesh effect center and radius" ) + SHADER_PARAM( FLESHEFFECTCENTERRADIUS4, SHADER_PARAM_TYPE_VEC4, "[0 0 0 0.001]", "Flesh effect center and radius" ) + SHADER_PARAM( FLESHSUBSURFACETINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "Subsurface Color" ) + SHADER_PARAM( FLESHBORDERWIDTH, SHADER_PARAM_TYPE_FLOAT, "0.3", "Flesh border" ) + SHADER_PARAM( FLESHBORDERSOFTNESS, SHADER_PARAM_TYPE_FLOAT, "0.42", "Flesh border softness (> 0.0 && <= 0.5)" ) + SHADER_PARAM( FLESHBORDERTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "Flesh border Color" ) + SHADER_PARAM( FLESHGLOBALOPACITY, SHADER_PARAM_TYPE_FLOAT, "1.0", "Flesh global opacity" ) + SHADER_PARAM( FLESHGLOSSBRIGHTNESS, SHADER_PARAM_TYPE_FLOAT, "0.66", "Flesh gloss brightness" ) + SHADER_PARAM( FLESHSCROLLSPEED, SHADER_PARAM_TYPE_FLOAT, "1.0", "Flesh scroll speed" ) + + // Color Replacement Pass + SHADER_PARAM( BLENDTINTBYBASEALPHA, SHADER_PARAM_TYPE_BOOL, "0", "Use the base alpha to blend in the $color modulation") + SHADER_PARAM( BLENDTINTCOLOROVERBASE, SHADER_PARAM_TYPE_FLOAT, "0", "blend between tint acting as a multiplication versus a replace" ) + + END_SHADER_PARAMS + + // Cloak Pass + void SetupVarsCloakBlendedPass( CloakBlendedPassVars_t &info ) + { + info.m_nCloakFactor = CLOAKFACTOR; + info.m_nCloakColorTint = CLOAKCOLORTINT; + info.m_nRefractAmount = REFRACTAMOUNT; + + // Delete these lines if not bump mapping! + info.m_nBumpmap = BUMPMAP; + info.m_nBumpFrame = BUMPFRAME; + info.m_nBumpTransform = BUMPTRANSFORM; + } + + bool NeedsPowerOfTwoFrameBufferTexture( IMaterialVar **params, bool bCheckSpecificToThisFrame ) const + { + if ( params[CLOAKPASSENABLED]->GetIntValue() ) // If material supports cloaking + { + if ( bCheckSpecificToThisFrame == false ) // For setting model flag at load time + return true; + else if ( ( params[CLOAKFACTOR]->GetFloatValue() > 0.0f ) && ( params[CLOAKFACTOR]->GetFloatValue() < 1.0f ) ) // Per-frame check + return true; + // else, not cloaking this frame, so check flag2 in case the base material still needs it + } + + // Check flag2 if not drawing cloak pass + return IS_FLAG2_SET( MATERIAL_VAR2_NEEDS_POWER_OF_TWO_FRAME_BUFFER_TEXTURE ); + } + + bool IsTranslucent( IMaterialVar **params ) const + { + if ( params[CLOAKPASSENABLED]->GetIntValue() ) // If material supports cloaking + { + if ( ( params[CLOAKFACTOR]->GetFloatValue() > 0.0f ) && ( params[CLOAKFACTOR]->GetFloatValue() < 1.0f ) ) // Per-frame check + return true; + // else, not cloaking this frame, so check flag in case the base material still needs it + } + + // Check flag if not drawing cloak pass + return IS_FLAG_SET( MATERIAL_VAR_TRANSLUCENT ); + } + + // Emissive Scroll Pass + void SetupVarsEmissiveScrollBlendedPass( EmissiveScrollBlendedPassVars_t &info ) + { + info.m_nBlendStrength = EMISSIVEBLENDSTRENGTH; + info.m_nBaseTexture = EMISSIVEBLENDBASETEXTURE; + info.m_nFlowTexture = -1; // Not used in DX8 + info.m_nEmissiveTexture = EMISSIVEBLENDTEXTURE; + info.m_nEmissiveTint = EMISSIVEBLENDTINT; + info.m_nEmissiveScrollVector = EMISSIVEBLENDSCROLLVECTOR; + info.m_nTime = TIME; + } + + // Flesh Interior Pass + void SetupVarsFleshInteriorBlendedPass( FleshInteriorBlendedPassVars_t &info ) + { + info.m_nFleshTexture = FLESHINTERIORTEXTURE; + info.m_nFleshNoiseTexture = FLESHINTERIORNOISETEXTURE; + info.m_nFleshBorderTexture1D = FLESHBORDERTEXTURE1D; + info.m_nFleshNormalTexture = FLESHNORMALTEXTURE; + info.m_nFleshSubsurfaceTexture = FLESHSUBSURFACETEXTURE; + info.m_nFleshCubeTexture = FLESHCUBETEXTURE; + + info.m_nflBorderNoiseScale = FLESHBORDERNOISESCALE; + info.m_nflDebugForceFleshOn = FLESHDEBUGFORCEFLESHON; + info.m_nvEffectCenterRadius1 = FLESHEFFECTCENTERRADIUS1; + info.m_nvEffectCenterRadius2 = FLESHEFFECTCENTERRADIUS2; + info.m_nvEffectCenterRadius3 = FLESHEFFECTCENTERRADIUS3; + info.m_nvEffectCenterRadius4 = FLESHEFFECTCENTERRADIUS4; + + info.m_ncSubsurfaceTint = FLESHSUBSURFACETINT; + info.m_nflBorderWidth = FLESHBORDERWIDTH; + info.m_nflBorderSoftness = FLESHBORDERSOFTNESS; + info.m_ncBorderTint = FLESHBORDERTINT; + info.m_nflGlobalOpacity = FLESHGLOBALOPACITY; + info.m_nflGlossBrightness = FLESHGLOSSBRIGHTNESS; + info.m_nflScrollSpeed = FLESHSCROLLSPEED; + + info.m_nTime = TIME; + } + + SHADER_INIT_PARAMS() + { + // FLASHLIGHTFIXME + params[FLASHLIGHTTEXTURE]->SetStringValue( "effects/flashlight001" ); + + // We don't want no stinking bump mapping on models in dx8. + // Wait a minute! We want specular bump. .need to make that work by itself. +// params[BUMPMAP]->SetUndefined(); +// if( IS_FLAG_SET( MATERIAL_VAR_NORMALMAPALPHAENVMAPMASK ) ) +// { +// CLEAR_FLAGS( MATERIAL_VAR_NORMALMAPALPHAENVMAPMASK ); +// params[ENVMAP]->SetUndefined(); +// } + SET_FLAGS2( MATERIAL_VAR2_SUPPORTS_HW_SKINNING ); + + if( !params[ENVMAPMASKSCALE]->IsDefined() ) + params[ENVMAPMASKSCALE]->SetFloatValue( 1.0f ); + + if( !params[ENVMAPMASKFRAME]->IsDefined() ) + params[ENVMAPMASKFRAME]->SetIntValue( 0 ); + + if( !params[ENVMAPTINT]->IsDefined() ) + params[ENVMAPTINT]->SetVecValue( 1.0f, 1.0f, 1.0f ); + + if( !params[SELFILLUMTINT]->IsDefined() ) + params[SELFILLUMTINT]->SetVecValue( 1.0f, 1.0f, 1.0f ); + + if( !params[DETAILSCALE]->IsDefined() ) + params[DETAILSCALE]->SetFloatValue( 4.0f ); + + if( !params[DETAILBLENDFACTOR]->IsDefined() ) + params[DETAILBLENDFACTOR]->SetFloatValue( 1.0f ); + + if( !params[DETAILBLENDMODE]->IsDefined() ) + params[DETAILBLENDMODE]->SetFloatValue( 0 ); + + if( !params[ENVMAPCONTRAST]->IsDefined() ) + params[ENVMAPCONTRAST]->SetFloatValue( 0.0f ); + + if( !params[ENVMAPSATURATION]->IsDefined() ) + params[ENVMAPSATURATION]->SetFloatValue( 1.0f ); + + if( !params[ENVMAPFRAME]->IsDefined() ) + params[ENVMAPFRAME]->SetIntValue( 0 ); + + if( !params[BUMPFRAME]->IsDefined() ) + params[BUMPFRAME]->SetIntValue( 0 ); + + if( !params[ALPHATESTREFERENCE]->IsDefined() ) + params[ALPHATESTREFERENCE]->SetFloatValue( 0.0f ); + + // No texture means no self-illum or env mask in base alpha + if ( !params[BASETEXTURE]->IsDefined() ) + { + CLEAR_FLAGS( MATERIAL_VAR_SELFILLUM ); + CLEAR_FLAGS( MATERIAL_VAR_BASEALPHAENVMAPMASK ); + } + + // If in decal mode, no debug override... + if (IS_FLAG_SET(MATERIAL_VAR_DECAL)) + { + SET_FLAGS( MATERIAL_VAR_NO_DEBUG_OVERRIDE ); + } + + if( g_pConfig->UseBumpmapping() && params[BUMPMAP]->IsDefined() ) + { + SET_FLAGS2( MATERIAL_VAR2_NEEDS_TANGENT_SPACES ); + } + + SET_FLAGS2( MATERIAL_VAR2_LIGHTING_VERTEX_LIT ); + + // Get rid of the envmap if it's optional for this dx level. + if( params[ENVMAPOPTIONAL]->IsDefined() && params[ENVMAPOPTIONAL]->GetIntValue() ) + { + params[ENVMAP]->SetUndefined(); + } + + // If mat_specular 0, then get rid of envmap + if( !g_pConfig->UseSpecular() && params[ENVMAP]->IsDefined() && params[BASETEXTURE]->IsDefined() ) + { + params[ENVMAP]->SetUndefined(); + } + + // If a bumpmap is defined but an envmap isn't, then ignore the bumpmap. + // It was meant to be used with diffuse + if ( !params[ENVMAP]->IsDefined() ) + { + params[BUMPMAP]->SetUndefined(); + } + + // Cloak Pass + if ( !params[CLOAKPASSENABLED]->IsDefined() ) + { + params[CLOAKPASSENABLED]->SetIntValue( 0 ); + } + else if ( params[CLOAKPASSENABLED]->GetIntValue() ) + { + CloakBlendedPassVars_t info; + SetupVarsCloakBlendedPass( info ); + InitParamsCloakBlendedPass( this, params, pMaterialName, info ); + } + + // Emissive Scroll Pass + if ( !params[EMISSIVEBLENDENABLED]->IsDefined() ) + { + params[EMISSIVEBLENDENABLED]->SetIntValue( 0 ); + } + else if ( params[EMISSIVEBLENDENABLED]->GetIntValue() ) + { + EmissiveScrollBlendedPassVars_t info; + SetupVarsEmissiveScrollBlendedPass( info ); + InitParamsEmissiveScrollBlendedPass( this, params, pMaterialName, info ); + } + + // Flesh Interior Pass + if ( !params[FLESHINTERIORENABLED]->IsDefined() ) + { + params[FLESHINTERIORENABLED]->SetIntValue( 0 ); + } + else if ( params[FLESHINTERIORENABLED]->GetIntValue() ) + { + FleshInteriorBlendedPassVars_t info; + SetupVarsFleshInteriorBlendedPass( info ); + InitParamsFleshInteriorBlendedPass( this, params, pMaterialName, info ); + } + + // Color Replacement Pass + if ( !params[BLENDTINTBYBASEALPHA]->IsDefined() ) + { + params[BLENDTINTBYBASEALPHA]->SetIntValue(0); + } + + if ( !params[BLENDTINTCOLOROVERBASE]->IsDefined() ) + { + params[BLENDTINTCOLOROVERBASE]->SetFloatValue(0); + } + } + + SHADER_FALLBACK + { + if ( IsPC() ) + { + if ( g_pHardwareConfig->GetDXSupportLevel() < 70) + return "VertexLitGeneric_DX6"; + + if ( g_pHardwareConfig->GetDXSupportLevel() < 80) + return "VertexLitGeneric_DX7"; + + if ( g_pHardwareConfig->PreferReducedFillrate() ) + return "VertexLitGeneric_NoBump_DX8"; + } + return 0; + } + + SHADER_INIT + { + LoadTexture( FLASHLIGHTTEXTURE ); + + if (params[BASETEXTURE]->IsDefined()) + { + LoadTexture( BASETEXTURE ); + + if (!params[BASETEXTURE]->GetTextureValue()->IsTranslucent()) + { + CLEAR_FLAGS( MATERIAL_VAR_SELFILLUM ); + CLEAR_FLAGS( MATERIAL_VAR_BASEALPHAENVMAPMASK ); + } + } + + if (params[DETAIL]->IsDefined()) + { + LoadTexture( DETAIL ); + } + + if (g_pConfig->UseBumpmapping() && params[BUMPMAP]->IsDefined()) + { + LoadBumpMap( BUMPMAP ); + } + + // Don't alpha test if the alpha channel is used for other purposes + if (IS_FLAG_SET(MATERIAL_VAR_SELFILLUM) || IS_FLAG_SET(MATERIAL_VAR_BASEALPHAENVMAPMASK) ) + { + CLEAR_FLAGS( MATERIAL_VAR_ALPHATEST ); + } + + if (params[ENVMAP]->IsDefined()) + { + if( !IS_FLAG_SET(MATERIAL_VAR_ENVMAPSPHERE) ) + { + LoadCubeMap( ENVMAP ); + } + else + { + LoadTexture( ENVMAP ); + } + + if( !g_pHardwareConfig->SupportsCubeMaps() ) + { + SET_FLAGS( MATERIAL_VAR_ENVMAPSPHERE ); + } + + if (params[ENVMAPMASK]->IsDefined()) + { + LoadTexture( ENVMAPMASK ); + } + } + + // Cloak Pass + if ( params[CLOAKPASSENABLED]->GetIntValue() ) + { + CloakBlendedPassVars_t info; + SetupVarsCloakBlendedPass( info ); + InitCloakBlendedPass( this, params, info ); + } + + // Emissive Scroll Pass + if ( params[EMISSIVEBLENDENABLED]->GetIntValue() ) + { + EmissiveScrollBlendedPassVars_t info; + SetupVarsEmissiveScrollBlendedPass( info ); + InitEmissiveScrollBlendedPass( this, params, info ); + } + + // Flesh Interior Pass + if ( params[FLESHINTERIORENABLED]->GetIntValue() ) + { + FleshInteriorBlendedPassVars_t info; + SetupVarsFleshInteriorBlendedPass( info ); + InitFleshInteriorBlendedPass( this, params, info ); + } + } + + inline const char *GetUnbumpedPixelShaderName( IMaterialVar** params, bool bSkipEnvmap ) + { + static char const* s_pPixelShaders[] = + { + "VertexLitGeneric_EnvmapV2", + "VertexLitGeneric_SelfIlluminatedEnvmapV2", + + "VertexLitGeneric_BaseAlphaMaskedEnvmapV2", + "VertexLitGeneric_SelfIlluminatedEnvmapV2", + + // Env map mask + "VertexLitGeneric_MaskedEnvmapV2", + "VertexLitGeneric_SelfIlluminatedMaskedEnvmapV2", + + "VertexLitGeneric_MaskedEnvmapV2", + "VertexLitGeneric_SelfIlluminatedMaskedEnvmapV2", + + // Detail + "VertexLitGeneric_DetailEnvmapV2", + "VertexLitGeneric_DetailSelfIlluminatedEnvmapV2", + + "VertexLitGeneric_DetailBaseAlphaMaskedEnvmapV2", + "VertexLitGeneric_DetailSelfIlluminatedEnvmapV2", + + // Env map mask + "VertexLitGeneric_DetailMaskedEnvmapV2", + "VertexLitGeneric_DetailSelfIlluminatedMaskedEnvmapV2", + + "VertexLitGeneric_DetailMaskedEnvmapV2", + "VertexLitGeneric_DetailSelfIlluminatedMaskedEnvmapV2", + }; + + if ( !params[BASETEXTURE]->IsTexture() ) + { + if (params[ENVMAP]->IsTexture() && !bSkipEnvmap ) + { + if (!params[ENVMAPMASK]->IsTexture()) + { + return "VertexLitGeneric_EnvmapNoTexture"; + } + else + { + return "VertexLitGeneric_MaskedEnvmapNoTexture"; + } + } + else + { + if ( params[DETAIL]->IsTexture() ) + { + return "VertexLitGeneric_DetailNoTexture"; + } + else + { + return "VertexLitGeneric_NoTexture"; + } + } + } + else + { + if ( params[BLENDTINTBYBASEALPHA]->GetIntValue() ) + { + return "VertexLitGeneric_BlendTint"; + } + else if ( params[ENVMAP]->IsTexture() && !bSkipEnvmap ) + { + int pshIndex = 0; + if (IS_FLAG_SET(MATERIAL_VAR_SELFILLUM)) + pshIndex |= 0x1; + if (IS_FLAG_SET(MATERIAL_VAR_BASEALPHAENVMAPMASK)) + pshIndex |= 0x2; + if (params[ENVMAPMASK]->IsTexture()) + pshIndex |= 0x4; + if (params[DETAIL]->IsTexture()) + pshIndex |= 0x8; + return s_pPixelShaders[pshIndex]; + } + else + { + if (IS_FLAG_SET(MATERIAL_VAR_SELFILLUM)) + { + if ( params[DETAIL]->IsTexture() ) + return "VertexLitGeneric_DetailSelfIlluminated"; + else + return "VertexLitGeneric_SelfIlluminated"; + } + else if ( params[DETAIL]->IsTexture() ) + { + switch( params[DETAILBLENDMODE]->GetIntValue() ) + { + case 0: + return "VertexLitGeneric_Detail"; + + case 1: // additive modes + return "VertexLitGeneric_Detail_Additive"; + + case 5: + case 6: + return "VertexLitGeneric_Detail_Additive_selfillum"; + break; + + default: + return "VertexLitGeneric_Detail_LerpBase"; + } + } + else + { + return "VertexLitGeneric"; + } + } + } + } + + void DrawUnbumpedUsingVertexShader( IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow, bool bSkipEnvmap ) + { + SHADOW_STATE + { + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableAlphaTest( IS_FLAG_SET(MATERIAL_VAR_ALPHATEST) ); + + if ( params[ALPHATESTREFERENCE]->GetFloatValue() > 0.0f ) + { + pShaderShadow->AlphaFunc( SHADER_ALPHAFUNC_GEQUAL, params[ALPHATESTREFERENCE]->GetFloatValue() ); + } + + int fmt = VERTEX_POSITION | VERTEX_NORMAL; + + // FIXME: We could enable this, but we'd never get it working on dx7 or lower + // FIXME: This isn't going to work until we make more vertex shaders that + // pass the vertex color and alpha values through. +#if 0 + if ( IS_FLAG_SET( MATERIAL_VAR_VERTEXCOLOR ) || IS_FLAG_SET( MATERIAL_VAR_VERTEXALPHA ) ) + fmt |= VERTEX_COLOR; +#endif + + if (params[ENVMAP]->IsTexture() && !bSkipEnvmap ) + { + // envmap on stage 1 + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + + // envmapmask on stage 2 + if (params[ENVMAPMASK]->IsTexture() || IS_FLAG_SET(MATERIAL_VAR_BASEALPHAENVMAPMASK ) ) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER2, true ); + } + } + + if (params[BASETEXTURE]->IsTexture()) + { + SetDefaultBlendingShadowState( BASETEXTURE, true ); + } + else + { + SetDefaultBlendingShadowState( ENVMAPMASK, false ); + } + + if ( params[DETAIL]->IsTexture()) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER3, true ); + } + + pShaderShadow->VertexShaderVertexFormat( fmt, 1, 0, 0 ); + + // Set up the vertex shader index. + vertexlitgeneric_vs11_Static_Index vshIndex; + vshIndex.SetHALF_LAMBERT( IS_FLAG_SET( MATERIAL_VAR_HALFLAMBERT ) ); + //vshIndex.SetDETAIL( params[DETAIL]->IsTexture() ); + if( params[ENVMAP]->IsTexture() && !bSkipEnvmap ) + { + vshIndex.SetENVMAP( true ); + vshIndex.SetENVMAPCAMERASPACE( IS_FLAG_SET(MATERIAL_VAR_ENVMAPCAMERASPACE) ); + if( IS_FLAG_SET(MATERIAL_VAR_ENVMAPCAMERASPACE) ) + { + vshIndex.SetENVMAPSPHERE( false ); + } + else + { + vshIndex.SetENVMAPSPHERE( IS_FLAG_SET( MATERIAL_VAR_ENVMAPSPHERE ) ); + } + } + else + { + vshIndex.SetENVMAP( false ); + vshIndex.SetENVMAPCAMERASPACE( false ); + vshIndex.SetENVMAPSPHERE( false ); + } + pShaderShadow->SetVertexShader( "vertexlitgeneric_vs11", vshIndex.GetIndex() ); + + const char *pshName = GetUnbumpedPixelShaderName( params, bSkipEnvmap ); + pShaderShadow->SetPixelShader( pshName ); + DefaultFog(); + pShaderShadow->EnableAlphaWrites( true ); + } + DYNAMIC_STATE + { + if (params[BASETEXTURE]->IsTexture()) + { + BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME ); + SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, BASETEXTURETRANSFORM ); + } + +// if (params[ENVMAP]->IsTexture()) + if (params[ENVMAP]->IsTexture() && !bSkipEnvmap ) + { + BindTexture( SHADER_SAMPLER1, ENVMAP, ENVMAPFRAME ); + + if (params[ENVMAPMASK]->IsTexture() || IS_FLAG_SET(MATERIAL_VAR_BASEALPHAENVMAPMASK) ) + { + if (params[ENVMAPMASK]->IsTexture() ) + BindTexture( SHADER_SAMPLER2, ENVMAPMASK, ENVMAPMASKFRAME ); + else + BindTexture( SHADER_SAMPLER2, BASETEXTURE, FRAME ); + + SetVertexShaderTextureScaledTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_2, BASETEXTURETRANSFORM, ENVMAPMASKSCALE ); + } + + if (IS_FLAG_SET(MATERIAL_VAR_ENVMAPSPHERE) || + IS_FLAG_SET(MATERIAL_VAR_ENVMAPCAMERASPACE)) + { + LoadViewMatrixIntoVertexShaderConstant( VERTEX_SHADER_VIEWMODEL ); + } + SetEnvMapTintPixelShaderDynamicState( 2, ENVMAPTINT, -1 ); + } + + if ( params[DETAIL]->IsTexture()) + { + BindTexture( SHADER_SAMPLER3, DETAIL, DETAILFRAME ); + SetVertexShaderTextureScaledTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_4, BASETEXTURETRANSFORM, DETAILSCALE ); + } + + SetAmbientCubeDynamicStateVertexShader(); + SetModulationPixelShaderDynamicState( 3 ); + EnablePixelShaderOverbright( 0, true, true ); + SetPixelShaderConstant( 1, SELFILLUMTINT ); + + if ( params[DETAIL]->IsTexture() && ( ! IS_FLAG_SET( MATERIAL_VAR_SELFILLUM ) ) ) + { + float c1[4] = { 1.0f, 1.0f, 1.0f, 1.0f }; + c1[0] = c1[1] = c1[2] = c1[3] = params[DETAILBLENDFACTOR]->GetFloatValue(); + pShaderAPI->SetPixelShaderConstant( 1, c1, 1 ); + } + + if ( params[BLENDTINTBYBASEALPHA]->GetIntValue() ) + { + float c1[4] = { 1.0f, 1.0f, 1.0f, 1.0f }; + c1[0] = c1[1] = c1[2] = c1[3] = params[BLENDTINTCOLOROVERBASE]->GetFloatValue(); + pShaderAPI->SetPixelShaderConstant( 1, c1 ); + } + + vertexlitgeneric_vs11_Dynamic_Index vshIndex; + vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + vshIndex.SetSKINNING( pShaderAPI->GetCurrentNumBones() > 0 ); + vshIndex.SetLIGHT_COMBO( pShaderAPI->GetCurrentLightCombo() ); + pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() ); + if( pShaderAPI->GetIntRenderingParameter( INT_RENDERPARM_WRITE_DEPTH_TO_DESTALPHA ) ) + { + pShaderAPI->SetPixelShaderIndex( 0 ); + } + else + { + // write 255 to alpha if we aren't told to write depth to dest alpha (We don't ever actually write depth to dest alpha in dx8) + pShaderAPI->SetPixelShaderIndex( 1 ); + float c4[4] = { 1.0f, 1.0f, 1.0f, 1.0f }; + pShaderAPI->SetPixelShaderConstant( 4, c4, 1 ); + } + } + Draw(); + } + + SHADER_DRAW + { + // Skip the standard rendering if cloak pass is fully opaque + bool bDrawStandardPass = true; + if ( false/*disabled! no effect*/ && params[CLOAKPASSENABLED]->GetIntValue() && ( pShaderShadow == NULL ) ) // && not snapshotting + { + CloakBlendedPassVars_t info; + SetupVarsCloakBlendedPass( info ); + if ( CloakBlendedPassIsFullyOpaque( params, info ) ) + { + // There is some strangeness in DX8 when trying to skip the main pass, so leave this alone for now + //bDrawStandardPass = false; + } + } + + // Standard rendering pass + if ( bDrawStandardPass ) + { + // FLASHLIGHTFIXME: need to make these the same. + bool hasFlashlight = UsingFlashlight( params ); + bool bBump = g_pConfig->UseBumpmapping() && params[BUMPMAP]->IsTexture(); + + if( hasFlashlight ) + { + DrawFlashlight_dx80( params, pShaderAPI, pShaderShadow, bBump, BUMPMAP, BUMPFRAME, BUMPTRANSFORM, + FLASHLIGHTTEXTURE, FLASHLIGHTTEXTUREFRAME, false, false, 0, -1, -1 ); + } + else if( bBump ) + { + bool bSkipEnvmap = true; + DrawUnbumpedUsingVertexShader( params, pShaderAPI, pShaderShadow, bSkipEnvmap ); + + // specular pass + bool bBlendSpecular = true; + if( params[ENVMAP]->IsTexture() ) + { + DrawModelBumpedSpecularLighting( BUMPMAP, BUMPFRAME, ENVMAP, ENVMAPFRAME, + ENVMAPTINT, ALPHA, ENVMAPCONTRAST, ENVMAPSATURATION, BUMPTRANSFORM, bBlendSpecular ); + } + } + else + { + bool bSkipEnvmap = false; + DrawUnbumpedUsingVertexShader( params, pShaderAPI, pShaderShadow, bSkipEnvmap ); + } + } + else + { + // Skip this pass! + Draw( false ); + } + + // Cloak Pass + if ( params[CLOAKPASSENABLED]->GetIntValue() ) + { + // If ( snapshotting ) or ( we need to draw this frame ) + if ( ( pShaderShadow != NULL ) || ( ( params[CLOAKFACTOR]->GetFloatValue() > 0.0f ) && ( params[CLOAKFACTOR]->GetFloatValue() < 1.0f ) ) ) + { + CloakBlendedPassVars_t info; + SetupVarsCloakBlendedPass( info ); + DrawCloakBlendedPass( this, params, pShaderAPI, pShaderShadow, info, vertexCompression ); + } + else // We're not snapshotting and we don't need to draw this frame + { + // Skip this pass! + Draw( false ); + } + } + + // Emissive Scroll Pass + if ( params[EMISSIVEBLENDENABLED]->GetIntValue() ) + { + // If ( snapshotting ) or ( we need to draw this frame ) + if ( ( pShaderShadow != NULL ) || ( params[EMISSIVEBLENDSTRENGTH]->GetFloatValue() > 0.0f ) ) + { + EmissiveScrollBlendedPassVars_t info; + SetupVarsEmissiveScrollBlendedPass( info ); + DrawEmissiveScrollBlendedPass( this, params, pShaderAPI, pShaderShadow, info, vertexCompression ); + } + else // We're not snapshotting and we don't need to draw this frame + { + // Skip this pass! + Draw( false ); + } + } + + // Flesh Interior Pass + if ( params[FLESHINTERIORENABLED]->GetIntValue() ) + { + // If ( snapshotting ) or ( we need to draw this frame ) + if ( ( pShaderShadow != NULL ) || ( true ) ) + { + FleshInteriorBlendedPassVars_t info; + SetupVarsFleshInteriorBlendedPass( info ); + DrawFleshInteriorBlendedPass( this, params, pShaderAPI, pShaderShadow, info, vertexCompression ); + } + else // We're not snapshotting and we don't need to draw this frame + { + // Skip this pass! + Draw( false ); + } + } + } +END_SHADER + + +//----------------------------------------------------------------------------- +// Version that doesn't do bumpmapping +//----------------------------------------------------------------------------- +BEGIN_INHERITED_SHADER( VertexLitGeneric_NoBump_DX8, VertexLitGeneric_DX8, + "Help for VertexLitGeneric_NoBump_DX8" ) + + SHADER_FALLBACK + { + if (g_pConfig->bSoftwareLighting) + return "VertexLitGeneric_DX6"; + + if (!g_pHardwareConfig->SupportsVertexAndPixelShaders()) + return "VertexLitGeneric_DX7"; + + return 0; + } + + virtual bool ShouldUseBumpmapping( IMaterialVar **params ) + { + if ( !g_pConfig->UseBumpmapping() ) + return false; + + if ( !params[BUMPMAP]->IsDefined() ) + return false; + + return ( params[FORCEBUMP]->GetIntValue() != 0 ); + } + +END_INHERITED_SHADER + diff --git a/materialsystem/stdshaders/vertexlitgeneric_dx9.cpp b/materialsystem/stdshaders/vertexlitgeneric_dx9.cpp new file mode 100644 index 0000000..5e7e61e --- /dev/null +++ b/materialsystem/stdshaders/vertexlitgeneric_dx9.cpp @@ -0,0 +1,524 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $Header: $ +// $NoKeywords: $ +//=====================================================================================// + +#include "BaseVSShader.h" +#include "vertexlitgeneric_dx9_helper.h" +#include "emissive_scroll_blended_pass_helper.h" +#include "cloak_blended_pass_helper.h" +#include "flesh_interior_blended_pass_helper.h" +#include "weapon_sheen_pass_helper.h" + + +BEGIN_VS_SHADER( VertexLitGeneric, "Help for VertexLitGeneric" ) + BEGIN_SHADER_PARAMS + SHADER_PARAM( ALBEDO, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "albedo (Base texture with no baked lighting)" ) + SHADER_PARAM( COMPRESS, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "compression wrinklemap" ) + SHADER_PARAM( STRETCH, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "expansion wrinklemap" ) + SHADER_PARAM( SELFILLUMTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "Self-illumination tint" ) + SHADER_PARAM( DETAIL, SHADER_PARAM_TYPE_TEXTURE, "shadertest/detail", "detail texture" ) + SHADER_PARAM( DETAILFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $detail" ) + SHADER_PARAM( DETAILSCALE, SHADER_PARAM_TYPE_FLOAT, "4", "scale of the detail texture" ) + SHADER_PARAM( ENVMAP, SHADER_PARAM_TYPE_TEXTURE, "shadertest/shadertest_env", "envmap" ) + SHADER_PARAM( ENVMAPFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "envmap frame number" ) + SHADER_PARAM( ENVMAPMASK, SHADER_PARAM_TYPE_TEXTURE, "shadertest/shadertest_envmask", "envmap mask" ) + SHADER_PARAM( ENVMAPMASKFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "" ) + SHADER_PARAM( ENVMAPMASKTRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$envmapmask texcoord transform" ) + SHADER_PARAM( ENVMAPTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "envmap tint" ) + SHADER_PARAM( BUMPMAP, SHADER_PARAM_TYPE_TEXTURE, "models/shadertest/shader1_normal", "bump map" ) + SHADER_PARAM( BUMPCOMPRESS, SHADER_PARAM_TYPE_TEXTURE, "models/shadertest/shader3_normal", "compression bump map" ) + SHADER_PARAM( BUMPSTRETCH, SHADER_PARAM_TYPE_TEXTURE, "models/shadertest/shader1_normal", "expansion bump map" ) + SHADER_PARAM( BUMPFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $bumpmap" ) + SHADER_PARAM( BUMPTRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$bumpmap texcoord transform" ) + SHADER_PARAM( ENVMAPCONTRAST, SHADER_PARAM_TYPE_FLOAT, "0.0", "contrast 0 == normal 1 == color*color" ) + SHADER_PARAM( ENVMAPSATURATION, SHADER_PARAM_TYPE_FLOAT, "1.0", "saturation 0 == greyscale 1 == normal" ) + SHADER_PARAM( SELFILLUM_ENVMAPMASK_ALPHA, SHADER_PARAM_TYPE_FLOAT,"0.0","defines that self illum value comes from env map mask alpha" ) + SHADER_PARAM( SELFILLUMFRESNEL, SHADER_PARAM_TYPE_BOOL, "0", "Self illum fresnel" ) + SHADER_PARAM( SELFILLUMFRESNELMINMAXEXP, SHADER_PARAM_TYPE_VEC4, "0", "Self illum fresnel min, max, exp" ) + SHADER_PARAM( ALPHATESTREFERENCE, SHADER_PARAM_TYPE_FLOAT, "0.0", "" ) + SHADER_PARAM( FLASHLIGHTNOLAMBERT, SHADER_PARAM_TYPE_BOOL, "0", "Flashlight pass sets N.L=1.0" ) + SHADER_PARAM( LIGHTMAP, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "lightmap texture--will be bound by the engine") + + // Debugging term for visualizing ambient data on its own + SHADER_PARAM( AMBIENTONLY, SHADER_PARAM_TYPE_INTEGER, "0", "Control drawing of non-ambient light ()" ) + + SHADER_PARAM( PHONGEXPONENT, SHADER_PARAM_TYPE_FLOAT, "5.0", "Phong exponent for local specular lights" ) + SHADER_PARAM( PHONGTINT, SHADER_PARAM_TYPE_VEC3, "5.0", "Phong tint for local specular lights" ) + SHADER_PARAM( PHONGALBEDOTINT, SHADER_PARAM_TYPE_BOOL, "1.0", "Apply tint by albedo (controlled by spec exponent texture" ) + SHADER_PARAM( LIGHTWARPTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "1D ramp texture for tinting scalar diffuse term" ) + SHADER_PARAM( PHONGWARPTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "warp the specular term" ) + SHADER_PARAM( PHONGFRESNELRANGES, SHADER_PARAM_TYPE_VEC3, "[0 0.5 1]", "Parameters for remapping fresnel output" ) + SHADER_PARAM( PHONGBOOST, SHADER_PARAM_TYPE_FLOAT, "1.0", "Phong overbrightening factor (specular mask channel should be authored to account for this)" ) + SHADER_PARAM( PHONGEXPONENTTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "Phong Exponent map" ) + SHADER_PARAM( PHONGEXPONENTFACTOR, SHADER_PARAM_TYPE_FLOAT, "0.0", "When using a phong exponent texture, this will be multiplied by the 0..1 that comes out of the texture." ) + SHADER_PARAM( PHONG, SHADER_PARAM_TYPE_BOOL, "0", "enables phong lighting" ) + SHADER_PARAM( BASEMAPALPHAPHONGMASK, SHADER_PARAM_TYPE_INTEGER, "0", "indicates that there is no normal map and that the phong mask is in base alpha" ) + SHADER_PARAM( INVERTPHONGMASK, SHADER_PARAM_TYPE_INTEGER, "0", "invert the phong mask (0=full phong, 1=no phong)" ) + SHADER_PARAM( ENVMAPFRESNEL, SHADER_PARAM_TYPE_FLOAT, "0", "Degree to which Fresnel should be applied to env map" ) + SHADER_PARAM( SELFILLUMMASK, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "If we bind a texture here, it overrides base alpha (if any) for self illum" ) + + // detail (multi-) texturing + SHADER_PARAM( DETAILBLENDMODE, SHADER_PARAM_TYPE_INTEGER, "0", "mode for combining detail texture with base. 0=normal, 1= additive, 2=alpha blend detail over base, 3=crossfade" ) + SHADER_PARAM( DETAILBLENDFACTOR, SHADER_PARAM_TYPE_FLOAT, "1", "blend amount for detail texture." ) + SHADER_PARAM( DETAILTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "detail texture tint" ) + SHADER_PARAM( DETAILTEXTURETRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$detail texcoord transform" ) + + // Rim lighting terms + SHADER_PARAM( RIMLIGHT, SHADER_PARAM_TYPE_BOOL, "0", "enables rim lighting" ) + SHADER_PARAM( RIMLIGHTEXPONENT, SHADER_PARAM_TYPE_FLOAT, "4.0", "Exponent for rim lights" ) + SHADER_PARAM( RIMLIGHTBOOST, SHADER_PARAM_TYPE_FLOAT, "1.0", "Boost for rim lights" ) + SHADER_PARAM( RIMMASK, SHADER_PARAM_TYPE_BOOL, "0", "Indicates whether or not to use alpha channel of exponent texture to mask the rim term" ) + + // Seamless mapping scale + SHADER_PARAM( SEAMLESS_BASE, SHADER_PARAM_TYPE_BOOL, "0", "whether to apply seamless mapping to the base texture. requires a smooth model." ) + SHADER_PARAM( SEAMLESS_DETAIL, SHADER_PARAM_TYPE_BOOL, "0", "where to apply seamless mapping to the detail texture." ) + SHADER_PARAM( SEAMLESS_SCALE, SHADER_PARAM_TYPE_FLOAT, "1.0", "the scale for the seamless mapping. # of repetions of texture per inch." ) + + // Emissive Scroll Pass + SHADER_PARAM( EMISSIVEBLENDENABLED, SHADER_PARAM_TYPE_BOOL, "0", "Enable emissive blend pass" ) + SHADER_PARAM( EMISSIVEBLENDBASETEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "self-illumination map" ) + SHADER_PARAM( EMISSIVEBLENDSCROLLVECTOR, SHADER_PARAM_TYPE_VEC2, "[0.11 0.124]", "Emissive scroll vec" ) + SHADER_PARAM( EMISSIVEBLENDSTRENGTH, SHADER_PARAM_TYPE_FLOAT, "1.0", "Emissive blend strength" ) + SHADER_PARAM( EMISSIVEBLENDTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "self-illumination map" ) + SHADER_PARAM( EMISSIVEBLENDTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "Self-illumination tint" ) + SHADER_PARAM( EMISSIVEBLENDFLOWTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "flow map" ) + SHADER_PARAM( TIME, SHADER_PARAM_TYPE_FLOAT, "0.0", "Needs CurrentTime Proxy" ) + + // Cloak Pass + SHADER_PARAM( CLOAKPASSENABLED, SHADER_PARAM_TYPE_BOOL, "0", "Enables cloak render in a second pass" ) + SHADER_PARAM( CLOAKFACTOR, SHADER_PARAM_TYPE_FLOAT, "0.0", "" ) + SHADER_PARAM( CLOAKCOLORTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "Cloak color tint" ) + SHADER_PARAM( REFRACTAMOUNT, SHADER_PARAM_TYPE_FLOAT, "2", "" ) + + // Weapon Sheen Pass + SHADER_PARAM( SHEENPASSENABLED, SHADER_PARAM_TYPE_BOOL, "0", "Enables weapon sheen render in a second pass" ) + SHADER_PARAM( SHEENMAP, SHADER_PARAM_TYPE_TEXTURE, "shadertest/shadertest_env", "sheenmap" ) + SHADER_PARAM( SHEENMAPMASK, SHADER_PARAM_TYPE_TEXTURE, "shadertest/shadertest_envmask", "sheenmap mask" ) + SHADER_PARAM( SHEENMAPMASKFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "" ) + SHADER_PARAM( SHEENMAPTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "sheenmap tint" ) + SHADER_PARAM( SHEENMAPMASKSCALEX, SHADER_PARAM_TYPE_FLOAT, "1", "X Scale the size of the map mask to the size of the target" ) + SHADER_PARAM( SHEENMAPMASKSCALEY, SHADER_PARAM_TYPE_FLOAT, "1", "Y Scale the size of the map mask to the size of the target" ) + SHADER_PARAM( SHEENMAPMASKOFFSETX, SHADER_PARAM_TYPE_FLOAT, "0", "X Offset of the mask relative to model space coords of target" ) + SHADER_PARAM( SHEENMAPMASKOFFSETY, SHADER_PARAM_TYPE_FLOAT, "0", "Y Offset of the mask relative to model space coords of target" ) + SHADER_PARAM( SHEENMAPMASKDIRECTION, SHADER_PARAM_TYPE_INTEGER, "0", "The direction the sheen should move (length direction of weapon) XYZ, 0,1,2" ) + SHADER_PARAM( SHEENINDEX, SHADER_PARAM_TYPE_INTEGER, "0", "Index of the Effect Type (Color Additive, Override etc...)" ) + + // Flesh Interior Pass + SHADER_PARAM( FLESHINTERIORENABLED, SHADER_PARAM_TYPE_BOOL, "0", "Enable Flesh interior blend pass" ) + SHADER_PARAM( FLESHINTERIORTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "Flesh color texture" ) + SHADER_PARAM( FLESHINTERIORNOISETEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "Flesh noise texture" ) + SHADER_PARAM( FLESHBORDERTEXTURE1D, SHADER_PARAM_TYPE_TEXTURE, "", "Flesh border 1D texture" ) + SHADER_PARAM( FLESHNORMALTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "Flesh normal texture" ) + SHADER_PARAM( FLESHSUBSURFACETEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "Flesh subsurface texture" ) + SHADER_PARAM( FLESHCUBETEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "Flesh cubemap texture" ) + SHADER_PARAM( FLESHBORDERNOISESCALE, SHADER_PARAM_TYPE_FLOAT, "1.5", "Flesh Noise UV scalar for border" ) + SHADER_PARAM( FLESHDEBUGFORCEFLESHON, SHADER_PARAM_TYPE_BOOL, "0", "Flesh Debug full flesh" ) + SHADER_PARAM( FLESHEFFECTCENTERRADIUS1, SHADER_PARAM_TYPE_VEC4, "[0 0 0 0.001]", "Flesh effect center and radius" ) + SHADER_PARAM( FLESHEFFECTCENTERRADIUS2, SHADER_PARAM_TYPE_VEC4, "[0 0 0 0.001]", "Flesh effect center and radius" ) + SHADER_PARAM( FLESHEFFECTCENTERRADIUS3, SHADER_PARAM_TYPE_VEC4, "[0 0 0 0.001]", "Flesh effect center and radius" ) + SHADER_PARAM( FLESHEFFECTCENTERRADIUS4, SHADER_PARAM_TYPE_VEC4, "[0 0 0 0.001]", "Flesh effect center and radius" ) + SHADER_PARAM( FLESHSUBSURFACETINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "Subsurface Color" ) + SHADER_PARAM( FLESHBORDERWIDTH, SHADER_PARAM_TYPE_FLOAT, "0.3", "Flesh border" ) + SHADER_PARAM( FLESHBORDERSOFTNESS, SHADER_PARAM_TYPE_FLOAT, "0.42", "Flesh border softness (> 0.0 && <= 0.5)" ) + SHADER_PARAM( FLESHBORDERTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "Flesh border Color" ) + SHADER_PARAM( FLESHGLOBALOPACITY, SHADER_PARAM_TYPE_FLOAT, "1.0", "Flesh global opacity" ) + SHADER_PARAM( FLESHGLOSSBRIGHTNESS, SHADER_PARAM_TYPE_FLOAT, "0.66", "Flesh gloss brightness" ) + SHADER_PARAM( FLESHSCROLLSPEED, SHADER_PARAM_TYPE_FLOAT, "1.0", "Flesh scroll speed" ) + + SHADER_PARAM( SEPARATEDETAILUVS, SHADER_PARAM_TYPE_BOOL, "0", "Use texcoord1 for detail texture" ) + SHADER_PARAM( LINEARWRITE, SHADER_PARAM_TYPE_INTEGER, "0", "Disables SRGB conversion of shader results." ) + SHADER_PARAM( DEPTHBLEND, SHADER_PARAM_TYPE_INTEGER, "0", "fade at intersection boundaries. Only supported without bumpmaps" ) + SHADER_PARAM( DEPTHBLENDSCALE, SHADER_PARAM_TYPE_FLOAT, "50.0", "Amplify or reduce DEPTHBLEND fading. Lower values make harder edges." ) + + SHADER_PARAM( BLENDTINTBYBASEALPHA, SHADER_PARAM_TYPE_BOOL, "0", "Use the base alpha to blend in the $color modulation") + SHADER_PARAM( BLENDTINTCOLOROVERBASE, SHADER_PARAM_TYPE_FLOAT, "0", "blend between tint acting as a multiplication versus a replace" ) + END_SHADER_PARAMS + + void SetupVars( VertexLitGeneric_DX9_Vars_t& info ) + { + info.m_nBaseTexture = BASETEXTURE; + info.m_nWrinkle = COMPRESS; + info.m_nStretch = STRETCH; + info.m_nBaseTextureFrame = FRAME; + info.m_nBaseTextureTransform = BASETEXTURETRANSFORM; + info.m_nAlbedo = ALBEDO; + info.m_nSelfIllumTint = SELFILLUMTINT; + info.m_nDetail = DETAIL; + info.m_nDetailFrame = DETAILFRAME; + info.m_nDetailScale = DETAILSCALE; + info.m_nEnvmap = ENVMAP; + info.m_nEnvmapFrame = ENVMAPFRAME; + info.m_nEnvmapMask = ENVMAPMASK; + info.m_nEnvmapMaskFrame = ENVMAPMASKFRAME; + info.m_nEnvmapMaskTransform = ENVMAPMASKTRANSFORM; + info.m_nEnvmapTint = ENVMAPTINT; + info.m_nBumpmap = BUMPMAP; + info.m_nNormalWrinkle = BUMPCOMPRESS; + info.m_nNormalStretch = BUMPSTRETCH; + info.m_nBumpFrame = BUMPFRAME; + info.m_nBumpTransform = BUMPTRANSFORM; + info.m_nEnvmapContrast = ENVMAPCONTRAST; + info.m_nEnvmapSaturation = ENVMAPSATURATION; + info.m_nAlphaTestReference = ALPHATESTREFERENCE; + info.m_nFlashlightNoLambert = FLASHLIGHTNOLAMBERT; + info.m_nLightmap = LIGHTMAP; + + info.m_nFlashlightTexture = FLASHLIGHTTEXTURE; + info.m_nFlashlightTextureFrame = FLASHLIGHTTEXTUREFRAME; + info.m_nSelfIllumEnvMapMask_Alpha = SELFILLUM_ENVMAPMASK_ALPHA; + info.m_nSelfIllumFresnel = SELFILLUMFRESNEL; + info.m_nSelfIllumFresnelMinMaxExp = SELFILLUMFRESNELMINMAXEXP; + + info.m_nAmbientOnly = AMBIENTONLY; + info.m_nPhongExponent = PHONGEXPONENT; + info.m_nPhongExponentTexture = PHONGEXPONENTTEXTURE; + info.m_nPhongTint = PHONGTINT; + info.m_nPhongAlbedoTint = PHONGALBEDOTINT; + info.m_nDiffuseWarpTexture = LIGHTWARPTEXTURE; + info.m_nPhongWarpTexture = PHONGWARPTEXTURE; + info.m_nPhongBoost = PHONGBOOST; + info.m_nPhongExponentFactor = PHONGEXPONENTFACTOR; + info.m_nPhongFresnelRanges = PHONGFRESNELRANGES; + info.m_nPhong = PHONG; + info.m_nBaseMapAlphaPhongMask = BASEMAPALPHAPHONGMASK; + info.m_nEnvmapFresnel = ENVMAPFRESNEL; + info.m_nDetailTextureCombineMode = DETAILBLENDMODE; + info.m_nDetailTextureBlendFactor = DETAILBLENDFACTOR; + info.m_nDetailTextureTransform = DETAILTEXTURETRANSFORM; + + // Rim lighting parameters + info.m_nRimLight = RIMLIGHT; + info.m_nRimLightPower = RIMLIGHTEXPONENT; + info.m_nRimLightBoost = RIMLIGHTBOOST; + info.m_nRimMask = RIMMASK; + + // seamless + info.m_nSeamlessScale = SEAMLESS_SCALE; + info.m_nSeamlessDetail = SEAMLESS_DETAIL; + info.m_nSeamlessBase = SEAMLESS_BASE; + + info.m_nSeparateDetailUVs = SEPARATEDETAILUVS; + + info.m_nLinearWrite = LINEARWRITE; + info.m_nDetailTint = DETAILTINT; + info.m_nInvertPhongMask = INVERTPHONGMASK; + + info.m_nDepthBlend = DEPTHBLEND; + info.m_nDepthBlendScale = DEPTHBLENDSCALE; + + info.m_nSelfIllumMask = SELFILLUMMASK; + info.m_nBlendTintByBaseAlpha = BLENDTINTBYBASEALPHA; + info.m_nTintReplacesBaseColor = BLENDTINTCOLOROVERBASE; + } + + // Cloak Pass + void SetupVarsCloakBlendedPass( CloakBlendedPassVars_t &info ) + { + info.m_nCloakFactor = CLOAKFACTOR; + info.m_nCloakColorTint = CLOAKCOLORTINT; + info.m_nRefractAmount = REFRACTAMOUNT; + + // Delete these lines if not bump mapping! + info.m_nBumpmap = BUMPMAP; + info.m_nBumpFrame = BUMPFRAME; + info.m_nBumpTransform = BUMPTRANSFORM; + } + + // Weapon Sheen Pass + void SetupVarsWeaponSheenPass( WeaponSheenPassVars_t &info ) + { + info.m_nSheenMap = SHEENMAP; + info.m_nSheenMapMask = SHEENMAPMASK; + info.m_nSheenMapMaskFrame = SHEENMAPMASKFRAME; + info.m_nSheenMapTint = SHEENMAPTINT; + info.m_nSheenMapMaskScaleX = SHEENMAPMASKSCALEX; + info.m_nSheenMapMaskScaleY = SHEENMAPMASKSCALEY; + info.m_nSheenMapMaskOffsetX = SHEENMAPMASKOFFSETX; + info.m_nSheenMapMaskOffsetY = SHEENMAPMASKOFFSETY; + info.m_nSheenMapMaskDirection = SHEENMAPMASKDIRECTION; + info.m_nSheenIndex = SHEENINDEX; + + info.m_nBumpmap = BUMPMAP; + info.m_nBumpFrame = BUMPFRAME; + info.m_nBumpTransform = BUMPTRANSFORM; + } + + bool NeedsPowerOfTwoFrameBufferTexture( IMaterialVar **params, bool bCheckSpecificToThisFrame ) const + { + if ( params[CLOAKPASSENABLED]->GetIntValue() ) // If material supports cloaking + { + if ( bCheckSpecificToThisFrame == false ) // For setting model flag at load time + return true; + else if ( ( params[CLOAKFACTOR]->GetFloatValue() > 0.0f ) && ( params[CLOAKFACTOR]->GetFloatValue() < 1.0f ) ) // Per-frame check + return true; + // else, not cloaking this frame, so check flag2 in case the base material still needs it + } + if ( params[SHEENPASSENABLED]->GetIntValue() ) // If material supports weapon sheen + return true; + + // Check flag2 if not drawing cloak pass + return IS_FLAG2_SET( MATERIAL_VAR2_NEEDS_POWER_OF_TWO_FRAME_BUFFER_TEXTURE ); + } + + bool IsTranslucent( IMaterialVar **params ) const + { + if ( params[CLOAKPASSENABLED]->GetIntValue() ) // If material supports cloaking + { + if ( ( params[CLOAKFACTOR]->GetFloatValue() > 0.0f ) && ( params[CLOAKFACTOR]->GetFloatValue() < 1.0f ) ) // Per-frame check + return true; + // else, not cloaking this frame, so check flag in case the base material still needs it + } + + // Check flag if not drawing cloak pass + return IS_FLAG_SET( MATERIAL_VAR_TRANSLUCENT ); + } + + // Emissive Scroll Pass + void SetupVarsEmissiveScrollBlendedPass( EmissiveScrollBlendedPassVars_t &info ) + { + info.m_nBlendStrength = EMISSIVEBLENDSTRENGTH; + info.m_nBaseTexture = EMISSIVEBLENDBASETEXTURE; + info.m_nFlowTexture = EMISSIVEBLENDFLOWTEXTURE; + info.m_nEmissiveTexture = EMISSIVEBLENDTEXTURE; + info.m_nEmissiveTint = EMISSIVEBLENDTINT; + info.m_nEmissiveScrollVector = EMISSIVEBLENDSCROLLVECTOR; + info.m_nTime = TIME; + } + + // Flesh Interior Pass + void SetupVarsFleshInteriorBlendedPass( FleshInteriorBlendedPassVars_t &info ) + { + info.m_nFleshTexture = FLESHINTERIORTEXTURE; + info.m_nFleshNoiseTexture = FLESHINTERIORNOISETEXTURE; + info.m_nFleshBorderTexture1D = FLESHBORDERTEXTURE1D; + info.m_nFleshNormalTexture = FLESHNORMALTEXTURE; + info.m_nFleshSubsurfaceTexture = FLESHSUBSURFACETEXTURE; + info.m_nFleshCubeTexture = FLESHCUBETEXTURE; + + info.m_nflBorderNoiseScale = FLESHBORDERNOISESCALE; + info.m_nflDebugForceFleshOn = FLESHDEBUGFORCEFLESHON; + info.m_nvEffectCenterRadius1 = FLESHEFFECTCENTERRADIUS1; + info.m_nvEffectCenterRadius2 = FLESHEFFECTCENTERRADIUS2; + info.m_nvEffectCenterRadius3 = FLESHEFFECTCENTERRADIUS3; + info.m_nvEffectCenterRadius4 = FLESHEFFECTCENTERRADIUS4; + + info.m_ncSubsurfaceTint = FLESHSUBSURFACETINT; + info.m_nflBorderWidth = FLESHBORDERWIDTH; + info.m_nflBorderSoftness = FLESHBORDERSOFTNESS; + info.m_ncBorderTint = FLESHBORDERTINT; + info.m_nflGlobalOpacity = FLESHGLOBALOPACITY; + info.m_nflGlossBrightness = FLESHGLOSSBRIGHTNESS; + info.m_nflScrollSpeed = FLESHSCROLLSPEED; + + info.m_nTime = TIME; + } + + SHADER_INIT_PARAMS() + { + VertexLitGeneric_DX9_Vars_t vars; + SetupVars( vars ); + InitParamsVertexLitGeneric_DX9( this, params, pMaterialName, true, vars ); + + // Cloak Pass + if ( !params[CLOAKPASSENABLED]->IsDefined() ) + { + params[CLOAKPASSENABLED]->SetIntValue( 0 ); + } + else if ( params[CLOAKPASSENABLED]->GetIntValue() ) + { + CloakBlendedPassVars_t info; + SetupVarsCloakBlendedPass( info ); + InitParamsCloakBlendedPass( this, params, pMaterialName, info ); + } + + // Sheen Pass + if ( !params[SHEENPASSENABLED]->IsDefined() ) + { + params[SHEENPASSENABLED]->SetIntValue( 0 ); + } + else if ( params[SHEENPASSENABLED]->GetIntValue() ) + { + WeaponSheenPassVars_t info; + SetupVarsWeaponSheenPass( info ); + InitParamsWeaponSheenPass( this, params, pMaterialName, info ); + } + + // Emissive Scroll Pass + if ( !params[EMISSIVEBLENDENABLED]->IsDefined() ) + { + params[EMISSIVEBLENDENABLED]->SetIntValue( 0 ); + } + else if ( params[EMISSIVEBLENDENABLED]->GetIntValue() ) + { + EmissiveScrollBlendedPassVars_t info; + SetupVarsEmissiveScrollBlendedPass( info ); + InitParamsEmissiveScrollBlendedPass( this, params, pMaterialName, info ); + } + + // Flesh Interior Pass + if ( !params[FLESHINTERIORENABLED]->IsDefined() ) + { + params[FLESHINTERIORENABLED]->SetIntValue( 0 ); + } + else if ( params[FLESHINTERIORENABLED]->GetIntValue() ) + { + FleshInteriorBlendedPassVars_t info; + SetupVarsFleshInteriorBlendedPass( info ); + InitParamsFleshInteriorBlendedPass( this, params, pMaterialName, info ); + } + } + + SHADER_FALLBACK + { + if (g_pHardwareConfig->GetDXSupportLevel() < 70) + return "VertexLitGeneric_DX6"; + + if (g_pHardwareConfig->GetDXSupportLevel() < 80) + return "VertexLitGeneric_DX7"; + + if (g_pHardwareConfig->GetDXSupportLevel() < 90) + return "VertexLitGeneric_DX8"; + + return 0; + } + + SHADER_INIT + { + VertexLitGeneric_DX9_Vars_t vars; + SetupVars( vars ); + InitVertexLitGeneric_DX9( this, params, true, vars ); + + // Cloak Pass + if ( params[CLOAKPASSENABLED]->GetIntValue() ) + { + CloakBlendedPassVars_t info; + SetupVarsCloakBlendedPass( info ); + InitCloakBlendedPass( this, params, info ); + } + + // TODO : Only do this if we're in range of the camera + // Weapon Sheen + if ( params[SHEENPASSENABLED]->GetIntValue() ) + { + WeaponSheenPassVars_t info; + SetupVarsWeaponSheenPass( info ); + InitWeaponSheenPass( this, params, info ); + } + + // Emissive Scroll Pass + if ( params[EMISSIVEBLENDENABLED]->GetIntValue() ) + { + EmissiveScrollBlendedPassVars_t info; + SetupVarsEmissiveScrollBlendedPass( info ); + InitEmissiveScrollBlendedPass( this, params, info ); + } + + // Flesh Interior Pass + if ( params[FLESHINTERIORENABLED]->GetIntValue() ) + { + FleshInteriorBlendedPassVars_t info; + SetupVarsFleshInteriorBlendedPass( info ); + InitFleshInteriorBlendedPass( this, params, info ); + } + } + + SHADER_DRAW + { + // Skip the standard rendering if cloak pass is fully opaque + bool bDrawStandardPass = true; + if ( params[CLOAKPASSENABLED]->GetIntValue() && ( pShaderShadow == NULL ) ) // && not snapshotting + { + CloakBlendedPassVars_t info; + SetupVarsCloakBlendedPass( info ); + if ( CloakBlendedPassIsFullyOpaque( params, info ) ) + { + bDrawStandardPass = false; + } + } + + // Standard rendering pass + if ( bDrawStandardPass ) + { + VertexLitGeneric_DX9_Vars_t vars; + SetupVars( vars ); + DrawVertexLitGeneric_DX9( this, params, pShaderAPI, pShaderShadow, true, vars, vertexCompression, pContextDataPtr ); + } + else + { + // Skip this pass! + Draw( false ); + } + + // Weapon sheen pass + // only if doing standard as well (don't do it if cloaked) + if ( params[SHEENPASSENABLED]->GetIntValue() ) + { + WeaponSheenPassVars_t info; + SetupVarsWeaponSheenPass( info ); + if ( ( pShaderShadow != NULL ) || ( bDrawStandardPass && ShouldDrawMaterialSheen( params, info ) ) ) + { + DrawWeaponSheenPass( this, params, pShaderAPI, pShaderShadow, info, vertexCompression ); + } + else + { + // Skip this pass! + Draw( false ); + } + } + + // Cloak Pass + if ( params[CLOAKPASSENABLED]->GetIntValue() ) + { + // If ( snapshotting ) or ( we need to draw this frame ) + if ( ( pShaderShadow != NULL ) || ( ( params[CLOAKFACTOR]->GetFloatValue() > 0.0f ) && ( params[CLOAKFACTOR]->GetFloatValue() < 1.0f ) ) ) + { + CloakBlendedPassVars_t info; + SetupVarsCloakBlendedPass( info ); + DrawCloakBlendedPass( this, params, pShaderAPI, pShaderShadow, info, vertexCompression ); + } + else // We're not snapshotting and we don't need to draw this frame + { + // Skip this pass! + Draw( false ); + } + } + + // Emissive Scroll Pass + if ( params[EMISSIVEBLENDENABLED]->GetIntValue() ) + { + // If ( snapshotting ) or ( we need to draw this frame ) + if ( ( pShaderShadow != NULL ) || ( params[EMISSIVEBLENDSTRENGTH]->GetFloatValue() > 0.0f ) ) + { + EmissiveScrollBlendedPassVars_t info; + SetupVarsEmissiveScrollBlendedPass( info ); + DrawEmissiveScrollBlendedPass( this, params, pShaderAPI, pShaderShadow, info, vertexCompression ); + } + else // We're not snapshotting and we don't need to draw this frame + { + // Skip this pass! + Draw( false ); + } + } + + // Flesh Interior Pass + if ( params[FLESHINTERIORENABLED]->GetIntValue() ) + { + // If ( snapshotting ) or ( we need to draw this frame ) + if ( ( pShaderShadow != NULL ) || ( true ) ) + { + FleshInteriorBlendedPassVars_t info; + SetupVarsFleshInteriorBlendedPass( info ); + DrawFleshInteriorBlendedPass( this, params, pShaderAPI, pShaderShadow, info, vertexCompression ); + } + else // We're not snapshotting and we don't need to draw this frame + { + // Skip this pass! + Draw( false ); + } + } + } +END_SHADER diff --git a/materialsystem/stdshaders/vertexlitgeneric_dx95_helper.h b/materialsystem/stdshaders/vertexlitgeneric_dx95_helper.h new file mode 100644 index 0000000..3736bfe --- /dev/null +++ b/materialsystem/stdshaders/vertexlitgeneric_dx95_helper.h @@ -0,0 +1,71 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//============================================================================= + +#ifndef VERTEXLITGENERIC_DX95_HELPER_H +#define VERTEXLITGENERIC_DX95_HELPER_H + +#include + + +//----------------------------------------------------------------------------- +// Forward declarations +//----------------------------------------------------------------------------- +class CBaseVSShader; +class IMaterialVar; +class IShaderDynamicAPI; +class IShaderShadow; + + +//----------------------------------------------------------------------------- +// Init params/ init/ draw methods +//----------------------------------------------------------------------------- +struct VertexLitGeneric_DX95_Vars_t +{ + VertexLitGeneric_DX95_Vars_t() { memset( this, 0xFF, sizeof(VertexLitGeneric_DX95_Vars_t) ); } + + int m_nBaseTexture; + int m_nBaseTextureFrame; + int m_nBaseTexture2; + int m_nBaseTextureFrame2; + int m_nBaseTexture3; + int m_nBaseTextureFrame3; + int m_nBaseTextureTransform; + int m_nAlbedo; + int m_nSelfIllumTint; + int m_nDetail; + int m_nDetailFrame; + int m_nDetailScale; + int m_nEnvmap; + int m_nEnvmapFrame; + int m_nEnvmapMask; + int m_nEnvmapMaskFrame; + int m_nEnvmapMaskTransform; + int m_nEnvmapTint; + int m_nBumpmap; + int m_nBumpFrame; + int m_nBumpmap2; + int m_nBumpFrame2; + int m_nBumpMask; + int m_nBumpmap3; + int m_nBumpFrame3; + int m_nBumpTransform; + int m_nEnvmapContrast; + int m_nEnvmapSaturation; + int m_nAlphaTestReference; + int m_nFlashlightTexture; + int m_nFlashlightTextureFrame; + int m_nSelfIllumEnvMapMask_Alpha; + +}; + +void InitParamsVertexLitGeneric_DX95( CBaseVSShader *pShader, IMaterialVar** params, const char *pMaterialName, bool bVertexLitGeneric, VertexLitGeneric_DX95_Vars_t &info ); +void InitVertexLitGeneric_DX95( CBaseVSShader *pShader, IMaterialVar** params, bool bVertexLitGeneric, VertexLitGeneric_DX95_Vars_t &info ); +void DrawVertexLitGeneric_DX95( CBaseVSShader *pShader, IMaterialVar** params, + IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow, bool bVertexLitGeneric, VertexLitGeneric_DX95_Vars_t &info ); + + +#endif // VERTEXLITGENERIC_DX95_HELPER_H diff --git a/materialsystem/stdshaders/vertexlitgeneric_dx9_helper.cpp b/materialsystem/stdshaders/vertexlitgeneric_dx9_helper.cpp new file mode 100644 index 0000000..d3fd54f --- /dev/null +++ b/materialsystem/stdshaders/vertexlitgeneric_dx9_helper.cpp @@ -0,0 +1,1468 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +// +//===========================================================================// +#include "BaseVSShader.h" +#include "vertexlitgeneric_dx9_helper.h" +#include "skin_dx9_helper.h" + +#include "VertexLit_and_unlit_Generic_vs20.inc" +#include "VertexLit_and_unlit_Generic_bump_vs20.inc" + +#include "vertexlit_and_unlit_generic_ps20.inc" +#include "vertexlit_and_unlit_generic_ps20b.inc" +#include "vertexlit_and_unlit_generic_bump_ps20.inc" +#include "vertexlit_and_unlit_generic_bump_ps20b.inc" + +#ifndef _X360 +#include "vertexlit_and_unlit_generic_vs30.inc" +#include "vertexlit_and_unlit_generic_ps30.inc" +#include "vertexlit_and_unlit_generic_bump_vs30.inc" +#include "vertexlit_and_unlit_generic_bump_ps30.inc" +#endif + +#include "commandbuilder.h" +#include "convar.h" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +static ConVar mat_fullbright( "mat_fullbright","0", FCVAR_CHEAT ); +static ConVar r_lightwarpidentity( "r_lightwarpidentity","0", FCVAR_CHEAT ); +static ConVar mat_luxels( "mat_luxels", "0", FCVAR_CHEAT ); + + +static inline bool WantsSkinShader( IMaterialVar** params, const VertexLitGeneric_DX9_Vars_t &info ) +{ + if ( info.m_nPhong == -1) // Don't use skin without Phong + return false; + + if ( params[info.m_nPhong]->GetIntValue() == 0 ) // Don't use skin without Phong turned on + return false; + + if ( ( info.m_nDiffuseWarpTexture != -1 ) && params[info.m_nDiffuseWarpTexture]->IsTexture() ) // If there's Phong and diffuse warp do skin + return true; + + if ( ( info.m_nBaseMapAlphaPhongMask != -1 ) && params[info.m_nBaseMapAlphaPhongMask]->GetIntValue() != 1 ) + { + if ( info.m_nBumpmap == -1 ) // Don't use without a bump map + return false; + + if ( !params[info.m_nBumpmap]->IsTexture() ) // Don't use if the texture isn't specified + return false; + } + + return true; +} + +int g_nSnapShots; + +//----------------------------------------------------------------------------- +// Initialize shader parameters +//----------------------------------------------------------------------------- +void InitParamsVertexLitGeneric_DX9( CBaseVSShader *pShader, IMaterialVar** params, const char *pMaterialName, bool bVertexLitGeneric, VertexLitGeneric_DX9_Vars_t &info ) +{ + InitIntParam( info.m_nPhong, params, 0 ); + + InitFloatParam( info.m_nAlphaTestReference, params, 0.0f ); + InitIntParam( info.m_nVertexAlphaTest, params, 0 ); + + InitIntParam( info.m_nFlashlightNoLambert, params, 0 ); + + if ( info.m_nDetailTint != -1 && !params[info.m_nDetailTint]->IsDefined() ) + { + params[info.m_nDetailTint]->SetVecValue( 1.0f, 1.0f, 1.0f ); + } + + if ( info.m_nEnvmapTint != -1 && !params[info.m_nEnvmapTint]->IsDefined() ) + { + params[info.m_nEnvmapTint]->SetVecValue( 1.0f, 1.0f, 1.0f ); + } + + InitIntParam( info.m_nEnvmapFrame, params, 0 ); + InitIntParam( info.m_nBumpFrame, params, 0 ); + InitFloatParam( info.m_nDetailTextureBlendFactor, params, 1.0 ); + InitIntParam( info.m_nReceiveFlashlight, params, 0 ); + + InitFloatParam( info.m_nDetailScale, params, 4.0f ); + + if ( (info.m_nBlendTintByBaseAlpha != -1) && (!params[info.m_nBlendTintByBaseAlpha]->IsDefined()) ) + { + params[info.m_nBlendTintByBaseAlpha]->SetIntValue( 0 ); + } + + InitFloatParam( info.m_nTintReplacesBaseColor, params, 0 ); + + if ( (info.m_nSelfIllumTint != -1) && (!params[info.m_nSelfIllumTint]->IsDefined()) ) + { + params[info.m_nSelfIllumTint]->SetVecValue( 1.0f, 1.0f, 1.0f ); + } + + + if ( WantsSkinShader( params, info ) ) + { + if ( !g_pHardwareConfig->SupportsPixelShaders_2_b() || !g_pConfig->UsePhong() ) + { + params[info.m_nPhong]->SetIntValue( 0 ); + } + else + { + InitParamsSkin_DX9( pShader, params, pMaterialName, info ); + return; + } + } + + // FLASHLIGHTFIXME: Do ShaderAPI::BindFlashlightTexture + if ( info.m_nFlashlightTexture != -1 ) + { + if ( g_pHardwareConfig->SupportsBorderColor() ) + { + params[FLASHLIGHTTEXTURE]->SetStringValue( "effects/flashlight_border" ); + } + else + { + params[FLASHLIGHTTEXTURE]->SetStringValue( "effects/flashlight001" ); + } + } + + // Write over $basetexture with $info.m_nBumpmap if we are going to be using diffuse normal mapping. + if ( info.m_nAlbedo != -1 && g_pConfig->UseBumpmapping() && info.m_nBumpmap != -1 && params[info.m_nBumpmap]->IsDefined() && params[info.m_nAlbedo]->IsDefined() && + params[info.m_nBaseTexture]->IsDefined() ) + { + params[info.m_nBaseTexture]->SetStringValue( params[info.m_nAlbedo]->GetStringValue() ); + } + + // This shader can be used with hw skinning + SET_FLAGS2( MATERIAL_VAR2_SUPPORTS_HW_SKINNING ); + + if ( bVertexLitGeneric ) + { + SET_FLAGS2( MATERIAL_VAR2_LIGHTING_VERTEX_LIT ); + } + else + { + CLEAR_FLAGS( MATERIAL_VAR_SELFILLUM ); + } + + InitIntParam( info.m_nEnvmapMaskFrame, params, 0 ); + InitFloatParam( info.m_nEnvmapContrast, params, 0.0 ); + InitFloatParam( info.m_nEnvmapSaturation, params, 1.0f ); + InitFloatParam( info.m_nSeamlessScale, params, 0.0 ); + + // handle line art parms + InitFloatParam( info.m_nEdgeSoftnessStart, params, 0.5 ); + InitFloatParam( info.m_nEdgeSoftnessEnd, params, 0.5 ); + InitFloatParam( info.m_nGlowAlpha, params, 1.0 ); + InitFloatParam( info.m_nOutlineAlpha, params, 1.0 ); + + // No texture means no self-illum or env mask in base alpha + if ( info.m_nBaseTexture != -1 && !params[info.m_nBaseTexture]->IsDefined() ) + { + CLEAR_FLAGS( MATERIAL_VAR_SELFILLUM ); + CLEAR_FLAGS( MATERIAL_VAR_BASEALPHAENVMAPMASK ); + } + + // If in decal mode, no debug override... + if (IS_FLAG_SET(MATERIAL_VAR_DECAL)) + { + SET_FLAGS( MATERIAL_VAR_NO_DEBUG_OVERRIDE ); + } + + if( ( (info.m_nBumpmap != -1) && g_pConfig->UseBumpmapping() && params[info.m_nBumpmap]->IsDefined() ) + // we don't need a tangent space if we have envmap without bumpmap + // || ( info.m_nEnvmap != -1 && params[info.m_nEnvmap]->IsDefined() ) + ) + { + SET_FLAGS2( MATERIAL_VAR2_NEEDS_TANGENT_SPACES ); + } + else if ( (info.m_nDiffuseWarpTexture != -1) && params[info.m_nDiffuseWarpTexture]->IsDefined() ) // diffuse warp goes down bump path... + { + SET_FLAGS2( MATERIAL_VAR2_NEEDS_TANGENT_SPACES ); + } + else // no tangent space needed + { + CLEAR_FLAGS( MATERIAL_VAR_NORMALMAPALPHAENVMAPMASK ); + } + + bool hasNormalMapAlphaEnvmapMask = IS_FLAG_SET( MATERIAL_VAR_NORMALMAPALPHAENVMAPMASK ); + if ( hasNormalMapAlphaEnvmapMask ) + { + params[info.m_nEnvmapMask]->SetUndefined(); + CLEAR_FLAGS( MATERIAL_VAR_BASEALPHAENVMAPMASK ); + } + + if ( IS_FLAG_SET( MATERIAL_VAR_BASEALPHAENVMAPMASK ) && info.m_nBumpmap != -1 && + params[info.m_nBumpmap]->IsDefined() && !hasNormalMapAlphaEnvmapMask ) + { + Warning( "material %s has a normal map and $basealphaenvmapmask. Must use $normalmapalphaenvmapmask to get specular.\n\n", pMaterialName ); + params[info.m_nEnvmap]->SetUndefined(); + } + + if ( info.m_nEnvmapMask != -1 && params[info.m_nEnvmapMask]->IsDefined() && info.m_nBumpmap != -1 && params[info.m_nBumpmap]->IsDefined() ) + { + params[info.m_nEnvmapMask]->SetUndefined(); + if ( !hasNormalMapAlphaEnvmapMask ) + { + Warning( "material %s has a normal map and an envmapmask. Must use $normalmapalphaenvmapmask.\n\n", pMaterialName ); + params[info.m_nEnvmap]->SetUndefined(); + } + } + + // If mat_specular 0, then get rid of envmap + if ( !g_pConfig->UseSpecular() && info.m_nEnvmap != -1 && params[info.m_nEnvmap]->IsDefined() && params[info.m_nBaseTexture]->IsDefined() ) + { + params[info.m_nEnvmap]->SetUndefined(); + } + + InitFloatParam( info.m_nHDRColorScale, params, 1.0f ); + + InitIntParam( info.m_nLinearWrite, params, 0 ); + InitIntParam( info.m_nGammaColorRead, params, 0 ); + + InitIntParam( info.m_nDepthBlend, params, 0 ); + InitFloatParam( info.m_nDepthBlendScale, params, 50.0f ); +} + + +//----------------------------------------------------------------------------- +// Initialize shader +//----------------------------------------------------------------------------- + +void InitVertexLitGeneric_DX9( CBaseVSShader *pShader, IMaterialVar** params, bool bVertexLitGeneric, VertexLitGeneric_DX9_Vars_t &info ) +{ + // both detailed and bumped = needs skin shader (for now) + bool bNeedsSkinBecauseOfDetail = false; + + //bool bHasBump = ( info.m_nBumpmap != -1 ) && params[info.m_nBumpmap]->IsTexture(); + //if ( bHasBump ) + //{ + // if ( ( info.m_nDetail != -1 ) && params[info.m_nDetail]->IsDefined() ) + // bNeedsSkinBecauseOfDetail = true; + //} + + if ( bNeedsSkinBecauseOfDetail || + ( info.m_nPhong != -1 && + params[info.m_nPhong]->GetIntValue() && + g_pHardwareConfig->SupportsPixelShaders_2_b() ) ) + { + InitSkin_DX9( pShader, params, info ); + return; + } + + if ( info.m_nFlashlightTexture != -1 ) + { + pShader->LoadTexture( info.m_nFlashlightTexture, TEXTUREFLAGS_SRGB ); + } + + bool bIsBaseTextureTranslucent = false; + if ( info.m_nBaseTexture != -1 && params[info.m_nBaseTexture]->IsDefined() ) + { + pShader->LoadTexture( info.m_nBaseTexture, ( info.m_nGammaColorRead != -1 ) && ( params[info.m_nGammaColorRead]->GetIntValue() == 1 ) ? 0 : TEXTUREFLAGS_SRGB ); + + if ( params[info.m_nBaseTexture]->GetTextureValue()->IsTranslucent() ) + { + bIsBaseTextureTranslucent = true; + } + } + + bool bHasSelfIllumMask = IS_FLAG_SET( MATERIAL_VAR_SELFILLUM ) && (info.m_nSelfIllumMask != -1) && params[info.m_nSelfIllumMask]->IsDefined(); + + // No alpha channel in any of the textures? No self illum or envmapmask + if ( !bIsBaseTextureTranslucent ) + { + bool bHasSelfIllumFresnel = IS_FLAG_SET( MATERIAL_VAR_SELFILLUM ) && ( info.m_nSelfIllumFresnel != -1 ) && ( params[info.m_nSelfIllumFresnel]->GetIntValue() != 0 ); + + // Can still be self illum with no base alpha if using one of these alternate modes + if ( !bHasSelfIllumFresnel && !bHasSelfIllumMask ) + { + CLEAR_FLAGS( MATERIAL_VAR_SELFILLUM ); + } + + CLEAR_FLAGS( MATERIAL_VAR_BASEALPHAENVMAPMASK ); + } + + if ( info.m_nDetail != -1 && params[info.m_nDetail]->IsDefined() ) + { + int nDetailBlendMode = ( info.m_nDetailTextureCombineMode == -1 ) ? 0 : params[info.m_nDetailTextureCombineMode]->GetIntValue(); + if ( nDetailBlendMode == 0 ) //Mod2X + pShader->LoadTexture( info.m_nDetail ); + else + pShader->LoadTexture( info.m_nDetail, TEXTUREFLAGS_SRGB ); + } + + if ( g_pConfig->UseBumpmapping() ) + { + if ( (info.m_nBumpmap != -1) && params[info.m_nBumpmap]->IsDefined() ) + { + pShader->LoadBumpMap( info.m_nBumpmap ); + SET_FLAGS2( MATERIAL_VAR2_DIFFUSE_BUMPMAPPED_MODEL ); + } + else if ( (info.m_nDiffuseWarpTexture != -1) && params[info.m_nDiffuseWarpTexture]->IsDefined() ) + { + SET_FLAGS2( MATERIAL_VAR2_DIFFUSE_BUMPMAPPED_MODEL ); + } + } + + // Don't alpha test if the alpha channel is used for other purposes + if ( IS_FLAG_SET(MATERIAL_VAR_SELFILLUM) || IS_FLAG_SET(MATERIAL_VAR_BASEALPHAENVMAPMASK) ) + { + CLEAR_FLAGS( MATERIAL_VAR_ALPHATEST ); + } + + if ( info.m_nEnvmap != -1 && params[info.m_nEnvmap]->IsDefined() ) + { + if ( !IS_FLAG_SET(MATERIAL_VAR_ENVMAPSPHERE) ) + { + pShader->LoadCubeMap( info.m_nEnvmap, g_pHardwareConfig->GetHDRType() == HDR_TYPE_NONE ? TEXTUREFLAGS_SRGB : 0 ); + } + else + { + pShader->LoadTexture( info.m_nEnvmap, g_pHardwareConfig->GetHDRType() == HDR_TYPE_NONE ? TEXTUREFLAGS_SRGB : 0 ); + } + + if ( !g_pHardwareConfig->SupportsCubeMaps() ) + { + SET_FLAGS( MATERIAL_VAR_ENVMAPSPHERE ); + } + } + if ( info.m_nEnvmapMask != -1 && params[info.m_nEnvmapMask]->IsDefined() ) + { + pShader->LoadTexture( info.m_nEnvmapMask ); + } + + if ( (info.m_nDiffuseWarpTexture != -1) && params[info.m_nDiffuseWarpTexture]->IsDefined() ) + { + pShader->LoadTexture( info.m_nDiffuseWarpTexture ); + } + + if ( bHasSelfIllumMask ) + { + pShader->LoadTexture( info.m_nSelfIllumMask ); + } +} + +class CVertexLitGeneric_DX9_Context : public CBasePerMaterialContextData +{ +public: + CCommandBufferBuilder< CFixedCommandStorageBuffer< 800 > > m_SemiStaticCmdsOut; + +}; + + +//----------------------------------------------------------------------------- +// Draws the shader +//----------------------------------------------------------------------------- +static void DrawVertexLitGeneric_DX9_Internal( CBaseVSShader *pShader, IMaterialVar** params, + IShaderDynamicAPI *pShaderAPI, + IShaderShadow* pShaderShadow, + bool bVertexLitGeneric, bool bHasFlashlight, + VertexLitGeneric_DX9_Vars_t &info, + VertexCompressionType_t vertexCompression, + CBasePerMaterialContextData **pContextDataPtr ) + +{ + CVertexLitGeneric_DX9_Context *pContextData = reinterpret_cast< CVertexLitGeneric_DX9_Context *> ( *pContextDataPtr ); + +/*^*/ // printf("\t\t>DrawVertexLitGeneric_DX9_Internal\n"); + + bool bHasBump = IsTextureSet( info.m_nBumpmap, params ); +#if !defined( _X360 ) + bool bIsDecal = IS_FLAG_SET( MATERIAL_VAR_DECAL ); +#endif + + bool hasDiffuseLighting = bVertexLitGeneric; +/*^*/ // printf("\t\t[%d] bVertexLitGeneric\n",(int)bVertexLitGeneric); + + if ( IS_FLAG_SET(MATERIAL_VAR_ENVMAPSPHERE) ) + { + bHasFlashlight = false; + } + + bool bIsAlphaTested = IS_FLAG_SET( MATERIAL_VAR_ALPHATEST ) != 0; + bool bHasDiffuseWarp = (!bHasFlashlight || IsX360() ) && hasDiffuseLighting && (info.m_nDiffuseWarpTexture != -1) && params[info.m_nDiffuseWarpTexture]->IsTexture(); + bool bHasLightmapTexture = IsTextureSet( info.m_nLightmap, params ); + bool bHasMatLuxel = bHasLightmapTexture && mat_luxels.GetBool(); + + //bool bNoCull = IS_FLAG_SET( MATERIAL_VAR_NOCULL ); + bool bFlashlightNoLambert = false; + if ( ( info.m_nFlashlightNoLambert != -1 ) && params[info.m_nFlashlightNoLambert]->GetIntValue() ) + { + bFlashlightNoLambert = true; + } + + bool bAmbientOnly = IsBoolSet( info.m_nAmbientOnly, params ); + + float fBlendFactor = GetFloatParam( info.m_nDetailTextureBlendFactor, params, 1.0 ); + bool bHasDetailTexture = IsTextureSet( info.m_nDetail, params ); + int nDetailBlendMode = bHasDetailTexture ? GetIntParam( info.m_nDetailTextureCombineMode, params ) : 0; + int nDetailTranslucencyTexture = -1; + + if ( bHasDetailTexture ) + { + if ( ( nDetailBlendMode == 6 ) && ( ! (g_pHardwareConfig->SupportsPixelShaders_2_b() ) ) ) + { + nDetailBlendMode = 5; // skip fancy threshold blending if ps2.0 + } + if ( ( nDetailBlendMode == 3 ) || ( nDetailBlendMode == 8 ) || ( nDetailBlendMode == 9 ) ) + nDetailTranslucencyTexture = info.m_nDetail; + } + + bool bBlendTintByBaseAlpha = IsBoolSet( info.m_nBlendTintByBaseAlpha, params ); + float fTintReplaceFactor = GetFloatParam( info.m_nTintReplacesBaseColor, params, 0.0 ); + + BlendType_t nBlendType; + bool bHasBaseTexture = IsTextureSet( info.m_nBaseTexture, params ); + if ( bHasBaseTexture ) + { + // if base alpha is used for tinting, ignore the base texture for computing translucency + nBlendType = pShader->EvaluateBlendRequirements( bBlendTintByBaseAlpha ? -1 : info.m_nBaseTexture, true, nDetailTranslucencyTexture ); + } + else + { + nBlendType = pShader->EvaluateBlendRequirements( info.m_nEnvmapMask, false ); + } + bool bFullyOpaque = (nBlendType != BT_BLENDADD) && (nBlendType != BT_BLEND) && !bIsAlphaTested && (!bHasFlashlight || IsX360() ); //dest alpha is free for special use + + bool bHasEnvmap = (!bHasFlashlight || IsX360() ) && info.m_nEnvmap != -1 && params[info.m_nEnvmap]->IsTexture(); + + + bool bHasVertexColor = bVertexLitGeneric ? false : IS_FLAG_SET( MATERIAL_VAR_VERTEXCOLOR ); + bool bHasVertexAlpha = bVertexLitGeneric ? false : IS_FLAG_SET( MATERIAL_VAR_VERTEXALPHA ); +/*^*/ // printf("\t\t[%d] bHasVertexColor\n",(int)bHasVertexColor); +/*^*/ // printf("\t\t[%d] bHasVertexAlpha\n",(int)bHasVertexAlpha); + + if ( pShader->IsSnapshotting() || (! pContextData ) || ( pContextData->m_bMaterialVarsChanged ) ) + { +/*^*/ // printf("\t\t[1] snapshotting=%d pContextData=%08x pContextData->m_bMaterialVarsChanged=%d \n",(int)pShader->IsSnapshotting(), (int)pContextData, pContextData ? (int)pContextData->m_bMaterialVarsChanged : -1 ); + bool bSeamlessBase = IsBoolSet( info.m_nSeamlessBase, params ); + bool bSeamlessDetail = IsBoolSet( info.m_nSeamlessDetail, params ); + bool bDistanceAlpha = IsBoolSet( info.m_nDistanceAlpha, params ); + bool bHasSelfIllum = (!bHasFlashlight || IsX360() ) && IS_FLAG_SET( MATERIAL_VAR_SELFILLUM ); + bool bHasEnvmapMask = (!bHasFlashlight || IsX360() ) && info.m_nEnvmapMask != -1 && params[info.m_nEnvmapMask]->IsTexture(); + bool bHasSelfIllumFresnel = ( !IsTextureSet( info.m_nDetail, params ) ) && ( bHasSelfIllum ) && ( info.m_nSelfIllumFresnel != -1 ) && ( params[info.m_nSelfIllumFresnel]->GetIntValue() != 0 ); + + bool bHasSelfIllumMask = bHasSelfIllum && IsTextureSet( info.m_nSelfIllumMask, params ); + bool hasSelfIllumInEnvMapMask = + ( info.m_nSelfIllumEnvMapMask_Alpha != -1 ) && + ( params[info.m_nSelfIllumEnvMapMask_Alpha]->GetFloatValue() != 0.0 ) ; + + if ( pShader->IsSnapshotting() ) + { +/*^*/ // printf("\t\t[2] snapshotting...\n"); + + bool hasBaseAlphaEnvmapMask = IS_FLAG_SET( MATERIAL_VAR_BASEALPHAENVMAPMASK ); + bool hasNormalMapAlphaEnvmapMask = IS_FLAG_SET( MATERIAL_VAR_NORMALMAPALPHAENVMAPMASK ); + + + if ( info.m_nVertexAlphaTest != -1 && params[info.m_nVertexAlphaTest]->GetIntValue() > 0 ) + { + bHasVertexAlpha = true; + } + + // look at color and alphamod stuff. + // Unlit generic never uses the flashlight + if ( bHasSelfIllumFresnel ) + { + CLEAR_FLAGS( MATERIAL_VAR_NORMALMAPALPHAENVMAPMASK ); + hasNormalMapAlphaEnvmapMask = false; + } + + bool bHasEnvmap = (!bHasFlashlight || IsX360() ) && ( info.m_nEnvmap != -1 ) && params[info.m_nEnvmap]->IsTexture(); + bool bHasLegacyEnvSphereMap = bHasEnvmap && IS_FLAG_SET(MATERIAL_VAR_ENVMAPSPHERE); + bool bHasNormal = bVertexLitGeneric || bHasEnvmap || bHasFlashlight || bSeamlessBase || bSeamlessDetail; + if ( IsPC() ) + { + // On PC, LIGHTING_PREVIEW requires normals (they won't use much memory - unlitgeneric isn't used on many models) + bHasNormal = true; + } + + bool bHalfLambert = IS_FLAG_SET( MATERIAL_VAR_HALFLAMBERT ); + // Alpha test: FIXME: shouldn't this be handled in CBaseVSShader::SetInitialShadowState + pShaderShadow->EnableAlphaTest( bIsAlphaTested ); + + if ( info.m_nAlphaTestReference != -1 && params[info.m_nAlphaTestReference]->GetFloatValue() > 0.0f ) + { + pShaderShadow->AlphaFunc( SHADER_ALPHAFUNC_GEQUAL, params[info.m_nAlphaTestReference]->GetFloatValue() ); + } + + int nShadowFilterMode = 0; + if ( bHasFlashlight ) + { + if ( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + nShadowFilterMode = g_pHardwareConfig->GetShadowFilterMode(); // Based upon vendor and device dependent formats + } + + if ( !IsX360() ) + { + if (params[info.m_nBaseTexture]->IsTexture()) + { + pShader->SetAdditiveBlendingShadowState( info.m_nBaseTexture, true ); + } + else + { + pShader->SetAdditiveBlendingShadowState( info.m_nEnvmapMask, false ); + } + + if ( bIsAlphaTested ) + { + // disable alpha test and use the zfunc zequals since alpha isn't guaranteed to + // be the same on both the regular pass and the flashlight pass. + pShaderShadow->EnableAlphaTest( false ); + pShaderShadow->DepthFunc( SHADER_DEPTHFUNC_EQUAL ); + } + + // Be sure not to write to dest alpha + pShaderShadow->EnableAlphaWrites( false ); + + pShaderShadow->EnableBlending( true ); + pShaderShadow->EnableDepthWrites( false ); + } + else + { + pShader->SetBlendingShadowState( nBlendType ); + } + } + else + { + pShader->SetBlendingShadowState( nBlendType ); + } + + unsigned int flags = VERTEX_POSITION; + if ( bHasNormal ) + { + flags |= VERTEX_NORMAL; + } +/*^*/ // printf("\t\t[%1d] VERTEX_NORMAL\n",(flags&VERTEX_NORMAL)!=0); + + int userDataSize = 0; + bool bSRGBInputAdapter = false; + + // basetexture + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + if ( bHasBaseTexture ) + { + if ( ( info.m_nGammaColorRead != -1 ) && ( params[info.m_nGammaColorRead]->GetIntValue() == 1 ) ) + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, false ); + else + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, true ); + + // If we're on OSX GL on a crappy OS which can't do sRGB from render targets, check to see if we're reading from one... + if ( IsOSX() && !g_pHardwareConfig->CanDoSRGBReadFromRTs() ) + { + ITexture *pBaseTexture = params[info.m_nBaseTexture]->GetTextureValue(); + if ( pBaseTexture && pBaseTexture->IsRenderTarget() ) + { + bSRGBInputAdapter = true; + } + } + } + + if ( bHasEnvmap ) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + if( g_pHardwareConfig->GetHDRType() == HDR_TYPE_NONE ) + { + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER1, true ); + } + } + if ( bHasFlashlight ) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER8, true ); // Depth texture + pShaderShadow->SetShadowDepthFiltering( SHADER_SAMPLER8 ); + pShaderShadow->EnableTexture( SHADER_SAMPLER6, true ); // Noise map + pShaderShadow->EnableTexture( SHADER_SAMPLER7, true ); // Flashlight cookie + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER7, true ); + userDataSize = 4; // tangent S + } + + if ( bHasDetailTexture ) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER2, true ); + if ( nDetailBlendMode != 0 ) //Not Mod2X + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER2, true ); + } + + if ( bHasBump || bHasDiffuseWarp ) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER3, true ); + userDataSize = 4; // tangent S + // Normalizing cube map + pShaderShadow->EnableTexture( SHADER_SAMPLER5, true ); + } + if ( bHasEnvmapMask ) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER4, true ); + } + + if ( bHasVertexColor || bHasVertexAlpha ) + { + flags |= VERTEX_COLOR; + } +/*^*/ // printf("\t\t[%1d] VERTEX_COLOR\n",(flags&VERTEX_COLOR)!=0); +/*^*/ // printf("\t\t[%1d] VERTEX_COLOR_STREAM_1\n",(flags&VERTEX_COLOR_STREAM_1)!=0); + + + if( bHasDiffuseWarp && (!bHasFlashlight || IsX360() ) && !bHasSelfIllumFresnel ) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER9, true ); // Diffuse warp texture + } + + if ( (info.m_nDepthBlend != -1) && (params[info.m_nDepthBlend]->GetIntValue()) ) + { + if( bHasBump ) + Warning( "DEPTHBLEND not supported by bump mapped variations of vertexlitgeneric to avoid shader bloat. Either remove the bump map or convince a graphics programmer that it's worth it.\n" ); + + pShaderShadow->EnableTexture( SHADER_SAMPLER10, true ); + } + + if( bHasSelfIllum ) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER11, true ); // self illum mask + } + + + // Always enable this sampler, used for lightmaps depending on the dynamic combo. + // Lightmaps are generated in gamma space, but not sRGB, so leave that disabled. Conversion is done in the shader. + pShaderShadow->EnableTexture( SHADER_SAMPLER12, true ); + + bool bSRGBWrite = true; + if( (info.m_nLinearWrite != -1) && (params[info.m_nLinearWrite]->GetIntValue() == 1) ) + { + bSRGBWrite = false; + } + + pShaderShadow->EnableSRGBWrite( bSRGBWrite ); + + // texcoord0 : base texcoord + int pTexCoordDim[3] = { 2, 2, 3 }; + int nTexCoordCount = 1; + + if ( IsBoolSet( info.m_nSeparateDetailUVs, params ) ) + { + ++nTexCoordCount; + } + else + { + pTexCoordDim[1] = 0; + } + +#ifndef _X360 + // Special morphed decal information + if ( bIsDecal && g_pHardwareConfig->HasFastVertexTextures() ) + { + nTexCoordCount = 3; + } +#endif + + // This shader supports compressed vertices, so OR in that flag: + flags |= VERTEX_FORMAT_COMPRESSED; +/*^*/ // printf("\t\t[%1d] VERTEX_FORMAT_COMPRESSED\n",(flags&VERTEX_FORMAT_COMPRESSED)!=0); + +/*^*/ // printf("\t\t -> CShaderShadowDX8::VertexShaderVertexFormat( flags=%08x, texcount=%d )\n",flags,nTexCoordCount); + + + pShaderShadow->VertexShaderVertexFormat( flags, nTexCoordCount, pTexCoordDim, userDataSize ); + + if ( bHasBump || bHasDiffuseWarp ) + { +#ifndef _X360 + if ( !g_pHardwareConfig->HasFastVertexTextures() ) +#endif + { + bool bUseStaticControlFlow = g_pHardwareConfig->SupportsStaticControlFlow(); + + DECLARE_STATIC_VERTEX_SHADER( vertexlit_and_unlit_generic_bump_vs20 ); + SET_STATIC_VERTEX_SHADER_COMBO( HALFLAMBERT, bHalfLambert); + SET_STATIC_VERTEX_SHADER_COMBO( USE_WITH_2B, g_pHardwareConfig->SupportsPixelShaders_2_b() ); +#ifdef _X360 + SET_STATIC_VERTEX_SHADER_COMBO( FLASHLIGHT, bHasFlashlight ); +#endif + SET_STATIC_VERTEX_SHADER_COMBO( USE_STATIC_CONTROL_FLOW, bUseStaticControlFlow ); + SET_STATIC_VERTEX_SHADER( vertexlit_and_unlit_generic_bump_vs20 ); + + if ( g_pHardwareConfig->SupportsPixelShaders_2_b() || g_pHardwareConfig->ShouldAlwaysUseShaderModel2bShaders() ) // Always send GL this way + { + DECLARE_STATIC_PIXEL_SHADER( vertexlit_and_unlit_generic_bump_ps20b ); + SET_STATIC_PIXEL_SHADER_COMBO( CUBEMAP, bHasEnvmap ); + SET_STATIC_PIXEL_SHADER_COMBO( DIFFUSELIGHTING, hasDiffuseLighting ); + SET_STATIC_PIXEL_SHADER_COMBO( LIGHTWARPTEXTURE, bHasDiffuseWarp && !bHasSelfIllumFresnel ); + SET_STATIC_PIXEL_SHADER_COMBO( SELFILLUM, bHasSelfIllum ); + SET_STATIC_PIXEL_SHADER_COMBO( SELFILLUMFRESNEL, bHasSelfIllumFresnel ); + SET_STATIC_PIXEL_SHADER_COMBO( NORMALMAPALPHAENVMAPMASK, hasNormalMapAlphaEnvmapMask && bHasEnvmap ); + SET_STATIC_PIXEL_SHADER_COMBO( HALFLAMBERT, bHalfLambert); + SET_STATIC_PIXEL_SHADER_COMBO( FLASHLIGHT, bHasFlashlight ); + SET_STATIC_PIXEL_SHADER_COMBO( DETAILTEXTURE, bHasDetailTexture ); + SET_STATIC_PIXEL_SHADER_COMBO( DETAIL_BLEND_MODE, nDetailBlendMode ); + SET_STATIC_PIXEL_SHADER_COMBO( FLASHLIGHTDEPTHFILTERMODE, nShadowFilterMode ); + SET_STATIC_PIXEL_SHADER_COMBO( BLENDTINTBYBASEALPHA, bBlendTintByBaseAlpha ); + SET_STATIC_PIXEL_SHADER( vertexlit_and_unlit_generic_bump_ps20b ); + } + else // ps_2_0 + { + DECLARE_STATIC_PIXEL_SHADER( vertexlit_and_unlit_generic_bump_ps20 ); + SET_STATIC_PIXEL_SHADER_COMBO( CUBEMAP, bHasEnvmap ); + SET_STATIC_PIXEL_SHADER_COMBO( DIFFUSELIGHTING, hasDiffuseLighting ); + SET_STATIC_PIXEL_SHADER_COMBO( LIGHTWARPTEXTURE, bHasDiffuseWarp && !bHasSelfIllumFresnel ); + SET_STATIC_PIXEL_SHADER_COMBO( SELFILLUM, bHasSelfIllum ); + SET_STATIC_PIXEL_SHADER_COMBO( SELFILLUMFRESNEL, bHasSelfIllumFresnel ); + SET_STATIC_PIXEL_SHADER_COMBO( NORMALMAPALPHAENVMAPMASK, hasNormalMapAlphaEnvmapMask && bHasEnvmap ); + SET_STATIC_PIXEL_SHADER_COMBO( HALFLAMBERT, bHalfLambert); + SET_STATIC_PIXEL_SHADER_COMBO( FLASHLIGHT, bHasFlashlight ); + SET_STATIC_PIXEL_SHADER_COMBO( DETAILTEXTURE, bHasDetailTexture ); + SET_STATIC_PIXEL_SHADER_COMBO( DETAIL_BLEND_MODE, nDetailBlendMode ); + SET_STATIC_PIXEL_SHADER_COMBO( BLENDTINTBYBASEALPHA, bBlendTintByBaseAlpha ); + SET_STATIC_PIXEL_SHADER( vertexlit_and_unlit_generic_bump_ps20 ); + } + } +#ifndef _X360 + else + { + // The vertex shader uses the vertex id stream + SET_FLAGS2( MATERIAL_VAR2_USES_VERTEXID ); + + DECLARE_STATIC_VERTEX_SHADER( vertexlit_and_unlit_generic_bump_vs30 ); + SET_STATIC_VERTEX_SHADER_COMBO( HALFLAMBERT, bHalfLambert); + SET_STATIC_VERTEX_SHADER_COMBO( USE_WITH_2B, true ); + SET_STATIC_VERTEX_SHADER_COMBO( DECAL, bIsDecal ); + SET_STATIC_VERTEX_SHADER( vertexlit_and_unlit_generic_bump_vs30 ); + + DECLARE_STATIC_PIXEL_SHADER( vertexlit_and_unlit_generic_bump_ps30 ); + SET_STATIC_PIXEL_SHADER_COMBO( CUBEMAP, bHasEnvmap ); + SET_STATIC_PIXEL_SHADER_COMBO( DIFFUSELIGHTING, hasDiffuseLighting ); + SET_STATIC_PIXEL_SHADER_COMBO( LIGHTWARPTEXTURE, bHasDiffuseWarp && !bHasSelfIllumFresnel ); + SET_STATIC_PIXEL_SHADER_COMBO( SELFILLUM, bHasSelfIllum ); + SET_STATIC_PIXEL_SHADER_COMBO( SELFILLUMFRESNEL, bHasSelfIllumFresnel ); + SET_STATIC_PIXEL_SHADER_COMBO( NORMALMAPALPHAENVMAPMASK, hasNormalMapAlphaEnvmapMask && bHasEnvmap ); + SET_STATIC_PIXEL_SHADER_COMBO( HALFLAMBERT, bHalfLambert); + SET_STATIC_PIXEL_SHADER_COMBO( FLASHLIGHT, bHasFlashlight ); + SET_STATIC_PIXEL_SHADER_COMBO( DETAILTEXTURE, bHasDetailTexture ); + SET_STATIC_PIXEL_SHADER_COMBO( DETAIL_BLEND_MODE, nDetailBlendMode ); + SET_STATIC_PIXEL_SHADER_COMBO( FLASHLIGHTDEPTHFILTERMODE, nShadowFilterMode ); + SET_STATIC_PIXEL_SHADER_COMBO( BLENDTINTBYBASEALPHA, bBlendTintByBaseAlpha ); + SET_STATIC_PIXEL_SHADER( vertexlit_and_unlit_generic_bump_ps30 ); + } +#endif + } + else // !(bHasBump || bHasDiffuseWarp) + { + bool bDistanceAlphaFromDetail = false; + bool bSoftMask = false; + bool bGlow = false; + bool bOutline = false; + + static ConVarRef mat_reduceparticles( "mat_reduceparticles" ); + bool bDoDepthBlend = IsBoolSet( info.m_nDepthBlend, params ) && !mat_reduceparticles.GetBool(); + + if ( bDistanceAlpha ) + { + bDistanceAlphaFromDetail = IsBoolSet( info.m_nDistanceAlphaFromDetail, params ); + bSoftMask = IsBoolSet( info.m_nSoftEdges, params ); + bGlow = IsBoolSet( info.m_nGlow, params ); + bOutline = IsBoolSet( info.m_nOutline, params ); + } + +#ifndef _X360 + if ( !g_pHardwareConfig->HasFastVertexTextures() ) +#endif + { + bool bUseStaticControlFlow = g_pHardwareConfig->SupportsStaticControlFlow(); + + DECLARE_STATIC_VERTEX_SHADER( vertexlit_and_unlit_generic_vs20 ); + SET_STATIC_VERTEX_SHADER_COMBO( VERTEXCOLOR, bHasVertexColor || bHasVertexAlpha ); + SET_STATIC_VERTEX_SHADER_COMBO( CUBEMAP, bHasEnvmap ); + SET_STATIC_VERTEX_SHADER_COMBO( HALFLAMBERT, bHalfLambert ); + SET_STATIC_VERTEX_SHADER_COMBO( FLASHLIGHT, bHasFlashlight ); + SET_STATIC_VERTEX_SHADER_COMBO( SEAMLESS_BASE, bSeamlessBase ); + SET_STATIC_VERTEX_SHADER_COMBO( SEAMLESS_DETAIL, bSeamlessDetail ); + SET_STATIC_VERTEX_SHADER_COMBO( SEPARATE_DETAIL_UVS, IsBoolSet( info.m_nSeparateDetailUVs, params ) ); + SET_STATIC_VERTEX_SHADER_COMBO( USE_STATIC_CONTROL_FLOW, bUseStaticControlFlow ); + SET_STATIC_VERTEX_SHADER_COMBO( DONT_GAMMA_CONVERT_VERTEX_COLOR, (! bSRGBWrite ) && bHasVertexColor ); + SET_STATIC_VERTEX_SHADER( vertexlit_and_unlit_generic_vs20 ); + + if ( g_pHardwareConfig->SupportsPixelShaders_2_b() || g_pHardwareConfig->ShouldAlwaysUseShaderModel2bShaders() ) // Always send Gl this way + { + DECLARE_STATIC_PIXEL_SHADER( vertexlit_and_unlit_generic_ps20b ); + SET_STATIC_PIXEL_SHADER_COMBO( SELFILLUM_ENVMAPMASK_ALPHA, ( hasSelfIllumInEnvMapMask && ( bHasEnvmapMask ) ) ); + SET_STATIC_PIXEL_SHADER_COMBO( CUBEMAP, bHasEnvmap ); + SET_STATIC_PIXEL_SHADER_COMBO( CUBEMAP_SPHERE_LEGACY, bHasLegacyEnvSphereMap ); + SET_STATIC_PIXEL_SHADER_COMBO( DIFFUSELIGHTING, hasDiffuseLighting ); + SET_STATIC_PIXEL_SHADER_COMBO( ENVMAPMASK, bHasEnvmapMask ); + SET_STATIC_PIXEL_SHADER_COMBO( BASEALPHAENVMAPMASK, hasBaseAlphaEnvmapMask ); + SET_STATIC_PIXEL_SHADER_COMBO( SELFILLUM, bHasSelfIllum ); + SET_STATIC_PIXEL_SHADER_COMBO( VERTEXCOLOR, bHasVertexColor ); + SET_STATIC_PIXEL_SHADER_COMBO( FLASHLIGHT, bHasFlashlight ); + SET_STATIC_PIXEL_SHADER_COMBO( DETAILTEXTURE, bHasDetailTexture ); + SET_STATIC_PIXEL_SHADER_COMBO( DETAIL_BLEND_MODE, nDetailBlendMode ); + SET_STATIC_PIXEL_SHADER_COMBO( SEAMLESS_BASE, bSeamlessBase ); + SET_STATIC_PIXEL_SHADER_COMBO( SEAMLESS_DETAIL, bSeamlessDetail ); + SET_STATIC_PIXEL_SHADER_COMBO( DISTANCEALPHA, bDistanceAlpha ); + SET_STATIC_PIXEL_SHADER_COMBO( DISTANCEALPHAFROMDETAIL, bDistanceAlphaFromDetail ); + SET_STATIC_PIXEL_SHADER_COMBO( SOFT_MASK, bSoftMask ); + SET_STATIC_PIXEL_SHADER_COMBO( OUTLINE, bOutline ); + SET_STATIC_PIXEL_SHADER_COMBO( OUTER_GLOW, bGlow ); + SET_STATIC_PIXEL_SHADER_COMBO( FLASHLIGHTDEPTHFILTERMODE, nShadowFilterMode ); + SET_STATIC_PIXEL_SHADER_COMBO( DEPTHBLEND, bDoDepthBlend ); + SET_STATIC_PIXEL_SHADER_COMBO( SRGB_INPUT_ADAPTER, bSRGBInputAdapter ? 1 : 0 ); + SET_STATIC_PIXEL_SHADER_COMBO( BLENDTINTBYBASEALPHA, bBlendTintByBaseAlpha ); + SET_STATIC_PIXEL_SHADER( vertexlit_and_unlit_generic_ps20b ); + } + else // ps_2_0 + { + DECLARE_STATIC_PIXEL_SHADER( vertexlit_and_unlit_generic_ps20 ); + SET_STATIC_PIXEL_SHADER_COMBO( SELFILLUM_ENVMAPMASK_ALPHA, ( hasSelfIllumInEnvMapMask && ( bHasEnvmapMask ) ) ); + SET_STATIC_PIXEL_SHADER_COMBO( CUBEMAP, bHasEnvmap ); + SET_STATIC_PIXEL_SHADER_COMBO( CUBEMAP_SPHERE_LEGACY, bHasLegacyEnvSphereMap ); + SET_STATIC_PIXEL_SHADER_COMBO( DIFFUSELIGHTING, hasDiffuseLighting ); + SET_STATIC_PIXEL_SHADER_COMBO( ENVMAPMASK, bHasEnvmapMask ); + SET_STATIC_PIXEL_SHADER_COMBO( BASEALPHAENVMAPMASK, hasBaseAlphaEnvmapMask ); + SET_STATIC_PIXEL_SHADER_COMBO( SELFILLUM, bHasSelfIllum ); + SET_STATIC_PIXEL_SHADER_COMBO( VERTEXCOLOR, bHasVertexColor ); + SET_STATIC_PIXEL_SHADER_COMBO( FLASHLIGHT, bHasFlashlight ); + SET_STATIC_PIXEL_SHADER_COMBO( DETAILTEXTURE, bHasDetailTexture ); + SET_STATIC_PIXEL_SHADER_COMBO( DETAIL_BLEND_MODE, nDetailBlendMode ); + SET_STATIC_PIXEL_SHADER_COMBO( SEAMLESS_BASE, bSeamlessBase ); + SET_STATIC_PIXEL_SHADER_COMBO( SEAMLESS_DETAIL, bSeamlessDetail ); + SET_STATIC_PIXEL_SHADER_COMBO( DISTANCEALPHA, bDistanceAlpha ); + SET_STATIC_PIXEL_SHADER_COMBO( DISTANCEALPHAFROMDETAIL, bDistanceAlphaFromDetail ); + SET_STATIC_PIXEL_SHADER_COMBO( SOFT_MASK, bSoftMask ); + SET_STATIC_PIXEL_SHADER_COMBO( OUTLINE, bOutline ); + SET_STATIC_PIXEL_SHADER_COMBO( OUTER_GLOW, bGlow ); + SET_STATIC_PIXEL_SHADER_COMBO( BLENDTINTBYBASEALPHA, bBlendTintByBaseAlpha ); + SET_STATIC_PIXEL_SHADER( vertexlit_and_unlit_generic_ps20 ); + } + } +#ifndef _X360 + else + { + // The vertex shader uses the vertex id stream + SET_FLAGS2( MATERIAL_VAR2_USES_VERTEXID ); + + DECLARE_STATIC_VERTEX_SHADER( vertexlit_and_unlit_generic_vs30 ); + SET_STATIC_VERTEX_SHADER_COMBO( VERTEXCOLOR, bHasVertexColor || bHasVertexAlpha ); + SET_STATIC_VERTEX_SHADER_COMBO( CUBEMAP, bHasEnvmap ); + SET_STATIC_VERTEX_SHADER_COMBO( HALFLAMBERT, bHalfLambert ); + SET_STATIC_VERTEX_SHADER_COMBO( FLASHLIGHT, bHasFlashlight ); + SET_STATIC_VERTEX_SHADER_COMBO( SEAMLESS_BASE, bSeamlessBase ); + SET_STATIC_VERTEX_SHADER_COMBO( SEAMLESS_DETAIL, bSeamlessDetail ); + SET_STATIC_VERTEX_SHADER_COMBO( SEPARATE_DETAIL_UVS, IsBoolSet( info.m_nSeparateDetailUVs, params ) ); + SET_STATIC_VERTEX_SHADER_COMBO( DECAL, bIsDecal ); + SET_STATIC_VERTEX_SHADER_COMBO( DONT_GAMMA_CONVERT_VERTEX_COLOR, bSRGBWrite ? 0 : 1 ); + SET_STATIC_VERTEX_SHADER( vertexlit_and_unlit_generic_vs30 ); + + DECLARE_STATIC_PIXEL_SHADER( vertexlit_and_unlit_generic_ps30 ); + SET_STATIC_PIXEL_SHADER_COMBO( SELFILLUM_ENVMAPMASK_ALPHA, ( hasSelfIllumInEnvMapMask && ( bHasEnvmapMask ) ) ); + SET_STATIC_PIXEL_SHADER_COMBO( CUBEMAP, bHasEnvmap ); + SET_STATIC_PIXEL_SHADER_COMBO( CUBEMAP_SPHERE_LEGACY, bHasLegacyEnvSphereMap ); + SET_STATIC_PIXEL_SHADER_COMBO( DIFFUSELIGHTING, hasDiffuseLighting ); + SET_STATIC_PIXEL_SHADER_COMBO( ENVMAPMASK, bHasEnvmapMask ); + SET_STATIC_PIXEL_SHADER_COMBO( BASEALPHAENVMAPMASK, hasBaseAlphaEnvmapMask ); + SET_STATIC_PIXEL_SHADER_COMBO( SELFILLUM, bHasSelfIllum ); + SET_STATIC_PIXEL_SHADER_COMBO( VERTEXCOLOR, bHasVertexColor ); + SET_STATIC_PIXEL_SHADER_COMBO( FLASHLIGHT, bHasFlashlight ); + SET_STATIC_PIXEL_SHADER_COMBO( DETAILTEXTURE, bHasDetailTexture ); + SET_STATIC_PIXEL_SHADER_COMBO( DETAIL_BLEND_MODE, nDetailBlendMode ); + SET_STATIC_PIXEL_SHADER_COMBO( SEAMLESS_BASE, bSeamlessBase ); + SET_STATIC_PIXEL_SHADER_COMBO( SEAMLESS_DETAIL, bSeamlessDetail ); + SET_STATIC_PIXEL_SHADER_COMBO( DISTANCEALPHA, bDistanceAlpha ); + SET_STATIC_PIXEL_SHADER_COMBO( DISTANCEALPHAFROMDETAIL, bDistanceAlphaFromDetail ); + SET_STATIC_PIXEL_SHADER_COMBO( SOFT_MASK, bSoftMask ); + SET_STATIC_PIXEL_SHADER_COMBO( OUTLINE, bOutline ); + SET_STATIC_PIXEL_SHADER_COMBO( OUTER_GLOW, bGlow ); + SET_STATIC_PIXEL_SHADER_COMBO( FLASHLIGHTDEPTHFILTERMODE, nShadowFilterMode ); + SET_STATIC_PIXEL_SHADER_COMBO( DEPTHBLEND, bDoDepthBlend ); + SET_STATIC_PIXEL_SHADER_COMBO( BLENDTINTBYBASEALPHA, bBlendTintByBaseAlpha ); + SET_STATIC_PIXEL_SHADER( vertexlit_and_unlit_generic_ps30 ); + } +#endif + } + + if ( bHasFlashlight && !IsX360() ) + { + pShader->FogToBlack(); + } + else + { + pShader->DefaultFog(); + } + + // HACK HACK HACK - enable alpha writes all the time so that we have them for + // underwater stuff and the loadout and character select screens. + pShaderShadow->EnableAlphaWrites( bFullyOpaque ); + } + + if ( pShaderAPI && ( (! pContextData ) || ( pContextData->m_bMaterialVarsChanged ) ) ) + { +/*^*/ // printf("\t\t[3] pShaderAPI && ( (! pContextData ) || ( pContextData->m_bMaterialVarsChanged ) ) TRUE \n"); + if ( ! pContextData ) // make sure allocated + { + ++g_nSnapShots; + pContextData = new CVertexLitGeneric_DX9_Context; + *pContextDataPtr = pContextData; + } + pContextData->m_SemiStaticCmdsOut.Reset(); + pContextData->m_SemiStaticCmdsOut.SetPixelShaderFogParams( 21 ); + if ( bHasBaseTexture ) + { + pContextData->m_SemiStaticCmdsOut.BindTexture( pShader, SHADER_SAMPLER0, info.m_nBaseTexture, info.m_nBaseTextureFrame ); + } + else + { + if( bHasEnvmap ) + { + // if we only have an envmap (no basetexture), then we want the albedo to be black. + pContextData->m_SemiStaticCmdsOut.BindStandardTexture( SHADER_SAMPLER0, TEXTURE_BLACK ); + } + else + { + pContextData->m_SemiStaticCmdsOut.BindStandardTexture( SHADER_SAMPLER0, TEXTURE_WHITE ); + } + } + if ( bHasDetailTexture ) + { + pContextData->m_SemiStaticCmdsOut.BindTexture( pShader, SHADER_SAMPLER2, info.m_nDetail, info.m_nDetailFrame ); + } + if ( bHasSelfIllum ) + { + if ( bHasSelfIllumMask ) // Separate texture for self illum? + { + pContextData->m_SemiStaticCmdsOut.BindTexture( pShader, SHADER_SAMPLER11, info.m_nSelfIllumMask, -1 ); // Bind it + } + else // else + { + pContextData->m_SemiStaticCmdsOut.BindStandardTexture( SHADER_SAMPLER11, TEXTURE_BLACK ); // Bind dummy + } + } + + if ( (info.m_nDepthBlend != -1) && (params[info.m_nDepthBlend]->GetIntValue()) ) + { + pContextData->m_SemiStaticCmdsOut.BindStandardTexture( SHADER_SAMPLER10, TEXTURE_FRAME_BUFFER_FULL_DEPTH ); + } + if ( bSeamlessDetail || bSeamlessBase ) + { + float flSeamlessData[4]={ params[info.m_nSeamlessScale]->GetFloatValue(), + 0,0,0}; + pContextData->m_SemiStaticCmdsOut.SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_2, flSeamlessData ); + } + + if ( info.m_nBaseTextureTransform != -1 ) + { + pContextData->m_SemiStaticCmdsOut.SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, info.m_nBaseTextureTransform ); + } + + + if ( bHasDetailTexture ) + { + if ( IS_PARAM_DEFINED( info.m_nDetailTextureTransform ) ) + pContextData->m_SemiStaticCmdsOut.SetVertexShaderTextureScaledTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_4, info.m_nDetailTextureTransform, info.m_nDetailScale ); + else + pContextData->m_SemiStaticCmdsOut.SetVertexShaderTextureScaledTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_4, info.m_nBaseTextureTransform, info.m_nDetailScale ); + //Assert( !bHasBump ); + if ( info.m_nDetailTint != -1 ) + pContextData->m_SemiStaticCmdsOut.SetPixelShaderConstantGammaToLinear( 10, info.m_nDetailTint ); + else + { + pContextData->m_SemiStaticCmdsOut.SetPixelShaderConstant4( 10, 1, 1, 1, 1 ); + } + } + if ( bDistanceAlpha ) + { + float flSoftStart = GetFloatParam( info.m_nEdgeSoftnessStart, params ); + float flSoftEnd = GetFloatParam( info.m_nEdgeSoftnessEnd, params ); + // set all line art shader parms + bool bScaleEdges = IsBoolSet( info.m_nScaleEdgeSoftnessBasedOnScreenRes, params ); + bool bScaleOutline = IsBoolSet( info.m_nScaleOutlineSoftnessBasedOnScreenRes, params ); + + float flResScale = 1.0; + + float flOutlineStart0 = GetFloatParam( info.m_nOutlineStart0, params ); + float flOutlineStart1 = GetFloatParam( info.m_nOutlineStart1, params ); + float flOutlineEnd0 = GetFloatParam( info.m_nOutlineEnd0, params ); + float flOutlineEnd1 = GetFloatParam( info.m_nOutlineEnd1, params ); + + if ( bScaleEdges || bScaleOutline ) + { + int nWidth, nHeight; + pShaderAPI->GetBackBufferDimensions( nWidth, nHeight ); + flResScale=max( 0.5f, max( 1024.f/nWidth, 768.f/nHeight ) ); + + if ( bScaleEdges ) + { + float flMid = 0.5 * ( flSoftStart + flSoftEnd ); + flSoftStart = clamp( flMid + flResScale * ( flSoftStart - flMid ), 0.05, 0.99 ); + flSoftEnd = clamp( flMid + flResScale * ( flSoftEnd - flMid ), 0.05, 0.99 ); + } + + + if ( bScaleOutline ) + { + // shrink the soft part of the outline, enlarging hard part + float flMidS = 0.5 * ( flOutlineStart1 + flOutlineStart0 ); + flOutlineStart1 = clamp( flMidS + flResScale * ( flOutlineStart1 - flMidS ), 0.05, 0.99 ); + float flMidE = 0.5 * ( flOutlineEnd1 + flOutlineEnd0 ); + flOutlineEnd1 = clamp( flMidE + flResScale * ( flOutlineEnd1 - flMidE ), 0.05, 0.99 ); + } + + } + + float flConsts[]={ + // c5 - glow values + GetFloatParam( info.m_nGlowX, params ), + GetFloatParam( info.m_nGlowY, params ), + GetFloatParam( info.m_nGlowStart, params ), + GetFloatParam( info.m_nGlowEnd, params ), + // c6 - glow color + 0,0,0, // will be filled in + GetFloatParam( info.m_nGlowAlpha, params ), + // c7 - mask range parms + flSoftStart, + flSoftEnd, + 0,0, + // c8 - outline color + 0,0,0, + GetFloatParam( info.m_nOutlineAlpha, params ), + // c9 - outline parms. ordered for optimal ps20 .wzyx swizzling + flOutlineStart0, + flOutlineEnd1, + flOutlineEnd0, + flOutlineStart1, + }; + + if ( info.m_nGlowColor != -1 ) + { + params[info.m_nGlowColor]->GetVecValue( flConsts+4, 3 ); + } + if ( info.m_nOutlineColor != -1 ) + { + params[info.m_nOutlineColor]->GetVecValue( flConsts+12, 3 ); + } + pContextData->m_SemiStaticCmdsOut.SetPixelShaderConstant( 5, flConsts, 5 ); + + } + if ( !g_pConfig->m_bFastNoBump ) + { + if ( bHasBump ) + { + pContextData->m_SemiStaticCmdsOut.BindTexture( pShader, SHADER_SAMPLER3, info.m_nBumpmap, info.m_nBumpFrame ); + } + else if ( bHasDiffuseWarp ) + { + pContextData->m_SemiStaticCmdsOut.BindStandardTexture( SHADER_SAMPLER3, TEXTURE_NORMALMAP_FLAT ); + } + } + else + { + if ( bHasBump ) + { + pContextData->m_SemiStaticCmdsOut.BindStandardTexture( SHADER_SAMPLER3, TEXTURE_NORMALMAP_FLAT ); + } + } + // Setting w to 1 means use separate selfillummask + float vEnvMapSaturation_SelfIllumMask[4] = {1.0f, 1.0f, 1.0f, 0.0f}; + if ( info.m_nEnvmapSaturation != -1 ) + params[info.m_nEnvmapSaturation]->GetVecValue( vEnvMapSaturation_SelfIllumMask, 3 ); + + vEnvMapSaturation_SelfIllumMask[3] = bHasSelfIllumMask ? 1.0f : 0.0f; + pContextData->m_SemiStaticCmdsOut.SetPixelShaderConstant( 3, vEnvMapSaturation_SelfIllumMask, 1 ); + if ( bHasEnvmap ) + { + pContextData->m_SemiStaticCmdsOut.SetEnvMapTintPixelShaderDynamicStateGammaToLinear( 0, info.m_nEnvmapTint, fTintReplaceFactor ); + } + else + { + pContextData->m_SemiStaticCmdsOut.SetEnvMapTintPixelShaderDynamicStateGammaToLinear( 0, -1, fTintReplaceFactor); + } + + if ( bHasEnvmapMask ) + { + pContextData->m_SemiStaticCmdsOut.BindTexture( pShader, SHADER_SAMPLER4, info.m_nEnvmapMask, info.m_nEnvmapMaskFrame ); + } + + if ( bHasSelfIllumFresnel && (!bHasFlashlight || IsX360() ) ) + { + float vConstScaleBiasExp[4] = { 1.0f, 0.0f, 1.0f, 0.0f }; + float flMin = IS_PARAM_DEFINED( info.m_nSelfIllumFresnelMinMaxExp ) ? params[info.m_nSelfIllumFresnelMinMaxExp]->GetVecValue()[0] : 0.0f; + float flMax = IS_PARAM_DEFINED( info.m_nSelfIllumFresnelMinMaxExp ) ? params[info.m_nSelfIllumFresnelMinMaxExp]->GetVecValue()[1] : 1.0f; + float flExp = IS_PARAM_DEFINED( info.m_nSelfIllumFresnelMinMaxExp ) ? params[info.m_nSelfIllumFresnelMinMaxExp]->GetVecValue()[2] : 1.0f; + + vConstScaleBiasExp[1] = ( flMax != 0.0f ) ? ( flMin / flMax ) : 0.0f; // Bias + vConstScaleBiasExp[0] = 1.0f - vConstScaleBiasExp[1]; // Scale + vConstScaleBiasExp[2] = flExp; // Exp + vConstScaleBiasExp[3] = flMax; // Brightness + + pContextData->m_SemiStaticCmdsOut.SetPixelShaderConstant( 11, vConstScaleBiasExp ); + } + + if( bHasDiffuseWarp && (!bHasFlashlight || IsX360() ) && !bHasSelfIllumFresnel ) + { + if ( r_lightwarpidentity.GetBool() ) + { + pContextData->m_SemiStaticCmdsOut.BindStandardTexture( SHADER_SAMPLER9, TEXTURE_IDENTITY_LIGHTWARP ); + } + else + { + pContextData->m_SemiStaticCmdsOut.BindTexture( pShader, SHADER_SAMPLER9, info.m_nDiffuseWarpTexture, -1 ); + } + } + + if ( bHasFlashlight ) + { + // Tweaks associated with a given flashlight + VMatrix worldToTexture; + const FlashlightState_t &flashlightState = pShaderAPI->GetFlashlightState( worldToTexture ); + float tweaks[4]; + tweaks[0] = flashlightState.m_flShadowFilterSize / flashlightState.m_flShadowMapResolution; + tweaks[1] = ShadowAttenFromState( flashlightState ); + pShader->HashShadow2DJitter( flashlightState.m_flShadowJitterSeed, &tweaks[2], &tweaks[3] ); + pShaderAPI->SetPixelShaderConstant( 2, tweaks, 1 ); + + // Dimensions of screen, used for screen-space noise map sampling + float vScreenScale[4] = {1280.0f / 32.0f, 720.0f / 32.0f, 0, 0}; + int nWidth, nHeight; + pShaderAPI->GetBackBufferDimensions( nWidth, nHeight ); + vScreenScale[0] = (float) nWidth / 32.0f; + vScreenScale[1] = (float) nHeight / 32.0f; + pShaderAPI->SetPixelShaderConstant( 31, vScreenScale, 1 ); + } + + if ( ( !bHasFlashlight || IsX360() ) && ( info.m_nEnvmapContrast != -1 ) ) + pContextData->m_SemiStaticCmdsOut.SetPixelShaderConstant( 2, info.m_nEnvmapContrast ); + + // mat_fullbright 2 handling + bool bLightingOnly = bVertexLitGeneric && mat_fullbright.GetInt() == 2 && !IS_FLAG_SET( MATERIAL_VAR_NO_DEBUG_OVERRIDE ); + if( bLightingOnly ) + { + if ( bHasBaseTexture ) + { + if( ( bHasSelfIllum && !hasSelfIllumInEnvMapMask ) ) + { + pContextData->m_SemiStaticCmdsOut.BindStandardTexture( SHADER_SAMPLER0, TEXTURE_GREY_ALPHA_ZERO ); + } + else + { + pContextData->m_SemiStaticCmdsOut.BindStandardTexture( SHADER_SAMPLER0, TEXTURE_GREY ); + } + } + if ( bHasDetailTexture ) + { + pContextData->m_SemiStaticCmdsOut.BindStandardTexture( SHADER_SAMPLER2, TEXTURE_GREY ); + } + } + + if ( bHasBump || bHasDiffuseWarp ) + { + pContextData->m_SemiStaticCmdsOut.BindStandardTexture( SHADER_SAMPLER5, TEXTURE_NORMALIZATION_CUBEMAP_SIGNED ); + pContextData->m_SemiStaticCmdsOut.SetPixelShaderStateAmbientLightCube( 5 ); + pContextData->m_SemiStaticCmdsOut.CommitPixelShaderLighting( 13 ); + } + pContextData->m_SemiStaticCmdsOut.SetPixelShaderConstant_W( 4, info.m_nSelfIllumTint, fBlendFactor ); + pContextData->m_SemiStaticCmdsOut.SetAmbientCubeDynamicStateVertexShader(); + pContextData->m_SemiStaticCmdsOut.End(); + } + } + if ( pShaderAPI ) + { + CCommandBufferBuilder< CFixedCommandStorageBuffer< 1000 > > DynamicCmdsOut; + DynamicCmdsOut.Call( pContextData->m_SemiStaticCmdsOut.Base() ); + + if ( bHasEnvmap ) + { + DynamicCmdsOut.BindTexture( pShader, SHADER_SAMPLER1, info.m_nEnvmap, info.m_nEnvmapFrame ); + } + + bool bFlashlightShadows = false; + if ( bHasFlashlight ) + { + VMatrix worldToTexture; + ITexture *pFlashlightDepthTexture; + FlashlightState_t state = pShaderAPI->GetFlashlightStateEx( worldToTexture, &pFlashlightDepthTexture ); + bFlashlightShadows = state.m_bEnableShadows && ( pFlashlightDepthTexture != NULL ); + + if( pFlashlightDepthTexture && g_pConfig->ShadowDepthTexture() && state.m_bEnableShadows ) + { + pShader->BindTexture( SHADER_SAMPLER8, pFlashlightDepthTexture, 0 ); + DynamicCmdsOut.BindStandardTexture( SHADER_SAMPLER6, TEXTURE_SHADOW_NOISE_2D ); + } + + SetFlashLightColorFromState( state, pShaderAPI, 28, bFlashlightNoLambert ); + + Assert( info.m_nFlashlightTexture >= 0 && info.m_nFlashlightTextureFrame >= 0 ); + pShader->BindTexture( SHADER_SAMPLER7, state.m_pSpotlightTexture, state.m_nSpotlightTextureFrame ); + } + + + // Set up light combo state + LightState_t lightState = { 0, false, false, false }; + if ( bVertexLitGeneric && (!bHasFlashlight || IsX360() ) ) + { + pShaderAPI->GetDX9LightState( &lightState ); + } + + // Override the lighting desired if we have a lightmap set! + if ( bHasLightmapTexture ) + { + lightState.m_bStaticLightVertex = false; + lightState.m_bStaticLightTexel = true; + + // Usual case, not debugging. + if (!bHasMatLuxel) + { + pShader->BindTexture(SHADER_SAMPLER12, info.m_nLightmap); + } + else + { + float dimensions[] = { 0.0f, 0.0f, 0.0f, 0.0f }; + DynamicCmdsOut.BindStandardTexture( SHADER_SAMPLER12, TEXTURE_DEBUG_LUXELS ); + pShader->GetTextureDimensions( &dimensions[0], &dimensions[1], info.m_nLightmap ); + DynamicCmdsOut.SetPixelShaderConstant( 11, dimensions, 1 ); + } + } + + MaterialFogMode_t fogType = pShaderAPI->GetSceneFogMode(); + int fogIndex = ( fogType == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ) ? 1 : 0; + int numBones = pShaderAPI->GetCurrentNumBones(); + + bool bWriteDepthToAlpha; + bool bWriteWaterFogToAlpha; + if( bFullyOpaque ) + { + bWriteDepthToAlpha = pShaderAPI->ShouldWriteDepthToDestAlpha(); + bWriteWaterFogToAlpha = (fogType == MATERIAL_FOG_LINEAR_BELOW_FOG_Z); + AssertMsg( !(bWriteDepthToAlpha && bWriteWaterFogToAlpha), "Can't write two values to alpha at the same time." ); + } + else + { + //can't write a special value to dest alpha if we're actually using as-intended alpha + bWriteDepthToAlpha = false; + bWriteWaterFogToAlpha = false; + } + + if ( bHasBump || bHasDiffuseWarp ) + { +#ifndef _X360 + if ( !g_pHardwareConfig->HasFastVertexTextures() ) +#endif + { + bool bUseStaticControlFlow = g_pHardwareConfig->SupportsStaticControlFlow(); + + DECLARE_DYNAMIC_VERTEX_SHADER( vertexlit_and_unlit_generic_bump_vs20 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( DOWATERFOG, fogIndex ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, numBones > 0 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( NUM_LIGHTS, bUseStaticControlFlow ? 0 : lightState.m_nNumLights ); + SET_DYNAMIC_VERTEX_SHADER_CMD( DynamicCmdsOut, vertexlit_and_unlit_generic_bump_vs20 ); + + // Bind ps_2_b shader so we can get shadow mapping... + if ( g_pHardwareConfig->SupportsPixelShaders_2_b() || g_pHardwareConfig->ShouldAlwaysUseShaderModel2bShaders() ) // Always send GL this way + { + DECLARE_DYNAMIC_PIXEL_SHADER( vertexlit_and_unlit_generic_bump_ps20b ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( NUM_LIGHTS, lightState.m_nNumLights ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( AMBIENT_LIGHT, lightState.m_bAmbientLight ? 1 : 0 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( FLASHLIGHTSHADOWS, bFlashlightShadows ); +// SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + SET_DYNAMIC_PIXEL_SHADER_CMD( DynamicCmdsOut, vertexlit_and_unlit_generic_bump_ps20b ); + } + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( vertexlit_and_unlit_generic_bump_ps20 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( NUM_LIGHTS, lightState.m_nNumLights ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( AMBIENT_LIGHT, lightState.m_bAmbientLight ? 1 : 0 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( WRITEWATERFOGTODESTALPHA, bWriteWaterFogToAlpha ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + SET_DYNAMIC_PIXEL_SHADER_CMD( DynamicCmdsOut, vertexlit_and_unlit_generic_bump_ps20 ); + } + } +#ifndef _X360 + else + { + pShader->SetHWMorphVertexShaderState( VERTEX_SHADER_SHADER_SPECIFIC_CONST_10, VERTEX_SHADER_SHADER_SPECIFIC_CONST_11, SHADER_VERTEXTEXTURE_SAMPLER0 ); + + DECLARE_DYNAMIC_VERTEX_SHADER( vertexlit_and_unlit_generic_bump_vs30 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( DOWATERFOG, fogIndex ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, numBones > 0 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( MORPHING, pShaderAPI->IsHWMorphingEnabled() ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression ); + SET_DYNAMIC_VERTEX_SHADER( vertexlit_and_unlit_generic_bump_vs30 ); + + DECLARE_DYNAMIC_PIXEL_SHADER( vertexlit_and_unlit_generic_bump_ps30 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( NUM_LIGHTS, lightState.m_nNumLights ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( AMBIENT_LIGHT, lightState.m_bAmbientLight ? 1 : 0 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( FLASHLIGHTSHADOWS, bFlashlightShadows ); +// SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + SET_DYNAMIC_PIXEL_SHADER_CMD( DynamicCmdsOut, vertexlit_and_unlit_generic_bump_ps30 ); + + bool bUnusedTexCoords[3] = { false, false, !pShaderAPI->IsHWMorphingEnabled() || !bIsDecal }; + pShaderAPI->MarkUnusedVertexFields( 0, 3, bUnusedTexCoords ); + } +#endif + } + else // !( bHasBump || bHasDiffuseWarp ) + { + if ( bAmbientOnly ) // Override selected light combo to be ambient only + { + lightState.m_bAmbientLight = true; + lightState.m_bStaticLightVertex = false; + lightState.m_nNumLights = 0; + } + +#ifndef _X360 + if ( !g_pHardwareConfig->HasFastVertexTextures() ) +#endif + { + bool bUseStaticControlFlow = g_pHardwareConfig->SupportsStaticControlFlow(); + + DECLARE_DYNAMIC_VERTEX_SHADER( vertexlit_and_unlit_generic_vs20 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( DYNAMIC_LIGHT, lightState.HasDynamicLight() ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( STATIC_LIGHT_VERTEX, lightState.m_bStaticLightVertex ? 1 : 0 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( STATIC_LIGHT_LIGHTMAP, lightState.m_bStaticLightTexel ? 1 : 0); + SET_DYNAMIC_VERTEX_SHADER_COMBO( DOWATERFOG, fogIndex ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, numBones > 0 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( + LIGHTING_PREVIEW, + pShaderAPI->GetIntRenderingParameter(INT_RENDERPARM_ENABLE_FIXED_LIGHTING)!=0); + SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( NUM_LIGHTS, bUseStaticControlFlow ? 0 : lightState.m_nNumLights ); + SET_DYNAMIC_VERTEX_SHADER_CMD( DynamicCmdsOut, vertexlit_and_unlit_generic_vs20 ); + + // Bind ps_2_b shader so we can get shadow mapping + if ( g_pHardwareConfig->SupportsPixelShaders_2_b() || g_pHardwareConfig->ShouldAlwaysUseShaderModel2bShaders() ) // Always send GL this way + { + DECLARE_DYNAMIC_PIXEL_SHADER( vertexlit_and_unlit_generic_ps20b ); + +// SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( FLASHLIGHTSHADOWS, bFlashlightShadows ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( STATIC_LIGHT_LIGHTMAP, lightState.m_bStaticLightTexel ? 1 : 0 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( DEBUG_LUXELS, bHasMatLuxel ? 1 : 0 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( + LIGHTING_PREVIEW, + pShaderAPI->GetIntRenderingParameter(INT_RENDERPARM_ENABLE_FIXED_LIGHTING) ); + SET_DYNAMIC_PIXEL_SHADER_CMD( DynamicCmdsOut, vertexlit_and_unlit_generic_ps20b ); + } + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( vertexlit_and_unlit_generic_ps20 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( STATIC_LIGHT_LIGHTMAP, lightState.m_bStaticLightTexel ? 1 : 0 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( + LIGHTING_PREVIEW, + pShaderAPI->GetIntRenderingParameter(INT_RENDERPARM_ENABLE_FIXED_LIGHTING) ); + SET_DYNAMIC_PIXEL_SHADER_CMD( DynamicCmdsOut, vertexlit_and_unlit_generic_ps20 ); + } + } +#ifndef _X360 + else + { + pShader->SetHWMorphVertexShaderState( VERTEX_SHADER_SHADER_SPECIFIC_CONST_10, VERTEX_SHADER_SHADER_SPECIFIC_CONST_11, SHADER_VERTEXTEXTURE_SAMPLER0 ); + + DECLARE_DYNAMIC_VERTEX_SHADER( vertexlit_and_unlit_generic_vs30 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( DYNAMIC_LIGHT, lightState.HasDynamicLight() ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( STATIC_LIGHT_VERTEX, lightState.m_bStaticLightVertex ? 1 : 0 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( STATIC_LIGHT_LIGHTMAP, lightState.m_bStaticLightTexel ? 1 : 0 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( DOWATERFOG, fogIndex ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, numBones > 0 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( LIGHTING_PREVIEW, + pShaderAPI->GetIntRenderingParameter(INT_RENDERPARM_ENABLE_FIXED_LIGHTING)!=0); + SET_DYNAMIC_VERTEX_SHADER_COMBO( MORPHING, pShaderAPI->IsHWMorphingEnabled() ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression ); + SET_DYNAMIC_VERTEX_SHADER_CMD( DynamicCmdsOut, vertexlit_and_unlit_generic_vs30 ); + + DECLARE_DYNAMIC_PIXEL_SHADER( vertexlit_and_unlit_generic_ps30 ); +// SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( FLASHLIGHTSHADOWS, bFlashlightShadows ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( STATIC_LIGHT_LIGHTMAP, lightState.m_bStaticLightTexel ? 1 : 0 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( DEBUG_LUXELS, bHasMatLuxel ? 1 : 0 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( LIGHTING_PREVIEW, + pShaderAPI->GetIntRenderingParameter(INT_RENDERPARM_ENABLE_FIXED_LIGHTING) ); + SET_DYNAMIC_PIXEL_SHADER_CMD( DynamicCmdsOut, vertexlit_and_unlit_generic_ps30 ); + + bool bUnusedTexCoords[3] = { false, false, !pShaderAPI->IsHWMorphingEnabled() || !bIsDecal }; + pShaderAPI->MarkUnusedVertexFields( 0, 3, bUnusedTexCoords ); + } +#endif + } + + if ( ( info.m_nHDRColorScale != -1 ) && pShader->IsHDREnabled() ) + { + pShader->SetModulationPixelShaderDynamicState_LinearColorSpace_LinearScale( 1, params[info.m_nHDRColorScale]->GetFloatValue() ); + } + else + { + pShader->SetModulationPixelShaderDynamicState_LinearColorSpace( 1 ); + } + + float eyePos[4]; + pShaderAPI->GetWorldSpaceCameraPosition( eyePos ); + DynamicCmdsOut.SetPixelShaderConstant( 20, eyePos ); + + // Non-bump case does its own depth feathering work + if ( !bHasBump && !bHasDiffuseWarp ) + { + DynamicCmdsOut.SetDepthFeatheringPixelShaderConstant( 13, GetFloatParam( info.m_nDepthBlendScale, params, 50.0f ) ); + } + + float fPixelFogType = pShaderAPI->GetPixelFogCombo() == 1 ? 1 : 0; + float fWriteDepthToAlpha = bWriteDepthToAlpha && IsPC() ? 1 : 0; + float fWriteWaterFogToDestAlpha = (pShaderAPI->GetPixelFogCombo() == 1 && bWriteWaterFogToAlpha) ? 1 : 0; + float fVertexAlpha = bHasVertexAlpha ? 1 : 0; + + // Controls for lerp-style paths through shader code (bump and non-bump have use different register) + float vShaderControls[4] = { fPixelFogType, fWriteDepthToAlpha, fWriteWaterFogToDestAlpha, fVertexAlpha }; + DynamicCmdsOut.SetPixelShaderConstant( 12, vShaderControls, 1 ); + + // flashlightfixme: put this in common code. + if ( bHasFlashlight ) + { + VMatrix worldToTexture; + const FlashlightState_t &flashlightState = pShaderAPI->GetFlashlightState( worldToTexture ); + SetFlashLightColorFromState( flashlightState, pShaderAPI, 28, bFlashlightNoLambert ); + + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_6, worldToTexture.Base(), 4 ); + + pShader->BindTexture( SHADER_SAMPLER7, flashlightState.m_pSpotlightTexture, flashlightState.m_nSpotlightTextureFrame ); + + float atten_pos[8]; + atten_pos[0] = flashlightState.m_fConstantAtten; // Set the flashlight attenuation factors + atten_pos[1] = flashlightState.m_fLinearAtten; + atten_pos[2] = flashlightState.m_fQuadraticAtten; + atten_pos[3] = flashlightState.m_FarZ; + atten_pos[4] = flashlightState.m_vecLightOrigin[0]; // Set the flashlight origin + atten_pos[5] = flashlightState.m_vecLightOrigin[1]; + atten_pos[6] = flashlightState.m_vecLightOrigin[2]; + atten_pos[7] = 1.0f; + DynamicCmdsOut.SetPixelShaderConstant( 22, atten_pos, 2 ); + + DynamicCmdsOut.SetPixelShaderConstant( 24, worldToTexture.Base(), 4 ); + } + DynamicCmdsOut.End(); + pShaderAPI->ExecuteCommandBuffer( DynamicCmdsOut.Base() ); + } + pShader->Draw(); + +/*^*/ // printf("\t\tSupportsPixelShaders_2_b() && g_pConfig->UseBumpmapping() && g_pConfig->UsePhong() ) + { + DrawSkin_DX9( pShader, params, pShaderAPI, pShaderShadow, info, vertexCompression, pContextDataPtr ); + return; + } + + bool bReceiveFlashlight = bVertexLitGeneric; + bool bNewFlashlight = IsX360(); + if ( bNewFlashlight ) + { + bReceiveFlashlight = bReceiveFlashlight || ( GetIntParam( info.m_nReceiveFlashlight, params ) != 0 ); + } + bool bHasFlashlight = bReceiveFlashlight && pShader->UsingFlashlight( params ); + + DrawVertexLitGeneric_DX9_Internal( pShader, params, pShaderAPI, + pShaderShadow, bVertexLitGeneric, bHasFlashlight, info, vertexCompression, pContextDataPtr ); +} diff --git a/materialsystem/stdshaders/vertexlitgeneric_dx9_helper.h b/materialsystem/stdshaders/vertexlitgeneric_dx9_helper.h new file mode 100644 index 0000000..5820dbe --- /dev/null +++ b/materialsystem/stdshaders/vertexlitgeneric_dx9_helper.h @@ -0,0 +1,145 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//============================================================================= + +#ifndef VERTEXLITGENERIC_DX9_HELPER_H +#define VERTEXLITGENERIC_DX9_HELPER_H + +#include + + +//----------------------------------------------------------------------------- +// Forward declarations +//----------------------------------------------------------------------------- +class CBaseVSShader; +class IMaterialVar; +class IShaderDynamicAPI; +class IShaderShadow; + + +//----------------------------------------------------------------------------- +// Init params/ init/ draw methods +//----------------------------------------------------------------------------- +struct VertexLitGeneric_DX9_Vars_t +{ + VertexLitGeneric_DX9_Vars_t() { memset( this, 0xFF, sizeof(*this) ); } + + int m_nBaseTexture; + int m_nWrinkle; + int m_nStretch; + int m_nBaseTextureFrame; + int m_nBaseTextureTransform; + int m_nAlbedo; + int m_nDetail; + int m_nDetailFrame; + int m_nDetailScale; + int m_nEnvmap; + int m_nEnvmapFrame; + int m_nEnvmapMask; + int m_nEnvmapMaskFrame; + int m_nEnvmapMaskTransform; + int m_nEnvmapTint; + int m_nBumpmap; + int m_nNormalWrinkle; + int m_nNormalStretch; + int m_nBumpFrame; + int m_nBumpTransform; + int m_nEnvmapContrast; + int m_nEnvmapSaturation; + int m_nAlphaTestReference; + int m_nVertexAlphaTest; + int m_nFlashlightNoLambert; + int m_nFlashlightTexture; + int m_nFlashlightTextureFrame; + int m_nLightmap; + + int m_nSelfIllumTint; + int m_nSelfIllumFresnel; + int m_nSelfIllumFresnelMinMaxExp; + + int m_nPhongExponent; + int m_nPhongTint; + int m_nPhongAlbedoTint; + int m_nPhongExponentTexture; + int m_nDiffuseWarpTexture; + int m_nPhongWarpTexture; + int m_nPhongBoost; + int m_nPhongFresnelRanges; + int m_nPhongExponentFactor; + int m_nSelfIllumEnvMapMask_Alpha; + int m_nAmbientOnly; + int m_nHDRColorScale; + int m_nPhong; + int m_nBaseMapAlphaPhongMask; + int m_nEnvmapFresnel; + + int m_nDetailTextureCombineMode; + int m_nDetailTextureBlendFactor; + + // Rim lighting parameters + int m_nRimLight; + int m_nRimLightPower; + int m_nRimLightBoost; + int m_nRimMask; + + int m_nSeamlessScale; + int m_nSeamlessBase; + int m_nSeamlessDetail; + + // distance coded line art parameters + int m_nDistanceAlpha; + int m_nDistanceAlphaFromDetail; + + int m_nSoftEdges; + int m_nEdgeSoftnessStart; + int m_nEdgeSoftnessEnd; + int m_nScaleEdgeSoftnessBasedOnScreenRes; + + int m_nGlow; + int m_nGlowColor; + int m_nGlowAlpha; + int m_nGlowStart; + int m_nGlowEnd; + int m_nGlowX; + int m_nGlowY; + int m_nOutline; + int m_nOutlineColor; + int m_nOutlineAlpha; + int m_nOutlineStart0; + int m_nOutlineStart1; + int m_nOutlineEnd0; + int m_nOutlineEnd1; + int m_nScaleOutlineSoftnessBasedOnScreenRes; + + int m_nSeparateDetailUVs; + int m_nDetailTextureTransform; + + int m_nLinearWrite; + int m_nGammaColorRead; + + int m_nDetailTint; + int m_nInvertPhongMask; + + int m_nDepthBlend; + int m_nDepthBlendScale; + + int m_nSelfIllumMask; + int m_nReceiveFlashlight; + + int m_nBlendTintByBaseAlpha; + + int m_nTintReplacesBaseColor; +}; + +void InitParamsVertexLitGeneric_DX9( CBaseVSShader *pShader, IMaterialVar** params, const char *pMaterialName, bool bVertexLitGeneric, VertexLitGeneric_DX9_Vars_t &info ); +void InitVertexLitGeneric_DX9( CBaseVSShader *pShader, IMaterialVar** params, bool bVertexLitGeneric, VertexLitGeneric_DX9_Vars_t &info ); +void DrawVertexLitGeneric_DX9( CBaseVSShader *pShader, IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow, + bool bVertexLitGeneric, VertexLitGeneric_DX9_Vars_t &info, VertexCompressionType_t vertexCompression, + CBasePerMaterialContextData **pContextDataPtr + ); + + +#endif // VERTEXLITGENERIC_DX9_HELPER_H diff --git a/materialsystem/stdshaders/vertexlitgeneric_envmap.psh b/materialsystem/stdshaders/vertexlitgeneric_envmap.psh new file mode 100644 index 0000000..019f8c0 --- /dev/null +++ b/materialsystem/stdshaders/vertexlitgeneric_envmap.psh @@ -0,0 +1,17 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; Draw a texture . . woo hoo! +; t0 - texture +; +; The texture coordinates need to be defined as follows: +; tc0 - texcoords +;------------------------------------------------------------------------------ + +tex t0 ; base color +tex t1 ; cube map + +mul r0, t0, c3 ; base times modulation +mad r0.rgb, t1, c2, r0 ; + envmap * envmaptint (color only) +mul r0.rgb, v0, r0 ; apply vertex lighting +mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2) diff --git a/materialsystem/stdshaders/vertexlitgeneric_flashlight_vs11.vsh b/materialsystem/stdshaders/vertexlitgeneric_flashlight_vs11.vsh new file mode 100644 index 0000000..a5810b5 --- /dev/null +++ b/materialsystem/stdshaders/vertexlitgeneric_flashlight_vs11.vsh @@ -0,0 +1,137 @@ +vs.1.1 + +# DYNAMIC: "DOWATERFOG" "0..1" +# DYNAMIC: "SKINNING" "0..1" +# STATIC: "TEETH" "0..1" + +#include "macros.vsh" + +local( $worldPos, $worldNormal, $projPos ); + +alloc $worldPos +alloc $worldNormal +alloc $projPos + +if( 0 ) +{ + ; NOTE: Don't do this optimization anymore since it would mean a gazillion combos + ; Special case for static prop lighting. We can go directly from + ; world to proj space for position, with the exception of z, which + ; is needed for fogging *if* height fog is enabled. + + ; NOTE: We don't use this path if $envmap is defined since we need + ; worldpos for envmapping. + dp4 $projPos.x, $vPos, $cModelViewProj0 + dp4 $projPos.y, $vPos, $cModelViewProj1 + dp4 $projPos.z, $vPos, $cModelViewProj2 + dp4 $projPos.w, $vPos, $cModelViewProj3 + ; normal + dp3 $worldNormal.x, $vNormal, $cModel0 + dp3 $worldNormal.y, $vNormal, $cModel1 + dp3 $worldNormal.z, $vNormal, $cModel2 + + ; Need this for height fog if it's enabled and for height clipping + dp4 $worldPos.z, $vPos, $cModel2 +} +else +{ + &SkinPositionAndNormal( $worldPos, $worldNormal ); + + if( $SKINNING == 1 ) + { + &Normalize( $worldNormal ); + } + + ;------------------------------------------------------------------------------ + ; Transform the position from world to view space + ;------------------------------------------------------------------------------ + dp4 $projPos.x, $worldPos, $cViewProj0 + dp4 $projPos.y, $worldPos, $cViewProj1 + dp4 $projPos.z, $worldPos, $cViewProj2 + dp4 $projPos.w, $worldPos, $cViewProj3 +} + +mov oPos, $projPos + +;------------------------------------------------------------------------------ +; Fog +;------------------------------------------------------------------------------ +&CalcFog( $worldPos, $projPos ); + +; base tex coords +dp4 oT1.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_6 +dp4 oT1.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_7 + +; normal map coords +;dp4 oT3.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_8 +;dp4 oT3.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_9 + +; spotlight texcoords +dp4 oT0.x, $worldPos, $SHADER_SPECIFIC_CONST_1 +dp4 oT0.y, $worldPos, $SHADER_SPECIFIC_CONST_2 +dp4 oT0.z, $worldPos, $SHADER_SPECIFIC_CONST_3 +dp4 oT0.w, $worldPos, $SHADER_SPECIFIC_CONST_4 + +local( $worldPosToLightVector, $distFactors ); + +alloc $worldPosToLightVector + +sub $worldPosToLightVector, $SHADER_SPECIFIC_CONST_0, $worldPos +mov oT2, $worldPosToLightVector + +local( $distatten ); +alloc $distatten +; $distatten = [ 1, 1/dist, 1/distsquared ] + +; dist squared +dp3 $distatten.z, $worldPosToLightVector, $worldPosToLightVector + +; oodist +rsq $distatten.y, $distatten.z + +mov $distatten.x, $cOne + +local( $dist ); +alloc $dist +mul $dist.x, $distatten.z, $distatten.y + +rcp $distatten.z, $distatten.z ; 1/distsquared + +local( $endFalloffFactor ); +alloc $endFalloffFactor + +; ( dist - farZ ) +sub $endFalloffFactor.x, $dist.x, $SHADER_SPECIFIC_CONST_5.w +; 1 / ( (0.6f * farZ) - farZ) +mul $endFalloffFactor, $endFalloffFactor.x, $SHADER_SPECIFIC_CONST_0.w +max $endFalloffFactor, $endFalloffFactor, $cZero +min $endFalloffFactor, $endFalloffFactor, $cOne + +local( $vertAtten ); +alloc $vertAtten +dp3 $vertAtten, $distatten, $SHADER_SPECIFIC_CONST_5 +mul $vertAtten, $vertAtten, $endFalloffFactor + +if( $TEETH ) +{ + alloc $mouthAtten + dp3 $mouthAtten, $worldNormal.xyz, $SHADER_SPECIFIC_CONST_10.xyz + max $mouthAtten, $cZero, $mouthAtten + mul $mouthAtten, $mouthAtten, $SHADER_SPECIFIC_CONST_10.w + mul $vertAtten, $vertAtten, $mouthAtten + free $mouthAtten +} + +mov oD0, $vertAtten + +mov oT3.xyz, $worldNormal.xyz + + +free $dist +free $endFalloffFactor +free $worldPos +free $worldNormal +free $projPos +free $worldPosToLightVector +free $distatten +free $vertAtten diff --git a/materialsystem/stdshaders/vertexlitgeneric_inc.vsh b/materialsystem/stdshaders/vertexlitgeneric_inc.vsh new file mode 100644 index 0000000..da6b6bf --- /dev/null +++ b/materialsystem/stdshaders/vertexlitgeneric_inc.vsh @@ -0,0 +1,145 @@ +#include "macros.vsh" + +sub VertexLitGeneric +{ + local( $detail ) = shift; + local( $envmap ) = shift; + local( $envmapcameraspace ) = shift; + local( $envmapsphere ) = shift; + local( $decal ) = shift; + + local( $worldPos, $worldNormal, $projPos ); + local( $reflectionVector ); + + ;------------------------------------------------------------------------------ + ; Vertex blending + ;------------------------------------------------------------------------------ + &AllocateRegister( \$worldPos ); + &AllocateRegister( \$worldNormal ); + &AllocateRegister( \$projPos ); +; if( $g_staticLightType eq "static" && $g_ambientLightType eq "none" && +; $g_localLightType1 eq "none" && $g_localLightType2 eq "none" && !$envmap ) + if( 0 ) + { + ; NOTE: Don't do this optimization anymore since it would mean a gazillion combos + ; of the flashlight shaders + ; Special case for static prop lighting. We can go directly from + ; world to proj space for position, with the exception of z, which + ; is needed for fogging *if* height fog is enabled. + + ; NOTE: We don't use this path if $envmap is defined since we need + ; worldpos for envmapping. + dp4 $projPos.x, $vPos, $cModelViewProj0 + dp4 $projPos.y, $vPos, $cModelViewProj1 + dp4 $projPos.z, $vPos, $cModelViewProj2 + dp4 $projPos.w, $vPos, $cModelViewProj3 + ; normal + dp3 $worldNormal.x, $vNormal, $cModel0 + dp3 $worldNormal.y, $vNormal, $cModel1 + dp3 $worldNormal.z, $vNormal, $cModel2 + + ; Need this for height fog if it's enabled and for height clipping + dp4 $worldPos.z, $vPos, $cModel2 + } + else + { + &SkinPositionAndNormal( $worldPos, $worldNormal ); + + if( $SKINNING == 1 ) + { + &Normalize( $worldNormal ); + } + + ;------------------------------------------------------------------------------ + ; Transform the position from world to view space + ;------------------------------------------------------------------------------ + dp4 $projPos.x, $worldPos, $cViewProj0 + dp4 $projPos.y, $worldPos, $cViewProj1 + dp4 $projPos.z, $worldPos, $cViewProj2 + dp4 $projPos.w, $worldPos, $cViewProj3 + } + + mov oPos, $projPos + + ;------------------------------------------------------------------------------ + ; Fog + ;------------------------------------------------------------------------------ + &CalcFog( $worldPos, $projPos ); + &FreeRegister( \$projPos ); + + ;------------------------------------------------------------------------------ + ; Lighting + ;------------------------------------------------------------------------------ + &DoLighting( $worldPos, $worldNormal ); + + if( !$envmap ) + { + &FreeRegister( \$worldNormal ); + } + + ;------------------------------------------------------------------------------ + ; Texture coordinates + ;------------------------------------------------------------------------------ + + dp4 oT0.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_0 + dp4 oT0.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_1 + + if( $envmap ) + { + if( $envmapcameraspace ) + { + &AllocateRegister( \$reflectionVector ); + &ComputeReflectionVector( $worldPos, $worldNormal, $reflectionVector ); + + ; transform reflection vector into view space + dp3 oT1.x, $reflectionVector, $cViewModel0 + dp3 oT1.y, $reflectionVector, $cViewModel1 + dp3 oT1.z, $reflectionVector, $cViewModel2 + + &FreeRegister( \$reflectionVector ); + } + elsif( $envmapsphere ) + { + &AllocateRegister( \$reflectionVector ); + &ComputeReflectionVector( $worldPos, $worldNormal, $reflectionVector ); + &ComputeSphereMapTexCoords( $reflectionVector, "oT1" ); + + &FreeRegister( \$reflectionVector ); + } + else + { + &ComputeReflectionVector( $worldPos, $worldNormal, "oT1" ); + } + + ; envmap mask + dp4 oT2.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_2 + dp4 oT2.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_3 + + &FreeRegister( \$worldNormal ); + } + else + { + if ( $decal ) + { + &AllocateRegister( \$temp ); + mov $temp, $vTexCoord0 + sub oT1.xyz, $temp.xyz, $vTexCoord1.xyz + sub oT2.xyz, $vTexCoord2.xyz, $temp.xyz + &FreeRegister( \$temp ); + } + else + { + ; YUCK! This is to make texcoords continuous for mat_softwaretl + mov oT1, $cZero + mov oT2, $cZero + } + } + + if( $detail ) + { + dp4 oT3.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_4 + dp4 oT3.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_5 + } + &FreeRegister( \$worldPos ); +} + diff --git a/materialsystem/stdshaders/vertexlitgeneric_lightingonly_overbright2.psh b/materialsystem/stdshaders/vertexlitgeneric_lightingonly_overbright2.psh new file mode 100644 index 0000000..722e141 --- /dev/null +++ b/materialsystem/stdshaders/vertexlitgeneric_lightingonly_overbright2.psh @@ -0,0 +1,5 @@ +ps.1.1 + +mov r0, v0 + + diff --git a/materialsystem/stdshaders/vertexlitgeneric_lightingonly_overbright2_ps11.fxc b/materialsystem/stdshaders/vertexlitgeneric_lightingonly_overbright2_ps11.fxc new file mode 100644 index 0000000..70ad709 --- /dev/null +++ b/materialsystem/stdshaders/vertexlitgeneric_lightingonly_overbright2_ps11.fxc @@ -0,0 +1,9 @@ +struct PS_INPUT +{ + float3 vColor0 : COLOR0; +}; + +float4 main( PS_INPUT i ) : COLOR +{ + return float4( i.vColor0, 1.0 ); +} diff --git a/materialsystem/stdshaders/vertexlitgeneric_maskedenvmap.psh b/materialsystem/stdshaders/vertexlitgeneric_maskedenvmap.psh new file mode 100644 index 0000000..afee48a --- /dev/null +++ b/materialsystem/stdshaders/vertexlitgeneric_maskedenvmap.psh @@ -0,0 +1,19 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; Draw a texture . . woo hoo! +; t0 - texture +; +; The texture coordinates need to be defined as follows: +; tc0 - texcoords +;------------------------------------------------------------------------------ + +tex t0 ; base color +tex t1 ; cube map +tex t2 ; envmap mask + +mul r0, t0, c3 ; Base times modulation +mul r1, t1, t2 ; Envmap * mask +mad r0.rgb, r1, c2, r0 ; Base * mod + envmap * mask * tint +mul r0.rgb, v0, r0 ; apply vertex lighting +mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2) diff --git a/materialsystem/stdshaders/vertexlitgeneric_selfilluminatedenvmap.psh b/materialsystem/stdshaders/vertexlitgeneric_selfilluminatedenvmap.psh new file mode 100644 index 0000000..4b47919 --- /dev/null +++ b/materialsystem/stdshaders/vertexlitgeneric_selfilluminatedenvmap.psh @@ -0,0 +1,25 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; Draw a texture . . woo hoo! +; t0 - texture +; +; The texture coordinates need to be defined as follows: +; tc0 - texcoords +;------------------------------------------------------------------------------ + +; Get the color from the texture +tex t0 +tex t1 + +mul r0.rgb, t0, c3 + ; base times modulation +mov r0.a, c3.a ; use modulation alpha (don't use texture alpha) + +mad r0.rgb, t1, c2, r0 ; + envmap * envmaptint (color only) + +mul r0.rgb, v0, r0 ; Apply lighting +mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2) + +mul r1, t0, c1 ; Self illum * tint +lrp r0.rgb, t0.a, r1, r0 ; Blend between self-illum + base * lighting + diff --git a/materialsystem/stdshaders/vertexlitgeneric_selfilluminatedmaskedenvmap.psh b/materialsystem/stdshaders/vertexlitgeneric_selfilluminatedmaskedenvmap.psh new file mode 100644 index 0000000..38c80e4 --- /dev/null +++ b/materialsystem/stdshaders/vertexlitgeneric_selfilluminatedmaskedenvmap.psh @@ -0,0 +1,26 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; Draw a texture . . woo hoo! +; t0 - texture +; +; The texture coordinates need to be defined as follows: +; tc0 - texcoords +;------------------------------------------------------------------------------ + +; Get the color from the texture +tex t0 ; base +tex t1 ; env map +tex t2 ; mask + +mul r0.rgb, t0, c3 + ; base times modulation +mul r0.a, c3.a, t2.a ; alpha = mod alpha * mask alpha + +mul r1, t2, t1 ; envmapmask * envmap +mad r0.rgb, r1, c2, r0 ; + envmapmask * envmap * envmaptint (color only) + +mul r0.rgb, v0, r0 ; Apply lighting +mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2) + +mul r1, t0, c1 ; Self illum * tint +lrp r0.rgb, t0.a, r1, r0 ; Blend between self-illum + base * lighting diff --git a/materialsystem/stdshaders/vertexlitgeneric_vs11.vsh b/materialsystem/stdshaders/vertexlitgeneric_vs11.vsh new file mode 100644 index 0000000..c0ab276 --- /dev/null +++ b/materialsystem/stdshaders/vertexlitgeneric_vs11.vsh @@ -0,0 +1,22 @@ +vs.1.1 + +# STATIC: "HALF_LAMBERT" "0..1" +# STATIC: "ENVMAP" "0..1" +# STATIC: "ENVMAPCAMERASPACE" "0..0" +# STATIC: "ENVMAPSPHERE" "0..1" +# DYNAMIC: "DOWATERFOG" "0..1" +# DYNAMIC: "LIGHT_COMBO" "0..21" +# DYNAMIC: "SKINNING" "0..1" + +# can't have envmapshere or envmapcameraspace without envmap +# SKIP: !$ENVMAP && ( $ENVMAPSPHERE || $ENVMAPCAMERASPACE ) + +# can't have both envmapsphere and envmapcameraspace +# SKIP: $ENVMAPSPHERE && $ENVMAPCAMERASPACE + +# decal is by itself +# SKIP: $DECAL && ( $DETAIL || $ENVMAP || $ENVMAPCAMERASPACE || $ENVMAPSPHERE ) + +#include "VertexLitGeneric_inc.vsh" + +&VertexLitGeneric( 1, $ENVMAP, $ENVMAPCAMERASPACE, $ENVMAPSPHERE, 0 ); diff --git a/materialsystem/stdshaders/viewalpha.cpp b/materialsystem/stdshaders/viewalpha.cpp new file mode 100644 index 0000000..4ee2c71 --- /dev/null +++ b/materialsystem/stdshaders/viewalpha.cpp @@ -0,0 +1,48 @@ +//========= 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_FLAGS( ViewAlpha, "Help for ViewAlpha", SHADER_NOT_EDITABLE ) + + BEGIN_SHADER_PARAMS + END_SHADER_PARAMS + + SHADER_INIT + { + LoadTexture( BASETEXTURE ); + } + + SHADER_DRAW + { + SHADOW_STATE + { + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableCustomPixelPipe( true ); + pShaderShadow->CustomTextureStages( 1 ); + pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE0, + SHADER_TEXCHANNEL_COLOR, SHADER_TEXOP_SELECTARG1, + SHADER_TEXARG_TEXTUREALPHA, SHADER_TEXARG_CONSTANTCOLOR ); + pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE0, + SHADER_TEXCHANNEL_ALPHA, SHADER_TEXOP_SELECTARG1, + SHADER_TEXARG_TEXTURE, SHADER_TEXARG_VERTEXCOLOR ); + + pShaderShadow->DrawFlags( SHADER_DRAW_POSITION | SHADER_DRAW_TEXCOORD0 ); + } + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME ); + SetFixedFunctionTextureTransform( MATERIAL_TEXTURE0, BASETEXTURETRANSFORM ); + } + Draw( ); + + } +END_SHADER diff --git a/materialsystem/stdshaders/volume_clouds.cpp b/materialsystem/stdshaders/volume_clouds.cpp new file mode 100644 index 0000000..1421dbb --- /dev/null +++ b/materialsystem/stdshaders/volume_clouds.cpp @@ -0,0 +1,59 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// + +#include "BaseVSShader.h" +#include "volume_clouds_helper.h" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +DEFINE_FALLBACK_SHADER( VolumeClouds, VolumeClouds_dx9 ) +BEGIN_VS_SHADER( VolumeClouds_dx9, "VolumeClouds" ) + BEGIN_SHADER_PARAMS + SHADER_PARAM( REFRACTAMOUNT, SHADER_PARAM_TYPE_FLOAT, "2", "" ) + SHADER_PARAM( BASETEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "Texture 1" ) + SHADER_PARAM( BASETEXTURE2, SHADER_PARAM_TYPE_TEXTURE, "", "Texture 2" ) + SHADER_PARAM( BASETEXTURE3, SHADER_PARAM_TYPE_TEXTURE, "", "Texture 3" ) + SHADER_PARAM( TIME, SHADER_PARAM_TYPE_FLOAT, "0.0", "Needs CurrentTime Proxy" ) + END_SHADER_PARAMS + + void SetupVarsVolumeClouds( VolumeCloudsVars_t &info ) + { + info.m_nRefractAmount = REFRACTAMOUNT; + info.m_nTexture1 = BASETEXTURE; + info.m_nTexture2 = BASETEXTURE2; + info.m_nTexture3 = BASETEXTURE3; + info.m_nTime = TIME; + } + + SHADER_INIT_PARAMS() + { + VolumeCloudsVars_t info; + SetupVarsVolumeClouds( info ); + InitParamsVolumeClouds( this, params, pMaterialName, info ); + } + + SHADER_FALLBACK + { + if ( g_pHardwareConfig->GetDXSupportLevel() < 90 ) + { + // Fallback to unlit generic + return "UnlitGeneric_DX8"; + } + + return 0; + } + + SHADER_INIT + { + VolumeCloudsVars_t info; + SetupVarsVolumeClouds( info ); + InitVolumeClouds( this, params, info ); + } + + SHADER_DRAW + { + VolumeCloudsVars_t info; + SetupVarsVolumeClouds( info ); + DrawVolumeClouds( this, params, pShaderAPI, pShaderShadow, info, vertexCompression ); + } +END_SHADER diff --git a/materialsystem/stdshaders/volume_clouds_helper.cpp b/materialsystem/stdshaders/volume_clouds_helper.cpp new file mode 100644 index 0000000..cd2e889 --- /dev/null +++ b/materialsystem/stdshaders/volume_clouds_helper.cpp @@ -0,0 +1,138 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// + +#include "BaseVSShader.h" +#include "mathlib/vmatrix.h" +#include "volume_clouds_helper.h" +#include "convar.h" + +// Auto generated inc files +#include "volume_clouds_vs20.inc" +#include "volume_clouds_ps20.inc" +#include "volume_clouds_ps20b.inc" + + +void InitParamsVolumeClouds( CBaseVSShader *pShader, IMaterialVar** params, const char *pMaterialName, VolumeCloudsVars_t &info ) +{ + // Set material flags + SET_FLAGS2( MATERIAL_VAR2_SUPPORTS_HW_SKINNING ); + SET_FLAGS2( MATERIAL_VAR2_NEEDS_TANGENT_SPACES ); + SET_FLAGS( MATERIAL_VAR_TRANSLUCENT ); + SET_PARAM_FLOAT_IF_NOT_DEFINED( info.m_nTime, 0.0f ); + + // Set material parameter default values + SET_PARAM_FLOAT_IF_NOT_DEFINED( info.m_nRefractAmount, kDefaultRefractAmount ); +} + +void InitVolumeClouds( CBaseVSShader *pShader, IMaterialVar** params, VolumeCloudsVars_t &info ) +{ + // Load textures + if ( (info.m_nTexture1 != -1) && params[info.m_nTexture1]->IsDefined() ) + { + pShader->LoadTexture( info.m_nTexture1, TEXTUREFLAGS_SRGB ); + } + + if ( (info.m_nTexture2 != -1) && params[info.m_nTexture2]->IsDefined() ) + { + pShader->LoadTexture( info.m_nTexture2, TEXTUREFLAGS_SRGB ); + } + + if ( (info.m_nTexture3 != -1) && params[info.m_nTexture3]->IsDefined() ) + { + pShader->LoadTexture( info.m_nTexture3, TEXTUREFLAGS_SRGB ); + } +} + +void DrawVolumeClouds( CBaseVSShader *pShader, IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, + IShaderShadow* pShaderShadow, VolumeCloudsVars_t &info, VertexCompressionType_t vertexCompression ) +{ + SHADOW_STATE + { + // Set stream format (note that this shader supports compression) + unsigned int flags = VERTEX_POSITION | VERTEX_NORMAL | VERTEX_FORMAT_COMPRESSED; + int nTexCoordCount = 1; + int userDataSize = 0; + pShaderShadow->VertexShaderVertexFormat( flags, nTexCoordCount, NULL, userDataSize ); + + // Vertex Shader + DECLARE_STATIC_VERTEX_SHADER( volume_clouds_vs20 ); + SET_STATIC_VERTEX_SHADER( volume_clouds_vs20 ); + + // Pixel Shader + if( g_pHardwareConfig->SupportsPixelShaders_2_b() && !IsOpenGL() ) // Always send POSIX down the 20 path (rg - why?) + { + DECLARE_STATIC_PIXEL_SHADER( volume_clouds_ps20b ); + SET_STATIC_PIXEL_SHADER( volume_clouds_ps20b ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( volume_clouds_ps20 ); + SET_STATIC_PIXEL_SHADER( volume_clouds_ps20 ); + } + + // Textures + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER1, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER2, true ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER2, true ); + pShaderShadow->EnableSRGBWrite( true ); + + // Blending + pShader->EnableAlphaBlending( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA ); + pShaderShadow->EnableAlphaWrites( false ); + + // !!! We need to turn this back on because EnableAlphaBlending() above disables it! + //pShaderShadow->EnableDepthWrites( true ); + } + DYNAMIC_STATE + { + // Set Vertex Shader Combos + DECLARE_DYNAMIC_VERTEX_SHADER( volume_clouds_vs20 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, pShaderAPI->GetCurrentNumBones() > 0 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression ); + SET_DYNAMIC_VERTEX_SHADER( volume_clouds_vs20 ); + + // Set Vertex Shader Constants + + // Time + float vPackedVsConst1[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; + float flTime = IS_PARAM_DEFINED( info.m_nTime ) && params[info.m_nTime]->GetFloatValue() > 0.0f ? params[info.m_nTime]->GetFloatValue() : pShaderAPI->CurrentTime(); + float flRotateSpeed = 0.065f; + vPackedVsConst1[0] = flTime * flRotateSpeed * 1.0f; + vPackedVsConst1[1] = flTime * flRotateSpeed * 2.0f; + vPackedVsConst1[2] = flTime * flRotateSpeed * 4.0f; + vPackedVsConst1[0] -= (float)( (int)( vPackedVsConst1[0] / ( 2.0f * 3.14159f ) ) ) * 2.0f * 3.14159f; + vPackedVsConst1[1] -= (float)( (int)( vPackedVsConst1[1] / ( 2.0f * 3.14159f ) ) ) * 2.0f * 3.14159f; + vPackedVsConst1[2] -= (float)( (int)( vPackedVsConst1[2] / ( 2.0f * 3.14159f ) ) ) * 2.0f * 3.14159f; + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, vPackedVsConst1, 1 ); + + // Set Pixel Shader Combos + if ( g_pHardwareConfig->SupportsPixelShaders_2_b() && !IsOpenGL() ) // Always send POSIX down the 20 path (rg - why?) + { + DECLARE_DYNAMIC_PIXEL_SHADER( volume_clouds_ps20b ); + SET_DYNAMIC_PIXEL_SHADER( volume_clouds_ps20b ); + } + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( volume_clouds_ps20 ); + SET_DYNAMIC_PIXEL_SHADER( volume_clouds_ps20 ); + } + + // Bind textures + pShader->BindTexture( SHADER_SAMPLER0, info.m_nTexture1 ); + pShader->BindTexture( SHADER_SAMPLER1, info.m_nTexture2 ); + pShader->BindTexture( SHADER_SAMPLER2, info.m_nTexture3 ); + + // Set Pixel Shader Constants + float vEyePos[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; + pShaderAPI->GetWorldSpaceCameraPosition( vEyePos ); + pShaderAPI->SetPixelShaderConstant( 5, vEyePos, 1 ); + + float vPackedConst6[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; + vPackedConst6[0] = IS_PARAM_DEFINED( info.m_nRefractAmount ) ? params[info.m_nRefractAmount]->GetFloatValue() : kDefaultRefractAmount; + vPackedConst6[1] = vPackedVsConst1[0]; // Time % 1000 + pShaderAPI->SetPixelShaderConstant( 6, vPackedConst6, 1 ); + } + pShader->Draw(); +} diff --git a/materialsystem/stdshaders/volume_clouds_helper.h b/materialsystem/stdshaders/volume_clouds_helper.h new file mode 100644 index 0000000..abbb63b --- /dev/null +++ b/materialsystem/stdshaders/volume_clouds_helper.h @@ -0,0 +1,41 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// + +#ifndef VOLUME_CLOUDS_HELPER_H +#define VOLUME_CLOUDS_HELPER_H +#ifdef _WIN32 +#pragma once +#endif + +#include + +//----------------------------------------------------------------------------- +// Forward declarations +//----------------------------------------------------------------------------- +class CBaseVSShader; +class IMaterialVar; +class IShaderDynamicAPI; +class IShaderShadow; + +//----------------------------------------------------------------------------- +// Init params/ init/ draw methods +//----------------------------------------------------------------------------- +struct VolumeCloudsVars_t +{ + VolumeCloudsVars_t() { memset( this, 0xFF, sizeof( VolumeCloudsVars_t ) ); } + + int m_nRefractAmount; + int m_nTexture1; + int m_nTexture2; + int m_nTexture3; + int m_nTime; +}; + +// Default values (Arrays should only be vec[4]) +static const float kDefaultRefractAmount = 0.1f; + +void InitParamsVolumeClouds( CBaseVSShader *pShader, IMaterialVar** params, const char *pMaterialName, VolumeCloudsVars_t &info ); +void InitVolumeClouds( CBaseVSShader *pShader, IMaterialVar** params, VolumeCloudsVars_t &info ); +void DrawVolumeClouds( CBaseVSShader *pShader, IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, + IShaderShadow* pShaderShadow, VolumeCloudsVars_t &info, VertexCompressionType_t vertexCompression ); + +#endif // VolumeClouds_HELPER_H diff --git a/materialsystem/stdshaders/volume_clouds_ps2x.fxc b/materialsystem/stdshaders/volume_clouds_ps2x.fxc new file mode 100644 index 0000000..7435f30 --- /dev/null +++ b/materialsystem/stdshaders/volume_clouds_ps2x.fxc @@ -0,0 +1,66 @@ +//========= Copyright © 1996-2006, Valve Corporation, All rights reserved. ============// + +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX] + +// Includes ======================================================================================= +#include "common_vertexlitgeneric_dx9.h" + +// Texture Samplers =============================================================================== +sampler g_tInnerSampler : register( s0 ); +sampler g_tMiddleSampler : register( s1 ); +sampler g_tOuterSampler : register( s2 ); + +// Shaders Constants and Globals ================================================================== +//const float4 g_vPackedConst6 : register( c6 ); +//#define g_flTime g_vPackedConst6.w + +// Interpolated values ============================================================================ +struct PS_INPUT +{ + float4 v2DTangentViewVector01 : TEXCOORD0; + float4 vUv01 : TEXCOORD1; + float4 v2DTangentViewVector2_vUv2 : TEXCOORD2; +}; + +// Main =========================================================================================== +float4 main( PS_INPUT i ) : COLOR +{ + float4 vFinalColor = float4( 0.0f, 0.0f, 0.0f, 1.0f ); + +#if defined(SHADER_MODEL_PS_2_0) + float flNumLayers = 2.0f; +#else + float flNumLayers = 10.0f; +#endif + + //float flColorDim = 1.0f; + for ( float j=flNumLayers-1.0f; j>=0.0f; j-=1.0f ) // From hightest to lowest layer + { + float4 vInnerTexel = tex2D( g_tInnerSampler, saturate( i.vUv01.xy + i.v2DTangentViewVector01.xy * 0.005 * j ) ); + float4 vMiddleTexel = tex2D( g_tMiddleSampler, saturate( i.vUv01.wz + i.v2DTangentViewVector01.wz * 0.005 * j ) ); + float4 vOuterTexel = tex2D( g_tOuterSampler, saturate( i.v2DTangentViewVector2_vUv2.wz + i.v2DTangentViewVector2_vUv2.xy * 0.005 * j ) ); + + float4 vThisTexel; + vThisTexel.rgb = ( vInnerTexel.rgb * vInnerTexel.a ) + ( vMiddleTexel.rgb * vMiddleTexel.a ) + ( vOuterTexel.rgb * vOuterTexel.a ); + vThisTexel.a = 1.0f - ( ( 1.0f - vOuterTexel.a ) * ( 1.0f - vMiddleTexel.a ) * ( 1.0f - vInnerTexel.a ) ); + + //vThisTexel.rgb *= flColorDim; + //flColorDim *= 0.95f; + + // 5.0 and 0.8625 are magic numbers that look good with the current textures + float flBlendValue = saturate( pow( vThisTexel.a, lerp( 5.0f, 0.8625f, saturate( j/(flNumLayers-1.0f) ) ) ) ); + + vFinalColor.rgb = vThisTexel.rgb + ( vFinalColor.rgb * ( 1.0f - flBlendValue ) ); + vFinalColor.a *= 1.0f - flBlendValue; // Dest alpha scalar + } + + //===============// + // Combine terms // + //===============// + float4 result; + result.rgb = vFinalColor.rgb; + result.a = 1.0f - vFinalColor.a; + + return FinalOutput( result, 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_LINEAR ); //go back to final output when it'll fit. +} diff --git a/materialsystem/stdshaders/volume_clouds_vs20.fxc b/materialsystem/stdshaders/volume_clouds_vs20.fxc new file mode 100644 index 0000000..ccab257 --- /dev/null +++ b/materialsystem/stdshaders/volume_clouds_vs20.fxc @@ -0,0 +1,103 @@ +//========= Copyright © 1996-2006, Valve Corporation, All rights reserved. ============// + +// DYNAMIC: "COMPRESSED_VERTS" "0..1" +// DYNAMIC: "SKINNING" "0..1" + +// Includes +#include "common_vs_fxc.h" + +// Globals +static const bool g_bSkinning = SKINNING ? true : false; + +const float3 g_vTime : register( SHADER_SPECIFIC_CONST_0 ); +#define g_flTime1x g_vTime.x +#define g_flTime2x g_vTime.y +#define g_flTime4x g_vTime.z + +const float4 cBaseTexCoordTransform[2] : register( SHADER_SPECIFIC_CONST_1 ); + +// Structs +struct VS_INPUT +{ + float4 vPos : POSITION; // Position + float4 vNormal : NORMAL; // Normal + float4 vBoneWeights : BLENDWEIGHT; // Skin weights + float4 vBoneIndices : BLENDINDICES; // Skin indices + float4 vTexCoord0 : TEXCOORD0; // Base texture coordinates + float4 vUserData : TANGENT; +}; + +struct VS_OUTPUT +{ + float4 vProjPosition : POSITION; // Projection-space position + float4 v2DTangentViewVector01 : TEXCOORD0; + float4 vUv01 : TEXCOORD1; + float4 v2DTangentViewVector2_vUv2 : TEXCOORD2; +}; + +// Main +VS_OUTPUT main( const VS_INPUT i ) +{ + VS_OUTPUT o; + + // Decompress compressed normal and tangent + float4 vObjPosition = i.vPos.xyzw; + float3 vObjNormal; + float4 vObjTangent; + DecompressVertex_NormalTangent( i.vNormal, i.vUserData, vObjNormal, vObjTangent ); + + // Transform the position + float3 vWorldPosition = { 0.0f, 0.0f, 0.0f }; + float3 vWorldNormal = { 0.0f, 0.0f, 0.0f }; + float3 vWorldTangent = { 0.0f, 0.0f, 0.0f }; + float3 vWorldBinormal = { 0.0f, 0.0f, 0.0f }; + SkinPositionNormalAndTangentSpace( g_bSkinning, vObjPosition, vObjNormal.xyz, vObjTangent.xyzw, i.vBoneWeights, i.vBoneIndices, vWorldPosition, vWorldNormal, vWorldTangent, vWorldBinormal ); + vWorldNormal.xyz = normalize( vWorldNormal.xyz ); + vWorldTangent.xyz = normalize( vWorldTangent.xyz ); + vWorldBinormal.xyz = normalize( vWorldBinormal.xyz ); + + // Transform into projection space + float4 vProjPosition = mul( float4( vWorldPosition, 1.0f ), cViewProj ); + o.vProjPosition = vProjPosition; + + // View vector + float3 vWorldViewVector = normalize( vWorldPosition.xyz - cEyePos.xyz ); + float3 vTangentViewVector = Vec3WorldToTangentNormalized( vWorldViewVector.xyz, vWorldNormal.xyz, vWorldTangent.xyz, vWorldBinormal.xyz ); + + // Texture coordinates + float4 mRotate; + float2 vBaseUv = i.vTexCoord0.xy; + + // Inner layer + mRotate.x = cos( g_flTime4x ); + mRotate.y = -sin( g_flTime4x ); + mRotate.z = -mRotate.y; + mRotate.w = mRotate.x; + o.vUv01.xy = ( vBaseUv.xy - 0.5f ) * 1.0f; + o.vUv01.xy = float2( dot( o.vUv01.xy, mRotate.xy ), dot( o.vUv01.xy, mRotate.zw ) ); + o.vUv01.xy += 0.5f; + o.v2DTangentViewVector01.xy = float2( dot( vTangentViewVector.xy, mRotate.xy ), dot( vTangentViewVector.xy, mRotate.zw ) ); + + // Middle layer + mRotate.x = cos( g_flTime2x ); + mRotate.y = -sin( g_flTime2x ); + mRotate.z = -mRotate.y; + mRotate.w = mRotate.x; + o.vUv01.wz = ( vBaseUv.xy - 0.5f ) * 1.0f; + o.vUv01.wz = float2( dot( o.vUv01.wz, mRotate.xy ), dot( o.vUv01.wz, mRotate.zw ) ); + o.vUv01.wz += 0.5f; + o.v2DTangentViewVector01.wz = float2( dot( vTangentViewVector.xy, mRotate.xy ), dot( vTangentViewVector.xy, mRotate.zw ) ); + + // Outer layer + mRotate.x = cos( g_flTime1x ); + mRotate.y = -sin( g_flTime1x ); + mRotate.z = -mRotate.y; + mRotate.w = mRotate.x; + float2 vUv2 = ( vBaseUv.xy - 0.5f ) * 1.0f; + vUv2.xy = float2( dot( vUv2.xy, mRotate.xy ), dot( vUv2.xy, mRotate.zw ) ); + vUv2.xy += 0.5f; + o.v2DTangentViewVector2_vUv2.wz = vUv2.xy; + o.v2DTangentViewVector2_vUv2.xy = float2( dot( vTangentViewVector.xy, mRotate.xy ), dot( vTangentViewVector.xy, mRotate.zw ) ); + + return o; +} diff --git a/materialsystem/stdshaders/volumetricfog.cpp b/materialsystem/stdshaders/volumetricfog.cpp new file mode 100644 index 0000000..ffae581 --- /dev/null +++ b/materialsystem/stdshaders/volumetricfog.cpp @@ -0,0 +1,37 @@ +//========= 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( VolumetricFog, "Help for VolumetricFog" ) + BEGIN_SHADER_PARAMS + END_SHADER_PARAMS + + SHADER_INIT + { + } + + SHADER_DRAW + { + SHADOW_STATE + { + pShaderShadow->DepthFunc( SHADER_DEPTHFUNC_NEAREROREQUAL ); + pShaderShadow->EnableDepthWrites( false ); + pShaderShadow->BlendFunc( SHADER_BLEND_ONE, SHADER_BLEND_ONE_MINUS_SRC_ALPHA ); + pShaderShadow->EnableBlending( true ); + pShaderShadow->DrawFlags( SHADER_DRAW_POSITION | SHADER_DRAW_COLOR ); + } + DYNAMIC_STATE + { + } + Draw(); + } +END_SHADER diff --git a/materialsystem/stdshaders/vortwarp_dx7.cpp b/materialsystem/stdshaders/vortwarp_dx7.cpp new file mode 100644 index 0000000..5c807e5 --- /dev/null +++ b/materialsystem/stdshaders/vortwarp_dx7.cpp @@ -0,0 +1,268 @@ +//========= 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" + +DEFINE_FALLBACK_SHADER( Vortwarp, VortWarp_DX7 ) + +float QuadraticBezier( float t, float A, float B, float C ) +{ + return Lerp( t, Lerp( t, A, B ), Lerp( t, B, C ) ); +} + +float CubicBezier( float t, float A, float B, float C, float D ) +{ + return QuadraticBezier( t, Lerp( t, A, B ), Lerp( t, B, C ), Lerp( t, C, D ) ); +} + +BEGIN_SHADER( VortWarp_DX7, + "Help for VortWarp_DX7" ) + + BEGIN_SHADER_PARAMS + SHADER_PARAM( SELFILLUMTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "Self-illumination tint" ) + SHADER_PARAM( ENTITYORIGIN, SHADER_PARAM_TYPE_VEC3,"0.0","center if the model in world space" ) + SHADER_PARAM( WARPPARAM, SHADER_PARAM_TYPE_FLOAT,"0.0","animation param between 0 and 1" ) + + SHADER_PARAM( SELFILLUMMAP, SHADER_PARAM_TYPE_TEXTURE, "", "self-illumination map" ) + SHADER_PARAM( UNLIT, SHADER_PARAM_TYPE_BOOL, "", "" ) + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + SET_FLAGS2( MATERIAL_VAR2_SUPPORTS_HW_SKINNING ); + + if( !params[SELFILLUMTINT]->IsDefined() ) + params[SELFILLUMTINT]->SetVecValue( 1.0f, 1.0f, 1.0f ); + + SET_FLAGS2( MATERIAL_VAR2_LIGHTING_VERTEX_LIT ); + + if( !params[UNLIT]->IsDefined() ) + { + params[UNLIT]->SetIntValue( 0 ); + } + } + + SHADER_FALLBACK + { + if (g_pHardwareConfig->GetDXSupportLevel() < 70) + return "VertexLitGeneric_DX6"; + return 0; + } + + SHADER_INIT + { + if (params[BASETEXTURE]->IsDefined()) + { + LoadTexture( BASETEXTURE ); + + if (!params[BASETEXTURE]->GetTextureValue()->IsTranslucent()) + { + CLEAR_FLAGS( MATERIAL_VAR_SELFILLUM ); + CLEAR_FLAGS( MATERIAL_VAR_BASEALPHAENVMAPMASK ); + } + } + if( params[SELFILLUMMAP]->IsDefined() ) + { + LoadTexture( SELFILLUMMAP ); + } + + // Don't alpha test if the alpha channel is used for other purposes + if (IS_FLAG_SET(MATERIAL_VAR_SELFILLUM) || IS_FLAG_SET(MATERIAL_VAR_BASEALPHAENVMAPMASK) ) + CLEAR_FLAGS( MATERIAL_VAR_ALPHATEST ); + } + + void DrawBaseTimesVertexColor( bool bUnlit, IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow ) + { + SHADOW_STATE + { + // alpha test + pShaderShadow->EnableAlphaTest( IS_FLAG_SET(MATERIAL_VAR_ALPHATEST) ); + + pShaderShadow->EnableCustomPixelPipe( true ); + + pShaderShadow->CustomTextureStages( 1 ); + + if( bUnlit ) + { + pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE0, + SHADER_TEXCHANNEL_COLOR, SHADER_TEXOP_SELECTARG1, + SHADER_TEXARG_TEXTURE, SHADER_TEXARG_NONE ); + } + else + { + pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE0, + SHADER_TEXCHANNEL_COLOR, SHADER_TEXOP_MODULATE2X, + SHADER_TEXARG_TEXTURE, SHADER_TEXARG_VERTEXCOLOR ); + } + + pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE0, + SHADER_TEXCHANNEL_ALPHA, SHADER_TEXOP_SELECTARG1, + SHADER_TEXARG_TEXTURE, SHADER_TEXARG_NONE ); + + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + int flags = SHADER_DRAW_POSITION | SHADER_DRAW_NORMAL | SHADER_DRAW_TEXCOORD0; + pShaderShadow->DrawFlags( flags ); + DefaultFog(); + + pShaderShadow->CustomTextureStages( 2 ); + + pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE1, + SHADER_TEXCHANNEL_COLOR, SHADER_TEXOP_SELECTARG1, + SHADER_TEXARG_PREVIOUSSTAGE, SHADER_TEXARG_NONE ); + + pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE1, + SHADER_TEXCHANNEL_ALPHA, SHADER_TEXOP_ADD, + SHADER_TEXARG_PREVIOUSSTAGE, SHADER_TEXARG_CONSTANTCOLOR ); + + // for warping in + pShaderShadow->EnableAlphaTest( true ); + + pShaderShadow->AlphaFunc( SHADER_ALPHAFUNC_GEQUAL, 1.0f ); + +// SetDefaultBlendingShadowState( BASETEXTURE, true ); + } + DYNAMIC_STATE + { + SetFixedFunctionTextureTransform( MATERIAL_TEXTURE0, BASETEXTURETRANSFORM ); + BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME ); + float warp = params[WARPPARAM]->GetFloatValue(); + float t = warp; + warp = CubicBezier( warp, 0.0f, 1.0f, 0.0f, 0.0f ); + warp = Lerp( t, warp, 1.0f ); + pShaderAPI->Color4f( 1.0f, 1.0f, 1.0f, warp ); + } + Draw(); + } + + int GetDrawFlagsPass1(IMaterialVar** params) + { + int flags = SHADER_DRAW_POSITION; + if (IS_FLAG_SET(MATERIAL_VAR_VERTEXCOLOR)) + flags |= SHADER_DRAW_COLOR; + if (params[BASETEXTURE]->IsTexture()) + flags |= SHADER_DRAW_TEXCOORD0; + return flags; + } + + void DrawUnlit( IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow ) + { + SHADOW_STATE + { + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + SetModulationShadowState(); + SetNormalBlendingShadowState( BASETEXTURE, true ); + pShaderShadow->DrawFlags( GetDrawFlagsPass1(params) ); + FogToFogColor(); + } + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME ); + SetFixedFunctionTextureTransform( MATERIAL_TEXTURE0, BASETEXTURETRANSFORM ); + SetModulationDynamicState(); + } + Draw( ); + } + + //----------------------------------------------------------------------------- + // Fixed function Self illumination pass + //----------------------------------------------------------------------------- + void ScrollySelfIllumPass( IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow ) + { + SHADOW_STATE + { + SetInitialShadowState(); + + // A little setup for self illum here... + SetModulationShadowState( SELFILLUMTINT ); + + s_pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + s_pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + + // Don't bother with z writes here... + s_pShaderShadow->EnableDepthWrites( false ); + + pShaderShadow->EnableCustomPixelPipe( true ); + + pShaderShadow->CustomTextureStages( 2 ); + + // basetexture * selfillumtint + pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE0, + SHADER_TEXCHANNEL_COLOR, SHADER_TEXOP_MODULATE, + SHADER_TEXARG_TEXTURE, SHADER_TEXARG_CONSTANTCOLOR ); + // previous * selfillummap + pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE1, + SHADER_TEXCHANNEL_COLOR, SHADER_TEXOP_MODULATE, + SHADER_TEXARG_TEXTURE, SHADER_TEXARG_PREVIOUSSTAGE ); + + // We're always blending + EnableAlphaBlending( SHADER_BLEND_ONE, SHADER_BLEND_ONE ); + + s_pShaderShadow->DrawFlags( SHADER_DRAW_POSITION | SHADER_DRAW_TEXCOORD0 | SHADER_DRAW_TEXCOORD1 ); + FogToFogColor(); + } + DYNAMIC_STATE + { + s_pShaderAPI->SetDefaultState(); + + BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME ); + BindTexture( SHADER_SAMPLER1, SELFILLUMMAP, -1 ); + + // ----------------------------------------------------------- + // Set up the self illum tint + // ----------------------------------------------------------- + float selfIllumTint[3]; + params[SELFILLUMTINT]->GetVecValue( selfIllumTint, 3 ); + selfIllumTint[0] = clamp( selfIllumTint[0], 0.0f, 1.0f ); + selfIllumTint[1] = clamp( selfIllumTint[1], 0.0f, 1.0f ); + selfIllumTint[2] = clamp( selfIllumTint[2], 0.0f, 1.0f ); +// Warning( "selfillumtint: %f %f %f\n", selfIllumTint[0], selfIllumTint[1], selfIllumTint[2] ); + + pShaderAPI->Color4f( selfIllumTint[0], selfIllumTint[1], selfIllumTint[2], 1.0f ); + + // ----------------------------------------------------------- + // Set up the self illum scrolling + // ----------------------------------------------------------- + float curTime = pShaderAPI->CurrentTime(); + pShaderAPI->MatrixMode( MATERIAL_TEXTURE0 ); + + // only do the upper 3x3 since this is a 2D matrix + float mat[16]; + mat[0] = 1.0f; mat[1] = 0.0f; mat[2] = 0.0f; + mat[4] = 0.0f; mat[5] = 1.0f; mat[6] = 0.0f; + mat[8] = .11f * curTime; mat[9] = .124 * curTime; mat[10] = 1.0f; + + // Better set the stuff we don't set with some sort of value! + mat[3] = mat[7] = mat[11] = 0; + mat[12] = mat[13] = mat[14] = 0; + mat[15] = 1; + + s_pShaderAPI->LoadMatrix( mat ); + } + Draw(); + } + + SHADER_DRAW + { + bool hasFlashlight = UsingFlashlight( params ); + + if( hasFlashlight ) + { +// DrawFlashlight_dx70( params, pShaderAPI, pShaderShadow, FLASHLIGHTTEXTURE, FLASHLIGHTTEXTUREFRAME ); + return; + } + + // Draw base times lighting. + // Lighting is either sent down per vertex from the app, or it's in the second + // stream as color values. + DrawBaseTimesVertexColor( params[UNLIT]->GetIntValue() != 0, params, pShaderAPI, pShaderShadow ); +// ScrollySelfIllumPass( params, pShaderAPI, pShaderShadow ); + } +END_SHADER diff --git a/materialsystem/stdshaders/vortwarp_dx8.cpp b/materialsystem/stdshaders/vortwarp_dx8.cpp new file mode 100644 index 0000000..9c071e6 --- /dev/null +++ b/materialsystem/stdshaders/vortwarp_dx8.cpp @@ -0,0 +1,175 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $Header: $ +// $NoKeywords: $ +//=============================================================================// + +#include "BaseVSShader.h" + +#include "vortwarp_vs11.inc" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +DEFINE_FALLBACK_SHADER( VortWarp, VortWarp_dx8 ) + +float QuadraticBezier( float t, float A, float B, float C ) +{ + return Lerp( t, Lerp( t, A, B ), Lerp( t, B, C ) ); +} + +float CubicBezier( float t, float A, float B, float C, float D ) +{ + return QuadraticBezier( t, Lerp( t, A, B ), Lerp( t, B, C ), Lerp( t, C, D ) ); +} + +BEGIN_VS_SHADER( VortWarp_dx8, + "Help for VortWarp_dx8" ) + BEGIN_SHADER_PARAMS + SHADER_PARAM( SELFILLUMTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "Self-illumination tint" ) + SHADER_PARAM( ENTITYORIGIN, SHADER_PARAM_TYPE_VEC3,"0.0","center if the model in world space" ) + SHADER_PARAM( WARPPARAM, SHADER_PARAM_TYPE_FLOAT,"0.0","animation param between 0 and 1" ) + + SHADER_PARAM( SELFILLUMMAP, SHADER_PARAM_TYPE_TEXTURE, "", "self-illumination map" ) + SHADER_PARAM( UNLIT, SHADER_PARAM_TYPE_BOOL, "", "" ) + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + SET_FLAGS2( MATERIAL_VAR2_SUPPORTS_HW_SKINNING ); + + if( !params[SELFILLUMTINT]->IsDefined() ) + params[SELFILLUMTINT]->SetVecValue( 1.0f, 1.0f, 1.0f ); + + if( !params[UNLIT]->IsDefined() ) + { + params[UNLIT]->SetIntValue( 0 ); + } + if( !params[SELFILLUMTINT]->IsDefined() ) + { + params[SELFILLUMTINT]->SetVecValue( 0.0f, 0.0f, 0.0f, 0.0f ); + } + + SET_FLAGS2( MATERIAL_VAR2_LIGHTING_VERTEX_LIT ); + } + + SHADER_FALLBACK + { + if ( g_pHardwareConfig->GetDXSupportLevel() < 80) + return "Vortwarp_dx7"; + return 0; + } + + SHADER_INIT + { + if (params[BASETEXTURE]->IsDefined()) + { + LoadTexture( BASETEXTURE ); + } + if( params[SELFILLUMMAP]->IsDefined() ) + { + LoadTexture( SELFILLUMMAP ); + } + } + + SHADER_DRAW + { + BlendType_t blendType = BT_BLEND; + if ( params[BASETEXTURE]->IsTexture() ) + { + blendType = EvaluateBlendRequirements( BASETEXTURE, true ); + } + SHADOW_STATE + { + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + + int fmt = VERTEX_POSITION | VERTEX_NORMAL; + + if (params[BASETEXTURE]->IsTexture()) + { + SetDefaultBlendingShadowState( BASETEXTURE, true ); + } + + pShaderShadow->VertexShaderVertexFormat( fmt, 1, 0, 0 ); + + // Set up the vertex shader index. + vortwarp_vs11_Static_Index vshIndex; + vshIndex.SetUNLIT( params[UNLIT]->GetIntValue() != 0 ); + vshIndex.SetHALF_LAMBERT( IS_FLAG_SET( MATERIAL_VAR_HALFLAMBERT ) ); + + pShaderShadow->SetVertexShader( "vortwarp_vs11", vshIndex.GetIndex() ); + + int pshIndex; + if( blendType == BT_BLEND ) + { + pShaderShadow->EnableBlending( true ); + pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA ); + pShaderShadow->EnableAlphaWrites( false ); + pshIndex = 1; + } + else + { + pShaderShadow->EnableAlphaWrites( true ); + pshIndex = 0; + } + + if( params[UNLIT]->GetIntValue() != 0 ) + { + pshIndex |= 0x2; + } + + pShaderShadow->SetPixelShader( "vortwarp_ps11", pshIndex ); + + + DefaultFog(); + } + DYNAMIC_STATE + { + if (params[BASETEXTURE]->IsTexture()) + { + BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME ); + SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, BASETEXTURETRANSFORM ); + } + + if( params[SELFILLUMMAP]->IsTexture() ) + { + BindTexture( SHADER_SAMPLER1, SELFILLUMMAP, -1 ); + } + + float warp = params[WARPPARAM]->GetFloatValue(); + float t = warp; + warp = CubicBezier( warp, 0.0f, 1.0f, 0.0f, 0.0f ); + warp = Lerp( t, warp, 1.0f ); + float warpVec[4] = { warp, warp, warp, warp }; + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_2, warpVec, 1 ); + SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_3, ENTITYORIGIN ); + SetAmbientCubeDynamicStateVertexShader(); + SetModulationPixelShaderDynamicState( 3 ); + EnablePixelShaderOverbright( 0, true, true ); + SetPixelShaderConstant( 1, SELFILLUMTINT ); + float c4[4] = { 0.0f, 0.0f, 0.0f, 1.0f }; + if( warp > 0.0f && warp < 1.0f ) + { + c4[3] = 0.0f; + } + pShaderAPI->SetPixelShaderConstant( 4, c4, 1 ); + + float c5[4] = { 1.0f, 1.0f, 1.0f, 1.0f }; + pShaderAPI->SetPixelShaderConstant( 5, c5, 1 ); + + float curTime = pShaderAPI->CurrentTime(); + float selfIllumScroll[4] = { .11f * curTime, .124 * curTime, 0.0f, 0.0f }; + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_4, selfIllumScroll, 1 ); + + vortwarp_vs11_Dynamic_Index vshIndex; + vshIndex.SetSKINNING( pShaderAPI->GetCurrentNumBones() > 0 ); + vshIndex.SetLIGHT_COMBO( 0 ); + vshIndex.SetLIGHT_COMBO( pShaderAPI->GetCurrentLightCombo() ); + pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() ); + } + Draw(); + } +END_SHADER diff --git a/materialsystem/stdshaders/vortwarp_dx9.cpp b/materialsystem/stdshaders/vortwarp_dx9.cpp new file mode 100644 index 0000000..7c133f6 --- /dev/null +++ b/materialsystem/stdshaders/vortwarp_dx9.cpp @@ -0,0 +1,640 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $Header: $ +// $NoKeywords: $ +//===========================================================================// + +#include "BaseVSShader.h" +#include "vertexlitgeneric_dx9_helper.h" +#include "vortwarp_vs20.inc" +#include "vortwarp_ps20.inc" +#include "vortwarp_ps20b.inc" +#include "convar.h" + +#ifndef _X360 +#include "vortwarp_vs30.inc" +#include "vortwarp_ps30.inc" +#endif + +DEFINE_FALLBACK_SHADER( VortWarp, VortWarp_dx9 ) + +extern ConVar r_flashlight_version2; + +struct VortWarp_DX9_Vars_t : public VertexLitGeneric_DX9_Vars_t +{ + VortWarp_DX9_Vars_t() { memset( this, 0xFF, sizeof(*this) ); } + int m_nEntityOrigin; + int m_nWarpParam; + int m_nFlowMap; + int m_nSelfIllumMap; + int m_nUnlit; +}; + + +//----------------------------------------------------------------------------- +// Draws the shader +//----------------------------------------------------------------------------- +void DrawVortWarp_DX9( CBaseVSShader *pShader, IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, + IShaderShadow* pShaderShadow, bool bVertexLitGeneric, bool hasFlashlight, VortWarp_DX9_Vars_t &info, VertexCompressionType_t vertexCompression ) +{ + bool hasBaseTexture = params[info.m_nBaseTexture]->IsTexture(); + bool hasBump = (info.m_nBumpmap != -1) && params[info.m_nBumpmap]->IsTexture(); + bool hasDetailTexture = !hasBump && params[info.m_nDetail]->IsTexture(); + bool hasNormalMapAlphaEnvmapMask = IS_FLAG_SET( MATERIAL_VAR_NORMALMAPALPHAENVMAPMASK ); + bool hasVertexColor = bVertexLitGeneric ? false : IS_FLAG_SET( MATERIAL_VAR_VERTEXCOLOR ); + bool hasVertexAlpha = bVertexLitGeneric ? false : IS_FLAG_SET( MATERIAL_VAR_VERTEXALPHA ); + bool bIsAlphaTested = IS_FLAG_SET( MATERIAL_VAR_ALPHATEST ) != 0; + bool hasSelfIllumInEnvMapMask = + ( info.m_nSelfIllumEnvMapMask_Alpha != -1 ) && + ( params[info.m_nSelfIllumEnvMapMask_Alpha]->GetFloatValue() != 0.0 ) ; + bool bHasFlowMap = ( info.m_nFlowMap != -1 ) && params[info.m_nFlowMap]->IsTexture(); + bool bHasSelfIllumMap = ( info.m_nSelfIllumMap != -1 ) && params[info.m_nSelfIllumMap]->IsTexture(); + + BlendType_t blendType; + if ( params[info.m_nBaseTexture]->IsTexture() ) + { + blendType = pShader->EvaluateBlendRequirements( info.m_nBaseTexture, true ); + } + else + { + blendType = pShader->EvaluateBlendRequirements( info.m_nEnvmapMask, false ); + } + + + if( pShader->IsSnapshotting() ) + { + // look at color and alphamod stuff. + // Unlit generic never uses the flashlight + bool hasEnvmap = !hasFlashlight && params[info.m_nEnvmap]->IsTexture(); + bool hasEnvmapMask = (hasSelfIllumInEnvMapMask || !hasFlashlight) && + params[info.m_nEnvmapMask]->IsTexture(); + bool bHasNormal = bVertexLitGeneric || hasEnvmap; + + if( hasFlashlight ) + { + hasEnvmapMask = false; + } + + bool bHalfLambert = IS_FLAG_SET( MATERIAL_VAR_HALFLAMBERT ); + // Alpha test: FIXME: shouldn't this be handled in CBaseVSShader::SetInitialShadowState + pShaderShadow->EnableAlphaTest( bIsAlphaTested ); + + if( info.m_nAlphaTestReference != -1 && params[info.m_nAlphaTestReference]->GetFloatValue() > 0.0f ) + { + pShaderShadow->AlphaFunc( SHADER_ALPHAFUNC_GEQUAL, params[info.m_nAlphaTestReference]->GetFloatValue() ); + } + + if( hasFlashlight ) + { + if (params[info.m_nBaseTexture]->IsTexture()) + { + pShader->SetAdditiveBlendingShadowState( info.m_nBaseTexture, true ); + } + else + { + pShader->SetAdditiveBlendingShadowState( info.m_nEnvmapMask, false ); + } + if( bIsAlphaTested ) + { + // disable alpha test and use the zfunc zequals since alpha isn't guaranteed to + // be the same on both the regular pass and the flashlight pass. + pShaderShadow->EnableAlphaTest( false ); + pShaderShadow->DepthFunc( SHADER_DEPTHFUNC_EQUAL ); + } + pShaderShadow->EnableBlending( true ); + pShaderShadow->EnableDepthWrites( false ); + } + else + { + if (params[info.m_nBaseTexture]->IsTexture()) + { + pShader->SetDefaultBlendingShadowState( info.m_nBaseTexture, true ); + } + else + { + pShader->SetDefaultBlendingShadowState( info.m_nEnvmapMask, false ); + } + } + + unsigned int flags = VERTEX_POSITION; + int nTexCoordCount = 1; // texcoord0 : base texcoord + int userDataSize = 0; + if( bHasNormal ) + { + flags |= VERTEX_NORMAL; + } + + if( hasBaseTexture ) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, true ); + } + if( hasEnvmap ) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + if( g_pHardwareConfig->GetHDRType() == HDR_TYPE_NONE ) + { + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER1, true ); + } + } + if( hasFlashlight ) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER7, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER4, true ); + userDataSize = 4; // tangent S + } + if( hasDetailTexture ) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER2, true ); + } + if( hasBump ) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER3, true ); + userDataSize = 4; // tangent S + // Normalizing cube map + pShaderShadow->EnableTexture( SHADER_SAMPLER5, true ); + } + if( hasEnvmapMask ) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER4, true ); + } + + if( hasVertexColor || hasVertexAlpha ) + { + flags |= VERTEX_COLOR; + } + + pShaderShadow->EnableSRGBWrite( true ); + + if( bHasSelfIllumMap ) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER6, true ); + } + + if( bHasFlowMap ) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER2, true ); + } + + // This shader supports compressed vertices, so OR in that flag: + flags |= VERTEX_FORMAT_COMPRESSED; + + pShaderShadow->VertexShaderVertexFormat( flags, nTexCoordCount, NULL, userDataSize ); + + Assert( hasBump ); + +#ifndef _X360 + if ( !g_pHardwareConfig->HasFastVertexTextures() ) +#endif + { + bool bUseStaticControlFlow = g_pHardwareConfig->SupportsStaticControlFlow(); + + DECLARE_STATIC_VERTEX_SHADER( vortwarp_vs20 ); + SET_STATIC_VERTEX_SHADER_COMBO( HALFLAMBERT, bHalfLambert); + SET_STATIC_VERTEX_SHADER_COMBO( USE_STATIC_CONTROL_FLOW, bUseStaticControlFlow ); + SET_STATIC_VERTEX_SHADER( vortwarp_vs20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_STATIC_PIXEL_SHADER( vortwarp_ps20b ); + SET_STATIC_PIXEL_SHADER_COMBO( BASETEXTURE, hasBaseTexture ); + SET_STATIC_PIXEL_SHADER_COMBO( CUBEMAP, hasEnvmap ); + SET_STATIC_PIXEL_SHADER_COMBO( DIFFUSELIGHTING, !params[info.m_nUnlit]->GetIntValue() ); + SET_STATIC_PIXEL_SHADER_COMBO( NORMALMAPALPHAENVMAPMASK, hasNormalMapAlphaEnvmapMask ); + SET_STATIC_PIXEL_SHADER_COMBO( HALFLAMBERT, bHalfLambert); + SET_STATIC_PIXEL_SHADER_COMBO( FLASHLIGHT, hasFlashlight ); + SET_STATIC_PIXEL_SHADER_COMBO( TRANSLUCENT, blendType == BT_BLEND ); + SET_STATIC_PIXEL_SHADER( vortwarp_ps20b ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( vortwarp_ps20 ); + SET_STATIC_PIXEL_SHADER_COMBO( BASETEXTURE, hasBaseTexture ); + SET_STATIC_PIXEL_SHADER_COMBO( CUBEMAP, hasEnvmap ); + SET_STATIC_PIXEL_SHADER_COMBO( DIFFUSELIGHTING, !params[info.m_nUnlit]->GetIntValue() ); + SET_STATIC_PIXEL_SHADER_COMBO( NORMALMAPALPHAENVMAPMASK, hasNormalMapAlphaEnvmapMask ); + SET_STATIC_PIXEL_SHADER_COMBO( HALFLAMBERT, bHalfLambert); + SET_STATIC_PIXEL_SHADER_COMBO( FLASHLIGHT, hasFlashlight ); + SET_STATIC_PIXEL_SHADER_COMBO( TRANSLUCENT, blendType == BT_BLEND ); + SET_STATIC_PIXEL_SHADER( vortwarp_ps20 ); + } + } +#ifndef _X360 + else + { + // The vertex shader uses the vertex id stream + SET_FLAGS2( MATERIAL_VAR2_USES_VERTEXID ); + + DECLARE_STATIC_VERTEX_SHADER( vortwarp_vs30 ); + SET_STATIC_VERTEX_SHADER_COMBO( HALFLAMBERT, bHalfLambert); + SET_STATIC_VERTEX_SHADER( vortwarp_vs30 ); + + DECLARE_STATIC_PIXEL_SHADER( vortwarp_ps30 ); + SET_STATIC_PIXEL_SHADER_COMBO( BASETEXTURE, hasBaseTexture ); + SET_STATIC_PIXEL_SHADER_COMBO( CUBEMAP, hasEnvmap ); + SET_STATIC_PIXEL_SHADER_COMBO( DIFFUSELIGHTING, !params[info.m_nUnlit]->GetIntValue() ); + SET_STATIC_PIXEL_SHADER_COMBO( NORMALMAPALPHAENVMAPMASK, hasNormalMapAlphaEnvmapMask ); + SET_STATIC_PIXEL_SHADER_COMBO( HALFLAMBERT, bHalfLambert); + SET_STATIC_PIXEL_SHADER_COMBO( FLASHLIGHT, hasFlashlight ); + SET_STATIC_PIXEL_SHADER_COMBO( TRANSLUCENT, blendType == BT_BLEND ); + SET_STATIC_PIXEL_SHADER( vortwarp_ps30 ); + } +#endif + + if( hasFlashlight ) + { + pShader->FogToBlack(); + } + else + { + pShader->DefaultFog(); + } + + if( blendType == BT_BLEND ) + { + pShaderShadow->EnableBlending( true ); + pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA ); + pShaderShadow->EnableAlphaWrites( false ); + } + else + { + pShaderShadow->EnableAlphaWrites( true ); + } + } + else + { + bool hasEnvmap = !hasFlashlight && params[info.m_nEnvmap]->IsTexture(); + bool hasEnvmapMask = !hasFlashlight && params[info.m_nEnvmapMask]->IsTexture(); + + if( hasBaseTexture ) + { + pShader->BindTexture( SHADER_SAMPLER0, info.m_nBaseTexture, info.m_nBaseTextureFrame ); + } + if( hasEnvmap ) + { + pShader->BindTexture( SHADER_SAMPLER1, info.m_nEnvmap, info.m_nEnvmapFrame ); + } + if( hasDetailTexture ) + { + pShader->BindTexture( SHADER_SAMPLER2, info.m_nDetail, info.m_nDetailFrame ); + } + if( !g_pConfig->m_bFastNoBump ) + { + if( hasBump ) + { + pShader->BindTexture( SHADER_SAMPLER3, info.m_nBumpmap, info.m_nBumpFrame ); + } + } + else + { + if( hasBump ) + { + pShaderAPI->BindStandardTexture( SHADER_SAMPLER3, TEXTURE_NORMALMAP_FLAT ); + } + } + if( hasEnvmapMask ) + { + pShader->BindTexture( SHADER_SAMPLER4, info.m_nEnvmapMask, info.m_nEnvmapMaskFrame ); + } + + if( hasFlashlight ) + { + Assert( info.m_nFlashlightTexture >= 0 && info.m_nFlashlightTextureFrame >= 0 ); + pShader->BindTexture( SHADER_SAMPLER7, info.m_nFlashlightTexture, info.m_nFlashlightTextureFrame ); + VMatrix worldToTexture; + ITexture *pFlashlightDepthTexture; + FlashlightState_t state = pShaderAPI->GetFlashlightStateEx( worldToTexture, &pFlashlightDepthTexture ); + SetFlashLightColorFromState( state, pShaderAPI ); + } + + // Set up light combo state + LightState_t lightState = {0, false, false}; + if ( bVertexLitGeneric && !hasFlashlight ) + { + pShaderAPI->GetDX9LightState( &lightState ); + } + + MaterialFogMode_t fogType = pShaderAPI->GetSceneFogMode(); + int fogIndex = ( fogType == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ) ? 1 : 0; + int numBones = pShaderAPI->GetCurrentNumBones(); + + Assert( hasBump ); + +#ifndef _X360 + if ( !g_pHardwareConfig->HasFastVertexTextures() ) +#endif + { + bool bUseStaticControlFlow = g_pHardwareConfig->SupportsStaticControlFlow(); + + DECLARE_DYNAMIC_VERTEX_SHADER( vortwarp_vs20 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( DOWATERFOG, fogIndex ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, numBones > 0 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( NUM_LIGHTS, bUseStaticControlFlow ? 0 : lightState.m_nNumLights ); + SET_DYNAMIC_VERTEX_SHADER( vortwarp_vs20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_DYNAMIC_PIXEL_SHADER( vortwarp_ps20b ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( NUM_LIGHTS, lightState.m_nNumLights ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( AMBIENT_LIGHT, lightState.m_bAmbientLight ? 1 : 0 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( WRITEWATERFOGTODESTALPHA, fogType == MATERIAL_FOG_LINEAR_BELOW_FOG_Z && + blendType != BT_BLENDADD && blendType != BT_BLEND && !bIsAlphaTested ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + float warpParam = params[info.m_nWarpParam]->GetFloatValue(); + // float selfIllumTint = params[info.m_nSelfIllumTint]->GetFloatValue(); + // DevMsg( 1, "warpParam: %f %f\n", warpParam, selfIllumTint ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( WARPINGIN, warpParam > 0.0f && warpParam < 1.0f ); + SET_DYNAMIC_PIXEL_SHADER( vortwarp_ps20b ); + } + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( vortwarp_ps20 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( NUM_LIGHTS, lightState.m_nNumLights ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( AMBIENT_LIGHT, lightState.m_bAmbientLight ? 1 : 0 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( WRITEWATERFOGTODESTALPHA, fogType == MATERIAL_FOG_LINEAR_BELOW_FOG_Z && + blendType != BT_BLENDADD && blendType != BT_BLEND && !bIsAlphaTested ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + float warpParam = params[info.m_nWarpParam]->GetFloatValue(); + // float selfIllumTint = params[info.m_nSelfIllumTint]->GetFloatValue(); + // DevMsg( 1, "warpParam: %f %f\n", warpParam, selfIllumTint ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( WARPINGIN, warpParam > 0.0f && warpParam < 1.0f ); + SET_DYNAMIC_PIXEL_SHADER( vortwarp_ps20 ); + } + } +#ifndef _X360 + else + { + pShader->SetHWMorphVertexShaderState( VERTEX_SHADER_SHADER_SPECIFIC_CONST_6, VERTEX_SHADER_SHADER_SPECIFIC_CONST_7, SHADER_VERTEXTEXTURE_SAMPLER0 ); + + DECLARE_DYNAMIC_VERTEX_SHADER( vortwarp_vs30 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( DOWATERFOG, fogIndex ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, numBones > 0 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( MORPHING, pShaderAPI->IsHWMorphingEnabled() ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression ); + SET_DYNAMIC_VERTEX_SHADER( vortwarp_vs30 ); + + DECLARE_DYNAMIC_PIXEL_SHADER( vortwarp_ps30 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( NUM_LIGHTS, lightState.m_nNumLights ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( AMBIENT_LIGHT, lightState.m_bAmbientLight ? 1 : 0 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( WRITEWATERFOGTODESTALPHA, fogType == MATERIAL_FOG_LINEAR_BELOW_FOG_Z && + blendType != BT_BLENDADD && blendType != BT_BLEND && !bIsAlphaTested ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + float warpParam = params[info.m_nWarpParam]->GetFloatValue(); + // float selfIllumTint = params[info.m_nSelfIllumTint]->GetFloatValue(); + // DevMsg( 1, "warpParam: %f %f\n", warpParam, selfIllumTint ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( WARPINGIN, warpParam > 0.0f && warpParam < 1.0f ); + SET_DYNAMIC_PIXEL_SHADER( vortwarp_ps30 ); + } +#endif + + pShader->SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, info.m_nBaseTextureTransform ); + + if( hasDetailTexture ) + { + pShader->SetVertexShaderTextureScaledTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_2, info.m_nBaseTextureTransform, info.m_nDetailScale ); + Assert( !hasBump ); + } + if( hasBump ) + { + pShader->SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_2, info.m_nBumpTransform ); + Assert( !hasDetailTexture ); + } + if( hasEnvmapMask ) + { + pShader->SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_4, info.m_nEnvmapMaskTransform ); + } + + if( hasEnvmap ) + { + pShader->SetEnvMapTintPixelShaderDynamicState( 0, info.m_nEnvmapTint, -1, true ); + } + if( ( info.m_nHDRColorScale != -1 ) && pShader->IsHDREnabled() ) + { + pShader->SetModulationPixelShaderDynamicState_LinearColorSpace_LinearScale( 1, params[info.m_nHDRColorScale]->GetFloatValue() ); + } + else + { + pShader->SetModulationPixelShaderDynamicState_LinearColorSpace( 1 ); + } + + pShader->SetPixelShaderConstant( 2, info.m_nEnvmapContrast ); + pShader->SetPixelShaderConstant( 3, info.m_nEnvmapSaturation ); + + pShader->SetPixelShaderConstant( 4, info.m_nSelfIllumTint ); + pShader->SetAmbientCubeDynamicStateVertexShader(); + if( hasBump ) + { + pShaderAPI->BindStandardTexture( SHADER_SAMPLER5, TEXTURE_NORMALIZATION_CUBEMAP_SIGNED ); + pShaderAPI->SetPixelShaderStateAmbientLightCube( 5 ); + pShaderAPI->CommitPixelShaderLighting( 13 ); + + } + + if( bHasSelfIllumMap ) + { + pShader->BindTexture( SHADER_SAMPLER6, info.m_nSelfIllumMap, -1 ); + } + + if( bHasFlowMap ) + { + pShader->BindTexture( SHADER_SAMPLER2, info.m_nFlowMap, -1 ); + } + + float eyePos[4]; + pShaderAPI->GetWorldSpaceCameraPosition( eyePos ); + pShaderAPI->SetPixelShaderConstant( 20, eyePos, 1 ); + pShaderAPI->SetPixelShaderFogParams( 21 ); + + // dynamic drawing code that extends vertexlitgeneric + float curTime = params[info.m_nWarpParam]->GetFloatValue(); + float timeVec[4] = { 0.0f, 0.0f, 0.0f, curTime }; + Assert( params[info.m_nEntityOrigin]->IsDefined() ); + params[info.m_nEntityOrigin]->GetVecValue( timeVec, 3 ); + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_4, timeVec, 1 ); + + curTime = pShaderAPI->CurrentTime(); + timeVec[0] = curTime; + timeVec[1] = curTime; + timeVec[2] = curTime; + timeVec[3] = curTime; + pShaderAPI->SetPixelShaderConstant( 22, timeVec, 1 ); + + // flashlightfixme: put this in common code. + if( hasFlashlight ) + { + VMatrix worldToTexture; + const FlashlightState_t &flashlightState = pShaderAPI->GetFlashlightState( worldToTexture ); + + // Set the flashlight attenuation factors + float atten[4]; + atten[0] = flashlightState.m_fConstantAtten; + atten[1] = flashlightState.m_fLinearAtten; + atten[2] = flashlightState.m_fQuadraticAtten; + atten[3] = flashlightState.m_FarZ; + pShaderAPI->SetPixelShaderConstant( 22, atten, 1 ); + + // Set the flashlight origin + float pos[4]; + pos[0] = flashlightState.m_vecLightOrigin[0]; + pos[1] = flashlightState.m_vecLightOrigin[1]; + pos[2] = flashlightState.m_vecLightOrigin[2]; + pos[3] = 1.0f; + pShaderAPI->SetPixelShaderConstant( 23, pos, 1 ); + + pShaderAPI->SetPixelShaderConstant( 24, worldToTexture.Base(), 4 ); + } + } + pShader->Draw(); +} + + +BEGIN_VS_SHADER( VortWarp_DX9, + "Help for VortWarp_DX9" ) + BEGIN_SHADER_PARAMS + SHADER_PARAM( ALBEDO, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "albedo (Base texture with no baked lighting)" ) + SHADER_PARAM( SELFILLUMTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "Self-illumination tint" ) + SHADER_PARAM( DETAIL, SHADER_PARAM_TYPE_TEXTURE, "shadertest/detail", "detail texture" ) + SHADER_PARAM( DETAILFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $detail" ) + SHADER_PARAM( DETAILSCALE, SHADER_PARAM_TYPE_FLOAT, "4", "scale of the detail texture" ) + SHADER_PARAM( ENVMAP, SHADER_PARAM_TYPE_TEXTURE, "shadertest/shadertest_env", "envmap" ) + SHADER_PARAM( ENVMAPFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "envmap frame number" ) + SHADER_PARAM( ENVMAPMASK, SHADER_PARAM_TYPE_TEXTURE, "shadertest/shadertest_envmask", "envmap mask" ) + SHADER_PARAM( ENVMAPMASKFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "" ) + SHADER_PARAM( ENVMAPMASKTRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$envmapmask texcoord transform" ) + SHADER_PARAM( ENVMAPTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "envmap tint" ) + SHADER_PARAM( BUMPMAP, SHADER_PARAM_TYPE_TEXTURE, "models/shadertest/shader1_normal", "bump map" ) + SHADER_PARAM( BUMPFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $bumpmap" ) + SHADER_PARAM( BUMPTRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$bumpmap texcoord transform" ) + SHADER_PARAM( ENVMAPCONTRAST, SHADER_PARAM_TYPE_FLOAT, "0.0", "contrast 0 == normal 1 == color*color" ) + SHADER_PARAM( ENVMAPSATURATION, SHADER_PARAM_TYPE_FLOAT, "1.0", "saturation 0 == greyscale 1 == normal" ) + SHADER_PARAM( SELFILLUM_ENVMAPMASK_ALPHA, SHADER_PARAM_TYPE_FLOAT,"0.0","defines that self illum value comes from env map mask alpha" ) + + // Debugging term for visualizing ambient data on its own + SHADER_PARAM( AMBIENTONLY, SHADER_PARAM_TYPE_INTEGER, "0", "Control drawing of non-ambient light ()" ) + + + // hack hack hack + + + SHADER_PARAM( ENTITYORIGIN, SHADER_PARAM_TYPE_VEC3,"0.0","center if the model in world space" ) + SHADER_PARAM( WARPPARAM, SHADER_PARAM_TYPE_FLOAT,"0.0","animation param between 0 and 1" ) + + SHADER_PARAM( FLOWMAP, SHADER_PARAM_TYPE_TEXTURE, "", "flow map" ) + SHADER_PARAM( SELFILLUMMAP, SHADER_PARAM_TYPE_TEXTURE, "", "self-illumination map" ) + SHADER_PARAM( UNLIT, SHADER_PARAM_TYPE_BOOL, "", "" ) + + SHADER_PARAM( PHONGEXPONENT, SHADER_PARAM_TYPE_FLOAT, "5.0", "Phong exponent for local specular lights" ) + SHADER_PARAM( PHONGTINT, SHADER_PARAM_TYPE_VEC3, "5.0", "Phong tint for local specular lights" ) + SHADER_PARAM( PHONGALBEDOTINT, SHADER_PARAM_TYPE_BOOL, "1.0", "Apply tint by albedo (controlled by spec exponent texture" ) + SHADER_PARAM( LIGHTWARPTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "1D ramp texture for tinting scalar diffuse term" ) + SHADER_PARAM( PHONGWARPTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "warp specular term" ) + SHADER_PARAM( PHONGFRESNELRANGES, SHADER_PARAM_TYPE_VEC3, "[0 0.5 1]", "Parameters for remapping fresnel output" ) + SHADER_PARAM( PHONGBOOST, SHADER_PARAM_TYPE_FLOAT, "1.0", "Phong overbrightening factor (specular mask channel should be authored to account for this)" ) + SHADER_PARAM( PHONGEXPONENTTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "Phong Exponent map" ) + SHADER_PARAM( PHONG, SHADER_PARAM_TYPE_BOOL, "0", "enables phong lighting" ) + END_SHADER_PARAMS + + void SetupVars( VortWarp_DX9_Vars_t& info ) + { + info.m_nBaseTexture = BASETEXTURE; + info.m_nBaseTextureFrame = FRAME; + info.m_nBaseTextureTransform = BASETEXTURETRANSFORM; + info.m_nAlbedo = ALBEDO; + info.m_nSelfIllumTint = SELFILLUMTINT; + info.m_nDetail = DETAIL; + info.m_nDetailFrame = DETAILFRAME; + info.m_nDetailScale = DETAILSCALE; + info.m_nEnvmap = ENVMAP; + info.m_nEnvmapFrame = ENVMAPFRAME; + info.m_nEnvmapMask = ENVMAPMASK; + info.m_nEnvmapMaskFrame = ENVMAPMASKFRAME; + info.m_nEnvmapMaskTransform = ENVMAPMASKTRANSFORM; + info.m_nEnvmapTint = ENVMAPTINT; + info.m_nBumpmap = BUMPMAP; + info.m_nBumpFrame = BUMPFRAME; + info.m_nBumpTransform = BUMPTRANSFORM; + info.m_nEnvmapContrast = ENVMAPCONTRAST; + info.m_nEnvmapSaturation = ENVMAPSATURATION; + info.m_nAlphaTestReference = -1; + info.m_nFlashlightTexture = FLASHLIGHTTEXTURE; + info.m_nFlashlightTextureFrame = FLASHLIGHTTEXTUREFRAME; + info.m_nSelfIllumEnvMapMask_Alpha = SELFILLUM_ENVMAPMASK_ALPHA; + info.m_nAmbientOnly = AMBIENTONLY; + info.m_nEntityOrigin = ENTITYORIGIN; + info.m_nWarpParam = WARPPARAM; + info.m_nFlowMap = FLOWMAP; + info.m_nSelfIllumMap = SELFILLUMMAP; + info.m_nUnlit = UNLIT; + info.m_nPhongExponent = PHONGEXPONENT; + info.m_nPhongExponentTexture = PHONGEXPONENTTEXTURE; + info.m_nDiffuseWarpTexture = LIGHTWARPTEXTURE; + info.m_nPhongWarpTexture = PHONGWARPTEXTURE; + info.m_nPhongBoost = PHONGBOOST; + info.m_nPhongFresnelRanges = PHONGFRESNELRANGES; + info.m_nPhong = PHONG; + + } + + SHADER_INIT_PARAMS() + { + VortWarp_DX9_Vars_t vars; + if( !params[BUMPMAP]->IsDefined() ) + { + params[BUMPMAP]->SetStringValue( "dev/flat_normal" ); + } + SetupVars( vars ); + if( !params[UNLIT]->IsDefined() ) + { + params[UNLIT]->SetIntValue( 0 ); + } + if( !params[SELFILLUMTINT]->IsDefined() ) + { + params[SELFILLUMTINT]->SetVecValue( 0.0f, 0.0f, 0.0f, 0.0f ); + } + InitParamsVertexLitGeneric_DX9( this, params, pMaterialName, true, vars ); + } + + SHADER_FALLBACK + { + if (g_pHardwareConfig->GetDXSupportLevel() < 90) + return "vortwarp_DX8"; + + return 0; + } + + SHADER_INIT + { + VortWarp_DX9_Vars_t vars; + SetupVars( vars ); + InitVertexLitGeneric_DX9( this, params, true, vars ); + if( params[FLOWMAP]->IsDefined() ) + { + LoadTexture( FLOWMAP ); + } + if( params[SELFILLUMMAP]->IsDefined() ) + { + LoadTexture( SELFILLUMMAP ); + } + } + + SHADER_DRAW + { + VortWarp_DX9_Vars_t vars; + SetupVars( vars ); + // UGH!!! FIXME!!!!! Should fix VertexlitGeneric_dx9_helper so that you + // can override the vertex shader/pixel shader used (along with the combo vars). + bool bHasFlashlight = UsingFlashlight( params ); + if ( bHasFlashlight && ( IsX360() || r_flashlight_version2.GetInt() ) ) + { + DrawVortWarp_DX9( this, params, pShaderAPI, pShaderShadow, true, false, vars, vertexCompression ); + SHADOW_STATE + { + SetInitialShadowState(); + } + } + DrawVortWarp_DX9( this, params, pShaderAPI, pShaderShadow, true, bHasFlashlight, vars, vertexCompression ); + } +END_SHADER diff --git a/materialsystem/stdshaders/vortwarp_ps11.psh b/materialsystem/stdshaders/vortwarp_ps11.psh new file mode 100644 index 0000000..faadf18 --- /dev/null +++ b/materialsystem/stdshaders/vortwarp_ps11.psh @@ -0,0 +1,42 @@ +; STATIC: "TRANSLUCENT" "0..1" +; STATIC: "UNLIT" "0..1" +ps.1.1 + +;------------------------------------------------------------------------------ +; Draw a texture . . woo hoo! +; t0 - texture +; +; The texture coordinates need to be defined as follows: +; tc0 - texcoords +;------------------------------------------------------------------------------ + +;------------------------------------------------------------------------------ +#if UNLIT==0 +tex t0 +tex t1 + +mul_sat t1, c1, t1 +lrp r1.rgb, t1, c5, v0 ; blend between unlit and lit. +mul r0, t0, c3 +mul r0.rgb, r1, r0 ; Apply lighting +mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2) + +# if TRANSLUCENT==0 +mov r0.a, c4.a +# endif +#endif + +;------------------------------------------------------------------------------ +#if UNLIT!=0 +; Get the color from the texture +tex t0 + +mul r0, t0, c3 +mul r0.rgb, v0, r0 ; Apply lighting +mul_x2 r0.rgb, c0, r0 ; * 2 * (overbrightFactor/2) + +# if TRANSLUCENT==0 +mov r0.a, c4.a +# endif + +#endif diff --git a/materialsystem/stdshaders/vortwarp_ps2x.fxc b/materialsystem/stdshaders/vortwarp_ps2x.fxc new file mode 100644 index 0000000..1426739 --- /dev/null +++ b/materialsystem/stdshaders/vortwarp_ps2x.fxc @@ -0,0 +1,198 @@ +//======= Copyright © 1996-2006, Valve Corporation, All rights reserved. ====== + +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps30][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX] +// STATIC: "BASETEXTURE" "0..1" +// STATIC: "CUBEMAP" "0..1" +// STATIC: "DIFFUSELIGHTING" "0..1" +// STATIC: "NORMALMAPALPHAENVMAPMASK" "0..1" +// STATIC: "HALFLAMBERT" "0..1" +// STATIC: "FLASHLIGHT" "0..1" +// STATIC: "TRANSLUCENT" "0..1" + +// DYNAMIC: "WRITEWATERFOGTODESTALPHA" "0..1" +// DYNAMIC: "PIXELFOGTYPE" "0..1" +// DYNAMIC: "WARPINGIN" "0..1" +// DYNAMIC: "AMBIENT_LIGHT" "0..1" +// DYNAMIC: "NUM_LIGHTS" "0..2" [ps20] +// DYNAMIC: "NUM_LIGHTS" "0..4" [ps20b] +// DYNAMIC: "NUM_LIGHTS" "0..4" [ps30] + +// We don't use other lights when doing the flashlight, so just skip that +// SKIP: ( $FLASHLIGHT != 0 ) && ( $NUM_LIGHTS > 0 ) [PC] + +#include "common_flashlight_fxc.h" +#include "common_vertexlitgeneric_dx9.h" + +const HALF4 g_EnvmapTint : register( c0 ); +const HALF4 g_DiffuseModulation : register( c1 ); +#if !FLASHLIGHT + const HALF3 g_EnvmapContrast : register( c2 ); + const HALF3 g_EnvmapSaturation : register( c3 ); +#endif +const HALF4 g_SelfIllumTint : register( c4 ); +const float3 cAmbientCube[6] : register( c5 ); + +// 2 registers each - 6 register total +PixelShaderLightInfo cLightInfo[3] : register( c13 ); // through c18 +const HALF3 g_EyePos : register( c20 ); +const HALF4 g_FogParams : register( c21 ); + +#if FLASHLIGHT +const float4 g_FlashlightAttenuationFactors : register( c22 ); +const HALF3 g_FlashlightPos : register( c23 ); +const float4x4 g_FlashlightWorldToTexture : register( c24 ); // through c27 +#else +const float g_Time : register( c22 ); +#endif + +sampler BaseTextureSampler : register( s0 ); +sampler EnvmapSampler : register( s1 ); +sampler FlowMapSampler : register( s2 ); +sampler BumpmapSampler : register( s3 ); +sampler EnvmapMaskSampler : register( s4 ); +sampler NormalizeSampler : register( s5 ); +sampler SelfIllumMapSampler : register( s6 ); +sampler FlashlightSampler : register( s7 ); + +struct PS_INPUT +{ + HALF4 baseTexCoord2_tangentSpaceVertToEyeVectorXY : TEXCOORD0; + + // bump mapping and a separate envmap mask texture are mutually exclusive. + float4 lightAtten : TEXCOORD1; + float4 worldVertToEyeVectorXYZ_tangentSpaceVertToEyeVectorZ : TEXCOORD2; + float3x3 tangentSpaceTranspose : TEXCOORD3; + // second row : TEXCOORD4; + // third row : TEXCOORD5; + float4 worldPos_projPosZ : TEXCOORD6; + float4 fogFactorW : COLOR1; +}; + +float4 main( PS_INPUT i ) : COLOR +{ + bool bBaseTexture = BASETEXTURE ? true : false; + bool bCubemap = CUBEMAP ? true : false; + bool bDiffuseLighting = DIFFUSELIGHTING ? true : false; + bool bNormalMapAlphaEnvmapMask = NORMALMAPALPHAENVMAPMASK ? true : false; + bool bHalfLambert = HALFLAMBERT ? true : false; + bool bFlashlight = (FLASHLIGHT!=0) ? true : false; + bool bAmbientLight = AMBIENT_LIGHT ? true : false; + int nNumLights = NUM_LIGHTS; + + HALF4 baseColor = HALF4( 1.0f, 1.0f, 1.0f, 1.0f ); + if( bBaseTexture ) + baseColor = tex2D( BaseTextureSampler, i.baseTexCoord2_tangentSpaceVertToEyeVectorXY.xy ); + + float specularFactor = 1.0f; + HALF4 normalTexel = tex2D( BumpmapSampler, i.baseTexCoord2_tangentSpaceVertToEyeVectorXY.xy ); + HALF3 tangentSpaceNormal = 2.0f * normalTexel - 1.0f; + + if( bNormalMapAlphaEnvmapMask ) + specularFactor = normalTexel.a; + + HALF3 diffuseLighting = HALF3( 1.0f, 1.0f, 1.0f ); + if( bDiffuseLighting ) + { + float3 worldSpaceNormal = mul( i.tangentSpaceTranspose, tangentSpaceNormal ); + worldSpaceNormal = NormalizeWithCubemap( NormalizeSampler, worldSpaceNormal ); + diffuseLighting = PixelShaderDoLighting( i.worldPos_projPosZ.xyz, worldSpaceNormal, + float3( 0.0f, 0.0f, 0.0f ), false, bAmbientLight, i.lightAtten, + cAmbientCube, NormalizeSampler, nNumLights, cLightInfo, bHalfLambert, + false, 0, false, NormalizeSampler ); + } + + HALF3 albedo = HALF3( 1.0f, 1.0f, 1.0f ); + HALF alpha = 1.0f; + if( bBaseTexture ) + { + albedo *= baseColor; + alpha *= baseColor.a; + } + + // If we only have specularity, assume that we want a black diffuse component, and + // get alpha from the envmapmask + if( !bBaseTexture && bCubemap ) + { + diffuseLighting = HALF3( 0.0f, 0.0f, 0.0f ); + if( bNormalMapAlphaEnvmapMask ) + { + alpha *= specularFactor; + } + } + +#if FLASHLIGHT + if( bFlashlight ) + { + float3 worldSpaceNormal = mul( i.tangentSpaceTranspose, tangentSpaceNormal ); + float4 flashlightSpacePosition = mul( float4( i.worldPos_projPosZ.xyz, 1.0f ), g_FlashlightWorldToTexture ); + + diffuseLighting = DoFlashlight( g_FlashlightPos, i.worldPos_projPosZ.xyz, flashlightSpacePosition, + worldSpaceNormal, g_FlashlightAttenuationFactors.xyz, + g_FlashlightAttenuationFactors.w, FlashlightSampler, + EnvmapMaskSampler, EnvmapMaskSampler, 0, false, false, float2(0, 0), true ); + } +#endif + + diffuseLighting *= g_DiffuseModulation.rgb; + alpha *= g_DiffuseModulation.a; + + HALF3 diffuseComponent = albedo * diffuseLighting; + + HALF4 flowmapSample = tex2D( FlowMapSampler, i.baseTexCoord2_tangentSpaceVertToEyeVectorXY.xy ); +#if !FLASHLIGHT + flowmapSample.xy += float2( .11, .124 ) * g_Time.xx; +#endif + HALF4 selfIllumSample = tex2D( SelfIllumMapSampler, flowmapSample.xy ); + +// float thing = ( 0.5f * ( cos( g_Time * 3 ) + 1.0f ) ); +// diffuseComponent.xyz += albedo * 10.0f * pow( selfIllumSample.xyz, thing ); + diffuseComponent.xyz += albedo * g_SelfIllumTint.xyz * selfIllumSample.xyz; + + HALF3 specularLighting = HALF3( 0.0f, 0.0f, 0.0f ); +#if !FLASHLIGHT + if( bCubemap ) + { + // If we've *only* specified a cubemap, blow off the diffuse component + if ( !bBaseTexture && !bDiffuseLighting && !bFlashlight ) + { + diffuseComponent = HALF3( 0.0f, 0.0f, 0.0f ); + } + + HALF3 worldSpaceNormal = mul( i.tangentSpaceTranspose, tangentSpaceNormal ); + + HALF3 reflectVect = CalcReflectionVectorUnnormalized( worldSpaceNormal, i.worldVertToEyeVectorXYZ_tangentSpaceVertToEyeVectorZ.xyz ); + + specularLighting = ENV_MAP_SCALE * texCUBE( EnvmapSampler, reflectVect ); + specularLighting *= specularFactor; + specularLighting *= g_EnvmapTint; + HALF3 specularLightingSquared = specularLighting * specularLighting; + specularLighting = lerp( specularLighting, specularLightingSquared, g_EnvmapContrast ); + HALF3 greyScale = dot( specularLighting, HALF3( 0.299f, 0.587f, 0.114f ) ); + specularLighting = lerp( greyScale, specularLighting, g_EnvmapSaturation ); + } +#endif + + HALF3 result = diffuseComponent + specularLighting; + + float fogFactor = CalcPixelFogFactor( PIXELFOGTYPE, g_FogParams, g_EyePos.z, i.worldPos_projPosZ.z, i.worldPos_projPosZ.w ); +#if WRITEWATERFOGTODESTALPHA && (PIXELFOGTYPE == PIXEL_FOG_TYPE_HEIGHT) + alpha = fogFactor; +#endif + + + +// result.xyz = float3( 1.0f, 1.0f, 1.0f ); +#if TRANSLUCENT==0 +# if WARPINGIN + alpha = 0.0f; // write alpha where the vortigaunt is so that we can selectivly draw pixels when refracting + #else + alpha = 1.0f; // write alpha where the vortigaunt is so that we can selectivly draw pixels when refracting +# endif +#endif + + //FIXME: need to take dowaterfog into consideration + return FinalOutput( float4( result, alpha ), fogFactor, PIXELFOGTYPE, TONEMAP_SCALE_LINEAR ); +} + diff --git a/materialsystem/stdshaders/vortwarp_vs11.vsh b/materialsystem/stdshaders/vortwarp_vs11.vsh new file mode 100644 index 0000000..e5bb7ca --- /dev/null +++ b/materialsystem/stdshaders/vortwarp_vs11.vsh @@ -0,0 +1,85 @@ +# STATIC: "UNLIT" "0..1" +# STATIC: "HALF_LAMBERT" "0..1" +# DYNAMIC: "LIGHT_COMBO" "0..21" +# DYNAMIC: "SKINNING" "0..1" + +vs.1.1 +#include "macros.vsh" + +$WARPPARAM = $SHADER_SPECIFIC_CONST_2; +$ENTITY_ORIGIN = $SHADER_SPECIFIC_CONST_3; + +;------------------------------------------------------------------------------ +; Vertex blending +;------------------------------------------------------------------------------ +&AllocateRegister( \$worldPos ); +&AllocateRegister( \$worldNormal ); +&AllocateRegister( \$projPos ); + +&SkinPositionAndNormal( $worldPos, $worldNormal ); + +alloc $tmp +sub $tmp.xyz, $worldPos, $ENTITY_ORIGIN +mul $tmp.xy, $tmp, $WARPPARAM +add $worldPos.xyz, $tmp, $ENTITY_ORIGIN +free $tmp + +if( $SKINNING == 1 ) +{ + &Normalize( $worldNormal ); +} + +;------------------------------------------------------------------------------ +; Transform the position from world to view space +;------------------------------------------------------------------------------ +dp4 $projPos.x, $worldPos, $cViewProj0 +dp4 $projPos.y, $worldPos, $cViewProj1 +dp4 $projPos.z, $worldPos, $cViewProj2 +dp4 $projPos.w, $worldPos, $cViewProj3 + +mov oPos, $projPos + +;------------------------------------------------------------------------------ +; Fog - don't bother with water fog for intro effects +;------------------------------------------------------------------------------ +&DepthFog( $projPos, "oFog" ); +&FreeRegister( \$projPos ); + +;------------------------------------------------------------------------------ +; Lighting +;------------------------------------------------------------------------------ +if( $UNLIT ) +{ + mov oD0, $cHalf +} +else +{ + &DoLighting( $worldPos, $worldNormal ); +} + +if( !$envmap ) +{ + &FreeRegister( \$worldNormal ); +} + +;------------------------------------------------------------------------------ +; Texture coordinates +;------------------------------------------------------------------------------ + +dp4 oT0.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_0 +dp4 oT0.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_1 + +alloc $tmp2 + +dp4 $tmp2.x, $vTexCoord0, $SHADER_SPECIFIC_CONST_0 +dp4 $tmp2.y, $vTexCoord0, $SHADER_SPECIFIC_CONST_1 + +add oT1.xy, $tmp2, $SHADER_SPECIFIC_CONST_4 + +free $tmp2 + +; YUCK! This is to make texcoords continuous for mat_softwaretl +mov oT2, $cZero + +&FreeRegister( \$worldPos ); + diff --git a/materialsystem/stdshaders/vortwarp_vs20.fxc b/materialsystem/stdshaders/vortwarp_vs20.fxc new file mode 100644 index 0000000..07d7cbf --- /dev/null +++ b/materialsystem/stdshaders/vortwarp_vs20.fxc @@ -0,0 +1,174 @@ +//======= Copyright (c) 1996-2007, Valve Corporation, All rights reserved. ====== + +// STATIC: "HALFLAMBERT" "0..1" +// STATIC: "USE_STATIC_CONTROL_FLOW" "0..1" [vs20] + +// DYNAMIC: "COMPRESSED_VERTS" "0..1" +// DYNAMIC: "DOWATERFOG" "0..1" +// DYNAMIC: "SKINNING" "0..1" +// DYNAMIC: "MORPHING" "0..1" [vs30] +// DYNAMIC: "NUM_LIGHTS" "0..2" [vs20] + +// If using static control flow on Direct3D, we should use the NUM_LIGHTS=0 combo +// SKIP: $USE_STATIC_CONTROL_FLOW && ( $NUM_LIGHTS > 0 ) [vs20] +// SKIP: $DOWATERFOG + +#include "vortwarp_vs20_helper.h" + +static const bool g_bSkinning = SKINNING ? true : false; +static const int g_FogType = DOWATERFOG; + +const float4 cBaseTexCoordTransform[2] : register( SHADER_SPECIFIC_CONST_0 ); + +const float4 const4 : register( SHADER_SPECIFIC_CONST_4 ); +#define g_Time const4.w +#define modelOrigin const4.xyz + +#ifdef SHADER_MODEL_VS_3_0 +// NOTE: cMorphTargetTextureDim.xy = target dimensions, +// cMorphTargetTextureDim.z = 4tuples/morph +const float3 cMorphTargetTextureDim : register( SHADER_SPECIFIC_CONST_6 ); +const float4 cMorphSubrect : register( SHADER_SPECIFIC_CONST_7 ); + +sampler2D morphSampler : register( D3DVERTEXTEXTURESAMPLER0, s0 ); +#endif + + +//----------------------------------------------------------------------------- +// Input vertex format +//----------------------------------------------------------------------------- +struct VS_INPUT +{ + // This is all of the stuff that we ever use. + float4 vPos : POSITION; + float4 vBoneWeights : BLENDWEIGHT; + float4 vBoneIndices : BLENDINDICES; + float4 vNormal : NORMAL; + float4 vColor : COLOR0; + float3 vSpecular : COLOR1; + // make these float2's and stick the [n n 0 1] in the dot math. + float4 vTexCoord0 : TEXCOORD0; + float4 vTexCoord1 : TEXCOORD1; + float4 vTexCoord2 : TEXCOORD2; + float4 vTexCoord3 : TEXCOORD3; + float3 vTangentS : TANGENT; + float3 vTangentT : BINORMAL; + float4 vUserData : TANGENT; + + // Position and normal/tangent deltas + float3 vPosFlex : POSITION1; + float3 vNormalFlex : NORMAL1; +#ifdef SHADER_MODEL_VS_3_0 + float vVertexID : POSITION2; +#endif +}; + + +//----------------------------------------------------------------------------- +// Output vertex format +//----------------------------------------------------------------------------- +struct VS_OUTPUT +{ + float4 projPos : POSITION; +#if !defined( _X360 ) + float fog : FOG; +#endif + + HALF4 baseTexCoord2_tangentSpaceVertToEyeVectorXY : TEXCOORD0; + // bump mapping and a separate envmap mask texture are mutually exclusive. + float4 lightAtten : TEXCOORD1; + float4 worldVertToEyeVectorXYZ_tangentSpaceVertToEyeVectorZ : TEXCOORD2; + float3x3 tangentSpaceTranspose : TEXCOORD3; + // second row : TEXCOORD4; + // third row : TEXCOORD5; + float4 worldPos_projPosZ : TEXCOORD6; + float4 fogFactorW : COLOR1; +}; + +//----------------------------------------------------------------------------- +// Main shader entry point +//----------------------------------------------------------------------------- +VS_OUTPUT main( const VS_INPUT v ) +{ + VS_OUTPUT o = ( VS_OUTPUT )0; + + float4 vPosition = v.vPos; + float3 vNormal; + float4 vTangent; + + DecompressVertex_NormalTangent( v.vNormal, v.vUserData, vNormal, vTangent ); + +#if !defined( SHADER_MODEL_VS_3_0 ) || !MORPHING + ApplyMorph( v.vPosFlex, v.vNormalFlex, vPosition.xyz, vNormal, vTangent.xyz ); +#else + ApplyMorph( morphSampler, cMorphTargetTextureDim, cMorphSubrect, v.vVertexID, float3( 0, 0, 0 ), + vPosition.xyz, vNormal, vTangent.xyz ); +#endif + + // Perform skinning + float3 worldNormal, worldPos, worldTangentS, worldTangentT; + SkinPositionNormalAndTangentSpace( + g_bSkinning, + vPosition, vNormal, vTangent, + v.vBoneWeights, v.vBoneIndices, + worldPos, worldNormal, worldTangentS, worldTangentT ); + + WorldSpaceVertexProcess( g_Time, modelOrigin, worldPos, worldNormal, worldTangentS, worldTangentT ); + + // Always normalize since flex path is controlled by runtime + // constant not a shader combo and will always generate the normalization + worldNormal = normalize( worldNormal ); + worldTangentS = normalize( worldTangentS ); + worldTangentT = normalize( worldTangentT ); + + // Transform into projection space + float4 projPos = mul( float4( worldPos, 1 ), cViewProj ); + o.projPos = projPos; + projPos.z = mul( float4( worldPos, 1 ), cViewProjZ ); + o.fogFactorW = CalcFog( worldPos, projPos, g_FogType ); +#if !defined( _X360 ) + o.fog = o.fogFactorW; +#endif + // Needed for water fog alpha and diffuse lighting + // FIXME: we shouldn't have to compute this all the time. + o.worldPos_projPosZ = float4( worldPos, projPos.z ); + + // Needed for cubemapping + parallax mapping + // FIXME: We shouldn't have to compute this all the time. + o.worldVertToEyeVectorXYZ_tangentSpaceVertToEyeVectorZ.xyz = VSHADER_VECT_SCALE * (cEyePos - worldPos); + +#if defined ( SHADER_MODEL_VS_2_0 ) && ( !USE_STATIC_CONTROL_FLOW ) + o.lightAtten = float4(0,0,0,0); + #if ( NUM_LIGHTS > 0 ) + o.lightAtten.x = GetVertexAttenForLight( worldPos, 0, false ); + #endif + #if ( NUM_LIGHTS > 1 ) + o.lightAtten.y = GetVertexAttenForLight( worldPos, 1, false ); + #endif + #if ( NUM_LIGHTS > 2 ) + o.lightAtten.z = GetVertexAttenForLight( worldPos, 2, false ); + #endif + #if ( NUM_LIGHTS > 3 ) + o.lightAtten.w = GetVertexAttenForLight( worldPos, 3, false ); + #endif +#else + // Scalar light attenuation + o.lightAtten.x = GetVertexAttenForLight( worldPos, 0, true ); + o.lightAtten.y = GetVertexAttenForLight( worldPos, 1, true ); + o.lightAtten.z = GetVertexAttenForLight( worldPos, 2, true ); + o.lightAtten.w = GetVertexAttenForLight( worldPos, 3, true ); +#endif + + // Base texture coordinate transform + o.baseTexCoord2_tangentSpaceVertToEyeVectorXY.x = dot( v.vTexCoord0, cBaseTexCoordTransform[0] ); + o.baseTexCoord2_tangentSpaceVertToEyeVectorXY.y = dot( v.vTexCoord0, cBaseTexCoordTransform[1] ); + + // Tangent space transform + o.tangentSpaceTranspose[0] = float3( worldTangentS.x, worldTangentT.x, worldNormal.x ); + o.tangentSpaceTranspose[1] = float3( worldTangentS.y, worldTangentT.y, worldNormal.y ); + o.tangentSpaceTranspose[2] = float3( worldTangentS.z, worldTangentT.z, worldNormal.z ); + + return o; +} + + diff --git a/materialsystem/stdshaders/vortwarp_vs20_helper.h b/materialsystem/stdshaders/vortwarp_vs20_helper.h new file mode 100644 index 0000000..f2cc2ad --- /dev/null +++ b/materialsystem/stdshaders/vortwarp_vs20_helper.h @@ -0,0 +1,42 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +#include "common_vs_fxc.h" + +float Sine( float min, float max, float t ) +{ + return ( sin( t ) * 0.5f + 0.5f ) * ( max - min ) + min; +} + +float3 QuadraticBezier( float3 A, float3 B, float3 C, float t ) +{ + return lerp( lerp( A, B, t ), lerp( B, C, t ), t ); +} + +float3 CubicBezier( float3 A, float3 B, float3 C, float3 D, float t ) +{ + return QuadraticBezier( lerp( A, B, t ), lerp( B, C, t ), lerp( C, D, t ), t ); +} + +void WorldSpaceVertexProcess( in float time, in float3 modelOrigin, inout float3 worldPos, inout float3 worldNormal, inout float3 worldTangentS, inout float3 worldTangentT ) +{ + float myTime = time; + myTime = saturate( 1.0f - myTime ); + myTime *= myTime; + myTime *= myTime; + myTime *= myTime; +// worldPos.z += 72.0f * myTime; + + // end + float3 A = float3( 0.0f, 0.0f, 1.0f ); + float3 B = float3( 1.0f, 1.0f, 1.0f ); + float3 C = float3( 0.0f, 0.0f, 1.0f ); + float3 D = float3( 0.0f, 0.0f, 1.0f ); + // start + +// float3 modelOrigin = float3( 70.0f, -14.0f, 0.0f ); + + float t = worldPos.z * ( 1.0f / ( 72.0f ) ); // about 72 inches tall + t = saturate( t ); + float3 worldPosDelta = ( worldPos - modelOrigin ) * CubicBezier( A, B, C, D, t ); + worldPosDelta.z += Sine( 0.0f, 10.0, worldPos.z ); + worldPos = lerp( worldPos, worldPosDelta + modelOrigin, myTime ); +} diff --git a/materialsystem/stdshaders/vr_distort_hud.cpp b/materialsystem/stdshaders/vr_distort_hud.cpp new file mode 100644 index 0000000..b78a3e5 --- /dev/null +++ b/materialsystem/stdshaders/vr_distort_hud.cpp @@ -0,0 +1,224 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//============================================================================= + +#include "BaseVSShader.h" +#include "commandbuilder.h" + +#include "vr_distort_hud_ps20.inc" +#include "vr_distort_hud_ps20b.inc" +#include "vr_distort_hud_vs20.inc" +#include "vr_distort_hud_ps30.inc" +#include "vr_distort_hud_vs30.inc" + +#include "../materialsystem_global.h" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + + +class CVRDistortTexture_DX9_Context : public CBasePerMaterialContextData +{ +public: + uint8 *m_pStaticCmds; + CCommandBufferBuilder< CFixedCommandStorageBuffer< 1000 > > m_SemiStaticCmdsOut; + + void ResetStaticCmds( void ) + { + if ( m_pStaticCmds ) + { + delete[] m_pStaticCmds; + m_pStaticCmds = NULL; + } + } + + CVRDistortTexture_DX9_Context( void ) + { + m_pStaticCmds = NULL; + } + + ~CVRDistortTexture_DX9_Context( void ) + { + ResetStaticCmds(); + } + +}; + + +BEGIN_VS_SHADER( vr_distort_hud, "Help for hud warp" ) + BEGIN_SHADER_PARAMS + + SHADER_PARAM( BASETEXTURE, SHADER_PARAM_TYPE_TEXTURE, "_rt_gui", "" ) + SHADER_PARAM( DISTORTMAP, SHADER_PARAM_TYPE_TEXTURE, "vr_distort_map_left", "" ) + SHADER_PARAM( DISTORTBOUNDS, SHADER_PARAM_TYPE_VEC4, "[ 0 0 1 1 ]", "" ) + SHADER_PARAM( HUDTRANSLUCENT, SHADER_PARAM_TYPE_INTEGER, "0", "" ) + SHADER_PARAM( HUDUNDISTORT, SHADER_PARAM_TYPE_INTEGER, "0", "" ) + + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + } + + SHADER_FALLBACK + { + return 0; + } + + SHADER_INIT + { + LoadTexture( BASETEXTURE, TEXTUREFLAGS_SRGB ); + LoadTexture( DISTORTMAP, TEXTUREFLAGS_NOMIP | TEXTUREFLAGS_NOLOD | TEXTUREFLAGS_NODEBUGOVERRIDE | TEXTUREFLAGS_SINGLECOPY | + TEXTUREFLAGS_CLAMPS | TEXTUREFLAGS_CLAMPT ); + } + + SHADER_DRAW + { + CVRDistortTexture_DX9_Context *pContextData = reinterpret_cast< CVRDistortTexture_DX9_Context *> ( *pContextDataPtr ); + bool bNeedRegenStaticCmds = ( !pContextData ) || pShaderShadow; + + if ( !pContextData ) // make sure allocated + { + pContextData = new CVRDistortTexture_DX9_Context; + *pContextDataPtr = pContextData; + } + + if ( pShaderShadow || bNeedRegenStaticCmds ) + { + pContextData->ResetStaticCmds(); + CCommandBufferBuilder< CFixedCommandStorageBuffer< 5000 > > staticCmdsBuf; + + staticCmdsBuf.BindTexture( this, SHADER_SAMPLER0, BASETEXTURE, -1 ); + staticCmdsBuf.BindTexture( this, SHADER_SAMPLER1, DISTORTMAP, -1 ); + + staticCmdsBuf.End(); + + // now, copy buf + pContextData->m_pStaticCmds = new uint8[ staticCmdsBuf.Size() ]; + memcpy( pContextData->m_pStaticCmds, staticCmdsBuf.Base(), staticCmdsBuf.Size() ); + } + + if ( pShaderAPI && pContextData->m_bMaterialVarsChanged ) + { + // need to regenerate the semistatic cmds + pContextData->m_SemiStaticCmdsOut.Reset(); + pContextData->m_bMaterialVarsChanged = false; + + pContextData->m_SemiStaticCmdsOut.SetAmbientCubeDynamicStateVertexShader(); + pContextData->m_SemiStaticCmdsOut.End(); + } + + SHADOW_STATE + { + SetInitialShadowState( ); + + pShaderShadow->EnableDepthWrites( false ); + pShaderShadow->EnableDepthTest( false ); + + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, true ); + + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + + pShaderShadow->EnableSRGBWrite( true ); + pShaderShadow->EnableAlphaWrites( false ); + + pShaderShadow->AlphaFunc( SHADER_ALPHAFUNC_GREATER, 0.0f ); + + if ( IS_FLAG_SET( MATERIAL_VAR_TRANSLUCENT ) ) + { + pShaderShadow->EnableAlphaTest( true ); + pShaderShadow->EnableBlending( true ); + pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA ); + } + else + { + pShaderShadow->EnableAlphaTest( false ); + pShaderShadow->EnableBlending( false ); + pShaderShadow->BlendFunc( SHADER_BLEND_ONE, SHADER_BLEND_ZERO ); + } + + DefaultFog(); + + int nFormat = 0; + nFormat |= VERTEX_POSITION; + pShaderShadow->VertexShaderVertexFormat( nFormat, 2, 0, 0 ); + + if ( !g_pHardwareConfig->SupportsShaderModel_3_0() ) + { + DECLARE_STATIC_VERTEX_SHADER( vr_distort_hud_vs20 ); + SET_STATIC_VERTEX_SHADER( vr_distort_hud_vs20 ); + + if ( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_STATIC_PIXEL_SHADER( vr_distort_hud_ps20b ); + SET_STATIC_PIXEL_SHADER( vr_distort_hud_ps20b ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( vr_distort_hud_ps20 ); + SET_STATIC_PIXEL_SHADER( vr_distort_hud_ps20 ); + } + } + else + { + DECLARE_STATIC_VERTEX_SHADER( vr_distort_hud_vs30 ); + SET_STATIC_VERTEX_SHADER( vr_distort_hud_vs30 ); + + DECLARE_STATIC_PIXEL_SHADER( vr_distort_hud_ps30 ); + SET_STATIC_PIXEL_SHADER( vr_distort_hud_ps30 ); + } + } + + DYNAMIC_STATE + { + CCommandBufferBuilder< CFixedCommandStorageBuffer< 1000 > > DynamicCmdsOut; + DynamicCmdsOut.Call( pContextData->m_pStaticCmds ); + DynamicCmdsOut.Call( pContextData->m_SemiStaticCmdsOut.Base() ); + + pShaderAPI->SetDefaultState(); + + SetPixelShaderConstant( 0, DISTORTBOUNDS ); + SetPixelShaderConstant( 1, HUDTRANSLUCENT ); + + int hudUndistortEnabled = ( params[ HUDUNDISTORT ]->GetIntValue() == 0 ) ? 0 : 1; + + if ( !g_pHardwareConfig->SupportsShaderModel_3_0() ) + { + DECLARE_DYNAMIC_VERTEX_SHADER( vr_distort_hud_vs20 ); + SET_DYNAMIC_VERTEX_SHADER( vr_distort_hud_vs20 ); + + if ( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_DYNAMIC_PIXEL_SHADER( vr_distort_hud_ps20b ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( CMBO_HUDUNDISTORT, hudUndistortEnabled ); + SET_DYNAMIC_PIXEL_SHADER( vr_distort_hud_ps20b ); + } + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( vr_distort_hud_ps20 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( CMBO_HUDUNDISTORT, hudUndistortEnabled ); + SET_DYNAMIC_PIXEL_SHADER( vr_distort_hud_ps20 ); + } + } + else + { + DECLARE_DYNAMIC_VERTEX_SHADER( vr_distort_hud_vs30 ); + SET_DYNAMIC_VERTEX_SHADER( vr_distort_hud_vs30 ); + + DECLARE_DYNAMIC_PIXEL_SHADER( vr_distort_hud_ps30 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( CMBO_HUDUNDISTORT, hudUndistortEnabled ); + SET_DYNAMIC_PIXEL_SHADER( vr_distort_hud_ps30 ); + } + + DynamicCmdsOut.End(); + pShaderAPI->ExecuteCommandBuffer( DynamicCmdsOut.Base() ); + } + + Draw(); + + } +END_SHADER diff --git a/materialsystem/stdshaders/vr_distort_hud_ps2x.fxc b/materialsystem/stdshaders/vr_distort_hud_ps2x.fxc new file mode 100644 index 0000000..331c189 --- /dev/null +++ b/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; +} diff --git a/materialsystem/stdshaders/vr_distort_hud_vs20.fxc b/materialsystem/stdshaders/vr_distort_hud_vs20.fxc new file mode 100644 index 0000000..b82bfa1 --- /dev/null +++ b/materialsystem/stdshaders/vr_distort_hud_vs20.fxc @@ -0,0 +1,26 @@ +#include "common_vs_fxc.h" + + +struct VS_INPUT +{ + float4 vPos : POSITION; + float2 vBaseTexCoord : TEXCOORD0; +}; + + +struct VS_OUTPUT +{ + float4 vProjPos : POSITION; + float2 vBaseTexCoord : TEXCOORD0; +}; + + +VS_OUTPUT main( const VS_INPUT v ) +{ + VS_OUTPUT o; + + o.vProjPos = v.vPos; + o.vBaseTexCoord = v.vBaseTexCoord; + + return o; +} diff --git a/materialsystem/stdshaders/vr_distort_texture.cpp b/materialsystem/stdshaders/vr_distort_texture.cpp new file mode 100644 index 0000000..1e87d72 --- /dev/null +++ b/materialsystem/stdshaders/vr_distort_texture.cpp @@ -0,0 +1,213 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//============================================================================= + +#include "BaseVSShader.h" +#include "commandbuilder.h" + +#include "vr_distort_texture_ps20.inc" +#include "vr_distort_texture_ps20b.inc" +#include "vr_distort_texture_vs20.inc" +#include "vr_distort_texture_ps30.inc" +#include "vr_distort_texture_vs30.inc" + +#include "../materialsystem_global.h" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + + + + + + + +class CVRDistortTexture_DX9_Context : public CBasePerMaterialContextData +{ +public: + uint8 *m_pStaticCmds; + CCommandBufferBuilder< CFixedCommandStorageBuffer< 1000 > > m_SemiStaticCmdsOut; + + void ResetStaticCmds( void ) + { + if ( m_pStaticCmds ) + { + delete[] m_pStaticCmds; + m_pStaticCmds = NULL; + } + } + + CVRDistortTexture_DX9_Context( void ) + { + m_pStaticCmds = NULL; + } + + ~CVRDistortTexture_DX9_Context( void ) + { + ResetStaticCmds(); + } + +}; + + +static const float kAllZeros[ 4 ] = { 0.0f, 0.0f, 0.0f, 0.0f }; + + +BEGIN_VS_SHADER( vr_distort_texture, "Help for warp" ) + BEGIN_SHADER_PARAMS + + SHADER_PARAM( BASETEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "" ) + SHADER_PARAM( DISTORTMAP, SHADER_PARAM_TYPE_TEXTURE, "vr_distort_map", "" ) + SHADER_PARAM( USERENDERTARGET, SHADER_PARAM_TYPE_INTEGER, "0", "" ) + + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + } + + SHADER_FALLBACK + { + return 0; + } + + SHADER_INIT + { + LoadTexture( BASETEXTURE, TEXTUREFLAGS_SRGB ); + LoadTexture( DISTORTMAP, TEXTUREFLAGS_NOMIP | TEXTUREFLAGS_NOLOD | TEXTUREFLAGS_NODEBUGOVERRIDE | + TEXTUREFLAGS_SINGLECOPY | TEXTUREFLAGS_CLAMPS | TEXTUREFLAGS_CLAMPT ); + } + + SHADER_DRAW + { + CVRDistortTexture_DX9_Context *pContextData = reinterpret_cast< CVRDistortTexture_DX9_Context *> ( *pContextDataPtr ); + bool bNeedRegenStaticCmds = ( !pContextData ) || pShaderShadow; + + if ( !pContextData ) // make sure allocated + { + pContextData = new CVRDistortTexture_DX9_Context; + *pContextDataPtr = pContextData; + } + + if ( pShaderShadow || bNeedRegenStaticCmds ) + { + pContextData->ResetStaticCmds(); + CCommandBufferBuilder< CFixedCommandStorageBuffer< 5000 > > staticCmdsBuf; + + staticCmdsBuf.BindTexture( this, SHADER_SAMPLER0, BASETEXTURE, -1 ); + staticCmdsBuf.BindTexture( this, SHADER_SAMPLER1, DISTORTMAP, -1 ); + + staticCmdsBuf.End(); + + // now, copy buf + pContextData->m_pStaticCmds = new uint8[ staticCmdsBuf.Size() ]; + memcpy( pContextData->m_pStaticCmds, staticCmdsBuf.Base(), staticCmdsBuf.Size() ); + } + + if ( pShaderAPI && pContextData->m_bMaterialVarsChanged ) + { + // need to regenerate the semistatic cmds + pContextData->m_SemiStaticCmdsOut.Reset(); + pContextData->m_bMaterialVarsChanged = false; + + pContextData->m_SemiStaticCmdsOut.SetAmbientCubeDynamicStateVertexShader(); + pContextData->m_SemiStaticCmdsOut.End(); + } + + SHADOW_STATE + { + SetInitialShadowState( ); + + pShaderShadow->EnableDepthWrites( false ); + pShaderShadow->EnableDepthTest( false ); + + pShaderShadow->EnableBlending( false ); + + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, true ); + + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + + pShaderShadow->EnableSRGBWrite( true ); + pShaderShadow->EnableAlphaWrites( false ); + pShaderShadow->EnableAlphaTest( false ); + + DefaultFog(); + + int nFormat = 0; + nFormat |= VERTEX_POSITION; + pShaderShadow->VertexShaderVertexFormat( nFormat, 2, 0, 0 ); + + if ( !g_pHardwareConfig->SupportsShaderModel_3_0() ) + { + DECLARE_STATIC_VERTEX_SHADER( vr_distort_texture_vs20 ); + SET_STATIC_VERTEX_SHADER( vr_distort_texture_vs20 ); + + if ( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_STATIC_PIXEL_SHADER( vr_distort_texture_ps20b ); + SET_STATIC_PIXEL_SHADER( vr_distort_texture_ps20b ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( vr_distort_texture_ps20 ); + SET_STATIC_PIXEL_SHADER( vr_distort_texture_ps20 ); + } + } + else + { + DECLARE_STATIC_VERTEX_SHADER( vr_distort_texture_vs30 ); + SET_STATIC_VERTEX_SHADER( vr_distort_texture_vs30 ); + + DECLARE_STATIC_PIXEL_SHADER( vr_distort_texture_ps30 ); + SET_STATIC_PIXEL_SHADER( vr_distort_texture_ps30 ); + } + } + + DYNAMIC_STATE + { + CCommandBufferBuilder< CFixedCommandStorageBuffer< 1000 > > DynamicCmdsOut; + DynamicCmdsOut.Call( pContextData->m_pStaticCmds ); + DynamicCmdsOut.Call( pContextData->m_SemiStaticCmdsOut.Base() ); + + pShaderAPI->SetDefaultState(); + + int useRenderTarget = ( params[ USERENDERTARGET ]->GetIntValue() == 0 ) ? 0 : 1; + + if ( !g_pHardwareConfig->SupportsShaderModel_3_0() ) + { + DECLARE_DYNAMIC_VERTEX_SHADER( vr_distort_texture_vs20 ); + SET_DYNAMIC_VERTEX_SHADER( vr_distort_texture_vs20 ); + + if ( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_DYNAMIC_PIXEL_SHADER( vr_distort_texture_ps20b ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( CMBO_USERENDERTARGET, useRenderTarget ); + SET_DYNAMIC_PIXEL_SHADER( vr_distort_texture_ps20b ); + } + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( vr_distort_texture_ps20 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( CMBO_USERENDERTARGET, useRenderTarget ); + SET_DYNAMIC_PIXEL_SHADER( vr_distort_texture_ps20 ); + } + } + else + { + DECLARE_DYNAMIC_VERTEX_SHADER( vr_distort_texture_vs30 ); + SET_DYNAMIC_VERTEX_SHADER( vr_distort_texture_vs30 ); + + DECLARE_DYNAMIC_PIXEL_SHADER( vr_distort_texture_ps30 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( CMBO_USERENDERTARGET, useRenderTarget ); + SET_DYNAMIC_PIXEL_SHADER( vr_distort_texture_ps30 ); + } + + DynamicCmdsOut.End(); + pShaderAPI->ExecuteCommandBuffer( DynamicCmdsOut.Base() ); + } + Draw(); + } +END_SHADER diff --git a/materialsystem/stdshaders/vr_distort_texture_ps2x.fxc b/materialsystem/stdshaders/vr_distort_texture_ps2x.fxc new file mode 100644 index 0000000..23ff3f5 --- /dev/null +++ b/materialsystem/stdshaders/vr_distort_texture_ps2x.fxc @@ -0,0 +1,49 @@ +// DYNAMIC: "CMBO_USERENDERTARGET" "0..1" + +#include "shader_constant_register_map.h" +#include "common_ps_fxc.h" + +sampler BaseTextureSampler : register( s0 ); +sampler DistortMapTextureSampler : register( s1 ); + + +struct PS_INPUT +{ + float2 vBaseTexCoord : TEXCOORD0; +}; + + +float4 main( PS_INPUT i ) : COLOR +{ + float2 vOriginal = i.vBaseTexCoord.xy; + + float4 vRead = tex2D( DistortMapTextureSampler, vOriginal ); + + float2 vGreen; + vGreen.r = ( vRead.x + vRead.z ) / 2.0; + vGreen.g = ( vRead.y + vRead.w ) / 2.0; + + float4 vFinal; + vFinal.r = tex2D( BaseTextureSampler, vRead.xy ).r; + vFinal.ga = tex2D( BaseTextureSampler, vGreen ).ga; + vFinal.b = tex2D( BaseTextureSampler, vRead.zw ).b; + + float fBoundsCheck; + #if ( CMBO_USERENDERTARGET ) + { + fBoundsCheck = saturate( dot( (vGreen.xy < float2(0.01,0.01)), float2(1,1)) + dot( (vGreen.xy > float2(0.99,0.99)), float2(1,1)) ); + } + #else + { + fBoundsCheck = saturate( dot( (vGreen.xy < float2(0.005,0.005)), float2(1,1)) + dot( (vGreen.xy > float2(0.995,0.995)), float2(1,1)) + + (vGreen.x > 0.495 && vGreen.x < 0.505 ) ); + } + #endif + + vFinal.xyz = lerp( vFinal.xyz, float3(0,0,0), fBoundsCheck ); + + return vFinal; +} + + + diff --git a/materialsystem/stdshaders/vr_distort_texture_vs20.fxc b/materialsystem/stdshaders/vr_distort_texture_vs20.fxc new file mode 100644 index 0000000..b82bfa1 --- /dev/null +++ b/materialsystem/stdshaders/vr_distort_texture_vs20.fxc @@ -0,0 +1,26 @@ +#include "common_vs_fxc.h" + + +struct VS_INPUT +{ + float4 vPos : POSITION; + float2 vBaseTexCoord : TEXCOORD0; +}; + + +struct VS_OUTPUT +{ + float4 vProjPos : POSITION; + float2 vBaseTexCoord : TEXCOORD0; +}; + + +VS_OUTPUT main( const VS_INPUT v ) +{ + VS_OUTPUT o; + + o.vProjPos = v.vPos; + o.vBaseTexCoord = v.vBaseTexCoord; + + return o; +} diff --git a/materialsystem/stdshaders/vshtmp9/BufferClearObeyStencil_vs11.inc b/materialsystem/stdshaders/vshtmp9/BufferClearObeyStencil_vs11.inc new file mode 100644 index 0000000..ed1aab9 --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9/BufferClearObeyStencil_vs11.inc @@ -0,0 +1,30 @@ +class bufferclearobeystencil_vs11_Static_Index +{ +public: + bufferclearobeystencil_vs11_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class bufferclearobeystencil_vs11_Dynamic_Index +{ +public: + bufferclearobeystencil_vs11_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9/BumpmappedEnvmap.inc b/materialsystem/stdshaders/vshtmp9/BumpmappedEnvmap.inc new file mode 100644 index 0000000..a177a09 --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9/BumpmappedEnvmap.inc @@ -0,0 +1,57 @@ +class bumpmappedenvmap_Static_Index +{ +public: + bumpmappedenvmap_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class bumpmappedenvmap_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + bumpmappedenvmap_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9/BumpmappedLightmap.inc b/materialsystem/stdshaders/vshtmp9/BumpmappedLightmap.inc new file mode 100644 index 0000000..45c30c4 --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9/BumpmappedLightmap.inc @@ -0,0 +1,57 @@ +class bumpmappedlightmap_Static_Index +{ +public: + bumpmappedlightmap_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class bumpmappedlightmap_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + bumpmappedlightmap_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9/Cable.inc b/materialsystem/stdshaders/vshtmp9/Cable.inc new file mode 100644 index 0000000..b86952d --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9/Cable.inc @@ -0,0 +1,57 @@ +class cable_Static_Index +{ +public: + cable_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class cable_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + cable_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9/DebugTangentSpace.inc b/materialsystem/stdshaders/vshtmp9/DebugTangentSpace.inc new file mode 100644 index 0000000..4587dea --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9/DebugTangentSpace.inc @@ -0,0 +1,82 @@ +class debugtangentspace_Static_Index +{ +public: + debugtangentspace_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class debugtangentspace_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +public: + debugtangentspace_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG && m_bSKINNING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + ( 2 * m_nSKINNING ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9/Eyes.inc b/materialsystem/stdshaders/vshtmp9/Eyes.inc new file mode 100644 index 0000000..db49b5a --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9/Eyes.inc @@ -0,0 +1,134 @@ +class eyes_Static_Index +{ +private: + int m_nHALF_LAMBERT; +#ifdef _DEBUG + bool m_bHALF_LAMBERT; +#endif +public: + void SetHALF_LAMBERT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHALF_LAMBERT = i; +#ifdef _DEBUG + m_bHALF_LAMBERT = true; +#endif + } + void SetHALF_LAMBERT( bool i ) + { + m_nHALF_LAMBERT = i ? 1 : 0; +#ifdef _DEBUG + m_bHALF_LAMBERT = true; +#endif + } +public: + eyes_Static_Index() + { +#ifdef _DEBUG + m_bHALF_LAMBERT = false; +#endif // _DEBUG + m_nHALF_LAMBERT = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bHALF_LAMBERT; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 88 * m_nHALF_LAMBERT ) + 0; + } +}; +class eyes_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nLIGHT_COMBO; +#ifdef _DEBUG + bool m_bLIGHT_COMBO; +#endif +public: + void SetLIGHT_COMBO( int i ) + { + Assert( i >= 0 && i <= 21 ); + m_nLIGHT_COMBO = i; +#ifdef _DEBUG + m_bLIGHT_COMBO = true; +#endif + } + void SetLIGHT_COMBO( bool i ) + { + m_nLIGHT_COMBO = i ? 1 : 0; +#ifdef _DEBUG + m_bLIGHT_COMBO = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +public: + eyes_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bLIGHT_COMBO = false; +#endif // _DEBUG + m_nLIGHT_COMBO = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG && m_bLIGHT_COMBO && m_bSKINNING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + ( 2 * m_nLIGHT_COMBO ) + ( 44 * m_nSKINNING ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9/JellyFish.inc b/materialsystem/stdshaders/vshtmp9/JellyFish.inc new file mode 100644 index 0000000..3e8c7ee --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9/JellyFish.inc @@ -0,0 +1,82 @@ +class jellyfish_Static_Index +{ +public: + jellyfish_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class jellyfish_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +public: + jellyfish_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG && m_bSKINNING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + ( 2 * m_nSKINNING ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9/Jojirium.inc b/materialsystem/stdshaders/vshtmp9/Jojirium.inc new file mode 100644 index 0000000..464b594 --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9/Jojirium.inc @@ -0,0 +1,57 @@ +class jojirium_Static_Index +{ +public: + jojirium_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class jojirium_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + jojirium_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9/LightingOnly.inc b/materialsystem/stdshaders/vshtmp9/LightingOnly.inc new file mode 100644 index 0000000..393a67e --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9/LightingOnly.inc @@ -0,0 +1,134 @@ +class lightingonly_Static_Index +{ +private: + int m_nHALF_LAMBERT; +#ifdef _DEBUG + bool m_bHALF_LAMBERT; +#endif +public: + void SetHALF_LAMBERT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHALF_LAMBERT = i; +#ifdef _DEBUG + m_bHALF_LAMBERT = true; +#endif + } + void SetHALF_LAMBERT( bool i ) + { + m_nHALF_LAMBERT = i ? 1 : 0; +#ifdef _DEBUG + m_bHALF_LAMBERT = true; +#endif + } +public: + lightingonly_Static_Index() + { +#ifdef _DEBUG + m_bHALF_LAMBERT = false; +#endif // _DEBUG + m_nHALF_LAMBERT = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bHALF_LAMBERT; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 88 * m_nHALF_LAMBERT ) + 0; + } +}; +class lightingonly_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nLIGHT_COMBO; +#ifdef _DEBUG + bool m_bLIGHT_COMBO; +#endif +public: + void SetLIGHT_COMBO( int i ) + { + Assert( i >= 0 && i <= 21 ); + m_nLIGHT_COMBO = i; +#ifdef _DEBUG + m_bLIGHT_COMBO = true; +#endif + } + void SetLIGHT_COMBO( bool i ) + { + m_nLIGHT_COMBO = i ? 1 : 0; +#ifdef _DEBUG + m_bLIGHT_COMBO = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +public: + lightingonly_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bLIGHT_COMBO = false; +#endif // _DEBUG + m_nLIGHT_COMBO = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG && m_bLIGHT_COMBO && m_bSKINNING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + ( 2 * m_nLIGHT_COMBO ) + ( 44 * m_nSKINNING ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9/LightmappedGeneric_BaseTexture.inc b/materialsystem/stdshaders/vshtmp9/LightmappedGeneric_BaseTexture.inc new file mode 100644 index 0000000..3df8215 --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9/LightmappedGeneric_BaseTexture.inc @@ -0,0 +1,57 @@ +class lightmappedgeneric_basetexture_Static_Index +{ +public: + lightmappedgeneric_basetexture_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class lightmappedgeneric_basetexture_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + lightmappedgeneric_basetexture_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9/LightmappedGeneric_BumpmappedLightmap_Base_ps14.inc b/materialsystem/stdshaders/vshtmp9/LightmappedGeneric_BumpmappedLightmap_Base_ps14.inc new file mode 100644 index 0000000..f0d6d24 --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9/LightmappedGeneric_BumpmappedLightmap_Base_ps14.inc @@ -0,0 +1,57 @@ +class lightmappedgeneric_bumpmappedlightmap_base_ps14_Static_Index +{ +public: + lightmappedgeneric_bumpmappedlightmap_base_ps14_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class lightmappedgeneric_bumpmappedlightmap_base_ps14_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + lightmappedgeneric_bumpmappedlightmap_base_ps14_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9/LightmappedGeneric_BumpmappedLightmap_Blend_ps14.inc b/materialsystem/stdshaders/vshtmp9/LightmappedGeneric_BumpmappedLightmap_Blend_ps14.inc new file mode 100644 index 0000000..119a92a --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9/LightmappedGeneric_BumpmappedLightmap_Blend_ps14.inc @@ -0,0 +1,57 @@ +class lightmappedgeneric_bumpmappedlightmap_blend_ps14_Static_Index +{ +public: + lightmappedgeneric_bumpmappedlightmap_blend_ps14_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class lightmappedgeneric_bumpmappedlightmap_blend_ps14_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + lightmappedgeneric_bumpmappedlightmap_blend_ps14_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9/LightmappedGeneric_Decal.inc b/materialsystem/stdshaders/vshtmp9/LightmappedGeneric_Decal.inc new file mode 100644 index 0000000..1c0a730 --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9/LightmappedGeneric_Decal.inc @@ -0,0 +1,57 @@ +class lightmappedgeneric_decal_Static_Index +{ +public: + lightmappedgeneric_decal_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class lightmappedgeneric_decal_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + lightmappedgeneric_decal_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9/LightmappedGeneric_LightingOnly.inc b/materialsystem/stdshaders/vshtmp9/LightmappedGeneric_LightingOnly.inc new file mode 100644 index 0000000..f929467 --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9/LightmappedGeneric_LightingOnly.inc @@ -0,0 +1,57 @@ +class lightmappedgeneric_lightingonly_Static_Index +{ +public: + lightmappedgeneric_lightingonly_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class lightmappedgeneric_lightingonly_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + lightmappedgeneric_lightingonly_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9/Refract_model_vs11.inc b/materialsystem/stdshaders/vshtmp9/Refract_model_vs11.inc new file mode 100644 index 0000000..7d34b9e --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9/Refract_model_vs11.inc @@ -0,0 +1,82 @@ +class refract_model_vs11_Static_Index +{ +public: + refract_model_vs11_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class refract_model_vs11_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +public: + refract_model_vs11_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG && m_bSKINNING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + ( 2 * m_nSKINNING ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9/Refract_world_vs11.inc b/materialsystem/stdshaders/vshtmp9/Refract_world_vs11.inc new file mode 100644 index 0000000..b5e6997 --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9/Refract_world_vs11.inc @@ -0,0 +1,57 @@ +class refract_world_vs11_Static_Index +{ +public: + refract_world_vs11_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class refract_world_vs11_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + refract_world_vs11_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9/ScreenSpaceEffect.inc b/materialsystem/stdshaders/vshtmp9/ScreenSpaceEffect.inc new file mode 100644 index 0000000..6b44278 --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9/ScreenSpaceEffect.inc @@ -0,0 +1,57 @@ +class screenspaceeffect_Static_Index +{ +public: + screenspaceeffect_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class screenspaceeffect_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + screenspaceeffect_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9/ShadowModel.inc b/materialsystem/stdshaders/vshtmp9/ShadowModel.inc new file mode 100644 index 0000000..0ccffcf --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9/ShadowModel.inc @@ -0,0 +1,82 @@ +class shadowmodel_Static_Index +{ +public: + shadowmodel_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class shadowmodel_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +public: + shadowmodel_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG && m_bSKINNING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + ( 2 * m_nSKINNING ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9/ShatteredGlass.inc b/materialsystem/stdshaders/vshtmp9/ShatteredGlass.inc new file mode 100644 index 0000000..c37df42 --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9/ShatteredGlass.inc @@ -0,0 +1,57 @@ +class shatteredglass_Static_Index +{ +public: + shatteredglass_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class shatteredglass_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + shatteredglass_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9/ShatteredGlass_EnvMap.inc b/materialsystem/stdshaders/vshtmp9/ShatteredGlass_EnvMap.inc new file mode 100644 index 0000000..362f62a --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9/ShatteredGlass_EnvMap.inc @@ -0,0 +1,57 @@ +class shatteredglass_envmap_Static_Index +{ +public: + shatteredglass_envmap_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class shatteredglass_envmap_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + shatteredglass_envmap_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9/ShatteredGlass_EnvMapSphere.inc b/materialsystem/stdshaders/vshtmp9/ShatteredGlass_EnvMapSphere.inc new file mode 100644 index 0000000..99aba87 --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9/ShatteredGlass_EnvMapSphere.inc @@ -0,0 +1,57 @@ +class shatteredglass_envmapsphere_Static_Index +{ +public: + shatteredglass_envmapsphere_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class shatteredglass_envmapsphere_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + shatteredglass_envmapsphere_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9/Teeth.inc b/materialsystem/stdshaders/vshtmp9/Teeth.inc new file mode 100644 index 0000000..4d4231e --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9/Teeth.inc @@ -0,0 +1,159 @@ +class teeth_Static_Index +{ +private: + int m_nINTRO; +#ifdef _DEBUG + bool m_bINTRO; +#endif +public: + void SetINTRO( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nINTRO = i; +#ifdef _DEBUG + m_bINTRO = true; +#endif + } + void SetINTRO( bool i ) + { + m_nINTRO = i ? 1 : 0; +#ifdef _DEBUG + m_bINTRO = true; +#endif + } +private: + int m_nHALF_LAMBERT; +#ifdef _DEBUG + bool m_bHALF_LAMBERT; +#endif +public: + void SetHALF_LAMBERT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHALF_LAMBERT = i; +#ifdef _DEBUG + m_bHALF_LAMBERT = true; +#endif + } + void SetHALF_LAMBERT( bool i ) + { + m_nHALF_LAMBERT = i ? 1 : 0; +#ifdef _DEBUG + m_bHALF_LAMBERT = true; +#endif + } +public: + teeth_Static_Index() + { +#ifdef _DEBUG + m_bINTRO = false; +#endif // _DEBUG + m_nINTRO = 0; +#ifdef _DEBUG + m_bHALF_LAMBERT = false; +#endif // _DEBUG + m_nHALF_LAMBERT = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bINTRO && m_bHALF_LAMBERT; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 88 * m_nINTRO ) + ( 176 * m_nHALF_LAMBERT ) + 0; + } +}; +class teeth_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nLIGHT_COMBO; +#ifdef _DEBUG + bool m_bLIGHT_COMBO; +#endif +public: + void SetLIGHT_COMBO( int i ) + { + Assert( i >= 0 && i <= 21 ); + m_nLIGHT_COMBO = i; +#ifdef _DEBUG + m_bLIGHT_COMBO = true; +#endif + } + void SetLIGHT_COMBO( bool i ) + { + m_nLIGHT_COMBO = i ? 1 : 0; +#ifdef _DEBUG + m_bLIGHT_COMBO = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +public: + teeth_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bLIGHT_COMBO = false; +#endif // _DEBUG + m_nLIGHT_COMBO = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG && m_bLIGHT_COMBO && m_bSKINNING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + ( 2 * m_nLIGHT_COMBO ) + ( 44 * m_nSKINNING ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9/UnlitGeneric_LightingOnly.inc b/materialsystem/stdshaders/vshtmp9/UnlitGeneric_LightingOnly.inc new file mode 100644 index 0000000..395c340 --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9/UnlitGeneric_LightingOnly.inc @@ -0,0 +1,82 @@ +class unlitgeneric_lightingonly_Static_Index +{ +public: + unlitgeneric_lightingonly_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class unlitgeneric_lightingonly_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +public: + unlitgeneric_lightingonly_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG && m_bSKINNING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + ( 2 * m_nSKINNING ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9/UnlitTwoTexture.inc b/materialsystem/stdshaders/vshtmp9/UnlitTwoTexture.inc new file mode 100644 index 0000000..6813b5c --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9/UnlitTwoTexture.inc @@ -0,0 +1,82 @@ +class unlittwotexture_Static_Index +{ +public: + unlittwotexture_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class unlittwotexture_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +public: + unlittwotexture_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG && m_bSKINNING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + ( 2 * m_nSKINNING ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9/VertexLitGeneric_EnvmappedBumpmap_NoLighting.inc b/materialsystem/stdshaders/vshtmp9/VertexLitGeneric_EnvmappedBumpmap_NoLighting.inc new file mode 100644 index 0000000..814abae --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9/VertexLitGeneric_EnvmappedBumpmap_NoLighting.inc @@ -0,0 +1,82 @@ +class vertexlitgeneric_envmappedbumpmap_nolighting_Static_Index +{ +public: + vertexlitgeneric_envmappedbumpmap_nolighting_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class vertexlitgeneric_envmappedbumpmap_nolighting_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +public: + vertexlitgeneric_envmappedbumpmap_nolighting_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG && m_bSKINNING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + ( 2 * m_nSKINNING ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9/VertexLitGeneric_EnvmappedBumpmap_NoLighting_ps14.inc b/materialsystem/stdshaders/vshtmp9/VertexLitGeneric_EnvmappedBumpmap_NoLighting_ps14.inc new file mode 100644 index 0000000..7e76ddb --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9/VertexLitGeneric_EnvmappedBumpmap_NoLighting_ps14.inc @@ -0,0 +1,82 @@ +class vertexlitgeneric_envmappedbumpmap_nolighting_ps14_Static_Index +{ +public: + vertexlitgeneric_envmappedbumpmap_nolighting_ps14_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class vertexlitgeneric_envmappedbumpmap_nolighting_ps14_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +public: + vertexlitgeneric_envmappedbumpmap_nolighting_ps14_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG && m_bSKINNING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + ( 2 * m_nSKINNING ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9/VertexLitGeneric_SelfIllumOnly.inc b/materialsystem/stdshaders/vshtmp9/VertexLitGeneric_SelfIllumOnly.inc new file mode 100644 index 0000000..a6a07d2 --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9/VertexLitGeneric_SelfIllumOnly.inc @@ -0,0 +1,82 @@ +class vertexlitgeneric_selfillumonly_Static_Index +{ +public: + vertexlitgeneric_selfillumonly_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class vertexlitgeneric_selfillumonly_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +public: + vertexlitgeneric_selfillumonly_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG && m_bSKINNING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + ( 2 * m_nSKINNING ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9/VertexLitGeneric_vs11.inc b/materialsystem/stdshaders/vshtmp9/VertexLitGeneric_vs11.inc new file mode 100644 index 0000000..659e598 --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9/VertexLitGeneric_vs11.inc @@ -0,0 +1,200 @@ +class vertexlitgeneric_vs11_Static_Index +{ +private: + int m_nHALF_LAMBERT; +#ifdef _DEBUG + bool m_bHALF_LAMBERT; +#endif +public: + void SetHALF_LAMBERT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHALF_LAMBERT = i; +#ifdef _DEBUG + m_bHALF_LAMBERT = true; +#endif + } + void SetHALF_LAMBERT( bool i ) + { + m_nHALF_LAMBERT = i ? 1 : 0; +#ifdef _DEBUG + m_bHALF_LAMBERT = true; +#endif + } +private: + int m_nENVMAP; +#ifdef _DEBUG + bool m_bENVMAP; +#endif +public: + void SetENVMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nENVMAP = i; +#ifdef _DEBUG + m_bENVMAP = true; +#endif + } + void SetENVMAP( bool i ) + { + m_nENVMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bENVMAP = true; +#endif + } +private: + int m_nENVMAPCAMERASPACE; +#ifdef _DEBUG + bool m_bENVMAPCAMERASPACE; +#endif +public: + void SetENVMAPCAMERASPACE( int i ) + { + } + void SetENVMAPCAMERASPACE( bool i ) + { + } +private: + int m_nENVMAPSPHERE; +#ifdef _DEBUG + bool m_bENVMAPSPHERE; +#endif +public: + void SetENVMAPSPHERE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nENVMAPSPHERE = i; +#ifdef _DEBUG + m_bENVMAPSPHERE = true; +#endif + } + void SetENVMAPSPHERE( bool i ) + { + m_nENVMAPSPHERE = i ? 1 : 0; +#ifdef _DEBUG + m_bENVMAPSPHERE = true; +#endif + } +public: + vertexlitgeneric_vs11_Static_Index() + { +#ifdef _DEBUG + m_bHALF_LAMBERT = false; +#endif // _DEBUG + m_nHALF_LAMBERT = 0; +#ifdef _DEBUG + m_bENVMAP = false; +#endif // _DEBUG + m_nENVMAP = 0; +#ifdef _DEBUG + m_bENVMAPCAMERASPACE = true; +#endif // _DEBUG + m_nENVMAPCAMERASPACE = 0; +#ifdef _DEBUG + m_bENVMAPSPHERE = false; +#endif // _DEBUG + m_nENVMAPSPHERE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bHALF_LAMBERT && m_bENVMAP && m_bENVMAPCAMERASPACE && m_bENVMAPSPHERE; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 88 * m_nHALF_LAMBERT ) + ( 176 * m_nENVMAP ) + ( 352 * m_nENVMAPCAMERASPACE ) + ( 352 * m_nENVMAPSPHERE ) + 0; + } +}; +class vertexlitgeneric_vs11_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nLIGHT_COMBO; +#ifdef _DEBUG + bool m_bLIGHT_COMBO; +#endif +public: + void SetLIGHT_COMBO( int i ) + { + Assert( i >= 0 && i <= 21 ); + m_nLIGHT_COMBO = i; +#ifdef _DEBUG + m_bLIGHT_COMBO = true; +#endif + } + void SetLIGHT_COMBO( bool i ) + { + m_nLIGHT_COMBO = i ? 1 : 0; +#ifdef _DEBUG + m_bLIGHT_COMBO = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +public: + vertexlitgeneric_vs11_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bLIGHT_COMBO = false; +#endif // _DEBUG + m_nLIGHT_COMBO = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG && m_bLIGHT_COMBO && m_bSKINNING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + ( 2 * m_nLIGHT_COMBO ) + ( 44 * m_nSKINNING ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9/WaterCheapPerVertexFresnel_vs11.inc b/materialsystem/stdshaders/vshtmp9/WaterCheapPerVertexFresnel_vs11.inc new file mode 100644 index 0000000..99282ad --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9/WaterCheapPerVertexFresnel_vs11.inc @@ -0,0 +1,57 @@ +class watercheappervertexfresnel_vs11_Static_Index +{ +public: + watercheappervertexfresnel_vs11_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class watercheappervertexfresnel_vs11_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + watercheappervertexfresnel_vs11_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9/WaterCheap_vs11.inc b/materialsystem/stdshaders/vshtmp9/WaterCheap_vs11.inc new file mode 100644 index 0000000..8928f05 --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9/WaterCheap_vs11.inc @@ -0,0 +1,57 @@ +class watercheap_vs11_Static_Index +{ +public: + watercheap_vs11_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class watercheap_vs11_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + watercheap_vs11_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9/WaterCheap_vs14.inc b/materialsystem/stdshaders/vshtmp9/WaterCheap_vs14.inc new file mode 100644 index 0000000..86f751f --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9/WaterCheap_vs14.inc @@ -0,0 +1,57 @@ +class watercheap_vs14_Static_Index +{ +public: + watercheap_vs14_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class watercheap_vs14_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + watercheap_vs14_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9/Water_ps14.inc b/materialsystem/stdshaders/vshtmp9/Water_ps14.inc new file mode 100644 index 0000000..18e0009 --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9/Water_ps14.inc @@ -0,0 +1,57 @@ +class water_ps14_Static_Index +{ +public: + water_ps14_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class water_ps14_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + water_ps14_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9/Water_vs11.inc b/materialsystem/stdshaders/vshtmp9/Water_vs11.inc new file mode 100644 index 0000000..033251f --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9/Water_vs11.inc @@ -0,0 +1,57 @@ +class water_vs11_Static_Index +{ +public: + water_vs11_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class water_vs11_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + water_vs11_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9/WorldVertexAlpha.inc b/materialsystem/stdshaders/vshtmp9/WorldVertexAlpha.inc new file mode 100644 index 0000000..d2a260c --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9/WorldVertexAlpha.inc @@ -0,0 +1,57 @@ +class worldvertexalpha_Static_Index +{ +public: + worldvertexalpha_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class worldvertexalpha_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + worldvertexalpha_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9/WorldVertexTransition.inc b/materialsystem/stdshaders/vshtmp9/WorldVertexTransition.inc new file mode 100644 index 0000000..5034b05 --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9/WorldVertexTransition.inc @@ -0,0 +1,57 @@ +class worldvertextransition_Static_Index +{ +public: + worldvertextransition_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class worldvertextransition_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + worldvertextransition_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9/bik_vs11.inc b/materialsystem/stdshaders/vshtmp9/bik_vs11.inc new file mode 100644 index 0000000..e076044 --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9/bik_vs11.inc @@ -0,0 +1,30 @@ +class bik_vs11_Static_Index +{ +public: + bik_vs11_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class bik_vs11_Dynamic_Index +{ +public: + bik_vs11_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9/cloak_blended_pass_dx8_vs11.inc b/materialsystem/stdshaders/vshtmp9/cloak_blended_pass_dx8_vs11.inc new file mode 100644 index 0000000..70e7fa9 --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9/cloak_blended_pass_dx8_vs11.inc @@ -0,0 +1,57 @@ +class cloak_blended_pass_dx8_vs11_Static_Index +{ +public: + cloak_blended_pass_dx8_vs11_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class cloak_blended_pass_dx8_vs11_Dynamic_Index +{ +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +public: + cloak_blended_pass_dx8_vs11_Dynamic_Index() + { +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bSKINNING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nSKINNING ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9/cloud_vs11.inc b/materialsystem/stdshaders/vshtmp9/cloud_vs11.inc new file mode 100644 index 0000000..f6ed85b --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9/cloud_vs11.inc @@ -0,0 +1,48 @@ +class cloud_vs11_Static_Index +{ +public: + cloud_vs11_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class cloud_vs11_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + } + void SetDOWATERFOG( bool i ) + { + } +public: + cloud_vs11_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9/emissive_scroll_blended_pass_dx8_vs11.inc b/materialsystem/stdshaders/vshtmp9/emissive_scroll_blended_pass_dx8_vs11.inc new file mode 100644 index 0000000..e8cba9f --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9/emissive_scroll_blended_pass_dx8_vs11.inc @@ -0,0 +1,57 @@ +class emissive_scroll_blended_pass_dx8_vs11_Static_Index +{ +public: + emissive_scroll_blended_pass_dx8_vs11_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class emissive_scroll_blended_pass_dx8_vs11_Dynamic_Index +{ +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +public: + emissive_scroll_blended_pass_dx8_vs11_Dynamic_Index() + { +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bSKINNING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nSKINNING ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9/eyes_flashlight_vs11.inc b/materialsystem/stdshaders/vshtmp9/eyes_flashlight_vs11.inc new file mode 100644 index 0000000..c37a74e --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9/eyes_flashlight_vs11.inc @@ -0,0 +1,82 @@ +class eyes_flashlight_vs11_Static_Index +{ +public: + eyes_flashlight_vs11_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class eyes_flashlight_vs11_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +public: + eyes_flashlight_vs11_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG && m_bSKINNING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + ( 2 * m_nSKINNING ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9/fillrate.inc b/materialsystem/stdshaders/vshtmp9/fillrate.inc new file mode 100644 index 0000000..67060c3 --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9/fillrate.inc @@ -0,0 +1,82 @@ +class fillrate_Static_Index +{ +public: + fillrate_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class fillrate_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +public: + fillrate_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG && m_bSKINNING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + ( 2 * m_nSKINNING ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9/flesh_interior_blended_pass_dx8_vs11.inc b/materialsystem/stdshaders/vshtmp9/flesh_interior_blended_pass_dx8_vs11.inc new file mode 100644 index 0000000..ecdc8ef --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9/flesh_interior_blended_pass_dx8_vs11.inc @@ -0,0 +1,57 @@ +class flesh_interior_blended_pass_dx8_vs11_Static_Index +{ +public: + flesh_interior_blended_pass_dx8_vs11_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class flesh_interior_blended_pass_dx8_vs11_Dynamic_Index +{ +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +public: + flesh_interior_blended_pass_dx8_vs11_Dynamic_Index() + { +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bSKINNING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nSKINNING ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9/lightmappedgeneric_basetextureblend.inc b/materialsystem/stdshaders/vshtmp9/lightmappedgeneric_basetextureblend.inc new file mode 100644 index 0000000..d8608dc --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9/lightmappedgeneric_basetextureblend.inc @@ -0,0 +1,57 @@ +class lightmappedgeneric_basetextureblend_Static_Index +{ +public: + lightmappedgeneric_basetextureblend_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class lightmappedgeneric_basetextureblend_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + lightmappedgeneric_basetextureblend_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9/lightmappedgeneric_bumpmappedenvmap.inc b/materialsystem/stdshaders/vshtmp9/lightmappedgeneric_bumpmappedenvmap.inc new file mode 100644 index 0000000..0da1336 --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9/lightmappedgeneric_bumpmappedenvmap.inc @@ -0,0 +1,57 @@ +class lightmappedgeneric_bumpmappedenvmap_Static_Index +{ +public: + lightmappedgeneric_bumpmappedenvmap_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class lightmappedgeneric_bumpmappedenvmap_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + lightmappedgeneric_bumpmappedenvmap_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9/lightmappedgeneric_bumpmappedenvmap_ps14.inc b/materialsystem/stdshaders/vshtmp9/lightmappedgeneric_bumpmappedenvmap_ps14.inc new file mode 100644 index 0000000..ab20b33 --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9/lightmappedgeneric_bumpmappedenvmap_ps14.inc @@ -0,0 +1,57 @@ +class lightmappedgeneric_bumpmappedenvmap_ps14_Static_Index +{ +public: + lightmappedgeneric_bumpmappedenvmap_ps14_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class lightmappedgeneric_bumpmappedenvmap_ps14_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + lightmappedgeneric_bumpmappedenvmap_ps14_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9/lightmappedgeneric_bumpmappedlightmap.inc b/materialsystem/stdshaders/vshtmp9/lightmappedgeneric_bumpmappedlightmap.inc new file mode 100644 index 0000000..88ca14d --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9/lightmappedgeneric_bumpmappedlightmap.inc @@ -0,0 +1,57 @@ +class lightmappedgeneric_bumpmappedlightmap_Static_Index +{ +public: + lightmappedgeneric_bumpmappedlightmap_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class lightmappedgeneric_bumpmappedlightmap_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + lightmappedgeneric_bumpmappedlightmap_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9/lightmappedgeneric_vs11.inc b/materialsystem/stdshaders/vshtmp9/lightmappedgeneric_vs11.inc new file mode 100644 index 0000000..d16efaa --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9/lightmappedgeneric_vs11.inc @@ -0,0 +1,175 @@ +class lightmappedgeneric_vs11_Static_Index +{ +private: + int m_nDETAIL; +#ifdef _DEBUG + bool m_bDETAIL; +#endif +public: + void SetDETAIL( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDETAIL = i; +#ifdef _DEBUG + m_bDETAIL = true; +#endif + } + void SetDETAIL( bool i ) + { + m_nDETAIL = i ? 1 : 0; +#ifdef _DEBUG + m_bDETAIL = true; +#endif + } +private: + int m_nENVMAP; +#ifdef _DEBUG + bool m_bENVMAP; +#endif +public: + void SetENVMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nENVMAP = i; +#ifdef _DEBUG + m_bENVMAP = true; +#endif + } + void SetENVMAP( bool i ) + { + m_nENVMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bENVMAP = true; +#endif + } +private: + int m_nENVMAPCAMERASPACE; +#ifdef _DEBUG + bool m_bENVMAPCAMERASPACE; +#endif +public: + void SetENVMAPCAMERASPACE( int i ) + { + } + void SetENVMAPCAMERASPACE( bool i ) + { + } +private: + int m_nENVMAPSPHERE; +#ifdef _DEBUG + bool m_bENVMAPSPHERE; +#endif +public: + void SetENVMAPSPHERE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nENVMAPSPHERE = i; +#ifdef _DEBUG + m_bENVMAPSPHERE = true; +#endif + } + void SetENVMAPSPHERE( bool i ) + { + m_nENVMAPSPHERE = i ? 1 : 0; +#ifdef _DEBUG + m_bENVMAPSPHERE = true; +#endif + } +private: + int m_nVERTEXCOLOR; +#ifdef _DEBUG + bool m_bVERTEXCOLOR; +#endif +public: + void SetVERTEXCOLOR( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nVERTEXCOLOR = i; +#ifdef _DEBUG + m_bVERTEXCOLOR = true; +#endif + } + void SetVERTEXCOLOR( bool i ) + { + m_nVERTEXCOLOR = i ? 1 : 0; +#ifdef _DEBUG + m_bVERTEXCOLOR = true; +#endif + } +public: + lightmappedgeneric_vs11_Static_Index() + { +#ifdef _DEBUG + m_bDETAIL = false; +#endif // _DEBUG + m_nDETAIL = 0; +#ifdef _DEBUG + m_bENVMAP = false; +#endif // _DEBUG + m_nENVMAP = 0; +#ifdef _DEBUG + m_bENVMAPCAMERASPACE = true; +#endif // _DEBUG + m_nENVMAPCAMERASPACE = 0; +#ifdef _DEBUG + m_bENVMAPSPHERE = false; +#endif // _DEBUG + m_nENVMAPSPHERE = 0; +#ifdef _DEBUG + m_bVERTEXCOLOR = false; +#endif // _DEBUG + m_nVERTEXCOLOR = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bDETAIL && m_bENVMAP && m_bENVMAPCAMERASPACE && m_bENVMAPSPHERE && m_bVERTEXCOLOR; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nDETAIL ) + ( 4 * m_nENVMAP ) + ( 8 * m_nENVMAPCAMERASPACE ) + ( 8 * m_nENVMAPSPHERE ) + ( 16 * m_nVERTEXCOLOR ) + 0; + } +}; +class lightmappedgeneric_vs11_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + lightmappedgeneric_vs11_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9/overlay_fit_vs11.inc b/materialsystem/stdshaders/vshtmp9/overlay_fit_vs11.inc new file mode 100644 index 0000000..3d4606e --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9/overlay_fit_vs11.inc @@ -0,0 +1,57 @@ +class overlay_fit_vs11_Static_Index +{ +public: + overlay_fit_vs11_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class overlay_fit_vs11_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + overlay_fit_vs11_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9/predator.inc b/materialsystem/stdshaders/vshtmp9/predator.inc new file mode 100644 index 0000000..fed889e --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9/predator.inc @@ -0,0 +1,82 @@ +class predator_Static_Index +{ +public: + predator_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class predator_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +public: + predator_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG && m_bSKINNING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + ( 2 * m_nSKINNING ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9/rendertargetblit_vs11.inc b/materialsystem/stdshaders/vshtmp9/rendertargetblit_vs11.inc new file mode 100644 index 0000000..f315ad1 --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9/rendertargetblit_vs11.inc @@ -0,0 +1,30 @@ +class rendertargetblit_vs11_Static_Index +{ +public: + rendertargetblit_vs11_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class rendertargetblit_vs11_Dynamic_Index +{ +public: + rendertargetblit_vs11_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9/shadow_vs14.inc b/materialsystem/stdshaders/vshtmp9/shadow_vs14.inc new file mode 100644 index 0000000..97572d5 --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9/shadow_vs14.inc @@ -0,0 +1,57 @@ +class shadow_vs14_Static_Index +{ +public: + shadow_vs14_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class shadow_vs14_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + shadow_vs14_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9/sprite_vs11.inc b/materialsystem/stdshaders/vshtmp9/sprite_vs11.inc new file mode 100644 index 0000000..daabad6 --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9/sprite_vs11.inc @@ -0,0 +1,100 @@ +class sprite_vs11_Static_Index +{ +private: + int m_nVERTEXCOLOR; +#ifdef _DEBUG + bool m_bVERTEXCOLOR; +#endif +public: + void SetVERTEXCOLOR( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nVERTEXCOLOR = i; +#ifdef _DEBUG + m_bVERTEXCOLOR = true; +#endif + } + void SetVERTEXCOLOR( bool i ) + { + m_nVERTEXCOLOR = i ? 1 : 0; +#ifdef _DEBUG + m_bVERTEXCOLOR = true; +#endif + } +public: + sprite_vs11_Static_Index() + { +#ifdef _DEBUG + m_bVERTEXCOLOR = false; +#endif // _DEBUG + m_nVERTEXCOLOR = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bVERTEXCOLOR; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nVERTEXCOLOR ) + 0; + } +}; +class sprite_vs11_Dynamic_Index +{ +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + } + void SetSKINNING( bool i ) + { + } +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + sprite_vs11_Dynamic_Index() + { +#ifdef _DEBUG + m_bSKINNING = true; +#endif // _DEBUG + m_nSKINNING = 0; +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bSKINNING && m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nSKINNING ) + ( 1 * m_nDOWATERFOG ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9/unlitgeneric_vs11.inc b/materialsystem/stdshaders/vshtmp9/unlitgeneric_vs11.inc new file mode 100644 index 0000000..fb1bb21 --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9/unlitgeneric_vs11.inc @@ -0,0 +1,225 @@ +class unlitgeneric_vs11_Static_Index +{ +private: + int m_nDETAIL; +#ifdef _DEBUG + bool m_bDETAIL; +#endif +public: + void SetDETAIL( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDETAIL = i; +#ifdef _DEBUG + m_bDETAIL = true; +#endif + } + void SetDETAIL( bool i ) + { + m_nDETAIL = i ? 1 : 0; +#ifdef _DEBUG + m_bDETAIL = true; +#endif + } +private: + int m_nENVMAP; +#ifdef _DEBUG + bool m_bENVMAP; +#endif +public: + void SetENVMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nENVMAP = i; +#ifdef _DEBUG + m_bENVMAP = true; +#endif + } + void SetENVMAP( bool i ) + { + m_nENVMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bENVMAP = true; +#endif + } +private: + int m_nENVMAPCAMERASPACE; +#ifdef _DEBUG + bool m_bENVMAPCAMERASPACE; +#endif +public: + void SetENVMAPCAMERASPACE( int i ) + { + } + void SetENVMAPCAMERASPACE( bool i ) + { + } +private: + int m_nENVMAPSPHERE; +#ifdef _DEBUG + bool m_bENVMAPSPHERE; +#endif +public: + void SetENVMAPSPHERE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nENVMAPSPHERE = i; +#ifdef _DEBUG + m_bENVMAPSPHERE = true; +#endif + } + void SetENVMAPSPHERE( bool i ) + { + m_nENVMAPSPHERE = i ? 1 : 0; +#ifdef _DEBUG + m_bENVMAPSPHERE = true; +#endif + } +private: + int m_nVERTEXCOLOR; +#ifdef _DEBUG + bool m_bVERTEXCOLOR; +#endif +public: + void SetVERTEXCOLOR( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nVERTEXCOLOR = i; +#ifdef _DEBUG + m_bVERTEXCOLOR = true; +#endif + } + void SetVERTEXCOLOR( bool i ) + { + m_nVERTEXCOLOR = i ? 1 : 0; +#ifdef _DEBUG + m_bVERTEXCOLOR = true; +#endif + } +private: + int m_nSEPARATEDETAILUVS; +#ifdef _DEBUG + bool m_bSEPARATEDETAILUVS; +#endif +public: + void SetSEPARATEDETAILUVS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSEPARATEDETAILUVS = i; +#ifdef _DEBUG + m_bSEPARATEDETAILUVS = true; +#endif + } + void SetSEPARATEDETAILUVS( bool i ) + { + m_nSEPARATEDETAILUVS = i ? 1 : 0; +#ifdef _DEBUG + m_bSEPARATEDETAILUVS = true; +#endif + } +public: + unlitgeneric_vs11_Static_Index() + { +#ifdef _DEBUG + m_bDETAIL = false; +#endif // _DEBUG + m_nDETAIL = 0; +#ifdef _DEBUG + m_bENVMAP = false; +#endif // _DEBUG + m_nENVMAP = 0; +#ifdef _DEBUG + m_bENVMAPCAMERASPACE = true; +#endif // _DEBUG + m_nENVMAPCAMERASPACE = 0; +#ifdef _DEBUG + m_bENVMAPSPHERE = false; +#endif // _DEBUG + m_nENVMAPSPHERE = 0; +#ifdef _DEBUG + m_bVERTEXCOLOR = false; +#endif // _DEBUG + m_nVERTEXCOLOR = 0; +#ifdef _DEBUG + m_bSEPARATEDETAILUVS = false; +#endif // _DEBUG + m_nSEPARATEDETAILUVS = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bDETAIL && m_bENVMAP && m_bENVMAPCAMERASPACE && m_bENVMAPSPHERE && m_bVERTEXCOLOR && m_bSEPARATEDETAILUVS; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 4 * m_nDETAIL ) + ( 8 * m_nENVMAP ) + ( 16 * m_nENVMAPCAMERASPACE ) + ( 16 * m_nENVMAPSPHERE ) + ( 32 * m_nVERTEXCOLOR ) + ( 64 * m_nSEPARATEDETAILUVS ) + 0; + } +}; +class unlitgeneric_vs11_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +public: + unlitgeneric_vs11_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG && m_bSKINNING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + ( 2 * m_nSKINNING ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9/vertexlitgeneric_flashlight_vs11.inc b/materialsystem/stdshaders/vshtmp9/vertexlitgeneric_flashlight_vs11.inc new file mode 100644 index 0000000..41b87c0 --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9/vertexlitgeneric_flashlight_vs11.inc @@ -0,0 +1,109 @@ +class vertexlitgeneric_flashlight_vs11_Static_Index +{ +private: + int m_nTEETH; +#ifdef _DEBUG + bool m_bTEETH; +#endif +public: + void SetTEETH( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nTEETH = i; +#ifdef _DEBUG + m_bTEETH = true; +#endif + } + void SetTEETH( bool i ) + { + m_nTEETH = i ? 1 : 0; +#ifdef _DEBUG + m_bTEETH = true; +#endif + } +public: + vertexlitgeneric_flashlight_vs11_Static_Index() + { +#ifdef _DEBUG + m_bTEETH = false; +#endif // _DEBUG + m_nTEETH = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bTEETH; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 4 * m_nTEETH ) + 0; + } +}; +class vertexlitgeneric_flashlight_vs11_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +public: + vertexlitgeneric_flashlight_vs11_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG && m_bSKINNING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + ( 2 * m_nSKINNING ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9/vortwarp_vs11.inc b/materialsystem/stdshaders/vshtmp9/vortwarp_vs11.inc new file mode 100644 index 0000000..77d43a3 --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9/vortwarp_vs11.inc @@ -0,0 +1,134 @@ +class vortwarp_vs11_Static_Index +{ +private: + int m_nUNLIT; +#ifdef _DEBUG + bool m_bUNLIT; +#endif +public: + void SetUNLIT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nUNLIT = i; +#ifdef _DEBUG + m_bUNLIT = true; +#endif + } + void SetUNLIT( bool i ) + { + m_nUNLIT = i ? 1 : 0; +#ifdef _DEBUG + m_bUNLIT = true; +#endif + } +private: + int m_nHALF_LAMBERT; +#ifdef _DEBUG + bool m_bHALF_LAMBERT; +#endif +public: + void SetHALF_LAMBERT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHALF_LAMBERT = i; +#ifdef _DEBUG + m_bHALF_LAMBERT = true; +#endif + } + void SetHALF_LAMBERT( bool i ) + { + m_nHALF_LAMBERT = i ? 1 : 0; +#ifdef _DEBUG + m_bHALF_LAMBERT = true; +#endif + } +public: + vortwarp_vs11_Static_Index() + { +#ifdef _DEBUG + m_bUNLIT = false; +#endif // _DEBUG + m_nUNLIT = 0; +#ifdef _DEBUG + m_bHALF_LAMBERT = false; +#endif // _DEBUG + m_nHALF_LAMBERT = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bUNLIT && m_bHALF_LAMBERT; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 44 * m_nUNLIT ) + ( 88 * m_nHALF_LAMBERT ) + 0; + } +}; +class vortwarp_vs11_Dynamic_Index +{ +private: + int m_nLIGHT_COMBO; +#ifdef _DEBUG + bool m_bLIGHT_COMBO; +#endif +public: + void SetLIGHT_COMBO( int i ) + { + Assert( i >= 0 && i <= 21 ); + m_nLIGHT_COMBO = i; +#ifdef _DEBUG + m_bLIGHT_COMBO = true; +#endif + } + void SetLIGHT_COMBO( bool i ) + { + m_nLIGHT_COMBO = i ? 1 : 0; +#ifdef _DEBUG + m_bLIGHT_COMBO = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +public: + vortwarp_vs11_Dynamic_Index() + { +#ifdef _DEBUG + m_bLIGHT_COMBO = false; +#endif // _DEBUG + m_nLIGHT_COMBO = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bLIGHT_COMBO && m_bSKINNING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nLIGHT_COMBO ) + ( 22 * m_nSKINNING ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9/worldvertextransition_seamless.inc b/materialsystem/stdshaders/vshtmp9/worldvertextransition_seamless.inc new file mode 100644 index 0000000..b64798d --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9/worldvertextransition_seamless.inc @@ -0,0 +1,57 @@ +class worldvertextransition_seamless_Static_Index +{ +public: + worldvertextransition_seamless_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class worldvertextransition_seamless_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + worldvertextransition_seamless_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9/worldvertextransition_vs14.inc b/materialsystem/stdshaders/vshtmp9/worldvertextransition_vs14.inc new file mode 100644 index 0000000..5991050 --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9/worldvertextransition_vs14.inc @@ -0,0 +1,57 @@ +class worldvertextransition_vs14_Static_Index +{ +public: + worldvertextransition_vs14_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class worldvertextransition_vs14_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + worldvertextransition_vs14_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9/writez.inc b/materialsystem/stdshaders/vshtmp9/writez.inc new file mode 100644 index 0000000..82c36f0 --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9/writez.inc @@ -0,0 +1,57 @@ +class writez_Static_Index +{ +public: + writez_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class writez_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + writez_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9_360/BufferClearObeyStencil_vs11.inc b/materialsystem/stdshaders/vshtmp9_360/BufferClearObeyStencil_vs11.inc new file mode 100644 index 0000000..ed1aab9 --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9_360/BufferClearObeyStencil_vs11.inc @@ -0,0 +1,30 @@ +class bufferclearobeystencil_vs11_Static_Index +{ +public: + bufferclearobeystencil_vs11_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class bufferclearobeystencil_vs11_Dynamic_Index +{ +public: + bufferclearobeystencil_vs11_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9_360/BumpmappedEnvmap.inc b/materialsystem/stdshaders/vshtmp9_360/BumpmappedEnvmap.inc new file mode 100644 index 0000000..a177a09 --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9_360/BumpmappedEnvmap.inc @@ -0,0 +1,57 @@ +class bumpmappedenvmap_Static_Index +{ +public: + bumpmappedenvmap_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class bumpmappedenvmap_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + bumpmappedenvmap_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9_360/BumpmappedLightmap.inc b/materialsystem/stdshaders/vshtmp9_360/BumpmappedLightmap.inc new file mode 100644 index 0000000..45c30c4 --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9_360/BumpmappedLightmap.inc @@ -0,0 +1,57 @@ +class bumpmappedlightmap_Static_Index +{ +public: + bumpmappedlightmap_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class bumpmappedlightmap_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + bumpmappedlightmap_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9_360/Cable.inc b/materialsystem/stdshaders/vshtmp9_360/Cable.inc new file mode 100644 index 0000000..b86952d --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9_360/Cable.inc @@ -0,0 +1,57 @@ +class cable_Static_Index +{ +public: + cable_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class cable_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + cable_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9_360/DebugTangentSpace.inc b/materialsystem/stdshaders/vshtmp9_360/DebugTangentSpace.inc new file mode 100644 index 0000000..4587dea --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9_360/DebugTangentSpace.inc @@ -0,0 +1,82 @@ +class debugtangentspace_Static_Index +{ +public: + debugtangentspace_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class debugtangentspace_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +public: + debugtangentspace_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG && m_bSKINNING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + ( 2 * m_nSKINNING ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9_360/Eyes.inc b/materialsystem/stdshaders/vshtmp9_360/Eyes.inc new file mode 100644 index 0000000..db49b5a --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9_360/Eyes.inc @@ -0,0 +1,134 @@ +class eyes_Static_Index +{ +private: + int m_nHALF_LAMBERT; +#ifdef _DEBUG + bool m_bHALF_LAMBERT; +#endif +public: + void SetHALF_LAMBERT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHALF_LAMBERT = i; +#ifdef _DEBUG + m_bHALF_LAMBERT = true; +#endif + } + void SetHALF_LAMBERT( bool i ) + { + m_nHALF_LAMBERT = i ? 1 : 0; +#ifdef _DEBUG + m_bHALF_LAMBERT = true; +#endif + } +public: + eyes_Static_Index() + { +#ifdef _DEBUG + m_bHALF_LAMBERT = false; +#endif // _DEBUG + m_nHALF_LAMBERT = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bHALF_LAMBERT; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 88 * m_nHALF_LAMBERT ) + 0; + } +}; +class eyes_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nLIGHT_COMBO; +#ifdef _DEBUG + bool m_bLIGHT_COMBO; +#endif +public: + void SetLIGHT_COMBO( int i ) + { + Assert( i >= 0 && i <= 21 ); + m_nLIGHT_COMBO = i; +#ifdef _DEBUG + m_bLIGHT_COMBO = true; +#endif + } + void SetLIGHT_COMBO( bool i ) + { + m_nLIGHT_COMBO = i ? 1 : 0; +#ifdef _DEBUG + m_bLIGHT_COMBO = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +public: + eyes_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bLIGHT_COMBO = false; +#endif // _DEBUG + m_nLIGHT_COMBO = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG && m_bLIGHT_COMBO && m_bSKINNING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + ( 2 * m_nLIGHT_COMBO ) + ( 44 * m_nSKINNING ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9_360/JellyFish.inc b/materialsystem/stdshaders/vshtmp9_360/JellyFish.inc new file mode 100644 index 0000000..3e8c7ee --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9_360/JellyFish.inc @@ -0,0 +1,82 @@ +class jellyfish_Static_Index +{ +public: + jellyfish_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class jellyfish_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +public: + jellyfish_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG && m_bSKINNING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + ( 2 * m_nSKINNING ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9_360/LightingOnly.inc b/materialsystem/stdshaders/vshtmp9_360/LightingOnly.inc new file mode 100644 index 0000000..393a67e --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9_360/LightingOnly.inc @@ -0,0 +1,134 @@ +class lightingonly_Static_Index +{ +private: + int m_nHALF_LAMBERT; +#ifdef _DEBUG + bool m_bHALF_LAMBERT; +#endif +public: + void SetHALF_LAMBERT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHALF_LAMBERT = i; +#ifdef _DEBUG + m_bHALF_LAMBERT = true; +#endif + } + void SetHALF_LAMBERT( bool i ) + { + m_nHALF_LAMBERT = i ? 1 : 0; +#ifdef _DEBUG + m_bHALF_LAMBERT = true; +#endif + } +public: + lightingonly_Static_Index() + { +#ifdef _DEBUG + m_bHALF_LAMBERT = false; +#endif // _DEBUG + m_nHALF_LAMBERT = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bHALF_LAMBERT; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 88 * m_nHALF_LAMBERT ) + 0; + } +}; +class lightingonly_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nLIGHT_COMBO; +#ifdef _DEBUG + bool m_bLIGHT_COMBO; +#endif +public: + void SetLIGHT_COMBO( int i ) + { + Assert( i >= 0 && i <= 21 ); + m_nLIGHT_COMBO = i; +#ifdef _DEBUG + m_bLIGHT_COMBO = true; +#endif + } + void SetLIGHT_COMBO( bool i ) + { + m_nLIGHT_COMBO = i ? 1 : 0; +#ifdef _DEBUG + m_bLIGHT_COMBO = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +public: + lightingonly_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bLIGHT_COMBO = false; +#endif // _DEBUG + m_nLIGHT_COMBO = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG && m_bLIGHT_COMBO && m_bSKINNING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + ( 2 * m_nLIGHT_COMBO ) + ( 44 * m_nSKINNING ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9_360/LightmappedGeneric_BaseTexture.inc b/materialsystem/stdshaders/vshtmp9_360/LightmappedGeneric_BaseTexture.inc new file mode 100644 index 0000000..3df8215 --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9_360/LightmappedGeneric_BaseTexture.inc @@ -0,0 +1,57 @@ +class lightmappedgeneric_basetexture_Static_Index +{ +public: + lightmappedgeneric_basetexture_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class lightmappedgeneric_basetexture_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + lightmappedgeneric_basetexture_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9_360/LightmappedGeneric_BumpmappedLightmap_Base_ps14.inc b/materialsystem/stdshaders/vshtmp9_360/LightmappedGeneric_BumpmappedLightmap_Base_ps14.inc new file mode 100644 index 0000000..f0d6d24 --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9_360/LightmappedGeneric_BumpmappedLightmap_Base_ps14.inc @@ -0,0 +1,57 @@ +class lightmappedgeneric_bumpmappedlightmap_base_ps14_Static_Index +{ +public: + lightmappedgeneric_bumpmappedlightmap_base_ps14_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class lightmappedgeneric_bumpmappedlightmap_base_ps14_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + lightmappedgeneric_bumpmappedlightmap_base_ps14_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9_360/LightmappedGeneric_BumpmappedLightmap_Blend_ps14.inc b/materialsystem/stdshaders/vshtmp9_360/LightmappedGeneric_BumpmappedLightmap_Blend_ps14.inc new file mode 100644 index 0000000..119a92a --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9_360/LightmappedGeneric_BumpmappedLightmap_Blend_ps14.inc @@ -0,0 +1,57 @@ +class lightmappedgeneric_bumpmappedlightmap_blend_ps14_Static_Index +{ +public: + lightmappedgeneric_bumpmappedlightmap_blend_ps14_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class lightmappedgeneric_bumpmappedlightmap_blend_ps14_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + lightmappedgeneric_bumpmappedlightmap_blend_ps14_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9_360/LightmappedGeneric_Decal.inc b/materialsystem/stdshaders/vshtmp9_360/LightmappedGeneric_Decal.inc new file mode 100644 index 0000000..1c0a730 --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9_360/LightmappedGeneric_Decal.inc @@ -0,0 +1,57 @@ +class lightmappedgeneric_decal_Static_Index +{ +public: + lightmappedgeneric_decal_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class lightmappedgeneric_decal_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + lightmappedgeneric_decal_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9_360/LightmappedGeneric_LightingOnly.inc b/materialsystem/stdshaders/vshtmp9_360/LightmappedGeneric_LightingOnly.inc new file mode 100644 index 0000000..f929467 --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9_360/LightmappedGeneric_LightingOnly.inc @@ -0,0 +1,57 @@ +class lightmappedgeneric_lightingonly_Static_Index +{ +public: + lightmappedgeneric_lightingonly_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class lightmappedgeneric_lightingonly_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + lightmappedgeneric_lightingonly_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9_360/Refract_model_vs11.inc b/materialsystem/stdshaders/vshtmp9_360/Refract_model_vs11.inc new file mode 100644 index 0000000..7d34b9e --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9_360/Refract_model_vs11.inc @@ -0,0 +1,82 @@ +class refract_model_vs11_Static_Index +{ +public: + refract_model_vs11_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class refract_model_vs11_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +public: + refract_model_vs11_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG && m_bSKINNING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + ( 2 * m_nSKINNING ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9_360/Refract_world_vs11.inc b/materialsystem/stdshaders/vshtmp9_360/Refract_world_vs11.inc new file mode 100644 index 0000000..b5e6997 --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9_360/Refract_world_vs11.inc @@ -0,0 +1,57 @@ +class refract_world_vs11_Static_Index +{ +public: + refract_world_vs11_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class refract_world_vs11_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + refract_world_vs11_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9_360/ScreenSpaceEffect.inc b/materialsystem/stdshaders/vshtmp9_360/ScreenSpaceEffect.inc new file mode 100644 index 0000000..6b44278 --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9_360/ScreenSpaceEffect.inc @@ -0,0 +1,57 @@ +class screenspaceeffect_Static_Index +{ +public: + screenspaceeffect_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class screenspaceeffect_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + screenspaceeffect_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9_360/ShadowModel.inc b/materialsystem/stdshaders/vshtmp9_360/ShadowModel.inc new file mode 100644 index 0000000..0ccffcf --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9_360/ShadowModel.inc @@ -0,0 +1,82 @@ +class shadowmodel_Static_Index +{ +public: + shadowmodel_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class shadowmodel_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +public: + shadowmodel_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG && m_bSKINNING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + ( 2 * m_nSKINNING ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9_360/ShatteredGlass.inc b/materialsystem/stdshaders/vshtmp9_360/ShatteredGlass.inc new file mode 100644 index 0000000..c37df42 --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9_360/ShatteredGlass.inc @@ -0,0 +1,57 @@ +class shatteredglass_Static_Index +{ +public: + shatteredglass_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class shatteredglass_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + shatteredglass_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9_360/ShatteredGlass_EnvMap.inc b/materialsystem/stdshaders/vshtmp9_360/ShatteredGlass_EnvMap.inc new file mode 100644 index 0000000..362f62a --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9_360/ShatteredGlass_EnvMap.inc @@ -0,0 +1,57 @@ +class shatteredglass_envmap_Static_Index +{ +public: + shatteredglass_envmap_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class shatteredglass_envmap_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + shatteredglass_envmap_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9_360/ShatteredGlass_EnvMapSphere.inc b/materialsystem/stdshaders/vshtmp9_360/ShatteredGlass_EnvMapSphere.inc new file mode 100644 index 0000000..99aba87 --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9_360/ShatteredGlass_EnvMapSphere.inc @@ -0,0 +1,57 @@ +class shatteredglass_envmapsphere_Static_Index +{ +public: + shatteredglass_envmapsphere_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class shatteredglass_envmapsphere_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + shatteredglass_envmapsphere_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9_360/Teeth.inc b/materialsystem/stdshaders/vshtmp9_360/Teeth.inc new file mode 100644 index 0000000..4d4231e --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9_360/Teeth.inc @@ -0,0 +1,159 @@ +class teeth_Static_Index +{ +private: + int m_nINTRO; +#ifdef _DEBUG + bool m_bINTRO; +#endif +public: + void SetINTRO( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nINTRO = i; +#ifdef _DEBUG + m_bINTRO = true; +#endif + } + void SetINTRO( bool i ) + { + m_nINTRO = i ? 1 : 0; +#ifdef _DEBUG + m_bINTRO = true; +#endif + } +private: + int m_nHALF_LAMBERT; +#ifdef _DEBUG + bool m_bHALF_LAMBERT; +#endif +public: + void SetHALF_LAMBERT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHALF_LAMBERT = i; +#ifdef _DEBUG + m_bHALF_LAMBERT = true; +#endif + } + void SetHALF_LAMBERT( bool i ) + { + m_nHALF_LAMBERT = i ? 1 : 0; +#ifdef _DEBUG + m_bHALF_LAMBERT = true; +#endif + } +public: + teeth_Static_Index() + { +#ifdef _DEBUG + m_bINTRO = false; +#endif // _DEBUG + m_nINTRO = 0; +#ifdef _DEBUG + m_bHALF_LAMBERT = false; +#endif // _DEBUG + m_nHALF_LAMBERT = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bINTRO && m_bHALF_LAMBERT; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 88 * m_nINTRO ) + ( 176 * m_nHALF_LAMBERT ) + 0; + } +}; +class teeth_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nLIGHT_COMBO; +#ifdef _DEBUG + bool m_bLIGHT_COMBO; +#endif +public: + void SetLIGHT_COMBO( int i ) + { + Assert( i >= 0 && i <= 21 ); + m_nLIGHT_COMBO = i; +#ifdef _DEBUG + m_bLIGHT_COMBO = true; +#endif + } + void SetLIGHT_COMBO( bool i ) + { + m_nLIGHT_COMBO = i ? 1 : 0; +#ifdef _DEBUG + m_bLIGHT_COMBO = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +public: + teeth_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bLIGHT_COMBO = false; +#endif // _DEBUG + m_nLIGHT_COMBO = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG && m_bLIGHT_COMBO && m_bSKINNING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + ( 2 * m_nLIGHT_COMBO ) + ( 44 * m_nSKINNING ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9_360/UnlitGeneric_LightingOnly.inc b/materialsystem/stdshaders/vshtmp9_360/UnlitGeneric_LightingOnly.inc new file mode 100644 index 0000000..395c340 --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9_360/UnlitGeneric_LightingOnly.inc @@ -0,0 +1,82 @@ +class unlitgeneric_lightingonly_Static_Index +{ +public: + unlitgeneric_lightingonly_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class unlitgeneric_lightingonly_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +public: + unlitgeneric_lightingonly_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG && m_bSKINNING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + ( 2 * m_nSKINNING ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9_360/UnlitTwoTexture.inc b/materialsystem/stdshaders/vshtmp9_360/UnlitTwoTexture.inc new file mode 100644 index 0000000..6813b5c --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9_360/UnlitTwoTexture.inc @@ -0,0 +1,82 @@ +class unlittwotexture_Static_Index +{ +public: + unlittwotexture_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class unlittwotexture_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +public: + unlittwotexture_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG && m_bSKINNING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + ( 2 * m_nSKINNING ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9_360/VertexLitGeneric_EnvmappedBumpmap_NoLighting.inc b/materialsystem/stdshaders/vshtmp9_360/VertexLitGeneric_EnvmappedBumpmap_NoLighting.inc new file mode 100644 index 0000000..814abae --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9_360/VertexLitGeneric_EnvmappedBumpmap_NoLighting.inc @@ -0,0 +1,82 @@ +class vertexlitgeneric_envmappedbumpmap_nolighting_Static_Index +{ +public: + vertexlitgeneric_envmappedbumpmap_nolighting_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class vertexlitgeneric_envmappedbumpmap_nolighting_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +public: + vertexlitgeneric_envmappedbumpmap_nolighting_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG && m_bSKINNING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + ( 2 * m_nSKINNING ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9_360/VertexLitGeneric_EnvmappedBumpmap_NoLighting_ps14.inc b/materialsystem/stdshaders/vshtmp9_360/VertexLitGeneric_EnvmappedBumpmap_NoLighting_ps14.inc new file mode 100644 index 0000000..7e76ddb --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9_360/VertexLitGeneric_EnvmappedBumpmap_NoLighting_ps14.inc @@ -0,0 +1,82 @@ +class vertexlitgeneric_envmappedbumpmap_nolighting_ps14_Static_Index +{ +public: + vertexlitgeneric_envmappedbumpmap_nolighting_ps14_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class vertexlitgeneric_envmappedbumpmap_nolighting_ps14_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +public: + vertexlitgeneric_envmappedbumpmap_nolighting_ps14_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG && m_bSKINNING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + ( 2 * m_nSKINNING ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9_360/VertexLitGeneric_SelfIllumOnly.inc b/materialsystem/stdshaders/vshtmp9_360/VertexLitGeneric_SelfIllumOnly.inc new file mode 100644 index 0000000..a6a07d2 --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9_360/VertexLitGeneric_SelfIllumOnly.inc @@ -0,0 +1,82 @@ +class vertexlitgeneric_selfillumonly_Static_Index +{ +public: + vertexlitgeneric_selfillumonly_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class vertexlitgeneric_selfillumonly_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +public: + vertexlitgeneric_selfillumonly_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG && m_bSKINNING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + ( 2 * m_nSKINNING ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9_360/VertexLitGeneric_vs11.inc b/materialsystem/stdshaders/vshtmp9_360/VertexLitGeneric_vs11.inc new file mode 100644 index 0000000..659e598 --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9_360/VertexLitGeneric_vs11.inc @@ -0,0 +1,200 @@ +class vertexlitgeneric_vs11_Static_Index +{ +private: + int m_nHALF_LAMBERT; +#ifdef _DEBUG + bool m_bHALF_LAMBERT; +#endif +public: + void SetHALF_LAMBERT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHALF_LAMBERT = i; +#ifdef _DEBUG + m_bHALF_LAMBERT = true; +#endif + } + void SetHALF_LAMBERT( bool i ) + { + m_nHALF_LAMBERT = i ? 1 : 0; +#ifdef _DEBUG + m_bHALF_LAMBERT = true; +#endif + } +private: + int m_nENVMAP; +#ifdef _DEBUG + bool m_bENVMAP; +#endif +public: + void SetENVMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nENVMAP = i; +#ifdef _DEBUG + m_bENVMAP = true; +#endif + } + void SetENVMAP( bool i ) + { + m_nENVMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bENVMAP = true; +#endif + } +private: + int m_nENVMAPCAMERASPACE; +#ifdef _DEBUG + bool m_bENVMAPCAMERASPACE; +#endif +public: + void SetENVMAPCAMERASPACE( int i ) + { + } + void SetENVMAPCAMERASPACE( bool i ) + { + } +private: + int m_nENVMAPSPHERE; +#ifdef _DEBUG + bool m_bENVMAPSPHERE; +#endif +public: + void SetENVMAPSPHERE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nENVMAPSPHERE = i; +#ifdef _DEBUG + m_bENVMAPSPHERE = true; +#endif + } + void SetENVMAPSPHERE( bool i ) + { + m_nENVMAPSPHERE = i ? 1 : 0; +#ifdef _DEBUG + m_bENVMAPSPHERE = true; +#endif + } +public: + vertexlitgeneric_vs11_Static_Index() + { +#ifdef _DEBUG + m_bHALF_LAMBERT = false; +#endif // _DEBUG + m_nHALF_LAMBERT = 0; +#ifdef _DEBUG + m_bENVMAP = false; +#endif // _DEBUG + m_nENVMAP = 0; +#ifdef _DEBUG + m_bENVMAPCAMERASPACE = true; +#endif // _DEBUG + m_nENVMAPCAMERASPACE = 0; +#ifdef _DEBUG + m_bENVMAPSPHERE = false; +#endif // _DEBUG + m_nENVMAPSPHERE = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bHALF_LAMBERT && m_bENVMAP && m_bENVMAPCAMERASPACE && m_bENVMAPSPHERE; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 88 * m_nHALF_LAMBERT ) + ( 176 * m_nENVMAP ) + ( 352 * m_nENVMAPCAMERASPACE ) + ( 352 * m_nENVMAPSPHERE ) + 0; + } +}; +class vertexlitgeneric_vs11_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nLIGHT_COMBO; +#ifdef _DEBUG + bool m_bLIGHT_COMBO; +#endif +public: + void SetLIGHT_COMBO( int i ) + { + Assert( i >= 0 && i <= 21 ); + m_nLIGHT_COMBO = i; +#ifdef _DEBUG + m_bLIGHT_COMBO = true; +#endif + } + void SetLIGHT_COMBO( bool i ) + { + m_nLIGHT_COMBO = i ? 1 : 0; +#ifdef _DEBUG + m_bLIGHT_COMBO = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +public: + vertexlitgeneric_vs11_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bLIGHT_COMBO = false; +#endif // _DEBUG + m_nLIGHT_COMBO = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG && m_bLIGHT_COMBO && m_bSKINNING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + ( 2 * m_nLIGHT_COMBO ) + ( 44 * m_nSKINNING ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9_360/WaterCheapPerVertexFresnel_vs11.inc b/materialsystem/stdshaders/vshtmp9_360/WaterCheapPerVertexFresnel_vs11.inc new file mode 100644 index 0000000..99282ad --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9_360/WaterCheapPerVertexFresnel_vs11.inc @@ -0,0 +1,57 @@ +class watercheappervertexfresnel_vs11_Static_Index +{ +public: + watercheappervertexfresnel_vs11_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class watercheappervertexfresnel_vs11_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + watercheappervertexfresnel_vs11_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9_360/WaterCheap_vs11.inc b/materialsystem/stdshaders/vshtmp9_360/WaterCheap_vs11.inc new file mode 100644 index 0000000..8928f05 --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9_360/WaterCheap_vs11.inc @@ -0,0 +1,57 @@ +class watercheap_vs11_Static_Index +{ +public: + watercheap_vs11_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class watercheap_vs11_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + watercheap_vs11_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9_360/WaterCheap_vs14.inc b/materialsystem/stdshaders/vshtmp9_360/WaterCheap_vs14.inc new file mode 100644 index 0000000..86f751f --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9_360/WaterCheap_vs14.inc @@ -0,0 +1,57 @@ +class watercheap_vs14_Static_Index +{ +public: + watercheap_vs14_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class watercheap_vs14_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + watercheap_vs14_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9_360/Water_ps14.inc b/materialsystem/stdshaders/vshtmp9_360/Water_ps14.inc new file mode 100644 index 0000000..18e0009 --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9_360/Water_ps14.inc @@ -0,0 +1,57 @@ +class water_ps14_Static_Index +{ +public: + water_ps14_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class water_ps14_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + water_ps14_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9_360/Water_vs11.inc b/materialsystem/stdshaders/vshtmp9_360/Water_vs11.inc new file mode 100644 index 0000000..033251f --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9_360/Water_vs11.inc @@ -0,0 +1,57 @@ +class water_vs11_Static_Index +{ +public: + water_vs11_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class water_vs11_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + water_vs11_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9_360/WorldVertexAlpha.inc b/materialsystem/stdshaders/vshtmp9_360/WorldVertexAlpha.inc new file mode 100644 index 0000000..d2a260c --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9_360/WorldVertexAlpha.inc @@ -0,0 +1,57 @@ +class worldvertexalpha_Static_Index +{ +public: + worldvertexalpha_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class worldvertexalpha_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + worldvertexalpha_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9_360/WorldVertexTransition.inc b/materialsystem/stdshaders/vshtmp9_360/WorldVertexTransition.inc new file mode 100644 index 0000000..5034b05 --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9_360/WorldVertexTransition.inc @@ -0,0 +1,57 @@ +class worldvertextransition_Static_Index +{ +public: + worldvertextransition_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class worldvertextransition_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + worldvertextransition_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9_360/bik_vs11.inc b/materialsystem/stdshaders/vshtmp9_360/bik_vs11.inc new file mode 100644 index 0000000..e076044 --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9_360/bik_vs11.inc @@ -0,0 +1,30 @@ +class bik_vs11_Static_Index +{ +public: + bik_vs11_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class bik_vs11_Dynamic_Index +{ +public: + bik_vs11_Dynamic_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9_360/cloak_blended_pass_dx8_vs11.inc b/materialsystem/stdshaders/vshtmp9_360/cloak_blended_pass_dx8_vs11.inc new file mode 100644 index 0000000..70e7fa9 --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9_360/cloak_blended_pass_dx8_vs11.inc @@ -0,0 +1,57 @@ +class cloak_blended_pass_dx8_vs11_Static_Index +{ +public: + cloak_blended_pass_dx8_vs11_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class cloak_blended_pass_dx8_vs11_Dynamic_Index +{ +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +public: + cloak_blended_pass_dx8_vs11_Dynamic_Index() + { +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bSKINNING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nSKINNING ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9_360/cloud_vs11.inc b/materialsystem/stdshaders/vshtmp9_360/cloud_vs11.inc new file mode 100644 index 0000000..f6ed85b --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9_360/cloud_vs11.inc @@ -0,0 +1,48 @@ +class cloud_vs11_Static_Index +{ +public: + cloud_vs11_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class cloud_vs11_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + } + void SetDOWATERFOG( bool i ) + { + } +public: + cloud_vs11_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9_360/emissive_scroll_blended_pass_dx8_vs11.inc b/materialsystem/stdshaders/vshtmp9_360/emissive_scroll_blended_pass_dx8_vs11.inc new file mode 100644 index 0000000..e8cba9f --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9_360/emissive_scroll_blended_pass_dx8_vs11.inc @@ -0,0 +1,57 @@ +class emissive_scroll_blended_pass_dx8_vs11_Static_Index +{ +public: + emissive_scroll_blended_pass_dx8_vs11_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class emissive_scroll_blended_pass_dx8_vs11_Dynamic_Index +{ +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +public: + emissive_scroll_blended_pass_dx8_vs11_Dynamic_Index() + { +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bSKINNING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nSKINNING ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9_360/eyes_flashlight_vs11.inc b/materialsystem/stdshaders/vshtmp9_360/eyes_flashlight_vs11.inc new file mode 100644 index 0000000..c37a74e --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9_360/eyes_flashlight_vs11.inc @@ -0,0 +1,82 @@ +class eyes_flashlight_vs11_Static_Index +{ +public: + eyes_flashlight_vs11_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class eyes_flashlight_vs11_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +public: + eyes_flashlight_vs11_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG && m_bSKINNING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + ( 2 * m_nSKINNING ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9_360/fillrate.inc b/materialsystem/stdshaders/vshtmp9_360/fillrate.inc new file mode 100644 index 0000000..67060c3 --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9_360/fillrate.inc @@ -0,0 +1,82 @@ +class fillrate_Static_Index +{ +public: + fillrate_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class fillrate_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +public: + fillrate_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG && m_bSKINNING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + ( 2 * m_nSKINNING ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9_360/flesh_interior_blended_pass_dx8_vs11.inc b/materialsystem/stdshaders/vshtmp9_360/flesh_interior_blended_pass_dx8_vs11.inc new file mode 100644 index 0000000..ecdc8ef --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9_360/flesh_interior_blended_pass_dx8_vs11.inc @@ -0,0 +1,57 @@ +class flesh_interior_blended_pass_dx8_vs11_Static_Index +{ +public: + flesh_interior_blended_pass_dx8_vs11_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class flesh_interior_blended_pass_dx8_vs11_Dynamic_Index +{ +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +public: + flesh_interior_blended_pass_dx8_vs11_Dynamic_Index() + { +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bSKINNING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nSKINNING ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9_360/lightmappedgeneric_basetextureblend.inc b/materialsystem/stdshaders/vshtmp9_360/lightmappedgeneric_basetextureblend.inc new file mode 100644 index 0000000..d8608dc --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9_360/lightmappedgeneric_basetextureblend.inc @@ -0,0 +1,57 @@ +class lightmappedgeneric_basetextureblend_Static_Index +{ +public: + lightmappedgeneric_basetextureblend_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class lightmappedgeneric_basetextureblend_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + lightmappedgeneric_basetextureblend_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9_360/lightmappedgeneric_bumpmappedenvmap.inc b/materialsystem/stdshaders/vshtmp9_360/lightmappedgeneric_bumpmappedenvmap.inc new file mode 100644 index 0000000..0da1336 --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9_360/lightmappedgeneric_bumpmappedenvmap.inc @@ -0,0 +1,57 @@ +class lightmappedgeneric_bumpmappedenvmap_Static_Index +{ +public: + lightmappedgeneric_bumpmappedenvmap_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class lightmappedgeneric_bumpmappedenvmap_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + lightmappedgeneric_bumpmappedenvmap_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9_360/lightmappedgeneric_bumpmappedenvmap_ps14.inc b/materialsystem/stdshaders/vshtmp9_360/lightmappedgeneric_bumpmappedenvmap_ps14.inc new file mode 100644 index 0000000..ab20b33 --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9_360/lightmappedgeneric_bumpmappedenvmap_ps14.inc @@ -0,0 +1,57 @@ +class lightmappedgeneric_bumpmappedenvmap_ps14_Static_Index +{ +public: + lightmappedgeneric_bumpmappedenvmap_ps14_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class lightmappedgeneric_bumpmappedenvmap_ps14_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + lightmappedgeneric_bumpmappedenvmap_ps14_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9_360/lightmappedgeneric_bumpmappedlightmap.inc b/materialsystem/stdshaders/vshtmp9_360/lightmappedgeneric_bumpmappedlightmap.inc new file mode 100644 index 0000000..88ca14d --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9_360/lightmappedgeneric_bumpmappedlightmap.inc @@ -0,0 +1,57 @@ +class lightmappedgeneric_bumpmappedlightmap_Static_Index +{ +public: + lightmappedgeneric_bumpmappedlightmap_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class lightmappedgeneric_bumpmappedlightmap_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + lightmappedgeneric_bumpmappedlightmap_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9_360/lightmappedgeneric_vs11.inc b/materialsystem/stdshaders/vshtmp9_360/lightmappedgeneric_vs11.inc new file mode 100644 index 0000000..d16efaa --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9_360/lightmappedgeneric_vs11.inc @@ -0,0 +1,175 @@ +class lightmappedgeneric_vs11_Static_Index +{ +private: + int m_nDETAIL; +#ifdef _DEBUG + bool m_bDETAIL; +#endif +public: + void SetDETAIL( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDETAIL = i; +#ifdef _DEBUG + m_bDETAIL = true; +#endif + } + void SetDETAIL( bool i ) + { + m_nDETAIL = i ? 1 : 0; +#ifdef _DEBUG + m_bDETAIL = true; +#endif + } +private: + int m_nENVMAP; +#ifdef _DEBUG + bool m_bENVMAP; +#endif +public: + void SetENVMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nENVMAP = i; +#ifdef _DEBUG + m_bENVMAP = true; +#endif + } + void SetENVMAP( bool i ) + { + m_nENVMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bENVMAP = true; +#endif + } +private: + int m_nENVMAPCAMERASPACE; +#ifdef _DEBUG + bool m_bENVMAPCAMERASPACE; +#endif +public: + void SetENVMAPCAMERASPACE( int i ) + { + } + void SetENVMAPCAMERASPACE( bool i ) + { + } +private: + int m_nENVMAPSPHERE; +#ifdef _DEBUG + bool m_bENVMAPSPHERE; +#endif +public: + void SetENVMAPSPHERE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nENVMAPSPHERE = i; +#ifdef _DEBUG + m_bENVMAPSPHERE = true; +#endif + } + void SetENVMAPSPHERE( bool i ) + { + m_nENVMAPSPHERE = i ? 1 : 0; +#ifdef _DEBUG + m_bENVMAPSPHERE = true; +#endif + } +private: + int m_nVERTEXCOLOR; +#ifdef _DEBUG + bool m_bVERTEXCOLOR; +#endif +public: + void SetVERTEXCOLOR( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nVERTEXCOLOR = i; +#ifdef _DEBUG + m_bVERTEXCOLOR = true; +#endif + } + void SetVERTEXCOLOR( bool i ) + { + m_nVERTEXCOLOR = i ? 1 : 0; +#ifdef _DEBUG + m_bVERTEXCOLOR = true; +#endif + } +public: + lightmappedgeneric_vs11_Static_Index() + { +#ifdef _DEBUG + m_bDETAIL = false; +#endif // _DEBUG + m_nDETAIL = 0; +#ifdef _DEBUG + m_bENVMAP = false; +#endif // _DEBUG + m_nENVMAP = 0; +#ifdef _DEBUG + m_bENVMAPCAMERASPACE = true; +#endif // _DEBUG + m_nENVMAPCAMERASPACE = 0; +#ifdef _DEBUG + m_bENVMAPSPHERE = false; +#endif // _DEBUG + m_nENVMAPSPHERE = 0; +#ifdef _DEBUG + m_bVERTEXCOLOR = false; +#endif // _DEBUG + m_nVERTEXCOLOR = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bDETAIL && m_bENVMAP && m_bENVMAPCAMERASPACE && m_bENVMAPSPHERE && m_bVERTEXCOLOR; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nDETAIL ) + ( 4 * m_nENVMAP ) + ( 8 * m_nENVMAPCAMERASPACE ) + ( 8 * m_nENVMAPSPHERE ) + ( 16 * m_nVERTEXCOLOR ) + 0; + } +}; +class lightmappedgeneric_vs11_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + lightmappedgeneric_vs11_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9_360/overlay_fit_vs11.inc b/materialsystem/stdshaders/vshtmp9_360/overlay_fit_vs11.inc new file mode 100644 index 0000000..3d4606e --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9_360/overlay_fit_vs11.inc @@ -0,0 +1,57 @@ +class overlay_fit_vs11_Static_Index +{ +public: + overlay_fit_vs11_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class overlay_fit_vs11_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + overlay_fit_vs11_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9_360/predator.inc b/materialsystem/stdshaders/vshtmp9_360/predator.inc new file mode 100644 index 0000000..fed889e --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9_360/predator.inc @@ -0,0 +1,82 @@ +class predator_Static_Index +{ +public: + predator_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class predator_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +public: + predator_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG && m_bSKINNING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + ( 2 * m_nSKINNING ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9_360/shadow_vs14.inc b/materialsystem/stdshaders/vshtmp9_360/shadow_vs14.inc new file mode 100644 index 0000000..97572d5 --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9_360/shadow_vs14.inc @@ -0,0 +1,57 @@ +class shadow_vs14_Static_Index +{ +public: + shadow_vs14_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class shadow_vs14_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + shadow_vs14_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9_360/sprite_vs11.inc b/materialsystem/stdshaders/vshtmp9_360/sprite_vs11.inc new file mode 100644 index 0000000..daabad6 --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9_360/sprite_vs11.inc @@ -0,0 +1,100 @@ +class sprite_vs11_Static_Index +{ +private: + int m_nVERTEXCOLOR; +#ifdef _DEBUG + bool m_bVERTEXCOLOR; +#endif +public: + void SetVERTEXCOLOR( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nVERTEXCOLOR = i; +#ifdef _DEBUG + m_bVERTEXCOLOR = true; +#endif + } + void SetVERTEXCOLOR( bool i ) + { + m_nVERTEXCOLOR = i ? 1 : 0; +#ifdef _DEBUG + m_bVERTEXCOLOR = true; +#endif + } +public: + sprite_vs11_Static_Index() + { +#ifdef _DEBUG + m_bVERTEXCOLOR = false; +#endif // _DEBUG + m_nVERTEXCOLOR = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bVERTEXCOLOR; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 2 * m_nVERTEXCOLOR ) + 0; + } +}; +class sprite_vs11_Dynamic_Index +{ +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + } + void SetSKINNING( bool i ) + { + } +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + sprite_vs11_Dynamic_Index() + { +#ifdef _DEBUG + m_bSKINNING = true; +#endif // _DEBUG + m_nSKINNING = 0; +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bSKINNING && m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nSKINNING ) + ( 1 * m_nDOWATERFOG ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9_360/unlitgeneric_vs11.inc b/materialsystem/stdshaders/vshtmp9_360/unlitgeneric_vs11.inc new file mode 100644 index 0000000..fb1bb21 --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9_360/unlitgeneric_vs11.inc @@ -0,0 +1,225 @@ +class unlitgeneric_vs11_Static_Index +{ +private: + int m_nDETAIL; +#ifdef _DEBUG + bool m_bDETAIL; +#endif +public: + void SetDETAIL( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDETAIL = i; +#ifdef _DEBUG + m_bDETAIL = true; +#endif + } + void SetDETAIL( bool i ) + { + m_nDETAIL = i ? 1 : 0; +#ifdef _DEBUG + m_bDETAIL = true; +#endif + } +private: + int m_nENVMAP; +#ifdef _DEBUG + bool m_bENVMAP; +#endif +public: + void SetENVMAP( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nENVMAP = i; +#ifdef _DEBUG + m_bENVMAP = true; +#endif + } + void SetENVMAP( bool i ) + { + m_nENVMAP = i ? 1 : 0; +#ifdef _DEBUG + m_bENVMAP = true; +#endif + } +private: + int m_nENVMAPCAMERASPACE; +#ifdef _DEBUG + bool m_bENVMAPCAMERASPACE; +#endif +public: + void SetENVMAPCAMERASPACE( int i ) + { + } + void SetENVMAPCAMERASPACE( bool i ) + { + } +private: + int m_nENVMAPSPHERE; +#ifdef _DEBUG + bool m_bENVMAPSPHERE; +#endif +public: + void SetENVMAPSPHERE( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nENVMAPSPHERE = i; +#ifdef _DEBUG + m_bENVMAPSPHERE = true; +#endif + } + void SetENVMAPSPHERE( bool i ) + { + m_nENVMAPSPHERE = i ? 1 : 0; +#ifdef _DEBUG + m_bENVMAPSPHERE = true; +#endif + } +private: + int m_nVERTEXCOLOR; +#ifdef _DEBUG + bool m_bVERTEXCOLOR; +#endif +public: + void SetVERTEXCOLOR( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nVERTEXCOLOR = i; +#ifdef _DEBUG + m_bVERTEXCOLOR = true; +#endif + } + void SetVERTEXCOLOR( bool i ) + { + m_nVERTEXCOLOR = i ? 1 : 0; +#ifdef _DEBUG + m_bVERTEXCOLOR = true; +#endif + } +private: + int m_nSEPARATEDETAILUVS; +#ifdef _DEBUG + bool m_bSEPARATEDETAILUVS; +#endif +public: + void SetSEPARATEDETAILUVS( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSEPARATEDETAILUVS = i; +#ifdef _DEBUG + m_bSEPARATEDETAILUVS = true; +#endif + } + void SetSEPARATEDETAILUVS( bool i ) + { + m_nSEPARATEDETAILUVS = i ? 1 : 0; +#ifdef _DEBUG + m_bSEPARATEDETAILUVS = true; +#endif + } +public: + unlitgeneric_vs11_Static_Index() + { +#ifdef _DEBUG + m_bDETAIL = false; +#endif // _DEBUG + m_nDETAIL = 0; +#ifdef _DEBUG + m_bENVMAP = false; +#endif // _DEBUG + m_nENVMAP = 0; +#ifdef _DEBUG + m_bENVMAPCAMERASPACE = true; +#endif // _DEBUG + m_nENVMAPCAMERASPACE = 0; +#ifdef _DEBUG + m_bENVMAPSPHERE = false; +#endif // _DEBUG + m_nENVMAPSPHERE = 0; +#ifdef _DEBUG + m_bVERTEXCOLOR = false; +#endif // _DEBUG + m_nVERTEXCOLOR = 0; +#ifdef _DEBUG + m_bSEPARATEDETAILUVS = false; +#endif // _DEBUG + m_nSEPARATEDETAILUVS = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bDETAIL && m_bENVMAP && m_bENVMAPCAMERASPACE && m_bENVMAPSPHERE && m_bVERTEXCOLOR && m_bSEPARATEDETAILUVS; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 4 * m_nDETAIL ) + ( 8 * m_nENVMAP ) + ( 16 * m_nENVMAPCAMERASPACE ) + ( 16 * m_nENVMAPSPHERE ) + ( 32 * m_nVERTEXCOLOR ) + ( 64 * m_nSEPARATEDETAILUVS ) + 0; + } +}; +class unlitgeneric_vs11_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +public: + unlitgeneric_vs11_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG && m_bSKINNING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + ( 2 * m_nSKINNING ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9_360/vertexlitgeneric_flashlight_vs11.inc b/materialsystem/stdshaders/vshtmp9_360/vertexlitgeneric_flashlight_vs11.inc new file mode 100644 index 0000000..41b87c0 --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9_360/vertexlitgeneric_flashlight_vs11.inc @@ -0,0 +1,109 @@ +class vertexlitgeneric_flashlight_vs11_Static_Index +{ +private: + int m_nTEETH; +#ifdef _DEBUG + bool m_bTEETH; +#endif +public: + void SetTEETH( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nTEETH = i; +#ifdef _DEBUG + m_bTEETH = true; +#endif + } + void SetTEETH( bool i ) + { + m_nTEETH = i ? 1 : 0; +#ifdef _DEBUG + m_bTEETH = true; +#endif + } +public: + vertexlitgeneric_flashlight_vs11_Static_Index() + { +#ifdef _DEBUG + m_bTEETH = false; +#endif // _DEBUG + m_nTEETH = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bTEETH; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 4 * m_nTEETH ) + 0; + } +}; +class vertexlitgeneric_flashlight_vs11_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +public: + vertexlitgeneric_flashlight_vs11_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG && m_bSKINNING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + ( 2 * m_nSKINNING ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9_360/vortwarp_vs11.inc b/materialsystem/stdshaders/vshtmp9_360/vortwarp_vs11.inc new file mode 100644 index 0000000..77d43a3 --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9_360/vortwarp_vs11.inc @@ -0,0 +1,134 @@ +class vortwarp_vs11_Static_Index +{ +private: + int m_nUNLIT; +#ifdef _DEBUG + bool m_bUNLIT; +#endif +public: + void SetUNLIT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nUNLIT = i; +#ifdef _DEBUG + m_bUNLIT = true; +#endif + } + void SetUNLIT( bool i ) + { + m_nUNLIT = i ? 1 : 0; +#ifdef _DEBUG + m_bUNLIT = true; +#endif + } +private: + int m_nHALF_LAMBERT; +#ifdef _DEBUG + bool m_bHALF_LAMBERT; +#endif +public: + void SetHALF_LAMBERT( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nHALF_LAMBERT = i; +#ifdef _DEBUG + m_bHALF_LAMBERT = true; +#endif + } + void SetHALF_LAMBERT( bool i ) + { + m_nHALF_LAMBERT = i ? 1 : 0; +#ifdef _DEBUG + m_bHALF_LAMBERT = true; +#endif + } +public: + vortwarp_vs11_Static_Index() + { +#ifdef _DEBUG + m_bUNLIT = false; +#endif // _DEBUG + m_nUNLIT = 0; +#ifdef _DEBUG + m_bHALF_LAMBERT = false; +#endif // _DEBUG + m_nHALF_LAMBERT = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllStaticVarsDefined = m_bUNLIT && m_bHALF_LAMBERT; + Assert( bAllStaticVarsDefined ); +#endif // _DEBUG + return ( 44 * m_nUNLIT ) + ( 88 * m_nHALF_LAMBERT ) + 0; + } +}; +class vortwarp_vs11_Dynamic_Index +{ +private: + int m_nLIGHT_COMBO; +#ifdef _DEBUG + bool m_bLIGHT_COMBO; +#endif +public: + void SetLIGHT_COMBO( int i ) + { + Assert( i >= 0 && i <= 21 ); + m_nLIGHT_COMBO = i; +#ifdef _DEBUG + m_bLIGHT_COMBO = true; +#endif + } + void SetLIGHT_COMBO( bool i ) + { + m_nLIGHT_COMBO = i ? 1 : 0; +#ifdef _DEBUG + m_bLIGHT_COMBO = true; +#endif + } +private: + int m_nSKINNING; +#ifdef _DEBUG + bool m_bSKINNING; +#endif +public: + void SetSKINNING( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nSKINNING = i; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } + void SetSKINNING( bool i ) + { + m_nSKINNING = i ? 1 : 0; +#ifdef _DEBUG + m_bSKINNING = true; +#endif + } +public: + vortwarp_vs11_Dynamic_Index() + { +#ifdef _DEBUG + m_bLIGHT_COMBO = false; +#endif // _DEBUG + m_nLIGHT_COMBO = 0; +#ifdef _DEBUG + m_bSKINNING = false; +#endif // _DEBUG + m_nSKINNING = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bLIGHT_COMBO && m_bSKINNING; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nLIGHT_COMBO ) + ( 22 * m_nSKINNING ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9_360/worldvertextransition_seamless.inc b/materialsystem/stdshaders/vshtmp9_360/worldvertextransition_seamless.inc new file mode 100644 index 0000000..b64798d --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9_360/worldvertextransition_seamless.inc @@ -0,0 +1,57 @@ +class worldvertextransition_seamless_Static_Index +{ +public: + worldvertextransition_seamless_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class worldvertextransition_seamless_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + worldvertextransition_seamless_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9_360/worldvertextransition_vs14.inc b/materialsystem/stdshaders/vshtmp9_360/worldvertextransition_vs14.inc new file mode 100644 index 0000000..5991050 --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9_360/worldvertextransition_vs14.inc @@ -0,0 +1,57 @@ +class worldvertextransition_vs14_Static_Index +{ +public: + worldvertextransition_vs14_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class worldvertextransition_vs14_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + worldvertextransition_vs14_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; diff --git a/materialsystem/stdshaders/vshtmp9_360/writez.inc b/materialsystem/stdshaders/vshtmp9_360/writez.inc new file mode 100644 index 0000000..82c36f0 --- /dev/null +++ b/materialsystem/stdshaders/vshtmp9_360/writez.inc @@ -0,0 +1,57 @@ +class writez_Static_Index +{ +public: + writez_Static_Index() + { + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG +#endif // _DEBUG + return 0; + } +}; +class writez_Dynamic_Index +{ +private: + int m_nDOWATERFOG; +#ifdef _DEBUG + bool m_bDOWATERFOG; +#endif +public: + void SetDOWATERFOG( int i ) + { + Assert( i >= 0 && i <= 1 ); + m_nDOWATERFOG = i; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } + void SetDOWATERFOG( bool i ) + { + m_nDOWATERFOG = i ? 1 : 0; +#ifdef _DEBUG + m_bDOWATERFOG = true; +#endif + } +public: + writez_Dynamic_Index() + { +#ifdef _DEBUG + m_bDOWATERFOG = false; +#endif // _DEBUG + m_nDOWATERFOG = 0; + } + int GetIndex() + { + // Asserts to make sure that we aren't using any skipped combinations. + // Asserts to make sure that we are setting all of the combination vars. +#ifdef _DEBUG + bool bAllDynamicVarsDefined = m_bDOWATERFOG; + Assert( bAllDynamicVarsDefined ); +#endif // _DEBUG + return ( 1 * m_nDOWATERFOG ) + 0; + } +}; diff --git a/materialsystem/stdshaders/warp.cpp b/materialsystem/stdshaders/warp.cpp new file mode 100644 index 0000000..17f80fb --- /dev/null +++ b/materialsystem/stdshaders/warp.cpp @@ -0,0 +1,251 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//============================================================================= + +#include "BaseVSShader.h" +#include "commandbuilder.h" + +#include "warp_ps20.inc" +#include "warp_ps20b.inc" +#include "warp_vs20.inc" +#include "warp_ps30.inc" +#include "warp_vs30.inc" + +#include "../materialsystem_global.h" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + + + + + + + +class CWarp_DX9_Context : public CBasePerMaterialContextData +{ +public: + uint8 *m_pStaticCmds; + CCommandBufferBuilder< CFixedCommandStorageBuffer< 1000 > > m_SemiStaticCmdsOut; + + void ResetStaticCmds( void ) + { + if ( m_pStaticCmds ) + { + delete[] m_pStaticCmds; + m_pStaticCmds = NULL; + } + } + + CWarp_DX9_Context( void ) + { + m_pStaticCmds = NULL; + } + + ~CWarp_DX9_Context( void ) + { + ResetStaticCmds(); + } + +}; + + +static const float kAllZeros[ 4 ] = { 0.0f, 0.0f, 0.0f, 0.0f }; + + +BEGIN_VS_SHADER( warp, "Help for warp" ) + BEGIN_SHADER_PARAMS + + SHADER_PARAM( BASETEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "" ) + + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + } + + SHADER_FALLBACK + { + return 0; + } + + SHADER_INIT + { + LoadTexture( BASETEXTURE, TEXTUREFLAGS_SRGB ); + } + + SHADER_DRAW + { + CWarp_DX9_Context *pContextData = reinterpret_cast< CWarp_DX9_Context *> ( *pContextDataPtr ); + bool bNeedRegenStaticCmds = ( !pContextData ) || pShaderShadow; + + if ( !pContextData ) // make sure allocated + { + pContextData = new CWarp_DX9_Context; + *pContextDataPtr = pContextData; + } + + if ( pShaderShadow || bNeedRegenStaticCmds ) + { + pContextData->ResetStaticCmds(); + CCommandBufferBuilder< CFixedCommandStorageBuffer< 5000 > > staticCmdsBuf; + + staticCmdsBuf.BindTexture( this, SHADER_SAMPLER0, BASETEXTURE, -1 ); + + staticCmdsBuf.End(); + + // now, copy buf + pContextData->m_pStaticCmds = new uint8[ staticCmdsBuf.Size() ]; + memcpy( pContextData->m_pStaticCmds, staticCmdsBuf.Base(), staticCmdsBuf.Size() ); + } + + if ( pShaderAPI && pContextData->m_bMaterialVarsChanged ) + { + // need to regenerate the semistatic cmds + pContextData->m_SemiStaticCmdsOut.Reset(); + pContextData->m_bMaterialVarsChanged = false; + + pContextData->m_SemiStaticCmdsOut.SetAmbientCubeDynamicStateVertexShader(); + pContextData->m_SemiStaticCmdsOut.End(); + } + + SHADOW_STATE + { + SetInitialShadowState( ); + + pShaderShadow->EnableDepthWrites( false ); + pShaderShadow->EnableDepthTest( false ); + + pShaderShadow->EnableBlending( false ); + + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, true ); + + pShaderShadow->EnableSRGBWrite( true ); + pShaderShadow->EnableAlphaWrites( false ); + pShaderShadow->EnableAlphaTest( false ); + + DefaultFog(); + + int nFormat = 0; + nFormat |= VERTEX_POSITION; + pShaderShadow->VertexShaderVertexFormat( nFormat, 2, 0, 0 ); + + if ( !g_pHardwareConfig->SupportsShaderModel_3_0() ) + { + DECLARE_STATIC_VERTEX_SHADER( warp_vs20 ); + SET_STATIC_VERTEX_SHADER( warp_vs20 ); + + if ( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_STATIC_PIXEL_SHADER( warp_ps20b ); + SET_STATIC_PIXEL_SHADER( warp_ps20b ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( warp_ps20 ); + SET_STATIC_PIXEL_SHADER( warp_ps20 ); + } + } + else + { + DECLARE_STATIC_VERTEX_SHADER( warp_vs30 ); + SET_STATIC_VERTEX_SHADER( warp_vs30 ); + + DECLARE_STATIC_PIXEL_SHADER( warp_ps30 ); + SET_STATIC_PIXEL_SHADER( warp_ps30 ); + } + } + + DYNAMIC_STATE + { + CCommandBufferBuilder< CFixedCommandStorageBuffer< 1000 > > DynamicCmdsOut; + DynamicCmdsOut.Call( pContextData->m_pStaticCmds ); + DynamicCmdsOut.Call( pContextData->m_SemiStaticCmdsOut.Base() ); + + pShaderAPI->SetDefaultState(); + + Vector4D vParms; + Vector vTemp; + + // GetVectorRenderingParameter only return a Vec3, not a Vec4, so I need to repack these :-( + vTemp = pShaderAPI->GetVectorRenderingParameter ( VECTOR_RENDERPARM_HMDWARP_GROW_OUTIN ); + vParms.x = vTemp.x; + vParms.y = vTemp.y; + vTemp = pShaderAPI->GetVectorRenderingParameter ( VECTOR_RENDERPARM_HMDWARP_GROW_ABOVEBELOW ); + vParms.z = vTemp.x; + vParms.w = vTemp.y; + pShaderAPI->SetPixelShaderConstant( 0, vParms.Base() ); + + vTemp = pShaderAPI->GetVectorRenderingParameter ( VECTOR_RENDERPARM_HMDWARP_LEFT_CENTRE ); + vParms.x = vTemp.x; + vParms.y = vTemp.y; + vTemp = pShaderAPI->GetVectorRenderingParameter ( VECTOR_RENDERPARM_HMDWARP_RIGHT_CENTRE ); + vParms.z = vTemp.x; + vParms.w = vTemp.y; + pShaderAPI->SetPixelShaderConstant( 1, vParms.Base() ); + + vTemp = pShaderAPI->GetVectorRenderingParameter ( VECTOR_RENDERPARM_HMDWARP_LEFT_COEFF012 ); + vParms.x = vTemp.x; + vParms.y = vTemp.y; + vParms.z = vTemp.z; + vTemp = pShaderAPI->GetVectorRenderingParameter ( VECTOR_RENDERPARM_HMDWARP_LEFT_COEFF34_RED_OFFSET ); + vParms.w = vTemp.z; // Red offset + // Shader doesn't support a 4th & 5th coefficient (yet?). + pShaderAPI->SetPixelShaderConstant( 2, vParms.Base() ); + + vTemp = pShaderAPI->GetVectorRenderingParameter ( VECTOR_RENDERPARM_HMDWARP_RIGHT_COEFF012 ); + vParms.x = vTemp.x; + vParms.y = vTemp.y; + vParms.z = vTemp.z; + vTemp = pShaderAPI->GetVectorRenderingParameter ( VECTOR_RENDERPARM_HMDWARP_RIGHT_COEFF34_BLUE_OFFSET ); + vParms.w = vTemp.z; // Blue offset + // Shader doesn't support a 4th & 5th coefficient (yet?). + pShaderAPI->SetPixelShaderConstant( 3, vParms.Base() ); + + vTemp = pShaderAPI->GetVectorRenderingParameter ( VECTOR_RENDERPARM_HMDWARP_ASPECT ); + vParms.x = vTemp.x; + vParms.y = vTemp.y; + vParms.z = vTemp.z; + vParms.w = 0.0f; + pShaderAPI->SetPixelShaderConstant( 4, vParms.Base() ); + + int nDistortType = pShaderAPI->GetIntRenderingParameter( INT_RENDERPARM_DISTORTION_TYPE ); + + if ( !g_pHardwareConfig->SupportsShaderModel_3_0() ) + { + DECLARE_DYNAMIC_VERTEX_SHADER( warp_vs20 ); + SET_DYNAMIC_VERTEX_SHADER( warp_vs20 ); + + if ( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_DYNAMIC_PIXEL_SHADER( warp_ps20b ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( DISTORT_TYPE, nDistortType ); + SET_DYNAMIC_PIXEL_SHADER( warp_ps20b ); + } + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( warp_ps20 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( DISTORT_TYPE, nDistortType ); + SET_DYNAMIC_PIXEL_SHADER( warp_ps20 ); + } + } + else + { + DECLARE_DYNAMIC_VERTEX_SHADER( warp_vs30 ); + SET_DYNAMIC_VERTEX_SHADER( warp_vs30 ); + + DECLARE_DYNAMIC_PIXEL_SHADER( warp_ps30 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( DISTORT_TYPE, nDistortType ); + SET_DYNAMIC_PIXEL_SHADER( warp_ps30 ); + } + + DynamicCmdsOut.End(); + pShaderAPI->ExecuteCommandBuffer( DynamicCmdsOut.Base() ); + } + Draw(); + } +END_SHADER diff --git a/materialsystem/stdshaders/warp_ps2x.fxc b/materialsystem/stdshaders/warp_ps2x.fxc new file mode 100644 index 0000000..b0b41a9 --- /dev/null +++ b/materialsystem/stdshaders/warp_ps2x.fxc @@ -0,0 +1,210 @@ +// DYNAMIC: "DISTORT_TYPE" "0..2" + +#include "shader_constant_register_map.h" +#include "common_ps_fxc.h" + +sampler BaseTextureSampler : register( s0 ); + + +// Faster, but less readable maths. +#define OPTIMISED 1 + + + +const float4 g_vWarpParms0 : register( c0 ); +#if OPTIMISED +#define stereo_distortion_ScaleX g_vWarpParms0.x +#define stereo_distortion_OffsetX g_vWarpParms0.y +#define stereo_distortion_ScaleY g_vWarpParms0.z +#define stereo_distortion_OffsetY g_vWarpParms0.w +#else +#define stereo_distortion_grow_outside g_vWarpParms0.x +#define stereo_distortion_grow_inside g_vWarpParms0.y +#define stereo_distortion_grow_above g_vWarpParms0.z +#define stereo_distortion_grow_below g_vWarpParms0.w +#endif + +const float4 g_vWarpParms1 : register( c1 ); +#define distortion_l_centre g_vWarpParms1.xy +#define distortion_r_centre g_vWarpParms1.zw + +const float4 g_vWarpParms2 : register( c2 ); +#define distortion_l_coeff0 g_vWarpParms2.x +#define distortion_l_coeff1 g_vWarpParms2.y +#define distortion_l_coeff2 g_vWarpParms2.z +#define distortion_red_coeff0delta g_vWarpParms2.w + +const float4 g_vWarpParms3 : register( c3 ); +#define distortion_r_coeff0 g_vWarpParms3.x +#define distortion_r_coeff1 g_vWarpParms3.y +#define distortion_r_coeff2 g_vWarpParms3.z +#define distortion_blue_coeff0delta g_vWarpParms3.w + +const float4 g_vWarpParms4 : register( c4 ); +#define aspect_height_over_width_t2 g_vWarpParms4.x + + +struct PS_INPUT +{ + float2 vBaseTexCoord : TEXCOORD0; +}; + + +float4 main( PS_INPUT i ) : COLOR +{ + float2 vOriginal = i.vBaseTexCoord.xy; + float BaseX; + + float2 centre; + float dcoeff0; + float dcoeff1; + float dcoeff2; + +#if OPTIMISED + float stereo_distortion_OffsetX_Corrected; +#else + float stereo_distortion_grow_left; + float stereo_distortion_grow_right; +#endif + + if ( vOriginal.x < 0.5 ) + { + BaseX = 0.25; +#if OPTIMISED + stereo_distortion_OffsetX_Corrected = stereo_distortion_OffsetX; +#else + stereo_distortion_grow_left = stereo_distortion_grow_outside; + stereo_distortion_grow_right = stereo_distortion_grow_inside; +#endif + + centre = distortion_l_centre; + dcoeff0 = distortion_l_coeff0; + dcoeff1 = distortion_l_coeff1; + dcoeff2 = distortion_l_coeff2; + } + else + { + BaseX = 0.75; +#if OPTIMISED + stereo_distortion_OffsetX_Corrected = -stereo_distortion_OffsetX; +#else + stereo_distortion_grow_left = stereo_distortion_grow_inside; + stereo_distortion_grow_right = stereo_distortion_grow_outside; +#endif + + centre = distortion_r_centre; + dcoeff0 = distortion_r_coeff0; + dcoeff1 = distortion_r_coeff1; + dcoeff2 = distortion_r_coeff2; + } + + float fLocalAspectHeightOverWidthTimes2 = aspect_height_over_width_t2; + + float2 Delta; + Delta.x = ( vOriginal.x - BaseX ) * 4.0; + Delta.y = ( vOriginal.y - 0.5 ) * fLocalAspectHeightOverWidthTimes2; + + // Delta now runs from -1.0 to +1.0, i.e. NDC, of the right/left destination (i.e. left/right half of the rendertarget). + // Vertically, it has the same scale in pixels as horizontally, but because the aspect ratio is usually not 1:1, the range may be larger or smaller than [-1,+1] + + // Offset by the calibration center. + Delta -= centre; + + float r2 = Delta.x * Delta.x + Delta.y * Delta.y; + + // case DISTORT_DPOLY3: + // { + // T rdistortion = T(1.0) / (T(1.0) + r2 * (T(dcoeff[0]) + r2 * (T(dcoeff[1]) + r2 * T(dcoeff[2])))); + // xp = xp*rdistortion; + // yp = yp*rdistortion; + // } + // break; + + float rdistortion_r = 1.0; + float rdistortion_g = 1.0; + float rdistortion_b = 1.0; + #if ( DISTORT_TYPE == 1 ) + { + rdistortion_r = 1.0 / (1.0 + r2 * ((dcoeff0+distortion_red_coeff0delta) + r2 * (dcoeff1 + r2 * dcoeff2))); + rdistortion_g = 1.0 / (1.0 + r2 * ( dcoeff0 + r2 * (dcoeff1 + r2 * dcoeff2))); + rdistortion_b = 1.0 / (1.0 + r2 * ((dcoeff0+distortion_blue_coeff0delta) + r2 * (dcoeff1 + r2 * dcoeff2))); + } + #elif ( DISTORT_TYPE == 2 ) + { + rdistortion_r = (1.0 + r2 * ((dcoeff0+distortion_red_coeff0delta) + r2 * (dcoeff1 + r2 * dcoeff2))); + rdistortion_g = (1.0 + r2 * ( dcoeff0 + r2 * (dcoeff1 + r2 * dcoeff2))); + rdistortion_b = (1.0 + r2 * ((dcoeff0+distortion_blue_coeff0delta) + r2 * (dcoeff1 + r2 * dcoeff2))); + } + #endif + + float2 DeltaR = Delta * rdistortion_r; + float2 DeltaG = Delta * rdistortion_g; + float2 DeltaB = Delta * rdistortion_b; + + // Offset back from the calibration center. + DeltaR += centre; + DeltaG += centre; + DeltaB += centre; + + float inv_aspect = 2.0 / fLocalAspectHeightOverWidthTimes2; + +#if OPTIMISED + + float stereo_distortion_ScaleY_corrected = stereo_distortion_ScaleY * inv_aspect; + + DeltaR.x = DeltaR.x * stereo_distortion_ScaleX + stereo_distortion_OffsetX_Corrected; + DeltaR.y = DeltaR.y * stereo_distortion_ScaleY_corrected + stereo_distortion_OffsetY; + DeltaG.x = DeltaG.x * stereo_distortion_ScaleX + stereo_distortion_OffsetX_Corrected; + DeltaG.y = DeltaG.y * stereo_distortion_ScaleY_corrected + stereo_distortion_OffsetY; + DeltaB.x = DeltaB.x * stereo_distortion_ScaleX + stereo_distortion_OffsetX_Corrected; + DeltaB.y = DeltaB.y * stereo_distortion_ScaleY_corrected + stereo_distortion_OffsetY; + +#else + + // This is now in NDC of the left/right half of the source, if there was no distortion growth. + // So now include the growth. + float ScaleX = 2.0f / ( stereo_distortion_grow_left + stereo_distortion_grow_right + 2.0f ); + float ScaleY = 2.0f / ( stereo_distortion_grow_above + stereo_distortion_grow_below + 2.0f ); + float OffsetX = ( stereo_distortion_grow_left - stereo_distortion_grow_right ) * ScaleX * 0.5; + float OffsetY = ( stereo_distortion_grow_above - stereo_distortion_grow_below ) * ScaleY * 0.5; + + ScaleY *= inv_aspect; + + DeltaR.x = DeltaR.x * ScaleX + OffsetX; + DeltaR.y = DeltaR.y * ScaleY + OffsetY; + DeltaG.x = DeltaG.x * ScaleX + OffsetX; + DeltaG.y = DeltaG.y * ScaleY + OffsetY; + DeltaB.x = DeltaB.x * ScaleX + OffsetX; + DeltaB.y = DeltaB.y * ScaleY + OffsetY; + +#endif + + // Now convert back to useful texcoords. + float2 PixPosR, PixPosG, PixPosB; + PixPosR.x = DeltaR.x * 0.25 + BaseX; + PixPosR.y = DeltaR.y * 0.5 + 0.5; + PixPosG.x = DeltaG.x * 0.25 + BaseX; + PixPosG.y = DeltaG.y * 0.5 + 0.5; + PixPosB.x = DeltaB.x * 0.25 + BaseX; + PixPosB.y = DeltaB.y * 0.5 + 0.5; + + float4 vFinal = 0.0; + if ( ( DeltaG.x > -1.0 ) && ( DeltaG.y > -1.0 ) && ( DeltaG.x < 1.0 ) && ( DeltaG.y < 1.0 ) ) + { + vFinal.r = tex2D( BaseTextureSampler, PixPosR ).r; + vFinal.g = tex2D( BaseTextureSampler, PixPosG ).g; + vFinal.b = tex2D( BaseTextureSampler, PixPosB ).b; + } + +#if 0 // useful for checking where the center of distortion is. + if ( ( r2 > 0.45*0.45 ) && ( r2 < 0.55*0.55 ) ) + { + vFinal.g = 0.0; + } +#endif + + return vFinal; +} + + + diff --git a/materialsystem/stdshaders/warp_vs20.fxc b/materialsystem/stdshaders/warp_vs20.fxc new file mode 100644 index 0000000..b82bfa1 --- /dev/null +++ b/materialsystem/stdshaders/warp_vs20.fxc @@ -0,0 +1,26 @@ +#include "common_vs_fxc.h" + + +struct VS_INPUT +{ + float4 vPos : POSITION; + float2 vBaseTexCoord : TEXCOORD0; +}; + + +struct VS_OUTPUT +{ + float4 vProjPos : POSITION; + float2 vBaseTexCoord : TEXCOORD0; +}; + + +VS_OUTPUT main( const VS_INPUT v ) +{ + VS_OUTPUT o; + + o.vProjPos = v.vPos; + o.vBaseTexCoord = v.vBaseTexCoord; + + return o; +} diff --git a/materialsystem/stdshaders/water.cpp b/materialsystem/stdshaders/water.cpp new file mode 100644 index 0000000..f980030 --- /dev/null +++ b/materialsystem/stdshaders/water.cpp @@ -0,0 +1,592 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//=============================================================================// + +#include "BaseVSShader.h" +#include "mathlib/vmatrix.h" +#include "common_hlsl_cpp_consts.h" // hack hack hack! +#include "convar.h" + +#include "WaterCheap_vs20.inc" +#include "WaterCheap_ps20.inc" +#include "WaterCheap_ps20b.inc" +#include "Water_vs20.inc" +#include "Water_ps20.inc" +#include "water_ps20b.inc" + +#ifndef _X360 +static ConVar r_waterforceexpensive( "r_waterforceexpensive", "0", FCVAR_ARCHIVE ); +#endif + +DEFINE_FALLBACK_SHADER( Water, Water_DX9_HDR ) + +BEGIN_VS_SHADER( Water_DX90, + "Help for Water" ) + + BEGIN_SHADER_PARAMS + SHADER_PARAM( REFRACTTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "_rt_WaterRefraction", "" ) + SHADER_PARAM( REFLECTTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "_rt_WaterReflection", "" ) + SHADER_PARAM( REFRACTAMOUNT, SHADER_PARAM_TYPE_FLOAT, "0", "" ) + SHADER_PARAM( REFRACTTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "refraction tint" ) + SHADER_PARAM( REFLECTAMOUNT, SHADER_PARAM_TYPE_FLOAT, "0.8", "" ) + SHADER_PARAM( REFLECTTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "reflection tint" ) + SHADER_PARAM( NORMALMAP, SHADER_PARAM_TYPE_TEXTURE, "dev/water_normal", "normal map" ) + SHADER_PARAM( BUMPFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $bumpmap" ) + SHADER_PARAM( BUMPTRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$bumpmap texcoord transform" ) + SHADER_PARAM( SCALE, SHADER_PARAM_TYPE_VEC2, "[1 1]", "" ) + SHADER_PARAM( TIME, SHADER_PARAM_TYPE_FLOAT, "", "" ) + SHADER_PARAM( WATERDEPTH, SHADER_PARAM_TYPE_FLOAT, "", "" ) + SHADER_PARAM( CHEAPWATERSTARTDISTANCE, SHADER_PARAM_TYPE_FLOAT, "", "This is the distance from the eye in inches that the shader should start transitioning to a cheaper water shader." ) + SHADER_PARAM( CHEAPWATERENDDISTANCE, SHADER_PARAM_TYPE_FLOAT, "", "This is the distance from the eye in inches that the shader should finish transitioning to a cheaper water shader." ) + SHADER_PARAM( ENVMAP, SHADER_PARAM_TYPE_TEXTURE, "env_cubemap", "envmap" ) + SHADER_PARAM( ENVMAPFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "" ) + SHADER_PARAM( FOGCOLOR, SHADER_PARAM_TYPE_COLOR, "", "" ) + SHADER_PARAM( FORCECHEAP, SHADER_PARAM_TYPE_BOOL, "", "" ) + SHADER_PARAM( FORCEEXPENSIVE, SHADER_PARAM_TYPE_BOOL, "", "" ) + SHADER_PARAM( REFLECTENTITIES, SHADER_PARAM_TYPE_BOOL, "", "" ) + SHADER_PARAM( FOGSTART, SHADER_PARAM_TYPE_FLOAT, "", "" ) + SHADER_PARAM( FOGEND, SHADER_PARAM_TYPE_FLOAT, "", "" ) + SHADER_PARAM( ABOVEWATER, SHADER_PARAM_TYPE_BOOL, "", "" ) + SHADER_PARAM( REFLECTBLENDFACTOR, SHADER_PARAM_TYPE_FLOAT, "1.0", "" ) + SHADER_PARAM( NOFRESNEL, SHADER_PARAM_TYPE_BOOL, "0", "" ) + SHADER_PARAM( NOLOWENDLIGHTMAP, SHADER_PARAM_TYPE_BOOL, "0", "" ) + SHADER_PARAM( SCROLL1, SHADER_PARAM_TYPE_COLOR, "", "" ) + SHADER_PARAM( SCROLL2, SHADER_PARAM_TYPE_COLOR, "", "" ) + SHADER_PARAM( BLURREFRACT, SHADER_PARAM_TYPE_BOOL, "0", "Cause the refraction to be blurry on ps2b hardware" ) + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + if( !params[ABOVEWATER]->IsDefined() ) + { + Warning( "***need to set $abovewater for material %s\n", pMaterialName ); + params[ABOVEWATER]->SetIntValue( 1 ); + } + SET_FLAGS2( MATERIAL_VAR2_NEEDS_TANGENT_SPACES ); + if( !params[CHEAPWATERSTARTDISTANCE]->IsDefined() ) + { + params[CHEAPWATERSTARTDISTANCE]->SetFloatValue( 500.0f ); + } + if( !params[CHEAPWATERENDDISTANCE]->IsDefined() ) + { + params[CHEAPWATERENDDISTANCE]->SetFloatValue( 1000.0f ); + } + if( !params[SCALE]->IsDefined() ) + { + params[SCALE]->SetVecValue( 1.0f, 1.0f ); + } + if( !params[SCROLL1]->IsDefined() ) + { + params[SCROLL1]->SetVecValue( 0.0f, 0.0f, 0.0f ); + } + if( !params[SCROLL2]->IsDefined() ) + { + params[SCROLL2]->SetVecValue( 0.0f, 0.0f, 0.0f ); + } + if( !params[FOGCOLOR]->IsDefined() ) + { + params[FOGCOLOR]->SetVecValue( 1.0f, 0.0f, 0.0f ); + Warning( "material %s needs to have a $fogcolor.\n", pMaterialName ); + } + if( !params[REFLECTENTITIES]->IsDefined() ) + { + params[REFLECTENTITIES]->SetIntValue( 0 ); + } + if( !params[REFLECTBLENDFACTOR]->IsDefined() ) + { + params[REFLECTBLENDFACTOR]->SetFloatValue( 1.0f ); + } + + // By default, we're force expensive on dx9. NO WE DON'T!!!! + if( !params[FORCEEXPENSIVE]->IsDefined() ) + { +#ifdef _X360 + params[FORCEEXPENSIVE]->SetIntValue( 0 ); +#else + params[FORCEEXPENSIVE]->SetIntValue( 1 ); +#endif + } + if( params[FORCEEXPENSIVE]->GetIntValue() && params[FORCECHEAP]->GetIntValue() ) + { + params[FORCEEXPENSIVE]->SetIntValue( 0 ); + } + + // Fallbacks for water need lightmaps usually + if ( !params[NOLOWENDLIGHTMAP]->GetIntValue() ) + { + SET_FLAGS2( MATERIAL_VAR2_LIGHTING_LIGHTMAP ); + } + + SET_FLAGS2( MATERIAL_VAR2_LIGHTING_LIGHTMAP ); + if( g_pConfig->UseBumpmapping() && params[NORMALMAP]->IsDefined() ) + { + SET_FLAGS2( MATERIAL_VAR2_LIGHTING_BUMPED_LIGHTMAP ); + } + } + + SHADER_FALLBACK + { + if( g_pHardwareConfig->GetDXSupportLevel() < 90 ) + { + return "Water_DX81"; + } + return 0; + } + + SHADER_INIT + { + Assert( params[WATERDEPTH]->IsDefined() ); + + if( params[REFRACTTEXTURE]->IsDefined() ) + { + LoadTexture( REFRACTTEXTURE, TEXTUREFLAGS_SRGB ); + } + if( params[REFLECTTEXTURE]->IsDefined() ) + { + LoadTexture( REFLECTTEXTURE, TEXTUREFLAGS_SRGB ); + } + if ( params[ENVMAP]->IsDefined() ) + { + LoadCubeMap( ENVMAP, TEXTUREFLAGS_SRGB ); + } + if ( params[NORMALMAP]->IsDefined() ) + { + LoadBumpMap( NORMALMAP ); + } + if( params[BASETEXTURE]->IsDefined() ) + { + LoadTexture( BASETEXTURE, TEXTUREFLAGS_SRGB ); + } + } + + inline void GetVecParam( int constantVar, float *val ) + { + if( constantVar == -1 ) + return; + + IMaterialVar* pVar = s_ppParams[constantVar]; + Assert( pVar ); + + if (pVar->GetType() == MATERIAL_VAR_TYPE_VECTOR) + pVar->GetVecValue( val, 4 ); + else + val[0] = val[1] = val[2] = val[3] = pVar->GetFloatValue(); + } + + inline void DrawReflectionRefraction( IMaterialVar **params, IShaderShadow* pShaderShadow, + IShaderDynamicAPI* pShaderAPI, bool bReflection, bool bRefraction ) + { + SHADOW_STATE + { + SetInitialShadowState( ); + if( bRefraction ) + { + // refract sampler + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, true ); + } + if( bReflection ) + { + // reflect sampler + pShaderShadow->EnableTexture( SHADER_SAMPLER2, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER3, true ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER2, true ); + if( params[BASETEXTURE]->IsTexture() ) + { + // BASETEXTURE + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER1, true ); + // LIGHTMAP + pShaderShadow->EnableTexture( SHADER_SAMPLER3, true ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER3, true ); + } + } + // normal map + pShaderShadow->EnableTexture( SHADER_SAMPLER4, true ); + // Normalizing cube map + pShaderShadow->EnableTexture( SHADER_SAMPLER5, true ); + + int fmt = VERTEX_POSITION | VERTEX_NORMAL | VERTEX_TANGENT_S | VERTEX_TANGENT_T; + + // texcoord0 : base texcoord + // texcoord1 : lightmap texcoord + // texcoord2 : lightmap texcoord offset + int numTexCoords = 1; + if( params[BASETEXTURE]->IsTexture() ) + { + numTexCoords = 3; + } + pShaderShadow->VertexShaderVertexFormat( fmt, numTexCoords, 0, 0 ); + + Vector4D Scroll1; + params[SCROLL1]->GetVecValue( Scroll1.Base(), 4 ); + + DECLARE_STATIC_VERTEX_SHADER( water_vs20 ); + SET_STATIC_VERTEX_SHADER_COMBO( MULTITEXTURE,fabs(Scroll1.x) > 0.0); + SET_STATIC_VERTEX_SHADER_COMBO( BASETEXTURE, params[BASETEXTURE]->IsTexture() ); + SET_STATIC_VERTEX_SHADER( water_vs20 ); + + // "REFLECT" "0..1" + // "REFRACT" "0..1" + + if ( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_STATIC_PIXEL_SHADER( water_ps20b ); + SET_STATIC_PIXEL_SHADER_COMBO( REFLECT, bReflection ); + SET_STATIC_PIXEL_SHADER_COMBO( REFRACT, bRefraction ); + SET_STATIC_PIXEL_SHADER_COMBO( ABOVEWATER, params[ABOVEWATER]->GetIntValue() ); + SET_STATIC_PIXEL_SHADER_COMBO( MULTITEXTURE,fabs(Scroll1.x) > 0.0); + SET_STATIC_PIXEL_SHADER_COMBO( BASETEXTURE, params[BASETEXTURE]->IsTexture() ); + SET_STATIC_PIXEL_SHADER_COMBO( BLURRY_REFRACT, params[BLURREFRACT]->GetIntValue() ); + SET_STATIC_PIXEL_SHADER_COMBO( NORMAL_DECODE_MODE, (int) NORMAL_DECODE_NONE ); + SET_STATIC_PIXEL_SHADER( water_ps20b ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( water_ps20 ); + SET_STATIC_PIXEL_SHADER_COMBO( REFLECT, bReflection ); + SET_STATIC_PIXEL_SHADER_COMBO( REFRACT, bRefraction ); + SET_STATIC_PIXEL_SHADER_COMBO( ABOVEWATER, params[ABOVEWATER]->GetIntValue() ); + SET_STATIC_PIXEL_SHADER_COMBO( MULTITEXTURE,fabs(Scroll1.x) > 0.0); + SET_STATIC_PIXEL_SHADER_COMBO( BASETEXTURE, params[BASETEXTURE]->IsTexture() ); + SET_STATIC_PIXEL_SHADER_COMBO( NORMAL_DECODE_MODE, (int) NORMAL_DECODE_NONE ); + SET_STATIC_PIXEL_SHADER( water_ps20 ); + } + + FogToFogColor(); + + // we are writing linear values from this shader. + pShaderShadow->EnableSRGBWrite( true ); + + pShaderShadow->EnableAlphaWrites( true ); + } + DYNAMIC_STATE + { + pShaderAPI->SetDefaultState(); + if( bRefraction ) + { + // HDRFIXME: add comment about binding.. Specify the number of MRTs in the enable + BindTexture( SHADER_SAMPLER0, REFRACTTEXTURE, -1 ); + } + if( bReflection ) + { + BindTexture( SHADER_SAMPLER2, REFLECTTEXTURE, -1 ); + } + BindTexture( SHADER_SAMPLER4, NORMALMAP, BUMPFRAME ); + if( params[BASETEXTURE]->IsTexture() ) + { + BindTexture( SHADER_SAMPLER1, BASETEXTURE, FRAME ); + pShaderAPI->BindStandardTexture( SHADER_SAMPLER3, TEXTURE_LIGHTMAP ); + } + + pShaderAPI->BindStandardTexture( SHADER_SAMPLER5, TEXTURE_NORMALIZATION_CUBEMAP_SIGNED ); + + // Refraction tint + if( bRefraction ) + { + SetPixelShaderConstantGammaToLinear( 1, REFRACTTINT ); + } + // Reflection tint + if( bReflection ) + { + if( g_pHardwareConfig->GetHDRType() == HDR_TYPE_INTEGER ) + { + // Need to multiply by 4 in linear space since we premultiplied into + // the render target by .25 to get overbright data in the reflection render target. + float gammaReflectTint[3]; + params[REFLECTTINT]->GetVecValue( gammaReflectTint, 3 ); + float linearReflectTint[4]; + linearReflectTint[0] = GammaToLinear( gammaReflectTint[0] ) * 4.0f; + linearReflectTint[1] = GammaToLinear( gammaReflectTint[1] ) * 4.0f; + linearReflectTint[2] = GammaToLinear( gammaReflectTint[2] ) * 4.0f; + linearReflectTint[3] = 1.0f; + pShaderAPI->SetPixelShaderConstant( 4, linearReflectTint, 1 ); + } + else + { + SetPixelShaderConstantGammaToLinear( 4, REFLECTTINT ); + } + } + + SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_1, BUMPTRANSFORM ); + + float curtime=pShaderAPI->CurrentTime(); + float vc0[4]; + float v0[4]; + params[SCROLL1]->GetVecValue(v0,4); + vc0[0]=curtime*v0[0]; + vc0[1]=curtime*v0[1]; + params[SCROLL2]->GetVecValue(v0,4); + vc0[2]=curtime*v0[0]; + vc0[3]=curtime*v0[1]; + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_3, vc0, 1 ); + + float c0[4] = { 1.0f / 3.0f, 1.0f / 3.0f, 1.0f / 3.0f, 0.0f }; + pShaderAPI->SetPixelShaderConstant( 0, c0, 1 ); + + float c2[4] = { 0.5f, 0.5f, 0.5f, 0.5f }; + pShaderAPI->SetPixelShaderConstant( 2, c2, 1 ); + + // fresnel constants + float c3[4] = { 1.0f, 0.0f, 0.0f, 0.0f }; + pShaderAPI->SetPixelShaderConstant( 3, c3, 1 ); + + float c5[4] = { params[REFLECTAMOUNT]->GetFloatValue(), params[REFLECTAMOUNT]->GetFloatValue(), + params[REFRACTAMOUNT]->GetFloatValue(), params[REFRACTAMOUNT]->GetFloatValue() }; + pShaderAPI->SetPixelShaderConstant( 5, c5, 1 ); + + SetPixelShaderConstantGammaToLinear( 6, FOGCOLOR ); + + float c7[4] = + { + params[FOGSTART]->GetFloatValue(), + params[FOGEND]->GetFloatValue() - params[FOGSTART]->GetFloatValue(), + 1.0f, + 0.0f + }; + if (g_pHardwareConfig->GetHDRType() == HDR_TYPE_INTEGER ) + { + // water overbright factor + c7[2] = 4.0; + } + pShaderAPI->SetPixelShaderConstant( 7, c7, 1 ); + + pShaderAPI->SetPixelShaderFogParams( 8 ); + + DECLARE_DYNAMIC_VERTEX_SHADER( water_vs20 ); + SET_DYNAMIC_VERTEX_SHADER( water_vs20 ); + + if ( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_DYNAMIC_PIXEL_SHADER( water_ps20b ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( WRITE_DEPTH_TO_DESTALPHA, pShaderAPI->ShouldWriteDepthToDestAlpha() ); + SET_DYNAMIC_PIXEL_SHADER( water_ps20b ); + } + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( water_ps20 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + SET_DYNAMIC_PIXEL_SHADER( water_ps20 ); + } + } + Draw(); + } + + inline void DrawCheapWater( IMaterialVar **params, IShaderShadow* pShaderShadow, + IShaderDynamicAPI* pShaderAPI, bool bBlend, bool bRefraction ) + { + SHADOW_STATE + { + SetInitialShadowState( ); + + // In edit mode, use nocull + if ( UsingEditor( params ) ) + { + s_pShaderShadow->EnableCulling( false ); + } + + if( bBlend ) + { + EnableAlphaBlending( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA ); + } + // envmap + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + // normal map + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + if( bRefraction && bBlend ) + { + // refraction map (used for alpha) + pShaderShadow->EnableTexture( SHADER_SAMPLER2, true ); + } + // Normalizing cube map + pShaderShadow->EnableTexture( SHADER_SAMPLER6, true ); + int fmt = VERTEX_POSITION | VERTEX_NORMAL | VERTEX_TANGENT_S | VERTEX_TANGENT_T; + pShaderShadow->VertexShaderVertexFormat( fmt, 1, 0, 0 ); + + DECLARE_STATIC_VERTEX_SHADER( watercheap_vs20 ); + SET_STATIC_VERTEX_SHADER_COMBO( BLEND, bBlend && bRefraction ); + SET_STATIC_VERTEX_SHADER( watercheap_vs20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_STATIC_PIXEL_SHADER( watercheap_ps20b ); + SET_STATIC_PIXEL_SHADER_COMBO( FRESNEL, params[NOFRESNEL]->GetIntValue() == 0 ); + SET_STATIC_PIXEL_SHADER_COMBO( BLEND, bBlend ); + SET_STATIC_PIXEL_SHADER_COMBO( REFRACTALPHA, bRefraction ); + SET_STATIC_PIXEL_SHADER_COMBO( HDRTYPE, g_pHardwareConfig->GetHDRType() ); + Vector4D Scroll1; + params[SCROLL1]->GetVecValue( Scroll1.Base(), 4 ); + SET_STATIC_PIXEL_SHADER_COMBO( MULTITEXTURE,fabs(Scroll1.x) > 0.0); + SET_STATIC_PIXEL_SHADER_COMBO( NORMAL_DECODE_MODE, (int) NORMAL_DECODE_NONE ); + SET_STATIC_PIXEL_SHADER( watercheap_ps20b ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( watercheap_ps20 ); + SET_STATIC_PIXEL_SHADER_COMBO( FRESNEL, params[NOFRESNEL]->GetIntValue() == 0 ); + SET_STATIC_PIXEL_SHADER_COMBO( BLEND, bBlend ); + SET_STATIC_PIXEL_SHADER_COMBO( REFRACTALPHA, bRefraction ); + SET_STATIC_PIXEL_SHADER_COMBO( HDRTYPE, g_pHardwareConfig->GetHDRType() ); + Vector4D Scroll1; + params[SCROLL1]->GetVecValue( Scroll1.Base(), 4 ); + SET_STATIC_PIXEL_SHADER_COMBO( MULTITEXTURE,fabs(Scroll1.x) > 0.0); + SET_STATIC_PIXEL_SHADER_COMBO( NORMAL_DECODE_MODE, (int) NORMAL_DECODE_NONE ); + SET_STATIC_PIXEL_SHADER( watercheap_ps20 ); + } + + // HDRFIXME: test cheap water! + if( g_pHardwareConfig->GetHDRType() != HDR_TYPE_NONE ) + { + // we are writing linear values from this shader. + pShaderShadow->EnableSRGBWrite( true ); + } + + FogToFogColor(); + } + DYNAMIC_STATE + { + pShaderAPI->SetDefaultState(); + + BindTexture( SHADER_SAMPLER0, ENVMAP, ENVMAPFRAME ); + BindTexture( SHADER_SAMPLER1, NORMALMAP, BUMPFRAME ); + if( bRefraction && bBlend ) + { + BindTexture( SHADER_SAMPLER2, REFRACTTEXTURE, -1 ); + } + pShaderAPI->BindStandardTexture( SHADER_SAMPLER6, TEXTURE_NORMALIZATION_CUBEMAP_SIGNED ); + + SetPixelShaderConstant( 0, FOGCOLOR ); + + float cheapWaterStartDistance = params[CHEAPWATERSTARTDISTANCE]->GetFloatValue(); + float cheapWaterEndDistance = params[CHEAPWATERENDDISTANCE]->GetFloatValue(); + float cheapWaterParams[4] = + { + (float)(cheapWaterStartDistance * VSHADER_VECT_SCALE), + (float)(cheapWaterEndDistance * VSHADER_VECT_SCALE), + (float)(PSHADER_VECT_SCALE / ( cheapWaterEndDistance - cheapWaterStartDistance )), + cheapWaterStartDistance / ( cheapWaterEndDistance - cheapWaterStartDistance ), + }; + pShaderAPI->SetPixelShaderConstant( 1, cheapWaterParams ); + + if( g_pConfig->bShowSpecular ) + { + SetPixelShaderConstant( 2, REFLECTTINT, REFLECTBLENDFACTOR ); + } + else + { + float zero[4] = { 0.0f, 0.0f, 0.0f, params[REFLECTBLENDFACTOR]->GetFloatValue() }; + pShaderAPI->SetPixelShaderConstant( 2, zero ); + } + + pShaderAPI->SetPixelShaderFogParams( 3 ); + + if( params[SCROLL1]->IsDefined()) + { + float curtime=pShaderAPI->CurrentTime(); + float vc0[4]; + float v0[4]; + params[SCROLL1]->GetVecValue(v0,4); + vc0[0]=curtime*v0[0]; + vc0[1]=curtime*v0[1]; + params[SCROLL2]->GetVecValue(v0,4); + vc0[2]=curtime*v0[0]; + vc0[3]=curtime*v0[1]; + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_3, vc0, 1 ); + } + + DECLARE_DYNAMIC_VERTEX_SHADER( watercheap_vs20 ); + SET_DYNAMIC_VERTEX_SHADER( watercheap_vs20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_DYNAMIC_PIXEL_SHADER( watercheap_ps20b ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( HDRENABLED, IsHDREnabled() ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + SET_DYNAMIC_PIXEL_SHADER( watercheap_ps20b ); + } + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( watercheap_ps20 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( HDRENABLED, IsHDREnabled() ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + SET_DYNAMIC_PIXEL_SHADER( watercheap_ps20 ); + } + } + Draw(); + } + + SHADER_DRAW + { + // TODO: fit the cheap water stuff into the water shader so that we don't have to do + // 2 passes. +#ifdef _X360 + bool bForceExpensive = false; +#else + bool bForceExpensive = r_waterforceexpensive.GetBool(); +#endif + bool bForceCheap = (params[FORCECHEAP]->GetIntValue() != 0) || UsingEditor( params ); + if ( bForceCheap ) + { + bForceExpensive = false; + } + else + { + bForceExpensive = bForceExpensive || (params[FORCEEXPENSIVE]->GetIntValue() != 0); + } + Assert( !( bForceCheap && bForceExpensive ) ); + + bool bRefraction = params[REFRACTTEXTURE]->IsTexture(); +#ifdef _X360 + bool bReflection = params[REFLECTTEXTURE]->IsTexture(); +#else + bool bReflection = bForceExpensive && params[REFLECTTEXTURE]->IsTexture(); +#endif + bool bDrewSomething = false; + if ( !bForceCheap && ( bReflection || bRefraction ) ) + { + bDrewSomething = true; + DrawReflectionRefraction( params, pShaderShadow, pShaderAPI, bReflection, bRefraction ); + } + + // Use $decal to see if we are a decal or not. . if we are, then don't bother + // drawing the cheap version for now since we don't have access to env_cubemap +#ifdef _X360 + if( params[ENVMAP]->IsTexture() && !IS_FLAG_SET( MATERIAL_VAR_DECAL ) && !bForceExpensive ) +#else + if( !bReflection && params[ENVMAP]->IsTexture() && !IS_FLAG_SET( MATERIAL_VAR_DECAL ) ) +#endif + { + bDrewSomething = true; + DrawCheapWater( params, pShaderShadow, pShaderAPI, !bForceCheap, bRefraction ); + } + + if( !bDrewSomething ) + { + // We are likely here because of the tools. . . draw something so that + // we won't go into wireframe-land. + Draw(); + } + } +END_SHADER + +//----------------------------------------------------------------------------- +// This allows us to use a block labelled 'Water_DX9_HDR' in the water materials +//----------------------------------------------------------------------------- +BEGIN_INHERITED_SHADER( Water_DX9_HDR, Water_DX90, + "Help for Water_DX9_HDR" ) + + SHADER_FALLBACK + { + if( g_pHardwareConfig->GetHDRType() == HDR_TYPE_NONE ) + { + return "WATER_DX90"; + } + return 0; + } +END_INHERITED_SHADER + diff --git a/materialsystem/stdshaders/water_dudv.cpp b/materialsystem/stdshaders/water_dudv.cpp new file mode 100644 index 0000000..cf29c18 --- /dev/null +++ b/materialsystem/stdshaders/water_dudv.cpp @@ -0,0 +1,95 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//===========================================================================// + + +#include "BaseVSShader.h" + +#include "waterdudv_vs11.inc" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +BEGIN_VS_SHADER( Water_DuDv, "Help for Water_DuDv" ) + + BEGIN_SHADER_PARAMS + SHADER_PARAM( BUMPMAP, SHADER_PARAM_TYPE_TEXTURE, "", "dudv bump map" ) + SHADER_PARAM( BUMPFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $bumpmap" ) + SHADER_PARAM( BUMPTRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$bumpmap texcoord transform" ) + SHADER_PARAM( REFRACTAMOUNT, SHADER_PARAM_TYPE_FLOAT, "0", "" ) + SHADER_PARAM( REFRACTTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "refraction tint" ) + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + } + + SHADER_FALLBACK + { + return 0; + } + + SHADER_INIT + { + if ( params[BUMPMAP]->IsDefined() ) + { + LoadTexture( BUMPMAP ); + } + if( !params[REFRACTTINT]->IsDefined() ) + { + params[REFRACTTINT]->SetVecValue( 1.0f, 1.0f, 1.0f ); + } + } + + SHADER_DRAW + { + SHADOW_STATE + { + pShaderShadow->EnableAlphaWrites( true ); + pShaderShadow->EnableColorWrites( true ); + pShaderShadow->EnableTexture( SHADER_TEXTURE_STAGE0, true ); + int fmt = VERTEX_POSITION | VERTEX_NORMAL; + pShaderShadow->VertexShaderVertexFormat( fmt, 1, 0, 0, 0 ); + + pShaderShadow->SetVertexShader( "WaterDuDv_vs11", 0 ); + pShaderShadow->SetPixelShader( "WaterDuDv_ps11", 0 ); + DisableFog(); + } + DYNAMIC_STATE + { + waterdudv_vs11_Dynamic_Index vshIndex; + vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + vshIndex.SetDOFOG( pShaderAPI->GetSceneFogMode() != MATERIAL_FOG_NONE ); + pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() ); + + SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_1, BUMPTRANSFORM ); + + Vector4D vec; + const float *pTint = params[REFRACTTINT]->GetVecValue(); + float flAverage = ( pTint[0] + pTint[1] + pTint[2] ) / 3.0f; + vec.Init( flAverage, flAverage, flAverage, 1.0f ); + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_3, vec.Base() ); + + // Amount to refract + SetPixelShaderConstant( 0, REFRACTAMOUNT ); + + // Used to renormalize + vec.Init( 1.0f, 1.0f, 1.0f, 1.0f ); + pShaderAPI->SetPixelShaderConstant( 1, vec.Base() ); + + // Used to deal with the red channel + vec.Init( 0.0f, 1.0f, 1.0f, 1.0f ); + pShaderAPI->SetPixelShaderConstant( 2, vec.Base() ); + + vec.Init( 1.0f, 0.0f, 0.0f, 0.0f ); + pShaderAPI->SetPixelShaderConstant( 3, vec.Base() ); + + BindTexture( SHADER_TEXTURE_STAGE0, BUMPMAP, BUMPFRAME ); + } + Draw(); + } +END_SHADER + diff --git a/materialsystem/stdshaders/water_dx60.cpp b/materialsystem/stdshaders/water_dx60.cpp new file mode 100644 index 0000000..b6c952b --- /dev/null +++ b/materialsystem/stdshaders/water_dx60.cpp @@ -0,0 +1,15 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//=============================================================================// + +#include "shaderlib/cshader.h" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +// NOTE: Water DX60 is located in LightmappedGeneric_DX6 so it can inherit +DEFINE_FALLBACK_SHADER( Water, Water_DX60 ) + diff --git a/materialsystem/stdshaders/water_dx80.cpp b/materialsystem/stdshaders/water_dx80.cpp new file mode 100644 index 0000000..2f31bb5 --- /dev/null +++ b/materialsystem/stdshaders/water_dx80.cpp @@ -0,0 +1,419 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//===========================================================================// + + +#include "BaseVSShader.h" +#include "mathlib/vmatrix.h" + +#include "water_vs11.inc" +#include "watercheappervertexfresnel_vs11.inc" +#include "watercheap_vs11.inc" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +BEGIN_VS_SHADER( Water_DX80, + "Help for Water_DX80" ) + + BEGIN_SHADER_PARAMS + SHADER_PARAM( REFRACTTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "" ) + SHADER_PARAM( REFLECTTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "_rt_WaterReflection", "" ) + SHADER_PARAM( REFRACTAMOUNT, SHADER_PARAM_TYPE_FLOAT, "0", "" ) + SHADER_PARAM( REFRACTTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "refraction tint" ) + SHADER_PARAM( REFLECTAMOUNT, SHADER_PARAM_TYPE_FLOAT, "0", "" ) + SHADER_PARAM( REFLECTTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "reflection tint" ) + SHADER_PARAM( BUMPMAP, SHADER_PARAM_TYPE_TEXTURE, "", "dudv bump map" ) + SHADER_PARAM( NORMALMAP, SHADER_PARAM_TYPE_TEXTURE, "", "normal map" ) + SHADER_PARAM( BUMPFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $bumpmap" ) + SHADER_PARAM( BUMPTRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$bumpmap texcoord transform" ) + SHADER_PARAM( SCALE, SHADER_PARAM_TYPE_VEC2, "[1 1]", "" ) + SHADER_PARAM( TIME, SHADER_PARAM_TYPE_FLOAT, "", "" ) + SHADER_PARAM( WATERDEPTH, SHADER_PARAM_TYPE_FLOAT, "", "" ) + SHADER_PARAM( CHEAPWATERSTARTDISTANCE, SHADER_PARAM_TYPE_FLOAT, "", "This is the distance from the eye in inches that the shader should start transitioning to a cheaper water shader." ) + SHADER_PARAM( CHEAPWATERENDDISTANCE, SHADER_PARAM_TYPE_FLOAT, "", "This is the distance from the eye in inches that the shader should finish transitioning to a cheaper water shader." ) + SHADER_PARAM( ENVMAP, SHADER_PARAM_TYPE_TEXTURE, "env_cubemap", "envmap" ) + SHADER_PARAM( ENVMAPFRAME, SHADER_PARAM_TYPE_INTEGER, "", "" ) + SHADER_PARAM( FOGCOLOR, SHADER_PARAM_TYPE_COLOR, "", "" ) + SHADER_PARAM( FORCECHEAP, SHADER_PARAM_TYPE_INTEGER, "", "" ) + SHADER_PARAM( FORCEEXPENSIVE, SHADER_PARAM_TYPE_BOOL, "", "" ) + SHADER_PARAM( REFLECTENTITIES, SHADER_PARAM_TYPE_BOOL, "", "" ) + SHADER_PARAM( REFLECTBLENDFACTOR, SHADER_PARAM_TYPE_FLOAT, "1.0", "" ) + SHADER_PARAM( NOFRESNEL, SHADER_PARAM_TYPE_BOOL, "0", "" ) + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + SET_FLAGS2( MATERIAL_VAR2_NEEDS_TANGENT_SPACES ); + if( !params[CHEAPWATERSTARTDISTANCE]->IsDefined() ) + { + params[CHEAPWATERSTARTDISTANCE]->SetFloatValue( 500.0f ); + } + if( !params[CHEAPWATERENDDISTANCE]->IsDefined() ) + { + params[CHEAPWATERENDDISTANCE]->SetFloatValue( 1000.0f ); + } + if( !params[SCALE]->IsDefined() ) + { + params[SCALE]->SetVecValue( 1.0f, 1.0f ); + } + if( !params[FOGCOLOR]->IsDefined() ) + { + params[FOGCOLOR]->SetVecValue( 1.0f, 0.0f, 0.0f ); + Warning( "material %s needs to have a $fogcolor.\n", pMaterialName ); + } + if( !params[REFLECTENTITIES]->IsDefined() ) + { + params[REFLECTENTITIES]->SetIntValue( 0 ); + } + if( !params[FORCEEXPENSIVE]->IsDefined() ) + { + params[FORCEEXPENSIVE]->SetIntValue( 0 ); + } + if( !params[REFLECTBLENDFACTOR]->IsDefined() ) + { + params[REFLECTBLENDFACTOR]->SetFloatValue( 1.0f ); + } + if( params[FORCEEXPENSIVE]->GetIntValue() && params[FORCECHEAP]->GetIntValue() ) + { + params[FORCEEXPENSIVE]->SetIntValue( 0 ); + } + } + + SHADER_FALLBACK + { + if ( IsPC() && ( g_pHardwareConfig->GetDXSupportLevel() < 80 || !g_pHardwareConfig->HasProjectedBumpEnv() ) ) + { + return "Water_DX60"; + } + return 0; + } + + SHADER_INIT + { + Assert( params[WATERDEPTH]->IsDefined() ); + if( params[REFRACTTEXTURE]->IsDefined() ) + { + LoadTexture( REFRACTTEXTURE ); + } + if( params[REFLECTTEXTURE]->IsDefined() ) + { + LoadTexture( REFLECTTEXTURE ); + } + if (params[BUMPMAP]->IsDefined() ) + { + LoadTexture( BUMPMAP ); + } + if (params[ENVMAP]->IsDefined() ) + { + LoadCubeMap( ENVMAP ); + } + if (params[NORMALMAP]->IsDefined() ) + { + LoadBumpMap( NORMALMAP ); + } + } + + inline void SetCheapWaterFactors( IMaterialVar **params, IShaderDynamicAPI* pShaderAPI, int nConstantReg ) + { + float flCheapWaterStartDistance = params[CHEAPWATERSTARTDISTANCE]->GetFloatValue(); + float flCheapWaterEndDistance = params[CHEAPWATERENDDISTANCE]->GetFloatValue(); + float flCheapWaterConstants[4] = + { + flCheapWaterStartDistance, + 1.0f / ( flCheapWaterEndDistance - flCheapWaterStartDistance ), + 0.0f, + 0.0f + }; + pShaderAPI->SetVertexShaderConstant( nConstantReg, flCheapWaterConstants ); + } + + inline void DrawReflection( IMaterialVar **params, IShaderShadow* pShaderShadow, + IShaderDynamicAPI* pShaderAPI, bool bBlendReflection ) + { + SHADOW_STATE + { + SetInitialShadowState( ); + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER2, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER3, true ); + + int fmt = VERTEX_POSITION | VERTEX_NORMAL | VERTEX_TANGENT_S | VERTEX_TANGENT_T; + pShaderShadow->VertexShaderVertexFormat( fmt, 1, 0, 0 ); + if( bBlendReflection ) + { + EnableAlphaBlending( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA ); + } + + water_vs11_Static_Index vshIndex; + pShaderShadow->SetVertexShader( "Water_vs11", vshIndex.GetIndex() ); + + pShaderShadow->SetPixelShader( "WaterReflect_ps11", 0 ); + + FogToFogColor(); + } + DYNAMIC_STATE + { + pShaderAPI->SetDefaultState(); + + // The dx9.0c runtime says that we shouldn't have a non-zero dimension when using vertex and pixel shaders. + pShaderAPI->SetTextureTransformDimension( SHADER_TEXTURE_STAGE1, 0, true ); + + float fReflectionAmount = params[REFLECTAMOUNT]->GetFloatValue(); + pShaderAPI->SetBumpEnvMatrix( SHADER_TEXTURE_STAGE1, fReflectionAmount, 0.0f, 0.0f, fReflectionAmount ); + + BindTexture( SHADER_SAMPLER0, BUMPMAP, BUMPFRAME ); + BindTexture( SHADER_SAMPLER1, REFLECTTEXTURE, -1 ); + BindTexture( SHADER_SAMPLER2, NORMALMAP, BUMPFRAME ); + pShaderAPI->BindStandardTexture( SHADER_SAMPLER3, TEXTURE_NORMALIZATION_CUBEMAP ); + pShaderAPI->SetVertexShaderIndex( 0 ); + + SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_1, BUMPTRANSFORM ); + + // used to invert y + float c[4] = { 0.0f, 0.0f, 0.0f, 1.0f }; + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_4, c, 1 ); + + SetPixelShaderConstant( 0, REFLECTTINT ); + + water_vs11_Dynamic_Index vshIndex; + vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() ); + } + Draw(); + } + + inline void DrawRefraction( IMaterialVar **params, IShaderShadow* pShaderShadow, + IShaderDynamicAPI* pShaderAPI ) + { + SHADOW_STATE + { + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + int fmt = VERTEX_POSITION | VERTEX_NORMAL | VERTEX_TANGENT_S | VERTEX_TANGENT_T; + pShaderShadow->VertexShaderVertexFormat( fmt, 1, 0, 0 ); + + water_vs11_Static_Index vshIndex; + pShaderShadow->SetVertexShader( "Water_vs11", vshIndex.GetIndex() ); + + pShaderShadow->SetPixelShader( "WaterRefract_ps11", 0 ); + FogToFogColor(); + } + DYNAMIC_STATE + { + // The dx9.0c runtime says that we shouldn't have a non-zero dimension when using vertex and pixel shaders. + pShaderAPI->SetTextureTransformDimension( SHADER_TEXTURE_STAGE1, 0, true ); + float fRefractionAmount = params[REFRACTAMOUNT]->GetFloatValue(); + pShaderAPI->SetBumpEnvMatrix( SHADER_TEXTURE_STAGE1, fRefractionAmount, 0.0f, 0.0f, fRefractionAmount ); + BindTexture( SHADER_SAMPLER0, BUMPMAP, BUMPFRAME ); + BindTexture( SHADER_SAMPLER1, REFRACTTEXTURE ); + + SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_1, BUMPTRANSFORM ); + + // used to invert y + float c[4] = { 0.0f, 0.0f, 0.0f, -1.0f }; + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_4, c, 1 ); + + SetPixelShaderConstant( 0, REFRACTTINT ); + + water_vs11_Dynamic_Index vshIndex; + vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() ); + } + Draw(); + } + + inline void DrawRefractionForFresnel( IMaterialVar **params, IShaderShadow* pShaderShadow, + IShaderDynamicAPI* pShaderAPI ) + { + SHADOW_STATE + { + pShaderShadow->EnableAlphaWrites( true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER2, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER3, true ); + + int fmt = VERTEX_POSITION | VERTEX_NORMAL | VERTEX_TANGENT_S | VERTEX_TANGENT_T; + pShaderShadow->VertexShaderVertexFormat( fmt, 1, 0, 0 ); + + water_vs11_Static_Index vshIndex; + pShaderShadow->SetVertexShader( "Water_vs11", vshIndex.GetIndex() ); + + pShaderShadow->SetPixelShader( "WaterRefractFresnel_ps11", 0 ); + FogToFogColor(); + } + DYNAMIC_STATE + { + // The dx9.0c runtime says that we shouldn't have a non-zero dimension when using vertex and pixel shaders. + pShaderAPI->SetTextureTransformDimension( SHADER_TEXTURE_STAGE1, 0, true ); + float fRefractionAmount = params[REFRACTAMOUNT]->GetFloatValue(); + pShaderAPI->SetBumpEnvMatrix( SHADER_TEXTURE_STAGE1, fRefractionAmount, 0.0f, 0.0f, fRefractionAmount ); + BindTexture( SHADER_SAMPLER0, BUMPMAP, BUMPFRAME ); + BindTexture( SHADER_SAMPLER1, REFRACTTEXTURE ); + BindTexture( SHADER_SAMPLER2, NORMALMAP, BUMPFRAME ); + s_pShaderAPI->BindStandardTexture( SHADER_SAMPLER3, TEXTURE_NORMALIZATION_CUBEMAP ); + + SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_1, BUMPTRANSFORM ); + SetCheapWaterFactors( params, pShaderAPI, VERTEX_SHADER_SHADER_SPECIFIC_CONST_3 ); + + // used to invert y + float c[4] = { 0.0f, 0.0f, 0.0f, -1.0f }; + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_4, c, 1 ); + + SetPixelShaderConstant( 0, REFRACTTINT ); + + water_vs11_Dynamic_Index vshIndex; + vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() ); + } + Draw(); + } + + inline void DrawCheapWater( IMaterialVar **params, IShaderShadow* pShaderShadow, + IShaderDynamicAPI* pShaderAPI, bool bBlend, bool bBlendFresnel, bool bNoPerVertexFresnel ) + { + SHADOW_STATE + { + SetInitialShadowState( ); + + // In edit mode, use nocull + if ( UsingEditor( params ) ) + { + s_pShaderShadow->EnableCulling( false ); + } + + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER3, true ); + if( bBlend ) + { + if ( bBlendFresnel ) + { + EnableAlphaBlending( SHADER_BLEND_DST_ALPHA, SHADER_BLEND_ONE_MINUS_DST_ALPHA ); + } + else + { + EnableAlphaBlending( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA ); + } + } + + pShaderShadow->VertexShaderVertexFormat( + VERTEX_POSITION | VERTEX_NORMAL | VERTEX_TANGENT_S | + VERTEX_TANGENT_T, 1, 0, 0 ); + + if( bNoPerVertexFresnel ) + { + watercheap_vs11_Static_Index vshIndex; + pShaderShadow->SetVertexShader( "WaterCheap_vs11", vshIndex.GetIndex() ); + } + else + { + watercheappervertexfresnel_vs11_Static_Index vshIndex; + pShaderShadow->SetVertexShader( "WaterCheapPerVertexFresnel_vs11", vshIndex.GetIndex() ); + } + + static const char *s_pPixelShaderName[] = + { + "WaterCheapOpaque_ps11", + "WaterCheap_ps11", + "WaterCheapNoFresnelOpaque_ps11", + "WaterCheapNoFresnel_ps11", + }; + + int nPshIndex = 0; + if ( bBlend ) nPshIndex |= 0x1; + if ( bNoPerVertexFresnel ) nPshIndex |= 0x2; + pShaderShadow->SetPixelShader( s_pPixelShaderName[nPshIndex] ); + + FogToFogColor(); + } + DYNAMIC_STATE + { + pShaderAPI->SetDefaultState(); + BindTexture( SHADER_SAMPLER0, NORMALMAP, BUMPFRAME ); + BindTexture( SHADER_SAMPLER3, ENVMAP, ENVMAPFRAME ); + + if( bBlend && !bBlendFresnel ) + { + SetCheapWaterFactors( params, pShaderAPI, VERTEX_SHADER_SHADER_SPECIFIC_CONST_2 ); + } + else + { + float flCheapWaterConstants[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_2, flCheapWaterConstants ); + } + + SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, BUMPTRANSFORM ); + + SetPixelShaderConstant( 0, FOGCOLOR ); + SetPixelShaderConstant( 1, REFLECTTINT, REFLECTBLENDFACTOR ); + + if( bNoPerVertexFresnel ) + { + watercheap_vs11_Dynamic_Index vshIndex; + vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() ); + } + else + { + watercheappervertexfresnel_vs11_Dynamic_Index vshIndex; + vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() ); + } + } + Draw(); + } + + SHADER_DRAW + { + // NOTE: Here's what all this means. + // 1) ForceCheap means use env_cubemap only + // 2) ForceExpensive means do real reflection instead of env_cubemap. + // By default, it will do refraction and use env_cubemap for the reflection. + // If dest alpha is available, it will also use dest alpha for a fresnel term. + // otherwise there will be no fresnel term as it looks bizzare. + + bool bBlendReflection = false; + bool bForceCheap = params[FORCECHEAP]->GetIntValue() != 0 || UsingEditor( params ); + bool bForceExpensive = !bForceCheap && (params[FORCEEXPENSIVE]->GetIntValue() != 0); + bool bRefraction = params[REFRACTTEXTURE]->IsTexture(); + bool bReflection = bForceExpensive && params[REFLECTTEXTURE]->IsTexture(); + bool bReflectionUseFresnel = false; + + // Can't do fresnel when forcing cheap or if there's no refraction + if( !bForceCheap ) + { + if( bRefraction ) + { + // NOTE: Expensive reflection does the fresnel correctly per-pixel + if ( g_pHardwareConfig->HasDestAlphaBuffer() && !bReflection && !params[NOFRESNEL]->GetIntValue() ) + { + DrawRefractionForFresnel( params, pShaderShadow, pShaderAPI ); + bReflectionUseFresnel = true; + } + else + { + DrawRefraction( params, pShaderShadow, pShaderAPI ); + } + bBlendReflection = true; + } + if( bReflection ) + { + DrawReflection( params, pShaderShadow, pShaderAPI, bBlendReflection ); + } + } + + // Use $decal to see if we are a decal or not. . if we are, then don't bother + // drawing the cheap version for now since we don't have access to env_cubemap + if( !bReflection && params[ENVMAP]->IsTexture() && !IS_FLAG_SET( MATERIAL_VAR_DECAL ) ) + { + bool bNoPerVertexFresnel = ( params[NOFRESNEL]->GetIntValue() || bReflectionUseFresnel || bForceCheap || !bRefraction ); + DrawCheapWater( params, pShaderShadow, pShaderAPI, bBlendReflection, bReflectionUseFresnel, bNoPerVertexFresnel ); + } + } +END_SHADER + diff --git a/materialsystem/stdshaders/water_dx81.cpp b/materialsystem/stdshaders/water_dx81.cpp new file mode 100644 index 0000000..764ffe9 --- /dev/null +++ b/materialsystem/stdshaders/water_dx81.cpp @@ -0,0 +1,311 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//=============================================================================// + +#include "BaseVSShader.h" +#include "mathlib/vmatrix.h" + +#include "water_ps14.inc" +#include "watercheap_vs14.inc" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +DEFINE_FALLBACK_SHADER( Water, Water_DX81 ) + +BEGIN_VS_SHADER( Water_DX81, + "Help for Water_DX81" ) + + BEGIN_SHADER_PARAMS + SHADER_PARAM( REFRACTTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "" ) + SHADER_PARAM( REFLECTTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "_rt_WaterReflection", "" ) + SHADER_PARAM( REFRACTAMOUNT, SHADER_PARAM_TYPE_FLOAT, "0", "" ) + SHADER_PARAM( REFRACTTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "refraction tint" ) + SHADER_PARAM( REFLECTAMOUNT, SHADER_PARAM_TYPE_FLOAT, "0", "" ) + SHADER_PARAM( REFLECTTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "reflection tint" ) + SHADER_PARAM( NORMALMAP, SHADER_PARAM_TYPE_TEXTURE, "", "normal map" ) + SHADER_PARAM( BUMPFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $bumpmap" ) + SHADER_PARAM( BUMPTRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$bumpmap texcoord transform" ) + SHADER_PARAM( SCALE, SHADER_PARAM_TYPE_VEC2, "[1 1]", "" ) + SHADER_PARAM( TIME, SHADER_PARAM_TYPE_FLOAT, "", "" ) + SHADER_PARAM( WATERDEPTH, SHADER_PARAM_TYPE_FLOAT, "", "" ) + SHADER_PARAM( CHEAPWATERSTARTDISTANCE, SHADER_PARAM_TYPE_FLOAT, "", "This is the distance from the eye in inches that the shader should start transitioning to a cheaper water shader." ) + SHADER_PARAM( CHEAPWATERENDDISTANCE, SHADER_PARAM_TYPE_FLOAT, "", "This is the distance from the eye in inches that the shader should finish transitioning to a cheaper water shader." ) + SHADER_PARAM( ENVMAP, SHADER_PARAM_TYPE_TEXTURE, "env_cubemap", "envmap" ) + SHADER_PARAM( ENVMAPFRAME, SHADER_PARAM_TYPE_INTEGER, "", "" ) + SHADER_PARAM( FOGCOLOR, SHADER_PARAM_TYPE_COLOR, "", "" ) + SHADER_PARAM( FORCECHEAP, SHADER_PARAM_TYPE_INTEGER, "", "" ) + SHADER_PARAM( FORCEEXPENSIVE, SHADER_PARAM_TYPE_BOOL, "", "" ) + SHADER_PARAM( REFLECTENTITIES, SHADER_PARAM_TYPE_BOOL, "", "" ) + SHADER_PARAM( REFLECTBLENDFACTOR, SHADER_PARAM_TYPE_FLOAT, "1.0", "" ) + SHADER_PARAM( NOFRESNEL, SHADER_PARAM_TYPE_BOOL, "0", "" ) + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + SET_FLAGS2( MATERIAL_VAR2_NEEDS_TANGENT_SPACES ); + if( !params[CHEAPWATERSTARTDISTANCE]->IsDefined() ) + { + params[CHEAPWATERSTARTDISTANCE]->SetFloatValue( 500.0f ); + } + if( !params[CHEAPWATERENDDISTANCE]->IsDefined() ) + { + params[CHEAPWATERENDDISTANCE]->SetFloatValue( 1000.0f ); + } + if( !params[SCALE]->IsDefined() ) + { + params[SCALE]->SetVecValue( 1.0f, 1.0f ); + } + if( !params[FOGCOLOR]->IsDefined() ) + { + params[FOGCOLOR]->SetVecValue( 1.0f, 0.0f, 0.0f ); + Warning( "material %s needs to have a $fogcolor.\n", pMaterialName ); + } + if( !params[REFLECTENTITIES]->IsDefined() ) + { + params[REFLECTENTITIES]->SetIntValue( 0 ); + } + if( !params[FORCEEXPENSIVE]->IsDefined() ) + { + params[FORCEEXPENSIVE]->SetIntValue( 0 ); + } + if( params[FORCEEXPENSIVE]->GetIntValue() && params[FORCECHEAP]->GetIntValue() ) + { + params[FORCEEXPENSIVE]->SetIntValue( 0 ); + } + if( !params[REFLECTBLENDFACTOR]->IsDefined() ) + { + params[REFLECTBLENDFACTOR]->SetFloatValue( 1.0f ); + } + if( !params[FORCEEXPENSIVE]->GetIntValue() && !params[ENVMAP]->IsDefined() ) + { + params[ENVMAP]->SetStringValue( "engine/defaultcubemap" ); + } + } + + SHADER_FALLBACK + { + if( g_pHardwareConfig->GetDXSupportLevel() < 81 ) + { + return "Water_DX80"; + } + return 0; + } + + SHADER_INIT + { + Assert( params[WATERDEPTH]->IsDefined() ); + if( params[REFRACTTEXTURE]->IsDefined() ) + { + LoadTexture( REFRACTTEXTURE ); + } + if( params[REFLECTTEXTURE]->IsDefined() ) + { + LoadTexture( REFLECTTEXTURE ); + } + if (params[ENVMAP]->IsDefined() ) + { + LoadTexture( ENVMAP ); + } + if (params[NORMALMAP]->IsDefined() ) + { + LoadBumpMap( NORMALMAP ); + } + } + + inline int GetReflectionRefractionPixelShaderIndex( bool bReflection, bool bRefraction ) + { + // "REFLECT" "0..1" + // "REFRACT" "0..1" + int pshIndex = ( bReflection ? 1 : 0 ) | ( bRefraction ? 2 : 0 ); + return pshIndex; + } + + inline void DrawReflectionRefraction( IMaterialVar **params, IShaderShadow* pShaderShadow, + IShaderDynamicAPI* pShaderAPI, bool bReflection, bool bRefraction ) + { + SHADOW_STATE + { + SetInitialShadowState( ); + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + if( bRefraction ) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER2, true ); + } + pShaderShadow->EnableTexture( SHADER_SAMPLER3, true ); + if( bReflection ) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER4, true ); + } + int fmt = VERTEX_POSITION | VERTEX_NORMAL | VERTEX_TANGENT_S | VERTEX_TANGENT_T; + pShaderShadow->VertexShaderVertexFormat( fmt, 1, 0, 0 ); + + water_ps14_Static_Index vshIndex; + pShaderShadow->SetVertexShader( "Water_ps14", vshIndex.GetIndex() ); + + int pshIndex = GetReflectionRefractionPixelShaderIndex( bReflection, bRefraction ); + pShaderShadow->SetPixelShader ( "Water_ps14", pshIndex ); + FogToFogColor(); + } + DYNAMIC_STATE + { + pShaderAPI->SetDefaultState(); + pShaderAPI->BindStandardTexture( SHADER_SAMPLER1, TEXTURE_NORMALIZATION_CUBEMAP ); + if( bRefraction ) + { + BindTexture( SHADER_SAMPLER2, REFRACTTEXTURE, -1 ); + } + BindTexture( SHADER_SAMPLER3, NORMALMAP, BUMPFRAME ); + if( bReflection ) + { + BindTexture( SHADER_SAMPLER4, REFLECTTEXTURE, -1 ); + } + + SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, REFLECTAMOUNT ); + SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_1, BUMPTRANSFORM ); + SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_3, REFRACTAMOUNT ); + + float c0[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; + pShaderAPI->SetPixelShaderConstant( 0, c0, 1 ); + + SetPixelShaderConstant( 1, REFRACTTINT ); + SetPixelShaderConstant( 4, REFLECTTINT ); + + float c2[4] = { 0.5f, 0.5f, 0.5f, 0.5f }; + pShaderAPI->SetPixelShaderConstant( 2, c2, 1 ); + + // ERASE ME! + float c3[4] = { 5.0f, 0.0f, 0.0f, 0.0f }; + pShaderAPI->SetPixelShaderConstant( 3, c3, 1 ); + + // reflection/refraction scale + float reflectionRefractionScale[4] = { params[REFLECTAMOUNT]->GetFloatValue(), + params[REFRACTAMOUNT]->GetFloatValue(), 0.0f, 0.0f }; + pShaderAPI->SetPixelShaderConstant( 5, reflectionRefractionScale, 1 ); + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_4, reflectionRefractionScale, 1 ); + + water_ps14_Dynamic_Index vshIndex; + vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() ); + } + Draw(); + } + + enum DrawCheapType_t + { + DRAW_CHEAP_OPAQUE = 0, + DRAW_CHEAP_FRESNEL_OPAQUE, + DRAW_CHEAP_LOD_ONLY, + DRAW_CHEAP_FRESNEL_AND_LOD, + }; + + inline void DrawCheapWater( IMaterialVar **params, IShaderShadow* pShaderShadow, + IShaderDynamicAPI* pShaderAPI, DrawCheapType_t type ) + { + SHADOW_STATE + { + SetInitialShadowState( ); + + // In edit mode, use nocull + if ( UsingEditor( params ) ) + { + s_pShaderShadow->EnableCulling( false ); + } + + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER3, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER4, true ); + if ( (type != DRAW_CHEAP_OPAQUE) && (type != DRAW_CHEAP_FRESNEL_OPAQUE) ) + { + EnableAlphaBlending( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA ); + } + pShaderShadow->VertexShaderVertexFormat( + VERTEX_POSITION | VERTEX_NORMAL | VERTEX_TANGENT_S | + VERTEX_TANGENT_T, 1, 0, 0 ); + + watercheap_vs14_Static_Index vshIndex; + pShaderShadow->SetVertexShader( "WaterCheap_vs14", vshIndex.GetIndex() ); + + static const char *s_pPixelShader[] = + { + "WaterCheapOpaque_ps14", + "WaterCheapFresnelOpaque_ps14", + "WaterCheap_ps14", + "WaterCheapFresnel_ps14", + }; + + pShaderShadow->SetPixelShader( s_pPixelShader[type] ); + FogToFogColor(); + } + DYNAMIC_STATE + { + pShaderAPI->SetDefaultState(); + BindTexture( SHADER_SAMPLER0, NORMALMAP, BUMPFRAME ); + BindTexture( SHADER_SAMPLER3, ENVMAP, ENVMAPFRAME ); + pShaderAPI->BindStandardTexture( SHADER_SAMPLER4, TEXTURE_NORMALIZATION_CUBEMAP ); + + float pCheapWaterConstants[4] = { 0, 0, 0, 0 }; + if ( (type != DRAW_CHEAP_OPAQUE) && (type != DRAW_CHEAP_FRESNEL_OPAQUE) ) + { + float flCheapWaterStartDistance = params[CHEAPWATERSTARTDISTANCE]->GetFloatValue(); + float flCheapWaterEndDistance = params[CHEAPWATERENDDISTANCE]->GetFloatValue(); + pCheapWaterConstants[0] = flCheapWaterStartDistance; + pCheapWaterConstants[1] = 1.0f / ( flCheapWaterEndDistance - flCheapWaterStartDistance ); + } + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_2, pCheapWaterConstants ); + + SetPixelShaderConstant( 0, FOGCOLOR ); + SetPixelShaderConstant( 1, REFLECTTINT, REFLECTBLENDFACTOR ); + + SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, BUMPTRANSFORM ); + + watercheap_vs14_Dynamic_Index vshIndex; + vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() ); + } + Draw(); + } + + SHADER_DRAW + { + // NOTE: Here's what all this means. + // 1) ForceCheap means use env_cubemap only + // 2) ForceExpensive means do real reflection instead of env_cubemap. + // By default, it will do refraction and use env_cubemap for the reflection. + + // Also, it will fade to cheap water at a particular distance, + // based on CheapWaterStartDistance and CheapWaterEndDistance + // * In the ForceCheap case, no fading is required + // * In the default case, it will fade based on these parameters in a single pass + // * In the expensive case, it will have to perform the fade in a separate pass. + + bool bForceCheap = params[FORCECHEAP]->GetIntValue() != 0 || UsingEditor( params ); + bool bForceExpensive = params[FORCEEXPENSIVE]->GetIntValue() != 0; + bool bRefraction = params[REFRACTTEXTURE]->IsTexture(); + bool bReflection = bForceExpensive && params[REFLECTTEXTURE]->IsTexture(); + DrawCheapType_t type = params[NOFRESNEL]->GetIntValue() ? DRAW_CHEAP_OPAQUE : DRAW_CHEAP_FRESNEL_OPAQUE; + if( !bForceCheap && (bRefraction || bReflection) ) + { + DrawReflectionRefraction( params, pShaderShadow, pShaderAPI, bReflection, bRefraction ); + if ( !bReflection ) + { + type = params[NOFRESNEL]->GetIntValue() ? DRAW_CHEAP_LOD_ONLY : DRAW_CHEAP_FRESNEL_AND_LOD; + } + else + { + type = DRAW_CHEAP_LOD_ONLY; + } + } + + // Use $decal to see if we are a decal or not. . if we are, then don't bother + // drawing the cheap version for now since we don't have access to env_cubemap + if( params[ENVMAP]->IsTexture() && !IS_FLAG_SET( MATERIAL_VAR_DECAL ) && !bReflection ) + { + DrawCheapWater( params, pShaderShadow, pShaderAPI, type ); + } + } +END_SHADER + diff --git a/materialsystem/stdshaders/water_ps2x.fxc b/materialsystem/stdshaders/water_ps2x.fxc new file mode 100644 index 0000000..a80a8a1 --- /dev/null +++ b/materialsystem/stdshaders/water_ps2x.fxc @@ -0,0 +1,110 @@ +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b] [= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX] +// STATIC: "BASETEXTURE" "0..1" +// STATIC: "MULTITEXTURE" "0..1" +// STATIC: "REFLECT" "0..1" +// STATIC: "REFRACT" "0..1" +// STATIC: "ABOVEWATER" "0..1" +// STATIC: "BLURRY_REFRACT" "0..1" [ps20b] + +// When we turn NORMAL_DECODE_MODE on, this shader only needs 0..1, not 0..2 +// STATIC: "NORMAL_DECODE_MODE" "0..0" [XBOX] +// STATIC: "NORMAL_DECODE_MODE" "0..0" [PC] + +// DYNAMIC: "PIXELFOGTYPE" "0..1" +// DYNAMIC: "WRITE_DEPTH_TO_DESTALPHA" "0..1" [ps20b] [PC] +// DYNAMIC: "WRITE_DEPTH_TO_DESTALPHA" "0..0" [ps20b] [XBOX] + +// SKIP: $MULTITEXTURE && $BASETEXTURE + +#if defined(SHADER_MODEL_PS_2_0) +# define BLURRY_REFRACT 0 +# define WRITE_DEPTH_TO_DESTALPHA 0 +#endif + +#include "water_ps2x_helper.h" + + +sampler RefractSampler : register( s0 ); +#if BASETEXTURE +sampler BaseTextureSampler : register( s1 ); +#endif +sampler ReflectSampler : register( s2 ); +#if BASETEXTURE +sampler LightmapSampler : register( s3 ); +#endif +sampler NormalSampler : register( s4 ); + +const HALF4 vRefractTint : register( c1 ); +const HALF4 vReflectTint : register( c4 ); +const float4 g_ReflectRefractScale : register( c5 ); // xy - reflect scale, zw - refract scale +const HALF4 g_WaterFogColor : register( c6 ); +const HALF4 g_WaterFogParams : register( c7 ); + +const float4 g_PixelFogParams : register( c8 ); + + +#define g_WaterFogStart g_WaterFogParams.x +#define g_WaterFogEndMinusStart g_WaterFogParams.y +#define g_Reflect_OverBright g_WaterFogParams.z + +struct PS_INPUT +{ + float2 vBumpTexCoord : TEXCOORD0; + half3 vTangentEyeVect : TEXCOORD1; + float4 vReflectXY_vRefractYX : TEXCOORD2; + float W : TEXCOORD3; + float4 vProjPos : TEXCOORD4; + float screenCoord : TEXCOORD5; +#if MULTITEXTURE + float4 vExtraBumpTexCoord : TEXCOORD6; +#endif +#if BASETEXTURE +// CENTROID: TEXCOORD6 + HALF4 lightmapTexCoord1And2 : TEXCOORD6; +// CENTROID: TEXCOORD7 + HALF4 lightmapTexCoord3 : TEXCOORD7; +#endif + + float4 fogFactorW : COLOR1; +}; + +float4 main( PS_INPUT i ) : COLOR +{ + DrawWater_params_t params; + + params.vBumpTexCoord = i.vBumpTexCoord; +#if MULTITEXTURE + params.vExtraBumpTexCoord = i.vExtraBumpTexCoord; +#endif + params.vReflectXY_vRefractYX = i.vReflectXY_vRefractYX; + params.w = i.W; + params.vReflectRefractScale = g_ReflectRefractScale; + params.fReflectOverbright = g_Reflect_OverBright; + params.vReflectTint = vReflectTint; + params.vRefractTint = vRefractTint; + params.vTangentEyeVect = i.vTangentEyeVect; + params.waterFogColor = g_WaterFogColor; +#if BASETEXTURE + params.lightmapTexCoord1And2 = i.lightmapTexCoord1And2; + params.lightmapTexCoord3 = i.lightmapTexCoord3; +#endif + params.vProjPos = i.vProjPos; + params.pixelFogParams = g_PixelFogParams; + params.fWaterFogStart = g_WaterFogStart; + params.fWaterFogEndMinusStart = g_WaterFogEndMinusStart; + + float4 result; + float fogFactor; + DrawWater( params, + // yay. . can't put sampler in a struct. +#if BASETEXTURE + BaseTextureSampler, + LightmapSampler, +#endif + NormalSampler, RefractSampler, ReflectSampler, + result, fogFactor ); + + return FinalOutput( float4( result.rgb, 1.0f ), fogFactor, PIXELFOGTYPE, TONEMAP_SCALE_NONE, (WRITE_DEPTH_TO_DESTALPHA != 0), i.vProjPos.z ); +} + diff --git a/materialsystem/stdshaders/water_ps2x_helper.h b/materialsystem/stdshaders/water_ps2x_helper.h new file mode 100644 index 0000000..b15b998 --- /dev/null +++ b/materialsystem/stdshaders/water_ps2x_helper.h @@ -0,0 +1,239 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +#include "common_ps_fxc.h" + +struct DrawWater_params_t +{ + float2 vBumpTexCoord; +#if MULTITEXTURE + float4 vExtraBumpTexCoord; +#endif + float4 vReflectXY_vRefractYX; + float w; + float4 vReflectRefractScale; + float fReflectOverbright; + float4 vReflectTint; + float4 vRefractTint; + half3 vTangentEyeVect; + float4 waterFogColor; +#if BASETEXTURE + HALF4 lightmapTexCoord1And2; + HALF4 lightmapTexCoord3; +#endif + float4 vProjPos; + float4 pixelFogParams; + float fWaterFogStart; + float fWaterFogEndMinusStart; +}; + +void DrawWater( in DrawWater_params_t i, +#if BASETEXTURE + in sampler BaseTextureSampler, + in sampler LightmapSampler, +#endif + in sampler NormalSampler, + in sampler RefractSampler, + in sampler ReflectSampler, + out float4 result, out float fogFactor ) +{ + bool bReflect = REFLECT ? true : false; + bool bRefract = REFRACT ? true : false; + +#if MULTITEXTURE + float4 vNormal = tex2D( NormalSampler, i.vBumpTexCoord ); + float4 vNormal1 = tex2D( NormalSampler, i.vExtraBumpTexCoord.xy ); + float4 vNormal2 = tex2D( NormalSampler, i.vExtraBumpTexCoord.zw ); + vNormal = 0.33 * ( vNormal + vNormal1 + vNormal2 ); + +#if ( NORMAL_DECODE_MODE == NORM_DECODE_ATI2N ) + vNormal.xy = vNormal.xy * 2.0f - 1.0f; + vNormal.z = sqrt( 1.0f - dot(vNormal.xy, vNormal.xy) ); + vNormal.a = 1.0f; +#else + vNormal.xyz = 2.0 * vNormal.xyz - 1.0; +#endif + +#else + float4 vNormal = DecompressNormal( NormalSampler, i.vBumpTexCoord, NORMAL_DECODE_MODE ); +#endif + + // Perform division by W only once + float ooW = 1.0f / i.w; + + float2 unwarpedRefractTexCoord = i.vReflectXY_vRefractYX.wz * ooW; + +#if ABOVEWATER + float waterFogDepthValue = tex2D( RefractSampler, unwarpedRefractTexCoord ).a; +#else + // We don't actually have valid depth values in alpha when we are underwater looking out, so + // just set to farthest value. + float waterFogDepthValue = 1.0f; +#endif + float4 reflectRefractScale = i.vReflectRefractScale; +#if !BASETEXTURE +#if ( BLURRY_REFRACT == 0 ) + reflectRefractScale *= waterFogDepthValue; +#endif +#endif + + // Compute coordinates for sampling Reflection + float2 vReflectTexCoord; + float2 vRefractTexCoord; + + // vectorize the dependent UV calculations (reflect = .xy, refract = .wz) + float4 vN; + vN.xy = vNormal.xy; + vN.w = vNormal.x; + vN.z = vNormal.y; + float4 vDependentTexCoords = vN * vNormal.a * reflectRefractScale; + + vDependentTexCoords += ( i.vReflectXY_vRefractYX * ooW ); + vReflectTexCoord = vDependentTexCoords.xy; + vRefractTexCoord = vDependentTexCoords.wz; + + HALF4 vReflectColor = tex2D( ReflectSampler, vReflectTexCoord ); +#if BLURRY_REFRACT + // Sample reflection and refraction + float2 ddx1=float2(0.005,0); + float2 ddy1=float2(0,0.005); + float4 vRefractColor=float4(0,0,0,0); + +#if 0 + float sumweights=0; + for(int ix=-2;ix<=2;ix++) + { + for(int iy=-2;iy<=2;iy++) + { + float weight=1; ///(1+abs(ix)+abs(iy)); + vRefractColor += weight*tex2D( RefractSampler, vRefractTexCoord+ix*ddx1+iy*ddy1); + sumweights+=weight; + } + } +#else + // NOTE: Generated by genwaterloop.pl in the stdshaders directory. + // Need to unroll for 360 to avoid shader compilation problems. + // Modified genwaterloop.pl and regenerate if you need different params + vRefractColor += tex2D( RefractSampler, vRefractTexCoord + -2 * ddx1 + -2 * ddy1 ); + vRefractColor += tex2D( RefractSampler, vRefractTexCoord + -2 * ddx1 + -1 * ddy1 ); + vRefractColor += tex2D( RefractSampler, vRefractTexCoord + -2 * ddx1 + 0 * ddy1 ); + vRefractColor += tex2D( RefractSampler, vRefractTexCoord + -2 * ddx1 + 1 * ddy1 ); + vRefractColor += tex2D( RefractSampler, vRefractTexCoord + -2 * ddx1 + 2 * ddy1 ); + vRefractColor += tex2D( RefractSampler, vRefractTexCoord + -1 * ddx1 + -2 * ddy1 ); + vRefractColor += tex2D( RefractSampler, vRefractTexCoord + -1 * ddx1 + -1 * ddy1 ); + vRefractColor += tex2D( RefractSampler, vRefractTexCoord + -1 * ddx1 + 0 * ddy1 ); + vRefractColor += tex2D( RefractSampler, vRefractTexCoord + -1 * ddx1 + 1 * ddy1 ); + vRefractColor += tex2D( RefractSampler, vRefractTexCoord + -1 * ddx1 + 2 * ddy1 ); + vRefractColor += tex2D( RefractSampler, vRefractTexCoord + 0 * ddx1 + -2 * ddy1 ); + vRefractColor += tex2D( RefractSampler, vRefractTexCoord + 0 * ddx1 + -1 * ddy1 ); + vRefractColor += tex2D( RefractSampler, vRefractTexCoord + 0 * ddx1 + 0 * ddy1 ); + vRefractColor += tex2D( RefractSampler, vRefractTexCoord + 0 * ddx1 + 1 * ddy1 ); + vRefractColor += tex2D( RefractSampler, vRefractTexCoord + 0 * ddx1 + 2 * ddy1 ); + vRefractColor += tex2D( RefractSampler, vRefractTexCoord + 1 * ddx1 + -2 * ddy1 ); + vRefractColor += tex2D( RefractSampler, vRefractTexCoord + 1 * ddx1 + -1 * ddy1 ); + vRefractColor += tex2D( RefractSampler, vRefractTexCoord + 1 * ddx1 + 0 * ddy1 ); + vRefractColor += tex2D( RefractSampler, vRefractTexCoord + 1 * ddx1 + 1 * ddy1 ); + vRefractColor += tex2D( RefractSampler, vRefractTexCoord + 1 * ddx1 + 2 * ddy1 ); + vRefractColor += tex2D( RefractSampler, vRefractTexCoord + 2 * ddx1 + -2 * ddy1 ); + vRefractColor += tex2D( RefractSampler, vRefractTexCoord + 2 * ddx1 + -1 * ddy1 ); + vRefractColor += tex2D( RefractSampler, vRefractTexCoord + 2 * ddx1 + 0 * ddy1 ); + vRefractColor += tex2D( RefractSampler, vRefractTexCoord + 2 * ddx1 + 1 * ddy1 ); + vRefractColor += tex2D( RefractSampler, vRefractTexCoord + 2 * ddx1 + 2 * ddy1 ); + float sumweights = 25; + // NOTE: end of generated code. +#endif + + vRefractColor *= (1.0/sumweights); + vReflectColor *= i.fReflectOverbright; + vReflectColor *= i.vReflectTint; + vRefractColor *= i.vRefractTint; +# if ABOVEWATER + // Don't mess with this in the underwater case since we don't really have + // depth values there. + // get the blurred depth value to be used for fog. + waterFogDepthValue = vRefractColor.a; +# endif +#else + vReflectColor *= i.vReflectTint; + HALF4 vRefractColor = tex2D( RefractSampler, vRefractTexCoord ); + // get the depth value from the refracted sample to be used for fog. +# if ABOVEWATER + // Don't mess with this in the underwater case since we don't really have + // depth values there. + waterFogDepthValue = tex2D( RefractSampler, vRefractTexCoord ).a; +# endif +#endif + + half3 vEyeVect; + vEyeVect = normalize( i.vTangentEyeVect ); + + // Fresnel term + HALF fNdotV = saturate( dot( vEyeVect, vNormal ) ); + HALF fFresnel = pow( 1.0 - fNdotV, 5 ); + +#if !BASETEXTURE + // fFresnel == 1.0f means full reflection + fFresnel *= saturate( ( waterFogDepthValue - 0.05f ) * 20.0f ); +#endif + + + // blend between refraction and fog color. +#if ABOVEWATER + vRefractColor = lerp( vRefractColor, i.waterFogColor * LINEAR_LIGHT_SCALE, saturate( waterFogDepthValue - 0.05f ) ); +#else + float waterFogFactor = saturate( ( i.vProjPos.z - i.fWaterFogStart ) / i.fWaterFogEndMinusStart ); + vRefractColor = lerp( vRefractColor, i.waterFogColor * LINEAR_LIGHT_SCALE, waterFogFactor ); +#endif + +#if BASETEXTURE + float4 baseSample = tex2D( BaseTextureSampler, i.vBumpTexCoord.xy ); + HALF2 bumpCoord1; + HALF2 bumpCoord2; + HALF2 bumpCoord3; + ComputeBumpedLightmapCoordinates( i.lightmapTexCoord1And2, i.lightmapTexCoord3.xy, + bumpCoord1, bumpCoord2, bumpCoord3 ); + + HALF4 lightmapSample1 = tex2D( LightmapSampler, bumpCoord1 ); + HALF3 lightmapColor1 = lightmapSample1.rgb; + HALF3 lightmapColor2 = tex2D( LightmapSampler, bumpCoord2 ); + HALF3 lightmapColor3 = tex2D( LightmapSampler, bumpCoord3 ); + + float3 dp; + dp.x = saturate( dot( vNormal, bumpBasis[0] ) ); + dp.y = saturate( dot( vNormal, bumpBasis[1] ) ); + dp.z = saturate( dot( vNormal, bumpBasis[2] ) ); + dp *= dp; + + float3 diffuseLighting = dp.x * lightmapColor1 + + dp.y * lightmapColor2 + + dp.z * lightmapColor3; + float sum = dot( dp, float3( 1.0f, 1.0f, 1.0f ) ); + diffuseLighting *= LIGHT_MAP_SCALE / sum; + HALF3 diffuseComponent = baseSample.rgb * diffuseLighting; +#endif + + if( bReflect && bRefract ) + { + result = lerp( vRefractColor, vReflectColor, fFresnel ); + } + else if( bReflect ) + { +#if BASETEXTURE + result = float4( diffuseComponent, 1.0f ) + vReflectColor * fFresnel * baseSample.a; +#else + result = vReflectColor; +#endif + } + else if( bRefract ) + { + result = vRefractColor; + } + else + { + result = float4( 0.0f, 0.0f, 0.0f, 0.0f ); + } + +#if (PIXELFOGTYPE == PIXEL_FOG_TYPE_RANGE) + fogFactor = CalcRangeFog( i.vProjPos.z, i.pixelFogParams.x, i.pixelFogParams.z, i.pixelFogParams.w ); +#else + fogFactor = 0; +#endif +} diff --git a/materialsystem/stdshaders/waterreflect_ps14.psh b/materialsystem/stdshaders/waterreflect_ps14.psh new file mode 100644 index 0000000..4d277b1 --- /dev/null +++ b/materialsystem/stdshaders/waterreflect_ps14.psh @@ -0,0 +1,8 @@ +ps.1.4 + +texld r0, t0_dw.xyw ; sample dudv map + +phase + +texld r0, t0 + diff --git a/materialsystem/stdshaders/waterrefract_ps14.psh b/materialsystem/stdshaders/waterrefract_ps14.psh new file mode 100644 index 0000000..8d63934 --- /dev/null +++ b/materialsystem/stdshaders/waterrefract_ps14.psh @@ -0,0 +1,23 @@ +ps.1.4 + +; non-fresnel version +; t0: +; texture: dudv map +; texcoords: coords for normal map +; t1: +; texcoords: uvw for first dp3 +; t2: +; texture: renderable texture that we are going to perturb +; texcoords: uvw for second dp3 +;tex t0 ; sample dudv map +;texm3x2pad t1, t0 ; +;texm3x2tex t2, t0 ; sample renderabletexture + +;mul r0, t2, c1 + + +texld r0, t0 ; sample dudv map + +phase + +texld r0, t2_dw.xyw diff --git a/materialsystem/stdshaders/weapon_sheen_pass_helper.cpp b/materialsystem/stdshaders/weapon_sheen_pass_helper.cpp new file mode 100644 index 0000000..05fb43f --- /dev/null +++ b/materialsystem/stdshaders/weapon_sheen_pass_helper.cpp @@ -0,0 +1,291 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// + +/* Based heavily on cloak_blended_pass, look at cloak_blended_pass_helper.cpp + +==================================================================================================== */ + +#include "BaseVSShader.h" +#include "mathlib/vmatrix.h" +#include "weapon_sheen_pass_helper.h" +#include "convar.h" + +// Auto generated inc files +#include "weapon_sheen_pass_vs20.inc" +#include "weapon_sheen_pass_ps20.inc" +#include "weapon_sheen_pass_ps20b.inc" + +#ifndef _X360 +#include "weapon_sheen_pass_vs30.inc" +#include "weapon_sheen_pass_ps30.inc" +#endif + +void InitParamsWeaponSheenPass( CBaseVSShader *pShader, IMaterialVar** params, const char *pMaterialName, WeaponSheenPassVars_t &info ) +{ + // Set material flags + SET_FLAGS2( MATERIAL_VAR2_SUPPORTS_HW_SKINNING ); + SET_FLAGS( MATERIAL_VAR_MODEL ); + SET_FLAGS2( MATERIAL_VAR2_NEEDS_TANGENT_SPACES ); + + // Set material parameter default values + if ( ( info.m_nSheenMapMaskFrame != -1 ) && ( !params[info.m_nSheenMapMaskFrame]->IsDefined() ) ) + { + params[info.m_nSheenMapMaskFrame]->SetFloatValue( 0 ); + } + + if ( ( info.m_nSheenMapTint != -1 ) && ( !params[info.m_nSheenMapTint]->IsDefined() ) ) + { + params[info.m_nSheenMapTint]->SetVecValue( 1.0f, 1.0f, 1.0f, 1.0f ); + } + + if ( ( info.m_nSheenMapMaskScaleX != -1 ) && ( !params[info.m_nSheenMapMaskScaleX]->IsDefined() ) ) + { + params[info.m_nSheenMapMaskScaleX]->SetFloatValue( 1.0f ); + } + if ( ( info.m_nSheenMapMaskScaleY != -1 ) && ( !params[info.m_nSheenMapMaskScaleY]->IsDefined() ) ) + { + params[info.m_nSheenMapMaskScaleY]->SetFloatValue( 1.0f ); + } + + if ( ( info.m_nSheenMapMaskOffsetX != -1 ) && ( !params[info.m_nSheenMapMaskOffsetX]->IsDefined() ) ) + { + params[info.m_nSheenMapMaskOffsetX]->SetFloatValue( 0 ); + } + if ( ( info.m_nSheenMapMaskOffsetY != -1 ) && ( !params[info.m_nSheenMapMaskOffsetY]->IsDefined() ) ) + { + params[info.m_nSheenMapMaskOffsetY]->SetFloatValue( 0 ); + } + + if ( ( info.m_nSheenMapMaskDirection != -1 ) && ( !params[info.m_nSheenMapMaskDirection]->IsDefined() ) ) + { + params[info.m_nSheenMapMaskDirection]->SetFloatValue( 0 ); + } + + if( (info.m_nSheenIndex != -1 ) && !params[info.m_nSheenIndex]->IsDefined() ) + { + params[info.m_nSheenIndex]->SetIntValue( 0 ); + } + + if( (info.m_nBumpFrame != -1 ) && !params[info.m_nBumpFrame]->IsDefined() ) + { + params[info.m_nBumpFrame]->SetIntValue( 0 ); + } +} + +void InitWeaponSheenPass( CBaseVSShader *pShader, IMaterialVar** params, WeaponSheenPassVars_t &info ) +{ + // Load textures + if ( g_pConfig->UseBumpmapping() ) + { + if ( (info.m_nBumpmap != -1) && params[info.m_nBumpmap]->IsDefined() ) + { + pShader->LoadTexture( info.m_nBumpmap ); + } + } + + if ( (info.m_nSheenMap != -1) && params[info.m_nSheenMap]->IsDefined() ) + { + pShader->LoadCubeMap( info.m_nSheenMap, g_pHardwareConfig->GetHDRType() == HDR_TYPE_NONE ? TEXTUREFLAGS_SRGB : 0 ); + } + + if ( (info.m_nSheenMapMask != -1) && params[info.m_nSheenMapMask]->IsDefined() ) + { + pShader->LoadTexture( info.m_nSheenMapMask ); + } + +} + +void DrawWeaponSheenPass( CBaseVSShader *pShader, IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, + IShaderShadow* pShaderShadow, WeaponSheenPassVars_t &info, VertexCompressionType_t vertexCompression ) +{ + bool bBumpMapping = ( !g_pConfig->UseBumpmapping() ) || ( info.m_nBumpmap == -1 ) || !params[info.m_nBumpmap]->IsTexture() ? 0 : 1; + + SHADOW_STATE + { + // Reset shadow state manually since we're drawing from two materials + pShader->SetInitialShadowState( ); + + // Set stream format (note that this shader supports compression) + unsigned int flags = VERTEX_POSITION | VERTEX_NORMAL | VERTEX_FORMAT_COMPRESSED; + int nTexCoordCount = 1; + int userDataSize = 0; + pShaderShadow->VertexShaderVertexFormat( flags, nTexCoordCount, NULL, userDataSize ); + +#ifndef _X360 + if ( !g_pHardwareConfig->HasFastVertexTextures() ) +#endif + { + // Vertex Shader + DECLARE_STATIC_VERTEX_SHADER( weapon_sheen_pass_vs20 ); + SET_STATIC_VERTEX_SHADER_COMBO( BUMPMAP, bBumpMapping ? 1 : 0 ); + SET_STATIC_VERTEX_SHADER( weapon_sheen_pass_vs20 ); + + // Pixel Shader + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_STATIC_PIXEL_SHADER( weapon_sheen_pass_ps20b ); + SET_STATIC_PIXEL_SHADER_COMBO( BUMPMAP, bBumpMapping ? 1 : 0 ); + SET_STATIC_PIXEL_SHADER( weapon_sheen_pass_ps20b ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( weapon_sheen_pass_ps20 ); + SET_STATIC_PIXEL_SHADER_COMBO( BUMPMAP, bBumpMapping ? 1 : 0 ); + SET_STATIC_PIXEL_SHADER( weapon_sheen_pass_ps20 ); + } + } +#ifndef _X360 + else + { + // The vertex shader uses the vertex id stream + SET_FLAGS2( MATERIAL_VAR2_USES_VERTEXID ); + + // Vertex Shader + DECLARE_STATIC_VERTEX_SHADER( weapon_sheen_pass_vs30 ); + SET_STATIC_VERTEX_SHADER_COMBO( BUMPMAP, bBumpMapping ? 1 : 0 ); + SET_STATIC_VERTEX_SHADER( weapon_sheen_pass_vs30 ); + + // Pixel Shader + DECLARE_STATIC_PIXEL_SHADER( weapon_sheen_pass_ps30 ); + SET_STATIC_PIXEL_SHADER_COMBO( BUMPMAP, bBumpMapping ? 1 : 0 ); + SET_STATIC_PIXEL_SHADER( weapon_sheen_pass_ps30 ); + } +#endif + + // Textures + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); // Refraction texture + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, true ); + if ( bBumpMapping ) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); // Bump + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER1, false ); // Not sRGB + } + pShaderShadow->EnableSRGBWrite( true ); + + pShaderShadow->EnableTexture( SHADER_SAMPLER2, true ); + if( g_pHardwareConfig->GetHDRType() == HDR_TYPE_NONE ) + { + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER2, true ); + } + + pShaderShadow->EnableTexture( SHADER_SAMPLER3, true ); + if( g_pHardwareConfig->GetHDRType() == HDR_TYPE_NONE ) + { + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER3, true ); + } + + // Blending + pShader->EnableAlphaBlending( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA ); + pShaderShadow->EnableAlphaWrites( false ); + + // !!! We need to turn this back on because EnableAlphaBlending() above disables it! + pShaderShadow->EnableDepthWrites( true ); + } + DYNAMIC_STATE + { + // Reset render state manually since we're drawing from two materials + pShaderAPI->SetDefaultState(); + + // Set Vertex Shader Constants + if ( ( bBumpMapping ) && ( info.m_nBumpTransform != -1 ) ) + { + pShader->SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, info.m_nBumpTransform ); + } + +#ifndef _X360 + if ( !g_pHardwareConfig->HasFastVertexTextures() ) +#endif + { + // Set Vertex Shader Combos + DECLARE_DYNAMIC_VERTEX_SHADER( weapon_sheen_pass_vs20 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, pShaderAPI->GetCurrentNumBones() > 0 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression ); + SET_DYNAMIC_VERTEX_SHADER( weapon_sheen_pass_vs20 ); + + // Set Pixel Shader Combos + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_DYNAMIC_PIXEL_SHADER( weapon_sheen_pass_ps20b ); + SET_DYNAMIC_PIXEL_SHADER( weapon_sheen_pass_ps20b ); + } + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( weapon_sheen_pass_ps20 ); + SET_DYNAMIC_PIXEL_SHADER( weapon_sheen_pass_ps20 ); + } + } +#ifndef _X360 + else + { + pShader->SetHWMorphVertexShaderState( VERTEX_SHADER_SHADER_SPECIFIC_CONST_6, VERTEX_SHADER_SHADER_SPECIFIC_CONST_7, SHADER_VERTEXTEXTURE_SAMPLER0 ); + + // Set Vertex Shader Combos + DECLARE_DYNAMIC_VERTEX_SHADER( weapon_sheen_pass_vs30 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, pShaderAPI->GetCurrentNumBones() > 0 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( MORPHING, pShaderAPI->IsHWMorphingEnabled() ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression ); + SET_DYNAMIC_VERTEX_SHADER( weapon_sheen_pass_vs30 ); + + // Set Pixel Shader Combos + DECLARE_DYNAMIC_PIXEL_SHADER( weapon_sheen_pass_ps30 ); + SET_DYNAMIC_PIXEL_SHADER( weapon_sheen_pass_ps30 ); + } +#endif + + // Bind textures + pShaderAPI->BindStandardTexture( SHADER_SAMPLER0, TEXTURE_FRAME_BUFFER_FULL_TEXTURE_0 ); // Refraction Map + if ( bBumpMapping ) + { + pShader->BindTexture( SHADER_SAMPLER1, info.m_nBumpmap, info.m_nBumpFrame ); + } + + if ( info.m_nSheenMap != -1 ) + { + pShader->BindTexture( SHADER_SAMPLER2, info.m_nSheenMap, -1 ); + } + + if ( info.m_nSheenMapMask != -1 ) + { + pShader->BindTexture( SHADER_SAMPLER3, info.m_nSheenMapMask, info.m_nSheenMapMaskFrame ); + } + + // Set Pixel Shader Constants + float vEyePos[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; + pShaderAPI->GetWorldSpaceCameraPosition( vEyePos ); + pShaderAPI->SetPixelShaderConstant( 5, vEyePos, 1 ); + + float vPackedConst1[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; + vPackedConst1[0] = IS_PARAM_DEFINED( info.m_nSheenMapMaskScaleX ) ? params[info.m_nSheenMapMaskScaleX]->GetFloatValue() : 1.0f; + vPackedConst1[1] = IS_PARAM_DEFINED( info.m_nSheenMapMaskScaleY ) ? params[info.m_nSheenMapMaskScaleY]->GetFloatValue() : 1.0f; + vPackedConst1[2] = IS_PARAM_DEFINED( info.m_nSheenMapMaskOffsetX ) ? params[info.m_nSheenMapMaskOffsetX]->GetFloatValue() : 0.0f; + vPackedConst1[3] = IS_PARAM_DEFINED( info.m_nSheenMapMaskOffsetY ) ? params[info.m_nSheenMapMaskOffsetY]->GetFloatValue() : 0.0f; + pShaderAPI->SetPixelShaderConstant( 6, vPackedConst1, 1 ); + + float vPackedConst2[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; + vPackedConst2[0] = IS_PARAM_DEFINED( info.m_nSheenMapMaskDirection ) ? params[info.m_nSheenMapMaskDirection]->GetFloatValue() : 0.0f; + vPackedConst2[1] = IS_PARAM_DEFINED( info.m_nSheenIndex ) ? params[info.m_nSheenIndex]->GetFloatValue() : 0.0f; + pShaderAPI->SetPixelShaderConstant( 7, vPackedConst2, 1 ); + + // Map color tint + pShaderAPI->SetPixelShaderConstant( 8, IS_PARAM_DEFINED( info.m_nSheenMapTint ) ? params[info.m_nSheenMapTint]->GetVecValue() : kDefaultSheenColorTint, 1 ); + + // Set c0 and c1 to contain first two rows of ViewProj matrix + VMatrix mView, mProj; + pShaderAPI->GetMatrix( MATERIAL_VIEW, mView.m[0] ); + pShaderAPI->GetMatrix( MATERIAL_PROJECTION, mProj.m[0] ); + VMatrix mViewProj = mView * mProj; + mViewProj = mViewProj.Transpose3x3(); + pShaderAPI->SetPixelShaderConstant( 0, mViewProj.m[0], 2 ); + } + pShader->Draw(); +} + +bool ShouldDrawMaterialSheen ( IMaterialVar** params, WeaponSheenPassVars_t &info ) +{ + // If the frame is zero we're not rendering + if ( IS_PARAM_DEFINED( info.m_nSheenMapMaskFrame ) && params[info.m_nSheenMapMaskFrame]->GetIntValue() > 0 ) + { + return true; + } + + return false; +} \ No newline at end of file diff --git a/materialsystem/stdshaders/weapon_sheen_pass_helper.h b/materialsystem/stdshaders/weapon_sheen_pass_helper.h new file mode 100644 index 0000000..91dd333 --- /dev/null +++ b/materialsystem/stdshaders/weapon_sheen_pass_helper.h @@ -0,0 +1,51 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// + +#ifndef WEAPON_SHEEN_PASS_HELPER_H +#define WEAPON_SHEEN_PASS_HELPER_H +#ifdef _WIN32 +#pragma once +#endif + +#include + +//----------------------------------------------------------------------------- +// Forward declarations +//----------------------------------------------------------------------------- +class CBaseVSShader; +class IMaterialVar; +class IShaderDynamicAPI; +class IShaderShadow; + +//----------------------------------------------------------------------------- +// Init params/ init/ draw methods +//----------------------------------------------------------------------------- +struct WeaponSheenPassVars_t +{ + WeaponSheenPassVars_t() { memset( this, 0xFF, sizeof(WeaponSheenPassVars_t) ); } + + int m_nSheenMap; + int m_nSheenMapMask; + int m_nSheenMapMaskFrame; + int m_nSheenMapTint; + int m_nSheenMapMaskScaleX; + int m_nSheenMapMaskScaleY; + int m_nSheenMapMaskOffsetX; + int m_nSheenMapMaskOffsetY; + int m_nSheenMapMaskDirection; + int m_nSheenIndex; + + int m_nBumpmap; + int m_nBumpFrame; + int m_nBumpTransform; +}; + +static const float kDefaultSheenColorTint[4] = { 0.0f, 1.0f, 0.0f, 1.0f }; + +void InitParamsWeaponSheenPass( CBaseVSShader *pShader, IMaterialVar** params, const char *pMaterialName, WeaponSheenPassVars_t &info ); +void InitWeaponSheenPass( CBaseVSShader *pShader, IMaterialVar** params, WeaponSheenPassVars_t &info ); +void DrawWeaponSheenPass( CBaseVSShader *pShader, IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, + IShaderShadow* pShaderShadow, WeaponSheenPassVars_t &info, VertexCompressionType_t vertexCompression ); + +bool ShouldDrawMaterialSheen ( IMaterialVar** params, WeaponSheenPassVars_t &info ); + +#endif // WEAPON_SHEEN_PASS_HELPER_H diff --git a/materialsystem/stdshaders/weapon_sheen_pass_ps2x.fxc b/materialsystem/stdshaders/weapon_sheen_pass_ps2x.fxc new file mode 100644 index 0000000..3a59118 --- /dev/null +++ b/materialsystem/stdshaders/weapon_sheen_pass_ps2x.fxc @@ -0,0 +1,199 @@ +//========= Copyright © 1996-2006, Valve Corporation, All rights reserved. ============// + +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps30][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX] +// STATIC: "BUMPMAP" "0..1" + +// Includes ======================================================================================= +#include "common_vertexlitgeneric_dx9.h" + +// Texture Samplers =============================================================================== +sampler g_tRefractionSampler : register( s0 ); +#if BUMPMAP + sampler g_tBumpSampler : register( s1 ); +#endif + +sampler EnvmapSampler : register( s2 ); +sampler EnvmapMaskSampler : register( s3 ); + +// Shaders Constants and Globals ================================================================== +const float4 g_mViewProj0 : register( c0 ); // 1st row of matrix +const float4 g_mViewProj1 : register( c1 ); // 2nd row of matrix + +const float4 g_vCameraPosition : register( c5 ); +const float4 g_vPackedConst6 : register( c6 ); +const float4 g_vPackedConst7 : register( c7 ); +const float4 g_cCloakColorTint : register( c8 ); + +#define g_flSheenMapMaskScaleX g_vPackedConst6.x // Default = 1.0f +#define g_flSheenMapMaskScaleY g_vPackedConst6.y // Default = 1.0f +#define g_flSheenMapMaskOffsetX g_vPackedConst6.z // Default = 0.0f +#define g_flSheenMapMaskOffsetY g_vPackedConst6.w // Default = 0.0f + +#define g_flSheenDirection g_vPackedConst7.x // 0,1,2 -> XYZ +#define g_flEffectIndex g_vPackedConst7.y // W + +// 8 2D Poisson offsets (designed to use .xy and .wz swizzles (not .zw) +static const float4 g_vPoissonOffset[4] = { float4 (-0.0876f, 0.9703f, 0.5651f, 0.4802f ), + float4 ( 0.1851f, 0.1580f, -0.0617f, -0.2616f ), + float4 (-0.5477f, -0.6603f, 0.0711f, -0.5325f ), + float4 (-0.0751f, -0.8954f, 0.4054f, 0.6384f ) }; + +// Interpolated values ============================================================================ +struct PS_INPUT +{ + float3 vWorldNormal : TEXCOORD0; // World-space normal + float3 vProjPosForRefract : TEXCOORD1; + float3 vWorldViewVector : TEXCOORD2; + float3x3 mTangentSpaceTranspose : TEXCOORD3; + // second row : TEXCOORD4; + // third row : TEXCOORD5; + float2 vTexCoord0 : TEXCOORD6; + + float4 vModelSpacePos : TEXCOORD7; +}; + +// Main =========================================================================================== +float4 main( PS_INPUT i ) : COLOR +{ + float3 vWorldNormal = normalize( i.vWorldNormal.xyz ); + + #if BUMPMAP + float4 vBumpTexel = tex2D( g_tBumpSampler, i.vTexCoord0.xy ); + float3 vTangentNormal = ( 2.0f * vBumpTexel ) - 1.0f; + vWorldNormal.xyz = mul( i.mTangentSpaceTranspose, vTangentNormal.xyz ); + #endif + + float4 result; + + // Staging test for weapon patterns + if ( g_flEffectIndex == 2 ) + { + float3 ppos = i.vModelSpacePos; + float2 temp = 0; + + // 'Scaling' of texture to get it to map to the weapons + // No Skewing, just move left to right + if ( g_flSheenDirection == 0 ) + { + temp.x = ppos.z; + temp.y = ppos.y; + } + else if ( g_flSheenDirection == 1 ) + { + temp.x = ppos.z; + temp.y = ppos.x; + } + else + { + temp.x = ppos.y; + temp.y = ppos.x; + } + + temp.x -= ( g_flSheenMapMaskOffsetX ); // offset + temp.y -= ( g_flSheenMapMaskOffsetY ); // offset + + temp.x /= g_flSheenMapMaskScaleX; // scale + temp.y /= g_flSheenMapMaskScaleY; + + temp.y = 1.0 - temp.y; + + // Sample Texture + // Sample Mask + //float4 patternTexel = tex2D( EnvmapSampler, temp ); + float4 patternTexel = tex2D( EnvmapSampler, i.vTexCoord0.xy ); + float4 maskTexel = tex2D( EnvmapMaskSampler, i.vTexCoord0.xy ); + + //result.rgba = float4( patternTexel.xyz * 1.0, maskTexel.x * 1.0); // 0.3 is a hack to preserve rimlight + //result.rgba = float4( patternTexel.xyz, 1.0); // 0.3 is a hack to preserve rimlight + result.rgba = float4( 0.0,0.0,0.0,0.0); // 0.3 is a hack to preserve rimlight + } + else + { + // generate a hard reflection in to the cube map + float3 vEyeDir = -normalize(i.vWorldViewVector.xyz); + float3 worldSpaceNormal, tangentSpaceNormal; + + tangentSpaceNormal = float3(0, 0, 1); + worldSpaceNormal = normalize( mul( i.mTangentSpaceTranspose, tangentSpaceNormal ) ); + + float3 vReflect = 2 * worldSpaceNormal * dot(worldSpaceNormal, vEyeDir) - vEyeDir; + + float3 envMapColor = float3( 0.0f, 0.0f, 0.0f ); + envMapColor = ENV_MAP_SCALE * texCUBE( EnvmapSampler, vReflect ) * g_cCloakColorTint.xyz; + envMapColor *= 10.0f; + + // Sample the Mask + float4 envmapMaskTexel; + float2 temp = 0; + float3 ppos = i.vModelSpacePos; + + // + // skew the sampling based on sheen direction + //if ( g_flSheenDirection == 0 ) + //{ + // temp.x = ppos.z - ppos.y; + // temp.y = (ppos.x + ppos.y); + //} + //else if ( g_flSheenDirection == 1 ) + //{ + // temp.x = ppos.x - ppos.z; + // temp.y = (ppos.y + ppos.z); + //} + //else + //{ + // temp.x = ppos.y - ppos.x; + // temp.y = (ppos.z + ppos.x); + //} + + // No Skewing, just move left to right + if ( g_flSheenDirection == 0 ) + { + temp.x = ppos.z; + temp.y = ppos.y; + } + else if ( g_flSheenDirection == 1 ) + { + temp.x = ppos.z; + temp.y = ppos.x; + } + else + { + temp.x = ppos.y; + temp.y = ppos.x; + } + + temp.x -= ( g_flSheenMapMaskOffsetX ); // offset + temp.y -= ( g_flSheenMapMaskOffsetY ); // offset + + temp.x /= g_flSheenMapMaskScaleX; // scale + temp.y /= g_flSheenMapMaskScaleY; + + temp.y = 1.0 - temp.y; + + envmapMaskTexel = tex2D( EnvmapMaskSampler, temp ); + + // Build result, only have alpha if there was value in the mask. + // High alpha (white) will override the underlying texture while low to none will show model underneath + //float4 result; + //result.rgba = float4( envMapColor, envmapMaskTexel.x * g_cCloakColorTint.w ); + + if ( g_flEffectIndex == 1 ) + { + //float alpha = max( max( envmapMaskTexel.x, envmapMaskTexel.y), envmapMaskTexel.z ); + //result.rgba = float4( envMapColor.xyz * envmapMaskTexel.xyz, alpha ); + + float alpha = max( max( envMapColor.x, envMapColor.y), envMapColor.z ); + result.rgba = float4( envMapColor.xyz * envmapMaskTexel.xyz, alpha * envmapMaskTexel.x ); + result.rgba = result.rgba * 1.8f; + } + else + { + float alpha = max( max( envMapColor.x, envMapColor.y), envMapColor.z ); + result.rgba = float4( envMapColor.xyz * envmapMaskTexel.xyz, alpha * envmapMaskTexel.x ); + } + } + + return FinalOutput( result, 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE ); +} diff --git a/materialsystem/stdshaders/weapon_sheen_pass_vs20.fxc b/materialsystem/stdshaders/weapon_sheen_pass_vs20.fxc new file mode 100644 index 0000000..e54d45b --- /dev/null +++ b/materialsystem/stdshaders/weapon_sheen_pass_vs20.fxc @@ -0,0 +1,132 @@ +//========= Copyright © 1996-2006, Valve Corporation, All rights reserved. ============// + +// STATIC: "BUMPMAP" "0..1" + +// DYNAMIC: "COMPRESSED_VERTS" "0..1" +// DYNAMIC: "SKINNING" "0..1" +// DYNAMIC: "MORPHING" "0..1" [vs30] + +// Includes +#include "common_vs_fxc.h" + +// Globals +static const bool g_bSkinning = SKINNING ? true : false; +const float4 cBaseTexCoordTransform[2] : register( SHADER_SPECIFIC_CONST_0 ); + +#ifdef SHADER_MODEL_VS_3_0 +// NOTE: cMorphTargetTextureDim.xy = target dimensions, +// cMorphTargetTextureDim.z = 4tuples/morph +const float3 cMorphTargetTextureDim : register( SHADER_SPECIFIC_CONST_6 ); +const float4 cMorphSubrect : register( SHADER_SPECIFIC_CONST_7 ); + +sampler2D morphSampler : register( D3DVERTEXTEXTURESAMPLER0, s0 ); +#endif + +// Structs +struct VS_INPUT +{ + float4 vPos : POSITION; // Position + float4 vNormal : NORMAL; // Normal + float4 vBoneWeights : BLENDWEIGHT; // Skin weights + float4 vBoneIndices : BLENDINDICES; // Skin indices + float4 vTexCoord0 : TEXCOORD0; // Base texture coordinates + + #if BUMPMAP + float4 vTangent : TANGENT; + #endif + + // Position and normal/tangent deltas + float3 vPosFlex : POSITION1; + float3 vNormalFlex : NORMAL1; + + #ifdef SHADER_MODEL_VS_3_0 + float vVertexID : POSITION2; + #endif +}; + +struct VS_OUTPUT +{ + float4 vProjPosition : POSITION; // Projection-space position + float3 vWorldNormal : TEXCOORD0; // World-space normal + float3 vProjPosForRefract : TEXCOORD1; + float3 vWorldViewVector : TEXCOORD2; + + float3x3 mTangentSpaceTranspose : TEXCOORD3; + // second row : TEXCOORD4; + // third row : TEXCOORD5; + float2 vTexCoord0 : TEXCOORD6; + + float4 vModelSpacePos : TEXCOORD7; +}; + +// Main +VS_OUTPUT main( const VS_INPUT i ) +{ + VS_OUTPUT o; + + // Flexes coming in from a separate stream (contribution masked by cFlexScale.x) + float4 vObjPosition = i.vPos; + float3 vObjNormal; + + #if BUMPMAP + float4 vObjTangent; + DecompressVertex_NormalTangent( i.vNormal, i.vTangent, vObjNormal, vObjTangent ); + + #if !defined( SHADER_MODEL_VS_3_0 ) || !MORPHING + ApplyMorph( i.vPosFlex, i.vNormalFlex, vObjPosition.xyz, vObjNormal, vObjTangent.xyz ); + #else + ApplyMorph( morphSampler, cMorphTargetTextureDim, cMorphSubrect, i.vVertexID, float3( 0, 0, 0 ), vObjPosition.xyz, vObjNormal, vObjTangent.xyz ); + #endif + #else // !BUMPMAP + DecompressVertex_Normal( i.vNormal, vObjNormal ); + + #if !defined( SHADER_MODEL_VS_3_0 ) || !MORPHING + ApplyMorph( i.vPosFlex, i.vNormalFlex, vObjPosition.xyz, vObjNormal ); + #else + ApplyMorph( morphSampler, cMorphTargetTextureDim, cMorphSubrect, i.vVertexID, float3( 0, 0, 0 ), + vObjPosition.xyz, vObjNormal ); + #endif + #endif + + // Transform the position + float3 vWorldPosition = { 0.0f, 0.0f, 0.0f }; + float3 vWorldNormal = { 0.0f, 0.0f, 0.0f }; + + float3 vWorldTangent = { 0.0f, 0.0f, 0.0f }; + float3 vWorldBinormal = { 0.0f, 0.0f, 0.0f }; + + #if BUMPMAP + SkinPositionNormalAndTangentSpace( g_bSkinning, vObjPosition, vObjNormal.xyz, vObjTangent.xyzw, i.vBoneWeights, i.vBoneIndices, vWorldPosition, vWorldNormal, vWorldTangent, vWorldBinormal ); + #else + SkinPositionAndNormal( g_bSkinning, vObjPosition, vObjNormal.xyz, i.vBoneWeights, i.vBoneIndices, vWorldPosition, vWorldNormal ); + #endif + o.vWorldNormal.xyz = normalize( vWorldNormal.xyz ); + + // Transform into projection space + float4 vProjPosition = mul( float4( vWorldPosition, 1.0f ), cViewProj ); + o.vProjPosition = vProjPosition; + + // Map projected position to the refraction texture + float2 vRefractPos; + vRefractPos.x = vProjPosition.x; + vRefractPos.y = -vProjPosition.y; // Invert Y + vRefractPos = (vRefractPos + vProjPosition.w) * 0.5f; + o.vProjPosForRefract.xyz = float3(vRefractPos.x, vRefractPos.y, vProjPosition.w); + + // View vector + float3 vWorldViewVector = normalize (vWorldPosition.xyz - cEyePos.xyz); + o.vWorldViewVector.xyz = vWorldViewVector.xyz; + + // Tangent space transform + o.mTangentSpaceTranspose[0] = float3( vWorldTangent.x, vWorldBinormal.x, vWorldNormal.x ); + o.mTangentSpaceTranspose[1] = float3( vWorldTangent.y, vWorldBinormal.y, vWorldNormal.y ); + o.mTangentSpaceTranspose[2] = float3( vWorldTangent.z, vWorldBinormal.z, vWorldNormal.z ); + + // Texture coordinates + o.vTexCoord0.x = dot( i.vTexCoord0.xy, cBaseTexCoordTransform[0] ); + o.vTexCoord0.y = dot( i.vTexCoord0.xy, cBaseTexCoordTransform[1] ); + + // model space + o.vModelSpacePos = float4( i.vPos.xyz, 0) ; + return o; +} diff --git a/materialsystem/stdshaders/white.psh b/materialsystem/stdshaders/white.psh new file mode 100644 index 0000000..67d586f --- /dev/null +++ b/materialsystem/stdshaders/white.psh @@ -0,0 +1,8 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; Just use the vertex color +;------------------------------------------------------------------------------ + +def c0, 1.0f, 1.0f, 1.0f, 1.0f +mov r0, c0 diff --git a/materialsystem/stdshaders/white_ps2x.fxc b/materialsystem/stdshaders/white_ps2x.fxc new file mode 100644 index 0000000..cd5b34f --- /dev/null +++ b/materialsystem/stdshaders/white_ps2x.fxc @@ -0,0 +1,13 @@ +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX] + +#include "common_ps_fxc.h" + +struct PS_INPUT +{ +}; + +HALF4 main( PS_INPUT i ) : COLOR +{ + return FinalOutput( float4( 1.0f, 1.0f, 1.0f, 1.0f ), 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE ); +} diff --git a/materialsystem/stdshaders/windowimposter_dx80.cpp b/materialsystem/stdshaders/windowimposter_dx80.cpp new file mode 100644 index 0000000..970c3c6 --- /dev/null +++ b/materialsystem/stdshaders/windowimposter_dx80.cpp @@ -0,0 +1,70 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//=============================================================================// + +#include "BaseVSShader.h" + +#include "windowimposter_vs11.inc" +#include "windowimposter_ps11.inc" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +DEFINE_FALLBACK_SHADER( WindowImposter, WindowImposter_DX80 ) + +BEGIN_VS_SHADER( WindowImposter_DX80, + "Help for WindowImposter_DX80" ) + + BEGIN_SHADER_PARAMS + SHADER_PARAM( ENVMAP, SHADER_PARAM_TYPE_TEXTURE, "shadertest/shadertest_env", "envmap" ) + END_SHADER_PARAMS + + // Set up anything that is necessary to make decisions in SHADER_FALLBACK. + SHADER_INIT_PARAMS() + { + } + + SHADER_FALLBACK + { + if ( IsPC() && g_pHardwareConfig->GetDXSupportLevel() < 80) + return "WindowImposter_DX60"; + + return NULL; + } + + SHADER_INIT + { + LoadCubeMap( ENVMAP ); + } + + SHADER_DRAW + { + SHADOW_STATE + { + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + + windowimposter_vs11_Static_Index vshIndex; + pShaderShadow->SetVertexShader( "windowimposter_vs11", vshIndex.GetIndex() ); + + pShaderShadow->SetPixelShader("windowimposter_ps11"); + pShaderShadow->VertexShaderVertexFormat( VERTEX_POSITION, 1, 0, 0 ); + pShaderShadow->EnableBlending( true ); + pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA ); + pShaderShadow->EnableDepthWrites( false ); + FogToFogColor(); + } + DYNAMIC_STATE + { + windowimposter_vs11_Dynamic_Index vshIndex; + vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() ); + + BindTexture( SHADER_SAMPLER0, ENVMAP, -1 ); + SetModulationVertexShaderDynamicState(); + } + Draw(); + } + +END_SHADER diff --git a/materialsystem/stdshaders/windowimposter_dx90.cpp b/materialsystem/stdshaders/windowimposter_dx90.cpp new file mode 100644 index 0000000..0bbe291 --- /dev/null +++ b/materialsystem/stdshaders/windowimposter_dx90.cpp @@ -0,0 +1,107 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//=============================================================================// + +#include "BaseVSShader.h" +#include "cpp_shader_constant_register_map.h" + +#include "windowimposter_vs20.inc" +#include "windowimposter_ps20.inc" +#include "windowimposter_ps20b.inc" + + + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +DEFINE_FALLBACK_SHADER( WindowImposter, WindowImposter_DX90 ) + +BEGIN_VS_SHADER( WindowImposter_DX90, + "Help for WindowImposter_DX90" ) + + BEGIN_SHADER_PARAMS + SHADER_PARAM( ENVMAP, SHADER_PARAM_TYPE_TEXTURE, "shadertest/shadertest_env", "envmap" ) + END_SHADER_PARAMS + + // Set up anything that is necessary to make decisions in SHADER_FALLBACK. + SHADER_INIT_PARAMS() + { + } + + SHADER_FALLBACK + { + if ( g_pHardwareConfig->GetDXSupportLevel() < 90) + return "WindowImposter_DX80"; + + return NULL; + } + + SHADER_INIT + { + LoadCubeMap( ENVMAP ); + } + + SHADER_DRAW + { + SHADOW_STATE + { + if( g_pHardwareConfig->GetHDRType() != HDR_TYPE_NONE ) + pShaderShadow->EnableSRGBWrite( true ); + + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + + DECLARE_STATIC_VERTEX_SHADER( windowimposter_vs20 ); + SET_STATIC_VERTEX_SHADER( windowimposter_vs20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_STATIC_PIXEL_SHADER( windowimposter_ps20b ); + SET_STATIC_PIXEL_SHADER( windowimposter_ps20b ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( windowimposter_ps20 ); + SET_STATIC_PIXEL_SHADER( windowimposter_ps20 ); + } + + pShaderShadow->VertexShaderVertexFormat( VERTEX_POSITION, 1, 0, 0 ); + pShaderShadow->EnableBlending( true ); + pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA ); + pShaderShadow->EnableDepthWrites( false ); + FogToFogColor(); + } + DYNAMIC_STATE + { + DECLARE_DYNAMIC_VERTEX_SHADER( windowimposter_vs20 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( DOWATERFOG, pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + SET_DYNAMIC_VERTEX_SHADER( windowimposter_vs20 ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_DYNAMIC_PIXEL_SHADER( windowimposter_ps20b ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + SET_DYNAMIC_PIXEL_SHADER( windowimposter_ps20b ); + } + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( windowimposter_ps20 ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + SET_DYNAMIC_PIXEL_SHADER( windowimposter_ps20 ); + } + + pShaderAPI->SetPixelShaderFogParams( PSREG_FOG_PARAMS ); + + float vEyePos_SpecExponent[4]; + pShaderAPI->GetWorldSpaceCameraPosition( vEyePos_SpecExponent ); + vEyePos_SpecExponent[3] = 0.0f; + pShaderAPI->SetPixelShaderConstant( PSREG_EYEPOS_SPEC_EXPONENT, vEyePos_SpecExponent, 1 ); + + BindTexture( SHADER_SAMPLER0, ENVMAP, -1 ); + SetModulationVertexShaderDynamicState(); + } + Draw(); + } + +END_SHADER diff --git a/materialsystem/stdshaders/windowimposter_ps11.fxc b/materialsystem/stdshaders/windowimposter_ps11.fxc new file mode 100644 index 0000000..24364ce --- /dev/null +++ b/materialsystem/stdshaders/windowimposter_ps11.fxc @@ -0,0 +1,24 @@ +//====== Copyright © 1996-2004, Valve Corporation, All rights reserved. ======= +// +// Purpose: +// +//============================================================================= + +#include "common_ps_fxc.h" + +sampler EnvmapSampler : register( s0 ); + +struct PS_INPUT +{ + float3 eyeToVertVector : TEXCOORD0; + float4 vertexColor : COLOR; +}; + +HALF4 main( PS_INPUT i ) : COLOR +{ + HALF4 color; + color.xyz = texCUBE( EnvmapSampler, i.eyeToVertVector ); + color.a = 1.0f; + color *= i.vertexColor; + return color; +} diff --git a/materialsystem/stdshaders/windowimposter_ps2x.fxc b/materialsystem/stdshaders/windowimposter_ps2x.fxc new file mode 100644 index 0000000..6c396f9 --- /dev/null +++ b/materialsystem/stdshaders/windowimposter_ps2x.fxc @@ -0,0 +1,37 @@ +//====== Copyright © 1996-2004, Valve Corporation, All rights reserved. ======= +// +// Purpose: +// +//============================================================================= + +// DYNAMIC: "PIXELFOGTYPE" "0..1" + +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX] + +#include "common_ps_fxc.h" +#include "shader_constant_register_map.h" + +sampler EnvmapSampler : register( s0 ); + +const float4 g_FogParams : register( PSREG_FOG_PARAMS ); +const float4 g_EyePos_SpecExponent : register( PSREG_EYEPOS_SPEC_EXPONENT ); + +struct PS_INPUT +{ + float3 eyeToVertVector : TEXCOORD0; + float4 vertexColor : COLOR; + + float4 worldPos_projPosZ : TEXCOORD7; // Necessary for pixel fog +}; + +float4 main( PS_INPUT i ) : COLOR +{ + HALF4 color; + color.xyz = ENV_MAP_SCALE * texCUBE( EnvmapSampler, i.eyeToVertVector ); + color.a = 1.0f; + color *= i.vertexColor; + + float fogFactor = CalcPixelFogFactor( PIXELFOGTYPE, g_FogParams, g_EyePos_SpecExponent.z, i.worldPos_projPosZ.z, i.worldPos_projPosZ.w ); + return FinalOutput( color, fogFactor, PIXELFOGTYPE, TONEMAP_SCALE_LINEAR ); +} diff --git a/materialsystem/stdshaders/windowimposter_vs11.fxc b/materialsystem/stdshaders/windowimposter_vs11.fxc new file mode 100644 index 0000000..0c69312 --- /dev/null +++ b/materialsystem/stdshaders/windowimposter_vs11.fxc @@ -0,0 +1,42 @@ +// DYNAMIC: "DOWATERFOG" "0..1" + +//====== Copyright © 1996-2004, Valve Corporation, All rights reserved. ======= +// +// Purpose: +// +//============================================================================= + +#include "common_vs_fxc.h" + +static const int g_FogType = DOWATERFOG; + +struct VS_INPUT +{ + float3 vPos : POSITION; +}; + +struct VS_OUTPUT +{ + float4 projPos : POSITION; +#if !defined( _X360 ) + float fog : FOG; +#endif + float3 eyeToVertVector : TEXCOORD0; + float4 vertexColor : COLOR; +}; + +VS_OUTPUT main( const VS_INPUT v ) +{ + VS_OUTPUT o = ( VS_OUTPUT )0; + + o.projPos = mul( float4( v.vPos, 1 ), cModelViewProj ); + + float3 worldPos = mul( float4( v.vPos, 1 ), cModel[0] ); + o.eyeToVertVector = worldPos - cEyePos; +#if !defined( _X360 ) + o.fog = CalcFog( worldPos, o.projPos, g_FogType ); +#endif + o.vertexColor = cModulationColor; + return o; +} + diff --git a/materialsystem/stdshaders/windowimposter_vs20.fxc b/materialsystem/stdshaders/windowimposter_vs20.fxc new file mode 100644 index 0000000..d9d3d04 --- /dev/null +++ b/materialsystem/stdshaders/windowimposter_vs20.fxc @@ -0,0 +1,45 @@ +// DYNAMIC: "DOWATERFOG" "0..1" + +//====== Copyright © 1996-2004, Valve Corporation, All rights reserved. ======= +// +// Purpose: +// +//============================================================================= + +#include "common_vs_fxc.h" + +static const int g_FogType = DOWATERFOG; + +struct VS_INPUT +{ + float3 vPos : POSITION; +}; + +struct VS_OUTPUT +{ + float4 projPos : POSITION; +#if !defined( _X360 ) + float fog : FOG; +#endif + float3 eyeToVertVector : TEXCOORD0; + float4 vertexColor : COLOR; + + float4 worldPos_projPosZ : TEXCOORD7; // Necessary for pixel fog +}; + +VS_OUTPUT main( const VS_INPUT v ) +{ + VS_OUTPUT o = ( VS_OUTPUT )0; + + o.projPos = mul( float4( v.vPos, 1 ), cModelViewProj ); + + float3 worldPos = mul( float4( v.vPos, 1 ), cModel[0] ); + o.worldPos_projPosZ = float4( worldPos.xyz, o.projPos.z ); + o.eyeToVertVector = worldPos - cEyePos; +#if !defined( _X360 ) + o.fog = CalcFog( worldPos, o.projPos, g_FogType ); +#endif + o.vertexColor = cModulationColor; + return o; +} + diff --git a/materialsystem/stdshaders/wireframe_dx8.cpp b/materialsystem/stdshaders/wireframe_dx8.cpp new file mode 100644 index 0000000..af5bd97 --- /dev/null +++ b/materialsystem/stdshaders/wireframe_dx8.cpp @@ -0,0 +1,50 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $Header: $ +// $NoKeywords: $ +//=============================================================================// + +#include "BaseVSShader.h" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +DEFINE_FALLBACK_SHADER( Wireframe, Wireframe_DX8 ) +DEFINE_FALLBACK_SHADER( Wireframe_DX9, Wireframe_DX8 ) + +BEGIN_VS_SHADER( Wireframe_DX8, + "Help for Wireframe_DX8" ) + + BEGIN_SHADER_PARAMS + END_SHADER_PARAMS + + SHADER_FALLBACK + { + return 0; + } + + SHADER_INIT_PARAMS() + { + InitParamsUnlitGeneric_DX8( -1, -1, -1, -1, -1, -1, -1 ); + + SET_FLAGS( MATERIAL_VAR_NO_DEBUG_OVERRIDE ); + SET_FLAGS( MATERIAL_VAR_NOFOG ); + SET_FLAGS( MATERIAL_VAR_WIREFRAME ); + } + + SHADER_INIT + { + InitUnlitGeneric_DX8( -1, -1, -1, -1 ); + } + + SHADER_DRAW + { + VertexShaderUnlitGenericPass( + -1, -1, -1, + -1, -1, true, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 ); + } +END_SHADER + diff --git a/materialsystem/stdshaders/wireframe_dx9.cpp b/materialsystem/stdshaders/wireframe_dx9.cpp new file mode 100644 index 0000000..5ff1f02 --- /dev/null +++ b/materialsystem/stdshaders/wireframe_dx9.cpp @@ -0,0 +1,52 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//=====================================================================================// + +#include "BaseVSShader.h" +#include "vertexlitgeneric_dx9_helper.h" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +DEFINE_FALLBACK_SHADER( Wireframe, Wireframe_DX9 ) + +BEGIN_VS_SHADER( Wireframe_DX9, + "Help for Wireframe_DX9" ) + + BEGIN_SHADER_PARAMS + END_SHADER_PARAMS + + SHADER_FALLBACK + { + if ( IsWindows() && g_pHardwareConfig->GetDXSupportLevel() < 90 ) + { + return "Wireframe_DX8"; + } + return 0; + } + + SHADER_INIT_PARAMS() + { + VertexLitGeneric_DX9_Vars_t vars; + InitParamsVertexLitGeneric_DX9( this, params, pMaterialName, false, vars ); + + SET_FLAGS( MATERIAL_VAR_NO_DEBUG_OVERRIDE ); + SET_FLAGS( MATERIAL_VAR_NOFOG ); + SET_FLAGS( MATERIAL_VAR_WIREFRAME ); + } + + SHADER_INIT + { + VertexLitGeneric_DX9_Vars_t vars; + InitVertexLitGeneric_DX9( this, params, false, vars ); + } + + SHADER_DRAW + { + VertexLitGeneric_DX9_Vars_t vars; + DrawVertexLitGeneric_DX9( this, params, pShaderAPI, pShaderShadow, false, vars, vertexCompression, pContextDataPtr ); + } +END_SHADER + diff --git a/materialsystem/stdshaders/worldtwotextureblend.cpp b/materialsystem/stdshaders/worldtwotextureblend.cpp new file mode 100644 index 0000000..542013e --- /dev/null +++ b/materialsystem/stdshaders/worldtwotextureblend.cpp @@ -0,0 +1,500 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $Header: $ +// $NoKeywords: $ +//===========================================================================// + +#include "BaseVSShader.h" + +#include "convar.h" + +#include "lightmappedgeneric_vs20.inc" +#include "WorldTwoTextureBlend_ps20.inc" +#include "WorldTwoTextureBlend_ps20b.inc" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +extern ConVar r_flashlight_version2; + +// FIXME: Need to make a dx9 version so that "CENTROID" works. +BEGIN_VS_SHADER( WorldTwoTextureBlend, + "Help for WorldTwoTextureBlend" ) + +BEGIN_SHADER_PARAMS + SHADER_PARAM_OVERRIDE( BASETEXTURE, SHADER_PARAM_TYPE_TEXTURE, "shadertest/WorldTwoTextureBlend", "iris texture", 0 ) + SHADER_PARAM( ALBEDO, SHADER_PARAM_TYPE_TEXTURE, "shadertest/WorldTwoTextureBlend", "albedo (Base texture with no baked lighting)" ) + SHADER_PARAM( SELFILLUMTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "Self-illumination tint" ) + SHADER_PARAM( DETAIL, SHADER_PARAM_TYPE_TEXTURE, "shadertest/WorldTwoTextureBlend_detail", "detail texture" ) + SHADER_PARAM( DETAILFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $detail" ) + SHADER_PARAM( DETAILSCALE, SHADER_PARAM_TYPE_FLOAT, "1.0", "scale of the detail texture" ) + SHADER_PARAM( DETAIL_ALPHA_MASK_BASE_TEXTURE, SHADER_PARAM_TYPE_BOOL, "0", + "If this is 1, then when detail alpha=0, no base texture is blended and when " + "detail alpha=1, you get detail*base*lightmap" ) + SHADER_PARAM( BUMPMAP, SHADER_PARAM_TYPE_TEXTURE, "models/shadertest/shader1_normal", "bump map" ) + SHADER_PARAM( BUMPFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $bumpmap" ) + SHADER_PARAM( BUMPTRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$bumpmap texcoord transform" ) + SHADER_PARAM( NODIFFUSEBUMPLIGHTING, SHADER_PARAM_TYPE_INTEGER, "0", "0 == Use diffuse bump lighting, 1 = No diffuse bump lighting" ) + SHADER_PARAM( SEAMLESS_SCALE, SHADER_PARAM_TYPE_FLOAT, "0", "Scale factor for 'seamless' texture mapping. 0 means to use ordinary mapping" ) +END_SHADER_PARAMS + + SHADER_FALLBACK + { + if( g_pHardwareConfig->GetDXSupportLevel() < 80 ) + return "WorldTwoTextureBlend_DX6"; + + if( g_pHardwareConfig->GetDXSupportLevel() < 90 ) + return "WorldTwoTextureBlend_DX8"; + + return 0; + } + + SHADER_INIT_PARAMS() + { + + if( !params[DETAIL_ALPHA_MASK_BASE_TEXTURE]->IsDefined() ) + { + params[DETAIL_ALPHA_MASK_BASE_TEXTURE]->SetIntValue( 0 ); + } + + if ( g_pHardwareConfig->SupportsBorderColor() ) + { + params[FLASHLIGHTTEXTURE]->SetStringValue( "effects/flashlight_border" ); + } + else + { + params[FLASHLIGHTTEXTURE]->SetStringValue( "effects/flashlight001" ); + } + + // Write over $basetexture with $albedo if we are going to be using diffuse normal mapping. + if( g_pConfig->UseBumpmapping() && params[BUMPMAP]->IsDefined() && params[ALBEDO]->IsDefined() && + params[BASETEXTURE]->IsDefined() && + !( params[NODIFFUSEBUMPLIGHTING]->IsDefined() && params[NODIFFUSEBUMPLIGHTING]->GetIntValue() ) ) + { + params[BASETEXTURE]->SetStringValue( params[ALBEDO]->GetStringValue() ); + } + + if( !params[NODIFFUSEBUMPLIGHTING]->IsDefined() ) + { + params[NODIFFUSEBUMPLIGHTING]->SetIntValue( 0 ); + } + + if( !params[SELFILLUMTINT]->IsDefined() ) + { + params[SELFILLUMTINT]->SetVecValue( 1.0f, 1.0f, 1.0f ); + } + + if( !params[DETAILSCALE]->IsDefined() ) + { + params[DETAILSCALE]->SetFloatValue( 4.0f ); + } + + if( !params[BUMPFRAME]->IsDefined() ) + { + params[BUMPFRAME]->SetIntValue( 0 ); + } + + if( !params[DETAILFRAME]->IsDefined() ) + { + params[DETAILFRAME]->SetIntValue( 0 ); + } + + // No texture means no self-illum or env mask in base alpha + if ( !params[BASETEXTURE]->IsDefined() ) + { + CLEAR_FLAGS( MATERIAL_VAR_SELFILLUM ); + CLEAR_FLAGS( MATERIAL_VAR_BASEALPHAENVMAPMASK ); + } + + // If in decal mode, no debug override... + if (IS_FLAG_SET(MATERIAL_VAR_DECAL)) + { + SET_FLAGS( MATERIAL_VAR_NO_DEBUG_OVERRIDE ); + } + + SET_FLAGS2( MATERIAL_VAR2_LIGHTING_LIGHTMAP ); + if( g_pConfig->UseBumpmapping() && params[BUMPMAP]->IsDefined() && (params[NODIFFUSEBUMPLIGHTING]->GetIntValue() == 0) ) + { + SET_FLAGS2( MATERIAL_VAR2_LIGHTING_BUMPED_LIGHTMAP ); + } + } + + SHADER_INIT + { + if( g_pConfig->UseBumpmapping() && params[BUMPMAP]->IsDefined() ) + { + LoadBumpMap( BUMPMAP ); + } + + if (params[BASETEXTURE]->IsDefined()) + { + LoadTexture( BASETEXTURE, TEXTUREFLAGS_SRGB ); + + if (!params[BASETEXTURE]->GetTextureValue()->IsTranslucent()) + { + CLEAR_FLAGS( MATERIAL_VAR_SELFILLUM ); + CLEAR_FLAGS( MATERIAL_VAR_BASEALPHAENVMAPMASK ); + } + } + + if (params[DETAIL]->IsDefined()) + { + LoadTexture( DETAIL ); + } + + LoadTexture( FLASHLIGHTTEXTURE, TEXTUREFLAGS_SRGB ); + + // Don't alpha test if the alpha channel is used for other purposes + if (IS_FLAG_SET(MATERIAL_VAR_SELFILLUM) || IS_FLAG_SET(MATERIAL_VAR_BASEALPHAENVMAPMASK) ) + { + CLEAR_FLAGS( MATERIAL_VAR_ALPHATEST ); + } + + // We always need this because of the flashlight. + SET_FLAGS2( MATERIAL_VAR2_NEEDS_TANGENT_SPACES ); + } + + void DrawPass( IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, + IShaderShadow* pShaderShadow, bool hasFlashlight, VertexCompressionType_t vertexCompression ) + { + bool hasBump = params[BUMPMAP]->IsTexture(); + bool hasDiffuseBumpmap = hasBump && (params[NODIFFUSEBUMPLIGHTING]->GetIntValue() == 0); + bool hasBaseTexture = params[BASETEXTURE]->IsTexture(); + bool hasDetailTexture = /*!hasBump && */params[DETAIL]->IsTexture(); + bool hasVertexColor = IS_FLAG_SET( MATERIAL_VAR_VERTEXCOLOR ) != 0; + bool bHasDetailAlpha = params[DETAIL_ALPHA_MASK_BASE_TEXTURE]->GetIntValue() != 0; + bool bIsAlphaTested = IS_FLAG_SET( MATERIAL_VAR_ALPHATEST ) != 0; + + BlendType_t nBlendType = EvaluateBlendRequirements( BASETEXTURE, true ); + bool bFullyOpaque = (nBlendType != BT_BLENDADD) && (nBlendType != BT_BLEND) && !IS_FLAG_SET(MATERIAL_VAR_ALPHATEST); //dest alpha is free for special use + + bool bSeamlessMapping = params[SEAMLESS_SCALE]->GetFloatValue() != 0.0; + + SHADOW_STATE + { + int nShadowFilterMode = 0; + + // Alpha test: FIXME: shouldn't this be handled in Shader_t::SetInitialShadowState + pShaderShadow->EnableAlphaTest( bIsAlphaTested ); + if( hasFlashlight ) + { + if ( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + nShadowFilterMode = g_pHardwareConfig->GetShadowFilterMode(); // Based upon vendor and device dependent formats + } + + SetAdditiveBlendingShadowState( BASETEXTURE, true ); + pShaderShadow->EnableDepthWrites( false ); + + // Be sure not to write to dest alpha + pShaderShadow->EnableAlphaWrites( false ); + } + else + { + SetDefaultBlendingShadowState( BASETEXTURE, true ); + } + + unsigned int flags = VERTEX_POSITION; + if( hasBaseTexture ) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, true ); + } + // if( hasLightmap ) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + pShaderShadow->EnableSRGBRead( SHADER_SAMPLER1, g_pHardwareConfig->GetHDRType() == HDR_TYPE_NONE ); + } + if( hasFlashlight ) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER2, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER7, true ); + pShaderShadow->SetShadowDepthFiltering( SHADER_SAMPLER7 ); + flags |= VERTEX_TANGENT_S | VERTEX_TANGENT_T | VERTEX_NORMAL; + } + if( hasDetailTexture ) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER3, true ); + } + if( hasBump ) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER4, true ); + } + if( hasVertexColor ) + { + flags |= VERTEX_COLOR; + } + + // Normalizing cube map + pShaderShadow->EnableTexture( SHADER_SAMPLER6, true ); + + // texcoord0 : base texcoord + // texcoord1 : lightmap texcoord + // texcoord2 : lightmap texcoord offset + int numTexCoords = 2; + if( hasBump ) + { + numTexCoords = 3; + } + + pShaderShadow->VertexShaderVertexFormat( flags, numTexCoords, 0, 0 ); + + // Pre-cache pixel shaders + bool hasSelfIllum = IS_FLAG_SET( MATERIAL_VAR_SELFILLUM ); + + pShaderShadow->EnableSRGBWrite( true ); + + DECLARE_STATIC_VERTEX_SHADER( lightmappedgeneric_vs20 ); + SET_STATIC_VERTEX_SHADER_COMBO( ENVMAP_MASK, false ); + SET_STATIC_VERTEX_SHADER_COMBO( BUMPMASK, false ); + SET_STATIC_VERTEX_SHADER_COMBO( TANGENTSPACE, hasFlashlight ); + SET_STATIC_VERTEX_SHADER_COMBO( BUMPMAP, hasBump ); + SET_STATIC_VERTEX_SHADER_COMBO( DIFFUSEBUMPMAP, hasDiffuseBumpmap ); + SET_STATIC_VERTEX_SHADER_COMBO( VERTEXCOLOR, hasVertexColor ); + SET_STATIC_VERTEX_SHADER_COMBO( VERTEXALPHATEXBLENDFACTOR, false ); + SET_STATIC_VERTEX_SHADER_COMBO( RELIEF_MAPPING, 0 ); //( bumpmap_variant == 2 )?1:0); + SET_STATIC_VERTEX_SHADER_COMBO( SEAMLESS, bSeamlessMapping ); //( bumpmap_variant == 2 )?1:0); +#ifdef _X360 + SET_STATIC_VERTEX_SHADER_COMBO( FLASHLIGHT, hasFlashlight ); +#endif + SET_STATIC_VERTEX_SHADER( lightmappedgeneric_vs20 ); + + if ( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_STATIC_PIXEL_SHADER( worldtwotextureblend_ps20b ); + SET_STATIC_PIXEL_SHADER_COMBO( DETAILTEXTURE, hasDetailTexture ); + SET_STATIC_PIXEL_SHADER_COMBO( BUMPMAP, hasBump ); + SET_STATIC_PIXEL_SHADER_COMBO( DIFFUSEBUMPMAP, hasDiffuseBumpmap ); + SET_STATIC_PIXEL_SHADER_COMBO( VERTEXCOLOR, hasVertexColor ); + SET_STATIC_PIXEL_SHADER_COMBO( SELFILLUM, hasSelfIllum ); + SET_STATIC_PIXEL_SHADER_COMBO( DETAIL_ALPHA_MASK_BASE_TEXTURE, bHasDetailAlpha ); + SET_STATIC_PIXEL_SHADER_COMBO( FLASHLIGHT, hasFlashlight ); + SET_STATIC_PIXEL_SHADER_COMBO( SEAMLESS, bSeamlessMapping ); + SET_STATIC_PIXEL_SHADER_COMBO( FLASHLIGHTDEPTHFILTERMODE, nShadowFilterMode ); + SET_STATIC_PIXEL_SHADER( worldtwotextureblend_ps20b ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( worldtwotextureblend_ps20 ); + SET_STATIC_PIXEL_SHADER_COMBO( DETAILTEXTURE, hasDetailTexture ); + SET_STATIC_PIXEL_SHADER_COMBO( BUMPMAP, hasBump ); + SET_STATIC_PIXEL_SHADER_COMBO( DIFFUSEBUMPMAP, hasDiffuseBumpmap ); + SET_STATIC_PIXEL_SHADER_COMBO( VERTEXCOLOR, hasVertexColor ); + SET_STATIC_PIXEL_SHADER_COMBO( SELFILLUM, hasSelfIllum ); + SET_STATIC_PIXEL_SHADER_COMBO( DETAIL_ALPHA_MASK_BASE_TEXTURE, bHasDetailAlpha ); + SET_STATIC_PIXEL_SHADER_COMBO( FLASHLIGHT, hasFlashlight ); + SET_STATIC_PIXEL_SHADER_COMBO( SEAMLESS, bSeamlessMapping ); + SET_STATIC_PIXEL_SHADER( worldtwotextureblend_ps20 ); + } + + // HACK HACK HACK - enable alpha writes all the time so that we have them for + // underwater stuff. + // But only do it if we're not using the alpha already for translucency + pShaderShadow->EnableAlphaWrites( bFullyOpaque ); + + + if( hasFlashlight ) + { + FogToBlack(); + } + else + { + DefaultFog(); + } + } + DYNAMIC_STATE + { + if( hasBaseTexture ) + { + BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME ); + } + else + { + pShaderAPI->BindStandardTexture( SHADER_SAMPLER0, TEXTURE_WHITE ); + } + + // if( hasLightmap ) + { + pShaderAPI->BindStandardTexture( SHADER_SAMPLER1, TEXTURE_LIGHTMAP ); + } + + bool bFlashlightShadows = false; + if( hasFlashlight ) + { + VMatrix worldToTexture; + ITexture *pFlashlightDepthTexture; + FlashlightState_t state = pShaderAPI->GetFlashlightStateEx( worldToTexture, &pFlashlightDepthTexture ); + bFlashlightShadows = state.m_bEnableShadows && ( pFlashlightDepthTexture != NULL ); + + SetFlashLightColorFromState( state, pShaderAPI ); + + BindTexture( SHADER_SAMPLER2, state.m_pSpotlightTexture, state.m_nSpotlightTextureFrame ); + + if( pFlashlightDepthTexture && g_pConfig->ShadowDepthTexture() ) + { + BindTexture( SHADER_SAMPLER7, pFlashlightDepthTexture ); + } + } + if( hasDetailTexture ) + { + BindTexture( SHADER_SAMPLER3, DETAIL, DETAILFRAME ); + } + if( hasBump ) + { + if( !g_pConfig->m_bFastNoBump ) + { + BindTexture( SHADER_SAMPLER4, BUMPMAP, BUMPFRAME ); + } + else + { + pShaderAPI->BindStandardTexture( SHADER_SAMPLER4, TEXTURE_NORMALMAP_FLAT ); + } + } + pShaderAPI->BindStandardTexture( SHADER_SAMPLER6, TEXTURE_NORMALIZATION_CUBEMAP_SIGNED ); + + // If we don't have a texture transform, we don't have + // to set vertex shader constants or run vertex shader instructions + // for the texture transform. + bool bHasTextureTransform = + !( params[BASETEXTURETRANSFORM]->MatrixIsIdentity() && + params[BUMPTRANSFORM]->MatrixIsIdentity() ); + + bool bVertexShaderFastPath = !bHasTextureTransform; + if( params[DETAIL]->IsTexture() ) + { + bVertexShaderFastPath = false; + } + if( pShaderAPI->GetIntRenderingParameter(INT_RENDERPARM_ENABLE_FIXED_LIGHTING)!=0 ) + { + bVertexShaderFastPath = false; + } + + float color[4] = { 1.0, 1.0, 1.0, 1.0 }; + ComputeModulationColor( color ); + if( !( bVertexShaderFastPath && color[0] == 1.0f && color[1] == 1.0f && color[2] == 1.0f && color[3] == 1.0f ) ) + { + bVertexShaderFastPath = false; + s_pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_MODULATION_COLOR, color ); + if (! bSeamlessMapping) + SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, BASETEXTURETRANSFORM ); + if( hasBump && !bHasDetailAlpha ) + { + SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_2, BUMPTRANSFORM ); + Assert( !hasDetailTexture ); + } + } + + MaterialFogMode_t fogType = pShaderAPI->GetSceneFogMode(); + DECLARE_DYNAMIC_VERTEX_SHADER( lightmappedgeneric_vs20 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( DOWATERFOG, fogType == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( FASTPATH, bVertexShaderFastPath ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( + LIGHTING_PREVIEW, pShaderAPI->GetIntRenderingParameter(INT_RENDERPARM_ENABLE_FIXED_LIGHTING)!=0); + SET_DYNAMIC_VERTEX_SHADER( lightmappedgeneric_vs20 ); + + bool bWriteDepthToAlpha; + bool bWriteWaterFogToAlpha; + if( bFullyOpaque ) + { + bWriteDepthToAlpha = pShaderAPI->ShouldWriteDepthToDestAlpha(); + bWriteWaterFogToAlpha = (fogType == MATERIAL_FOG_LINEAR_BELOW_FOG_Z); + AssertMsg( !(bWriteDepthToAlpha && bWriteWaterFogToAlpha), "Can't write two values to alpha at the same time." ); + } + else + { + //can't write a special value to dest alpha if we're actually using as-intended alpha + bWriteDepthToAlpha = false; + bWriteWaterFogToAlpha = false; + } + + + if ( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_DYNAMIC_PIXEL_SHADER( worldtwotextureblend_ps20b ); + + // Don't write fog to alpha if we're using translucency + SET_DYNAMIC_PIXEL_SHADER_COMBO( WRITEWATERFOGTODESTALPHA, bWriteWaterFogToAlpha ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( WRITE_DEPTH_TO_DESTALPHA, bWriteDepthToAlpha ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( FLASHLIGHTSHADOWS, bFlashlightShadows ); + SET_DYNAMIC_PIXEL_SHADER( worldtwotextureblend_ps20b ); + } + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( worldtwotextureblend_ps20 ); + + // Don't write fog to alpha if we're using translucency + SET_DYNAMIC_PIXEL_SHADER_COMBO( WRITEWATERFOGTODESTALPHA, (fogType == MATERIAL_FOG_LINEAR_BELOW_FOG_Z) && + (nBlendType != BT_BLENDADD) && (nBlendType != BT_BLEND) && !bIsAlphaTested ); + SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() ); + SET_DYNAMIC_PIXEL_SHADER( worldtwotextureblend_ps20 ); + } + + + // always set the transform for detail textures since I'm assuming that you'll + // always have a detailscale. + if( hasDetailTexture ) + { + SetVertexShaderTextureScaledTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_2, BASETEXTURETRANSFORM, DETAILSCALE ); + Assert( !( hasBump && !bHasDetailAlpha ) ); + } + + SetPixelShaderConstantGammaToLinear( 7, SELFILLUMTINT ); + + float eyePos[4]; + pShaderAPI->GetWorldSpaceCameraPosition( eyePos ); + pShaderAPI->SetPixelShaderConstant( 10, eyePos, 1 ); + pShaderAPI->SetPixelShaderFogParams( 11 ); + + if ( bSeamlessMapping ) + { + float map_scale[4]={ params[SEAMLESS_SCALE]->GetFloatValue(),0,0,0}; + pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, map_scale ); + } + + + if( hasFlashlight ) + { + VMatrix worldToTexture; + const FlashlightState_t &flashlightState = pShaderAPI->GetFlashlightState( worldToTexture ); + + // Set the flashlight attenuation factors + float atten[4]; + atten[0] = flashlightState.m_fConstantAtten; + atten[1] = flashlightState.m_fLinearAtten; + atten[2] = flashlightState.m_fQuadraticAtten; + atten[3] = flashlightState.m_FarZ; + pShaderAPI->SetPixelShaderConstant( 20, atten, 1 ); + + // Set the flashlight origin + float pos[4]; + pos[0] = flashlightState.m_vecLightOrigin[0]; + pos[1] = flashlightState.m_vecLightOrigin[1]; + pos[2] = flashlightState.m_vecLightOrigin[2]; + pos[3] = 1.0f; + pShaderAPI->SetPixelShaderConstant( 15, pos, 1 ); + + pShaderAPI->SetPixelShaderConstant( 16, worldToTexture.Base(), 4 ); + } + } + Draw(); + } + + SHADER_DRAW + { + bool bHasFlashlight = UsingFlashlight( params ); + if ( bHasFlashlight && ( IsX360() || r_flashlight_version2.GetInt() ) ) + { + DrawPass( params, pShaderAPI, pShaderShadow, false, vertexCompression ); + SHADOW_STATE + { + SetInitialShadowState( ); + } + } + DrawPass( params, pShaderAPI, pShaderShadow, bHasFlashlight, vertexCompression ); + } + +END_SHADER + diff --git a/materialsystem/stdshaders/worldtwotextureblend_dx6.cpp b/materialsystem/stdshaders/worldtwotextureblend_dx6.cpp new file mode 100644 index 0000000..3ae6383 --- /dev/null +++ b/materialsystem/stdshaders/worldtwotextureblend_dx6.cpp @@ -0,0 +1,258 @@ +//========= 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" + + +DEFINE_FALLBACK_SHADER( WorldTwoTextureBlend, WorldTwoTextureBlend_DX6 ) + + +BEGIN_SHADER( WorldTwoTextureBlend_DX6, + "Help for WorldTwoTextureBlend" ) + + BEGIN_SHADER_PARAMS + SHADER_PARAM_OVERRIDE( BASETEXTURE, SHADER_PARAM_TYPE_TEXTURE, "shadertest/WorldTwoTextureBlend", "iris texture", 0 ) + SHADER_PARAM( DETAIL, SHADER_PARAM_TYPE_TEXTURE, "shadertest/WorldTwoTextureBlend_detail", "detail texture" ) + SHADER_PARAM( DETAILSCALE, SHADER_PARAM_TYPE_FLOAT, "1.0", "scale of the detail texture" ) + SHADER_PARAM( DETAIL_ALPHA_MASK_BASE_TEXTURE, SHADER_PARAM_TYPE_BOOL, "0", + "If this is 1, then when detail alpha=0, no base texture is blended and when " + "detail alpha=1, you get detail*base*lightmap" ) + END_SHADER_PARAMS + + SHADER_INIT + { + LoadTexture( FLASHLIGHTTEXTURE ); + LoadTexture( BASETEXTURE ); + LoadTexture( DETAIL ); + } + + SHADER_INIT_PARAMS() + { + // FLASHLIGHTFIXME + params[FLASHLIGHTTEXTURE]->SetStringValue( "effects/flashlight001" ); + + if( !params[DETAIL_ALPHA_MASK_BASE_TEXTURE]->IsDefined() ) + params[DETAIL_ALPHA_MASK_BASE_TEXTURE]->SetIntValue( 0 ); + + SET_FLAGS2( MATERIAL_VAR2_LIGHTING_LIGHTMAP ); + } + + SHADER_DRAW + { + float detailScale = params[DETAILSCALE]->GetFloatValue(); + + bool hasFlashlight = UsingFlashlight( params ); + + if( hasFlashlight ) + { + DrawFlashlight_dx70( params, pShaderAPI, pShaderShadow, FLASHLIGHTTEXTURE, FLASHLIGHTTEXTUREFRAME ); + return; + } + + // DX6 fallback mode. + if ( params[DETAIL_ALPHA_MASK_BASE_TEXTURE]->GetIntValue() ) + { + DetailAlphaMaskPass1( pShaderShadow, pShaderAPI, params, detailScale ); + DetailAlphaMaskPass2( pShaderShadow, pShaderAPI, detailScale ); + } + else + { + // FIXME: add multitexture support! + NormalModePass1( pShaderShadow, pShaderAPI ); + NormalModePass2( pShaderShadow, pShaderAPI, params, detailScale ); + NormalModePass3( pShaderShadow, pShaderAPI, params, detailScale ); + } + } + + + // ------------------------------------------------------------------------------ // + // "Normal" mode - doesn't use the detail texture's alpha mask. + // ------------------------------------------------------------------------------ // + + void NormalModePass1( + IShaderShadow *pShaderShadow, + IShaderDynamicAPI *pShaderAPI ) + { + SHADOW_STATE + { + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->DrawFlags( SHADER_DRAW_POSITION | SHADER_DRAW_TEXCOORD0 ); + FogToFogColor(); + } + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME ); + } + Draw(); + } + + void NormalModePass2( + IShaderShadow *pShaderShadow, + IShaderDynamicAPI *pShaderAPI, + IMaterialVar **params, + float detailScale ) + { + SHADOW_STATE + { + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableBlending( true ); + pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA ); + pShaderShadow->DrawFlags( SHADER_DRAW_POSITION | SHADER_DRAW_TEXCOORD0 ); + FogToFogColor(); + } + + DYNAMIC_STATE + { + if ( detailScale != 1.0f ) + { + pShaderAPI->MatrixMode( MATERIAL_TEXTURE0 ); + pShaderAPI->LoadIdentity(); + pShaderAPI->ScaleXY( detailScale, detailScale ); + } + BindTexture( SHADER_SAMPLER0, DETAIL ); + } + Draw(); + } + + void NormalModePass3( + IShaderShadow *pShaderShadow, + IShaderDynamicAPI *pShaderAPI, + IMaterialVar **params, + float detailScale ) + { + SHADOW_STATE + { + SET_FLAGS2( MATERIAL_VAR2_LIGHTING_LIGHTMAP ); + SingleTextureLightmapBlendMode(); + pShaderShadow->DrawFlags( SHADER_DRAW_POSITION | SHADER_DRAW_LIGHTMAP_TEXCOORD0 ); + FogToOOOverbright(); + } + DYNAMIC_STATE + { + if ( detailScale != 1.0f ) + pShaderAPI->LoadIdentity( ); + + pShaderAPI->BindStandardTexture( SHADER_SAMPLER0, TEXTURE_LIGHTMAP ); + } + Draw(); + } + + + // ------------------------------------------------------------------------------ // + // "Detail alpha mask mode". + // ------------------------------------------------------------------------------ // + + void DetailAlphaMaskPass1( + IShaderShadow *pShaderShadow, + IShaderDynamicAPI *pShaderAPI, + IMaterialVar **params, + float detailScale ) + { + // The equation is [B*Da + (1-Da)] * [D * L] + SHADOW_STATE + { + SET_FLAGS2( MATERIAL_VAR2_LIGHTING_LIGHTMAP ); + + pShaderShadow->EnableCustomPixelPipe( true ); + pShaderShadow->CustomTextureStages( 2 ); + + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + + // Stage 0 + // Color = B*2 + // Note the 2x here.. we do 4x total in this shader and + // the first 2x is here. The second is in SingleTextureLightmapBlendMode in the 2nd pass. + pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE0, + SHADER_TEXCHANNEL_COLOR, SHADER_TEXOP_MODULATE2X, + SHADER_TEXARG_TEXTURE, SHADER_TEXARG_CONSTANTCOLOR ); + + // Stage 1 [where P = prev stage] + // Color = B*Da + (1-Da) + pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE1, + SHADER_TEXCHANNEL_COLOR, SHADER_TEXOP_MODULATEINVCOLOR_ADDALPHA, + SHADER_TEXARG_INVTEXTUREALPHA, SHADER_TEXARG_PREVIOUSSTAGE ); + + pShaderShadow->DrawFlags( SHADER_DRAW_POSITION | SHADER_DRAW_TEXCOORD0 | SHADER_DRAW_TEXCOORD1 ); + FogToFogColor(); + } + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME ); + BindTexture( SHADER_SAMPLER1, DETAIL ); + + pShaderAPI->Color4f( 1, 1, 1, 1 ); + + if ( detailScale != 1.0f ) + { + pShaderAPI->MatrixMode( MATERIAL_TEXTURE1 ); + pShaderAPI->LoadIdentity(); + pShaderAPI->ScaleXY( detailScale, detailScale ); + } + + } + Draw(); + } + + void DetailAlphaMaskPass2( IShaderShadow *pShaderShadow, IShaderDynamicAPI *pShaderAPI, float detailScale ) + { + SHADOW_STATE + { + s_pShaderShadow->EnableCustomPixelPipe( true ); + s_pShaderShadow->CustomTextureStages( 2 ); + + s_pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + s_pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + + s_pShaderShadow->EnableTexGen( SHADER_TEXTURE_STAGE0, true); + + // Make sure the texgen transform is applied to the texture coordinates and not to an auto-generated reflection vector or whatever. + s_pShaderShadow->TexGen( SHADER_TEXTURE_STAGE0, SHADER_TEXGENPARAM_OBJECT_LINEAR ); + + // This turns on blending and does overbrighting if it's enabled. + SingleTextureLightmapBlendMode(); + + // Stage 0, color = D + pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE0, + SHADER_TEXCHANNEL_COLOR, SHADER_TEXOP_SELECTARG1, + SHADER_TEXARG_TEXTURE, SHADER_TEXARG_CONSTANTCOLOR ); + + // Stage 1, color = D*L + pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE1, + SHADER_TEXCHANNEL_COLOR, SHADER_TEXOP_MODULATE, + SHADER_TEXARG_PREVIOUSSTAGE, SHADER_TEXARG_TEXTURE ); + + // Use the lightmap coordinates in both stages. + pShaderShadow->DrawFlags( SHADER_DRAW_POSITION | SHADER_DRAW_TEXCOORD0 | SHADER_DRAW_LIGHTMAP_TEXCOORD1 ); + FogToFogColor(); + } + + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER0, DETAIL); + pShaderAPI->BindStandardTexture( SHADER_SAMPLER1, TEXTURE_LIGHTMAP ); + + if ( detailScale != 1.0f ) + { + pShaderAPI->MatrixMode( MATERIAL_TEXTURE1 ); + pShaderAPI->LoadIdentity(); + + pShaderAPI->MatrixMode( MATERIAL_TEXTURE0 ); + pShaderAPI->LoadIdentity(); + pShaderAPI->ScaleXY( detailScale, detailScale ); + } + } + + Draw(); + } + +END_SHADER + diff --git a/materialsystem/stdshaders/worldtwotextureblend_dx8.cpp b/materialsystem/stdshaders/worldtwotextureblend_dx8.cpp new file mode 100644 index 0000000..a58d9df --- /dev/null +++ b/materialsystem/stdshaders/worldtwotextureblend_dx8.cpp @@ -0,0 +1,175 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $Header: $ +// $NoKeywords: $ +//=============================================================================// + +#include "BaseVSShader.h" + +#include "lightmappedgeneric_vs11.inc" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + + +DEFINE_FALLBACK_SHADER( WorldTwoTextureBlend, WorldTwoTextureBlend_DX8 ) + +BEGIN_VS_SHADER( WorldTwoTextureBlend_DX8, + "Help for WorldTwoTextureBlend_DX8" ) + + BEGIN_SHADER_PARAMS + SHADER_PARAM_OVERRIDE( BASETEXTURE, SHADER_PARAM_TYPE_TEXTURE, "shadertest/WorldTwoTextureBlend", "iris texture", 0 ) + SHADER_PARAM( SELFILLUMTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "Self-illumination tint" ) + SHADER_PARAM( DETAIL, SHADER_PARAM_TYPE_TEXTURE, "shadertest/WorldTwoTextureBlend_detail", "detail texture" ) + SHADER_PARAM( DETAILSCALE, SHADER_PARAM_TYPE_FLOAT, "1.0", "scale of the detail texture" ) + SHADER_PARAM( DETAIL_ALPHA_MASK_BASE_TEXTURE, SHADER_PARAM_TYPE_BOOL, "0", + "If this is 1, then when detail alpha=0, no base texture is blended and when " + "detail alpha=1, you get detail*base*lightmap" ) + END_SHADER_PARAMS + + SHADER_FALLBACK + { + if ( IsPC() && g_pHardwareConfig->GetDXSupportLevel() < 80 ) + return "WorldTwoTextureBlend_DX6"; + + return 0; + } + SHADER_INIT + { + LoadTexture( FLASHLIGHTTEXTURE ); + if (params[BASETEXTURE]->IsDefined()) + { + LoadTexture( BASETEXTURE ); + } + + if (params[DETAIL]->IsDefined()) + { + LoadTexture( DETAIL ); + } + } + + SHADER_INIT_PARAMS() + { + // FLASHLIGHTFIXME + params[FLASHLIGHTTEXTURE]->SetStringValue( "effects/flashlight001" ); + + if( !params[SELFILLUMTINT]->IsDefined() ) + { + params[SELFILLUMTINT]->SetVecValue( 1.0f, 1.0f, 1.0f ); + } + + if( !params[DETAIL_ALPHA_MASK_BASE_TEXTURE]->IsDefined() ) + { + params[DETAIL_ALPHA_MASK_BASE_TEXTURE]->SetIntValue( 0 ); + } + + SET_FLAGS2( MATERIAL_VAR2_LIGHTING_LIGHTMAP ); + } + + const char *GetPixelShaderName( IMaterialVar** params, bool bHasBaseTexture, bool bHasDetailTexture ) + { + bool bSelfIllum = IS_FLAG_SET(MATERIAL_VAR_SELFILLUM); + if ( !bHasBaseTexture ) + { + if ( !bHasDetailTexture ) + return "LightmappedGeneric_NoTexture"; + + return "LightmappedGeneric_DetailNoTexture"; + } + + if ( !bHasDetailTexture ) + { + if ( bSelfIllum ) + return "LightmappedGeneric_SelfIlluminated"; + + return "LightmappedGeneric"; + } + + if ( !params[DETAIL_ALPHA_MASK_BASE_TEXTURE]->GetIntValue() ) + { + if ( bSelfIllum ) + return "WorldTwoTextureBlend_SelfIlluminated"; + + return "WorldTwoTextureBlend"; + } + + return "WorldTwoTextureBlend_DetailAlpha"; + } + + + SHADER_DRAW + { + bool hasFlashlight = UsingFlashlight( params ); + if( hasFlashlight ) + { + DrawFlashlight_dx80( params, pShaderAPI, pShaderShadow, false, -1, -1, -1, + FLASHLIGHTTEXTURE, FLASHLIGHTTEXTUREFRAME, true, false, 0, -1, -1 ); + return; + } + + bool bHasBaseTexture = params[BASETEXTURE]->IsTexture(); + bool bHasDetailTexture = params[DETAIL]->IsTexture(); + bool bHasVertexColor = IS_FLAG_SET( MATERIAL_VAR_VERTEXCOLOR ); + + SHADOW_STATE + { + if ( bHasBaseTexture ) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + } + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + if ( bHasDetailTexture ) + { + pShaderShadow->EnableTexture( SHADER_SAMPLER2, true ); + } + pShaderShadow->EnableBlending( false ); + + pShaderShadow->VertexShaderVertexFormat( VERTEX_POSITION, 2, 0, 0 ); + + // Let the shaders do the fun stuff. + lightmappedgeneric_vs11_Static_Index vshIndex; + vshIndex.SetDETAIL( bHasDetailTexture ); + vshIndex.SetENVMAP( false ); + vshIndex.SetENVMAPCAMERASPACE( false ); + vshIndex.SetENVMAPSPHERE( false ); + vshIndex.SetVERTEXCOLOR( bHasVertexColor ); + pShaderShadow->SetVertexShader( "LightmappedGeneric_vs11", vshIndex.GetIndex() ); + + const char *pPixelShaderName = GetPixelShaderName( params, bHasBaseTexture, bHasDetailTexture ); + pShaderShadow->SetPixelShader( pPixelShaderName ); + + FogToFogColor(); + } + DYNAMIC_STATE + { + if ( bHasBaseTexture ) + { + BindTexture( SHADER_SAMPLER0, BASETEXTURE, FRAME ); + SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, BASETEXTURETRANSFORM ); + } + + pShaderAPI->BindStandardTexture( SHADER_SAMPLER1, TEXTURE_LIGHTMAP ); + + if ( bHasDetailTexture ) + { + BindTexture( SHADER_SAMPLER2, DETAIL ); + SetVertexShaderTextureScaledTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_4, BASETEXTURETRANSFORM, DETAILSCALE ); + } + + SetModulationVertexShaderDynamicState(); + + // Dynamic vertex shader index. + lightmappedgeneric_vs11_Dynamic_Index vshIndex; + vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() ); + + EnablePixelShaderOverbright( 0, true, true ); + SetPixelShaderConstant( 1, SELFILLUMTINT ); + } + Draw(); + } + +END_SHADER + diff --git a/materialsystem/stdshaders/worldtwotextureblend_ps2x.fxc b/materialsystem/stdshaders/worldtwotextureblend_ps2x.fxc new file mode 100644 index 0000000..b81fa7b --- /dev/null +++ b/materialsystem/stdshaders/worldtwotextureblend_ps2x.fxc @@ -0,0 +1,217 @@ +//====== Copyright © 1996-2007, Valve Corporation, All rights reserved. =======// +// +// Purpose: +// +// $NoKeywords: $ +// +//=============================================================================// +// STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC] +// STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX] +// STATIC: "DETAILTEXTURE" "0..1" +// STATIC: "BUMPMAP" "0..1" +// STATIC: "VERTEXCOLOR" "0..1" +// STATIC: "SELFILLUM" "0..1" +// STATIC: "DIFFUSEBUMPMAP" "0..1" +// STATIC: "DETAIL_ALPHA_MASK_BASE_TEXTURE" "0..1" +// STATIC: "FLASHLIGHT" "0..1" +// STATIC: "SEAMLESS" "0..1" +// STATIC: "FLASHLIGHTDEPTHFILTERMODE" "0..2" [ps20b] [PC] +// STATIC: "FLASHLIGHTDEPTHFILTERMODE" "0..0" [ps20b] [XBOX] + +// DYNAMIC: "WRITEWATERFOGTODESTALPHA" "0..1" +// DYNAMIC: "PIXELFOGTYPE" "0..1" +// DYNAMIC: "WRITE_DEPTH_TO_DESTALPHA" "0..1" [ps20b] [PC] +// DYNAMIC: "WRITE_DEPTH_TO_DESTALPHA" "0..0" [ps20b] [XBOX] +// DYNAMIC: "FLASHLIGHTSHADOWS" "0..1" [ps20b] + +// SKIP: $DETAILTEXTURE && ( $BUMPMAP && !$DETAIL_ALPHA_MASK_BASE_TEXTURE ) +// SKIP: !$BUMPMAP && $DIFFUSEBUMPMAP +// SKIP: $VERTEXCOLOR && $BUMPMAP +// SKIP: FLASHLIGHT && $SELFILLUM +// SKIP: FLASHLIGHT && $DETAIL_ALPHA_MASK_BASE_TEXTURE +// SKIP: FLASHLIGHT && ($BUMPMAP || $DIFFUSEBUMPMAP) + +// We don't care about flashlight depth unless the flashlight is on +// SKIP: ( $FLASHLIGHT == 0 ) && ( $FLASHLIGHTSHADOWS == 1 ) [ps20b] + +#if defined( SHADER_MODEL_PS_2_0 ) +# define WRITE_DEPTH_TO_DESTALPHA 0 +#endif + + +#define HDRTYPE HDR_TYPE_NONE +#include "common_flashlight_fxc.h" +#include "common_ps_fxc.h" + +const HALF4 g_SelfIllumTint : register( c7 ); +static const HALF g_OverbrightFactor = 2.0f; + +const HALF3 g_EyePos : register( c10 ); +const HALF4 g_FogParams : register( c11 ); + +const HALF3 g_FlashlightPos : register( c15 ); +// flashlightfixme: Move this math into the vertex shader. +const float4x4 g_FlashlightWorldToTexture : register( c16 ); + +const float4 g_FlashlightAttenuationFactors : register( c20 ); + +sampler BaseTextureSampler : register( s0 ); +sampler LightmapSampler : register( s1 ); +sampler FlashlightSampler : register( s2 ); +sampler DetailSampler : register( s3 ); +sampler BumpmapSampler : register( s4 ); +sampler NormalizeSampler : register( s6 ); + +struct PS_INPUT +{ + HALF2 baseTexCoord : TEXCOORD0; + HALF4 detailOrBumpTexCoord : TEXCOORD1; + HALF4 lightmapTexCoord1And2 : TEXCOORD2; // CENTROID: TEXCOORD2 + HALF2 lightmapTexCoord3 : TEXCOORD3; // CENTROID: TEXCOORD3 + HALF4 worldPos_projPosZ : TEXCOORD4; + HALF3x3 tangentSpaceTranspose : TEXCOORD5; + // tangentSpaceTranspose : TEXCOORD6; + // tangentSpaceTranspose : TEXCOORD7; + HALF4 vertexColor : COLOR; +}; + + +float4 main( PS_INPUT i ) : COLOR +{ + bool bDetailTexture = DETAILTEXTURE ? true : false; + bool bBumpmap = BUMPMAP ? true : false; + bool bDiffuseBumpmap = DIFFUSEBUMPMAP ? true : false; + bool bVertexColor = VERTEXCOLOR ? true : false; + bool bSelfIllum = SELFILLUM ? true : false; + bool bDetailAlphaMaskBaseTexture = DETAIL_ALPHA_MASK_BASE_TEXTURE ? true : false; + bool bFlashlight = FLASHLIGHT ? true : false; + + HALF3 lightmapColor1 = HALF3( 1.0f, 1.0f, 1.0f ); + HALF3 lightmapColor2 = HALF3( 1.0f, 1.0f, 1.0f ); + HALF3 lightmapColor3 = HALF3( 1.0f, 1.0f, 1.0f ); + if( bBumpmap && bDiffuseBumpmap ) + { + HALF2 bumpCoord1; + HALF2 bumpCoord2; + HALF2 bumpCoord3; + ComputeBumpedLightmapCoordinates( i.lightmapTexCoord1And2, i.lightmapTexCoord3.xy, + bumpCoord1, bumpCoord2, bumpCoord3 ); + + HALF4 lightmapSample1 = tex2D( LightmapSampler, bumpCoord1 ); + lightmapColor1 = lightmapSample1.rgb; + lightmapColor2 = tex2D( LightmapSampler, bumpCoord2 ); + lightmapColor3 = tex2D( LightmapSampler, bumpCoord3 ); + } + else + { + if( !bFlashlight ) + { + HALF2 bumpCoord1 = ComputeLightmapCoordinates( i.lightmapTexCoord1And2, i.lightmapTexCoord3.xy ); + HALF4 lightmapSample1 = tex2D( LightmapSampler, bumpCoord1 ); + lightmapColor1 = lightmapSample1.rgb; + } + } + + HALF4 detailColor = HALF4( 1.0f, 1.0f, 1.0f, 1.0f ); + if( bDetailTexture ) + { + detailColor = tex2D( DetailSampler, i.detailOrBumpTexCoord.xy ); + } + + HALF4 baseColor = HALF4( 1.0f, 1.0f, 1.0f, 1.0f ); + baseColor = tex2D( BaseTextureSampler, i.baseTexCoord ); + if ( bDetailAlphaMaskBaseTexture ) + { + // This is what WorldTwoTextureBlend_DX6 does. + baseColor.rgb = saturate( saturate( baseColor * 2 ) * detailColor.a + (1 - detailColor.a) ); + baseColor.rgb *= detailColor; + } + else + { + baseColor.rgb = lerp( baseColor, detailColor, detailColor.a ); + } + + HALF3 normal = HALF3( 0.0f, 0.0f, 1.0f ); + if( bBumpmap ) + { + HALF3 normalTexel; + normalTexel = tex2D( BumpmapSampler, i.detailOrBumpTexCoord.xy ); + normal = 2.0 * normalTexel - 1.0; + } + + HALF3 albedo = HALF3( 1.0f, 1.0f, 1.0f ); + HALF alpha = 1.0f; + albedo *= baseColor; + if( !bSelfIllum ) + { + alpha *= baseColor.a; + } + + // The vertex color contains the modulation color + vertex color combined + albedo *= i.vertexColor; + alpha *= i.vertexColor.a; // not sure about this one + + HALF3 diffuseLighting; + if( bFlashlight ) + { + float3 worldSpaceNormal; + // Make the unbumped version not so fucking stupid and not need tangentSpaceTranspose you knob. + worldSpaceNormal = mul( normal, i.tangentSpaceTranspose ); + + int nShadowSampleLevel = 0; + bool bDoShadows = false; +// On ps_2_b, we can do shadow mapping +#if ( FLASHLIGHTSHADOWS && (defined(SHADER_MODEL_PS_2_B) || defined(SHADER_MODEL_PS_3_0) ) ) + nShadowSampleLevel = FLASHLIGHTDEPTHFILTERMODE; + bDoShadows = true; +#endif + float4 flashlightSpacePosition = mul( float4( i.worldPos_projPosZ.xyz, 1.0f ), g_FlashlightWorldToTexture ); + + diffuseLighting = DoFlashlight( g_FlashlightPos, i.worldPos_projPosZ.xyz, flashlightSpacePosition, + worldSpaceNormal, g_FlashlightAttenuationFactors.xyz, + g_FlashlightAttenuationFactors.w, FlashlightSampler, FlashlightSampler, NormalizeSampler, + nShadowSampleLevel, bDoShadows, false, float2(0, 0), false ); + } + else + { + if( bBumpmap && bDiffuseBumpmap ) + { + float dot1 = saturate( dot( normal, bumpBasis[0] ) ); + float dot2 = saturate( dot( normal, bumpBasis[1] ) ); + float dot3 = saturate( dot( normal, bumpBasis[2] ) ); + + float sum = dot1 + dot2 + dot3; + diffuseLighting = dot1 * lightmapColor1 + + dot2 * lightmapColor2 + + dot3 * lightmapColor3; + diffuseLighting *= 1.0f / sum; + } + else + { + diffuseLighting = lightmapColor1; + } + + // Only scale here since the flashlight will already be scaled properly + diffuseLighting *= g_OverbrightFactor; + } + + HALF3 diffuseComponent = albedo * diffuseLighting; + + if( bSelfIllum ) + { + HALF3 selfIllumComponent = g_SelfIllumTint * albedo; + diffuseComponent = lerp( diffuseComponent, selfIllumComponent, baseColor.a ); + } + + HALF3 specularLighting = HALF3( 0.0f, 0.0f, 0.0f ); + HALF3 result = diffuseComponent + specularLighting; + + float fogFactor = CalcPixelFogFactor( PIXELFOGTYPE, g_FogParams, g_EyePos.z, i.worldPos_projPosZ.z, i.worldPos_projPosZ.w ); + +#if WRITEWATERFOGTODESTALPHA && (PIXELFOGTYPE == PIXEL_FOG_TYPE_HEIGHT) + alpha = fogFactor; +#endif + + return FinalOutput( float4( result, alpha ), fogFactor, PIXELFOGTYPE, TONEMAP_SCALE_LINEAR, (WRITE_DEPTH_TO_DESTALPHA != 0), i.worldPos_projPosZ.w ); +} + diff --git a/materialsystem/stdshaders/worldvertexalpha.cpp b/materialsystem/stdshaders/worldvertexalpha.cpp new file mode 100644 index 0000000..85bad1c --- /dev/null +++ b/materialsystem/stdshaders/worldvertexalpha.cpp @@ -0,0 +1,259 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $Header: $ +// $NoKeywords: $ +//=============================================================================// + +#include "BaseVSShader.h" + +#include "WorldVertexAlpha.inc" +#include "worldvertexalpha_ps20.inc" +#include "worldvertexalpha_ps20b.inc" + +BEGIN_VS_SHADER( WorldVertexAlpha, + "Help for WorldVertexAlpha" ) + + BEGIN_SHADER_PARAMS + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + SET_FLAGS2( MATERIAL_VAR2_LIGHTING_LIGHTMAP ); + SET_FLAGS2( MATERIAL_VAR2_BLEND_WITH_LIGHTMAP_ALPHA ); + } + SHADER_INIT + { + // Load the base texture here! + LoadTexture( BASETEXTURE ); + } + + SHADER_FALLBACK + { +// if( g_pHardwareConfig->GetDXSupportLevel() < 90 || g_pHardwareConfig->GetHDRType() == HDR_TYPE_NONE ) + { + return "WorldVertexAlpha_DX8"; + } + return 0; + } + + SHADER_DRAW + { + if( g_pHardwareConfig->SupportsVertexAndPixelShaders() && !UsingEditor( params ) ) + { + if( g_pHardwareConfig->GetDXSupportLevel() < 90 ) + { + // NOTE: This is the DX8, Non-Hammer version. + + SHADOW_STATE + { + // Base time lightmap (Need two texture stages) + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + + int fmt = VERTEX_POSITION; + pShaderShadow->VertexShaderVertexFormat( fmt, 2, 0, 0 ); + + pShaderShadow->EnableBlending( true ); + + // Looks backwards, but this is done so that lightmap alpha = 1 when only + // using 1 texture (needed for translucent displacements). + pShaderShadow->BlendFunc( SHADER_BLEND_ONE_MINUS_SRC_ALPHA, SHADER_BLEND_SRC_ALPHA ); + + worldvertexalpha_Static_Index vshIndex; + pShaderShadow->SetVertexShader( "WorldVertexAlpha", vshIndex.GetIndex() ); + + pShaderShadow->SetPixelShader( "WorldVertexAlpha" ); + FogToFogColor(); + } + + DYNAMIC_STATE + { + // Bind the base texture (Stage0) and lightmap (Stage1) + BindTexture( SHADER_SAMPLER0, BASETEXTURE ); + pShaderAPI->BindStandardTexture( SHADER_SAMPLER1, TEXTURE_LIGHTMAP ); + + EnablePixelShaderOverbright( 0, true, true ); + + worldvertexalpha_Dynamic_Index vshIndex; + vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() ); + } + + Draw(); + } + else + { + // DX 9 version with HDR support + + // Pass 1 + SHADOW_STATE + { + SetInitialShadowState(); + + pShaderShadow->EnableAlphaWrites( true ); + + // Base time lightmap (Need two texture stages) + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER2, true ); + + int fmt = VERTEX_POSITION; + pShaderShadow->VertexShaderVertexFormat( fmt, 2, 0, 0 ); + + pShaderShadow->EnableBlending( true ); + + // Looks backwards, but this is done so that lightmap alpha = 1 when only + // using 1 texture (needed for translucent displacements). + pShaderShadow->BlendFunc( SHADER_BLEND_ONE_MINUS_SRC_ALPHA, SHADER_BLEND_SRC_ALPHA ); + pShaderShadow->EnableBlendingSeparateAlpha( true ); + pShaderShadow->BlendFuncSeparateAlpha( SHADER_BLEND_ZERO, SHADER_BLEND_SRC_ALPHA ); + + worldvertexalpha_Static_Index vshIndex; + pShaderShadow->SetVertexShader( "WorldVertexAlpha", vshIndex.GetIndex() ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_STATIC_PIXEL_SHADER( worldvertexalpha_ps20b ); + SET_STATIC_PIXEL_SHADER_COMBO( PASS, 0 ); + SET_STATIC_PIXEL_SHADER( worldvertexalpha_ps20b ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( worldvertexalpha_ps20 ); + SET_STATIC_PIXEL_SHADER_COMBO( PASS, 0 ); + SET_STATIC_PIXEL_SHADER( worldvertexalpha_ps20 ); + } + + + FogToFogColor(); + } + + DYNAMIC_STATE + { + // Bind the base texture (Stage0) and lightmap (Stage1) + BindTexture( SHADER_SAMPLER0, BASETEXTURE ); + pShaderAPI->BindStandardTexture( SHADER_SAMPLER1, TEXTURE_LIGHTMAP ); + + worldvertexalpha_Dynamic_Index vshIndex; + vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_DYNAMIC_PIXEL_SHADER( worldvertexalpha_ps20b ); + SET_DYNAMIC_PIXEL_SHADER( worldvertexalpha_ps20b ); + } + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( worldvertexalpha_ps20 ); + SET_DYNAMIC_PIXEL_SHADER( worldvertexalpha_ps20 ); + } + } + Draw(); + + // Pass 2 + SHADOW_STATE + { + SetInitialShadowState(); + + pShaderShadow->EnableAlphaWrites( true ); + pShaderShadow->EnableColorWrites( false ); + + // Base time lightmap (Need two texture stages) + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER2, true ); + + int fmt = VERTEX_POSITION; + pShaderShadow->VertexShaderVertexFormat( fmt, 2, 0, 0 ); + + pShaderShadow->EnableBlending( true ); + + // Looks backwards, but this is done so that lightmap alpha = 1 when only + // using 1 texture (needed for translucent displacements). + pShaderShadow->BlendFunc( SHADER_BLEND_ONE_MINUS_SRC_ALPHA, SHADER_BLEND_SRC_ALPHA ); + pShaderShadow->EnableBlendingSeparateAlpha( true ); + pShaderShadow->BlendFuncSeparateAlpha( SHADER_BLEND_ONE, SHADER_BLEND_ONE ); + + worldvertexalpha_Static_Index vshIndex; + pShaderShadow->SetVertexShader( "WorldVertexAlpha", vshIndex.GetIndex() ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_STATIC_PIXEL_SHADER( worldvertexalpha_ps20b ); + SET_STATIC_PIXEL_SHADER_COMBO( PASS, 1 ); + SET_STATIC_PIXEL_SHADER( worldvertexalpha_ps20b ); + } + else + { + DECLARE_STATIC_PIXEL_SHADER( worldvertexalpha_ps20 ); + SET_STATIC_PIXEL_SHADER_COMBO( PASS, 1 ); + SET_STATIC_PIXEL_SHADER( worldvertexalpha_ps20 ); + } + + FogToFogColor(); + } + + DYNAMIC_STATE + { + // Bind the base texture (Stage0) and lightmap (Stage1) + BindTexture( SHADER_SAMPLER0, BASETEXTURE ); + pShaderAPI->BindStandardTexture( SHADER_SAMPLER1, TEXTURE_LIGHTMAP ); + + worldvertexalpha_Dynamic_Index vshIndex; + vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() ); + + if( g_pHardwareConfig->SupportsPixelShaders_2_b() ) + { + DECLARE_DYNAMIC_PIXEL_SHADER( worldvertexalpha_ps20b ); + SET_DYNAMIC_PIXEL_SHADER( worldvertexalpha_ps20b ); + } + else + { + DECLARE_DYNAMIC_PIXEL_SHADER( worldvertexalpha_ps20 ); + SET_DYNAMIC_PIXEL_SHADER( worldvertexalpha_ps20 ); + } + } + Draw(); + } + } + else + { + // NOTE: This is the DX7, Hammer version. + SHADOW_STATE + { + SET_FLAGS2( MATERIAL_VAR2_LIGHTING_LIGHTMAP ); + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + pShaderShadow->OverbrightValue( SHADER_TEXTURE_STAGE1, OVERBRIGHT ); + + pShaderShadow->EnableBlending( true ); + + // Looks backwards, but this is done so that lightmap alpha = 1 when only + // using 1 texture (needed for translucent displacements). + pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA ); +// pShaderShadow->BlendFunc( SHADER_BLEND_ONE_MINUS_SRC_ALPHA, SHADER_BLEND_SRC_ALPHA ); + + // Use vertex color for Hammer because it puts the blending alpha in the vertices. + unsigned int colorFlag = 0; + if( UsingEditor( params ) ) + { + colorFlag |= SHADER_DRAW_COLOR; + } + + pShaderShadow->DrawFlags( colorFlag | SHADER_DRAW_POSITION | SHADER_DRAW_TEXCOORD1 | + SHADER_DRAW_LIGHTMAP_TEXCOORD0 ); + } + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER1, BASETEXTURE ); + pShaderAPI->BindStandardTexture( SHADER_SAMPLER0, TEXTURE_LIGHTMAP ); + } + + Draw(); + } + } +END_SHADER diff --git a/materialsystem/stdshaders/worldvertexalpha_dx8.cpp b/materialsystem/stdshaders/worldvertexalpha_dx8.cpp new file mode 100644 index 0000000..0ea139e --- /dev/null +++ b/materialsystem/stdshaders/worldvertexalpha_dx8.cpp @@ -0,0 +1,113 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $Header: $ +// $NoKeywords: $ +//=============================================================================// + +#include "BaseVSShader.h" + +#include "worldvertexalpha.inc" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +DEFINE_FALLBACK_SHADER( WorldVertexAlpha, WorldVertexAlpha_DX8 ) + +BEGIN_VS_SHADER( WorldVertexAlpha_DX8, + "Help for WorldVertexAlpha_DX8" ) + + BEGIN_SHADER_PARAMS + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + SET_FLAGS2( MATERIAL_VAR2_LIGHTING_LIGHTMAP ); + } + SHADER_INIT + { + // Load the base texture here! + LoadTexture( BASETEXTURE ); + } + + SHADER_DRAW + { + if( g_pHardwareConfig->SupportsVertexAndPixelShaders() && !UsingEditor( params ) ) + { + // NOTE: This is the DX8, Non-Hammer version. + + SHADOW_STATE + { + // Base time lightmap (Need two texture stages) + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + + int fmt = VERTEX_POSITION; + pShaderShadow->VertexShaderVertexFormat( fmt, 2, 0, 0 ); + + pShaderShadow->EnableBlending( true ); + + // Looks backwards, but this is done so that lightmap alpha = 1 when only + // using 1 texture (needed for translucent displacements). + pShaderShadow->BlendFunc( SHADER_BLEND_ONE_MINUS_SRC_ALPHA, SHADER_BLEND_SRC_ALPHA ); + + worldvertexalpha_Static_Index vshIndex; + pShaderShadow->SetVertexShader( "WorldVertexAlpha", vshIndex.GetIndex() ); + + pShaderShadow->SetPixelShader( "WorldVertexAlpha" ); + FogToFogColor(); + } + + DYNAMIC_STATE + { + // Bind the base texture (Stage0) and lightmap (Stage1) + BindTexture( SHADER_SAMPLER0, BASETEXTURE ); + pShaderAPI->BindStandardTexture( SHADER_SAMPLER1, TEXTURE_LIGHTMAP ); + EnablePixelShaderOverbright( 0, true, true ); + + worldvertexalpha_Dynamic_Index vshIndex; + vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() ); + } + + Draw(); + } + else + { + // NOTE: This is the DX7, Hammer version. + // FIXME: Gary - you need to write a proper non-fixed function shader for this. + SHADOW_STATE + { + SET_FLAGS2( MATERIAL_VAR2_LIGHTING_LIGHTMAP ); + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + pShaderShadow->OverbrightValue( SHADER_TEXTURE_STAGE1, OVERBRIGHT ); + + pShaderShadow->EnableBlending( true ); + + // Looks backwards, but this is done so that lightmap alpha = 1 when only + // using 1 texture (needed for translucent displacements). + pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA ); +// pShaderShadow->BlendFunc( SHADER_BLEND_ONE_MINUS_SRC_ALPHA, SHADER_BLEND_SRC_ALPHA ); + + // Use vertex color for Hammer because it puts the blending alpha in the vertices. + unsigned int colorFlag = 0; + if( UsingEditor( params ) ) + { + colorFlag |= SHADER_DRAW_COLOR; + } + + pShaderShadow->DrawFlags( colorFlag | SHADER_DRAW_POSITION | SHADER_DRAW_TEXCOORD1 | + SHADER_DRAW_LIGHTMAP_TEXCOORD0 ); + } + DYNAMIC_STATE + { + BindTexture( SHADER_SAMPLER1, BASETEXTURE ); + pShaderAPI->BindStandardTexture( SHADER_SAMPLER0, TEXTURE_LIGHTMAP ); + } + + Draw(); + } + } +END_SHADER diff --git a/materialsystem/stdshaders/worldvertextransition.cpp b/materialsystem/stdshaders/worldvertextransition.cpp new file mode 100644 index 0000000..e7d6a9a --- /dev/null +++ b/materialsystem/stdshaders/worldvertextransition.cpp @@ -0,0 +1,157 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $Header: $ +// $NoKeywords: $ +//=============================================================================// + +#include "BaseVSShader.h" +#include "convar.h" + +#include "worldvertextransition_dx8_helper.h" +#include "lightmappedgeneric_dx9_helper.h" + +static LightmappedGeneric_DX9_Vars_t s_info; + + +DEFINE_FALLBACK_SHADER( WorldVertexTransition, WorldVertexTransition_DX9 ) + +BEGIN_VS_SHADER( WorldVertexTransition_DX9, "Help for WorldVertexTransition" ) + + BEGIN_SHADER_PARAMS + SHADER_PARAM( ALBEDO, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture", "albedo (Base texture with no baked lighting)" ) + SHADER_PARAM( SELFILLUMTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "Self-illumination tint" ) + SHADER_PARAM( DETAIL, SHADER_PARAM_TYPE_TEXTURE, "shadertest/detail", "detail texture" ) + SHADER_PARAM( DETAILFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $detail" ) + SHADER_PARAM( DETAILSCALE, SHADER_PARAM_TYPE_FLOAT, "4", "scale of the detail texture" ) + + // detail (multi-) texturing + SHADER_PARAM( DETAILBLENDMODE, SHADER_PARAM_TYPE_INTEGER, "0", "mode for combining detail texture with base. 0=normal, 1= additive, 2=alpha blend detail over base, 3=crossfade" ) + SHADER_PARAM( DETAILBLENDFACTOR, SHADER_PARAM_TYPE_FLOAT, "1", "blend amount for detail texture." ) + SHADER_PARAM( DETAILTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "detail texture tint" ) + + SHADER_PARAM( ENVMAP, SHADER_PARAM_TYPE_TEXTURE, "shadertest/shadertest_env", "envmap" ) + SHADER_PARAM( ENVMAPFRAME, SHADER_PARAM_TYPE_INTEGER, "", "" ) + SHADER_PARAM( ENVMAPMASK, SHADER_PARAM_TYPE_TEXTURE, "shadertest/shadertest_envmask", "envmap mask" ) + SHADER_PARAM( ENVMAPMASKFRAME, SHADER_PARAM_TYPE_INTEGER, "", "" ) + SHADER_PARAM( ENVMAPMASKTRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$envmapmask texcoord transform" ) + SHADER_PARAM( ENVMAPTINT, SHADER_PARAM_TYPE_COLOR, "[1 1 1]", "envmap tint" ) + SHADER_PARAM( BUMPMAP, SHADER_PARAM_TYPE_TEXTURE, "models/shadertest/shader1_normal", "bump map" ) + SHADER_PARAM( BUMPFRAME, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $bumpmap" ) + SHADER_PARAM( BUMPTRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$bumpmap texcoord transform" ) + SHADER_PARAM( ENVMAPCONTRAST, SHADER_PARAM_TYPE_FLOAT, "0.0", "contrast 0 == normal 1 == color*color" ) + SHADER_PARAM( ENVMAPSATURATION, SHADER_PARAM_TYPE_FLOAT, "1.0", "saturation 0 == greyscale 1 == normal" ) + SHADER_PARAM( FRESNELREFLECTION, SHADER_PARAM_TYPE_FLOAT, "1.0", "1.0 == mirror, 0.0 == water" ) + SHADER_PARAM( NODIFFUSEBUMPLIGHTING, SHADER_PARAM_TYPE_INTEGER, "0", "0 == Use diffuse bump lighting, 1 = No diffuse bump lighting" ) + SHADER_PARAM( BUMPMAP2, SHADER_PARAM_TYPE_TEXTURE, "models/shadertest/shader3_normal", "bump map" ) + SHADER_PARAM( BUMPFRAME2, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $bumpmap" ) + SHADER_PARAM( BUMPTRANSFORM2, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$bumpmap texcoord transform" ) + SHADER_PARAM( BUMPMASK, SHADER_PARAM_TYPE_TEXTURE, "models/shadertest/shader1_normal", "bump map" ) + SHADER_PARAM( BASETEXTURE2, SHADER_PARAM_TYPE_TEXTURE, "shadertest/detail", "detail texture" ) + SHADER_PARAM( FRAME2, SHADER_PARAM_TYPE_INTEGER, "0", "frame number for $basetexture2" ) + SHADER_PARAM( BASETEXTURENOENVMAP, SHADER_PARAM_TYPE_BOOL, "0", "" ) + SHADER_PARAM( BASETEXTURE2NOENVMAP, SHADER_PARAM_TYPE_BOOL, "0", "" ) + SHADER_PARAM( DETAIL_ALPHA_MASK_BASE_TEXTURE, SHADER_PARAM_TYPE_BOOL, "0", + "If this is 1, then when detail alpha=0, no base texture is blended and when " + "detail alpha=1, you get detail*base*lightmap" ) + SHADER_PARAM( LIGHTWARPTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "light munging lookup texture" ) + SHADER_PARAM( BLENDMODULATETEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "texture to use r/g channels for blend range for" ) + SHADER_PARAM( BLENDMASKTRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$blendmodulatetexture texcoord transform" ) + SHADER_PARAM( MASKEDBLENDING, SHADER_PARAM_TYPE_INTEGER, "0", "blend using texture with no vertex alpha. For using texture blending on non-displacements" ) + SHADER_PARAM( SSBUMP, SHADER_PARAM_TYPE_INTEGER, "0", "whether or not to use alternate bumpmap format with height" ) + SHADER_PARAM( SEAMLESS_SCALE, SHADER_PARAM_TYPE_FLOAT, "0", "Scale factor for 'seamless' texture mapping. 0 means to use ordinary mapping" ) + END_SHADER_PARAMS + + void SetupVars( WorldVertexTransitionEditor_DX8_Vars_t& info ) + { + info.m_nBaseTextureVar = BASETEXTURE; + info.m_nBaseTextureFrameVar = FRAME; + info.m_nBaseTextureTransformVar = BASETEXTURETRANSFORM; + info.m_nBaseTexture2Var = BASETEXTURE2; + info.m_nBaseTexture2FrameVar = FRAME2; + info.m_nBaseTexture2TransformVar = BASETEXTURETRANSFORM; // FIXME!!!! + } + + void SetupVars( LightmappedGeneric_DX9_Vars_t& info ) + { + info.m_nBaseTexture = BASETEXTURE; + info.m_nBaseTextureFrame = FRAME; + info.m_nBaseTextureTransform = BASETEXTURETRANSFORM; + info.m_nAlbedo = ALBEDO; + info.m_nSelfIllumTint = SELFILLUMTINT; + + info.m_nDetail = DETAIL; + info.m_nDetailFrame = DETAILFRAME; + info.m_nDetailScale = DETAILSCALE; + info.m_nDetailTextureCombineMode = DETAILBLENDMODE; + info.m_nDetailTextureBlendFactor = DETAILBLENDFACTOR; + info.m_nDetailTint = DETAILTINT; + + info.m_nEnvmap = ENVMAP; + info.m_nEnvmapFrame = ENVMAPFRAME; + info.m_nEnvmapMask = ENVMAPMASK; + info.m_nEnvmapMaskFrame = ENVMAPMASKFRAME; + info.m_nEnvmapMaskTransform = ENVMAPMASKTRANSFORM; + info.m_nEnvmapTint = ENVMAPTINT; + info.m_nBumpmap = BUMPMAP; + info.m_nBumpFrame = BUMPFRAME; + info.m_nBumpTransform = BUMPTRANSFORM; + info.m_nEnvmapContrast = ENVMAPCONTRAST; + info.m_nEnvmapSaturation = ENVMAPSATURATION; + info.m_nFresnelReflection = FRESNELREFLECTION; + info.m_nNoDiffuseBumpLighting = NODIFFUSEBUMPLIGHTING; + info.m_nBumpmap2 = BUMPMAP2; + info.m_nBumpFrame2 = BUMPFRAME2; + info.m_nBaseTexture2 = BASETEXTURE2; + info.m_nBaseTexture2Frame = FRAME2; + info.m_nBumpTransform2 = BUMPTRANSFORM2; + info.m_nBumpMask = BUMPMASK; + info.m_nBaseTextureNoEnvmap = BASETEXTURENOENVMAP; + info.m_nBaseTexture2NoEnvmap = BASETEXTURE2NOENVMAP; + info.m_nDetailAlphaMaskBaseTexture = DETAIL_ALPHA_MASK_BASE_TEXTURE; + info.m_nFlashlightTexture = FLASHLIGHTTEXTURE; + info.m_nFlashlightTextureFrame = FLASHLIGHTTEXTUREFRAME; + info.m_nLightWarpTexture = LIGHTWARPTEXTURE; + info.m_nBlendModulateTexture = BLENDMODULATETEXTURE; + info.m_nBlendMaskTransform = BLENDMASKTRANSFORM; + info.m_nMaskedBlending = MASKEDBLENDING; + info.m_nSelfShadowedBumpFlag = SSBUMP; + info.m_nSeamlessMappingScale = SEAMLESS_SCALE; + info.m_nAlphaTestReference = -1; + } + + SHADER_FALLBACK + { + if( g_pHardwareConfig->GetDXSupportLevel() < 90 ) + return "WorldVertexTransition_DX8"; + + return 0; + } + + SHADER_INIT_PARAMS() + { + SetupVars( s_info ); + InitParamsLightmappedGeneric_DX9( this, params, pMaterialName, s_info ); + } + + SHADER_INIT + { + SetupVars( s_info ); + InitLightmappedGeneric_DX9( this, params, s_info ); + } + + SHADER_DRAW + { + if ( UsingEditor( params ) ) + { + WorldVertexTransitionEditor_DX8_Vars_t info; + SetupVars( info ); + DrawWorldVertexTransitionEditor_DX8( this, params, pShaderAPI, pShaderShadow, info ); + return; + } + + DrawLightmappedGeneric_DX9( this, params, pShaderAPI, pShaderShadow, s_info, pContextDataPtr ); + } +END_SHADER + diff --git a/materialsystem/stdshaders/worldvertextransition_dx6.cpp b/materialsystem/stdshaders/worldvertextransition_dx6.cpp new file mode 100644 index 0000000..163291e --- /dev/null +++ b/materialsystem/stdshaders/worldvertextransition_dx6.cpp @@ -0,0 +1,52 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//=============================================================================// + +#include "shaderlib/cshader.h" + +#include "worldvertextransition_dx6_helper.h" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +DEFINE_FALLBACK_SHADER( WorldVertexTransition, WorldVertexTransition_DX6 ) + +BEGIN_SHADER( WorldVertexTransition_DX6, + "Help for WorldVertexTransition_dx6" ) + + BEGIN_SHADER_PARAMS + SHADER_PARAM( BASETEXTURE2, SHADER_PARAM_TYPE_TEXTURE, "shadertest/BaseTexture2", "base texture2 help" ) + END_SHADER_PARAMS + + void SetupVars( WorldVertexTransition_DX6_Vars_t& info ) + { + info.m_nBaseTextureVar = BASETEXTURE; + info.m_nBaseTextureFrameVar = FRAME; + info.m_nBaseTexture2Var = BASETEXTURE2; + info.m_nFlashlightTextureVar = FLASHLIGHTTEXTURE; + } + + SHADER_INIT_PARAMS() + { + WorldVertexTransition_DX6_Vars_t info; + SetupVars( info ); + InitParamsWorldVertexTransition_DX6( params, info ); + } + + SHADER_INIT + { + WorldVertexTransition_DX6_Vars_t info; + SetupVars( info ); + InitWorldVertexTransition_DX6( this, params, info ); + } + + SHADER_DRAW + { + WorldVertexTransition_DX6_Vars_t info; + SetupVars( info ); + DrawWorldVertexTransition_DX6( this, params, pShaderAPI, pShaderShadow, info ); + } +END_SHADER diff --git a/materialsystem/stdshaders/worldvertextransition_dx6_helper.cpp b/materialsystem/stdshaders/worldvertextransition_dx6_helper.cpp new file mode 100644 index 0000000..7539ff2 --- /dev/null +++ b/materialsystem/stdshaders/worldvertextransition_dx6_helper.cpp @@ -0,0 +1,206 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//============================================================================= + +#include "shaderlib/cshader.h" +#include "worldvertextransition_dx6_helper.h" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + + +void InitParamsWorldVertexTransition_DX6( IMaterialVar** params, WorldVertexTransition_DX6_Vars_t &info ) +{ + SET_FLAGS2( MATERIAL_VAR2_LIGHTING_LIGHTMAP ); + // FLASHLIGHTFIXME + params[info.m_nFlashlightTextureVar]->SetStringValue( "effects/flashlight001" ); +} + +void InitWorldVertexTransition_DX6( CBaseShader *pShader, IMaterialVar** params, WorldVertexTransition_DX6_Vars_t &info ) +{ + // FLASHLIGHTFIXME + if ( params[info.m_nFlashlightTextureVar]->IsDefined() ) + { + pShader->LoadTexture( info.m_nFlashlightTextureVar ); + } + + if ( params[info.m_nBaseTextureVar]->IsDefined() ) + { + pShader->LoadTexture( info.m_nBaseTextureVar ); + } + + if ( params[info.m_nBaseTexture2Var]->IsDefined() ) + { + pShader->LoadTexture( info.m_nBaseTexture2Var ); + } +} + +static void DrawFlashlightPass( CBaseShader *pShader, IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow, int nPass, WorldVertexTransition_DX6_Vars_t &info ) +{ + SHADOW_STATE + { + SET_FLAGS2( MATERIAL_VAR2_NEEDS_FIXED_FUNCTION_FLASHLIGHT ); + pShaderShadow->EnableDepthWrites( false ); + pShaderShadow->EnableAlphaWrites( false ); + + pShaderShadow->SetDiffuseMaterialSource( SHADER_MATERIALSOURCE_COLOR1 ); + if( nPass == 0 ) + { + pShader->EnableAlphaBlending( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE ); + } + else + { + pShader->EnableAlphaBlending( SHADER_BLEND_ONE_MINUS_SRC_ALPHA, SHADER_BLEND_ONE ); + } + + int flags = SHADER_DRAW_POSITION | SHADER_DRAW_TEXCOORD1 | SHADER_DRAW_COLOR | SHADER_DRAW_NORMAL; + pShaderShadow->DrawFlags( flags ); + pShader->FogToBlack(); + + pShaderShadow->EnableLighting( true ); + + pShaderShadow->EnableCustomPixelPipe( true ); + pShaderShadow->CustomTextureStages( 2 ); + + // color stage 0 + // projected texture * vertex color (lighting) + pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE0, + SHADER_TEXCHANNEL_COLOR, + SHADER_TEXOP_MODULATE, + SHADER_TEXARG_TEXTURE, + SHADER_TEXARG_VERTEXCOLOR ); + + // color stage 1 + // * base texture + pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE1, + SHADER_TEXCHANNEL_COLOR, + SHADER_TEXOP_MODULATE, + SHADER_TEXARG_TEXTURE, SHADER_TEXARG_PREVIOUSSTAGE ); + + // alpha stage 0 + // get alpha from constant alpha * vertex color + pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE0, + SHADER_TEXCHANNEL_ALPHA, + SHADER_TEXOP_MODULATE, + SHADER_TEXARG_CONSTANTCOLOR, SHADER_TEXARG_VERTEXCOLOR ); + + // alpha stage 1 + // get alpha from $basetexture + pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE1, + SHADER_TEXCHANNEL_ALPHA, + SHADER_TEXOP_MODULATE, + SHADER_TEXARG_TEXTURE, SHADER_TEXARG_PREVIOUSSTAGE ); + + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + + // Shove the view position into texcoord 0 before the texture matrix. + pShaderShadow->TexGen( SHADER_TEXTURE_STAGE0, SHADER_TEXGENPARAM_EYE_LINEAR ); + pShaderShadow->EnableTexGen( SHADER_TEXTURE_STAGE0, true ); + } + DYNAMIC_STATE + { + pShader->SetFlashlightFixedFunctionTextureTransform( MATERIAL_TEXTURE0 ); + + // NOTE: This has to come after the loadmatrix since the loadmatrix screws with the + // transform flags!!!!!! + // Specify that we have XYZ texcoords that need to be divided by W before the pixel shader. + // NOTE Tried to divide XY by Z, but doesn't work. + pShaderAPI->SetTextureTransformDimension( SHADER_TEXTURE_STAGE0, 3, true ); + + pShader->BindTexture( SHADER_SAMPLER0, FLASHLIGHTTEXTURE, FLASHLIGHTTEXTUREFRAME ); + if( nPass == 0 ) + { + pShader->BindTexture( SHADER_SAMPLER1, info.m_nBaseTexture2Var, -1 ); + } + else + { + pShader->BindTexture( SHADER_SAMPLER1, info.m_nBaseTextureVar, info.m_nBaseTextureFrameVar ); + } + } + pShader->Draw(); +} + + +void DrawWorldVertexTransition_DX6( CBaseShader *pShader, IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow, WorldVertexTransition_DX6_Vars_t &info ) +{ + bool bHasFlashlight = pShader->UsingFlashlight( params ); + if( bHasFlashlight ) + { + DrawFlashlightPass( pShader, params, pShaderAPI, pShaderShadow, 0, info ); + DrawFlashlightPass( pShader, params, pShaderAPI, pShaderShadow, 1, info ); + return; + } + + SHADOW_STATE + { + SET_FLAGS2( MATERIAL_VAR2_LIGHTING_LIGHTMAP ); + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + pShaderShadow->OverbrightValue( SHADER_TEXTURE_STAGE1, OVERBRIGHT ); + + pShaderShadow->DrawFlags( SHADER_DRAW_COLOR | SHADER_DRAW_POSITION | SHADER_DRAW_TEXCOORD1 | SHADER_DRAW_LIGHTMAP_TEXCOORD0 ); + pShader->FogToFogColor(); + } + DYNAMIC_STATE + { + //pShaderAPI->TexMinFilter( SHADER_TEXFILTERMODE_NEAREST ); + //pShaderAPI->TexMagFilter( SHADER_TEXFILTERMODE_NEAREST ); + pShader->BindTexture( SHADER_SAMPLER1, info.m_nBaseTextureVar ); + pShaderAPI->BindStandardTexture( SHADER_SAMPLER0, TEXTURE_LIGHTMAP ); + } + pShader->Draw(); + + SHADOW_STATE + { + SET_FLAGS2( MATERIAL_VAR2_LIGHTING_LIGHTMAP ); + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + pShaderShadow->EnableBlending( true ); + + pShaderShadow->EnableCustomPixelPipe( true ); + pShaderShadow->CustomTextureStages( 2 ); + + // alpha and color stage 0 + pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE0, + SHADER_TEXCHANNEL_ALPHA, + SHADER_TEXOP_SELECTARG1, + SHADER_TEXARG_TEXTURE, + SHADER_TEXARG_TEXTURE ); + + pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE0, + SHADER_TEXCHANNEL_COLOR, + SHADER_TEXOP_SELECTARG1, + SHADER_TEXARG_TEXTURE, + SHADER_TEXARG_TEXTURE ); + + // alpha and color stage 1 + pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE1, + SHADER_TEXCHANNEL_ALPHA, + SHADER_TEXOP_MODULATE, + SHADER_TEXARG_TEXTURE, + SHADER_TEXARG_VERTEXCOLOR ); + + pShaderShadow->CustomTextureOperation( SHADER_TEXTURE_STAGE1, + SHADER_TEXCHANNEL_COLOR, + SHADER_TEXOP_MODULATE2X, + SHADER_TEXARG_PREVIOUSSTAGE, + SHADER_TEXARG_TEXTURE ); + + // Looks backwards, but this is done so that lightmap alpha = 1 when only + // using 1 texture (needed for translucent displacements). + pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA ); + + pShaderShadow->DrawFlags( SHADER_DRAW_COLOR | SHADER_DRAW_POSITION | SHADER_DRAW_TEXCOORD1 | SHADER_DRAW_LIGHTMAP_TEXCOORD0 ); + pShader->FogToFogColor(); + } + DYNAMIC_STATE + { + pShader->BindTexture( SHADER_SAMPLER1, info.m_nBaseTexture2Var ); + pShaderAPI->BindStandardTexture( SHADER_SAMPLER0, TEXTURE_LIGHTMAP ); + } + pShader->Draw(); +} diff --git a/materialsystem/stdshaders/worldvertextransition_dx6_helper.h b/materialsystem/stdshaders/worldvertextransition_dx6_helper.h new file mode 100644 index 0000000..16e0bfd --- /dev/null +++ b/materialsystem/stdshaders/worldvertextransition_dx6_helper.h @@ -0,0 +1,39 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//============================================================================= + +#ifndef WORLDVERTEXTRANSITION_DX6_HELPER_H +#define WORLDVERTEXTRANSITION_DX6_HELPER_H + +//----------------------------------------------------------------------------- +// Forward declarations +//----------------------------------------------------------------------------- +class CBaseShader; +class IMaterialVar; +class IShaderDynamicAPI; +class IShaderShadow; + + +//----------------------------------------------------------------------------- +// Init params/ init/ draw methods +//----------------------------------------------------------------------------- +struct WorldVertexTransition_DX6_Vars_t +{ + WorldVertexTransition_DX6_Vars_t() { memset( this, 0xFF, sizeof(WorldVertexTransition_DX6_Vars_t) ); } + + int m_nBaseTextureVar; + int m_nBaseTextureFrameVar; + int m_nBaseTexture2Var; + int m_nFlashlightTextureVar; +}; + +void InitParamsWorldVertexTransition_DX6( IMaterialVar** params, WorldVertexTransition_DX6_Vars_t &info ); +void InitWorldVertexTransition_DX6( CBaseShader *pShader, IMaterialVar** params, WorldVertexTransition_DX6_Vars_t &info ); +void DrawWorldVertexTransition_DX6( CBaseShader *pShader, IMaterialVar** params, + IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow, WorldVertexTransition_DX6_Vars_t &info ); + + +#endif // WORLDVERTEXTRANSITION_DX6_HELPER_H \ No newline at end of file diff --git a/materialsystem/stdshaders/worldvertextransition_dx8_helper.cpp b/materialsystem/stdshaders/worldvertextransition_dx8_helper.cpp new file mode 100644 index 0000000..6a49fd7 --- /dev/null +++ b/materialsystem/stdshaders/worldvertextransition_dx8_helper.cpp @@ -0,0 +1,81 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//============================================================================= + +#include "worldvertextransition_dx8_helper.h" +#include "BaseVSShader.h" + +#include "WorldVertexTransition.inc" + + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + + +void InitParamsWorldVertexTransitionEditor_DX8( IMaterialVar** params, WorldVertexTransitionEditor_DX8_Vars_t &info ) +{ + SET_FLAGS2( MATERIAL_VAR2_LIGHTING_LIGHTMAP ); +} + +void InitWorldVertexTransitionEditor_DX8( CBaseVSShader *pShader, IMaterialVar** params, WorldVertexTransitionEditor_DX8_Vars_t &info ) +{ + if ( params[info.m_nBaseTextureVar]->IsDefined() ) + { + pShader->LoadTexture( info.m_nBaseTextureVar ); + } + + if ( params[info.m_nBaseTexture2Var]->IsDefined() ) + { + pShader->LoadTexture( info.m_nBaseTexture2Var ); + } +} + +void DrawWorldVertexTransitionEditor_DX8( CBaseVSShader *pShader, IMaterialVar** params, IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow, WorldVertexTransitionEditor_DX8_Vars_t &info ) +{ + SHADOW_STATE + { + // This is the dx8 worldcraft version (non-bumped always.. too bad) + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); + pShaderShadow->EnableTexture( SHADER_SAMPLER2, true ); + + int fmt = VERTEX_POSITION | VERTEX_COLOR; + pShaderShadow->VertexShaderVertexFormat( fmt, 2, 0, 0 ); + + worldvertextransition_Static_Index vshIndex; + pShaderShadow->SetVertexShader( "WorldVertexTransition", vshIndex.GetIndex() ); + pShaderShadow->SetPixelShader( "WorldVertexTransition_Editor" ); + + pShader->FogToFogColor(); + } + DYNAMIC_STATE + { + pShader->BindTexture( SHADER_SAMPLER0, info.m_nBaseTextureVar, info.m_nBaseTextureFrameVar ); + pShader->BindTexture( SHADER_SAMPLER1, info.m_nBaseTexture2Var, info.m_nBaseTexture2FrameVar ); + + // Texture 3 = lightmap + pShaderAPI->BindStandardTexture( SHADER_SAMPLER2, TEXTURE_LIGHTMAP ); + + pShader->EnablePixelShaderOverbright( 0, true, true ); + + // JasonM - Gnarly hack since we're calling this legacy shader from DX9 + int nTextureTransformConst = VERTEX_SHADER_SHADER_SPECIFIC_CONST_0; + int nTextureTransformConst2 = VERTEX_SHADER_SHADER_SPECIFIC_CONST_2; + if ( g_pHardwareConfig->GetDXSupportLevel() >= 90) + { + nTextureTransformConst -= 10; + nTextureTransformConst2 -= 10; + } + + pShader->SetVertexShaderTextureTransform( nTextureTransformConst, info.m_nBaseTextureTransformVar ); + pShader->SetVertexShaderTextureTransform( nTextureTransformConst2, info.m_nBaseTexture2TransformVar ); + + worldvertextransition_Dynamic_Index vshIndex; + vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() ); + } + pShader->Draw(); +} diff --git a/materialsystem/stdshaders/worldvertextransition_dx8_helper.h b/materialsystem/stdshaders/worldvertextransition_dx8_helper.h new file mode 100644 index 0000000..d17d532 --- /dev/null +++ b/materialsystem/stdshaders/worldvertextransition_dx8_helper.h @@ -0,0 +1,44 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//============================================================================= + +#ifndef WORLDVERTEXTRANSITION_DX8_HELPER_H +#define WORLDVERTEXTRANSITION_DX8_HELPER_H + +#include + + +//----------------------------------------------------------------------------- +// Forward declarations +//----------------------------------------------------------------------------- +class CBaseVSShader; +class IMaterialVar; +class IShaderDynamicAPI; +class IShaderShadow; + + +//----------------------------------------------------------------------------- +// Init params/ init/ draw methods +//----------------------------------------------------------------------------- +struct WorldVertexTransitionEditor_DX8_Vars_t +{ + WorldVertexTransitionEditor_DX8_Vars_t() { memset( this, 0xFF, sizeof(WorldVertexTransitionEditor_DX8_Vars_t) ); } + + int m_nBaseTextureVar; + int m_nBaseTextureFrameVar; + int m_nBaseTextureTransformVar; + int m_nBaseTexture2Var; + int m_nBaseTexture2FrameVar; + int m_nBaseTexture2TransformVar; +}; + +void InitParamsWorldVertexTransitionEditor_DX8( IMaterialVar** params, WorldVertexTransitionEditor_DX8_Vars_t &info ); +void InitWorldVertexTransitionEditor_DX8( CBaseVSShader *pShader, IMaterialVar** params, WorldVertexTransitionEditor_DX8_Vars_t &info ); +void DrawWorldVertexTransitionEditor_DX8( CBaseVSShader *pShader, IMaterialVar** params, + IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow, WorldVertexTransitionEditor_DX8_Vars_t &info ); + + +#endif // WORLDVERTEXTRANSITION_DX8_HELPER_H \ No newline at end of file diff --git a/materialsystem/stdshaders/writestencil_dx8.cpp b/materialsystem/stdshaders/writestencil_dx8.cpp new file mode 100644 index 0000000..6feb211 --- /dev/null +++ b/materialsystem/stdshaders/writestencil_dx8.cpp @@ -0,0 +1,61 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//=============================================================================// + +#include "BaseVSShader.h" + +#include "writez.inc" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +DEFINE_FALLBACK_SHADER( WriteStencil, WriteStencil_DX8 ) + +BEGIN_VS_SHADER_FLAGS( WriteStencil_DX8, "Help for WriteStencil", SHADER_NOT_EDITABLE ) + + BEGIN_SHADER_PARAMS + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + } + + SHADER_FALLBACK + { + if ( IsPC() && g_pHardwareConfig->GetDXSupportLevel() < 80 ) + return "WriteStencil_DX6"; + + return 0; + } + + SHADER_INIT + { + } + + SHADER_DRAW + { + SHADOW_STATE + { + pShaderShadow->EnableColorWrites( false ); // + pShaderShadow->EnableAlphaWrites( false ); // Write ONLY to stencil + pShaderShadow->EnableDepthWrites( false ); // + + writez_Static_Index vshIndex; + pShaderShadow->SetVertexShader( "writez", vshIndex.GetIndex() ); + + pShaderShadow->SetPixelShader( "white" ); + pShaderShadow->VertexShaderVertexFormat( VERTEX_POSITION, 1, 0, 0 ); + } + DYNAMIC_STATE + { + writez_Dynamic_Index vshIndex; + vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() ); + } + Draw(); + } +END_SHADER + diff --git a/materialsystem/stdshaders/writestencil_dx9.cpp b/materialsystem/stdshaders/writestencil_dx9.cpp new file mode 100644 index 0000000..e4d9e56 --- /dev/null +++ b/materialsystem/stdshaders/writestencil_dx9.cpp @@ -0,0 +1,81 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//=============================================================================// + +#include "BaseVSShader.h" + +#include "writez_vs20.inc" +#include "white_ps20.inc" +#include "white_ps20b.inc" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +DEFINE_FALLBACK_SHADER( WriteStencil, WriteStencil_DX9 ) + +BEGIN_VS_SHADER_FLAGS( WriteStencil_DX9, "Help for WriteStencil", SHADER_NOT_EDITABLE ) + + BEGIN_SHADER_PARAMS + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + } + + SHADER_FALLBACK + { + if ( g_pHardwareConfig->GetDXSupportLevel() < 90 ) + return "WriteStencil_DX8"; + + return 0; + } + + SHADER_INIT + { + } + + SHADER_DRAW + { + SHADOW_STATE + { + pShaderShadow->EnableColorWrites( false ); // + pShaderShadow->EnableAlphaWrites( false ); // Write ONLY to stencil + pShaderShadow->EnableDepthWrites( false ); // + + DECLARE_STATIC_VERTEX_SHADER( writez_vs20 ); + SET_STATIC_VERTEX_SHADER( writez_vs20 ); + + // No pixel shader on Direct3D, doubles fill rate + if ( g_pHardwareConfig->PlatformRequiresNonNullPixelShaders() ) + { + DECLARE_STATIC_PIXEL_SHADER( white_ps20 ); + SET_STATIC_PIXEL_SHADER( white_ps20 ); + } + + // Set stream format (note that this shader supports compression) + unsigned int flags = VERTEX_POSITION | VERTEX_FORMAT_COMPRESSED; + int nTexCoordCount = 1; + int userDataSize = 0; + pShaderShadow->VertexShaderVertexFormat( flags, nTexCoordCount, NULL, userDataSize ); + } + DYNAMIC_STATE + { + DECLARE_DYNAMIC_VERTEX_SHADER( writez_vs20 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( DOWATERFOG, pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression ); + SET_DYNAMIC_VERTEX_SHADER( writez_vs20 ); + + // No pixel shader on Direct3D, doubles fill rate + if ( g_pHardwareConfig->PlatformRequiresNonNullPixelShaders() ) + { + DECLARE_DYNAMIC_PIXEL_SHADER( white_ps20 ); + SET_DYNAMIC_PIXEL_SHADER( white_ps20 ); + } + } + Draw(); + } +END_SHADER + diff --git a/materialsystem/stdshaders/writevertexalphatodestalpha_ps11.fxc b/materialsystem/stdshaders/writevertexalphatodestalpha_ps11.fxc new file mode 100644 index 0000000..98554c7 --- /dev/null +++ b/materialsystem/stdshaders/writevertexalphatodestalpha_ps11.fxc @@ -0,0 +1,18 @@ +//====== Copyright © 1996-2004, Valve Corporation, All rights reserved. ======= +// +// Purpose: +// +//============================================================================= + +#include "common_ps_fxc.h" + + +struct PS_INPUT +{ + float4 vColor : COLOR0; +}; + +float4 main( PS_INPUT i ) : COLOR +{ + return float4( 1.0f, 1.0f, 1.0f, 1-i.vColor.a ); +} diff --git a/materialsystem/stdshaders/writevertexalphatodestalpha_vs11.fxc b/materialsystem/stdshaders/writevertexalphatodestalpha_vs11.fxc new file mode 100644 index 0000000..c793eaa --- /dev/null +++ b/materialsystem/stdshaders/writevertexalphatodestalpha_vs11.fxc @@ -0,0 +1,33 @@ +//====== Copyright © 1996-2004, Valve Corporation, All rights reserved. ======= +// +// Purpose: +// +//============================================================================= + +#include "common_vs_fxc.h" + +struct VS_INPUT +{ + // If this is float4, and the input is float3, the w component default to one. + float4 vPos : POSITION; + float4 vColor : COLOR0; +}; + +struct VS_OUTPUT +{ + float4 projPos : POSITION; + float4 vColor : COLOR0; +}; + +VS_OUTPUT main( const VS_INPUT v ) +{ + VS_OUTPUT o; + + float4 projPos; + + projPos = mul( v.vPos, cModelViewProj ); + o.projPos = projPos; + + o.vColor = v.vColor; + return o; +} diff --git a/materialsystem/stdshaders/writez.vsh b/materialsystem/stdshaders/writez.vsh new file mode 100644 index 0000000..8b1aa4b --- /dev/null +++ b/materialsystem/stdshaders/writez.vsh @@ -0,0 +1,22 @@ +vs.1.1 + +# DYNAMIC: "DOWATERFOG" "0..1" + +#include "macros.vsh" + +;------------------------------------------------------------------------------ +; $SHADER_SPECIFIC_CONST_0-$SHADER_SPECIFIC_CONST_1 = Base texture transform +; $SHADER_SPECIFIC_CONST_2-$SHADER_SPECIFIC_CONST_3 = Mask texture transform +; $SHADER_SPECIFIC_CONST_4 = Modulation color +;------------------------------------------------------------------------------ + +&AllocateRegister( \$projPos ); + +dp4 $projPos.x, $vPos, $cModelViewProj0 +dp4 $projPos.y, $vPos, $cModelViewProj1 +dp4 $projPos.z, $vPos, $cModelViewProj2 +dp4 $projPos.w, $vPos, $cModelViewProj3 +mov oPos, $projPos + +&FreeRegister( \$projPos ); + diff --git a/materialsystem/stdshaders/writez_dx6.cpp b/materialsystem/stdshaders/writez_dx6.cpp new file mode 100644 index 0000000..b5d35c5 --- /dev/null +++ b/materialsystem/stdshaders/writez_dx6.cpp @@ -0,0 +1,41 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//=============================================================================// + +#include "shaderlib/cshader.h" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +DEFINE_FALLBACK_SHADER( WriteZ, WriteZ_DX6 ) + +BEGIN_SHADER_FLAGS( WriteZ_DX6, "Help for WriteZ_DX6", SHADER_NOT_EDITABLE ) + BEGIN_SHADER_PARAMS + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + } + + SHADER_INIT + { + } + + SHADER_DRAW + { + SHADOW_STATE + { + pShaderShadow->EnableColorWrites( false ); + pShaderShadow->EnableAlphaWrites( false ); + pShaderShadow->DrawFlags( SHADER_DRAW_POSITION ); + } + DYNAMIC_STATE + { + } + Draw(); + } +END_SHADER + diff --git a/materialsystem/stdshaders/writez_dx8.cpp b/materialsystem/stdshaders/writez_dx8.cpp new file mode 100644 index 0000000..0262ea5 --- /dev/null +++ b/materialsystem/stdshaders/writez_dx8.cpp @@ -0,0 +1,60 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//=============================================================================// + +#include "BaseVSShader.h" + +#include "writez.inc" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +DEFINE_FALLBACK_SHADER( WriteZ, WriteZ_DX8 ) + +BEGIN_VS_SHADER_FLAGS( WriteZ_DX8, "Help for WriteZ", SHADER_NOT_EDITABLE ) + + BEGIN_SHADER_PARAMS + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + } + + SHADER_FALLBACK + { + if ( IsPC() && g_pHardwareConfig->GetDXSupportLevel() < 80 ) + return "WriteZ_DX6"; + + return 0; + } + + SHADER_INIT + { + } + + SHADER_DRAW + { + SHADOW_STATE + { + pShaderShadow->EnableColorWrites( false ); + pShaderShadow->EnableAlphaWrites( false ); + + writez_Static_Index vshIndex; + pShaderShadow->SetVertexShader( "writez", vshIndex.GetIndex() ); + + pShaderShadow->SetPixelShader( "white" ); + pShaderShadow->VertexShaderVertexFormat( VERTEX_POSITION, 1, 0, 0 ); + } + DYNAMIC_STATE + { + writez_Dynamic_Index vshIndex; + vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() ); + } + Draw(); + } +END_SHADER + diff --git a/materialsystem/stdshaders/writez_dx9.cpp b/materialsystem/stdshaders/writez_dx9.cpp new file mode 100644 index 0000000..c1cd52a --- /dev/null +++ b/materialsystem/stdshaders/writez_dx9.cpp @@ -0,0 +1,81 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//=============================================================================// + +#include "BaseVSShader.h" + + +#include "writez_vs20.inc" +#include "white_ps20.inc" +#include "white_ps20b.inc" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +DEFINE_FALLBACK_SHADER( WriteZ, WriteZ_DX9 ) + +BEGIN_VS_SHADER_FLAGS( WriteZ_DX9, "Help for WriteZ", SHADER_NOT_EDITABLE ) + + BEGIN_SHADER_PARAMS + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + } + + SHADER_FALLBACK + { + if ( g_pHardwareConfig->GetDXSupportLevel() < 90 ) + return "WriteZ_DX8"; + + return 0; + } + + SHADER_INIT + { + } + + SHADER_DRAW + { + SHADOW_STATE + { + pShaderShadow->EnableColorWrites( false ); + pShaderShadow->EnableAlphaWrites( false ); + + DECLARE_STATIC_VERTEX_SHADER( writez_vs20 ); + SET_STATIC_VERTEX_SHADER( writez_vs20 ); + + // No pixel shader on Direct3D, doubles fill rate + if ( g_pHardwareConfig->PlatformRequiresNonNullPixelShaders() ) + { + DECLARE_STATIC_PIXEL_SHADER( white_ps20 ); + SET_STATIC_PIXEL_SHADER( white_ps20 ); + } + + // Set stream format (note that this shader supports compression) + unsigned int flags = VERTEX_POSITION | VERTEX_FORMAT_COMPRESSED; + int nTexCoordCount = 1; + int userDataSize = 0; + pShaderShadow->VertexShaderVertexFormat( flags, nTexCoordCount, NULL, userDataSize ); + } + DYNAMIC_STATE + { + DECLARE_DYNAMIC_VERTEX_SHADER( writez_vs20 ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( DOWATERFOG, pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression ); + SET_DYNAMIC_VERTEX_SHADER( writez_vs20 ); + + // No pixel shader on Direct3D, doubles fill rate + if ( g_pHardwareConfig->PlatformRequiresNonNullPixelShaders() ) + { + DECLARE_DYNAMIC_PIXEL_SHADER( white_ps20 ); + SET_DYNAMIC_PIXEL_SHADER( white_ps20 ); + } + } + Draw(); + } +END_SHADER + diff --git a/materialsystem/stdshaders/writez_vs20.fxc b/materialsystem/stdshaders/writez_vs20.fxc new file mode 100644 index 0000000..3f31f3f --- /dev/null +++ b/materialsystem/stdshaders/writez_vs20.fxc @@ -0,0 +1,24 @@ +// DYNAMIC: "COMPRESSED_VERTS" "0..1" +// DYNAMIC: "DOWATERFOG" "0..1" + +#include "common_vs_fxc.h" + +struct VS_INPUT +{ + float4 vPos : POSITION; +}; + +struct VS_OUTPUT +{ + float4 vProjPos : POSITION; +}; + + +VS_OUTPUT main( const VS_INPUT v ) +{ + VS_OUTPUT o = ( VS_OUTPUT )0; + + o.vProjPos = mul( v.vPos, cModelViewProj ); + + return o; +} \ No newline at end of file diff --git a/materialsystem/stdshaders/xbox/xbox_dbg.def b/materialsystem/stdshaders/xbox/xbox_dbg.def new file mode 100644 index 0000000..91e7e62 --- /dev/null +++ b/materialsystem/stdshaders/xbox/xbox_dbg.def @@ -0,0 +1,4 @@ +LIBRARY stdshader_dbg_360.dll +EXPORTS + CreateInterface @1 + diff --git a/materialsystem/stdshaders/xbox/xbox_dx8.def b/materialsystem/stdshaders/xbox/xbox_dx8.def new file mode 100644 index 0000000..d919b32 --- /dev/null +++ b/materialsystem/stdshaders/xbox/xbox_dx8.def @@ -0,0 +1,4 @@ +LIBRARY stdshader_dx8_360.dll +EXPORTS + CreateInterface @1 + diff --git a/materialsystem/stdshaders/xbox/xbox_dx9.def b/materialsystem/stdshaders/xbox/xbox_dx9.def new file mode 100644 index 0000000..8c86190 --- /dev/null +++ b/materialsystem/stdshaders/xbox/xbox_dx9.def @@ -0,0 +1,4 @@ +LIBRARY stdshader_dx9_360.dll +EXPORTS + CreateInterface @1 + diff --git a/materialsystem/stdshaders/yuv.cpp b/materialsystem/stdshaders/yuv.cpp new file mode 100644 index 0000000..dba70dc --- /dev/null +++ b/materialsystem/stdshaders/yuv.cpp @@ -0,0 +1,62 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//=============================================================================// + +#include "BaseVSShader.h" + +#include "screenspaceeffect.inc" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +BEGIN_VS_SHADER_FLAGS( YUV, "Help for YUV", SHADER_NOT_EDITABLE ) + BEGIN_SHADER_PARAMS + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + SET_FLAGS2( MATERIAL_VAR2_NEEDS_FULL_FRAME_BUFFER_TEXTURE ); + } + + SHADER_INIT + { + } + + SHADER_FALLBACK + { + // Requires DX8 + above + if ( IsPC() && !g_pHardwareConfig->SupportsVertexAndPixelShaders()) + { + Assert( 0 ); + return "Wireframe"; + } + return 0; + } + + SHADER_DRAW + { + SHADOW_STATE + { + pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); + pShaderShadow->VertexShaderVertexFormat( VERTEX_POSITION, 1, 0, 0 ); + + screenspaceeffect_Static_Index vshIndex; + pShaderShadow->SetVertexShader( "ScreenSpaceEffect", vshIndex.GetIndex() ); + + pShaderShadow->SetPixelShader( "YUV" ); + } + + DYNAMIC_STATE + { + pShaderAPI->BindStandardTexture( SHADER_SAMPLER0, TEXTURE_FRAME_BUFFER_FULL_TEXTURE_0 ); + + screenspaceeffect_Dynamic_Index vshIndex; + vshIndex.SetDOWATERFOG( pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z ); + pShaderAPI->SetVertexShaderIndex( vshIndex.GetIndex() ); + } + Draw(); + } +END_SHADER diff --git a/materialsystem/stdshaders/yuv.psh b/materialsystem/stdshaders/yuv.psh new file mode 100644 index 0000000..ce34ba2 --- /dev/null +++ b/materialsystem/stdshaders/yuv.psh @@ -0,0 +1,23 @@ +ps.1.1 + +;------------------------------------------------------------------------------ +; Draw a texture . . woo hoo! +; t0 - texture +; +; The texture coordinates need to be defined as follows: +; tc0 - texcoords +;------------------------------------------------------------------------------ + +def c0, 0.299f, 0.587f, 0.114f, 1.0f + +; Get the color from the texture +tex t0 + +; FIXME: This can only be implemented in dx9 (or ps1.4) +; need to output max( r, g, b ) in all channels +; Instead, I'm going to do the RGB->YUV conversion +dp3 r1, c0, t0 +mov r0.rgb, r1.a +mov r0.a, c0.a + + diff --git a/materialsystem/texturemanager.cpp b/materialsystem/texturemanager.cpp new file mode 100644 index 0000000..eb5be14 --- /dev/null +++ b/materialsystem/texturemanager.cpp @@ -0,0 +1,3102 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//===========================================================================// + +#include +#include +#include "materialsystem_global.h" +#include "string.h" +#include "shaderapi/ishaderapi.h" +#include "materialsystem/materialsystem_config.h" +#include "IHardwareConfigInternal.h" +#include "texturemanager.h" +#include "materialsystem/imaterialvar.h" +#include "materialsystem/IColorCorrection.h" +#include "tier1/strtools.h" +#include "utlvector.h" +#include "utldict.h" +#include "itextureinternal.h" +#include "vtf/vtf.h" +#include "pixelwriter.h" +#include "basetypes.h" +#include "utlbuffer.h" +#include "filesystem.h" +#include "materialsystem/imesh.h" +#include "materialsystem/ishaderapi.h" +#include "vstdlib/random.h" +#include "imorphinternal.h" +#include "tier1/utlrbtree.h" +#include "tier1/utlpair.h" +#include "ctype.h" +#include "utlqueue.h" +#include "tier0/icommandline.h" +#include "ctexturecompositor.h" + +#include "vprof_telemetry.h" + +// Need lightmaps access here +#define MATSYS_INTERNAL +#include "cmatlightmaps.h" +#include "cmaterialsystem.h" +#undef MATSYS_INTERNAL + +#include "tier0/memdbgon.h" + +#define ERROR_TEXTURE_SIZE 32 +#define WHITE_TEXTURE_SIZE 1 +#define BLACK_TEXTURE_SIZE 1 +#define GREY_TEXTURE_SIZE 1 +#define NORMALIZATION_CUBEMAP_SIZE 32 + +struct AsyncLoadJob_t; +struct AsyncReadJob_t; +class AsyncLoader; +class AsyncReader; + +#define MAX_READS_OUTSTANDING 2 + +static ImageFormat GetImageFormatRawReadback( ImageFormat fmt ); + +#ifdef STAGING_ONLY + static ConVar mat_texture_list_dump( "mat_texture_list_dump", "0" ); +#endif + +const char* cTextureCachePathDir = "__texture_cache"; + +// TODO: Relocate this somewhere else. It works like python's "strip" function, +// removing leading and trailing whitespace, including newlines. Whitespace between +// non-whitespace characters is preserved. +void V_StripWhitespace( char* pBuffer ) +{ + Assert( pBuffer ); + + char* pSrc = pBuffer; + char* pDst = pBuffer; + char* pDstFirstTrailingWhitespace = NULL; + + // Remove leading whitespace + bool leading = true; + while ( *pSrc ) + { + if ( leading ) + { + if ( V_isspace( *pSrc ) ) + { + ++pSrc; + continue; + } + else + { + leading = false; + // Drop through + } + } + + if ( pDst != pSrc ) + *pDst = *pSrc; + + if ( !leading && V_isspace( *pDst ) && pDstFirstTrailingWhitespace == NULL ) + pDstFirstTrailingWhitespace = pDst; + else if ( !leading && !V_isspace( *pDst ) && pDstFirstTrailingWhitespace != NULL ) + pDstFirstTrailingWhitespace = NULL; + + ++pSrc; + ++pDst; + } + + (*pDst) = 0; + + if ( pDstFirstTrailingWhitespace ) + ( *pDstFirstTrailingWhitespace ) = 0; +} + +//----------------------------------------------------------------------------- +// +// Various procedural texture regeneration classes +// +//----------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +// Creates a checkerboard texture +//----------------------------------------------------------------------------- +class CCheckerboardTexture : public ITextureRegenerator +{ +public: + CCheckerboardTexture( int nCheckerSize, color32 color1, color32 color2 ) : + m_nCheckerSize( nCheckerSize ), m_Color1(color1), m_Color2(color2) + { + } + + virtual ~CCheckerboardTexture() { } + + virtual void RegenerateTextureBits( ITexture *pTexture, IVTFTexture *pVTFTexture, Rect_t *pSubRect ) + { + for (int iFrame = 0; iFrame < pVTFTexture->FrameCount(); ++iFrame ) + { + for (int iFace = 0; iFace < pVTFTexture->FaceCount(); ++iFace ) + { + int nWidth = pVTFTexture->Width(); + int nHeight = pVTFTexture->Height(); + int nDepth = pVTFTexture->Depth(); + for (int z = 0; z < nDepth; ++z) + { + // Fill mip 0 with a checkerboard + CPixelWriter pixelWriter; + pixelWriter.SetPixelMemory( pVTFTexture->Format(), + pVTFTexture->ImageData( iFrame, iFace, 0, 0, 0, z ), pVTFTexture->RowSizeInBytes( 0 ) ); + + for (int y = 0; y < nHeight; ++y) + { + pixelWriter.Seek( 0, y ); + for (int x = 0; x < nWidth; ++x) + { + if ( ((x & m_nCheckerSize) ^ (y & m_nCheckerSize)) ^ (z & m_nCheckerSize) ) + { + pixelWriter.WritePixel( m_Color1.r, m_Color1.g, m_Color1.b, m_Color1.a ); + } + else + { + pixelWriter.WritePixel( m_Color2.r, m_Color2.g, m_Color2.b, m_Color2.a ); + } + } + } + } + } + } + } + + virtual void Release() + { + delete this; + } + +private: + int m_nCheckerSize; + color32 m_Color1; + color32 m_Color2; +}; + +static void CreateCheckerboardTexture( ITextureInternal *pTexture, int nCheckerSize, color32 color1, color32 color2 ) +{ + ITextureRegenerator *pRegen = new CCheckerboardTexture( nCheckerSize, color1, color2 ); + pTexture->SetTextureRegenerator( pRegen ); +} + + +//----------------------------------------------------------------------------- +// Creates a solid texture +//----------------------------------------------------------------------------- +class CSolidTexture : public ITextureRegenerator +{ +public: + CSolidTexture( color32 color ) : m_Color(color) + { + } + + virtual ~CSolidTexture() { } + + virtual void RegenerateTextureBits( ITexture *pTexture, IVTFTexture *pVTFTexture, Rect_t *pSubRect ) + { + int nMipCount = pTexture->IsMipmapped() ? pVTFTexture->MipCount() : 1; + for (int iFrame = 0; iFrame < pVTFTexture->FrameCount(); ++iFrame ) + { + for (int iFace = 0; iFace < pVTFTexture->FaceCount(); ++iFace ) + { + for (int iMip = 0; iMip < nMipCount; ++iMip ) + { + int nWidth, nHeight, nDepth; + pVTFTexture->ComputeMipLevelDimensions( iMip, &nWidth, &nHeight, &nDepth ); + for (int z = 0; z < nDepth; ++z) + { + CPixelWriter pixelWriter; + pixelWriter.SetPixelMemory( pVTFTexture->Format(), + pVTFTexture->ImageData( iFrame, iFace, iMip, 0, 0, z ), pVTFTexture->RowSizeInBytes( iMip ) ); + + for (int y = 0; y < nHeight; ++y) + { + pixelWriter.Seek( 0, y ); + for (int x = 0; x < nWidth; ++x) + { + pixelWriter.WritePixel( m_Color.r, m_Color.g, m_Color.b, m_Color.a ); + } + } + } + } + } + } + } + + virtual void Release() + { + delete this; + } + +private: + color32 m_Color; +}; + +static void CreateSolidTexture( ITextureInternal *pTexture, color32 color ) +{ + ITextureRegenerator *pRegen = new CSolidTexture( color ); + pTexture->SetTextureRegenerator( pRegen ); +} + +//----------------------------------------------------------------------------- +// Creates a normalization cubemap texture +//----------------------------------------------------------------------------- +class CNormalizationCubemap : public ITextureRegenerator +{ +public: + virtual void RegenerateTextureBits( ITexture *pTexture, IVTFTexture *pVTFTexture, Rect_t *pSubRect ) + { + // Normalization cubemap doesn't make sense on low-end hardware + // So we won't construct a spheremap out of this + CPixelWriter pixelWriter; + + Vector direction; + for (int iFace = 0; iFace < 6; ++iFace) + { + pixelWriter.SetPixelMemory( pVTFTexture->Format(), + pVTFTexture->ImageData( 0, iFace, 0 ), pVTFTexture->RowSizeInBytes( 0 ) ); + + int nWidth = pVTFTexture->Width(); + int nHeight = pVTFTexture->Height(); + + float flInvWidth = 2.0f / (float)(nWidth-1); + float flInvHeight = 2.0f / (float)(nHeight-1); + + for (int y = 0; y < nHeight; ++y) + { + float v = y * flInvHeight - 1.0f; + + pixelWriter.Seek( 0, y ); + for (int x = 0; x < nWidth; ++x) + { + float u = x * flInvWidth - 1.0f; + float oow = 1.0f / sqrt( 1.0f + u*u + v*v ); + + int ix = (int)(255.0f * 0.5f * (u*oow + 1.0f) + 0.5f); + ix = clamp( ix, 0, 255 ); + int iy = (int)(255.0f * 0.5f * (v*oow + 1.0f) + 0.5f); + iy = clamp( iy, 0, 255 ); + int iz = (int)(255.0f * 0.5f * (oow + 1.0f) + 0.5f); + iz = clamp( iz, 0, 255 ); + + switch (iFace) + { + case CUBEMAP_FACE_RIGHT: + pixelWriter.WritePixel( iz, 255 - iy, 255 - ix, 255 ); + break; + case CUBEMAP_FACE_LEFT: + pixelWriter.WritePixel( 255 - iz, 255 - iy, ix, 255 ); + break; + case CUBEMAP_FACE_BACK: + pixelWriter.WritePixel( ix, iz, iy, 255 ); + break; + case CUBEMAP_FACE_FRONT: + pixelWriter.WritePixel( ix, 255 - iz, 255 - iy, 255 ); + break; + case CUBEMAP_FACE_UP: + pixelWriter.WritePixel( ix, 255 - iy, iz, 255 ); + break; + case CUBEMAP_FACE_DOWN: + pixelWriter.WritePixel( 255 - ix, 255 - iy, 255 - iz, 255 ); + break; + default: + break; + } + } + } + } + } + + // NOTE: The normalization cubemap regenerator is stateless + // so there's no need to allocate + deallocate them + virtual void Release() {} +}; + +//----------------------------------------------------------------------------- +// Creates a normalization cubemap texture +//----------------------------------------------------------------------------- +class CSignedNormalizationCubemap : public ITextureRegenerator +{ +public: + virtual void RegenerateTextureBits( ITexture *pTexture, IVTFTexture *pVTFTexture, Rect_t *pSubRect ) + { + // Normalization cubemap doesn't make sense on low-end hardware + // So we won't construct a spheremap out of this + CPixelWriter pixelWriter; + + Vector direction; + for (int iFace = 0; iFace < 6; ++iFace) + { + pixelWriter.SetPixelMemory( pVTFTexture->Format(), + pVTFTexture->ImageData( 0, iFace, 0 ), pVTFTexture->RowSizeInBytes( 0 ) ); + + int nWidth = pVTFTexture->Width(); + int nHeight = pVTFTexture->Height(); + + float flInvWidth = 2.0f / (float)(nWidth-1); + float flInvHeight = 2.0f / (float)(nHeight-1); + + for (int y = 0; y < nHeight; ++y) + { + float v = y * flInvHeight - 1.0f; + + pixelWriter.Seek( 0, y ); + for (int x = 0; x < nWidth; ++x) + { + float u = x * flInvWidth - 1.0f; + float oow = 1.0f / sqrt( 1.0f + u*u + v*v ); + +#ifdef DX_TO_GL_ABSTRACTION + float flX = (255.0f * 0.5 * (u*oow + 1.0f) + 0.5f); + float flY = (255.0f * 0.5 * (v*oow + 1.0f) + 0.5f); + float flZ = (255.0f * 0.5 * (oow + 1.0f) + 0.5f); + + switch (iFace) + { + case CUBEMAP_FACE_RIGHT: + flX = 255.0f - flX; + flY = 255.0f - flY; + break; + case CUBEMAP_FACE_LEFT: + flY = 255.0f - flY; + flZ = 255.0f - flZ; + break; + case CUBEMAP_FACE_BACK: + break; + case CUBEMAP_FACE_FRONT: + flY = 255.0f - flY; + flZ = 255.0f - flZ; + break; + case CUBEMAP_FACE_UP: + flY = 255.0f - flY; + break; + case CUBEMAP_FACE_DOWN: + flX = 255.0f - flX; + flY = 255.0f - flY; + flZ = 255.0f - flZ; + break; + default: + break; + } + + flX -= 128.0f; + flY -= 128.0f; + flZ -= 128.0f; + + flX /= 128.0f; + flY /= 128.0f; + flZ /= 128.0f; + + switch ( iFace ) + { + case CUBEMAP_FACE_RIGHT: + pixelWriter.WritePixelF( flZ, flY, flX, 0.0f ); + break; + case CUBEMAP_FACE_LEFT: + pixelWriter.WritePixelF( flZ, flY, flX, 0.0f ); + break; + case CUBEMAP_FACE_BACK: + pixelWriter.WritePixelF( flX, flZ, flY, 0.0f ); + break; + case CUBEMAP_FACE_FRONT: + pixelWriter.WritePixelF( flX, flZ, flY, 0.0f ); + break; + case CUBEMAP_FACE_UP: + pixelWriter.WritePixelF( flX, flY, flZ, 0.0f ); + break; + case CUBEMAP_FACE_DOWN: + pixelWriter.WritePixelF( flX, flY, flZ, 0.0f ); + break; + default: + break; + } +#else + int ix = (int)(255 * 0.5 * (u*oow + 1.0f) + 0.5f); + ix = clamp( ix, 0, 255 ); + int iy = (int)(255 * 0.5 * (v*oow + 1.0f) + 0.5f); + iy = clamp( iy, 0, 255 ); + int iz = (int)(255 * 0.5 * (oow + 1.0f) + 0.5f); + iz = clamp( iz, 0, 255 ); + + switch (iFace) + { + case CUBEMAP_FACE_RIGHT: + ix = 255 - ix; + iy = 255 - iy; + break; + case CUBEMAP_FACE_LEFT: + iy = 255 - iy; + iz = 255 - iz; + break; + case CUBEMAP_FACE_BACK: + break; + case CUBEMAP_FACE_FRONT: + iy = 255 - iy; + iz = 255 - iz; + break; + case CUBEMAP_FACE_UP: + iy = 255 - iy; + break; + case CUBEMAP_FACE_DOWN: + ix = 255 - ix; + iy = 255 - iy; + iz = 255 - iz; + break; + default: + break; + } + + ix -= 128; + iy -= 128; + iz -= 128; + + Assert( ix >= -128 && ix <= 127 ); + Assert( iy >= -128 && iy <= 127 ); + Assert( iz >= -128 && iz <= 127 ); + + switch (iFace) + { + case CUBEMAP_FACE_RIGHT: + // correct +// pixelWriter.WritePixelSigned( -128, -128, -128, 0 ); + pixelWriter.WritePixelSigned( iz, iy, ix, 0 ); + break; + case CUBEMAP_FACE_LEFT: + // correct +// pixelWriter.WritePixelSigned( -128, -128, -128, 0 ); + pixelWriter.WritePixelSigned( iz, iy, ix, 0 ); + break; + case CUBEMAP_FACE_BACK: + // wrong +// pixelWriter.WritePixelSigned( -128, -128, -128, 0 ); + pixelWriter.WritePixelSigned( ix, iz, iy, 0 ); +// pixelWriter.WritePixelSigned( -127, -127, 127, 0 ); + break; + case CUBEMAP_FACE_FRONT: + // wrong +// pixelWriter.WritePixelSigned( -128, -128, -128, 0 ); + pixelWriter.WritePixelSigned( ix, iz, iy, 0 ); + break; + case CUBEMAP_FACE_UP: + // correct +// pixelWriter.WritePixelSigned( -128, -128, -128, 0 ); + pixelWriter.WritePixelSigned( ix, iy, iz, 0 ); + break; + case CUBEMAP_FACE_DOWN: + // correct +// pixelWriter.WritePixelSigned( -128, -128, -128, 0 ); + pixelWriter.WritePixelSigned( ix, iy, iz, 0 ); + break; + default: + break; + } +#endif + } // x + } // y + } // iFace + } + + // NOTE: The normalization cubemap regenerator is stateless + // so there's no need to allocate + deallocate them + virtual void Release() {} +}; + +static void CreateNormalizationCubemap( ITextureInternal *pTexture ) +{ + // NOTE: The normalization cubemap regenerator is stateless + // so there's no need to allocate + deallocate them + static CNormalizationCubemap s_NormalizationCubemap; + pTexture->SetTextureRegenerator( &s_NormalizationCubemap ); +} + +static void CreateSignedNormalizationCubemap( ITextureInternal *pTexture ) +{ + // NOTE: The normalization cubemap regenerator is stateless + // so there's no need to allocate + deallocate them + static CSignedNormalizationCubemap s_SignedNormalizationCubemap; + pTexture->SetTextureRegenerator( &s_SignedNormalizationCubemap ); +} + +//----------------------------------------------------------------------------- +// Creates a color correction texture +//----------------------------------------------------------------------------- +class CColorCorrectionTexture : public ITextureRegenerator +{ +public: + CColorCorrectionTexture( ColorCorrectionHandle_t handle ) : m_ColorCorrectionHandle(handle) + { + } + + virtual ~CColorCorrectionTexture() { } + + virtual void RegenerateTextureBits( ITexture *pTexture, IVTFTexture *pVTFTexture, Rect_t *pSubRect ) + { + int nWidth = pVTFTexture->Width(); + int nHeight = pVTFTexture->Height(); + int nDepth = pVTFTexture->Depth(); + Assert( nWidth == COLOR_CORRECTION_TEXTURE_SIZE && nHeight == COLOR_CORRECTION_TEXTURE_SIZE && nDepth == COLOR_CORRECTION_TEXTURE_SIZE ); + + for ( int z = 0; z < nDepth; ++z ) + { + CPixelWriter pixelWriter; + pixelWriter.SetPixelMemory( pVTFTexture->Format(), + pVTFTexture->ImageData( 0, 0, 0, 0, 0, z ), pVTFTexture->RowSizeInBytes( 0 ) ); + + for ( int y = 0; y < nHeight; ++y ) + { + pixelWriter.Seek( 0, y ); + for (int x = 0; x < nWidth; ++x) + { + RGBX5551_t inColor; + inColor.r = x; + inColor.g = y; + inColor.b = z; + + color24 col = ColorCorrectionSystem()->GetLookup( m_ColorCorrectionHandle, inColor ); + pixelWriter.WritePixel( col.r, col.g, col.b, 255 ); + } + } + } + } + + virtual void Release() + { + delete this; + } + +private: + ColorCorrectionHandle_t m_ColorCorrectionHandle; +}; + + +void CreateColorCorrectionTexture( ITextureInternal *pTexture, ColorCorrectionHandle_t handle ) +{ + ITextureRegenerator *pRegen = new CColorCorrectionTexture( handle ); + pTexture->SetTextureRegenerator( pRegen ); +} + +//----------------------------------------------------------------------------- +// Implementation of the texture manager +//----------------------------------------------------------------------------- +class CTextureManager : public ITextureManager +{ +public: + CTextureManager( void ); + + // Initialization + shutdown + virtual void Init( int nFlags ) OVERRIDE; + virtual void Shutdown(); + + virtual void AllocateStandardRenderTargets( ); + virtual void FreeStandardRenderTargets(); + + virtual void CacheExternalStandardRenderTargets(); + + virtual ITextureInternal *CreateProceduralTexture( const char *pTextureName, const char *pTextureGroupName, int w, int h, int d, ImageFormat fmt, int nFlags, ITextureRegenerator* generator = NULL ); + virtual ITextureInternal *FindOrLoadTexture( const char *textureName, const char *pTextureGroupName, int nAdditionalCreationFlags = 0 ); + virtual bool IsTextureLoaded( const char *pTextureName ); + + virtual void AddTextureAlias( const char *pAlias, const char *pRealName ); + virtual void RemoveTextureAlias( const char *pAlias ); + + virtual void SetExcludedTextures( const char *pScriptName ); + virtual void UpdateExcludedTextures(); + + virtual void ResetTextureFilteringState(); + void ReloadTextures( void ); + + // These are used when we lose our video memory due to a mode switch etc + void ReleaseTextures( void ); + void RestoreNonRenderTargetTextures( void ); + void RestoreRenderTargets( void ); + + // Suspend or resume texture streaming requests + void SuspendTextureStreaming( void ); + void ResumeTextureStreaming( void ); + + // delete any texture that has a refcount <= 0 + void RemoveUnusedTextures( void ); + void DebugPrintUsedTextures( void ); + + // Request a texture ID + virtual int RequestNextTextureID(); + + // Get at a couple standard textures + virtual ITextureInternal *ErrorTexture(); + virtual ITextureInternal *NormalizationCubemap(); + virtual ITextureInternal *SignedNormalizationCubemap(); + virtual ITextureInternal *ShadowNoise2D(); + virtual ITextureInternal *IdentityLightWarp(); + virtual ITextureInternal *ColorCorrectionTexture( int i ); + virtual ITextureInternal *FullFrameDepthTexture(); + virtual ITextureInternal *DebugLuxels2D(); + + + // Generates an error texture pattern + virtual void GenerateErrorTexture( ITexture *pTexture, IVTFTexture *pVTFTexture ); + + // Updates the color correction state + virtual void SetColorCorrectionTexture( int i, ITextureInternal *pTexture ); + + virtual void ForceAllTexturesIntoHardware( void ); + + virtual ITextureInternal *CreateRenderTargetTexture( + const char *pRTName, // NULL for auto-generated name + int w, + int h, + RenderTargetSizeMode_t sizeMode, + ImageFormat fmt, + RenderTargetType_t type, + unsigned int textureFlags, + unsigned int renderTargetFlags ); + + virtual bool HasPendingTextureDestroys() const; + virtual void MarkUnreferencedTextureForCleanup( ITextureInternal *pTexture ); + virtual void RemoveTexture( ITextureInternal *pTexture ); + virtual void ReloadFilesInList( IFileList *pFilesToReload ); + + // start with -1, list terminates with -1 + virtual int FindNext( int iIndex, ITextureInternal **ppTexture ); + + virtual void ReleaseTempRenderTargetBits( void ); + + // Called once per frame by material system "somewhere." + virtual void Update(); + + // Load a texture asynchronously and then call the provided callback. + virtual void AsyncFindOrLoadTexture( const char *pTextureName, const char *pTextureGroupName, IAsyncTextureOperationReceiver* pRecipient, void* pExtraArgs, bool bComplain, int nAdditionalCreationFlags ); + void CompleteAsyncLoad( AsyncLoadJob_t* pJob ); + + virtual void AsyncCreateTextureFromRenderTarget( ITexture* pSrcRt, const char* pDstName, ImageFormat dstFmt, bool bGenMips, int nAdditionalCreationFlags, IAsyncTextureOperationReceiver* pRecipient, void* pExtraArgs ); + void CompleteAsyncRead( AsyncReadJob_t* pJob ); + + ITextureInternal* AcquireReadbackTexture( int w, int h, ImageFormat fmt ); + void ReleaseReadbackTexture( ITextureInternal* pTex ); + + void WarmTextureCache(); + void CoolTextureCache(); + + virtual void RequestAllMipmaps( ITextureInternal* pTex ); + virtual void EvictAllTextures(); + virtual void UpdatePostAsync(); + + virtual void ReleaseAsyncScratchVTF( IVTFTexture* pScratchVTF ); + + virtual bool ThreadInAsyncLoadThread() const; + virtual bool ThreadInAsyncReadThread() const; + + virtual bool AddTextureCompositorTemplate( const char* pName, KeyValues* pTmplDesc ) OVERRIDE; + virtual bool VerifyTextureCompositorTemplates() OVERRIDE; + + virtual CTextureCompositorTemplate* FindTextureCompositorTemplate( const char* pName ) OVERRIDE; + +protected: + ITextureInternal *FindTexture( const char *textureName ); + ITextureInternal *LoadTexture( const char *textureName, const char *pTextureGroupName, int nAdditionalCreationFlags = 0, bool bDownload = true ); + + void AsyncLoad( const AsyncLoadJob_t& job ); + void AsyncReadTexture( AsyncReadJob_t* job ); + + // Restores a single texture + void RestoreTexture( ITextureInternal* pTex ); + + void CleanupPossiblyUnreferencedTextures(); + +#ifdef STAGING_ONLY + void DumpTextureList( ); +#endif + + void FindFilesToLoad( CUtlDict< int >* pOutFilesToLoad, const char* pFilename ); + void ReadFilesToLoad( CUtlDict< int >* pOutFilesToLoad, const char* pFilename ); + + CUtlDict< ITextureInternal *, unsigned short > m_TextureList; + CUtlDict< const char *, unsigned short > m_TextureAliases; + CUtlDict< int, unsigned short > m_TextureExcludes; + CUtlDict< CCopyableUtlVector > m_PendingAsyncLoads; + CUtlVector< ITextureInternal* > m_ReadbackTextures; + CUtlVector< ITextureInternal* > m_preloadedTextures; + CUtlMap< ITextureInternal*, int > m_textureStreamingRequests; + CTSQueue< ITextureInternal* > m_asyncStreamingRequests; + CTSQueue< ITextureInternal * > m_PossiblyUnreferencedTextures; + + CUtlDict< CTextureCompositorTemplate *, unsigned short > m_TexCompTemplates; + + + int m_iNextTexID; + int m_nFlags; + + ITextureInternal *m_pErrorTexture; + ITextureInternal *m_pBlackTexture; + ITextureInternal *m_pWhiteTexture; + ITextureInternal *m_pGreyTexture; + ITextureInternal *m_pGreyAlphaZeroTexture; + ITextureInternal *m_pNormalizationCubemap; + ITextureInternal *m_pFullScreenTexture; + ITextureInternal *m_pSignedNormalizationCubemap; + ITextureInternal *m_pShadowNoise2D; + ITextureInternal *m_pIdentityLightWarp; + ITextureInternal *m_pColorCorrectionTextures[ COLOR_CORRECTION_MAX_TEXTURES ]; + ITextureInternal *m_pFullScreenDepthTexture; + ITextureInternal *m_pDebugLuxels2D; + + // Used to generate various error texture patterns when necessary + CCheckerboardTexture *m_pErrorRegen; + + friend class AsyncLoader; + AsyncLoader* m_pAsyncLoader; + + friend class AsyncReader; + AsyncReader* m_pAsyncReader; + + uint m_nAsyncLoadThread; + uint m_nAsyncReadThread; + + int m_iSuspendTextureStreaming; +}; + + +//----------------------------------------------------------------------------- +// Singleton instance +//----------------------------------------------------------------------------- +static CTextureManager s_TextureManager; +ITextureManager *g_pTextureManager = &s_TextureManager; + +struct AsyncLoadJob_t +{ + CUtlString m_TextureName; + CUtlString m_TextureGroupName; + IAsyncTextureOperationReceiver* m_pRecipient; + void* m_pExtraArgs; + bool m_bComplain; + int m_nAdditionalCreationFlags; + ITextureInternal* m_pResultData; + + AsyncLoadJob_t() + : m_pRecipient( NULL ) + , m_pExtraArgs( NULL ) + , m_bComplain( false ) + , m_nAdditionalCreationFlags( 0 ) + , m_pResultData( NULL ) + { } + + AsyncLoadJob_t( const char *pTextureName, const char *pTextureGroupName, IAsyncTextureOperationReceiver* pRecipient, void* pExtraArgs, bool bComplain, int nAdditionalCreationFlags ) + : m_TextureName( pTextureName ) + , m_TextureGroupName( pTextureGroupName ) + , m_pRecipient( pRecipient ) + , m_pExtraArgs( pExtraArgs ) + , m_bComplain( bComplain ) + , m_nAdditionalCreationFlags( nAdditionalCreationFlags ) + , m_pResultData( NULL ) + { + + } +}; + + +class CAsyncCopyRequest : public IAsyncTextureOperationReceiver +{ +public: + CAsyncCopyRequest() + : m_nReferenceCount( 0 ) + , m_bSignalled( false ) + { } + + virtual ~CAsyncCopyRequest() { } + + virtual int AddRef() OVERRIDE{ return ++m_nReferenceCount; } + virtual int Release() OVERRIDE + { + int retVal = --m_nReferenceCount; + if ( retVal == 0 ) + delete this; + + return retVal; + } + + virtual int GetRefCount() const OVERRIDE{ return m_nReferenceCount; } + + virtual void OnAsyncCreateComplete( ITexture* pTex, void* pExtraArgs ) OVERRIDE { } + virtual void OnAsyncFindComplete( ITexture* pTex, void* pExtraArgs ) OVERRIDE { } + virtual void OnAsyncMapComplete( ITexture* pTex, void* pExtraArgs, void* pMemory, int nPitch ) OVERRIDE { } + virtual void OnAsyncReadbackBegin( ITexture* pDst, ITexture* pSrc, void* pExtraArgs ) OVERRIDE + { + m_bSignalled = true; + } + + bool IsSignalled() const { return m_bSignalled; } + +private: + CInterlockedInt m_nReferenceCount; + volatile bool m_bSignalled; +}; + +class CAsyncMapResult : public IAsyncTextureOperationReceiver +{ +public: + CAsyncMapResult( ITextureInternal* pTex ) + : m_pTexToMap( pTex ) + , m_nReferenceCount( 0 ) + , m_pMemory( NULL ) + , m_nPitch( 0 ) + , m_bSignalled( false ) + { } + + virtual ~CAsyncMapResult() { } + + virtual int AddRef() OVERRIDE { return ++m_nReferenceCount; } + virtual int Release() OVERRIDE + { + int retVal = --m_nReferenceCount; + if ( retVal == 0 ) + delete this; + + return retVal; + } + + virtual int GetRefCount() const OVERRIDE{ return m_nReferenceCount; } + + virtual void OnAsyncCreateComplete( ITexture* pTex, void* pExtraArgs ) OVERRIDE { } + virtual void OnAsyncFindComplete( ITexture* pTex, void* pExtraArgs ) OVERRIDE { } + virtual void OnAsyncMapComplete( ITexture* pTex, void* pExtraArgs, void* pMemory, int nPitch ) OVERRIDE + { + Assert( pTex == m_pTexToMap ); + m_pMemory = pMemory; + m_nPitch = nPitch; + m_bSignalled = true; + } + + virtual void OnAsyncReadbackBegin( ITexture* pDst, ITexture* pSrc, void* pExtraArgs ) OVERRIDE { } + + + bool IsSignalled() const { return m_bSignalled; } + + ITextureInternal* const m_pTexToMap; + CInterlockedInt m_nReferenceCount; + volatile void* m_pMemory; + volatile int m_nPitch; + +private: + volatile bool m_bSignalled; +}; + +struct AsyncReadJob_t +{ + ITexture* m_pSrcRt; + ITextureInternal* m_pSysmemTex; + CAsyncCopyRequest* m_pAsyncRead; + CAsyncMapResult* m_pAsyncMap; + const char* m_pDstName; + ImageFormat m_dstFmt; + bool m_bGenMips; + int m_nAdditionalCreationFlags; + IAsyncTextureOperationReceiver* m_pRecipient; + void* m_pExtraArgs; + + CUtlMemory m_finalTexelData; + + AsyncReadJob_t() + : m_pSrcRt( NULL ) + , m_pSysmemTex( NULL ) + , m_pAsyncRead( NULL ) + , m_pAsyncMap( NULL ) + , m_pDstName( NULL ) + , m_dstFmt( IMAGE_FORMAT_UNKNOWN ) + , m_bGenMips( false ) + , m_nAdditionalCreationFlags( 0 ) + , m_pRecipient( NULL ) + , m_pExtraArgs( NULL ) + { } + + AsyncReadJob_t( ITexture* pSrcRt, const char* pDstName, ImageFormat dstFmt, bool bGenMips, int nAdditionalCreationFlags, IAsyncTextureOperationReceiver* pRecipient, void* pExtraArgs ) + : m_pSrcRt( pSrcRt ) + , m_pSysmemTex( NULL ) + , m_pAsyncRead( NULL ) + , m_pAsyncMap( NULL ) + , m_pDstName( pDstName ) // We take ownership of this string. + , m_dstFmt( dstFmt ) + , m_bGenMips( bGenMips ) + , m_nAdditionalCreationFlags( nAdditionalCreationFlags ) + , m_pRecipient( pRecipient ) + , m_pExtraArgs( pExtraArgs ) + { + + } + + ~AsyncReadJob_t() + { + Assert( ThreadInMainThread() ); + + delete [] m_pDstName; + + SafeRelease( &m_pRecipient ); + + if ( m_pSysmemTex ) + { + if ( m_pAsyncMap ) + { + extern CMaterialSystem g_MaterialSystem; + g_MaterialSystem.GetRenderContextInternal()->AsyncUnmap( m_pSysmemTex ); + } + + assert_cast< CTextureManager* >( g_pTextureManager )->ReleaseReadbackTexture( m_pSysmemTex ); + m_pSysmemTex = NULL; + } + + SafeRelease( &m_pAsyncMap ); + } + +}; + +bool IsJobCancelled( AsyncReadJob_t* pJob ) +{ + Assert( pJob != NULL ); + + // The texture manager holds a reference to the object, so if we're the only one who is holding a ref + // then the job has been abandoned. This gives us the opportunity to cleanup and skip some work. + if ( pJob->m_pRecipient->GetRefCount() == 1 ) + { + return true; + } + + return false; +} + +bool IsJobCancelled( AsyncLoadJob_t* pJob ) +{ + Assert( pJob != NULL ); + + // The texture manager holds a reference to the object, so if we're the only one who is holding a ref + // then the job has been abandoned. This gives us the opportunity to cleanup and skip some work. + if ( pJob->m_pRecipient->GetRefCount() == 1 ) + { + return true; + } + + return false; +} + +//----------------------------------------------------------------------------- +// Functions can be called from any thread, unless they are prefixed with a thread name. +class AsyncLoader +{ +public: + AsyncLoader() + : m_bQuit( false ) + { + for ( int i = 0; i < MAX_READS_OUTSTANDING; ++i ) + { + m_asyncScratchVTFs.PushItem( CreateVTFTexture() ); + } + + // Do this after everything else. + m_LoaderThread = CreateSimpleThread( AsyncLoader::LoaderMain, this ); + } + + ~AsyncLoader() + { + Assert( m_asyncScratchVTFs.Count() == MAX_READS_OUTSTANDING ); + while ( m_asyncScratchVTFs.Count() > 0 ) + { + IVTFTexture* pScratchVTF = NULL; + m_asyncScratchVTFs.PopItem( &pScratchVTF ); + delete pScratchVTF; + } + } + + void AsyncLoad( const AsyncLoadJob_t& job ) + { + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s", __FUNCTION__ ); + + // TODO: This could be made faster by keeping a pool of these things. + m_pendingJobs.PushItem( new AsyncLoadJob_t( job ) ); + } + + void Shutdown() + { + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s", __FUNCTION__ ); + + m_bQuit = true; + ThreadJoin( m_LoaderThread ); + } + + void ThreadMain_Update() + { + Assert( ThreadInMainThread() ); + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s", __FUNCTION__ ); + + AsyncLoadJob_t *pJob = NULL; + if ( m_completedJobs.PopItem( &pJob ) ) + { + Assert( pJob != NULL ); + + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s - CompleteAsyncLoad", __FUNCTION__ ); + // Complete the load, then make the callback. + assert_cast< CTextureManager* >( g_pTextureManager )->CompleteAsyncLoad( pJob ); + delete pJob; + pJob = NULL; + } + } + + void ReleaseAsyncReadBuffer( IVTFTexture *pScratchVTF ) + { + Assert( pScratchVTF != NULL ); + m_asyncScratchVTFs.PushItem( pScratchVTF ); + } + +private: + inline bool ThreadInLoaderThread() + { + return s_TextureManager.ThreadInAsyncLoadThread(); + } + + void ThreadLoader_Main( ) + { + Assert( ThreadInLoaderThread() ); + + while ( !m_bQuit ) + { + AsyncLoadJob_t *pJob = NULL; + IVTFTexture *pScratchVTF = NULL; + while ( !m_pendingJobs.PopItem( &pJob ) ) + { + // "awhile" + ThreadSleep( 8 ); + if ( m_bQuit ) + return; + } + Assert( pJob != NULL ); + + while ( !m_asyncScratchVTFs.PopItem( &pScratchVTF ) ) + { + // Also awhile, but not as long.. + ThreadSleep( 4 ); + if ( m_bQuit ) + return; + } + Assert( pScratchVTF != NULL ); + + ThreadLoader_ProcessLoad( pJob, pScratchVTF ); + } + } + + void ThreadLoader_ProcessLoad( AsyncLoadJob_t *pJob, IVTFTexture* pScratchVTF ) + { + Assert( ThreadInLoaderThread() ); + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s", __FUNCTION__ ); + + Assert( pJob->m_pResultData ); + + if ( !pJob->m_pResultData->AsyncReadTextureFromFile( pScratchVTF, pJob->m_nAdditionalCreationFlags ) ) + m_asyncScratchVTFs.PushItem( pScratchVTF ); + + m_completedJobs.PushItem( pJob ); + } + + static unsigned LoaderMain( void* _this ) + { + ThreadSetDebugName( "Loader" ); + + s_TextureManager.m_nAsyncLoadThread = ThreadGetCurrentId(); + ( ( AsyncLoader* )_this )->ThreadLoader_Main(); + s_TextureManager.m_nAsyncLoadThread = 0xFFFFFFFF; + return 0; + } + + ThreadHandle_t m_LoaderThread; + volatile bool m_bQuit; + + CTSQueue< AsyncLoadJob_t *> m_pendingJobs; + CTSQueue< AsyncLoadJob_t *> m_completedJobs; + CTSQueue< IVTFTexture *> m_asyncScratchVTFs; +}; + +//----------------------------------------------------------------------------- +// Functions can be called from any thread, unless they are prefixed with a thread name. +class AsyncReader +{ +public: + AsyncReader() + : m_bQuit( false ) + { + + // Do this after everything else. + m_HelperThread = CreateSimpleThread( AsyncReader::ReaderMain, this ); + } + + void AsyncReadback( AsyncReadJob_t* job ) + { + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s", __FUNCTION__ ); + + m_requestedCopies.PushItem( job ); + } + + void Shutdown() + { + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s", __FUNCTION__ ); + + m_bQuit = true; + ThreadJoin( m_HelperThread ); + } + + void ThreadMain_Update() + { + Assert( ThreadInMainThread() ); + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s", __FUNCTION__ ); + + while ( !m_queuedMaps.IsEmpty() ) + { + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "CompleteMap" ); + AsyncReadJob_t* pMapped = m_queuedMaps.Head(); + Assert( pMapped != NULL ); + { + if ( IsJobCancelled( pMapped ) ) + { + // Remove the head, which is pMapped + m_queuedMaps.RemoveAtHead(); + delete pMapped; + continue; + } + + if ( pMapped->m_pAsyncMap->IsSignalled() ) + { + if ( pMapped->m_pAsyncMap->m_pMemory != 0 && pMapped->m_pAsyncMap->m_nPitch != 0 ) + { + // Stick it in the queue for the other thread to work on it. + m_pendingJobs.PushItem( pMapped ); + } + else + { + Assert( !"Failed to perform a map that shouldn't fail, need to deal with this if it ever happens." ); + DevWarning( "Failed to perform a map that shouldn't fail, need to deal with this if it ever happens." ); + } + + // Remove the head, which is pMapped + m_queuedMaps.RemoveAtHead(); + } + + // Stop as soon as we complete one, regardless of success. + break; + } + + } + + // This is ugly, but basically we need to do map and unmap on the main thread. Other + // stuff can (mostly) happen on the async thread + while ( !m_queuedReads.IsEmpty() ) + { + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "CompleteQueuedRead" ); + + AsyncReadJob_t* pRead = NULL; + if ( m_queuedReads.RemoveAtHead( pRead ) ) + { + if ( IsJobCancelled( pRead ) ) + { + delete pRead; + continue; + } + + SafeAssign( &pRead->m_pAsyncMap, new CAsyncMapResult( pRead->m_pSysmemTex ) ); + // Trigger the map. + extern CMaterialSystem g_MaterialSystem; + g_MaterialSystem.GetRenderContextInternal()->AsyncMap( pRead->m_pSysmemTex, pRead->m_pAsyncMap, NULL ); + m_queuedMaps.Insert( pRead ); + + // Stop as soon as we complete one successfully. + break; + } + } + + if ( !m_scheduledReads.IsEmpty() ) + { + if ( m_scheduledReads.Head()->m_pAsyncRead->IsSignalled() ) + { + AsyncReadJob_t* pScheduledRead = m_scheduledReads.RemoveAtHead(); + SafeRelease( &pScheduledRead->m_pAsyncRead ); + + m_queuedReads.Insert( pScheduledRead ); + } + } + + AsyncReadJob_t* pRequestCopy = NULL; + if ( m_requestedCopies.PopItem( &pRequestCopy ) ) + { + SafeAssign( &pRequestCopy->m_pAsyncRead, new CAsyncCopyRequest ); + extern CMaterialSystem g_MaterialSystem; + g_MaterialSystem.GetRenderContextInternal()->AsyncCopyRenderTargetToStagingTexture( pRequestCopy->m_pSysmemTex, pRequestCopy->m_pSrcRt, pRequestCopy->m_pAsyncRead, NULL ); + + m_scheduledReads.Insert( pRequestCopy ); + } + + while ( m_completedJobs.Count() > 0 ) + { + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "CreateTextureFromBits" ); + + AsyncReadJob_t* pCreate = NULL; + if ( m_completedJobs.PopItem( &pCreate ) ) + { + // Check after we do the unmap, we need to do that here. + if ( IsJobCancelled( pCreate ) ) + { + delete pCreate; + continue; + } + + extern CMaterialSystem g_MaterialSystem; + g_MaterialSystem.GetRenderContextInternal()->AsyncUnmap( pCreate->m_pSysmemTex ); + SafeRelease( &pCreate->m_pAsyncMap ); + + assert_cast< CTextureManager* >( g_pTextureManager )->CompleteAsyncRead( pCreate ); + delete pCreate; + pCreate = NULL; + // Stop as soon as we complete one successfully. + break; + } + } + } + +private: + inline bool ThreadInReaderThread() + { + return s_TextureManager.ThreadInAsyncReadThread(); + } + + void ThreadReader_Main() + { + Assert( ThreadInReaderThread() ); + + while ( !m_bQuit ) + { + AsyncReadJob_t *pJob = NULL; + if ( m_pendingJobs.PopItem( &pJob ) ) + { + Assert( pJob != NULL ); + ThreadReader_ProcessRead( pJob ); + } + else + { + // "awhile" + ThreadSleep( 8 ); + } + } + } + + void ThreadReader_ProcessRead( AsyncReadJob_t *pJob ) + { + Assert( ThreadInReaderThread() ); + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s", __FUNCTION__ ); + + // This code does a few things: + // 1. Reads from a previously mapped scratch buffer texture and performs byte swapping (if necessary). + // 2. Uses byteswapped data to generate mipmaps + // 3. Encodes mipmapped data into the destination format. + + const int h = pJob->m_pSysmemTex->GetActualHeight(); + const int w = pJob->m_pSysmemTex->GetActualWidth(); + const ImageFormat srcFmt = pJob->m_pSysmemTex->GetImageFormat(); + + // Convert the data + CUtlMemory< unsigned char > srcBufferFinestMip; + CUtlMemory< unsigned char > srcBufferAllMips; + const int srcFinestMemRequired = ImageLoader::GetMemRequired( w, h, 1, srcFmt, false ); + const int srcAllMemRequired = ImageLoader::GetMemRequired( w, h, 1, srcFmt, pJob->m_bGenMips ); + const int srcPitch = ImageLoader::GetMemRequired( w, 1, 1, srcFmt, false ); + + const ImageFormat dstFmt = pJob->m_dstFmt; + CUtlMemory< unsigned char > dstBufferAllMips; + const int dstMemRequried = ImageLoader::GetMemRequired( w, h, 1, dstFmt, pJob->m_bGenMips ); + + { + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s-Allocations", __FUNCTION__ ); + srcBufferFinestMip.EnsureCapacity( srcFinestMemRequired ); + if ( srcFinestMemRequired != srcAllMemRequired ) + { + srcBufferAllMips.EnsureCapacity( srcAllMemRequired ); + } + else + { + Assert( !pJob->m_bGenMips ); + } + + if ( srcFmt != dstFmt ) + { + dstBufferAllMips.EnsureCapacity( dstMemRequried ); + } + } + + // If this fires, you will get data corruption below. We can fix this case, it just doesn't seem + // to be needed right now. + Assert( pJob->m_pAsyncMap->m_nPitch == srcPitch ); + srcPitch; // Hush compiler. + + { + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s-ByteSwapInPlace", __FUNCTION__ ); + ImageLoader::ConvertImageFormat( (unsigned char*) pJob->m_pAsyncMap->m_pMemory, GetImageFormatRawReadback( srcFmt ), srcBufferFinestMip.Base(), srcFmt, w, h ); + } + + if ( pJob->m_bGenMips ) + { + GenerateMipmaps( &srcBufferAllMips, srcBufferFinestMip.Base(), w, h, srcFmt ); + } + else + { + // If we're not generating mips, then allmips == finest mip, but the code below expects everything to + // be in all mips. + srcBufferAllMips.Swap( srcBufferFinestMip ); + } + + // Code below expects that the data is here one way or another. + Assert( srcBufferAllMips.Count() == srcAllMemRequired ); + + if ( srcFmt != dstFmt ) + { + ConvertTexelData( &dstBufferAllMips, dstFmt, srcBufferAllMips, w, h, srcFmt, pJob->m_bGenMips ); + pJob->m_finalTexelData.Swap( dstBufferAllMips ); + } + else + { + // Just swap out the buffers. + pJob->m_finalTexelData.Swap( srcBufferAllMips ); + } + + // At this point, the data should be ready to go. Quick sanity check. + Assert( pJob->m_finalTexelData.Count() == dstMemRequried ); + + m_completedJobs.PushItem( pJob ); + } + + void GenerateMipmaps( CUtlMemory< unsigned char >* outBuffer, unsigned char* pSrc, int w, int h, ImageFormat fmt ) const + { + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s", __FUNCTION__ ); + + ImageLoader::GenerateMipmapLevelsLQ( pSrc, outBuffer->Base(), w, h, fmt, 0 ); + } + + void ConvertTexelData( CUtlMemory< unsigned char > *outBuffer, ImageFormat dstFmt, /* const */ CUtlMemory< unsigned char > &inBuffer, int w, int h, ImageFormat srcFmt, bool bGenMips ) + { + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s", __FUNCTION__ ); + + const int mipmapCount = bGenMips ? ImageLoader::GetNumMipMapLevels( w, h ) : 1; + + unsigned char* pSrc = inBuffer.Base(); + unsigned char* pDst = (*outBuffer).Base(); + int mip_w = w; + int mip_h = h; + + for ( int i = 0; i < mipmapCount; ++i ) + { + ImageLoader::ConvertImageFormat( pSrc, srcFmt, pDst, dstFmt, mip_w, mip_h ); + + pSrc += ImageLoader::GetMemRequired( mip_w, mip_h, 1, srcFmt, false ); + pDst += ImageLoader::GetMemRequired( mip_w, mip_h, 1, dstFmt, false ); + + mip_w = Max( 1, mip_w >> 1 ); + mip_h = Max( 1, mip_h >> 1 ); + } + } + static unsigned ReaderMain( void* _this ) + { + ThreadSetDebugName( "Helper" ); + + s_TextureManager.m_nAsyncReadThread = ThreadGetCurrentId(); + ( ( AsyncReader* ) _this )->ThreadReader_Main(); + s_TextureManager.m_nAsyncReadThread = 0xFFFFFFFF; + return 0; + } + + ThreadHandle_t m_HelperThread; + volatile bool m_bQuit; + + CTSQueue< AsyncReadJob_t*> m_requestedCopies; + CUtlQueue< AsyncReadJob_t* > m_queuedReads; + CUtlQueue< AsyncReadJob_t* > m_scheduledReads; + CUtlQueue< AsyncReadJob_t* > m_queuedMaps; + + CTSQueue< AsyncReadJob_t* > m_pendingJobs; + CTSQueue< AsyncReadJob_t* > m_completedJobs; +}; + +//----------------------------------------------------------------------------- +// Texture manager +//----------------------------------------------------------------------------- +CTextureManager::CTextureManager( void ) +: m_TextureList( true ) +, m_TextureAliases( true ) +, m_TextureExcludes( true ) +, m_PendingAsyncLoads( true ) +, m_textureStreamingRequests( DefLessFunc( ITextureInternal* ) ) +, m_nAsyncLoadThread( 0xFFFFFFFF ) +, m_nAsyncReadThread( 0xFFFFFFFF ) +{ + m_pErrorTexture = NULL; + m_pBlackTexture = NULL; + m_pWhiteTexture = NULL; + m_pGreyTexture = NULL; + m_pGreyAlphaZeroTexture = NULL; + m_pNormalizationCubemap = NULL; + m_pErrorRegen = NULL; + m_pFullScreenTexture = NULL; + m_pSignedNormalizationCubemap = NULL; + m_pShadowNoise2D = NULL; + m_pIdentityLightWarp = NULL; + m_pFullScreenDepthTexture = NULL; + m_pDebugLuxels2D = NULL; + m_pAsyncLoader = new AsyncLoader; + m_pAsyncReader = new AsyncReader; + m_iSuspendTextureStreaming = 0; +} + + +//----------------------------------------------------------------------------- +// Initialization + shutdown +//----------------------------------------------------------------------------- +void CTextureManager::Init( int nFlags ) +{ + m_nFlags = nFlags; + color32 color, color2; + m_iNextTexID = 4096; + + // setup the checkerboard generator for failed texture loading + color.r = color.g = color.b = 0; color.a = 128; + color2.r = color2.b = color2.a = 255; color2.g = 0; + m_pErrorRegen = new CCheckerboardTexture( 4, color, color2 ); + + // Create an error texture + m_pErrorTexture = CreateProceduralTexture( "error", TEXTURE_GROUP_OTHER, + ERROR_TEXTURE_SIZE, ERROR_TEXTURE_SIZE, 1, IMAGE_FORMAT_BGRA8888, TEXTUREFLAGS_NOMIP | TEXTUREFLAGS_SINGLECOPY ); + CreateCheckerboardTexture( m_pErrorTexture, 4, color, color2 ); + m_pErrorTexture->SetErrorTexture( true ); + + // Create a white texture + m_pWhiteTexture = CreateProceduralTexture( "white", TEXTURE_GROUP_OTHER, + WHITE_TEXTURE_SIZE, WHITE_TEXTURE_SIZE, 1, IMAGE_FORMAT_BGRX8888, TEXTUREFLAGS_NOMIP | TEXTUREFLAGS_SINGLECOPY ); + color.r = color.g = color.b = color.a = 255; + CreateSolidTexture( m_pWhiteTexture, color ); + + // Create a black texture + m_pBlackTexture = CreateProceduralTexture( "black", TEXTURE_GROUP_OTHER, + BLACK_TEXTURE_SIZE, BLACK_TEXTURE_SIZE, 1, IMAGE_FORMAT_BGRX8888, TEXTUREFLAGS_NOMIP | TEXTUREFLAGS_SINGLECOPY ); + color.r = color.g = color.b = 0; + CreateSolidTexture( m_pBlackTexture, color ); + + // Create a grey texture + m_pGreyTexture = CreateProceduralTexture( "grey", TEXTURE_GROUP_OTHER, + GREY_TEXTURE_SIZE, GREY_TEXTURE_SIZE, 1, IMAGE_FORMAT_BGRA8888, TEXTUREFLAGS_NOMIP | TEXTUREFLAGS_SINGLECOPY ); + color.r = color.g = color.b = 128; + color.a = 255; + CreateSolidTexture( m_pGreyTexture, color ); + + // Create a grey texture + m_pGreyAlphaZeroTexture = CreateProceduralTexture( "greyalphazero", TEXTURE_GROUP_OTHER, + GREY_TEXTURE_SIZE, GREY_TEXTURE_SIZE, 1, IMAGE_FORMAT_BGRA8888, TEXTUREFLAGS_NOMIP | TEXTUREFLAGS_SINGLECOPY ); + color.r = color.g = color.b = 128; + color.a = 0; + CreateSolidTexture( m_pGreyAlphaZeroTexture, color ); + + if ( HardwareConfig()->GetMaxDXSupportLevel() >= 80 ) + { + // Create a normalization cubemap + m_pNormalizationCubemap = CreateProceduralTexture( "normalize", TEXTURE_GROUP_CUBE_MAP, + NORMALIZATION_CUBEMAP_SIZE, NORMALIZATION_CUBEMAP_SIZE, 1, IMAGE_FORMAT_BGRX8888, + TEXTUREFLAGS_ENVMAP | TEXTUREFLAGS_NOMIP | TEXTUREFLAGS_SINGLECOPY | + TEXTUREFLAGS_CLAMPS | TEXTUREFLAGS_CLAMPT | TEXTUREFLAGS_CLAMPU ); + CreateNormalizationCubemap( m_pNormalizationCubemap ); + } + + if ( HardwareConfig()->GetMaxDXSupportLevel() >= 90 ) + { + // In GL, we have poor format support, so we ask for signed float + ImageFormat fmt = IsOpenGL() ? IMAGE_FORMAT_RGBA16161616F : IMAGE_FORMAT_UVWQ8888; + + int nTextureFlags = TEXTUREFLAGS_ENVMAP | TEXTUREFLAGS_NOMIP | TEXTUREFLAGS_NOLOD | TEXTUREFLAGS_SINGLECOPY | TEXTUREFLAGS_CLAMPS | TEXTUREFLAGS_CLAMPT | TEXTUREFLAGS_CLAMPU; + +#ifdef OSX + // JasonM - ridiculous hack around R500 lameness...we never use this texture on OSX anyways (right?) + // Now assuming this was an OSX specific workaround. + nTextureFlags |= TEXTUREFLAGS_POINTSAMPLE; +#endif + + // Create a normalization cubemap + m_pSignedNormalizationCubemap = CreateProceduralTexture( "normalizesigned", TEXTURE_GROUP_CUBE_MAP, + NORMALIZATION_CUBEMAP_SIZE, NORMALIZATION_CUBEMAP_SIZE, 1, fmt, nTextureFlags ); + CreateSignedNormalizationCubemap( m_pSignedNormalizationCubemap ); + + m_pIdentityLightWarp = FindOrLoadTexture( "dev/IdentityLightWarp", TEXTURE_GROUP_OTHER ); + m_pIdentityLightWarp->IncrementReferenceCount(); + } + + // High end hardware needs this texture for shadow mapping + if ( HardwareConfig()->ActuallySupportsPixelShaders_2_b() ) + { + m_pShadowNoise2D = FindOrLoadTexture( "engine/NormalizedRandomDirections2D", TEXTURE_GROUP_OTHER ); + m_pShadowNoise2D->IncrementReferenceCount(); + } + + m_pDebugLuxels2D = FindOrLoadTexture( "debug/debugluxelsnoalpha", TEXTURE_GROUP_OTHER ); + m_pDebugLuxels2D->IncrementReferenceCount(); +} + +void CTextureManager::Shutdown() +{ + // Clean up any textures we have hanging around that are waiting to go. + CleanupPossiblyUnreferencedTextures(); + + // Cool the texture cache first to drop all the refs back to 0 for the streamable things. + CoolTextureCache(); + + if ( m_pAsyncLoader ) + { + m_pAsyncLoader->Shutdown(); + delete m_pAsyncLoader; + m_pAsyncLoader = NULL; + } + + if ( m_pAsyncReader ) + { + m_pAsyncReader->Shutdown(); + delete m_pAsyncReader; + m_pAsyncReader = NULL; + } + + FreeStandardRenderTargets(); + + FOR_EACH_VEC( m_ReadbackTextures, i ) + { + m_ReadbackTextures[ i ]->Release(); + } + + if ( m_pDebugLuxels2D ) + { + m_pDebugLuxels2D->DecrementReferenceCount(); + m_pDebugLuxels2D = NULL; + } + + // These checks added because it's possible for shutdown to be called before the material system is + // fully initialized. + if ( m_pWhiteTexture ) + { + m_pWhiteTexture->DecrementReferenceCount(); + m_pWhiteTexture = NULL; + } + + if ( m_pBlackTexture ) + { + m_pBlackTexture->DecrementReferenceCount(); + m_pBlackTexture = NULL; + } + + if ( m_pGreyTexture ) + { + m_pGreyTexture->DecrementReferenceCount(); + m_pGreyTexture = NULL; + } + + if ( m_pGreyAlphaZeroTexture ) + { + m_pGreyAlphaZeroTexture->DecrementReferenceCount(); + m_pGreyAlphaZeroTexture = NULL; + } + + if ( m_pNormalizationCubemap ) + { + m_pNormalizationCubemap->DecrementReferenceCount(); + m_pNormalizationCubemap = NULL; + } + + if ( m_pSignedNormalizationCubemap ) + { + m_pSignedNormalizationCubemap->DecrementReferenceCount(); + m_pSignedNormalizationCubemap = NULL; + } + + if ( m_pShadowNoise2D ) + { + m_pShadowNoise2D->DecrementReferenceCount(); + m_pShadowNoise2D = NULL; + } + + if ( m_pIdentityLightWarp ) + { + m_pIdentityLightWarp->DecrementReferenceCount(); + m_pIdentityLightWarp = NULL; + } + + if ( m_pErrorTexture ) + { + m_pErrorTexture->DecrementReferenceCount(); + m_pErrorTexture = NULL; + } + + ReleaseTextures(); + + if ( m_pErrorRegen ) + { + m_pErrorRegen->Release(); + m_pErrorRegen = NULL; + } + + for ( int i = m_TextureList.First(); i != m_TextureList.InvalidIndex(); i = m_TextureList.Next( i ) ) + { + ITextureInternal::Destroy( m_TextureList[i], true ); + } + m_TextureList.RemoveAll(); + + for( int i = m_TextureAliases.First(); i != m_TextureAliases.InvalidIndex(); i = m_TextureAliases.Next( i ) ) + { + delete []m_TextureAliases[i]; + } + m_TextureAliases.RemoveAll(); + + m_TextureExcludes.RemoveAll(); +} + + +//----------------------------------------------------------------------------- +// Allocate, free standard render target textures +//----------------------------------------------------------------------------- +void CTextureManager::AllocateStandardRenderTargets( ) +{ + bool bAllocateFullscreenTexture = ( m_nFlags & MATERIAL_INIT_ALLOCATE_FULLSCREEN_TEXTURE ) != 0; + bool bAllocateMorphAccumTexture = g_pMorphMgr->ShouldAllocateScratchTextures(); + + if ( IsPC() && ( bAllocateFullscreenTexture || bAllocateMorphAccumTexture ) ) + { + MaterialSystem()->BeginRenderTargetAllocation(); + + // A offscreen render target which is the size + format of the back buffer (*not* HDR format!) + if ( bAllocateFullscreenTexture ) + { + m_pFullScreenTexture = CreateRenderTargetTexture( "_rt_FullScreen", 1, 1, RT_SIZE_FULL_FRAME_BUFFER_ROUNDED_UP, + MaterialSystem()->GetBackBufferFormat(), RENDER_TARGET, TEXTUREFLAGS_CLAMPS | TEXTUREFLAGS_CLAMPT, 0 ); + m_pFullScreenTexture->IncrementReferenceCount(); + } + + // This texture is the one we accumulate morph deltas into + if ( bAllocateMorphAccumTexture ) + { + g_pMorphMgr->AllocateScratchTextures(); + g_pMorphMgr->AllocateMaterials(); + } + + MaterialSystem()->EndRenderTargetAllocation(); + } +} + + +void CTextureManager::FreeStandardRenderTargets() +{ + if ( m_pFullScreenTexture ) + { + m_pFullScreenTexture->DecrementReferenceCount(); + m_pFullScreenTexture = NULL; + } + + g_pMorphMgr->FreeMaterials(); + g_pMorphMgr->FreeScratchTextures(); +} + + +void CTextureManager::CacheExternalStandardRenderTargets() +{ + m_pFullScreenDepthTexture = FindTexture( "_rt_FullFrameDepth" ); //created/destroyed in engine/matsys_interface.cpp to properly track hdr changes +} + + +//----------------------------------------------------------------------------- +// Generates an error texture pattern +//----------------------------------------------------------------------------- +void CTextureManager::GenerateErrorTexture( ITexture *pTexture, IVTFTexture *pVTFTexture ) +{ + m_pErrorRegen->RegenerateTextureBits( pTexture, pVTFTexture, NULL ); +} + +//----------------------------------------------------------------------------- +// Updates the color correction state +//----------------------------------------------------------------------------- +ITextureInternal *CTextureManager::ColorCorrectionTexture( int i ) +{ + Assert( iDecrementReferenceCount(); + } + + m_pColorCorrectionTextures[i] = pTexture; + if( pTexture ) + pTexture->IncrementReferenceCount(); +} + + +//----------------------------------------------------------------------------- +// Releases all textures (cause we've lost video memory) +//----------------------------------------------------------------------------- +void CTextureManager::ReleaseTextures( void ) +{ + g_pShaderAPI->SetFullScreenTextureHandle( INVALID_SHADERAPI_TEXTURE_HANDLE ); + + for ( int i = m_TextureList.First(); i != m_TextureList.InvalidIndex(); i = m_TextureList.Next( i ) ) + { + // Release the texture... + m_TextureList[i]->ReleaseMemory(); + } +} + + +//----------------------------------------------------------------------------- +// Request a texture ID +//----------------------------------------------------------------------------- +int CTextureManager::RequestNextTextureID() +{ + // FIXME: Deal better with texture ids + // The range between 19000 and 21000 are used for standard textures + lightmaps + if (m_iNextTexID == 19000) + { + m_iNextTexID = 21000; + } + + return m_iNextTexID++; +} + + +//----------------------------------------------------------------------------- +// Restores a single texture +//----------------------------------------------------------------------------- +void CTextureManager::RestoreTexture( ITextureInternal* pTexture ) +{ + // Put the texture back onto the board + pTexture->OnRestore(); // Give render targets a chance to reinitialize themselves if necessary (due to AA changes). + pTexture->Download(); +} + +//----------------------------------------------------------------------------- +// Purges our complete list of textures that might currently be unreferenced +//----------------------------------------------------------------------------- +void CTextureManager::CleanupPossiblyUnreferencedTextures() +{ + if ( !ThreadInMainThread() || MaterialSystem()->GetRenderThreadId() != 0xFFFFFFFF ) + { + Assert( !"CTextureManager::CleanupPossiblyUnreferencedTextures should never be called here" ); + // This is catastrophically bad, don't do this. Someone needs to fix this. See JohnS or McJohn + DebuggerBreakIfDebugging_StagingOnly(); + return; + } + + // It is perfectly valid for a texture to become referenced again (it lives on in our texture list, and can be + // re-loaded) and then free'd again, so ensure we don't have any duplicates in queue. + CUtlVector< ITextureInternal * > texturesToDelete( /* growSize */ 0, /* initialSize */ m_PossiblyUnreferencedTextures.Count() ); + ITextureInternal *pMaybeUnreferenced = NULL; + while ( m_PossiblyUnreferencedTextures.PopItem( &pMaybeUnreferenced ) ) + { + Assert( pMaybeUnreferenced->GetReferenceCount() >= 0 ); + if ( pMaybeUnreferenced->GetReferenceCount() == 0 && texturesToDelete.Find( pMaybeUnreferenced ) == texturesToDelete.InvalidIndex() ) + { + texturesToDelete.AddToTail( pMaybeUnreferenced ); + } + } + + // Free them + FOR_EACH_VEC( texturesToDelete, i ) + { + RemoveTexture( texturesToDelete[ i ] ); + } +} + +//----------------------------------------------------------------------------- +// Restore all textures (cause we've got video memory again) +//----------------------------------------------------------------------------- +void CTextureManager::RestoreNonRenderTargetTextures( ) +{ + // 360 should not have gotten here + Assert( !IsX360() ); + + for ( int i = m_TextureList.First(); i != m_TextureList.InvalidIndex(); i = m_TextureList.Next( i ) ) + { + if ( !m_TextureList[i]->IsRenderTarget() ) + { + RestoreTexture( m_TextureList[i] ); + } + } +} + +//----------------------------------------------------------------------------- +// Restore just the render targets (cause we've got video memory again) +//----------------------------------------------------------------------------- +void CTextureManager::RestoreRenderTargets() +{ + // 360 should not have gotten here + Assert( !IsX360() ); + + for ( int i = m_TextureList.First(); i != m_TextureList.InvalidIndex(); i = m_TextureList.Next( i ) ) + { + if ( m_TextureList[i]->IsRenderTarget() ) + { + RestoreTexture( m_TextureList[i] ); + } + } + + if ( m_pFullScreenTexture ) + { + g_pShaderAPI->SetFullScreenTextureHandle( m_pFullScreenTexture->GetTextureHandle( 0 ) ); + } + + CacheExternalStandardRenderTargets(); +} + + +//----------------------------------------------------------------------------- +// Reloads all textures +//----------------------------------------------------------------------------- +void CTextureManager::ReloadTextures() +{ + for ( int i = m_TextureList.First(); i != m_TextureList.InvalidIndex(); i = m_TextureList.Next( i ) ) + { + // Put the texture back onto the board + m_TextureList[i]->Download(); + } +} + +static void ForceTextureIntoHardware( ITexture *pTexture, IMaterial *pMaterial, IMaterialVar *pBaseTextureVar ) +{ + if ( IsX360() ) + return; + + pBaseTextureVar->SetTextureValue( pTexture ); + + CMatRenderContextPtr pRenderContext( MaterialSystem()->GetRenderContext() ); + pRenderContext->Bind( pMaterial ); + IMesh* pMesh = pRenderContext->GetDynamicMesh( true ); + + CMeshBuilder meshBuilder; + meshBuilder.Begin( pMesh, MATERIAL_TRIANGLES, 1 ); + + meshBuilder.Position3f( 0.0f, 0.0f, 0.0f ); + meshBuilder.TangentS3f( 0.0f, 1.0f, 0.0f ); + meshBuilder.TangentT3f( 1.0f, 0.0f, 0.0f ); + meshBuilder.Normal3f( 0.0f, 0.0f, 1.0f ); + meshBuilder.TexCoord2f( 0, 0.0f, 0.0f ); + meshBuilder.AdvanceVertex(); + + meshBuilder.Position3f( 0.0f, 0.0f, 0.0f ); + meshBuilder.TangentS3f( 0.0f, 1.0f, 0.0f ); + meshBuilder.TangentT3f( 1.0f, 0.0f, 0.0f ); + meshBuilder.Normal3f( 0.0f, 0.0f, 1.0f ); + meshBuilder.TexCoord2f( 0, 0.0f, 0.0f ); + meshBuilder.AdvanceVertex(); + + meshBuilder.Position3f( 0.0f, 0.0f, 0.0f ); + meshBuilder.TangentS3f( 0.0f, 1.0f, 0.0f ); + meshBuilder.TangentT3f( 1.0f, 0.0f, 0.0f ); + meshBuilder.Normal3f( 0.0f, 0.0f, 1.0f ); + meshBuilder.TexCoord2f( 0, 0.0f, 0.0f ); + meshBuilder.AdvanceVertex(); + + meshBuilder.End(); + pMesh->Draw(); +} + +//----------------------------------------------------------------------------- +// Reloads all textures +//----------------------------------------------------------------------------- +void CTextureManager::ForceAllTexturesIntoHardware( void ) +{ + if ( IsX360() ) + return; + + IMaterial *pMaterial = MaterialSystem()->FindMaterial( "engine/preloadtexture", "texture preload" ); + pMaterial = ((IMaterialInternal *)pMaterial)->GetRealTimeVersion(); //always work with the realtime material internally + pMaterial->IncrementReferenceCount(); + bool bFound; + IMaterialVar *pBaseTextureVar = pMaterial->FindVar( "$basetexture", &bFound ); + if( !bFound ) + { + return; + } + + for ( int i = m_TextureList.First(); i != m_TextureList.InvalidIndex(); i = m_TextureList.Next( i ) ) + { + // Put the texture back onto the board + ForceTextureIntoHardware( m_TextureList[i], pMaterial, pBaseTextureVar ); + } + pMaterial->DecrementReferenceCount(); +} + +//----------------------------------------------------------------------------- +// Get at a couple standard textures +//----------------------------------------------------------------------------- +ITextureInternal *CTextureManager::ErrorTexture() +{ + return m_pErrorTexture; +} + +ITextureInternal *CTextureManager::NormalizationCubemap() +{ + return m_pNormalizationCubemap; +} + +ITextureInternal *CTextureManager::SignedNormalizationCubemap() +{ + return m_pSignedNormalizationCubemap; +} + +ITextureInternal *CTextureManager::ShadowNoise2D() +{ + return m_pShadowNoise2D; +} + +ITextureInternal *CTextureManager::IdentityLightWarp() +{ + return m_pIdentityLightWarp; +} + +ITextureInternal *CTextureManager::FullFrameDepthTexture() +{ + return m_pFullScreenDepthTexture; +} + +ITextureInternal *CTextureManager::DebugLuxels2D() +{ + return m_pDebugLuxels2D; +} + + + +//----------------------------------------------------------------------------- +// Creates a procedural texture +//----------------------------------------------------------------------------- +ITextureInternal *CTextureManager::CreateProceduralTexture( + const char *pTextureName, + const char *pTextureGroupName, + int w, + int h, + int d, + ImageFormat fmt, + int nFlags, + ITextureRegenerator *generator ) +{ + ITextureInternal *pNewTexture = ITextureInternal::CreateProceduralTexture( pTextureName, pTextureGroupName, w, h, d, fmt, nFlags, generator ); + if ( !pNewTexture ) + return NULL; + + // Add it to the list of textures so it can be restored, etc. + m_TextureList.Insert( pNewTexture->GetName(), pNewTexture ); + + // NOTE: This will download the texture only if the shader api is ready + pNewTexture->Download(); + + return pNewTexture; +} + +//----------------------------------------------------------------------------- +// FIXME: Need some better understanding of when textures should be added to +// the texture dictionary here. Is it only for files, for example? +// Texture dictionary... +//----------------------------------------------------------------------------- +ITextureInternal *CTextureManager::LoadTexture( const char *pTextureName, const char *pTextureGroupName, int nAdditionalCreationFlags /* = 0 */, bool bDownload /* = true */ ) +{ + ITextureInternal *pNewTexture = ITextureInternal::CreateFileTexture( pTextureName, pTextureGroupName ); + if ( pNewTexture ) + { + int iIndex = m_TextureExcludes.Find( pNewTexture->GetName() ); + if ( m_TextureExcludes.IsValidIndex( iIndex ) ) + { + // mark the new texture as excluded + int nDimensionsLimit = m_TextureExcludes[iIndex]; + pNewTexture->MarkAsExcluded( ( nDimensionsLimit == 0 ), nDimensionsLimit ); + } + + // Stick the texture onto the board + if ( bDownload ) + pNewTexture->Download( NULL, nAdditionalCreationFlags ); + + // FIXME: If there's been an error loading, we don't also want this error... + } + + return pNewTexture; +} + +ITextureInternal *CTextureManager::FindTexture( const char *pTextureName ) +{ + if ( !pTextureName || pTextureName[0] == 0 ) + return NULL; + + char szCleanName[MAX_PATH]; + NormalizeTextureName( pTextureName, szCleanName, sizeof( szCleanName ) ); + + int i = m_TextureList.Find( szCleanName ); + if ( i != m_TextureList.InvalidIndex() ) + { + return m_TextureList[i]; + } + + i = m_TextureAliases.Find( szCleanName ); + if ( i != m_TextureAliases.InvalidIndex() ) + { + return FindTexture( m_TextureAliases[i] ); + } + + // Special handling: lightmaps + if ( char const *szLightMapNum = StringAfterPrefix( szCleanName, "[lightmap" ) ) + { + int iLightMapNum = atoi( szLightMapNum ); + extern CMaterialSystem g_MaterialSystem; + CMatLightmaps *plm = g_MaterialSystem.GetLightmaps(); + if ( iLightMapNum >= 0 && + iLightMapNum < plm->GetNumLightmapPages() ) + { + ShaderAPITextureHandle_t hTex = plm->GetLightmapPageTextureHandle( iLightMapNum ); + if ( hTex != INVALID_SHADERAPI_TEXTURE_HANDLE ) + { + // Establish the lookup linking in the dictionary + ITextureInternal *pTxInt = ITextureInternal::CreateReferenceTextureFromHandle( pTextureName, TEXTURE_GROUP_LIGHTMAP, hTex ); + m_TextureList.Insert( pTextureName, pTxInt ); + return pTxInt; + } + } + } + + return NULL; +} + +void CTextureManager::AddTextureAlias( const char *pAlias, const char *pRealName ) +{ + if ( (pAlias == NULL) || (pRealName == NULL) ) + return; //invalid alias + + char szCleanName[MAX_PATH]; + int index = m_TextureAliases.Find( NormalizeTextureName( pAlias, szCleanName, sizeof( szCleanName ) ) ); + + if ( index != m_TextureAliases.InvalidIndex() ) + { + AssertMsg( Q_stricmp( pRealName, m_TextureAliases[index] ) == 0, "Trying to use one name to alias two different textures." ); + RemoveTextureAlias( pAlias ); //remove the old alias to make room for the new one. + } + + size_t iRealNameLength = strlen( pRealName ) + 1; + char *pRealNameCopy = new char [iRealNameLength]; + memcpy( pRealNameCopy, pRealName, iRealNameLength ); + + m_TextureAliases.Insert( szCleanName, pRealNameCopy ); +} + +void CTextureManager::RemoveTextureAlias( const char *pAlias ) +{ + if ( pAlias == NULL ) + return; + + char szCleanName[MAX_PATH]; + int index = m_TextureAliases.Find( NormalizeTextureName( pAlias, szCleanName, sizeof( szCleanName ) ) ); + if ( index == m_TextureAliases.InvalidIndex() ) + return; //not found + + delete []m_TextureAliases[index]; + m_TextureAliases.RemoveAt( index ); +} + +void CTextureManager::SetExcludedTextures( const char *pScriptName ) +{ + // clear all exisiting texture's exclusion + for ( int i = m_TextureExcludes.First(); i != m_TextureExcludes.InvalidIndex(); i = m_TextureExcludes.Next( i ) ) + { + ITextureInternal *pTexture = FindTexture( m_TextureExcludes.GetElementName( i ) ); + if ( pTexture ) + { + pTexture->MarkAsExcluded( false, 0 ); + } + } + m_TextureExcludes.RemoveAll(); + + MEM_ALLOC_CREDIT(); + + // get optional script + CUtlBuffer excludeBuffer( 0, 0, CUtlBuffer::TEXT_BUFFER ); + if ( g_pFullFileSystem->ReadFile( pScriptName, NULL, excludeBuffer ) ) + { + char szToken[MAX_PATH]; + while ( 1 ) + { + // must support spaces in names without quotes + // have to brute force parse up to a valid line + while ( 1 ) + { + excludeBuffer.EatWhiteSpace(); + if ( !excludeBuffer.EatCPPComment() ) + { + // not a comment + break; + } + } + excludeBuffer.GetLine( szToken, sizeof( szToken ) ); + int tokenLength = strlen( szToken ); + if ( !tokenLength ) + { + // end of list + break; + } + + // remove all trailing whitespace + while ( tokenLength > 0 ) + { + tokenLength--; + if ( isgraph( szToken[tokenLength] ) ) + { + break; + } + szToken[tokenLength] = '\0'; + } + + // first optional token may be a dimension limit hint + int nDimensionsLimit = 0; + char *pTextureName = szToken; + if ( pTextureName[0] != 0 && isdigit( pTextureName[0] ) ) + { + nDimensionsLimit = atoi( pTextureName ); + + // skip forward to name + for ( ;; ) + { + char ch = *pTextureName; + if ( !ch || ( !isdigit( ch ) && !isspace( ch ) ) ) + { + break; + } + pTextureName++; + } + } + + char szCleanName[MAX_PATH]; + NormalizeTextureName( pTextureName, szCleanName, sizeof( szCleanName ) ); + + if ( m_TextureExcludes.Find( szCleanName ) != m_TextureExcludes.InvalidIndex() ) + { + // avoid duplicates + continue; + } + + m_TextureExcludes.Insert( szCleanName, nDimensionsLimit ); + + // set any existing texture's exclusion + // textures that don't exist yet will get caught during their creation path + ITextureInternal *pTexture = FindTexture( szCleanName ); + if ( pTexture ) + { + pTexture->MarkAsExcluded( ( nDimensionsLimit == 0 ), nDimensionsLimit ); + } + } + } +} + +void CTextureManager::UpdateExcludedTextures( void ) +{ + for ( int i = m_TextureList.First(); i != m_TextureList.InvalidIndex(); i = m_TextureList.Next( i ) ) + { + m_TextureList[i]->UpdateExcludedState(); + } +} + +ITextureInternal *CTextureManager::FindOrLoadTexture( const char *pTextureName, const char *pTextureGroupName, int nAdditionalCreationFlags /* = 0 */ ) +{ + ITextureInternal *pTexture = FindTexture( pTextureName ); + if ( !pTexture ) + { + pTexture = LoadTexture( pTextureName, pTextureGroupName, nAdditionalCreationFlags ); + if ( pTexture ) + { + // insert into the dictionary using the processed texture name + m_TextureList.Insert( pTexture->GetName(), pTexture ); + } + } + + return pTexture; +} + +bool CTextureManager::IsTextureLoaded( const char *pTextureName ) +{ + ITextureInternal *pTexture = FindTexture( pTextureName ); + return ( pTexture != NULL ); +} + + +//----------------------------------------------------------------------------- +// Creates a texture that's a render target +//----------------------------------------------------------------------------- +ITextureInternal *CTextureManager::CreateRenderTargetTexture( + const char *pRTName, // NULL for auto-generated name + int w, + int h, + RenderTargetSizeMode_t sizeMode, + ImageFormat fmt, + RenderTargetType_t type, + unsigned int textureFlags, + unsigned int renderTargetFlags ) +{ + MEM_ALLOC_CREDIT_( __FILE__ ": Render target" ); + + ITextureInternal *pTexture; + if ( pRTName ) + { + // caller is re-initing or changing + pTexture = FindTexture( pRTName ); + if ( pTexture ) + { + // Changing the underlying render target, but leaving the pointer and refcount + // alone fixes callers that have exisiting references to this object. + ITextureInternal::ChangeRenderTarget( pTexture, w, h, sizeMode, fmt, type, + textureFlags, renderTargetFlags ); + + // download if ready + pTexture->Download(); + return pTexture; + } + } + + pTexture = ITextureInternal::CreateRenderTarget( pRTName, w, h, sizeMode, fmt, type, + textureFlags, renderTargetFlags ); + if ( !pTexture ) + return NULL; + + // Add the render target to the list of textures + // that way it'll get cleaned up correctly in case of a task switch + m_TextureList.Insert( pTexture->GetName(), pTexture ); + + // NOTE: This will download the texture only if the shader api is ready + pTexture->Download(); + + return pTexture; +} + +void CTextureManager::ResetTextureFilteringState( ) +{ + for ( int i = m_TextureList.First(); i != m_TextureList.InvalidIndex(); i = m_TextureList.Next( i ) ) + { + m_TextureList[i]->SetFilteringAndClampingMode(); + } +} + +void CTextureManager::SuspendTextureStreaming( void ) +{ + m_iSuspendTextureStreaming++; +} + +void CTextureManager::ResumeTextureStreaming( void ) +{ + AssertMsg( m_iSuspendTextureStreaming, "Mismatched Suspend/Resume texture streaming calls" ); + if ( m_iSuspendTextureStreaming ) + { + m_iSuspendTextureStreaming--; + } +} + +void CTextureManager::RemoveUnusedTextures( void ) +{ + // First, need to flush all of our textures that are pending cleanup. + CleanupPossiblyUnreferencedTextures(); + + int iNext; + for ( int i = m_TextureList.First(); i != m_TextureList.InvalidIndex(); i = iNext ) + { + iNext = m_TextureList.Next( i ); + +#ifdef _DEBUG + if ( m_TextureList[i]->GetReferenceCount() < 0 ) + { + Warning( "RemoveUnusedTextures: pTexture->m_referenceCount < 0 for %s\n", m_TextureList[i]->GetName() ); + } +#endif + if ( m_TextureList[i]->GetReferenceCount() <= 0 ) + { + ITextureInternal::Destroy( m_TextureList[i] ); + m_TextureList.RemoveAt( i ); + } + } +} + +void CTextureManager::MarkUnreferencedTextureForCleanup( ITextureInternal *pTexture ) +{ + Assert( pTexture->GetReferenceCount() == 0 ); + m_PossiblyUnreferencedTextures.PushItem( pTexture ); +} + +void CTextureManager::RemoveTexture( ITextureInternal *pTexture ) +{ + TM_ZONE_DEFAULT( TELEMETRY_LEVEL0 ); + + Assert( pTexture->GetReferenceCount() <= 0 ); + + if ( !ThreadInMainThread() || MaterialSystem()->GetRenderThreadId() != 0xFFFFFFFF ) + { + Assert( !"CTextureManager::RemoveTexture should never be called here"); + // This is catastrophically bad, don't do this. Someone needs to fix this. + DebuggerBreakIfDebugging_StagingOnly(); + return; + } + + bool bTextureFound = false; + + // If the queue'd rendering thread is running, RemoveTexture() is going to explode. If it isn't, calling + // RemoveTexture while still dealing with immediate removal textures seems fishy, but could be legit, in which case + // this assert could be softened. + int nUnreferencedQueue = m_PossiblyUnreferencedTextures.Count(); + if ( nUnreferencedQueue ) + { + Assert( !"RemoveTexture() being called while textures sitting in possibly unreferenced queue" ); + // Assuming that this is all a wholesome main-thread misunderstanding, we can try to continue after filtering + // this texture from the queue. + ITextureInternal *pPossiblyUnreferenced = NULL; + for ( int i = 0; i < nUnreferencedQueue && m_PossiblyUnreferencedTextures.PopItem( &pPossiblyUnreferenced ); i++ ) + { + m_PossiblyUnreferencedTextures.PushItem( pPossiblyUnreferenced ); + + if ( pPossiblyUnreferenced == pTexture ) + { + bTextureFound = true; + break; + } + } + } + + if ( bTextureFound ) + { + Assert( !"CTextureManager::RemoveTexture has been called for a texture that has already requested cleanup. That's a paddlin'." ); + // This is catastrophically bad, don't do this. Someone needs to fix this. + DebuggerBreakIfDebugging_StagingOnly(); + return; + } + + for ( int i = m_TextureList.First(); i != m_TextureList.InvalidIndex(); i = m_TextureList.Next( i ) ) + { + // search by object + if ( m_TextureList[i] == pTexture ) + { + // This code is always sure that the texture we're tryign to clean up is no longer in the the possibly unreferenced list, + // So let Destroy work without checking. + ITextureInternal::Destroy( m_TextureList[i], true ); + m_TextureList.RemoveAt( i ); + break; + } + } +} + +void CTextureManager::ReloadFilesInList( IFileList *pFilesToReload ) +{ + if ( !IsPC() ) + return; + + for ( int i=m_TextureList.First(); i != m_TextureList.InvalidIndex(); i=m_TextureList.Next( i ) ) + { + ITextureInternal *pTex = m_TextureList[i]; + + pTex->ReloadFilesInList( pFilesToReload ); + } +} + +void CTextureManager::ReleaseTempRenderTargetBits( void ) +{ + if( IsX360() ) //only sane on 360 + { + int iNext; + for ( int i = m_TextureList.First(); i != m_TextureList.InvalidIndex(); i = iNext ) + { + iNext = m_TextureList.Next( i ); + + if ( m_TextureList[i]->IsTempRenderTarget() ) + { + m_TextureList[i]->ReleaseMemory(); + } + } + } +} + +void CTextureManager::DebugPrintUsedTextures( void ) +{ + for ( int i = m_TextureList.First(); i != m_TextureList.InvalidIndex(); i = m_TextureList.Next( i ) ) + { + ITextureInternal *pTexture = m_TextureList[i]; + Msg( "Texture: '%s' RefCount: %d\n", pTexture->GetName(), pTexture->GetReferenceCount() ); + } + + if ( m_TextureExcludes.Count() ) + { + Msg( "\nExcluded Textures: (%d)\n", m_TextureExcludes.Count() ); + for ( int i = m_TextureExcludes.First(); i != m_TextureExcludes.InvalidIndex(); i = m_TextureExcludes.Next( i ) ) + { + char buff[256]; + const char *pName = m_TextureExcludes.GetElementName( i ); + V_snprintf( buff, sizeof( buff ), "Excluded: %d '%s' \n", m_TextureExcludes[i], pName ); + + // an excluded texture is valid, but forced tiny + if ( IsTextureLoaded( pName ) ) + { + Msg( "%s", buff ); + } + else + { + // warn as unknown, could be a spelling error + Warning( "%s", buff ); + } + } + } +} + +int CTextureManager::FindNext( int iIndex, ITextureInternal **pTexInternal ) +{ + if ( iIndex == -1 && m_TextureList.Count() ) + { + iIndex = m_TextureList.First(); + } + else if ( !m_TextureList.Count() || !m_TextureList.IsValidIndex( iIndex ) ) + { + *pTexInternal = NULL; + return -1; + } + + *pTexInternal = m_TextureList[iIndex]; + + iIndex = m_TextureList.Next( iIndex ); + if ( iIndex == m_TextureList.InvalidIndex() ) + { + // end of list + iIndex = -1; + } + + return iIndex; +} + +void CTextureManager::Update() +{ + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s", __FUNCTION__ ); + + #ifdef STAGING_ONLY + if ( mat_texture_list_dump.GetBool() ) + { + DumpTextureList(); + mat_texture_list_dump.SetValue( 0 ); + } + #endif + + if ( m_pAsyncReader ) + m_pAsyncReader->ThreadMain_Update(); +} + +// Load a texture asynchronously and then call the provided callback. +void CTextureManager::AsyncFindOrLoadTexture( const char *pTextureName, const char *pTextureGroupName, IAsyncTextureOperationReceiver* pRecipient, void* pExtraArgs, bool bComplain, int nAdditionalCreationFlags ) +{ + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s", __FUNCTION__ ); + + bool bStreamingRequest = ( nAdditionalCreationFlags & TEXTUREFLAGS_STREAMABLE ) != 0; + + ITextureInternal* pLoadedTex = FindTexture( pTextureName ); + // It'd be weird to indicate that we're streaming and not actually have a texture that already exists. + Assert( !bStreamingRequest || pLoadedTex != NULL ); + + if ( pLoadedTex ) + { + if ( !bStreamingRequest ) + { + if ( pLoadedTex->IsError() && bComplain ) + DevWarning( "Texture '%s' not found.\n", pTextureName ); + pRecipient->OnAsyncFindComplete( pLoadedTex, pExtraArgs ); + SafeRelease( pRecipient ); + return; + } + } + + AsyncLoadJob_t asyncLoad( pTextureName, pTextureGroupName, pRecipient, pExtraArgs, bComplain, nAdditionalCreationFlags ); + + // If this is the first person asking to load this, then remember so we don't load the same thing over and over again. + int pendingIndex = m_PendingAsyncLoads.Find( pTextureName ); + if ( pendingIndex == m_PendingAsyncLoads.InvalidIndex() ) + { + // Create the texture here, we'll load the data in the async thread. Load is a misnomer, because it doesn't actually + // load the data--Download does. + if ( bStreamingRequest ) + asyncLoad.m_pResultData = pLoadedTex; + else + asyncLoad.m_pResultData = LoadTexture( pTextureName, pTextureGroupName, nAdditionalCreationFlags, false ); + AsyncLoad( asyncLoad ); + pendingIndex = m_PendingAsyncLoads.Insert( pTextureName ); + } + else + { + // If this is a thing we've seen before, just note that we also need it. + m_PendingAsyncLoads[ pendingIndex ].AddToTail( asyncLoad ); + } +} + +void CTextureManager::CompleteAsyncLoad( AsyncLoadJob_t* pJob ) +{ + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s", __FUNCTION__ ); + + Assert( pJob ); + bool bDownloaded = false; + + if ( !IsJobCancelled( pJob ) ) + { + // Perform the download. We did the read already. + pJob->m_pResultData->Download( NULL, pJob->m_nAdditionalCreationFlags ); + bDownloaded = true; + } + + // Then notify the caller that they're finished. + pJob->m_pRecipient->OnAsyncFindComplete( pJob->m_pResultData, pJob->m_pExtraArgs ); + + // Finally, deal with any other stragglers that asked for the same surface we did. + int pendingIndex = m_PendingAsyncLoads.Find( pJob->m_TextureName.Get() ); + Assert( pendingIndex != m_PendingAsyncLoads.InvalidIndex() ); + + FOR_EACH_VEC( m_PendingAsyncLoads[ pendingIndex ], i ) + { + AsyncLoadJob_t& straggler = m_PendingAsyncLoads[ pendingIndex ][ i ]; + straggler.m_pResultData = pJob->m_pResultData; + + if ( !bDownloaded && !IsJobCancelled( &straggler ) ) + { + bDownloaded = true; + straggler.m_pResultData->Download( NULL, straggler.m_nAdditionalCreationFlags ); + } + + straggler.m_pRecipient->OnAsyncFindComplete( straggler.m_pResultData, straggler.m_pExtraArgs ); + SafeRelease( &straggler.m_pRecipient ); + } + + // Add ourselves to the list of loaded things. + if ( bDownloaded ) + { + // The texture list has to be protected by the materials lock. + MaterialLock_t hMaterialLock = materials->Lock(); + + // It's possible that the texture wasn't actually unloaded, so we may have reloaded something unnecessarily. + // If so, just don't re-add it. + if ( m_TextureList.Find( pJob->m_pResultData->GetName() ) == m_TextureList.InvalidIndex() ) + m_TextureList.Insert( pJob->m_pResultData->GetName(), pJob->m_pResultData ); + + materials->Unlock( hMaterialLock ); + } + else + { + // If we didn't download, need to clean up the leftover file data that we loaded on the other thread + pJob->m_pResultData->AsyncCancelReadTexture(); + } + + // Can't release the Recipient until after we tell the stragglers, because the recipient may be the only + // ref to the texture, and cleaning it up may clean up the texture but leave us with a seemingly valid pointer. + SafeRelease( &pJob->m_pRecipient ); + + // Dump out the whole lot. + m_PendingAsyncLoads.RemoveAt( pendingIndex ); +} + +void CTextureManager::AsyncLoad( const AsyncLoadJob_t& job ) +{ + Assert( m_pAsyncLoader ); + m_pAsyncLoader->AsyncLoad( job ); +} + +void CTextureManager::AsyncCreateTextureFromRenderTarget( ITexture* pSrcRt, const char* pDstName, ImageFormat dstFmt, bool bGenMips, int nAdditionalCreationFlags, IAsyncTextureOperationReceiver* pRecipient, void* pExtraArgs ) +{ + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s", __FUNCTION__ ); + + Assert( pSrcRt ); + + AsyncReadJob_t* pAsyncRead = new AsyncReadJob_t( pSrcRt, pDstName, dstFmt, bGenMips, nAdditionalCreationFlags, pRecipient, pExtraArgs ); + AsyncReadTexture( pAsyncRead ); +} + +void CTextureManager::CompleteAsyncRead( AsyncReadJob_t* pJob ) +{ + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s", __FUNCTION__ ); + + // Release the texture back into the pool. + ReleaseReadbackTexture( pJob->m_pSysmemTex ); + pJob->m_pSysmemTex = NULL; + + int w = pJob->m_pSrcRt->GetActualWidth(); + int h = pJob->m_pSrcRt->GetActualHeight(); + + int mips = pJob->m_bGenMips ? ImageLoader::GetNumMipMapLevels( w, h ) : 1; + + int nFlags = pJob->m_nAdditionalCreationFlags + | TEXTUREFLAGS_SINGLECOPY + | TEXTUREFLAGS_IGNORE_PICMIP + | ( mips > 1 + ? TEXTUREFLAGS_ALL_MIPS + : TEXTUREFLAGS_NOMIP + ) + ; + + // Create the texture + ITexture* pFinalTex = materials->CreateNamedTextureFromBitsEx( pJob->m_pDstName, TEXTURE_GROUP_RUNTIME_COMPOSITE, w, h, mips, pJob->m_dstFmt, pJob->m_finalTexelData.Count(), pJob->m_finalTexelData.Base(), nFlags ); + Assert( pFinalTex ); + + // Make the callback! + pJob->m_pRecipient->OnAsyncCreateComplete( pFinalTex, pJob->m_pExtraArgs ); + SafeRelease( &pJob->m_pSrcRt ); + SafeRelease( &pJob->m_pRecipient ); + SafeRelease( &pFinalTex ); +} + +void CTextureManager::AsyncReadTexture( AsyncReadJob_t* pJob ) +{ + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s", __FUNCTION__ ); + + Assert( m_pAsyncReader ); + Assert( pJob ); + + pJob->m_pSysmemTex = AcquireReadbackTexture( pJob->m_pSrcRt->GetActualWidth(), pJob->m_pSrcRt->GetActualHeight(), pJob->m_pSrcRt->GetImageFormat() ); + Assert( pJob->m_pSysmemTex ); + + if ( !pJob->m_pSysmemTex ) + { + Assert( !"Need to deal with this error case" ); // TODOERROR + return; + } + + m_pAsyncReader->AsyncReadback( pJob ); +} + + +ITextureInternal* CTextureManager::AcquireReadbackTexture( int w, int h, ImageFormat fmt ) +{ + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s", __FUNCTION__ ); + + { + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s-TryExisting", __FUNCTION__ ); + MaterialLock_t hMaterialLock = materials->Lock(); + + FOR_EACH_VEC( m_ReadbackTextures, i ) + { + ITextureInternal* pTex = m_ReadbackTextures[ i ]; + Assert( pTex ); + + if ( pTex->GetActualWidth() == w + && pTex->GetActualHeight() == h + && pTex->GetImageFormat() == fmt ) + { + // Found one in the cache already + pTex->AddRef(); + m_ReadbackTextures.Remove( i ); + + materials->Unlock( hMaterialLock ); + return pTex; + } + } + + materials->Unlock( hMaterialLock ); + } + + tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s-CreateNew", __FUNCTION__ ); + ITextureInternal* stagingTex = CreateProceduralTexture( "readbacktex", TEXTURE_GROUP_OTHER, w, h, 1, fmt, TEXTUREFLAGS_STAGING_MEMORY | TEXTUREFLAGS_NOMIP | TEXTUREFLAGS_SINGLECOPY | TEXTUREFLAGS_IMMEDIATE_CLEANUP ); + // AddRef here for caller. + stagingTex->AddRef(); + return stagingTex; +} + +void CTextureManager::ReleaseReadbackTexture( ITextureInternal* pTex ) +{ + Assert( pTex ); + + MaterialLock_t hMaterialLock = materials->Lock(); + // Release matching AddRef in AcquireReadbackTexture + pTex->Release(); + m_ReadbackTextures.AddToTail( pTex ); + materials->Unlock( hMaterialLock ); +} + +#ifdef STAGING_ONLY + static int SortTexturesForDump( const CUtlPair< CUtlString, void* >* sz1, const CUtlPair< CUtlString, void* >* sz2 ) + { + int sortVal = CUtlString::SortCaseSensitive( &sz1->first, &sz2->first ); + if ( sortVal != 0 ) + return sortVal; + + return int( ( int ) sz1->second - ( int ) sz2->second ); + } + + void CTextureManager::DumpTextureList() + { + CUtlVector< CUtlPair< CUtlString, void* > > textures; + MaterialLock_t hMaterialLock = materials->Lock(); + FOR_EACH_DICT( m_TextureList, i ) + { + textures.AddToTail( MakeUtlPair( CUtlString( m_TextureList[i]->GetName() ), (void*) m_TextureList[i] ) ); + } + materials->Unlock( hMaterialLock ); + + // Now dump them out, sorted first by the texture name, then by address. + textures.Sort( SortTexturesForDump ); + FOR_EACH_VEC( textures, i ) + { + CUtlPair< CUtlString, void* >& pair = textures[i]; + Warning( "[%p]: %s\n", pair.second, pair.first.Get() ) ; + } + } +#endif + +//----------------------------------------------------------------------------- +// Warms the texture cache from a vpk. This will cause coarse mipmaps to be +// available all the time, starting with mipmap level 3. This allows us to have +// all the textures available all the time, but we only pay for fine levels when +// we actually need them. +//----------------------------------------------------------------------------- +void CTextureManager::WarmTextureCache() +{ + // Disable cache for osx/linux for now. + if ( CommandLine()->CheckParm( "-no_texture_stream" ) ) + return; + MemoryInformation memInfo; + if ( GetMemoryInformation( &memInfo ) ) + { + if ( memInfo.m_nPhysicalRamMbTotal <= 3584 ) + return; + } + + COM_TimestampedLog( "WarmTextureCache() - Begin" ); + + // If this fires, we need to relocate this elsewhere--there's no point in doing the loading + // if we're not going to be able to download them right now. + Assert( g_pShaderAPI->CanDownloadTextures() ); + + g_pFullFileSystem->AddSearchPath( "tf2_texture_cache.vpk", cTextureCachePathDir, PATH_ADD_TO_TAIL ); + + CUtlDict< int > filesToLoad( k_eDictCompareTypeCaseSensitive ); + + // TODO: Maybe work directly with VPK (still need to add to the filesystem for LoadTexture)? + // CPackFile + + // Add the pak and then walk through the contents. + FindFilesToLoad( &filesToLoad, "*.*" ); + + // Then add the list of files from the cache, which will deal with running without a VPK and also + // allow us to add late stragglers. + ReadFilesToLoad( &filesToLoad, "texture_preload_list.txt" ); + + if ( filesToLoad.Count() == 0 ) + { + COM_TimestampedLog( "WarmTextureCache() - End (No files loaded)" ); + return; + } + + Assert( filesToLoad.Count() > 0 ); + + // Now read all of the files. + // TODO: This needs to read in specific order to ensure peak performance. + FOR_EACH_DICT( filesToLoad, i ) + { + const char* pFilename = filesToLoad.GetElementName( i ); + + // Load the texture. This will only load the lower mipmap levels because that's the file we'll find now. + ITextureInternal* pTex = LoadTexture( pFilename, TEXTURE_GROUP_PRECACHED, TEXTUREFLAGS_STREAMABLE_COARSE ); + COM_TimestampedLog( "WarmTextureCache(): LoadTexture( %s ): Complete", pFilename ); + + if ( ( pTex->GetFlags() & TEXTUREFLAGS_STREAMABLE ) == 0 ) + { + STAGING_ONLY_EXEC( Warning( "%s is listed in texture_preload_list.txt or is otherwise marked for streaming. It cannot be streamed and should be removed from the streaming system.\n", pFilename ) ); + ITextureInternal::Destroy( pTex ); + continue; + } + + if ( !pTex->IsError() ) + { + m_TextureList.Insert( pTex->GetName(), pTex ); + pTex->AddRef(); + m_preloadedTextures.AddToTail( pTex ); + } + else + { + // Don't preload broken textures + ITextureInternal::Destroy( pTex ); + } + } + + g_pFullFileSystem->RemoveSearchPath( "tf2_texture_cache.vpk", cTextureCachePathDir ); + + COM_TimestampedLog( "WarmTextureCache() - End" ); +} + +//----------------------------------------------------------------------------- +// Reads the list of files contained in the vpk loaded above, and adds them to the +// list of files we need to load (passing in as pOutFilesToLoad). The map contains +// the +//----------------------------------------------------------------------------- +void CTextureManager::FindFilesToLoad( CUtlDict< int >* pOutFilesToLoad, const char* pFilename ) +{ + Assert( pOutFilesToLoad != NULL ); + + FileFindHandle_t fh; + pFilename = g_pFullFileSystem->FindFirstEx( pFilename, cTextureCachePathDir, &fh ); + + while ( pFilename != NULL ) + { + if ( g_pFullFileSystem->FindIsDirectory( fh ) ) + { + if ( pFilename[0] != '.' ) + { + char childFilename[_MAX_PATH]; + V_sprintf_safe( childFilename, "%s/*.*", pFilename ); + FindFilesToLoad( pOutFilesToLoad, childFilename ); + } + } + else + { + char filenameNoExtension[_MAX_PATH]; + V_StripExtension( pFilename, filenameNoExtension, _MAX_PATH ); + // Add the file to the list, which we will later traverse in order to ensure we're hitting these in the expected order for the VPK. + ( *pOutFilesToLoad ).Insert( CUtlString( filenameNoExtension ), 0 ); + } + + pFilename = g_pFullFileSystem->FindNext( fh ); + } +} + +//----------------------------------------------------------------------------- +// Read the contents of pFilename, which should just be a list of texture names +// that we should load. +//----------------------------------------------------------------------------- +void CTextureManager::ReadFilesToLoad( CUtlDict< int >* pOutFilesToLoad, const char* pFilename ) +{ + Assert( pOutFilesToLoad != NULL ); + + FileHandle_t fh = g_pFullFileSystem->Open( pFilename, "r" ); + if ( !fh ) + return; + + CUtlBuffer fileContents( 0, 0, CUtlBuffer::TEXT_BUFFER ); + if ( !g_pFullFileSystem->ReadToBuffer( fh, fileContents ) ) + goto cleanup; + + char buffer[_MAX_PATH + 1]; + while ( 1 ) + { + fileContents.GetLine( buffer, _MAX_PATH ); + if ( buffer[ 0 ] == 0 ) + break; + + V_StripWhitespace( buffer ); + + if ( buffer[ 0 ] == 0 ) + continue; + + // If it's not in the map already, add it. + if ( pOutFilesToLoad->Find( buffer ) == pOutFilesToLoad->InvalidIndex() ) + ( *pOutFilesToLoad ).Insert( buffer, 0 ); + } + +cleanup: + g_pFullFileSystem->Close( fh ); +} + +void CTextureManager::UpdatePostAsync() +{ + TM_ZONE_DEFAULT( TELEMETRY_LEVEL0 ); + + // Update the async loader, which affects streaming in (streaming out is handled below). + // Both stream in and stream out have to happen while the async job is not running because + // they muck with shaderapi texture handles which could be in use if the async job is currently + // being run + if ( m_pAsyncLoader ) + m_pAsyncLoader->ThreadMain_Update(); + + // First, move everything from the async request queue to active list + ITextureInternal* pRequest = NULL; + while ( m_asyncStreamingRequests.PopItem( &pRequest ) ) + { + Assert( pRequest != NULL ); + + // Update the LOD bias to smoothly stream the texture in. We only need to do this on frames that + // we actually have been requested to draw--other frames it doesn't matter (see, because we're not drawing?) + pRequest->UpdateLodBias(); + m_textureStreamingRequests.InsertOrReplace( pRequest, g_FrameNum ); + } + + // Then update streaming + const int cThirtySecondsOrSoInFrames = 2000; + + // First, remove old stuff. + FOR_EACH_MAP_FAST( m_textureStreamingRequests, i ) + { + if ( m_textureStreamingRequests[ i ] + cThirtySecondsOrSoInFrames < g_FrameNum ) + { + ITextureInternal* pTex = m_textureStreamingRequests.Key( i ); + + // It's been awhile since we were asked to full res this texture, so let's evict + // if it's still full res. + + if ( pTex->GetTargetResidence() == RESIDENT_FULL ) + pTex->MakeResident( RESIDENT_PARTIAL ); + + m_textureStreamingRequests.RemoveAt( i ); + } + } + + // Then, start allowing new stuff to ask for data. + FOR_EACH_MAP_FAST( m_textureStreamingRequests, i ) + { + int requestFrame = m_textureStreamingRequests[ i ]; + + if ( g_FrameNum == requestFrame ) + { + ITextureInternal* pTex = m_textureStreamingRequests.Key( i ); + + if ( pTex->GetTargetResidence() == RESIDENT_FULL ) + continue; + + // TODO: What to do if this fails? Auto-reask next frame? + pTex->MakeResident( RESIDENT_FULL ); + } + } + + // Finally, flush any immediate release textures marked for cleanup that are still unreferenced. + CleanupPossiblyUnreferencedTextures(); +} + +void CTextureManager::ReleaseAsyncScratchVTF( IVTFTexture *pScratchVTF ) +{ + Assert( m_pAsyncLoader != NULL && pScratchVTF != NULL ); + m_pAsyncLoader->ReleaseAsyncReadBuffer( pScratchVTF ); +} + +bool CTextureManager::ThreadInAsyncLoadThread() const +{ + return ThreadGetCurrentId() == m_nAsyncLoadThread; +} + +bool CTextureManager::ThreadInAsyncReadThread() const +{ + return ThreadGetCurrentId() == m_nAsyncReadThread; +} + +bool CTextureManager::AddTextureCompositorTemplate( const char* pName, KeyValues* pTmplDesc ) +{ + Assert( pName && pTmplDesc ); + + int ndx = m_TexCompTemplates.Find( pName ); + if ( ndx != m_TexCompTemplates.InvalidIndex() ) + { + // Later definitions stomp earlier ones. This lets the GC win. + delete m_TexCompTemplates[ ndx ]; + m_TexCompTemplates.RemoveAt( ndx ); + } + + CTextureCompositorTemplate* pNewTmpl = CTextureCompositorTemplate::Create( pName, pTmplDesc ); + + // If this is the case, the logging has already been done. + if ( pNewTmpl == NULL ) + return false; + + m_TexCompTemplates.Insert( pName, pNewTmpl ); + return true; +} + +bool CTextureManager::VerifyTextureCompositorTemplates() +{ + TM_ZONE_DEFAULT( TELEMETRY_LEVEL1 ); + + bool allSuccess = true; + + FOR_EACH_DICT_FAST( m_TexCompTemplates, i ) + { + if ( m_TexCompTemplates[ i ]->ResolveDependencies() ) + { + if ( m_TexCompTemplates[ i ]->HasDependencyCycles() ) + { + allSuccess = false; + } + } + else + { + allSuccess = false; + } + } + + return allSuccess; +} + + +CTextureCompositorTemplate* CTextureManager::FindTextureCompositorTemplate( const char* pName ) +{ + unsigned short i = m_TexCompTemplates.Find( pName ); + if ( m_TexCompTemplates.IsValidIndex( i ) ) + return m_TexCompTemplates[ i ]; + + return NULL; +} + +bool CTextureManager::HasPendingTextureDestroys() const +{ + return m_PossiblyUnreferencedTextures.Count() != 0; +} + +void CTextureManager::CoolTextureCache() +{ + FOR_EACH_VEC( m_preloadedTextures, i ) + { + m_preloadedTextures[ i ]->Release(); + } + + m_preloadedTextures.RemoveAll(); +} + +void CTextureManager::RequestAllMipmaps( ITextureInternal* pTex ) +{ + Assert( pTex ); + + // Don't mark these for load if suspended + if ( m_iSuspendTextureStreaming ) + return; + + unsigned int nTexFlags = pTex->GetFlags(); + + // If this isn't a streamable texture or if there are no mipmaps, there's nothing to do. + if ( !( nTexFlags & TEXTUREFLAGS_STREAMABLE ) || ( nTexFlags & TEXTUREFLAGS_NOMIP ) ) + return; + + m_asyncStreamingRequests.PushItem( pTex ); +} + +void CTextureManager::EvictAllTextures() +{ + FOR_EACH_DICT_FAST( m_TextureList, i ) + { + ITextureInternal* pTex = m_TextureList[ i ]; + if ( !pTex ) + continue; + + // If the fine mipmaps are present + if ( ( ( pTex->GetFlags() & TEXTUREFLAGS_STREAMABLE ) != 0 ) && pTex->GetTargetResidence() == RESIDENT_FULL ) + pTex->MakeResident( RESIDENT_PARTIAL ); + } +} + +CON_COMMAND( mat_evict_all, "Evict all fine mipmaps from the gpu" ) +{ + TextureManager()->EvictAllTextures(); +} + +// ------------------------------------------------------------------------------------------------ +// ------------------------------------------------------------------------------------------------ +// ------------------------------------------------------------------------------------------------ +static ImageFormat GetImageFormatRawReadback( ImageFormat fmt ) +{ + switch ( fmt ) + { + case IMAGE_FORMAT_RGBA8888: + return IMAGE_FORMAT_BGRA8888; + case IMAGE_FORMAT_BGRA8888: + return IMAGE_FORMAT_BGRA8888; + default: + Assert( !"Unsupported format in GetImageFormatRawReadback, this will likely result in color-swapped textures" ); + }; + + return fmt; +} + diff --git a/materialsystem/texturemanager.h b/materialsystem/texturemanager.h new file mode 100644 index 0000000..6542138 --- /dev/null +++ b/materialsystem/texturemanager.h @@ -0,0 +1,180 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $Header: $ +// $NoKeywords: $ +//===========================================================================// + +#ifndef TEXTUREMANAGER_H +#define TEXTUREMANAGER_H + +#ifdef _WIN32 +#pragma once +#endif + +#include "itextureinternal.h" +class ITexture; +class ITextureInternal; +class IVTFTexture; + +enum +{ + COLOR_CORRECTION_MAX_TEXTURES = 4, + COLOR_CORRECTION_TEXTURE_SIZE = 32 +}; + +class CTextureCompositorTemplate; + +//----------------------------------------------------------------------------- +// Texture manager interface +//----------------------------------------------------------------------------- +abstract_class ITextureManager +{ +public: + // Initialization + shutdown + virtual void Init( int nFlags ) = 0; + virtual void Shutdown() = 0; + + // Allocate, free standard render target textures + virtual void AllocateStandardRenderTargets( ) = 0; + virtual void FreeStandardRenderTargets() = 0; + + //Some render targets are managed by code outside of the materialsystem but are used by the materialsystem all the time. + virtual void CacheExternalStandardRenderTargets() = 0; + + // Creates a procedural texture + // NOTE: Passing in NULL as a texture name will cause it to not + // be able to be looked up by name using FindOrLoadTexture. + // Also, you may not get a texture with the requested size or format; + // you'll get something close though. + virtual ITextureInternal *CreateProceduralTexture( + const char *pTextureName, + const char *pTextureGroupName, + int w, + int h, + int d, + ImageFormat fmt, + int nFlags, + ITextureRegenerator *generator = NULL) = 0; + + // Creates a texture which is a render target + virtual ITextureInternal *CreateRenderTargetTexture( + const char *pRTName, // NULL for auto-generated name + int w, + int h, + RenderTargetSizeMode_t sizeMode, + ImageFormat fmt, + RenderTargetType_t type, + unsigned int textureFlags, + unsigned int renderTargetFlags ) = 0; + + // Loads a texture from disk + virtual ITextureInternal *FindOrLoadTexture( const char *pTextureName, const char *pTextureGroupName, int nAdditionalCreationFlags = 0 ) = 0; + + // Call this to reset the filtering state + virtual void ResetTextureFilteringState() = 0; + + // Reload all textures + virtual void ReloadTextures( void ) = 0; + + // These two are used when we lose our video memory due to a mode switch etc + virtual void ReleaseTextures( void ) = 0; + virtual void RestoreRenderTargets( void ) = 0; + virtual void RestoreNonRenderTargetTextures( void ) = 0; + + // Suspend or resume texture streaming requests + virtual void SuspendTextureStreaming( void ) = 0; + virtual void ResumeTextureStreaming( void ) = 0; + + // delete any texture that has a refcount <= 0 + virtual void RemoveUnusedTextures( void ) = 0; + virtual void DebugPrintUsedTextures( void ) = 0; + + // Request a texture ID + virtual int RequestNextTextureID() = 0; + + // Get at a couple standard textures + virtual ITextureInternal *ErrorTexture() = 0; + virtual ITextureInternal *NormalizationCubemap() = 0; + virtual ITextureInternal *SignedNormalizationCubemap() = 0; + virtual ITextureInternal *ColorCorrectionTexture( int index ) = 0; + virtual ITextureInternal *ShadowNoise2D() = 0; + virtual ITextureInternal *IdentityLightWarp() = 0; + virtual ITextureInternal *FullFrameDepthTexture() = 0; + virtual ITextureInternal *DebugLuxels2D() = 0; + + // Generates an error texture pattern + virtual void GenerateErrorTexture( ITexture *pTexture, IVTFTexture *pVTFTexture ) = 0; + + // Updates the color correction state + virtual void SetColorCorrectionTexture( int i, ITextureInternal *pTexture ) = 0; + + virtual void ForceAllTexturesIntoHardware( void ) = 0; + + virtual bool IsTextureLoaded( const char *pTextureName ) = 0; + + // Mark a texture as now-unreferenced, so it can be checked for removal at a later (and thread-safe) time. + virtual void MarkUnreferencedTextureForCleanup( ITextureInternal *pTexture ) = 0; + + virtual void RemoveTexture( ITextureInternal *pTexture ) = 0; + + // start with -1, list terminates with -1 + virtual int FindNext( int iIndex, ITextureInternal **ppTexture ) = 0; + + virtual void AddTextureAlias( const char *pAlias, const char *pRealName ) = 0; + virtual void RemoveTextureAlias( const char *pAlias ) = 0; + + virtual void SetExcludedTextures( const char *pScriptName ) = 0; + virtual void UpdateExcludedTextures( void ) = 0; + + //Releases texture memory bits for temporary render targets, does NOT destroy the CTexture entirely + virtual void ReleaseTempRenderTargetBits( void ) = 0; + + // See CL_HandlePureServerWhitelist for a description of the pure server stuff. + virtual void ReloadFilesInList( IFileList *pFilesToReload ) = 0; + + // Called once per frame by material system "somewhere." + virtual void Update( ) = 0; + + // Load a texture asynchronously and then call the provided callback. + virtual void AsyncFindOrLoadTexture( const char *pTextureName, const char *pTextureGroupName, IAsyncTextureOperationReceiver* pRecipient, void* pExtraArgs, bool bComplain, int nAdditionalCreationFlags ) = 0; + + // Stream a render target back to system memory, perform format conversion to the specified destination format, + virtual void AsyncCreateTextureFromRenderTarget( ITexture* pSrcRt, const char* pDstName, ImageFormat dstFmt, bool bGenMips, int nAdditionalCreationFlags, IAsyncTextureOperationReceiver* pRecipient, void* pExtraArgs ) = 0; + + virtual void WarmTextureCache() = 0; + virtual void CoolTextureCache() = 0; + + virtual void RequestAllMipmaps( ITextureInternal* pTex ) = 0; + + virtual void EvictAllTextures() = 0; + + virtual void UpdatePostAsync() = 0; + + virtual void ReleaseAsyncScratchVTF( IVTFTexture* pScratchVTF ) = 0; + + virtual bool ThreadInAsyncLoadThread() const = 0; + virtual bool ThreadInAsyncReadThread() const = 0; + + virtual bool HasPendingTextureDestroys() const = 0; + + virtual bool AddTextureCompositorTemplate( const char* pName, KeyValues* pTmplDesc ) = 0; + virtual bool VerifyTextureCompositorTemplates() = 0; + + virtual CTextureCompositorTemplate* FindTextureCompositorTemplate( const char* pName ) = 0; + +}; + + +//----------------------------------------------------------------------------- +// Singleton instance +//----------------------------------------------------------------------------- +inline ITextureManager *TextureManager() +{ + extern ITextureManager *g_pTextureManager; + return g_pTextureManager; +} + + +#endif // TEXTUREMANAGER_H diff --git a/materialsystem/wireframe.cpp b/materialsystem/wireframe.cpp new file mode 100644 index 0000000..686722c --- /dev/null +++ b/materialsystem/wireframe.cpp @@ -0,0 +1,58 @@ +//========= 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" + +#ifdef _WIN32 +DEFINE_FALLBACK_SHADER( Wireframe, Wireframe_DX6 ) +BEGIN_SHADER( Wireframe_DX6, + "Help for Wireframe_DX6" ) + + BEGIN_SHADER_PARAMS + SHADER_PARAM_OVERRIDE( BASETEXTURE, SHADER_PARAM_TYPE_TEXTURE, "shadertest/basetexture", "unused", SHADER_PARAM_NOT_EDITABLE ) + SHADER_PARAM_OVERRIDE( FRAME, SHADER_PARAM_TYPE_INTEGER, "0", "unused", SHADER_PARAM_NOT_EDITABLE ) + SHADER_PARAM_OVERRIDE( BASETEXTURETRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "unused", SHADER_PARAM_NOT_EDITABLE ) + END_SHADER_PARAMS + + SHADER_INIT_PARAMS() + { + SET_FLAGS( MATERIAL_VAR_NO_DEBUG_OVERRIDE ); + SET_FLAGS( MATERIAL_VAR_NOFOG ); + } + + SHADER_INIT + { + } + + SHADER_DRAW + { + SHADOW_STATE + { + pShaderShadow->PolyMode( SHADER_POLYMODEFACE_FRONT_AND_BACK, SHADER_POLYMODE_LINE ); + + SetModulationShadowState(); + SetDefaultBlendingShadowState(); + + int flags = SHADER_DRAW_POSITION; + if ( IS_FLAG_SET(MATERIAL_VAR_VERTEXCOLOR) || IS_FLAG_SET(MATERIAL_VAR_VERTEXALPHA) ) + { + flags |= SHADER_DRAW_COLOR; + } + pShaderShadow->DrawFlags( flags ); + } + DYNAMIC_STATE + { + SetModulationDynamicState(); + } + Draw(); + } +END_SHADER +#endif diff --git a/materialsystem/xbox/xbox.def b/materialsystem/xbox/xbox.def new file mode 100644 index 0000000..b980a7b --- /dev/null +++ b/materialsystem/xbox/xbox.def @@ -0,0 +1,3 @@ +LIBRARY materialsystem_360.dll +EXPORTS + CreateInterface @1 -- cgit v1.2.3